From patchwork Wed Jun 28 21:51:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sargun Dhillon X-Patchwork-Id: 9815551 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D76A5603F2 for ; Wed, 28 Jun 2017 21:51:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C906F27968 for ; Wed, 28 Jun 2017 21:51:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDBE328384; Wed, 28 Jun 2017 21:51:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7C9127968 for ; Wed, 28 Jun 2017 21:51:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751659AbdF1Vvj (ORCPT ); Wed, 28 Jun 2017 17:51:39 -0400 Received: from mail-io0-f182.google.com ([209.85.223.182]:36482 "EHLO mail-io0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751574AbdF1Vva (ORCPT ); Wed, 28 Jun 2017 17:51:30 -0400 Received: by mail-io0-f182.google.com with SMTP id z62so43527244ioi.3 for ; Wed, 28 Jun 2017 14:51:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=fvJ5iboRf7AtPcqGh8XTYGykCsVq8CNlhp8E7+aI8HQ=; b=WmNzjsA+ZdL1jMkhS0NMO9coQ81wLvKW1ok3k6Boj1/F9We0hNxGTfl/G2bEn8hgoz 6DfbgMEoBAHDkc2qKN/hW5hFeMU6dEuJov227twlv6FYaTe8Cd/SbI1HBltr9EBj0zmo rudbD6LQ2KLOikfxV5wI6JoZ+aIvgexSAAm6w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-disposition:user-agent; bh=fvJ5iboRf7AtPcqGh8XTYGykCsVq8CNlhp8E7+aI8HQ=; b=CsxIdVGrVAW1/hp/eNo6o2KAGsjAu5KowWLtq+SRuRRJ+SfozhAEU2OWyHjN8Z50t2 3ml0IGuNIYUFKKPkQ46utaLFUAVV1NoLANi2rhzbBKpB7/7LyppuLcCwGjoCgPkr8jx+ YfwfSG6FaHRZZhP+WvfwP98njoFkXbW6bFpHiSmGGlv/ZJ7l2j/y1vFpxCT1QAp8C8/R yvkupM/ysaaYv9miJtNhkPCSo/5+3XGdw6nNI7bkBSmk04RuF48tFcmw63T+lDOvySHT NswhkmVZnBqmvGJOWLvrlbnkOJvp7PCKImT4x5AjQczjkmemYgtgf6k3TlTRe5V7fKMJ v3Gg== X-Gm-Message-State: AKS2vOzIZnHMSm+jS94i9U32mnh43jXOf/3a2q8s0M1EJcQRPr4HkASC ock0U6L2NpAKBPHzNt1W+w== X-Received: by 10.107.46.143 with SMTP id u15mr12773721iou.169.1498686688887; Wed, 28 Jun 2017 14:51:28 -0700 (PDT) Received: from ircssh-2.c.rugged-nimbus-611.internal (80.60.198.104.bc.googleusercontent.com. [104.198.60.80]) by smtp.gmail.com with ESMTPSA id j12sm1779243iod.12.2017.06.28.14.51.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Jun 2017 14:51:28 -0700 (PDT) Date: Wed, 28 Jun 2017 21:51:27 +0000 From: Sargun Dhillon To: linux-btrfs@vger.kernel.org Subject: [PATCH] btrfs: Add qgroup_auto_cleanup mount flag to automatically cleanup qgroups Message-ID: <20170628215125.GA23319@ircssh-2.c.rugged-nimbus-611.internal> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch introduces a new mount option - qgroup_auto_cleanup. The purpose of this mount option is to cause btrfs to automatically delete qgroups on subvolume deletion. This only cleans up the associated level-0 qgroup, and not qgroups that are above it. Since this behaviour is API-changing it is opt-in. Existing software, and scripts may be doing qgroup cleanup on subvolume deletion explicitly, and the absence of a qgroup may cause failure. Signed-off-by: Sargun Dhillon --- fs/btrfs/ctree.h | 1 + fs/btrfs/ioctl.c | 15 +++++++++++++++ fs/btrfs/super.c | 15 ++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 5bdd3666..b3d54e4 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1336,6 +1336,7 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info) #define BTRFS_MOUNT_FRAGMENT_METADATA (1 << 25) #define BTRFS_MOUNT_FREE_SPACE_TREE (1 << 26) #define BTRFS_MOUNT_NOLOGREPLAY (1 << 27) +#define BTRFS_MOUNT_QGROUP_AUTO_CLEANUP (1 << 28) #define BTRFS_DEFAULT_COMMIT_INTERVAL (30) #define BTRFS_DEFAULT_MAX_INLINE (2048) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index fa1b78c..e9901c4 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2546,6 +2546,21 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, goto out_end_trans; } } + /* + * Attempt to automatically remove the automatically attached qgroup + * setup in btrfs_qgroup_inherit. As a matter of convention, the id + * is the same as the subvolume id. + * + * This can fail non-fatally for level 0 qgroups, therefore we do + * not abort the transaction if this fails, nor return an error. + */ + if (btrfs_test_opt(fs_info, QGROUP_AUTO_CLEANUP)) { + ret = btrfs_remove_qgroup(trans, fs_info, + dest->root_key.objectid, 0); + if (ret && ret != -ENOENT) + btrfs_warn(fs_info, + "Failed to cleanup qgroup. err: %d", ret); + } out_end_trans: trans->block_rsv = NULL; diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 74e4779..d83c841 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -321,7 +321,8 @@ enum { Opt_commit_interval, Opt_barrier, Opt_nodefrag, Opt_nodiscard, Opt_noenospc_debug, Opt_noflushoncommit, Opt_acl, Opt_datacow, Opt_datasum, Opt_treelog, Opt_noinode_cache, Opt_usebackuproot, - Opt_nologreplay, Opt_norecovery, + Opt_nologreplay, Opt_norecovery, Opt_qgroup_auto_cleanup, + Opt_no_qgroup_auto_cleanup, #ifdef CONFIG_BTRFS_DEBUG Opt_fragment_data, Opt_fragment_metadata, Opt_fragment_all, #endif @@ -381,6 +382,8 @@ static const match_table_t tokens = { {Opt_rescan_uuid_tree, "rescan_uuid_tree"}, {Opt_fatal_errors, "fatal_errors=%s"}, {Opt_commit_interval, "commit=%d"}, + {Opt_qgroup_auto_cleanup, "qgroup_auto_cleanup"}, + {Opt_no_qgroup_auto_cleanup, "no_qgroup_auto_cleanup"}, #ifdef CONFIG_BTRFS_DEBUG {Opt_fragment_data, "fragment=data"}, {Opt_fragment_metadata, "fragment=metadata"}, @@ -798,6 +801,14 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; } break; + case Opt_qgroup_auto_cleanup: + btrfs_set_and_info(info, QGROUP_AUTO_CLEANUP, + "enabling qgroup auto cleanup"); + break; + case Opt_no_qgroup_auto_cleanup: + btrfs_clear_and_info(info, QGROUP_AUTO_CLEANUP, + "disabling qgroup auto cleanup"); + break; #ifdef CONFIG_BTRFS_DEBUG case Opt_fragment_all: btrfs_info(info, "fragmenting all space"); @@ -1287,6 +1298,8 @@ static int btrfs_show_options(struct seq_file *seq, struct dentry *dentry) seq_puts(seq, ",fatal_errors=panic"); if (info->commit_interval != BTRFS_DEFAULT_COMMIT_INTERVAL) seq_printf(seq, ",commit=%d", info->commit_interval); + if (btrfs_test_opt(info, QGROUP_AUTO_CLEANUP)) + seq_puts(seq, ",qgroup_auto_cleanup"); #ifdef CONFIG_BTRFS_DEBUG if (btrfs_test_opt(info, FRAGMENT_DATA)) seq_puts(seq, ",fragment=data");