common/rc: factor out _scratch_xfs_[get|set]_sb_field
[xfstests-dev.git] / tests / xfs / 327
1 #! /bin/bash
2 # FS QA Test No. 327
3 #
4 # Create 100 reflinked files, CoW them all, and see if xfs_repair will
5 # clear the reflink flag.  There was a buffer handling bug in xfs_repair
6 # that (fortunately) triggered asserts in the rmap code when clearing
7 # the reflink flag.
8 #
9 #-----------------------------------------------------------------------
10 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
11 #
12 # This program is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as
14 # published by the Free Software Foundation.
15 #
16 # This program is distributed in the hope that it would be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 # GNU General Public License for more details.
20 #
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write the Free Software Foundation,
23 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24 #-----------------------------------------------------------------------
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1    # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37         cd /
38         _scratch_unmount > /dev/null 2>&1
39         rm -rf $tmp.*
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45 . ./common/reflink
46
47 # real QA test starts here
48 _supported_os Linux
49 _supported_fs xfs
50 _require_cp_reflink
51 _require_scratch_reflink
52
53 rm -f $seqres.full
54
55 nr=128 # spanning at least one inode chunk tickles a bug in xfs_repair
56 echo "Format filesystem"
57 _scratch_mkfs >/dev/null 2>&1
58 _scratch_mount >> $seqres.full
59
60 echo "Create files"
61 _pwrite_byte 0x66 0 1 $SCRATCH_MNT/file.0 >> $seqres.full
62 seq 1 $nr | while read i; do
63         _cp_reflink $SCRATCH_MNT/file.0 $SCRATCH_MNT/file.$i
64 done
65 sync
66
67 echo "Check files"
68 for i in 0 $((nr / 2)) $nr; do
69         md5sum $SCRATCH_MNT/file.$i | _filter_scratch
70         $XFS_IO_PROG -c 'lsattr -v' $SCRATCH_MNT/file.$i | _filter_scratch
71 done
72
73 echo "CoW all files"
74 seq 1 $nr | while read i; do
75         echo m >> $SCRATCH_MNT/file.$i
76 done
77
78 echo "Repair filesystem"
79 _scratch_unmount
80 _repair_scratch_fs >> $seqres.full
81 _scratch_mount
82
83 echo "Check files again"
84 for i in 0 $((nr / 2)) $nr; do
85         md5sum $SCRATCH_MNT/file.$i | _filter_scratch
86         $XFS_IO_PROG -c 'lsattr -v' $SCRATCH_MNT/file.$i | _filter_scratch
87 done
88
89 echo "Done"
90
91 # success, all done
92 status=0
93 exit