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