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