summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2015-07-27 16:27:28 +0200
committerDavid Sterba <dsterba@suse.com>2015-08-31 19:25:11 +0200
commite5a6610c943b0cdc29054dc2d247e7477019310d (patch)
treeaae06503529ddbe33ba38345c242c18d4a0fa6c8
parent79a851f143d58c4ab9f36753098ad95ddc3377bd (diff)
btrfs-progs: qgroup assign: add option to schedule rescan
Previous patch detecs inconsistency and unconditionally triggers quota rescan. This may not be always desired as it's a heavy metadata operation. In case of batch assignments it's better to trigger the rescan at the end. Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--Documentation/btrfs-qgroup.asciidoc10
-rw-r--r--cmds-qgroup.c55
2 files changed, 51 insertions, 14 deletions
diff --git a/Documentation/btrfs-qgroup.asciidoc b/Documentation/btrfs-qgroup.asciidoc
index eadfe1c9..cd7192c0 100644
--- a/Documentation/btrfs-qgroup.asciidoc
+++ b/Documentation/btrfs-qgroup.asciidoc
@@ -36,9 +36,17 @@ will not be functional until qgroup '0/<subvolume id>' is created again.
SUBCOMMAND
----------
-*assign* <src> <dst> <path>::
+*assign* [options] <src> <dst> <path>::
Assign qgroup <src> as the child qgroup of <dst> in the btrfs filesystem
identified by <path>.
++
+`Options`
++
+--rescan::::
+Automatically schedule quota rescan if the new qgroup assignment leads to
+quota inconsistency.
+--no-rescan::::
+Explicitly ask not to do a rescan.
*create* <qgroupid> <path>::
Create a subvolume quota group.
diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index f2200b7e..4a8b8d23 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -37,19 +37,40 @@ static int qgroup_assign(int assign, int argc, char **argv)
int ret = 0;
int fd;
int e;
+ int rescan = 0;
char *path;
struct btrfs_ioctl_qgroup_assign_args args;
DIR *dirstream = NULL;
- if (check_argc_exact(argc, 4))
+ while (1) {
+ enum { GETOPT_VAL_RESCAN = 256 };
+ static const struct option long_options[] = {
+ { "rescan", no_argument, NULL, GETOPT_VAL_RESCAN },
+ { NULL, 0, NULL, 0 }
+ };
+ int c = getopt_long(argc, argv, "", long_options, NULL);
+
+ if (c < 0)
+ break;
+ switch (c) {
+ case GETOPT_VAL_RESCAN:
+ rescan = 1;
+ break;
+ default:
+ /* Usage printed by the caller */
+ return -1;
+ }
+ }
+
+ if (check_argc_exact(argc - optind, 3))
return -1;
memset(&args, 0, sizeof(args));
args.assign = assign;
- args.src = parse_qgroupid(argv[1]);
- args.dst = parse_qgroupid(argv[2]);
+ args.src = parse_qgroupid(argv[optind]);
+ args.dst = parse_qgroupid(argv[optind + 1]);
- path = argv[3];
+ path = argv[optind + 2];
/*
* FIXME src should accept subvol path
@@ -82,14 +103,19 @@ static int qgroup_assign(int assign, int argc, char **argv)
* INCONSISTENT bit.
*/
if (ret > 0) {
- struct btrfs_ioctl_quota_rescan_args args;
-
- printf("Quota data changed, quota rescan scheduled\n");
- memset(&args, 0, sizeof(args));
- ret = ioctl(fd, BTRFS_IOC_QUOTA_RESCAN, &args);
- if (ret < 0)
- fprintf(stderr, "ERROR: quota rescan failed: %s\n",
- strerror(errno));
+ if (rescan) {
+ struct btrfs_ioctl_quota_rescan_args args;
+
+ printf("Quota data changed, rescan scheduled\n");
+ memset(&args, 0, sizeof(args));
+ ret = ioctl(fd, BTRFS_IOC_QUOTA_RESCAN, &args);
+ if (ret < 0)
+ fprintf(stderr,
+ "ERROR: quota rescan failed: %s\n",
+ strerror(errno));
+ } else {
+ printf("WARNING: quotas may be inconsistent, rescan needed\n");
+ }
}
close_file_or_dir(fd, dirstream);
return ret;
@@ -179,8 +205,11 @@ static int parse_limit(const char *p, unsigned long long *s)
}
static const char * const cmd_qgroup_assign_usage[] = {
- "btrfs qgroup assign <src> <dst> <path>",
+ "btrfs qgroup assign [options] <src> <dst> <path>",
"Enable subvolume qgroup support for a filesystem.",
+ "",
+ "--rescan schedule qutoa rescan if needed",
+ "--no-rescan ",
NULL
};