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