2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2021 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test that when using the NO_HOLES feature, if we truncate down a file, clone a
8 # file range covering only a hole into an offset beyond the current file size,
9 # and then fsync the file, after a power failure we get the expected file content
10 # and we do not get stale data corresponding to file extents that existed before
11 # truncating the file.
14 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
17 status=1 # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
27 # get standard environment, filters and checks
32 # real QA test starts here
35 _require_btrfs_fs_feature "no_holes"
36 _require_btrfs_mkfs_feature "no-holes"
37 _require_dm_target flakey
41 _scratch_mkfs -O no-holes >>$seqres.full 2>&1
42 _require_metadata_journaling $SCRATCH_DEV
46 # Create our test file with 3 extents of 256K and a 256K hole at offset 256K.
47 # The file has a size of 1280K.
49 -c "pwrite -S 0xab -b 256K 0 256K" \
50 -c "pwrite -S 0xcd -b 256K 512K 256K" \
51 -c "pwrite -S 0xef -b 256K 768K 256K" \
52 -c "pwrite -S 0x73 -b 256K 1024K 256K" \
53 $SCRATCH_MNT/foobar | _filter_xfs_io
55 # Make sure it's durably persisted. We want the last committed super block to
56 # point to this particular file extent layout.
59 # Now truncate our file to a smaller size, falling within a position of the
60 # second extent. This sets the full sync runtime flag on the inode.
61 # Then fsync the file to log it and clear the full sync flag from the inode.
62 # The third extent is no longer part of the file and therefore it is not logged.
63 $XFS_IO_PROG -c "truncate 800K" -c "fsync" $SCRATCH_MNT/foobar
65 # Now do a clone operation that only clones the hole and sets back the file size
66 # to match the size it had before the truncate operation (1280K).
68 -c "reflink $SCRATCH_MNT/foobar 256K 1024K 256K" \
70 $SCRATCH_MNT/foobar | _filter_xfs_io
72 echo "File data before power failure:"
73 od -A d -t x1 $SCRATCH_MNT/foobar
75 # Simulate a power failure and then mount again the filesystem to replay the log
77 _flakey_drop_and_remount
79 # This should match what we got before the power failure. The range from 1024K
80 # to 1280K should be a hole and not point to an extent full of bytes with a
82 echo "File data after power failure:"
83 od -A d -t x1 $SCRATCH_MNT/foobar