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