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