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