generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 276
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. 276
6 #
7 # Test DIO CoW behavior when the write temporarily fails and we unmount.
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.*
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_odirect
30
31 echo "Format and mount"
32 _scratch_mkfs > $seqres.full 2>&1
33 _dmerror_init
34 _dmerror_mount >> $seqres.full 2>&1
35
36 testdir=$SCRATCH_MNT/test-$seq
37 mkdir $testdir
38
39 blksz=65536
40 nr=640
41 bufnr=128
42 filesize=$((blksz * nr))
43 bufsize=$((blksz * bufnr))
44
45 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
46
47 echo "Create the original files"
48 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file1 >> $seqres.full
49 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
50 _dmerror_unmount
51 _dmerror_mount
52
53 echo "Compare files"
54 md5sum $testdir/file1 | _filter_scratch
55 md5sum $testdir/file2 | _filter_scratch
56
57 echo "CoW and unmount"
58 sync
59 _dmerror_load_error_table
60 $XFS_IO_PROG -d -f -c "pwrite -S 0x63 -b $bufsize 0 $filesize" $testdir/file2 \
61         >> $seqres.full 2>&1
62 _dmerror_load_working_table
63 rm -rf $testdir/file2 >> $seqres.full 2>&1
64 _dmerror_unmount
65 _dmerror_mount
66
67 echo "Compare files"
68 md5sum $testdir/file1 | _filter_scratch
69
70 echo "Check for damage"
71 _dmerror_unmount
72 _dmerror_cleanup
73 _repair_scratch_fs >> $seqres.full
74
75 # success, all done
76 status=0
77 exit