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