2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 Fujitsu. All Rights Reserved.
7 # QA test that checks rmdir(2) works for subvolumes like ordinary directories.
9 # This behavior has been restricted long time but becomes allowed by kernel
10 # commit a79a464d5675 ("btrfs: Allow rmdir(2) to delete an empty subvolume")
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
29 $BTRFS_UTIL_PROG subvolume create $1 >> $seqres.full 2>&1
34 $BTRFS_UTIL_PROG subvolume snapshot $@ >> $seqres.full 2>&1
39 rmdir $1 >> $seqres.full 2>&1
43 rm -r $1 >> $seqres.full 2>&1
46 # get standard environment, filters and checks
50 # remove previous $seqres.full before test
53 # real QA test starts here
57 _require_btrfs_fs_feature "rmdir_subvol"
59 _scratch_mkfs > /dev/null 2>&1 || _fail "mkfs failed"
62 # Check that an empty subvolume can be deleted by rmdir
63 create_subvol $SCRATCH_MNT/sub1
64 rmdir_subvol $SCRATCH_MNT/sub1 || \
65 echo "rmdir should delete an empty subvolume"
67 # Check that non-empty subvolume cannot be deleted by rmdir
68 create_subvol $SCRATCH_MNT/sub2
69 touch $SCRATCH_MNT/sub2/file
70 rmdir_subvol $SCRATCH_MNT/sub2 && \
71 echo "rmdir should fail for non-empty subvolume"
72 rm $SCRATCH_MNT/sub2/file
73 rmdir_subvol $SCRATCH_MNT/sub2 || \
74 echo "rmdir should delete an empty subvolume"
76 # Check that read-only empty subvolume can be deleted by rmdir
77 create_subvol $SCRATCH_MNT/sub3
78 create_snapshot -r $SCRATCH_MNT/sub3 $SCRATCH_MNT/snap
79 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/sub3 ro true >> $seqres.full 2>&1
80 rmdir_subvol $SCRATCH_MNT/sub3 || \
81 echo "rmdir should delete an empty subvolume"
82 rmdir_subvol $SCRATCH_MNT/snap || \
83 echo "rmdir should delete a readonly empty subvolume"
85 # Check that the default subvolume cannot be deleted by rmdir
86 create_subvol $SCRATCH_MNT/sub4
87 subvolid=$(_btrfs_get_subvolid $SCRATCH_MNT sub4)
88 $BTRFS_UTIL_PROG subvolume set-default $subvolid $SCRATCH_MNT \
90 rmdir_subvol $SCRATCH_MNT/sub4 && \
91 echo "rmdir should fail for the default subvolume"
93 # Check that subvolume stub (created by snapshot) can be deleted by rmdir
94 # (Note: this has been always allowed)
95 create_subvol $SCRATCH_MNT/sub5
96 create_subvol $SCRATCH_MNT/sub5/sub6
97 create_snapshot $SCRATCH_MNT/sub5 $SCRATCH_MNT/snap2
98 rmdir $SCRATCH_MNT/snap2/sub6 || \
99 echo "rmdir should delete a subvolume stub (ino number == 2)"
101 # Check that rm -r works for both non-snapshot subvolume and snapshot
102 create_subvol $SCRATCH_MNT/sub7
103 mkdir $SCRATCH_MNT/sub7/dir
104 create_subvol $SCRATCH_MNT/sub7/dir/sub8
105 touch $SCRATCH_MNT/sub7/dir/sub8/file
107 create_snapshot $SCRATCH_MNT/sub7 $SCRATCH_MNT/snap3
108 create_snapshot -r $SCRATCH_MNT/sub7 $SCRATCH_MNT/snap4
110 rm_r_subvol $SCRATCH_MNT/sub7 || \
111 echo "rm -r should delete subvolumes recursively"
112 rm_r_subvol $SCRATCH_MNT/snap3 || \
113 echo "rm -r should delete subvolumes recursively"
114 rm_r_subvol $SCRATCH_MNT/snap4 && \
115 echo "rm -r should fail for non-empty readonly subvolume"
117 $BTRFS_UTIL_PROG property set $SCRATCH_MNT/snap4 ro false >> $seqres.full 2>&1
118 rm_r_subvol $SCRATCH_MNT/snap4 || \
119 echo "rm -r should delete subvolumes recursively"
122 echo "Silence is golden"