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