generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / generic / 331
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 331
6 #
7 # Test AIO CoW behavior when the write temporarily fails.
8 #
9 . ./common/preamble
10 _begin_fstest auto quick clone eio
11
12 # Override the default cleanup function.
13 _cleanup()
14 {
15     cd /
16     rm -rf $tmp.* $TEST_DIR/moo
17     _dmerror_cleanup
18 }
19
20 # Import common functions.
21 . ./common/filter
22 . ./common/reflink
23 . ./common/dmerror
24
25 # real QA test starts here
26 _require_scratch_reflink
27 _require_cp_reflink
28 _require_dm_target error
29 _require_aiodio "aiocp"
30 AIO_TEST="$here/src/aio-dio-regress/aiocp"
31
32 echo "Format and mount"
33 _scratch_mkfs > $seqres.full 2>&1
34 _dmerror_init
35 _dmerror_mount >> $seqres.full 2>&1
36
37 testdir=$SCRATCH_MNT/test-$seq
38 mkdir $testdir
39
40 blksz=65536
41 nr=640
42 bufnr=128
43 filesize=$((blksz * nr))
44 bufsize=$((blksz * bufnr))
45
46 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
47
48 echo "Create the original files"
49 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file1 >> $seqres.full
50 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
51 _dmerror_unmount
52 _dmerror_mount
53
54 echo "Compare files"
55 md5sum $testdir/file1 | _filter_scratch
56 md5sum $testdir/file2 | _filter_scratch
57
58 echo "CoW and unmount"
59 $XFS_IO_PROG -f -c "pwrite -S 0x63 $bufsize 1" $testdir/file2 >> $seqres.full
60 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $bufsize 0 $filesize" $TEST_DIR/moo >> $seqres.full
61 sync
62 _dmerror_load_error_table
63 $AIO_TEST -b $bufsize $TEST_DIR/moo $testdir/file2 >> $seqres.full
64 $XFS_IO_PROG -c "fdatasync" $testdir/file2
65 _dmerror_load_working_table
66 _dmerror_unmount
67 _dmerror_mount
68
69 echo "Compare files"
70 md5sum $testdir/file1 | _filter_scratch
71 md5sum $testdir/file2 | _filter_scratch
72
73 echo "Check for damage"
74 _dmerror_unmount
75 _dmerror_cleanup
76 _repair_scratch_fs >> $seqres.full
77
78 # success, all done
79 status=0
80 exit