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