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