Whamcloud - gitweb
LU-17744 ldiskfs: mballoc stats fixes
[fs/lustre-release.git] / lustre / tests / ost-pools.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6
7 ONLY=${ONLY:-"$*"}
8 ORIG_PWD=${PWD}
9
10 LUSTRE=${LUSTRE:-$(dirname $0)/..}
11 . $LUSTRE/tests/test-framework.sh
12 init_test_env "$@"
13 init_logging
14
15 ALWAYS_EXCEPT="$OST_POOLS_EXCEPT"
16 # bug number for skipped test: -
17 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18
19 build_test_filter
20
21 check_and_setup_lustre
22
23 if ! combined_mgs_mds; then
24         do_facet mgs "mkdir -p $MOUNT"
25         zconf_mount $mgs_HOST $MOUNT $MOUNT_OPTS ||
26                 error "unable to mount $MOUNT on the MGS"
27 fi
28
29 DIR=${DIR:-$MOUNT}
30 assert_DIR
31
32 MAXFREE=${MAXFREE:-$((2000000 * OSTCOUNT))}
33
34 # OST pools tests
35 POOL=testpool
36 POOL2=${POOL2:-${POOL}2}
37 POOL3=${POOL3:-${POOL}3}
38 NON_EXISTANT_POOL=nonexistantpool
39 NON_EXISTANT_FS=nonexistantfs
40 INVALID_POOL=some_invalid_pool_name
41 TGT_COUNT=$OSTCOUNT
42 TGT_FIRST=$(printf %04x 0)
43 TGT_MAX=$(printf %04x $((TGT_COUNT-1)))
44 TGT_STEP=1
45 TGT_LIST=$(seq 0x$TGT_FIRST $TGT_STEP 0x$TGT_MAX)
46 TGT_LIST2=$(seq 0x$TGT_FIRST 2 0x$TGT_MAX)
47
48 TGT_ALL="$FSNAME-OST[$TGT_FIRST-$TGT_MAX/1]"
49 TGT_HALF="$FSNAME-OST[$TGT_FIRST-$TGT_MAX/2]"
50
51 TGT_UUID=$(for i in $TGT_LIST; do printf "$FSNAME-OST%04x_UUID " $i; done)
52 TGT_UUID2=$(for i in $TGT_LIST2; do printf "$FSNAME-OST%04x_UUID " $i; done)
53
54 create_dir() {
55         local dir=$1
56         local pool=$2
57         local count=${3:-"-1"}
58         local idx=$4
59
60         mkdir -p $dir
61         if [[ -n $idx ]]; then
62                 $LFS setstripe -c $count -p $pool -i $idx $dir
63         else
64                 $LFS setstripe -c $count -p $pool -i -1 $dir
65         fi
66         [[ $? -eq 0 ]] || error "$LFS setstripe -p $pool $dir failed"
67         [[ "$($LFS getstripe --pool $dir)" == "$pool" ]] ||
68                 error "$dir not created in expected pool '$pool'"
69 }
70
71 create_file() {
72         local file=$1
73         local pool=$2
74         local count=${3:-"-1"}
75         local index=${4:-"-1"}
76         rm -f $file
77         $LFS setstripe -i $index -c $count -p $pool $file
78         [[ $? -eq 0 ]] || error "$LFS setstripe -p $pool $file failed"
79         [[ "$($LFS getstripe --pool $file)" == "$pool" ]] ||
80                 error "$file not created in '$pool'"
81 }
82
83 osts_in_pool() {
84         local pool=$1
85         local res
86         for i in $(list_pool $FSNAME.$pool |
87                 sed -e 's/_UUID$//;s/^.*-OST//'); do
88                 res="$res $(printf "%d" 0x$i)"
89         done
90         echo $res
91 }
92
93 check_dir_in_pool() {
94         local dir=$1
95         local pool=$2
96         local res=$($LFS getstripe --pool $dir)
97
98         [ -n "$res" ] || error "dir '$dir' not in any pool"
99
100         [ "$res" == "$pool" ] ||
101                 error "dir '$dir' in pool '$res' instead of '$pool'"
102 }
103
104 check_file_in_pool() {
105         local file="$1"
106         local pool=$2
107         local count=$3
108         local osts=$(osts_in_pool $pool)
109         local res=$($LFS getstripe --pool $file)
110
111         [ -n "$res" ] || error "file '$file' not in any pool"
112
113         [ "$res" == "$pool" ] ||
114                 error "file '$file' in pool '$res' instead of '$pool'"
115
116         local osts=$(osts_in_pool $2)
117         check_file_in_osts "$file" "$osts" $count
118 }
119
120 check_file_in_osts() {
121         local file=$1
122         local ost_list=${2:-$TGT_LIST}
123         local count=$3
124         local res=$($LFS getstripe $file | awk '/0x/ { print $1 }')
125         local i
126
127         for i in $res; do
128                 found=$(echo :$ost_list: | tr " " ":" | grep :$i:)
129                 if [[ "$found" == "" ]]; then
130                         echo "ost list: $ost_list"
131                         echo "striping: $res"
132                         $LFS getstripe -v $file
133                         error "$file not allocated from OSTs $ost_list."
134                 fi
135         done
136
137         local ost_count=$($LFS getstripe -c $file)
138         [[ -n "$count" ]] && [[ $ost_count -ne $count ]] &&
139                 error "$file stripe count $count expected; got $ost_count" &&
140                 return 1
141
142 }
143
144 check_file_not_in_pool() {
145         local file=$1
146         local pool=$2
147         local res=$($LFS getstripe --pool $file)
148
149         [ "$res" != "$pool" ] || error "File '$file' is in pool: $res"
150 }
151
152 check_dir_not_in_pool() {
153         local dir=$1
154         local pool=$2
155         local res=$($LFS getstripe --pool $dir)
156
157         [ "$res" != "$pool" ] || error "Dir '$dir' is in pool: $res"
158 }
159
160 drain_pool() {
161     pool=$1
162     wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool" "" ||
163         error "Failed to remove targets from pool: $pool"
164 }
165
166 add_pool() {
167         local pool=$1
168         local osts=$2
169         local tgt="${3}$(lctl get_param -n lov.$FSNAME-*.pools.$pool |
170                 sort -u | tr '\n' ' ')"
171
172         do_facet mgs lctl pool_add $FSNAME.$pool $osts
173         local RC=$?
174         [[ $RC -ne 0 ]] && return $RC
175
176         # wait for OSTs to be added to the pool
177         for mds_id in $(seq $MDSCOUNT); do
178                 local mdt_id=$((mds_id-1))
179                 local lodname=$FSNAME-MDT$(printf "%04x" $mdt_id)-mdtlov
180                 wait_update_facet mds$mds_id \
181                         "lctl get_param -n lod.$lodname.pools.$pool |
182                                 sort -u | tr '\n' ' ' " "$tgt" >/dev/null ||
183                         error "mds$mds_id:pool add failed $1; $2"
184         done
185         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool |
186                 sort -u | tr '\n' ' ' " "$tgt" >/dev/null ||
187                 error "pool_add failed: $1; $2"
188         return $RC
189 }
190
191 create_pool_nofail() {
192         create_pool $FSNAME.$1
193         [[ $? -ne 0 ]] && error "Pool creation of $1 failed"
194         return 0
195 }
196
197 create_pool_fail() {
198         create_pool $FSNAME.$1
199         [[ $? -ne 0 ]] ||
200                 error "Pool creation of $1 succeeded; should have failed"
201         return 0
202 }
203
204 ost_pools_init() {
205         destroy_test_pools
206 }
207
208 # Initialization
209 remote_mds_nodsh && skip "remote MDS with nodsh"
210 remote_ost_nodsh && skip "remote OST with nodsh"
211 ost_pools_init
212 # reset root directory's stripe offset
213 $LFS getstripe -d $MOUNT
214 save_layout_restore_at_exit $MOUNT
215 $LFS setstripe -i -1 $MOUNT
216
217 # Tests for new commands added
218 test_1a() {
219         create_pool_nofail p
220         destroy_pool p
221 }
222 run_test 1a "Create a pool with a 1 character pool name"
223
224 test_1b() {
225         create_pool_nofail ${POOL}12
226         destroy_pool ${POOL}12
227 }
228 run_test 1b "Create a pool with a 10 char pool name"
229
230 test_1c() {
231         create_pool_nofail ${POOL}1234567
232         destroy_pool ${POOL}1234567
233 }
234 run_test 1c "Create a pool with a 15 char pool name"
235
236 test_1d() {
237         create_pool_fail ${POOL}12345678
238 }
239 run_test 1d "Create a pool with a 16 char pool name; should fail"
240
241 test_1e() {
242         local pool_name="$POOL"
243         for ((i = 1; i <= 991; i++)); do pool_name=${pool_name}"o"; done
244         create_pool_fail $pool_name
245 }
246 run_test 1e "Create a pool with a 1000 char pool name; should fail"
247
248 test_1f() {
249         create_pool .$POOL
250         [[ $? -ne 0 ]] ||
251                 error "pool_new did not fail even though fs-name was missing"
252 }
253 run_test 1f "pool_new should fail if fs-name is missing"
254
255 test_1g() {
256         create_pool $POOL
257         [[ $? -ne 0 ]] ||
258                 error "pool_new did not fail even though fs-name was missing"
259 }
260 run_test 1g "pool_new should fail if fs-name is missing"
261
262 test_1h() {
263         create_pool ${FSNAME}.
264         [[ $? -ne 0 ]] ||
265                 error "pool_new did not fail even though pool name was missing"
266 }
267 run_test 1h "pool_new should fail if poolname is missing"
268
269 test_1i() {
270         create_pool .
271         [[ $? -ne 0 ]] ||
272                 error "pool_new did not fail even if pool/fs-name was missing"
273 }
274 run_test 1i "pool_new should fail if poolname and fs-name are missing"
275
276 test_1j() {
277         do_facet mgs lctl pool_new ${FSNAME},$POOL
278         [[ $? -ne 0 ]] ||
279                 error "pool_new did not fail even if poolname format was wrong"
280 }
281 run_test 1j "pool_new should fail if poolname format is wrong"
282
283 test_1k() {
284         do_facet mgs lctl pool_new ${FSNAME}/$POOL
285         [[ $? -ne 0 ]] ||
286                 error "pool_new did not fail even if poolname format was wrong"
287 }
288 run_test 1k "pool_new should fail if poolname format is wrong"
289
290 test_1m() {
291         create_pool_nofail $POOL2
292         create_pool ${FSNAME}.$POOL2
293         [[ $? -ne 0 ]] ||
294                 error "pool_new did not fail even though $POOL2 existed"
295         destroy_pool $POOL2
296 }
297 run_test 1m "pool_new did not fail even though $POOL2 existed"
298
299 test_1n() {
300         create_pool_nofail ${POOL}1234567
301
302         add_pool ${POOL}1234567 "OST0000" "$FSNAME-OST0000_UUID "
303         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
304         create_dir $POOL_ROOT ${POOL}1234567
305         stack_trap "rm -f $POOL_ROOT/file"
306         dd if=/dev/zero of=$POOL_ROOT/file bs=1M count=100
307         RC=$?; [[ $RC -eq 0 ]] ||
308                 error "failed to write to $POOL_ROOT/file: $RC"
309         do_facet mgs lctl pool_remove $FSNAME.${POOL}1234567 OST0000
310         drain_pool ${POOL}1234567
311
312         destroy_pool ${POOL}1234567
313 }
314 run_test 1n "Pool with a 15 char pool name works well"
315
316 test_2a() {
317         destroy_pool $POOL
318
319         do_facet mgs lctl pool_add $FSNAME.$POOL $FSNAME-OST0000 2>/dev/null
320         [[ $? -ne 0 ]] ||
321                 error "pool_add did not fail even though $POOL did not exist"
322 }
323 run_test 2a "pool_add: non-existant pool $POOL"
324
325 test_2b() {
326         do_facet mgs lctl pool_add $FSNAME.${POOL}1234567890 \
327                 $FSNAME-OST0000 2>/dev/null
328         [[ $? -ne 0 ]] ||
329                 error "pool_add did not fail even though pool name was invalid."
330 }
331 run_test 2b "pool_add: Invalid pool name"
332
333 # Testing various combinations of OST name list
334 test_2c() {
335         local TGT
336         local RC
337
338         lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
339         [[ $? -ne 0 ]] || destroy_pool $POOL
340
341         create_pool_nofail $POOL
342
343         # 1. OST0000
344         do_facet mgs lctl pool_add $FSNAME.$POOL OST0000
345         RC=$?; [[ $RC -eq 0 ]] ||
346                 error "pool_add failed. $FSNAME $POOL OST0000: $RC"
347         do_facet mgs lctl pool_remove $FSNAME.$POOL OST0000
348         drain_pool $POOL
349
350         # 2. $FSNAME-OST0000
351         do_facet mgs lctl pool_add $FSNAME.$POOL $FSNAME-OST0000
352         RC=$?; [[ $RC -eq 0 ]] ||
353                 error "pool_add failed. $FSNAME $POOL $FSNAME-OST0000: $RC"
354         do_facet mgs lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000
355         drain_pool $POOL
356
357         # 3. $FSNAME-OST0000_UUID
358         do_facet mgs lctl pool_add $FSNAME.$POOL $FSNAME-OST0000_UUID
359         RC=$?; [[ $RC -eq 0 ]] ||
360                 error "pool_add failed. $FSNAME $POOL $FSNAME-OST0000_UUID: $RC"
361         do_facet mgs lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000_UUID
362         drain_pool $POOL
363
364         # 4. $FSNAME-OST[0,1,2,3,]
365         TGT="$FSNAME-OST["
366         for i in $TGT_LIST; do TGT=${TGT}$(printf "%04x," $i); done
367         TGT="${TGT}]"
368         do_facet mgs lctl pool_add $FSNAME.$POOL $TGT
369         [[ $? -eq 0 ]] || error "pool_add failed. $FSNAME.$POOL $TGT. $RC"
370         do_facet mgs lctl pool_remove $FSNAME.$POOL $TGT
371         drain_pool $POOL
372
373         # 5. $FSNAME-OST[0-5/1]
374         do_facet mgs lctl pool_add $FSNAME.$POOL $TGT_ALL
375         RC=$?; [[ $RC -eq 0 ]] ||
376                 error "pool_add failed. $FSNAME $POOL" "$TGT_ALL $RC"
377         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL |
378                 sort -u | tr '\n' ' ' " "$TGT_UUID" ||
379                         error "Add to pool failed"
380         do_facet mgs lctl pool_remove $FSNAME.$POOL $TGT_ALL
381         drain_pool $POOL
382
383         destroy_pool $POOL
384 }
385 run_test 2c "pool_add: OST index combinations"
386
387 test_2d() {
388         local TGT
389         local RC
390
391         lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
392         [[ $? -ne 0 ]] || destroy_pool $POOL
393
394         create_pool_nofail $POOL
395
396         TGT=$(printf "$FSNAME-OST%04x_UUID " $OSTCOUNT)
397         do_facet mgs lctl pool_add $FSNAME.$POOL $TGT
398         RC=$?; [[ $RC -ne 0 ]] ||
399                 error "pool_add succeeded for an OST ($TGT) that does not exist."
400
401         destroy_pool $POOL
402 }
403 run_test 2d "pool_add: OSTs that don't exist should be rejected"
404
405 test_2e() {
406         local TGT
407         local RC
408         local RESULT
409
410         $LCTL get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
411         [[ $? -ne 0 ]] || destroy_pool $POOL
412
413         create_pool_nofail $POOL
414
415         TGT="$FSNAME-OST0000_UUID"
416         do_facet mgs lctl pool_add $FSNAME.$POOL $TGT
417         wait_update_facet $SINGLEMDS \
418                 "lctl pool_list $FSNAME.$POOL | sed '1d'" "$TGT" ||
419                 error "Add $TGT to $FSNAME.$POOL failed"
420         RESULT=$(do_facet mgs \
421                 "LOCALE=C $LCTL pool_add $FSNAME.$POOL $TGT 2>&1")
422         RC=$?
423         echo $RESULT
424
425         [[ $RC -ne 0 ]] ||
426                 error "pool_add succeeded for an OST that was already in the pool."
427
428         [[ $(grep "already in pool" <<< $RESULT) ]] ||
429                 error "pool_add failed as expected but error message not as expected."
430
431         destroy_pool $POOL
432 }
433 run_test 2e "pool_add: OST already in a pool should be rejected"
434
435 test_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         i=1
928         while [[ $i -lt 10 ]]; do
929                 dd if=/dev/zero of=$POOL_ROOT/dir2/f${i} bs=1M count=$FILE_SIZE
930                 i=$((i + 1))
931         done
932         sleep 1 # get new statfs info
933         $LFS df $POOL_ROOT/dir2
934
935         # OST $TGT_FIRST is no longer favored; but it may still be used.
936         create_dir $POOL_ROOT/dir3 $POOL 1
937         create_file $POOL_ROOT/dir3/file $POOL 1
938         createmany -o $POOL_ROOT/dir3/$tfile- $numfiles ||
939                 error "createmany $POOL_ROOT/dir3/$tfile- failed!"
940         for file in $POOL_ROOT/dir3/*; do
941                 check_file_in_pool $file $POOL
942         done
943
944         rm -rf $POOL_ROOT
945
946         return 0
947 }
948 run_test 14 "Round robin and QOS striping within a pool"
949
950 test_15() {
951         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
952         local numfiles=100
953         local i=0
954
955         while [[ $i -lt $OSTCOUNT ]]; do
956                 create_pool_nofail $POOL${i}
957
958                 local tgt=$(printf "$FSNAME-OST%04x_UUID " $i)
959                 add_pool $POOL${i} "$FSNAME-OST[$(printf %04x $i)]" "$tgt"
960                 create_dir $POOL_ROOT/dir${i} $POOL${i}
961                 createmany -o $POOL_ROOT/dir$i/$tfile $numfiles ||
962                         error "createmany $POOL_ROOT/dir$i/$tfile failed!"
963
964                 for file in $POOL_ROOT/dir$i/*; do
965                         check_file_in_osts $file $i
966                 done
967
968                 i=$((i + 1))
969         done
970
971         return 0
972 }
973 run_test 15 "One directory per OST/pool"
974
975 test_16() {
976         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
977         local numfiles=10
978         local i=0
979
980         create_pool_nofail $POOL
981
982         add_pool $POOL $TGT_HALF "$TGT_UUID2"
983
984         local dir=$POOL_ROOT/$tdir
985         create_dir $dir $POOL
986
987         for i in $(seq 1 10); do
988                 dir=${dir}/dir${i}
989         done
990         mkdir -p $dir
991
992         createmany -o $dir/$tfile $numfiles ||
993                 error "createmany $dir/$tfile failed!"
994
995         for file in $dir/*; do
996                 check_file_in_pool $file $POOL
997         done
998
999         rm -rf $POOL_ROOT/$tdir
1000
1001         return 0
1002 }
1003 run_test 16 "Inheritance of pool properties"
1004
1005 test_17() {
1006         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1007         local numfiles=10
1008         local i=0
1009
1010         create_pool_nofail $POOL
1011
1012         add_pool $POOL $TGT_ALL "$TGT_UUID"
1013
1014         local dir=$POOL_ROOT/dir
1015         create_dir $dir $POOL
1016
1017         createmany -o $dir/${tfile}1_ $numfiles ||
1018                 error "createmany $dir/${tfile}1_ failed!"
1019
1020         for file in $dir/*; do
1021                 check_file_in_pool $file $POOL
1022         done
1023
1024         destroy_pool $POOL
1025
1026         createmany -o $dir/${tfile}2_ $numfiles ||
1027                 error "createmany $dir/${tfile}2_ failed!"
1028
1029         rm -rf $dir
1030         return 0
1031 }
1032 run_test 17 "Referencing an empty pool"
1033
1034 create_perf() {
1035         local cdir=$1/d
1036         local numsec=$2
1037
1038         mkdir -p $cdir
1039         sync
1040         wait_delete_completed >/dev/null # give pending IO chance to go to disk
1041         stat=$(createmany -o $cdir/${tfile} -t $numsec | tail -1)
1042         files=$(echo $stat | cut -f 2 -d ' ')
1043         echo $stat 1>&2
1044         unlinkmany $cdir/${tfile} $files > /dev/null
1045         sync
1046
1047         echo $files
1048 }
1049
1050 test_18() {
1051         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1052         local numsec=15
1053         local iter=3
1054         local plaindir=$POOL_ROOT/plaindir
1055         local pooldir=$POOL_ROOT/pooldir
1056         local f1=0
1057         local f2=0
1058         local f3=0
1059         local diff
1060
1061         for i in $(seq 1 $iter); do
1062                 echo "Create performance, iteration $i, $numsec seconds x 3"
1063
1064                 local files1=$(create_perf $plaindir $numsec)
1065                 [[ $files1 -eq 0 ]] && error "Zero files created without pool"
1066                 f1=$((f1 + files1))
1067                 echo "iter $i: $files1 creates without pool"
1068
1069                 create_pool_nofail $POOL > /dev/null
1070                 add_pool $POOL $TGT_ALL "$TGT_UUID" > /dev/null
1071                 create_dir $pooldir $POOL
1072                 local files2=$(create_perf $pooldir $numsec)
1073                 [[ $files2 -eq 0 ]] && error "Zero files created with pool"
1074                 f2=$((f2 + files2))
1075                 echo "iter $i: $files2 creates with pool"
1076
1077                 destroy_pool $POOL > /dev/null
1078                 local files3=$(create_perf $pooldir $numsec)
1079                 [[ $files3 -eq 0 ]] &&
1080                         error "Zero files created with missing pool"
1081                 f3=$((f3 + files3))
1082                 echo "iter $i: $files3 creates with missing pool"
1083
1084                 echo
1085         done
1086
1087         echo Avg files created in $numsec seconds without pool: $((f1 / iter))
1088         echo Avg files created in $numsec seconds with pool: $((f2 / iter))
1089         echo Avg files created in $numsec seconds missing pool: $((f3 / iter))
1090
1091         # Set this high until we establish a baseline for what the degradation
1092         # is / should be
1093         max=30
1094
1095         diff=$((($f1 - $f2) * 100 / $f1))
1096         echo  "No pool / wide pool: $diff %."
1097         [ $diff -gt $max ] &&
1098                 error_ignore bz23408 "Degradation with wide pool is $diff% > $max%"
1099
1100         max=30
1101         diff=$((($f1 - $f3) * 100 / $f1))
1102         echo  "No pool / missing pool: $diff %."
1103         [ $diff -gt $max ] &&
1104                 error_ignore bz23408 "Degradation with wide pool is $diff% > $max%"
1105
1106         return 0
1107 }
1108 run_test 18 "File create in a directory which references a deleted pool"
1109
1110 test_19() {
1111         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1112         local numfiles=12
1113         local dir1=$POOL_ROOT/dir1
1114         local dir2=$POOL_ROOT/dir2
1115         local i=0
1116
1117         create_pool_nofail $POOL
1118
1119         add_pool $POOL $TGT_HALF "$TGT_UUID2"
1120
1121         create_dir $dir1 $POOL
1122         createmany -o $dir1/${tfile} $numfiles ||
1123                 error "createmany $dir1/${tfile} failed!"
1124         for file in $dir1/*; do
1125                 check_file_in_pool $file $POOL
1126         done
1127
1128         mkdir -p $dir2
1129         createmany -o $dir2/${tfile} $numfiles ||
1130                 error "createmany $dir2/${tfile} failed!"
1131         for file in $dir2/*; do
1132                 check_file_not_in_pool $file $POOL
1133         done
1134
1135         rm -rf $dir1 $dir2
1136
1137         return 0
1138 }
1139 run_test 19 "Pools should not come into play when not specified"
1140
1141 test_20() {
1142         [[ $OSTCOUNT -ge 2 ]] || skip_env "needs >= 2 OSTs"
1143
1144         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1145         local numfiles=12
1146         local dir1=$POOL_ROOT/dir1
1147         local dir2=$dir1/dir2
1148         local dir3=$dir1/dir3
1149         local i=0
1150         local TGT
1151
1152         create_pool_nofail $POOL
1153         create_pool_nofail $POOL2
1154
1155         add_pool $POOL $TGT_HALF "$TGT_UUID2"
1156
1157         local start=$(printf %04x $((TGT_FIRST + 1)))
1158         TGT=$(for i in $(seq 0x$start 2 0x$TGT_MAX); do \
1159                 printf "$FSNAME-OST%04x_UUID " $i; done)
1160         add_pool $POOL2 "$FSNAME-OST[$start-$TGT_MAX/2]" "$TGT"
1161
1162         create_dir $dir1 $POOL
1163         create_file $dir1/file1 $POOL2  # Should replace $dir1 pool with $POOL2
1164         create_dir $dir2 $POOL2
1165         touch $dir2/file2               # Should inherit $POOL2 from $dir2
1166         mkdir $dir3                     # Should inherit $POOL from $dir1
1167         $LFS setstripe -c 1 $dir3       # Should remain existing $POOL
1168         touch $dir3/file3               # Should inherit $POOL from $dir3
1169         $LFS setstripe -c 1 $dir2/file4 # Should inherit $POOL2 from dir2
1170         $LFS setstripe -S 64K $dir1/file5 # Should inderit $POOL from $dir1
1171
1172         check_file_in_pool $dir1/file1 $POOL2
1173         check_file_in_pool $dir2/file2 $POOL2
1174         check_dir_not_in_pool $dir3 $POOL2
1175         check_file_not_in_pool $dir3/file3 $POOL2
1176         check_file_not_in_pool $dir2/file4 $POOL
1177         check_file_not_in_pool $dir1/file5 $POOL2
1178
1179         if [ "$MDS1_VERSION" -ge $(version_code 2.10.54) ]; then
1180                 check_dir_in_pool $dir3 $POOL
1181                 check_file_in_pool $dir3/file3 $POOL
1182                 check_file_in_pool $dir2/file4 $POOL2
1183                 check_file_in_pool $dir1/file5 $POOL
1184         fi
1185
1186         rm -rf $dir1
1187
1188         return 0
1189 }
1190 run_test 20 "Different pools in a directory hierarchy."
1191
1192 test_21() {
1193         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1194         [[ $OSTCOUNT -le 1 ]] && skip_env "needs >= 2 OSTs"
1195
1196         local numfiles=12
1197         local i=0
1198         local dir=$POOL_ROOT/dir
1199
1200         create_pool_nofail $POOL
1201
1202         add_pool $POOL $TGT_HALF "$TGT_UUID2"
1203
1204         create_dir $dir $POOL $OSTCOUNT
1205         create_file $dir/file1 $POOL $OSTCOUNT
1206         $LFS getstripe -v $dir/file1
1207         check_file_in_pool $dir/file1 $POOL
1208
1209         rm -rf $dir
1210
1211         return 0
1212 }
1213 run_test 21 "OST pool with fewer OSTs than stripe count"
1214
1215 add_loop() {
1216         local pool=$1
1217         local step=$2
1218
1219         echo loop for $pool
1220
1221         for c in $(seq 1 10); do
1222                 echo "Pool $pool, iteration $c"
1223                 do_facet mgs lctl pool_add $FSNAME.$pool \
1224                         OST[$TGT_FIRST-$TGT_MAX/$step] 2>/dev/null
1225                 local TGT_SECOND=$(printf %04x $((TGT_FIRST + $step)))
1226                 if [ $((16#$TGT_SECOND)) -le $((16#$TGT_MAX)) ]; then
1227                 do_facet mgs lctl pool_remove $FSNAME.$pool \
1228                         OST[$TGT_SECOND-$TGT_MAX/$step]
1229                 fi
1230         done
1231         echo loop for $pool complete
1232 }
1233
1234 test_22() {
1235         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1236         [[ $OSTCOUNT -le 1 ]] && skip_env "needs >= 2 OSTs"
1237
1238         local numfiles=100
1239
1240         create_pool_nofail $POOL
1241         add_pool $POOL "OST0000" "$FSNAME-OST0000_UUID "
1242         create_pool_nofail $POOL2
1243         add_pool $POOL2 "OST0000" "$FSNAME-OST0000_UUID "
1244
1245         add_loop $POOL 1 &
1246         add_loop $POOL2 2 &
1247         sleep 5
1248         create_dir $POOL_ROOT $POOL
1249         createmany -o $POOL_ROOT/${tfile} $numfiles ||
1250                 error "createmany $POOL_ROOT/${tfile} failed!"
1251         wait
1252
1253         return 0
1254 }
1255 run_test 22 "Simultaneous manipulation of a pool"
1256
1257 test_23a() {
1258         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1259         [[ $OSTCOUNT -le 1 ]] && skip_env "needs >= 2 OSTs"
1260
1261         mkdir -p $POOL_ROOT
1262         check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS ||
1263                 skip_env "User $RUNAS_ID does not exist - skipping"
1264
1265         local i=0
1266         local TGT
1267         local BUNIT_SZ=1024  # min block quota unit(kB)
1268         local LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1)))
1269         local dir=$POOL_ROOT/dir
1270         local file="$dir/$tfile-quota"
1271
1272         create_pool_nofail $POOL
1273
1274         local TGT=$(for i in $(seq 0x$TGT_FIRST 3 0x$TGT_MAX); do \
1275                 printf "$FSNAME-OST%04x_UUID " $i; done)
1276         add_pool $POOL "$FSNAME-OST[$TGT_FIRST-$TGT_MAX/3]" "$TGT"
1277         create_dir $dir $POOL
1278
1279         # XXX remove the interoperability code once we drop the old server
1280         #     ( < 2.3.50) support.
1281         if [ "$MDS1_VERSION" -lt $(version_code 2.3.50) ]; then
1282                 $LFS quotaoff -ug $MOUNT
1283                 $LFS quotacheck -ug $MOUNT
1284         else
1285                 if [[ $PERM_CMD == *"set_param -P"* ]]; then
1286                         do_facet mgs $PERM_CMD \
1287                                 osd-*.$FSNAME-OST*.quota_slave.enabled=ug
1288                 else
1289                         do_facet mgs $PERM_CMD $FSNAME.quota.ost=ug
1290                 fi
1291                 sleep 5
1292         fi
1293
1294         $LFS setquota -u $RUNAS_ID -b $LIMIT -B $LIMIT $dir
1295         sleep 3
1296         $LFS quota -v -u $RUNAS_ID $dir
1297
1298         $LFS setstripe -c 1 -p $POOL $file
1299         chown $RUNAS_ID.$RUNAS_GID $file
1300         ls -l $file
1301
1302         # This does two "dd" runs to ensure that the quota failure is returned
1303         # to userspace when we check.  The first "dd" might otherwise complete
1304         # without error if it is only writing into cache.
1305         stat=$(LOCALE=C $RUNAS dd if=/dev/zero of=$file bs=$BUNIT_SZ \
1306                 count=$((BUNIT_SZ*2)) 2>&1)
1307         echo $stat | grep "Disk quota exceeded" > /dev/null
1308         if [ $? -eq 0 ]; then
1309                 $LFS quota -v -u $RUNAS_ID $dir
1310                 cancel_lru_locks osc
1311                 stack_trap "rm -f $file"
1312                 stat=$(LOCALE=C $RUNAS dd if=/dev/zero of=$file bs=$BUNIT_SZ \
1313                         count=$BUNIT_SZ seek=$((BUNIT_SZ*2)) 2>&1)
1314                 RC=$?
1315                 echo $stat
1316                 [[ $RC -eq 0 ]] && error "second dd did not fail."
1317                 echo $stat | grep "Disk quota exceeded" > /dev/null
1318                 [[ $? -eq 1 ]] && error "second dd did not fail with EDQUOT."
1319         else
1320                 log "first dd failed with EDQUOT."
1321         fi
1322         $LFS quota -v -u $RUNAS_ID $dir
1323 }
1324 run_test 23a "OST pools and quota"
1325
1326 test_23b() {
1327         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1328         [[ $OSTCOUNT -le 1 ]] && skip_env "needs >= 2 OSTs"
1329
1330         mkdir -p $POOL_ROOT
1331         check_runas_id $RUNAS_ID $RUNAS_GID $RUNAS || {
1332                 skip_env "User $RUNAS_ID does not exist - skipping"
1333         }
1334
1335         local i=0
1336         local TGT
1337         local dir=$POOL_ROOT/dir
1338         local file="$dir/$tfile-quota"
1339
1340         create_pool_nofail $POOL
1341
1342         local TGT=$(for i in $(seq 0x$TGT_FIRST 3 0x$TGT_MAX); do \
1343                 printf "$FSNAME-OST%04x_UUID " $i; done)
1344         add_pool $POOL "$FSNAME-OST[$TGT_FIRST-$TGT_MAX/3]" "$TGT"
1345         create_dir $dir $POOL
1346
1347         local maxfree=$((1024 * 1024 * 30)) # 30G
1348         local AVAIL=$(lfs_df -p $POOL $dir | awk '/summary/ { print $4 }')
1349         [ $AVAIL -gt $maxfree ] &&
1350                 skip_env "Filesystem space $AVAIL is larger than " \
1351                         "$maxfree limit"
1352
1353         echo "OSTCOUNT=$OSTCOUNT, OSTSIZE=$OSTSIZE, AVAIL=$AVAIL"
1354         echo "MAXFREE=$maxfree, SLOW=$SLOW"
1355
1356         # XXX remove the interoperability code once we drop the old server
1357         #     ( < 2.3.50) support.
1358         if [ "$MDS1_VERSION" -lt $(version_code 2.3.50) ]; then
1359                 $LFS quotaoff -ug $MOUNT
1360         else
1361                 if [[ $PERM_CMD == *"set_param -P"* ]]; then
1362                         do_facet mgs $PERM_CMD \
1363                                 osd-*.$FSNAME-OST*.quota_slave.enabled=none
1364                 else
1365                         do_facet mgs $PERM_CMD $FSNAME.quota.ost=none
1366                 fi
1367                 sleep 5
1368         fi
1369
1370         chown $RUNAS_ID.$RUNAS_ID $dir
1371         i=0
1372         local RC=0
1373         local TOTAL=0 # KB
1374         local stime=$(date +%s)
1375         local stat
1376         local etime
1377         local elapsed
1378         local maxtime=300 # minimum speed: 5GB / 300sec ~= 17MB/s
1379         while [ $RC -eq 0 ]; do
1380                 i=$((i + 1))
1381                 stat=$(LOCALE=C $RUNAS2 dd if=/dev/zero of=${file}$i bs=1M \
1382                         count=$((5 * 1024)) 2>&1)
1383                 RC=$?
1384                 TOTAL=$((TOTAL + 1024 * 1024 * 5))
1385                 echo "[$i iteration] $stat"
1386                 echo "total written: $TOTAL"
1387
1388                 etime=$(date +%s)
1389                 elapsed=$((etime - stime))
1390                 echo "stime=$stime, etime=$etime, elapsed=$elapsed"
1391
1392                 if [ $RC -eq 1 ]; then
1393                         echo $stat | grep -q "Disk quota exceeded"
1394                         [[ $? -eq 0 ]] &&
1395                                 error "dd failed with EDQUOT with quota off"
1396
1397                         echo $stat | grep -q "No space left on device"
1398                         [[ $? -ne 0 ]] &&
1399                                 error "dd did not fail with ENOSPC"
1400                 elif [ $TOTAL -gt $AVAIL ]; then
1401                         error "dd didn't fail with ENOSPC ($TOTAL > $AVAIL)"
1402                 elif [ $i -eq 1 -a $elapsed -gt $maxtime ]; then
1403                         log "The first 5G write used $elapsed (> $maxtime) " \
1404                                 "seconds, terminated"
1405                         RC=1
1406                 fi
1407         done
1408
1409         df -h
1410         rm -rf $POOL_ROOT
1411 }
1412 run_test 23b "OST pools and OOS"
1413
1414 test_24() {
1415         [[ $OSTCOUNT -le 1 ]] && skip_env "needs >= 2 OSTs"
1416         [[ "$MDS1_VERSION" -ge $(version_code 2.8.56) ]] ||
1417                 skip "Need server version newer than 2.8.55"
1418
1419         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1420         local numfiles=10
1421         local i=0
1422         local TGT
1423         local dir
1424         local res
1425
1426         create_pool_nofail $POOL
1427
1428         add_pool $POOL $TGT_ALL "$TGT_UUID"
1429
1430         create_dir $POOL_ROOT/dir1 $POOL $OSTCOUNT
1431
1432         mkdir $POOL_ROOT/dir2
1433         $LFS setstripe -p $POOL -S 65536 -i 0 -c 1 $POOL_ROOT/dir2 ||
1434                 error "$LFS setstripe $POOL_ROOT/dir2 failed"
1435
1436         mkdir $POOL_ROOT/dir3
1437         $LFS setstripe -S 65536 -i 0 -c 1 $POOL_ROOT/dir3 ||
1438                 error "$LFS setstripe $POOL_ROOT/dir3 failed"
1439
1440         mkdir $POOL_ROOT/dir4
1441
1442         for i in 1 2 3 4; do
1443                 dir=${POOL_ROOT}/dir${i}
1444                 local pool
1445                 local pool1
1446                 local count
1447                 local count1
1448                 local index
1449                 local size
1450                 local size1
1451
1452                 createmany -o $dir/${tfile} $numfiles ||
1453                         error "createmany $dir/${tfile} failed!"
1454                 pool=$($LFS getstripe --pool $dir)
1455                 index=$($LFS getstripe -i $dir)
1456                 size=$($LFS getstripe -S $dir)
1457                 count=$($LFS getstripe -c $dir)
1458
1459                 for file in $dir/*; do
1460                         if [ "$pool" != "" ]; then
1461                                 check_file_in_pool $file $pool
1462                         fi
1463                         pool1=$($LFS getstripe --pool $file)
1464                         count1=$($LFS getstripe -c $file)
1465                         size1=$($LFS getstripe -S $file)
1466                         [[ "$pool" != "$pool1" ]] &&
1467                                 error "Pool '$pool' not on $file:$pool1"
1468                         [[ "$count" != "$count1" ]] &&
1469                                 [[ "$count" != "-1" ]] &&
1470                                         error "Stripe count $count not on"\
1471                                                 "$file:$count1"
1472                         [[ "$count1" != "$OSTCOUNT" ]] &&
1473                                 [[ "$count" = "-1" ]] &&
1474                                         error "Stripe count $count1 not on"\
1475                                                 "$file:$OSTCOUNT"
1476                         [[ "$size" != "$size1" ]] && [[ "$size" != "0" ]] &&
1477                                 error "Stripe size $size not on $file:$size1"
1478                 done
1479         done
1480
1481         rm -rf $POOL_ROOT
1482
1483         return 0
1484 }
1485 run_test 24 "Independence of pool from other setstripe parameters"
1486
1487 test_25() {
1488         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1489
1490         mkdir_on_mdt0 $POOL_ROOT
1491
1492         for i in $(seq 10); do
1493                 create_pool_nofail $POOL$i
1494                 do_facet mgs "lctl pool_add $FSNAME.$POOL$i OST0000; sync"
1495                 wait_update $HOSTNAME "lctl get_param -n \
1496                         lov.$FSNAME-*.pools.$POOL$i | sort -u |
1497                         tr '\n' ' ' " "$FSNAME-OST0000_UUID " >/dev/null ||
1498                                 error "pool_add failed: $1; $2"
1499
1500                 facet_failover $SINGLEMDS ||
1501                         error "failed to failover $SINGLEMDS"
1502                 wait_osc_import_state $SINGLEMDS ost FULL
1503                 clients_up
1504
1505                 wait_mds_ost_sync
1506                 # Veriy that the pool got created and is usable
1507                 df $POOL_ROOT > /dev/null
1508                 sleep 5
1509
1510                 # Make sure OST0 can be striped on
1511                 $LFS setstripe -i 0 -c 1 $POOL_ROOT/$tfile
1512                 local STR=$($LFS getstripe -i $POOL_ROOT/$tfile)
1513                 rm $POOL_ROOT/$tfile
1514                 if [[ "$STR" == "0" ]]; then
1515                         echo "Creating a file in pool$i"
1516                         create_file $POOL_ROOT/file$i $POOL$i || break
1517                         check_file_in_pool $POOL_ROOT/file$i $POOL$i || break
1518                 else
1519                         echo "OST 0 seems to be unavailable.  Try later."
1520                 fi
1521         done
1522
1523         rm -rf $POOL_ROOT
1524 }
1525 run_test 25 "Create new pool and restart MDS"
1526
1527 test_26() {
1528         [[ $OSTCOUNT -le 2 ]] && skip_env "needs >= 3 OSTs"
1529         local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1530
1531         mkdir -p $POOL_ROOT
1532
1533         create_pool_nofail $POOL2
1534
1535         do_facet mgs "lctl pool_add $FSNAME.$POOL2 OST0000; sync"
1536         wait_update $HOSTNAME "lctl get_param -n \
1537                 lov.$FSNAME-*.pools.$POOL2 | sort -u |
1538                 grep $FSNAME-OST0000_UUID " "$FSNAME-OST0000_UUID" ||
1539                         error "pool_add failed: $1; $2"
1540
1541         do_facet mgs "lctl pool_add $FSNAME.$POOL2 OST0002; sync"
1542         wait_update $HOSTNAME "lctl get_param -n \
1543                 lov.$FSNAME-*.pools.$POOL2 | sort -u |
1544                 grep $FSNAME-OST0002_UUID" "$FSNAME-OST0002_UUID" ||
1545                         error "pool_add failed: $1; $2"
1546
1547         # Veriy that the pool got created and is usable
1548         df $POOL_ROOT
1549         echo "Creating files in $POOL2"
1550
1551         for ((i = 0; i < 10; i++)); do
1552                 #OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147
1553                 #Fail OST0000 to ensure objects create on
1554                 #the other OST in the pool
1555                 do_facet $SINGLEMDS lctl set_param fail_loc=0x147
1556                 do_facet $SINGLEMDS lctl set_param fail_val=0
1557                 create_file $POOL_ROOT/file$i $POOL2 1 -1 || break
1558                 do_facet $SINGLEMDS lctl set_param fail_loc=0
1559                 check_file_in_pool $POOL_ROOT/file$i $POOL2 || break
1560         done
1561         rm -rf $POOL_ROOT
1562 }
1563 run_test 26 "Choose other OSTs in the pool first in the creation remedy"
1564
1565 test_27() {
1566         [[ $OSTCOUNT -le 1 ]] && skip_env "Need at least 2 OSTs"
1567
1568         local osts
1569         local pid
1570         local count=$OSTCOUNT
1571
1572         create_pool_nofail $POOL
1573         do_facet mgs lctl pool_add $FSNAME.$POOL $TGT_ALL
1574         wait_update_facet $SINGLEMDS \
1575                 "lctl pool_list $FSNAME.$POOL | wc -l" "$((OSTCOUNT + 1))" ||
1576                 error "MDS: pool_list $FSNAME.$POOL failed"
1577         osts=$(list_pool $FSNAME.$POOL)
1578         for ost in ${osts}; do
1579                 ((count--))
1580                 if [[ $count -eq 0 ]]; then
1581                         #define OBD_FAIL_OST_LIST_ASSERT    0x239
1582                         do_facet $SINGLEMDS \
1583                                 $LCTL set_param fail_loc=0x239 fail_val=10
1584                         list_pool $FSNAME.$POOL &
1585                         pid=$!
1586                         sleep 5
1587                         do_facet $SINGLEMDS $LCTL set_param fail_loc=0
1588                         do_facet mgs $LCTL pool_remove $FSNAME.$POOL $ost
1589                         wait $pid
1590                         do_facet $SINGLEMDS $LCTL set_param fail_val=0
1591                 else
1592                         do_facet mgs $LCTL pool_remove $FSNAME.$POOL $ost
1593                 fi
1594         done
1595         destroy_pool $POOL
1596 }
1597 run_test 27 "Race pool_list and pool_remove"
1598
1599 test_28() {
1600         create_pool_nofail $POOL
1601         create_pool_nofail $POOL2
1602         add_pool $POOL $TGT_ALL "$TGT_UUID"
1603         add_pool $POOL2 $TGT_ALL "$TGT_UUID"
1604
1605         start_full_debug_logging
1606         #$LFS setstripe -E 4M -c 1 -p $POOL -E 16M -c 2 $DIR/$tfile
1607         $LFS setstripe -c 1 -p $POOL $DIR/$tfile
1608         dd if=/dev/urandom of=$DIR/$tfile bs=1M count=1 seek=16
1609         local csum=$(cksum $DIR/$tfile)
1610         $LFS getstripe $DIR/$tfile
1611         local pool="$($LFS getstripe -p $DIR/$tfile)"
1612         [[ "$pool" == "$POOL" ]] ||
1613                 error "$tfile is in '$pool', not created on $POOL"
1614         $LFS_MIGRATE -y -p $POOL2 $DIR/$tfile ||
1615                 error "migrate $tfile to $POOL2 failed"
1616         $LFS getstripe $DIR/$tfile
1617         pool="$($LFS getstripe -p $DIR/$tfile)"
1618         [[ "$pool" == "$POOL2" ]] ||
1619                 error "$tfile is in '$pool', not migrated to $POOL2"
1620         local csum2=$(cksum $DIR/$tfile)
1621         [[ "$csum" == "$csum2" ]] || error "checksum error after migration"
1622         stop_full_debug_logging
1623 }
1624 run_test 28 "lfs_migrate with pool name"
1625
1626 fill_ost_pool_cnt=0
1627
1628 function fill_ost_pool() {
1629         local pool=$1
1630         local threshold=$2
1631         local tmpfile=$DIR/$tdir/$tfile-$pool-filler-$fill_ost_pool_cnt
1632
1633         mkdir -p $DIR/$tdir
1634         lfs setstripe $tmpfile -p $pool -c -1
1635
1636         local dfa=($(lfs_df -p $pool | grep _summary))
1637         local total=${dfa[1]}
1638         local used=${dfa[2]}
1639         local towrite=$(( (total * (threshold + 1) / 100) - used ))
1640
1641         echo "total $total, used $used, towrite $towrite"
1642         (( towrite > 0 )) && {
1643                 fallocate -l$((towrite * 1024)) $tmpfile ||
1644                         error "can't fallocate"
1645         }
1646         echo ">> filled to $threshold"
1647         ((fill_ost_pool_cnt++))
1648 }
1649
1650 test_29() {
1651         local pool1=${TESTNAME}-1
1652         local pool2=${TESTNAME}-2
1653         local mdts=$(comma_list $(mdts_nodes))
1654         local threshold=20
1655         local prefix="lod.$FSNAME-MDT0000-mdtlov.pool.$pool1"
1656         local cmd="$LCTL get_param -n $prefix"
1657         local before
1658         local after
1659
1660         (( $MDS1_VERSION >= $(version_code 2.14.53) )) ||
1661                 skip "Need MDS version at least 2.14.53"
1662         (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
1663         check_set_fallocate_or_skip
1664
1665         mkdir_on_mdt0 $DIR/$tdir
1666         stack_trap "rm -rf $DIR/$tdir"
1667         local delay=$(do_facet mds1 lctl get_param -n lo[vd].*.qos_maxage |
1668                       awk '{ print $1 * 2; exit; }')
1669
1670         pool_add $pool1 || error "Pool creation failed"
1671         pool_add_targets $pool1 0 1 || error "pool_add_targets failed"
1672
1673         pool_add $pool2 || error "Pool creation failed"
1674         pool_add_targets $pool2 2 3 || error "pool_add_targets failed"
1675
1676         do_facet mds1 $LCTL set_param $prefix.spill_target=$pool2
1677         do_facet mds1 $LCTL set_param $prefix.spill_threshold_pct=$threshold
1678         stack_trap "do_facet mds1 $LCTL set_param $prefix.spill_threshold_pct=0"
1679
1680         [[ $(do_facet mds1 "$cmd.spill_target" | uniq) == "$pool2" ]] ||
1681                 error "spill target wasn't set to $pool2"
1682         [[ $(do_facet mds1 "$cmd.spill_threshold_pct" | uniq) == "$threshold" ]] ||
1683                 error "spill threshold wasn't set"
1684         before=$(do_facet mds1 "$cmd.spill_hit")
1685         lfs_df -p $pool1 | grep summary
1686
1687         mkdir -p $DIR/$tdir
1688         stack_trap "rm -rf $DIR/$tdir"
1689         $LFS setstripe -p $pool1 $DIR/$tdir || error "can't set default layout"
1690
1691         echo "check status with empty $pool1"
1692         sleep $((delay + 1))
1693         [[ $(do_nodes $mdts $cmd.spill_is_active | uniq) == "0" ]] || {
1694                 do_nodes $mdts $cmd.spill_is_active
1695                 error "spilling on $pool1 is on"
1696         }
1697         touch $DIR/$tdir/$tfile-5
1698         [[ $($LFS getstripe -p $DIR/$tdir/$tfile-5) == "$pool1" ]] || {
1699                 $LFS getstripe $DIR/$tdir/$tfile-5
1700                 error "not old pool on $tfile-5"
1701         }
1702
1703         echo "check with non-empty $pool1"
1704         fill_ost_pool $pool1 $((threshold / 2))
1705         cancel_lru_locks osc
1706         sleep $((delay + 1))
1707         lfs_df -p $pool1 | grep summary
1708         [[ $(do_nodes $mdts $cmd.spill_is_active | uniq) == "0" ]] || {
1709                 do_nodes $mdts $cmd.spill_is_active
1710                 error "spilling on $pool1 is on"
1711         }
1712         touch $DIR/$tdir/$tfile-4
1713         [[ $($LFS getstripe -p $DIR/$tdir/$tfile-4) == "$pool1" ]] || {
1714                 $LFS getstripe $DIR/$tdir/$tfile-4
1715                 error "new pool on $tfile-4"
1716         }
1717
1718         fill_ost_pool $pool1 $threshold
1719         cancel_lru_locks osc
1720         sleep $((delay + 1))
1721         lfs_df -p $pool1 | grep summary
1722         [[ $(do_nodes $mdts $cmd.spill_is_active | uniq) == "1" ]] || {
1723                 do_nodes $mdts $cmd.spill_is_active
1724                 error "spilling on $pool1 is off"
1725         }
1726
1727         # in a directory with default striping
1728         $LFS setstripe -p $pool1 $DIR/$tdir || error "can't set default layout"
1729         touch $DIR/$tdir/$tfile-2
1730         [[ $($LFS getstripe -p $DIR/$tdir/$tfile-2) == "$pool2" ]] || {
1731                 $LFS getstripe $DIR/$tdir/$tfile-2
1732                 error "old pool on $tfile-2"
1733         }
1734         after=$(do_facet mds1 "$cmd.spill_hit")
1735         (( after == before + 1 )) || error "after $after != before $before + 1"
1736
1737         # when striping is specified explicitly
1738         $LFS setstripe -p $pool1 $DIR/$tdir/$tfile-3 || error "can't setstripe"
1739         touch $DIR/$tdir/$tfile-3
1740         [[ $($LFS getstripe -p $DIR/$tdir/$tfile-3) == "$pool2" ]] || {
1741                 $LFS getstripe $DIR/$tdir/$tfile-3
1742                 error "old pool on $tfile-3"
1743         }
1744         after=$(do_facet mds1 "$cmd.spill_hit")
1745         (( after == before + 2 )) || error "after $after != before $before + 2"
1746
1747         # spill is revalidated at object creation
1748         wait_update_facet mds1 "$cmd.spill_is_active" "1" ||
1749                 error "spilling is still inactive"
1750
1751         rm -f $DIR/$tdir/$tfile* || error "can't rm $DIR/$tfile*"
1752         wait_delete_completed
1753         sleep $delay
1754         lfs_df -p $pool1
1755
1756         touch $DIR/$tdir/$tfile-2
1757         [[ $($LFS getstripe -p $DIR/$tdir/$tfile-2) == "$pool1" ]] || {
1758                 $LFS getstripe $DIR/$tdir/$tfile-2
1759                 error "new pool != $pool1"
1760         }
1761         # spill is revaluated at object creation
1762         wait_update_facet mds1 "$cmd.spill_is_active" "0" ||
1763                 error "spilling is still active"
1764
1765         do_facet mds1 "$LCTL set_param $prefix.spill_threshold_pct=0"
1766         [[ $(do_facet mds1 "$cmd.spill_threshold_pct") == "0" ]] ||
1767                 error "spill threshold wasn't reset"
1768 }
1769 run_test 29 "check OST pool spilling"
1770
1771 test_30() {
1772         local MDT_DEV=$(mdsdevname 1)
1773         local mdts=$(comma_list $(mdts_nodes))
1774         local pool1=${TESTNAME}-1
1775         local pool2=${TESTNAME}-2
1776         local threshold=10
1777         local prefix="lod.$FSNAME-MDT0000*.pool.$pool1"
1778         local cmd="$LCTL get_param -n $prefix"
1779
1780         (( $MDS1_VERSION >= $(version_code 2.14.53) )) ||
1781                 skip "Need MDS version at least 2.14.53"
1782         (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
1783
1784         pool_add $pool1 || error "Pool creation failed"
1785         pool_add_targets $pool1 0 1 || error "pool_add_targets failed"
1786
1787         pool_add $pool2 || error "Pool creation failed"
1788         pool_add_targets $pool2 2 3 || error "pool_add_targets failed"
1789
1790         # feed a poison
1791         do_facet mds1 $LCTL set_param $prefix.spill_target="0123456789ABCDEF" &&
1792                 error "pool name"
1793         do_facet mds1 $LCTL set_param $prefix.spill_target="$pool1-2" &&
1794                 error "non-exising pool"
1795         do_facet mds1 $LCTL set_param $prefix.spill_target="$pool1" &&
1796                 error "poolback"
1797         do_facet mds1 $LCTL set_param $prefix.spill_threshold_pct="101" &&
1798                 error ">100%"
1799         do_facet mds1 $LCTL set_param $prefix.spill_threshold_pct="-1" &&
1800                 error "<0%"
1801
1802         # set persistent spilling
1803         do_facet mgs $LCTL set_param -P $prefix.spill_target="$pool2"
1804         do_facet mgs $LCTL set_param -P $prefix.spill_threshold_pct=$threshold
1805         wait_update_facet mds1 "$cmd.spill_target" "$pool2" ||
1806                 error "spill target wasn't set"
1807         wait_update_facet mds1 "$cmd.spill_threshold_pct" $threshold ||
1808                 error "spill target wasn't set"
1809
1810         stop mds1 || error "Fail to stop MDT."
1811         start mds1 $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
1812         wait_update_facet mds1 "$cmd.spill_target" "$pool2" ||
1813                 error "spill target wasn't set after restart"
1814         wait_update_facet mds1 "$cmd.spill_threshold_pct" $threshold ||
1815                 error "spill target wasn't set after restart"
1816
1817         # now reset spilling
1818         do_facet mgs $LCTL set_param -P $prefix.spill_threshold_pct=0
1819         wait_update_facet mds1 "$cmd.spill_threshold_pct" 0 ||
1820                 error "spill target wasn't set"
1821
1822         stop mds1 || error "Fail to stop MDT."
1823         start mds1 $MDT_DEV $MDS_MOUNT_OPTS || error "Fail to start MDT."
1824         wait_update_facet mds1 "$cmd.spill_threshold_pct" 0 ||
1825                 error "spill target wasn't set"
1826 }
1827 run_test 30 "persistent OST pool spilling"
1828
1829 test_31() {
1830         local prefix="lod.$FSNAME-*.pool."
1831         local MDT_DEV=$(mdsdevname mds1)
1832         local mdts=$(comma_list $(mdts_nodes))
1833         local do_mdts="do_nodes $mdts $LCTL"
1834         local pool1=${TESTNAME}-1
1835         local pool2=${TESTNAME}-2
1836         local pool3=${TESTNAME}-3
1837         local pool4=${TESTNAME}-4
1838         local threshold=10
1839
1840         (( $MDS1_VERSION >= $(version_code 2.14.53) )) ||
1841                 skip "Need MDS version at least 2.14.53"
1842         (( $OSTCOUNT >= 4 )) || skip "needs >= 4 OSTs"
1843         check_set_fallocate_or_skip
1844
1845         pool_add $pool1 || error "Pool creation failed"
1846         pool_add_targets $pool1 0 0 || error "pool_add_targets failed"
1847
1848         pool_add $pool2 || error "Pool creation failed"
1849         pool_add_targets $pool2 1 1 || error "pool_add_targets failed"
1850
1851         pool_add $pool3 || error "Pool creation failed"
1852         pool_add_targets $pool3 2 2 || error "pool_add_targets failed"
1853
1854         pool_add $pool4 || error "Pool creation failed"
1855         pool_add_targets $pool4 3 3 || error "pool_add_targets failed"
1856
1857         fill_ost_pool $pool1 $threshold
1858         fill_ost_pool $pool2 $threshold
1859         fill_ost_pool $pool3 $threshold
1860         cancel_lru_locks osc
1861         local delay=$(do_facet mds1 lctl get_param -n lo[vd].*.qos_maxage |
1862                       awk '{ print $1 * 2; exit; }')
1863         sleep $((delay + 1))
1864
1865         stack_trap "$do_mdts set_param lod.*.pool.*.spill_threshold_pct=0"
1866
1867         $do_mdts set_param lod.*.pool.$pool1.spill_target="$pool2"
1868         $do_mdts set_param lod.*.pool.$pool1.spill_threshold_pct="$threshold"
1869
1870         $do_mdts set_param lod.*.pool.$pool2.spill_target="$pool3"
1871         $do_mdts set_param lod.*.pool.$pool2.spill_threshold_pct="$threshold"
1872
1873         $do_mdts set_param lod.*.pool.$pool3.spill_target="$pool4"
1874         $do_mdts set_param lod.*.pool.$pool3.spill_threshold_pct="$threshold"
1875
1876         $do_mdts get_param lod.*.pool.*.spill*
1877
1878         $LFS setstripe -p $pool1 $DIR/$tdir || error "can't set default layout"
1879         local tmpfile=$DIR/$tdir/$tfile-2
1880         touch $tmpfile
1881         $LFS getstripe $tmpfile | grep -q pool.*$pool4 || {
1882                 $LFS getstripe $tmpfile
1883                 error "old pool is not $pool4"
1884         }
1885
1886         # check for loops
1887
1888         # reset all loop spilling
1889         $do_mdts set_param lod.*.pool.*.spill_threshold_pct="0"
1890
1891         # pool1->pool2->pool3, then pool4->pool1 fails
1892         $do_mdts set_param lod.*.pool.$pool1.spill_target="$pool2" ||
1893                 error "can't set spill target for $pool1"
1894         $do_mdts set_param lod.*.pool.$pool2.spill_target="$pool3" ||
1895                 error "can't set spill target for $pool1"
1896         $do_mdts set_param lod.*.pool.$pool3.spill_target="$pool4" ||
1897                 error "can't set spill target for $pool1"
1898         $do_mdts set_param lod.*.pool.$pool4.spill_target="$pool1" &&
1899                 error "loop succeed"
1900
1901         # reset all loop spilling
1902         $do_mdts set_param lod.*.pool.*.spill_threshold_pct="0"
1903
1904         # pool1->pool2,pool4->pool1, then pool3->pool4 fails
1905         $do_mdts set_param lod.*.pool.$pool1.spill_target="$pool2" ||
1906                 error "can't set spill target for $pool1"
1907         $do_mdts set_param lod.*.pool.$pool2.spill_target="$pool3" ||
1908                 error "can't set spill target for $pool1"
1909         $do_mdts set_param lod.*.pool.$pool4.spill_target="$pool1" ||
1910                 error "can't set spill target for $pool4"
1911         $do_mdts set_param lod.*.pool.$pool3.spill_target="$pool4" &&
1912                 error "loop succeed"
1913
1914         return 0
1915 }
1916 run_test 31 "OST pool spilling chained"
1917
1918 test_32() { # LU-15707
1919         (( OSTCOUNT >= 2 )) || skip "Need at least 2 OST"
1920
1921         local pool=$TESTNAME
1922         pool_add $pool || error "add $pool failed"
1923         pool_add_targets $pool 0 ||
1924                 error "add targets to $pool failed"
1925
1926         test_mkdir $DIR/$tdir
1927         $LFS setstripe -p $pool $DIR/$tdir ||
1928                 error "setstripe fail on $DIR/$tdir"
1929
1930         ( $LFS getstripe -p $DIR/$tdir | grep -q $pool ) ||
1931                 error "fail to set pool on $DIR/$tdir"
1932
1933         local ig_pool="ignore_pool"
1934
1935         pool_add $ig_pool || error "add $ig_pool failed"
1936
1937         $LFS setstripe -p $ig_pool $DIR/$tdir/$tfile ||
1938                 error "setstripe fail on $DIR/$tdir/$tfile"
1939
1940         ( $LFS getstripe -p $DIR/$tdir/$tfile | grep -q $ig_pool ) ||
1941                 error "fail to create $DIR/$tdir/$tfile without pool"
1942
1943         # Test with start index
1944         local got idx
1945         for ((idx = 0; idx < OSTCOUNT; idx++)); do
1946                 $LFS setstripe -p $ig_pool -i $idx $DIR/$tdir/$tfile.$idx ||
1947                         error "setstripe -i fail on $DIR/$tdir/$tfile.$idx"
1948
1949                 got=$($LFS getstripe -i $DIR/$tdir/$tfile.$idx)
1950                 (( got == idx )) ||
1951                         error "file $tfile.$idx on OST $got != $idx"
1952         done
1953
1954         # Test with ost list
1955         $LFS setstripe -p $ig_pool -o 1,0 $DIR/$tdir/$tfile.1_0 ||
1956                 error "setstripe --ost fail on $DIR/$tdir/$tfile.1_0"
1957
1958         got=$($LFS getstripe -i $DIR/$tdir/$tfile.1_0)
1959         (( got == 1 )) ||
1960                 error "file $tfile.1_0 (ostlist) start on OST $got != 1"
1961
1962         got=$($LFS getstripe -c $DIR/$tdir/$tfile.1_0)
1963         (( got == 2 )) ||
1964                 error "file $tfile.1_0 (ostlist) has stripe count $got != 2"
1965 }
1966 run_test 32 "force to create a file without pool (no inheritance)"
1967
1968 cd $ORIG_PWD
1969
1970 complete_test $SECONDS
1971 destroy_test_pools $FSNAME
1972 if ! combined_mgs_mds; then
1973         zconf_umount $mgs_HOST $MOUNT
1974         do_facet mgs "rm -rf $MOUNT"
1975 fi
1976 check_and_cleanup_lustre
1977 exit_status