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