Whamcloud - gitweb
LU-797 tests: fix ost-pools test timeout issues on b1_8
[fs/lustre-release.git] / lustre / tests / ost-pools.sh
1 #!/bin/bash
2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:autoindent:shiftwidth=4:tabstop=4:
4 #
5 # Run select tests by setting ONLY, or as arguments to the script.
6 # Skip specific tests by setting EXCEPT.
7 #
8 # Run test by setting NOSETUP=true when ltest has setup env for us
9
10 SRCDIR=$(dirname $0)
11 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
12
13 ONLY=${ONLY:-"$*"}
14 ALWAYS_EXCEPT="$OST_POOLS_EXCEPT"
15 # bug number for skipped test: -
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17
18 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
19     echo "Skipping tests: $(echo $ALWAYS_EXCEPT $EXCEPT)"
20
21 TMP=${TMP:-/tmp}
22 ORIG_PWD=${PWD}
23
24 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
25 . $LUSTRE/tests/test-framework.sh
26 init_test_env $@
27 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
28 init_logging
29
30 check_and_setup_lustre
31
32 [ "$SLOW" = "no" ] && EXCEPT_SLOW="23b"
33
34 DIR=${DIR:-$MOUNT}
35 assert_DIR
36
37 build_test_filter
38
39 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
40 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
41
42 SINGLEMDS=mds
43
44 MAXFREE=${MAXFREE:-$((2000000 * OSTCOUNT))}
45
46 # OST pools tests
47 POOL=testpool
48 POOL2=${POOL2:-${POOL}2}
49 POOL3=${POOL3:-${POOL}3}
50 NON_EXISTANT_POOL=nonexistantpool
51 NON_EXISTANT_FS=nonexistantfs
52 INVALID_POOL=some_invalid_pool_name
53 TGT_COUNT=$OSTCOUNT
54 TGT_FIRST=$(printf %04x 0)
55 TGT_MAX=$(printf %04x $((TGT_COUNT-1)))
56 TGT_STEP=1
57 TGT_LIST=$(seq 0x$TGT_FIRST $TGT_STEP 0x$TGT_MAX)
58 TGT_LIST2=$(seq 0x$TGT_FIRST 2 0x$TGT_MAX)
59
60 TGT_ALL="$FSNAME-OST[$TGT_FIRST-$TGT_MAX/1]"
61 TGT_HALF="$FSNAME-OST[$TGT_FIRST-$TGT_MAX/2]"
62
63 TGT_UUID=$(for i in $TGT_LIST; do printf "$FSNAME-OST%04x_UUID " $i; done)
64 TGT_UUID2=$(for i in $TGT_LIST2; do printf "$FSNAME-OST%04x_UUID " $i; done)
65
66 create_dir() {
67     local dir=$1
68     local pool=$2
69     local count=${3:-"-1"}
70     local idx=$4
71
72     mkdir -p $dir
73     if [[ -n $4 ]]; then
74         $SETSTRIPE -c $count -p $pool $dir -o $idx
75     else
76         $SETSTRIPE -c $count -p $pool $dir
77     fi
78     [[ $? -eq 0 ]] ||
79         error "$SETSTRIPE -p $pool $dir failed."
80 }
81
82 create_file() {
83     local file=$1
84     local pool=$2
85     local count=${3:-"-1"}
86     local index=${4:-"-1"}
87     rm -f $file
88     $SETSTRIPE -o $index -c $count -p $pool $file
89     [[ $? -eq 0 ]] ||
90         error "$SETSTRIPE -p $pool $file failed."
91 }
92
93 osts_in_pool() {
94     local pool=$1
95     local res
96     for i in $(do_facet $SINGLEMDS lctl pool_list $FSNAME.$pool |
97                grep -v "^Pool:" | sed -e 's/_UUID$//;s/^.*-OST//'); do
98         res="$res $(printf "%d" 0x$i)"
99     done
100     echo $res
101 }
102
103 check_dir_in_pool() {
104     local dir=$1
105     local pool=$2
106     local res=$($GETSTRIPE $dir | grep "^stripe_count:" |
107                 cut -d ':' -f 5 | tr -d "[:blank:]")
108     if [[ "$res" != "$pool" ]]; then
109         error found $res instead of $pool
110         return 1
111     fi
112
113     return 0
114 }
115
116 check_file_in_pool() {
117     local osts=$(osts_in_pool $2)
118     check_file_in_osts $1 "$osts" $3
119 }
120
121 check_file_in_osts() {
122     local file=$1
123     local pool_list=${2:-$TGT_LIST}
124     local count=$3
125     local res=$($GETSTRIPE $file | grep 0x | cut -f2)
126     local i
127     for i in $res; do
128         found=$(echo :$pool_list: | tr " " ":" | grep :$i:)
129         if [[ "$found" == "" ]]; then
130             echo "pool list: $pool_list"
131             echo "striping: $res"
132             $GETSTRIPE $file
133             error "$file not allocated from OSTs $pool_list."
134             return 1
135         fi
136     done
137
138     local ost_count=$($GETSTRIPE $file | grep 0x | wc -l)
139     [[ -n "$count" ]] && [[ $ost_count -ne $count ]] &&
140         { error "Stripe count $count expected; got $ost_count" && return 1;}
141
142     return 0
143 }
144
145 file_pool() {
146     $GETSTRIPE -v $1 | grep "^lmm_pool:" | tr -d "[:blank:]" | cut -f 2 -d ':'
147 }
148
149 check_file_not_in_pool() {
150     local file=$1
151     local pool=$2
152     local res=$(file_pool $file)
153
154     if [[ "$res" == "$pool" ]]; then
155         error "File $file is in pool: $res"
156         return 1
157     else
158         return 0
159     fi
160 }
161
162 check_dir_not_in_pool() {
163     local dir=$1
164     local pool=$2
165     local res=$($GETSTRIPE -v $dir | grep "^stripe_count" | head -1 |
166                 cut -f 8 -d ' ')
167     if [[ "$res" == "$pool" ]]; then
168         error "File $dir is in pool: $res"
169         return 1
170     fi
171     return 0
172 }
173
174 drain_pool() {
175     pool=$1
176     wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool" "" ||
177         error "Failed to remove targets from pool: $pool"
178 }
179
180 add_pool() {
181     local pool=$1
182     local osts=$2
183     local tgt="${3}$(lctl get_param -n lov.$FSNAME-*.pools.$pool |
184                sort -u | tr '\n' ' ')"
185
186     do_facet $SINGLEMDS lctl pool_add $FSNAME.$pool $osts
187     local RC=$?
188     [[ $RC -ne 0 ]] && return $RC
189
190     wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool |
191                            sort -u | tr '\n' ' ' " "$tgt" >/dev/null || RC=1
192     [[ $RC -ne 0 ]] && error "pool_add failed: $1; $2"
193     return $RC
194 }
195
196 create_pool_nofail() {
197     create_pool $FSNAME.$1
198     if [[ $? != 0 ]]; then
199         error "Pool creation of $1 failed"
200     fi
201 }
202
203 create_pool_fail() {
204     create_pool $FSNAME.$1
205     if [[ $? == 0 ]]; then
206         error "Pool creation of $1 succeeded; should have failed"
207     fi
208 }
209
210 cleanup_tests() {
211     # Destroy pools from previous test runs
212     for p in $(do_facet $SINGLEMDS lctl pool_list $FSNAME | grep $POOL); do
213         destroy_pool_int $p;
214     done
215     rm -rf $DIR/d0.${TESTSUITE}
216 }
217
218 ost_pools_init() {
219     cleanup_tests
220 }
221
222 set_cleanup_trap() {
223     trap "cleanup_tests $FSNAME" EXIT
224 }
225
226 # Initialization
227 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
228 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
229 ost_pools_init
230
231
232 # Tests for new commands added
233 test_1a() {
234     set_cleanup_trap
235     create_pool_nofail p
236     destroy_pool p
237 }
238 run_test 1a "Create a pool with a 1 character pool name"
239
240 test_1b() {
241     set_cleanup_trap
242     create_pool_nofail ${POOL}12
243     destroy_pool ${POOL}12
244 }
245 run_test 1b "Create a pool with a 10 character pool name"
246
247 test_1c() {
248     set_cleanup_trap
249     create_pool_nofail ${POOL}12345678
250     destroy_pool ${POOL}12345678
251 }
252 run_test 1c "Create a pool with a 16 character pool name"
253
254 test_1d() {
255     set_cleanup_trap
256     create_pool_fail ${POOL}123456789
257 }
258 run_test 1d "Create a pool with a 17 char pool name; should fail"
259
260 test_1e() {
261     set_cleanup_trap
262     local pool_name="$POOL"
263     for ((i = 1; i <= 991; i++)); do pool_name=${pool_name}"o"; done
264     create_pool_fail $pool_name
265 }
266 run_test 1e "Create a pool with a 1000 char pool name; should fail"
267
268 test_1f() {
269     set_cleanup_trap
270     do_facet $SINGLEMDS lctl pool_new .$POOL 2>/dev/null
271     [[ $? -ne 0 ]] ||
272         error "pool_new did not fail even though fs-name was missing"
273 }
274 run_test 1f "pool_new should fail if fs-name is missing"
275
276 test_1g() {
277     set_cleanup_trap
278     do_facet $SINGLEMDS lctl pool_new $POOL 2>/dev/null
279     [[ $? -ne 0 ]] ||
280         error "pool_new did not fail even though fs-name was missing"
281 }
282 run_test 1g "pool_new should fail if fs-name is missing"
283
284 test_1h() {
285     set_cleanup_trap
286     do_facet $SINGLEMDS lctl pool_new ${FSNAME}. 2>/dev/null
287     [[ $? -ne 0 ]] ||
288         error "pool_new did not fail even though pool name was missing"
289 }
290 run_test 1h "pool_new should fail if poolname is missing"
291
292 test_1i() {
293     set_cleanup_trap
294     do_facet $SINGLEMDS lctl pool_new . 2>/dev/null
295     [[ $? -ne 0 ]] ||
296         error "pool_new did not fail even if pool and fs-name were missing"
297 }
298 run_test 1i "pool_new should fail if poolname and fs-name are missing"
299
300 test_1j() {
301     set_cleanup_trap
302     do_facet $SINGLEMDS lctl pool_new ${FSNAME},$POOL 2>/dev/null
303     [[ $? -ne 0 ]] ||
304         error "pool_new did not fail even though pool name format was wrong"
305 }
306 run_test 1j "pool_new should fail if poolname format is wrong"
307
308 test_1k() {
309     set_cleanup_trap
310     do_facet $SINGLEMDS lctl pool_new ${FSNAME}/$POOL 2>/dev/null
311     [[ $? -ne 0 ]] ||
312         error "pool_new did not fail even though pool name format was wrong"
313 }
314 run_test 1k "pool_new should fail if poolname format is wrong"
315
316 test_1m() {
317     set_cleanup_trap
318     create_pool_nofail $POOL2
319     do_facet $SINGLEMDS lctl pool_new ${FSNAME}.$POOL2 2>/dev/null
320     [[ $? -ne 0 ]] ||
321         error "pool_new did not fail even though $POOL2 existed"
322     destroy_pool $POOL2
323 }
324 run_test 1m "pool_new did not fail even though $POOL2 existed"
325
326 test_2a() {
327     set_cleanup_trap
328     destroy_pool $POOL
329
330     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $FSNAME-OST0000 2>/dev/null
331     [[ $? -ne 0 ]] ||
332         error "pool_add did not fail even though $POOL did not exist"
333 }
334 run_test 2a "pool_add: non-existant pool $POOL"
335
336 test_2b() {
337     set_cleanup_trap
338     do_facet $SINGLEMDS lctl pool_add $FSNAME.${POOL}1234567890 \
339         $FSNAME-OST0000 2>/dev/null
340     [[ $? -ne 0 ]] ||
341         error "pool_add did not fail even though pool name was invalid."
342 }
343 run_test 2b "pool_add: Invalid pool name"
344
345 # Testing various combinations of OST name list
346 test_2c() {
347     set_cleanup_trap
348     local TGT
349     local RC
350
351     lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
352     [[ $? -ne 0 ]] || destroy_pool $POOL
353
354     create_pool_nofail $POOL
355
356     # 1. OST0000
357     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL OST0000
358     RC=$?; [[ $RC -eq 0 ]] ||
359         error "pool_add failed. $FSNAME $POOL OST0000: $RC"
360     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL OST0000
361     drain_pool $POOL
362
363     # 2. lustre-OST0000
364     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $FSNAME-OST0000
365     RC=$?; [[ $RC -eq 0 ]] ||
366         error "pool_add failed. $FSNAME $POOL $FSNAME-OST0000: $RC"
367     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000
368     drain_pool $POOL
369
370     # 3. lustre-OST0000_UUID
371     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $FSNAME-OST0000_UUID
372     RC=$?; [[ $RC -eq 0 ]] ||
373         error "pool_add failed. $FSNAME $POOL $FSNAME-OST0000_UUID: $RC"
374     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000_UUID
375     drain_pool $POOL
376
377     # 4. lustre-OST[0,1,2,3,]
378     TGT="$FSNAME-OST["
379     for i in $TGT_LIST; do TGT=${TGT}$(printf "%04x," $i); done
380     TGT="${TGT}]"
381     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $TGT
382     [[ $? -eq 0 ]] || error "pool_add failed. $FSNAME.$POOL $TGT. $RC"
383     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $TGT
384     drain_pool $POOL
385
386     # 5. lustre-OST[0-5/1]
387     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $TGT_ALL
388     RC=$?; [[ $RC -eq 0 ]] ||
389         error "pool_add failed. $FSNAME $POOL" "$TGT_ALL $RC"
390     wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL |
391       sort -u | tr '\n' ' ' " "$TGT_UUID" || error "Add to pool failed"
392     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $TGT_ALL
393     drain_pool $POOL
394
395     destroy_pool $POOL
396 }
397 run_test 2c "pool_add: OST index combinations"
398
399 test_2d() {
400     set_cleanup_trap
401     local TGT
402     local RC
403
404     lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
405     [[ $? -ne 0 ]] || destroy_pool $POOL
406
407     create_pool_nofail $POOL
408
409     TGT=$(printf "$FSNAME-OST%04x_UUID " $OSTCOUNT)
410     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $TGT
411     RC=$?; [[ $RC -ne 0 ]] ||
412         error "pool_add succeeded for an OST ($TGT) that does not exist."
413
414     destroy_pool $POOL
415 }
416 run_test 2d "pool_add: OSTs that don't exist should be rejected"
417
418 test_2e() {
419     set_cleanup_trap
420     local TGT
421     local RC
422     local RESULT
423
424     $LCTL get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
425     [[ $? -ne 0 ]] || destroy_pool $POOL
426
427     create_pool_nofail $POOL
428
429     TGT="$FSNAME-OST0000_UUID "
430     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $TGT
431     wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL |
432         sort -u | tr '\n' ' ' " "$TGT" || error "Add to pool failed"
433     RESULT=$(do_facet $SINGLEMDS \
434              "LOCALE=C $LCTL pool_add $FSNAME.$POOL $TGT 2>&1")
435     RC=$?
436     echo $RESULT
437
438     [[ $RC -ne 0 ]] ||
439         error "pool_add succeeded for an OST that was already in the pool."
440
441     [[ $(grep "already in pool" <<< $RESULT) ]] ||
442         error "pool_add failed as expected but error message not as expected."
443
444     destroy_pool $POOL
445 }
446 run_test 2e "pool_add: OST already in a pool should be rejected"
447
448 test_3a() {
449     set_cleanup_trap
450     lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
451     [[ $? -ne 0 ]] || destroy_pool $POOL
452
453     do_facet $SINGLEMDS \
454         lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000 2>/dev/null
455     [[ $? -ne 0 ]] ||
456         error "pool_remove did not fail even though pool did not exist."
457 }
458 run_test 3a "pool_remove: non-existant pool"
459
460 test_3b() {
461     set_cleanup_trap
462     do_facet $SINGLEMDS \
463         lctl pool_remove ${NON_EXISTANT_FS}.$POOL OST0000 2>/dev/null
464     [[ $? -ne 0 ]] ||
465         error "pool_remove did not fail even though fsname did not exist."
466 }
467 run_test 3b "pool_remove: non-existant fsname"
468
469 test_3c() {
470     set_cleanup_trap
471     do_facet $SINGLEMDS lctl pool_remove $FSNAME.p1234567891234567890 \
472         $FSNAME-OST0000 2>/dev/null
473     [[ $? -ne 0 ]] ||
474         error "pool_remove did not fail even though pool name was invalid."
475 }
476 run_test 3c "pool_remove: Invalid pool name"
477
478 # Testing various combinations of OST name list
479 test_3d() {
480     set_cleanup_trap
481     lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
482     [[ $? -ne 0 ]] || destroy_pool $POOL
483
484     create_pool_nofail $POOL
485     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL OST0000
486     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL OST0000
487     [[ $? -eq 0 ]] || error "pool_remove failed. $FSNAME $POOL OST0000"
488     drain_pool $POOL
489
490     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $FSNAME-OST0000
491     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000
492     [[ $? -eq 0 ]] || error "pool_remove failed. $FSNAME $POOL $FSNAME-OST0000"
493     drain_pool $POOL
494
495     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $FSNAME-OST0000_UUID
496     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000_UUID
497     [[ $? -eq 0 ]] ||
498         error "pool_remove failed. $FSNAME $POOL $FSNAME-OST0000_UUID"
499     drain_pool $POOL
500
501     add_pool $POOL $TGT_ALL "$TGT_UUID"
502     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $TGT_ALL
503     [[ $? -eq 0 ]] || error "pool_remove failed. $FSNAME $POOL" $TGT_ALL
504     drain_pool $POOL
505
506     destroy_pool $POOL
507 }
508 run_test 3d "pool_remove: OST index combinations"
509
510 test_4a() {
511     set_cleanup_trap
512     lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
513     [[ $? -ne 0 ]] || destroy_pool $POOL
514
515     do_facet $SINGLEMDS lctl pool_destroy $FSNAME.$POOL 2>/dev/null
516     [[ $? -ne 0 ]] ||
517         error "pool_destroy did not fail even though pool did not exist."
518 }
519 run_test 4a "pool_destroy: non-existant pool"
520
521 test_4b() {
522     set_cleanup_trap
523     do_facet $SINGLEMDS lctl pool_destroy ${NON_EXISTANT_FS}.$POOL 2>/dev/null
524     [[ $? -ne 0 ]] ||
525         error "pool_destroy did not fail even though filesystem did not exist."
526 }
527 run_test 4b "pool_destroy: non-existant fs-name"
528
529 test_4c() {
530     set_cleanup_trap
531     create_pool_nofail $POOL
532     add_pool $POOL "OST0000" "$FSNAME-OST0000_UUID "
533
534     do_facet $SINGLEMDS lctl pool_destroy ${FSNAME}.$POOL
535     [[ $? -ne 0 ]] || error "pool_destroy succeeded with a non-empty pool."
536     destroy_pool $POOL
537 }
538 run_test 4c "pool_destroy: non-empty pool"
539
540 sub_test_5() {
541     local LCMD=$1
542
543     $LCMD pool_list 2>/dev/null
544     [[ $? -ne 0 ]] || error "pool_list did not fail even though fsname missing."
545
546     destroy_pool $POOL 2>/dev/null
547     destroy_pool $POOL2 2>/dev/null
548
549     create_pool_nofail $POOL
550     create_pool_nofail $POOL2
551     $LCMD pool_list $FSNAME
552     [[ $? -eq 0 ]] || error "pool_list $FSNAME failed."
553
554     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $TGT_ALL
555
556     $LCMD pool_list $FSNAME.$POOL
557     [[ $? -eq 0 ]] || error "pool_list $FSNAME.$POOL failed."
558
559     $LCMD pool_list ${NON_EXISTANT_FS} 2>/dev/null
560     [[ $? -ne 0 ]] || error "pool_list did not fail for fsname $NON_EXISTANT_FS"
561
562     $LCMD pool_list ${FSNAME}.$NON_EXISTANT_POOL 2>/dev/null
563     [[ $? -ne 0 ]] || error "pool_list did not fail for pool $NON_EXISTANT_POOL"
564
565     if [[ ! $(grep $SINGLEMDS <<< $LCMD) ]]; then
566         echo $LCMD pool_list $DIR
567         $LCMD pool_list $DIR
568         [[ $? -eq 0 ]] || error "pool_list failed for $DIR"
569
570         mkdir -p ${DIR}/d1
571         $LCMD pool_list ${DIR}/d1
572         [[ $? -eq 0 ]] || error "pool_list failed for ${DIR}/d1"
573     fi
574
575     rm -rf ${DIR}nonexistant
576     $LCMD pool_list ${DIR}nonexistant 2>/dev/null
577     [[ $? -ne 0 ]] ||
578         error "pool_list did not fail for invalid mountpoint ${DIR}nonexistant"
579
580     destroy_pool $POOL
581     destroy_pool $POOL2
582 }
583
584 test_5() {
585     set_cleanup_trap
586     # Issue commands from client
587     sub_test_5 $LCTL
588     sub_test_5 $LFS
589
590     # Issue commands from MDS
591     sub_test_5 "do_facet $SINGLEMDS lctl"
592     sub_test_5 "do_facet $SINGLEMDS lfs"
593
594 }
595 run_test 5 "lfs/lctl pool_list"
596
597 test_6() {
598     set_cleanup_trap
599     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
600     local POOL_DIR=$POOL_ROOT/dir_tst
601     local POOL_FILE=$POOL_ROOT/file_tst
602
603     create_pool_nofail $POOL
604
605     do_facet $SINGLEMDS lctl pool_list $FSNAME
606     [[ $? -eq 0 ]] || error "pool_list $FSNAME failed."
607
608     add_pool $POOL $TGT_ALL "$TGT_UUID"
609
610     mkdir -p $POOL_DIR
611     $SETSTRIPE -c -1 -p $POOL $POOL_DIR
612     [[ $? -eq 0 ]] || error "$SETSTRIPE -p $POOL failed."
613     check_dir_in_pool $POOL_DIR $POOL
614
615     # If an invalid pool name is specified, the command should fail
616     $SETSTRIPE -c 2 -p $INVALID_POOL $POOL_DIR 2>/dev/null
617     [[ $? -ne 0 ]] || error "setstripe to invalid pool did not fail."
618
619     # If the pool name does not exist, the command should fail
620     $SETSTRIPE -c 2 -p $NON_EXISTANT_POOL $POOL_DIR 2>/dev/null
621     [[ $? -ne 0 ]] || error "setstripe to non-existant pool did not fail."
622
623     # lfs setstripe should work as before if a pool name is not specified.
624     $SETSTRIPE -c -1 $POOL_DIR
625     [[ $? -eq 0 ]] || error "$SETSTRIPE -p $POOL_DIR failed."
626     $SETSTRIPE -c -1 $POOL_FILE
627     [[ $? -eq 0 ]] || error "$SETSTRIPE -p $POOL_FILE failed."
628
629     # lfs setstripe should fail if a start index that is outside the
630     # pool is specified.
631     create_pool_nofail $POOL2
632     add_pool $POOL2 "OST0000" "$FSNAME-OST0000_UUID "
633     $SETSTRIPE -o 1 -p $POOL2 $ROOT_POOL/$tfile 2>/dev/null
634     [[ $? -ne 0 ]] ||
635         error "$SETSTRIPE with start index outside the pool did not fail."
636
637     destroy_pool $POOL
638     destroy_pool $POOL2
639 }
640 run_test 6 "getstripe/setstripe"
641
642 test_11() {
643     set_cleanup_trap
644     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
645
646     [[ $OSTCOUNT -le 1 ]] && skip_env "Need at least 2 OSTs" && return
647
648     create_pool_nofail $POOL
649     create_pool_nofail $POOL2
650
651     local start=$(printf %04x $((TGT_FIRST + 1)))
652     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL2 \
653         $FSNAME-OST[$start-$TGT_MAX/2]
654
655     add_pool $POOL $TGT_HALF "$TGT_UUID2"
656
657     create_dir $POOL_ROOT/dir1  $POOL
658     create_dir $POOL_ROOT/dir2  $POOL2
659     check_dir_in_pool $POOL_ROOT/dir1 $POOL
660     check_dir_in_pool $POOL_ROOT/dir1 $POOL
661
662     local numfiles=100
663     createmany -o $POOL_ROOT/dir1/$tfile $numfiles ||
664         error "createmany $POOL_ROOT/dir1/$tfile failed!"
665
666     for file in $POOL_ROOT/dir1/*; do
667         check_file_in_pool $file $POOL
668     done
669
670     createmany -o $POOL_ROOT/dir2/$tfile $numfiles ||
671         error "createmany $POOL_ROOT/dir2/$tfile failed!"
672     for file in $POOL_ROOT/dir2/*; do
673         check_file_in_pool $file $POOL2
674     done
675
676     rm -rf $POOL_ROOT/dir?
677
678     destroy_pool $POOL
679     destroy_pool $POOL2
680
681     return 0
682 }
683 run_test 11 "OSTs in overlapping/multiple pools"
684
685 test_12() {
686     set_cleanup_trap
687     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
688
689     [[ $OSTCOUNT -le 2 ]] && skip_env "Need at least 3 OSTs" && return
690
691     create_pool_nofail $POOL
692     create_pool_nofail $POOL2
693
694     local start=$(printf %04x $((TGT_FIRST + 1)))
695     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL2 \
696         $FSNAME-OST[$start-$TGT_MAX/2]
697
698     add_pool $POOL $TGT_HALF "$TGT_UUID2"
699
700     echo creating some files in $POOL and $POOL2
701
702     create_dir $POOL_ROOT/dir1  $POOL
703     create_dir $POOL_ROOT/dir2  $POOL2
704     create_file $POOL_ROOT/file1 $POOL
705     create_file $POOL_ROOT/file2 $POOL2
706
707     echo Checking the files created
708     check_dir_in_pool $POOL_ROOT/dir1 $POOL
709     check_dir_in_pool $POOL_ROOT/dir2 $POOL2
710     check_file_in_pool $POOL_ROOT/file1 $POOL
711     check_file_in_pool $POOL_ROOT/file2 $POOL2
712
713     echo Changing the pool membership
714     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $FSNAME-OST[$TGT_FIRST]
715     do_facet $SINGLEMDS lctl pool_list $FSNAME.$POOL
716     FIRST_UUID=$(echo $TGT_UUID | awk '{print $1}')
717     add_pool $POOL2 $FSNAME-OST[$TGT_FIRST] "$FIRST_UUID "
718     do_facet $SINGLEMDS lctl pool_list $FSNAME.$POOL2
719
720     echo Checking the files again
721     check_dir_in_pool $POOL_ROOT/dir1 $POOL
722     check_dir_in_pool $POOL_ROOT/dir2 $POOL2
723     check_file_in_osts $POOL_ROOT/file1 "$TGT_LIST2"
724     check_file_in_osts $POOL_ROOT/file2 "$(seq 0x$start 2 0x$TGT_MAX)"
725
726     echo Creating some more files
727     create_dir $POOL_ROOT/dir3 $POOL
728     create_dir $POOL_ROOT/dir4 $POOL2
729     create_file $POOL_ROOT/file3 $POOL
730     create_file $POOL_ROOT/file4 $POOL2
731
732     echo Checking the new files
733     check_file_in_pool $POOL_ROOT/file3 $POOL
734     check_file_in_pool $POOL_ROOT/file4 $POOL2
735
736     destroy_pool $POOL
737     destroy_pool $POOL2
738
739     return 0
740 }
741 run_test 12 "OST Pool Membership"
742
743 test_13() {
744     set_cleanup_trap
745     [[ $OSTCOUNT -le 2 ]] && skip_env "Need at least 3 OSTs" && return
746
747     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
748     local numfiles=10
749     local count=3
750
751     create_pool_nofail $POOL
752     add_pool $POOL $TGT_ALL "$TGT_UUID"
753
754     create_dir $POOL_ROOT/dir1 $POOL -1
755     createmany -o $POOL_ROOT/dir1/$tfile $numfiles ||
756         error "createmany $POOL_ROOT/dir1/$tfile failed!"
757     for file in $POOL_ROOT/dir1/*; do
758         check_file_in_pool $file $POOL $OSTCOUNT
759     done
760
761     create_file $POOL_ROOT/dir1/file1 $POOL 1 $TGT_FIRST
762     create_file $POOL_ROOT/dir1/file2 $POOL 1 $((TGT_FIRST + 1))
763     create_file $POOL_ROOT/dir1/file3 $POOL 1 $((TGT_FIRST + 2))
764     check_file_in_pool $POOL_ROOT/dir1/file1 $POOL 1
765     check_file_in_pool $POOL_ROOT/dir1/file2 $POOL 1
766     create_file $POOL_ROOT/dir1/file3 $POOL 1 $((TGT_FIRST + 2))
767     check_file_in_osts $POOL_ROOT/dir1/file1 $((16#$TGT_FIRST))
768     check_file_in_osts $POOL_ROOT/dir1/file2 "$((TGT_FIRST + 1))"
769     check_file_in_osts $POOL_ROOT/dir1/file3 "$((TGT_FIRST + 2))"
770
771     create_dir $POOL_ROOT/dir2 $POOL $count
772     createmany -o $POOL_ROOT/dir2/$tfile- $numfiles ||
773         error "createmany $POOL_ROOT/dir2/$tfile- failed!"
774     for file in $POOL_ROOT/dir2/*; do
775         check_file_in_pool $file $POOL $count
776     done
777
778     create_dir $POOL_ROOT/dir3 $POOL $count $((TGT_FIRST + 1))
779     createmany -o $POOL_ROOT/dir3/$tfile- $numfiles ||
780         error "createmany $POOL_ROOT/dir3/$tfile- failed!"
781     for file in $POOL_ROOT/dir3/*; do
782         check_file_in_pool $file $POOL $count
783     done
784
785     create_dir $POOL_ROOT/dir4 $POOL 1
786     createmany -o $POOL_ROOT/dir4/$tfile- $numfiles ||
787         error "createmany $POOL_ROOT/dir4/$tfile- failed!"
788     for file in $POOL_ROOT/dir4/*; do
789         check_file_in_pool $file $POOL 1
790     done
791
792     create_dir $POOL_ROOT/dir5 $POOL 1 $((TGT_FIRST + 2))
793     createmany -o $POOL_ROOT/dir5/$tfile- $numfiles ||
794         error "createmany $POOL_ROOT/dir5/$tfile- failed!"
795     for file in $POOL_ROOT/dir5/*; do
796         check_file_in_pool $file $POOL 1
797         check_file_in_osts  $file "$((TGT_FIRST + 2))"
798     done
799
800     rm -rf $POOL_ROOT/dir[1-5]/
801     destroy_pool $POOL
802
803     return 0
804 }
805 run_test 13 "Striping characteristics in a pool"
806
807 test_14() {
808     set_cleanup_trap
809     [[ $OSTCOUNT -le 2 ]] && skip_env "Need at least 3 OSTs" && return
810
811     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
812     local numfiles=100
813     local i
814
815     [ $OSTSIZE -gt $((MAXFREE / OSTCOUNT)) ] &&
816         skip_env "OST size $OSTSIZE is larger than $((MAXFREE / OSTCOUNT))" &&
817             return 0
818
819     create_pool_nofail $POOL
820     create_pool_nofail $POOL2
821
822     add_pool $POOL $TGT_HALF "$TGT_UUID2"
823     add_pool $POOL2 "OST0000" "$FSNAME-OST0000_UUID "
824
825     create_dir $POOL_ROOT/dir1 $POOL 1
826     create_file $POOL_ROOT/dir1/file $POOL 1
827     local OST=$($GETSTRIPE -i $POOL_ROOT/dir1/file)
828     i=0
829     while [[ $i -lt $numfiles ]]; do
830         OST=$((OST + 2))
831         [[ $OST -gt $((16#$TGT_MAX)) ]] && OST=$TGT_FIRST
832
833         # echo "Iteration: $i OST: $OST"
834         create_file $POOL_ROOT/dir1/file${i} $POOL 1
835         check_file_in_pool $POOL_ROOT/dir1/file${i} $POOL
836         i=$((i + 1))
837     done
838
839     # Fill up OST0 until it is nearly full.
840     # Create 9 files of size OST0_SIZE/10 each.
841     create_dir $POOL_ROOT/dir2 $POOL2 1
842     $LFS df $POOL_ROOT/dir2
843     OST0_SIZE=$($LFS df $POOL_ROOT/dir2 | awk '/\[OST:0\]/ { print $4 }')
844     FILE_SIZE=$((OST0_SIZE/1024/10))
845     echo "Filling OST0 with 9 files of ${FILE_SIZE}MB in $POOL_ROOT/dir2"
846     i=1
847     while [[ $i -lt 10 ]]; do
848         dd if=/dev/zero of=$POOL_ROOT/dir2/f${i} bs=1M count=$FILE_SIZE
849         i=$((i + 1))
850     done
851     sleep 1 # get new statfs info
852     $LFS df $POOL_ROOT/dir2
853
854     # OST $TGT_FIRST is no longer favored; but it may still be used.
855     create_dir $POOL_ROOT/dir3 $POOL 1
856     create_file $POOL_ROOT/dir3/file $POOL 1
857     createmany -o $POOL_ROOT/dir3/$tfile- $numfiles ||
858         error "createmany $POOL_ROOT/dir3/$tfile- failed!"
859     for file in $POOL_ROOT/dir3/*; do
860         check_file_in_pool $file $POOL
861     done
862
863     rm -rf $POOL_ROOT
864     destroy_pool $POOL
865     destroy_pool $POOL2
866
867     return 0
868 }
869 run_test 14 "Round robin and QOS striping within a pool"
870
871 test_15() {
872     set_cleanup_trap
873     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
874     local numfiles=100
875     local i=0
876
877     while [[ $i -lt $OSTCOUNT ]]; do
878         create_pool_nofail $POOL${i}
879
880         local tgt=$(printf "$FSNAME-OST%04x_UUID " $i)
881         add_pool $POOL${i} "$FSNAME-OST[$(printf %04x $i)]" "$tgt"
882         create_dir $POOL_ROOT/dir${i} $POOL${i}
883         createmany -o $POOL_ROOT/dir$i/$tfile $numfiles ||
884             error "createmany $POOL_ROOT/dir$i/$tfile failed!"
885
886         for file in $POOL_ROOT/dir$i/*; do
887             check_file_in_osts $file $i
888         done
889
890         i=$((i + 1))
891     done
892
893     i=0
894     while [[ $i -lt $OSTCOUNT ]]; do
895           destroy_pool $POOL${i}
896           i=$((i + 1))
897     done
898
899     return 0
900 }
901 run_test 15 "One directory per OST/pool"
902
903 test_16() {
904     set_cleanup_trap
905     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
906     local numfiles=10
907     local i=0
908
909     create_pool_nofail $POOL
910
911     add_pool $POOL $TGT_HALF "$TGT_UUID2"
912
913     local dir=$POOL_ROOT/$tdir
914     create_dir $dir $POOL
915
916     for i in $(seq 1 10); do
917         dir=${dir}/dir${i}
918     done
919     mkdir -p $dir
920
921     createmany -o $dir/$tfile $numfiles ||
922         error "createmany $dir/$tfile failed!"
923
924     for file in $dir/*; do
925         check_file_in_pool $file $POOL
926     done
927
928     rm -rf $POOL_ROOT/$tdir
929
930     destroy_pool $POOL
931
932     return 0
933 }
934 run_test 16 "Inheritance of pool properties"
935
936 test_17() {
937     set_cleanup_trap
938     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
939     local numfiles=10
940     local i=0
941
942     create_pool_nofail $POOL
943
944     add_pool $POOL $TGT_ALL "$TGT_UUID"
945
946     local dir=$POOL_ROOT/dir
947     create_dir $dir $POOL
948
949     createmany -o $dir/${tfile}1_ $numfiles ||
950         error "createmany $dir/${tfile}1_ failed!"
951
952     for file in $dir/*; do
953         check_file_in_pool $file $POOL
954     done
955
956     destroy_pool $POOL
957
958     createmany -o $dir/${tfile}2_ $numfiles ||
959           error "createmany $dir/${tfile}2_ failed!"
960
961     rm -rf $dir
962     return 0
963 }
964 run_test 17 "Referencing an empty pool"
965
966 create_perf() {
967     local cdir=$1/d
968     local numsec=$2
969     local time
970
971     mkdir -p $cdir
972     sync
973     wait_delete_completed >/dev/null # give pending IO a chance to go to disk
974     stat=$(createmany -o $cdir/${tfile} -$numsec | tail -1)
975     files=$(echo $stat | cut -f 2 -d ' ')
976     echo $stat 1>&2
977     unlinkmany $cdir/${tfile} $files > /dev/null
978     sync
979
980     echo $files
981 }
982
983 test_18() {
984     set_cleanup_trap
985     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
986     local numsec=15
987     local iter=3
988     local plaindir=$POOL_ROOT/plaindir
989     local pooldir=$POOL_ROOT/pooldir
990     local f1=0
991     local f2=0
992     local f3=0
993     local diff
994
995     for i in $(seq 1 $iter); do
996         echo "Create performance, iteration $i, $numsec seconds x 3"
997
998         files1=$(create_perf $plaindir $numsec)
999         echo "iter $i: $files1 creates without pool"
1000         f1=$(($f1 + $files1))
1001
1002         create_pool_nofail $POOL > /dev/null
1003         add_pool $POOL $TGT_ALL "$TGT_UUID" > /dev/null
1004         create_dir $pooldir $POOL
1005         files2=$(create_perf $pooldir $numsec)
1006         echo "iter $i: $files2 creates with pool"
1007         f2=$(($f2 + $files2))
1008
1009         destroy_pool $POOL > /dev/null
1010         files3=$(create_perf $pooldir $numsec)
1011         echo "iter $i: $files3 creates with missing pool"
1012         f3=$(($f3 + $files3))
1013
1014         echo
1015     done
1016
1017     echo Avg files created in $numsec seconds without pool: $((files1 / iter))
1018     echo Avg files created in $numsec seconds with pool: $((files2 / iter))
1019     echo Avg files created in $numsec seconds missing pool: $((files3 / iter))
1020
1021     # Set this high until we establish a baseline for what the degradation
1022     # is / should be
1023     max=30
1024     diff=$((($files1 - $files2) * 100 / $files1))
1025     echo  "No pool / wide pool: $diff %."
1026     [ $diff -gt $max ] &&
1027         error_ignore 23408 "Degradation with wide pool is $diff% > $max%"
1028
1029     max=30
1030     diff=$((($files1 - $files3) * 100 / $files1))
1031     echo  "No pool / missing pool: $diff %."
1032     [ $diff -gt $max ] &&
1033         error_ignore 23408 "Degradation with wide pool is $diff% > $max%"
1034
1035     return 0
1036 }
1037 run_test 18 "File create in a directory which references a deleted pool"
1038
1039 test_19() {
1040     set_cleanup_trap
1041     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1042     local numfiles=12
1043     local dir1=$POOL_ROOT/dir1
1044     local dir2=$POOL_ROOT/dir2
1045     local i=0
1046
1047     create_pool_nofail $POOL
1048
1049     add_pool $POOL $TGT_HALF "$TGT_UUID2"
1050
1051     create_dir $dir1 $POOL
1052     createmany -o $dir1/${tfile} $numfiles ||
1053           error "createmany $dir1/${tfile} failed!"
1054     for file in $dir1/*; do
1055         check_file_in_pool $file $POOL
1056     done
1057
1058     mkdir -p $dir2
1059     createmany -o $dir2/${tfile} $numfiles ||
1060           error "createmany $dir2/${tfile} failed!"
1061     for file in $dir2/*; do
1062         check_file_not_in_pool $file $POOL
1063     done
1064
1065     rm -rf $dir1 $dir2
1066     destroy_pool $POOL
1067
1068     return 0
1069 }
1070 run_test 19 "Pools should not come into play when not specified"
1071
1072 test_20() {
1073     set_cleanup_trap
1074     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1075     local numfiles=12
1076     local dir1=$POOL_ROOT/dir1
1077     local dir2=$dir1/dir2
1078     local dir3=$dir1/dir3
1079     local i=0
1080     local TGT
1081
1082     create_pool_nofail $POOL
1083     create_pool_nofail $POOL2
1084
1085     add_pool $POOL $TGT_HALF "$TGT_UUID2"
1086
1087     local start=$(printf %04x $((TGT_FIRST + 1)))
1088     TGT=$(for i in $(seq 0x$start 2 0x$TGT_MAX); do \
1089           printf "$FSNAME-OST%04x_UUID " $i; done)
1090     add_pool $POOL2 "$FSNAME-OST[$start-$TGT_MAX/2]" "$TGT"
1091
1092     create_dir $dir1 $POOL
1093     create_file $dir1/file1 $POOL2
1094     create_dir $dir2 $POOL2
1095     touch $dir2/file2
1096     mkdir $dir3
1097     $SETSTRIPE -c 1 $dir3 # No pool assignment
1098     touch $dir3/file3
1099     $SETSTRIPE -c 1 $dir2/file4 # No pool assignment
1100
1101     check_file_in_pool $dir1/file1 $POOL2
1102     check_file_in_pool $dir2/file2 $POOL2
1103
1104     check_dir_not_in_pool $dir3 $POOL
1105     check_dir_not_in_pool $dir3 $POOL2
1106
1107     check_file_not_in_pool $dir3/file3 $POOL
1108     check_file_not_in_pool $dir3/file3 $POOL2
1109
1110     check_file_not_in_pool $dir2/file4 $POOL
1111     check_file_not_in_pool $dir2/file4 $POOL2
1112
1113     rm -rf $dir1
1114     destroy_pool $POOL
1115     destroy_pool $POOL2
1116
1117     return 0
1118 }
1119 run_test 20 "Different pools in a directory hierarchy."
1120
1121 test_21() {
1122     set_cleanup_trap
1123     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1124     [[ $OSTCOUNT -le 1 ]] && skip_env "Need at least 2 OSTs" && return
1125
1126     local numfiles=12
1127     local i=0
1128     local dir=$POOL_ROOT/dir
1129
1130     create_pool_nofail $POOL
1131
1132     add_pool $POOL $TGT_HALF "$TGT_UUID2"
1133
1134     create_dir $dir $POOL $OSTCOUNT
1135     create_file $dir/file1 $POOL $OSTCOUNT
1136     $GETSTRIPE -v $dir/file1
1137     check_file_in_pool $dir/file1 $POOL
1138
1139     rm -rf $dir
1140     destroy_pool $POOL
1141
1142     return 0
1143 }
1144 run_test 21 "OST pool with fewer OSTs than stripe count"
1145
1146 add_loop() {
1147     local pool=$1
1148     local step=$2
1149
1150     echo loop for $pool
1151
1152     for c in $(seq 1 10); do
1153         echo "Pool $pool, iteration $c"
1154         do_facet $SINGLEMDS lctl pool_add $FSNAME.$pool \
1155             OST[$TGT_FIRST-$TGT_MAX/$step] 2>/dev/null
1156         local TGT_SECOND=$(printf %04x $((TGT_FIRST + $step)))
1157         if [ $((16#$TGT_SECOND)) -le $((16#$TGT_MAX)) ]; then
1158             do_facet $SINGLEMDS lctl pool_remove $FSNAME.$pool \
1159                 OST[$TGT_SECOND-$TGT_MAX/$step]
1160         fi
1161     done
1162     echo loop for $pool complete
1163 }
1164
1165 test_22() {
1166     set_cleanup_trap
1167     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1168     [[ $OSTCOUNT -le 1 ]] && skip_env "Need at least 2 OSTs" && return
1169
1170     local numfiles=100
1171
1172     create_pool_nofail $POOL
1173     add_pool $POOL "OST0000" "$FSNAME-OST0000_UUID "
1174     create_pool_nofail $POOL2
1175     add_pool $POOL2 "OST0000" "$FSNAME-OST0000_UUID "
1176
1177     add_loop $POOL 1 &
1178     add_loop $POOL2 2 &
1179     sleep 5
1180     create_dir $POOL_ROOT $POOL
1181     createmany -o $POOL_ROOT/${tfile} $numfiles ||
1182         error "createmany $POOL_ROOT/${tfile} failed!"
1183     wait
1184
1185     destroy_pool $POOL
1186     destroy_pool $POOL2
1187
1188     return 0
1189 }
1190 run_test 22 "Simultaneous manipulation of a pool"
1191
1192 test_23a() {
1193     set_cleanup_trap
1194     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1195     [[ $OSTCOUNT -le 1 ]] && skip_env "Need at least 2 OSTs" && return
1196
1197     mkdir -p $POOL_ROOT
1198     check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS || {
1199         skip_env "User $RUNAS_ID does not exist - skipping"
1200         return 0
1201     }
1202
1203     local i=0
1204     local TGT
1205     local BUNIT_SZ=1024  # min block quota unit(kB)
1206     local LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1)))
1207     local dir=$POOL_ROOT/dir
1208     local file="$dir/$tfile-quota"
1209
1210     create_pool_nofail $POOL
1211
1212     local TGT=$(for i in $(seq 0x$TGT_FIRST 3 0x$TGT_MAX); do \
1213                 printf "$FSNAME-OST%04x_UUID " $i; done)
1214     add_pool $POOL "$FSNAME-OST[$TGT_FIRST-$TGT_MAX/3]" "$TGT"
1215     create_dir $dir $POOL
1216
1217     # XXX remove the interoperability code once we drop the old server
1218     #     (< 2.3.50) support.
1219     if [ $(lustre_version_code mds) -lt $(version_code 2.3.50) ]; then
1220         $LFS quotaoff -ug $MOUNT
1221         $LFS quotacheck -ug $MOUNT
1222     else
1223         do_facet mgs $LCTL conf_param $FSNAME.quota.ost=ug
1224         sleep 5
1225     fi
1226
1227     $LFS setquota -u $RUNAS_ID -b $LIMIT -B $LIMIT $dir
1228     sleep 3
1229     $LFS quota -v -u $RUNAS_ID $dir
1230
1231     $LFS setstripe $file -c 1 -p $POOL
1232     chown $RUNAS_ID.$RUNAS_GID $file
1233     ls -l $file
1234
1235     # This does two "dd" runs to ensure that the quota failure is returned
1236     # to userspace when we check.  The first "dd" might otherwise complete
1237     # without error if it is only writing into cache.
1238     stat=$(LOCALE=C $RUNAS dd if=/dev/zero of=$file bs=$BUNIT_SZ \
1239            count=$((BUNIT_SZ*2)) 2>&1)
1240     echo $stat | grep "Disk quota exceeded" > /dev/null
1241     if [ $? -eq 0 ]; then
1242         $LFS quota -v -u $RUNAS_ID $dir
1243         cancel_lru_locks osc
1244         stat=$(LOCALE=C $RUNAS dd if=/dev/zero of=$file bs=$BUNIT_SZ \
1245                count=$BUNIT_SZ seek=$((BUNIT_SZ*2)) 2>&1)
1246         RC=$?
1247         echo $stat
1248         [[ $RC -eq 0 ]] && error "second dd did not fail."
1249         echo $stat | grep "Disk quota exceeded" > /dev/null
1250         [[ $? -eq 1 ]] && error "second dd did not fail with EDQUOT."
1251     else
1252         log "first dd failed with EDQUOT."
1253     fi
1254     $LFS quota -v -u $RUNAS_ID $dir
1255 }
1256 run_test 23a "OST pools and quota"
1257
1258 test_23b() {
1259     set_cleanup_trap
1260     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1261     [[ $OSTCOUNT -le 1 ]] && skip_env "Need at least 2 OSTs" && return 0
1262
1263     mkdir -p $POOL_ROOT
1264     check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS || {
1265         skip_env "User $RUNAS_ID does not exist - skipping"
1266         return 0
1267     }
1268
1269     local i=0
1270     local TGT
1271     local dir=$POOL_ROOT/dir
1272     local file="$dir/$tfile-quota"
1273
1274     create_pool_nofail $POOL
1275
1276     local TGT=$(for i in $(seq 0x$TGT_FIRST 3 0x$TGT_MAX); do \
1277                 printf "$FSNAME-OST%04x_UUID " $i; done)
1278     add_pool $POOL "$FSNAME-OST[$TGT_FIRST-$TGT_MAX/3]" "$TGT"
1279     create_dir $dir $POOL
1280
1281     local maxfree=$((1024 * 1024 * 30)) # 30G
1282     local AVAIL=$(lfs_df -p $POOL $dir | awk '/summary/ { print $4 }')
1283     [ $AVAIL -gt $maxfree ] &&
1284         skip_env "Filesystem space $AVAIL is larger than $maxfree limit" &&
1285             return 0
1286     log "OSTCOUNT=$OSTCOUNT, OSTSIZE=$OSTSIZE"
1287     log "MAXFREE=$MAXFREE, AVAIL=$AVAIL, SLOW=$SLOW"
1288
1289     # XXX remove the interoperability code once we drop the old server
1290     #     (< 2.3.50) support.
1291     if [ $(lustre_version_code mds) -lt $(version_code 2.3.50) ]; then
1292         $LFS quotaoff -ug $MOUNT
1293     else
1294         do_facet mgs $LCTL conf_param $FSNAME.quota.ost=none
1295         sleep 5
1296     fi
1297
1298     chown $RUNAS_ID.$RUNAS_ID $dir
1299     i=0
1300     local RC=0
1301     local TOTAL=0 # KB
1302     local stime=$(date +%s)
1303     local stat
1304     local etime
1305     local elapsed
1306     local maxtime=300 # minimum speed: 5GB / 300sec ~= 17MB/s
1307     while [ $RC -eq 0 ]; do
1308         i=$((i + 1))
1309         stat=$(LOCALE=C $RUNAS2 dd if=/dev/zero of=${file}$i bs=1M \
1310             count=$((5 * 1024)) 2>&1)
1311         RC=$?
1312         TOTAL=$((TOTAL + 1024 * 1024 * 5))
1313         echo "[$i iteration] $stat"
1314         echo "total written: $TOTAL"
1315
1316         etime=$(date +%s)
1317         elapsed=$((etime - stime))
1318         echo "stime=$stime, etime=$etime, elapsed=$elapsed"
1319
1320         if [ $RC -eq 1 ]; then
1321             echo $stat | grep -q "Disk quota exceeded"
1322             [[ $? -eq 0 ]] && error "dd failed with EDQUOT with quota off"
1323
1324             echo $stat | grep -q "No space left on device"
1325             [[ $? -ne 0 ]] && error "dd did not fail with ENOSPC"
1326         elif [ $TOTAL -gt $AVAIL ]; then
1327             error "dd didn't fail with ENOSPC ($TOTAL > $AVAIL)"
1328         elif [ $i -eq 1 -a $elapsed -gt $maxtime ]; then
1329             log "The first 5G write used $elapsed (> $maxtime) " \
1330                 "seconds, terminated"
1331             RC=1
1332         fi
1333     done
1334
1335     df -h
1336
1337     rm -rf $POOL_ROOT
1338 }
1339 run_test 23b "OST pools and OOS"
1340
1341 test_24() {
1342     set_cleanup_trap
1343     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1344     [[ $OSTCOUNT -le 1 ]] && skip_env "Need at least 2 OSTs" && return
1345
1346     local numfiles=10
1347     local i=0
1348     local TGT
1349     local dir
1350     local res
1351
1352     create_pool_nofail $POOL
1353
1354     add_pool $POOL $TGT_ALL "$TGT_UUID"
1355
1356     create_dir $POOL_ROOT/dir1 $POOL $OSTCOUNT
1357
1358     mkdir $POOL_ROOT/dir2
1359     $SETSTRIPE $POOL_ROOT/dir2 -p $POOL -s 65536 -i 0 -c 1 ||
1360         error "$SETSTRIPE $POOL_ROOT/dir2 failed"
1361
1362     mkdir $POOL_ROOT/dir3
1363     $SETSTRIPE $POOL_ROOT/dir3 -s 65536 -i 0 -c 1 ||
1364         error "$SETSTRIPE $POOL_ROOT/dir3 failed"
1365
1366     mkdir $POOL_ROOT/dir4
1367
1368     for i in 1 2 3 4; do
1369         dir=${POOL_ROOT}/dir${i}
1370         local pool
1371         local pool1
1372         local count
1373         local count1
1374         local index
1375         local size
1376         local size1
1377
1378         createmany -o $dir/${tfile} $numfiles ||
1379             error "createmany $dir/${tfile} failed!"
1380         res=$($GETSTRIPE -v $dir | grep "^stripe_count:")
1381         if [ $? -ne 0 ]; then
1382             res=$($GETSTRIPE -v $dir | grep "^(Default) ")
1383             pool=$(cut -f 9 -d ' ' <<< $res)
1384             index=$(cut -f 7 -d ' ' <<< $res)
1385             size=$(cut -f 5 -d ' ' <<< $res)
1386             count=$(cut -f 3 -d ' ' <<< $res)
1387         else
1388             pool=$(cut -f 8 -d ' ' <<< $res)
1389             index=$(cut -f 6 -d ' ' <<< $res)
1390             size=$(cut -f 4 -d ' ' <<< $res)
1391             count=$(cut -f 2 -d ' ' <<< $res)
1392         fi
1393
1394         for file in $dir/*; do
1395             if [ "$pool" != "" ]; then
1396                 check_file_in_pool $file $pool
1397             fi
1398             pool1=$($GETSTRIPE -v $file | grep "^pool:" |
1399                     tr -d '[:blank:]' | cut -f 2 -d ':')
1400             count1=$($GETSTRIPE -v $file | grep "^lmm_stripe_count:" |
1401                      tr -d '[:blank:]' | cut -f 2 -d ':')
1402             size1=$($GETSTRIPE -v $file | grep "^lmm_stripe_size:" |
1403                     tr -d '[:blank:]' | cut -f 2 -d ':')
1404             [[ "$pool" != "$pool1" ]] &&
1405                 error "Pool name ($pool) not inherited in $file($pool1)"
1406             [[ "$count" != "$count1" ]] &&
1407                 error "Stripe count ($count) not inherited in $file ($count1)"
1408             [[ "$size" != "$size1" ]] && [[ "$size" != "0" ]] &&
1409                 error "Stripe size ($size) not inherited in $file ($size1)"
1410         done
1411     done
1412
1413     rm -rf $POOL_ROOT
1414     destroy_pool $POOL
1415
1416     return 0
1417 }
1418 run_test 24 "Independence of pool from other setstripe parameters"
1419
1420 test_25() {
1421     set_cleanup_trap
1422     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1423
1424     mkdir -p $POOL_ROOT
1425
1426     for i in $(seq 10); do
1427         create_pool_nofail $POOL$i
1428         do_facet $SINGLEMDS "lctl pool_add $FSNAME.$POOL$i OST0000; sync"
1429         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL$i |
1430             sort -u | tr '\n' ' ' " "$FSNAME-OST0000_UUID " >/dev/null ||
1431                 error "pool_add failed: $1; $2"
1432
1433         stop $SINGLEMDS || return 1
1434         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS  ||
1435             { error "Failed to start $SINGLEMDS after stopping" && break; }
1436         wait_osc_import_state mds ost FULL
1437         clients_up
1438
1439         # Verify that the pool got created and is usable
1440         df $POOL_ROOT > /dev/null
1441         sleep 5
1442         # Make sure OST0 can be striped on
1443         $SETSTRIPE -o 0 -c 1 $POOL_ROOT/$tfile
1444         STR=$($GETSTRIPE $POOL_ROOT/$tfile | grep 0x | cut -f2 | tr -d " ")
1445         rm $POOL_ROOT/$tfile
1446         if [[ "$STR" == "0" ]]; then
1447             echo "Creating a file in $POOL$i"
1448             create_file $POOL_ROOT/file$i $POOL$i || break
1449             check_file_in_pool $POOL_ROOT/file$i $POOL$i || break
1450         else
1451             echo "OST 0 seems to be unavailable.  Try later."
1452         fi
1453     done
1454
1455     rm -rf $POOL_ROOT
1456     for i in $(seq 10); do
1457         destroy_pool $POOL$i
1458     done
1459 }
1460 run_test 25 "Create new pool and restart MDS"
1461
1462 cd $ORIG_PWD
1463
1464 complete $(basename $0) $SECONDS
1465 cleanup_pools $FSNAME
1466 check_and_cleanup_lustre
1467 exit_status