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