X-Git-Url: https://git.camperquake.de/gitweb.cgi?a=blobdiff_plain;f=scripts%2Fcommon.sh.in;h=c6d98f66bc0611a354598bccb76bb3d66bc5cc00;hb=ff5b1c8065c8a43add534892172f0aa5aba90f3d;hp=cf558594502daf67ce5b5cbf4b2714b66bf9d6b4;hpb=fa417e57a68b7aa026ec5fd8c0471b6c60ca109f;p=zfs.git diff --git a/scripts/common.sh.in b/scripts/common.sh.in index cf55859..c6d98f6 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,46 @@ skip() { echo -e "${COLOR_BROWN}Skip${COLOR_RESET}" } +populate() { + local ROOT=$1 + local MAX_DIR_SIZE=$2 + local MAX_FILE_SIZE=$3 + + mkdir -p $ROOT/{a,b,c,d,e,f,g}/{h,i} + DIRS=`find $ROOT` + + for DIR in $DIRS; do + COUNT=$(($RANDOM % $MAX_DIR_SIZE)) + + for i in `seq $COUNT`; do + FILE=`mktemp -p ${DIR}` + SIZE=$(($RANDOM % $MAX_FILE_SIZE)) + dd if=/dev/urandom of=$FILE bs=1k count=$SIZE &>/dev/null + done + done + + return 0 +} + +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` + trap "rm -Rf $SRC_DIR" INT TERM EXIT + 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' '` @@ -247,7 +290,7 @@ check_loop_utils() { # Find and return an unused loopback device. # unused_loop_device() { - for DEVICE in `ls -1 /dev/loop* 2>/dev/null`; do + for DEVICE in `ls -1 /dev/loop[0-9]* 2>/dev/null`; do ${LOSETUP} ${DEVICE} &>/dev/null if [ $? -ne 0 ]; then echo ${DEVICE} @@ -292,6 +335,48 @@ 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 + + # Force 4K blocksize, else mkfs.ext2 tries to use 8K, which + # won't mount + /sbin/mkfs.${FSTYPE} -b 4096 -F -q ${DEVICE} >/dev/null || return 1 + + return 0 +} + +# # Check that the mdadm utilities are installed. # check_md_utils() { @@ -635,3 +720,29 @@ wait_udev() { return 0 } + +stack_clear() { + local STACK_MAX_SIZE=/sys/kernel/debug/tracing/stack_max_size + local STACK_TRACER_ENABLED=/proc/sys/kernel/stack_tracer_enabled + + if [ -e $STACK_MAX_SIZE ]; then + echo 1 >$STACK_TRACER_ENABLED + echo 0 >$STACK_MAX_SIZE + fi +} + +stack_check() { + local STACK_MAX_SIZE=/sys/kernel/debug/tracing/stack_max_size + local STACK_TRACE=/sys/kernel/debug/tracing/stack_trace + local STACK_LIMIT=7000 + + if [ -e $STACK_MAX_SIZE ]; then + STACK_SIZE=`cat $STACK_MAX_SIZE` + + if [ $STACK_SIZE -ge $STACK_LIMIT ]; then + echo + echo "Warning: max stack size $STACK_SIZE bytes" + cat $STACK_TRACE + fi + fi +}