2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test a scenario were we fsync a range of a file and have a power failure.
8 # We want to check that after a power failure and mounting the filesystem, we
9 # do not end up with a missing file extent representing a hole. This applies
10 # only when not using the NO_HOLES feature.
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
26 # get standard environment, filters and checks
32 # real QA test starts here
36 _require_dm_target flakey
37 _require_btrfs_fs_feature "no_holes"
38 _require_btrfs_mkfs_feature "no-holes"
39 _require_xfs_io_command "sync_range"
43 _scratch_mkfs -O ^no-holes >>$seqres.full 2>&1
44 _require_metadata_journaling $SCRATCH_DEV
48 # Create a 256K file with a single extent and fsync it to clear the full sync
49 # bit from the inode - we want the msync below to trigger a fast fsync.
51 -c "pwrite -S 0xab 0 256K" \
53 $SCRATCH_MNT/foo | _filter_xfs_io
55 # Force a transaction commit and wipe out the log tree.
58 # Dirty 768K of data, increasing the file size to 1Mb, and flush only the range
59 # from 256K to 512K without updating the log tree (sync_file_range() does not
60 # trigger fsync, it only starts writeback and waits for it to finish).
61 $XFS_IO_PROG -c "pwrite -S 0xcd 256K 768K" \
62 -c "sync_range -abw 256K 256K" \
63 $SCRATCH_MNT/foo | _filter_xfs_io
65 # Now dirty the range from 768K to 1M again and sync that range.
67 -c "mmap -w 768K 256K" \
68 -c "mwrite -S 0xef 768K 256K" \
69 -c "msync -s 768K 256K" \
71 $SCRATCH_MNT/foo | _filter_xfs_io
73 echo "File digest before power failure: $(_md5_checksum $SCRATCH_MNT/foo)"
75 # Simulate a power failure and mount again the filesystem.
76 _flakey_drop_and_remount
78 # Should match what we got before the power failure.
79 echo "File digest after power failure: $(_md5_checksum $SCRATCH_MNT/foo)"
81 # We also want to check that fsck doesn't fail due to an error of a missing
82 # file extent item that represents a hole for the range 256K to 512K. The
83 # fstests framework does the fsck once the test exits.