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