xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / xfs / 148
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0-or-newer
3 # Copyright (c) 2019, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 148
6 #
7 # See if we catch corrupt directory names or attr names with nulls or slashes
8 # in them.
9
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1    # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21         cd /
22         $UMOUNT_PROG $mntpt > /dev/null 2>&1
23         test -n "$loopdev" && _destroy_loop_device $loopdev > /dev/null 2>&1
24         rm -r -f $imgfile $mntpt $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30 . ./common/attr
31
32 # real QA test starts here
33 _supported_fs xfs
34 _require_test
35 _require_attrs
36 _require_xfs_mkfs_crc
37 _disable_dmesg_check
38
39 rm -f $seqres.full
40
41 imgfile=$TEST_DIR/img-$seq
42 mntpt=$TEST_DIR/mount-$seq
43 testdir=$mntpt/testdir
44 testfile=$mntpt/testfile
45 nullstr="too_many_beans"
46 slashstr="are_bad_for_you"
47 test_names=("something" "$nullstr" "$slashstr" "another")
48
49 # Format image file w/o crcs so we can sed the image file
50 $XFS_IO_PROG -f -c 'truncate 40m' $imgfile
51 loopdev=$(_create_loop_device $imgfile)
52 MKFS_OPTIONS="-m crc=0" _mkfs_dev $loopdev >> $seqres.full
53
54 # Mount image file
55 mkdir -p $mntpt
56 _mount $loopdev $mntpt
57
58 echo "creating entries" >> $seqres.full
59
60 # Create directory entries
61 mkdir -p $testdir
62 for name in "${test_names[@]}"; do
63         touch "$testdir/f_$name"
64 done
65
66 # Create attrs
67 touch $testfile
68 for name in "${test_names[@]}"; do
69         $ATTR_PROG -s "a_$name" -V heh $testfile >> $seqres.full
70 done
71
72 # Now put in the first part of the garbage names to make sure we can't
73 # access those directly
74 test_names+=("too_many" "are_bad/for_you")
75
76 access_stuff() {
77         ls $testdir
78         $ATTR_PROG -l $testfile | grep 'a_' | sort
79
80         for name in "${test_names[@]}"; do
81                 ls "$testdir/f_$name"
82                 $ATTR_PROG -g "a_$name" $testfile
83         done
84 }
85
86 # Does it work?
87 echo "++ ACCESSING GOOD METADATA" | tee -a $seqres.full
88 access_stuff > $tmp.log 2>&1
89 cat $tmp.log >> $seqres.full
90 cat $tmp.log | _filter_test_dir
91
92 # Corrupt the entries
93 $UMOUNT_PROG $mntpt
94 _destroy_loop_device $loopdev
95 cp $imgfile $imgfile.old
96 sed -b \
97         -e "s/$nullstr/too_many\x00beans/g" \
98         -e "s/$slashstr/are_bad\/for_you/g" \
99         -i $imgfile
100 test "$(md5sum < $imgfile)" != "$(md5sum < $imgfile.old)" ||
101         _fail "sed failed to change the image file?"
102 rm -f $imgfile.old
103 loopdev=$(_create_loop_device $imgfile)
104 _mount $loopdev $mntpt
105
106 # Try to access the corrupt metadata
107 echo "++ ACCESSING BAD METADATA" | tee -a $seqres.full
108 access_stuff > $tmp.log 2>&1
109 cat $tmp.log >> $seqres.full
110 cat $tmp.log | _filter_test_dir | sed -e '/Could not list/d'
111
112 echo "does scrub complain?" >> $seqres.full
113
114 # Does scrub complain about this?
115 if _supports_xfs_scrub $mntpt $loopdev; then
116         $XFS_SCRUB_PROG -n $mntpt >> $seqres.full 2>&1
117         res=$?
118         test $((res & 1)) -eq 0 && \
119                 echo "scrub failed to report corruption ($res)"
120 fi
121
122 echo "does repair complain?" >> $seqres.full
123
124 # Does repair complain about this?
125 $UMOUNT_PROG $mntpt
126 $XFS_REPAIR_PROG -n $loopdev >> $seqres.full 2>&1
127 res=$?
128 test $res -eq 1 || \
129         echo "repair failed to report corruption ($res)"
130
131 _destroy_loop_device $loopdev
132 loopdev=
133
134 # success, all done
135 status=0
136 exit