Whamcloud - gitweb
b=24226 typo fix for sanity test 72
[fs/lustre-release.git] / lustre / tests / conf-sanity.sh
1 #!/bin/bash
2 # requirement:
3 #       add uml1 uml2 uml3 in your /etc/hosts
4
5 # FIXME - there is no reason to use all of these different
6 #   return codes, espcially when most of them are mapped to something
7 #   else anyway.  The combination of test number and return code
8 #   figure out what failed.
9
10 set -e
11
12 ONLY=${ONLY:-"$*"}
13
14 # bug number for skipped test:      13369
15 ALWAYS_EXCEPT=" $CONF_SANITY_EXCEPT 34a"
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17
18 if [ "$FAILURE_MODE" = "HARD" ]; then
19         CONFIG_EXCEPTIONS="24a " && \
20         echo "Except the tests: $CONFIG_EXCEPTIONS for FAILURE_MODE=$FAILURE_MODE, bug 23573" && \
21         ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
22 fi
23
24 SRCDIR=`dirname $0`
25 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
26
27 SAVE_PWD=$PWD
28 LUSTRE=${LUSTRE:-`dirname $0`/..}
29 RLUSTRE=${RLUSTRE:-$LUSTRE}
30 HOSTNAME=`hostname`
31
32 . $LUSTRE/tests/test-framework.sh
33 init_test_env $@
34 # STORED_MDSSIZE is used in test_18
35 if [ -n "$MDSSIZE" ]; then
36     STORED_MDSSIZE=$MDSSIZE
37 fi
38 # use small MDS + OST size to speed formatting time
39 MDSSIZE=40000
40 OSTSIZE=40000
41 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
42
43 if ! combined_mgs_mds; then
44     # bug number for skipped test:    23954
45     ALWAYS_EXCEPT="$ALWAYS_EXCEPT       24b"
46 fi
47
48 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
49 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
50
51 #
52 [ "$SLOW" = "no" ] && EXCEPT_SLOW="30 31 45"
53
54 assert_DIR
55
56 reformat() {
57         formatall
58 }
59
60 writeconf1() {
61         local facet=$1
62         local dev=$2
63
64         stop ${facet} -f
65         rm -f ${facet}active
66         # who knows if/where $TUNEFS is installed?  Better reformat if it fails...
67         do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" ||
68                 { echo "tunefs failed, reformatting instead" && reformat_and_config && return 1; }
69         return 0
70 }
71
72 writeconf() {
73         # we need ldiskfs
74         load_modules
75         # if writeconf fails anywhere, we reformat everything
76         writeconf1 mds $MDSDEV || return 0
77         writeconf1 ost1 `ostdevname 1` || return 0
78         writeconf1 ost2 `ostdevname 2` || return 0
79 }
80
81 gen_config() {
82         # The MGS must be started before the OSTs for a new fs, so start
83         # and stop to generate the startup logs.
84         start_mds
85         start_ost
86         wait_osc_import_state mds ost FULL
87         stop_ost
88         stop_mds
89 }
90
91 reformat_and_config() {
92         reformat
93         if ! combined_mgs_mds ; then
94                 start_mgs
95         fi
96         gen_config
97 }
98
99 start_mgs () {
100         echo "start mgs"
101         start mgs $MGSDEV $MGS_MOUNT_OPTS
102 }
103
104 start_mds() {
105         echo "start mds service on `facet_active_host mds`"
106         start mds $MDSDEV $MDS_MOUNT_OPTS $@ || return 94
107 }
108
109 stop_mgs() {
110         echo "stop mgs service on `facet_active_host mgs`"
111         # These tests all use non-failover stop
112         stop mgs -f  || return 97
113 }
114
115 start_mgsmds() {
116         if ! combined_mgs_mds ; then
117                 start_mgs
118         fi
119         start_mds $@
120 }
121
122 stop_mds() {
123         echo "stop mds service on `facet_active_host mds`"
124         # These tests all use non-failover stop
125         stop mds -f  || return 97
126 }
127
128 start_ost() {
129         echo "start ost1 service on `facet_active_host ost1`"
130         start ost1 `ostdevname 1` $OST_MOUNT_OPTS $@ || return 95
131 }
132
133 stop_ost() {
134         echo "stop ost1 service on `facet_active_host ost1`"
135         # These tests all use non-failover stop
136         stop ost1 -f  || return 98
137 }
138
139 start_ost2() {
140         echo "start ost2 service on `facet_active_host ost2`"
141         start ost2 `ostdevname 2` $OST_MOUNT_OPTS $@ || return 92
142 }
143
144 stop_ost2() {
145         echo "stop ost2 service on `facet_active_host ost2`"
146         # These tests all use non-failover stop
147         stop ost2 -f  || return 93
148 }
149
150 start_client() {
151         echo "start client on `facet_active_host client`"
152         start client || return 99
153 }
154
155 stop_client() {
156         echo "stop client on `facet_active_host client`"
157         stop client || return 100
158 }
159
160 mount_client() {
161         local MOUNTPATH=$1
162         echo "mount $FSNAME on ${MOUNTPATH}....."
163         zconf_mount `hostname` $MOUNTPATH  || return 96
164 }
165
166 remount_client() {
167         local SAVEMOUNTOPT=$MOUNTOPT
168         MOUNTOPT="remount,$1"
169         local MOUNTPATH=$2
170         echo "remount '$1' lustre on ${MOUNTPATH}....."
171         zconf_mount `hostname`  $MOUNTPATH  || return 96
172         MOUNTOPT=$SAVEMOUNTOPT
173 }
174
175 umount_client() {
176         local MOUNTPATH=$1
177         echo "umount lustre on ${MOUNTPATH}....."
178         zconf_umount `hostname` $MOUNTPATH || return 97
179 }
180
181 manual_umount_client(){
182         local rc
183         local FORCE=$1
184         echo "manual umount lustre on ${MOUNT}...."
185         do_facet client "umount -d ${FORCE} $MOUNT"
186         rc=$?
187         return $rc
188 }
189
190 setup() {
191         start_mds || error "MDT start failed"
192         start_ost || error "OST start failed"
193         mount_client $MOUNT || error "client start failed"
194         df $MOUNT
195 }
196
197 setup_noconfig() {
198         if ! combined_mgs_mds ; then
199                 start_mgs
200         fi
201
202         start_mds
203         start_ost
204         mount_client $MOUNT
205 }
206
207 unload_modules_conf () {
208         if combined_mgs_mds || ! local_mode; then
209                 unload_modules || return 1
210         fi
211 }
212
213 cleanup_nocli() {
214         stop_mds || return 201
215         stop_ost || return 202
216         unload_modules_conf || return 203
217 }
218
219 cleanup() {
220         umount_client $MOUNT || return 200
221         cleanup_nocli || return $?
222 }
223
224 check_mount() {
225         do_facet client "cp /etc/passwd $DIR/a" || return 71
226         do_facet client "rm $DIR/a" || return 72
227         # make sure lustre is actually mounted (touch will block,
228         # but grep won't, so do it after)
229         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
230         echo "setup single mount lustre success"
231 }
232
233 check_mount2() {
234         do_facet client "touch $DIR/a" || return 71
235         do_facet client "rm $DIR/a" || return 72
236         do_facet client "touch $DIR2/a" || return 73
237         do_facet client "rm $DIR2/a" || return 74
238         echo "setup double mount lustre success"
239 }
240
241 build_test_filter
242
243 if [ "$ONLY" == "setup" ]; then
244         setup
245         exit
246 fi
247
248 if [ "$ONLY" == "cleanup" ]; then
249         cleanup
250         exit
251 fi
252
253 #create single point mountpoint
254
255 reformat_and_config
256
257 test_0() {
258         setup
259         check_mount || return 41
260         cleanup || return $?
261 }
262 run_test 0 "single mount setup"
263
264 test_1() {
265         start_ost
266         echo "start ost second time..."
267         start_ost && error "2nd OST start should fail"
268         start_mds || error "MDT start failed"
269         mount_client $MOUNT || error "client start failed"
270         check_mount || return 42
271         cleanup || return $?
272 }
273 run_test 1 "start up ost twice (should return errors)"
274
275 test_2() {
276         start_ost
277         start_mds
278         echo "start mds second time.."
279         start_mds && error "2nd MDT start should fail"
280         mount_client $MOUNT
281         check_mount || return 43
282         cleanup || return $?
283 }
284 run_test 2 "start up mds twice (should return err)"
285
286 test_3() {
287         setup
288         #mount.lustre returns an error if already in mtab
289         mount_client $MOUNT && error "2nd client mount should fail"
290         check_mount || return 44
291         cleanup || return $?
292 }
293 run_test 3 "mount client twice (should return err)"
294
295 test_4() {
296         setup
297         touch $DIR/$tfile || return 85
298         stop_ost -f
299         cleanup
300         eno=$?
301         # ok for ost to fail shutdown
302         if [ 202 -ne $eno ]; then
303                 return $eno;
304         fi
305         return 0
306 }
307 run_test 4 "force cleanup ost, then cleanup"
308
309 test_5a() {     # was test_5
310         setup
311         touch $DIR/$tfile || return 1
312         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
313
314         stop_mds -f || return 2
315
316         # cleanup may return an error from the failed
317         # disconnects; for now I'll consider this successful
318         # if all the modules have unloaded.
319         umount -d $MOUNT &
320         UMOUNT_PID=$!
321         sleep 6
322         echo "killing umount"
323         kill -TERM $UMOUNT_PID
324         echo "waiting for umount to finish"
325         wait $UMOUNT_PID
326         if grep " $MOUNT " /proc/mounts; then
327                 echo "test 5: /proc/mounts after failed umount"
328                 umount $MOUNT &
329                 UMOUNT_PID=$!
330                 sleep 2
331                 echo "killing umount"
332                 kill -TERM $UMOUNT_PID
333                 echo "waiting for umount to finish"
334                 wait $UMOUNT_PID
335                 grep " $MOUNT " /proc/mounts && echo "test 5: /proc/mounts after second umount" && return 11
336         fi
337
338         manual_umount_client
339         # stop_mds is a no-op here, and should not fail
340         cleanup_nocli || return $?
341         # df may have lingering entry
342         manual_umount_client
343         # mtab may have lingering entry
344         local WAIT=0
345         local MAX_WAIT=20
346         local sleep=1
347         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
348                 sleep $sleep
349                 grep -q $MOUNT" " /etc/mtab || break
350                 echo "Waiting /etc/mtab updated ... "
351                 WAIT=$(( WAIT + sleep))
352         done
353         [ "$WAIT" -eq "$MAX_WAIT" ] && error "/etc/mtab is not updated in $WAIT secs"
354         echo "/etc/mtab updated in $WAIT secs"
355 }
356 run_test 5a "force cleanup mds, then cleanup"
357
358 cleanup_5b () {
359         trap 0
360         start_mgs
361 }
362
363 test_5b() {
364         grep " $MOUNT " /etc/mtab && \
365                 error false "unexpected entry in mtab before mount" && return 10
366
367         local rc=0
368         start_ost
369         if ! combined_mgs_mds ; then
370                 trap cleanup_5b EXIT ERR
371                 start_mds
372                 stop mgs
373         fi
374
375         [ -d $MOUNT ] || mkdir -p $MOUNT
376         mount_client $MOUNT && rc=1
377         grep " $MOUNT " /etc/mtab && \
378                 error "$MOUNT entry in mtab after failed mount" && rc=11
379         umount_client $MOUNT
380         # stop_mds is a no-op here, and should not fail
381         cleanup_nocli || rc=$?
382         if ! combined_mgs_mds ; then
383                 cleanup_5b
384         fi
385         return $rc
386 }
387 run_test 5b "Try to start a client with no MGS (should return errs)"
388
389 test_5c() {
390         grep " $MOUNT " /etc/mtab && \
391                 error false "unexpected entry in mtab before mount" && return 10
392
393         local rc=0
394         start_ost
395         start_mds
396         [ -d $MOUNT ] || mkdir -p $MOUNT
397         local oldfs="${FSNAME}"
398         FSNAME="wrong.${FSNAME}"
399         mount_client $MOUNT || :
400         FSNAME=${oldfs}
401         grep " $MOUNT " /etc/mtab && \
402                 error "$MOUNT entry in mtab after failed mount" && rc=11
403         umount_client $MOUNT
404         cleanup_nocli  || rc=$?
405         return $rc
406 }
407 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
408
409 test_5d() {
410         grep " $MOUNT " /etc/mtab && \
411                 error false "unexpected entry in mtab before mount" && return 10
412
413         local rc=0
414         start_ost
415         start_mds
416         stop_ost -f
417         mount_client $MOUNT || rc=1
418         cleanup  || rc=$?
419         grep " $MOUNT " /etc/mtab && \
420                 error "$MOUNT entry in mtab after unmount" && rc=11
421         return $rc
422 }
423 run_test 5d "mount with ost down"
424
425 test_5e() {
426         grep " $MOUNT " /etc/mtab && \
427                 error false "unexpected entry in mtab before mount" && return 10
428
429         local rc=0
430         start_ost
431         start_mds
432
433 #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
434         do_facet client "lctl set_param fail_loc=0x80000506"
435         mount_client $MOUNT || echo "mount failed (not fatal)"
436         cleanup  || rc=$?
437         grep " $MOUNT " /etc/mtab && \
438                 error "$MOUNT entry in mtab after unmount" && rc=11
439         return $rc
440 }
441 run_test 5e "delayed connect, don't crash (bug 10268)"
442
443 test_5f() {
444         if combined_mgs_mds ; then
445                 skip "combined mgs and mds"
446                 return 0
447         fi
448
449         grep " $MOUNT " /etc/mtab && \
450                 error false "unexpected entry in mtab before mount" && return 10
451
452         local rc=0
453         start_ost
454         [ -d $MOUNT ] || mkdir -p $MOUNT
455         mount_client $MOUNT &
456         local pid=$!
457         echo client_mount pid is $pid
458
459         sleep 5
460
461         if ! ps -f -p $pid >/dev/null; then 
462                 wait $pid
463                 rc=$?
464                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
465                 error "mount returns $rc, expected to hang"
466                 rc=11
467                 cleanup || rc=$?
468                 return $rc
469         fi
470
471         # start mds
472         start_mds
473
474         # mount should succeed after start mds 
475         wait $pid
476         rc=$?
477         [ $rc -eq 0 ] || error "mount returned $rc"
478         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
479         cleanup || return $?
480         return $rc
481 }
482 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
483
484 test_6() {
485         setup
486         manual_umount_client
487         mount_client ${MOUNT} || return 87
488         touch $DIR/a || return 86
489         cleanup  || return $?
490 }
491 run_test 6 "manual umount, then mount again"
492
493 test_7() {
494         setup
495         manual_umount_client
496         cleanup_nocli || return $?
497 }
498 run_test 7 "manual umount, then cleanup"
499
500 test_8() {
501         setup
502         mount_client $MOUNT2
503         check_mount2 || return 45
504         umount_client $MOUNT2
505         cleanup  || return $?
506 }
507 run_test 8 "double mount setup"
508
509 test_9() {
510         start_ost
511
512         do_facet ost1 lctl set_param debug=\'inode trace\' || return 1
513         do_facet ost1 lctl set_param subsystem_debug=\'mds ost\' || return 1
514
515         CHECK_PTLDEBUG="`do_facet ost1 lctl get_param -n debug`"
516         # interop 1.8 <-> 2.0: "trace inode warning error emerg console"
517         local lustre_version=$(get_lustre_version ost1)
518         echo ost1 running $lustre_version
519         if [ "$CHECK_PTLDEBUG" ] && [ "$CHECK_PTLDEBUG" = "trace inode" ]; then
520             echo "lnet.debug success"
521         elif [[ $lustre_version != 1.8* ]] && \
522                 [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ]; then
523             echo "lnet.debug success"
524         else
525            echo "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
526            return 1
527         fi
528         CHECK_SUBSYS="`do_facet ost1 lctl get_param -n subsystem_debug`"
529         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
530            echo "lnet.subsystem_debug success"
531         else
532            echo "lnet.subsystem_debug: want 'mds ost', have '$CHECK_SUBSYS'"
533            return 1
534         fi
535         stop_ost || return $?
536 }
537 run_test 9 "test ptldebug and subsystem for mkfs"
538
539 is_blkdev () {
540         local facet=$1
541         local dev=$2
542         local size=${3:-""}
543
544         local rc=0
545         do_facet $facet "test -b $dev" || rc=1
546         if [[ "$size" ]]; then
547                 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k count=1 skip=$size 2>&1" |\
548                         awk '($3 == "in") { print $1 }')
549                 [[ $in  = "1+0" ]] || rc=1
550         fi
551         return $rc
552 }
553
554 test_16() {
555         setup
556         # Skip this test if MDS is 2.0+, see bug 22944.
557         if [[ "$(get_mds_version_major)" != "1" ]]; then
558                 skip "not running on 2.0 server"
559                 cleanup
560                 return 0
561         fi
562
563         check_mount || return 41
564         cleanup || return $?
565
566         local TMPMTPT="${TMP}/conf16"
567         local files="{OBJECTS,PENDING,LOGS}"
568
569         is_blkdev mds $MDSDEV || LOOPOPT="-o loop"
570
571         log "change the mode of $MDSDEV/$files to 555"
572         do_facet mds "mkdir -p $TMPMTPT &&
573                       mount $LOOPOPT -t $FSTYPE $MDSDEV $TMPMTPT &&
574                       chmod 555 $TMPMTPT/$files &&
575                       umount $TMPMTPT" || return $?
576
577         log "mount Lustre to change the mode of $files, then umount Lustre"
578         setup
579         check_mount || return 41
580         cleanup || return $?
581
582         log "read the mode of $files and check if they has been changed properly"
583         local file
584         for file in ${files//[\{\},]/ }; do
585             expected=`do_facet mds "$DEBUGFS -R 'stat $file' $MDSDEV 2> /dev/null" | \
586                        grep 'Mode: ' | sed -e "s/.*Mode: *//" -e "s/ *Flags:.*//"`
587
588             if [ "$expected" = "0777" ]; then
589                 log "Success:Lustre change the mode of $file correctly"
590             else
591                 error "Lustre does not change mode of $file properly"
592             fi
593         done
594 }
595 run_test 16 "verify that lustre will correct the mode of OBJECTS/LOGS/PENDING"
596
597 test_17() {
598         setup
599         check_mount || return 41
600         cleanup || return $?
601
602         echo "Remove mds config log"
603         if ! combined_mgs_mds ; then
604                 stop mgs
605         fi
606
607         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' $MGSDEV || return \$?" || return $?
608
609         if ! combined_mgs_mds ; then
610                 start_mgs
611         fi
612
613         start_ost
614         start_mds && return 42
615         reformat_and_config
616 }
617 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
618
619 test_18() {
620         [ "$FSTYPE" != "ldiskfs" ] && skip "not needed for FSTYPE=$FSTYPE" && return
621
622         local MIN=2000000
623
624         local OK=
625         # check if current MDSSIZE is large enough
626         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE && \
627                 log "use MDSSIZE=$MDSSIZE"
628
629         # check if the global config has a large enough MDSSIZE
630         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] && [ $STORED_MDSSIZE -ge $MIN ] && \
631                 OK=1 && myMDSSIZE=$STORED_MDSSIZE && \
632                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
633
634         # check if the block device is large enough
635         [ -z "$OK" ] && $(is_blkdev mds $MDSDEV $MIN) && OK=1 &&
636                 myMDSSIZE=$MIN && log "use device $MDSDEV with MIN=$MIN"
637
638         # check if a loopback device has enough space for fs metadata (5%)
639
640         if [ -z "$OK" ]; then
641                 local SPACE=$(do_facet mds "[ -f $MDSDEV -o ! -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
642                         awk '($1 != "Filesystem") {print $4}')
643                 ! [ -z "$SPACE" ]  &&  [ $SPACE -gt $((MIN / 20)) ] && \
644                         OK=1 && myMDSSIZE=$MIN && \
645                         log "use file $MDSDEV with MIN=$MIN"
646         fi
647
648         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
649
650
651         echo "mount mds with large journal..."
652         local OLD_MDS_MKFS_OPTS=$MDS_MKFS_OPTS
653
654         local opts="--mdt --fsname=$FSNAME --device-size=$myMDSSIZE --param sys.timeout=$TIMEOUT $MDSOPT" 
655
656         if combined_mgs_mds ; then
657             MDS_MKFS_OPTS="--mgs $opts"
658         else
659             MDS_MKFS_OPTS="--mgsnode=$MGSNID $opts"
660         fi
661
662         reformat_and_config
663         echo "mount lustre system..."
664         setup
665         check_mount || return 41
666
667         echo "check journal size..."
668         local FOUNDSIZE=$(do_facet mds "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
669         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
670                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
671         else
672                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
673         fi
674
675         cleanup || return $?
676
677         MDS_MKFS_OPTS=$OLD_MDS_MKFS_OPTS
678         reformat_and_config
679 }
680 run_test 18 "check mkfs creates large journals"
681
682 test_19a() {
683         start_mds || return 1
684         stop_mds -f || return 2
685 }
686 run_test 19a "start/stop MDS without OSTs"
687
688 test_19b() {
689         start_ost || return 1
690         stop_ost -f || return 2
691 }
692 run_test 19b "start/stop OSTs without MDS"
693
694 test_20() {
695         # first format the ost/mdt
696         start_ost
697         start_mds
698         mount_client $MOUNT
699         check_mount || return 43
700         rm -f $DIR/$tfile
701         remount_client ro $MOUNT || return 44
702         touch $DIR/$tfile && echo "$DIR/$tfile created incorrectly" && return 45
703         [ -e $DIR/$tfile ] && echo "$DIR/$tfile exists incorrectly" && return 46
704         remount_client rw $MOUNT || return 47
705         touch $DIR/$tfile
706         [ ! -f $DIR/$tfile ] && echo "$DIR/$tfile missing" && return 48
707         MCNT=`grep -c $MOUNT /etc/mtab`
708         [ "$MCNT" -ne 1 ] && echo "$MOUNT in /etc/mtab $MCNT times" && return 49
709         umount_client $MOUNT
710         stop_mds
711         stop_ost
712 }
713 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
714
715 test_21a() {
716         start_mds
717         start_ost
718         wait_osc_import_state mds ost FULL
719         stop_ost
720         stop_mds
721 }
722 run_test 21a "start mds before ost, stop ost first"
723
724 test_21b() {
725         start_ost
726         start_mds
727         wait_osc_import_state mds ost FULL
728         stop_mds
729         stop_ost
730 }
731 run_test 21b "start ost before mds, stop mds first"
732
733 test_21c() {
734         start_ost
735         start_mds
736         start_ost2
737         wait_osc_import_state mds ost2 FULL
738
739         stop_ost
740         stop_ost2
741         stop_mds
742         #writeconf to remove all ost2 traces for subsequent tests
743         writeconf
744 }
745 run_test 21c "start mds between two osts, stop mds last"
746
747 test_21d() {
748         if combined_mgs_mds ; then
749                 skip "need separate mgs device" && return 0
750         fi
751         stopall
752
753         reformat
754
755         start_mgs
756         start_ost
757         start_ost2
758         start_mds
759
760         stop_ost
761         stop_ost2
762         stop_mds
763         writeconf
764 }
765 run_test 21d "start mgs then ost and then mds"
766
767
768 test_22() {
769         start_mds
770
771         echo Client mount with ost in logs, but none running
772         start_ost
773         wait_osc_import_state mds ost FULL
774         stop_ost
775         mount_client $MOUNT
776         # check_mount will block trying to contact ost
777         mcreate $DIR/$tfile || return 40
778         rm -f $DIR/$tfile || return 42
779         umount_client $MOUNT
780         pass
781
782         echo Client mount with a running ost
783         start_ost
784         mount_client $MOUNT
785         check_mount || return 41
786         pass
787
788         cleanup
789 }
790 run_test 22 "start a client before osts (should return errs)"
791
792 test_23a() {    # was test_23
793         setup
794         # fail mds
795         stop mds
796         # force down client so that recovering mds waits for reconnect
797         local running=$(grep -c $MOUNT /proc/mounts) || true
798         if [ $running -ne 0 ]; then
799                 echo "Stopping client $MOUNT (opts: -f)"
800                 umount -f $MOUNT
801         fi
802
803         # enter recovery on mds
804         start_mds
805         # try to start a new client
806         mount_client $MOUNT &
807         sleep 5
808         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
809         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
810         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
811         ps --ppid $MOUNT_PID
812         ps --ppid $MOUNT_LUSTRE_PID
813         # FIXME why o why can't I kill these? Manual "ctrl-c" works...
814         kill -TERM $MOUNT_LUSTRE_PID
815         echo "waiting for mount to finish"
816         ps -ef | grep mount
817         # we can not wait $MOUNT_PID because it is not a child of this shell
818         local PID1
819         local PID2
820         local WAIT=0
821         local MAX_WAIT=30
822         local sleep=1
823         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
824                 sleep $sleep
825                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
826                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
827                 echo PID1=$PID1
828                 echo PID2=$PID2
829                 [ -z "$PID1" -a -z "$PID2" ] && break
830                 echo "waiting for mount to finish ... "
831                 WAIT=$(( WAIT + sleep))
832         done
833         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
834                 error "MOUNT_PID $MOUNT_PID and \
835                 MOUNT__LUSTRE_PID $MOUNT__LUSTRE_PID still not killed in $WAIT secs"
836                 ps -ef | grep mount
837         fi
838         stop_mds || error
839         stop_ost || error
840 }
841 run_test 23a "interrupt client during recovery mount delay"
842
843 umount_client $MOUNT
844 cleanup_nocli
845
846 test_23b() {    # was test_23
847         start_ost
848         start_mds
849         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
850         lctl set_param fail_loc=0x80000313
851         mount_client $MOUNT
852         cleanup
853 }
854 run_test 23b "Simulate -EINTR during mount"
855
856 fs2mds_HOST=$mds_HOST
857 fs2ost_HOST=$ost_HOST
858
859 cleanup_24a() {
860         trap 0
861         echo "umount $MOUNT2 ..."
862         umount $MOUNT2 || true
863         echo "stopping fs2mds ..."
864         stop fs2mds -f || true
865         echo "stopping fs2ost ..."
866         stop fs2ost -f || true
867 }
868
869 test_24a() {
870         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
871                 is_blkdev mds $MDSDEV && \
872                 skip_env "mixed loopback and real device not working" && return
873         fi
874
875         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
876         
877         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
878         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
879
880         # test 8-char fsname as well
881         local FSNAME2=test1234
882         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --nomgs --mgsnode=$MGSNID --reformat $fs2mdsdev || exit 10
883
884         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2ostdev || exit 10
885
886         setup
887         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
888         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
889         mkdir -p $MOUNT2
890         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
891         # 1 still works
892         check_mount || return 2
893         # files written on 1 should not show up on 2
894         cp /etc/passwd $DIR/$tfile
895         sleep 10
896         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
897         # 2 should work
898         cp /etc/passwd $MOUNT2/b || return 3
899         rm $MOUNT2/b || return 4
900         # 2 is actually mounted
901         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
902         # failover
903         facet_failover fs2mds
904         facet_failover fs2ost
905         df
906         umount_client $MOUNT
907         # the MDS must remain up until last MDT
908         stop_mds
909
910         local mdt_obdname=$(do_facet mds "lctl get_param -n devices" | \
911         awk '/ mdt / { print $4 }' | head -1)
912         [ -z "$mdt_obdname" ] && error "No MDT" && return 8
913         
914         cleanup_24a
915         cleanup_nocli || return 6
916 }
917 run_test 24a "Multiple MDTs on a single node"
918
919 test_24b() {
920         if [ -z "$fs2mds_DEV" ]; then
921                 is_blkdev mds $MDSDEV && \
922                 skip_env "mixed loopback and real device not working" && return
923         fi
924
925         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
926
927         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME}2 --mgs --reformat $fs2mdsdev || exit 10
928         setup
929         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
930         cleanup || return 6
931 }
932 run_test 24b "Multiple MGSs on a single node (should return err)"
933
934 test_25() {
935         setup
936         check_mount || return 2
937         local MODULES=$($LCTL modules | awk '{ print $2 }')
938         rmmod $MODULES 2>/dev/null || true
939         cleanup || return 6
940 }
941 run_test 25 "Verify modules are referenced"
942
943 test_26() {
944     load_modules
945     # we need modules before mount for sysctl, so make sure...
946     do_facet mds "lsmod | grep -q lustre || modprobe lustre"
947 #define OBD_FAIL_MDS_FS_SETUP            0x135
948     do_facet mds "lctl set_param fail_loc=0x80000135"
949     start_mds && echo MDS started && return 1
950     lctl get_param -n devices
951     DEVS=$(lctl get_param -n devices | egrep -v MG | wc -l)
952     [ $DEVS -gt 0 ] && return 2
953     unload_modules_conf || return $?
954 }
955 run_test 26 "MDT startup failure cleans LOV (should return errs)"
956
957 set_and_check() {
958         local myfacet=$1
959         local TEST=$2
960         local PARAM=$3
961         local ORIG=$(do_facet $myfacet "$TEST")
962         if [ $# -gt 3 ]; then
963             local FINAL=$4
964         else
965             local -i FINAL
966             FINAL=$(($ORIG + 5))
967         fi
968         echo "Setting $PARAM from $ORIG to $FINAL"
969         do_facet mds "$LCTL conf_param $PARAM=$FINAL" || error conf_param failed
970
971         wait_update $(facet_host $myfacet) "$TEST" $FINAL || error check failed!
972 }
973
974 test_27a() {
975         start_ost || return 1
976         start_mds || return 2
977         echo "Requeue thread should have started: "
978         ps -e | grep ll_cfg_requeue
979         set_and_check ost1 "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" "$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         setup
986
987         # interop 1.8 <-> 2.0:
988         # 1.8: group_acquire_expire, 2.0: identity_acquire_expire 
989         local acquire_expire=$(do_facet mds lctl get_param md*.$FSNAME-MDT0000.*acquire_expire | \
990                 cut -d= -f1 | cut -d. -f3)
991         facet_failover mds
992         set_and_check mds "lctl get_param -n md*.$FSNAME-MDT0000.$acquire_expire" \
993                 "$FSNAME-MDT0000.mdt.$acquire_expire" || return 3
994         set_and_check client "lctl get_param -n mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight" \
995                 "$FSNAME-MDT0000.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_and_check client "$TEST" "$PARAM" $FINAL || return 3
1008         FINAL=$(($FINAL + 1))
1009         set_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_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-*.active"
1032         local PROC_UUID="osc.$FSNAME-OST0001-osc-*.ost_server_uuid"
1033
1034         ACTV=$(lctl get_param -n $PROC_ACT)
1035         DEAC=$((1 - $ACTV))
1036         set_and_check client "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
1037         # also check ost_server_uuid status
1038         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
1039         if [ -z "$RESULT" ]; then
1040             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
1041             return 3
1042         else
1043             echo "Live client success: got $RESULT"
1044         fi
1045
1046         # check MDT too
1047         local MPROC="osc.$(get_mdtosc_proc_path $FSNAME-OST0001).active"
1048         local MAX=30
1049         local WAIT=0
1050         while [ 1 ]; do
1051             sleep 5
1052             RESULT=`do_facet mds " lctl get_param -n $MPROC"`
1053             [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
1054             if [ $RESULT -eq $DEAC ]; then
1055                 echo "MDT deactivated also after $WAIT sec (got $RESULT)"
1056                 break
1057             fi
1058             WAIT=$((WAIT + 5))
1059             if [ $WAIT -eq $MAX ]; then
1060                 echo "MDT not deactivated: wanted $DEAC got $RESULT"
1061                 return 4
1062             fi
1063             echo "Waiting $(($MAX - $WAIT)) secs for MDT deactivated"
1064         done
1065
1066         # test new client starts deactivated
1067         umount_client $MOUNT || return 200
1068         mount_client $MOUNT
1069         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1070         if [ -z "$RESULT" ]; then
1071             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
1072             return 5
1073         else
1074             echo "New client success: got $RESULT"
1075         fi
1076
1077         # make sure it reactivates
1078         set_and_check client "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
1079
1080         umount_client $MOUNT
1081         stop_ost2
1082         cleanup_nocli
1083         #writeconf to remove all ost2 traces for subsequent tests
1084         writeconf
1085 }
1086 run_test 29 "permanently remove an OST"
1087
1088 test_30a() {
1089         setup
1090
1091         echo Big config llog
1092         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1093         ORIG=$($TEST)
1094         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1095         for i in ${LIST[@]}; do
1096             set_and_check client "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
1097         done
1098         # make sure client restart still works
1099         umount_client $MOUNT
1100         mount_client $MOUNT || return 4
1101         [ "$($TEST)" -ne "$i" ] && error "Param didn't stick across restart $($TEST) != $i"
1102         pass
1103
1104         echo Erase parameter setting
1105         do_facet mgs "$LCTL conf_param -d $FSNAME.llite.max_read_ahead_whole_mb" || return 6
1106         umount_client $MOUNT
1107         mount_client $MOUNT || return 6
1108         FINAL=$($TEST)
1109         echo "deleted (default) value=$FINAL, orig=$ORIG"
1110         # assumes this parameter started at the default value
1111         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1112
1113         cleanup
1114 }
1115 run_test 30a "Big config llog and conf_param deletion"
1116
1117 test_30b() {
1118         setup
1119
1120         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1121         # numerical part of it. Hopefully that's not already a failover address for
1122         # the server.
1123         OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
1124         ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1125         NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1126         NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1127         echo "Using fake nid $NEW"
1128
1129         TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1130         set_and_check client "$TEST" "$FSNAME-OST0000.failover.node" $NEW || error "didn't add failover nid $NEW"
1131         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1132         echo $NIDS
1133         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1134         echo "should have 2 failover nids: $NIDCOUNT"
1135         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1136         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" || error "conf_param delete failed"
1137         umount_client $MOUNT
1138         mount_client $MOUNT || return 3
1139
1140         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1141         echo $NIDS
1142         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1143         echo "only 1 final nid should remain: $NIDCOUNT"
1144         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1145
1146         cleanup
1147 }
1148 run_test 30b "Remove failover nids"
1149
1150 test_31() { # bug 10734
1151         # ipaddr must not exist
1152         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
1153         cleanup
1154 }
1155 run_test 31 "Connect to non-existent node (returns errors, should not crash)"
1156
1157 # Use these start32/stop32 fn instead of t-f start/stop fn,
1158 # for local devices, to skip global facet vars init
1159 stop32 () {
1160         local facet=$1
1161         shift
1162         echo "Stopping local ${MOUNT%/*}/${facet} (opts:$@)"
1163         umount -d $@ ${MOUNT%/*}/${facet}
1164         losetup -a
1165 }
1166
1167 start32 () {
1168         local facet=$1
1169         shift
1170         local device=$1
1171         shift
1172         mkdir -p ${MOUNT%/*}/${facet}
1173
1174         echo "Starting local ${facet}: $@ $device ${MOUNT%/*}/${facet}"
1175         mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
1176         RC=$?
1177         if [ $RC -ne 0 ]; then
1178                 echo "mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}"
1179                 echo "Start of ${device} of local ${facet} failed ${RC}"
1180         fi
1181         losetup -a
1182         return $RC
1183 }
1184
1185 cleanup_nocli32 () {
1186         stop32 mds -f
1187         stop32 ost1 -f
1188         wait_exit_ST client
1189 }
1190
1191 cleanup_32() {
1192         trap 0
1193         echo "Cleanup test_32 umount $MOUNT ..."
1194         umount -f $MOUNT || true
1195         echo "Cleanup local mds ost1 ..."
1196         cleanup_nocli32
1197         combined_mgs_mds || start_mgs
1198         unload_modules_conf
1199 }
1200
1201 test_32a() {
1202         # this test is totally useless on a client-only system
1203         client_only && skip "client only testing" && return 0
1204         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
1205         [ -z "$TUNEFS" ] && skip_env "No tunefs" && return 0
1206
1207         local DISK1_6=$LUSTRE/tests/disk1_6.tar.bz2
1208         [ ! -r $DISK1_6 ] && skip_env "Cant find $DISK1_6, skipping" && return
1209
1210         local tmpdir=$TMP/conf32a
1211         mkdir -p $tmpdir
1212
1213         tar xjvf $DISK1_6 -C $tmpdir ||
1214                 { skip_env "Cant untar $DISK1_6, skipping" && return ; }
1215         load_modules
1216         lctl set_param debug=$PTLDEBUG
1217
1218         $TUNEFS $tmpdir/mds || error "tunefs failed"
1219
1220         combined_mgs_mds || stop mgs
1221
1222         # nids are wrong, so client wont work, but server should start
1223         start32 mds $tmpdir/mds "-o loop,exclude=lustre-OST0000" && \
1224                 trap cleanup_32 EXIT INT || return 3
1225
1226         local UUID=$(lctl get_param -n mds.lustre-MDT0000.uuid)
1227         echo MDS uuid $UUID
1228         [ "$UUID" == "lustre-MDT0000_UUID" ] || error "UUID is wrong: $UUID"
1229
1230         $TUNEFS --mgsnode=`hostname` $tmpdir/ost1 || error "tunefs failed"
1231         start32 ost1 $tmpdir/ost1 "-o loop" || return 5
1232         UUID=$(lctl get_param -n obdfilter.lustre-OST0000.uuid)
1233         echo OST uuid $UUID
1234         [ "$UUID" == "lustre-OST0000_UUID" ] || error "UUID is wrong: $UUID"
1235
1236         local NID=$($LCTL list_nids | head -1)
1237
1238         echo "OSC changes should succeed:"
1239         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 || return 7
1240         $LCTL conf_param lustre-OST0000.failover.node=$NID || return 8
1241         echo "ok."
1242         echo "MDC changes should succeed:"
1243         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1244         $LCTL conf_param lustre-MDT0000.failover.node=$NID || return 10
1245         echo "ok."
1246
1247         cleanup_32
1248
1249         # mount a second time to make sure we didnt leave upgrade flag on
1250         load_modules
1251         $TUNEFS --dryrun $tmpdir/mds || error "tunefs failed"
1252
1253         combined_mgs_mds || stop mgs
1254
1255         start32 mds $tmpdir/mds "-o loop,exclude=lustre-OST0000" && \
1256                 trap cleanup_32 EXIT INT || return 12
1257
1258         cleanup_32
1259
1260         rm -rf $tmpdir || true  # true is only for TMP on NFS
1261 }
1262 run_test 32a "Upgrade from 1.6 (not live)"
1263
1264 test_32b() {
1265         # this test is totally useless on a client-only system
1266         client_only && skip "client only testing" && return 0
1267         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
1268         [ -z "$TUNEFS" ] && skip_env "No tunefs" && return
1269
1270         local DISK1_6=$LUSTRE/tests/disk1_6.tar.bz2
1271         [ ! -r $DISK1_6 ] && skip_env "Cant find $DISK1_6, skipping" && return
1272
1273         local tmpdir=$TMP/conf32b
1274         mkdir -p $tmpdir
1275
1276         tar xjvf $DISK1_6 -C $tmpdir ||
1277                 { skip_env "Cant untar $DISK1_6, skipping" && return ; }
1278
1279         load_modules
1280         lctl set_param debug=$PTLDEBUG
1281
1282         # Ugrade process in according to comment 2 bug 20246
1283         # writeconf will cause servers to register with their current nids
1284         $TUNEFS --mdt --writeconf --erase-param \
1285                 --param="mdt.group_upcall=/usr/sbin/l_getgroups" $tmpdir/mds || \
1286                 error "tunefs mds failed"
1287
1288         combined_mgs_mds || stop mgs
1289
1290         start32 mds $tmpdir/mds "-o loop,abort_recov" && \
1291                 trap cleanup_32 EXIT INT || return 3
1292
1293         stop32 mds
1294         start32 mds "-o loop" $tmpdir/mds || return 4
1295         local UUID=$(lctl get_param -n mds.lustre-MDT0000.uuid)
1296         echo MDS uuid $UUID
1297         [ "$UUID" == "lustre-MDT0000_UUID" ] || error "UUID is wrong: $UUID"
1298
1299         $TUNEFS --ost --writeconf  --erase-param --mgsnode=`hostname`@$NETTYPE $tmpdir/ost1 || \
1300                 error "tunefs ost failed"
1301         start32 ost1 $tmpdir/ost1 "-o loop,abort_recov" || return 5
1302
1303         UUID=$(lctl get_param -n obdfilter.lustre-OST0000.uuid)
1304         echo OST uuid $UUID
1305         [ "$UUID" == "lustre-OST0000_UUID" ] || error "UUID is wrong: $UUID"
1306
1307         local NID=$($LCTL list_nids | head -1)
1308
1309         echo "OSC changes should succeed:"
1310         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 || error "OSC conf_param failed"
1311         $LCTL conf_param lustre-OST0000.failover.node=$NID || error "add failover nid=$NID failed"
1312         echo "ok."
1313         echo "MDC changes should succeed:"
1314         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1315         echo "ok."
1316
1317         # MDT and OST should have registered with new nids, so we should have
1318         # a fully-functioning client
1319         echo "Check client and old fs contents"
1320
1321         local device=`h2$NETTYPE $HOSTNAME`:/lustre
1322         echo "Starting local client: $HOSTNAME: $device $MOUNT"
1323         mount -t lustre $device $MOUNT || return 1
1324
1325         local old=$(lctl get_param -n mdc.*.max_rpcs_in_flight)
1326         local new=$((old + 5))
1327         lctl conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=$new
1328         wait_update $HOSTNAME "lctl get_param -n mdc.*.max_rpcs_in_flight" $new || return 11
1329
1330         [ "$(cksum $MOUNT/passwd | cut -d' ' -f 1,2)" == "2940530074 2837" ] || return 12
1331         echo "ok."
1332
1333         cleanup_32
1334
1335         rm -rf $tmpdir || true  # true is only for TMP on NFS
1336 }
1337 run_test 32b "Upgrade from 1.6 with writeconf"
1338
1339 test_33a() { # bug 12333, was test_33
1340         local rc=0
1341         local FSNAME2=test-123
1342         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1343
1344         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1345                 is_blkdev mds $MDSDEV && \
1346                 skip_env "mixed loopback and real device not working" && return
1347         fi
1348
1349         # interop 1.8 <-> 2.0
1350         local mkfs_opts
1351         local major=$(get_mds_version_major)
1352         local minor=$(get_mds_version_minor)
1353         if [ $major -le 1 -a $minor -le 8 ]; then
1354                 mkfs_opts=""
1355         else
1356                 mkfs_opts="--mkfsoptions='-J size=8'" # bug 17931
1357         fi
1358
1359         combined_mgs_mds || mkfs_opts="$mkfs_opts --nomgs"
1360
1361         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1362         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1363         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} $mkfs_opts --reformat $fs2mdsdev || exit 10
1364         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --index=8191 --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1365
1366         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1367         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1368         do_facet mds "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1369         mkdir -p $MOUNT2
1370         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1371         cp /etc/hosts $MOUNT2/. || rc=3
1372         echo "ok."
1373
1374         cp /etc/hosts $MOUNT2/ || rc=3
1375         $LFS getstripe $MOUNT2/hosts
1376
1377         umount -d $MOUNT2
1378         stop fs2ost -f
1379         stop fs2mds -f
1380         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev
1381         cleanup_nocli || rc=6
1382         return $rc
1383 }
1384 run_test 33a "Mount ost with a large index number"
1385
1386 test_33b() {    # was test_33a
1387         setup
1388
1389         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1390         # Drop lock cancelation reply during umount
1391         #define OBD_FAIL_LDLM_CANCEL             0x304
1392         do_facet client lctl set_param fail_loc=0x80000304
1393         #lctl set_param debug=-1
1394         umount_client $MOUNT
1395         cleanup
1396 }
1397 run_test 33b "Drop cancel during umount"
1398
1399 test_34a() {
1400         setup
1401         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
1402         manual_umount_client
1403         rc=$?
1404         do_facet client killall -USR1 multiop
1405         if [ $rc -eq 0 ]; then
1406                 error "umount not fail!"
1407         fi
1408         sleep 1
1409         cleanup
1410 }
1411 run_test 34a "umount with opened file should be fail"
1412
1413
1414 test_34b() {
1415         setup
1416         touch $DIR/$tfile || return 1
1417         stop_mds --force || return 2
1418
1419         manual_umount_client --force
1420         rc=$?
1421         if [ $rc -ne 0 ]; then
1422                 error "mtab after failed umount - rc $rc"
1423         fi
1424
1425         cleanup
1426         return 0
1427 }
1428 run_test 34b "force umount with failed mds should be normal"
1429
1430 test_34c() {
1431         setup
1432         touch $DIR/$tfile || return 1
1433         stop_ost --force || return 2
1434
1435         manual_umount_client --force
1436         rc=$?
1437         if [ $rc -ne 0 ]; then
1438                 error "mtab after failed umount - rc $rc"
1439         fi
1440
1441         cleanup
1442         return 0
1443 }
1444 run_test 34c "force umount with failed ost should be normal"
1445
1446 test_35a() { # bug 12459
1447         setup
1448
1449         debugsave
1450         lctl set_param debug="ha"
1451
1452         log "Set up a fake failnode for the MDS"
1453         FAKENID="127.0.0.2"
1454         do_facet mds $LCTL conf_param ${FSNAME}-MDT0000.failover.node=$FAKENID || return 4
1455
1456         log "Wait for RECONNECT_INTERVAL seconds (10s)"
1457         sleep 10
1458
1459         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
1460         $LCTL clear
1461         log "$MSG"
1462         log "Stopping the MDT:"
1463         stop_mds || return 5
1464
1465         df $MOUNT > /dev/null 2>&1 &
1466         DFPID=$!
1467         log "Restarting the MDT:"
1468         start_mds || return 6
1469         log "Wait for df ($DFPID) ... "
1470         wait $DFPID
1471         log "done"
1472         debugrestore
1473
1474         # retrieve from the log the first server that the client tried to
1475         # contact after the connection loss
1476         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1477         NEXTCONN=`awk "/${MSG}/ {start = 1;}
1478                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
1479                                 if (start) {
1480                                         if (\\\$NF ~ /$FAKENID/)
1481                                                 print \\\$NF;
1482                                         else
1483                                                 print 0;
1484                                         exit;
1485                                 }
1486                        }" $TMP/lustre-log-$TESTNAME.log`
1487         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
1488         cleanup
1489         # remove nid settings
1490         writeconf
1491 }
1492 run_test 35a "Reconnect to the last active server first"
1493
1494 test_35b() { # bug 18674
1495         remote_mds || { skip "local MDS" && return 0; }
1496         setup
1497
1498         debugsave
1499         $LCTL set_param debug="ha"
1500         $LCTL clear
1501         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
1502         log "$MSG"
1503
1504         log "Set up a fake failnode for the MDS"
1505         FAKENID="127.0.0.2"
1506         do_facet mds $LCTL conf_param ${FSNAME}-MDT0000.failover.node=$FAKENID || \
1507                 return 1
1508
1509         local at_max_saved=0
1510         # adaptive timeouts may prevent seeing the issue 
1511         if at_is_enabled; then
1512                 at_max_saved=$(at_max_get mds)
1513                 at_max_set 0 mds client
1514         fi
1515
1516         mkdir -p $MOUNT/$tdir
1517
1518         log "Injecting EBUSY on MDS"
1519         # Setting OBD_FAIL_MDS_RESEND=0x136
1520         do_facet mds "$LCTL set_param fail_loc=0x80000136" || return 2
1521
1522         $LCTL set_param mdc.${FSNAME}*.stats=clear
1523
1524         log "Creating a test file and stat it"
1525         touch $MOUNT/$tdir/$tfile
1526         stat $MOUNT/$tdir/$tfile
1527
1528         log "Stop injecting EBUSY on MDS"
1529         do_facet mds "$LCTL set_param fail_loc=0" || return 3
1530         rm -f $MOUNT/$tdir/$tfile
1531
1532         log "done"
1533         # restore adaptive timeout
1534         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
1535
1536         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1537
1538         CONNCNT=`$LCTL get_param mdc.${FSNAME}*.stats | awk '/mds_connect/{print $2}'`
1539
1540         # retrieve from the log if the client has ever tried to
1541         # contact the fake server after the loss of connection
1542         FAILCONN=`awk "BEGIN {ret = 0;}
1543                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
1544                                 ret = 1;
1545                                 if (\\\$NF ~ /$FAKENID/) {
1546                                         ret = 2;
1547                                         exit;
1548                                 }
1549                        }
1550                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
1551
1552         [ "$FAILCONN" == "0" ] && \
1553                 log "ERROR: The client reconnection has not been triggered" && \
1554                 return 4
1555         [ "$FAILCONN" == "2" ] && \
1556                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
1557                 return 5
1558
1559         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
1560         # Reconnects are supposed to be rate limited to one every 5s
1561         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] && \
1562                 log "ERROR: Too many reconnects $CONNCNT" && \
1563                 return 6
1564
1565         cleanup
1566         # remove nid settings
1567         writeconf
1568 }
1569 run_test 35b "Continue reconnection retries, if the active server is busy"
1570
1571 test_36() { # 12743
1572         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
1573
1574         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
1575                 { skip "remote OST" && return 0; }
1576
1577         local rc=0
1578         local FSNAME2=test1234
1579         local fs3ost_HOST=$ost_HOST
1580
1581         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
1582
1583         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
1584                 is_blkdev mds $MDSDEV && \
1585                 skip_env "mixed loopback and real device not working" && return
1586         fi
1587
1588         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1589         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1590         local fs3ostdev=${fs3ost_DEV:-$(ostdevname 2)_2}
1591         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2mdsdev || exit 10
1592         # XXX after we support non 4K disk blocksize, change following --mkfsoptions with
1593         # other argument
1594         add fs2ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1595         add fs3ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs3ostdev || exit 10
1596
1597         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
1598         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1599         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
1600         mkdir -p $MOUNT2
1601         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
1602
1603         sleep 5 # until 11778 fixed
1604
1605         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
1606
1607         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1608         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
1609         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
1610         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
1611         DFTOTAL=`echo $STRING | cut -d, -f1`
1612         DFUSED=`echo $STRING  | cut -d, -f2`
1613         DFAVAIL=`echo $STRING | cut -d, -f3`
1614         DFFREE=$(($DFTOTAL - $DFUSED))
1615
1616         ALLOWANCE=$((64 * $OSTCOUNT))
1617
1618         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
1619            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
1620                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
1621                 rc=1
1622         fi
1623         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
1624            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
1625                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
1626                 rc=2
1627         fi
1628         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
1629            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
1630                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
1631                 rc=3
1632        fi
1633
1634         umount -d $MOUNT2
1635         stop fs3ost -f || return 200
1636         stop fs2ost -f || return 201
1637         stop fs2mds -f || return 202
1638         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev $fs3ostdev
1639         unload_modules_conf || return 203
1640         return $rc
1641 }
1642 run_test 36 "df report consistency on OSTs with different block size"
1643
1644 test_37() {
1645         local mntpt=$(facet_mntpt mds)
1646         local mdsdev=$MDSDEV
1647         local mdsdev_sym="$TMP/sym_mdt.img"
1648
1649         echo "MDS :     $mdsdev"
1650         echo "SYMLINK : $mdsdev_sym"
1651         do_facet mds rm -f $mdsdev_sym
1652
1653         do_facet mds ln -s $mdsdev $mdsdev_sym
1654
1655         echo "mount symlink device - $mdsdev_sym"
1656
1657         local rc=0
1658         mount_op=$(do_facet mds mount -v -t lustre $MDS_MOUNT_OPTS  $mdsdev_sym $mntpt 2>&1 )
1659         rc=${PIPESTATUS[0]}
1660
1661         echo mount_op=$mount_op
1662
1663         do_facet mds "umount -d $mntpt && rm -f $mdsdev_sym"
1664
1665         if $(echo $mount_op | grep -q "unable to set tunable"); then
1666                 error "set tunables failed for symlink device"
1667         fi
1668
1669         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
1670
1671         return 0
1672 }
1673 run_test 37 "verify set tunables works for symlink device"
1674
1675 test_38() { # bug 14222
1676         setup
1677         # like runtests
1678         COUNT=10
1679         SRC="/etc /bin"
1680         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
1681         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
1682         mkdir -p $DIR/$tdir
1683         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
1684                 error "copying $SRC to $DIR/$tdir"
1685         sync
1686         umount_client $MOUNT
1687         stop_mds
1688         log "rename lov_objid file on MDS"
1689         rm -f $TMP/lov_objid.orig
1690         do_facet mds "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
1691         do_facet mds "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1692
1693         do_facet mds "od -Ax -td8 $TMP/lov_objid.orig"
1694         # check create in mds_lov_connect
1695         start_mds
1696         mount_client $MOUNT
1697         for f in $FILES; do
1698                 [ $V ] && log "verifying $DIR/$tdir/$f"
1699                 diff -q $f $DIR/$tdir/$f || ERROR=y
1700         done
1701         do_facet mds "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
1702         do_facet mds "od -Ax -td8 $TMP/lov_objid.new"
1703         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
1704
1705
1706         # check it's updates in sync
1707         umount_client $MOUNT
1708         stop_mds
1709
1710         do_facet mds dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
1711         do_facet mds "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1712         do_facet mds "$DEBUGFS -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
1713
1714         start_mds
1715         mount_client $MOUNT
1716         for f in $FILES; do
1717                 [ $V ] && log "verifying $DIR/$tdir/$f"
1718                 diff -q $f $DIR/$tdir/$f || ERROR=y
1719         done
1720         do_facet mds "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
1721         do_facet mds "od -Ax -td8 $TMP/lov_objid.new1"
1722         umount_client $MOUNT
1723         stop_mds
1724         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
1725
1726         log "files compared the same"
1727         cleanup
1728 }
1729 run_test 38 "MDS recreates missing lov_objid file from OST data"
1730
1731 test_39() { #bug 14413
1732         PTLDEBUG=+malloc
1733         setup
1734         cleanup
1735         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
1736                 error "memory leak detected" || true
1737 }
1738 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
1739
1740 test_40() { # bug 15759
1741         start_ost
1742         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
1743         do_facet mds "lctl set_param fail_loc=0x80000706"
1744         start_mds
1745         cleanup
1746 }
1747 run_test 40 "race during service thread startup"
1748
1749 test_41() { #bug 14134
1750         local rc
1751         start mds $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
1752         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
1753         start mds $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
1754         mkdir -p $MOUNT
1755         mount_client $MOUNT || return 1
1756         sleep 5
1757
1758         echo "blah blah" > $MOUNT/$tfile
1759         cat $MOUNT/$tfile
1760
1761         umount_client $MOUNT
1762         stop ost1 -f || return 201
1763         stop mds -f || return 202
1764         stop mds -f || return 203
1765         unload_modules_conf || return 204
1766         return $rc
1767 }
1768 run_test 41 "mount mds with --nosvc and --nomgs"
1769
1770 test_42() { #bug 14693
1771         setup
1772         check_mount || return 2
1773         do_facet client lctl conf_param lustre.llite.some_wrong_param=10
1774         umount_client $MOUNT
1775         mount_client $MOUNT || return 1
1776         cleanup
1777         return 0
1778 }
1779 run_test 42 "invalid config param should not prevent client from mounting"
1780
1781 test_43() { #bug 15993
1782         setup
1783         VERSION_1_8=$(do_facet mds $LCTL get_param version | grep ^lustre.*1\.[78])
1784         if [ -z "$VERSION_1_8" ]; then
1785                 skip "skipping test for non 1.8 MDS"
1786                 cleanup
1787                 return 0
1788         fi
1789
1790         check_mount || return 2
1791         testfile=$DIR/$tfile
1792         lma="this-should-be-removed-after-remount-and-accessed"
1793         touch $testfile
1794         echo "set/get trusted.lma"
1795 #define OBD_FAIL_MDS_ALLOW_COMMON_EA_SETTING    0x13f
1796         do_facet mds "lctl set_param fail_loc=0x13f"
1797         lctl set_param fail_loc=0x13f
1798         setfattr -n trusted.lma -v $lma $testfile || error "create common EA"
1799         do_facet mds "lctl set_param fail_loc=0"
1800         lctl set_param fail_loc=0
1801         ATTR=$(getfattr -n trusted.lma $testfile 2> /dev/null | grep trusted.lma)
1802         [ "$ATTR" = "trusted.lma=\"$lma\"" ] || error "check common EA"
1803         umount_client $MOUNT
1804         stop_mds
1805         sleep 5
1806         start_mds
1807         mount_client $MOUNT
1808         check_mount || return 3
1809 #define OBD_FAIL_MDS_REMOVE_COMMON_EA    0x13e
1810         do_facet mds "lctl set_param fail_loc=0x13e"
1811         stat $testfile
1812         do_facet mds "lctl set_param fail_loc=0"
1813         getfattr -d -m trusted $testfile 2> /dev/null | \
1814             grep "trusted.lma" && error "common EA not removed" || true
1815         cleanup
1816         return 0
1817 }
1818 run_test 43 "remove common EA if it exists"
1819
1820 test_44() { # 16317
1821         setup
1822         check_mount || return 2
1823         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
1824         STATS_FOUND=no
1825         UUIDS=$(do_facet mds "$LCTL get_param $(get_mds_mdt_device_proc_path).${FSNAME}*.exports.*.uuid")
1826         for VAL in $UUIDS; do
1827                 NID=$(echo $VAL | cut -d= -f1)
1828                 CLUUID=$(echo $VAL | cut -d= -f2)
1829                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
1830         done
1831         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
1832         cleanup
1833         return 0
1834 }
1835 run_test 44 "mounted client proc entry exists"
1836
1837 test_45() { #17310
1838         setup
1839         check_mount || return 2
1840         stop_mds
1841         df -h $MOUNT &
1842         log "sleep 60 sec"
1843         sleep 60
1844 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
1845         do_facet client "lctl set_param fail_loc=0x50f"
1846         log "sleep 10 sec"
1847         sleep 10
1848         manual_umount_client --force || return 3
1849         do_facet client "lctl set_param fail_loc=0x0"
1850         start_mds
1851         mount_client $MOUNT || return 4
1852         cleanup
1853         return 0
1854 }
1855 run_test 45 "long unlink handling in ptlrpcd"
1856
1857 cleanup_46a() {
1858         trap 0
1859         local rc=0
1860         local count=$1
1861
1862         umount_client $MOUNT2 || rc=$?
1863         umount_client $MOUNT || rc=$?
1864         while [ $count -gt 0 ]; do
1865                 stop ost${count} -f || rc=$?
1866                 let count=count-1
1867         done    
1868         stop_mds || rc=$? 
1869         cleanup_nocli || rc=$?
1870         #writeconf to remove all ost2 traces for subsequent tests
1871         writeconf
1872         return $rc
1873 }
1874
1875 test_46a() {
1876         echo "Testing with $OSTCOUNT OSTs"
1877         reformat_and_config
1878         start_mds || return 1
1879         #first client should see only one ost
1880         start_ost || return 2
1881         wait_osc_import_state mds ost FULL
1882         #start_client
1883         mount_client $MOUNT || return 3
1884         trap "cleanup_46a $OSTCOUNT" EXIT ERR
1885
1886         local i 
1887         for (( i=2; i<=$OSTCOUNT; i++ )); do
1888             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
1889         done
1890
1891         # wait until osts in sync
1892         for (( i=2; i<=$OSTCOUNT; i++ )); do
1893             wait_osc_import_state mds ost$i FULL
1894         done
1895
1896         #second client see all ost's
1897
1898         mount_client $MOUNT2 || return 8
1899         $LFS setstripe $MOUNT2 -c -1 || return 9
1900         $LFS getstripe $MOUNT2 || return 10
1901
1902         echo "ok" > $MOUNT2/widestripe
1903         $LFS getstripe $MOUNT2/widestripe || return 11
1904         # fill acl buffer for avoid expand lsm to them
1905         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
1906             setfacl -m $acl $MOUNT2/widestripe
1907         done
1908
1909         # will be deadlock
1910         stat $MOUNT/widestripe || return 12
1911
1912         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
1913         return 0
1914 }
1915 run_test 46a "handle ost additional - wide striped file"
1916
1917 test_47() { #17674
1918         reformat
1919         setup_noconfig
1920         check_mount || return 2
1921         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
1922
1923         local lru_size=[]
1924         local count=0
1925         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
1926             lrs=$(echo $ns | sed 's/.*lru_size=//')
1927             lru_size[count]=$lrs
1928             let count=count+1
1929         done
1930
1931         facet_failover ost1
1932         facet_failover mds
1933         client_up || return 3
1934
1935         count=0
1936         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
1937             lrs=$(echo $ns | sed 's/.*lru_size=//')
1938             if ! test "$lrs" -eq "${lru_size[count]}"; then
1939                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
1940                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
1941             fi
1942             let count=count+1
1943         done
1944
1945         cleanup
1946         return 0
1947 }
1948 run_test 47 "server restart does not make client loss lru_resize settings"
1949
1950 cleanup_48() {
1951         trap 0
1952
1953         # reformat after this test is needed - if test will failed
1954         # we will have unkillable file at FS
1955         reformat_and_config
1956 }
1957
1958 test_48() { # bug 17636
1959         reformat
1960         setup_noconfig
1961         check_mount || return 2
1962
1963         $LFS setstripe $MOUNT -c -1 || return 9
1964         $LFS getstripe $MOUNT || return 10
1965
1966         echo "ok" > $MOUNT/widestripe
1967         $LFS getstripe $MOUNT/widestripe || return 11
1968
1969         trap cleanup_48 EXIT ERR
1970
1971         # fill acl buffer for avoid expand lsm to them
1972         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
1973             setfacl -m $acl $MOUNT/widestripe
1974         done
1975
1976         stat $MOUNT/widestripe || return 12
1977
1978         cleanup_48
1979         return 0
1980 }
1981 run_test 48 "too many acls on file"
1982
1983 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
1984 test_49() { # bug 17710
1985         local OLD_MDS_MKFS_OPTS=$MDS_MKFS_OPTS
1986         local OLD_OST_MKFS_OPTS=$OST_MKFS_OPTS
1987         local LOCAL_TIMEOUT=20
1988
1989         OST_MKFS_OPTS="--ost --fsname=$FSNAME --device-size=$OSTSIZE --mgsnode=$MGSNID --param sys.timeout=$LOCAL_TIMEOUT --param sys.ldlm_timeout=$LOCAL_TIMEOUT $MKFSOPT $OSTOPT"
1990
1991         reformat
1992         setup_noconfig
1993         check_mount || return 1
1994
1995         echo "check ldlm_timout..."
1996         LDLM_MDS="`do_facet mds lctl get_param -n ldlm_timeout`"
1997         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
1998         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
1999
2000         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2001                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2002         fi
2003
2004         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
2005                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2006         fi
2007
2008         umount_client $MOUNT
2009         stop_ost || return 2
2010         stop_mds || return 3
2011
2012         OST_MKFS_OPTS="--ost --fsname=$FSNAME --device-size=$OSTSIZE --mgsnode=$MGSNID --param sys.timeout=$LOCAL_TIMEOUT --param sys.ldlm_timeout=$((LOCAL_TIMEOUT - 1)) $MKFSOPT $OSTOPT"
2013
2014         reformat
2015         setup_noconfig
2016         check_mount || return 7
2017
2018         LDLM_MDS="`do_facet mds lctl get_param -n ldlm_timeout`"
2019         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2020         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2021
2022         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2023                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2024         fi
2025
2026         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
2027                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2028         fi
2029
2030         cleanup || return $?
2031
2032         MDS_MKFS_OPTS=$OLD_MDS_MKFS_OPTS
2033         OST_MKFS_OPTS=$OLD_OST_MKFS_OPTS
2034 }
2035 run_test 49 "check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE"
2036
2037 lazystatfs() {
2038         # Test both statfs and lfs df and fail if either one fails
2039         multiop_bg_pause $1 f_
2040         RC1=$?
2041         PID=$!
2042         killall -USR1 multiop
2043         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
2044         wait $PID || { RC1=$?; log "multiop return error "; }
2045
2046         $LFS df &
2047         PID=$!
2048         sleep 5
2049         kill -s 0 $PID
2050         RC2=$?
2051         if [ $RC2 -eq 0 ]; then
2052             kill -s 9 $PID
2053             log "lazystatfs df failed"
2054         fi
2055
2056         RC=0
2057         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
2058         return $RC
2059 }
2060
2061 test_50a() {
2062         setup
2063         lctl set_param llite.$FSNAME-*.lazystatfs=1
2064         touch $DIR/$tfile
2065
2066         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
2067
2068         cleanup || return $?
2069 }
2070 run_test 50a "lazystatfs all servers available =========================="
2071
2072 test_50b() {
2073         setup
2074         lctl set_param llite.$FSNAME-*.lazystatfs=1
2075         touch $DIR/$tfile
2076
2077         # Wait for client to detect down OST
2078         stop_ost || error "Unable to stop OST1"
2079         wait_osc_import_state mds ost DISCONN
2080
2081         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
2082
2083         umount_client $MOUNT || error "Unable to unmount client"
2084         stop_mds || error "Unable to stop MDS"
2085 }
2086 run_test 50b "lazystatfs all servers down =========================="
2087
2088 test_50c() {
2089         start_mds || error "Unable to start MDS"
2090         start_ost || error "Unable to start OST1"
2091         start_ost2 || error "Unable to start OST2"
2092         mount_client $MOUNT || error "Unable to mount client"
2093         lctl set_param llite.$FSNAME-*.lazystatfs=1
2094         touch $DIR/$tfile
2095
2096         # Wait for client to detect down OST
2097         stop_ost || error "Unable to stop OST1"
2098         wait_osc_import_state mds ost DISCONN
2099         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2100
2101         umount_client $MOUNT || error "Unable to unmount client"
2102         stop_ost2 || error "Unable to stop OST2"
2103         stop_mds || error "Unable to stop MDS"
2104 }
2105 run_test 50c "lazystatfs one server down =========================="
2106
2107 test_50d() {
2108         start_mds || error "Unable to start MDS"
2109         start_ost || error "Unable to start OST1"
2110         start_ost2 || error "Unable to start OST2"
2111         mount_client $MOUNT || error "Unable to mount client"
2112         lctl set_param llite.$FSNAME-*.lazystatfs=1
2113         touch $DIR/$tfile
2114
2115         # Issue the statfs during the window where the client still
2116         # belives the OST to be available but it is in fact down.
2117         # No failure just a statfs which hangs for a timeout interval.
2118         stop_ost || error "Unable to stop OST1"
2119         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2120
2121         umount_client $MOUNT || error "Unable to unmount client"
2122         stop_ost2 || error "Unable to stop OST2"
2123         stop_mds || error "Unable to stop MDS"
2124 }
2125 run_test 50d "lazystatfs client/server conn race =========================="
2126
2127 test_50e() {
2128         local RC1
2129         local pid
2130
2131         reformat_and_config
2132         start_mds || return 1
2133         #first client should see only one ost
2134         start_ost || return 2
2135         wait_osc_import_state mds ost FULL
2136
2137         # Wait for client to detect down OST
2138         stop_ost || error "Unable to stop OST1"
2139         wait_osc_import_state mds ost DISCONN
2140
2141         mount_client $MOUNT || error "Unable to mount client"
2142         lctl set_param llite.$FSNAME-*.lazystatfs=0
2143
2144         multiop_bg_pause $MOUNT _f
2145         RC1=$?
2146         pid=$!
2147
2148         if [ $RC1 -ne 0 ]; then
2149                 log "lazystatfs multiop failed $RC1"
2150         else
2151             kill -USR1 $pid
2152             sleep $(( $TIMEOUT+1 ))
2153             kill -0 $pid
2154             [ $? -ne 0 ] && error "process isn't sleep"
2155             start_ost || error "Unable to start OST1"
2156             wait $pid || error "statfs failed"
2157         fi
2158
2159         umount_client $MOUNT || error "Unable to unmount client"
2160         stop_ost || error "Unable to stop OST1"
2161         stop_mds || error "Unable to stop MDS"
2162 }
2163 run_test 50e "normal statfs all servers down =========================="
2164
2165 test_50f() {
2166         local RC1
2167         local pid
2168         CONN_PROC="osc.$FSNAME-OST0001-osc.ost_server_uuid"
2169
2170         start_mds || error "Unable to start mds"
2171         #first client should see only one ost
2172         start_ost || error "Unable to start OST1"
2173         wait_osc_import_state mds ost FULL
2174
2175         start_ost2 || error "Unable to start OST2"
2176         wait_osc_import_state mds ost2 FULL
2177
2178         # Wait for client to detect down OST
2179         stop_ost2 || error "Unable to stop OST2"
2180         wait_osc_import_state mds ost2 DISCONN
2181
2182         mount_client $MOUNT || error "Unable to mount client"
2183         lctl set_param llite.$FSNAME-*.lazystatfs=0
2184
2185         multiop_bg_pause $MOUNT _f
2186         RC1=$?
2187         pid=$!
2188
2189         if [ $RC1 -ne 0 ]; then
2190                 log "lazystatfs multiop failed $RC1"
2191         else
2192             kill -USR1 $pid
2193             sleep $(( $TIMEOUT+1 ))
2194             kill -0 $pid
2195             [ $? -ne 0 ] && error "process isn't sleep"
2196             start_ost2 || error "Unable to start OST2"
2197             wait $pid || error "statfs failed"
2198             stop_ost2 || error "Unable to stop OST2"
2199         fi
2200
2201         umount_client $MOUNT || error "Unable to unmount client"
2202         stop_ost || error "Unable to stop OST1"
2203         stop_mds || error "Unable to stop MDS"
2204         #writeconf to remove all ost2 traces for subsequent tests
2205         writeconf
2206 }
2207 run_test 50f "normal statfs one server in down =========================="
2208
2209 test_50g() {
2210         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2211         setup
2212         start_ost2 || error "Unable to start OST2"
2213         wait_osc_import_state mds ost2 FULL
2214         wait_osc_import_state client ost2 FULL
2215
2216         local PARAM="${FSNAME}-OST0001.osc.active"
2217
2218         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
2219         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
2220
2221         umount_client $MOUNT || error "Unable to unmount client"
2222         mount_client $MOUNT || error "Unable to mount client"
2223         # This df should not cause a panic
2224         df -k $MOUNT
2225
2226         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
2227         rm -f $DIR/$tfile
2228         umount_client $MOUNT || error "Unable to unmount client"
2229         stop_ost2 || error "Unable to stop OST2"
2230         stop_ost || error "Unable to stop OST1"
2231         stop_mds || error "Unable to stop MDS"
2232         #writeconf to remove all ost2 traces for subsequent tests
2233         writeconf
2234 }
2235 run_test 50g "deactivated OST should not cause panic====================="
2236
2237 lov_objid_size()
2238 {
2239         local max_ost_index=$1
2240         echo -n $(($max_ost_index * 8 + 8))
2241 }
2242
2243 test_55() {
2244         local saved_opts=$OST_MKFS_OPTS
2245
2246         for i in 0 1023 2048
2247         do
2248                 OST_MKFS_OPTS="$saved_opts --index $i"
2249                 reformat
2250
2251                 setup_noconfig
2252                 cp /etc/passwd $DIR/1
2253                 stopall
2254
2255                 setup
2256                 cp /etc/passwd $DIR/2
2257                 sync
2258
2259                 echo checking size of lov_objid for ost index $i
2260                 local file_size=`do_facet mds \
2261                     "$DEBUGFS -R 'stat lov_objid' $MDSDEV 2>/dev/null" | \
2262                     grep ^User | awk '{print $6}'`
2263                 if [ "$file_size" != $(lov_objid_size $i) ]; then
2264                         error "lov_objid size has to be $(lov_objid_size $i), \
2265 not $file_size"
2266                 else
2267                         echo ok, lov_objid size is correct: $file_size
2268                 fi
2269                 stopall
2270         done
2271
2272         OST_MKFS_OPTS=$saved_opts
2273         reformat
2274 }
2275 run_test 55 "check lov_objid size"
2276
2277 test_56() {
2278         add mds $MDS_MKFS_OPTS --mkfsoptions='\"-J size=16\"' --reformat $MDSDEV
2279         add ost1 $OST_MKFS_OPTS --index=1000 --reformat `ostdevname 1`
2280         add ost2 $OST_MKFS_OPTS --index=10000 --reformat `ostdevname 2`
2281
2282         start_mds
2283         start_ost
2284         start_ost2 || error "Unable to start second ost"
2285         mount_client $MOUNT || error "Unable to mount client"
2286         [ -n "$ENABLE_QUOTA" ] && { $LFS quotacheck -ug $MOUNT || error "quotacheck has failed" ; }
2287
2288         stopall
2289         reformat
2290 }
2291 run_test 56 "check big indexes"
2292
2293 test_57() { # bug 22656
2294         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
2295         writeconf
2296         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" || error "tunefs failed"
2297         start_mgsmds
2298         stop_mds
2299         start_ost && error "OST registration from failnode should fail"
2300         reformat
2301 }
2302 run_test 57 "initial registration from failnode should fail (should return errs)"
2303
2304 test_58() { # bug 22658
2305         [ "$FSTYPE" != "ldiskfs" ] && skip "not supported for $FSTYPE" && return
2306         setup
2307         mkdir -p $DIR/$tdir
2308         createmany -o $DIR/$tdir/$tfile-%d 100
2309         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
2310 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
2311         do_facet mds "lctl set_param fail_loc=0x601"
2312         unlinkmany $DIR/$tdir/$tfile-%d 100
2313         stop mds
2314         local MNTDIR=$(facet_mntpt mds)
2315         # remove all files from the OBJECTS dir
2316         do_facet mds "mount -t ldiskfs $MDSDEV $MNTDIR"
2317         do_facet mds "find $MNTDIR/OBJECTS -type f -delete"
2318         do_facet mds "umount $MNTDIR"
2319         # restart MDS with missing llog files
2320         start_mds
2321         do_facet mds "lctl set_param fail_loc=0"
2322         reformat
2323 }
2324 run_test 58 "missing llog files must not prevent MDT from mounting"
2325
2326 count_osts() {
2327         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
2328 }
2329
2330 test_59() {
2331         start_mgsmds >> /dev/null
2332         local C1=$(count_osts)
2333         if [ $C1 -eq 0 ]; then
2334                 start_ost >> /dev/null
2335                 C1=$(count_osts)
2336         fi
2337         stopall
2338         echo "original ost count: $C1 (expect > 0)"
2339         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
2340         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
2341         local C2=$(count_osts)
2342         echo "after mdt writeconf count: $C2 (expect 0)"
2343         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
2344         echo "OST start without writeconf should fail:"
2345         start_ost >> /dev/null && error "OST start without writeconf didn't fail"
2346         echo "OST start with writeconf should succeed:"
2347         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
2348         local C3=$(count_osts)
2349         echo "after ost writeconf count: $C3 (expect 1)"
2350         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
2351         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
2352         local C4=$(count_osts)
2353         echo "after ost2 writeconf count: $C4 (expect 2)"
2354         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
2355         stop_ost2 >> /dev/null
2356         cleanup_nocli >> /dev/null
2357 }
2358 run_test 59 "writeconf mount option"
2359
2360 if ! combined_mgs_mds ; then
2361         stop mgs
2362 fi
2363
2364 equals_msg `basename $0`: test complete
2365 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG && grep -q FAIL $TESTSUITELOG && exit 1 || true
2366
2367