linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs: change resize ioctl to take device path instead of id
@ 2011-12-12  3:12 Phillip Susi
  2011-12-12  3:31 ` Li Zefan
  2012-01-09 15:15 ` Phillip Susi
  0 siblings, 2 replies; 4+ messages in thread
From: Phillip Susi @ 2011-12-12  3:12 UTC (permalink / raw)
  To: linux-btrfs

The resize ioctl took an optional argument that was a string
representation of the devid which you wish to resize.  For
the sake of consistency with the other ioctls that take a
device argument, I converted this to take a device path instead
of a devid number, and look up the number from the path.

Signed-off-by: Phillip Susi <psusi@cfl.rr.com>
---
 fs/btrfs/ioctl.c |   33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 72d4616..b4a0d46 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1211,13 +1211,32 @@ static noinline int btrfs_ioctl_resize(struct btrfs_root *root,
 	sizestr = vol_args->name;
 	devstr = strchr(sizestr, ':');
 	if (devstr) {
-		char *end;
-		sizestr = devstr + 1;
-		*devstr = '\0';
-		devstr = vol_args->name;
-		devid = simple_strtoull(devstr, &end, 10);
-		printk(KERN_INFO "btrfs: resizing devid %llu\n",
-		       (unsigned long long)devid);
+		struct block_device *bdev;
+		struct btrfs_super_block *disk_super;
+		struct buffer_head *bh;
+
+		*devstr = 0;
+		devstr++;
+		printk(KERN_INFO "btrfs: resizing device %s\n",
+			devstr);
+		bdev = blkdev_get_by_path(devstr, FMODE_READ | FMODE_EXCL,
+					  root->fs_info->bdev_holder);
+		if (IS_ERR(bdev)) {
+			ret = PTR_ERR(bdev);
+			goto out_unlock;
+		}
+
+		set_blocksize(bdev, 4096);
+		bh = btrfs_read_dev_super(bdev);
+		if (!bh) {
+			ret = -EINVAL;
+			blkdev_put(bdev, FMODE_READ | FMODE_EXCL);
+			goto out_unlock;
+		}
+		disk_super = (struct btrfs_super_block *)bh->b_data;
+		devid = btrfs_stack_device_id(&disk_super->dev_item);
+		brelse(bh);
+		blkdev_put(bdev, FMODE_READ | FMODE_EXCL);
 	}
 	device = btrfs_find_device(root, devid, NULL, NULL);
 	if (!device) {
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: change resize ioctl to take device path instead of id
  2011-12-12  3:12 [PATCH] btrfs: change resize ioctl to take device path instead of id Phillip Susi
@ 2011-12-12  3:31 ` Li Zefan
  2011-12-12  3:49   ` Phillip Susi
  2012-01-09 15:15 ` Phillip Susi
  1 sibling, 1 reply; 4+ messages in thread
From: Li Zefan @ 2011-12-12  3:31 UTC (permalink / raw)
  To: Phillip Susi; +Cc: linux-btrfs

Phillip Susi wrote:
> The resize ioctl took an optional argument that was a string
> representation of the devid which you wish to resize.  For
> the sake of consistency with the other ioctls that take a
> device argument, I converted this to take a device path instead
> of a devid number, and look up the number from the path.
> 

but.. isn't this an ABI change?

so instead of changing it, I think it's ok to extend it.

> Signed-off-by: Phillip Susi <psusi@cfl.rr.com>
> ---
>  fs/btrfs/ioctl.c |   33 ++++++++++++++++++++++++++-------
>  1 files changed, 26 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 72d4616..b4a0d46 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -1211,13 +1211,32 @@ static noinline int btrfs_ioctl_resize(struct btrfs_root *root,
>  	sizestr = vol_args->name;
>  	devstr = strchr(sizestr, ':');
>  	if (devstr) {
> -		char *end;
> -		sizestr = devstr + 1;
> -		*devstr = '\0';
> -		devstr = vol_args->name;
> -		devid = simple_strtoull(devstr, &end, 10);
> -		printk(KERN_INFO "btrfs: resizing devid %llu\n",
> -		       (unsigned long long)devid);
> +		struct block_device *bdev;
> +		struct btrfs_super_block *disk_super;
> +		struct buffer_head *bh;
> +
> +		*devstr = 0;
> +		devstr++;
> +		printk(KERN_INFO "btrfs: resizing device %s\n",
> +			devstr);
> +		bdev = blkdev_get_by_path(devstr, FMODE_READ | FMODE_EXCL,
> +					  root->fs_info->bdev_holder);
> +		if (IS_ERR(bdev)) {
> +			ret = PTR_ERR(bdev);
> +			goto out_unlock;
> +		}
> +
> +		set_blocksize(bdev, 4096);
> +		bh = btrfs_read_dev_super(bdev);
> +		if (!bh) {
> +			ret = -EINVAL;
> +			blkdev_put(bdev, FMODE_READ | FMODE_EXCL);
> +			goto out_unlock;
> +		}
> +		disk_super = (struct btrfs_super_block *)bh->b_data;
> +		devid = btrfs_stack_device_id(&disk_super->dev_item);
> +		brelse(bh);
> +		blkdev_put(bdev, FMODE_READ | FMODE_EXCL);
>  	}
>  	device = btrfs_find_device(root, devid, NULL, NULL);
>  	if (!device) {

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: change resize ioctl to take device path instead of id
  2011-12-12  3:31 ` Li Zefan
@ 2011-12-12  3:49   ` Phillip Susi
  0 siblings, 0 replies; 4+ messages in thread
From: Phillip Susi @ 2011-12-12  3:49 UTC (permalink / raw)
  To: Li Zefan; +Cc: linux-btrfs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12/11/2011 10:31 PM, Li Zefan wrote:
> Phillip Susi wrote:
>> The resize ioctl took an optional argument that was a string
>> representation of the devid which you wish to resize.  For
>> the sake of consistency with the other ioctls that take a
>> device argument, I converted this to take a device path instead
>> of a devid number, and look up the number from the path.
>>
> 
> but.. isn't this an ABI change?

Technically no, since the ABI is just a string that may (undocumented) have a colon in it followed by digits.

> so instead of changing it, I think it's ok to extend it.

I considered that at first, but the existing code appears to not handle errors ( what happens when the string can't be converted to an integer? ) and the interface has not been documented until now, so I figured may as well just get rid of it.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7leawACgkQJ4UciIs+XuIJ3ACeKuQidLKrb/nVqaS13Z1yzzoh
MDAAoIIPhBEnAbmTWdc6M4NBQUdX1+Pv
=7JV1
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs: change resize ioctl to take device path instead of id
  2011-12-12  3:12 [PATCH] btrfs: change resize ioctl to take device path instead of id Phillip Susi
  2011-12-12  3:31 ` Li Zefan
@ 2012-01-09 15:15 ` Phillip Susi
  1 sibling, 0 replies; 4+ messages in thread
From: Phillip Susi @ 2012-01-09 15:15 UTC (permalink / raw)
  To: linux-btrfs

Bump.

On 12/11/2011 10:12 PM, Phillip Susi wrote:
> The resize ioctl took an optional argument that was a string
> representation of the devid which you wish to resize.  For
> the sake of consistency with the other ioctls that take a
> device argument, I converted this to take a device path instead
> of a devid number, and look up the number from the path.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-01-09 15:15 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-12  3:12 [PATCH] btrfs: change resize ioctl to take device path instead of id Phillip Susi
2011-12-12  3:31 ` Li Zefan
2011-12-12  3:49   ` Phillip Susi
2012-01-09 15:15 ` Phillip Susi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).