fi
zpool get name "$pool" > /dev/null 2>&1
- return $?
}
# Return 0 if all the specified datasets exist; $? otherwise
return 1
fi
- while (($# > 0)); do
- zfs get name $1 > /dev/null 2>&1 || \
- return $?
- shift
- done
-
- return 0
+ zfs get name "$@" > /dev/null 2>&1
}
# return 0 if none of the specified datasets exists, otherwise return 1.
# $2 - custom arguments for zfs destroy
# Destroy dataset with the given parameters.
-function destroy_dataset #dataset #args
+function destroy_dataset # dataset [args]
{
typeset dataset=$1
typeset mtpt
mtpt=$(get_prop mountpoint "$dataset")
log_must_busy zfs destroy $args $dataset
- [[ -d $mtpt ]] && \
- log_must rm -rf $mtpt
+ [ -d $mtpt ] && log_must rm -rf $mtpt
else
log_note "Dataset does not exist. ($dataset)"
return 1
log_mustnot zpool import -d $DEVICE_DIR $TESTPOOL1
# error message should not mention "readonly"
-log_mustnot eval "zpool import -d $DEVICE_DIR $TESTPOOL1 | grep readonly"
+log_mustnot eval "zpool import -d $DEVICE_DIR $TESTPOOL1 | grep -q readonly"
log_mustnot poolexists $TESTPOOL1
for feature in $active_features; do
log_must eval "zpool import -d $DEVICE_DIR $TESTPOOL1 \
- | grep $feature"
+ | grep -q $feature"
log_mustnot poolexists $TESTPOOL1
done
for feature in $enabled_features; do
log_mustnot eval "zpool import -d $DEVICE_DIR $TESTPOOL1 \
- | grep $feature"
+ | grep -q $feature"
log_mustnot poolexists $TESTPOOL1
done
function get_conf_section # regex conf
{
- typeset dsk_line next_vd_line conf section
typeset regex="$1"
typeset conf="$2"
- dsk_line=$(grep -n "$regex" "$conf" | awk -F: '{print $1}')
- if [[ -z "$dsk_line" ]]; then
- return
- fi
- next_vd_line=$(tail -n +$dsk_line "$conf" | \
- grep -n "children\[" | awk -F: '{print $1}' | head -n 1)
-
- if [[ -n "$next_vd_line" ]]; then
- section=$(cat "$conf" | sed "1,${dsk_line}d" | head -n \
- $(($next_vd_line - 2)))
-
- else
- section=$(tail -n +$dsk_line "$conf")
- fi
- echo "$section"
+ awk -v r="$1" '$0 ~ r, 0 {if($0 ~ r) next; if(/children\[/) exit; print}' "$conf"
}
function get_leaf_vd_zap # dsk conf
{
- typeset section=$(get_conf_section "$1" "$2")
- echo "$section" | egrep \
- "com.delphix:vdev_zap_leaf: [0-9]+" | awk '{print $2}'
+ get_conf_section "$1" "$2" | awk '/com.delphix:vdev_zap_leaf: [0-9]+/ {print $2}'
}
function get_top_vd_zap # dsk conf
{
- typeset section=$(get_conf_section "$1" "$2")
- echo "$section" | egrep \
- "com.delphix:vdev_zap_top: [0-9]+" | awk '{print $2}'
+ get_conf_section "$1" "$2" | awk '/com.delphix:vdev_zap_top: [0-9]+/ {print $2}'
}
function assert_has_sentinel # conf
{
- res=$(grep "com.delphix:has_per_vdev_zaps" "$1")
- [[ -z "$res" ]] && log_fail "Pool missing ZAP feature sentinel value"
+ log_must grep -q "com.delphix:has_per_vdev_zaps" "$1"
}
function assert_zap_common # pool vd lvl zapobj
typeset lvl=$3
typeset zapobj=$4
- if [[ -z "$zapobj" ]]; then
+ if [ -z "$zapobj" ]; then
log_fail "$vd on $pool has no $lvl ZAP in config"
- elif [[ -z "$(zdb -d $pool $zapobj | grep 'zap')" ]]; then
+ elif ! zdb -d $pool $zapobj | grep -q 'zap'; then
log_fail "$vd on $pool has no $lvl ZAP in MOS"
fi
}
function cleanup
{
- if datasetexists $TESTPOOL ; then
- log_must zpool destroy -f $TESTPOOL
- fi
- if [[ -e $conf ]]; then
- log_must rm -f "$conf"
- fi
- if [[ -e $POOL2 ]]; then
- log_must zpool destroy -f $POOL2
- fi
+ datasetexists $TESTPOOL && log_must zpool destroy -f $TESTPOOL
+ [ -e $conf ] && log_must rm -f "$conf"
+ poolexists $POOL2 && log_must zpool destroy -f $POOL2
}
log_onexit cleanup