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