Whamcloud - gitweb
LU-2775 osp: enable fid-on-OST only for DNE.
[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 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT"
14 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15
16 is_sles11()                                             # LU-2181
17 {
18         if [ -r /etc/SuSE-release ]
19         then
20                 local vers=`grep VERSION /etc/SuSE-release | awk '{print $3}'`
21                 local patchlev=`grep PATCHLEVEL /etc/SuSE-release \
22                         | awk '{print $3}'`
23                 if [ $vers -eq 11 ] && [ $patchlev -eq 2 ]
24                 then
25                         return 0
26                 fi
27         fi
28         return 1
29 }
30
31 if is_sles11; then                                      # LU-2181
32         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 23a 34b"
33 fi
34
35 if [ "$FAILURE_MODE" = "HARD" ]; then
36         CONFIG_EXCEPTIONS="24a " && \
37         echo "Except the tests: $CONFIG_EXCEPTIONS for FAILURE_MODE=$FAILURE_MODE, bug 23573" && \
38         ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
39 fi
40
41 # bug number for skipped test:
42 # a tool to create lustre filesystem images
43 ALWAYS_EXCEPT="32newtarball $ALWAYS_EXCEPT"
44
45 SRCDIR=`dirname $0`
46 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
47
48 PTLDEBUG=${PTLDEBUG:--1}
49 SAVE_PWD=$PWD
50 LUSTRE=${LUSTRE:-`dirname $0`/..}
51 RLUSTRE=${RLUSTRE:-$LUSTRE}
52 export MULTIOP=${MULTIOP:-multiop}
53
54 . $LUSTRE/tests/test-framework.sh
55 init_test_env $@
56
57 # use small MDS + OST size to speed formatting time
58 # do not use too small MDSSIZE/OSTSIZE, which affect the default jouranl size
59 MDSSIZE=200000
60 OSTSIZE=200000
61 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
62
63 if ! combined_mgs_mds; then
64     # bug number for skipped test:    23954
65     ALWAYS_EXCEPT="$ALWAYS_EXCEPT       24b"
66 fi
67
68 # STORED_MDSSIZE is used in test_18
69 if [ -n "$MDSSIZE" ]; then
70     STORED_MDSSIZE=$MDSSIZE
71 fi
72
73 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
74 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
75         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
76 fi
77
78 init_logging
79
80 #
81 require_dsh_mds || exit 0
82 require_dsh_ost || exit 0
83 #
84 [ "$SLOW" = "no" ] && EXCEPT_SLOW="30a 31 45"
85
86
87 assert_DIR
88
89 gen_config() {
90         # The MGS must be started before the OSTs for a new fs, so start
91         # and stop to generate the startup logs.
92         start_mds
93         start_ost
94         wait_osc_import_state mds ost FULL
95         stop_ost
96         stop_mds
97 }
98
99 reformat_and_config() {
100         reformat
101         if ! combined_mgs_mds ; then
102                 start_mgs
103         fi
104         gen_config
105 }
106
107 writeconf_or_reformat() {
108         # There are at most 2 OSTs for write_conf test
109         # who knows if/where $TUNEFS is installed?
110         # Better reformat if it fails...
111         writeconf_all $MDSCOUNT 2 ||
112                 { echo "tunefs failed, reformatting instead" &&
113                   reformat_and_config && return 1; }
114         return 0
115 }
116
117 reformat() {
118         formatall
119 }
120
121 start_mgs () {
122         echo "start mgs"
123         start mgs $MGSDEV $MGS_MOUNT_OPTS
124 }
125
126 start_mdt() {
127         local num=$1
128         local facet=mds$num
129         local dev=$(mdsdevname $num)
130         shift 1
131
132         echo "start mds service on `facet_active_host $facet`"
133         start $facet ${dev} $MDS_MOUNT_OPTS $@ || return 94
134 }
135
136 stop_mdt() {
137         local num=$1
138         local facet=mds$num
139         local dev=$(mdsdevname $num)
140         shift 1
141
142         echo "stop mds service on `facet_active_host $facet`"
143         # These tests all use non-failover stop
144         stop $facet -f  || return 97
145 }
146
147 start_mds() {
148         local num
149
150         for num in $(seq $MDSCOUNT); do
151                 start_mdt $num $@ || return 94
152         done
153 }
154
155 start_mgsmds() {
156         if ! combined_mgs_mds ; then
157                 start_mgs
158         fi
159         start_mds $@
160 }
161
162 stop_mds() {
163         local num
164         for num in $(seq $MDSCOUNT); do
165                 stop_mdt $num || return 97
166         done
167 }
168
169 stop_mgs() {
170        echo "stop mgs service on `facet_active_host mgs`"
171        # These tests all use non-failover stop
172        stop mgs -f  || return 97
173 }
174
175 start_ost() {
176         echo "start ost1 service on `facet_active_host ost1`"
177         start ost1 `ostdevname 1` $OST_MOUNT_OPTS $@ || return 95
178 }
179
180 stop_ost() {
181         echo "stop ost1 service on `facet_active_host ost1`"
182         # These tests all use non-failover stop
183         stop ost1 -f  || return 98
184 }
185
186 start_ost2() {
187         echo "start ost2 service on `facet_active_host ost2`"
188         start ost2 `ostdevname 2` $OST_MOUNT_OPTS $@ || return 92
189 }
190
191 stop_ost2() {
192         echo "stop ost2 service on `facet_active_host ost2`"
193         # These tests all use non-failover stop
194         stop ost2 -f  || return 93
195 }
196
197 mount_client() {
198         local MOUNTPATH=$1
199         echo "mount $FSNAME on ${MOUNTPATH}....."
200         zconf_mount `hostname` $MOUNTPATH  || return 96
201 }
202
203 remount_client() {
204         local mountopt="-o remount,$1"
205         local MOUNTPATH=$2
206         echo "remount '$1' lustre on ${MOUNTPATH}....."
207         zconf_mount `hostname`  $MOUNTPATH "$mountopt"  || return 96
208 }
209
210 umount_client() {
211         local MOUNTPATH=$1
212         echo "umount lustre on ${MOUNTPATH}....."
213         zconf_umount `hostname` $MOUNTPATH || return 97
214 }
215
216 manual_umount_client(){
217         local rc
218         local FORCE=$1
219         echo "manual umount lustre on ${MOUNT}...."
220         do_facet client "umount -d ${FORCE} $MOUNT"
221         rc=$?
222         return $rc
223 }
224
225 setup() {
226         start_mds || error "MDT start failed"
227         start_ost || error "OST start failed"
228         mount_client $MOUNT || error "client start failed"
229         client_up || error "client_up failed"
230 }
231
232 setup_noconfig() {
233         if ! combined_mgs_mds ; then
234                 start_mgs
235         fi
236
237         start_mds
238         start_ost
239         mount_client $MOUNT
240 }
241
242 unload_modules_conf () {
243         if combined_mgs_mds || ! local_mode; then
244                 unload_modules || return 1
245         fi
246 }
247
248 cleanup_nocli() {
249         stop_ost || return 202
250         stop_mds || return 201
251         unload_modules_conf || return 203
252 }
253
254 cleanup() {
255         umount_client $MOUNT || return 200
256         cleanup_nocli || return $?
257 }
258
259 check_mount() {
260         do_facet client "cp /etc/passwd $DIR/a" || return 71
261         do_facet client "rm $DIR/a" || return 72
262         # make sure lustre is actually mounted (touch will block,
263         # but grep won't, so do it after)
264         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
265         echo "setup single mount lustre success"
266 }
267
268 check_mount2() {
269         do_facet client "touch $DIR/a" || return 71
270         do_facet client "rm $DIR/a" || return 72
271         do_facet client "touch $DIR2/a" || return 73
272         do_facet client "rm $DIR2/a" || return 74
273         echo "setup double mount lustre success"
274 }
275
276 build_test_filter
277
278 if [ "$ONLY" == "setup" ]; then
279         setup
280         exit
281 fi
282
283 if [ "$ONLY" == "cleanup" ]; then
284         cleanup
285         exit
286 fi
287
288 init_gss
289
290 #create single point mountpoint
291
292 reformat_and_config
293
294 test_0() {
295         setup
296         check_mount || return 41
297         cleanup || return $?
298 }
299 run_test 0 "single mount setup"
300
301 test_1() {
302         start_mds || error "MDT start failed"
303         start_ost
304         echo "start ost second time..."
305         start_ost && error "2nd OST start should fail"
306         mount_client $MOUNT || error "client start failed"
307         check_mount || return 42
308         cleanup || return $?
309 }
310 run_test 1 "start up ost twice (should return errors)"
311
312 test_2() {
313         start_mdt 1
314         echo "start mds second time.."
315         start_mdt 1 && error "2nd MDT start should fail"
316         start_ost
317         mount_client $MOUNT
318         check_mount || return 43
319         cleanup || return $?
320 }
321 run_test 2 "start up mds twice (should return err)"
322
323 test_3() {
324         setup
325         #mount.lustre returns an error if already in mtab
326         mount_client $MOUNT && error "2nd client mount should fail"
327         check_mount || return 44
328         cleanup || return $?
329 }
330 run_test 3 "mount client twice (should return err)"
331
332 test_4() {
333         setup
334         touch $DIR/$tfile || return 85
335         stop_ost -f
336         cleanup
337         eno=$?
338         # ok for ost to fail shutdown
339         if [ 202 -ne $eno ]; then
340                 return $eno;
341         fi
342         return 0
343 }
344 run_test 4 "force cleanup ost, then cleanup"
345
346 test_5a() {     # was test_5
347         setup
348         touch $DIR/$tfile || return 1
349         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
350
351         stop_mds -f || return 2
352
353         # cleanup may return an error from the failed
354         # disconnects; for now I'll consider this successful
355         # if all the modules have unloaded.
356         umount -d $MOUNT &
357         UMOUNT_PID=$!
358         sleep 6
359         echo "killing umount"
360         kill -TERM $UMOUNT_PID
361         echo "waiting for umount to finish"
362         wait $UMOUNT_PID
363         if grep " $MOUNT " /proc/mounts; then
364                 echo "test 5: /proc/mounts after failed umount"
365                 umount $MOUNT &
366                 UMOUNT_PID=$!
367                 sleep 2
368                 echo "killing umount"
369                 kill -TERM $UMOUNT_PID
370                 echo "waiting for umount to finish"
371                 wait $UMOUNT_PID
372                 grep " $MOUNT " /proc/mounts && echo "test 5: /proc/mounts after second umount" && return 11
373         fi
374
375         manual_umount_client
376         # stop_mds is a no-op here, and should not fail
377         cleanup_nocli || return $?
378         # df may have lingering entry
379         manual_umount_client
380         # mtab may have lingering entry
381         local WAIT=0
382         local MAX_WAIT=20
383         local sleep=1
384         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
385                 sleep $sleep
386                 grep -q $MOUNT" " /etc/mtab || break
387                 echo "Waiting /etc/mtab updated ... "
388                 WAIT=$(( WAIT + sleep))
389         done
390         [ "$WAIT" -eq "$MAX_WAIT" ] && error "/etc/mtab is not updated in $WAIT secs"
391         echo "/etc/mtab updated in $WAIT secs"
392 }
393 run_test 5a "force cleanup mds, then cleanup"
394
395 cleanup_5b () {
396         trap 0
397         start_mgs
398 }
399
400 test_5b() {
401         grep " $MOUNT " /etc/mtab && \
402                 error false "unexpected entry in mtab before mount" && return 10
403
404         local rc=0
405         start_ost
406         if ! combined_mgs_mds ; then
407                 trap cleanup_5b EXIT ERR
408                 start_mds
409                 stop mgs
410         fi
411
412         [ -d $MOUNT ] || mkdir -p $MOUNT
413         mount_client $MOUNT && rc=1
414         grep " $MOUNT " /etc/mtab && \
415                 error "$MOUNT entry in mtab after failed mount" && rc=11
416         umount_client $MOUNT
417         # stop_mds is a no-op here, and should not fail
418         cleanup_nocli || rc=$?
419         if ! combined_mgs_mds ; then
420                 cleanup_5b
421         fi
422         return $rc
423 }
424 run_test 5b "Try to start a client with no MGS (should return errs)"
425
426 test_5c() {
427         grep " $MOUNT " /etc/mtab && \
428                 error false "unexpected entry in mtab before mount" && return 10
429
430         local rc=0
431         start_mds
432         start_ost
433         [ -d $MOUNT ] || mkdir -p $MOUNT
434         local oldfs="${FSNAME}"
435         FSNAME="wrong.${FSNAME}"
436         mount_client $MOUNT || :
437         FSNAME=${oldfs}
438         grep " $MOUNT " /etc/mtab && \
439                 error "$MOUNT entry in mtab after failed mount" && rc=11
440         umount_client $MOUNT
441         cleanup_nocli  || rc=$?
442         return $rc
443 }
444 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
445
446 test_5d() {
447         grep " $MOUNT " /etc/mtab && \
448                 error false "unexpected entry in mtab before mount" && return 10
449
450         [ "$(facet_fstype ost1)" = "zfs" ] &&
451                 skip "LU-2059: no local config for ZFS OSTs" && return
452
453         local rc=0
454         start_ost
455         start_mds
456         stop_ost -f
457         mount_client $MOUNT || rc=1
458         cleanup  || rc=$?
459         grep " $MOUNT " /etc/mtab && \
460                 error "$MOUNT entry in mtab after unmount" && rc=11
461         return $rc
462 }
463 run_test 5d "mount with ost down"
464
465 test_5e() {
466         grep " $MOUNT " /etc/mtab && \
467                 error false "unexpected entry in mtab before mount" && return 10
468
469         local rc=0
470         start_mds
471         start_ost
472
473 #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
474         do_facet client "lctl set_param fail_loc=0x80000506"
475         mount_client $MOUNT || echo "mount failed (not fatal)"
476         cleanup  || rc=$?
477         grep " $MOUNT " /etc/mtab && \
478                 error "$MOUNT entry in mtab after unmount" && rc=11
479         return $rc
480 }
481 run_test 5e "delayed connect, don't crash (bug 10268)"
482
483 test_5f() {
484         if combined_mgs_mds ; then
485                 skip "combined mgs and mds"
486                 return 0
487         fi
488
489         grep " $MOUNT " /etc/mtab && \
490                 error false "unexpected entry in mtab before mount" && return 10
491
492         local rc=0
493         start_ost
494         [ -d $MOUNT ] || mkdir -p $MOUNT
495         mount_client $MOUNT &
496         local pid=$!
497         echo client_mount pid is $pid
498
499         sleep 5
500
501         if ! ps -f -p $pid >/dev/null; then
502                 wait $pid
503                 rc=$?
504                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
505                 error "mount returns $rc, expected to hang"
506                 rc=11
507                 cleanup || rc=$?
508                 return $rc
509         fi
510
511         # start mds
512         start_mds
513
514         # mount should succeed after start mds
515         wait $pid
516         rc=$?
517         [ $rc -eq 0 ] || error "mount returned $rc"
518         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
519         cleanup || return $?
520         return $rc
521 }
522 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
523
524 test_6() {
525         setup
526         manual_umount_client
527         mount_client ${MOUNT} || return 87
528         touch $DIR/a || return 86
529         cleanup  || return $?
530 }
531 run_test 6 "manual umount, then mount again"
532
533 test_7() {
534         setup
535         manual_umount_client
536         cleanup_nocli || return $?
537 }
538 run_test 7 "manual umount, then cleanup"
539
540 test_8() {
541         setup
542         mount_client $MOUNT2
543         check_mount2 || return 45
544         umount_client $MOUNT2
545         cleanup  || return $?
546 }
547 run_test 8 "double mount setup"
548
549 test_9() {
550         start_ost
551
552         do_facet ost1 lctl set_param debug=\'inode trace\' || return 1
553         do_facet ost1 lctl set_param subsystem_debug=\'mds ost\' || return 1
554
555         CHECK_PTLDEBUG="`do_facet ost1 lctl get_param -n debug`"
556         if [ "$CHECK_PTLDEBUG" ] && { \
557            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
558            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
559            echo "lnet.debug success"
560         else
561            echo "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
562            return 1
563         fi
564         CHECK_SUBSYS="`do_facet ost1 lctl get_param -n subsystem_debug`"
565         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
566            echo "lnet.subsystem_debug success"
567         else
568            echo "lnet.subsystem_debug: want 'mds ost', have '$CHECK_SUBSYS'"
569            return 1
570         fi
571         stop_ost || return $?
572 }
573 run_test 9 "test ptldebug and subsystem for mkfs"
574
575 is_blkdev () {
576         local facet=$1
577         local dev=$2
578         local size=${3:-""}
579
580         local rc=0
581         do_facet $facet "test -b $dev" || rc=1
582         if [[ "$size" ]]; then
583                 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k count=1 skip=$size 2>&1" |\
584                         awk '($3 == "in") { print $1 }')
585                 [[ $in  = "1+0" ]] || rc=1
586         fi
587         return $rc
588 }
589
590 #
591 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
592 # But with new MDS stack we don't care about the mode of local objects
593 # anymore, so this test is removed. See bug 22944 for more details.
594 #
595
596 test_17() {
597         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
598                 skip "Only applicable to ldiskfs-based MDTs"
599                 return
600         fi
601
602         setup
603         check_mount || return 41
604         cleanup || return $?
605
606         echo "Remove mds config log"
607         if ! combined_mgs_mds ; then
608                 stop mgs
609         fi
610
611         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' $MGSDEV || return \$?" || return $?
612
613         if ! combined_mgs_mds ; then
614                 start_mgs
615         fi
616
617         start_ost
618         start_mds && return 42
619         reformat_and_config
620 }
621 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
622
623 test_18() {
624         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
625                 skip "Only applicable to ldiskfs-based MDTs"
626                 return
627         fi
628
629         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
630
631         local MIN=2000000
632
633         local OK=
634         # check if current MDSSIZE is large enough
635         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE && \
636                 log "use MDSSIZE=$MDSSIZE"
637
638         # check if the global config has a large enough MDSSIZE
639         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] && [ $STORED_MDSSIZE -ge $MIN ] && \
640                 OK=1 && myMDSSIZE=$STORED_MDSSIZE && \
641                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
642
643         # check if the block device is large enough
644         is_blkdev $SINGLEMDS $MDSDEV $MIN
645         local large_enough=$?
646         if [ -n "$OK" ]; then
647                 [ $large_enough -ne 0 ] && OK=""
648         else
649                 [ $large_enough -eq 0 ] && OK=1 && myMDSSIZE=$MIN &&
650                         log "use device $MDSDEV with MIN=$MIN"
651         fi
652
653         # check if a loopback device has enough space for fs metadata (5%)
654
655         if [ -z "$OK" ]; then
656                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
657                         awk '($1 != "Filesystem") {print $4}')
658                 ! [ -z "$SPACE" ]  &&  [ $SPACE -gt $((MIN / 20)) ] && \
659                         OK=1 && myMDSSIZE=$MIN && \
660                         log "use file $MDSDEV with MIN=$MIN"
661         fi
662
663         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
664
665
666         echo "mount mds with large journal..."
667
668         local OLD_MDSSIZE=$MDSSIZE
669         MDSSIZE=$myMDSSIZE
670
671         reformat_and_config
672         echo "mount lustre system..."
673         setup
674         check_mount || return 41
675
676         echo "check journal size..."
677         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
678         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
679                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
680         else
681                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
682         fi
683
684         cleanup || return $?
685
686         MDSSIZE=$OLD_MDSSIZE
687         reformat_and_config
688 }
689 run_test 18 "check mkfs creates large journals"
690
691 test_19a() {
692         start_mds || return 1
693         stop_mds -f || return 2
694 }
695 run_test 19a "start/stop MDS without OSTs"
696
697 test_19b() {
698         [ "$(facet_fstype ost1)" = "zfs" ] &&
699                 skip "LU-2059: no local config for ZFS OSTs" && return
700
701         start_ost || return 1
702         stop_ost -f || return 2
703 }
704 run_test 19b "start/stop OSTs without MDS"
705
706 test_20() {
707         # first format the ost/mdt
708         start_mds
709         start_ost
710         mount_client $MOUNT
711         check_mount || return 43
712         rm -f $DIR/$tfile
713         remount_client ro $MOUNT || return 44
714         touch $DIR/$tfile && echo "$DIR/$tfile created incorrectly" && return 45
715         [ -e $DIR/$tfile ] && echo "$DIR/$tfile exists incorrectly" && return 46
716         remount_client rw $MOUNT || return 47
717         touch $DIR/$tfile
718         [ ! -f $DIR/$tfile ] && echo "$DIR/$tfile missing" && return 48
719         MCNT=`grep -c $MOUNT /etc/mtab`
720         [ "$MCNT" -ne 1 ] && echo "$MOUNT in /etc/mtab $MCNT times" && return 49
721         umount_client $MOUNT
722         stop_mds
723         stop_ost
724 }
725 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
726
727 test_21a() {
728         start_mds
729         start_ost
730         wait_osc_import_state mds ost FULL
731         stop_ost
732         stop_mds
733 }
734 run_test 21a "start mds before ost, stop ost first"
735
736 test_21b() {
737         [ "$(facet_fstype ost1)" = "zfs" ] &&
738                 skip "LU-2059: no local config for ZFS OSTs" && return
739
740         start_ost
741         start_mds
742         wait_osc_import_state mds ost FULL
743         stop_mds
744         stop_ost
745 }
746 run_test 21b "start ost before mds, stop mds first"
747
748 test_21c() {
749         start_ost
750         start_mds
751         start_ost2
752         wait_osc_import_state mds ost2 FULL
753         stop_ost
754         stop_ost2
755         stop_mds
756         #writeconf to remove all ost2 traces for subsequent tests
757         writeconf_or_reformat
758 }
759 run_test 21c "start mds between two osts, stop mds last"
760
761 test_21d() {
762         if combined_mgs_mds ; then
763                 skip "need separate mgs device" && return 0
764         fi
765         stopall
766
767         reformat
768
769         start_mgs
770         start_ost
771         start_ost2
772         start_mds
773         wait_osc_import_state mds ost2 FULL
774
775         stop_ost
776         stop_ost2
777         stop_mds
778         stop_mgs
779         #writeconf to remove all ost2 traces for subsequent tests
780         writeconf_or_reformat
781         start_mgs
782 }
783 run_test 21d "start mgs then ost and then mds"
784
785 test_22() {
786         local num
787
788         start_mds
789
790         echo Client mount with ost in logs, but none running
791         start_ost
792         # wait until mds connected to ost and open client connection
793         for num in $(seq 1 $MDSCOUNT); do
794                 wait_osc_import_state mds${num} ost FULL
795         done
796         stop_ost
797         mount_client $MOUNT
798         # check_mount will block trying to contact ost
799         mcreate $DIR/$tfile || return 40
800         rm -f $DIR/$tfile || return 42
801         umount_client $MOUNT
802         pass
803
804         echo Client mount with a running ost
805         start_ost
806         if $GSS; then
807                 # if gss enabled, wait full time to let connection from
808                 # mds to ost be established, due to the mismatch between
809                 # initial connect timeout and gss context negotiation timeout.
810                 # This perhaps could be remove after AT landed.
811                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
812                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
813         fi
814         mount_client $MOUNT
815         for num in $(seq 1 $MDSCOUNT); do
816                 wait_osc_import_state mds${num} ost FULL
817         done
818         wait_osc_import_state client ost FULL
819         check_mount || return 41
820         pass
821
822         cleanup
823 }
824 run_test 22 "start a client before osts (should return errs)"
825
826 test_23a() {    # was test_23
827         setup
828         # fail mds
829         stop $SINGLEMDS
830         # force down client so that recovering mds waits for reconnect
831         local running=$(grep -c $MOUNT /proc/mounts) || true
832         if [ $running -ne 0 ]; then
833                 echo "Stopping client $MOUNT (opts: -f)"
834                 umount -f $MOUNT
835         fi
836
837         # enter recovery on mds
838         start_mds
839         # try to start a new client
840         mount_client $MOUNT &
841         sleep 5
842         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
843         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
844         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
845         ps --ppid $MOUNT_PID
846         ps --ppid $MOUNT_LUSTRE_PID
847         echo "waiting for mount to finish"
848         ps -ef | grep mount
849         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
850         # SIGTERM works but it does not spread to offspring processses
851         kill -s TERM $MOUNT_PID
852         kill -s TERM $MOUNT_LUSTRE_PID
853         # we can not wait $MOUNT_PID because it is not a child of this shell
854         local PID1
855         local PID2
856         local WAIT=0
857         local MAX_WAIT=30
858         local sleep=1
859         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
860                 sleep $sleep
861                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
862                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
863                 echo PID1=$PID1
864                 echo PID2=$PID2
865                 [ -z "$PID1" -a -z "$PID2" ] && break
866                 echo "waiting for mount to finish ... "
867                 WAIT=$(( WAIT + sleep))
868         done
869         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
870                 error "MOUNT_PID $MOUNT_PID and "\
871                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
872                 ps -ef | grep mount
873         fi
874         stop_mds || error
875         stop_ost || error
876 }
877 run_test 23a "interrupt client during recovery mount delay"
878
879 umount_client $MOUNT
880 cleanup_nocli
881
882 test_23b() {    # was test_23
883         start_mds
884         start_ost
885         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
886         lctl set_param fail_loc=0x80000313
887         mount_client $MOUNT
888         cleanup
889 }
890 run_test 23b "Simulate -EINTR during mount"
891
892 fs2mds_HOST=$mds_HOST
893 fs2ost_HOST=$ost_HOST
894
895 MDSDEV1_2=$fs2mds_DEV
896 OSTDEV1_2=$fs2ost_DEV
897 OSTDEV2_2=$fs3ost_DEV
898
899 cleanup_24a() {
900         trap 0
901         echo "umount $MOUNT2 ..."
902         umount $MOUNT2 || true
903         echo "stopping fs2mds ..."
904         stop fs2mds -f || true
905         echo "stopping fs2ost ..."
906         stop fs2ost -f || true
907 }
908
909 test_24a() {
910         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
911
912         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
913                 is_blkdev $SINGLEMDS $MDSDEV && \
914                 skip_env "mixed loopback and real device not working" && return
915         fi
916
917         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
918
919         local fs2mdsdev=$(mdsdevname 1_2)
920         local fs2ostdev=$(ostdevname 1_2)
921         local fs2mdsvdev=$(mdsvdevname 1_2)
922         local fs2ostvdev=$(ostvdevname 1_2)
923
924         # test 8-char fsname as well
925         local FSNAME2=test1234
926
927         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --nomgs --mgsnode=$MGSNID \
928                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
929
930         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --fsname=${FSNAME2} \
931                 --reformat $fs2ostdev $fs2ostvdev || exit 10
932
933         setup
934         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
935         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
936         mkdir -p $MOUNT2
937         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
938         # 1 still works
939         check_mount || return 2
940         # files written on 1 should not show up on 2
941         cp /etc/passwd $DIR/$tfile
942         sleep 10
943         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
944         # 2 should work
945         sleep 5
946         cp /etc/passwd $MOUNT2/b || return 3
947         rm $MOUNT2/b || return 4
948         # 2 is actually mounted
949         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
950         # failover
951         facet_failover fs2mds
952         facet_failover fs2ost
953         df
954         umount_client $MOUNT
955         # the MDS must remain up until last MDT
956         stop_mds
957         MDS=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
958         [ -z "$MDS" ] && error "No MDT" && return 8
959         cleanup_24a
960         cleanup_nocli || return 6
961 }
962 run_test 24a "Multiple MDTs on a single node"
963
964 test_24b() {
965         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
966
967         if [ -z "$fs2mds_DEV" ]; then
968                 local dev=${SINGLEMDS}_dev
969                 local MDSDEV=${!dev}
970                 is_blkdev $SINGLEMDS $MDSDEV && \
971                 skip_env "mixed loopback and real device not working" && return
972         fi
973
974         local fs2mdsdev=$(mdsdevname 1_2)
975         local fs2mdsvdev=$(mdsvdevname 1_2)
976
977         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --mgs --fsname=${FSNAME}2 \
978                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
979         setup
980         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
981         cleanup || return 6
982 }
983 run_test 24b "Multiple MGSs on a single node (should return err)"
984
985 test_25() {
986         setup
987         check_mount || return 2
988         local MODULES=$($LCTL modules | awk '{ print $2 }')
989         rmmod $MODULES 2>/dev/null || true
990         cleanup || return 6
991 }
992 run_test 25 "Verify modules are referenced"
993
994 test_26() {
995     load_modules
996     # we need modules before mount for sysctl, so make sure...
997     do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
998 #define OBD_FAIL_MDS_FS_SETUP            0x135
999     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000135"
1000     start_mds && echo MDS started && return 1
1001     lctl get_param -n devices
1002     DEVS=$(lctl get_param -n devices | egrep -v MG | wc -l)
1003     [ $DEVS -gt 0 ] && return 2
1004     # start mds to drop writeconf setting
1005     start_mds || return 3
1006     stop_mds || return 4
1007     unload_modules_conf || return $?
1008 }
1009 run_test 26 "MDT startup failure cleans LOV (should return errs)"
1010
1011 test_27a() {
1012         [ "$(facet_fstype ost1)" = "zfs" ] &&
1013                 skip "LU-2059: no local config for ZFS OSTs" && return
1014
1015         start_ost || return 1
1016         start_mds || return 2
1017         echo "Requeue thread should have started: "
1018         ps -e | grep ll_cfg_requeue
1019         set_conf_param_and_check ost1                                         \
1020            "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" \
1021            "$FSNAME-OST0000.ost.client_cache_seconds" || return 3
1022         cleanup_nocli
1023 }
1024 run_test 27a "Reacquire MGS lock if OST started first"
1025
1026 test_27b() {
1027         # FIXME. ~grev
1028         setup
1029         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" |
1030                         awk '($3 ~ "mdt" && $4 ~ "MDT0000") { print $4 }')
1031
1032         facet_failover $SINGLEMDS
1033         set_conf_param_and_check $SINGLEMDS                             \
1034                 "lctl get_param -n mdt.$device.identity_acquire_expire" \
1035                 "$device.mdt.identity_acquire_expire" || return 3
1036         set_conf_param_and_check client                                 \
1037                 "lctl get_param -n mdc.$device-mdc-*.max_rpcs_in_flight"\
1038                 "$device.mdc.max_rpcs_in_flight" || return 4
1039         check_mount
1040         cleanup
1041 }
1042 run_test 27b "Reacquire MGS lock after failover"
1043
1044 test_28() {
1045         setup
1046         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1047         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1048         ORIG=$($TEST)
1049         FINAL=$(($ORIG + 1))
1050         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 3
1051         FINAL=$(($FINAL + 1))
1052         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 4
1053         umount_client $MOUNT || return 200
1054         mount_client $MOUNT
1055         RESULT=$($TEST)
1056         if [ $RESULT -ne $FINAL ]; then
1057             echo "New config not seen: wanted $FINAL got $RESULT"
1058             return 4
1059         else
1060             echo "New config success: got $RESULT"
1061         fi
1062         set_conf_param_and_check client "$TEST" "$PARAM" $ORIG || return 5
1063         cleanup
1064 }
1065 run_test 28 "permanent parameter setting"
1066
1067 test_29() {
1068         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
1069         setup > /dev/null 2>&1
1070         start_ost2
1071         sleep 10
1072
1073         local PARAM="$FSNAME-OST0001.osc.active"
1074         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
1075         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1076
1077         ACTV=$(lctl get_param -n $PROC_ACT)
1078         DEAC=$((1 - $ACTV))
1079         set_conf_param_and_check client \
1080                 "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
1081         # also check ost_server_uuid status
1082         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
1083         if [ -z "$RESULT" ]; then
1084             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
1085             return 3
1086         else
1087             echo "Live client success: got $RESULT"
1088         fi
1089
1090         # check MDTs too
1091         for num in $(seq $MDSCOUNT); do
1092                 local mdtosc=$(get_mdtosc_proc_path mds${num} $FSNAME-OST0001)
1093                 local MPROC="osc.$mdtosc.active"
1094                 local MAX=30
1095                 local WAIT=0
1096                 while [ 1 ]; do
1097                         sleep 5
1098                         RESULT=$(do_facet mds${num} " lctl get_param -n $MPROC")
1099                         [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
1100                         if [ $RESULT -eq $DEAC ]; then
1101                                 echo -n "MDT deactivated also after"
1102                                 echo "$WAIT sec (got $RESULT)"
1103                                 break
1104                         fi
1105                         WAIT=$((WAIT + 5))
1106                         if [ $WAIT -eq $MAX ]; then
1107                                 echo -n "MDT not deactivated: wanted $DEAC"
1108                                 echo  "got $RESULT"
1109                                 return 4
1110                         fi
1111                         echo "Waiting $(($MAX - $WAIT))secs for MDT deactivated"
1112                 done
1113         done
1114         # test new client starts deactivated
1115         umount_client $MOUNT || return 200
1116         mount_client $MOUNT
1117         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1118         if [ -z "$RESULT" ]; then
1119             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
1120             return 5
1121         else
1122             echo "New client success: got $RESULT"
1123         fi
1124
1125         # make sure it reactivates
1126         set_conf_param_and_check client \
1127                 "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
1128
1129         umount_client $MOUNT
1130         stop_ost2
1131         cleanup_nocli
1132         #writeconf to remove all ost2 traces for subsequent tests
1133         writeconf_or_reformat
1134 }
1135 run_test 29 "permanently remove an OST"
1136
1137 test_30a() {
1138         setup
1139
1140         echo Big config llog
1141         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1142         ORIG=$($TEST)
1143         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1144         for i in ${LIST[@]}; do
1145                 set_conf_param_and_check client "$TEST" \
1146                         "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
1147         done
1148         # make sure client restart still works
1149         umount_client $MOUNT
1150         mount_client $MOUNT || return 4
1151         [ "$($TEST)" -ne "$i" ] && error "Param didn't stick across restart $($TEST) != $i"
1152         pass
1153
1154         echo Erase parameter setting
1155         do_facet mgs "$LCTL conf_param -d $FSNAME.llite.max_read_ahead_whole_mb" || return 6
1156         umount_client $MOUNT
1157         mount_client $MOUNT || return 6
1158         FINAL=$($TEST)
1159         echo "deleted (default) value=$FINAL, orig=$ORIG"
1160         # assumes this parameter started at the default value
1161         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1162
1163         cleanup
1164 }
1165 run_test 30a "Big config llog and conf_param deletion"
1166
1167 test_30b() {
1168         setup
1169
1170         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1171         # numerical part of it. Hopefully that's not already a failover address for
1172         # the server.
1173         OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
1174         ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1175         NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1176         NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1177         echo "Using fake nid $NEW"
1178
1179         TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1180         set_conf_param_and_check client "$TEST" \
1181                 "$FSNAME-OST0000.failover.node" $NEW ||
1182                 error "didn't add failover nid $NEW"
1183         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1184         echo $NIDS
1185         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1186         echo "should have 2 failover nids: $NIDCOUNT"
1187         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1188         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" || error "conf_param delete failed"
1189         umount_client $MOUNT
1190         mount_client $MOUNT || return 3
1191
1192         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1193         echo $NIDS
1194         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1195         echo "only 1 final nid should remain: $NIDCOUNT"
1196         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1197
1198         cleanup
1199 }
1200 run_test 30b "Remove failover nids"
1201
1202 test_31() { # bug 10734
1203         # ipaddr must not exist
1204         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
1205         cleanup
1206 }
1207 run_test 31 "Connect to non-existent node (shouldn't crash)"
1208
1209 #
1210 # This is not really a test but a tool to create new disk
1211 # image tarballs for the upgrade tests.
1212 #
1213 # Disk image tarballs should be created on single-node
1214 # clusters by running this test with default configurations
1215 # plus a few mandatory environment settings that are verified
1216 # at the beginning of the test.
1217 #
1218 test_32newtarball() {
1219         local version
1220         local dst=.
1221         local src=/etc/rc.d
1222         local tmp=$TMP/t32_image_create
1223
1224         if [ $FSNAME != t32fs -o $MDSCOUNT -ne 1 -o                                                             \
1225                  \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o $OSTCOUNT -ne 1 -o                      \
1226                  -z "$OSTDEV1" ]; then
1227                 error "Needs FSNAME=t32fs MDSCOUNT=1 MDSDEV1=<nonexistent_file>"        \
1228                           "(or MDSDEV, in the case of b1_8) OSTCOUNT=1"                                 \
1229                           "OSTDEV1=<nonexistent_file>"
1230         fi
1231
1232         mkdir $tmp || {
1233                 echo "Found stale $tmp"
1234                 return 1
1235         }
1236
1237         mkdir $tmp/src
1238         tar cf - -C $src . | tar xf - -C $tmp/src
1239
1240         formatall
1241
1242         setupall
1243         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1244         stopall
1245
1246         mkdir $tmp/img
1247
1248         setupall
1249         pushd /mnt/$FSNAME
1250         ls -Rni --time-style=+%s >$tmp/img/list
1251         find . ! -name .lustre -type f -exec sha1sum {} \; |
1252                 sort -k 2 >$tmp/img/sha1sums
1253         popd
1254         $LCTL get_param -n version | head -n 1 |
1255                 sed -e 's/^lustre: *//' >$tmp/img/commit
1256         stopall
1257
1258         pushd $tmp/src
1259         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1260         popd
1261
1262         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1263                 echo "Data verification failed"
1264         fi
1265
1266         uname -r >$tmp/img/kernel
1267         uname -m >$tmp/img/arch
1268
1269         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1270         mv $OSTDEV1 $tmp/img
1271
1272         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1273                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1274         dst=$(cd $dst; pwd)
1275         pushd $tmp/img
1276         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1277         popd
1278
1279         rm -r $tmp
1280 }
1281 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1282
1283 #
1284 # The list of applicable tarballs is returned via the caller's
1285 # variable "tarballs".
1286 #
1287 t32_check() {
1288         local node=$(facet_active_host $SINGLEMDS)
1289         local r="do_node $node"
1290
1291         if [ "$CLIENTONLY" ]; then
1292                 skip "Client-only testing"
1293                 exit 0
1294         fi
1295
1296         if ! $r which $TUNEFS; then
1297                 skip_env "tunefs.lustre required on $node"
1298                 exit 0
1299         fi
1300
1301         if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1302                 skip "LU-2200: Test cannot run over Infiniband"
1303                 exit 0
1304         fi
1305
1306         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1307
1308         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 -name \'disk*-$IMGTYPE.tar.bz2\')
1309
1310         if [ -z "$tarballs" ]; then
1311                 skip "No applicable tarballs found"
1312                 exit 0
1313         fi
1314 }
1315
1316 t32_test_cleanup() {
1317         local node=$(facet_active_host $SINGLEMDS)
1318         local r="do_node $node"
1319         local tmp=$TMP/t32
1320         local rc=$?
1321
1322         if $shall_cleanup_lustre; then
1323                 umount $tmp/mnt/lustre || rc=$?
1324         fi
1325         if $shall_cleanup_mdt; then
1326                 $r umount -d $tmp/mnt/mdt || rc=$?
1327         fi
1328         if $shall_cleanup_mdt1; then
1329                 $r umount -d $tmp/mnt/mdt1 || rc=$?
1330         fi
1331         if $shall_cleanup_ost; then
1332                 $r umount -d $tmp/mnt/ost || rc=$?
1333         fi
1334         $r rm -rf $tmp || rc=$?
1335         rm -rf $tmp || rc=$?
1336         return $rc
1337 }
1338
1339 t32_bits_per_long() {
1340         #
1341         # Yes, this is not meant to be perfect.
1342         #
1343         case $1 in
1344                 ppc64|x86_64)
1345                         echo -n 64;;
1346                 i*86)
1347                         echo -n 32;;
1348         esac
1349 }
1350
1351 t32_reload_modules() {
1352         local node=$1
1353         local all_removed=false
1354         local i=0
1355
1356         while ((i < 20)); do
1357                 echo "Unloading modules on $node: Attempt $i"
1358                 do_rpc_nodes $node $LUSTRE_RMMOD $(facet_fstype $SINGLEMDS) &&
1359                         all_removed=true
1360                 do_rpc_nodes $node check_mem_leak || return 1
1361                 if $all_removed; then
1362                         load_modules
1363                         return 0
1364                 fi
1365                 sleep 5
1366                 i=$((i + 1))
1367         done
1368         echo "Unloading modules on $node: Given up"
1369         return 1
1370 }
1371
1372 t32_wait_til_devices_gone() {
1373         local node=$1
1374         local devices
1375         local i=0
1376
1377         echo wait for devices to go
1378         while ((i < 20)); do
1379                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1380                 echo $device
1381                 ((devices == 0)) && return 1
1382                 sleep 5
1383                 i=$((i + 1))
1384         done
1385         echo "waiting for devices on $node: Given up"
1386         return 1
1387 }
1388
1389 t32_test() {
1390         local tarball=$1
1391         local writeconf=$2
1392         local dne_upgrade=${dne_upgrade:-"no"}
1393         local shall_cleanup_mdt=false
1394         local shall_cleanup_mdt1=false
1395         local shall_cleanup_ost=false
1396         local shall_cleanup_lustre=false
1397         local node=$(facet_active_host $SINGLEMDS)
1398         local r="do_node $node"
1399         local node2=$(facet_active_host mds2)
1400         local r2="do_node $node2"
1401         local tmp=$TMP/t32
1402         local img_commit
1403         local img_kernel
1404         local img_arch
1405         local fsname=t32fs
1406         local nid=$($r $LCTL list_nids | head -1)
1407         local mopts
1408         local uuid
1409         local nrpcs_orig
1410         local nrpcs
1411         local list
1412
1413         trap 'trap - RETURN; t32_test_cleanup' RETURN
1414
1415         mkdir -p $tmp/mnt/lustre
1416         $r mkdir -p $tmp/mnt/{mdt,ost}
1417         $r tar xjvf $tarball -S -C $tmp || {
1418                 error_noexit "Unpacking the disk image tarball"
1419                 return 1
1420         }
1421         img_commit=$($r cat $tmp/commit)
1422         img_kernel=$($r cat $tmp/kernel)
1423         img_arch=$($r cat $tmp/arch)
1424         echo "Upgrading from $(basename $tarball), created with:"
1425         echo "  Commit: $img_commit"
1426         echo "  Kernel: $img_kernel"
1427         echo "    Arch: $img_arch"
1428
1429         $r $LCTL set_param debug="$PTLDEBUG"
1430
1431         $r $TUNEFS --dryrun $tmp/mdt || {
1432                 error_noexit "tunefs.lustre before mounting the MDT"
1433                 return 1
1434         }
1435         if [ "$writeconf" ]; then
1436                 mopts=loop,writeconf
1437         else
1438                 mopts=loop,exclude=$fsname-OST0000
1439         fi
1440
1441         t32_wait_til_devices_gone $node
1442
1443         $r mount -t lustre -o $mopts $tmp/mdt $tmp/mnt/mdt || {
1444                 error_noexit "Mounting the MDT"
1445                 return 1
1446         }
1447         shall_cleanup_mdt=true
1448
1449         if [ "$dne_upgrade" != "no" ]; then
1450                 echo "mkfs new MDT...."
1451                 add mds2 $(mkfs_opts mds2 $(mdsdevname 2) $fsname) --reformat \
1452                         $(mdsdevname 2) $(mdsvdevname 2) > /dev/null || {
1453                         error_noexit "Mkfs new MDT failed"
1454                         return 1
1455                 }
1456
1457                 $r2 $TUNEFS --dryrun $(mdsdevname 2) || {
1458                         error_noexit "tunefs.lustre before mounting the MDT"
1459                         return 1
1460                 }
1461
1462                 echo "mount new MDT...."
1463                 $r2 mkdir -p $tmp/mnt/mdt1
1464                 $r2 mount -t lustre -o $mopts $(mdsdevname 2) $tmp/mnt/mdt1 || {
1465                         error_noexit "mount mdt1 failed"
1466                         return 1
1467                 }
1468                 shall_cleanup_mdt1=true
1469         fi
1470
1471         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1472                 error_noexit "Getting MDT UUID"
1473                 return 1
1474         }
1475         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1476                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1477                 return 1
1478         fi
1479
1480         $r $TUNEFS --dryrun $tmp/ost || {
1481                 error_noexit "tunefs.lustre before mounting the OST"
1482                 return 1
1483         }
1484         if [ "$writeconf" ]; then
1485                 mopts=loop,mgsnode=$nid,$writeconf
1486         else
1487                 mopts=loop,mgsnode=$nid
1488         fi
1489         $r mount -t lustre -o $mopts $tmp/ost $tmp/mnt/ost || {
1490                 error_noexit "Mounting the OST"
1491                 return 1
1492         }
1493         shall_cleanup_ost=true
1494
1495         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1496                 error_noexit "Getting OST UUID"
1497                 return 1
1498         }
1499         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1500                 error_noexit "Unexpected OST UUID: \"$uuid\""
1501                 return 1
1502         fi
1503
1504         $r $LCTL conf_param $fsname-OST0000.osc.max_dirty_mb=15 || {
1505                 error_noexit "Setting \"max_dirty_mb\""
1506                 return 1
1507         }
1508         $r $LCTL conf_param $fsname-OST0000.failover.node=$nid || {
1509                 error_noexit "Setting OST \"failover.node\""
1510                 return 1
1511         }
1512         $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1513                 error_noexit "Setting \"max_rpcs_in_flight\""
1514                 return 1
1515         }
1516         $r $LCTL conf_param $fsname-MDT0000.failover.node=$nid || {
1517                 error_noexit "Setting MDT \"failover.node\""
1518                 return 1
1519         }
1520         $r $LCTL pool_new $fsname.interop || {
1521                 error_noexit "Setting \"interop\""
1522                 return 1
1523         }
1524         $r $LCTL conf_param $fsname-MDT0000.lov.stripesize=4M || {
1525                 error_noexit "Setting \"lov.stripesize\""
1526                 return 1
1527         }
1528
1529         if [ "$dne_upgrade" != "no" ]; then
1530                 $r2 $LCTL conf_param \
1531                                 $fsname-MDT0001.mdc.max_rpcs_in_flight=9 || {
1532                         error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
1533                         return 1
1534                 }
1535                 $r2 $LCTL conf_param $fsname-MDT0001.failover.node=$nid || {
1536                         error_noexit "Setting MDT1 \"failover.node\""
1537                         return 1
1538                 }
1539                 $r2 $LCTL conf_param $fsname-MDT0001.lov.stripesize=4M || {
1540                         error_noexit "Setting MDT1 \"lov.stripesize\""
1541                         return 1
1542                 }
1543
1544         fi
1545
1546         if [ "$writeconf" ]; then
1547                 mount -t lustre $nid:/$fsname $tmp/mnt/lustre || {
1548                         error_noexit "Mounting the client"
1549                         return 1
1550                 }
1551                 shall_cleanup_lustre=true
1552                 $LCTL set_param debug="$PTLDEBUG"
1553                 if [ "$dne_upgrade" != "no" ]; then
1554                         $LFS mkdir -i 1 $tmp/mnt/lustre/remote_dir || {
1555                                 error_noexit "set remote dir failed"
1556                                 return 1
1557                         }
1558
1559                         pushd $tmp/mnt/lustre
1560                         tar -cf - . --exclude=./remote_dir |
1561                                 tar -xvf - -C remote_dir 1>/dev/null || {
1562                                 error_noexit "cp to remote dir failed"
1563                                 return 1
1564                         }
1565                         popd
1566                 fi
1567
1568                 dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
1569                         error_noexit "dd failed"
1570                         return 1
1571                 }
1572                 rm -rf $tmp/mnt/lustre/tmp_file || {
1573                         error_noexit "rm failed"
1574                         return 1
1575                 }
1576
1577                 if $r test -f $tmp/sha1sums; then
1578                         # LU-2393 - do both sorts on same node to ensure locale
1579                         # is identical
1580                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
1581                         if [ "$dne_upgrade" != "no" ]; then
1582                                 pushd $tmp/mnt/lustre/remote_dir
1583                         else
1584                                 pushd $tmp/mnt/lustre
1585                         fi
1586
1587                         find ! -name .lustre -type f -exec sha1sum {} \; |
1588                                 sort -k 2 >$tmp/sha1sums || {
1589                                 error_noexit "sha1sum"
1590                                 return 1
1591                         }
1592                         popd
1593                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
1594                                 error_noexit "sha1sum verification failed"
1595                                 return 1
1596                         fi
1597                 else
1598                         echo "sha1sum verification skipped"
1599                 fi
1600
1601                 if [ "$dne_upgrade" != "no" ]; then
1602                         rm -rf $tmp/mnt/lustre/remote_dir || {
1603                                 error_noexit "remove remote dir failed"
1604                                 return 1
1605                         }
1606                 fi
1607
1608                 if $r test -f $tmp/list; then
1609                         #
1610                         # There is not a Test Framework API to copy files to or
1611                         # from a remote node.
1612                         #
1613                         # LU-2393 - do both sorts on same node to ensure locale
1614                         # is identical
1615                         $r cat $tmp/list | sort -k 6 >$tmp/list.orig
1616                         pushd $tmp/mnt/lustre
1617                         ls -Rni --time-style=+%s | sort -k 6 >$tmp/list || {
1618                                 error_noexit "ls"
1619                                 return 1
1620                         }
1621                         popd
1622                         #
1623                         # 32-bit and 64-bit clients use different algorithms to
1624                         # convert FIDs into inode numbers.  Hence, remove the inode
1625                         # numbers from the lists, if the original list was created
1626                         # on an architecture with different number of bits per
1627                         # "long".
1628                         #
1629                         if [ $(t32_bits_per_long $(uname -m)) !=                                                \
1630                                  $(t32_bits_per_long $img_arch) ]; then
1631                                 echo "Different number of bits per \"long\" from the disk image"
1632                                 for list in list.orig list; do
1633                                         sed -i -e 's/^[0-9]\+[ \t]\+//' $tmp/$list
1634                                 done
1635                         fi
1636                         if ! diff -ub $tmp/list.orig $tmp/list; then
1637                                 error_noexit "list verification failed"
1638                                 return 1
1639                         fi
1640                 else
1641                         echo "list verification skipped"
1642                 fi
1643
1644                 #
1645                 # When adding new data verification tests, please check for
1646                 # the presence of the required reference files first, like
1647                 # the "sha1sums" and "list" tests above, to avoid the need to
1648                 # regenerate every image for each test addition.
1649                 #
1650
1651                 nrpcs_orig=$($LCTL get_param \
1652                                 -n mdc.*MDT0000*.max_rpcs_in_flight) || {
1653                         error_noexit "Getting \"max_rpcs_in_flight\""
1654                         return 1
1655                 }
1656                 nrpcs=$((nrpcs_orig + 5))
1657                 $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=$nrpcs || {
1658                         error_noexit "Changing \"max_rpcs_in_flight\""
1659                         return 1
1660                 }
1661                 wait_update $HOSTNAME "$LCTL get_param \
1662                         -n mdc.*MDT0000*.max_rpcs_in_flight" $nrpcs || {
1663                         error_noexit "Verifying \"max_rpcs_in_flight\""
1664                         return 1
1665                 }
1666
1667                 umount $tmp/mnt/lustre || {
1668                         error_noexit "Unmounting the client"
1669                         return 1
1670                 }
1671                 shall_cleanup_lustre=false
1672         else
1673                 $r umount -d $tmp/mnt/mdt || {
1674                         error_noexit "Unmounting the MDT"
1675                         return 1
1676                 }
1677                 shall_cleanup_mdt=false
1678                 $r umount -d $tmp/mnt/ost || {
1679                         error_noexit "Unmounting the OST"
1680                         return 1
1681                 }
1682                 shall_cleanup_ost=false
1683
1684                 t32_reload_modules $node || {
1685                         error_noexit "Reloading modules"
1686                         return 1
1687                 }
1688
1689                 # mount a second time to make sure we didnt leave upgrade flag on
1690                 $r $TUNEFS --dryrun $tmp/mdt || {
1691                         error_noexit "tunefs.lustre before remounting the MDT"
1692                         return 1
1693                 }
1694                 $r mount -t lustre -o loop,exclude=$fsname-OST0000 $tmp/mdt                     \
1695                                  $tmp/mnt/mdt || {
1696                         error_noexit "Remounting the MDT"
1697                         return 1
1698                 }
1699                 shall_cleanup_mdt=true
1700         fi
1701 }
1702
1703 test_32a() {
1704         local tarballs
1705         local tarball
1706         local rc=0
1707
1708         t32_check
1709         for tarball in $tarballs; do
1710                 t32_test $tarball || rc=$?
1711         done
1712         return $rc
1713 }
1714 run_test 32a "Upgrade (not live)"
1715
1716 test_32b() {
1717         local tarballs
1718         local tarball
1719         local rc=0
1720
1721         t32_check
1722         for tarball in $tarballs; do
1723                 t32_test $tarball writeconf || rc=$?
1724         done
1725         return $rc
1726 }
1727 run_test 32b "Upgrade with writeconf"
1728
1729 test_32c() {
1730         local tarballs
1731         local tarball
1732         local rc=0
1733
1734         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
1735         t32_check
1736         for tarball in $tarballs; do
1737                 dne_upgrade=yes t32_test $tarball writeconf || rc=$?
1738         done
1739         return $rc
1740 }
1741 run_test 32c "dne upgrade test"
1742
1743 test_33a() { # bug 12333, was test_33
1744         local rc=0
1745         local FSNAME2=test-123
1746         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1747         local mkfsoptions
1748
1749         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1750
1751         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1752                 local dev=${SINGLEMDS}_dev
1753                 local MDSDEV=${!dev}
1754                 is_blkdev $SINGLEMDS $MDSDEV && \
1755                 skip_env "mixed loopback and real device not working" && return
1756         fi
1757
1758         local fs2mdsdev=$(mdsdevname 1_2)
1759         local fs2ostdev=$(ostdevname 1_2)
1760         local fs2mdsvdev=$(mdsvdevname 1_2)
1761         local fs2ostvdev=$(ostvdevname 1_2)
1762
1763         if [ $(facet_fstype mds1) == ldiskfs ]; then
1764                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
1765         fi
1766
1767         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
1768                 --reformat $mkfsoptions $fs2mdsdev $fs2mdsvdev || exit 10
1769         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
1770                 --fsname=${FSNAME2} --index=8191 --reformat $fs2ostdev \
1771                 $fs2ostvdev || exit 10
1772
1773         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1774         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1775         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1776         mkdir -p $MOUNT2
1777         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1778         echo "ok."
1779
1780         cp /etc/hosts $MOUNT2/ || rc=3
1781         $LFS getstripe $MOUNT2/hosts
1782
1783         umount -d $MOUNT2
1784         stop fs2ost -f
1785         stop fs2mds -f
1786         cleanup_nocli || rc=6
1787         return $rc
1788 }
1789 run_test 33a "Mount ost with a large index number"
1790
1791 test_33b() {    # was test_34
1792         setup
1793
1794         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1795         # Drop lock cancelation reply during umount
1796         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
1797         do_facet client lctl set_param fail_loc=0x80000304
1798         #lctl set_param debug=-1
1799         umount_client $MOUNT
1800         cleanup
1801 }
1802 run_test 33b "Drop cancel during umount"
1803
1804 test_34a() {
1805         setup
1806         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
1807         manual_umount_client
1808         rc=$?
1809         do_facet client killall -USR1 multiop
1810         if [ $rc -eq 0 ]; then
1811                 error "umount not fail!"
1812         fi
1813         sleep 1
1814         cleanup
1815 }
1816 run_test 34a "umount with opened file should be fail"
1817
1818
1819 test_34b() {
1820         setup
1821         touch $DIR/$tfile || return 1
1822         stop_mds --force || return 2
1823
1824         manual_umount_client --force
1825         rc=$?
1826         if [ $rc -ne 0 ]; then
1827                 error "mtab after failed umount - rc $rc"
1828         fi
1829
1830         cleanup
1831         return 0
1832 }
1833 run_test 34b "force umount with failed mds should be normal"
1834
1835 test_34c() {
1836         setup
1837         touch $DIR/$tfile || return 1
1838         stop_ost --force || return 2
1839
1840         manual_umount_client --force
1841         rc=$?
1842         if [ $rc -ne 0 ]; then
1843                 error "mtab after failed umount - rc $rc"
1844         fi
1845
1846         cleanup
1847         return 0
1848 }
1849 run_test 34c "force umount with failed ost should be normal"
1850
1851 test_35a() { # bug 12459
1852         setup
1853
1854         DBG_SAVE="`lctl get_param -n debug`"
1855         lctl set_param debug="ha"
1856
1857         log "Set up a fake failnode for the MDS"
1858         FAKENID="127.0.0.2"
1859         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1860         do_facet mgs "$LCTL conf_param ${device}.failover.node=" \
1861                 "$(h2$NETTYPE $FAKENID)" || return 4
1862
1863         log "Wait for RECONNECT_INTERVAL seconds (10s)"
1864         sleep 10
1865
1866         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
1867         $LCTL clear
1868         log "$MSG"
1869         log "Stopping the MDT: $device"
1870         stop_mdt 1 || return 5
1871
1872         df $MOUNT > /dev/null 2>&1 &
1873         DFPID=$!
1874         log "Restarting the MDT: $device"
1875         start_mdt 1 || return 6
1876         log "Wait for df ($DFPID) ... "
1877         wait $DFPID
1878         log "done"
1879         lctl set_param debug="$DBG_SAVE"
1880
1881         # retrieve from the log the first server that the client tried to
1882         # contact after the connection loss
1883         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1884         NEXTCONN=`awk "/${MSG}/ {start = 1;}
1885                        /import_select_connection.*$device-mdc.* using connection/ {
1886                                 if (start) {
1887                                         if (\\\$NF ~ /$FAKENID/)
1888                                                 print \\\$NF;
1889                                         else
1890                                                 print 0;
1891                                         exit;
1892                                 }
1893                        }" $TMP/lustre-log-$TESTNAME.log`
1894         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
1895         cleanup
1896         # remove nid settings
1897         writeconf_or_reformat
1898 }
1899 run_test 35a "Reconnect to the last active server first"
1900
1901 test_35b() { # bug 18674
1902         remote_mds || { skip "local MDS" && return 0; }
1903         setup
1904
1905         debugsave
1906         $LCTL set_param debug="ha"
1907         $LCTL clear
1908         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
1909         log "$MSG"
1910
1911         log "Set up a fake failnode for the MDS"
1912         FAKENID="127.0.0.2"
1913         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" | \
1914                         awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1915         do_facet mgs "$LCTL conf_param ${device}.failover.node=" \
1916                 "$(h2$NETTYPE $FAKENID)" || return 1
1917
1918         local at_max_saved=0
1919         # adaptive timeouts may prevent seeing the issue
1920         if at_is_enabled; then
1921                 at_max_saved=$(at_max_get mds)
1922                 at_max_set 0 mds client
1923         fi
1924
1925         mkdir -p $MOUNT/$tdir
1926
1927         log "Injecting EBUSY on MDS"
1928         # Setting OBD_FAIL_MDS_RESEND=0x136
1929         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" || return 2
1930
1931         $LCTL set_param mdc.${FSNAME}*.stats=clear
1932
1933         log "Creating a test file and stat it"
1934         touch $MOUNT/$tdir/$tfile
1935         stat $MOUNT/$tdir/$tfile
1936
1937         log "Stop injecting EBUSY on MDS"
1938         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" || return 3
1939         rm -f $MOUNT/$tdir/$tfile
1940
1941         log "done"
1942         # restore adaptive timeout
1943         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
1944
1945         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1946
1947         CONNCNT=`$LCTL get_param mdc.${FSNAME}*.stats | awk '/mds_connect/{print $2}'`
1948
1949         # retrieve from the log if the client has ever tried to
1950         # contact the fake server after the loss of connection
1951         FAILCONN=`awk "BEGIN {ret = 0;}
1952                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
1953                                 ret = 1;
1954                                 if (\\\$NF ~ /$FAKENID/) {
1955                                         ret = 2;
1956                                         exit;
1957                                 }
1958                        }
1959                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
1960
1961         [ "$FAILCONN" == "0" ] && \
1962                 log "ERROR: The client reconnection has not been triggered" && \
1963                 return 4
1964         [ "$FAILCONN" == "2" ] && \
1965                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
1966                 return 5
1967
1968         # LU-290
1969         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
1970         # Reconnects are supposed to be rate limited to one every 5s
1971         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] && \
1972                 log "ERROR: Too many reconnects $CONNCNT" && \
1973                 return 6
1974
1975         cleanup
1976         # remove nid settings
1977         writeconf_or_reformat
1978 }
1979 run_test 35b "Continue reconnection retries, if the active server is busy"
1980
1981 test_36() { # 12743
1982         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
1983
1984         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
1985                 { skip "remote OST" && return 0; }
1986
1987         local rc=0
1988         local FSNAME2=test1234
1989         local fs3ost_HOST=$ost_HOST
1990         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1991
1992         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
1993
1994         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
1995                 is_blkdev $SINGLEMDS $MDSDEV && \
1996                 skip_env "mixed loopback and real device not working" && return
1997         fi
1998
1999         local fs2mdsdev=$(mdsdevname 1_2)
2000         local fs2ostdev=$(ostdevname 1_2)
2001         local fs3ostdev=$(ostdevname 2_2)
2002         local fs2mdsvdev=$(mdsvdevname 1_2)
2003         local fs2ostvdev=$(ostvdevname 1_2)
2004         local fs3ostvdev=$(ostvdevname 2_2)
2005
2006         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2007                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
2008         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
2009         #     different one than the default value here.
2010         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2011                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
2012         add fs3ost $(mkfs_opts ost1 ${fs3ostdev}) --mgsnode=$MGSNID \
2013                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
2014
2015         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
2016         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2017         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
2018         mkdir -p $MOUNT2
2019         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
2020
2021         sleep 5 # until 11778 fixed
2022
2023         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
2024
2025         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
2026         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
2027         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
2028         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
2029         DFTOTAL=`echo $STRING | cut -d, -f1`
2030         DFUSED=`echo $STRING  | cut -d, -f2`
2031         DFAVAIL=`echo $STRING | cut -d, -f3`
2032         DFFREE=$(($DFTOTAL - $DFUSED))
2033
2034         ALLOWANCE=$((64 * $OSTCOUNT))
2035
2036         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
2037            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
2038                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
2039                 rc=1
2040         fi
2041         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
2042            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
2043                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
2044                 rc=2
2045         fi
2046         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
2047            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
2048                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
2049                 rc=3
2050        fi
2051
2052         umount -d $MOUNT2
2053         stop fs3ost -f || return 200
2054         stop fs2ost -f || return 201
2055         stop fs2mds -f || return 202
2056         unload_modules_conf || return 203
2057         return $rc
2058 }
2059 run_test 36 "df report consistency on OSTs with different block size"
2060
2061 test_37() {
2062         local mntpt=$(facet_mntpt $SINGLEMDS)
2063         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
2064         local mdsdev_sym="$TMP/sym_mdt.img"
2065         local opts=$MDS_MOUNT_OPTS
2066         local rc=0
2067
2068         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2069                 skip "Currently only applicable to ldiskfs-based MDTs"
2070                 return
2071         fi
2072
2073         echo "MDS :     $mdsdev"
2074         echo "SYMLINK : $mdsdev_sym"
2075         do_facet $SINGLEMDS rm -f $mdsdev_sym
2076
2077         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
2078
2079         echo "mount symlink device - $mdsdev_sym"
2080
2081         if ! do_facet $SINGLEMDS test -b $mdsdev; then
2082                 opts=$(csa_add "$opts" -o loop)
2083         fi
2084         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
2085                 $mdsdev_sym $mntpt 2>&1)
2086         rc=${PIPESTATUS[0]}
2087
2088         echo mount_op=$mount_op
2089
2090         do_facet $SINGLEMDS "umount -d $mntpt && rm -f $mdsdev_sym"
2091
2092         if $(echo $mount_op | grep -q "unable to set tunable"); then
2093                 error "set tunables failed for symlink device"
2094         fi
2095
2096         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
2097
2098         return 0
2099 }
2100 run_test 37 "verify set tunables works for symlink device"
2101
2102 test_38() { # bug 14222
2103         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2104                 skip "Only applicable to ldiskfs-based MDTs"
2105                 return
2106         fi
2107
2108         setup
2109         # like runtests
2110         COUNT=10
2111         SRC="/etc /bin"
2112         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
2113         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
2114         mkdir -p $DIR/$tdir
2115         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
2116                 error "copying $SRC to $DIR/$tdir"
2117         sync
2118         umount_client $MOUNT
2119         stop_mds
2120         log "rename lov_objid file on MDS"
2121         rm -f $TMP/lov_objid.orig
2122
2123         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2124         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
2125         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
2126
2127         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.orig"
2128         # check create in mds_lov_connect
2129         start_mds
2130         mount_client $MOUNT
2131         for f in $FILES; do
2132                 [ $V ] && log "verifying $DIR/$tdir/$f"
2133                 diff -q $f $DIR/$tdir/$f || ERROR=y
2134         done
2135         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
2136         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new"
2137         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
2138
2139         # check it's updates in sync
2140         umount_client $MOUNT
2141         stop_mds
2142
2143         do_facet $SINGLEMDS dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
2144         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
2145         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
2146
2147         start_mds
2148         mount_client $MOUNT
2149         for f in $FILES; do
2150                 [ $V ] && log "verifying $DIR/$tdir/$f"
2151                 diff -q $f $DIR/$tdir/$f || ERROR=y
2152         done
2153         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
2154         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new1"
2155         umount_client $MOUNT
2156         stop_mds
2157         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
2158
2159         log "files compared the same"
2160         cleanup
2161 }
2162 run_test 38 "MDS recreates missing lov_objid file from OST data"
2163
2164 test_39() {
2165         PTLDEBUG=+malloc
2166         setup
2167         cleanup
2168         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2169                 error "memory leak detected" || true
2170 }
2171 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2172
2173 test_40() { # bug 15759
2174         start_ost
2175         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2176         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2177         start_mds
2178         cleanup
2179 }
2180 run_test 40 "race during service thread startup"
2181
2182 test_41a() { #bug 14134
2183         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2184            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2185                 skip "Loop devices does not work with nosvc option"
2186                 return
2187         fi
2188
2189         local rc
2190         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2191
2192         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2193         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
2194         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2195         mkdir -p $MOUNT
2196         mount_client $MOUNT || return 1
2197         sleep 5
2198
2199         echo "blah blah" > $MOUNT/$tfile
2200         cat $MOUNT/$tfile
2201
2202         umount_client $MOUNT
2203         stop ost1 -f || return 201
2204         stop_mds -f || return 202
2205         stop_mds -f || return 203
2206         unload_modules_conf || return 204
2207         return $rc
2208 }
2209 run_test 41a "mount mds with --nosvc and --nomgs"
2210
2211 test_41b() {
2212         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2213            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2214                 skip "Loop devices does not work with nosvc option"
2215                 return
2216         fi
2217
2218         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2219
2220         stopall
2221         reformat
2222         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2223
2224         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2225         start_ost
2226         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2227         mkdir -p $MOUNT
2228         mount_client $MOUNT || return 1
2229         sleep 5
2230
2231         echo "blah blah" > $MOUNT/$tfile
2232         cat $MOUNT/$tfile || return 200
2233
2234         umount_client $MOUNT
2235         stop_ost || return 201
2236         stop_mds -f || return 202
2237         stop_mds -f || return 203
2238
2239 }
2240 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2241
2242 test_42() { #bug 14693
2243         setup
2244         check_mount || error "client was not mounted"
2245
2246         do_facet mgs $LCTL conf_param $FSNAME.llite.some_wrong_param=10
2247         umount_client $MOUNT ||
2248                 error "unmounting client failed with invalid llite param"
2249         mount_client $MOUNT ||
2250                 error "mounting client failed with invalid llite param"
2251
2252         do_facet mgs $LCTL conf_param $FSNAME.sys.some_wrong_param=20
2253         cleanup || error "stopping $FSNAME failed with invalid sys param"
2254         setup
2255         check_mount || "client was not mounted with invalid sys param"
2256         cleanup || error "stopping $FSNAME failed with invalid sys param"
2257         return 0
2258 }
2259 run_test 42 "allow client/server mount/unmount with invalid config param"
2260
2261 test_43() {
2262         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
2263         setup
2264         chmod ugo+x $DIR || error "chmod 0 failed"
2265         set_conf_param_and_check mds                                    \
2266                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2267                 "$FSNAME.mdt.root_squash"                               \
2268                 "0:0"
2269         set_conf_param_and_check mds                                    \
2270                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2271                 "$FSNAME.mdt.nosquash_nids"                             \
2272                 "NONE"
2273
2274     #
2275     # create set of test files
2276     #
2277     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
2278     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
2279     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
2280
2281     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
2282     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
2283
2284     mkdir $DIR/$tdir-rootdir -p       || error "mkdir failed"
2285     chmod go-rwx $DIR/$tdir-rootdir   || error "chmod 3 failed"
2286     touch $DIR/$tdir-rootdir/tfile-1  || error "touch failed"
2287
2288         #
2289         # check root_squash:
2290         #   set root squash UID:GID to RUNAS_ID
2291         #   root should be able to access only files owned by RUNAS_ID
2292         #
2293         set_conf_param_and_check mds                                    \
2294                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2295                 "$FSNAME.mdt.root_squash"                               \
2296                 "$RUNAS_ID:$RUNAS_ID"
2297
2298     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
2299     dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2300         error "$ST: root read permission is denied"
2301     echo "$ST: root read permission is granted - ok"
2302
2303     echo "444" | \
2304     dd conv=notrunc if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2305         error "$ST: root write permission is denied"
2306     echo "$ST: root write permission is granted - ok"
2307
2308     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2309     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2310         error "$ST: root read permission is granted"
2311     echo "$ST: root read permission is denied - ok"
2312
2313     echo "555" | \
2314     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2315         error "$ST: root write permission is granted"
2316     echo "$ST: root write permission is denied - ok"
2317
2318     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2319     rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null && \
2320         error "$ST: root unlink permission is granted"
2321     echo "$ST: root unlink permission is denied - ok"
2322
2323     touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null && \
2324         error "$ST: root create permission is granted"
2325     echo "$ST: root create permission is denied - ok"
2326
2327         #
2328         # check nosquash_nids:
2329         #   put client's NID into nosquash_nids list,
2330         #   root should be able to access root file after that
2331         #
2332         local NIDLIST=$(lctl list_nids all | tr '\n' ' ')
2333         NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
2334         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
2335         set_conf_param_and_check mds                                    \
2336                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2337                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
2338                 "$NIDLIST"
2339
2340     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2341     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2342         error "$ST: root read permission is denied"
2343     echo "$ST: root read permission is granted - ok"
2344
2345     echo "666" | \
2346     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2347         error "$ST: root write permission is denied"
2348     echo "$ST: root write permission is granted - ok"
2349
2350     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2351     rm $DIR/$tdir-rootdir/tfile-1 || \
2352         error "$ST: root unlink permission is denied"
2353     echo "$ST: root unlink permission is granted - ok"
2354     touch $DIR/$tdir-rootdir/tfile-2 || \
2355         error "$ST: root create permission is denied"
2356     echo "$ST: root create permission is granted - ok"
2357
2358     return 0
2359 }
2360 run_test 43 "check root_squash and nosquash_nids"
2361
2362 umount_client $MOUNT
2363 cleanup_nocli
2364
2365 test_44() { # 16317
2366         setup
2367         check_mount || return 2
2368         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
2369         STATS_FOUND=no
2370         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
2371         for VAL in $UUIDS; do
2372                 NID=$(echo $VAL | cut -d= -f1)
2373                 CLUUID=$(echo $VAL | cut -d= -f2)
2374                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
2375         done
2376         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
2377         cleanup
2378         return 0
2379 }
2380 run_test 44 "mounted client proc entry exists"
2381
2382 test_45() { #17310
2383         setup
2384         check_mount || return 2
2385         stop_mds
2386         df -h $MOUNT &
2387         log "sleep 60 sec"
2388         sleep 60
2389 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
2390         do_facet client "lctl set_param fail_loc=0x50f"
2391         log "sleep 10 sec"
2392         sleep 10
2393         manual_umount_client --force || return 3
2394         do_facet client "lctl set_param fail_loc=0x0"
2395         start_mds
2396         mount_client $MOUNT || return 4
2397         cleanup
2398         return 0
2399 }
2400 run_test 45 "long unlink handling in ptlrpcd"
2401
2402 cleanup_46a() {
2403         trap 0
2404         local rc=0
2405         local count=$1
2406
2407         umount_client $MOUNT2 || rc=$?
2408         umount_client $MOUNT || rc=$?
2409         while [ $count -gt 0 ]; do
2410                 stop ost${count} -f || rc=$?
2411                 let count=count-1
2412         done    
2413         stop_mds || rc=$?
2414         cleanup_nocli || rc=$?
2415         #writeconf to remove all ost2 traces for subsequent tests
2416         writeconf_or_reformat
2417         return $rc
2418 }
2419
2420 test_46a() {
2421         echo "Testing with $OSTCOUNT OSTs"
2422         reformat_and_config
2423         start_mds || return 1
2424         #first client should see only one ost
2425         start_ost || return 2
2426         wait_osc_import_state mds ost FULL
2427         #start_client
2428         mount_client $MOUNT || return 3
2429         trap "cleanup_46a $OSTCOUNT" EXIT ERR
2430
2431         local i
2432         for (( i=2; i<=$OSTCOUNT; i++ )); do
2433             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
2434         done
2435
2436         # wait until osts in sync
2437         for (( i=2; i<=$OSTCOUNT; i++ )); do
2438             wait_osc_import_state mds ost$i FULL
2439             wait_osc_import_state client ost$i FULL
2440         done
2441
2442         #second client see all ost's
2443
2444         mount_client $MOUNT2 || return 8
2445         $LFS setstripe -c -1 $MOUNT2 || return 9
2446         $LFS getstripe $MOUNT2 || return 10
2447
2448         echo "ok" > $MOUNT2/widestripe
2449         $LFS getstripe $MOUNT2/widestripe || return 11
2450         # fill acl buffer for avoid expand lsm to them
2451         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
2452             setfacl -m $acl $MOUNT2/widestripe
2453         done
2454
2455         # will be deadlock
2456         stat $MOUNT/widestripe || return 12
2457
2458         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
2459         return 0
2460 }
2461 run_test 46a "handle ost additional - wide striped file"
2462
2463 test_47() { #17674
2464         reformat
2465         setup_noconfig
2466         check_mount || return 2
2467         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
2468
2469         local lru_size=[]
2470         local count=0
2471         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2472             if echo $ns | grep "MDT[[:digit:]]*"; then
2473                 continue
2474             fi
2475             lrs=$(echo $ns | sed 's/.*lru_size=//')
2476             lru_size[count]=$lrs
2477             let count=count+1
2478         done
2479
2480         facet_failover ost1
2481         facet_failover $SINGLEMDS
2482         client_up || return 3
2483
2484         count=0
2485         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2486             if echo $ns | grep "MDT[[:digit:]]*"; then
2487                 continue
2488             fi
2489             lrs=$(echo $ns | sed 's/.*lru_size=//')
2490             if ! test "$lrs" -eq "${lru_size[count]}"; then
2491                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
2492                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
2493             fi
2494             let count=count+1
2495         done
2496
2497         cleanup
2498         return 0
2499 }
2500 run_test 47 "server restart does not make client loss lru_resize settings"
2501
2502 cleanup_48() {
2503         trap 0
2504
2505         # reformat after this test is needed - if test will failed
2506         # we will have unkillable file at FS
2507         reformat_and_config
2508 }
2509
2510 test_48() { # bug 17636
2511         reformat
2512         setup_noconfig
2513         check_mount || return 2
2514
2515         $LFS setstripe -c -1 $MOUNT || return 9
2516         $LFS getstripe $MOUNT || return 10
2517
2518         echo "ok" > $MOUNT/widestripe
2519         $LFS getstripe $MOUNT/widestripe || return 11
2520
2521         trap cleanup_48 EXIT ERR
2522
2523         # fill acl buffer for avoid expand lsm to them
2524         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
2525             setfacl -m $acl $MOUNT/widestripe
2526         done
2527
2528         stat $MOUNT/widestripe || return 12
2529
2530         cleanup_48
2531         return 0
2532 }
2533 run_test 48 "too many acls on file"
2534
2535 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
2536 test_49() { # bug 17710
2537         local timeout_orig=$TIMEOUT
2538         local ldlm_timeout_orig=$LDLM_TIMEOUT
2539         local LOCAL_TIMEOUT=20
2540
2541         LDLM_TIMEOUT=$LOCAL_TIMEOUT
2542         TIMEOUT=$LOCAL_TIMEOUT
2543
2544         reformat
2545         setup_noconfig
2546         check_mount || return 1
2547
2548         echo "check ldlm_timout..."
2549         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2550         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2551         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2552
2553         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2554                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2555         fi
2556
2557         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
2558                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2559         fi
2560
2561         umount_client $MOUNT
2562         stop_ost || return 2
2563         stop_mds || return 3
2564
2565         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
2566
2567         reformat
2568         setup_noconfig
2569         check_mount || return 7
2570
2571         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2572         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2573         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2574
2575         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2576                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2577         fi
2578
2579         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
2580                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2581         fi
2582
2583         cleanup || return $?
2584
2585         LDLM_TIMEOUT=$ldlm_timeout_orig
2586         TIMEOUT=$timeout_orig
2587 }
2588 run_test 49 "check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE"
2589
2590 lazystatfs() {
2591         # Test both statfs and lfs df and fail if either one fails
2592         multiop_bg_pause $1 f_
2593         RC1=$?
2594         PID=$!
2595         killall -USR1 multiop
2596         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
2597         wait $PID || { RC1=$?; log "multiop return error "; }
2598
2599         $LFS df &
2600         PID=$!
2601         sleep 5
2602         kill -s 0 $PID
2603         RC2=$?
2604         if [ $RC2 -eq 0 ]; then
2605             kill -s 9 $PID
2606             log "lazystatfs df failed"
2607         fi
2608
2609         RC=0
2610         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
2611         return $RC
2612 }
2613
2614 test_50a() {
2615         setup
2616         lctl set_param llite.$FSNAME-*.lazystatfs=1
2617         touch $DIR/$tfile
2618
2619         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
2620
2621         cleanup || return $?
2622 }
2623 run_test 50a "lazystatfs all servers available =========================="
2624
2625 test_50b() {
2626         setup
2627         lctl set_param llite.$FSNAME-*.lazystatfs=1
2628         touch $DIR/$tfile
2629
2630         # Wait for client to detect down OST
2631         stop_ost || error "Unable to stop OST1"
2632         wait_osc_import_state mds ost DISCONN
2633
2634         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
2635
2636         umount_client $MOUNT || error "Unable to unmount client"
2637         stop_mds || error "Unable to stop MDS"
2638 }
2639 run_test 50b "lazystatfs all servers down =========================="
2640
2641 test_50c() {
2642         start_mds || error "Unable to start MDS"
2643         start_ost || error "Unable to start OST1"
2644         start_ost2 || error "Unable to start OST2"
2645         mount_client $MOUNT || error "Unable to mount client"
2646         lctl set_param llite.$FSNAME-*.lazystatfs=1
2647         touch $DIR/$tfile
2648
2649         # Wait for client to detect down OST
2650         stop_ost || error "Unable to stop OST1"
2651         wait_osc_import_state mds ost DISCONN
2652         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2653
2654         umount_client $MOUNT || error "Unable to unmount client"
2655         stop_ost2 || error "Unable to stop OST2"
2656         stop_mds || error "Unable to stop MDS"
2657         #writeconf to remove all ost2 traces for subsequent tests
2658         writeconf_or_reformat
2659 }
2660 run_test 50c "lazystatfs one server down =========================="
2661
2662 test_50d() {
2663         start_mds || error "Unable to start MDS"
2664         start_ost || error "Unable to start OST1"
2665         start_ost2 || error "Unable to start OST2"
2666         mount_client $MOUNT || error "Unable to mount client"
2667         lctl set_param llite.$FSNAME-*.lazystatfs=1
2668         touch $DIR/$tfile
2669
2670         # Issue the statfs during the window where the client still
2671         # belives the OST to be available but it is in fact down.
2672         # No failure just a statfs which hangs for a timeout interval.
2673         stop_ost || error "Unable to stop OST1"
2674         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2675
2676         umount_client $MOUNT || error "Unable to unmount client"
2677         stop_ost2 || error "Unable to stop OST2"
2678         stop_mds || error "Unable to stop MDS"
2679         #writeconf to remove all ost2 traces for subsequent tests
2680         writeconf_or_reformat
2681 }
2682 run_test 50d "lazystatfs client/server conn race =========================="
2683
2684 test_50e() {
2685         local RC1
2686         local pid
2687
2688         reformat_and_config
2689         start_mds || return 1
2690         #first client should see only one ost
2691         start_ost || return 2
2692         wait_osc_import_state mds ost FULL
2693
2694         # Wait for client to detect down OST
2695         stop_ost || error "Unable to stop OST1"
2696         wait_osc_import_state mds ost DISCONN
2697
2698         mount_client $MOUNT || error "Unable to mount client"
2699         lctl set_param llite.$FSNAME-*.lazystatfs=0
2700
2701         multiop_bg_pause $MOUNT _f
2702         RC1=$?
2703         pid=$!
2704
2705         if [ $RC1 -ne 0 ]; then
2706                 log "multiop failed $RC1"
2707         else
2708             kill -USR1 $pid
2709             sleep $(( $TIMEOUT+1 ))
2710             kill -0 $pid
2711             [ $? -ne 0 ] && error "process isn't sleep"
2712             start_ost || error "Unable to start OST1"
2713             wait $pid || error "statfs failed"
2714         fi
2715
2716         umount_client $MOUNT || error "Unable to unmount client"
2717         stop_ost || error "Unable to stop OST1"
2718         stop_mds || error "Unable to stop MDS"
2719 }
2720 run_test 50e "normal statfs all servers down =========================="
2721
2722 test_50f() {
2723         local RC1
2724         local pid
2725         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
2726
2727         start_mds || error "Unable to start mds"
2728         #first client should see only one ost
2729         start_ost || error "Unable to start OST1"
2730         wait_osc_import_state mds ost FULL
2731
2732         start_ost2 || error "Unable to start OST2"
2733         wait_osc_import_state mds ost2 FULL
2734
2735         # Wait for client to detect down OST
2736         stop_ost2 || error "Unable to stop OST2"
2737
2738         wait_osc_import_state mds ost2 DISCONN
2739         mount_client $MOUNT || error "Unable to mount client"
2740         lctl set_param llite.$FSNAME-*.lazystatfs=0
2741
2742         multiop_bg_pause $MOUNT _f
2743         RC1=$?
2744         pid=$!
2745
2746         if [ $RC1 -ne 0 ]; then
2747                 log "lazystatfs multiop failed $RC1"
2748         else
2749             kill -USR1 $pid
2750             sleep $(( $TIMEOUT+1 ))
2751             kill -0 $pid
2752             [ $? -ne 0 ] && error "process isn't sleep"
2753             start_ost2 || error "Unable to start OST2"
2754             wait $pid || error "statfs failed"
2755             stop_ost2 || error "Unable to stop OST2"
2756         fi
2757
2758         umount_client $MOUNT || error "Unable to unmount client"
2759         stop_ost || error "Unable to stop OST1"
2760         stop_mds || error "Unable to stop MDS"
2761         #writeconf to remove all ost2 traces for subsequent tests
2762         writeconf_or_reformat
2763 }
2764 run_test 50f "normal statfs one server in down =========================="
2765
2766 test_50g() {
2767         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2768         setup
2769         start_ost2 || error "Unable to start OST2"
2770         wait_osc_import_state mds ost2 FULL
2771         wait_osc_import_state client ost2 FULL
2772
2773         local PARAM="${FSNAME}-OST0001.osc.active"
2774
2775         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
2776         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
2777
2778         umount_client $MOUNT || error "Unable to unmount client"
2779         mount_client $MOUNT || error "Unable to mount client"
2780         # This df should not cause a panic
2781         df -k $MOUNT
2782
2783         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
2784         rm -f $DIR/$tfile
2785         umount_client $MOUNT || error "Unable to unmount client"
2786         stop_ost2 || error "Unable to stop OST2"
2787         stop_ost || error "Unable to stop OST1"
2788         stop_mds || error "Unable to stop MDS"
2789         #writeconf to remove all ost2 traces for subsequent tests
2790         writeconf_or_reformat
2791 }
2792 run_test 50g "deactivated OST should not cause panic====================="
2793
2794 # LU-642
2795 test_50h() {
2796         # prepare MDT/OST, make OSC inactive for OST1
2797         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2798         do_facet ost1 "$TUNEFS --param osc.active=0 `ostdevname 1`" ||
2799                 error "tunefs OST1 failed"
2800         start_mds  || error "Unable to start MDT"
2801         start_ost  || error "Unable to start OST1"
2802         start_ost2 || error "Unable to start OST2"
2803         mount_client $MOUNT || error "client start failed"
2804
2805         mkdir -p $DIR/$tdir
2806
2807         # activatate OSC for OST1
2808         local TEST="$LCTL get_param -n osc.${FSNAME}-OST0000-osc-[!M]*.active"
2809         set_conf_param_and_check client                                 \
2810                 "$TEST" "${FSNAME}-OST0000.osc.active" 1 ||
2811                 error "Unable to activate OST1"
2812
2813         mkdir -p $DIR/$tdir/2
2814         $LFS setstripe -c -1 -i 0 $DIR/$tdir/2
2815         sleep 1 && echo "create a file after OST1 is activated"
2816         # create some file
2817         createmany -o $DIR/$tdir/2/$tfile-%d 1
2818
2819         # check OSC import is working
2820         stat $DIR/$tdir/2/* >/dev/null 2>&1 ||
2821                 error "some OSC imports are still not connected"
2822
2823         # cleanup
2824         umount_client $MOUNT || error "Unable to umount client"
2825         stop_ost2 || error "Unable to stop OST2"
2826         cleanup_nocli
2827 }
2828 run_test 50h "LU-642: activate deactivated OST  ==="
2829
2830 test_51() {
2831         local LOCAL_TIMEOUT=20
2832
2833         reformat
2834         setup_noconfig
2835         check_mount || return 1
2836
2837         mkdir $MOUNT/d1
2838         $LFS setstripe -c -1 $MOUNT/d1
2839         #define OBD_FAIL_MDS_REINT_DELAY         0x142
2840         do_facet $SINGLEMDS "lctl set_param fail_loc=0x142"
2841         touch $MOUNT/d1/f1 &
2842         local pid=$!
2843         sleep 2
2844         start_ost2 || return 2
2845         wait $pid
2846         stop_ost2 || return 3
2847         cleanup
2848         #writeconf to remove all ost2 traces for subsequent tests
2849         writeconf_or_reformat
2850 }
2851 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
2852
2853 copy_files_xattrs()
2854 {
2855         local node=$1
2856         local dest=$2
2857         local xattrs=$3
2858         shift 3
2859
2860         do_node $node mkdir -p $dest
2861         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2862
2863         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
2864                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
2865         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
2866
2867         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
2868         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
2869 }
2870
2871 diff_files_xattrs()
2872 {
2873         local node=$1
2874         local backup=$2
2875         local xattrs=$3
2876         shift 3
2877
2878         local backup2=${TMP}/backup2
2879
2880         do_node $node mkdir -p $backup2
2881         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2882
2883         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
2884                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
2885         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
2886
2887         do_node $node "diff -rq $backup $backup2"
2888         [ $? -eq 0 ] || { error "contents differ"; return 3; }
2889
2890         local xattrs2=${TMP}/xattrs2
2891         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
2892         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
2893
2894         do_node $node "diff $xattrs $xattrs2"
2895         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
2896
2897         do_node $node "rm -rf $backup2 $xattrs2"
2898         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
2899 }
2900
2901 test_52() {
2902         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2903                 skip "Only applicable to ldiskfs-based MDTs"
2904                 return
2905         fi
2906
2907         start_mds
2908         [ $? -eq 0 ] || { error "Unable to start MDS"; return 1; }
2909         start_ost
2910         [ $? -eq 0 ] || { error "Unable to start OST1"; return 2; }
2911         mount_client $MOUNT
2912         [ $? -eq 0 ] || { error "Unable to mount client"; return 3; }
2913
2914         local nrfiles=8
2915         local ost1mnt=$(facet_mntpt ost1)
2916         local ost1node=$(facet_active_host ost1)
2917         local ost1tmp=$TMP/conf52
2918         local loop
2919
2920         mkdir -p $DIR/$tdir
2921         [ $? -eq 0 ] || { error "Unable to create tdir"; return 4; }
2922         touch $TMP/modified_first
2923         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 5; }
2924         local mtime=$(stat -c %Y $TMP/modified_first)
2925         do_node $ost1node "mkdir -p $ost1tmp && touch -m -d @$mtime $ost1tmp/modified_first"
2926
2927         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 6; }
2928         sleep 1
2929
2930         $LFS setstripe -c -1 -S 1M $DIR/$tdir
2931         [ $? -eq 0 ] || { error "lfs setstripe failed"; return 7; }
2932
2933         for (( i=0; i < nrfiles; i++ )); do
2934                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c
2935                 [ $? -eq 0 ] || { error "multiop failed"; return 8; }
2936                 echo -n .
2937         done
2938         echo
2939
2940         # backup files
2941         echo backup files to $TMP/files
2942         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
2943         copy_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
2944         [ $? -eq 0 ] || { error "Unable to copy files"; return 9; }
2945
2946         umount_client $MOUNT
2947         [ $? -eq 0 ] || { error "Unable to umount client"; return 10; }
2948         stop_ost
2949         [ $? -eq 0 ] || { error "Unable to stop ost1"; return 11; }
2950
2951         echo mount ost1 as ldiskfs
2952         do_node $ost1node mkdir -p $ost1mnt
2953         [ $? -eq 0 ] || { error "Unable to create $ost1mnt"; return 23; }
2954         if ! do_node $ost1node test -b $ost1_dev; then
2955                 loop="-o loop"
2956         fi
2957         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
2958                 $ost1mnt
2959         [ $? -eq 0 ] || { error "Unable to mount ost1 as ldiskfs"; return 12; }
2960
2961         # backup objects
2962         echo backup objects to $ost1tmp/objects
2963         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/[0-9]* -type f'\
2964                 '-size +0 -newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
2965         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs \
2966                         $objects
2967         [ $? -eq 0 ] || { error "Unable to copy objects"; return 13; }
2968
2969         # move objects to lost+found
2970         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
2971         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
2972
2973         # recover objects
2974         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found"
2975         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
2976
2977         # compare restored objects against saved ones
2978         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
2979         [ $? -eq 0 ] || { error "Unable to diff objects"; return 16; }
2980
2981         do_node $ost1node "umount $ost1mnt"
2982         [ $? -eq 0 ] || { error "Unable to umount ost1 as ldiskfs"; return 17; }
2983
2984         start_ost
2985         [ $? -eq 0 ] || { error "Unable to start ost1"; return 18; }
2986         mount_client $MOUNT
2987         [ $? -eq 0 ] || { error "Unable to mount client"; return 19; }
2988
2989         # compare files
2990         diff_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
2991         [ $? -eq 0 ] || { error "Unable to diff files"; return 20; }
2992
2993         rm -rf $TMP/files $TMP/file_xattrs
2994         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 21; }
2995         do_node $ost1node "rm -rf $ost1tmp"
2996         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 22; }
2997         cleanup
2998 }
2999 run_test 52 "check recovering objects from lost+found"
3000
3001 # Checks threads_min/max/started for some service
3002 #
3003 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
3004 # parameter pattern prefix like 'ost.*.ost'.
3005 thread_sanity() {
3006         local modname=$1
3007         local facet=$2
3008         local parampat=$3
3009         local opts=$4
3010         local basethr=$5
3011         local tmin
3012         local tmin2
3013         local tmax
3014         local tmax2
3015         local tstarted
3016         local paramp
3017         local msg="Insane $modname thread counts"
3018         local ncpts=$(check_cpt_number $facet)
3019         local nthrs
3020         shift 4
3021
3022         check_mount || return 41
3023
3024         # We need to expand $parampat, but it may match multiple parameters, so
3025         # we'll pick the first one
3026         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
3027                 error "Couldn't expand ${parampat}.threads_min parameter name"
3028                 return 22
3029         fi
3030
3031         # Remove the .threads_min part
3032         paramp=${paramp%.threads_min}
3033
3034         # Check for sanity in defaults
3035         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3036         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3037         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started" || echo 0)
3038         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' || return $?
3039         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
3040         nthrs=$(expr $tmax - $tmin)
3041         if [ $nthrs -lt $ncpts ]; then
3042                 nthrs=0
3043         else
3044                 nthrs=$ncpts
3045         fi
3046
3047         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
3048                 skip_env "module parameter forced $facet thread count" &&
3049                 tmin=3 && tmax=$((3 * tmax))
3050
3051         # Check that we can change min/max
3052         do_facet $facet "lctl set_param ${paramp}.threads_min=$((tmin + nthrs))"
3053         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmax - nthrs))"
3054         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3055         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3056         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) && $tmax2 == ($tmax - $nthrs)))' || return $?
3057
3058         # Check that we can set min/max to the same value
3059         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3060         do_facet $facet "lctl set_param ${paramp}.threads_max=$tmin"
3061         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3062         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3063         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
3064
3065         # Check that we can't set max < min
3066         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmin - 1))"
3067         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3068         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3069         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
3070
3071         # We need to ensure that we get the module options desired; to do this
3072         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
3073         LOAD_MODULES_REMOTE=true
3074         cleanup
3075         local oldvalue
3076         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
3077         setmodopts -a $modname "$newvalue" oldvalue
3078
3079         load_modules
3080         setup
3081         check_mount || return 41
3082
3083         # Restore previous setting of MODOPTS_*
3084         setmodopts $modname "$oldvalue"
3085
3086         # Check that $opts took
3087         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min")
3088         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max")
3089         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started")
3090         lassert 28 "$msg" '(($tstarted == $tmin && $tstarted == $tmax ))' || return $?
3091         cleanup
3092
3093         load_modules
3094         setup
3095 }
3096
3097 test_53a() {
3098         setup
3099         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
3100         cleanup
3101 }
3102 run_test 53a "check OSS thread count params"
3103
3104 test_53b() {
3105         setup
3106         local mds=$(do_facet $SINGLEMDS "lctl get_param -N mds.*.*.threads_max \
3107                     2>/dev/null")
3108         if [ -z "$mds" ]; then
3109                 #running this on an old MDT
3110                 thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' 16
3111         else
3112                 thread_sanity MDT $SINGLEMDS 'mds.*.*.' 'mds_num_threads' 16
3113         fi
3114         cleanup
3115 }
3116 run_test 53b "check MDS thread count params"
3117
3118 test_54a() {
3119         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3120                 skip "Only applicable to ldiskfs-based MDTs"
3121                 return
3122         fi
3123
3124     do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p
3125     [ $? -eq 0 ] || error "llverdev failed!"
3126     reformat_and_config
3127 }
3128 run_test 54a "test llverdev and partial verify of device"
3129
3130 test_54b() {
3131         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3132                 skip "Only applicable to ldiskfs-based MDTs"
3133                 return
3134         fi
3135
3136     setup
3137     run_llverfs $MOUNT -p
3138     [ $? -eq 0 ] || error "llverfs failed!"
3139     cleanup
3140 }
3141 run_test 54b "test llverfs and partial verify of filesystem"
3142
3143 lov_objid_size()
3144 {
3145         local max_ost_index=$1
3146         echo -n $(((max_ost_index + 1) * 8))
3147 }
3148
3149 test_55() {
3150         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3151                 skip "Only applicable to ldiskfs-based MDTs"
3152                 return
3153         fi
3154
3155         local mdsdev=$(mdsdevname 1)
3156         local mdsvdev=$(mdsvdevname 1)
3157
3158         for i in 1023 2048
3159         do
3160                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
3161                         $mdsvdev || exit 10
3162                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
3163                         --reformat $(ostdevname 1) $(ostvdevname 1)
3164                 setup_noconfig
3165                 stopall
3166                 setup_noconfig
3167                 sync
3168
3169                 echo checking size of lov_objid for ost index $i
3170                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" | grep ^User | awk '{print $6}')
3171                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
3172                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
3173                 else
3174                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
3175                 fi
3176                 stopall
3177         done
3178
3179         reformat
3180 }
3181 run_test 55 "check lov_objid size"
3182
3183 test_56() {
3184         local mds_journal_size_orig=$MDSJOURNALSIZE
3185
3186         MDSJOURNALSIZE=16
3187
3188         for num in $(seq 1 $MDSCOUNT); do
3189                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3190                         --reformat $(mdsdevname $num) $(mdsvdevname $num)
3191         done
3192         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=1000 --reformat \
3193                 $(ostdevname 1) $(ostvdevname 1)
3194         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=10000 --reformat \
3195                 $(ostdevname 2) $(ostvdevname 2)
3196
3197         start_mgsmds
3198         start_ost
3199         start_ost2 || error "Unable to start second ost"
3200         mount_client $MOUNT || error "Unable to mount client"
3201         echo ok
3202         $LFS osts
3203         stopall
3204         MDSJOURNALSIZE=$mds_journal_size_orig
3205         reformat
3206 }
3207 run_test 56 "check big indexes"
3208
3209 test_57a() { # bug 22656
3210         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3211         writeconf_or_reformat
3212         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" || error "tunefs failed"
3213         start_mgsmds
3214         start_ost && error "OST registration from failnode should fail"
3215         reformat
3216 }
3217 run_test 57a "initial registration from failnode should fail (should return errs)"
3218
3219 test_57b() {
3220         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3221         writeconf_or_reformat
3222         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" || error "tunefs failed"
3223         start_mgsmds
3224         start_ost || error "OST registration from servicenode should not fail"
3225         reformat
3226 }
3227 run_test 57b "initial registration from servicenode should not fail"
3228
3229 count_osts() {
3230         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
3231 }
3232
3233 test_58() { # bug 22658
3234         if [ $(facet_fstype mds) != ldiskfs ]; then
3235                 skip "Only applicable to ldiskfs-based MDTs"
3236                 return
3237         fi
3238         setup_noconfig
3239         mkdir -p $DIR/$tdir
3240         createmany -o $DIR/$tdir/$tfile-%d 100
3241         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
3242 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
3243         do_facet mds "lctl set_param fail_loc=0x601"
3244         unlinkmany $DIR/$tdir/$tfile-%d 100
3245         stop mds
3246         local MNTDIR=$(facet_mntpt mds)
3247         # remove all files from the OBJECTS dir
3248         do_facet mds "mount -t ldiskfs $MDSDEV $MNTDIR"
3249         do_facet mds "find $MNTDIR/OBJECTS -type f -delete"
3250         do_facet mds "umount $MNTDIR"
3251         # restart MDS with missing llog files
3252         start_mds
3253         do_facet mds "lctl set_param fail_loc=0"
3254         reformat
3255 }
3256 run_test 58 "missing llog files must not prevent MDT from mounting"
3257
3258 test_59() {
3259         start_mgsmds >> /dev/null
3260         local C1=$(count_osts)
3261         if [ $C1 -eq 0 ]; then
3262                 start_ost >> /dev/null
3263                 C1=$(count_osts)
3264         fi
3265         stopall
3266         echo "original ost count: $C1 (expect > 0)"
3267         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
3268         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
3269         local C2=$(count_osts)
3270         echo "after mdt writeconf count: $C2 (expect 0)"
3271         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
3272         echo "OST start without writeconf should fail:"
3273         start_ost >> /dev/null && error "OST start without writeconf didn't fail"
3274         echo "OST start with writeconf should succeed:"
3275         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
3276         local C3=$(count_osts)
3277         echo "after ost writeconf count: $C3 (expect 1)"
3278         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
3279         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
3280         local C4=$(count_osts)
3281         echo "after ost2 writeconf count: $C4 (expect 2)"
3282         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
3283         stop_ost2 >> /dev/null
3284         cleanup_nocli >> /dev/null
3285         #writeconf to remove all ost2 traces for subsequent tests
3286         writeconf_or_reformat
3287 }
3288 run_test 59 "writeconf mount option"
3289
3290 test_60() { # LU-471
3291         local num
3292
3293         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3294                 skip "Only applicable to ldiskfs-based MDTs"
3295                 return
3296         fi
3297
3298         for num in $(seq $MDSCOUNT); do
3299                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3300                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
3301                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3302                         exit 10
3303         done
3304
3305         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
3306         rc=${PIPESTATUS[0]}
3307         [ $rc -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
3308
3309         # MDT default has dirdata feature
3310         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
3311         # we disable uninit_bg feature
3312         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
3313         # we set stride extended options
3314         echo $dump | grep stride > /dev/null || error "stride is not set"
3315         reformat
3316 }
3317 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
3318
3319 test_61() { # LU-80
3320         local reformat=false
3321
3322         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
3323                 { skip "Need MDS version at least 2.1.53"; return 0; }
3324
3325         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3326            ! large_xattr_enabled; then
3327                 reformat=true
3328                 LDISKFS_MKFS_OPTS+=" -O large_xattr"
3329
3330                 for num in $(seq $MDSCOUNT); do
3331                         add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
3332                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3333                         error "add mds $num failed"
3334                 done
3335         fi
3336
3337     setup_noconfig || error "setting up the filesystem failed"
3338     client_up || error "starting client failed"
3339
3340     local file=$DIR/$tfile
3341     touch $file
3342
3343     local large_value="$(generate_string $(max_xattr_size))"
3344     local small_value="bar"
3345
3346     local name="trusted.big"
3347     log "save large xattr $name on $file"
3348     setfattr -n $name -v $large_value $file ||
3349         error "saving $name on $file failed"
3350
3351     local new_value=$(get_xattr_value $name $file)
3352     [[ "$new_value" != "$large_value" ]] &&
3353         error "$name different after saving"
3354
3355     log "shrink value of $name on $file"
3356     setfattr -n $name -v $small_value $file ||
3357         error "shrinking value of $name on $file failed"
3358
3359     new_value=$(get_xattr_value $name $file)
3360     [[ "$new_value" != "$small_value" ]] &&
3361         error "$name different after shrinking"
3362
3363     log "grow value of $name on $file"
3364     setfattr -n $name -v $large_value $file ||
3365         error "growing value of $name on $file failed"
3366
3367     new_value=$(get_xattr_value $name $file)
3368     [[ "$new_value" != "$large_value" ]] &&
3369         error "$name different after growing"
3370
3371     log "check value of $name on $file after remounting MDS"
3372     fail $SINGLEMDS
3373     new_value=$(get_xattr_value $name $file)
3374     [[ "$new_value" != "$large_value" ]] &&
3375         error "$name different after remounting MDS"
3376
3377     log "remove large xattr $name from $file"
3378     setfattr -x $name $file || error "removing $name from $file failed"
3379
3380     rm -f $file
3381     stopall
3382         if $reformat; then
3383                 LDISKFS_MKFS_OPTS=${LDISKFS_MKFS_OPTS% -O large_xattr}
3384                 reformat
3385         fi
3386 }
3387 run_test 61 "large xattr"
3388
3389 test_62() {
3390         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3391                 skip "Only applicable to ldiskfs-based MDTs"
3392                 return
3393         fi
3394
3395         # MRP-118
3396         local mdsdev=$(mdsdevname 1)
3397         local ostdev=$(ostdevname 1)
3398
3399         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
3400                 { skip "Need MDS version at least 2.2.51"; return 0; }
3401
3402         echo "disable journal for mds"
3403         do_facet mds tune2fs -O ^has_journal $mdsdev || error "tune2fs failed"
3404         start_mds && error "MDT start should fail"
3405         echo "disable journal for ost"
3406         do_facet ost1 tune2fs -O ^has_journal $ostdev || error "tune2fs failed"
3407         start_ost && error "OST start should fail"
3408         cleanup || return $?
3409         reformat_and_config
3410 }
3411 run_test 62 "start with disabled journal"
3412
3413 test_63() {
3414         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3415                 skip "Only applicable to ldiskfs-based MDTs"
3416                 return
3417         fi
3418
3419         local inode_slab=$(do_facet $SINGLEMDS \
3420                 "awk '/ldiskfs_inode_cache/ { print \\\$5 }' /proc/slabinfo")
3421         if [ -z "$inode_slab" ]; then
3422                 skip "ldiskfs module has not been loaded"
3423                 return
3424         fi
3425
3426         echo "$inode_slab ldisk inodes per page"
3427         [ "$inode_slab" -ge "3" ] ||
3428                 error "ldisk inode size is too big, $inode_slab objs per page"
3429         return
3430 }
3431 run_test 63 "Verify each page can at least hold 3 ldisk inodes"
3432
3433 test_64() {
3434         start_mds
3435         start_ost
3436         start_ost2 || error "Unable to start second ost"
3437         mount_client $MOUNT || error "Unable to mount client"
3438         stop_ost2 || error "Unable to stop second ost"
3439         echo "$LFS df"
3440         $LFS df --lazy || error "lfs df failed"
3441         cleanup || return $?
3442         #writeconf to remove all ost2 traces for subsequent tests
3443         writeconf_or_reformat
3444 }
3445 run_test 64 "check lfs df --lazy "
3446
3447 test_65() { # LU-2237
3448         # Currently, the test is only valid for ldiskfs backend
3449         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3450                 skip "non-ldiskfs backend" && return
3451
3452         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3453         local brpt=$(facet_mntpt brpt)
3454         local opts=""
3455
3456         if ! do_facet $SINGLEMDS "test -b $devname"; then
3457                 opts="-o loop"
3458         fi
3459
3460         stop_mds
3461         local obj=$(do_facet $SINGLEMDS \
3462                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
3463                     grep Inode)
3464         if [ -z "$obj" ]; then
3465                 # The MDT may be just re-formatted, mount the MDT for the
3466                 # first time to guarantee the "last_rcvd" file is there.
3467                 start_mds || error "fail to mount the MDS for the first time"
3468                 stop_mds
3469         fi
3470
3471         # remove the "last_rcvd" file
3472         do_facet $SINGLEMDS "mkdir -p $brpt"
3473         do_facet $SINGLEMDS \
3474                 "mount -t $(facet_fstype $SINGLEMDS) $opts $devname $brpt"
3475         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
3476         do_facet $SINGLEMDS "umount $brpt"
3477
3478         # restart MDS, the "last_rcvd" file should be recreated.
3479         start_mds || error "fail to restart the MDS"
3480         stop_mds
3481         obj=$(do_facet $SINGLEMDS \
3482               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
3483         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
3484 }
3485 run_test 65 "re-create the lost last_rcvd file when server mount"
3486
3487 test_66() {
3488         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
3489                 { skip "Need MGS version at least 2.3.59"; return 0; }
3490
3491         setup
3492         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
3493         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
3494
3495         echo "replace_nids should fail if MDS, OSTs and clients are UP"
3496         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3497                 error "replace_nids fail"
3498
3499         umount_client $MOUNT || error "unmounting client failed"
3500         echo "replace_nids should fail if MDS and OSTs are UP"
3501         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3502                 error "replace_nids fail"
3503
3504         stop_ost
3505         echo "replace_nids should fail if MDS is UP"
3506         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3507                 error "replace_nids fail"
3508
3509         stop_mds || error "stopping mds failed"
3510
3511         if combined_mgs_mds; then
3512                 start_mds "-o nosvc" ||
3513                         error "starting mds with nosvc option failed"
3514         fi
3515
3516         echo "command should accept two parameters"
3517         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
3518                 error "command should accept two params"
3519
3520         echo "correct device name should be passed"
3521         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
3522                 error "wrong devname"
3523
3524         echo "wrong nids list should not destroy the system"
3525         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
3526                 error "wrong parse"
3527
3528         echo "replace OST nid"
3529         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
3530                 error "replace nids failed"
3531
3532         echo "command should accept two parameters"
3533         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
3534                 error "command should accept two params"
3535
3536         echo "wrong nids list should not destroy the system"
3537         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
3538                 error "wrong parse"
3539
3540         echo "replace MDS nid"
3541         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
3542                 error "replace nids failed"
3543
3544         if ! combined_mgs_mds ; then
3545                 stop_mgs
3546         else
3547                 stop_mds
3548         fi
3549
3550         setup_noconfig
3551         check_mount || error "error after nid replace"
3552         cleanup
3553         reformat
3554 }
3555 run_test 66 "replace nids"
3556
3557 test_70a() {
3558         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3559         local MDTIDX=1
3560
3561         start_mdt 1 || error "MDT0 start fail"
3562
3563         start_ost || error "OST0 start fail"
3564
3565         start_mdt 2 || error "MDT1 start fail"
3566
3567         mount_client $MOUNT || error "mount client fails"
3568
3569         mkdir -p $DIR/$tdir || error "create dir fail"
3570
3571         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3572                                         error "create remote dir fail"
3573
3574         rm -rf $DIR/$tdir || error "delete dir fail"
3575         cleanup || return $?
3576 }
3577 run_test 70a "start MDT0, then OST, then MDT1"
3578
3579 test_70b() {
3580         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3581         local MDTIDX=1
3582
3583         start_ost || error "OST0 start fail"
3584
3585         start_mdt 1 || error "MDT0 start fail"
3586         start_mdt 2 || error "MDT1 start fail"
3587
3588         mount_client $MOUNT || error "mount client fails"
3589
3590         mkdir -p $DIR/$tdir || error "create dir fail"
3591
3592         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3593                                         error "create remote dir fail"
3594
3595         rm -rf $DIR/$tdir || error "delete dir fail"
3596
3597         cleanup || return $?
3598 }
3599 run_test 70b "start OST, MDT1, MDT0"
3600
3601 test_70c() {
3602         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3603         local MDTIDX=1
3604
3605         start_mdt 1 || error "MDT0 start fail"
3606         start_mdt 2 || error "MDT1 start fail"
3607         start_ost || error "OST0 start fail"
3608
3609         mount_client $MOUNT || error "mount client fails"
3610         stop_mdt 1 || error "MDT1 start fail"
3611
3612         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
3613         echo "deactivate $mdc_for_mdt1"
3614         $LCTL --device $mdc_for_mdt1 deactivate || return 1
3615
3616         mkdir -p $DIR/$tdir && error "mkdir succeed"
3617
3618         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
3619                                         error "create remote dir succeed"
3620
3621         cleanup || return $?
3622 }
3623 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
3624
3625 test_70d() {
3626         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3627         local MDTIDX=1
3628
3629         start_mdt 1 || error "MDT0 start fail"
3630         start_mdt 2 || error "MDT1 start fail"
3631         start_ost || error "OST0 start fail"
3632
3633         mount_client $MOUNT || error "mount client fails"
3634
3635         stop_mdt 2 || error "MDT1 start fail"
3636
3637         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
3638                              awk '{print $4}')
3639         echo "deactivate $mdc_for_mdt2"
3640         $LCTL --device $mdc_for_mdt2 deactivate ||
3641                         error "set $mdc_for_mdt2 deactivate failed"
3642
3643         mkdir -p $DIR/$tdir || error "mkdir fail"
3644         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
3645                         error "create remote dir succeed"
3646
3647         rm -rf $DIR/$tdir || error "delete dir fail"
3648
3649         cleanup || return $?
3650 }
3651 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
3652
3653 test_71a() {
3654         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3655         if combined_mgs_mds; then
3656                 skip "needs separate MGS/MDT" && return
3657         fi
3658         local MDTIDX=1
3659
3660         start_mdt 1 || error "MDT0 start fail"
3661         start_ost || error "OST0 start fail"
3662         start_mdt 2 || error "MDT1 start fail"
3663         start_ost2 || error "OST1 start fail"
3664
3665         mount_client $MOUNT || error "mount client fails"
3666
3667         mkdir -p $DIR/$tdir || error "mkdir fail"
3668         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3669                         error "create remote dir succeed"
3670
3671         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
3672         rm -rf $DIR/$tdir || error "delete dir fail"
3673
3674         umount_client $MOUNT
3675         stop_mdt 1 || error "MDT0 stop fail"
3676         stop_mdt 2 || error "MDT1 stop fail"
3677         stop_ost || error "OST0 stop fail"
3678         stop_ost2 || error "OST1 stop fail"
3679 }
3680 run_test 71a "start MDT0 OST0, MDT1, OST1"
3681
3682 test_71b() {
3683         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3684         if combined_mgs_mds; then
3685                 skip "needs separate MGS/MDT" && return
3686         fi
3687         local MDTIDX=1
3688
3689         start_mdt 2 || error "MDT1 start fail"
3690         start_ost || error "OST0 start fail"
3691         start_mdt 1 || error "MDT0 start fail"
3692         start_ost2 || error "OST1 start fail"
3693
3694         mount_client $MOUNT || error "mount client fails"
3695
3696         mkdir -p $DIR/$tdir || error "mkdir fail"
3697         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3698                         error "create remote dir succeed"
3699
3700         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
3701         rm -rf $DIR/$tdir || error "delete dir fail"
3702
3703         umount_client $MOUNT
3704         stop_mdt 1 || error "MDT0 stop fail"
3705         stop_mdt 2 || error "MDT1 stop fail"
3706         stop_ost || error "OST0 stop fail"
3707         stop_ost2 || error "OST1 stop fail"
3708 }
3709 run_test 71b "start MDT1, OST0, MDT0, OST1"
3710
3711 test_71c() {
3712         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3713         if combined_mgs_mds; then
3714                 skip "needs separate MGS/MDT" && return
3715         fi
3716         local MDTIDX=1
3717
3718         start_ost || error "OST0 start fail"
3719         start_ost2 || error "OST1 start fail"
3720         start_mdt 2 || error "MDT1 start fail"
3721         start_mdt 1 || error "MDT0 start fail"
3722
3723         mount_client $MOUNT || error "mount client fails"
3724
3725         mkdir -p $DIR/$tdir || error "mkdir fail"
3726         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3727                         error "create remote dir succeed"
3728
3729         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
3730         rm -rf $DIR/$tdir || error "delete dir fail"
3731
3732         umount_client $MOUNT
3733         stop_mdt 1 || error "MDT0 stop fail"
3734         stop_mdt 2 || error "MDT1 stop fail"
3735         stop_ost || error "OST0 stop fail"
3736         stop_ost2 || error "OST1 stop fail"
3737
3738 }
3739 run_test 71c "start OST0, OST1, MDT1, MDT0"
3740
3741 test_71d() {
3742         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3743         if combined_mgs_mds; then
3744                 skip "needs separate MGS/MDT" && return
3745         fi
3746         local MDTIDX=1
3747
3748         start_ost || error "OST0 start fail"
3749         start_mdt 2 || error "MDT0 start fail"
3750         start_mdt 1 || error "MDT0 start fail"
3751         start_ost2 || error "OST1 start fail"
3752
3753         mount_client $MOUNT || error "mount client fails"
3754
3755         mkdir -p $DIR/$tdir || error "mkdir fail"
3756         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3757                         error "create remote dir succeed"
3758
3759         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
3760         rm -rf $DIR/$tdir || error "delete dir fail"
3761
3762         umount_client $MOUNT
3763         stop_mdt 1 || error "MDT0 stop fail"
3764         stop_mdt 2 || error "MDT1 stop fail"
3765         stop_ost || error "OST0 stop fail"
3766         stop_ost2 || error "OST1 stop fail"
3767
3768 }
3769 run_test 71d "start OST0, MDT1, MDT0, OST1"
3770
3771 test_71e() {
3772         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
3773         if combined_mgs_mds; then
3774                 skip "needs separate MGS/MDT" && return
3775         fi
3776         local MDTIDX=1
3777
3778         start_ost || error "OST0 start fail"
3779         start_mdt 2 || error "MDT1 start fail"
3780         start_ost2 || error "OST1 start fail"
3781         start_mdt 1 || error "MDT0 start fail"
3782
3783         mount_client $MOUNT || error "mount client fails"
3784
3785         mkdir -p $DIR/$tdir || error "mkdir fail"
3786         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
3787                         error "create remote dir succeed"
3788
3789         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
3790         rm -rf $DIR/$tdir || error "delete dir fail"
3791
3792         umount_client $MOUNT
3793         stop_mdt 1 || error "MDT0 stop fail"
3794         stop_mdt 2 || error "MDT1 stop fail"
3795         stop_ost || error "OST0 stop fail"
3796         stop_ost2 || error "OST1 stop fail"
3797
3798 }
3799 run_test 71e "start OST0, MDT1, OST1, MDT0"
3800
3801 if ! combined_mgs_mds ; then
3802         stop mgs
3803 fi
3804
3805 cleanup_gss
3806
3807 complete $SECONDS
3808 exit_status