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