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