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