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