Whamcloud - gitweb
Empty filesystems for creating tests. Using these is _much_ faster than
[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 next_loop_dev() {
25         NEXT=
26         while [ -b ${LOOP}${LOOPNUM} ]; do
27                 LOOPDEV=${LOOP}${LOOPNUM}
28                 losetup ${LOOPDEV} > /dev/null 2>&1 || NEXT=${LOOPDEV}
29                 LOOPNUM=`expr ${LOOPNUM} + 1`
30                 [ "$NEXT" ] && echo ${NEXT} && break
31         done
32 }
33
34 list_mods() {
35     $DEBCTL modules > $R/tmp/ogdb
36     echo "The GDB module script is in /tmp/ogdb.  Press enter to continue"
37     read
38 }
39
40 new_fs () {
41     dd if=/dev/zero of=$2 bs=1k count=$3 1>&2 || exit -1
42     mkfs.$1 -b 4096 -F $2 1>&2 || exit -1
43     LOOPDEV=`next_loop_dev`
44     losetup ${LOOPDEV} $2 1>&2 || exit -1
45 }
46
47 old_fs () {
48     [ -e $2 ] || exit -1
49     LOOPDEV=`next_loop_dev`
50     losetup ${LOOPDEV} $2 1>&2 || exit -1
51 }
52
53 setup() {
54     [ -c /dev/portals ] || mknod /dev/portals c 10 240
55
56     insmod $SRCDIR/../../portals/linux/oslib/portals.o || exit -1
57     insmod $SRCDIR/../../portals/linux/qswnal/kqswnal.o
58     insmod $SRCDIR/../../portals/linux/socknal/ksocknal.o || exit -1
59
60     [ "$NETWORK" = "tcp" ] && ($ACCEPTOR $PORT &)
61
62     [ -c /dev/obd ] || mknod /dev/obd c 10 241
63
64     insmod $SRCDIR/../../obd/class/obdclass.o || exit -1
65     insmod $SRCDIR/../../obd/rpc/ptlrpc.o || exit -1
66     insmod $SRCDIR/../../obd/ext2obd/obdext2.o || exit -1
67     insmod $SRCDIR/../../obd/ost/ost.o || exit -1
68     insmod $SRCDIR/../../obd/osc/osc.o || exit -1
69     insmod $SRCDIR/../../obd/obdecho/obdecho.o || exit -1
70     insmod $SRCDIR/../../obd/mds/mds.o || exit -1
71     insmod $SRCDIR/../../obd/mdc/mdc.o || exit -1
72     insmod $SRCDIR/../../obd/llight/llight.o || exit -1
73
74     list_mods
75
76     [ -d /mnt/obd ] || mkdir /mnt/obd
77 }
78
79 setup_portals() {
80         if [ -z "$NETWORK" -o -z "$LOCALHOST" -o -z "$SERVER" ]; then
81                 echo "$0: NETWORK or LOCALHOST or SERVER is not set"
82                 exit -1
83         fi
84
85         case $NETWORK in
86         elan)   if [ "$PORT" ]; then
87                         echo "$0: NETWORK is elan but PORT is set"
88                         exit -1
89                 fi
90                 ;;
91         tcp)    if [ -z "$PORT" ]; then
92                         echo "$0: NETWORK is tcp but PORT is not set"
93                         exit -1
94                 fi
95                 ;;
96         *)      echo "$0: unknown NETWORK \'$NETWORK\'"
97                 exit -1
98                 ;;
99         esac
100
101         $PTLCTL <<- EOF
102         setup $NETWORK
103         mynid $LOCALHOST
104         connect $SERVER $PORT
105         add_uuid self
106         add_uuid mds
107         add_uuid ost
108         quit
109         EOF
110 }
111
112 setup_ldlm() {
113     [ -c /dev/portals ] || mknod /dev/portals c 10 240
114
115     insmod $SRCDIR/../../portals/linux/oslib/portals.o || exit -1
116
117     insmod $SRCDIR/../../obd/class/obdclass.o || exit -1
118     insmod $SRCDIR/../../obd/ldlm/ldlm.o || exit -1
119
120     list_mods
121 }