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