Whamcloud - gitweb
- name switch: "light" --> "lite"
[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         [ "$1" = "ext3" ] && MKFS="mkfs.ext2 -j"
49
50         if [ -b "$2" ]; then
51                 [ $# -lt 2 -o $# -gt 3 ] && \
52                         echo "usage: $0 <fstype> <file> [size]" 1>&2 && exit -1
53
54                 PM="/proc/mounts"
55                 [ -f "$PM" ] || PM="/etc/mtab"
56
57                 grep "$2 " $PM 1>&2 && echo "$0: $2 is in $PM!" 1>&2 && exit -1
58
59                 $MKFS $MKFSOPT $2 $3 || exit -1
60                 LOOPDEV=$2      # Not really a loop device
61         else
62                 [ $# -ne 3 ] && \
63                         echo "usage: $0 <fstype> <file> <size>" 1>&2 && exit -1
64
65                 if [ -f "$EFILE" ]; then
66                         echo "using existing filesystem $EFILE for $2"
67                         zcat "$EFILE" > $2 || exit -1
68                         sync
69                 else
70                         echo "creating new filesystem on $2"
71                         dd if=/dev/zero of=$2 bs=1k count=$3 1>&2 || exit -1
72                         $MKFS $MKFSOPT -F $2 1>&2 || exit -1
73                 fi
74                 LOOPDEV=`next_loop_dev`
75                 losetup ${LOOPDEV} $2 1>&2 || exit -1
76         fi
77 }
78
79 # Set up to use an existing filesystem.  We take the same parameters as
80 # new_fs, even though we only use the <file> parameter, to make it easy
81 # to convert between new_fs and old_fs in testing scripts.
82 old_fs () {
83         [ -e $2 ] || exit -1
84
85         if [ -b "$2" ]; then
86                 LOOPDEV=$2      # Not really a loop device
87         else
88                 LOOPDEV=`next_loop_dev`
89                 losetup ${LOOPDEV} $2 1>&2 || exit -1
90         fi
91 }
92
93 list_mods() {
94         $DEBCTL modules > $R/tmp/ogdb
95         echo "The GDB module script is in /tmp/ogdb.  Press enter to continue"
96         read
97 }
98
99 setup() {
100     [ -c /dev/portals ] || mknod /dev/portals c 10 240
101
102     insmod $SRCDIR/../../portals/linux/oslib/portals.o || exit -1
103     insmod $SRCDIR/../../portals/linux/qswnal/kqswnal.o
104     insmod $SRCDIR/../../portals/linux/socknal/ksocknal.o || exit -1
105
106     [ "$NETWORK" = "tcp" ] && ($ACCEPTOR $PORT)
107
108     [ -c /dev/obd ] || mknod /dev/obd c 10 241
109
110     insmod $SRCDIR/../../obd/class/obdclass.o || exit -1
111     insmod $SRCDIR/../../obd/rpc/ptlrpc.o || exit -1
112     insmod $SRCDIR/../../obd/ldlm/ldlm.o || exit -1
113     insmod $SRCDIR/../../obd/ext2obd/obdext2.o || exit -1
114     insmod $SRCDIR/../../obd/filterobd/obdfilter.o || exit -1
115     insmod $SRCDIR/../../obd/ost/ost.o || exit -1
116     insmod $SRCDIR/../../obd/osc/osc.o || exit -1
117     insmod $SRCDIR/../../obd/obdecho/obdecho.o || exit -1
118     insmod $SRCDIR/../../obd/mds/mds.o || exit -1
119     insmod $SRCDIR/../../obd/mdc/mdc.o || exit -1
120     insmod $SRCDIR/../../obd/llight/llite.o || exit -1
121
122     list_mods
123
124     [ -d /mnt/lustre ] || mkdir /mnt/lustre
125 }
126
127 setup_portals() {
128         if [ -z "$NETWORK" -o -z "$LOCALHOST" -o -z "$SERVER" ]; then
129                 echo "$0: NETWORK or LOCALHOST or SERVER is not set"
130                 exit -1
131         fi
132
133         case $NETWORK in
134         elan)   if [ "$PORT" ]; then
135                         echo "$0: NETWORK is elan but PORT is set"
136                         exit -1
137                 fi
138                 ;;
139         tcp)    if [ -z "$PORT" ]; then
140                         echo "$0: NETWORK is tcp but PORT is not set"
141                         exit -1
142                 fi
143                 ;;
144         *)      echo "$0: unknown NETWORK \'$NETWORK\'"
145                 exit -1
146                 ;;
147         esac
148
149         $PTLCTL <<- EOF
150         setup $NETWORK
151         mynid $LOCALHOST
152         connect $SERVER $PORT
153         add_uuid self
154         add_uuid mds
155         add_uuid ost
156         quit
157         EOF
158 }
159
160 setup_ldlm() {
161     [ -c /dev/portals ] || mknod /dev/portals c 10 240
162
163     insmod $SRCDIR/../../portals/linux/oslib/portals.o || exit -1
164
165     insmod $SRCDIR/../../obd/class/obdclass.o || exit -1
166     insmod $SRCDIR/../../obd/ldlm/ldlm.o || exit -1
167
168     list_mods
169 }