2 # FS QA Test No. btrfs/085
4 # Tests to ensure that orphan items are properly created and cleaned up
7 # There are three cases where orphan items may be cleaned up:
8 # 1) Default subvolume is fs tree root (mkfs default)
9 # 2) Default subvolume is explicitly created subvolume
10 # (i.e. btrfs subvol set-default)
11 # 3) Non-default subvolume lookup
13 #-----------------------------------------------------------------------
14 # Copyright (c) 2015 SUSE. All Rights Reserved.
16 # This program is free software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License as
18 # published by the Free Software Foundation.
20 # This program is distributed in the hope that it would be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 # GNU General Public License for more details.
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write the Free Software Foundation,
27 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #-----------------------------------------------------------------------
33 seqres=$RESULT_DIR/$seq
34 echo "QA output created by $seq"
38 status=1 # failure is the default!
46 trap "_cleanup ; exit \$status" 0 1 2 3 15
48 # get standard environment, filters and checks
53 # real QA test starts here
57 _require_dm_target flakey
59 BTRFS_DEBUG_TREE_PROG="`set_prog_path btrfs-debug-tree`"
60 _require_command "$BTRFS_DEBUG_TREE_PROG" btrfs-debug-tree
67 if $BTRFS_DEBUG_TREE_PROG $SCRATCH_DEV | \
68 grep -q "key (ORPHAN ORPHAN_ITEM $INO)"; then
79 _scratch_mkfs >> $seqres.full 2>&1
86 TESTPATH=$SCRATCH_MNT/testdir/testfile
87 DIR=$(dirname $TESTPATH)
89 [ -d "$DIR" ] || mkdir -p $DIR
91 SIZE=$(( 1024 * 1024 ))
92 run_check dd if=/dev/zero of=$TESTPATH bs=$SIZE count=1
94 INO=$(stat -c %i $TESTPATH)
96 # Orphan item won't be created if the file doesn't make it to disk
99 # Open and delete the file
103 # Ensure the unlink (and orphan item creation) hits the disk
106 # Turn off writes before closing so the orphan item will be left behind
107 _load_flakey_table $FLAKEY_DROP_WRITES
109 # Close the file so we can umount
112 # Orphan item should be on disk if operating correctly
114 _load_flakey_table $FLAKEY_ALLOW_WRITES
115 if ! has_orphan_item $INO; then
116 echo "ERROR: No orphan item found after umount."
121 # If $DIR is a subvolume, this will cause a lookup and orphan cleanup
124 # Orphan item will be cleaned up during mount but won't be on
125 # disk until there's a sync.
129 if has_orphan_item $INO; then
130 echo "ERROR: Orphan item found after successful mount/sync."
137 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/testdir
143 SUB=$($BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT |awk '{print $2}')
144 _run_btrfs_util_prog subvolume set-default $SUB $SCRATCH_MNT
150 echo "Testing with fs root as default subvolume"
153 echo "Testing with explicit default subvolume"
154 test_orphan new_default
156 echo "Testing with orphan on non-default subvolume"
157 test_orphan new_subvolume