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