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
60 BTRFS_DEBUG_TREE_PROG="`set_prog_path btrfs-debug-tree`"
61 _require_command "$BTRFS_DEBUG_TREE_PROG" btrfs-debug-tree
68 if $BTRFS_DEBUG_TREE_PROG $SCRATCH_DEV | \
69 grep -q "key (ORPHAN ORPHAN_ITEM $INO)"; then
80 _scratch_mkfs >> $seqres.full 2>&1
87 TESTPATH=$SCRATCH_MNT/testdir/testfile
88 DIR=$(dirname $TESTPATH)
90 [ -d "$DIR" ] || mkdir -p $DIR
92 SIZE=$(( 1024 * 1024 ))
93 run_check dd if=/dev/zero of=$TESTPATH bs=$SIZE count=1
95 INO=$(stat -c %i $TESTPATH)
97 # Orphan item won't be created if the file doesn't make it to disk
100 # Open and delete the file
104 # Ensure the unlink (and orphan item creation) hits the disk
107 # Turn off writes before closing so the orphan item will be left behind
108 _load_flakey_table $FLAKEY_DROP_WRITES
110 # Close the file so we can umount
113 # Orphan item should be on disk if operating correctly
115 _load_flakey_table $FLAKEY_ALLOW_WRITES
116 if ! has_orphan_item $INO; then
117 echo "ERROR: No orphan item found after umount."
122 # If $DIR is a subvolume, this will cause a lookup and orphan cleanup
125 # Orphan item will be cleaned up during mount but won't be on
126 # disk until there's a sync.
130 if has_orphan_item $INO; then
131 echo "ERROR: Orphan item found after successful mount/sync."
138 _run_btrfs_util_prog subvol create $SCRATCH_MNT/testdir
144 SUB=$($BTRFS_UTIL_PROG subvol list $SCRATCH_MNT |awk '{print $2}')
145 _run_btrfs_util_prog subvol set-default $SUB $SCRATCH_MNT
151 echo "Testing with fs root as default subvolume"
154 echo "Testing with explicit default subvolume"
155 test_orphan new_default
157 echo "Testing with orphan on non-default subvolume"
158 test_orphan new_subvolume