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