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