Whamcloud - gitweb
4ed9e779ccfa95e8d12feabf2d7216a501b6a65e
[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:
8 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT"
9 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
10
11 # bug number for skipped test:
12 # a tool to create lustre filesystem images
13 ALWAYS_EXCEPT="32newtarball $ALWAYS_EXCEPT"
14 if $SHARED_KEY; then
15 # bug number for skipped tests:         LU-9795 (all below)
16         ALWAYS_EXCEPT="$ALWAYS_EXCEPT   0       31      32a     32d     35a"
17         ALWAYS_EXCEPT="$ALWAYS_EXCEPT   53a     53b     54b     76a     76b"
18         ALWAYS_EXCEPT="$ALWAYS_EXCEPT   76c     76d     78      103"
19 fi
20
21 SRCDIR=$(dirname $0)
22 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
23
24 PTLDEBUG=${PTLDEBUG:--1}
25 SAVE_PWD=$PWD
26 LUSTRE=${LUSTRE:-$(dirname $0)/..}
27 RLUSTRE=${RLUSTRE:-$LUSTRE}
28 export MULTIOP=${MULTIOP:-multiop}
29
30 . $LUSTRE/tests/test-framework.sh
31 init_test_env $@
32 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
33
34 # use small MDS + OST size to speed formatting time
35 # do not use too small MDSSIZE/OSTSIZE, which affect the default journal size
36 # STORED_MDSSIZE is used in test_18
37 STORED_MDSSIZE=$MDSSIZE
38 STORED_OSTSIZE=$OSTSIZE
39 MDSSIZE=200000
40 [ $(facet_fstype $SINGLEMDS) = "zfs" ] && MDSSIZE=400000
41 OSTSIZE=200000
42 [ $(facet_fstype ost1) = "zfs" ] && OSTSIZE=400000
43
44 fs2mds_HOST=$mds_HOST
45 fs2ost_HOST=$ost_HOST
46 fs3ost_HOST=$ost_HOST
47
48 MDSDEV1_2=$fs2mds_DEV
49 OSTDEV1_2=$fs2ost_DEV
50 OSTDEV2_2=$fs3ost_DEV
51
52 if ! combined_mgs_mds; then
53         # bug number for skipped test: LU-9860 LU-9860 LU-9860
54         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  43b     53b     54b"
55         # bug number for skipped test: LU-9875 LU-9879 LU-9879 LU-9879 LU-9879
56         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  70e     80      84      87      100"
57         # bug number for skipped test: LU-8110 LU-9879 LU-9879 LU-9879
58         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  102     104     105     107"
59 fi
60
61 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
62 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
63         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
64 fi
65
66 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
67 # bug number for skipped test:
68         ALWAYS_EXCEPT="$ALWAYS_EXCEPT"
69 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
70
71 init_logging
72
73 #
74 require_dsh_mds || exit 0
75 require_dsh_ost || exit 0
76
77 #                                  8  22   (min)"
78 [ "$SLOW" = "no" ] && EXCEPT_SLOW="45 69"
79
80 assert_DIR
81
82 gen_config() {
83         # The MGS must be started before the OSTs for a new fs, so start
84         # and stop to generate the startup logs.
85         start_mds
86         start_ost
87         wait_osc_import_state mds ost FULL
88         stop_ost
89         stop_mds
90 }
91
92 reformat_and_config() {
93         reformat
94         if ! combined_mgs_mds ; then
95                 start_mgs
96         fi
97         gen_config
98 }
99
100 writeconf_or_reformat() {
101         # There are at most 2 OSTs for write_conf test
102         # who knows if/where $TUNEFS is installed?
103         # Better reformat if it fails...
104         writeconf_all $MDSCOUNT 2 ||
105                 { echo "tunefs failed, reformatting instead" &&
106                   reformat_and_config && return 0; }
107         return 0
108 }
109
110 reformat() {
111         formatall
112 }
113
114 start_mgs () {
115         echo "start mgs service on $(facet_active_host mgs)"
116         start mgs $(mgsdevname) $MGS_MOUNT_OPTS $@
117 }
118
119 start_mdt() {
120         local num=$1
121         local facet=mds$num
122         local dev=$(mdsdevname $num)
123         shift 1
124
125         echo "start mds service on `facet_active_host $facet`"
126         start $facet ${dev} $MDS_MOUNT_OPTS $@ || return 94
127 }
128
129 stop_mdt() {
130         local num=$1
131         local facet=mds$num
132         local dev=$(mdsdevname $num)
133         shift 1
134
135         echo "stop mds service on `facet_active_host $facet`"
136         # These tests all use non-failover stop
137         stop $facet -f || return 97
138 }
139
140 start_mds() {
141         local num
142
143         for num in $(seq $MDSCOUNT); do
144                 start_mdt $num $@ || return 94
145         done
146 }
147
148 start_mgsmds() {
149         if ! combined_mgs_mds ; then
150                 start_mgs
151         fi
152         start_mds $@
153 }
154
155 stop_mds() {
156         local num
157         for num in $(seq $MDSCOUNT); do
158                 stop_mdt $num || return 97
159         done
160 }
161
162 stop_mgs() {
163        echo "stop mgs service on `facet_active_host mgs`"
164        # These tests all use non-failover stop
165        stop mgs -f  || return 97
166 }
167
168 start_ost() {
169         echo "start ost1 service on `facet_active_host ost1`"
170         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS $@ || return 95
171 }
172
173 stop_ost() {
174         echo "stop ost1 service on `facet_active_host ost1`"
175         # These tests all use non-failover stop
176         stop ost1 -f || return 98
177 }
178
179 start_ost2() {
180         echo "start ost2 service on `facet_active_host ost2`"
181         start ost2 $(ostdevname 2) $OST_MOUNT_OPTS $@ || return 92
182 }
183
184 stop_ost2() {
185         echo "stop ost2 service on `facet_active_host ost2`"
186         # These tests all use non-failover stop
187         stop ost2 -f || return 93
188 }
189
190 mount_client() {
191         local MOUNTPATH=$1
192         echo "mount $FSNAME on ${MOUNTPATH}....."
193         zconf_mount $(hostname) $MOUNTPATH || return 96
194 }
195
196 remount_client() {
197         local mountopt="remount,$1"
198         local MOUNTPATH=$2
199         echo "remount '$1' lustre on ${MOUNTPATH}....."
200         zconf_mount $(hostname) $MOUNTPATH "$mountopt" || return 96
201 }
202
203 umount_client() {
204         local mountpath=$1
205         shift
206         echo "umount lustre on $mountpath....."
207         zconf_umount $HOSTNAME $mountpath $@ || return 97
208 }
209
210 manual_umount_client(){
211         local rc
212         local FORCE=$1
213         echo "manual umount lustre on ${MOUNT}...."
214         do_facet client "umount ${FORCE} $MOUNT"
215         rc=$?
216         return $rc
217 }
218
219 setup() {
220         start_mds || error "MDT start failed"
221         start_ost || error "Unable to start OST1"
222         mount_client $MOUNT || error "client start failed"
223         client_up || error "client_up failed"
224 }
225
226 setup_noconfig() {
227         start_mgsmds
228         start_ost
229         mount_client $MOUNT
230 }
231
232 unload_modules_conf () {
233         if combined_mgs_mds || ! local_mode; then
234                 unload_modules || return 1
235         fi
236 }
237
238 cleanup_nocli() {
239         stop_ost || return 202
240         stop_mds || return 201
241         unload_modules_conf || return 203
242 }
243
244 cleanup() {
245         local force=""
246         [ "x$1" != "x" ] && force='-f'
247         umount_client $MOUNT $force|| return 200
248         cleanup_nocli || return $?
249 }
250
251 cleanup_fs2() {
252         trap 0
253         echo "umount $MOUNT2 ..."
254         umount $MOUNT2 || true
255         echo "stopping fs2mds ..."
256         stop fs2mds -f || true
257         echo "stopping fs2ost ..."
258         stop fs2ost -f || true
259 }
260
261 check_mount() {
262         do_facet client "cp /etc/passwd $DIR/a" || return 71
263         do_facet client "rm $DIR/a" || return 72
264         # make sure lustre is actually mounted (touch will block,
265         # but grep won't, so do it after)
266         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
267         echo "setup single mount lustre success"
268 }
269
270 check_mount2() {
271         do_facet client "touch $DIR/a" || return 71
272         do_facet client "rm $DIR/a" || return 72
273         do_facet client "touch $DIR2/a" || return 73
274         do_facet client "rm $DIR2/a" || return 74
275         echo "setup double mount lustre success"
276 }
277
278 build_test_filter
279
280 if [ "$ONLY" == "setup" ]; then
281         setup
282         exit
283 fi
284
285 if [ "$ONLY" == "cleanup" ]; then
286         cleanup
287         exit
288 fi
289
290 init_gss
291
292 #create single point mountpoint
293
294 reformat_and_config
295
296 test_0() {
297         setup
298         check_mount || error "check_mount failed"
299         cleanup || error "cleanup failed with $?"
300 }
301 run_test 0 "single mount setup"
302
303 test_1() {
304         start_mds || error "MDS start failed"
305         start_ost || error "unable to start OST"
306         echo "start ost second time..."
307         start_ost && error "2nd OST start should fail"
308         mount_client $MOUNT || error "client start failed"
309         check_mount || error "check_mount failed"
310         cleanup || error "cleanup failed with $?"
311 }
312 run_test 1 "start up ost twice (should return errors)"
313
314 test_2() {
315         start_mds || error "MDT start failed"
316         echo "start mds second time.."
317         start_mds && error "2nd MDT start should fail"
318         start_ost || error "OST start failed"
319         mount_client $MOUNT || error "mount_client failed to start client"
320         check_mount || error "check_mount failed"
321         cleanup || error "cleanup failed with $?"
322 }
323 run_test 2 "start up mds twice (should return err)"
324
325 test_3() {
326         setup
327         #mount.lustre returns an error if already in mtab
328         mount_client $MOUNT && error "2nd client mount should fail"
329         check_mount || error "check_mount failed"
330         cleanup || error "cleanup failed with $?"
331 }
332 run_test 3 "mount client twice (should return err)"
333
334 test_4() {
335         setup
336         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
337         stop_ost || error "Unable to stop OST1"
338         umount_client $MOUNT -f || error “unmount $MOUNT failed”
339         cleanup_nocli
340         eno=$?
341         # ok for ost to fail shutdown
342         if [ 202 -ne $eno ] && [ 0 -ne $eno ]; then
343                 error "cleanup failed with $?"
344         fi
345 }
346 run_test 4 "force cleanup ost, then cleanup"
347
348 test_5a() {     # was test_5
349         setup
350         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
351         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
352
353         stop_mds || error "Unable to stop MDS"
354
355         # cleanup may return an error from the failed
356         # disconnects; for now I'll consider this successful
357         # if all the modules have unloaded.
358         $UMOUNT -f $MOUNT &
359         UMOUNT_PID=$!
360         sleep 6
361         echo "killing umount"
362         kill -TERM $UMOUNT_PID
363         echo "waiting for umount to finish"
364         wait $UMOUNT_PID
365         if grep " $MOUNT " /proc/mounts; then
366                 echo "test 5: /proc/mounts after failed umount"
367                 umount -f $MOUNT &
368                 UMOUNT_PID=$!
369                 sleep 2
370                 echo "killing umount"
371                 kill -TERM $UMOUNT_PID
372                 echo "waiting for umount to finish"
373                 wait $UMOUNT_PID
374                 grep " $MOUNT " /proc/mounts &&
375                         error "/proc/mounts after second umount"
376         fi
377
378         # manual_mount_client may fail due to umount succeeding above
379         manual_umount_client
380         # stop_mds is a no-op here, and should not fail
381         cleanup_nocli || error "cleanup_nocli failed with $?"
382         # df may have lingering entry
383         manual_umount_client
384         # mtab may have lingering entry
385         local WAIT=0
386         local MAX_WAIT=20
387         local sleep=1
388         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
389                 sleep $sleep
390                 grep -q $MOUNT" " /etc/mtab || break
391                 echo "Waiting /etc/mtab updated ... "
392                 WAIT=$(( WAIT + sleep))
393         done
394         [ "$WAIT" -eq "$MAX_WAIT" ] &&
395                 error "/etc/mtab is not updated in $WAIT secs"
396         echo "/etc/mtab updated in $WAIT secs"
397 }
398 run_test 5a "force cleanup mds, then cleanup"
399
400 cleanup_5b () {
401         trap 0
402         start_mgs
403 }
404
405 test_5b() {
406         grep " $MOUNT " /etc/mtab &&
407                 error false "unexpected entry in mtab before mount" && return 10
408
409         start_ost || error "OST start failed"
410         if ! combined_mgs_mds ; then
411                 trap cleanup_5b EXIT ERR
412                 start_mds || error "MDS start failed"
413                 stop mgs
414         fi
415
416         mount_client $MOUNT && error "mount_client $MOUNT should fail"
417         grep " $MOUNT " /etc/mtab &&
418                 error "$MOUNT entry in mtab after failed mount"
419         umount_client $MOUNT
420         # stop_mds is a no-op here, and should not fail
421         cleanup_nocli || error "cleanup_nocli failed with $?"
422         if ! combined_mgs_mds ; then
423                 cleanup_5b
424         fi
425 }
426 run_test 5b "Try to start a client with no MGS (should return errs)"
427
428 test_5c() {
429         grep " $MOUNT " /etc/mtab &&
430                 error false "unexpected entry in mtab before mount" && return 10
431
432         start_mds || error "MDS start failed"
433         start_ost || error "OST start failed"
434         local oldfs="${FSNAME}"
435         FSNAME="wrong.${FSNAME}"
436         mount_client $MOUNT || :
437         FSNAME=${oldfs}
438         grep " $MOUNT " /etc/mtab &&
439                 error "$MOUNT entry in mtab after failed mount"
440         umount_client $MOUNT
441         cleanup_nocli || error "cleanup_nocli failed with $?"
442 }
443 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
444
445 test_5d() {
446         grep " $MOUNT " /etc/mtab &&
447                 error "unexpected entry in mtab before mount"
448
449         start_ost || error "OST start failed"
450         start_mds || error "MDS start failed"
451         stop_ost -f || error "Unable to stop OST1"
452         mount_client $MOUNT || error "mount_client $MOUNT failed"
453         umount_client $MOUNT -f || error "umount_client $MOUNT failed"
454         cleanup_nocli || error "cleanup_nocli failed with $?"
455         ! grep " $MOUNT " /etc/mtab ||
456                 error "$MOUNT entry in mtab after unmount"
457 }
458 run_test 5d "mount with ost down"
459
460 test_5e() {
461         grep " $MOUNT " /etc/mtab &&
462                 error false "unexpected entry in mtab before mount" && return 10
463
464         start_mds || error "MDS start failed"
465         start_ost || error "OST start failed"
466
467         #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
468         do_facet client "$LCTL set_param fail_loc=0x80000506"
469         mount_client $MOUNT || echo "mount failed (not fatal)"
470         cleanup || error "cleanup failed with $?"
471         grep " $MOUNT " /etc/mtab &&
472                 error "$MOUNT entry in mtab after unmount"
473         pass
474 }
475 run_test 5e "delayed connect, don't crash (bug 10268)"
476
477 test_5f() {
478         if combined_mgs_mds ; then
479                 skip "needs separate mgs and mds"
480                 return 0
481         fi
482
483         grep " $MOUNT " /etc/mtab &&
484                 error false "unexpected entry in mtab before mount" && return 10
485
486         local rc=0
487         start_ost || error "OST start failed"
488         mount_client $MOUNT &
489         local pid=$!
490         echo client_mount pid is $pid
491
492         sleep 5
493
494         if ! ps -f -p $pid >/dev/null; then
495                 wait $pid
496                 rc=$?
497                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
498                 error "mount returns $rc, expected to hang"
499                 rc=11
500                 cleanup || error "cleanup failed with $?"
501                 return $rc
502         fi
503
504         # start mds
505         start_mds || error "start MDS failed"
506
507         # mount should succeed after start mds
508         wait $pid
509         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
510         cleanup || error "final call to cleanup failed with rc $?"
511 }
512 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
513
514 test_5g() {
515         modprobe lustre
516         [ $(lustre_version_code client) -lt $(version_code 2.9.53) ] &&
517                 { skip "automount of debugfs missing before 2.9.53" && return 0; }
518         umount /sys/kernel/debug
519         $LCTL get_param -n devices | egrep -v "error" && \
520                 error "lctl can't access debugfs data"
521         grep " debugfs " /etc/mtab || error "debugfs failed to remount"
522 }
523 run_test 5g "handle missing debugfs"
524
525 test_6() {
526         setup
527         manual_umount_client
528         mount_client $MOUNT || error "mount_client $MOUNT failed"
529         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
530         cleanup || error "cleanup failed with rc $?"
531 }
532 run_test 6 "manual umount, then mount again"
533
534 test_7() {
535         setup
536         manual_umount_client
537         cleanup_nocli || error "cleanup_nocli failed with $?"
538 }
539 run_test 7 "manual umount, then cleanup"
540
541 test_8() {
542         setup
543         mount_client $MOUNT2 || error "mount_client $MOUNT2 failed"
544         check_mount2 || error "check_mount2 failed"
545         umount_client $MOUNT2 || error "umount_client $MOUNT2 failed"
546         cleanup || error "cleanup failed with rc $?"
547 }
548 run_test 8 "double mount setup"
549
550 test_9() {
551         start_ost || error "OST start failed"
552
553         do_facet ost1 $LCTL set_param debug=\'inode trace\' ||
554                 error "do_facet ost1 set_param inode trace failed."
555         do_facet ost1 $LCTL set_param subsystem_debug=\'mds ost\' ||
556                 error "do_facet ost1 set_param debug mds ost failed."
557
558         CHECK_PTLDEBUG="`do_facet ost1 $LCTL get_param -n debug`"
559         if [ "$CHECK_PTLDEBUG" ] && { \
560            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
561            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
562                 echo "lnet.debug success"
563         else
564                 error "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
565         fi
566         CHECK_SUBSYS="`do_facet ost1 $LCTL get_param -n subsystem_debug`"
567         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
568                 echo "lnet.subsystem_debug success"
569         else
570                 error "lnet.subsystem_debug: want 'mds ost' got '$CHECK_SUBSYS'"
571         fi
572         stop_ost || error "Unable to stop OST1"
573 }
574 run_test 9 "test ptldebug and subsystem for mkfs"
575
576 #
577 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
578 # But with new MDS stack we don't care about the mode of local objects
579 # anymore, so this test is removed. See bug 22944 for more details.
580 #
581
582 test_17() {
583         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
584                 skip "ldiskfs only test"
585                 return
586         fi
587
588         setup
589         check_mount || error "check_mount failed"
590         cleanup || error "cleanup failed with rc $?"
591
592         echo "Remove mds config log"
593         if ! combined_mgs_mds ; then
594                 stop mgs
595         fi
596
597         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' \
598                       $(mgsdevname) || return \$?" ||
599                 error "do_facet mgs failed with $?"
600
601         if ! combined_mgs_mds ; then
602                 start_mgs
603         fi
604
605         start_ost || error "OST start failed"
606         start_mds && error "MDS start succeeded, but should fail"
607         reformat_and_config
608 }
609 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
610
611 test_18() {
612         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
613                 skip "ldiskfs only test"
614                 return
615         fi
616
617         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
618
619         local MIN=2000000
620
621         local OK=
622         # check if current MDSSIZE is large enough
623         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE &&
624                 log "use MDSSIZE=$MDSSIZE"
625
626         # check if the global config has a large enough MDSSIZE
627         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] &&
628                 [ $STORED_MDSSIZE -ge $MIN ] &&
629                 OK=1 && myMDSSIZE=$STORED_MDSSIZE &&
630                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
631
632         # check if the block device is large enough
633         is_blkdev $SINGLEMDS $MDSDEV $MIN
634         local large_enough=$?
635         if [ -n "$OK" ]; then
636                 [ $large_enough -ne 0 ] && OK=""
637         else
638                 [ $large_enough -eq 0 ] && OK=1 && myMDSSIZE=$MIN &&
639                         log "use device $MDSDEV with MIN=$MIN"
640         fi
641
642         # check if a loopback device has enough space for fs metadata (5%)
643
644         if [ -z "$OK" ]; then
645                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! \
646                               -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
647                         awk '($1 != "Filesystem") { print $4 }')
648                 ! [ -z "$SPACE" ] && [ $SPACE -gt $((MIN / 20)) ] &&
649                         OK=1 && myMDSSIZE=$MIN &&
650                         log "use file $MDSDEV with MIN=$MIN"
651         fi
652
653         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
654
655         echo "mount mds with large journal..."
656
657         local OLD_MDSSIZE=$MDSSIZE
658         MDSSIZE=$myMDSSIZE
659
660         reformat_and_config
661         echo "mount lustre system..."
662         setup
663         check_mount || error "check_mount failed"
664
665         echo "check journal size..."
666         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
667         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
668                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
669         else
670                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
671         fi
672
673         cleanup || error "cleanup failed with rc $?"
674
675         MDSSIZE=$OLD_MDSSIZE
676         reformat_and_config
677 }
678 run_test 18 "check mkfs creates large journals"
679
680 test_19a() {
681         start_mds || error "MDS start failed"
682         stop_mds || error "Unable to stop MDS"
683 }
684 run_test 19a "start/stop MDS without OSTs"
685
686 test_19b() {
687         start_ost || error "Unable to start OST1"
688         stop_ost -f || error "Unable to stop OST1"
689 }
690 run_test 19b "start/stop OSTs without MDS"
691
692 test_20() {
693         # first format the ost/mdt
694         start_mds || error "MDS start failed"
695         start_ost || error "Unable to start OST1"
696         mount_client $MOUNT || error "mount_client $MOUNT failed"
697         check_mount || error "check_mount failed"
698         rm -f $DIR/$tfile || error "remove $DIR/$tfile failed."
699         remount_client ro $MOUNT || error "remount_client with ro failed"
700         touch $DIR/$tfile && error "$DIR/$tfile created incorrectly"
701         [ -e $DIR/$tfile ] && error "$DIR/$tfile exists incorrectly"
702         remount_client rw $MOUNT || error "remount_client with rw failed"
703         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
704         MCNT=$(grep -c $MOUNT' ' /etc/mtab)
705         [ "$MCNT" -ne 1 ] && error "$MOUNT in /etc/mtab $MCNT times"
706         umount_client $MOUNT
707         stop_mds || error "Unable to stop MDS"
708         stop_ost || error "Unable to stop OST1"
709 }
710 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
711
712 test_21a() {
713         start_mds || error "MDS start failed"
714         start_ost || error "unable to start OST1"
715         wait_osc_import_state mds ost FULL
716         stop_ost || error "unable to stop OST1"
717         stop_mds || error "unable to stop MDS"
718 }
719 run_test 21a "start mds before ost, stop ost first"
720
721 test_21b() {
722         start_ost || error "unable to start OST1"
723         start_mds || error "MDS start failed"
724         wait_osc_import_state mds ost FULL
725         stop_mds || error "unable to stop MDS"
726         stop_ost || error "unable to stop OST1"
727 }
728 run_test 21b "start ost before mds, stop mds first"
729
730 test_21c() {
731         start_ost || error "Unable to start OST1"
732         start_mds || error "MDS start failed"
733         start_ost2 || error "Unable to start OST2"
734         wait_osc_import_state mds ost2 FULL
735         stop_ost || error "Unable to stop OST1"
736         stop_ost2 || error "Unable to stop OST2"
737         stop_mds || error "Unable to stop MDS"
738         #writeconf to remove all ost2 traces for subsequent tests
739         writeconf_or_reformat
740 }
741 run_test 21c "start mds between two osts, stop mds last"
742
743 test_21d() {
744         if combined_mgs_mds ; then
745                 skip "need separate mgs device" && return 0
746         fi
747         stopall
748
749         reformat
750
751         start_mgs || error "unable to start MGS"
752         start_ost || error "unable to start OST1"
753         start_ost2 || error "unable to start OST2"
754         start_mds || error "MDS start failed"
755         wait_osc_import_state mds ost2 FULL
756
757         stop_ost || error "Unable to stop OST1"
758         stop_ost2 || error "Unable to stop OST2"
759         stop_mds || error "Unable to stop MDS"
760         stop_mgs
761         #writeconf to remove all ost2 traces for subsequent tests
762         writeconf_or_reformat
763         start_mgs || error "unable to start MGS"
764 }
765 run_test 21d "start mgs then ost and then mds"
766
767 cleanup_21e() {
768         MGSNID="$saved_mgsnid"
769         cleanup_fs2
770         echo "stopping fs2mgs ..."
771         stop $fs2mgs -f || true
772 }
773
774 test_21e() { # LU-5863
775         if [[ -z "$fs3ost_DEV" || -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
776                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
777                 skip_env "mixed loopback and real device not working" && return
778         fi
779
780         local fs2mdsdev=$(mdsdevname 1_2)
781         local fs2ostdev=$(ostdevname 1_2)
782         local fs3ostdev=$(ostdevname 2_2)
783
784         local fs2mdsvdev=$(mdsvdevname 1_2)
785         local fs2ostvdev=$(ostvdevname 1_2)
786         local fs3ostvdev=$(ostvdevname 2_2)
787
788         # temporarily use fs3ost as fs2mgs
789         local fs2mgs=fs3ost
790         local fs2mgsdev=$fs3ostdev
791         local fs2mgsvdev=$fs3ostvdev
792
793         local fsname=test1234
794
795         add $fs2mgs $(mkfs_opts mgs $fs2mgsdev) --fsname=$fsname \
796                 --reformat $fs2mgsdev $fs2mgsvdev || error "add fs2mgs failed"
797         start $fs2mgs $fs2mgsdev $MGS_MOUNT_OPTS && trap cleanup_21e EXIT INT ||
798                 error "start fs2mgs failed"
799
800         local saved_mgsnid="$MGSNID"
801         MGSNID=$(do_facet $fs2mgs $LCTL list_nids | xargs | tr ' ' ,)
802
803         add fs2mds $(mkfs_opts mds1 $fs2mdsdev $fsname) \
804                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
805         add fs2ost $(mkfs_opts ost1 $fs2ostdev $fsname) \
806                 --reformat $fs2ostdev $fs2ostvdev || error "add fs2ost failed"
807
808         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
809         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS || error "start fs2mds failed"
810
811         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
812         $MOUNT_CMD $MGSNID:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
813         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
814
815         cleanup_21e
816 }
817 run_test 21e "separate MGS and MDS"
818
819 test_22() {
820         start_mds || error "MDS start failed"
821
822         echo "Client mount with ost in logs, but none running"
823         start_ost || error "unable to start OST1"
824         # wait until mds connected to ost and open client connection
825         wait_osc_import_state mds ost FULL
826         stop_ost || error "unable to stop OST1"
827         mount_client $MOUNT || error "mount_client $MOUNT failed"
828         # check_mount will block trying to contact ost
829         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
830         rm -f $DIR/$tfile || error "remove $DIR/$tfile failed"
831         umount_client $MOUNT -f
832         pass
833
834         echo "Client mount with a running ost"
835         start_ost || error "unable to start OST1"
836         if $GSS; then
837                 # if gss enabled, wait full time to let connection from
838                 # mds to ost be established, due to the mismatch between
839                 # initial connect timeout and gss context negotiation timeout.
840                 # This perhaps could be remove after AT landed.
841                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
842                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
843         fi
844         mount_client $MOUNT || error "mount_client $MOUNT failed"
845         wait_osc_import_state mds ost FULL
846         wait_osc_import_ready client ost
847         check_mount || error "check_mount failed"
848         pass
849
850         cleanup || error "cleanup failed with rc $?"
851 }
852 run_test 22 "start a client before osts (should return errs)"
853
854 test_23a() {    # was test_23
855         setup
856         # fail mds
857         stop $SINGLEMDS || error "failed to stop $SINGLEMDS"
858         # force down client so that recovering mds waits for reconnect
859         local running=$(grep -c $MOUNT /proc/mounts) || true
860         if [ $running -ne 0 ]; then
861                 echo "Stopping client $MOUNT (opts: -f)"
862                 umount -f $MOUNT
863         fi
864
865         # enter recovery on failed mds
866         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
867         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "MDS start failed"
868         # try to start a new client
869         mount_client $MOUNT &
870         sleep 5
871         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
872         MOUNT_LUSTRE_PID=$(ps -ef | grep mount.lustre |
873                            grep -v grep | awk '{print $2}')
874         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
875         ps --ppid $MOUNT_PID
876         ps --ppid $MOUNT_LUSTRE_PID
877         echo "waiting for mount to finish"
878         ps -ef | grep mount
879         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
880         # SIGTERM works but it does not spread to offspring processses
881         kill -s TERM $MOUNT_PID
882         kill -s TERM $MOUNT_LUSTRE_PID
883         # we can not wait $MOUNT_PID because it is not a child of this shell
884         local PID1
885         local PID2
886         local WAIT=0
887         local MAX_WAIT=30
888         local sleep=1
889         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
890                 sleep $sleep
891                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
892                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
893                 echo PID1=$PID1
894                 echo PID2=$PID2
895                 [ -z "$PID1" -a -z "$PID2" ] && break
896                 echo "waiting for mount to finish ... "
897                 WAIT=$(( WAIT + sleep))
898         done
899         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
900                 error "MOUNT_PID $MOUNT_PID and "\
901                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
902                 ps -ef | grep mount
903         fi
904         cleanup || error "cleanup failed with rc $?"
905 }
906 run_test 23a "interrupt client during recovery mount delay"
907
908 test_23b() {    # was test_23
909         start_mds || error "MDS start failed"
910         start_ost || error "Unable to start OST1"
911         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
912         $LCTL set_param fail_loc=0x80000313
913         mount_client $MOUNT
914         cleanup || error "cleanup failed with rc $?"
915 }
916 run_test 23b "Simulate -EINTR during mount"
917
918 test_24a() {
919         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
920
921         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
922                 is_blkdev $SINGLEMDS $MDSDEV &&
923                 skip_env "mixed loopback and real device not working" && return
924         fi
925
926         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
927
928         local fs2mdsdev=$(mdsdevname 1_2)
929         local fs2ostdev=$(ostdevname 1_2)
930         local fs2mdsvdev=$(mdsvdevname 1_2)
931         local fs2ostvdev=$(ostvdevname 1_2)
932         local cl_user
933
934         # LU-9733 test fsname started with numbers as well
935         local FSNAME2=969362ae
936
937         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --nomgs --mgsnode=$MGSNID \
938                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
939
940         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --fsname=${FSNAME2} \
941                 --reformat $fs2ostdev $fs2ostvdev || exit 10
942
943         setup
944         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
945         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
946         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
947         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
948
949         # LU-9733 test fsname started with numbers
950         cl_user=$(do_facet $SINGLEMDS lctl --device $FSNAME2-MDT0000 \
951                         changelog_register -n) ||
952                                 error "register changelog failed"
953
954         do_facet $SINGLEMDS lctl --device $FSNAME2-MDT0000 \
955                         changelog_deregister $cl_user ||
956                                 error "deregister changelog failed"
957         # 1 still works
958         check_mount || error "check_mount failed"
959         # files written on 1 should not show up on 2
960         cp /etc/passwd $DIR/$tfile
961         sleep 10
962         [ -e $MOUNT2/$tfile ] && error "File bleed"
963         # 2 should work
964         sleep 5
965         cp /etc/passwd $MOUNT2/$tfile ||
966                 error "cp /etc/passwd $MOUNT2/$tfile failed"
967         rm $MOUNT2/$tfile || error "remove $MOUNT2/$tfile failed"
968         # 2 is actually mounted
969         grep $MOUNT2' ' /proc/mounts > /dev/null || error "$MOUNT2 not mounted"
970         # failover
971         facet_failover fs2mds
972         facet_failover fs2ost
973         df
974         umount_client $MOUNT
975         # the MDS must remain up until last MDT
976         stop_mds
977         MDS=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
978               awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
979         [ -z "$MDS" ] && error "No MDT"
980         cleanup_fs2
981         cleanup_nocli || error "cleanup_nocli failed with rc $?"
982 }
983 run_test 24a "Multiple MDTs on a single node"
984
985 test_24b() {
986         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
987
988         if [ -z "$fs2mds_DEV" ]; then
989                 local dev=${SINGLEMDS}_dev
990                 local MDSDEV=${!dev}
991                 is_blkdev $SINGLEMDS $MDSDEV &&
992                 skip_env "mixed loopback and real device not working" && return
993         fi
994
995         local fs2mdsdev=$(mdsdevname 1_2)
996         local fs2mdsvdev=$(mdsvdevname 1_2)
997
998         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --mgs --fsname=${FSNAME}2 \
999                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
1000         setup
1001         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS &&
1002                 error "start MDS should fail"
1003         stop fs2mds -f
1004         cleanup || error "cleanup failed with rc $?"
1005 }
1006 run_test 24b "Multiple MGSs on a single node (should return err)"
1007
1008 test_25() {
1009         setup
1010         check_mount || error "check_mount failed"
1011         local MODULES=$($LCTL modules | awk '{ print $2 }')
1012         rmmod $MODULES 2>/dev/null || true
1013         cleanup || error "cleanup failed with $?"
1014 }
1015 run_test 25 "Verify modules are referenced"
1016
1017 test_26() {
1018         load_modules
1019         # we need modules before mount for sysctl, so make sure...
1020         do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
1021         #define OBD_FAIL_MDS_FS_SETUP            0x135
1022         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000135"
1023         start_mds && error "MDS started but should not have started"
1024         $LCTL get_param -n devices
1025         DEVS=$($LCTL get_param -n devices | egrep -v MG | wc -l)
1026         [ $DEVS -gt 0 ] && error "number of devices is $DEVS, should be zero"
1027         # start mds to drop writeconf setting
1028         start_mds || error "Unable to start MDS"
1029         stop_mds || error "Unable to stop MDS"
1030         unload_modules_conf || error "unload_modules_conf failed with $?"
1031 }
1032 run_test 26 "MDT startup failure cleans LOV (should return errs)"
1033
1034 test_27a() {
1035         start_ost || error "Unable to start OST1"
1036         start_mds || error "Unable to start MDS"
1037         echo "Requeue thread should have started: "
1038         ps -e | grep ll_cfg_requeue
1039         set_persistent_param_and_check ost1                     \
1040            "obdfilter.$FSNAME-OST0000.client_cache_seconds"     \
1041            "$FSNAME-OST0000.ost.client_cache_seconds"
1042         cleanup_nocli || error "cleanup_nocli failed with rc $?"
1043 }
1044 run_test 27a "Reacquire MGS lock if OST started first"
1045
1046 test_27b() {
1047         # FIXME. ~grev
1048         setup
1049         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
1050                         awk '($3 ~ "mdt" && $4 ~ "MDT0000") { print $4 }')
1051
1052         facet_failover $SINGLEMDS
1053         set_persistent_param_and_check $SINGLEMDS       \
1054                 "mdt.$device.identity_acquire_expire"   \
1055                 "$device.mdt.identity_acquire_expire"
1056         set_persistent_param_and_check client           \
1057                 "mdc.$device-mdc-*.max_rpcs_in_flight"  \
1058                 "$device.mdc.max_rpcs_in_flight"
1059         check_mount
1060         cleanup || error "cleanup failed with $?"
1061 }
1062 run_test 27b "Reacquire MGS lock after failover"
1063
1064 test_28A() { # was test_28
1065         setup
1066         TEST="llite.$FSNAME-*.max_read_ahead_whole_mb"
1067         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1068         ORIG=$($LCTL get_param -n $TEST)
1069         FINAL=$(($ORIG + 1))
1070         set_persistent_param_and_check client "$TEST" "$PARAM" $FINAL
1071         FINAL=$(($FINAL + 1))
1072         set_persistent_param_and_check client "$TEST" "$PARAM" $FINAL
1073         umount_client $MOUNT || error "umount_client $MOUNT failed"
1074         mount_client $MOUNT || error "mount_client $MOUNT failed"
1075         RESULT=$($LCTL get_param -n $TEST)
1076         if [ $RESULT -ne $FINAL ]; then
1077                 error "New config not seen: wanted $FINAL got $RESULT"
1078         else
1079                 echo "New config success: got $RESULT"
1080         fi
1081         set_persistent_param_and_check client "$TEST" "$PARAM" $ORIG
1082         cleanup || error "cleanup failed with rc $?"
1083 }
1084 run_test 28A "permanent parameter setting"
1085
1086 test_28a() { # LU-4221
1087         [[ $(lustre_version_code ost1) -ge $(version_code 2.5.52) ]] ||
1088                 { skip "Need OST version at least 2.5.52" && return 0; }
1089         [ "$(facet_fstype ost1)" = "zfs" ] &&
1090                 skip "LU-4221: no such proc params for ZFS OSTs" && return
1091
1092         local name
1093         local param
1094         local cmd
1095         local old
1096         local new
1097         local device="$FSNAME-OST0000"
1098
1099         setup
1100
1101         # In this test we will set three kinds of proc parameters with
1102         # lctl set_param -P or lctl conf_param:
1103         # 1. non-symlink ones in the OFD
1104         # 2. non-symlink ones in the OSD
1105
1106         # Check 1.
1107         # prepare a non-symlink parameter in the OFD
1108         name="client_cache_seconds"
1109         param="$device.ost.$name"
1110         cmd="obdfilter.$device.$name"
1111
1112         # permanently setting the parameter in the OFD
1113         old=$(do_facet ost1 $LCTL get_param -n $cmd)
1114         new=$((old * 2))
1115         set_persistent_param_and_check ost1 "$cmd" "$param" $new
1116         set_persistent_param_and_check ost1 "$cmd" "$param" $old
1117
1118         # Check 2.
1119         # prepare a non-symlink parameter in the OSD
1120         name="auto_scrub"
1121         param="$device.osd.$name"
1122         cmd="osd-*.$device.$name"
1123
1124         # conf_param the parameter in the OSD
1125         old=$(do_facet ost1 $LCTL get_param -n $cmd)
1126         new=$(((old + 1) % 2))
1127         set_persistent_param_and_check ost1 "$cmd" "$param" $new
1128         set_persistent_param_and_check ost1 "$cmd" "$param" $old
1129
1130         cleanup || error "cleanup failed with $?"
1131 }
1132 run_test 28a "set symlink parameters permanently with lctl"
1133
1134 test_29() {
1135         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1136         setup > /dev/null 2>&1
1137         start_ost2 || error "Unable to start OST2"
1138         sleep 10
1139
1140         local PARAM="$FSNAME-OST0001.osc.active"
1141         # With lctl set_param -P the value $PROC_ACT will be sent to
1142         # all nodes. The [^M] filter out the ability to set active
1143         # on the MDS servers which is tested with wait_osp_* below.
1144         # For ost_server_uuid that only exist on client so filtering
1145         # is safe.
1146         local PROC_ACT="osc.$FSNAME-OST0001-osc-*.active"
1147         local PROC_UUID="osc.$FSNAME-OST0001-osc-[!M]*.ost_server_uuid"
1148
1149         ACTV=$($LCTL get_param -n $PROC_ACT)
1150         DEAC=$((1 - $ACTV))
1151         set_persistent_param_and_check client $PROC_ACT $PARAM $DEAC
1152         # also check ost_server_uuid status
1153         RESULT=$($LCTL get_param -n $PROC_UUID | grep DEACTIV)
1154         if [ -z "$RESULT" ]; then
1155                 error "Client not deactivated: $($LCTL get_param \
1156                        -n $PROC_UUID)"
1157         else
1158                 echo "Live client success: got $RESULT"
1159         fi
1160
1161         # check MDTs too
1162         wait_osp_active ost ${FSNAME}-OST0001 1 0
1163
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_persistent_param_and_check client $PROC_ACT $PARAM $ACTV
1176
1177         umount_client $MOUNT
1178         stop_ost2 || error "Unable to stop OST2"
1179         cleanup_nocli || error "cleanup_nocli failed with $?"
1180         #writeconf to remove all ost2 traces for subsequent tests
1181         writeconf_or_reformat
1182 }
1183 run_test 29 "permanently remove an OST"
1184
1185 test_30a() {
1186         setup
1187
1188         echo Big config llog
1189         TEST="llite.$FSNAME-*.max_read_ahead_whole_mb"
1190         ORIG=$($LCTL get_param -n $TEST)
1191         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1192         for i in ${LIST[@]}; do
1193                 set_persistent_param_and_check client "$TEST" \
1194                         "$FSNAME.llite.max_read_ahead_whole_mb" $i
1195         done
1196         # make sure client restart still works
1197         umount_client $MOUNT
1198         mount_client $MOUNT || error "mount_client $MOUNT failed"
1199         [ "$($LCTL get_param -n $TEST)" -ne "$i" ] &&
1200                 error "Param didn't stick across restart $($TEST) != $i"
1201         pass
1202
1203         echo Erase parameter setting
1204         if [[ $PERM_CMD = *"set_param -P"* ]]; then
1205                 do_facet mgs "$PERM_CMD -d $TEST" ||
1206                         error "Erase param $TEST failed"
1207         else
1208                 do_facet mgs "$PERM_CMD \
1209                               -d $FSNAME.llite.max_read_ahead_whole_mb" ||
1210                         error "Erase param $FSNAME.llite.max_read_ahead_whole_mb failed"
1211         fi
1212         umount_client $MOUNT
1213         mount_client $MOUNT || error "mount_client $MOUNT failed"
1214         FINAL=$($LCTL get_param -n $TEST)
1215         echo "deleted (default) value=$FINAL, orig=$ORIG"
1216         # assumes this parameter started at the default value
1217         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1218
1219         cleanup || error "cleanup failed with rc $?"
1220 }
1221 run_test 30a "Big config llog and permanent parameter deletion"
1222
1223 test_30b() {
1224         setup
1225
1226         local orignids=$($LCTL get_param -n \
1227                 osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1228
1229         local orignidcount=$(echo "$orignids" | wc -w)
1230
1231         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1232         # numerical part of it. Hopefully that's not already a failover address
1233         # for the server.
1234         local OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | \
1235                 awk '{print $1}')
1236         local ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1237         local NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1238         local NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1239         echo "Using fake nid $NEW"
1240
1241         local TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1242                 grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1243         if [[ $PERM_CMD = *"set_param -P"* ]]; then
1244                 PARAM="osc.$FSNAME-OST0000-osc-[^M]*.import"
1245                 echo "Setting $PARAM from $TEST to $NEW"
1246                 do_facet mgs "$PERM_CMD $PARAM='connection=$NEW'" ||
1247                         error "$PERM_CMD $PARAM failed"
1248         else
1249                 PARAM="$FSNAME-OST0000.failover.node"
1250                 echo "Setting $PARAM from $TEST to $NEW"
1251                 do_facet mgs "$PERM_CMD $PARAM='$NEW'" ||
1252                         error "$PARAM $PARAM failed"
1253         fi
1254         wait_update_facet client "$TEST" "$NEW" ||
1255                 error "check $PARAM failed!"
1256
1257         local NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1258                 grep failover_nids)
1259         local NIDCOUNT=$(echo "$NIDS" | wc -w)
1260         echo "should have $((orignidcount + 1)) entries \
1261                 in failover nids string, have $NIDCOUNT"
1262         [ $NIDCOUNT -eq $((orignidcount + 1)) ] ||
1263                 error "Failover nid not added"
1264
1265         if [[ $PERM_CMD = *"set_param -P"* ]]; then
1266                 do_facet mgs "$PERM_CMD -d osc.$FSNAME-OST0000-osc-*.import"
1267         else
1268                 do_facet mgs "$PERM_CMD -d $FSNAME-OST0000.failover.node" ||
1269                         error "$PERM_CMD delete failed"
1270         fi
1271         umount_client $MOUNT
1272         mount_client $MOUNT || error "mount_client $MOUNT failed"
1273
1274         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1275                 grep failover_nids)
1276         NIDCOUNT=$(echo "$NIDS" | wc -w)
1277         echo "only $orignidcount final entries should remain \
1278                 in failover nids string, have $NIDCOUNT"
1279         [ $NIDCOUNT -eq $orignidcount ] || error "Failover nids not removed"
1280
1281         cleanup || error "cleanup failed with rc $?"
1282 }
1283 run_test 30b "Remove failover nids"
1284
1285 test_31() { # bug 10734
1286         # ipaddr must not exist
1287         $MOUNT_CMD 4.3.2.1@tcp:/lustre $MOUNT || true
1288         cleanup || error "cleanup failed with rc $?"
1289 }
1290 run_test 31 "Connect to non-existent node (shouldn't crash)"
1291
1292
1293 T32_QID=60000
1294 T32_BLIMIT=40960 # Kbytes
1295 T32_ILIMIT=4
1296
1297 #
1298 # This is not really a test but a tool to create new disk
1299 # image tarballs for the upgrade tests.
1300 #
1301 # Disk image tarballs should be created on single-node
1302 # clusters by running this test with default configurations
1303 # plus a few mandatory environment settings that are verified
1304 # at the beginning of the test.
1305 #
1306 test_32newtarball() {
1307         local version
1308         local dst=.
1309         local src=/etc/rc.d
1310         local tmp=$TMP/t32_image_create
1311         local server_version=$(lustre_version_code $SINGLEMDS)
1312         local remote_dir
1313         local striped_dir
1314         local pushd_dir
1315
1316         if [ $FSNAME != t32fs -o \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o \
1317              $OSTCOUNT -ne 1 -o -z "$OSTDEV1" ]; then
1318                 error "Needs FSNAME=t32fs MDSCOUNT=2 "                  \
1319                       "MDSDEV1=<nonexistent_file>"                      \
1320                       "MDSDEV2=<nonexistent_file>"                      \
1321                       "(or MDSDEV, in the case of b1_8)"                \
1322                       "OSTCOUNT=1 OSTDEV1=<nonexistent_file>"
1323         fi
1324
1325         mkdir $tmp || {
1326                 echo "Found stale $tmp"
1327                 return 1
1328         }
1329
1330         mkdir $tmp/src || return 1
1331         tar cf - -C $src . | tar xf - -C $tmp/src
1332         dd if=/dev/zero of=$tmp/src/t32_qf_old bs=1M \
1333                 count=$(($T32_BLIMIT / 1024 / 4))
1334         chown $T32_QID.$T32_QID $tmp/src/t32_qf_old
1335
1336         # format ost with comma-separated NIDs to verify LU-4460
1337         local failnid="$(h2nettype 1.2.3.4),$(h2nettype 4.3.2.1)"
1338         MGSNID="$MGSNID,$MGSNID" OSTOPT="--failnode=$failnid" formatall
1339
1340         setupall
1341
1342         [[ $server_version -ge $(version_code 2.3.50) ]] ||
1343                 $LFS quotacheck -ug /mnt/$FSNAME
1344         $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
1345                 /mnt/$FSNAME
1346
1347         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1348
1349         if [[ $MDSCOUNT -ge 2 ]]; then
1350                 remote_dir=/mnt/$FSNAME/remote_dir
1351                 $LFS mkdir -i 1 $remote_dir
1352                 tar cf - -C $tmp/src . | tar xf - -C $remote_dir
1353
1354                 if [[ $server_version -ge $(version_code 2.7.0) ]]; then
1355                         striped_dir=/mnt/$FSNAME/striped_dir_old
1356                         $LFS mkdir -i 1 -c 2 $striped_dir
1357                         tar cf - -C $tmp/src . | tar xf - -C $striped_dir
1358                 fi
1359         fi
1360
1361         stopall
1362
1363         mkdir $tmp/img || return 1
1364
1365         setupall
1366
1367         pushd_dir=/mnt/$FSNAME
1368         if [[ $MDSCOUNT -ge 2 ]]; then
1369                 pushd_dir=$remote_dir
1370                 if [[ $server_version -ge $(version_code 2.7.0) ]]; then
1371                         pushd $striped_dir
1372                         ls -Rni --time-style=+%s >$tmp/img/list2
1373                         popd
1374                 fi
1375         fi
1376
1377         pushd $pushd_dir
1378         ls -Rni --time-style=+%s >$tmp/img/list
1379         find ! -name .lustre -type f -exec sha1sum {} \; |
1380                 sort -k 2 >$tmp/img/sha1sums
1381         popd
1382         $LCTL get_param -n version | head -n 1 |
1383                 sed -e 's/^lustre: *//' >$tmp/img/commit
1384
1385         [[ $server_version -ge $(version_code 2.3.50) ]] ||
1386                 $LFS quotaon -ug /mnt/$FSNAME
1387         $LFS quota -u $T32_QID -v /mnt/$FSNAME
1388         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1389                 awk 'BEGIN { num='1' } { if ($1 == "'/mnt/$FSNAME'") \
1390                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1391                 | tr -d "*" > $tmp/img/bspace
1392         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1393                 awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
1394                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1395                 | tr -d "*" > $tmp/img/ispace
1396         echo $T32_BLIMIT > $tmp/img/blimit
1397         echo $T32_ILIMIT > $tmp/img/ilimit
1398
1399         stopall
1400
1401         pushd $tmp/src
1402         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1403         popd
1404
1405         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1406                 echo "Data verification failed"
1407         fi
1408
1409         uname -r >$tmp/img/kernel
1410         uname -m >$tmp/img/arch
1411
1412         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1413         for num in $(seq 2 $MDSCOUNT); do
1414                 local devname=$(mdsdevname $num)
1415                 local facet=mds$num
1416                 [[ $(facet_fstype $facet) != zfs ]] ||
1417                         devname=$(mdsvdevname $num)
1418                 mv $devname $tmp/img
1419         done
1420         mv $OSTDEV1 $tmp/img
1421
1422         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1423                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1424         dst=$(cd $dst; pwd)
1425         pushd $tmp/img
1426         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1427         popd
1428
1429         rm -r $tmp
1430 }
1431 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1432
1433 #
1434 # The list of applicable tarballs is returned via the caller's
1435 # variable "tarballs".
1436 #
1437 t32_check() {
1438         local node=$(facet_active_host $SINGLEMDS)
1439         local r="do_node $node"
1440
1441         if [ "$CLIENTONLY" ]; then
1442                 skip "Client-only testing"
1443                 exit 0
1444         fi
1445
1446         if ! $r which $TUNEFS; then
1447                 skip_env "tunefs.lustre required on $node"
1448                 exit 0
1449         fi
1450
1451         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1452
1453         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 \
1454                    -name \'disk*-$IMGTYPE.tar.bz2\')
1455
1456         if [ -z "$tarballs" ]; then
1457                 skip "No applicable tarballs found"
1458                 exit 0
1459         fi
1460 }
1461
1462 t32_test_cleanup() {
1463         local tmp=$TMP/t32
1464         local facet=$SINGLEMDS
1465         local fstype=$(facet_fstype $facet)
1466         local rc=$?
1467
1468         if $shall_cleanup_lustre; then
1469                 umount $tmp/mnt/lustre || rc=$?
1470         fi
1471         if $shall_cleanup_mdt; then
1472                 $r $UMOUNT $tmp/mnt/mdt || rc=$?
1473         fi
1474         if $shall_cleanup_mdt1; then
1475                 $r $UMOUNT $tmp/mnt/mdt1 || rc=$?
1476         fi
1477         if $shall_cleanup_ost; then
1478                 $r $UMOUNT $tmp/mnt/ost || rc=$?
1479         fi
1480
1481         $r rm -rf $tmp
1482         rm -rf $tmp
1483         if [[ $fstype == zfs ]]; then
1484                 local poolname
1485                 local poolname_list="t32fs-mdt1 t32fs-ost1"
1486
1487                 ! $mdt2_is_available || poolname_list+=" t32fs-mdt2"
1488
1489                 for poolname in $poolname_list; do
1490                         destroy_zpool $facet $poolname
1491                 done
1492         fi
1493         combined_mgs_mds || start_mgs || rc=$?
1494         return $rc
1495 }
1496
1497 t32_bits_per_long() {
1498         #
1499         # Yes, this is not meant to be perfect.
1500         #
1501         case $1 in
1502                 ppc64|x86_64)
1503                         echo -n 64;;
1504                 i*86)
1505                         echo -n 32;;
1506         esac
1507 }
1508
1509 t32_reload_modules() {
1510         local node=$1
1511         local all_removed=false
1512         local i=0
1513         local fstype=$(facet_fstype $SINGLEMDS)
1514
1515         [ $fstype == "zfs" ] && do_rpc_nodes $node "service zed stop"
1516
1517         while ((i < 20)); do
1518                 echo "Unloading modules on $node: Attempt $i"
1519                 do_rpc_nodes $node $LUSTRE_RMMOD $fstype &&
1520                         all_removed=true
1521                 do_rpc_nodes $node check_mem_leak || return 1
1522                 if $all_removed; then
1523                         do_rpc_nodes $node load_modules
1524                         return 0
1525                 fi
1526                 if [ $fstype == "zfs" ]; then
1527                         do_rpc_nodes $node "$ZPOOL status -v"
1528                 fi
1529                 sleep 5
1530                 i=$((i + 1))
1531         done
1532         echo "Unloading modules on $node: Given up"
1533         return 1
1534 }
1535
1536 t32_wait_til_devices_gone() {
1537         local node=$1
1538         local devices
1539         local loops
1540         local i=0
1541
1542         echo wait for devices to go
1543         while ((i < 20)); do
1544                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1545                 loops=$(do_rpc_nodes $node losetup -a | grep -c t32)
1546                 ((devices == 0 && loops == 0)) && return 0
1547                 sleep 5
1548                 i=$((i + 1))
1549         done
1550         echo "waiting for dev on $node: dev $devices loop $loops given up"
1551         do_rpc_nodes $node "losetup -a"
1552         do_rpc_nodes $node "$LCTL device_list"
1553         return 1
1554 }
1555
1556 t32_verify_quota() {
1557         local facet=$1
1558         local fsname=$2
1559         local mnt=$3
1560         local fstype=$(facet_fstype $SINGLEMDS)
1561         local qval
1562         local cmd
1563
1564         # LU-2435: if the underlying zfs doesn't support userobj_accounting,
1565         # lustre will estimate the object count usage. This fails quota
1566         # verification in 32b. The object quota usage should be accurate after
1567         # zfs-0.7.0 is released.
1568         [ $fstype == "zfs" ] && {
1569                 local zfs_version=$(do_facet $facet cat /sys/module/zfs/version)
1570
1571                 [ $(version_code $zfs_version) -lt $(version_code 0.7.0) ] && {
1572                         echo "Skip quota verify for zfs: $zfs_version"
1573                         return 0
1574                 }
1575         }
1576
1577         $LFS quota -u $T32_QID -v $mnt
1578
1579         qval=$($LFS quota -v -u $T32_QID $mnt |
1580                 awk 'BEGIN { num='1' } { if ($1 == "'$mnt'") \
1581                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1582                 | tr -d "*")
1583         [ $qval -eq $img_bspace ] || {
1584                 echo "bspace, act:$qval, exp:$img_bspace"
1585                 return 1
1586         }
1587
1588         qval=$($LFS quota -v -u $T32_QID $mnt |
1589                 awk 'BEGIN { num='5' } { if ($1 == "'$mnt'") \
1590                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1591                 | tr -d "*")
1592         [ $qval -eq $img_ispace ] || {
1593                 echo "ispace, act:$qval, exp:$img_ispace"
1594                 return 1
1595         }
1596
1597         qval=$($LFS quota -v -u $T32_QID $mnt |
1598                 awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
1599                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1600                 | tr -d "*")
1601         [ $qval -eq $img_blimit ] || {
1602                 echo "blimit, act:$qval, exp:$img_blimit"
1603                 return 1
1604         }
1605
1606         qval=$($LFS quota -v -u $T32_QID $mnt |
1607                 awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
1608                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1609                 | tr -d "*")
1610         [ $qval -eq $img_ilimit ] || {
1611                 echo "ilimit, act:$qval, exp:$img_ilimit"
1612                 return 1
1613         }
1614
1615         set_persistent_param_and_check $facet \
1616                 "osd-$fstype.$fsname-MDT0000.quota_slave.enabled" \
1617                 "$fsname.quota.mdt" ug
1618
1619         set_persistent_param_and_check $facet \
1620                 "osd-$fstype.$fsname-OST0000.quota_slave.enabled" \
1621                 "$fsname.quota.ost" ug
1622
1623         chmod 0777 $mnt
1624         runas -u $T32_QID -g $T32_QID dd if=/dev/zero of=$mnt/t32_qf_new \
1625                 bs=1M count=$((img_blimit / 1024)) oflag=sync && {
1626                 echo "Write succeed, but expect -EDQUOT"
1627                 return 1
1628         }
1629         rm -f $mnt/t32_qf_new
1630
1631         runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
1632                 $img_ilimit && {
1633                 echo "Create succeed, but expect -EDQUOT"
1634                 return 1
1635         }
1636         unlinkmany $mnt/t32_qf_ $img_ilimit
1637
1638         return 0
1639 }
1640
1641 t32_test() {
1642         local tarball=$1
1643         local writeconf=$2
1644         local dne_upgrade=${dne_upgrade:-"no"}
1645         local dom_upgrade=${dom_upgrade:-"no"}
1646         local ff_convert=${ff_convert:-"no"}
1647         local shall_cleanup_mdt=false
1648         local shall_cleanup_mdt1=false
1649         local shall_cleanup_ost=false
1650         local shall_cleanup_lustre=false
1651         local mdt2_is_available=false
1652         local node=$(facet_active_host $SINGLEMDS)
1653         local r="do_node $node"
1654         local tmp=$TMP/t32
1655         local img_commit
1656         local img_kernel
1657         local img_arch
1658         local img_bspace
1659         local img_ispace
1660         local img_blimit
1661         local img_ilimit
1662         local fsname=t32fs
1663         local nid
1664         local mopts
1665         local uuid
1666         local nrpcs_orig
1667         local nrpcs
1668         local list
1669         local fstype=$(facet_fstype $SINGLEMDS)
1670         local mdt_dev=$tmp/mdt
1671         local mdt2_dev=$tmp/mdt2
1672         local ost_dev=$tmp/ost
1673         local stripe_index
1674         local stripe_count
1675         local dir
1676
1677         combined_mgs_mds || stop_mgs || error "Unable to stop MGS"
1678         trap 'trap - RETURN; t32_test_cleanup' RETURN
1679
1680         load_modules
1681         nid=$($r $LCTL list_nids | head -1)
1682
1683         mkdir -p $tmp/mnt/lustre || error "mkdir $tmp/mnt/lustre failed"
1684         $r mkdir -p $tmp/mnt/{mdt,mdt1,ost}
1685         $r tar xjvf $tarball -S -C $tmp || {
1686                 error_noexit "Unpacking the disk image tarball"
1687                 return 1
1688         }
1689         img_commit=$($r cat $tmp/commit)
1690         img_kernel=$($r cat $tmp/kernel)
1691         img_arch=$($r cat $tmp/arch)
1692         img_bspace=$($r cat $tmp/bspace)
1693         img_ispace=$($r cat $tmp/ispace)
1694
1695         # older images did not have "blimit" and "ilimit" files
1696         # use old values for T32_BLIMIT and T32_ILIMIT
1697         $r test -f $tmp/blimit && img_blimit=$($r cat $tmp/blimit) ||
1698                 img_blimit=20480
1699         $r test -f $tmp/ilimit && img_ilimit=$($r cat $tmp/ilimit) ||
1700                 img_ilimit=2
1701
1702         echo "Upgrading from $(basename $tarball), created with:"
1703         echo "  Commit: $img_commit"
1704         echo "  Kernel: $img_kernel"
1705         echo "    Arch: $img_arch"
1706         echo "OST version: $(lustre_build_version ost1)"
1707
1708         # The conversion can be made only when both of the following
1709         # conditions are satisfied:
1710         # - ost device img version < 2.3.64
1711         # - ost server version >= 2.5
1712         [ $(version_code $img_commit) -ge $(version_code 2.3.64) -o \
1713                 $(lustre_version_code ost1) -lt $(version_code 2.5.0) ] &&
1714                         ff_convert="no"
1715
1716         ! $r test -f $mdt2_dev || mdt2_is_available=true
1717
1718         if [[ $fstype == zfs ]]; then
1719                 # import pool first
1720                 local poolname
1721                 local poolname_list="t32fs-mdt1 t32fs-ost1"
1722
1723                 ! $mdt2_is_available || poolname_list+=" t32fs-mdt2"
1724
1725                 for poolname in $poolname_list; do
1726                         $r "modprobe zfs;
1727                                 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1728                                 $ZPOOL import -f -d $tmp $poolname"
1729                 done
1730
1731                 # upgrade zpool to latest supported features, including
1732                 # dnode quota accounting in 0.7.0
1733                 $r "$ZPOOL upgrade -a"
1734
1735                 mdt_dev=t32fs-mdt1/mdt1
1736                 ost_dev=t32fs-ost1/ost1
1737                 ! $mdt2_is_available || mdt2_dev=t32fs-mdt2/mdt2
1738                 wait_update_facet $SINGLEMDS "$ZPOOL list |
1739                         awk '/^t32fs-mdt1/ { print \\\$1 }'" "t32fs-mdt1" || {
1740                                 error_noexit "import zfs pool failed"
1741                                 return 1
1742                         }
1743         fi
1744
1745         $r $LCTL set_param debug="$PTLDEBUG"
1746
1747         $r $TUNEFS --dryrun $mdt_dev || {
1748                 $r losetup -a
1749                 error_noexit "tunefs.lustre before mounting the MDT"
1750                 return 1
1751         }
1752
1753         if $mdt2_is_available; then
1754                 $r $TUNEFS --dryrun $mdt2_dev || {
1755                         $r losetup -a
1756                         error_noexit "tunefs.lustre before mounting the MDT"
1757                         return 1
1758                 }
1759         fi
1760
1761         if [ "$writeconf" ]; then
1762                 mopts=writeconf
1763                 if [ $fstype == "ldiskfs" ]; then
1764                         mopts="loop,$mopts"
1765                         $r $TUNEFS --quota $mdt_dev || {
1766                                 $r losetup -a
1767                                 error_noexit "Enable mdt quota feature"
1768                                 return 1
1769                         }
1770                         if $mdt2_is_available; then
1771                                 $r $TUNEFS --quota $mdt2_dev || {
1772                                         $r losetup -a
1773                                         error_noexit "Enable mdt quota feature"
1774                                         return 1
1775                                 }
1776                         fi
1777                 fi
1778         else
1779                 if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1780                         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
1781                         { skip "LU-2200: Cannot run over Inifiniband w/o lctl replace_nids "
1782                                 "(Need MGS version at least 2.3.59)"; return 0; }
1783
1784                         local osthost=$(facet_active_host ost1)
1785                         local ostnid=$(do_node $osthost $LCTL list_nids | head -1)
1786
1787                         mopts=nosvc
1788                         if [ $fstype == "ldiskfs" ]; then
1789                                 mopts="loop,$mopts"
1790                         fi
1791                         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt
1792                         $r $LCTL replace_nids $fsname-OST0000 $ostnid
1793                         $r $LCTL replace_nids $fsname-MDT0000 $nid
1794                         $r $UMOUNT $tmp/mnt/mdt
1795                 fi
1796
1797                 mopts=exclude=$fsname-OST0000
1798                 if [ $fstype == "ldiskfs" ]; then
1799                         mopts="loop,$mopts"
1800                 fi
1801         fi
1802
1803         t32_wait_til_devices_gone $node
1804
1805         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
1806                 $r losetup -a
1807                 error_noexit "Mounting the MDT"
1808                 return 1
1809         }
1810         shall_cleanup_mdt=true
1811
1812         if $mdt2_is_available; then
1813                 mopts=mgsnode=$nid,$mopts
1814                 $r $MOUNT_CMD -o $mopts $mdt2_dev $tmp/mnt/mdt1 || {
1815                         $r losetup -a
1816                         error_noexit "Mounting the MDT"
1817                         return 1
1818                 }
1819
1820                 echo "mount new MDT....$mdt2_dev"
1821                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
1822                         error_noexit "enable remote dir create failed"
1823
1824                 shall_cleanup_mdt1=true
1825         elif [ "$dne_upgrade" != "no" ]; then
1826                 local fs2mdsdev=$(mdsdevname 1_2)
1827                 local fs2mdsvdev=$(mdsvdevname 1_2)
1828
1829                 echo "mkfs new MDT on ${fs2mdsdev}...."
1830                 if [ $(facet_fstype mds1) == ldiskfs ]; then
1831                         mkfsoptions="--mkfsoptions=\\\"-J size=8\\\""
1832                 fi
1833
1834                 add $SINGLEMDS $(mkfs_opts mds2 $fs2mdsdev $fsname) --reformat \
1835                            $mkfsoptions $fs2mdsdev $fs2mdsvdev > /dev/null || {
1836                         error_noexit "Mkfs new MDT failed"
1837                         return 1
1838                 }
1839
1840                 [[ $(facet_fstype mds1) != zfs ]] || import_zpool mds1
1841
1842                 $r $TUNEFS --dryrun $fs2mdsdev || {
1843                         error_noexit "tunefs.lustre before mounting the MDT"
1844                         return 1
1845                 }
1846
1847                 echo "mount new MDT....$fs2mdsdev"
1848                 $r $MOUNT_CMD -o $mopts $fs2mdsdev $tmp/mnt/mdt1 || {
1849                         error_noexit "mount mdt1 failed"
1850                         return 1
1851                 }
1852
1853                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
1854                         error_noexit "enable remote dir create failed"
1855
1856                 shall_cleanup_mdt1=true
1857         fi
1858
1859         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1860                 error_noexit "Getting MDT UUID"
1861                 return 1
1862         }
1863         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1864                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1865                 return 1
1866         fi
1867
1868         $r $TUNEFS --dryrun $ost_dev || {
1869                 error_noexit "tunefs.lustre before mounting the OST"
1870                 return 1
1871         }
1872         if [ "$writeconf" ]; then
1873                 mopts=mgsnode=$nid,$writeconf
1874                 if [ $fstype == "ldiskfs" ]; then
1875                         mopts="loop,$mopts"
1876                         $r $TUNEFS --quota $ost_dev || {
1877                                 $r losetup -a
1878                                 error_noexit "Enable ost quota feature"
1879                                 return 1
1880                         }
1881                 fi
1882         else
1883                 mopts=mgsnode=$nid
1884                 if [ $fstype == "ldiskfs" ]; then
1885                         mopts="loop,$mopts"
1886                 fi
1887         fi
1888
1889         $r $MOUNT_CMD -onomgs -o$mopts $ost_dev $tmp/mnt/ost || {
1890                 error_noexit "Mounting the OST"
1891                 return 1
1892         }
1893         shall_cleanup_ost=true
1894
1895         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1896                 error_noexit "Getting OST UUID"
1897                 return 1
1898         }
1899         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1900                 error_noexit "Unexpected OST UUID: \"$uuid\""
1901                 return 1
1902         fi
1903
1904         if [[ $PERM_CMD = *"set_param -P"* ]]; then
1905                 $r $PERM_CMD osc.$fsname-OST0000*.import=connection=$nid || {
1906                         error_noexit "Setting OST \"failover.node\""
1907                         return 1
1908                 }
1909                 $r $PERM_CMD mdc.$fsname-MDT0000*.import=connection=$nid || {
1910                         error_noexit "Setting MDT \"failover.node\""
1911                         return 1
1912                 }
1913                 $r $PERM_CMD osc.$fsname-OST0000-*.max_dirty_mb=15 || {
1914                         error_noexit "Setting \"max_dirty_mb\""
1915                         return 1
1916                 }
1917                 $r $PERM_CMD mdc.$fsname-MDT0000-*.max_rpcs_in_flight=9 || {
1918                         error_noexit "Setting \"max_rpcs_in_flight\""
1919                         return 1
1920                 }
1921                 $r $PERM_CMD lov.$fsname-MDT0000-*.stripesize=4M || {
1922                         error_noexit "Setting \"lov.stripesize\""
1923                         return 1
1924                 }
1925                 $r $PERM_CMD mdd.$fsname-MDT0000-*.atime_diff=70 || {
1926                         error_noexit "Setting \"mdd.atime_diff\""
1927                         return 1
1928                 }
1929         else
1930                 $r $PERM_CMD $fsname-OST0000.failover.node=$nid || {
1931                         error_noexit "Setting OST \"failover.node\""
1932                         return 1
1933                 }
1934
1935                 $r $PERM_CMD $fsname-MDT0000.failover.node=$nid || {
1936                         error_noexit "Setting MDT \"failover.node\""
1937                         return 1
1938                 }
1939
1940                 $r $PERM_CMD $fsname-OST0000.osc.max_dirty_mb=15 || {
1941                         error_noexit "Setting \"max_dirty_mb\""
1942                         return 1
1943                 }
1944                 $r $PERM_CMD $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1945                         error_noexit "Setting \"max_rpcs_in_flight\""
1946                         return 1
1947                 }
1948                 $r $PERM_CMD $fsname-MDT0000.lov.stripesize=4M || {
1949                         error_noexit "Setting \"lov.stripesize\""
1950                         return 1
1951                 }
1952                 $r $PERM_CMD $fsname-MDT0000.mdd.atime_diff=70 || {
1953                         error_noexit "Setting \"mdd.atime_diff\""
1954                         return 1
1955                 }
1956         fi
1957
1958         $r $LCTL pool_new $fsname.interop || {
1959                 error_noexit "Setting \"interop\""
1960                 return 1
1961         }
1962
1963         if [ "$ff_convert" != "no" -a $(facet_fstype ost1) == "ldiskfs" ]; then
1964                 $r $LCTL lfsck_start -M $fsname-OST0000 || {
1965                         error_noexit "Start OI scrub on OST0"
1966                         return 1
1967                 }
1968
1969                 # The oi_scrub should be on ost1, but for test_32(),
1970                 # all on the SINGLEMDS.
1971                 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1972                         osd-ldiskfs.$fsname-OST0000.oi_scrub |
1973                         awk '/^status/ { print \\\$2 }'" "completed" 30 || {
1974                         error_noexit "Failed to get the expected 'completed'"
1975                         return 1
1976                 }
1977
1978                 local UPDATED=$($r $LCTL get_param -n \
1979                                 osd-ldiskfs.$fsname-OST0000.oi_scrub |
1980                                 awk '/^updated/ { print $2 }')
1981                 [ $UPDATED -ge 1 ] || {
1982                         error_noexit "Only $UPDATED objects have been converted"
1983                         return 1
1984                 }
1985         fi
1986
1987         if [ "$dne_upgrade" != "no" ]; then
1988                 if [[ $PERM_CMD = *"set_param -P"* ]]; then
1989                         $r $PERM_CMD mdc.$fsname-MDT0001*.import=connection=$nid || {
1990                                 error_noexit "Setting MDT1 \"failover.node\""
1991                                 return 1
1992                         }
1993
1994                         $r $PERM_CMD mdc.$fsname-MDT0001-*.max_rpcs_in_flight=9 || {
1995                                 error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
1996                                 return 1
1997                         }
1998                         $r $PERM_CMD lov.$fsname-MDT0001-*.stripesize=4M || {
1999                                 error_noexit "Setting MDT1 \"lov.stripesize\""
2000                                 return 1
2001                         }
2002                 else
2003                         $r $PERM_CMD $fsname-MDT0001.failover.node=$nid || {
2004                                 error_noexit "Setting MDT1 \"failover.node\""
2005                                 return 1
2006                         }
2007                         $r $PERM_CMD $fsname-MDT0001.mdc.max_rpcs_in_flight=9 || {
2008                                 error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
2009                                 return 1
2010                         }
2011                         $r $PERM_CMD $fsname-MDT0001.lov.stripesize=4M || {
2012                                 error_noexit "Setting MDT1 \"lov.stripesize\""
2013                                 return 1
2014                         }
2015                 fi
2016         fi
2017
2018         if [ "$writeconf" ]; then
2019                 $MOUNT_CMD $nid:/$fsname $tmp/mnt/lustre || {
2020                         error_noexit "Mounting the client"
2021                         return 1
2022                 }
2023
2024                 shall_cleanup_lustre=true
2025                 $r $LCTL set_param debug="$PTLDEBUG"
2026
2027                 # Leave re-enabling this to a separate patch for LU-11558
2028                 # t32_verify_quota $SINGLEMDS $fsname $tmp/mnt/lustre || {
2029                 #       error_noexit "verify quota failed"
2030                 #       return 1
2031                 #}
2032
2033                 if $r test -f $tmp/list; then
2034                         #
2035                         # There is not a Test Framework API to copy files to or
2036                         # from a remote node.
2037                         #
2038                         # LU-2393 - do both sorts on same node to ensure locale
2039                         # is identical
2040                         local list_file=$tmp/list
2041
2042                         if $mdt2_is_available; then
2043                                 if [[ -d $tmp/mnt/lustre/striped_dir_old ]] &&
2044                                    $r test -f $tmp/list2; then
2045                                         list_file=$tmp/list2
2046                                         pushd $tmp/mnt/lustre/striped_dir_old
2047                                 else
2048                                         pushd $tmp/mnt/lustre/remote_dir
2049                                 fi
2050                         else
2051                                 pushd $tmp/mnt/lustre
2052                         fi
2053                         $r cat $list_file | sort -k 6 >$tmp/list.orig
2054                         ls -Rni --time-style=+%s | sort -k 6 |
2055                                 sed 's/\. / /' >$tmp/list || {
2056                                 error_noexit "ls"
2057                                 return 1
2058                         }
2059                         popd
2060                         #
2061                         # 32-bit and 64-bit clients use different algorithms to
2062                         # convert FIDs into inode numbers.  Hence, remove the
2063                         # inode numbers from the lists, if the original list was
2064                         # created on an architecture with different number of
2065                         # bits per "long".
2066                         #
2067                         if [ $(t32_bits_per_long $(uname -m)) != \
2068                                 $(t32_bits_per_long $img_arch) ]; then
2069                                 echo "Different number of bits per \"long\"" \
2070                                      "from the disk image"
2071                                 for list in list.orig list; do
2072                                         sed -i -e 's/^[0-9]\+[ \t]\+//' \
2073                                                   $tmp/$list
2074                                 done
2075                         fi
2076                         if ! diff -ub $tmp/list.orig $tmp/list; then
2077                                 error_noexit "list verification failed"
2078                                 return 1
2079                         fi
2080                 else
2081                         echo "list verification skipped"
2082                 fi
2083
2084                 if [ "$dom_upgrade" != "no" ]; then
2085                         echo "Check DoM file can be created"
2086                         $LFS setstripe -E 1M -L mdt -E EOF $tmp/mnt/lustre/dom || {
2087                                 error_noexit "Verify DoM creation"
2088                                 return 1
2089                         }
2090                         [ $($LFS getstripe -L $tmp/mnt/lustre/dom) == "mdt" ] || {
2091                                 error_noexit "Verify a DoM file"
2092                                 return 1
2093                         }
2094                         dd if=/dev/urandom of=$tmp/mnt/lustre/dom bs=4096 \
2095                                 count=1 conv=fsync || {
2096                                 error_noexit "Cannot write to DoM file"
2097                                 return 1
2098                         }
2099                         [ $(stat -c%s $tmp/mnt/lustre/dom) == 4096 ] || {
2100                                 error_noexit "DoM: bad size after write"
2101                                 return 1
2102                         }
2103                         rm $tmp/mnt/lustre/dom
2104
2105                         set_persistent_param_and_check mds \
2106                            "lod.*MDT0000*.dom_stripesize" \
2107                            "$fsname-MDT0000.lod.dom_stripesize" 0 || {
2108                                 error_noexit "Changing \"dom_stripesize\""
2109                                 return 1
2110                         }
2111                 fi
2112
2113                 if [ "$dne_upgrade" != "no" ]; then
2114                         $LFS mkdir -i 1 -c2 $tmp/mnt/lustre/striped_dir || {
2115                                 error_noexit "set striped dir failed"
2116                                 return 1
2117                         }
2118
2119                         $LFS setdirstripe -D -c2 $tmp/mnt/lustre/striped_dir
2120
2121                         pushd $tmp/mnt/lustre
2122                         tar -cf - . --exclude=./striped_dir \
2123                                     --exclude=./striped_dir_old \
2124                                     --exclude=./remote_dir |
2125                                 tar -xvf - -C striped_dir 1>/dev/null || {
2126                                 error_noexit "cp to striped dir failed"
2127                                 return 1
2128                         }
2129                         popd
2130                 fi
2131
2132                 # If it is upgrade from DNE (2.5), then rename the remote dir,
2133                 # which is created in 2.5 to striped dir.
2134                 if $mdt2_is_available && [[ "$dne_upgrade" != "no" ]]; then
2135                         stripe_index=$($LFS getdirstripe -i     \
2136                                        $tmp/mnt/lustre/remote_dir)
2137
2138                         [[ $stripe_index -eq 1 ]] || {
2139                                 error_noexit "get index \"$stripe_index\"" \
2140                                              "from remote dir failed"
2141                                 return 1
2142                         }
2143                         mv $tmp/mnt/lustre/remote_dir   \
2144                                 $tmp/mnt/lustre/striped_dir/ || {
2145                                 error_noexit "mv remote dir failed"
2146                                 return 1
2147                         }
2148                 fi
2149
2150                 # If it is upgraded from DNE (2.7), then move the striped dir
2151                 # which was created in 2.7 to the new striped dir.
2152                 if $mdt2_is_available && [[ "$dne_upgrade" != "no" ]] &&
2153                         [[ -d $tmp/mnt/lustre/striped_dir_old ]]; then
2154                         stripe_count=$($LFS getdirstripe -c     \
2155                                        $tmp/mnt/lustre/striped_dir_old)
2156                         [[ $stripe_count -eq 2 ]] || {
2157                                 error_noexit "get count $stripe_count" \
2158                                              "from striped dir failed"
2159                                 return 1
2160                         }
2161                         mv $tmp/mnt/lustre/striped_dir_old      \
2162                                 $tmp/mnt/lustre/striped_dir/ || {
2163                                 error_noexit "mv striped dir failed"
2164                                 return 1
2165                         }
2166                 fi
2167
2168                 sync; sleep 5; sync
2169                 $r $LCTL set_param -n osd*.*.force_sync=1
2170                 dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
2171                         error_noexit "dd failed"
2172                         return 1
2173                 }
2174                 rm -rf $tmp/mnt/lustre/tmp_file || {
2175                         error_noexit "rm failed"
2176                         return 1
2177                 }
2178
2179                 if $r test -f $tmp/sha1sums; then
2180                         # LU-2393 - do both sorts on same node to ensure locale
2181                         # is identical
2182                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
2183                         if [ "$dne_upgrade" != "no" ]; then
2184                                 pushd $tmp/mnt/lustre/striped_dir
2185                         else
2186                                 pushd $tmp/mnt/lustre
2187                         fi
2188
2189                         find ! -path "*remote_dir*" ! -path "*striped_dir*" \
2190                                 ! -name .lustre -type f -exec sha1sum {} \; |
2191                                 sort -k 2 >$tmp/sha1sums || {
2192                                 popd
2193                                 error_noexit "sha1sum"
2194                                 return 1
2195                         }
2196                         popd
2197                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
2198                                 error_noexit "sha1sum verification failed"
2199                                 return 1
2200                         fi
2201
2202                         # if upgrade from DNE(2.5), then check remote directory
2203                         # if upgrade from DNE(2.7), then check striped directory
2204                         if $mdt2_is_available &&
2205                            [[ "$dne_upgrade" != "no" ]]; then
2206                                 local new_dir="$tmp/mnt/lustre/striped_dir"
2207                                 local striped_dir_old="$new_dir/striped_dir_old"
2208
2209                                 local dir_list="$new_dir/remote_dir"
2210                                 [[ ! -d $triped_dir_old ]] ||
2211                                         dir_list+=" $striped_dir_old"
2212
2213                                 for dir in $dir_list; do
2214                                         pushd $dir
2215                                         find ! -name .lustre -type f    \
2216                                                 -exec sha1sum {} \; |
2217                                                 sort -k 2 >$tmp/sha1sums || {
2218                                                         popd
2219                                                         error_noexit "sha1sum"
2220                                                         return 1
2221                                                 }
2222                                         popd
2223                                         if ! diff -ub $tmp/sha1sums.orig \
2224                                                 $tmp/sha1sums; then
2225                                                 error_noexit "sha1sum $dir" \
2226                                                              "failed"
2227                                                 return 1
2228                                         fi
2229                                 done
2230                         fi
2231                 else
2232                         echo "sha1sum verification skipped"
2233                 fi
2234
2235                 if [ "$dne_upgrade" != "no" ]; then
2236                         rm -rf $tmp/mnt/lustre/striped_dir || {
2237                                 error_noexit "remove remote dir failed"
2238                                 return 1
2239                         }
2240                 fi
2241
2242                 # migrate files/dirs to remote MDT, then move them back
2243                 if [ $(lustre_version_code mds1) -ge $(version_code 2.7.50) -a \
2244                      $dne_upgrade != "no" ]; then
2245                         $r $LCTL set_param -n   \
2246                                 mdt.${fsname}*.enable_remote_dir=1 2>/dev/null
2247
2248                         echo "test migration"
2249                         pushd $tmp/mnt/lustre
2250                         for dir in $(find ! -name .lustre ! -name . -type d); do
2251                                 mdt_index=$($LFS getdirstripe -i $dir)
2252                                 stripe_cnt=$($LFS getdirstripe -c $dir)
2253                                 if [ $mdt_index = 0 -a $stripe_cnt -le 1 ]; then
2254                                         $LFS migrate -m 1 $dir || {
2255                                         popd
2256                                         error_noexit "migrate MDT1 failed"
2257                                         return 1
2258                                 }
2259                                 fi
2260                         done
2261
2262                         for dir in $(find ! -name . ! -name .lustre -type d); do
2263                                 mdt_index=$($LFS getdirstripe -i $dir)
2264                                 stripe_cnt=$($LFS getdirstripe -c $dir)
2265                                 if [ $mdt_index = 1 -a $stripe_cnt -le 1 ]; then
2266                                         $LFS migrate -m 0 $dir || {
2267                                         popd
2268                                         error_noexit "migrate MDT0 failed"
2269                                         return 1
2270                                 }
2271                                 fi
2272                         done
2273                         popd
2274                 fi
2275
2276                 #
2277                 # When adding new data verification tests, please check for
2278                 # the presence of the required reference files first, like
2279                 # the "sha1sums" and "list" tests above, to avoid the need to
2280                 # regenerate every image for each test addition.
2281                 #
2282
2283                 nrpcs_orig=$($LCTL get_param \
2284                                 -n mdc.*MDT0000*.max_rpcs_in_flight) || {
2285                         error_noexit "Getting \"max_rpcs_in_flight\""
2286                         return 1
2287                 }
2288                 nrpcs=$((nrpcs_orig + 5))
2289
2290                 set_persistent_param_and_check client \
2291                    "mdc.$fsname-MDT0000*.max_rpcs_in_flight" \
2292                    "$fsname-MDT0000.mdc.max_rpcs_in_flight" $nrpcs || {
2293                         error_noexit "Changing \"max_rpcs_in_flight\""
2294                         return 1
2295                 }
2296
2297                 umount $tmp/mnt/lustre || {
2298                         error_noexit "Unmounting the client"
2299                         return 1
2300                 }
2301                 shall_cleanup_lustre=false
2302         else
2303                 if [[ "$dne_upgrade" != "no" ]] || $mdt2_is_available; then
2304                         $r $UMOUNT $tmp/mnt/mdt1 || {
2305                                 error_noexit "Unmounting the MDT2"
2306                                 return 1
2307                         }
2308                         if [[ $fstype == zfs ]]; then
2309                             $r "$ZPOOL export t32fs-mdt2"
2310                         fi
2311                         shall_cleanup_mdt1=false
2312                 fi
2313
2314                 $r $UMOUNT $tmp/mnt/mdt || {
2315                         error_noexit "Unmounting the MDT"
2316                         return 1
2317                 }
2318                 if [[ $fstype == zfs ]]; then
2319                     $r "$ZPOOL export t32fs-mdt1"
2320                 fi
2321                 shall_cleanup_mdt=false
2322
2323                 $r $UMOUNT $tmp/mnt/ost || {
2324                         error_noexit "Unmounting the OST"
2325                         return 1
2326                 }
2327                 if [[ $fstype == zfs ]]; then
2328                     $r "$ZPOOL export t32fs-ost1"
2329                 fi
2330                 shall_cleanup_ost=false
2331
2332                 t32_reload_modules $node || {
2333                         error_noexit "Reloading modules"
2334                         return 1
2335                 }
2336
2337                 if [[ $fstype == zfs ]]; then
2338                         local poolname=t32fs-mdt1
2339                         $r "modprobe zfs;
2340                             $ZPOOL list -H $poolname >/dev/null 2>&1 ||
2341                                 $ZPOOL import -f -d $tmp $poolname"
2342
2343                         # upgrade zpool to latest supported features,
2344                         # including dnode quota accounting in 0.7.0
2345                         $r "$ZPOOL upgrade $poolname"
2346                 fi
2347
2348                 # mount a second time to make sure we didnt leave upgrade flag on
2349                 $r $TUNEFS --dryrun $mdt_dev || {
2350                         $r losetup -a
2351                         error_noexit "tunefs.lustre before remounting the MDT"
2352                         return 1
2353                 }
2354
2355                 mopts=exclude=$fsname-OST0000
2356                 if [ $fstype == "ldiskfs" ]; then
2357                         mopts="loop,$mopts"
2358                 fi
2359                 $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
2360                         error_noexit "Remounting the MDT"
2361                         return 1
2362                 }
2363                 shall_cleanup_mdt=true
2364         fi
2365 }
2366
2367 test_32a() {
2368         local tarballs
2369         local tarball
2370         local rc=0
2371
2372         t32_check
2373         for tarball in $tarballs; do
2374                 t32_test $tarball || let "rc += $?"
2375         done
2376         return $rc
2377 }
2378 run_test 32a "Upgrade (not live)"
2379
2380 test_32b() {
2381         local tarballs
2382         local tarball
2383         local rc=0
2384
2385         t32_check
2386         for tarball in $tarballs; do
2387                 t32_test $tarball writeconf || let "rc += $?"
2388         done
2389         return $rc
2390 }
2391 run_test 32b "Upgrade with writeconf"
2392
2393 test_32c() {
2394         local tarballs
2395         local tarball
2396         local rc=0
2397
2398         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2399         t32_check
2400         for tarball in $tarballs; do
2401                 # Do not support 1_8 and 2_1 direct upgrade to DNE2 anymore */
2402                 echo $tarball | grep "1_8" && continue
2403                 echo $tarball | grep "2_1" && continue
2404                 load_modules
2405                 dne_upgrade=yes t32_test $tarball writeconf || rc=$?
2406         done
2407         return $rc
2408 }
2409 run_test 32c "dne upgrade test"
2410
2411 test_32d() {
2412         local tarballs
2413         local tarball
2414         local rc=0
2415
2416         t32_check
2417         for tarball in $tarballs; do
2418                 ff_convert=yes t32_test $tarball || rc=$?
2419         done
2420         return $rc
2421 }
2422 run_test 32d "convert ff test"
2423
2424 test_32e() {
2425         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
2426                 { skip "Need MDS version at least 2.10.56"; return 0; }
2427
2428         local tarballs
2429         local tarball
2430         local rc=0
2431
2432         t32_check
2433         for tarball in $tarballs; do
2434                 echo $tarball | grep "2_9" || continue
2435                 #load_modules
2436                 dom_upgrade=yes t32_test $tarball writeconf || let "rc += $?"
2437         done
2438         return $rc
2439 }
2440 run_test 32e "dom upgrade test"
2441
2442 test_33a() { # bug 12333, was test_33
2443         local FSNAME2=test-123
2444         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2445         local mkfsoptions
2446
2447         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
2448
2449         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
2450                 local dev=${SINGLEMDS}_dev
2451                 local MDSDEV=${!dev}
2452                 is_blkdev $SINGLEMDS $MDSDEV &&
2453                         skip_env "mixed loopback and real device not working" &&
2454                         return
2455         fi
2456
2457         local fs2mdsdev=$(mdsdevname 1_2)
2458         local fs2ostdev=$(ostdevname 1_2)
2459         local fs2mdsvdev=$(mdsvdevname 1_2)
2460         local fs2ostvdev=$(ostvdevname 1_2)
2461
2462         if [ $(facet_fstype mds1) == ldiskfs ]; then
2463                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
2464         fi
2465
2466         if combined_mgs_mds; then
2467                 local mgs_flag="--mgs"
2468         fi
2469
2470         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --fsname=${FSNAME2} \
2471                 --reformat $mgs_flag $mkfsoptions $fs2mdsdev $fs2mdsvdev ||
2472                 exit 10
2473         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2474                 --fsname=${FSNAME2} --index=8191 --reformat $fs2ostdev \
2475                 $fs2ostvdev || exit 10
2476
2477         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
2478         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2479
2480         if [[ $PERM_CMD = *"set_param -P"* ]]; then
2481                 do_facet mgs "$PERM_CMD timeout=200" ||
2482                         error "$PERM_CMD timeout=200 failed"
2483         else
2484                 do_facet mgs "$PERM_CMD $FSNAME2.sys.timeout=200" ||
2485                         error "$PERM_CMD $FSNAME2.sys.timeout=200 failed"
2486         fi
2487         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
2488         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
2489         echo "ok."
2490
2491         cp /etc/hosts $MOUNT2/ || error "copy /etc/hosts $MOUNT2/ failed"
2492         $GETSTRIPE $MOUNT2/hosts || error "$GETSTRIPE $MOUNT2/hosts failed"
2493
2494         umount $MOUNT2
2495         stop fs2ost -f
2496         stop fs2mds -f
2497         cleanup_nocli || error "cleanup_nocli failed with $?"
2498 }
2499 run_test 33a "Mount ost with a large index number"
2500
2501 test_33b() {    # was test_34
2502         setup
2503
2504         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
2505         # Drop lock cancelation reply during umount
2506         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
2507         do_facet client $LCTL set_param fail_loc=0x80000304
2508         #lctl set_param debug=-1
2509         umount_client $MOUNT
2510         cleanup || error "cleanup failed with $?"
2511 }
2512 run_test 33b "Drop cancel during umount"
2513
2514 test_34a() {
2515         setup
2516         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
2517         manual_umount_client
2518         rc=$?
2519         do_facet client killall -USR1 multiop
2520         if [ $rc -eq 0 ]; then
2521                 error "umount not fail!"
2522         fi
2523         sleep 1
2524         cleanup || error "cleanup failed with rc $?"
2525 }
2526 run_test 34a "umount with opened file should be fail"
2527
2528 test_34b() {
2529         setup
2530         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2531         stop_mds || error "Unable to stop MDS"
2532
2533         manual_umount_client --force || error "mtab after failed umount with $?"
2534
2535         cleanup || error "cleanup failed with $?"
2536 }
2537 run_test 34b "force umount with failed mds should be normal"
2538
2539 test_34c() {
2540         setup
2541         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2542         stop_ost || error "Unable to stop OST1"
2543
2544         manual_umount_client --force || error "mtab after failed umount with $?"
2545
2546         cleanup || error "cleanup failed with $?"
2547 }
2548 run_test 34c "force umount with failed ost should be normal"
2549
2550 test_35a() { # bug 12459
2551         setup
2552
2553         DBG_SAVE="`$LCTL get_param -n debug`"
2554         $LCTL set_param debug="ha"
2555
2556         log "Set up a fake failnode for the MDS"
2557         FAKENID="127.0.0.2"
2558         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2559                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2560
2561         if [[ $PERM_CMD = *"set_param -P"* ]]; then
2562                 do_facet mgs "$PERM_CMD \
2563                               mdc.*${device}*.import=connection=$(h2nettype $FAKENID)" ||
2564                         error "Setting mdc.*${device}*.import=connection=\
2565                                $(h2nettype $FAKENID) failed."
2566         else
2567                 do_facet mgs "$PERM_CMD \
2568                               ${device}.failover.node=$(h2nettype $FAKENID)" ||
2569                         error "Setting ${device}.failover.node=\
2570                                $(h2nettype $FAKENID) failed."
2571         fi
2572         log "Wait for RECONNECT_INTERVAL seconds (10s)"
2573         sleep 10
2574
2575         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
2576         $LCTL clear
2577         log "$MSG"
2578         log "Stopping the MDT: $device"
2579         stop_mdt 1 || error "MDT0 stop fail"
2580
2581         df $MOUNT > /dev/null 2>&1 &
2582         DFPID=$!
2583         log "Restarting the MDT: $device"
2584         start_mdt 1 || error "MDT0 start fail"
2585         log "Wait for df ($DFPID) ... "
2586         wait $DFPID
2587         log "done"
2588         $LCTL set_param debug="$DBG_SAVE"
2589
2590         # retrieve from the log the first server that the client tried to
2591         # contact after the connection loss
2592         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2593         NEXTCONN=`awk "/${MSG}/ {start = 1;}
2594                        /import_select_connection.*$device-mdc.* using connection/ {
2595                                 if (start) {
2596                                         if (\\\$NF ~ /$FAKENID/)
2597                                                 print \\\$NF;
2598                                         else
2599                                                 print 0;
2600                                         exit;
2601                                 }
2602                        }" $TMP/lustre-log-$TESTNAME.log`
2603         [ "$NEXTCONN" != "0" ] &&
2604                 error "Tried to connect to ${NEXTCONN} not last active server"
2605         cleanup || error "cleanup failed with $?"
2606         # remove nid settings
2607         writeconf_or_reformat
2608 }
2609 run_test 35a "Reconnect to the last active server first"
2610
2611 test_35b() { # bug 18674
2612         remote_mds || { skip "local MDS" && return 0; }
2613         setup
2614
2615         debugsave
2616         $LCTL set_param debug="ha"
2617         $LCTL clear
2618         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
2619         log "$MSG"
2620
2621         log "Set up a fake failnode for the MDS"
2622         FAKENID="127.0.0.2"
2623         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2624                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2625
2626         if [[ $PERM_CMD = *"set_param -P"* ]]; then
2627                 do_facet mgs "$PERM_CMD \
2628                               mdc.*${device}*.import=connection=$(h2nettype $FAKENID)" ||
2629                         error "Set mdc.*${device}*.import=connection=\
2630                                $(h2nettype $FAKENID) failed"
2631         else
2632                 do_facet mgs "$PERM_CMD \
2633                               ${device}.failover.node=$(h2nettype $FAKENID)" ||
2634                         error "Set ${device}.failover.node=\
2635                                $(h2nettype $FAKENID) failed"
2636         fi
2637
2638         local at_max_saved=0
2639         # adaptive timeouts may prevent seeing the issue
2640         if at_is_enabled; then
2641                 at_max_saved=$(at_max_get mds)
2642                 at_max_set 0 mds client
2643         fi
2644
2645         mkdir $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
2646
2647         log "Injecting EBUSY on MDS"
2648         # Setting OBD_FAIL_MDS_RESEND=0x136
2649         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" ||
2650                 error "unable to set param fail_loc=0x80000136"
2651
2652         $LCTL set_param mdc.${FSNAME}*.stats=clear
2653
2654         log "Creating a test file and stat it"
2655         touch $MOUNT/$tdir/$tfile || error "touch $MOUNT/$tdir/$tfile failed"
2656         stat $MOUNT/$tdir/$tfile
2657
2658         log "Stop injecting EBUSY on MDS"
2659         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" ||
2660                 error "unable to set param fail_loc=0"
2661         rm -f $MOUNT/$tdir/$tfile || error "remove $MOUNT/$tdir/$tfile failed"
2662
2663         log "done"
2664         # restore adaptive timeout
2665         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
2666
2667         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2668
2669         CONNCNT=$($LCTL get_param mdc.${FSNAME}*.stats |
2670                   awk '/mds_connect/{print $2}')
2671
2672         # retrieve from the log if the client has ever tried to
2673         # contact the fake server after the loss of connection
2674         FAILCONN=`awk "BEGIN {ret = 0;}
2675                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
2676                                 ret = 1;
2677                                 if (\\\$NF ~ /$FAKENID/) {
2678                                         ret = 2;
2679                                         exit;
2680                                 }
2681                        }
2682                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
2683
2684         [ "$FAILCONN" == "0" ] &&
2685                 error "The client reconnection has not been triggered"
2686         [ "$FAILCONN" == "2" ] &&
2687                 error "Primary server busy, client reconnect to failover failed"
2688
2689         # LU-290
2690         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
2691         # Reconnects are supposed to be rate limited to one every 5s
2692         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] &&
2693                 error "Too many reconnects $CONNCNT"
2694
2695         cleanup || error "cleanup failed with $?"
2696         # remove nid settings
2697         writeconf_or_reformat
2698 }
2699 run_test 35b "Continue reconnection retries, if the active server is busy"
2700
2701 test_36() { # 12743
2702         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs" && return
2703
2704         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] ||
2705                 { skip "remote OST" && return 0; }
2706
2707         local rc=0
2708         local FSNAME2=test1234
2709         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2710
2711         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
2712
2713         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
2714                 is_blkdev $SINGLEMDS $MDSDEV &&
2715                 skip_env "mixed loopback and real device not working" && return
2716         fi
2717
2718         local fs2mdsdev=$(mdsdevname 1_2)
2719         local fs2ostdev=$(ostdevname 1_2)
2720         local fs3ostdev=$(ostdevname 2_2)
2721         local fs2mdsvdev=$(mdsvdevname 1_2)
2722         local fs2ostvdev=$(ostvdevname 1_2)
2723         local fs3ostvdev=$(ostvdevname 2_2)
2724
2725         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2726                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
2727         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
2728         #     different one than the default value here.
2729         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2730                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
2731         add fs3ost $(mkfs_opts ost2 ${fs3ostdev}) --mgsnode=$MGSNID \
2732                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
2733
2734         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
2735         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2736         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
2737         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
2738         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
2739
2740         sleep 5 # until 11778 fixed
2741
2742         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || error "dd failed"
2743
2744         BKTOTAL=$($LCTL get_param -n obdfilter.*.kbytestotal |
2745                   awk 'BEGIN{total=0}; {total+=$1}; END{print total}')
2746         BKFREE=$($LCTL get_param -n obdfilter.*.kbytesfree |
2747                  awk 'BEGIN{free=0}; {free+=$1}; END{print free}')
2748         BKAVAIL=$($LCTL get_param -n obdfilter.*.kbytesavail |
2749                   awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
2750         STRING=$(df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}')
2751         DFTOTAL=$(echo $STRING | cut -d, -f1)
2752         DFUSED=$(echo $STRING  | cut -d, -f2)
2753         DFAVAIL=$(echo $STRING | cut -d, -f3)
2754         DFFREE=$(($DFTOTAL - $DFUSED))
2755
2756         ALLOWANCE=$((64 * $OSTCOUNT))
2757
2758         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
2759            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
2760                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
2761                 rc=1
2762         fi
2763         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
2764            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
2765                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
2766                 rc=2
2767         fi
2768         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
2769            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
2770                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
2771                 rc=3
2772        fi
2773
2774         $UMOUNT $MOUNT2
2775         stop fs3ost -f || error "unable to stop OST3"
2776         stop fs2ost -f || error "unable to stop OST2"
2777         stop fs2mds -f || error "unable to stop second MDS"
2778         unload_modules_conf || error "unable unload modules"
2779         return $rc
2780 }
2781 run_test 36 "df report consistency on OSTs with different block size"
2782
2783 test_37() {
2784         local mntpt=$(facet_mntpt $SINGLEMDS)
2785         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
2786         local mdsdev_sym="$TMP/sym_mdt.img"
2787         local opts=$MDS_MOUNT_OPTS
2788         local rc=0
2789
2790         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2791                 skip "ldiskfs only test"
2792                 return
2793         fi
2794
2795         echo "MDS :     $mdsdev"
2796         echo "SYMLINK : $mdsdev_sym"
2797         do_facet $SINGLEMDS rm -f $mdsdev_sym
2798
2799         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
2800
2801         echo "mount symlink device - $mdsdev_sym"
2802
2803         if ! do_facet $SINGLEMDS test -b $mdsdev; then
2804                 opts=$(csa_add "$opts" -o loop)
2805         fi
2806         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
2807                 $mdsdev_sym $mntpt 2>&1)
2808         rc=${PIPESTATUS[0]}
2809
2810         echo mount_op=$mount_op
2811
2812         do_facet $SINGLEMDS "$UMOUNT $mntpt && rm -f $mdsdev_sym"
2813
2814         if $(echo $mount_op | grep -q "unable to set tunable"); then
2815                 error "set tunables failed for symlink device"
2816         fi
2817
2818         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
2819 }
2820 run_test 37 "verify set tunables works for symlink device"
2821
2822 test_38() { # bug 14222
2823         local fstype=$(facet_fstype $SINGLEMDS)
2824         local mntpt=$(facet_mntpt $SINGLEMDS)
2825
2826         setup
2827         # like runtests
2828         local COUNT=10
2829         local SRC="/etc /bin"
2830         local FILES=$(find $SRC -type f -mtime +1 | head -n $COUNT)
2831         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
2832         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2833         tar cf - $FILES | tar xf - -C $DIR/$tdir ||
2834                 error "copying $SRC to $DIR/$tdir"
2835         sync
2836         umount_client $MOUNT || error "umount_client $MOUNT failed"
2837         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2838         stop_mds || error "Unable to stop MDS"
2839         log "delete lov_objid file on MDS"
2840
2841         mount_fstype $SINGLEMDS || error "mount MDS failed (1)"
2842
2843         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid; rm $mntpt/lov_objid"
2844
2845         unmount_fstype $SINGLEMDS || error "umount failed (1)"
2846
2847         # check create in mds_lov_connect
2848         start_mds || error "unable to start MDS"
2849         mount_client $MOUNT || error "mount_client $MOUNT failed"
2850         for f in $FILES; do
2851                 [ $V ] && log "verifying $DIR/$tdir/$f"
2852                 diff -q $f $DIR/$tdir/$f || ERROR=y
2853         done
2854         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2855         if [ "$ERROR" = "y" ]; then
2856                 # check it's updates in sync
2857                 umount_client $MOUNT
2858                 stop_mds
2859                 mount_fstype $SIGNLEMDS
2860                 do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2861                 unmount_fstype $SINGLEMDS
2862                 error "old and new files are different after connect" || true
2863         fi
2864         touch $DIR/$tdir/f2 || error "f2 file create failed"
2865
2866         # check it's updates in sync
2867         umount_client $MOUNT || error "second umount_client $MOUNT failed"
2868         stop_mds
2869
2870         mount_fstype $SINGLEMDS || error "mount MDS failed (3)"
2871
2872         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2873         do_facet $SINGLEMDS dd if=/dev/zero of=$mntpt/lov_objid.clear count=8
2874
2875         unmount_fstype $SINGLEMDS || error "umount failed (3)"
2876
2877         start_mds || error "unable to start MDS"
2878         mount_client $MOUNT || error "mount_client $MOUNT failed"
2879         for f in $FILES; do
2880                 [ $V ] && log "verifying $DIR/$tdir/$f"
2881                 diff -q $f $DIR/$tdir/$f || ERROR=y
2882         done
2883         touch $DIR/$tdir/f3 || error "f3 file create failed"
2884         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2885         umount_client $MOUNT || error "third umount_client $MOUNT failed"
2886         stop_mds
2887         mount_fstype $SINGLEMDS || error "mount MDS failed (4)"
2888         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2889         unmount_fstype $SINGLEMDS || error "umount failed (4)"
2890
2891         [ "$ERROR" = "y" ] &&
2892                 error "old and new files are different after sync" || true
2893
2894         log "files compared the same"
2895         cleanup || error "cleanup failed with $?"
2896 }
2897 run_test 38 "MDS recreates missing lov_objid file from OST data"
2898
2899 test_39() {
2900         PTLDEBUG=+malloc
2901         setup
2902         cleanup || error "cleanup failed with $?"
2903         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2904                 error "memory leak detected" || true
2905 }
2906 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2907
2908 test_40() { # bug 15759
2909         start_ost || error "Unable to start OST1"
2910         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2911         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2912         start_mds
2913         cleanup || error "cleanup failed with rc $?"
2914 }
2915 run_test 40 "race during service thread startup"
2916
2917 test_41a() { #bug 14134
2918         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2919            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2920                 skip "Loop devices does not work with nosvc option"
2921                 return
2922         fi
2923
2924         combined_mgs_mds ||
2925                 { skip "needs combined MGT and MDT device" && return 0; }
2926
2927         start_mdt 1 -o nosvc -n
2928         if [ $MDSCOUNT -ge 2 ]; then
2929                 for num in $(seq 2 $MDSCOUNT); do
2930                         start_mdt $num || return
2931                 done
2932         fi
2933         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
2934         start_mdt 1 -o nomgs,force
2935         mount_client $MOUNT || error "mount_client $MOUNT failed"
2936         sleep 5
2937
2938         echo "blah blah" > $MOUNT/$tfile
2939         cat $MOUNT/$tfile
2940
2941         umount_client $MOUNT || error "umount_client $MOUNT failed"
2942         stop ost1 -f || error "unable to stop OST1"
2943         stop_mds || error "Unable to stop MDS"
2944         stop_mds || error "Unable to stop MDS on second try"
2945 }
2946 run_test 41a "mount mds with --nosvc and --nomgs"
2947
2948 test_41b() {
2949         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2950            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2951                 skip "Loop devices does not work with nosvc option"
2952                 return
2953         fi
2954
2955         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2956
2957         stopall
2958         reformat
2959         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2960
2961         start_mdt 1 -o nosvc -n
2962         if [ $MDSCOUNT -ge 2 ]; then
2963                 for num in $(seq 2 $MDSCOUNT); do
2964                         start_mdt $num || return
2965                 done
2966         fi
2967         start_ost || error "Unable to start OST1"
2968         start_mdt 1 -o nomgs,force
2969         mount_client $MOUNT || error "mount_client $MOUNT failed"
2970         sleep 5
2971
2972         echo "blah blah" > $MOUNT/$tfile
2973         cat $MOUNT/$tfile || error "cat $MOUNT/$tfile failed"
2974
2975         umount_client $MOUNT -f || error "umount_client $MOUNT failed"
2976         stop_ost || error "Unable to stop OST1"
2977         stop_mds || error "Unable to stop MDS"
2978         stop_mds || error "Unable to stop MDS on second try"
2979 }
2980 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2981
2982 test_41c() {
2983         local server_version=$(lustre_version_code $SINGLEMDS)
2984         local oss_list=$(comma_list $(osts_nodes))
2985
2986         [[ $server_version -ge $(version_code 2.6.52) ]] ||
2987         [[ $server_version -ge $(version_code 2.5.26) &&
2988            $server_version -lt $(version_code 2.5.50) ]] ||
2989         [[ $server_version -ge $(version_code 2.5.4) &&
2990            $server_version -lt $(version_code 2.5.11) ]] ||
2991                 { skip "Need MDS version 2.5.4+ or 2.5.26+ or 2.6.52+"; return; }
2992
2993         # ensure mds1 ost1 have been created even if running sub-test standalone
2994         cleanup
2995         setup
2996         cleanup || error "cleanup failed"
2997
2998         # using directly mount command instead of start() function to avoid
2999         # any side effect of // with others/externals tools/features
3000         # ("zpool import", ...)
3001
3002         # MDT concurrent start
3003
3004         LOAD_MODULES_REMOTE=true load_modules
3005         do_facet $SINGLEMDS "lsmod | grep -q libcfs" ||
3006                 error "MDT concurrent start: libcfs module not loaded"
3007
3008         local mds1dev=$(mdsdevname 1)
3009         local mds1mnt=$(facet_mntpt mds1)
3010         local mds1fstype=$(facet_fstype mds1)
3011         local mds1opts=$MDS_MOUNT_OPTS
3012
3013         if [ $mds1fstype == ldiskfs ] &&
3014            ! do_facet mds1 test -b $mds1dev; then
3015                 mds1opts=$(csa_add "$mds1opts" -o loop)
3016         fi
3017         if [[ $mds1fstype == zfs ]]; then
3018                 import_zpool mds1 || return ${PIPESTATUS[0]}
3019         fi
3020
3021         #define OBD_FAIL_TGT_MOUNT_RACE 0x716
3022         do_facet mds1 "$LCTL set_param fail_loc=0x80000716"
3023
3024         do_facet mds1 mount -t lustre $mds1dev $mds1mnt $mds1opts &
3025         local pid=$!
3026
3027         do_facet mds1 mount -t lustre $mds1dev $mds1mnt $mds1opts
3028         local rc2=$?
3029         wait $pid
3030         local rc=$?
3031         do_facet mds1 "$LCTL set_param fail_loc=0x0"
3032         if [ $rc -eq 0 ] && [ $rc2 -ne 0 ]; then
3033                 echo "1st MDT start succeed"
3034                 echo "2nd MDT start failed with $rc2"
3035         elif [ $rc2 -eq 0 ] && [ $rc -ne 0 ]; then
3036                 echo "1st MDT start failed with $rc"
3037                 echo "2nd MDT start succeed"
3038         else
3039                 stop mds1 -f
3040                 error "unexpected concurrent MDT mounts result, rc=$rc rc2=$rc2"
3041         fi
3042
3043         if [ $MDSCOUNT -ge 2 ]; then
3044                 for num in $(seq 2 $MDSCOUNT); do
3045                         start_mdt $num || return
3046                 done
3047         fi
3048
3049         # OST concurrent start
3050
3051         do_rpc_nodes $oss_list "lsmod | grep -q libcfs" ||
3052                 error "OST concurrent start: libcfs module not loaded"
3053
3054         local ost1dev=$(ostdevname 1)
3055         local ost1mnt=$(facet_mntpt ost1)
3056         local ost1fstype=$(facet_fstype ost1)
3057         local ost1opts=$OST_MOUNT_OPTS
3058
3059         if [ $ost1fstype == ldiskfs ] &&
3060            ! do_facet ost1 test -b $ost1dev; then
3061                 ost1opts=$(csa_add "$ost1opts" -o loop)
3062         fi
3063         if [[ $ost1fstype == zfs ]]; then
3064                 import_zpool ost1 || return ${PIPESTATUS[0]}
3065         fi
3066
3067         #define OBD_FAIL_TGT_MOUNT_RACE 0x716
3068         do_facet ost1 "$LCTL set_param fail_loc=0x80000716"
3069
3070         do_facet ost1 mount -t lustre $ost1dev $ost1mnt $ost1opts &
3071         pid=$!
3072
3073         do_facet ost1 mount -t lustre $ost1dev $ost1mnt $ost1opts
3074         rc2=$?
3075         wait $pid
3076         rc=$?
3077         do_facet ost1 "$LCTL set_param fail_loc=0x0"
3078         if [ $rc -eq 0 ] && [ $rc2 -ne 0 ]; then
3079                 echo "1st OST start succeed"
3080                 echo "2nd OST start failed with $rc2"
3081         elif [ $rc2 -eq 0 ] && [ $rc -ne 0 ]; then
3082                 echo "1st OST start failed with $rc"
3083                 echo "2nd OST start succeed"
3084         else
3085                 stop_mds -f
3086                 stop ost1 -f
3087                 error "unexpected concurrent OST mounts result, rc=$rc rc2=$rc2"
3088         fi
3089         # cleanup
3090         stop_mds
3091         stop ost1 -f
3092
3093         # verify everything ok
3094         start_mds
3095         if [ $? != 0 ]
3096         then
3097                 stop_mds
3098                 error "MDT(s) start failed"
3099         fi
3100
3101         start_ost
3102         if [ $? != 0 ]
3103         then
3104                 stop_mds
3105                 stop ost1 -f
3106                 error "OST(s) start failed"
3107         fi
3108
3109         mount_client $MOUNT
3110         if [ $? != 0 ]
3111         then
3112                 stop_mds
3113                 stop ost1 -f
3114                 error "client start failed"
3115         fi
3116         check_mount
3117         if [ $? != 0 ]
3118         then
3119                 stop_mds
3120                 stop ost1 -f
3121                 error "client mount failed"
3122         fi
3123         cleanup
3124 }
3125 run_test 41c "concurrent mounts of MDT/OST should all fail but one"
3126
3127 test_42() { #bug 14693
3128         local PARAM
3129
3130         setup
3131         check_mount || error "client was not mounted"
3132
3133         if [[ $PERM_CMD = *"set_param -P"* ]]; then
3134                 PARAM="llite.$FSNAME-*.some_wrong_param"
3135         else
3136                 PARAM="$FSNAME.llite.some_wrong_param"
3137         fi
3138
3139         do_facet mgs $PERM_CMD $PARAM=10
3140         umount_client $MOUNT ||
3141                 error "unmounting client failed with invalid llite param"
3142         mount_client $MOUNT ||
3143                 error "mounting client failed with invalid llite param"
3144
3145         do_facet mgs $PERM_CMD $PARAM=20
3146         cleanup || error "stopping $FSNAME failed with invalid sys param"
3147         setup
3148         check_mount || error "client was not mounted with invalid sys param"
3149         cleanup || error "stopping $FSNAME failed with invalid sys param"
3150 }
3151 run_test 42 "allow client/server mount/unmount with invalid config param"
3152
3153 test_43a() {
3154         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.58) ]] ||
3155                 { skip "Need MDS version at least 2.5.58" && return 0; }
3156         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
3157
3158         ID1=${ID1:-501}
3159         USER1=$(getent passwd | grep :$ID1:$ID1: | cut -d: -f1)
3160         [ -z "$USER1" ] && skip_env "missing user with uid=$ID1 gid=$ID1" &&
3161                 return
3162
3163         setup
3164         chmod ugo+x $DIR || error "chmod 0 failed"
3165         set_persistent_param_and_check mds1                             \
3166                 "mdt.$FSNAME-MDT0000.root_squash"                       \
3167                 "$FSNAME.mdt.root_squash"                               \
3168                 "0:0"
3169         wait_update $HOSTNAME                                           \
3170                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
3171                 "0:0" ||
3172                 error "check llite root_squash failed!"
3173         set_persistent_param_and_check mds1                             \
3174                 "mdt.$FSNAME-MDT0000.nosquash_nids"                     \
3175                 "$FSNAME.mdt.nosquash_nids"                             \
3176                 "NONE"
3177         wait_update $HOSTNAME                                           \
3178                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
3179                 "NONE" ||
3180                 error "check llite nosquash_nids failed!"
3181
3182         #
3183         # create set of test files
3184         #
3185         echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
3186         chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
3187         chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
3188
3189         echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
3190         chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
3191
3192         mkdir $DIR/$tdir-rootdir || error "mkdir failed"
3193         chmod go-rwx $DIR/$tdir-rootdir || error "chmod 3 failed"
3194         touch $DIR/$tdir-rootdir/tfile-1 || error "touch failed"
3195
3196         echo "777" > $DIR/$tfile-user1file || error "write 7 failed"
3197         chmod go-rw $DIR/$tfile-user1file || error "chmod 7 failed"
3198         chown $ID1.$ID1 $DIR/$tfile-user1file || error "chown failed"
3199
3200         #
3201         # check root_squash:
3202         #   set root squash UID:GID to RUNAS_ID
3203         #   root should be able to access only files owned by RUNAS_ID
3204         #
3205         set_persistent_param_and_check mds1                             \
3206                 "mdt.$FSNAME-MDT0000.root_squash"                       \
3207                 "$FSNAME.mdt.root_squash"                               \
3208                 "$RUNAS_ID:$RUNAS_ID"
3209         wait_update $HOSTNAME                                           \
3210                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
3211                 "$RUNAS_ID:$RUNAS_ID" ||
3212                 error "check llite root_squash failed!"
3213
3214         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
3215         dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
3216                 error "$ST: root read permission is denied"
3217         echo "$ST: root read permission is granted - ok"
3218
3219         echo "444" |
3220         dd conv=notrunc of=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
3221                 error "$ST: root write permission is denied"
3222         echo "$ST: root write permission is granted - ok"
3223
3224         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
3225         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
3226                 error "$ST: root read permission is granted"
3227         echo "$ST: root read permission is denied - ok"
3228
3229         echo "555" |
3230         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
3231                 error "$ST: root write permission is granted"
3232         echo "$ST: root write permission is denied - ok"
3233
3234         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
3235                 rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null &&
3236                         error "$ST: root unlink permission is granted"
3237         echo "$ST: root unlink permission is denied - ok"
3238
3239         touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null &&
3240                 error "$ST: root create permission is granted"
3241         echo "$ST: root create permission is denied - ok"
3242
3243         # LU-1778
3244         # check root_squash is enforced independently
3245         # of client cache content
3246         #
3247         # access file by USER1, keep access open
3248         # root should be denied access to user file
3249
3250         runas -u $ID1 tail -f $DIR/$tfile-user1file 1>/dev/null 2>&1 &
3251         pid=$!
3252         sleep 1
3253
3254         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-user1file)
3255         dd if=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
3256             { kill $pid; error "$ST: root read permission is granted"; }
3257         echo "$ST: root read permission is denied - ok"
3258
3259         echo "777" |
3260         dd conv=notrunc of=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
3261             { kill $pid; error "$ST: root write permission is granted"; }
3262         echo "$ST: root write permission is denied - ok"
3263
3264         kill $pid
3265         wait $pid
3266
3267         #
3268         # check nosquash_nids:
3269         #   put client's NID into nosquash_nids list,
3270         #   root should be able to access root file after that
3271         #
3272         local NIDLIST=$($LCTL list_nids all | tr '\n' ' ')
3273         NIDLIST="2@gni $NIDLIST 192.168.0.[2,10]@tcp"
3274         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
3275         set_persistent_param_and_check mds1                             \
3276                 "mdt.$FSNAME-MDT0000.nosquash_nids"                     \
3277                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
3278                 "$NIDLIST"
3279         wait_update $HOSTNAME                                           \
3280                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
3281                 "$NIDLIST" ||
3282                 error "check llite nosquash_nids failed!"
3283
3284         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
3285         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
3286                 error "$ST: root read permission is denied"
3287         echo "$ST: root read permission is granted - ok"
3288
3289         echo "666" |
3290         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
3291                 error "$ST: root write permission is denied"
3292         echo "$ST: root write permission is granted - ok"
3293
3294         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
3295         rm $DIR/$tdir-rootdir/tfile-1 ||
3296                 error "$ST: root unlink permission is denied"
3297         echo "$ST: root unlink permission is granted - ok"
3298         touch $DIR/$tdir-rootdir/tfile-2 ||
3299                 error "$ST: root create permission is denied"
3300         echo "$ST: root create permission is granted - ok"
3301         cleanup || error "cleanup failed with $?"
3302 }
3303 run_test 43a "check root_squash and nosquash_nids"
3304
3305 test_43b() { # LU-5690
3306         [[ $(lustre_version_code mgs) -ge $(version_code 2.7.62) ]] ||
3307                 { skip "Need MGS version 2.7.62+"; return; }
3308
3309         if [[ -z "$fs2mds_DEV" ]]; then
3310                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
3311                 skip_env "mixed loopback and real device not working" && return
3312         fi
3313
3314         local fs2mdsdev=$(mdsdevname 1_2)
3315         local fs2mdsvdev=$(mdsvdevname 1_2)
3316
3317         # temporarily use fs2mds as fs2mgs
3318         local fs2mgs=fs2mds
3319         local fs2mgsdev=$fs2mdsdev
3320         local fs2mgsvdev=$fs2mdsvdev
3321
3322         local fsname=test1234
3323
3324         load_module llite/lustre
3325         local client_ip=$(host_nids_address $HOSTNAME $NETTYPE)
3326         local host=${client_ip//*./}
3327         local net=${client_ip/%$host/}
3328         local nosquash_nids=$(h2nettype $net[$host,$host,$host])
3329
3330         add $fs2mgs $(mkfs_opts mgs $fs2mgsdev) --fsname=$fsname \
3331                 --param mdt.root_squash=$RUNAS_ID:$RUNAS_ID \
3332                 --param mdt.nosquash_nids=$nosquash_nids \
3333                 --reformat $fs2mgsdev $fs2mgsvdev || error "add fs2mgs failed"
3334         start $fs2mgs $fs2mgsdev $MGS_MOUNT_OPTS  || error "start fs2mgs failed"
3335         stop $fs2mgs -f || error "stop fs2mgs failed"
3336         cleanup || error "cleanup failed with $?"
3337 }
3338 run_test 43b "parse nosquash_nids with commas in expr_list"
3339
3340 test_44() { # 16317
3341         setup
3342         check_mount || error "check_mount"
3343         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
3344         STATS_FOUND=no
3345         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
3346         for VAL in $UUIDS; do
3347                 NID=$(echo $VAL | cut -d= -f1)
3348                 CLUUID=$(echo $VAL | cut -d= -f2)
3349                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
3350         done
3351         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
3352         cleanup || error "cleanup failed with $?"
3353 }
3354 run_test 44 "mounted client proc entry exists"
3355
3356 test_45() { #17310
3357         setup
3358         check_mount || error "check_mount"
3359         stop_mds || error "Unable to stop MDS"
3360         df -h $MOUNT &
3361         log "sleep 60 sec"
3362         sleep 60
3363         #define OBD_FAIL_PTLRPC_LONG_REPL_UNLINK        0x50f
3364         do_facet client "$LCTL set_param fail_loc=0x8000050f"
3365         log "sleep 10 sec"
3366         sleep 10
3367         manual_umount_client --force || error "manual_umount_client failed"
3368         do_facet client "$LCTL set_param fail_loc=0x0"
3369         start_mds || error "unable to start MDS"
3370         mount_client $MOUNT || error "mount_client $MOUNT failed"
3371         cleanup || error "cleanup failed with $?"
3372 }
3373 run_test 45 "long unlink handling in ptlrpcd"
3374
3375 cleanup_46a() {
3376         trap 0
3377         local rc=0
3378         local count=$1
3379
3380         umount_client $MOUNT2 || rc=$?
3381         umount_client $MOUNT || rc=$?
3382         while [ $count -gt 0 ]; do
3383                 stop ost${count} -f || rc=$?
3384                 let count=count-1
3385         done
3386         stop_mds || rc=$?
3387         cleanup_nocli || rc=$?
3388         #writeconf to remove all ost2 traces for subsequent tests
3389         writeconf_or_reformat
3390         return $rc
3391 }
3392
3393 test_46a() {
3394         echo "Testing with $OSTCOUNT OSTs"
3395         reformat_and_config
3396         start_mds || error "unable to start MDS"
3397         #first client should see only one ost
3398         start_ost || error "Unable to start OST1"
3399         wait_osc_import_state mds ost FULL
3400         #start_client
3401         mount_client $MOUNT || error "mount_client $MOUNT failed"
3402         trap "cleanup_46a $OSTCOUNT" EXIT ERR
3403
3404         local i
3405         for (( i=2; i<=$OSTCOUNT; i++ )); do
3406                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
3407                         error "start_ost$i $(ostdevname $i) failed"
3408         done
3409
3410         # wait until osts in sync
3411         for (( i=2; i<=$OSTCOUNT; i++ )); do
3412             wait_osc_import_state mds ost$i FULL
3413             wait_osc_import_ready client ost$i
3414         done
3415
3416         #second client see all ost's
3417
3418         mount_client $MOUNT2 || error "mount_client failed"
3419         $SETSTRIPE -c -1 $MOUNT2 || error "$SETSTRIPE -c -1 $MOUNT2 failed"
3420         $GETSTRIPE $MOUNT2 || error "$GETSTRIPE $MOUNT2 failed"
3421
3422         echo "ok" > $MOUNT2/widestripe
3423         $GETSTRIPE $MOUNT2/widestripe ||
3424                 error "$GETSTRIPE $MOUNT2/widestripe failed"
3425         # fill acl buffer for avoid expand lsm to them
3426         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd |
3427                 while read acl; do
3428             setfacl -m $acl $MOUNT2/widestripe
3429         done
3430
3431         # will be deadlock
3432         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
3433
3434         cleanup_46a $OSTCOUNT || error "cleanup_46a failed"
3435 }
3436 run_test 46a "handle ost additional - wide striped file"
3437
3438 test_47() { #17674
3439         reformat
3440         setup_noconfig
3441         check_mount || error "check_mount failed"
3442         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
3443
3444         local lru_size=[]
3445         local count=0
3446         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
3447             if echo $ns | grep "MDT[[:digit:]]*"; then
3448                 continue
3449             fi
3450             lrs=$(echo $ns | sed 's/.*lru_size=//')
3451             lru_size[count]=$lrs
3452             let count=count+1
3453         done
3454
3455         facet_failover ost1
3456         facet_failover $SINGLEMDS
3457         client_up || error "client_up failed"
3458
3459         count=0
3460         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
3461             if echo $ns | grep "MDT[[:digit:]]*"; then
3462                 continue
3463             fi
3464             lrs=$(echo $ns | sed 's/.*lru_size=//')
3465             if ! test "$lrs" -eq "${lru_size[count]}"; then
3466                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
3467                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
3468             fi
3469             let count=count+1
3470         done
3471
3472         cleanup || error "cleanup failed with $?"
3473 }
3474 run_test 47 "server restart does not make client loss lru_resize settings"
3475
3476 cleanup_48() {
3477         trap 0
3478
3479         # reformat after this test is needed - if the test fails,
3480         # we will have unkillable file at FS
3481         reformat_and_config
3482 }
3483
3484 test_48() { # bz-17636 LU-7473
3485         local count
3486
3487         setup_noconfig
3488         check_mount || error "check_mount failed"
3489
3490         $SETSTRIPE -c -1 $MOUNT || error "$SETSTRIPE -c -1 $MOUNT failed"
3491         $GETSTRIPE $MOUNT || error "$GETSTRIPE $MOUNT failed"
3492
3493         echo "ok" > $MOUNT/widestripe
3494         $GETSTRIPE $MOUNT/widestripe ||
3495                 error "$GETSTRIPE $MOUNT/widestripe failed"
3496
3497         # In the future, we may introduce more EAs, such as selinux, enlarged
3498         # LOV EA, and so on. These EA will use some EA space that is shared by
3499         # ACL entries. So here we only check some reasonable ACL entries count,
3500         # instead of the max number that is calculated from the max_ea_size.
3501         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.57) ];
3502         then
3503                 count=28        # hard coded of RPC protocol
3504         elif [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3505                 count=4000      # max_num 4091 max_ea_size = 32768
3506         elif ! large_xattr_enabled; then
3507                 count=450       # max_num 497 max_ea_size = 4012
3508         else
3509                 count=4500      # max_num 8187 max_ea_size = 1048492
3510                                 # not create too much (>5000) to save test time
3511         fi
3512
3513         echo "It is expected to hold at least $count ACL entries"
3514         trap cleanup_48 EXIT ERR
3515         for ((i = 0; i < $count; i++)) do
3516                 setfacl -m u:$((i + 100)):rw $MOUNT/widestripe ||
3517                         error "Fail to setfacl for $MOUNT/widestripe at $i"
3518         done
3519
3520         cancel_lru_locks mdc
3521         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
3522         local r_count=$(getfacl $MOUNT/widestripe | grep "user:" | wc -l)
3523         count=$((count + 1)) # for the entry "user::rw-"
3524
3525         [ $count -eq $r_count ] ||
3526                 error "Expected ACL entries $count, but got $r_count"
3527
3528         cleanup_48
3529 }
3530 run_test 48 "too many acls on file"
3531
3532 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
3533 test_49a() { # bug 17710
3534         local timeout_orig=$TIMEOUT
3535         local ldlm_timeout_orig=$LDLM_TIMEOUT
3536         local LOCAL_TIMEOUT=20
3537
3538         LDLM_TIMEOUT=$LOCAL_TIMEOUT
3539         TIMEOUT=$LOCAL_TIMEOUT
3540
3541         reformat
3542         setup_noconfig
3543         check_mount || error "client mount failed"
3544
3545         echo "check ldlm_timout..."
3546         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
3547         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
3548         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
3549
3550         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
3551                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3552         fi
3553
3554         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
3555                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT / 3))"
3556         fi
3557
3558         umount_client $MOUNT || error "umount_client $MOUNT failed"
3559         stop_ost || error "problem stopping OSS"
3560         stop_mds || error "problem stopping MDS"
3561
3562         LDLM_TIMEOUT=$ldlm_timeout_orig
3563         TIMEOUT=$timeout_orig
3564 }
3565 run_test 49a "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
3566
3567 test_49b() { # bug 17710
3568         local timeout_orig=$TIMEOUT
3569         local ldlm_timeout_orig=$LDLM_TIMEOUT
3570         local LOCAL_TIMEOUT=20
3571
3572         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
3573         TIMEOUT=$LOCAL_TIMEOUT
3574
3575         reformat
3576         setup_noconfig
3577         check_mount || error "client mount failed"
3578
3579         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
3580         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
3581         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
3582
3583         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
3584                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3585         fi
3586
3587         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
3588                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT - 1))"
3589         fi
3590
3591         cleanup || error "cleanup failed"
3592
3593         LDLM_TIMEOUT=$ldlm_timeout_orig
3594         TIMEOUT=$timeout_orig
3595 }
3596 run_test 49b "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
3597
3598 lazystatfs() {
3599         # wait long enough to exceed OBD_STATFS_CACHE_SECONDS = 1
3600         sleep 2
3601         # Test both statfs and lfs df and fail if either one fails
3602         multiop_bg_pause $1 f_
3603         RC=$?
3604         PID=$!
3605         killall -USR1 multiop
3606         [ $RC -ne 0 ] && log "lazystatfs multiop failed"
3607         wait $PID || { RC=$?; log "multiop return error "; }
3608
3609         # wait long enough to exceed OBD_STATFS_CACHE_SECONDS = 1
3610         sleep 2
3611         $LFS df -l &
3612         PID=$!
3613         sleep 5
3614         if kill -s 0 $PID; then
3615                 RC=1
3616                 kill -s 9 $PID
3617                 log "lazystatfs lfs df failed to complete in 5s"
3618         fi
3619
3620         return $RC
3621 }
3622
3623 test_50a() {
3624         setup
3625         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3626         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3627
3628         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
3629
3630         cleanup || error "cleanup failed with rc $?"
3631 }
3632 run_test 50a "lazystatfs all servers available"
3633
3634 test_50b() {
3635         setup
3636         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3637         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3638
3639         # Wait for client to detect down OST
3640         stop_ost || error "Unable to stop OST1"
3641         wait_osc_import_state client ost DISCONN
3642         $LCTL dl
3643         log "OSCs should all be DISCONN"
3644
3645         lazystatfs $MOUNT || error "lazystatfs should not return EIO"
3646
3647         umount_client $MOUNT || error "Unable to unmount client"
3648         stop_mds || error "Unable to stop MDS"
3649 }
3650 run_test 50b "lazystatfs all servers down"
3651
3652 test_50c() {
3653         start_mds || error "Unable to start MDS"
3654         start_ost || error "Unable to start OST1"
3655         start_ost2 || error "Unable to start OST2"
3656         mount_client $MOUNT || error "Unable to mount client"
3657         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3658         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3659
3660         # Wait for client to detect down OST
3661         stop_ost || error "Unable to stop OST1"
3662         wait_osc_import_state mds ost DISCONN
3663         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3664
3665         umount_client $MOUNT || error "Unable to unmount client"
3666         stop_ost2 || error "Unable to stop OST2"
3667         stop_mds || error "Unable to stop MDS"
3668         #writeconf to remove all ost2 traces for subsequent tests
3669         writeconf_or_reformat