generic: test for file loss after mix of rename, fsync and inode eviction
[xfstests-dev.git] / tests / generic / 296
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. 296
6 #
7 # - Create two reflinked files a byte longer than a block.
8 # - Rewrite the whole file.
9 #
10 . ./common/preamble
11 _begin_fstest auto quick clone
12
13 # Import common functions.
14 . ./common/filter
15 . ./common/reflink
16
17 # real QA test starts here
18 _require_scratch_reflink
19 _require_cp_reflink
20
21 echo "Format and mount"
22 _scratch_mkfs > $seqres.full 2>&1
23 _scratch_mount >> $seqres.full 2>&1
24
25 testdir=$SCRATCH_MNT/test-$seq
26 mkdir $testdir
27
28 blksz=65536
29 nr=128
30 filesize=$((blksz * nr))
31 bufnr=16
32 bufsize=$((blksz * bufnr))
33
34 real_blksz=$(_get_block_size "$testdir")
35 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
36
37 echo "Create the original files"
38 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file1 >> $seqres.full
39 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
40 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $((filesize + 1))" $testdir/file2.chk >> $seqres.full
41 _scratch_cycle_mount
42
43 echo "Compare files"
44 md5sum $testdir/file1 | _filter_scratch
45 md5sum $testdir/file2 | _filter_scratch
46 md5sum $testdir/file2.chk | _filter_scratch
47
48 echo "CoW and unmount"
49 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file2 >> $seqres.full
50 $XFS_IO_PROG -f -c "pwrite -S 0x63 -b $real_blksz 0 $((filesize + 1))" -c "fdatasync" $testdir/file2.chk >> $seqres.full
51 _scratch_cycle_mount
52
53 echo "Compare files"
54 md5sum $testdir/file1 | _filter_scratch
55 md5sum $testdir/file2 | _filter_scratch
56 md5sum $testdir/file2.chk | _filter_scratch
57
58 # success, all done
59 status=0
60 exit