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