4 # Test that when we have the no-holes mode enabled and a specific metadata
5 # layout, if we punch a hole and fsync the file, at replay time the whole
8 #-----------------------------------------------------------------------
10 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
11 # Author: Filipe Manana <fdmanana@suse.com>
13 # This program is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License as
15 # published by the Free Software Foundation.
17 # This program is distributed in the hope that it would be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License
23 # along with this program; if not, write the Free Software Foundation,
24 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #-----------------------------------------------------------------------
29 seqres=$RESULT_DIR/$seq
30 echo "QA output created by $seq"
32 status=1 # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
42 # get standard environment, filters and checks
47 # real QA test starts here
51 _require_dm_target flakey
52 _require_xfs_io_command "fpunch"
61 # We create the filesystem with a node size of 64Kb because we need to
62 # create a specific metadata layout in order to trigger the bug we are
63 # testing. At the moment the node size can not be smaller then the
64 # system's page size, so given that the largest possible page size is
65 # 64Kb and by default the node size is set to the system's page size
66 # value, we explicitly create a filesystem with a 64Kb node size.
67 _scratch_mkfs -O no-holes -n $((64 * 1024)) >>$seqres.full 2>&1
68 _require_metadata_journaling $SCRATCH_DEV
72 # Create our test file with 832 extents of 256Kb each. Before each
73 # extent, there is a 256Kb hole (except for the first extent, which
74 # starts at offset 0). This creates two leafs in the filesystem tree.
75 # We use direct IO to ensure we get exactly 256K extents (with buffered
76 # IO we can get writeback triggered at any time and therefore get
77 # extents smaller than 256K).
78 for ((i = 0; i <= 831; i++)); do
79 local offset=$((i * 2 * 256 * 1024))
80 $XFS_IO_PROG -f -d -c "pwrite -S 0xab -b 256K $offset 256K" \
81 $SCRATCH_MNT/foobar >/dev/null
84 # Make sure everything done so far is durably persisted.
87 # Now punch a hole that covers part of the extent at offset
89 # We want to punch a hole that starts in the middle of the last extent
90 # item in the first leaf. On a system without selinux enabled that is
91 # the extent that starts at offset 216530944, while on a system with it
92 # enabled it is the extent that starts at offset 216006656 (because
93 # selinux causes a xattr item to be added to our test file).
94 $XFS_IO_PROG -c "fpunch $((punch_offset + 128 * 1024 - 4000)) 256K" \
98 echo "File digest before power failure:"
99 md5sum $SCRATCH_MNT/foobar | _filter_scratch
100 # Simulate a power failure and mount the filesystem to check that
101 # replaying the fsync log/journal succeeds and our test file has the
103 _flakey_drop_and_remount
104 echo "File digest after power failure and log replay:"
105 md5sum $SCRATCH_MNT/foobar | _filter_scratch