Whamcloud - gitweb
Branch HEAD
[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: 13739 19280
15 HEAD_EXCEPT="                  32a    50e 50f"
16
17 # bug number for skipped test:
18 ALWAYS_EXCEPT=" $CONF_SANITY_EXCEPT $HEAD_EXCEPT"
19 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20
21 SRCDIR=`dirname $0`
22 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
23
24 PTLDEBUG=${PTLDEBUG:--1}
25 SAVE_PWD=$PWD
26 LUSTRE=${LUSTRE:-`dirname $0`/..}
27 RLUSTRE=${RLUSTRE:-$LUSTRE}
28
29 . $LUSTRE/tests/test-framework.sh
30 init_test_env $@
31 # STORED_MDSSIZE is used in test_18
32 if [ -n "$MDSSIZE" ]; then
33     STORED_MDSSIZE=$MDSSIZE
34 fi
35 # use small MDS + OST size to speed formatting time
36 MDSSIZE=40000
37 OSTSIZE=40000
38 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
39
40 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
41 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
42
43 #
44 [ "$SLOW" = "no" ] && EXCEPT_SLOW="0 1 2 3 6 7 15 18 24b 25 30 31 32 33 34a 45"
45
46 assert_DIR
47
48 reformat() {
49         formatall
50 }
51
52 writeconf() {
53         local facet=$SINGLEMDS
54         local dev=${facet}_dev
55         shift
56         stop ${facet} -f
57         rm -f ${facet}active
58         # who knows if/where $TUNEFS is installed?  Better reformat if it fails...
59         do_facet ${facet} "$TUNEFS --writeconf ${!dev}" || echo "tunefs failed, reformatting instead" && reformat
60
61         gen_config
62 }
63
64 gen_config() {
65         # The MGS must be started before the OSTs for a new fs, so start
66         # and stop to generate the startup logs.
67         start_mds
68         start_ost
69         wait_osc_import_state mds ost FULL
70         stop_ost
71         stop_mds
72 }
73
74 reformat_and_config() {
75         reformat
76         gen_config
77 }
78
79 start_mds() {
80         local facet=$SINGLEMDS
81         # we can not use MDSDEV1 here because SINGLEMDS could be set not to mds1 only
82         local num=$(echo $facet | tr -d "mds")
83         local dev=$(mdsdevname $num)
84         echo "start mds service on `facet_active_host $facet`"
85         start $facet ${dev} $MDS_MOUNT_OPTS || return 94
86 }
87
88 stop_mds() {
89         echo "stop mds service on `facet_active_host $SINGLEMDS`"
90         # These tests all use non-failover stop
91         stop $SINGLEMDS -f  || return 97
92 }
93
94 start_ost() {
95         echo "start ost1 service on `facet_active_host ost1`"
96         start ost1 `ostdevname 1` $OST_MOUNT_OPTS || return 95
97 }
98
99 stop_ost() {
100         echo "stop ost1 service on `facet_active_host ost1`"
101         # These tests all use non-failover stop
102         stop ost1 -f  || return 98
103 }
104
105 start_ost2() {
106         echo "start ost2 service on `facet_active_host ost2`"
107         start ost2 `ostdevname 2` $OST_MOUNT_OPTS || return 92
108 }
109
110 stop_ost2() {
111         echo "stop ost2 service on `facet_active_host ost2`"
112         # These tests all use non-failover stop
113         stop ost2 -f  || return 93
114 }
115
116 mount_client() {
117         local MOUNTPATH=$1
118         echo "mount $FSNAME on ${MOUNTPATH}....."
119         zconf_mount `hostname` $MOUNTPATH  || return 96
120 }
121
122 remount_client() {
123         local SAVEMOUNTOPT=$MOUNTOPT
124         MOUNTOPT="remount,$1"
125         local MOUNTPATH=$2
126         echo "remount '$1' lustre on ${MOUNTPATH}....."
127         zconf_mount `hostname`  $MOUNTPATH  || return 96
128         MOUNTOPT=$SAVEMOUNTOPT
129 }
130
131 umount_client() {
132         local MOUNTPATH=$1
133         echo "umount lustre on ${MOUNTPATH}....."
134         zconf_umount `hostname` $MOUNTPATH || return 97
135 }
136
137 manual_umount_client(){
138         local rc
139         local FORCE=$1
140         echo "manual umount lustre on ${MOUNT}...."
141         do_facet client "umount -d ${FORCE} $MOUNT"
142         rc=$?
143         return $rc
144 }
145
146 setup() {
147         start_ost
148         start_mds
149         mount_client $MOUNT
150 }
151
152 setup_noconfig() {
153         start_mds
154         start_ost
155         mount_client $MOUNT
156 }
157
158 cleanup_nocli() {
159         stop_mds || return 201
160         stop_ost || return 202
161         unload_modules || return 203
162 }
163
164 cleanup() {
165         umount_client $MOUNT || return 200
166         cleanup_nocli || return $?
167 }
168
169 check_mount() {
170         do_facet client "cp /etc/passwd $DIR/a" || return 71
171         do_facet client "rm $DIR/a" || return 72
172         # make sure lustre is actually mounted (touch will block,
173         # but grep won't, so do it after)
174         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
175         echo "setup single mount lustre success"
176 }
177
178 check_mount2() {
179         do_facet client "touch $DIR/a" || return 71
180         do_facet client "rm $DIR/a" || return 72
181         do_facet client "touch $DIR2/a" || return 73
182         do_facet client "rm $DIR2/a" || return 74
183         echo "setup double mount lustre success"
184 }
185
186 build_test_filter
187
188 if [ "$ONLY" == "setup" ]; then
189         setup
190         exit
191 fi
192
193 if [ "$ONLY" == "cleanup" ]; then
194         cleanup
195         exit
196 fi
197
198 init_gss
199
200 #create single point mountpoint
201
202 reformat_and_config
203
204 test_0() {
205         setup
206         check_mount || return 41
207         cleanup || return $?
208 }
209 run_test 0 "single mount setup"
210
211 test_1() {
212         start_ost
213         echo "start ost second time..."
214         setup
215         check_mount || return 42
216         cleanup || return $?
217 }
218 run_test 1 "start up ost twice (should return errors)"
219
220 test_2() {
221         start_ost
222         start_mds
223         echo "start mds second time.."
224         start_mds
225         mount_client $MOUNT
226         check_mount || return 43
227         cleanup || return $?
228 }
229 run_test 2 "start up mds twice (should return err)"
230
231 test_3() {
232         setup
233         #mount.lustre returns an error if already in mtab
234         mount_client $MOUNT && return $?
235         check_mount || return 44
236         cleanup || return $?
237 }
238 run_test 3 "mount client twice (should return err)"
239
240 test_4() {
241         setup
242         touch $DIR/$tfile || return 85
243         stop_ost -f
244         cleanup
245         eno=$?
246         # ok for ost to fail shutdown
247         if [ 202 -ne $eno ]; then
248                 return $eno;
249         fi
250         return 0
251 }
252 run_test 4 "force cleanup ost, then cleanup"
253
254 test_5a() {     # was test_5
255         setup
256         touch $DIR/$tfile || return 1
257         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
258
259         stop_mds -f || return 2
260
261         # cleanup may return an error from the failed
262         # disconnects; for now I'll consider this successful
263         # if all the modules have unloaded.
264         umount -d $MOUNT &
265         UMOUNT_PID=$!
266         sleep 6
267         echo "killing umount"
268         kill -TERM $UMOUNT_PID
269         echo "waiting for umount to finish"
270         wait $UMOUNT_PID
271         if grep " $MOUNT " /proc/mounts; then
272                 echo "test 5: /proc/mounts after failed umount"
273                 umount $MOUNT &
274                 UMOUNT_PID=$!
275                 sleep 2
276                 echo "killing umount"
277                 kill -TERM $UMOUNT_PID
278                 echo "waiting for umount to finish"
279                 wait $UMOUNT_PID
280                 grep " $MOUNT " /proc/mounts && echo "test 5: /proc/mounts after second umount" && return 11
281         fi
282
283         manual_umount_client
284         # stop_mds is a no-op here, and should not fail
285         cleanup_nocli || return $?
286         # df may have lingering entry
287         manual_umount_client
288         # mtab may have lingering entry
289         local WAIT=0
290         local MAX_WAIT=20
291         local sleep=1
292         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
293                 sleep $sleep
294                 grep -q $MOUNT" " /etc/mtab || break
295                 echo "Waiting /etc/mtab updated ... "
296                 WAIT=$(( WAIT + sleep))
297         done
298         [ "$WAIT" -eq "$MAX_WAIT" ] && error "/etc/mtab is not updated in $WAIT secs"
299         echo "/etc/mtab updated in $WAIT secs"
300 }
301 run_test 5a "force cleanup mds, then cleanup"
302
303 test_5b() {
304         start_ost
305         [ -d $MOUNT ] || mkdir -p $MOUNT
306         grep " $MOUNT " /etc/mtab && echo "test 5b: mtab before mount" && return 10
307         mount_client $MOUNT && return 1
308         grep " $MOUNT " /etc/mtab && echo "test 5b: mtab after failed mount" && return 11
309         umount_client $MOUNT
310         # stop_mds is a no-op here, and should not fail
311         cleanup_nocli || return $?
312         return 0
313 }
314 run_test 5b "mds down, cleanup after failed mount (bug 2712) (should return errs)"
315
316 test_5c() {
317         start_ost
318         start_mds
319         [ -d $MOUNT ] || mkdir -p $MOUNT
320         grep " $MOUNT " /etc/mtab && echo "test 5c: mtab before mount" && return 10
321         local oldfs="${FSNAME}"
322         FSNAME="wrong.${FSNAME}"
323         mount_client $MOUNT || :
324         FSNAME=${oldfs}
325         grep " $MOUNT " /etc/mtab && echo "test 5c: mtab after failed mount" && return 11
326         umount_client $MOUNT
327         cleanup_nocli  || return $?
328 }
329 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
330
331 test_5d() {
332         start_ost
333         start_mds
334         stop_ost -f
335         grep " $MOUNT " /etc/mtab && echo "test 5d: mtab before mount" && return 10
336         mount_client $MOUNT || return 1
337         cleanup  || return $?
338         grep " $MOUNT " /etc/mtab && echo "test 5d: mtab after unmount" && return 11
339         return 0
340 }
341 run_test 5d "mount with ost down"
342
343 test_5e() {
344         start_ost
345         start_mds
346
347 #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
348         do_facet client "lctl set_param fail_loc=0x80000506"
349         grep " $MOUNT " /etc/mtab && echo "test 5e: mtab before mount" && return 10
350         mount_client $MOUNT || echo "mount failed (not fatal)"
351         cleanup  || return $?
352         grep " $MOUNT " /etc/mtab && echo "test 5e: mtab after unmount" && return 11
353         return 0
354 }
355 run_test 5e "delayed connect, don't crash (bug 10268)"
356
357 test_6() {
358         setup
359         manual_umount_client
360         mount_client ${MOUNT} || return 87
361         touch $DIR/a || return 86
362         cleanup  || return $?
363 }
364 run_test 6 "manual umount, then mount again"
365
366 test_7() {
367         setup
368         manual_umount_client
369         cleanup_nocli || return $?
370 }
371 run_test 7 "manual umount, then cleanup"
372
373 test_8() {
374         setup
375         mount_client $MOUNT2
376         check_mount2 || return 45
377         umount_client $MOUNT2
378         cleanup  || return $?
379 }
380 run_test 8 "double mount setup"
381
382 test_9() {
383         start_ost
384
385         do_facet ost1 lctl set_param debug=\'inode trace\' || return 1
386         do_facet ost1 lctl set_param subsystem_debug=\'mds ost\' || return 1
387
388         CHECK_PTLDEBUG="`do_facet ost1 lctl get_param -n debug`"
389         if [ "$CHECK_PTLDEBUG" ] && { \
390            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
391            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
392            echo "lnet.debug success"
393         else
394            echo "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
395            return 1
396         fi
397         CHECK_SUBSYS="`do_facet ost1 lctl get_param -n subsystem_debug`"
398         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
399            echo "lnet.subsystem_debug success"
400         else
401            echo "lnet.subsystem_debug: want 'mds ost', have '$CHECK_SUBSYS'"
402            return 1
403         fi
404         stop_ost || return $?
405 }
406
407 run_test 9 "test ptldebug and subsystem for mkfs"
408
409 # LOGS/PENDING do not exist anymore since CMD3
410 test_16() {
411         local TMPMTPT="${TMP}/conf16"
412         local dev=${SINGLEMDS}_dev
413         local MDSDEV=${!dev}
414         if [ ! -e "$MDSDEV" ]; then
415             log "no $MDSDEV existing, so mount Lustre to create one"
416             setup
417             check_mount || return 41
418             cleanup || return $?
419         fi
420
421         [ -f "$MDSDEV" ] && LOOPOPT="-o loop"
422
423         log "change the mode of $MDSDEV/OBJECTS to 555"
424         do_facet $SINGLEMDS "mkdir -p $TMPMTPT &&
425                       mount $LOOPOPT -t $FSTYPE $MDSDEV $TMPMTPT &&
426                       chmod 555 $TMPMTPT/OBJECTS &&
427                       umount $TMPMTPT" || return $?
428
429         log "mount Lustre to change the mode of OBJECTS, then umount Lustre"
430         setup
431         check_mount || return 41
432         cleanup || return $?
433
434         log "read the mode of OBJECTS and check if they has been changed properly"
435         EXPECTEDOBJECTSMODE=`do_facet $SINGLEMDS "$DEBUGFS -R 'stat OBJECTS' $MDSDEV 2> /dev/null" | grep 'Mode: ' | sed -e "s/.*Mode: *//" -e "s/ *Flags:.*//"`
436
437         if [ "$EXPECTEDOBJECTSMODE" = "0777" ]; then
438                 log "Success:Lustre change the mode of OBJECTS correctly"
439         else
440                 error "Lustre does not change mode of OBJECTS properly"
441         fi
442 }
443 run_test 16 "verify that lustre will correct the mode of OBJECTS"
444
445 test_17() {
446         local dev=${SINGLEMDS}_dev
447         local MDSDEV=${!dev}
448
449         if [ ! -e "$MDSDEV" ]; then
450             echo "no $MDSDEV existing, so mount Lustre to create one"
451             setup
452             check_mount || return 41
453             cleanup || return $?
454         fi
455
456         echo "Remove mds config log"
457         do_facet $SINGLEMDS "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' $MDSDEV || return \$?" || return $?
458
459         start_ost
460         start_mds && return 42
461         reformat_and_config
462 }
463 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
464
465 test_18() {
466         [ "$FSTYPE" != "ldiskfs" ] && skip "not needed for FSTYPE=$FSTYPE" && return
467
468         local dev=${SINGLEMDS}_dev
469         local MDSDEV=${!dev}
470
471         local MIN=2000000
472
473         local OK=
474         # check if current MDSSIZE is large enough
475         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE && \
476                 log "use MDSSIZE=$MDSSIZE"
477
478         # check if the global config has a large enough MDSSIZE
479         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] && [ $STORED_MDSSIZE -ge $MIN ] && \
480                 OK=1 && myMDSSIZE=$STORED_MDSSIZE && \
481                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
482
483         # check if the block device is large enough
484         [ -z "$OK" -a -b $MDSDEV ] && \
485                 [ "$(dd if=$MDSDEV of=/dev/null bs=1k count=1 skip=$MIN 2>&1 |
486                      awk '($3 == "in") { print $1 }')" = "1+0" ] && OK=1 && \
487                 myMDSSIZE=$MIN && log "use device $MDSDEV with MIN=$MIN"
488
489         # check if a loopback device has enough space for fs metadata (5%)
490         [ -z "$OK" ] && [ -f $MDSDEV -o ! -e $MDSDEV ] &&
491                 SPACE=$(df -P $(dirname $MDSDEV) |
492                         awk '($1 != "Filesystem") {print $4}') &&
493                 [ $SPACE -gt $((MIN / 20)) ] && OK=1 && myMDSSIZE=$MIN && \
494                         log "use file $MDSDEV with MIN=$MIN"
495
496         [ -z "$OK" ] && skip "$MDSDEV too small for ${MIN}kB MDS" && return
497
498
499         echo "mount mds with large journal..."
500         local OLD_MDS_MKFS_OPTS=$MDS_MKFS_OPTS
501
502         MDS_MKFS_OPTS="--mgs --mdt --fsname=$FSNAME --device-size=$myMDSSIZE --param sys.timeout=$TIMEOUT $MDSOPT"
503
504         reformat_and_config
505         echo "mount lustre system..."
506         setup
507         check_mount || return 41
508
509         echo "check journal size..."
510         local FOUNDSIZE=`do_facet mds "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}'`
511         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
512                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
513         else
514                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
515         fi
516
517         cleanup || return $?
518
519         MDS_MKFS_OPTS=$OLD_MDS_MKFS_OPTS
520         reformat_and_config
521 }
522 run_test 18 "check mkfs creates large journals"
523
524 test_19a() {
525         start_mds || return 1
526         stop_mds -f || return 2
527 }
528 run_test 19a "start/stop MDS without OSTs"
529
530 test_19b() {
531         start_ost || return 1
532         stop_ost -f || return 2
533 }
534 run_test 19b "start/stop OSTs without MDS"
535
536 test_20() {
537         # first format the ost/mdt
538         start_ost
539         start_mds
540         mount_client $MOUNT
541         check_mount || return 43
542         rm -f $DIR/$tfile
543         remount_client ro $MOUNT || return 44
544         touch $DIR/$tfile && echo "$DIR/$tfile created incorrectly" && return 45
545         [ -e $DIR/$tfile ] && echo "$DIR/$tfile exists incorrectly" && return 46
546         remount_client rw $MOUNT || return 47
547         touch $DIR/$tfile
548         [ ! -f $DIR/$tfile ] && echo "$DIR/$tfile missing" && return 48
549         MCNT=`grep -c $MOUNT /etc/mtab`
550         [ "$MCNT" -ne 1 ] && echo "$MOUNT in /etc/mtab $MCNT times" && return 49
551         umount_client $MOUNT
552         stop_mds
553         stop_ost
554 }
555 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
556
557 test_21a() {
558         start_mds
559         start_ost
560         wait_osc_import_state mds ost FULL
561         stop_ost
562         stop_mds
563 }
564 run_test 21a "start mds before ost, stop ost first"
565
566 test_21b() {
567         start_ost
568         start_mds
569         wait_osc_import_state mds ost FULL
570         stop_mds
571         stop_ost
572 }
573 run_test 21b "start ost before mds, stop mds first"
574
575 test_21c() {
576         start_ost
577         start_mds
578         start_ost2
579         wait_osc_import_state mds ost2 FULL
580         stop_ost
581         stop_ost2
582         stop_mds
583         #writeconf to remove all ost2 traces for subsequent tests
584         writeconf
585 }
586 run_test 21c "start mds between two osts, stop mds last"
587
588 test_22() {
589         start_mds
590
591         echo Client mount with ost in logs, but none running
592         start_ost
593         # wait until mds connected to ost and open client connection
594         wait_osc_import_state mds ost FULL
595         stop_ost
596         mount_client $MOUNT
597         # check_mount will block trying to contact ost
598         umount_client $MOUNT
599         pass
600
601         echo Client mount with a running ost
602         start_ost
603         if $GSS; then
604                 # if gss enabled, wait full time to let connection from
605                 # mds to ost be established, due to the mismatch between
606                 # initial connect timeout and gss context negotiation timeout.
607                 # This perhaps could be remove after AT landed.
608                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
609                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
610         fi
611         mount_client $MOUNT
612         check_mount || return 41
613         pass
614
615         cleanup
616 }
617 run_test 22 "start a client before osts (should return errs)"
618
619 test_23a() {    # was test_23
620         setup
621         # fail mds
622         stop $SINGLEMDS
623         # force down client so that recovering mds waits for reconnect
624         local running=$(grep -c $MOUNT /proc/mounts) || true
625         if [ $running -ne 0 ]; then
626                 echo "Stopping client $MOUNT (opts: -f)"
627                 umount -f $MOUNT
628         fi
629
630         # enter recovery on mds
631         start_mds
632         # try to start a new client
633         mount_client $MOUNT &
634         sleep 5
635         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
636         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
637         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
638         ps --ppid $MOUNT_PID
639         ps --ppid $MOUNT_LUSTRE_PID
640         # FIXME why o why can't I kill these? Manual "ctrl-c" works...
641         kill -TERM $MOUNT_LUSTRE_PID
642         echo "waiting for mount to finish"
643         ps -ef | grep mount
644         # we can not wait $MOUNT_PID because it is not a child of this shell
645         local PID1
646         local PID2
647         local WAIT=0
648         local MAX_WAIT=20
649         local sleep=1
650         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
651                 sleep $sleep
652                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
653                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
654                 echo PID1=$PID1
655                 echo PID2=$PID2
656                 [ -z "$PID1" -a -z "$PID2" ] && break
657                 echo "waiting for mount to finish ... "
658                 WAIT=$(( WAIT + sleep))
659         done
660         [ "$WAIT" -eq "$MAX_WAIT" ] && error "MOUNT_PID $MOUNT_PID and \
661                 MOUNT__LUSTRE_PID $MOUNT__LUSTRE_PID still not killed in $WAIT secs"
662         ps -ef | grep mount
663         stop_mds || error
664         stop_ost || error
665 }
666 run_test 23a "interrupt client during recovery mount delay"
667
668 umount_client $MOUNT
669 cleanup_nocli
670
671 test_23b() {    # was test_23
672         start_ost
673         start_mds
674         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
675         lctl set_param fail_loc=0x80000313
676         mount_client $MOUNT
677         cleanup
678 }
679 run_test 23b "Simulate -EINTR during mount"
680
681 fs2mds_HOST=$mds_HOST
682 fs2ost_HOST=$ost_HOST
683
684 cleanup_24a() {
685         trap 0
686         echo "umount $MOUNT2 ..."
687         umount $MOUNT2 || true
688         echo "stopping fs2mds ..."
689         stop fs2mds -f || true
690         echo "stopping fs2ost ..."
691         stop fs2ost -f || true
692 }
693
694 test_24a() {
695         #set up fs1
696         gen_config
697         #set up fs2
698         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
699         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
700                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
701                 skip "mixed loopback and real device not working" && return
702         fi
703
704         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
705         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
706
707         # test 8-char fsname as well
708         local FSNAME2=test1234
709         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --nomgs --mgsnode=$MGSNID --reformat $fs2mdsdev || exit 10
710
711         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2ostdev || exit 10
712
713         setup
714         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
715         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
716         mkdir -p $MOUNT2
717         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
718         # 1 still works
719         check_mount || return 2
720         # files written on 1 should not show up on 2
721         cp /etc/passwd $DIR/$tfile
722         sleep 10
723         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
724         # 2 should work
725         sleep 5
726         cp /etc/passwd $MOUNT2/b || return 3
727         rm $MOUNT2/b || return 4
728         # 2 is actually mounted
729         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
730         # failover
731         facet_failover fs2mds
732         facet_failover fs2ost
733         df
734         umount_client $MOUNT
735         # the MDS must remain up until last MDT
736         stop_mds
737         MDS=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
738         [ -z "$MDS" ] && error "No MDT" && return 8
739         cleanup_24a
740         cleanup_nocli || return 6
741 }
742 run_test 24a "Multiple MDTs on a single node"
743
744 test_24b() {
745         if [ -z "$fs2mds_DEV" ]; then
746                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
747                 skip "mixed loopback and real device not working" && return
748         fi
749
750         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
751
752         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME}2 --mgs --reformat $fs2mdsdev || exit 10
753         setup
754         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
755         cleanup || return 6
756 }
757 run_test 24b "Multiple MGSs on a single node (should return err)"
758
759 test_25() {
760         setup
761         check_mount || return 2
762         local MODULES=$($LCTL modules | awk '{ print $2 }')
763         rmmod $MODULES 2>/dev/null || true
764         cleanup || return 6
765 }
766 run_test 25 "Verify modules are referenced"
767
768 test_26() {
769     load_modules
770     # we need modules before mount for sysctl, so make sure...
771     do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
772 #define OBD_FAIL_MDS_FS_SETUP            0x135
773     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000135"
774     start_mds && echo MDS started && return 1
775     lctl get_param -n devices
776     DEVS=$(lctl get_param -n devices | wc -l)
777     [ $DEVS -gt 0 ] && return 2
778     unload_modules || return 203
779 }
780 run_test 26 "MDT startup failure cleans LOV (should return errs)"
781
782 set_and_check() {
783         local myfacet=$1
784         local TEST=$2
785         local PARAM=$3
786         local ORIG=$(do_facet $myfacet "$TEST")
787         if [ $# -gt 3 ]; then
788             local FINAL=$4
789         else
790             local -i FINAL
791             FINAL=$(($ORIG + 5))
792         fi
793         echo "Setting $PARAM from $ORIG to $FINAL"
794         do_facet $SINGLEMDS "$LCTL conf_param $PARAM='$FINAL'" || error conf_param failed
795
796         wait_update $(facet_host $myfacet) "$TEST" "$FINAL" || error check failed!
797 }
798
799 test_27a() {
800         start_ost || return 1
801         start_mds || return 2
802         echo "Requeue thread should have started: "
803         ps -e | grep ll_cfg_requeue
804         set_and_check ost1 "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" "$FSNAME-OST0000.ost.client_cache_seconds" || return 3
805         cleanup_nocli
806 }
807 run_test 27a "Reacquire MGS lock if OST started first"
808
809 test_27b() {
810         # FIXME. ~grev
811         setup
812         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }')
813
814         facet_failover $SINGLEMDS
815         set_and_check $SINGLEMDS "lctl get_param -n mdt.$device.identity_acquire_expire" "$device.mdt.identity_acquire_expire" || return 3
816         set_and_check client "lctl get_param -n mdc.$device-mdc-*.max_rpcs_in_flight" "$device.mdc.max_rpcs_in_flight" || return 4
817         check_mount
818         cleanup
819 }
820 run_test 27b "Reacquire MGS lock after failover"
821
822 test_28() {
823         setup
824         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
825         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
826         ORIG=$($TEST)
827         FINAL=$(($ORIG + 1))
828         set_and_check client "$TEST" "$PARAM" $FINAL || return 3
829         FINAL=$(($FINAL + 1))
830         set_and_check client "$TEST" "$PARAM" $FINAL || return 4
831         umount_client $MOUNT || return 200
832         mount_client $MOUNT
833         RESULT=$($TEST)
834         if [ $RESULT -ne $FINAL ]; then
835             echo "New config not seen: wanted $FINAL got $RESULT"
836             return 4
837         else
838             echo "New config success: got $RESULT"
839         fi
840         set_and_check client "$TEST" "$PARAM" $ORIG || return 5
841         cleanup
842 }
843 run_test 28 "permanent parameter setting"
844
845 test_29() {
846         [ "$OSTCOUNT" -lt "2" ] && skip "$OSTCOUNT < 2, skipping" && return
847         setup > /dev/null 2>&1
848         start_ost2
849         sleep 10
850
851         local PARAM="$FSNAME-OST0001.osc.active"
852         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
853         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
854
855         ACTV=$(lctl get_param -n $PROC_ACT)
856         DEAC=$((1 - $ACTV))
857         set_and_check client "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
858         # also check ost_server_uuid status
859         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
860         if [ -z "$RESULT" ]; then
861             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
862             return 3
863         else
864             echo "Live client success: got $RESULT"
865         fi
866
867         # check MDT too
868         local MPROC="osc.$FSNAME-OST0001-osc-[M]*.active"
869         local MAX=30
870         local WAIT=0
871         while [ 1 ]; do
872             sleep 5
873             RESULT=`do_facet $SINGLEMDS " lctl get_param -n $MPROC"`
874             [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
875             if [ $RESULT -eq $DEAC ]; then
876                 echo "MDT deactivated also after $WAIT sec (got $RESULT)"
877                 break
878             fi
879             WAIT=$((WAIT + 5))
880             if [ $WAIT -eq $MAX ]; then
881                 echo "MDT not deactivated: wanted $DEAC got $RESULT"
882                 return 4
883             fi
884             echo "Waiting $(($MAX - $WAIT)) secs for MDT deactivated"
885         done
886
887         # test new client starts deactivated
888         umount_client $MOUNT || return 200
889         mount_client $MOUNT
890         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
891         if [ -z "$RESULT" ]; then
892             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
893             return 5
894         else
895             echo "New client success: got $RESULT"
896         fi
897
898         # make sure it reactivates
899         set_and_check client "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
900
901         umount_client $MOUNT
902         stop_ost2
903         cleanup_nocli
904         #writeconf to remove all ost2 traces for subsequent tests
905         writeconf
906 }
907 run_test 29 "permanently remove an OST"
908
909 test_30() {
910         setup
911
912         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
913         ORIG=$($TEST)
914         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
915         for i in ${LIST[@]}; do
916             set_and_check client "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
917         done
918         # make sure client restart still works
919         umount_client $MOUNT
920         mount_client $MOUNT || return 4
921         [ "$($TEST)" -ne "$i" ] && return 5
922         set_and_check client "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $ORIG || return 6
923         cleanup
924 }
925 run_test 30 "Big config llog"
926
927 test_31() { # bug 10734
928         # ipaddr must not exist
929         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
930         cleanup
931 }
932 run_test 31 "Connect to non-existent node (shouldn't crash)"
933
934 # Use these start32/stop32 fn instead of t-f start/stop fn,
935 # for local devices, to skip global facet vars init
936 stop32 () {
937         local facet=$1
938         shift
939         echo "Stopping local ${MOUNT%/*}/${facet} (opts:$@)"
940         umount -d $@ ${MOUNT%/*}/${facet}
941         losetup -a
942 }
943
944 start32 () {
945         local facet=$1
946         shift
947         local device=$1
948         shift
949         mkdir -p ${MOUNT%/*}/${facet}
950
951         echo "Starting local ${facet}: $@ $device ${MOUNT%/*}/${facet}"
952         mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
953         RC=$?
954         if [ $RC -ne 0 ]; then
955                 echo "mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}"
956                 echo "Start of ${device} of local ${facet} failed ${RC}"
957         fi
958         losetup -a
959         return $RC
960 }
961
962 cleanup_nocli32 () {
963         stop32 mds1 -f
964         stop32 ost1 -f
965         wait_exit_ST client
966 }
967
968 cleanup_32() {
969         trap 0
970         echo "Cleanup test_32 umount $MOUNT ..."
971         umount -f $MOUNT || true
972         echo "Cleanup local mds ost1 ..."
973         cleanup_nocli32
974         unload_modules
975 }
976
977 test_32a() {
978         # this test is totally useless on a client-only system
979         [ -n "$CLIENTONLY" -o -n "$CLIENTMODSONLY" ] && skip "client only testing" && return 0
980         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
981         [ -z "$TUNEFS" ] && skip "No tunefs" && return 0
982         local DISK1_8=$LUSTRE/tests/disk1_8.tgz
983         [ ! -r $DISK1_8 ] && skip "Cannot find $DISK1_8" && return 0
984
985         mkdir -p $TMP/$tdir
986         tar xjvf $DISK1_8 -C $TMP/$tdir || \
987                 { skip "Cannot untar $DISK1_8" && return 0; }
988
989         load_modules
990         lctl set_param debug=$PTLDEBUG
991
992         $TUNEFS $tmpdir/mds || error "tunefs failed"
993
994         # nids are wrong, so client wont work, but server should start
995         start32 mds $tmpdir/mds "-o loop,exclude=lustre-OST0000" && \
996                 trap cleanup_32 EXIT INT || return 3
997
998         local UUID=$(lctl get_param -n mds.lustre-MDT0000.uuid)
999         echo MDS uuid $UUID
1000         [ "$UUID" == "mdsA_UUID" ] || error "UUID is wrong: $UUID"
1001
1002         $TUNEFS --mgsnode=`hostname` $tmpdir/ost1 || error "tunefs failed"
1003         start32 ost1 $tmpdir/ost1 "-o loop" || return 5
1004         UUID=$(lctl get_param -n obdfilter.lustre-OST0000.uuid)
1005         echo OST uuid $UUID
1006         [ "$UUID" == "ost1_UUID" ] || error "UUID is wrong: $UUID"
1007
1008         local NID=$($LCTL list_nids | head -1)
1009
1010         echo "OSC changes should return err:"
1011         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 && return 7
1012         $LCTL conf_param lustre-OST0000.failover.node=$NID && return 8
1013         echo "ok."
1014         echo "MDC changes should succeed:"
1015         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1016         $LCTL conf_param lustre-MDT0000.failover.node=$NID || return 10
1017         echo "ok."
1018
1019         # With a new good MDT failover nid, we should be able to mount a client
1020         # (but it cant talk to OST)
1021         local mountopt="-o exclude=lustre-OST0000"
1022
1023         local device=`h2$NETTYPE $HOSTNAME`:/lustre
1024         echo "Starting local client: $HOSTNAME: $mountopt $device $MOUNT"
1025         mount -t lustre $mountopt $device $MOUNT || return 1
1026
1027         local old=$(lctl get_param -n mdc.*.max_rpcs_in_flight)
1028         local new=$((old + 5))
1029         lctl conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=$new
1030         wait_update $HOSTNAME "lctl get_param -n mdc.*.max_rpcs_in_flight" $new || return 11
1031
1032         cleanup_32
1033
1034         # mount a second time to make sure we didnt leave upgrade flag on
1035         load_modules
1036         $TUNEFS --dryrun $tmpdir/mds || error "tunefs failed"
1037         start32 mds $tmpdir/mds "-o loop,exclude=lustre-OST0000" && \
1038                 trap cleanup_32 EXIT INT || return 12
1039
1040         cleanup_32
1041
1042         rm -rf $tmpdir || true  # true is only for TMP on NFS
1043 }
1044 run_test 32a "Upgrade from 1.8 (not live)"
1045
1046 test_32b() {
1047         # this test is totally useless on a client-only system
1048         [ -n "$CLIENTONLY" -o -n "$CLIENTMODSONLY" ] && skip "client only testing" && return 0
1049         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
1050         [ -z "$TUNEFS" ] && skip "No tunefs" && return
1051
1052         local DISK1_8=$LUSTRE/tests/disk1_8.tar.bz2
1053         [ ! -r $DISK1_8 ] && skip "Cannot find $DISK1_8" && return 0
1054         local tmpdir=$TMP/$tdir
1055         mkdir -p $tmpdir
1056         tar xjvf $DISK1_8 -C $tmpdir || \
1057                 { skip "Cannot untar $DISK1_8" && return ; }
1058
1059         load_modules
1060         lctl set_param debug=$PTLDEBUG
1061         local NEWNAME=lustre
1062
1063         # writeconf will cause servers to register with their current nids
1064         $TUNEFS --writeconf --fsname=$NEWNAME $tmpdir/mds || error "tunefs failed"
1065         start32 mds1 $tmpdir/mds "-o loop" && \
1066                 trap cleanup_32 EXIT INT || return 3
1067
1068         local UUID=$(lctl get_param -n mdt.${NEWNAME}-MDT0000.uuid)
1069         echo MDS uuid $UUID
1070         [ "$UUID" == "${NEWNAME}-MDT0000_UUID" ] || error "UUID is wrong: $UUID"
1071
1072         $TUNEFS --mgsnode=`hostname` --writeconf --fsname=$NEWNAME $tmpdir/ost1 || error "tunefs failed"
1073         start32 ost1 $tmpdir/ost1 "-o loop" || return 5
1074         UUID=$(lctl get_param -n obdfilter.${NEWNAME}-OST0000.uuid)
1075         echo OST uuid $UUID
1076         [ "$UUID" == "${NEWNAME}-OST0000_UUID" ] || error "UUID is wrong: $UUID"
1077
1078         echo "OSC changes should succeed:"
1079         $LCTL conf_param ${NEWNAME}-OST0000.osc.max_dirty_mb=15 || return 7
1080         $LCTL conf_param ${NEWNAME}-OST0000.failover.node=$NID || return 8
1081         echo "ok."
1082         echo "MDC changes should succeed:"
1083         $LCTL conf_param ${NEWNAME}-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1084         echo "ok."
1085
1086         # MDT and OST should have registered with new nids, so we should have
1087         # a fully-functioning client
1088         echo "Check client and old fs contents"
1089
1090         local device=`h2$NETTYPE $HOSTNAME`:/$NEWNAME
1091         echo "Starting local client: $HOSTNAME: $device $MOUNT"
1092         mount -t lustre $device $MOUNT || return 1
1093
1094         local old=$(lctl get_param -n mdc.*.max_rpcs_in_flight)
1095         local new=$((old + 5))
1096         lctl conf_param ${NEWNAME}-MDT0000.mdc.max_rpcs_in_flight=$new
1097         wait_update $HOSTNAME "lctl get_param -n mdc.*.max_rpcs_in_flight" $new || return 11
1098
1099         [ "$(cksum $MOUNT/passwd | cut -d' ' -f 1,2)" == "94306271 1478" ] || return 12
1100         echo "ok."
1101
1102         cleanup_32
1103
1104         rm -rf $tmpdir || true  # true is only for TMP on NFS
1105 }
1106 run_test 32b "Upgrade from 1.8 with writeconf"
1107
1108 test_33a() { # bug 12333, was test_33
1109         local rc=0
1110         local FSNAME2=test-123
1111         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1112
1113         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1114                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
1115                 skip "mixed loopback and real device not working" && return
1116         fi
1117
1118         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1119         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1120         add fs2mds $MDS_MKFS_OPTS --mkfsoptions='\"-J size=8\"' --fsname=${FSNAME2} --reformat $fs2mdsdev || exit 10
1121         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --index=8191 --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1122
1123         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1124         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1125         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1126         mkdir -p $MOUNT2
1127         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1128         echo "ok."
1129
1130         cp /etc/hosts $MOUNT2/ || rc=3
1131         $LFS getstripe $MOUNT2/hosts
1132
1133         umount -d $MOUNT2
1134         stop fs2ost -f
1135         stop fs2mds -f
1136         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev
1137         cleanup_nocli || rc=6
1138         return $rc
1139 }
1140 run_test 33a "Mount ost with a large index number"
1141
1142 test_33b() {    # was test_34
1143         setup
1144
1145         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1146         # Drop lock cancelation reply during umount
1147         #define OBD_FAIL_LDLM_CANCEL             0x304
1148         do_facet client lctl set_param fail_loc=0x80000304
1149         #lctl set_param debug=-1
1150         umount_client $MOUNT
1151         cleanup
1152 }
1153 run_test 33b "Drop cancel during umount"
1154
1155 test_34a() {
1156         setup
1157         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
1158         manual_umount_client
1159         rc=$?
1160         do_facet client killall -USR1 multiop
1161         if [ $rc -eq 0 ]; then
1162                 error "umount not fail!"
1163         fi
1164         sleep 1
1165         cleanup
1166 }
1167 run_test 34a "umount with opened file should be fail"
1168
1169
1170 test_34b() {
1171         setup
1172         touch $DIR/$tfile || return 1
1173         stop_mds --force || return 2
1174
1175         manual_umount_client --force
1176         rc=$?
1177         if [ $rc -ne 0 ]; then
1178                 error "mtab after failed umount - rc $rc"
1179         fi
1180
1181         cleanup
1182         return 0
1183 }
1184 run_test 34b "force umount with failed mds should be normal"
1185
1186 test_34c() {
1187         setup
1188         touch $DIR/$tfile || return 1
1189         stop_ost --force || return 2
1190
1191         manual_umount_client --force
1192         rc=$?
1193         if [ $rc -ne 0 ]; then
1194                 error "mtab after failed umount - rc $rc"
1195         fi
1196
1197         cleanup
1198         return 0
1199 }
1200 run_test 34c "force umount with failed ost should be normal"
1201
1202 test_35() { # bug 12459
1203         setup
1204
1205         DBG_SAVE="`lctl get_param -n debug`"
1206         lctl set_param debug="ha"
1207
1208         log "Set up a fake failnode for the MDS"
1209         FAKENID="127.0.0.2"
1210         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1211         do_facet $SINGLEMDS $LCTL conf_param ${device}.failover.node=$FAKENID || return 4
1212
1213         log "Wait for RECONNECT_INTERVAL seconds (10s)"
1214         sleep 10
1215
1216         MSG="conf-sanity.sh test_35 `date +%F%kh%Mm%Ss`"
1217         $LCTL clear
1218         log "$MSG"
1219         log "Stopping the MDT:"
1220         stop_mds || return 5
1221
1222         df $MOUNT > /dev/null 2>&1 &
1223         DFPID=$!
1224         log "Restarting the MDT:"
1225         start_mds || return 6
1226         log "Wait for df ($DFPID) ... "
1227         wait $DFPID
1228         log "done"
1229         lctl set_param debug="$DBG_SAVE"
1230
1231         # retrieve from the log the first server that the client tried to
1232         # contact after the connection loss
1233         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1234         NEXTCONN=`awk "/${MSG}/ {start = 1;}
1235                        /import_select_connection.*$device-mdc.* using connection/ {
1236                                 if (start) {
1237                                         if (\\\$NF ~ /$FAKENID/)
1238                                                 print \\\$NF;
1239                                         else
1240                                                 print 0;
1241                                         exit;
1242                                 }
1243                        }" $TMP/lustre-log-$TESTNAME.log`
1244         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
1245         cleanup
1246 }
1247 run_test 35 "Reconnect to the last active server first"
1248
1249 test_36() { # 12743
1250         local rc
1251         local FSNAME2=test1234
1252         local fs3ost_HOST=$ost_HOST
1253
1254         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
1255         rc=0
1256
1257         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
1258                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
1259                 skip "mixed loopback and real device not working" && return
1260         fi
1261         [ $OSTCOUNT -lt 2 ] && skip "skipping test for single OST" && return
1262
1263         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
1264                 { skip "remote OST" && return 0; }
1265
1266         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1267         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1268         local fs3ostdev=${fs3ost_DEV:-$(ostdevname 2)_2}
1269         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2mdsdev || exit 10
1270         # XXX after we support non 4K disk blocksize, change following --mkfsoptions with
1271         # other argument
1272         add fs2ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1273         add fs3ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs3ostdev || exit 10
1274
1275         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
1276         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1277         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
1278         mkdir -p $MOUNT2
1279         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
1280
1281         sleep 5 # until 11778 fixed
1282
1283         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
1284
1285         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1286         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
1287         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
1288         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
1289         DFTOTAL=`echo $STRING | cut -d, -f1`
1290         DFUSED=`echo $STRING  | cut -d, -f2`
1291         DFAVAIL=`echo $STRING | cut -d, -f3`
1292         DFFREE=$(($DFTOTAL - $DFUSED))
1293
1294         ALLOWANCE=$((64 * $OSTCOUNT))
1295
1296         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
1297            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
1298                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
1299                 rc=1
1300         fi
1301         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
1302            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
1303                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
1304                 rc=2
1305         fi
1306         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
1307            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
1308                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
1309                 rc=3
1310        fi
1311
1312         umount -d $MOUNT2
1313         stop fs3ost -f || return 200
1314         stop fs2ost -f || return 201
1315         stop fs2mds -f || return 202
1316         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev $fs3ostdev
1317         unload_modules || return 203
1318         return $rc
1319 }
1320 run_test 36 "df report consistency on OSTs with different block size"
1321
1322 test_37() {
1323         [ -n "$CLIENTONLY" -o -n "$CLIENTMODSONLY" ] && skip "client only testing" && return 0
1324         LOCAL_MDSDEV="$TMP/mdt.img"
1325         SYM_MDSDEV="$TMP/sym_mdt.img"
1326
1327         echo "MDS :     $LOCAL_MDSDEV"
1328         echo "SYMLINK : $SYM_MDSDEV"
1329         rm -f $LOCAL_MDSDEV
1330
1331         touch $LOCAL_MDSDEV
1332         mkfs.lustre --reformat --fsname=lustre --mdt --mgs --device-size=9000 $LOCAL_MDSDEV ||
1333                 error "mkfs.lustre $LOCAL_MDSDEV failed"
1334         ln -s $LOCAL_MDSDEV $SYM_MDSDEV
1335
1336         echo "mount symlink device - $SYM_MDSDEV"
1337
1338         mount_op=`mount -v -t lustre -o loop $SYM_MDSDEV ${MOUNT%/*}/mds 2>&1 | grep "unable to set tunable"`
1339         umount -d ${MOUNT%/*}/mds
1340         rm -f $LOCAL_MDSDEV $SYM_MDSDEV
1341
1342         if [ -n "$mount_op" ]; then
1343                 error "**** FAIL: set tunables failed for symlink device"
1344         fi
1345         return 0
1346 }
1347 run_test 37 "verify set tunables works for symlink device"
1348
1349 test_38() { # bug 14222
1350         setup
1351         # like runtests
1352         COUNT=10
1353         SRC="/etc /bin"
1354         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
1355         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
1356         mkdir -p $DIR/$tdir
1357         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
1358                 error "copying $SRC to $DIR/$tdir"
1359         sync
1360         umount_client $MOUNT
1361         stop_mds
1362         log "rename lov_objid file on MDS"
1363         rm -f $TMP/lov_objid.orig
1364
1365         local dev=${SINGLEMDS}_dev
1366         local MDSDEV=${!dev}
1367         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
1368         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1369
1370         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.orig"
1371         # check create in mds_lov_connect
1372         start_mds
1373         mount_client $MOUNT
1374         for f in $FILES; do
1375                 [ $V ] && log "verifying $DIR/$tdir/$f"
1376                 diff -q $f $DIR/$tdir/$f || ERROR=y
1377         done
1378         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
1379         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new"
1380         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
1381
1382         # check it's updates in sync
1383         umount_client $MOUNT
1384         stop_mds
1385
1386         do_facet $SINGLEMDS dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
1387         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1388         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
1389
1390         start_mds
1391         mount_client $MOUNT
1392         for f in $FILES; do
1393                 [ $V ] && log "verifying $DIR/$tdir/$f"
1394                 diff -q $f $DIR/$tdir/$f || ERROR=y
1395         done
1396         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
1397         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new1"
1398         umount_client $MOUNT
1399         stop_mds
1400         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
1401
1402         log "files compared the same"
1403         cleanup
1404 }
1405 run_test 38 "MDS recreates missing lov_objid file from OST data"
1406
1407 test_39() {
1408         PTLDEBUG=+malloc
1409         setup
1410         cleanup
1411         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
1412                 error "memory leak detected" || true
1413 }
1414 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
1415
1416 test_40() { # bug 15759
1417         start_ost
1418         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
1419         do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000706"
1420         start_mds
1421         cleanup
1422 }
1423 run_test 40 "race during service thread startup"
1424
1425 test_41() { #bug 14134
1426         local rc
1427         local dev=${SINGLEMDS}_dev
1428         local MDSDEV=${!dev}
1429
1430         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
1431         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
1432         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
1433         mkdir -p $MOUNT
1434         mount_client $MOUNT || return 1
1435         sleep 5
1436
1437         echo "blah blah" > $MOUNT/$tfile
1438         cat $MOUNT/$tfile
1439
1440         umount_client $MOUNT
1441         stop ost1 -f || return 201
1442         stop_mds -f || return 202
1443         stop_mds -f || return 203
1444         unload_modules || return 204
1445         return $rc
1446 }
1447 run_test 41 "mount mds with --nosvc and --nomgs"
1448
1449 test_42() { #bug 14693
1450         setup
1451         check_mount || return 2
1452         do_facet client lctl conf_param lustre.llite.some_wrong_param=10
1453         umount_client $MOUNT
1454         mount_client $MOUNT || return 1
1455         cleanup
1456         return 0
1457 }
1458 run_test 42 "invalid config param should not prevent client from mounting"
1459
1460 test_43() {
1461     [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip "run as root"
1462     setup
1463     chmod ugo+x $DIR || error "chmod 0 failed"
1464     set_and_check mds                                        \
1465         "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"  \
1466         "$FSNAME.mdt.root_squash"                            \
1467         "0:0"
1468     set_and_check mds                                        \
1469        "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids" \
1470        "$FSNAME.mdt.nosquash_nids"                           \
1471        "NONE"
1472
1473     #
1474     # create set of test files
1475     #
1476     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
1477     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
1478     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
1479
1480     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
1481     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
1482
1483     mkdir $DIR/$tdir-rootdir -p       || error "mkdir failed"
1484     chmod go-rwx $DIR/$tdir-rootdir   || error "chmod 3 failed"
1485     touch $DIR/$tdir-rootdir/tfile-1  || error "touch failed"
1486
1487     #
1488     # check root_squash:
1489     #   set root squash UID:GID to RUNAS_ID
1490     #   root should be able to access only files owned by RUNAS_ID
1491     #
1492     set_and_check mds                                        \
1493        "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"   \
1494        "$FSNAME.mdt.root_squash"                             \
1495        "$RUNAS_ID:$RUNAS_ID"
1496
1497     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
1498     dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
1499         error "$ST: root read permission is denied"
1500     echo "$ST: root read permission is granted - ok"
1501
1502     echo "444" | \
1503     dd conv=notrunc if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
1504         error "$ST: root write permission is denied"
1505     echo "$ST: root write permission is granted - ok"
1506
1507     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
1508     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
1509         error "$ST: root read permission is granted"
1510     echo "$ST: root read permission is denied - ok"
1511
1512     echo "555" | \
1513     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
1514         error "$ST: root write permission is granted"
1515     echo "$ST: root write permission is denied - ok"
1516
1517     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
1518     rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null && \
1519         error "$ST: root unlink permission is granted"
1520     echo "$ST: root unlink permission is denied - ok"
1521
1522     touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null && \
1523         error "$ST: root create permission is granted"
1524     echo "$ST: root create permission is denied - ok"
1525
1526     #
1527     # check nosquash_nids:
1528     #   put client's NID into nosquash_nids list,
1529     #   root should be able to access root file after that
1530     #
1531     local NIDLIST=$(lctl list_nids all | tr '\n' ' ')
1532     NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
1533     NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
1534     set_and_check mds                                        \
1535        "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids" \
1536        "$FSNAME-MDTall.mdt.nosquash_nids"                    \
1537        "$NIDLIST"
1538
1539     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
1540     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
1541         error "$ST: root read permission is denied"
1542     echo "$ST: root read permission is granted - ok"
1543
1544     echo "666" | \
1545     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
1546         error "$ST: root write permission is denied"
1547     echo "$ST: root write permission is granted - ok"
1548
1549     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
1550     rm $DIR/$tdir-rootdir/tfile-1 || \
1551         error "$ST: root unlink permission is denied"
1552     echo "$ST: root unlink permission is granted - ok"
1553     touch $DIR/$tdir-rootdir/tfile-2 || \
1554         error "$ST: root create permission is denied"
1555     echo "$ST: root create permission is granted - ok"
1556
1557     return 0
1558 }
1559 run_test 43 "check root_squash and nosquash_nids"
1560
1561 umount_client $MOUNT
1562 cleanup_nocli
1563
1564 test_45() { #17310
1565         setup
1566         check_mount || return 2
1567         stop_mds
1568         df -h $MOUNT &
1569         log "sleep 60 sec"
1570         sleep 60
1571 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
1572         do_facet client "lctl set_param fail_loc=0x50f"
1573         log "sleep 10 sec"
1574         sleep 10
1575         manual_umount_client --force || return 3
1576         do_facet client "lctl set_param fail_loc=0x0"
1577         start_mds
1578         mount_client $MOUNT || return 4
1579         cleanup
1580         return 0
1581 }
1582 run_test 45 "long unlink handling in ptlrpcd"
1583
1584 test_46a() {
1585         OSTCOUNT=6
1586         reformat
1587         start_mds || return 1
1588         #first client should see only one ost
1589         start_ost || return 2
1590         wait_osc_import_state mds ost FULL
1591         #start_client
1592         mount_client $MOUNT || return 3
1593
1594         start_ost2 || return 4
1595         start ost3 `ostdevname 3` $OST_MOUNT_OPTS || return 5
1596         start ost4 `ostdevname 4` $OST_MOUNT_OPTS || return 6
1597         start ost5 `ostdevname 5` $OST_MOUNT_OPTS || return 7
1598         # wait until ost2-5 is sync
1599         # ping_interval + 1
1600         wait_osc_import_state mds ost2 FULL
1601         wait_osc_import_state mds ost3 FULL
1602         wait_osc_import_state mds ost4 FULL
1603         wait_osc_import_state mds ost5 FULL
1604         #second client see all ost's
1605
1606         mount_client $MOUNT2 || return 8
1607         $LFS setstripe $MOUNT2 -c -1 || return 9
1608         $LFS getstripe $MOUNT2 || return 10
1609
1610         echo "ok" > $MOUNT2/widestripe
1611         $LFS getstripe $MOUNT2/widestripe || return 11
1612         # fill acl buffer for avoid expand lsm to them
1613         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
1614             setfacl -m $acl $MOUNT2/widestripe
1615         done
1616
1617         # will be deadlock
1618         stat $MOUNT/widestripe || return 12
1619
1620         umount_client $MOUNT2 || return 13
1621         umount_client $MOUNT || return 14
1622         stop ost5 -f || return 20
1623         stop ost4 -f || return 21
1624         stop ost3 -f || return 22
1625         stop_ost2 || return 23
1626         stop_ost || return 24
1627         stop_mds || return 25
1628 }
1629 run_test 46a "handle ost additional - wide striped file"
1630
1631 test_47() { #17674
1632         reformat
1633         setup_noconfig
1634         check_mount || return 2
1635         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
1636
1637         local lru_size=[]
1638         local count=0
1639         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
1640             if echo $ns | grep "MDT[[:digit:]]*"; then
1641                 continue
1642             fi
1643             lrs=$(echo $ns | sed 's/.*lru_size=//')
1644             lru_size[count]=$lrs
1645             let count=count+1
1646         done
1647
1648         facet_failover ost1
1649         facet_failover $SINGLEMDS
1650         df -h $MOUNT || return 3
1651
1652         count=0
1653         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
1654             if echo $ns | grep "MDT[[:digit:]]*"; then
1655                 continue
1656             fi
1657             lrs=$(echo $ns | sed 's/.*lru_size=//')
1658             if ! test "$lrs" -eq "${lru_size[count]}"; then
1659                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
1660                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
1661             fi
1662             let count=count+1
1663         done
1664
1665         cleanup
1666         return 0
1667 }
1668 run_test 47 "server restart does not make client loss lru_resize settings"
1669
1670 cleanup_48() {
1671         trap 0
1672
1673         # reformat after this test is needed - if test will failed
1674         # we will have unkillable file at FS
1675         reformat_and_config
1676 }
1677
1678 test_48() { # bug 17636
1679         reformat
1680         setup_noconfig
1681         check_mount || return 2
1682
1683         $LFS setstripe $MOUNT -c -1 || return 9
1684         $LFS getstripe $MOUNT || return 10
1685
1686         echo "ok" > $MOUNT/widestripe
1687         $LFS getstripe $MOUNT/widestripe || return 11
1688
1689         trap cleanup_48 EXIT ERR
1690
1691         # fill acl buffer for avoid expand lsm to them
1692         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
1693             setfacl -m $acl $MOUNT/widestripe
1694         done
1695
1696         stat $MOUNT/widestripe || return 12
1697
1698         cleanup_48
1699         return 0
1700 }
1701 run_test 48 "too many acls on file"
1702
1703 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
1704 test_49() { # bug 17710
1705         local OLD_MDS_MKFS_OPTS=$MDS_MKFS_OPTS
1706         local OLD_OST_MKFS_OPTS=$OST_MKFS_OPTS
1707         local LOCAL_TIMEOUT=20
1708
1709
1710         OST_MKFS_OPTS="--ost --fsname=$FSNAME --device-size=$OSTSIZE --mgsnode=$MGSNID --param sys.timeout=$LOCAL_TIMEOUT --param sys.ldlm_timeout=$LOCAL_TIMEOUT $MKFSOPT $OSTOPT"
1711
1712         reformat
1713         start_mds
1714         start_ost
1715         mount_client $MOUNT
1716         check_mount || return 1
1717
1718         echo "check ldlm_timout..."
1719         LDLM_MDS="`do_facet mds lctl get_param -n ldlm_timeout`"
1720         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
1721         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
1722
1723         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
1724                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
1725         fi
1726
1727         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
1728                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
1729         fi
1730
1731         umount_client $MOUNT
1732         stop_ost || return 2
1733         stop_mds || return 3
1734
1735         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"
1736
1737         reformat
1738         start_mds || return 4
1739         start_ost || return 5
1740         mount_client $MOUNT || return 6
1741         check_mount || return 7
1742
1743         LDLM_MDS="`do_facet mds lctl get_param -n ldlm_timeout`"
1744         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
1745         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
1746
1747         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
1748                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
1749         fi
1750
1751         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
1752                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
1753         fi
1754
1755         cleanup || return $?
1756
1757         MDS_MKFS_OPTS=$OLD_MDS_MKFS_OPTS
1758         OST_MKFS_OPTS=$OLD_OST_MKFS_OPTS
1759 }
1760 run_test 49 "check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE"
1761
1762 lazystatfs() {
1763         # Test both statfs and lfs df and fail if either one fails
1764         multiop_bg_pause $1 f_
1765         RC1=$?
1766         PID=$!
1767         killall -USR1 multiop
1768         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
1769         wait $PID || { RC1=$?; log "multiop return error "; }
1770
1771         $LFS df &
1772         PID=$!
1773         sleep 5
1774         kill -s 0 $PID
1775         RC2=$?
1776         if [ $RC2 -eq 0 ]; then
1777             kill -s 9 $PID
1778             log "lazystatfs df failed"
1779         fi
1780
1781         RC=0
1782         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
1783         return $RC
1784 }
1785
1786 test_50a() {
1787         setup
1788         lctl set_param llite.$FSNAME-*.lazystatfs=1
1789         touch $DIR/$tfile
1790
1791         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
1792
1793         cleanup || return $?
1794 }
1795 run_test 50a "lazystatfs all servers available =========================="
1796
1797 test_50b() {
1798         setup
1799         lctl set_param llite.$FSNAME-*.lazystatfs=1
1800         touch $DIR/$tfile
1801
1802         # Wait for client to detect down OST
1803         stop_ost || error "Unable to stop OST1"
1804         wait_osc_import_state mds ost DISCONN
1805
1806         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
1807
1808         umount_client $MOUNT || error "Unable to unmount client"
1809         stop_mds || error "Unable to stop MDS"
1810 }
1811 run_test 50b "lazystatfs all servers down =========================="
1812
1813 test_50c() {
1814         start_mds || error "Unable to start MDS"
1815         start_ost || error "Unable to start OST1"
1816         start_ost2 || error "Unable to start OST2"
1817         mount_client $MOUNT || error "Unable to mount client"
1818         lctl set_param llite.$FSNAME-*.lazystatfs=1
1819         touch $DIR/$tfile
1820
1821         # Wait for client to detect down OST
1822         stop_ost || error "Unable to stop OST1"
1823         wait_osc_import_state mds ost DISCONN
1824         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
1825
1826         umount_client $MOUNT || error "Unable to unmount client"
1827         stop_ost2 || error "Unable to stop OST2"
1828         stop_mds || error "Unable to stop MDS"
1829 }
1830 run_test 50c "lazystatfs one server down =========================="
1831
1832 test_50d() {
1833         start_mds || error "Unable to start MDS"
1834         start_ost || error "Unable to start OST1"
1835         start_ost2 || error "Unable to start OST2"
1836         mount_client $MOUNT || error "Unable to mount client"
1837         lctl set_param llite.$FSNAME-*.lazystatfs=1
1838         touch $DIR/$tfile
1839
1840         # Issue the statfs during the window where the client still
1841         # belives the OST to be available but it is in fact down.
1842         # No failure just a statfs which hangs for a timeout interval.
1843         stop_ost || error "Unable to stop OST1"
1844         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
1845
1846         umount_client $MOUNT || error "Unable to unmount client"
1847         stop_ost2 || error "Unable to stop OST2"
1848         stop_mds || error "Unable to stop MDS"
1849 }
1850 run_test 50d "lazystatfs client/server conn race =========================="
1851
1852 test_50e() {
1853         local RC1
1854         local pid
1855
1856         reformat_and_config
1857         start_mds || return 1
1858         #first client should see only one ost
1859         start_ost || return 2
1860         wait_osc_import_state mds ost FULL
1861
1862         # Wait for client to detect down OST
1863         stop_ost || error "Unable to stop OST1"
1864         wait_osc_import_state mds ost DISCONN
1865
1866         mount_client $MOUNT || error "Unable to mount client"
1867         lctl set_param llite.$FSNAME-*.lazystatfs=0
1868
1869         multiop_bg_pause $MOUNT _f
1870         RC1=$?
1871         pid=$!
1872
1873         if [ $RC1 -ne 0 ]; then
1874                 log "multiop failed $RC1"
1875         else
1876             kill -USR1 $pid
1877             sleep $(( $TIMEOUT+1 ))
1878             kill -0 $pid
1879             [ $? -ne 0 ] && error "process isn't sleep"
1880             start_ost || error "Unable to start OST1"
1881             wait $pid || error "statfs failed"
1882         fi
1883
1884         umount_client $MOUNT || error "Unable to unmount client"
1885         stop_ost || error "Unable to stop OST1"
1886         stop_mds || error "Unable to stop MDS"
1887 }
1888 run_test 50e "normal statfs all servers down =========================="
1889
1890 test_50f() {
1891         local RC1
1892         local pid
1893         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
1894
1895         start_mds || error "Unable to start mds"
1896         #first client should see only one ost
1897         start_ost || error "Unable to start OST1"
1898         wait_osc_import_state mds ost FULL
1899
1900         start_ost2 || error "Unable to start OST2"
1901         wait_osc_import_state mds ost2 FULL
1902
1903         # Wait for client to detect down OST
1904         stop_ost2 || error "Unable to stop OST2"
1905
1906         wait_osc_import_state mds ost2 DISCONN
1907         mount_client $MOUNT || error "Unable to mount client"
1908         lctl set_param llite.$FSNAME-*.lazystatfs=0
1909
1910         multiop_bg_pause $MOUNT _f
1911         RC1=$?
1912         pid=$!
1913
1914         if [ $RC1 -ne 0 ]; then
1915                 log "lazystatfs multiop failed $RC1"
1916         else
1917             kill -USR1 $pid
1918             sleep $(( $TIMEOUT+1 ))
1919             kill -0 $pid
1920             [ $? -ne 0 ] && error "process isn't sleep"
1921             start_ost2 || error "Unable to start OST1"
1922             wait $pid || error "statfs failed"
1923         fi
1924
1925         umount_client $MOUNT || error "Unable to unmount client"
1926         stop_ost || error "Unable to stop OST1"
1927         stop_mds || error "Unable to stop MDS"
1928         writeconf
1929 }
1930 run_test 50f "normal statfs one server in down =========================="
1931
1932 test_51() {
1933         local LOCAL_TIMEOUT=20
1934
1935         reformat
1936         start_mds
1937         start_ost
1938         mount_client $MOUNT
1939         check_mount || return 1
1940
1941         mkdir $MOUNT/d1
1942         $LFS setstripe -c -1 $MOUNT/d1
1943         #define OBD_FAIL_MDS_REINT_DELAY         0x142
1944         do_facet $SINGLEMDS "lctl set_param fail_loc=0x142"
1945         touch $MOUNT/d1/f1 &
1946         local pid=$!
1947         sleep 2
1948         start_ost2 || return 2
1949         wait $pid
1950         stop_ost2 || return 3
1951         cleanup
1952 }
1953 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
1954
1955 cleanup_gss
1956 equals_msg `basename $0`: test complete
1957 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG && grep -q FAIL $TESTSUITELOG && exit 1 || true