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