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