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