generic: _require_dm_target() helper
[xfstests-dev.git] / tests / generic / 325
1 #! /bin/bash
2 # FS QA Test No. 325
3 #
4 # Make some pages/extents of a file dirty, do a ranged fsync that covers
5 # only some of the dirty pages/extents, and then do a regular fsync (or
6 # another ranged fsync that covers the remaining dirty pages/extents).
7 # Verify after that all extents were persisted.
8 #
9 # This test is motivated by a btrfs issue where the first ranged fsync
10 # would prevent the following fsync from persisting the remaining dirty
11 # pages/extents. This was fixed by the following btrfs kernel patch:
12 #
13 #     Btrfs: fix fsync data loss after a ranged fsync
14 #
15 #-----------------------------------------------------------------------
16 # Copyright (C) 2014 SUSE Linux Products GmbH. All Rights Reserved.
17 # Author: Filipe Manana <fdmanana@suse.com>
18 #
19 # This program is free software; you can redistribute it and/or
20 # modify it under the terms of the GNU General Public License as
21 # published by the Free Software Foundation.
22 #
23 # This program is distributed in the hope that it would be useful,
24 # but WITHOUT ANY WARRANTY; without even the implied warranty of
25 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 # GNU General Public License for more details.
27 #
28 # You should have received a copy of the GNU General Public License
29 # along with this program; if not, write the Free Software Foundation,
30 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
31 #-----------------------------------------------------------------------
32 #
33
34 seq=`basename $0`
35 seqres=$RESULT_DIR/$seq
36 echo "QA output created by $seq"
37
38 here=`pwd`
39 status=1        # failure is the default!
40
41 _cleanup()
42 {
43         _cleanup_flakey
44 }
45 trap "_cleanup; exit \$status" 0 1 2 3 15
46
47 # get standard environment, filters and checks
48 . ./common/rc
49 . ./common/filter
50 . ./common/dmflakey
51
52 # real QA test starts here
53 _supported_fs generic
54 _supported_os Linux
55 _need_to_be_root
56 _require_scratch
57 _require_dm_target flakey
58 _require_metadata_journaling $SCRATCH_DEV
59
60 rm -f $seqres.full
61
62 _scratch_mkfs >> $seqres.full 2>&1
63
64 _init_flakey
65 _mount_flakey
66
67 # Create the file first.
68 $XFS_IO_PROG -f -c "pwrite -S 0xff 0 256K" $SCRATCH_MNT/foo | _filter_xfs_io
69
70 # Now sync the file data to disk using 'sync' and not an fsync. This is because
71 # in btrfs the first fsync clears the btrfs inode full fsync flag, which must
72 # be set when the first msync below happens in order to trigger the bug.
73 sync
74
75 # Now update the first 4Kb and the last 4Kb of the file, using memory mapped IO
76 # because an msync(), since the linux kernel commit
77 # 7fc34a62ca4434a79c68e23e70ed26111b7a4cf8, invokes a ranged fsync.
78 #
79 # After those writes, msync a range covering the first 4Kb and then after
80 # perform a msync with a range covering the last 4Kb of the file.
81 # This second msync() used to be a no-op for that btrfs bug (and the first fsync
82 # didn't log the last 4Kb extent as expected too).
83 $XFS_IO_PROG \
84         -c "mmap -w 0 256K"         \
85         -c "mwrite -S 0xaa 0 4K"   \
86         -c "mwrite -S 0xbb 252K 4K" \
87         -c "msync -s 0K 64K"       \
88         -c "msync -s 192K 64K"      \
89         -c "munmap"                \
90         $SCRATCH_MNT/foo | _filter_xfs_io
91
92 echo "File content before crash/reboot:"
93 od -t x1 $SCRATCH_MNT/foo
94
95 _load_flakey_table $FLAKEY_DROP_WRITES
96 _unmount_flakey
97
98 _load_flakey_table $FLAKEY_ALLOW_WRITES
99 _mount_flakey
100
101 echo "File content after crash/reboot and fs mount:"
102 od -t x1 $SCRATCH_MNT/foo
103
104 _unmount_flakey
105
106 status=0
107 exit