generic/611: Use _getfattr instead of GETFATTR_PROG
[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 _require_scratch
35 _require_dm_target flakey
36
37 # This test was motivated by an issue found in btrfs when the btrfs no-holes
38 # feature is enabled (introduced in kernel 3.14). So enable the feature if the
39 # fs being tested is btrfs.
40 if [ $FSTYP == "btrfs" ]; then
41         _require_btrfs_fs_feature "no_holes"
42         _require_btrfs_mkfs_feature "no-holes"
43         MKFS_OPTIONS="$MKFS_OPTIONS -O no-holes"
44 fi
45
46 rm -f $seqres.full
47
48 _scratch_mkfs >>$seqres.full 2>&1
49 _require_metadata_journaling $SCRATCH_DEV
50 _init_flakey
51 _mount_flakey
52
53 # Create our test files and make sure everything is durably persisted.
54 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0 64K"         \
55                 -c "pwrite -S 0xbb 64K 61K"       \
56                 $SCRATCH_MNT/foo | _filter_xfs_io
57 $XFS_IO_PROG -f -c "pwrite -S 0xee 0 64K"         \
58                 -c "pwrite -S 0xff 64K 61K"       \
59                 $SCRATCH_MNT/bar | _filter_xfs_io
60 sync
61
62 # Now truncate our file foo to a smaller size (64Kb) and then truncate it to the
63 # size it had before the shrinking truncate (125Kb). Then fsync our file. If a
64 # power failure happens after the fsync, we expect our file to have a size of
65 # 125Kb, with the first 64Kb of data having the value 0xaa and the second 61Kb
66 # of data having the value 0x00.
67 $XFS_IO_PROG -c "truncate 64K" \
68                 -c "truncate 125K" \
69                 -c "fsync" \
70                 $SCRATCH_MNT/foo
71
72 # Do something similar to our file bar, but the first truncation sets the file
73 # size to 0 and the second truncation expands the size to the double of what it
74 # was initially.
75 $XFS_IO_PROG -c "truncate 0" \
76                 -c "truncate 253K" \
77                 -c "fsync" \
78                 $SCRATCH_MNT/bar
79
80 _flakey_drop_and_remount
81
82 # We expect foo to have a size of 125Kb, the first 64Kb of data all having the
83 # value 0xaa and the remaining 61Kb to be a hole (all bytes with value 0x00).
84 echo "File foo content after log replay:"
85 od -t x1 $SCRATCH_MNT/foo
86
87 # We expect bar to have a size of 253Kb and no extents (any byte read from bar
88 # has the value 0x00).
89 echo "File bar content after log replay:"
90 od -t x1 $SCRATCH_MNT/bar
91
92 status=0
93 exit