Whamcloud - gitweb
6446ac6979809937381d9a946389ce0d1da15a48
[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 return codes,
4 #   espcially when most of them are mapped to something else anyway.
5 #   The tests should use error() to describe the failure more clearly,
6 #   and reduce the need to look into the tests to see what failed.
7
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11
12 # bug number for skipped test:     LU-2828
13 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT 59 64"
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 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
57
58 # use small MDS + OST size to speed formatting time
59 # do not use too small MDSSIZE/OSTSIZE, which affect the default jouranl size
60 # STORED_MDSSIZE is used in test_18
61 STORED_MDSSIZE=$MDSSIZE
62 STORED_OSTSIZE=$OSTSIZE
63 MDSSIZE=200000
64 OSTSIZE=200000
65
66 if ! combined_mgs_mds; then
67     # bug number for skipped test:    23954
68     ALWAYS_EXCEPT="$ALWAYS_EXCEPT       24b"
69 fi
70
71 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
72 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
73         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
74 fi
75
76 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
77 # bug number for skipped test:        LU-2778 LU-4444
78         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 57b     69"
79
80 init_logging
81
82 #
83 require_dsh_mds || exit 0
84 require_dsh_ost || exit 0
85 #
86 [ "$SLOW" = "no" ] && EXCEPT_SLOW="30a 31 45 69"
87
88
89 assert_DIR
90
91 gen_config() {
92         # The MGS must be started before the OSTs for a new fs, so start
93         # and stop to generate the startup logs.
94         start_mds
95         start_ost
96         wait_osc_import_state mds ost FULL
97         stop_ost
98         stop_mds
99 }
100
101 reformat_and_config() {
102         reformat
103         if ! combined_mgs_mds ; then
104                 start_mgs
105         fi
106         gen_config
107 }
108
109 writeconf_or_reformat() {
110         # There are at most 2 OSTs for write_conf test
111         # who knows if/where $TUNEFS is installed?
112         # Better reformat if it fails...
113         writeconf_all $MDSCOUNT 2 ||
114                 { echo "tunefs failed, reformatting instead" &&
115                   reformat_and_config && return 0; }
116         return 0
117 }
118
119 reformat() {
120         formatall
121 }
122
123 start_mgs () {
124         echo "start mgs"
125         start mgs $(mgsdevname) $MGS_MOUNT_OPTS
126 }
127
128 start_mdt() {
129         local num=$1
130         local facet=mds$num
131         local dev=$(mdsdevname $num)
132         shift 1
133
134         echo "start mds service on `facet_active_host $facet`"
135         start $facet ${dev} $MDS_MOUNT_OPTS $@ || return 94
136 }
137
138 stop_mdt() {
139         local num=$1
140         local facet=mds$num
141         local dev=$(mdsdevname $num)
142         shift 1
143
144         echo "stop mds service on `facet_active_host $facet`"
145         # These tests all use non-failover stop
146         stop $facet -f  || return 97
147 }
148
149 start_mds() {
150         local num
151
152         for num in $(seq $MDSCOUNT); do
153                 start_mdt $num $@ || return 94
154         done
155 }
156
157 start_mgsmds() {
158         if ! combined_mgs_mds ; then
159                 start_mgs
160         fi
161         start_mds $@
162 }
163
164 stop_mds() {
165         local num
166         for num in $(seq $MDSCOUNT); do
167                 stop_mdt $num || return 97
168         done
169 }
170
171 stop_mgs() {
172        echo "stop mgs service on `facet_active_host mgs`"
173        # These tests all use non-failover stop
174        stop mgs -f  || return 97
175 }
176
177 start_ost() {
178         echo "start ost1 service on `facet_active_host ost1`"
179         start ost1 `ostdevname 1` $OST_MOUNT_OPTS $@ || return 95
180 }
181
182 stop_ost() {
183         echo "stop ost1 service on `facet_active_host ost1`"
184         # These tests all use non-failover stop
185         stop ost1 -f  || return 98
186 }
187
188 start_ost2() {
189         echo "start ost2 service on `facet_active_host ost2`"
190         start ost2 `ostdevname 2` $OST_MOUNT_OPTS $@ || return 92
191 }
192
193 stop_ost2() {
194         echo "stop ost2 service on `facet_active_host ost2`"
195         # These tests all use non-failover stop
196         stop ost2 -f  || return 93
197 }
198
199 mount_client() {
200         local MOUNTPATH=$1
201         echo "mount $FSNAME on ${MOUNTPATH}....."
202         zconf_mount `hostname` $MOUNTPATH  || return 96
203 }
204
205 remount_client() {
206         local mountopt="-o remount,$1"
207         local MOUNTPATH=$2
208         echo "remount '$1' lustre on ${MOUNTPATH}....."
209         zconf_mount `hostname`  $MOUNTPATH "$mountopt"  || return 96
210 }
211
212 umount_client() {
213         local MOUNTPATH=$1
214         echo "umount lustre on ${MOUNTPATH}....."
215         zconf_umount `hostname` $MOUNTPATH || return 97
216 }
217
218 manual_umount_client(){
219         local rc
220         local FORCE=$1
221         echo "manual umount lustre on ${MOUNT}...."
222         do_facet client "umount -d ${FORCE} $MOUNT"
223         rc=$?
224         return $rc
225 }
226
227 setup() {
228         start_mds || error "MDT start failed"
229         start_ost || error "OST start failed"
230         mount_client $MOUNT || error "client start failed"
231         client_up || error "client_up failed"
232 }
233
234 setup_noconfig() {
235         if ! combined_mgs_mds ; then
236                 start_mgs
237         fi
238
239         start_mds
240         start_ost
241         mount_client $MOUNT
242 }
243
244 unload_modules_conf () {
245         if combined_mgs_mds || ! local_mode; then
246                 unload_modules || return 1
247         fi
248 }
249
250 cleanup_nocli() {
251         stop_ost || return 202
252         stop_mds || return 201
253         unload_modules_conf || return 203
254 }
255
256 cleanup() {
257         umount_client $MOUNT || return 200
258         cleanup_nocli || return $?
259 }
260
261 check_mount() {
262         do_facet client "cp /etc/passwd $DIR/a" || return 71
263         do_facet client "rm $DIR/a" || return 72
264         # make sure lustre is actually mounted (touch will block,
265         # but grep won't, so do it after)
266         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
267         echo "setup single mount lustre success"
268 }
269
270 check_mount2() {
271         do_facet client "touch $DIR/a" || return 71
272         do_facet client "rm $DIR/a" || return 72
273         do_facet client "touch $DIR2/a" || return 73
274         do_facet client "rm $DIR2/a" || return 74
275         echo "setup double mount lustre success"
276 }
277
278 build_test_filter
279
280 if [ "$ONLY" == "setup" ]; then
281         setup
282         exit
283 fi
284
285 if [ "$ONLY" == "cleanup" ]; then
286         cleanup
287         exit
288 fi
289
290 init_gss
291
292 #create single point mountpoint
293
294 reformat_and_config
295
296 test_0() {
297         setup
298         check_mount || return 41
299         cleanup || return $?
300 }
301 run_test 0 "single mount setup"
302
303 test_1() {
304         start_mds || error "MDT start failed"
305         start_ost
306         echo "start ost second time..."
307         start_ost && error "2nd OST start should fail"
308         mount_client $MOUNT || error "client start failed"
309         check_mount || return 42
310         cleanup || return $?
311 }
312 run_test 1 "start up ost twice (should return errors)"
313
314 test_2() {
315         start_mdt 1
316         echo "start mds second time.."
317         start_mdt 1 && error "2nd MDT start should fail"
318         start_ost
319         mount_client $MOUNT
320         check_mount || return 43
321         cleanup || return $?
322 }
323 run_test 2 "start up mds twice (should return err)"
324
325 test_3() {
326         setup
327         #mount.lustre returns an error if already in mtab
328         mount_client $MOUNT && error "2nd client mount should fail"
329         check_mount || return 44
330         cleanup || return $?
331 }
332 run_test 3 "mount client twice (should return err)"
333
334 test_4() {
335         setup
336         touch $DIR/$tfile || return 85
337         stop_ost -f
338         cleanup
339         eno=$?
340         # ok for ost to fail shutdown
341         if [ 202 -ne $eno ]; then
342                 return $eno;
343         fi
344         return 0
345 }
346 run_test 4 "force cleanup ost, then cleanup"
347
348 test_5a() {     # was test_5
349         setup
350         touch $DIR/$tfile || return 1
351         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
352
353         stop_mds -f || return 2
354
355         # cleanup may return an error from the failed
356         # disconnects; for now I'll consider this successful
357         # if all the modules have unloaded.
358         umount -d $MOUNT &
359         UMOUNT_PID=$!
360         sleep 6
361         echo "killing umount"
362         kill -TERM $UMOUNT_PID
363         echo "waiting for umount to finish"
364         wait $UMOUNT_PID
365         if grep " $MOUNT " /proc/mounts; then
366                 echo "test 5: /proc/mounts after failed umount"
367                 umount $MOUNT &
368                 UMOUNT_PID=$!
369                 sleep 2
370                 echo "killing umount"
371                 kill -TERM $UMOUNT_PID
372                 echo "waiting for umount to finish"
373                 wait $UMOUNT_PID
374                 grep " $MOUNT " /proc/mounts && echo "test 5: /proc/mounts after second umount" && return 11
375         fi
376
377         manual_umount_client
378         # stop_mds is a no-op here, and should not fail
379         cleanup_nocli || return $?
380         # df may have lingering entry
381         manual_umount_client
382         # mtab may have lingering entry
383         local WAIT=0
384         local MAX_WAIT=20
385         local sleep=1
386         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
387                 sleep $sleep
388                 grep -q $MOUNT" " /etc/mtab || break
389                 echo "Waiting /etc/mtab updated ... "
390                 WAIT=$(( WAIT + sleep))
391         done
392         [ "$WAIT" -eq "$MAX_WAIT" ] && error "/etc/mtab is not updated in $WAIT secs"
393         echo "/etc/mtab updated in $WAIT secs"
394 }
395 run_test 5a "force cleanup mds, then cleanup"
396
397 cleanup_5b () {
398         trap 0
399         start_mgs
400 }
401
402 test_5b() {
403         grep " $MOUNT " /etc/mtab && \
404                 error false "unexpected entry in mtab before mount" && return 10
405
406         local rc=0
407         start_ost
408         if ! combined_mgs_mds ; then
409                 trap cleanup_5b EXIT ERR
410                 start_mds
411                 stop mgs
412         fi
413
414         [ -d $MOUNT ] || mkdir -p $MOUNT
415         mount_client $MOUNT && rc=1
416         grep " $MOUNT " /etc/mtab && \
417                 error "$MOUNT entry in mtab after failed mount" && rc=11
418         umount_client $MOUNT
419         # stop_mds is a no-op here, and should not fail
420         cleanup_nocli || rc=$?
421         if ! combined_mgs_mds ; then
422                 cleanup_5b
423         fi
424         return $rc
425 }
426 run_test 5b "Try to start a client with no MGS (should return errs)"
427
428 test_5c() {
429         grep " $MOUNT " /etc/mtab && \
430                 error false "unexpected entry in mtab before mount" && return 10
431
432         local rc=0
433         start_mds
434         start_ost
435         [ -d $MOUNT ] || mkdir -p $MOUNT
436         local oldfs="${FSNAME}"
437         FSNAME="wrong.${FSNAME}"
438         mount_client $MOUNT || :
439         FSNAME=${oldfs}
440         grep " $MOUNT " /etc/mtab && \
441                 error "$MOUNT entry in mtab after failed mount" && rc=11
442         umount_client $MOUNT
443         cleanup_nocli  || rc=$?
444         return $rc
445 }
446 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
447
448 test_5d() {
449         grep " $MOUNT " /etc/mtab && \
450                 error false "unexpected entry in mtab before mount" && return 10
451
452         local rc=0
453         start_ost
454         start_mds
455         stop_ost -f
456         mount_client $MOUNT || rc=1
457         cleanup  || rc=$?
458         grep " $MOUNT " /etc/mtab && \
459                 error "$MOUNT entry in mtab after unmount" && rc=11
460         return $rc
461 }
462 run_test 5d "mount with ost down"
463
464 test_5e() {
465         grep " $MOUNT " /etc/mtab && \
466                 error false "unexpected entry in mtab before mount" && return 10
467
468         local rc=0
469         start_mds
470         start_ost
471
472 #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
473         do_facet client "lctl set_param fail_loc=0x80000506"
474         mount_client $MOUNT || echo "mount failed (not fatal)"
475         cleanup  || rc=$?
476         grep " $MOUNT " /etc/mtab && \
477                 error "$MOUNT entry in mtab after unmount" && rc=11
478         return $rc
479 }
480 run_test 5e "delayed connect, don't crash (bug 10268)"
481
482 test_5f() {
483         if combined_mgs_mds ; then
484                 skip "combined mgs and mds"
485                 return 0
486         fi
487
488         grep " $MOUNT " /etc/mtab && \
489                 error false "unexpected entry in mtab before mount" && return 10
490
491         local rc=0
492         start_ost
493         [ -d $MOUNT ] || mkdir -p $MOUNT
494         mount_client $MOUNT &
495         local pid=$!
496         echo client_mount pid is $pid
497
498         sleep 5
499
500         if ! ps -f -p $pid >/dev/null; then
501                 wait $pid
502                 rc=$?
503                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
504                 error "mount returns $rc, expected to hang"
505                 rc=11
506                 cleanup || rc=$?
507                 return $rc
508         fi
509
510         # start mds
511         start_mds
512
513         # mount should succeed after start mds
514         wait $pid
515         rc=$?
516         [ $rc -eq 0 ] || error "mount returned $rc"
517         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
518         cleanup || return $?
519         return $rc
520 }
521 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
522
523 test_6() {
524         setup
525         manual_umount_client
526         mount_client ${MOUNT} || return 87
527         touch $DIR/a || return 86
528         cleanup  || return $?
529 }
530 run_test 6 "manual umount, then mount again"
531
532 test_7() {
533         setup
534         manual_umount_client
535         cleanup_nocli || return $?
536 }
537 run_test 7 "manual umount, then cleanup"
538
539 test_8() {
540         setup
541         mount_client $MOUNT2
542         check_mount2 || return 45
543         umount_client $MOUNT2
544         cleanup  || return $?
545 }
546 run_test 8 "double mount setup"
547
548 test_9() {
549         start_ost
550
551         do_facet ost1 lctl set_param debug=\'inode trace\' || return 1
552         do_facet ost1 lctl set_param subsystem_debug=\'mds ost\' || return 1
553
554         CHECK_PTLDEBUG="`do_facet ost1 lctl get_param -n debug`"
555         if [ "$CHECK_PTLDEBUG" ] && { \
556            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
557            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
558            echo "lnet.debug success"
559         else
560            echo "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
561            return 1
562         fi
563         CHECK_SUBSYS="`do_facet ost1 lctl get_param -n subsystem_debug`"
564         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
565            echo "lnet.subsystem_debug success"
566         else
567            echo "lnet.subsystem_debug: want 'mds ost', have '$CHECK_SUBSYS'"
568            return 1
569         fi
570         stop_ost || return $?
571 }
572 run_test 9 "test ptldebug and subsystem for mkfs"
573
574 is_blkdev () {
575         local facet=$1
576         local dev=$2
577         local size=${3:-""}
578
579         local rc=0
580         do_facet $facet "test -b $dev" || rc=1
581         if [[ "$size" ]]; then
582                 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k count=1 skip=$size 2>&1" |\
583                         awk '($3 == "in") { print $1 }')
584                 [[ $in  = "1+0" ]] || rc=1
585         fi
586         return $rc
587 }
588
589 #
590 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
591 # But with new MDS stack we don't care about the mode of local objects
592 # anymore, so this test is removed. See bug 22944 for more details.
593 #
594
595 test_17() {
596         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
597                 skip "Only applicable to ldiskfs-based MDTs"
598                 return
599         fi
600
601         setup
602         check_mount || return 41
603         cleanup || return $?
604
605         echo "Remove mds config log"
606         if ! combined_mgs_mds ; then
607                 stop mgs
608         fi
609
610         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' \
611                 $(mgsdevname) || return \$?" || return $?
612
613         if ! combined_mgs_mds ; then
614                 start_mgs
615         fi
616
617         start_ost
618         start_mds && return 42
619         reformat_and_config
620 }
621 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
622
623 test_18() {
624         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
625                 skip "Only applicable to ldiskfs-based MDTs"
626                 return
627         fi
628
629         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
630
631         local MIN=2000000
632
633         local OK=
634         # check if current MDSSIZE is large enough
635         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE && \
636                 log "use MDSSIZE=$MDSSIZE"
637
638         # check if the global config has a large enough MDSSIZE
639         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] && [ $STORED_MDSSIZE -ge $MIN ] && \
640                 OK=1 && myMDSSIZE=$STORED_MDSSIZE && \
641                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
642
643         # check if the block device is large enough
644         is_blkdev $SINGLEMDS $MDSDEV $MIN
645         local large_enough=$?
646         if [ -n "$OK" ]; then
647                 [ $large_enough -ne 0 ] && OK=""
648         else
649                 [ $large_enough -eq 0 ] && OK=1 && myMDSSIZE=$MIN &&
650                         log "use device $MDSDEV with MIN=$MIN"
651         fi
652
653         # check if a loopback device has enough space for fs metadata (5%)
654
655         if [ -z "$OK" ]; then
656                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
657                         awk '($1 != "Filesystem") {print $4}')
658                 ! [ -z "$SPACE" ]  &&  [ $SPACE -gt $((MIN / 20)) ] && \
659                         OK=1 && myMDSSIZE=$MIN && \
660                         log "use file $MDSDEV with MIN=$MIN"
661         fi
662
663         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
664
665
666         echo "mount mds with large journal..."
667
668         local OLD_MDSSIZE=$MDSSIZE
669         MDSSIZE=$myMDSSIZE
670
671         reformat_and_config
672         echo "mount lustre system..."
673         setup
674         check_mount || return 41
675
676         echo "check journal size..."
677         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
678         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
679                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
680         else
681                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
682         fi
683
684         cleanup || return $?
685
686         MDSSIZE=$OLD_MDSSIZE
687         reformat_and_config
688 }
689 run_test 18 "check mkfs creates large journals"
690
691 test_19a() {
692         start_mds || return 1
693         stop_mds -f || return 2
694 }
695 run_test 19a "start/stop MDS without OSTs"
696
697 test_19b() {
698         start_ost || return 1
699         stop_ost -f || return 2
700 }
701 run_test 19b "start/stop OSTs without MDS"
702
703 test_20() {
704         # first format the ost/mdt
705         start_mds
706         start_ost
707         mount_client $MOUNT
708         check_mount || return 43
709         rm -f $DIR/$tfile
710         remount_client ro $MOUNT || return 44
711         touch $DIR/$tfile && echo "$DIR/$tfile created incorrectly" && return 45
712         [ -e $DIR/$tfile ] && echo "$DIR/$tfile exists incorrectly" && return 46
713         remount_client rw $MOUNT || return 47
714         touch $DIR/$tfile
715         [ ! -f $DIR/$tfile ] && echo "$DIR/$tfile missing" && return 48
716         MCNT=`grep -c $MOUNT /etc/mtab`
717         [ "$MCNT" -ne 1 ] && echo "$MOUNT in /etc/mtab $MCNT times" && return 49
718         umount_client $MOUNT
719         stop_mds
720         stop_ost
721 }
722 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
723
724 test_21a() {
725         start_mds
726         start_ost
727         wait_osc_import_state mds ost FULL
728         stop_ost
729         stop_mds
730 }
731 run_test 21a "start mds before ost, stop ost first"
732
733 test_21b() {
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         start_mds
781
782         echo Client mount with ost in logs, but none running
783         start_ost
784         # wait until mds connected to ost and open client connection
785         wait_osc_import_state mds ost FULL
786         stop_ost
787         mount_client $MOUNT
788         # check_mount will block trying to contact ost
789         mcreate $DIR/$tfile || return 40
790         rm -f $DIR/$tfile || return 42
791         umount_client $MOUNT
792         pass
793
794         echo Client mount with a running ost
795         start_ost
796         if $GSS; then
797                 # if gss enabled, wait full time to let connection from
798                 # mds to ost be established, due to the mismatch between
799                 # initial connect timeout and gss context negotiation timeout.
800                 # This perhaps could be remove after AT landed.
801                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
802                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
803         fi
804         mount_client $MOUNT
805         wait_osc_import_state mds ost FULL
806         wait_osc_import_state client ost FULL
807         check_mount || return 41
808         pass
809
810         cleanup
811 }
812 run_test 22 "start a client before osts (should return errs)"
813
814 test_23a() {    # was test_23
815         setup
816         # fail mds
817         stop $SINGLEMDS
818         # force down client so that recovering mds waits for reconnect
819         local running=$(grep -c $MOUNT /proc/mounts) || true
820         if [ $running -ne 0 ]; then
821                 echo "Stopping client $MOUNT (opts: -f)"
822                 umount -f $MOUNT
823         fi
824
825         # enter recovery on mds
826         start_mds
827         # try to start a new client
828         mount_client $MOUNT &
829         sleep 5
830         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
831         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
832         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
833         ps --ppid $MOUNT_PID
834         ps --ppid $MOUNT_LUSTRE_PID
835         echo "waiting for mount to finish"
836         ps -ef | grep mount
837         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
838         # SIGTERM works but it does not spread to offspring processses
839         kill -s TERM $MOUNT_PID
840         kill -s TERM $MOUNT_LUSTRE_PID
841         # we can not wait $MOUNT_PID because it is not a child of this shell
842         local PID1
843         local PID2
844         local WAIT=0
845         local MAX_WAIT=30
846         local sleep=1
847         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
848                 sleep $sleep
849                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
850                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
851                 echo PID1=$PID1
852                 echo PID2=$PID2
853                 [ -z "$PID1" -a -z "$PID2" ] && break
854                 echo "waiting for mount to finish ... "
855                 WAIT=$(( WAIT + sleep))
856         done
857         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
858                 error "MOUNT_PID $MOUNT_PID and "\
859                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
860                 ps -ef | grep mount
861         fi
862         stop_mds || error "stopping MDSes failed"
863         stop_ost || error "stopping OSSes failed"
864 }
865 run_test 23a "interrupt client during recovery mount delay"
866
867 umount_client $MOUNT
868 cleanup_nocli
869
870 test_23b() {    # was test_23
871         start_mds
872         start_ost
873         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
874         lctl set_param fail_loc=0x80000313
875         mount_client $MOUNT
876         cleanup
877 }
878 run_test 23b "Simulate -EINTR during mount"
879
880 fs2mds_HOST=$mds_HOST
881 fs2ost_HOST=$ost_HOST
882
883 MDSDEV1_2=$fs2mds_DEV
884 OSTDEV1_2=$fs2ost_DEV
885 OSTDEV2_2=$fs3ost_DEV
886
887 cleanup_fs2() {
888         trap 0
889         echo "umount $MOUNT2 ..."
890         umount $MOUNT2 || true
891         echo "stopping fs2mds ..."
892         stop fs2mds -f || true
893         echo "stopping fs2ost ..."
894         stop fs2ost -f || true
895 }
896
897 test_24a() {
898         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
899
900         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
901                 is_blkdev $SINGLEMDS $MDSDEV && \
902                 skip_env "mixed loopback and real device not working" && return
903         fi
904
905         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
906
907         local fs2mdsdev=$(mdsdevname 1_2)
908         local fs2ostdev=$(ostdevname 1_2)
909         local fs2mdsvdev=$(mdsvdevname 1_2)
910         local fs2ostvdev=$(ostvdevname 1_2)
911
912         # test 8-char fsname as well
913         local FSNAME2=test1234
914
915         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --nomgs --mgsnode=$MGSNID \
916                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
917
918         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --fsname=${FSNAME2} \
919                 --reformat $fs2ostdev $fs2ostvdev || exit 10
920
921         setup
922         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
923         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
924         mkdir -p $MOUNT2
925         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || return 1
926         # 1 still works
927         check_mount || return 2
928         # files written on 1 should not show up on 2
929         cp /etc/passwd $DIR/$tfile
930         sleep 10
931         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
932         # 2 should work
933         sleep 5
934         cp /etc/passwd $MOUNT2/b || return 3
935         rm $MOUNT2/b || return 4
936         # 2 is actually mounted
937         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
938         # failover
939         facet_failover fs2mds
940         facet_failover fs2ost
941         df
942         umount_client $MOUNT
943         # the MDS must remain up until last MDT
944         stop_mds
945         MDS=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
946         [ -z "$MDS" ] && error "No MDT" && return 8
947         cleanup_fs2
948         cleanup_nocli || return 6
949 }
950 run_test 24a "Multiple MDTs on a single node"
951
952 test_24b() {
953         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
954
955         if [ -z "$fs2mds_DEV" ]; then
956                 local dev=${SINGLEMDS}_dev
957                 local MDSDEV=${!dev}
958                 is_blkdev $SINGLEMDS $MDSDEV && \
959                 skip_env "mixed loopback and real device not working" && return
960         fi
961
962         local fs2mdsdev=$(mdsdevname 1_2)
963         local fs2mdsvdev=$(mdsvdevname 1_2)
964
965         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --mgs --fsname=${FSNAME}2 \
966                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
967         setup
968         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
969         cleanup || return 6
970 }
971 run_test 24b "Multiple MGSs on a single node (should return err)"
972
973 test_25() {
974         setup
975         check_mount || return 2
976         local MODULES=$($LCTL modules | awk '{ print $2 }')
977         rmmod $MODULES 2>/dev/null || true
978         cleanup || return 6
979 }
980 run_test 25 "Verify modules are referenced"
981
982 test_26() {
983     load_modules
984     # we need modules before mount for sysctl, so make sure...
985     do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
986 #define OBD_FAIL_MDS_FS_SETUP            0x135
987     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000135"
988     start_mds && echo MDS started && return 1
989     lctl get_param -n devices
990     DEVS=$(lctl get_param -n devices | egrep -v MG | wc -l)
991     [ $DEVS -gt 0 ] && return 2
992     # start mds to drop writeconf setting
993     start_mds || return 3
994     stop_mds || return 4
995     unload_modules_conf || return $?
996 }
997 run_test 26 "MDT startup failure cleans LOV (should return errs)"
998
999 test_27a() {
1000         start_ost || return 1
1001         start_mds || return 2
1002         echo "Requeue thread should have started: "
1003         ps -e | grep ll_cfg_requeue
1004         set_conf_param_and_check ost1                                         \
1005            "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" \
1006            "$FSNAME-OST0000.ost.client_cache_seconds" || return 3
1007         cleanup_nocli
1008 }
1009 run_test 27a "Reacquire MGS lock if OST started first"
1010
1011 test_27b() {
1012         # FIXME. ~grev
1013         setup
1014         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" |
1015                         awk '($3 ~ "mdt" && $4 ~ "MDT0000") { print $4 }')
1016
1017         facet_failover $SINGLEMDS
1018         set_conf_param_and_check $SINGLEMDS                             \
1019                 "lctl get_param -n mdt.$device.identity_acquire_expire" \
1020                 "$device.mdt.identity_acquire_expire" || return 3
1021         set_conf_param_and_check client                                 \
1022                 "lctl get_param -n mdc.$device-mdc-*.max_rpcs_in_flight"\
1023                 "$device.mdc.max_rpcs_in_flight" || return 4
1024         check_mount
1025         cleanup
1026 }
1027 run_test 27b "Reacquire MGS lock after failover"
1028
1029 test_28() {
1030         setup
1031         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1032         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1033         ORIG=$($TEST)
1034         FINAL=$(($ORIG + 1))
1035         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 3
1036         FINAL=$(($FINAL + 1))
1037         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 4
1038         umount_client $MOUNT || return 200
1039         mount_client $MOUNT
1040         RESULT=$($TEST)
1041         if [ $RESULT -ne $FINAL ]; then
1042             echo "New config not seen: wanted $FINAL got $RESULT"
1043             return 4
1044         else
1045             echo "New config success: got $RESULT"
1046         fi
1047         set_conf_param_and_check client "$TEST" "$PARAM" $ORIG || return 5
1048         cleanup
1049 }
1050 run_test 28 "permanent parameter setting"
1051
1052 test_28a() { # LU-4221
1053         [[ $(lustre_version_code ost1) -ge $(version_code 2.5.52) ]] ||
1054                 { skip "Need OST version at least 2.5.52" && return 0; }
1055         [ "$(facet_fstype ost1)" = "zfs" ] &&
1056                 skip "LU-4221: no such proc params for ZFS OSTs" && return
1057
1058         local name
1059         local param
1060         local cmd
1061         local old
1062         local new
1063         local device="$FSNAME-OST0000"
1064
1065         setup
1066
1067         # In this test we will set three kinds of proc parameters with
1068         # lctl conf_param:
1069         # 1. the ones moved from the OFD to the OSD, and only their
1070         #    symlinks kept in obdfilter
1071         # 2. non-symlink ones in the OFD
1072         # 3. non-symlink ones in the OSD
1073
1074         # Check 1.
1075         # prepare a symlink parameter in the OFD
1076         name="writethrough_cache_enable"
1077         param="$device.ost.$name"
1078         cmd="$LCTL get_param -n obdfilter.$device.$name"
1079
1080         # conf_param the symlink parameter in the OFD
1081         old=$(do_facet ost1 $cmd)
1082         new=$(((old + 1) % 2))
1083         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1084                 error "lctl conf_param $device.ost.$param=$new failed"
1085
1086         # conf_param the target parameter in the OSD
1087         param="$device.osd.$name"
1088         cmd="$LCTL get_param -n osd-*.$device.$name"
1089         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1090                 error "lctl conf_param $device.osd.$param=$old failed"
1091
1092         # Check 2.
1093         # prepare a non-symlink parameter in the OFD
1094         name="client_cache_seconds"
1095         param="$device.ost.$name"
1096         cmd="$LCTL get_param -n obdfilter.$device.$name"
1097
1098         # conf_param the parameter in the OFD
1099         old=$(do_facet ost1 $cmd)
1100         new=$((old * 2))
1101         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1102                 error "lctl conf_param $device.ost.$param=$new failed"
1103         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1104                 error "lctl conf_param $device.ost.$param=$old failed"
1105
1106         # Check 3.
1107         # prepare a non-symlink parameter in the OSD
1108         name="lma_self_repair"
1109         param="$device.osd.$name"
1110         cmd="$LCTL get_param -n osd-*.$device.$name"
1111
1112         # conf_param the parameter in the OSD
1113         old=$(do_facet ost1 $cmd)
1114         new=$(((old + 1) % 2))
1115         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1116                 error "lctl conf_param $device.osd.$param=$new failed"
1117         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1118                 error "lctl conf_param $device.osd.$param=$old failed"
1119
1120         cleanup
1121 }
1122 run_test 28a "set symlink parameters permanently with conf_param"
1123
1124 test_29() {
1125         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
1126         setup > /dev/null 2>&1
1127         start_ost2
1128         sleep 10
1129
1130         local PARAM="$FSNAME-OST0001.osc.active"
1131         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
1132         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1133
1134         ACTV=$(lctl get_param -n $PROC_ACT)
1135         DEAC=$((1 - $ACTV))
1136         set_conf_param_and_check client \
1137                 "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
1138         # also check ost_server_uuid status
1139         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
1140         if [ -z "$RESULT" ]; then
1141             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
1142             return 3
1143         else
1144             echo "Live client success: got $RESULT"
1145         fi
1146
1147         # check MDTs too
1148         for num in $(seq $MDSCOUNT); do
1149                 local mdtosc=$(get_mdtosc_proc_path mds${num} $FSNAME-OST0001)
1150                 local MPROC="osc.$mdtosc.active"
1151                 local MAX=30
1152                 local WAIT=0
1153                 while [ 1 ]; do
1154                         sleep 5
1155                         RESULT=$(do_facet mds${num} " lctl get_param -n $MPROC")
1156                         [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
1157                         if [ $RESULT -eq $DEAC ]; then
1158                                 echo -n "MDT deactivated also after"
1159                                 echo "$WAIT sec (got $RESULT)"
1160                                 break
1161                         fi
1162                         WAIT=$((WAIT + 5))
1163                         if [ $WAIT -eq $MAX ]; then
1164                                 echo -n "MDT not deactivated: wanted $DEAC"
1165                                 echo  "got $RESULT"
1166                                 return 4
1167                         fi
1168                         echo "Waiting $(($MAX - $WAIT))secs for MDT deactivated"
1169                 done
1170         done
1171         # test new client starts deactivated
1172         umount_client $MOUNT || return 200
1173         mount_client $MOUNT
1174         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1175         if [ -z "$RESULT" ]; then
1176             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
1177             return 5
1178         else
1179             echo "New client success: got $RESULT"
1180         fi
1181
1182         # make sure it reactivates
1183         set_conf_param_and_check client \
1184                 "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
1185
1186         umount_client $MOUNT
1187         stop_ost2
1188         cleanup_nocli
1189         #writeconf to remove all ost2 traces for subsequent tests
1190         writeconf_or_reformat
1191 }
1192 run_test 29 "permanently remove an OST"
1193
1194 test_30a() {
1195         setup
1196
1197         echo Big config llog
1198         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1199         ORIG=$($TEST)
1200         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1201         for i in ${LIST[@]}; do
1202                 set_conf_param_and_check client "$TEST" \
1203                         "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
1204         done
1205         # make sure client restart still works
1206         umount_client $MOUNT
1207         mount_client $MOUNT || return 4
1208         [ "$($TEST)" -ne "$i" ] && error "Param didn't stick across restart $($TEST) != $i"
1209         pass
1210
1211         echo Erase parameter setting
1212         do_facet mgs "$LCTL conf_param -d $FSNAME.llite.max_read_ahead_whole_mb" || return 6
1213         umount_client $MOUNT
1214         mount_client $MOUNT || return 6
1215         FINAL=$($TEST)
1216         echo "deleted (default) value=$FINAL, orig=$ORIG"
1217         # assumes this parameter started at the default value
1218         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1219
1220         cleanup
1221 }
1222 run_test 30a "Big config llog and conf_param deletion"
1223
1224 test_30b() {
1225         setup
1226
1227         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1228         # numerical part of it. Hopefully that's not already a failover address for
1229         # the server.
1230         OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
1231         ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1232         NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1233         NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1234         echo "Using fake nid $NEW"
1235
1236         TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1237         set_conf_param_and_check client "$TEST" \
1238                 "$FSNAME-OST0000.failover.node" $NEW ||
1239                 error "didn't add failover nid $NEW"
1240         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1241         echo $NIDS
1242         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1243         echo "should have 2 failover nids: $NIDCOUNT"
1244         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1245         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" || error "conf_param delete failed"
1246         umount_client $MOUNT
1247         mount_client $MOUNT || return 3
1248
1249         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1250         echo $NIDS
1251         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1252         echo "only 1 final nid should remain: $NIDCOUNT"
1253         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1254
1255         cleanup
1256 }
1257 run_test 30b "Remove failover nids"
1258
1259 test_31() { # bug 10734
1260         # ipaddr must not exist
1261         $MOUNT_CMD 4.3.2.1@tcp:/lustre $MOUNT || true
1262         cleanup
1263 }
1264 run_test 31 "Connect to non-existent node (shouldn't crash)"
1265
1266
1267 T32_QID=60000
1268 T32_BLIMIT=20480 # Kbytes
1269 T32_ILIMIT=2
1270
1271 #
1272 # This is not really a test but a tool to create new disk
1273 # image tarballs for the upgrade tests.
1274 #
1275 # Disk image tarballs should be created on single-node
1276 # clusters by running this test with default configurations
1277 # plus a few mandatory environment settings that are verified
1278 # at the beginning of the test.
1279 #
1280 test_32newtarball() {
1281         local version
1282         local dst=.
1283         local src=/etc/rc.d
1284         local tmp=$TMP/t32_image_create
1285
1286         if [ $FSNAME != t32fs -o $MDSCOUNT -ne 1 -o                                                             \
1287                  \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o $OSTCOUNT -ne 1 -o                      \
1288                  -z "$OSTDEV1" ]; then
1289                 error "Needs FSNAME=t32fs MDSCOUNT=1 MDSDEV1=<nonexistent_file>"        \
1290                           "(or MDSDEV, in the case of b1_8) OSTCOUNT=1"                                 \
1291                           "OSTDEV1=<nonexistent_file>"
1292         fi
1293
1294         mkdir $tmp || {
1295                 echo "Found stale $tmp"
1296                 return 1
1297         }
1298
1299         mkdir $tmp/src
1300         tar cf - -C $src . | tar xf - -C $tmp/src
1301         dd if=/dev/zero of=$tmp/src/t32_qf_old bs=1M \
1302                 count=$(($T32_BLIMIT / 1024 / 2))
1303         chown $T32_QID.$T32_QID $tmp/src/t32_qf_old
1304
1305         # format ost with comma-separated NIDs to verify LU-4460
1306         local failnid="$(h2$NETTYPE 1.2.3.4),$(h2$NETTYPE 4.3.2.1)"
1307         MGSNID="$MGSNID,$MGSNID" OSTOPT="--failnode=$failnid" formatall
1308
1309         setupall
1310
1311         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1312                 $LFS quotacheck -ug /mnt/$FSNAME
1313         $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
1314                 /mnt/$FSNAME
1315
1316         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1317         stopall
1318
1319         mkdir $tmp/img
1320
1321         setupall
1322         pushd /mnt/$FSNAME
1323         ls -Rni --time-style=+%s >$tmp/img/list
1324         find . ! -name .lustre -type f -exec sha1sum {} \; |
1325                 sort -k 2 >$tmp/img/sha1sums
1326         popd
1327         $LCTL get_param -n version | head -n 1 |
1328                 sed -e 's/^lustre: *//' >$tmp/img/commit
1329
1330         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1331                 $LFS quotaon -ug /mnt/$FSNAME
1332         $LFS quota -u $T32_QID -v /mnt/$FSNAME
1333         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1334                 awk 'BEGIN { num='1' } { if ($1 == "'/mnt/$FSNAME'") \
1335                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1336                 | tr -d "*" > $tmp/img/bspace
1337         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1338                 awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
1339                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1340                 | tr -d "*" > $tmp/img/ispace
1341
1342         stopall
1343
1344         pushd $tmp/src
1345         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1346         popd
1347
1348         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1349                 echo "Data verification failed"
1350         fi
1351
1352         uname -r >$tmp/img/kernel
1353         uname -m >$tmp/img/arch
1354
1355         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1356         mv $OSTDEV1 $tmp/img
1357
1358         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1359                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1360         dst=$(cd $dst; pwd)
1361         pushd $tmp/img
1362         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1363         popd
1364
1365         rm -r $tmp
1366 }
1367 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1368
1369 #
1370 # The list of applicable tarballs is returned via the caller's
1371 # variable "tarballs".
1372 #
1373 t32_check() {
1374         local node=$(facet_active_host $SINGLEMDS)
1375         local r="do_node $node"
1376
1377         if [ "$CLIENTONLY" ]; then
1378                 skip "Client-only testing"
1379                 exit 0
1380         fi
1381
1382         if ! $r which $TUNEFS; then
1383                 skip_env "tunefs.lustre required on $node"
1384                 exit 0
1385         fi
1386
1387         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1388
1389         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 -name \'disk*-$IMGTYPE.tar.bz2\')
1390
1391         if [ -z "$tarballs" ]; then
1392                 skip "No applicable tarballs found"
1393                 exit 0
1394         fi
1395 }
1396
1397 t32_test_cleanup() {
1398         local tmp=$TMP/t32
1399         local fstype=$(facet_fstype $SINGLEMDS)
1400         local rc=$?
1401
1402         if $shall_cleanup_lustre; then
1403                 umount $tmp/mnt/lustre || rc=$?
1404         fi
1405         if $shall_cleanup_mdt; then
1406                 $r umount -d $tmp/mnt/mdt || rc=$?
1407         fi
1408         if $shall_cleanup_mdt1; then
1409                 $r umount -d $tmp/mnt/mdt1 || rc=$?
1410         fi
1411         if $shall_cleanup_ost; then
1412                 $r umount -d $tmp/mnt/ost || rc=$?
1413         fi
1414
1415         $r rm -rf $tmp
1416         rm -rf $tmp
1417         if [ $fstype == "zfs" ]; then
1418                 $r $ZPOOL destroy t32fs-mdt1 || rc=$?
1419                 $r $ZPOOL destroy t32fs-ost1 || rc=$?
1420         fi
1421         return $rc
1422 }
1423
1424 t32_bits_per_long() {
1425         #
1426         # Yes, this is not meant to be perfect.
1427         #
1428         case $1 in
1429                 ppc64|x86_64)
1430                         echo -n 64;;
1431                 i*86)
1432                         echo -n 32;;
1433         esac
1434 }
1435
1436 t32_reload_modules() {
1437         local node=$1
1438         local all_removed=false
1439         local i=0
1440
1441         while ((i < 20)); do
1442                 echo "Unloading modules on $node: Attempt $i"
1443                 do_rpc_nodes $node $LUSTRE_RMMOD $(facet_fstype $SINGLEMDS) &&
1444                         all_removed=true
1445                 do_rpc_nodes $node check_mem_leak || return 1
1446                 if $all_removed; then
1447                         do_rpc_nodes $node load_modules
1448                         return 0
1449                 fi
1450                 sleep 5
1451                 i=$((i + 1))
1452         done
1453         echo "Unloading modules on $node: Given up"
1454         return 1
1455 }
1456
1457 t32_wait_til_devices_gone() {
1458         local node=$1
1459         local devices
1460         local loops
1461         local i=0
1462
1463         echo wait for devices to go
1464         while ((i < 20)); do
1465                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1466                 loops=$(do_rpc_nodes $node losetup -a | grep -c t32)
1467                 ((devices == 0 && loops == 0)) && return 0
1468                 sleep 5
1469                 i=$((i + 1))
1470         done
1471         echo "waiting for dev on $node: dev $devices loop $loops given up"
1472         do_rpc_nodes $node "losetup -a"
1473         do_rpc_nodes $node "$LCTL devices_list"
1474         return 1
1475 }
1476
1477 t32_verify_quota() {
1478         local node=$1
1479         local fsname=$2
1480         local mnt=$3
1481         local fstype=$(facet_fstype $SINGLEMDS)
1482         local qval
1483         local cmd
1484
1485         $LFS quota -u $T32_QID -v $mnt
1486
1487         qval=$($LFS quota -v -u $T32_QID $mnt |
1488                 awk 'BEGIN { num='1' } { if ($1 == "'$mnt'") \
1489                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1490                 | tr -d "*")
1491         [ $qval -eq $img_bspace ] || {
1492                 echo "bspace, act:$qval, exp:$img_bspace"
1493                 return 1
1494         }
1495
1496         qval=$($LFS quota -v -u $T32_QID $mnt |
1497                 awk 'BEGIN { num='5' } { if ($1 == "'$mnt'") \
1498                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1499                 | tr -d "*")
1500         [ $qval -eq $img_ispace ] || {
1501                 echo "ispace, act:$qval, exp:$img_ispace"
1502                 return 1
1503         }
1504
1505         qval=$($LFS quota -v -u $T32_QID $mnt |
1506                 awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
1507                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1508                 | tr -d "*")
1509         [ $qval -eq $T32_BLIMIT ] || {
1510                 echo "blimit, act:$qval, exp:$T32_BLIMIT"
1511                 return 1
1512         }
1513
1514         qval=$($LFS quota -v -u $T32_QID $mnt |
1515                 awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
1516                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1517                 | tr -d "*")
1518         [ $qval -eq $T32_ILIMIT ] || {
1519                 echo "ilimit, act:$qval, exp:$T32_ILIMIT"
1520                 return 1
1521         }
1522
1523         do_node $node $LCTL conf_param $fsname.quota.mdt=ug
1524         cmd="$LCTL get_param -n osd-$fstype.$fsname-MDT0000"
1525         cmd=$cmd.quota_slave.enabled
1526         wait_update $node "$cmd" "ug" || {
1527                 echo "Enable mdt quota failed"
1528                 return 1
1529         }
1530
1531         do_node $node $LCTL conf_param $fsname.quota.ost=ug
1532         cmd="$LCTL get_param -n osd-$fstype.$fsname-OST0000"
1533         cmd=$cmd.quota_slave.enabled
1534         wait_update $node "$cmd" "ug" || {
1535                 echo "Enable ost quota failed"
1536                 return 1
1537         }
1538
1539         chmod 0777 $mnt
1540         runas -u $T32_QID -g $T32_QID dd if=/dev/zero of=$mnt/t32_qf_new \
1541                 bs=1M count=$(($T32_BLIMIT / 1024)) oflag=sync && {
1542                 echo "Write succeed, but expect -EDQUOT"
1543                 return 1
1544         }
1545         rm -f $mnt/t32_qf_new
1546
1547         runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
1548                 $T32_ILIMIT && {
1549                 echo "Create succeed, but expect -EDQUOT"
1550                 return 1
1551         }
1552         unlinkmany $mnt/t32_qf_ $T32_ILIMIT
1553
1554         return 0
1555 }
1556
1557 t32_test() {
1558         local tarball=$1
1559         local writeconf=$2
1560         local dne_upgrade=${dne_upgrade:-"no"}
1561         local ff_convert=${ff_convert:-"no"}
1562         local shall_cleanup_mdt=false
1563         local shall_cleanup_mdt1=false
1564         local shall_cleanup_ost=false
1565         local shall_cleanup_lustre=false
1566         local node=$(facet_active_host $SINGLEMDS)
1567         local r="do_node $node"
1568         local node2=$(facet_active_host mds2)
1569         local tmp=$TMP/t32
1570         local img_commit
1571         local img_kernel
1572         local img_arch
1573         local img_bspace
1574         local img_ispace
1575         local fsname=t32fs
1576         local nid=$($r $LCTL list_nids | head -1)
1577         local mopts
1578         local uuid
1579         local nrpcs_orig
1580         local nrpcs
1581         local list
1582         local fstype=$(facet_fstype $SINGLEMDS)
1583         local mdt_dev=$tmp/mdt
1584         local ost_dev=$tmp/ost
1585
1586         trap 'trap - RETURN; t32_test_cleanup' RETURN
1587
1588         mkdir -p $tmp/mnt/lustre
1589         $r mkdir -p $tmp/mnt/{mdt,ost}
1590         $r tar xjvf $tarball -S -C $tmp || {
1591                 error_noexit "Unpacking the disk image tarball"
1592                 return 1
1593         }
1594         img_commit=$($r cat $tmp/commit)
1595         img_kernel=$($r cat $tmp/kernel)
1596         img_arch=$($r cat $tmp/arch)
1597         img_bspace=$($r cat $tmp/bspace)
1598         img_ispace=$($r cat $tmp/ispace)
1599         echo "Upgrading from $(basename $tarball), created with:"
1600         echo "  Commit: $img_commit"
1601         echo "  Kernel: $img_kernel"
1602         echo "    Arch: $img_arch"
1603
1604         local version=$(version_code $img_commit)
1605         [[ $version -ge $(version_code 2.5.0) ]] && ff_convert="no"
1606
1607         if [ $fstype == "zfs" ]; then
1608                 # import pool first
1609                 $r $ZPOOL import -f -d $tmp t32fs-mdt1
1610                 $r $ZPOOL import -f -d $tmp t32fs-ost1
1611                 mdt_dev=t32fs-mdt1/mdt1
1612                 ost_dev=t32fs-ost1/ost1
1613                 wait_update_facet $SINGLEMDS "$ZPOOL list |
1614                         awk '/^t32fs-mdt1/ { print \\\$1 }'" "t32fs-mdt1" || {
1615                                 error_noexit "import zfs pool failed"
1616                                 return 1
1617                         }
1618         fi
1619
1620         $r $LCTL set_param debug="$PTLDEBUG"
1621
1622         $r $TUNEFS --dryrun $mdt_dev || {
1623                 $r losetup -a
1624                 error_noexit "tunefs.lustre before mounting the MDT"
1625                 return 1
1626         }
1627         if [ "$writeconf" ]; then
1628                 mopts=writeconf
1629                 if [ $fstype == "ldiskfs" ]; then
1630                         mopts="loop,$mopts"
1631                         $r $TUNEFS --quota $mdt_dev || {
1632                                 $r losetup -a
1633                                 error_noexit "Enable mdt quota feature"
1634                                 return 1
1635                         }
1636                 fi
1637         else
1638                 if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1639                         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
1640                         { skip "LU-2200: Cannot run over Inifiniband w/o lctl replace_nids "
1641                                 "(Need MGS version at least 2.3.59)"; return 0; }
1642
1643                         local osthost=$(facet_active_host ost1)
1644                         local ostnid=$(do_node $osthost $LCTL list_nids | head -1)
1645
1646                         mopts=nosvc
1647                         if [ $fstype == "ldiskfs" ]; then
1648                                 mopts="loop,$mopts"
1649                         fi
1650                         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt
1651                         $r lctl replace_nids $fsname-OST0000 $ostnid
1652                         $r lctl replace_nids $fsname-MDT0000 $nid
1653                         $r umount -d $tmp/mnt/mdt
1654                 fi
1655
1656                 mopts=exclude=$fsname-OST0000
1657                 if [ $fstype == "ldiskfs" ]; then
1658                         mopts="loop,$mopts"
1659                 fi
1660         fi
1661
1662         t32_wait_til_devices_gone $node
1663
1664         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
1665                 $r losetup -a
1666                 error_noexit "Mounting the MDT"
1667                 return 1
1668         }
1669         shall_cleanup_mdt=true
1670
1671         if [ "$dne_upgrade" != "no" ]; then
1672                 local fs2mdsdev=$(mdsdevname 1_2)
1673                 local fs2mdsvdev=$(mdsvdevname 1_2)
1674
1675                 echo "mkfs new MDT on ${fs2mdsdev}...."
1676                 if [ $(facet_fstype mds1) == ldiskfs ]; then
1677                         mkfsoptions="--mkfsoptions=\\\"-J size=8\\\""
1678                 fi
1679
1680                 add fs2mds $(mkfs_opts mds2 $fs2mdsdev $fsname) --reformat \
1681                            $mkfsoptions $fs2mdsdev $fs2mdsvdev > /dev/null || {
1682                         error_noexit "Mkfs new MDT failed"
1683                         return 1
1684                 }
1685
1686                 $r $TUNEFS --dryrun $fs2mdsdev || {
1687                         error_noexit "tunefs.lustre before mounting the MDT"
1688                         return 1
1689                 }
1690
1691                 echo "mount new MDT....$fs2mdsdev"
1692                 $r mkdir -p $tmp/mnt/mdt1
1693                 $r $MOUNT_CMD -o $mopts $fs2mdsdev $tmp/mnt/mdt1 || {
1694                         error_noexit "mount mdt1 failed"
1695                         return 1
1696                 }
1697
1698                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
1699                         error_noexit "enable remote dir create failed"
1700
1701                 shall_cleanup_mdt1=true
1702         fi
1703
1704         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1705                 error_noexit "Getting MDT UUID"
1706                 return 1
1707         }
1708         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1709                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1710                 return 1
1711         fi
1712
1713         $r $TUNEFS --dryrun $ost_dev || {
1714                 error_noexit "tunefs.lustre before mounting the OST"
1715                 return 1
1716         }
1717         if [ "$writeconf" ]; then
1718                 mopts=mgsnode=$nid,$writeconf
1719                 if [ $fstype == "ldiskfs" ]; then
1720                         mopts="loop,$mopts"
1721                         $r $TUNEFS --quota $ost_dev || {
1722                                 $r losetup -a
1723                                 error_noexit "Enable ost quota feature"
1724                                 return 1
1725                         }
1726                 fi
1727         else
1728                 mopts=mgsnode=$nid
1729                 if [ $fstype == "ldiskfs" ]; then
1730                         mopts="loop,$mopts"
1731                 fi
1732         fi
1733         $r $MOUNT_CMD -o $mopts $ost_dev $tmp/mnt/ost || {
1734                 error_noexit "Mounting the OST"
1735                 return 1
1736         }
1737         shall_cleanup_ost=true
1738
1739         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1740                 error_noexit "Getting OST UUID"
1741                 return 1
1742         }
1743         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1744                 error_noexit "Unexpected OST UUID: \"$uuid\""
1745                 return 1
1746         fi
1747
1748         $r $LCTL conf_param $fsname-OST0000.osc.max_dirty_mb=15 || {
1749                 error_noexit "Setting \"max_dirty_mb\""
1750                 return 1
1751         }
1752         $r $LCTL conf_param $fsname-OST0000.failover.node=$nid || {
1753                 error_noexit "Setting OST \"failover.node\""
1754                 return 1
1755         }
1756         $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1757                 error_noexit "Setting \"max_rpcs_in_flight\""
1758                 return 1
1759         }
1760         $r $LCTL conf_param $fsname-MDT0000.failover.node=$nid || {
1761                 error_noexit "Setting MDT \"failover.node\""
1762                 return 1
1763         }
1764         $r $LCTL pool_new $fsname.interop || {
1765                 error_noexit "Setting \"interop\""
1766                 return 1
1767         }
1768         $r $LCTL conf_param $fsname-MDT0000.lov.stripesize=4M || {
1769                 error_noexit "Setting \"lov.stripesize\""
1770                 return 1
1771         }
1772
1773         if [ "$ff_convert" != "no" -a $(facet_fstype ost1) == "ldiskfs" ]; then
1774                 $r $LCTL lfsck_start -M $fsname-OST0000 || {
1775                         error_noexit "Start OI scrub on OST0"
1776                         return 1
1777                 }
1778
1779                 # The oi_scrub should be on ost1, but for test_32(),
1780                 # all on the SINGLEMDS.
1781                 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1782                         osd-ldiskfs.$fsname-OST0000.oi_scrub |
1783                         awk '/^status/ { print \\\$2 }'" "completed" 30 || {
1784                         error_noexit "Failed to get the expected 'completed'"
1785                         return 1
1786                 }
1787
1788                 local UPDATED=$($r $LCTL get_param -n \
1789                                 osd-ldiskfs.$fsname-OST0000.oi_scrub |
1790                                 awk '/^updated/ { print $2 }')
1791                 [ $UPDATED -ge 1 ] || {
1792                         error_noexit "Only $UPDATED objects have been converted"
1793                         return 1
1794                 }
1795         fi
1796
1797         if [ "$dne_upgrade" != "no" ]; then
1798                 $r $LCTL conf_param \
1799                                 $fsname-MDT0001.mdc.max_rpcs_in_flight=9 || {
1800                         error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
1801                         return 1
1802                 }
1803                 $r $LCTL conf_param $fsname-MDT0001.failover.node=$nid || {
1804                         error_noexit "Setting MDT1 \"failover.node\""
1805                         return 1
1806                 }
1807                 $r $LCTL conf_param $fsname-MDT0001.lov.stripesize=4M || {
1808                         error_noexit "Setting MDT1 \"lov.stripesize\""
1809                         return 1
1810                 }
1811
1812         fi
1813
1814         if [ "$writeconf" ]; then
1815                 $MOUNT_CMD $nid:/$fsname $tmp/mnt/lustre || {
1816                         error_noexit "Mounting the client"
1817                         return 1
1818                 }
1819                 shall_cleanup_lustre=true
1820                 $LCTL set_param debug="$PTLDEBUG"
1821
1822                 t32_verify_quota $node $fsname $tmp/mnt/lustre || {
1823                         error_noexit "verify quota failed"
1824                         return 1
1825                 }
1826
1827                 if [ "$dne_upgrade" != "no" ]; then
1828                         $LFS mkdir -i 1 $tmp/mnt/lustre/remote_dir || {
1829                                 error_noexit "set remote dir failed"
1830                                 return 1
1831                         }
1832
1833                         pushd $tmp/mnt/lustre
1834                         tar -cf - . --exclude=./remote_dir |
1835                                 tar -xvf - -C remote_dir 1>/dev/null || {
1836                                 error_noexit "cp to remote dir failed"
1837                                 return 1
1838                         }
1839                         popd
1840                 fi
1841
1842                 dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
1843                         error_noexit "dd failed"
1844                         return 1
1845                 }
1846                 rm -rf $tmp/mnt/lustre/tmp_file || {
1847                         error_noexit "rm failed"
1848                         return 1
1849                 }
1850
1851                 if $r test -f $tmp/sha1sums; then
1852                         # LU-2393 - do both sorts on same node to ensure locale
1853                         # is identical
1854                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
1855                         if [ "$dne_upgrade" != "no" ]; then
1856                                 pushd $tmp/mnt/lustre/remote_dir
1857                         else
1858                                 pushd $tmp/mnt/lustre
1859                         fi
1860
1861                         find ! -name .lustre -type f -exec sha1sum {} \; |
1862                                 sort -k 2 >$tmp/sha1sums || {
1863                                 error_noexit "sha1sum"
1864                                 return 1
1865                         }
1866                         popd
1867                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
1868                                 error_noexit "sha1sum verification failed"
1869                                 return 1
1870                         fi
1871                 else
1872                         echo "sha1sum verification skipped"
1873                 fi
1874
1875                 if [ "$dne_upgrade" != "no" ]; then
1876                         rm -rf $tmp/mnt/lustre/remote_dir || {
1877                                 error_noexit "remove remote dir failed"
1878                                 return 1
1879                         }
1880                 fi
1881
1882                 if $r test -f $tmp/list; then
1883                         #
1884                         # There is not a Test Framework API to copy files to or
1885                         # from a remote node.
1886                         #
1887                         # LU-2393 - do both sorts on same node to ensure locale
1888                         # is identical
1889                         $r cat $tmp/list | sort -k 6 >$tmp/list.orig
1890                         pushd $tmp/mnt/lustre
1891                         ls -Rni --time-style=+%s | sort -k 6 >$tmp/list || {
1892                                 error_noexit "ls"
1893                                 return 1
1894                         }
1895                         popd
1896                         #
1897                         # 32-bit and 64-bit clients use different algorithms to
1898                         # convert FIDs into inode numbers.  Hence, remove the inode
1899                         # numbers from the lists, if the original list was created
1900                         # on an architecture with different number of bits per
1901                         # "long".
1902                         #
1903                         if [ $(t32_bits_per_long $(uname -m)) != \
1904                                 $(t32_bits_per_long $img_arch) ]; then
1905                                 echo "Different number of bits per \"long\" from the disk image"
1906                                 for list in list.orig list; do
1907                                         sed -i -e 's/^[0-9]\+[ \t]\+//' $tmp/$list
1908                                 done
1909                         fi
1910                         if ! diff -ub $tmp/list.orig $tmp/list; then
1911                                 error_noexit "list verification failed"
1912                                 return 1
1913                         fi
1914                 else
1915                         echo "list verification skipped"
1916                 fi
1917
1918                 #
1919                 # When adding new data verification tests, please check for
1920                 # the presence of the required reference files first, like
1921                 # the "sha1sums" and "list" tests above, to avoid the need to
1922                 # regenerate every image for each test addition.
1923                 #
1924
1925                 nrpcs_orig=$($LCTL get_param \
1926                                 -n mdc.*MDT0000*.max_rpcs_in_flight) || {
1927                         error_noexit "Getting \"max_rpcs_in_flight\""
1928                         return 1
1929                 }
1930                 nrpcs=$((nrpcs_orig + 5))
1931                 $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=$nrpcs || {
1932                         error_noexit "Changing \"max_rpcs_in_flight\""
1933                         return 1
1934                 }
1935                 wait_update $HOSTNAME "$LCTL get_param \
1936                         -n mdc.*MDT0000*.max_rpcs_in_flight" $nrpcs || {
1937                         error_noexit "Verifying \"max_rpcs_in_flight\""
1938                         return 1
1939                 }
1940
1941                 umount $tmp/mnt/lustre || {
1942                         error_noexit "Unmounting the client"
1943                         return 1
1944                 }
1945                 shall_cleanup_lustre=false
1946         else
1947                 if [ "$dne_upgrade" != "no" ]; then
1948                         $r umount -d $tmp/mnt/mdt1 || {
1949                                 error_noexit "Unmounting the MDT2"
1950                                 return 1
1951                         }
1952                         shall_cleanup_mdt1=false
1953                 fi
1954
1955                 $r umount -d $tmp/mnt/mdt || {
1956                         error_noexit "Unmounting the MDT"
1957                         return 1
1958                 }
1959                 shall_cleanup_mdt=false
1960
1961                 $r umount -d $tmp/mnt/ost || {
1962                         error_noexit "Unmounting the OST"
1963                         return 1
1964                 }
1965                 shall_cleanup_ost=false
1966
1967                 t32_reload_modules $node || {
1968                         error_noexit "Reloading modules"
1969                         return 1
1970                 }
1971
1972                 # mount a second time to make sure we didnt leave upgrade flag on
1973                 $r $TUNEFS --dryrun $mdt_dev || {
1974                         $r losetup -a
1975                         error_noexit "tunefs.lustre before remounting the MDT"
1976                         return 1
1977                 }
1978
1979                 mopts=exclude=$fsname-OST0000
1980                 if [ $fstype == "ldiskfs" ]; then
1981                         mopts="loop,$mopts"
1982                 fi
1983                 $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
1984                         error_noexit "Remounting the MDT"
1985                         return 1
1986                 }
1987                 shall_cleanup_mdt=true
1988         fi
1989 }
1990
1991 test_32a() {
1992         local tarballs
1993         local tarball
1994         local rc=0
1995
1996         t32_check
1997         for tarball in $tarballs; do
1998                 t32_test $tarball || let "rc += $?"
1999         done
2000         return $rc
2001 }
2002 run_test 32a "Upgrade (not live)"
2003
2004 test_32b() {
2005         local tarballs
2006         local tarball
2007         local rc=0
2008
2009         t32_check
2010         for tarball in $tarballs; do
2011                 t32_test $tarball writeconf || let "rc += $?"
2012         done
2013         return $rc
2014 }
2015 run_test 32b "Upgrade with writeconf"
2016
2017 test_32c() {
2018         local tarballs
2019         local tarball
2020         local rc=0
2021
2022         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2023         t32_check
2024         for tarball in $tarballs; do
2025                 dne_upgrade=yes t32_test $tarball writeconf || rc=$?
2026         done
2027         return $rc
2028 }
2029 run_test 32c "dne upgrade test"
2030
2031 test_32d() {
2032         local tarballs
2033         local tarball
2034         local rc=0
2035
2036         t32_check
2037         for tarball in $tarballs; do
2038                 ff_convert=yes t32_test $tarball || rc=$?
2039         done
2040         return $rc
2041 }
2042 run_test 32d "convert ff test"
2043
2044 test_33a() { # bug 12333, was test_33
2045         local rc=0
2046         local FSNAME2=test-123
2047         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2048         local mkfsoptions
2049
2050         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
2051
2052         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
2053                 local dev=${SINGLEMDS}_dev
2054                 local MDSDEV=${!dev}
2055                 is_blkdev $SINGLEMDS $MDSDEV && \
2056                 skip_env "mixed loopback and real device not working" && return
2057         fi
2058
2059         local fs2mdsdev=$(mdsdevname 1_2)
2060         local fs2ostdev=$(ostdevname 1_2)
2061         local fs2mdsvdev=$(mdsvdevname 1_2)
2062         local fs2ostvdev=$(ostvdevname 1_2)
2063
2064         if [ $(facet_fstype mds1) == ldiskfs ]; then
2065                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
2066         fi
2067
2068         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2069                 --reformat $mkfsoptions $fs2mdsdev $fs2mdsvdev || exit 10
2070         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2071                 --fsname=${FSNAME2} --index=8191 --reformat $fs2ostdev \
2072                 $fs2ostvdev || exit 10
2073
2074         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
2075         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2076         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
2077         mkdir -p $MOUNT2
2078         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
2079         echo "ok."
2080
2081         cp /etc/hosts $MOUNT2/ || rc=3
2082         $LFS getstripe $MOUNT2/hosts
2083
2084         umount -d $MOUNT2
2085         stop fs2ost -f
2086         stop fs2mds -f
2087         cleanup_nocli || rc=6
2088         return $rc
2089 }
2090 run_test 33a "Mount ost with a large index number"
2091
2092 test_33b() {    # was test_34
2093         setup
2094
2095         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
2096         # Drop lock cancelation reply during umount
2097         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
2098         do_facet client lctl set_param fail_loc=0x80000304
2099         #lctl set_param debug=-1
2100         umount_client $MOUNT
2101         cleanup
2102 }
2103 run_test 33b "Drop cancel during umount"
2104
2105 test_34a() {
2106         setup
2107         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
2108         manual_umount_client
2109         rc=$?
2110         do_facet client killall -USR1 multiop
2111         if [ $rc -eq 0 ]; then
2112                 error "umount not fail!"
2113         fi
2114         sleep 1
2115         cleanup
2116 }
2117 run_test 34a "umount with opened file should be fail"
2118
2119
2120 test_34b() {
2121         setup
2122         touch $DIR/$tfile || return 1
2123         stop_mds --force || return 2
2124
2125         manual_umount_client --force
2126         rc=$?
2127         if [ $rc -ne 0 ]; then
2128                 error "mtab after failed umount - rc $rc"
2129         fi
2130
2131         cleanup
2132         return 0
2133 }
2134 run_test 34b "force umount with failed mds should be normal"
2135
2136 test_34c() {
2137         setup
2138         touch $DIR/$tfile || return 1
2139         stop_ost --force || return 2
2140
2141         manual_umount_client --force
2142         rc=$?
2143         if [ $rc -ne 0 ]; then
2144                 error "mtab after failed umount - rc $rc"
2145         fi
2146
2147         cleanup
2148         return 0
2149 }
2150 run_test 34c "force umount with failed ost should be normal"
2151
2152 test_35a() { # bug 12459
2153         setup
2154
2155         DBG_SAVE="`lctl get_param -n debug`"
2156         lctl set_param debug="ha"
2157
2158         log "Set up a fake failnode for the MDS"
2159         FAKENID="127.0.0.2"
2160         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" |
2161                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2162         do_facet mgs "$LCTL conf_param \
2163                 ${device}.failover.node=$(h2$NETTYPE $FAKENID)" || return 4
2164
2165         log "Wait for RECONNECT_INTERVAL seconds (10s)"
2166         sleep 10
2167
2168         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
2169         $LCTL clear
2170         log "$MSG"
2171         log "Stopping the MDT: $device"
2172         stop_mdt 1 || return 5
2173
2174         df $MOUNT > /dev/null 2>&1 &
2175         DFPID=$!
2176         log "Restarting the MDT: $device"
2177         start_mdt 1 || return 6
2178         log "Wait for df ($DFPID) ... "
2179         wait $DFPID
2180         log "done"
2181         lctl set_param debug="$DBG_SAVE"
2182
2183         # retrieve from the log the first server that the client tried to
2184         # contact after the connection loss
2185         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2186         NEXTCONN=`awk "/${MSG}/ {start = 1;}
2187                        /import_select_connection.*$device-mdc.* using connection/ {
2188                                 if (start) {
2189                                         if (\\\$NF ~ /$FAKENID/)
2190                                                 print \\\$NF;
2191                                         else
2192                                                 print 0;
2193                                         exit;
2194                                 }
2195                        }" $TMP/lustre-log-$TESTNAME.log`
2196         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
2197         cleanup
2198         # remove nid settings
2199         writeconf_or_reformat
2200 }
2201 run_test 35a "Reconnect to the last active server first"
2202
2203 test_35b() { # bug 18674
2204         remote_mds || { skip "local MDS" && return 0; }
2205         setup
2206
2207         debugsave
2208         $LCTL set_param debug="ha"
2209         $LCTL clear
2210         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
2211         log "$MSG"
2212
2213         log "Set up a fake failnode for the MDS"
2214         FAKENID="127.0.0.2"
2215         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2216                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2217         do_facet mgs "$LCTL conf_param \
2218                 ${device}.failover.node=$(h2$NETTYPE $FAKENID)" || return 1
2219
2220         local at_max_saved=0
2221         # adaptive timeouts may prevent seeing the issue
2222         if at_is_enabled; then
2223                 at_max_saved=$(at_max_get mds)
2224                 at_max_set 0 mds client
2225         fi
2226
2227         mkdir -p $MOUNT/$tdir
2228
2229         log "Injecting EBUSY on MDS"
2230         # Setting OBD_FAIL_MDS_RESEND=0x136
2231         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" || return 2
2232
2233         $LCTL set_param mdc.${FSNAME}*.stats=clear
2234
2235         log "Creating a test file and stat it"
2236         touch $MOUNT/$tdir/$tfile
2237         stat $MOUNT/$tdir/$tfile
2238
2239         log "Stop injecting EBUSY on MDS"
2240         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" || return 3
2241         rm -f $MOUNT/$tdir/$tfile
2242
2243         log "done"
2244         # restore adaptive timeout
2245         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
2246
2247         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2248
2249         CONNCNT=`$LCTL get_param mdc.${FSNAME}*.stats | awk '/mds_connect/{print $2}'`
2250
2251         # retrieve from the log if the client has ever tried to
2252         # contact the fake server after the loss of connection
2253         FAILCONN=`awk "BEGIN {ret = 0;}
2254                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
2255                                 ret = 1;
2256                                 if (\\\$NF ~ /$FAKENID/) {
2257                                         ret = 2;
2258                                         exit;
2259                                 }
2260                        }
2261                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
2262
2263         [ "$FAILCONN" == "0" ] && \
2264                 log "ERROR: The client reconnection has not been triggered" && \
2265                 return 4
2266         [ "$FAILCONN" == "2" ] && \
2267                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
2268                 return 5
2269
2270         # LU-290
2271         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
2272         # Reconnects are supposed to be rate limited to one every 5s
2273         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] && \
2274                 log "ERROR: Too many reconnects $CONNCNT" && \
2275                 return 6
2276
2277         cleanup
2278         # remove nid settings
2279         writeconf_or_reformat
2280 }
2281 run_test 35b "Continue reconnection retries, if the active server is busy"
2282
2283 test_36() { # 12743
2284         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
2285
2286         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
2287                 { skip "remote OST" && return 0; }
2288
2289         local rc=0
2290         local FSNAME2=test1234
2291         local fs3ost_HOST=$ost_HOST
2292         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2293
2294         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
2295
2296         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
2297                 is_blkdev $SINGLEMDS $MDSDEV && \
2298                 skip_env "mixed loopback and real device not working" && return
2299         fi
2300
2301         local fs2mdsdev=$(mdsdevname 1_2)
2302         local fs2ostdev=$(ostdevname 1_2)
2303         local fs3ostdev=$(ostdevname 2_2)
2304         local fs2mdsvdev=$(mdsvdevname 1_2)
2305         local fs2ostvdev=$(ostvdevname 1_2)
2306         local fs3ostvdev=$(ostvdevname 2_2)
2307
2308         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2309                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
2310         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
2311         #     different one than the default value here.
2312         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2313                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
2314         add fs3ost $(mkfs_opts ost2 ${fs3ostdev}) --mgsnode=$MGSNID \
2315                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
2316
2317         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
2318         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2319         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
2320         mkdir -p $MOUNT2
2321         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || return 1
2322
2323         sleep 5 # until 11778 fixed
2324
2325         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
2326
2327         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
2328         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
2329         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
2330         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
2331         DFTOTAL=`echo $STRING | cut -d, -f1`
2332         DFUSED=`echo $STRING  | cut -d, -f2`
2333         DFAVAIL=`echo $STRING | cut -d, -f3`
2334         DFFREE=$(($DFTOTAL - $DFUSED))
2335
2336         ALLOWANCE=$((64 * $OSTCOUNT))
2337
2338         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
2339            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
2340                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
2341                 rc=1
2342         fi
2343         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
2344            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
2345                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
2346                 rc=2
2347         fi
2348         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
2349            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
2350                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
2351                 rc=3
2352        fi
2353
2354         umount -d $MOUNT2
2355         stop fs3ost -f || return 200
2356         stop fs2ost -f || return 201
2357         stop fs2mds -f || return 202
2358         unload_modules_conf || return 203
2359         return $rc
2360 }
2361 run_test 36 "df report consistency on OSTs with different block size"
2362
2363 test_37() {
2364         local mntpt=$(facet_mntpt $SINGLEMDS)
2365         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
2366         local mdsdev_sym="$TMP/sym_mdt.img"
2367         local opts=$MDS_MOUNT_OPTS
2368         local rc=0
2369
2370         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2371                 skip "Currently only applicable to ldiskfs-based MDTs"
2372                 return
2373         fi
2374
2375         echo "MDS :     $mdsdev"
2376         echo "SYMLINK : $mdsdev_sym"
2377         do_facet $SINGLEMDS rm -f $mdsdev_sym
2378
2379         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
2380
2381         echo "mount symlink device - $mdsdev_sym"
2382
2383         if ! do_facet $SINGLEMDS test -b $mdsdev; then
2384                 opts=$(csa_add "$opts" -o loop)
2385         fi
2386         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
2387                 $mdsdev_sym $mntpt 2>&1)
2388         rc=${PIPESTATUS[0]}
2389
2390         echo mount_op=$mount_op
2391
2392         do_facet $SINGLEMDS "umount -d $mntpt && rm -f $mdsdev_sym"
2393
2394         if $(echo $mount_op | grep -q "unable to set tunable"); then
2395                 error "set tunables failed for symlink device"
2396         fi
2397
2398         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
2399
2400         return 0
2401 }
2402 run_test 37 "verify set tunables works for symlink device"
2403
2404 test_38() { # bug 14222
2405         local fstype=$(facet_fstype $SINGLEMDS)
2406         local mntpt=$(facet_mntpt $SINGLEMDS)
2407
2408         setup
2409         # like runtests
2410         local COUNT=10
2411         local SRC="/etc /bin"
2412         local FILES=$(find $SRC -type f -mtime +1 | head -n $COUNT)
2413         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
2414         mkdir -p $DIR/$tdir
2415         tar cf - $FILES | tar xf - -C $DIR/$tdir ||
2416                 error "copying $SRC to $DIR/$tdir"
2417         sync
2418         umount_client $MOUNT
2419         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2420         stop_mds
2421         log "delete lov_objid file on MDS"
2422
2423         mount_fstype $SINGLEMDS || error "mount MDS failed (1)"
2424
2425         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid; rm $mntpt/lov_objid"
2426
2427         unmount_fstype $SINGLEMDS || error "umount failed (1)"
2428
2429         # check create in mds_lov_connect
2430         start_mds
2431         mount_client $MOUNT
2432         for f in $FILES; do
2433                 [ $V ] && log "verifying $DIR/$tdir/$f"
2434                 diff -q $f $DIR/$tdir/$f || ERROR=y
2435         done
2436         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2437         if [ "$ERROR" = "y" ]; then
2438                 # check it's updates in sync
2439                 umount_client $MOUNT
2440                 stop_mds
2441                 mount_fstype $SIGNLEMDS
2442                 do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2443                 unmount_fstype $SINGLEMDS
2444                 error "old and new files are different after connect" || true
2445         fi
2446         touch $DIR/$tdir/f2 || error "f2 file create failed"
2447
2448         # check it's updates in sync
2449         umount_client $MOUNT
2450         stop_mds
2451
2452         mount_fstype $SINGLEMDS || error "mount MDS failed (3)"
2453
2454         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2455         do_facet $SINGLEMDS dd if=/dev/zero of=$mntpt/lov_objid.clear count=8
2456
2457         unmount_fstype $SINGLEMDS || error "umount failed (3)"
2458
2459         start_mds
2460         mount_client $MOUNT
2461         for f in $FILES; do
2462                 [ $V ] && log "verifying $DIR/$tdir/$f"
2463                 diff -q $f $DIR/$tdir/$f || ERROR=y
2464         done
2465         touch $DIR/$tdir/f3 || error "f3 file create failed"
2466         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2467         umount_client $MOUNT
2468         stop_mds
2469         mount_fstype $SINGLEMDS || error "mount MDS failed (4)"
2470         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2471         unmount_fstype $SINGLEMDS || error "umount failed (4)"
2472
2473         [ "$ERROR" = "y" ] &&
2474                 error "old and new files are different after sync" || true
2475
2476         log "files compared the same"
2477         cleanup
2478 }
2479 run_test 38 "MDS recreates missing lov_objid file from OST data"
2480
2481 test_39() {
2482         PTLDEBUG=+malloc
2483         setup
2484         cleanup
2485         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2486                 error "memory leak detected" || true
2487 }
2488 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2489
2490 test_40() { # bug 15759
2491         start_ost
2492         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2493         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2494         start_mds
2495         cleanup
2496 }
2497 run_test 40 "race during service thread startup"
2498
2499 test_41a() { #bug 14134
2500         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2501            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2502                 skip "Loop devices does not work with nosvc option"
2503                 return
2504         fi
2505
2506         local rc
2507         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2508
2509         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2510         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
2511         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2512         mkdir -p $MOUNT
2513         mount_client $MOUNT || return 1
2514         sleep 5
2515
2516         echo "blah blah" > $MOUNT/$tfile
2517         cat $MOUNT/$tfile
2518
2519         umount_client $MOUNT
2520         stop ost1 -f || return 201
2521         stop_mds -f || return 202
2522         stop_mds -f || return 203
2523         unload_modules_conf || return 204
2524         return $rc
2525 }
2526 run_test 41a "mount mds with --nosvc and --nomgs"
2527
2528 test_41b() {
2529         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2530            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2531                 skip "Loop devices does not work with nosvc option"
2532                 return
2533         fi
2534
2535         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2536
2537         stopall
2538         reformat
2539         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2540
2541         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2542         start_ost
2543         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2544         mkdir -p $MOUNT
2545         mount_client $MOUNT || return 1
2546         sleep 5
2547
2548         echo "blah blah" > $MOUNT/$tfile
2549         cat $MOUNT/$tfile || return 200
2550
2551         umount_client $MOUNT
2552         stop_ost || return 201
2553         stop_mds -f || return 202
2554         stop_mds -f || return 203
2555
2556 }
2557 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2558
2559 test_42() { #bug 14693
2560         setup
2561         check_mount || error "client was not mounted"
2562
2563         do_facet mgs $LCTL conf_param $FSNAME.llite.some_wrong_param=10
2564         umount_client $MOUNT ||
2565                 error "unmounting client failed with invalid llite param"
2566         mount_client $MOUNT ||
2567                 error "mounting client failed with invalid llite param"
2568
2569         do_facet mgs $LCTL conf_param $FSNAME.sys.some_wrong_param=20
2570         cleanup || error "stopping $FSNAME failed with invalid sys param"
2571         load_modules
2572         setup
2573         check_mount || "client was not mounted with invalid sys param"
2574         cleanup || error "stopping $FSNAME failed with invalid sys param"
2575         return 0
2576 }
2577 run_test 42 "allow client/server mount/unmount with invalid config param"
2578
2579 test_43() {
2580         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.58) ]] ||
2581                 { skip "Need MDS version at least 2.5.58" && return 0; }
2582         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
2583
2584         ID1=${ID1:-501}
2585         USER1=$(cat /etc/passwd | grep :$ID1:$ID1: | cut -d: -f1)
2586         [ -z "$USER1" ] && skip_env "missing user with uid=$ID1 gid=$ID1" &&
2587                 return
2588
2589         setup
2590         chmod ugo+x $DIR || error "chmod 0 failed"
2591         set_conf_param_and_check mds                                    \
2592                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2593                 "$FSNAME.mdt.root_squash"                               \
2594                 "0:0"
2595         wait_update $HOSTNAME                                           \
2596                 "lctl get_param -n llite.${FSNAME}*.root_squash"        \
2597                 "0:0" ||
2598                 error "check llite root_squash failed!"
2599         set_conf_param_and_check mds                                    \
2600                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2601                 "$FSNAME.mdt.nosquash_nids"                             \
2602                 "NONE"
2603         wait_update $HOSTNAME                                           \
2604                 "lctl get_param -n llite.${FSNAME}*.nosquash_nids"      \
2605                 "NONE" ||
2606                 error "check llite nosquash_nids failed!"
2607
2608     #
2609     # create set of test files
2610     #
2611     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
2612     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
2613     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
2614
2615     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
2616     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
2617
2618     mkdir $DIR/$tdir-rootdir -p       || error "mkdir failed"
2619     chmod go-rwx $DIR/$tdir-rootdir   || error "chmod 3 failed"
2620     touch $DIR/$tdir-rootdir/tfile-1  || error "touch failed"
2621
2622         echo "777" > $DIR/$tfile-user1file || error "write 7 failed"
2623         chmod go-rw $DIR/$tfile-user1file  || error "chmod 7 failed"
2624         chown $ID1.$ID1 $DIR/$tfile-user1file || error "chown failed"
2625
2626         #
2627         # check root_squash:
2628         #   set root squash UID:GID to RUNAS_ID
2629         #   root should be able to access only files owned by RUNAS_ID
2630         #
2631         set_conf_param_and_check mds                                    \
2632                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2633                 "$FSNAME.mdt.root_squash"                               \
2634                 "$RUNAS_ID:$RUNAS_ID"
2635         wait_update $HOSTNAME                                           \
2636                 "lctl get_param -n llite.${FSNAME}*.root_squash"        \
2637                 "$RUNAS_ID:$RUNAS_ID" ||
2638                 error "check llite root_squash failed!"
2639
2640     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
2641     dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2642         error "$ST: root read permission is denied"
2643     echo "$ST: root read permission is granted - ok"
2644
2645     echo "444" | \
2646     dd conv=notrunc of=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2647         error "$ST: root write permission is denied"
2648     echo "$ST: root write permission is granted - ok"
2649
2650     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2651     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2652         error "$ST: root read permission is granted"
2653     echo "$ST: root read permission is denied - ok"
2654
2655     echo "555" | \
2656     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2657         error "$ST: root write permission is granted"
2658     echo "$ST: root write permission is denied - ok"
2659
2660     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2661     rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null && \
2662         error "$ST: root unlink permission is granted"
2663     echo "$ST: root unlink permission is denied - ok"
2664
2665     touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null && \
2666         error "$ST: root create permission is granted"
2667     echo "$ST: root create permission is denied - ok"
2668
2669
2670         # LU-1778
2671         # check root_squash is enforced independently
2672         # of client cache content
2673         #
2674         # access file by USER1, keep access open
2675         # root should be denied access to user file
2676
2677         runas -u $ID1 tail -f $DIR/$tfile-user1file 1>/dev/null 2>&1 &
2678         pid=$!
2679         sleep 1
2680
2681         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-user1file)
2682         dd if=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
2683             { kill $pid; error "$ST: root read permission is granted"; }
2684         echo "$ST: root read permission is denied - ok"
2685
2686         echo "777" | \
2687         dd conv=notrunc of=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
2688             { kill $pid; error "$ST: root write permission is granted"; }
2689         echo "$ST: root write permission is denied - ok"
2690
2691         kill $pid
2692         wait $pid
2693
2694         #
2695         # check nosquash_nids:
2696         #   put client's NID into nosquash_nids list,
2697         #   root should be able to access root file after that
2698         #
2699         local NIDLIST=$(lctl list_nids all | tr '\n' ' ')
2700         NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
2701         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
2702         set_conf_param_and_check mds                                    \
2703                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2704                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
2705                 "$NIDLIST"
2706         wait_update $HOSTNAME                                           \
2707                 "lctl get_param -n llite.${FSNAME}*.nosquash_nids"      \
2708                 "$NIDLIST" ||
2709                 error "check llite nosquash_nids failed!"
2710
2711     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2712     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2713         error "$ST: root read permission is denied"
2714     echo "$ST: root read permission is granted - ok"
2715
2716     echo "666" | \
2717     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2718         error "$ST: root write permission is denied"
2719     echo "$ST: root write permission is granted - ok"
2720
2721     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2722     rm $DIR/$tdir-rootdir/tfile-1 || \
2723         error "$ST: root unlink permission is denied"
2724     echo "$ST: root unlink permission is granted - ok"
2725     touch $DIR/$tdir-rootdir/tfile-2 || \
2726         error "$ST: root create permission is denied"
2727     echo "$ST: root create permission is granted - ok"
2728
2729     return 0
2730 }
2731 run_test 43 "check root_squash and nosquash_nids"
2732
2733 umount_client $MOUNT
2734 cleanup_nocli
2735
2736 test_44() { # 16317
2737         setup
2738         check_mount || return 2
2739         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
2740         STATS_FOUND=no
2741         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
2742         for VAL in $UUIDS; do
2743                 NID=$(echo $VAL | cut -d= -f1)
2744                 CLUUID=$(echo $VAL | cut -d= -f2)
2745                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
2746         done
2747         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
2748         cleanup
2749         return 0
2750 }
2751 run_test 44 "mounted client proc entry exists"
2752
2753 test_45() { #17310
2754         setup
2755         check_mount || return 2
2756         stop_mds
2757         df -h $MOUNT &
2758         log "sleep 60 sec"
2759         sleep 60
2760 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
2761         do_facet client "lctl set_param fail_loc=0x50f"
2762         log "sleep 10 sec"
2763         sleep 10
2764         manual_umount_client --force || return 3
2765         do_facet client "lctl set_param fail_loc=0x0"
2766         start_mds
2767         mount_client $MOUNT || return 4
2768         cleanup
2769         return 0
2770 }
2771 run_test 45 "long unlink handling in ptlrpcd"
2772
2773 cleanup_46a() {
2774         trap 0
2775         local rc=0
2776         local count=$1
2777
2778         umount_client $MOUNT2 || rc=$?
2779         umount_client $MOUNT || rc=$?
2780         while [ $count -gt 0 ]; do
2781                 stop ost${count} -f || rc=$?
2782                 let count=count-1
2783         done    
2784         stop_mds || rc=$?
2785         cleanup_nocli || rc=$?
2786         #writeconf to remove all ost2 traces for subsequent tests
2787         writeconf_or_reformat
2788         return $rc
2789 }
2790
2791 test_46a() {
2792         echo "Testing with $OSTCOUNT OSTs"
2793         reformat_and_config
2794         start_mds || return 1
2795         #first client should see only one ost
2796         start_ost || return 2
2797         wait_osc_import_state mds ost FULL
2798         #start_client
2799         mount_client $MOUNT || return 3
2800         trap "cleanup_46a $OSTCOUNT" EXIT ERR
2801
2802         local i
2803         for (( i=2; i<=$OSTCOUNT; i++ )); do
2804             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
2805         done
2806
2807         # wait until osts in sync
2808         for (( i=2; i<=$OSTCOUNT; i++ )); do
2809             wait_osc_import_state mds ost$i FULL
2810             wait_osc_import_state client ost$i FULL
2811         done
2812
2813         #second client see all ost's
2814
2815         mount_client $MOUNT2 || return 8
2816         $LFS setstripe -c -1 $MOUNT2 || return 9
2817         $LFS getstripe $MOUNT2 || return 10
2818
2819         echo "ok" > $MOUNT2/widestripe
2820         $LFS getstripe $MOUNT2/widestripe || return 11
2821         # fill acl buffer for avoid expand lsm to them
2822         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
2823             setfacl -m $acl $MOUNT2/widestripe
2824         done
2825
2826         # will be deadlock
2827         stat $MOUNT/widestripe || return 12
2828
2829         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
2830         return 0
2831 }
2832 run_test 46a "handle ost additional - wide striped file"
2833
2834 test_47() { #17674
2835         reformat
2836         setup_noconfig
2837         check_mount || return 2
2838         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
2839
2840         local lru_size=[]
2841         local count=0
2842         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2843             if echo $ns | grep "MDT[[:digit:]]*"; then
2844                 continue
2845             fi
2846             lrs=$(echo $ns | sed 's/.*lru_size=//')
2847             lru_size[count]=$lrs
2848             let count=count+1
2849         done
2850
2851         facet_failover ost1
2852         facet_failover $SINGLEMDS
2853         client_up || return 3
2854
2855         count=0
2856         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2857             if echo $ns | grep "MDT[[:digit:]]*"; then
2858                 continue
2859             fi
2860             lrs=$(echo $ns | sed 's/.*lru_size=//')
2861             if ! test "$lrs" -eq "${lru_size[count]}"; then
2862                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
2863                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
2864             fi
2865             let count=count+1
2866         done
2867
2868         cleanup
2869         return 0
2870 }
2871 run_test 47 "server restart does not make client loss lru_resize settings"
2872
2873 cleanup_48() {
2874         trap 0
2875
2876         # reformat after this test is needed - if test will failed
2877         # we will have unkillable file at FS
2878         reformat_and_config
2879 }
2880
2881 test_48() { # bug 17636
2882         reformat
2883         setup_noconfig
2884         check_mount || return 2
2885
2886         $LFS setstripe -c -1 $MOUNT || return 9
2887         $LFS getstripe $MOUNT || return 10
2888
2889         echo "ok" > $MOUNT/widestripe
2890         $LFS getstripe $MOUNT/widestripe || return 11
2891
2892         trap cleanup_48 EXIT ERR
2893
2894         # fill acl buffer for avoid expand lsm to them
2895         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
2896             setfacl -m $acl $MOUNT/widestripe
2897         done
2898
2899         stat $MOUNT/widestripe || return 12
2900
2901         cleanup_48
2902         return 0
2903 }
2904 run_test 48 "too many acls on file"
2905
2906 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
2907 test_49a() { # bug 17710
2908         local timeout_orig=$TIMEOUT
2909         local ldlm_timeout_orig=$LDLM_TIMEOUT
2910         local LOCAL_TIMEOUT=20
2911
2912         LDLM_TIMEOUT=$LOCAL_TIMEOUT
2913         TIMEOUT=$LOCAL_TIMEOUT
2914
2915         reformat
2916         setup_noconfig
2917         check_mount || error "client mount failed"
2918
2919         echo "check ldlm_timout..."
2920         local LDLM_MDS="$(do_facet $SINGLEMDS lctl get_param -n ldlm_timeout)"
2921         local LDLM_OST1="$(do_facet ost1 lctl get_param -n ldlm_timeout)"
2922         local LDLM_CLIENT="$(do_facet client lctl get_param -n ldlm_timeout)"
2923
2924         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
2925                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2926         fi
2927
2928         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
2929                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT / 3))"
2930         fi
2931
2932         umount_client $MOUNT
2933         stop_ost || error "problem stopping OSS"
2934         stop_mds || error "problem stopping MDS"
2935
2936         LDLM_TIMEOUT=$ldlm_timeout_orig
2937         TIMEOUT=$timeout_orig
2938 }
2939 run_test 49a "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
2940
2941 test_49b() { # bug 17710
2942         local timeout_orig=$TIMEOUT
2943         local ldlm_timeout_orig=$LDLM_TIMEOUT
2944         local LOCAL_TIMEOUT=20
2945
2946         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
2947         TIMEOUT=$LOCAL_TIMEOUT
2948
2949         reformat
2950         setup_noconfig
2951         check_mount || error "client mount failed"
2952
2953         local LDLM_MDS="$(do_facet $SINGLEMDS lctl get_param -n ldlm_timeout)"
2954         local LDLM_OST1="$(do_facet ost1 lctl get_param -n ldlm_timeout)"
2955         local LDLM_CLIENT="$(do_facet client lctl get_param -n ldlm_timeout)"
2956
2957         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
2958                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2959         fi
2960
2961         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
2962                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT - 1))"
2963         fi
2964
2965         cleanup || error "cleanup failed"
2966
2967         LDLM_TIMEOUT=$ldlm_timeout_orig
2968         TIMEOUT=$timeout_orig
2969 }
2970 run_test 49b "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
2971
2972 lazystatfs() {
2973         # Test both statfs and lfs df and fail if either one fails
2974         multiop_bg_pause $1 f_
2975         RC1=$?
2976         PID=$!
2977         killall -USR1 multiop
2978         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
2979         wait $PID || { RC1=$?; log "multiop return error "; }
2980
2981         $LFS df &
2982         PID=$!
2983         sleep 5
2984         kill -s 0 $PID
2985         RC2=$?
2986         if [ $RC2 -eq 0 ]; then
2987             kill -s 9 $PID
2988             log "lazystatfs df failed"
2989         fi
2990
2991         RC=0
2992         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
2993         return $RC
2994 }
2995
2996 test_50a() {
2997         setup
2998         lctl set_param llite.$FSNAME-*.lazystatfs=1
2999         touch $DIR/$tfile
3000
3001         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
3002
3003         cleanup || return $?
3004 }
3005 run_test 50a "lazystatfs all servers available =========================="
3006
3007 test_50b() {
3008         setup
3009         lctl set_param llite.$FSNAME-*.lazystatfs=1
3010         touch $DIR/$tfile
3011
3012         # Wait for client to detect down OST
3013         stop_ost || error "Unable to stop OST1"
3014         wait_osc_import_state mds ost DISCONN
3015
3016         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
3017
3018         umount_client $MOUNT || error "Unable to unmount client"
3019         stop_mds || error "Unable to stop MDS"
3020 }
3021 run_test 50b "lazystatfs all servers down =========================="
3022
3023 test_50c() {
3024         start_mds || error "Unable to start MDS"
3025         start_ost || error "Unable to start OST1"
3026         start_ost2 || error "Unable to start OST2"
3027         mount_client $MOUNT || error "Unable to mount client"
3028         lctl set_param llite.$FSNAME-*.lazystatfs=1
3029         touch $DIR/$tfile
3030
3031         # Wait for client to detect down OST
3032         stop_ost || error "Unable to stop OST1"
3033         wait_osc_import_state mds ost DISCONN
3034         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3035
3036         umount_client $MOUNT || error "Unable to unmount client"
3037         stop_ost2 || error "Unable to stop OST2"
3038         stop_mds || error "Unable to stop MDS"
3039         #writeconf to remove all ost2 traces for subsequent tests
3040         writeconf_or_reformat
3041 }
3042 run_test 50c "lazystatfs one server down =========================="
3043
3044 test_50d() {
3045         start_mds || error "Unable to start MDS"
3046         start_ost || error "Unable to start OST1"
3047         start_ost2 || error "Unable to start OST2"
3048         mount_client $MOUNT || error "Unable to mount client"
3049         lctl set_param llite.$FSNAME-*.lazystatfs=1
3050         touch $DIR/$tfile
3051
3052         # Issue the statfs during the window where the client still
3053         # belives the OST to be available but it is in fact down.
3054         # No failure just a statfs which hangs for a timeout interval.
3055         stop_ost || error "Unable to stop OST1"
3056         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3057
3058         umount_client $MOUNT || error "Unable to unmount client"
3059         stop_ost2 || error "Unable to stop OST2"
3060         stop_mds || error "Unable to stop MDS"
3061         #writeconf to remove all ost2 traces for subsequent tests
3062         writeconf_or_reformat
3063 }
3064 run_test 50d "lazystatfs client/server conn race =========================="
3065
3066 test_50e() {
3067         local RC1
3068         local pid
3069
3070         reformat_and_config
3071         start_mds || return 1
3072         #first client should see only one ost
3073         start_ost || return 2
3074         wait_osc_import_state mds ost FULL
3075
3076         # Wait for client to detect down OST
3077         stop_ost || error "Unable to stop OST1"
3078         wait_osc_import_state mds ost DISCONN
3079
3080         mount_client $MOUNT || error "Unable to mount client"
3081         lctl set_param llite.$FSNAME-*.lazystatfs=0
3082
3083         multiop_bg_pause $MOUNT _f
3084         RC1=$?
3085         pid=$!
3086
3087         if [ $RC1 -ne 0 ]; then
3088                 log "multiop failed $RC1"
3089         else
3090             kill -USR1 $pid
3091             sleep $(( $TIMEOUT+1 ))
3092             kill -0 $pid
3093             [ $? -ne 0 ] && error "process isn't sleep"
3094             start_ost || error "Unable to start OST1"
3095             wait $pid || error "statfs failed"
3096         fi
3097
3098         umount_client $MOUNT || error "Unable to unmount client"
3099         stop_ost || error "Unable to stop OST1"
3100         stop_mds || error "Unable to stop MDS"
3101 }
3102 run_test 50e "normal statfs all servers down =========================="
3103
3104 test_50f() {
3105         local RC1
3106         local pid
3107         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
3108
3109         start_mds || error "Unable to start mds"
3110         #first client should see only one ost
3111         start_ost || error "Unable to start OST1"
3112         wait_osc_import_state mds ost FULL
3113
3114         start_ost2 || error "Unable to start OST2"
3115         wait_osc_import_state mds ost2 FULL
3116
3117         # Wait for client to detect down OST
3118         stop_ost2 || error "Unable to stop OST2"
3119
3120         wait_osc_import_state mds ost2 DISCONN
3121         mount_client $MOUNT || error "Unable to mount client"
3122         lctl set_param llite.$FSNAME-*.lazystatfs=0
3123
3124         multiop_bg_pause $MOUNT _f
3125         RC1=$?
3126         pid=$!
3127
3128         if [ $RC1 -ne 0 ]; then
3129                 log "lazystatfs multiop failed $RC1"
3130         else
3131             kill -USR1 $pid
3132             sleep $(( $TIMEOUT+1 ))
3133             kill -0 $pid
3134             [ $? -ne 0 ] && error "process isn't sleep"
3135             start_ost2 || error "Unable to start OST2"
3136             wait $pid || error "statfs failed"
3137             stop_ost2 || error "Unable to stop OST2"
3138         fi
3139
3140         umount_client $MOUNT || error "Unable to unmount client"
3141         stop_ost || error "Unable to stop OST1"
3142         stop_mds || error "Unable to stop MDS"
3143         #writeconf to remove all ost2 traces for subsequent tests
3144         writeconf_or_reformat
3145 }
3146 run_test 50f "normal statfs one server in down =========================="
3147
3148 test_50g() {
3149         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
3150         setup
3151         start_ost2 || error "Unable to start OST2"
3152         wait_osc_import_state mds ost2 FULL
3153         wait_osc_import_state client ost2 FULL
3154
3155         local PARAM="${FSNAME}-OST0001.osc.active"
3156
3157         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
3158         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
3159
3160         umount_client $MOUNT || error "Unable to unmount client"
3161         mount_client $MOUNT || error "Unable to mount client"
3162         # This df should not cause a panic
3163         df -k $MOUNT
3164
3165         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
3166         rm -f $DIR/$tfile
3167         umount_client $MOUNT || error "Unable to unmount client"
3168         stop_ost2 || error "Unable to stop OST2"
3169         stop_ost || error "Unable to stop OST1"
3170         stop_mds || error "Unable to stop MDS"
3171         #writeconf to remove all ost2 traces for subsequent tests
3172         writeconf_or_reformat
3173 }
3174 run_test 50g "deactivated OST should not cause panic====================="
3175
3176 # LU-642
3177 test_50h() {
3178         # prepare MDT/OST, make OSC inactive for OST1
3179         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
3180
3181         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3182         do_facet ost1 "$TUNEFS --param osc.active=0 `ostdevname 1`" ||
3183                 error "tunefs OST1 failed"
3184         start_mds  || error "Unable to start MDT"
3185         start_ost  || error "Unable to start OST1"
3186         start_ost2 || error "Unable to start OST2"
3187         mount_client $MOUNT || error "client start failed"
3188
3189         mkdir -p $DIR/$tdir
3190
3191         # activatate OSC for OST1
3192         local TEST="$LCTL get_param -n osc.${FSNAME}-OST0000-osc-[!M]*.active"
3193         set_conf_param_and_check client                                 \
3194                 "$TEST" "${FSNAME}-OST0000.osc.active" 1 ||
3195                 error "Unable to activate OST1"
3196
3197         mkdir -p $DIR/$tdir/2
3198         $LFS setstripe -c -1 -i 0 $DIR/$tdir/2
3199         sleep 1 && echo "create a file after OST1 is activated"
3200         # create some file
3201         createmany -o $DIR/$tdir/2/$tfile-%d 1
3202
3203         # check OSC import is working
3204         stat $DIR/$tdir/2/* >/dev/null 2>&1 ||
3205                 error "some OSC imports are still not connected"
3206
3207         # cleanup
3208         umount_client $MOUNT || error "Unable to umount client"
3209         stop_ost2 || error "Unable to stop OST2"
3210         cleanup_nocli
3211 }
3212 run_test 50h "LU-642: activate deactivated OST  ==="
3213
3214 test_51() {
3215         local LOCAL_TIMEOUT=20
3216
3217         reformat
3218         setup_noconfig
3219         check_mount || return 1
3220
3221         mkdir $MOUNT/d1
3222         $LFS setstripe -c -1 $MOUNT/d1
3223         #define OBD_FAIL_MDS_REINT_DELAY         0x142
3224         do_facet $SINGLEMDS "lctl set_param fail_loc=0x142"
3225         touch $MOUNT/d1/f1 &
3226         local pid=$!
3227         sleep 2
3228         start_ost2 || return 2
3229         wait $pid
3230         stop_ost2 || return 3
3231         cleanup
3232         #writeconf to remove all ost2 traces for subsequent tests
3233         writeconf_or_reformat
3234 }
3235 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
3236
3237 copy_files_xattrs()
3238 {
3239         local node=$1
3240         local dest=$2
3241         local xattrs=$3
3242         shift 3
3243
3244         do_node $node mkdir -p $dest
3245         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3246
3247         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
3248                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3249         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
3250
3251         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
3252         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
3253 }
3254
3255 diff_files_xattrs()
3256 {
3257         local node=$1
3258         local backup=$2
3259         local xattrs=$3
3260         shift 3
3261
3262         local backup2=${TMP}/backup2
3263
3264         do_node $node mkdir -p $backup2
3265         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3266
3267         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
3268                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3269         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
3270
3271         do_node $node "diff -rq $backup $backup2"
3272         [ $? -eq 0 ] || { error "contents differ"; return 3; }
3273
3274         local xattrs2=${TMP}/xattrs2
3275         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
3276         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
3277
3278         do_node $node "diff $xattrs $xattrs2"
3279         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
3280
3281         do_node $node "rm -rf $backup2 $xattrs2"
3282         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
3283 }
3284
3285 test_52() {
3286         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3287                 skip "Only applicable to ldiskfs-based MDTs"
3288                 return
3289         fi
3290
3291         start_mds
3292         [ $? -eq 0 ] || { error "Unable to start MDS"; return 1; }
3293         start_ost
3294         [ $? -eq 0 ] || { error "Unable to start OST1"; return 2; }
3295         mount_client $MOUNT
3296         [ $? -eq 0 ] || { error "Unable to mount client"; return 3; }
3297
3298         local nrfiles=8
3299         local ost1mnt=$(facet_mntpt ost1)
3300         local ost1node=$(facet_active_host ost1)
3301         local ost1tmp=$TMP/conf52
3302         local loop
3303
3304         mkdir -p $DIR/$tdir
3305         [ $? -eq 0 ] || { error "Unable to create tdir"; return 4; }
3306         touch $TMP/modified_first
3307         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 5; }
3308         local mtime=$(stat -c %Y $TMP/modified_first)
3309         do_node $ost1node "mkdir -p $ost1tmp && touch -m -d @$mtime $ost1tmp/modified_first"
3310
3311         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 6; }
3312         sleep 1
3313
3314         $LFS setstripe -c -1 -S 1M $DIR/$tdir
3315         [ $? -eq 0 ] || { error "lfs setstripe failed"; return 7; }
3316
3317         for (( i=0; i < nrfiles; i++ )); do
3318                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c
3319                 [ $? -eq 0 ] || { error "multiop failed"; return 8; }
3320                 echo -n .
3321         done
3322         echo
3323
3324         # backup files
3325         echo backup files to $TMP/files
3326         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
3327         copy_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
3328         [ $? -eq 0 ] || { error "Unable to copy files"; return 9; }
3329
3330         umount_client $MOUNT
3331         [ $? -eq 0 ] || { error "Unable to umount client"; return 10; }
3332         stop_ost
3333         [ $? -eq 0 ] || { error "Unable to stop ost1"; return 11; }
3334
3335         echo mount ost1 as ldiskfs
3336         do_node $ost1node mkdir -p $ost1mnt
3337         [ $? -eq 0 ] || { error "Unable to create $ost1mnt"; return 23; }
3338         if ! do_node $ost1node test -b $ost1_dev; then
3339                 loop="-o loop"
3340         fi
3341         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
3342                 $ost1mnt
3343         [ $? -eq 0 ] || { error "Unable to mount ost1 as ldiskfs"; return 12; }
3344
3345         # backup objects
3346         echo backup objects to $ost1tmp/objects
3347         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/[0-9]* -type f'\
3348                 '-size +0 -newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
3349         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs \
3350                         $objects
3351         [ $? -eq 0 ] || { error "Unable to copy objects"; return 13; }
3352
3353         # move objects to lost+found
3354         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
3355         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
3356
3357         # recover objects dry-run
3358         echo "ll_recover_lost_found_objs dry_run"
3359         do_node $ost1node "ll_recover_lost_found_objs -n -d $ost1mnt/O"
3360         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
3361
3362         # recover objects
3363         echo "ll_recover_lost_found_objs fix run"
3364         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found"
3365         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
3366
3367         # compare restored objects against saved ones
3368         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
3369         [ $? -eq 0 ] || { error "Unable to diff objects"; return 16; }
3370
3371         do_node $ost1node "umount $ost1mnt"
3372         [ $? -eq 0 ] || { error "Unable to umount ost1 as ldiskfs"; return 17; }
3373
3374         start_ost
3375         [ $? -eq 0 ] || { error "Unable to start ost1"; return 18; }
3376         mount_client $MOUNT
3377         [ $? -eq 0 ] || { error "Unable to mount client"; return 19; }
3378
3379         # compare files
3380         diff_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
3381         [ $? -eq 0 ] || { error "Unable to diff files"; return 20; }
3382
3383         rm -rf $TMP/files $TMP/file_xattrs
3384         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 21; }
3385         do_node $ost1node "rm -rf $ost1tmp"
3386         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 22; }
3387         cleanup
3388 }
3389 run_test 52 "check recovering objects from lost+found"
3390
3391 # Checks threads_min/max/started for some service
3392 #
3393 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
3394 # parameter pattern prefix like 'ost.*.ost'.
3395 thread_sanity() {
3396         local modname=$1
3397         local facet=$2
3398         local parampat=$3
3399         local opts=$4
3400         local basethr=$5
3401         local tmin
3402         local tmin2
3403         local tmax
3404         local tmax2
3405         local tstarted
3406         local paramp
3407         local msg="Insane $modname thread counts"
3408         local ncpts=$(check_cpt_number $facet)
3409         local nthrs
3410         shift 4
3411
3412         check_mount || return 41
3413
3414         # We need to expand $parampat, but it may match multiple parameters, so
3415         # we'll pick the first one
3416         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
3417                 error "Couldn't expand ${parampat}.threads_min parameter name"
3418                 return 22
3419         fi
3420
3421         # Remove the .threads_min part
3422         paramp=${paramp%.threads_min}
3423
3424         # Check for sanity in defaults
3425         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3426         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3427         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started" || echo 0)
3428         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' || return $?
3429         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
3430         nthrs=$(expr $tmax - $tmin)
3431         if [ $nthrs -lt $ncpts ]; then
3432                 nthrs=0
3433         else
3434                 nthrs=$ncpts
3435         fi
3436
3437         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
3438                 skip_env "module parameter forced $facet thread count" &&
3439                 tmin=3 && tmax=$((3 * tmax))
3440
3441         # Check that we can change min/max
3442         do_facet $facet "lctl set_param ${paramp}.threads_min=$((tmin + nthrs))"
3443         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmax - nthrs))"
3444         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3445         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3446         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) && $tmax2 == ($tmax - $nthrs)))' || return $?
3447
3448         # Check that we can set min/max to the same value
3449         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3450         do_facet $facet "lctl set_param ${paramp}.threads_max=$tmin"
3451         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3452         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3453         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
3454
3455         # Check that we can't set max < min
3456         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmin - 1))"
3457         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3458         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3459         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
3460
3461         # We need to ensure that we get the module options desired; to do this
3462         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
3463         LOAD_MODULES_REMOTE=true
3464         cleanup
3465         local oldvalue
3466         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
3467         setmodopts -a $modname "$newvalue" oldvalue
3468
3469         load_modules
3470         setup
3471         check_mount || return 41
3472
3473         # Restore previous setting of MODOPTS_*
3474         setmodopts $modname "$oldvalue"
3475
3476         # Check that $opts took
3477         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min")
3478         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max")
3479         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started")
3480         lassert 28 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
3481         cleanup
3482
3483         load_modules
3484         setup
3485 }
3486
3487 test_53a() {
3488         setup
3489         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
3490         cleanup
3491 }
3492 run_test 53a "check OSS thread count params"
3493
3494 test_53b() {
3495         setup
3496         local mds=$(do_facet $SINGLEMDS "lctl get_param -N mds.*.*.threads_max \
3497                     2>/dev/null")
3498         if [ -z "$mds" ]; then
3499                 #running this on an old MDT
3500                 thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' 16
3501         else
3502                 thread_sanity MDT $SINGLEMDS 'mds.*.*.' 'mds_num_threads' 16
3503         fi
3504         cleanup
3505 }
3506 run_test 53b "check MDS thread count params"
3507
3508 test_54a() {
3509         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3510                 skip "Only applicable to ldiskfs-based MDTs"
3511                 return
3512         fi
3513
3514     do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p
3515     [ $? -eq 0 ] || error "llverdev failed!"
3516     reformat_and_config
3517 }
3518 run_test 54a "test llverdev and partial verify of device"
3519
3520 test_54b() {
3521         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3522                 skip "Only applicable to ldiskfs-based MDTs"
3523                 return
3524         fi
3525
3526     setup
3527     run_llverfs $MOUNT -p
3528     [ $? -eq 0 ] || error "llverfs failed!"
3529     cleanup
3530 }
3531 run_test 54b "test llverfs and partial verify of filesystem"
3532
3533 lov_objid_size()
3534 {
3535         local max_ost_index=$1
3536         echo -n $(((max_ost_index + 1) * 8))
3537 }
3538
3539 test_55() {
3540         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3541                 skip "Only applicable to ldiskfs-based MDTs"
3542                 return
3543         fi
3544
3545         local mdsdev=$(mdsdevname 1)
3546         local mdsvdev=$(mdsvdevname 1)
3547
3548         for i in 1023 2048
3549         do
3550                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
3551                         $mdsvdev || exit 10
3552                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
3553                         --reformat $(ostdevname 1) $(ostvdevname 1)
3554                 setup_noconfig
3555                 stopall
3556                 setup_noconfig
3557                 sync
3558
3559                 echo checking size of lov_objid for ost index $i
3560                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" | grep ^User | awk '{print $6}')
3561                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
3562                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
3563                 else
3564                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
3565                 fi
3566                 stopall
3567         done
3568
3569         reformat
3570 }
3571 run_test 55 "check lov_objid size"
3572
3573 test_56() {
3574         local mds_journal_size_orig=$MDSJOURNALSIZE
3575
3576         MDSJOURNALSIZE=16
3577
3578         for num in $(seq 1 $MDSCOUNT); do
3579                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3580                         --reformat $(mdsdevname $num) $(mdsvdevname $num)
3581         done
3582         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=1000 --reformat \
3583                 $(ostdevname 1) $(ostvdevname 1)
3584         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=10000 --reformat \
3585                 $(ostdevname 2) $(ostvdevname 2)
3586
3587         start_mgsmds
3588         start_ost
3589         start_ost2 || error "Unable to start second ost"
3590         mount_client $MOUNT || error "Unable to mount client"
3591         echo ok
3592         $LFS osts
3593         stopall
3594         MDSJOURNALSIZE=$mds_journal_size_orig
3595         reformat
3596 }
3597 run_test 56 "check big indexes"
3598
3599 test_57a() { # bug 22656
3600         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3601         writeconf_or_reformat
3602         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3603         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" || error "tunefs failed"
3604         start_mgsmds
3605         start_ost && error "OST registration from failnode should fail"
3606         reformat
3607 }
3608 run_test 57a "initial registration from failnode should fail (should return errs)"
3609
3610 test_57b() {
3611         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3612         writeconf_or_reformat
3613         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3614         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" || error "tunefs failed"
3615         start_mgsmds
3616         start_ost || error "OST registration from servicenode should not fail"
3617         reformat
3618 }
3619 run_test 57b "initial registration from servicenode should not fail"
3620
3621 count_osts() {
3622         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
3623 }
3624
3625 test_58() { # bug 22658
3626         setup_noconfig
3627         mkdir -p $DIR/$tdir
3628         createmany -o $DIR/$tdir/$tfile-%d 100
3629         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
3630 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
3631         do_facet $SINGLEMDS "lctl set_param fail_loc=0x601"
3632         unlinkmany $DIR/$tdir/$tfile-%d 100
3633         stop_mds
3634
3635         local MNTDIR=$(facet_mntpt $SINGLEMDS)
3636         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3637
3638         # remove all files from the OBJECTS dir
3639         mount_fstype $SINGLEMDS
3640
3641         do_facet $SINGLEMDS "find $MNTDIR/O/1/d* -type f -delete"
3642
3643         unmount_fstype $SINGLEMDS
3644         # restart MDS with missing llog files
3645         start_mds
3646         do_facet mds "lctl set_param fail_loc=0"
3647         reformat
3648 }
3649 run_test 58 "missing llog files must not prevent MDT from mounting"
3650
3651 test_59() {
3652         start_mgsmds >> /dev/null
3653         local C1=$(count_osts)
3654         if [ $C1 -eq 0 ]; then
3655                 start_ost >> /dev/null
3656                 C1=$(count_osts)
3657         fi
3658         stopall
3659         echo "original ost count: $C1 (expect > 0)"
3660         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
3661         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
3662         local C2=$(count_osts)
3663         echo "after mdt writeconf count: $C2 (expect 0)"
3664         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
3665         echo "OST start without writeconf should fail:"
3666         start_ost >> /dev/null && error "OST start without writeconf didn't fail"
3667         echo "OST start with writeconf should succeed:"
3668         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
3669         local C3=$(count_osts)
3670         echo "after ost writeconf count: $C3 (expect 1)"
3671         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
3672         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
3673         local C4=$(count_osts)
3674         echo "after ost2 writeconf count: $C4 (expect 2)"
3675         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
3676         stop_ost2 >> /dev/null
3677         cleanup_nocli >> /dev/null
3678         #writeconf to remove all ost2 traces for subsequent tests
3679         writeconf_or_reformat
3680 }
3681 run_test 59 "writeconf mount option"
3682
3683 test_60() { # LU-471
3684         local num
3685
3686         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3687                 skip "Only applicable to ldiskfs-based MDTs"
3688                 return
3689         fi
3690
3691         for num in $(seq $MDSCOUNT); do
3692                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3693                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
3694                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3695                         exit 10
3696         done
3697
3698         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
3699         rc=${PIPESTATUS[0]}
3700         [ $rc -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
3701
3702         # MDT default has dirdata feature
3703         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
3704         # we disable uninit_bg feature
3705         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
3706         # we set stride extended options
3707         echo $dump | grep stride > /dev/null || error "stride is not set"
3708         reformat
3709 }
3710 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
3711
3712 test_61() { # LU-80
3713         local reformat=false
3714
3715         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
3716                 { skip "Need MDS version at least 2.1.53"; return 0; }
3717
3718         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3719            ! large_xattr_enabled; then
3720                 reformat=true
3721                 LDISKFS_MKFS_OPTS+=" -O large_xattr"
3722
3723                 for num in $(seq $MDSCOUNT); do
3724                         add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
3725                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3726                         error "add mds $num failed"
3727                 done
3728         fi
3729
3730     setup_noconfig || error "setting up the filesystem failed"
3731     client_up || error "starting client failed"
3732
3733     local file=$DIR/$tfile
3734     touch $file
3735
3736     local large_value="$(generate_string $(max_xattr_size))"
3737     local small_value="bar"
3738
3739     local name="trusted.big"
3740     log "save large xattr $name on $file"
3741     setfattr -n $name -v $large_value $file ||
3742         error "saving $name on $file failed"
3743
3744     local new_value=$(get_xattr_value $name $file)
3745     [[ "$new_value" != "$large_value" ]] &&
3746         error "$name different after saving"
3747
3748     log "shrink value of $name on $file"
3749     setfattr -n $name -v $small_value $file ||
3750         error "shrinking value of $name on $file failed"
3751
3752     new_value=$(get_xattr_value $name $file)
3753     [[ "$new_value" != "$small_value" ]] &&
3754         error "$name different after shrinking"
3755
3756     log "grow value of $name on $file"
3757     setfattr -n $name -v $large_value $file ||
3758         error "growing value of $name on $file failed"
3759
3760     new_value=$(get_xattr_value $name $file)
3761     [[ "$new_value" != "$large_value" ]] &&
3762         error "$name different after growing"
3763
3764     log "check value of $name on $file after remounting MDS"
3765     fail $SINGLEMDS
3766     new_value=$(get_xattr_value $name $file)
3767     [[ "$new_value" != "$large_value" ]] &&
3768         error "$name different after remounting MDS"
3769
3770     log "remove large xattr $name from $file"
3771     setfattr -x $name $file || error "removing $name from $file failed"
3772
3773     rm -f $file
3774     stopall
3775         if $reformat; then
3776                 LDISKFS_MKFS_OPTS=${LDISKFS_MKFS_OPTS% -O large_xattr}
3777                 reformat
3778         fi
3779 }
3780 run_test 61 "large xattr"
3781
3782 test_62() {
3783         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3784                 skip "Only applicable to ldiskfs-based MDTs"
3785                 return
3786         fi
3787
3788         # MRP-118
3789         local mdsdev=$(mdsdevname 1)
3790         local ostdev=$(ostdevname 1)
3791
3792         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
3793                 { skip "Need MDS version at least 2.2.51"; return 0; }
3794
3795         echo "disable journal for mds"
3796         do_facet mds tune2fs -O ^has_journal $mdsdev || error "tune2fs failed"
3797         start_mds && error "MDT start should fail"
3798         echo "disable journal for ost"
3799         do_facet ost1 tune2fs -O ^has_journal $ostdev || error "tune2fs failed"
3800         start_ost && error "OST start should fail"
3801         cleanup || return $?
3802         reformat_and_config
3803 }
3804 run_test 62 "start with disabled journal"
3805
3806 test_63() {
3807         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3808                 skip "Only applicable to ldiskfs-based MDTs"
3809                 return
3810         fi
3811
3812         local inode_slab=$(do_facet $SINGLEMDS \
3813                 "awk '/ldiskfs_inode_cache/ { print \\\$5 }' /proc/slabinfo")
3814         if [ -z "$inode_slab" ]; then
3815                 skip "ldiskfs module has not been loaded"
3816                 return
3817         fi
3818
3819         echo "$inode_slab ldisk inodes per page"
3820         [ "$inode_slab" -ge "3" ] ||
3821                 error "ldisk inode size is too big, $inode_slab objs per page"
3822         return
3823 }
3824 run_test 63 "Verify each page can at least hold 3 ldisk inodes"
3825
3826 test_64() {
3827         start_mds
3828         start_ost
3829         start_ost2 || error "Unable to start second ost"
3830         mount_client $MOUNT || error "Unable to mount client"
3831         stop_ost2 || error "Unable to stop second ost"
3832         echo "$LFS df"
3833         $LFS df --lazy || error "lfs df failed"
3834         cleanup || return $?
3835         #writeconf to remove all ost2 traces for subsequent tests
3836         writeconf_or_reformat
3837 }
3838 run_test 64 "check lfs df --lazy "
3839
3840 test_65() { # LU-2237
3841         # Currently, the test is only valid for ldiskfs backend
3842         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3843                 skip "non-ldiskfs backend" && return
3844
3845         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3846         local brpt=$(facet_mntpt brpt)
3847         local opts=""
3848
3849         if ! do_facet $SINGLEMDS "test -b $devname"; then
3850                 opts="-o loop"
3851         fi
3852
3853         stop_mds
3854         local obj=$(do_facet $SINGLEMDS \
3855                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
3856                     grep Inode)
3857         if [ -z "$obj" ]; then
3858                 # The MDT may be just re-formatted, mount the MDT for the
3859                 # first time to guarantee the "last_rcvd" file is there.
3860                 start_mds || error "fail to mount the MDS for the first time"
3861                 stop_mds
3862         fi
3863
3864         # remove the "last_rcvd" file
3865         do_facet $SINGLEMDS "mkdir -p $brpt"
3866         do_facet $SINGLEMDS \
3867                 "mount -t $(facet_fstype $SINGLEMDS) $opts $devname $brpt"
3868         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
3869         do_facet $SINGLEMDS "umount -d $brpt"
3870
3871         # restart MDS, the "last_rcvd" file should be recreated.
3872         start_mds || error "fail to restart the MDS"
3873         stop_mds
3874         obj=$(do_facet $SINGLEMDS \
3875               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
3876         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
3877 }
3878 run_test 65 "re-create the lost last_rcvd file when server mount"
3879
3880 test_66() {
3881         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
3882                 { skip "Need MGS version at least 2.3.59"; return 0; }
3883
3884         setup
3885         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
3886         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
3887
3888         echo "replace_nids should fail if MDS, OSTs and clients are UP"
3889         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3890                 error "replace_nids fail"
3891
3892         umount_client $MOUNT || error "unmounting client failed"
3893         echo "replace_nids should fail if MDS and OSTs are UP"
3894         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3895                 error "replace_nids fail"
3896
3897         stop_ost
3898         echo "replace_nids should fail if MDS is UP"
3899         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3900                 error "replace_nids fail"
3901
3902         stop_mds || error "stopping mds failed"
3903
3904         if combined_mgs_mds; then
3905                 start_mdt 1 "-o nosvc" ||
3906                         error "starting mds with nosvc option failed"
3907         fi
3908
3909         echo "command should accept two parameters"
3910         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
3911                 error "command should accept two params"
3912
3913         echo "correct device name should be passed"
3914         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
3915                 error "wrong devname"
3916
3917         echo "wrong nids list should not destroy the system"
3918         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
3919                 error "wrong parse"
3920
3921         echo "replace OST nid"
3922         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
3923                 error "replace nids failed"
3924
3925         echo "command should accept two parameters"
3926         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
3927                 error "command should accept two params"
3928
3929         echo "wrong nids list should not destroy the system"
3930         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
3931                 error "wrong parse"
3932
3933         echo "replace MDS nid"
3934         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
3935                 error "replace nids failed"
3936
3937         if ! combined_mgs_mds ; then
3938                 stop_mgs
3939         else
3940                 stop_mds
3941         fi
3942
3943         setup_noconfig
3944         check_mount || error "error after nid replace"
3945         cleanup || error "cleanup failed"
3946         reformat
3947 }
3948 run_test 66 "replace nids"
3949
3950 test_67() { #LU-2950
3951         local legacy="$TMP/legacy_lnet_config"
3952         local new="$TMP/new_routes_test"
3953         local out="$TMP/config_out_file"
3954         local verify="$TMP/conv_verify"
3955         local verify_conf="$TMP/conf_verify"
3956
3957         # Create the legacy file that will be run through the
3958         # lustre_routes_conversion script
3959         cat <<- LEGACY_LNET_CONFIG > $legacy
3960                 tcp1 23 192.168.213.1@tcp:1; tcp5 34 193.30.4.3@tcp:4;
3961                 tcp2 54 10.1.3.2@tcp;
3962                 tcp3 10.3.4.3@tcp:3;
3963                 tcp4 10.3.3.4@tcp;
3964         LEGACY_LNET_CONFIG
3965
3966         # Create the verification file to verify the output of
3967         # lustre_routes_conversion script against.
3968         cat <<- VERIFY_LNET_CONFIG > $verify
3969                 tcp1: { gateway: 192.168.213.1@tcp, hop: 23, priority: 1 }
3970                 tcp5: { gateway: 193.30.4.3@tcp, hop: 34, priority: 4 }
3971                 tcp2: { gateway: 10.1.3.2@tcp, hop: 54 }
3972                 tcp3: { gateway: 10.3.4.3@tcp, priority: 3 }
3973                 tcp4: { gateway: 10.3.3.4@tcp }
3974         VERIFY_LNET_CONFIG
3975
3976         # Create the verification file to verify the output of
3977         # lustre_routes_config script against
3978         cat <<- VERIFY_LNET_CONFIG > $verify_conf
3979                 lctl --net tcp1 add_route 192.168.213.1@tcp 23 1
3980                 lctl --net tcp5 add_route 193.30.4.3@tcp 34 4
3981                 lctl --net tcp2 add_route 10.1.3.2@tcp 54 4
3982                 lctl --net tcp3 add_route 10.3.4.3@tcp 1 3
3983                 lctl --net tcp4 add_route 10.3.3.4@tcp 1 3
3984         VERIFY_LNET_CONFIG
3985
3986         lustre_routes_conversion $legacy $new > /dev/null
3987         if [ -f $new ]; then
3988                 # verify the conversion output
3989                 cmp -s $new $verify > /dev/null
3990                 if [ $? -eq 1 ]; then
3991                         error "routes conversion failed"
3992                 fi
3993
3994                 lustre_routes_config --dry-run --verbose $new > $out
3995                 # check that the script succeeded
3996                 cmp -s $out $verify_conf > /dev/null
3997                 if [ $? -eq 1 ]; then
3998                         error "routes config failed"
3999                 fi
4000         else
4001                 error "routes conversion test failed"
4002         fi
4003         # remove generated files
4004         rm -f $new $legacy $verify $verify_conf $out
4005 }
4006 run_test 67 "test routes conversion and configuration"
4007
4008 test_68() {
4009         local fid
4010         local seq
4011         local START
4012         local END
4013
4014         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.53) ] ||
4015                 { skip "Need MDS version at least 2.4.53"; return 0; }
4016
4017         umount_client $MOUNT || error "umount client failed"
4018
4019         start_mdt 1 || error "MDT start failed"
4020         start_ost
4021
4022         # START-END - the sequences we'll be reserving
4023         START=$(do_facet $SINGLEMDS \
4024                 lctl get_param -n seq.ctl*.space | awk -F'[[ ]' '{print $2}')
4025         END=$((START + (1 << 30)))
4026         do_facet $SINGLEMDS \
4027                 lctl set_param seq.ctl*.fldb="[$START-$END\):0:mdt"
4028
4029         # reset the sequences MDT0000 has already assigned
4030         do_facet $SINGLEMDS \
4031                 lctl set_param seq.srv*MDT0000.space=clear
4032
4033         # remount to let the client allocate new sequence
4034         mount_client $MOUNT || error "mount client failed"
4035
4036         touch $DIR/$tfile
4037         do_facet $SINGLEMDS \
4038                 lctl get_param seq.srv*MDT0000.space
4039         $LFS path2fid $DIR/$tfile
4040
4041         local old_ifs="$IFS"
4042         IFS='[:]'
4043         fid=($($LFS path2fid $DIR/$tfile))
4044         IFS="$old_ifs"
4045         let seq=${fid[1]}
4046
4047         if [[ $seq < $END ]]; then
4048                 error "used reserved sequence $seq?"
4049         fi
4050         cleanup || return $?
4051 }
4052 run_test 68 "be able to reserve specific sequences in FLDB"
4053
4054 test_69() {
4055         local server_version=$(lustre_version_code $SINGLEMDS)
4056
4057         [[ $server_version -lt $(version_code 2.4.2) ]] &&
4058                 skip "Need MDS version at least 2.4.2" && return
4059
4060         [[ $server_version -ge $(version_code 2.4.50) ]] &&
4061         [[ $server_version -lt $(version_code 2.5.0) ]] &&
4062                 skip "Need MDS version at least 2.5.0" && return
4063
4064         setup
4065
4066         # use OST0000 since it probably has the most creations
4067         local OSTNAME=$(ostname_from_index 0)
4068         local mdtosc_proc1=$(get_mdtosc_proc_path mds1 $OSTNAME)
4069         local last_id=$(do_facet mds1 lctl get_param -n \
4070                         osc.$mdtosc_proc1.prealloc_last_id)
4071
4072         # Want to have OST LAST_ID over 1.5 * OST_MAX_PRECREATE to
4073         # verify that the LAST_ID recovery is working properly.  If
4074         # not, then the OST will refuse to allow the MDS connect
4075         # because the LAST_ID value is too different from the MDS
4076         #define OST_MAX_PRECREATE=20000
4077         local num_create=$((20000 * 5))
4078
4079         mkdir -p $DIR/$tdir
4080         $LFS setstripe -i 0 $DIR/$tdir
4081         createmany -o $DIR/$tdir/$tfile- $num_create ||
4082                 error "createmany: failed to create $num_create files: $?"
4083         # delete all of the files with objects on OST0 so the
4084         # filesystem is not inconsistent later on
4085         $LFS find $MOUNT --ost 0 | xargs rm
4086
4087         stop_ost || error "OST0 stop failure"
4088         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat --replace \
4089                 $(ostdevname 1) $(ostvdevname 1) ||
4090                 error "reformat and replace $ostdev failed"
4091         start_ost || error "OST0 restart failure"
4092         wait_osc_import_state mds ost FULL
4093
4094         touch $DIR/$tdir/$tfile-last || error "create file after reformat"
4095         local idx=$($LFS getstripe -i $DIR/$tdir/$tfile-last)
4096         [ $idx -ne 0 ] && error "$DIR/$tdir/$tfile-last on $idx not 0" || true
4097
4098         cleanup
4099 }
4100 run_test 69 "replace an OST with the same index"
4101
4102 test_70a() {
4103         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4104         local MDTIDX=1
4105
4106         cleanup
4107
4108         start_mdt 1 || error "MDT0 start fail"
4109
4110         start_ost || error "OST0 start fail"
4111
4112         start_mdt 2 || error "MDT1 start fail"
4113
4114         mount_client $MOUNT || error "mount client fails"
4115
4116         mkdir -p $DIR/$tdir || error "create dir fail"
4117
4118         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4119                                         error "create remote dir fail"
4120
4121         rm -rf $DIR/$tdir || error "delete dir fail"
4122         cleanup || return $?
4123 }
4124 run_test 70a "start MDT0, then OST, then MDT1"
4125
4126 test_70b() {
4127         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4128         local MDTIDX=1
4129
4130         start_ost || error "OST0 start fail"
4131
4132         start_mdt 1 || error "MDT0 start fail"
4133         start_mdt 2 || error "MDT1 start fail"
4134
4135         mount_client $MOUNT || error "mount client fails"
4136
4137         mkdir -p $DIR/$tdir || error "create dir fail"
4138
4139         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4140                                         error "create remote dir fail"
4141
4142         rm -rf $DIR/$tdir || error "delete dir fail"
4143
4144         cleanup || return $?
4145 }
4146 run_test 70b "start OST, MDT1, MDT0"
4147
4148 test_70c() {
4149         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4150         local MDTIDX=1
4151
4152         start_mdt 1 || error "MDT0 start fail"
4153         start_mdt 2 || error "MDT1 start fail"
4154         start_ost || error "OST0 start fail"
4155
4156         mount_client $MOUNT || error "mount client fails"
4157         stop_mdt 1 || error "MDT1 start fail"
4158
4159         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
4160         echo "deactivate $mdc_for_mdt1"
4161         $LCTL --device $mdc_for_mdt1 deactivate || return 1
4162
4163         mkdir -p $DIR/$tdir && error "mkdir succeed"
4164
4165         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4166                                         error "create remote dir succeed"
4167
4168         cleanup || return $?
4169 }
4170 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
4171
4172 test_70d() {
4173         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4174         local MDTIDX=1
4175
4176         start_mdt 1 || error "MDT0 start fail"
4177         start_mdt 2 || error "MDT1 start fail"
4178         start_ost || error "OST0 start fail"
4179
4180         mount_client $MOUNT || error "mount client fails"
4181
4182         stop_mdt 2 || error "MDT1 start fail"
4183
4184         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
4185                              awk '{print $4}')
4186         echo "deactivate $mdc_for_mdt2"
4187         $LCTL --device $mdc_for_mdt2 deactivate ||
4188                         error "set $mdc_for_mdt2 deactivate failed"
4189
4190         mkdir -p $DIR/$tdir || error "mkdir fail"
4191         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4192                         error "create remote dir succeed"
4193
4194         rm -rf $DIR/$tdir || error "delete dir fail"
4195
4196         cleanup || return $?
4197 }
4198 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
4199
4200 test_71a() {
4201         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4202         if combined_mgs_mds; then
4203                 skip "needs separate MGS/MDT" && return
4204         fi
4205         local MDTIDX=1
4206
4207         start_mdt 1 || error "MDT0 start fail"
4208         start_ost || error "OST0 start fail"
4209         start_mdt 2 || error "MDT1 start fail"
4210         start_ost2 || error "OST1 start fail"
4211
4212         mount_client $MOUNT || error "mount client fails"
4213
4214         mkdir -p $DIR/$tdir || error "mkdir fail"
4215         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4216                         error "create remote dir succeed"
4217
4218         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4219         rm -rf $DIR/$tdir || error "delete dir fail"
4220
4221         umount_client $MOUNT
4222         stop_mdt 1 || error "MDT0 stop fail"
4223         stop_mdt 2 || error "MDT1 stop fail"
4224         stop_ost || error "OST0 stop fail"
4225         stop_ost2 || error "OST1 stop fail"
4226 }
4227 run_test 71a "start MDT0 OST0, MDT1, OST1"
4228
4229 test_71b() {
4230         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4231         if combined_mgs_mds; then
4232                 skip "needs separate MGS/MDT" && return
4233         fi
4234         local MDTIDX=1
4235
4236         start_mdt 2 || error "MDT1 start fail"
4237         start_ost || error "OST0 start fail"
4238         start_mdt 1 || error "MDT0 start fail"
4239         start_ost2 || error "OST1 start fail"
4240
4241         mount_client $MOUNT || error "mount client fails"
4242
4243         mkdir -p $DIR/$tdir || error "mkdir fail"
4244         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4245                         error "create remote dir succeed"
4246
4247         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4248         rm -rf $DIR/$tdir || error "delete dir fail"
4249
4250         umount_client $MOUNT
4251         stop_mdt 1 || error "MDT0 stop fail"
4252         stop_mdt 2 || error "MDT1 stop fail"
4253         stop_ost || error "OST0 stop fail"
4254         stop_ost2 || error "OST1 stop fail"
4255 }
4256 run_test 71b "start MDT1, OST0, MDT0, OST1"
4257
4258 test_71c() {
4259         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4260         if combined_mgs_mds; then
4261                 skip "needs separate MGS/MDT" && return
4262         fi
4263         local MDTIDX=1
4264
4265         start_ost || error "OST0 start fail"
4266         start_ost2 || error "OST1 start fail"
4267         start_mdt 2 || error "MDT1 start fail"
4268         start_mdt 1 || error "MDT0 start fail"
4269
4270         mount_client $MOUNT || error "mount client fails"
4271
4272         mkdir -p $DIR/$tdir || error "mkdir fail"
4273         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4274                         error "create remote dir succeed"
4275
4276         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4277         rm -rf $DIR/$tdir || error "delete dir fail"
4278
4279         umount_client $MOUNT
4280         stop_mdt 1 || error "MDT0 stop fail"
4281         stop_mdt 2 || error "MDT1 stop fail"
4282         stop_ost || error "OST0 stop fail"
4283         stop_ost2 || error "OST1 stop fail"
4284
4285 }
4286 run_test 71c "start OST0, OST1, MDT1, MDT0"
4287
4288 test_71d() {
4289         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4290         if combined_mgs_mds; then
4291                 skip "needs separate MGS/MDT" && return
4292         fi
4293         local MDTIDX=1
4294
4295         start_ost || error "OST0 start fail"
4296         start_mdt 2 || error "MDT0 start fail"
4297         start_mdt 1 || error "MDT0 start fail"
4298         start_ost2 || error "OST1 start fail"
4299
4300         mount_client $MOUNT || error "mount client fails"
4301
4302         mkdir -p $DIR/$tdir || error "mkdir fail"
4303         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4304                         error "create remote dir succeed"
4305
4306         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4307         rm -rf $DIR/$tdir || error "delete dir fail"
4308
4309         umount_client $MOUNT
4310         stop_mdt 1 || error "MDT0 stop fail"
4311         stop_mdt 2 || error "MDT1 stop fail"
4312         stop_ost || error "OST0 stop fail"
4313         stop_ost2 || error "OST1 stop fail"
4314
4315 }
4316 run_test 71d "start OST0, MDT1, MDT0, OST1"
4317
4318 test_71e() {
4319         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4320         if combined_mgs_mds; then
4321                 skip "needs separate MGS/MDT" && return
4322         fi
4323         local MDTIDX=1
4324
4325         start_ost || error "OST0 start fail"
4326         start_mdt 2 || error "MDT1 start fail"
4327         start_ost2 || error "OST1 start fail"
4328         start_mdt 1 || error "MDT0 start fail"
4329
4330         mount_client $MOUNT || error "mount client fails"
4331
4332         mkdir -p $DIR/$tdir || error "mkdir fail"
4333         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4334                         error "create remote dir succeed"
4335
4336         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4337         rm -rf $DIR/$tdir || error "delete dir fail"
4338
4339         umount_client $MOUNT
4340         stop_mdt 1 || error "MDT0 stop fail"
4341         stop_mdt 2 || error "MDT1 stop fail"
4342         stop_ost || error "OST0 stop fail"
4343         stop_ost2 || error "OST1 stop fail"
4344
4345 }
4346 run_test 71e "start OST0, MDT1, OST1, MDT0"
4347
4348 test_72() { #LU-2634
4349         local mdsdev=$(mdsdevname 1)
4350         local ostdev=$(ostdevname 1)
4351         local cmd="$E2FSCK -fnvd $mdsdev"
4352         local fn=3
4353
4354         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
4355                 skip "ldiskfs only test" && return
4356
4357         #tune MDT with "-O extents"
4358
4359         for num in $(seq $MDSCOUNT); do
4360                 add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
4361                 --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
4362                 error "add mds $num failed"
4363                 $TUNE2FS -O extents $(mdsdevname $num)
4364         done
4365
4366         add ost1 $(mkfs_opts ost1 $ostdev) --reformat $ostdev ||
4367                 error "add $ostdev failed"
4368         start_mgsmds || error "start mds failed"
4369         start_ost || error "start ost failed"
4370         mount_client $MOUNT || error "mount client failed"
4371
4372         #create some short symlinks
4373         mkdir -p $DIR/$tdir
4374         createmany -o $DIR/$tdir/$tfile-%d $fn
4375         echo "create $fn short symlinks"
4376         for i in $(seq -w 1 $fn); do
4377                 ln -s $DIR/$tdir/$tfile-$i $MOUNT/$tfile-$i
4378         done
4379         ls -al $MOUNT
4380
4381         #umount
4382         umount_client $MOUNT || error "umount client failed"
4383         stop_mds || error "stop mds failed"
4384         stop_ost || error "stop ost failed"
4385
4386         #run e2fsck
4387         run_e2fsck $(facet_active_host $SINGLEMDS) $mdsdev "-n"
4388 }
4389 run_test 72 "test fast symlink with extents flag enabled"
4390
4391 test_73() { #LU-3006
4392         load_modules
4393         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
4394         do_facet ost1 "$TUNEFS --failnode=1.2.3.4@$NETTYPE $(ostdevname 1)" ||
4395                 error "1st tunefs failed"
4396         start_mgsmds || error "start mds failed"
4397         start_ost || error "start ost failed"
4398         mount_client $MOUNT || error "mount client failed"
4399         lctl get_param -n osc.*OST0000-osc-[^M]*.import | grep failover_nids |
4400                 grep 1.2.3.4@$NETTYPE || error "failover nids haven't changed"
4401         umount_client $MOUNT || error "umount client failed"
4402         stopall
4403         reformat
4404 }
4405 run_test 73 "failnode to update from mountdata properly"
4406
4407 test_75() { # LU-2374
4408         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
4409                         skip "Need MDS version at least 2.4.1" && return
4410
4411         local index=0
4412         local opts_mds="$(mkfs_opts mds1 $(mdsdevname 1)) \
4413                 --reformat $(mdsdevname 1) $(mdsvdevname 1)"
4414         local opts_ost="$(mkfs_opts ost1 $(ostdevname 1)) \
4415                 --reformat $(ostdevname 1) $(ostvdevname 1)"
4416
4417         #check with default parameters
4418         add mds1 $opts_mds || error "add mds1 failed for default params"
4419         add ost1 $opts_ost || error "add ost1 failed for default params"
4420
4421         opts_mds=$(echo $opts_mds | sed -e "s/--mdt//")
4422         opts_mds=$(echo $opts_mds |
4423                    sed -e "s/--index=$index/--index=$index --mdt/")
4424         opts_ost=$(echo $opts_ost | sed -e "s/--ost//")
4425         opts_ost=$(echo $opts_ost |
4426                    sed -e "s/--index=$index/--index=$index --ost/")
4427
4428         add mds1 $opts_mds || error "add mds1 failed for new params"
4429         add ost1 $opts_ost || error "add ost1 failed for new params"
4430         return 0
4431 }
4432 run_test 75 "The order of --index should be irrelevant"
4433
4434 test_76a() {
4435         [[ $(lustre_version_code mgs) -ge $(version_code 2.4.52) ]] ||
4436                 { skip "Need MDS version at least 2.4.52" && return 0; }
4437         setup
4438         local MDMB_PARAM="osc.*.max_dirty_mb"
4439         echo "Change MGS params"
4440         local MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM |
4441                 head -1)
4442         echo "max_dirty_mb: $MAX_DIRTY_MB"
4443         local NEW_MAX_DIRTY_MB=$((MAX_DIRTY_MB + MAX_DIRTY_MB))
4444         echo "new_max_dirty_mb: $NEW_MAX_DIRTY_MB"
4445         do_facet mgs $LCTL set_param -P $MDMB_PARAM=$NEW_MAX_DIRTY_MB
4446         wait_update $HOSTNAME "lctl get_param -n $MDMB_PARAM |
4447                 head -1" $NEW_MAX_DIRTY_MB
4448         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
4449         echo "$MAX_DIRTY_MB"
4450         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
4451                 error "error while apply max_dirty_mb"
4452
4453         echo "Check the value is stored after remount"
4454         stopall
4455         setupall
4456         wait_update $HOSTNAME "lctl get_param -n $MDMB_PARAM |
4457                 head -1" $NEW_MAX_DIRTY_MB
4458         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
4459         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
4460                 error "max_dirty_mb is not saved after remount"
4461
4462         echo "Change OST params"
4463         CLIENT_PARAM="obdfilter.*.client_cache_count"
4464         local CLIENT_CACHE_COUNT
4465         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4466                 head -1)
4467         echo "client_cache_count: $CLIENT_CACHE_COUNT"
4468         NEW_CLIENT_CACHE_COUNT=$((CLIENT_CACHE_COUNT+CLIENT_CACHE_COUNT))
4469         echo "new_client_cache_count: $NEW_CLIENT_CACHE_COUNT"
4470         do_facet mgs $LCTL set_param -P $CLIENT_PARAM=$NEW_CLIENT_CACHE_COUNT
4471         wait_update $(facet_host ost1) "lctl get_param -n $CLIENT_PARAM |
4472                 head -1" $NEW_CLIENT_CACHE_COUNT
4473         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4474                 head -1)
4475         echo "$CLIENT_CACHE_COUNT"
4476         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
4477                 error "error while apply client_cache_count"
4478
4479         echo "Check the value is stored after remount"
4480         stopall
4481         setupall
4482         wait_update $(facet_host ost1) "lctl get_param -n $CLIENT_PARAM |
4483                 head -1" $NEW_CLIENT_CACHE_COUNT
4484         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4485                 head -1)
4486         echo "$CLIENT_CACHE_COUNT"
4487         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
4488                 error "client_cache_count is not saved after remount"
4489         stopall
4490 }
4491 run_test 76a "set permanent params set_param -P"
4492
4493 test_76b() { # LU-4783
4494         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.57) ]] ||
4495                 { skip "Need MGS version at least 2.5.57" && return 0; }
4496         stopall
4497         setupall
4498         do_facet mgs $LCTL get_param mgs.MGS.live.params ||
4499                 error "start params log failed"
4500         stopall
4501 }
4502 run_test 76b "verify params log setup correctly"
4503
4504 test_77() { # LU-3445
4505         local server_version=$(lustre_version_code $SINGLEMDS)
4506
4507         [[ $server_version -ge $(version_code 2.2.60) ]] &&
4508         [[ $server_version -le $(version_code 2.4.0) ]] &&
4509                 skip "Need MDS version < 2.2.60 or > 2.4.0" && return
4510
4511         if [[ -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
4512                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
4513                 skip_env "mixed loopback and real device not working" && return
4514         fi
4515
4516         local fs2mdsdev=$(mdsdevname 1_2)
4517         local fs2ostdev=$(ostdevname 1_2)
4518         local fs2mdsvdev=$(mdsvdevname 1_2)
4519         local fs2ostvdev=$(ostvdevname 1_2)
4520         local fsname=test1234
4521         local mgsnid
4522         local failnid="$(h2$NETTYPE 1.2.3.4),$(h2$NETTYPE 4.3.2.1)"
4523
4524         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --mgs --fsname=$fsname \
4525                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
4526         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT ||
4527                 error "start fs2mds failed"
4528
4529         mgsnid=$(do_facet fs2mds $LCTL list_nids | xargs | tr ' ' ,)
4530         [[ $mgsnid = *,* ]] || mgsnid+=",$mgsnid"
4531
4532         add fs2ost $(mkfs_opts ost1 $fs2ostdev) --mgsnode=$mgsnid \
4533                 --failnode=$failnid --fsname=$fsname \
4534                 --reformat $fs2ostdev $fs2ostvdev ||
4535                         error "add fs2ost failed"
4536         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
4537
4538         mkdir -p $MOUNT2
4539         $MOUNT_CMD $mgsnid:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
4540         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
4541         cleanup_fs2
4542 }
4543 run_test 77 "comma-separated MGS NIDs and failover node NIDs"
4544
4545 test_78() {
4546         [[ $(facet_fstype $SINGLEMDS) != ldiskfs ||
4547            $(facet_fstype ost1) != ldiskfs ]] &&
4548                 skip "only applicable to ldiskfs-based MDTs and OSTs" && return
4549
4550         # reformat the Lustre filesystem with a smaller size
4551         local saved_MDSSIZE=$MDSSIZE
4552         local saved_OSTSIZE=$OSTSIZE
4553         MDSSIZE=$((MDSSIZE - 20000))
4554         OSTSIZE=$((OSTSIZE - 20000))
4555         reformat || error "(1) reformat Lustre filesystem failed"
4556         MDSSIZE=$saved_MDSSIZE
4557         OSTSIZE=$saved_OSTSIZE
4558
4559         # mount the Lustre filesystem
4560         setup_noconfig || error "(2) setup Lustre filesystem failed"
4561
4562         # create some files
4563         log "create test files"
4564         local i
4565         local file
4566         local num_files=100
4567         mkdir -p $MOUNT/$tdir || error "(3) mkdir $MOUNT/$tdir failed"
4568         for i in $(seq $num_files); do
4569                 file=$MOUNT/$tdir/$tfile-$i
4570                 dd if=/dev/urandom of=$file count=1 bs=1M ||
4571                         error "(4) create $file failed"
4572         done
4573
4574         # unmount the Lustre filesystem
4575         cleanup || error "(5) cleanup Lustre filesystem failed"
4576
4577         # run e2fsck on the MDT and OST devices
4578         local mds_host=$(facet_active_host $SINGLEMDS)
4579         local ost_host=$(facet_active_host ost1)
4580         local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4581         local ost_dev=$(ostdevname 1)
4582
4583         run_e2fsck $mds_host $mds_dev "-y"
4584         run_e2fsck $ost_host $ost_dev "-y"
4585
4586         # get the original block count of the MDT and OST filesystems
4587         local mds_orig_blks=$(get_block_count $SINGLEMDS $mds_dev)
4588         local ost_orig_blks=$(get_block_count ost1 $ost_dev)
4589
4590         # expand the MDT and OST filesystems to the device size
4591         run_resize2fs $SINGLEMDS $mds_dev "" || error "expand $SINGLEMDS failed"
4592         run_resize2fs ost1 $ost_dev "" || error "expand ost1 failed"
4593
4594         # run e2fsck on the MDT and OST devices again
4595         run_e2fsck $mds_host $mds_dev "-y"
4596         run_e2fsck $ost_host $ost_dev "-y"
4597
4598         # mount the Lustre filesystem
4599         setup
4600
4601         # check the files
4602         log "check files after expanding the MDT and OST filesystems"
4603         for i in $(seq $num_files); do
4604                 file=$MOUNT/$tdir/$tfile-$i
4605                 $CHECKSTAT -t file -s 1048576 $file ||
4606                         error "(6) checkstat $file failed"
4607         done
4608
4609         # create more files
4610         log "create more files after expanding the MDT and OST filesystems"
4611         for i in $(seq $((num_files + 1)) $((num_files + 10))); do
4612                 file=$MOUNT/$tdir/$tfile-$i
4613                 dd if=/dev/urandom of=$file count=1 bs=1M ||
4614                         error "(7) create $file failed"
4615         done
4616
4617         # unmount the Lustre filesystem
4618         cleanup || error "(8) cleanup Lustre filesystem failed"
4619
4620         # run e2fsck on the MDT and OST devices
4621         run_e2fsck $mds_host $mds_dev "-y"
4622         run_e2fsck $ost_host $ost_dev "-y"
4623
4624         # get the maximum block count of the MDT and OST filesystems
4625         local mds_max_blks=$(get_block_count $SINGLEMDS $mds_dev)
4626         local ost_max_blks=$(get_block_count ost1 $ost_dev)
4627
4628         # get the minimum block count of the MDT and OST filesystems
4629         local mds_min_blks=$(run_resize2fs $SINGLEMDS $mds_dev "" "-P" 2>&1 |
4630                                 grep minimum | sed -e 's/^.*filesystem: //g')
4631         local ost_min_blks=$(run_resize2fs ost1 $ost_dev "" "-P" 2>&1 |
4632                                 grep minimum | sed -e 's/^.*filesystem: //g')
4633
4634         # shrink the MDT and OST filesystems to a smaller size
4635         local shrunk=false
4636         local new_blks
4637         local base_blks
4638         if [[ $mds_max_blks -gt $mds_min_blks &&
4639               $mds_max_blks -gt $mds_orig_blks ]]; then
4640                 [[ $mds_orig_blks -gt $mds_min_blks ]] &&
4641                         base_blks=$mds_orig_blks || base_blks=$mds_min_blks
4642                 new_blks=$(( (mds_max_blks - base_blks) / 2 + base_blks ))
4643                 run_resize2fs $SINGLEMDS $mds_dev $new_blks ||
4644                         error "shrink $SINGLEMDS to $new_blks failed"
4645                 shrunk=true
4646         fi
4647
4648         if [[ $ost_max_blks -gt $ost_min_blks &&
4649               $ost_max_blks -gt $ost_orig_blks ]]; then
4650                 [[ $ost_orig_blks -gt $ost_min_blks ]] &&
4651                         base_blks=$ost_orig_blks || base_blks=$ost_min_blks
4652                 new_blks=$(( (ost_max_blks - base_blks) / 2 + base_blks ))
4653                 run_resize2fs ost1 $ost_dev $new_blks ||
4654                         error "shrink ost1 to $new_blks failed"
4655                 shrunk=true
4656         fi
4657
4658         # check whether the MDT or OST filesystem was shrunk or not
4659         if ! $shrunk; then
4660                 combined_mgs_mds || stop_mgs || error "(9) stop mgs failed"
4661                 reformat || error "(10) reformat Lustre filesystem failed"
4662                 return 0
4663         fi
4664
4665         # run e2fsck on the MDT and OST devices again
4666         run_e2fsck $mds_host $mds_dev "-y"
4667         run_e2fsck $ost_host $ost_dev "-y"
4668
4669         # mount the Lustre filesystem again
4670         setup
4671
4672         # check the files
4673         log "check files after shrinking the MDT and OST filesystems"
4674         for i in $(seq $((num_files + 10))); do
4675                 file=$MOUNT/$tdir/$tfile-$i
4676                 $CHECKSTAT -t file -s 1048576 $file ||
4677                         error "(11) checkstat $file failed"
4678         done
4679
4680         # unmount and reformat the Lustre filesystem
4681         cleanup || error "(12) cleanup Lustre filesystem failed"
4682         combined_mgs_mds || stop_mgs || error "(13) stop mgs failed"
4683         reformat || error "(14) reformat Lustre filesystem failed"
4684 }
4685 run_test 78 "run resize2fs on MDT and OST filesystems"
4686
4687 test_79() { # LU-4227
4688         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.59) ]] ||
4689                 { skip "Need MDS version at least 2.5.59"; return 0; }
4690
4691         local mdsdev1=$(mdsdevname 1)
4692         local mdsvdev1=$(mdsvdevname 1)
4693         local mdsdev2=$(mdsdevname 2)
4694         local mdsvdev2=$(mdsvdevname 2)
4695         local ostdev1=$(ostdevname 1)
4696         local ostvdev1=$(ostvdevname 1)
4697         local opts_mds1="$(mkfs_opts mds1 $mdsdev1) --reformat"
4698         local opts_mds2="$(mkfs_opts mds2 $mdsdev2) --reformat"
4699         local opts_ost1="$(mkfs_opts ost1 $ostdev1) --reformat"
4700         local mgsnode_opt
4701
4702         # remove --mgs/--mgsnode from mkfs.lustre options
4703         opts_mds1=$(echo $opts_mds1 | sed -e "s/--mgs//")
4704
4705         mgsnode_opt=$(echo $opts_mds2 |
4706                 awk '{ for ( i = 1; i < NF; i++ )
4707                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
4708         [ -n $mgsnode_opt ] &&
4709                 opts_mds2=$(echo $opts_mds2 | sed -e "s/$mgsnode_opt//")
4710
4711         mgsnode_opt=$(echo $opts_ost1 |
4712                 awk '{ for ( i = 1; i < NF; i++ )
4713                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
4714         [ -n $mgsnode_opt ] &&
4715                 opts_ost1=$(echo $opts_ost1 | sed -e "s/$mgsnode_opt//")
4716
4717         # -MGS, format a mdt without --mgs option
4718         add mds1 $opts_mds1 $mdsdev1 $mdsvdev1 &&
4719                 error "Must specify --mgs when formatting mdt combined with mgs"
4720
4721         # +MGS, format a mdt/ost without --mgsnode option
4722         add mds1 $(mkfs_opts mds1 $mdsdev1) --reformat $mdsdev1 $mdsvdev1 \
4723                 > /dev/null || error "start mds1 failed"
4724         add mds2 $opts_mds2 $mdsdev2 $mdsvdev2 &&
4725                 error "Must specify --mgsnode when formatting a mdt"
4726         add ost1 $opts_ost1 $ostdev1 $ostvdev2 &&
4727                 error "Must specify --mgsnode when formatting an ost"
4728
4729         return 0
4730 }
4731 run_test 79 "format MDT/OST without mgs option (should return errors)"
4732
4733 test_80() {
4734         start_mds
4735         start_ost
4736         uuid=$(do_facet ost1 lctl get_param -n mgc.*.uuid)
4737 #define OBD_FAIL_MGS_PAUSE_TARGET_CON       0x906
4738         do_facet ost1 "lctl set_param fail_val=10 fail_loc=0x906"
4739         do_facet mgs "lctl set_param fail_val=10 fail_loc=0x906"
4740         do_facet mgs "lctl set_param -n mgs/MGS/evict_client $uuid"
4741         sleep 30
4742         start_ost2
4743
4744         do_facet ost1 "lctl set_param fail_loc=0"
4745         stopall
4746 }
4747 run_test 80 "mgc import reconnect race"
4748
4749 if ! combined_mgs_mds ; then
4750         stop mgs
4751 fi
4752
4753 cleanup_gss
4754
4755 # restore the values of MDSSIZE and OSTSIZE
4756 MDSSIZE=$STORED_MDSSIZE
4757 OSTSIZE=$STORED_OSTSIZE
4758 reformat
4759
4760 complete $SECONDS
4761 exit_status