2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that subvolume deletion is resumed on RW mounts, that it is not performed
8 # on RO mounts and that after remounting a filesystem from RO to RW mode, it is
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
15 status=1 # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
30 # real QA test starts here
33 _require_dm_target flakey
34 _require_btrfs_command inspect-internal dump-tree
38 _scratch_mkfs >>$seqres.full 2>&1
39 _require_metadata_journaling $SCRATCH_DEV
43 check_subvol_orphan_item_exists()
45 # Check that the orphan item for our subvolume exists in the root tree.
46 $BTRFS_UTIL_PROG inspect-internal dump-tree -t 1 $SCRATCH_DEV | \
47 grep -q 'ORPHAN ORPHAN_ITEM 256'
48 [ $? -ne 0 ] && echo "subvolume orphan item is missing"
51 check_subvol_orphan_item_not_exists()
53 # Check that the orphan item for our subvolume does not exists in the
55 $BTRFS_UTIL_PROG inspect-internal dump-tree -t 1 $SCRATCH_DEV | \
56 grep -q 'ORPHAN ORPHAN_ITEM 256'
57 [ $? -eq 0 ] && echo "subvolume orphan item still exists"
60 check_subvol_btree_exists()
62 $BTRFS_UTIL_PROG inspect-internal dump-tree $SCRATCH_DEV | \
63 grep -q 'file tree key (256 ROOT_ITEM 0)'
64 [ $? -ne 0 ] && echo "subvolume btree is missing"
67 check_subvol_btree_not_exists()
69 $BTRFS_UTIL_PROG inspect-internal dump-tree $SCRATCH_DEV | \
70 grep -q 'file tree key (256 ROOT_ITEM 0)'
71 [ $? -eq 0 ] && echo "subvolume btree still exists"
74 create_subvol_with_orphan()
76 $BTRFS_UTIL_PROG subvolume create $SCRATCH_MNT/testsv | _filter_scratch
78 # Create a file in our subvolume and make it durably persisted.
79 touch $SCRATCH_MNT/testsv/foobar
82 # Now open a file descriptor on the file and, while holding the file
83 # open, delete the subvolume, then 'sync' to durably persist the orphan
84 # item for the subvolume.
85 exec 73< $SCRATCH_MNT/testsv/foobar
86 $BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/testsv | _filter_scratch
89 # Now silently drop writes on the device, close the file descriptor and
90 # unmount the filesystem. After this we should have an orphan item in
91 # root tree for the subvolume, so that its tree is deleted on the next
93 _load_flakey_table $FLAKEY_DROP_WRITES
97 check_subvol_orphan_item_exists
98 check_subvol_btree_exists
100 _load_flakey_table $FLAKEY_ALLOW_WRITES
103 create_subvol_with_orphan
105 # Mount the filesystem in RW mode and unmount it. After that, the subvolume
106 # and its orphan item should not exist anymore.
107 # Use a commit interval lower than the default (30 seconds) so that the test
108 # is faster and we spend less time waiting for transaction commits.
109 MOUNT_OPTIONS="-o commit=1"
111 $BTRFS_UTIL_PROG subvolume sync $SCRATCH_MNT >>$seqres.full
114 check_subvol_orphan_item_not_exists
115 check_subvol_btree_not_exists
117 # Now lets check a RO mount does not trigger subvolume deletion.
119 _scratch_mkfs >>$seqres.full 2>&1
123 create_subvol_with_orphan
124 MOUNT_OPTIONS="-o ro,commit=1"
126 # The subvolume path should not be accessible anymore, even if deletion of the
127 # subvolume btree did not happen yet.
128 [ -e $SCRATCH_MNT/testsv ] && echo "subvolume path still exists"
131 # The subvolume btree should still exist, even though the path is not accessible.
132 check_subvol_btree_exists
133 # The orphan item for the subvolume should still exist, as the subvolume btree
134 # was not yet deleted.
135 check_subvol_orphan_item_exists
137 # Mount the filesystem RO again.
140 # Now remount RW, then unmount and then check the subvolume's orphan item, btree
141 # and path don't exist anymore.
142 MOUNT_OPTIONS="-o remount,rw"
144 $BTRFS_UTIL_PROG subvolume sync $SCRATCH_MNT >>$seqres.full
145 [ -e $SCRATCH_MNT/testsv ] && echo "subvolume path still exists"
148 check_subvol_orphan_item_not_exists
149 check_subvol_btree_not_exists