Whamcloud - gitweb
b=23409 add "-i" to the setstripe usage and manpage
[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() {
934     local cdir=$1/d
935     local numfiles=$2
936     local time
937
938     mkdir -p $cdir
939     sync; sleep 5 # give pending IO a chance to go to disk
940     stat=$(createmany -o $cdir/${tfile} $numfiles)
941     rm -rf $cdir
942     sync
943     time=$(echo $stat | cut -f 5 -d ' ')
944     echo $stat >> /dev/stderr
945     echo $time
946 }
947
948 test_18() {
949     set_cleanup_trap
950     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
951     local numfiles=9877
952     local plaindir=$POOL_ROOT/plaindir
953     local pooldir=$POOL_ROOT/pooldir
954         local t1=0
955         local t2=0
956         local t3=0
957         local diff
958
959     for i in $(seq 1 3);
960     do
961         echo "Create performance, iteration $i, $numfiles files x 3"
962
963                 time1=$(create_perf $plaindir $numfiles)
964                 echo "iter $i: $numfiles creates without pool: $time1"
965                 t1=$(echo "scale=2; $t1 + $time1" | bc)
966
967                 create_pool_nofail $POOL > /dev/null
968                 add_pool $POOL $TGT_ALL "$TGT_UUID" > /dev/null
969                 create_dir $pooldir $POOL
970                 time2=$(create_perf $pooldir $numfiles)
971                 echo "iter $i: $numfiles creates with pool: $time2"
972                 t2=$(echo "scale=2; $t2 + $time2" | bc)
973
974                 destroy_pool $POOL > /dev/null
975                 time3=$(create_perf $pooldir $numfiles)
976                 echo "iter $i: $numfiles creates with missing pool: $time3"
977                 t3=$(echo "scale=2; $t3 + $time3" | bc)
978
979                 echo
980         done
981
982         time1=$(echo "scale=2; $t1 / $i" | bc)
983         echo Avg time taken for $numfiles creates without pool: $time1
984         time2=$(echo "scale=2; $t2 / $i" | bc)
985         echo Avg time taken for $numfiles creates with pool: $time2
986         time3=$(echo "scale=2; $t3 / $i" | bc)
987         echo Avg time taken for $numfiles creates with missing pool: $time3
988
989         # Set this high until we establish a baseline for what the degradation
990         # is / should be
991         max=15
992     diff=$(echo "scale=2; ($time2 - $time1) * 100 / $time1" | bc)
993     echo  "No pool to wide pool: $diff %."
994     deg=$(echo "scale=2; $diff > $max" | bc)
995     [ "$deg" == "1" ] && error "Degradation with wide pool is $diff % (> $max %)"
996
997     diff=$(echo "scale=2; ($time3 - $time1) * 100 / $time1" | bc)
998     echo  "No pool to missing pool: $diff %."
999     deg=$(echo "scale=2; $diff > $max" | bc)
1000     [ "$deg" == "1" ] && error "Degradation with missing pool is $diff % (> $max %)"
1001
1002     return 0
1003 }
1004 run_test 18 "File create in a directory which references a deleted pool"
1005
1006
1007 test_19() {
1008     set_cleanup_trap
1009     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1010     local numfiles=12
1011     local dir1=$POOL_ROOT/dir1
1012     local dir2=$POOL_ROOT/dir2
1013     local i=0
1014
1015     create_pool_nofail $POOL
1016
1017     add_pool $POOL $TGT_HALF "$TGT_UUID2"
1018
1019     create_dir $dir1 $POOL
1020     createmany -o $dir1/${tfile} $numfiles || \
1021           error "createmany $dir1/${tfile} failed!"
1022     for file in $dir1/*; do
1023         check_file_in_pool $file $POOL
1024     done
1025
1026     mkdir -p $dir2
1027     createmany -o $dir2/${tfile} $numfiles || \
1028           error "createmany $dir2/${tfile} failed!"
1029     for file in $dir2/*; do
1030         check_file_not_in_pool $file $POOL
1031     done
1032
1033     rm -rf $dir1 $dir2
1034
1035     return 0
1036 }
1037 run_test 19 "Pools should not come into play when not specified"
1038
1039 test_20() {
1040     set_cleanup_trap
1041     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1042     local numfiles=12
1043     local dir1=$POOL_ROOT/dir1
1044     local dir2=$dir1/dir2
1045     local dir3=$dir1/dir3
1046     local i=0
1047     local TGT
1048
1049     create_pool_nofail $POOL
1050     create_pool_nofail $POOL2
1051
1052     add_pool $POOL $TGT_HALF "$TGT_UUID2"
1053
1054     local start=$((TGT_FIRST+1))
1055     TGT=$(for i in `seq $start 2 $TGT_MAX`; \
1056         do printf "$FSNAME-OST%04x_UUID " $i; done)
1057     add_pool $POOL2 "$FSNAME-OST[$start-$TGT_MAX/2]" "$TGT"
1058
1059     create_dir $dir1 $POOL
1060     create_file $dir1/file1 $POOL2
1061     create_dir $dir2 $POOL2
1062     touch $dir2/file2
1063     mkdir $dir3
1064     $SETSTRIPE -c 1 $dir3 # No pool assignment
1065     touch $dir3/file3
1066     $SETSTRIPE -c 1 $dir2/file4 # No pool assignment
1067
1068     check_file_in_pool $dir1/file1 $POOL2
1069     check_file_in_pool $dir2/file2 $POOL2
1070
1071     check_dir_not_in_pool $dir3 $POOL
1072     check_dir_not_in_pool $dir3 $POOL2
1073
1074     check_file_not_in_pool $dir3/file3 $POOL
1075     check_file_not_in_pool $dir3/file3 $POOL2
1076
1077     check_file_not_in_pool $dir2/file4 $POOL
1078     check_file_not_in_pool $dir2/file4 $POOL2
1079
1080     rm -rf $dir1
1081
1082     return 0
1083 }
1084 run_test 20 "Different pools in a directory hierarchy."
1085
1086 test_21() {
1087     set_cleanup_trap
1088     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1089     [[ $OSTCOUNT -le 1 ]] && skip_env "Need atleast 2 OSTs" && return
1090
1091     local numfiles=12
1092     local i=0
1093     local dir=$POOL_ROOT/dir
1094
1095     create_pool_nofail $POOL
1096
1097     add_pool $POOL $TGT_HALF "$TGT_UUID2"
1098
1099     create_dir $dir $POOL $OSTCOUNT
1100     create_file $dir/file1 $POOL $OSTCOUNT
1101     $GETSTRIPE -v $dir/file1
1102     check_file_in_pool $dir/file1 $POOL
1103
1104     rm -rf $dir
1105
1106     return 0
1107 }
1108 run_test 21 "OST pool with fewer OSTs than stripe count"
1109
1110 add_loop() {
1111     local pool=$1
1112     local step=$2
1113
1114     echo loop for $pool
1115
1116     for c in $(seq 1 10);
1117     do
1118         echo "Pool $pool, iteration $c"
1119         do_facet $SINGLEMDS lctl pool_add $FSNAME.$pool OST[$TGT_FIRST-$TGT_MAX/$step] 2>/dev/null
1120         local TGT_SECOND=$(($TGT_FIRST+$step))
1121         if [ "$TGT_SECOND" -le "$TGT_MAX" ]; then
1122             do_facet $SINGLEMDS lctl pool_remove $FSNAME.$pool OST[$TGT_SECOND-$TGT_MAX/$step]
1123         fi
1124     done
1125     echo loop for $pool complete
1126 }
1127
1128 test_22() {
1129     set_cleanup_trap
1130     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1131     [[ $OSTCOUNT -le 1 ]] && skip_env "Need at least 2 OSTs" && return
1132
1133     local numfiles=100
1134
1135     create_pool_nofail $POOL
1136     add_pool $POOL "OST0000" "$FSNAME-OST0000_UUID "
1137     create_pool_nofail $POOL2
1138     add_pool $POOL2 "OST0000" "$FSNAME-OST0000_UUID "
1139
1140     add_loop $POOL 1 &
1141     add_loop $POOL2 2 &
1142     sleep 5
1143     create_dir $POOL_ROOT $POOL
1144     createmany -o $POOL_ROOT/${tfile} $numfiles || \
1145           error "createmany $POOL_ROOT/${tfile} failed!"
1146     wait
1147
1148     return 0
1149 }
1150 run_test 22 "Simultaneous manipulation of a pool"
1151
1152 test_23() {
1153     set_cleanup_trap
1154     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1155     [[ $OSTCOUNT -le 1 ]] && skip_env "Need atleast 2 OSTs" && return
1156
1157     mkdir -p $POOL_ROOT
1158     check_runas_id $TSTID $TSTID $RUNAS  || {
1159         skip_env "User $RUNAS_ID does not exist - skipping"
1160         return 0
1161     }
1162
1163     local i=0
1164     local TGT
1165     local BLK_SZ=1024
1166     local BUNIT_SZ=1024         # min block quota unit(kB)
1167     local LOVNAME=`lctl get_param -n llite.*.lov.common_name | tail -n 1`
1168     local OSTCOUNT=`lctl get_param -n lov.$LOVNAME.numobd`
1169     local LIMIT
1170     local dir=$POOL_ROOT/dir
1171     local file="$dir/$tfile-quota"
1172
1173     create_pool_nofail $POOL
1174
1175     local TGT=$(for i in `seq $TGT_FIRST 3 $TGT_MAX`; \
1176         do printf "$FSNAME-OST%04x_UUID " $i; done)
1177     add_pool $POOL "$FSNAME-OST[$TGT_FIRST-$TGT_MAX/3]" "$TGT"
1178     create_dir $dir $POOL
1179
1180     $LFS quotaoff -ug $MOUNT
1181     $LFS quotacheck -ug $MOUNT
1182     LIMIT=$((BUNIT_SZ * (OSTCOUNT + 1)))
1183     $LFS setquota -u $TSTUSR -b $LIMIT -B $LIMIT $dir
1184     sleep 3
1185     $LFS quota -v -u $TSTUSR $dir
1186
1187     $LFS setstripe $file -c 1 -p $POOL
1188     chown $TSTUSR.$TSTUSR $file
1189     ls -l $file
1190     type runas
1191
1192     LOCALE=C $RUNAS dd if=/dev/zero of=$file bs=$BLK_SZ count=$((BUNIT_SZ*2)) || true
1193     $LFS quota -v -u $TSTUSR $dir
1194     cancel_lru_locks osc
1195     stat=$(LOCALE=C $RUNAS dd if=/dev/zero of=$file bs=$BLK_SZ count=$BUNIT_SZ seek=$((BUNIT_SZ*2)) 2>&1)
1196     RC=$?
1197     echo $stat
1198     [[ $RC -eq 0 ]] && error "dd did not fail with EDQUOT."
1199     echo $stat | grep "Disk quota exceeded" > /dev/null
1200     [[ $? -eq 1 ]] && error "dd did not fail with EDQUOT."
1201     $LFS quota -v -u $TSTUSR $dir
1202
1203     echo "second run"
1204     $LFS quotaoff -ug $MOUNT
1205     # $LFS setquota -u $TSTUSR -b $LIMIT -B $LIMIT $dir
1206     chown $TSTUSR.$TSTUSR $dir
1207     i=0
1208     RC=0
1209     while [ $RC -eq 0 ];
1210     do
1211       i=$((i+1))
1212       stat=$(LOCALE=C $RUNAS2 dd if=/dev/zero of=${file}$i bs=1M \
1213           count=$((LIMIT*LIMIT)) 2>&1)
1214       RC=$?
1215       if [ $RC -eq 1 ]; then
1216           echo $stat
1217           echo $stat | grep "Disk quota exceeded"
1218           [[ $? -eq 0 ]] && error "dd failed with EDQUOT"
1219
1220           echo $stat | grep "No space left on device"
1221           [[ $? -ne 0 ]] && error "dd did not fail with ENOSPC; " \
1222               "failed with $stat"
1223       fi
1224     done
1225
1226     df -h
1227
1228     rm -rf $POOL_ROOT
1229
1230     return 0
1231 }
1232 run_test 23 "OST pools and quota"
1233
1234 test_24() {
1235     set_cleanup_trap
1236     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1237     [[ $OSTCOUNT -le 1 ]] && skip_env "Need atleast 2 OSTs" && return
1238
1239     local numfiles=10
1240     local i=0
1241     local TGT
1242     local dir
1243     local res
1244
1245
1246     create_pool_nofail $POOL
1247
1248     add_pool $POOL $TGT_ALL "$TGT_UUID"
1249
1250     create_dir $POOL_ROOT/dir1 $POOL $OSTCOUNT
1251
1252     mkdir $POOL_ROOT/dir2
1253     $SETSTRIPE $POOL_ROOT/dir2 -p $POOL -s 65536 -i 0 -c 1 || \
1254         error "$SETSTRIPE $POOL_ROOT/dir2 failed"
1255
1256     mkdir $POOL_ROOT/dir3
1257     $SETSTRIPE $POOL_ROOT/dir3 -s 65536 -i 0 -c 1 || \
1258         error "$SETSTRIPE $POOL_ROOT/dir3 failed"
1259
1260     mkdir $POOL_ROOT/dir4
1261
1262     for i in $(seq 1 4);
1263     do
1264       dir=${POOL_ROOT}/dir${i}
1265       local pool
1266       local pool1
1267       local count
1268       local count1
1269       local index
1270       local size
1271       local size1
1272
1273       createmany -o $dir/${tfile} $numfiles || \
1274           error "createmany $dir/${tfile} failed!"
1275       res=$($GETSTRIPE -v $dir | grep "^stripe_count:")
1276       if [ $? -ne 0 ]; then
1277           res=$($GETSTRIPE -v $dir | grep "^(Default) ")
1278           pool=$(cut -f 9 -d ' ' <<< $res)
1279           index=$(cut -f 7 -d ' ' <<< $res)
1280           size=$(cut -f 5 -d ' ' <<< $res)
1281           count=$(cut -f 3 -d ' ' <<< $res)
1282       else
1283           pool=$(cut -f 8 -d ' ' <<< $res)
1284           index=$(cut -f 6 -d ' ' <<< $res)
1285           size=$(cut -f 4 -d ' ' <<< $res)
1286           count=$(cut -f 2 -d ' ' <<< $res)
1287       fi
1288
1289       for file in $dir/*; do
1290           if [ "$pool" != "" ]; then
1291               check_file_in_pool $file $pool
1292           fi
1293           pool1=$($GETSTRIPE -v $file | grep "^pool:" |\
1294               tr -d '[:blank:]' | cut -f 2 -d ':')
1295           count1=$($GETSTRIPE -v $file | grep "^lmm_stripe_count:" |\
1296               tr -d '[:blank:]' | cut -f 2 -d ':')
1297           size1=$($GETSTRIPE -v $file | grep "^lmm_stripe_size:" |\
1298               tr -d '[:blank:]' | cut -f 2 -d ':')
1299           [[ "$pool" != "$pool1" ]] && \
1300               error "Pool name ($pool) not inherited in $file($pool1)"
1301           [[ "$count" != "$count1" ]] && \
1302               error "Stripe count ($count) not inherited in $file ($count1)"
1303           [[ "$size" != "$size1" ]] && [[ "$size" != "0" ]] && \
1304               error "Stripe size ($size) not inherited in $file ($size1)"
1305       done 
1306     done
1307
1308     rm -rf $POOL_ROOT
1309
1310     return 0
1311 }
1312 run_test 24 "Independence of pool from other setstripe parameters"
1313
1314 test_25() {
1315     set_cleanup_trap
1316     local dev=$(mdsdevname ${SINGLEMDS//mds/})
1317     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1318
1319     mkdir -p $POOL_ROOT
1320
1321     for i in $(seq 10); do
1322         create_pool_nofail pool$i
1323         do_facet $SINGLEMDS "lctl pool_add $FSNAME.pool$i OST0000; sync"
1324         wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.pool$i | \
1325             sort -u | tr '\n' ' ' " "$FSNAME-OST0000_UUID " || \
1326             error "pool_add failed: $1; $2"
1327
1328         stop $SINGLEMDS || return 1
1329         start $SINGLEMDS ${dev} $MDS_MOUNT_OPTS  || \
1330             { error "Failed to start $SINGLEMDS after stopping" && break; }
1331         wait_osc_import_state mds ost FULL
1332         clients_up
1333
1334         wait_mds_ost_sync 
1335         # Veriy that the pool got created and is usable
1336         df $POOL_ROOT > /dev/null
1337         sleep 5
1338         # Make sure OST0 can be striped on
1339         $SETSTRIPE -o 0 -c 1 $POOL_ROOT/$tfile
1340         STR=$($GETSTRIPE $POOL_ROOT/$tfile | grep 0x | cut -f2 | tr -d " ")
1341         rm $POOL_ROOT/$tfile
1342         if [[ "$STR" == "0" ]]; then
1343                 echo "Creating a file in pool$i"
1344                 create_file $POOL_ROOT/file$i pool$i || break
1345                 check_file_in_pool $POOL_ROOT/file$i pool$i || break
1346         else
1347                 echo "OST 0 seems to be unavailable.  Try later."
1348         fi
1349     done
1350
1351     rm -rf $POOL_ROOT
1352 }
1353 run_test 25 "Create new pool and restart MDS ======================="
1354
1355 test_26() {
1356     local OSTCOUNT=`lctl get_param -n lov.$LOVNAME.*clilov*.numobd`
1357     [[ $OSTCOUNT -le 2 ]] && skip_env "Need at least 3 OSTs" && return
1358     set_cleanup_trap
1359     local dev=$(mdsdevname ${SINGLEMDS//mds/})
1360     local POOL_ROOT=${POOL_ROOT:-$DIR/$tdir}
1361
1362     mkdir -p $POOL_ROOT
1363
1364     create_pool_nofail $POOL 
1365  
1366     do_facet $SINGLEMDS "lctl pool_add $FSNAME.pool1 OST0000; sync"
1367     wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.pool1 | \
1368     sort -u | grep $FSNAME-OST0000_UUID " "$FSNAME-OST0000_UUID" || \
1369     error "pool_add failed: $1; $2"
1370   
1371     do_facet $SINGLEMDS "lctl pool_add $FSNAME.pool1 OST0002; sync"
1372     wait_update $HOSTNAME "lctl get_param -n lov.$FSNAME-*.pools.pool1 | \
1373     sort -u | grep $FSNAME-OST0002_UUID" "$FSNAME-OST0002_UUID" || \
1374     error "pool_add failed: $1; $2"
1375   
1376     # Veriy that the pool got created and is usable
1377     df $POOL_ROOT
1378     echo "Creating files in $POOL"
1379
1380     for ((i=0;i<10;i++)); do
1381         #OBD_FAIL_MDS_OSC_CREATE_FAIL     0x147  
1382         #Fail OST0000 to make sure the objects create on the other ost in the pool 
1383         do_facet $SINGLEMDS lctl set_param fail_loc=0x147
1384         do_facet $SINGLEMDS lctl set_param fail_val=0
1385         create_file $POOL_ROOT/file$i $POOL 1 -1 || break
1386         do_facet $SINGLEMDS lctl set_param fail_loc=0
1387         check_file_in_pool $POOL_ROOT/file$i $POOL || break
1388     done
1389     rm -rf $POOL_ROOT
1390 }
1391 run_test 26 "Choose other OSTs in the pool first in the creation remedy"
1392
1393 log "cleanup: ======================================================"
1394 cd $ORIG_PWD
1395 cleanup_pools $FSNAME
1396 check_and_cleanup_lustre
1397 echo '=========================== finished ==============================='
1398 [ -f "$POOLSLOG" ] && cat $POOLSLOG && grep -q FAIL $POOLSLOG && exit 1 || true
1399 echo "$0: completed"