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