Whamcloud - gitweb
e3996842de78cd5bda7595b5f2a290cdeeec83fd
[fs/lustre-release.git] / lustre / tests / conf-sanity.sh
1 #!/bin/bash
2
3 # FIXME - there is no reason to use all of these different
4 #   return codes, espcially when most of them are mapped to something
5 #   else anyway.  The combination of test number and return code
6 #   figure out what failed.
7
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11
12 # bug number for skipped test:
13 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT"
14 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15
16 if [ "$FAILURE_MODE" = "HARD" ]; then
17         CONFIG_EXCEPTIONS="24a " && \
18         echo "Except the tests: $CONFIG_EXCEPTIONS for FAILURE_MODE=$FAILURE_MODE, bug 23573" && \
19         ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
20 fi
21
22 # bug number for skipped test:
23 # a tool to create lustre filesystem images
24 ALWAYS_EXCEPT="32newtarball $ALWAYS_EXCEPT"
25
26 SRCDIR=`dirname $0`
27 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
28
29 PTLDEBUG=${PTLDEBUG:--1}
30 SAVE_PWD=$PWD
31 LUSTRE=${LUSTRE:-`dirname $0`/..}
32 RLUSTRE=${RLUSTRE:-$LUSTRE}
33 export MULTIOP=${MULTIOP:-multiop}
34
35 . $LUSTRE/tests/test-framework.sh
36 init_test_env $@
37
38 # use small MDS + OST size to speed formatting time
39 # do not use too small MDSSIZE/OSTSIZE, which affect the default jouranl size
40 MDSSIZE=200000
41 OSTSIZE=200000
42 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
43
44 if ! combined_mgs_mds; then
45     # bug number for skipped test:    23954
46     ALWAYS_EXCEPT="$ALWAYS_EXCEPT       24b"
47 fi
48
49 # STORED_MDSSIZE is used in test_18
50 if [ -n "$MDSSIZE" ]; then
51     STORED_MDSSIZE=$MDSSIZE
52 fi
53
54 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
55 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
56         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
57 fi
58
59 init_logging
60
61 #
62 require_dsh_mds || exit 0
63 require_dsh_ost || exit 0
64 #
65 [ "$SLOW" = "no" ] && EXCEPT_SLOW="30a 31 45"
66
67
68 assert_DIR
69
70 reformat() {
71         formatall
72 }
73
74 writeconf1() {
75         local facet=$1
76         local dev=$2
77
78         stop ${facet} -f
79         rm -f ${facet}active
80         # who knows if/where $TUNEFS is installed?  Better reformat if it fails...
81         do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" ||
82                 { echo "tunefs failed, reformatting instead" && reformat_and_config && return 1; }
83         return 0
84 }
85
86 writeconf() {
87         # we need ldiskfs
88         load_modules
89         # if writeconf fails anywhere, we reformat everything
90         writeconf1 mds `mdsdevname 1` || return 0
91         writeconf1 ost1 `ostdevname 1` || return 0
92         writeconf1 ost2 `ostdevname 2` || return 0
93 }
94
95 gen_config() {
96         # The MGS must be started before the OSTs for a new fs, so start
97         # and stop to generate the startup logs.
98         start_mds
99         start_ost
100         wait_osc_import_state mds ost FULL
101         stop_ost
102         stop_mds
103 }
104
105 reformat_and_config() {
106         reformat
107         if ! combined_mgs_mds ; then
108                 start_mgs
109         fi
110         gen_config
111 }
112
113 start_mgs () {
114         echo "start mgs"
115         start mgs $MGSDEV $MGS_MOUNT_OPTS
116 }
117
118 start_mds() {
119         local facet=$SINGLEMDS
120         # we can not use MDSDEV1 here because SINGLEMDS could be set not to mds1 only
121         local num=$(echo $facet | tr -d "mds")
122         local dev=$(mdsdevname $num)
123         echo "start mds service on `facet_active_host $facet`"
124         start $facet ${dev} $MDS_MOUNT_OPTS $@ || return 94
125 }
126
127 start_mgsmds() {
128         if ! combined_mgs_mds ; then
129                 start_mgs
130         fi
131         start_mds $@
132 }
133
134 stop_mds() {
135         echo "stop mds service on `facet_active_host $SINGLEMDS`"
136         # These tests all use non-failover stop
137         stop $SINGLEMDS -f  || return 97
138 }
139
140 stop_mgs() {
141        echo "stop mgs service on `facet_active_host mgs`"
142        # These tests all use non-failover stop
143        stop mgs -f  || return 97
144 }
145
146 start_ost() {
147         echo "start ost1 service on `facet_active_host ost1`"
148         start ost1 `ostdevname 1` $OST_MOUNT_OPTS $@ || return 95
149 }
150
151 stop_ost() {
152         echo "stop ost1 service on `facet_active_host ost1`"
153         # These tests all use non-failover stop
154         stop ost1 -f  || return 98
155 }
156
157 start_ost2() {
158         echo "start ost2 service on `facet_active_host ost2`"
159         start ost2 `ostdevname 2` $OST_MOUNT_OPTS $@ || return 92
160 }
161
162 stop_ost2() {
163         echo "stop ost2 service on `facet_active_host ost2`"
164         # These tests all use non-failover stop
165         stop ost2 -f  || return 93
166 }
167
168 mount_client() {
169         local MOUNTPATH=$1
170         echo "mount $FSNAME on ${MOUNTPATH}....."
171         zconf_mount `hostname` $MOUNTPATH  || return 96
172 }
173
174 remount_client() {
175         local mountopt="-o remount,$1"
176         local MOUNTPATH=$2
177         echo "remount '$1' lustre on ${MOUNTPATH}....."
178         zconf_mount `hostname`  $MOUNTPATH "$mountopt"  || return 96
179 }
180
181 umount_client() {
182         local MOUNTPATH=$1
183         echo "umount lustre on ${MOUNTPATH}....."
184         zconf_umount `hostname` $MOUNTPATH || return 97
185 }
186
187 manual_umount_client(){
188         local rc
189         local FORCE=$1
190         echo "manual umount lustre on ${MOUNT}...."
191         do_facet client "umount -d ${FORCE} $MOUNT"
192         rc=$?
193         return $rc
194 }
195
196 setup() {
197         start_mds || error "MDT start failed"
198         start_ost || error "OST start failed"
199         mount_client $MOUNT || error "client start failed"
200         client_up || error "client_up failed"
201 }
202
203 setup_noconfig() {
204         if ! combined_mgs_mds ; then
205                 start_mgs
206         fi
207
208         start_mds
209         start_ost
210         mount_client $MOUNT
211 }
212
213 unload_modules_conf () {
214         if combined_mgs_mds || ! local_mode; then
215                 unload_modules || return 1
216         fi
217 }
218
219 cleanup_nocli() {
220         stop_ost || return 202
221         stop_mds || return 201
222         unload_modules_conf || return 203
223 }
224
225 cleanup() {
226         umount_client $MOUNT || return 200
227         cleanup_nocli || return $?
228 }
229
230 check_mount() {
231         do_facet client "cp /etc/passwd $DIR/a" || return 71
232         do_facet client "rm $DIR/a" || return 72
233         # make sure lustre is actually mounted (touch will block,
234         # but grep won't, so do it after)
235         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
236         echo "setup single mount lustre success"
237 }
238
239 check_mount2() {
240         do_facet client "touch $DIR/a" || return 71
241         do_facet client "rm $DIR/a" || return 72
242         do_facet client "touch $DIR2/a" || return 73
243         do_facet client "rm $DIR2/a" || return 74
244         echo "setup double mount lustre success"
245 }
246
247 build_test_filter
248
249 if [ "$ONLY" == "setup" ]; then
250         setup
251         exit
252 fi
253
254 if [ "$ONLY" == "cleanup" ]; then
255         cleanup
256         exit
257 fi
258
259 init_gss
260
261 #create single point mountpoint
262
263 reformat_and_config
264
265 test_0() {
266         setup
267         check_mount || return 41
268         cleanup || return $?
269 }
270 run_test 0 "single mount setup"
271
272 test_1() {
273         start_mds || error "MDT start failed"
274         start_ost
275         echo "start ost second time..."
276         start_ost && error "2nd OST start should fail"
277         mount_client $MOUNT || error "client start failed"
278         check_mount || return 42
279         cleanup || return $?
280 }
281 run_test 1 "start up ost twice (should return errors)"
282
283 test_2() {
284         start_mds
285         echo "start mds second time.."
286         start_mds && error "2nd MDT start should fail"
287         start_ost
288         mount_client $MOUNT
289         check_mount || return 43
290         cleanup || return $?
291 }
292 run_test 2 "start up mds twice (should return err)"
293
294 test_3() {
295         setup
296         #mount.lustre returns an error if already in mtab
297         mount_client $MOUNT && error "2nd client mount should fail"
298         check_mount || return 44
299         cleanup || return $?
300 }
301 run_test 3 "mount client twice (should return err)"
302
303 test_4() {
304         setup
305         touch $DIR/$tfile || return 85
306         stop_ost -f
307         cleanup
308         eno=$?
309         # ok for ost to fail shutdown
310         if [ 202 -ne $eno ]; then
311                 return $eno;
312         fi
313         return 0
314 }
315 run_test 4 "force cleanup ost, then cleanup"
316
317 test_5a() {     # was test_5
318         setup
319         touch $DIR/$tfile || return 1
320         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
321
322         stop_mds -f || return 2
323
324         # cleanup may return an error from the failed
325         # disconnects; for now I'll consider this successful
326         # if all the modules have unloaded.
327         umount -d $MOUNT &
328         UMOUNT_PID=$!
329         sleep 6
330         echo "killing umount"
331         kill -TERM $UMOUNT_PID
332         echo "waiting for umount to finish"
333         wait $UMOUNT_PID
334         if grep " $MOUNT " /proc/mounts; then
335                 echo "test 5: /proc/mounts after failed umount"
336                 umount $MOUNT &
337                 UMOUNT_PID=$!
338                 sleep 2
339                 echo "killing umount"
340                 kill -TERM $UMOUNT_PID
341                 echo "waiting for umount to finish"
342                 wait $UMOUNT_PID
343                 grep " $MOUNT " /proc/mounts && echo "test 5: /proc/mounts after second umount" && return 11
344         fi
345
346         manual_umount_client
347         # stop_mds is a no-op here, and should not fail
348         cleanup_nocli || return $?
349         # df may have lingering entry
350         manual_umount_client
351         # mtab may have lingering entry
352         local WAIT=0
353         local MAX_WAIT=20
354         local sleep=1
355         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
356                 sleep $sleep
357                 grep -q $MOUNT" " /etc/mtab || break
358                 echo "Waiting /etc/mtab updated ... "
359                 WAIT=$(( WAIT + sleep))
360         done
361         [ "$WAIT" -eq "$MAX_WAIT" ] && error "/etc/mtab is not updated in $WAIT secs"
362         echo "/etc/mtab updated in $WAIT secs"
363 }
364 run_test 5a "force cleanup mds, then cleanup"
365
366 cleanup_5b () {
367         trap 0
368         start_mgs
369 }
370
371 test_5b() {
372         grep " $MOUNT " /etc/mtab && \
373                 error false "unexpected entry in mtab before mount" && return 10
374
375         local rc=0
376         start_ost
377         if ! combined_mgs_mds ; then
378                 trap cleanup_5b EXIT ERR
379                 start_mds
380                 stop mgs
381         fi
382
383         [ -d $MOUNT ] || mkdir -p $MOUNT
384         mount_client $MOUNT && rc=1
385         grep " $MOUNT " /etc/mtab && \
386                 error "$MOUNT entry in mtab after failed mount" && rc=11
387         umount_client $MOUNT
388         # stop_mds is a no-op here, and should not fail
389         cleanup_nocli || rc=$?
390         if ! combined_mgs_mds ; then
391                 cleanup_5b
392         fi
393         return $rc
394 }
395 run_test 5b "Try to start a client with no MGS (should return errs)"
396
397 test_5c() {
398         grep " $MOUNT " /etc/mtab && \
399                 error false "unexpected entry in mtab before mount" && return 10
400
401         local rc=0
402         start_mds
403         start_ost
404         [ -d $MOUNT ] || mkdir -p $MOUNT
405         local oldfs="${FSNAME}"
406         FSNAME="wrong.${FSNAME}"
407         mount_client $MOUNT || :
408         FSNAME=${oldfs}
409         grep " $MOUNT " /etc/mtab && \
410                 error "$MOUNT entry in mtab after failed mount" && rc=11
411         umount_client $MOUNT
412         cleanup_nocli  || rc=$?
413         return $rc
414 }
415 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
416
417 test_5d() {
418         grep " $MOUNT " /etc/mtab && \
419                 error false "unexpected entry in mtab before mount" && return 10
420
421         [ "$(facet_fstype ost1)" = "zfs" ] &&
422                 skip "LU-2059: no local config for ZFS OSTs" && return
423
424         local rc=0
425         start_ost
426         start_mds
427         stop_ost -f
428         mount_client $MOUNT || rc=1
429         cleanup  || rc=$?
430         grep " $MOUNT " /etc/mtab && \
431                 error "$MOUNT entry in mtab after unmount" && rc=11
432         return $rc
433 }
434 run_test 5d "mount with ost down"
435
436 test_5e() {
437         grep " $MOUNT " /etc/mtab && \
438                 error false "unexpected entry in mtab before mount" && return 10
439
440         local rc=0
441         start_mds
442         start_ost
443
444 #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
445         do_facet client "lctl set_param fail_loc=0x80000506"
446         mount_client $MOUNT || echo "mount failed (not fatal)"
447         cleanup  || rc=$?
448         grep " $MOUNT " /etc/mtab && \
449                 error "$MOUNT entry in mtab after unmount" && rc=11
450         return $rc
451 }
452 run_test 5e "delayed connect, don't crash (bug 10268)"
453
454 test_5f() {
455         if combined_mgs_mds ; then
456                 skip "combined mgs and mds"
457                 return 0
458         fi
459
460         grep " $MOUNT " /etc/mtab && \
461                 error false "unexpected entry in mtab before mount" && return 10
462
463         local rc=0
464         start_ost
465         [ -d $MOUNT ] || mkdir -p $MOUNT
466         mount_client $MOUNT &
467         local pid=$!
468         echo client_mount pid is $pid
469
470         sleep 5
471
472         if ! ps -f -p $pid >/dev/null; then
473                 wait $pid
474                 rc=$?
475                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
476                 error "mount returns $rc, expected to hang"
477                 rc=11
478                 cleanup || rc=$?
479                 return $rc
480         fi
481
482         # start mds
483         start_mds
484
485         # mount should succeed after start mds
486         wait $pid
487         rc=$?
488         [ $rc -eq 0 ] || error "mount returned $rc"
489         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
490         cleanup || return $?
491         return $rc
492 }
493 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
494
495 test_6() {
496         setup
497         manual_umount_client
498         mount_client ${MOUNT} || return 87
499         touch $DIR/a || return 86
500         cleanup  || return $?
501 }
502 run_test 6 "manual umount, then mount again"
503
504 test_7() {
505         setup
506         manual_umount_client
507         cleanup_nocli || return $?
508 }
509 run_test 7 "manual umount, then cleanup"
510
511 test_8() {
512         setup
513         mount_client $MOUNT2
514         check_mount2 || return 45
515         umount_client $MOUNT2
516         cleanup  || return $?
517 }
518 run_test 8 "double mount setup"
519
520 test_9() {
521         start_ost
522
523         do_facet ost1 lctl set_param debug=\'inode trace\' || return 1
524         do_facet ost1 lctl set_param subsystem_debug=\'mds ost\' || return 1
525
526         CHECK_PTLDEBUG="`do_facet ost1 lctl get_param -n debug`"
527         if [ "$CHECK_PTLDEBUG" ] && { \
528            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
529            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
530            echo "lnet.debug success"
531         else
532            echo "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
533            return 1
534         fi
535         CHECK_SUBSYS="`do_facet ost1 lctl get_param -n subsystem_debug`"
536         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
537            echo "lnet.subsystem_debug success"
538         else
539            echo "lnet.subsystem_debug: want 'mds ost', have '$CHECK_SUBSYS'"
540            return 1
541         fi
542         stop_ost || return $?
543 }
544 run_test 9 "test ptldebug and subsystem for mkfs"
545
546 is_blkdev () {
547         local facet=$1
548         local dev=$2
549         local size=${3:-""}
550
551         local rc=0
552         do_facet $facet "test -b $dev" || rc=1
553         if [[ "$size" ]]; then
554                 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k count=1 skip=$size 2>&1" |\
555                         awk '($3 == "in") { print $1 }')
556                 [[ $in  = "1+0" ]] || rc=1
557         fi
558         return $rc
559 }
560
561 #
562 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
563 # But with new MDS stack we don't care about the mode of local objects
564 # anymore, so this test is removed. See bug 22944 for more details.
565 #
566
567 test_17() {
568         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
569                 skip "Only applicable to ldiskfs-based MDTs"
570                 return
571         fi
572
573         setup
574         check_mount || return 41
575         cleanup || return $?
576
577         echo "Remove mds config log"
578         if ! combined_mgs_mds ; then
579                 stop mgs
580         fi
581
582         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' $MGSDEV || return \$?" || return $?
583
584         if ! combined_mgs_mds ; then
585                 start_mgs
586         fi
587
588         start_ost
589         start_mds && return 42
590         reformat_and_config
591 }
592 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
593
594 test_18() {
595         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
596                 skip "Only applicable to ldiskfs-based MDTs"
597                 return
598         fi
599
600         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
601
602         local MIN=2000000
603
604         local OK=
605         # check if current MDSSIZE is large enough
606         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE && \
607                 log "use MDSSIZE=$MDSSIZE"
608
609         # check if the global config has a large enough MDSSIZE
610         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] && [ $STORED_MDSSIZE -ge $MIN ] && \
611                 OK=1 && myMDSSIZE=$STORED_MDSSIZE && \
612                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
613
614         # check if the block device is large enough
615         [ -z "$OK" ] && $(is_blkdev $SINGLEMDS $MDSDEV $MIN) && OK=1 &&
616                 myMDSSIZE=$MIN && log "use device $MDSDEV with MIN=$MIN"
617
618         # check if a loopback device has enough space for fs metadata (5%)
619
620         if [ -z "$OK" ]; then
621                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
622                         awk '($1 != "Filesystem") {print $4}')
623                 ! [ -z "$SPACE" ]  &&  [ $SPACE -gt $((MIN / 20)) ] && \
624                         OK=1 && myMDSSIZE=$MIN && \
625                         log "use file $MDSDEV with MIN=$MIN"
626         fi
627
628         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
629
630
631         echo "mount mds with large journal..."
632
633         local OLD_MDSSIZE=$MDSSIZE
634         MDSSIZE=$myMDSSIZE
635
636         reformat_and_config
637         echo "mount lustre system..."
638         setup
639         check_mount || return 41
640
641         echo "check journal size..."
642         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
643         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
644                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
645         else
646                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
647         fi
648
649         cleanup || return $?
650
651         MDSSIZE=$OLD_MDSSIZE
652         reformat_and_config
653 }
654 run_test 18 "check mkfs creates large journals"
655
656 test_19a() {
657         start_mds || return 1
658         stop_mds -f || return 2
659 }
660 run_test 19a "start/stop MDS without OSTs"
661
662 test_19b() {
663         [ "$(facet_fstype ost1)" = "zfs" ] &&
664                 skip "LU-2059: no local config for ZFS OSTs" && return
665
666         start_ost || return 1
667         stop_ost -f || return 2
668 }
669 run_test 19b "start/stop OSTs without MDS"
670
671 test_20() {
672         # first format the ost/mdt
673         start_mds
674         start_ost
675         mount_client $MOUNT
676         check_mount || return 43
677         rm -f $DIR/$tfile
678         remount_client ro $MOUNT || return 44
679         touch $DIR/$tfile && echo "$DIR/$tfile created incorrectly" && return 45
680         [ -e $DIR/$tfile ] && echo "$DIR/$tfile exists incorrectly" && return 46
681         remount_client rw $MOUNT || return 47
682         touch $DIR/$tfile
683         [ ! -f $DIR/$tfile ] && echo "$DIR/$tfile missing" && return 48
684         MCNT=`grep -c $MOUNT /etc/mtab`
685         [ "$MCNT" -ne 1 ] && echo "$MOUNT in /etc/mtab $MCNT times" && return 49
686         umount_client $MOUNT
687         stop_mds
688         stop_ost
689 }
690 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
691
692 test_21a() {
693         start_mds
694         start_ost
695         wait_osc_import_state mds ost FULL
696         stop_ost
697         stop_mds
698 }
699 run_test 21a "start mds before ost, stop ost first"
700
701 test_21b() {
702         [ "$(facet_fstype ost1)" = "zfs" ] &&
703                 skip "LU-2059: no local config for ZFS OSTs" && return
704
705         start_ost
706         start_mds
707         wait_osc_import_state mds ost FULL
708         stop_mds
709         stop_ost
710 }
711 run_test 21b "start ost before mds, stop mds first"
712
713 test_21c() {
714         start_ost
715         start_mds
716         start_ost2
717         wait_osc_import_state mds ost2 FULL
718         stop_ost
719         stop_ost2
720         stop_mds
721         #writeconf to remove all ost2 traces for subsequent tests
722         writeconf
723 }
724 run_test 21c "start mds between two osts, stop mds last"
725
726 test_21d() {
727         if combined_mgs_mds ; then
728                 skip "need separate mgs device" && return 0
729         fi
730         stopall
731
732         reformat
733
734         start_mgs
735         start_ost
736         start_ost2
737         start_mds
738         wait_osc_import_state mds ost2 FULL
739
740         stop_ost
741         stop_ost2
742         stop_mds
743         stop_mgs
744         #writeconf to remove all ost2 traces for subsequent tests
745         writeconf
746         start_mgs
747 }
748 run_test 21d "start mgs then ost and then mds"
749
750 test_22() {
751         start_mds
752
753         echo Client mount with ost in logs, but none running
754         start_ost
755         # wait until mds connected to ost and open client connection
756         wait_osc_import_state mds ost FULL
757         stop_ost
758         mount_client $MOUNT
759         # check_mount will block trying to contact ost
760         mcreate $DIR/$tfile || return 40
761         rm -f $DIR/$tfile || return 42
762         umount_client $MOUNT
763         pass
764
765         echo Client mount with a running ost
766         start_ost
767         if $GSS; then
768                 # if gss enabled, wait full time to let connection from
769                 # mds to ost be established, due to the mismatch between
770                 # initial connect timeout and gss context negotiation timeout.
771                 # This perhaps could be remove after AT landed.
772                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
773                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
774         fi
775         mount_client $MOUNT
776         wait_osc_import_state mds ost FULL
777         wait_osc_import_state client ost FULL
778         check_mount || return 41
779         pass
780
781         cleanup
782 }
783 run_test 22 "start a client before osts (should return errs)"
784
785 test_23a() {    # was test_23
786         setup
787         # fail mds
788         stop $SINGLEMDS
789         # force down client so that recovering mds waits for reconnect
790         local running=$(grep -c $MOUNT /proc/mounts) || true
791         if [ $running -ne 0 ]; then
792                 echo "Stopping client $MOUNT (opts: -f)"
793                 umount -f $MOUNT
794         fi
795
796         # enter recovery on mds
797         start_mds
798         # try to start a new client
799         mount_client $MOUNT &
800         sleep 5
801         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
802         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
803         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
804         ps --ppid $MOUNT_PID
805         ps --ppid $MOUNT_LUSTRE_PID
806         echo "waiting for mount to finish"
807         ps -ef | grep mount
808         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
809         # SIGTERM works but it does not spread to offspring processses
810         kill -s TERM $MOUNT_PID
811         kill -s TERM $MOUNT_LUSTRE_PID
812         # we can not wait $MOUNT_PID because it is not a child of this shell
813         local PID1
814         local PID2
815         local WAIT=0
816         local MAX_WAIT=30
817         local sleep=1
818         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
819                 sleep $sleep
820                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
821                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
822                 echo PID1=$PID1
823                 echo PID2=$PID2
824                 [ -z "$PID1" -a -z "$PID2" ] && break
825                 echo "waiting for mount to finish ... "
826                 WAIT=$(( WAIT + sleep))
827         done
828         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
829                 error "MOUNT_PID $MOUNT_PID and "\
830                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
831                 ps -ef | grep mount
832         fi
833         stop_mds || error
834         stop_ost || error
835 }
836 run_test 23a "interrupt client during recovery mount delay"
837
838 umount_client $MOUNT
839 cleanup_nocli
840
841 test_23b() {    # was test_23
842         start_mds
843         start_ost
844         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
845         lctl set_param fail_loc=0x80000313
846         mount_client $MOUNT
847         cleanup
848 }
849 run_test 23b "Simulate -EINTR during mount"
850
851 fs2mds_HOST=$mds_HOST
852 fs2ost_HOST=$ost_HOST
853
854 MDSDEV1_2=$fs2mds_DEV
855 OSTDEV1_2=$fs2ost_DEV
856 OSTDEV2_2=$fs3ost_DEV
857
858 cleanup_24a() {
859         trap 0
860         echo "umount $MOUNT2 ..."
861         umount $MOUNT2 || true
862         echo "stopping fs2mds ..."
863         stop fs2mds -f || true
864         echo "stopping fs2ost ..."
865         stop fs2ost -f || true
866 }
867
868 test_24a() {
869         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
870
871         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
872                 is_blkdev $SINGLEMDS $MDSDEV && \
873                 skip_env "mixed loopback and real device not working" && return
874         fi
875
876         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
877
878         local fs2mdsdev=$(mdsdevname 1_2)
879         local fs2ostdev=$(ostdevname 1_2)
880         local fs2mdsvdev=$(mdsvdevname 1_2)
881         local fs2ostvdev=$(ostvdevname 1_2)
882
883         # test 8-char fsname as well
884         local FSNAME2=test1234
885         add fs2mds $(mkfs_opts mds1) --nomgs --mgsnode=$MGSNID \
886                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
887
888         add fs2ost $(mkfs_opts ost1) --fsname=${FSNAME2} --reformat \
889                 $fs2ostdev $fs2ostvdev || exit 10
890
891         setup
892         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
893         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
894         mkdir -p $MOUNT2
895         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
896         # 1 still works
897         check_mount || return 2
898         # files written on 1 should not show up on 2
899         cp /etc/passwd $DIR/$tfile
900         sleep 10
901         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
902         # 2 should work
903         sleep 5
904         cp /etc/passwd $MOUNT2/b || return 3
905         rm $MOUNT2/b || return 4
906         # 2 is actually mounted
907         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
908         # failover
909         facet_failover fs2mds
910         facet_failover fs2ost
911         df
912         umount_client $MOUNT
913         # the MDS must remain up until last MDT
914         stop_mds
915         MDS=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
916         [ -z "$MDS" ] && error "No MDT" && return 8
917         cleanup_24a
918         cleanup_nocli || return 6
919 }
920 run_test 24a "Multiple MDTs on a single node"
921
922 test_24b() {
923         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
924
925         if [ -z "$fs2mds_DEV" ]; then
926                 local dev=${SINGLEMDS}_dev
927                 local MDSDEV=${!dev}
928                 is_blkdev $SINGLEMDS $MDSDEV && \
929                 skip_env "mixed loopback and real device not working" && return
930         fi
931
932         local fs2mdsdev=$(mdsdevname 1_2)
933         local fs2mdsvdev=$(mdsvdevname 1_2)
934
935         add fs2mds $(mkfs_opts mds1) --mgs --fsname=${FSNAME}2 --reformat \
936                 $fs2mdsdev $fs2mdsvdev || exit 10
937         setup
938         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
939         cleanup || return 6
940 }
941 run_test 24b "Multiple MGSs on a single node (should return err)"
942
943 test_25() {
944         setup
945         check_mount || return 2
946         local MODULES=$($LCTL modules | awk '{ print $2 }')
947         rmmod $MODULES 2>/dev/null || true
948         cleanup || return 6
949 }
950 run_test 25 "Verify modules are referenced"
951
952 test_26() {
953     load_modules
954     # we need modules before mount for sysctl, so make sure...
955     do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
956 #define OBD_FAIL_MDS_FS_SETUP            0x135
957     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000135"
958     start_mds && echo MDS started && return 1
959     lctl get_param -n devices
960     DEVS=$(lctl get_param -n devices | egrep -v MG | wc -l)
961     [ $DEVS -gt 0 ] && return 2
962     # start mds to drop writeconf setting
963     start_mds || return 3
964     stop_mds || return 4
965     unload_modules_conf || return $?
966 }
967 run_test 26 "MDT startup failure cleans LOV (should return errs)"
968
969 test_27a() {
970         [ "$(facet_fstype ost1)" = "zfs" ] &&
971                 skip "LU-2059: no local config for ZFS OSTs" && return
972
973         start_ost || return 1
974         start_mds || return 2
975         echo "Requeue thread should have started: "
976         ps -e | grep ll_cfg_requeue
977         set_conf_param_and_check ost1                                         \
978            "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" \
979            "$FSNAME-OST0000.ost.client_cache_seconds" || return 3
980         cleanup_nocli
981 }
982 run_test 27a "Reacquire MGS lock if OST started first"
983
984 test_27b() {
985         # FIXME. ~grev
986         setup
987         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }')
988
989         facet_failover $SINGLEMDS
990         set_conf_param_and_check $SINGLEMDS                             \
991                 "lctl get_param -n mdt.$device.identity_acquire_expire" \
992                 "$device.mdt.identity_acquire_expire" || return 3
993         set_conf_param_and_check client                                 \
994                 "lctl get_param -n mdc.$device-mdc-*.max_rpcs_in_flight"\
995                 "$device.mdc.max_rpcs_in_flight" || return 4
996         check_mount
997         cleanup
998 }
999 run_test 27b "Reacquire MGS lock after failover"
1000
1001 test_28() {
1002         setup
1003         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1004         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1005         ORIG=$($TEST)
1006         FINAL=$(($ORIG + 1))
1007         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 3
1008         FINAL=$(($FINAL + 1))
1009         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 4
1010         umount_client $MOUNT || return 200
1011         mount_client $MOUNT
1012         RESULT=$($TEST)
1013         if [ $RESULT -ne $FINAL ]; then
1014             echo "New config not seen: wanted $FINAL got $RESULT"
1015             return 4
1016         else
1017             echo "New config success: got $RESULT"
1018         fi
1019         set_conf_param_and_check client "$TEST" "$PARAM" $ORIG || return 5
1020         cleanup
1021 }
1022 run_test 28 "permanent parameter setting"
1023
1024 test_29() {
1025         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
1026         setup > /dev/null 2>&1
1027         start_ost2
1028         sleep 10
1029
1030         local PARAM="$FSNAME-OST0001.osc.active"
1031         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
1032         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1033
1034         ACTV=$(lctl get_param -n $PROC_ACT)
1035         DEAC=$((1 - $ACTV))
1036         set_conf_param_and_check client \
1037                 "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
1038         # also check ost_server_uuid status
1039         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
1040         if [ -z "$RESULT" ]; then
1041             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
1042             return 3
1043         else
1044             echo "Live client success: got $RESULT"
1045         fi
1046
1047         # check MDT too
1048         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0001)
1049         mdtosc=${mdtosc/-MDT*/-MDT\*}
1050         local MPROC="osc.$mdtosc.active"
1051         local MAX=30
1052         local WAIT=0
1053         while [ 1 ]; do
1054             sleep 5
1055             RESULT=`do_facet $SINGLEMDS " lctl get_param -n $MPROC"`
1056             [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
1057             if [ $RESULT -eq $DEAC ]; then
1058                 echo "MDT deactivated also after $WAIT sec (got $RESULT)"
1059                 break
1060             fi
1061             WAIT=$((WAIT + 5))
1062             if [ $WAIT -eq $MAX ]; then
1063                 echo "MDT not deactivated: wanted $DEAC got $RESULT"
1064                 return 4
1065             fi
1066             echo "Waiting $(($MAX - $WAIT)) secs for MDT deactivated"
1067         done
1068
1069         # test new client starts deactivated
1070         umount_client $MOUNT || return 200
1071         mount_client $MOUNT
1072         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1073         if [ -z "$RESULT" ]; then
1074             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
1075             return 5
1076         else
1077             echo "New client success: got $RESULT"
1078         fi
1079
1080         # make sure it reactivates
1081         set_conf_param_and_check client \
1082                 "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
1083
1084         umount_client $MOUNT
1085         stop_ost2
1086         cleanup_nocli
1087         #writeconf to remove all ost2 traces for subsequent tests
1088         writeconf
1089 }
1090 run_test 29 "permanently remove an OST"
1091
1092 test_30a() {
1093         setup
1094
1095         echo Big config llog
1096         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1097         ORIG=$($TEST)
1098         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1099         for i in ${LIST[@]}; do
1100                 set_conf_param_and_check client "$TEST" \
1101                         "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
1102         done
1103         # make sure client restart still works
1104         umount_client $MOUNT
1105         mount_client $MOUNT || return 4
1106         [ "$($TEST)" -ne "$i" ] && error "Param didn't stick across restart $($TEST) != $i"
1107         pass
1108
1109         echo Erase parameter setting
1110         do_facet mgs "$LCTL conf_param -d $FSNAME.llite.max_read_ahead_whole_mb" || return 6
1111         umount_client $MOUNT
1112         mount_client $MOUNT || return 6
1113         FINAL=$($TEST)
1114         echo "deleted (default) value=$FINAL, orig=$ORIG"
1115         # assumes this parameter started at the default value
1116         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1117
1118         cleanup
1119 }
1120 run_test 30a "Big config llog and conf_param deletion"
1121
1122 test_30b() {
1123         setup
1124
1125         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1126         # numerical part of it. Hopefully that's not already a failover address for
1127         # the server.
1128         OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
1129         ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1130         NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1131         NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1132         echo "Using fake nid $NEW"
1133
1134         TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1135         set_conf_param_and_check client "$TEST" \
1136                 "$FSNAME-OST0000.failover.node" $NEW ||
1137                 error "didn't add failover nid $NEW"
1138         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1139         echo $NIDS
1140         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1141         echo "should have 2 failover nids: $NIDCOUNT"
1142         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1143         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" || error "conf_param delete failed"
1144         umount_client $MOUNT
1145         mount_client $MOUNT || return 3
1146
1147         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1148         echo $NIDS
1149         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1150         echo "only 1 final nid should remain: $NIDCOUNT"
1151         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1152
1153         cleanup
1154 }
1155 run_test 30b "Remove failover nids"
1156
1157 test_31() { # bug 10734
1158         # ipaddr must not exist
1159         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
1160         cleanup
1161 }
1162 run_test 31 "Connect to non-existent node (shouldn't crash)"
1163
1164 #
1165 # This is not really a test but a tool to create new disk
1166 # image tarballs for the upgrade tests.
1167 #
1168 # Disk image tarballs should be created on single-node
1169 # clusters by running this test with default configurations
1170 # plus a few mandatory environment settings that are verified
1171 # at the beginning of the test.
1172 #
1173 test_32newtarball() {
1174         local version
1175         local dst=.
1176         local src=/etc/rc.d
1177         local tmp=$TMP/t32_image_create
1178
1179         if [ $FSNAME != t32fs -o $MDSCOUNT -ne 1 -o                                                             \
1180                  \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o $OSTCOUNT -ne 1 -o                      \
1181                  -z "$OSTDEV1" ]; then
1182                 error "Needs FSNAME=t32fs MDSCOUNT=1 MDSDEV1=<nonexistent_file>"        \
1183                           "(or MDSDEV, in the case of b1_8) OSTCOUNT=1"                                 \
1184                           "OSTDEV1=<nonexistent_file>"
1185         fi
1186
1187         mkdir $tmp || {
1188                 echo "Found stale $tmp"
1189                 return 1
1190         }
1191
1192         mkdir $tmp/src
1193         tar cf - -C $src . | tar xf - -C $tmp/src
1194
1195         formatall
1196
1197         setupall
1198         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1199         stopall
1200
1201         mkdir $tmp/img
1202
1203         setupall
1204         pushd /mnt/$FSNAME
1205         ls -Rni --time-style=+%s >$tmp/img/list
1206         find . ! -name .lustre -type f -exec sha1sum {} \; |
1207                 sort -k 2 >$tmp/img/sha1sums
1208         popd
1209         $LCTL get_param -n version | head -n 1 |
1210                 sed -e 's/^lustre: *//' >$tmp/img/commit
1211         stopall
1212
1213         pushd $tmp/src
1214         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1215         popd
1216
1217         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1218                 echo "Data verification failed"
1219         fi
1220
1221         uname -r >$tmp/img/kernel
1222         uname -m >$tmp/img/arch
1223
1224         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1225         mv $OSTDEV1 $tmp/img
1226
1227         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1228                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1229         dst=$(cd $dst; pwd)
1230         pushd $tmp/img
1231         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1232         popd
1233
1234         rm -r $tmp
1235 }
1236 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1237
1238 #
1239 # The list of applicable tarballs is returned via the caller's
1240 # variable "tarballs".
1241 #
1242 t32_check() {
1243         local node=$(facet_active_host $SINGLEMDS)
1244         local r="do_node $node"
1245
1246         if [ "$CLIENTONLY" ]; then
1247                 skip "Client-only testing"
1248                 exit 0
1249         fi
1250
1251         if ! $r which $TUNEFS; then
1252                 skip_env "tunefs.lustre required on $node"
1253                 exit 0
1254         fi
1255
1256         if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1257                 skip "LU-2200: Test cannot run over Infiniband"
1258                 exit 0
1259         fi
1260
1261         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1262
1263         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 -name \'disk*-$IMGTYPE.tar.bz2\')
1264
1265         if [ -z "$tarballs" ]; then
1266                 skip "No applicable tarballs found"
1267                 exit 0
1268         fi
1269 }
1270
1271 t32_test_cleanup() {
1272         local node=$(facet_active_host $SINGLEMDS)
1273         local r="do_node $node"
1274         local tmp=$TMP/t32
1275         local rc=$?
1276
1277         if $shall_cleanup_lustre; then
1278                 umount $tmp/mnt/lustre || rc=$?
1279         fi
1280         if $shall_cleanup_mdt; then
1281                 $r umount -d $tmp/mnt/mdt || rc=$?
1282         fi
1283         if $shall_cleanup_ost; then
1284                 $r umount -d $tmp/mnt/ost || rc=$?
1285         fi
1286         $r rm -rf $tmp || rc=$?
1287         rm -rf $tmp || rc=$?
1288         return $rc
1289 }
1290
1291 t32_bits_per_long() {
1292         #
1293         # Yes, this is not meant to be perfect.
1294         #
1295         case $1 in
1296                 ppc64|x86_64)
1297                         echo -n 64;;
1298                 i*86)
1299                         echo -n 32;;
1300         esac
1301 }
1302
1303 t32_reload_modules() {
1304         local node=$1
1305         local all_removed=false
1306         local i=0
1307
1308         while ((i < 20)); do
1309                 echo "Unloading modules on $node: Attempt $i"
1310                 do_rpc_nodes $node $LUSTRE_RMMOD $(facet_fstype $SINGLEMDS) &&
1311                         all_removed=true
1312                 do_rpc_nodes $node check_mem_leak || return 1
1313                 if $all_removed; then
1314                         load_modules
1315                         return 0
1316                 fi
1317                 sleep 5
1318                 i=$((i + 1))
1319         done
1320         echo "Unloading modules on $node: Given up"
1321         return 1
1322 }
1323
1324 t32_wait_til_devices_gone() {
1325         local node=$1
1326         local devices
1327         local i=0
1328
1329         echo wait for devices to go
1330         while ((i < 20)); do
1331                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1332                 echo $device
1333                 ((devices == 0)) && return 1
1334                 sleep 5
1335                 i=$((i + 1))
1336         done
1337         echo "waiting for devices on $node: Given up"
1338         return 1
1339 }
1340
1341 t32_test() {
1342         local tarball=$1
1343         local writeconf=$2
1344         local shall_cleanup_mdt=false
1345         local shall_cleanup_ost=false
1346         local shall_cleanup_lustre=false
1347         local node=$(facet_active_host $SINGLEMDS)
1348         local r="do_node $node"
1349         local tmp=$TMP/t32
1350         local img_commit
1351         local img_kernel
1352         local img_arch
1353         local fsname=t32fs
1354         local nid=$($r $LCTL list_nids | head -1)
1355         local mopts
1356         local uuid
1357         local nrpcs_orig
1358         local nrpcs
1359         local list
1360
1361         trap 'trap - RETURN; t32_test_cleanup' RETURN
1362
1363         mkdir -p $tmp/mnt/lustre
1364         $r mkdir -p $tmp/mnt/{mdt,ost}
1365         $r tar xjvf $tarball -S -C $tmp || {
1366                 error_noexit "Unpacking the disk image tarball"
1367                 return 1
1368         }
1369         img_commit=$($r cat $tmp/commit)
1370         img_kernel=$($r cat $tmp/kernel)
1371         img_arch=$($r cat $tmp/arch)
1372         echo "Upgrading from $(basename $tarball), created with:"
1373         echo "  Commit: $img_commit"
1374         echo "  Kernel: $img_kernel"
1375         echo "    Arch: $img_arch"
1376
1377         $r $LCTL set_param debug="$PTLDEBUG"
1378
1379         $r $TUNEFS --dryrun $tmp/mdt || {
1380                 error_noexit "tunefs.lustre before mounting the MDT"
1381                 return 1
1382         }
1383         if [ "$writeconf" ]; then
1384                 mopts=loop,writeconf
1385         else
1386                 mopts=loop,exclude=$fsname-OST0000
1387         fi
1388
1389         t32_wait_til_devices_gone $node
1390
1391         $r mount -t lustre -o $mopts $tmp/mdt $tmp/mnt/mdt || {
1392                 error_noexit "Mounting the MDT"
1393                 return 1
1394         }
1395         shall_cleanup_mdt=true
1396
1397         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1398                 error_noexit "Getting MDT UUID"
1399                 return 1
1400         }
1401         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1402                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1403                 return 1
1404         fi
1405
1406         $r $TUNEFS --dryrun $tmp/ost || {
1407                 error_noexit "tunefs.lustre before mounting the OST"
1408                 return 1
1409         }
1410         if [ "$writeconf" ]; then
1411                 mopts=loop,mgsnode=$nid,$writeconf
1412         else
1413                 mopts=loop,mgsnode=$nid
1414         fi
1415         $r mount -t lustre -o $mopts $tmp/ost $tmp/mnt/ost || {
1416                 error_noexit "Mounting the OST"
1417                 return 1
1418         }
1419         shall_cleanup_ost=true
1420
1421         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1422                 error_noexit "Getting OST UUID"
1423                 return 1
1424         }
1425         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1426                 error_noexit "Unexpected OST UUID: \"$uuid\""
1427                 return 1
1428         fi
1429
1430         $r $LCTL conf_param $fsname-OST0000.osc.max_dirty_mb=15 || {
1431                 error_noexit "Setting \"max_dirty_mb\""
1432                 return 1
1433         }
1434         $r $LCTL conf_param $fsname-OST0000.failover.node=$nid || {
1435                 error_noexit "Setting OST \"failover.node\""
1436                 return 1
1437         }
1438         $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1439                 error_noexit "Setting \"max_rpcs_in_flight\""
1440                 return 1
1441         }
1442         $r $LCTL conf_param $fsname-MDT0000.failover.node=$nid || {
1443                 error_noexit "Setting MDT \"failover.node\""
1444                 return 1
1445         }
1446         $r $LCTL pool_new $fsname.interop || {
1447                 error_noexit "Setting \"interop\""
1448                 return 1
1449         }
1450         $r $LCTL conf_param $fsname-MDT0000.lov.stripesize=4M || {
1451                 error_noexit "Setting \"lov.stripesize\""
1452                 return 1
1453         }
1454
1455         if [ "$writeconf" ]; then
1456                 mount -t lustre $nid:/$fsname $tmp/mnt/lustre || {
1457                         error_noexit "Mounting the client"
1458                         return 1
1459                 }
1460                 shall_cleanup_lustre=true
1461                 $LCTL set_param debug="$PTLDEBUG"
1462
1463                 if $r test -f $tmp/sha1sums; then
1464                         $r sort -k 2 $tmp/sha1sums >$tmp/sha1sums.orig
1465                         pushd $tmp/mnt/lustre
1466                         find ! -name .lustre -type f -exec sha1sum {} \; |
1467                                 sort -k 2 >$tmp/sha1sums || {
1468                                 error_noexit "sha1sum"
1469                                 return 1
1470                         }
1471                         popd
1472                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
1473                                 error_noexit "sha1sum verification failed"
1474                                 return 1
1475                         fi
1476                 else
1477                         echo "sha1sum verification skipped"
1478                 fi
1479
1480                 if $r test -f $tmp/list; then
1481                         #
1482                         # There is not a Test Framework API to copy files to or
1483                         # from a remote node.
1484                         #
1485                         $r sort -k 6 $tmp/list >$tmp/list.orig
1486                         pushd $tmp/mnt/lustre
1487                         ls -Rni --time-style=+%s | sort -k 6 >$tmp/list || {
1488                                 error_noexit "ls"
1489                                 return 1
1490                         }
1491                         popd
1492                         #
1493                         # 32-bit and 64-bit clients use different algorithms to
1494                         # convert FIDs into inode numbers.  Hence, remove the inode
1495                         # numbers from the lists, if the original list was created
1496                         # on an architecture with different number of bits per
1497                         # "long".
1498                         #
1499                         if [ $(t32_bits_per_long $(uname -m)) !=                                                \
1500                                  $(t32_bits_per_long $img_arch) ]; then
1501                                 echo "Different number of bits per \"long\" from the disk image"
1502                                 for list in list.orig list; do
1503                                         sed -i -e 's/^[0-9]\+[ \t]\+//' $tmp/$list
1504                                 done
1505                         fi
1506                         if ! diff -ub $tmp/list.orig $tmp/list; then
1507                                 error_noexit "list verification failed"
1508                                 return 1
1509                         fi
1510                 else
1511                         echo "list verification skipped"
1512                 fi
1513
1514                 #
1515                 # When adding new data verification tests, please check for
1516                 # the presence of the required reference files first, like
1517                 # the "sha1sums" and "list" tests above, to avoid the need to
1518                 # regenerate every image for each test addition.
1519                 #
1520
1521                 nrpcs_orig=$($LCTL get_param -n mdc.*.max_rpcs_in_flight) || {
1522                         error_noexit "Getting \"max_rpcs_in_flight\""
1523                         return 1
1524                 }
1525                 nrpcs=$((nrpcs_orig + 5))
1526                 $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=$nrpcs || {
1527                         error_noexit "Changing \"max_rpcs_in_flight\""
1528                         return 1
1529                 }
1530                 wait_update $HOSTNAME "$LCTL get_param -n mdc.*.max_rpcs_in_flight"     \
1531                             $nrpcs || {
1532                         error_noexit "Verifying \"max_rpcs_in_flight\""
1533                         return 1
1534                 }
1535
1536                 umount $tmp/mnt/lustre || {
1537                         error_noexit "Unmounting the client"
1538                         return 1
1539                 }
1540                 shall_cleanup_lustre=false
1541         else
1542                 $r umount -d $tmp/mnt/mdt || {
1543                         error_noexit "Unmounting the MDT"
1544                         return 1
1545                 }
1546                 shall_cleanup_mdt=false
1547                 $r umount -d $tmp/mnt/ost || {
1548                         error_noexit "Unmounting the OST"
1549                         return 1
1550                 }
1551                 shall_cleanup_ost=false
1552
1553                 t32_reload_modules $node || {
1554                         error_noexit "Reloading modules"
1555                         return 1
1556                 }
1557
1558                 # mount a second time to make sure we didnt leave upgrade flag on
1559                 $r $TUNEFS --dryrun $tmp/mdt || {
1560                         error_noexit "tunefs.lustre before remounting the MDT"
1561                         return 1
1562                 }
1563                 $r mount -t lustre -o loop,exclude=$fsname-OST0000 $tmp/mdt                     \
1564                                  $tmp/mnt/mdt || {
1565                         error_noexit "Remounting the MDT"
1566                         return 1
1567                 }
1568                 shall_cleanup_mdt=true
1569         fi
1570 }
1571
1572 test_32a() {
1573         local tarballs
1574         local tarball
1575         local rc=0
1576
1577         t32_check
1578         for tarball in $tarballs; do
1579                 t32_test $tarball || rc=$?
1580         done
1581         return $rc
1582 }
1583 run_test 32a "Upgrade (not live)"
1584
1585 test_32b() {
1586         local tarballs
1587         local tarball
1588         local rc=0
1589
1590         t32_check
1591         for tarball in $tarballs; do
1592                 t32_test $tarball writeconf || rc=$?
1593         done
1594         return $rc
1595 }
1596 run_test 32b "Upgrade with writeconf"
1597
1598 test_33a() { # bug 12333, was test_33
1599         local rc=0
1600         local FSNAME2=test-123
1601         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1602         local mkfsoptions
1603
1604         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1605
1606         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1607                 local dev=${SINGLEMDS}_dev
1608                 local MDSDEV=${!dev}
1609                 is_blkdev $SINGLEMDS $MDSDEV && \
1610                 skip_env "mixed loopback and real device not working" && return
1611         fi
1612
1613         local fs2mdsdev=$(mdsdevname 1_2)
1614         local fs2ostdev=$(ostdevname 1_2)
1615         local fs2mdsvdev=$(mdsvdevname 1_2)
1616         local fs2ostvdev=$(ostvdevname 1_2)
1617
1618         if [ $(facet_fstype mds1) == ldiskfs ]; then
1619                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
1620         fi
1621
1622         add fs2mds $(mkfs_opts mds1) --fsname=${FSNAME2} --reformat \
1623                 $mkfsoptions $fs2mdsdev $fs2mdsvdev || exit 10
1624         add fs2ost $(mkfs_opts ost1) --mgsnode=$MGSNID --fsname=${FSNAME2} \
1625                 --index=8191 --reformat $fs2ostdev $fs2ostvdev || exit 10
1626
1627         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1628         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1629         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1630         mkdir -p $MOUNT2
1631         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1632         echo "ok."
1633
1634         cp /etc/hosts $MOUNT2/ || rc=3
1635         $LFS getstripe $MOUNT2/hosts
1636
1637         umount -d $MOUNT2
1638         stop fs2ost -f
1639         stop fs2mds -f
1640         cleanup_nocli || rc=6
1641         return $rc
1642 }
1643 run_test 33a "Mount ost with a large index number"
1644
1645 test_33b() {    # was test_34
1646         setup
1647
1648         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1649         # Drop lock cancelation reply during umount
1650         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
1651         do_facet client lctl set_param fail_loc=0x80000304
1652         #lctl set_param debug=-1
1653         umount_client $MOUNT
1654         cleanup
1655 }
1656 run_test 33b "Drop cancel during umount"
1657
1658 test_34a() {
1659         setup
1660         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
1661         manual_umount_client
1662         rc=$?
1663         do_facet client killall -USR1 multiop
1664         if [ $rc -eq 0 ]; then
1665                 error "umount not fail!"
1666         fi
1667         sleep 1
1668         cleanup
1669 }
1670 run_test 34a "umount with opened file should be fail"
1671
1672
1673 test_34b() {
1674         setup
1675         touch $DIR/$tfile || return 1
1676         stop_mds --force || return 2
1677
1678         manual_umount_client --force
1679         rc=$?
1680         if [ $rc -ne 0 ]; then
1681                 error "mtab after failed umount - rc $rc"
1682         fi
1683
1684         cleanup
1685         return 0
1686 }
1687 run_test 34b "force umount with failed mds should be normal"
1688
1689 test_34c() {
1690         setup
1691         touch $DIR/$tfile || return 1
1692         stop_ost --force || return 2
1693
1694         manual_umount_client --force
1695         rc=$?
1696         if [ $rc -ne 0 ]; then
1697                 error "mtab after failed umount - rc $rc"
1698         fi
1699
1700         cleanup
1701         return 0
1702 }
1703 run_test 34c "force umount with failed ost should be normal"
1704
1705 test_35a() { # bug 12459
1706         setup
1707
1708         DBG_SAVE="`lctl get_param -n debug`"
1709         lctl set_param debug="ha"
1710
1711         log "Set up a fake failnode for the MDS"
1712         FAKENID="127.0.0.2"
1713         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1714         do_facet mgs "$LCTL conf_param ${device}.failover.node=" \
1715                 "$(h2$NETTYPE $FAKENID)" || return 4
1716
1717         log "Wait for RECONNECT_INTERVAL seconds (10s)"
1718         sleep 10
1719
1720         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
1721         $LCTL clear
1722         log "$MSG"
1723         log "Stopping the MDT:"
1724         stop_mds || return 5
1725
1726         df $MOUNT > /dev/null 2>&1 &
1727         DFPID=$!
1728         log "Restarting the MDT:"
1729         start_mds || return 6
1730         log "Wait for df ($DFPID) ... "
1731         wait $DFPID
1732         log "done"
1733         lctl set_param debug="$DBG_SAVE"
1734
1735         # retrieve from the log the first server that the client tried to
1736         # contact after the connection loss
1737         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1738         NEXTCONN=`awk "/${MSG}/ {start = 1;}
1739                        /import_select_connection.*$device-mdc.* using connection/ {
1740                                 if (start) {
1741                                         if (\\\$NF ~ /$FAKENID/)
1742                                                 print \\\$NF;
1743                                         else
1744                                                 print 0;
1745                                         exit;
1746                                 }
1747                        }" $TMP/lustre-log-$TESTNAME.log`
1748         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
1749         cleanup
1750         # remove nid settings
1751         writeconf
1752 }
1753 run_test 35a "Reconnect to the last active server first"
1754
1755 test_35b() { # bug 18674
1756         remote_mds || { skip "local MDS" && return 0; }
1757         setup
1758
1759         debugsave
1760         $LCTL set_param debug="ha"
1761         $LCTL clear
1762         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
1763         log "$MSG"
1764
1765         log "Set up a fake failnode for the MDS"
1766         FAKENID="127.0.0.2"
1767         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" | \
1768                         awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1769         do_facet mgs "$LCTL conf_param ${device}.failover.node=" \
1770                 "$(h2$NETTYPE $FAKENID)" || return 1
1771
1772         local at_max_saved=0
1773         # adaptive timeouts may prevent seeing the issue
1774         if at_is_enabled; then
1775                 at_max_saved=$(at_max_get mds)
1776                 at_max_set 0 mds client
1777         fi
1778
1779         mkdir -p $MOUNT/$tdir
1780
1781         log "Injecting EBUSY on MDS"
1782         # Setting OBD_FAIL_MDS_RESEND=0x136
1783         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" || return 2
1784
1785         $LCTL set_param mdc.${FSNAME}*.stats=clear
1786
1787         log "Creating a test file and stat it"
1788         touch $MOUNT/$tdir/$tfile
1789         stat $MOUNT/$tdir/$tfile
1790
1791         log "Stop injecting EBUSY on MDS"
1792         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" || return 3
1793         rm -f $MOUNT/$tdir/$tfile
1794
1795         log "done"
1796         # restore adaptive timeout
1797         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
1798
1799         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1800
1801         CONNCNT=`$LCTL get_param mdc.${FSNAME}*.stats | awk '/mds_connect/{print $2}'`
1802
1803         # retrieve from the log if the client has ever tried to
1804         # contact the fake server after the loss of connection
1805         FAILCONN=`awk "BEGIN {ret = 0;}
1806                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
1807                                 ret = 1;
1808                                 if (\\\$NF ~ /$FAKENID/) {
1809                                         ret = 2;
1810                                         exit;
1811                                 }
1812                        }
1813                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
1814
1815         [ "$FAILCONN" == "0" ] && \
1816                 log "ERROR: The client reconnection has not been triggered" && \
1817                 return 4
1818         [ "$FAILCONN" == "2" ] && \
1819                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
1820                 return 5
1821
1822         # LU-290
1823         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
1824         # Reconnects are supposed to be rate limited to one every 5s
1825         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] && \
1826                 log "ERROR: Too many reconnects $CONNCNT" && \
1827                 return 6
1828
1829         cleanup
1830         # remove nid settings
1831         writeconf
1832 }
1833 run_test 35b "Continue reconnection retries, if the active server is busy"
1834
1835 test_36() { # 12743
1836         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
1837
1838         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
1839                 { skip "remote OST" && return 0; }
1840
1841         local rc=0
1842         local FSNAME2=test1234
1843         local fs3ost_HOST=$ost_HOST
1844         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1845
1846         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
1847
1848         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
1849                 is_blkdev $SINGLEMDS $MDSDEV && \
1850                 skip_env "mixed loopback and real device not working" && return
1851         fi
1852
1853         local fs2mdsdev=$(mdsdevname 1_2)
1854         local fs2ostdev=$(ostdevname 1_2)
1855         local fs3ostdev=$(ostdevname 2_2)
1856         local fs2mdsvdev=$(mdsvdevname 1_2)
1857         local fs2ostvdev=$(ostvdevname 1_2)
1858         local fs3ostvdev=$(ostvdevname 2_2)
1859
1860         add fs2mds $(mkfs_opts mds1) --fsname=${FSNAME2} --reformat \
1861                 $fs2mdsdev $fs2mdsvdev || exit 10
1862         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
1863         #     different one than the default value here.
1864         add fs2ost $(mkfs_opts ost1) --mgsnode=$MGSNID --fsname=${FSNAME2} \
1865                 --reformat $fs2ostdev $fs2ostvdev || exit 10
1866         add fs3ost $(mkfs_opts ost1) --mgsnode=$MGSNID --fsname=${FSNAME2} \
1867                 --reformat $fs3ostdev $fs3ostvdev || exit 10
1868
1869         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
1870         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1871         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
1872         mkdir -p $MOUNT2
1873         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
1874
1875         sleep 5 # until 11778 fixed
1876
1877         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
1878
1879         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1880         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
1881         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
1882         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
1883         DFTOTAL=`echo $STRING | cut -d, -f1`
1884         DFUSED=`echo $STRING  | cut -d, -f2`
1885         DFAVAIL=`echo $STRING | cut -d, -f3`
1886         DFFREE=$(($DFTOTAL - $DFUSED))
1887
1888         ALLOWANCE=$((64 * $OSTCOUNT))
1889
1890         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
1891            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
1892                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
1893                 rc=1
1894         fi
1895         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
1896            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
1897                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
1898                 rc=2
1899         fi
1900         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
1901            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
1902                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
1903                 rc=3
1904        fi
1905
1906         umount -d $MOUNT2
1907         stop fs3ost -f || return 200
1908         stop fs2ost -f || return 201
1909         stop fs2mds -f || return 202
1910         unload_modules_conf || return 203
1911         return $rc
1912 }
1913 run_test 36 "df report consistency on OSTs with different block size"
1914
1915 test_37() {
1916         local mntpt=$(facet_mntpt $SINGLEMDS)
1917         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
1918         local mdsdev_sym="$TMP/sym_mdt.img"
1919         local opts=$MDS_MOUNT_OPTS
1920         local rc=0
1921
1922         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
1923                 skip "Currently only applicable to ldiskfs-based MDTs"
1924                 return
1925         fi
1926
1927         echo "MDS :     $mdsdev"
1928         echo "SYMLINK : $mdsdev_sym"
1929         do_facet $SINGLEMDS rm -f $mdsdev_sym
1930
1931         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
1932
1933         echo "mount symlink device - $mdsdev_sym"
1934
1935         if ! do_facet $SINGLEMDS test -b $mdsdev; then
1936                 opts=$(csa_add "$opts" -o loop)
1937         fi
1938         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
1939                 $mdsdev_sym $mntpt 2>&1)
1940         rc=${PIPESTATUS[0]}
1941
1942         echo mount_op=$mount_op
1943
1944         do_facet $SINGLEMDS "umount -d $mntpt && rm -f $mdsdev_sym"
1945
1946         if $(echo $mount_op | grep -q "unable to set tunable"); then
1947                 error "set tunables failed for symlink device"
1948         fi
1949
1950         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
1951
1952         return 0
1953 }
1954 run_test 37 "verify set tunables works for symlink device"
1955
1956 test_38() { # bug 14222
1957         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
1958                 skip "Only applicable to ldiskfs-based MDTs"
1959                 return
1960         fi
1961
1962         setup
1963         # like runtests
1964         COUNT=10
1965         SRC="/etc /bin"
1966         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
1967         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
1968         mkdir -p $DIR/$tdir
1969         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
1970                 error "copying $SRC to $DIR/$tdir"
1971         sync
1972         umount_client $MOUNT
1973         stop_mds
1974         log "rename lov_objid file on MDS"
1975         rm -f $TMP/lov_objid.orig
1976
1977         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1978         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
1979         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1980
1981         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.orig"
1982         # check create in mds_lov_connect
1983         start_mds
1984         mount_client $MOUNT
1985         for f in $FILES; do
1986                 [ $V ] && log "verifying $DIR/$tdir/$f"
1987                 diff -q $f $DIR/$tdir/$f || ERROR=y
1988         done
1989         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
1990         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new"
1991         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
1992
1993         # check it's updates in sync
1994         umount_client $MOUNT
1995         stop_mds
1996
1997         do_facet $SINGLEMDS dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
1998         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1999         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
2000
2001         start_mds
2002         mount_client $MOUNT
2003         for f in $FILES; do
2004                 [ $V ] && log "verifying $DIR/$tdir/$f"
2005                 diff -q $f $DIR/$tdir/$f || ERROR=y
2006         done
2007         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
2008         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new1"
2009         umount_client $MOUNT
2010         stop_mds
2011         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
2012
2013         log "files compared the same"
2014         cleanup
2015 }
2016 run_test 38 "MDS recreates missing lov_objid file from OST data"
2017
2018 test_39() {
2019         PTLDEBUG=+malloc
2020         setup
2021         cleanup
2022         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2023                 error "memory leak detected" || true
2024 }
2025 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2026
2027 test_40() { # bug 15759
2028         start_ost
2029         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2030         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2031         start_mds
2032         cleanup
2033 }
2034 run_test 40 "race during service thread startup"
2035
2036 test_41a() { #bug 14134
2037         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2038            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2039                 skip "Loop devices does not work with nosvc option"
2040                 return
2041         fi
2042
2043         local rc
2044         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2045
2046         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2047         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
2048         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2049         mkdir -p $MOUNT
2050         mount_client $MOUNT || return 1
2051         sleep 5
2052
2053         echo "blah blah" > $MOUNT/$tfile
2054         cat $MOUNT/$tfile
2055
2056         umount_client $MOUNT
2057         stop ost1 -f || return 201
2058         stop_mds -f || return 202
2059         stop_mds -f || return 203
2060         unload_modules_conf || return 204
2061         return $rc
2062 }
2063 run_test 41a "mount mds with --nosvc and --nomgs"
2064
2065 test_41b() {
2066         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2067            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2068                 skip "Loop devices does not work with nosvc option"
2069                 return
2070         fi
2071
2072         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2073
2074         stopall
2075         reformat
2076         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2077
2078         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2079         start_ost
2080         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2081         mkdir -p $MOUNT
2082         mount_client $MOUNT || return 1
2083         sleep 5
2084
2085         echo "blah blah" > $MOUNT/$tfile
2086         cat $MOUNT/$tfile || return 200
2087
2088         umount_client $MOUNT
2089         stop_ost || return 201
2090         stop_mds -f || return 202
2091         stop_mds -f || return 203
2092
2093 }
2094 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2095
2096 test_42() { #bug 14693
2097         setup
2098         check_mount || return 2
2099         do_facet mgs $LCTL conf_param lustre.llite.some_wrong_param=10
2100         umount_client $MOUNT
2101         mount_client $MOUNT || return 1
2102         cleanup
2103         return 0
2104 }
2105 run_test 42 "invalid config param should not prevent client from mounting"
2106
2107 test_43() {
2108         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
2109         setup
2110         chmod ugo+x $DIR || error "chmod 0 failed"
2111         set_conf_param_and_check mds                                    \
2112                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2113                 "$FSNAME.mdt.root_squash"                               \
2114                 "0:0"
2115         set_conf_param_and_check mds                                    \
2116                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2117                 "$FSNAME.mdt.nosquash_nids"                             \
2118                 "NONE"
2119
2120     #
2121     # create set of test files
2122     #
2123     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
2124     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
2125     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
2126
2127     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
2128     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
2129
2130     mkdir $DIR/$tdir-rootdir -p       || error "mkdir failed"
2131     chmod go-rwx $DIR/$tdir-rootdir   || error "chmod 3 failed"
2132     touch $DIR/$tdir-rootdir/tfile-1  || error "touch failed"
2133
2134         #
2135         # check root_squash:
2136         #   set root squash UID:GID to RUNAS_ID
2137         #   root should be able to access only files owned by RUNAS_ID
2138         #
2139         set_conf_param_and_check mds                                    \
2140                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2141                 "$FSNAME.mdt.root_squash"                               \
2142                 "$RUNAS_ID:$RUNAS_ID"
2143
2144     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
2145     dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2146         error "$ST: root read permission is denied"
2147     echo "$ST: root read permission is granted - ok"
2148
2149     echo "444" | \
2150     dd conv=notrunc if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2151         error "$ST: root write permission is denied"
2152     echo "$ST: root write permission is granted - ok"
2153
2154     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2155     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2156         error "$ST: root read permission is granted"
2157     echo "$ST: root read permission is denied - ok"
2158
2159     echo "555" | \
2160     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2161         error "$ST: root write permission is granted"
2162     echo "$ST: root write permission is denied - ok"
2163
2164     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2165     rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null && \
2166         error "$ST: root unlink permission is granted"
2167     echo "$ST: root unlink permission is denied - ok"
2168
2169     touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null && \
2170         error "$ST: root create permission is granted"
2171     echo "$ST: root create permission is denied - ok"
2172
2173         #
2174         # check nosquash_nids:
2175         #   put client's NID into nosquash_nids list,
2176         #   root should be able to access root file after that
2177         #
2178         local NIDLIST=$(lctl list_nids all | tr '\n' ' ')
2179         NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
2180         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
2181         set_conf_param_and_check mds                                    \
2182                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2183                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
2184                 "$NIDLIST"
2185
2186     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2187     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2188         error "$ST: root read permission is denied"
2189     echo "$ST: root read permission is granted - ok"
2190
2191     echo "666" | \
2192     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2193         error "$ST: root write permission is denied"
2194     echo "$ST: root write permission is granted - ok"
2195
2196     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2197     rm $DIR/$tdir-rootdir/tfile-1 || \
2198         error "$ST: root unlink permission is denied"
2199     echo "$ST: root unlink permission is granted - ok"
2200     touch $DIR/$tdir-rootdir/tfile-2 || \
2201         error "$ST: root create permission is denied"
2202     echo "$ST: root create permission is granted - ok"
2203
2204     return 0
2205 }
2206 run_test 43 "check root_squash and nosquash_nids"
2207
2208 umount_client $MOUNT
2209 cleanup_nocli
2210
2211 test_44() { # 16317
2212         setup
2213         check_mount || return 2
2214         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
2215         STATS_FOUND=no
2216         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
2217         for VAL in $UUIDS; do
2218                 NID=$(echo $VAL | cut -d= -f1)
2219                 CLUUID=$(echo $VAL | cut -d= -f2)
2220                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
2221         done
2222         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
2223         cleanup
2224         return 0
2225 }
2226 run_test 44 "mounted client proc entry exists"
2227
2228 test_45() { #17310
2229         setup
2230         check_mount || return 2
2231         stop_mds
2232         df -h $MOUNT &
2233         log "sleep 60 sec"
2234         sleep 60
2235 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
2236         do_facet client "lctl set_param fail_loc=0x50f"
2237         log "sleep 10 sec"
2238         sleep 10
2239         manual_umount_client --force || return 3
2240         do_facet client "lctl set_param fail_loc=0x0"
2241         start_mds
2242         mount_client $MOUNT || return 4
2243         cleanup
2244         return 0
2245 }
2246 run_test 45 "long unlink handling in ptlrpcd"
2247
2248 cleanup_46a() {
2249         trap 0
2250         local rc=0
2251         local count=$1
2252
2253         umount_client $MOUNT2 || rc=$?
2254         umount_client $MOUNT || rc=$?
2255         while [ $count -gt 0 ]; do
2256                 stop ost${count} -f || rc=$?
2257                 let count=count-1
2258         done    
2259         stop_mds || rc=$?
2260         cleanup_nocli || rc=$?
2261         #writeconf to remove all ost2 traces for subsequent tests
2262         writeconf
2263         return $rc
2264 }
2265
2266 test_46a() {
2267         echo "Testing with $OSTCOUNT OSTs"
2268         reformat_and_config
2269         start_mds || return 1
2270         #first client should see only one ost
2271         start_ost || return 2
2272         wait_osc_import_state mds ost FULL
2273         #start_client
2274         mount_client $MOUNT || return 3
2275         trap "cleanup_46a $OSTCOUNT" EXIT ERR
2276
2277         local i
2278         for (( i=2; i<=$OSTCOUNT; i++ )); do
2279             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
2280         done
2281
2282         # wait until osts in sync
2283         for (( i=2; i<=$OSTCOUNT; i++ )); do
2284             wait_osc_import_state mds ost$i FULL
2285             wait_osc_import_state client ost$i FULL
2286         done
2287
2288         #second client see all ost's
2289
2290         mount_client $MOUNT2 || return 8
2291         $LFS setstripe -c -1 $MOUNT2 || return 9
2292         $LFS getstripe $MOUNT2 || return 10
2293
2294         echo "ok" > $MOUNT2/widestripe
2295         $LFS getstripe $MOUNT2/widestripe || return 11
2296         # fill acl buffer for avoid expand lsm to them
2297         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
2298             setfacl -m $acl $MOUNT2/widestripe
2299         done
2300
2301         # will be deadlock
2302         stat $MOUNT/widestripe || return 12
2303
2304         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
2305         return 0
2306 }
2307 run_test 46a "handle ost additional - wide striped file"
2308
2309 test_47() { #17674
2310         reformat
2311         setup_noconfig
2312         check_mount || return 2
2313         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
2314
2315         local lru_size=[]
2316         local count=0
2317         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2318             if echo $ns | grep "MDT[[:digit:]]*"; then
2319                 continue
2320             fi
2321             lrs=$(echo $ns | sed 's/.*lru_size=//')
2322             lru_size[count]=$lrs
2323             let count=count+1
2324         done
2325
2326         facet_failover ost1
2327         facet_failover $SINGLEMDS
2328         client_up || return 3
2329
2330         count=0
2331         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2332             if echo $ns | grep "MDT[[:digit:]]*"; then
2333                 continue
2334             fi
2335             lrs=$(echo $ns | sed 's/.*lru_size=//')
2336             if ! test "$lrs" -eq "${lru_size[count]}"; then
2337                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
2338                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
2339             fi
2340             let count=count+1
2341         done
2342
2343         cleanup
2344         return 0
2345 }
2346 run_test 47 "server restart does not make client loss lru_resize settings"
2347
2348 cleanup_48() {
2349         trap 0
2350
2351         # reformat after this test is needed - if test will failed
2352         # we will have unkillable file at FS
2353         reformat_and_config
2354 }
2355
2356 test_48() { # bug 17636
2357         reformat
2358         setup_noconfig
2359         check_mount || return 2
2360
2361         $LFS setstripe -c -1 $MOUNT || return 9
2362         $LFS getstripe $MOUNT || return 10
2363
2364         echo "ok" > $MOUNT/widestripe
2365         $LFS getstripe $MOUNT/widestripe || return 11
2366
2367         trap cleanup_48 EXIT ERR
2368
2369         # fill acl buffer for avoid expand lsm to them
2370         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
2371             setfacl -m $acl $MOUNT/widestripe
2372         done
2373
2374         stat $MOUNT/widestripe || return 12
2375
2376         cleanup_48
2377         return 0
2378 }
2379 run_test 48 "too many acls on file"
2380
2381 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
2382 test_49() { # bug 17710
2383         local timeout_orig=$TIMEOUT
2384         local ldlm_timeout_orig=$LDLM_TIMEOUT
2385         local LOCAL_TIMEOUT=20
2386
2387         LDLM_TIMEOUT=$LOCAL_TIMEOUT
2388         TIMEOUT=$LOCAL_TIMEOUT
2389
2390         reformat
2391         setup_noconfig
2392         check_mount || return 1
2393
2394         echo "check ldlm_timout..."
2395         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2396         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2397         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2398
2399         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2400                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2401         fi
2402
2403         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
2404                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2405         fi
2406
2407         umount_client $MOUNT
2408         stop_ost || return 2
2409         stop_mds || return 3
2410
2411         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
2412
2413         reformat
2414         setup_noconfig
2415         check_mount || return 7
2416
2417         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2418         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2419         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2420
2421         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2422                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2423         fi
2424
2425         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
2426                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2427         fi
2428
2429         cleanup || return $?
2430
2431         LDLM_TIMEOUT=$ldlm_timeout_orig
2432         TIMEOUT=$timeout_orig
2433 }
2434 run_test 49 "check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE"
2435
2436 lazystatfs() {
2437         # Test both statfs and lfs df and fail if either one fails
2438         multiop_bg_pause $1 f_
2439         RC1=$?
2440         PID=$!
2441         killall -USR1 multiop
2442         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
2443         wait $PID || { RC1=$?; log "multiop return error "; }
2444
2445         $LFS df &
2446         PID=$!
2447         sleep 5
2448         kill -s 0 $PID
2449         RC2=$?
2450         if [ $RC2 -eq 0 ]; then
2451             kill -s 9 $PID
2452             log "lazystatfs df failed"
2453         fi
2454
2455         RC=0
2456         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
2457         return $RC
2458 }
2459
2460 test_50a() {
2461         setup
2462         lctl set_param llite.$FSNAME-*.lazystatfs=1
2463         touch $DIR/$tfile
2464
2465         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
2466
2467         cleanup || return $?
2468 }
2469 run_test 50a "lazystatfs all servers available =========================="
2470
2471 test_50b() {
2472         setup
2473         lctl set_param llite.$FSNAME-*.lazystatfs=1
2474         touch $DIR/$tfile
2475
2476         # Wait for client to detect down OST
2477         stop_ost || error "Unable to stop OST1"
2478         wait_osc_import_state mds ost DISCONN
2479
2480         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
2481
2482         umount_client $MOUNT || error "Unable to unmount client"
2483         stop_mds || error "Unable to stop MDS"
2484 }
2485 run_test 50b "lazystatfs all servers down =========================="
2486
2487 test_50c() {
2488         start_mds || error "Unable to start MDS"
2489         start_ost || error "Unable to start OST1"
2490         start_ost2 || error "Unable to start OST2"
2491         mount_client $MOUNT || error "Unable to mount client"
2492         lctl set_param llite.$FSNAME-*.lazystatfs=1
2493         touch $DIR/$tfile
2494
2495         # Wait for client to detect down OST
2496         stop_ost || error "Unable to stop OST1"
2497         wait_osc_import_state mds ost DISCONN
2498         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2499
2500         umount_client $MOUNT || error "Unable to unmount client"
2501         stop_ost2 || error "Unable to stop OST2"
2502         stop_mds || error "Unable to stop MDS"
2503         #writeconf to remove all ost2 traces for subsequent tests
2504         writeconf
2505 }
2506 run_test 50c "lazystatfs one server down =========================="
2507
2508 test_50d() {
2509         start_mds || error "Unable to start MDS"
2510         start_ost || error "Unable to start OST1"
2511         start_ost2 || error "Unable to start OST2"
2512         mount_client $MOUNT || error "Unable to mount client"
2513         lctl set_param llite.$FSNAME-*.lazystatfs=1
2514         touch $DIR/$tfile
2515
2516         # Issue the statfs during the window where the client still
2517         # belives the OST to be available but it is in fact down.
2518         # No failure just a statfs which hangs for a timeout interval.
2519         stop_ost || error "Unable to stop OST1"
2520         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2521
2522         umount_client $MOUNT || error "Unable to unmount client"
2523         stop_ost2 || error "Unable to stop OST2"
2524         stop_mds || error "Unable to stop MDS"
2525         #writeconf to remove all ost2 traces for subsequent tests
2526         writeconf
2527 }
2528 run_test 50d "lazystatfs client/server conn race =========================="
2529
2530 test_50e() {
2531         local RC1
2532         local pid
2533
2534         reformat_and_config
2535         start_mds || return 1
2536         #first client should see only one ost
2537         start_ost || return 2
2538         wait_osc_import_state mds ost FULL
2539
2540         # Wait for client to detect down OST
2541         stop_ost || error "Unable to stop OST1"
2542         wait_osc_import_state mds ost DISCONN
2543
2544         mount_client $MOUNT || error "Unable to mount client"
2545         lctl set_param llite.$FSNAME-*.lazystatfs=0
2546
2547         multiop_bg_pause $MOUNT _f
2548         RC1=$?
2549         pid=$!
2550
2551         if [ $RC1 -ne 0 ]; then
2552                 log "multiop failed $RC1"
2553         else
2554             kill -USR1 $pid
2555             sleep $(( $TIMEOUT+1 ))
2556             kill -0 $pid
2557             [ $? -ne 0 ] && error "process isn't sleep"
2558             start_ost || error "Unable to start OST1"
2559             wait $pid || error "statfs failed"
2560         fi
2561
2562         umount_client $MOUNT || error "Unable to unmount client"
2563         stop_ost || error "Unable to stop OST1"
2564         stop_mds || error "Unable to stop MDS"
2565 }
2566 run_test 50e "normal statfs all servers down =========================="
2567
2568 test_50f() {
2569         local RC1
2570         local pid
2571         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
2572
2573         start_mds || error "Unable to start mds"
2574         #first client should see only one ost
2575         start_ost || error "Unable to start OST1"
2576         wait_osc_import_state mds ost FULL
2577
2578         start_ost2 || error "Unable to start OST2"
2579         wait_osc_import_state mds ost2 FULL
2580
2581         # Wait for client to detect down OST
2582         stop_ost2 || error "Unable to stop OST2"
2583
2584         wait_osc_import_state mds ost2 DISCONN
2585         mount_client $MOUNT || error "Unable to mount client"
2586         lctl set_param llite.$FSNAME-*.lazystatfs=0
2587
2588         multiop_bg_pause $MOUNT _f
2589         RC1=$?
2590         pid=$!
2591
2592         if [ $RC1 -ne 0 ]; then
2593                 log "lazystatfs multiop failed $RC1"
2594         else
2595             kill -USR1 $pid
2596             sleep $(( $TIMEOUT+1 ))
2597             kill -0 $pid
2598             [ $? -ne 0 ] && error "process isn't sleep"
2599             start_ost2 || error "Unable to start OST2"
2600             wait $pid || error "statfs failed"
2601             stop_ost2 || error "Unable to stop OST2"
2602         fi
2603
2604         umount_client $MOUNT || error "Unable to unmount client"
2605         stop_ost || error "Unable to stop OST1"
2606         stop_mds || error "Unable to stop MDS"
2607         #writeconf to remove all ost2 traces for subsequent tests
2608         writeconf
2609 }
2610 run_test 50f "normal statfs one server in down =========================="
2611
2612 test_50g() {
2613         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2614         setup
2615         start_ost2 || error "Unable to start OST2"
2616         wait_osc_import_state mds ost2 FULL
2617         wait_osc_import_state client ost2 FULL
2618
2619         local PARAM="${FSNAME}-OST0001.osc.active"
2620
2621         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
2622         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
2623
2624         umount_client $MOUNT || error "Unable to unmount client"
2625         mount_client $MOUNT || error "Unable to mount client"
2626         # This df should not cause a panic
2627         df -k $MOUNT
2628
2629         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
2630         rm -f $DIR/$tfile
2631         umount_client $MOUNT || error "Unable to unmount client"
2632         stop_ost2 || error "Unable to stop OST2"
2633         stop_ost || error "Unable to stop OST1"
2634         stop_mds || error "Unable to stop MDS"
2635         #writeconf to remove all ost2 traces for subsequent tests
2636         writeconf
2637 }
2638 run_test 50g "deactivated OST should not cause panic====================="
2639
2640 test_51() {
2641         local LOCAL_TIMEOUT=20
2642
2643         reformat
2644         setup_noconfig
2645         check_mount || return 1
2646
2647         mkdir $MOUNT/d1
2648         $LFS setstripe -c -1 $MOUNT/d1
2649         #define OBD_FAIL_MDS_REINT_DELAY         0x142
2650         do_facet $SINGLEMDS "lctl set_param fail_loc=0x142"
2651         touch $MOUNT/d1/f1 &
2652         local pid=$!
2653         sleep 2
2654         start_ost2 || return 2
2655         wait $pid
2656         stop_ost2 || return 3
2657         cleanup
2658         #writeconf to remove all ost2 traces for subsequent tests
2659         writeconf
2660 }
2661 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
2662
2663 copy_files_xattrs()
2664 {
2665         local node=$1
2666         local dest=$2
2667         local xattrs=$3
2668         shift 3
2669
2670         do_node $node mkdir -p $dest
2671         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2672
2673         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
2674                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
2675         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
2676
2677         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
2678         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
2679 }
2680
2681 diff_files_xattrs()
2682 {
2683         local node=$1
2684         local backup=$2
2685         local xattrs=$3
2686         shift 3
2687
2688         local backup2=${TMP}/backup2
2689
2690         do_node $node mkdir -p $backup2
2691         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2692
2693         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
2694                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
2695         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
2696
2697         do_node $node "diff -rq $backup $backup2"
2698         [ $? -eq 0 ] || { error "contents differ"; return 3; }
2699
2700         local xattrs2=${TMP}/xattrs2
2701         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
2702         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
2703
2704         do_node $node "diff $xattrs $xattrs2"
2705         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
2706
2707         do_node $node "rm -rf $backup2 $xattrs2"
2708         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
2709 }
2710
2711 test_52() {
2712         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2713                 skip "Only applicable to ldiskfs-based MDTs"
2714                 return
2715         fi
2716
2717         start_mds
2718         [ $? -eq 0 ] || { error "Unable to start MDS"; return 1; }
2719         start_ost
2720         [ $? -eq 0 ] || { error "Unable to start OST1"; return 2; }
2721         mount_client $MOUNT
2722         [ $? -eq 0 ] || { error "Unable to mount client"; return 3; }
2723
2724         local nrfiles=8
2725         local ost1mnt=$(facet_mntpt ost1)
2726         local ost1node=$(facet_active_host ost1)
2727         local ost1tmp=$TMP/conf52
2728         local loop
2729
2730         mkdir -p $DIR/$tdir
2731         [ $? -eq 0 ] || { error "Unable to create tdir"; return 4; }
2732         touch $TMP/modified_first
2733         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 5; }
2734         local mtime=$(stat -c %Y $TMP/modified_first)
2735         do_node $ost1node "mkdir -p $ost1tmp && touch -m -d @$mtime $ost1tmp/modified_first"
2736
2737         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 6; }
2738         sleep 1
2739
2740         $LFS setstripe -c -1 -S 1M $DIR/$tdir
2741         [ $? -eq 0 ] || { error "lfs setstripe failed"; return 7; }
2742
2743         for (( i=0; i < nrfiles; i++ )); do
2744                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c
2745                 [ $? -eq 0 ] || { error "multiop failed"; return 8; }
2746                 echo -n .
2747         done
2748         echo
2749
2750         # backup files
2751         echo backup files to $TMP/files
2752         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
2753         copy_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
2754         [ $? -eq 0 ] || { error "Unable to copy files"; return 9; }
2755
2756         umount_client $MOUNT
2757         [ $? -eq 0 ] || { error "Unable to umount client"; return 10; }
2758         stop_ost
2759         [ $? -eq 0 ] || { error "Unable to stop ost1"; return 11; }
2760
2761         echo mount ost1 as ldiskfs
2762         do_node $ost1node mkdir -p $ost1mnt
2763         [ $? -eq 0 ] || { error "Unable to create $ost1mnt"; return 23; }
2764         if ! do_node $ost1node test -b $ost1_dev; then
2765                 loop="-o loop"
2766         fi
2767         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
2768                 $ost1mnt
2769         [ $? -eq 0 ] || { error "Unable to mount ost1 as ldiskfs"; return 12; }
2770
2771         # backup objects
2772         echo backup objects to $ost1tmp/objects
2773         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/0 -type f -size +0'\
2774                         '-newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
2775         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
2776         [ $? -eq 0 ] || { error "Unable to copy objects"; return 13; }
2777
2778         # move objects to lost+found
2779         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
2780         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
2781
2782         # recover objects
2783         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found"
2784         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
2785
2786         # compare restored objects against saved ones
2787         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
2788         [ $? -eq 0 ] || { error "Unable to diff objects"; return 16; }
2789
2790         do_node $ost1node "umount $ost1mnt"
2791         [ $? -eq 0 ] || { error "Unable to umount ost1 as ldiskfs"; return 17; }
2792
2793         start_ost
2794         [ $? -eq 0 ] || { error "Unable to start ost1"; return 18; }
2795         mount_client $MOUNT
2796         [ $? -eq 0 ] || { error "Unable to mount client"; return 19; }
2797
2798         # compare files
2799         diff_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
2800         [ $? -eq 0 ] || { error "Unable to diff files"; return 20; }
2801
2802         rm -rf $TMP/files $TMP/file_xattrs
2803         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 21; }
2804         do_node $ost1node "rm -rf $ost1tmp"
2805         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 22; }
2806         cleanup
2807 }
2808 run_test 52 "check recovering objects from lost+found"
2809
2810 # Checks threads_min/max/started for some service
2811 #
2812 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
2813 # parameter pattern prefix like 'ost.*.ost'.
2814 thread_sanity() {
2815         local modname=$1
2816         local facet=$2
2817         local parampat=$3
2818         local opts=$4
2819         local basethr=$5
2820         local tmin
2821         local tmin2
2822         local tmax
2823         local tmax2
2824         local tstarted
2825         local paramp
2826         local msg="Insane $modname thread counts"
2827         local ncpts=$(check_cpt_number $facet)
2828         local nthrs
2829         shift 4
2830
2831         setup
2832         check_mount || return 41
2833
2834         # We need to expand $parampat, but it may match multiple parameters, so
2835         # we'll pick the first one
2836         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
2837                 error "Couldn't expand ${parampat}.threads_min parameter name"
2838                 return 22
2839         fi
2840
2841         # Remove the .threads_min part
2842         paramp=${paramp%.threads_min}
2843
2844         # Check for sanity in defaults
2845         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2846         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2847         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started" || echo 0)
2848         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' || return $?
2849         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
2850         nthrs=$(expr $tmax - $tmin)
2851         if [ $nthrs -lt $ncpts ]; then
2852                 nthrs=0
2853         else
2854                 nthrs=$ncpts
2855         fi
2856
2857         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
2858                 skip_env "module parameter forced $facet thread count" &&
2859                 tmin=3 && tmax=$((3 * tmax))
2860
2861         # Check that we can change min/max
2862         do_facet $facet "lctl set_param ${paramp}.threads_min=$((tmin + nthrs))"
2863         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmax - nthrs))"
2864         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2865         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2866         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) && $tmax2 == ($tmax - $nthrs)))' || return $?
2867
2868         # Check that we can set min/max to the same value
2869         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2870         do_facet $facet "lctl set_param ${paramp}.threads_max=$tmin"
2871         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2872         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2873         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
2874
2875         # Check that we can't set max < min
2876         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmin - 1))"
2877         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2878         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2879         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
2880
2881         # We need to ensure that we get the module options desired; to do this
2882         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
2883         LOAD_MODULES_REMOTE=true
2884         cleanup
2885         local oldvalue
2886         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
2887         setmodopts -a $modname "$newvalue" oldvalue
2888
2889         load_modules
2890         setup
2891         check_mount || return 41
2892
2893         # Restore previous setting of MODOPTS_*
2894         setmodopts $modname "$oldvalue"
2895
2896         # Check that $opts took
2897         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min")
2898         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max")
2899         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started")
2900         lassert 28 "$msg" '(($tstarted == $tmin && $tstarted == $tmax ))' || return $?
2901         cleanup
2902
2903         load_modules
2904         setup
2905         cleanup
2906 }
2907
2908 test_53a() {
2909         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
2910 }
2911 run_test 53a "check OSS thread count params"
2912
2913 test_53b() {
2914         thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' '16'
2915 }
2916 run_test 53b "check MDT thread count params"
2917
2918 test_54a() {
2919         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2920                 skip "Only applicable to ldiskfs-based MDTs"
2921                 return
2922         fi
2923
2924     do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p
2925     [ $? -eq 0 ] || error "llverdev failed!"
2926     reformat_and_config
2927 }
2928 run_test 54a "test llverdev and partial verify of device"
2929
2930 test_54b() {
2931         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2932                 skip "Only applicable to ldiskfs-based MDTs"
2933                 return
2934         fi
2935
2936     setup
2937     run_llverfs $MOUNT -p
2938     [ $? -eq 0 ] || error "llverfs failed!"
2939     cleanup
2940 }
2941 run_test 54b "test llverfs and partial verify of filesystem"
2942
2943 lov_objid_size()
2944 {
2945         local max_ost_index=$1
2946         echo -n $(((max_ost_index + 1) * 8))
2947 }
2948
2949 test_55() {
2950         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2951                 skip "Only applicable to ldiskfs-based MDTs"
2952                 return
2953         fi
2954
2955         local mdsdev=$(mdsdevname 1)
2956         local mdsvdev=$(mdsvdevname 1)
2957
2958         for i in 1023 2048
2959         do
2960                 add mds1 $(mkfs_opts mds1) --reformat $mdsdev $mdsvdev ||
2961                         exit 10
2962                 add ost1 $(mkfs_opts ost1) --index=$i --reformat \
2963                         $(ostdevname 1) $(ostvdevname 1)
2964                 setup_noconfig
2965                 stopall
2966                 setup_noconfig
2967                 sync
2968
2969                 echo checking size of lov_objid for ost index $i
2970                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" | grep ^User | awk '{print $6}')
2971                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
2972                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
2973                 else
2974                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
2975                 fi
2976                 stopall
2977         done
2978
2979         reformat
2980 }
2981 run_test 55 "check lov_objid size"
2982
2983 test_56() {
2984         local mds_journal_size_orig=$MDSJOURNALSIZE
2985
2986         MDSJOURNALSIZE=16
2987         add mds1 $(mkfs_opts mds1) --reformat $(mdsdevname 1) $(mdsvdevname 1)
2988         add ost1 $(mkfs_opts ost1) --index=1000 --reformat \
2989                 $(ostdevname 1) $(ostvdevname 1)
2990         add ost2 $(mkfs_opts ost2) --index=10000 --reformat \
2991                 $(ostdevname 2) $(ostvdevname 2)
2992
2993         start_mgsmds
2994         start_ost
2995         start_ost2 || error "Unable to start second ost"
2996         mount_client $MOUNT || error "Unable to mount client"
2997         echo ok
2998         $LFS osts
2999         stopall
3000         MDSJOURNALSIZE=$mds_journal_size_orig
3001         reformat
3002 }
3003 run_test 56 "check big indexes"
3004
3005 test_57a() { # bug 22656
3006         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3007         writeconf
3008         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" || error "tunefs failed"
3009         start_mgsmds
3010         start_ost && error "OST registration from failnode should fail"
3011         reformat
3012 }
3013 run_test 57a "initial registration from failnode should fail (should return errs)"
3014
3015 test_57b() {
3016         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3017         writeconf
3018         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" || error "tunefs failed"
3019         start_mgsmds
3020         start_ost || error "OST registration from servicenode should not fail"
3021         reformat
3022 }
3023 run_test 57b "initial registration from servicenode should not fail"
3024
3025 count_osts() {
3026         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
3027 }
3028
3029 test_58() { # bug 22658
3030         if [ $(facet_fstype mds) != ldiskfs ]; then
3031                 skip "Only applicable to ldiskfs-based MDTs"
3032                 return
3033         fi
3034         setup_noconfig
3035         mkdir -p $DIR/$tdir
3036         createmany -o $DIR/$tdir/$tfile-%d 100
3037         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
3038 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
3039         do_facet mds "lctl set_param fail_loc=0x601"
3040         unlinkmany $DIR/$tdir/$tfile-%d 100
3041         stop mds
3042         local MNTDIR=$(facet_mntpt mds)
3043         # remove all files from the OBJECTS dir
3044         do_facet mds "mount -t ldiskfs $MDSDEV $MNTDIR"
3045         do_facet mds "find $MNTDIR/OBJECTS -type f -delete"
3046         do_facet mds "umount $MNTDIR"
3047         # restart MDS with missing llog files
3048         start_mds
3049         do_facet mds "lctl set_param fail_loc=0"
3050         reformat
3051 }
3052 run_test 58 "missing llog files must not prevent MDT from mounting"
3053
3054 test_59() {
3055         start_mgsmds >> /dev/null
3056         local C1=$(count_osts)
3057         if [ $C1 -eq 0 ]; then
3058                 start_ost >> /dev/null
3059                 C1=$(count_osts)
3060         fi
3061         stopall
3062         echo "original ost count: $C1 (expect > 0)"
3063         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
3064         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
3065         local C2=$(count_osts)
3066         echo "after mdt writeconf count: $C2 (expect 0)"
3067         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
3068         echo "OST start without writeconf should fail:"
3069         start_ost >> /dev/null && error "OST start without writeconf didn't fail"
3070         echo "OST start with writeconf should succeed:"
3071         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
3072         local C3=$(count_osts)
3073         echo "after ost writeconf count: $C3 (expect 1)"
3074         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
3075         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
3076         local C4=$(count_osts)
3077         echo "after ost2 writeconf count: $C4 (expect 2)"
3078         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
3079         stop_ost2 >> /dev/null
3080         cleanup_nocli >> /dev/null
3081         #writeconf to remove all ost2 traces for subsequent tests
3082         writeconf
3083 }
3084 run_test 59 "writeconf mount option"
3085
3086 test_60() { # LU-471
3087         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3088                 skip "Only applicable to ldiskfs-based MDTs"
3089                 return
3090         fi
3091
3092         add mds1 $(mkfs_opts mds1) \
3093                 --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' --reformat \
3094                 $(mdsdevname 1) $(mdsvdevname 1) || exit 10
3095
3096         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
3097         rc=${PIPESTATUS[0]}
3098         [ $rc -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
3099
3100         # MDT default has dirdata feature
3101         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
3102         # we disable uninit_bg feature
3103         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
3104         # we set stride extended options
3105         echo $dump | grep stride > /dev/null || error "stride is not set"
3106         reformat
3107 }
3108 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
3109
3110 test_61() { # LU-80
3111         local reformat=false
3112
3113         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
3114                 { skip "Need MDS version at least 2.1.53"; return 0; }
3115
3116         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3117            ! large_xattr_enabled; then
3118                 reformat=true
3119                 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
3120                 LDISKFS_MKFS_OPTS+=" -O large_xattr"
3121                 add $SINGLEMDS $(mkfs_opts $SINGLEMDS) --reformat $mds_dev ||
3122                         error "reformatting $mds_dev failed"
3123         fi
3124
3125     setup_noconfig || error "setting up the filesystem failed"
3126     client_up || error "starting client failed"
3127
3128     local file=$DIR/$tfile
3129     touch $file
3130
3131     local large_value="$(generate_string $(max_xattr_size))"
3132     local small_value="bar"
3133
3134     local name="trusted.big"
3135     log "save large xattr $name on $file"
3136     setfattr -n $name -v $large_value $file ||
3137         error "saving $name on $file failed"
3138
3139     local new_value=$(get_xattr_value $name $file)
3140     [[ "$new_value" != "$large_value" ]] &&
3141         error "$name different after saving"
3142
3143     log "shrink value of $name on $file"
3144     setfattr -n $name -v $small_value $file ||
3145         error "shrinking value of $name on $file failed"
3146
3147     new_value=$(get_xattr_value $name $file)
3148     [[ "$new_value" != "$small_value" ]] &&
3149         error "$name different after shrinking"
3150
3151     log "grow value of $name on $file"
3152     setfattr -n $name -v $large_value $file ||
3153         error "growing value of $name on $file failed"
3154
3155     new_value=$(get_xattr_value $name $file)
3156     [[ "$new_value" != "$large_value" ]] &&
3157         error "$name different after growing"
3158
3159     log "check value of $name on $file after remounting MDS"
3160     fail $SINGLEMDS
3161     new_value=$(get_xattr_value $name $file)
3162     [[ "$new_value" != "$large_value" ]] &&
3163         error "$name different after remounting MDS"
3164
3165     log "remove large xattr $name from $file"
3166     setfattr -x $name $file || error "removing $name from $file failed"
3167
3168     rm -f $file
3169     stopall
3170         if $reformat; then
3171                 LDISKFS_MKFS_OPTS=${LDISKFS_MKFS_OPTS% -O large_xattr}
3172                 reformat
3173         fi
3174 }
3175 run_test 61 "large xattr"
3176
3177 test_62() {
3178         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3179                 skip "Only applicable to ldiskfs-based MDTs"
3180                 return
3181         fi
3182
3183         # MRP-118
3184         local mdsdev=$(mdsdevname 1)
3185         local ostdev=$(ostdevname 1)
3186
3187         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
3188                 { skip "Need MDS version at least 2.2.51"; return 0; }
3189
3190         echo "disable journal for mds"
3191         do_facet mds tune2fs -O ^has_journal $mdsdev || error "tune2fs failed"
3192         start_mds && error "MDT start should fail"
3193         echo "disable journal for ost"
3194         do_facet ost1 tune2fs -O ^has_journal $ostdev || error "tune2fs failed"
3195         start_ost && error "OST start should fail"
3196         cleanup || return $?
3197         reformat_and_config
3198 }
3199 run_test 62 "start with disabled journal"
3200
3201 test_63() {
3202         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3203                 skip "Only applicable to ldiskfs-based MDTs"
3204                 return
3205         fi
3206
3207         local inode_slab=$(do_facet $SINGLEMDS \
3208                 "awk '/ldiskfs_inode_cache/ { print \\\$5 }' /proc/slabinfo")
3209         if [ -z "$inode_slab" ]; then
3210                 skip "ldiskfs module has not been loaded"
3211                 return
3212         fi
3213
3214         echo "$inode_slab ldisk inodes per page"
3215         [ "$inode_slab" -ge "3" ] ||
3216                 error "ldisk inode size is too big, $inode_slab objs per page"
3217         return
3218 }
3219 run_test 63 "Verify each page can at least hold 3 ldisk inodes"
3220
3221 test_64() {
3222         start_mds
3223         start_ost
3224         start_ost2 || error "Unable to start second ost"
3225         mount_client $MOUNT || error "Unable to mount client"
3226         stop_ost2 || error "Unable to stop second ost"
3227         echo "$LFS df"
3228         $LFS df --lazy || error "lfs df failed"
3229         cleanup || return $?
3230 }
3231 run_test 64 "check lfs df --lazy "
3232
3233 if ! combined_mgs_mds ; then
3234         stop mgs
3235 fi
3236
3237 cleanup_gss
3238
3239 complete $SECONDS
3240 exit_status