Whamcloud - gitweb
LU-9311 tests: add sanity-pfl.sh test_13
[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         #instantiate all components, so that objs are allocted
51         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
52
53         local ost_idx1=$($LFS getstripe -I 1 -i $comp_file)
54         local ost_idx2=$($LFS getstripe -I 2 -i $comp_file)
55
56         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
57
58         small_write $comp_file $rw_len || error "Verify RW failed"
59
60         rm -f $comp_file || error "Delete $comp_file failed"
61 }
62 run_test 0 "Create full components file, no reused OSTs"
63
64 test_1() {
65         local comp_file=$DIR/$tfile
66         local rw_len=$((3 * 1024 * 1024))       # 3M
67
68         rm -f $comp_file
69
70         $LFS setstripe -E 1m -S 1m -o 0 -E -1 -o 0 $comp_file ||
71                 error "Create $comp_file failed"
72
73         #instantiate all components, so that objs are allocted
74         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
75
76         local ost_idx1=$($LFS getstripe -I 1 -i $comp_file)
77         local ost_idx2=$($LFS getstripe -I 2 -i $comp_file)
78
79         [ $ost_idx1 -ne $ost_idx2 ] && error "$ost_idx1 != $ost_idx2"
80
81         small_write $comp_file $rw_len || error "Verify RW failed"
82
83         rm -f $comp_file || error "Delete $comp_file failed"
84 }
85 run_test 1 "Create full components file, reused OSTs"
86
87 test_2() {
88         local comp_file=$DIR/$tfile
89         local rw_len=$((5 * 1024 * 1024))       # 5M
90
91         rm -f $comp_file
92
93         $LFS setstripe -E 1m -S 1m $comp_file ||
94                 error "Create $comp_file failed"
95
96         local comp_cnt=$($LFS getstripe --component-count $comp_file)
97         [ $comp_cnt -ne 1 ] && error "component count $comp_cnt != 1"
98
99         dd if=/dev/zero of=$comp_file bs=1M count=1 > /dev/null 2>&1 ||
100                 error "Write first component failed"
101         dd if=$comp_file of=/dev/null bs=1M count=1 > /dev/null 2>&1 ||
102                 error "Read first component failed"
103
104         dd if=/dev/zero of=$comp_file bs=1M count=2 > /dev/null 2>&1 &&
105                 error "Write beyond component should fail"
106         dd if=$comp_file of=/dev/null bs=1M count=2 > /dev/null 2>&1 ||
107                 error "Read beyond component should short read, not fail"
108
109         $LFS setstripe --component-add -E 2M -c 1 $comp_file ||
110                 error "Add component to $comp_file failed"
111
112         comp_cnt=$($LFS getstripe --component-count $comp_file)
113         [ $comp_cnt -ne 2 ] && error "component count $comp_cnt != 2"
114
115         $LFS setstripe --component-add -E -1 -c 3 $comp_file ||
116                 error "Add last component to $comp_file failed"
117
118         comp_cnt=$($LFS getstripe --component-count $comp_file)
119         [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
120
121         small_write $comp_file $rw_len || error "Verify RW failed"
122
123         rm -f $comp_file || error "Delete $comp_file failed"
124 }
125 run_test 2 "Add component to existing file"
126
127 del_comp_and_verify() {
128         local comp_file=$1
129         local id=$2
130         local left=$3
131         local size=$4
132
133         local opt="-I"
134         if [ $id == "init" ]; then
135                 opt="--component-flags"
136         fi
137
138         $LFS setstripe --component-del $opt $id $comp_file ||
139                 error "Delete component $id from $comp_file failed"
140
141         local comp_cnt=$($LFS getstripe --component-count $comp_file)
142         if grep -q "has no stripe info" <<< "$comp_cnt" ; then
143                 comp_cnt=0
144         fi
145         [ $comp_cnt -ne $left ] && error "$comp_cnt != $left"
146
147         $CHECKSTAT -s $size $comp_file || error "size != $size"
148 }
149
150 test_3() {
151         local comp_file=$DIR/$tfile
152
153         rm -f $comp_file
154
155         $LFS setstripe -E 1M -E 64M -c 2 -E -1 -c 3 $comp_file ||
156                 error "Create $comp_file failed"
157
158         local comp_cnt=$($LFS getstripe --component-count $comp_file)
159         [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
160
161         dd if=/dev/zero of=$comp_file bs=1M count=2
162
163         $LFS setstripe --component-del -I 2 $comp_file &&
164                 error "Component deletion makes hole"
165
166         del_comp_and_verify $comp_file 3 2 $((2 * 1024 * 1024))
167         del_comp_and_verify $comp_file 2 1 $((1 * 1024 * 1024))
168         del_comp_and_verify $comp_file 1 0 0
169
170         rm -f $comp_file || error "Delete $comp_file failed"
171
172         $LFS setstripe -E 1M -E 16M -E -1 $comp_file ||
173                 error "Create second $comp_file failed"
174
175         #instantiate all components, so that objs are allocted
176         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=17k
177
178         del_comp_and_verify $comp_file "init" 0 0
179         rm -f $comp_file || error "Delete second $comp_file failed"
180 }
181 run_test 3 "Delete component from existing file"
182
183 test_4() {
184         skip "Not supported in PFL" && return
185         # In PFL project, only LCME_FL_INIT is supported, and it can't
186         # be altered by application.
187 }
188 run_test 4 "Modify component flags in existing file"
189
190 test_5() {
191         local parent=$DIR/$tdir
192         local comp_file=$DIR/$tdir/$tfile
193         local subdir=$parent/subdir
194
195         rm -fr $parent
196         mkdir -p $parent || error "Create dir $parent failed"
197
198         # set default layout to parent directory
199         $LFS setstripe -E 64M -c 2 -i 0 -E -1 -c 4 -i 0 $parent ||
200                 error "Set default layout to $parent failed"
201
202         # create file under parent
203         touch $comp_file || error "Create $comp_file failed"
204         local comp_cnt=$($LFS getstripe --component-count $comp_file)
205         [ $comp_cnt -ne 2 ] && error "file $comp_cnt != 2"
206
207         #instantiate all components, so that objs are allocted
208         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=65k
209
210         local ost_idx=$($LFS getstripe -I 1 -i $comp_file)
211         [ $ost_idx -ne 0 ] &&
212                 error "component 1 ost_idx $ost_idx != 0"
213
214         ost_idx=$($LFS getstripe -I 2 -i $comp_file)
215         [ $ost_idx -ne 0 ] &&
216                 error "component 2 ost_idx $ost_idx != 0"
217
218         # create subdir under parent
219         mkdir -p $subdir || error "Create subdir $subdir failed"
220
221         comp_cnt=$($LFS getstripe -d --component-count $subdir)
222         [ $comp_cnt -ne 2 ] && error "subdir $comp_cnt != 2"
223
224         # create file under subdir
225         touch $subdir/$tfile || error "Create $subdir/$tfile failed"
226
227         comp_cnt=$($LFS getstripe --component-count $subdir/$tfile)
228         [ $comp_cnt -ne 2 ] && error "$subdir/$tfile $comp_cnt != 2"
229
230         # delete default layout setting from parent
231         $LFS setstripe -d $parent ||
232                 error "Delete default layout from $parent failed"
233
234         comp_cnt=$($LFS getstripe -d --component-count $parent)
235         [ ! -z "$comp_cnt" ] && error "$comp_cnt isn't empty"
236
237         rm -f $comp_file || error "Delete $comp_file failed"
238         rm -f $subdir/$tfile || error "Delete $subdir/$tfile failed"
239         rm -r $subdir || error "Delete subdir $subdir failed"
240         rmdir $parent || error "Delete dir $parent failed"
241 }
242 run_test 5 "Inherit composite layout from parent directory"
243
244 test_6() {
245         local comp_file=$DIR/$tfile
246
247         rm -f $DIR/$tfile
248
249         $LFS setstripe -c 1 -S 128K $comp_file ||
250                 error "Create v1 $comp_file failed"
251
252         local comp_cnt=$($LFS getstripe --component-count $comp_file)
253         [ ! -z "$comp_cnt" ] && error "Wrong component count $comp_cnt"
254
255         dd if=/dev/urandom of=$comp_file bs=1M count=5 oflag=sync ||
256                 error "Write to v1 $comp_file failed"
257
258         local old_chksum=$(md5sum $comp_file)
259
260         # Migrate v1 to composite
261         $LFS migrate -E 1M -S 512K -c 1 -E -1 -S 1M -c 2 $comp_file ||
262                 error "Migrate(v1 -> composite) $comp_file failed"
263
264         comp_cnt=$($LFS getstripe --component-count $comp_file)
265         [ "$comp_cnt" -ne 2 ] && error "$comp_cnt != 2"
266
267         local chksum=$(md5sum $comp_file)
268         [ "$old_chksum" != "$chksum" ] &&
269                 error "(v1 -> compsoite) $old_chksum != $chksum"
270
271         # Migrate composite to composite
272         $LFS migrate -E 1M -S 1M -c 2 -E 4M -S 1M -c 2 \
273                 -E -1 -S 3M -c 3 $comp_file ||
274                 error "Migrate(compsoite -> composite) $comp_file failed"
275
276         comp_cnt=$($LFS getstripe --component-count $comp_file)
277         [ "$comp_cnt" -ne 3 ] && error "$comp_cnt != 3"
278
279         chksum=$(md5sum $comp_file)
280         [ "$old_chksum" != "$chksum" ] &&
281                 error "(composite -> compsoite) $old_chksum != $chksum"
282
283         # Migrate composite to v1
284         $LFS migrate -c 2 -S 2M $comp_file ||
285                 error "Migrate(composite -> v1) $comp_file failed"
286
287         comp_cnt=$($LFS getstripe --component-count $comp_file)
288         [ ! -z "$comp_cnt" ] && error "$comp_cnt isn't empty"
289
290         chksum=$(md5sum $comp_file)
291         [ "$old_chksum" != "$chksum" ] &&
292                 error "(composite -> v1) $old_chksum != $chksum"
293
294         rm -f $comp_file || "Delete $comp_file failed"
295 }
296 run_test 6 "Migrate composite file"
297
298 test_7() {
299         mkdir -p $DIR/$tdir || error "mkdir failed"
300         chmod 0777 $DIR/$tdir || error "chmod $tdir failed"
301
302         local comp_file=$DIR/$tdir/$tfile
303         $RUNAS $LFS setstripe -E 1M -c 1 $comp_file ||
304                 error "Create composite file $comp_file failed"
305
306         $RUNAS $LFS setstripe --component-add -E 64M -c 4 $comp_file ||
307                 error "Add component to $comp_file failed"
308
309         $RUNAS $LFS setstripe --component-del -I 2 $comp_file ||
310                 error "Delete component from $comp_file failed"
311
312         $RUNAS $LFS setstripe --component-add -E -1 -c 5 $comp_file ||
313                 error "Add last component to $comp_file failed"
314
315         rm $comp_file || "Delete composite failed"
316 }
317 run_test 7 "Add/Delete/Create composite file by non-privileged user"
318
319 test_8() {
320         local parent=$DIR/$tdir
321
322         rm -fr $parent
323         mkdir -p $parent || error "Create dir $parent failed"
324
325         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c 2 -S 2M \
326                 -E -1 -c 4 -S 4M $parent ||
327                 error "Set default layout to $parent failed"
328
329         sh rundbench -C -D $parent 2 || error "debench failed"
330
331         rm -fr $parent || error "Delete dir $parent failed"
332 }
333 run_test 8 "Run debench over composite files"
334
335 test_9() {
336         local comp_file=$DIR/$tfile
337
338         rm -f $comp_file
339
340         $LFS setstripe -E 1m -S 1m -E 2M -c 1 $comp_file ||
341                 error "Create $comp_file failed"
342
343         local comp_cnt=$($LFS getstripe --component-count $comp_file)
344         [ $comp_cnt -ne 2 ] && error "component count $comp_cnt != 2"
345
346         replay_barrier $SINGLEMDS
347
348         # instantiate the 2nd component
349         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
350
351         local f1=$($LFS getstripe -I 2 $comp_file |
352                         awk '/l_fid:/ {print $7}')
353         echo "before MDS recovery, the ost fid of 2nd component is $f1"
354         fail $SINGLEMDS
355
356         local f2=$($LFS getstripe -I 2 $comp_file |
357                         awk '/l_fid:/ {print $7}')
358         echo "after MDS recovery, the ost fid of 2nd component is $f2"
359         [ $f1 == $f2 ] || error "$f1 != $f2"
360 }
361 run_test 9 "Replay layout extend object instantiation"
362
363 component_dump() {
364         echo $($LFS getstripe $1 |
365                 awk '$1 == "lcm_entry_count:" { printf("%d", $2) }
366                      $1 == "lcme_extent.e_start:" { printf("[%#lx", $2) }
367                      $1 == "lcme_extent.e_end:" { printf(",%s]", $2) }')
368 }
369
370 test_10() {
371         local parent=$DIR/$tdir
372         local root_layout=$(get_layout_param $MOUNT)
373
374         rm -rf $parent
375         $LFS setstripe -d $MOUNT || error "clear root layout"
376
377         # set root composite layout
378         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c2 -S 2M \
379                 -E -1 -c 4 -S 4M $MOUNT ||
380                 error "Set root layout failed"
381
382         mkdir -p $parent || error "Create dir $parent failed"
383         # set a different layout for parent
384         $LFS setstripe -E -1 -c 1 -S 1M $parent ||
385                 error "set $parent layout failed"
386         touch $parent/file1
387
388         local f1_entry=$(component_dump $parent/file1)
389
390         # delete parent's layout
391         $LFS setstripe -d $parent || error "Clear $parent layout failed"
392         touch $parent/file2
393
394         local f2_entry=$(component_dump $parent/file2)
395
396         # verify layout inheritance
397         local eof="EOF"
398         local f1_expect="1[0,EOF]"
399         local f2_expect="3[0,2097152][0x200000,16777216][0x1000000,EOF]"
400
401         echo "f1 expect=$f1_expect"
402         echo "f1 get   =$f1_entry"
403         echo "f2 expect=$f2_expect"
404         echo "f2 get   =$f2_entry"
405
406         [  x$f1_expect != x$f1_entry ] &&
407                 error "$parent/file1 does not inherite parent layout"
408         [  x$f2_expect != x$f2_entry ] &&
409                 error "$parent/file2 does not inherite root layout"
410
411         $LFS setstripe $root_layout $MOUNT
412         return 0
413 }
414 run_test 10 "Inherit composite template from root"
415
416 test_11() {
417         local comp_file=$DIR/$tfile
418         rm -f $comp_file
419
420         # only 1st component instantiated
421         $LFS setstripe -E 1m -E 2m -E 3m -E -1 $comp_file ||
422                 error "Create $comp_file failed"
423
424         local f1=$($LFS getstripe -I 1 $comp_file | grep "l_fid")
425         [[ -z $f1 ]] && error "1: 1st component uninstantiated"
426         local f2=$($LFS getstripe -I 2 $comp_file | grep "l_fid")
427         [[ -n $f2 ]] && error "1: 2nd component instantiated"
428         local f3=$($LFS getstripe -I 3 $comp_file | grep "l_fid")
429         [[ -n $f3 ]] && error "1: 3rd component instantiated"
430         local f4=$($LFS getstripe -I 4 $comp_file | grep "l_fid")
431         [[ -n $f4 ]] && error "1: 4th component instantiated"
432
433         # the first 2 components instantiated
434         $TRUNCATE $comp_file $((1024*1024*1+1))
435
436         f2=$($LFS getstripe -I 2 $comp_file | grep "l_fid")
437         [[ -z $f2 ]] && error "2: 2nd component uninstantiated"
438         f3=$($LFS getstripe -I 3 $comp_file | grep "l_fid")
439         [[ -n $f3 ]] && error "2: 3rd component instantiated"
440         f4=$($LFS getstripe -I 4 $comp_file | grep "l_fid")
441         [[ -n $f4 ]] && error "2: 4th component instantiated"
442
443         # the first 3 components instantiated
444         $TRUNCATE $comp_file $((1024*1024*3))
445         $TRUNCATE $comp_file $((1024*1024*1+1))
446
447         f2=$($LFS getstripe -I 2 $comp_file | grep "l_fid")
448         [[ -z $f2 ]] && error "2: 2nd component uninstantiated"
449         f3=$($LFS getstripe -I 3 $comp_file | grep "l_fid")
450         [[ -z $f3 ]] && error "3: 3rd component uninstantiated"
451         f4=$($LFS getstripe -I 4 $comp_file | grep "l_fid")
452         [[ -n $f4 ]] && error "3: 4th component instantiated"
453
454         # all 4 components instantiated, using append write
455         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
456         ls -l $comp_file
457         rwv -f $comp_file -w -a -n 2 $((1024*1023)) 1
458         ls -l $comp_file
459
460         f4=$($LFS getstripe -I 4 $comp_file | grep "l_fid")
461         [[ -z $f4 ]] && error "4: 4th component uninstantiated"
462
463         return 0
464 }
465 run_test 11 "Verify component instantiation with write/truncate"
466
467 test_12() {
468         [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return
469
470         local file=$DIR/$tfile
471         rm -f $file
472
473         # specify ost list for component
474         $LFS setstripe -E1m -c2 -o0,1 -E2m -c2 -o1,2 -E3m -c2 -o2,1 \
475                 -E4m -c2 -o2,0 -E-1 $file ||
476                 error "Create $file failed"
477         # instantiate all components
478         $TRUNCATE $file $((1024*1024*4+1))
479
480         #verify object alloc order
481         local o1=$($LFS getstripe -I1 $file |
482                         awk '/l_ost_idx:/ {printf("%d",$5)}')
483         [[ $o1 != "01" ]] && error "$o1 is not 01"
484
485         local o2=$($LFS getstripe -I2 $file |
486                         awk '/l_ost_idx:/ {printf("%d",$5)}')
487         [[ $o2 != "12" ]] && error "$o2 is not 12"
488
489         local o3=$($LFS getstripe -I3 $file |
490                         awk '/l_ost_idx:/ {printf("%d",$5)}')
491         [[ $o3 != "21" ]] && error "$o3 is not 21"
492
493         local o4=$($LFS getstripe -I4 $file |
494                         awk '/l_ost_idx:/ {printf("%d",$5)}')
495         [[ $o4 != "20" ]] && error "$o4 is not 20"
496
497         return 0
498 }
499 run_test 12 "Verify ost list specification"
500
501 test_13() { # LU-9311
502         [ $OSTCOUNT -lt 8 ] && skip "needs >= 8 OSTs" && return
503
504         local file=$DIR/$tfile
505         local dd_count=4
506         local dd_size=$(($dd_count * 1024 * 1024))
507         local real_size
508
509         rm -f $file
510         $LFS setstripe -E 1M -c 1 -E 2M -c 2 -E -1 -c -1 -i 1 $file ||
511                 error "Create $file failed"
512         dd if=/dev/zero of=$file bs=1M count=$dd_count
513         real_size=$(stat -c %s $file)
514         [ $real_size -eq $dd_size ] ||
515                 error "dd actually wrote $real_size != $dd_size bytes"
516
517         rm -f $file
518 }
519 run_test 13 "shouldn't reprocess granted resent request"
520
521 complete $SECONDS
522 check_and_cleanup_lustre
523 exit_status