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