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