btrfs-progs: replace: use btrfs_open_dir for btrfs replace command

We can use btrfs_open_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:
  # ./btrfs replace cancel /mnt/tmp1
  ERROR: ioctl(DEV_REPLACE_CANCEL) failed on "/mnt/tmp1": Inappropriate ioctl for device
  # ./btrfs replace status /mnt/tmp1
  ERROR: ioctl(DEV_REPLACE_STATUS) failed on "/mnt/tmp1": Inappropriate ioctl for device

After patch:
  # ./btrfs replace cancel /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1
  # ./btrfs replace status /mnt/tmp1
  ERROR: not a btrfs filesystem: /mnt/tmp1

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
master
Zhao Lei 2015-10-12 21:23:03 +08:00 committed by David Sterba
parent 078618d822
commit 0b4e2d0c8a
1 changed files with 4 additions and 12 deletions

View File

@ -348,7 +348,6 @@ static const char *const cmd_replace_status_usage[] = {
static int cmd_replace_status(int argc, char **argv)
{
int fd;
int e;
int c;
char *path;
int once = 0;
@ -370,13 +369,9 @@ static int cmd_replace_status(int argc, char **argv)
usage(cmd_replace_status_usage);
path = argv[optind];
fd = open_file_or_dir(path, &dirstream);
e = errno;
if (fd < 0) {
fprintf(stderr, "ERROR: can't access \"%s\": %s\n",
path, strerror(e));
fd = btrfs_open_dir(path, &dirstream, 1);
if (fd < 0)
return 1;
}
ret = print_replace_status(fd, path, once);
close_file_or_dir(fd, dirstream);
@ -541,12 +536,9 @@ static int cmd_replace_cancel(int argc, char **argv)
usage(cmd_replace_cancel_usage);
path = argv[optind];
fd = open_file_or_dir(path, &dirstream);
if (fd < 0) {
fprintf(stderr, "ERROR: can't access \"%s\": %s\n",
path, strerror(errno));
fd = btrfs_open_dir(path, &dirstream, 1);
if (fd < 0)
return 1;
}
args.cmd = BTRFS_IOCTL_DEV_REPLACE_CMD_CANCEL;
args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT;