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
35 _require_dm_target flakey
36 _require_btrfs_fs_feature "no_holes"
37 _require_btrfs_mkfs_feature "no-holes"
38 _require_xfs_io_command "sync_range"
42 _scratch_mkfs -O ^no-holes >>$seqres.full 2>&1
43 _require_metadata_journaling $SCRATCH_DEV
47 # Create a 256K file with a single extent and fsync it to clear the full sync
48 # bit from the inode - we want the msync below to trigger a fast fsync.
50 -c "pwrite -S 0xab 0 256K" \
52 $SCRATCH_MNT/foo | _filter_xfs_io
54 # Force a transaction commit and wipe out the log tree.
57 # Dirty 768K of data, increasing the file size to 1Mb, and flush only the range
58 # from 256K to 512K without updating the log tree (sync_file_range() does not
59 # trigger fsync, it only starts writeback and waits for it to finish).
60 $XFS_IO_PROG -c "pwrite -S 0xcd 256K 768K" \
61 -c "sync_range -abw 256K 256K" \
62 $SCRATCH_MNT/foo | _filter_xfs_io
64 # Now dirty the range from 768K to 1M again and sync that range.
66 -c "mmap -w 768K 256K" \
67 -c "mwrite -S 0xef 768K 256K" \
68 -c "msync -s 768K 256K" \
70 $SCRATCH_MNT/foo | _filter_xfs_io
72 echo "File digest before power failure: $(_md5_checksum $SCRATCH_MNT/foo)"
74 # Simulate a power failure and mount again the filesystem.
75 _flakey_drop_and_remount
77 # Should match what we got before the power failure.
78 echo "File digest after power failure: $(_md5_checksum $SCRATCH_MNT/foo)"
80 # We also want to check that fsck doesn't fail due to an error of a missing
81 # file extent item that represents a hole for the range 256K to 512K. The
82 # fstests framework does the fsck once the test exits.