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