From patchwork Thu Apr 19 07:23:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Misono Tomohiro X-Patchwork-Id: 10349227 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 6D49B60244 for ; Thu, 19 Apr 2018 07:25:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5383028789 for ; Thu, 19 Apr 2018 07:25:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4847C237F1; Thu, 19 Apr 2018 07:25: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 9EDFC237F1 for ; Thu, 19 Apr 2018 07:25:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752717AbeDSHZl (ORCPT ); Thu, 19 Apr 2018 03:25:41 -0400 Received: from mgwym03.jp.fujitsu.com ([211.128.242.42]:12369 "EHLO mgwym03.jp.fujitsu.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750716AbeDSHZj (ORCPT ); Thu, 19 Apr 2018 03:25:39 -0400 Received: from yt-mxoi2.gw.nic.fujitsu.com (unknown [192.168.229.69]) by mgwym03.jp.fujitsu.com with smtp id 28bb_434d_313e9b0f_fcae_4255_887c_2f8ae3fe5a19; Thu, 19 Apr 2018 16:25:32 +0900 Received: from g01jpfmpwkw02.exch.g01.fujitsu.local (g01jpfmpwkw02.exch.g01.fujitsu.local [10.0.193.56]) by yt-mxoi2.gw.nic.fujitsu.com (Postfix) with ESMTP id C5DAFAC019D; Thu, 19 Apr 2018 16:25:31 +0900 (JST) Received: from G01JPEXCHKW18.g01.fujitsu.local (G01JPEXCHKW18.g01.fujitsu.local [10.0.194.57]) by g01jpfmpwkw02.exch.g01.fujitsu.local (Postfix) with ESMTP id 109A63287B3; Thu, 19 Apr 2018 16:25:31 +0900 (JST) X-SecurityPolicyCheck: OK by SHieldMailChecker v2.5.2 X-SHieldMailCheckerPolicyVersion: FJ-ISEC-20170217-enc X-SHieldMailCheckerMailID: 1307c35e8a7a440aaaf2fbeb3febf647 From: Misono Tomohiro Subject: [PATCH] btrfs: Add test that checks rmdir(2) can delete a subvolume To: CC: linux-btrfs Message-ID: <2f99b131-7eb5-df33-12b9-f05a1468a710@jp.fujitsu.com> Date: Thu, 19 Apr 2018 16:23:35 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 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 Add btrfs test that checks "rmdir" or "rm -r" command can delete a subvolume like an ordinary drectory. This behavior has been restricted long time but becomes allowed by following patch in the kernel: btrfs: Allow rmdir(2) to delete an empty subvolume Signed-off-by: Tomohiro Misono --- tests/btrfs/159 | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/btrfs/159.out | 2 + tests/btrfs/group | 1 + 3 files changed, 143 insertions(+) create mode 100755 tests/btrfs/159 create mode 100644 tests/btrfs/159.out diff --git a/tests/btrfs/159 b/tests/btrfs/159 new file mode 100755 index 00000000..2d830502 --- /dev/null +++ b/tests/btrfs/159 @@ -0,0 +1,140 @@ +#! /bin/bash +# FS QA Test btrfs/159 +# +# QA test that checks rmdir(2) works for subvolumes like ordinary directories. +# +# This behavior has been restricted long time but becomes allowed by following +# patch in the kernel: +# btrfs: Allow rmdir(2) to delete an empty subvolume +# +#----------------------------------------------------------------------- +# Copyright (c) 2018 Fujitsu. All Rights Reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#----------------------------------------------------------------------- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* +} + +_create_subvol() +{ + $BTRFS_UTIL_PROG subvolume create $1 2>&1 | \ + _filter_scratch >> $seqres.full +} + +_create_snapshot() +{ + $BTRFS_UTIL_PROG subvolume snapshot $@ 2>&1 | \ + _filter_scratch >> $seqres.full +} + +_rmdir_subvol() +{ + rmdir $1 2>&1 | _filter_scratch + return ${PIPESTATUS[0]} +} + +_rm_r_subvol() { + rm -r $1 2>&1 | _filter_scratch + return ${PIPESTATUS[0]} +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/btrfs + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here + +# Modify as appropriate. +_supported_fs btrfs +_supported_os Linux +_require_scratch + +_scratch_mkfs > /dev/null 2>&1 || _fail "mkfs failed" +_scratch_mount + +# Check that an empty subvolume can be deleted by rmdir +_create_subvol $SCRATCH_MNT/sub1 +_rmdir_subvol $SCRATCH_MNT/sub1 + +# Check that non-empty subvolume cannot be deleted by rmdir +_create_subvol $SCRATCH_MNT/sub2 +touch $SCRATCH_MNT/sub2/file +_rmdir_subvol $SCRATCH_MNT/sub2 >> $seqres.full && \ + _fail "rmdir should fail for non-empty subvolume" +rm $SCRATCH_MNT/sub2/file +_rmdir_subvol $SCRATCH_MNT/sub2 + +# Check that read-only empty subvolume can be deleted by rmdir +_create_subvol $SCRATCH_MNT/sub3 +_create_snapshot -r $SCRATCH_MNT/sub3 $SCRATCH_MNT/snap +$BTRFS_UTIL_PROG property set $SCRATCH_MNT/sub3 ro true 2>&1 | \ + _filter_scratch >> $seqres.full +_rmdir_subvol $SCRATCH_MNT/sub3 +_rmdir_subvol $SCRATCH_MNT/snap + +# Check that the default subvolume cannot be deleted by rmdir +_create_subvol $SCRATCH_MNT/sub4 +subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT sub4) +$BTRFS_UTIL_PROG subvolume set-default $subvolid $SCRATCH_MNT 2>&1 | \ + _filter_scratch >> $seqres.full +_rmdir_subvol $SCRATCH_MNT/sub4 >> $seqres.full && \ + _fail "rmdir should fail for the default subvolume" + +# Check that subvolume stub (created by snapshot) can be deleted by rmdir +# (Note: this has been always allowed) +_create_subvol $SCRATCH_MNT/sub5 +_create_subvol $SCRATCH_MNT/sub5/sub6 +_create_snapshot $SCRATCH_MNT/sub5 $SCRATCH_MNT/snap2 +rmdir $SCRATCH_MNT/snap2/sub6 + +# Check that rm -r works for both non-snapshot subvolume and snapshot +_create_subvol $SCRATCH_MNT/sub7 +mkdir $SCRATCH_MNT/sub7/dir +_create_subvol $SCRATCH_MNT/sub7/dir/sub8 +touch $SCRATCH_MNT/sub7/dir/sub8/file + +_create_snapshot $SCRATCH_MNT/sub7 $SCRATCH_MNT/snap3 +_create_snapshot -r $SCRATCH_MNT/sub7 $SCRATCH_MNT/snap4 + +_rm_r_subvol $SCRATCH_MNT/sub7 +_rm_r_subvol $SCRATCH_MNT/snap3 +_rm_r_subvol $SCRATCH_MNT/snap4 >> $seqres.full && \ + _fail "rm -r should fail for non-empty readonly subvolume" + +$BTRFS_UTIL_PROG property set $SCRATCH_MNT/snap4 ro false 2>&1 | \ + _filter_scratch >> $seqres.full +_rm_r_subvol $SCRATCH_MNT/snap4 + +# success, all done +echo "Silence is golden" +status=0 +exit diff --git a/tests/btrfs/159.out b/tests/btrfs/159.out new file mode 100644 index 00000000..e569e60c --- /dev/null +++ b/tests/btrfs/159.out @@ -0,0 +1,2 @@ +QA output created by 159 +Silence is golden diff --git a/tests/btrfs/group b/tests/btrfs/group index 8007e07e..6a288285 100644 --- a/tests/btrfs/group +++ b/tests/btrfs/group @@ -161,3 +161,4 @@ 156 auto quick trim 157 auto quick raid 158 auto quick raid scrub +159 auto quick subvol