From patchwork Sat May 20 08:39:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sargun Dhillon X-Patchwork-Id: 9738527 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 49C3F6034C for ; Sat, 20 May 2017 08:39:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3EF99285C8 for ; Sat, 20 May 2017 08:39:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 34209285D4; Sat, 20 May 2017 08:39:33 +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 97C19285C8 for ; Sat, 20 May 2017 08:39:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755665AbdETIj3 (ORCPT ); Sat, 20 May 2017 04:39:29 -0400 Received: from mail-it0-f44.google.com ([209.85.214.44]:38663 "EHLO mail-it0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755650AbdETIjY (ORCPT ); Sat, 20 May 2017 04:39:24 -0400 Received: by mail-it0-f44.google.com with SMTP id r63so1904880itc.1 for ; Sat, 20 May 2017 01:39:24 -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=dT/O7xrdy7EaJEsvtqcDdyXfSmgHONhH383faM8/XLA=; b=P+JGBGtBOwEHOnfv7NXiakAkw5gpsdeFvROokLlk1BNN0wDsOsoM5/sAFg98ewyjrn vuQsRaPa0oaDBg6FfShExtPV2d/7kvy+6qDV16EPEV2sCuH0DnLlwIbV4Fwi8z5X8Ua1 BE0t/WNlaOueU9Pq9Snr6/+xeBPnBq/rYGYcY= 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=dT/O7xrdy7EaJEsvtqcDdyXfSmgHONhH383faM8/XLA=; b=l7ZHfDPfargEke6onzB977LKz0LFSdbbk4QRBpffG7fauPPv5fDYeQoqhpoPVt7EIq Pm0TRbSo3P8mGPhriI56akLVgdZvQTWOQpCwUyGvTI18Qy/H39b1nljjHz55kjQY7I1x FMxM5Y8SO++khp53mjXm4OnCkzOkn/sSJan3L637tWXrYNAC/Q3r1iavMpMueBH3ZG7T DZL2NAvCGFe9+52Kjwm4OWqaWxoDQpV1k7CQQzviVeYTgve4606MUmqifG7/byHJ9LIw yjeQUzcX0olPq90vdyVmCwt0wDSYV+Uh3bZw8NFCWEDz9vbS4nW3g1abR5SSWkj02m7E 3WMg== X-Gm-Message-State: AODbwcC5KG+5igHycagNv+oHnSPQhw207OOwW41wvFOdJhWeOT2VJyTR fMGfb3q0ZIsJdzLB19Dc5A== X-Received: by 10.36.163.131 with SMTP id p125mr33336333ite.105.1495269563185; Sat, 20 May 2017 01:39:23 -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 e191sm11276495ita.9.2017.05.20.01.39.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 20 May 2017 01:39:23 -0700 (PDT) Date: Sat, 20 May 2017 08:39:21 +0000 From: Sargun Dhillon To: linux-btrfs@vger.kernel.org Subject: [PATCH 4/8] btrfs: autoremove qgroup by default, and add a mount flag to override Message-ID: <20170520083920.GA4222@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 change follows the change to automatically remove qgroups if the associated subvolume has also been removed. It changes the default behaviour to automatically remove qgroups when a subvolume is deleted, but this can be override with the qgroup_keep mount flag. Signed-off-by: Sargun Dhillon --- fs/btrfs/ctree.h | 1 + fs/btrfs/ioctl.c | 14 ++++++++++++++ fs/btrfs/super.c | 16 +++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 643c70d..4d57eb6 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -1348,6 +1348,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_KEEP (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 e176375..b10d7bb 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2544,6 +2544,20 @@ static noinline int btrfs_ioctl_snap_destroy(struct file *file, } } + /* + * 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, and potentially + * leave the filesystem in an awkward, (but working) state. + */ + if (!btrfs_test_opt(fs_info, QGROUP_KEEP)) { + ret = btrfs_remove_qgroup(trans, fs_info, + dest->root_key.objectid); + if (ret && ret != -ENOENT) + pr_info("Could not automatically delete qgroup: %d\n", ret); + } out_end_trans: trans->block_rsv = NULL; trans->bytes_reserved = 0; diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 4f1cdd5..232e1b8 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -321,7 +321,7 @@ 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_keep, Opt_qgroup_nokeep, #ifdef CONFIG_BTRFS_DEBUG Opt_fragment_data, Opt_fragment_metadata, Opt_fragment_all, #endif @@ -381,6 +381,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_keep, "qgroup_keep"}, + {Opt_qgroup_nokeep, "qgroup_nokeep"}, #ifdef CONFIG_BTRFS_DEBUG {Opt_fragment_data, "fragment=data"}, {Opt_fragment_metadata, "fragment=metadata"}, @@ -808,6 +810,14 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options, info->commit_interval = BTRFS_DEFAULT_COMMIT_INTERVAL; } break; + case Opt_qgroup_keep: + btrfs_set_and_info(info, QGROUP_KEEP, + "do not automatically delete qgroups"); + break; + case Opt_qgroup_nokeep: + btrfs_clear_and_info(info, QGROUP_KEEP, + "automatically delete qgroups"); + break; #ifdef CONFIG_BTRFS_DEBUG case Opt_fragment_all: btrfs_info(info, "fragmenting all space"); @@ -1299,6 +1309,10 @@ 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_KEEP)) + seq_puts(seq, ",qgroup_keep"); + else + seq_puts(seq, ",qgroup_nokeep"); #ifdef CONFIG_BTRFS_DEBUG if (btrfs_test_opt(info, FRAGMENT_DATA)) seq_puts(seq, ",fragment=data");