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