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