xfs/{263,106}: erase max warnings printout
[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 _supported_os Linux
32 _require_scratch
33 _require_dm_target flakey
34
35 rm -f $seqres.full
36
37 _scratch_mkfs >>$seqres.full 2>&1
38 _require_metadata_journaling $SCRATCH_DEV
39 _init_flakey
40 _mount_flakey
41
42 _run_btrfs_util_prog quota enable $SCRATCH_MNT
43
44 # Create 2 directories with one file in one of them.
45 # We use these just to trigger a transaction commit later, moving the file from
46 # directory a to directory b and doing an fsync against directory a.
47 mkdir $SCRATCH_MNT/a
48 mkdir $SCRATCH_MNT/b
49 touch $SCRATCH_MNT/a/f
50 sync
51
52 # Create our test file with 2 4K extents.
53 $XFS_IO_PROG -f -s -c "pwrite -S 0xaa 0 8K" $SCRATCH_MNT/foobar | _filter_xfs_io
54
55 # Create a snapshot and delete it. This doesn't really delete the snapshot
56 # immediately, just makes it inaccessible and invisible to user space, the
57 # snapshot is deleted later by a dedicated kernel thread (cleaner kthread)
58 # which is woke up at the next transaction commit.
59 # A root orphan item is inserted into the tree of tree roots, so that if a
60 # power failure happens before the dedicated kernel thread does the snapshot
61 # deletion, the next time the filesystem is mounted it resumes the snapshot
62 # deletion.
63 _run_btrfs_util_prog subvolume snapshot $SCRATCH_MNT $SCRATCH_MNT/snap
64 _run_btrfs_util_prog subvolume delete $SCRATCH_MNT/snap
65
66 # Now overwrite half of the extents we wrote before. Because we made a snapshpot
67 # before, which isn't really deleted yet (since no transaction commit happened
68 # after we did the snapshot delete request), the non overwritten extents get
69 # referenced twice, once by the default subvolume and once by the snapshot.
70 $XFS_IO_PROG -c "pwrite -S 0xbb 4K 8K" $SCRATCH_MNT/foobar | _filter_xfs_io
71
72 # Now move file f from directory a to directory b and fsync directory a.
73 # The fsync on the directory a triggers a transaction commit (because a file
74 # was moved from it to another directory) and the file fsync leaves a log tree
75 # with file extent items to replay.
76 mv $SCRATCH_MNT/a/f $SCRATCH_MNT/a/b
77 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/a
78 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foobar
79
80 echo "File digest before power failure:"
81 md5sum $SCRATCH_MNT/foobar | _filter_scratch
82
83 # Now simulate a power failure and mount the filesystem to replay the log tree.
84 # After the log tree was replayed, we used to hit a BUG_ON() when processing
85 # the root orphan item for the deleted snapshot. This is because when processing
86 # an orphan root the code expected to be the first code inserting the root into
87 # the fs_info->fs_root_radix radix tree, while in reallity it was the second
88 # caller attempting to do it - the first caller was the transaction commit that
89 # took place after replaying the log tree, when updating the qgroup counters.
90 _flakey_drop_and_remount
91
92 echo "File digest before after failure:"
93 # Must match what he got before the power failure.
94 md5sum $SCRATCH_MNT/foobar | _filter_scratch
95
96 _unmount_flakey
97
98 status=0
99 exit