summaryrefslogtreecommitdiff
path: root/cmds-quota.c
diff options
context:
space:
mode:
authorJan Schmidt <list.btrfs@jan-o-sch.net>2013-04-05 13:44:06 +0200
committerDavid Sterba <dsterba@suse.cz>2013-04-23 18:56:27 +0200
commite9217541db0861ce30178a11f9aadba6c914289b (patch)
treeae715d0fc8e45c286a6b64db5aa33a22a8956cc1 /cmds-quota.c
parentaa5f0626f8a7797278e55e9976c2e868962af8da (diff)
Btrfs-progs: quota rescan
This adds the quota rescan command to be used if qgroup tracking should get out of sync. Can also be used to query the status of a running rescan operation. Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Diffstat (limited to 'cmds-quota.c')
-rw-r--r--cmds-quota.c64
1 files changed, 58 insertions, 6 deletions
diff --git a/cmds-quota.c b/cmds-quota.c
index 71cd9f1e..2e2971a4 100644
--- a/cmds-quota.c
+++ b/cmds-quota.c
@@ -93,18 +93,70 @@ static int cmd_quota_disable(int argc, char **argv)
}
static const char * const cmd_quota_rescan_usage[] = {
- "btrfs quota rescan <path>",
- "Rescan the subvolume for a changed quota setting.",
- "Not yet implemented.",
+ "btrfs quota rescan [-s] <path>",
+ "Trash all qgroup numbers and scan the metadata again with the current config.",
+ "",
+ "-s show status of a running rescan operation",
NULL
};
static int cmd_quota_rescan(int argc, char **argv)
{
- int ret = quota_ctl(BTRFS_QUOTA_CTL_RESCAN, argc, argv);
- if (ret < 0)
+ int ret = 0;
+ int fd;
+ int e;
+ char *path = NULL;
+ struct btrfs_ioctl_quota_rescan_args args;
+ int ioctlnum = BTRFS_IOC_QUOTA_RESCAN;
+
+ optind = 1;
+ while (1) {
+ int c = getopt(argc, argv, "s");
+ if (c < 0)
+ break;
+ switch (c) {
+ case 's':
+ ioctlnum = BTRFS_IOC_QUOTA_RESCAN_STATUS;
+ break;
+ default:
+ usage(cmd_quota_rescan_usage);
+ }
+ }
+
+ if (check_argc_exact(argc - optind, 1))
usage(cmd_quota_rescan_usage);
- return ret;
+
+ memset(&args, 0, sizeof(args));
+
+ path = argv[optind];
+ fd = open_file_or_dir(path);
+ if (fd < 0) {
+ fprintf(stderr, "ERROR: can't access '%s'\n", path);
+ return 12;
+ }
+
+ ret = ioctl(fd, ioctlnum, &args);
+ e = errno;
+ close(fd);
+
+ if (ioctlnum == BTRFS_IOC_QUOTA_RESCAN) {
+ if (ret < 0) {
+ fprintf(stderr, "ERROR: quota rescan failed: "
+ "%s\n", strerror(e));
+ return 30;
+ } else {
+ printf("quota rescan started\n");
+ }
+ } else {
+ if (!args.flags) {
+ printf("no rescan operation in progress\n");
+ } else {
+ printf("rescan operation running (current key %lld)\n",
+ args.progress);
+ }
+ }
+
+ return 0;
}
const struct cmd_group quota_cmd_group = {