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