Whamcloud - gitweb
LU-9860 tests: Add conf-sanity tests to ALWAYS_EXCEPT list
[fs/lustre-release.git] / lustre / tests / conf-sanity.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6
7 # bug number for skipped test:  LU-8972
8 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT 101"
9 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
10
11 is_sles11()                                             # LU-2181
12 {
13         if [ -r /etc/SuSE-release ]
14         then
15                 local vers=$(grep VERSION /etc/SuSE-release | awk '{print $3}')
16                 local patchlev=$(grep PATCHLEVEL /etc/SuSE-release |
17                         awk '{ print $3 }')
18                 if [ $vers -eq 11 ] && [ $patchlev -eq 2 ]
19                 then
20                         return 0
21                 fi
22         fi
23         return 1
24 }
25
26 if is_sles11; then                                      # LU-2181
27         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 23a 34b"
28 fi
29
30 if [ "$FAILURE_MODE" = "HARD" ]; then
31         CONFIG_EXCEPTIONS="24a " &&
32         echo "Except the tests: $CONFIG_EXCEPTIONS for " \
33              "FAILURE_MODE=$FAILURE_MODE, b=23573" &&
34                 ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
35 fi
36
37 # bug number for skipped test:
38 # a tool to create lustre filesystem images
39 ALWAYS_EXCEPT="32newtarball $ALWAYS_EXCEPT"
40
41 SRCDIR=$(dirname $0)
42 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
43
44 PTLDEBUG=${PTLDEBUG:--1}
45 SAVE_PWD=$PWD
46 LUSTRE=${LUSTRE:-$(dirname $0)/..}
47 RLUSTRE=${RLUSTRE:-$LUSTRE}
48 export MULTIOP=${MULTIOP:-multiop}
49
50 . $LUSTRE/tests/test-framework.sh
51 init_test_env $@
52 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
53
54 # use small MDS + OST size to speed formatting time
55 # do not use too small MDSSIZE/OSTSIZE, which affect the default journal size
56 # STORED_MDSSIZE is used in test_18
57 STORED_MDSSIZE=$MDSSIZE
58 STORED_OSTSIZE=$OSTSIZE
59 MDSSIZE=200000
60 OSTSIZE=200000
61
62 fs2mds_HOST=$mds_HOST
63 fs2ost_HOST=$ost_HOST
64 fs3ost_HOST=$ost_HOST
65
66 MDSDEV1_2=$fs2mds_DEV
67 OSTDEV1_2=$fs2ost_DEV
68 OSTDEV2_2=$fs3ost_DEV
69
70 if ! combined_mgs_mds; then
71         # bug number for skipped test: 23954 LU-9860 LU-9860 LU-9860 LU-9860
72         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  24b   33a     43b     53b     54b"
73         # bug number for skipped test: LU-9875 LU-9879 LU-9879 LU-9879 LU-9879
74         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  70e     80      84      87      100"
75         # bug number for skipped test: LU-8110 LU-9400 LU-9879 LU-9879 LU-9879
76         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  102     103     104     105     107"
77 fi
78
79 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
80 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
81         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
82 fi
83
84 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
85 # bug number for skipped test:        LU-9888
86         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 32b"
87
88 init_logging
89
90 #
91 require_dsh_mds || exit 0
92 require_dsh_ost || exit 0
93
94 #                                  8  22   (min)"
95 [ "$SLOW" = "no" ] && EXCEPT_SLOW="45 69"
96
97 assert_DIR
98
99 gen_config() {
100         # The MGS must be started before the OSTs for a new fs, so start
101         # and stop to generate the startup logs.
102         start_mds
103         start_ost
104         wait_osc_import_state mds ost FULL
105         stop_ost
106         stop_mds
107 }
108
109 reformat_and_config() {
110         reformat
111         if ! combined_mgs_mds ; then
112                 start_mgs
113         fi
114         gen_config
115 }
116
117 writeconf_or_reformat() {
118         # There are at most 2 OSTs for write_conf test
119         # who knows if/where $TUNEFS is installed?
120         # Better reformat if it fails...
121         writeconf_all $MDSCOUNT 2 ||
122                 { echo "tunefs failed, reformatting instead" &&
123                   reformat_and_config && return 0; }
124         return 0
125 }
126
127 reformat() {
128         formatall
129 }
130
131 start_mgs () {
132         echo "start mgs"
133         start mgs $(mgsdevname) $MGS_MOUNT_OPTS
134 }
135
136 start_mdt() {
137         local num=$1
138         local facet=mds$num
139         local dev=$(mdsdevname $num)
140         shift 1
141
142         echo "start mds service on `facet_active_host $facet`"
143         start $facet ${dev} $MDS_MOUNT_OPTS $@ || return 94
144 }
145
146 stop_mdt() {
147         local num=$1
148         local facet=mds$num
149         local dev=$(mdsdevname $num)
150         shift 1
151
152         echo "stop mds service on `facet_active_host $facet`"
153         # These tests all use non-failover stop
154         stop $facet -f || return 97
155 }
156
157 start_mds() {
158         local num
159
160         for num in $(seq $MDSCOUNT); do
161                 start_mdt $num $@ || return 94
162         done
163 }
164
165 start_mgsmds() {
166         if ! combined_mgs_mds ; then
167                 start_mgs
168         fi
169         start_mds $@
170 }
171
172 stop_mds() {
173         local num
174         for num in $(seq $MDSCOUNT); do
175                 stop_mdt $num || return 97
176         done
177 }
178
179 stop_mgs() {
180        echo "stop mgs service on `facet_active_host mgs`"
181        # These tests all use non-failover stop
182        stop mgs -f  || return 97
183 }
184
185 start_ost() {
186         echo "start ost1 service on `facet_active_host ost1`"
187         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS $@ || return 95
188 }
189
190 stop_ost() {
191         echo "stop ost1 service on `facet_active_host ost1`"
192         # These tests all use non-failover stop
193         stop ost1 -f || return 98
194 }
195
196 start_ost2() {
197         echo "start ost2 service on `facet_active_host ost2`"
198         start ost2 $(ostdevname 2) $OST_MOUNT_OPTS $@ || return 92
199 }
200
201 stop_ost2() {
202         echo "stop ost2 service on `facet_active_host ost2`"
203         # These tests all use non-failover stop
204         stop ost2 -f || return 93
205 }
206
207 mount_client() {
208         local MOUNTPATH=$1
209         echo "mount $FSNAME on ${MOUNTPATH}....."
210         zconf_mount $(hostname) $MOUNTPATH || return 96
211 }
212
213 remount_client() {
214         local mountopt="remount,$1"
215         local MOUNTPATH=$2
216         echo "remount '$1' lustre on ${MOUNTPATH}....."
217         zconf_mount $(hostname) $MOUNTPATH "$mountopt" || return 96
218 }
219
220 umount_client() {
221         local mountpath=$1
222         shift
223         echo "umount lustre on $mountpath....."
224         zconf_umount $HOSTNAME $mountpath $@ || return 97
225 }
226
227 manual_umount_client(){
228         local rc
229         local FORCE=$1
230         echo "manual umount lustre on ${MOUNT}...."
231         do_facet client "umount ${FORCE} $MOUNT"
232         rc=$?
233         return $rc
234 }
235
236 setup() {
237         start_mds || error "MDT start failed"
238         start_ost || error "Unable to start OST1"
239         mount_client $MOUNT || error "client start failed"
240         client_up || error "client_up failed"
241 }
242
243 setup_noconfig() {
244         start_mgsmds
245         start_ost
246         mount_client $MOUNT
247 }
248
249 unload_modules_conf () {
250         if combined_mgs_mds || ! local_mode; then
251                 unload_modules || return 1
252         fi
253 }
254
255 cleanup_nocli() {
256         stop_ost || return 202
257         stop_mds || return 201
258         unload_modules_conf || return 203
259 }
260
261 cleanup() {
262         umount_client $MOUNT || return 200
263         cleanup_nocli || return $?
264 }
265
266 cleanup_fs2() {
267         trap 0
268         echo "umount $MOUNT2 ..."
269         umount $MOUNT2 || true
270         echo "stopping fs2mds ..."
271         stop fs2mds -f || true
272         echo "stopping fs2ost ..."
273         stop fs2ost -f || true
274 }
275
276 check_mount() {
277         do_facet client "cp /etc/passwd $DIR/a" || return 71
278         do_facet client "rm $DIR/a" || return 72
279         # make sure lustre is actually mounted (touch will block,
280         # but grep won't, so do it after)
281         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
282         echo "setup single mount lustre success"
283 }
284
285 check_mount2() {
286         do_facet client "touch $DIR/a" || return 71
287         do_facet client "rm $DIR/a" || return 72
288         do_facet client "touch $DIR2/a" || return 73
289         do_facet client "rm $DIR2/a" || return 74
290         echo "setup double mount lustre success"
291 }
292
293 build_test_filter
294
295 if [ "$ONLY" == "setup" ]; then
296         setup
297         exit
298 fi
299
300 if [ "$ONLY" == "cleanup" ]; then
301         cleanup
302         exit
303 fi
304
305 init_gss
306
307 #create single point mountpoint
308
309 reformat_and_config
310
311 test_0() {
312         setup
313         check_mount || error "check_mount failed"
314         cleanup || error "cleanup failed with $?"
315 }
316 run_test 0 "single mount setup"
317
318 test_1() {
319         start_mds || error "MDS start failed"
320         start_ost || error "unable to start OST"
321         echo "start ost second time..."
322         start_ost && error "2nd OST start should fail"
323         mount_client $MOUNT || error "client start failed"
324         check_mount || error "check_mount failed"
325         cleanup || error "cleanup failed with $?"
326 }
327 run_test 1 "start up ost twice (should return errors)"
328
329 test_2() {
330         start_mds || error "MDT start failed"
331         echo "start mds second time.."
332         start_mds && error "2nd MDT start should fail"
333         start_ost || error "OST start failed"
334         mount_client $MOUNT || error "mount_client failed to start client"
335         check_mount || error "check_mount failed"
336         cleanup || error "cleanup failed with $?"
337 }
338 run_test 2 "start up mds twice (should return err)"
339
340 test_3() {
341         setup
342         #mount.lustre returns an error if already in mtab
343         mount_client $MOUNT && error "2nd client mount should fail"
344         check_mount || error "check_mount failed"
345         cleanup || error "cleanup failed with $?"
346 }
347 run_test 3 "mount client twice (should return err)"
348
349 test_4() {
350         setup
351         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
352         stop_ost || error "Unable to stop OST1"
353         umount_client $MOUNT -f || error “unmount $MOUNT failed”
354         cleanup_nocli
355         eno=$?
356         # ok for ost to fail shutdown
357         if [ 202 -ne $eno ] && [ 0 -ne $eno ]; then
358                 error "cleanup failed with $?"
359         fi
360 }
361 run_test 4 "force cleanup ost, then cleanup"
362
363 test_5a() {     # was test_5
364         setup
365         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
366         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
367
368         stop_mds || error "Unable to stop MDS"
369
370         # cleanup may return an error from the failed
371         # disconnects; for now I'll consider this successful
372         # if all the modules have unloaded.
373         $UMOUNT -f $MOUNT &
374         UMOUNT_PID=$!
375         sleep 6
376         echo "killing umount"
377         kill -TERM $UMOUNT_PID
378         echo "waiting for umount to finish"
379         wait $UMOUNT_PID
380         if grep " $MOUNT " /proc/mounts; then
381                 echo "test 5: /proc/mounts after failed umount"
382                 umount -f $MOUNT &
383                 UMOUNT_PID=$!
384                 sleep 2
385                 echo "killing umount"
386                 kill -TERM $UMOUNT_PID
387                 echo "waiting for umount to finish"
388                 wait $UMOUNT_PID
389                 grep " $MOUNT " /proc/mounts &&
390                         error "/proc/mounts after second umount"
391         fi
392
393         # manual_mount_client may fail due to umount succeeding above
394         manual_umount_client
395         # stop_mds is a no-op here, and should not fail
396         cleanup_nocli || error "cleanup_nocli failed with $?"
397         # df may have lingering entry
398         manual_umount_client
399         # mtab may have lingering entry
400         local WAIT=0
401         local MAX_WAIT=20
402         local sleep=1
403         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
404                 sleep $sleep
405                 grep -q $MOUNT" " /etc/mtab || break
406                 echo "Waiting /etc/mtab updated ... "
407                 WAIT=$(( WAIT + sleep))
408         done
409         [ "$WAIT" -eq "$MAX_WAIT" ] &&
410                 error "/etc/mtab is not updated in $WAIT secs"
411         echo "/etc/mtab updated in $WAIT secs"
412 }
413 run_test 5a "force cleanup mds, then cleanup"
414
415 cleanup_5b () {
416         trap 0
417         start_mgs
418 }
419
420 test_5b() {
421         grep " $MOUNT " /etc/mtab &&
422                 error false "unexpected entry in mtab before mount" && return 10
423
424         start_ost || error "OST start failed"
425         if ! combined_mgs_mds ; then
426                 trap cleanup_5b EXIT ERR
427                 start_mds || error "MDS start failed"
428                 stop mgs
429         fi
430
431         mount_client $MOUNT && error "mount_client $MOUNT should fail"
432         grep " $MOUNT " /etc/mtab &&
433                 error "$MOUNT entry in mtab after failed mount"
434         umount_client $MOUNT
435         # stop_mds is a no-op here, and should not fail
436         cleanup_nocli || error "cleanup_nocli failed with $?"
437         if ! combined_mgs_mds ; then
438                 cleanup_5b
439         fi
440 }
441 run_test 5b "Try to start a client with no MGS (should return errs)"
442
443 test_5c() {
444         grep " $MOUNT " /etc/mtab &&
445                 error false "unexpected entry in mtab before mount" && return 10
446
447         start_mds || error "MDS start failed"
448         start_ost || error "OST start failed"
449         local oldfs="${FSNAME}"
450         FSNAME="wrong.${FSNAME}"
451         mount_client $MOUNT || :
452         FSNAME=${oldfs}
453         grep " $MOUNT " /etc/mtab &&
454                 error "$MOUNT entry in mtab after failed mount"
455         umount_client $MOUNT
456         cleanup_nocli || error "cleanup_nocli failed with $?"
457 }
458 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
459
460 test_5d() {
461         grep " $MOUNT " /etc/mtab &&
462                 error "unexpected entry in mtab before mount"
463
464         start_ost || error "OST start failed"
465         start_mds || error "MDS start failed"
466         stop_ost -f || error "Unable to stop OST1"
467         mount_client $MOUNT || error "mount_client $MOUNT failed"
468         umount_client $MOUNT -f || error "umount_client $MOUNT failed"
469         cleanup_nocli || error "cleanup_nocli failed with $?"
470         ! grep " $MOUNT " /etc/mtab ||
471                 error "$MOUNT entry in mtab after unmount"
472 }
473 run_test 5d "mount with ost down"
474
475 test_5e() {
476         grep " $MOUNT " /etc/mtab &&
477                 error false "unexpected entry in mtab before mount" && return 10
478
479         start_mds || error "MDS start failed"
480         start_ost || error "OST start failed"
481
482         #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
483         do_facet client "$LCTL set_param fail_loc=0x80000506"
484         mount_client $MOUNT || echo "mount failed (not fatal)"
485         cleanup || error "cleanup failed with $?"
486         grep " $MOUNT " /etc/mtab &&
487                 error "$MOUNT entry in mtab after unmount"
488         pass
489 }
490 run_test 5e "delayed connect, don't crash (bug 10268)"
491
492 test_5f() {
493         if combined_mgs_mds ; then
494                 skip "needs separate mgs and mds"
495                 return 0
496         fi
497
498         grep " $MOUNT " /etc/mtab &&
499                 error false "unexpected entry in mtab before mount" && return 10
500
501         local rc=0
502         start_ost || error "OST start failed"
503         mount_client $MOUNT &
504         local pid=$!
505         echo client_mount pid is $pid
506
507         sleep 5
508
509         if ! ps -f -p $pid >/dev/null; then
510                 wait $pid
511                 rc=$?
512                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
513                 error "mount returns $rc, expected to hang"
514                 rc=11
515                 cleanup || error "cleanup failed with $?"
516                 return $rc
517         fi
518
519         # start mds
520         start_mds || error "start MDS failed"
521
522         # mount should succeed after start mds
523         wait $pid
524         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
525         cleanup || error "final call to cleanup failed with rc $?"
526 }
527 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
528
529 test_5g() {
530         modprobe lustre
531         [ $(lustre_version_code client) -lt $(version_code 2.9.53) ] &&
532                 { skip "automount of debugfs missing before 2.9.53" && return 0; }
533         umount /sys/kernel/debug
534         $LCTL get_param -n devices | egrep -v "error" && \
535                 error "lctl can't access debugfs data"
536         grep " debugfs " /etc/mtab || error "debugfs failed to remount"
537 }
538 run_test 5g "handle missing debugfs"
539
540 test_6() {
541         setup
542         manual_umount_client
543         mount_client $MOUNT || error "mount_client $MOUNT failed"
544         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
545         cleanup || error "cleanup failed with rc $?"
546 }
547 run_test 6 "manual umount, then mount again"
548
549 test_7() {
550         setup
551         manual_umount_client
552         cleanup_nocli || error "cleanup_nocli failed with $?"
553 }
554 run_test 7 "manual umount, then cleanup"
555
556 test_8() {
557         setup
558         mount_client $MOUNT2 || error "mount_client $MOUNT2 failed"
559         check_mount2 || error "check_mount2 failed"
560         umount_client $MOUNT2 || error "umount_client $MOUNT2 failed"
561         cleanup || error "cleanup failed with rc $?"
562 }
563 run_test 8 "double mount setup"
564
565 test_9() {
566         start_ost || error "OST start failed"
567
568         do_facet ost1 $LCTL set_param debug=\'inode trace\' ||
569                 error "do_facet ost1 set_param inode trace failed."
570         do_facet ost1 $LCTL set_param subsystem_debug=\'mds ost\' ||
571                 error "do_facet ost1 set_param debug mds ost failed."
572
573         CHECK_PTLDEBUG="`do_facet ost1 $LCTL get_param -n debug`"
574         if [ "$CHECK_PTLDEBUG" ] && { \
575            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
576            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
577                 echo "lnet.debug success"
578         else
579                 error "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
580         fi
581         CHECK_SUBSYS="`do_facet ost1 $LCTL get_param -n subsystem_debug`"
582         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
583                 echo "lnet.subsystem_debug success"
584         else
585                 error "lnet.subsystem_debug: want 'mds ost' got '$CHECK_SUBSYS'"
586         fi
587         stop_ost || error "Unable to stop OST1"
588 }
589 run_test 9 "test ptldebug and subsystem for mkfs"
590
591 is_blkdev () {
592         local facet=$1
593         local dev=$2
594         local size=${3:-""}
595
596         local rc=0
597         do_facet $facet "test -b $dev" || rc=1
598         if [[ "$size" ]]; then
599                 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k \
600                            count=1 skip=$size 2>&1" |
601                         awk '($3 == "in") { print $1 }')
602                 [[ $in  = "1+0" ]] || rc=1
603         fi
604         return $rc
605 }
606
607 #
608 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
609 # But with new MDS stack we don't care about the mode of local objects
610 # anymore, so this test is removed. See bug 22944 for more details.
611 #
612
613 test_17() {
614         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
615                 skip "ldiskfs only test"
616                 return
617         fi
618
619         setup
620         check_mount || error "check_mount failed"
621         cleanup || error "cleanup failed with rc $?"
622
623         echo "Remove mds config log"
624         if ! combined_mgs_mds ; then
625                 stop mgs
626         fi
627
628         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' \
629                       $(mgsdevname) || return \$?" ||
630                 error "do_facet mgs failed with $?"
631
632         if ! combined_mgs_mds ; then
633                 start_mgs
634         fi
635
636         start_ost || error "OST start failed"
637         start_mds && error "MDS start succeeded, but should fail"
638         reformat_and_config
639 }
640 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
641
642 test_18() {
643         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
644                 skip "ldiskfs only test"
645                 return
646         fi
647
648         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
649
650         local MIN=2000000
651
652         local OK=
653         # check if current MDSSIZE is large enough
654         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE &&
655                 log "use MDSSIZE=$MDSSIZE"
656
657         # check if the global config has a large enough MDSSIZE
658         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] &&
659                 [ $STORED_MDSSIZE -ge $MIN ] &&
660                 OK=1 && myMDSSIZE=$STORED_MDSSIZE &&
661                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
662
663         # check if the block device is large enough
664         is_blkdev $SINGLEMDS $MDSDEV $MIN
665         local large_enough=$?
666         if [ -n "$OK" ]; then
667                 [ $large_enough -ne 0 ] && OK=""
668         else
669                 [ $large_enough -eq 0 ] && OK=1 && myMDSSIZE=$MIN &&
670                         log "use device $MDSDEV with MIN=$MIN"
671         fi
672
673         # check if a loopback device has enough space for fs metadata (5%)
674
675         if [ -z "$OK" ]; then
676                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! \
677                               -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
678                         awk '($1 != "Filesystem") { print $4 }')
679                 ! [ -z "$SPACE" ] && [ $SPACE -gt $((MIN / 20)) ] &&
680                         OK=1 && myMDSSIZE=$MIN &&
681                         log "use file $MDSDEV with MIN=$MIN"
682         fi
683
684         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
685
686         echo "mount mds with large journal..."
687
688         local OLD_MDSSIZE=$MDSSIZE
689         MDSSIZE=$myMDSSIZE
690
691         reformat_and_config
692         echo "mount lustre system..."
693         setup
694         check_mount || error "check_mount failed"
695
696         echo "check journal size..."
697         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
698         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
699                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
700         else
701                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
702         fi
703
704         cleanup || error "cleanup failed with rc $?"
705
706         MDSSIZE=$OLD_MDSSIZE
707         reformat_and_config
708 }
709 run_test 18 "check mkfs creates large journals"
710
711 test_19a() {
712         start_mds || error "MDS start failed"
713         stop_mds || error "Unable to stop MDS"
714 }
715 run_test 19a "start/stop MDS without OSTs"
716
717 test_19b() {
718         start_ost || error "Unable to start OST1"
719         stop_ost -f || error "Unable to stop OST1"
720 }
721 run_test 19b "start/stop OSTs without MDS"
722
723 test_20() {
724         # first format the ost/mdt
725         start_mds || error "MDS start failed"
726         start_ost || error "Unable to start OST1"
727         mount_client $MOUNT || error "mount_client $MOUNT failed"
728         check_mount || error "check_mount failed"
729         rm -f $DIR/$tfile || error "remove $DIR/$tfile failed."
730         remount_client ro $MOUNT || error "remount_client with ro failed"
731         touch $DIR/$tfile && error "$DIR/$tfile created incorrectly"
732         [ -e $DIR/$tfile ] && error "$DIR/$tfile exists incorrectly"
733         remount_client rw $MOUNT || error "remount_client with rw failed"
734         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
735         MCNT=$(grep -c $MOUNT /etc/mtab)
736         [ "$MCNT" -ne 1 ] && error "$MOUNT in /etc/mtab $MCNT times"
737         umount_client $MOUNT
738         stop_mds || error "Unable to stop MDS"
739         stop_ost || error "Unable to stop OST1"
740 }
741 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
742
743 test_21a() {
744         start_mds || error "MDS start failed"
745         start_ost || error "unable to start OST1"
746         wait_osc_import_state mds ost FULL
747         stop_ost || error "unable to stop OST1"
748         stop_mds || error "unable to stop MDS"
749 }
750 run_test 21a "start mds before ost, stop ost first"
751
752 test_21b() {
753         start_ost || error "unable to start OST1"
754         start_mds || error "MDS start failed"
755         wait_osc_import_state mds ost FULL
756         stop_mds || error "unable to stop MDS"
757         stop_ost || error "unable to stop OST1"
758 }
759 run_test 21b "start ost before mds, stop mds first"
760
761 test_21c() {
762         start_ost || error "Unable to start OST1"
763         start_mds || error "MDS start failed"
764         start_ost2 || error "Unable to start OST2"
765         wait_osc_import_state mds ost2 FULL
766         stop_ost || error "Unable to stop OST1"
767         stop_ost2 || error "Unable to stop OST2"
768         stop_mds || error "Unable to stop MDS"
769         #writeconf to remove all ost2 traces for subsequent tests
770         writeconf_or_reformat
771 }
772 run_test 21c "start mds between two osts, stop mds last"
773
774 test_21d() {
775         if combined_mgs_mds ; then
776                 skip "need separate mgs device" && return 0
777         fi
778         stopall
779
780         reformat
781
782         start_mgs || error "unable to start MGS"
783         start_ost || error "unable to start OST1"
784         start_ost2 || error "unable to start OST2"
785         start_mds || error "MDS start failed"
786         wait_osc_import_state mds ost2 FULL
787
788         stop_ost || error "Unable to stop OST1"
789         stop_ost2 || error "Unable to stop OST2"
790         stop_mds || error "Unable to stop MDS"
791         stop_mgs
792         #writeconf to remove all ost2 traces for subsequent tests
793         writeconf_or_reformat
794         start_mgs || error "unable to start MGS"
795 }
796 run_test 21d "start mgs then ost and then mds"
797
798 cleanup_21e() {
799         MGSNID="$saved_mgsnid"
800         cleanup_fs2
801         echo "stopping fs2mgs ..."
802         stop $fs2mgs -f || true
803 }
804
805 test_21e() { # LU-5863
806         if [[ -z "$fs3ost_DEV" || -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
807                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
808                 skip_env "mixed loopback and real device not working" && return
809         fi
810
811         local fs2mdsdev=$(mdsdevname 1_2)
812         local fs2ostdev=$(ostdevname 1_2)
813         local fs3ostdev=$(ostdevname 2_2)
814
815         local fs2mdsvdev=$(mdsvdevname 1_2)
816         local fs2ostvdev=$(ostvdevname 1_2)
817         local fs3ostvdev=$(ostvdevname 2_2)
818
819         # temporarily use fs3ost as fs2mgs
820         local fs2mgs=fs3ost
821         local fs2mgsdev=$fs3ostdev
822         local fs2mgsvdev=$fs3ostvdev
823
824         local fsname=test1234
825
826         add $fs2mgs $(mkfs_opts mgs $fs2mgsdev) --fsname=$fsname \
827                 --reformat $fs2mgsdev $fs2mgsvdev || error "add fs2mgs failed"
828         start $fs2mgs $fs2mgsdev $MGS_MOUNT_OPTS && trap cleanup_21e EXIT INT ||
829                 error "start fs2mgs failed"
830
831         local saved_mgsnid="$MGSNID"
832         MGSNID=$(do_facet $fs2mgs $LCTL list_nids | xargs | tr ' ' ,)
833
834         add fs2mds $(mkfs_opts mds1 $fs2mdsdev $fsname) \
835                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
836         add fs2ost $(mkfs_opts ost1 $fs2ostdev $fsname) \
837                 --reformat $fs2ostdev $fs2ostvdev || error "add fs2ost failed"
838
839         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
840         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS || error "start fs2mds failed"
841
842         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
843         $MOUNT_CMD $MGSNID:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
844         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
845
846         cleanup_21e
847 }
848 run_test 21e "separate MGS and MDS"
849
850 test_22() {
851         start_mds || error "MDS start failed"
852
853         echo "Client mount with ost in logs, but none running"
854         start_ost || error "unable to start OST1"
855         # wait until mds connected to ost and open client connection
856         wait_osc_import_state mds ost FULL
857         stop_ost || error "unable to stop OST1"
858         mount_client $MOUNT || error "mount_client $MOUNT failed"
859         # check_mount will block trying to contact ost
860         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
861         rm -f $DIR/$tfile || error "remove $DIR/$tfile failed"
862         umount_client $MOUNT -f
863         pass
864
865         echo "Client mount with a running ost"
866         start_ost || error "unable to start OST1"
867         if $GSS; then
868                 # if gss enabled, wait full time to let connection from
869                 # mds to ost be established, due to the mismatch between
870                 # initial connect timeout and gss context negotiation timeout.
871                 # This perhaps could be remove after AT landed.
872                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
873                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
874         fi
875         mount_client $MOUNT || error "mount_client $MOUNT failed"
876         wait_osc_import_state mds ost FULL
877         wait_osc_import_state client ost FULL
878         check_mount || error "check_mount failed"
879         pass
880
881         cleanup || error "cleanup failed with rc $?"
882 }
883 run_test 22 "start a client before osts (should return errs)"
884
885 test_23a() {    # was test_23
886         setup
887         # fail mds
888         stop $SINGLEMDS || error "failed to stop $SINGLEMDS"
889         # force down client so that recovering mds waits for reconnect
890         local running=$(grep -c $MOUNT /proc/mounts) || true
891         if [ $running -ne 0 ]; then
892                 echo "Stopping client $MOUNT (opts: -f)"
893                 umount -f $MOUNT
894         fi
895
896         # enter recovery on failed mds
897         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
898         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "MDS start failed"
899         # try to start a new client
900         mount_client $MOUNT &
901         sleep 5
902         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
903         MOUNT_LUSTRE_PID=$(ps -ef | grep mount.lustre |
904                            grep -v grep | awk '{print $2}')
905         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
906         ps --ppid $MOUNT_PID
907         ps --ppid $MOUNT_LUSTRE_PID
908         echo "waiting for mount to finish"
909         ps -ef | grep mount
910         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
911         # SIGTERM works but it does not spread to offspring processses
912         kill -s TERM $MOUNT_PID
913         kill -s TERM $MOUNT_LUSTRE_PID
914         # we can not wait $MOUNT_PID because it is not a child of this shell
915         local PID1
916         local PID2
917         local WAIT=0
918         local MAX_WAIT=30
919         local sleep=1
920         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
921                 sleep $sleep
922                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
923                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
924                 echo PID1=$PID1
925                 echo PID2=$PID2
926                 [ -z "$PID1" -a -z "$PID2" ] && break
927                 echo "waiting for mount to finish ... "
928                 WAIT=$(( WAIT + sleep))
929         done
930         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
931                 error "MOUNT_PID $MOUNT_PID and "\
932                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
933                 ps -ef | grep mount
934         fi
935         stop_mds || error "stopping MDSes failed"
936         stop_ost || error "stopping OSSes failed"
937 }
938 run_test 23a "interrupt client during recovery mount delay"
939
940 umount_client $MOUNT
941 cleanup_nocli
942
943 test_23b() {    # was test_23
944         start_mds || error "MDS start failed"
945         start_ost || error "Unable to start OST1"
946         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
947         $LCTL set_param fail_loc=0x80000313
948         mount_client $MOUNT
949         cleanup || error "cleanup failed with rc $?"
950 }
951 run_test 23b "Simulate -EINTR during mount"
952
953 test_24a() {
954         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
955
956         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
957                 is_blkdev $SINGLEMDS $MDSDEV &&
958                 skip_env "mixed loopback and real device not working" && return
959         fi
960
961         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
962
963         local fs2mdsdev=$(mdsdevname 1_2)
964         local fs2ostdev=$(ostdevname 1_2)
965         local fs2mdsvdev=$(mdsvdevname 1_2)
966         local fs2ostvdev=$(ostvdevname 1_2)
967         local cl_user
968
969         # LU-9733 test fsname started with numbers as well
970         local FSNAME2=969362ae
971
972         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --nomgs --mgsnode=$MGSNID \
973                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
974
975         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --fsname=${FSNAME2} \
976                 --reformat $fs2ostdev $fs2ostvdev || exit 10
977
978         setup
979         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
980         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
981         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
982         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
983
984         # LU-9733 test fsname started with numbers
985         cl_user=$(do_facet $SINGLEMDS lctl --device $FSNAME2-MDT0000 \
986                         changelog_register -n) ||
987                                 error "register changelog failed"
988
989         do_facet $SINGLEMDS lctl --device $FSNAME2-MDT0000 \
990                         changelog_deregister $cl_user ||
991                                 error "deregister changelog failed"
992         # 1 still works
993         check_mount || error "check_mount failed"
994         # files written on 1 should not show up on 2
995         cp /etc/passwd $DIR/$tfile
996         sleep 10
997         [ -e $MOUNT2/$tfile ] && error "File bleed"
998         # 2 should work
999         sleep 5
1000         cp /etc/passwd $MOUNT2/$tfile ||
1001                 error "cp /etc/passwd $MOUNT2/$tfile failed"
1002         rm $MOUNT2/$tfile || error "remove $MOUNT2/$tfile failed"
1003         # 2 is actually mounted
1004         grep $MOUNT2' ' /proc/mounts > /dev/null || error "$MOUNT2 not mounted"
1005         # failover
1006         facet_failover fs2mds
1007         facet_failover fs2ost
1008         df
1009         umount_client $MOUNT
1010         # the MDS must remain up until last MDT
1011         stop_mds
1012         MDS=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
1013               awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1014         [ -z "$MDS" ] && error "No MDT"
1015         cleanup_fs2
1016         cleanup_nocli || error "cleanup_nocli failed with rc $?"
1017 }
1018 run_test 24a "Multiple MDTs on a single node"
1019
1020 test_24b() {
1021         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
1022
1023         if [ -z "$fs2mds_DEV" ]; then
1024                 local dev=${SINGLEMDS}_dev
1025                 local MDSDEV=${!dev}
1026                 is_blkdev $SINGLEMDS $MDSDEV &&
1027                 skip_env "mixed loopback and real device not working" && return
1028         fi
1029
1030         local fs2mdsdev=$(mdsdevname 1_2)
1031         local fs2mdsvdev=$(mdsvdevname 1_2)
1032
1033         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --mgs --fsname=${FSNAME}2 \
1034                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
1035         setup
1036         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS &&
1037                 error "start MDS should fail"
1038         stop fs2mds -f
1039         cleanup || error "cleanup failed with rc $?"
1040 }
1041 run_test 24b "Multiple MGSs on a single node (should return err)"
1042
1043 test_25() {
1044         setup
1045         check_mount || error "check_mount failed"
1046         local MODULES=$($LCTL modules | awk '{ print $2 }')
1047         rmmod $MODULES 2>/dev/null || true
1048         cleanup || error "cleanup failed with $?"
1049 }
1050 run_test 25 "Verify modules are referenced"
1051
1052 test_26() {
1053         load_modules
1054         # we need modules before mount for sysctl, so make sure...
1055         do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
1056         #define OBD_FAIL_MDS_FS_SETUP            0x135
1057         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000135"
1058         start_mds && error "MDS started but should not have started"
1059         $LCTL get_param -n devices
1060         DEVS=$($LCTL get_param -n devices | egrep -v MG | wc -l)
1061         [ $DEVS -gt 0 ] && error "number of devices is $DEVS, should be zero"
1062         # start mds to drop writeconf setting
1063         start_mds || error "Unable to start MDS"
1064         stop_mds || error "Unable to stop MDS"
1065         unload_modules_conf || error "unload_modules_conf failed with $?"
1066 }
1067 run_test 26 "MDT startup failure cleans LOV (should return errs)"
1068
1069 test_27a() {
1070         start_ost || error "Unable to start OST1"
1071         start_mds || error "Unable to start MDS"
1072         echo "Requeue thread should have started: "
1073         ps -e | grep ll_cfg_requeue
1074         set_conf_param_and_check ost1                                         \
1075            "$LCTL get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" \
1076            "$FSNAME-OST0000.ost.client_cache_seconds" ||
1077                 error "set_conf_param_and_check ost1 failed"
1078         cleanup_nocli || error "cleanup_nocli failed with rc $?"
1079 }
1080 run_test 27a "Reacquire MGS lock if OST started first"
1081
1082 test_27b() {
1083         # FIXME. ~grev
1084         setup
1085         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
1086                         awk '($3 ~ "mdt" && $4 ~ "MDT0000") { print $4 }')
1087
1088         facet_failover $SINGLEMDS
1089         set_conf_param_and_check $SINGLEMDS                             \
1090                 "$LCTL get_param -n mdt.$device.identity_acquire_expire" \
1091                 "$device.mdt.identity_acquire_expire" ||
1092                 error "set_conf_param_and_check $SINGLEMDS failed"
1093         set_conf_param_and_check client                          \
1094                 "$LCTL get_param -n mdc.$device-mdc-*.max_rpcs_in_flight"\
1095                 "$device.mdc.max_rpcs_in_flight" ||
1096                 error "set_conf_param_and_check client failed"
1097         check_mount
1098         cleanup || error "cleanup failed with $?"
1099 }
1100 run_test 27b "Reacquire MGS lock after failover"
1101
1102 test_28() {
1103         setup
1104         TEST="$LCTL get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1105         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1106         ORIG=$($TEST)
1107         FINAL=$(($ORIG + 1))
1108         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL ||
1109                 error "first set_conf_param_and_check client failed"
1110         FINAL=$(($FINAL + 1))
1111         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL ||
1112                 error "second set_conf_param_and_check client failed"
1113         umount_client $MOUNT || error "umount_client $MOUNT failed"
1114         mount_client $MOUNT || error "mount_client $MOUNT failed"
1115         RESULT=$($TEST)
1116         if [ $RESULT -ne $FINAL ]; then
1117                 error "New config not seen: wanted $FINAL got $RESULT"
1118         else
1119                 echo "New config success: got $RESULT"
1120         fi
1121         set_conf_param_and_check client "$TEST" "$PARAM" $ORIG ||
1122                 error "third set_conf_param_and_check client failed"
1123         cleanup || error "cleanup failed with rc $?"
1124 }
1125 run_test 28 "permanent parameter setting"
1126
1127 test_28a() { # LU-4221
1128         [[ $(lustre_version_code ost1) -ge $(version_code 2.5.52) ]] ||
1129                 { skip "Need OST version at least 2.5.52" && return 0; }
1130         [ "$(facet_fstype ost1)" = "zfs" ] &&
1131                 skip "LU-4221: no such proc params for ZFS OSTs" && return
1132
1133         local name
1134         local param
1135         local cmd
1136         local old
1137         local new
1138         local device="$FSNAME-OST0000"
1139
1140         setup
1141
1142         # In this test we will set three kinds of proc parameters with
1143         # lctl conf_param:
1144         # 1. the ones moved from the OFD to the OSD, and only their
1145         #    symlinks kept in obdfilter
1146         # 2. non-symlink ones in the OFD
1147         # 3. non-symlink ones in the OSD
1148
1149         # Check 1.
1150         # prepare a symlink parameter in the OFD
1151         name="writethrough_cache_enable"
1152         param="$device.ost.$name"
1153         cmd="$LCTL get_param -n obdfilter.$device.$name"
1154
1155         # conf_param the symlink parameter in the OFD
1156         old=$(do_facet ost1 $cmd)
1157         new=$(((old + 1) % 2))
1158         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1159                 error "lctl conf_param $device.ost.$param=$new failed"
1160
1161         # conf_param the target parameter in the OSD
1162         param="$device.osd.$name"
1163         cmd="$LCTL get_param -n osd-*.$device.$name"
1164         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1165                 error "lctl conf_param $device.osd.$param=$old failed"
1166
1167         # Check 2.
1168         # prepare a non-symlink parameter in the OFD
1169         name="client_cache_seconds"
1170         param="$device.ost.$name"
1171         cmd="$LCTL get_param -n obdfilter.$device.$name"
1172
1173         # conf_param the parameter in the OFD
1174         old=$(do_facet ost1 $cmd)
1175         new=$((old * 2))
1176         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1177                 error "lctl conf_param $device.ost.$param=$new failed"
1178         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1179                 error "lctl conf_param $device.ost.$param=$old failed"
1180
1181         # Check 3.
1182         # prepare a non-symlink parameter in the OSD
1183         name="auto_scrub"
1184         param="$device.osd.$name"
1185         cmd="$LCTL get_param -n osd-*.$device.$name"
1186
1187         # conf_param the parameter in the OSD
1188         old=$(do_facet ost1 $cmd)
1189         new=$(((old + 1) % 2))
1190         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1191                 error "lctl conf_param $device.osd.$param=$new failed"
1192         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1193                 error "lctl conf_param $device.osd.$param=$old failed"
1194
1195         cleanup || error "cleanup failed with $?"
1196 }
1197 run_test 28a "set symlink parameters permanently with conf_param"
1198
1199 test_29() {
1200         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs" && return
1201         setup > /dev/null 2>&1
1202         start_ost2 || error "Unable to start OST2"
1203         sleep 10
1204
1205         local PARAM="$FSNAME-OST0001.osc.active"
1206         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
1207         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1208
1209         ACTV=$($LCTL get_param -n $PROC_ACT)
1210         DEAC=$((1 - $ACTV))
1211         set_conf_param_and_check client \
1212                 "$LCTL get_param -n $PROC_ACT" "$PARAM" $DEAC ||
1213                 error "set_conf_param_and_check client failed"
1214         # also check ost_server_uuid status
1215         RESULT=$($LCTL get_param -n $PROC_UUID | grep DEACTIV)
1216         if [ -z "$RESULT" ]; then
1217                 error "Client not deactivated: $($LCTL get_param \
1218                        -n $PROC_UUID)"
1219         else
1220                 echo "Live client success: got $RESULT"
1221         fi
1222
1223         # check MDTs too
1224         wait_osp_active ost ${FSNAME}-OST0001 1 0
1225
1226         # test new client starts deactivated
1227         umount_client $MOUNT || error "umount_client $MOUNT failed"
1228         mount_client $MOUNT || error "mount_client $MOUNT failed"
1229         RESULT=$($LCTL get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1230         if [ -z "$RESULT" ]; then
1231                 error "New client start active: $(lctl get_param -n $PROC_UUID)"
1232         else
1233                 echo "New client success: got $RESULT"
1234         fi
1235
1236         # make sure it reactivates
1237         set_conf_param_and_check client \
1238                 "$LCTL get_param -n $PROC_ACT" "$PARAM" $ACTV ||
1239                 error "lctl get_param $PROC_ACT $PARAM $ACTV failed"
1240
1241         umount_client $MOUNT
1242         stop_ost2 || error "Unable to stop OST2"
1243         cleanup_nocli || error "cleanup_nocli failed with $?"
1244         #writeconf to remove all ost2 traces for subsequent tests
1245         writeconf_or_reformat
1246 }
1247 run_test 29 "permanently remove an OST"
1248
1249 test_30a() {
1250         setup
1251
1252         echo Big config llog
1253         TEST="$LCTL get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1254         ORIG=$($TEST)
1255         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1256         for i in ${LIST[@]}; do
1257                 set_conf_param_and_check client "$TEST" \
1258                         "$FSNAME.llite.max_read_ahead_whole_mb" $i ||
1259                         error "Set $FSNAME.llite.max_read_ahead_whole_mb failed"
1260         done
1261         # make sure client restart still works
1262         umount_client $MOUNT
1263         mount_client $MOUNT || error "mount_client $MOUNT failed"
1264         [ "$($TEST)" -ne "$i" ] &&
1265                 error "Param didn't stick across restart $($TEST) != $i"
1266         pass
1267
1268         echo Erase parameter setting
1269         do_facet mgs "$LCTL conf_param \
1270                       -d $FSNAME.llite.max_read_ahead_whole_mb" ||
1271                 error "Erase param $FSNAME.llite.max_read_ahead_whole_mb failed"
1272         umount_client $MOUNT
1273         mount_client $MOUNT || error "mount_client $MOUNT failed"
1274         FINAL=$($TEST)
1275         echo "deleted (default) value=$FINAL, orig=$ORIG"
1276         # assumes this parameter started at the default value
1277         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1278
1279         cleanup || error "cleanup failed with rc $?"
1280 }
1281 run_test 30a "Big config llog and conf_param deletion"
1282
1283 test_30b() {
1284         setup
1285
1286         local orignids=$($LCTL get_param -n \
1287                 osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1288
1289         local orignidcount=$(echo "$orignids" | wc -w)
1290
1291         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1292         # numerical part of it. Hopefully that's not already a failover address
1293         # for the server.
1294         local OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | \
1295                 awk '{print $1}')
1296         local ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1297         local NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1298         local NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1299         echo "Using fake nid $NEW"
1300
1301         local TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1302                 grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1303         set_conf_param_and_check client "$TEST" \
1304                 "$FSNAME-OST0000.failover.node" $NEW ||
1305                 error "didn't add failover nid $NEW"
1306         local NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1307                 grep failover_nids)
1308         echo $NIDS
1309         local NIDCOUNT=$(echo "$NIDS" | wc -w)
1310         echo "should have $((orignidcount + 1)) entries \
1311                 in failover nids string, have $NIDCOUNT"
1312         [ $NIDCOUNT -eq $((orignidcount + 1)) ] ||
1313                 error "Failover nid not added"
1314
1315         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" ||
1316                 error "conf_param delete failed"
1317         umount_client $MOUNT
1318         mount_client $MOUNT || error "mount_client $MOUNT failed"
1319
1320         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1321                 grep failover_nids)
1322         echo $NIDS
1323         NIDCOUNT=$(echo "$NIDS" | wc -w)
1324         echo "only $orignidcount final entries should remain \
1325                 in failover nids string, have $NIDCOUNT"
1326         [ $NIDCOUNT -eq $orignidcount ] || error "Failover nids not removed"
1327
1328         cleanup || error "cleanup failed with rc $?"
1329 }
1330 run_test 30b "Remove failover nids"
1331
1332 test_31() { # bug 10734
1333         # ipaddr must not exist
1334         $MOUNT_CMD 4.3.2.1@tcp:/lustre $MOUNT || true
1335         cleanup || error "cleanup failed with rc $?"
1336 }
1337 run_test 31 "Connect to non-existent node (shouldn't crash)"
1338
1339
1340 T32_QID=60000
1341 T32_BLIMIT=40960 # Kbytes
1342 T32_ILIMIT=4
1343
1344 #
1345 # This is not really a test but a tool to create new disk
1346 # image tarballs for the upgrade tests.
1347 #
1348 # Disk image tarballs should be created on single-node
1349 # clusters by running this test with default configurations
1350 # plus a few mandatory environment settings that are verified
1351 # at the beginning of the test.
1352 #
1353 test_32newtarball() {
1354         local version
1355         local dst=.
1356         local src=/etc/rc.d
1357         local tmp=$TMP/t32_image_create
1358         local server_version=$(lustre_version_code $SINGLEMDS)
1359         local remote_dir
1360         local striped_dir
1361         local pushd_dir
1362
1363         if [ $FSNAME != t32fs -o \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o \
1364              $OSTCOUNT -ne 1 -o -z "$OSTDEV1" ]; then
1365                 error "Needs FSNAME=t32fs MDSCOUNT=2 "                  \
1366                       "MDSDEV1=<nonexistent_file>"                      \
1367                       "MDSDEV2=<nonexistent_file>"                      \
1368                       "(or MDSDEV, in the case of b1_8)"                \
1369                       "OSTCOUNT=1 OSTDEV1=<nonexistent_file>"
1370         fi
1371
1372         mkdir $tmp || {
1373                 echo "Found stale $tmp"
1374                 return 1
1375         }
1376
1377         mkdir $tmp/src || return 1
1378         tar cf - -C $src . | tar xf - -C $tmp/src
1379         dd if=/dev/zero of=$tmp/src/t32_qf_old bs=1M \
1380                 count=$(($T32_BLIMIT / 1024 / 4))
1381         chown $T32_QID.$T32_QID $tmp/src/t32_qf_old
1382
1383         # format ost with comma-separated NIDs to verify LU-4460
1384         local failnid="$(h2nettype 1.2.3.4),$(h2nettype 4.3.2.1)"
1385         MGSNID="$MGSNID,$MGSNID" OSTOPT="--failnode=$failnid" formatall
1386
1387         setupall
1388
1389         [[ $server_version -ge $(version_code 2.3.50) ]] ||
1390                 $LFS quotacheck -ug /mnt/$FSNAME
1391         $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
1392                 /mnt/$FSNAME
1393
1394         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1395
1396         if [[ $MDSCOUNT -ge 2 ]]; then
1397                 remote_dir=/mnt/$FSNAME/remote_dir
1398                 $LFS mkdir -i 1 $remote_dir
1399                 tar cf - -C $tmp/src . | tar xf - -C $remote_dir
1400
1401                 if [[ $server_version -ge $(version_code 2.7.0) ]]; then
1402                         striped_dir=/mnt/$FSNAME/striped_dir_old
1403                         $LFS mkdir -i 1 -c 2 $striped_dir
1404                         tar cf - -C $tmp/src . | tar xf - -C $striped_dir
1405                 fi
1406         fi
1407
1408         stopall
1409
1410         mkdir $tmp/img || return 1
1411
1412         setupall
1413
1414         pushd_dir=/mnt/$FSNAME
1415         if [[ $MDSCOUNT -ge 2 ]]; then
1416                 pushd_dir=$remote_dir
1417                 if [[ $server_version -ge $(version_code 2.7.0) ]]; then
1418                         pushd $striped_dir
1419                         ls -Rni --time-style=+%s >$tmp/img/list2
1420                         popd
1421                 fi
1422         fi
1423
1424         pushd $pushd_dir
1425         ls -Rni --time-style=+%s >$tmp/img/list
1426         find ! -name .lustre -type f -exec sha1sum {} \; |
1427                 sort -k 2 >$tmp/img/sha1sums
1428         popd
1429         $LCTL get_param -n version | head -n 1 |
1430                 sed -e 's/^lustre: *//' >$tmp/img/commit
1431
1432         [[ $server_version -ge $(version_code 2.3.50) ]] ||
1433                 $LFS quotaon -ug /mnt/$FSNAME
1434         $LFS quota -u $T32_QID -v /mnt/$FSNAME
1435         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1436                 awk 'BEGIN { num='1' } { if ($1 == "'/mnt/$FSNAME'") \
1437                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1438                 | tr -d "*" > $tmp/img/bspace
1439         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1440                 awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
1441                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1442                 | tr -d "*" > $tmp/img/ispace
1443         echo $T32_BLIMIT > $tmp/img/blimit
1444         echo $T32_ILIMIT > $tmp/img/ilimit
1445
1446         stopall
1447
1448         pushd $tmp/src
1449         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1450         popd
1451
1452         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1453                 echo "Data verification failed"
1454         fi
1455
1456         uname -r >$tmp/img/kernel
1457         uname -m >$tmp/img/arch
1458
1459         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1460         for num in $(seq 2 $MDSCOUNT); do
1461                 local devname=$(mdsdevname $num)
1462                 local facet=mds$num
1463                 [[ $(facet_fstype $facet) != zfs ]] ||
1464                         devname=$(mdsvdevname $num)
1465                 mv $devname $tmp/img
1466         done
1467         mv $OSTDEV1 $tmp/img
1468
1469         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1470                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1471         dst=$(cd $dst; pwd)
1472         pushd $tmp/img
1473         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1474         popd
1475
1476         rm -r $tmp
1477 }
1478 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1479
1480 #
1481 # The list of applicable tarballs is returned via the caller's
1482 # variable "tarballs".
1483 #
1484 t32_check() {
1485         local node=$(facet_active_host $SINGLEMDS)
1486         local r="do_node $node"
1487
1488         if [ "$CLIENTONLY" ]; then
1489                 skip "Client-only testing"
1490                 exit 0
1491         fi
1492
1493         if ! $r which $TUNEFS; then
1494                 skip_env "tunefs.lustre required on $node"
1495                 exit 0
1496         fi
1497
1498         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1499
1500         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 \
1501                    -name \'disk*-$IMGTYPE.tar.bz2\')
1502
1503         if [ -z "$tarballs" ]; then
1504                 skip "No applicable tarballs found"
1505                 exit 0
1506         fi
1507 }
1508
1509 t32_test_cleanup() {
1510         local tmp=$TMP/t32
1511         local facet=$SINGLEMDS
1512         local fstype=$(facet_fstype $facet)
1513         local rc=$?
1514
1515         if $shall_cleanup_lustre; then
1516                 umount $tmp/mnt/lustre || rc=$?
1517         fi
1518         if $shall_cleanup_mdt; then
1519                 $r $UMOUNT $tmp/mnt/mdt || rc=$?
1520         fi
1521         if $shall_cleanup_mdt1; then
1522                 $r $UMOUNT $tmp/mnt/mdt1 || rc=$?
1523         fi
1524         if $shall_cleanup_ost; then
1525                 $r $UMOUNT $tmp/mnt/ost || rc=$?
1526         fi
1527
1528         $r rm -rf $tmp
1529         rm -rf $tmp
1530         if [[ $fstype == zfs ]]; then
1531                 local poolname
1532                 local poolname_list="t32fs-mdt1 t32fs-ost1"
1533
1534                 ! $mdt2_is_available || poolname_list+=" t32fs-mdt2"
1535
1536                 for poolname in $poolname_list; do
1537                         destroy_zpool $facet $poolname
1538                 done
1539         fi
1540         combined_mgs_mds || start_mgs || rc=$?
1541         return $rc
1542 }
1543
1544 t32_bits_per_long() {
1545         #
1546         # Yes, this is not meant to be perfect.
1547         #
1548         case $1 in
1549                 ppc64|x86_64)
1550                         echo -n 64;;
1551                 i*86)
1552                         echo -n 32;;
1553         esac
1554 }
1555
1556 t32_reload_modules() {
1557         local node=$1
1558         local all_removed=false
1559         local i=0
1560
1561         while ((i < 20)); do
1562                 echo "Unloading modules on $node: Attempt $i"
1563                 do_rpc_nodes $node $LUSTRE_RMMOD $(facet_fstype $SINGLEMDS) &&
1564                         all_removed=true
1565                 do_rpc_nodes $node check_mem_leak || return 1
1566                 if $all_removed; then
1567                         do_rpc_nodes $node load_modules
1568                         return 0
1569                 fi
1570                 sleep 5
1571                 i=$((i + 1))
1572         done
1573         echo "Unloading modules on $node: Given up"
1574         return 1
1575 }
1576
1577 t32_wait_til_devices_gone() {
1578         local node=$1
1579         local devices
1580         local loops
1581         local i=0
1582
1583         echo wait for devices to go
1584         while ((i < 20)); do
1585                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1586                 loops=$(do_rpc_nodes $node losetup -a | grep -c t32)
1587                 ((devices == 0 && loops == 0)) && return 0
1588                 sleep 5
1589                 i=$((i + 1))
1590         done
1591         echo "waiting for dev on $node: dev $devices loop $loops given up"
1592         do_rpc_nodes $node "losetup -a"
1593         do_rpc_nodes $node "$LCTL device_list"
1594         return 1
1595 }
1596
1597 t32_verify_quota() {
1598         local node=$1
1599         local fsname=$2
1600         local mnt=$3
1601         local fstype=$(facet_fstype $SINGLEMDS)
1602         local qval
1603         local cmd
1604
1605         # LU-2435: if the underlying zfs doesn't support userobj_accounting,
1606         # lustre will estimate the object count usage. This fails quota
1607         # verification in 32b. The object quota usage should be accurate after
1608         # zfs-0.7.0 is released.
1609         [ $fstype == "zfs" ] && {
1610                 local zfs_version=$(do_node $node cat /sys/module/zfs/version)
1611
1612                 [ $(version_code $zfs_version) -lt $(version_code 0.7.0) ] && {
1613                         echo "Skip quota verify for zfs: $zfs_version"
1614                         return 0
1615                 }
1616         }
1617
1618         $LFS quota -u $T32_QID -v $mnt
1619
1620         qval=$($LFS quota -v -u $T32_QID $mnt |
1621                 awk 'BEGIN { num='1' } { if ($1 == "'$mnt'") \
1622                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1623                 | tr -d "*")
1624         [ $qval -eq $img_bspace ] || {
1625                 echo "bspace, act:$qval, exp:$img_bspace"
1626                 return 1
1627         }
1628
1629         qval=$($LFS quota -v -u $T32_QID $mnt |
1630                 awk 'BEGIN { num='5' } { if ($1 == "'$mnt'") \
1631                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1632                 | tr -d "*")
1633         [ $qval -eq $img_ispace ] || {
1634                 echo "ispace, act:$qval, exp:$img_ispace"
1635                 return 1
1636         }
1637
1638         qval=$($LFS quota -v -u $T32_QID $mnt |
1639                 awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
1640                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1641                 | tr -d "*")
1642         [ $qval -eq $img_blimit ] || {
1643                 echo "blimit, act:$qval, exp:$img_blimit"
1644                 return 1
1645         }
1646
1647         qval=$($LFS quota -v -u $T32_QID $mnt |
1648                 awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
1649                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1650                 | tr -d "*")
1651         [ $qval -eq $img_ilimit ] || {
1652                 echo "ilimit, act:$qval, exp:$img_ilimit"
1653                 return 1
1654         }
1655
1656         do_node $node $LCTL conf_param $fsname.quota.mdt=ug
1657         cmd="$LCTL get_param -n osd-$fstype.$fsname-MDT0000"
1658         cmd=$cmd.quota_slave.enabled
1659         wait_update $node "$cmd" "ug" || {
1660                 echo "Enable mdt quota failed"
1661                 return 1
1662         }
1663
1664         do_node $node $LCTL conf_param $fsname.quota.ost=ug
1665         cmd="$LCTL get_param -n osd-$fstype.$fsname-OST0000"
1666         cmd=$cmd.quota_slave.enabled
1667         wait_update $node "$cmd" "ug" || {
1668                 echo "Enable ost quota failed"
1669                 return 1
1670         }
1671
1672         chmod 0777 $mnt
1673         runas -u $T32_QID -g $T32_QID dd if=/dev/zero of=$mnt/t32_qf_new \
1674                 bs=1M count=$((img_blimit / 1024)) oflag=sync && {
1675                 echo "Write succeed, but expect -EDQUOT"
1676                 return 1
1677         }
1678         rm -f $mnt/t32_qf_new
1679
1680         runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
1681                 $img_ilimit && {
1682                 echo "Create succeed, but expect -EDQUOT"
1683                 return 1
1684         }
1685         unlinkmany $mnt/t32_qf_ $img_ilimit
1686
1687         return 0
1688 }
1689
1690 t32_test() {
1691         local tarball=$1
1692         local writeconf=$2
1693         local dne_upgrade=${dne_upgrade:-"no"}
1694         local ff_convert=${ff_convert:-"no"}
1695         local shall_cleanup_mdt=false
1696         local shall_cleanup_mdt1=false
1697         local shall_cleanup_ost=false
1698         local shall_cleanup_lustre=false
1699         local mdt2_is_available=false
1700         local node=$(facet_active_host $SINGLEMDS)
1701         local r="do_node $node"
1702         local tmp=$TMP/t32
1703         local img_commit
1704         local img_kernel
1705         local img_arch
1706         local img_bspace
1707         local img_ispace
1708         local img_blimit
1709         local img_ilimit
1710         local fsname=t32fs
1711         local nid
1712         local mopts
1713         local uuid
1714         local nrpcs_orig
1715         local nrpcs
1716         local list
1717         local fstype=$(facet_fstype $SINGLEMDS)
1718         local mdt_dev=$tmp/mdt
1719         local mdt2_dev=$tmp/mdt2
1720         local ost_dev=$tmp/ost
1721         local stripe_index
1722         local stripe_count
1723         local dir
1724
1725         combined_mgs_mds || stop_mgs || error "Unable to stop MGS"
1726         trap 'trap - RETURN; t32_test_cleanup' RETURN
1727
1728         load_modules
1729         nid=$($r $LCTL list_nids | head -1)
1730
1731         mkdir -p $tmp/mnt/lustre || error "mkdir $tmp/mnt/lustre failed"
1732         $r mkdir -p $tmp/mnt/{mdt,mdt1,ost}
1733         $r tar xjvf $tarball -S -C $tmp || {
1734                 error_noexit "Unpacking the disk image tarball"
1735                 return 1
1736         }
1737         img_commit=$($r cat $tmp/commit)
1738         img_kernel=$($r cat $tmp/kernel)
1739         img_arch=$($r cat $tmp/arch)
1740         img_bspace=$($r cat $tmp/bspace)
1741         img_ispace=$($r cat $tmp/ispace)
1742
1743         # older images did not have "blimit" and "ilimit" files
1744         # use old values for T32_BLIMIT and T32_ILIMIT
1745         $r test -f $tmp/blimit && img_blimit=$($r cat $tmp/blimit) ||
1746                 img_blimit=20480
1747         $r test -f $tmp/ilimit && img_ilimit=$($r cat $tmp/ilimit) ||
1748                 img_ilimit=2
1749
1750         echo "Upgrading from $(basename $tarball), created with:"
1751         echo "  Commit: $img_commit"
1752         echo "  Kernel: $img_kernel"
1753         echo "    Arch: $img_arch"
1754         echo "OST version: $(lustre_build_version ost1)"
1755
1756         # The conversion can be made only when both of the following
1757         # conditions are satisfied:
1758         # - ost device img version < 2.3.64
1759         # - ost server version >= 2.5
1760         [ $(version_code $img_commit) -ge $(version_code 2.3.64) -o \
1761                 $(lustre_version_code ost1) -lt $(version_code 2.5.0) ] &&
1762                         ff_convert="no"
1763
1764         ! $r test -f $mdt2_dev || mdt2_is_available=true
1765
1766         if [[ $fstype == zfs ]]; then
1767                 # import pool first
1768                 local poolname
1769                 local poolname_list="t32fs-mdt1 t32fs-ost1"
1770
1771                 ! $mdt2_is_available || poolname_list+=" t32fs-mdt2"
1772
1773                 for poolname in $poolname_list; do
1774                         $r "modprobe zfs;
1775                                 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1776                                 $ZPOOL import -f -d $tmp $poolname"
1777                 done
1778
1779                 # upgrade zpool to latest supported features, including
1780                 # dnode quota accounting in 0.7.0
1781                 $r "$ZPOOL upgrade -a"
1782
1783                 mdt_dev=t32fs-mdt1/mdt1
1784                 ost_dev=t32fs-ost1/ost1
1785                 ! $mdt2_is_available || mdt2_dev=t32fs-mdt2/mdt2
1786                 wait_update_facet $SINGLEMDS "$ZPOOL list |
1787                         awk '/^t32fs-mdt1/ { print \\\$1 }'" "t32fs-mdt1" || {
1788                                 error_noexit "import zfs pool failed"
1789                                 return 1
1790                         }
1791         fi
1792
1793         $r $LCTL set_param debug="$PTLDEBUG"
1794
1795         $r $TUNEFS --dryrun $mdt_dev || {
1796                 $r losetup -a
1797                 error_noexit "tunefs.lustre before mounting the MDT"
1798                 return 1
1799         }
1800
1801         if $mdt2_is_available; then
1802                 $r $TUNEFS --dryrun $mdt2_dev || {
1803                         $r losetup -a
1804                         error_noexit "tunefs.lustre before mounting the MDT"
1805                         return 1
1806                 }
1807         fi
1808
1809         if [ "$writeconf" ]; then
1810                 mopts=writeconf
1811                 if [ $fstype == "ldiskfs" ]; then
1812                         mopts="loop,$mopts"
1813                         $r $TUNEFS --quota $mdt_dev || {
1814                                 $r losetup -a
1815                                 error_noexit "Enable mdt quota feature"
1816                                 return 1
1817                         }
1818                         if $mdt2_is_available; then
1819                                 $r $TUNEFS --quota $mdt2_dev || {
1820                                         $r losetup -a
1821                                         error_noexit "Enable mdt quota feature"
1822                                         return 1
1823                                 }
1824                         fi
1825                 fi
1826         else
1827                 if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1828                         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
1829                         { skip "LU-2200: Cannot run over Inifiniband w/o lctl replace_nids "
1830                                 "(Need MGS version at least 2.3.59)"; return 0; }
1831
1832                         local osthost=$(facet_active_host ost1)
1833                         local ostnid=$(do_node $osthost $LCTL list_nids | head -1)
1834
1835                         mopts=nosvc
1836                         if [ $fstype == "ldiskfs" ]; then
1837                                 mopts="loop,$mopts"
1838                         fi
1839                         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt
1840                         $r $LCTL replace_nids $fsname-OST0000 $ostnid
1841                         $r $LCTL replace_nids $fsname-MDT0000 $nid
1842                         $r $UMOUNT $tmp/mnt/mdt
1843                 fi
1844
1845                 mopts=exclude=$fsname-OST0000
1846                 if [ $fstype == "ldiskfs" ]; then
1847                         mopts="loop,$mopts"
1848                 fi
1849         fi
1850
1851         t32_wait_til_devices_gone $node
1852
1853         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
1854                 $r losetup -a
1855                 error_noexit "Mounting the MDT"
1856                 return 1
1857         }
1858         shall_cleanup_mdt=true
1859
1860         if $mdt2_is_available; then
1861                 mopts=mgsnode=$nid,$mopts
1862                 $r $MOUNT_CMD -o $mopts $mdt2_dev $tmp/mnt/mdt1 || {
1863                         $r losetup -a
1864                         error_noexit "Mounting the MDT"
1865                         return 1
1866                 }
1867
1868                 echo "mount new MDT....$mdt2_dev"
1869                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
1870                         error_noexit "enable remote dir create failed"
1871
1872                 shall_cleanup_mdt1=true
1873         elif [ "$dne_upgrade" != "no" ]; then
1874                 local fs2mdsdev=$(mdsdevname 1_2)
1875                 local fs2mdsvdev=$(mdsvdevname 1_2)
1876
1877                 echo "mkfs new MDT on ${fs2mdsdev}...."
1878                 if [ $(facet_fstype mds1) == ldiskfs ]; then
1879                         mkfsoptions="--mkfsoptions=\\\"-J size=8\\\""
1880                 fi
1881
1882                 add $SINGLEMDS $(mkfs_opts mds2 $fs2mdsdev $fsname) --reformat \
1883                            $mkfsoptions $fs2mdsdev $fs2mdsvdev > /dev/null || {
1884                         error_noexit "Mkfs new MDT failed"
1885                         return 1
1886                 }
1887
1888                 [[ $(facet_fstype mds1) != zfs ]] || import_zpool mds1
1889
1890                 $r $TUNEFS --dryrun $fs2mdsdev || {
1891                         error_noexit "tunefs.lustre before mounting the MDT"
1892                         return 1
1893                 }
1894
1895                 echo "mount new MDT....$fs2mdsdev"
1896                 $r $MOUNT_CMD -o $mopts $fs2mdsdev $tmp/mnt/mdt1 || {
1897                         error_noexit "mount mdt1 failed"
1898                         return 1
1899                 }
1900
1901                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
1902                         error_noexit "enable remote dir create failed"
1903
1904                 shall_cleanup_mdt1=true
1905         fi
1906
1907         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1908                 error_noexit "Getting MDT UUID"
1909                 return 1
1910         }
1911         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1912                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1913                 return 1
1914         fi
1915
1916         $r $TUNEFS --dryrun $ost_dev || {
1917                 error_noexit "tunefs.lustre before mounting the OST"
1918                 return 1
1919         }
1920         if [ "$writeconf" ]; then
1921                 mopts=mgsnode=$nid,$writeconf
1922                 if [ $fstype == "ldiskfs" ]; then
1923                         mopts="loop,$mopts"
1924                         $r $TUNEFS --quota $ost_dev || {
1925                                 $r losetup -a
1926                                 error_noexit "Enable ost quota feature"
1927                                 return 1
1928                         }
1929                 fi
1930         else
1931                 mopts=mgsnode=$nid
1932                 if [ $fstype == "ldiskfs" ]; then
1933                         mopts="loop,$mopts"
1934                 fi
1935         fi
1936
1937         $r $MOUNT_CMD -onomgs -o$mopts $ost_dev $tmp/mnt/ost || {
1938                 error_noexit "Mounting the OST"
1939                 return 1
1940         }
1941         shall_cleanup_ost=true
1942
1943         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1944                 error_noexit "Getting OST UUID"
1945                 return 1
1946         }
1947         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1948                 error_noexit "Unexpected OST UUID: \"$uuid\""
1949                 return 1
1950         fi
1951
1952         $r $LCTL conf_param $fsname-OST0000.osc.max_dirty_mb=15 || {
1953                 error_noexit "Setting \"max_dirty_mb\""
1954                 return 1
1955         }
1956         $r $LCTL conf_param $fsname-OST0000.failover.node=$nid || {
1957                 error_noexit "Setting OST \"failover.node\""
1958                 return 1
1959         }
1960         $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1961                 error_noexit "Setting \"max_rpcs_in_flight\""
1962                 return 1
1963         }
1964         $r $LCTL conf_param $fsname-MDT0000.failover.node=$nid || {
1965                 error_noexit "Setting MDT \"failover.node\""
1966                 return 1
1967         }
1968         $r $LCTL pool_new $fsname.interop || {
1969                 error_noexit "Setting \"interop\""
1970                 return 1
1971         }
1972         $r $LCTL conf_param $fsname-MDT0000.lov.stripesize=4M || {
1973                 error_noexit "Setting \"lov.stripesize\""
1974                 return 1
1975         }
1976         $r $LCTL conf_param $fsname-MDT0000.mdd.atime_diff=70 || {
1977                 error_noexit "Setting \"mdd.atime_diff\""
1978                 return 1
1979         }
1980
1981         if [ "$ff_convert" != "no" -a $(facet_fstype ost1) == "ldiskfs" ]; then
1982                 $r $LCTL lfsck_start -M $fsname-OST0000 || {
1983                         error_noexit "Start OI scrub on OST0"
1984                         return 1
1985                 }
1986
1987                 # The oi_scrub should be on ost1, but for test_32(),
1988                 # all on the SINGLEMDS.
1989                 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1990                         osd-ldiskfs.$fsname-OST0000.oi_scrub |
1991                         awk '/^status/ { print \\\$2 }'" "completed" 30 || {
1992                         error_noexit "Failed to get the expected 'completed'"
1993                         return 1
1994                 }
1995
1996                 local UPDATED=$($r $LCTL get_param -n \
1997                                 osd-ldiskfs.$fsname-OST0000.oi_scrub |
1998                                 awk '/^updated/ { print $2 }')
1999                 [ $UPDATED -ge 1 ] || {
2000                         error_noexit "Only $UPDATED objects have been converted"
2001                         return 1
2002                 }
2003         fi
2004
2005         if [ "$dne_upgrade" != "no" ]; then
2006                 $r $LCTL conf_param \
2007                                 $fsname-MDT0001.mdc.max_rpcs_in_flight=9 || {
2008                         error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
2009                         return 1
2010                 }
2011                 $r $LCTL conf_param $fsname-MDT0001.failover.node=$nid || {
2012                         error_noexit "Setting MDT1 \"failover.node\""
2013                         return 1
2014                 }
2015                 $r $LCTL conf_param $fsname-MDT0001.lov.stripesize=4M || {
2016                         error_noexit "Setting MDT1 \"lov.stripesize\""
2017                         return 1
2018                 }
2019         fi
2020
2021         if [ "$writeconf" ]; then
2022                 $MOUNT_CMD $nid:/$fsname $tmp/mnt/lustre || {
2023                         error_noexit "Mounting the client"
2024                         return 1
2025                 }
2026
2027                 shall_cleanup_lustre=true
2028                 $r $LCTL set_param debug="$PTLDEBUG"
2029
2030                 t32_verify_quota $node $fsname $tmp/mnt/lustre || {
2031                         error_noexit "verify quota failed"
2032                         return 1
2033                 }
2034
2035                 if $r test -f $tmp/list; then
2036                         #
2037                         # There is not a Test Framework API to copy files to or
2038                         # from a remote node.
2039                         #
2040                         # LU-2393 - do both sorts on same node to ensure locale
2041                         # is identical
2042                         local list_file=$tmp/list
2043
2044                         if $mdt2_is_available; then
2045                                 if [[ -d $tmp/mnt/lustre/striped_dir_old ]] &&
2046                                    $r test -f $tmp/list2; then
2047                                         list_file=$tmp/list2
2048                                         pushd $tmp/mnt/lustre/striped_dir_old
2049                                 else
2050                                         pushd $tmp/mnt/lustre/remote_dir
2051                                 fi
2052                         else
2053                                 pushd $tmp/mnt/lustre
2054                         fi
2055                         $r cat $list_file | sort -k 6 >$tmp/list.orig
2056                         ls -Rni --time-style=+%s | sort -k 6 |
2057                                 sed 's/\. / /' >$tmp/list || {
2058                                 error_noexit "ls"
2059                                 return 1
2060                         }
2061                         popd
2062                         #
2063                         # 32-bit and 64-bit clients use different algorithms to
2064                         # convert FIDs into inode numbers.  Hence, remove the
2065                         # inode numbers from the lists, if the original list was
2066                         # created on an architecture with different number of
2067                         # bits per "long".
2068                         #
2069                         if [ $(t32_bits_per_long $(uname -m)) != \
2070                                 $(t32_bits_per_long $img_arch) ]; then
2071                                 echo "Different number of bits per \"long\"" \
2072                                      "from the disk image"
2073                                 for list in list.orig list; do
2074                                         sed -i -e 's/^[0-9]\+[ \t]\+//' \
2075                                                   $tmp/$list
2076                                 done
2077                         fi
2078                         if ! diff -ub $tmp/list.orig $tmp/list; then
2079                                 error_noexit "list verification failed"
2080                                 return 1
2081                         fi
2082                 else
2083                         echo "list verification skipped"
2084                 fi
2085
2086                 if [ "$dne_upgrade" != "no" ]; then
2087                         $LFS mkdir -i 1 -c2 $tmp/mnt/lustre/striped_dir || {
2088                                 error_noexit "set striped dir failed"
2089                                 return 1
2090                         }
2091
2092                         $LFS setdirstripe -D -c2 $tmp/mnt/lustre/striped_dir
2093
2094                         pushd $tmp/mnt/lustre
2095                         tar -cf - . --exclude=./striped_dir \
2096                                     --exclude=./striped_dir_old \
2097                                     --exclude=./remote_dir |
2098                                 tar -xvf - -C striped_dir 1>/dev/null || {
2099                                 error_noexit "cp to striped dir failed"
2100                                 return 1
2101                         }
2102                         popd
2103                 fi
2104
2105                 # If it is upgrade from DNE (2.5), then rename the remote dir,
2106                 # which is created in 2.5 to striped dir.
2107                 if $mdt2_is_available && [[ "$dne_upgrade" != "no" ]]; then
2108                         stripe_index=$($LFS getdirstripe -i     \
2109                                        $tmp/mnt/lustre/remote_dir)
2110
2111                         [[ $stripe_index -eq 1 ]] || {
2112                                 error_noexit "get index \"$stripe_index\"" \
2113                                              "from remote dir failed"
2114                                 return 1
2115                         }
2116                         mv $tmp/mnt/lustre/remote_dir   \
2117                                 $tmp/mnt/lustre/striped_dir/ || {
2118                                 error_noexit "mv remote dir failed"
2119                                 return 1
2120                         }
2121                 fi
2122
2123                 # If it is upgraded from DNE (2.7), then move the striped dir
2124                 # which was created in 2.7 to the new striped dir.
2125                 if $mdt2_is_available && [[ "$dne_upgrade" != "no" ]] &&
2126                         [[ -d $tmp/mnt/lustre/striped_dir_old ]]; then
2127                         stripe_count=$($LFS getdirstripe -c     \
2128                                        $tmp/mnt/lustre/striped_dir_old)
2129                         [[ $stripe_count -eq 2 ]] || {
2130                                 error_noexit "get count $stripe_count" \
2131                                              "from striped dir failed"
2132                                 return 1
2133                         }
2134                         mv $tmp/mnt/lustre/striped_dir_old      \
2135                                 $tmp/mnt/lustre/striped_dir/ || {
2136                                 error_noexit "mv striped dir failed"
2137                                 return 1
2138                         }
2139                 fi
2140
2141                 sync; sleep 5; sync
2142                 $r $LCTL set_param -n osd*.*.force_sync=1
2143                 dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
2144                         error_noexit "dd failed"
2145                         return 1
2146                 }
2147                 rm -rf $tmp/mnt/lustre/tmp_file || {
2148                         error_noexit "rm failed"
2149                         return 1
2150                 }
2151
2152                 if $r test -f $tmp/sha1sums; then
2153                         # LU-2393 - do both sorts on same node to ensure locale
2154                         # is identical
2155                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
2156                         if [ "$dne_upgrade" != "no" ]; then
2157                                 pushd $tmp/mnt/lustre/striped_dir
2158                         else
2159                                 pushd $tmp/mnt/lustre
2160                         fi
2161
2162                         find ! -path "*remote_dir*" ! -path "*striped_dir*" \
2163                                 ! -name .lustre -type f -exec sha1sum {} \; |
2164                                 sort -k 2 >$tmp/sha1sums || {
2165                                 popd
2166                                 error_noexit "sha1sum"
2167                                 return 1
2168                         }
2169                         popd
2170                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
2171                                 error_noexit "sha1sum verification failed"
2172                                 return 1
2173                         fi
2174
2175                         # if upgrade from DNE(2.5), then check remote directory
2176                         # if upgrade from DNE(2.7), then check striped directory
2177                         if $mdt2_is_available &&
2178                            [[ "$dne_upgrade" != "no" ]]; then
2179                                 local new_dir="$tmp/mnt/lustre/striped_dir"
2180                                 local striped_dir_old="$new_dir/striped_dir_old"
2181
2182                                 local dir_list="$new_dir/remote_dir"
2183                                 [[ ! -d $triped_dir_old ]] ||
2184                                         dir_list+=" $striped_dir_old"
2185
2186                                 for dir in $dir_list; do
2187                                         pushd $dir
2188                                         find ! -name .lustre -type f    \
2189                                                 -exec sha1sum {} \; |
2190                                                 sort -k 2 >$tmp/sha1sums || {
2191                                                         popd
2192                                                         error_noexit "sha1sum"
2193                                                         return 1
2194                                                 }
2195                                         popd
2196                                         if ! diff -ub $tmp/sha1sums.orig \
2197                                                 $tmp/sha1sums; then
2198                                                 error_noexit "sha1sum $dir" \
2199                                                              "failed"
2200                                                 return 1
2201                                         fi
2202                                 done
2203                         fi
2204                 else
2205                         echo "sha1sum verification skipped"
2206                 fi
2207
2208                 if [ "$dne_upgrade" != "no" ]; then
2209                         rm -rf $tmp/mnt/lustre/striped_dir || {
2210                                 error_noexit "remove remote dir failed"
2211                                 return 1
2212                         }
2213                 fi
2214
2215                 # migrate files/dirs to remote MDT, then move them back
2216                 if [ $(lustre_version_code mds1) -ge $(version_code 2.7.50) -a \
2217                      $dne_upgrade != "no" ]; then
2218                         $r $LCTL set_param -n   \
2219                                 mdt.${fsname}*.enable_remote_dir=1 2>/dev/null
2220
2221                         echo "test migration"
2222                         pushd $tmp/mnt/lustre
2223                         for dir in $(find ! -name .lustre ! -name . -type d); do
2224                                 mdt_index=$($LFS getdirstripe -i $dir)
2225                                 stripe_cnt=$($LFS getdirstripe -c $dir)
2226                                 if [ $mdt_index = 0 -a $stripe_cnt -le 1 ]; then
2227                                         $LFS mv -M 1 $dir || {
2228                                         popd
2229                                         error_noexit "migrate MDT1 failed"
2230                                         return 1
2231                                 }
2232                                 fi
2233                         done
2234
2235                         for dir in $(find ! -name . ! -name .lustre -type d); do
2236                                 mdt_index=$($LFS getdirstripe -i $dir)
2237                                 stripe_cnt=$($LFS getdirstripe -c $dir)
2238                                 if [ $mdt_index = 1 -a $stripe_cnt -le 1 ]; then
2239                                         $LFS mv -M 0 $dir || {
2240                                         popd
2241                                         error_noexit "migrate MDT0 failed"
2242                                         return 1
2243                                 }
2244                                 fi
2245                         done
2246                         popd
2247                 fi
2248
2249                 #
2250                 # When adding new data verification tests, please check for
2251                 # the presence of the required reference files first, like
2252                 # the "sha1sums" and "list" tests above, to avoid the need to
2253                 # regenerate every image for each test addition.
2254                 #
2255
2256                 nrpcs_orig=$($LCTL get_param \
2257                                 -n mdc.*MDT0000*.max_rpcs_in_flight) || {
2258                         error_noexit "Getting \"max_rpcs_in_flight\""
2259                         return 1
2260                 }
2261                 nrpcs=$((nrpcs_orig + 5))
2262                 $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=$nrpcs || {
2263                         error_noexit "Changing \"max_rpcs_in_flight\""
2264                         return 1
2265                 }
2266                 wait_update $HOSTNAME "$LCTL get_param \
2267                         -n mdc.*MDT0000*.max_rpcs_in_flight" $nrpcs || {
2268                         error_noexit "Verifying \"max_rpcs_in_flight\""
2269                         return 1
2270                 }
2271
2272                 umount $tmp/mnt/lustre || {
2273                         error_noexit "Unmounting the client"
2274                         return 1
2275                 }
2276                 shall_cleanup_lustre=false
2277         else
2278                 if [[ "$dne_upgrade" != "no" ]] || $mdt2_is_available; then
2279                         $r $UMOUNT $tmp/mnt/mdt1 || {
2280                                 error_noexit "Unmounting the MDT2"
2281                                 return 1
2282                         }
2283                         shall_cleanup_mdt1=false
2284                 fi
2285
2286                 $r $UMOUNT $tmp/mnt/mdt || {
2287                         error_noexit "Unmounting the MDT"
2288                         return 1
2289                 }
2290                 shall_cleanup_mdt=false
2291
2292                 $r $UMOUNT $tmp/mnt/ost || {
2293                         error_noexit "Unmounting the OST"
2294                         return 1
2295                 }
2296                 shall_cleanup_ost=false
2297
2298                 t32_reload_modules $node || {
2299                         error_noexit "Reloading modules"
2300                         return 1
2301                 }
2302
2303                 if [[ $fstype == zfs ]]; then
2304                         local poolname=t32fs-mdt1
2305                         $r "modprobe zfs;
2306                             $ZPOOL list -H $poolname >/dev/null 2>&1 ||
2307                                 $ZPOOL import -f -d $tmp $poolname"
2308
2309                         # upgrade zpool to latest supported features,
2310                         # including dnode quota accounting in 0.7.0
2311                         $r "$ZPOOL upgrade $poolname"
2312                 fi
2313
2314                 # mount a second time to make sure we didnt leave upgrade flag on
2315                 $r $TUNEFS --dryrun $mdt_dev || {
2316                         $r losetup -a
2317                         error_noexit "tunefs.lustre before remounting the MDT"
2318                         return 1
2319                 }
2320
2321                 mopts=exclude=$fsname-OST0000
2322                 if [ $fstype == "ldiskfs" ]; then
2323                         mopts="loop,$mopts"
2324                 fi
2325                 $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
2326                         error_noexit "Remounting the MDT"
2327                         return 1
2328                 }
2329                 shall_cleanup_mdt=true
2330         fi
2331 }
2332
2333 test_32a() {
2334         local tarballs
2335         local tarball
2336         local rc=0
2337
2338         t32_check
2339         for tarball in $tarballs; do
2340                 t32_test $tarball || let "rc += $?"
2341         done
2342         return $rc
2343 }
2344 run_test 32a "Upgrade (not live)"
2345
2346 test_32b() {
2347         local tarballs
2348         local tarball
2349         local rc=0
2350
2351         t32_check
2352         for tarball in $tarballs; do
2353                 t32_test $tarball writeconf || let "rc += $?"
2354         done
2355         return $rc
2356 }
2357 run_test 32b "Upgrade with writeconf"
2358
2359 test_32c() {
2360         local tarballs
2361         local tarball
2362         local rc=0
2363
2364         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2365         t32_check
2366         for tarball in $tarballs; do
2367                 # Do not support 1_8 and 2_1 direct upgrade to DNE2 anymore */
2368                 echo $tarball | grep "1_8" && continue
2369                 echo $tarball | grep "2_1" && continue
2370                 load_modules
2371                 dne_upgrade=yes t32_test $tarball writeconf || rc=$?
2372         done
2373         return $rc
2374 }
2375 run_test 32c "dne upgrade test"
2376
2377 test_32d() {
2378         local tarballs
2379         local tarball
2380         local rc=0
2381
2382         t32_check
2383         for tarball in $tarballs; do
2384                 ff_convert=yes t32_test $tarball || rc=$?
2385         done
2386         return $rc
2387 }
2388 run_test 32d "convert ff test"
2389
2390 test_33a() { # bug 12333, was test_33
2391         local FSNAME2=test-123
2392         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2393         local mkfsoptions
2394
2395         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
2396
2397         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
2398                 local dev=${SINGLEMDS}_dev
2399                 local MDSDEV=${!dev}
2400                 is_blkdev $SINGLEMDS $MDSDEV &&
2401                         skip_env "mixed loopback and real device not working" &&
2402                         return
2403         fi
2404
2405         local fs2mdsdev=$(mdsdevname 1_2)
2406         local fs2ostdev=$(ostdevname 1_2)
2407         local fs2mdsvdev=$(mdsvdevname 1_2)
2408         local fs2ostvdev=$(ostvdevname 1_2)
2409
2410         if [ $(facet_fstype mds1) == ldiskfs ]; then
2411                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
2412         fi
2413
2414         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2415                 --reformat $mkfsoptions $fs2mdsdev $fs2mdsvdev || exit 10
2416         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2417                 --fsname=${FSNAME2} --index=8191 --reformat $fs2ostdev \
2418                 $fs2ostvdev || exit 10
2419
2420         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
2421         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2422         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" ||
2423                 error "$LCTL conf_param $FSNAME2.sys.timeout=200 failed"
2424         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
2425         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
2426         echo "ok."
2427
2428         cp /etc/hosts $MOUNT2/ || error "copy /etc/hosts $MOUNT2/ failed"
2429         $GETSTRIPE $MOUNT2/hosts || error "$GETSTRIPE $MOUNT2/hosts failed"
2430
2431         umount $MOUNT2
2432         stop fs2ost -f
2433         stop fs2mds -f
2434         cleanup_nocli || error "cleanup_nocli failed with $?"
2435 }
2436 run_test 33a "Mount ost with a large index number"
2437
2438 test_33b() {    # was test_34
2439         setup
2440
2441         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
2442         # Drop lock cancelation reply during umount
2443         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
2444         do_facet client $LCTL set_param fail_loc=0x80000304
2445         #lctl set_param debug=-1
2446         umount_client $MOUNT
2447         cleanup || error "cleanup failed with $?"
2448 }
2449 run_test 33b "Drop cancel during umount"
2450
2451 test_34a() {
2452         setup
2453         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
2454         manual_umount_client
2455         rc=$?
2456         do_facet client killall -USR1 multiop
2457         if [ $rc -eq 0 ]; then
2458                 error "umount not fail!"
2459         fi
2460         sleep 1
2461         cleanup || error "cleanup failed with rc $?"
2462 }
2463 run_test 34a "umount with opened file should be fail"
2464
2465 test_34b() {
2466         setup
2467         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2468         stop_mds || error "Unable to stop MDS"
2469
2470         manual_umount_client --force || error "mtab after failed umount with $?"
2471
2472         cleanup || error "cleanup failed with $?"
2473 }
2474 run_test 34b "force umount with failed mds should be normal"
2475
2476 test_34c() {
2477         setup
2478         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2479         stop_ost || error "Unable to stop OST1"
2480
2481         manual_umount_client --force || error "mtab after failed umount with $?"
2482
2483         cleanup || error "cleanup failed with $?"
2484 }
2485 run_test 34c "force umount with failed ost should be normal"
2486
2487 test_35a() { # bug 12459
2488         setup
2489
2490         DBG_SAVE="`$LCTL get_param -n debug`"
2491         $LCTL set_param debug="ha"
2492
2493         log "Set up a fake failnode for the MDS"
2494         FAKENID="127.0.0.2"
2495         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2496                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2497         do_facet mgs "$LCTL conf_param \
2498                       ${device}.failover.node=$(h2nettype $FAKENID)" ||
2499                 error "Setting ${device}.failover.node=\
2500                        $(h2nettype $FAKENID) failed."
2501
2502         log "Wait for RECONNECT_INTERVAL seconds (10s)"
2503         sleep 10
2504
2505         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
2506         $LCTL clear
2507         log "$MSG"
2508         log "Stopping the MDT: $device"
2509         stop_mdt 1 || error "MDT0 stop fail"
2510
2511         df $MOUNT > /dev/null 2>&1 &
2512         DFPID=$!
2513         log "Restarting the MDT: $device"
2514         start_mdt 1 || error "MDT0 start fail"
2515         log "Wait for df ($DFPID) ... "
2516         wait $DFPID
2517         log "done"
2518         $LCTL set_param debug="$DBG_SAVE"
2519
2520         # retrieve from the log the first server that the client tried to
2521         # contact after the connection loss
2522         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2523         NEXTCONN=`awk "/${MSG}/ {start = 1;}
2524                        /import_select_connection.*$device-mdc.* using connection/ {
2525                                 if (start) {
2526                                         if (\\\$NF ~ /$FAKENID/)
2527                                                 print \\\$NF;
2528                                         else
2529                                                 print 0;
2530                                         exit;
2531                                 }
2532                        }" $TMP/lustre-log-$TESTNAME.log`
2533         [ "$NEXTCONN" != "0" ] &&
2534                 error "Tried to connect to ${NEXTCONN} not last active server"
2535         cleanup || error "cleanup failed with $?"
2536         # remove nid settings
2537         writeconf_or_reformat
2538 }
2539 run_test 35a "Reconnect to the last active server first"
2540
2541 test_35b() { # bug 18674
2542         remote_mds || { skip "local MDS" && return 0; }
2543         setup
2544
2545         debugsave
2546         $LCTL set_param debug="ha"
2547         $LCTL clear
2548         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
2549         log "$MSG"
2550
2551         log "Set up a fake failnode for the MDS"
2552         FAKENID="127.0.0.2"
2553         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2554                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2555         do_facet mgs "$LCTL conf_param \
2556                       ${device}.failover.node=$(h2nettype $FAKENID)" ||
2557                 error "Set ${device}.failover.node=\
2558                        $(h2nettype $FAKENID) failed"
2559
2560         local at_max_saved=0
2561         # adaptive timeouts may prevent seeing the issue
2562         if at_is_enabled; then
2563                 at_max_saved=$(at_max_get mds)
2564                 at_max_set 0 mds client
2565         fi
2566
2567         mkdir $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
2568
2569         log "Injecting EBUSY on MDS"
2570         # Setting OBD_FAIL_MDS_RESEND=0x136
2571         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" ||
2572                 error "unable to set param fail_loc=0x80000136"
2573
2574         $LCTL set_param mdc.${FSNAME}*.stats=clear
2575
2576         log "Creating a test file and stat it"
2577         touch $MOUNT/$tdir/$tfile || error "touch $MOUNT/$tdir/$tfile failed"
2578         stat $MOUNT/$tdir/$tfile
2579
2580         log "Stop injecting EBUSY on MDS"
2581         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" ||
2582                 error "unable to set param fail_loc=0"
2583         rm -f $MOUNT/$tdir/$tfile || error "remove $MOUNT/$tdir/$tfile failed"
2584
2585         log "done"
2586         # restore adaptive timeout
2587         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
2588
2589         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2590
2591         CONNCNT=$($LCTL get_param mdc.${FSNAME}*.stats |
2592                   awk '/mds_connect/{print $2}')
2593
2594         # retrieve from the log if the client has ever tried to
2595         # contact the fake server after the loss of connection
2596         FAILCONN=`awk "BEGIN {ret = 0;}
2597                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
2598                                 ret = 1;
2599                                 if (\\\$NF ~ /$FAKENID/) {
2600                                         ret = 2;
2601                                         exit;
2602                                 }
2603                        }
2604                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
2605
2606         [ "$FAILCONN" == "0" ] &&
2607                 error "The client reconnection has not been triggered"
2608         [ "$FAILCONN" == "2" ] &&
2609                 error "Primary server busy, client reconnect to failover failed"
2610
2611         # LU-290
2612         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
2613         # Reconnects are supposed to be rate limited to one every 5s
2614         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] &&
2615                 error "Too many reconnects $CONNCNT"
2616
2617         cleanup || error "cleanup failed with $?"
2618         # remove nid settings
2619         writeconf_or_reformat
2620 }
2621 run_test 35b "Continue reconnection retries, if the active server is busy"
2622
2623 test_36() { # 12743
2624         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs" && return
2625
2626         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] ||
2627                 { skip "remote OST" && return 0; }
2628
2629         local rc=0
2630         local FSNAME2=test1234
2631         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2632
2633         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
2634
2635         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
2636                 is_blkdev $SINGLEMDS $MDSDEV &&
2637                 skip_env "mixed loopback and real device not working" && return
2638         fi
2639
2640         local fs2mdsdev=$(mdsdevname 1_2)
2641         local fs2ostdev=$(ostdevname 1_2)
2642         local fs3ostdev=$(ostdevname 2_2)
2643         local fs2mdsvdev=$(mdsvdevname 1_2)
2644         local fs2ostvdev=$(ostvdevname 1_2)
2645         local fs3ostvdev=$(ostvdevname 2_2)
2646
2647         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2648                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
2649         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
2650         #     different one than the default value here.
2651         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2652                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
2653         add fs3ost $(mkfs_opts ost2 ${fs3ostdev}) --mgsnode=$MGSNID \
2654                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
2655
2656         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
2657         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2658         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
2659         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
2660         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
2661
2662         sleep 5 # until 11778 fixed
2663
2664         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || error "dd failed"
2665
2666         BKTOTAL=$($LCTL get_param -n obdfilter.*.kbytestotal |
2667                   awk 'BEGIN{total=0}; {total+=$1}; END{print total}')
2668         BKFREE=$($LCTL get_param -n obdfilter.*.kbytesfree |
2669                  awk 'BEGIN{free=0}; {free+=$1}; END{print free}')
2670         BKAVAIL=$($LCTL get_param -n obdfilter.*.kbytesavail |
2671                   awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
2672         STRING=$(df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}')
2673         DFTOTAL=$(echo $STRING | cut -d, -f1)
2674         DFUSED=$(echo $STRING  | cut -d, -f2)
2675         DFAVAIL=$(echo $STRING | cut -d, -f3)
2676         DFFREE=$(($DFTOTAL - $DFUSED))
2677
2678         ALLOWANCE=$((64 * $OSTCOUNT))
2679
2680         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
2681            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
2682                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
2683                 rc=1
2684         fi
2685         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
2686            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
2687                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
2688                 rc=2
2689         fi
2690         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
2691            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
2692                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
2693                 rc=3
2694        fi
2695
2696         $UMOUNT $MOUNT2
2697         stop fs3ost -f || error "unable to stop OST3"
2698         stop fs2ost -f || error "unable to stop OST2"
2699         stop fs2mds -f || error "unable to stop second MDS"
2700         unload_modules_conf || error "unable unload modules"
2701         return $rc
2702 }
2703 run_test 36 "df report consistency on OSTs with different block size"
2704
2705 test_37() {
2706         local mntpt=$(facet_mntpt $SINGLEMDS)
2707         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
2708         local mdsdev_sym="$TMP/sym_mdt.img"
2709         local opts=$MDS_MOUNT_OPTS
2710         local rc=0
2711
2712         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2713                 skip "ldiskfs only test"
2714                 return
2715         fi
2716
2717         echo "MDS :     $mdsdev"
2718         echo "SYMLINK : $mdsdev_sym"
2719         do_facet $SINGLEMDS rm -f $mdsdev_sym
2720
2721         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
2722
2723         echo "mount symlink device - $mdsdev_sym"
2724
2725         if ! do_facet $SINGLEMDS test -b $mdsdev; then
2726                 opts=$(csa_add "$opts" -o loop)
2727         fi
2728         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
2729                 $mdsdev_sym $mntpt 2>&1)
2730         rc=${PIPESTATUS[0]}
2731
2732         echo mount_op=$mount_op
2733
2734         do_facet $SINGLEMDS "$UMOUNT $mntpt && rm -f $mdsdev_sym"
2735
2736         if $(echo $mount_op | grep -q "unable to set tunable"); then
2737                 error "set tunables failed for symlink device"
2738         fi
2739
2740         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
2741 }
2742 run_test 37 "verify set tunables works for symlink device"
2743
2744 test_38() { # bug 14222
2745         local fstype=$(facet_fstype $SINGLEMDS)
2746         local mntpt=$(facet_mntpt $SINGLEMDS)
2747
2748         setup
2749         # like runtests
2750         local COUNT=10
2751         local SRC="/etc /bin"
2752         local FILES=$(find $SRC -type f -mtime +1 | head -n $COUNT)
2753         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
2754         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2755         tar cf - $FILES | tar xf - -C $DIR/$tdir ||
2756                 error "copying $SRC to $DIR/$tdir"
2757         sync
2758         umount_client $MOUNT || error "umount_client $MOUNT failed"
2759         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2760         stop_mds || error "Unable to stop MDS"
2761         log "delete lov_objid file on MDS"
2762
2763         mount_fstype $SINGLEMDS || error "mount MDS failed (1)"
2764
2765         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid; rm $mntpt/lov_objid"
2766
2767         unmount_fstype $SINGLEMDS || error "umount failed (1)"
2768
2769         # check create in mds_lov_connect
2770         start_mds || error "unable to start MDS"
2771         mount_client $MOUNT || error "mount_client $MOUNT failed"
2772         for f in $FILES; do
2773                 [ $V ] && log "verifying $DIR/$tdir/$f"
2774                 diff -q $f $DIR/$tdir/$f || ERROR=y
2775         done
2776         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2777         if [ "$ERROR" = "y" ]; then
2778                 # check it's updates in sync
2779                 umount_client $MOUNT
2780                 stop_mds
2781                 mount_fstype $SIGNLEMDS
2782                 do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2783                 unmount_fstype $SINGLEMDS
2784                 error "old and new files are different after connect" || true
2785         fi
2786         touch $DIR/$tdir/f2 || error "f2 file create failed"
2787
2788         # check it's updates in sync
2789         umount_client $MOUNT || error "second umount_client $MOUNT failed"
2790         stop_mds
2791
2792         mount_fstype $SINGLEMDS || error "mount MDS failed (3)"
2793
2794         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2795         do_facet $SINGLEMDS dd if=/dev/zero of=$mntpt/lov_objid.clear count=8
2796
2797         unmount_fstype $SINGLEMDS || error "umount failed (3)"
2798
2799         start_mds || error "unable to start MDS"
2800         mount_client $MOUNT || error "mount_client $MOUNT failed"
2801         for f in $FILES; do
2802                 [ $V ] && log "verifying $DIR/$tdir/$f"
2803                 diff -q $f $DIR/$tdir/$f || ERROR=y
2804         done
2805         touch $DIR/$tdir/f3 || error "f3 file create failed"
2806         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2807         umount_client $MOUNT || error "third umount_client $MOUNT failed"
2808         stop_mds
2809         mount_fstype $SINGLEMDS || error "mount MDS failed (4)"
2810         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2811         unmount_fstype $SINGLEMDS || error "umount failed (4)"
2812
2813         [ "$ERROR" = "y" ] &&
2814                 error "old and new files are different after sync" || true
2815
2816         log "files compared the same"
2817         cleanup || error "cleanup failed with $?"
2818 }
2819 run_test 38 "MDS recreates missing lov_objid file from OST data"
2820
2821 test_39() {
2822         PTLDEBUG=+malloc
2823         setup
2824         cleanup || error "cleanup failed with $?"
2825         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2826                 error "memory leak detected" || true
2827 }
2828 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2829
2830 test_40() { # bug 15759
2831         start_ost || error "Unable to start OST1"
2832         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2833         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2834         start_mds
2835         cleanup || error "cleanup failed with rc $?"
2836 }
2837 run_test 40 "race during service thread startup"
2838
2839 test_41a() { #bug 14134
2840         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2841            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2842                 skip "Loop devices does not work with nosvc option"
2843                 return
2844         fi
2845
2846         combined_mgs_mds ||
2847                 { skip "needs combined MGT and MDT device" && return 0; }
2848
2849         start_mdt 1 -o nosvc -n
2850         if [ $MDSCOUNT -ge 2 ]; then
2851                 for num in $(seq 2 $MDSCOUNT); do
2852                         start_mdt $num || return
2853                 done
2854         fi
2855         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
2856         start_mdt 1 -o nomgs,force
2857         mount_client $MOUNT || error "mount_client $MOUNT failed"
2858         sleep 5
2859
2860         echo "blah blah" > $MOUNT/$tfile
2861         cat $MOUNT/$tfile
2862
2863         umount_client $MOUNT || error "umount_client $MOUNT failed"
2864         stop ost1 -f || error "unable to stop OST1"
2865         stop_mds || error "Unable to stop MDS"
2866         stop_mds || error "Unable to stop MDS on second try"
2867 }
2868 run_test 41a "mount mds with --nosvc and --nomgs"
2869
2870 test_41b() {
2871         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2872            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2873                 skip "Loop devices does not work with nosvc option"
2874                 return
2875         fi
2876
2877         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2878
2879         stopall
2880         reformat
2881         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2882
2883         start_mdt 1 -o nosvc -n
2884         if [ $MDSCOUNT -ge 2 ]; then
2885                 for num in $(seq 2 $MDSCOUNT); do
2886                         start_mdt $num || return
2887                 done
2888         fi
2889         start_ost || error "Unable to start OST1"
2890         start_mdt 1 -o nomgs,force
2891         mount_client $MOUNT || error "mount_client $MOUNT failed"
2892         sleep 5
2893
2894         echo "blah blah" > $MOUNT/$tfile
2895         cat $MOUNT/$tfile || error "cat $MOUNT/$tfile failed"
2896
2897         umount_client $MOUNT || error "umount_client $MOUNT failed"
2898         stop_ost || error "Unable to stop OST1"
2899         stop_mds || error "Unable to stop MDS"
2900         stop_mds || error "Unable to stop MDS on second try"
2901 }
2902 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2903
2904 test_41c() {
2905         local server_version=$(lustre_version_code $SINGLEMDS)
2906         local oss_list=$(comma_list $(osts_nodes))
2907
2908         [[ $server_version -ge $(version_code 2.6.52) ]] ||
2909         [[ $server_version -ge $(version_code 2.5.26) &&
2910            $server_version -lt $(version_code 2.5.50) ]] ||
2911         [[ $server_version -ge $(version_code 2.5.4) &&
2912            $server_version -lt $(version_code 2.5.11) ]] ||
2913                 { skip "Need MDS version 2.5.4+ or 2.5.26+ or 2.6.52+"; return; }
2914
2915         # ensure mds1 ost1 have been created even if running sub-test standalone
2916         cleanup
2917         setup
2918         cleanup || error "cleanup failed"
2919
2920         # using directly mount command instead of start() function to avoid
2921         # any side effect of // with others/externals tools/features
2922         # ("zpool import", ...)
2923
2924         # MDT concurrent start
2925
2926         LOAD_MODULES_REMOTE=true load_modules
2927         do_facet $SINGLEMDS "lsmod | grep -q libcfs" ||
2928                 error "MDT concurrent start: libcfs module not loaded"
2929
2930         local mds1dev=$(mdsdevname 1)
2931         local mds1mnt=$(facet_mntpt mds1)
2932         local mds1fstype=$(facet_fstype mds1)
2933         local mds1opts=$MDS_MOUNT_OPTS
2934
2935         if [ $mds1fstype == ldiskfs ] &&
2936            ! do_facet mds1 test -b $mds1dev; then
2937                 mds1opts=$(csa_add "$mds1opts" -o loop)
2938         fi
2939         if [[ $mds1fstype == zfs ]]; then
2940                 import_zpool mds1 || return ${PIPESTATUS[0]}
2941         fi
2942
2943         #define OBD_FAIL_TGT_MOUNT_RACE 0x716
2944         do_facet mds1 "$LCTL set_param fail_loc=0x80000716"
2945
2946         do_facet mds1 mount -t lustre $mds1dev $mds1mnt $mds1opts &
2947         local pid=$!
2948
2949         do_facet mds1 mount -t lustre $mds1dev $mds1mnt $mds1opts
2950         local rc2=$?
2951         wait $pid
2952         local rc=$?
2953         do_facet mds1 "$LCTL set_param fail_loc=0x0"
2954         if [ $rc -eq 0 ] && [ $rc2 -ne 0 ]; then
2955                 echo "1st MDT start succeed"
2956                 echo "2nd MDT start failed with $rc2"
2957         elif [ $rc2 -eq 0 ] && [ $rc -ne 0 ]; then
2958                 echo "1st MDT start failed with $rc"
2959                 echo "2nd MDT start succeed"
2960         else
2961                 stop mds1 -f
2962                 error "unexpected concurrent MDT mounts result, rc=$rc rc2=$rc2"
2963         fi
2964
2965         if [ $MDSCOUNT -ge 2 ]; then
2966                 for num in $(seq 2 $MDSCOUNT); do
2967                         start_mdt $num || return
2968                 done
2969         fi
2970
2971         # OST concurrent start
2972
2973         do_rpc_nodes $oss_list "lsmod | grep -q libcfs" ||
2974                 error "OST concurrent start: libcfs module not loaded"
2975
2976         local ost1dev=$(ostdevname 1)
2977         local ost1mnt=$(facet_mntpt ost1)
2978         local ost1fstype=$(facet_fstype ost1)
2979         local ost1opts=$OST_MOUNT_OPTS
2980
2981         if [ $ost1fstype == ldiskfs ] &&
2982            ! do_facet ost1 test -b $ost1dev; then
2983                 ost1opts=$(csa_add "$ost1opts" -o loop)
2984         fi
2985         if [[ $ost1fstype == zfs ]]; then
2986                 import_zpool ost1 || return ${PIPESTATUS[0]}
2987         fi
2988
2989         #define OBD_FAIL_TGT_MOUNT_RACE 0x716
2990         do_facet ost1 "$LCTL set_param fail_loc=0x80000716"
2991
2992         do_facet ost1 mount -t lustre $ost1dev $ost1mnt $ost1opts &
2993         pid=$!
2994
2995         do_facet ost1 mount -t lustre $ost1dev $ost1mnt $ost1opts
2996         rc2=$?
2997         wait $pid
2998         rc=$?
2999         do_facet ost1 "$LCTL set_param fail_loc=0x0"
3000         if [ $rc -eq 0 ] && [ $rc2 -ne 0 ]; then
3001                 echo "1st OST start succeed"
3002                 echo "2nd OST start failed with $rc2"
3003         elif [ $rc2 -eq 0 ] && [ $rc -ne 0 ]; then
3004                 echo "1st OST start failed with $rc"
3005                 echo "2nd OST start succeed"
3006         else
3007                 stop_mds -f
3008                 stop ost1 -f
3009                 error "unexpected concurrent OST mounts result, rc=$rc rc2=$rc2"
3010         fi
3011         # cleanup
3012         stop_mds
3013         stop ost1 -f
3014
3015         # verify everything ok
3016         start_mds
3017         if [ $? != 0 ]
3018         then
3019                 stop_mds
3020                 error "MDT(s) start failed"
3021         fi
3022
3023         start_ost
3024         if [ $? != 0 ]
3025         then
3026                 stop_mds
3027                 stop ost1 -f
3028                 error "OST(s) start failed"
3029         fi
3030
3031         mount_client $MOUNT
3032         if [ $? != 0 ]
3033         then
3034                 stop_mds
3035                 stop ost1 -f
3036                 error "client start failed"
3037         fi
3038         check_mount
3039         if [ $? != 0 ]
3040         then
3041                 stop_mds
3042                 stop ost1 -f
3043                 error "client mount failed"
3044         fi
3045         cleanup
3046 }
3047 run_test 41c "concurrent mounts of MDT/OST should all fail but one"
3048
3049 test_42() { #bug 14693
3050         setup
3051         check_mount || error "client was not mounted"
3052
3053         do_facet mgs $LCTL conf_param $FSNAME.llite.some_wrong_param=10
3054         umount_client $MOUNT ||
3055                 error "unmounting client failed with invalid llite param"
3056         mount_client $MOUNT ||
3057                 error "mounting client failed with invalid llite param"
3058
3059         do_facet mgs $LCTL conf_param $FSNAME.sys.some_wrong_param=20
3060         cleanup || error "stopping $FSNAME failed with invalid sys param"
3061         setup
3062         check_mount || error "client was not mounted with invalid sys param"
3063         cleanup || error "stopping $FSNAME failed with invalid sys param"
3064 }
3065 run_test 42 "allow client/server mount/unmount with invalid config param"
3066
3067 test_43a() {
3068         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.58) ]] ||
3069                 { skip "Need MDS version at least 2.5.58" && return 0; }
3070         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
3071
3072         ID1=${ID1:-501}
3073         USER1=$(getent passwd | grep :$ID1:$ID1: | cut -d: -f1)
3074         [ -z "$USER1" ] && skip_env "missing user with uid=$ID1 gid=$ID1" &&
3075                 return
3076
3077         setup
3078         chmod ugo+x $DIR || error "chmod 0 failed"
3079         set_conf_param_and_check mds1                                   \
3080                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.root_squash"    \
3081                 "$FSNAME.mdt.root_squash"                               \
3082                 "0:0"
3083         wait_update $HOSTNAME                                           \
3084                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
3085                 "0:0" ||
3086                 error "check llite root_squash failed!"
3087         set_conf_param_and_check mds1                                   \
3088                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"  \
3089                 "$FSNAME.mdt.nosquash_nids"                             \
3090                 "NONE"
3091         wait_update $HOSTNAME                                           \
3092                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
3093                 "NONE" ||
3094                 error "check llite nosquash_nids failed!"
3095
3096     #
3097     # create set of test files
3098     #
3099     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
3100     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
3101     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
3102
3103     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
3104     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
3105
3106         mkdir $DIR/$tdir-rootdir || error "mkdir failed"
3107         chmod go-rwx $DIR/$tdir-rootdir || error "chmod 3 failed"
3108         touch $DIR/$tdir-rootdir/tfile-1 || error "touch failed"
3109
3110         echo "777" > $DIR/$tfile-user1file || error "write 7 failed"
3111         chmod go-rw $DIR/$tfile-user1file || error "chmod 7 failed"
3112         chown $ID1.$ID1 $DIR/$tfile-user1file || error "chown failed"
3113
3114         #
3115         # check root_squash:
3116         #   set root squash UID:GID to RUNAS_ID
3117         #   root should be able to access only files owned by RUNAS_ID
3118         #
3119         set_conf_param_and_check mds1                                   \
3120                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.root_squash"    \
3121                 "$FSNAME.mdt.root_squash"                               \
3122                 "$RUNAS_ID:$RUNAS_ID"
3123         wait_update $HOSTNAME                                           \
3124                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
3125                 "$RUNAS_ID:$RUNAS_ID" ||
3126                 error "check llite root_squash failed!"
3127
3128         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
3129         dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
3130                 error "$ST: root read permission is denied"
3131         echo "$ST: root read permission is granted - ok"
3132
3133         echo "444" |
3134         dd conv=notrunc of=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
3135                 error "$ST: root write permission is denied"
3136         echo "$ST: root write permission is granted - ok"
3137
3138         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
3139         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
3140                 error "$ST: root read permission is granted"
3141         echo "$ST: root read permission is denied - ok"
3142
3143         echo "555" |
3144         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
3145                 error "$ST: root write permission is granted"
3146         echo "$ST: root write permission is denied - ok"
3147
3148         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
3149                 rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null &&
3150                         error "$ST: root unlink permission is granted"
3151         echo "$ST: root unlink permission is denied - ok"
3152
3153         touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null &&
3154                 error "$ST: root create permission is granted"
3155         echo "$ST: root create permission is denied - ok"
3156
3157         # LU-1778
3158         # check root_squash is enforced independently
3159         # of client cache content
3160         #
3161         # access file by USER1, keep access open
3162         # root should be denied access to user file
3163
3164         runas -u $ID1 tail -f $DIR/$tfile-user1file 1>/dev/null 2>&1 &
3165         pid=$!
3166         sleep 1
3167
3168         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-user1file)
3169         dd if=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
3170             { kill $pid; error "$ST: root read permission is granted"; }
3171         echo "$ST: root read permission is denied - ok"
3172
3173         echo "777" |
3174         dd conv=notrunc of=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
3175             { kill $pid; error "$ST: root write permission is granted"; }
3176         echo "$ST: root write permission is denied - ok"
3177
3178         kill $pid
3179         wait $pid
3180
3181         #
3182         # check nosquash_nids:
3183         #   put client's NID into nosquash_nids list,
3184         #   root should be able to access root file after that
3185         #
3186         local NIDLIST=$($LCTL list_nids all | tr '\n' ' ')
3187         NIDLIST="2@gni $NIDLIST 192.168.0.[2,10]@tcp"
3188         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
3189         set_conf_param_and_check mds1                                   \
3190                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"  \
3191                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
3192                 "$NIDLIST"
3193         wait_update $HOSTNAME                                           \
3194                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
3195                 "$NIDLIST" ||
3196                 error "check llite nosquash_nids failed!"
3197
3198         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
3199         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
3200                 error "$ST: root read permission is denied"
3201         echo "$ST: root read permission is granted - ok"
3202
3203         echo "666" |
3204         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
3205                 error "$ST: root write permission is denied"
3206         echo "$ST: root write permission is granted - ok"
3207
3208         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
3209         rm $DIR/$tdir-rootdir/tfile-1 ||
3210                 error "$ST: root unlink permission is denied"
3211         echo "$ST: root unlink permission is granted - ok"
3212         touch $DIR/$tdir-rootdir/tfile-2 ||
3213                 error "$ST: root create permission is denied"
3214         echo "$ST: root create permission is granted - ok"
3215         cleanup || error "cleanup failed with $?"
3216 }
3217 run_test 43a "check root_squash and nosquash_nids"
3218
3219 test_43b() { # LU-5690
3220         [[ $(lustre_version_code mgs) -ge $(version_code 2.7.62) ]] ||
3221                 { skip "Need MGS version 2.7.62+"; return; }
3222
3223         if [[ -z "$fs2mds_DEV" ]]; then
3224                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
3225                 skip_env "mixed loopback and real device not working" && return
3226         fi
3227
3228         local fs2mdsdev=$(mdsdevname 1_2)
3229         local fs2mdsvdev=$(mdsvdevname 1_2)
3230
3231         # temporarily use fs2mds as fs2mgs
3232         local fs2mgs=fs2mds
3233         local fs2mgsdev=$fs2mdsdev
3234         local fs2mgsvdev=$fs2mdsvdev
3235
3236         local fsname=test1234
3237
3238         load_module llite/lustre
3239         local client_ip=$(host_nids_address $HOSTNAME $NETTYPE)
3240         local host=${client_ip//*./}
3241         local net=${client_ip/%$host/}
3242         local nosquash_nids=$(h2nettype $net[$host,$host,$host])
3243
3244         add $fs2mgs $(mkfs_opts mgs $fs2mgsdev) --fsname=$fsname \
3245                 --param mdt.root_squash=$RUNAS_ID:$RUNAS_ID \
3246                 --param mdt.nosquash_nids=$nosquash_nids \
3247                 --reformat $fs2mgsdev $fs2mgsvdev || error "add fs2mgs failed"
3248         start $fs2mgs $fs2mgsdev $MGS_MOUNT_OPTS  || error "start fs2mgs failed"
3249         stop $fs2mgs -f || error "stop fs2mgs failed"
3250 }
3251 run_test 43b "parse nosquash_nids with commas in expr_list"
3252
3253 umount_client $MOUNT
3254 cleanup_nocli
3255
3256 test_44() { # 16317
3257         setup
3258         check_mount || error "check_mount"
3259         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
3260         STATS_FOUND=no
3261         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
3262         for VAL in $UUIDS; do
3263                 NID=$(echo $VAL | cut -d= -f1)
3264                 CLUUID=$(echo $VAL | cut -d= -f2)
3265                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
3266         done
3267         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
3268         cleanup || error "cleanup failed with $?"
3269 }
3270 run_test 44 "mounted client proc entry exists"
3271
3272 test_45() { #17310
3273         setup
3274         check_mount || error "check_mount"
3275         stop_mds || error "Unable to stop MDS"
3276         df -h $MOUNT &
3277         log "sleep 60 sec"
3278         sleep 60
3279         #define OBD_FAIL_PTLRPC_LONG_REPL_UNLINK        0x50f
3280         do_facet client "$LCTL set_param fail_loc=0x8000050f"
3281         log "sleep 10 sec"
3282         sleep 10
3283         manual_umount_client --force || error "manual_umount_client failed"
3284         do_facet client "$LCTL set_param fail_loc=0x0"
3285         start_mds || error "unable to start MDS"
3286         mount_client $MOUNT || error "mount_client $MOUNT failed"
3287         cleanup || error "cleanup failed with $?"
3288 }
3289 run_test 45 "long unlink handling in ptlrpcd"
3290
3291 cleanup_46a() {
3292         trap 0
3293         local rc=0
3294         local count=$1
3295
3296         umount_client $MOUNT2 || rc=$?
3297         umount_client $MOUNT || rc=$?
3298         while [ $count -gt 0 ]; do
3299                 stop ost${count} -f || rc=$?
3300                 let count=count-1
3301         done
3302         stop_mds || rc=$?
3303         cleanup_nocli || rc=$?
3304         #writeconf to remove all ost2 traces for subsequent tests
3305         writeconf_or_reformat
3306         return $rc
3307 }
3308
3309 test_46a() {
3310         echo "Testing with $OSTCOUNT OSTs"
3311         reformat_and_config
3312         start_mds || error "unable to start MDS"
3313         #first client should see only one ost
3314         start_ost || error "Unable to start OST1"
3315         wait_osc_import_state mds ost FULL
3316         #start_client
3317         mount_client $MOUNT || error "mount_client $MOUNT failed"
3318         trap "cleanup_46a $OSTCOUNT" EXIT ERR
3319
3320         local i
3321         for (( i=2; i<=$OSTCOUNT; i++ )); do
3322                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
3323                         error "start_ost$i $(ostdevname $i) failed"
3324         done
3325
3326         # wait until osts in sync
3327         for (( i=2; i<=$OSTCOUNT; i++ )); do
3328             wait_osc_import_state mds ost$i FULL
3329             wait_osc_import_state client ost$i FULL
3330         done
3331
3332         #second client see all ost's
3333
3334         mount_client $MOUNT2 || error "mount_client failed"
3335         $SETSTRIPE -c -1 $MOUNT2 || error "$SETSTRIPE -c -1 $MOUNT2 failed"
3336         $GETSTRIPE $MOUNT2 || error "$GETSTRIPE $MOUNT2 failed"
3337
3338         echo "ok" > $MOUNT2/widestripe
3339         $GETSTRIPE $MOUNT2/widestripe ||
3340                 error "$GETSTRIPE $MOUNT2/widestripe failed"
3341         # fill acl buffer for avoid expand lsm to them
3342         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd |
3343                 while read acl; do
3344             setfacl -m $acl $MOUNT2/widestripe
3345         done
3346
3347         # will be deadlock
3348         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
3349
3350         cleanup_46a $OSTCOUNT || error "cleanup_46a failed"
3351 }
3352 run_test 46a "handle ost additional - wide striped file"
3353
3354 test_47() { #17674
3355         reformat
3356         setup_noconfig
3357         check_mount || error "check_mount failed"
3358         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
3359
3360         local lru_size=[]
3361         local count=0
3362         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
3363             if echo $ns | grep "MDT[[:digit:]]*"; then
3364                 continue
3365             fi
3366             lrs=$(echo $ns | sed 's/.*lru_size=//')
3367             lru_size[count]=$lrs
3368             let count=count+1
3369         done
3370
3371         facet_failover ost1
3372         facet_failover $SINGLEMDS
3373         client_up || error "client_up failed"
3374
3375         count=0
3376         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
3377             if echo $ns | grep "MDT[[:digit:]]*"; then
3378                 continue
3379             fi
3380             lrs=$(echo $ns | sed 's/.*lru_size=//')
3381             if ! test "$lrs" -eq "${lru_size[count]}"; then
3382                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
3383                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
3384             fi
3385             let count=count+1
3386         done
3387
3388         cleanup || error "cleanup failed with $?"
3389 }
3390 run_test 47 "server restart does not make client loss lru_resize settings"
3391
3392 cleanup_48() {
3393         trap 0
3394
3395         # reformat after this test is needed - if the test fails,
3396         # we will have unkillable file at FS
3397         reformat_and_config
3398 }
3399
3400 test_48() { # bz-17636 LU-7473
3401         local count
3402
3403         setup_noconfig
3404         check_mount || error "check_mount failed"
3405
3406         $SETSTRIPE -c -1 $MOUNT || error "$SETSTRIPE -c -1 $MOUNT failed"
3407         $GETSTRIPE $MOUNT || error "$GETSTRIPE $MOUNT failed"
3408
3409         echo "ok" > $MOUNT/widestripe
3410         $GETSTRIPE $MOUNT/widestripe ||
3411                 error "$GETSTRIPE $MOUNT/widestripe failed"
3412
3413         # In the future, we may introduce more EAs, such as selinux, enlarged
3414         # LOV EA, and so on. These EA will use some EA space that is shared by
3415         # ACL entries. So here we only check some reasonable ACL entries count,
3416         # instead of the max number that is calculated from the max_ea_size.
3417         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.57) ];
3418         then
3419                 count=28        # hard coded of RPC protocol
3420         elif [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3421                 count=4000      # max_num 4091 max_ea_size = 32768
3422         elif ! large_xattr_enabled; then
3423                 count=450       # max_num 497 max_ea_size = 4012
3424         else
3425                 count=4500      # max_num 8187 max_ea_size = 1048492
3426                                 # not create too much (>5000) to save test time
3427         fi
3428
3429         echo "It is expected to hold at least $count ACL entries"
3430         trap cleanup_48 EXIT ERR
3431         for ((i = 0; i < $count; i++)) do
3432                 setfacl -m u:$((i + 100)):rw $MOUNT/widestripe ||
3433                         error "Fail to setfacl for $MOUNT/widestripe at $i"
3434         done
3435
3436         cancel_lru_locks mdc
3437         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
3438         local r_count=$(getfacl $MOUNT/widestripe | grep "user:" | wc -l)
3439         count=$((count + 1)) # for the entry "user::rw-"
3440
3441         [ $count -eq $r_count ] ||
3442                 error "Expected ACL entries $count, but got $r_count"
3443
3444         cleanup_48
3445 }
3446 run_test 48 "too many acls on file"
3447
3448 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
3449 test_49a() { # bug 17710
3450         local timeout_orig=$TIMEOUT
3451         local ldlm_timeout_orig=$LDLM_TIMEOUT
3452         local LOCAL_TIMEOUT=20
3453
3454         LDLM_TIMEOUT=$LOCAL_TIMEOUT
3455         TIMEOUT=$LOCAL_TIMEOUT
3456
3457         reformat
3458         setup_noconfig
3459         check_mount || error "client mount failed"
3460
3461         echo "check ldlm_timout..."
3462         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
3463         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
3464         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
3465
3466         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
3467                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3468         fi
3469
3470         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
3471                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT / 3))"
3472         fi
3473
3474         umount_client $MOUNT || error "umount_client $MOUNT failed"
3475         stop_ost || error "problem stopping OSS"
3476         stop_mds || error "problem stopping MDS"
3477
3478         LDLM_TIMEOUT=$ldlm_timeout_orig
3479         TIMEOUT=$timeout_orig
3480 }
3481 run_test 49a "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
3482
3483 test_49b() { # bug 17710
3484         local timeout_orig=$TIMEOUT
3485         local ldlm_timeout_orig=$LDLM_TIMEOUT
3486         local LOCAL_TIMEOUT=20
3487
3488         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
3489         TIMEOUT=$LOCAL_TIMEOUT
3490
3491         reformat
3492         setup_noconfig
3493         check_mount || error "client mount failed"
3494
3495         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
3496         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
3497         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
3498
3499         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
3500                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3501         fi
3502
3503         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
3504                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT - 1))"
3505         fi
3506
3507         cleanup || error "cleanup failed"
3508
3509         LDLM_TIMEOUT=$ldlm_timeout_orig
3510         TIMEOUT=$timeout_orig
3511 }
3512 run_test 49b "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
3513
3514 lazystatfs() {
3515         # Test both statfs and lfs df and fail if either one fails
3516         multiop_bg_pause $1 f_
3517         RC1=$?
3518         PID=$!
3519         killall -USR1 multiop
3520         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
3521         wait $PID || { RC1=$?; log "multiop return error "; }
3522
3523         $LFS df &
3524         PID=$!
3525         sleep 5
3526         kill -s 0 $PID
3527         RC2=$?
3528         if [ $RC2 -eq 0 ]; then
3529             kill -s 9 $PID
3530             log "lazystatfs df failed"
3531         fi
3532
3533         RC=0
3534         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
3535         return $RC
3536 }
3537
3538 test_50a() {
3539         setup
3540         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3541         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3542
3543         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
3544
3545         cleanup || error "cleanup failed with rc $?"
3546 }
3547 run_test 50a "lazystatfs all servers available"
3548
3549 test_50b() {
3550         setup
3551         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3552         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3553
3554         # Wait for client to detect down OST
3555         stop_ost || error "Unable to stop OST1"
3556         wait_osc_import_state mds ost DISCONN
3557
3558         lazystatfs $MOUNT || error "lazystatfs should not return EIO"
3559
3560         umount_client $MOUNT || error "Unable to unmount client"
3561         stop_mds || error "Unable to stop MDS"
3562 }
3563 run_test 50b "lazystatfs all servers down"
3564
3565 test_50c() {
3566         start_mds || error "Unable to start MDS"
3567         start_ost || error "Unable to start OST1"
3568         start_ost2 || error "Unable to start OST2"
3569         mount_client $MOUNT || error "Unable to mount client"
3570         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3571         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3572
3573         # Wait for client to detect down OST
3574         stop_ost || error "Unable to stop OST1"
3575         wait_osc_import_state mds ost DISCONN
3576         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3577
3578         umount_client $MOUNT || error "Unable to unmount client"
3579         stop_ost2 || error "Unable to stop OST2"
3580         stop_mds || error "Unable to stop MDS"
3581         #writeconf to remove all ost2 traces for subsequent tests
3582         writeconf_or_reformat
3583 }
3584 run_test 50c "lazystatfs one server down"
3585
3586 test_50d() {
3587         start_mds || error "Unable to start MDS"
3588         start_ost || error "Unable to start OST1"
3589         start_ost2 || error "Unable to start OST2"
3590         mount_client $MOUNT || error "Unable to mount client"
3591         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3592         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3593
3594         # Issue the statfs during the window where the client still
3595         # belives the OST to be available but it is in fact down.
3596         # No failure just a statfs which hangs for a timeout interval.
3597         stop_ost || error "Unable to stop OST1"
3598         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3599
3600         umount_client $MOUNT || error "Unable to unmount client"
3601         stop_ost2 || error "Unable to stop OST2"
3602         stop_mds || error "Unable to stop MDS"
3603         #writeconf to remove all ost2 traces for subsequent tests
3604         writeconf_or_reformat
3605 }
3606 run_test 50d "lazystatfs client/server conn race"
3607
3608 test_50e() {
3609         local RC1
3610         local pid
3611
3612         reformat_and_config
3613         start_mds || error "Unable to start MDS"
3614         #first client should see only one ost
3615         start_ost || error "Unable to start OST1"
3616         wait_osc_import_state mds ost FULL
3617
3618         # Wait for client to detect down OST
3619         stop_ost || error "Unable to stop OST1"
3620         wait_osc_import_state mds ost DISCONN
3621
3622         mount_client $MOUNT || error "Unable to mount client"
3623         $LCTL set_param llite.$FSNAME-*.lazystatfs=0
3624
3625         multiop_bg_pause $MOUNT _f
3626         RC1=$?
3627         pid=$!
3628
3629         if [ $RC1 -ne 0 ]; then
3630                 log "multiop failed $RC1"
3631         else
3632             kill -USR1 $pid
3633             sleep $(( $TIMEOUT+1 ))
3634             kill -0 $pid
3635             [ $? -ne 0 ] && error "process isn't sleep"
3636             start_ost || error "Unable to start OST1"
3637             wait $pid || error "statfs failed"
3638         fi
3639
3640         umount_client $MOUNT || error "Unable to unmount client"
3641         stop_ost || error "Unable to stop OST1"
3642         stop_mds || error "Unable to stop MDS"
3643 }
3644 run_test 50e "normal statfs all servers down"
3645
3646 test_50f() {
3647         local RC1
3648         local pid
3649         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
3650
3651         start_mds || error "Unable to start mds"
3652         #first client should see only one ost
3653         start_ost || error "Unable to start OST1"
3654         wait_osc_import_state mds ost FULL
3655
3656         start_ost2 || error "Unable to start OST2"
3657         wait_osc_import_state mds ost2 FULL
3658
3659         # Wait for client to detect down OST
3660         stop_ost2 || error "Unable to stop OST2"
3661
3662         wait_osc_import_state mds ost2 DISCONN
3663         mount_client $MOUNT || error "Unable to mount client"
3664         $LCTL set_param llite.$FSNAME-*.lazystatfs=0
3665
3666         multiop_bg_pause $MOUNT _f
3667         RC1=$?
3668         pid=$!
3669
3670         if [ $RC1 -ne 0 ]; then
3671                 log "lazystatfs multiop failed $RC1"
3672         else
3673             kill -USR1 $pid
3674             sleep $(( $TIMEOUT+1 ))
3675             kill -0 $pid
3676             [ $? -ne 0 ] && error "process isn't sleep"
3677             start_ost2 || error "Unable to start OST2"
3678             wait $pid || error "statfs failed"
3679             stop_ost2 || error "Unable to stop OST2"
3680         fi
3681
3682         umount_client $MOUNT -f || error "Unable to unmount client"
3683         stop_ost || error "Unable to stop OST1"
3684         stop_mds || error "Unable to stop MDS"
3685         #writeconf to remove all ost2 traces for subsequent tests
3686         writeconf_or_reformat
3687 }
3688 run_test 50f "normal statfs one server in down"
3689
3690 test_50g() {
3691         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >=2 OSTs" && return
3692         setup
3693         start_ost2 || error "Unable to start OST2"
3694         wait_osc_import_state mds ost2 FULL
3695         wait_osc_import_state client ost2 FULL
3696
3697         local PARAM="${FSNAME}-OST0001.osc.active"
3698
3699         $SETSTRIPE -c -1 $DIR/$tfile || error "$SETSTRIPE failed"
3700         do_facet mgs $LCTL conf_param $PARAM=0 ||
3701                 error "Unable to deactivate OST"
3702
3703         umount_client $MOUNT || error "Unable to unmount client"
3704         mount_client $MOUNT || error "Unable to mount client"
3705         # This df should not cause a panic
3706         df -k $MOUNT
3707
3708         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
3709         rm -f $DIR/$tfile || error "unable to remove file $DIR/$tfile"
3710         umount_client $MOUNT || error "Unable to unmount client"
3711         stop_ost2 || error "Unable to stop OST2"
3712         stop_ost || error "Unable to stop OST1"
3713         stop_mds || error "Unable to stop MDS"
3714         #writeconf to remove all ost2 traces for subsequent tests
3715         writeconf_or_reformat
3716 }
3717 run_test 50g "deactivated OST should not cause panic"
3718
3719 # LU-642
3720 test_50h() {
3721         # prepare MDT/OST, make OSC inactive for OST1
3722         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >=2 OSTs" && return
3723
3724         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3725         do_facet ost1 "$TUNEFS --param osc.active=0 `ostdevname 1`" ||
3726                 error "tunefs OST1 failed"
3727         start_mds  || error "Unable to start MDT"
3728         start_ost  || error "Unable to start OST1"
3729         start_ost2 || error "Unable to start OST2"
3730         mount_client $MOUNT || error "client start failed"
3731
3732         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3733
3734         # activatate OSC for OST1
3735         local TEST="$LCTL get_param -n osc.${FSNAME}-OST0000-osc-[!M]*.active"
3736         set_conf_param_and_check client                                 \
3737                 "$TEST" "${FSNAME}-OST0000.osc.active" 1 ||
3738                 error "Unable to activate OST1"
3739
3740         mkdir $DIR/$tdir/2 || error "mkdir $DIR/$tdir/2 failed"
3741         $SETSTRIPE -c -1 -i 0 $DIR/$tdir/2 ||
3742                 error "$SETSTRIPE $DIR/$tdir/2 failed"
3743         sleep 1 && echo "create a file after OST1 is activated"
3744         # create some file
3745         createmany -o $DIR/$tdir/2/$tfile-%d 1
3746
3747         # check OSC import is working
3748         stat $DIR/$tdir/2/* >/dev/null 2>&1 ||
3749                 error "some OSC imports are still not connected"
3750
3751         # cleanup
3752         umount_client $MOUNT || error "Unable to umount client"
3753         stop_ost2 || error "Unable to stop OST2"
3754         cleanup_nocli || error "cleanup_nocli failed with $?"
3755 }
3756 run_test 50h "LU-642: activate deactivated OST"
3757
3758 test_50i() {
3759         # prepare MDT/OST, make OSC inactive for OST1
3760         [ "$MDSCOUNT" -lt "2" ] && skip_env "needs >= 2 MDTs" && return
3761
3762         load_modules
3763         [ $(facet_fstype mds2) == zfs ] && import_zpool mds2
3764         do_facet mds2 "$TUNEFS --param mdc.active=0 $(mdsdevname 2)" ||
3765                 error "tunefs MDT2 failed"
3766         start_mds  || error "Unable to start MDT"
3767         start_ost  || error "Unable to start OST1"
3768         start_ost2 || error "Unable to start OST2"
3769         mount_client $MOUNT || error "client start failed"
3770
3771         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3772
3773         $LCTL conf_param ${FSNAME}-MDT0000.mdc.active=0 &&
3774                 error "deactive MDC0 succeeds"
3775         # activate MDC for MDT2
3776         local TEST="$LCTL get_param -n mdc.${FSNAME}-MDT0001-mdc-[!M]*.active"
3777         set_conf_param_and_check client                                 \
3778                 "$TEST" "${FSNAME}-MDT0001.mdc.active" 1 ||
3779                 error "Unable to activate MDT2"
3780
3781         wait_clients_import_state ${CLIENTS:-$HOSTNAME} mds2 FULL
3782         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.60) ]
3783         then
3784                 wait_dne_interconnect
3785         fi
3786         $LFS mkdir -i1 $DIR/$tdir/2 || error "mkdir $DIR/$tdir/2 failed"
3787         # create some file
3788         createmany -o $DIR/$tdir/2/$tfile-%d 1 || error "create files failed"
3789
3790         rm -rf $DIR/$tdir/2 || error "unlink dir failed"
3791
3792         # deactivate MDC for MDT2
3793         local TEST="$LCTL get_param -n mdc.${FSNAME}-MDT0001-mdc-[!M]*.active"
3794         set_conf_param_and_check client                                 \
3795                 "$TEST" "${FSNAME}-MDT0001.mdc.active" 0 ||
3796                 error "Unable to deactivate MDT2"
3797
3798         wait_osp_active mds ${FSNAME}-MDT0001 1 0
3799
3800         $LFS mkdir -i1 $DIR/$tdir/2 &&
3801                 error "mkdir $DIR/$tdir/2 succeeds after deactive MDT"
3802
3803         $LFS mkdir -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
3804                 error "mkdir $DIR/$tdir/striped_dir fails after deactive MDT2"
3805
3806         local stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
3807         [ $stripe_count -eq $((MDSCOUNT - 1)) ] ||
3808                 error "wrong $stripe_count != $((MDSCOUNT -1)) for striped_dir"
3809
3810         # cleanup
3811         umount_client $MOUNT || error "Unable to umount client"
3812         stop_mds
3813         stop_ost
3814         stop_ost 2
3815 }
3816 run_test 50i "activate deactivated MDT"
3817
3818 test_51() {
3819         local LOCAL_TIMEOUT=20
3820
3821         reformat
3822         setup_noconfig
3823         check_mount || error "check_mount failed"
3824
3825         mkdir $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
3826         $SETSTRIPE -c -1 $MOUNT/$tdir ||
3827                 error "$SETSTRIPE -c -1 $MOUNT/$tdir failed"
3828         #define OBD_FAIL_MDS_REINT_DELAY         0x142
3829         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x142"
3830         touch $MOUNT/$tdir/$tfile &
3831         local pid=$!
3832         sleep 2
3833         start_ost2 || error "Unable to start OST1"
3834         wait $pid
3835         stop_ost2 || error "Unable to stop OST1"
3836         umount_client $MOUNT -f || error “unmount $MOUNT failed”
3837         cleanup_nocli || error “stop server failed”
3838         #writeconf to remove all ost2 traces for subsequent tests
3839         writeconf_or_reformat
3840 }
3841 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
3842
3843 copy_files_xattrs()
3844 {
3845         local node=$1
3846         local dest=$2
3847         local xattrs=$3
3848         shift 3
3849
3850         do_node $node mkdir -p $dest
3851         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3852
3853         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
3854                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3855         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
3856
3857         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
3858         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
3859 }
3860
3861 diff_files_xattrs()
3862 {
3863         local node=$1
3864         local backup=$2
3865         local xattrs=$3
3866         shift 3
3867
3868         local backup2=${TMP}/backup2
3869
3870         do_node $node mkdir -p $backup2
3871         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3872
3873         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
3874                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3875         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
3876
3877         do_node $node "diff -rq $backup $backup2"
3878         [ $? -eq 0 ] || { error "contents differ"; return 3; }
3879
3880         local xattrs2=${TMP}/xattrs2
3881         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
3882         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
3883
3884         do_node $node "diff $xattrs $xattrs2"
3885         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
3886
3887         do_node $node "rm -rf $backup2 $xattrs2"
3888         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
3889 }
3890
3891 test_52() {
3892         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3893                 skip "ldiskfs only test"
3894                 return
3895         fi
3896
3897         start_mds || error "Unable to start MDS"
3898         start_ost || error "Unable to start OST1"
3899         mount_client $MOUNT || error "Unable to mount client"
3900
3901         local nrfiles=8
3902         local ost1mnt=$(facet_mntpt ost1)
3903         local ost1node=$(facet_active_host ost1)
3904         local ost1tmp=$TMP/conf52
3905         local loop
3906
3907         mkdir $DIR/$tdir || error "Unable to create $DIR/$tdir"
3908         touch $TMP/modified_first || error "Unable to create temporary file"
3909         local mtime=$(stat -c %Y $TMP/modified_first)
3910         do_node $ost1node "mkdir -p $ost1tmp &&
3911                            touch -m -d @$mtime $ost1tmp/modified_first" ||
3912                 error "Unable to create temporary file"
3913         sleep 1
3914
3915         $SETSTRIPE -c -1 -S 1M $DIR/$tdir || error "$SETSTRIPE failed"
3916
3917         for (( i=0; i < nrfiles; i++ )); do
3918                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c ||
3919                         error "multiop failed"
3920                 echo -n .
3921         done
3922         echo
3923
3924         # backup files
3925         echo backup files to $TMP/$tdir
3926         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
3927         copy_files_xattrs $(hostname) $TMP/$tdir $TMP/file_xattrs $files ||
3928                 error "Unable to copy files"
3929
3930         umount_client $MOUNT || error "Unable to umount client"
3931         stop_ost || error "Unable to stop ost1"
3932
3933         echo mount ost1 as ldiskfs
3934         do_node $ost1node mkdir -p $ost1mnt || error "Unable to create $ost1mnt"
3935         if ! do_node $ost1node test -b $ost1_dev; then
3936                 loop="-o loop"
3937         fi
3938         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
3939                 $ost1mnt ||
3940                 error "Unable to mount ost1 as ldiskfs"
3941
3942         # backup objects
3943         echo backup objects to $ost1tmp/objects
3944         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/[0-9]* -type f'\
3945                 '-size +0 -newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
3946         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs \
3947                         $objects ||
3948                 error "Unable to copy objects"
3949
3950         # move objects to lost+found
3951         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
3952         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
3953
3954         do_node $ost1node "umount $ost1mnt" ||
3955                 error "Unable to umount ost1 as ldiskfs"
3956
3957         start_ost || error "Unable to start OST1"
3958         mount_client $MOUNT || error "Unable to mount client"
3959
3960         local REPAIRED=$(do_node $ost1node "$LCTL get_param \
3961                          -n osd-ldiskfs.$FSNAME-OST0000.oi_scrub" |
3962                          awk '/^lf_repa[ri]*ed/ { print $2 }')
3963         [ $REPAIRED -gt 0 ] ||
3964                 error "Some entry under /lost+found should be repaired"
3965
3966         # compare files
3967         diff_files_xattrs $(hostname) $TMP/$tdir $TMP/file_xattrs $files ||
3968                 error "Unable to diff files"
3969
3970         rm -rf $TMP/$tdir $TMP/file_xattrs ||
3971                 error "Unable to delete temporary files"
3972         do_node $ost1node "rm -rf $ost1tmp" ||
3973                 error "Unable to delete temporary files"
3974         cleanup || error "cleanup failed with $?"
3975 }
3976 run_test 52 "check recovering objects from lost+found"
3977
3978 # Checks threads_min/max/started for some service
3979 #
3980 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
3981 # parameter pattern prefix like 'ost.*.ost'.
3982 thread_sanity() {
3983         local modname=$1
3984         local facet=$2
3985         local parampat=$3
3986         local opts=$4
3987         local basethr=$5
3988         local tmin
3989         local tmin2
3990         local tmax
3991         local tmax2
3992         local tstarted
3993         local paramp
3994         local msg="Insane $modname thread counts"
3995         local ncpts=$(check_cpt_number $facet)
3996         local nthrs
3997         shift 4
3998
3999         check_mount || return 41
4000
4001         # We need to expand $parampat, but it may match multiple parameters, so
4002         # we'll pick the first one
4003         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
4004                 error "Couldn't expand ${parampat}.threads_min parameter name"
4005                 return 22
4006         fi
4007
4008         # Remove the .threads_min part
4009         paramp=${paramp%.threads_min}
4010
4011         # Check for sanity in defaults
4012         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4013                echo 0)
4014         tmax=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4015                echo 0)
4016         tstarted=$(do_facet $facet "$LCTL get_param \
4017                                     -n ${paramp}.threads_started" || echo 0)
4018         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' ||
4019                 return $?
4020         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' ||
4021                 return $?
4022         nthrs=$(expr $tmax - $tmin)
4023         if [ $nthrs -lt $ncpts ]; then
4024                 nthrs=0
4025         else
4026                 nthrs=$ncpts
4027         fi
4028
4029         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
4030                 skip_env "module parameter forced $facet thread count" &&
4031                 tmin=3 && tmax=$((3 * tmax))
4032
4033         # Check that we can change min/max
4034         do_facet $facet "$LCTL set_param \
4035                          ${paramp}.threads_min=$((tmin + nthrs))"
4036         do_facet $facet "$LCTL set_param \
4037                          ${paramp}.threads_max=$((tmax - nthrs))"
4038         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4039                 echo 0)
4040         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4041                 echo 0)
4042         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) &&
4043                             $tmax2 == ($tmax - $nthrs)))' || return $?
4044
4045         # Check that we can set min/max to the same value
4046         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4047                echo 0)
4048         do_facet $facet "$LCTL set_param ${paramp}.threads_max=$tmin"
4049         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4050                 echo 0)
4051         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4052                 echo 0)
4053         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
4054
4055         # Check that we can't set max < min
4056         do_facet $facet "$LCTL set_param ${paramp}.threads_max=$((tmin - 1))"
4057         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4058                 echo 0)
4059         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4060                 echo 0)
4061         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
4062
4063         # We need to ensure that we get the module options desired; to do this
4064         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
4065         LOAD_MODULES_REMOTE=true
4066         cleanup
4067         local oldvalue
4068         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
4069         setmodopts -a $modname "$newvalue" oldvalue
4070
4071         setup
4072         check_mount || return 41
4073
4074         # Restore previous setting of MODOPTS_*
4075         setmodopts $modname "$oldvalue"
4076
4077         # Check that $opts took
4078         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min")
4079         tmax=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max")
4080         tstarted=$(do_facet $facet \
4081                    "$LCTL get_param -n ${paramp}.threads_started")
4082         lassert 28 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' ||
4083                 return $?
4084         cleanup
4085
4086         setup
4087 }
4088
4089 test_53a() {
4090         setup
4091         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
4092         cleanup || error "cleanup failed with rc $?"
4093 }
4094 run_test 53a "check OSS thread count params"
4095
4096 test_53b() {
4097         setup
4098         local mds=$(do_facet $SINGLEMDS "$LCTL get_param \
4099                                          -N mds.*.*.threads_max 2>/dev/null")
4100         if [ -z "$mds" ]; then
4101                 #running this on an old MDT
4102                 thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' 16
4103         else
4104                 thread_sanity MDT $SINGLEMDS 'mds.*.*.' 'mds_num_threads' 16
4105         fi
4106         cleanup || error "cleanup failed with $?"
4107 }
4108 run_test 53b "check MDS thread count params"
4109
4110 test_54a() {
4111         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4112                 skip "ldiskfs only test"
4113                 return
4114         fi
4115
4116         do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p ||
4117                 error "llverdev failed with rc=$?"
4118         reformat_and_config
4119 }
4120 run_test 54a "test llverdev and partial verify of device"
4121
4122 test_54b() {
4123         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4124                 skip "ldiskfs only test"
4125                 return
4126         fi
4127
4128         setup
4129         run_llverfs $MOUNT -p || error "llverfs failed with rc=$?"
4130         cleanup || error "cleanup failed with rc=$?"
4131 }
4132 run_test 54b "test llverfs and partial verify of filesystem"
4133
4134 lov_objid_size()
4135 {
4136         local max_ost_index=$1
4137         echo -n $(((max_ost_index + 1) * 8))
4138 }
4139
4140 test_55() {
4141         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4142                 skip "ldiskfs only test"
4143                 return
4144         fi
4145
4146         local mdsdev=$(mdsdevname 1)
4147         local mdsvdev=$(mdsvdevname 1)
4148
4149         for i in 1023 2048
4150         do
4151                 if ! combined_mgs_mds; then
4152                         stop_mgs || error "stopping MGS service failed"
4153                         format_mgs || error "formatting MGT failed"
4154                 fi
4155                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
4156                         $mdsvdev || exit 10
4157                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
4158                         --reformat $(ostdevname 1) $(ostvdevname 1)
4159                 setup_noconfig
4160                 stopall
4161                 setup_noconfig
4162                 sync
4163
4164                 echo checking size of lov_objid for ost index $i
4165                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" |
4166                                  grep ^User | awk -F 'Size: ' '{print $2}')
4167                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
4168                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
4169                 else
4170                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
4171                 fi
4172                 stopall
4173         done
4174
4175         reformat
4176 }
4177 run_test 55 "check lov_objid size"
4178
4179 test_56a() {
4180         local server_version=$(lustre_version_code $SINGLEMDS)
4181         local mds_journal_size_orig=$MDSJOURNALSIZE
4182         local n
4183
4184         MDSJOURNALSIZE=16
4185
4186         formatall
4187         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=10000 --reformat \
4188                 $(ostdevname 1) $(ostvdevname 1)
4189         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=1000 --reformat \
4190                 $(ostdevname 2) $(ostvdevname 2)
4191
4192         start_mgsmds
4193         start_ost || error "Unable to start first ost (idx 10000)"
4194         start_ost2 || error "Unable to start second ost (idx 1000)"
4195         mount_client $MOUNT || error "Unable to mount client"
4196         echo ok
4197         $LFS osts
4198
4199         if [[ $server_version -ge $(version_code 2.6.54) ]] ||
4200            [[ $server_version -ge $(version_code 2.5.4) &&
4201               $server_version -lt $(version_code 2.5.11) ]]; then
4202                 wait_osc_import_state mds ost1 FULL
4203                 wait_osc_import_state mds ost2 FULL
4204                 $SETSTRIPE --stripe-count=-1 $DIR/$tfile ||
4205                         error "Unable to setstripe $DIR/$tfile"
4206                 n=$($LFS getstripe --stripe-count $DIR/$tfile)
4207                 [ "$n" -eq 2 ] || error "Stripe count not two: $n"
4208                 rm $DIR/$tfile
4209         fi
4210
4211         stopall
4212         MDSJOURNALSIZE=$mds_journal_size_orig
4213         reformat
4214 }
4215 run_test 56a "check big OST indexes and out-of-index-order start"
4216
4217 cleanup_56b() {
4218         trap 0
4219
4220         umount_client $MOUNT -f || error "unmount client failed"
4221         stop mds1
4222         stop mds2
4223         stop mds3
4224         stopall
4225         reformat
4226 }
4227
4228 test_56b() {
4229         [ $MDSCOUNT -lt 3 ] && skip "needs >= 3 MDTs" && return
4230
4231         trap cleanup_56b EXIT RETURN ERR
4232         stopall
4233
4234         if ! combined_mgs_mds ; then
4235                 format_mgs
4236                 start_mgs
4237         fi
4238
4239         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) --index=0 --reformat \
4240                 $(mdsdevname 1) $(mdsvdevname 1)
4241         add mds2 $(mkfs_opts mds2 $(mdsdevname 2)) --index=1 --reformat \
4242                 $(mdsdevname 2) $(mdsvdevname 2)
4243         add mds3 $(mkfs_opts mds3 $(mdsdevname 3)) --index=1000 --reformat \
4244                 $(mdsdevname 3) $(mdsvdevname 3)
4245         format_ost 1
4246         format_ost 2
4247
4248         start_mdt 1 || error "MDT 1 (idx 0) start failed"
4249         start_mdt 2 || error "MDT 2 (idx 1) start failed"
4250         start_mdt 3 || error "MDT 3 (idx 1000) start failed"
4251         start_ost || error "Unable to start first ost"
4252         start_ost2 || error "Unable to start second ost"
4253
4254         do_nodes $(comma_list $(mdts_nodes)) \
4255                 "$LCTL set_param mdt.*.enable_remote_dir=1 \
4256                 mdt.*.enable_remote_dir_gid=-1"
4257
4258         mount_client $MOUNT || error "Unable to mount client"
4259
4260         $LFS mkdir -c3 $MOUNT/$tdir || error "failed to make testdir"
4261
4262         echo "This is test file 1!" > $MOUNT/$tdir/$tfile.1 ||
4263                 error "failed to make test file 1"
4264         echo "This is test file 2!" > $MOUNT/$tdir/$tfile.2 ||
4265                 error "failed to make test file 2"
4266         echo "This is test file 1000!" > $MOUNT/$tdir/$tfile.1000 ||
4267                 error "failed to make test file 1000"
4268
4269         rm -rf $MOUNT/$tdir || error "failed to remove testdir"
4270
4271         $LFS mkdir -i1000 $MOUNT/$tdir.1000 ||
4272                 error "create remote dir at idx 1000 failed"
4273
4274         output=$($LFS df)
4275         echo "=== START lfs df OUTPUT ==="
4276         echo -e "$output"
4277         echo "==== END lfs df OUTPUT ===="
4278
4279         mdtcnt=$(echo -e "$output" | grep $FSNAME-MDT | wc -l)
4280         ostcnt=$(echo -e "$output" | grep $FSNAME-OST | wc -l)
4281
4282         echo "lfs df returned mdt count $mdtcnt and ost count $ostcnt"
4283         [ $mdtcnt -eq 3 ] || error "lfs df returned wrong mdt count"
4284         [ $ostcnt -eq 2 ] || error "lfs df returned wrong ost count"
4285
4286         echo "This is test file 1!" > $MOUNT/$tdir.1000/$tfile.1 ||
4287                 error "failed to make test file 1"
4288         echo "This is test file 2!" > $MOUNT/$tdir.1000/$tfile.2 ||
4289                 error "failed to make test file 2"
4290         echo "This is test file 1000!" > $MOUNT/$tdir.1000/$tfile.1000 ||
4291                 error "failed to make test file 1000"
4292         rm -rf $MOUNT/$tdir.1000 || error "failed to remove remote_dir"
4293
4294         output=$($LFS mdts)
4295         echo "=== START lfs mdts OUTPUT ==="
4296         echo -e "$output"
4297         echo "==== END lfs mdts OUTPUT ===="
4298
4299         echo -e "$output" | grep -v "MDTS:" | awk '{print $1}' |
4300                 sed 's/://g' > $TMP/mdts-actual.txt
4301         sort $TMP/mdts-actual.txt -o $TMP/mdts-actual.txt
4302
4303         echo -e "0\n1\n1000" > $TMP/mdts-expected.txt
4304
4305         diff $TMP/mdts-expected.txt $TMP/mdts-actual.txt
4306         result=$?
4307
4308         rm $TMP/mdts-expected.txt $TMP/mdts-actual.txt
4309
4310         [ $result -eq 0 ] || error "target_obd proc file is incorrect!"
4311 }
4312 run_test 56b "test target_obd correctness with nonconsecutive MDTs"
4313
4314 test_57a() { # bug 22656
4315         do_rpc_nodes $(facet_active_host ost1) load_modules_local
4316         local NID=$(do_facet ost1 "$LCTL get_param nis" |
4317                     tail -1 | awk '{print $1}')
4318         writeconf_or_reformat
4319         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
4320         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" ||
4321                 error "tunefs failed"
4322         start_mgsmds
4323         start_ost && error "OST registration from failnode should fail"
4324         reformat
4325 }
4326 run_test 57a "initial registration from failnode should fail (should return errs)"
4327
4328 test_57b() {
4329         do_rpc_nodes $(facet_active_host ost1) load_modules_local
4330         local NID=$(do_facet ost1 "$LCTL get_param nis" |
4331                     tail -1 | awk '{print $1}')
4332         writeconf_or_reformat
4333         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
4334         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" ||
4335                 error "tunefs failed"
4336         start_mgsmds
4337         start_ost || error "OST registration from servicenode should not fail"
4338         reformat
4339 }
4340 run_test 57b "initial registration from servicenode should not fail"
4341
4342 count_osts() {
4343         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
4344 }
4345
4346 test_58() { # bug 22658
4347         combined_mgs_mds || stop_mgs || error "stopping MGS service failed"
4348         setup_noconfig
4349         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4350         createmany -o $DIR/$tdir/$tfile-%d 100
4351         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
4352 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
4353         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x601"
4354         unlinkmany $DIR/$tdir/$tfile-%d 100
4355         stop_mds || error "Unable to stop MDS"
4356
4357         local MNTDIR=$(facet_mntpt $SINGLEMDS)
4358         local devname=$(mdsdevname ${SINGLEMDS//mds/})
4359
4360         # remove all files from the OBJECTS dir
4361         mount_fstype $SINGLEMDS
4362
4363         do_facet $SINGLEMDS "find $MNTDIR/O/1/d* -type f -delete"
4364
4365         unmount_fstype $SINGLEMDS
4366         # restart MDS with missing llog files
4367         start_mds || error "unable to start MDS"
4368         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0"
4369         reformat
4370 }
4371 run_test 58 "missing llog files must not prevent MDT from mounting"
4372
4373 test_59() {
4374         start_mgsmds >> /dev/null
4375         local C1=$(count_osts)
4376         if [ $C1 -eq 0 ]; then
4377                 start_ost >> /dev/null
4378                 C1=$(count_osts)
4379         fi
4380         stopall
4381         echo "original ost count: $C1 (expect > 0)"
4382         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
4383         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
4384         local C2=$(count_osts)
4385         echo "after mdt writeconf count: $C2 (expect 0)"
4386         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
4387         echo "OST start without writeconf should fail:"
4388         start_ost >> /dev/null &&
4389                 error "OST start without writeconf didn't fail"
4390         echo "OST start with writeconf should succeed:"
4391         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
4392         local C3=$(count_osts)
4393         echo "after ost writeconf count: $C3 (expect 1)"
4394         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
4395         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
4396         local C4=$(count_osts)
4397         echo "after ost2 writeconf count: $C4 (expect 2)"
4398         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
4399         stop_ost2 >> /dev/null
4400         cleanup_nocli >> /dev/null
4401         #writeconf to remove all ost2 traces for subsequent tests
4402         writeconf_or_reformat
4403 }
4404 run_test 59 "writeconf mount option"
4405
4406 test_60() { # LU-471
4407         local num
4408
4409         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4410                 skip "ldiskfs only test"
4411                 return
4412         fi
4413
4414         for num in $(seq $MDSCOUNT); do
4415                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
4416                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
4417                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
4418                         exit 10
4419         done
4420
4421         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
4422         [ ${PIPESTATUS[0]} -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
4423
4424         # MDT default has dirdata feature
4425         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
4426         # we disable uninit_bg feature
4427         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
4428         # we set stride extended options
4429         echo $dump | grep stride > /dev/null || error "stride is not set"
4430         reformat
4431 }
4432 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
4433
4434 test_61() { # LU-80
4435         local lxattr=false
4436
4437         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
4438                 { skip "Need MDS version at least 2.1.53"; return 0; }
4439
4440         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
4441              ! large_xattr_enabled; then
4442                 lxattr=true
4443
4444                 for num in $(seq $MDSCOUNT); do
4445                         do_facet mds${num} $TUNE2FS -O large_xattr \
4446                                 $(mdsdevname $num) ||
4447                                 error "tune2fs on mds $num failed"
4448                 done
4449         fi
4450
4451         combined_mgs_mds || stop_mgs || error "stopping MGS service failed"
4452         setup_noconfig || error "setting up the filesystem failed"
4453         client_up || error "starting client failed"
4454
4455         local file=$DIR/$tfile
4456         touch $file || error "touch $file failed"
4457
4458         local large_value="$(generate_string $(max_xattr_size))"
4459         local small_value="bar"
4460
4461         local name="trusted.big"
4462         log "save large xattr $name on $file"
4463         setfattr -n $name -v $large_value $file ||
4464                 error "saving $name on $file failed"
4465
4466         local new_value=$(get_xattr_value $name $file)
4467         [[ "$new_value" != "$large_value" ]] &&
4468                 error "$name different after saving"
4469
4470         log "shrink value of $name on $file"
4471         setfattr -n $name -v $small_value $file ||
4472                 error "shrinking value of $name on $file failed"
4473
4474         new_value=$(get_xattr_value $name $file)
4475         [[ "$new_value" != "$small_value" ]] &&
4476                 error "$name different after shrinking"
4477
4478         log "grow value of $name on $file"
4479         setfattr -n $name -v $large_value $file ||
4480                 error "growing value of $name on $file failed"
4481
4482         new_value=$(get_xattr_value $name $file)
4483         [[ "$new_value" != "$large_value" ]] &&
4484                 error "$name different after growing"
4485
4486         log "check value of $name on $file after remounting MDS"
4487         fail $SINGLEMDS
4488         new_value=$(get_xattr_value $name $file)
4489         [[ "$new_value" != "$large_value" ]] &&
4490                 error "$name different after remounting MDS"
4491
4492         log "remove large xattr $name from $file"
4493         setfattr -x $name $file || error "removing $name from $file failed"
4494
4495         if $lxattr; then
4496                 stopall || error "stopping for e2fsck run"
4497                 for num in $(seq $MDSCOUNT); do
4498                         run_e2fsck $(facet_active_host mds$num) \
4499                                 $(mdsdevname $num) "-y" ||
4500                                 error "e2fsck MDT$num failed"
4501                 done
4502                 setup_noconfig || error "remounting the filesystem failed"
4503         fi
4504
4505         # need to delete this file to avoid problems in other tests
4506         rm -f $file
4507         stopall || error "stopping systems to turn off large_xattr"
4508         if $lxattr; then
4509                 for num in $(seq $MDSCOUNT); do
4510                         do_facet mds${num} $TUNE2FS -O ^large_xattr \
4511                                 $(mdsdevname $num) ||
4512                                 error "tune2fs on mds $num failed"
4513                 done
4514         fi
4515 }
4516 run_test 61 "large xattr"
4517
4518 test_62() {
4519         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4520                 skip "ldiskfs only test"
4521                 return
4522         fi
4523
4524         # MRP-118
4525         local mdsdev=$(mdsdevname 1)
4526         local ostdev=$(ostdevname 1)
4527
4528         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
4529                 { skip "Need MDS version at least 2.2.51"; return 0; }
4530
4531         echo "disable journal for mds"
4532         do_facet mds1 $TUNE2FS -O ^has_journal $mdsdev || error "tune2fs failed"
4533         start_mds && error "MDT start should fail"
4534         echo "disable journal for ost"
4535         do_facet ost1 $TUNE2FS -O ^has_journal $ostdev || error "tune2fs failed"
4536         start_ost && error "OST start should fail"
4537         cleanup || error "cleanup failed with rc $?"
4538         reformat_and_config
4539 }
4540 run_test 62 "start with disabled journal"
4541
4542 test_63() {
4543         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4544                 skip "ldiskfs only test"
4545                 return
4546         fi
4547
4548         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_module ldiskfs
4549         local inode_slab=$(do_facet $SINGLEMDS "cat /proc/slabinfo" |
4550                            awk '/ldiskfs_inode_cache/ { print $5 / $6 }')
4551         if [ -z "$inode_slab" ]; then
4552                 skip "ldiskfs module has not been loaded"
4553                 return
4554         fi
4555
4556         echo "$inode_slab ldiskfs inodes per page"
4557         [ "${inode_slab%.*}" -ge "3" ] && return 0
4558
4559         # If kmalloc-128 is also 1 per page - this is a debug kernel
4560         # and so this is not an error.
4561         local kmalloc128=$(do_facet $SINGLEMDS "cat /proc/slabinfo" |
4562                            awk '/^(kmalloc|size)-128 / { print $5 / $6 }')
4563         # 32 128-byte chunks in 4k
4564         [ "${kmalloc128%.*}" -lt "32" ] ||
4565                 error "ldiskfs inode too big, only $inode_slab objs/page, " \
4566                       "kmalloc128 = $kmalloc128 objs/page"
4567 }
4568 run_test 63 "Verify each page can at least hold 3 ldiskfs inodes"
4569
4570 test_64() {
4571         start_mds || error "unable to start MDS"
4572         start_ost || error "Unable to start OST1"
4573         start_ost2 || error "Unable to start second ost"
4574         mount_client $MOUNT || error "Unable to mount client"
4575         stop_ost2 || error "Unable to stop second ost"
4576         echo "$LFS df"
4577         $LFS df --lazy
4578         umount_client $MOUNT -f || error “unmount $MOUNT failed”
4579         cleanup_nocli || error "cleanup_nocli failed with $?"
4580         #writeconf to remove all ost2 traces for subsequent tests
4581         writeconf_or_reformat
4582 }
4583 run_test 64 "check lfs df --lazy "
4584
4585 test_65() { # LU-2237
4586         # Currently, the test is only valid for ldiskfs backend
4587         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
4588                 skip "ldiskfs only test" && return
4589
4590         local devname=$(mdsdevname ${SINGLEMDS//mds/})
4591         local brpt=$(facet_mntpt brpt)
4592         local opts=""
4593
4594         if ! do_facet $SINGLEMDS "test -b $devname"; then
4595                 opts="-o loop"
4596         fi
4597
4598         stop_mds || error "Unable to stop MDS"
4599         local obj=$(do_facet $SINGLEMDS \
4600                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
4601                     grep Inode)
4602         if [ -z "$obj" ]; then
4603                 # The MDT may be just re-formatted, mount the MDT for the
4604                 # first time to guarantee the "last_rcvd" file is there.
4605                 start_mds || error "fail to mount the MDS for the first time"
4606                 stop_mds || error "Unable to stop MDS"
4607         fi
4608
4609         # remove the "last_rcvd" file
4610         do_facet $SINGLEMDS "mkdir -p $brpt"
4611         do_facet $SINGLEMDS \
4612                 "mount -t $(facet_fstype $SINGLEMDS) $opts $devname $brpt"
4613         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
4614         do_facet $SINGLEMDS "$UMOUNT $brpt"
4615
4616         # restart MDS, the "last_rcvd" file should be recreated.
4617         start_mds || error "fail to restart the MDS"
4618         stop_mds || error "Unable to stop MDS"
4619         obj=$(do_facet $SINGLEMDS \
4620               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
4621         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
4622 }
4623 run_test 65 "re-create the lost last_rcvd file when server mount"
4624
4625 test_66() {
4626         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
4627                 { skip "Need MGS version at least 2.3.59"; return 0; }
4628
4629         setup
4630         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
4631         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
4632
4633         echo "replace_nids should fail if MDS, OSTs and clients are UP"
4634         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4635                 error "replace_nids fail"
4636
4637         umount_client $MOUNT || error "unmounting client failed"
4638         echo "replace_nids should fail if MDS and OSTs are UP"
4639         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4640                 error "replace_nids fail"
4641
4642         stop_ost || error "Unable to stop OST1"
4643         echo "replace_nids should fail if MDS is UP"
4644         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4645                 error "replace_nids fail"
4646
4647         stop_mds || error "stopping mds failed"
4648
4649         if combined_mgs_mds; then
4650                 start_mdt 1 "-o nosvc" ||
4651                         error "starting mds with nosvc option failed"
4652         fi
4653
4654         echo "command should accept two parameters"
4655         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
4656                 error "command should accept two params"
4657
4658         echo "correct device name should be passed"
4659         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
4660                 error "wrong devname"
4661
4662         echo "wrong nids list should not destroy the system"
4663         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
4664                 error "wrong parse"
4665
4666         echo "replace OST nid"
4667         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
4668                 error "replace nids failed"
4669
4670         echo "command should accept two parameters"
4671         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
4672                 error "command should accept two params"
4673
4674         echo "wrong nids list should not destroy the system"
4675         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
4676                 error "wrong parse"
4677
4678         echo "replace MDS nid"
4679         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
4680                 error "replace nids failed"
4681
4682         if ! combined_mgs_mds ; then
4683                 stop_mgs
4684         else
4685                 stop_mds || error "Unable to stop MDS"
4686         fi
4687
4688         setup_noconfig
4689         check_mount || error "error after nid replace"
4690         cleanup || error "cleanup failed"
4691         reformat
4692 }
4693 run_test 66 "replace nids"
4694
4695 test_67() { #LU-2950
4696         local legacy="$TMP/legacy_lnet_config"
4697         local new="$TMP/new_routes_test"
4698         local out="$TMP/config_out_file"
4699         local verify="$TMP/conv_verify"
4700         local verify_conf="$TMP/conf_verify"
4701
4702         # Create the legacy file that will be run through the
4703         # lustre_routes_conversion script
4704         cat <<- LEGACY_LNET_CONFIG > $legacy
4705                 tcp1 23 192.168.213.1@tcp:1; tcp5 34 193.30.4.3@tcp:4;
4706                 tcp2 54 10.1.3.2@tcp;
4707                 tcp3 10.3.4.3@tcp:3;
4708                 tcp4 10.3.3.4@tcp;
4709         LEGACY_LNET_CONFIG
4710
4711         # Create the verification file to verify the output of
4712         # lustre_routes_conversion script against.
4713         cat <<- VERIFY_LNET_CONFIG > $verify
4714                 tcp1: { gateway: 192.168.213.1@tcp, hop: 23, priority: 1 }
4715                 tcp5: { gateway: 193.30.4.3@tcp, hop: 34, priority: 4 }
4716                 tcp2: { gateway: 10.1.3.2@tcp, hop: 54 }
4717                 tcp3: { gateway: 10.3.4.3@tcp, priority: 3 }
4718                 tcp4: { gateway: 10.3.3.4@tcp }
4719         VERIFY_LNET_CONFIG
4720
4721         # Create the verification file to verify the output of
4722         # lustre_routes_config script against
4723         cat <<- VERIFY_LNET_CONFIG > $verify_conf
4724                 lctl --net tcp1 add_route 192.168.213.1@tcp 23 1
4725                 lctl --net tcp5 add_route 193.30.4.3@tcp 34 4
4726                 lctl --net tcp2 add_route 10.1.3.2@tcp 54 4
4727                 lctl --net tcp3 add_route 10.3.4.3@tcp 1 3
4728                 lctl --net tcp4 add_route 10.3.3.4@tcp 1 3
4729         VERIFY_LNET_CONFIG
4730
4731         lustre_routes_conversion $legacy $new > /dev/null
4732         if [ -f $new ]; then
4733                 # verify the conversion output
4734                 cmp -s $new $verify > /dev/null
4735                 if [ $? -eq 1 ]; then
4736                         error "routes conversion failed"
4737                 fi
4738
4739                 lustre_routes_config --dry-run --verbose $new > $out
4740                 # check that the script succeeded
4741                 cmp -s $out $verify_conf > /dev/null
4742                 if [ $? -eq 1 ]; then
4743                         error "routes config failed"
4744                 fi
4745         else
4746                 error "routes conversion test failed"
4747         fi
4748         # remove generated files
4749         rm -f $new $legacy $verify $verify_conf $out
4750 }
4751 run_test 67 "test routes conversion and configuration"
4752
4753 test_68() {
4754         local fid
4755         local seq
4756         local START
4757         local END
4758
4759         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.53) ] ||
4760                 { skip "Need MDS version at least 2.4.53"; return 0; }
4761
4762         umount_client $MOUNT || error "umount client failed"
4763
4764         if ! combined_mgs_mds; then
4765                 start_mgs || error "start mgs failed"
4766         fi
4767
4768         start_mdt 1 || error "MDT start failed"
4769         start_ost || error "Unable to start OST1"
4770
4771         # START-END - the sequences we'll be reserving
4772         START=$(do_facet $SINGLEMDS \
4773                 $LCTL get_param -n seq.ctl*.space | awk -F'[[ ]' '{print $2}')
4774         END=$((START + (1 << 30)))
4775         do_facet $SINGLEMDS \
4776                 $LCTL set_param seq.ctl*.fldb="[$START-$END\):0:mdt"
4777
4778         # reset the sequences MDT0000 has already assigned
4779         do_facet $SINGLEMDS \
4780                 $LCTL set_param seq.srv*MDT0000.space=clear
4781
4782         # remount to let the client allocate new sequence
4783         mount_client $MOUNT || error "mount client failed"
4784
4785         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4786         do_facet $SINGLEMDS \
4787                 $LCTL get_param seq.srv*MDT0000.space
4788         $LFS path2fid $DIR/$tfile
4789
4790         local old_ifs="$IFS"
4791         IFS='[:]'
4792         fid=($($LFS path2fid $DIR/$tfile))
4793         IFS="$old_ifs"
4794         let seq=${fid[1]}
4795
4796         if [[ $seq < $END ]]; then
4797                 error "used reserved sequence $seq?"
4798         fi
4799         cleanup || error "cleanup failed with $?"
4800 }
4801 run_test 68 "be able to reserve specific sequences in FLDB"
4802
4803 # Test 69: is about the total number of objects ever created on an OST.
4804 # so that when it is reformatted the normal MDS->OST orphan recovery won't
4805 # just "precreate" the missing objects. In the past it might try to recreate
4806 # millions of objects after an OST was reformatted
4807 test_69() {
4808         local server_version=$(lustre_version_code $SINGLEMDS)
4809
4810         [[ $server_version -lt $(version_code 2.4.2) ]] &&
4811                 skip "Need MDS version at least 2.4.2" && return
4812
4813         [[ $server_version -ge $(version_code 2.4.50) ]] &&
4814         [[ $server_version -lt $(version_code 2.5.0) ]] &&
4815                 skip "Need MDS version at least 2.5.0" && return
4816
4817         setup
4818         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4819
4820         # use OST0000 since it probably has the most creations
4821         local OSTNAME=$(ostname_from_index 0)
4822         local mdtosc_proc1=$(get_mdtosc_proc_path mds1 $OSTNAME)
4823         local last_id=$(do_facet mds1 $LCTL get_param -n \
4824                         osc.$mdtosc_proc1.prealloc_last_id)
4825
4826         # Want to have OST LAST_ID over 5 * OST_MAX_PRECREATE to
4827         # verify that the LAST_ID recovery is working properly. If
4828         # not, then the OST will refuse to allow the MDS connect
4829         # because the LAST_ID value is too different from the MDS
4830         #define OST_MAX_PRECREATE=20000
4831         local ost_max_pre=20000
4832         local num_create=$(( ost_max_pre * 5 + 1 - last_id))
4833
4834         # If the LAST_ID is already over 5 * OST_MAX_PRECREATE, we don't
4835         # need to create any files. So, skip this section.
4836         if [ $num_create -gt 0 ]; then
4837                 # Check the number of inodes available on OST0
4838                 local files=0
4839                 local ifree=$($LFS df -i $MOUNT | awk '/OST0000/ { print $4 }')
4840                 log "On OST0, $ifree inodes available. Want $num_create."
4841
4842                 $SETSTRIPE -i 0 $DIR/$tdir ||
4843                         error "$SETSTRIPE -i 0 $DIR/$tdir failed"
4844                 if [ $ifree -lt 10000 ]; then
4845                         files=$(( ifree - 50 ))
4846                 else
4847                         files=10000
4848                 fi
4849
4850                 local j=$((num_create / files + 1))
4851                 for i in $(seq 1 $j); do
4852                         createmany -o $DIR/$tdir/$tfile-$i- $files ||
4853                                 error "createmany fail create $files files: $?"
4854                         unlinkmany $DIR/$tdir/$tfile-$i- $files ||
4855                                 error "unlinkmany failed unlink $files files"
4856                 done
4857         fi
4858
4859         # delete all of the files with objects on OST0 so the
4860         # filesystem is not inconsistent later on
4861         $LFS find $MOUNT --ost 0 -print0 | xargs -0 rm
4862
4863         umount_client $MOUNT || error "umount client failed"
4864         stop_ost || error "OST0 stop failure"
4865         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat --replace \
4866                 $(ostdevname 1) $(ostvdevname 1) ||
4867                 error "reformat and replace $ostdev failed"
4868         start_ost || error "OST0 restart failure"
4869         wait_osc_import_state mds ost FULL
4870
4871         mount_client $MOUNT || error "mount client failed"
4872         touch $DIR/$tdir/$tfile-last || error "create file after reformat"
4873         local idx=$($GETSTRIPE -i $DIR/$tdir/$tfile-last)
4874         [ $idx -ne 0 ] && error "$DIR/$tdir/$tfile-last on $idx not 0" || true
4875
4876         local iused=$($LFS df -i $MOUNT | awk '/OST0000/ { print $3 }')
4877         log "On OST0, $iused used inodes"
4878         [ $iused -ge $((ost_max_pre/2 + 1000)) ] &&
4879                 error "OST replacement created too many inodes; $iused"
4880         cleanup || error "cleanup failed with $?"
4881 }
4882 run_test 69 "replace an OST with the same index"
4883
4884 test_70a() {
4885         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4886         local MDTIDX=1
4887
4888         cleanup || error "cleanup failed with $?"
4889
4890         start_mdt 1 || error "MDT0 start fail"
4891
4892         start_ost || error "OST0 start fail"
4893         for num in $(seq 2 $MDSCOUNT); do
4894                 start_mdt $num || return
4895         done
4896
4897         mount_client $MOUNT || error "mount client fails"
4898
4899         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
4900
4901         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4902                 error "create remote dir fail"
4903
4904         rm -rf $DIR/$tdir || error "delete dir fail"
4905         cleanup || error "cleanup failed with $?"
4906 }
4907 run_test 70a "start MDT0, then OST, then MDT1"
4908
4909 test_70b() {
4910         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4911         local MDTIDX=1
4912
4913         start_ost || error "OST0 start fail"
4914
4915         start_mds || error "MDS start fail"
4916
4917         mount_client $MOUNT || error "mount client fails"
4918
4919         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
4920
4921         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4922                 error "create remote dir fail"
4923
4924         rm -rf $DIR/$tdir || error "delete dir fail"
4925
4926         cleanup || error "cleanup failed with $?"
4927 }
4928 run_test 70b "start OST, MDT1, MDT0"
4929
4930 test_70c() {
4931         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4932         local MDTIDX=1
4933
4934         start_mds || error "MDS start fail"
4935         start_ost || error "OST0 start fail"
4936
4937         mount_client $MOUNT || error "mount client fails"
4938         stop_mdt 1 || error "MDT1 start fail"
4939
4940         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
4941         echo "deactivate $mdc_for_mdt1"
4942         $LCTL --device $mdc_for_mdt1 deactivate ||
4943                 error "set $mdc_for_mdt1 deactivate failed"
4944
4945         mkdir $DIR/$tdir && error "mkdir succeed"
4946
4947         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4948                 error "create remote dir succeed"
4949
4950         cleanup || error "cleanup failed with $?"
4951 }
4952 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
4953
4954 test_70d() {
4955         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4956         local MDTIDX=1
4957
4958         start_mds || error "MDS start fail"
4959         start_ost || error "OST0 start fail"
4960
4961         mount_client $MOUNT || error "mount client fails"
4962
4963         stop_mdt 2 || error "MDT1 start fail"
4964
4965         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
4966                              awk '{print $4}')
4967         echo "deactivate $mdc_for_mdt2"
4968         $LCTL --device $mdc_for_mdt2 deactivate ||
4969                 error "set $mdc_for_mdt2 deactivate failed"
4970
4971         mkdir $DIR/$tdir || error "mkdir fail"
4972         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4973                 error "create remote dir succeed"
4974
4975         rm -rf $DIR/$tdir || error "delete dir fail"
4976
4977         cleanup || error "cleanup failed with $?"
4978 }
4979 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
4980
4981 test_70e() {
4982         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4983
4984         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.62) ] ||
4985                 { skip "Need MDS version at least 2.7.62"; return 0; }
4986
4987         cleanup || error "cleanup failed with $?"
4988
4989         local mdsdev=$(mdsdevname 1)
4990         local ostdev=$(ostdevname 1)
4991         local mdsvdev=$(mdsvdevname 1)
4992         local ostvdev=$(ostvdevname 1)
4993         local opts_mds="$(mkfs_opts mds1 $mdsdev) --reformat $mdsdev $mdsvdev"
4994         local opts_ost="$(mkfs_opts ost1 $ostdev) --reformat $ostdev $ostvdev"
4995
4996         add mds1 $opts_mds || error "add mds1 failed"
4997         start_mdt 1 || error "start mdt1 failed"
4998         add ost1 $opts_ost || error "add ost1 failed"
4999         start_ost || error "start ost failed"
5000         mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
5001
5002         local soc=$(do_facet mds1 "$LCTL get_param -n \
5003                     mdt.*MDT0000.sync_lock_cancel")
5004         [ $soc == "never" ] || error "SoC enabled on single MDS"
5005
5006         for i in $(seq 2 $MDSCOUNT); do
5007                 mdsdev=$(mdsdevname $i)
5008                 mdsvdev=$(mdsvdevname $i)
5009                 opts_mds="$(mkfs_opts mds$i $mdsdev) --reformat $mdsdev \
5010                           $mdsvdev"
5011                 add mds$i $opts_mds || error "add mds$i failed"
5012                 start_mdt $i || error "start mdt$i fail"
5013         done
5014
5015         wait_dne_interconnect
5016
5017         for i in $(seq $MDSCOUNT); do
5018                 soc=$(do_facet mds$i "$LCTL get_param -n \
5019                         mdt.*MDT000$((i - 1)).sync_lock_cancel")
5020                 [ $soc == "blocking" ] || error "SoC not enabled on DNE"
5021         done
5022
5023         for i in $(seq 2 $MDSCOUNT); do
5024                 stop_mdt $i || error "stop mdt$i fail"
5025         done
5026         soc=$(do_facet mds1 "$LCTL get_param -n \
5027                 mdt.*MDT0000.sync_lock_cancel")
5028         [ $soc == "never" ] || error "SoC enabled on single MDS"
5029
5030         cleanup || error "cleanup failed with $?"
5031 }
5032 run_test 70e "Sync-on-Cancel will be enabled by default on DNE"
5033
5034 test_71a() {
5035         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5036         if combined_mgs_mds; then
5037                 skip "needs separate MGS/MDT" && return
5038         fi
5039         local MDTIDX=1
5040
5041         start_mdt 1 || error "MDT0 start fail"
5042         start_ost || error "OST0 start fail"
5043         for num in $(seq 2 $MDSCOUNT); do
5044                 start_mdt $num || return
5045         done
5046
5047         start_ost2 || error "OST1 start fail"
5048
5049         mount_client $MOUNT || error "mount client fails"
5050
5051         mkdir $DIR/$tdir || error "mkdir fail"
5052         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5053                 error "create remote dir succeed"
5054
5055         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5056         rm -rf $DIR/$tdir || error "delete dir fail"
5057
5058         umount_client $MOUNT || error "umount_client failed"
5059         stop_mds || error "MDS stop fail"
5060         stop_ost || error "OST0 stop fail"
5061         stop_ost2 || error "OST1 stop fail"
5062 }
5063 run_test 71a "start MDT0 OST0, MDT1, OST1"
5064
5065 test_71b() {
5066         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5067         if combined_mgs_mds; then
5068                 skip "needs separate MGS/MDT" && return
5069         fi
5070         local MDTIDX=1
5071
5072         for num in $(seq 2 $MDSCOUNT); do
5073                 start_mdt $num || return
5074         done
5075         start_ost || error "OST0 start fail"
5076         start_mdt 1 || error "MDT0 start fail"
5077         start_ost2 || error "OST1 start fail"
5078
5079         mount_client $MOUNT || error "mount client fails"
5080
5081         mkdir $DIR/$tdir || error "mkdir fail"
5082         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5083                 error "create remote dir succeed"
5084
5085         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5086         rm -rf $DIR/$tdir || error "delete dir fail"
5087
5088         umount_client $MOUNT || error "umount_client failed"
5089         stop_mds || error "MDT0 stop fail"
5090         stop_ost || error "OST0 stop fail"
5091         stop_ost2 || error "OST1 stop fail"
5092 }
5093 run_test 71b "start MDT1, OST0, MDT0, OST1"
5094
5095 test_71c() {
5096         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5097         if combined_mgs_mds; then
5098                 skip "needs separate MGS/MDT" && return
5099         fi
5100         local MDTIDX=1
5101
5102         start_ost || error "OST0 start fail"
5103         start_ost2 || error "OST1 start fail"
5104         for num in $(seq 2 $MDSCOUNT); do
5105                 start_mdt $num || return
5106         done
5107         start_mdt 1 || error "MDT0 start fail"
5108
5109         mount_client $MOUNT || error "mount client fails"
5110
5111         mkdir $DIR/$tdir || error "mkdir fail"
5112         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5113                 error "create remote dir succeed"
5114
5115         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5116         rm -rf $DIR/$tdir || error "delete dir fail"
5117
5118         umount_client $MOUNT || error "umount_client failed"
5119         stop_mds || error "MDS stop fail"
5120         stop_ost || error "OST0 stop fail"
5121         stop_ost2 || error "OST1 stop fail"
5122
5123 }
5124 run_test 71c "start OST0, OST1, MDT1, MDT0"
5125
5126 test_71d() {
5127         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5128         if combined_mgs_mds; then
5129                 skip "needs separate MGS/MDT" && return
5130         fi
5131         local MDTIDX=1
5132
5133         start_ost || error "OST0 start fail"
5134         for num in $(seq 2 $MDSCOUNT); do
5135                 start_mdt $num || return
5136         done
5137         start_mdt 1 || error "MDT0 start fail"
5138         start_ost2 || error "OST1 start fail"
5139
5140         mount_client $MOUNT || error "mount client fails"
5141
5142         mkdir $DIR/$tdir || error "mkdir fail"
5143         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5144                         error "create remote dir succeed"
5145
5146         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5147         rm -rf $DIR/$tdir || error "delete dir fail"
5148
5149         umount_client $MOUNT || error "umount_client failed"
5150         stop_mds || error "MDS stop fail"
5151         stop_ost || error "OST0 stop fail"
5152         stop_ost2 || error "OST1 stop fail"
5153
5154 }
5155 run_test 71d "start OST0, MDT1, MDT0, OST1"
5156
5157 test_71e() {
5158         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
5159         if combined_mgs_mds; then
5160                 skip "needs separate MGS/MDT" && return
5161         fi
5162         local MDTIDX=1
5163
5164         start_ost || error "OST0 start fail"
5165         for num in $(seq 2 $MDSCOUNT); do
5166                 start_mdt $num || return
5167         done
5168         start_ost2 || error "OST1 start fail"
5169         start_mdt 1 || error "MDT0 start fail"
5170
5171         mount_client $MOUNT || error "mount client fails"
5172
5173         mkdir $DIR/$tdir || error "mkdir fail"
5174         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5175                 error "create remote dir succeed"
5176
5177         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5178         rm -rf $DIR/$tdir || error "delete dir fail"
5179
5180         umount_client $MOUNT || error "umount_client failed"
5181         stop_mds || error "MDS stop fail"
5182         stop_ost || error "OST0 stop fail"
5183         stop_ost2 || error "OST1 stop fail"
5184
5185 }
5186 run_test 71e "start OST0, MDT1, OST1, MDT0"
5187
5188 test_72() { #LU-2634
5189         local mdsdev=$(mdsdevname 1)
5190         local ostdev=$(ostdevname 1)
5191         local cmd="$E2FSCK -fnvd $mdsdev"
5192         local fn=3
5193         local add_options
5194
5195         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
5196                 skip "ldiskfs only test" && return
5197
5198         if combined_mgs_mds; then
5199                 add_options='--reformat'
5200         else
5201                 add_options='--reformat --replace'
5202         fi
5203
5204         #tune MDT with "-O extents"
5205
5206         for num in $(seq $MDSCOUNT); do
5207                 add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
5208                         $add_options $(mdsdevname $num) $(mdsvdevname $num) ||
5209                         error "add mds $num failed"
5210                 do_facet mds${num} "$TUNE2FS -O extents $(mdsdevname $num)" ||
5211                         error "$TUNE2FS failed on mds${num}"
5212         done
5213
5214         add ost1 $(mkfs_opts ost1 $ostdev) $add_options $ostdev ||
5215                 error "add $ostdev failed"
5216         start_mds || error "start mds failed"
5217         start_ost || error "start ost failed"
5218         mount_client $MOUNT || error "mount client failed"
5219
5220         #create some short symlinks
5221         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5222         createmany -o $DIR/$tdir/$tfile-%d $fn
5223         echo "create $fn short symlinks"
5224         for i in $(seq -w 1 $fn); do
5225                 ln -s $DIR/$tdir/$tfile-$i $MOUNT/$tfile-$i
5226         done
5227         ls -al $MOUNT
5228
5229         #umount
5230         umount_client $MOUNT || error "umount client failed"
5231         stop_mds || error "stop mds failed"
5232         stop_ost || error "stop ost failed"
5233
5234         #run e2fsck
5235         run_e2fsck $(facet_active_host $SINGLEMDS) $mdsdev "-n"
5236 }
5237 run_test 72 "test fast symlink with extents flag enabled"
5238
5239 test_73() { #LU-3006
5240         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
5241         do_facet ost1 "$TUNEFS --failnode=1.2.3.4@$NETTYPE $(ostdevname 1)" ||
5242                 error "1st tunefs failed"
5243         start_mgsmds || error "start mds failed"
5244         start_ost || error "start ost failed"
5245         mount_client $MOUNT || error "mount client failed"
5246         $LCTL get_param -n osc.*OST0000-osc-[^M]*.import | grep failover_nids |
5247                 grep 1.2.3.4@$NETTYPE || error "failover nids haven't changed"
5248         umount_client $MOUNT || error "umount client failed"
5249         stopall
5250         reformat
5251 }
5252 run_test 73 "failnode to update from mountdata properly"
5253
5254 test_75() { # LU-2374
5255         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
5256                         skip "Need MDS version at least 2.4.1" && return
5257
5258         local index=0
5259         local opts_mds="$(mkfs_opts mds1 $(mdsdevname 1)) \
5260                 --reformat $(mdsdevname 1) $(mdsvdevname 1)"
5261         local opts_ost="$(mkfs_opts ost1 $(ostdevname 1)) \
5262                 --reformat $(ostdevname 1) $(ostvdevname 1)"
5263
5264         #check with default parameters
5265         add mds1 $opts_mds || error "add mds1 failed for default params"
5266         add ost1 $opts_ost || error "add ost1 failed for default params"
5267
5268         opts_mds=$(echo $opts_mds | sed -e "s/--mdt//")
5269         opts_mds=$(echo $opts_mds |
5270                    sed -e "s/--index=$index/--index=$index --mdt/")
5271         opts_ost=$(echo $opts_ost | sed -e "s/--ost//")
5272         opts_ost=$(echo $opts_ost |
5273                    sed -e "s/--index=$index/--index=$index --ost/")
5274
5275         add mds1 $opts_mds || error "add mds1 failed for new params"
5276         add ost1 $opts_ost || error "add ost1 failed for new params"
5277         if ! combined_mgs_mds; then
5278                 stop_mgs || error "stop mgs failed"
5279         fi
5280         reformat
5281         return 0
5282 }
5283 run_test 75 "The order of --index should be irrelevant"
5284
5285 test_76a() {
5286         [[ $(lustre_version_code mgs) -ge $(version_code 2.4.52) ]] ||
5287                 { skip "Need MDS version at least 2.4.52" && return 0; }
5288
5289         if ! combined_mgs_mds; then
5290                 start_mgs || error "start mgs failed"
5291         fi
5292         setup
5293         local MDMB_PARAM="osc.*.max_dirty_mb"
5294         echo "Change MGS params"
5295         local MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM |
5296                 head -1)
5297         echo "max_dirty_mb: $MAX_DIRTY_MB"
5298         local NEW_MAX_DIRTY_MB=$((MAX_DIRTY_MB + MAX_DIRTY_MB))
5299         echo "new_max_dirty_mb: $NEW_MAX_DIRTY_MB"
5300         do_facet mgs $LCTL set_param -P $MDMB_PARAM=$NEW_MAX_DIRTY_MB
5301         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
5302                 head -1" $NEW_MAX_DIRTY_MB
5303         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
5304         echo "$MAX_DIRTY_MB"
5305         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
5306                 error "error while apply max_dirty_mb"
5307
5308         echo "Check the value is stored after remount"
5309         stopall
5310         setupall
5311         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
5312                 head -1" $NEW_MAX_DIRTY_MB
5313         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
5314         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
5315                 error "max_dirty_mb is not saved after remount"
5316
5317         echo "Change OST params"
5318         CLIENT_PARAM="obdfilter.*.client_cache_count"
5319         local CLIENT_CACHE_COUNT
5320         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
5321                 head -1)
5322         echo "client_cache_count: $CLIENT_CACHE_COUNT"
5323         NEW_CLIENT_CACHE_COUNT=$((CLIENT_CACHE_COUNT+CLIENT_CACHE_COUNT))
5324         echo "new_client_cache_count: $NEW_CLIENT_CACHE_COUNT"
5325         do_facet mgs $LCTL set_param -P $CLIENT_PARAM=$NEW_CLIENT_CACHE_COUNT
5326         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
5327                 head -1" $NEW_CLIENT_CACHE_COUNT
5328         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
5329                 head -1)
5330         echo "$CLIENT_CACHE_COUNT"
5331         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
5332                 error "error while apply client_cache_count"
5333
5334         echo "Check the value is stored after remount"
5335         stopall
5336         setupall
5337         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
5338                 head -1" $NEW_CLIENT_CACHE_COUNT
5339         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
5340                 head -1)
5341         echo "$CLIENT_CACHE_COUNT"
5342         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
5343                 error "client_cache_count is not saved after remount"
5344         stopall
5345 }
5346 run_test 76a "set permanent params set_param -P"
5347
5348 test_76b() { # LU-4783
5349         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.57) ]] ||
5350                 { skip "Need MGS version at least 2.5.57" && return 0; }
5351         stopall
5352         setupall
5353         do_facet mgs $LCTL get_param mgs.MGS.live.params ||
5354                 error "start params log failed"
5355         stopall
5356 }
5357 run_test 76b "verify params log setup correctly"
5358
5359 test_76c() {
5360         [[ $(lustre_version_code mgs) -ge $(version_code 2.8.54) ]] ||
5361                 { skip "Need MDS version at least 2.4.52" && return 0; }
5362         setupall
5363         local MASK_PARAM="mdd.*.changelog_mask"
5364         echo "Change changelog_mask"
5365         do_facet mgs $LCTL set_param -P $MASK_PARAM=-CLOSE ||
5366                 error "Can't change changlog_mask"
5367         wait_update $(facet_host mds) "$LCTL get_param -n $MASK_PARAM |
5368                 grep 'CLOSE'" ""
5369
5370         echo "Check the value is stored after mds remount"
5371         stop_mds || error "Failed to stop MDS"
5372         start_mds || error "Failed to start MDS"
5373         local CHANGELOG_MASK=$(do_facet mgs $LCTL get_param -n $MASK_PARAM)
5374         echo $CHANGELOG_MASK | grep CLOSE > /dev/null &&
5375                 error "changelog_mask is not changed"
5376
5377         stopall
5378 }
5379 run_test 76c "verify changelog_mask is applied with set_param -P"
5380
5381 test_76d() { #LU-9399
5382         setupall
5383
5384         local xattr_cache="llite.*.xattr_cache"
5385         local cmd="$LCTL get_param -n $xattr_cache | head -1"
5386         local new=$((($(eval $cmd) + 1) % 2))
5387
5388         echo "lctl set_param -P llite.*.xattr_cache=$new"
5389         do_facet mgs $LCTL set_param -P $xattr_cache=$new ||
5390                 error "Can't change xattr_cache"
5391         wait_update $HOSTNAME "$cmd" "$new"
5392
5393         echo "Check $xattr_cache on client $MOUNT"
5394         umount_client $MOUNT || error "umount $MOUNT failed"
5395         mount_client $MOUNT || error "mount $MOUNT failed"
5396         [ $(eval $cmd) -eq $new ] ||
5397                 error "$xattr_cache != $new on client $MOUNT"
5398
5399         echo "Check $xattr_cache on the new client $MOUNT2"
5400         mount_client $MOUNT2 || error "mount $MOUNT2 failed"
5401         [ $(eval $cmd) -eq $new ] ||
5402                 error "$xattr_cache != $new on client $MOUNT2"
5403         umount_client $MOUNT2 || error "umount $MOUNT2 failed"
5404
5405         stopall
5406 }
5407 run_test 76d "verify llite.*.xattr_cache can be set by 'set_param -P' correctly"
5408
5409 test_77() { # LU-3445
5410         local server_version=$(lustre_version_code $SINGLEMDS)
5411         [[ $server_version -ge $(version_code 2.8.55) ]] ||
5412                 { skip "Need MDS version 2.8.55+ "; return; }
5413
5414         if [[ -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
5415                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
5416                 skip_env "mixed loopback and real device not working" && return
5417         fi
5418
5419         local fs2mdsdev=$(mdsdevname 1_2)
5420         local fs2ostdev=$(ostdevname 1_2)
5421         local fs2mdsvdev=$(mdsvdevname 1_2)
5422         local fs2ostvdev=$(ostvdevname 1_2)
5423         local fsname=test1234
5424         local mgsnid
5425         local failnid="$(h2nettype 1.2.3.4),$(h2nettype 4.3.2.1)"
5426
5427         combined_mgs_mds || stop_mgs || error "stopping MGS service failed"
5428
5429         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --mgs --fsname=$fsname \
5430                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
5431         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT ||
5432                 error "start fs2mds failed"
5433
5434         mgsnid=$(do_facet fs2mds $LCTL list_nids | xargs | tr ' ' ,)
5435         mgsnid="0.0.0.0@tcp,$mgsnid,$mgsnid:$mgsnid"
5436
5437         add fs2ost --mgsnode=$mgsnid $(mkfs_opts ost1 $fs2ostdev) \
5438                 --failnode=$failnid --fsname=$fsname \
5439                 --reformat $fs2ostdev $fs2ostvdev ||
5440                         error "add fs2ost failed"
5441         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
5442
5443         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
5444         $MOUNT_CMD $mgsnid:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
5445         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
5446         cleanup_fs2
5447 }
5448 run_test 77 "comma-separated MGS NIDs and failover node NIDs"
5449
5450 test_78() {
5451         [[ $(facet_fstype $SINGLEMDS) != ldiskfs ||
5452            $(facet_fstype ost1) != ldiskfs ]] &&
5453                 skip "ldiskfs only test" && return
5454
5455         # reformat the Lustre filesystem with a smaller size
5456         local saved_MDSCOUNT=$MDSCOUNT
5457         local saved_MDSSIZE=$MDSSIZE
5458         local saved_OSTCOUNT=$OSTCOUNT
5459         local saved_OSTSIZE=$OSTSIZE
5460         MDSCOUNT=1
5461         OSTCOUNT=1
5462         MDSSIZE=$((MDSSIZE - 20000))
5463         OSTSIZE=$((OSTSIZE - 20000))
5464         reformat || error "(1) reformat Lustre filesystem failed"
5465         MDSSIZE=$saved_MDSSIZE
5466         OSTSIZE=$saved_OSTSIZE
5467
5468         # mount the Lustre filesystem
5469         setup_noconfig || error "(2) setup Lustre filesystem failed"
5470
5471         # create some files
5472         log "create test files"
5473         local i
5474         local file
5475         local num_files=100
5476
5477         mkdir $MOUNT/$tdir || error "(3) mkdir $MOUNT/$tdir failed"
5478         $LFS df; $LFS df -i
5479         for i in $(seq $num_files); do
5480                 file=$MOUNT/$tdir/$tfile-$i
5481                 dd if=/dev/urandom of=$file count=1 bs=1M || {
5482                         $LCTL get_param osc.*.cur*grant*
5483                         $LFS df; $LFS df -i;
5484                         # stop creating files if there is no more space
5485                         if [ ! -e $file ]; then
5486                                 num_files=$((i - 1))
5487                                 break
5488                         fi
5489
5490                         $LFS getstripe -v $file
5491                         local ost_idx=$(LFS getstripe -i $file)
5492                         do_facet ost$((ost_idx + 1)) \
5493                                 $LCTL get_param obdfilter.*.*grant*
5494                         error "(4) create $file failed"
5495                 }
5496         done
5497
5498         # unmount the Lustre filesystem
5499         cleanup || error "(5) cleanup Lustre filesystem failed"
5500
5501         # run e2fsck on the MDT and OST devices
5502         local mds_host=$(facet_active_host $SINGLEMDS)
5503         local ost_host=$(facet_active_host ost1)
5504         local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
5505         local ost_dev=$(ostdevname 1)
5506
5507         run_e2fsck $mds_host $mds_dev "-y"
5508         run_e2fsck $ost_host $ost_dev "-y"
5509
5510         # get the original block count of the MDT and OST filesystems
5511         local mds_orig_blks=$(get_block_count $SINGLEMDS $mds_dev)
5512         local ost_orig_blks=$(get_block_count ost1 $ost_dev)
5513
5514         # expand the MDT and OST filesystems to the device size
5515         run_resize2fs $SINGLEMDS $mds_dev "" || error "expand $SINGLEMDS failed"
5516         run_resize2fs ost1 $ost_dev "" || error "expand ost1 failed"
5517
5518         # run e2fsck on the MDT and OST devices again
5519         run_e2fsck $mds_host $mds_dev "-y"
5520         run_e2fsck $ost_host $ost_dev "-y"
5521
5522         # mount the Lustre filesystem
5523         setup
5524
5525         # check the files
5526         log "check files after expanding the MDT and OST filesystems"
5527         for i in $(seq $num_files); do
5528                 file=$MOUNT/$tdir/$tfile-$i
5529                 $CHECKSTAT -t file -s 1048576 $file ||
5530                         error "(6) checkstat $file failed"
5531         done
5532
5533         # create more files
5534         log "create more files after expanding the MDT and OST filesystems"
5535         for i in $(seq $((num_files + 1)) $((num_files + 10))); do
5536                 file=$MOUNT/$tdir/$tfile-$i
5537                 dd if=/dev/urandom of=$file count=1 bs=1M ||
5538                         error "(7) create $file failed"
5539         done
5540
5541         # unmount the Lustre filesystem
5542         cleanup || error "(8) cleanup Lustre filesystem failed"
5543
5544         # run e2fsck on the MDT and OST devices
5545         run_e2fsck $mds_host $mds_dev "-y"
5546         run_e2fsck $ost_host $ost_dev "-y"
5547
5548         # get the maximum block count of the MDT and OST filesystems
5549         local mds_max_blks=$(get_block_count $SINGLEMDS $mds_dev)
5550         local ost_max_blks=$(get_block_count ost1 $ost_dev)
5551
5552         # get the minimum block count of the MDT and OST filesystems
5553         local mds_min_blks=$(run_resize2fs $SINGLEMDS $mds_dev "" "-P" 2>&1 |
5554                                 grep minimum | sed -e 's/^.*filesystem: //g')
5555         local ost_min_blks=$(run_resize2fs ost1 $ost_dev "" "-P" 2>&1 |
5556                                 grep minimum | sed -e 's/^.*filesystem: //g')
5557
5558         # shrink the MDT and OST filesystems to a smaller size
5559         local shrunk=false
5560         local new_blks
5561         local base_blks
5562         if [[ $mds_max_blks -gt $mds_min_blks &&
5563               $mds_max_blks -gt $mds_orig_blks ]]; then
5564                 [[ $mds_orig_blks -gt $mds_min_blks ]] &&
5565                         base_blks=$mds_orig_blks || base_blks=$mds_min_blks
5566                 new_blks=$(( (mds_max_blks - base_blks) / 2 + base_blks ))
5567                 run_resize2fs $SINGLEMDS $mds_dev $new_blks ||
5568                         error "shrink $SINGLEMDS to $new_blks failed"
5569                 shrunk=true
5570         fi
5571
5572         if [[ $ost_max_blks -gt $ost_min_blks &&
5573               $ost_max_blks -gt $ost_orig_blks ]]; then
5574                 [[ $ost_orig_blks -gt $ost_min_blks ]] &&
5575                         base_blks=$ost_orig_blks || base_blks=$ost_min_blks
5576                 new_blks=$(( (ost_max_blks - base_blks) / 2 + base_blks ))
5577                 run_resize2fs ost1 $ost_dev $new_blks ||
5578                         error "shrink ost1 to $new_blks failed"
5579                 shrunk=true
5580         fi
5581
5582         # check whether the MDT or OST filesystem was shrunk or not
5583         if ! $shrunk; then
5584                 combined_mgs_mds || stop_mgs || error "(9) stop mgs failed"
5585                 reformat || error "(10) reformat Lustre filesystem failed"
5586                 return 0
5587         fi
5588
5589         # run e2fsck on the MDT and OST devices again
5590         run_e2fsck $mds_host $mds_dev "-y"
5591         run_e2fsck $ost_host $ost_dev "-y"
5592
5593         # mount the Lustre filesystem again
5594         setup
5595
5596         # check the files
5597         log "check files after shrinking the MDT and OST filesystems"
5598         for i in $(seq $((num_files + 10))); do
5599                 file=$MOUNT/$tdir/$tfile-$i
5600                 $CHECKSTAT -t file -s 1048576 $file ||
5601                         error "(11) checkstat $file failed"
5602         done
5603
5604         # unmount and reformat the Lustre filesystem
5605         cleanup || error "(12) cleanup Lustre filesystem failed"
5606         combined_mgs_mds || stop_mgs || error "(13) stop mgs failed"
5607
5608         MDSCOUNT=$saved_MDSCOUNT
5609         OSTCOUNT=$saved_OSTCOUNT
5610         reformat || error "(14) reformat Lustre filesystem failed"
5611 }
5612 run_test 78 "run resize2fs on MDT and OST filesystems"
5613
5614 test_79() { # LU-4227
5615         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.59) ]] ||
5616                 { skip "Need MDS version at least 2.5.59"; return 0; }
5617
5618         local mdsdev1=$(mdsdevname 1)
5619         local mdsvdev1=$(mdsvdevname 1)
5620         local mdsdev2=$(mdsdevname 2)
5621         local mdsvdev2=$(mdsvdevname 2)
5622         local ostdev1=$(ostdevname 1)
5623         local ostvdev1=$(ostvdevname 1)
5624         local opts_mds1="$(mkfs_opts mds1 $mdsdev1) --reformat"
5625         local opts_mds2="$(mkfs_opts mds2 $mdsdev2) --reformat"
5626         local opts_ost1="$(mkfs_opts ost1 $ostdev1) --reformat"
5627         local mgsnode_opt
5628
5629         # remove --mgs/--mgsnode from mkfs.lustre options
5630         opts_mds1=$(echo $opts_mds1 | sed -e "s/--mgs//")
5631
5632         mgsnode_opt=$(echo $opts_mds2 |
5633                 awk '{ for ( i = 1; i < NF; i++ )
5634                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
5635         [ -n $mgsnode_opt ] &&
5636                 opts_mds2=$(echo $opts_mds2 | sed -e "s/$mgsnode_opt//")
5637
5638         mgsnode_opt=$(echo $opts_ost1 |
5639                 awk '{ for ( i = 1; i < NF; i++ )
5640                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
5641         [ -n $mgsnode_opt ] &&
5642                 opts_ost1=$(echo $opts_ost1 | sed -e "s/$mgsnode_opt//")
5643
5644         # -MGS, format a mdt without --mgs option
5645         add mds1 $opts_mds1 $mdsdev1 $mdsvdev1 &&
5646                 error "Must specify --mgs when formatting mdt combined with mgs"
5647
5648         # +MGS, format a mdt/ost without --mgsnode option
5649         add mds1 $(mkfs_opts mds1 $mdsdev1) --reformat $mdsdev1 $mdsvdev1 \
5650                 > /dev/null || error "start mds1 failed"
5651         add mds2 $opts_mds2 $mdsdev2 $mdsvdev2 &&
5652                 error "Must specify --mgsnode when formatting a mdt"
5653         add ost1 $opts_ost1 $ostdev1 $ostvdev2 &&
5654                 error "Must specify --mgsnode when formatting an ost"
5655
5656         reformat
5657 }
5658 run_test 79 "format MDT/OST without mgs option (should return errors)"
5659
5660 test_80() {
5661         start_mds || error "Failed to start MDT"
5662         start_ost || error "Failed to start OST1"
5663         uuid=$(do_facet ost1 $LCTL get_param -n mgc.*.uuid)
5664 #define OBD_FAIL_MGS_PAUSE_TARGET_CON       0x906
5665         do_facet ost1 "$LCTL set_param fail_val=10 fail_loc=0x906"
5666         do_facet mgs "$LCTL set_param fail_val=10 fail_loc=0x906"
5667         do_facet mgs "$LCTL set_param -n mgs/MGS/evict_client $uuid"
5668         sleep 30
5669         start_ost2 || error "Failed to start OST2"
5670
5671         do_facet ost1 "$LCTL set_param fail_loc=0"
5672         stopall
5673 }
5674 run_test 80 "mgc import reconnect race"
5675
5676 #Save the original values of $OSTCOUNT and $OSTINDEX$i.
5677 save_ostindex() {
5678         local new_ostcount=$1
5679         saved_ostcount=$OSTCOUNT
5680         OSTCOUNT=$new_ostcount
5681
5682         local i
5683         local index
5684         for i in $(seq $OSTCOUNT); do
5685                 index=OSTINDEX$i
5686                 eval saved_ostindex$i=${!index}
5687                 eval OSTINDEX$i=""
5688         done
5689 }
5690
5691 # Restore the original values of $OSTCOUNT and $OSTINDEX$i.
5692 restore_ostindex() {
5693         trap 0
5694
5695         local i
5696         local index
5697         for i in $(seq $OSTCOUNT); do
5698                 index=saved_ostindex$i
5699                 eval OSTINDEX$i=${!index}
5700         done
5701         OSTCOUNT=$saved_ostcount
5702
5703         formatall
5704 }
5705
5706 # The main purpose of this test is to ensure the OST_INDEX_LIST functions as
5707 # expected. This test uses OST_INDEX_LIST to format OSTs with a randomly
5708 # assigned index and ensures we can mount such a formatted file system
5709 test_81() { # LU-4665
5710         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
5711                 { skip "Need MDS version at least 2.6.54" && return; }
5712         [[ $OSTCOUNT -ge 3 ]] || { skip_env "needs >= 3 OSTs" && return; }
5713
5714         stopall
5715
5716         # Each time RANDOM is referenced, a random integer between 0 and 32767
5717         # is generated.
5718         local i
5719         local saved_ostindex1=$OSTINDEX1
5720         for i in 65535 $((RANDOM + 65536)); do
5721                 echo -e "\nFormat ost1 with --index=$i, should fail"
5722                 OSTINDEX1=$i
5723                 if add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat \
5724                    $(ostdevname 1) $(ostvdevname 1); then
5725                         OSTINDEX1=$saved_ostindex1
5726                         error "format ost1 with --index=$i should fail"
5727                 fi
5728         done
5729         OSTINDEX1=$saved_ostindex1
5730
5731         save_ostindex 3
5732
5733         # Format OSTs with random sparse indices.
5734         trap "restore_ostindex" EXIT
5735         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices"
5736         OST_INDEX_LIST=[0,$((RANDOM * 2 % 65533 + 1)),65534] formatall
5737
5738         # Setup and check Lustre filesystem.
5739         start_mgsmds || error "start_mgsmds failed"
5740         for i in $(seq $OSTCOUNT); do
5741                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5742                         error "start ost$i failed"
5743         done
5744
5745         mount_client $MOUNT || error "mount client $MOUNT failed"
5746         check_mount || error "check client $MOUNT failed"
5747
5748         # Check max_easize.
5749         local max_easize=$($LCTL get_param -n llite.*.max_easize)
5750         [[ $max_easize -eq 128 ]] ||
5751                 error "max_easize is $max_easize, should be 128 bytes"
5752
5753         restore_ostindex
5754 }
5755 run_test 81 "sparse OST indexing"
5756
5757 # Here we exercise the stripe placement functionality on a file system that
5758 # has formatted the OST with a random index. With the file system the following
5759 # functionality is tested:
5760 #
5761 # 1. Creating a new file with a specific stripe layout.
5762 #
5763 # 2. Modifiy a existing empty file with a specific stripe layout.
5764 #
5765 # 3. Ensure we fail to set the stripe layout of a file that already has one.
5766 #
5767 # 4. If ost-index is defined we need to ensure it is the first entry in the
5768 #    ost index list returned by lfs getstripe.
5769 #
5770 # 5. Lastly ensure this functionality fails with directories.
5771 test_82a() { # LU-4665
5772         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
5773                 { skip "Need MDS version at least 2.6.54" && return; }
5774         [[ $OSTCOUNT -ge 3 ]] || { skip_env "needs >= 3 OSTs" && return; }
5775
5776         stopall
5777
5778         save_ostindex 3
5779
5780         # Format OSTs with random sparse indices.
5781         local i
5782         local index
5783         local ost_indices
5784         local LOV_V1_INSANE_STRIPE_COUNT=65532
5785         for i in $(seq $OSTCOUNT); do
5786                 index=$(((RANDOM * 2) % LOV_V1_INSANE_STRIPE_COUNT))
5787                 ost_indices+=" $index"
5788         done
5789         ost_indices=$(comma_list $ost_indices)
5790
5791         trap "restore_ostindex" EXIT
5792         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
5793         OST_INDEX_LIST=[$ost_indices] formatall
5794
5795         # Setup Lustre filesystem.
5796         start_mgsmds || error "start_mgsmds failed"
5797         for i in $(seq $OSTCOUNT); do
5798                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5799                         error "start ost$i failed"
5800         done
5801
5802         mount_client $MOUNT || error "mount client $MOUNT failed"
5803         wait_osts_up
5804
5805         $LFS df $MOUNT || error "$LFS df $MOUNT failed"
5806         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5807
5808         # 1. If the file does not exist, new file will be created
5809         #    with specified OSTs.
5810         local file=$DIR/$tdir/$tfile-1
5811         local cmd="$SETSTRIPE -o $ost_indices $file"
5812         echo -e "\n$cmd"
5813         eval $cmd || error "$cmd failed"
5814         check_stripe_count $file $OSTCOUNT
5815         check_obdidx $file $ost_indices
5816         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5817                 error "write $file failed"
5818
5819         # 2. If the file already exists and is an empty file, the file
5820         #    will be attached with specified layout.
5821         file=$DIR/$tdir/$tfile-2
5822         mcreate $file || error "mcreate $file failed"
5823         cmd="$SETSTRIPE -o $ost_indices $file"
5824         echo -e "\n$cmd"
5825         eval $cmd || error "$cmd failed"
5826         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5827                 error "write $file failed"
5828         check_stripe_count $file $OSTCOUNT
5829         check_obdidx $file $ost_indices
5830
5831         # 3. If the file already has a valid layout attached, the command
5832         #    should fail with EBUSY.
5833         echo -e "\n$cmd"
5834         eval $cmd && error "stripe is already set on $file, $cmd should fail"
5835
5836         # 4. If [--stripe-index|-i <start_ost_idx>] is used, the index must
5837         #    be in the OST indices list.
5838         local start_ost_idx=${ost_indices##*,}
5839         file=$DIR/$tdir/$tfile-3
5840         cmd="$SETSTRIPE -o $ost_indices -i $start_ost_idx $file"
5841         echo -e "\n$cmd"
5842         eval $cmd || error "$cmd failed"
5843         check_stripe_count $file $OSTCOUNT
5844         check_obdidx $file $ost_indices
5845         check_start_ost_idx $file $start_ost_idx
5846
5847         file=$DIR/$tdir/$tfile-4
5848         cmd="$SETSTRIPE"
5849         cmd+=" -o $(exclude_items_from_list $ost_indices $start_ost_idx)"
5850         cmd+=" -i $start_ost_idx $file"
5851         echo -e "\n$cmd"
5852         eval $cmd && error "index $start_ost_idx should be in $ost_indices"
5853
5854         # 5. Specifying OST indices for directory should fail with ENOSUPP.
5855         local dir=$DIR/$tdir/$tdir
5856         mkdir $dir || error "mkdir $dir failed"
5857         cmd="$SETSTRIPE -o $ost_indices $dir"
5858         echo -e "\n$cmd"
5859         eval $cmd && error "$cmd should fail, specifying OST indices" \
5860                            "for directory is not supported"
5861
5862         restore_ostindex
5863 }
5864 run_test 82a "specify OSTs for file (succeed) or directory (fail)"
5865
5866 cleanup_82b() {
5867         trap 0
5868
5869         # Remove OSTs from a pool and destroy the pool.
5870         destroy_pool $ost_pool || true
5871
5872         restore_ostindex
5873 }
5874
5875 # Test 82b is run to ensure that if the user supplies a pool with a specific
5876 # stripe layout that it behaves proprerly. It should fail in the case that
5877 # the supplied OST index list points to OSTs not contained in the user
5878 # supplied pool.
5879 test_82b() { # LU-4665
5880         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
5881                 { skip "Need MDS version at least 2.6.54" && return; }
5882         [[ $OSTCOUNT -ge 4 ]] || { skip_env "needs >= 4 OSTs" && return; }
5883
5884         stopall
5885
5886         save_ostindex 4
5887
5888         # Format OSTs with random sparse indices.
5889         local i
5890         local index
5891         local ost_indices
5892         local LOV_V1_INSANE_STRIPE_COUNT=65532
5893         for i in $(seq $OSTCOUNT); do
5894                 index=$(((RANDOM * 2) % LOV_V1_INSANE_STRIPE_COUNT))
5895                 ost_indices+=" $index"
5896         done
5897         ost_indices=$(comma_list $ost_indices)
5898
5899         trap "restore_ostindex" EXIT
5900         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
5901         OST_INDEX_LIST=[$ost_indices] formatall
5902
5903         # Setup Lustre filesystem.
5904         start_mgsmds || error "start_mgsmds failed"
5905         for i in $(seq $OSTCOUNT); do
5906                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5907                         error "start ost$i failed"
5908         done
5909
5910         mount_client $MOUNT || error "mount client $MOUNT failed"
5911         wait_osts_up
5912         $LFS df $MOUNT || error "$LFS df $MOUNT failed"
5913         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5914
5915         # Create a new pool and add OSTs into it.
5916         local ost_pool=$FSNAME.$TESTNAME
5917         create_pool $ost_pool || error "create OST pool $ost_pool failed"
5918
5919         trap - EXIT
5920         trap "cleanup_82b" EXIT
5921
5922         local ost_idx_in_list=${ost_indices##*,}
5923         local ost_idx_in_pool=$(exclude_items_from_list $ost_indices \
5924                                 $ost_idx_in_list)
5925
5926         local ost_targets="$FSNAME-OST["
5927         for i in ${ost_idx_in_pool//,/ }; do
5928                 ost_targets=$ost_targets$(printf "%04x," $i)
5929         done
5930         ost_targets="${ost_targets%,}]"
5931
5932         local ost_targets_uuid=$(for i in ${ost_idx_in_pool//,/ }; \
5933                                  do printf "$FSNAME-OST%04x_UUID\n" $i; done |
5934                                  sort -u | tr '\n' ' ')
5935
5936         local cmd="$LCTL pool_add $ost_pool $ost_targets"
5937         do_facet mgs $cmd || error "$cmd failed"
5938         wait_update $HOSTNAME "$LCTL get_param -n lov.$FSNAME-*.pools.$TESTNAME|
5939                                sort -u | tr '\n' ' ' " "$ost_targets_uuid" ||
5940                                         error "wait_update $ost_pool failed"
5941         wait_update_facet $SINGLEMDS "$LCTL pool_list $ost_pool | wc -l" 4 ||
5942                                 error "wait_update pool_list $ost_pool failed"
5943
5944         # If [--pool|-p <pool_name>] is set with [--ost-list|-o <ost_indices>],
5945         # then the OSTs must be the members of the pool.
5946         local file=$DIR/$tdir/$tfile
5947         cmd="$SETSTRIPE -p $ost_pool -o $ost_idx_in_list $file"
5948         echo -e "\n$cmd"
5949         eval $cmd && error "OST with index $ost_idx_in_list should be" \
5950                            "in OST pool $ost_pool"
5951
5952         # Only select OST $ost_idx_in_list from $ost_pool for file.
5953         ost_idx_in_list=${ost_idx_in_pool#*,}
5954         cmd="$SETSTRIPE -p $ost_pool -o $ost_idx_in_list $file"
5955         echo -e "\n$cmd"
5956         eval $cmd || error "$cmd failed"
5957         cmd="$GETSTRIPE $file"
5958         echo -e "\n$cmd"
5959         eval $cmd || error "$cmd failed"
5960         check_stripe_count $file 2
5961         check_obdidx $file $ost_idx_in_list
5962         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5963                 error "write $file failed"
5964
5965         cleanup_82b
5966 }
5967 run_test 82b "specify OSTs for file with --pool and --ost-list options"
5968
5969 test_83() {
5970         [[ $(lustre_version_code ost1) -ge $(version_code 2.6.91) ]] ||
5971                 { skip "Need OST version at least 2.6.91" && return 0; }
5972         if [ $(facet_fstype ost1) != ldiskfs ]; then
5973                 skip "ldiskfs only test"
5974                 return
5975         fi
5976
5977         local dev
5978         local ostmnt
5979         local fstype
5980         local mnt_opts
5981
5982         dev=$(ostdevname 1)
5983         ostmnt=$(facet_mntpt ost1)
5984         fstype=$(facet_fstype ost1)
5985
5986         # Mount the OST as an ldiskfs filesystem.
5987         log "mount the OST $dev as a $fstype filesystem"
5988         add ost1 $(mkfs_opts ost1 $dev) $FSTYPE_OPT \
5989                 --reformat $dev > /dev/null ||
5990                 error "format ost1 error"
5991
5992         if ! test -b $dev; then
5993                 mnt_opts=$(csa_add "$OST_MOUNT_OPTS" -o loop)
5994         fi
5995         echo "mnt_opts $mnt_opts"
5996         do_facet ost1 mount -t $fstype $dev \
5997                 $ostmnt $mnt_opts
5998         # Run llverfs on the mounted ldiskfs filesystem.
5999         # It is needed to get ENOSPACE.
6000         log "run llverfs in partial mode on the OST $fstype $ostmnt"
6001         do_rpc_nodes $(facet_host ost1) run_llverfs $ostmnt -vpl \
6002                 "no" || error "run_llverfs error on $fstype"
6003
6004         # Unmount the OST.
6005         log "unmount the OST $dev"
6006         stop ost1
6007
6008         # Delete file IO_scrub. Later osd_scrub_setup will try to
6009         # create "IO_scrub" but will get ENOSPACE.
6010         writeconf_all
6011         echo "start ost1 service on `facet_active_host ost1`"
6012         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
6013
6014         local err
6015         err=$(do_facet ost1 dmesg | grep "VFS: Busy inodes after unmount of")
6016         echo "string err $err"
6017         [ -z "$err" ] || error $err
6018         reformat
6019 }
6020 run_test 83 "ENOSPACE on OST doesn't cause message VFS: \
6021 Busy inodes after unmount ..."
6022
6023 test_84() {
6024         local facet=$SINGLEMDS
6025         local num=$(echo $facet | tr -d "mds")
6026         local dev=$(mdsdevname $num)
6027         local time_min=$(recovery_time_min)
6028         local recovery_duration
6029         local completed_clients
6030         local correct_clients
6031         local wrap_up=5
6032
6033         echo "start mds service on $(facet_active_host $facet)"
6034         start_mds \
6035         "-o recovery_time_hard=$time_min,recovery_time_soft=$time_min" $@ ||
6036                 error "start MDS failed"
6037
6038         start_ost || error "start OST0000 failed"
6039         start_ost2 || error "start OST0001 failed"
6040
6041         echo "recovery_time=$time_min, timeout=$TIMEOUT, wrap_up=$wrap_up"
6042
6043         mount_client $MOUNT1 || error "mount $MOUNT1 failed"
6044         mount_client $MOUNT2 || error "mount $MOUNT2 failed"
6045         # make sure new superblock labels are sync'd before disabling writes
6046         sync_all_data
6047         sleep 5
6048
6049         replay_barrier $SINGLEMDS
6050         createmany -o $DIR1/$tfile-%d 1000
6051
6052         # We need to catch the end of recovery window to extend it.
6053         # Skip 5 requests and add delay to request handling.
6054         #define OBD_FAIL_TGT_REPLAY_DELAY  0x709 | FAIL_SKIP
6055         do_facet $SINGLEMDS "lctl set_param fail_loc=0x20000709 fail_val=5"
6056
6057         facet_failover --fsck $SINGLEMDS || error "failover: $?"
6058         client_up
6059
6060         echo "recovery status"
6061         do_facet $SINGLEMDS \
6062                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status"
6063
6064         recovery_duration=$(do_facet $SINGLEMDS \
6065                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
6066                 awk '/recovery_duration/ { print $2 }')
6067         (( $recovery_duration > $time_min + $wrap_up )) &&
6068                 error "recovery_duration > recovery_time_hard + wrap up"
6069         completed_clients=$(do_facet $SINGLEMDS \
6070                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
6071                 awk '/completed_clients/ { print $2 }')
6072
6073         correct_clients="$MDSCOUNT/$((MDSCOUNT+1))"
6074         [ "$completed_clients" = "${correct_clients}" ] ||
6075                 error "$completed_clients != $correct_clients"
6076
6077         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
6078         umount_client $MOUNT1
6079         umount_client $MOUNT2
6080
6081         stop_ost
6082         stop_ost2
6083         stop_mds
6084 }
6085 run_test 84 "check recovery_hard_time"
6086
6087 test_85() {
6088         [[ $(lustre_version_code ost1) -ge $(version_code 2.7.55) ]] ||
6089                 { skip "Need OST version at least 2.7.55" && return 0; }
6090 ##define OBD_FAIL_OSD_OST_EA_FID_SET 0x197
6091         do_facet ost1 "lctl set_param fail_loc=0x197"
6092         start_ost
6093         stop_ost
6094 }
6095 run_test 85 "osd_ost init: fail ea_fid_set"
6096
6097 cleanup_86() {
6098         trap 0
6099
6100         # ost1 has already registered to the MGS before the reformat.
6101         # So after reformatting it with option "-G", it could not be
6102         # mounted to the MGS. Cleanup the system for subsequent tests.
6103         reformat_and_config
6104 }
6105
6106 test_86() {
6107         local server_version=$(lustre_version_code $SINGLEMDS)
6108         [ "$(facet_fstype ost1)" = "zfs" ] &&
6109                 skip "LU-6442: no such mkfs params for ZFS OSTs" && return
6110         [[ $server_version -ge $(version_code 2.7.56) ]] ||
6111                 { skip "Need server version newer than 2.7.55"; return 0; }
6112
6113         local OST_OPTS="$(mkfs_opts ost1 $(ostdevname 1)) \
6114                 --reformat $(ostdevname 1) $(ostvdevname 1)"
6115
6116         local NEWSIZE=1024
6117         local OLDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
6118                 awk '/Flex block group size: / { print $NF; exit; }')
6119
6120         local opts=OST_OPTS
6121         if [[ ${!opts} != *mkfsoptions* ]]; then
6122                 eval opts=\"${!opts} \
6123                         --mkfsoptions='\\\"-O flex_bg -G $NEWSIZE\\\"'\"
6124         else
6125                 val=${!opts//--mkfsoptions=\\\"/ \
6126                         --mkfsoptions=\\\"-O flex_bg -G $NEWSIZE }
6127                 eval opts='${val}'
6128         fi
6129
6130         echo "params: $opts"
6131
6132         trap cleanup_86 EXIT ERR
6133
6134         stopall
6135         add ost1 $opts || error "add ost1 failed with new params"
6136
6137         local FOUNDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
6138                 awk '/Flex block group size: / { print $NF; exit; }')
6139
6140         [[ $FOUNDSIZE == $NEWSIZE ]] ||
6141                 error "Flex block group size: $FOUNDSIZE, expected: $NEWSIZE"
6142
6143         cleanup_86
6144 }
6145 run_test 86 "Replacing mkfs.lustre -G option"
6146
6147 test_87() { #LU-6544
6148         [[ $(lustre_version_code $SINGLEMDS1) -ge $(version_code 2.9.51) ]] ||
6149                 { skip "Need MDS version at least 2.9.51" && return; }
6150         [[ $(facet_fstype $SINGLEMDS) != ldiskfs ]] &&
6151                 { skip "ldiskfs only test" && return; }
6152         [[ $OSTCOUNT -gt 59 ]] &&
6153                 { skip "Ignore wide striping situation" && return; }
6154
6155         local mdsdev=$(mdsdevname 1)
6156         local mdsvdev=$(mdsvdevname 1)
6157         local file=$DIR/$tfile
6158         local mntpt=$(facet_mntpt $SINGLEMDS)
6159         local used_xattr_blk=0
6160         local inode_size=${1:-1024}
6161         local left_size=0
6162         local xtest="trusted.test"
6163         local value
6164         local orig
6165         local i
6166         local stripe_cnt=$(($OSTCOUNT + 2))
6167
6168         #Please see ldiskfs_make_lustre() for MDT inode size calculation
6169         if [ $stripe_cnt -gt 16 ]; then
6170                 inode_size=2048
6171         fi
6172         left_size=$(expr $inode_size - \
6173                         156 - \
6174                         32 - \
6175                         32 - 40 \* 3 - 32 \* 3 - $stripe_cnt \* 24 - 16 - 3 -  \
6176                         24 - 16 - 3 - \
6177                         24 - 18 - $(expr length $tfile) - 16 - 4)
6178         if [ $left_size -le 0 ]; then
6179                 echo "No space($left_size) is expected in inode."
6180                 echo "Try 1-byte xattr instead to verify this."
6181                 left_size=1
6182         else
6183                 echo "Estimate: at most $left_size-byte space left in inode."
6184         fi
6185
6186         unload_modules
6187         reformat
6188
6189         add mds1 $(mkfs_opts mds1 ${mdsdev}) --stripe-count-hint=$stripe_cnt \
6190                 --reformat $mdsdev $mdsvdev || error "add mds1 failed"
6191         start_mdt 1 > /dev/null || error "start mdt1 failed"
6192         for i in $(seq $OSTCOUNT); do
6193                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS > /dev/null ||
6194                         error "start ost$i failed"
6195         done
6196         mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
6197         check_mount || error "check client $MOUNT failed"
6198
6199         #set xattr
6200         $SETSTRIPE -E 1M -c 1 -E 64M -c 1 -E -1 -c -1 $file ||
6201                 error "Create file with 3 components failed"
6202         $TRUNCATE $file $((1024*1024*64+1)) || error "truncate file failed"
6203         i=$($GETSTRIPE -I3 -c $file) || error "get 3rd stripe count failed"
6204         if [ $i -ne $OSTCOUNT ]; then
6205                 left_size=$(expr $left_size + $(expr $OSTCOUNT - $i) \* 24)
6206                 echo -n "Since only $i out $OSTCOUNT OSTs are used, "
6207                 echo -n "the expected left space is changed to "
6208                 echo "$left_size bytes at most."
6209         fi
6210         value=$(generate_string $left_size)
6211         setfattr -n $xtest -v $value $file
6212         orig=$(get_xattr_value $xtest $file)
6213         [[ "$orig" != "$value" ]] && error "$xtest changed"
6214
6215         #Verify if inode has some expected space left
6216         umount $MOUNT > /dev/null || error "umount $MOUNT failed"
6217         stop_mdt 1 > /dev/null || error "stop mdt1 failed"
6218         mount_ldiskfs $SINGLEMDS || error "mount -t ldiskfs $SINGLEMDS failed"
6219
6220         do_facet $SINGLEMDS ls -sal $mntpt/ROOT/$tfile
6221         used_xattr_blk=$(do_facet $SINGLEMDS ls -s $mntpt/ROOT/$tfile |
6222                         awk '{ print $1 }')
6223         [[ $used_xattr_blk -eq 0 ]] &&
6224                 error "Please check MDS inode size calculation: \
6225                        more than $left_size-byte space left in inode."
6226         echo "Verified: at most $left_size-byte space left in inode."
6227
6228         stopall
6229 }
6230 run_test 87 "check if MDT inode can hold EAs with N stripes properly"
6231
6232 test_88() {
6233         [ "$(facet_fstype mds1)" == "zfs" ] &&
6234                 skip "LU-6662: no implementation for ZFS" && return
6235
6236         load_modules
6237
6238         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
6239                 --reformat $(mdsdevname 1) || error "add mds1 failed"
6240
6241         do_facet mds1 "$TUNEFS $(mdsdevname 1) |
6242                 grep -e \".*opts:.*errors=remount-ro.*\"" ||
6243                 error "default mount options is missing"
6244
6245         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
6246                 --mountfsoptions="user_xattr,errors=panic" \
6247                 --reformat $(mdsdevname 1) || error "add mds1 failed"
6248
6249         do_facet mds1 "$TUNEFS $(mdsdevname 1) |
6250                 grep -e \".*opts:.*errors=panic.*\"" ||
6251                 error "user can't override default mount options"
6252 }
6253 run_test 88 "check the default mount options can be overridden"
6254
6255 test_89() { # LU-7131
6256         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.9.54) ]] ||
6257                 { skip "Need MDT version at least 2.9.54" && return 0; }
6258
6259         local key=failover.node
6260         local val1=192.0.2.254@tcp0 # Reserved IPs, see RFC 5735
6261         local val2=192.0.2.255@tcp0
6262         local mdsdev=$(mdsdevname 1)
6263         local params
6264
6265         stopall
6266
6267         [ $(facet_fstype mds1) == zfs ] && import_zpool mds1
6268         # Check that parameters are added correctly
6269         echo "tunefs --param $key=$val1"
6270         do_facet mds "$TUNEFS --param $key=$val1 $mdsdev >/dev/null" ||
6271                 error "tunefs --param $key=$val1 failed"
6272         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6273                 error "tunefs --dryrun failed"
6274         params=${params##*Parameters:}
6275         params=${params%%exiting*}
6276         [ $(echo $params | tr ' ' '\n' | grep -c $key=$val1) = "1" ] ||
6277                 error "on-disk parameter not added correctly via tunefs"
6278
6279         # Check that parameters replace existing instances when added
6280         echo "tunefs --param $key=$val2"
6281         do_facet mds "$TUNEFS --param $key=$val2 $mdsdev >/dev/null" ||
6282                 error "tunefs --param $key=$val2 failed"
6283         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6284                 error "tunefs --dryrun failed"
6285         params=${params##*Parameters:}
6286         params=${params%%exiting*}
6287         [ $(echo $params | tr ' ' '\n' | grep -c $key=) = "1" ] ||
6288                 error "on-disk parameter not replaced via tunefs"
6289         [ $(echo $params | tr ' ' '\n' | grep -c $key=$val2) = "1" ] ||
6290                 error "on-disk parameter not replaced correctly via tunefs"
6291
6292         # Check that a parameter is erased properly
6293         echo "tunefs --erase-param $key"
6294         do_facet mds "$TUNEFS --erase-param $key $mdsdev >/dev/null" ||
6295                 error "tunefs --erase-param $key failed"
6296         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6297                 error "tunefs --dryrun failed"
6298         params=${params##*Parameters:}
6299         params=${params%%exiting*}
6300         [ $(echo $params | tr ' ' '\n' | grep -c $key=) = "0" ] ||
6301                 error "on-disk parameter not erased correctly via tunefs"
6302
6303         # Check that all the parameters are erased
6304         echo "tunefs --erase-params"
6305         do_facet mds "$TUNEFS --erase-params $mdsdev >/dev/null" ||
6306                 error "tunefs --erase-params failed"
6307         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6308                 error "tunefs --dryrun failed"
6309         params=${params##*Parameters:}
6310         params=${params%%exiting*}
6311         [ -z $params ] ||
6312                 error "all on-disk parameters not erased correctly via tunefs"
6313
6314         # Check the order of options --erase-params and --param
6315         echo "tunefs --param $key=$val1 --erase-params"
6316         do_facet mds \
6317                 "$TUNEFS --param $key=$val1 --erase-params $mdsdev >/dev/null"||
6318                 error "tunefs --param $key=$val1 --erase-params failed"
6319         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6320                 error "tunefs --dryrun failed"
6321         params=${params##*Parameters:}
6322         params=${params%%exiting*}
6323         [ $(echo $params | tr ' ' '\n') == "$key=$val1" ] ||
6324                 error "on-disk param not added correctly with --erase-params"
6325
6326         reformat
6327 }
6328 run_test 89 "check tunefs --param and --erase-param{s} options"
6329
6330 # $1 test directory
6331 # $2 (optional) value of max_mod_rpcs_in_flight to set
6332 check_max_mod_rpcs_in_flight() {
6333         local dir="$1"
6334         local mmr="$2"
6335         local idx
6336         local facet
6337         local tmp
6338         local i
6339
6340         idx=$(printf "%04x" $($LFS getdirstripe -i $dir))
6341         facet="mds$((0x$idx + 1))"
6342
6343         if [ -z "$mmr" ]; then
6344                 # get value of max_mod_rcps_in_flight
6345                 mmr=$($LCTL get_param -n \
6346                         mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight) ||
6347                         error "Unable to get max_mod_rpcs_in_flight"
6348                 echo "max_mod_rcps_in_flight is $mmr"
6349         else
6350                 # set value of max_mod_rpcs_in_flight
6351                 $LCTL set_param \
6352                     mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight=$mmr ||
6353                         error "Unable to set max_mod_rpcs_in_flight to $mmr"
6354                 echo "max_mod_rpcs_in_flight set to $mmr"
6355         fi
6356
6357         # create mmr+1 files
6358         echo "creating $((mmr + 1)) files ..."
6359         umask 0022
6360         for i in $(seq $((mmr + 1))); do
6361                 touch $dir/file-$i
6362         done
6363
6364         ### part 1 ###
6365
6366         # consumes mmr-1 modify RPC slots
6367         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
6368         # drop requests on MDT so that RPC slots are consumed
6369         # during all the request resend interval
6370         do_facet $facet "$LCTL set_param fail_loc=0x159"
6371         echo "launch $((mmr - 1)) chmod in parallel ..."
6372         for i in $(seq $((mmr - 1))); do
6373                 chmod 0600 $dir/file-$i &
6374         done
6375         sleep 1
6376
6377         # send one additional modify RPC
6378         do_facet $facet "$LCTL set_param fail_loc=0"
6379         echo "launch 1 additional chmod in parallel ..."
6380         chmod 0600 $dir/file-$mmr &
6381         sleep 1
6382
6383         # check this additional modify RPC get a modify RPC slot
6384         # and succeed its operation
6385         checkstat -vp 0600 $dir/file-$mmr ||
6386                 error "Unable to send $mmr modify RPCs in parallel"
6387         wait
6388
6389         ### part 2 ###
6390
6391         # consumes mmr modify RPC slots
6392         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
6393         # drop requests on MDT so that RPC slots are consumed
6394         # during all the request resend interval
6395         do_facet $facet "$LCTL set_param fail_loc=0x159"
6396         echo "launch $mmr chmod in parallel ..."
6397         for i in $(seq $mmr); do
6398                 chmod 0666 $dir/file-$i &
6399         done
6400         sleep 1
6401
6402         # send one additional modify RPC
6403         do_facet $facet "$LCTL set_param fail_loc=0"
6404         echo "launch 1 additional chmod in parallel ..."
6405         chmod 0666 $dir/file-$((mmr + 1)) &
6406         sleep 1
6407
6408         # check this additional modify RPC blocked getting a modify RPC slot
6409         checkstat -vp 0644 $dir/file-$((mmr + 1)) ||
6410                 error "Unexpectedly send $(($mmr + 1)) modify RPCs in parallel"
6411         wait
6412 }
6413
6414 test_90a() {
6415         reformat
6416         if ! combined_mgs_mds ; then
6417                 start_mgs
6418         fi
6419         setup
6420
6421         [[ $($LCTL get_param mdc.*.import |
6422              grep "connect_flags:.*multi_mod_rpc") ]] ||
6423                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
6424
6425         # check default value
6426         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6427         check_max_mod_rpcs_in_flight $DIR/$tdir
6428
6429         cleanup
6430 }
6431 run_test 90a "check max_mod_rpcs_in_flight is enforced"
6432
6433 test_90b() {
6434         local idx
6435         local facet
6436         local tmp
6437         local mmrpc
6438
6439         setup
6440
6441         [[ $($LCTL get_param mdc.*.import |
6442              grep "connect_flags:.*multi_mod_rpc") ]] ||
6443                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
6444
6445         ### test 1.
6446         # update max_mod_rpcs_in_flight
6447         $LFS mkdir -c1 $DIR/${tdir}1 || error "mkdir $DIR/${tdir}1 failed"
6448         check_max_mod_rpcs_in_flight $DIR/${tdir}1 1
6449
6450         ### test 2.
6451         # check client is able to send multiple modify RPCs in paralell
6452         tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
6453                 grep -c "multi_mod_rpcs")
6454         if [ "$tmp" -ne $MDSCOUNT ]; then
6455                 echo "Client not able to send multiple modify RPCs in parallel"
6456                 cleanup
6457                 return
6458         fi
6459
6460         # update max_mod_rpcs_in_flight
6461         $LFS mkdir -c1 $DIR/${tdir}2 || error "mkdir $DIR/${tdir}2 failed"
6462         check_max_mod_rpcs_in_flight $DIR/${tdir}2 5
6463
6464         ### test 3.
6465         $LFS mkdir -c1 $DIR/${tdir}3 || error "mkdir $DIR/${tdir}3 failed"
6466         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/${tdir}3))
6467         facet="mds$((0x$idx + 1))"
6468
6469         # save MDT max_mod_rpcs_per_client
6470         mmrpc=$(do_facet $facet \
6471                     cat /sys/module/mdt/parameters/max_mod_rpcs_per_client)
6472
6473         # update max_mod_rpcs_in_flight
6474         umount_client $MOUNT
6475         do_facet $facet \
6476                 "echo 16 > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6477         mount_client $MOUNT
6478         $LCTL set_param mdc.$FSNAME-MDT$idx-mdc-*.max_rpcs_in_flight=17
6479         check_max_mod_rpcs_in_flight $DIR/${tdir}3 16
6480
6481         # restore MDT max_mod_rpcs_per_client initial value
6482         do_facet $facet \
6483                 "echo $mmrpc > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6484
6485         rm -rf $DIR/${tdir}?
6486         cleanup
6487 }
6488 run_test 90b "check max_mod_rpcs_in_flight is enforced after update"
6489
6490 test_90c() {
6491         local tmp
6492         local mrif
6493         local mmrpc
6494
6495         setup
6496
6497         [[ $($LCTL get_param mdc.*.import |
6498              grep "connect_flags:.*multi_mod_rpc") ]] ||
6499                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
6500
6501         # check client is able to send multiple modify RPCs in paralell
6502         tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
6503                 grep -c "multi_mod_rpcs")
6504         if [ "$tmp" -ne $MDSCOUNT ]; then
6505                 skip "Client not able to send multiple modify RPCs in parallel"
6506                 cleanup
6507                 return
6508         fi
6509
6510         # get max_rpcs_in_flight value
6511         mrif=$($LCTL get_param -n mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight)
6512         echo "max_rpcs_in_flight is $mrif"
6513
6514         # get MDT max_mod_rpcs_per_client
6515         mmrpc=$(do_facet mds1 \
6516                     cat /sys/module/mdt/parameters/max_mod_rpcs_per_client)
6517         echo "max_mod_rpcs_per_client is $mmrpc"
6518
6519         # testcase 1
6520         # attempt to set max_mod_rpcs_in_flight to max_rpcs_in_flight value
6521         # prerequisite: set max_mod_rpcs_per_client to max_rpcs_in_flight value
6522         umount_client $MOUNT
6523         do_facet mds1 \
6524                 "echo $mrif > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6525         mount_client $MOUNT
6526
6527         $LCTL set_param \
6528             mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$mrif &&
6529             error "set max_mod_rpcs_in_flight to $mrif should fail"
6530
6531         umount_client $MOUNT
6532         do_facet mds1 \
6533                 "echo $mmrpc > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6534         mount_client $MOUNT
6535
6536         # testcase 2
6537         # attempt to set max_mod_rpcs_in_flight to max_mod_rpcs_per_client+1
6538         # prerequisite: set max_rpcs_in_flight to max_mod_rpcs_per_client+2
6539         $LCTL set_param \
6540             mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight=$((mmrpc + 2))
6541
6542         $LCTL set_param \
6543             mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$((mmrpc + 1)) &&
6544             error "set max_mod_rpcs_in_flight to $((mmrpc + 1)) should fail"
6545
6546         cleanup
6547 }
6548 run_test 90c "check max_mod_rpcs_in_flight update limits"
6549
6550 test_90d() {
6551         local idx
6552         local facet
6553         local mmr
6554         local i
6555         local pid
6556
6557         setup
6558
6559         [[ $($LCTL get_param mdc.*.import |
6560              grep "connect_flags:.*multi_mod_rpc") ]] ||
6561                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
6562
6563         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6564         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
6565         facet="mds$((0x$idx + 1))"
6566
6567         # check client version supports multislots
6568         tmp=$($LCTL get_param -N \
6569                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
6570         if [ -z "$tmp" ]; then
6571                 skip "Client does not support multiple modify RPCs in flight"
6572                 cleanup
6573                 return
6574         fi
6575
6576         # get current value of max_mod_rcps_in_flight
6577         mmr=$($LCTL get_param -n \
6578                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
6579         echo "max_mod_rcps_in_flight is $mmr"
6580
6581         # create mmr files
6582         echo "creating $mmr files ..."
6583         umask 0022
6584         for i in $(seq $mmr); do
6585                 touch $DIR/$tdir/file-$i
6586         done
6587
6588         # prepare for close RPC
6589         multiop_bg_pause $DIR/$tdir/file-close O_c
6590         pid=$!
6591
6592         # consumes mmr modify RPC slots
6593         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
6594         # drop requests on MDT so that RPC slots are consumed
6595         # during all the request resend interval
6596         do_facet $facet "$LCTL set_param fail_loc=0x159"
6597         echo "launch $mmr chmod in parallel ..."
6598         for i in $(seq $mmr); do
6599                 chmod 0600 $DIR/$tdir/file-$i &
6600         done
6601
6602         # send one additional close RPC
6603         do_facet $facet "$LCTL set_param fail_loc=0"
6604         echo "launch 1 additional close in parallel ..."
6605         kill -USR1 $pid
6606         cancel_lru_locks mdc
6607         sleep 1
6608
6609         # check this additional close RPC get a modify RPC slot
6610         # and multiop process completed
6611         [ -d /proc/$pid ] &&
6612                 error "Unable to send the additional close RPC in parallel"
6613         wait
6614         rm -rf $DIR/$tdir
6615         cleanup
6616 }
6617 run_test 90d "check one close RPC is allowed above max_mod_rpcs_in_flight"
6618
6619 check_uuid_on_ost() {
6620         local nid=$1
6621         do_facet ost1 "$LCTL get_param obdfilter.${FSNAME}*.exports.'$nid'.uuid"
6622 }
6623
6624 check_uuid_on_mdt() {
6625         local nid=$1
6626         do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.'$nid'.uuid"
6627 }
6628
6629 test_91() {
6630         local uuid
6631         local nid
6632         local found
6633
6634         [[ $(lustre_version_code ost1) -ge $(version_code 2.7.63) ]] ||
6635                 { skip "Need OST version at least 2.7.63" && return 0; }
6636         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.63) ]] ||
6637                 { skip "Need MDT version at least 2.7.63" && return 0; }
6638
6639         start_mds || error "MDS start failed"
6640         start_ost || error "unable to start OST"
6641         mount_client $MOUNT || error "client start failed"
6642         check_mount || error "check_mount failed"
6643
6644         if remote_mds; then
6645                 nid=$($LCTL list_nids | head -1 | sed  "s/\./\\\./g")
6646         else
6647                 nid="0@lo"
6648         fi
6649         uuid=$(get_client_uuid $MOUNT)
6650
6651         echo "list nids on mdt:"
6652         do_facet $SINGLEMDS "$LCTL list_param mdt.${FSNAME}*.exports.*"
6653         echo "uuid from $nid:"
6654         do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.'$nid'.uuid"
6655
6656         found=$(check_uuid_on_mdt $nid | grep $uuid)
6657         [ -z "$found" ] && error "can't find $uuid $nid on MDT"
6658         found=$(check_uuid_on_ost $nid | grep $uuid)
6659         [ -z "$found" ] && error "can't find $uuid $nid on OST"
6660
6661         # umount the client so it won't reconnect
6662         manual_umount_client --force || error "failed to umount $?"
6663         # shouldn't disappear on MDS after forced umount
6664         found=$(check_uuid_on_mdt $nid | grep $uuid)
6665         [ -z "$found" ] && error "can't find $uuid $nid"
6666
6667         echo "evict $nid"
6668         do_facet $SINGLEMDS \
6669                 "$LCTL set_param -n mdt.${mds1_svc}.evict_client nid:$nid"
6670
6671         found=$(check_uuid_on_mdt $nid | grep $uuid)
6672         [ -n "$found" ] && error "found $uuid $nid on MDT"
6673         found=$(check_uuid_on_ost $nid | grep $uuid)
6674         [ -n "$found" ] && error "found $uuid $nid on OST"
6675
6676         # check it didn't reconnect (being umounted)
6677         sleep $((TIMEOUT+1))
6678         found=$(check_uuid_on_mdt $nid | grep $uuid)
6679         [ -n "$found" ] && error "found $uuid $nid on MDT"
6680         found=$(check_uuid_on_ost $nid | grep $uuid)
6681         [ -n "$found" ] && error "found $uuid $nid on OST"
6682
6683         cleanup
6684 }
6685 run_test 91 "evict-by-nid support"
6686
6687 generate_ldev_conf() {
6688         # generate an ldev.conf file
6689         local ldevconfpath=$1
6690         local fstype=
6691         local fsldevformat=""
6692         touch $ldevconfpath
6693
6694         fstype=$(facet_fstype mgs)
6695         if [ "$fstype" == "zfs" ]; then
6696                 fsldevformat="$fstype:"
6697         else
6698                 fsldevformat=""
6699         fi
6700
6701         printf "%s\t-\t%s-MGS0000\t%s%s\n" \
6702                 $mgs_HOST \
6703                 $FSNAME \
6704                 $fsldevformat \
6705                 $(mgsdevname) > $ldevconfpath
6706
6707         local mdsfo_host=$mdsfailover_HOST;
6708         if [ -z "$mdsfo_host" ]; then
6709                 mdsfo_host="-"
6710         fi
6711
6712         for num in $(seq $MDSCOUNT); do
6713                 fstype=$(facet_fstype mds$num)
6714                 if [ "$fstype" == "zfs" ]; then
6715                         fsldevformat="$fstype:"
6716                 else
6717                         fsldevformat=""
6718                 fi
6719
6720                 printf "%s\t%s\t%s-MDT%04d\t%s%s\n" \
6721                         $mds_HOST \
6722                         $mdsfo_host \
6723                         $FSNAME \
6724                         $num \
6725                         $fsldevformat \
6726                         $(mdsdevname $num) >> $ldevconfpath
6727         done
6728
6729         local ostfo_host=$ostfailover_HOST;
6730         if [ -z "$ostfo_host" ]; then
6731                 ostfo_host="-"
6732         fi
6733
6734         for num in $(seq $OSTCOUNT); do
6735                 fstype=$(facet_fstype ost$num)
6736                 if [ "$fstype" == "zfs" ]; then
6737                         fsldevformat="$fstype:"
6738                 else
6739                         fsldevformat=""
6740                 fi
6741
6742                 printf "%s\t%s\t%s-OST%04d\t%s%s\n" \
6743                         $ost_HOST \
6744                         $ostfo_host \
6745                         $FSNAME \
6746                         $num \
6747                         $fsldevformat \
6748                         $(ostdevname $num) >> $ldevconfpath
6749         done
6750
6751         echo "----- $ldevconfpath -----"
6752         cat $ldevconfpath
6753         echo "--- END $ldevconfpath ---"
6754
6755 }
6756
6757 generate_nids() {
6758         # generate a nids file (mapping between hostname to nid)
6759         # looks like we only have the MGS nid available to us
6760         # so just echo that to a file
6761         local nidspath=$1
6762         echo -e "${mgs_HOST}\t${MGSNID}" > $nidspath
6763
6764         echo "----- $nidspath -----"
6765         cat $nidspath
6766         echo "--- END $nidspath ---"
6767 }
6768
6769 compare_ldev_output() {
6770         ldev_output=$1
6771         expected_output=$2
6772
6773         sort $expected_output -o $expected_output
6774         sort $ldev_output -o $ldev_output
6775
6776         echo "-- START OF LDEV OUTPUT --"
6777         cat $ldev_output
6778         echo "--- END OF LDEV OUTPUT ---"
6779
6780         echo "-- START OF EXPECTED OUTPUT --"
6781         cat $expected_output
6782         echo "--- END OF EXPECTED OUTPUT ---"
6783
6784         diff $expected_output $ldev_output
6785         return $?
6786 }
6787
6788 test_92() {
6789         if [ -z "$LDEV" ]; then
6790                 error "ldev is missing!"
6791         fi
6792
6793         local LDEVCONFPATH=$TMP/ldev.conf
6794         local NIDSPATH=$TMP/nids
6795
6796         echo "Host is $(hostname)"
6797
6798         generate_ldev_conf $LDEVCONFPATH
6799         generate_nids $NIDSPATH
6800
6801         # echo the mgs nid and compare it to environment variable MGSNID
6802         # also, ldev.conf and nids is a server side thing, use the OSS
6803         # hostname
6804         local output
6805         output=$($LDEV -c $LDEVCONFPATH -H $ost_HOST -n $NIDSPATH echo %m)
6806
6807         echo "-- START OF LDEV OUTPUT --"
6808         echo -e "$output"
6809         echo "--- END OF LDEV OUTPUT ---"
6810
6811         # ldev failed, error
6812         if [ $? -ne 0 ]; then
6813                 rm $LDEVCONFPATH $NIDSPATH
6814                 error "ldev failed to execute!"
6815         fi
6816
6817         # need to process multiple lines because of combined MGS and MDS
6818         echo -e $output | awk '{ print $2 }' | while read -r line ; do
6819                 if [ "$line" != "$MGSNID" ]; then
6820                         rm $LDEVCONFPATH $NIDSPATH
6821                         error "ldev failed mgs nid '$line', expected '$MGSNID'"
6822                 fi
6823         done
6824
6825         rm $LDEVCONFPATH $NIDSPATH
6826 }
6827 run_test 92 "ldev returns MGS NID correctly in command substitution"
6828
6829 test_93() {
6830         [ $MDSCOUNT -lt 3 ] && skip "needs >= 3 MDTs" && return
6831
6832         reformat
6833         #start mgs or mgs/mdt0
6834         if ! combined_mgs_mds ; then
6835                 start_mgs
6836                 start_mdt 1
6837         else
6838                 start_mdt 1
6839         fi
6840
6841         start_ost || error "OST0 start fail"
6842
6843         #define OBD_FAIL_MGS_WRITE_TARGET_DELAY  0x90e
6844         do_facet mgs "$LCTL set_param fail_val = 10 fail_loc=0x8000090e"
6845         for num in $(seq 2 $MDSCOUNT); do
6846                 start_mdt $num &
6847         done
6848
6849         mount_client $MOUNT || error "mount client fails"
6850         wait_osc_import_state mds ost FULL
6851         wait_osc_import_state client ost FULL
6852         check_mount || error "check_mount failed"
6853
6854         cleanup || error "cleanup failed with $?"
6855 }
6856 run_test 93 "register mulitple MDT at the same time"
6857
6858 test_94() {
6859         if [ -z "$LDEV" ]; then
6860                 error "ldev is missing!"
6861         fi
6862
6863         local LDEVCONFPATH=$TMP/ldev.conf
6864         local NIDSPATH=$TMP/nids
6865
6866         generate_ldev_conf $LDEVCONFPATH
6867         generate_nids $NIDSPATH
6868
6869         local LDEV_OUTPUT=$TMP/ldev-output.txt
6870         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME > $LDEV_OUTPUT
6871
6872         # ldev failed, error
6873         if [ $? -ne 0 ]; then
6874                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
6875                 error "ldev failed to execute!"
6876         fi
6877
6878         # expected output
6879         local EXPECTED_OUTPUT=$TMP/ldev-expected.txt
6880
6881         printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT
6882
6883         for num in $(seq $MDSCOUNT); do
6884                 printf "%s-MDT%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
6885         done
6886
6887         for num in $(seq $OSTCOUNT); do
6888                 printf "%s-OST%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
6889         done
6890
6891         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
6892
6893         if [ $? -ne 0 ]; then
6894                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
6895                 error "ldev failed to produce the correct hostlist!"
6896         fi
6897
6898         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
6899 }
6900 run_test 94 "ldev outputs correct labels for file system name query"
6901
6902 test_95() {
6903         if [ -z "$LDEV" ]; then
6904                 error "ldev is missing!"
6905         fi
6906
6907         local LDEVCONFPATH=$TMP/ldev.conf
6908         local NIDSPATH=$TMP/nids
6909
6910         generate_ldev_conf $LDEVCONFPATH
6911         generate_nids $NIDSPATH
6912
6913         # SUCCESS CASES
6914         # file sys filter
6915         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME &>/dev/null
6916         if [ $? -ne 0 ]; then
6917                 rm $LDEVCONFPATH $NIDSPATH
6918                 error "ldev label filtering w/ -F failed!"
6919         fi
6920
6921         # local filter
6922         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -l  &>/dev/null
6923         if [ $? -ne 0 ]; then
6924                 rm $LDEVCONFPATH $NIDSPATH
6925                 error "ldev label filtering w/ -l failed!"
6926         fi
6927
6928         # foreign filter
6929         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f &>/dev/null
6930         if [ $? -ne 0 ]; then
6931                 rm $LDEVCONFPATH $NIDSPATH
6932                 error "ldev label filtering w/ -f failed!"
6933         fi
6934
6935         # all filter
6936         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a &>/dev/null
6937         if [ $? -ne 0 ]; then
6938                 rm $LDEVCONFPATH $NIDSPATH
6939                 error "ldev label filtering w/ -a failed!"
6940         fi
6941
6942         # FAILURE CASES
6943         # all & file sys
6944         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -F $FSNAME &>/dev/null
6945         if [ $? -eq 0 ]; then
6946                 rm $LDEVCONFPATH $NIDSPATH
6947                 error "ldev label filtering w/ -a and -F incorrectly succeeded"
6948         fi
6949
6950         # all & foreign
6951         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -f &>/dev/null
6952         if [ $? -eq 0 ]; then
6953                 rm $LDEVCONFPATH $NIDSPATH
6954                 error "ldev label filtering w/ -a and -f incorrectly succeeded"
6955         fi
6956
6957         # all & local
6958         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -l &>/dev/null
6959         if [ $? -eq 0 ]; then
6960                 rm $LDEVCONFPATH $NIDSPATH
6961                 error "ldev label filtering w/ -a and -l incorrectly succeeded"
6962         fi
6963
6964         # foreign & local
6965         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f -l &>/dev/null
6966         if [ $? -eq 0 ]; then
6967                 rm $LDEVCONFPATH $NIDSPATH
6968                 error "ldev label filtering w/ -f and -l incorrectly succeeded"
6969         fi
6970
6971         # file sys & local
6972         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -l &>/dev/null
6973         if [ $? -eq 0 ]; then
6974                 rm $LDEVCONFPATH $NIDSPATH
6975                 error "ldev label filtering w/ -F and -l incorrectly succeeded"
6976         fi
6977
6978         # file sys & foreign
6979         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -f &>/dev/null
6980         if [ $? -eq 0 ]; then
6981                 rm $LDEVCONFPATH $NIDSPATH
6982                 error "ldev label filtering w/ -F and -f incorrectly succeeded"
6983         fi
6984
6985         rm $LDEVCONFPATH $NIDSPATH
6986 }
6987 run_test 95 "ldev should only allow one label filter"
6988
6989 test_96() {
6990         if [ -z "$LDEV" ]; then
6991                 error "ldev is missing!"
6992         fi
6993
6994         local LDEVCONFPATH=$TMP/ldev.conf
6995         local NIDSPATH=$TMP/nids
6996
6997         generate_ldev_conf $LDEVCONFPATH
6998         generate_nids $NIDSPATH
6999
7000         local LDEV_OUTPUT=$TMP/ldev-output.txt
7001         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -H $mgs_HOST \
7002                 echo %H-%b | \
7003                 awk '{print $2}' > $LDEV_OUTPUT
7004
7005         # ldev failed, error
7006         if [ $? -ne 0 ]; then
7007                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
7008                 error "ldev failed to execute!"
7009         fi
7010
7011         # expected output
7012         local EXPECTED_OUTPUT=$TMP/ldev-expected-output.txt
7013
7014         echo "$mgs_HOST-$(facet_fstype mgs)" > $EXPECTED_OUTPUT
7015
7016         if [ "$mgs_HOST" == "$mds_HOST" ]; then
7017                 for num in $(seq $MDSCOUNT); do
7018                         echo "$mds_HOST-$(facet_fstype mds$num)" \
7019                         >> $EXPECTED_OUTPUT
7020                 done
7021         fi
7022
7023         if [ "$mgs_HOST" == "$ost_HOST" ]; then
7024                 for num in $(seq $OSTCOUNT); do
7025                         echo "$ost_HOST-$(facet_fstype ost$num)" \
7026                         >> $EXPECTED_OUTPUT
7027                 done
7028         fi
7029
7030         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7031
7032         if [ $? -ne 0 ]; then
7033                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7034                 error "ldev failed to produce the correct output!"
7035         fi
7036
7037         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7038 }
7039 run_test 96 "ldev returns hostname and backend fs correctly in command sub"
7040
7041 test_97() {
7042         if [ -z "$LDEV" ]; then
7043                 error "ldev is missing!"
7044         fi
7045
7046         local LDEVCONFPATH=$TMP/ldev.conf
7047         local NIDSPATH=$TMP/nids
7048
7049         generate_ldev_conf $LDEVCONFPATH
7050         generate_nids $NIDSPATH
7051
7052         local LDEV_OUTPUT=$TMP/ldev-output.txt
7053         local EXPECTED_OUTPUT=$TMP/ldev-expected-output.txt
7054
7055         echo -e "\nMDT role"
7056         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R mdt > $LDEV_OUTPUT
7057
7058         if [ $? -ne 0 ]; then
7059                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
7060                 error "ldev failed to execute for mdt role!"
7061         fi
7062
7063         for num in $(seq $MDSCOUNT); do
7064                 printf "%s-MDT%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
7065         done
7066
7067         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7068
7069         if [ $? -ne 0 ]; then
7070                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7071                 error "ldev failed to produce the correct output for mdt role!"
7072         fi
7073
7074         echo -e "\nOST role"
7075         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R ost > $LDEV_OUTPUT
7076
7077         if [ $? -ne 0 ]; then
7078                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT $EXPECTED_OUTPUT
7079                 error "ldev failed to execute for ost role!"
7080         fi
7081
7082         rm $EXPECTED_OUTPUT
7083         for num in $(seq $OSTCOUNT); do
7084                 printf "%s-OST%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
7085         done
7086
7087         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7088
7089         if [ $? -ne 0 ]; then
7090                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7091                 error "ldev failed to produce the correct output for ost role!"
7092         fi
7093
7094         echo -e "\nMGS role"
7095         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R mgs > $LDEV_OUTPUT
7096
7097         if [ $? -ne 0 ]; then
7098                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT $EXPECTED_OUTPUT
7099                 error "ldev failed to execute for mgs role!"
7100         fi
7101
7102         printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT
7103
7104         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7105
7106         if [ $? -ne 0 ]; then
7107                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7108                 error "ldev failed to produce the correct output for mgs role!"
7109         fi
7110
7111         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7112 }
7113 run_test 97 "ldev returns correct ouput when querying based on role"
7114
7115 test_98()
7116 {
7117         local mountopt
7118         local temp=$MDS_MOUNT_OPTS
7119
7120         setup
7121         check_mount || error "mount failed"
7122         mountopt="user_xattr"
7123         for ((x = 1; x <= 400; x++)); do
7124                 mountopt="$mountopt,user_xattr"
7125         done
7126         remount_client $mountopt $MOUNT  2>&1 | grep "too long" ||
7127                 error "Buffer overflow check failed"
7128         cleanup || error "cleanup failed"
7129 }
7130 run_test 98 "Buffer-overflow check while parsing mount_opts"
7131
7132 test_99()
7133 {
7134         [[ $(facet_fstype ost1) != ldiskfs ]] &&
7135                 { skip "ldiskfs only test" && return; }
7136         [[ $(lustre_version_code ost1) -ge $(version_code 2.8.57) ]] ||
7137                 { skip "Need OST version at least 2.8.57" && return 0; }
7138
7139         local ost_opts="$(mkfs_opts ost1 $(ostdevname 1)) \
7140                 --reformat $(ostdevname 1) $(ostvdevname 1)"
7141         do_facet ost1 $DEBUGFS -c -R stats `ostdevname 1` | grep "meta_bg" &&
7142                 skip "meta_bg already set" && return
7143
7144         local opts=ost_opts
7145         if [[ ${!opts} != *mkfsoptions* ]]; then
7146                 eval opts=\"${!opts} \
7147                 --mkfsoptions='\\\"-O ^resize_inode,meta_bg\\\"'\"
7148         else
7149                 local val=${!opts//--mkfsoptions=\\\"/ \
7150                 --mkfsoptions=\\\"-O ^resize_inode,meta_bg }
7151                 eval opts='${val}'
7152         fi
7153
7154         echo "params: $opts"
7155
7156         add ost1 $opts || error "add ost1 failed with new params"
7157
7158         do_facet ost1 $DEBUGFS -c -R stats `ostdevname 1` | grep "meta_bg" ||
7159                 error "meta_bg is not set"
7160
7161         return 0
7162 }
7163 run_test 99 "Adding meta_bg option"
7164
7165 test_100() {
7166         reformat
7167         start_mds || error "MDS start failed"
7168         start_ost || error "unable to start OST"
7169         mount_client $MOUNT || error "client start failed"
7170         check_mount || error "check_mount failed"
7171
7172         # Desired output
7173         # MGS:
7174         #     0@lo
7175         # lustre-MDT0000:
7176         #     0@lo
7177         # lustre-OST0000:
7178         #     0@lo
7179         do_facet mgs 'lshowmount -v' | awk 'BEGIN {NR == 0; rc=1} /MGS:/ {rc=0}
7180                 END {exit rc}' || error "lshowmount have no output MGS"
7181
7182         do_facet mds1 'lshowmount -v' | awk 'BEGIN {NR == 2; rc=1} /-MDT0000:/
7183                 {rc=0} END {exit rc}' || error "lshowmount have no output MDT0"
7184
7185         do_facet ost1 'lshowmount -v' | awk 'BEGIN {NR == 4; rc=1} /-OST0000:/
7186                 {rc=0} END {exit rc}' || error "lshowmount have no output OST0"
7187
7188         cleanup || error "cleanup failed with $?"
7189 }
7190 run_test 100 "check lshowmount lists MGS, MDT, OST and 0@lo"
7191
7192 test_101() {
7193         local createmany_oid
7194         local dev=$FSNAME-OST0000-osc-MDT0000
7195         setup
7196
7197         createmany -o $DIR1/$tfile-%d 50000 &
7198         createmany_oid=$!
7199         # MDT->OST reconnection causes MDT<->OST last_id synchornisation
7200         # via osp_precreate_cleanup_orphans.
7201         for ((i = 0; i < 100; i++)); do
7202                 for ((k = 0; k < 10; k++)); do
7203                         do_facet $SINGLEMDS "$LCTL --device $dev deactivate;" \
7204                                             "$LCTL --device $dev activate"
7205                 done
7206
7207                 ls -asl $MOUNT | grep '???' &&
7208                         (kill -9 $createmany_oid &>/dev/null; \
7209                          error "File hasn't object on OST")
7210
7211                 kill -s 0 $createmany_oid || break
7212         done
7213         wait $createmany_oid
7214         cleanup
7215 }
7216 run_test 101 "Race MDT->OST reconnection with create"
7217
7218 test_102() {
7219         cleanup || error "cleanup failed with $?"
7220
7221         local mds1dev=$(mdsdevname 1)
7222         local mds1mnt=$(facet_mntpt mds1)
7223         local mds1fstype=$(facet_fstype mds1)
7224         local mds1opts=$MDS_MOUNT_OPTS
7225
7226         if [ $mds1fstype == ldiskfs ] &&
7227            ! do_facet mds1 test -b $mds1dev; then
7228                 mds1opts=$(csa_add "$mds1opts" -o loop)
7229         fi
7230         if [[ $mds1fstype == zfs ]]; then
7231                 import_zpool mds1 || return ${PIPESTATUS[0]}
7232         fi
7233
7234         # unload all and only load libcfs to allow fail_loc setting
7235         do_facet mds1 lustre_rmmod || error "unable to unload modules"
7236         do_facet mds1 modprobe libcfs || error "libcfs not loaded"
7237         do_facet mds1 lsmod \| grep libcfs || error "libcfs not loaded"
7238
7239         #define OBD_FAIL_OBDCLASS_MODULE_LOAD    0x60a
7240         do_facet mds1 "$LCTL set_param fail_loc=0x8000060a"
7241
7242         do_facet mds1 $MOUNT_CMD $mds1dev $mds1mnt $mds1opts &&
7243                 error "mdt start must fail"
7244         do_facet mds1 lsmod \| grep  obdclass && error "obdclass must not load"
7245
7246         do_facet mds1 "$LCTL set_param fail_loc=0x0"
7247
7248         do_facet mds1 $MOUNT_CMD $mds1dev $mds1mnt $mds1opts ||
7249                 error "mdt start must not fail"
7250
7251         cleanup || error "cleanup failed with $?"
7252 }
7253 run_test 102 "obdclass module cleanup upon error"
7254
7255 test_renamefs() {
7256         local newname=$1
7257
7258         echo "rename $FSNAME to $newname"
7259
7260         if [ ! combined_mgs_mds ]; then
7261                 local facet=$(mgsdevname)
7262
7263                 do_facet mgs \
7264                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $facet"||
7265                         error "(7) Fail to rename MGS"
7266                 if [ "$(facet_fstype $facet)" = "zfs" ]; then
7267                         reimport_zpool mgs $newname-mgs
7268                 fi
7269         fi
7270
7271         for num in $(seq $MDSCOUNT); do
7272                 local facet=$(mdsdevname $num)
7273
7274                 do_facet mds${num} \
7275                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $facet"||
7276                         error "(8) Fail to rename MDT $num"
7277                 if [ "$(facet_fstype $facet)" = "zfs" ]; then
7278                         reimport_zpool mds${num} $newname-mdt${num}
7279                 fi
7280         done
7281
7282         for num in $(seq $OSTCOUNT); do
7283                 local facet=$(ostdevname $num)
7284
7285                 do_facet ost${num} \
7286                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $facet"||
7287                         error "(9) Fail to rename OST $num"
7288                 if [ "$(facet_fstype $facet)" = "zfs" ]; then
7289                         reimport_zpool ost${num} $newname-ost${num}
7290                 fi
7291         done
7292 }
7293
7294 test_103_set_pool() {
7295         local pname=$1
7296         local ost_x=$2
7297
7298         do_facet mgs $LCTL pool_add $FSNAME.$pname ${FSNAME}-$ost_x ||
7299                 error "Fail to add $ost_x to $FSNAME.$pname"
7300         wait_update $HOSTNAME \
7301                 "lctl get_param -n lov.$FSNAME-clilov-*.pools.$pname |
7302                  grep $ost_x" "$FSNAME-${ost_x}_UUID" ||
7303                 error "$ost_x is NOT in pool $FSNAME.$pname"
7304 }
7305
7306 test_103_check_pool() {
7307         local save_fsname=$1
7308         local errno=$2
7309
7310         stat $DIR/$tdir/test-framework.sh ||
7311                 error "($errno) Fail to stat"
7312         do_facet mgs $LCTL pool_list $FSNAME.pool1 ||
7313                 error "($errno) Fail to list $FSNAME.pool1"
7314         do_facet mgs $LCTL pool_list $FSNAME.$save_fsname ||
7315                 error "($errno) Fail to list $FSNAME.$save_fsname"
7316         do_facet mgs $LCTL pool_list $FSNAME.$save_fsname |
7317                 grep ${FSNAME}-OST0000 ||
7318                 error "($errno) List $FSNAME.$save_fsname is invalid"
7319
7320         local pname=$($LFS getstripe --pool $DIR/$tdir/d0)
7321         [ "$pname" = "$save_fsname" ] ||
7322                 error "($errno) Unexpected pool name $pname"
7323 }
7324
7325 test_103() {
7326         check_mount_and_prep
7327         rm -rf $DIR/$tdir
7328         mkdir $DIR/$tdir || error "(1) Fail to mkdir $DIR/$tdir"
7329         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir ||
7330                 error "(2) Fail to copy test-framework.sh"
7331
7332         do_facet mgs $LCTL pool_new $FSNAME.pool1 ||
7333                 error "(3) Fail to create $FSNAME.pool1"
7334         # name the pool name as the fsname
7335         do_facet mgs $LCTL pool_new $FSNAME.$FSNAME ||
7336                 error "(4) Fail to create $FSNAME.$FSNAME"
7337
7338         test_103_set_pool $FSNAME OST0000
7339
7340         $SETSTRIPE -p $FSNAME $DIR/$tdir/d0 ||
7341                 error "(6) Fail to setstripe on $DIR/$tdir/d0"
7342
7343         KEEP_ZPOOL=true
7344         stopall
7345
7346         test_renamefs mylustre
7347
7348         local save_fsname=$FSNAME
7349         FSNAME="mylustre"
7350         setupall
7351
7352         test_103_check_pool $save_fsname 7
7353
7354         if [ $OSTCOUNT -ge 2 ]; then
7355                 test_103_set_pool $save_fsname OST0001
7356         fi
7357
7358         $SETSTRIPE -p $save_fsname $DIR/$tdir/f0 ||
7359                 error "(16) Fail to setstripe on $DIR/$tdir/f0"
7360
7361         stopall
7362
7363         test_renamefs tfs
7364
7365         FSNAME="tfs"
7366         setupall
7367
7368         test_103_check_pool $save_fsname 17
7369
7370         stopall
7371
7372         test_renamefs $save_fsname
7373
7374         FSNAME=$save_fsname
7375         setupall
7376         KEEP_ZPOOL=false
7377 }
7378 run_test 103 "rename filesystem name"
7379
7380 test_104() { # LU-6952
7381         local mds_mountopts=$MDS_MOUNT_OPTS
7382         local ost_mountopts=$OST_MOUNT_OPTS
7383         local mds_mountfsopts=$MDS_MOUNT_FS_OPTS
7384         local lctl_ver=$(do_facet $SINGLEMDS $LCTL --version |
7385                         awk '{ print $2 }')
7386
7387         [[ $(version_code $lctl_ver) -lt $(version_code 2.9.55) ]] &&
7388                 { skip "this test needs utils above 2.9.55" && return 0; }
7389
7390         # specify "acl" in mount options used by mkfs.lustre
7391         if [ -z "$MDS_MOUNT_FS_OPTS" ]; then
7392                 MDS_MOUNT_FS_OPTS="acl,user_xattr"
7393         else
7394
7395                 MDS_MOUNT_FS_OPTS="${MDS_MOUNT_FS_OPTS},acl,user_xattr"
7396         fi
7397
7398         echo "mountfsopt: $MDS_MOUNT_FS_OPTS"
7399
7400         #reformat/remount the MDT to apply the MDT_MOUNT_FS_OPT options
7401         formatall
7402         if [ -z "$MDS_MOUNT_OPTS" ]; then
7403                 MDS_MOUNT_OPTS="-o noacl"
7404         else
7405                 MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7406         fi
7407
7408         for num in $(seq $MDSCOUNT); do
7409                 start mds$num $(mdsdevname $num) $MDS_MOUNT_OPTS ||
7410                         error "Failed to start MDS"
7411         done
7412
7413         for num in $(seq $OSTCOUNT); do
7414                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
7415                         error "Failed to start OST"
7416         done
7417
7418         mount_client $MOUNT
7419         setfacl -m "d:$RUNAS_ID:rwx" $MOUNT &&
7420                 error "ACL is applied when FS is mounted with noacl."
7421
7422         MDS_MOUNT_OPTS=$mds_mountopts
7423         OST_MOUNT_OPTS=$ost_mountopts
7424         MDS_MOUNT_FS_OPTS=$mds_mountfsopts
7425
7426         formatall
7427         setupall
7428 }
7429 run_test 104 "Make sure user defined options are reflected in mount"
7430
7431 error_and_umount() {
7432         umount $TMP/$tdir
7433         rmdir $TMP/$tdir
7434         error $*
7435 }
7436
7437 test_105() {
7438         cleanup
7439         reformat
7440         setup
7441         mkdir -p $TMP/$tdir
7442         mount --bind $DIR $TMP/$tdir || error "mount bind mnt pt failed"
7443         rm -f $TMP/$tdir/$tfile
7444         rm -f $TMP/$tdir/${tfile}1
7445
7446         # Files should not be created in ro bind mount point
7447         # remounting from rw to ro
7448         mount -o remount,ro $TMP/$tdir ||
7449                 error_and_umount "readonly remount of bind mnt pt failed"
7450         touch $TMP/$tdir/$tfile &&
7451                 error_and_umount "touch succeeds on ro bind mnt pt"
7452         [ -e $TMP/$tdir/$tfile ] &&
7453                 error_and_umount "file created on ro bind mnt pt"
7454
7455         # Files should be created in rw bind mount point
7456         # remounting from ro to rw
7457         mount -o remount,rw $TMP/$tdir ||
7458                 error_and_umount "read-write remount of bind mnt pt failed"
7459         touch $TMP/$tdir/${tfile}1 ||
7460                 error_and_umount "touch fails on rw bind mnt pt"
7461         [ -e $TMP/$tdir/${tfile}1 ] ||
7462                 error_and_umount "file not created on rw bind mnt pt"
7463         umount $TMP/$tdir || error "umount of bind mnt pt failed"
7464         rmdir $TMP/$tdir
7465         cleanup || error "cleanup failed with $?"
7466 }
7467 run_test 105 "check file creation for ro and rw bind mnt pt"
7468
7469 test_107() {
7470         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.50) ]] ||
7471                 { skip "Need MDS version > 2.10.50"; return; }
7472
7473         start_mgsmds || error "start_mgsmds failed"
7474         start_ost || error "unable to start OST"
7475
7476         # add unknown configuration parameter.
7477         local PARAM="$FSNAME-OST0000.ost.unknown_param=50"
7478         do_facet mgs "$LCTL conf_param $PARAM"
7479         cleanup_nocli || error "cleanup_nocli failed with $?"
7480         load_modules
7481
7482         # unknown param should be ignored while mounting.
7483         start_ost || error "unable to start OST after unknown param set"
7484
7485         cleanup || error "cleanup failed with $?"
7486 }
7487 run_test 107 "Unknown config param should not fail target mounting"
7488
7489 if ! combined_mgs_mds ; then
7490         stop mgs
7491 fi
7492
7493 cleanup_gss
7494
7495 # restore the values of MDSSIZE and OSTSIZE
7496 MDSSIZE=$STORED_MDSSIZE
7497 OSTSIZE=$STORED_OSTSIZE
7498 reformat
7499
7500 complete $SECONDS
7501 exit_status