X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=cmds-quota.c;h=15bd4b9355ebc93c27143bbc07d4daa1a3b9a7bc;hb=f181e18f46de24b99a1341670a8936452cc55b12;hp=34b8dacfc5983cd60e2ba31268875a5facb6e093;hpb=3d6f61f8cb6ae24b2ff7494e48d635ef29570b5d;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/cmds-quota.c b/cmds-quota.c index 34b8dac..15bd4b9 100644 --- a/cmds-quota.c +++ b/cmds-quota.c @@ -24,6 +24,7 @@ #include "commands.h" #include "utils.h" +#include "help.h" static const char * const quota_cmd_group_usage[] = { "btrfs quota [options] ", @@ -70,7 +71,12 @@ static const char * const cmd_quota_enable_usage[] = { static int cmd_quota_enable(int argc, char **argv) { - int ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argc, argv); + int ret; + + clean_args_no_options(argc, argv, cmd_quota_enable_usage); + + ret = quota_ctl(BTRFS_QUOTA_CTL_ENABLE, argc, argv); + if (ret < 0) usage(cmd_quota_enable_usage); return ret; @@ -84,7 +90,12 @@ static const char * const cmd_quota_disable_usage[] = { static int cmd_quota_disable(int argc, char **argv) { - int ret = quota_ctl(BTRFS_QUOTA_CTL_DISABLE, argc, argv); + int ret; + + clean_args_no_options(argc, argv, cmd_quota_disable_usage); + + ret = quota_ctl(BTRFS_QUOTA_CTL_DISABLE, argc, argv); + if (ret < 0) usage(cmd_quota_disable_usage); return ret; @@ -110,7 +121,6 @@ static int cmd_quota_rescan(int argc, char **argv) DIR *dirstream = NULL; int wait_for_completion = 0; - optind = 1; while (1) { int c = getopt(argc, argv, "sw"); if (c < 0) @@ -145,28 +155,42 @@ static int cmd_quota_rescan(int argc, char **argv) ret = ioctl(fd, ioctlnum, &args); e = errno; - if (wait_for_completion && (ret == 0 || e == EINPROGRESS)) { - ret = ioctl(fd, BTRFS_IOC_QUOTA_RESCAN_WAIT, &args); - e = errno; - } - close_file_or_dir(fd, dirstream); - - if (ioctlnum == BTRFS_IOC_QUOTA_RESCAN) { + if (ioctlnum == BTRFS_IOC_QUOTA_RESCAN_STATUS) { + close_file_or_dir(fd, dirstream); if (ret < 0) { - error("quota rescan failed: %s", strerror(e)); + error("could not obtain quota rescan status: %s", + strerror(e)); return 1; - } else { - printf("quota rescan started\n"); } - } else { - if (!args.flags) { + if (!args.flags) printf("no rescan operation in progress\n"); - } else { + else printf("rescan operation running (current key %lld)\n", args.progress); + return 0; + } + + if (ret == 0) { + printf("quota rescan started\n"); + fflush(stdout); + } else if (ret < 0 && (!wait_for_completion || e != EINPROGRESS)) { + error("quota rescan failed: %s", strerror(e)); + close_file_or_dir(fd, dirstream); + return 1; + } + + if (wait_for_completion) { + ret = ioctl(fd, BTRFS_IOC_QUOTA_RESCAN_WAIT, &args); + e = errno; + if (ret < 0) { + error("quota rescan wait failed: %s", + strerror(e)); + close_file_or_dir(fd, dirstream); + return 1; } } + close_file_or_dir(fd, dirstream); return 0; }