Whamcloud - gitweb
LU-14119 lfsck: check linkea if it's newly added
[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_0() {
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 0 "Create full components file, no reused OSTs"
67
68 test_1() {
69         local comp_file=$DIR/$tdir/$tfile
70         local rw_len=$((3 * 1024 * 1024))       # 3M
71
72         test_mkdir $DIR/$tdir
73         rm -f $comp_file
74
75         $LFS setstripe -E 1m -S 1m -o 0 -E -1 -o 0 $comp_file ||
76                 error "Create $comp_file failed"
77
78         #instantiate all components, so that objs are allocted
79         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
80
81         local ost_idx1=$($LFS getstripe -I1 -i $comp_file)
82         local ost_idx2=$($LFS getstripe -I2 -i $comp_file)
83
84         [ $ost_idx1 -ne $ost_idx2 ] && error "$ost_idx1 != $ost_idx2"
85
86         small_write $comp_file $rw_len || error "Verify RW failed"
87
88         rm -f $comp_file || error "Delete $comp_file failed"
89 }
90 run_test 1 "Create full components file, reused OSTs"
91
92 test_2() {
93         local comp_file=$DIR/$tdir/$tfile
94         local rw_len=$((5 * 1024 * 1024))       # 5M
95
96         test_mkdir $DIR/$tdir
97         rm -f $comp_file
98
99         $LFS setstripe -E 1m -S 1m $comp_file ||
100                 error "Create $comp_file failed"
101
102         local comp_cnt=$($LFS getstripe --component-count $comp_file)
103         [ $comp_cnt -ne 1 ] && error "component count $comp_cnt != 1"
104
105         dd if=/dev/zero of=$comp_file bs=1M count=1 > /dev/null 2>&1 ||
106                 error "Write first component failed"
107         dd if=$comp_file of=/dev/null bs=1M count=1 > /dev/null 2>&1 ||
108                 error "Read first component failed"
109
110         dd if=/dev/zero of=$comp_file bs=1M count=2 > /dev/null 2>&1 &&
111                 error "Write beyond component should fail"
112         dd if=$comp_file of=/dev/null bs=1M count=2 > /dev/null 2>&1 ||
113                 error "Read beyond component should short read, not fail"
114
115         $LFS setstripe --component-add -E 2M -S 1M -c 1 $comp_file ||
116                 error "Add component to $comp_file failed"
117
118         comp_cnt=$($LFS getstripe --component-count $comp_file)
119         [ $comp_cnt -ne 2 ] && error "component count $comp_cnt != 2"
120
121         $LFS setstripe --component-add -E -1 -c 3 $comp_file ||
122                 error "Add last component to $comp_file failed"
123
124         comp_cnt=$($LFS getstripe --component-count $comp_file)
125         [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
126
127         small_write $comp_file $rw_len || error "Verify RW failed"
128
129         rm -f $comp_file || error "Delete $comp_file failed"
130 }
131 run_test 2 "Add component to existing file"
132
133 del_comp_and_verify() {
134         local comp_file=$1
135         local id=$2
136         local left=$3
137         local size=$4
138
139         local opt="-I "
140         if [ $id == "init" -o $id == "^init" ]; then
141                 opt="--component-flags="
142         fi
143
144         $LFS setstripe --component-del $opt$id $comp_file ||
145                 error "Delete component $id from $comp_file failed"
146
147         local comp_cnt=$($LFS getstripe --component-count $comp_file)
148         if grep -q "has no stripe info" <<< "$comp_cnt" ; then
149                 comp_cnt=0
150         fi
151         [ $comp_cnt -ne $left ] && error "$comp_cnt != $left"
152
153         $CHECKSTAT -s $size $comp_file || error "size != $size"
154 }
155
156 test_3() {
157         local comp_file=$DIR/$tdir/$tfile
158
159         test_mkdir $DIR/$tdir
160         rm -f $comp_file
161
162         $LFS setstripe -E 1M -S 1M -E 64M -c 2 -E -1 -c 3 $comp_file ||
163                 error "Create $comp_file failed"
164
165         local comp_cnt=$($LFS getstripe --component-count $comp_file)
166         [ $comp_cnt -ne 3 ] && error "component count $comp_cnt != 3"
167
168         dd if=/dev/zero of=$comp_file bs=1M count=2
169
170         $LFS setstripe --component-del -I 2 $comp_file &&
171                 error "Component deletion makes hole"
172
173         del_comp_and_verify $comp_file 3 2 $((2 * 1024 * 1024))
174         del_comp_and_verify $comp_file 2 1 $((1 * 1024 * 1024))
175         del_comp_and_verify $comp_file 1 0 0
176
177         rm -f $comp_file || error "Delete $comp_file failed"
178
179         $LFS setstripe -E 1M -S 1M -E 16M -E -1 $comp_file ||
180                 error "Create second $comp_file failed"
181
182         del_comp_and_verify $comp_file "^init" 1 0
183         del_comp_and_verify $comp_file "init" 0 0
184         rm -f $comp_file || error "Delete second $comp_file failed"
185
186 }
187 run_test 3 "Delete component from existing file"
188
189 test_4() {
190         skip "Not supported in PFL"
191         # In PFL project, only LCME_FL_INIT is supported, and it can't
192         # be altered by application.
193 }
194 run_test 4 "Modify component flags in existing file"
195
196 test_5() {
197         local parent=$DIR/$tdir
198         local comp_file=$DIR/$tdir/$tfile
199         local subdir=$parent/subdir
200
201         rm -fr $parent
202         test_mkdir $parent
203
204         # set default layout to parent directory
205         $LFS setstripe -E 64M -c 2 -i 0 -E -1 -c 4 -i 0 $parent ||
206                 error "Set default layout to $parent failed"
207
208         # create file under parent
209         touch $comp_file || error "Create $comp_file failed"
210         local comp_cnt=$($LFS getstripe --component-count $comp_file)
211         [ $comp_cnt -ne 2 ] && error "file $comp_cnt != 2"
212
213         #instantiate all components, so that objs are allocted
214         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=65k
215
216         local ost_idx=$($LFS getstripe -I1 -i $comp_file)
217         [ $ost_idx -ne 0 ] &&
218                 error "component 1 ost_idx $ost_idx != 0"
219
220         ost_idx=$($LFS getstripe -I2 -i $comp_file)
221         [ $ost_idx -ne 0 ] &&
222                 error "component 2 ost_idx $ost_idx != 0"
223
224         # create subdir under parent
225         mkdir -p $subdir || error "Create subdir $subdir failed"
226
227         comp_cnt=$($LFS getstripe -d --component-count $subdir)
228         [ $comp_cnt -ne 2 ] && error "subdir $comp_cnt != 2"
229
230         # create file under subdir
231         touch $subdir/$tfile || error "Create $subdir/$tfile failed"
232
233         comp_cnt=$($LFS getstripe --component-count $subdir/$tfile)
234         [ $comp_cnt -ne 2 ] && error "$subdir/$tfile $comp_cnt != 2"
235
236         # delete default layout setting from parent
237         $LFS setstripe -d $parent ||
238                 error "Delete default layout from $parent failed"
239
240         comp_cnt=$($LFS getstripe -d --component-count $parent)
241         [ $comp_cnt -ne 0 ] && error "$comp_cnt isn't 0"
242
243         rm -f $comp_file || error "Delete $comp_file failed"
244         rm -f $subdir/$tfile || error "Delete $subdir/$tfile failed"
245         rm -r $subdir || error "Delete subdir $subdir failed"
246         rmdir $parent || error "Delete dir $parent failed"
247 }
248 run_test 5 "Inherit composite layout from parent directory"
249
250 test_6() {
251         local comp_file=$DIR/$tdir/$tfile
252
253         test_mkdir $DIR/$tdir
254         rm -f $DIR/$tfile
255
256         $LFS setstripe -c 1 -S 128K $comp_file ||
257                 error "Create v1 $comp_file failed"
258
259         local comp_cnt=$($LFS getstripe --component-count $comp_file)
260         [ $comp_cnt -ne 0 ] && error "Wrong component count $comp_cnt"
261
262         dd if=/dev/urandom of=$comp_file bs=1M count=5 oflag=sync ||
263                 error "Write to v1 $comp_file failed"
264
265         local old_chksum=$(md5sum $comp_file)
266
267         # Migrate v1 to composite
268         $LFS migrate -E 1M -S 512K -c 1 -E -1 -S 1M -c 2 $comp_file ||
269                 error "Migrate(v1 -> composite) $comp_file failed"
270
271         comp_cnt=$($LFS getstripe --component-count $comp_file)
272         [ "$comp_cnt" -ne 2 ] && error "$comp_cnt != 2"
273
274         local chksum=$(md5sum $comp_file)
275         [ "$old_chksum" != "$chksum" ] &&
276                 error "(v1 -> compsoite) $old_chksum != $chksum"
277
278         # Migrate composite to composite
279         $LFS migrate -E 1M -S 1M -c 2 -E 4M -S 1M -c 2 \
280                 -E -1 -S 3M -c 3 $comp_file ||
281                 error "Migrate(compsoite -> composite) $comp_file failed"
282
283         comp_cnt=$($LFS getstripe --component-count $comp_file)
284         [ "$comp_cnt" -ne 3 ] && error "$comp_cnt != 3"
285
286         chksum=$(md5sum $comp_file)
287         [ "$old_chksum" != "$chksum" ] &&
288                 error "(composite -> compsoite) $old_chksum != $chksum"
289
290         # Migrate composite to v1
291         $LFS migrate -c 2 -S 2M $comp_file ||
292                 error "Migrate(composite -> v1) $comp_file failed"
293
294         comp_cnt=$($LFS getstripe --component-count $comp_file)
295         [ $comp_cnt -ne 0 ] && error "$comp_cnt isn't 0"
296
297         chksum=$(md5sum $comp_file)
298         [ "$old_chksum" != "$chksum" ] &&
299                 error "(composite -> v1) $old_chksum != $chksum"
300
301         rm -f $comp_file || "Delete $comp_file failed"
302 }
303 run_test 6 "Migrate composite file"
304
305 test_7() {
306         test_mkdir $DIR/$tdir
307         chmod 0777 $DIR/$tdir || error "chmod $tdir failed"
308
309         local comp_file=$DIR/$tdir/$tfile
310         $RUNAS $LFS setstripe -E 1M -S 1M -c 1 $comp_file ||
311                 error "Create composite file $comp_file failed"
312
313         $RUNAS $LFS setstripe --component-add -E 64M -c 4 $comp_file ||
314                 error "Add component to $comp_file failed"
315
316         $RUNAS $LFS setstripe --component-del -I 2 $comp_file ||
317                 error "Delete component from $comp_file failed"
318
319         $RUNAS $LFS setstripe --component-add -E -1 -c 5 $comp_file ||
320                 error "Add last component to $comp_file failed"
321
322         rm $comp_file || "Delete composite failed"
323 }
324 run_test 7 "Add/Delete/Create composite file by non-privileged user"
325
326 test_8() {
327         local parent=$DIR/$tdir
328
329         rm -fr $parent
330         test_mkdir $parent
331
332         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c 2 -S 2M \
333                 -E -1 -c 4 -S 4M $parent ||
334                 error "Set default layout to $parent failed"
335
336         sh rundbench -C -D $parent 2 || error "dbench failed"
337
338         rm -fr $parent || error "Delete dir $parent failed"
339 }
340 run_test 8 "Run dbench over composite files"
341
342 test_9() {
343         local comp_file=$DIR/$tdir/$tfile
344
345         test_mkdir $DIR/$tdir
346         rm -f $comp_file
347
348         $LFS setstripe -E 1M -S 1M -E -1 -c 1 $comp_file ||
349                 error "Create $comp_file failed"
350
351         local comp_cnt=$($LFS getstripe --component-count $comp_file)
352         [ $comp_cnt -ne 2 ] && error "component count $comp_cnt != 2"
353
354         replay_barrier $SINGLEMDS
355
356         # instantiate the 2nd component
357         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
358
359         local f1=$($LFS getstripe -I2 $comp_file |
360                         awk '/l_fid:/ {print $7}')
361         echo "before MDS recovery, the ost fid of 2nd component is $f1"
362         fail $SINGLEMDS
363
364         local f2=$($LFS getstripe -I2 $comp_file |
365                         awk '/l_fid:/ {print $7}')
366         echo "after MDS recovery, the ost fid of 2nd component is $f2"
367         [ "x$f1" == "x$f2" ] || error "$f1 != $f2"
368 }
369 run_test 9 "Replay layout extend object instantiation"
370
371 component_dump() {
372         echo $($LFS getstripe $1 |
373                 awk '$1 == "lcm_entry_count:" { printf("%d", $2) }
374                      $1 == "lcme_extent.e_start:" { printf("[%#lx", $2) }
375                      $1 == "lcme_extent.e_end:" { printf(",%s]", $2) }')
376 }
377
378 test_10() {
379         local parent=$DIR/$tdir
380
381         save_layout_restore_at_exit $MOUNT
382
383         rm -rf $parent
384         $LFS setstripe -d $MOUNT || error "clear root layout"
385
386         # set root composite layout
387         $LFS setstripe -E 2M -c 1 -S 1M -E 16M -c2 -S 2M \
388                 -E -1 -c 4 -S 4M $MOUNT ||
389                 error "Set root layout failed"
390
391         test_mkdir $parent
392         # set a different layout for parent
393         $LFS setstripe -E -1 -c 1 -S 1M $parent ||
394                 error "set $parent layout failed"
395         touch $parent/file1
396
397         local f1_entry=$(component_dump $parent/file1)
398
399         # delete parent's layout
400         $LFS setstripe -d $parent || error "Clear $parent layout failed"
401         touch $parent/file2
402
403         local f2_entry=$(component_dump $parent/file2)
404
405         # verify layout inheritance
406         local eof="EOF"
407         local f1_expect="1[0,EOF]"
408         local f2_expect="3[0,2097152][0x200000,16777216][0x1000000,EOF]"
409
410         echo "f1 expect=$f1_expect"
411         echo "f1 get   =$f1_entry"
412         echo "f2 expect=$f2_expect"
413         echo "f2 get   =$f2_entry"
414
415         [  x$f1_expect != x$f1_entry ] &&
416                 error "$parent/file1 does not inherite parent layout"
417         [  x$f2_expect != x$f2_entry ] &&
418                 error "$parent/file2 does not inherite root layout"
419
420         return 0
421 }
422 run_test 10 "Inherit composite template from root"
423
424 test_11() {
425         local comp_file=$DIR/$tdir/$tfile
426         test_mkdir $DIR/$tdir
427         rm -f $comp_file
428
429         # only 1st component instantiated
430         $LFS setstripe -E 1M -S 1M -E 2M -E 3M -E -1 $comp_file ||
431                 error "Create $comp_file failed"
432
433         local f1=$($LFS getstripe -I1 $comp_file | grep "l_fid")
434         [[ -z $f1 ]] && error "1: 1st component uninstantiated"
435         local f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
436         [[ -n $f2 ]] && error "1: 2nd component instantiated"
437         local f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
438         [[ -n $f3 ]] && error "1: 3rd component instantiated"
439         local f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
440         [[ -n $f4 ]] && error "1: 4th component instantiated"
441
442         # the first 2 components instantiated
443         # Truncate to exact start of new component - LU-12586
444         $TRUNCATE $comp_file $((1024*1024*1))
445
446         f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
447         [[ -z $f2 ]] && error "2: 2nd component uninstantiated"
448         f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
449         [[ -n $f3 ]] && error "2: 3rd component instantiated"
450         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
451         [[ -n $f4 ]] && error "2: 4th component instantiated"
452
453         # the first 3 components instantiated
454         $TRUNCATE $comp_file $((1024*1024*3 - 1))
455         $TRUNCATE $comp_file $((1024*1024*1+1))
456
457         f2=$($LFS getstripe -I2 $comp_file | grep "l_fid")
458         [[ -z $f2 ]] && error "3: 2nd component uninstantiated"
459         f3=$($LFS getstripe -I3 $comp_file | grep "l_fid")
460         [[ -z $f3 ]] && error "3: 3rd component uninstantiated"
461         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
462         [[ -n $f4 ]] && error "3: 4th component instantiated"
463
464         # all 4 components instantiated, using append write
465         dd if=/dev/zero of=$comp_file bs=1k count=1 seek=2k
466         ls -l $comp_file
467         rwv -f $comp_file -w -a -n 2 $((1024*1023)) 1
468         ls -l $comp_file
469
470         f4=$($LFS getstripe -I4 $comp_file | grep "l_fid")
471         [[ -z $f4 ]] && error "4: 4th component uninstantiated"
472
473         return 0
474 }
475 run_test 11 "Verify component instantiation with write/truncate"
476
477 test_12() {
478         [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs"
479
480         local file=$DIR/$tdir/$tfile
481         test_mkdir $DIR/$tdir
482         rm -f $file
483
484         # specify ost list for component
485         $LFS setstripe -E 1M -S 1M -c 2 -o 0,1 -E 2M -c 2 -o 1,2 \
486                 -E 3M -c 2 -o 2,1 -E 4M -c 1 -i 2 -E -1 $file ||
487                 error "Create $file failed"
488
489         # clear lod component cache
490         stop $SINGLEMDS || error "stop MDS"
491         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
492         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "start MDS"
493
494         # instantiate all components
495         $TRUNCATE $file $((1024*1024*4+1))
496
497         #verify object alloc order
498         local o1=$($LFS getstripe -I1 $file |
499                         awk '/l_ost_idx:/ {printf("%d",$5)}')
500         [[ $o1 != "01" ]] && error "$o1 is not 01"
501
502         local o2=$($LFS getstripe -I2 $file |
503                         awk '/l_ost_idx:/ {printf("%d",$5)}')
504         [[ $o2 != "12" ]] && error "$o2 is not 12"
505
506         local o3=$($LFS getstripe -I3 $file |
507                         awk '/l_ost_idx:/ {printf("%d",$5)}')
508         [[ $o3 != "21" ]] && error "$o3 is not 21"
509
510         local o4=$($LFS getstripe -I4 $file |
511                         awk '/l_ost_idx:/ {printf("%d",$5)}')
512         [[ $o4 != "2" ]] && error "$o4 is not 2"
513
514         return 0
515 }
516 run_test 12 "Verify ost list specification"
517
518 test_13() { # LU-9311
519         [ $OSTCOUNT -lt 8 ] && skip "needs >= 8 OSTs"
520
521         local file=$DIR/$tfile
522         local dd_count=4
523         local dd_size=$(($dd_count * 1024 * 1024))
524         local real_size
525
526         rm -f $file
527         $LFS setstripe -E 1M -S 1M -c 1 -E 2M -c 2 -E -1 -c -1 -i 1 $file ||
528                 error "Create $file failed"
529         dd if=/dev/zero of=$file bs=1M count=$dd_count
530         real_size=$(stat -c %s $file)
531         [ $real_size -eq $dd_size ] ||
532                 error "dd actually wrote $real_size != $dd_size bytes"
533
534         rm -f $file
535 }
536 run_test 13 "shouldn't reprocess granted resent request"
537
538 test_14() {
539         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
540         local file=$DIR/$tdir/$tfile
541         test_mkdir -p $DIR/$tdir
542         rm -f $file
543
544         $LFS setstripe -E1m -c1 -S1m --pool="pool1" -E2m \
545                         -E4m -c2 -S2m --pool="pool2" -E-1 $file ||
546                 error "Create $file failed"
547
548         # check --pool inheritance
549         local pool
550         pool="$($LFS getstripe -I2 --pool $file)"
551         [ x"$pool" != "xpool1" ] && $LFS getstripe -I2 $file &&
552                 error "$file: component 2 doesn't have poolname pool1"
553         pool="$($LFS getstripe -I4 --pool $file)"
554         [ x"$pool" != "xpool2" ] && $LFS getstripe -I4 $file &&
555                 error "$file: component 4 doesn't have poolname pool2"
556
557         #check --stripe-count inheritance
558         local count
559         count="$($LFS getstripe -I2 -c $file)"
560         [ $count -ne 1 ] && $LFS getstripe -I2 $file &&
561                 error "$file: component 2 doesn't have 1 stripe_count"
562         count="$($LFS getstripe -I4 -c $file)"
563         [ $count -ne 2 ] && $LFS getstripe -I4 $file &&
564                 error "$file: component 4 doesn't have 2 stripe_count"
565
566         #check --stripe-size inheritance
567         local size
568         size="$($LFS getstripe -I2 -S $file)"
569         [ $size -ne $((1024*1024)) ] && $LFS getstripe -I2 $file &&
570                 error "$file: component 2 doesn't have 1M stripe_size"
571         size="$($LFS getstripe -I4 -S $file)"
572         [ $size -ne $((1024*1024*2)) ] && $LFS getstripe -I4 $file &&
573                 error "$file: component 4 doesn't have 2M stripe_size"
574
575         return 0
576 }
577 run_test 14 "Verify setstripe poolname/stripe_count/stripe_size inheritance"
578
579 test_15() {
580         local parent=$DIR/$tdir
581
582         rm -fr $parent
583         test_mkdir $parent
584
585         $LFS setstripe -d $parent || error "delete default layout"
586
587         $LFS setstripe -E 1M -S 1M -E 10M -E eof $parent/f1 || error "create f1"
588         $LFS setstripe -E 4M -E 20M -E eof $parent/f2 || error "create f2"
589         test_mkdir $parent/subdir
590         $LFS setstripe -E 6M -S 1M -c1 -E 30M -c4 -E eof -c -1 $parent/subdir ||
591                 error "setstripe to subdir"
592         $LFS setstripe -E 8M -E eof $parent/subdir/f3 || error "create f3"
593         $LFS setstripe -c 1 $parent/subdir/f4 || error "create f4"
594
595         # none
596         local found=$($LFS find --component-start +2M -E -15M $parent | wc -l)
597         [ $found -eq 0 ] || error "start+2M, end-15M, $found != 0"
598
599         # f2, f3
600         found=$($LFS find --component-start +2M -E -35M $parent | wc -l)
601         [ $found -eq 2 ] || error "start+2M, end-35M, $found != 2"
602
603         # subdir
604         found=$($LFS find --component-start +4M -E -eof $parent | wc -l)
605         [ $found -eq 1 ] || error "start+4M, end-eof, $found != 1"
606
607         local flg_opts="--component-flags init"
608         # none
609         found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
610         [ $found -eq 0 ] ||
611                 error "before write: start=1M, end=10M, flag=init, $found != 0"
612
613         dd if=/dev/zero of=$parent/f1 bs=1M count=2 ||
614                 error "dd $parent/f1 failed"
615
616         # f1
617         found=$($LFS find --component-start 1M -E 10M $flg_opts $parent | wc -l)
618         [ $found -eq 1 ] ||
619                 error "after write: start=1M, end=10M, flag=init, $found != 1"
620
621         local ext_opts="--component-start -1M -E +5M"
622         # parent, subdir, f3, f4
623         found=$($LFS find $ext_opts $parent | wc -l)
624         [ $found -eq 4 ] || error "start-1M, end+5M, $found != 4"
625
626         local cnt_opts="--component-count +2"
627         # subdir
628         found=$($LFS find $ext_opts $cnt_opts $parent | wc -l)
629         [ $found -eq 1 ] || error "start-1M, end+5M, count+2, $found != 1"
630
631         # none
632         found=$($LFS find $ext_opts $cnt_opts $flg_opts $parent | wc -l)
633         [ $found -eq 0 ] ||
634                 error "start-1M, end+5M, count+2, flag=init, $found != 0"
635
636         # f3, f4
637         found=$($LFS find $ext_opts ! $cnt_opts $flg_opts $parent | wc -l)
638         [ $found -eq 2 ] ||
639                 error "start-1M, end+5M, !count+2, flag=init, $found != 2"
640
641         # check last component stripe count
642         if [ $OSTCOUNT -gt 1 ]; then
643                 touch $parent/subdir/f5
644                 $TRUNCATE $parent/subdir/f5 $((32*1024*1024))
645                 found=$($LFS find $parent/subdir -c $OSTCOUNT)
646                 [[ "$found" == "$parent/subdir/f5" ]] ||
647                         error "got '$found' with stripe_count=$OSTCOUNT, not f5"
648         fi
649 }
650 run_test 15 "Verify component options for lfs find"
651
652 test_16() {
653         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
654
655         local file=$DIR/$tdir/$tfile
656         local dir=$DIR/$tdir/dir
657         local temp=$DIR/$tdir/template
658         rm -rf $DIR/$tdir
659         test_mkdir $DIR/$tdir
660
661         #####################################################################
662         #                           1. PFL file
663         # set stripe for source file
664         $LFS setstripe -E1m -S 1M -c2 -o0,1 -E2m -c2 -E3m -o1,0 -E4m -c1 -E-1 \
665                 $file || error "Create $file failed"
666
667         echo "1. PFL file"
668         verify_yaml_layout $file $file.copy $temp "1. PFL file"
669
670         #####################################################################
671         #                           2. plain file
672         # set stripe for source file
673         rm -f $file
674         $LFS setstripe -c2 -o0,1 -i1 $file || error "Create $file failed"
675
676         rm -f $file.copy
677         echo "2. plain file"
678         verify_yaml_layout $file $file.copy $temp "2. plain file"
679
680         #####################################################################
681         #                           3. PFL dir
682         # set stripe for source dir
683         test_mkdir $dir
684         $LFS setstripe -E1m -S 1M -c2 -E2m -c1 -E-1 $dir ||
685                 error "setstripe $dir failed"
686
687         test_mkdir $dir.copy
688         echo "3. PFL dir"
689         verify_yaml_layout $dir $dir.copy $temp.dir "3. PFL dir"
690
691         #####################################################################
692         #                           4. plain dir
693         # set stripe for source dir
694         $LFS setstripe -c2 -i-1 $dir || error "setstripe $dir failed"
695
696         echo "4. plain dir"
697         verify_yaml_layout $dir $dir.copy $temp.dir "4. plain dir"
698 }
699 run_test 16 "Verify setstripe/getstripe with YAML config file"
700
701 test_17() {
702         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs"
703         local file=$DIR/$tdir/$tfile
704         test_mkdir -p $DIR/$tdir
705         rm -f $file
706
707         $LFS setstripe -E 1M -S 1M -E 2M -c 2 -E -1 -c -1 $file ||
708                 error "Create $file failed"
709
710         local s1=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
711         local s2=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
712         local s3=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
713         echo "1st init: comp size 1:$s1 2:$s2 3:$s3"
714
715         # init 2nd component
716         $TRUNCATE $file $((1024*1024+1))
717         local s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
718         local s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
719         echo "2nd init: comp size 1:$s1n 2:$s2n 3:$s3"
720
721         [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
722         [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
723
724         # init 3rd component
725         $TRUNCATE $file $((1024*1024*2+1))
726         s1n=$($LFS getstripe -I1 -v $file | awk '/lcme_size:/{print $2}')
727         s2n=$($LFS getstripe -I2 -v $file | awk '/lcme_size:/{print $2}')
728         local s3n=$($LFS getstripe -I3 -v $file | awk '/lcme_size:/{print $2}')
729         echo "3rd init: comp size 1:$s1n 2:$s2n 3:$s3n"
730
731         [ $s1 -eq $s1n ] || error "1st comp size $s1 should == $s1n"
732         [ $s2 -lt $s2n ] || error "2nd comp size $s2 should < $s2n"
733         [ $s3 -lt $s3n ] || error "3rd comp size $s3 should < $s3n"
734 }
735 run_test 17 "Verify LOVEA grows with more component inited"
736
737 check_distribution() {
738         local file=$1
739         local objs
740         local ave
741         local obj_min_one=$((OSTCOUNT - 1))
742
743         objs=$($LFS getstripe $file |
744                 awk '/l_ost_idx:/ { print $5 }' | wc -l)
745         let ave=$((objs / OSTCOUNT))
746
747         # collect objects per OST distribution
748         $LFS getstripe $file | awk '/l_ost_idx:/ { print $5 }' | tr -d "," |
749                 (inuse=( $(for i in $(seq 0 $obj_min_one); do echo 0; done) )
750                 while read O; do
751                         let inuse[$O]=$((1 + ${inuse[$O]}))
752                 done;
753
754                 # verify object distribution varies no more than +-1
755                 for idx in $(seq 0 $obj_min_one); do
756                         let dif=$((${inuse[$idx]} - ave))
757                         let dif=${dif#-}
758                         if [ "$dif" -gt 1 ]; then
759                                 echo "OST${idx}: ${inuse[$idx]} objects"
760                                 error "bad distribution on OST${idx}"
761                         fi
762                 done)
763 }
764
765 test_18() {
766         local file1=$DIR/${tfile}-1
767         local file2=$DIR/${tfile}-2
768         local file3=$DIR/${tfile}-3
769
770         rm -f $file1 $file2 $file3
771
772         $LFS setstripe -E 1m -S 1m $file1 ||
773                 error "Create $file1 failed"
774         $LFS setstripe -E 1m -S 1m $file2 ||
775                 error "Create $file2 failed"
776         $LFS setstripe -E 1m -S 1m $file3 ||
777                 error "Create $file3 failed"
778
779         local objs=$((OSTCOUNT+1))
780         for comp in $(seq 1 $OSTCOUNT); do
781                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file1 ||
782                         error "Add component to $file1 failed 2"
783                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file2 ||
784                         error "Add component to $file2 failed 2"
785                 $LFS setstripe --component-add -E $((comp+1))M -c 1 $file3 ||
786                         error "Add component to $file3 failed 2"
787         done
788
789         $LFS setstripe --component-add -E -1 -c -1 $file1 ||
790                 error "Add component to $file1 failed 3"
791         $LFS setstripe --component-add -E -1 -c -1 $file2 ||
792                 error "Add component to $file2 failed 3"
793         $LFS setstripe --component-add -E -1 -c -1 $file3 ||
794                 error "Add component to $file3 failed 3"
795
796         # Instantiate all components
797         dd if=/dev/urandom of=$file1 bs=1M count=$((objs+1)) ||
798                 error "dd failed for $file1"
799         dd if=/dev/urandom of=$file2 bs=1M count=$((objs+1)) ||
800                 error "dd failed for $file2"
801         dd if=/dev/urandom of=$file3 bs=1M count=$((objs+1)) ||
802                 error "dd failed for $file3"
803
804         check_distribution $file1
805         check_distribution $file2
806         check_distribution $file3
807
808 }
809 run_test 18 "check component distribution"
810
811 complete $SECONDS
812 check_and_cleanup_lustre
813 exit_status