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