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