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