X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=scripts%2Fcommon.sh.in;h=71a6b18a06f7401cefc2a57353a4253e66a4e63b;hb=ebe7e575eae1e03b1faa545a424f008faeac589d;hp=51671ebc019314bae11f39022f2745479ad3f427;hpb=10715a018760e1d862b8348e31dc505e832a0904;p=zfs.git diff --git a/scripts/common.sh.in b/scripts/common.sh.in index 51671eb..71a6b18 100644 --- a/scripts/common.sh.in +++ b/scripts/common.sh.in @@ -36,6 +36,9 @@ libexecdir=@libexecdir@ pkglibexecdir=${libexecdir}/@PACKAGE@ bindir=@bindir@ sbindir=@sbindir@ +udevdir=@udevdir@ +udevruledir=@udevruledir@ +sysconfdir=@sysconfdir@ ETCDIR=${ETCDIR:-/etc} DEVDIR=${DEVDIR:-/dev/disk/zpool} @@ -113,6 +116,19 @@ skip() { echo -e "${COLOR_BROWN}Skip${COLOR_RESET}" } +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}; exit $?" INT TERM EXIT + mv ${RULE} ${RULE}.disabled + fi +} + spl_dump_log() { ${SYSCTL} -w kernel.spl.debug.dump=1 &>/dev/null local NAME=`dmesg | tail -n 1 | cut -f5 -d' '` @@ -292,6 +308,46 @@ destroy_loop_devices() { } # +# Create a device label. +# +label() { + local DEVICE=$1 + local LABEL=$2 + + ${PARTED} ${DEVICE} --script -- mklabel ${LABEL} || return 1 + + return 0 +} + +# +# Create a primary partition on a block device. +# +partition() { + local DEVICE=$1 + local TYPE=$2 + local START=$3 + local END=$4 + + ${PARTED} --align optimal ${DEVICE} --script -- \ + mkpart ${TYPE} ${START} ${END} || return 1 + udev_trigger + + return 0 +} + +# +# Create a filesystem on the block device +# +format() { + local DEVICE=$1 + local FSTYPE=$2 + + /sbin/mkfs.${FSTYPE} -q ${DEVICE} || return 1 + + return 0 +} + +# # Check that the mdadm utilities are installed. # check_md_utils() {