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