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