From patchwork Fri Aug 3 06:21:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Misono Tomohiro X-Patchwork-Id: 10554587 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0936F1822 for ; Fri, 3 Aug 2018 06:22:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E8F732BFB7 for ; Fri, 3 Aug 2018 06:22:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DCFA22BFEF; Fri, 3 Aug 2018 06:22:03 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 57DAA2BFB7 for ; Fri, 3 Aug 2018 06:22:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727610AbeHCIQp (ORCPT ); Fri, 3 Aug 2018 04:16:45 -0400 Received: from mgwkm04.jp.fujitsu.com ([202.219.69.171]:64189 "EHLO mgwkm04.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727457AbeHCIQp (ORCPT ); Fri, 3 Aug 2018 04:16:45 -0400 Received: from kw-mxauth.gw.nic.fujitsu.com (unknown [192.168.231.132]) by mgwkm04.jp.fujitsu.com with smtp id 0ac0_8ba2_e47bf41e_035e_4c0c_8883_f2a2af380d0f; Fri, 03 Aug 2018 15:21:53 +0900 Received: from g01jpfmpwyt01.exch.g01.fujitsu.local (g01jpfmpwyt01.exch.g01.fujitsu.local [10.128.193.38]) by kw-mxauth.gw.nic.fujitsu.com (Postfix) with ESMTP id CBE89AC01E3 for ; Fri, 3 Aug 2018 15:21:51 +0900 (JST) Received: from g01jpexchyt36.g01.fujitsu.local (unknown [10.128.193.4]) by g01jpfmpwyt01.exch.g01.fujitsu.local (Postfix) with ESMTP id E0D246D688F for ; Fri, 3 Aug 2018 15:21:50 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v2.5.2 X-SHieldMailCheckerPolicyVersion: FJ-ISEC-20170217-enc X-SHieldMailCheckerMailID: 32c5bca870c54e6fb7c9134de83db979 Subject: [PATCH v2] btrfs: qgroup: Remove qgroup item along with subvolume deletion From: Misono Tomohiro To: linux-btrfs References: Message-ID: <9e46637d-f717-7210-06e2-a077a58d9638@jp.fujitsu.com> Date: Fri, 3 Aug 2018 15:21:12 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-SecurityPolicyCheck-GC: OK by FENCE-Mail X-TM-AS-MML: disable 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 When qgroup is on, subvolume deletion does not remove qgroup item of the subvolume (qgroup info, limits, relation) from quota tree and they needs to get removed manually by "btrfs qgroup destroy". Since level 0 qgroup cannot be used/inherited by any other subvolume, let's remove them automatically when subvolume is deleted (to be precise, when the subvolume root is dropped). Signed-off-by: Misono Tomohiro Reviewed-by: Lu Fengqi Reviewed-by: Qu Wenruo --- Note that btrfs/057 fails, but it is the problem of testcase. I will update it too. v1 -> v2: Move call of btrfs_remove_qgroup() from btrfs_delete_subvolume() to btrfs_snapshot_destroy() so that it will be called after the subvolume root is really dropped fs/btrfs/extent-tree.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 9e7b237b9547..b56dea8c8b9f 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -8871,12 +8871,13 @@ int btrfs_drop_snapshot(struct btrfs_root *root, struct btrfs_root_item *root_item = &root->root_item; struct walk_control *wc; struct btrfs_key key; + u64 objectid = root->objectid; int err = 0; int ret; int level; bool root_dropped = false; - btrfs_debug(fs_info, "Drop subvolume %llu", root->objectid); + btrfs_debug(fs_info, "Drop subvolume %llu", objectid); path = btrfs_alloc_path(); if (!path) { @@ -9030,7 +9031,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root, goto out_end_trans; } - if (root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID) { + if (objectid != BTRFS_TREE_RELOC_OBJECTID) { ret = btrfs_find_root(tree_root, &root->root_key, path, NULL, NULL); if (ret < 0) { @@ -9043,8 +9044,7 @@ int btrfs_drop_snapshot(struct btrfs_root *root, * * The most common failure here is just -ENOENT. */ - btrfs_del_orphan_item(trans, tree_root, - root->root_key.objectid); + btrfs_del_orphan_item(trans, tree_root, objectid); } } @@ -9056,6 +9056,14 @@ int btrfs_drop_snapshot(struct btrfs_root *root, btrfs_put_fs_root(root); } root_dropped = true; + + /* Remove level-0 qgroup items since no other subvolume can use them */ + ret = btrfs_remove_qgroup(trans, objectid); + if (ret && ret != -EINVAL && ret != -ENOENT) { + btrfs_abort_transaction(trans, ret); + err = ret; + } + out_end_trans: btrfs_end_transaction_throttle(trans); out_free: