From patchwork Wed Apr 18 02:35:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Misono Tomohiro X-Patchwork-Id: 10347143 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 2AC3560216 for ; Wed, 18 Apr 2018 02:35:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BB1628448 for ; Wed, 18 Apr 2018 02:35:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1083E2847E; Wed, 18 Apr 2018 02:35:45 +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 6DF6228448 for ; Wed, 18 Apr 2018 02:35:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753244AbeDRCfm (ORCPT ); Tue, 17 Apr 2018 22:35:42 -0400 Received: from mgwym02.jp.fujitsu.com ([211.128.242.41]:52411 "EHLO mgwym02.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753002AbeDRCfl (ORCPT ); Tue, 17 Apr 2018 22:35:41 -0400 Received: from yt-mxoi1.gw.nic.fujitsu.com (unknown [192.168.229.67]) by mgwym02.jp.fujitsu.com with smtp id 5d20_5d23_65b0a254_1597_4eed_bda9_7d23e4b0da64; Wed, 18 Apr 2018 11:35:37 +0900 Received: from g01jpfmpwkw03.exch.g01.fujitsu.local (g01jpfmpwkw03.exch.g01.fujitsu.local [10.0.193.57]) by yt-mxoi1.gw.nic.fujitsu.com (Postfix) with ESMTP id 62F8AAC00F2 for ; Wed, 18 Apr 2018 11:35:36 +0900 (JST) Received: from g01jpexchkw36.g01.fujitsu.local (unknown [10.0.193.4]) by g01jpfmpwkw03.exch.g01.fujitsu.local (Postfix) with ESMTP id 404CBBD6732 for ; Wed, 18 Apr 2018 11:35:35 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v2.5.2 X-SHieldMailCheckerPolicyVersion: FJ-ISEC-20170217-enc X-SHieldMailCheckerMailID: c0b918bc079e4ff19c31534595d69b1e Subject: [PATCH v5 3/3] btrfs: Allow rmdir(2) to delete an empty subvolume From: Misono Tomohiro To: linux-btrfs References: <558a949c-ceb5-115d-744f-80fac2620f7d@jp.fujitsu.com> Message-ID: Date: Wed, 18 Apr 2018 11:35:31 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <558a949c-ceb5-115d-744f-80fac2620f7d@jp.fujitsu.com> 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 Change the behavior of rmdir(2) and allow it to delete an empty subvolume by using btrfs_delete_subvolume() which is used by btrfs_ioctl_snap_destroy(). The required lock for @dir and inode of @dentry is already acquired in vfs layer. We need some check before deleting a subvolume. Permission check is done in vfs layer, emptiness check is in btrfs_rmdir() and additional check (i.e. neither the subvolume is a default subvolume nor send is in progress) is in btrfs_delete_subvolume(). Note that in btrfs_ioctl_snap_destroy(), d_delete() is called after btrfs_delete_subvolume(). For rmdir(2), d_delete() is called in vfs layer later. Tested-by: Goffredo Baroncelli Signed-off-by: Tomohiro Misono --- fs/btrfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index b421aa8dd1a4..231e4c2ea1b4 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -4522,7 +4522,7 @@ static int btrfs_rmdir(struct inode *dir, struct dentry *dentry) if (inode->i_size > BTRFS_EMPTY_DIR_SIZE) return -ENOTEMPTY; if (btrfs_ino(BTRFS_I(inode)) == BTRFS_FIRST_FREE_OBJECTID) - return -EPERM; + return btrfs_delete_subvolume(dir, dentry); trans = __unlink_start_trans(dir); if (IS_ERR(trans))