Whamcloud - gitweb
LU-16962 build: parallel configure cleanup
[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 ONLY=${ONLY:-"$*"}
8
9 LUSTRE=${LUSTRE:-$(dirname $0)/..}
10 . $LUSTRE/tests/test-framework.sh
11 init_test_env "$@"
12 init_logging
13
14 # bug number for skipped test:
15 ALWAYS_EXCEPT="$SANITY_PFL_EXCEPT "
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17
18 # Skip tests for PPC that fail frequently
19 if [[ $(uname -m) = ppc64 ]]; then
20         # bug number:    LU-13186 LU-13205 LU-13207 LU-13186
21         ALWAYS_EXCEPT+=" 14       16a      16b      17"
22 fi
23
24 if [[ "$ost1_FSTYPE" == "zfs" ]]; then
25         # bug #:        LU-1941
26         ALWAYS_EXCEPT+="24a"
27 fi
28 build_test_filter
29
30 check_and_setup_lustre
31
32 if [[ "$MDS1_VERSION" -lt $(version_code 2.9.51) ]]; then
33         skip_env "Need MDS version at least 2.9.51"
34 fi
35
36 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
37         error "\$RUNAS_ID set to 0, but \$UID is also 0!"
38 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
39
40 assert_DIR
41 rm -rf $DIR/[Rdfs][0-9]*
42
43 force_new_seq mds1
44
45 test_0a() {
46         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
47
48         local comp_file=$DIR/$tdir/$tfile
49         local rw_len=$((3 * 1024 * 1024))       # 3M
50
51         test_mkdir $DIR/$tdir
52         rm -f $comp_file
53
54         $LFS setstripe -E 1m -S 1M -c 1 -E -1 -c 1 $comp_file ||
55                 error "Create $comp_file failed"
56
57         #instantiate all components, so that objs are allocted
58         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
59
60         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
61         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
62
63         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
64
65         small_write $comp_file $rw_len || error "Verify RW failed"
66
67         rm -f $comp_file || error "Delete $comp_file failed"
68 }
69 run_test 0a "Create full components file, no reused OSTs"
70
71 test_0b() {
72         [[ $($LCTL get_param mdc.*.import |
73                 grep "connect_flags:.*overstriping") ]] ||
74                 skip "server does not support overstriping"
75         large_xattr_enabled || skip_env "no large xattr support"
76
77         force_new_seq_all
78
79         local comp_file=$DIR/$tdir/$tfile
80
81         test_mkdir $DIR/$tdir
82
83         $LFS setstripe -E -1 -C $LOV_MAX_STRIPE_COUNT $comp_file ||
84                 error "Create $comp_file failed"
85
86         local count=$($LFS getstripe -I1 -c $comp_file)
87         [ $count -eq $LOV_MAX_STRIPE_COUNT ] ||
88                 error "stripe count of first component is shrinked to $count"
89
90         rm -f $comp_file || error "Delete $comp_file failed"
91
92         # Create file with 1.1*LOV_MAX_STRIPE_COUNT stripes should succeed
93         $LFS setstripe -E 1m -C $((LOV_MAX_STRIPE_COUNT / 10)) -E -1 \
94                 -C $LOV_MAX_STRIPE_COUNT $comp_file ||
95                 error "Create $comp_file failed"
96
97         local count=$($LFS getstripe -I2 -c $comp_file)
98         [ $count -eq $LOV_MAX_STRIPE_COUNT ] ||
99                 error "stripe count of second component is shrinked to $count"
100
101         rm -f $comp_file || error "Delete $comp_file failed"
102
103         # Create file with 3*LOV_MAX_STRIPE_COUNT stripes should fail
104         $LFS setstripe -E 200G -C $LOV_MAX_STRIPE_COUNT \
105                 -E 500G -C $LOV_MAX_STRIPE_COUNT \
106                 -E -1 -C $LOV_MAX_STRIPE_COUNT $comp_file &&
107                 error "Create $comp_file succeeded"
108
109         rm -f $comp_file || error "Delete $comp_file failed"
110 }
111 run_test 0b "Verify comp stripe count limits"
112
113 test_0c() {
114         [[ $($LCTL get_param mdc.*.import |
115                 grep "connect_flags:.*overstriping") ]] ||
116                 skip "server does not support overstriping"
117         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code $SEL_VER) ] &&
118                 skip "skipped for lustre < $SEL_VER"
119
120         large_xattr_enabled || skip_env "no large xattr support"
121
122         force_new_seq_all
123
124         local comp_file=$DIR/$tdir/$tfile
125
126         test_mkdir $DIR/$tdir
127
128         # extension size aligned to 64M and limit to 1G
129         $LFS setstripe -E-1 -S64K -C $LOV_MAX_STRIPE_COUNT \
130                 -z $((64*1024*((LOV_MAX_STRIPE_COUNT+1023)>>10<<10))) \
131                 $comp_file || error "Create $comp_file failed"
132
133         local count=$($LFS getstripe -I1 -c $comp_file)
134         [ $count -eq $LOV_MAX_STRIPE_COUNT ] ||
135                 error "stripe count is shrinked to $count"
136 }
137 run_test 0c "Verify SEL comp stripe count limits"
138
139 test_0d() {
140         (( $MDS1_VERSION > $(version_code 2.14.50.115) )) ||
141                 skip_env "Need MDS version at least 2.14.50.115"
142
143         local td=$DIR/$tdir
144         local tf=$td/$tfile
145         local comp_end
146         local stripe_size
147
148         # Create parent directory
149         test_mkdir $td
150
151         # Component end must be a multiple of stripe size
152         # and a multiple of 64KiB to align with the minimum
153         # stripe size value.
154         # Values below 4096 are assumed to be in KiB units.
155         $LFS setstripe -E 127 $tf-1 > /dev/null 2>&1 &&
156                 error "creating $tf-1 with '-E 127' should fail"
157
158         $LFS setstripe -E 128 -S 512 $tf-1 > /dev/null 2>&1 &&
159                 error "creating $tf-1 with '-E 128 -S 512' should fail"
160
161         $LFS setstripe -E 128 $tf-1 ||
162                 error "creating $tf-1 failed"
163
164         yes | dd bs=1K count=129 iflag=fullblock of=$tf-1 &&
165                 error "writing to $tf-1 should fail"
166
167         yes | dd bs=1K count=128 iflag=fullblock of=$tf-1 ||
168                 error "writing to $tf-1 failed"
169
170         comp_end=$($LFS getstripe -I1 -E $tf-1)
171         stripe_size=$($LFS getstripe -I1 -S $tf-1)
172
173         [[ $comp_end == $((128 * 1024)) ]] ||
174                 error "incorrect component end '$comp_end' for $tf-1"
175
176         [[ $stripe_size == $((128 * 1024)) ]] ||
177                 error "incorrect stripe size '$stripe_size' for $tf-1"
178
179         rm $tf-1 || error "removing $tf-1 failed"
180
181         # The stripe size must be a multiple of 64KiB.
182         # Values below 4096 are assumed to be in KiB units.
183         $LFS setstripe -E -1 -S 2047 $tf-2 > /dev/null 2>&1 &&
184                 error "creating $tf-2 with '-S 2047' should fail"
185
186         $LFS setstripe -E -1 -S 2048 $tf-2 ||
187                 error "creating $tf-2 failed"
188
189         stripe_size=$($LFS getstripe -I1 -S $tf-2)
190         [[ $stripe_size == $((2048 * 1024)) ]] ||
191                 error "incorrect stripe size '$stripe_size' for $tf-2"
192
193         rm $tf-2 || error "removing $tf-2 failed"
194 }
195 run_test 0d "Verify comp end and stripe size"
196
197 test_0e() {
198         (( OSTCOUNT >= 2 )) || skip "needs >= 2 OSTs"
199
200         local td=$DIR/$tdir
201         local tf=$td/$tfile
202
203         test_mkdir $td
204
205         # component size 1M can only utilize 1 stripe
206         $LFS setstripe -E1M -S1M -c2 -Eeof -S1M -c2 $tf ||
207                 error "failed to setstripe $tf"
208
209         local sc=$($LFS getstripe -I1 -c $tf)
210         (( sc == 1 )) || {
211                 $LFS getstripe $tf
212                 error "expect 1 stripe count instread of $sc"
213         }
214         sc=$($LFS getstripe -I2 -c $tf)
215         (( sc == 2 )) || {
216                 $LFS getstripe $tf
217                 error "expect 2 stripe count instread of $sc"
218         }
219
220         (( OSTCOUNT >= 3 )) || skip "needs >= 3 OSTs"
221
222         rm -f $tf
223         # component size 2M can only utilize 2 stripes
224         $LFS setstripe -E2M -S1M -c3 -Eeof -S1M -c3 $tf ||
225                 error "failed to setstripe $tf"
226         sc=$($LFS getstripe -I1 -c $tf)
227         (( sc == 2 )) || {
228                 $LFS getstripe $tf
229                 error "expect 2 stripe count instread of $sc"
230         }
231         sc=$($LFS getstripe -I2 -c $tf)
232         (( sc == 3 )) || {
233                 $LFS getstripe $tf
234                 error "expect 3 stripe count instread of $sc"
235         }
236
237         rm -f $tf
238         # 2nd component size 11M and stripe_size 4M should cross 3 stripes
239         $LFS setstripe -E1M -S1M -c3 -E12M -S4M -c3 $tf ||
240                 error "failed to setstripe $tf"
241         sc=$($LFS getstripe -I1 -c $tf)
242         (( sc == 1 )) || {
243                 $LFS getstripe $tf
244                 error "expect 1 stripe count instread of $sc"
245         }
246         sc=$($LFS getstripe -I2 -c $tf)
247         (( sc == 3 )) || {
248                 $LFS getstripe $tf
249                 error "expect 3 stripe count instread of $sc"
250         }
251 }
252 run_test 0e "lfs setstripe should limite stripe count for component size"
253
254 test_1a() {
255         local comp_file=$DIR/$tdir/$tfile
256         local rw_len=$((3 * 1024 * 1024))       # 3M
257
258         test_mkdir $DIR/$tdir
259         rm -f $comp_file
260
261         $LFS setstripe -E 1m -S 1m -o 0 -E -1 -o 0 $comp_file ||
262                 error "Create $comp_file failed"
263
264         #instantiate all components, so that objs are allocted
265         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
266
267         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
268         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
269
270         [ $ost_idx1 -ne $ost_idx2 ] && error "$ost_idx1 != $ost_idx2"
271
272         small_write $comp_file $rw_len || error "Verify RW failed"
273
274         rm -f $comp_file || error "Delete $comp_file failed"
275 }
276 run_test 1a "Create full components file, reused OSTs"
277
278 # test overstriping (>1 stripe/OST within a component)
279 test_1b() {
280         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
281         [[ $($LCTL get_param mdc.*.import |
282                 grep "connect_flags:.*overstriping") ]] ||
283                 skip "server does not support overstriping"
284
285         local comp_file=$DIR/$tdir/$tfile
286         local rw_len=$((3 * 1024 * 1024))       # 3M
287
288         test_mkdir $DIR/$tdir
289
290         $LFS setstripe -E 2m -S 1m -o 0,0 -E -1 -o 1,1,0,0 $comp_file ||
291                 error "Create $comp_file failed"
292
293         #instantiate all components, so that objs are allocted
294         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=1M
295
296         $LFS getstripe $comp_file
297         local OSTS_1=$($LFS getstripe -I1 $comp_file | grep -o 'l_ost_idx.*' |
298                       awk -e '{print $2}' | tr "\n" "\0")
299         local OSTS_2=$($LFS getstripe -I2 $comp_file | grep -o 'l_ost_idx.*' |
300                       awk -e '{print $2}' | tr "\n" "\0")
301
302         echo ":"$OSTS_1":"
303         echo ":"$OSTS_2":"
304         [ "$OSTS_1" = "0,0," ] || error "incorrect OSTs($OSTS_1) in component 1"
305         [ "$OSTS_2" = "1,1,0,0," ] ||
306                 error "incorrect OSTs($OSTS_2) in component 2"
307
308         small_write $comp_file $rw_len || error "Verify RW failed"
309
310         rm -f $comp_file || error "Delete $comp_file failed"
311 }
312 run_test 1b "Create full components file, overstriping in components"
313
314 # test overstriping with max stripe count
315 test_1c() {
316         [[ $($LCTL get_param mdc.*.import |
317                 grep "connect_flags:.*overstriping") ]] ||
318                 skip "server does not support overstriping"
319         large_xattr_enabled || skip_env "no large xattr support"
320
321         force_new_seq_all
322
323         local comp_file=$DIR/$tdir/$tfile
324         local rw_len=$((3 * 1024 * 1024))       # 3M
325
326         test_mkdir $DIR/$tdir
327
328         $LFS setstripe -E 10m -C 10 -E 110M -C 100 -E -1 \
329             -C $LOV_MAX_STRIPE_COUNT $comp_file ||
330                 error "Create $comp_file failed"
331
332         # Seek & write in to last component so all objects are allocated
333         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=20000
334
335         local count=$($LFS getstripe -c -I1 $DIR/$tdir/$tfile)
336         [ $count -eq 10 ] || error "comp1 stripe count $count, should be 10"
337         count=$($LFS getstripe -c -I2 $DIR/$tdir/$tfile)
338         [ $count -eq 100 ] || error "comp2 stripe count $count, should be 100"
339         count=$($LFS getstripe -c -I3 $DIR/$tdir/$tfile)
340         [ $count -eq $LOV_MAX_STRIPE_COUNT ] ||
341                 error "comp4 stripe count $count != $LOV_MAX_STRIPE_COUNT"
342
343         small_write $comp_file $rw_len || error "Verify RW failed"
344
345         rm -f $comp_file || error "Delete $comp_file failed"
346 }
347 run_test 1c "Test overstriping w/max stripe count"
348
349 base_test_2() {
350         local comp_file=$DIR/$tdir/$tfile
351         local rw_len=$((5 * 1024 * 1024))       # 5M
352         local params=$1
353
354         test_mkdir $DIR/$tdir
355         rm -f $comp_file
356
357         multiop $comp_file oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:c ||
358                 error "create failed $comp_file"
359
360         $LFS setstripe --component-add $params $comp_file ||
361                 error "Add component to $comp_file failed"
362
363         check_component_count $comp_file 1
364
365         dd if=/dev/zero of=$comp_file bs=1M count=1 > /dev/null 2>&1 ||
366                 error "Write first component failed"
367         dd if=$comp_file of=/dev/null bs=1M count=1 > /dev/null 2>&1 ||
368                 error "Read first component failed"
369
370         dd if=/dev/zero of=$comp_file bs=1M count=2 > /dev/null 2>&1 &&
371                 error "Write beyond component should fail"
372         dd if=$comp_file of=/dev/null bs=1M count=2 > /dev/null 2>&1 ||
373                 error "Read beyond component should short read, not fail"
374
375         $LFS setstripe --component-add -E 2M -S 1M -c 1 $comp_file ||
376                 error "Add component to $comp_file failed"
377
378         check_component_count $comp_file 2
379
380         $LFS setstripe --component-add -E -1 -c 3 $comp_file ||
381                 error "Add last component to $comp_file failed"
382
383         check_component_count $comp_file 3
384
385         small_write $comp_file $rw_len || error "Verify RW failed"
386
387         rm -f $comp_file || error "Delete $comp_file failed"
388 }
389
390 test_2a() {
391         base_test_2 "-E 1m -S 1m"
392 }
393 run_test 2a "Add components to existing file"
394
395 test_2b () {
396         base_test_2 "-E 1m -L mdt"
397 }
398 run_test 2b "Add components w/DOM to existing file"
399
400 del_comp_and_verify() {
401         local comp_file=$1
402         local id=$2
403         local left=$3
404         local size=$4
405
406         local opt="-I "
407         if [ $id == "init" -o $id == "^init" ]; then
408                 opt="--component-flags="
409         fi
410
411         $LFS setstripe --component-del $opt$id $comp_file ||
412                 error "Delete component $id from $comp_file failed"
413
414         local comp_cnt=$($LFS getstripe --component-count $comp_file)
415         if grep -q "has no stripe info" <<< "$comp_cnt" ; then
416                 comp_cnt=0
417         fi
418         [ $comp_cnt -ne $left ] && error "$comp_cnt != $left"
419
420         $CHECKSTAT -s $size $comp_file || error "size != $size"
421 }
422
423 base_test_3() {
424         local comp_file=$DIR/$tdir/$tfile
425         local params=$1
426
427         test_mkdir $DIR/$tdir
428         rm -f $comp_file
429
430         $LFS setstripe $params $comp_file || error "Create $comp_file failed"
431
432         check_component_count $comp_file 3
433
434         dd if=/dev/zero of=$comp_file bs=1M count=2
435
436         $LFS setstripe --component-del -I 2 $comp_file &&
437                 error "Component deletion makes hole"
438
439         del_comp_and_verify $comp_file 3 2 $((2 * 1024 * 1024))
440         del_comp_and_verify $comp_file 2 1 $((1 * 1024 * 1024))
441         del_comp_and_verify $comp_file 1 0 0
442
443         rm -f $comp_file || error "Delete $comp_file failed"
444
445         $LFS setstripe -E 1M -S 1M -E 16M -E -1 $comp_file ||
446                 error "Create second $comp_file failed"
447
448         del_comp_and_verify $comp_file "^init" 1 0
449         del_comp_and_verify $comp_file "init" 0 0
450         rm -f $comp_file || error "Delete second $comp_file failed"
451 }
452
453 test_3a() {
454         base_test_3 "-E 1M -S 1M -E 64M -c 2 -E -1 -c 3"
455 }
456 run_test 3a "Delete components from existing file"
457
458 test_3b() {
459         base_test_3 "-E 1M -L mdt -E 64M -S 1M -c 2 -E -1 -c 3"
460 }
461 run_test 3b "Delete components w/DOM from existing file"
462
463 test_4() {
464         skip "Not supported in PFL"
465         # In PFL project, only LCME_FL_INIT is supported, and it can't
466         # be altered by application.
467 }
468 run_test 4 "Modify component flags in existing file"
469
470 test_5() {
471         local parent=$DIR/$tdir
472         local comp_file=$DIR/$tdir/$tfile
473         local subdir=$parent/subdir
474
475         rm -fr $parent
476         test_mkdir $parent
477
478         # set default layout to parent directory
479         $LFS setstripe -E 64M -c 2 -i 0 -E -1 -c 4 -i 0 $parent ||
480                 error "Set default layout to $parent failed"
481
482         # create file under parent
483         touch $comp_file || error "Create $comp_file failed"
484         check_component_count $comp_file 2
485
486         #instantiate all components, so that objs are allocted
487         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=65k
488
489         local ost_idx=$($LFS getstripe -I1 -i $comp_file)
490         [ $ost_idx -ne 0 ] &&
491                 error "component 1 ost_idx $ost_idx != 0"
492
493         ost_idx=$($LFS getstripe -I2 -i $comp_file)
494         [ $ost_idx -ne 0 ] &&
495                 error "component 2 ost_idx $ost_idx != 0"
496
497         # create subdir under parent
498         mkdir -p $subdir || error "Create subdir $subdir failed"
499
500         comp_cnt=$($LFS getstripe -d --component-count $subdir)
501         [ $comp_cnt -ne 2 ] && error "subdir $comp_cnt != 2"
502
503         # create file under subdir
504         touch $subdir/$tfile || error "Create $subdir/$tfile failed"
505
506         check_component_count $subdir/$tfile 2
507
508         # delete default layout setting from parent
509         $LFS setstripe -d $parent ||
510                 error "Delete default layout from $parent failed"
511
512         comp_cnt=$($LFS getstripe -d --component-count $parent)
513         [ $comp_cnt -ne 0 ] && error "$comp_cnt isn't 0"
514
515         rm -f $comp_file || error "Delete $comp_file failed"
516         rm -f $subdir/$tfile || error "Delete $subdir/$tfile failed"
517         rm -r $subdir || error "Delete subdir $subdir failed"
518         rmdir $parent || error "Delete dir $parent failed"
519 }
520 run_test 5 "Inherit composite layout from parent directory"
521
522 test_6() {
523         local comp_file=$DIR/$tdir/$tfile
524
525         test_mkdir $DIR/$tdir
526         rm -f $DIR/$tfile
527
528         $LFS setstripe -c 1 -S 128K $comp_file ||
529                 error "Create v1 $comp_file failed"
530
531         check_component_count $comp_file 0
532
533         dd if=/dev/urandom of=$comp_file bs=1M count=5 oflag=sync ||
534                 error "Write to v1 $comp_file failed"
535
536         local old_chksum=$(md5sum $comp_file)
537
538         # Migrate v1 to composite
539         $LFS migrate -E 1M -S 512K -c 1 -E -1 -S 1M -c 2 $comp_file ||
540                 error "Migrate(v1 -> composite) $comp_file failed"
541
542         check_component_count $comp_file 2
543
544         local chksum=$(md5sum $comp_file)
545         [ "$old_chksum" != "$chksum" ] &&
546                 error "(v1 -> compsoite) $old_chksum != $chksum"
547
548         # Migrate composite to composite
549         $LFS migrate -E 1M -S 1M -c 2 -E 4M -S 1M -c 2 \
550                 -E -1 -S 3M -c 3 $comp_file ||
551                 error "Migrate(compsoite -> composite) $comp_file failed"
552
553         check_component_count $comp_file 3
554
555         chksum=$(md5sum $comp_file)
556         [ "$old_chksum" != "$chksum" ] &&
557                 error "(composite -> compsoite) $old_chksum != $chksum"
558
559         # Migrate composite to v1
560         $LFS migrate -c 2 -S 2M $comp_file ||
561                 error "Migrate(composite -> v1) $comp_file failed"
562
563         check_component_count $comp_file 0
564
565         chksum=$(md5sum $comp_file)
566         [ "$old_chksum" != "$chksum" ] &&
567                 error "(composite -> v1) $old_chksum != $chksum"
568
569         rm -f $comp_file || error "Delete $comp_file failed"
570 }
571 run_test 6 "Migrate composite file"
572
573 test_7() {
574         test_mkdir $DIR/$tdir
575         chmod 0777 $DIR/$tdir || error "chmod $tdir failed"
576
577         local comp_file=$DIR/$tdir/$tfile
578         $RUNAS $LFS setstripe -E 1M -S 1M -c 1 $comp_file ||
579                 error "Create composite file $comp_file failed"
580
581         $RUNAS $LFS setstripe --component-add -E 64M -c 4 $comp_file ||
582                 error "Add component to $comp_file failed"
583
584         $RUNAS $LFS setstripe --component-del -I 2 $comp_file ||
585                 error "Delete component from $comp_file failed"
586
587         $RUNAS $LFS setstripe --component-add -E -1 -c 5 $comp_file ||
588                 error "Add last component to $comp_file failed"
589
590         rm $comp_file || error "Delete composite failed"
591 }
592 run_test 7 "Add/Delete/Create composite file by non-privileged user"
593
594 test_8() {
595         local parent=$DIR/$tdir
596
597         rm -fr $parent
598         mkdir_on_mdt0 $parent
599
600         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c 2 -S 2M \
601                 -E -1 -c 4 -S 4M $parent ||
602                 error "Set default layout to $parent failed"
603
604         bash rundbench -C -D $parent 2 || error "dbench failed"
605
606         rm -fr $parent || error "Delete dir $parent failed"
607 }
608 run_test 8 "Run dbench over composite files"
609
610 test_9() {
611         local comp_file=$DIR/$tdir/$tfile
612
613         test_mkdir $DIR/$tdir
614         rm -f $comp_file
615
616         $LFS setstripe -E 1M -S 1M -E -1 -c 1 $comp_file ||
617                 error "Create $comp_file failed"
618
619         check_component_count $comp_file 2
620
621         replay_barrier $SINGLEMDS
622
623         # instantiate the 2nd component
624         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
625
626         local f1=$($LFS getstripe -I2 $comp_file |
627                         awk '/l_fid:/ {print $7}')
628         echo "before MDS recovery, the ost fid of 2nd component is $f1"
629         fail $SINGLEMDS
630
631         local f2=$($LFS getstripe -I2 $comp_file |
632                         awk '/l_fid:/ {print $7}')
633         echo "after MDS recovery, the ost fid of 2nd component is $f2"
634         [ "x$f1" == "x$f2" ] || error "$f1 != $f2"
635 }
636 run_test 9 "Replay layout extend object instantiation"
637
638 component_dump() {
639         echo $($LFS getstripe $1 |
640                 awk '$1 == "lcm_entry_count:" { printf("%d", $2) }
641                      $1 == "lcme_extent.e_start:" { printf("[%#lx", $2) }
642                      $1 == "lcme_extent.e_end:" { printf(",%s]", $2) }')
643 }
644
645 test_10() {
646         local parent=$DIR/$tdir
647         local root=$MOUNT
648
649         save_layout_restore_at_exit $MOUNT
650
651         rm -rf $parent
652
653         # mount root on $MOUNT2 if FILESET is set
654         if [ -n "$FILESET" ]; then
655                 FILESET="" mount_client $MOUNT2 ||
656                         error "mount $MOUNT2 fail"
657                 root=$MOUNT2
658         fi
659
660         $LFS setstripe -d $root || error "clear root layout"
661
662         # set root composite layout
663         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c2 -S 2M \
664                 -E -1 -c 4 -S 4M $root ||
665                 error "Set root layout failed"
666
667         if [ "$root" == "$MOUNT2" ]; then
668                 umount_client $MOUNT2 ||
669                         error "umount $MOUNT2 fail"
670         fi
671
672         test_mkdir $parent
673         # set a different layout for parent
674         $LFS setstripe -E -1 -c 1 -S 1M $parent ||
675                 error "set $parent layout failed"
676         touch $parent/file1
677
678         local f1_entry=$(component_dump $parent/file1)
679
680         # delete parent's layout
681         $LFS setstripe -d $parent || error "Clear $parent layout failed"
682         touch $parent/file2
683
684         local f2_entry=$(component_dump $parent/file2)
685
686         # verify layout inheritance
687         local eof="EOF"
688         local f1_expect="1[0,EOF]"
689         local f2_expect="3[0,2097152][0x200000,16777216][0x1000000,EOF]"
690
691         echo "f1 expect=$f1_expect"
692         echo "f1 get   =$f1_entry"
693         echo "f2 expect=$f2_expect"
694         echo "f2 get   =$f2_entry"
695
696         [  x$f1_expect != x$f1_entry ] &&
697                 error "$parent/file1 does not inherite parent layout"
698         [  x$f2_expect != x$f2_entry ] &&
699                 error "$parent/file2 does not inherite root layout"
700
701         return 0
702 }
703 run_test 10 "Inherit composite template from root"
704
705 test_11a() {
706         local comp_file=$DIR/$tdir/$tfile
707         test_mkdir $DIR/$tdir
708         rm -f $comp_file
709
710         # only 1st component instantiated
711         $LFS setstripe -E 1M -S 1M -E 2M -E 3M -E -1 $comp_file ||
712                 error "Create $comp_file failed"
713
714         local f1=$($LFS getstripe -I1 $comp_file | grep "l_fid")
715         [[ -z $f1 ]] && error "1: 1st component uninstantiated"
716         local f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
717         [[ -n $f2 ]] && error "1: 2nd component instantiated"
718         local f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
719         [[ -n $f3 ]] && error "1: 3rd component instantiated"
720         local f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
721         [[ -n $f4 ]] && error "1: 4th component instantiated"
722
723         # the first 2 components instantiated
724         # Truncate to exact start of new component - LU-12586
725         $TRUNCATE $comp_file $((1024*1024*1))
726
727         f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
728         [[ -z $f2 ]] && error "2: 2nd component uninstantiated"
729         f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
730         [[ -n $f3 ]] && error "2: 3rd component instantiated"
731         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
732         [[ -n $f4 ]] && error "2: 4th component instantiated"
733
734         # the first 3 components instantiated
735         $TRUNCATE $comp_file $((1024*1024*3 - 1))
736         $TRUNCATE $comp_file $((1024*1024*1+1))
737
738         f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
739         [[ -z $f2 ]] && error "3: 2nd component uninstantiated"
740         f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
741         [[ -z $f3 ]] && error "3: 3rd component uninstantiated"
742         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
743         [[ -n $f4 ]] && error "3: 4th component instantiated"
744
745         # all 4 components instantiated, using append write
746         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
747         ls -l $comp_file
748         rwv -f $comp_file -w -a -n 2 $((1024*1023)) 1
749         ls -l $comp_file
750
751         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
752         [[ -z $f4 ]] && error "4: 4th component uninstantiated"
753
754         return 0
755 }
756 run_test 11a "Verify component instantiation with write/truncate"
757
758 test_11b() {
759         [ $OSTCOUNT -lt 4 ] && skip "needs >= 4 OSTs"
760
761         local file=$DIR/$tdir/$tfile
762
763         test_mkdir $DIR/$tdir
764         rm -f $file
765
766         $LFS setstripe -E 1m -E 1g -c 4 -E eof $DIR/$tdir ||
767                 error "setstripe dir $DIR/$tdir failed"
768         expand_truncate_test $file ||
769                 error "expand_truncate_test failed on $file"
770 }
771 run_test 11b "truncate file set file size correctly"
772
773 test_12() {
774         [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs"
775
776         local file=$DIR/$tdir/$tfile
777         test_mkdir $DIR/$tdir
778         rm -f $file
779
780         # specify ost list for component
781         $LFS setstripe -E 2M -S 1M -c 2 -o 0,1 -E 4M -c 2 -o 1,2 \
782                 -E 6M -c 2 -o 2,1 -E 8M -c 1 -i 2 -E -1 $file ||
783                 error "Create $file failed"
784
785         # clear lod component cache
786         stop $SINGLEMDS || error "stop MDS"
787         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
788         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "start MDS"
789
790         # instantiate all components
791         $TRUNCATE $file $((1024*1024*8+1))
792
793         #verify object alloc order
794         local o1=$($LFS getstripe -I1 $file |
795                         awk '/l_ost_idx:/ {printf("%d",$5)}')
796         [[ $o1 != "01" ]] && error "$o1 is not 01"
797
798         local o2=$($LFS getstripe -I2 $file |
799                         awk '/l_ost_idx:/ {printf("%d",$5)}')
800         [[ $o2 != "12" ]] && error "$o2 is not 12"
801
802         local o3=$($LFS getstripe -I3 $file |
803                         awk '/l_ost_idx:/ {printf("%d",$5)}')
804         [[ $o3 != "21" ]] && error "$o3 is not 21"
805
806         local o4=$($LFS getstripe -I4 $file |
807                         awk '/l_ost_idx:/ {printf("%d",$5)}')
808         [[ $o4 != "2" ]] && error "$o4 is not 2"
809
810         return 0
811 }
812 run_test 12 "Verify ost list specification"
813
814 test_13() { # LU-9311
815         [ $OSTCOUNT -lt 8 ] && skip "needs >= 8 OSTs"
816
817         local file=$DIR/$tfile
818         local dd_count=4
819         local dd_size=$(($dd_count * 1024 * 1024))
820         local real_size
821
822         rm -f $file
823         $LFS setstripe -E 1M -S 1M -c 1 -E 2M -c 2 -E -1 -c -1 -i 1 $file ||
824                 error "Create $file failed"
825         dd if=/dev/zero of=$file bs=1M count=$dd_count
826         real_size=$(stat -c %s $file)
827         [ $real_size -eq $dd_size ] ||
828                 error "dd actually wrote $real_size != $dd_size bytes"
829
830         rm -f $file
831 }
832 run_test 13 "shouldn't reprocess granted resent request"
833
834 test_14() {
835         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
836         local file=$DIR/$tdir/$tfile
837         test_mkdir -p $DIR/$tdir
838         rm -f $file
839
840         $LFS setstripe -E1m -c1 -S1m --pool="pool1" -E2m \
841                         -E4m -c2 -S2m --pool="pool2" -E-1 $file ||
842                 error "Create $file failed"
843
844         # check --pool inheritance
845         local pool
846         pool="$($LFS getstripe -I2 --pool $file)"
847         [ x"$pool" != "xpool1" ] && $LFS getstripe -I2 $file &&
848                 error "$file: component 2 doesn't have poolname pool1"
849         pool="$($LFS getstripe -I4 --pool $file)"
850         [ x"$pool" != "xpool2" ] && $LFS getstripe -I4 $file &&
851                 error "$file: component 4 doesn't have poolname pool2"
852
853         #check --stripe-count inheritance
854         local count
855         count="$($LFS getstripe -I2 -c $file)"
856         [ $count -ne 1 ] && $LFS getstripe -I2 $file &&
857                 error "$file: component 2 doesn't have 1 stripe_count"
858         count="$($LFS getstripe -I4 -c $file)"
859         [ $count -ne 2 ] && $LFS getstripe -I4 $file &&
860                 error "$file: component 4 doesn't have 2 stripe_count"
861
862         #check --stripe-size inheritance
863         local size
864         size="$($LFS getstripe -I2 -S $file)"
865         [ $size -ne $((1024*1024)) ] && $LFS getstripe -I2 $file &&
866                 error "$file: component 2 doesn't have 1M stripe_size"
867         size="$($LFS getstripe -I4 -S $file)"
868         [ $size -ne $((1024*1024*2)) ] && $LFS getstripe -I4 $file &&
869                 error "$file: component 4 doesn't have 2M stripe_size"
870
871         return 0
872 }
873 run_test 14 "Verify setstripe poolname/stripe_count/stripe_size inheritance"
874
875 test_15() {
876         local parent=$DIR/$tdir
877
878         rm -fr $parent
879         test_mkdir $parent
880
881         $LFS setstripe -d $parent || error "delete default layout"
882
883         $LFS setstripe -E 1M -S 1M -E 10M -E eof $parent/f1 || error "create f1"
884         $LFS setstripe -E 4M -E 20M -E eof $parent/f2 || error "create f2"
885         test_mkdir $parent/subdir
886         $LFS setstripe -E 6M -S 1M -c1 -E 30M -c4 -E eof -c $OSTCOUNT \
887                 $parent/subdir || error "setstripe to subdir"
888         $LFS setstripe -E 8M -E eof $parent/subdir/f3 || error "create f3"
889         $LFS setstripe -c 1 $parent/subdir/f4 || error "create f4"
890
891         # none
892         local found=$($LFS find --component-start +2M -E -15M $parent | wc -l)
893         [ $found -eq 0 ] || error "start+2M, end-15M, $found != 0"
894
895         # f2, f3
896         found=$($LFS find --component-start +2M -E -35M $parent | wc -l)
897         [ $found -eq 2 ] || error "start+2M, end-35M, $found != 2"
898
899         # subdir
900         found=$($LFS find --component-start +4M -E -eof $parent | wc -l)
901         [ $found -eq 1 ] || error "start+4M, end-eof, $found != 1"
902
903         local flg_opts="--component-flags init"
904         # none
905         found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
906         [ $found -eq 0 ] ||
907                 error "before write: start=1M, end=10M, flag=init, $found != 0"
908
909         dd if=/dev/zero of=$parent/f1 bs=1M count=2 ||
910                 error "dd $parent/f1 failed"
911
912         # f1
913         found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
914         [ $found -eq 1 ] ||
915                 error "after write: start=1M, end=10M, flag=init, $found != 1"
916
917         local ext_opts="--component-start -1M -E +5M"
918         # parent, subdir, f3, f4
919         found=$($LFS find $ext_opts $parent | wc -l)
920         [ $found -eq 4 ] || error "start-1M, end+5M, $found != 4"
921
922         local cnt_opts="--component-count +2"
923         # subdir
924         found=$($LFS find $ext_opts $cnt_opts $parent | wc -l)
925         [ $found -eq 1 ] || error "start-1M, end+5M, count+2, $found != 1"
926
927         # none
928         found=$($LFS find $ext_opts $cnt_opts $flg_opts $parent | wc -l)
929         [ $found -eq 0 ] ||
930                 error "start-1M, end+5M, count+2, flag=init, $found != 0"
931
932         # f3, f4
933         found=$($LFS find $ext_opts ! $cnt_opts $flg_opts $parent | wc -l)
934         [ $found -eq 2 ] ||
935                 error "start-1M, end+5M, !count+2, flag=init, $found != 2"
936
937         # check last component stripe count
938         if [ $OSTCOUNT -gt 1 ]; then
939                 touch $parent/subdir/f5
940                 $TRUNCATE $parent/subdir/f5 $((32*1024*1024))
941                 found=$($LFS find $parent/subdir -c $OSTCOUNT)
942                 [[ "$found" == "$parent/subdir/f5" ]] ||
943                         error "got '$found' with stripe_count=$OSTCOUNT, not f5"
944         fi
945 }
946 run_test 15 "Verify component options for lfs find"
947
948 test_16a() {
949         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
950         large_xattr_enabled || skip_env "ea_inode feature disabled"
951
952         local file=$DIR/$tdir/$tfile
953         local dir=$DIR/$tdir/dir
954         local temp=$DIR/$tdir/template
955         rm -rf $DIR/$tdir
956         test_mkdir $DIR/$tdir
957
958         #####################################################################
959         #                           1. PFL file
960         # set stripe for source file
961         $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
962                 $file || error "Create $file failed"
963
964         echo "1. PFL file"
965         verify_yaml_layout $file $file.copy $temp "1. PFL file"
966
967         #####################################################################
968         #                           2. plain file
969         # set stripe for source file
970         rm -f $file
971         $LFS setstripe -c2 -o0,1 -i1 $file || error "Create $file failed"
972
973         rm -f $file.copy
974         echo "2. plain file"
975         verify_yaml_layout $file $file.copy $temp "2. plain file"
976
977         #####################################################################
978         #                           3. PFL dir
979         # set stripe for source dir
980         test_mkdir $dir
981         $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
982                 error "setstripe $dir failed"
983
984         test_mkdir $dir.copy
985         echo "3. PFL dir"
986         verify_yaml_layout $dir $dir.copy $temp.dir "3. PFL dir"
987
988         #####################################################################
989         #                           4. plain dir
990         # set stripe for source dir
991         $LFS setstripe -c2 -i-1 $dir || error "setstripe $dir failed"
992
993         echo "4. plain dir"
994         verify_yaml_layout $dir $dir.copy $temp.dir "4. plain dir"
995 }
996 run_test 16a "Verify setstripe/getstripe with YAML config file"
997
998 test_16b() {
999         [[ $($LCTL get_param mdc.*.import |
1000                 grep "connect_flags:.*overstriping") ]] ||
1001                 skip "server does not support overstriping"
1002         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1003         [[ $OSTCOUNT -ge $(($LOV_MAX_STRIPE_COUNT / 2)) ]] &&
1004                 skip_env "too many osts, skipping"
1005         large_xattr_enabled || skip_env "ea_inode feature disabled"
1006
1007         force_new_seq_all
1008
1009         local file=$DIR/$tdir/$tfile
1010         local dir=$DIR/$tdir/dir
1011         local temp=$DIR/$tdir/template
1012         # We know OSTCOUNT < (LOV_MAX_STRIPE_COUNT / 2), so this is overstriping
1013         local large_count=$((LOV_MAX_STRIPE_COUNT / 2 + 10))
1014
1015         rm -rf $DIR/$tdir
1016         test_mkdir $DIR/$tdir
1017
1018         #####################################################################
1019         #                           1. PFL file, overstriping in first comps
1020         # set stripe for source file
1021         $LFS setstripe -E1m -S 1M -o0,0 -E2m -o1,1 -E3m -C $large_count -E-1 \
1022                 $file || error "Create $file failed"
1023
1024         echo "1. PFL file"
1025         verify_yaml_layout $file $file.copy $temp "1. PFL file"
1026
1027         #####################################################################
1028         #                           2. plain file + overstriping
1029         # set stripe for source file
1030         rm -f $file
1031         $LFS setstripe -C $large_count -i1 $file || error "Create $file failed"
1032
1033         rm -f $file.copy
1034         echo "2. plain file"
1035         verify_yaml_layout $file $file.copy $temp "2. plain file"
1036
1037         #####################################################################
1038         #                           3. PFL dir + overstriping
1039         # set stripe for source dir
1040         test_mkdir $dir
1041         $LFS setstripe -E1m -S 1M -o 0,0 -E2m -C $large_count -E-1 $dir ||
1042                 error "setstripe $dir failed"
1043
1044         test_mkdir $dir.copy
1045         echo "3. PFL dir"
1046         verify_yaml_layout $dir $dir.copy $temp.dir "3. PFL dir"
1047
1048         #####################################################################
1049         #                           4. plain dir + overstriping
1050         # set stripe for source dir
1051         $LFS setstripe -C $large_count $dir || error "setstripe $dir failed"
1052
1053         echo "4. plain dir"
1054         verify_yaml_layout $dir $dir.copy $temp.dir "4. plain dir"
1055 }
1056 run_test 16b "Verify setstripe/getstripe with YAML config file + overstriping"
1057
1058 test_16c() {
1059         (( $MDS1_VERSION >= $(version_code 2.13.53.205) )) ||
1060                 skip "need MDS version at least 2.13.53.205"
1061
1062         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1063
1064         local file=$DIR/$tdir/$tfile
1065         local dir=$DIR/$tdir/dir
1066         local temp=$DIR/$tdir/template
1067         rm -rf $DIR/$tdir
1068         test_mkdir $DIR/$tdir
1069
1070         #####################################################################
1071         #                           1. SEL file
1072         # set stripe for source file
1073         $LFS setstripe -E256M -S 1M -c2 -o0,1 -z 64M -E-1 -o1,0 -z 128M \
1074                 $file || error "Create $file failed"
1075
1076         echo "1. SEL file"
1077         verify_yaml_layout $file $file.copy $temp "1. PFL file"
1078
1079         #####################################################################
1080         #                           2. SEL dir
1081         # set stripe for source dir
1082         test_mkdir $dir
1083         $LFS setstripe -E256M -S 1M -c2 -z 64M -E-1 -z 128M \
1084                 $dir || error "setstripe $dir failed"
1085
1086         test_mkdir $dir.copy
1087         echo "2. SEL template on dir"
1088         verify_yaml_layout $dir $dir.copy $temp.dir "2. PFL dir"
1089 }
1090 run_test 16c "Verify setstripe/getstripe for SEL layout with YAML config file"
1091
1092 test_16d() {
1093         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1094
1095         local file=$DIR/$tdir/$tfile
1096         local dir=$DIR/$tdir/dir
1097         local temp=$DIR/$tdir/template
1098         rm -rf $DIR/$tdir
1099         test_mkdir $DIR/$tdir
1100
1101         #####################################################################
1102         #                           1. DOM file
1103         # set stripe for source file
1104         $LFS setstripe -E1m -L mdt -E-1 -o1,0 $file ||
1105                 error "Create $file failed"
1106
1107         echo "1. DOM file"
1108         verify_yaml_layout $file $file.copy $temp "1. DOM file"
1109
1110         #####################################################################
1111         #                           2. DOM dir
1112         # set stripe for source dir
1113         test_mkdir $dir
1114         $LFS setstripe -E1m -L mdt -E-1 -o1,0 $dir || error "Create $dir failed"
1115
1116         test_mkdir $dir.copy
1117         echo "2. DOM dir"
1118         verify_yaml_layout $dir $dir.copy $temp.dir "2. DOM dir"
1119 }
1120 run_test 16d "Verify setstripe/getstripe for DOM layout with YAML config file"
1121
1122
1123 test_17() {
1124         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1125         local file=$DIR/$tdir/$tfile
1126         test_mkdir -p $DIR/$tdir
1127         rm -f $file
1128
1129         $LFS setstripe -E 1M -S 1M -E 3M -c 2 -E -1 -c -1 $file ||
1130                 error "Create $file failed"
1131
1132         local s1=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
1133         local s2=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
1134         local s3=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
1135         echo "1st init: comp size 1:$s1 2:$s2 3:$s3"
1136
1137         # init 2nd component
1138         $TRUNCATE $file $((1024*1024+1))
1139         local s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
1140         local s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
1141         echo "2nd init: comp size 1:$s1n 2:$s2n 3:$s3"
1142
1143         [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
1144         [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
1145
1146         # init 3rd component
1147         $TRUNCATE $file $((1024*1024*3+1))
1148         s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
1149         s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
1150         local s3n=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
1151         echo "3rd init: comp size 1:$s1n 2:$s2n 3:$s3n"
1152
1153         [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
1154         [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
1155         [ $s3 -lt $s3n ] || error "3rd comp size $s3 should < $s3n"
1156 }
1157 run_test 17 "Verify LOVEA grows with more component inited"
1158
1159 check_distribution() {
1160         local file=$1
1161         local objs
1162         local ave
1163         local obj_min_one=$((OSTCOUNT - 1))
1164
1165         objs=$($LFS getstripe $file |
1166                 awk '/l_ost_idx:/ { print $5 }' | wc -l)
1167         let ave=$((objs / OSTCOUNT))
1168
1169         # collect objects per OST distribution
1170         $LFS getstripe $file | awk '/l_ost_idx:/ { print $5 }' | tr -d "," |
1171                 (inuse=( $(for i in $(seq 0 $obj_min_one); do echo 0; done) )
1172                 while read O; do
1173                         let inuse[$O]=$((1 + ${inuse[$O]}))
1174                 done;
1175
1176                 # verify object distribution varies no more than +-1
1177                 for idx in $(seq 0 $obj_min_one); do
1178                         let dif=$((${inuse[$idx]} - ave))
1179                         let dif=${dif#-}
1180                         if [ "$dif" -gt 1 ]; then
1181                                 echo "OST${idx}: ${inuse[$idx]} objects"
1182                                 error "bad distribution on OST${idx}"
1183                         fi
1184                 done)
1185 }
1186
1187 test_18() {
1188         local file1=$DIR/${tfile}-1
1189         local file2=$DIR/${tfile}-2
1190         local file3=$DIR/${tfile}-3
1191
1192         rm -f $file1 $file2 $file3
1193
1194         $LFS setstripe -E 1m -S 1m $file1 ||
1195                 error "Create $file1 failed"
1196         $LFS setstripe -E 1m -S 1m $file2 ||
1197                 error "Create $file2 failed"
1198         $LFS setstripe -E 1m -S 1m $file3 ||
1199                 error "Create $file3 failed"
1200
1201         local objs=$((OSTCOUNT+1))
1202         for comp in $(seq 1 $OSTCOUNT); do
1203                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file1 ||
1204                         error "Add component to $file1 failed 2"
1205                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file2 ||
1206                         error "Add component to $file2 failed 2"
1207                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file3 ||
1208                         error "Add component to $file3 failed 2"
1209         done
1210
1211         $LFS setstripe --component-add -E -1 -c -1 $file1 ||
1212                 error "Add component to $file1 failed 3"
1213         $LFS setstripe --component-add -E -1 -c -1 $file2 ||
1214                 error "Add component to $file2 failed 3"
1215         $LFS setstripe --component-add -E -1 -c -1 $file3 ||
1216                 error "Add component to $file3 failed 3"
1217
1218         # Instantiate all components
1219         dd if=/dev/urandom of=$file1 bs=1M count=$((objs+1)) ||
1220                 error "dd failed for $file1"
1221         dd if=/dev/urandom of=$file2 bs=1M count=$((objs+1)) ||
1222                 error "dd failed for $file2"
1223         dd if=/dev/urandom of=$file3 bs=1M count=$((objs+1)) ||
1224                 error "dd failed for $file3"
1225
1226         check_distribution $file1
1227         check_distribution $file2
1228         check_distribution $file3
1229
1230 }
1231 run_test 18 "check component distribution"
1232
1233 test19_io_base() {
1234         local comp_file=$1
1235         local already_created=${2:-0}
1236         local rw_len=$((3 * 1024 * 1024))       # 3M
1237         local flg_opts=""
1238         local found=""
1239
1240         if [ $already_created != 1 ]; then
1241                 test_mkdir -p $DIR/$tdir
1242                 $LFS setstripe --extension-size 64M -c 1 -E -1 $comp_file ||
1243                         error "Create $comp_file failed"
1244         fi
1245
1246         # write past end of first component, so it is extended
1247         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=127 conv=notrunc ||
1248                 error "dd to extend failed"
1249
1250         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
1251         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
1252
1253         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
1254         [ $ost_idx2 -ne "-1" ] && error "second component init $ost_idx2"
1255
1256         flg_opts="--comp-flags init"
1257         found=$($LFS find --comp-start 0 -E 128M $flg_opts $comp_file | wc -l)
1258         [ $found -eq 1 ] || error "Write: Extended first component not found"
1259
1260         flg_opts="--comp-flags extension"
1261         found=$($LFS find --comp-start 128M -E EOF $flg_opts $comp_file | wc -l)
1262         [ $found -eq 1 ] || error "Write: second component not found"
1263
1264         found=$($LFS find -z 64M $comp_file | wc -l)
1265         [ $found -eq 1 ] || error "component not found by ext size"
1266
1267         found=$($LFS find --extension-size +63M $comp_file | wc -l)
1268         [ $found -eq 1 ] || error "component not found by +ext size"
1269
1270         found=$($LFS find --ext-size -65M $comp_file | wc -l)
1271         [ $found -eq 1 ] || error "component not found by -ext size"
1272
1273         found=$($LFS find -z 65M $comp_file | wc -l)
1274         [ $found -eq 0 ] || error "component found by wrong ext size"
1275
1276         found=$($LFS find -z +65M $comp_file | wc -l)
1277         [ $found -eq 0 ] || error "component found by wrong +ext size"
1278
1279         found=$($LFS find -z -63M $comp_file | wc -l)
1280         [ $found -eq 0 ] || error "component found by wrong -ext size"
1281
1282         found=$($LFS find ! -z 64M $comp_file | wc -l)
1283         [ $found -eq 0 ] || error "component found by negation of ext size"
1284
1285         found=$($LFS find ! -z +63M $comp_file | wc -l)
1286         [ $found -eq 0 ] || error "component found by negation of +ext size"
1287
1288         found=$($LFS find ! -z -65M $comp_file | wc -l)
1289         [ $found -eq 0 ] || error "component found by negation of -ext size"
1290
1291         found=$($LFS find ! -z 65M $comp_file | wc -l)
1292         [ $found -eq 1 ] ||
1293                 error "component not found by negation of wrong ext size"
1294
1295         found=$($LFS find ! -z +65M $comp_file | wc -l)
1296         [ $found -eq 1 ] ||
1297                 error "component not found by negation of wrong +ext size"
1298
1299         found=$($LFS find ! -z -63M $comp_file | wc -l)
1300         [ $found -eq 1 ] ||
1301                 error "component not found by negation of wrong -ext size"
1302
1303         found=$($LFS find -S +1M $comp_file | wc -l)
1304         [ $found -eq 0 ] || error "component found by wrong +stripe size"
1305
1306         found=$($LFS find -c 1 $comp_file | wc -l)
1307         [ $found -eq 1 ] || error "component not found by stripe count"
1308
1309         small_write $comp_file $rw_len || error "Verify RW failed"
1310
1311         sel_layout_sanity $comp_file 2
1312 }
1313
1314 # Self-extending PFL tests
1315 test_19a() {
1316         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1317         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1318                 skip "skipped for lustre < $SEL_VER"
1319
1320         test19_io_base $DIR/$tdir/$tfile
1321 }
1322 run_test 19a "Simple test of extension behavior"
1323
1324 # Same as 19a, but with default layout set on directory rather than on file
1325 test_19b() {
1326         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1327         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1328                 skip "skipped for lustre < $SEL_VER"
1329
1330         local comp_file=$DIR/$tdir/$tfile
1331         local comp_dir=$DIR/$tdir/$tdir
1332         local flg_opts=""
1333         local found=""
1334
1335         test_mkdir -p $DIR/$tdir
1336         $LFS setstripe --ext-size 64M -c 1 -E -1 $DIR/$tdir ||
1337                 error "Setstripe on $DIR/$tdir failed"
1338
1339         # check inheritance for a sub-dir and a file
1340         test_mkdir $comp_dir
1341         found=$($LFS find --comp-start 0 -E 64M $comp_dir | wc -l)
1342         [ $found -eq 1 ] || error "Dir Inheritance: wrong first component size"
1343
1344         flg_opts="--comp-flags extension"
1345         found=$($LFS find --comp-start 64M -E EOF $flg_opts $comp_dir | wc -l)
1346         [ $found -eq 1 ] || error "Dir Inheritance: Second component not found"
1347
1348         touch $comp_file
1349
1350         flg_opts="--comp-flags init"
1351         found=$($LFS find --comp-start 0 -E 64M $flg_opts $comp_file | wc -l)
1352         [ $found -eq 1 ] || error "File Inheritance: wrong first component size"
1353
1354         flg_opts="--comp-flags extension"
1355         found=$($LFS find --comp-start 64M -E EOF $flg_opts $comp_file | wc -l)
1356         [ $found -eq 1 ] || error "File Inheritance: Second component not found"
1357
1358         test19_io_base $comp_file 1
1359 }
1360 run_test 19b "Simple test of SEL as default layout"
1361
1362 # Test behavior when seeking deep in a file
1363 test_19c() {
1364         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1365         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1366                 skip "skipped for lustre < $SEL_VER"
1367
1368         local comp_file=$DIR/$tdir/$tfile
1369         local flg_opts=""
1370         local found=""
1371
1372         test_mkdir -p $DIR/$tdir
1373
1374         $LFS setstripe -z 128M -E 1G -E -1 $comp_file ||
1375                 error "Create $comp_file failed"
1376
1377         # write past end of first component, so it is extended
1378         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=130 conv=notrunc ||
1379                 error "dd to extend failed"
1380
1381         flg_opts="--comp-flags init"
1382         found=$($LFS find --comp-start 0M -E 256M $flg_opts $comp_file | wc -l)
1383         [ $found -eq 1 ] || error "Write: first extension component not found"
1384
1385         flg_opts="--comp-flags extension,^init"
1386         found=$($LFS find --comp-start 256M -E 1024M $flg_opts $comp_file |\
1387                 wc -l)
1388         [ $found -eq 1 ] || error "Write: second extension component not found"
1389
1390         local end_1=$($LFS getstripe -I1 -E $comp_file)
1391
1392         # 256 MiB
1393         [ $end_1 -eq 268435456 ] ||
1394                 error "end of first component $end_1 != 268435456"
1395
1396         # Write past end of extension space component, in to normal component
1397         # should exhaust & remove extension component
1398         dd if=/dev/zero bs=1M count=1 seek=1100 of=$comp_file conv=notrunc ||
1399                 error "dd distant seek failed"
1400
1401         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
1402         # the last component index is 3
1403         local ost_idx2=$($LFS getstripe -I3 -i $comp_file)
1404
1405         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
1406
1407         local start1=$($LFS getstripe -I1 --comp-start $comp_file)
1408         local end1=$($LFS getstripe -I1 -E $comp_file)
1409         local start2=$($LFS getstripe -I3 --comp-start $comp_file)
1410         local end2=$($LFS getstripe -I3 -E $comp_file)
1411
1412         [ $start1 -eq 0 ] || error "start of first component incorrect"
1413         [ $end1 -eq 1073741824 ] || error "end of first component incorrect"
1414         [ $start2 -eq 1073741824  ] ||
1415                 error "start of second component incorrect"
1416         [ "$end2" = "EOF" ] || error "end of second component incorrect"
1417
1418         flg_opts="--comp-flags extension"
1419         found=$($LFS find $flg_opts $comp_file | wc -l)
1420         [ $found -eq 0 ] || error "Seek Write: extension component exists"
1421
1422         sel_layout_sanity $comp_file 2
1423 }
1424 run_test 19c "Test self-extending layout seeking behavior"
1425
1426 test_19d() {
1427         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1428         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1429                 skip "skipped for lustre < $SEL_VER"
1430
1431         local comp_file=$DIR/$tdir/$tfile
1432         local flg_opts=""
1433         local found=""
1434
1435         test_mkdir -p $DIR/$tdir
1436
1437         $LFS setstripe -E 128M -c 1 -z 64M -E -1 $comp_file ||
1438                 error "Create $comp_file failed"
1439
1440         # This will cause component 1 to be extended to 128M, then the
1441         # extension space component will be removed
1442         dd if=/dev/zero of=$comp_file bs=130M count=1 ||
1443                 error "dd to extend failed"
1444
1445         flg_opts="--comp-flags init"
1446         found=$($LFS find --comp-start 0M -E 128M $flg_opts $comp_file | wc -l)
1447         [ $found -eq 1 ] || error "Write: first component not found"
1448
1449         flg_opts="--comp-flags init"
1450         found=$($LFS find --comp-start 128M -E EOF $flg_opts $comp_file | wc -l)
1451         [ $found -eq 1 ] || error "Write: second component not found"
1452
1453         sel_layout_sanity $comp_file 2
1454
1455         # always remove large files in case of DO_CLEANUP=false
1456         rm -f $comp_file || error "Delete $comp_file failed"
1457 }
1458 run_test 19d "Test write which completely spans extension space component"
1459
1460 test_19e_check() {
1461         comp_file=$1
1462
1463         local comp2_flags=$($LFS getstripe -I2 --comp-flags $comp_file)
1464         local comp3_flags=$($LFS getstripe -I3 --comp-flags $comp_file)
1465
1466         [ "$comp2_flags" != "init" ] && error "$comp2_flags != init"
1467         [ "$comp3_flags" != "extension" ] && error "$comp3_flags != extension"
1468
1469         local flg_opts=" --comp-start 2M -E 66M --comp-flags init"
1470         local found=$($LFS find $flg_opts $comp_file | wc -l)
1471         [ $found -eq 1 ] || error "Write: extended second component not found"
1472
1473         flg_opts="--comp-start 66M -E EOF --comp-flags extension"
1474         found=$($LFS find $flg_opts $comp_file | wc -l)
1475         [ $found -eq 1 ] || error "Write: third component not found"
1476
1477         sel_layout_sanity $comp_file 3
1478 }
1479
1480 test_19e() {
1481         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1482         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1483                 skip "skipped for lustre < $SEL_VER"
1484
1485         local comp_file=$DIR/$tdir/$tfile
1486         local rw_len=$((3 * 1024 * 1024))       # 3M
1487         local flg_opts=""
1488         local found=""
1489
1490         test_mkdir -p $DIR/$tdir
1491
1492         $LFS setstripe -E 2m -E -1 -z 64M $comp_file ||
1493                 error "Create $comp_file failed"
1494
1495         replay_barrier $SINGLEMDS
1496
1497         #instantiate & extend second component
1498         dd if=/dev/zero of=$comp_file bs=4M count=1 ||
1499                 error "dd to extend failed"
1500
1501         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
1502         local ost_idx3=$($LFS getstripe -I3 -i $comp_file)
1503
1504         [ $ost_idx2 -eq $ost_idx3 ] && error "$ost_idx2 == $ost_idx3"
1505         [ $ost_idx3 -ne "-1" ] && error "third component init $ost_idx3"
1506
1507         test_19e_check $comp_file
1508
1509         local f1=$($LFS getstripe -I2 $comp_file | awk '/l_fid:/ {print $7}')
1510         echo "before MDS recovery, the ost fid of 2nd component is $f1"
1511
1512         fail $SINGLEMDS
1513
1514         local f2=$($LFS getstripe -I2 $comp_file | awk '/l_fid:/ {print $7}')
1515         echo "after MDS recovery, the ost fid of 2nd component is $f2"
1516         [ "x$f1" == "x$f2" ] || error "$f1 != $f2"
1517
1518         # simply repeat all previous checks, but also verify components are on
1519         # the same OST as before
1520
1521         local ost_idx2_2=$($LFS getstripe -I2 -i $comp_file)
1522         local ost_idx3_2=$($LFS getstripe -I3 -i $comp_file)
1523
1524         [ $ost_idx2_2 -eq $ost_idx3_2 ] && error "$ost_idx2_2 == $ost_idx3_2"
1525         [ $ost_idx3_2 -ne "-1" ] && error "second component init $ost_idx3_2"
1526
1527         # verify OST id is the same after failover
1528         [ $ost_idx2 -ne $ost_idx2_2 ] &&
1529                 error "$ost_idx2 != $ost_idx2_2, changed after failover"
1530
1531         test_19e_check $comp_file
1532 }
1533 run_test 19e "Replay of layout instantiation & extension"
1534
1535 test_19f() {
1536         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1537         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1538                 skip "skipped for lustre < $SEL_VER"
1539
1540         local comp_file=$DIR/$tdir/$tfile
1541         local flg_opts=""
1542         local found=""
1543
1544         test_mkdir -p $DIR/$tdir
1545
1546         $LFS setstripe -E 256M --comp-flags extension -E -1 $comp_file
1547
1548         [ $? != 0 ] || error "should not be able to manually set extension flag"
1549
1550 }
1551 run_test 19f "Rejection of invalid layouts"
1552
1553 test_19g() {
1554         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1555         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1556                 skip "skipped for lustre < $SEL_VER"
1557
1558         local file1=$DIR/${tfile}-1
1559         local file2=$DIR/${tfile}-2
1560
1561         test_mkdir -p $DIR/$tdir
1562         multiop $file1 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:c ||
1563                 error "create failed $file1"
1564         multiop $file2 oO_RDWR:O_CREAT:O_LOV_DELAY_CREATE:c ||
1565                 error "create failed $file2"
1566
1567         $LFS setstripe --component-add -E 1G -c 1 $file1 ||
1568                 error "comp-add [0,1G] failed $file1"
1569         $LFS setstripe --component-add -E 512M -z 128M $file1 &&
1570                 error "comp-add [1G,1G],SEL[1G,512M] succeded $file1"
1571         $LFS setstripe --component-add -E 10G -z 128M $file1 ||
1572                 error "comp-add [1G,1G],SEL[1G,10G] failed $file1"
1573         $LFS setstripe --component-add -E -1 $file1 ||
1574                 error "comp-add [10G,-1] failed $file1"
1575
1576         $LFS setstripe --component-add -E 1G -z 32M -c 1 $file2 &&
1577                 error "comp-add with smal ext size succeeded $file1"
1578         $LFS setstripe --component-add -E 1G -z 100M -c 1 $file2 &&
1579                 error "comp-add with not aligned ext size succeeded $file1"
1580         $LFS setstripe --component-add -E 1G -z 128M -c 1 $file2 ||
1581                 error "comp-add [0,128M],SEL[128M,1G] failed $file1"
1582         $LFS setstripe --component-add -E 10G $file2 ||
1583                 error "comp-add [1G,10G] failed $file1"
1584         $LFS setstripe --component-add -E -1 -z 128M -c 1 $file2 ||
1585                 error "comp-add [10G,10G],SEL[10G,-1] failed $file1"
1586         $LFS setstripe --component-add -E -1 -z 128M -c 1 $file2 &&
1587                 error "repeated comp-add [10G,10G],SEL[10G,-1] succeeded $file1"
1588
1589         $LFS getstripe $file1
1590         flg_opts="--comp-flags init"
1591         found=$($LFS find --comp-start 0 -E 1G $flg_opts $file1 | wc -l)
1592         [ $found -eq 1 ] || error "First component not found $file1"
1593
1594         flg_opts="--comp-flags ^init"
1595         found=$($LFS find --comp-start 1G -E 1G $flg_opts $file1 | wc -l)
1596         [ $found -eq 1 ] || error "Second component not found $file1"
1597
1598         flg_opts="--comp-flags ^init,extension"
1599         found=$($LFS find --comp-start 1G -E 10G $flg_opts $file1 | wc -l)
1600         [ $found -eq 1 ] || error "Third component not found $file1"
1601
1602         flg_opts="--comp-flags ^init"
1603         found=$($LFS find --comp-start 10G -E EOF $flg_opts $file1 | wc -l)
1604         [ $found -eq 1 ] || error "Fourth component not found $file1"
1605
1606         $LFS getstripe $file2
1607         flg_opts="--comp-flags init"
1608         found=$($LFS find --comp-start 0 -E 128M $flg_opts $file2 | wc -l)
1609         [ $found -eq 1 ] || error "First component not found $file2"
1610
1611         flg_opts="--comp-flags extension"
1612         found=$($LFS find --comp-start 128M -E 1G $flg_opts $file2 | wc -l)
1613         [ $found -eq 1 ] || error "Second component not found $file2"
1614
1615         flg_opts="--comp-flags ^init"
1616         found=$($LFS find --comp-start 1G -E 10G $flg_opts $file2 | wc -l)
1617         [ $found -eq 1 ] || error "Third component not found $file2"
1618
1619         flg_opts="--comp-flags ^init"
1620         found=$($LFS find --comp-start 10G -E 10G $flg_opts $file2 | wc -l)
1621         [ $found -eq 1 ] || error "Fourth component not found $file2"
1622
1623         flg_opts="--comp-flags ^init,extension"
1624         found=$($LFS find --comp-start 10G -E EOF $flg_opts $file2 | wc -l)
1625         [ $found -eq 1 ] || error "Fifth component not found $file2"
1626 }
1627 run_test 19g "component-add behaviour"
1628
1629 # Test out of space behavior
1630 test_20a() {
1631         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1632         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1633                 skip "skipped for lustre < $SEL_VER"
1634
1635         local comp_file=$DIR/$tdir/$tfile
1636         local flg_opts=""
1637         local found=""
1638
1639         test_mkdir -p $DIR/$tdir
1640
1641         # without this, a previous delete can finish after we check free space
1642         wait_delete_completed
1643         wait_mds_ost_sync
1644
1645         # First component is on OST0
1646         $LFS setstripe -E 256M -i 0 -z 64M -E -1 -z 128M $comp_file ||
1647                 error "Create $comp_file failed"
1648
1649         # write past end of first component, so it is extended
1650         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=66 ||
1651                 error "dd to extend failed"
1652
1653         flg_opts="--comp-flags extension"
1654         found=$($LFS find --comp-start 128M -E 256M $flg_opts $comp_file |wc -l)
1655         [ $found -eq 1 ] || error "Write: Second component not found"
1656
1657         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
1658         local wms=$(ost_watermarks_set_enospc $tfile $ost_idx1 |
1659                     grep "watermarks")
1660         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
1661
1662         flg_opts="--comp-flags extension"
1663         # Write past current init comp, but we won't extend (because no space)
1664         dd if=/dev/zero of=$comp_file bs=1M count=10 seek=200 ||
1665                 error "dd write past current comp failed"
1666
1667         $LFS getstripe $comp_file
1668
1669         flg_opts="--comp-flags init"
1670         found=$($LFS find --comp-start 128M -E 256M $flg_opts $comp_file | \
1671                 wc -l)
1672         [ $found -eq 1 ] || error "Write: third component not found"
1673
1674         flg_opts="--comp-flags extension"
1675         found=$($LFS find --comp-start 256M -E EOF $flg_opts $comp_file |wc -l)
1676         [ $found -eq 1 ] || error "Write: fourth extension component not found"
1677
1678         sel_layout_sanity $comp_file 3
1679 }
1680 run_test 20a "Test out of space, spillover to defined component"
1681
1682 test_20b() {
1683         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1684         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1685                 skip "skipped for lustre < $SEL_VER"
1686
1687         local comp_file=$DIR/$tdir/$tfile
1688         local flg_opts=""
1689         local found=""
1690
1691         test_mkdir -p $DIR/$tdir
1692
1693         # Pool allows us to force use of only certain OSTs
1694         pool_add $TESTNAME || error "Pool creation failed"
1695         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
1696
1697         # normal component to 10M, extendable component to 1G
1698         # further extendable to EOF
1699         $LFS setstripe -E 10M -E 1G -p $TESTNAME -z 64M -E -1 -p "" -z 128M \
1700                 $comp_file || error "Create $comp_file failed"
1701
1702         replay_barrier $SINGLEMDS
1703
1704         found=$($LFS find --comp-start 10M -E 10M $flg_opts $comp_file | wc -l)
1705         [ $found -eq 1 ] || error "Zero length component not found"
1706
1707         local ost_idx1=0
1708         local wms=$(ost_watermarks_set_enospc $tfile $ost_idx1 |
1709                     grep "watermarks")
1710         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
1711
1712         # write past end of first component
1713         # This should remove the next component, since OST0 is out of space
1714         # and it is striped there (pool contains only OST0)
1715         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=14 ||
1716                 error "dd to extend/remove failed"
1717
1718         $LFS getstripe $comp_file
1719
1720         found=$($LFS find --comp-start 10M -E 10M $flg_opts $comp_file | wc -l)
1721         [ $found -eq 0 ] || error "Write: zero length component still present"
1722
1723         flg_opts="--comp-flags init"
1724         found=$($LFS find --comp-start 10M -E 138M $flg_opts $comp_file | wc -l)
1725         [ $found -eq 1 ] || error "Write: second component not found"
1726
1727         flg_opts="--comp-flags extension"
1728         found=$($LFS find --comp-start 138M -E EOF $flg_opts $comp_file | wc -l)
1729         [ $found -eq 1 ] || error "Write: third component not found"
1730
1731         fail $SINGLEMDS
1732
1733         found=$($LFS find --comp-start 10M -E 10M $flg_opts $comp_file | wc -l)
1734         [ $found -eq 0 ] || error "Failover: 0-length component still present"
1735
1736         flg_opts="--comp-flags init"
1737         found=$($LFS find --comp-start 10M -E 138M $flg_opts $comp_file | wc -l)
1738         [ $found -eq 1 ] || error "Failover: second component not found"
1739
1740         flg_opts="--comp-flags extension"
1741         found=$($LFS find --comp-start 138M -E EOF $flg_opts $comp_file | wc -l)
1742         [ $found -eq 1 ] || error "Failover: third component not found"
1743
1744         sel_layout_sanity $comp_file 3
1745 }
1746 run_test 20b "Remove component without instantiation when there is no space"
1747
1748 test_20c() {
1749         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1750         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1751                 skip "skipped for lustre < $SEL_VER"
1752
1753         local comp_file=$DIR/$tdir/$tfile
1754         local flg_opts=""
1755         local found=""
1756
1757         test_mkdir -p $DIR/$tdir
1758
1759         # pool is used to limit available OSTs to 0 and 1, so we can set all
1760         # available OSTs out of space
1761         pool_add $TESTNAME || error "Pool creation failed"
1762         pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
1763
1764         # without this, a previous delete can finish after we check free space
1765         wait_delete_completed
1766         wait_mds_ost_sync
1767
1768         $LFS setstripe -E 100M -E -1 -p $TESTNAME -z 64M $comp_file ||
1769                 error "Create $comp_file failed"
1770
1771         local ost_idx1=0
1772         local ost_idx2=1
1773         local wms=$(ost_watermarks_set_enospc $tfile $ost_idx1 |
1774                     grep "watermarks")
1775         local wms2=$(ost_watermarks_set_enospc $tfile $ost_idx2 |
1776                      grep "watermarks")
1777         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
1778         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx2 $wms2" EXIT
1779
1780         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=120 &&
1781                 error "dd should fail with ENOSPC"
1782
1783         flg_opts="--comp-flags init"
1784         found=$($LFS find --comp-start 0M -E 100M $flg_opts $comp_file | wc -l)
1785         [ $found -eq 1 ] || error "Write: First component not found"
1786
1787         flg_opts="--comp-flags ^init"
1788         found=$($LFS find --comp-start 100M -E 100M $flg_opts $comp_file |wc -l)
1789         [ $found -eq 1 ] || error "Write: 0-length component not found"
1790
1791         flg_opts="--comp-flags extension"
1792         found=$($LFS find --comp-start 100M -E EOF $flg_opts $comp_file | wc -l)
1793         [ $found -eq 1 ] || error "Write: third extension component not found"
1794
1795         sel_layout_sanity $comp_file 3
1796 }
1797 run_test 20c "Test inability to stripe new extension component"
1798
1799 test_20d() {
1800         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1801         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1802                 skip "skipped for lustre < $SEL_VER"
1803
1804         local comp_file=$DIR/$tdir/$tfile
1805         test_mkdir -p $DIR/$tdir
1806
1807         wait_delete_completed
1808         wait_mds_ost_sync
1809
1810         pool_add $TESTNAME || error "Pool creation failed"
1811         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
1812         $LFS setstripe -E 64m -E -1 -p $TESTNAME -z 64M $comp_file ||
1813                 error "Create $comp_file failed"
1814
1815         replay_barrier $SINGLEMDS
1816
1817         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
1818         dd if=/dev/zero bs=1M count=1 seek=100 of=$comp_file
1819         RC=$?
1820
1821         ost_watermarks_clear_enospc $tfile 0 $wms
1822         [ $RC -eq 0 ] || error "dd failed: $RC"
1823
1824         $LFS getstripe $comp_file
1825         local flg_opts="--comp-start 64M -E 128M --comp-flags init"
1826         local found=$($LFS find $flg_opts $comp_file | wc -l)
1827         [ $found -eq 1 ] || error "Write: component (64M-128M) not found"
1828
1829         local ost_idx=$($LFS getstripe -I3 -i $comp_file)
1830         [ "$ost_idx" != "-1" ] && error "Write: EXT component disappeared"
1831
1832         fail $SINGLEMDS
1833
1834         found=$($LFS find $flg_opts $comp_file | wc -l)
1835         [ $found -eq 1 ] || error "Failover: component (64M-128M) not found"
1836
1837         ost_idx=$($LFS getstripe -I3 -i $comp_file)
1838         [ "$ost_idx" != "-1" ] && error "Failover: EXT component disappeared"
1839
1840         sel_layout_sanity $comp_file 3
1841 }
1842 run_test 20d "Low on space + 0-length comp: force extension"
1843
1844 test_20e() {
1845         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1846         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1847                 skip "skipped for lustre < $SEL_VER"
1848
1849         local comp_file=$DIR/$tdir/$tfile
1850         test_mkdir -p $DIR/$tdir
1851
1852         wait_delete_completed
1853         wait_mds_ost_sync
1854
1855         pool_add $TESTNAME || error "Pool creation failed"
1856         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
1857
1858         $LFS setstripe -E 64m -E 640M -z 64M -p $TESTNAME -E -1 $comp_file ||
1859                 error "Create $comp_file failed"
1860
1861         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
1862
1863         dd if=/dev/zero bs=1M count=1 seek=100 of=$comp_file
1864         RC=$?
1865
1866         ost_watermarks_clear_enospc $tfile 0 $wms
1867         [ $RC -eq 0 ] || error "dd failed $RC"
1868
1869         $LFS getstripe $comp_file
1870         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
1871         local found=$($LFS find $flg_opts $comp_file | wc -l)
1872         [ $found -eq 1 ] || error "Write: component (64M-EOF) not found"
1873
1874         local ost_idx=$($LFS getstripe -I2 -i $comp_file)
1875         [ "$ost_idx" != "" ] && error "Write: 0-length component still exists"
1876         ost_idx=$($LFS getstripe -I3 -i $comp_file)
1877         [ "$ost_idx" != "" ] && error "Write: extension component still exists"
1878
1879         sel_layout_sanity $comp_file 2
1880 }
1881 run_test 20e "ENOSPC with next real comp: spillover and backward extension"
1882
1883 # Simple DoM interaction test
1884 test_21a() {
1885         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1886                 skip "skipped for lustre < $SEL_VER"
1887
1888         local comp_file=$DIR/$tdir/$tfile
1889         local flg_opts=""
1890         local found=""
1891
1892         test_mkdir -p $DIR/$tdir
1893
1894         # simple, correct self-extending layout after DoM component
1895         $LFS setstripe -E 1M -L mdt -E -1 -z 64m $comp_file || \
1896                 error "Create $comp_file failed"
1897
1898         # Write to DoM component & to self-extending comp after it
1899         dd if=/dev/zero bs=1M count=12 of=$comp_file ||
1900                 error "dd to extend failed"
1901
1902         flg_opts="--comp-flags init"
1903         found=$($LFS find --comp-start 1M -E 65M $flg_opts $comp_file | wc -l)
1904         [ $found -eq 1 ] || error "Write: extended component not found"
1905
1906         flg_opts="--comp-flags extension"
1907         found=$($LFS find --comp-start 65M $flg_opts $comp_file | wc -l)
1908         [ $found -eq 1 ] || error "Write: extension component not found"
1909
1910         sel_layout_sanity $comp_file 3
1911 }
1912 run_test 21a "Simple DoM interaction tests"
1913
1914 # DoM + extension + removal
1915 test_21b() {
1916         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1917         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1918                 skip "skipped for lustre < $SEL_VER"
1919
1920         local comp_file=$DIR/$tdir/$tfile
1921         local ost_name=$(ostname_from_index 0)
1922         local flg_opts=""
1923         local found=""
1924
1925         test_mkdir -p $DIR/$tdir
1926
1927         # DoM, extendable component, further extendable component
1928         $LFS setstripe -E 1M -L mdt -E 256M -i 0 -z 64M -E -1 -z 128M \
1929                 $comp_file || error "Create $comp_file failed"
1930
1931         found=$($LFS find --comp-start 1M -E 1M $flg_opts $comp_file | wc -l)
1932         [ $found -eq 1 ] || error "Write: Zero length component not found"
1933
1934         # This also demonstrates that we will avoid degraded OSTs
1935         do_facet ost1 $LCTL set_param -n obdfilter.$ost_name.degraded=1
1936         # sleep to guarantee we see the degradation
1937         sleep_maxage
1938
1939         # un-degrade on exit
1940         stack_trap "do_facet ost1 $LCTL set_param -n \
1941                 obdfilter.$ost_name.degraded=0; sleep_maxage" EXIT
1942
1943         # This should remove the first component after DoM and spill over to
1944         # the next one
1945         dd if=/dev/zero bs=1M count=2 of=$comp_file ||
1946                 error "dd to remove+spill over failed"
1947
1948         found=$($LFS find --comp-start 1M -E 1M $flg_opts $comp_file | wc -l)
1949         [ $found -eq 0 ] || error "Write: Zero length component still present"
1950
1951         flg_opts="--comp-flags init"
1952         found=$($LFS find --comp-start 1M -E 129M $flg_opts $comp_file | wc -l)
1953         [ $found -eq 1 ] || error "Write: extended component not found"
1954
1955         flg_opts="--comp-flags extension"
1956         found=$($LFS find --comp-start 129M -E EOF $flg_opts $comp_file |wc -l)
1957         [ $found -eq 1 ] || error "Write: extension component not found"
1958
1959         sel_layout_sanity $comp_file 3
1960 }
1961 run_test 21b "DoM followed by extendable component with removal"
1962
1963 # Test of repeat component behavior with OOS/degraded OST
1964 test_22a() {
1965         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
1966         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
1967                 skip "skipped for lustre < $SEL_VER"
1968
1969         local comp_file=$DIR/$tdir/$tfile
1970         local flg_opts=""
1971         local found=""
1972
1973         test_mkdir -p $DIR/$tdir
1974
1975         $LFS setstripe -E -1 -c 1 -z 128M $comp_file ||
1976                 error "Create $comp_file failed"
1977
1978         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
1979         local ost_name=$(ostname_from_index $ost_idx1)
1980
1981         # write past end of first component, so it is extended
1982         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=130 ||
1983                 error "dd to extend failed"
1984
1985         flg_opts="--comp-flags extension"
1986         found=$($LFS find --comp-start 256M -E EOF $flg_opts $comp_file | wc -l)
1987         [ $found -eq 1 ] || error "Write: second component not found"
1988
1989         # degrade OST for component 1
1990         do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
1991                 obdfilter.$ost_name.degraded=1
1992         # sleep to guarantee we see the degradation
1993         sleep_maxage
1994
1995         # un-degrade on exit
1996         stack_trap "do_facet ost$((ost_idx1+1)) $LCTL set_param -n \
1997                 obdfilter.$ost_name.degraded=0; sleep_maxage" EXIT
1998
1999         replay_barrier $SINGLEMDS
2000
2001         # seek past the end of current comp & write, should cause a new comp
2002         # to be created (ie repeat previous comp)
2003         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=300 ||
2004                 error "dd to repeat failed"
2005
2006         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
2007
2008         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
2009
2010         flg_opts="--comp-flags init"
2011         found=$($LFS find --comp-start 256M $flg_opts $comp_file | wc -l)
2012         [ $found -eq 1 ] || error "Write: second component not found"
2013
2014         flg_opts="--comp-flags extension"
2015         found=$($LFS find --comp-start 384M -E EOF $flg_opts $comp_file | wc -l)
2016         [ $found -eq 1 ] || error "Write: extension component not found"
2017
2018         fail $SINGLEMDS
2019
2020         local ost_idx2_2=$($LFS getstripe -I2 -i $comp_file)
2021         [ $ost_idx2_2 -ne $ost_idx2 ] && error "$ost_idx2_2 != $ost_idx2"
2022
2023         flg_opts="--comp-flags init"
2024         found=$($LFS find --comp-start 256M $flg_opts $comp_file | wc -l)
2025         [ $found -eq 1 ] || error "Failover: second component not found"
2026
2027         flg_opts="--comp-flags extension"
2028         found=$($LFS find --comp-start 384M -E EOF $flg_opts $comp_file | wc -l)
2029         [ $found -eq 1 ] || error "Failover: extension component not found"
2030
2031         sel_layout_sanity $comp_file 3
2032 }
2033 run_test 22a "Test repeat component behavior with degraded OST"
2034
2035 # Test repeat behavior with low space
2036 test_22b() {
2037         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2038         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2039                 skip "skipped for lustre < $SEL_VER"
2040
2041         local comp_file=$DIR/$tdir/$tfile
2042         local flg_opts=""
2043         local found=""
2044
2045         test_mkdir -p $DIR/$tdir
2046
2047         # without this, a previous delete can finish after we check free space
2048         wait_delete_completed
2049         wait_mds_ost_sync
2050
2051         $LFS setstripe -E -1 -c 1 -z 128M \
2052                 $comp_file || error "Create $comp_file failed"
2053
2054         # write past end of first component, so it is extended
2055         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=130 ||
2056                 error "dd to extend failed"
2057
2058         flg_opts="--comp-flags extension"
2059         found=$($LFS find --comp-start 256M -E EOF $flg_opts $comp_file | wc -l)
2060         [ $found -eq 1 ] || error "Write: Second component not found"
2061
2062         # set our OST low on space
2063         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
2064         local wms=$(ost_watermarks_set_low_space $ost_idx1 | grep "watermarks")
2065
2066         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
2067
2068         # Write past end of current space, fail to extend, causing repeat
2069         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=300 ||
2070                 error "dd to repeat failed"
2071
2072         $LFS getstripe $comp_file
2073
2074         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
2075
2076         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
2077
2078         flg_opts="--comp-flags init"
2079         found=$($LFS find --comp-start 256M $flg_opts $comp_file | wc -l)
2080         [ $found -eq 1 ] || error "Write: Second component not found"
2081
2082         flg_opts="--comp-flags extension"
2083         found=$($LFS find --comp-start 384M -E EOF $flg_opts $comp_file | wc -l)
2084         [ $found -eq 1 ] || error "Write: Extension component not found"
2085
2086         sel_layout_sanity $comp_file 3
2087 }
2088 run_test 22b "Test simple 'out of space' condition with repeat"
2089
2090 # This tests both "repeat" and "extend in place when repeat fails" aspects
2091 # of repeating components
2092 test_22c() {
2093         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2094         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2095                 skip "skipped for lustre < $SEL_VER"
2096
2097         local comp_file=$DIR/$tdir/$tfile
2098         local flg_opts=""
2099         local found=""
2100
2101         test_mkdir -p $DIR/$tdir
2102
2103         # pool is used to limit available OSTs to 0 and 1, so we can set all
2104         # available OSTs out of space
2105         pool_add $TESTNAME || error "Pool creation failed"
2106         pool_add_targets $TESTNAME 0 1 || error "Pool add targets failed"
2107
2108         # without this, a previous delete can finish after we check free space
2109         wait_delete_completed
2110         wait_mds_ost_sync
2111
2112         $LFS setstripe -E -1 -z 64M -c 1 -p "$TESTNAME" $comp_file || \
2113                 error "Create $comp_file failed"
2114
2115         # write past end of first component, so it is extended
2116         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=80 conv=notrunc ||
2117                 error "dd to extend failed"
2118
2119         $LFS getstripe $comp_file
2120
2121         flg_opts="--comp-flags extension"
2122         found=$($LFS find --comp-start 128M -E EOF $flg_opts $comp_file | wc -l)
2123         [ $found -eq 1 ] || error "Write: second component not found"
2124
2125         # set our OST out of space
2126         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
2127         local wms=$(ost_watermarks_set_enospc $tfile $ost_idx1 |
2128                     grep "watermarks")
2129         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx1 $wms" EXIT
2130
2131         # This should create a repeat component on a new OST
2132         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=180 conv=notrunc ||
2133                 error "dd to repeat failed"
2134
2135         $LFS getstripe $comp_file
2136
2137         local comp_cnt=$($LFS getstripe --component-count $comp_file)
2138         [ $comp_cnt -ne 3 ] && error "component count: $comp_cnt, should be 3"
2139
2140         # New second component should be on a different OST
2141         local ost_idx2=$($LFS getstripe --comp-start=128m \
2142                          --comp-end=192m --comp-flags=init -i $comp_file)
2143
2144         [ $ost_idx1 -eq $ost_idx2 ] && error "2nd comp: same OST $ost_idx1"
2145
2146         local wms2=$(ost_watermarks_set_enospc $tfile $ost_idx2 |
2147                      grep "watermarks")
2148         stack_trap "ost_watermarks_clear_enospc $tfile $ost_idx2 $wms2" EXIT
2149
2150         # now that the second OST is out of space (as is the first OST), we
2151         # attempt to extend.  This should result in an extension of the
2152         # existing component, rather than a new component.
2153         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=240 conv=notrunc ||
2154                 error "dd for forced extension failed"
2155
2156         $LFS getstripe $comp_file
2157
2158         # clear out of space on first OST
2159         ost_watermarks_clear_enospc $tfile $ost_idx1 $wms
2160
2161         # finally, now that the first OST has space again, we attempt to
2162         # extend one last time.  This should create a new component on the
2163         # first OST
2164         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=300 conv=notrunc ||
2165                 error "dd for repeat on first OST failed"
2166
2167         $LFS getstripe $comp_file
2168
2169         flg_opts="--comp-flags init"
2170         found=$($LFS find --comp-start 128M $flg_opts $comp_file | wc -l)
2171         [ $found -eq 1 ] || error "Write: second component not found"
2172
2173         flg_opts="--comp-flags init"
2174         found=$($LFS find --comp-start 256M $flg_opts $comp_file | wc -l)
2175         [ $found -eq 1 ] || error "Write: third component not found"
2176
2177         flg_opts="--comp-flags extension"
2178         found=$($LFS find --comp-start 320M -E EOF $flg_opts $comp_file | wc -l)
2179         [ $found -eq 1 ] || error "Write: extension component not found"
2180
2181         sel_layout_sanity $comp_file 4
2182 }
2183 run_test 22c "Test repeat with out of space on > 1 OST"
2184
2185 test_22d_post_check() {
2186         local comp_file=$1
2187         local name=$2
2188         local flg_opts="--comp-flags init"
2189         local found=$($LFS find --comp-start 0M -E 128M $flg_opts $comp_file |
2190                       wc -l)
2191         [ $found -eq 1 ] || {
2192                 $LFS getstripe $comp_file
2193                 error "$name: second component not found"
2194         }
2195
2196         flg_opts="--comp-flags extension"
2197         found=$($LFS find --comp-start 128M -E EOF $flg_opts $comp_file | wc -l)
2198         [ $found -eq 1 ] || error "$name: third extension component not found"
2199
2200         sel_layout_sanity $comp_file 2
2201 }
2202
2203 test_22d_pre() {
2204         local comp_file=$1
2205         local wms="$2"
2206         local RC
2207
2208         # write past end of first component
2209         dd if=/dev/zero of=$comp_file bs=1M count=1 seek=70
2210         RC=$?
2211
2212         ost_watermarks_clear_enospc $tfile 0 $wms
2213         [ $RC -eq 0 ] || error "dd to force extend failed"
2214
2215         test_22d_post_check $comp_file "Write"
2216 }
2217
2218 test_22d() {
2219         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2220         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2221                 skip "skipped for lustre < $SEL_VER"
2222
2223         local comp_file=$DIR/$tdir/$tfile
2224         local flg_opts=""
2225         local found=""
2226
2227         test_mkdir -p $DIR/$tdir
2228
2229         # without this, a previous delete can finish after we check free space
2230         wait_delete_completed
2231         wait_mds_ost_sync
2232
2233         # Pool allows us to force use of only certain OSTs
2234         pool_add $TESTNAME || error "Pool creation failed"
2235         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
2236
2237         # 1. Fail to extend due to OOS, try to repeat within the same pool,
2238         # fail to stripe (again OOS) the 0-length component, remove the
2239         # repeated one, force the extension on the original one.
2240         $LFS setstripe -E -1 -p $TESTNAME -z 64M $comp_file ||
2241                 error "Create $comp_file failed"
2242
2243         replay_barrier $SINGLEMDS
2244
2245         # set our OST out of space
2246         local wms=$(ost_watermarks_set_enospc $tfile 0 | grep "watermarks")
2247
2248         test_22d_pre $comp_file "$wms"
2249         fail $SINGLEMDS
2250         test_22d_post_check $comp_file "Failover"
2251
2252         # 2. repeat with low on space: 0-length repeated component will be
2253         # striped, but still fails to be extended; otherwise the same as (1).
2254         rm -f $comp_file
2255         $LFS setstripe -E -1 -p $TESTNAME -z 64M $comp_file ||
2256                 error "Create $comp_file failed"
2257
2258         replay_barrier $SINGLEMDS
2259
2260         # set our OST low on space
2261         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
2262
2263         test_22d_pre $comp_file "$wms"
2264         fail $SINGLEMDS
2265         test_22d_post_check $comp_file "Failover"
2266 }
2267 run_test 22d "out of/low on space + failed to repeat + forced extension"
2268
2269 test_23a() {
2270         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2271         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2272                 skip "skipped for lustre < $SEL_VER"
2273
2274         local comp_file=$DIR/$tdir/$tfile
2275         test_mkdir -p $DIR/$tdir
2276
2277         $LFS setstripe -z 64M -c 1 -E -1 $comp_file ||
2278                 error "Create $comp_file failed"
2279
2280         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file ||
2281                 error "dd append failed"
2282
2283         local flg_opts="--comp-start 0 -E EOF --comp-flags init"
2284         local found=$($LFS find $flg_opts $comp_file | wc -l)
2285         [ $found -eq 1 ] || error "Append: first component (0-EOF) not found"
2286
2287         local ost_idx=$($LFS getstripe -I2 -i $comp_file)
2288         [ "$ost_idx" != "" ] && error "Append: second component still exists"
2289
2290         sel_layout_sanity $comp_file 1
2291 }
2292 run_test 23a "Append: remove EXT comp"
2293
2294 test_23b() {
2295         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2296         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2297                 skip "skipped for lustre < $SEL_VER"
2298
2299         local comp_file=$DIR/$tdir/$tfile
2300         test_mkdir -p $DIR/$tdir
2301
2302         $LFS setstripe -E 64m -E -1 -z 64M $comp_file ||
2303                 error "Create $comp_file failed"
2304
2305         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file ||
2306                 error "dd append failed"
2307
2308         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
2309         local found=$($LFS find $flg_opts $comp_file | wc -l)
2310         [ $found -eq 1 ] || error "Append: component (64M-EOF) not found"
2311
2312         local ost_idx=$($LFS getstripe -I3 -i $comp_file)
2313         [ "$ost_idx" != "" ] && error "Append: third component still exists"
2314
2315         sel_layout_sanity $comp_file 2
2316 }
2317 run_test 23b "Append with 0-length comp: remove EXT comp"
2318
2319 test_23c() {
2320         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2321         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2322                 skip "skipped for lustre < $SEL_VER"
2323
2324         local comp_file=$DIR/$tdir/$tfile
2325         test_mkdir -p $DIR/$tdir
2326
2327         wait_delete_completed
2328         wait_mds_ost_sync
2329
2330         pool_add $TESTNAME || error "Pool creation failed"
2331         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
2332         $LFS setstripe -E 64m -E -1 -p $TESTNAME -z 64M $comp_file ||
2333                 error "Create $comp_file failed"
2334
2335         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
2336         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file
2337         RC=$?
2338
2339         ost_watermarks_clear_enospc $tfile 0 $wms
2340         [ $RC -eq 0 ] || error "dd append failed: $RC"
2341
2342         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
2343         local found=$($LFS find $flg_opts $comp_file | wc -l)
2344         [ $found -eq 1 ] || error "Append: component (64M-EOF) not found"
2345
2346         local ost_idx=$($LFS getstripe -I3 -i $comp_file)
2347         [ "$ost_idx" != "" ] && error "Append: EXT component still exists"
2348
2349         sel_layout_sanity $comp_file 2
2350 }
2351 run_test 23c "Append with low on space + 0-length comp: force extension"
2352
2353 test_23d() {
2354         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2355         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2356                 skip "skipped for lustre < $SEL_VER"
2357
2358         local comp_file=$DIR/$tdir/$tfile
2359         test_mkdir -p $DIR/$tdir
2360
2361         $LFS setstripe -E 64m -E 640M -z 64M -E -1 $comp_file ||
2362                 error "Create $comp_file failed"
2363
2364         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file ||
2365                 error "dd append failed"
2366
2367         flg_opts="--comp-start 64M -E 640M --comp-flags init"
2368         found=$($LFS find $flg_opts $comp_file | wc -l)
2369         [ $found -eq 1 ] || error "Append: component (64M-640M) not found"
2370
2371         ost_idx=$($LFS getstripe -I3 -i $comp_file)
2372         [ "$ost_idx" != "" ] && error "Append: third component still exists"
2373
2374         sel_layout_sanity $comp_file 3
2375 }
2376 run_test 23d "Append with 0-length comp + next real comp: remove EXT comp"
2377
2378 test_23e() {
2379         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2380         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2381                 skip "skipped for lustre < $SEL_VER"
2382
2383         local comp_file=$DIR/$tdir/$tfile
2384         test_mkdir -p $DIR/$tdir
2385
2386         wait_delete_completed
2387         wait_mds_ost_sync
2388
2389         pool_add $TESTNAME || error "Pool creation failed"
2390         pool_add_targets $TESTNAME 0 || error "Pool add targets failed"
2391
2392         $LFS setstripe -E 64m -E 640M -z 64M -p $TESTNAME -E -1 $comp_file ||
2393                 error "Create $comp_file failed"
2394
2395         local wms=$(ost_watermarks_set_low_space 0 | grep "watermarks")
2396
2397         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file
2398         RC=$?
2399
2400         ost_watermarks_clear_enospc $tfile 0 $wms
2401         [ $RC -eq 0 ] || error "dd append failed $RC"
2402
2403         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
2404         local found=$($LFS find $flg_opts $comp_file | wc -l)
2405         [ $found -eq 1 ] || error "Append: component (64M-EOF) not found"
2406
2407         local ost_idx=$($LFS getstripe -I2 -i $comp_file)
2408         [ "$ost_idx" != "" ] && error "Append: 0-length component still exists"
2409         ost_idx=$($LFS getstripe -I3 -i $comp_file)
2410         [ "$ost_idx" != "" ] && error "Append: extension component still exists"
2411
2412         sel_layout_sanity $comp_file 2
2413 }
2414 run_test 23e "Append with next real comp: spillover and backward extension"
2415
2416 test_23f() {
2417         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
2418         [ "$MDS1_VERSION" -lt $(version_code $SEL_VER) ] &&
2419                 skip "skipped for lustre < $SEL_VER"
2420
2421         local comp_file=$DIR/$tdir/$tfile
2422         test_mkdir -p $DIR/$tdir
2423
2424         $LFS setstripe -z 64M -c 1 -E -1 $comp_file ||
2425                 error "Create $comp_file failed"
2426
2427         local ost_idx=$($LFS getstripe -I1 -i $comp_file)
2428         local wms=$(ost_watermarks_set_low_space $ost_idx | grep "watermarks")
2429
2430         dd if=/dev/zero bs=1M oflag=append count=1 of=$comp_file
2431         RC=$?
2432
2433         ost_watermarks_clear_enospc $tfile $ost_idx $wms
2434         [ $RC -eq 0 ] || error "dd append failed"
2435
2436         local flg_opts="--comp-start 64M -E EOF --comp-flags init"
2437         local found=$($LFS find $flg_opts $comp_file | wc -l)
2438         [ $found -eq 1 ] || error "Append: component (64M-EOF) not found"
2439
2440         ost_idx=$($LFS getstripe -I2 -i $comp_file)
2441         [ "$ost_idx" != "" ] && error "Append: extension component still exists"
2442
2443         sel_layout_sanity $comp_file 2
2444 }
2445 run_test 23f "Append with low on space: repeat and remove EXT comp"
2446
2447 OLDIFS="$IFS"
2448 cleanup_24() {
2449         trap 0
2450         IFS="$OLDIFS"
2451 }
2452
2453 test_24a() {
2454         [ "$OSTCOUNT" -lt "3" ] && skip_env "needs >= 3 OSTs"
2455
2456         trap cleanup_24 EXIT RETURN
2457
2458         local file=$DIR/$tfile
2459
2460         $LFS setstripe -E 1m -c1 -o0 -E eof -c2 -o1,2 $file ||
2461                 error "setstripe on $file"
2462
2463         dd if=/dev/zero of=$file bs=1M count=3 || error "dd failed for $file"
2464         sync
2465
2466         filefrag -ves $file || error "filefrag $file failed"
2467         filefrag_op=$(filefrag -ve -k $file |
2468                       sed -n '/ext:/,/found/{/ext:/d; /found/d; p}')
2469
2470 #Filesystem type is: bd00bd0
2471 #File size of /mnt/lustre/f24a.sanity-pfl is 3145728 (3072 blocks of 1024 bytes)
2472 # ext:     device_logical:        physical_offset: length:  dev: flags:
2473 #   0:        0..    1023:    1572864..   1573887:   1024: 0000: net
2474 #   1:        0..    1023:    1572864..   1573887:   1024: 0002: net
2475 #   2:     1024..    2047:    1573888..   1574911:   1024: 0001: last,net
2476 #/mnt/lustre/f24a.sanity-pfl: 3 extents found
2477
2478         last_lun=$(echo $filefrag_op | cut -d: -f5)
2479
2480         IFS=$'\n'
2481         tot_len=0
2482         num_luns=1
2483         for line in $filefrag_op; do
2484                 frag_lun=$(echo $line | cut -d: -f5)
2485                 ext_len=$(echo $line | cut -d: -f4)
2486                 if [[ "$frag_lun" != "$last_lun" ]]; then
2487                         if (( tot_len != 1024 )); then
2488                                 cleanup_24
2489                                 error "$file: OST$last_lun $tot_len != 1024"
2490                         else
2491                                 (( num_luns += 1 ))
2492                                 tot_len=0
2493                         fi
2494                 fi
2495                 (( tot_len += ext_len ))
2496                 last_lun=$frag_lun
2497         done
2498         if (( num_luns != 3 || tot_len != 1024 )); then
2499                 cleanup_24
2500                 error "$file: $num_luns != 3, $tot_len != 1024 on OST$last_lun"
2501         fi
2502
2503         echo "FIEMAP on $file succeeded"
2504 }
2505 run_test 24a "FIEMAP upon PFL file"
2506
2507 test_25() {
2508         local pfl_f=$DIR/$tdir/"$tfile"_pfl
2509         local dom_f=$DIR/$tdir/"$tfile"_dom
2510         local common_f=$DIR/$tdir/"$tfile"_common
2511         local stripe_count
2512         local stripe_size
2513
2514         mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2515         $LFS setstripe -E 10M -S 64k -c -1 -E 20M -S 1M -E -1 -S 2M -c 1 \
2516                 $pfl_f || error "setstripe $pfl_f failed"
2517         $LFS setstripe -E 256k -L mdt -E -1 -S 1M $dom_f ||
2518                 error "setstripe $dom_f failed"
2519         $LFS setstripe -S 512K -c -1 $common_f ||
2520                 error "setstripe $common_f failed"
2521
2522         #verify lov_getstripe_old with PFL file
2523         stripe_count=$(lov_getstripe_old $pfl_f |
2524                         awk '/stripe_count/ { print $2 }')
2525         stripe_size=$(lov_getstripe_old $pfl_f |
2526                         awk '/stripe_size/ { print $2 }')
2527         [ $stripe_count -eq 1 ] ||
2528                 error "stripe_count $stripe_count !=1 for $pfl_f"
2529         [ $stripe_size -eq 2097152 ] ||
2530                 error "stripe_size $stripe_size != 2097152 for $pfl_f"
2531
2532         #verify lov_getstripe_old with DoM file
2533         stripe_count=$(lov_getstripe_old $dom_f |
2534                         awk '/stripe_count/ { print $2 }')
2535         stripe_size=$(lov_getstripe_old $dom_f |
2536                         awk '/stripe_size/ { print $2 }')
2537         [ $stripe_count -eq 1 ] ||
2538                 error "stripe_count $stripe_count !=1 for $dom_f"
2539         [ $stripe_size -eq 1048576 ] ||
2540                 error "stripe_size $stripe_size != 1048576 for $dom_f"
2541
2542         #verify lov_getstripe_old with common file
2543         stripe_count=$(lov_getstripe_old $common_f |
2544                         awk '/stripe_count/ { print $2 }')
2545         stripe_size=$(lov_getstripe_old $common_f |
2546                         awk '/stripe_size/ { print $2 }')
2547         [ $stripe_count -eq $OSTCOUNT ] ||
2548                 error "stripe_count $stripe_count !=$OSTCOUNT for $common_f"
2549         [ $stripe_size -eq 524288 ] ||
2550                 error "stripe_size $stripe_size != 524288 for $common_f"
2551 }
2552 run_test 25 "Verify old lov stripe API with PFL files"
2553
2554 test_26a() {
2555         $LFS setstripe -E 1m -S 1M -c 1 $DIR/$tfile
2556         dd if=/dev/urandom bs=1M count=10 >> $DIR/$tfile
2557         [ $? != 0 ] || error "append must return an error"
2558 }
2559 run_test 26a "Append to not-existent component"
2560
2561 test_26b() {
2562         $LFS setstripe -E 1m -S 1M -c 1 $DIR/$tfile
2563         dd if=/dev/urandom bs=1M count=1 > $DIR/$tfile
2564         dd if=/dev/urandom bs=1M count=1 >> $DIR/$tfile
2565         [ $? != 0 ] || error "append must return an error"
2566 }
2567 run_test 26b "Append to not-existend component, file size is unknown"
2568
2569 test_26c() {
2570         $LFS setstripe -E 1m -S 1M -c 1 $DIR/$tfile
2571         dd if=/dev/urandom bs=2M count=1 >> $DIR/$tfile
2572         [ $? != 0 ] || error "append must return an error"
2573 }
2574 run_test 26c "Append to not-existend component, crossing the component border"
2575
2576 test_27() {
2577         [[ $($LCTL get_param mdc.*.import) =~ connect_flags.*overstriping ]] ||
2578                 skip "server does not support overstriping"
2579         (( $MDS1_VERSION >= $(version_code 2.15.55.102) )) ||
2580                 skip "need MDS >= 2.12.55.102 for mdt_dump_lmm fix"
2581
2582         stack_trap "rm -f $DIR/$tfile"
2583         # start_full_debug_logging
2584         $LFS setstripe -S 64K -C -1 $DIR/$tfile || error "create $tfile failed"
2585         $LFS getstripe -c $DIR/$tfile || error "getstripe $tfile failed"
2586         cancel_lru_locks
2587         $LFS getstripe -c $DIR/$tfile || error "getstripe failed after clear"
2588
2589         test_mkdir $DIR/$tdir
2590         stack_trap "rm -rf $DIR/$tdir/$tfile"
2591         $LFS setstripe -S 64K -C -1 $DIR/$tdir || error "mkdir $tdir failed"
2592         $LFS getstripe -y $DIR/$tdir || error "getstripe $tdir failed"
2593         touch $DIR/$tdir/$tfile || error "create $tdir/$tfile failed"
2594         cancel_lru_locks
2595         $LFS getstripe -c $DIR/$tdir/$tfile ||
2596                 error "getstripe $tdir/$tfile failed"
2597         #stop_full_debug_logging
2598 }
2599 run_test 27 "overstriping with -C -1 in mdt_dump_lmm"
2600
2601 complete_test $SECONDS
2602 check_and_cleanup_lustre
2603 exit_status