generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 201
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 201
6 #
7 # See what happens if we dirty a lot of pages via CoW and immediately
8 # unlink the file.
9 #
10 . ./common/preamble
11 _begin_fstest auto quick clone
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16     cd /
17     rm -rf $tmp.* $testdir
18 }
19
20 # Import common functions.
21 . ./common/filter
22 . ./common/reflink
23
24 # real QA test starts here
25 _require_scratch_reflink
26 _require_xfs_io_command "falloc"
27
28 echo "Format and mount"
29 _scratch_mkfs > $seqres.full 2>&1
30 _scratch_mount >> $seqres.full 2>&1
31
32 testdir=$SCRATCH_MNT/test-$seq
33 mkdir $testdir
34
35 echo "Create the original files"
36 blksz=65536
37 nr=64
38 filesize=$((blksz * nr))
39 _pwrite_byte 0x61 0 $filesize $testdir/file1 >> $seqres.full
40 _pwrite_byte 0x62 0 $filesize $testdir/file3 >> $seqres.full
41 _pwrite_byte 0x62 0 $filesize $testdir/file3.chk >> $seqres.full
42 seq 0 2 $((nr-1)) | while read f; do
43         _reflink_range $testdir/file1 $((blksz * f)) $testdir/file3 $((blksz * f)) $blksz >> $seqres.full
44         _pwrite_byte 0x61 $((blksz * f)) $blksz $testdir/file3.chk >> $seqres.full
45 done
46 _scratch_cycle_mount
47
48 echo "Compare files"
49 md5sum $testdir/file1 | _filter_scratch
50 md5sum $testdir/file3 | _filter_scratch
51 md5sum $testdir/file3.chk | _filter_scratch
52
53 echo "CoW and unmount"
54 cowoff=$((filesize / 4))
55 cowsz=$((filesize / 2))
56 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $cowsz $cowoff $cowsz" $testdir/file3 >> $seqres.full
57 rm $testdir/file3
58
59 # success, all done
60 status=0
61 exit