Message ID | 88fb97835205d1faa824e695128eeff5927eeda1.1440579753.git.zhaolei@cn.fujitsu.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
On Wed, Aug 26, 2015 at 05:04:23PM +0800, Zhao Lei wrote: > We can use open_btrfs_dir() to check whether target dir is > in btrfs's mount point before open, instead of checking it in kernel > space of ioctl, and return fuzzy error message. > > Before patch: > # (/mnt/tmp is not btrfs mountpoint) > # > # btrfs device add -f /dev/sda13 /mnt/tmp > ERROR: error adding the device '/dev/sda13' - Inappropriate ioctl for device > # > > After patch: > # btrfs device add -f /dev/sda13 /mnt/tmp > ERROR: not btrfs filesystem: /mnt/tmp > # > > Similar fix for device remove and device usage. > > Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Applied, thanks. -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/cmds-device.c b/cmds-device.c index 00e362a..2dba050 100644 --- a/cmds-device.c +++ b/cmds-device.c @@ -84,11 +84,9 @@ static int cmd_device_add(int argc, char **argv) mntpnt = argv[optind + argc - 1]; - fdmnt = open_file_or_dir(mntpnt, &dirstream); - if (fdmnt < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", mntpnt); + fdmnt = open_btrfs_dir(mntpnt, &dirstream, 1); + if (fdmnt < 0) return 1; - } for (i = optind; i < optind + argc - 1; i++){ struct btrfs_ioctl_vol_args ioctl_args; @@ -157,11 +155,9 @@ static int _cmd_device_remove(int argc, char **argv, mntpnt = argv[argc - 1]; - fdmnt = open_file_or_dir(mntpnt, &dirstream); - if (fdmnt < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", mntpnt); + fdmnt = open_btrfs_dir(mntpnt, &dirstream, 1); + if (fdmnt < 0) return 1; - } for(i=1 ; i < argc - 1; i++ ){ struct btrfs_ioctl_vol_args arg; @@ -586,10 +582,8 @@ int cmd_device_usage(int argc, char **argv) if (more_than_one) printf("\n"); - fd = open_file_or_dir(argv[i], &dirstream); + fd = open_btrfs_dir(argv[i], &dirstream, 1); if (fd < 0) { - fprintf(stderr, "ERROR: can't access '%s'\n", - argv[1]); ret = 1; goto out; }
We can use open_btrfs_dir() to check whether target dir is in btrfs's mount point before open, instead of checking it in kernel space of ioctl, and return fuzzy error message. Before patch: # (/mnt/tmp is not btrfs mountpoint) # # btrfs device add -f /dev/sda13 /mnt/tmp ERROR: error adding the device '/dev/sda13' - Inappropriate ioctl for device # After patch: # btrfs device add -f /dev/sda13 /mnt/tmp ERROR: not btrfs filesystem: /mnt/tmp # Similar fix for device remove and device usage. Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> --- cmds-device.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-)