Btrfs-progs: added "btrfs quota rescan" -w switch (wait)
authorJan Schmidt <list.btrfs@jan-o-sch.net>
Mon, 6 May 2013 19:15:18 +0000 (21:15 +0200)
committerDavid Sterba <dsterba@suse.cz>
Tue, 3 Sep 2013 17:40:50 +0000 (19:40 +0200)
With -w one can wait for a rescan operation to finish. It can be used when
starting a rescan operation or later to wait for the currently running
rescan operation to finish. Waiting is interruptible.

Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
cmds-quota.c
ioctl.h

index 792aa7e..3bef65c 100644 (file)
@@ -94,10 +94,11 @@ static int cmd_quota_disable(int argc, char **argv)
 }
 
 static const char * const cmd_quota_rescan_usage[] = {
-       "btrfs quota rescan [-s] <path>",
+       "btrfs quota rescan [-sw] <path>",
        "Trash all qgroup numbers and scan the metadata again with the current config.",
        "",
        "-s   show status of a running rescan operation",
+       "-w   wait for rescan operation to finish (can be already in progress)",
        NULL
 };
 
@@ -110,21 +111,30 @@ static int cmd_quota_rescan(int argc, char **argv)
        struct btrfs_ioctl_quota_rescan_args args;
        int ioctlnum = BTRFS_IOC_QUOTA_RESCAN;
        DIR *dirstream = NULL;
+       int wait_for_completion = 0;
 
        optind = 1;
        while (1) {
-               int c = getopt(argc, argv, "s");
+               int c = getopt(argc, argv, "sw");
                if (c < 0)
                        break;
                switch (c) {
                case 's':
                        ioctlnum = BTRFS_IOC_QUOTA_RESCAN_STATUS;
                        break;
+               case 'w':
+                       wait_for_completion = 1;
+                       break;
                default:
                        usage(cmd_quota_rescan_usage);
                }
        }
 
+       if (ioctlnum != BTRFS_IOC_QUOTA_RESCAN && wait_for_completion) {
+               fprintf(stderr, "ERROR: -w cannot be used with -s\n");
+               return 12;
+       }
+
        if (check_argc_exact(argc - optind, 1))
                usage(cmd_quota_rescan_usage);
 
@@ -139,6 +149,11 @@ 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) {
diff --git a/ioctl.h b/ioctl.h
index 27521d5..b1e3f1c 100644 (file)
--- a/ioctl.h
+++ b/ioctl.h
@@ -584,6 +584,7 @@ struct btrfs_ioctl_clone_range_args {
                               struct btrfs_ioctl_quota_rescan_args)
 #define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45, \
                               struct btrfs_ioctl_quota_rescan_args)
+#define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
 #define BTRFS_IOC_GET_FSLABEL _IOR(BTRFS_IOCTL_MAGIC, 49, \
                                   char[BTRFS_LABEL_SIZE])
 #define BTRFS_IOC_SET_FSLABEL _IOW(BTRFS_IOCTL_MAGIC, 50, \