# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
# Copyright 2016 Nexenta Systems, Inc.
# Copyright (c) 2017 Lawrence Livermore National Security, LLC.
+# Copyright (c) 2017 Datto Inc.
#
. ${STF_TOOLS}/include/logapi.shlib
set_partition $i "" 0mb $diskname
done
fi
+
+ return 0
}
#
if poolexists "$pool" ; then
mtpt=$(get_prop mountpoint "$pool")
- # At times, syseventd activity can cause attempts to
- # destroy a pool to fail with EBUSY. We retry a few
+ # At times, syseventd/udev activity can cause attempts
+ # to destroy a pool to fail with EBUSY. We retry a few
# times allowing failures before requiring the destroy
# to succeed.
- typeset -i wait_time=10 ret=1 count=0
- must=""
- while [[ $ret -ne 0 ]]; do
- $must zpool destroy -f $pool
- ret=$?
- [[ $ret -eq 0 ]] && break
- log_note "zpool destroy failed with $ret"
- [[ count++ -ge 7 ]] && must=log_must
- sleep $wait_time
- done
+ log_must_busy zpool destroy -f $pool
[[ -d $mtpt ]] && \
log_must rm -rf $mtpt
echo $(get_prop mountpoint $fs)/.zfs/snapshot/$snap
}
+#
+# Given a device and 'ashift' value verify it's correctly set on every label
+#
+function verify_ashift # device ashift
+{
+ typeset device="$1"
+ typeset ashift="$2"
+
+ zdb -e -lll $device | awk -v ashift=$ashift '/ashift: / {
+ if (ashift != $2)
+ exit 1;
+ else
+ count++;
+ } END {
+ if (count != 4)
+ exit 1;
+ else
+ exit 0;
+ }'
+
+ return $?
+}
+
#
# Given a pool and file system, this function will verify the file system
# using the zdb internal tool. Note that the pool is exported and imported
}
#
-# Synchronize all the data in pool
+# Sync data to the pool
#
# $1 pool name
+# $2 boolean to force uberblock (and config including zpool cache file) update
#
-function sync_pool #pool
+function sync_pool #pool <force>
{
typeset pool=${1:-$TESTPOOL}
+ typeset force=${2:-false}
- log_must $SYNC
- log_must sleep 2
- # Flush all the pool data.
- typeset -i ret
- zpool scrub $pool >/dev/null 2>&1
- ret=$?
- (( $ret != 0 )) && \
- log_fail "zpool scrub $pool failed."
-
- while ! is_pool_scrubbed $pool; do
- if is_pool_resilvered $pool ; then
- log_fail "$pool should not be resilver completed."
- fi
- log_must sleep 2
- done
+ if [[ $force == true ]]; then
+ log_must zpool sync -f $pool
+ else
+ log_must zpool sync $pool
+ fi
+
+ return 0
}
#
done
}
+#
+# Wait for every device replace operation to complete
+#
+# $1 pool name
+#
+function wait_replacing #pool
+{
+ typeset pool=${1:-$TESTPOOL}
+ while true; do
+ [[ "" == "$(zpool status $pool |
+ awk '/replacing-[0-9]+/ {print $1}')" ]] && break
+ log_must sleep 1
+ done
+}
+
+#
+# Setup custom environment for the ZED.
+#
+function zed_setup
+{
+ if ! is_linux; then
+ return
+ fi
+
+ if [[ ! -d $ZEDLET_DIR ]]; then
+ log_must mkdir $ZEDLET_DIR
+ fi
+
+ if [[ ! -e $VDEVID_CONF ]]; then
+ log_must touch $VDEVID_CONF
+ fi
+
+ if [[ -e $VDEVID_CONF_ETC ]]; then
+ log_fail "Must not have $VDEVID_CONF_ETC file present on system"
+ fi
+
+ # Create a symlink for /etc/zfs/vdev_id.conf file.
+ log_must ln -s $VDEVID_CONF $VDEVID_CONF_ETC
+
+ # Setup minimal ZED configuration. Individual test cases should
+ # add additional ZEDLETs as needed for their specific test.
+ log_must cp ${ZEDLET_ETC_DIR}/zed.rc $ZEDLET_DIR
+ log_must cp ${ZEDLET_ETC_DIR}/zed-functions.sh $ZEDLET_DIR
+
+ # Customize the zed.rc file to enable the full debug log.
+ log_must sed -i '/\#ZED_DEBUG_LOG=.*/d' $ZEDLET_DIR/zed.rc
+ echo "ZED_DEBUG_LOG=$ZEDLET_DIR/zed.debug.log" >>$ZEDLET_DIR/zed.rc
+
+ log_must cp ${ZEDLET_LIBEXEC_DIR}/all-syslog.sh $ZEDLET_DIR
+ log_must cp ${ZEDLET_LIBEXEC_DIR}/all-debug.sh $ZEDLET_DIR
+ log_must touch $ZEDLET_DIR/zed.debug.log
+}
+
+#
+# Cleanup custom ZED environment.
+#
+function zed_cleanup
+{
+ if ! is_linux; then
+ return
+ fi
+
+ log_must rm -f ${ZEDLET_DIR}/zed.rc
+ log_must rm -f ${ZEDLET_DIR}/zed-functions.sh
+ log_must rm -f ${ZEDLET_DIR}/all-syslog.sh
+ log_must rm -f ${ZEDLET_DIR}/all-debug.sh
+ log_must rm -f ${ZEDLET_DIR}/zed.pid
+ log_must rm -f ${ZEDLET_DIR}/zedlog
+ log_must rm -f ${ZEDLET_DIR}/zed.debug.log
+ log_must rm -f ${ZEDLET_DIR}/state
+ log_must rm -f $VDEVID_CONF_ETC
+ log_must rm -f $VDEVID_CONF
+ rmdir $ZEDLET_DIR
+}
+
#
# Check if ZED is currently running, if not start ZED.
#
function zed_start
{
- if is_linux; then
- # ZEDLET_DIR=/var/tmp/zed
- if [[ ! -d $ZEDLET_DIR ]]; then
- log_must mkdir $ZEDLET_DIR
- fi
-
- # Verify the ZED is not already running.
- pgrep -x zed > /dev/null
- if (($? == 0)); then
- log_fail "ZED already running"
- fi
+ if ! is_linux; then
+ return
+ fi
- # ZEDLETDIR=</etc/zfs/zed.d | ${SRCDIR}/cmd/zed/zed.d>
- log_must cp ${ZEDLETDIR}/all-syslog.sh $ZEDLET_DIR
+ # ZEDLET_DIR=/var/tmp/zed
+ if [[ ! -d $ZEDLET_DIR ]]; then
+ log_must mkdir $ZEDLET_DIR
+ fi
- log_note "Starting ZED"
- # run ZED in the background and redirect foreground logging
- # output to zedlog
- log_must eval "zed -vF -d $ZEDLET_DIR -p $ZEDLET_DIR/zed.pid" \
- "-s $ZEDLET_DIR/state 2>${ZEDLET_DIR}/zedlog &"
+ # Verify the ZED is not already running.
+ pgrep -x zed > /dev/null
+ if (($? == 0)); then
+ log_fail "ZED already running"
fi
+
+ log_note "Starting ZED"
+ # run ZED in the background and redirect foreground logging
+ # output to zedlog
+ log_must eval "zed -vF -d $ZEDLET_DIR -p $ZEDLET_DIR/zed.pid" \
+ "-s $ZEDLET_DIR/state 2>${ZEDLET_DIR}/zedlog &"
+
+ return 0
}
#
#
function zed_stop
{
+ if ! is_linux; then
+ return
+ fi
+
+ log_note "Stopping ZED"
+ if [[ -f ${ZEDLET_DIR}/zed.pid ]]; then
+ zedpid=$(cat ${ZEDLET_DIR}/zed.pid)
+ log_must kill $zedpid
+ fi
+
+ return 0
+}
+
+#
+# Check is provided device is being active used as a swap device.
+#
+function is_swap_inuse
+{
+ typeset device=$1
+
+ if [[ -z $device ]] ; then
+ log_note "No device specified."
+ return 1
+ fi
+
+ if is_linux; then
+ swapon -s | grep -w $(readlink -f $device) > /dev/null 2>&1
+ else
+ swap -l | grep -w $device > /dev/null 2>&1
+ fi
+
+ return $?
+}
+
+#
+# Setup a swap device using the provided device.
+#
+function swap_setup
+{
+ typeset swapdev=$1
+
if is_linux; then
- if [[ -f ${ZEDLET_DIR}/zed.pid ]]; then
- zedpid=$(cat ${ZEDLET_DIR}/zed.pid)
- log_must kill $zedpid
+ log_must mkswap $swapdev > /dev/null 2>&1
+ log_must swapon $swapdev
+ else
+ log_must swap -a $swapdev
+ fi
+
+ return 0
+}
+
+#
+# Cleanup a swap device on the provided device.
+#
+function swap_cleanup
+{
+ typeset swapdev=$1
+
+ if is_swap_inuse $swapdev; then
+ if is_linux; then
+ log_must swapoff $swapdev
+ else
+ log_must swap -d $swapdev
fi
- log_must rm -f ${ZEDLET_DIR}/all-syslog.sh
- log_must rm -f ${ZEDLET_DIR}/zed.pid
- log_must rm -f ${ZEDLET_DIR}/zedlog
- log_must rm -f ${ZEDLET_DIR}/state
- log_must rmdir $ZEDLET_DIR
fi
+
+ return 0
}