Add snapdev=[hidden|visible] dataset property
[zfs.git] / scripts / common.sh.in
index 71a6b18..c99894c 100644 (file)
@@ -41,7 +41,7 @@ udevruledir=@udevruledir@
 sysconfdir=@sysconfdir@
 
 ETCDIR=${ETCDIR:-/etc}
-DEVDIR=${DEVDIR:-/dev/disk/zpool}
+DEVDIR=${DEVDIR:-/dev/disk/by-vdev}
 ZPOOLDIR=${ZPOOLDIR:-${pkglibexecdir}/zpool-config}
 ZPIOSDIR=${ZPIOSDIR:-${pkglibexecdir}/zpios-test}
 ZPIOSPROFILEDIR=${ZPIOSPROFILEDIR:-${pkglibexecdir}/zpios-profile}
@@ -50,7 +50,6 @@ ZDB=${ZDB:-${sbindir}/zdb}
 ZFS=${ZFS:-${sbindir}/zfs}
 ZINJECT=${ZINJECT:-${sbindir}/zinject}
 ZPOOL=${ZPOOL:-${sbindir}/zpool}
-ZPOOL_ID=${ZPOOL_ID:-${bindir}/zpool_id}
 ZTEST=${ZTEST:-${sbindir}/ztest}
 ZPIOS=${ZPIOS:-${sbindir}/zpios}
 
@@ -116,6 +115,27 @@ 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.
@@ -124,9 +144,15 @@ init() {
        # 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
+               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() {
@@ -263,7 +289,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}
@@ -342,7 +368,9 @@ format() {
        local DEVICE=$1
        local FSTYPE=$2
 
-       /sbin/mkfs.${FSTYPE} -q ${DEVICE} || return 1
+       # 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
 }
@@ -496,7 +524,7 @@ udev_trigger() {
 
 #
 # The following udev helper functions assume that the provided
-# udev rules file will create a /dev/disk/zpool/<CHANNEL><RANK>
+# udev rules file will create a /dev/disk/by-vdev/<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