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