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