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