xfs: test what happens when we reset the root dir and it has xattrs
[xfstests-dev.git] / tests / xfs / 179
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. 179
6 #
7 # See how well reflink handles overflowing reflink counts.
8 #
9 seq=`basename $0`
10 seqres=$RESULT_DIR/$seq
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1    # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20     cd /
21     rm -rf $tmp.*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27 . ./common/attr
28 . ./common/reflink
29
30 # real QA test starts here
31 _supported_fs xfs
32 _require_scratch_reflink
33 _require_scratch_nocheck
34 _require_cp_reflink
35 _require_test_program "punch-alternating"
36
37 rm -f $seqres.full
38
39 echo "Format and mount"
40 _scratch_mkfs -d agcount=1 > $seqres.full 2>&1
41 _scratch_mount >> $seqres.full 2>&1
42
43 testdir=$SCRATCH_MNT/test-$seq
44 mkdir $testdir
45
46 blksz=65536
47
48 echo "Create original files"
49 _pwrite_byte 0x61 0 $blksz $testdir/file1 >> $seqres.full
50 _cp_reflink $testdir/file1 $testdir/file2 >> $seqres.full
51
52 echo "Change reference count"
53 _scratch_unmount
54 echo "set refcount to -4" >> $seqres.full
55 _scratch_xfs_db -x -c 'agf 0' -c 'addr refcntroot' -c 'write recs[1].refcount 4294967292' >> $seqres.full
56 echo "check refcount after setting to -4" >> $seqres.full
57 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
58 _scratch_mount >> $seqres.full
59
60 echo "Reflink the overlinked file"
61 _cp_reflink $testdir/file1 $testdir/file3 >> $seqres.full
62 _cp_reflink $testdir/file1 $testdir/file4 >> $seqres.full
63 _cp_reflink $testdir/file1 $testdir/file5 >> $seqres.full
64 _cp_reflink $testdir/file1 $testdir/file6 >> $seqres.full
65 _cp_reflink $testdir/file1 $testdir/file7 >> $seqres.full
66
67 echo "Check scratch fs"
68 _scratch_unmount
69 echo "check refcount after reflinking 5 more times" >> $seqres.full
70 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
71 _scratch_mount >> $seqres.full
72
73 echo "CoW a couple files"
74 _pwrite_byte 0x62 0 $blksz $testdir/file3 >> $seqres.full
75 _pwrite_byte 0x62 0 $blksz $testdir/file5 >> $seqres.full
76 _pwrite_byte 0x62 0 $blksz $testdir/file7 >> $seqres.full
77
78 echo "Check scratch fs"
79 _scratch_unmount
80 echo "check refcount after cowing 3 files" >> $seqres.full
81 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
82 _scratch_mount >> $seqres.full
83
84 echo "Remove reflinked files"
85 rm -rf $testdir/file*
86
87 echo "Check scratch fs"
88 _scratch_unmount
89 echo "check refcount after removing all files" >> $seqres.full
90 _scratch_xfs_db -c 'agf 0' -c 'addr refcntroot' -c 'p recs[1]' >> $seqres.full
91 _scratch_xfs_repair -o force_geometry -n >> $seqres.full 2>&1
92 res=$?
93 if [ $res -eq 0 ]; then
94         # If repair succeeds then format the device so that the post-test
95         # check doesn't fail due to the single AG.
96         _scratch_mkfs >> $seqres.full 2>&1
97 else
98         _fail "xfs_repair fails"
99 fi
100
101 # success, all done
102 status=0
103 exit