Whamcloud - gitweb
LU-4018 tests: improve racer file_create workload
[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 |
1237                 grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1238         set_conf_param_and_check client "$TEST" \
1239                 "$FSNAME-OST0000.failover.node" $NEW ||
1240                 error "didn't add failover nid $NEW"
1241         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1242                 grep failover_nids)
1243         echo $NIDS
1244         # The NIDS value is the failover nid strings and "[" and "]". So
1245         # we need to subtract the space taken by the delimiters. This has
1246         # changed from earlier version of Lustre but this test is run only
1247         # locally so this change will not break interop. See LU-3386
1248         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 3))
1249         echo "should have 2 failover nids: $NIDCOUNT"
1250         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1251         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" ||
1252                 error "conf_param delete failed"
1253         umount_client $MOUNT
1254         mount_client $MOUNT || return 3
1255
1256         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1257                 grep failover_nids)
1258         echo $NIDS
1259         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 3))
1260         echo "only 1 final nid should remain: $NIDCOUNT"
1261         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1262
1263         cleanup
1264 }
1265 run_test 30b "Remove failover nids"
1266
1267 test_31() { # bug 10734
1268         # ipaddr must not exist
1269         $MOUNT_CMD 4.3.2.1@tcp:/lustre $MOUNT || true
1270         cleanup
1271 }
1272 run_test 31 "Connect to non-existent node (shouldn't crash)"
1273
1274
1275 T32_QID=60000
1276 T32_BLIMIT=20480 # Kbytes
1277 T32_ILIMIT=2
1278
1279 #
1280 # This is not really a test but a tool to create new disk
1281 # image tarballs for the upgrade tests.
1282 #
1283 # Disk image tarballs should be created on single-node
1284 # clusters by running this test with default configurations
1285 # plus a few mandatory environment settings that are verified
1286 # at the beginning of the test.
1287 #
1288 test_32newtarball() {
1289         local version
1290         local dst=.
1291         local src=/etc/rc.d
1292         local tmp=$TMP/t32_image_create
1293
1294         if [ $FSNAME != t32fs -o $MDSCOUNT -ne 1 -o                                                             \
1295                  \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o $OSTCOUNT -ne 1 -o                      \
1296                  -z "$OSTDEV1" ]; then
1297                 error "Needs FSNAME=t32fs MDSCOUNT=1 MDSDEV1=<nonexistent_file>"        \
1298                           "(or MDSDEV, in the case of b1_8) OSTCOUNT=1"                                 \
1299                           "OSTDEV1=<nonexistent_file>"
1300         fi
1301
1302         mkdir $tmp || {
1303                 echo "Found stale $tmp"
1304                 return 1
1305         }
1306
1307         mkdir $tmp/src
1308         tar cf - -C $src . | tar xf - -C $tmp/src
1309         dd if=/dev/zero of=$tmp/src/t32_qf_old bs=1M \
1310                 count=$(($T32_BLIMIT / 1024 / 2))
1311         chown $T32_QID.$T32_QID $tmp/src/t32_qf_old
1312
1313         # format ost with comma-separated NIDs to verify LU-4460
1314         local failnid="$(h2$NETTYPE 1.2.3.4),$(h2$NETTYPE 4.3.2.1)"
1315         MGSNID="$MGSNID,$MGSNID" OSTOPT="--failnode=$failnid" formatall
1316
1317         setupall
1318
1319         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1320                 $LFS quotacheck -ug /mnt/$FSNAME
1321         $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
1322                 /mnt/$FSNAME
1323
1324         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1325         stopall
1326
1327         mkdir $tmp/img
1328
1329         setupall
1330         pushd /mnt/$FSNAME
1331         ls -Rni --time-style=+%s >$tmp/img/list
1332         find . ! -name .lustre -type f -exec sha1sum {} \; |
1333                 sort -k 2 >$tmp/img/sha1sums
1334         popd
1335         $LCTL get_param -n version | head -n 1 |
1336                 sed -e 's/^lustre: *//' >$tmp/img/commit
1337
1338         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1339                 $LFS quotaon -ug /mnt/$FSNAME
1340         $LFS quota -u $T32_QID -v /mnt/$FSNAME
1341         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1342                 awk 'BEGIN { num='1' } { if ($1 == "'/mnt/$FSNAME'") \
1343                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1344                 | tr -d "*" > $tmp/img/bspace
1345         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1346                 awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
1347                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1348                 | tr -d "*" > $tmp/img/ispace
1349
1350         stopall
1351
1352         pushd $tmp/src
1353         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1354         popd
1355
1356         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1357                 echo "Data verification failed"
1358         fi
1359
1360         uname -r >$tmp/img/kernel
1361         uname -m >$tmp/img/arch
1362
1363         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1364         mv $OSTDEV1 $tmp/img
1365
1366         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1367                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1368         dst=$(cd $dst; pwd)
1369         pushd $tmp/img
1370         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1371         popd
1372
1373         rm -r $tmp
1374 }
1375 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1376
1377 #
1378 # The list of applicable tarballs is returned via the caller's
1379 # variable "tarballs".
1380 #
1381 t32_check() {
1382         local node=$(facet_active_host $SINGLEMDS)
1383         local r="do_node $node"
1384
1385         if [ "$CLIENTONLY" ]; then
1386                 skip "Client-only testing"
1387                 exit 0
1388         fi
1389
1390         if ! $r which $TUNEFS; then
1391                 skip_env "tunefs.lustre required on $node"
1392                 exit 0
1393         fi
1394
1395         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1396
1397         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 -name \'disk*-$IMGTYPE.tar.bz2\')
1398
1399         if [ -z "$tarballs" ]; then
1400                 skip "No applicable tarballs found"
1401                 exit 0
1402         fi
1403 }
1404
1405 t32_test_cleanup() {
1406         local tmp=$TMP/t32
1407         local fstype=$(facet_fstype $SINGLEMDS)
1408         local rc=$?
1409
1410         if $shall_cleanup_lustre; then
1411                 umount $tmp/mnt/lustre || rc=$?
1412         fi
1413         if $shall_cleanup_mdt; then
1414                 $r umount -d $tmp/mnt/mdt || rc=$?
1415         fi
1416         if $shall_cleanup_mdt1; then
1417                 $r umount -d $tmp/mnt/mdt1 || rc=$?
1418         fi
1419         if $shall_cleanup_ost; then
1420                 $r umount -d $tmp/mnt/ost || rc=$?
1421         fi
1422
1423         $r rm -rf $tmp
1424         rm -rf $tmp
1425         if [ $fstype == "zfs" ]; then
1426                 $r $ZPOOL destroy t32fs-mdt1 || rc=$?
1427                 $r $ZPOOL destroy t32fs-ost1 || rc=$?
1428         fi
1429         return $rc
1430 }
1431
1432 t32_bits_per_long() {
1433         #
1434         # Yes, this is not meant to be perfect.
1435         #
1436         case $1 in
1437                 ppc64|x86_64)
1438                         echo -n 64;;
1439                 i*86)
1440                         echo -n 32;;
1441         esac
1442 }
1443
1444 t32_reload_modules() {
1445         local node=$1
1446         local all_removed=false
1447         local i=0
1448
1449         while ((i < 20)); do
1450                 echo "Unloading modules on $node: Attempt $i"
1451                 do_rpc_nodes $node $LUSTRE_RMMOD $(facet_fstype $SINGLEMDS) &&
1452                         all_removed=true
1453                 do_rpc_nodes $node check_mem_leak || return 1
1454                 if $all_removed; then
1455                         do_rpc_nodes $node load_modules
1456                         return 0
1457                 fi
1458                 sleep 5
1459                 i=$((i + 1))
1460         done
1461         echo "Unloading modules on $node: Given up"
1462         return 1
1463 }
1464
1465 t32_wait_til_devices_gone() {
1466         local node=$1
1467         local devices
1468         local loops
1469         local i=0
1470
1471         echo wait for devices to go
1472         while ((i < 20)); do
1473                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1474                 loops=$(do_rpc_nodes $node losetup -a | grep -c t32)
1475                 ((devices == 0 && loops == 0)) && return 0
1476                 sleep 5
1477                 i=$((i + 1))
1478         done
1479         echo "waiting for dev on $node: dev $devices loop $loops given up"
1480         do_rpc_nodes $node "losetup -a"
1481         do_rpc_nodes $node "$LCTL devices_list"
1482         return 1
1483 }
1484
1485 t32_verify_quota() {
1486         local node=$1
1487         local fsname=$2
1488         local mnt=$3
1489         local fstype=$(facet_fstype $SINGLEMDS)
1490         local qval
1491         local cmd
1492
1493         $LFS quota -u $T32_QID -v $mnt
1494
1495         qval=$($LFS quota -v -u $T32_QID $mnt |
1496                 awk 'BEGIN { num='1' } { if ($1 == "'$mnt'") \
1497                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1498                 | tr -d "*")
1499         [ $qval -eq $img_bspace ] || {
1500                 echo "bspace, act:$qval, exp:$img_bspace"
1501                 return 1
1502         }
1503
1504         qval=$($LFS quota -v -u $T32_QID $mnt |
1505                 awk 'BEGIN { num='5' } { if ($1 == "'$mnt'") \
1506                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1507                 | tr -d "*")
1508         [ $qval -eq $img_ispace ] || {
1509                 echo "ispace, act:$qval, exp:$img_ispace"
1510                 return 1
1511         }
1512
1513         qval=$($LFS quota -v -u $T32_QID $mnt |
1514                 awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
1515                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1516                 | tr -d "*")
1517         [ $qval -eq $T32_BLIMIT ] || {
1518                 echo "blimit, act:$qval, exp:$T32_BLIMIT"
1519                 return 1
1520         }
1521
1522         qval=$($LFS quota -v -u $T32_QID $mnt |
1523                 awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
1524                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1525                 | tr -d "*")
1526         [ $qval -eq $T32_ILIMIT ] || {
1527                 echo "ilimit, act:$qval, exp:$T32_ILIMIT"
1528                 return 1
1529         }
1530
1531         do_node $node $LCTL conf_param $fsname.quota.mdt=ug
1532         cmd="$LCTL get_param -n osd-$fstype.$fsname-MDT0000"
1533         cmd=$cmd.quota_slave.enabled
1534         wait_update $node "$cmd" "ug" || {
1535                 echo "Enable mdt quota failed"
1536                 return 1
1537         }
1538
1539         do_node $node $LCTL conf_param $fsname.quota.ost=ug
1540         cmd="$LCTL get_param -n osd-$fstype.$fsname-OST0000"
1541         cmd=$cmd.quota_slave.enabled
1542         wait_update $node "$cmd" "ug" || {
1543                 echo "Enable ost quota failed"
1544                 return 1
1545         }
1546
1547         chmod 0777 $mnt
1548         runas -u $T32_QID -g $T32_QID dd if=/dev/zero of=$mnt/t32_qf_new \
1549                 bs=1M count=$(($T32_BLIMIT / 1024)) oflag=sync && {
1550                 echo "Write succeed, but expect -EDQUOT"
1551                 return 1
1552         }
1553         rm -f $mnt/t32_qf_new
1554
1555         runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
1556                 $T32_ILIMIT && {
1557                 echo "Create succeed, but expect -EDQUOT"
1558                 return 1
1559         }
1560         unlinkmany $mnt/t32_qf_ $T32_ILIMIT
1561
1562         return 0
1563 }
1564
1565 t32_test() {
1566         local tarball=$1
1567         local writeconf=$2
1568         local dne_upgrade=${dne_upgrade:-"no"}
1569         local ff_convert=${ff_convert:-"no"}
1570         local shall_cleanup_mdt=false
1571         local shall_cleanup_mdt1=false
1572         local shall_cleanup_ost=false
1573         local shall_cleanup_lustre=false
1574         local node=$(facet_active_host $SINGLEMDS)
1575         local r="do_node $node"
1576         local node2=$(facet_active_host mds2)
1577         local tmp=$TMP/t32
1578         local img_commit
1579         local img_kernel
1580         local img_arch
1581         local img_bspace
1582         local img_ispace
1583         local fsname=t32fs
1584         local nid=$($r $LCTL list_nids | head -1)
1585         local mopts
1586         local uuid
1587         local nrpcs_orig
1588         local nrpcs
1589         local list
1590         local fstype=$(facet_fstype $SINGLEMDS)
1591         local mdt_dev=$tmp/mdt
1592         local ost_dev=$tmp/ost
1593
1594         trap 'trap - RETURN; t32_test_cleanup' RETURN
1595
1596         mkdir -p $tmp/mnt/lustre
1597         $r mkdir -p $tmp/mnt/{mdt,ost}
1598         $r tar xjvf $tarball -S -C $tmp || {
1599                 error_noexit "Unpacking the disk image tarball"
1600                 return 1
1601         }
1602         img_commit=$($r cat $tmp/commit)
1603         img_kernel=$($r cat $tmp/kernel)
1604         img_arch=$($r cat $tmp/arch)
1605         img_bspace=$($r cat $tmp/bspace)
1606         img_ispace=$($r cat $tmp/ispace)
1607         echo "Upgrading from $(basename $tarball), created with:"
1608         echo "  Commit: $img_commit"
1609         echo "  Kernel: $img_kernel"
1610         echo "    Arch: $img_arch"
1611
1612         local version=$(version_code $img_commit)
1613         [[ $version -ge $(version_code 2.5.0) ]] && ff_convert="no"
1614
1615         if [ $fstype == "zfs" ]; then
1616                 # import pool first
1617                 $r $ZPOOL import -f -d $tmp t32fs-mdt1
1618                 $r $ZPOOL import -f -d $tmp t32fs-ost1
1619                 mdt_dev=t32fs-mdt1/mdt1
1620                 ost_dev=t32fs-ost1/ost1
1621                 wait_update_facet $SINGLEMDS "$ZPOOL list |
1622                         awk '/^t32fs-mdt1/ { print \\\$1 }'" "t32fs-mdt1" || {
1623                                 error_noexit "import zfs pool failed"
1624                                 return 1
1625                         }
1626         fi
1627
1628         $r $LCTL set_param debug="$PTLDEBUG"
1629
1630         $r $TUNEFS --dryrun $mdt_dev || {
1631                 $r losetup -a
1632                 error_noexit "tunefs.lustre before mounting the MDT"
1633                 return 1
1634         }
1635         if [ "$writeconf" ]; then
1636                 mopts=writeconf
1637                 if [ $fstype == "ldiskfs" ]; then
1638                         mopts="loop,$mopts"
1639                         $r $TUNEFS --quota $mdt_dev || {
1640                                 $r losetup -a
1641                                 error_noexit "Enable mdt quota feature"
1642                                 return 1
1643                         }
1644                 fi
1645         else
1646                 if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1647                         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
1648                         { skip "LU-2200: Cannot run over Inifiniband w/o lctl replace_nids "
1649                                 "(Need MGS version at least 2.3.59)"; return 0; }
1650
1651                         local osthost=$(facet_active_host ost1)
1652                         local ostnid=$(do_node $osthost $LCTL list_nids | head -1)
1653
1654                         mopts=nosvc
1655                         if [ $fstype == "ldiskfs" ]; then
1656                                 mopts="loop,$mopts"
1657                         fi
1658                         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt
1659                         $r lctl replace_nids $fsname-OST0000 $ostnid
1660                         $r lctl replace_nids $fsname-MDT0000 $nid
1661                         $r umount -d $tmp/mnt/mdt
1662                 fi
1663
1664                 mopts=exclude=$fsname-OST0000
1665                 if [ $fstype == "ldiskfs" ]; then
1666                         mopts="loop,$mopts"
1667                 fi
1668         fi
1669
1670         t32_wait_til_devices_gone $node
1671
1672         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
1673                 $r losetup -a
1674                 error_noexit "Mounting the MDT"
1675                 return 1
1676         }
1677         shall_cleanup_mdt=true
1678
1679         if [ "$dne_upgrade" != "no" ]; then
1680                 local fs2mdsdev=$(mdsdevname 1_2)
1681                 local fs2mdsvdev=$(mdsvdevname 1_2)
1682
1683                 echo "mkfs new MDT on ${fs2mdsdev}...."
1684                 if [ $(facet_fstype mds1) == ldiskfs ]; then
1685                         mkfsoptions="--mkfsoptions=\\\"-J size=8\\\""
1686                 fi
1687
1688                 add fs2mds $(mkfs_opts mds2 $fs2mdsdev $fsname) --reformat \
1689                            $mkfsoptions $fs2mdsdev $fs2mdsvdev > /dev/null || {
1690                         error_noexit "Mkfs new MDT failed"
1691                         return 1
1692                 }
1693
1694                 $r $TUNEFS --dryrun $fs2mdsdev || {
1695                         error_noexit "tunefs.lustre before mounting the MDT"
1696                         return 1
1697                 }
1698
1699                 echo "mount new MDT....$fs2mdsdev"
1700                 $r mkdir -p $tmp/mnt/mdt1
1701                 $r $MOUNT_CMD -o $mopts $fs2mdsdev $tmp/mnt/mdt1 || {
1702                         error_noexit "mount mdt1 failed"
1703                         return 1
1704                 }
1705
1706                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
1707                         error_noexit "enable remote dir create failed"
1708
1709                 shall_cleanup_mdt1=true
1710         fi
1711
1712         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1713                 error_noexit "Getting MDT UUID"
1714                 return 1
1715         }
1716         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1717                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1718                 return 1
1719         fi
1720
1721         $r $TUNEFS --dryrun $ost_dev || {
1722                 error_noexit "tunefs.lustre before mounting the OST"
1723                 return 1
1724         }
1725         if [ "$writeconf" ]; then
1726                 mopts=mgsnode=$nid,$writeconf
1727                 if [ $fstype == "ldiskfs" ]; then
1728                         mopts="loop,$mopts"
1729                         $r $TUNEFS --quota $ost_dev || {
1730                                 $r losetup -a
1731                                 error_noexit "Enable ost quota feature"
1732                                 return 1
1733                         }
1734                 fi
1735         else
1736                 mopts=mgsnode=$nid
1737                 if [ $fstype == "ldiskfs" ]; then
1738                         mopts="loop,$mopts"
1739                 fi
1740         fi
1741         $r $MOUNT_CMD -o $mopts $ost_dev $tmp/mnt/ost || {
1742                 error_noexit "Mounting the OST"
1743                 return 1
1744         }
1745         shall_cleanup_ost=true
1746
1747         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1748                 error_noexit "Getting OST UUID"
1749                 return 1
1750         }
1751         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1752                 error_noexit "Unexpected OST UUID: \"$uuid\""
1753                 return 1
1754         fi
1755
1756         $r $LCTL conf_param $fsname-OST0000.osc.max_dirty_mb=15 || {
1757                 error_noexit "Setting \"max_dirty_mb\""
1758                 return 1
1759         }
1760         $r $LCTL conf_param $fsname-OST0000.failover.node=$nid || {
1761                 error_noexit "Setting OST \"failover.node\""
1762                 return 1
1763         }
1764         $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1765                 error_noexit "Setting \"max_rpcs_in_flight\""
1766                 return 1
1767         }
1768         $r $LCTL conf_param $fsname-MDT0000.failover.node=$nid || {
1769                 error_noexit "Setting MDT \"failover.node\""
1770                 return 1
1771         }
1772         $r $LCTL pool_new $fsname.interop || {
1773                 error_noexit "Setting \"interop\""
1774                 return 1
1775         }
1776         $r $LCTL conf_param $fsname-MDT0000.lov.stripesize=4M || {
1777                 error_noexit "Setting \"lov.stripesize\""
1778                 return 1
1779         }
1780
1781         if [ "$ff_convert" != "no" -a $(facet_fstype ost1) == "ldiskfs" ]; then
1782                 $r $LCTL lfsck_start -M $fsname-OST0000 || {
1783                         error_noexit "Start OI scrub on OST0"
1784                         return 1
1785                 }
1786
1787                 # The oi_scrub should be on ost1, but for test_32(),
1788                 # all on the SINGLEMDS.
1789                 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1790                         osd-ldiskfs.$fsname-OST0000.oi_scrub |
1791                         awk '/^status/ { print \\\$2 }'" "completed" 30 || {
1792                         error_noexit "Failed to get the expected 'completed'"
1793                         return 1
1794                 }
1795
1796                 local UPDATED=$($r $LCTL get_param -n \
1797                                 osd-ldiskfs.$fsname-OST0000.oi_scrub |
1798                                 awk '/^updated/ { print $2 }')
1799                 [ $UPDATED -ge 1 ] || {
1800                         error_noexit "Only $UPDATED objects have been converted"
1801                         return 1
1802                 }
1803         fi
1804
1805         if [ "$dne_upgrade" != "no" ]; then
1806                 $r $LCTL conf_param \
1807                                 $fsname-MDT0001.mdc.max_rpcs_in_flight=9 || {
1808                         error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
1809                         return 1
1810                 }
1811                 $r $LCTL conf_param $fsname-MDT0001.failover.node=$nid || {
1812                         error_noexit "Setting MDT1 \"failover.node\""
1813                         return 1
1814                 }
1815                 $r $LCTL conf_param $fsname-MDT0001.lov.stripesize=4M || {
1816                         error_noexit "Setting MDT1 \"lov.stripesize\""
1817                         return 1
1818                 }
1819
1820         fi
1821
1822         if [ "$writeconf" ]; then
1823                 $MOUNT_CMD $nid:/$fsname $tmp/mnt/lustre || {
1824                         error_noexit "Mounting the client"
1825                         return 1
1826                 }
1827                 shall_cleanup_lustre=true
1828                 $LCTL set_param debug="$PTLDEBUG"
1829
1830                 t32_verify_quota $node $fsname $tmp/mnt/lustre || {
1831                         error_noexit "verify quota failed"
1832                         return 1
1833                 }
1834
1835                 if [ "$dne_upgrade" != "no" ]; then
1836                         $LFS mkdir -i 1 $tmp/mnt/lustre/remote_dir || {
1837                                 error_noexit "set remote dir failed"
1838                                 return 1
1839                         }
1840
1841                         pushd $tmp/mnt/lustre
1842                         tar -cf - . --exclude=./remote_dir |
1843                                 tar -xvf - -C remote_dir 1>/dev/null || {
1844                                 error_noexit "cp to remote dir failed"
1845                                 return 1
1846                         }
1847                         popd
1848                 fi
1849
1850                 dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
1851                         error_noexit "dd failed"
1852                         return 1
1853                 }
1854                 rm -rf $tmp/mnt/lustre/tmp_file || {
1855                         error_noexit "rm failed"
1856                         return 1
1857                 }
1858
1859                 if $r test -f $tmp/sha1sums; then
1860                         # LU-2393 - do both sorts on same node to ensure locale
1861                         # is identical
1862                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
1863                         if [ "$dne_upgrade" != "no" ]; then
1864                                 pushd $tmp/mnt/lustre/remote_dir
1865                         else
1866                                 pushd $tmp/mnt/lustre
1867                         fi
1868
1869                         find ! -name .lustre -type f -exec sha1sum {} \; |
1870                                 sort -k 2 >$tmp/sha1sums || {
1871                                 error_noexit "sha1sum"
1872                                 return 1
1873                         }
1874                         popd
1875                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
1876                                 error_noexit "sha1sum verification failed"
1877                                 return 1
1878                         fi
1879                 else
1880                         echo "sha1sum verification skipped"
1881                 fi
1882
1883                 if [ "$dne_upgrade" != "no" ]; then
1884                         rm -rf $tmp/mnt/lustre/remote_dir || {
1885                                 error_noexit "remove remote dir failed"
1886                                 return 1
1887                         }
1888                 fi
1889
1890                 if $r test -f $tmp/list; then
1891                         #
1892                         # There is not a Test Framework API to copy files to or
1893                         # from a remote node.
1894                         #
1895                         # LU-2393 - do both sorts on same node to ensure locale
1896                         # is identical
1897                         $r cat $tmp/list | sort -k 6 >$tmp/list.orig
1898                         pushd $tmp/mnt/lustre
1899                         ls -Rni --time-style=+%s | sort -k 6 >$tmp/list || {
1900                                 error_noexit "ls"
1901                                 return 1
1902                         }
1903                         popd
1904                         #
1905                         # 32-bit and 64-bit clients use different algorithms to
1906                         # convert FIDs into inode numbers.  Hence, remove the inode
1907                         # numbers from the lists, if the original list was created
1908                         # on an architecture with different number of bits per
1909                         # "long".
1910                         #
1911                         if [ $(t32_bits_per_long $(uname -m)) != \
1912                                 $(t32_bits_per_long $img_arch) ]; then
1913                                 echo "Different number of bits per \"long\" from the disk image"
1914                                 for list in list.orig list; do
1915                                         sed -i -e 's/^[0-9]\+[ \t]\+//' $tmp/$list
1916                                 done
1917                         fi
1918                         if ! diff -ub $tmp/list.orig $tmp/list; then
1919                                 error_noexit "list verification failed"
1920                                 return 1
1921                         fi
1922                 else
1923                         echo "list verification skipped"
1924                 fi
1925
1926                 #
1927                 # When adding new data verification tests, please check for
1928                 # the presence of the required reference files first, like
1929                 # the "sha1sums" and "list" tests above, to avoid the need to
1930                 # regenerate every image for each test addition.
1931                 #
1932
1933                 nrpcs_orig=$($LCTL get_param \
1934                                 -n mdc.*MDT0000*.max_rpcs_in_flight) || {
1935                         error_noexit "Getting \"max_rpcs_in_flight\""
1936                         return 1
1937                 }
1938                 nrpcs=$((nrpcs_orig + 5))
1939                 $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=$nrpcs || {
1940                         error_noexit "Changing \"max_rpcs_in_flight\""
1941                         return 1
1942                 }
1943                 wait_update $HOSTNAME "$LCTL get_param \
1944                         -n mdc.*MDT0000*.max_rpcs_in_flight" $nrpcs || {
1945                         error_noexit "Verifying \"max_rpcs_in_flight\""
1946                         return 1
1947                 }
1948
1949                 umount $tmp/mnt/lustre || {
1950                         error_noexit "Unmounting the client"
1951                         return 1
1952                 }
1953                 shall_cleanup_lustre=false
1954         else
1955                 if [ "$dne_upgrade" != "no" ]; then
1956                         $r umount -d $tmp/mnt/mdt1 || {
1957                                 error_noexit "Unmounting the MDT2"
1958                                 return 1
1959                         }
1960                         shall_cleanup_mdt1=false
1961                 fi
1962
1963                 $r umount -d $tmp/mnt/mdt || {
1964                         error_noexit "Unmounting the MDT"
1965                         return 1
1966                 }
1967                 shall_cleanup_mdt=false
1968
1969                 $r umount -d $tmp/mnt/ost || {
1970                         error_noexit "Unmounting the OST"
1971                         return 1
1972                 }
1973                 shall_cleanup_ost=false
1974
1975                 t32_reload_modules $node || {
1976                         error_noexit "Reloading modules"
1977                         return 1
1978                 }
1979
1980                 # mount a second time to make sure we didnt leave upgrade flag on
1981                 $r $TUNEFS --dryrun $mdt_dev || {
1982                         $r losetup -a
1983                         error_noexit "tunefs.lustre before remounting the MDT"
1984                         return 1
1985                 }
1986
1987                 mopts=exclude=$fsname-OST0000
1988                 if [ $fstype == "ldiskfs" ]; then
1989                         mopts="loop,$mopts"
1990                 fi
1991                 $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
1992                         error_noexit "Remounting the MDT"
1993                         return 1
1994                 }
1995                 shall_cleanup_mdt=true
1996         fi
1997 }
1998
1999 test_32a() {
2000         local tarballs
2001         local tarball
2002         local rc=0
2003
2004         t32_check
2005         for tarball in $tarballs; do
2006                 t32_test $tarball || let "rc += $?"
2007         done
2008         return $rc
2009 }
2010 run_test 32a "Upgrade (not live)"
2011
2012 test_32b() {
2013         local tarballs
2014         local tarball
2015         local rc=0
2016
2017         t32_check
2018         for tarball in $tarballs; do
2019                 t32_test $tarball writeconf || let "rc += $?"
2020         done
2021         return $rc
2022 }
2023 run_test 32b "Upgrade with writeconf"
2024
2025 test_32c() {
2026         local tarballs
2027         local tarball
2028         local rc=0
2029
2030         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2031         t32_check
2032         for tarball in $tarballs; do
2033                 dne_upgrade=yes t32_test $tarball writeconf || rc=$?
2034         done
2035         return $rc
2036 }
2037 run_test 32c "dne upgrade test"
2038
2039 test_32d() {
2040         local tarballs
2041         local tarball
2042         local rc=0
2043
2044         t32_check
2045         for tarball in $tarballs; do
2046                 ff_convert=yes t32_test $tarball || rc=$?
2047         done
2048         return $rc
2049 }
2050 run_test 32d "convert ff test"
2051
2052 test_33a() { # bug 12333, was test_33
2053         local rc=0
2054         local FSNAME2=test-123
2055         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2056         local mkfsoptions
2057
2058         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
2059
2060         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
2061                 local dev=${SINGLEMDS}_dev
2062                 local MDSDEV=${!dev}
2063                 is_blkdev $SINGLEMDS $MDSDEV && \
2064                 skip_env "mixed loopback and real device not working" && return
2065         fi
2066
2067         local fs2mdsdev=$(mdsdevname 1_2)
2068         local fs2ostdev=$(ostdevname 1_2)
2069         local fs2mdsvdev=$(mdsvdevname 1_2)
2070         local fs2ostvdev=$(ostvdevname 1_2)
2071
2072         if [ $(facet_fstype mds1) == ldiskfs ]; then
2073                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
2074         fi
2075
2076         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2077                 --reformat $mkfsoptions $fs2mdsdev $fs2mdsvdev || exit 10
2078         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2079                 --fsname=${FSNAME2} --index=8191 --reformat $fs2ostdev \
2080                 $fs2ostvdev || exit 10
2081
2082         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
2083         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2084         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
2085         mkdir -p $MOUNT2
2086         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
2087         echo "ok."
2088
2089         cp /etc/hosts $MOUNT2/ || rc=3
2090         $LFS getstripe $MOUNT2/hosts
2091
2092         umount -d $MOUNT2
2093         stop fs2ost -f
2094         stop fs2mds -f
2095         cleanup_nocli || rc=6
2096         return $rc
2097 }
2098 run_test 33a "Mount ost with a large index number"
2099
2100 test_33b() {    # was test_34
2101         setup
2102
2103         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
2104         # Drop lock cancelation reply during umount
2105         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
2106         do_facet client lctl set_param fail_loc=0x80000304
2107         #lctl set_param debug=-1
2108         umount_client $MOUNT
2109         cleanup
2110 }
2111 run_test 33b "Drop cancel during umount"
2112
2113 test_34a() {
2114         setup
2115         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
2116         manual_umount_client
2117         rc=$?
2118         do_facet client killall -USR1 multiop
2119         if [ $rc -eq 0 ]; then
2120                 error "umount not fail!"
2121         fi
2122         sleep 1
2123         cleanup
2124 }
2125 run_test 34a "umount with opened file should be fail"
2126
2127
2128 test_34b() {
2129         setup
2130         touch $DIR/$tfile || return 1
2131         stop_mds --force || return 2
2132
2133         manual_umount_client --force
2134         rc=$?
2135         if [ $rc -ne 0 ]; then
2136                 error "mtab after failed umount - rc $rc"
2137         fi
2138
2139         cleanup
2140         return 0
2141 }
2142 run_test 34b "force umount with failed mds should be normal"
2143
2144 test_34c() {
2145         setup
2146         touch $DIR/$tfile || return 1
2147         stop_ost --force || return 2
2148
2149         manual_umount_client --force
2150         rc=$?
2151         if [ $rc -ne 0 ]; then
2152                 error "mtab after failed umount - rc $rc"
2153         fi
2154
2155         cleanup
2156         return 0
2157 }
2158 run_test 34c "force umount with failed ost should be normal"
2159
2160 test_35a() { # bug 12459
2161         setup
2162
2163         DBG_SAVE="`lctl get_param -n debug`"
2164         lctl set_param debug="ha"
2165
2166         log "Set up a fake failnode for the MDS"
2167         FAKENID="127.0.0.2"
2168         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" |
2169                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2170         do_facet mgs "$LCTL conf_param \
2171                 ${device}.failover.node=$(h2$NETTYPE $FAKENID)" || return 4
2172
2173         log "Wait for RECONNECT_INTERVAL seconds (10s)"
2174         sleep 10
2175
2176         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
2177         $LCTL clear
2178         log "$MSG"
2179         log "Stopping the MDT: $device"
2180         stop_mdt 1 || return 5
2181
2182         df $MOUNT > /dev/null 2>&1 &
2183         DFPID=$!
2184         log "Restarting the MDT: $device"
2185         start_mdt 1 || return 6
2186         log "Wait for df ($DFPID) ... "
2187         wait $DFPID
2188         log "done"
2189         lctl set_param debug="$DBG_SAVE"
2190
2191         # retrieve from the log the first server that the client tried to
2192         # contact after the connection loss
2193         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2194         NEXTCONN=`awk "/${MSG}/ {start = 1;}
2195                        /import_select_connection.*$device-mdc.* using connection/ {
2196                                 if (start) {
2197                                         if (\\\$NF ~ /$FAKENID/)
2198                                                 print \\\$NF;
2199                                         else
2200                                                 print 0;
2201                                         exit;
2202                                 }
2203                        }" $TMP/lustre-log-$TESTNAME.log`
2204         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
2205         cleanup
2206         # remove nid settings
2207         writeconf_or_reformat
2208 }
2209 run_test 35a "Reconnect to the last active server first"
2210
2211 test_35b() { # bug 18674
2212         remote_mds || { skip "local MDS" && return 0; }
2213         setup
2214
2215         debugsave
2216         $LCTL set_param debug="ha"
2217         $LCTL clear
2218         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
2219         log "$MSG"
2220
2221         log "Set up a fake failnode for the MDS"
2222         FAKENID="127.0.0.2"
2223         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2224                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2225         do_facet mgs "$LCTL conf_param \
2226                 ${device}.failover.node=$(h2$NETTYPE $FAKENID)" || return 1
2227
2228         local at_max_saved=0
2229         # adaptive timeouts may prevent seeing the issue
2230         if at_is_enabled; then
2231                 at_max_saved=$(at_max_get mds)
2232                 at_max_set 0 mds client
2233         fi
2234
2235         mkdir -p $MOUNT/$tdir
2236
2237         log "Injecting EBUSY on MDS"
2238         # Setting OBD_FAIL_MDS_RESEND=0x136
2239         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" || return 2
2240
2241         $LCTL set_param mdc.${FSNAME}*.stats=clear
2242
2243         log "Creating a test file and stat it"
2244         touch $MOUNT/$tdir/$tfile
2245         stat $MOUNT/$tdir/$tfile
2246
2247         log "Stop injecting EBUSY on MDS"
2248         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" || return 3
2249         rm -f $MOUNT/$tdir/$tfile
2250
2251         log "done"
2252         # restore adaptive timeout
2253         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
2254
2255         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2256
2257         CONNCNT=`$LCTL get_param mdc.${FSNAME}*.stats | awk '/mds_connect/{print $2}'`
2258
2259         # retrieve from the log if the client has ever tried to
2260         # contact the fake server after the loss of connection
2261         FAILCONN=`awk "BEGIN {ret = 0;}
2262                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
2263                                 ret = 1;
2264                                 if (\\\$NF ~ /$FAKENID/) {
2265                                         ret = 2;
2266                                         exit;
2267                                 }
2268                        }
2269                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
2270
2271         [ "$FAILCONN" == "0" ] && \
2272                 log "ERROR: The client reconnection has not been triggered" && \
2273                 return 4
2274         [ "$FAILCONN" == "2" ] && \
2275                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
2276                 return 5
2277
2278         # LU-290
2279         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
2280         # Reconnects are supposed to be rate limited to one every 5s
2281         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] && \
2282                 log "ERROR: Too many reconnects $CONNCNT" && \
2283                 return 6
2284
2285         cleanup
2286         # remove nid settings
2287         writeconf_or_reformat
2288 }
2289 run_test 35b "Continue reconnection retries, if the active server is busy"
2290
2291 test_36() { # 12743
2292         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
2293
2294         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
2295                 { skip "remote OST" && return 0; }
2296
2297         local rc=0
2298         local FSNAME2=test1234
2299         local fs3ost_HOST=$ost_HOST
2300         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2301
2302         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
2303
2304         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
2305                 is_blkdev $SINGLEMDS $MDSDEV && \
2306                 skip_env "mixed loopback and real device not working" && return
2307         fi
2308
2309         local fs2mdsdev=$(mdsdevname 1_2)
2310         local fs2ostdev=$(ostdevname 1_2)
2311         local fs3ostdev=$(ostdevname 2_2)
2312         local fs2mdsvdev=$(mdsvdevname 1_2)
2313         local fs2ostvdev=$(ostvdevname 1_2)
2314         local fs3ostvdev=$(ostvdevname 2_2)
2315
2316         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2317                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
2318         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
2319         #     different one than the default value here.
2320         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2321                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
2322         add fs3ost $(mkfs_opts ost2 ${fs3ostdev}) --mgsnode=$MGSNID \
2323                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
2324
2325         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
2326         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2327         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
2328         mkdir -p $MOUNT2
2329         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || return 1
2330
2331         sleep 5 # until 11778 fixed
2332
2333         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
2334
2335         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
2336         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
2337         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
2338         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
2339         DFTOTAL=`echo $STRING | cut -d, -f1`
2340         DFUSED=`echo $STRING  | cut -d, -f2`
2341         DFAVAIL=`echo $STRING | cut -d, -f3`
2342         DFFREE=$(($DFTOTAL - $DFUSED))
2343
2344         ALLOWANCE=$((64 * $OSTCOUNT))
2345
2346         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
2347            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
2348                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
2349                 rc=1
2350         fi
2351         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
2352            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
2353                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
2354                 rc=2
2355         fi
2356         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
2357            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
2358                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
2359                 rc=3
2360        fi
2361
2362         umount -d $MOUNT2
2363         stop fs3ost -f || return 200
2364         stop fs2ost -f || return 201
2365         stop fs2mds -f || return 202
2366         unload_modules_conf || return 203
2367         return $rc
2368 }
2369 run_test 36 "df report consistency on OSTs with different block size"
2370
2371 test_37() {
2372         local mntpt=$(facet_mntpt $SINGLEMDS)
2373         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
2374         local mdsdev_sym="$TMP/sym_mdt.img"
2375         local opts=$MDS_MOUNT_OPTS
2376         local rc=0
2377
2378         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2379                 skip "Currently only applicable to ldiskfs-based MDTs"
2380                 return
2381         fi
2382
2383         echo "MDS :     $mdsdev"
2384         echo "SYMLINK : $mdsdev_sym"
2385         do_facet $SINGLEMDS rm -f $mdsdev_sym
2386
2387         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
2388
2389         echo "mount symlink device - $mdsdev_sym"
2390
2391         if ! do_facet $SINGLEMDS test -b $mdsdev; then
2392                 opts=$(csa_add "$opts" -o loop)
2393         fi
2394         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
2395                 $mdsdev_sym $mntpt 2>&1)
2396         rc=${PIPESTATUS[0]}
2397
2398         echo mount_op=$mount_op
2399
2400         do_facet $SINGLEMDS "umount -d $mntpt && rm -f $mdsdev_sym"
2401
2402         if $(echo $mount_op | grep -q "unable to set tunable"); then
2403                 error "set tunables failed for symlink device"
2404         fi
2405
2406         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
2407
2408         return 0
2409 }
2410 run_test 37 "verify set tunables works for symlink device"
2411
2412 test_38() { # bug 14222
2413         local fstype=$(facet_fstype $SINGLEMDS)
2414         local mntpt=$(facet_mntpt $SINGLEMDS)
2415
2416         setup
2417         # like runtests
2418         local COUNT=10
2419         local SRC="/etc /bin"
2420         local FILES=$(find $SRC -type f -mtime +1 | head -n $COUNT)
2421         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
2422         mkdir -p $DIR/$tdir
2423         tar cf - $FILES | tar xf - -C $DIR/$tdir ||
2424                 error "copying $SRC to $DIR/$tdir"
2425         sync
2426         umount_client $MOUNT
2427         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2428         stop_mds
2429         log "delete lov_objid file on MDS"
2430
2431         mount_fstype $SINGLEMDS || error "mount MDS failed (1)"
2432
2433         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid; rm $mntpt/lov_objid"
2434
2435         unmount_fstype $SINGLEMDS || error "umount failed (1)"
2436
2437         # check create in mds_lov_connect
2438         start_mds
2439         mount_client $MOUNT
2440         for f in $FILES; do
2441                 [ $V ] && log "verifying $DIR/$tdir/$f"
2442                 diff -q $f $DIR/$tdir/$f || ERROR=y
2443         done
2444         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2445         if [ "$ERROR" = "y" ]; then
2446                 # check it's updates in sync
2447                 umount_client $MOUNT
2448                 stop_mds
2449                 mount_fstype $SIGNLEMDS
2450                 do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2451                 unmount_fstype $SINGLEMDS
2452                 error "old and new files are different after connect" || true
2453         fi
2454         touch $DIR/$tdir/f2 || error "f2 file create failed"
2455
2456         # check it's updates in sync
2457         umount_client $MOUNT
2458         stop_mds
2459
2460         mount_fstype $SINGLEMDS || error "mount MDS failed (3)"
2461
2462         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2463         do_facet $SINGLEMDS dd if=/dev/zero of=$mntpt/lov_objid.clear count=8
2464
2465         unmount_fstype $SINGLEMDS || error "umount failed (3)"
2466
2467         start_mds
2468         mount_client $MOUNT
2469         for f in $FILES; do
2470                 [ $V ] && log "verifying $DIR/$tdir/$f"
2471                 diff -q $f $DIR/$tdir/$f || ERROR=y
2472         done
2473         touch $DIR/$tdir/f3 || error "f3 file create failed"
2474         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2475         umount_client $MOUNT
2476         stop_mds
2477         mount_fstype $SINGLEMDS || error "mount MDS failed (4)"
2478         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2479         unmount_fstype $SINGLEMDS || error "umount failed (4)"
2480
2481         [ "$ERROR" = "y" ] &&
2482                 error "old and new files are different after sync" || true
2483
2484         log "files compared the same"
2485         cleanup
2486 }
2487 run_test 38 "MDS recreates missing lov_objid file from OST data"
2488
2489 test_39() {
2490         PTLDEBUG=+malloc
2491         setup
2492         cleanup
2493         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2494                 error "memory leak detected" || true
2495 }
2496 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2497
2498 test_40() { # bug 15759
2499         start_ost
2500         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2501         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2502         start_mds
2503         cleanup
2504 }
2505 run_test 40 "race during service thread startup"
2506
2507 test_41a() { #bug 14134
2508         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2509            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2510                 skip "Loop devices does not work with nosvc option"
2511                 return
2512         fi
2513
2514         local rc
2515         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2516
2517         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2518         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
2519         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2520         mkdir -p $MOUNT
2521         mount_client $MOUNT || return 1
2522         sleep 5
2523
2524         echo "blah blah" > $MOUNT/$tfile
2525         cat $MOUNT/$tfile
2526
2527         umount_client $MOUNT
2528         stop ost1 -f || return 201
2529         stop_mds -f || return 202
2530         stop_mds -f || return 203
2531         unload_modules_conf || return 204
2532         return $rc
2533 }
2534 run_test 41a "mount mds with --nosvc and --nomgs"
2535
2536 test_41b() {
2537         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2538            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2539                 skip "Loop devices does not work with nosvc option"
2540                 return
2541         fi
2542
2543         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2544
2545         stopall
2546         reformat
2547         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2548
2549         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2550         start_ost
2551         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2552         mkdir -p $MOUNT
2553         mount_client $MOUNT || return 1
2554         sleep 5
2555
2556         echo "blah blah" > $MOUNT/$tfile
2557         cat $MOUNT/$tfile || return 200
2558
2559         umount_client $MOUNT
2560         stop_ost || return 201
2561         stop_mds -f || return 202
2562         stop_mds -f || return 203
2563
2564 }
2565 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2566
2567 test_42() { #bug 14693
2568         setup
2569         check_mount || error "client was not mounted"
2570
2571         do_facet mgs $LCTL conf_param $FSNAME.llite.some_wrong_param=10
2572         umount_client $MOUNT ||
2573                 error "unmounting client failed with invalid llite param"
2574         mount_client $MOUNT ||
2575                 error "mounting client failed with invalid llite param"
2576
2577         do_facet mgs $LCTL conf_param $FSNAME.sys.some_wrong_param=20
2578         cleanup || error "stopping $FSNAME failed with invalid sys param"
2579         load_modules
2580         setup
2581         check_mount || "client was not mounted with invalid sys param"
2582         cleanup || error "stopping $FSNAME failed with invalid sys param"
2583         return 0
2584 }
2585 run_test 42 "allow client/server mount/unmount with invalid config param"
2586
2587 test_43() {
2588         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.58) ]] ||
2589                 { skip "Need MDS version at least 2.5.58" && return 0; }
2590         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
2591
2592         ID1=${ID1:-501}
2593         USER1=$(cat /etc/passwd | grep :$ID1:$ID1: | cut -d: -f1)
2594         [ -z "$USER1" ] && skip_env "missing user with uid=$ID1 gid=$ID1" &&
2595                 return
2596
2597         setup
2598         chmod ugo+x $DIR || error "chmod 0 failed"
2599         set_conf_param_and_check mds                                    \
2600                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2601                 "$FSNAME.mdt.root_squash"                               \
2602                 "0:0"
2603         wait_update $HOSTNAME                                           \
2604                 "lctl get_param -n llite.${FSNAME}*.root_squash"        \
2605                 "0:0" ||
2606                 error "check llite root_squash failed!"
2607         set_conf_param_and_check mds                                    \
2608                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2609                 "$FSNAME.mdt.nosquash_nids"                             \
2610                 "NONE"
2611         wait_update $HOSTNAME                                           \
2612                 "lctl get_param -n llite.${FSNAME}*.nosquash_nids"      \
2613                 "NONE" ||
2614                 error "check llite nosquash_nids failed!"
2615
2616     #
2617     # create set of test files
2618     #
2619     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
2620     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
2621     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
2622
2623     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
2624     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
2625
2626     mkdir $DIR/$tdir-rootdir -p       || error "mkdir failed"
2627     chmod go-rwx $DIR/$tdir-rootdir   || error "chmod 3 failed"
2628     touch $DIR/$tdir-rootdir/tfile-1  || error "touch failed"
2629
2630         echo "777" > $DIR/$tfile-user1file || error "write 7 failed"
2631         chmod go-rw $DIR/$tfile-user1file  || error "chmod 7 failed"
2632         chown $ID1.$ID1 $DIR/$tfile-user1file || error "chown failed"
2633
2634         #
2635         # check root_squash:
2636         #   set root squash UID:GID to RUNAS_ID
2637         #   root should be able to access only files owned by RUNAS_ID
2638         #
2639         set_conf_param_and_check mds                                    \
2640                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2641                 "$FSNAME.mdt.root_squash"                               \
2642                 "$RUNAS_ID:$RUNAS_ID"
2643         wait_update $HOSTNAME                                           \
2644                 "lctl get_param -n llite.${FSNAME}*.root_squash"        \
2645                 "$RUNAS_ID:$RUNAS_ID" ||
2646                 error "check llite root_squash failed!"
2647
2648     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
2649     dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2650         error "$ST: root read permission is denied"
2651     echo "$ST: root read permission is granted - ok"
2652
2653     echo "444" | \
2654     dd conv=notrunc of=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2655         error "$ST: root write permission is denied"
2656     echo "$ST: root write permission is granted - ok"
2657
2658     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2659     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2660         error "$ST: root read permission is granted"
2661     echo "$ST: root read permission is denied - ok"
2662
2663     echo "555" | \
2664     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2665         error "$ST: root write permission is granted"
2666     echo "$ST: root write permission is denied - ok"
2667
2668     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2669     rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null && \
2670         error "$ST: root unlink permission is granted"
2671     echo "$ST: root unlink permission is denied - ok"
2672
2673     touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null && \
2674         error "$ST: root create permission is granted"
2675     echo "$ST: root create permission is denied - ok"
2676
2677
2678         # LU-1778
2679         # check root_squash is enforced independently
2680         # of client cache content
2681         #
2682         # access file by USER1, keep access open
2683         # root should be denied access to user file
2684
2685         runas -u $ID1 tail -f $DIR/$tfile-user1file 1>/dev/null 2>&1 &
2686         pid=$!
2687         sleep 1
2688
2689         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-user1file)
2690         dd if=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
2691             { kill $pid; error "$ST: root read permission is granted"; }
2692         echo "$ST: root read permission is denied - ok"
2693
2694         echo "777" | \
2695         dd conv=notrunc of=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
2696             { kill $pid; error "$ST: root write permission is granted"; }
2697         echo "$ST: root write permission is denied - ok"
2698
2699         kill $pid
2700         wait $pid
2701
2702         #
2703         # check nosquash_nids:
2704         #   put client's NID into nosquash_nids list,
2705         #   root should be able to access root file after that
2706         #
2707         local NIDLIST=$(lctl list_nids all | tr '\n' ' ')
2708         NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
2709         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
2710         set_conf_param_and_check mds                                    \
2711                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2712                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
2713                 "$NIDLIST"
2714         wait_update $HOSTNAME                                           \
2715                 "lctl get_param -n llite.${FSNAME}*.nosquash_nids"      \
2716                 "$NIDLIST" ||
2717                 error "check llite nosquash_nids failed!"
2718
2719     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2720     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2721         error "$ST: root read permission is denied"
2722     echo "$ST: root read permission is granted - ok"
2723
2724     echo "666" | \
2725     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2726         error "$ST: root write permission is denied"
2727     echo "$ST: root write permission is granted - ok"
2728
2729     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2730     rm $DIR/$tdir-rootdir/tfile-1 || \
2731         error "$ST: root unlink permission is denied"
2732     echo "$ST: root unlink permission is granted - ok"
2733     touch $DIR/$tdir-rootdir/tfile-2 || \
2734         error "$ST: root create permission is denied"
2735     echo "$ST: root create permission is granted - ok"
2736
2737     return 0
2738 }
2739 run_test 43 "check root_squash and nosquash_nids"
2740
2741 umount_client $MOUNT
2742 cleanup_nocli
2743
2744 test_44() { # 16317
2745         setup
2746         check_mount || return 2
2747         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
2748         STATS_FOUND=no
2749         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
2750         for VAL in $UUIDS; do
2751                 NID=$(echo $VAL | cut -d= -f1)
2752                 CLUUID=$(echo $VAL | cut -d= -f2)
2753                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
2754         done
2755         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
2756         cleanup
2757         return 0
2758 }
2759 run_test 44 "mounted client proc entry exists"
2760
2761 test_45() { #17310
2762         setup
2763         check_mount || return 2
2764         stop_mds
2765         df -h $MOUNT &
2766         log "sleep 60 sec"
2767         sleep 60
2768 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
2769         do_facet client "lctl set_param fail_loc=0x50f"
2770         log "sleep 10 sec"
2771         sleep 10
2772         manual_umount_client --force || return 3
2773         do_facet client "lctl set_param fail_loc=0x0"
2774         start_mds
2775         mount_client $MOUNT || return 4
2776         cleanup
2777         return 0
2778 }
2779 run_test 45 "long unlink handling in ptlrpcd"
2780
2781 cleanup_46a() {
2782         trap 0
2783         local rc=0
2784         local count=$1
2785
2786         umount_client $MOUNT2 || rc=$?
2787         umount_client $MOUNT || rc=$?
2788         while [ $count -gt 0 ]; do
2789                 stop ost${count} -f || rc=$?
2790                 let count=count-1
2791         done    
2792         stop_mds || rc=$?
2793         cleanup_nocli || rc=$?
2794         #writeconf to remove all ost2 traces for subsequent tests
2795         writeconf_or_reformat
2796         return $rc
2797 }
2798
2799 test_46a() {
2800         echo "Testing with $OSTCOUNT OSTs"
2801         reformat_and_config
2802         start_mds || return 1
2803         #first client should see only one ost
2804         start_ost || return 2
2805         wait_osc_import_state mds ost FULL
2806         #start_client
2807         mount_client $MOUNT || return 3
2808         trap "cleanup_46a $OSTCOUNT" EXIT ERR
2809
2810         local i
2811         for (( i=2; i<=$OSTCOUNT; i++ )); do
2812             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
2813         done
2814
2815         # wait until osts in sync
2816         for (( i=2; i<=$OSTCOUNT; i++ )); do
2817             wait_osc_import_state mds ost$i FULL
2818             wait_osc_import_state client ost$i FULL
2819         done
2820
2821         #second client see all ost's
2822
2823         mount_client $MOUNT2 || return 8
2824         $LFS setstripe -c -1 $MOUNT2 || return 9
2825         $LFS getstripe $MOUNT2 || return 10
2826
2827         echo "ok" > $MOUNT2/widestripe
2828         $LFS getstripe $MOUNT2/widestripe || return 11
2829         # fill acl buffer for avoid expand lsm to them
2830         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
2831             setfacl -m $acl $MOUNT2/widestripe
2832         done
2833
2834         # will be deadlock
2835         stat $MOUNT/widestripe || return 12
2836
2837         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
2838         return 0
2839 }
2840 run_test 46a "handle ost additional - wide striped file"
2841
2842 test_47() { #17674
2843         reformat
2844         setup_noconfig
2845         check_mount || return 2
2846         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
2847
2848         local lru_size=[]
2849         local count=0
2850         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2851             if echo $ns | grep "MDT[[:digit:]]*"; then
2852                 continue
2853             fi
2854             lrs=$(echo $ns | sed 's/.*lru_size=//')
2855             lru_size[count]=$lrs
2856             let count=count+1
2857         done
2858
2859         facet_failover ost1
2860         facet_failover $SINGLEMDS
2861         client_up || return 3
2862
2863         count=0
2864         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2865             if echo $ns | grep "MDT[[:digit:]]*"; then
2866                 continue
2867             fi
2868             lrs=$(echo $ns | sed 's/.*lru_size=//')
2869             if ! test "$lrs" -eq "${lru_size[count]}"; then
2870                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
2871                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
2872             fi
2873             let count=count+1
2874         done
2875
2876         cleanup
2877         return 0
2878 }
2879 run_test 47 "server restart does not make client loss lru_resize settings"
2880
2881 cleanup_48() {
2882         trap 0
2883
2884         # reformat after this test is needed - if test will failed
2885         # we will have unkillable file at FS
2886         reformat_and_config
2887 }
2888
2889 test_48() { # bug 17636
2890         reformat
2891         setup_noconfig
2892         check_mount || return 2
2893
2894         $LFS setstripe -c -1 $MOUNT || return 9
2895         $LFS getstripe $MOUNT || return 10
2896
2897         echo "ok" > $MOUNT/widestripe
2898         $LFS getstripe $MOUNT/widestripe || return 11
2899
2900         trap cleanup_48 EXIT ERR
2901
2902         # fill acl buffer for avoid expand lsm to them
2903         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
2904             setfacl -m $acl $MOUNT/widestripe
2905         done
2906
2907         stat $MOUNT/widestripe || return 12
2908
2909         cleanup_48
2910         return 0
2911 }
2912 run_test 48 "too many acls on file"
2913
2914 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
2915 test_49a() { # bug 17710
2916         local timeout_orig=$TIMEOUT
2917         local ldlm_timeout_orig=$LDLM_TIMEOUT
2918         local LOCAL_TIMEOUT=20
2919
2920         LDLM_TIMEOUT=$LOCAL_TIMEOUT
2921         TIMEOUT=$LOCAL_TIMEOUT
2922
2923         reformat
2924         setup_noconfig
2925         check_mount || error "client mount failed"
2926
2927         echo "check ldlm_timout..."
2928         local LDLM_MDS="$(do_facet $SINGLEMDS lctl get_param -n ldlm_timeout)"
2929         local LDLM_OST1="$(do_facet ost1 lctl get_param -n ldlm_timeout)"
2930         local LDLM_CLIENT="$(do_facet client lctl get_param -n ldlm_timeout)"
2931
2932         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
2933                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2934         fi
2935
2936         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
2937                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT / 3))"
2938         fi
2939
2940         umount_client $MOUNT
2941         stop_ost || error "problem stopping OSS"
2942         stop_mds || error "problem stopping MDS"
2943
2944         LDLM_TIMEOUT=$ldlm_timeout_orig
2945         TIMEOUT=$timeout_orig
2946 }
2947 run_test 49a "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
2948
2949 test_49b() { # bug 17710
2950         local timeout_orig=$TIMEOUT
2951         local ldlm_timeout_orig=$LDLM_TIMEOUT
2952         local LOCAL_TIMEOUT=20
2953
2954         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
2955         TIMEOUT=$LOCAL_TIMEOUT
2956
2957         reformat
2958         setup_noconfig
2959         check_mount || error "client mount failed"
2960
2961         local LDLM_MDS="$(do_facet $SINGLEMDS lctl get_param -n ldlm_timeout)"
2962         local LDLM_OST1="$(do_facet ost1 lctl get_param -n ldlm_timeout)"
2963         local LDLM_CLIENT="$(do_facet client lctl get_param -n ldlm_timeout)"
2964
2965         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
2966                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2967         fi
2968
2969         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
2970                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT - 1))"
2971         fi
2972
2973         cleanup || error "cleanup failed"
2974
2975         LDLM_TIMEOUT=$ldlm_timeout_orig
2976         TIMEOUT=$timeout_orig
2977 }
2978 run_test 49b "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
2979
2980 lazystatfs() {
2981         # Test both statfs and lfs df and fail if either one fails
2982         multiop_bg_pause $1 f_
2983         RC1=$?
2984         PID=$!
2985         killall -USR1 multiop
2986         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
2987         wait $PID || { RC1=$?; log "multiop return error "; }
2988
2989         $LFS df &
2990         PID=$!
2991         sleep 5
2992         kill -s 0 $PID
2993         RC2=$?
2994         if [ $RC2 -eq 0 ]; then
2995             kill -s 9 $PID
2996             log "lazystatfs df failed"
2997         fi
2998
2999         RC=0
3000         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
3001         return $RC
3002 }
3003
3004 test_50a() {
3005         setup
3006         lctl set_param llite.$FSNAME-*.lazystatfs=1
3007         touch $DIR/$tfile
3008
3009         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
3010
3011         cleanup || return $?
3012 }
3013 run_test 50a "lazystatfs all servers available =========================="
3014
3015 test_50b() {
3016         setup
3017         lctl set_param llite.$FSNAME-*.lazystatfs=1
3018         touch $DIR/$tfile
3019
3020         # Wait for client to detect down OST
3021         stop_ost || error "Unable to stop OST1"
3022         wait_osc_import_state mds ost DISCONN
3023
3024         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
3025
3026         umount_client $MOUNT || error "Unable to unmount client"
3027         stop_mds || error "Unable to stop MDS"
3028 }
3029 run_test 50b "lazystatfs all servers down =========================="
3030
3031 test_50c() {
3032         start_mds || error "Unable to start MDS"
3033         start_ost || error "Unable to start OST1"
3034         start_ost2 || error "Unable to start OST2"
3035         mount_client $MOUNT || error "Unable to mount client"
3036         lctl set_param llite.$FSNAME-*.lazystatfs=1
3037         touch $DIR/$tfile
3038
3039         # Wait for client to detect down OST
3040         stop_ost || error "Unable to stop OST1"
3041         wait_osc_import_state mds ost DISCONN
3042         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3043
3044         umount_client $MOUNT || error "Unable to unmount client"
3045         stop_ost2 || error "Unable to stop OST2"
3046         stop_mds || error "Unable to stop MDS"
3047         #writeconf to remove all ost2 traces for subsequent tests
3048         writeconf_or_reformat
3049 }
3050 run_test 50c "lazystatfs one server down =========================="
3051
3052 test_50d() {
3053         start_mds || error "Unable to start MDS"
3054         start_ost || error "Unable to start OST1"
3055         start_ost2 || error "Unable to start OST2"
3056         mount_client $MOUNT || error "Unable to mount client"
3057         lctl set_param llite.$FSNAME-*.lazystatfs=1
3058         touch $DIR/$tfile
3059
3060         # Issue the statfs during the window where the client still
3061         # belives the OST to be available but it is in fact down.
3062         # No failure just a statfs which hangs for a timeout interval.
3063         stop_ost || error "Unable to stop OST1"
3064         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3065
3066         umount_client $MOUNT || error "Unable to unmount client"
3067         stop_ost2 || error "Unable to stop OST2"
3068         stop_mds || error "Unable to stop MDS"
3069         #writeconf to remove all ost2 traces for subsequent tests
3070         writeconf_or_reformat
3071 }
3072 run_test 50d "lazystatfs client/server conn race =========================="
3073
3074 test_50e() {
3075         local RC1
3076         local pid
3077
3078         reformat_and_config
3079         start_mds || return 1
3080         #first client should see only one ost
3081         start_ost || return 2
3082         wait_osc_import_state mds ost FULL
3083
3084         # Wait for client to detect down OST
3085         stop_ost || error "Unable to stop OST1"
3086         wait_osc_import_state mds ost DISCONN
3087
3088         mount_client $MOUNT || error "Unable to mount client"
3089         lctl set_param llite.$FSNAME-*.lazystatfs=0
3090
3091         multiop_bg_pause $MOUNT _f
3092         RC1=$?
3093         pid=$!
3094
3095         if [ $RC1 -ne 0 ]; then
3096                 log "multiop failed $RC1"
3097         else
3098             kill -USR1 $pid
3099             sleep $(( $TIMEOUT+1 ))
3100             kill -0 $pid
3101             [ $? -ne 0 ] && error "process isn't sleep"
3102             start_ost || error "Unable to start OST1"
3103             wait $pid || error "statfs failed"
3104         fi
3105
3106         umount_client $MOUNT || error "Unable to unmount client"
3107         stop_ost || error "Unable to stop OST1"
3108         stop_mds || error "Unable to stop MDS"
3109 }
3110 run_test 50e "normal statfs all servers down =========================="
3111
3112 test_50f() {
3113         local RC1
3114         local pid
3115         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
3116
3117         start_mds || error "Unable to start mds"
3118         #first client should see only one ost
3119         start_ost || error "Unable to start OST1"
3120         wait_osc_import_state mds ost FULL
3121
3122         start_ost2 || error "Unable to start OST2"
3123         wait_osc_import_state mds ost2 FULL
3124
3125         # Wait for client to detect down OST
3126         stop_ost2 || error "Unable to stop OST2"
3127
3128         wait_osc_import_state mds ost2 DISCONN
3129         mount_client $MOUNT || error "Unable to mount client"
3130         lctl set_param llite.$FSNAME-*.lazystatfs=0
3131
3132         multiop_bg_pause $MOUNT _f
3133         RC1=$?
3134         pid=$!
3135
3136         if [ $RC1 -ne 0 ]; then
3137                 log "lazystatfs multiop failed $RC1"
3138         else
3139             kill -USR1 $pid
3140             sleep $(( $TIMEOUT+1 ))
3141             kill -0 $pid
3142             [ $? -ne 0 ] && error "process isn't sleep"
3143             start_ost2 || error "Unable to start OST2"
3144             wait $pid || error "statfs failed"
3145             stop_ost2 || error "Unable to stop OST2"
3146         fi
3147
3148         umount_client $MOUNT || error "Unable to unmount client"
3149         stop_ost || error "Unable to stop OST1"
3150         stop_mds || error "Unable to stop MDS"
3151         #writeconf to remove all ost2 traces for subsequent tests
3152         writeconf_or_reformat
3153 }
3154 run_test 50f "normal statfs one server in down =========================="
3155
3156 test_50g() {
3157         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
3158         setup
3159         start_ost2 || error "Unable to start OST2"
3160         wait_osc_import_state mds ost2 FULL
3161         wait_osc_import_state client ost2 FULL
3162
3163         local PARAM="${FSNAME}-OST0001.osc.active"
3164
3165         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
3166         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
3167
3168         umount_client $MOUNT || error "Unable to unmount client"
3169         mount_client $MOUNT || error "Unable to mount client"
3170         # This df should not cause a panic
3171         df -k $MOUNT
3172
3173         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
3174         rm -f $DIR/$tfile
3175         umount_client $MOUNT || error "Unable to unmount client"
3176         stop_ost2 || error "Unable to stop OST2"
3177         stop_ost || error "Unable to stop OST1"
3178         stop_mds || error "Unable to stop MDS"
3179         #writeconf to remove all ost2 traces for subsequent tests
3180         writeconf_or_reformat
3181 }
3182 run_test 50g "deactivated OST should not cause panic====================="
3183
3184 # LU-642
3185 test_50h() {
3186         # prepare MDT/OST, make OSC inactive for OST1
3187         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
3188
3189         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3190         do_facet ost1 "$TUNEFS --param osc.active=0 `ostdevname 1`" ||
3191                 error "tunefs OST1 failed"
3192         start_mds  || error "Unable to start MDT"
3193         start_ost  || error "Unable to start OST1"
3194         start_ost2 || error "Unable to start OST2"
3195         mount_client $MOUNT || error "client start failed"
3196
3197         mkdir -p $DIR/$tdir
3198
3199         # activatate OSC for OST1
3200         local TEST="$LCTL get_param -n osc.${FSNAME}-OST0000-osc-[!M]*.active"
3201         set_conf_param_and_check client                                 \
3202                 "$TEST" "${FSNAME}-OST0000.osc.active" 1 ||
3203                 error "Unable to activate OST1"
3204
3205         mkdir -p $DIR/$tdir/2
3206         $LFS setstripe -c -1 -i 0 $DIR/$tdir/2
3207         sleep 1 && echo "create a file after OST1 is activated"
3208         # create some file
3209         createmany -o $DIR/$tdir/2/$tfile-%d 1
3210
3211         # check OSC import is working
3212         stat $DIR/$tdir/2/* >/dev/null 2>&1 ||
3213                 error "some OSC imports are still not connected"
3214
3215         # cleanup
3216         umount_client $MOUNT || error "Unable to umount client"
3217         stop_ost2 || error "Unable to stop OST2"
3218         cleanup_nocli
3219 }
3220 run_test 50h "LU-642: activate deactivated OST  ==="
3221
3222 test_51() {
3223         local LOCAL_TIMEOUT=20
3224
3225         reformat
3226         setup_noconfig
3227         check_mount || return 1
3228
3229         mkdir $MOUNT/d1
3230         $LFS setstripe -c -1 $MOUNT/d1
3231         #define OBD_FAIL_MDS_REINT_DELAY         0x142
3232         do_facet $SINGLEMDS "lctl set_param fail_loc=0x142"
3233         touch $MOUNT/d1/f1 &
3234         local pid=$!
3235         sleep 2
3236         start_ost2 || return 2
3237         wait $pid
3238         stop_ost2 || return 3
3239         cleanup
3240         #writeconf to remove all ost2 traces for subsequent tests
3241         writeconf_or_reformat
3242 }
3243 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
3244
3245 copy_files_xattrs()
3246 {
3247         local node=$1
3248         local dest=$2
3249         local xattrs=$3
3250         shift 3
3251
3252         do_node $node mkdir -p $dest
3253         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3254
3255         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
3256                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3257         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
3258
3259         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
3260         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
3261 }
3262
3263 diff_files_xattrs()
3264 {
3265         local node=$1
3266         local backup=$2
3267         local xattrs=$3
3268         shift 3
3269
3270         local backup2=${TMP}/backup2
3271
3272         do_node $node mkdir -p $backup2
3273         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3274
3275         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
3276                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3277         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
3278
3279         do_node $node "diff -rq $backup $backup2"
3280         [ $? -eq 0 ] || { error "contents differ"; return 3; }
3281
3282         local xattrs2=${TMP}/xattrs2
3283         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
3284         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
3285
3286         do_node $node "diff $xattrs $xattrs2"
3287         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
3288
3289         do_node $node "rm -rf $backup2 $xattrs2"
3290         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
3291 }
3292
3293 test_52() {
3294         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3295                 skip "Only applicable to ldiskfs-based MDTs"
3296                 return
3297         fi
3298
3299         start_mds
3300         [ $? -eq 0 ] || { error "Unable to start MDS"; return 1; }
3301         start_ost
3302         [ $? -eq 0 ] || { error "Unable to start OST1"; return 2; }
3303         mount_client $MOUNT
3304         [ $? -eq 0 ] || { error "Unable to mount client"; return 3; }
3305
3306         local nrfiles=8
3307         local ost1mnt=$(facet_mntpt ost1)
3308         local ost1node=$(facet_active_host ost1)
3309         local ost1tmp=$TMP/conf52
3310         local loop
3311
3312         mkdir -p $DIR/$tdir
3313         [ $? -eq 0 ] || { error "Unable to create tdir"; return 4; }
3314         touch $TMP/modified_first
3315         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 5; }
3316         local mtime=$(stat -c %Y $TMP/modified_first)
3317         do_node $ost1node "mkdir -p $ost1tmp && touch -m -d @$mtime $ost1tmp/modified_first"
3318
3319         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 6; }
3320         sleep 1
3321
3322         $LFS setstripe -c -1 -S 1M $DIR/$tdir
3323         [ $? -eq 0 ] || { error "lfs setstripe failed"; return 7; }
3324
3325         for (( i=0; i < nrfiles; i++ )); do
3326                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c
3327                 [ $? -eq 0 ] || { error "multiop failed"; return 8; }
3328                 echo -n .
3329         done
3330         echo
3331
3332         # backup files
3333         echo backup files to $TMP/files
3334         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
3335         copy_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
3336         [ $? -eq 0 ] || { error "Unable to copy files"; return 9; }
3337
3338         umount_client $MOUNT
3339         [ $? -eq 0 ] || { error "Unable to umount client"; return 10; }
3340         stop_ost
3341         [ $? -eq 0 ] || { error "Unable to stop ost1"; return 11; }
3342
3343         echo mount ost1 as ldiskfs
3344         do_node $ost1node mkdir -p $ost1mnt
3345         [ $? -eq 0 ] || { error "Unable to create $ost1mnt"; return 23; }
3346         if ! do_node $ost1node test -b $ost1_dev; then
3347                 loop="-o loop"
3348         fi
3349         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
3350                 $ost1mnt
3351         [ $? -eq 0 ] || { error "Unable to mount ost1 as ldiskfs"; return 12; }
3352
3353         # backup objects
3354         echo backup objects to $ost1tmp/objects
3355         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/[0-9]* -type f'\
3356                 '-size +0 -newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
3357         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs \
3358                         $objects
3359         [ $? -eq 0 ] || { error "Unable to copy objects"; return 13; }
3360
3361         # move objects to lost+found
3362         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
3363         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
3364
3365         # recover objects dry-run
3366         echo "ll_recover_lost_found_objs dry_run"
3367         do_node $ost1node "ll_recover_lost_found_objs -n -d $ost1mnt/O"
3368         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
3369
3370         # recover objects
3371         echo "ll_recover_lost_found_objs fix run"
3372         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found"
3373         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
3374
3375         # compare restored objects against saved ones
3376         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
3377         [ $? -eq 0 ] || { error "Unable to diff objects"; return 16; }
3378
3379         do_node $ost1node "umount $ost1mnt"
3380         [ $? -eq 0 ] || { error "Unable to umount ost1 as ldiskfs"; return 17; }
3381
3382         start_ost
3383         [ $? -eq 0 ] || { error "Unable to start ost1"; return 18; }
3384         mount_client $MOUNT
3385         [ $? -eq 0 ] || { error "Unable to mount client"; return 19; }
3386
3387         # compare files
3388         diff_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
3389         [ $? -eq 0 ] || { error "Unable to diff files"; return 20; }
3390
3391         rm -rf $TMP/files $TMP/file_xattrs
3392         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 21; }
3393         do_node $ost1node "rm -rf $ost1tmp"
3394         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 22; }
3395         cleanup
3396 }
3397 run_test 52 "check recovering objects from lost+found"
3398
3399 # Checks threads_min/max/started for some service
3400 #
3401 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
3402 # parameter pattern prefix like 'ost.*.ost'.
3403 thread_sanity() {
3404         local modname=$1
3405         local facet=$2
3406         local parampat=$3
3407         local opts=$4
3408         local basethr=$5
3409         local tmin
3410         local tmin2
3411         local tmax
3412         local tmax2
3413         local tstarted
3414         local paramp
3415         local msg="Insane $modname thread counts"
3416         local ncpts=$(check_cpt_number $facet)
3417         local nthrs
3418         shift 4
3419
3420         check_mount || return 41
3421
3422         # We need to expand $parampat, but it may match multiple parameters, so
3423         # we'll pick the first one
3424         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
3425                 error "Couldn't expand ${parampat}.threads_min parameter name"
3426                 return 22
3427         fi
3428
3429         # Remove the .threads_min part
3430         paramp=${paramp%.threads_min}
3431
3432         # Check for sanity in defaults
3433         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3434         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3435         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started" || echo 0)
3436         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' || return $?
3437         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
3438         nthrs=$(expr $tmax - $tmin)
3439         if [ $nthrs -lt $ncpts ]; then
3440                 nthrs=0
3441         else
3442                 nthrs=$ncpts
3443         fi
3444
3445         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
3446                 skip_env "module parameter forced $facet thread count" &&
3447                 tmin=3 && tmax=$((3 * tmax))
3448
3449         # Check that we can change min/max
3450         do_facet $facet "lctl set_param ${paramp}.threads_min=$((tmin + nthrs))"
3451         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmax - nthrs))"
3452         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3453         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3454         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) && $tmax2 == ($tmax - $nthrs)))' || return $?
3455
3456         # Check that we can set min/max to the same value
3457         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3458         do_facet $facet "lctl set_param ${paramp}.threads_max=$tmin"
3459         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3460         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3461         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
3462
3463         # Check that we can't set max < min
3464         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmin - 1))"
3465         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3466         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3467         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
3468
3469         # We need to ensure that we get the module options desired; to do this
3470         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
3471         LOAD_MODULES_REMOTE=true
3472         cleanup
3473         local oldvalue
3474         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
3475         setmodopts -a $modname "$newvalue" oldvalue
3476
3477         load_modules
3478         setup
3479         check_mount || return 41
3480
3481         # Restore previous setting of MODOPTS_*
3482         setmodopts $modname "$oldvalue"
3483
3484         # Check that $opts took
3485         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min")
3486         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max")
3487         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started")
3488         lassert 28 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
3489         cleanup
3490
3491         load_modules
3492         setup
3493 }
3494
3495 test_53a() {
3496         setup
3497         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
3498         cleanup
3499 }
3500 run_test 53a "check OSS thread count params"
3501
3502 test_53b() {
3503         setup
3504         local mds=$(do_facet $SINGLEMDS "lctl get_param -N mds.*.*.threads_max \
3505                     2>/dev/null")
3506         if [ -z "$mds" ]; then
3507                 #running this on an old MDT
3508                 thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' 16
3509         else
3510                 thread_sanity MDT $SINGLEMDS 'mds.*.*.' 'mds_num_threads' 16
3511         fi
3512         cleanup
3513 }
3514 run_test 53b "check MDS thread count params"
3515
3516 test_54a() {
3517         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3518                 skip "Only applicable to ldiskfs-based MDTs"
3519                 return
3520         fi
3521
3522     do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p
3523     [ $? -eq 0 ] || error "llverdev failed!"
3524     reformat_and_config
3525 }
3526 run_test 54a "test llverdev and partial verify of device"
3527
3528 test_54b() {
3529         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3530                 skip "Only applicable to ldiskfs-based MDTs"
3531                 return
3532         fi
3533
3534     setup
3535     run_llverfs $MOUNT -p
3536     [ $? -eq 0 ] || error "llverfs failed!"
3537     cleanup
3538 }
3539 run_test 54b "test llverfs and partial verify of filesystem"
3540
3541 lov_objid_size()
3542 {
3543         local max_ost_index=$1
3544         echo -n $(((max_ost_index + 1) * 8))
3545 }
3546
3547 test_55() {
3548         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3549                 skip "Only applicable to ldiskfs-based MDTs"
3550                 return
3551         fi
3552
3553         local mdsdev=$(mdsdevname 1)
3554         local mdsvdev=$(mdsvdevname 1)
3555
3556         for i in 1023 2048
3557         do
3558                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
3559                         $mdsvdev || exit 10
3560                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
3561                         --reformat $(ostdevname 1) $(ostvdevname 1)
3562                 setup_noconfig
3563                 stopall
3564                 setup_noconfig
3565                 sync
3566
3567                 echo checking size of lov_objid for ost index $i
3568                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" | grep ^User | awk '{print $6}')
3569                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
3570                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
3571                 else
3572                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
3573                 fi
3574                 stopall
3575         done
3576
3577         reformat
3578 }
3579 run_test 55 "check lov_objid size"
3580
3581 test_56() {
3582         local mds_journal_size_orig=$MDSJOURNALSIZE
3583
3584         MDSJOURNALSIZE=16
3585
3586         for num in $(seq 1 $MDSCOUNT); do
3587                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3588                         --reformat $(mdsdevname $num) $(mdsvdevname $num)
3589         done
3590         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=1000 --reformat \
3591                 $(ostdevname 1) $(ostvdevname 1)
3592         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=10000 --reformat \
3593                 $(ostdevname 2) $(ostvdevname 2)
3594
3595         start_mgsmds
3596         start_ost
3597         start_ost2 || error "Unable to start second ost"
3598         mount_client $MOUNT || error "Unable to mount client"
3599         echo ok
3600         $LFS osts
3601         stopall
3602         MDSJOURNALSIZE=$mds_journal_size_orig
3603         reformat
3604 }
3605 run_test 56 "check big indexes"
3606
3607 test_57a() { # bug 22656
3608         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3609         writeconf_or_reformat
3610         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3611         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" || error "tunefs failed"
3612         start_mgsmds
3613         start_ost && error "OST registration from failnode should fail"
3614         reformat
3615 }
3616 run_test 57a "initial registration from failnode should fail (should return errs)"
3617
3618 test_57b() {
3619         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3620         writeconf_or_reformat
3621         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3622         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" || error "tunefs failed"
3623         start_mgsmds
3624         start_ost || error "OST registration from servicenode should not fail"
3625         reformat
3626 }
3627 run_test 57b "initial registration from servicenode should not fail"
3628
3629 count_osts() {
3630         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
3631 }
3632
3633 test_58() { # bug 22658
3634         setup_noconfig
3635         mkdir -p $DIR/$tdir
3636         createmany -o $DIR/$tdir/$tfile-%d 100
3637         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
3638 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
3639         do_facet $SINGLEMDS "lctl set_param fail_loc=0x601"
3640         unlinkmany $DIR/$tdir/$tfile-%d 100
3641         stop_mds
3642
3643         local MNTDIR=$(facet_mntpt $SINGLEMDS)
3644         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3645
3646         # remove all files from the OBJECTS dir
3647         mount_fstype $SINGLEMDS
3648
3649         do_facet $SINGLEMDS "find $MNTDIR/O/1/d* -type f -delete"
3650
3651         unmount_fstype $SINGLEMDS
3652         # restart MDS with missing llog files
3653         start_mds
3654         do_facet mds "lctl set_param fail_loc=0"
3655         reformat
3656 }
3657 run_test 58 "missing llog files must not prevent MDT from mounting"
3658
3659 test_59() {
3660         start_mgsmds >> /dev/null
3661         local C1=$(count_osts)
3662         if [ $C1 -eq 0 ]; then
3663                 start_ost >> /dev/null
3664                 C1=$(count_osts)
3665         fi
3666         stopall
3667         echo "original ost count: $C1 (expect > 0)"
3668         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
3669         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
3670         local C2=$(count_osts)
3671         echo "after mdt writeconf count: $C2 (expect 0)"
3672         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
3673         echo "OST start without writeconf should fail:"
3674         start_ost >> /dev/null && error "OST start without writeconf didn't fail"
3675         echo "OST start with writeconf should succeed:"
3676         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
3677         local C3=$(count_osts)
3678         echo "after ost writeconf count: $C3 (expect 1)"
3679         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
3680         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
3681         local C4=$(count_osts)
3682         echo "after ost2 writeconf count: $C4 (expect 2)"
3683         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
3684         stop_ost2 >> /dev/null
3685         cleanup_nocli >> /dev/null
3686         #writeconf to remove all ost2 traces for subsequent tests
3687         writeconf_or_reformat
3688 }
3689 run_test 59 "writeconf mount option"
3690
3691 test_60() { # LU-471
3692         local num
3693
3694         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3695                 skip "Only applicable to ldiskfs-based MDTs"
3696                 return
3697         fi
3698
3699         for num in $(seq $MDSCOUNT); do
3700                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3701                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
3702                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3703                         exit 10
3704         done
3705
3706         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
3707         rc=${PIPESTATUS[0]}
3708         [ $rc -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
3709
3710         # MDT default has dirdata feature
3711         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
3712         # we disable uninit_bg feature
3713         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
3714         # we set stride extended options
3715         echo $dump | grep stride > /dev/null || error "stride is not set"
3716         reformat
3717 }
3718 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
3719
3720 test_61() { # LU-80
3721         local reformat=false
3722
3723         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
3724                 { skip "Need MDS version at least 2.1.53"; return 0; }
3725
3726         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3727            ! large_xattr_enabled; then
3728                 reformat=true
3729                 LDISKFS_MKFS_OPTS+=" -O large_xattr"
3730
3731                 for num in $(seq $MDSCOUNT); do
3732                         add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
3733                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3734                         error "add mds $num failed"
3735                 done
3736         fi
3737
3738     setup_noconfig || error "setting up the filesystem failed"
3739     client_up || error "starting client failed"
3740
3741     local file=$DIR/$tfile
3742     touch $file
3743
3744     local large_value="$(generate_string $(max_xattr_size))"
3745     local small_value="bar"
3746
3747     local name="trusted.big"
3748     log "save large xattr $name on $file"
3749     setfattr -n $name -v $large_value $file ||
3750         error "saving $name on $file failed"
3751
3752     local new_value=$(get_xattr_value $name $file)
3753     [[ "$new_value" != "$large_value" ]] &&
3754         error "$name different after saving"
3755
3756     log "shrink value of $name on $file"
3757     setfattr -n $name -v $small_value $file ||
3758         error "shrinking value of $name on $file failed"
3759
3760     new_value=$(get_xattr_value $name $file)
3761     [[ "$new_value" != "$small_value" ]] &&
3762         error "$name different after shrinking"
3763
3764     log "grow value of $name on $file"
3765     setfattr -n $name -v $large_value $file ||
3766         error "growing value of $name on $file failed"
3767
3768     new_value=$(get_xattr_value $name $file)
3769     [[ "$new_value" != "$large_value" ]] &&
3770         error "$name different after growing"
3771
3772     log "check value of $name on $file after remounting MDS"
3773     fail $SINGLEMDS
3774     new_value=$(get_xattr_value $name $file)
3775     [[ "$new_value" != "$large_value" ]] &&
3776         error "$name different after remounting MDS"
3777
3778     log "remove large xattr $name from $file"
3779     setfattr -x $name $file || error "removing $name from $file failed"
3780
3781     rm -f $file
3782     stopall
3783         if $reformat; then
3784                 LDISKFS_MKFS_OPTS=${LDISKFS_MKFS_OPTS% -O large_xattr}
3785                 reformat
3786         fi
3787 }
3788 run_test 61 "large xattr"
3789
3790 test_62() {
3791         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3792                 skip "Only applicable to ldiskfs-based MDTs"
3793                 return
3794         fi
3795
3796         # MRP-118
3797         local mdsdev=$(mdsdevname 1)
3798         local ostdev=$(ostdevname 1)
3799
3800         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
3801                 { skip "Need MDS version at least 2.2.51"; return 0; }
3802
3803         echo "disable journal for mds"
3804         do_facet mds tune2fs -O ^has_journal $mdsdev || error "tune2fs failed"
3805         start_mds && error "MDT start should fail"
3806         echo "disable journal for ost"
3807         do_facet ost1 tune2fs -O ^has_journal $ostdev || error "tune2fs failed"
3808         start_ost && error "OST start should fail"
3809         cleanup || return $?
3810         reformat_and_config
3811 }
3812 run_test 62 "start with disabled journal"
3813
3814 test_63() {
3815         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3816                 skip "Only applicable to ldiskfs-based MDTs"
3817                 return
3818         fi
3819
3820         local inode_slab=$(do_facet $SINGLEMDS \
3821                 "awk '/ldiskfs_inode_cache/ { print \\\$5 }' /proc/slabinfo")
3822         if [ -z "$inode_slab" ]; then
3823                 skip "ldiskfs module has not been loaded"
3824                 return
3825         fi
3826
3827         echo "$inode_slab ldisk inodes per page"
3828         [ "$inode_slab" -ge "3" ] ||
3829                 error "ldisk inode size is too big, $inode_slab objs per page"
3830         return
3831 }
3832 run_test 63 "Verify each page can at least hold 3 ldisk inodes"
3833
3834 test_64() {
3835         start_mds
3836         start_ost
3837         start_ost2 || error "Unable to start second ost"
3838         mount_client $MOUNT || error "Unable to mount client"
3839         stop_ost2 || error "Unable to stop second ost"
3840         echo "$LFS df"
3841         $LFS df --lazy || error "lfs df failed"
3842         cleanup || return $?
3843         #writeconf to remove all ost2 traces for subsequent tests
3844         writeconf_or_reformat
3845 }
3846 run_test 64 "check lfs df --lazy "
3847
3848 test_65() { # LU-2237
3849         # Currently, the test is only valid for ldiskfs backend
3850         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3851                 skip "non-ldiskfs backend" && return
3852
3853         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3854         local brpt=$(facet_mntpt brpt)
3855         local opts=""
3856
3857         if ! do_facet $SINGLEMDS "test -b $devname"; then
3858                 opts="-o loop"
3859         fi
3860
3861         stop_mds
3862         local obj=$(do_facet $SINGLEMDS \
3863                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
3864                     grep Inode)
3865         if [ -z "$obj" ]; then
3866                 # The MDT may be just re-formatted, mount the MDT for the
3867                 # first time to guarantee the "last_rcvd" file is there.
3868                 start_mds || error "fail to mount the MDS for the first time"
3869                 stop_mds
3870         fi
3871
3872         # remove the "last_rcvd" file
3873         do_facet $SINGLEMDS "mkdir -p $brpt"
3874         do_facet $SINGLEMDS \
3875                 "mount -t $(facet_fstype $SINGLEMDS) $opts $devname $brpt"
3876         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
3877         do_facet $SINGLEMDS "umount -d $brpt"
3878
3879         # restart MDS, the "last_rcvd" file should be recreated.
3880         start_mds || error "fail to restart the MDS"
3881         stop_mds
3882         obj=$(do_facet $SINGLEMDS \
3883               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
3884         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
3885 }
3886 run_test 65 "re-create the lost last_rcvd file when server mount"
3887
3888 test_66() {
3889         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
3890                 { skip "Need MGS version at least 2.3.59"; return 0; }
3891
3892         setup
3893         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
3894         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
3895
3896         echo "replace_nids should fail if MDS, OSTs and clients are UP"
3897         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3898                 error "replace_nids fail"
3899
3900         umount_client $MOUNT || error "unmounting client failed"
3901         echo "replace_nids should fail if MDS and OSTs are UP"
3902         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3903                 error "replace_nids fail"
3904
3905         stop_ost
3906         echo "replace_nids should fail if MDS is UP"
3907         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3908                 error "replace_nids fail"
3909
3910         stop_mds || error "stopping mds failed"
3911
3912         if combined_mgs_mds; then
3913                 start_mdt 1 "-o nosvc" ||
3914                         error "starting mds with nosvc option failed"
3915         fi
3916
3917         echo "command should accept two parameters"
3918         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
3919                 error "command should accept two params"
3920
3921         echo "correct device name should be passed"
3922         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
3923                 error "wrong devname"
3924
3925         echo "wrong nids list should not destroy the system"
3926         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
3927                 error "wrong parse"
3928
3929         echo "replace OST nid"
3930         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
3931                 error "replace nids failed"
3932
3933         echo "command should accept two parameters"
3934         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
3935                 error "command should accept two params"
3936
3937         echo "wrong nids list should not destroy the system"
3938         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
3939                 error "wrong parse"
3940
3941         echo "replace MDS nid"
3942         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
3943                 error "replace nids failed"
3944
3945         if ! combined_mgs_mds ; then
3946                 stop_mgs
3947         else
3948                 stop_mds
3949         fi
3950
3951         setup_noconfig
3952         check_mount || error "error after nid replace"
3953         cleanup || error "cleanup failed"
3954         reformat
3955 }
3956 run_test 66 "replace nids"
3957
3958 test_67() { #LU-2950
3959         local legacy="$TMP/legacy_lnet_config"
3960         local new="$TMP/new_routes_test"
3961         local out="$TMP/config_out_file"
3962         local verify="$TMP/conv_verify"
3963         local verify_conf="$TMP/conf_verify"
3964
3965         # Create the legacy file that will be run through the
3966         # lustre_routes_conversion script
3967         cat <<- LEGACY_LNET_CONFIG > $legacy
3968                 tcp1 23 192.168.213.1@tcp:1; tcp5 34 193.30.4.3@tcp:4;
3969                 tcp2 54 10.1.3.2@tcp;
3970                 tcp3 10.3.4.3@tcp:3;
3971                 tcp4 10.3.3.4@tcp;
3972         LEGACY_LNET_CONFIG
3973
3974         # Create the verification file to verify the output of
3975         # lustre_routes_conversion script against.
3976         cat <<- VERIFY_LNET_CONFIG > $verify
3977                 tcp1: { gateway: 192.168.213.1@tcp, hop: 23, priority: 1 }
3978                 tcp5: { gateway: 193.30.4.3@tcp, hop: 34, priority: 4 }
3979                 tcp2: { gateway: 10.1.3.2@tcp, hop: 54 }
3980                 tcp3: { gateway: 10.3.4.3@tcp, priority: 3 }
3981                 tcp4: { gateway: 10.3.3.4@tcp }
3982         VERIFY_LNET_CONFIG
3983
3984         # Create the verification file to verify the output of
3985         # lustre_routes_config script against
3986         cat <<- VERIFY_LNET_CONFIG > $verify_conf
3987                 lctl --net tcp1 add_route 192.168.213.1@tcp 23 1
3988                 lctl --net tcp5 add_route 193.30.4.3@tcp 34 4
3989                 lctl --net tcp2 add_route 10.1.3.2@tcp 54 4
3990                 lctl --net tcp3 add_route 10.3.4.3@tcp 1 3
3991                 lctl --net tcp4 add_route 10.3.3.4@tcp 1 3
3992         VERIFY_LNET_CONFIG
3993
3994         lustre_routes_conversion $legacy $new > /dev/null
3995         if [ -f $new ]; then
3996                 # verify the conversion output
3997                 cmp -s $new $verify > /dev/null
3998                 if [ $? -eq 1 ]; then
3999                         error "routes conversion failed"
4000                 fi
4001
4002                 lustre_routes_config --dry-run --verbose $new > $out
4003                 # check that the script succeeded
4004                 cmp -s $out $verify_conf > /dev/null
4005                 if [ $? -eq 1 ]; then
4006                         error "routes config failed"
4007                 fi
4008         else
4009                 error "routes conversion test failed"
4010         fi
4011         # remove generated files
4012         rm -f $new $legacy $verify $verify_conf $out
4013 }
4014 run_test 67 "test routes conversion and configuration"
4015
4016 test_68() {
4017         local fid
4018         local seq
4019         local START
4020         local END
4021
4022         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.53) ] ||
4023                 { skip "Need MDS version at least 2.4.53"; return 0; }
4024
4025         umount_client $MOUNT || error "umount client failed"
4026
4027         start_mdt 1 || error "MDT start failed"
4028         start_ost
4029
4030         # START-END - the sequences we'll be reserving
4031         START=$(do_facet $SINGLEMDS \
4032                 lctl get_param -n seq.ctl*.space | awk -F'[[ ]' '{print $2}')
4033         END=$((START + (1 << 30)))
4034         do_facet $SINGLEMDS \
4035                 lctl set_param seq.ctl*.fldb="[$START-$END\):0:mdt"
4036
4037         # reset the sequences MDT0000 has already assigned
4038         do_facet $SINGLEMDS \
4039                 lctl set_param seq.srv*MDT0000.space=clear
4040
4041         # remount to let the client allocate new sequence
4042         mount_client $MOUNT || error "mount client failed"
4043
4044         touch $DIR/$tfile
4045         do_facet $SINGLEMDS \
4046                 lctl get_param seq.srv*MDT0000.space
4047         $LFS path2fid $DIR/$tfile
4048
4049         local old_ifs="$IFS"
4050         IFS='[:]'
4051         fid=($($LFS path2fid $DIR/$tfile))
4052         IFS="$old_ifs"
4053         let seq=${fid[1]}
4054
4055         if [[ $seq < $END ]]; then
4056                 error "used reserved sequence $seq?"
4057         fi
4058         cleanup || return $?
4059 }
4060 run_test 68 "be able to reserve specific sequences in FLDB"
4061
4062 test_69() {
4063         local server_version=$(lustre_version_code $SINGLEMDS)
4064
4065         [[ $server_version -lt $(version_code 2.4.2) ]] &&
4066                 skip "Need MDS version at least 2.4.2" && return
4067
4068         [[ $server_version -ge $(version_code 2.4.50) ]] &&
4069         [[ $server_version -lt $(version_code 2.5.0) ]] &&
4070                 skip "Need MDS version at least 2.5.0" && return
4071
4072         setup
4073
4074         # use OST0000 since it probably has the most creations
4075         local OSTNAME=$(ostname_from_index 0)
4076         local mdtosc_proc1=$(get_mdtosc_proc_path mds1 $OSTNAME)
4077         local last_id=$(do_facet mds1 lctl get_param -n \
4078                         osc.$mdtosc_proc1.prealloc_last_id)
4079
4080         # Want to have OST LAST_ID over 1.5 * OST_MAX_PRECREATE to
4081         # verify that the LAST_ID recovery is working properly.  If
4082         # not, then the OST will refuse to allow the MDS connect
4083         # because the LAST_ID value is too different from the MDS
4084         #define OST_MAX_PRECREATE=20000
4085         local num_create=$((20000 * 5))
4086
4087         mkdir -p $DIR/$tdir
4088         $LFS setstripe -i 0 $DIR/$tdir
4089         createmany -o $DIR/$tdir/$tfile- $num_create ||
4090                 error "createmany: failed to create $num_create files: $?"
4091         # delete all of the files with objects on OST0 so the
4092         # filesystem is not inconsistent later on
4093         $LFS find $MOUNT --ost 0 | xargs rm
4094
4095         stop_ost || error "OST0 stop failure"
4096         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat --replace \
4097                 $(ostdevname 1) $(ostvdevname 1) ||
4098                 error "reformat and replace $ostdev failed"
4099         start_ost || error "OST0 restart failure"
4100         wait_osc_import_state mds ost FULL
4101
4102         touch $DIR/$tdir/$tfile-last || error "create file after reformat"
4103         local idx=$($LFS getstripe -i $DIR/$tdir/$tfile-last)
4104         [ $idx -ne 0 ] && error "$DIR/$tdir/$tfile-last on $idx not 0" || true
4105
4106         cleanup
4107 }
4108 run_test 69 "replace an OST with the same index"
4109
4110 test_70a() {
4111         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4112         local MDTIDX=1
4113
4114         cleanup
4115
4116         start_mdt 1 || error "MDT0 start fail"
4117
4118         start_ost || error "OST0 start fail"
4119
4120         start_mdt 2 || error "MDT1 start fail"
4121
4122         mount_client $MOUNT || error "mount client fails"
4123
4124         mkdir -p $DIR/$tdir || error "create dir fail"
4125
4126         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4127                                         error "create remote dir fail"
4128
4129         rm -rf $DIR/$tdir || error "delete dir fail"
4130         cleanup || return $?
4131 }
4132 run_test 70a "start MDT0, then OST, then MDT1"
4133
4134 test_70b() {
4135         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4136         local MDTIDX=1
4137
4138         start_ost || error "OST0 start fail"
4139
4140         start_mdt 1 || error "MDT0 start fail"
4141         start_mdt 2 || error "MDT1 start fail"
4142
4143         mount_client $MOUNT || error "mount client fails"
4144
4145         mkdir -p $DIR/$tdir || error "create dir fail"
4146
4147         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4148                                         error "create remote dir fail"
4149
4150         rm -rf $DIR/$tdir || error "delete dir fail"
4151
4152         cleanup || return $?
4153 }
4154 run_test 70b "start OST, MDT1, MDT0"
4155
4156 test_70c() {
4157         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4158         local MDTIDX=1
4159
4160         start_mdt 1 || error "MDT0 start fail"
4161         start_mdt 2 || error "MDT1 start fail"
4162         start_ost || error "OST0 start fail"
4163
4164         mount_client $MOUNT || error "mount client fails"
4165         stop_mdt 1 || error "MDT1 start fail"
4166
4167         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
4168         echo "deactivate $mdc_for_mdt1"
4169         $LCTL --device $mdc_for_mdt1 deactivate || return 1
4170
4171         mkdir -p $DIR/$tdir && error "mkdir succeed"
4172
4173         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4174                                         error "create remote dir succeed"
4175
4176         cleanup || return $?
4177 }
4178 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
4179
4180 test_70d() {
4181         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4182         local MDTIDX=1
4183
4184         start_mdt 1 || error "MDT0 start fail"
4185         start_mdt 2 || error "MDT1 start fail"
4186         start_ost || error "OST0 start fail"
4187
4188         mount_client $MOUNT || error "mount client fails"
4189
4190         stop_mdt 2 || error "MDT1 start fail"
4191
4192         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
4193                              awk '{print $4}')
4194         echo "deactivate $mdc_for_mdt2"
4195         $LCTL --device $mdc_for_mdt2 deactivate ||
4196                         error "set $mdc_for_mdt2 deactivate failed"
4197
4198         mkdir -p $DIR/$tdir || error "mkdir fail"
4199         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4200                         error "create remote dir succeed"
4201
4202         rm -rf $DIR/$tdir || error "delete dir fail"
4203
4204         cleanup || return $?
4205 }
4206 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
4207
4208 test_71a() {
4209         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4210         if combined_mgs_mds; then
4211                 skip "needs separate MGS/MDT" && return
4212         fi
4213         local MDTIDX=1
4214
4215         start_mdt 1 || error "MDT0 start fail"
4216         start_ost || error "OST0 start fail"
4217         start_mdt 2 || error "MDT1 start fail"
4218         start_ost2 || error "OST1 start fail"
4219
4220         mount_client $MOUNT || error "mount client fails"
4221
4222         mkdir -p $DIR/$tdir || error "mkdir fail"
4223         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4224                         error "create remote dir succeed"
4225
4226         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4227         rm -rf $DIR/$tdir || error "delete dir fail"
4228
4229         umount_client $MOUNT
4230         stop_mdt 1 || error "MDT0 stop fail"
4231         stop_mdt 2 || error "MDT1 stop fail"
4232         stop_ost || error "OST0 stop fail"
4233         stop_ost2 || error "OST1 stop fail"
4234 }
4235 run_test 71a "start MDT0 OST0, MDT1, OST1"
4236
4237 test_71b() {
4238         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4239         if combined_mgs_mds; then
4240                 skip "needs separate MGS/MDT" && return
4241         fi
4242         local MDTIDX=1
4243
4244         start_mdt 2 || error "MDT1 start fail"
4245         start_ost || error "OST0 start fail"
4246         start_mdt 1 || error "MDT0 start fail"
4247         start_ost2 || error "OST1 start fail"
4248
4249         mount_client $MOUNT || error "mount client fails"
4250
4251         mkdir -p $DIR/$tdir || error "mkdir fail"
4252         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4253                         error "create remote dir succeed"
4254
4255         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4256         rm -rf $DIR/$tdir || error "delete dir fail"
4257
4258         umount_client $MOUNT
4259         stop_mdt 1 || error "MDT0 stop fail"
4260         stop_mdt 2 || error "MDT1 stop fail"
4261         stop_ost || error "OST0 stop fail"
4262         stop_ost2 || error "OST1 stop fail"
4263 }
4264 run_test 71b "start MDT1, OST0, MDT0, OST1"
4265
4266 test_71c() {
4267         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4268         if combined_mgs_mds; then
4269                 skip "needs separate MGS/MDT" && return
4270         fi
4271         local MDTIDX=1
4272
4273         start_ost || error "OST0 start fail"
4274         start_ost2 || error "OST1 start fail"
4275         start_mdt 2 || error "MDT1 start fail"
4276         start_mdt 1 || error "MDT0 start fail"
4277
4278         mount_client $MOUNT || error "mount client fails"
4279
4280         mkdir -p $DIR/$tdir || error "mkdir fail"
4281         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4282                         error "create remote dir succeed"
4283
4284         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4285         rm -rf $DIR/$tdir || error "delete dir fail"
4286
4287         umount_client $MOUNT
4288         stop_mdt 1 || error "MDT0 stop fail"
4289         stop_mdt 2 || error "MDT1 stop fail"
4290         stop_ost || error "OST0 stop fail"
4291         stop_ost2 || error "OST1 stop fail"
4292
4293 }
4294 run_test 71c "start OST0, OST1, MDT1, MDT0"
4295
4296 test_71d() {
4297         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4298         if combined_mgs_mds; then
4299                 skip "needs separate MGS/MDT" && return
4300         fi
4301         local MDTIDX=1
4302
4303         start_ost || error "OST0 start fail"
4304         start_mdt 2 || error "MDT0 start fail"
4305         start_mdt 1 || error "MDT0 start fail"
4306         start_ost2 || error "OST1 start fail"
4307
4308         mount_client $MOUNT || error "mount client fails"
4309
4310         mkdir -p $DIR/$tdir || error "mkdir fail"
4311         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4312                         error "create remote dir succeed"
4313
4314         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4315         rm -rf $DIR/$tdir || error "delete dir fail"
4316
4317         umount_client $MOUNT
4318         stop_mdt 1 || error "MDT0 stop fail"
4319         stop_mdt 2 || error "MDT1 stop fail"
4320         stop_ost || error "OST0 stop fail"
4321         stop_ost2 || error "OST1 stop fail"
4322
4323 }
4324 run_test 71d "start OST0, MDT1, MDT0, OST1"
4325
4326 test_71e() {
4327         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4328         if combined_mgs_mds; then
4329                 skip "needs separate MGS/MDT" && return
4330         fi
4331         local MDTIDX=1
4332
4333         start_ost || error "OST0 start fail"
4334         start_mdt 2 || error "MDT1 start fail"
4335         start_ost2 || error "OST1 start fail"
4336         start_mdt 1 || error "MDT0 start fail"
4337
4338         mount_client $MOUNT || error "mount client fails"
4339
4340         mkdir -p $DIR/$tdir || error "mkdir fail"
4341         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4342                         error "create remote dir succeed"
4343
4344         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4345         rm -rf $DIR/$tdir || error "delete dir fail"
4346
4347         umount_client $MOUNT
4348         stop_mdt 1 || error "MDT0 stop fail"
4349         stop_mdt 2 || error "MDT1 stop fail"
4350         stop_ost || error "OST0 stop fail"
4351         stop_ost2 || error "OST1 stop fail"
4352
4353 }
4354 run_test 71e "start OST0, MDT1, OST1, MDT0"
4355
4356 test_72() { #LU-2634
4357         local mdsdev=$(mdsdevname 1)
4358         local ostdev=$(ostdevname 1)
4359         local cmd="$E2FSCK -fnvd $mdsdev"
4360         local fn=3
4361
4362         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
4363                 skip "ldiskfs only test" && return
4364
4365         #tune MDT with "-O extents"
4366
4367         for num in $(seq $MDSCOUNT); do
4368                 add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
4369                 --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
4370                 error "add mds $num failed"
4371                 $TUNE2FS -O extents $(mdsdevname $num)
4372         done
4373
4374         add ost1 $(mkfs_opts ost1 $ostdev) --reformat $ostdev ||
4375                 error "add $ostdev failed"
4376         start_mgsmds || error "start mds failed"
4377         start_ost || error "start ost failed"
4378         mount_client $MOUNT || error "mount client failed"
4379
4380         #create some short symlinks
4381         mkdir -p $DIR/$tdir
4382         createmany -o $DIR/$tdir/$tfile-%d $fn
4383         echo "create $fn short symlinks"
4384         for i in $(seq -w 1 $fn); do
4385                 ln -s $DIR/$tdir/$tfile-$i $MOUNT/$tfile-$i
4386         done
4387         ls -al $MOUNT
4388
4389         #umount
4390         umount_client $MOUNT || error "umount client failed"
4391         stop_mds || error "stop mds failed"
4392         stop_ost || error "stop ost failed"
4393
4394         #run e2fsck
4395         run_e2fsck $(facet_active_host $SINGLEMDS) $mdsdev "-n"
4396 }
4397 run_test 72 "test fast symlink with extents flag enabled"
4398
4399 test_73() { #LU-3006
4400         load_modules
4401         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
4402         do_facet ost1 "$TUNEFS --failnode=1.2.3.4@$NETTYPE $(ostdevname 1)" ||
4403                 error "1st tunefs failed"
4404         start_mgsmds || error "start mds failed"
4405         start_ost || error "start ost failed"
4406         mount_client $MOUNT || error "mount client failed"
4407         lctl get_param -n osc.*OST0000-osc-[^M]*.import | grep failover_nids |
4408                 grep 1.2.3.4@$NETTYPE || error "failover nids haven't changed"
4409         umount_client $MOUNT || error "umount client failed"
4410         stopall
4411         reformat
4412 }
4413 run_test 73 "failnode to update from mountdata properly"
4414
4415 test_75() { # LU-2374
4416         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
4417                         skip "Need MDS version at least 2.4.1" && return
4418
4419         local index=0
4420         local opts_mds="$(mkfs_opts mds1 $(mdsdevname 1)) \
4421                 --reformat $(mdsdevname 1) $(mdsvdevname 1)"
4422         local opts_ost="$(mkfs_opts ost1 $(ostdevname 1)) \
4423                 --reformat $(ostdevname 1) $(ostvdevname 1)"
4424
4425         #check with default parameters
4426         add mds1 $opts_mds || error "add mds1 failed for default params"
4427         add ost1 $opts_ost || error "add ost1 failed for default params"
4428
4429         opts_mds=$(echo $opts_mds | sed -e "s/--mdt//")
4430         opts_mds=$(echo $opts_mds |
4431                    sed -e "s/--index=$index/--index=$index --mdt/")
4432         opts_ost=$(echo $opts_ost | sed -e "s/--ost//")
4433         opts_ost=$(echo $opts_ost |
4434                    sed -e "s/--index=$index/--index=$index --ost/")
4435
4436         add mds1 $opts_mds || error "add mds1 failed for new params"
4437         add ost1 $opts_ost || error "add ost1 failed for new params"
4438         return 0
4439 }
4440 run_test 75 "The order of --index should be irrelevant"
4441
4442 test_76a() {
4443         [[ $(lustre_version_code mgs) -ge $(version_code 2.4.52) ]] ||
4444                 { skip "Need MDS version at least 2.4.52" && return 0; }
4445         setup
4446         local MDMB_PARAM="osc.*.max_dirty_mb"
4447         echo "Change MGS params"
4448         local MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM |
4449                 head -1)
4450         echo "max_dirty_mb: $MAX_DIRTY_MB"
4451         local NEW_MAX_DIRTY_MB=$((MAX_DIRTY_MB + MAX_DIRTY_MB))
4452         echo "new_max_dirty_mb: $NEW_MAX_DIRTY_MB"
4453         do_facet mgs $LCTL set_param -P $MDMB_PARAM=$NEW_MAX_DIRTY_MB
4454         wait_update $HOSTNAME "lctl get_param -n $MDMB_PARAM |
4455                 head -1" $NEW_MAX_DIRTY_MB
4456         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
4457         echo "$MAX_DIRTY_MB"
4458         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
4459                 error "error while apply max_dirty_mb"
4460
4461         echo "Check the value is stored after remount"
4462         stopall
4463         setupall
4464         wait_update $HOSTNAME "lctl get_param -n $MDMB_PARAM |
4465                 head -1" $NEW_MAX_DIRTY_MB
4466         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
4467         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
4468                 error "max_dirty_mb is not saved after remount"
4469
4470         echo "Change OST params"
4471         CLIENT_PARAM="obdfilter.*.client_cache_count"
4472         local CLIENT_CACHE_COUNT
4473         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4474                 head -1)
4475         echo "client_cache_count: $CLIENT_CACHE_COUNT"
4476         NEW_CLIENT_CACHE_COUNT=$((CLIENT_CACHE_COUNT+CLIENT_CACHE_COUNT))
4477         echo "new_client_cache_count: $NEW_CLIENT_CACHE_COUNT"
4478         do_facet mgs $LCTL set_param -P $CLIENT_PARAM=$NEW_CLIENT_CACHE_COUNT
4479         wait_update $(facet_host ost1) "lctl get_param -n $CLIENT_PARAM |
4480                 head -1" $NEW_CLIENT_CACHE_COUNT
4481         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4482                 head -1)
4483         echo "$CLIENT_CACHE_COUNT"
4484         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
4485                 error "error while apply client_cache_count"
4486
4487         echo "Check the value is stored after remount"
4488         stopall
4489         setupall
4490         wait_update $(facet_host ost1) "lctl get_param -n $CLIENT_PARAM |
4491                 head -1" $NEW_CLIENT_CACHE_COUNT
4492         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4493                 head -1)
4494         echo "$CLIENT_CACHE_COUNT"
4495         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
4496                 error "client_cache_count is not saved after remount"
4497         stopall
4498 }
4499 run_test 76a "set permanent params set_param -P"
4500
4501 test_76b() { # LU-4783
4502         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.57) ]] ||
4503                 { skip "Need MGS version at least 2.5.57" && return 0; }
4504         stopall
4505         setupall
4506         do_facet mgs $LCTL get_param mgs.MGS.live.params ||
4507                 error "start params log failed"
4508         stopall
4509 }
4510 run_test 76b "verify params log setup correctly"
4511
4512 test_77() { # LU-3445
4513         local server_version=$(lustre_version_code $SINGLEMDS)
4514
4515         [[ $server_version -ge $(version_code 2.2.60) ]] &&
4516         [[ $server_version -le $(version_code 2.4.0) ]] &&
4517                 skip "Need MDS version < 2.2.60 or > 2.4.0" && return
4518
4519         if [[ -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
4520                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
4521                 skip_env "mixed loopback and real device not working" && return
4522         fi
4523
4524         local fs2mdsdev=$(mdsdevname 1_2)
4525         local fs2ostdev=$(ostdevname 1_2)
4526         local fs2mdsvdev=$(mdsvdevname 1_2)
4527         local fs2ostvdev=$(ostvdevname 1_2)
4528         local fsname=test1234
4529         local mgsnid
4530         local failnid="$(h2$NETTYPE 1.2.3.4),$(h2$NETTYPE 4.3.2.1)"
4531
4532         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --mgs --fsname=$fsname \
4533                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
4534         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT ||
4535                 error "start fs2mds failed"
4536
4537         mgsnid=$(do_facet fs2mds $LCTL list_nids | xargs | tr ' ' ,)
4538         [[ $mgsnid = *,* ]] || mgsnid+=",$mgsnid"
4539
4540         add fs2ost $(mkfs_opts ost1 $fs2ostdev) --mgsnode=$mgsnid \
4541                 --failnode=$failnid --fsname=$fsname \
4542                 --reformat $fs2ostdev $fs2ostvdev ||
4543                         error "add fs2ost failed"
4544         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
4545
4546         mkdir -p $MOUNT2
4547         $MOUNT_CMD $mgsnid:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
4548         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
4549         cleanup_fs2
4550 }
4551 run_test 77 "comma-separated MGS NIDs and failover node NIDs"
4552
4553 test_78() {
4554         [[ $(facet_fstype $SINGLEMDS) != ldiskfs ||
4555            $(facet_fstype ost1) != ldiskfs ]] &&
4556                 skip "only applicable to ldiskfs-based MDTs and OSTs" && return
4557
4558         # reformat the Lustre filesystem with a smaller size
4559         local saved_MDSSIZE=$MDSSIZE
4560         local saved_OSTSIZE=$OSTSIZE
4561         MDSSIZE=$((MDSSIZE - 20000))
4562         OSTSIZE=$((OSTSIZE - 20000))
4563         reformat || error "(1) reformat Lustre filesystem failed"
4564         MDSSIZE=$saved_MDSSIZE
4565         OSTSIZE=$saved_OSTSIZE
4566
4567         # mount the Lustre filesystem
4568         setup_noconfig || error "(2) setup Lustre filesystem failed"
4569
4570         # create some files
4571         log "create test files"
4572         local i
4573         local file
4574         local num_files=100
4575         mkdir -p $MOUNT/$tdir || error "(3) mkdir $MOUNT/$tdir failed"
4576         for i in $(seq $num_files); do
4577                 file=$MOUNT/$tdir/$tfile-$i
4578                 dd if=/dev/urandom of=$file count=1 bs=1M ||
4579                         error "(4) create $file failed"
4580         done
4581
4582         # unmount the Lustre filesystem
4583         cleanup || error "(5) cleanup Lustre filesystem failed"
4584
4585         # run e2fsck on the MDT and OST devices
4586         local mds_host=$(facet_active_host $SINGLEMDS)
4587         local ost_host=$(facet_active_host ost1)
4588         local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4589         local ost_dev=$(ostdevname 1)
4590
4591         run_e2fsck $mds_host $mds_dev "-y"
4592         run_e2fsck $ost_host $ost_dev "-y"
4593
4594         # get the original block count of the MDT and OST filesystems
4595         local mds_orig_blks=$(get_block_count $SINGLEMDS $mds_dev)
4596         local ost_orig_blks=$(get_block_count ost1 $ost_dev)
4597
4598         # expand the MDT and OST filesystems to the device size
4599         run_resize2fs $SINGLEMDS $mds_dev "" || error "expand $SINGLEMDS failed"
4600         run_resize2fs ost1 $ost_dev "" || error "expand ost1 failed"
4601
4602         # run e2fsck on the MDT and OST devices again
4603         run_e2fsck $mds_host $mds_dev "-y"
4604         run_e2fsck $ost_host $ost_dev "-y"
4605
4606         # mount the Lustre filesystem
4607         setup
4608
4609         # check the files
4610         log "check files after expanding the MDT and OST filesystems"
4611         for i in $(seq $num_files); do
4612                 file=$MOUNT/$tdir/$tfile-$i
4613                 $CHECKSTAT -t file -s 1048576 $file ||
4614                         error "(6) checkstat $file failed"
4615         done
4616
4617         # create more files
4618         log "create more files after expanding the MDT and OST filesystems"
4619         for i in $(seq $((num_files + 1)) $((num_files + 10))); do
4620                 file=$MOUNT/$tdir/$tfile-$i
4621                 dd if=/dev/urandom of=$file count=1 bs=1M ||
4622                         error "(7) create $file failed"
4623         done
4624
4625         # unmount the Lustre filesystem
4626         cleanup || error "(8) cleanup Lustre filesystem failed"
4627
4628         # run e2fsck on the MDT and OST devices
4629         run_e2fsck $mds_host $mds_dev "-y"
4630         run_e2fsck $ost_host $ost_dev "-y"
4631
4632         # get the maximum block count of the MDT and OST filesystems
4633         local mds_max_blks=$(get_block_count $SINGLEMDS $mds_dev)
4634         local ost_max_blks=$(get_block_count ost1 $ost_dev)
4635
4636         # get the minimum block count of the MDT and OST filesystems
4637         local mds_min_blks=$(run_resize2fs $SINGLEMDS $mds_dev "" "-P" 2>&1 |
4638                                 grep minimum | sed -e 's/^.*filesystem: //g')
4639         local ost_min_blks=$(run_resize2fs ost1 $ost_dev "" "-P" 2>&1 |
4640                                 grep minimum | sed -e 's/^.*filesystem: //g')
4641
4642         # shrink the MDT and OST filesystems to a smaller size
4643         local shrunk=false
4644         local new_blks
4645         local base_blks
4646         if [[ $mds_max_blks -gt $mds_min_blks &&
4647               $mds_max_blks -gt $mds_orig_blks ]]; then
4648                 [[ $mds_orig_blks -gt $mds_min_blks ]] &&
4649                         base_blks=$mds_orig_blks || base_blks=$mds_min_blks
4650                 new_blks=$(( (mds_max_blks - base_blks) / 2 + base_blks ))
4651                 run_resize2fs $SINGLEMDS $mds_dev $new_blks ||
4652                         error "shrink $SINGLEMDS to $new_blks failed"
4653                 shrunk=true
4654         fi
4655
4656         if [[ $ost_max_blks -gt $ost_min_blks &&
4657               $ost_max_blks -gt $ost_orig_blks ]]; then
4658                 [[ $ost_orig_blks -gt $ost_min_blks ]] &&
4659                         base_blks=$ost_orig_blks || base_blks=$ost_min_blks
4660                 new_blks=$(( (ost_max_blks - base_blks) / 2 + base_blks ))
4661                 run_resize2fs ost1 $ost_dev $new_blks ||
4662                         error "shrink ost1 to $new_blks failed"
4663                 shrunk=true
4664         fi
4665
4666         # check whether the MDT or OST filesystem was shrunk or not
4667         if ! $shrunk; then
4668                 combined_mgs_mds || stop_mgs || error "(9) stop mgs failed"
4669                 reformat || error "(10) reformat Lustre filesystem failed"
4670                 return 0
4671         fi
4672
4673         # run e2fsck on the MDT and OST devices again
4674         run_e2fsck $mds_host $mds_dev "-y"
4675         run_e2fsck $ost_host $ost_dev "-y"
4676
4677         # mount the Lustre filesystem again
4678         setup
4679
4680         # check the files
4681         log "check files after shrinking the MDT and OST filesystems"
4682         for i in $(seq $((num_files + 10))); do
4683                 file=$MOUNT/$tdir/$tfile-$i
4684                 $CHECKSTAT -t file -s 1048576 $file ||
4685                         error "(11) checkstat $file failed"
4686         done
4687
4688         # unmount and reformat the Lustre filesystem
4689         cleanup || error "(12) cleanup Lustre filesystem failed"
4690         combined_mgs_mds || stop_mgs || error "(13) stop mgs failed"
4691         reformat || error "(14) reformat Lustre filesystem failed"
4692 }
4693 run_test 78 "run resize2fs on MDT and OST filesystems"
4694
4695 test_79() { # LU-4227
4696         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.59) ]] ||
4697                 { skip "Need MDS version at least 2.5.59"; return 0; }
4698
4699         local mdsdev1=$(mdsdevname 1)
4700         local mdsvdev1=$(mdsvdevname 1)
4701         local mdsdev2=$(mdsdevname 2)
4702         local mdsvdev2=$(mdsvdevname 2)
4703         local ostdev1=$(ostdevname 1)
4704         local ostvdev1=$(ostvdevname 1)
4705         local opts_mds1="$(mkfs_opts mds1 $mdsdev1) --reformat"
4706         local opts_mds2="$(mkfs_opts mds2 $mdsdev2) --reformat"
4707         local opts_ost1="$(mkfs_opts ost1 $ostdev1) --reformat"
4708         local mgsnode_opt
4709
4710         # remove --mgs/--mgsnode from mkfs.lustre options
4711         opts_mds1=$(echo $opts_mds1 | sed -e "s/--mgs//")
4712
4713         mgsnode_opt=$(echo $opts_mds2 |
4714                 awk '{ for ( i = 1; i < NF; i++ )
4715                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
4716         [ -n $mgsnode_opt ] &&
4717                 opts_mds2=$(echo $opts_mds2 | sed -e "s/$mgsnode_opt//")
4718
4719         mgsnode_opt=$(echo $opts_ost1 |
4720                 awk '{ for ( i = 1; i < NF; i++ )
4721                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
4722         [ -n $mgsnode_opt ] &&
4723                 opts_ost1=$(echo $opts_ost1 | sed -e "s/$mgsnode_opt//")
4724
4725         # -MGS, format a mdt without --mgs option
4726         add mds1 $opts_mds1 $mdsdev1 $mdsvdev1 &&
4727                 error "Must specify --mgs when formatting mdt combined with mgs"
4728
4729         # +MGS, format a mdt/ost without --mgsnode option
4730         add mds1 $(mkfs_opts mds1 $mdsdev1) --reformat $mdsdev1 $mdsvdev1 \
4731                 > /dev/null || error "start mds1 failed"
4732         add mds2 $opts_mds2 $mdsdev2 $mdsvdev2 &&
4733                 error "Must specify --mgsnode when formatting a mdt"
4734         add ost1 $opts_ost1 $ostdev1 $ostvdev2 &&
4735                 error "Must specify --mgsnode when formatting an ost"
4736
4737         return 0
4738 }
4739 run_test 79 "format MDT/OST without mgs option (should return errors)"
4740
4741 test_80() {
4742         start_mds
4743         start_ost
4744         uuid=$(do_facet ost1 lctl get_param -n mgc.*.uuid)
4745 #define OBD_FAIL_MGS_PAUSE_TARGET_CON       0x906
4746         do_facet ost1 "lctl set_param fail_val=10 fail_loc=0x906"
4747         do_facet mgs "lctl set_param fail_val=10 fail_loc=0x906"
4748         do_facet mgs "lctl set_param -n mgs/MGS/evict_client $uuid"
4749         sleep 30
4750         start_ost2
4751
4752         do_facet ost1 "lctl set_param fail_loc=0"
4753         stopall
4754 }
4755 run_test 80 "mgc import reconnect race"
4756
4757 if ! combined_mgs_mds ; then
4758         stop mgs
4759 fi
4760
4761 cleanup_gss
4762
4763 # restore the values of MDSSIZE and OSTSIZE
4764 MDSSIZE=$STORED_MDSSIZE
4765 OSTSIZE=$STORED_OSTSIZE
4766 reformat
4767
4768 complete $SECONDS
4769 exit_status