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