fstests: move test group info to test files
[xfstests-dev.git] / tests / btrfs / 159
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2018 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 159
6 #
7 # Test that when we have the no-holes mode enabled and a specific metadata
8 # layout, if we punch a hole and fsync the file, at replay time the whole
9 # hole was preserved.
10 #
11 . ./common/preamble
12 _begin_fstest auto quick punch log
13
14 # Override the default cleanup function.
15 _cleanup()
16 {
17         _cleanup_flakey
18         cd /
19         rm -f $tmp.*
20 }
21
22 # Import common functions.
23 . ./common/filter
24 . ./common/dmflakey
25
26 # real QA test starts here
27 _supported_fs btrfs
28 _require_scratch
29 _require_dm_target flakey
30 _require_xfs_io_command "fpunch"
31 _require_odirect
32
33 run_test()
34 {
35         local punch_offset=$1
36
37         # We create the filesystem with a node size of 64Kb because we need to
38         # create a specific metadata layout in order to trigger the bug we are
39         # testing. At the moment the node size can not be smaller then the
40         # system's page size, so given that the largest possible page size is
41         # 64Kb and by default the node size is set to the system's page size
42         # value, we explicitly create a filesystem with a 64Kb node size.
43         _scratch_mkfs -O no-holes -n $((64 * 1024)) >>$seqres.full 2>&1
44         _require_metadata_journaling $SCRATCH_DEV
45         _init_flakey
46         _mount_flakey
47
48         # Create our test file with 832 extents of 256Kb each. Before each
49         # extent, there is a 256Kb hole (except for the first extent, which
50         # starts at offset 0). This creates two leafs in the filesystem tree.
51         # We use direct IO to ensure we get exactly 256K extents (with buffered
52         # IO we can get writeback triggered at any time and therefore get
53         # extents smaller than 256K).
54         for ((i = 0; i <= 831; i++)); do
55                 local offset=$((i * 2 * 256 * 1024))
56                 $XFS_IO_PROG -f -d -c "pwrite -S 0xab -b 256K $offset 256K" \
57                         $SCRATCH_MNT/foobar >/dev/null
58         done
59
60         # Make sure everything done so far is durably persisted.
61         sync
62
63         # Now punch a hole that covers part of the extent at offset
64         # "$punch_offset".
65         # We want to punch a hole that starts in the middle of the last extent
66         # item in the first leaf. On a system without selinux enabled that is
67         # the extent that starts at offset 216530944, while on a system with it
68         # enabled it is the extent that starts at offset 216006656 (because
69         # selinux causes a xattr item to be added to our test file).
70         $XFS_IO_PROG -c "fpunch $((punch_offset + 128 * 1024 - 4000)) 256K" \
71                      -c "fsync" \
72                      $SCRATCH_MNT/foobar
73
74         echo "File digest before power failure:"
75         md5sum $SCRATCH_MNT/foobar | _filter_scratch
76         # Simulate a power failure and mount the filesystem to check that
77         # replaying the fsync log/journal succeeds and our test file has the
78         # expected content.
79         _flakey_drop_and_remount
80         echo "File digest after power failure and log replay:"
81         md5sum $SCRATCH_MNT/foobar | _filter_scratch
82
83         _unmount_flakey
84         _cleanup_flakey
85 }
86
87 run_test 216006656
88 run_test 216530944
89
90 status=0
91 exit