fsx/fsstress: round blocksize properly
[xfstests-dev.git] / tests / btrfs / 209
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2020 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FSQA Test No. 209
6 #
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.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         _cleanup_flakey
22         cd /
23         rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/attr
29 . ./common/filter
30 . ./common/dmflakey
31
32 # real QA test starts here
33 _supported_fs btrfs
34 _require_scratch
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"
39
40 rm -f $seqres.full
41
42 _scratch_mkfs -O ^no-holes >>$seqres.full 2>&1
43 _require_metadata_journaling $SCRATCH_DEV
44 _init_flakey
45 _mount_flakey
46
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.
49 $XFS_IO_PROG -f \
50              -c "pwrite -S 0xab 0 256K" \
51              -c "fsync" \
52              $SCRATCH_MNT/foo | _filter_xfs_io
53
54 # Force a transaction commit and wipe out the log tree.
55 sync
56
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
63
64 # Now dirty the range from 768K to 1M again and sync that range.
65 $XFS_IO_PROG \
66     -c "mmap -w 768K 256K"        \
67     -c "mwrite -S 0xef 768K 256K" \
68     -c "msync -s 768K 256K"       \
69     -c "munmap"                   \
70     $SCRATCH_MNT/foo | _filter_xfs_io
71
72 echo "File digest before power failure: $(_md5_checksum $SCRATCH_MNT/foo)"
73
74 # Simulate a power failure and mount again the filesystem.
75 _flakey_drop_and_remount
76
77 # Should match what we got before the power failure.
78 echo "File digest after power failure: $(_md5_checksum $SCRATCH_MNT/foo)"
79
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.
83 _unmount_flakey
84
85 status=0
86 exit