fstests: convert remaining tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 212
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. 212
6 #
7 # Test recovery of "lost" CoW blocks after a crash:
8 # - Create two reflinked files.  Set extsz hint on second file.
9 # - Dirty one byte on the second file and fsync.
10 # - Crash the FS to test recovery.
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1    # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23     cd /
24     rm -rf $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/reflink
31
32 # real QA test starts here
33 _supported_os Linux
34 _supported_fs xfs
35 _require_scratch_reflink
36 _require_cp_reflink
37 _require_xfs_io_command "fiemap"
38
39 rm -f $seqres.full
40
41 echo "Format and mount"
42 _scratch_mkfs > $seqres.full 2>&1
43 _scratch_mount >> $seqres.full 2>&1
44
45 testdir=$SCRATCH_MNT/test-$seq
46 mkdir $testdir
47
48 blksz=65536
49 nr=16
50 filesize=$((blksz * nr))
51 bufnr=2
52 bufsize=$((blksz * bufnr))
53
54 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
55
56 echo "Create the original files"
57 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file1 >> $seqres.full
58 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file2.chk >> $seqres.full
59 $XFS_IO_PROG -f -c "extsize $bufsize" $testdir/file2
60 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
61 _scratch_cycle_mount
62
63 echo "Compare files"
64 md5sum $testdir/file1 | _filter_scratch
65 md5sum $testdir/file2 | _filter_scratch
66 md5sum $testdir/file2.chk | _filter_scratch
67
68 echo "CoW and leave leftovers"
69 $XFS_IO_PROG -f -c "extsize" $testdir/file2 >> $seqres.full
70 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((filesize - 1)) 1" -c "fsync" $testdir/file2 >> $seqres.full
71 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((filesize - 1)) 1" -c "fsync" $testdir/file2.chk >> $seqres.full
72 sync
73
74 echo "Crash and recover"
75 $XFS_IO_PROG -x -c "shutdown" $testdir/file2 >> $seqres.full
76 _scratch_cycle_mount
77
78 echo "Compare files"
79 md5sum $testdir/file1 | _filter_scratch
80 md5sum $testdir/file2 | _filter_scratch
81 md5sum $testdir/file2.chk | _filter_scratch
82
83 # success, all done
84 status=0
85 exit