Whamcloud - gitweb
Minor change - rename "run" to "test_fail" to match runfailure-mds.
[fs/lustre-release.git] / lustre / tests / common.sh
1 export PATH=$PATH:/sbin:/usr/sbin
2
3 if [ -d /r ]; then
4         R=/r
5 fi
6
7 PTLCTL=$SRCDIR/../../portals/linux/utils/ptlctl
8 OBDCTL=$SRCDIR/../../obd/utils/obdctl
9 DEBCTL=$SRCDIR/../../portals/linux/utils/debugctl
10 ACCEPTOR=$SRCDIR/../../portals/linux/utils/acceptor
11
12 LOOPNUM=0; export LOOPNUM
13 if [ -b /dev/loop0 ]; then
14         LOOP=/dev/loop
15 else
16         if [ -b /dev/loop/0 ]; then
17                 LOOP=/dev/loop/
18         else
19                 echo "Cannot find /dev/loop0 or /dev/loop/0" 1>&2 && exit -1
20         fi
21 fi
22
23 # Return the next unused loop device on stdout and in the $LOOPDEV
24 # environment variable.
25 next_loop_dev() {
26         NEXT=
27         while [ -b ${LOOP}${LOOPNUM} ]; do
28                 LOOPDEV=${LOOP}${LOOPNUM}
29                 losetup ${LOOPDEV} > /dev/null 2>&1 || NEXT=${LOOPDEV}
30                 LOOPNUM=`expr ${LOOPNUM} + 1`
31                 [ "$NEXT" ] && echo ${NEXT} && break
32         done
33 }
34
35 # Create a new filesystem.  If we are using a loopback device, we check
36 # for existing "template" filesystems instead of creating a new one,
37 # because it is _much_ faster to gunzip the empty filesystem instead of
38 # creating a new one from scratch.  Conversely, if we are creating a
39 # filesystem on a device we use mkfs, because that only writes sparsely
40 # to the device.  The empty filesystems are also highly compressed (1000:1)
41 # so they don't take too much space.
42 new_fs () {
43         EFILE="$1_$3.gz"
44         MKFS="mkfs.$1"
45         MKFSOPT="-b 4096"
46
47         [ "$1" = "ext3" ] && MKFS="mkfs.ext2 -j"
48
49         if [ -b "$2" ]; then
50                 [ $# -lt 2 -o $# -gt 3 ] && \
51                         echo "usage: $0 <fstype> <file> [size]" 1>&2 && exit -1
52
53                 PM="/proc/mounts"
54                 [ -f "$PM" ] || PM="/etc/mtab"
55
56                 grep "$2 " $PM 1>&2 && echo "$0: $2 is in $PM!" 1>&2 && exit -1
57
58                 $MKFS $MKFSOPT $2 $3 || exit -1
59                 LOOPDEV=$2      # Not really a loop device
60         else
61                 [ $# -ne 3 ] && \
62                         echo "usage: $0 <fstype> <file> <size>" 1>&2 && exit -1
63
64                 if [ -f "$EFILE" ]; then
65                         echo "using existing filesystem $EFILE for $2"
66                         zcat "$EFILE" > $2 || exit -1
67                         sync
68                 else
69                         echo "creating new filesystem on $2"
70                         dd if=/dev/zero of=$2 bs=1k count=$3 1>&2 || exit -1
71                         $MKFS $MKFSOPT -F $2 1>&2 || exit -1
72                 fi
73                 LOOPDEV=`next_loop_dev`
74                 losetup ${LOOPDEV} $2 1>&2 || exit -1
75         fi
76 }
77
78 # Set up to use an existing filesystem.  We take the same parameters as
79 # new_fs, even though we only use the <file> parameter, to make it easy
80 # to convert between new_fs and old_fs in testing scripts.
81 old_fs () {
82         [ -e $2 ] || exit -1
83
84         if [ -b "$2" ]; then
85                 LOOPDEV=$2      # Not really a loop device
86         else
87                 LOOPDEV=`next_loop_dev`
88                 losetup ${LOOPDEV} $2 1>&2 || exit -1
89         fi
90 }
91
92 list_mods() {
93         $DEBCTL modules > $R/tmp/ogdb
94         echo "The GDB module script is in /tmp/ogdb"
95 }
96
97 setup_portals() {
98         if [ -z "$NETWORK" -o -z "$LOCALHOST" -o -z "$SERVER" ]; then
99                 echo "$0: NETWORK or LOCALHOST or SERVER is not set" 1>&2
100                 exit -1
101         fi
102
103         [ -c /dev/portals ] || mknod /dev/portals c 10 240
104
105         insmod $SRCDIR/../../portals/linux/oslib/portals.o || exit -1
106
107         case $NETWORK in
108         elan)   if [ "$PORT" ]; then
109                         echo "$0: NETWORK is elan but PORT is set" 1>&2
110                         exit -1
111                 fi
112                 insmod $SRCDIR/../../portals/linux/qswnal/kqswnal.o
113                 ;;
114         tcp)    if [ -z "$PORT" ]; then
115                         echo "$0: NETWORK is tcp but PORT is not set" 1>&2
116                         exit -1
117                 fi
118                 insmod $SRCDIR/../../portals/linux/socknal/ksocknal.o || exit -1
119                 $ACCEPTOR $PORT
120                 ;;
121         *)      echo "$0: unknown NETWORK \'$NETWORK\'" 1>&2
122                 exit -1
123                 ;;
124         esac
125
126         $PTLCTL <<- EOF
127         setup $NETWORK
128         mynid $LOCALHOST
129         connect $SERVER $PORT
130         add_uuid self
131         add_uuid mds
132         add_uuid ost
133         quit
134         EOF
135 }
136
137 setup_lustre() {
138         [ -c /dev/obd ] || mknod /dev/obd c 10 241
139
140         insmod $SRCDIR/../../obd/class/obdclass.o || exit -1
141         insmod $SRCDIR/../../obd/rpc/ptlrpc.o || exit -1
142         insmod $SRCDIR/../../obd/ldlm/ldlm.o || exit -1
143         insmod $SRCDIR/../../obd/ext2obd/obdext2.o || exit -1
144         insmod $SRCDIR/../../obd/filterobd/obdfilter.o || exit -1
145         insmod $SRCDIR/../../obd/ost/ost.o || exit -1
146         insmod $SRCDIR/../../obd/osc/osc.o || exit -1
147         insmod $SRCDIR/../../obd/obdecho/obdecho.o || exit -1
148         insmod $SRCDIR/../../obd/mds/mds.o || exit -1
149         insmod $SRCDIR/../../obd/mdc/mdc.o || exit -1
150         insmod $SRCDIR/../../obd/llight/llite.o || exit -1
151
152         list_mods
153
154         [ -d /mnt/lustre ] || mkdir /mnt/lustre
155 }
156
157 setup_ldlm() {
158         [ -c /dev/portals ] || mknod /dev/portals c 10 240
159
160         insmod $SRCDIR/../../portals/linux/oslib/portals.o || exit -1
161
162         insmod $SRCDIR/../../obd/class/obdclass.o || exit -1
163         insmod $SRCDIR/../../obd/ldlm/ldlm.o || exit -1
164
165         list_mods
166 }