Whamcloud - gitweb
LU-9846 lod: Add overstriping support
[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 SRCDIR=$(dirname $0)
8 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
9
10 ONLY=${ONLY:-"$*"}
11 # Bug number for skipped test:
12 ALWAYS_EXCEPT="$SANITY_PFL_EXCEPT"
13 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
14
15 TMP=${TMP:-/tmp}
16 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
17
18 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
19 . $LUSTRE/tests/test-framework.sh
20 init_test_env $@
21 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
22 init_logging
23
24 check_and_setup_lustre
25
26 if [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.9.51) ]]; then
27         skip_env "Need MDS version at least 2.9.51"
28 fi
29
30 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
31         echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
32
33 build_test_filter
34
35 [ $UID -eq 0 -a $RUNAS_ID -eq 0 ] &&
36         error "\$RUNAS_ID set to 0, but \$UID is also 0!"
37 check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS
38
39 assert_DIR
40 rm -rf $DIR/[Rdfs][0-9]*
41
42 test_0a() {
43         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
44
45         local comp_file=$DIR/$tdir/$tfile
46         local rw_len=$((3 * 1024 * 1024))       # 3M
47
48         test_mkdir $DIR/$tdir
49         rm -f $comp_file
50
51         $LFS setstripe -E 1m -S 1M -c 1 -E -1 -c 1 $comp_file ||
52                 error "Create $comp_file failed"
53
54         #instantiate all components, so that objs are allocted
55         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
56
57         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
58         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
59
60         [ $ost_idx1 -eq $ost_idx2 ] && error "$ost_idx1 == $ost_idx2"
61
62         small_write $comp_file $rw_len || error "Verify RW failed"
63
64         rm -f $comp_file || error "Delete $comp_file failed"
65 }
66 run_test 0a "Create full components file, no reused OSTs"
67
68 test_0b() {
69         [[ $($LCTL get_param mdc.*.import |
70                 grep "connect_flags:.*overstriping") ]] ||
71                 skip "server does not support overstriping"
72         large_xattr_enabled || skip_env "no large xattr support"
73
74         local comp_file=$DIR/$tdir/$tfile
75
76         test_mkdir $DIR/$tdir
77
78         # Create file with 1.1*LOV_MAX_STRIPE_COUNT stripes should succeed
79         $LFS setstripe -E 1m -C $((LOV_MAX_STRIPE_COUNT / 10)) -E -1 \
80                 -C $LOV_MAX_STRIPE_COUNT $comp_file ||
81         error "Create $comp_file failed"
82
83         rm -f $comp_file || error "Delete $comp_file failed"
84
85         # Create file with 2*LOV_MAX_STRIPE_COUNT stripes should fail
86         $LFS setstripe -E 1m -C $LOV_MAX_STRIPE_COUNT -E -1 -C $LOV_MAX_STRIPE_COUNT \
87                 $comp_file && error "Create $comp_file succeeded"
88
89         rm -f $comp_file || error "Delete $comp_file failed"
90 }
91 run_test 0b "Verify comp stripe count limits"
92
93 test_1a() {
94         local comp_file=$DIR/$tdir/$tfile
95         local rw_len=$((3 * 1024 * 1024))       # 3M
96
97         test_mkdir $DIR/$tdir
98         rm -f $comp_file
99
100         $LFS setstripe -E 1m -S 1m -o 0 -E -1 -o 0 $comp_file ||
101                 error "Create $comp_file failed"
102
103         #instantiate all components, so that objs are allocted
104         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
105
106         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
107         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
108
109         [ $ost_idx1 -ne $ost_idx2 ] && error "$ost_idx1 != $ost_idx2"
110
111         small_write $comp_file $rw_len || error "Verify RW failed"
112
113         rm -f $comp_file || error "Delete $comp_file failed"
114 }
115 run_test 1a "Create full components file, reused OSTs"
116
117 # test overstriping (>1 stripe/OST within a component)
118 test_1b() {
119         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
120         [[ $($LCTL get_param mdc.*.import |
121                 grep "connect_flags:.*overstriping") ]] ||
122                 skip "server does not support overstriping"
123
124         local comp_file=$DIR/$tdir/$tfile
125         local rw_len=$((3 * 1024 * 1024))       # 3M
126
127         test_mkdir $DIR/$tdir
128
129         $LFS setstripe -E 1m -S 1m -o 0,0 -E -1 -o 1,1,0,0 $comp_file ||
130                 error "Create $comp_file failed"
131
132         #instantiate all components, so that objs are allocted
133         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=1M
134
135         $LFS getstripe $comp_file
136         local OSTS_1=$($LFS getstripe -I1 $comp_file | grep -o 'l_ost_idx.*' |
137                       awk -e '{print $2}' | tr "\n" "\0")
138         local OSTS_2=$($LFS getstripe -I2 $comp_file | grep -o 'l_ost_idx.*' |
139                       awk -e '{print $2}' | tr "\n" "\0")
140
141         echo ":"$OSTS_1":"
142         echo ":"$OSTS_2":"
143         [ "$OSTS_1" = "0,0," ] || error "incorrect OSTs($OSTS_1) in component 1"
144         [ "$OSTS_2" = "1,1,0,0," ] ||
145                 error "incorrect OSTs($OSTS_2) in component 2"
146
147         small_write $comp_file $rw_len || error "Verify RW failed"
148
149         rm -f $comp_file || error "Delete $comp_file failed"
150 }
151 run_test 1b "Create full components file, overstriping in components"
152
153 # test overstriping with max stripe count
154 test_1c() {
155         [[ $($LCTL get_param mdc.*.import |
156                 grep "connect_flags:.*overstriping") ]] ||
157                 skip "server does not support overstriping"
158         large_xattr_enabled || skip_env "no large xattr support"
159
160         local comp_file=$DIR/$tdir/$tfile
161         local rw_len=$((3 * 1024 * 1024))       # 3M
162
163         test_mkdir $DIR/$tdir
164
165         $LFS setstripe -E 1m -C 10 -E 10M -C 100 -E -1 \
166             -C $LOV_MAX_STRIPE_COUNT $comp_file ||
167                 error "Create $comp_file failed"
168
169         # Seek & write in to last component so all objects are allocated
170         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=20000
171
172         local count=$($LFS getstripe -c -I1 $DIR/$tdir/$tfile)
173         [ $count -eq 10 ] || error "comp1 stripe count $count, should be 10"
174         count=$($LFS getstripe -c -I2 $DIR/$tdir/$tfile)
175         [ $count -eq 100 ] || error "comp2 stripe count $count, should be 100"
176         count=$($LFS getstripe -c -I3 $DIR/$tdir/$tfile)
177         [ $count -eq $LOV_MAX_STRIPE_COUNT ] ||
178                 error "comp4 stripe count $count != $LOV_MAX_STRIPE_COUNT"
179
180         small_write $comp_file $rw_len || error "Verify RW failed"
181
182         rm -f $comp_file || error "Delete $comp_file failed"
183 }
184 run_test 1c "Test overstriping w/max stripe count"
185
186 test_2() {
187         local comp_file=$DIR/$tdir/$tfile
188         local rw_len=$((5 * 1024 * 1024))       # 5M
189
190         test_mkdir $DIR/$tdir
191         rm -f $comp_file
192
193         $LFS setstripe -E 1m -S 1m $comp_file ||
194                 error "Create $comp_file failed"
195
196         local comp_cnt=$($LFS getstripe --component-count $comp_file)
197         [ $comp_cnt -ne 1 ] && error "component count $comp_cnt != 1"
198
199         dd if=/dev/zero of=$comp_file bs=1M count=1 > /dev/null 2>&1 ||
200                 error "Write first component failed"
201         dd if=$comp_file of=/dev/null bs=1M count=1 > /dev/null 2>&1 ||
202                 error "Read first component failed"
203
204         dd if=/dev/zero of=$comp_file bs=1M count=2 > /dev/null 2>&1 &&
205                 error "Write beyond component should fail"
206         dd if=$comp_file of=/dev/null bs=1M count=2 > /dev/null 2>&1 ||
207                 error "Read beyond component should short read, not fail"
208
209         $LFS setstripe --component-add -E 2M -S 1M -c 1 $comp_file ||
210                 error "Add component to $comp_file failed"
211
212         comp_cnt=$($LFS getstripe --component-count $comp_file)
213         [ $comp_cnt -ne 2 ] && error "component count $comp_cnt != 2"
214
215         $LFS setstripe --component-add -E -1 -c 3 $comp_file ||
216                 error "Add last component to $comp_file failed"
217
218         comp_cnt=$($LFS getstripe --component-count $comp_file)
219         [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
220
221         small_write $comp_file $rw_len || error "Verify RW failed"
222
223         rm -f $comp_file || error "Delete $comp_file failed"
224 }
225 run_test 2 "Add component to existing file"
226
227 del_comp_and_verify() {
228         local comp_file=$1
229         local id=$2
230         local left=$3
231         local size=$4
232
233         local opt="-I "
234         if [ $id == "init" -o $id == "^init" ]; then
235                 opt="--component-flags="
236         fi
237
238         $LFS setstripe --component-del $opt$id $comp_file ||
239                 error "Delete component $id from $comp_file failed"
240
241         local comp_cnt=$($LFS getstripe --component-count $comp_file)
242         if grep -q "has no stripe info" <<< "$comp_cnt" ; then
243                 comp_cnt=0
244         fi
245         [ $comp_cnt -ne $left ] && error "$comp_cnt != $left"
246
247         $CHECKSTAT -s $size $comp_file || error "size != $size"
248 }
249
250 test_3() {
251         local comp_file=$DIR/$tdir/$tfile
252
253         test_mkdir $DIR/$tdir
254         rm -f $comp_file
255
256         $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 3 $comp_file ||
257                 error "Create $comp_file failed"
258
259         local comp_cnt=$($LFS getstripe --component-count $comp_file)
260         [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
261
262         dd if=/dev/zero of=$comp_file bs=1M count=2
263
264         $LFS setstripe --component-del -I 2 $comp_file &&
265                 error "Component deletion makes hole"
266
267         del_comp_and_verify $comp_file 3 2 $((2 * 1024 * 1024))
268         del_comp_and_verify $comp_file 2 1 $((1 * 1024 * 1024))
269         del_comp_and_verify $comp_file 1 0 0
270
271         rm -f $comp_file || error "Delete $comp_file failed"
272
273         $LFS setstripe -E 1M -S 1M -E 16M -E -1 $comp_file ||
274                 error "Create second $comp_file failed"
275
276         del_comp_and_verify $comp_file "^init" 1 0
277         del_comp_and_verify $comp_file "init" 0 0
278         rm -f $comp_file || error "Delete second $comp_file failed"
279
280 }
281 run_test 3 "Delete component from existing file"
282
283 test_4() {
284         skip "Not supported in PFL"
285         # In PFL project, only LCME_FL_INIT is supported, and it can't
286         # be altered by application.
287 }
288 run_test 4 "Modify component flags in existing file"
289
290 test_5() {
291         local parent=$DIR/$tdir
292         local comp_file=$DIR/$tdir/$tfile
293         local subdir=$parent/subdir
294
295         rm -fr $parent
296         test_mkdir $parent
297
298         # set default layout to parent directory
299         $LFS setstripe -E 64M -c 2 -i 0 -E -1 -c 4 -i 0 $parent ||
300                 error "Set default layout to $parent failed"
301
302         # create file under parent
303         touch $comp_file || error "Create $comp_file failed"
304         local comp_cnt=$($LFS getstripe --component-count $comp_file)
305         [ $comp_cnt -ne 2 ] && error "file $comp_cnt != 2"
306
307         #instantiate all components, so that objs are allocted
308         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=65k
309
310         local ost_idx=$($LFS getstripe -I1 -i $comp_file)
311         [ $ost_idx -ne 0 ] &&
312                 error "component 1 ost_idx $ost_idx != 0"
313
314         ost_idx=$($LFS getstripe -I2 -i $comp_file)
315         [ $ost_idx -ne 0 ] &&
316                 error "component 2 ost_idx $ost_idx != 0"
317
318         # create subdir under parent
319         mkdir -p $subdir || error "Create subdir $subdir failed"
320
321         comp_cnt=$($LFS getstripe -d --component-count $subdir)
322         [ $comp_cnt -ne 2 ] && error "subdir $comp_cnt != 2"
323
324         # create file under subdir
325         touch $subdir/$tfile || error "Create $subdir/$tfile failed"
326
327         comp_cnt=$($LFS getstripe --component-count $subdir/$tfile)
328         [ $comp_cnt -ne 2 ] && error "$subdir/$tfile $comp_cnt != 2"
329
330         # delete default layout setting from parent
331         $LFS setstripe -d $parent ||
332                 error "Delete default layout from $parent failed"
333
334         comp_cnt=$($LFS getstripe -d --component-count $parent)
335         [ $comp_cnt -ne 0 ] && error "$comp_cnt isn't 0"
336
337         rm -f $comp_file || error "Delete $comp_file failed"
338         rm -f $subdir/$tfile || error "Delete $subdir/$tfile failed"
339         rm -r $subdir || error "Delete subdir $subdir failed"
340         rmdir $parent || error "Delete dir $parent failed"
341 }
342 run_test 5 "Inherit composite layout from parent directory"
343
344 test_6() {
345         local comp_file=$DIR/$tdir/$tfile
346
347         test_mkdir $DIR/$tdir
348         rm -f $DIR/$tfile
349
350         $LFS setstripe -c 1 -S 128K $comp_file ||
351                 error "Create v1 $comp_file failed"
352
353         local comp_cnt=$($LFS getstripe --component-count $comp_file)
354         [ $comp_cnt -ne 0 ] && error "Wrong component count $comp_cnt"
355
356         dd if=/dev/urandom of=$comp_file bs=1M count=5 oflag=sync ||
357                 error "Write to v1 $comp_file failed"
358
359         local old_chksum=$(md5sum $comp_file)
360
361         # Migrate v1 to composite
362         $LFS migrate -E 1M -S 512K -c 1 -E -1 -S 1M -c 2 $comp_file ||
363                 error "Migrate(v1 -> composite) $comp_file failed"
364
365         comp_cnt=$($LFS getstripe --component-count $comp_file)
366         [ "$comp_cnt" -ne 2 ] && error "$comp_cnt != 2"
367
368         local chksum=$(md5sum $comp_file)
369         [ "$old_chksum" != "$chksum" ] &&
370                 error "(v1 -> compsoite) $old_chksum != $chksum"
371
372         # Migrate composite to composite
373         $LFS migrate -E 1M -S 1M -c 2 -E 4M -S 1M -c 2 \
374                 -E -1 -S 3M -c 3 $comp_file ||
375                 error "Migrate(compsoite -> composite) $comp_file failed"
376
377         comp_cnt=$($LFS getstripe --component-count $comp_file)
378         [ "$comp_cnt" -ne 3 ] && error "$comp_cnt != 3"
379
380         chksum=$(md5sum $comp_file)
381         [ "$old_chksum" != "$chksum" ] &&
382                 error "(composite -> compsoite) $old_chksum != $chksum"
383
384         # Migrate composite to v1
385         $LFS migrate -c 2 -S 2M $comp_file ||
386                 error "Migrate(composite -> v1) $comp_file failed"
387
388         comp_cnt=$($LFS getstripe --component-count $comp_file)
389         [ $comp_cnt -ne 0 ] && error "$comp_cnt isn't 0"
390
391         chksum=$(md5sum $comp_file)
392         [ "$old_chksum" != "$chksum" ] &&
393                 error "(composite -> v1) $old_chksum != $chksum"
394
395         rm -f $comp_file || "Delete $comp_file failed"
396 }
397 run_test 6 "Migrate composite file"
398
399 test_7() {
400         test_mkdir $DIR/$tdir
401         chmod 0777 $DIR/$tdir || error "chmod $tdir failed"
402
403         local comp_file=$DIR/$tdir/$tfile
404         $RUNAS $LFS setstripe -E 1M -S 1M -c 1 $comp_file ||
405                 error "Create composite file $comp_file failed"
406
407         $RUNAS $LFS setstripe --component-add -E 64M -c 4 $comp_file ||
408                 error "Add component to $comp_file failed"
409
410         $RUNAS $LFS setstripe --component-del -I 2 $comp_file ||
411                 error "Delete component from $comp_file failed"
412
413         $RUNAS $LFS setstripe --component-add -E -1 -c 5 $comp_file ||
414                 error "Add last component to $comp_file failed"
415
416         rm $comp_file || "Delete composite failed"
417 }
418 run_test 7 "Add/Delete/Create composite file by non-privileged user"
419
420 test_8() {
421         local parent=$DIR/$tdir
422
423         rm -fr $parent
424         test_mkdir $parent
425
426         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c 2 -S 2M \
427                 -E -1 -c 4 -S 4M $parent ||
428                 error "Set default layout to $parent failed"
429
430         sh rundbench -C -D $parent 2 || error "dbench failed"
431
432         rm -fr $parent || error "Delete dir $parent failed"
433 }
434 run_test 8 "Run dbench over composite files"
435
436 test_9() {
437         local comp_file=$DIR/$tdir/$tfile
438
439         test_mkdir $DIR/$tdir
440         rm -f $comp_file
441
442         $LFS setstripe -E 1M -S 1M -E -1 -c 1 $comp_file ||
443                 error "Create $comp_file failed"
444
445         local comp_cnt=$($LFS getstripe --component-count $comp_file)
446         [ $comp_cnt -ne 2 ] && error "component count $comp_cnt != 2"
447
448         replay_barrier $SINGLEMDS
449
450         # instantiate the 2nd component
451         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
452
453         local f1=$($LFS getstripe -I2 $comp_file |
454                         awk '/l_fid:/ {print $7}')
455         echo "before MDS recovery, the ost fid of 2nd component is $f1"
456         fail $SINGLEMDS
457
458         local f2=$($LFS getstripe -I2 $comp_file |
459                         awk '/l_fid:/ {print $7}')
460         echo "after MDS recovery, the ost fid of 2nd component is $f2"
461         [ "x$f1" == "x$f2" ] || error "$f1 != $f2"
462 }
463 run_test 9 "Replay layout extend object instantiation"
464
465 component_dump() {
466         echo $($LFS getstripe $1 |
467                 awk '$1 == "lcm_entry_count:" { printf("%d", $2) }
468                      $1 == "lcme_extent.e_start:" { printf("[%#lx", $2) }
469                      $1 == "lcme_extent.e_end:" { printf(",%s]", $2) }')
470 }
471
472 test_10() {
473         local parent=$DIR/$tdir
474         local root=$MOUNT
475
476         save_layout_restore_at_exit $MOUNT
477
478         rm -rf $parent
479
480         # mount root on $MOUNT2 if FILESET is set
481         if [ -n "$FILESET" ]; then
482                 FILESET="" mount_client $MOUNT2 ||
483                         error "mount $MOUNT2 fail"
484                 root=$MOUNT2
485         fi
486
487         $LFS setstripe -d $root || error "clear root layout"
488
489         # set root composite layout
490         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c2 -S 2M \
491                 -E -1 -c 4 -S 4M $root ||
492                 error "Set root layout failed"
493
494         if [ "$root" == "$MOUNT2" ]; then
495                 umount_client $MOUNT2 ||
496                         error "umount $MOUNT2 fail"
497         fi
498
499         test_mkdir $parent
500         # set a different layout for parent
501         $LFS setstripe -E -1 -c 1 -S 1M $parent ||
502                 error "set $parent layout failed"
503         touch $parent/file1
504
505         local f1_entry=$(component_dump $parent/file1)
506
507         # delete parent's layout
508         $LFS setstripe -d $parent || error "Clear $parent layout failed"
509         touch $parent/file2
510
511         local f2_entry=$(component_dump $parent/file2)
512
513         # verify layout inheritance
514         local eof="EOF"
515         local f1_expect="1[0,EOF]"
516         local f2_expect="3[0,2097152][0x200000,16777216][0x1000000,EOF]"
517
518         echo "f1 expect=$f1_expect"
519         echo "f1 get   =$f1_entry"
520         echo "f2 expect=$f2_expect"
521         echo "f2 get   =$f2_entry"
522
523         [  x$f1_expect != x$f1_entry ] &&
524                 error "$parent/file1 does not inherite parent layout"
525         [  x$f2_expect != x$f2_entry ] &&
526                 error "$parent/file2 does not inherite root layout"
527
528         return 0
529 }
530 run_test 10 "Inherit composite template from root"
531
532 test_11() {
533         local comp_file=$DIR/$tdir/$tfile
534         test_mkdir $DIR/$tdir
535         rm -f $comp_file
536
537         # only 1st component instantiated
538         $LFS setstripe -E 1M -S 1M -E 2M -E 3M -E -1 $comp_file ||
539                 error "Create $comp_file failed"
540
541         local f1=$($LFS getstripe -I1 $comp_file | grep "l_fid")
542         [[ -z $f1 ]] && error "1: 1st component uninstantiated"
543         local f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
544         [[ -n $f2 ]] && error "1: 2nd component instantiated"
545         local f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
546         [[ -n $f3 ]] && error "1: 3rd component instantiated"
547         local f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
548         [[ -n $f4 ]] && error "1: 4th component instantiated"
549
550         # the first 2 components instantiated
551         $TRUNCATE $comp_file $((1024*1024*1+1))
552
553         f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
554         [[ -z $f2 ]] && error "2: 2nd component uninstantiated"
555         f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
556         [[ -n $f3 ]] && error "2: 3rd component instantiated"
557         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
558         [[ -n $f4 ]] && error "2: 4th component instantiated"
559
560         # the first 3 components instantiated
561         $TRUNCATE $comp_file $((1024*1024*3))
562         $TRUNCATE $comp_file $((1024*1024*1+1))
563
564         f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
565         [[ -z $f2 ]] && error "3: 2nd component uninstantiated"
566         f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
567         [[ -z $f3 ]] && error "3: 3rd component uninstantiated"
568         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
569         [[ -n $f4 ]] && error "3: 4th component instantiated"
570
571         # all 4 components instantiated, using append write
572         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
573         ls -l $comp_file
574         rwv -f $comp_file -w -a -n 2 $((1024*1023)) 1
575         ls -l $comp_file
576
577         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
578         [[ -z $f4 ]] && error "4: 4th component uninstantiated"
579
580         return 0
581 }
582 run_test 11 "Verify component instantiation with write/truncate"
583
584 test_12() {
585         [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs"
586
587         local file=$DIR/$tdir/$tfile
588         test_mkdir $DIR/$tdir
589         rm -f $file
590
591         # specify ost list for component
592         $LFS setstripe -E 1M -S 1M -c 2 -o 0,1 -E 2M -c 2 -o 1,2 \
593                 -E 3M -c 2 -o 2,1 -E 4M -c 1 -i 2 -E -1 $file ||
594                 error "Create $file failed"
595
596         # clear lod component cache
597         stop $SINGLEMDS || error "stop MDS"
598         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
599         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "start MDS"
600
601         # instantiate all components
602         $TRUNCATE $file $((1024*1024*4+1))
603
604         #verify object alloc order
605         local o1=$($LFS getstripe -I1 $file |
606                         awk '/l_ost_idx:/ {printf("%d",$5)}')
607         [[ $o1 != "01" ]] && error "$o1 is not 01"
608
609         local o2=$($LFS getstripe -I2 $file |
610                         awk '/l_ost_idx:/ {printf("%d",$5)}')
611         [[ $o2 != "12" ]] && error "$o2 is not 12"
612
613         local o3=$($LFS getstripe -I3 $file |
614                         awk '/l_ost_idx:/ {printf("%d",$5)}')
615         [[ $o3 != "21" ]] && error "$o3 is not 21"
616
617         local o4=$($LFS getstripe -I4 $file |
618                         awk '/l_ost_idx:/ {printf("%d",$5)}')
619         [[ $o4 != "2" ]] && error "$o4 is not 2"
620
621         return 0
622 }
623 run_test 12 "Verify ost list specification"
624
625 test_13() { # LU-9311
626         [ $OSTCOUNT -lt 8 ] && skip "needs >= 8 OSTs"
627
628         local file=$DIR/$tfile
629         local dd_count=4
630         local dd_size=$(($dd_count * 1024 * 1024))
631         local real_size
632
633         rm -f $file
634         $LFS setstripe -E 1M -S 1M -c 1 -E 2M -c 2 -E -1 -c -1 -i 1 $file ||
635                 error "Create $file failed"
636         dd if=/dev/zero of=$file bs=1M count=$dd_count
637         real_size=$(stat -c %s $file)
638         [ $real_size -eq $dd_size ] ||
639                 error "dd actually wrote $real_size != $dd_size bytes"
640
641         rm -f $file
642 }
643 run_test 13 "shouldn't reprocess granted resent request"
644
645 test_14() {
646         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
647         local file=$DIR/$tdir/$tfile
648         test_mkdir -p $DIR/$tdir
649         rm -f $file
650
651         $LFS setstripe -E1m -c1 -S1m --pool="pool1" -E2m \
652                         -E4m -c2 -S2m --pool="pool2" -E-1 $file ||
653                 error "Create $file failed"
654
655         # check --pool inheritance
656         local pool
657         pool="$($LFS getstripe -I2 --pool $file)"
658         [ x"$pool" != "xpool1" ] && $LFS getstripe -I2 $file &&
659                 error "$file: component 2 doesn't have poolname pool1"
660         pool="$($LFS getstripe -I4 --pool $file)"
661         [ x"$pool" != "xpool2" ] && $LFS getstripe -I4 $file &&
662                 error "$file: component 4 doesn't have poolname pool2"
663
664         #check --stripe-count inheritance
665         local count
666         count="$($LFS getstripe -I2 -c $file)"
667         [ $count -ne 1 ] && $LFS getstripe -I2 $file &&
668                 error "$file: component 2 doesn't have 1 stripe_count"
669         count="$($LFS getstripe -I4 -c $file)"
670         [ $count -ne 2 ] && $LFS getstripe -I4 $file &&
671                 error "$file: component 4 doesn't have 2 stripe_count"
672
673         #check --stripe-size inheritance
674         local size
675         size="$($LFS getstripe -I2 -S $file)"
676         [ $size -ne $((1024*1024)) ] && $LFS getstripe -I2 $file &&
677                 error "$file: component 2 doesn't have 1M stripe_size"
678         size="$($LFS getstripe -I4 -S $file)"
679         [ $size -ne $((1024*1024*2)) ] && $LFS getstripe -I4 $file &&
680                 error "$file: component 4 doesn't have 2M stripe_size"
681
682         return 0
683 }
684 run_test 14 "Verify setstripe poolname/stripe_count/stripe_size inheritance"
685
686 test_15() {
687         local parent=$DIR/$tdir
688
689         rm -fr $parent
690         test_mkdir $parent
691
692         $LFS setstripe -d $parent || error "delete default layout"
693
694         $LFS setstripe -E 1M -S 1M -E 10M -E eof $parent/f1 || error "create f1"
695         $LFS setstripe -E 4M -E 20M -E eof $parent/f2 || error "create f2"
696         test_mkdir $parent/subdir
697         $LFS setstripe -E 6M -S 1M -E 30M -E eof $parent/subdir ||
698                 error "setstripe to subdir"
699         $LFS setstripe -E 8M -E eof $parent/subdir/f3 || error "create f3"
700         $LFS setstripe -c 1 $parent/subdir/f4 || error "create f4"
701
702         # none
703         local found=$($LFS find --component-start +2M -E -15M $parent | wc -l)
704         [ $found -eq 0 ] || error "start+2M, end-15M, $found != 0"
705
706         # f2, f3
707         found=$($LFS find --component-start +2M -E -35M $parent | wc -l)
708         [ $found -eq 2 ] || error "start+2M, end-35M, $found != 2"
709
710         # subdir
711         found=$($LFS find --component-start +4M -E -eof $parent | wc -l)
712         [ $found -eq 1 ] || error "start+4M, end-eof, $found != 1"
713
714         local flg_opts="--component-flags init"
715         # none
716         found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
717         [ $found -eq 0 ] ||
718                 error "before write: start=1M, end=10M, flag=init, $found != 0"
719
720         dd if=/dev/zero of=$parent/f1 bs=1M count=2 ||
721                 error "dd $parent/f1 failed"
722
723         # f1
724         found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
725         [ $found -eq 1 ] ||
726                 error "after write: start=1M, end=10M, flag=init, $found != 1"
727
728         local ext_opts="--component-start -1M -E +5M"
729         # parent, subdir, f3, f4
730         found=$($LFS find $ext_opts $parent | wc -l)
731         [ $found -eq 4 ] || error "start-1M, end+5M, $found != 4"
732
733         local cnt_opts="--component-count +2"
734         # subdir
735         found=$($LFS find $ext_opts $cnt_opts $parent | wc -l)
736         [ $found -eq 1 ] || error "start-1M, end+5M, count+2, $found != 1"
737
738         # none
739         found=$($LFS find $ext_opts $cnt_opts $flg_opts $parent | wc -l)
740         [ $found -eq 0 ] ||
741                 error "start-1M, end+5M, count+2, flag=init, $found != 0"
742
743         # f3, f4
744         found=$($LFS find $ext_opts ! $cnt_opts $flg_opts $parent | wc -l)
745         [ $found -eq 2 ] ||
746                 error "start-1M, end+5M, !count+2, flag=init, $found != 2"
747 }
748 run_test 15 "Verify component options for lfs find"
749
750 test_16a() {
751         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
752         large_xattr_enabled || skip_env "ea_inode feature disabled"
753
754         local file=$DIR/$tdir/$tfile
755         local dir=$DIR/$tdir/dir
756         local temp=$DIR/$tdir/template
757         rm -rf $DIR/$tdir
758         test_mkdir $DIR/$tdir
759
760         #####################################################################
761         #                           1. PFL file
762         # set stripe for source file
763         $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
764                 $file || error "Create $file failed"
765
766         echo "1. PFL file"
767         verify_yaml_layout $file $file.copy $temp "1. PFL file"
768
769         #####################################################################
770         #                           2. plain file
771         # set stripe for source file
772         rm -f $file
773         $LFS setstripe -c2 -o0,1 -i1 $file || error "Create $file failed"
774
775         rm -f $file.copy
776         echo "2. plain file"
777         verify_yaml_layout $file $file.copy $temp "2. plain file"
778
779         #####################################################################
780         #                           3. PFL dir
781         # set stripe for source dir
782         test_mkdir $dir
783         $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
784                 error "setstripe $dir failed"
785
786         test_mkdir $dir.copy
787         echo "3. PFL dir"
788         verify_yaml_layout $dir $dir.copy $temp.dir "3. PFL dir"
789
790         #####################################################################
791         #                           4. plain dir
792         # set stripe for source dir
793         $LFS setstripe -c2 -i-1 $dir || error "setstripe $dir failed"
794
795         echo "4. plain dir"
796         verify_yaml_layout $dir $dir.copy $temp.dir "4. plain dir"
797 }
798 run_test 16a "Verify setstripe/getstripe with YAML config file"
799
800 test_16b() {
801         [[ $($LCTL get_param mdc.*.import |
802                 grep "connect_flags:.*overstriping") ]] ||
803                 skip "server does not support overstriping"
804         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
805         [[ $OSTCOUNT -ge $(($LOV_MAX_STRIPE_COUNT / 2)) ]] &&
806                 skip_env "too many osts, skipping"
807         large_xattr_enabled || skip_env "ea_inode feature disabled"
808
809         local file=$DIR/$tdir/$tfile
810         local dir=$DIR/$tdir/dir
811         local temp=$DIR/$tdir/template
812         # We know OSTCOUNT < (LOV_MAX_STRIPE_COUNT / 2), so this is overstriping
813         local large_count=$((LOV_MAX_STRIPE_COUNT / 2 + 10))
814
815         rm -rf $DIR/$tdir
816         test_mkdir $DIR/$tdir
817
818         #####################################################################
819         #                           1. PFL file, overstriping in first comps
820         # set stripe for source file
821         $LFS setstripe -E1m -S 1M -o0,0 -E2m -o1,1 -E3m -C $large_count -E-1 \
822                 $file || error "Create $file failed"
823
824         echo "1. PFL file"
825         verify_yaml_layout $file $file.copy $temp "1. PFL file"
826
827         #####################################################################
828         #                           2. plain file + overstriping
829         # set stripe for source file
830         rm -f $file
831         $LFS setstripe -C $large_count -i1 $file || error "Create $file failed"
832
833         rm -f $file.copy
834         echo "2. plain file"
835         verify_yaml_layout $file $file.copy $temp "2. plain file"
836
837         #####################################################################
838         #                           3. PFL dir + overstriping
839         # set stripe for source dir
840         test_mkdir $dir
841         $LFS setstripe -E1m -S 1M -o 0,0 -E2m -C $large_count -E-1 $dir ||
842                 error "setstripe $dir failed"
843
844         test_mkdir $dir.copy
845         echo "3. PFL dir"
846         verify_yaml_layout $dir $dir.copy $temp.dir "3. PFL dir"
847
848         #####################################################################
849         #                           4. plain dir + overstriping
850         # set stripe for source dir
851         $LFS setstripe -C $large_count $dir || error "setstripe $dir failed"
852
853         echo "4. plain dir"
854         verify_yaml_layout $dir $dir.copy $temp.dir "4. plain dir"
855 }
856 run_test 16b "Verify setstripe/getstripe with YAML config file + overstriping"
857
858 test_17() {
859         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
860         local file=$DIR/$tdir/$tfile
861         test_mkdir -p $DIR/$tdir
862         rm -f $file
863
864         $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E -1 -c -1 $file ||
865                 error "Create $file failed"
866
867         local s1=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
868         local s2=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
869         local s3=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
870         echo "1st init: comp size 1:$s1 2:$s2 3:$s3"
871
872         # init 2nd component
873         $TRUNCATE $file $((1024*1024+1))
874         local s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
875         local s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
876         echo "2nd init: comp size 1:$s1n 2:$s2n 3:$s3"
877
878         [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
879         [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
880
881         # init 3rd component
882         $TRUNCATE $file $((1024*1024*2+1))
883         s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
884         s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
885         local s3n=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
886         echo "3rd init: comp size 1:$s1n 2:$s2n 3:$s3n"
887
888         [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
889         [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
890         [ $s3 -lt $s3n ] || error "3rd comp size $s3 should < $s3n"
891 }
892 run_test 17 "Verify LOVEA grows with more component inited"
893
894 check_distribution() {
895         local file=$1
896         local objs
897         local ave
898         local obj_min_one=$((OSTCOUNT - 1))
899
900         objs=$($LFS getstripe $file |
901                 awk '/l_ost_idx:/ { print $5 }' | wc -l)
902         let ave=$((objs / OSTCOUNT))
903
904         # collect objects per OST distribution
905         $LFS getstripe $file | awk '/l_ost_idx:/ { print $5 }' | tr -d "," |
906                 (inuse=( $(for i in $(seq 0 $obj_min_one); do echo 0; done) )
907                 while read O; do
908                         let inuse[$O]=$((1 + ${inuse[$O]}))
909                 done;
910
911                 # verify object distribution varies no more than +-1
912                 for idx in $(seq 0 $obj_min_one); do
913                         let dif=$((${inuse[$idx]} - ave))
914                         let dif=${dif#-}
915                         if [ "$dif" -gt 1 ]; then
916                                 echo "OST${idx}: ${inuse[$idx]} objects"
917                                 error "bad distribution on OST${idx}"
918                         fi
919                 done)
920 }
921
922 test_18() {
923         local file1=$DIR/${tfile}-1
924         local file2=$DIR/${tfile}-2
925         local file3=$DIR/${tfile}-3
926
927         rm -f $file1 $file2 $file3
928
929         $LFS setstripe -E 1m -S 1m $file1 ||
930                 error "Create $file1 failed"
931         $LFS setstripe -E 1m -S 1m $file2 ||
932                 error "Create $file2 failed"
933         $LFS setstripe -E 1m -S 1m $file3 ||
934                 error "Create $file3 failed"
935
936         local objs=$((OSTCOUNT+1))
937         for comp in $(seq 1 $OSTCOUNT); do
938                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file1 ||
939                         error "Add component to $file1 failed 2"
940                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file2 ||
941                         error "Add component to $file2 failed 2"
942                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file3 ||
943                         error "Add component to $file3 failed 2"
944         done
945
946         $LFS setstripe --component-add -E -1 -c -1 $file1 ||
947                 error "Add component to $file1 failed 3"
948         $LFS setstripe --component-add -E -1 -c -1 $file2 ||
949                 error "Add component to $file2 failed 3"
950         $LFS setstripe --component-add -E -1 -c -1 $file3 ||
951                 error "Add component to $file3 failed 3"
952
953         # Instantiate all components
954         dd if=/dev/urandom of=$file1 bs=1M count=$((objs+1)) ||
955                 error "dd failed for $file1"
956         dd if=/dev/urandom of=$file2 bs=1M count=$((objs+1)) ||
957                 error "dd failed for $file2"
958         dd if=/dev/urandom of=$file3 bs=1M count=$((objs+1)) ||
959                 error "dd failed for $file3"
960
961         check_distribution $file1
962         check_distribution $file2
963         check_distribution $file3
964
965 }
966 run_test 18 "check component distribution"
967
968 complete $SECONDS
969 check_and_cleanup_lustre
970 exit_status