Whamcloud - gitweb
5c130ef6232513ed17dcae4264e0e054df65e9d3
[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 mgs 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 mgs 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 mgs 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 mgs 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 mgs 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 mgs 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 mgs 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 mgs 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 mgs 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 mgs 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 mgs 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 mgs 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 mgs 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 mgs lctl pool_add $FSNAME.$POOL OST0000
370         RC=$?; [[ $RC -eq 0 ]] ||
371                 error "pool_add failed. $FSNAME $POOL OST0000: $RC"
372         do_facet mgs lctl pool_remove $FSNAME.$POOL OST0000
373         drain_pool $POOL
374
375         # 2. $FSNAME-OST0000
376         do_facet mgs 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 mgs lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000
380         drain_pool $POOL
381
382         # 3. $FSNAME-OST0000_UUID
383         do_facet mgs 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 mgs 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 mgs lctl pool_add $FSNAME.$POOL $TGT
394         [[ $? -eq 0 ]] || error "pool_add failed. $FSNAME.$POOL $TGT. $RC"
395         do_facet mgs lctl pool_remove $FSNAME.$POOL $TGT
396         drain_pool $POOL
397
398         # 5. $FSNAME-OST[0-5/1]
399         do_facet mgs 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" ||
404                         error "Add to pool failed"
405         do_facet mgs lctl pool_remove $FSNAME.$POOL $TGT_ALL
406         drain_pool $POOL
407
408         destroy_pool $POOL
409 }
410 run_test 2c "pool_add: OST index combinations"
411
412 test_2d() {
413         set_cleanup_trap
414         local TGT
415         local RC
416
417         lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
418         [[ $? -ne 0 ]] || destroy_pool $POOL
419
420         create_pool_nofail $POOL
421
422         TGT=$(printf "$FSNAME-OST%04x_UUID " $OSTCOUNT)
423         do_facet mgs lctl pool_add $FSNAME.$POOL $TGT
424         RC=$?; [[ $RC -ne 0 ]] ||
425                 error "pool_add succeeded for an OST ($TGT) that does not exist."
426
427         destroy_pool $POOL
428 }
429 run_test 2d "pool_add: OSTs that don't exist should be rejected"
430
431 test_2e() {
432         set_cleanup_trap
433         local TGT
434         local RC
435         local RESULT
436
437         $LCTL get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
438         [[ $? -ne 0 ]] || destroy_pool $POOL
439
440         create_pool_nofail $POOL
441
442         TGT="$FSNAME-OST0000_UUID "
443         do_facet mgs lctl pool_add $FSNAME.$POOL $TGT
444         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL |
445                 sort -u | tr '\n' ' ' " "$TGT" || error "Add to pool failed"
446         RESULT=$(do_facet mgs \
447                 "LOCALE=C $LCTL pool_add $FSNAME.$POOL $TGT 2>&1")
448         RC=$?
449         echo $RESULT
450
451         [[ $RC -ne 0 ]] ||
452                 error "pool_add succeeded for an OST that was already in the pool."
453
454         [[ $(grep "already in pool" <<< $RESULT) ]] ||
455                 error "pool_add failed as expected but error message not as expected."
456
457         destroy_pool $POOL
458 }
459 run_test 2e "pool_add: OST already in a pool should be rejected"
460
461 test_3a() {
462         set_cleanup_trap
463         lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
464         [[ $? -ne 0 ]] || destroy_pool $POOL
465
466         do_facet mgs \
467                 lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000 2>/dev/null
468         [[ $? -ne 0 ]] ||
469                 error "pool_remove did not fail even though pool did not exist."
470 }
471 run_test 3a "pool_remove: non-existant pool"
472
473 test_3b() {
474         set_cleanup_trap
475         do_facet mgs \
476                 lctl pool_remove ${NON_EXISTANT_FS}.$POOL OST0000 2>/dev/null
477         [[ $? -ne 0 ]] ||
478                 error "pool_remove did not fail even though fsname did not exist."
479 }
480 run_test 3b "pool_remove: non-existant fsname"
481
482 test_3c() {
483         set_cleanup_trap
484         do_facet mgs lctl pool_remove $FSNAME.p1234567891234567890 \
485                 $FSNAME-OST0000 2>/dev/null
486         [[ $? -ne 0 ]] ||
487                 error "pool_remove did not fail even though pool name was invalid."
488 }
489 run_test 3c "pool_remove: Invalid pool name"
490
491 # Testing various combinations of OST name list
492 test_3d() {
493         set_cleanup_trap
494         lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
495         [[ $? -ne 0 ]] || destroy_pool $POOL
496
497         create_pool_nofail $POOL
498         do_facet mgs lctl pool_add $FSNAME.$POOL OST0000
499         do_facet mgs lctl pool_remove $FSNAME.$POOL OST0000
500         [[ $? -eq 0 ]] || error "pool_remove failed. $FSNAME $POOL OST0000"
501         drain_pool $POOL
502
503         do_facet mgs lctl pool_add $FSNAME.$POOL $FSNAME-OST0000
504         do_facet mgs lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000
505         [[ $? -eq 0 ]] || error "pool_remove failed. $FSNAME $POOL $FSNAME-OST0000"
506         drain_pool $POOL
507
508         do_facet mgs lctl pool_add $FSNAME.$POOL $FSNAME-OST0000_UUID
509         do_facet mgs lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000_UUID
510         [[ $? -eq 0 ]] ||
511                 error "pool_remove failed. $FSNAME $POOL $FSNAME-OST0000_UUID"
512         drain_pool $POOL
513
514         add_pool $POOL $TGT_ALL "$TGT_UUID"
515         do_facet mgs lctl pool_remove $FSNAME.$POOL $TGT_ALL
516         [[ $? -eq 0 ]] || error "pool_remove failed. $FSNAME $POOL" $TGT_ALL
517         drain_pool $POOL
518
519         destroy_pool $POOL
520 }
521 run_test 3d "pool_remove: OST index combinations"
522
523 test_4a() {
524         set_cleanup_trap
525         lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
526         [[ $? -ne 0 ]] || destroy_pool $POOL
527
528         do_facet mgs lctl pool_destroy $FSNAME.$POOL 2>/dev/null
529         [[ $? -ne 0 ]] ||
530                 error "pool_destroy did not fail even though pool did not exist."
531 }
532 run_test 4a "pool_destroy: non-existant pool"
533
534 test_4b() {
535         set_cleanup_trap
536         do_facet mgs lctl pool_destroy ${NON_EXISTANT_FS}.$POOL 2>/dev/null
537         [[ $? -ne 0 ]] ||
538                 error "pool_destroy did not fail even though filesystem did not exist."
539 }
540 run_test 4b "pool_destroy: non-existant fs-name"
541
542 test_4c() {
543         set_cleanup_trap
544         create_pool_nofail $POOL
545         add_pool $POOL "OST0000" "$FSNAME-OST0000_UUID "
546
547         do_facet mgs lctl pool_destroy ${FSNAME}.$POOL
548         [[ $? -ne 0 ]] || error "pool_destroy succeeded with a non-empty pool."
549         destroy_pool $POOL
550 }
551 run_test 4c "pool_destroy: non-empty pool"
552
553 sub_test_5() {
554         local LCMD=$1
555
556         $LCMD pool_list 2>/dev/null
557         [[ $? -ne 0 ]] ||
558                 error "pool_list did not fail even though fsname missing."
559
560         destroy_pool $POOL 2>/dev/null
561         destroy_pool $POOL2 2>/dev/null
562
563         create_pool_nofail $POOL
564         create_pool_nofail $POOL2
565         $LCMD pool_list $FSNAME
566         [[ $? -eq 0 ]] || error "pool_list $FSNAME failed."
567
568         do_facet mgs lctl pool_add $FSNAME.$POOL $TGT_ALL
569
570         $LCMD pool_list $FSNAME.$POOL
571         [[ $? -eq 0 ]] || error "pool_list $FSNAME.$POOL failed."
572
573         $LCMD pool_list ${NON_EXISTANT_FS} 2>/dev/null
574         [[ $? -ne 0 ]] ||
575                 error "pool_list did not fail for fsname $NON_EXISTANT_FS"
576
577         $LCMD pool_list ${FSNAME}.$NON_EXISTANT_POOL 2>/dev/null
578         [[ $? -ne 0 ]] ||
579                 error "pool_list did not fail for pool $NON_EXISTANT_POOL"
580
581         if [[ ! $(grep $SINGLEMDS <<< $LCMD) ]]; then
582                 echo $LCMD pool_list $DIR
583                 $LCMD pool_list $DIR
584                 [[ $? -eq 0 ]] || error "pool_list failed for $DIR"
585
586                 mkdir -p ${DIR}/d1
587                 $LCMD pool_list ${DIR}/d1
588                 [[ $? -eq 0 ]] || error "pool_list failed for ${DIR}/d1"
589         fi
590
591         rm -rf ${DIR}nonexistant
592         $LCMD pool_list ${DIR}nonexistant 2>/dev/null
593         [[ $? -ne 0 ]] ||
594                 error "pool_list did not fail for invalid mountpoint ${DIR}nonexistant"
595
596         destroy_pool $POOL
597         destroy_pool $POOL2
598 }
599
600 test_5a() {
601     set_cleanup_trap
602     # Issue commands from client
603     sub_test_5 $LFS
604 }
605 run_test 5a "lfs pool_list from client"
606
607 test_5b() {
608     set_cleanup_trap
609     sub_test_5 "do_facet $SINGLEMDS lctl"
610 }
611 run_test 5b "lctl pool_list from MDS"
612
613 test_6() {
614     set_cleanup_trap
615     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
616     local POOL_DIR=$POOL_ROOT/dir_tst
617     local POOL_FILE=$POOL_ROOT/file_tst
618
619     create_pool_nofail $POOL
620
621     do_facet $SINGLEMDS lctl pool_list $FSNAME
622     [[ $? -eq 0 ]] || error "pool_list $FSNAME failed."
623
624     add_pool $POOL $TGT_ALL "$TGT_UUID"
625
626     mkdir -p $POOL_DIR
627     $SETSTRIPE -c -1 -p $POOL $POOL_DIR
628     [[ $? -eq 0 ]] || error "$SETSTRIPE -p $POOL failed."
629     check_dir_in_pool $POOL_DIR $POOL
630
631     # If an invalid pool name is specified, the command should fail
632     $SETSTRIPE -c 2 -p $INVALID_POOL $POOL_DIR 2>/dev/null
633     [[ $? -ne 0 ]] || error "setstripe to invalid pool did not fail."
634
635     # If the pool name does not exist, the command should fail
636     $SETSTRIPE -c 2 -p $NON_EXISTANT_POOL $POOL_DIR 2>/dev/null
637     [[ $? -ne 0 ]] || error "setstripe to non-existant pool did not fail."
638
639     # lfs setstripe should work as before if a pool name is not specified.
640     $SETSTRIPE -c -1 $POOL_DIR
641     [[ $? -eq 0 ]] || error "$SETSTRIPE -p $POOL_DIR failed."
642     $SETSTRIPE -c -1 $POOL_FILE
643     [[ $? -eq 0 ]] || error "$SETSTRIPE -p $POOL_FILE failed."
644
645     # lfs setstripe should fail if a start index that is outside the
646     # pool is specified.
647     create_pool_nofail $POOL2
648     add_pool $POOL2 "OST0000" "$FSNAME-OST0000_UUID "
649     $SETSTRIPE -i 1 -p $POOL2 $ROOT_POOL/$tfile 2>/dev/null
650     [[ $? -ne 0 ]] ||
651         error "$SETSTRIPE with start index outside the pool did not fail."
652
653 }
654 run_test 6 "getstripe/setstripe"
655
656 helper_test_7a()
657 {
658         # Create a pool, stripe a directory and file with it
659         local pool=$1
660
661         pool_add $pool || error "pool_add failed"
662         pool_add_targets $pool 0 1 || error "pool_add_targets failed"
663
664         $SETSTRIPE -c 1 $DIR/$tdir/testfile1 --pool "$pool" || \
665                 error "setstripe failed"
666         $SETSTRIPE -c 1 $DIR/$tdir/testfile2 --pool "$FSNAME.$pool" || \
667                 error "setstripe failed"
668
669         mkdir $DIR/$tdir/testdir
670         $SETSTRIPE -c 1 $DIR/$tdir/testdir  -p "$pool" || \
671                 error "setstripe failed"
672         $SETSTRIPE -c 1 $DIR/$tdir/testdir  -p "$FSNAME.$pool" || \
673                 error "setstripe failed"
674
675         rm -f $DIR/$tdir/testfile1
676         rm -f $DIR/$tdir/testfile2
677         rmdir $DIR/$tdir/testdir
678
679         destroy_pool_int $FSNAME.$pool
680 }
681
682 test_7a()
683 {
684         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
685
686         mkdir -p $DIR/$tdir
687
688         # Generate pool with random name from 1 to 15 characters
689         for i in 1 9 15 ; do
690                 POOLNAME=$(echo $$$RANDOM$RANDOM |
691                            tr -dc 'a-zA-Z0-9' | fold -w $i |
692                            head -n 1)
693                 echo set poolname to $POOLNAME
694                 helper_test_7a $POOLNAME
695         done
696 }
697 run_test 7a "create various pool name"
698
699 test_7b()
700 {
701         # No fsname
702         do_facet mgs lctl pool_new qwerty
703         [ $? -ne 22 ] && error "can create a pool with no fsname"
704
705         # No pool name
706         do_facet mgs lctl pool_new $FSNAME.
707         [ $? -ne 22 ] && error "can create a pool with no name"
708
709         # Invalid character
710         do_facet mgs lctl pool_new $FSNAME.0123456789^bdef
711         [ $? -ne 22 ] && error "can create a pool with an invalid name"
712
713         # Too long
714         do_facet mgs lctl pool_new $FSNAME.0123456789abdefg
715         [ $? -ne 36 ] && error "can create a pool with a name too long"
716
717         return 0
718 }
719 run_test 7b "try to create pool name with invalid lengths or names"
720
721 test_7c()
722 {
723         [ $OSTCOUNT -lt 2 ] && skip "needs >= 2 OSTs" && return
724
725         mkdir -p $DIR/$tdir
726
727         # Create a pool with 15 letters
728         local pool=0123456789abcde
729         pool_add $pool || error "pool_add failed"
730         pool_add_targets $pool 0 1 || error "pool_add_targets failed"
731
732         # setstripe with the same pool name plus 1 letter
733         $SETSTRIPE -c 1 $DIR/$tdir/testfile1 --pool "${pool}X" && \
734                 error "setstripe succedeed"
735
736         # setstripe with the same pool name minus 1 letter
737         $SETSTRIPE -c 1 $DIR/$tdir/testfile1 --pool "${pool%?}" && \
738                 error "setstripe succedeed"
739
740         rm -f $DIR/$tdir/testfile1
741
742         destroy_pool_int $FSNAME.$pool
743 }
744 run_test 7c "create a valid pool name and setstripe with a bad one"
745
746 test_11() {
747         set_cleanup_trap
748         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
749
750         [[ $OSTCOUNT -le 1 ]] && skip_env "Need at least 2 OSTs" && return
751
752         create_pool_nofail $POOL
753         create_pool_nofail $POOL2
754
755         local start=$(printf %04x $((TGT_FIRST + 1)))
756         do_facet mgs lctl pool_add $FSNAME.$POOL2 \
757                 $FSNAME-OST[$start-$TGT_MAX/2]
758
759         add_pool $POOL $TGT_HALF "$TGT_UUID2"
760
761         create_dir $POOL_ROOT/dir1  $POOL
762         create_dir $POOL_ROOT/dir2  $POOL2
763         check_dir_in_pool $POOL_ROOT/dir1 $POOL
764         check_dir_in_pool $POOL_ROOT/dir1 $POOL
765
766         local numfiles=100
767         createmany -o $POOL_ROOT/dir1/$tfile $numfiles ||
768                 error "createmany $POOL_ROOT/dir1/$tfile failed!"
769
770         for file in $POOL_ROOT/dir1/*; do
771                 check_file_in_pool $file $POOL
772         done
773
774         createmany -o $POOL_ROOT/dir2/$tfile $numfiles ||
775                 error "createmany $POOL_ROOT/dir2/$tfile failed!"
776         for file in $POOL_ROOT/dir2/*; do
777                 check_file_in_pool $file $POOL2
778         done
779
780         rm -rf $POOL_ROOT/dir?
781
782         return 0
783 }
784 run_test 11 "OSTs in overlapping/multiple pools"
785
786 test_12() {
787         set_cleanup_trap
788         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
789
790         [[ $OSTCOUNT -le 2 ]] && skip_env "Need at least 3 OSTs" && return
791
792         create_pool_nofail $POOL
793         create_pool_nofail $POOL2
794
795         local start=$(printf %04x $((TGT_FIRST + 1)))
796         do_facet mgs lctl pool_add $FSNAME.$POOL2 \
797                 $FSNAME-OST[$start-$TGT_MAX/2]
798
799         add_pool $POOL $TGT_HALF "$TGT_UUID2"
800
801         echo creating some files in $POOL and $POOL2
802
803         create_dir $POOL_ROOT/dir1  $POOL
804         create_dir $POOL_ROOT/dir2  $POOL2
805         create_file $POOL_ROOT/file1 $POOL
806         create_file $POOL_ROOT/file2 $POOL2
807
808         echo Checking the files created
809         check_dir_in_pool $POOL_ROOT/dir1 $POOL
810         check_dir_in_pool $POOL_ROOT/dir2 $POOL2
811         check_file_in_pool $POOL_ROOT/file1 $POOL
812         check_file_in_pool $POOL_ROOT/file2 $POOL2
813
814         echo Changing the pool membership
815         do_facet mgs lctl pool_remove $FSNAME.$POOL $FSNAME-OST[$TGT_FIRST]
816         do_facet mgs lctl pool_list $FSNAME.$POOL
817         FIRST_UUID=$(echo $TGT_UUID | awk '{print $1}')
818         add_pool $POOL2 $FSNAME-OST[$TGT_FIRST] "$FIRST_UUID "
819         do_facet mgs lctl pool_list $FSNAME.$POOL2
820
821         echo Checking the files again
822         check_dir_in_pool $POOL_ROOT/dir1 $POOL
823         check_dir_in_pool $POOL_ROOT/dir2 $POOL2
824         check_file_in_osts $POOL_ROOT/file1 "$TGT_LIST2"
825         check_file_in_osts $POOL_ROOT/file2 "$(seq 0x$start 2 0x$TGT_MAX)"
826
827         echo Creating some more files
828         create_dir $POOL_ROOT/dir3 $POOL
829         create_dir $POOL_ROOT/dir4 $POOL2
830         create_file $POOL_ROOT/file3 $POOL
831         create_file $POOL_ROOT/file4 $POOL2
832
833         echo Checking the new files
834         check_file_in_pool $POOL_ROOT/file3 $POOL
835         check_file_in_pool $POOL_ROOT/file4 $POOL2
836
837         return 0
838 }
839 run_test 12 "OST Pool Membership"
840
841 test_13() {
842     set_cleanup_trap
843     [[ $OSTCOUNT -le 2 ]] && skip_env "Need at least 3 OSTs" && return
844
845     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
846     local numfiles=10
847     local count=3
848
849     create_pool_nofail $POOL
850     add_pool $POOL $TGT_ALL "$TGT_UUID"
851
852     create_dir $POOL_ROOT/dir1 $POOL -1
853     createmany -o $POOL_ROOT/dir1/$tfile $numfiles ||
854         error "createmany $POOL_ROOT/dir1/$tfile failed!"
855     for file in $POOL_ROOT/dir1/*; do
856         check_file_in_pool $file $POOL $OSTCOUNT
857     done
858
859     create_file $POOL_ROOT/dir1/file1 $POOL 1 $TGT_FIRST
860     create_file $POOL_ROOT/dir1/file2 $POOL 1 $((TGT_FIRST + 1))
861     create_file $POOL_ROOT/dir1/file3 $POOL 1 $((TGT_FIRST + 2))
862     check_file_in_pool $POOL_ROOT/dir1/file1 $POOL 1
863     check_file_in_pool $POOL_ROOT/dir1/file2 $POOL 1
864     create_file $POOL_ROOT/dir1/file3 $POOL 1 $((TGT_FIRST + 2))
865     check_file_in_osts $POOL_ROOT/dir1/file1 $((16#$TGT_FIRST))
866     check_file_in_osts $POOL_ROOT/dir1/file2 "$((TGT_FIRST + 1))"
867     check_file_in_osts $POOL_ROOT/dir1/file3 "$((TGT_FIRST + 2))"
868
869     create_dir $POOL_ROOT/dir2 $POOL $count
870     createmany -o $POOL_ROOT/dir2/$tfile- $numfiles ||
871         error "createmany $POOL_ROOT/dir2/$tfile- failed!"
872     for file in $POOL_ROOT/dir2/*; do
873         check_file_in_pool $file $POOL $count
874     done
875
876     create_dir $POOL_ROOT/dir3 $POOL $count $((TGT_FIRST + 1))
877     createmany -o $POOL_ROOT/dir3/$tfile- $numfiles ||
878         error "createmany $POOL_ROOT/dir3/$tfile- failed!"
879     for file in $POOL_ROOT/dir3/*; do
880         check_file_in_pool $file $POOL $count
881     done
882
883     create_dir $POOL_ROOT/dir4 $POOL 1
884     createmany -o $POOL_ROOT/dir4/$tfile- $numfiles ||
885         error "createmany $POOL_ROOT/dir4/$tfile- failed!"
886     for file in $POOL_ROOT/dir4/*; do
887         check_file_in_pool $file $POOL 1
888     done
889
890     create_dir $POOL_ROOT/dir5 $POOL 1 $((TGT_FIRST + 2))
891     createmany -o $POOL_ROOT/dir5/$tfile- $numfiles ||
892         error "createmany $POOL_ROOT/dir5/$tfile- failed!"
893     for file in $POOL_ROOT/dir5/*; do
894         check_file_in_pool $file $POOL 1
895         check_file_in_osts  $file "$((TGT_FIRST + 2))"
896     done
897
898     rm -rf $POOL_ROOT/dir[1-5]/
899
900     return 0
901 }
902 run_test 13 "Striping characteristics in a pool"
903
904 test_14() {
905     set_cleanup_trap
906     [[ $OSTCOUNT -le 2 ]] && skip_env "Need at least 3 OSTs" && return
907
908     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
909     local numfiles=100
910     local i
911
912     [ $OSTSIZE -gt $((MAXFREE / OSTCOUNT)) ] &&
913         skip_env "OST size $OSTSIZE is larger than $((MAXFREE / OSTCOUNT))" &&
914                         return 0
915
916     create_pool_nofail $POOL
917     create_pool_nofail $POOL2
918
919     add_pool $POOL $TGT_HALF "$TGT_UUID2"
920     add_pool $POOL2 "OST0000" "$FSNAME-OST0000_UUID "
921
922     create_dir $POOL_ROOT/dir1 $POOL 1
923     create_file $POOL_ROOT/dir1/file $POOL 1
924     local OST=$($GETSTRIPE -i $POOL_ROOT/dir1/file)
925     i=0
926     while [[ $i -lt $numfiles ]]; do
927         OST=$((OST + 2))
928         [[ $OST -gt $((16#$TGT_MAX)) ]] && OST=$TGT_FIRST
929
930         # echo "Iteration: $i OST: $OST"
931         create_file $POOL_ROOT/dir1/file${i} $POOL 1
932         check_file_in_pool $POOL_ROOT/dir1/file${i} $POOL
933         i=$((i + 1))
934     done
935
936     # Fill up OST0 until it is nearly full.
937     # Create 9 files of size OST0_SIZE/10 each.
938     create_dir $POOL_ROOT/dir2 $POOL2 1
939     $LFS df $POOL_ROOT/dir2
940     OST0_SIZE=$($LFS df $POOL_ROOT/dir2 | awk '/\[OST:0\]/ { print $4 }')
941     FILE_SIZE=$((OST0_SIZE/1024/10))
942     echo "Filling OST0 with 9 files of ${FILE_SIZE}MB in $POOL_ROOT/dir2"
943     i=1
944     while [[ $i -lt 10 ]]; do
945         dd if=/dev/zero of=$POOL_ROOT/dir2/f${i} bs=1M count=$FILE_SIZE
946         i=$((i + 1))
947     done
948     sleep 1 # get new statfs info
949     $LFS df $POOL_ROOT/dir2
950
951     # OST $TGT_FIRST is no longer favored; but it may still be used.
952     create_dir $POOL_ROOT/dir3 $POOL 1
953     create_file $POOL_ROOT/dir3/file $POOL 1
954     createmany -o $POOL_ROOT/dir3/$tfile- $numfiles ||
955         error "createmany $POOL_ROOT/dir3/$tfile- failed!"
956     for file in $POOL_ROOT/dir3/*; do
957         check_file_in_pool $file $POOL
958     done
959
960     rm -rf $POOL_ROOT
961
962     return 0
963 }
964 run_test 14 "Round robin and QOS striping within a pool"
965
966 test_15() {
967     set_cleanup_trap
968     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
969     local numfiles=100
970     local i=0
971
972     while [[ $i -lt $OSTCOUNT ]]; do
973         create_pool_nofail $POOL${i}
974
975         local tgt=$(printf "$FSNAME-OST%04x_UUID " $i)
976         add_pool $POOL${i} "$FSNAME-OST[$(printf %04x $i)]" "$tgt"
977         create_dir $POOL_ROOT/dir${i} $POOL${i}
978         createmany -o $POOL_ROOT/dir$i/$tfile $numfiles ||
979             error "createmany $POOL_ROOT/dir$i/$tfile failed!"
980
981         for file in $POOL_ROOT/dir$i/*; do
982             check_file_in_osts $file $i
983         done
984
985         i=$((i + 1))
986     done
987
988     return 0
989 }
990 run_test 15 "One directory per OST/pool"
991
992 test_16() {
993     set_cleanup_trap
994     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
995     local numfiles=10
996     local i=0
997
998     create_pool_nofail $POOL
999
1000     add_pool $POOL $TGT_HALF "$TGT_UUID2"
1001
1002     local dir=$POOL_ROOT/$tdir
1003     create_dir $dir $POOL
1004
1005     for i in $(seq 1 10); do
1006         dir=${dir}/dir${i}
1007     done
1008     mkdir -p $dir
1009
1010     createmany -o $dir/$tfile $numfiles ||
1011         error "createmany $dir/$tfile failed!"
1012
1013     for file in $dir/*; do
1014         check_file_in_pool $file $POOL
1015     done
1016
1017     rm -rf $POOL_ROOT/$tdir
1018
1019     return 0
1020 }
1021 run_test 16 "Inheritance of pool properties"
1022
1023 test_17() {
1024     set_cleanup_trap
1025     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1026     local numfiles=10
1027     local i=0
1028
1029     create_pool_nofail $POOL
1030
1031     add_pool $POOL $TGT_ALL "$TGT_UUID"
1032
1033     local dir=$POOL_ROOT/dir
1034     create_dir $dir $POOL
1035
1036     createmany -o $dir/${tfile}1_ $numfiles ||
1037         error "createmany $dir/${tfile}1_ failed!"
1038
1039     for file in $dir/*; do
1040         check_file_in_pool $file $POOL
1041     done
1042
1043     destroy_pool $POOL
1044
1045     createmany -o $dir/${tfile}2_ $numfiles ||
1046           error "createmany $dir/${tfile}2_ failed!"
1047
1048     rm -rf $dir
1049     return 0
1050 }
1051 run_test 17 "Referencing an empty pool"
1052
1053 create_perf() {
1054     local cdir=$1/d
1055     local numsec=$2
1056     local time
1057
1058     mkdir -p $cdir
1059     sync
1060     wait_delete_completed >/dev/null # give pending IO a chance to go to disk
1061     stat=$(createmany -o $cdir/${tfile} -$numsec | tail -1)
1062     files=$(echo $stat | cut -f 2 -d ' ')
1063     echo $stat 1>&2
1064     unlinkmany $cdir/${tfile} $files > /dev/null
1065     sync
1066
1067     echo $files
1068 }
1069
1070 test_18() {
1071         set_cleanup_trap
1072         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1073         local numsec=15
1074         local iter=3
1075         local plaindir=$POOL_ROOT/plaindir
1076         local pooldir=$POOL_ROOT/pooldir
1077         local f1=0
1078         local f2=0
1079         local f3=0
1080         local diff
1081
1082         for i in $(seq 1 $iter); do
1083                 echo "Create performance, iteration $i, $numsec seconds x 3"
1084
1085                 local files1=$(create_perf $plaindir $numsec)
1086                 [[ $files1 -eq 0 ]] && error "Zero files created without pool"
1087                 f1=$((f1 + files1))
1088                 echo "iter $i: $files1 creates without pool"
1089
1090                 create_pool_nofail $POOL > /dev/null
1091                 add_pool $POOL $TGT_ALL "$TGT_UUID" > /dev/null
1092                 create_dir $pooldir $POOL
1093                 local files2=$(create_perf $pooldir $numsec)
1094                 [[ $files2 -eq 0 ]] && error "Zero files created with pool"
1095                 f2=$((f2 + files2))
1096                 echo "iter $i: $files2 creates with pool"
1097
1098                 destroy_pool $POOL > /dev/null
1099                 local files3=$(create_perf $pooldir $numsec)
1100                 [[ $files3 -eq 0 ]] &&
1101                         error "Zero files created with missing pool"
1102                 f3=$((f3 + files3))
1103                 echo "iter $i: $files3 creates with missing pool"
1104
1105                 echo
1106         done
1107
1108         echo Avg files created in $numsec seconds without pool: $((f1 / iter))
1109         echo Avg files created in $numsec seconds with pool: $((f2 / iter))
1110         echo Avg files created in $numsec seconds missing pool: $((f3 / iter))
1111
1112         # Set this high until we establish a baseline for what the degradation
1113         # is / should be
1114         max=30
1115
1116         diff=$((($f1 - $f2) * 100 / $f1))
1117         echo  "No pool / wide pool: $diff %."
1118         [ $diff -gt $max ] &&
1119                 error_ignore bz23408 "Degradation with wide pool is $diff% > $max%"
1120
1121         max=30
1122         diff=$((($f1 - $f3) * 100 / $f1))
1123         echo  "No pool / missing pool: $diff %."
1124         [ $diff -gt $max ] &&
1125                 error_ignore bz23408 "Degradation with wide pool is $diff% > $max%"
1126
1127         return 0
1128 }
1129 run_test 18 "File create in a directory which references a deleted pool"
1130
1131 test_19() {
1132     set_cleanup_trap
1133     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1134     local numfiles=12
1135     local dir1=$POOL_ROOT/dir1
1136     local dir2=$POOL_ROOT/dir2
1137     local i=0
1138
1139     create_pool_nofail $POOL
1140
1141     add_pool $POOL $TGT_HALF "$TGT_UUID2"
1142
1143     create_dir $dir1 $POOL
1144     createmany -o $dir1/${tfile} $numfiles ||
1145           error "createmany $dir1/${tfile} failed!"
1146     for file in $dir1/*; do
1147         check_file_in_pool $file $POOL
1148     done
1149
1150     mkdir -p $dir2
1151     createmany -o $dir2/${tfile} $numfiles ||
1152           error "createmany $dir2/${tfile} failed!"
1153     for file in $dir2/*; do
1154         check_file_not_in_pool $file $POOL
1155     done
1156
1157     rm -rf $dir1 $dir2
1158
1159     return 0
1160 }
1161 run_test 19 "Pools should not come into play when not specified"
1162
1163 test_20() {
1164     set_cleanup_trap
1165     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1166     local numfiles=12
1167     local dir1=$POOL_ROOT/dir1
1168     local dir2=$dir1/dir2
1169     local dir3=$dir1/dir3
1170     local i=0
1171     local TGT
1172
1173     create_pool_nofail $POOL
1174     create_pool_nofail $POOL2
1175
1176     add_pool $POOL $TGT_HALF "$TGT_UUID2"
1177
1178     local start=$(printf %04x $((TGT_FIRST + 1)))
1179     TGT=$(for i in $(seq 0x$start 2 0x$TGT_MAX); do \
1180           printf "$FSNAME-OST%04x_UUID " $i; done)
1181     add_pool $POOL2 "$FSNAME-OST[$start-$TGT_MAX/2]" "$TGT"
1182
1183     create_dir $dir1 $POOL
1184     create_file $dir1/file1 $POOL2
1185     create_dir $dir2 $POOL2
1186     touch $dir2/file2
1187     mkdir $dir3
1188     $SETSTRIPE -c 1 $dir3 # No pool assignment
1189     touch $dir3/file3
1190     $SETSTRIPE -c 1 $dir2/file4 # No pool assignment
1191
1192     check_file_in_pool $dir1/file1 $POOL2
1193     check_file_in_pool $dir2/file2 $POOL2
1194
1195     check_dir_not_in_pool $dir3 $POOL
1196     check_dir_not_in_pool $dir3 $POOL2
1197
1198     check_file_not_in_pool $dir3/file3 $POOL
1199     check_file_not_in_pool $dir3/file3 $POOL2
1200
1201     check_file_not_in_pool $dir2/file4 $POOL
1202     check_file_not_in_pool $dir2/file4 $POOL2
1203
1204     rm -rf $dir1
1205
1206     return 0
1207 }
1208 run_test 20 "Different pools in a directory hierarchy."
1209
1210 test_21() {
1211     set_cleanup_trap
1212     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1213     [[ $OSTCOUNT -le 1 ]] && skip_env "Need at least 2 OSTs" && return
1214
1215     local numfiles=12
1216     local i=0
1217     local dir=$POOL_ROOT/dir
1218
1219     create_pool_nofail $POOL
1220
1221     add_pool $POOL $TGT_HALF "$TGT_UUID2"
1222
1223     create_dir $dir $POOL $OSTCOUNT
1224     create_file $dir/file1 $POOL $OSTCOUNT
1225     $GETSTRIPE -v $dir/file1
1226     check_file_in_pool $dir/file1 $POOL
1227
1228     rm -rf $dir
1229
1230     return 0
1231 }
1232 run_test 21 "OST pool with fewer OSTs than stripe count"
1233
1234 add_loop() {
1235         local pool=$1
1236         local step=$2
1237
1238         echo loop for $pool
1239
1240         for c in $(seq 1 10); do
1241                 echo "Pool $pool, iteration $c"
1242                 do_facet mgs lctl pool_add $FSNAME.$pool \
1243                         OST[$TGT_FIRST-$TGT_MAX/$step] 2>/dev/null
1244                 local TGT_SECOND=$(printf %04x $((TGT_FIRST + $step)))
1245                 if [ $((16#$TGT_SECOND)) -le $((16#$TGT_MAX)) ]; then
1246                 do_facet mgs lctl pool_remove $FSNAME.$pool \
1247                         OST[$TGT_SECOND-$TGT_MAX/$step]
1248                 fi
1249         done
1250         echo loop for $pool complete
1251 }
1252
1253 test_22() {
1254     set_cleanup_trap
1255     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1256     [[ $OSTCOUNT -le 1 ]] && skip_env "Need at least 2 OSTs" && return
1257
1258     local numfiles=100
1259
1260     create_pool_nofail $POOL
1261     add_pool $POOL "OST0000" "$FSNAME-OST0000_UUID "
1262     create_pool_nofail $POOL2
1263     add_pool $POOL2 "OST0000" "$FSNAME-OST0000_UUID "
1264
1265     add_loop $POOL 1 &
1266     add_loop $POOL2 2 &
1267     sleep 5
1268     create_dir $POOL_ROOT $POOL
1269     createmany -o $POOL_ROOT/${tfile} $numfiles ||
1270         error "createmany $POOL_ROOT/${tfile} failed!"
1271     wait
1272
1273     return 0
1274 }
1275 run_test 22 "Simultaneous manipulation of a pool"
1276
1277 test_23a() {
1278     set_cleanup_trap
1279     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1280     [[ $OSTCOUNT -le 1 ]] && skip_env "Need at least 2 OSTs" && return
1281
1282     mkdir -p $POOL_ROOT
1283     check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS || {
1284         skip_env "User $RUNAS_ID does not exist - skipping"
1285         return 0
1286     }
1287
1288     local i=0
1289     local TGT
1290     local BUNIT_SZ=1024  # min block quota unit(kB)
1291     local LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1)))
1292     local dir=$POOL_ROOT/dir
1293     local file="$dir/$tfile-quota"
1294
1295     create_pool_nofail $POOL
1296
1297     local TGT=$(for i in $(seq 0x$TGT_FIRST 3 0x$TGT_MAX); do \
1298                 printf "$FSNAME-OST%04x_UUID " $i; done)
1299     add_pool $POOL "$FSNAME-OST[$TGT_FIRST-$TGT_MAX/3]" "$TGT"
1300     create_dir $dir $POOL
1301
1302         # XXX remove the interoperability code once we drop the old server
1303         #     ( < 2.3.50) support.
1304         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1305                 $LFS quotaoff -ug $MOUNT
1306                 $LFS quotacheck -ug $MOUNT
1307         else
1308                 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=ug
1309                 sleep 5
1310         fi
1311
1312     $LFS setquota -u $RUNAS_ID -b $LIMIT -B $LIMIT $dir
1313     sleep 3
1314     $LFS quota -v -u $RUNAS_ID $dir
1315
1316     $SETSTRIPE -c 1 -p $POOL $file
1317     chown $RUNAS_ID.$RUNAS_GID $file
1318     ls -l $file
1319
1320     # This does two "dd" runs to ensure that the quota failure is returned
1321     # to userspace when we check.  The first "dd" might otherwise complete
1322     # without error if it is only writing into cache.
1323     stat=$(LOCALE=C $RUNAS dd if=/dev/zero of=$file bs=$BUNIT_SZ \
1324            count=$((BUNIT_SZ*2)) 2>&1)
1325     echo $stat | grep "Disk quota exceeded" > /dev/null
1326     if [ $? -eq 0 ]; then
1327         $LFS quota -v -u $RUNAS_ID $dir
1328         cancel_lru_locks osc
1329         stat=$(LOCALE=C $RUNAS dd if=/dev/zero of=$file bs=$BUNIT_SZ \
1330                count=$BUNIT_SZ seek=$((BUNIT_SZ*2)) 2>&1)
1331         RC=$?
1332         echo $stat
1333         [[ $RC -eq 0 ]] && error "second dd did not fail."
1334         echo $stat | grep "Disk quota exceeded" > /dev/null
1335         [[ $? -eq 1 ]] && error "second dd did not fail with EDQUOT."
1336     else
1337         log "first dd failed with EDQUOT."
1338     fi
1339     $LFS quota -v -u $RUNAS_ID $dir
1340 }
1341 run_test 23a "OST pools and quota"
1342
1343 test_23b() {
1344     set_cleanup_trap
1345     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1346     [[ $OSTCOUNT -le 1 ]] && skip_env "Need at least 2 OSTs" && return 0
1347
1348     mkdir -p $POOL_ROOT
1349     check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS || {
1350         skip_env "User $RUNAS_ID does not exist - skipping"
1351         return 0
1352     }
1353
1354     local i=0
1355     local TGT
1356     local dir=$POOL_ROOT/dir
1357     local file="$dir/$tfile-quota"
1358
1359     create_pool_nofail $POOL
1360
1361     local TGT=$(for i in $(seq 0x$TGT_FIRST 3 0x$TGT_MAX); do \
1362                 printf "$FSNAME-OST%04x_UUID " $i; done)
1363     add_pool $POOL "$FSNAME-OST[$TGT_FIRST-$TGT_MAX/3]" "$TGT"
1364     create_dir $dir $POOL
1365
1366         local maxfree=$((1024 * 1024 * 30)) # 30G
1367         local AVAIL=$(lfs_df -p $POOL $dir | awk '/summary/ { print $4 }')
1368         [ $AVAIL -gt $maxfree ] &&
1369                 skip_env "Filesystem space $AVAIL is larger than " \
1370                         "$maxfree limit" && return 0
1371
1372         echo "OSTCOUNT=$OSTCOUNT, OSTSIZE=$OSTSIZE, AVAIL=$AVAIL"
1373         echo "MAXFREE=$maxfree, SLOW=$SLOW"
1374
1375         # XXX remove the interoperability code once we drop the old server
1376         #     ( < 2.3.50) support.
1377         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ]; then
1378                 $LFS quotaoff -ug $MOUNT
1379         else
1380                 do_facet mgs $LCTL conf_param $FSNAME.quota.ost=none
1381                 sleep 5
1382         fi
1383
1384         chown $RUNAS_ID.$RUNAS_ID $dir
1385         i=0
1386         local RC=0
1387         local TOTAL=0 # KB
1388         local stime=$(date +%s)
1389         local stat
1390         local etime
1391         local elapsed
1392         local maxtime=300 # minimum speed: 5GB / 300sec ~= 17MB/s
1393         while [ $RC -eq 0 ]; do
1394                 i=$((i + 1))
1395                 stat=$(LOCALE=C $RUNAS2 dd if=/dev/zero of=${file}$i bs=1M \
1396                         count=$((5 * 1024)) 2>&1)
1397                 RC=$?
1398                 TOTAL=$((TOTAL + 1024 * 1024 * 5))
1399                 echo "[$i iteration] $stat"
1400                 echo "total written: $TOTAL"
1401
1402                 etime=$(date +%s)
1403                 elapsed=$((etime - stime))
1404                 echo "stime=$stime, etime=$etime, elapsed=$elapsed"
1405
1406                 if [ $RC -eq 1 ]; then
1407                         echo $stat | grep -q "Disk quota exceeded"
1408                         [[ $? -eq 0 ]] &&
1409                                 error "dd failed with EDQUOT with quota off"
1410
1411                         echo $stat | grep -q "No space left on device"
1412                         [[ $? -ne 0 ]] &&
1413                                 error "dd did not fail with ENOSPC"
1414                 elif [ $TOTAL -gt $AVAIL ]; then
1415                         error "dd didn't fail with ENOSPC ($TOTAL > $AVAIL)"
1416                 elif [ $i -eq 1 -a $elapsed -gt $maxtime ]; then
1417                         log "The first 5G write used $elapsed (> $maxtime) " \
1418                                 "seconds, terminated"
1419                         RC=1
1420                 fi
1421         done
1422
1423         df -h
1424         rm -rf $POOL_ROOT
1425 }
1426 run_test 23b "OST pools and OOS"
1427
1428 test_24() {
1429     set_cleanup_trap
1430     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1431     [[ $OSTCOUNT -le 1 ]] && skip_env "Need at least 2 OSTs" && return
1432
1433     local numfiles=10
1434     local i=0
1435     local TGT
1436     local dir
1437     local res
1438
1439     create_pool_nofail $POOL
1440
1441     add_pool $POOL $TGT_ALL "$TGT_UUID"
1442
1443     create_dir $POOL_ROOT/dir1 $POOL $OSTCOUNT
1444
1445     mkdir $POOL_ROOT/dir2
1446     $SETSTRIPE -p $POOL -S 65536 -i 0 -c 1 $POOL_ROOT/dir2 ||
1447         error "$SETSTRIPE $POOL_ROOT/dir2 failed"
1448
1449     mkdir $POOL_ROOT/dir3
1450     $SETSTRIPE -S 65536 -i 0 -c 1 $POOL_ROOT/dir3 ||
1451         error "$SETSTRIPE $POOL_ROOT/dir3 failed"
1452
1453     mkdir $POOL_ROOT/dir4
1454
1455     for i in 1 2 3 4; do
1456         dir=${POOL_ROOT}/dir${i}
1457         local pool
1458         local pool1
1459         local count
1460         local count1
1461         local index
1462         local size
1463         local size1
1464
1465         createmany -o $dir/${tfile} $numfiles ||
1466             error "createmany $dir/${tfile} failed!"
1467         res=$($GETSTRIPE -v $dir | grep "^stripe_count:")
1468         if [ $? -ne 0 ]; then
1469             res=$($GETSTRIPE -v $dir | grep "^(Default) ")
1470             pool=$(cut -f 9 -d ' ' <<< $res)
1471             index=$(cut -f 7 -d ' ' <<< $res)
1472             size=$(cut -f 5 -d ' ' <<< $res)
1473             count=$(cut -f 3 -d ' ' <<< $res)
1474         else
1475             pool=$(cut -f 8 -d ' ' <<< $res)
1476             index=$(cut -f 6 -d ' ' <<< $res)
1477             size=$(cut -f 4 -d ' ' <<< $res)
1478             count=$(cut -f 2 -d ' ' <<< $res)
1479         fi
1480
1481         for file in $dir/*; do
1482             if [ "$pool" != "" ]; then
1483                 check_file_in_pool $file $pool
1484             fi
1485             pool1=$(file_pool $file)
1486             count1=$($GETSTRIPE -v $file | grep "^lmm_stripe_count:" |
1487                      tr -d '[:blank:]' | cut -f 2 -d ':')
1488             size1=$($GETSTRIPE -v $file | grep "^lmm_stripe_size:" |
1489                     tr -d '[:blank:]' | cut -f 2 -d ':')
1490             [[ "$pool" != "$pool1" ]] &&
1491                 error "Pool name ($pool) not inherited in $file($pool1)"
1492             [[ "$count" != "$count1" ]] &&
1493                 error "Stripe count ($count) not inherited in $file ($count1)"
1494             [[ "$size" != "$size1" ]] && [[ "$size" != "0" ]] &&
1495                 error "Stripe size ($size) not inherited in $file ($size1)"
1496         done
1497     done
1498
1499     rm -rf $POOL_ROOT
1500
1501     return 0
1502 }
1503 run_test 24 "Independence of pool from other setstripe parameters"
1504
1505 test_25() {
1506         set_cleanup_trap
1507         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1508
1509         mkdir -p $POOL_ROOT
1510
1511         for i in $(seq 10); do
1512                 create_pool_nofail $POOL$i
1513                 do_facet mgs "lctl pool_add $FSNAME.$POOL$i OST0000; sync"
1514                 wait_update $HOSTNAME "lctl get_param -n \
1515                         lov.$FSNAME-*.pools.$POOL$i | sort -u |
1516                         tr '\n' ' ' " "$FSNAME-OST0000_UUID " >/dev/null ||
1517                                 error "pool_add failed: $1; $2"
1518
1519                 facet_failover $SINGLEMDS ||
1520                         error "failed to failover $SINGLEMDS"
1521                 wait_osc_import_state $SINGLEMDS ost FULL
1522                 clients_up
1523
1524                 wait_mds_ost_sync
1525                 # Veriy that the pool got created and is usable
1526                 df $POOL_ROOT > /dev/null
1527                 sleep 5
1528                 # Make sure OST0 can be striped on
1529                 $SETSTRIPE -i 0 -c 1 $POOL_ROOT/$tfile
1530                 STR=$($GETSTRIPE $POOL_ROOT/$tfile | grep 0x |
1531                         cut -f2 | tr -d " ")
1532                 rm $POOL_ROOT/$tfile
1533                 if [[ "$STR" == "0" ]]; then
1534                         echo "Creating a file in pool$i"
1535                         create_file $POOL_ROOT/file$i $POOL$i || break
1536                         check_file_in_pool $POOL_ROOT/file$i $POOL$i || break
1537                 else
1538                         echo "OST 0 seems to be unavailable.  Try later."
1539                 fi
1540         done
1541
1542         rm -rf $POOL_ROOT
1543 }
1544 run_test 25 "Create new pool and restart MDS"
1545
1546 test_26() {
1547         [[ $OSTCOUNT -le 2 ]] && skip_env "Need at least 3 OSTs" && return
1548         set_cleanup_trap
1549         local dev=$(mdsdevname ${SINGLEMDS//mds/})
1550         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1551
1552         mkdir -p $POOL_ROOT
1553
1554         create_pool_nofail $POOL2
1555
1556         do_facet mgs "lctl pool_add $FSNAME.$POOL2 OST0000; sync"
1557         wait_update $HOSTNAME "lctl get_param -n \
1558                 lov.$FSNAME-*.pools.$POOL2 | sort -u |
1559                 grep $FSNAME-OST0000_UUID " "$FSNAME-OST0000_UUID" ||
1560                         error "pool_add failed: $1; $2"
1561
1562         do_facet mgs "lctl pool_add $FSNAME.$POOL2 OST0002; sync"
1563         wait_update $HOSTNAME "lctl get_param -n \
1564                 lov.$FSNAME-*.pools.$POOL2 | sort -u |
1565                 grep $FSNAME-OST0002_UUID" "$FSNAME-OST0002_UUID" ||
1566                         error "pool_add failed: $1; $2"
1567
1568         # Veriy that the pool got created and is usable
1569         df $POOL_ROOT
1570         echo "Creating files in $POOL2"
1571
1572         for ((i = 0; i < 10; i++)); do
1573                 #OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
1574                 #Fail OST0000 to ensure objects create on
1575                 #the other OST in the pool
1576                 do_facet $SINGLEMDS lctl set_param fail_loc=0x147
1577                 do_facet $SINGLEMDS lctl set_param fail_val=0
1578                 create_file $POOL_ROOT/file$i $POOL2 1 -1 || break
1579                 do_facet $SINGLEMDS lctl set_param fail_loc=0
1580                 check_file_in_pool $POOL_ROOT/file$i $POOL2 || break
1581         done
1582         rm -rf $POOL_ROOT
1583 }
1584 run_test 26 "Choose other OSTs in the pool first in the creation remedy"
1585
1586 cd $ORIG_PWD
1587
1588 complete $SECONDS
1589 cleanup_pools $FSNAME
1590 check_and_cleanup_lustre
1591 exit_status