From: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Fan Chengniang <fancn.fnst@cn.fujitsu.com>,
Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Subject: [PATCH 2/4] btrfs-progs: specify qgroup type when creating subvolume
Date: Tue, 10 Feb 2015 18:24:14 +0800 [thread overview]
Message-ID: <1423563862-9151-4-git-send-email-yangds.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <1423563862-9151-1-git-send-email-yangds.fnst@cn.fujitsu.com>
From: Fan Chengniang <fancn.fnst@cn.fujitsu.com>
add --qgroup-type option to specify qgroup type. Type
can be metadata, data or all.
Signed-off-by: Fan Chengniang <fancn.fnst@cn.fujitsu.com>
Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
---
Documentation/btrfs-subvolume.txt | 4 ++++
cmds-subvolume.c | 50 +++++++++++++++++++++++++++++++++------
qgroup.c | 15 ++++++++++++
qgroup.h | 1 +
4 files changed, 63 insertions(+), 7 deletions(-)
diff --git a/Documentation/btrfs-subvolume.txt b/Documentation/btrfs-subvolume.txt
index fe13943..4ac8cf5 100644
--- a/Documentation/btrfs-subvolume.txt
+++ b/Documentation/btrfs-subvolume.txt
@@ -60,6 +60,10 @@ set the newly created subvolume's max reference size
+
-e <max_excl>::::
set the newly created subvolume's max exclusive size
+--qgroup-type=<type>::::
+specify the <type> of qgroup to set qgroup limit.
++
+<attr> can be one of metadata, data, mixed.
*delete* [options] <subvolume> [<subvolume>...]::
Delete the subvolume(s) from the filesystem.
diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index f0e22ac..871f749 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -51,6 +51,8 @@ static const char * const cmd_subvol_create_usage[] = {
" option can be given multiple times.",
"-r <max_rfer> set the newly created subvolume's max reference size",
"-e <max_excl> set the newly created subvolume's max exclusive size",
+ "--qgroup-type=metadata,data,mixed",
+ " specify which qgroup type to set qgroup limit",
NULL
};
@@ -65,10 +67,19 @@ static int cmd_subvol_create(int argc, char **argv)
char *dst;
struct btrfs_qgroup_inherit *inherit = NULL;
DIR *dirstream = NULL;
+ __u8 qgroup_type = 0;
+ int set_qgroup_type = 0;
optind = 1;
while (1) {
- int c = getopt(argc, argv, "c:i:r:e:v");
+ int c;
+ static const struct option long_options[] = {
+ {"qgroup-type", required_argument, NULL, 'q'},
+ {NULL, 0, NULL, 0}
+ };
+
+ c = getopt_long(argc, argv, "c:i:r:e:v",
+ long_options, NULL);
if (c < 0)
break;
@@ -101,6 +112,14 @@ static int cmd_subvol_create(int argc, char **argv)
goto out;
}
break;
+ case 'q':
+ set_qgroup_type = 1;
+ res = btrfs_qgroup_set_qgroup_type(&qgroup_type, optarg);
+ if (res) {
+ retval = res;
+ goto out;
+ }
+ break;
default:
usage(cmd_subvol_create_usage);
}
@@ -143,11 +162,21 @@ static int cmd_subvol_create(int argc, char **argv)
}
printf("Create subvolume '%s/%s'\n", dstdir, newname);
- if (inherit) {
- struct btrfs_ioctl_vol_args_v2 args;
- struct btrfs_ioctl_quota_ctl_args sa;
+ if (set_qgroup_type || inherit)
printf("Set qgroup arguments:\n");
+
+ if (set_qgroup_type) {
+ if (qgroup_type != 0) {
+ printf("\tqgroup type: ");
+ if (qgroup_type & BTRFS_QGROUP_TYPE_METADATA)
+ printf("metadata ");
+ if (qgroup_type & BTRFS_QGROUP_TYPE_DATA)
+ printf("data");
+ printf("\n");
+ }
+ }
+ if (inherit) {
if (inherit->num_qgroups > 0) {
__u64 index;
__u64 qgroupid;
@@ -168,7 +197,11 @@ static int cmd_subvol_create(int argc, char **argv)
printf("\tmax exclusive: %llu\n",
inherit->lim.max_exclusive);
}
+ }
+ if (inherit || set_qgroup_type) {
+ struct btrfs_ioctl_vol_args_v2 args;
+ struct btrfs_ioctl_quota_ctl_args sa;
sa.cmd = BTRFS_QUOTA_CTL_STATUS;
res = ioctl(fddst, BTRFS_IOC_QUOTA_CTL, &sa);
if (res < 0) {
@@ -185,9 +218,12 @@ static int cmd_subvol_create(int argc, char **argv)
memset(&args, 0, sizeof(args));
strncpy_null(args.name, newname);
- args.flags |= BTRFS_SUBVOL_QGROUP_INHERIT;
- args.size = qgroup_inherit_size(inherit);
- args.qgroup_inherit = inherit;
+ if (inherit != NULL) {
+ args.flags |= BTRFS_SUBVOL_QGROUP_INHERIT;
+ args.size = qgroup_inherit_size(inherit);
+ args.qgroup_inherit = inherit;
+ }
+ args.qgroup_type = qgroup_type;
res = ioctl(fddst, BTRFS_IOC_SUBVOL_CREATE_V2, &args);
} else {
diff --git a/qgroup.c b/qgroup.c
index 8a7c20f..a647925 100644
--- a/qgroup.c
+++ b/qgroup.c
@@ -1483,3 +1483,18 @@ int qgroup_inherit_set_maxexcl(struct btrfs_qgroup_inherit **inherit, char *arg)
(*inherit)->lim.max_exclusive = size;
return 0;
}
+
+int btrfs_qgroup_set_qgroup_type(__u8 *qgroup_type, char *arg)
+{
+ if (strcmp(arg, "metadata") == 0)
+ *qgroup_type = BTRFS_QGROUP_TYPE_METADATA;
+ else if (strcmp(arg, "data") == 0)
+ *qgroup_type = BTRFS_QGROUP_TYPE_DATA;
+ else if (strcmp(arg, "mixed") == 0) {
+ *qgroup_type = BTRFS_QGROUP_TYPE_MIXED;
+ } else {
+ fprintf(stderr, "ERROR: Invalid qgroup type arguments given\n");
+ return -EINVAL;
+ }
+ return 0;
+}
diff --git a/qgroup.h b/qgroup.h
index 421eb42..8423fdf 100644
--- a/qgroup.h
+++ b/qgroup.h
@@ -109,6 +109,7 @@ void btrfs_qgroup_free_comparer_set(struct btrfs_qgroup_comparer_set *comp_set);
int btrfs_qgroup_setup_comparer(struct btrfs_qgroup_comparer_set **comp_set,
enum btrfs_qgroup_comp_enum comparer,
int is_descending);
+int btrfs_qgroup_set_qgroup_type(__u8 *qgroup_type, char *arg);
u64 parse_qgroupid(char *p);
int parse_limit(const char *p, unsigned long long *s);
int qgroup_inherit_size(struct btrfs_qgroup_inherit *p);
--
1.8.4.2
next prev parent reply other threads:[~2015-02-10 10:27 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-10 10:24 [RFC PATCH 0/7] Btrfs: qgroup: part-4: Add type to btrfs qgroup Dongsheng Yang
2015-02-10 10:24 ` [PATCH 1/4] btrfs-progs: Add type to qgroup Dongsheng Yang
2015-02-10 10:24 ` [PATCH 1/7] Btrfs: qgroup: Add type to btrfs_qgroup Dongsheng Yang
2015-02-10 10:24 ` Dongsheng Yang [this message]
2015-02-10 10:24 ` [PATCH 2/7] btrfs: qgroup: apply type to the recording and accounting Dongsheng Yang
2015-02-10 10:24 ` [PATCH 3/4] btrfs-progs:specify qgroup type when creating qgroup Dongsheng Yang
2015-02-10 10:24 ` [PATCH 3/7] btrfs: qgroup: Apply type to btrfs_qgroup_inherit() Dongsheng Yang
2015-02-10 10:24 ` [PATCH 4/4] btrfs-progs:show qgroup type Dongsheng Yang
2015-02-10 10:24 ` [PATCH 4/7] btrfs: qgroup: Apply qgroup type to qgroup creating Dongsheng Yang
2015-02-10 10:24 ` [PATCH 5/7] btrfs: qgroup: Apply qgroup type to subvol creating Dongsheng Yang
2015-02-10 10:24 ` [PATCH 6/7] btrfs: qgroup: apply type to quota rescan Dongsheng Yang
2015-02-10 10:24 ` [PATCH 7/7] btrfs: qgroup: fix a bug when type of parent is different with child's Dongsheng Yang
2015-03-04 1:49 ` [RFC PATCH 0/7] Btrfs: qgroup: part-4: Add type to btrfs qgroup Dongsheng Yang
2015-03-17 10:08 ` Dongsheng Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1423563862-9151-4-git-send-email-yangds.fnst@cn.fujitsu.com \
--to=yangds.fnst@cn.fujitsu.com \
--cc=fancn.fnst@cn.fujitsu.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).