]> git.proxmox.com Git - mirror_zfs-debian.git/blobdiff - scripts/common.sh
New upstream version 0.7.11
[mirror_zfs-debian.git] / scripts / common.sh
index d9f6efac5fe351be0f35aaa4ee85ce7d8b8d9048..84c4de0badc126dc780df31056e09026d120f2da 100644 (file)
@@ -12,7 +12,7 @@ if [ -f "${basedir}/../${SCRIPT_CONFIG}" ]; then
 . "${basedir}/../${SCRIPT_CONFIG}"
 else
 KERNEL_MODULES=(zlib_deflate zlib_inflate)
-MODULES=(spl splat zavl znvpair zunicode zcommon zfs)
+MODULES=(spl splat zavl znvpair zunicode zcommon icp zfs)
 fi
 
 PROG="<define PROG>"
@@ -21,7 +21,6 @@ VERBOSE=
 VERBOSE_FLAG=
 FORCE=
 FORCE_FLAG=
-DUMP_LOG=
 ERROR=
 RAID0S=()
 RAID10S=()
@@ -35,19 +34,24 @@ exec_prefix=${prefix}
 pkgdatadir=${prefix}/share/zfs
 bindir=${exec_prefix}/bin
 sbindir=${exec_prefix}/sbin
-udevdir=${exec_prefix}/lib/udev
-udevruledir=${udevdir}/rules.d
+udevdir=
+udevruledir=
+mounthelperdir=
 sysconfdir=${prefix}/etc
+localstatedir=${prefix}/var
 
 ETCDIR=${ETCDIR:-/etc}
 DEVDIR=${DEVDIR:-/dev/disk/by-vdev}
 ZPOOLDIR=${ZPOOLDIR:-${pkgdatadir}/zpool-config}
 ZPIOSDIR=${ZPIOSDIR:-${pkgdatadir}/zpios-test}
 ZPIOSPROFILEDIR=${ZPIOSPROFILEDIR:-${pkgdatadir}/zpios-profile}
+TESTSDIR=${TESTSDIR:-${pkgdatadir}/zfs-tests}
+RUNFILEDIR=${RUNFILEDIR:-${pkgdatadir}/runfiles}
 
 ZDB=${ZDB:-${sbindir}/zdb}
 ZFS=${ZFS:-${sbindir}/zfs}
 ZINJECT=${ZINJECT:-${sbindir}/zinject}
+ZHACK=${ZHACK:-${sbindir}/zhack}
 ZPOOL=${ZPOOL:-${sbindir}/zpool}
 ZTEST=${ZTEST:-${sbindir}/ztest}
 ZPIOS=${ZPIOS:-${sbindir}/zpios}
@@ -57,6 +61,9 @@ ZFS_SH=${ZFS_SH:-${pkgdatadir}/zfs.sh}
 ZPOOL_CREATE_SH=${ZPOOL_CREATE_SH:-${pkgdatadir}/zpool-create.sh}
 ZPIOS_SH=${ZPIOS_SH:-${pkgdatadir}/zpios.sh}
 ZPIOS_SURVEY_SH=${ZPIOS_SURVEY_SH:-${pkgdatadir}/zpios-survey.sh}
+TEST_RUNNER=${TEST_RUNNER:-${pkgdatadir}/test-runner/bin/test-runner.py}
+STF_TOOLS=${STF_TOOLS:-${pkgdatadir}/test-runner}
+STF_SUITE=${STF_SUITE:-${pkgdatadir}/zfs-tests}
 
 LDMOD=${LDMOD:-/sbin/modprobe}
 LSMOD=${LSMOD:-/sbin/lsmod}
@@ -64,6 +71,7 @@ RMMOD=${RMMOD:-/sbin/rmmod}
 INFOMOD=${INFOMOD:-/sbin/modinfo}
 LOSETUP=${LOSETUP:-/sbin/losetup}
 MDADM=${MDADM:-/sbin/mdadm}
