overlay: run unionmount testsuite test cases
[xfstests-dev.git] / tests / xfs / 253
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2011 SGI.  All Rights Reserved.
4 #
5 # FS QA Test No. 253
6 #
7 # Test xfs_db metadump functionality.
8 #
9 # This test was created to verify fixes for problems where metadump
10 # would never complete due to an inability to find a suitable
11 # obfuscated name to use.  It also verifies a few other things,
12 # including ensuring the "lost+found" directory and orphaned files
13 # in it do not get obfuscated.
14 #
15 # This test also creates a number of files that are effectively
16 # duplicates of existing files; this can happen in certain rare
17 # instances where the obfuscation process has produced a filename
18 # that is already in use (and no other name is available to use).
19 #
20 seq=`basename $0`
21 seqres=$RESULT_DIR/$seq
22 echo "QA output created by $seq"
23
24 here=`pwd`
25 tmp=/tmp/$$
26 status=1        # failure is the default!
27 trap "_cleanup; exit \$status" 0 1 2 3 15
28
29 _cleanup()
30 {
31     cd /
32     rm -f $tmp.*
33     rm -rf "${OUTPUT_DIR}"
34     rm -f "${METADUMP_FILE}"
35 }
36
37 # get standard environment, filters and checks
38 . ./common/rc
39 . ./common/filter
40
41 _require_test
42 _require_scratch
43
44 # real QA test starts here
45
46 OUTPUT_DIR="${SCRATCH_MNT}/test_${seq}"
47 METADUMP_FILE="${TEST_DIR}/${seq}_metadump"
48 ORPHANAGE="lost+found"
49
50 _supported_fs xfs
51 _supported_os Linux
52
53 function create_file() {
54         [ $# -eq 1 ] ||         return 1
55         touch $(printf "$@")
56 }
57
58 echo "Disciplyne of silence is goed."
59
60 rm -f $seqres.full
61
62 _scratch_mkfs >/dev/null 2>&1
63 _scratch_mount
64
65 # Initialize and mount the scratch filesystem, then create a bunch
66 # of files that exercise the original problem.
67 #
68 # The problem arose when a file name produced a hash that contained
69 # either 0x00 (string terminator) or 0x27 ('/' character) in a
70 # spot used to determine a character in an obfuscated name.  This
71 # occurred in one of 5 spots at the end of the name, at position
72 # (last-4), (last-3), (last-2), (last-1), or (last).
73
74 rm -f "${METADUMP_FILE}"
75
76 mkdir -p "${OUTPUT_DIR}"
77
78 cd "${OUTPUT_DIR}"
79 # Start out with some basic test files
80 create_file 'abcde'             # hash 0x1c58f263 ("normal" name)
81
82 create_file 'f'                 # hash 0x00000066 (1-byte name)
83 create_file 'gh'                # hash 0x000033e8 (2-byte name)
84 create_file 'ijk'               # hash 0x001a756b (3-byte name)
85 create_file 'lmno'              # hash 0x0d9b776f (4-byte name)
86 create_file 'pqrstu'            # hash 0x1e5cf9f2 (6-byte name)
87 create_file 'abcdefghijklmnopqrstuvwxyz' # a most remarkable word (0x55004ae3)
88
89 # Create a short directory name; it won't be obfuscated.  Populate
90 # it with some longer named-files.  The first part of the obfuscated
91 # filenames should use printable characters.
92 mkdir foo
93 create_file 'foo/longer_file_name_1'    # hash 0xe83634ec
94 create_file 'foo/longer_file_name_2'    # hash 0xe83634ef
95 create_file 'foo/longer_file_name_3'    # hash 0xe83634ee
96
97 # Now create a longer directory name
98 mkdir longer_directory_name
99 create_file 'longer_directory_name/f1'  # directory hash 0x9c7accdd
100 create_file 'longer_directory_name/f2'  # filenames are short, no hash
101 create_file 'longer_directory_name/f3'
102
103 # The problematic name originally reported by Arkadiusz Miƛkiewicz
104
105 create_file 'R\323\257NE'       # hash 0x3a4be740, forces  (last-3) = 0x2f
106
107 # Other names that force a 0x00 byte
108 create_file 'Pbcde'             # hash 0x0c58f260, forces  (last-4) = 0x00
109 create_file 'a\001\203de'       # hash 0x1000f263, forces  (last-3) = 0x00
110 create_file 'ab\001\344e'       # hash 0x1c403263, forces  (last-2) = 0x00
111 create_file 'abc\200e'          # hash 0x1c588063, forces  (last-1) = 0x00
112 create_file 'abcd\006'          # hash 0x1c58f200, forces    (last) = 0x00
113
114 # Names that force a 0x2f byte; note no name will ever force (last-4) = 0x2f
115 create_file 'a.\343de'          # hash 0x15f8f263 forces   (last-3) = 0x00
116 create_file 'ac\257de'          # hash 0x1c4bf263, forces  (last-2) = 0x2f
117 create_file 'abe\257e'          # hash 0x1c5917e3, forces  (last-1) = 0x2f
118 create_file 'abcd)'             # hash 0x1c58f22f, forces    (last) = 0x2f
119
120 # The following names are possible results of obfuscating the name
121 # "abcde".  Previously, xfs_metadump could get hung up trying to
122 # obfuscate names when too many of the same length had the same hash
123 # value.
124 create_file '!bcda'             # essentially a dup of 'abcde'
125 create_file 'Abcdg'             # essentially a dup of 'abcde'
126 create_file 'qbcdd'             # essentially a dup of 'abcde'
127 create_file '1bcd`'             # essentially a dup of 'abcde'
128 create_file 'Qbcdf'             # essentially a dup of 'abcde'
129 create_file '\001bcdc'          # essentially a dup of 'abcde'
130 create_file 'Qbce\346'          # essentially a dup of 'abcde'
131 create_file 'abb\344e'          # essentially a dup of 'abcde'
132
133 # The orphanage directory (lost+found) should not be obfuscated.
134 # Files thereunder can be, but not if their name is the same as
135 # their inode number.  Test this.
136
137 cd "${SCRATCH_MNT}"
138 mkdir -p "${ORPHANAGE}"
139
140 TEMP_ORPHAN="${ORPHANAGE}/__orphan__"
141 NON_ORPHAN="${ORPHANAGE}/__should_be_obfuscated__"
142
143 # Create an orphan, whose name is the same as its inode number
144 touch "${TEMP_ORPHAN}"
145 INUM=$(ls -i "${TEMP_ORPHAN}" | awk '{ print $1; }')
146 ORPHAN="${SCRATCH_MNT}/lost+found/${INUM}"
147 mv "${TEMP_ORPHAN}" "${ORPHAN}"
148
149 # Create non-orphan, which *should* be obfuscated
150 touch "${NON_ORPHAN}"
151
152 # Get a listing of all the files before obfuscation
153 ls -R >> $seqres.full
154 ls -R | od -c >> $seqres.full
155
156 # Now unmount the filesystem and create a metadump file
157 cd $here
158
159 _scratch_unmount
160 _scratch_metadump $METADUMP_FILE
161
162 # Now restore the obfuscated one back and take a look around
163 xfs_mdrestore "${METADUMP_FILE}" "${SCRATCH_DEV}"
164
165 _scratch_mount
166
167 # Get a listing of all the files after obfuscation
168 cd ${SCRATCH_MNT}
169 ls -R >> $seqres.full
170 ls -R | od -c >> $seqres.full
171
172 # Finally, re-make the filesystem since to ensure we don't
173 # leave a directory with duplicate entries lying around.
174 cd /
175 _scratch_unmount
176 _scratch_mkfs >/dev/null 2>&1
177
178 # all done
179 status=0
180 exit