2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 SUSE. All Rights Reserved.
5 # FS QA Test No. btrfs/085
7 # Tests to ensure that orphan items are properly created and cleaned up
10 # There are three cases where orphan items may be cleaned up:
11 # 1) Default subvolume is fs tree root (mkfs default)
12 # 2) Default subvolume is explicitly created subvolume
13 # (i.e. btrfs subvol set-default)
14 # 3) Non-default subvolume lookup
17 seqres=$RESULT_DIR/$seq
18 echo "QA output created by $seq"
22 status=1 # failure is the default!
30 trap "_cleanup ; exit \$status" 0 1 2 3 15
32 # get standard environment, filters and checks
37 # real QA test starts here
40 _require_dm_target flakey
41 _require_btrfs_command inspect-internal dump-tree
48 if $BTRFS_UTIL_PROG inspect-internal dump-tree $FLAKEY_DEV | \
49 grep -q "key (ORPHAN ORPHAN_ITEM $INO)"; then
60 _scratch_mkfs >> $seqres.full 2>&1
67 TESTPATH=$SCRATCH_MNT/testdir/testfile
68 DIR=$(dirname $TESTPATH)
70 [ -d "$DIR" ] || mkdir -p $DIR
72 SIZE=$(( 1024 * 1024 ))
73 run_check dd if=/dev/zero of=$TESTPATH bs=$SIZE count=1
75 INO=$(stat -c %i $TESTPATH)
77 # Orphan item won't be created if the file doesn't make it to disk
80 # Open and delete the file
84 # Ensure the unlink (and orphan item creation) hits the disk
87 # Turn off writes before closing so the orphan item will be left behind
88 _load_flakey_table $FLAKEY_DROP_WRITES
90 # Close the file so we can umount
93 # Orphan item should be on disk if operating correctly
95 _load_flakey_table $FLAKEY_ALLOW_WRITES
96 if ! has_orphan_item $INO; then
97 echo "ERROR: No orphan item found after umount."
102 # If $DIR is a subvolume, this will cause a lookup and orphan cleanup
105 # Orphan item will be cleaned up during mount but won't be on
106 # disk until there's a sync.
110 if has_orphan_item $INO; then
111 echo "ERROR: Orphan item found after successful mount/sync."
118 _run_btrfs_util_prog subvolume create $SCRATCH_MNT/testdir
124 SUB=$($BTRFS_UTIL_PROG subvolume list $SCRATCH_MNT |awk '{print $2}')
125 _run_btrfs_util_prog subvolume set-default $SUB $SCRATCH_MNT
131 echo "Testing with fs root as default subvolume"
134 echo "Testing with explicit default subvolume"
135 test_orphan new_default
137 echo "Testing with orphan on non-default subvolume"
138 test_orphan new_subvolume