Whamcloud - gitweb
b=19919
[fs/lustre-release.git] / lustre / tests / ost-pools.sh
1 #!/bin/bash
2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:autoindent:shiftwidth=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
29 check_and_setup_lustre
30
31 DIR=${DIR:-$MOUNT}
32 assert_DIR
33
34 POOLSLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
35 [ "$POOLSLOG" ] && rm -f $POOLSLOG || true
36 build_test_filter
37
38 FAIL_ON_ERROR=${FAIL_ON_ERROR:-true}
39
40 LFS=${LFS:-lfs}
41 LCTL=${LCTL:-lctl}
42 SETSTRIPE=${SETSTRIPE:-"$LFS setstripe"}
43 GETSTRIPE=${GETSTRIPE:-"$LFS getstripe"}
44
45
46 TSTUSR=${TSTUSR:-"quota_usr"}
47 TSTID=${TSTID:-60000}
48 RUNAS="runas -u $TSTID -g $TSTID"
49
50 # OST pools tests
51 POOL=${POOL:-pool1}
52 POOL2=${POOL2:-pool2}
53 POOL3=${POOL3:-pool3}
54 NON_EXISTANT_POOL=nonexistantpool
55 NON_EXISTANT_FS=nonexistantfs
56 INVALID_POOL=some_invalid_pool_name
57 TGT_COUNT=$OSTCOUNT
58 TGT_FIRST=0
59 TGT_MAX=$((TGT_COUNT-1))
60 TGT_STEP=1
61 TGT_LIST=$(seq $TGT_FIRST $TGT_STEP $TGT_MAX)
62 TGT_LIST2=$(seq $TGT_FIRST 2 $TGT_MAX)
63
64 TGT_ALL="$FSNAME-OST[$TGT_FIRST-$TGT_MAX/1]"
65 TGT_HALF="$FSNAME-OST[$TGT_FIRST-$TGT_MAX/2]"
66
67 TGT_UUID=$(for i in $TGT_LIST; do printf "$FSNAME-OST%04x_UUID " $i; done)
68 TGT_UUID2=$(for i in $TGT_LIST2; do printf "$FSNAME-OST%04x_UUID " $i; done)
69
70 create_dir() {
71     local dir=$1
72     local pool=$2
73     local count=${3:-"-1"}
74     local idx=$4
75
76     mkdir -p $dir
77     if [[ -n $4 ]]; then
78         $SETSTRIPE -c $count -p $pool $dir -o $idx
79     else
80         $SETSTRIPE -c $count -p $pool $dir
81     fi
82     [[ $? -eq 0 ]] || \
83         error "$SETSTRIPE -p $pool $dir failed."
84 }
85
86 create_file() {
87     local file=$1
88     local pool=$2
89     local count=${3:-"-1"}
90     local index=${4:-"-1"}
91     rm -f $file
92     $SETSTRIPE -o $index -c $count -p $pool $file
93     [[ $? -eq 0 ]] || \
94         error "$SETSTRIPE -p $pool $file failed."
95 }
96
97 osts_in_pool() {
98     local pool=$1
99     local res
100     for i in $(do_facet $SINGLEMDS lctl pool_list $FSNAME.$pool | \
101         grep -v "^Pool:" | sed -e 's/_UUID$//;s/^.*-OST//'); do
102       res="$res $(printf "%d" 0x$i)"
103     done
104     echo $res
105 }
106
107 check_dir_in_pool() {
108     local dir=$1
109     local pool=$2
110     local res=$($GETSTRIPE $dir | grep "^stripe_count:" \
111         | cut -d ':' -f 5 | tr -d "[:blank:]")
112     if [[ "$res" == "$pool" ]]; then
113         return 0
114     else
115         error found $res instead of $pool
116         return 1
117     fi
118 }
119
120 check_file_in_pool() {
121     local osts=$(osts_in_pool $2)
122     check_file_in_osts $1 "$osts" $3
123 }
124
125 check_file_in_osts() {
126         local file=$1
127         local pool_list=${2:-$TGT_LIST}
128         local count=$3
129         local res=$($GETSTRIPE $file | grep 0x | cut -f2)
130         local i
131         for i in $res
132         do
133                 found=$(echo :$pool_list: | tr " " ":"  | grep :$i:)
134                 if [[ "$found" == "" ]]; then
135                         echo "pool list: $pool_list"
136                         echo "striping: $res"
137                         $GETSTRIPE $file
138                         error "$file not allocated from OSTs $pool_list."
139                         return 1
140                 fi
141         done
142
143         local ost_count=$($GETSTRIPE $file | grep 0x | wc -l)
144         [[ -n "$count" ]] && [[ $ost_count -ne $count ]] && \
145             { error "Stripe count $count expected; got $ost_count" && return 1; }
146                 
147         return 0
148 }
149
150 check_file_not_in_pool() {
151     local file=$1
152     local pool=$2
153     local res=$($GETSTRIPE -v $file | grep "^pool:" | tr -d "[:blank:]" | cut -f 2 -d ':')
154     if [[ "$res" == "$pool" ]]; then
155         error "File $file is in pool: $res"
156         return 1
157     else
158         return 0
159     fi
160 }
161
162 check_dir_not_in_pool() {
163     local dir=$1
164     local pool=$2
165     local res=$($GETSTRIPE -v $dir | grep "^stripe_count" | head -1 | \
166         cut -f 8 -d ' ')
167     if [[ "$res" == "$pool" ]]; then
168         error "File $dir is in pool: $res"
169         return 1
170     else
171         return 0
172     fi
173 }
174
175 create_pool() {
176     do_facet $SINGLEMDS lctl pool_new $FSNAME.$1
177     local RC=$?
178     # get param should return err until pool is created
179     [[ $RC -ne 0 ]] && return $RC
180
181     wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$1 \
182         2>/dev/null || echo foo" "" || RC=1
183     [[ $RC -ne 0 ]] && error "pool_new failed"
184     return $RC
185 }
186
187 drain_pool() {
188     pool=$1
189     wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool" ""\
190         ||error "Failed to remove targets from pool: $pool"
191 }
192
193 add_pool() {
194     local pool=$1
195     local osts=$2
196     local tgt="${3}$(lctl get_param -n lov.$FSNAME-*.pools.$pool | \
197         sort -u | tr '\n' ' ')"
198
199     do_facet $SINGLEMDS lctl pool_add $FSNAME.$pool $osts
200     local RC=$?
201     [[ $RC -ne 0 ]] && return $RC
202
203     wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$pool | \
204         sort -u | tr '\n' ' ' " "$tgt" || RC=1
205     [[ $RC -ne 0 ]] && error "pool_add failed: $1; $2"
206     return $RC
207 }
208
209 create_pool_nofail() {
210     create_pool $1
211     if [[ $? != 0 ]]
212     then
213         error "Pool creation of $1 failed"
214     fi
215 }
216
217 create_pool_fail() {
218     create_pool $1
219     if [[ $? == 0 ]]
220     then
221         error "Pool creation of $1 succeeded; should have failed"
222     fi
223 }
224
225 cleanup_tests() {
226     # Destroy pools from previous test runs
227     for p in $(do_facet $SINGLEMDS lctl pool_list $FSNAME | \
228       grep $FSNAME.pool[0-$OSTCOUNT]); do
229         destroy_pool_int $p;
230     done
231     rm -rf $DIR/d0.${TESTSUITE}
232 }
233
234 ost_pools_init() {
235     cleanup_tests
236 }
237
238
239 # Initialization
240 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
241 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
242 ost_pools_init
243
244 # Tests for new commands added
245
246 test_1() {
247     echo "Creating a pool with a 1 character pool name"
248     create_pool_nofail p
249
250     echo "Creating a pool with a 10 character pool name"
251     create_pool_nofail p123456789
252     destroy_pool p123456789
253
254     echo "Creating a pool with a 16 character pool name"
255     create_pool_nofail p123456789123456
256     destroy_pool p123456789123456
257
258     echo "Creating a pool with a 17 character pool name; should fail"
259     create_pool_fail p1234567891234567
260
261     echo "Creating a pool with a 1000 character pool name; should fail"
262     NAME="p"
263     for i in `seq 1 999`; do NAME=${NAME}"o"; done
264     create_pool_fail $NAME
265
266     echo "pool_new should fail if fs-name or poolname are missing."
267     do_facet $SINGLEMDS lctl pool_new .pool1 2>/dev/null
268     [[ $? -ne 0 ]] || \
269         error "pool_new did not fail even though fs-name was missing."
270     do_facet $SINGLEMDS lctl pool_new pool1 2>/dev/null
271     [[ $? -ne 0 ]] || \
272         error "pool_new did not fail even though fs-name was missing."
273     do_facet $SINGLEMDS lctl pool_new ${FSNAME}. 2>/dev/null
274     [[ $? -ne 0 ]] || \
275         error "pool_new did not fail even though pool name was missing."
276     do_facet $SINGLEMDS lctl pool_new . 2>/dev/null
277     [[ $? -ne 0 ]] || \
278         error "pool_new did not fail even though pool name and fs-name " \
279             "were missing."
280     do_facet $SINGLEMDS lctl pool_new ${FSNAME},pool1 2>/dev/null
281     [[ $? -ne 0 ]] || \
282         error "pool_new did not fail even though pool name format was wrong"
283     do_facet $SINGLEMDS lctl pool_new ${FSNAME}/pool1 2>/dev/null
284     [[ $? -ne 0 ]] || \
285         error "pool_new did not fail even though pool name format was wrong"
286
287     do_facet $SINGLEMDS lctl pool_new ${FSNAME}.p 2>/dev/null
288     [[ $? -ne 0 ]] || \
289         error "pool_new did not fail even though pool1 existed"
290     destroy_pool p
291
292 }
293 run_test 1 "Test lctl pool_new  ========================================="
294
295 test_2a() {
296     destroy_pool $POOL
297
298     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $FSNAME-OST0000 2>/dev/null
299     [[ $? -ne 0 ]] || \
300         error " pool_add did not fail even though pool did " \
301         " not exist."
302 }
303 run_test 2a "pool_add: non-existant pool"
304
305 test_2b() {
306     do_facet $SINGLEMDS lctl pool_add $FSNAME.p1234567891234567890 \
307         $FSNAME-OST0000 2>/dev/null
308     [[ $? -ne 0 ]] || \
309         error "pool_add did not fail even though pool name was invalid."
310 }
311 run_test 2b "pool_add: Invalid pool name"
312
313 # Testing various combinations of OST name list
314 test_2c() {
315     local TGT
316     local RC
317
318     lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
319     [[ $? -ne 0 ]] || \
320         destroy_pool $POOL
321
322     create_pool_nofail $POOL
323
324     # 1. OST0000
325     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL OST0000
326     RC=$?; [[ $RC -eq 0 ]] || \
327         error "pool_add failed. $FSNAME $POOL OST0000: $RC"
328     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL OST0000
329     drain_pool $POOL
330
331     # 2. lustre-OST0000
332     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $FSNAME-OST0000
333     RC=$?; [[ $RC -eq 0 ]] || \
334         error "pool_add failed. $FSNAME $POOL $FSNAME-OST0000: $RC"
335     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000
336     drain_pool $POOL
337
338     # 3. lustre-OST0000_UUID
339     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $FSNAME-OST0000_UUID
340     RC=$?; [[ $RC -eq 0 ]] || \
341         error "pool_add failed. $FSNAME $POOL $FSNAME-OST0000_UUID: $RC"
342     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000_UUID
343     drain_pool $POOL
344
345     # 4. lustre-OST[0,1,2,3,]
346     TGT="$FSNAME-OST["
347     for i in $TGT_LIST; do TGT=${TGT}$(printf "$i," $i); done
348     TGT="${TGT}]"
349     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $TGT
350     [[ $? -eq 0 ]] || \
351         error "pool_add failed. $FSNAME.$POOL $TGT. $RC"
352     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $TGT
353     drain_pool $POOL
354
355     # 5. lustre-OST[0-5/1]
356     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $TGT_ALL
357     RC=$?; [[ $RC -eq 0 ]] || \
358         error "pool_add failed. $FSNAME $POOL" "$TGT_ALL $RC"
359     wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | \
360       sort -u | tr '\n' ' ' " "$TGT_UUID" || error "Add to pool failed"
361     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $TGT_ALL
362     drain_pool $POOL
363
364     destroy_pool $POOL
365 }
366 run_test 2c "pool_add: OST index combinations ==========================="
367
368 test_2d() {
369     local TGT
370     local RC
371
372     lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
373     [[ $? -ne 0 ]] || \
374         destroy_pool $POOL
375
376     create_pool_nofail $POOL
377
378     TGT=$(printf "$FSNAME-OST%04x_UUID " $OSTCOUNT)
379     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $TGT
380     RC=$?; [[ $RC -ne 0 ]] || \
381         error "pool_add succeeded for an OST ($TGT) that does not exist."
382
383     destroy_pool $POOL
384 }
385 run_test 2d "pool_add: OSTs that don't exist should be rejected ========"
386
387 test_2e() {
388     local TGT
389     local RC
390     local RESULT
391
392     $LCTL get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
393     [[ $? -ne 0 ]] || \
394         destroy_pool $POOL
395
396     create_pool_nofail $POOL
397
398     TGT="$FSNAME-OST0000_UUID "
399     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $TGT
400     wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.$POOL | \
401       sort -u | tr '\n' ' ' " "$TGT" || error "Add to pool failed"
402     RESULT=$(do_facet $SINGLEMDS \
403         "LOCALE=C $LCTL pool_add $FSNAME.$POOL $TGT 2>&1")
404     RC=$?
405     echo $RESULT
406
407     [[ $RC -ne 0 ]] || \
408         error "pool_add succeeded for an OST that was already in the pool."
409
410     [[ $(grep "already in pool" <<< $RESULT) ]] || \
411         error "pool_add failed as expected but error message not as expected."
412
413     destroy_pool $POOL
414 }
415 run_test 2e "pool_add: OST already in a pool should be rejected ========"
416
417 test_3a() {
418     lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
419     [[ $? -ne 0 ]] || \
420         destroy_pool $POOL
421
422     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000 2>/dev/null
423     [[ $? -ne 0 ]] || \
424         error "pool_remove did not fail even though pool did not exist."
425 }
426 run_test 3a "pool_remove: non-existant pool"
427
428 test_3b() {
429     do_facet $SINGLEMDS lctl pool_remove ${NON_EXISTANT_FS}.$POOL OST0000 2>/dev/null
430     [[ $? -ne 0 ]] || \
431         error "pool_remove did not fail even though fsname did not exist."
432 }
433 run_test 3b "pool_remove: non-existant fsname"
434
435 test_3c() {
436     do_facet $SINGLEMDS lctl pool_remove $FSNAME.p1234567891234567890 \
437         $FSNAME-OST0000 2>/dev/null
438     [[ $? -ne 0 ]] || \
439         error "pool_remove did not fail even though pool name was invalid."
440 }
441 run_test 3c "pool_remove: Invalid pool name"
442
443 # Testing various combinations of OST name list
444 test_3d() {
445     lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
446     [[ $? -ne 0 ]] || \
447         destroy_pool $POOL
448
449     create_pool_nofail $POOL
450     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL OST0000
451     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL OST0000
452     [[ $? -eq 0 ]] || \
453         error "pool_remove failed. $FSNAME $POOL OST0000"
454     drain_pool $POOL
455
456     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $FSNAME-OST0000
457     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000
458     [[ $? -eq 0 ]] || \
459         error "pool_remove failed. $FSNAME $POOL $FSNAME-OST0000"
460     drain_pool $POOL
461
462     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $FSNAME-OST0000_UUID
463     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $FSNAME-OST0000_UUID
464     [[ $? -eq 0 ]] || \
465         error "pool_remove failed. $FSNAME $POOL $FSNAME-OST0000_UUID"
466     drain_pool $POOL
467
468     add_pool $POOL $TGT_ALL "$TGT_UUID"
469     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $TGT_ALL
470     [[ $? -eq 0 ]] || \
471         error "pool_remove failed. $FSNAME $POOL" $TGT_ALL
472     drain_pool $POOL
473
474     destroy_pool $POOL
475 }
476 run_test 3d "pool_remove: OST index combinations ==========================="
477
478 test_4a() {
479     lctl get_param -n lov.$FSNAME-*.pools.$POOL 2>/dev/null
480     [[ $? -ne 0 ]] || \
481         destroy_pool $POOL
482
483     do_facet $SINGLEMDS lctl pool_destroy $FSNAME.$POOL 2>/dev/null
484     [[ $? -ne 0 ]] || \
485         error "pool_destroy did not fail even though pool did not exist."
486 }
487 run_test 4a "pool_destroy: non-existant pool"
488
489 test_4b() {
490     do_facet $SINGLEMDS lctl pool_destroy ${NON_EXISTANT_FS}.$POOL 2>/dev/null
491     [[ $? -ne 0 ]] || \
492         error "pool_destroy did not fail even though the filesystem did not exist."
493 }
494 run_test 4b "pool_destroy: non-existant fs-name"
495
496 test_4c() {
497     create_pool_nofail $POOL
498     add_pool $POOL "OST0000" "$FSNAME-OST0000_UUID "
499
500     do_facet $SINGLEMDS lctl pool_destroy ${FSNAME}.$POOL
501     [[ $? -ne 0 ]] || \
502         error "pool_destroy succeeded with a non-empty pool."
503     destroy_pool $POOL
504 }
505 run_test 4c "pool_destroy: non-empty pool ==============================="
506
507 sub_test_5() {
508     local LCMD=$1
509
510     $LCMD pool_list 2>/dev/null
511     [[ $? -ne 0 ]] || \
512         error "pool_list did not fail even though fsname was not mentioned."
513
514     destroy_pool $POOL 2>/dev/null
515     destroy_pool $POOL2 2>/dev/null
516
517     create_pool_nofail $POOL
518     create_pool_nofail $POOL2
519     $LCMD pool_list $FSNAME
520     [[ $? -eq 0 ]] || \
521         error "pool_list $FSNAME failed."
522
523     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $TGT_ALL
524
525     $LCMD pool_list $FSNAME.$POOL
526     [[ $? -eq 0 ]] || \
527         error "pool_list $FSNAME.$POOL failed."
528
529     $LCMD pool_list ${NON_EXISTANT_FS} 2>/dev/null
530     [[ $? -ne 0 ]] || \
531         error "pool_list did not fail for a non-existant fsname $NON_EXISTANT_FS"
532
533     $LCMD pool_list ${FSNAME}.$NON_EXISTANT_POOL 2>/dev/null
534     [[ $? -ne 0 ]] || \
535         error "pool_list did not fail for a non-existant pool $NON_EXISTANT_POOL"
536
537     if [[ ! $(grep $SINGLEMDS <<< $LCMD) ]]; then
538         echo $LCMD pool_list $DIR
539         $LCMD pool_list $DIR
540         [[ $? -eq 0 ]] || \
541             error "pool_list failed for $DIR"
542
543         mkdir -p ${DIR}/d1
544         $LCMD pool_list ${DIR}/d1
545         [[ $? -eq 0 ]] || \
546             error "pool_list failed for ${DIR}/d1"
547     fi
548
549     rm -rf ${DIR}nonexistant
550     $LCMD pool_list ${DIR}nonexistant 2>/dev/null
551     [[ $? -ne 0 ]] || \
552         error "pool_list did not fail for invalid mountpoint ${DIR}nonexistant"
553
554     destroy_pool $POOL
555     destroy_pool $POOL2
556 }
557
558 test_5() {
559     # Issue commands from client
560     sub_test_5 $LCTL
561     sub_test_5 $LFS
562
563     # Issue commands from MDS
564     sub_test_5 "do_facet $SINGLEMDS lctl"
565     sub_test_5 "do_facet $SINGLEMDS lfs"
566
567 }
568 run_test 5 "lfs/lctl pool_list"
569
570 test_6() {
571     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
572     local POOL_DIR=$POOL_ROOT/dir_tst
573     local POOL_FILE=$POOL_ROOT/file_tst
574
575     create_pool_nofail $POOL
576
577     do_facet $SINGLEMDS lctl pool_list $FSNAME
578     [[ $? -eq 0 ]] || \
579         error "pool_list $FSNAME failed."
580
581     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $TGT_ALL
582
583     mkdir -p $POOL_DIR
584     $SETSTRIPE -c -1 -p $POOL $POOL_DIR
585     [[ $? -eq 0 ]] || \
586         error "$SETSTRIPE -p $POOL failed."
587     check_dir_in_pool $POOL_DIR $POOL
588
589     # If an invalid pool name is specified, the command should fail
590     $SETSTRIPE -c 2 -p $INVALID_POOL $POOL_DIR 2>/dev/null
591     [[ $? -ne 0 ]] || \
592         error "setstripe to invalid pool did not fail."
593
594     # If the pool name does not exist, the command should fail
595     $SETSTRIPE -c 2 -p $NON_EXISTANT_POOL $POOL_DIR 2>/dev/null
596     [[ $? -ne 0 ]] || \
597         error "setstripe to non-existant pool did not fail."
598
599     # lfs setstripe should work as before if a pool name is not specified.
600     $SETSTRIPE -c -1 $POOL_DIR
601     [[ $? -eq 0 ]] || \
602         error "$SETSTRIPE -p $POOL_DIR failed."
603     $SETSTRIPE -c -1 $POOL_FILE
604     [[ $? -eq 0 ]] || \
605         error "$SETSTRIPE -p $POOL_FILE failed."
606
607     # lfs setstripe should fail if a start index that is outside the
608     # pool is specified.
609     create_pool_nofail $POOL2
610     add_pool $POOL2 "OST0000" "$FSNAME-OST0000_UUID "
611     $SETSTRIPE -o 1 -p $POOL2 $ROOT_POOL/$tfile 2>/dev/null
612     [[ $? -ne 0 ]] || \
613         error "$SETSTRIPE with start index outside the pool did not fail."
614
615     destroy_pool $POOL
616     destroy_pool $POOL2
617 }
618 run_test 6 "getstripe/setstripe"
619
620 test_11() {
621     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
622
623     [[ $OSTCOUNT -le 1 ]] && skip "Need atleast 2 OSTs" && return
624
625     create_pool_nofail $POOL
626     create_pool_nofail $POOL2
627
628     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL \
629         $FSNAME-OST[$TGT_FIRST-$TGT_MAX/2]
630     local start=$((TGT_FIRST+1))
631     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL2 \
632         $FSNAME-OST[$start-$TGT_MAX/2]
633
634     create_dir $POOL_ROOT/dir1  $POOL
635     create_dir $POOL_ROOT/dir2  $POOL2
636     check_dir_in_pool $POOL_ROOT/dir1 $POOL
637     check_dir_in_pool $POOL_ROOT/dir1 $POOL
638
639     local numfiles=100
640     createmany -o $POOL_ROOT/dir1/$tfile $numfiles || \
641         error "createmany $POOL_ROOT/dir1/$tfile failed!"
642
643     for file in $POOL_ROOT/dir1/*; do
644         check_file_in_pool $file $POOL
645     done
646
647     createmany -o $POOL_ROOT/dir2/$tfile $numfiles || \
648         error "createmany $POOL_ROOT/dir2/$tfile failed!"
649     for file in $POOL_ROOT/dir2/*; do
650         check_file_in_pool $file $POOL2
651     done
652
653     rm -rf $POOL_ROOT/dir?
654
655     destroy_pool $POOL
656     destroy_pool $POOL2
657
658     return 0
659 }
660 run_test 11 "OSTs in overlapping/multiple pools"
661
662 test_12() {
663     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
664
665     [[ $OSTCOUNT -le 2 ]] && skip "Need atleast 3 OSTs" && return
666
667     create_pool_nofail $POOL
668     create_pool_nofail $POOL2
669
670     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL \
671         $FSNAME-OST[$TGT_FIRST-$TGT_MAX/2]
672     local start=$((TGT_FIRST+1))
673     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL2 \
674         $FSNAME-OST[$start-$TGT_MAX/2]
675
676     echo creating some files in $POOL and $POOL2
677
678     create_dir $POOL_ROOT/dir1  $POOL
679     create_dir $POOL_ROOT/dir2  $POOL2
680     create_file $POOL_ROOT/file1 $POOL
681     create_file $POOL_ROOT/file2 $POOL2
682
683     echo Checking the files created
684     check_dir_in_pool $POOL_ROOT/dir1 $POOL
685     check_dir_in_pool $POOL_ROOT/dir2 $POOL2
686     check_file_in_pool $POOL_ROOT/file1 $POOL
687     check_file_in_pool $POOL_ROOT/file2 $POOL2
688
689     echo Changing the pool membership
690     do_facet $SINGLEMDS lctl pool_remove $FSNAME.$POOL $FSNAME-OST[$TGT_FIRST]
691     do_facet $SINGLEMDS lctl pool_list $FSNAME.$POOL
692     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL2 $FSNAME-OST[$TGT_FIRST]
693     do_facet $SINGLEMDS lctl pool_list $FSNAME.$POOL2
694
695     echo Checking the files again    
696     check_dir_in_pool $POOL_ROOT/dir1 $POOL
697     check_dir_in_pool $POOL_ROOT/dir2 $POOL2
698     check_file_in_osts $POOL_ROOT/file1 "$TGT_LIST2"    
699     check_file_in_osts $POOL_ROOT/file2 "$(seq $start 2 $TGT_MAX)"
700
701     echo Creating some more files
702     create_dir $POOL_ROOT/dir3 $POOL
703     create_dir $POOL_ROOT/dir4 POOL2
704     create_file $POOL_ROOT/file3 $POOL
705     create_file $POOL_ROOT/file4 $POOL2
706
707     echo Checking the new files 
708     check_file_in_pool $POOL_ROOT/file3 $POOL
709     check_file_in_pool $POOL_ROOT/file4 $POOL2
710
711     destroy_pool $POOL
712     destroy_pool $POOL2
713
714     return 0    
715 }
716 run_test 12 "OST Pool Membership"
717
718 test_13() {
719     [[ $OSTCOUNT -le 2 ]] && skip "Need atleast 3 OSTs" && return
720
721     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
722     local numfiles=10
723     local count=3
724
725     create_pool_nofail $POOL
726     do_facet $SINGLEMDS lctl pool_add $FSNAME.$POOL $TGT_ALL
727
728     create_dir $POOL_ROOT/dir1 $POOL -1
729     createmany -o $POOL_ROOT/dir1/$tfile $numfiles || \
730         error "createmany $POOL_ROOT/dir1/$tfile failed!"
731     for file in $POOL_ROOT/dir1/*; do
732         check_file_in_pool $file $POOL $OSTCOUNT
733     done
734
735     create_file $POOL_ROOT/dir1/file1 $POOL 1 $TGT_FIRST
736     create_file $POOL_ROOT/dir1/file2 $POOL 1 $((TGT_FIRST+1))
737     create_file $POOL_ROOT/dir1/file3 $POOL 1 $((TGT_FIRST+2))
738     check_file_in_pool $POOL_ROOT/dir1/file1 $POOL 1
739     check_file_in_pool $POOL_ROOT/dir1/file2 $POOL 1
740     create_file $POOL_ROOT/dir1/file3 $POOL 1 $((TGT_FIRST+2))
741     check_file_in_osts $POOL_ROOT/dir1/file1 "$TGT_FIRST"
742     check_file_in_osts $POOL_ROOT/dir1/file2 "$((TGT_FIRST+1))"
743     check_file_in_osts $POOL_ROOT/dir1/file3 "$((TGT_FIRST+2))"
744
745     create_dir $POOL_ROOT/dir2 $POOL $count
746     createmany -o $POOL_ROOT/dir2/$tfile $numfiles || \
747         error "createmany $POOL_ROOT/dir2/$tfile failed!"
748     for file in $POOL_ROOT/dir2/*; do
749         check_file_in_pool $file $POOL $count
750     done
751
752     create_dir $POOL_ROOT/dir3 $POOL $count $((TGT_FIRST+1))
753     createmany -o $POOL_ROOT/dir3/$tfile_ $numfiles || \
754         error "createmany $POOL_ROOT/dir3/$tfile_ failed!"
755     for file in $POOL_ROOT/dir3/*; do
756         check_file_in_pool $file $POOL $count
757     done
758
759     create_dir $POOL_ROOT/dir4 $POOL 1
760     createmany -o $POOL_ROOT/dir4/$tfile_ $numfiles || \
761         error "createmany $POOL_ROOT/dir4/$tfile_ failed!"
762     for file in $POOL_ROOT/dir4/*; do
763         check_file_in_pool $file $POOL 1
764     done
765
766     create_dir $POOL_ROOT/dir5 $POOL 1 $((TGT_FIRST+2))
767     createmany -o $POOL_ROOT/dir5/$tfile_ $numfiles || \
768         error "createmany $POOL_ROOT/dir5/$tfile_ failed!"
769     for file in $POOL_ROOT/dir5/*; do
770         check_file_in_pool $file $POOL 1
771         check_file_in_osts  $file "$((TGT_FIRST+2))"
772     done
773
774     rm -rf create_dir $POOL_ROOT/dir?
775     destroy_pool $POOL
776
777     return 0
778 }
779 run_test 13 "Striping characteristics in a pool"
780
781 test_14() {
782     [[ $OSTCOUNT -le 2 ]] && skip "Need atleast 3 OSTs" && return
783
784     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
785     local numfiles=100
786     local i
787
788     # Create a new filesystem that is guaranteed to be balanced.
789     formatall
790     setupall
791
792     create_pool_nofail $POOL
793     create_pool_nofail $POOL2
794
795     add_pool $POOL $TGT_HALF "$TGT_UUID2"
796     add_pool $POOL2 "OST0000" "$FSNAME-OST0000_UUID "
797
798     create_dir $POOL_ROOT/dir1 $POOL 1
799     create_file $POOL_ROOT/dir1/file $POOL 1
800     local OST=$($GETSTRIPE $POOL_ROOT/dir1/file | grep 0x | cut -f2)    
801     i=0
802     while [[ $i -lt $numfiles ]];
803     do
804         OST=$((OST+2))
805         [[ $OST -gt $TGT_MAX ]] && OST=$TGT_FIRST
806
807         # echo "Iteration: $i OST: $OST"
808         create_file $POOL_ROOT/dir1/file${i} $POOL 1
809         check_file_in_osts $POOL_ROOT/dir1/file${i} $OST
810         i=$((i+1))
811     done
812
813     # Fill OST $TGT_FIRST with 10M files
814     create_dir $POOL_ROOT/dir2 $POOL2 1
815     RC=0
816     i=0
817     while [[ $RC -eq 0 ]];
818     do
819       dd if=/dev/zero of=$POOL_ROOT/dir2/f${i} bs=1k count=$((1024*10))
820       RC=$?
821       i=$((i+1))
822     done
823
824     # Leave some space on the OST
825     rm -f $POOL_ROOT/dir2/f0
826     df -h /mnt/ost?
827
828     # OST $TGT_FIRST is no longer favored; but it may still be used.
829     create_dir $POOL_ROOT/dir3 $POOL 1
830     create_file $POOL_ROOT/dir3/file $POOL 1
831     createmany -o $POOL_ROOT/dir3/$tfile_ $numfiles || \
832         error "createmany $POOL_ROOT/dir3/$tfile_ failed!"
833     for file in $POOL_ROOT/dir3/*; do
834         check_file_in_pool $file $POOL
835     done
836
837     rm -rf $POOL_ROOT
838     destroy_pool $POOL
839     destroy_pool $POOL2
840     return 0
841 }
842 run_test 14 "Round robin and QOS striping within a pool"
843
844 test_15() {
845     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
846     local numfiles=100
847     local i=0
848
849     while [[ $i -lt $OSTCOUNT ]]
850     do
851       create_pool_nofail pool${i}
852
853       local tgt=$(printf "$FSNAME-OST%04x_UUID " $i)
854       add_pool pool${i} "$FSNAME-OST[$i]" "$tgt"
855       create_dir $POOL_ROOT/dir${i} pool${i}
856       createmany -o $POOL_ROOT/dir$i/$tfile $numfiles || \
857           error "createmany $POOL_ROOT/dir$i/$tfile failed!"
858
859       for file in $POOL_ROOT/dir$i/*; do
860           check_file_in_osts $file $i
861       done
862
863       i=$((i+1))
864     done
865
866     i=0
867     while [[ $i -lt $OSTCOUNT ]]
868     do
869       destroy_pool pool${i}
870       i=$((i+1))
871     done
872
873     return 0
874 }
875 run_test 15 "One directory per OST/pool"
876
877 test_16() {
878     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
879     local numfiles=10
880     local i=0
881
882     create_pool_nofail $POOL
883
884     add_pool $POOL $TGT_HALF "$TGT_UUID2"
885
886     local dir=$POOL_ROOT/$tdir
887     create_dir $dir $POOL
888
889     for i in $(seq 1 10); do
890         dir=${dir}/dir${i}
891     done
892     mkdir -p $dir
893
894     createmany -o $dir/$tfile $numfiles || \
895           error "createmany $dir/$tfile failed!"
896
897     for file in $dir/*; do
898         check_file_in_pool $file $POOL
899     done
900
901     rm -rf $POOL_ROOT/$tdir
902
903     destroy_pool $POOL
904
905     return 0
906 }
907 run_test 16 "Inheritance of pool properties"
908
909 test_17() {
910     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
911     local numfiles=10
912     local i=0
913
914     create_pool_nofail $POOL
915
916     add_pool $POOL $TGT_ALL "$TGT_UUID"
917
918     local dir=$POOL_ROOT/dir
919     create_dir $dir $POOL
920
921     createmany -o $dir/${tfile}1_ $numfiles || \
922           error "createmany $dir/${tfile}1_ failed!"
923
924     for file in $dir/*; do
925         check_file_in_pool $file $POOL
926     done
927
928     destroy_pool $POOL
929
930     createmany -o $dir/${tfile}2_ $numfiles || \
931           error "createmany $dir/${tfile}2_ failed!"
932
933     rm -rf $dir
934     return 0
935 }
936 run_test 17 "Referencing an empty pool"
937
938 create_perf_one() {
939     local dir=$1/d
940     local numfiles=$2
941     local time
942
943     mkdir -p $dir
944     sync; sleep 5 # give pending IO a chance to go to disk
945     stat=$(createmany -o $dir/${tfile} $numfiles)
946     rm -rf $dir
947     sync
948     time=$(echo $stat | cut -f 5 -d ' ')
949     echo $stat > /dev/stderr
950     echo $time
951 }
952
953 create_perf() {
954     local t1=$(create_perf_one $1 $2)
955     local t2=$(create_perf_one $1 $2)
956     local t3=$(create_perf_one $1 $2)
957     local time=$(echo "scale=2; ( $t1 + $t2 + $t3 ) / 3" | bc)
958
959     echo "$time"
960 }
961
962 test_18() {
963     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
964     local numfiles=10000
965     local i=0
966     local time1
967     local time2
968     local time3
969     local dir=$POOL_ROOT/dir
970     local stat
971     local diff
972
973     time1=$(create_perf $dir $numfiles)
974
975     create_pool_nofail $POOL
976
977     add_pool $POOL $TGT_ALL "$TGT_UUID"
978
979     create_dir $dir $POOL
980     time2=$(create_perf $dir $numfiles)
981
982     destroy_pool $POOL
983
984     time3=$(create_perf $dir $numfiles)
985
986     echo Time taken for $numfiles creates without pools: $time1
987     echo Time taken for $numfiles creates with pools: $time2
988     echo Time taken for $numfiles creates without pools: $time3
989
990     deg=$(echo "scale=2; (($time2 - $time3) * 100 / $time3) > 5" | bc)
991     diff=$(echo "scale=2; ($time2 - $time3) * 100 / $time3" | bc)
992
993     if [[ "$deg" == "1" ]]; then
994         error "Performance degradation with pools is $diff %."
995     else
996         echo  "Performance degradation with pools is $diff %."
997     fi
998     return 0
999 }
1000 run_test 18 "File create in a directory which references a deleted pool"
1001
1002
1003 test_19() {
1004     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1005     local numfiles=12
1006     local dir1=$POOL_ROOT/dir1
1007     local dir2=$POOL_ROOT/dir2
1008     local i=0
1009
1010     create_pool_nofail $POOL
1011
1012     add_pool $POOL $TGT_HALF "$TGT_UUID2"
1013
1014     create_dir $dir1 $POOL
1015     createmany -o $dir1/${tfile} $numfiles || \
1016           error "createmany $dir1/${tfile} failed!"
1017     for file in $dir1/*; do
1018         check_file_in_pool $file $POOL
1019     done
1020
1021     mkdir -p $dir2
1022     createmany -o $dir2/${tfile} $numfiles || \
1023           error "createmany $dir2/${tfile} failed!"
1024     for file in $dir2/*; do
1025         check_file_not_in_pool $file $POOL
1026     done
1027
1028     rm -rf $dir1 $dir2
1029     destroy_pool $POOL
1030
1031     return 0
1032 }
1033 run_test 19 "Pools should not come into play when not specified"
1034
1035 test_20() {
1036     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1037     local numfiles=12
1038     local dir1=$POOL_ROOT/dir1
1039     local dir2=$dir1/dir2
1040     local dir3=$dir1/dir3
1041     local i=0
1042     local TGT
1043
1044     create_pool_nofail $POOL
1045     create_pool_nofail $POOL2
1046
1047     add_pool $POOL $TGT_HALF "$TGT_UUID2"
1048
1049     local start=$((TGT_FIRST+1))
1050     TGT=$(for i in `seq $start 2 $TGT_MAX`; \
1051         do printf "$FSNAME-OST%04x_UUID " $i; done)
1052     add_pool $POOL2 "$FSNAME-OST[$start-$TGT_MAX/2]" "$TGT"
1053
1054     create_dir $dir1 $POOL
1055     create_file $dir1/file1 $POOL2
1056     create_dir $dir2 $POOL2
1057     touch $dir2/file2
1058     mkdir $dir3
1059     $SETSTRIPE -c 1 $dir3 # No pool assignment
1060     touch $dir3/file3
1061     $SETSTRIPE -c 1 $dir2/file4 # No pool assignment
1062
1063     check_file_in_pool $dir1/file1 $POOL2
1064     check_file_in_pool $dir2/file2 $POOL2
1065
1066     check_dir_not_in_pool $dir3 $POOL
1067     check_dir_not_in_pool $dir3 $POOL2
1068
1069     check_file_not_in_pool $dir3/file3 $POOL
1070     check_file_not_in_pool $dir3/file3 $POOL2
1071
1072     check_file_not_in_pool $dir2/file4 $POOL
1073     check_file_not_in_pool $dir2/file4 $POOL2
1074
1075     rm -rf $dir1
1076     destroy_pool $POOL
1077     destroy_pool $POOL2
1078
1079     return 0
1080 }
1081 run_test 20 "Different pools in a directory hierarchy."
1082
1083 test_21() {
1084     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1085     [[ $OSTCOUNT -le 1 ]] && skip "Need atleast 2 OSTs" && return
1086
1087     local numfiles=12
1088     local i=0
1089     local dir=$POOL_ROOT/dir
1090
1091     create_pool_nofail $POOL
1092
1093     add_pool $POOL $TGT_HALF "$TGT_UUID2"
1094
1095     create_dir $dir $POOL $OSTCOUNT
1096     create_file $dir/file1 $POOL $OSTCOUNT
1097     $GETSTRIPE -v $dir/file1
1098     check_file_in_pool $dir/file1 $POOL
1099
1100     rm -rf $dir
1101     destroy_pool $POOL
1102
1103     return 0
1104 }
1105 run_test 21 "OST pool with fewer OSTs than stripe count"
1106
1107 add_loop() {
1108     local pool=$1
1109     local step=$2
1110
1111     echo loop for $pool
1112
1113     for c in $(seq 1 10);
1114     do
1115         echo "Pool $pool, iteration $c"
1116         do_facet $SINGLEMDS lctl pool_add $FSNAME.$pool OST[$TGT_FIRST-$TGT_MAX/$step] 2>/dev/null
1117         local TGT_SECOND=$(($TGT_FIRST+$step))
1118         if [ "$TGT_SECOND" -le "$TGT_MAX" ]; then
1119             do_facet $SINGLEMDS lctl pool_remove $FSNAME.$pool OST[$TGT_SECOND-$TGT_MAX/$step]
1120         fi
1121     done
1122     echo loop for $pool complete
1123 }
1124
1125 test_22() {
1126     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1127     [[ $OSTCOUNT -le 1 ]] && skip "Need at least 2 OSTs" && return
1128
1129     local numfiles=100
1130
1131     create_pool_nofail $POOL
1132     add_pool $POOL "OST0000" "$FSNAME-OST0000_UUID "
1133     create_pool_nofail $POOL2
1134     add_pool $POOL2 "OST0000" "$FSNAME-OST0000_UUID "
1135
1136     add_loop $POOL 1 &
1137     add_loop $POOL2 2 &
1138     sleep 5
1139     create_dir $POOL_ROOT $POOL
1140     createmany -o $POOL_ROOT/${tfile} $numfiles || \
1141           error "createmany $POOL_ROOT/${tfile} failed!"
1142     wait
1143
1144     destroy_pool $POOL
1145     destroy_pool $POOL2
1146
1147     return 0
1148 }
1149 run_test 22 "Simultaneous manipulation of a pool"
1150
1151 test_23() {
1152     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1153     [[ $OSTCOUNT -le 1 ]] && skip "Need atleast 2 OSTs" && return
1154
1155     mkdir -p $POOL_ROOT
1156     check_runas_id $TSTID $TSTID $RUNAS  || {
1157         skip "User $RUNAS_ID does not exist - skipping"
1158         return 0
1159     }
1160
1161     local numfiles=12
1162     local i=0
1163     local TGT
1164     local LIMIT=1024
1165     local dir=$POOL_ROOT/dir
1166     local file1="$dir/$tfile-quota1"
1167     local file2="$dir/$tfile-quota2"
1168
1169     create_pool_nofail $POOL
1170
1171     local TGT=$(for i in `seq $TGT_FIRST 3 $TGT_MAX`; \
1172         do printf "$FSNAME-OST%04x_UUID " $i; done)
1173     add_pool $POOL "$FSNAME-OST[$TGT_FIRST-$TGT_MAX/3]" "$TGT"
1174     create_dir $dir $POOL
1175
1176     $LFS quotaoff -ug $MOUNT
1177     $LFS quotacheck -ug $MOUNT
1178     $LFS setquota -u $TSTUSR -b $LIMIT -B $LIMIT $dir #-i 5 -I 5 $dir
1179
1180     $LFS setstripe $file1 -c 1 -p $POOL
1181     chown $TSTUSR.$TSTUSR $file1
1182     ls -l $file1
1183     type runas
1184
1185     stat=$(LC_ALL=C $RUNAS dd if=/dev/zero of=$file1 bs=1024 count=$((LIMIT*2)) 2>&1)
1186     RC=$?
1187     echo $stat
1188     [[ $RC -eq 0 ]] && error "dd did not fail with EDQUOT."
1189     echo $stat | grep "Disk quota exceeded"
1190     [[ $? -eq 1 ]] && error "dd did not fail with EDQUOT."
1191
1192     echo "second run"
1193     $LFS quotaoff -ug $MOUNT
1194     # $LFS setquota -u $TSTUSR -b $LIMIT -B $LIMIT $dir
1195     chown $TSTUSR.$TSTUSR $dir
1196     i=0
1197     RC=0
1198     while [ $RC -eq 0 ];
1199     do
1200       i=$((i+1))
1201       stat=$(LOCALE=C $RUNAS2 dd if=/dev/zero of=${file2}$i bs=1024 \
1202           count=$((LIMIT*LIMIT)) 2>&1)
1203       RC=$?
1204       if [ $RC -eq 1 ]; then
1205           echo $stat
1206           echo $stat | grep "Disk quota exceeded"
1207           [[ $? -eq 0 ]] && error "dd failed with EDQUOT"
1208
1209           echo $stat | grep "No space left on device"
1210           [[ $? -ne 0 ]] && error "dd did not fail with ENOSPC; " \
1211               "failed with $stat"
1212       fi
1213     done
1214
1215     df -h
1216
1217     rm -rf $POOL_ROOT
1218     destroy_pool $POOL
1219
1220     return 0
1221 }
1222 run_test 23 "OST pools and quota"
1223
1224 test_24() {
1225     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1226     [[ $OSTCOUNT -le 1 ]] && skip "Need atleast 2 OSTs" && return
1227
1228     local numfiles=10
1229     local i=0
1230     local TGT
1231     local dir
1232     local res
1233
1234
1235     create_pool_nofail $POOL
1236
1237     add_pool $POOL $TGT_ALL "$TGT_UUID"
1238
1239     create_dir $POOL_ROOT/dir1 $POOL $OSTCOUNT
1240
1241     mkdir $POOL_ROOT/dir2
1242     $SETSTRIPE $POOL_ROOT/dir2 -p $POOL -s 65536 -i 0 -c 1 || \
1243         error "$SETSTRIPE $POOL_ROOT/dir2 failed"
1244
1245     mkdir $POOL_ROOT/dir3
1246     $SETSTRIPE $POOL_ROOT/dir3 -s 65536 -i 0 -c 1 || \
1247         error "$SETSTRIPE $POOL_ROOT/dir3 failed"
1248
1249     mkdir $POOL_ROOT/dir4
1250
1251     for i in $(seq 1 4);
1252     do
1253       dir=${POOL_ROOT}/dir${i}
1254       local pool
1255       local pool1
1256       local count
1257       local count1
1258       local index
1259       local size
1260       local size1
1261
1262       createmany -o $dir/${tfile} $numfiles || \
1263           error "createmany $dir/${tfile} failed!"
1264       res=$($GETSTRIPE -v $dir | grep "^stripe_count:")
1265       if [ $? -ne 0 ]; then
1266           res=$($GETSTRIPE -v $dir | grep "^(Default) ")
1267           pool=$(cut -f 9 -d ' ' <<< $res)
1268           index=$(cut -f 7 -d ' ' <<< $res)
1269           size=$(cut -f 5 -d ' ' <<< $res)
1270           count=$(cut -f 3 -d ' ' <<< $res)
1271       else
1272           pool=$(cut -f 8 -d ' ' <<< $res)
1273           index=$(cut -f 6 -d ' ' <<< $res)
1274           size=$(cut -f 4 -d ' ' <<< $res)
1275           count=$(cut -f 2 -d ' ' <<< $res)
1276       fi
1277
1278       for file in $dir/*; do
1279           if [ "$pool" != "" ]; then
1280               check_file_in_pool $file $pool
1281           fi
1282           pool1=$($GETSTRIPE -v $file | grep "^pool:" |\
1283               tr -d '[:blank:]' | cut -f 2 -d ':')
1284           count1=$($GETSTRIPE -v $file | grep "^lmm_stripe_count:" |\
1285               tr -d '[:blank:]' | cut -f 2 -d ':')
1286           size1=$($GETSTRIPE -v $file | grep "^lmm_stripe_size:" |\
1287               tr -d '[:blank:]' | cut -f 2 -d ':')
1288           [[ "$pool" != "$pool1" ]] && \
1289               error "Pool name ($pool) not inherited in $file($pool1)"
1290           [[ "$count" != "$count1" ]] && \
1291               error "Stripe count ($count) not inherited in $file ($count1)"
1292           [[ "$size" != "$size1" ]] && [[ "$size" != "0" ]] && \
1293               error "Stripe size ($size) not inherited in $file ($size1)"
1294       done 
1295     done
1296
1297     rm -rf $POOL_ROOT
1298     destroy_pool $POOL
1299
1300     return 0
1301 }
1302 run_test 24 "Independence of pool from other setstripe parameters"
1303
1304 test_25() {
1305     local dev=$(mdsdevname ${SINGLEMDS//mds/})
1306     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1307
1308     mkdir -p $POOL_ROOT
1309
1310     for i in $(seq 10); do
1311         create_pool_nofail pool$i
1312         do_facet $SINGLEMDS lctl pool_add $FSNAME.pool$i OST0000
1313         stop $SINGLEMDS || return 1
1314         start $SINGLEMDS ${dev} $MDS_MOUNT_OPTS  || \
1315             { error "Failed to start $SINGLEMDS after stopping" && break; }
1316         client_df
1317
1318         # Veriy that the pool got created and is usable
1319         echo "Creating a file in pool$i"
1320         create_file $POOL_ROOT/file$i pool$i || break
1321         check_file_in_pool $POOL_ROOT/file$i pool$i || break
1322     done
1323
1324     rm -rf $POOL_ROOT
1325     for i in $(seq 10); do
1326         destroy_pool pool$i
1327     done
1328 }
1329 run_test 25 "Create new pool and restart MDS ======================="
1330
1331 log "cleanup: ======================================================"
1332 cd $ORIG_PWD
1333 cleanup_tests
1334 check_and_cleanup_lustre
1335 echo '=========================== finished ==============================='
1336 [ -f "$POOLSLOG" ] && cat $POOLSLOG && grep -q FAIL $POOLSLOG && exit 1 || true
1337 echo "$0: completed"