+DMSETUP=${DMSETUP:-/sbin/dmsetup}
 PARTED=${PARTED:-/sbin/parted}
 BLOCKDEV=${BLOCKDEV:-/sbin/blockdev}
 LSSCSI=${LSSCSI:-/usr/bin/lsscsi}
@@ -71,6 +79,9 @@ SCSIRESCAN=${SCSIRESCAN:-/usr/bin/scsi-rescan}
 SYSCTL=${SYSCTL:-/sbin/sysctl}
 UDEVADM=${UDEVADM:-/sbin/udevadm}
 AWK=${AWK:-/usr/bin/awk}
+GDB=${GDB:-/usr/bin/gdb}
+
+ZED_PIDFILE=${ZED_PIDFILE:-${localstatedir}/run/zed.pid}
 
 COLOR_BLACK="\033[0;30m"
 COLOR_DK_GRAY="\033[1;30m"
@@ -136,17 +147,6 @@ populate() {
 }
 
 init() {
-       # Disable the udev rule 90-zfs.rules to prevent the zfs module
-       # stack from being loaded due to the detection of a zfs device.
-       # This is important because the test scripts require full control
-       # over when and how the modules are loaded/unloaded.  A trap is
-       # set to ensure the udev rule is correctly replaced on exit.
-       local RULE=${udevruledir}/90-zfs.rules
-       if test -e  ${RULE}; then
-               trap "mv ${RULE}.disabled ${RULE}" INT TERM EXIT
-               mv ${RULE} ${RULE}.disabled
-       fi
-
        # Create a random directory tree of files and sub-directories to
        # to act as a copy source for the various regression tests.
        SRC_DIR=`mktemp -d -p /var/tmp/ zfs.src.XXXXXXXX`
@@ -154,17 +154,6 @@ init() {
        populate $SRC_DIR 10 100
 }
 
-spl_dump_log() {
-       ${SYSCTL} -w kernel.spl.debug.dump=1 &>/dev/null
-       local NAME=`dmesg | tail -n 1 | cut -f5 -d' '`
-       ${SPLBUILD}/cmd/spl ${NAME} >${NAME}.log
-       echo
-       echo "Dumped debug log: ${NAME}.log"
-       tail -n1 ${NAME}.log
-       echo
-       return 0
-}
-
 check_modules() {
        local LOADED_MODULES=()
        local MISSING_MODULES=()
@@ -204,7 +193,11 @@ load_module() {
                echo "Loading ${NAME} ($@)"
        fi
 
-       ${LDMOD} $* &>/dev/null || ERROR="Failed to load $1" return 1
+       ${LDMOD} $* &>/dev/null
+       if [ $? -ne 0 ]; then
+               echo "Failed to load ${NAME} ($@)"
+               return 1
+       fi
 
        return 0
 }
@@ -213,7 +206,7 @@ load_modules() {
        mkdir -p /etc/zfs
 
        for MOD in ${KERNEL_MODULES[*]}; do
-               load_module ${MOD}
+               load_module ${MOD} >/dev/null
        done
 
        for MOD in ${MODULES[*]}; do
@@ -260,11 +253,6 @@ unload_modules() {
                                egrep "^${NAME} "| ${AWK} '{print $3}'`
 
                if [ "${USE_COUNT}" = 0 ] ; then
-
-                       if [ "${DUMP_LOG}" -a ${NAME} = "spl" ]; then
-                               spl_dump_log
-                       fi
-
                        unload_module ${MOD} || return 1
                fi
        done
@@ -285,34 +273,61 @@ check_loop_utils() {
 
 
 #
-# Find and return an unused loopback device.
+# Find and return an unused loop device.  A new /dev/loopN node will be
+# created if required.  The kernel loop driver will automatically register
+# the minor as long as it's less than /sys/module/loop/parameters/max_loop.
 #
 unused_loop_device() {
-       for DEVICE in `ls -1 /dev/loop[0-9]* 2>/dev/null`; do
-               ${LOSETUP} ${DEVICE} &>/dev/null
-               if [ $? -ne 0 ]; then
-                       echo ${DEVICE}
-                       return
+       local DEVICE=$(${LOSETUP} -f)
+       local MAX_LOOP_PATH="/sys/module/loop/parameters/max_loop"
+       local MAX_LOOP;
+
+       # An existing /dev/loopN device was available.
+       if [ -n "${DEVICE}" ]; then
+               echo "${DEVICE}"
+               return 0
+       fi
+
+       # Create a new /dev/loopN provided we are not at MAX_LOOP.
+       if [ -f "${MAX_LOOP_PATH}" ]; then
+               MAX_LOOP=`cat /sys/module/loop/parameters/max_loop`
+               if [ ${MAX_LOOP} -eq 0 ]; then
+                       MAX_LOOP=255
                fi
-       done
 
-       die "Error: Unable to find unused loopback device"
+               for (( i=0; i<=${MAX_LOOP}; i++ )); do
+                       DEVICE="/dev/loop$i"
+
+                       if [ -b "${DEVICE}" ]; then
+                               continue
+                       else
+                               mknod -m660 "${DEVICE}" b 7 $i
+                               chown root.disk "${DEVICE}"
+                               chmod 666 "${DEVICE}"
+
+                               echo "${DEVICE}"
+                               return 0
+                       fi
+               done
+       fi
+
+       die "Error: Unable to create new loopback device"
 }
 
 #
 # This can be slightly dangerous because the loop devices we are
 # cleaning up may not be ours.  However, if the devices are currently
 # in use we will not be able to remove them, and we only remove
-# devices which include 'zpool' in the name.  So any damage we might
-# do should be limited to other zfs related testing.
+# devices which include 'zpool' or 'deleted' in the name.  So any
+# damage we might do should be limited to other zfs related testing.
 #
 cleanup_loop_devices() {
        local TMP_FILE=`mktemp`
 
        ${LOSETUP} -a | tr -d '()' >${TMP_FILE}
        ${AWK} -F":" -v losetup="$LOSETUP" \
-           '/zpool/ { system("losetup -d "$1) }' ${TMP_FILE}
-       ${AWK} -F" " '/zpool/ { system("rm -f "$3) }' ${TMP_FILE}
+           '/zpool/ || /deleted/ { system("losetup -d "$1) }' ${TMP_FILE}
+       ${AWK} -F" " '/zpool/ || /deleted/ { system("rm -f "$3) }' ${TMP_FILE}
 
        rm -f ${TMP_FILE}
 }
@@ -325,7 +340,7 @@ destroy_loop_devices() {
        local LODEVICES="$1"
 
        msg "Destroying ${LODEVICES}"
-        ${LOSETUP} -d ${LODEVICES} || \
+       ${LOSETUP} -d ${LODEVICES} || \
                die "Error $? destroying ${FILE} -> ${DEVICE} loopback"
 
        rm -f ${FILES}
@@ -333,13 +348,14 @@ destroy_loop_devices() {
 }
 
 #
-# Create a device label.
+# Create a device label taking care to briefly wait if udev needs to settle.
 #
 label() {
        local DEVICE=$1
        local LABEL=$2
 
-       ${PARTED} ${DEVICE} --script -- mklabel ${LABEL} || return 1
+       wait_udev ${DEVICE} 30 || return 1
+       ${PARTED} ${DEVICE} --script -- mklabel ${LABEL} || return 2
 
        return 0
 }
@@ -534,8 +550,8 @@ udev_trigger() {
 udev_setup() {
        local SRC_PATH=$1
 
-       # When running in tree manually contruct symlinks in tree to
-       # the proper devices.  Symlinks are installed for all entires
+       # When running in tree manually construct symlinks in tree to
+       # the proper devices.  Symlinks are installed for all entries
        # in the config file regardless of if that device actually
        # exists.  When installed as a package udev can be relied on for
        # this and it will only create links for devices which exist.
@@ -744,3 +760,9 @@ stack_check() {
                fi
        fi
 }
+
+kill_zed() {
+        if [ -f $ZED_PIDFILE ]; then
+               kill $(cat $ZED_PIDFILE)
+        fi
+}