Whamcloud - gitweb
LU-5986 test: Ensure correct start for conf-sanity/84
[fs/lustre-release.git] / lustre / tests / conf-sanity.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6
7 # bug number for skipped test:     LU-2828
8 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT 59 64"
9 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
10
11 is_sles11()                                             # LU-2181
12 {
13         if [ -r /etc/SuSE-release ]
14         then
15                 local vers=$(grep VERSION /etc/SuSE-release | awk '{print $3}')
16                 local patchlev=$(grep PATCHLEVEL /etc/SuSE-release |
17                         awk '{ print $3 }')
18                 if [ $vers -eq 11 ] && [ $patchlev -eq 2 ]
19                 then
20                         return 0
21                 fi
22         fi
23         return 1
24 }
25
26 if is_sles11; then                                      # LU-2181
27         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 23a 34b"
28 fi
29
30 if [ "$FAILURE_MODE" = "HARD" ]; then
31         CONFIG_EXCEPTIONS="24a " &&
32         echo "Except the tests: $CONFIG_EXCEPTIONS for " \
33              "FAILURE_MODE=$FAILURE_MODE, b=23573" &&
34                 ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
35 fi
36
37 # bug number for skipped test:
38 # a tool to create lustre filesystem images
39 ALWAYS_EXCEPT="32newtarball $ALWAYS_EXCEPT"
40
41 SRCDIR=$(dirname $0)
42 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
43
44 PTLDEBUG=${PTLDEBUG:--1}
45 SAVE_PWD=$PWD
46 LUSTRE=${LUSTRE:-$(dirname $0)/..}
47 RLUSTRE=${RLUSTRE:-$LUSTRE}
48 export MULTIOP=${MULTIOP:-multiop}
49
50 . $LUSTRE/tests/test-framework.sh
51 init_test_env $@
52 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
53
54 # use small MDS + OST size to speed formatting time
55 # do not use too small MDSSIZE/OSTSIZE, which affect the default jouranl size
56 # STORED_MDSSIZE is used in test_18
57 STORED_MDSSIZE=$MDSSIZE
58 STORED_OSTSIZE=$OSTSIZE
59 MDSSIZE=200000
60 OSTSIZE=200000
61
62 if ! combined_mgs_mds; then
63     # bug number for skipped test:    23954
64     ALWAYS_EXCEPT="$ALWAYS_EXCEPT       24b"
65 fi
66
67 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
68 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
69         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
70 fi
71
72 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
73 # bug number for skipped test:        LU-2778 LU-4444
74         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 57b     69"
75
76 init_logging
77
78 #
79 require_dsh_mds || exit 0
80 require_dsh_ost || exit 0
81 #
82 [ "$SLOW" = "no" ] && EXCEPT_SLOW="30a 31 45 69"
83
84 assert_DIR
85
86 gen_config() {
87         # The MGS must be started before the OSTs for a new fs, so start
88         # and stop to generate the startup logs.
89         start_mds
90         start_ost
91         wait_osc_import_state mds ost FULL
92         stop_ost
93         stop_mds
94 }
95
96 reformat_and_config() {
97         reformat
98         if ! combined_mgs_mds ; then
99                 start_mgs
100         fi
101         gen_config
102 }
103
104 writeconf_or_reformat() {
105         # There are at most 2 OSTs for write_conf test
106         # who knows if/where $TUNEFS is installed?
107         # Better reformat if it fails...
108         writeconf_all $MDSCOUNT 2 ||
109                 { echo "tunefs failed, reformatting instead" &&
110                   reformat_and_config && return 0; }
111         return 0
112 }
113
114 reformat() {
115         formatall
116 }
117
118 start_mgs () {
119         echo "start mgs"
120         start mgs $(mgsdevname) $MGS_MOUNT_OPTS
121 }
122
123 start_mdt() {
124         local num=$1
125         local facet=mds$num
126         local dev=$(mdsdevname $num)
127         shift 1
128
129         echo "start mds service on `facet_active_host $facet`"
130         start $facet ${dev} $MDS_MOUNT_OPTS $@ || return 94
131 }
132
133 stop_mdt() {
134         local num=$1
135         local facet=mds$num
136         local dev=$(mdsdevname $num)
137         shift 1
138
139         echo "stop mds service on `facet_active_host $facet`"
140         # These tests all use non-failover stop
141         stop $facet -f || return 97
142 }
143
144 start_mds() {
145         local num
146
147         for num in $(seq $MDSCOUNT); do
148                 start_mdt $num $@ || return 94
149         done
150 }
151
152 start_mgsmds() {
153         if ! combined_mgs_mds ; then
154                 start_mgs
155         fi
156         start_mds $@
157 }
158
159 stop_mds() {
160         local num
161         for num in $(seq $MDSCOUNT); do
162                 stop_mdt $num || return 97
163         done
164 }
165
166 stop_mgs() {
167        echo "stop mgs service on `facet_active_host mgs`"
168        # These tests all use non-failover stop
169        stop mgs -f  || return 97
170 }
171
172 start_ost() {
173         echo "start ost1 service on `facet_active_host ost1`"
174         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS $@ || return 95
175 }
176
177 stop_ost() {
178         echo "stop ost1 service on `facet_active_host ost1`"
179         # These tests all use non-failover stop
180         stop ost1 -f || return 98
181 }
182
183 start_ost2() {
184         echo "start ost2 service on `facet_active_host ost2`"
185         start ost2 $(ostdevname 2) $OST_MOUNT_OPTS $@ || return 92
186 }
187
188 stop_ost2() {
189         echo "stop ost2 service on `facet_active_host ost2`"
190         # These tests all use non-failover stop
191         stop ost2 -f || return 93
192 }
193
194 mount_client() {
195         local MOUNTPATH=$1
196         echo "mount $FSNAME on ${MOUNTPATH}....."
197         zconf_mount $(hostname) $MOUNTPATH || return 96
198 }
199
200 remount_client() {
201         local mountopt="remount,$1"
202         local MOUNTPATH=$2
203         echo "remount '$1' lustre on ${MOUNTPATH}....."
204         zconf_mount $(hostname) $MOUNTPATH "$mountopt" || return 96
205 }
206
207 umount_client() {
208         local MOUNTPATH=$1
209         echo "umount lustre on ${MOUNTPATH}....."
210         zconf_umount $(hostname) $MOUNTPATH || return 97
211 }
212
213 manual_umount_client(){
214         local rc
215         local FORCE=$1
216         echo "manual umount lustre on ${MOUNT}...."
217         do_facet client "umount -d ${FORCE} $MOUNT"
218         rc=$?
219         return $rc
220 }
221
222 setup() {
223         start_mds || error "MDT start failed"
224         start_ost || error "Unable to start OST1"
225         mount_client $MOUNT || error "client start failed"
226         client_up || error "client_up failed"
227 }
228
229 setup_noconfig() {
230         start_mgsmds
231         start_ost
232         mount_client $MOUNT
233 }
234
235 unload_modules_conf () {
236         if combined_mgs_mds || ! local_mode; then
237                 unload_modules || return 1
238         fi
239 }
240
241 cleanup_nocli() {
242         stop_ost || return 202
243         stop_mds || return 201
244         unload_modules_conf || return 203
245 }
246
247 cleanup() {
248         umount_client $MOUNT || return 200
249         cleanup_nocli || return $?
250 }
251
252 check_mount() {
253         do_facet client "cp /etc/passwd $DIR/a" || return 71
254         do_facet client "rm $DIR/a" || return 72
255         # make sure lustre is actually mounted (touch will block,
256         # but grep won't, so do it after)
257         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
258         echo "setup single mount lustre success"
259 }
260
261 check_mount2() {
262         do_facet client "touch $DIR/a" || return 71
263         do_facet client "rm $DIR/a" || return 72
264         do_facet client "touch $DIR2/a" || return 73
265         do_facet client "rm $DIR2/a" || return 74
266         echo "setup double mount lustre success"
267 }
268
269 build_test_filter
270
271 if [ "$ONLY" == "setup" ]; then
272         setup
273         exit
274 fi
275
276 if [ "$ONLY" == "cleanup" ]; then
277         cleanup
278         exit
279 fi
280
281 init_gss
282
283 #create single point mountpoint
284
285 reformat_and_config
286
287 test_0() {
288         setup
289         check_mount || error "check_mount failed"
290         cleanup || error "cleanup failed with $?"
291 }
292 run_test 0 "single mount setup"
293
294 test_1() {
295         start_mds || error "MDS start failed"
296         start_ost || error "unable to start OST"
297         echo "start ost second time..."
298         start_ost && error "2nd OST start should fail"
299         mount_client $MOUNT || error "client start failed"
300         check_mount || error "check_mount failed"
301         cleanup || error "cleanup failed with $?"
302 }
303 run_test 1 "start up ost twice (should return errors)"
304
305 test_2() {
306         start_mdt 1 || error "MDT0 start fail"
307         echo "start mds second time.."
308         start_mdt 1 && error "2nd MDT start should fail"
309         start_ost || error "OST start failed"
310         mount_client $MOUNT || error "mount_client failed to start client"
311         check_mount || error "check_mount failed"
312         cleanup || error "cleanup failed with $?"
313 }
314 run_test 2 "start up mds twice (should return err)"
315
316 test_3() {
317         setup
318         #mount.lustre returns an error if already in mtab
319         mount_client $MOUNT && error "2nd client mount should fail"
320         check_mount || error "check_mount failed"
321         cleanup || error "cleanup failed with $?"
322 }
323 run_test 3 "mount client twice (should return err)"
324
325 test_4() {
326         setup
327         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
328         stop_ost || error "Unable to stop OST1"
329         cleanup
330         eno=$?
331         # ok for ost to fail shutdown
332         if [ 202 -ne $eno ] && [ 0 -ne $eno ]; then
333                 error "cleanup failed with $?"
334         fi
335 }
336 run_test 4 "force cleanup ost, then cleanup"
337
338 test_5a() {     # was test_5
339         setup
340         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
341         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
342
343         stop_mds || error "Unable to stop MDS"
344
345         # cleanup may return an error from the failed
346         # disconnects; for now I'll consider this successful
347         # if all the modules have unloaded.
348         umount -d $MOUNT &
349         UMOUNT_PID=$!
350         sleep 6
351         echo "killing umount"
352         kill -TERM $UMOUNT_PID
353         echo "waiting for umount to finish"
354         wait $UMOUNT_PID
355         if grep " $MOUNT " /proc/mounts; then
356                 echo "test 5: /proc/mounts after failed umount"
357                 umount -f $MOUNT &
358                 UMOUNT_PID=$!
359                 sleep 2
360                 echo "killing umount"
361                 kill -TERM $UMOUNT_PID
362                 echo "waiting for umount to finish"
363                 wait $UMOUNT_PID
364                 grep " $MOUNT " /proc/mounts &&
365                         error "/proc/mounts after second umount"
366         fi
367
368         # manual_mount_client may fail due to umount succeeding above
369         manual_umount_client
370         # stop_mds is a no-op here, and should not fail
371         cleanup_nocli || error "cleanup_nocli failed with $?"
372         # df may have lingering entry
373         manual_umount_client
374         # mtab may have lingering entry
375         local WAIT=0
376         local MAX_WAIT=20
377         local sleep=1
378         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
379                 sleep $sleep
380                 grep -q $MOUNT" " /etc/mtab || break
381                 echo "Waiting /etc/mtab updated ... "
382                 WAIT=$(( WAIT + sleep))
383         done
384         [ "$WAIT" -eq "$MAX_WAIT" ] &&
385                 error "/etc/mtab is not updated in $WAIT secs"
386         echo "/etc/mtab updated in $WAIT secs"
387 }
388 run_test 5a "force cleanup mds, then cleanup"
389
390 cleanup_5b () {
391         trap 0
392         start_mgs
393 }
394
395 test_5b() {
396         grep " $MOUNT " /etc/mtab &&
397                 error false "unexpected entry in mtab before mount" && return 10
398
399         start_ost || error "OST start failed"
400         if ! combined_mgs_mds ; then
401                 trap cleanup_5b EXIT ERR
402                 start_mds || error "MDS start failed"
403                 stop mgs
404         fi
405
406         mount_client $MOUNT && error "mount_client $MOUNT should fail"
407         grep " $MOUNT " /etc/mtab &&
408                 error "$MOUNT entry in mtab after failed mount"
409         umount_client $MOUNT
410         # stop_mds is a no-op here, and should not fail
411         cleanup_nocli || error "cleanup_nocli failed with $?"
412         if ! combined_mgs_mds ; then
413                 cleanup_5b
414         fi
415 }
416 run_test 5b "Try to start a client with no MGS (should return errs)"
417
418 test_5c() {
419         grep " $MOUNT " /etc/mtab &&
420                 error false "unexpected entry in mtab before mount" && return 10
421
422         start_mds || error "MDS start failed"
423         start_ost || error "OST start failed"
424         local oldfs="${FSNAME}"
425         FSNAME="wrong.${FSNAME}"
426         mount_client $MOUNT || :
427         FSNAME=${oldfs}
428         grep " $MOUNT " /etc/mtab &&
429                 error "$MOUNT entry in mtab after failed mount"
430         umount_client $MOUNT
431         cleanup_nocli || error "cleanup_nocli failed with $?"
432 }
433 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
434
435 test_5d() {
436         grep " $MOUNT " /etc/mtab &&
437                 error false "unexpected entry in mtab before mount" && return 10
438
439         start_ost || error "OST start failed"
440         start_mds || error "MDS start failed"
441         stop_ost || error "Unable to stop OST1"
442         mount_client $MOUNT || error "mount_client $MOUNT failed"
443         cleanup || error "cleanup_nocli failed with $?"
444         grep " $MOUNT " /etc/mtab &&
445                 error "$MOUNT entry in mtab after unmount"
446         pass
447 }
448 run_test 5d "mount with ost down"
449
450 test_5e() {
451         grep " $MOUNT " /etc/mtab &&
452                 error false "unexpected entry in mtab before mount" && return 10
453
454         start_mds || error "MDS start failed"
455         start_ost || error "OST start failed"
456
457         #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
458         do_facet client "$LCTL set_param fail_loc=0x80000506"
459         mount_client $MOUNT || echo "mount failed (not fatal)"
460         cleanup || error "cleanup failed with $?"
461         grep " $MOUNT " /etc/mtab &&
462                 error "$MOUNT entry in mtab after unmount"
463         pass
464 }
465 run_test 5e "delayed connect, don't crash (bug 10268)"
466
467 test_5f() {
468         if combined_mgs_mds ; then
469                 skip "combined mgs and mds"
470                 return 0
471         fi
472
473         grep " $MOUNT " /etc/mtab &&
474                 error false "unexpected entry in mtab before mount" && return 10
475
476         local rc=0
477         start_ost || error "OST start failed"
478         mount_client $MOUNT &
479         local pid=$!
480         echo client_mount pid is $pid
481
482         sleep 5
483
484         if ! ps -f -p $pid >/dev/null; then
485                 wait $pid
486                 rc=$?
487                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
488                 error "mount returns $rc, expected to hang"
489                 rc=11
490                 cleanup || error "cleanup failed with $?"
491                 return $rc
492         fi
493
494         # start mds
495         start_mds || error "start MDS failed"
496
497         # mount should succeed after start mds
498         wait $pid
499         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
500         cleanup || error "final call to cleanup failed with rc $?"
501 }
502 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
503
504 test_6() {
505         setup
506         manual_umount_client
507         mount_client $MOUNT || error "mount_client $MOUNT failed"
508         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
509         cleanup || error "cleanup failed with rc $?"
510 }
511 run_test 6 "manual umount, then mount again"
512
513 test_7() {
514         setup
515         manual_umount_client
516         cleanup_nocli || error "cleanup_nocli failed with $?"
517 }
518 run_test 7 "manual umount, then cleanup"
519
520 test_8() {
521         setup
522         mount_client $MOUNT2 || error "mount_client $MOUNT2 failed"
523         check_mount2 || error "check_mount2 failed"
524         umount_client $MOUNT2 || error "umount_client $MOUNT2 failed"
525         cleanup || error "cleanup failed with rc $?"
526 }
527 run_test 8 "double mount setup"
528
529 test_9() {
530         start_ost || error "OST start failed"
531
532         do_facet ost1 $LCTL set_param debug=\'inode trace\' ||
533                 error "do_facet ost1 set_param inode trace failed."
534         do_facet ost1 $LCTL set_param subsystem_debug=\'mds ost\' ||
535                 error "do_facet ost1 set_param debug mds ost failed."
536
537         CHECK_PTLDEBUG="`do_facet ost1 $LCTL get_param -n debug`"
538         if [ "$CHECK_PTLDEBUG" ] && { \
539            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
540            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
541                 echo "lnet.debug success"
542         else
543                 error "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
544         fi
545         CHECK_SUBSYS="`do_facet ost1 $LCTL get_param -n subsystem_debug`"
546         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
547                 echo "lnet.subsystem_debug success"
548         else
549                 error "lnet.subsystem_debug: want 'mds ost' got '$CHECK_SUBSYS'"
550         fi
551         stop_ost || error "Unable to stop OST1"
552 }
553 run_test 9 "test ptldebug and subsystem for mkfs"
554
555 is_blkdev () {
556         local facet=$1
557         local dev=$2
558         local size=${3:-""}
559
560         local rc=0
561         do_facet $facet "test -b $dev" || rc=1
562         if [[ "$size" ]]; then
563                 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
564                            count=1 skip=$size 2>&1" |
565                         awk '($3 == "in") { print $1 }')
566                 [[ $in  = "1+0" ]] || rc=1
567         fi
568         return $rc
569 }
570
571 #
572 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
573 # But with new MDS stack we don't care about the mode of local objects
574 # anymore, so this test is removed. See bug 22944 for more details.
575 #
576
577 test_17() {
578         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
579                 skip "Only applicable to ldiskfs-based MDTs"
580                 return
581         fi
582
583         setup
584         check_mount || error "check_mount failed"
585         cleanup || error "cleanup failed with rc $?"
586
587         echo "Remove mds config log"
588         if ! combined_mgs_mds ; then
589                 stop mgs
590         fi
591
592         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' \
593                       $(mgsdevname) || return \$?" ||
594                 error "do_facet mgs failed with $?"
595
596         if ! combined_mgs_mds ; then
597                 start_mgs
598         fi
599
600         start_ost || error "OST start failed"
601         start_mds && error "MDS start succeeded, but should fail"
602         reformat_and_config
603 }
604 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
605
606 test_18() {
607         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
608                 skip "Only applicable to ldiskfs-based MDTs"
609                 return
610         fi
611
612         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
613
614         local MIN=2000000
615
616         local OK=
617         # check if current MDSSIZE is large enough
618         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE &&
619                 log "use MDSSIZE=$MDSSIZE"
620
621         # check if the global config has a large enough MDSSIZE
622         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] &&
623                 [ $STORED_MDSSIZE -ge $MIN ] &&
624                 OK=1 && myMDSSIZE=$STORED_MDSSIZE &&
625                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
626
627         # check if the block device is large enough
628         is_blkdev $SINGLEMDS $MDSDEV $MIN
629         local large_enough=$?
630         if [ -n "$OK" ]; then
631                 [ $large_enough -ne 0 ] && OK=""
632         else
633                 [ $large_enough -eq 0 ] && OK=1 && myMDSSIZE=$MIN &&
634                         log "use device $MDSDEV with MIN=$MIN"
635         fi
636
637         # check if a loopback device has enough space for fs metadata (5%)
638
639         if [ -z "$OK" ]; then
640                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! \
641                               -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
642                         awk '($1 != "Filesystem") { print $4 }')
643                 ! [ -z "$SPACE" ] && [ $SPACE -gt $((MIN / 20)) ] &&
644                         OK=1 && myMDSSIZE=$MIN &&
645                         log "use file $MDSDEV with MIN=$MIN"
646         fi
647
648         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
649
650         echo "mount mds with large journal..."
651
652         local OLD_MDSSIZE=$MDSSIZE
653         MDSSIZE=$myMDSSIZE
654
655         reformat_and_config
656         echo "mount lustre system..."
657         setup
658         check_mount || error "check_mount failed"
659
660         echo "check journal size..."
661         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
662         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
663                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
664         else
665                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
666         fi
667
668         cleanup || error "cleanup failed with rc $?"
669
670         MDSSIZE=$OLD_MDSSIZE
671         reformat_and_config
672 }
673 run_test 18 "check mkfs creates large journals"
674
675 test_19a() {
676         start_mds || error "MDS start failed"
677         stop_mds || error "Unable to stop MDS"
678 }
679 run_test 19a "start/stop MDS without OSTs"
680
681 test_19b() {
682         start_ost || error "Unable to start OST1"
683         stop_ost || error "Unable to stop OST1"
684 }
685 run_test 19b "start/stop OSTs without MDS"
686
687 test_20() {
688         # first format the ost/mdt
689         start_mds || error "MDS start failed"
690         start_ost || error "Unable to start OST1"
691         mount_client $MOUNT || error "mount_client $MOUNT failed"
692         check_mount || error "check_mount failed"
693         rm -f $DIR/$tfile || error "remove $DIR/$tfile failed."
694         remount_client ro $MOUNT || error "remount_client with ro failed"
695         touch $DIR/$tfile && error "$DIR/$tfile created incorrectly"
696         [ -e $DIR/$tfile ] && error "$DIR/$tfile exists incorrectly"
697         remount_client rw $MOUNT || error "remount_client with rw failed"
698         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
699         MCNT=$(grep -c $MOUNT /etc/mtab)
700         [ "$MCNT" -ne 1 ] && error "$MOUNT in /etc/mtab $MCNT times"
701         umount_client $MOUNT
702         stop_mds || error "Unable to stop MDS"
703         stop_ost || error "Unable to stop OST1"
704 }
705 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
706
707 test_21a() {
708         start_mds || error "MDS start failed"
709         start_ost || error "unable to start OST1"
710         wait_osc_import_state mds ost FULL
711         stop_ost || error "unable to stop OST1"
712         stop_mds || error "unable to stop MDS"
713 }
714 run_test 21a "start mds before ost, stop ost first"
715
716 test_21b() {
717         start_ost || error "unable to start OST1"
718         start_mds || error "MDS start failed"
719         wait_osc_import_state mds ost FULL
720         stop_mds || error "unable to stop MDS"
721         stop_ost || error "unable to stop OST1"
722 }
723 run_test 21b "start ost before mds, stop mds first"
724
725 test_21c() {
726         start_ost || error "Unable to start OST1"
727         start_mds || error "MDS start failed"
728         start_ost2 || error "Unable to start OST2"
729         wait_osc_import_state mds ost2 FULL
730         stop_ost || error "Unable to stop OST1"
731         stop_ost2 || error "Unable to stop OST2"
732         stop_mds || error "Unable to stop MDS"
733         #writeconf to remove all ost2 traces for subsequent tests
734         writeconf_or_reformat
735 }
736 run_test 21c "start mds between two osts, stop mds last"
737
738 test_21d() {
739         if combined_mgs_mds ; then
740                 skip "need separate mgs device" && return 0
741         fi
742         stopall
743
744         reformat
745
746         start_mgs || error "unable to start MGS"
747         start_ost || error "unable to start OST1"
748         start_ost2 || error "unable to start OST2"
749         start_mds || error "MDS start failed"
750         wait_osc_import_state mds ost2 FULL
751
752         stop_ost || error "Unable to stop OST1"
753         stop_ost2 || error "Unable to stop OST2"
754         stop_mds || error "Unable to stop MDS"
755         stop_mgs
756         #writeconf to remove all ost2 traces for subsequent tests
757         writeconf_or_reformat
758         start_mgs || error "unable to start MGS"
759 }
760 run_test 21d "start mgs then ost and then mds"
761
762 test_22() {
763         start_mds || error "MDS start failed"
764
765         echo "Client mount with ost in logs, but none running"
766         start_ost || error "unable to start OST1"
767         # wait until mds connected to ost and open client connection
768         wait_osc_import_state mds ost FULL
769         stop_ost || error "unable to stop OST1"
770         mount_client $MOUNT || error "mount_client $MOUNT failed"
771         # check_mount will block trying to contact ost
772         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
773         rm -f $DIR/$tfile || error "remove $DIR/$tfile failed"
774         umount_client $MOUNT
775         pass
776
777         echo "Client mount with a running ost"
778         start_ost || error "unable to start OST1"
779         if $GSS; then
780                 # if gss enabled, wait full time to let connection from
781                 # mds to ost be established, due to the mismatch between
782                 # initial connect timeout and gss context negotiation timeout.
783                 # This perhaps could be remove after AT landed.
784                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
785                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
786         fi
787         mount_client $MOUNT || error "mount_client $MOUNT failed"
788         wait_osc_import_state mds ost FULL
789         wait_osc_import_state client ost FULL
790         check_mount || error "check_mount failed"
791         pass
792
793         cleanup || error "cleanup failed with rc $?"
794 }
795 run_test 22 "start a client before osts (should return errs)"
796
797 test_23a() {    # was test_23
798         setup
799         # fail mds
800         stop $SINGLEMDS || error "failed to stop $SINGLEMDS"
801         # force down client so that recovering mds waits for reconnect
802         local running=$(grep -c $MOUNT /proc/mounts) || true
803         if [ $running -ne 0 ]; then
804                 echo "Stopping client $MOUNT (opts: -f)"
805                 umount -f $MOUNT
806         fi
807
808         # enter recovery on failed mds
809         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
810         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "MDS start failed"
811         # try to start a new client
812         mount_client $MOUNT &
813         sleep 5
814         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
815         MOUNT_LUSTRE_PID=$(ps -ef | grep mount.lustre |
816                            grep -v grep | awk '{print $2}')
817         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
818         ps --ppid $MOUNT_PID
819         ps --ppid $MOUNT_LUSTRE_PID
820         echo "waiting for mount to finish"
821         ps -ef | grep mount
822         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
823         # SIGTERM works but it does not spread to offspring processses
824         kill -s TERM $MOUNT_PID
825         kill -s TERM $MOUNT_LUSTRE_PID
826         # we can not wait $MOUNT_PID because it is not a child of this shell
827         local PID1
828         local PID2
829         local WAIT=0
830         local MAX_WAIT=30
831         local sleep=1
832         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
833                 sleep $sleep
834                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
835                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
836                 echo PID1=$PID1
837                 echo PID2=$PID2
838                 [ -z "$PID1" -a -z "$PID2" ] && break
839                 echo "waiting for mount to finish ... "
840                 WAIT=$(( WAIT + sleep))
841         done
842         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
843                 error "MOUNT_PID $MOUNT_PID and "\
844                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
845                 ps -ef | grep mount
846         fi
847         stop_mds || error "stopping MDSes failed"
848         stop_ost || error "stopping OSSes failed"
849 }
850 run_test 23a "interrupt client during recovery mount delay"
851
852 umount_client $MOUNT
853 cleanup_nocli
854
855 test_23b() {    # was test_23
856         start_mds || error "MDS start failed"
857         start_ost || error "Unable to start OST1"
858         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
859         $LCTL set_param fail_loc=0x80000313
860         mount_client $MOUNT
861         cleanup || error "cleanup failed with rc $?"
862 }
863 run_test 23b "Simulate -EINTR during mount"
864
865 fs2mds_HOST=$mds_HOST
866 fs2ost_HOST=$ost_HOST
867
868 MDSDEV1_2=$fs2mds_DEV
869 OSTDEV1_2=$fs2ost_DEV
870 OSTDEV2_2=$fs3ost_DEV
871
872 cleanup_fs2() {
873         trap 0
874         echo "umount $MOUNT2 ..."
875         umount $MOUNT2 || true
876         echo "stopping fs2mds ..."
877         stop fs2mds -f || true
878         echo "stopping fs2ost ..."
879         stop fs2ost -f || true
880 }
881
882 test_24a() {
883         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
884
885         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
886                 is_blkdev $SINGLEMDS $MDSDEV &&
887                 skip_env "mixed loopback and real device not working" && return
888         fi
889
890         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
891
892         local fs2mdsdev=$(mdsdevname 1_2)
893         local fs2ostdev=$(ostdevname 1_2)
894         local fs2mdsvdev=$(mdsvdevname 1_2)
895         local fs2ostvdev=$(ostvdevname 1_2)
896
897         # test 8-char fsname as well
898         local FSNAME2=test1234
899
900         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --nomgs --mgsnode=$MGSNID \
901                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
902
903         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --fsname=${FSNAME2} \
904                 --reformat $fs2ostdev $fs2ostvdev || exit 10
905
906         setup
907         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
908         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
909         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
910         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
911         # 1 still works
912         check_mount || error "check_mount failed"
913         # files written on 1 should not show up on 2
914         cp /etc/passwd $DIR/$tfile
915         sleep 10
916         [ -e $MOUNT2/$tfile ] && error "File bleed"
917         # 2 should work
918         sleep 5
919         cp /etc/passwd $MOUNT2/$tfile ||
920                 error "cp /etc/passwd $MOUNT2/$tfile failed"
921         rm $MOUNT2/$tfile || error "remove $MOUNT2/$tfile failed"
922         # 2 is actually mounted
923         grep $MOUNT2' ' /proc/mounts > /dev/null || error "$MOUNT2 not mounted"
924         # failover
925         facet_failover fs2mds
926         facet_failover fs2ost
927         df
928         umount_client $MOUNT
929         # the MDS must remain up until last MDT
930         stop_mds
931         MDS=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
932               awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
933         [ -z "$MDS" ] && error "No MDT"
934         cleanup_fs2
935         cleanup_nocli || error "cleanup_nocli failed with rc $?"
936 }
937 run_test 24a "Multiple MDTs on a single node"
938
939 test_24b() {
940         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
941
942         if [ -z "$fs2mds_DEV" ]; then
943                 local dev=${SINGLEMDS}_dev
944                 local MDSDEV=${!dev}
945                 is_blkdev $SINGLEMDS $MDSDEV &&
946                 skip_env "mixed loopback and real device not working" && return
947         fi
948
949         local fs2mdsdev=$(mdsdevname 1_2)
950         local fs2mdsvdev=$(mdsvdevname 1_2)
951
952         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --mgs --fsname=${FSNAME}2 \
953                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
954         setup
955         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS &&
956                 error "start MDS should fail"
957         stop fs2mds -f
958         cleanup || error "cleanup failed with rc $?"
959 }
960 run_test 24b "Multiple MGSs on a single node (should return err)"
961
962 test_25() {
963         setup
964         check_mount || error "check_mount failed"
965         local MODULES=$($LCTL modules | awk '{ print $2 }')
966         rmmod $MODULES 2>/dev/null || true
967         cleanup || error "cleanup failed with $?"
968 }
969 run_test 25 "Verify modules are referenced"
970
971 test_26() {
972         load_modules
973         # we need modules before mount for sysctl, so make sure...
974         do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
975         #define OBD_FAIL_MDS_FS_SETUP            0x135
976         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000135"
977         start_mds && error "MDS started but should not have started"
978         $LCTL get_param -n devices
979         DEVS=$($LCTL get_param -n devices | egrep -v MG | wc -l)
980         [ $DEVS -gt 0 ] && error "number of devices is $DEVS, should be zero"
981         # start mds to drop writeconf setting
982         start_mds || error "Unable to start MDS"
983         stop_mds || error "Unable to stop MDS"
984         unload_modules_conf || error "unload_modules_conf failed with $?"
985 }
986 run_test 26 "MDT startup failure cleans LOV (should return errs)"
987
988 test_27a() {
989         start_ost || error "Unable to start OST1"
990         start_mds || error "Unable to start MDS"
991         echo "Requeue thread should have started: "
992         ps -e | grep ll_cfg_requeue
993         set_conf_param_and_check ost1                                         \
994            "$LCTL get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" \
995            "$FSNAME-OST0000.ost.client_cache_seconds" ||
996                 error "set_conf_param_and_check ost1 failed"
997         cleanup_nocli || error "cleanup_nocli failed with rc $?"
998 }
999 run_test 27a "Reacquire MGS lock if OST started first"
1000
1001 test_27b() {
1002         # FIXME. ~grev
1003         setup
1004         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
1005                         awk '($3 ~ "mdt" && $4 ~ "MDT0000") { print $4 }')
1006
1007         facet_failover $SINGLEMDS
1008         set_conf_param_and_check $SINGLEMDS                             \
1009                 "$LCTL get_param -n mdt.$device.identity_acquire_expire" \
1010                 "$device.mdt.identity_acquire_expire" ||
1011                 error "set_conf_param_and_check $SINGLEMDS failed"
1012         set_conf_param_and_check client                          \
1013                 "$LCTL get_param -n mdc.$device-mdc-*.max_rpcs_in_flight"\
1014                 "$device.mdc.max_rpcs_in_flight" ||
1015                 error "set_conf_param_and_check client failed"
1016         check_mount
1017         cleanup || error "cleanup failed with $?"
1018 }
1019 run_test 27b "Reacquire MGS lock after failover"
1020
1021 test_28() {
1022         setup
1023         TEST="$LCTL get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1024         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1025         ORIG=$($TEST)
1026         FINAL=$(($ORIG + 1))
1027         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL ||
1028                 error "first set_conf_param_and_check client failed"
1029         FINAL=$(($FINAL + 1))
1030         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL ||
1031                 error "second set_conf_param_and_check client failed"
1032         umount_client $MOUNT || error "umount_client $MOUNT failed"
1033         mount_client $MOUNT || error "mount_client $MOUNT failed"
1034         RESULT=$($TEST)
1035         if [ $RESULT -ne $FINAL ]; then
1036                 error "New config not seen: wanted $FINAL got $RESULT"
1037         else
1038                 echo "New config success: got $RESULT"
1039         fi
1040         set_conf_param_and_check client "$TEST" "$PARAM" $ORIG ||
1041                 error "third set_conf_param_and_check client failed"
1042         cleanup || error "cleanup failed with rc $?"
1043 }
1044 run_test 28 "permanent parameter setting"
1045
1046 test_28a() { # LU-4221
1047         [[ $(lustre_version_code ost1) -ge $(version_code 2.5.52) ]] ||
1048                 { skip "Need OST version at least 2.5.52" && return 0; }
1049         [ "$(facet_fstype ost1)" = "zfs" ] &&
1050                 skip "LU-4221: no such proc params for ZFS OSTs" && return
1051
1052         local name
1053         local param
1054         local cmd
1055         local old
1056         local new
1057         local device="$FSNAME-OST0000"
1058
1059         setup
1060
1061         # In this test we will set three kinds of proc parameters with
1062         # lctl conf_param:
1063         # 1. the ones moved from the OFD to the OSD, and only their
1064         #    symlinks kept in obdfilter
1065         # 2. non-symlink ones in the OFD
1066         # 3. non-symlink ones in the OSD
1067
1068         # Check 1.
1069         # prepare a symlink parameter in the OFD
1070         name="writethrough_cache_enable"
1071         param="$device.ost.$name"
1072         cmd="$LCTL get_param -n obdfilter.$device.$name"
1073
1074         # conf_param the symlink parameter in the OFD
1075         old=$(do_facet ost1 $cmd)
1076         new=$(((old + 1) % 2))
1077         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1078                 error "lctl conf_param $device.ost.$param=$new failed"
1079
1080         # conf_param the target parameter in the OSD
1081         param="$device.osd.$name"
1082         cmd="$LCTL get_param -n osd-*.$device.$name"
1083         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1084                 error "lctl conf_param $device.osd.$param=$old failed"
1085
1086         # Check 2.
1087         # prepare a non-symlink parameter in the OFD
1088         name="client_cache_seconds"
1089         param="$device.ost.$name"
1090         cmd="$LCTL get_param -n obdfilter.$device.$name"
1091
1092         # conf_param the parameter in the OFD
1093         old=$(do_facet ost1 $cmd)
1094         new=$((old * 2))
1095         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1096                 error "lctl conf_param $device.ost.$param=$new failed"
1097         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1098                 error "lctl conf_param $device.ost.$param=$old failed"
1099
1100         # Check 3.
1101         # prepare a non-symlink parameter in the OSD
1102         name="lma_self_repair"
1103         param="$device.osd.$name"
1104         cmd="$LCTL get_param -n osd-*.$device.$name"
1105
1106         # conf_param the parameter in the OSD
1107         old=$(do_facet ost1 $cmd)
1108         new=$(((old + 1) % 2))
1109         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1110                 error "lctl conf_param $device.osd.$param=$new failed"
1111         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1112                 error "lctl conf_param $device.osd.$param=$old failed"
1113
1114         cleanup || error "cleanup failed with $?"
1115 }
1116 run_test 28a "set symlink parameters permanently with conf_param"
1117
1118 test_29() {
1119         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
1120         setup > /dev/null 2>&1
1121         start_ost2 || error "Unable to start OST2"
1122         sleep 10
1123
1124         local PARAM="$FSNAME-OST0001.osc.active"
1125         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
1126         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1127
1128         ACTV=$($LCTL get_param -n $PROC_ACT)
1129         DEAC=$((1 - $ACTV))
1130         set_conf_param_and_check client \
1131                 "$LCTL get_param -n $PROC_ACT" "$PARAM" $DEAC ||
1132                 error "set_conf_param_and_check client failed"
1133         # also check ost_server_uuid status
1134         RESULT=$($LCTL get_param -n $PROC_UUID | grep DEACTIV)
1135         if [ -z "$RESULT" ]; then
1136                 error "Client not deactivated: $($LCTL get_param \
1137                        -n $PROC_UUID)"
1138         else
1139                 echo "Live client success: got $RESULT"
1140         fi
1141
1142         # check MDTs too
1143         for num in $(seq $MDSCOUNT); do
1144                 local mdtosc=$(get_mdtosc_proc_path mds${num} $FSNAME-OST0001)
1145                 local MPROC="osc.$mdtosc.active"
1146                 local MAX=30
1147                 local WAIT=0
1148                 while [ 1 ]; do
1149                         sleep 5
1150                         RESULT=$(do_facet mds${num} "$LCTL get_param -n $MPROC")
1151                         [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
1152                         if [ $RESULT -eq $DEAC ]; then
1153                                 echo -n "MDT deactivated also after"
1154                                 echo "$WAIT sec (got $RESULT)"
1155                                 break
1156                         fi
1157                         WAIT=$((WAIT + 5))
1158                         if [ $WAIT -eq $MAX ]; then
1159                                 error "MDT active: wanted $DEAC got $RESULT"
1160                         fi
1161                         echo "Waiting $(($MAX - $WAIT))secs for MDT deactivated"
1162                 done
1163         done
1164         # test new client starts deactivated
1165         umount_client $MOUNT || error "umount_client $MOUNT failed"
1166         mount_client $MOUNT || error "mount_client $MOUNT failed"
1167         RESULT=$($LCTL get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1168         if [ -z "$RESULT" ]; then
1169                 error "New client start active: $(lctl get_param -n $PROC_UUID)"
1170         else
1171                 echo "New client success: got $RESULT"
1172         fi
1173
1174         # make sure it reactivates
1175         set_conf_param_and_check client \
1176                 "$LCTL get_param -n $PROC_ACT" "$PARAM" $ACTV ||
1177                 error "lctl get_param $PROC_ACT $PARAM $ACTV failed"
1178
1179         umount_client $MOUNT
1180         stop_ost2 || error "Unable to stop OST2"
1181         cleanup_nocli || error "cleanup_nocli failed with $?"
1182         #writeconf to remove all ost2 traces for subsequent tests
1183         writeconf_or_reformat
1184 }
1185 run_test 29 "permanently remove an OST"
1186
1187 test_30a() {
1188         setup
1189
1190         echo Big config llog
1191         TEST="$LCTL get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1192         ORIG=$($TEST)
1193         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1194         for i in ${LIST[@]}; do
1195                 set_conf_param_and_check client "$TEST" \
1196                         "$FSNAME.llite.max_read_ahead_whole_mb" $i ||
1197                         error "Set $FSNAME.llite.max_read_ahead_whole_mb failed"
1198         done
1199         # make sure client restart still works
1200         umount_client $MOUNT
1201         mount_client $MOUNT || error "mount_client $MOUNT failed"
1202         [ "$($TEST)" -ne "$i" ] &&
1203                 error "Param didn't stick across restart $($TEST) != $i"
1204         pass
1205
1206         echo Erase parameter setting
1207         do_facet mgs "$LCTL conf_param \
1208                       -d $FSNAME.llite.max_read_ahead_whole_mb" ||
1209                 error "Erase param $FSNAME.llite.max_read_ahead_whole_mb failed"
1210         umount_client $MOUNT
1211         mount_client $MOUNT || error "mount_client $MOUNT failed"
1212         FINAL=$($TEST)
1213         echo "deleted (default) value=$FINAL, orig=$ORIG"
1214         # assumes this parameter started at the default value
1215         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1216
1217         cleanup || error "cleanup failed with rc $?"
1218 }
1219 run_test 30a "Big config llog and conf_param deletion"
1220
1221 test_30b() {
1222         setup
1223
1224         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1225         # numerical part of it. Hopefully that's not already a failover address
1226         # for the server.
1227         OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
1228         ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1229         NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1230         NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1231         echo "Using fake nid $NEW"
1232
1233         TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1234                 grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1235         set_conf_param_and_check client "$TEST" \
1236                 "$FSNAME-OST0000.failover.node" $NEW ||
1237                 error "didn't add failover nid $NEW"
1238         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1239                 grep failover_nids)
1240         echo $NIDS
1241         # The NIDS value is the failover nid strings and "[" and "]". So
1242         # we need to subtract the space taken by the delimiters. This has
1243         # changed from earlier version of Lustre but this test is run only
1244         # locally so this change will not break interop. See LU-3386
1245         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 3))
1246         echo "should have 2 failover nids: $NIDCOUNT"
1247         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1248         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" ||
1249                 error "conf_param delete failed"
1250         umount_client $MOUNT
1251         mount_client $MOUNT || error "mount_client $MOUNT failed"
1252
1253         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1254                 grep failover_nids)
1255         echo $NIDS
1256         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 3))
1257         echo "only 1 final nid should remain: $NIDCOUNT"
1258         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1259
1260         cleanup || error "cleanup failed with rc $?"
1261 }
1262 run_test 30b "Remove failover nids"
1263
1264 test_31() { # bug 10734
1265         # ipaddr must not exist
1266         $MOUNT_CMD 4.3.2.1@tcp:/lustre $MOUNT || true
1267         cleanup || error "cleanup failed with rc $?"
1268 }
1269 run_test 31 "Connect to non-existent node (shouldn't crash)"
1270
1271
1272 T32_QID=60000
1273 T32_BLIMIT=20480 # Kbytes
1274 T32_ILIMIT=2
1275
1276 #
1277 # This is not really a test but a tool to create new disk
1278 # image tarballs for the upgrade tests.
1279 #
1280 # Disk image tarballs should be created on single-node
1281 # clusters by running this test with default configurations
1282 # plus a few mandatory environment settings that are verified
1283 # at the beginning of the test.
1284 #
1285 test_32newtarball() {
1286         local version
1287         local dst=.
1288         local src=/etc/rc.d
1289         local tmp=$TMP/t32_image_create
1290
1291         if [ $FSNAME != t32fs -o $MDSCOUNT -ne 1 -o                                                             \
1292                  \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o $OSTCOUNT -ne 1 -o                      \
1293                  -z "$OSTDEV1" ]; then
1294                 error "Needs FSNAME=t32fs MDSCOUNT=1 MDSDEV1=<nonexistent_file>"        \
1295                           "(or MDSDEV, in the case of b1_8) OSTCOUNT=1"                                 \
1296                           "OSTDEV1=<nonexistent_file>"
1297         fi
1298
1299         mkdir $tmp || {
1300                 echo "Found stale $tmp"
1301                 return 1
1302         }
1303
1304         mkdir $tmp/src || return 1
1305         tar cf - -C $src . | tar xf - -C $tmp/src
1306         dd if=/dev/zero of=$tmp/src/t32_qf_old bs=1M \
1307                 count=$(($T32_BLIMIT / 1024 / 2))
1308         chown $T32_QID.$T32_QID $tmp/src/t32_qf_old
1309
1310         # format ost with comma-separated NIDs to verify LU-4460
1311         local failnid="$(h2$NETTYPE 1.2.3.4),$(h2$NETTYPE 4.3.2.1)"
1312         MGSNID="$MGSNID,$MGSNID" OSTOPT="--failnode=$failnid" formatall
1313
1314         setupall
1315
1316         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1317                 $LFS quotacheck -ug /mnt/$FSNAME
1318         $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
1319                 /mnt/$FSNAME
1320
1321         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1322         stopall
1323
1324         mkdir $tmp/img || return 1
1325
1326         setupall
1327         pushd /mnt/$FSNAME
1328         ls -Rni --time-style=+%s >$tmp/img/list
1329         find . ! -name .lustre -type f -exec sha1sum {} \; |
1330                 sort -k 2 >$tmp/img/sha1sums
1331         popd
1332         $LCTL get_param -n version | head -n 1 |
1333                 sed -e 's/^lustre: *//' >$tmp/img/commit
1334
1335         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1336                 $LFS quotaon -ug /mnt/$FSNAME
1337         $LFS quota -u $T32_QID -v /mnt/$FSNAME
1338         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1339                 awk 'BEGIN { num='1' } { if ($1 == "'/mnt/$FSNAME'") \
1340                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1341                 | tr -d "*" > $tmp/img/bspace
1342         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1343                 awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
1344                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1345                 | tr -d "*" > $tmp/img/ispace
1346
1347         stopall
1348
1349         pushd $tmp/src
1350         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1351         popd
1352
1353         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1354                 echo "Data verification failed"
1355         fi
1356
1357         uname -r >$tmp/img/kernel
1358         uname -m >$tmp/img/arch
1359
1360         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1361         mv $OSTDEV1 $tmp/img
1362
1363         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1364                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1365         dst=$(cd $dst; pwd)
1366         pushd $tmp/img
1367         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1368         popd
1369
1370         rm -r $tmp
1371 }
1372 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1373
1374 #
1375 # The list of applicable tarballs is returned via the caller's
1376 # variable "tarballs".
1377 #
1378 t32_check() {
1379         local node=$(facet_active_host $SINGLEMDS)
1380         local r="do_node $node"
1381
1382         if [ "$CLIENTONLY" ]; then
1383                 skip "Client-only testing"
1384                 exit 0
1385         fi
1386
1387         if ! $r which $TUNEFS; then
1388                 skip_env "tunefs.lustre required on $node"
1389                 exit 0
1390         fi
1391
1392         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1393
1394         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 -name \'disk*-$IMGTYPE.tar.bz2\')
1395
1396         if [ -z "$tarballs" ]; then
1397                 skip "No applicable tarballs found"
1398                 exit 0
1399         fi
1400 }
1401
1402 t32_test_cleanup() {
1403         local tmp=$TMP/t32
1404         local fstype=$(facet_fstype $SINGLEMDS)
1405         local rc=$?
1406
1407         if $shall_cleanup_lustre; then
1408                 umount $tmp/mnt/lustre || rc=$?
1409         fi
1410         if $shall_cleanup_mdt; then
1411                 $r umount -d $tmp/mnt/mdt || rc=$?
1412         fi
1413         if $shall_cleanup_mdt1; then
1414                 $r umount -d $tmp/mnt/mdt1 || rc=$?
1415         fi
1416         if $shall_cleanup_ost; then
1417                 $r umount -d $tmp/mnt/ost || rc=$?
1418         fi
1419
1420         $r rm -rf $tmp
1421         rm -rf $tmp
1422         if [ $fstype == "zfs" ]; then
1423                 $r $ZPOOL destroy t32fs-mdt1 || rc=$?
1424                 $r $ZPOOL destroy t32fs-ost1 || rc=$?
1425         fi
1426         return $rc
1427 }
1428
1429 t32_bits_per_long() {
1430         #
1431         # Yes, this is not meant to be perfect.
1432         #
1433         case $1 in
1434                 ppc64|x86_64)
1435                         echo -n 64;;
1436                 i*86)
1437                         echo -n 32;;
1438         esac
1439 }
1440
1441 t32_reload_modules() {
1442         local node=$1
1443         local all_removed=false
1444         local i=0
1445
1446         while ((i < 20)); do
1447                 echo "Unloading modules on $node: Attempt $i"
1448                 do_rpc_nodes $node $LUSTRE_RMMOD $(facet_fstype $SINGLEMDS) &&
1449                         all_removed=true
1450                 do_rpc_nodes $node check_mem_leak || return 1
1451                 if $all_removed; then
1452                         do_rpc_nodes $node load_modules
1453                         return 0
1454                 fi
1455                 sleep 5
1456                 i=$((i + 1))
1457         done
1458         echo "Unloading modules on $node: Given up"
1459         return 1
1460 }
1461
1462 t32_wait_til_devices_gone() {
1463         local node=$1
1464         local devices
1465         local loops
1466         local i=0
1467
1468         echo wait for devices to go
1469         while ((i < 20)); do
1470                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1471                 loops=$(do_rpc_nodes $node losetup -a | grep -c t32)
1472                 ((devices == 0 && loops == 0)) && return 0
1473                 sleep 5
1474                 i=$((i + 1))
1475         done
1476         echo "waiting for dev on $node: dev $devices loop $loops given up"
1477         do_rpc_nodes $node "losetup -a"
1478         do_rpc_nodes $node "$LCTL devices_list"
1479         return 1
1480 }
1481
1482 t32_verify_quota() {
1483         local node=$1
1484         local fsname=$2
1485         local mnt=$3
1486         local fstype=$(facet_fstype $SINGLEMDS)
1487         local qval
1488         local cmd
1489
1490         $LFS quota -u $T32_QID -v $mnt
1491
1492         qval=$($LFS quota -v -u $T32_QID $mnt |
1493                 awk 'BEGIN { num='1' } { if ($1 == "'$mnt'") \
1494                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1495                 | tr -d "*")
1496         [ $qval -eq $img_bspace ] || {
1497                 echo "bspace, act:$qval, exp:$img_bspace"
1498                 return 1
1499         }
1500
1501         qval=$($LFS quota -v -u $T32_QID $mnt |
1502                 awk 'BEGIN { num='5' } { if ($1 == "'$mnt'") \
1503                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1504                 | tr -d "*")
1505         [ $qval -eq $img_ispace ] || {
1506                 echo "ispace, act:$qval, exp:$img_ispace"
1507                 return 1
1508         }
1509
1510         qval=$($LFS quota -v -u $T32_QID $mnt |
1511                 awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
1512                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1513                 | tr -d "*")
1514         [ $qval -eq $T32_BLIMIT ] || {
1515                 echo "blimit, act:$qval, exp:$T32_BLIMIT"
1516                 return 1
1517         }
1518
1519         qval=$($LFS quota -v -u $T32_QID $mnt |
1520                 awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
1521                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1522                 | tr -d "*")
1523         [ $qval -eq $T32_ILIMIT ] || {
1524                 echo "ilimit, act:$qval, exp:$T32_ILIMIT"
1525                 return 1
1526         }
1527
1528         do_node $node $LCTL conf_param $fsname.quota.mdt=ug
1529         cmd="$LCTL get_param -n osd-$fstype.$fsname-MDT0000"
1530         cmd=$cmd.quota_slave.enabled
1531         wait_update $node "$cmd" "ug" || {
1532                 echo "Enable mdt quota failed"
1533                 return 1
1534         }
1535
1536         do_node $node $LCTL conf_param $fsname.quota.ost=ug
1537         cmd="$LCTL get_param -n osd-$fstype.$fsname-OST0000"
1538         cmd=$cmd.quota_slave.enabled
1539         wait_update $node "$cmd" "ug" || {
1540                 echo "Enable ost quota failed"
1541                 return 1
1542         }
1543
1544         chmod 0777 $mnt
1545         runas -u $T32_QID -g $T32_QID dd if=/dev/zero of=$mnt/t32_qf_new \
1546                 bs=1M count=$(($T32_BLIMIT / 1024)) oflag=sync && {
1547                 echo "Write succeed, but expect -EDQUOT"
1548                 return 1
1549         }
1550         rm -f $mnt/t32_qf_new
1551
1552         runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
1553                 $T32_ILIMIT && {
1554                 echo "Create succeed, but expect -EDQUOT"
1555                 return 1
1556         }
1557         unlinkmany $mnt/t32_qf_ $T32_ILIMIT
1558
1559         return 0
1560 }
1561
1562 t32_test() {
1563         local tarball=$1
1564         local writeconf=$2
1565         local dne_upgrade=${dne_upgrade:-"no"}
1566         local ff_convert=${ff_convert:-"no"}
1567         local shall_cleanup_mdt=false
1568         local shall_cleanup_mdt1=false
1569         local shall_cleanup_ost=false
1570         local shall_cleanup_lustre=false
1571         local node=$(facet_active_host $SINGLEMDS)
1572         local r="do_node $node"
1573         local node2=$(facet_active_host mds2)
1574         local tmp=$TMP/t32
1575         local img_commit
1576         local img_kernel
1577         local img_arch
1578         local img_bspace
1579         local img_ispace
1580         local fsname=t32fs
1581         local nid=$($r $LCTL list_nids | head -1)
1582         local mopts
1583         local uuid
1584         local nrpcs_orig
1585         local nrpcs
1586         local list
1587         local fstype=$(facet_fstype $SINGLEMDS)
1588         local mdt_dev=$tmp/mdt
1589         local ost_dev=$tmp/ost
1590
1591         trap 'trap - RETURN; t32_test_cleanup' RETURN
1592
1593         mkdir -p $tmp/mnt/lustre || error "mkdir $tmp/mnt/lustre failed"
1594         $r mkdir -p $tmp/mnt/{mdt,ost}
1595         $r tar xjvf $tarball -S -C $tmp || {
1596                 error_noexit "Unpacking the disk image tarball"
1597                 return 1
1598         }
1599         img_commit=$($r cat $tmp/commit)
1600         img_kernel=$($r cat $tmp/kernel)
1601         img_arch=$($r cat $tmp/arch)
1602         img_bspace=$($r cat $tmp/bspace)
1603         img_ispace=$($r cat $tmp/ispace)
1604         echo "Upgrading from $(basename $tarball), created with:"
1605         echo "  Commit: $img_commit"
1606         echo "  Kernel: $img_kernel"
1607         echo "    Arch: $img_arch"
1608         echo "OST version: $(get_lustre_version ost1)"
1609
1610         # The conversion can be made only when both of the following
1611         # conditions are satisfied:
1612         # - ost device img version < 2.3.64
1613         # - ost server version >= 2.5
1614         [ $(version_code $img_commit) -ge $(version_code 2.3.64) -o \
1615                 $(lustre_version_code ost1) -lt $(version_code 2.5.0) ] &&
1616                         ff_convert="no"
1617
1618         if [ $fstype == "zfs" ]; then
1619                 # import pool first
1620                 $r $ZPOOL import -f -d $tmp t32fs-mdt1
1621                 $r $ZPOOL import -f -d $tmp t32fs-ost1
1622                 mdt_dev=t32fs-mdt1/mdt1
1623                 ost_dev=t32fs-ost1/ost1
1624                 wait_update_facet $SINGLEMDS "$ZPOOL list |
1625                         awk '/^t32fs-mdt1/ { print \\\$1 }'" "t32fs-mdt1" || {
1626                                 error_noexit "import zfs pool failed"
1627                                 return 1
1628                         }
1629         fi
1630
1631         $r $LCTL set_param debug="$PTLDEBUG"
1632
1633         $r $TUNEFS --dryrun $mdt_dev || {
1634                 $r losetup -a
1635                 error_noexit "tunefs.lustre before mounting the MDT"
1636                 return 1
1637         }
1638         if [ "$writeconf" ]; then
1639                 mopts=writeconf
1640                 if [ $fstype == "ldiskfs" ]; then
1641                         mopts="loop,$mopts"
1642                         $r $TUNEFS --quota $mdt_dev || {
1643                                 $r losetup -a
1644                                 error_noexit "Enable mdt quota feature"
1645                                 return 1
1646                         }
1647                 fi
1648         else
1649                 if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1650                         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
1651                         { skip "LU-2200: Cannot run over Inifiniband w/o lctl replace_nids "
1652                                 "(Need MGS version at least 2.3.59)"; return 0; }
1653
1654                         local osthost=$(facet_active_host ost1)
1655                         local ostnid=$(do_node $osthost $LCTL list_nids | head -1)
1656
1657                         mopts=nosvc
1658                         if [ $fstype == "ldiskfs" ]; then
1659                                 mopts="loop,$mopts"
1660                         fi
1661                         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt
1662                         $r $LCTL replace_nids $fsname-OST0000 $ostnid
1663                         $r $LCTL replace_nids $fsname-MDT0000 $nid
1664                         $r umount -d $tmp/mnt/mdt
1665                 fi
1666
1667                 mopts=exclude=$fsname-OST0000
1668                 if [ $fstype == "ldiskfs" ]; then
1669                         mopts="loop,$mopts"
1670                 fi
1671         fi
1672
1673         t32_wait_til_devices_gone $node
1674
1675         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
1676                 $r losetup -a
1677                 error_noexit "Mounting the MDT"
1678                 return 1
1679         }
1680         shall_cleanup_mdt=true
1681
1682         if [ "$dne_upgrade" != "no" ]; then
1683                 local fs2mdsdev=$(mdsdevname 1_2)
1684                 local fs2mdsvdev=$(mdsvdevname 1_2)
1685
1686                 echo "mkfs new MDT on ${fs2mdsdev}...."
1687                 if [ $(facet_fstype mds1) == ldiskfs ]; then
1688                         mkfsoptions="--mkfsoptions=\\\"-J size=8\\\""
1689                 fi
1690
1691                 add fs2mds $(mkfs_opts mds2 $fs2mdsdev $fsname) --reformat \
1692                            $mkfsoptions $fs2mdsdev $fs2mdsvdev > /dev/null || {
1693                         error_noexit "Mkfs new MDT failed"
1694                         return 1
1695                 }
1696
1697                 $r $TUNEFS --dryrun $fs2mdsdev || {
1698                         error_noexit "tunefs.lustre before mounting the MDT"
1699                         return 1
1700                 }
1701
1702                 echo "mount new MDT....$fs2mdsdev"
1703                 $r mkdir -p $tmp/mnt/mdt1
1704                 $r $MOUNT_CMD -o $mopts $fs2mdsdev $tmp/mnt/mdt1 || {
1705                         error_noexit "mount mdt1 failed"
1706                         return 1
1707                 }
1708
1709                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
1710                         error_noexit "enable remote dir create failed"
1711
1712                 shall_cleanup_mdt1=true
1713         fi
1714
1715         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1716                 error_noexit "Getting MDT UUID"
1717                 return 1
1718         }
1719         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1720                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1721                 return 1
1722         fi
1723
1724         $r $TUNEFS --dryrun $ost_dev || {
1725                 error_noexit "tunefs.lustre before mounting the OST"
1726                 return 1
1727         }
1728         if [ "$writeconf" ]; then
1729                 mopts=mgsnode=$nid,$writeconf
1730                 if [ $fstype == "ldiskfs" ]; then
1731                         mopts="loop,$mopts"
1732                         $r $TUNEFS --quota $ost_dev || {
1733                                 $r losetup -a
1734                                 error_noexit "Enable ost quota feature"
1735                                 return 1
1736                         }
1737                 fi
1738         else
1739                 mopts=mgsnode=$nid
1740                 if [ $fstype == "ldiskfs" ]; then
1741                         mopts="loop,$mopts"
1742                 fi
1743         fi
1744         $r $MOUNT_CMD -o $mopts $ost_dev $tmp/mnt/ost || {
1745                 error_noexit "Mounting the OST"
1746                 return 1
1747         }
1748         shall_cleanup_ost=true
1749
1750         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1751                 error_noexit "Getting OST UUID"
1752                 return 1
1753         }
1754         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1755                 error_noexit "Unexpected OST UUID: \"$uuid\""
1756                 return 1
1757         fi
1758
1759         $r $LCTL conf_param $fsname-OST0000.osc.max_dirty_mb=15 || {
1760                 error_noexit "Setting \"max_dirty_mb\""
1761                 return 1
1762         }
1763         $r $LCTL conf_param $fsname-OST0000.failover.node=$nid || {
1764                 error_noexit "Setting OST \"failover.node\""
1765                 return 1
1766         }
1767         $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1768                 error_noexit "Setting \"max_rpcs_in_flight\""
1769                 return 1
1770         }
1771         $r $LCTL conf_param $fsname-MDT0000.failover.node=$nid || {
1772                 error_noexit "Setting MDT \"failover.node\""
1773                 return 1
1774         }
1775         $r $LCTL pool_new $fsname.interop || {
1776                 error_noexit "Setting \"interop\""
1777                 return 1
1778         }
1779         $r $LCTL conf_param $fsname-MDT0000.lov.stripesize=4M || {
1780                 error_noexit "Setting \"lov.stripesize\""
1781                 return 1
1782         }
1783
1784         if [ "$ff_convert" != "no" -a $(facet_fstype ost1) == "ldiskfs" ]; then
1785                 $r $LCTL lfsck_start -M $fsname-OST0000 || {
1786                         error_noexit "Start OI scrub on OST0"
1787                         return 1
1788                 }
1789
1790                 # The oi_scrub should be on ost1, but for test_32(),
1791                 # all on the SINGLEMDS.
1792                 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1793                         osd-ldiskfs.$fsname-OST0000.oi_scrub |
1794                         awk '/^status/ { print \\\$2 }'" "completed" 30 || {
1795                         error_noexit "Failed to get the expected 'completed'"
1796                         return 1
1797                 }
1798
1799                 local UPDATED=$($r $LCTL get_param -n \
1800                                 osd-ldiskfs.$fsname-OST0000.oi_scrub |
1801                                 awk '/^updated/ { print $2 }')
1802                 [ $UPDATED -ge 1 ] || {
1803                         error_noexit "Only $UPDATED objects have been converted"
1804                         return 1
1805                 }
1806         fi
1807
1808         if [ "$dne_upgrade" != "no" ]; then
1809                 $r $LCTL conf_param \
1810                                 $fsname-MDT0001.mdc.max_rpcs_in_flight=9 || {
1811                         error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
1812                         return 1
1813                 }
1814                 $r $LCTL conf_param $fsname-MDT0001.failover.node=$nid || {
1815                         error_noexit "Setting MDT1 \"failover.node\""
1816                         return 1
1817                 }
1818                 $r $LCTL conf_param $fsname-MDT0001.lov.stripesize=4M || {
1819                         error_noexit "Setting MDT1 \"lov.stripesize\""
1820                         return 1
1821                 }
1822
1823         fi
1824
1825         if [ "$writeconf" ]; then
1826                 $MOUNT_CMD $nid:/$fsname $tmp/mnt/lustre || {
1827                         error_noexit "Mounting the client"
1828                         return 1
1829                 }
1830                 shall_cleanup_lustre=true
1831                 $LCTL set_param debug="$PTLDEBUG"
1832
1833                 t32_verify_quota $node $fsname $tmp/mnt/lustre || {
1834                         error_noexit "verify quota failed"
1835                         return 1
1836                 }
1837
1838                 if [ "$dne_upgrade" != "no" ]; then
1839                         $LFS mkdir -i 1 $tmp/mnt/lustre/remote_dir || {
1840                                 error_noexit "set remote dir failed"
1841                                 return 1
1842                         }
1843
1844                         pushd $tmp/mnt/lustre
1845                         tar -cf - . --exclude=./remote_dir |
1846                                 tar -xvf - -C remote_dir 1>/dev/null || {
1847                                 error_noexit "cp to remote dir failed"
1848                                 return 1
1849                         }
1850                         popd
1851                 fi
1852
1853                 dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
1854                         error_noexit "dd failed"
1855                         return 1
1856                 }
1857                 rm -rf $tmp/mnt/lustre/tmp_file || {
1858                         error_noexit "rm failed"
1859                         return 1
1860                 }
1861
1862                 if $r test -f $tmp/sha1sums; then
1863                         # LU-2393 - do both sorts on same node to ensure locale
1864                         # is identical
1865                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
1866                         if [ "$dne_upgrade" != "no" ]; then
1867                                 pushd $tmp/mnt/lustre/remote_dir
1868                         else
1869                                 pushd $tmp/mnt/lustre
1870                         fi
1871
1872                         find ! -name .lustre -type f -exec sha1sum {} \; |
1873                                 sort -k 2 >$tmp/sha1sums || {
1874                                 error_noexit "sha1sum"
1875                                 return 1
1876                         }
1877                         popd
1878                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
1879                                 error_noexit "sha1sum verification failed"
1880                                 return 1
1881                         fi
1882                 else
1883                         echo "sha1sum verification skipped"
1884                 fi
1885
1886                 if [ "$dne_upgrade" != "no" ]; then
1887                         rm -rf $tmp/mnt/lustre/remote_dir || {
1888                                 error_noexit "remove remote dir failed"
1889                                 return 1
1890                         }
1891                 fi
1892
1893                 if $r test -f $tmp/list; then
1894                         #
1895                         # There is not a Test Framework API to copy files to or
1896                         # from a remote node.
1897                         #
1898                         # LU-2393 - do both sorts on same node to ensure locale
1899                         # is identical
1900                         $r cat $tmp/list | sort -k 6 >$tmp/list.orig
1901                         pushd $tmp/mnt/lustre
1902                         ls -Rni --time-style=+%s | sort -k 6 >$tmp/list || {
1903                                 error_noexit "ls"
1904                                 return 1
1905                         }
1906                         popd
1907                         #
1908                         # 32-bit and 64-bit clients use different algorithms to
1909                         # convert FIDs into inode numbers.  Hence, remove the inode
1910                         # numbers from the lists, if the original list was created
1911                         # on an architecture with different number of bits per
1912                         # "long".
1913                         #
1914                         if [ $(t32_bits_per_long $(uname -m)) != \
1915                                 $(t32_bits_per_long $img_arch) ]; then
1916                                 echo "Different number of bits per \"long\" from the disk image"
1917                                 for list in list.orig list; do
1918                                         sed -i -e 's/^[0-9]\+[ \t]\+//' $tmp/$list
1919                                 done
1920                         fi
1921                         if ! diff -ub $tmp/list.orig $tmp/list; then
1922                                 error_noexit "list verification failed"
1923                                 return 1
1924                         fi
1925                 else
1926                         echo "list verification skipped"
1927                 fi
1928
1929                 #
1930                 # When adding new data verification tests, please check for
1931                 # the presence of the required reference files first, like
1932                 # the "sha1sums" and "list" tests above, to avoid the need to
1933                 # regenerate every image for each test addition.
1934                 #
1935
1936                 nrpcs_orig=$($LCTL get_param \
1937                                 -n mdc.*MDT0000*.max_rpcs_in_flight) || {
1938                         error_noexit "Getting \"max_rpcs_in_flight\""
1939                         return 1
1940                 }
1941                 nrpcs=$((nrpcs_orig + 5))
1942                 $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=$nrpcs || {
1943                         error_noexit "Changing \"max_rpcs_in_flight\""
1944                         return 1
1945                 }
1946                 wait_update $HOSTNAME "$LCTL get_param \
1947                         -n mdc.*MDT0000*.max_rpcs_in_flight" $nrpcs || {
1948                         error_noexit "Verifying \"max_rpcs_in_flight\""
1949                         return 1
1950                 }
1951
1952                 umount $tmp/mnt/lustre || {
1953                         error_noexit "Unmounting the client"
1954                         return 1
1955                 }
1956                 shall_cleanup_lustre=false
1957         else
1958                 if [ "$dne_upgrade" != "no" ]; then
1959                         $r umount -d $tmp/mnt/mdt1 || {
1960                                 error_noexit "Unmounting the MDT2"
1961                                 return 1
1962                         }
1963                         shall_cleanup_mdt1=false
1964                 fi
1965
1966                 $r umount -d $tmp/mnt/mdt || {
1967                         error_noexit "Unmounting the MDT"
1968                         return 1
1969                 }
1970                 shall_cleanup_mdt=false
1971
1972                 $r umount -d $tmp/mnt/ost || {
1973                         error_noexit "Unmounting the OST"
1974                         return 1
1975                 }
1976                 shall_cleanup_ost=false
1977
1978                 t32_reload_modules $node || {
1979                         error_noexit "Reloading modules"
1980                         return 1
1981                 }
1982
1983                 # mount a second time to make sure we didnt leave upgrade flag on
1984                 $r $TUNEFS --dryrun $mdt_dev || {
1985                         $r losetup -a
1986                         error_noexit "tunefs.lustre before remounting the MDT"
1987                         return 1
1988                 }
1989
1990                 mopts=exclude=$fsname-OST0000
1991                 if [ $fstype == "ldiskfs" ]; then
1992                         mopts="loop,$mopts"
1993                 fi
1994                 $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
1995                         error_noexit "Remounting the MDT"
1996                         return 1
1997                 }
1998                 shall_cleanup_mdt=true
1999         fi
2000 }
2001
2002 test_32a() {
2003         local tarballs
2004         local tarball
2005         local rc=0
2006
2007         t32_check
2008         for tarball in $tarballs; do
2009                 t32_test $tarball || let "rc += $?"
2010         done
2011         return $rc
2012 }
2013 run_test 32a "Upgrade (not live)"
2014
2015 test_32b() {
2016         local tarballs
2017         local tarball
2018         local rc=0
2019
2020         t32_check
2021         for tarball in $tarballs; do
2022                 t32_test $tarball writeconf || let "rc += $?"
2023         done
2024         return $rc
2025 }
2026 run_test 32b "Upgrade with writeconf"
2027
2028 test_32c() {
2029         local tarballs
2030         local tarball
2031         local rc=0
2032
2033         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2034         t32_check
2035         for tarball in $tarballs; do
2036                 dne_upgrade=yes t32_test $tarball writeconf || rc=$?
2037         done
2038         return $rc
2039 }
2040 run_test 32c "dne upgrade test"
2041
2042 test_32d() {
2043         local tarballs
2044         local tarball
2045         local rc=0
2046
2047         t32_check
2048         for tarball in $tarballs; do
2049                 ff_convert=yes t32_test $tarball || rc=$?
2050         done
2051         return $rc
2052 }
2053 run_test 32d "convert ff test"
2054
2055 test_33a() { # bug 12333, was test_33
2056         local FSNAME2=test-123
2057         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2058         local mkfsoptions
2059
2060         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
2061
2062         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
2063                 local dev=${SINGLEMDS}_dev
2064                 local MDSDEV=${!dev}
2065                 is_blkdev $SINGLEMDS $MDSDEV &&
2066                         skip_env "mixed loopback and real device not working" &&
2067                         return
2068         fi
2069
2070         local fs2mdsdev=$(mdsdevname 1_2)
2071         local fs2ostdev=$(ostdevname 1_2)
2072         local fs2mdsvdev=$(mdsvdevname 1_2)
2073         local fs2ostvdev=$(ostvdevname 1_2)
2074
2075         if [ $(facet_fstype mds1) == ldiskfs ]; then
2076                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
2077         fi
2078
2079         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2080                 --reformat $mkfsoptions $fs2mdsdev $fs2mdsvdev || exit 10
2081         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2082                 --fsname=${FSNAME2} --index=8191 --reformat $fs2ostdev \
2083                 $fs2ostvdev || exit 10
2084
2085         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
2086         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2087         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" ||
2088                 error "$LCTL conf_param $FSNAME2.sys.timeout=200 failed"
2089         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
2090         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
2091         echo "ok."
2092
2093         cp /etc/hosts $MOUNT2/ || error "copy /etc/hosts $MOUNT2/ failed"
2094         $GETSTRIPE $MOUNT2/hosts || error "$GETSTRIPE $MOUNT2/hosts failed"
2095
2096         umount -d $MOUNT2
2097         stop fs2ost -f
2098         stop fs2mds -f
2099         cleanup_nocli || error "cleanup_nocli failed with $?"
2100 }
2101 run_test 33a "Mount ost with a large index number"
2102
2103 test_33b() {    # was test_34
2104         setup
2105
2106         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
2107         # Drop lock cancelation reply during umount
2108         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
2109         do_facet client $LCTL set_param fail_loc=0x80000304
2110         #lctl set_param debug=-1
2111         umount_client $MOUNT
2112         cleanup || error "cleanup failed with $?"
2113 }
2114 run_test 33b "Drop cancel during umount"
2115
2116 test_34a() {
2117         setup
2118         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
2119         manual_umount_client
2120         rc=$?
2121         do_facet client killall -USR1 multiop
2122         if [ $rc -eq 0 ]; then
2123                 error "umount not fail!"
2124         fi
2125         sleep 1
2126         cleanup || error "cleanup failed with rc $?"
2127 }
2128 run_test 34a "umount with opened file should be fail"
2129
2130 test_34b() {
2131         setup
2132         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2133         stop_mds || error "Unable to stop MDS"
2134
2135         manual_umount_client --force || error "mtab after failed umount with $?"
2136
2137         cleanup || error "cleanup failed with $?"
2138 }
2139 run_test 34b "force umount with failed mds should be normal"
2140
2141 test_34c() {
2142         setup
2143         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2144         stop_ost || error "Unable to stop OST1"
2145
2146         manual_umount_client --force || error "mtab after failed umount with $?"
2147
2148         cleanup || error "cleanup failed with $?"
2149 }
2150 run_test 34c "force umount with failed ost should be normal"
2151
2152 test_35a() { # bug 12459
2153         setup
2154
2155         DBG_SAVE="`$LCTL get_param -n debug`"
2156         $LCTL set_param debug="ha"
2157
2158         log "Set up a fake failnode for the MDS"
2159         FAKENID="127.0.0.2"
2160         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2161                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2162         do_facet mgs "$LCTL conf_param \
2163                       ${device}.failover.node=$(h2$NETTYPE $FAKENID)" ||
2164                 error "Setting ${device}.failover.node=\
2165                        $(h2$NETTYPE $FAKENID) failed."
2166
2167         log "Wait for RECONNECT_INTERVAL seconds (10s)"
2168         sleep 10
2169
2170         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
2171         $LCTL clear
2172         log "$MSG"
2173         log "Stopping the MDT: $device"
2174         stop_mdt 1 || error "MDT0 stop fail"
2175
2176         df $MOUNT > /dev/null 2>&1 &
2177         DFPID=$!
2178         log "Restarting the MDT: $device"
2179         start_mdt 1 || error "MDT0 start fail"
2180         log "Wait for df ($DFPID) ... "
2181         wait $DFPID
2182         log "done"
2183         $LCTL set_param debug="$DBG_SAVE"
2184
2185         # retrieve from the log the first server that the client tried to
2186         # contact after the connection loss
2187         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2188         NEXTCONN=`awk "/${MSG}/ {start = 1;}
2189                        /import_select_connection.*$device-mdc.* using connection/ {
2190                                 if (start) {
2191                                         if (\\\$NF ~ /$FAKENID/)
2192                                                 print \\\$NF;
2193                                         else
2194                                                 print 0;
2195                                         exit;
2196                                 }
2197                        }" $TMP/lustre-log-$TESTNAME.log`
2198         [ "$NEXTCONN" != "0" ] &&
2199                 error "Tried to connect to ${NEXTCONN} not last active server"
2200         cleanup || error "cleanup failed with $?"
2201         # remove nid settings
2202         writeconf_or_reformat
2203 }
2204 run_test 35a "Reconnect to the last active server first"
2205
2206 test_35b() { # bug 18674
2207         remote_mds || { skip "local MDS" && return 0; }
2208         setup
2209
2210         debugsave
2211         $LCTL set_param debug="ha"
2212         $LCTL clear
2213         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
2214         log "$MSG"
2215
2216         log "Set up a fake failnode for the MDS"
2217         FAKENID="127.0.0.2"
2218         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2219                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2220         do_facet mgs "$LCTL conf_param \
2221                       ${device}.failover.node=$(h2$NETTYPE $FAKENID)" ||
2222                 error "Set ${device}.failover.node=\
2223                        $(h2$NETTYPE $FAKENID) failed"
2224
2225         local at_max_saved=0
2226         # adaptive timeouts may prevent seeing the issue
2227         if at_is_enabled; then
2228                 at_max_saved=$(at_max_get mds)
2229                 at_max_set 0 mds client
2230         fi
2231
2232         mkdir $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
2233
2234         log "Injecting EBUSY on MDS"
2235         # Setting OBD_FAIL_MDS_RESEND=0x136
2236         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" ||
2237                 error "unable to set param fail_loc=0x80000136"
2238
2239         $LCTL set_param mdc.${FSNAME}*.stats=clear
2240
2241         log "Creating a test file and stat it"
2242         touch $MOUNT/$tdir/$tfile || error "touch $MOUNT/$tdir/$tfile failed"
2243         stat $MOUNT/$tdir/$tfile
2244
2245         log "Stop injecting EBUSY on MDS"
2246         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" ||
2247                 error "unable to set param fail_loc=0"
2248         rm -f $MOUNT/$tdir/$tfile || error "remove $MOUNT/$tdir/$tfile failed"
2249
2250         log "done"
2251         # restore adaptive timeout
2252         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
2253
2254         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2255
2256         CONNCNT=$($LCTL get_param mdc.${FSNAME}*.stats |
2257                   awk '/mds_connect/{print $2}')
2258
2259         # retrieve from the log if the client has ever tried to
2260         # contact the fake server after the loss of connection
2261         FAILCONN=`awk "BEGIN {ret = 0;}
2262                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
2263                                 ret = 1;
2264                                 if (\\\$NF ~ /$FAKENID/) {
2265                                         ret = 2;
2266                                         exit;
2267                                 }
2268                        }
2269                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
2270
2271         [ "$FAILCONN" == "0" ] &&
2272                 error "The client reconnection has not been triggered"
2273         [ "$FAILCONN" == "2" ] &&
2274                 error "Primary server busy, client reconnect to failover failed"
2275
2276         # LU-290
2277         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
2278         # Reconnects are supposed to be rate limited to one every 5s
2279         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] &&
2280                 error "Too many reconnects $CONNCNT"
2281
2282         cleanup || error "cleanup failed with $?"
2283         # remove nid settings
2284         writeconf_or_reformat
2285 }
2286 run_test 35b "Continue reconnection retries, if the active server is busy"
2287
2288 test_36() { # 12743
2289         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
2290
2291         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] ||
2292                 { skip "remote OST" && return 0; }
2293
2294         local rc=0
2295         local FSNAME2=test1234
2296         local fs3ost_HOST=$ost_HOST
2297         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2298
2299         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
2300
2301         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
2302                 is_blkdev $SINGLEMDS $MDSDEV &&
2303                 skip_env "mixed loopback and real device not working" && return
2304         fi
2305
2306         local fs2mdsdev=$(mdsdevname 1_2)
2307         local fs2ostdev=$(ostdevname 1_2)
2308         local fs3ostdev=$(ostdevname 2_2)
2309         local fs2mdsvdev=$(mdsvdevname 1_2)
2310         local fs2ostvdev=$(ostvdevname 1_2)
2311         local fs3ostvdev=$(ostvdevname 2_2)
2312
2313         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2314                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
2315         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
2316         #     different one than the default value here.
2317         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2318                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
2319         add fs3ost $(mkfs_opts ost2 ${fs3ostdev}) --mgsnode=$MGSNID \
2320                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
2321
2322         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
2323         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2324         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
2325         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
2326         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
2327
2328         sleep 5 # until 11778 fixed
2329
2330         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || error "dd failed"
2331
2332         BKTOTAL=$($LCTL get_param -n obdfilter.*.kbytestotal |
2333                   awk 'BEGIN{total=0}; {total+=$1}; END{print total}')
2334         BKFREE=$($LCTL get_param -n obdfilter.*.kbytesfree |
2335                  awk 'BEGIN{free=0}; {free+=$1}; END{print free}')
2336         BKAVAIL=$($LCTL get_param -n obdfilter.*.kbytesavail |
2337                   awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
2338         STRING=$(df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}')
2339         DFTOTAL=$(echo $STRING | cut -d, -f1)
2340         DFUSED=$(echo $STRING  | cut -d, -f2)
2341         DFAVAIL=$(echo $STRING | cut -d, -f3)
2342         DFFREE=$(($DFTOTAL - $DFUSED))
2343
2344         ALLOWANCE=$((64 * $OSTCOUNT))
2345
2346         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
2347            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
2348                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
2349                 rc=1
2350         fi
2351         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
2352            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
2353                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
2354                 rc=2
2355         fi
2356         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
2357            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
2358                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
2359                 rc=3
2360        fi
2361
2362         umount -d $MOUNT2
2363         stop fs3ost -f || error "unable to stop OST3"
2364         stop fs2ost -f || error "unable to stop OST2"
2365         stop fs2mds -f || error "unable to stop second MDS"
2366         unload_modules_conf || error "unable unload modules"
2367         return $rc
2368 }
2369 run_test 36 "df report consistency on OSTs with different block size"
2370
2371 test_37() {
2372         local mntpt=$(facet_mntpt $SINGLEMDS)
2373         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
2374         local mdsdev_sym="$TMP/sym_mdt.img"
2375         local opts=$MDS_MOUNT_OPTS
2376         local rc=0
2377
2378         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2379                 skip "Currently only applicable to ldiskfs-based MDTs"
2380                 return
2381         fi
2382
2383         echo "MDS :     $mdsdev"
2384         echo "SYMLINK : $mdsdev_sym"
2385         do_facet $SINGLEMDS rm -f $mdsdev_sym
2386
2387         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
2388
2389         echo "mount symlink device - $mdsdev_sym"
2390
2391         if ! do_facet $SINGLEMDS test -b $mdsdev; then
2392                 opts=$(csa_add "$opts" -o loop)
2393         fi
2394         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
2395                 $mdsdev_sym $mntpt 2>&1)
2396         rc=${PIPESTATUS[0]}
2397
2398         echo mount_op=$mount_op
2399
2400         do_facet $SINGLEMDS "umount -d $mntpt && rm -f $mdsdev_sym"
2401
2402         if $(echo $mount_op | grep -q "unable to set tunable"); then
2403                 error "set tunables failed for symlink device"
2404         fi
2405
2406         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
2407 }
2408 run_test 37 "verify set tunables works for symlink device"
2409
2410 test_38() { # bug 14222
2411         local fstype=$(facet_fstype $SINGLEMDS)
2412         local mntpt=$(facet_mntpt $SINGLEMDS)
2413
2414         setup
2415         # like runtests
2416         local COUNT=10
2417         local SRC="/etc /bin"
2418         local FILES=$(find $SRC -type f -mtime +1 | head -n $COUNT)
2419         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
2420         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2421         tar cf - $FILES | tar xf - -C $DIR/$tdir ||
2422                 error "copying $SRC to $DIR/$tdir"
2423         sync
2424         umount_client $MOUNT || error "umount_client $MOUNT failed"
2425         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2426         stop_mds || error "Unable to stop MDS"
2427         log "delete lov_objid file on MDS"
2428
2429         mount_fstype $SINGLEMDS || error "mount MDS failed (1)"
2430
2431         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid; rm $mntpt/lov_objid"
2432
2433         unmount_fstype $SINGLEMDS || error "umount failed (1)"
2434
2435         # check create in mds_lov_connect
2436         start_mds || error "unable to start MDS"
2437         mount_client $MOUNT || error "mount_client $MOUNT failed"
2438         for f in $FILES; do
2439                 [ $V ] && log "verifying $DIR/$tdir/$f"
2440                 diff -q $f $DIR/$tdir/$f || ERROR=y
2441         done
2442         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2443         if [ "$ERROR" = "y" ]; then
2444                 # check it's updates in sync
2445                 umount_client $MOUNT
2446                 stop_mds
2447                 mount_fstype $SIGNLEMDS
2448                 do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2449                 unmount_fstype $SINGLEMDS
2450                 error "old and new files are different after connect" || true
2451         fi
2452         touch $DIR/$tdir/f2 || error "f2 file create failed"
2453
2454         # check it's updates in sync
2455         umount_client $MOUNT || error "second umount_client $MOUNT failed"
2456         stop_mds
2457
2458         mount_fstype $SINGLEMDS || error "mount MDS failed (3)"
2459
2460         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2461         do_facet $SINGLEMDS dd if=/dev/zero of=$mntpt/lov_objid.clear count=8
2462
2463         unmount_fstype $SINGLEMDS || error "umount failed (3)"
2464
2465         start_mds || error "unable to start MDS"
2466         mount_client $MOUNT || error "mount_client $MOUNT failed"
2467         for f in $FILES; do
2468                 [ $V ] && log "verifying $DIR/$tdir/$f"
2469                 diff -q $f $DIR/$tdir/$f || ERROR=y
2470         done
2471         touch $DIR/$tdir/f3 || error "f3 file create failed"
2472         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2473         umount_client $MOUNT || error "third umount_client $MOUNT failed"
2474         stop_mds
2475         mount_fstype $SINGLEMDS || error "mount MDS failed (4)"
2476         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2477         unmount_fstype $SINGLEMDS || error "umount failed (4)"
2478
2479         [ "$ERROR" = "y" ] &&
2480                 error "old and new files are different after sync" || true
2481
2482         log "files compared the same"
2483         cleanup || error "cleanup failed with $?"
2484 }
2485 run_test 38 "MDS recreates missing lov_objid file from OST data"
2486
2487 test_39() {
2488         PTLDEBUG=+malloc
2489         setup
2490         cleanup || error "cleanup failed with $?"
2491         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2492                 error "memory leak detected" || true
2493 }
2494 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2495
2496 test_40() { # bug 15759
2497         start_ost || error "Unable to start OST1"
2498         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2499         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2500         start_mds
2501         cleanup || error "cleanup failed with rc $?"
2502 }
2503 run_test 40 "race during service thread startup"
2504
2505 test_41a() { #bug 14134
2506         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2507            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2508                 skip "Loop devices does not work with nosvc option"
2509                 return
2510         fi
2511
2512         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2513
2514         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2515         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
2516         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2517         mount_client $MOUNT || error "mount_client $MOUNT failed"
2518         sleep 5
2519
2520         echo "blah blah" > $MOUNT/$tfile
2521         cat $MOUNT/$tfile
2522
2523         umount_client $MOUNT || error "umount_client $MOUNT failed"
2524         stop ost1 -f || error "unable to stop OST1"
2525         stop_mds || error "Unable to stop MDS"
2526         stop_mds || error "Unable to stop MDS on second try"
2527         unload_modules_conf || error "unload_modules_conf failed"
2528 }
2529 run_test 41a "mount mds with --nosvc and --nomgs"
2530
2531 test_41b() {
2532         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2533            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2534                 skip "Loop devices does not work with nosvc option"
2535                 return
2536         fi
2537
2538         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2539
2540         stopall
2541         reformat
2542         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2543
2544         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2545         start_ost || error "Unable to start OST1"
2546         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2547         mount_client $MOUNT || error "mount_client $MOUNT failed"
2548         sleep 5
2549
2550         echo "blah blah" > $MOUNT/$tfile
2551         cat $MOUNT/$tfile || error "cat $MOUNT/$tfile failed"
2552
2553         umount_client $MOUNT || error "umount_client $MOUNT failed"
2554         stop_ost || error "Unable to stop OST1"
2555         stop_mds || error "Unable to stop MDS"
2556         stop_mds || error "Unable to stop MDS on second try"
2557 }
2558 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2559
2560 test_41c() {
2561         local server_version=$(lustre_version_code $SINGLEMDS)
2562
2563         [[ $server_version -ge $(version_code 2.6.52) ]] ||
2564         [[ $server_version -ge $(version_code 2.5.26) &&
2565            $server_version -lt $(version_code 2.5.50) ]] ||
2566         [[ $server_version -ge $(version_code 2.5.4) &&
2567            $server_version -lt $(version_code 2.5.11) ]] ||
2568                 { skip "Need MDS version 2.5.4+ or 2.5.26+ or 2.6.52+"; return; }
2569
2570         cleanup
2571         # MDT concurent start
2572         #define OBD_FAIL_TGT_DELAY_CONNECT 0x703
2573         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x703"
2574         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS &
2575         local pid=$!
2576         sleep 2
2577         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x0"
2578         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS &
2579         local pid2=$!
2580         wait $pid2
2581         local rc2=$?
2582         wait $pid
2583         local rc=$?
2584         if [ $rc == 0 ] && [ $rc2 == 114 ]; then
2585                 echo "1st MDT start succeed"
2586                 echo "2nd MDT start failed with EALREADY"
2587         elif [ $rc2 == 0 ] && [ $rc == 114 ]; then
2588                 echo "1st MDT start failed with EALREADY"
2589                 echo "2nd MDT start succeed"
2590         else
2591                 stop mds1 -f
2592                 error "unexpected concurent MDT mounts result, rc=$rc rc2=$rc2"
2593         fi
2594
2595         # OST concurent start
2596         #define OBD_FAIL_TGT_DELAY_CONNECT 0x703
2597         do_facet ost1 "$LCTL set_param fail_loc=0x703"
2598         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS &
2599         pid=$!
2600         sleep 2
2601         do_facet ost1 "$LCTL set_param fail_loc=0x0"
2602         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS &
2603         pid2=$!
2604         wait $pid2
2605         rc2=$?
2606         wait $pid
2607         rc=$?
2608         if [ $rc == 0 ] && [ $rc2 == 114 ]; then
2609                 echo "1st OST start succeed"
2610                 echo "2nd OST start failed with EALREADY"
2611         elif [ $rc2 == 0 ] && [ $rc == 114 ]; then
2612                 echo "1st OST start failed with EALREADY"
2613                 echo "2nd OST start succeed"
2614         else
2615                 stop mds1 -f
2616                 stop ost1 -f
2617                 error "unexpected concurent OST mounts result, rc=$rc rc2=$rc2"
2618         fi
2619         # cleanup
2620         stop mds1 -f
2621         stop ost1 -f
2622
2623         # verify everything ok
2624         start_mds
2625         if [ $? != 0 ]
2626         then
2627                 stop mds1 -f
2628                 error "MDT(s) start failed"
2629         fi
2630
2631         start_ost
2632         if [ $? != 0 ]
2633         then
2634                 stop mds1 -f
2635                 stop ost1 -f
2636                 error "OST(s) start failed"
2637         fi
2638
2639         mount_client $MOUNT
2640         if [ $? != 0 ]
2641         then
2642                 stop mds1 -f
2643                 stop ost1 -f
2644                 error "client start failed"
2645         fi
2646         check_mount
2647         if [ $? != 0 ]
2648         then
2649                 stop mds1 -f
2650                 stop ost1 -f
2651                 error "client mount failed"
2652         fi
2653         cleanup
2654 }
2655 run_test 41c "concurent mounts of MDT/OST should all fail but one"
2656
2657 test_42() { #bug 14693
2658         setup
2659         check_mount || error "client was not mounted"
2660
2661         do_facet mgs $LCTL conf_param $FSNAME.llite.some_wrong_param=10
2662         umount_client $MOUNT ||
2663                 error "unmounting client failed with invalid llite param"
2664         mount_client $MOUNT ||
2665                 error "mounting client failed with invalid llite param"
2666
2667         do_facet mgs $LCTL conf_param $FSNAME.sys.some_wrong_param=20
2668         cleanup || error "stopping $FSNAME failed with invalid sys param"
2669         load_modules
2670         setup
2671         check_mount || error "client was not mounted with invalid sys param"
2672         cleanup || error "stopping $FSNAME failed with invalid sys param"
2673 }
2674 run_test 42 "allow client/server mount/unmount with invalid config param"
2675
2676 test_43() {
2677         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.58) ]] ||
2678                 { skip "Need MDS version at least 2.5.58" && return 0; }
2679         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
2680
2681         ID1=${ID1:-501}
2682         USER1=$(cat /etc/passwd | grep :$ID1:$ID1: | cut -d: -f1)
2683         [ -z "$USER1" ] && skip_env "missing user with uid=$ID1 gid=$ID1" &&
2684                 return
2685
2686         setup
2687         chmod ugo+x $DIR || error "chmod 0 failed"
2688         set_conf_param_and_check mds                                    \
2689                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.root_squash"    \
2690                 "$FSNAME.mdt.root_squash"                               \
2691                 "0:0"
2692         wait_update $HOSTNAME                                           \
2693                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
2694                 "0:0" ||
2695                 error "check llite root_squash failed!"
2696         set_conf_param_and_check mds                                    \
2697                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"  \
2698                 "$FSNAME.mdt.nosquash_nids"                             \
2699                 "NONE"
2700         wait_update $HOSTNAME                                           \
2701                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
2702                 "NONE" ||
2703                 error "check llite nosquash_nids failed!"
2704
2705     #
2706     # create set of test files
2707     #
2708     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
2709     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
2710     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
2711
2712     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
2713     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
2714
2715         mkdir $DIR/$tdir-rootdir || error "mkdir failed"
2716         chmod go-rwx $DIR/$tdir-rootdir || error "chmod 3 failed"
2717         touch $DIR/$tdir-rootdir/tfile-1 || error "touch failed"
2718
2719         echo "777" > $DIR/$tfile-user1file || error "write 7 failed"
2720         chmod go-rw $DIR/$tfile-user1file || error "chmod 7 failed"
2721         chown $ID1.$ID1 $DIR/$tfile-user1file || error "chown failed"
2722
2723         #
2724         # check root_squash:
2725         #   set root squash UID:GID to RUNAS_ID
2726         #   root should be able to access only files owned by RUNAS_ID
2727         #
2728         set_conf_param_and_check mds                                    \
2729                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.root_squash"    \
2730                 "$FSNAME.mdt.root_squash"                               \
2731                 "$RUNAS_ID:$RUNAS_ID"
2732         wait_update $HOSTNAME                                           \
2733                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
2734                 "$RUNAS_ID:$RUNAS_ID" ||
2735                 error "check llite root_squash failed!"
2736
2737         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
2738         dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
2739                 error "$ST: root read permission is denied"
2740         echo "$ST: root read permission is granted - ok"
2741
2742         echo "444" |
2743         dd conv=notrunc of=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
2744                 error "$ST: root write permission is denied"
2745         echo "$ST: root write permission is granted - ok"
2746
2747         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2748         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
2749                 error "$ST: root read permission is granted"
2750         echo "$ST: root read permission is denied - ok"
2751
2752         echo "555" |
2753         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
2754                 error "$ST: root write permission is granted"
2755         echo "$ST: root write permission is denied - ok"
2756
2757         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2758                 rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null &&
2759                         error "$ST: root unlink permission is granted"
2760         echo "$ST: root unlink permission is denied - ok"
2761
2762         touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null &&
2763                 error "$ST: root create permission is granted"
2764         echo "$ST: root create permission is denied - ok"
2765
2766         # LU-1778
2767         # check root_squash is enforced independently
2768         # of client cache content
2769         #
2770         # access file by USER1, keep access open
2771         # root should be denied access to user file
2772
2773         runas -u $ID1 tail -f $DIR/$tfile-user1file 1>/dev/null 2>&1 &
2774         pid=$!
2775         sleep 1
2776
2777         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-user1file)
2778         dd if=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
2779             { kill $pid; error "$ST: root read permission is granted"; }
2780         echo "$ST: root read permission is denied - ok"
2781
2782         echo "777" |
2783         dd conv=notrunc of=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
2784             { kill $pid; error "$ST: root write permission is granted"; }
2785         echo "$ST: root write permission is denied - ok"
2786
2787         kill $pid
2788         wait $pid
2789
2790         #
2791         # check nosquash_nids:
2792         #   put client's NID into nosquash_nids list,
2793         #   root should be able to access root file after that
2794         #
2795         local NIDLIST=$($LCTL list_nids all | tr '\n' ' ')
2796         NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
2797         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
2798         set_conf_param_and_check mds                                    \
2799                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"  \
2800                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
2801                 "$NIDLIST"
2802         wait_update $HOSTNAME                                           \
2803                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
2804                 "$NIDLIST" ||
2805                 error "check llite nosquash_nids failed!"
2806
2807         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2808         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
2809                 error "$ST: root read permission is denied"
2810         echo "$ST: root read permission is granted - ok"
2811
2812         echo "666" |
2813         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
2814                 error "$ST: root write permission is denied"
2815         echo "$ST: root write permission is granted - ok"
2816
2817         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2818         rm $DIR/$tdir-rootdir/tfile-1 ||
2819                 error "$ST: root unlink permission is denied"
2820         echo "$ST: root unlink permission is granted - ok"
2821         touch $DIR/$tdir-rootdir/tfile-2 ||
2822                 error "$ST: root create permission is denied"
2823         echo "$ST: root create permission is granted - ok"
2824 }
2825 run_test 43 "check root_squash and nosquash_nids"
2826
2827 umount_client $MOUNT
2828 cleanup_nocli
2829
2830 test_44() { # 16317
2831         setup
2832         check_mount || error "check_mount"
2833         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
2834         STATS_FOUND=no
2835         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
2836         for VAL in $UUIDS; do
2837                 NID=$(echo $VAL | cut -d= -f1)
2838                 CLUUID=$(echo $VAL | cut -d= -f2)
2839                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
2840         done
2841         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
2842         cleanup || error "cleanup failed with $?"
2843 }
2844 run_test 44 "mounted client proc entry exists"
2845
2846 test_45() { #17310
2847         setup
2848         check_mount || error "check_mount"
2849         stop_mds || error "Unable to stop MDS"
2850         df -h $MOUNT &
2851         log "sleep 60 sec"
2852         sleep 60
2853         #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
2854         do_facet client "$LCTL set_param fail_loc=0x50f"
2855         log "sleep 10 sec"
2856         sleep 10
2857         manual_umount_client --force || error "manual_umount_client failed"
2858         do_facet client "$LCTL set_param fail_loc=0x0"
2859         start_mds || error "unable to start MDS"
2860         mount_client $MOUNT || error "mount_client $MOUNT failed"
2861         cleanup || error "cleanup failed with $?"
2862 }
2863 run_test 45 "long unlink handling in ptlrpcd"
2864
2865 cleanup_46a() {
2866         trap 0
2867         local rc=0
2868         local count=$1
2869
2870         umount_client $MOUNT2 || rc=$?
2871         umount_client $MOUNT || rc=$?
2872         while [ $count -gt 0 ]; do
2873                 stop ost${count} -f || rc=$?
2874                 let count=count-1
2875         done
2876         stop_mds || rc=$?
2877         cleanup_nocli || rc=$?
2878         #writeconf to remove all ost2 traces for subsequent tests
2879         writeconf_or_reformat
2880         return $rc
2881 }
2882
2883 test_46a() {
2884         echo "Testing with $OSTCOUNT OSTs"
2885         reformat_and_config
2886         start_mds || error "unable to start MDS"
2887         #first client should see only one ost
2888         start_ost || error "Unable to start OST1"
2889         wait_osc_import_state mds ost FULL
2890         #start_client
2891         mount_client $MOUNT || error "mount_client $MOUNT failed"
2892         trap "cleanup_46a $OSTCOUNT" EXIT ERR
2893
2894         local i
2895         for (( i=2; i<=$OSTCOUNT; i++ )); do
2896                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
2897                         error "start_ost$i $(ostdevname $i) failed"
2898         done
2899
2900         # wait until osts in sync
2901         for (( i=2; i<=$OSTCOUNT; i++ )); do
2902             wait_osc_import_state mds ost$i FULL
2903             wait_osc_import_state client ost$i FULL
2904         done
2905
2906         #second client see all ost's
2907
2908         mount_client $MOUNT2 || error "mount_client failed"
2909         $SETSTRIPE -c -1 $MOUNT2 || error "$SETSTRIPE -c -1 $MOUNT2 failed"
2910         $GETSTRIPE $MOUNT2 || error "$GETSTRIPE $MOUNT2 failed"
2911
2912         echo "ok" > $MOUNT2/widestripe
2913         $GETSTRIPE $MOUNT2/widestripe ||
2914                 error "$GETSTRIPE $MOUNT2/widestripe failed"
2915         # fill acl buffer for avoid expand lsm to them
2916         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd |
2917                 while read acl; do
2918             setfacl -m $acl $MOUNT2/widestripe
2919         done
2920
2921         # will be deadlock
2922         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
2923
2924         cleanup_46a $OSTCOUNT || error "cleanup_46a failed"
2925 }
2926 run_test 46a "handle ost additional - wide striped file"
2927
2928 test_47() { #17674
2929         reformat
2930         setup_noconfig
2931         check_mount || error "check_mount failed"
2932         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
2933
2934         local lru_size=[]
2935         local count=0
2936         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2937             if echo $ns | grep "MDT[[:digit:]]*"; then
2938                 continue
2939             fi
2940             lrs=$(echo $ns | sed 's/.*lru_size=//')
2941             lru_size[count]=$lrs
2942             let count=count+1
2943         done
2944
2945         facet_failover ost1
2946         facet_failover $SINGLEMDS
2947         client_up || error "client_up failed"
2948
2949         count=0
2950         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2951             if echo $ns | grep "MDT[[:digit:]]*"; then
2952                 continue
2953             fi
2954             lrs=$(echo $ns | sed 's/.*lru_size=//')
2955             if ! test "$lrs" -eq "${lru_size[count]}"; then
2956                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
2957                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
2958             fi
2959             let count=count+1
2960         done
2961
2962         cleanup || error "cleanup failed with $?"
2963 }
2964 run_test 47 "server restart does not make client loss lru_resize settings"
2965
2966 cleanup_48() {
2967         trap 0
2968
2969         # reformat after this test is needed - if test will failed
2970         # we will have unkillable file at FS
2971         reformat_and_config
2972 }
2973
2974 test_48() { # bug 17636
2975         reformat
2976         setup_noconfig
2977         check_mount || error "check_mount failed"
2978
2979         $SETSTRIPE -c -1 $MOUNT || error "$SETSTRIPE -c -1 $MOUNT failed"
2980         $GETSTRIPE $MOUNT || error "$GETSTRIPE $MOUNT failed"
2981
2982         echo "ok" > $MOUNT/widestripe
2983         $GETSTRIPE $MOUNT/widestripe ||
2984                 error "$GETSTRIPE $MOUNT/widestripe failed"
2985
2986         trap cleanup_48 EXIT ERR
2987
2988         # fill acl buffer for avoid expand lsm to them
2989         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
2990             setfacl -m $acl $MOUNT/widestripe
2991         done
2992
2993         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
2994
2995         cleanup_48
2996 }
2997 run_test 48 "too many acls on file"
2998
2999 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
3000 test_49a() { # bug 17710
3001         local timeout_orig=$TIMEOUT
3002         local ldlm_timeout_orig=$LDLM_TIMEOUT
3003         local LOCAL_TIMEOUT=20
3004
3005         LDLM_TIMEOUT=$LOCAL_TIMEOUT
3006         TIMEOUT=$LOCAL_TIMEOUT
3007
3008         reformat
3009         setup_noconfig
3010         check_mount || error "client mount failed"
3011
3012         echo "check ldlm_timout..."
3013         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
3014         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
3015         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
3016
3017         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
3018                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3019         fi
3020
3021         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
3022                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT / 3))"
3023         fi
3024
3025         umount_client $MOUNT || error "umount_client $MOUNT failed"
3026         stop_ost || error "problem stopping OSS"
3027         stop_mds || error "problem stopping MDS"
3028
3029         LDLM_TIMEOUT=$ldlm_timeout_orig
3030         TIMEOUT=$timeout_orig
3031 }
3032 run_test 49a "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
3033
3034 test_49b() { # bug 17710
3035         local timeout_orig=$TIMEOUT
3036         local ldlm_timeout_orig=$LDLM_TIMEOUT
3037         local LOCAL_TIMEOUT=20
3038
3039         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
3040         TIMEOUT=$LOCAL_TIMEOUT
3041
3042         reformat
3043         setup_noconfig
3044         check_mount || error "client mount failed"
3045
3046         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
3047         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
3048         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
3049
3050         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
3051                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3052         fi
3053
3054         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
3055                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT - 1))"
3056         fi
3057
3058         cleanup || error "cleanup failed"
3059
3060         LDLM_TIMEOUT=$ldlm_timeout_orig
3061         TIMEOUT=$timeout_orig
3062 }
3063 run_test 49b "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
3064
3065 lazystatfs() {
3066         # Test both statfs and lfs df and fail if either one fails
3067         multiop_bg_pause $1 f_
3068         RC1=$?
3069         PID=$!
3070         killall -USR1 multiop
3071         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
3072         wait $PID || { RC1=$?; log "multiop return error "; }
3073
3074         $LFS df &
3075         PID=$!
3076         sleep 5
3077         kill -s 0 $PID
3078         RC2=$?
3079         if [ $RC2 -eq 0 ]; then
3080             kill -s 9 $PID
3081             log "lazystatfs df failed"
3082         fi
3083
3084         RC=0
3085         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
3086         return $RC
3087 }
3088
3089 test_50a() {
3090         setup
3091         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3092         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3093
3094         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
3095
3096         cleanup || error "cleanup failed with rc $?"
3097 }
3098 run_test 50a "lazystatfs all servers available"
3099
3100 test_50b() {
3101         setup
3102         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3103         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3104
3105         # Wait for client to detect down OST
3106         stop_ost || error "Unable to stop OST1"
3107         wait_osc_import_state mds ost DISCONN
3108
3109         lazystatfs $MOUNT || error "lazystatfs should not return EIO"
3110
3111         umount_client $MOUNT || error "Unable to unmount client"
3112         stop_mds || error "Unable to stop MDS"
3113 }
3114 run_test 50b "lazystatfs all servers down"
3115
3116 test_50c() {
3117         start_mds || error "Unable to start MDS"
3118         start_ost || error "Unable to start OST1"
3119         start_ost2 || error "Unable to start OST2"
3120         mount_client $MOUNT || error "Unable to mount client"
3121         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3122         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3123
3124         # Wait for client to detect down OST
3125         stop_ost || error "Unable to stop OST1"
3126         wait_osc_import_state mds ost DISCONN
3127         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3128
3129         umount_client $MOUNT || error "Unable to unmount client"
3130         stop_ost2 || error "Unable to stop OST2"
3131         stop_mds || error "Unable to stop MDS"
3132         #writeconf to remove all ost2 traces for subsequent tests
3133         writeconf_or_reformat
3134 }
3135 run_test 50c "lazystatfs one server down"
3136
3137 test_50d() {
3138         start_mds || error "Unable to start MDS"
3139         start_ost || error "Unable to start OST1"
3140         start_ost2 || error "Unable to start OST2"
3141         mount_client $MOUNT || error "Unable to mount client"
3142         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3143         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3144
3145         # Issue the statfs during the window where the client still
3146         # belives the OST to be available but it is in fact down.
3147         # No failure just a statfs which hangs for a timeout interval.
3148         stop_ost || error "Unable to stop OST1"
3149         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3150
3151         umount_client $MOUNT || error "Unable to unmount client"
3152         stop_ost2 || error "Unable to stop OST2"
3153         stop_mds || error "Unable to stop MDS"
3154         #writeconf to remove all ost2 traces for subsequent tests
3155         writeconf_or_reformat
3156 }
3157 run_test 50d "lazystatfs client/server conn race"
3158
3159 test_50e() {
3160         local RC1
3161         local pid
3162
3163         reformat_and_config
3164         start_mds || error "Unable to start MDS"
3165         #first client should see only one ost
3166         start_ost || error "Unable to start OST1"
3167         wait_osc_import_state mds ost FULL
3168
3169         # Wait for client to detect down OST
3170         stop_ost || error "Unable to stop OST1"
3171         wait_osc_import_state mds ost DISCONN
3172
3173         mount_client $MOUNT || error "Unable to mount client"
3174         $LCTL set_param llite.$FSNAME-*.lazystatfs=0
3175
3176         multiop_bg_pause $MOUNT _f
3177         RC1=$?
3178         pid=$!
3179
3180         if [ $RC1 -ne 0 ]; then
3181                 log "multiop failed $RC1"
3182         else
3183             kill -USR1 $pid
3184             sleep $(( $TIMEOUT+1 ))
3185             kill -0 $pid
3186             [ $? -ne 0 ] && error "process isn't sleep"
3187             start_ost || error "Unable to start OST1"
3188             wait $pid || error "statfs failed"
3189         fi
3190
3191         umount_client $MOUNT || error "Unable to unmount client"
3192         stop_ost || error "Unable to stop OST1"
3193         stop_mds || error "Unable to stop MDS"
3194 }
3195 run_test 50e "normal statfs all servers down"
3196
3197 test_50f() {
3198         local RC1
3199         local pid
3200         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
3201
3202         start_mds || error "Unable to start mds"
3203         #first client should see only one ost
3204         start_ost || error "Unable to start OST1"
3205         wait_osc_import_state mds ost FULL
3206
3207         start_ost2 || error "Unable to start OST2"
3208         wait_osc_import_state mds ost2 FULL
3209
3210         # Wait for client to detect down OST
3211         stop_ost2 || error "Unable to stop OST2"
3212
3213         wait_osc_import_state mds ost2 DISCONN
3214         mount_client $MOUNT || error "Unable to mount client"
3215         $LCTL set_param llite.$FSNAME-*.lazystatfs=0
3216
3217         multiop_bg_pause $MOUNT _f
3218         RC1=$?
3219         pid=$!
3220
3221         if [ $RC1 -ne 0 ]; then
3222                 log "lazystatfs multiop failed $RC1"
3223         else
3224             kill -USR1 $pid
3225             sleep $(( $TIMEOUT+1 ))
3226             kill -0 $pid
3227             [ $? -ne 0 ] && error "process isn't sleep"
3228             start_ost2 || error "Unable to start OST2"
3229             wait $pid || error "statfs failed"
3230             stop_ost2 || error "Unable to stop OST2"
3231         fi
3232
3233         umount_client $MOUNT || error "Unable to unmount client"
3234         stop_ost || error "Unable to stop OST1"
3235         stop_mds || error "Unable to stop MDS"
3236         #writeconf to remove all ost2 traces for subsequent tests
3237         writeconf_or_reformat
3238 }
3239 run_test 50f "normal statfs one server in down"
3240
3241 test_50g() {
3242         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
3243         setup
3244         start_ost2 || error "Unable to start OST2"
3245         wait_osc_import_state mds ost2 FULL
3246         wait_osc_import_state client ost2 FULL
3247
3248         local PARAM="${FSNAME}-OST0001.osc.active"
3249
3250         $SETSTRIPE -c -1 $DIR/$tfile || error "$SETSTRIPE failed"
3251         do_facet mgs $LCTL conf_param $PARAM=0 ||
3252                 error "Unable to deactivate OST"
3253
3254         umount_client $MOUNT || error "Unable to unmount client"
3255         mount_client $MOUNT || error "Unable to mount client"
3256         # This df should not cause a panic
3257         df -k $MOUNT
3258
3259         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
3260         rm -f $DIR/$tfile || error "unable to remove file $DIR/$tfile"
3261         umount_client $MOUNT || error "Unable to unmount client"
3262         stop_ost2 || error "Unable to stop OST2"
3263         stop_ost || error "Unable to stop OST1"
3264         stop_mds || error "Unable to stop MDS"
3265         #writeconf to remove all ost2 traces for subsequent tests
3266         writeconf_or_reformat
3267 }
3268 run_test 50g "deactivated OST should not cause panic"
3269
3270 # LU-642
3271 test_50h() {
3272         # prepare MDT/OST, make OSC inactive for OST1
3273         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
3274
3275         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3276         do_facet ost1 "$TUNEFS --param osc.active=0 `ostdevname 1`" ||
3277                 error "tunefs OST1 failed"
3278         start_mds  || error "Unable to start MDT"
3279         start_ost  || error "Unable to start OST1"
3280         start_ost2 || error "Unable to start OST2"
3281         mount_client $MOUNT || error "client start failed"
3282
3283         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3284
3285         # activatate OSC for OST1
3286         local TEST="$LCTL get_param -n osc.${FSNAME}-OST0000-osc-[!M]*.active"
3287         set_conf_param_and_check client                                 \
3288                 "$TEST" "${FSNAME}-OST0000.osc.active" 1 ||
3289                 error "Unable to activate OST1"
3290
3291         mkdir $DIR/$tdir/2 || error "mkdir $DIR/$tdir/2 failed"
3292         $SETSTRIPE -c -1 -i 0 $DIR/$tdir/2 ||
3293                 error "$SETSTRIPE $DIR/$tdir/2 failed"
3294         sleep 1 && echo "create a file after OST1 is activated"
3295         # create some file
3296         createmany -o $DIR/$tdir/2/$tfile-%d 1
3297
3298         # check OSC import is working
3299         stat $DIR/$tdir/2/* >/dev/null 2>&1 ||
3300                 error "some OSC imports are still not connected"
3301
3302         # cleanup
3303         umount_client $MOUNT || error "Unable to umount client"
3304         stop_ost2 || error "Unable to stop OST2"
3305         cleanup_nocli || error "cleanup_nocli failed with $?"
3306 }
3307 run_test 50h "LU-642: activate deactivated OST"
3308
3309 test_51() {
3310         local LOCAL_TIMEOUT=20
3311
3312         reformat
3313         setup_noconfig
3314         check_mount || error "check_mount failed"
3315
3316         mkdir $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
3317         $SETSTRIPE -c -1 $MOUNT/$tdir ||
3318                 error "$SETSTRIPE -c -1 $MOUNT/$tdir failed"
3319         #define OBD_FAIL_MDS_REINT_DELAY         0x142
3320         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x142"
3321         touch $MOUNT/$tdir/$tfile &
3322         local pid=$!
3323         sleep 2
3324         start_ost2 || error "Unable to start OST1"
3325         wait $pid
3326         stop_ost2 || error "Unable to stop OST1"
3327         cleanup || error "cleanup failed with $?"
3328         #writeconf to remove all ost2 traces for subsequent tests
3329         writeconf_or_reformat
3330 }
3331 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
3332
3333 copy_files_xattrs()
3334 {
3335         local node=$1
3336         local dest=$2
3337         local xattrs=$3
3338         shift 3
3339
3340         do_node $node mkdir -p $dest
3341         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3342
3343         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
3344                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3345         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
3346
3347         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
3348         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
3349 }
3350
3351 diff_files_xattrs()
3352 {
3353         local node=$1
3354         local backup=$2
3355         local xattrs=$3
3356         shift 3
3357
3358         local backup2=${TMP}/backup2
3359
3360         do_node $node mkdir -p $backup2
3361         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3362
3363         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
3364                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3365         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
3366
3367         do_node $node "diff -rq $backup $backup2"
3368         [ $? -eq 0 ] || { error "contents differ"; return 3; }
3369
3370         local xattrs2=${TMP}/xattrs2
3371         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
3372         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
3373
3374         do_node $node "diff $xattrs $xattrs2"
3375         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
3376
3377         do_node $node "rm -rf $backup2 $xattrs2"
3378         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
3379 }
3380
3381 test_52() {
3382         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3383                 skip "Only applicable to ldiskfs-based MDTs"
3384                 return
3385         fi
3386
3387         start_mds || error "Unable to start MDS"
3388         start_ost || error "Unable to start OST1"
3389         mount_client $MOUNT || error "Unable to mount client"
3390
3391         local nrfiles=8
3392         local ost1mnt=$(facet_mntpt ost1)
3393         local ost1node=$(facet_active_host ost1)
3394         local ost1tmp=$TMP/conf52
3395         local loop
3396
3397         mkdir $DIR/$tdir || error "Unable to create $DIR/$tdir"
3398         touch $TMP/modified_first || error "Unable to create temporary file"
3399         local mtime=$(stat -c %Y $TMP/modified_first)
3400         do_node $ost1node "mkdir -p $ost1tmp &&
3401                            touch -m -d @$mtime $ost1tmp/modified_first" ||
3402                 error "Unable to create temporary file"
3403         sleep 1
3404
3405         $SETSTRIPE -c -1 -S 1M $DIR/$tdir || error "$SETSTRIPE failed"
3406
3407         for (( i=0; i < nrfiles; i++ )); do
3408                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c ||
3409                         error "multiop failed"
3410                 echo -n .
3411         done
3412         echo
3413
3414         # backup files
3415         echo backup files to $TMP/files
3416         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
3417         copy_files_xattrs $(hostname) $TMP/files $TMP/file_xattrs $files ||
3418                 error "Unable to copy files"
3419
3420         umount_client $MOUNT || error "Unable to umount client"
3421         stop_ost || error "Unable to stop ost1"
3422
3423         echo mount ost1 as ldiskfs
3424         do_node $ost1node mkdir -p $ost1mnt || error "Unable to create $ost1mnt"
3425         if ! do_node $ost1node test -b $ost1_dev; then
3426                 loop="-o loop"
3427         fi
3428         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
3429                 $ost1mnt ||
3430                 error "Unable to mount ost1 as ldiskfs"
3431
3432         # backup objects
3433         echo backup objects to $ost1tmp/objects
3434         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/[0-9]* -type f'\
3435                 '-size +0 -newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
3436         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs \
3437                         $objects ||
3438                 error "Unable to copy objects"
3439
3440         # move objects to lost+found
3441         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
3442         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
3443
3444         # recover objects dry-run
3445         echo "ll_recover_lost_found_objs dry_run"
3446         do_node $ost1node "ll_recover_lost_found_objs -n -d $ost1mnt/O" ||
3447                 error "ll_recover_lost_found_objs failed"
3448
3449         # recover objects
3450         echo "ll_recover_lost_found_objs fix run"
3451         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found" ||
3452                  error "ll_recover_lost_found_objs failed"
3453
3454         # compare restored objects against saved ones
3455         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
3456         [ $? -eq 0 ] || error "Unable to diff objects"
3457
3458         do_node $ost1node "umount $ost1mnt" ||
3459                 error "Unable to umount ost1 as ldiskfs"
3460
3461         start_ost || error "Unable to start OST1"
3462         mount_client $MOUNT || error "Unable to mount client"
3463
3464         # compare files
3465         diff_files_xattrs $(hostname) $TMP/files $TMP/file_xattrs $files ||
3466                 error "Unable to diff files"
3467
3468         rm -rf $TMP/files $TMP/file_xattrs ||
3469                 error "Unable to delete temporary files"
3470         do_node $ost1node "rm -rf $ost1tmp" ||
3471                 error "Unable to delete temporary files"
3472         cleanup || error "cleanup failed with $?"
3473 }
3474 run_test 52 "check recovering objects from lost+found"
3475
3476 # Checks threads_min/max/started for some service
3477 #
3478 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
3479 # parameter pattern prefix like 'ost.*.ost'.
3480 thread_sanity() {
3481         local modname=$1
3482         local facet=$2
3483         local parampat=$3
3484         local opts=$4
3485         local basethr=$5
3486         local tmin
3487         local tmin2
3488         local tmax
3489         local tmax2
3490         local tstarted
3491         local paramp
3492         local msg="Insane $modname thread counts"
3493         local ncpts=$(check_cpt_number $facet)
3494         local nthrs
3495         shift 4
3496
3497         check_mount || return 41
3498
3499         # We need to expand $parampat, but it may match multiple parameters, so
3500         # we'll pick the first one
3501         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
3502                 error "Couldn't expand ${parampat}.threads_min parameter name"
3503                 return 22
3504         fi
3505
3506         # Remove the .threads_min part
3507         paramp=${paramp%.threads_min}
3508
3509         # Check for sanity in defaults
3510         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
3511                echo 0)
3512         tmax=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
3513                echo 0)
3514         tstarted=$(do_facet $facet "$LCTL get_param \
3515                                     -n ${paramp}.threads_started" || echo 0)
3516         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' ||
3517                 return $?
3518         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' ||
3519                 return $?
3520         nthrs=$(expr $tmax - $tmin)
3521         if [ $nthrs -lt $ncpts ]; then
3522                 nthrs=0
3523         else
3524                 nthrs=$ncpts
3525         fi
3526
3527         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
3528                 skip_env "module parameter forced $facet thread count" &&
3529                 tmin=3 && tmax=$((3 * tmax))
3530
3531         # Check that we can change min/max
3532         do_facet $facet "$LCTL set_param \
3533                          ${paramp}.threads_min=$((tmin + nthrs))"
3534         do_facet $facet "$LCTL set_param \
3535                          ${paramp}.threads_max=$((tmax - nthrs))"
3536         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
3537                 echo 0)
3538         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
3539                 echo 0)
3540         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) &&
3541                             $tmax2 == ($tmax - $nthrs)))' || return $?
3542
3543         # Check that we can set min/max to the same value
3544         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
3545                echo 0)
3546         do_facet $facet "$LCTL set_param ${paramp}.threads_max=$tmin"
3547         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
3548                 echo 0)
3549         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
3550                 echo 0)
3551         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
3552
3553         # Check that we can't set max < min
3554         do_facet $facet "$LCTL set_param ${paramp}.threads_max=$((tmin - 1))"
3555         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
3556                 echo 0)
3557         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
3558                 echo 0)
3559         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
3560
3561         # We need to ensure that we get the module options desired; to do this
3562         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
3563         LOAD_MODULES_REMOTE=true
3564         cleanup
3565         local oldvalue
3566         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
3567         setmodopts -a $modname "$newvalue" oldvalue
3568
3569         load_modules
3570         setup
3571         check_mount || return 41
3572
3573         # Restore previous setting of MODOPTS_*
3574         setmodopts $modname "$oldvalue"
3575
3576         # Check that $opts took
3577         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min")
3578         tmax=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max")
3579         tstarted=$(do_facet $facet \
3580                    "$LCTL get_param -n ${paramp}.threads_started")
3581         lassert 28 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' ||
3582                 return $?
3583         cleanup
3584
3585         load_modules
3586         setup
3587 }
3588
3589 test_53a() {
3590         setup
3591         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
3592         cleanup || error "cleanup failed with rc $?"
3593 }
3594 run_test 53a "check OSS thread count params"
3595
3596 test_53b() {
3597         setup
3598         local mds=$(do_facet $SINGLEMDS "$LCTL get_param \
3599                                          -N mds.*.*.threads_max 2>/dev/null")
3600         if [ -z "$mds" ]; then
3601                 #running this on an old MDT
3602                 thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' 16
3603         else
3604                 thread_sanity MDT $SINGLEMDS 'mds.*.*.' 'mds_num_threads' 16
3605         fi
3606         cleanup || error "cleanup failed with $?"
3607 }
3608 run_test 53b "check MDS thread count params"
3609
3610 test_54a() {
3611         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3612                 skip "Only applicable to ldiskfs-based MDTs"
3613                 return
3614         fi
3615
3616         do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p ||
3617                 error "llverdev failed with rc=$?"
3618         reformat_and_config
3619 }
3620 run_test 54a "test llverdev and partial verify of device"
3621
3622 test_54b() {
3623         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3624                 skip "Only applicable to ldiskfs-based MDTs"
3625                 return
3626         fi
3627
3628         setup
3629         run_llverfs $MOUNT -p || error "llverfs failed with rc=$?"
3630         cleanup || error "cleanup failed with rc=$?"
3631 }
3632 run_test 54b "test llverfs and partial verify of filesystem"
3633
3634 lov_objid_size()
3635 {
3636         local max_ost_index=$1
3637         echo -n $(((max_ost_index + 1) * 8))
3638 }
3639
3640 test_55() {
3641         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3642                 skip "Only applicable to ldiskfs-based MDTs"
3643                 return
3644         fi
3645
3646         local mdsdev=$(mdsdevname 1)
3647         local mdsvdev=$(mdsvdevname 1)
3648
3649         for i in 1023 2048
3650         do
3651                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
3652                         $mdsvdev || exit 10
3653                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
3654                         --reformat $(ostdevname 1) $(ostvdevname 1)
3655                 setup_noconfig
3656                 stopall
3657                 setup_noconfig
3658                 sync
3659
3660                 echo checking size of lov_objid for ost index $i
3661                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" | grep ^User | awk '{print $6}')
3662                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
3663                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
3664                 else
3665                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
3666                 fi
3667                 stopall
3668         done
3669
3670         reformat
3671 }
3672 run_test 55 "check lov_objid size"
3673
3674 test_56() {
3675         local mds_journal_size_orig=$MDSJOURNALSIZE
3676         local n
3677
3678         MDSJOURNALSIZE=16
3679
3680         for num in $(seq 1 $MDSCOUNT); do
3681                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3682                         --reformat $(mdsdevname $num) $(mdsvdevname $num)
3683         done
3684         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=10000 --reformat \
3685                 $(ostdevname 1) $(ostvdevname 1)
3686         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=1000 --reformat \
3687                 $(ostdevname 2) $(ostvdevname 2)
3688
3689         start_mgsmds
3690         start_ost || error "Unable to start first ost (idx 10000)"
3691         start_ost2 || error "Unable to start second ost (idx 1000)"
3692         mount_client $MOUNT || error "Unable to mount client"
3693         echo ok
3694         $LFS osts
3695         wait_osc_import_state mds ost1 FULL
3696         wait_osc_import_state mds ost2 FULL
3697         $SETSTRIPE --stripe-count=-1 $DIR/$tfile ||
3698                 error "Unable to setstripe $DIR/$tfile"
3699         n=$($LFS getstripe --stripe-count $DIR/$tfile)
3700         [ "$n" -eq 2 ] || error "Stripe count not two: $n"
3701         rm $DIR/$tfile
3702         stopall
3703         MDSJOURNALSIZE=$mds_journal_size_orig
3704         reformat
3705 }
3706 run_test 56 "check big OST indexes and out-of-index-order start"
3707
3708 test_57a() { # bug 22656
3709         do_rpc_nodes $(facet_active_host ost1) load_modules_local
3710         local NID=$(do_facet ost1 "$LCTL get_param nis" |
3711                     tail -1 | awk '{print $1}')
3712         writeconf_or_reformat
3713         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3714         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" ||
3715                 error "tunefs failed"
3716         start_mgsmds
3717         start_ost && error "OST registration from failnode should fail"
3718         reformat
3719 }
3720 run_test 57a "initial registration from failnode should fail (should return errs)"
3721
3722 test_57b() {
3723         do_rpc_nodes $(facet_active_host ost1) load_modules_local
3724         local NID=$(do_facet ost1 "$LCTL get_param nis" |
3725                     tail -1 | awk '{print $1}')
3726         writeconf_or_reformat
3727         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3728         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" ||
3729                 error "tunefs failed"
3730         start_mgsmds
3731         start_ost || error "OST registration from servicenode should not fail"
3732         reformat
3733 }
3734 run_test 57b "initial registration from servicenode should not fail"
3735
3736 count_osts() {
3737         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
3738 }
3739
3740 test_58() { # bug 22658
3741         setup_noconfig
3742         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3743         createmany -o $DIR/$tdir/$tfile-%d 100
3744         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
3745 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
3746         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x601"
3747         unlinkmany $DIR/$tdir/$tfile-%d 100
3748         stop_mds || error "Unable to stop MDS"
3749
3750         local MNTDIR=$(facet_mntpt $SINGLEMDS)
3751         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3752
3753         # remove all files from the OBJECTS dir
3754         mount_fstype $SINGLEMDS
3755
3756         do_facet $SINGLEMDS "find $MNTDIR/O/1/d* -type f -delete"
3757
3758         unmount_fstype $SINGLEMDS
3759         # restart MDS with missing llog files
3760         start_mds || error "unable to start MDS"
3761         do_facet mds "$LCTL set_param fail_loc=0"
3762         reformat
3763 }
3764 run_test 58 "missing llog files must not prevent MDT from mounting"
3765
3766 test_59() {
3767         start_mgsmds >> /dev/null
3768         local C1=$(count_osts)
3769         if [ $C1 -eq 0 ]; then
3770                 start_ost >> /dev/null
3771                 C1=$(count_osts)
3772         fi
3773         stopall
3774         echo "original ost count: $C1 (expect > 0)"
3775         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
3776         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
3777         local C2=$(count_osts)
3778         echo "after mdt writeconf count: $C2 (expect 0)"
3779         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
3780         echo "OST start without writeconf should fail:"
3781         start_ost >> /dev/null &&
3782                 error "OST start without writeconf didn't fail"
3783         echo "OST start with writeconf should succeed:"
3784         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
3785         local C3=$(count_osts)
3786         echo "after ost writeconf count: $C3 (expect 1)"
3787         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
3788         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
3789         local C4=$(count_osts)
3790         echo "after ost2 writeconf count: $C4 (expect 2)"
3791         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
3792         stop_ost2 >> /dev/null
3793         cleanup_nocli >> /dev/null
3794         #writeconf to remove all ost2 traces for subsequent tests
3795         writeconf_or_reformat
3796 }
3797 run_test 59 "writeconf mount option"
3798
3799 test_60() { # LU-471
3800         local num
3801
3802         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3803                 skip "Only applicable to ldiskfs-based MDTs"
3804                 return
3805         fi
3806
3807         for num in $(seq $MDSCOUNT); do
3808                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3809                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
3810                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3811                         exit 10
3812         done
3813
3814         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
3815         [ ${PIPESTATUS[0]} -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
3816
3817         # MDT default has dirdata feature
3818         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
3819         # we disable uninit_bg feature
3820         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
3821         # we set stride extended options
3822         echo $dump | grep stride > /dev/null || error "stride is not set"
3823         reformat
3824 }
3825 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
3826
3827 test_61() { # LU-80
3828         local reformat=false
3829
3830         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
3831                 { skip "Need MDS version at least 2.1.53"; return 0; }
3832
3833         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3834            ! large_xattr_enabled; then
3835                 reformat=true
3836                 LDISKFS_MKFS_OPTS+=" -O large_xattr"
3837
3838                 for num in $(seq $MDSCOUNT); do
3839                         add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
3840                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3841                         error "add mds $num failed"
3842                 done
3843         fi
3844
3845         setup_noconfig || error "setting up the filesystem failed"
3846         client_up || error "starting client failed"
3847
3848         local file=$DIR/$tfile
3849         touch $file || error "touch $file failed"
3850
3851         local large_value="$(generate_string $(max_xattr_size))"
3852         local small_value="bar"
3853
3854     local name="trusted.big"
3855     log "save large xattr $name on $file"
3856     setfattr -n $name -v $large_value $file ||
3857         error "saving $name on $file failed"
3858
3859     local new_value=$(get_xattr_value $name $file)
3860     [[ "$new_value" != "$large_value" ]] &&
3861         error "$name different after saving"
3862
3863     log "shrink value of $name on $file"
3864     setfattr -n $name -v $small_value $file ||
3865         error "shrinking value of $name on $file failed"
3866
3867     new_value=$(get_xattr_value $name $file)
3868     [[ "$new_value" != "$small_value" ]] &&
3869         error "$name different after shrinking"
3870
3871     log "grow value of $name on $file"
3872     setfattr -n $name -v $large_value $file ||
3873         error "growing value of $name on $file failed"
3874
3875     new_value=$(get_xattr_value $name $file)
3876     [[ "$new_value" != "$large_value" ]] &&
3877         error "$name different after growing"
3878
3879     log "check value of $name on $file after remounting MDS"
3880     fail $SINGLEMDS
3881     new_value=$(get_xattr_value $name $file)
3882     [[ "$new_value" != "$large_value" ]] &&
3883         error "$name different after remounting MDS"
3884
3885     log "remove large xattr $name from $file"
3886     setfattr -x $name $file || error "removing $name from $file failed"
3887
3888     rm -f $file
3889     stopall
3890         if $reformat; then
3891                 LDISKFS_MKFS_OPTS=${LDISKFS_MKFS_OPTS% -O large_xattr}
3892                 reformat
3893         fi
3894 }
3895 run_test 61 "large xattr"
3896
3897 test_62() {
3898         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3899                 skip "Only applicable to ldiskfs-based MDTs"
3900                 return
3901         fi
3902
3903         # MRP-118
3904         local mdsdev=$(mdsdevname 1)
3905         local ostdev=$(ostdevname 1)
3906
3907         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
3908                 { skip "Need MDS version at least 2.2.51"; return 0; }
3909
3910         echo "disable journal for mds"
3911         do_facet mds tune2fs -O ^has_journal $mdsdev || error "tune2fs failed"
3912         start_mds && error "MDT start should fail"
3913         echo "disable journal for ost"
3914         do_facet ost1 tune2fs -O ^has_journal $ostdev || error "tune2fs failed"
3915         start_ost && error "OST start should fail"
3916         cleanup || error "cleanup failed with rc $?"
3917         reformat_and_config
3918 }
3919 run_test 62 "start with disabled journal"
3920
3921 test_63() {
3922         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3923                 skip "Only applicable to ldiskfs-based MDTs"
3924                 return
3925         fi
3926
3927         local inode_slab=$(do_facet $SINGLEMDS \
3928                 "awk '/ldiskfs_inode_cache/ { print \\\$5 }' /proc/slabinfo")
3929         if [ -z "$inode_slab" ]; then
3930                 skip "ldiskfs module has not been loaded"
3931                 return
3932         fi
3933
3934         echo "$inode_slab ldisk inodes per page"
3935         [ "$inode_slab" -ge "3" ] ||
3936                 error "ldisk inode size is too big, $inode_slab objs per page"
3937         return
3938 }
3939 run_test 63 "Verify each page can at least hold 3 ldisk inodes"
3940
3941 test_64() {
3942         start_mds || error "unable to start MDS"
3943         start_ost || error "Unable to start OST1"
3944         start_ost2 || error "Unable to start second ost"
3945         mount_client $MOUNT || error "Unable to mount client"
3946         stop_ost2 || error "Unable to stop second ost"
3947         echo "$LFS df"
3948         $LFS df --lazy || error "lfs df failed"
3949         cleanup || error "cleanup failed with $?"
3950         #writeconf to remove all ost2 traces for subsequent tests
3951         writeconf_or_reformat
3952 }
3953 run_test 64 "check lfs df --lazy "
3954
3955 test_65() { # LU-2237
3956         # Currently, the test is only valid for ldiskfs backend
3957         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3958                 skip "non-ldiskfs backend" && return
3959
3960         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3961         local brpt=$(facet_mntpt brpt)
3962         local opts=""
3963
3964         if ! do_facet $SINGLEMDS "test -b $devname"; then
3965                 opts="-o loop"
3966         fi
3967
3968         stop_mds || error "Unable to stop MDS"
3969         local obj=$(do_facet $SINGLEMDS \
3970                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
3971                     grep Inode)
3972         if [ -z "$obj" ]; then
3973                 # The MDT may be just re-formatted, mount the MDT for the
3974                 # first time to guarantee the "last_rcvd" file is there.
3975                 start_mds || error "fail to mount the MDS for the first time"
3976                 stop_mds || error "Unable to stop MDS"
3977         fi
3978
3979         # remove the "last_rcvd" file
3980         do_facet $SINGLEMDS "mkdir -p $brpt"
3981         do_facet $SINGLEMDS \
3982                 "mount -t $(facet_fstype $SINGLEMDS) $opts $devname $brpt"
3983         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
3984         do_facet $SINGLEMDS "umount -d $brpt"
3985
3986         # restart MDS, the "last_rcvd" file should be recreated.
3987         start_mds || error "fail to restart the MDS"
3988         stop_mds || error "Unable to stop MDS"
3989         obj=$(do_facet $SINGLEMDS \
3990               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
3991         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
3992 }
3993 run_test 65 "re-create the lost last_rcvd file when server mount"
3994
3995 test_66() {
3996         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
3997                 { skip "Need MGS version at least 2.3.59"; return 0; }
3998
3999         setup
4000         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
4001         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
4002
4003         echo "replace_nids should fail if MDS, OSTs and clients are UP"
4004         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4005                 error "replace_nids fail"
4006
4007         umount_client $MOUNT || error "unmounting client failed"
4008         echo "replace_nids should fail if MDS and OSTs are UP"
4009         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4010                 error "replace_nids fail"
4011
4012         stop_ost || error "Unable to stop OST1"
4013         echo "replace_nids should fail if MDS is UP"
4014         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4015                 error "replace_nids fail"
4016
4017         stop_mds || error "stopping mds failed"
4018
4019         if combined_mgs_mds; then
4020                 start_mdt 1 "-o nosvc" ||
4021                         error "starting mds with nosvc option failed"
4022         fi
4023
4024         echo "command should accept two parameters"
4025         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
4026                 error "command should accept two params"
4027
4028         echo "correct device name should be passed"
4029         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
4030                 error "wrong devname"
4031
4032         echo "wrong nids list should not destroy the system"
4033         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
4034                 error "wrong parse"
4035
4036         echo "replace OST nid"
4037         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
4038                 error "replace nids failed"
4039
4040         echo "command should accept two parameters"
4041         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
4042                 error "command should accept two params"
4043
4044         echo "wrong nids list should not destroy the system"
4045         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
4046                 error "wrong parse"
4047
4048         echo "replace MDS nid"
4049         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
4050                 error "replace nids failed"
4051
4052         if ! combined_mgs_mds ; then
4053                 stop_mgs
4054         else
4055                 stop_mds || error "Unable to stop MDS"
4056         fi
4057
4058         setup_noconfig
4059         check_mount || error "error after nid replace"
4060         cleanup || error "cleanup failed"
4061         reformat
4062 }
4063 run_test 66 "replace nids"
4064
4065 test_67() { #LU-2950
4066         local legacy="$TMP/legacy_lnet_config"
4067         local new="$TMP/new_routes_test"
4068         local out="$TMP/config_out_file"
4069         local verify="$TMP/conv_verify"
4070         local verify_conf="$TMP/conf_verify"
4071
4072         # Create the legacy file that will be run through the
4073         # lustre_routes_conversion script
4074         cat <<- LEGACY_LNET_CONFIG > $legacy
4075                 tcp1 23 192.168.213.1@tcp:1; tcp5 34 193.30.4.3@tcp:4;
4076                 tcp2 54 10.1.3.2@tcp;
4077                 tcp3 10.3.4.3@tcp:3;
4078                 tcp4 10.3.3.4@tcp;
4079         LEGACY_LNET_CONFIG
4080
4081         # Create the verification file to verify the output of
4082         # lustre_routes_conversion script against.
4083         cat <<- VERIFY_LNET_CONFIG > $verify
4084                 tcp1: { gateway: 192.168.213.1@tcp, hop: 23, priority: 1 }
4085                 tcp5: { gateway: 193.30.4.3@tcp, hop: 34, priority: 4 }
4086                 tcp2: { gateway: 10.1.3.2@tcp, hop: 54 }
4087                 tcp3: { gateway: 10.3.4.3@tcp, priority: 3 }
4088                 tcp4: { gateway: 10.3.3.4@tcp }
4089         VERIFY_LNET_CONFIG
4090
4091         # Create the verification file to verify the output of
4092         # lustre_routes_config script against
4093         cat <<- VERIFY_LNET_CONFIG > $verify_conf
4094                 lctl --net tcp1 add_route 192.168.213.1@tcp 23 1
4095                 lctl --net tcp5 add_route 193.30.4.3@tcp 34 4
4096                 lctl --net tcp2 add_route 10.1.3.2@tcp 54 4
4097                 lctl --net tcp3 add_route 10.3.4.3@tcp 1 3
4098                 lctl --net tcp4 add_route 10.3.3.4@tcp 1 3
4099         VERIFY_LNET_CONFIG
4100
4101         lustre_routes_conversion $legacy $new > /dev/null
4102         if [ -f $new ]; then
4103                 # verify the conversion output
4104                 cmp -s $new $verify > /dev/null
4105                 if [ $? -eq 1 ]; then
4106                         error "routes conversion failed"
4107                 fi
4108
4109                 lustre_routes_config --dry-run --verbose $new > $out
4110                 # check that the script succeeded
4111                 cmp -s $out $verify_conf > /dev/null
4112                 if [ $? -eq 1 ]; then
4113                         error "routes config failed"
4114                 fi
4115         else
4116                 error "routes conversion test failed"
4117         fi
4118         # remove generated files
4119         rm -f $new $legacy $verify $verify_conf $out
4120 }
4121 run_test 67 "test routes conversion and configuration"
4122
4123 test_68() {
4124         local fid
4125         local seq
4126         local START
4127         local END
4128
4129         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.53) ] ||
4130                 { skip "Need MDS version at least 2.4.53"; return 0; }
4131
4132         umount_client $MOUNT || error "umount client failed"
4133
4134         start_mdt 1 || error "MDT start failed"
4135         start_ost || error "Unable to start OST1"
4136
4137         # START-END - the sequences we'll be reserving
4138         START=$(do_facet $SINGLEMDS \
4139                 $LCTL get_param -n seq.ctl*.space | awk -F'[[ ]' '{print $2}')
4140         END=$((START + (1 << 30)))
4141         do_facet $SINGLEMDS \
4142                 $LCTL set_param seq.ctl*.fldb="[$START-$END\):0:mdt"
4143
4144         # reset the sequences MDT0000 has already assigned
4145         do_facet $SINGLEMDS \
4146                 $LCTL set_param seq.srv*MDT0000.space=clear
4147
4148         # remount to let the client allocate new sequence
4149         mount_client $MOUNT || error "mount client failed"
4150
4151         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4152         do_facet $SINGLEMDS \
4153                 $LCTL get_param seq.srv*MDT0000.space
4154         $LFS path2fid $DIR/$tfile
4155
4156         local old_ifs="$IFS"
4157         IFS='[:]'
4158         fid=($($LFS path2fid $DIR/$tfile))
4159         IFS="$old_ifs"
4160         let seq=${fid[1]}
4161
4162         if [[ $seq < $END ]]; then
4163                 error "used reserved sequence $seq?"
4164         fi
4165         cleanup || error "cleanup failed with $?"
4166 }
4167 run_test 68 "be able to reserve specific sequences in FLDB"
4168
4169 test_69() {
4170         local server_version=$(lustre_version_code $SINGLEMDS)
4171
4172         [[ $server_version -lt $(version_code 2.4.2) ]] &&
4173                 skip "Need MDS version at least 2.4.2" && return
4174
4175         [[ $server_version -ge $(version_code 2.4.50) ]] &&
4176         [[ $server_version -lt $(version_code 2.5.0) ]] &&
4177                 skip "Need MDS version at least 2.5.0" && return
4178
4179         setup
4180
4181         # use OST0000 since it probably has the most creations
4182         local OSTNAME=$(ostname_from_index 0)
4183         local mdtosc_proc1=$(get_mdtosc_proc_path mds1 $OSTNAME)
4184         local last_id=$(do_facet mds1 $LCTL get_param -n \
4185                         osc.$mdtosc_proc1.prealloc_last_id)
4186
4187         # Want to have OST LAST_ID over 1.5 * OST_MAX_PRECREATE to
4188         # verify that the LAST_ID recovery is working properly.  If
4189         # not, then the OST will refuse to allow the MDS connect
4190         # because the LAST_ID value is too different from the MDS
4191         #define OST_MAX_PRECREATE=20000
4192         local num_create=$((20000 * 5))
4193
4194         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4195         $SETSTRIPE -i 0 $DIR/$tdir || error "$SETSTRIPE -i 0 $DIR/$tdir failed"
4196         createmany -o $DIR/$tdir/$tfile- $num_create ||
4197                 error "createmany: failed to create $num_create files: $?"
4198         # delete all of the files with objects on OST0 so the
4199         # filesystem is not inconsistent later on
4200         $LFS find $MOUNT --ost 0 | xargs rm
4201
4202         stop_ost || error "OST0 stop failure"
4203         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat --replace \
4204                 $(ostdevname 1) $(ostvdevname 1) ||
4205                 error "reformat and replace $ostdev failed"
4206         start_ost || error "OST0 restart failure"
4207         wait_osc_import_state mds ost FULL
4208
4209         touch $DIR/$tdir/$tfile-last || error "create file after reformat"
4210         local idx=$($GETSTRIPE -i $DIR/$tdir/$tfile-last)
4211         [ $idx -ne 0 ] && error "$DIR/$tdir/$tfile-last on $idx not 0" || true
4212
4213         cleanup || error "cleanup failed with $?"
4214 }
4215 run_test 69 "replace an OST with the same index"
4216
4217 test_70a() {
4218         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4219         local MDTIDX=1
4220
4221         cleanup || error "cleanup failed with $?"
4222
4223         start_mdt 1 || error "MDT0 start fail"
4224
4225         start_ost || error "OST0 start fail"
4226
4227         start_mdt 2 || error "MDT1 start fail"
4228
4229         mount_client $MOUNT || error "mount client fails"
4230
4231         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
4232
4233         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4234                 error "create remote dir fail"
4235
4236         rm -rf $DIR/$tdir || error "delete dir fail"
4237         cleanup || error "cleanup failed with $?"
4238 }
4239 run_test 70a "start MDT0, then OST, then MDT1"
4240
4241 test_70b() {
4242         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4243         local MDTIDX=1
4244
4245         start_ost || error "OST0 start fail"
4246
4247         start_mdt 1 || error "MDT0 start fail"
4248         start_mdt 2 || error "MDT1 start fail"
4249
4250         mount_client $MOUNT || error "mount client fails"
4251
4252         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
4253
4254         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4255                 error "create remote dir fail"
4256
4257         rm -rf $DIR/$tdir || error "delete dir fail"
4258
4259         cleanup || error "cleanup failed with $?"
4260 }
4261 run_test 70b "start OST, MDT1, MDT0"
4262
4263 test_70c() {
4264         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4265         local MDTIDX=1
4266
4267         start_mdt 1 || error "MDT0 start fail"
4268         start_mdt 2 || error "MDT1 start fail"
4269         start_ost || error "OST0 start fail"
4270
4271         mount_client $MOUNT || error "mount client fails"
4272         stop_mdt 1 || error "MDT1 start fail"
4273
4274         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
4275         echo "deactivate $mdc_for_mdt1"
4276         $LCTL --device $mdc_for_mdt1 deactivate ||
4277                 error "set $mdc_for_mdt1 deactivate failed"
4278
4279         mkdir $DIR/$tdir && error "mkdir succeed"
4280
4281         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4282                 error "create remote dir succeed"
4283
4284         cleanup || error "cleanup failed with $?"
4285 }
4286 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
4287
4288 test_70d() {
4289         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4290         local MDTIDX=1
4291
4292         start_mdt 1 || error "MDT0 start fail"
4293         start_mdt 2 || error "MDT1 start fail"
4294         start_ost || error "OST0 start fail"
4295
4296         mount_client $MOUNT || error "mount client fails"
4297
4298         stop_mdt 2 || error "MDT1 start fail"
4299
4300         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
4301                              awk '{print $4}')
4302         echo "deactivate $mdc_for_mdt2"
4303         $LCTL --device $mdc_for_mdt2 deactivate ||
4304                 error "set $mdc_for_mdt2 deactivate failed"
4305
4306         mkdir $DIR/$tdir || error "mkdir fail"
4307         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4308                 error "create remote dir succeed"
4309
4310         rm -rf $DIR/$tdir || error "delete dir fail"
4311
4312         cleanup || error "cleanup failed with $?"
4313 }
4314 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
4315
4316 test_71a() {
4317         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4318         if combined_mgs_mds; then
4319                 skip "needs separate MGS/MDT" && return
4320         fi
4321         local MDTIDX=1
4322
4323         start_mdt 1 || error "MDT0 start fail"
4324         start_ost || error "OST0 start fail"
4325         start_mdt 2 || error "MDT1 start fail"
4326         start_ost2 || error "OST1 start fail"
4327
4328         mount_client $MOUNT || error "mount client fails"
4329
4330         mkdir $DIR/$tdir || error "mkdir fail"
4331         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4332                 error "create remote dir succeed"
4333
4334         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4335         rm -rf $DIR/$tdir || error "delete dir fail"
4336
4337         umount_client $MOUNT || error "umount_client failed"
4338         stop_mdt 1 || error "MDT0 stop fail"
4339         stop_mdt 2 || error "MDT1 stop fail"
4340         stop_ost || error "OST0 stop fail"
4341         stop_ost2 || error "OST1 stop fail"
4342 }
4343 run_test 71a "start MDT0 OST0, MDT1, OST1"
4344
4345 test_71b() {
4346         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4347         if combined_mgs_mds; then
4348                 skip "needs separate MGS/MDT" && return
4349         fi
4350         local MDTIDX=1
4351
4352         start_mdt 2 || error "MDT1 start fail"
4353         start_ost || error "OST0 start fail"
4354         start_mdt 1 || error "MDT0 start fail"
4355         start_ost2 || error "OST1 start fail"
4356
4357         mount_client $MOUNT || error "mount client fails"
4358
4359         mkdir $DIR/$tdir || error "mkdir fail"
4360         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4361                 error "create remote dir succeed"
4362
4363         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4364         rm -rf $DIR/$tdir || error "delete dir fail"
4365
4366         umount_client $MOUNT || error "umount_client failed"
4367         stop_mdt 1 || error "MDT0 stop fail"
4368         stop_mdt 2 || error "MDT1 stop fail"
4369         stop_ost || error "OST0 stop fail"
4370         stop_ost2 || error "OST1 stop fail"
4371 }
4372 run_test 71b "start MDT1, OST0, MDT0, OST1"
4373
4374 test_71c() {
4375         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4376         if combined_mgs_mds; then
4377                 skip "needs separate MGS/MDT" && return
4378         fi
4379         local MDTIDX=1
4380
4381         start_ost || error "OST0 start fail"
4382         start_ost2 || error "OST1 start fail"
4383         start_mdt 2 || error "MDT1 start fail"
4384         start_mdt 1 || error "MDT0 start fail"
4385
4386         mount_client $MOUNT || error "mount client fails"
4387
4388         mkdir $DIR/$tdir || error "mkdir fail"
4389         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4390                 error "create remote dir succeed"
4391
4392         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4393         rm -rf $DIR/$tdir || error "delete dir fail"
4394
4395         umount_client $MOUNT || error "umount_client failed"
4396         stop_mdt 1 || error "MDT0 stop fail"
4397         stop_mdt 2 || error "MDT1 stop fail"
4398         stop_ost || error "OST0 stop fail"
4399         stop_ost2 || error "OST1 stop fail"
4400
4401 }
4402 run_test 71c "start OST0, OST1, MDT1, MDT0"
4403
4404 test_71d() {
4405         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4406         if combined_mgs_mds; then
4407                 skip "needs separate MGS/MDT" && return
4408         fi
4409         local MDTIDX=1
4410
4411         start_ost || error "OST0 start fail"
4412         start_mdt 2 || error "MDT0 start fail"
4413         start_mdt 1 || error "MDT0 start fail"
4414         start_ost2 || error "OST1 start fail"
4415
4416         mount_client $MOUNT || error "mount client fails"
4417
4418         mkdir $DIR/$tdir || error "mkdir fail"
4419         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4420                         error "create remote dir succeed"
4421
4422         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4423         rm -rf $DIR/$tdir || error "delete dir fail"
4424
4425         umount_client $MOUNT || error "umount_client failed"
4426         stop_mdt 1 || error "MDT0 stop fail"
4427         stop_mdt 2 || error "MDT1 stop fail"
4428         stop_ost || error "OST0 stop fail"
4429         stop_ost2 || error "OST1 stop fail"
4430
4431 }
4432 run_test 71d "start OST0, MDT1, MDT0, OST1"
4433
4434 test_71e() {
4435         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4436         if combined_mgs_mds; then
4437                 skip "needs separate MGS/MDT" && return
4438         fi
4439         local MDTIDX=1
4440
4441         start_ost || error "OST0 start fail"
4442         start_mdt 2 || error "MDT1 start fail"
4443         start_ost2 || error "OST1 start fail"
4444         start_mdt 1 || error "MDT0 start fail"
4445
4446         mount_client $MOUNT || error "mount client fails"
4447
4448         mkdir $DIR/$tdir || error "mkdir fail"
4449         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4450                 error "create remote dir succeed"
4451
4452         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4453         rm -rf $DIR/$tdir || error "delete dir fail"
4454
4455         umount_client $MOUNT || error "umount_client failed"
4456         stop_mdt 1 || error "MDT0 stop fail"
4457         stop_mdt 2 || error "MDT1 stop fail"
4458         stop_ost || error "OST0 stop fail"
4459         stop_ost2 || error "OST1 stop fail"
4460
4461 }
4462 run_test 71e "start OST0, MDT1, OST1, MDT0"
4463
4464 test_72() { #LU-2634
4465         local mdsdev=$(mdsdevname 1)
4466         local ostdev=$(ostdevname 1)
4467         local cmd="$E2FSCK -fnvd $mdsdev"
4468         local fn=3
4469
4470         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
4471                 skip "ldiskfs only test" && return
4472
4473         #tune MDT with "-O extents"
4474
4475         for num in $(seq $MDSCOUNT); do
4476                 add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
4477                 --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
4478                 error "add mds $num failed"
4479                 $TUNE2FS -O extents $(mdsdevname $num)
4480         done
4481
4482         add ost1 $(mkfs_opts ost1 $ostdev) --reformat $ostdev ||
4483                 error "add $ostdev failed"
4484         start_mgsmds || error "start mds failed"
4485         start_ost || error "start ost failed"
4486         mount_client $MOUNT || error "mount client failed"
4487
4488         #create some short symlinks
4489         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4490         createmany -o $DIR/$tdir/$tfile-%d $fn
4491         echo "create $fn short symlinks"
4492         for i in $(seq -w 1 $fn); do
4493                 ln -s $DIR/$tdir/$tfile-$i $MOUNT/$tfile-$i
4494         done
4495         ls -al $MOUNT
4496
4497         #umount
4498         umount_client $MOUNT || error "umount client failed"
4499         stop_mds || error "stop mds failed"
4500         stop_ost || error "stop ost failed"
4501
4502         #run e2fsck
4503         run_e2fsck $(facet_active_host $SINGLEMDS) $mdsdev "-n"
4504 }
4505 run_test 72 "test fast symlink with extents flag enabled"
4506
4507 test_73() { #LU-3006
4508         load_modules
4509         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
4510         do_facet ost1 "$TUNEFS --failnode=1.2.3.4@$NETTYPE $(ostdevname 1)" ||
4511                 error "1st tunefs failed"
4512         start_mgsmds || error "start mds failed"
4513         start_ost || error "start ost failed"
4514         mount_client $MOUNT || error "mount client failed"
4515         $LCTL get_param -n osc.*OST0000-osc-[^M]*.import | grep failover_nids |
4516                 grep 1.2.3.4@$NETTYPE || error "failover nids haven't changed"
4517         umount_client $MOUNT || error "umount client failed"
4518         stopall
4519         reformat
4520 }
4521 run_test 73 "failnode to update from mountdata properly"
4522
4523 test_75() { # LU-2374
4524         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
4525                         skip "Need MDS version at least 2.4.1" && return
4526
4527         local index=0
4528         local opts_mds="$(mkfs_opts mds1 $(mdsdevname 1)) \
4529                 --reformat $(mdsdevname 1) $(mdsvdevname 1)"
4530         local opts_ost="$(mkfs_opts ost1 $(ostdevname 1)) \
4531                 --reformat $(ostdevname 1) $(ostvdevname 1)"
4532
4533         #check with default parameters
4534         add mds1 $opts_mds || error "add mds1 failed for default params"
4535         add ost1 $opts_ost || error "add ost1 failed for default params"
4536
4537         opts_mds=$(echo $opts_mds | sed -e "s/--mdt//")
4538         opts_mds=$(echo $opts_mds |
4539                    sed -e "s/--index=$index/--index=$index --mdt/")
4540         opts_ost=$(echo $opts_ost | sed -e "s/--ost//")
4541         opts_ost=$(echo $opts_ost |
4542                    sed -e "s/--index=$index/--index=$index --ost/")
4543
4544         add mds1 $opts_mds || error "add mds1 failed for new params"
4545         add ost1 $opts_ost || error "add ost1 failed for new params"
4546         return 0
4547 }
4548 run_test 75 "The order of --index should be irrelevant"
4549
4550 test_76a() {
4551         [[ $(lustre_version_code mgs) -ge $(version_code 2.4.52) ]] ||
4552                 { skip "Need MDS version at least 2.4.52" && return 0; }
4553         setup
4554         local MDMB_PARAM="osc.*.max_dirty_mb"
4555         echo "Change MGS params"
4556         local MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM |
4557                 head -1)
4558         echo "max_dirty_mb: $MAX_DIRTY_MB"
4559         local NEW_MAX_DIRTY_MB=$((MAX_DIRTY_MB + MAX_DIRTY_MB))
4560         echo "new_max_dirty_mb: $NEW_MAX_DIRTY_MB"
4561         do_facet mgs $LCTL set_param -P $MDMB_PARAM=$NEW_MAX_DIRTY_MB
4562         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
4563                 head -1" $NEW_MAX_DIRTY_MB
4564         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
4565         echo "$MAX_DIRTY_MB"
4566         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
4567                 error "error while apply max_dirty_mb"
4568
4569         echo "Check the value is stored after remount"
4570         stopall
4571         setupall
4572         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
4573                 head -1" $NEW_MAX_DIRTY_MB
4574         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
4575         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
4576                 error "max_dirty_mb is not saved after remount"
4577
4578         echo "Change OST params"
4579         CLIENT_PARAM="obdfilter.*.client_cache_count"
4580         local CLIENT_CACHE_COUNT
4581         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4582                 head -1)
4583         echo "client_cache_count: $CLIENT_CACHE_COUNT"
4584         NEW_CLIENT_CACHE_COUNT=$((CLIENT_CACHE_COUNT+CLIENT_CACHE_COUNT))
4585         echo "new_client_cache_count: $NEW_CLIENT_CACHE_COUNT"
4586         do_facet mgs $LCTL set_param -P $CLIENT_PARAM=$NEW_CLIENT_CACHE_COUNT
4587         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
4588                 head -1" $NEW_CLIENT_CACHE_COUNT
4589         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4590                 head -1)
4591         echo "$CLIENT_CACHE_COUNT"
4592         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
4593                 error "error while apply client_cache_count"
4594
4595         echo "Check the value is stored after remount"
4596         stopall
4597         setupall
4598         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
4599                 head -1" $NEW_CLIENT_CACHE_COUNT
4600         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4601                 head -1)
4602         echo "$CLIENT_CACHE_COUNT"
4603         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
4604                 error "client_cache_count is not saved after remount"
4605         stopall
4606 }
4607 run_test 76a "set permanent params set_param -P"
4608
4609 test_76b() { # LU-4783
4610         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.57) ]] ||
4611                 { skip "Need MGS version at least 2.5.57" && return 0; }
4612         stopall
4613         setupall
4614         do_facet mgs $LCTL get_param mgs.MGS.live.params ||
4615                 error "start params log failed"
4616         stopall
4617 }
4618 run_test 76b "verify params log setup correctly"
4619
4620 test_77() { # LU-3445
4621         local server_version=$(lustre_version_code $SINGLEMDS)
4622
4623         [[ $server_version -ge $(version_code 2.2.60) ]] &&
4624         [[ $server_version -le $(version_code 2.4.0) ]] &&
4625                 skip "Need MDS version < 2.2.60 or > 2.4.0" && return
4626
4627         if [[ -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
4628                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
4629                 skip_env "mixed loopback and real device not working" && return
4630         fi
4631
4632         local fs2mdsdev=$(mdsdevname 1_2)
4633         local fs2ostdev=$(ostdevname 1_2)
4634         local fs2mdsvdev=$(mdsvdevname 1_2)
4635         local fs2ostvdev=$(ostvdevname 1_2)
4636         local fsname=test1234
4637         local mgsnid
4638         local failnid="$(h2$NETTYPE 1.2.3.4),$(h2$NETTYPE 4.3.2.1)"
4639
4640         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --mgs --fsname=$fsname \
4641                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
4642         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT ||
4643                 error "start fs2mds failed"
4644
4645         mgsnid=$(do_facet fs2mds $LCTL list_nids | xargs | tr ' ' ,)
4646         [[ $mgsnid = *,* ]] || mgsnid+=",$mgsnid"
4647
4648         add fs2ost $(mkfs_opts ost1 $fs2ostdev) --mgsnode=$mgsnid \
4649                 --failnode=$failnid --fsname=$fsname \
4650                 --reformat $fs2ostdev $fs2ostvdev ||
4651                         error "add fs2ost failed"
4652         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
4653
4654         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
4655         $MOUNT_CMD $mgsnid:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
4656         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
4657         cleanup_fs2
4658 }
4659 run_test 77 "comma-separated MGS NIDs and failover node NIDs"
4660
4661 test_78() {
4662         [[ $(facet_fstype $SINGLEMDS) != ldiskfs ||
4663            $(facet_fstype ost1) != ldiskfs ]] &&
4664                 skip "only applicable to ldiskfs-based MDTs and OSTs" && return
4665
4666         # reformat the Lustre filesystem with a smaller size
4667         local saved_MDSSIZE=$MDSSIZE
4668         local saved_OSTSIZE=$OSTSIZE
4669         MDSSIZE=$((MDSSIZE - 20000))
4670         OSTSIZE=$((OSTSIZE - 20000))
4671         reformat || error "(1) reformat Lustre filesystem failed"
4672         MDSSIZE=$saved_MDSSIZE
4673         OSTSIZE=$saved_OSTSIZE
4674
4675         # mount the Lustre filesystem
4676         setup_noconfig || error "(2) setup Lustre filesystem failed"
4677
4678         # create some files
4679         log "create test files"
4680         local i
4681         local file
4682         local num_files=100
4683         mkdir $MOUNT/$tdir || error "(3) mkdir $MOUNT/$tdir failed"
4684         for i in $(seq $num_files); do
4685                 file=$MOUNT/$tdir/$tfile-$i
4686                 dd if=/dev/urandom of=$file count=1 bs=1M ||
4687                         error "(4) create $file failed"
4688         done
4689
4690         # unmount the Lustre filesystem
4691         cleanup || error "(5) cleanup Lustre filesystem failed"
4692
4693         # run e2fsck on the MDT and OST devices
4694         local mds_host=$(facet_active_host $SINGLEMDS)
4695         local ost_host=$(facet_active_host ost1)
4696         local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4697         local ost_dev=$(ostdevname 1)
4698
4699         run_e2fsck $mds_host $mds_dev "-y"
4700         run_e2fsck $ost_host $ost_dev "-y"
4701
4702         # get the original block count of the MDT and OST filesystems
4703         local mds_orig_blks=$(get_block_count $SINGLEMDS $mds_dev)
4704         local ost_orig_blks=$(get_block_count ost1 $ost_dev)
4705
4706         # expand the MDT and OST filesystems to the device size
4707         run_resize2fs $SINGLEMDS $mds_dev "" || error "expand $SINGLEMDS failed"
4708         run_resize2fs ost1 $ost_dev "" || error "expand ost1 failed"
4709
4710         # run e2fsck on the MDT and OST devices again
4711         run_e2fsck $mds_host $mds_dev "-y"
4712         run_e2fsck $ost_host $ost_dev "-y"
4713
4714         # mount the Lustre filesystem
4715         setup
4716
4717         # check the files
4718         log "check files after expanding the MDT and OST filesystems"
4719         for i in $(seq $num_files); do
4720                 file=$MOUNT/$tdir/$tfile-$i
4721                 $CHECKSTAT -t file -s 1048576 $file ||
4722                         error "(6) checkstat $file failed"
4723         done
4724
4725         # create more files
4726         log "create more files after expanding the MDT and OST filesystems"
4727         for i in $(seq $((num_files + 1)) $((num_files + 10))); do
4728                 file=$MOUNT/$tdir/$tfile-$i
4729                 dd if=/dev/urandom of=$file count=1 bs=1M ||
4730                         error "(7) create $file failed"
4731         done
4732
4733         # unmount the Lustre filesystem
4734         cleanup || error "(8) cleanup Lustre filesystem failed"
4735
4736         # run e2fsck on the MDT and OST devices
4737         run_e2fsck $mds_host $mds_dev "-y"
4738         run_e2fsck $ost_host $ost_dev "-y"
4739
4740         # get the maximum block count of the MDT and OST filesystems
4741         local mds_max_blks=$(get_block_count $SINGLEMDS $mds_dev)
4742         local ost_max_blks=$(get_block_count ost1 $ost_dev)
4743
4744         # get the minimum block count of the MDT and OST filesystems
4745         local mds_min_blks=$(run_resize2fs $SINGLEMDS $mds_dev "" "-P" 2>&1 |
4746                                 grep minimum | sed -e 's/^.*filesystem: //g')
4747         local ost_min_blks=$(run_resize2fs ost1 $ost_dev "" "-P" 2>&1 |
4748                                 grep minimum | sed -e 's/^.*filesystem: //g')
4749
4750         # shrink the MDT and OST filesystems to a smaller size
4751         local shrunk=false
4752         local new_blks
4753         local base_blks
4754         if [[ $mds_max_blks -gt $mds_min_blks &&
4755               $mds_max_blks -gt $mds_orig_blks ]]; then
4756                 [[ $mds_orig_blks -gt $mds_min_blks ]] &&
4757                         base_blks=$mds_orig_blks || base_blks=$mds_min_blks
4758                 new_blks=$(( (mds_max_blks - base_blks) / 2 + base_blks ))
4759                 run_resize2fs $SINGLEMDS $mds_dev $new_blks ||
4760                         error "shrink $SINGLEMDS to $new_blks failed"
4761                 shrunk=true
4762         fi
4763
4764         if [[ $ost_max_blks -gt $ost_min_blks &&
4765               $ost_max_blks -gt $ost_orig_blks ]]; then
4766                 [[ $ost_orig_blks -gt $ost_min_blks ]] &&
4767                         base_blks=$ost_orig_blks || base_blks=$ost_min_blks
4768                 new_blks=$(( (ost_max_blks - base_blks) / 2 + base_blks ))
4769                 run_resize2fs ost1 $ost_dev $new_blks ||
4770                         error "shrink ost1 to $new_blks failed"
4771                 shrunk=true
4772         fi
4773
4774         # check whether the MDT or OST filesystem was shrunk or not
4775         if ! $shrunk; then
4776                 combined_mgs_mds || stop_mgs || error "(9) stop mgs failed"
4777                 reformat || error "(10) reformat Lustre filesystem failed"
4778                 return 0
4779         fi
4780
4781         # run e2fsck on the MDT and OST devices again
4782         run_e2fsck $mds_host $mds_dev "-y"
4783         run_e2fsck $ost_host $ost_dev "-y"
4784
4785         # mount the Lustre filesystem again
4786         setup
4787
4788         # check the files
4789         log "check files after shrinking the MDT and OST filesystems"
4790         for i in $(seq $((num_files + 10))); do
4791                 file=$MOUNT/$tdir/$tfile-$i
4792                 $CHECKSTAT -t file -s 1048576 $file ||
4793                         error "(11) checkstat $file failed"
4794         done
4795
4796         # unmount and reformat the Lustre filesystem
4797         cleanup || error "(12) cleanup Lustre filesystem failed"
4798         combined_mgs_mds || stop_mgs || error "(13) stop mgs failed"
4799         reformat || error "(14) reformat Lustre filesystem failed"
4800 }
4801 run_test 78 "run resize2fs on MDT and OST filesystems"
4802
4803 test_79() { # LU-4227
4804         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.59) ]] ||
4805                 { skip "Need MDS version at least 2.5.59"; return 0; }
4806
4807         local mdsdev1=$(mdsdevname 1)
4808         local mdsvdev1=$(mdsvdevname 1)
4809         local mdsdev2=$(mdsdevname 2)
4810         local mdsvdev2=$(mdsvdevname 2)
4811         local ostdev1=$(ostdevname 1)
4812         local ostvdev1=$(ostvdevname 1)
4813         local opts_mds1="$(mkfs_opts mds1 $mdsdev1) --reformat"
4814         local opts_mds2="$(mkfs_opts mds2 $mdsdev2) --reformat"
4815         local opts_ost1="$(mkfs_opts ost1 $ostdev1) --reformat"
4816         local mgsnode_opt
4817
4818         # remove --mgs/--mgsnode from mkfs.lustre options
4819         opts_mds1=$(echo $opts_mds1 | sed -e "s/--mgs//")
4820
4821         mgsnode_opt=$(echo $opts_mds2 |
4822                 awk '{ for ( i = 1; i < NF; i++ )
4823                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
4824         [ -n $mgsnode_opt ] &&
4825                 opts_mds2=$(echo $opts_mds2 | sed -e "s/$mgsnode_opt//")
4826
4827         mgsnode_opt=$(echo $opts_ost1 |
4828                 awk '{ for ( i = 1; i < NF; i++ )
4829                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
4830         [ -n $mgsnode_opt ] &&
4831                 opts_ost1=$(echo $opts_ost1 | sed -e "s/$mgsnode_opt//")
4832
4833         # -MGS, format a mdt without --mgs option
4834         add mds1 $opts_mds1 $mdsdev1 $mdsvdev1 &&
4835                 error "Must specify --mgs when formatting mdt combined with mgs"
4836
4837         # +MGS, format a mdt/ost without --mgsnode option
4838         add mds1 $(mkfs_opts mds1 $mdsdev1) --reformat $mdsdev1 $mdsvdev1 \
4839                 > /dev/null || error "start mds1 failed"
4840         add mds2 $opts_mds2 $mdsdev2 $mdsvdev2 &&
4841                 error "Must specify --mgsnode when formatting a mdt"
4842         add ost1 $opts_ost1 $ostdev1 $ostvdev2 &&
4843                 error "Must specify --mgsnode when formatting an ost"
4844
4845         reformat
4846 }
4847 run_test 79 "format MDT/OST without mgs option (should return errors)"
4848
4849 test_80() {
4850         start_mds || error "Failed to start MDT"
4851         start_ost || error "Failed to start OST1"
4852         uuid=$(do_facet ost1 $LCTL get_param -n mgc.*.uuid)
4853 #define OBD_FAIL_MGS_PAUSE_TARGET_CON       0x906
4854         do_facet ost1 "$LCTL set_param fail_val=10 fail_loc=0x906"
4855         do_facet mgs "$LCTL set_param fail_val=10 fail_loc=0x906"
4856         do_facet mgs "$LCTL set_param -n mgs/MGS/evict_client $uuid"
4857         sleep 30
4858         start_ost2 || error "Failed to start OST2"
4859
4860         do_facet ost1 "$LCTL set_param fail_loc=0"
4861         stopall
4862 }
4863 run_test 80 "mgc import reconnect race"
4864
4865 # Save the original values of $OSTCOUNT and $OSTINDEX$i.
4866 save_ostindex() {
4867         local new_ostcount=$1
4868         saved_ostcount=$OSTCOUNT
4869         OSTCOUNT=$new_ostcount
4870
4871         local i
4872         local index
4873         for i in $(seq $OSTCOUNT); do
4874                 index=OSTINDEX$i
4875                 eval saved_ostindex$i=${!index}
4876                 eval OSTINDEX$i=""
4877         done
4878 }
4879
4880 # Restore the original values of $OSTCOUNT and $OSTINDEX$i.
4881 restore_ostindex() {
4882         trap 0
4883
4884         local i
4885         local index
4886         for i in $(seq $OSTCOUNT); do
4887                 index=saved_ostindex$i
4888                 eval OSTINDEX$i=${!index}
4889         done
4890         OSTCOUNT=$saved_ostcount
4891
4892         formatall
4893 }
4894
4895 # The main purpose of this test is to ensure the OST_INDEX_LIST functions as
4896 # expected. This test uses OST_INDEX_LIST to format OSTs with a randomly
4897 # assigned index and ensures we can mount such a formatted file system
4898 test_81() { # LU-4665
4899         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
4900                 { skip "Need MDS version at least 2.6.54" && return; }
4901         [[ $OSTCOUNT -ge 3 ]] || { skip_env "Need at least 3 OSTs" && return; }
4902
4903         stopall
4904
4905         # Each time RANDOM is referenced, a random integer between 0 and 32767
4906         # is generated.
4907         local i
4908         local saved_ostindex1=$OSTINDEX1
4909         for i in 65535 $((RANDOM + 65536)); do
4910                 echo -e "\nFormat ost1 with --index=$i, should fail"
4911                 OSTINDEX1=$i
4912                 if add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat \
4913                    $(ostdevname 1) $(ostvdevname 1); then
4914                         OSTINDEX1=$saved_ostindex1
4915                         error "format ost1 with --index=$i should fail"
4916                 fi
4917         done
4918         OSTINDEX1=$saved_ostindex1
4919
4920         save_ostindex 3
4921
4922         # Format OSTs with random sparse indices.
4923         trap "restore_ostindex" EXIT
4924         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices"
4925         OST_INDEX_LIST=[0,$((RANDOM * 2 % 65533 + 1)),65534] formatall
4926
4927         # Setup and check Lustre filesystem.
4928         start_mgsmds || error "start_mgsmds failed"
4929         for i in $(seq $OSTCOUNT); do
4930                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
4931                         error "start ost$i failed"
4932         done
4933
4934         mount_client $MOUNT || error "mount client $MOUNT failed"
4935         check_mount || error "check client $MOUNT failed"
4936
4937         # Check max_easize.
4938         local max_easize=$($LCTL get_param -n llite.*.max_easize)
4939         [[ $max_easize -eq 128 ]] ||
4940                 error "max_easize is $max_easize, should be 128 bytes"
4941
4942         restore_ostindex
4943 }
4944 run_test 81 "sparse OST indexing"
4945
4946 # Wait OSTs to be active on both client and MDT side.
4947 wait_osts_up() {
4948         local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
4949                 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
4950         wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
4951                 error "wait_update OSTs up on client failed"
4952
4953         cmd="$LCTL get_param -n lod.$FSNAME-MDT*-*.target_obd | sort -u |
4954              awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
4955         wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
4956                 error "wait_update OSTs up on MDT failed"
4957 }
4958
4959 # Here we exercise the stripe placement functionality on a file system that
4960 # has formatted the OST with a random index. With the file system the following
4961 # functionality is tested:
4962 #
4963 # 1. Creating a new file with a specific stripe layout.
4964 #
4965 # 2. Modifiy a existing empty file with a specific stripe layout.
4966 #
4967 # 3. Ensure we fail to set the stripe layout of a file that already has one.
4968 #
4969 # 4. If ost-index is defined we need to ensure it is the first entry in the
4970 #    ost index list returned by lfs getstripe.
4971 #
4972 # 5. Lastly ensure this functionality fails with directories.
4973 test_82a() { # LU-4665
4974         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
4975                 { skip "Need MDS version at least 2.6.54" && return; }
4976         [[ $OSTCOUNT -ge 3 ]] || { skip_env "Need at least 3 OSTs" && return; }
4977
4978         stopall
4979
4980         save_ostindex 3
4981
4982         # Format OSTs with random sparse indices.
4983         local i
4984         local index
4985         local ost_indices
4986         for i in $(seq $OSTCOUNT); do
4987                 index=$((RANDOM * 2))
4988                 ost_indices+=" $index"
4989         done
4990         ost_indices=$(comma_list $ost_indices)
4991
4992         trap "restore_ostindex" EXIT
4993         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
4994         OST_INDEX_LIST=[$ost_indices] formatall
4995
4996         # Setup Lustre filesystem.
4997         start_mgsmds || error "start_mgsmds failed"
4998         for i in $(seq $OSTCOUNT); do
4999                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5000                         error "start ost$i failed"
5001         done
5002
5003         mount_client $MOUNT || error "mount client $MOUNT failed"
5004         wait_osts_up
5005
5006         $LFS df $MOUNT || error "$LFS df $MOUNT failed"
5007         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5008
5009         # 1. If the file does not exist, new file will be created
5010         #    with specified OSTs.
5011         local file=$DIR/$tdir/$tfile-1
5012         local cmd="$SETSTRIPE -o $ost_indices $file"
5013         echo -e "\n$cmd"
5014         eval $cmd || error "$cmd failed"
5015         check_stripe_count $file $OSTCOUNT
5016         check_obdidx $file $ost_indices
5017         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5018                 error "write $file failed"
5019
5020         # 2. If the file already exists and is an empty file, the file
5021         #    will be attached with specified layout.
5022         file=$DIR/$tdir/$tfile-2
5023         mcreate $file || error "mcreate $file failed"
5024         cmd="$SETSTRIPE -o $ost_indices $file"
5025         echo -e "\n$cmd"
5026         eval $cmd || error "$cmd failed"
5027         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5028                 error "write $file failed"
5029         check_stripe_count $file $OSTCOUNT
5030         check_obdidx $file $ost_indices
5031
5032         # 3. If the file already has a valid layout attached, the command
5033         #    should fail with EBUSY.
5034         echo -e "\n$cmd"
5035         eval $cmd && error "stripe is already set on $file, $cmd should fail"
5036
5037         # 4. If [--stripe-index|-i <start_ost_idx>] is used, the index must
5038         #    be in the OST indices list.
5039         local start_ost_idx=${ost_indices##*,}
5040         file=$DIR/$tdir/$tfile-3
5041         cmd="$SETSTRIPE -o $ost_indices -i $start_ost_idx $file"
5042         echo -e "\n$cmd"
5043         eval $cmd || error "$cmd failed"
5044         check_stripe_count $file $OSTCOUNT
5045         check_obdidx $file $ost_indices
5046         check_start_ost_idx $file $start_ost_idx
5047
5048         file=$DIR/$tdir/$tfile-4
5049         cmd="$SETSTRIPE"
5050         cmd+=" -o $(exclude_items_from_list $ost_indices $start_ost_idx)"
5051         cmd+=" -i $start_ost_idx $file"
5052         echo -e "\n$cmd"
5053         eval $cmd && error "index $start_ost_idx should be in $ost_indices"
5054
5055         # 5. Specifying OST indices for directory should fail with ENOSUPP.
5056         local dir=$DIR/$tdir/$tdir
5057         mkdir $dir || error "mkdir $dir failed"
5058         cmd="$SETSTRIPE -o $ost_indices $dir"
5059         echo -e "\n$cmd"
5060         eval $cmd && error "$cmd should fail, specifying OST indices" \
5061                            "for directory is not supported"
5062
5063         restore_ostindex
5064 }
5065 run_test 82a "specify OSTs for file (succeed) or directory (fail)"
5066
5067 cleanup_82b() {
5068         trap 0
5069
5070         # Remove OSTs from a pool and destroy the pool.
5071         destroy_pool $ost_pool || true
5072
5073         restore_ostindex
5074 }
5075
5076 # Test 82b is run to ensure that if the user supplies a pool with a specific
5077 # stripe layout that it behaves proprerly. It should fail in the case that
5078 # the supplied OST index list points to OSTs not contained in the user
5079 # supplied pool.
5080 test_82b() { # LU-4665
5081         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
5082                 { skip "Need MDS version at least 2.6.54" && return; }
5083         [[ $OSTCOUNT -ge 4 ]] || { skip_env "Need at least 4 OSTs" && return; }
5084
5085         stopall
5086
5087         save_ostindex 4
5088
5089         # Format OSTs with random sparse indices.
5090         local i
5091         local index
5092         local ost_indices
5093         for i in $(seq $OSTCOUNT); do
5094                 index=$((RANDOM * 2))
5095                 ost_indices+=" $index"
5096         done
5097         ost_indices=$(comma_list $ost_indices)
5098
5099         trap "restore_ostindex" EXIT
5100         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
5101         OST_INDEX_LIST=[$ost_indices] formatall
5102
5103         # Setup Lustre filesystem.
5104         start_mgsmds || error "start_mgsmds failed"
5105         for i in $(seq $OSTCOUNT); do
5106                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5107                         error "start ost$i failed"
5108         done
5109
5110         mount_client $MOUNT || error "mount client $MOUNT failed"
5111         wait_osts_up
5112         $LFS df $MOUNT || error "$LFS df $MOUNT failed"
5113         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5114
5115         # Create a new pool and add OSTs into it.
5116         local ost_pool=$FSNAME.$TESTNAME
5117         create_pool $ost_pool || error "create OST pool $ost_pool failed"
5118
5119         trap - EXIT
5120         trap "cleanup_82b" EXIT
5121
5122         local ost_idx_in_list=${ost_indices##*,}
5123         local ost_idx_in_pool=$(exclude_items_from_list $ost_indices \
5124                                 $ost_idx_in_list)
5125
5126         local ost_targets="$FSNAME-OST["
5127         for i in ${ost_idx_in_pool//,/ }; do
5128                 ost_targets=$ost_targets$(printf "%04x," $i)
5129         done
5130         ost_targets="${ost_targets%,}]"
5131
5132         local ost_targets_uuid=$(for i in ${ost_idx_in_pool//,/ }; \
5133                                  do printf "$FSNAME-OST%04x_UUID\n" $i; done |
5134                                  sort -u | tr '\n' ' ')
5135
5136         local cmd="$LCTL pool_add $ost_pool $ost_targets"
5137         do_facet mgs $cmd || error "$cmd failed"
5138         wait_update $HOSTNAME "$LCTL get_param -n lov.$FSNAME-*.pools.$TESTNAME|
5139                                sort -u | tr '\n' ' ' " "$ost_targets_uuid" ||
5140                                         error "wait_update $ost_pool failed"
5141         pool_list $ost_pool || error "list OST pool $ost_pool failed"
5142
5143         # If [--pool|-p <pool_name>] is set with [--ost-list|-o <ost_indices>],
5144         # then the OSTs must be the members of the pool.
5145         local file=$DIR/$tdir/$tfile
5146         cmd="$SETSTRIPE -p $ost_pool -o $ost_idx_in_list $file"
5147         echo -e "\n$cmd"
5148         eval $cmd && error "OST with index $ost_idx_in_list should be" \
5149                            "in OST pool $ost_pool"
5150
5151         # Only select OST $ost_idx_in_list from $ost_pool for file.
5152         ost_idx_in_list=${ost_idx_in_pool#*,}
5153         cmd="$SETSTRIPE -p $ost_pool -o $ost_idx_in_list $file"
5154         echo -e "\n$cmd"
5155         eval $cmd || error "$cmd failed"
5156         cmd="$GETSTRIPE $file"
5157         echo -e "\n$cmd"
5158         eval $cmd || error "$cmd failed"
5159         check_stripe_count $file 2
5160         check_obdidx $file $ost_idx_in_list
5161         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5162                 error "write $file failed"
5163
5164         cleanup_82b
5165 }
5166 run_test 82b "specify OSTs for file with --pool and --ost-list options"
5167
5168 test_83() {
5169         local dev
5170         local ostmnt
5171         local fstype
5172         local mnt_opts
5173
5174         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
5175                 skip "Only applicable to ldiskfs-based MDTs"
5176                 return
5177         fi
5178
5179         dev=$(ostdevname 1)
5180         ostmnt=$(facet_mntpt ost1)
5181         fstype=$(facet_fstype ost1)
5182
5183         # Mount the OST as an ldiskfs filesystem.
5184         log "mount the OST $dev as a $fstype filesystem"
5185         add ost1 $(mkfs_opts ost1 $dev) $FSTYPE_OPT \
5186                 --reformat $dev $dev > /dev/null ||
5187                 error "format ost1 error"
5188
5189         if ! test -b $dev; then
5190                 mnt_opts=$(csa_add "$OST_MOUNT_OPTS" -o loop)
5191         fi
5192         echo "mnt_opts $mnt_opts"
5193         do_facet ost1 mount -t $fstype $dev \
5194                 $ostmnt $mnt_opts
5195         # Run llverfs on the mounted ldiskfs filesystem.
5196         # It is needed to get ENOSPACE.
5197         log "run llverfs in partial mode on the OST $fstype $ostmnt"
5198         do_rpc_nodes $(facet_host ost1) run_llverfs $ostmnt -vpl \
5199                 "no" || error "run_llverfs error on $fstype"
5200
5201         # Unmount the OST.
5202         log "unmount the OST $dev"
5203         stop ost1
5204
5205         # Delete file IO_scrub. Later osd_scrub_setup will try to
5206         # create "IO_scrub" but will get ENOSPACE.
5207         writeconf_all
5208         echo "start ost1 service on `facet_active_host ost1`"
5209         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
5210
5211         local err
5212         err=$(do_facet ost1 dmesg | grep "VFS: Busy inodes after unmount of")
5213         echo "string err $err"
5214         [ -z "$err" ] || error $err
5215         reformat
5216 }
5217 run_test 83 "ENOSPACE on OST doesn't cause message VFS: \
5218 Busy inodes after unmount ..."
5219
5220 recovery_time_min() {
5221         local CONNECTION_SWITCH_MIN=5
5222         local CONNECTION_SWITCH_INC=5
5223         local CONNECTION_SWITCH_MAX
5224         local RECONNECT_DELAY_MAX
5225         local INITIAL_CONNECT_TIMEOUT
5226         local max
5227         local TO_20
5228
5229         #CONNECTION_SWITCH_MAX=min(50, max($CONNECTION_SWITCH_MIN,$TIMEOUT)
5230         (($CONNECTION_SWITCH_MIN>$TIMEOUT)) && \
5231                 max=$CONNECTION_SWITCH_MIN || max=$TIMEOUT
5232         (($max<50)) && CONNECTION_SWITCH_MAX=$max || CONNECTION_SWITCH_MAX=50
5233
5234         #INITIAL_CONNECT_TIMEOUT = max(CONNECTION_SWITCH_MIN, \
5235         #obd_timeout/20)
5236         TO_20=$(($TIMEOUT/20))
5237         (($CONNECTION_SWITCH_MIN>$TO_20)) && \
5238                 INITIAL_CONNECT_TIMEOUT=$CONNECTION_SWITCH_MIN || \
5239                 INITIAL_CONNECT_TIMEOUT=$TO_20
5240
5241         RECONNECT_DELAY_MAX=$(($CONNECTION_SWITCH_MAX+$CONNECTION_SWITCH_INC+ \
5242                                 $INITIAL_CONNECT_TIMEOUT))
5243         echo $((2*$RECONNECT_DELAY_MAX))
5244 }
5245
5246 test_84() {
5247         local facet=$SINGLEMDS
5248         local num=$(echo $facet | tr -d "mds")
5249         local dev=$(mdsdevname $num)
5250         local time_min=$(recovery_time_min)
5251         local recovery_duration
5252         local completed_clients
5253
5254         echo "start mds service on `facet_active_host $facet`"
5255         start $facet ${dev} $MDS_MOUNT_OPTS \
5256                 "-o recovery_time_hard=$time_min,recovery_time_soft=$time_min"\
5257                 $@ || return 94
5258
5259         start_ost
5260         start_ost2
5261
5262         echo "recovery_time_hard $time_min, recovery_time_soft $time_min, \
5263                 timeout $TIMEOUT"
5264
5265         mount_client $MOUNT1 || error "mount failed"
5266         mount_client $MOUNT2 || error "mount failed"
5267
5268         replay_barrier $SINGLEMDS
5269         createmany -o $DIR1/$tfile-%d 1000
5270
5271         # We need to catch the end of recovery window to extend it.
5272         # Skip 5 requests and add delay to request handling.
5273         #define OBD_FAIL_TGT_REPLAY_DELAY  0x709 | FAIL_SKIP
5274         do_facet $SINGLEMDS "lctl set_param fail_loc=0x20000709"
5275         do_facet $SINGLEMDS "lctl set_param fail_val=5"
5276
5277         facet_failover $SINGLEMDS || error "failover: $?"
5278         client_up
5279
5280         echo "recovery status"
5281         do_facet $SINGLEMDS "$LCTL get_param -n \
5282                                 mdt.$FSNAME-MDT0000.recovery_status"
5283
5284         recovery_duration=$(do_facet $SINGLEMDS "$LCTL get_param -n \
5285                                 mdt.$FSNAME-MDT0000.recovery_status" | \
5286                                 grep recovery_duration |awk '{print $2}')
5287         (($recovery_duration>$time_min)) && \
5288                 error "recovery_duration > recovery_time_hard"
5289         completed_clients=$(do_facet $SINGLEMDS "$LCTL get_param -n \
5290                                 mdt.$FSNAME-MDT0000.recovery_status" | \
5291                                 grep completed_clients |awk '{print $2}')
5292         [ "$completed_clients" = "1/2" ] || \
5293                 error "completed_clients != 1/2: "$completed_clients
5294
5295         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
5296         umount_client $MOUNT1
5297         umount_client $MOUNT2
5298
5299         stop_ost
5300         stop_ost2
5301         stop_mds
5302 }
5303 run_test 84 "check recovery_hard_time"
5304
5305 if ! combined_mgs_mds ; then
5306         stop mgs
5307 fi
5308
5309 cleanup_gss
5310
5311 # restore the values of MDSSIZE and OSTSIZE
5312 MDSSIZE=$STORED_MDSSIZE
5313 OSTSIZE=$STORED_OSTSIZE
5314 reformat
5315
5316 complete $SECONDS
5317 exit_status