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