xfs/007: fix regressions on V4 filesystems
[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 . ./common/preamble
13 _begin_fstest shutdown auto quick clone
14
15 # Import common functions.
16 . ./common/filter
17 . ./common/reflink
18
19 # real QA test starts here
20 _supported_fs xfs
21 _require_scratch_reflink
22 _require_cp_reflink
23 _require_xfs_io_command "fiemap"
24
25 echo "Format and mount"
26 _scratch_mkfs > $seqres.full 2>&1
27 _scratch_mount >> $seqres.full 2>&1
28
29 testdir=$SCRATCH_MNT/test-$seq
30 mkdir $testdir
31
32 blksz=65536
33 nr=16
34 filesize=$((blksz * nr))
35 bufnr=2
36 bufsize=$((blksz * bufnr))
37
38 _require_fs_space $SCRATCH_MNT $((filesize / 1024 * 3 * 5 / 4))
39
40 echo "Create the original files"
41 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file1 >> $seqres.full
42 $XFS_IO_PROG -f -c "pwrite -S 0x61 -b $bufsize 0 $filesize" $testdir/file2.chk >> $seqres.full
43 $XFS_IO_PROG -f -c "extsize $bufsize" $testdir/file2
44 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
45 _scratch_cycle_mount
46
47 echo "Compare files"
48 md5sum $testdir/file1 | _filter_scratch
49 md5sum $testdir/file2 | _filter_scratch
50 md5sum $testdir/file2.chk | _filter_scratch
51
52 echo "CoW and leave leftovers"
53 $XFS_IO_PROG -f -c "extsize" $testdir/file2 >> $seqres.full
54 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((filesize - 1)) 1" -c "fsync" $testdir/file2 >> $seqres.full
55 $XFS_IO_PROG -f -c "pwrite -S 0x63 $((filesize - 1)) 1" -c "fsync" $testdir/file2.chk >> $seqres.full
56 sync
57
58 echo "Crash and recover"
59 $XFS_IO_PROG -x -c "shutdown" $testdir/file2 >> $seqres.full
60 _scratch_cycle_mount
61
62 echo "Compare files"
63 md5sum $testdir/file1 | _filter_scratch
64 md5sum $testdir/file2 | _filter_scratch
65 md5sum $testdir/file2.chk | _filter_scratch
66
67 # success, all done
68 status=0
69 exit