common: kill _supported_os
[xfstests-dev.git] / tests / btrfs / 119
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2016 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 119
6 #
7 # Test log tree replay when qgroups are enabled and orphan roots (deleted
8 # snapshots) exist.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13 tmp=/tmp/$$
14 status=1        # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
16
17 _cleanup()
18 {
19         _cleanup_flakey
20         cd /
21         rm -f $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/dmflakey
28
29 # real QA test starts here
30 _supported_fs btrfs
31 _require_scratch
32 _require_dm_target flakey
33
34 rm -f $seqres.full
35
36 _scratch_mkfs >>$seqres.full 2>&1
37 _require_metadata_journaling $SCRATCH_DEV
38 _init_flakey
39 _mount_flakey
40
41 _run_btrfs_util_prog quota enable $SCRATCH_MNT
42
43 # Create 2 directories with one file in one of them.
44 # We use these just to trigger a transaction commit later, moving the file from
45 # directory a to directory b and doing an fsync against directory a.
46 mkdir $SCRATCH_MNT/a
47 mkdir $SCRATCH_MNT/b
48 touch $SCRATCH_MNT/a/f
49 sync
50
51 # Create our test file with 2 4K extents.
52 $XFS_IO_PROG -f -s -c "pwrite -S 0xaa 0 8K" $SCRATCH_MNT/foobar | _filter_xfs_io
53
54 # Create a snapshot and delete it. This doesn't really delete the snapshot
55 # immediately, just makes it inaccessible and invisible to user space, the
56 # snapshot is deleted later by a dedicated kernel thread (cleaner kthread)
57 # which is woke up at the next transaction commit.
58 # A root orphan item is inserted into the tree of tree roots, so that if a
59 # power failure happens before the dedicated kernel thread does the snapshot
60 # deletion, the next time the filesystem is mounted it resumes the snapshot
61 # deletion.
62 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/snap
63 _run_btrfs_util_prog subvolume delete $SCRATCH_MNT/snap
64
65 # Now overwrite half of the extents we wrote before. Because we made a snapshpot
66 # before, which isn't really deleted yet (since no transaction commit happened
67 # after we did the snapshot delete request), the non overwritten extents get
68 # referenced twice, once by the default subvolume and once by the snapshot.
69 $XFS_IO_PROG -c "pwrite -S 0xbb 4K 8K" $SCRATCH_MNT/foobar | _filter_xfs_io
70
71 # Now move file f from directory a to directory b and fsync directory a.
72 # The fsync on the directory a triggers a transaction commit (because a file
73 # was moved from it to another directory) and the file fsync leaves a log tree
74 # with file extent items to replay.
75 mv $SCRATCH_MNT/a/f $SCRATCH_MNT/a/b
76 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a
77 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foobar
78
79 echo "File digest before power failure:"
80 md5sum $SCRATCH_MNT/foobar | _filter_scratch
81
82 # Now simulate a power failure and mount the filesystem to replay the log tree.
83 # After the log tree was replayed, we used to hit a BUG_ON() when processing
84 # the root orphan item for the deleted snapshot. This is because when processing
85 # an orphan root the code expected to be the first code inserting the root into
86 # the fs_info->fs_root_radix radix tree, while in reallity it was the second
87 # caller attempting to do it - the first caller was the transaction commit that
88 # took place after replaying the log tree, when updating the qgroup counters.
89 _flakey_drop_and_remount
90
91 echo "File digest before after failure:"
92 # Must match what he got before the power failure.
93 md5sum $SCRATCH_MNT/foobar | _filter_scratch
94
95 _unmount_flakey
96
97 status=0
98 exit