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