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