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