xfs/{263,106}: erase max warnings printout
[xfstests-dev.git] / tests / generic / 101
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2015 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 101
6 #
7 # Test that if we truncate a file to a smaller size, then truncate it to its
8 # original size or a larger size, then fsyncing it and a power failure happens,
9 # the file will have the range [first_truncate_size, last_size[ with all bytes
10 # having a value of 0x00 if we read it the next time the filesystem is mounted.
11 #
12 # This test is motivated by a bug found in btrfs.
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         _cleanup_flakey
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/dmflakey
31
32 # real QA test starts here
33 _supported_fs generic
34 _supported_os Linux
35 _require_scratch
36 _require_dm_target flakey
37
38 # This test was motivated by an issue found in btrfs when the btrfs no-holes
39 # feature is enabled (introduced in kernel 3.14). So enable the feature if the
40 # fs being tested is btrfs.
41 if [ $FSTYP == "btrfs" ]; then
42         _require_btrfs_fs_feature "no_holes"
43         _require_btrfs_mkfs_feature "no-holes"
44         MKFS_OPTIONS="$MKFS_OPTIONS -O no-holes"
45 fi
46
47 rm -f $seqres.full
48
49 _scratch_mkfs >>$seqres.full 2>&1
50 _require_metadata_journaling $SCRATCH_DEV
51 _init_flakey
52 _mount_flakey
53
54 # Create our test files and make sure everything is durably persisted.
55 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 64K"         \
56                 -c "pwrite -S 0xbb 64K 61K"       \
57                 $SCRATCH_MNT/foo | _filter_xfs_io
58 $XFS_IO_PROG -f -c "pwrite -S 0xee 0 64K"         \
59                 -c "pwrite -S 0xff 64K 61K"       \
60                 $SCRATCH_MNT/bar | _filter_xfs_io
61 sync
62
63 # Now truncate our file foo to a smaller size (64Kb) and then truncate it to the
64 # size it had before the shrinking truncate (125Kb). Then fsync our file. If a
65 # power failure happens after the fsync, we expect our file to have a size of
66 # 125Kb, with the first 64Kb of data having the value 0xaa and the second 61Kb
67 # of data having the value 0x00.
68 $XFS_IO_PROG -c "truncate 64K" \
69                 -c "truncate 125K" \
70                 -c "fsync" \
71                 $SCRATCH_MNT/foo
72
73 # Do something similar to our file bar, but the first truncation sets the file
74 # size to 0 and the second truncation expands the size to the double of what it
75 # was initially.
76 $XFS_IO_PROG -c "truncate 0" \
77                 -c "truncate 253K" \
78                 -c "fsync" \
79                 $SCRATCH_MNT/bar
80
81 _flakey_drop_and_remount
82
83 # We expect foo to have a size of 125Kb, the first 64Kb of data all having the
84 # value 0xaa and the remaining 61Kb to be a hole (all bytes with value 0x00).
85 echo "File foo content after log replay:"
86 od -t x1 $SCRATCH_MNT/foo
87
88 # We expect bar to have a size of 253Kb and no extents (any byte read from bar
89 # has the value 0x00).
90 echo "File bar content after log replay:"
91 od -t x1 $SCRATCH_MNT/bar
92
93 status=0
94 exit