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