Whamcloud - gitweb
- name switch: "light" --> "lite"
[fs/lustre-release.git] / lustre / tests / common.sh
index 5935d72..c8f7570 100644 (file)
@@ -21,6 +21,8 @@ else
   fi
 fi
 
+# Return the next unused loop device on stdout and in the $LOOPDEV
+# environment variable.
 next_loop_dev() {
        NEXT=
        while [ -b ${LOOP}${LOOPNUM} ]; do
@@ -31,23 +33,67 @@ next_loop_dev() {
        done
 }
 
-list_mods() {
-    $DEBCTL modules > $R/tmp/ogdb
-    echo "The GDB module script is in /tmp/ogdb.  Press enter to continue"
-    read
-}
-
+# Create a new filesystem.  If we are using a loopback device, we check
+# for existing "template" filesystems instead of creating a new one,
+# because it is _much_ faster to gunzip the empty filesystem instead of
+# creating a new one from scratch.  Conversely, if we are creating a
+# filesystem on a device we use mkfs, because that only writes sparsely
+# to the device.  The empty filesystems are also highly compressed (1000:1)
+# so they don't take too much space.
 new_fs () {
-    dd if=/dev/zero of=$2 bs=1k count=$3 1>&2 || exit -1
-    mkfs.$1 -b 4096 -F $2 1>&2 || exit -1
-    LOOPDEV=`next_loop_dev`
-    losetup ${LOOPDEV} $2 1>&2 || exit -1
+       EFILE="$1_$3.gz"
+       MKFS="mkfs.$1"
+       MKFSOPT="-b 4096"
+
+       [ "$1" = "ext3" ] && MKFS="mkfs.ext2 -j"
+
+       if [ -b "$2" ]; then
+               [ $# -lt 2 -o $# -gt 3 ] && \
+                       echo "usage: $0 <fstype> <file> [size]" 1>&2 && exit -1
+
+               PM="/proc/mounts"
+               [ -f "$PM" ] || PM="/etc/mtab"
+
+               grep "$2 " $PM 1>&2 && echo "$0: $2 is in $PM!" 1>&2 && exit -1
+
+               $MKFS $MKFSOPT $2 $3 || exit -1
+               LOOPDEV=$2      # Not really a loop device
+       else
+               [ $# -ne 3 ] && \
+                       echo "usage: $0 <fstype> <file> <size>" 1>&2 && exit -1
+
+               if [ -f "$EFILE" ]; then
+                       echo "using existing filesystem $EFILE for $2"
+                       zcat "$EFILE" > $2 || exit -1
+                       sync
+               else
+                       echo "creating new filesystem on $2"
+                       dd if=/dev/zero of=$2 bs=1k count=$3 1>&2 || exit -1
+                       $MKFS $MKFSOPT -F $2 1>&2 || exit -1
+               fi
+               LOOPDEV=`next_loop_dev`
+               losetup ${LOOPDEV} $2 1>&2 || exit -1
+       fi
 }
 
+# Set up to use an existing filesystem.  We take the same parameters as
+# new_fs, even though we only use the <file> parameter, to make it easy
+# to convert between new_fs and old_fs in testing scripts.
 old_fs () {
-    [ -e $2 ] || exit -1
-    LOOPDEV=`next_loop_dev`
-    losetup ${LOOPDEV} $2 1>&2 || exit -1
+       [ -e $2 ] || exit -1
+
+       if [ -b "$2" ]; then
+               LOOPDEV=$2      # Not really a loop device
+       else
+               LOOPDEV=`next_loop_dev`
+               losetup ${LOOPDEV} $2 1>&2 || exit -1
+       fi
+}
+
+list_mods() {
+       $DEBCTL modules > $R/tmp/ogdb
+       echo "The GDB module script is in /tmp/ogdb.  Press enter to continue"
+       read
 }
 
 setup() {
@@ -57,23 +103,25 @@ setup() {
     insmod $SRCDIR/../../portals/linux/qswnal/kqswnal.o
     insmod $SRCDIR/../../portals/linux/socknal/ksocknal.o || exit -1
 
-    [ "$NETWORK" = "tcp" ] && $ACCEPTOR $PORT &
+    [ "$NETWORK" = "tcp" ] && ($ACCEPTOR $PORT)
 
     [ -c /dev/obd ] || mknod /dev/obd c 10 241
 
     insmod $SRCDIR/../../obd/class/obdclass.o || exit -1
     insmod $SRCDIR/../../obd/rpc/ptlrpc.o || exit -1
+    insmod $SRCDIR/../../obd/ldlm/ldlm.o || exit -1
     insmod $SRCDIR/../../obd/ext2obd/obdext2.o || exit -1
+    insmod $SRCDIR/../../obd/filterobd/obdfilter.o || exit -1
     insmod $SRCDIR/../../obd/ost/ost.o || exit -1
     insmod $SRCDIR/../../obd/osc/osc.o || exit -1
     insmod $SRCDIR/../../obd/obdecho/obdecho.o || exit -1
     insmod $SRCDIR/../../obd/mds/mds.o || exit -1
     insmod $SRCDIR/../../obd/mdc/mdc.o || exit -1
-    insmod $SRCDIR/../../obd/llight/llight.o || exit -1
+    insmod $SRCDIR/../../obd/llight/llite.o || exit -1
 
     list_mods
 
-    [ -d /mnt/obd ] || mkdir /mnt/obd
+    [ -d /mnt/lustre ] || mkdir /mnt/lustre
 }
 
 setup_portals() {