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