Whamcloud - gitweb
LU-8998 tests: test scripts for PFL
[fs/lustre-release.git] / lustre / tests / sanity-pfl.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 set -e
6
7 SRCDIR=$(dirname $0)
8 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
9
10 ONLY=${ONLY:-"$*"}
11 # Bug number for skipped test:
12 ALWAYS_EXCEPT="$SANITY_PFL_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
16         echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
17
18 TMP=${TMP:-/tmp}
19 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
20
21 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
22 . $LUSTRE/tests/test-framework.sh
23 init_test_env $@
24 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
25 init_logging
26
27 check_and_setup_lustre
28
29 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.51) ]]; then
30         skip_env "Need MDS version at least 2.9.51" && exit
31 fi
32
33 build_test_filter
34
35 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
36         error "\$RUNAS_ID set to 0, but \$UID is also 0!"
37 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
38
39 test_0() {
40         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
41
42         local comp_file=$DIR/$tfile
43         local rw_len=$((3 * 1024 * 1024))       # 3M
44
45         rm -f $comp_file
46
47         $LFS setstripe -E 1m -S 1M -c 1 -E -1 -c 1 $comp_file ||
48                 error "Create $comp_file failed"
49
50         local ost_idx1=$($LFS getstripe -I 1 -i $comp_file)
51         local ost_idx2=$($LFS getstripe -I 2 -i $comp_file)
52
53         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
54
55         small_write $comp_file $rw_len || error "Verify RW failed"
56
57         rm -f $comp_file || error "Delete $comp_file failed"
58 }
59 run_test 0 "Create full components file, no reused OSTs"
60
61 test_1() {
62         local comp_file=$DIR/$tfile
63         local rw_len=$((3 * 1024 * 1024))       # 3M
64
65         rm -f $comp_file
66
67         $LFS setstripe -E 1m -S 1m -o 0 -E -1 -o 0 $comp_file ||
68                 error "Create $comp_file failed"
69
70         local ost_idx1=$($LFS getstripe -I 1 -i $comp_file)
71         local ost_idx2=$($LFS getstripe -I 2 -i $comp_file)
72
73         [ $ost_idx1 -ne $ost_idx2 ] && error "$ost_idx1 != $ost_idx2"
74
75         small_write $comp_file $rw_len || error "Verify RW failed"
76
77         rm -f $comp_file || error "Delete $comp_file failed"
78 }
79 run_test 1 "Create full components file, reused OSTs"
80
81 test_2() {
82         local comp_file=$DIR/$tfile
83         local rw_len=$((5 * 1024 * 1024))       # 5M
84
85         rm -f $comp_file
86
87         $LFS setstripe -E 1m -S 1m $comp_file ||
88                 error "Create $comp_file failed"
89
90         local comp_cnt=$($LFS getstripe --component-count $comp_file)
91         [ $comp_cnt -ne 1 ] && error "component count $comp_cnt != 1"
92
93         dd if=/dev/zero of=$comp_file bs=1M count=1 > /dev/null 2>&1 ||
94                 error "Write first component failed"
95         dd if=$comp_file of=/dev/null bs=1M count=1 > /dev/null 2>&1 ||
96                 error "Read first component failed"
97
98         dd if=/dev/zero of=$comp_file bs=1M count=2 > /dev/null 2>&1 &&
99                 error "Write beyond component should fail"
100         dd if=$comp_file of=/dev/null bs=1M count=2 > /dev/null 2>&1 &&
101                 error "Read beyond component should fail"
102
103         $LFS setstripe --component-add -E 2M -c 1 $comp_file ||
104                 error "Add component to $comp_file failed"
105
106         comp_cnt=$($LFS getstripe --component-count $comp_file)
107         [ $comp_cnt -ne 2 ] && error "component count $comp_cnt != 2"
108
109         $LFS setstripe --component-add -E -1 -c 3 $comp_file ||
110                 error "Add last component to $comp_file failed"
111
112         comp_cnt=$($LFS getstripe --component-count $comp_file)
113         [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
114
115         small_write $comp_file $rw_len || error "Verify RW failed"
116
117         rm -f $comp_file || error "Delete $comp_file failed"
118 }
119 run_test 2 "Add component to existing file"
120
121 del_comp_and_verify() {
122         local comp_file=$1
123         local id=$2
124         local left=$3
125         local size=$4
126
127         local opt="-I"
128         if [ $id == "init" ]; then
129                 opt="--component-flags"
130         fi
131
132         $LFS setstripe --component-del $opt $id $comp_file ||
133                 error "Delete component $id from $comp_file failed"
134
135         local comp_cnt=$($LFS getstripe --component-count $comp_file)
136         if grep -q "has no stripe info" <<< "$comp_cnt" ; then
137                 comp_cnt=0
138         fi
139         [ $comp_cnt -ne $left ] && error "$comp_cnt != $left"
140
141         $CHECKSTAT -s $size $comp_file || error "size != $size"
142 }
143
144 test_3() {
145         local comp_file=$DIR/$tfile
146
147         rm -f $comp_file
148
149         $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 3 $comp_file ||
150                 error "Create $comp_file failed"
151
152         local comp_cnt=$($LFS getstripe --component-count $comp_file)
153         [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
154
155         dd if=/dev/zero of=$comp_file bs=1M count=2
156
157         $LFS setstripe --component-del -I 2 $comp_file &&
158                 error "Component deletion makes hole"
159
160         del_comp_and_verify $comp_file 3 2 $((2 * 1024 * 1024))
161         del_comp_and_verify $comp_file 2 1 $((1 * 1024 * 1024))
162         del_comp_and_verify $comp_file 1 0 0
163
164         rm -f $comp_file || error "Delete $comp_file failed"
165
166         $LFS setstripe -E 1M -E 16M -E -1 $comp_file ||
167                 error "Create second $comp_file failed"
168
169         del_comp_and_verify $comp_file "init" 0 0
170         rm -f $comp_file || error "Delete second $comp_file failed"
171 }
172 run_test 3 "Delete component from existing file"
173
174 test_4() {
175         skip "Not supported in PFL" && return
176         # In PFL project, only LCME_FL_INIT is supported, and it can't
177         # be altered by application.
178 }
179 run_test 4 "Modify component flags in existing file"
180
181 test_5() {
182         local parent=$DIR/$tdir
183         local comp_file=$DIR/$tdir/$tfile
184         local subdir=$parent/subdir
185
186         rm -fr $parent
187         mkdir -p $parent || error "Create dir $parent failed"
188
189         # set default layout to parent directory
190         $LFS setstripe -E 64M -c 2 -i 0 -E -1 -c 4 -i 0 $parent ||
191                 error "Set default layout to $parent failed"
192
193         # create file under parent
194         touch $comp_file || error "Create $comp_file failed"
195         local comp_cnt=$($LFS getstripe --component-count $comp_file)
196         [ $comp_cnt -ne 2 ] && error "file $comp_cnt != 2"
197
198         local ost_idx=$($LFS getstripe -I 1 -i $comp_file)
199         [ $ost_idx -ne 0 ] &&
200                 error "component 1 ost_idx $ost_idx != 0"
201
202         ost_idx=$($LFS getstripe -I 2 -i $comp_file)
203         [ $ost_idx -ne 0 ] &&
204                 error "component 2 ost_idx $ost_idx != 0"
205
206         # create subdir under parent
207         mkdir -p $subdir || error "Create subdir $subdir failed"
208
209         comp_cnt=$($LFS getstripe -d --component-count $subdir)
210         [ $comp_cnt -ne 2 ] && error "subdir $comp_cnt != 2"
211
212         # create file under subdir
213         touch $subdir/$tfile || error "Create $subdir/$tfile failed"
214
215         comp_cnt=$($LFS getstripe --component-count $subdir/$tfile)
216         [ $comp_cnt -ne 2 ] && error "$subdir/$tfile $comp_cnt != 2"
217
218         # delete default layout setting from parent
219         $LFS setstripe -d $parent ||
220                 error "Delete default layout from $parent failed"
221
222         comp_cnt=$($LFS getstripe -d --component-count $parent)
223         [ ! -z "$comp_cnt" ] && error "$comp_cnt isn't empty"
224
225         rm -f $comp_file || error "Delete $comp_file failed"
226         rm -f $subdir/$tfile || error "Delete $subdir/$tfile failed"
227         rm -r $subdir || error "Delete subdir $subdir failed"
228         rmdir $parent || error "Delete dir $parent failed"
229 }
230 run_test 5 "Inherit composite layout from parent directory"
231
232 test_6() {
233         local comp_file=$DIR/$tfile
234
235         rm -f $DIR/$tfile
236
237         $LFS setstripe -c 1 -S 128K $comp_file ||
238                 error "Create v1 $comp_file failed"
239
240         local comp_cnt=$($LFS getstripe --component-count $comp_file)
241         [ ! -z "$comp_cnt" ] && error "Wrong component count $comp_cnt"
242
243         dd if=/dev/urandom of=$comp_file bs=1M count=5 oflag=sync ||
244                 error "Write to v1 $comp_file failed"
245
246         local old_chksum=$(md5sum $comp_file)
247
248         # Migrate v1 to composite
249         $LFS migrate -E 1M -S 512K -c 1 -E -1 -S 1M -c 2 $comp_file ||
250                 error "Migrate(v1 -> composite) $comp_file failed"
251
252         comp_cnt=$($LFS getstripe --component-count $comp_file)
253         [ "$comp_cnt" -ne 2 ] && error "$comp_cnt != 2"
254
255         local chksum=$(md5sum $comp_file)
256         [ "$old_chksum" != "$chksum" ] &&
257                 error "(v1 -> compsoite) $old_chksum != $chksum"
258
259         # Migrate composite to composite
260         $LFS migrate -E 1M -S 1M -c 2 -E 4M -S 1M -c 2 \
261                 -E -1 -S 3M -c 3 $comp_file ||
262                 error "Migrate(compsoite -> composite) $comp_file failed"
263
264         comp_cnt=$($LFS getstripe --component-count $comp_file)
265         [ "$comp_cnt" -ne 3 ] && error "$comp_cnt != 3"
266
267         chksum=$(md5sum $comp_file)
268         [ "$old_chksum" != "$chksum" ] &&
269                 error "(composite -> compsoite) $old_chksum != $chksum"
270
271         # Migrate composite to v1
272         $LFS migrate -c 2 -S 2M $comp_file ||
273                 error "Migrate(composite -> v1) $comp_file failed"
274
275         comp_cnt=$($LFS getstripe --component-count $comp_file)
276         [ ! -z "$comp_cnt" ] && error "$comp_cnt isn't empty"
277
278         chksum=$(md5sum $comp_file)
279         [ "$old_chksum" != "$chksum" ] &&
280                 error "(composite -> v1) $old_chksum != $chksum"
281
282         rm -f $comp_file || "Delete $comp_file failed"
283 }
284 run_test 6 "Migrate composite file"
285
286 test_7() {
287         mkdir -p $DIR/$tdir || error "mkdir failed"
288         chmod 0777 $DIR/$tdir || error "chmod $tdir failed"
289
290         local comp_file=$DIR/$tdir/$tfile
291         $RUNAS $LFS setstripe -E 1M -c 1 $comp_file ||
292                 error "Create composite file $comp_file failed"
293
294         $RUNAS $LFS setstripe --component-add -E 64M -c 4 $comp_file ||
295                 error "Add component to $comp_file failed"
296
297         $RUNAS $LFS setstripe --component-del -I 2 $comp_file ||
298                 error "Delete component from $comp_file failed"
299
300         $RUNAS $LFS setstripe --component-add -E -1 -c 5 $comp_file ||
301                 error "Add last component to $comp_file failed"
302
303         rm $comp_file || "Delete composite failed"
304 }
305 run_test 7 "Add/Delete/Create composite file by non-privileged user"
306
307 test_8() {
308         local parent=$DIR/$tdir
309
310         rm -fr $parent
311         mkdir -p $parent || error "Create dir $parent failed"
312
313         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c 2 -S 2M \
314                 -E -1 -c 4 -S 4M $parent ||
315                 error "Set default layout to $parent failed"
316
317         sh rundbench -C -D $parent 2 || error "debench failed"
318
319         rm -fr $parent || error "Delete dir $parent failed"
320 }
321 run_test 8 "Run debench over composite files"
322
323 test_9() {
324         local comp_file=$DIR/$tfile
325
326         rm -f $comp_file
327
328         $LFS setstripe -E 1m -S 1m $comp_file ||
329                 error "Create $comp_file failed"
330
331         local comp_cnt=$($LFS getstripe --component-count $comp_file)
332         [ $comp_cnt -ne 1 ] && error "component count $comp_cnt != 1"
333
334         replay_barrier $SINGLEMDS
335
336         $LFS setstripe --component-add -E 2M -c 1 $comp_file ||
337                 error "Add component to $comp_file failed"
338
339         local f1=$($LFS getstripe -I 2 $comp_file |
340                         awk '/l_fid:/ {print $7}')
341
342         fail $SINGLEMDS
343
344         local f2=$($LFS getstripe -I 2 $comp_file |
345                         awk '/l_fid:/ {print $7}')
346         [ $f1 == $f2 ] || error "$f1 != $f2"
347 }
348 run_test 9 "Replay component add"
349
350 component_dump() {
351         echo $($LFS getstripe $1 |
352                 awk '$1 == "lcm_entry_count:" { printf("%d", $2) }
353                      $1 == "lcme_extent.e_start:" { printf("[%#lx", $2) }
354                      $1 == "lcme_extent.e_end:" { printf(",%s]", $2) }')
355 }
356
357 test_10() {
358         local parent=$DIR/$tdir
359
360         rm -rf $parent
361         $LFS setstripe -d $MOUNT || error "clear root layout"
362
363         # set root composite layout
364         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c2 -S 2M \
365                 -E -1 -c 4 -S 4M $MOUNT ||
366                 error "Set root layout failed"
367
368         mkdir -p $parent || error "Create dir $parent failed"
369         # set a different layout for parent
370         $LFS setstripe -E -1 -c 1 -S 1M $parent ||
371                 error "set $parent layout failed"
372         touch $parent/file1
373
374         local f1_entry=$(component_dump $parent/file1)
375
376         # delete parent's layout
377         $LFS setstripe -d $parent || error "Clear $parent layout failed"
378         touch $parent/file2
379
380         local f2_entry=$(component_dump $parent/file2)
381
382         # verify layout inheritance
383         local eof="EOF"
384         local f1_expect="1[0,EOF]"
385         local f2_expect="3[0,2097152][0x200000,16777216][0x1000000,EOF]"
386
387         echo "f1 expect=$f1_expect"
388         echo "f1 get   =$f1_entry"
389         echo "f2 expect=$f2_expect"
390         echo "f2 get   =$f2_entry"
391
392         [  x$f1_expect != x$f1_entry ] &&
393                 error "$parent/file1 does not inherite parent layout"
394         [  x$f2_expect != x$f2_entry ] &&
395                 error "$parent/file2 does not inherite root layout"
396         return 0
397 }
398 run_test 10 "Inherit composite template from root"
399
400 complete $SECONDS
401 check_and_cleanup_lustre
402 exit_status