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