From patchwork Thu Mar 19 06:00:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Dongsheng X-Patchwork-Id: 6046741 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 99B6FBF90F for ; Thu, 19 Mar 2015 06:05:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A49D2204A2 for ; Thu, 19 Mar 2015 06:05:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BBA162049D for ; Thu, 19 Mar 2015 06:05:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751525AbbCSGE7 (ORCPT ); Thu, 19 Mar 2015 02:04:59 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:62294 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751380AbbCSGEz (ORCPT ); Thu, 19 Mar 2015 02:04:55 -0400 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="79802347" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 19 Mar 2015 14:01:12 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t2J63t3B029915; Thu, 19 Mar 2015 14:03:55 +0800 Received: from yds-PC.g08.fujitsu.local (10.167.226.66) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 19 Mar 2015 14:04:54 +0800 From: Dongsheng Yang To: , , , CC: Dongsheng Yang Subject: [PATCH 3/4] Btrfs-progs: qgroup: add a opt for type of qgroup limit. Date: Thu, 19 Mar 2015 14:00:58 +0800 Message-ID: <1426744864-7031-6-git-send-email-yangds.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.4.2 In-Reply-To: <1426744864-7031-1-git-send-email-yangds.fnst@cn.fujitsu.com> References: <1426744864-7031-1-git-send-email-yangds.fnst@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.66] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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;