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