Whamcloud - gitweb
LU-1581 tests: restore CONF_SANITY_EXCEPT handling
[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
4 #   return codes, espcially when most of them are mapped to something
5 #   else anyway.  The combination of test number and return code
6 #   figure out what failed.
7
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11
12 # bug number for skipped test:
13 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT"
14 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15
16 if [ "$FAILURE_MODE" = "HARD" ]; then
17         CONFIG_EXCEPTIONS="24a " && \
18         echo "Except the tests: $CONFIG_EXCEPTIONS for FAILURE_MODE=$FAILURE_MODE, bug 23573" && \
19         ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
20 fi
21
22 # LU-2059
23 ALWAYS_EXCEPT="$ALWAYS_EXCEPT 5d 19b 21b 27a"
24
25
26 SRCDIR=`dirname $0`
27 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
28
29 PTLDEBUG=${PTLDEBUG:--1}
30 SAVE_PWD=$PWD
31 LUSTRE=${LUSTRE:-`dirname $0`/..}
32 RLUSTRE=${RLUSTRE:-$LUSTRE}
33 export MULTIOP=${MULTIOP:-multiop}
34
35 . $LUSTRE/tests/test-framework.sh
36 init_test_env $@
37
38 # use small MDS + OST size to speed formatting time
39 # do not use too small MDSSIZE/OSTSIZE, which affect the default jouranl size
40 MDSSIZE=200000
41 OSTSIZE=200000
42 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
43
44 if ! combined_mgs_mds; then
45     # bug number for skipped test:    23954
46     ALWAYS_EXCEPT="$ALWAYS_EXCEPT       24b"
47 fi
48
49 # STORED_MDSSIZE is used in test_18
50 if [ -n "$MDSSIZE" ]; then
51     STORED_MDSSIZE=$MDSSIZE
52 fi
53
54 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
55 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
56         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
57 fi
58
59 init_logging
60
61 #
62 require_dsh_mds || exit 0
63 require_dsh_ost || exit 0
64 #
65 [ "$SLOW" = "no" ] && EXCEPT_SLOW="30a 31 45"
66
67
68 assert_DIR
69
70 reformat() {
71         formatall
72 }
73
74 writeconf1() {
75         local facet=$1
76         local dev=$2
77
78         stop ${facet} -f
79         rm -f ${facet}active
80         # who knows if/where $TUNEFS is installed?  Better reformat if it fails...
81         do_facet ${facet} "$TUNEFS --quiet --writeconf $dev" ||
82                 { echo "tunefs failed, reformatting instead" && reformat_and_config && return 1; }
83         return 0
84 }
85
86 writeconf() {
87         # we need ldiskfs
88         load_modules
89         # if writeconf fails anywhere, we reformat everything
90         writeconf1 mds `mdsdevname 1` || return 0
91         writeconf1 ost1 `ostdevname 1` || return 0
92         writeconf1 ost2 `ostdevname 2` || return 0
93 }
94
95 gen_config() {
96         # The MGS must be started before the OSTs for a new fs, so start
97         # and stop to generate the startup logs.
98         start_mds
99         start_ost
100         wait_osc_import_state mds ost FULL
101         stop_ost
102         stop_mds
103 }
104
105 reformat_and_config() {
106         reformat
107         if ! combined_mgs_mds ; then
108                 start_mgs
109         fi
110         gen_config
111 }
112
113 start_mgs () {
114         echo "start mgs"
115         start mgs $MGSDEV $MGS_MOUNT_OPTS
116 }
117
118 start_mds() {
119         local facet=$SINGLEMDS
120         # we can not use MDSDEV1 here because SINGLEMDS could be set not to mds1 only
121         local num=$(echo $facet | tr -d "mds")
122         local dev=$(mdsdevname $num)
123         echo "start mds service on `facet_active_host $facet`"
124         start $facet ${dev} $MDS_MOUNT_OPTS $@ || return 94
125 }
126
127 start_mgsmds() {
128         if ! combined_mgs_mds ; then
129                 start_mgs
130         fi
131         start_mds $@
132 }
133
134 stop_mds() {
135         echo "stop mds service on `facet_active_host $SINGLEMDS`"
136         # These tests all use non-failover stop
137         stop $SINGLEMDS -f  || return 97
138 }
139
140 stop_mgs() {
141        echo "stop mgs service on `facet_active_host mgs`"
142        # These tests all use non-failover stop
143        stop mgs -f  || return 97
144 }
145
146 start_ost() {
147         echo "start ost1 service on `facet_active_host ost1`"
148         start ost1 `ostdevname 1` $OST_MOUNT_OPTS $@ || return 95
149 }
150
151 stop_ost() {
152         echo "stop ost1 service on `facet_active_host ost1`"
153         # These tests all use non-failover stop
154         stop ost1 -f  || return 98
155 }
156
157 start_ost2() {
158         echo "start ost2 service on `facet_active_host ost2`"
159         start ost2 `ostdevname 2` $OST_MOUNT_OPTS $@ || return 92
160 }
161
162 stop_ost2() {
163         echo "stop ost2 service on `facet_active_host ost2`"
164         # These tests all use non-failover stop
165         stop ost2 -f  || return 93
166 }
167
168 mount_client() {
169         local MOUNTPATH=$1
170         echo "mount $FSNAME on ${MOUNTPATH}....."
171         zconf_mount `hostname` $MOUNTPATH  || return 96
172 }
173
174 remount_client() {
175         local mountopt="-o remount,$1"
176         local MOUNTPATH=$2
177         echo "remount '$1' lustre on ${MOUNTPATH}....."
178         zconf_mount `hostname`  $MOUNTPATH "$mountopt"  || return 96
179 }
180
181 umount_client() {
182         local MOUNTPATH=$1
183         echo "umount lustre on ${MOUNTPATH}....."
184         zconf_umount `hostname` $MOUNTPATH || return 97
185 }
186
187 manual_umount_client(){
188         local rc
189         local FORCE=$1
190         echo "manual umount lustre on ${MOUNT}...."
191         do_facet client "umount -d ${FORCE} $MOUNT"
192         rc=$?
193         return $rc
194 }
195
196 setup() {
197         start_mds || error "MDT start failed"
198         start_ost || error "OST start failed"
199         mount_client $MOUNT || error "client start failed"
200         client_up || error "client_up failed"
201 }
202
203 setup_noconfig() {
204         if ! combined_mgs_mds ; then
205                 start_mgs
206         fi
207
208         start_mds
209         start_ost
210         mount_client $MOUNT
211 }
212
213 unload_modules_conf () {
214         if combined_mgs_mds || ! local_mode; then
215                 unload_modules || return 1
216         fi
217 }
218
219 cleanup_nocli() {
220         stop_ost || return 202
221         stop_mds || return 201
222         unload_modules_conf || return 203
223 }
224
225 cleanup() {
226         umount_client $MOUNT || return 200
227         cleanup_nocli || return $?
228 }
229
230 check_mount() {
231         do_facet client "cp /etc/passwd $DIR/a" || return 71
232         do_facet client "rm $DIR/a" || return 72
233         # make sure lustre is actually mounted (touch will block,
234         # but grep won't, so do it after)
235         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
236         echo "setup single mount lustre success"
237 }
238
239 check_mount2() {
240         do_facet client "touch $DIR/a" || return 71
241         do_facet client "rm $DIR/a" || return 72
242         do_facet client "touch $DIR2/a" || return 73
243         do_facet client "rm $DIR2/a" || return 74
244         echo "setup double mount lustre success"
245 }
246
247 build_test_filter
248
249 if [ "$ONLY" == "setup" ]; then
250         setup
251         exit
252 fi
253
254 if [ "$ONLY" == "cleanup" ]; then
255         cleanup
256         exit
257 fi
258
259 init_gss
260
261 #create single point mountpoint
262
263 reformat_and_config
264
265 test_0() {
266         setup
267         check_mount || return 41
268         cleanup || return $?
269 }
270 run_test 0 "single mount setup"
271
272 test_1() {
273         start_mds || error "MDT start failed"
274         start_ost
275         echo "start ost second time..."
276         start_ost && error "2nd OST start should fail"
277         mount_client $MOUNT || error "client start failed"
278         check_mount || return 42
279         cleanup || return $?
280 }
281 run_test 1 "start up ost twice (should return errors)"
282
283 test_2() {
284         start_mds
285         echo "start mds second time.."
286         start_mds && error "2nd MDT start should fail"
287         start_ost
288         mount_client $MOUNT
289         check_mount || return 43
290         cleanup || return $?
291 }
292 run_test 2 "start up mds twice (should return err)"
293
294 test_3() {
295         setup
296         #mount.lustre returns an error if already in mtab
297         mount_client $MOUNT && error "2nd client mount should fail"
298         check_mount || return 44
299         cleanup || return $?
300 }
301 run_test 3 "mount client twice (should return err)"
302
303 test_4() {
304         setup
305         touch $DIR/$tfile || return 85
306         stop_ost -f
307         cleanup
308         eno=$?
309         # ok for ost to fail shutdown
310         if [ 202 -ne $eno ]; then
311                 return $eno;
312         fi
313         return 0
314 }
315 run_test 4 "force cleanup ost, then cleanup"
316
317 test_5a() {     # was test_5
318         setup
319         touch $DIR/$tfile || return 1
320         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
321
322         stop_mds -f || return 2
323
324         # cleanup may return an error from the failed
325         # disconnects; for now I'll consider this successful
326         # if all the modules have unloaded.
327         umount -d $MOUNT &
328         UMOUNT_PID=$!
329         sleep 6
330         echo "killing umount"
331         kill -TERM $UMOUNT_PID
332         echo "waiting for umount to finish"
333         wait $UMOUNT_PID
334         if grep " $MOUNT " /proc/mounts; then
335                 echo "test 5: /proc/mounts after failed umount"
336                 umount $MOUNT &
337                 UMOUNT_PID=$!
338                 sleep 2
339                 echo "killing umount"
340                 kill -TERM $UMOUNT_PID
341                 echo "waiting for umount to finish"
342                 wait $UMOUNT_PID
343                 grep " $MOUNT " /proc/mounts && echo "test 5: /proc/mounts after second umount" && return 11
344         fi
345
346         manual_umount_client
347         # stop_mds is a no-op here, and should not fail
348         cleanup_nocli || return $?
349         # df may have lingering entry
350         manual_umount_client
351         # mtab may have lingering entry
352         local WAIT=0
353         local MAX_WAIT=20
354         local sleep=1
355         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
356                 sleep $sleep
357                 grep -q $MOUNT" " /etc/mtab || break
358                 echo "Waiting /etc/mtab updated ... "
359                 WAIT=$(( WAIT + sleep))
360         done
361         [ "$WAIT" -eq "$MAX_WAIT" ] && error "/etc/mtab is not updated in $WAIT secs"
362         echo "/etc/mtab updated in $WAIT secs"
363 }
364 run_test 5a "force cleanup mds, then cleanup"
365
366 cleanup_5b () {
367         trap 0
368         start_mgs
369 }
370
371 test_5b() {
372         grep " $MOUNT " /etc/mtab && \
373                 error false "unexpected entry in mtab before mount" && return 10
374
375         local rc=0
376         start_ost
377         if ! combined_mgs_mds ; then
378                 trap cleanup_5b EXIT ERR
379                 start_mds
380                 stop mgs
381         fi
382
383         [ -d $MOUNT ] || mkdir -p $MOUNT
384         mount_client $MOUNT && rc=1
385         grep " $MOUNT " /etc/mtab && \
386                 error "$MOUNT entry in mtab after failed mount" && rc=11
387         umount_client $MOUNT
388         # stop_mds is a no-op here, and should not fail
389         cleanup_nocli || rc=$?
390         if ! combined_mgs_mds ; then
391                 cleanup_5b
392         fi
393         return $rc
394 }
395 run_test 5b "Try to start a client with no MGS (should return errs)"
396
397 test_5c() {
398         grep " $MOUNT " /etc/mtab && \
399                 error false "unexpected entry in mtab before mount" && return 10
400
401         local rc=0
402         start_mds
403         start_ost
404         [ -d $MOUNT ] || mkdir -p $MOUNT
405         local oldfs="${FSNAME}"
406         FSNAME="wrong.${FSNAME}"
407         mount_client $MOUNT || :
408         FSNAME=${oldfs}
409         grep " $MOUNT " /etc/mtab && \
410                 error "$MOUNT entry in mtab after failed mount" && rc=11
411         umount_client $MOUNT
412         cleanup_nocli  || rc=$?
413         return $rc
414 }
415 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
416
417 test_5d() {
418         grep " $MOUNT " /etc/mtab && \
419                 error false "unexpected entry in mtab before mount" && return 10
420
421         local rc=0
422         start_ost
423         start_mds
424         stop_ost -f
425         mount_client $MOUNT || rc=1
426         cleanup  || rc=$?
427         grep " $MOUNT " /etc/mtab && \
428                 error "$MOUNT entry in mtab after unmount" && rc=11
429         return $rc
430 }
431 run_test 5d "mount with ost down"
432
433 test_5e() {
434         grep " $MOUNT " /etc/mtab && \
435                 error false "unexpected entry in mtab before mount" && return 10
436
437         local rc=0
438         start_mds
439         start_ost
440
441 #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
442         do_facet client "lctl set_param fail_loc=0x80000506"
443         mount_client $MOUNT || echo "mount failed (not fatal)"
444         cleanup  || rc=$?
445         grep " $MOUNT " /etc/mtab && \
446                 error "$MOUNT entry in mtab after unmount" && rc=11
447         return $rc
448 }
449 run_test 5e "delayed connect, don't crash (bug 10268)"
450
451 test_5f() {
452         if combined_mgs_mds ; then
453                 skip "combined mgs and mds"
454                 return 0
455         fi
456
457         grep " $MOUNT " /etc/mtab && \
458                 error false "unexpected entry in mtab before mount" && return 10
459
460         local rc=0
461         start_ost
462         [ -d $MOUNT ] || mkdir -p $MOUNT
463         mount_client $MOUNT &
464         local pid=$!
465         echo client_mount pid is $pid
466
467         sleep 5
468
469         if ! ps -f -p $pid >/dev/null; then
470                 wait $pid
471                 rc=$?
472                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
473                 error "mount returns $rc, expected to hang"
474                 rc=11
475                 cleanup || rc=$?
476                 return $rc
477         fi
478
479         # start mds
480         start_mds
481
482         # mount should succeed after start mds
483         wait $pid
484         rc=$?
485         [ $rc -eq 0 ] || error "mount returned $rc"
486         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
487         cleanup || return $?
488         return $rc
489 }
490 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
491
492 test_6() {
493         setup
494         manual_umount_client
495         mount_client ${MOUNT} || return 87
496         touch $DIR/a || return 86
497         cleanup  || return $?
498 }
499 run_test 6 "manual umount, then mount again"
500
501 test_7() {
502         setup
503         manual_umount_client
504         cleanup_nocli || return $?
505 }
506 run_test 7 "manual umount, then cleanup"
507
508 test_8() {
509         setup
510         mount_client $MOUNT2
511         check_mount2 || return 45
512         umount_client $MOUNT2
513         cleanup  || return $?
514 }
515 run_test 8 "double mount setup"
516
517 test_9() {
518         start_ost
519
520         do_facet ost1 lctl set_param debug=\'inode trace\' || return 1
521         do_facet ost1 lctl set_param subsystem_debug=\'mds ost\' || return 1
522
523         CHECK_PTLDEBUG="`do_facet ost1 lctl get_param -n debug`"
524         if [ "$CHECK_PTLDEBUG" ] && { \
525            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
526            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
527            echo "lnet.debug success"
528         else
529            echo "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
530            return 1
531         fi
532         CHECK_SUBSYS="`do_facet ost1 lctl get_param -n subsystem_debug`"
533         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
534            echo "lnet.subsystem_debug success"
535         else
536            echo "lnet.subsystem_debug: want 'mds ost', have '$CHECK_SUBSYS'"
537            return 1
538         fi
539         stop_ost || return $?
540 }
541 run_test 9 "test ptldebug and subsystem for mkfs"
542
543 is_blkdev () {
544         local facet=$1
545         local dev=$2
546         local size=${3:-""}
547
548         local rc=0
549         do_facet $facet "test -b $dev" || rc=1
550         if [[ "$size" ]]; then
551                 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k count=1 skip=$size 2>&1" |\
552                         awk '($3 == "in") { print $1 }')
553                 [[ $in  = "1+0" ]] || rc=1
554         fi
555         return $rc
556 }
557
558 #
559 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
560 # But with new MDS stack we don't care about the mode of local objects
561 # anymore, so this test is removed. See bug 22944 for more details.
562 #
563
564 test_17() {
565         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
566                 skip "Only applicable to ldiskfs-based MDTs"
567                 return
568         fi
569
570         setup
571         check_mount || return 41
572         cleanup || return $?
573
574         echo "Remove mds config log"
575         if ! combined_mgs_mds ; then
576                 stop mgs
577         fi
578
579         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' $MGSDEV || return \$?" || return $?
580
581         if ! combined_mgs_mds ; then
582                 start_mgs
583         fi
584
585         start_ost
586         start_mds && return 42
587         reformat_and_config
588 }
589 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
590
591 test_18() {
592         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
593                 skip "Only applicable to ldiskfs-based MDTs"
594                 return
595         fi
596
597         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
598
599         local MIN=2000000
600
601         local OK=
602         # check if current MDSSIZE is large enough
603         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE && \
604                 log "use MDSSIZE=$MDSSIZE"
605
606         # check if the global config has a large enough MDSSIZE
607         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] && [ $STORED_MDSSIZE -ge $MIN ] && \
608                 OK=1 && myMDSSIZE=$STORED_MDSSIZE && \
609                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
610
611         # check if the block device is large enough
612         [ -z "$OK" ] && $(is_blkdev $SINGLEMDS $MDSDEV $MIN) && OK=1 &&
613                 myMDSSIZE=$MIN && log "use device $MDSDEV with MIN=$MIN"
614
615         # check if a loopback device has enough space for fs metadata (5%)
616
617         if [ -z "$OK" ]; then
618                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
619                         awk '($1 != "Filesystem") {print $4}')
620                 ! [ -z "$SPACE" ]  &&  [ $SPACE -gt $((MIN / 20)) ] && \
621                         OK=1 && myMDSSIZE=$MIN && \
622                         log "use file $MDSDEV with MIN=$MIN"
623         fi
624
625         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
626
627
628         echo "mount mds with large journal..."
629
630         local OLD_MDSSIZE=$MDSSIZE
631         MDSSIZE=$myMDSSIZE
632
633         reformat_and_config
634         echo "mount lustre system..."
635         setup
636         check_mount || return 41
637
638         echo "check journal size..."
639         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
640         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
641                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
642         else
643                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
644         fi
645
646         cleanup || return $?
647
648         MDSSIZE=$OLD_MDSSIZE
649         reformat_and_config
650 }
651 run_test 18 "check mkfs creates large journals"
652
653 test_19a() {
654         start_mds || return 1
655         stop_mds -f || return 2
656 }
657 run_test 19a "start/stop MDS without OSTs"
658
659 test_19b() {
660         start_ost || return 1
661         stop_ost -f || return 2
662 }
663 run_test 19b "start/stop OSTs without MDS"
664
665 test_20() {
666         # first format the ost/mdt
667         start_mds
668         start_ost
669         mount_client $MOUNT
670         check_mount || return 43
671         rm -f $DIR/$tfile
672         remount_client ro $MOUNT || return 44
673         touch $DIR/$tfile && echo "$DIR/$tfile created incorrectly" && return 45
674         [ -e $DIR/$tfile ] && echo "$DIR/$tfile exists incorrectly" && return 46
675         remount_client rw $MOUNT || return 47
676         touch $DIR/$tfile
677         [ ! -f $DIR/$tfile ] && echo "$DIR/$tfile missing" && return 48
678         MCNT=`grep -c $MOUNT /etc/mtab`
679         [ "$MCNT" -ne 1 ] && echo "$MOUNT in /etc/mtab $MCNT times" && return 49
680         umount_client $MOUNT
681         stop_mds
682         stop_ost
683 }
684 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
685
686 test_21a() {
687         start_mds
688         start_ost
689         wait_osc_import_state mds ost FULL
690         stop_ost
691         stop_mds
692 }
693 run_test 21a "start mds before ost, stop ost first"
694
695 test_21b() {
696         start_ost
697         start_mds
698         wait_osc_import_state mds ost FULL
699         stop_mds
700         stop_ost
701 }
702 run_test 21b "start ost before mds, stop mds first"
703
704 test_21c() {
705         start_ost
706         start_mds
707         start_ost2
708         wait_osc_import_state mds ost2 FULL
709         stop_ost
710         stop_ost2
711         stop_mds
712         #writeconf to remove all ost2 traces for subsequent tests
713         writeconf
714 }
715 run_test 21c "start mds between two osts, stop mds last"
716
717 test_21d() {
718         if combined_mgs_mds ; then
719                 skip "need separate mgs device" && return 0
720         fi
721         stopall
722
723         reformat
724
725         start_mgs
726         start_ost
727         start_ost2
728         start_mds
729         wait_osc_import_state mds ost2 FULL
730
731         stop_ost
732         stop_ost2
733         stop_mds
734         stop_mgs
735         #writeconf to remove all ost2 traces for subsequent tests
736         writeconf
737         start_mgs
738 }
739 run_test 21d "start mgs then ost and then mds"
740
741 test_22() {
742         start_mds
743
744         echo Client mount with ost in logs, but none running
745         start_ost
746         # wait until mds connected to ost and open client connection
747         wait_osc_import_state mds ost FULL
748         stop_ost
749         mount_client $MOUNT
750         # check_mount will block trying to contact ost
751         mcreate $DIR/$tfile || return 40
752         rm -f $DIR/$tfile || return 42
753         umount_client $MOUNT
754         pass
755
756         echo Client mount with a running ost
757         start_ost
758         if $GSS; then
759                 # if gss enabled, wait full time to let connection from
760                 # mds to ost be established, due to the mismatch between
761                 # initial connect timeout and gss context negotiation timeout.
762                 # This perhaps could be remove after AT landed.
763                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
764                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
765         fi
766         mount_client $MOUNT
767         wait_osc_import_state mds ost FULL
768         wait_osc_import_state client ost FULL
769         check_mount || return 41
770         pass
771
772         cleanup
773 }
774 run_test 22 "start a client before osts (should return errs)"
775
776 test_23a() {    # was test_23
777         setup
778         # fail mds
779         stop $SINGLEMDS
780         # force down client so that recovering mds waits for reconnect
781         local running=$(grep -c $MOUNT /proc/mounts) || true
782         if [ $running -ne 0 ]; then
783                 echo "Stopping client $MOUNT (opts: -f)"
784                 umount -f $MOUNT
785         fi
786
787         # enter recovery on mds
788         start_mds
789         # try to start a new client
790         mount_client $MOUNT &
791         sleep 5
792         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
793         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
794         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
795         ps --ppid $MOUNT_PID
796         ps --ppid $MOUNT_LUSTRE_PID
797         echo "waiting for mount to finish"
798         ps -ef | grep mount
799         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
800         # SIGTERM works but it does not spread to offspring processses
801         kill -s TERM $MOUNT_PID
802         kill -s TERM $MOUNT_LUSTRE_PID
803         # we can not wait $MOUNT_PID because it is not a child of this shell
804         local PID1
805         local PID2
806         local WAIT=0
807         local MAX_WAIT=30
808         local sleep=1
809         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
810                 sleep $sleep
811                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
812                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
813                 echo PID1=$PID1
814                 echo PID2=$PID2
815                 [ -z "$PID1" -a -z "$PID2" ] && break
816                 echo "waiting for mount to finish ... "
817                 WAIT=$(( WAIT + sleep))
818         done
819         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
820                 error "MOUNT_PID $MOUNT_PID and "\
821                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
822                 ps -ef | grep mount
823         fi
824         stop_mds || error
825         stop_ost || error
826 }
827 run_test 23a "interrupt client during recovery mount delay"
828
829 umount_client $MOUNT
830 cleanup_nocli
831
832 test_23b() {    # was test_23
833         start_mds
834         start_ost
835         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
836         lctl set_param fail_loc=0x80000313
837         mount_client $MOUNT
838         cleanup
839 }
840 run_test 23b "Simulate -EINTR during mount"
841
842 fs2mds_HOST=$mds_HOST
843 fs2ost_HOST=$ost_HOST
844
845 MDSDEV1_2=$fs2mds_DEV
846 OSTDEV1_2=$fs2ost_DEV
847 OSTDEV2_2=$fs3ost_DEV
848
849 cleanup_24a() {
850         trap 0
851         echo "umount $MOUNT2 ..."
852         umount $MOUNT2 || true
853         echo "stopping fs2mds ..."
854         stop fs2mds -f || true
855         echo "stopping fs2ost ..."
856         stop fs2ost -f || true
857 }
858
859 test_24a() {
860         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
861
862         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
863                 is_blkdev $SINGLEMDS $MDSDEV && \
864                 skip_env "mixed loopback and real device not working" && return
865         fi
866
867         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
868
869         local fs2mdsdev=$(mdsdevname 1_2)
870         local fs2ostdev=$(ostdevname 1_2)
871         local fs2mdsvdev=$(mdsvdevname 1_2)
872         local fs2ostvdev=$(ostvdevname 1_2)
873
874         # test 8-char fsname as well
875         local FSNAME2=test1234
876         add fs2mds $(mkfs_opts mds1) --nomgs --mgsnode=$MGSNID \
877                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
878
879         add fs2ost $(mkfs_opts ost1) --fsname=${FSNAME2} --reformat \
880                 $fs2ostdev $fs2ostvdev || exit 10
881
882         setup
883         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
884         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
885         mkdir -p $MOUNT2
886         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
887         # 1 still works
888         check_mount || return 2
889         # files written on 1 should not show up on 2
890         cp /etc/passwd $DIR/$tfile
891         sleep 10
892         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
893         # 2 should work
894         sleep 5
895         cp /etc/passwd $MOUNT2/b || return 3
896         rm $MOUNT2/b || return 4
897         # 2 is actually mounted
898         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
899         # failover
900         facet_failover fs2mds
901         facet_failover fs2ost
902         df
903         umount_client $MOUNT
904         # the MDS must remain up until last MDT
905         stop_mds
906         MDS=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
907         [ -z "$MDS" ] && error "No MDT" && return 8
908         cleanup_24a
909         cleanup_nocli || return 6
910 }
911 run_test 24a "Multiple MDTs on a single node"
912
913 test_24b() {
914         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
915
916         if [ -z "$fs2mds_DEV" ]; then
917                 local dev=${SINGLEMDS}_dev
918                 local MDSDEV=${!dev}
919                 is_blkdev $SINGLEMDS $MDSDEV && \
920                 skip_env "mixed loopback and real device not working" && return
921         fi
922
923         local fs2mdsdev=$(mdsdevname 1_2)
924         local fs2mdsvdev=$(mdsvdevname 1_2)
925
926         add fs2mds $(mkfs_opts mds1) --mgs --fsname=${FSNAME}2 --reformat \
927                 $fs2mdsdev $fs2mdsvdev || exit 10
928         setup
929         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
930         cleanup || return 6
931 }
932 run_test 24b "Multiple MGSs on a single node (should return err)"
933
934 test_25() {
935         setup
936         check_mount || return 2
937         local MODULES=$($LCTL modules | awk '{ print $2 }')
938         rmmod $MODULES 2>/dev/null || true
939         cleanup || return 6
940 }
941 run_test 25 "Verify modules are referenced"
942
943 test_26() {
944     load_modules
945     # we need modules before mount for sysctl, so make sure...
946     do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
947 #define OBD_FAIL_MDS_FS_SETUP            0x135
948     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000135"
949     start_mds && echo MDS started && return 1
950     lctl get_param -n devices
951     DEVS=$(lctl get_param -n devices | egrep -v MG | wc -l)
952     [ $DEVS -gt 0 ] && return 2
953     # start mds to drop writeconf setting
954     start_mds || return 3
955     stop_mds || return 4
956     unload_modules_conf || return $?
957 }
958 run_test 26 "MDT startup failure cleans LOV (should return errs)"
959
960 set_and_check() {
961         local myfacet=$1
962         local TEST=$2
963         local PARAM=$3
964         local ORIG=$(do_facet $myfacet "$TEST")
965         if [ $# -gt 3 ]; then
966             local FINAL=$4
967         else
968             local -i FINAL
969             FINAL=$(($ORIG + 5))
970         fi
971         echo "Setting $PARAM from $ORIG to $FINAL"
972         do_facet mgs "$LCTL conf_param $PARAM='$FINAL'" || error conf_param failed
973
974         wait_update $(facet_host $myfacet) "$TEST" "$FINAL" || error check failed!
975 }
976
977 test_27a() {
978         start_ost || return 1
979         start_mds || return 2
980         echo "Requeue thread should have started: "
981         ps -e | grep ll_cfg_requeue
982         set_and_check ost1 "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" "$FSNAME-OST0000.ost.client_cache_seconds" || return 3
983         cleanup_nocli
984 }
985 run_test 27a "Reacquire MGS lock if OST started first"
986
987 test_27b() {
988         # FIXME. ~grev
989         setup
990         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }')
991
992         facet_failover $SINGLEMDS
993         set_and_check $SINGLEMDS "lctl get_param -n mdt.$device.identity_acquire_expire" "$device.mdt.identity_acquire_expire" || return 3
994         set_and_check client "lctl get_param -n mdc.$device-mdc-*.max_rpcs_in_flight" "$device.mdc.max_rpcs_in_flight" || return 4
995         check_mount
996         cleanup
997 }
998 run_test 27b "Reacquire MGS lock after failover"
999
1000 test_28() {
1001         setup
1002         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1003         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1004         ORIG=$($TEST)
1005         FINAL=$(($ORIG + 1))
1006         set_and_check client "$TEST" "$PARAM" $FINAL || return 3
1007         FINAL=$(($FINAL + 1))
1008         set_and_check client "$TEST" "$PARAM" $FINAL || return 4
1009         umount_client $MOUNT || return 200
1010         mount_client $MOUNT
1011         RESULT=$($TEST)
1012         if [ $RESULT -ne $FINAL ]; then
1013             echo "New config not seen: wanted $FINAL got $RESULT"
1014             return 4
1015         else
1016             echo "New config success: got $RESULT"
1017         fi
1018         set_and_check client "$TEST" "$PARAM" $ORIG || return 5
1019         cleanup
1020 }
1021 run_test 28 "permanent parameter setting"
1022
1023 test_29() {
1024         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
1025         setup > /dev/null 2>&1
1026         start_ost2
1027         sleep 10
1028
1029         local PARAM="$FSNAME-OST0001.osc.active"
1030         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
1031         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1032
1033         ACTV=$(lctl get_param -n $PROC_ACT)
1034         DEAC=$((1 - $ACTV))
1035         set_and_check client "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
1036         # also check ost_server_uuid status
1037         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
1038         if [ -z "$RESULT" ]; then
1039             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
1040             return 3
1041         else
1042             echo "Live client success: got $RESULT"
1043         fi
1044
1045         # check MDT too
1046         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0001)
1047         mdtosc=${mdtosc/-MDT*/-MDT\*}
1048         local MPROC="osc.$mdtosc.active"
1049         local MAX=30
1050         local WAIT=0
1051         while [ 1 ]; do
1052             sleep 5
1053             RESULT=`do_facet $SINGLEMDS " lctl get_param -n $MPROC"`
1054             [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
1055             if [ $RESULT -eq $DEAC ]; then
1056                 echo "MDT deactivated also after $WAIT sec (got $RESULT)"
1057                 break
1058             fi
1059             WAIT=$((WAIT + 5))
1060             if [ $WAIT -eq $MAX ]; then
1061                 echo "MDT not deactivated: wanted $DEAC got $RESULT"
1062                 return 4
1063             fi
1064             echo "Waiting $(($MAX - $WAIT)) secs for MDT deactivated"
1065         done
1066
1067         # test new client starts deactivated
1068         umount_client $MOUNT || return 200
1069         mount_client $MOUNT
1070         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1071         if [ -z "$RESULT" ]; then
1072             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
1073             return 5
1074         else
1075             echo "New client success: got $RESULT"
1076         fi
1077
1078         # make sure it reactivates
1079         set_and_check client "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
1080
1081         umount_client $MOUNT
1082         stop_ost2
1083         cleanup_nocli
1084         #writeconf to remove all ost2 traces for subsequent tests
1085         writeconf
1086 }
1087 run_test 29 "permanently remove an OST"
1088
1089 test_30a() {
1090         setup
1091
1092         echo Big config llog
1093         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1094         ORIG=$($TEST)
1095         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1096         for i in ${LIST[@]}; do
1097             set_and_check client "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
1098         done
1099         # make sure client restart still works
1100         umount_client $MOUNT
1101         mount_client $MOUNT || return 4
1102         [ "$($TEST)" -ne "$i" ] && error "Param didn't stick across restart $($TEST) != $i"
1103         pass
1104
1105         echo Erase parameter setting
1106         do_facet mgs "$LCTL conf_param -d $FSNAME.llite.max_read_ahead_whole_mb" || return 6
1107         umount_client $MOUNT
1108         mount_client $MOUNT || return 6
1109         FINAL=$($TEST)
1110         echo "deleted (default) value=$FINAL, orig=$ORIG"
1111         # assumes this parameter started at the default value
1112         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1113
1114         cleanup
1115 }
1116 run_test 30a "Big config llog and conf_param deletion"
1117
1118 test_30b() {
1119         setup
1120
1121         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1122         # numerical part of it. Hopefully that's not already a failover address for
1123         # the server.
1124         OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
1125         ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1126         NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1127         NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1128         echo "Using fake nid $NEW"
1129
1130         TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1131         set_and_check client "$TEST" "$FSNAME-OST0000.failover.node" $NEW || error "didn't add failover nid $NEW"
1132         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1133         echo $NIDS
1134         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1135         echo "should have 2 failover nids: $NIDCOUNT"
1136         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1137         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" || error "conf_param delete failed"
1138         umount_client $MOUNT
1139         mount_client $MOUNT || return 3
1140
1141         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1142         echo $NIDS
1143         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 1))
1144         echo "only 1 final nid should remain: $NIDCOUNT"
1145         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1146
1147         cleanup
1148 }
1149 run_test 30b "Remove failover nids"
1150
1151 test_31() { # bug 10734
1152         # ipaddr must not exist
1153         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
1154         cleanup
1155 }
1156 run_test 31 "Connect to non-existent node (shouldn't crash)"
1157
1158 # Use these start32/stop32 fn instead of t-f start/stop fn,
1159 # for local devices, to skip global facet vars init
1160 stop32 () {
1161         local facet=$1
1162         shift
1163         echo "Stopping local ${MOUNT%/*}/${facet} (opts:$@)"
1164         umount -d $@ ${MOUNT%/*}/${facet}
1165         losetup -a
1166 }
1167
1168 start32 () {
1169         local facet=$1
1170         shift
1171         local device=$1
1172         shift
1173         mkdir -p ${MOUNT%/*}/${facet}
1174
1175         echo "Starting local ${facet}: $@ $device ${MOUNT%/*}/${facet}"
1176         mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
1177         local RC=$?
1178         if [ $RC -ne 0 ]; then
1179                 echo "mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}"
1180                 echo "Start of ${device} of local ${facet} failed ${RC}"
1181         fi
1182         losetup -a
1183         return $RC
1184 }
1185
1186 cleanup_nocli32 () {
1187         stop32 mds1 -f
1188         stop32 ost1 -f
1189         wait_exit_ST client
1190 }
1191
1192 cleanup_32() {
1193         trap 0
1194         echo "Cleanup test_32 umount $MOUNT ..."
1195         umount -f $MOUNT || true
1196         echo "Cleanup local mds ost1 ..."
1197         cleanup_nocli32
1198         combined_mgs_mds || start_mgs
1199         unload_modules_conf
1200 }
1201
1202 test_32a() {
1203         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
1204                 skip "Only applicable to ldiskfs-based MDTs"
1205                 return
1206         fi
1207
1208         client_only && skip "client only testing" && return 0
1209         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
1210         [ -z "$TUNEFS" ] && skip_env "No tunefs" && return 0
1211
1212         local DISK1_8=$LUSTRE/tests/disk1_8.tar.bz2
1213         [ ! -r $DISK1_8 ] && skip_env "Cannot find $DISK1_8" && return 0
1214         local tmpdir=$TMP/conf32a
1215         mkdir -p $tmpdir
1216         tar xjvf $DISK1_8 -C $tmpdir || \
1217                 { skip_env "Cannot untar $DISK1_8" && return 0; }
1218
1219         load_modules
1220         $LCTL set_param debug="$PTLDEBUG"
1221
1222         $TUNEFS $tmpdir/mds || error "tunefs failed"
1223
1224         combined_mgs_mds || stop mgs
1225
1226         # nids are wrong, so client wont work, but server should start
1227         start32 mds1 $tmpdir/mds "-o loop,exclude=lustre-OST0000" && \
1228                 trap cleanup_32 EXIT INT || return 3
1229
1230         local UUID=$($LCTL get_param -n mdt.lustre-MDT0000.uuid)
1231         echo MDS uuid $UUID
1232         [ "$UUID" == "lustre-MDT0000_UUID" ] || error "UUID is wrong: $UUID"
1233
1234         $TUNEFS --mgsnode=$HOSTNAME $tmpdir/ost1 || error "tunefs failed"
1235         start32 ost1 $tmpdir/ost1 "-o loop" || return 5
1236         UUID=$($LCTL get_param -n obdfilter.lustre-OST0000.uuid)
1237         echo OST uuid $UUID
1238         [ "$UUID" == "lustre-OST0000_UUID" ] || error "UUID is wrong: $UUID"
1239
1240         local NID=$($LCTL list_nids | head -1)
1241
1242         echo "OSC changes should succeed:"
1243         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 || return 7
1244         $LCTL conf_param lustre-OST0000.failover.node=$NID || return 8
1245         echo "ok."
1246
1247         echo "MDC changes should succeed:"
1248         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1249         $LCTL conf_param lustre-MDT0000.failover.node=$NID || return 10
1250         echo "ok."
1251
1252         echo "LOV changes should succeed:"
1253         $LCTL pool_new lustre.interop || return 11
1254         $LCTL conf_param lustre-MDT0000.lov.stripesize=4M || return 12
1255         echo "ok."
1256
1257         cleanup_32
1258
1259         # mount a second time to make sure we didnt leave upgrade flag on
1260         load_modules
1261         $TUNEFS --dryrun $tmpdir/mds || error "tunefs failed"
1262
1263         combined_mgs_mds || stop mgs
1264
1265         start32 mds1 $tmpdir/mds "-o loop,exclude=lustre-OST0000" && \
1266                 trap cleanup_32 EXIT INT || return 12
1267
1268         cleanup_32
1269
1270         rm -rf $tmpdir || true  # true is only for TMP on NFS
1271 }
1272 run_test 32a "Upgrade from 1.8 (not live)"
1273
1274 test_32b() {
1275         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
1276                 skip "Only applicable to ldiskfs-based MDTs"
1277                 return
1278         fi
1279
1280         client_only && skip "client only testing" && return 0
1281         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
1282         [ -z "$TUNEFS" ] && skip_env "No tunefs" && return
1283
1284         local DISK1_8=$LUSTRE/tests/disk1_8.tar.bz2
1285         [ ! -r $DISK1_8 ] && skip_env "Cannot find $DISK1_8" && return 0
1286         local tmpdir=$TMP/conf32b
1287         mkdir -p $tmpdir
1288         tar xjvf $DISK1_8 -C $tmpdir || \
1289                 { skip_env "Cannot untar $DISK1_8" && return ; }
1290
1291         load_modules
1292         $LCTL set_param debug="+config"
1293         local NEWNAME=lustre
1294
1295         # writeconf will cause servers to register with their current nids
1296         $TUNEFS --writeconf --erase-params \
1297         --param mdt.identity_upcall=$L_GETIDENTITY \
1298         --fsname=$NEWNAME $tmpdir/mds || error "tunefs failed"
1299         combined_mgs_mds || stop mgs
1300
1301         start32 mds1 $tmpdir/mds "-o loop" && \
1302                 trap cleanup_32 EXIT INT || return 3
1303
1304         local UUID=$($LCTL get_param -n mdt.${NEWNAME}-MDT0000.uuid)
1305         echo MDS uuid $UUID
1306         [ "$UUID" == "${NEWNAME}-MDT0000_UUID" ] || error "UUID is wrong: $UUID"
1307
1308         $TUNEFS  --writeconf --erase-params \
1309         --mgsnode=$HOSTNAME --fsname=$NEWNAME $tmpdir/ost1 ||\
1310             error "tunefs failed"
1311         start32 ost1 $tmpdir/ost1 "-o loop" || return 5
1312         UUID=$($LCTL get_param -n obdfilter.${NEWNAME}-OST0000.uuid)
1313         echo OST uuid $UUID
1314         [ "$UUID" == "${NEWNAME}-OST0000_UUID" ] || error "UUID is wrong: $UUID"
1315
1316         local NID=$($LCTL list_nids | head -1)
1317
1318         echo "OSC changes should succeed:"
1319         $LCTL conf_param ${NEWNAME}-OST0000.osc.max_dirty_mb=15 || return 7
1320         $LCTL conf_param ${NEWNAME}-OST0000.failover.node=$NID || return 8
1321         echo "ok."
1322
1323         echo "MDC changes should succeed:"
1324         $LCTL conf_param ${NEWNAME}-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1325         $LCTL conf_param ${NEWNAME}-MDT0000.failover.node=$NID || return 10
1326         echo "ok."
1327
1328         echo "LOV changes should succeed:"
1329         $LCTL pool_new ${NEWNAME}.interop || return 11
1330         $LCTL conf_param ${NEWNAME}-MDT0000.lov.stripesize=4M || return 12
1331         echo "ok."
1332
1333         # MDT and OST should have registered with new nids, so we should have
1334         # a fully-functioning client
1335         echo "Check client and old fs contents"
1336
1337         local device=`h2$NETTYPE $HOSTNAME`:/$NEWNAME
1338         echo "Starting local client: $HOSTNAME: $device $MOUNT"
1339         mount -t lustre $device $MOUNT || return 1
1340
1341         local old=$($LCTL get_param -n mdc.*.max_rpcs_in_flight)
1342         local new=$((old + 5))
1343         $LCTL conf_param ${NEWNAME}-MDT0000.mdc.max_rpcs_in_flight=$new
1344         wait_update $HOSTNAME "$LCTL get_param -n mdc.*.max_rpcs_in_flight" $new || return 11
1345
1346         [ "$(cksum $MOUNT/passwd | cut -d' ' -f 1,2)" == "94306271 1478" ] || return 12
1347         echo "ok."
1348
1349         cleanup_32
1350
1351         rm -rf $tmpdir || true  # true is only for TMP on NFS
1352 }
1353 run_test 32b "Upgrade from 1.8 with writeconf"
1354
1355 test_33a() { # bug 12333, was test_33
1356         local rc=0
1357         local FSNAME2=test-123
1358         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1359         local mkfsoptions
1360
1361         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1362
1363         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1364                 local dev=${SINGLEMDS}_dev
1365                 local MDSDEV=${!dev}
1366                 is_blkdev $SINGLEMDS $MDSDEV && \
1367                 skip_env "mixed loopback and real device not working" && return
1368         fi
1369
1370         local fs2mdsdev=$(mdsdevname 1_2)
1371         local fs2ostdev=$(ostdevname 1_2)
1372         local fs2mdsvdev=$(mdsvdevname 1_2)
1373         local fs2ostvdev=$(ostvdevname 1_2)
1374
1375         if [ $(facet_fstype mds1) == ldiskfs ]; then
1376                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
1377         fi
1378
1379         add fs2mds $(mkfs_opts mds1) --fsname=${FSNAME2} --reformat \
1380                 $mkfsoptions $fs2mdsdev $fs2mdsvdev || exit 10
1381         add fs2ost $(mkfs_opts ost1) --mgsnode=$MGSNID --fsname=${FSNAME2} \
1382                 --index=8191 --reformat $fs2ostdev $fs2ostvdev || exit 10
1383
1384         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1385         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1386         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1387         mkdir -p $MOUNT2
1388         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1389         echo "ok."
1390
1391         cp /etc/hosts $MOUNT2/ || rc=3
1392         $LFS getstripe $MOUNT2/hosts
1393
1394         umount -d $MOUNT2
1395         stop fs2ost -f
1396         stop fs2mds -f
1397         cleanup_nocli || rc=6
1398         return $rc
1399 }
1400 run_test 33a "Mount ost with a large index number"
1401
1402 test_33b() {    # was test_34
1403         setup
1404
1405         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1406         # Drop lock cancelation reply during umount
1407         #define OBD_FAIL_LDLM_CANCEL             0x304
1408         do_facet client lctl set_param fail_loc=0x80000304
1409         #lctl set_param debug=-1
1410         umount_client $MOUNT
1411         cleanup
1412 }
1413 run_test 33b "Drop cancel during umount"
1414
1415 test_34a() {
1416         setup
1417         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
1418         manual_umount_client
1419         rc=$?
1420         do_facet client killall -USR1 multiop
1421         if [ $rc -eq 0 ]; then
1422                 error "umount not fail!"
1423         fi
1424         sleep 1
1425         cleanup
1426 }
1427 run_test 34a "umount with opened file should be fail"
1428
1429
1430 test_34b() {
1431         setup
1432         touch $DIR/$tfile || return 1
1433         stop_mds --force || return 2
1434
1435         manual_umount_client --force
1436         rc=$?
1437         if [ $rc -ne 0 ]; then
1438                 error "mtab after failed umount - rc $rc"
1439         fi
1440
1441         cleanup
1442         return 0
1443 }
1444 run_test 34b "force umount with failed mds should be normal"
1445
1446 test_34c() {
1447         setup
1448         touch $DIR/$tfile || return 1
1449         stop_ost --force || return 2
1450
1451         manual_umount_client --force
1452         rc=$?
1453         if [ $rc -ne 0 ]; then
1454                 error "mtab after failed umount - rc $rc"
1455         fi
1456
1457         cleanup
1458         return 0
1459 }
1460 run_test 34c "force umount with failed ost should be normal"
1461
1462 test_35a() { # bug 12459
1463         setup
1464
1465         DBG_SAVE="`lctl get_param -n debug`"
1466         lctl set_param debug="ha"
1467
1468         log "Set up a fake failnode for the MDS"
1469         FAKENID="127.0.0.2"
1470         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1471         do_facet mgs $LCTL conf_param ${device}.failover.node=$FAKENID || return 4
1472
1473         log "Wait for RECONNECT_INTERVAL seconds (10s)"
1474         sleep 10
1475
1476         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
1477         $LCTL clear
1478         log "$MSG"
1479         log "Stopping the MDT:"
1480         stop_mds || return 5
1481
1482         df $MOUNT > /dev/null 2>&1 &
1483         DFPID=$!
1484         log "Restarting the MDT:"
1485         start_mds || return 6
1486         log "Wait for df ($DFPID) ... "
1487         wait $DFPID
1488         log "done"
1489         lctl set_param debug="$DBG_SAVE"
1490
1491         # retrieve from the log the first server that the client tried to
1492         # contact after the connection loss
1493         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1494         NEXTCONN=`awk "/${MSG}/ {start = 1;}
1495                        /import_select_connection.*$device-mdc.* using connection/ {
1496                                 if (start) {
1497                                         if (\\\$NF ~ /$FAKENID/)
1498                                                 print \\\$NF;
1499                                         else
1500                                                 print 0;
1501                                         exit;
1502                                 }
1503                        }" $TMP/lustre-log-$TESTNAME.log`
1504         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
1505         cleanup
1506         # remove nid settings
1507         writeconf
1508 }
1509 run_test 35a "Reconnect to the last active server first"
1510
1511 test_35b() { # bug 18674
1512         remote_mds || { skip "local MDS" && return 0; }
1513         setup
1514
1515         debugsave
1516         $LCTL set_param debug="ha"
1517         $LCTL clear
1518         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
1519         log "$MSG"
1520
1521         log "Set up a fake failnode for the MDS"
1522         FAKENID="127.0.0.2"
1523         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" | \
1524                         awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1525         do_facet mgs "$LCTL conf_param ${device}.failover.node=$FAKENID" || \
1526                 return 1
1527
1528         local at_max_saved=0
1529         # adaptive timeouts may prevent seeing the issue
1530         if at_is_enabled; then
1531                 at_max_saved=$(at_max_get mds)
1532                 at_max_set 0 mds client
1533         fi
1534
1535         mkdir -p $MOUNT/$tdir
1536
1537         log "Injecting EBUSY on MDS"
1538         # Setting OBD_FAIL_MDS_RESEND=0x136
1539         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" || return 2
1540
1541         $LCTL set_param mdc.${FSNAME}*.stats=clear
1542
1543         log "Creating a test file and stat it"
1544         touch $MOUNT/$tdir/$tfile
1545         stat $MOUNT/$tdir/$tfile
1546
1547         log "Stop injecting EBUSY on MDS"
1548         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" || return 3
1549         rm -f $MOUNT/$tdir/$tfile
1550
1551         log "done"
1552         # restore adaptive timeout
1553         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
1554
1555         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1556
1557         CONNCNT=`$LCTL get_param mdc.${FSNAME}*.stats | awk '/mds_connect/{print $2}'`
1558
1559         # retrieve from the log if the client has ever tried to
1560         # contact the fake server after the loss of connection
1561         FAILCONN=`awk "BEGIN {ret = 0;}
1562                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
1563                                 ret = 1;
1564                                 if (\\\$NF ~ /$FAKENID/) {
1565                                         ret = 2;
1566                                         exit;
1567                                 }
1568                        }
1569                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
1570
1571         [ "$FAILCONN" == "0" ] && \
1572                 log "ERROR: The client reconnection has not been triggered" && \
1573                 return 4
1574         [ "$FAILCONN" == "2" ] && \
1575                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
1576                 return 5
1577
1578         # LU-290
1579         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
1580         # Reconnects are supposed to be rate limited to one every 5s
1581         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] && \
1582                 log "ERROR: Too many reconnects $CONNCNT" && \
1583                 return 6
1584
1585         cleanup
1586         # remove nid settings
1587         writeconf
1588 }
1589 run_test 35b "Continue reconnection retries, if the active server is busy"
1590
1591 test_36() { # 12743
1592         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
1593
1594         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
1595                 { skip "remote OST" && return 0; }
1596
1597         local rc=0
1598         local FSNAME2=test1234
1599         local fs3ost_HOST=$ost_HOST
1600         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1601
1602         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
1603
1604         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
1605                 is_blkdev $SINGLEMDS $MDSDEV && \
1606                 skip_env "mixed loopback and real device not working" && return
1607         fi
1608
1609         local fs2mdsdev=$(mdsdevname 1_2)
1610         local fs2ostdev=$(ostdevname 1_2)
1611         local fs3ostdev=$(ostdevname 2_2)
1612         local fs2mdsvdev=$(mdsvdevname 1_2)
1613         local fs2ostvdev=$(ostvdevname 1_2)
1614         local fs3ostvdev=$(ostvdevname 2_2)
1615
1616         add fs2mds $(mkfs_opts mds1) --fsname=${FSNAME2} --reformat \
1617                 $fs2mdsdev $fs2mdsvdev || exit 10
1618         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
1619         #     different one than the default value here.
1620         add fs2ost $(mkfs_opts ost1) --mgsnode=$MGSNID --fsname=${FSNAME2} \
1621                 --reformat $fs2ostdev $fs2ostvdev || exit 10
1622         add fs3ost $(mkfs_opts ost1) --mgsnode=$MGSNID --fsname=${FSNAME2} \
1623                 --reformat $fs3ostdev $fs3ostvdev || exit 10
1624
1625         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
1626         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1627         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
1628         mkdir -p $MOUNT2
1629         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
1630
1631         sleep 5 # until 11778 fixed
1632
1633         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
1634
1635         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1636         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
1637         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
1638         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
1639         DFTOTAL=`echo $STRING | cut -d, -f1`
1640         DFUSED=`echo $STRING  | cut -d, -f2`
1641         DFAVAIL=`echo $STRING | cut -d, -f3`
1642         DFFREE=$(($DFTOTAL - $DFUSED))
1643
1644         ALLOWANCE=$((64 * $OSTCOUNT))
1645
1646         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
1647            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
1648                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
1649                 rc=1
1650         fi
1651         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
1652            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
1653                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
1654                 rc=2
1655         fi
1656         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
1657            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
1658                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
1659                 rc=3
1660        fi
1661
1662         umount -d $MOUNT2
1663         stop fs3ost -f || return 200
1664         stop fs2ost -f || return 201
1665         stop fs2mds -f || return 202
1666         unload_modules_conf || return 203
1667         return $rc
1668 }
1669 run_test 36 "df report consistency on OSTs with different block size"
1670
1671 test_37() {
1672         local mntpt=$(facet_mntpt $SINGLEMDS)
1673         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
1674         local mdsdev_sym="$TMP/sym_mdt.img"
1675         local opts=$MDS_MOUNT_OPTS
1676         local rc=0
1677
1678         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
1679                 skip "Currently only applicable to ldiskfs-based MDTs"
1680                 return
1681         fi
1682
1683         echo "MDS :     $mdsdev"
1684         echo "SYMLINK : $mdsdev_sym"
1685         do_facet $SINGLEMDS rm -f $mdsdev_sym
1686
1687         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
1688
1689         echo "mount symlink device - $mdsdev_sym"
1690
1691         if ! do_facet $SINGLEMDS test -b $mdsdev; then
1692                 opts=$(csa_add "$opts" -o loop)
1693         fi
1694         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
1695                 $mdsdev_sym $mntpt 2>&1)
1696         rc=${PIPESTATUS[0]}
1697
1698         echo mount_op=$mount_op
1699
1700         do_facet $SINGLEMDS "umount -d $mntpt && rm -f $mdsdev_sym"
1701
1702         if $(echo $mount_op | grep -q "unable to set tunable"); then
1703                 error "set tunables failed for symlink device"
1704         fi
1705
1706         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
1707
1708         return 0
1709 }
1710 run_test 37 "verify set tunables works for symlink device"
1711
1712 test_38() { # bug 14222
1713         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
1714                 skip "Only applicable to ldiskfs-based MDTs"
1715                 return
1716         fi
1717
1718         setup
1719         # like runtests
1720         COUNT=10
1721         SRC="/etc /bin"
1722         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
1723         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
1724         mkdir -p $DIR/$tdir
1725         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
1726                 error "copying $SRC to $DIR/$tdir"
1727         sync
1728         umount_client $MOUNT
1729         stop_mds
1730         log "rename lov_objid file on MDS"
1731         rm -f $TMP/lov_objid.orig
1732
1733         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1734         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
1735         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1736
1737         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.orig"
1738         # check create in mds_lov_connect
1739         start_mds
1740         mount_client $MOUNT
1741         for f in $FILES; do
1742                 [ $V ] && log "verifying $DIR/$tdir/$f"
1743                 diff -q $f $DIR/$tdir/$f || ERROR=y
1744         done
1745         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
1746         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new"
1747         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
1748
1749         # check it's updates in sync
1750         umount_client $MOUNT
1751         stop_mds
1752
1753         do_facet $SINGLEMDS dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
1754         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1755         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
1756
1757         start_mds
1758         mount_client $MOUNT
1759         for f in $FILES; do
1760                 [ $V ] && log "verifying $DIR/$tdir/$f"
1761                 diff -q $f $DIR/$tdir/$f || ERROR=y
1762         done
1763         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
1764         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new1"
1765         umount_client $MOUNT
1766         stop_mds
1767         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
1768
1769         log "files compared the same"
1770         cleanup
1771 }
1772 run_test 38 "MDS recreates missing lov_objid file from OST data"
1773
1774 test_39() {
1775         PTLDEBUG=+malloc
1776         setup
1777         cleanup
1778         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
1779                 error "memory leak detected" || true
1780 }
1781 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
1782
1783 test_40() { # bug 15759
1784         start_ost
1785         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
1786         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
1787         start_mds
1788         cleanup
1789 }
1790 run_test 40 "race during service thread startup"
1791
1792 test_41a() { #bug 14134
1793         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
1794            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
1795                 skip "Loop devices does not work with nosvc option"
1796                 return
1797         fi
1798
1799         local rc
1800         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1801
1802         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
1803         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
1804         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
1805         mkdir -p $MOUNT
1806         mount_client $MOUNT || return 1
1807         sleep 5
1808
1809         echo "blah blah" > $MOUNT/$tfile
1810         cat $MOUNT/$tfile
1811
1812         umount_client $MOUNT
1813         stop ost1 -f || return 201
1814         stop_mds -f || return 202
1815         stop_mds -f || return 203
1816         unload_modules_conf || return 204
1817         return $rc
1818 }
1819 run_test 41a "mount mds with --nosvc and --nomgs"
1820
1821 test_41b() {
1822         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
1823            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
1824                 skip "Loop devices does not work with nosvc option"
1825                 return
1826         fi
1827
1828         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
1829
1830         stopall
1831         reformat
1832         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1833
1834         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
1835         start_ost
1836         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
1837         mkdir -p $MOUNT
1838         mount_client $MOUNT || return 1
1839         sleep 5
1840
1841         echo "blah blah" > $MOUNT/$tfile
1842         cat $MOUNT/$tfile || return 200
1843
1844         umount_client $MOUNT
1845         stop_ost || return 201
1846         stop_mds -f || return 202
1847         stop_mds -f || return 203
1848
1849 }
1850 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
1851
1852 test_42() { #bug 14693
1853         setup
1854         check_mount || return 2
1855         do_facet mgs $LCTL conf_param lustre.llite.some_wrong_param=10
1856         umount_client $MOUNT
1857         mount_client $MOUNT || return 1
1858         cleanup
1859         return 0
1860 }
1861 run_test 42 "invalid config param should not prevent client from mounting"
1862
1863 test_43() {
1864     [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
1865     setup
1866     chmod ugo+x $DIR || error "chmod 0 failed"
1867     set_and_check mds                                        \
1868         "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"  \
1869         "$FSNAME.mdt.root_squash"                            \
1870         "0:0"
1871     set_and_check mds                                        \
1872        "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids" \
1873        "$FSNAME.mdt.nosquash_nids"                           \
1874        "NONE"
1875
1876     #
1877     # create set of test files
1878     #
1879     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
1880     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
1881     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
1882
1883     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
1884     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
1885
1886     mkdir $DIR/$tdir-rootdir -p       || error "mkdir failed"
1887     chmod go-rwx $DIR/$tdir-rootdir   || error "chmod 3 failed"
1888     touch $DIR/$tdir-rootdir/tfile-1  || error "touch failed"
1889
1890     #
1891     # check root_squash:
1892     #   set root squash UID:GID to RUNAS_ID
1893     #   root should be able to access only files owned by RUNAS_ID
1894     #
1895     set_and_check mds                                        \
1896        "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"   \
1897        "$FSNAME.mdt.root_squash"                             \
1898        "$RUNAS_ID:$RUNAS_ID"
1899
1900     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
1901     dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
1902         error "$ST: root read permission is denied"
1903     echo "$ST: root read permission is granted - ok"
1904
1905     echo "444" | \
1906     dd conv=notrunc if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
1907         error "$ST: root write permission is denied"
1908     echo "$ST: root write permission is granted - ok"
1909
1910     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
1911     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
1912         error "$ST: root read permission is granted"
1913     echo "$ST: root read permission is denied - ok"
1914
1915     echo "555" | \
1916     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
1917         error "$ST: root write permission is granted"
1918     echo "$ST: root write permission is denied - ok"
1919
1920     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
1921     rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null && \
1922         error "$ST: root unlink permission is granted"
1923     echo "$ST: root unlink permission is denied - ok"
1924
1925     touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null && \
1926         error "$ST: root create permission is granted"
1927     echo "$ST: root create permission is denied - ok"
1928
1929     #
1930     # check nosquash_nids:
1931     #   put client's NID into nosquash_nids list,
1932     #   root should be able to access root file after that
1933     #
1934     local NIDLIST=$(lctl list_nids all | tr '\n' ' ')
1935     NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
1936     NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
1937     set_and_check mds                                        \
1938        "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids" \
1939        "$FSNAME-MDTall.mdt.nosquash_nids"                    \
1940        "$NIDLIST"
1941
1942     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
1943     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
1944         error "$ST: root read permission is denied"
1945     echo "$ST: root read permission is granted - ok"
1946
1947     echo "666" | \
1948     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
1949         error "$ST: root write permission is denied"
1950     echo "$ST: root write permission is granted - ok"
1951
1952     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
1953     rm $DIR/$tdir-rootdir/tfile-1 || \
1954         error "$ST: root unlink permission is denied"
1955     echo "$ST: root unlink permission is granted - ok"
1956     touch $DIR/$tdir-rootdir/tfile-2 || \
1957         error "$ST: root create permission is denied"
1958     echo "$ST: root create permission is granted - ok"
1959
1960     return 0
1961 }
1962 run_test 43 "check root_squash and nosquash_nids"
1963
1964 umount_client $MOUNT
1965 cleanup_nocli
1966
1967 test_44() { # 16317
1968         setup
1969         check_mount || return 2
1970         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
1971         STATS_FOUND=no
1972         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
1973         for VAL in $UUIDS; do
1974                 NID=$(echo $VAL | cut -d= -f1)
1975                 CLUUID=$(echo $VAL | cut -d= -f2)
1976                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
1977         done
1978         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
1979         cleanup
1980         return 0
1981 }
1982 run_test 44 "mounted client proc entry exists"
1983
1984 test_45() { #17310
1985         setup
1986         check_mount || return 2
1987         stop_mds
1988         df -h $MOUNT &
1989         log "sleep 60 sec"
1990         sleep 60
1991 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
1992         do_facet client "lctl set_param fail_loc=0x50f"
1993         log "sleep 10 sec"
1994         sleep 10
1995         manual_umount_client --force || return 3
1996         do_facet client "lctl set_param fail_loc=0x0"
1997         start_mds
1998         mount_client $MOUNT || return 4
1999         cleanup
2000         return 0
2001 }
2002 run_test 45 "long unlink handling in ptlrpcd"
2003
2004 cleanup_46a() {
2005         trap 0
2006         local rc=0
2007         local count=$1
2008
2009         umount_client $MOUNT2 || rc=$?
2010         umount_client $MOUNT || rc=$?
2011         while [ $count -gt 0 ]; do
2012                 stop ost${count} -f || rc=$?
2013                 let count=count-1
2014         done    
2015         stop_mds || rc=$?
2016         cleanup_nocli || rc=$?
2017         #writeconf to remove all ost2 traces for subsequent tests
2018         writeconf
2019         return $rc
2020 }
2021
2022 test_46a() {
2023         echo "Testing with $OSTCOUNT OSTs"
2024         reformat_and_config
2025         start_mds || return 1
2026         #first client should see only one ost
2027         start_ost || return 2
2028         wait_osc_import_state mds ost FULL
2029         #start_client
2030         mount_client $MOUNT || return 3
2031         trap "cleanup_46a $OSTCOUNT" EXIT ERR
2032
2033         local i
2034         for (( i=2; i<=$OSTCOUNT; i++ )); do
2035             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
2036         done
2037
2038         # wait until osts in sync
2039         for (( i=2; i<=$OSTCOUNT; i++ )); do
2040             wait_osc_import_state mds ost$i FULL
2041             wait_osc_import_state client ost$i FULL
2042         done
2043
2044         #second client see all ost's
2045
2046         mount_client $MOUNT2 || return 8
2047         $LFS setstripe -c -1 $MOUNT2 || return 9
2048         $LFS getstripe $MOUNT2 || return 10
2049
2050         echo "ok" > $MOUNT2/widestripe
2051         $LFS getstripe $MOUNT2/widestripe || return 11
2052         # fill acl buffer for avoid expand lsm to them
2053         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
2054             setfacl -m $acl $MOUNT2/widestripe
2055         done
2056
2057         # will be deadlock
2058         stat $MOUNT/widestripe || return 12
2059
2060         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
2061         return 0
2062 }
2063 run_test 46a "handle ost additional - wide striped file"
2064
2065 test_47() { #17674
2066         reformat
2067         setup_noconfig
2068         check_mount || return 2
2069         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
2070
2071         local lru_size=[]
2072         local count=0
2073         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2074             if echo $ns | grep "MDT[[:digit:]]*"; then
2075                 continue
2076             fi
2077             lrs=$(echo $ns | sed 's/.*lru_size=//')
2078             lru_size[count]=$lrs
2079             let count=count+1
2080         done
2081
2082         facet_failover ost1
2083         facet_failover $SINGLEMDS
2084         client_up || return 3
2085
2086         count=0
2087         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2088             if echo $ns | grep "MDT[[:digit:]]*"; then
2089                 continue
2090             fi
2091             lrs=$(echo $ns | sed 's/.*lru_size=//')
2092             if ! test "$lrs" -eq "${lru_size[count]}"; then
2093                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
2094                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
2095             fi
2096             let count=count+1
2097         done
2098
2099         cleanup
2100         return 0
2101 }
2102 run_test 47 "server restart does not make client loss lru_resize settings"
2103
2104 cleanup_48() {
2105         trap 0
2106
2107         # reformat after this test is needed - if test will failed
2108         # we will have unkillable file at FS
2109         reformat_and_config
2110 }
2111
2112 test_48() { # bug 17636
2113         reformat
2114         setup_noconfig
2115         check_mount || return 2
2116
2117         $LFS setstripe -c -1 $MOUNT || return 9
2118         $LFS getstripe $MOUNT || return 10
2119
2120         echo "ok" > $MOUNT/widestripe
2121         $LFS getstripe $MOUNT/widestripe || return 11
2122
2123         trap cleanup_48 EXIT ERR
2124
2125         # fill acl buffer for avoid expand lsm to them
2126         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
2127             setfacl -m $acl $MOUNT/widestripe
2128         done
2129
2130         stat $MOUNT/widestripe || return 12
2131
2132         cleanup_48
2133         return 0
2134 }
2135 run_test 48 "too many acls on file"
2136
2137 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
2138 test_49() { # bug 17710
2139         local timeout_orig=$TIMEOUT
2140         local ldlm_timeout_orig=$LDLM_TIMEOUT
2141         local LOCAL_TIMEOUT=20
2142
2143         LDLM_TIMEOUT=$LOCAL_TIMEOUT
2144         TIMEOUT=$LOCAL_TIMEOUT
2145
2146         reformat
2147         setup_noconfig
2148         check_mount || return 1
2149
2150         echo "check ldlm_timout..."
2151         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2152         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2153         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2154
2155         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2156                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2157         fi
2158
2159         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
2160                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2161         fi
2162
2163         umount_client $MOUNT
2164         stop_ost || return 2
2165         stop_mds || return 3
2166
2167         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
2168
2169         reformat
2170         setup_noconfig
2171         check_mount || return 7
2172
2173         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
2174         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
2175         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
2176
2177         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
2178                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
2179         fi
2180
2181         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
2182                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
2183         fi
2184
2185         cleanup || return $?
2186
2187         LDLM_TIMEOUT=$ldlm_timeout_orig
2188         TIMEOUT=$timeout_orig
2189 }
2190 run_test 49 "check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE"
2191
2192 lazystatfs() {
2193         # Test both statfs and lfs df and fail if either one fails
2194         multiop_bg_pause $1 f_
2195         RC1=$?
2196         PID=$!
2197         killall -USR1 multiop
2198         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
2199         wait $PID || { RC1=$?; log "multiop return error "; }
2200
2201         $LFS df &
2202         PID=$!
2203         sleep 5
2204         kill -s 0 $PID
2205         RC2=$?
2206         if [ $RC2 -eq 0 ]; then
2207             kill -s 9 $PID
2208             log "lazystatfs df failed"
2209         fi
2210
2211         RC=0
2212         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
2213         return $RC
2214 }
2215
2216 test_50a() {
2217         setup
2218         lctl set_param llite.$FSNAME-*.lazystatfs=1
2219         touch $DIR/$tfile
2220
2221         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
2222
2223         cleanup || return $?
2224 }
2225 run_test 50a "lazystatfs all servers available =========================="
2226
2227 test_50b() {
2228         setup
2229         lctl set_param llite.$FSNAME-*.lazystatfs=1
2230         touch $DIR/$tfile
2231
2232         # Wait for client to detect down OST
2233         stop_ost || error "Unable to stop OST1"
2234         wait_osc_import_state mds ost DISCONN
2235
2236         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
2237
2238         umount_client $MOUNT || error "Unable to unmount client"
2239         stop_mds || error "Unable to stop MDS"
2240 }
2241 run_test 50b "lazystatfs all servers down =========================="
2242
2243 test_50c() {
2244         start_mds || error "Unable to start MDS"
2245         start_ost || error "Unable to start OST1"
2246         start_ost2 || error "Unable to start OST2"
2247         mount_client $MOUNT || error "Unable to mount client"
2248         lctl set_param llite.$FSNAME-*.lazystatfs=1
2249         touch $DIR/$tfile
2250
2251         # Wait for client to detect down OST
2252         stop_ost || error "Unable to stop OST1"
2253         wait_osc_import_state mds ost DISCONN
2254         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2255
2256         umount_client $MOUNT || error "Unable to unmount client"
2257         stop_ost2 || error "Unable to stop OST2"
2258         stop_mds || error "Unable to stop MDS"
2259         #writeconf to remove all ost2 traces for subsequent tests
2260         writeconf
2261 }
2262 run_test 50c "lazystatfs one server down =========================="
2263
2264 test_50d() {
2265         start_mds || error "Unable to start MDS"
2266         start_ost || error "Unable to start OST1"
2267         start_ost2 || error "Unable to start OST2"
2268         mount_client $MOUNT || error "Unable to mount client"
2269         lctl set_param llite.$FSNAME-*.lazystatfs=1
2270         touch $DIR/$tfile
2271
2272         # Issue the statfs during the window where the client still
2273         # belives the OST to be available but it is in fact down.
2274         # No failure just a statfs which hangs for a timeout interval.
2275         stop_ost || error "Unable to stop OST1"
2276         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
2277
2278         umount_client $MOUNT || error "Unable to unmount client"
2279         stop_ost2 || error "Unable to stop OST2"
2280         stop_mds || error "Unable to stop MDS"
2281         #writeconf to remove all ost2 traces for subsequent tests
2282         writeconf
2283 }
2284 run_test 50d "lazystatfs client/server conn race =========================="
2285
2286 test_50e() {
2287         local RC1
2288         local pid
2289
2290         reformat_and_config
2291         start_mds || return 1
2292         #first client should see only one ost
2293         start_ost || return 2
2294         wait_osc_import_state mds ost FULL
2295
2296         # Wait for client to detect down OST
2297         stop_ost || error "Unable to stop OST1"
2298         wait_osc_import_state mds ost DISCONN
2299
2300         mount_client $MOUNT || error "Unable to mount client"
2301         lctl set_param llite.$FSNAME-*.lazystatfs=0
2302
2303         multiop_bg_pause $MOUNT _f
2304         RC1=$?
2305         pid=$!
2306
2307         if [ $RC1 -ne 0 ]; then
2308                 log "multiop failed $RC1"
2309         else
2310             kill -USR1 $pid
2311             sleep $(( $TIMEOUT+1 ))
2312             kill -0 $pid
2313             [ $? -ne 0 ] && error "process isn't sleep"
2314             start_ost || error "Unable to start OST1"
2315             wait $pid || error "statfs failed"
2316         fi
2317
2318         umount_client $MOUNT || error "Unable to unmount client"
2319         stop_ost || error "Unable to stop OST1"
2320         stop_mds || error "Unable to stop MDS"
2321 }
2322 run_test 50e "normal statfs all servers down =========================="
2323
2324 test_50f() {
2325         local RC1
2326         local pid
2327         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
2328
2329         start_mds || error "Unable to start mds"
2330         #first client should see only one ost
2331         start_ost || error "Unable to start OST1"
2332         wait_osc_import_state mds ost FULL
2333
2334         start_ost2 || error "Unable to start OST2"
2335         wait_osc_import_state mds ost2 FULL
2336
2337         # Wait for client to detect down OST
2338         stop_ost2 || error "Unable to stop OST2"
2339
2340         wait_osc_import_state mds ost2 DISCONN
2341         mount_client $MOUNT || error "Unable to mount client"
2342         lctl set_param llite.$FSNAME-*.lazystatfs=0
2343
2344         multiop_bg_pause $MOUNT _f
2345         RC1=$?
2346         pid=$!
2347
2348         if [ $RC1 -ne 0 ]; then
2349                 log "lazystatfs multiop failed $RC1"
2350         else
2351             kill -USR1 $pid
2352             sleep $(( $TIMEOUT+1 ))
2353             kill -0 $pid
2354             [ $? -ne 0 ] && error "process isn't sleep"
2355             start_ost2 || error "Unable to start OST2"
2356             wait $pid || error "statfs failed"
2357             stop_ost2 || error "Unable to stop OST2"
2358         fi
2359
2360         umount_client $MOUNT || error "Unable to unmount client"
2361         stop_ost || error "Unable to stop OST1"
2362         stop_mds || error "Unable to stop MDS"
2363         #writeconf to remove all ost2 traces for subsequent tests
2364         writeconf
2365 }
2366 run_test 50f "normal statfs one server in down =========================="
2367
2368 test_50g() {
2369         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2370         setup
2371         start_ost2 || error "Unable to start OST2"
2372         wait_osc_import_state mds ost2 FULL
2373         wait_osc_import_state client ost2 FULL
2374
2375         local PARAM="${FSNAME}-OST0001.osc.active"
2376
2377         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
2378         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
2379
2380         umount_client $MOUNT || error "Unable to unmount client"
2381         mount_client $MOUNT || error "Unable to mount client"
2382         # This df should not cause a panic
2383         df -k $MOUNT
2384
2385         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
2386         rm -f $DIR/$tfile
2387         umount_client $MOUNT || error "Unable to unmount client"
2388         stop_ost2 || error "Unable to stop OST2"
2389         stop_ost || error "Unable to stop OST1"
2390         stop_mds || error "Unable to stop MDS"
2391         #writeconf to remove all ost2 traces for subsequent tests
2392         writeconf
2393 }
2394 run_test 50g "deactivated OST should not cause panic====================="
2395
2396 test_51() {
2397         local LOCAL_TIMEOUT=20
2398
2399         reformat
2400         setup_noconfig
2401         check_mount || return 1
2402
2403         mkdir $MOUNT/d1
2404         $LFS setstripe -c -1 $MOUNT/d1
2405         #define OBD_FAIL_MDS_REINT_DELAY         0x142
2406         do_facet $SINGLEMDS "lctl set_param fail_loc=0x142"
2407         touch $MOUNT/d1/f1 &
2408         local pid=$!
2409         sleep 2
2410         start_ost2 || return 2
2411         wait $pid
2412         stop_ost2 || return 3
2413         cleanup
2414         #writeconf to remove all ost2 traces for subsequent tests
2415         writeconf
2416 }
2417 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
2418
2419 copy_files_xattrs()
2420 {
2421         local node=$1
2422         local dest=$2
2423         local xattrs=$3
2424         shift 3
2425
2426         do_node $node mkdir -p $dest
2427         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2428
2429         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
2430                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
2431         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
2432
2433         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
2434         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
2435 }
2436
2437 diff_files_xattrs()
2438 {
2439         local node=$1
2440         local backup=$2
2441         local xattrs=$3
2442         shift 3
2443
2444         local backup2=${TMP}/backup2
2445
2446         do_node $node mkdir -p $backup2
2447         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2448
2449         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
2450                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
2451         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
2452
2453         do_node $node "diff -rq $backup $backup2"
2454         [ $? -eq 0 ] || { error "contents differ"; return 3; }
2455
2456         local xattrs2=${TMP}/xattrs2
2457         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
2458         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
2459
2460         do_node $node "diff $xattrs $xattrs2"
2461         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
2462
2463         do_node $node "rm -rf $backup2 $xattrs2"
2464         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
2465 }
2466
2467 test_52() {
2468         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2469                 skip "Only applicable to ldiskfs-based MDTs"
2470                 return
2471         fi
2472
2473         start_mds
2474         [ $? -eq 0 ] || { error "Unable to start MDS"; return 1; }
2475         start_ost
2476         [ $? -eq 0 ] || { error "Unable to start OST1"; return 2; }
2477         mount_client $MOUNT
2478         [ $? -eq 0 ] || { error "Unable to mount client"; return 3; }
2479
2480         local nrfiles=8
2481         local ost1mnt=$(facet_mntpt ost1)
2482         local ost1node=$(facet_active_host ost1)
2483         local ost1tmp=$TMP/conf52
2484         local loop
2485
2486         mkdir -p $DIR/$tdir
2487         [ $? -eq 0 ] || { error "Unable to create tdir"; return 4; }
2488         touch $TMP/modified_first
2489         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 5; }
2490         local mtime=$(stat -c %Y $TMP/modified_first)
2491         do_node $ost1node "mkdir -p $ost1tmp && touch -m -d @$mtime $ost1tmp/modified_first"
2492
2493         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 6; }
2494         sleep 1
2495
2496         $LFS setstripe -c -1 -S 1M $DIR/$tdir
2497         [ $? -eq 0 ] || { error "lfs setstripe failed"; return 7; }
2498
2499         for (( i=0; i < nrfiles; i++ )); do
2500                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c
2501                 [ $? -eq 0 ] || { error "multiop failed"; return 8; }
2502                 echo -n .
2503         done
2504         echo
2505
2506         # backup files
2507         echo backup files to $TMP/files
2508         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
2509         copy_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
2510         [ $? -eq 0 ] || { error "Unable to copy files"; return 9; }
2511
2512         umount_client $MOUNT
2513         [ $? -eq 0 ] || { error "Unable to umount client"; return 10; }
2514         stop_ost
2515         [ $? -eq 0 ] || { error "Unable to stop ost1"; return 11; }
2516
2517         echo mount ost1 as ldiskfs
2518         do_node $ost1node mkdir -p $ost1mnt
2519         [ $? -eq 0 ] || { error "Unable to create $ost1mnt"; return 23; }
2520         if ! do_node $ost1node test -b $ost1_dev; then
2521                 loop="-o loop"
2522         fi
2523         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
2524                 $ost1mnt
2525         [ $? -eq 0 ] || { error "Unable to mount ost1 as ldiskfs"; return 12; }
2526
2527         # backup objects
2528         echo backup objects to $ost1tmp/objects
2529         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/0 -type f -size +0'\
2530                         '-newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
2531         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
2532         [ $? -eq 0 ] || { error "Unable to copy objects"; return 13; }
2533
2534         # move objects to lost+found
2535         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
2536         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
2537
2538         # recover objects
2539         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found"
2540         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
2541
2542         # compare restored objects against saved ones
2543         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
2544         [ $? -eq 0 ] || { error "Unable to diff objects"; return 16; }
2545
2546         do_node $ost1node "umount $ost1mnt"
2547         [ $? -eq 0 ] || { error "Unable to umount ost1 as ldiskfs"; return 17; }
2548
2549         start_ost
2550         [ $? -eq 0 ] || { error "Unable to start ost1"; return 18; }
2551         mount_client $MOUNT
2552         [ $? -eq 0 ] || { error "Unable to mount client"; return 19; }
2553
2554         # compare files
2555         diff_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
2556         [ $? -eq 0 ] || { error "Unable to diff files"; return 20; }
2557
2558         rm -rf $TMP/files $TMP/file_xattrs
2559         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 21; }
2560         do_node $ost1node "rm -rf $ost1tmp"
2561         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 22; }
2562         cleanup
2563 }
2564 run_test 52 "check recovering objects from lost+found"
2565
2566 # Checks threads_min/max/started for some service
2567 #
2568 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
2569 # parameter pattern prefix like 'ost.*.ost'.
2570 thread_sanity() {
2571         local modname=$1
2572         local facet=$2
2573         local parampat=$3
2574         local opts=$4
2575         local basethr=$5
2576         local tmin
2577         local tmin2
2578         local tmax
2579         local tmax2
2580         local tstarted
2581         local paramp
2582         local msg="Insane $modname thread counts"
2583         local ncpts=$(check_cpt_number $facet)
2584         local nthrs
2585         shift 4
2586
2587         setup
2588         check_mount || return 41
2589
2590         # We need to expand $parampat, but it may match multiple parameters, so
2591         # we'll pick the first one
2592         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
2593                 error "Couldn't expand ${parampat}.threads_min parameter name"
2594                 return 22
2595         fi
2596
2597         # Remove the .threads_min part
2598         paramp=${paramp%.threads_min}
2599
2600         # Check for sanity in defaults
2601         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2602         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2603         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started" || echo 0)
2604         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' || return $?
2605         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
2606         nthrs=$(expr $tmax - $tmin)
2607         if [ $nthrs -lt $ncpts ]; then
2608                 nthrs=0
2609         else
2610                 nthrs=$ncpts
2611         fi
2612
2613         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
2614                 skip_env "module parameter forced $facet thread count" &&
2615                 tmin=3 && tmax=$((3 * tmax))
2616
2617         # Check that we can change min/max
2618         do_facet $facet "lctl set_param ${paramp}.threads_min=$((tmin + nthrs))"
2619         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmax - nthrs))"
2620         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2621         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2622         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) && $tmax2 == ($tmax - $nthrs)))' || return $?
2623
2624         # Check that we can set min/max to the same value
2625         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2626         do_facet $facet "lctl set_param ${paramp}.threads_max=$tmin"
2627         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2628         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2629         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
2630
2631         # Check that we can't set max < min
2632         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmin - 1))"
2633         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
2634         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
2635         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
2636
2637         # We need to ensure that we get the module options desired; to do this
2638         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
2639         LOAD_MODULES_REMOTE=true
2640         cleanup
2641         local oldvalue
2642         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
2643         setmodopts -a $modname "$newvalue" oldvalue
2644
2645         load_modules
2646         setup
2647         check_mount || return 41
2648
2649         # Restore previous setting of MODOPTS_*
2650         setmodopts $modname "$oldvalue"
2651
2652         # Check that $opts took
2653         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min")
2654         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max")
2655         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started")
2656         lassert 28 "$msg" '(($tstarted == $tmin && $tstarted == $tmax ))' || return $?
2657         cleanup
2658
2659         # Workaround a YALA bug where YALA expects that modules will remain
2660         # loaded on the servers
2661         LOAD_MODULES_REMOTE=false
2662         load_modules
2663         setup
2664         cleanup
2665 }
2666
2667 test_53a() {
2668         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
2669 }
2670 run_test 53a "check OSS thread count params"
2671
2672 test_53b() {
2673         thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' '16'
2674 }
2675 run_test 53b "check MDT thread count params"
2676
2677 test_54a() {
2678         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2679                 skip "Only applicable to ldiskfs-based MDTs"
2680                 return
2681         fi
2682
2683     do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p
2684     [ $? -eq 0 ] || error "llverdev failed!"
2685     reformat_and_config
2686 }
2687 run_test 54a "test llverdev and partial verify of device"
2688
2689 test_54b() {
2690         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2691                 skip "Only applicable to ldiskfs-based MDTs"
2692                 return
2693         fi
2694
2695     setup
2696     run_llverfs $MOUNT -p
2697     [ $? -eq 0 ] || error "llverfs failed!"
2698     cleanup
2699 }
2700 run_test 54b "test llverfs and partial verify of filesystem"
2701
2702 lov_objid_size()
2703 {
2704         local max_ost_index=$1
2705         echo -n $(((max_ost_index + 1) * 8))
2706 }
2707
2708 test_55() {
2709         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2710                 skip "Only applicable to ldiskfs-based MDTs"
2711                 return
2712         fi
2713
2714         local mdsdev=$(mdsdevname 1)
2715         local mdsvdev=$(mdsvdevname 1)
2716
2717         for i in 1023 2048
2718         do
2719                 add mds1 $(mkfs_opts mds1) --reformat $mdsdev $mdsvdev ||
2720                         exit 10
2721                 add ost1 $(mkfs_opts ost1) --index=$i --reformat \
2722                         $(ostdevname 1) $(ostvdevname 1)
2723                 setup_noconfig
2724                 stopall
2725                 setup_noconfig
2726                 sync
2727
2728                 echo checking size of lov_objid for ost index $i
2729                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" | grep ^User | awk '{print $6}')
2730                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
2731                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
2732                 else
2733                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
2734                 fi
2735                 stopall
2736         done
2737
2738         reformat
2739 }
2740 run_test 55 "check lov_objid size"
2741
2742 test_56() {
2743         local mds_journal_size_orig=$MDSJOURNALSIZE
2744
2745         MDSJOURNALSIZE=16
2746         add mds1 $(mkfs_opts mds1) --reformat $(mdsdevname 1) $(mdsvdevname 1)
2747         add ost1 $(mkfs_opts ost1) --index=1000 --reformat \
2748                 $(ostdevname 1) $(ostvdevname 1)
2749         add ost2 $(mkfs_opts ost2) --index=10000 --reformat \
2750                 $(ostdevname 2) $(ostvdevname 2)
2751
2752         start_mgsmds
2753         start_ost
2754         start_ost2 || error "Unable to start second ost"
2755         mount_client $MOUNT || error "Unable to mount client"
2756         echo ok
2757         $LFS osts
2758         stopall
2759         MDSJOURNALSIZE=$mds_journal_size_orig
2760         reformat
2761 }
2762 run_test 56 "check big indexes"
2763
2764 test_57a() { # bug 22656
2765         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
2766         writeconf
2767         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" || error "tunefs failed"
2768         start_mgsmds
2769         start_ost && error "OST registration from failnode should fail"
2770         reformat
2771 }
2772 run_test 57a "initial registration from failnode should fail (should return errs)"
2773
2774 test_57b() {
2775         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
2776         writeconf
2777         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" || error "tunefs failed"
2778         start_mgsmds
2779         start_ost || error "OST registration from servicenode should not fail"
2780         reformat
2781 }
2782 run_test 57b "initial registration from servicenode should not fail"
2783
2784 count_osts() {
2785         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
2786 }
2787
2788 test_58() { # bug 22658
2789         if [ $(facet_fstype mds) != ldiskfs ]; then
2790                 skip "Only applicable to ldiskfs-based MDTs"
2791                 return
2792         fi
2793         setup_noconfig
2794         mkdir -p $DIR/$tdir
2795         createmany -o $DIR/$tdir/$tfile-%d 100
2796         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
2797 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
2798         do_facet mds "lctl set_param fail_loc=0x601"
2799         unlinkmany $DIR/$tdir/$tfile-%d 100
2800         stop mds
2801         local MNTDIR=$(facet_mntpt mds)
2802         # remove all files from the OBJECTS dir
2803         do_facet mds "mount -t ldiskfs $MDSDEV $MNTDIR"
2804         do_facet mds "find $MNTDIR/OBJECTS -type f -delete"
2805         do_facet mds "umount $MNTDIR"
2806         # restart MDS with missing llog files
2807         start_mds
2808         do_facet mds "lctl set_param fail_loc=0"
2809         reformat
2810 }
2811 run_test 58 "missing llog files must not prevent MDT from mounting"
2812
2813 test_59() {
2814         start_mgsmds >> /dev/null
2815         local C1=$(count_osts)
2816         if [ $C1 -eq 0 ]; then
2817                 start_ost >> /dev/null
2818                 C1=$(count_osts)
2819         fi
2820         stopall
2821         echo "original ost count: $C1 (expect > 0)"
2822         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
2823         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
2824         local C2=$(count_osts)
2825         echo "after mdt writeconf count: $C2 (expect 0)"
2826         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
2827         echo "OST start without writeconf should fail:"
2828         start_ost >> /dev/null && error "OST start without writeconf didn't fail"
2829         echo "OST start with writeconf should succeed:"
2830         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
2831         local C3=$(count_osts)
2832         echo "after ost writeconf count: $C3 (expect 1)"
2833         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
2834         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
2835         local C4=$(count_osts)
2836         echo "after ost2 writeconf count: $C4 (expect 2)"
2837         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
2838         stop_ost2 >> /dev/null
2839         cleanup_nocli >> /dev/null
2840         #writeconf to remove all ost2 traces for subsequent tests
2841         writeconf
2842 }
2843 run_test 59 "writeconf mount option"
2844
2845 test_60() { # LU-471
2846         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2847                 skip "Only applicable to ldiskfs-based MDTs"
2848                 return
2849         fi
2850
2851         add mds1 $(mkfs_opts mds1) \
2852                 --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' --reformat \
2853                 $(mdsdevname 1) $(mdsvdevname 1) || exit 10
2854
2855         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
2856         rc=${PIPESTATUS[0]}
2857         [ $rc -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
2858
2859         # MDT default has dirdata feature
2860         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
2861         # we disable uninit_bg feature
2862         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
2863         # we set stride extended options
2864         echo $dump | grep stride > /dev/null || error "stride is not set"
2865         reformat
2866 }
2867 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
2868
2869 test_61() { # LU-80
2870         local reformat=false
2871
2872         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
2873                 { skip "Need MDS version at least 2.1.53"; return 0; }
2874
2875         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2876            ! large_xattr_enabled; then
2877                 reformat=true
2878                 local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
2879                 LDISKFS_MKFS_OPTS+=" -O large_xattr"
2880                 add $SINGLEMDS $(mkfs_opts $SINGLEMDS) --reformat $mds_dev ||
2881                         error "reformatting $mds_dev failed"
2882         fi
2883
2884     setup_noconfig || error "setting up the filesystem failed"
2885     client_up || error "starting client failed"
2886
2887     local file=$DIR/$tfile
2888     touch $file
2889
2890     local large_value="$(generate_string $(max_xattr_size))"
2891     local small_value="bar"
2892
2893     local name="trusted.big"
2894     log "save large xattr $name on $file"
2895     setfattr -n $name -v $large_value $file ||
2896         error "saving $name on $file failed"
2897
2898     local new_value=$(get_xattr_value $name $file)
2899     [[ "$new_value" != "$large_value" ]] &&
2900         error "$name different after saving"
2901
2902     log "shrink value of $name on $file"
2903     setfattr -n $name -v $small_value $file ||
2904         error "shrinking value of $name on $file failed"
2905
2906     new_value=$(get_xattr_value $name $file)
2907     [[ "$new_value" != "$small_value" ]] &&
2908         error "$name different after shrinking"
2909
2910     log "grow value of $name on $file"
2911     setfattr -n $name -v $large_value $file ||
2912         error "growing value of $name on $file failed"
2913
2914     new_value=$(get_xattr_value $name $file)
2915     [[ "$new_value" != "$large_value" ]] &&
2916         error "$name different after growing"
2917
2918     log "check value of $name on $file after remounting MDS"
2919     fail $SINGLEMDS
2920     new_value=$(get_xattr_value $name $file)
2921     [[ "$new_value" != "$large_value" ]] &&
2922         error "$name different after remounting MDS"
2923
2924     log "remove large xattr $name from $file"
2925     setfattr -x $name $file || error "removing $name from $file failed"
2926
2927     rm -f $file
2928     stopall
2929         if $reformat; then
2930                 LDISKFS_MKFS_OPTS=${LDISKFS_MKFS_OPTS% -O large_xattr}
2931                 reformat
2932         fi
2933 }
2934 run_test 61 "large xattr"
2935
2936 test_62() {
2937         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2938                 skip "Only applicable to ldiskfs-based MDTs"
2939                 return
2940         fi
2941
2942         # MRP-118
2943         local mdsdev=$(mdsdevname 1)
2944         local ostdev=$(ostdevname 1)
2945
2946         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
2947                 { skip "Need MDS version at least 2.2.51"; return 0; }
2948
2949         echo "disable journal for mds"
2950         do_facet mds tune2fs -O ^has_journal $mdsdev || error "tune2fs failed"
2951         start_mds && error "MDT start should fail"
2952         echo "disable journal for ost"
2953         do_facet ost1 tune2fs -O ^has_journal $ostdev || error "tune2fs failed"
2954         start_ost && error "OST start should fail"
2955         cleanup || return $?
2956         reformat_and_config
2957 }
2958 run_test 62 "start with disabled journal"
2959
2960 test_63() {
2961         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2962                 skip "Only applicable to ldiskfs-based MDTs"
2963                 return
2964         fi
2965
2966         local inode_slab=$(do_facet $SINGLEMDS \
2967                 "awk '/ldiskfs_inode_cache/ { print \\\$5 }' /proc/slabinfo")
2968         if [ -z "$inode_slab" ]; then
2969                 skip "ldiskfs module has not been loaded"
2970                 return
2971         fi
2972
2973         echo "$inode_slab ldisk inodes per page"
2974         [ "$inode_slab" -ge "3" ] ||
2975                 error "ldisk inode size is too big, $inode_slab objs per page"
2976         return
2977 }
2978 run_test 63 "Verify each page can at least hold 3 ldisk inodes"
2979
2980 if ! combined_mgs_mds ; then
2981         stop mgs
2982 fi
2983
2984 cleanup_gss
2985
2986 complete $(basename $0) $SECONDS
2987 exit_status