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