From eda2178b995a637529b95e748be9dd9460ec4d89 Mon Sep 17 00:00:00 2001 From: Jan Schmidt Date: Mon, 6 May 2013 21:15:18 +0200 Subject: Btrfs-progs: added "btrfs quota rescan" -w switch (wait) 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 Signed-off-by: David Sterba Signed-off-by: Chris Mason --- cmds-quota.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'cmds-quota.c') diff --git a/cmds-quota.c b/cmds-quota.c index 792aa7e2..3bef65c2 100644 --- a/cmds-quota.c +++ b/cmds-quota.c @@ -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] ", + "btrfs quota rescan [-sw] ", "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) { -- cgit v1.2.3