linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>, <dsterba@suse.cz>, <jbacik@fb.com>,
	<clm@fb.com>
Cc: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Subject: [PATCH 3/4] Btrfs-progs: qgroup: add a opt for type of qgroup limit.
Date: Thu, 19 Mar 2015 14:00:58 +0800	[thread overview]
Message-ID: <1426744864-7031-6-git-send-email-yangds.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <1426744864-7031-1-git-send-email-yangds.fnst@cn.fujitsu.com>

This patch add a support for user to limit the data, metadata,
or mixed of a qgroup. Even you can set these three limits at
one time for a qgroup.

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
---
 cmds-qgroup.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
 ioctl.h       | 13 +++++++++++++
 2 files changed, 60 insertions(+), 1 deletion(-)

diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index c5082f7..1c42fc8 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -367,14 +367,46 @@ static const char * const cmd_qgroup_limit_usage[] = {
 	"-c   limit amount of data after compression. This is the default,",
 	"     it is currently not possible to turn off this option.",
 	"-e   limit space exclusively assigned to this qgroup",
+	"-t   limit space for data, metadata or mixed",
 	NULL
 };
 
+inline u8 get_limit_type(u64 flag)
+{
+	return (flag >> BTRFS_QGROUP_LIMIT_TYPE_SHIFT);
+}
+
+inline u64 set_limit_type(u64 flag, u8 type)
+{
+	u64 temp = (flag >> BTRFS_QGROUP_LIMIT_TYPE_SHIFT);
+
+	temp |= type;
+	flag |= (temp << BTRFS_QGROUP_LIMIT_TYPE_SHIFT);
+
+	return flag;
+}
+
+static int parse_limit_type(u8 *qgroup_type, char *arg)
+{
+	if (strcmp(arg, "data") == 0)
+		*qgroup_type = BTRFS_QGROUP_LIMIT_DATA;
+	else if (strcmp(arg, "metadata") == 0)
+		*qgroup_type = BTRFS_QGROUP_LIMIT_METADATA;
+	else if (strcmp(arg, "mixed") == 0) {
+		*qgroup_type = BTRFS_QGROUP_LIMIT_MIXED;
+	} else {
+		fprintf(stderr, "ERROR: Invalid qgroup type arguments given\n");
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static int cmd_qgroup_limit(int argc, char **argv)
 {
 	int ret = 0;
 	int fd;
 	int e;
+	u8 type = BTRFS_QGROUP_LIMIT_MIXED;
 	char *path = NULL;
 	struct btrfs_ioctl_qgroup_limit_args args;
 	unsigned long long size;
@@ -384,7 +416,14 @@ static int cmd_qgroup_limit(int argc, char **argv)
 
 	optind = 1;
 	while (1) {
-		int c = getopt(argc, argv, "ce");
+		int c;
+		static const struct option long_options[] = {
+			{"type", required_argument, NULL, 't'},
+			{NULL, 0, NULL, 0}
+		};
+
+		c = getopt_long(argc, argv, "ce",
+			long_options, NULL);
 		if (c < 0)
 			break;
 		switch (c) {
@@ -394,6 +433,11 @@ static int cmd_qgroup_limit(int argc, char **argv)
 		case 'e':
 			exclusive = 1;
 			break;
+		case 't':
+			ret = parse_limit_type(&type, optarg);
+			if (ret)
+				return -EINVAL;
+			break;
 		default:
 			usage(cmd_qgroup_limit_usage);
 		}
@@ -419,6 +463,8 @@ static int cmd_qgroup_limit(int argc, char **argv)
 			args.lim.flags |= BTRFS_QGROUP_LIMIT_MAX_RFER;
 			args.lim.max_referenced = size;
 		}
+
+		args.lim.flags = set_limit_type(args.lim.flags, type);
 	}
 
 	if (argc - optind == 2) {
diff --git a/ioctl.h b/ioctl.h
index d550ca6..a1ebbb5 100644
--- a/ioctl.h
+++ b/ioctl.h
@@ -45,6 +45,19 @@ struct btrfs_ioctl_vol_args {
 
 #define BTRFS_QGROUP_INHERIT_SET_LIMITS	(1ULL << 0)
 
+/*
+ * As we can account and limit data and metadata in
+ * a qgroup separately. We use the first 8 bits in
+ * btrfs_qgroup_limit->flags to specify the type we
+ * want to limit. Currently, there are three choice:
+ * DATA, METADATA, MIXED.
+ */
+#define BTRFS_QGROUP_LIMIT_TYPE_SHIFT	56
+
+#define BTRFS_QGROUP_LIMIT_DATA		1
+#define BTRFS_QGROUP_LIMIT_METADATA	2
+#define BTRFS_QGROUP_LIMIT_MIXED	4
+
 struct btrfs_qgroup_limit {
 	__u64	flags;
 	__u64	max_referenced;
-- 
1.8.4.2


  parent reply	other threads:[~2015-03-19  6:04 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-19  6:00 [PATCH 0/7 V2] Btrfs: qgroup: part-4: Add type to btrfs qgroup Dongsheng Yang
2015-03-19  6:00 ` [PATCH 1/4] Btrfs-progs: qgroup: add incompatability feature for QGROUP_TYPE Dongsheng Yang
2015-03-19  6:00 ` [PATCH 1/7] Btrfs: qgroup: split information and limits in qgroup to other structures Dongsheng Yang
2015-03-19  6:00 ` [PATCH 2/4] Btrfs-progs: qgroup: print info and limits type in btrfs-debug-tree Dongsheng Yang
2015-03-19  6:00 ` [PATCH 2/7] Btrfs: qgroup: add incompatability feature for QGROUP_TYPE Dongsheng Yang
2015-03-19  6:00 ` Dongsheng Yang [this message]
2015-03-19  6:00 ` [PATCH 3/7] Btrfs: qgroup: record and account ref for qgroup in different type Dongsheng Yang
2015-03-19  6:01 ` [PATCH 4/4] Btrfs-progs: qgroup: show specified quota data Dongsheng Yang
2015-03-19  6:01 ` [PATCH 4/7] Btrfs: qgroup: update all infos and limits to disk Dongsheng Yang
2015-03-19  6:01 ` [PATCH 5/7] Btrfs: qgroup: update quota numbers in btrfs_qgroup_inherit Dongsheng Yang
2015-03-19  6:01 ` [PATCH 6/7] Btrfs: qgroup: account data and metadata separately in rescan Dongsheng Yang
2015-03-19  6:01 ` [PATCH 7/7] Btrfs: qgroup: allow user to limit qgroup in different type 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=1426744864-7031-6-git-send-email-yangds.fnst@cn.fujitsu.com \
    --to=yangds.fnst@cn.fujitsu.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.cz \
    --cc=jbacik@fb.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).