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