btrfs-progs: build: mention library dependency for reiserfs
[platform/upstream/btrfs-progs.git] / cmds-quota.c
index 34b8dac..15bd4b9 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "commands.h"
 #include "utils.h"
+#include "help.h"
 
 static const char * const quota_cmd_group_usage[] = {
        "btrfs quota <command> [options] <path>",
@@ -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;
 }