2009-01-16 20:06:25 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
2009-08-18 04:35:06 +00:00
|
|
|
# Common support functions for testing scripts. If a .script-config
|
|
|
|
# files is available it will be sourced so in-tree kernel modules and
|
|
|
|
# utilities will be used. If no .script-config can be found then the
|
|
|
|
# installed kernel modules and utilities will be used.
|
|
|
|
|
2010-03-09 22:50:15 +00:00
|
|
|
basedir="$(dirname $0)"
|
|
|
|
|
2009-08-18 04:35:06 +00:00
|
|
|
SCRIPT_CONFIG=.script-config
|
2010-03-09 22:50:15 +00:00
|
|
|
if [ -f "${basedir}/../${SCRIPT_CONFIG}" ]; then
|
|
|
|
. "${basedir}/../${SCRIPT_CONFIG}"
|
2009-08-18 04:35:06 +00:00
|
|
|
else
|
|
|
|
MODULES=(zlib_deflate spl zavl znvpair zunicode zcommon zfs)
|
2009-01-16 21:25:47 +00:00
|
|
|
fi
|
|
|
|
|
2009-01-16 20:06:25 +00:00
|
|
|
PROG="<define PROG>"
|
|
|
|
VERBOSE=
|
2009-01-16 21:25:47 +00:00
|
|
|
VERBOSE_FLAG=
|
2009-10-21 18:38:51 +00:00
|
|
|
FORCE=
|
|
|
|
FORCE_FLAG=
|
2009-01-16 20:06:25 +00:00
|
|
|
DUMP_LOG=
|
|
|
|
ERROR=
|
2009-10-21 18:38:51 +00:00
|
|
|
RAID0S=()
|
|
|
|
RAID10S=()
|
|
|
|
RAIDZS=()
|
|
|
|
RAIDZ2S=()
|
2009-01-16 20:06:25 +00:00
|
|
|
|
2010-03-02 00:45:31 +00:00
|
|
|
ETCDIR=${ETCDIR:-/etc}
|
2010-03-11 21:56:20 +00:00
|
|
|
DEVDIR=${DEVDIR:-/dev/disk/zpool}
|
2009-08-18 04:35:06 +00:00
|
|
|
ZPOOLDIR=${ZPOOLDIR:-/usr/libexec/zfs/zpool-config}
|
2009-08-18 04:50:55 +00:00
|
|
|
ZPIOSDIR=${ZPIOSDIR:-/usr/libexec/zfs/zpios-test}
|
|
|
|
ZPIOSPROFILEDIR=${ZPIOSPROFILEDIR:-/usr/libexec/zfs/zpios-profile}
|
2009-08-18 04:35:06 +00:00
|
|
|
|
|
|
|
ZDB=${ZDB:-/usr/sbin/zdb}
|
|
|
|
ZFS=${ZFS:-/usr/sbin/zfs}
|
|
|
|
ZINJECT=${ZINJECT:-/usr/sbin/zinject}
|
|
|
|
ZPOOL=${ZPOOL:-/usr/sbin/zpool}
|
2010-03-02 00:45:31 +00:00
|
|
|
ZPOOL_ID=${ZPOOL_ID:-/usr/bin/zpool_id}
|
2009-08-18 04:35:06 +00:00
|
|
|
ZTEST=${ZTEST:-/usr/sbin/ztest}
|
2009-08-18 04:50:55 +00:00
|
|
|
ZPIOS=${ZPIOS:-/usr/sbin/zpios}
|
2009-08-18 04:35:06 +00:00
|
|
|
|
|
|
|
COMMON_SH=${COMMON_SH:-/usr/libexec/zfs/common.sh}
|
|
|
|
ZFS_SH=${ZFS_SH:-/usr/libexec/zfs/zfs.sh}
|
|
|
|
ZPOOL_CREATE_SH=${ZPOOL_CREATE_SH:-/usr/libexec/zfs/zpool-create.sh}
|
2009-08-18 04:50:55 +00:00
|
|
|
ZPIOS_SH=${ZPIOS_SH:-/usr/libexec/zfs/zpios.sh}
|
|
|
|
ZPIOS_SURVEY_SH=${ZPIOS_SURVEY_SH:-/usr/libexec/zfs/zpios-survey.sh}
|
2009-08-18 04:35:06 +00:00
|
|
|
|
|
|
|
LDMOD=${LDMOD:-/sbin/modprobe}
|
|
|
|
LSMOD=${LSMOD:-/sbin/lsmod}
|
|
|
|
RMMOD=${RMMOD:-/sbin/rmmod}
|
|
|
|
INFOMOD=${INFOMOD:-/sbin/modinfo}
|
|
|
|
LOSETUP=${LOSETUP:-/sbin/losetup}
|
|
|
|
SYSCTL=${SYSCTL:-/sbin/sysctl}
|
2010-01-08 18:20:03 +00:00
|
|
|
UDEVADM=${UDEVADM:-/sbin/udevadm}
|
2010-03-11 21:56:20 +00:00
|
|
|
AWK=${AWK:-/bin/awk}
|
2009-07-24 17:25:01 +00:00
|
|
|
|
2009-01-16 20:06:25 +00:00
|
|
|
die() {
|
|
|
|
echo -e "${PROG}: $1" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
msg() {
|
|
|
|
if [ ${VERBOSE} ]; then
|
|
|
|
echo "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2009-10-01 23:55:34 +00:00
|
|
|
pass() {
|
|
|
|
echo "PASS"
|
|
|
|
}
|
|
|
|
|
|
|
|
fail() {
|
|
|
|
echo "FAIL ($1)"
|
|
|
|
exit $1
|
|
|
|
}
|
|
|
|
|
2009-01-16 20:06:25 +00:00
|
|
|
spl_dump_log() {
|
2009-10-21 18:38:51 +00:00
|
|
|
${SYSCTL} -w kernel.spl.debug.dump=1 &>/dev/null
|
2009-01-16 20:06:25 +00:00
|
|
|
local NAME=`dmesg | tail -n 1 | cut -f5 -d' '`
|
2009-10-21 18:38:51 +00:00
|
|
|
${SPLBUILD}/cmd/spl ${NAME} >${NAME}.log
|
2009-01-16 20:06:25 +00:00
|
|
|
echo
|
2009-10-21 18:38:51 +00:00
|
|
|
echo "Dumped debug log: ${NAME}.log"
|
|
|
|
tail -n1 ${NAME}.log
|
2009-01-16 20:06:25 +00:00
|
|
|
echo
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
check_modules() {
|
|
|
|
local LOADED_MODULES=()
|
|
|
|
local MISSING_MODULES=()
|
|
|
|
|
|
|
|
for MOD in ${MODULES[*]}; do
|
|
|
|
local NAME=`basename $MOD .ko`
|
|
|
|
|
2009-08-18 04:35:06 +00:00
|
|
|
if ${LSMOD} | egrep -q "^${NAME}"; then
|
2009-01-16 20:06:25 +00:00
|
|
|
LOADED_MODULES=(${NAME} ${LOADED_MODULES[*]})
|
|
|
|
fi
|
|
|
|
|
2009-08-18 04:35:06 +00:00
|
|
|
if [ ${INFOMOD} ${MOD} 2>/dev/null ]; then
|
2009-01-16 20:06:25 +00:00
|
|
|
MISSING_MODULES=("\t${MOD}\n" ${MISSING_MODULES[*]})
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ ${#LOADED_MODULES[*]} -gt 0 ]; then
|
|
|
|
ERROR="Unload these modules with '${PROG} -u':\n"
|
|
|
|
ERROR="${ERROR}${LOADED_MODULES[*]}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${#MISSING_MODULES[*]} -gt 0 ]; then
|
|
|
|
ERROR="The following modules can not be found,"
|
|
|
|
ERROR="${ERROR} ensure your source trees are built:\n"
|
|
|
|
ERROR="${ERROR}${MISSING_MODULES[*]}"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
load_module() {
|
|
|
|
local NAME=`basename $1 .ko`
|
|
|
|
|
|
|
|
if [ ${VERBOSE} ]; then
|
2009-08-18 04:35:06 +00:00
|
|
|
echo "Loading ${NAME} ($@)"
|
2009-01-16 20:06:25 +00:00
|
|
|
fi
|
|
|
|
|
2009-08-18 04:35:06 +00:00
|
|
|
${LDMOD} $* || ERROR="Failed to load $1" return 1
|
2009-01-16 20:06:25 +00:00
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
load_modules() {
|
2009-10-01 23:55:34 +00:00
|
|
|
mkdir -p /etc/zfs
|
2009-01-16 20:06:25 +00:00
|
|
|
|
|
|
|
for MOD in ${MODULES[*]}; do
|
|
|
|
local NAME=`basename ${MOD} .ko`
|
|
|
|
local VALUE=
|
|
|
|
|
|
|
|
for OPT in "$@"; do
|
|
|
|
OPT_NAME=`echo ${OPT} | cut -f1 -d'='`
|
|
|
|
|
|
|
|
if [ ${NAME} = "${OPT_NAME}" ]; then
|
|
|
|
VALUE=`echo ${OPT} | cut -f2- -d'='`
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
load_module ${MOD} ${VALUE} || return 1
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ ${VERBOSE} ]; then
|
|
|
|
echo "Successfully loaded ZFS module stack"
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
unload_module() {
|
|
|
|
local NAME=`basename $1 .ko`
|
|
|
|
|
|
|
|
if [ ${VERBOSE} ]; then
|
2009-08-18 04:35:06 +00:00
|
|
|
echo "Unloading ${NAME} ($@)"
|
2009-01-16 20:06:25 +00:00
|
|
|
fi
|
|
|
|
|
2009-08-18 04:35:06 +00:00
|
|
|
${RMMOD} ${NAME} || ERROR="Failed to unload ${NAME}" return 1
|
2009-01-16 20:06:25 +00:00
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
unload_modules() {
|
|
|
|
local MODULES_REVERSE=( $(echo ${MODULES[@]} |
|
2010-03-11 21:56:20 +00:00
|
|
|
${AWK} '{for (i=NF;i>=1;i--) printf $i" "} END{print ""}') )
|
2009-01-16 20:06:25 +00:00
|
|
|
|
|
|
|
for MOD in ${MODULES_REVERSE[*]}; do
|
|
|
|
local NAME=`basename ${MOD} .ko`
|
|
|
|
|
2009-08-18 04:35:06 +00:00
|
|
|
if ${LSMOD} | egrep -q "^${NAME}"; then
|
2009-01-16 20:06:25 +00:00
|
|
|
|
|
|
|
if [ "${DUMP_LOG}" -a ${NAME} = "spl" ]; then
|
|
|
|
spl_dump_log
|
|
|
|
fi
|
|
|
|
|
|
|
|
unload_module ${MOD} || return 1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ ${VERBOSE} ]; then
|
|
|
|
echo "Successfully unloaded ZFS module stack"
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
2009-07-21 23:17:54 +00:00
|
|
|
|
|
|
|
unused_loop_device() {
|
|
|
|
for DEVICE in `ls -1 /dev/loop*`; do
|
2009-07-24 17:25:01 +00:00
|
|
|
${LOSETUP} ${DEVICE} &>/dev/null
|
2009-07-21 23:17:54 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2009-07-24 17:25:01 +00:00
|
|
|
echo ${DEVICE}
|
2009-07-21 23:17:54 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
die "Error: Unable to find unused loopback device"
|
|
|
|
}
|
2009-10-21 18:38:51 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# The following udev helper functions assume that the provided
|
|
|
|
# udev rules file will create a /dev/disk/zpool/<CHANNEL><RANK>
|
|
|
|
# disk mapping. In this mapping each CHANNEL is represented by
|
|
|
|
# the letters a-z, and the RANK is represented by the numbers
|
|
|
|
# 1-n. A CHANNEL should identify a group of RANKS which are all
|
|
|
|
# attached to a single controller, each RANK represents a disk.
|
|
|
|
# This provides a simply mechanism to locate a specific drive
|
|
|
|
# given a known hardware configuration.
|
|
|
|
#
|
|
|
|
udev_setup() {
|
|
|
|
local SRC_PATH=$1
|
2010-03-02 00:45:31 +00:00
|
|
|
|
2010-03-11 21:56:20 +00:00
|
|
|
# When running in tree manually contruct symlinks in tree to
|
|
|
|
# the proper devices. Symlinks are installed for all entires
|
|
|
|
# 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.
|
|
|
|
if [ ${INTREE} ]; then
|
|
|
|
PWD=`pwd`
|
|
|
|
mkdir -p ${DEVDIR}/
|
|
|
|
cd ${DEVDIR}/
|
|
|
|
${AWK} '!/^#/ && /./ { system( \
|
|
|
|
"ln -f -s /dev/disk/by-path/"$2" "$1";" \
|
|
|
|
"ln -f -s /dev/disk/by-path/"$2"-part1 "$1"p1;" \
|
|
|
|
"ln -f -s /dev/disk/by-path/"$2"-part9 "$1"p9;" \
|
|
|
|
) }' $SRC_PATH
|
|
|
|
cd ${PWD}
|
|
|
|
else
|
|
|
|
DST_FILE=`basename ${SRC_PATH} | cut -f1-2 -d'.'`
|
|
|
|
DST_PATH=/etc/zfs/${DST_FILE}
|
|
|
|
|
|
|
|
if [ -e ${DST_PATH} ]; then
|
|
|
|
die "Error: Config ${DST_PATH} already exists"
|
|
|
|
fi
|
|
|
|
|
|
|
|
cp ${SRC_PATH} ${DST_PATH}
|
|
|
|
|
|
|
|
if [ -f ${UDEVADM} ]; then
|
|
|
|
${UDEVADM} trigger
|
|
|
|
${UDEVADM} settle
|
|
|
|
else
|
|
|
|
/sbin/udevtrigger
|
|
|
|
/sbin/udevsettle
|
|
|
|
fi
|
2010-03-02 00:45:31 +00:00
|
|
|
fi
|
|
|
|
|
2010-03-11 21:56:20 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
udev_cleanup() {
|
|
|
|
local SRC_PATH=$1
|
2010-03-02 00:45:31 +00:00
|
|
|
|
2010-03-11 21:56:20 +00:00
|
|
|
if [ ${INTREE} ]; then
|
|
|
|
PWD=`pwd`
|
|
|
|
cd ${DEVDIR}/
|
|
|
|
${AWK} '!/^#/ && /./ { system( \
|
|
|
|
"rm -f "$1" "$1"p1 "$1"p9") }' $SRC_PATH
|
|
|
|
cd ${PWD}
|
2010-01-08 18:20:03 +00:00
|
|
|
fi
|
2009-10-21 18:38:51 +00:00
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
udev_cr2d() {
|
|
|
|
local CHANNEL=`echo "obase=16; $1+96" | bc`
|
|
|
|
local RANK=$2
|
|
|
|
|
|
|
|
printf "\x${CHANNEL}${RANK}"
|
|
|
|
}
|
|
|
|
|
|
|
|
udev_raid0_setup() {
|
|
|
|
local RANKS=$1
|
|
|
|
local CHANNELS=$2
|
|
|
|
local IDX=0
|
|
|
|
|
|
|
|
RAID0S=()
|
|
|
|
for RANK in `seq 1 ${RANKS}`; do
|
|
|
|
for CHANNEL in `seq 1 ${CHANNELS}`; do
|
|
|
|
DISK=`udev_cr2d ${CHANNEL} ${RANK}`
|
2010-03-11 21:56:20 +00:00
|
|
|
RAID0S[${IDX}]="${DEVDIR}/${DISK}"
|
2009-10-21 18:38:51 +00:00
|
|
|
let IDX=IDX+1
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
udev_raid10_setup() {
|
|
|
|
local RANKS=$1
|
|
|
|
local CHANNELS=$2
|
|
|
|
local IDX=0
|
|
|
|
|
|
|
|
RAID10S=()
|
|
|
|
for RANK in `seq 1 ${RANKS}`; do
|
|
|
|
for CHANNEL1 in `seq 1 2 ${CHANNELS}`; do
|
|
|
|
let CHANNEL2=CHANNEL1+1
|
|
|
|
DISK1=`udev_cr2d ${CHANNEL1} ${RANK}`
|
|
|
|
DISK2=`udev_cr2d ${CHANNEL2} ${RANK}`
|
2010-03-11 21:56:20 +00:00
|
|
|
GROUP="${DEVDIR}/${DISK1} ${DEVDIR}/${DISK2}"
|
2009-10-21 18:38:51 +00:00
|
|
|
RAID10S[${IDX}]="mirror ${GROUP}"
|
|
|
|
let IDX=IDX+1
|
|
|
|
done
|
|
|
|
done
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
udev_raidz_setup() {
|
|
|
|
local RANKS=$1
|
|
|
|
local CHANNELS=$2
|
|
|
|
|
|
|
|
RAIDZS=()
|
|
|
|
for RANK in `seq 1 ${RANKS}`; do
|
|
|
|
RAIDZ=("raidz")
|
|
|
|
|
|
|
|
for CHANNEL in `seq 1 ${CHANNELS}`; do
|
|
|
|
DISK=`udev_cr2d ${CHANNEL} ${RANK}`
|
2010-03-11 21:56:20 +00:00
|
|
|
RAIDZ[${CHANNEL}]="${DEVDIR}/${DISK}"
|
2009-10-21 18:38:51 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
RAIDZS[${RANK}]="${RAIDZ[*]}"
|
|
|
|
done
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
udev_raidz2_setup() {
|
|
|
|
local RANKS=$1
|
|
|
|
local CHANNELS=$2
|
|
|
|
|
|
|
|
RAIDZ2S=()
|
|
|
|
for RANK in `seq 1 ${RANKS}`; do
|
|
|
|
RAIDZ2=("raidz2")
|
|
|
|
|
|
|
|
for CHANNEL in `seq 1 ${CHANNELS}`; do
|
|
|
|
DISK=`udev_cr2d ${CHANNEL} ${RANK}`
|
2010-03-11 21:56:20 +00:00
|
|
|
RAIDZ2[${CHANNEL}]="${DEVDIR}/${DISK}"
|
2009-10-21 18:38:51 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
RAIDZ2S[${RANK}]="${RAIDZ2[*]}"
|
|
|
|
done
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|