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