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