Whamcloud - gitweb
LU-10686 tests: stop running sanity-pfl test 9
[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 TMP=${TMP:-/tmp}
16 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
17
18 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
19 . $LUSTRE/tests/test-framework.sh
20 init_test_env $@
21 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
22 init_logging
23
24 check_and_setup_lustre
25
26 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.51) ]]; then
27         skip_env "Need MDS version at least 2.9.51"
28 fi
29
30 if [ $MDSCOUNT -eq 1 ]; then
31         # Bug number:    LU-10686
32         ALWAYS_EXCEPT+=" 9"
33 fi
34
35 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
36         echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
37
38 build_test_filter
39
40 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
41         error "\$RUNAS_ID set to 0, but \$UID is also 0!"
42 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
43
44 assert_DIR
45 rm -rf $DIR/[Rdfs][0-9]*
46
47 test_0() {
48         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
49
50         local comp_file=$DIR/$tdir/$tfile
51         local rw_len=$((3 * 1024 * 1024))       # 3M
52
53         test_mkdir $DIR/$tdir
54         rm -f $comp_file
55
56         $LFS setstripe -E 1m -S 1M -c 1 -E -1 -c 1 $comp_file ||
57                 error "Create $comp_file failed"
58
59         #instantiate all components, so that objs are allocted
60         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
61
62         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
63         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
64
65         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
66
67         small_write $comp_file $rw_len || error "Verify RW failed"
68
69         rm -f $comp_file || error "Delete $comp_file failed"
70 }
71 run_test 0 "Create full components file, no reused OSTs"
72
73 test_1() {
74         local comp_file=$DIR/$tdir/$tfile
75         local rw_len=$((3 * 1024 * 1024))       # 3M
76
77         test_mkdir $DIR/$tdir
78         rm -f $comp_file
79
80         $LFS setstripe -E 1m -S 1m -o 0 -E -1 -o 0 $comp_file ||
81                 error "Create $comp_file failed"
82
83         #instantiate all components, so that objs are allocted
84         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
85
86         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
87         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
88
89         [ $ost_idx1 -ne $ost_idx2 ] && error "$ost_idx1 != $ost_idx2"
90
91         small_write $comp_file $rw_len || error "Verify RW failed"
92
93         rm -f $comp_file || error "Delete $comp_file failed"
94 }
95 run_test 1 "Create full components file, reused OSTs"
96
97 test_2() {
98         local comp_file=$DIR/$tdir/$tfile
99         local rw_len=$((5 * 1024 * 1024))       # 5M
100
101         test_mkdir $DIR/$tdir
102         rm -f $comp_file
103
104         $LFS setstripe -E 1m -S 1m $comp_file ||
105                 error "Create $comp_file failed"
106
107         local comp_cnt=$($LFS getstripe --component-count $comp_file)
108         [ $comp_cnt -ne 1 ] && error "component count $comp_cnt != 1"
109
110         dd if=/dev/zero of=$comp_file bs=1M count=1 > /dev/null 2>&1 ||
111                 error "Write first component failed"
112         dd if=$comp_file of=/dev/null bs=1M count=1 > /dev/null 2>&1 ||
113                 error "Read first component failed"
114
115         dd if=/dev/zero of=$comp_file bs=1M count=2 > /dev/null 2>&1 &&
116                 error "Write beyond component should fail"
117         dd if=$comp_file of=/dev/null bs=1M count=2 > /dev/null 2>&1 ||
118                 error "Read beyond component should short read, not fail"
119
120         $LFS setstripe --component-add -E 2M -S 1M -c 1 $comp_file ||
121                 error "Add component to $comp_file failed"
122
123         comp_cnt=$($LFS getstripe --component-count $comp_file)
124         [ $comp_cnt -ne 2 ] && error "component count $comp_cnt != 2"
125
126         $LFS setstripe --component-add -E -1 -c 3 $comp_file ||
127                 error "Add last component to $comp_file failed"
128
129         comp_cnt=$($LFS getstripe --component-count $comp_file)
130         [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
131
132         small_write $comp_file $rw_len || error "Verify RW failed"
133
134         rm -f $comp_file || error "Delete $comp_file failed"
135 }
136 run_test 2 "Add component to existing file"
137
138 del_comp_and_verify() {
139         local comp_file=$1
140         local id=$2
141         local left=$3
142         local size=$4
143
144         local opt="-I "
145         if [ $id == "init" -o $id == "^init" ]; then
146                 opt="--component-flags="
147         fi
148
149         $LFS setstripe --component-del $opt$id $comp_file ||
150                 error "Delete component $id from $comp_file failed"
151
152         local comp_cnt=$($LFS getstripe --component-count $comp_file)
153         if grep -q "has no stripe info" <<< "$comp_cnt" ; then
154                 comp_cnt=0
155         fi
156         [ $comp_cnt -ne $left ] && error "$comp_cnt != $left"
157
158         $CHECKSTAT -s $size $comp_file || error "size != $size"
159 }
160
161 test_3() {
162         local comp_file=$DIR/$tdir/$tfile
163
164         test_mkdir $DIR/$tdir
165         rm -f $comp_file
166
167         $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 3 $comp_file ||
168                 error "Create $comp_file failed"
169
170         local comp_cnt=$($LFS getstripe --component-count $comp_file)
171         [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
172
173         dd if=/dev/zero of=$comp_file bs=1M count=2
174
175         $LFS setstripe --component-del -I 2 $comp_file &&
176                 error "Component deletion makes hole"
177
178         del_comp_and_verify $comp_file 3 2 $((2 * 1024 * 1024))
179         del_comp_and_verify $comp_file 2 1 $((1 * 1024 * 1024))
180         del_comp_and_verify $comp_file 1 0 0
181
182         rm -f $comp_file || error "Delete $comp_file failed"
183
184         $LFS setstripe -E 1M -S 1M -E 16M -E -1 $comp_file ||
185                 error "Create second $comp_file failed"
186
187         del_comp_and_verify $comp_file "^init" 1 0
188         del_comp_and_verify $comp_file "init" 0 0
189         rm -f $comp_file || error "Delete second $comp_file failed"
190
191 }
192 run_test 3 "Delete component from existing file"
193
194 test_4() {
195         skip "Not supported in PFL"
196         # In PFL project, only LCME_FL_INIT is supported, and it can't
197         # be altered by application.
198 }
199 run_test 4 "Modify component flags in existing file"
200
201 test_5() {
202         local parent=$DIR/$tdir
203         local comp_file=$DIR/$tdir/$tfile
204         local subdir=$parent/subdir
205
206         rm -fr $parent
207         test_mkdir $parent
208
209         # set default layout to parent directory
210         $LFS setstripe -E 64M -c 2 -i 0 -E -1 -c 4 -i 0 $parent ||
211                 error "Set default layout to $parent failed"
212
213         # create file under parent
214         touch $comp_file || error "Create $comp_file failed"
215         local comp_cnt=$($LFS getstripe --component-count $comp_file)
216         [ $comp_cnt -ne 2 ] && error "file $comp_cnt != 2"
217
218         #instantiate all components, so that objs are allocted
219         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=65k
220
221         local ost_idx=$($LFS getstripe -I1 -i $comp_file)
222         [ $ost_idx -ne 0 ] &&
223                 error "component 1 ost_idx $ost_idx != 0"
224
225         ost_idx=$($LFS getstripe -I2 -i $comp_file)
226         [ $ost_idx -ne 0 ] &&
227                 error "component 2 ost_idx $ost_idx != 0"
228
229         # create subdir under parent
230         mkdir -p $subdir || error "Create subdir $subdir failed"
231
232         comp_cnt=$($LFS getstripe -d --component-count $subdir)
233         [ $comp_cnt -ne 2 ] && error "subdir $comp_cnt != 2"
234
235         # create file under subdir
236         touch $subdir/$tfile || error "Create $subdir/$tfile failed"
237
238         comp_cnt=$($LFS getstripe --component-count $subdir/$tfile)
239         [ $comp_cnt -ne 2 ] && error "$subdir/$tfile $comp_cnt != 2"
240
241         # delete default layout setting from parent
242         $LFS setstripe -d $parent ||
243                 error "Delete default layout from $parent failed"
244
245         comp_cnt=$($LFS getstripe -d --component-count $parent)
246         [ $comp_cnt -ne 0 ] && error "$comp_cnt isn't 0"
247
248         rm -f $comp_file || error "Delete $comp_file failed"
249         rm -f $subdir/$tfile || error "Delete $subdir/$tfile failed"
250         rm -r $subdir || error "Delete subdir $subdir failed"
251         rmdir $parent || error "Delete dir $parent failed"
252 }
253 run_test 5 "Inherit composite layout from parent directory"
254
255 test_6() {
256         local comp_file=$DIR/$tdir/$tfile
257
258         test_mkdir $DIR/$tdir
259         rm -f $DIR/$tfile
260
261         $LFS setstripe -c 1 -S 128K $comp_file ||
262                 error "Create v1 $comp_file failed"
263
264         local comp_cnt=$($LFS getstripe --component-count $comp_file)
265         [ $comp_cnt -ne 0 ] && error "Wrong component count $comp_cnt"
266
267         dd if=/dev/urandom of=$comp_file bs=1M count=5 oflag=sync ||
268                 error "Write to v1 $comp_file failed"
269
270         local old_chksum=$(md5sum $comp_file)
271
272         # Migrate v1 to composite
273         $LFS migrate -E 1M -S 512K -c 1 -E -1 -S 1M -c 2 $comp_file ||
274                 error "Migrate(v1 -> composite) $comp_file failed"
275
276         comp_cnt=$($LFS getstripe --component-count $comp_file)
277         [ "$comp_cnt" -ne 2 ] && error "$comp_cnt != 2"
278
279         local chksum=$(md5sum $comp_file)
280         [ "$old_chksum" != "$chksum" ] &&
281                 error "(v1 -> compsoite) $old_chksum != $chksum"
282
283         # Migrate composite to composite
284         $LFS migrate -E 1M -S 1M -c 2 -E 4M -S 1M -c 2 \
285                 -E -1 -S 3M -c 3 $comp_file ||
286                 error "Migrate(compsoite -> composite) $comp_file failed"
287
288         comp_cnt=$($LFS getstripe --component-count $comp_file)
289         [ "$comp_cnt" -ne 3 ] && error "$comp_cnt != 3"
290
291         chksum=$(md5sum $comp_file)
292         [ "$old_chksum" != "$chksum" ] &&
293                 error "(composite -> compsoite) $old_chksum != $chksum"
294
295         # Migrate composite to v1
296         $LFS migrate -c 2 -S 2M $comp_file ||
297                 error "Migrate(composite -> v1) $comp_file failed"
298
299         comp_cnt=$($LFS getstripe --component-count $comp_file)
300         [ $comp_cnt -ne 0 ] && error "$comp_cnt isn't 0"
301
302         chksum=$(md5sum $comp_file)
303         [ "$old_chksum" != "$chksum" ] &&
304                 error "(composite -> v1) $old_chksum != $chksum"
305
306         rm -f $comp_file || "Delete $comp_file failed"
307 }
308 run_test 6 "Migrate composite file"
309
310 test_7() {
311         test_mkdir $DIR/$tdir
312         chmod 0777 $DIR/$tdir || error "chmod $tdir failed"
313
314         local comp_file=$DIR/$tdir/$tfile
315         $RUNAS $LFS setstripe -E 1M -S 1M -c 1 $comp_file ||
316                 error "Create composite file $comp_file failed"
317
318         $RUNAS $LFS setstripe --component-add -E 64M -c 4 $comp_file ||
319                 error "Add component to $comp_file failed"
320
321         $RUNAS $LFS setstripe --component-del -I 2 $comp_file ||
322                 error "Delete component from $comp_file failed"
323
324         $RUNAS $LFS setstripe --component-add -E -1 -c 5 $comp_file ||
325                 error "Add last component to $comp_file failed"
326
327         rm $comp_file || "Delete composite failed"
328 }
329 run_test 7 "Add/Delete/Create composite file by non-privileged user"
330
331 test_8() {
332         local parent=$DIR/$tdir
333
334         rm -fr $parent
335         test_mkdir $parent
336
337         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c 2 -S 2M \
338                 -E -1 -c 4 -S 4M $parent ||
339                 error "Set default layout to $parent failed"
340
341         sh rundbench -C -D $parent 2 || error "dbench failed"
342
343         rm -fr $parent || error "Delete dir $parent failed"
344 }
345 run_test 8 "Run dbench over composite files"
346
347 test_9() {
348         local comp_file=$DIR/$tdir/$tfile
349
350         test_mkdir $DIR/$tdir
351         rm -f $comp_file
352
353         $LFS setstripe -E 1M -S 1M -E 2M -c 1 $comp_file ||
354                 error "Create $comp_file failed"
355
356         local comp_cnt=$($LFS getstripe --component-count $comp_file)
357         [ $comp_cnt -ne 2 ] && error "component count $comp_cnt != 2"
358
359         replay_barrier $SINGLEMDS
360
361         # instantiate the 2nd component
362         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
363
364         local f1=$($LFS getstripe -I2 $comp_file |
365                         awk '/l_fid:/ {print $7}')
366         echo "before MDS recovery, the ost fid of 2nd component is $f1"
367         fail $SINGLEMDS
368
369         local f2=$($LFS getstripe -I2 $comp_file |
370                         awk '/l_fid:/ {print $7}')
371         echo "after MDS recovery, the ost fid of 2nd component is $f2"
372         [ "x$f1" == "x$f2" ] || error "$f1 != $f2"
373 }
374 run_test 9 "Replay layout extend object instantiation"
375
376 component_dump() {
377         echo $($LFS getstripe $1 |
378                 awk '$1 == "lcm_entry_count:" { printf("%d", $2) }
379                      $1 == "lcme_extent.e_start:" { printf("[%#lx", $2) }
380                      $1 == "lcme_extent.e_end:" { printf(",%s]", $2) }')
381 }
382
383 test_10() {
384         local parent=$DIR/$tdir
385
386         save_layout_restore_at_exit $MOUNT
387
388         rm -rf $parent
389         $LFS setstripe -d $MOUNT || error "clear root layout"
390
391         # set root composite layout
392         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c2 -S 2M \
393                 -E -1 -c 4 -S 4M $MOUNT ||
394                 error "Set root layout failed"
395
396         test_mkdir $parent
397         # set a different layout for parent
398         $LFS setstripe -E -1 -c 1 -S 1M $parent ||
399                 error "set $parent layout failed"
400         touch $parent/file1
401
402         local f1_entry=$(component_dump $parent/file1)
403
404         # delete parent's layout
405         $LFS setstripe -d $parent || error "Clear $parent layout failed"
406         touch $parent/file2
407
408         local f2_entry=$(component_dump $parent/file2)
409
410         # verify layout inheritance
411         local eof="EOF"
412         local f1_expect="1[0,EOF]"
413         local f2_expect="3[0,2097152][0x200000,16777216][0x1000000,EOF]"
414
415         echo "f1 expect=$f1_expect"
416         echo "f1 get   =$f1_entry"
417         echo "f2 expect=$f2_expect"
418         echo "f2 get   =$f2_entry"
419
420         [  x$f1_expect != x$f1_entry ] &&
421                 error "$parent/file1 does not inherite parent layout"
422         [  x$f2_expect != x$f2_entry ] &&
423                 error "$parent/file2 does not inherite root layout"
424
425         return 0
426 }
427 run_test 10 "Inherit composite template from root"
428
429 test_11() {
430         local comp_file=$DIR/$tdir/$tfile
431         test_mkdir $DIR/$tdir
432         rm -f $comp_file
433
434         # only 1st component instantiated
435         $LFS setstripe -E 1M -S 1M -E 2M -E 3M -E -1 $comp_file ||
436                 error "Create $comp_file failed"
437
438         local f1=$($LFS getstripe -I1 $comp_file | grep "l_fid")
439         [[ -z $f1 ]] && error "1: 1st component uninstantiated"
440         local f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
441         [[ -n $f2 ]] && error "1: 2nd component instantiated"
442         local f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
443         [[ -n $f3 ]] && error "1: 3rd component instantiated"
444         local f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
445         [[ -n $f4 ]] && error "1: 4th component instantiated"
446
447         # the first 2 components instantiated
448         $TRUNCATE $comp_file $((1024*1024*1+1))
449
450         f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
451         [[ -z $f2 ]] && error "2: 2nd component uninstantiated"
452         f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
453         [[ -n $f3 ]] && error "2: 3rd component instantiated"
454         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
455         [[ -n $f4 ]] && error "2: 4th component instantiated"
456
457         # the first 3 components instantiated
458         $TRUNCATE $comp_file $((1024*1024*3))
459         $TRUNCATE $comp_file $((1024*1024*1+1))
460
461         f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
462         [[ -z $f2 ]] && error "3: 2nd component uninstantiated"
463         f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
464         [[ -z $f3 ]] && error "3: 3rd component uninstantiated"
465         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
466         [[ -n $f4 ]] && error "3: 4th component instantiated"
467
468         # all 4 components instantiated, using append write
469         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
470         ls -l $comp_file
471         rwv -f $comp_file -w -a -n 2 $((1024*1023)) 1
472         ls -l $comp_file
473
474         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
475         [[ -z $f4 ]] && error "4: 4th component uninstantiated"
476
477         return 0
478 }
479 run_test 11 "Verify component instantiation with write/truncate"
480
481 test_12() {
482         [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs"
483
484         local file=$DIR/$tdir/$tfile
485         test_mkdir $DIR/$tdir
486         rm -f $file
487
488         # specify ost list for component
489         $LFS setstripe -E 1M -S 1M -c 2 -o 0,1 -E 2M -c 2 -o 1,2 \
490                 -E 3M -c 2 -o 2,1 -E 4M -c 1 -i 2 -E -1 $file ||
491                 error "Create $file failed"
492
493         # clear lod component cache
494         stop $SINGLEMDS || error "stop MDS"
495         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
496         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "start MDS"
497
498         # instantiate all components
499         $TRUNCATE $file $((1024*1024*4+1))
500
501         #verify object alloc order
502         local o1=$($LFS getstripe -I1 $file |
503                         awk '/l_ost_idx:/ {printf("%d",$5)}')
504         [[ $o1 != "01" ]] && error "$o1 is not 01"
505
506         local o2=$($LFS getstripe -I2 $file |
507                         awk '/l_ost_idx:/ {printf("%d",$5)}')
508         [[ $o2 != "12" ]] && error "$o2 is not 12"
509
510         local o3=$($LFS getstripe -I3 $file |
511                         awk '/l_ost_idx:/ {printf("%d",$5)}')
512         [[ $o3 != "21" ]] && error "$o3 is not 21"
513
514         local o4=$($LFS getstripe -I4 $file |
515                         awk '/l_ost_idx:/ {printf("%d",$5)}')
516         [[ $o4 != "2" ]] && error "$o4 is not 2"
517
518         return 0
519 }
520 run_test 12 "Verify ost list specification"
521
522 test_13() { # LU-9311
523         [ $OSTCOUNT -lt 8 ] && skip "needs >= 8 OSTs"
524
525         local file=$DIR/$tfile
526         local dd_count=4
527         local dd_size=$(($dd_count * 1024 * 1024))
528         local real_size
529
530         rm -f $file
531         $LFS setstripe -E 1M -S 1M -c 1 -E 2M -c 2 -E -1 -c -1 -i 1 $file ||
532                 error "Create $file failed"
533         dd if=/dev/zero of=$file bs=1M count=$dd_count
534         real_size=$(stat -c %s $file)
535         [ $real_size -eq $dd_size ] ||
536                 error "dd actually wrote $real_size != $dd_size bytes"
537
538         rm -f $file
539 }
540 run_test 13 "shouldn't reprocess granted resent request"
541
542 test_14() {
543         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
544         local file=$DIR/$tdir/$tfile
545         test_mkdir -p $DIR/$tdir
546         rm -f $file
547
548         $LFS setstripe -E1m -c1 -S1m --pool="pool1" -E2m \
549                         -E4m -c2 -S2m --pool="pool2" -E-1 $file ||
550                 error "Create $file failed"
551
552         # check --pool inheritance
553         local pool
554         pool="$($LFS getstripe -I2 --pool $file)"
555         [ x"$pool" != "xpool1" ] && $LFS getstripe -I2 $file &&
556                 error "$file: component 2 doesn't have poolname pool1"
557         pool="$($LFS getstripe -I4 --pool $file)"
558         [ x"$pool" != "xpool2" ] && $LFS getstripe -I4 $file &&
559                 error "$file: component 4 doesn't have poolname pool2"
560
561         #check --stripe-count inheritance
562         local count
563         count="$($LFS getstripe -I2 -c $file)"
564         [ $count -ne 1 ] && $LFS getstripe -I2 $file &&
565                 error "$file: component 2 doesn't have 1 stripe_count"
566         count="$($LFS getstripe -I4 -c $file)"
567         [ $count -ne 2 ] && $LFS getstripe -I4 $file &&
568                 error "$file: component 4 doesn't have 2 stripe_count"
569
570         #check --stripe-size inheritance
571         local size
572         size="$($LFS getstripe -I2 -S $file)"
573         [ $size -ne $((1024*1024)) ] && $LFS getstripe -I2 $file &&
574                 error "$file: component 2 doesn't have 1M stripe_size"
575         size="$($LFS getstripe -I4 -S $file)"
576         [ $size -ne $((1024*1024*2)) ] && $LFS getstripe -I4 $file &&
577                 error "$file: component 4 doesn't have 2M stripe_size"
578
579         return 0
580 }
581 run_test 14 "Verify setstripe poolname/stripe_count/stripe_size inheritance"
582
583 test_15() {
584         local parent=$DIR/$tdir
585
586         rm -fr $parent
587         test_mkdir $parent
588
589         $LFS setstripe -d $parent || error "delete default layout"
590
591         $LFS setstripe -E 1M -S 1M -E 10M -E eof $parent/f1 || error "create f1"
592         $LFS setstripe -E 4M -E 20M -E eof $parent/f2 || error "create f2"
593         test_mkdir $parent/subdir
594         $LFS setstripe -E 6M -S 1M -E 30M -E eof $parent/subdir ||
595                 error "setstripe to subdir"
596         $LFS setstripe -E 8M -E eof $parent/subdir/f3 || error "create f3"
597         $LFS setstripe -c 1 $parent/subdir/f4 || error "create f4"
598
599         # none
600         local found=$($LFS find --component-start +2M -E -15M $parent | wc -l)
601         [ $found -eq 0 ] || error "start+2M, end-15M, $found != 0"
602
603         # f2, f3
604         found=$($LFS find --component-start +2M -E -35M $parent | wc -l)
605         [ $found -eq 2 ] || error "start+2M, end-35M, $found != 2"
606
607         # subdir
608         found=$($LFS find --component-start +4M -E -eof $parent | wc -l)
609         [ $found -eq 1 ] || error "start+4M, end-eof, $found != 1"
610
611         local flg_opts="--component-flags init"
612         # none
613         found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
614         [ $found -eq 0 ] ||
615                 error "before write: start=1M, end=10M, flag=init, $found != 0"
616
617         dd if=/dev/zero of=$parent/f1 bs=1M count=2 ||
618                 error "dd $parent/f1 failed"
619
620         # f1
621         found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
622         [ $found -eq 1 ] ||
623                 error "after write: start=1M, end=10M, flag=init, $found != 1"
624
625         local ext_opts="--component-start -1M -E +5M"
626         # parent, subdir, f3, f4
627         found=$($LFS find $ext_opts $parent | wc -l)
628         [ $found -eq 4 ] || error "start-1M, end+5M, $found != 4"
629
630         local cnt_opts="--component-count +2"
631         # subdir
632         found=$($LFS find $ext_opts $cnt_opts $parent | wc -l)
633         [ $found -eq 1 ] || error "start-1M, end+5M, count+2, $found != 1"
634
635         # none
636         found=$($LFS find $ext_opts $cnt_opts $flg_opts $parent | wc -l)
637         [ $found -eq 0 ] ||
638                 error "start-1M, end+5M, count+2, flag=init, $found != 0"
639
640         # f3, f4
641         found=$($LFS find $ext_opts ! $cnt_opts $flg_opts $parent | wc -l)
642         [ $found -eq 2 ] ||
643                 error "start-1M, end+5M, !count+2, flag=init, $found != 2"
644 }
645 run_test 15 "Verify component options for lfs find"
646
647 verify_16() {
648         local src=$1
649         local dst=$2
650         local temp=$3
651         local msg_prefix=$4
652
653         echo "getstripe --yaml $src"
654         $LFS getstripe --yaml $src > $temp || error "getstripe $src failed"
655         echo "setstripe --yaml=$temp $dst"
656         $LFS setstripe --yaml=$temp $dst|| error "setstripe $dst failed"
657
658         echo "compare"
659         local layout1=$(get_layout_param $src)
660         local layout2=$(get_layout_param $dst)
661         # compare their layout info
662         [ "$layout1" == "$layout2" ] ||
663                 error "$msg_prefix $src/$dst layouts are not equal"
664 }
665
666 test_16() {
667         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
668
669         local file=$DIR/$tdir/$tfile
670         local dir=$DIR/$tdir/dir
671         local temp=$DIR/$tdir/template
672         rm -rf $DIR/$tdir
673         test_mkdir $DIR/$tdir
674
675         #####################################################################
676         #                           1. PFL file
677         # set stripe for source file
678         $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
679                 $file || error "Create $file failed"
680
681         echo "1. PFL file"
682         verify_16 $file $file.copy $temp "1. PFL file"
683
684         #####################################################################
685         #                           2. plain file
686         # set stripe for source file
687         rm -f $file
688         $LFS setstripe -c2 -o0,1 -i1 $file || error "Create $file failed"
689
690         rm -f $file.copy
691         echo "2. plain file"
692         verify_16 $file $file.copy $temp "2. plain file"
693
694         #####################################################################
695         #                           3. PFL dir
696         # set stripe for source dir
697         test_mkdir $dir
698         $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
699                 error "setstripe $dir failed"
700
701         test_mkdir $dir.copy
702         echo "3. PFL dir"
703         verify_16 $dir $dir.copy $temp.dir "3. PFL dir"
704
705         #####################################################################
706         #                           4. plain dir
707         # set stripe for source dir
708         $LFS setstripe -c2 -i-1 $dir || error "setstripe $dir failed"
709
710         echo "4. plain dir"
711         verify_16 $dir $dir.copy $temp.dir "4. plain dir"
712 }
713 run_test 16 "Verify setstripe/getstripe with YAML config file"
714
715 test_17() {
716         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
717         local file=$DIR/$tdir/$tfile
718         test_mkdir -p $DIR/$tdir
719         rm -f $file
720
721         $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E -1 -c -1 $file ||
722                 error "Create $file failed"
723
724         local s1=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
725         local s2=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
726         local s3=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
727         echo "1st init: comp size 1:$s1 2:$s2 3:$s3"
728
729         # init 2nd component
730         $TRUNCATE $file $((1024*1024+1))
731         local s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
732         local s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
733         echo "2nd init: comp size 1:$s1n 2:$s2n 3:$s3"
734
735         [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
736         [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
737
738         # init 3rd component
739         $TRUNCATE $file $((1024*1024*2+1))
740         s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
741         s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
742         local s3n=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
743         echo "3rd init: comp size 1:$s1n 2:$s2n 3:$s3n"
744
745         [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
746         [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
747         [ $s3 -lt $s3n ] || error "3rd comp size $s3 should < $s3n"
748 }
749 run_test 17 "Verify LOVEA grows with more component inited"
750
751 complete $SECONDS
752 check_and_cleanup_lustre
753 exit_status