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