generic/611: Use _getfattr instead of GETFATTR_PROG
[xfstests-dev.git] / tests / generic / 177
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. 177
6 #
7 # Test that a file fsync works after punching a hole for the same file range
8 # multiple times and that after log/journal replay the file's content is
9 # correct.
10 #
11 # This test is motivated by a bug found in btrfs.
12 #
13 seq=`basename $0`
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22         _cleanup_flakey
23         cd /
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/punch
31 . ./common/dmflakey
32
33 # real QA test starts here
34 _supported_fs generic
35 _require_scratch
36 _require_xfs_io_command "fpunch"
37 _require_xfs_io_command "fiemap"
38 _require_dm_target flakey
39
40 rm -f $seqres.full
41
42 _scratch_mkfs >>$seqres.full 2>&1
43 _require_metadata_journaling $SCRATCH_DEV
44 _init_flakey
45 _mount_flakey
46
47 BLOCK_SIZE=$(_get_file_block_size $SCRATCH_MNT)
48
49 # Create out test file with some data and then fsync it.
50 # We do the fsync only to make sure the last fsync we do in this test triggers
51 # the fast code path of btrfs' fsync implementation, a condition necessary to
52 # trigger the bug btrfs had.
53 $XFS_IO_PROG -f -c "pwrite -S 0xaa 0K $(($BLOCK_SIZE * 32))" \
54                 -c "fsync"                  \
55                 $SCRATCH_MNT/foobar | _filter_xfs_io_blocks_modified
56
57 # Now punch a hole against the range [96K, 128K[.
58 $XFS_IO_PROG -c "fpunch $(($BLOCK_SIZE * 24)) $(($BLOCK_SIZE * 8))" $SCRATCH_MNT/foobar
59
60 # Punch another hole against a range that overlaps the previous range and ends
61 # beyond eof.
62 $XFS_IO_PROG -c "fpunch $(($BLOCK_SIZE * 16)) $(($BLOCK_SIZE * 32))" $SCRATCH_MNT/foobar
63
64 # Punch another hole against a range that overlaps the first range ([96K, 128K[)
65 # and ends at eof.
66 $XFS_IO_PROG -c "fpunch $(($BLOCK_SIZE * 8)) $(($BLOCK_SIZE * 24))" $SCRATCH_MNT/foobar
67
68 # Fsync our file. We want to verify that, after a power failure and mounting the
69 # filesystem again, the file content reflects all the hole punch operations.
70 $XFS_IO_PROG -c "fsync" $SCRATCH_MNT/foobar
71
72 echo "File digest before power failure:"
73 od -t x1 $SCRATCH_MNT/foobar | _filter_od
74
75 echo "Fiemap before power failure:"
76 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foobar | _filter_fiemap $BLOCK_SIZE
77
78 _flakey_drop_and_remount
79
80 echo "File digest after log replay:"
81 # Must match the same digest we got before the power failure.
82 od -t x1 $SCRATCH_MNT/foobar | _filter_od
83
84 echo "Fiemap after log replay:"
85 # Must match the same extent listing we got before the power failure.
86 $XFS_IO_PROG -c "fiemap -v" $SCRATCH_MNT/foobar | _filter_fiemap $BLOCK_SIZE
87
88 _unmount_flakey
89
90 status=0
91 exit