From f80a6b40b910d6921aad5f5ecd024a9e408f7b82 Mon Sep 17 00:00:00 2001 From: Jeff Mahoney Date: Tue, 25 Oct 2022 20:45:27 +0200 Subject: [PATCH] btrfs-progs: quota: add -W option to rescan to wait without starting rescan Adds a new options -W and --wait-norescan to wait for a rescan without starting a new operation. This is useful for things like fstests where we want do to do a "btrfs quota enable" and not continue until the subsequent rescan has finished. In addition to documenting the new option in the man page, clean up the rescan entry to document the -w option a bit better. Pull-request: #139 Reviewed-by: Qu Wenruo Signed-off-by: Jeff Mahoney Signed-off-by: David Sterba --- Documentation/btrfs-quota.rst | 6 ++++-- cmds/quota.c | 23 ++++++++++++++++------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Documentation/btrfs-quota.rst b/Documentation/btrfs-quota.rst index 5cadf6f8..990bd693 100644 --- a/Documentation/btrfs-quota.rst +++ b/Documentation/btrfs-quota.rst @@ -47,7 +47,7 @@ disable enable Enable subvolume quota support for a filesystem. -rescan [-s] +rescan [options] Trash all qgroup numbers and scan the metadata again with the current config. ``Options`` @@ -55,7 +55,9 @@ rescan [-s] -s|--status show status of a running rescan operation. -w|--wait - wait for rescan operation to finish(can be already in progress). + start rescan and wait for it to finish (can be already in progress) + -W|--wait-norescan + wait for rescan to finish without starting it EXIT STATUS ----------- diff --git a/cmds/quota.c b/cmds/quota.c index 9e26d2cb..d11b0aaf 100644 --- a/cmds/quota.c +++ b/cmds/quota.c @@ -109,8 +109,9 @@ static const char * const cmd_quota_rescan_usage[] = { "btrfs quota rescan [-sw] ", "Trash all qgroup numbers and scan the metadata again with the current config.", "", - "-s|--status show status of a running rescan operation", - "-w|--wait wait for rescan operation to finish (can be already in progress)", + "-s|--status show status of a running rescan operation", + "-w|--wait start rescan and wait for it to finish (can be already in progress)", + "-W|--wait-norescan wait for rescan to finish without starting it", HELPINFO_INSERT_GLOBALS, HELPINFO_INSERT_QUIET, NULL @@ -132,11 +133,12 @@ static int cmd_quota_rescan(const struct cmd_struct *cmd, int argc, char **argv) static const struct option long_options[] = { {"status", no_argument, NULL, 's'}, {"wait", no_argument, NULL, 'w'}, + {"wait-norescan", no_argument, NULL, 'W'}, {NULL, 0, NULL, 0} }; int c; - c = getopt_long(argc, argv, "sw", long_options, NULL); + c = getopt_long(argc, argv, "swW", long_options, NULL); if (c < 0) break; @@ -145,14 +147,19 @@ static int cmd_quota_rescan(const struct cmd_struct *cmd, int argc, char **argv) ioctlnum = BTRFS_IOC_QUOTA_RESCAN_STATUS; break; case 'w': + ioctlnum = BTRFS_IOC_QUOTA_RESCAN; wait_for_completion = true; break; + case 'W': + ioctlnum = 0; + wait_for_completion = 1; + break; default: usage_unknown_option(cmd, argv); } } - if (ioctlnum != BTRFS_IOC_QUOTA_RESCAN && wait_for_completion) { + if (ioctlnum == BTRFS_IOC_QUOTA_RESCAN_STATUS && wait_for_completion) { error("switch -w cannot be used with -s"); return 1; } @@ -167,8 +174,10 @@ static int cmd_quota_rescan(const struct cmd_struct *cmd, int argc, char **argv) if (fd < 0) return 1; - ret = ioctl(fd, ioctlnum, &args); - e = errno; + if (ioctlnum) { + ret = ioctl(fd, ioctlnum, &args); + e = errno; + } if (ioctlnum == BTRFS_IOC_QUOTA_RESCAN_STATUS) { close_file_or_dir(fd, dirstream); @@ -184,7 +193,7 @@ static int cmd_quota_rescan(const struct cmd_struct *cmd, int argc, char **argv) return 0; } - if (ret == 0) { + if (ioctlnum == BTRFS_IOC_QUOTA_RESCAN && ret == 0) { pr_verbose(LOG_DEFAULT, "quota rescan started\n"); fflush(stdout); } else if (ret < 0 && (!wait_for_completion || e != EINPROGRESS)) {