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