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