generic: convert tests to SPDX license tags
[xfstests-dev.git] / tests / generic / 325
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2014 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test No. 325
6 #
7 # Make some pages/extents of a file dirty, do a ranged fsync that covers
8 # only some of the dirty pages/extents, and then do a regular fsync (or
9 # another ranged fsync that covers the remaining dirty pages/extents).
10 # Verify after that all extents were persisted.
11 #
12 # This test is motivated by a btrfs issue where the first ranged fsync
13 # would prevent the following fsync from persisting the remaining dirty
14 # pages/extents. This was fixed by the following btrfs kernel patch:
15 #
16 #     Btrfs: fix fsync data loss after a ranged fsync
17 #
18 seq=`basename $0`
19 seqres=$RESULT_DIR/$seq
20 echo "QA output created by $seq"
21
22 here=`pwd`
23 status=1        # failure is the default!
24
25 _cleanup()
26 {
27         _cleanup_flakey
28 }
29 trap "_cleanup; exit \$status" 0 1 2 3 15
30
31 # get standard environment, filters and checks
32 . ./common/rc
33 . ./common/filter
34 . ./common/dmflakey
35
36 # real QA test starts here
37 _supported_fs generic
38 _supported_os Linux
39 _require_scratch
40 _require_dm_target flakey
41
42 rm -f $seqres.full
43
44 _scratch_mkfs >> $seqres.full 2>&1
45 _require_metadata_journaling $SCRATCH_DEV
46 _init_flakey
47 _mount_flakey
48
49 # Create the file first.
50 $XFS_IO_PROG -f -c "pwrite -S 0xff 0 256K" $SCRATCH_MNT/foo | _filter_xfs_io
51
52 # Now sync the file data to disk using 'sync' and not an fsync. This is because
53 # in btrfs the first fsync clears the btrfs inode full fsync flag, which must
54 # be set when the first msync below happens in order to trigger the bug.
55 sync
56
57 # Now update the first 4Kb and the last 4Kb of the file, using memory mapped IO
58 # because an msync(), since the linux kernel commit
59 # 7fc34a62ca4434a79c68e23e70ed26111b7a4cf8, invokes a ranged fsync.
60 #
61 # After those writes, msync a range covering the first 4Kb and then after
62 # perform a msync with a range covering the last 4Kb of the file.
63 # This second msync() used to be a no-op for that btrfs bug (and the first fsync
64 # didn't log the last 4Kb extent as expected too).
65 $XFS_IO_PROG \
66         -c "mmap -w 0 256K"         \
67         -c "mwrite -S 0xaa 0 4K"   \
68         -c "mwrite -S 0xbb 252K 4K" \
69         -c "msync -s 0K 64K"       \
70         -c "msync -s 192K 64K"      \
71         -c "munmap"                \
72         $SCRATCH_MNT/foo | _filter_xfs_io
73
74 echo "File content before crash/reboot:"
75 od -t x1 $SCRATCH_MNT/foo
76
77 _flakey_drop_and_remount
78
79 echo "File content after crash/reboot and fs mount:"
80 od -t x1 $SCRATCH_MNT/foo
81
82 _unmount_flakey
83
84 status=0
85 exit