generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 254
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. 254
6 #
7 # Punch a file at midway through a CoW region.
8 #
9 # This test is dependent on the system page size, so we cannot use md5 in
10 # the golden output; we can only compare to a check file.
11 #
12 . ./common/preamble
13 _begin_fstest auto quick clone punch
14
15 # Import common functions.
16 . ./common/filter
17 . ./common/reflink
18
19 # real QA test starts here
20 _require_scratch_reflink
21 _require_cp_reflink
22 _require_xfs_io_command "fpunch"
23
24 echo "Format and mount"
25 _scratch_mkfs > $seqres.full 2>&1
26 _scratch_mount >> $seqres.full 2>&1
27
28 testdir=$SCRATCH_MNT/test-$seq
29 mkdir $testdir
30
31 blksz=65536
32 nr=5
33 filesize=$((blksz * nr))
34
35 echo "Create the original files"
36 _pwrite_byte 0x61 0 $filesize $testdir/file1 >> $seqres.full
37 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
38 _pwrite_byte 0x61 0 $filesize $testdir/file2.chk >> $seqres.full
39 _scratch_cycle_mount
40
41 echo "Compare files"
42 md5sum $testdir/file1 | _filter_scratch
43 md5sum $testdir/file2 | _filter_scratch
44 md5sum $testdir/file2.chk | _filter_scratch
45
46 echo "CoW and unmount"
47 $XFS_IO_PROG -f -c "pwrite -S 0x62 -b $((blksz * 3)) $blksz $((blksz * 3))" -c "fpunch $((blksz * 2)) $blksz" $testdir/file2 >> $seqres.full
48 _scratch_cycle_mount
49 $XFS_IO_PROG -f -c "pwrite -S 0x62 -b $((blksz * 3)) $blksz $((blksz * 3))" -c "pwrite -S 0x00 $((blksz * 2)) $blksz" $testdir/file2.chk >> $seqres.full
50 _scratch_cycle_mount
51
52 echo "Compare files"
53 md5sum $testdir/file1 | _filter_scratch
54 md5sum $testdir/file2 | _filter_scratch
55 md5sum $testdir/file2.chk | _filter_scratch
56
57 # success, all done
58 status=0
59 exit