forked from Mirrors/btrfs-progs
btrfs-progs: balance: use btrfs_open_dir for btrfs balance 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 balance start /mnt/tmp ERROR: error during balancing '/mnt/tmp' - Inappropriate ioctl for device There may be more info in syslog - try dmesg | tail # After patch: # btrfs balance start /mnt/tmp ERROR: not btrfs filesystem: /mnt/tmp # Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>master
parent
d0c0f90b38
commit
45401669b0
|
@ -306,11 +306,9 @@ static int do_balance(const char *path, struct btrfs_ioctl_balance_args *args,
|
||||||
int e;
|
int e;
|
||||||
DIR *dirstream = NULL;
|
DIR *dirstream = NULL;
|
||||||
|
|
||||||
fd = open_file_or_dir(path, &dirstream);
|
fd = btrfs_open_dir(path, &dirstream, 1);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
fprintf(stderr, "ERROR: can't access '%s'\n", path);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
ret = ioctl(fd, BTRFS_IOC_BALANCE_V2, args);
|
ret = ioctl(fd, BTRFS_IOC_BALANCE_V2, args);
|
||||||
e = errno;
|
e = errno;
|
||||||
|
@ -503,11 +501,9 @@ static int cmd_balance_pause(int argc, char **argv)
|
||||||
|
|
||||||
path = argv[1];
|
path = argv[1];
|
||||||
|
|
||||||
fd = open_file_or_dir(path, &dirstream);
|
fd = btrfs_open_dir(path, &dirstream, 1);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
fprintf(stderr, "ERROR: can't access '%s'\n", path);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
ret = ioctl(fd, BTRFS_IOC_BALANCE_CTL, BTRFS_BALANCE_CTL_PAUSE);
|
ret = ioctl(fd, BTRFS_IOC_BALANCE_CTL, BTRFS_BALANCE_CTL_PAUSE);
|
||||||
e = errno;
|
e = errno;
|
||||||
|
@ -544,11 +540,9 @@ static int cmd_balance_cancel(int argc, char **argv)
|
||||||
|
|
||||||
path = argv[1];
|
path = argv[1];
|
||||||
|
|
||||||
fd = open_file_or_dir(path, &dirstream);
|
fd = btrfs_open_dir(path, &dirstream, 1);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
fprintf(stderr, "ERROR: can't access '%s'\n", path);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
ret = ioctl(fd, BTRFS_IOC_BALANCE_CTL, BTRFS_BALANCE_CTL_CANCEL);
|
ret = ioctl(fd, BTRFS_IOC_BALANCE_CTL, BTRFS_BALANCE_CTL_CANCEL);
|
||||||
e = errno;
|
e = errno;
|
||||||
|
@ -586,11 +580,9 @@ static int cmd_balance_resume(int argc, char **argv)
|
||||||
|
|
||||||
path = argv[1];
|
path = argv[1];
|
||||||
|
|
||||||
fd = open_file_or_dir(path, &dirstream);
|
fd = btrfs_open_dir(path, &dirstream, 1);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
fprintf(stderr, "ERROR: can't access '%s'\n", path);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
memset(&args, 0, sizeof(args));
|
memset(&args, 0, sizeof(args));
|
||||||
args.flags |= BTRFS_BALANCE_RESUME;
|
args.flags |= BTRFS_BALANCE_RESUME;
|
||||||
|
@ -679,11 +671,9 @@ static int cmd_balance_status(int argc, char **argv)
|
||||||
|
|
||||||
path = argv[optind];
|
path = argv[optind];
|
||||||
|
|
||||||
fd = open_file_or_dir(path, &dirstream);
|
fd = btrfs_open_dir(path, &dirstream, 1);
|
||||||
if (fd < 0) {
|
if (fd < 0)
|
||||||
fprintf(stderr, "ERROR: can't access '%s'\n", path);
|
|
||||||
return 2;
|
return 2;
|
||||||
}
|
|
||||||
|
|
||||||
ret = ioctl(fd, BTRFS_IOC_BALANCE_PROGRESS, &args);
|
ret = ioctl(fd, BTRFS_IOC_BALANCE_PROGRESS, &args);
|
||||||
e = errno;
|
e = errno;
|
||||||
|
|
Loading…
Reference in New Issue