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