tests: review every awk(1) invocation

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #13259
This commit is contained in:
наб 2022-03-11 23:54:08 +01:00 committed by Brian Behlendorf
parent 72f3516094
commit 75746e9a40
132 changed files with 402 additions and 762 deletions

View File

@ -156,12 +156,11 @@ main(int argc, const char * const argv[])
(void) close(fd);
char buffer[BUFFER_SIZE];
memset(buffer, 0, BUFFER_SIZE);
char buffer[BUFFER_SIZE] = "";
(void) attribute_to_str(dosflags, buffer);
(void) printf("%s\n", buffer);
(void) puts(buffer);
return (EXIT_SUCCESS);
}

View File

@ -223,13 +223,11 @@ function set_slice_prefix
if is_linux; then
while (( i < $DISK_ARRAY_NUM )); do
disk="$(echo $DISKS | nawk '{print $(i + 1)}')"
if ( is_mpath_device $disk ) && [[ -z $(echo $disk | awk 'substr($1,18,1)\
~ /^[[:digit:]]+$/') ]] || ( is_real_device $disk ); then
disk="$(echo $DISKS | awk '{print $(i + 1)}')"
if is_mpath_device $disk && ! echo $disk | awk 'substr($1,18,1) ~ /^[[:digit:]]+$/ {exit 1}' || is_real_device $disk; then
export SLICE_PREFIX=""
return 0
elif ( is_mpath_device $disk || is_loop_device \
$disk ); then
elif is_mpath_device $disk || is_loop_device $disk; then
export SLICE_PREFIX="p"
return 0
else
@ -518,11 +516,11 @@ function get_pool_devices #testpool #devdir
typeset devdir=$2
typeset out=""
if is_linux || is_freebsd; then
out=$(zpool status -P $testpool |grep ${devdir} | awk '{print $1}')
out=$(echo $out | sed -e "s|${devdir}/||g" | tr '\n' ' ')
fi
echo $out
case $(uname) in
Linux|FreeBSD)
zpool status -P $testpool | awk -v d="$devdir" '$1 ~ d {sub(d "/", ""); printf("%s ", $1)}'
;;
esac
}
#

View File

@ -149,14 +149,11 @@ function ismounted
case $fstype in
zfs)
if [[ "$1" == "/"* ]] ; then
for out in $(zfs mount | awk '{print $2}'); do
[[ $1 == $out ]] && return 0
done
! zfs mount | awk -v fs="$1" '$2 == fs {exit 1}'
else
for out in $(zfs mount | awk '{print $1}'); do
[[ $1 == $out ]] && return 0
done
! zfs mount | awk -v ds="$1" '$1 == ds {exit 1}'
fi
return $?
;;
ufs|nfs)
if is_freebsd; then
@ -178,7 +175,7 @@ function ismounted
fi
;;
ext*)
out=$(df -t $fstype $1 2>/dev/null)
df -t $fstype $1 > /dev/null 2>&1
return $?
;;
zvol)
@ -608,10 +605,8 @@ function default_cleanup_noexit
log_must zfs set reservation=none $fs
log_must zfs set recordsize=128K $fs
log_must zfs set mountpoint=/$fs $fs
typeset enc=""
enc=$(get_prop encryption $fs)
if [[ $? -ne 0 ]] || [[ -z "$enc" ]] || \
[[ "$enc" == "off" ]]; then
typeset enc=$(get_prop encryption $fs)
if [ -z "$enc" ] || [ "$enc" = "off" ]; then
log_must zfs set checksum=on $fs
fi
log_must zfs set compression=off $fs
@ -684,8 +679,6 @@ function destroy_snapshot
typeset mtpt=""
if ismounted $snap; then
mtpt=$(get_prop mountpoint $snap)
(($? != 0)) && \
log_fail "get_prop mountpoint $snap failed."
fi
destroy_dataset "$snap"
@ -710,8 +703,6 @@ function destroy_clone
typeset mtpt=""
if ismounted $clone; then
mtpt=$(get_prop mountpoint $clone)
(($? != 0)) && \
log_fail "get_prop mountpoint $clone failed."
fi
destroy_dataset "$clone"
@ -743,7 +734,6 @@ function destroy_bookmark
function snapexists
{
zfs list -H -t snapshot "$1" > /dev/null 2>&1
return $?
}
#
@ -754,7 +744,6 @@ function snapexists
function bkmarkexists
{
zfs list -H -t bookmark "$1" > /dev/null 2>&1
return $?
}
#
@ -765,8 +754,7 @@ function bkmarkexists
#
function holdexists
{
zfs holds "$2" | awk '{ print $2 }' | grep "$1" > /dev/null 2>&1
return $?
! zfs holds "$2" | awk -v t="$1" '$2 ~ t { exit 1 }'
}
#
@ -934,9 +922,8 @@ function set_partition
# Determine the cylinder size for the device and using
# that calculate the end offset in cylinders.
typeset -i cly_size_kb=0
cly_size_kb=$(parted -m $disk -s -- \
unit cyl print | head -3 | tail -1 | \
awk -F '[:k.]' '{print $4}')
cly_size_kb=$(parted -m $disk -s -- unit cyl print |
awk -F '[:k.]' 'NR == 3 {print $4}')
((end = (size_mb * 1024 / cly_size_kb) + start))
parted $disk -s -- \
@ -1077,15 +1064,14 @@ function get_endslice #<disk> <slice>
typeset -i ratio=0
ratio=$(prtvtoc /dev/rdsk/${disk}s2 | \
grep "sectors\/cylinder" | \
awk '{print $2}')
awk '/sectors\/cylinder/ {print $2}')
if ((ratio == 0)); then
return
fi
typeset -i endcyl=$(prtvtoc -h /dev/rdsk/${disk}s2 |
nawk -v token="$slice" '{if ($1==token) print $6}')
awk -v token="$slice" '$1 == token {print $6}')
((endcyl = (endcyl + 1) / ratio))
;;
@ -1163,56 +1149,22 @@ function fill_fs # destdir dirnum filenum bytes num_writes data
return 0
}
#
# Simple function to get the specified property. If unable to
# get the property then exits.
#
# Note property is in 'parsable' format (-p)
#
# Get the specified dataset property in parsable format or fail
function get_prop # property dataset
{
typeset prop_val
typeset prop=$1
typeset dataset=$2
prop_val=$(zfs get -pH -o value $prop $dataset 2>/dev/null)
if [[ $? -ne 0 ]]; then
log_note "Unable to get $prop property for dataset " \
"$dataset"
return 1
fi
echo "$prop_val"
return 0
zfs get -Hpo value "$prop" "$dataset" || log_fail "zfs get $prop $dataset"
}
#
# Simple function to get the specified property of pool. If unable to
# get the property then exits.
#
# Note property is in 'parsable' format (-p)
#
# Get the specified pool property in parsable format or fail
function get_pool_prop # property pool
{
typeset prop_val
typeset prop=$1
typeset pool=$2
if poolexists $pool ; then
prop_val=$(zpool get -pH $prop $pool 2>/dev/null | tail -1 | \
awk '{print $3}')
if [[ $? -ne 0 ]]; then
log_note "Unable to get $prop property for pool " \
"$pool"
return 1
fi
else
log_note "Pool $pool not exists."
return 1
fi
echo "$prop_val"
return 0
zpool get -Hpo value "$prop" "$pool" || log_fail "zpool get $prop $pool"
}
# Return 0 if a pool exists; $? otherwise
@ -1988,19 +1940,16 @@ 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;
zdb -e -lll $device | awk -v ashift=$ashift '
/ashift: / {
if (ashift != $2)
exit 1;
else
count++;
}
END {
exit (count != 4);
}'
return $?
}
#
@ -2375,35 +2324,24 @@ function find_disks
swap -l > $sfi
dumpadm > $dmpi 2>/dev/null
# write an awk script that can process the output of format
# to produce a list of disks we know about. Note that we have
# to escape "$2" so that the shell doesn't interpret it while
# we're creating the awk script.
# -------------------
cat > /tmp/find_disks.awk <<EOF
#!/bin/nawk -f
BEGIN { FS="."; }
disks=${@:-$(echo "" | format -e 2>/dev/null | awk '
BEGIN { FS="."; }
/^Specify disk/{
searchdisks=0;
/^Specify disk/{
searchdisks=0;
}
{
if (searchdisks && $2 !~ "^$"){
split($2,arr," ");
print arr[1];
}
}
{
if (searchdisks && \$2 !~ "^$"){
split(\$2,arr," ");
print arr[1];
}
}
/^AVAILABLE DISK SELECTIONS:/{
searchdisks=1;
}
EOF
#---------------------
chmod 755 /tmp/find_disks.awk
disks=${@:-$(echo "" | format -e 2>/dev/null | /tmp/find_disks.awk)}
rm /tmp/find_disks.awk
/^AVAILABLE DISK SELECTIONS:/{
searchdisks=1;
}
')}
unused=""
for disk in $disks; do
@ -2801,23 +2739,21 @@ function safe_to_destroy_pool { # $1 the pool name
# this is a list of the top-level directories in each of the
# files that make up the path to the files the pool is based on
FILEPOOL=$(zpool status -v $pool | grep /$1/ | \
awk '{print $1}')
FILEPOOL=$(zpool status -v $pool | awk -v pool="/$1/" '$0 ~ pool {print $1}')
# this is a list of the zvols that make up the pool
ZVOLPOOL=$(zpool status -v $pool | grep "$ZVOL_DEVDIR/$1$" \
| awk '{print $1}')
ZVOLPOOL=$(zpool status -v $pool | awk -v zvols="$ZVOL_DEVDIR/$1$" '$0 ~ zvols {print $1}')
# also want to determine if it's a file-based pool using an
# alternate mountpoint...
POOL_FILE_DIRS=$(zpool status -v $pool | \
grep / | awk '{print $1}' | \
awk -F/ '{print $2}' | grep -v "dev")
awk '/\// {print $1}' | \
awk -F/ '!/dev/ {print $2}')
for pooldir in $POOL_FILE_DIRS
do
OUTPUT=$(zfs list -H -r -o mountpoint $1 | \
grep "${pooldir}$" | awk '{print $1}')
awk -v pd="${pooldir}$" '$0 ~ pd {print $1}')
ALTMOUNTPOOL="${ALTMOUNTPOOL}${OUTPUT}"
done
@ -2935,21 +2871,11 @@ function get_config
if ! poolexists "$pool" ; then
return 1
fi
alt_root=$(zpool list -H $pool | awk '{print $NF}')
if [[ $alt_root == "-" ]]; then
value=$(zdb -C $pool | grep "$config:" | awk -F: \
'{print $2}')
if [ "$(get_pool_prop cachefile "$pool")" = "none" ]; then
zdb -e $pool
else
value=$(zdb -e $pool | grep "$config:" | awk -F: \
'{print $2}')
fi
if [[ -n $value ]] ; then
value=${value#'}
value=${value%'}
fi
echo $value
return 0
zdb -C $pool
fi | awk -F: -v cfg="$config:" '$0 ~ cfg {sub(/^'\''/, $2); sub(/'\''$/, $2); print $2}'
}
#
@ -2967,8 +2893,7 @@ function _random_get
typeset -i ind
((ind = RANDOM % cnt + 1))
typeset ret=$(echo "$str" | cut -f $ind -d ' ')
echo $ret
echo "$str" | cut -f $ind -d ' '
}
#
@ -3031,20 +2956,7 @@ function datasetcksum
typeset cksum
sync
sync_all_pools
cksum=$(zdb -vvv $1 | grep "^Dataset $1 \[" | grep "cksum" \
| awk -F= '{print $7}')
echo $cksum
}
#
# Get cksum of file
# #1 file path
#
function checksum
{
typeset cksum
cksum=$(cksum $1 | awk '{print $1}')
echo $cksum
zdb -vvv $1 | awk -F= -v ds="^Dataset $1 "'\\[' '$0 ~ ds && /cksum/ {print $7}'
}
#
@ -3067,27 +2979,6 @@ function get_device_state #pool disk field("", "spares","logs")
echo $state
}
#
# print the given directory filesystem type
#
# $1 directory name
#
function get_fstype
{
typeset dir=$1
if [[ -z $dir ]]; then
log_fail "Usage: get_fstype <directory>"
fi
#
# $ df -n /
# / : ufs
#
df -n $dir | awk '{print $3}'
}
#
# Given a disk, label it to VTOC regardless what label was on the disk
# $1 disk
@ -3141,16 +3032,6 @@ function labelvtoc
return 0
}
#
# check if the system was installed as zfsroot or not
# return: 0 if zfsroot, non-zero if not
#
function is_zfsroot
{
df -n / | grep zfs > /dev/null 2>&1
return $?
}
#
# get the root filesystem name if it's zfsroot system.
#
@ -3162,7 +3043,7 @@ function get_rootfs
if is_freebsd; then
rootfs=$(mount -p | awk '$2 == "/" && $3 == "zfs" {print $1}')
elif ! is_linux; then
rootfs=$(awk '{if ($2 == "/" && $3 == "zfs") print $1}' \
rootfs=$(awk '$2 == "/" && $3 == "zfs" {print $1}' \
/etc/mnttab)
fi
if [[ -z "$rootfs" ]]; then
@ -3460,9 +3341,7 @@ function wait_freeing #pool
function wait_replacing #pool
{
typeset pool=${1:-$TESTPOOL}
while true; do
[[ "" == "$(zpool status $pool |
awk '/replacing-[0-9]+/ {print $1}')" ]] && break
while zpool status $pool | grep -qE 'replacing-[0-9]+'; do
log_must sleep 1
done
}
@ -3910,7 +3789,9 @@ function md5digest
md5 -q $file
;;
*)
md5sum -b $file | awk '{ print $1 }'
typeset sum _
read -r sum _ < <(md5sum -b $file)
echo $sum
;;
esac
}
@ -3928,7 +3809,9 @@ function sha256digest
sha256 -q $file
;;
*)
sha256sum -b $file | awk '{ print $1 }'
typeset sum _
read -r sum _ < <(sha256sum -b $file)
echo $sum
;;
esac
}
@ -4116,9 +3999,7 @@ function kstat # stat flags?
sysctl $flags kstat.zfs.misc.$stat
;;
Linux)
typeset zfs_kstat="/proc/spl/kstat/zfs/$stat"
[[ -f "$zfs_kstat" ]] || return 1
cat $zfs_kstat
cat "/proc/spl/kstat/zfs/$stat" 2>/dev/null
;;
*)
false
@ -4135,7 +4016,7 @@ function get_arcstat # stat
kstat arcstats.$stat
;;
Linux)
kstat arcstats | awk "/$stat/ { print \$3 }"
kstat arcstats | awk "/$stat/"' { print $3 }'
;;
*)
false

View File

@ -15,7 +15,7 @@ function test_zpool_script {
out="$($wholecmd)"
# Default number of columns that get printed without -c
if echo "$cmd" | grep -q iostat ; then
if [ "$cmd" != "${cmd/iostat/_/}" ]; then
# iostat
dcols=7
else
@ -39,9 +39,9 @@ function test_zpool_script {
# zpool iostat -v output is 7 columns, so if the script ran correctly
# we should see more than that.
if ! newcols=$(echo "$out" | \
awk '/\/dev/{print NF-'$dcols'; if (NF <= '$dcols') {exit 1}}' | \
head -n 1) ; \
then
awk '/\/dev/ {print NF-'$dcols'; if (NF <= '$dcols') {exit 1}}' | \
head -n 1)
then
log_fail "'$wholecmd' didn't create a new column value"
else
log_note "'$wholecmd' passed ($newcols new columns)"

View File

@ -185,9 +185,7 @@ function plus_sign_check_l #<obj>
return 1
fi
ls -ld $obj | awk '{print $1}' | grep "+$" > /dev/null
return $?
! ls -ld $obj | awk '$1 ~ /\+$/ {exit 1}'
}
#
@ -202,9 +200,7 @@ function plus_sign_check_v #<obj>
return 1
fi
ls -vd $obj | awk '(NR == 1) {print $1}' | grep "+$" > /dev/null
return $?
! ls -vd $obj | awk 'NR == 1 && $1 ~ /\+$ {exit 1}'
}
#
@ -216,7 +212,6 @@ function plus_sign_check_v #<obj>
function chgusr_exec #<login_name> <commands> [...]
{
chg_usr_exec $@
return $?
}
#
@ -237,7 +232,6 @@ function set_cur_usr #<login_name>
function usr_exec #<commands> [...]
{
chg_usr_exec "$ZFS_ACL_CUR_USER" $@
return $?
}
#
@ -447,12 +441,10 @@ function get_group #node
fi
if [[ -d $node ]]; then
value=$(ls -dl $node | awk '{print $4}')
ls -dl $node
elif [[ -e $node ]]; then
value=$(ls -l $node | awk '{print $4}')
fi
echo $value
ls -l $node
fi | awk '{print $4}'
}

View File

@ -55,12 +55,10 @@ function hasflag
typeset path=$2
if is_linux; then
read_dos_attributes $path | awk \
'{ gsub(",", "\n", $1); print $1 }' | grep -qxF $flag
read_dos_attributes $path
else
ls -lo $path | awk '{ gsub(",", "\n", $5); print $5 }' | \
grep -qxF $flag
fi
ls -lo $path | awk '{ print $5 }'
fi | grep -qwF $flag
}
log_assert "Verify DOS mode flags function correctly"

View File

@ -70,9 +70,8 @@ if [ "$?" -eq "0" ]; then
log_must chmod 700 $TESTDIR/dir.0
log_must setfacl -m g:$ZFS_ACL_STAFF_GROUP:rw $TESTDIR/dir.0
# Confirm permissions
ls -l $TESTDIR |grep "dir.0" |grep -q "drwxrw----+"
if [ "$?" -ne "0" ]; then
msk=$(ls -l $TESTDIR |grep "dir.0" | awk '{print $1}')
if ! ls -l $TESTDIR | grep "dir.0" | grep -q "drwxrw----+"; then
msk=$(ls -l $TESTDIR | awk '/dir.0/ {print $1}')
log_note "expected mask drwxrw----+ but found $msk"
log_fail "Expected permissions were not set."
fi

View File

@ -53,9 +53,8 @@ log_must mkdir $TESTDIR/dir.0
log_must chmod 700 $TESTDIR/dir.0
log_must setfacl -m g:$ZFS_ACL_STAFF_GROUP:wx $TESTDIR/dir.0
# Confirm permissions
ls -l $TESTDIR |grep "dir.0" |grep -q "drwx-wx---+"
if [ "$?" -ne "0" ]; then
msk=$(ls -l $TESTDIR |grep "dir.0" | awk '{print $1}')
if ! ls -l $TESTDIR | grep "dir.0" | grep -q "drwx-wx---+"; then
msk=$(ls -l $TESTDIR | awk '/dir.0/ {print $1}')
log_note "expected mask drwx-wx---+ but found $msk"
log_fail "Expected permissions were not set."
fi

View File

@ -42,7 +42,7 @@ do
log_must zpool create $TESTPOOL $type $ZPOOL_DISKS
fi
ac_value="$(zpool get -H -o property,value all | \
egrep allocation_classes | awk '{print $2}')"
awk '/allocation_classes/ {print $2}')"
if [ "$ac_value" = "enabled" ]; then
log_note "feature@allocation_classes is enabled"
else
@ -57,7 +57,7 @@ do
$CLASS_DISK0 $CLASS_DISK1
fi
ac_value="$(zpool get -H -o property,value all | \
egrep allocation_classes | awk '{print $2}')"
awk '/allocation_classes/ {print $2}')"
if [ "$ac_value" = "active" ]; then
log_note "feature@allocation_classes is active"
else

View File

@ -39,7 +39,7 @@ for value in 0 512 1024 2048 4096 8192 16384 32768 65536 131072
do
log_must zfs set special_small_blocks=$value $TESTPOOL
ACTUAL=$(zfs get -p special_small_blocks $TESTPOOL | \
grep special_small_blocks | awk '{print $3}')
awk '/special_small_blocks/ {print $3}')
if [ "$ACTUAL" != "$value" ]
then
log_fail "v. $ACTUAL set for $TESTPOOL, expected v. $value!"

View File

@ -56,8 +56,7 @@ function testdbufstat # stat_name dbufstat_filter
[[ -n "$2" ]] && filter="-F $2"
if is_linux; then
from_dbufstat=$(grep -w "$name" "$DBUFSTATS_FILE" |
awk '{ print $3 }')
read -r _ _ from_dbufstat _ < <(grep -w "$name" "$DBUFSTATS_FILE")
else
from_dbufstat=$(awk "/dbufstats\.$name:/ { print \$2 }" \
"$DBUFSTATS_FILE")

View File

@ -74,7 +74,7 @@ do
log_must zfs create $POOL/$TESTFS
log_must zpool set bootfs=$POOL/$TESTFS $POOL
RES=$(zpool get bootfs $POOL | tail -1 | awk '{print $3}' )
RES=$(zpool get bootfs $POOL | awk 'END {print $3}' )
if [ $RES != "$POOL/$TESTFS" ]
then
log_fail "Expected $RES == $POOL/$TESTFS"

View File

@ -60,7 +60,7 @@ function verify_bootfs { # $POOL
log_must zfs create $POOL/$TESTFS
log_must zpool set bootfs=$POOL/$TESTFS $POOL
VAL=$(zpool get bootfs $POOL | tail -1 | awk '{print $3}' )
VAL=$(zpool get bootfs $POOL | awk 'END {print $3}' )
if [ $VAL != "$POOL/$TESTFS" ]
then
log_must zpool status -v $POOL
@ -74,7 +74,7 @@ function verify_no_bootfs { # $POOL
POOL=$1
log_must zfs create $POOL/$TESTFS
log_mustnot zpool set bootfs=$POOL/$TESTFS $POOL
VAL=$(zpool get bootfs $POOL | tail -1 | awk '{print $3}' )
VAL=$(zpool get bootfs $POOL | awk 'END {print $3}' )
if [ $VAL == "$POOL/$TESTFS" ]
then
log_must zpool status -v $POOL

View File

@ -34,15 +34,11 @@ function test_instr_limit
{
typeset lim=$1
error=$(zfs program -t $lim $TESTPOOL $ZCP_ROOT/lua_core/tst.timeout.zcp 2>&1)
[[ $? -ne 0 ]] || log_fail "Channel program with limit $lim exited 0: $error"
log_mustnot eval 'error=$(zfs program -t '$lim' $TESTPOOL $ZCP_ROOT/lua_core/tst.timeout.zcp 2>&1)'
instrs_run=$(echo $error | awk -F "chunk" '{print $2}' | awk '{print $1}')
if [[ $instrs_run -lt $(( $lim - 100 )) ]]; then
log_fail "Runtime (${instrs_run} instr) < limit (${lim} - 100 instr)"
elif [[ $instrs_run -gt $(( $lim + 100 )) ]]; then
log_fail "Runtime (${instrs_run} instr) > limit (${lim} + 100 instr)"
fi
read -r instrs_run _ < <(echo $error | awk -F "chunk" '{print $2}')
log_must [ $instrs_run -ge $(( $lim - 100 )) ]
log_must [ $instrs_run -le $(( $lim + 100 )) ]
log_note "With limit $lim the program ended after $instrs_run instructions"
}

View File

@ -85,7 +85,7 @@ log_must zpool import $TESTPOOL
log_must zpool scrub $TESTPOOL
log_must wait_scrubbed $TESTPOOL
cksum=$(zpool status -P -v $TESTPOOL | grep "$firstvdev" | awk '{print $5}')
cksum=$(zpool status -P -v $TESTPOOL | awk -v v="$firstvdev" '$0 ~ v {print $5}')
log_assert "Normal file write test saw $cksum checksum errors"
log_must [ $cksum -eq 0 ]
@ -105,8 +105,7 @@ while [[ $j -lt ${#CHECKSUM_TYPES[*]} ]]; do
log_must zpool scrub $TESTPOOL
log_must wait_scrubbed $TESTPOOL
cksum=$(zpool status -P -v $TESTPOOL | grep "$firstvdev" | \
awk '{print $5}')
cksum=$(zpool status -P -v $TESTPOOL | awk -v v="$firstvdev" '$0 ~ v {print $5}')
log_assert "Checksum '$type' caught $cksum checksum errors"
log_must [ $cksum -ne 0 ]

View File

@ -30,14 +30,6 @@
. $STF_SUITE/include/libtest.shlib
#
# Get the checksum and size of the file.
#
function get_cksum # <file path>
{
return $(cksum $1 | awk '{print $1 $2}')
}
#
# Compare the checksum of target files with the original file
#
@ -45,7 +37,7 @@ function get_cksum # <file path>
function compare_cksum #<orig_data> <target_data1>...<target_datan>
{
typeset orig_data=$1
typeset orig_sum=$(get_cksum $orig_data)
typeset orig_sum=$(cksum < $orig_data)
typeset target_sum=""
typeset bad_data_list=""
typeset -i bad_count=0
@ -58,7 +50,7 @@ function compare_cksum #<orig_data> <target_data1>...<target_datan>
continue
fi
target_sum=$(get_cksum $data)
target_sum=$(cksum < $data)
if [[ $target_sum != $orig_sum ]]; then
bad_data_list="$bad_data_list $data"
(( bad_count +=1 ))

View File

@ -70,12 +70,14 @@ log_must dd if=$DEV_RDSKDIR/${DISK[0]} of=$DEV_RDSKDIR/${DISK[1]} bs=1K count=25
ubs=$(zdb -lu ${DISK[1]} | grep -e LABEL -e Uberblock -e 'labels = ')
log_note "vdev 1: ubs $ubs"
set -o pipefail
ub_dump_counts=$(zdb -lu ${DISK[1]} | \
awk ' /LABEL/ {label=$NF; blocks[label]=0};
/Uberblock/ {blocks[label]++};
END {print blocks[0],blocks[1],blocks[2],blocks[3]}')
(( $? != 0)) && log_fail "failed to get ub_dump_counts from DISK[1]"
END {print blocks[0],blocks[1],blocks[2],blocks[3]}') ||
log_fail "failed to get ub_dump_counts from DISK[1]"
log_note "vdev 1: ub_dump_counts $ub_dump_counts"
set +o pipefail
set -A dump_count $ub_dump_counts
for label in 0 1 2 3; do

View File

@ -73,7 +73,7 @@ obj=${array[0]}
log_note "file $init_data has object number $obj"
output=$(zdb -ddddddbbbbbb $TESTPOOL/$TESTFS $obj 2> /dev/null \
|grep -m 1 "L0 DVA" |head -n1)
|grep -m 1 "L0 DVA")
dva=$(sed -Ene 's/^.+DVA\[0\]=<([^>]+)>.*$/\1/p' <<< "$output")
log_note "block 0 of $init_data has a DVA of $dva"
@ -81,15 +81,13 @@ log_note "block 0 of $init_data has a DVA of $dva"
size_str=$(sed -Ene 's/^.+ size=([^ ]+) .*$/\1/p' <<< "$output")
log_note "block size $size_str"
vdev=$(echo "$dva" |awk '{split($0,array,":")} END{print array[1]}')
offset=$(echo "$dva" |awk '{split($0,array,":")} END{print array[2]}')
vdev=$(echo "$dva" | cut -d: -f1)
offset=$(echo "$dva" | cut -d: -f2)
output=$(zdb -R $TESTPOOL $vdev:$offset:$size_str:d 2> /dev/null)
echo $output |grep $pattern > /dev/null
(( $? != 0 )) && log_fail "zdb -R :d failed to decompress the data properly"
echo $output | grep -q $pattern || log_fail "zdb -R :d failed to decompress the data properly"
output=$(zdb -R $TESTPOOL $vdev:$offset:$size_str:dr 2> /dev/null)
echo $output |grep $four_k > /dev/null
(( $? != 0 )) && log_fail "zdb -R :dr failed to decompress the data properly"
echo $output | grep -q $four_k || log_fail "zdb -R :dr failed to decompress the data properly"
output=$(zdb -R $TESTPOOL $vdev:$offset:$size_str:dr 2> /dev/null)
result=${#output}
@ -97,8 +95,8 @@ result=${#output}
"zdb -R failed to decompress the data to the length (${#output} != $size_str)"
# decompress using lsize
lsize=$(echo $size_str |awk '{split($0,array,"/")} END{print array[1]}')
psize=$(echo $size_str |awk '{split($0,array,"/")} END{print array[2]}')
lsize=$(echo $size_str | cut -d/ -f1)
psize=$(echo $size_str | cut -d/ -f2)
output=$(zdb -R $TESTPOOL $vdev:$offset:$lsize:dr 2> /dev/null)
result=${#output}
(( $result != $blksize)) && log_fail \

View File

@ -76,11 +76,11 @@ log_note "block 0 of $init_data has a DVA of $dva"
# use the length reported by zdb -ddddddbbbbbb
size_str=$(sed -Ene 's/^.+ size=([^ ]+) .*$/\1/p' <<< "$output")
# convert sizes to decimal
lsize=$(echo $size_str |awk '{split($0,array,"/")} END{print array[1]}')
lsize=$(echo $size_str | cut -d/ -f 1)
lsize_orig=$lsize
lsize=${lsize%?}
lsize_bytes=$((16#$lsize))
psize=$(echo $size_str |awk '{split($0,array,"/")} END{print array[2]}')
psize=$(echo $size_str | cut -d/ -f 2)
psize_orig=$psize
psize=${psize%?}
psize_bytes=$((16#$psize))
@ -88,21 +88,21 @@ log_note "block size $size_str"
# Get the ZSTD header reported by zdb -Z
zstd_str=$(sed -Ene 's/^.+ ZSTD:size=([^:]+):version=([^:]+):level=([^:]+):.*$/\1:\2:\3/p' <<< "$output")
zstd_size=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[1]}')
zstd_size=$(echo "$zstd_str" | cut -d: -f 1)
log_note "ZSTD compressed size $zstd_size"
(( $psize_bytes < $zstd_size )) && log_fail \
"zdb -Z failed: physical block size was less than header content length ($psize_bytes < $zstd_size)"
zstd_version=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[2]}')
zstd_version=$(echo "$zstd_str" | cut -d: -f 2)
log_note "ZSTD version $zstd_version"
zstd_level=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[3]}')
zstd_level=$(echo "$zstd_str" | cut -d: -f 3)
log_note "ZSTD level $zstd_level"
(( $zstd_level != $random_level )) && log_fail \
"zdb -Z failed: compression level did not match header level ($zstd_level < $random_level)"
vdev=$(echo "$dva" |awk '{split($0,array,":")} END{print array[1]}')
offset=$(echo "$dva" |awk '{split($0,array,":")} END{print array[2]}')
vdev=$(echo "$dva" | cut -d: -f 1)
offset=$(echo "$dva" | cut -d: -f 2)
# Check the first 1024 bytes
output=$(ZDB_NO_ZLE="true" zdb -R $TESTPOOL $vdev:$offset:$size_str:dr 2> /dev/null)
outsize=$(wc -c <<< "$output")

View File

@ -106,8 +106,8 @@ if [ "$output" != "$blk_out1" ]; then
log_fail "zdb -R :b80d (block 1 display/decompress) failed"
fi
vdev=$(echo "$dva" |awk '{split($0,array,":")} END{print array[1]}')
offset=$(echo "$dva" |awk '{split($0,array,":")} END{print array[2]}')
vdev=$(echo "$dva" | cut -d: -f1)
offset=$(echo "$dva" | cut -d: -f2)
output=$(export ZDB_NO_ZLE=\"true\";\
zdb -R $TESTPOOL $vdev:$offset:$l1_read_size:id 2> /dev/null)
block_cnt=$(echo "$output" | grep 'L0' | wc -l)

View File

@ -65,7 +65,7 @@ done
# Specifying a non-existent object identifier returns an error
obj_id_highest=$(zdb -P -dd $TESTPOOL/$TESTFS 2>/dev/null |
egrep "^ +-?([0-9]+ +){7}" | sort -n | tail -n 1 | awk '{print $1}')
egrep "^ +-?([0-9]+ +){7}" | sort -n | awk 'END {print $1}')
obj_id_invalid=$(( $obj_id_highest + 1 ))
log_mustnot zdb -dd $TESTPOOL/$TESTFS $obj_id_invalid

View File

@ -42,8 +42,8 @@ function get_object_list_range
begin=$2
end=$3
get_object_list $dataset |
while read line; do
obj=$(echo $line | awk '{print $1}')
while read -r line; do
read -r obj _ <<<"$line"
if [[ $obj -ge $begin && $obj -le $end ]] ; then
echo "$line"
elif [[ $obj -gt $end ]] ; then
@ -142,7 +142,7 @@ log_must test "\n$actual\n" == "\n$expected\n"
# Specifying individual object IDs works
objects="$start1 $end1 $start2 $end2"
expected="$objects"
actual=$(get_object_list $TESTPOOL/$TESTFS $objects | awk '{print $1}' | tr '\n' ' ')
actual=$(get_object_list $TESTPOOL/$TESTFS $objects | awk '{printf("%s ", $1)}' | tr '\n' ' ')
log_must test "${actual% }" == "$expected"
# Get all objects in the meta-objset to test m (spacemap) and z (zap) flags

View File

@ -68,63 +68,41 @@ log_note "file $init_data has object number $obj"
sync_pool $TESTPOOL
output=$(zdb -d $TESTPOOL/$TESTFS)
objset_id=$(echo $output | awk '{split($0,array,",")} END{print array[2]}' |
awk '{split($0,array," ")} END{print array[2]}')
objset_id=$(echo $output | cut -d, -f2 | cut -d' ' -f2)
objset_hex=$(printf "0x%X" $objset_id)
log_note "objset $TESTPOOL/$TESTFS has objset ID $objset_id ($objset_hex)"
for id in "$objset_id" "$objset_hex"
do
log_note "zdb -dddddd $TESTPOOL/$id $obj"
output=$(zdb -dddddd $TESTPOOL/$id $obj)
reason="($TESTPOOL/$TESTFS not in zdb output)"
echo $output |grep "$TESTPOOL/$TESTFS" > /dev/null
(( $? != 0 )) && log_fail \
"zdb -dddddd $TESTPOOL/$id $obj failed $reason"
reason="(file1 not in zdb output)"
echo $output |grep "file1" > /dev/null
(( $? != 0 )) && log_fail \
"zdb -dddddd $TESTPOOL/$id $obj failed $reason"
obj=$(printf "0x%X" $obj)
output=$(zdb -dddddd $TESTPOOL/$id $obj)
echo $output | grep -q "$TESTPOOL/$TESTFS" ||
log_fail "zdb -dddddd $TESTPOOL/$id $obj failed ($TESTPOOL/$TESTFS not in zdb output)"
echo $output | grep -q "file1" ||
log_fail "zdb -dddddd $TESTPOOL/$id $obj failed (file1 not in zdb output)"
obj=$(printf "0x%X" $obj)
log_note "zdb -NNNNNN $TESTPOOL/$id $obj"
output=$(zdb -NNNNNN $TESTPOOL/$id $obj)
reason="($TESTPOOL/$TESTFS not in zdb output)"
echo $output |grep "$TESTPOOL/$TESTFS" > /dev/null
(( $? != 0 )) && log_fail \
"zdb -NNNNNN $TESTPOOL/$id $obj failed $reason"
reason="(file1 not in zdb output)"
echo $output |grep "file1" > /dev/null
(( $? != 0 )) && log_fail \
"zdb -NNNNNN $TESTPOOL/$id $obj failed $reason"
echo $output | grep -q "$TESTPOOL/$TESTFS" ||
log_fail "zdb -NNNNNN $TESTPOOL/$id $obj failed ($TESTPOOL/$TESTFS not in zdb output)"
echo $output | grep -q "file1" ||
log_fail "zdb -NNNNNN $TESTPOOL/$id $obj failed (file1 not in zdb output)"
done
if is_linux; then
output=$(ls -1 /proc/spl/kstat/zfs/$TESTPOOL |grep objset- |tail -1)
objset_hex=${output#*-}
name_from_proc=$(cat /proc/spl/kstat/zfs/$TESTPOOL/$output |
grep dataset_name | awk '{split($0,array," ")} END{print array[3]}')
grep dataset_name | cut -d' ' -f3)
log_note "checking zdb output for $name_from_proc"
reason="(name $name_from_proc from proc not in zdb output)"
log_note "zdb -dddddd $TESTPOOL/$objset_hex"
output=$(zdb -dddddd $TESTPOOL/$objset_hex)
echo $output |grep "$name_from_proc" > /dev/null
(( $? != 0 )) && log_fail \
"zdb -dddddd $TESTPOOL/$objset_hex failed $reason"
log_must eval "zdb -dddddd $TESTPOOL/$objset_hex | grep -q \"$name_from_proc\""
fi
log_must zfs create $hex_ds
log_must zfs create $num_ds
output=$(zdb -d $hex_ds)
reason="($TESTPOOL/0x400 not in zdb output)"
echo $output |grep "$hex_ds" > /dev/null
(( $? != 0 )) && log_fail \
"zdb -d $hex_ds failed $reason"
output=$(zdb -d $num_ds)
reason="($num_ds not in zdb output)"
echo $output |grep "$num_ds" > /dev/null
(( $? != 0 )) && log_fail \
"zdb -d $num_ds failed $reason"
log_must eval "zdb -d $hex_ds | grep -q \"$hex_ds\""
log_must eval "zdb -d $num_ds | grep -q \"$num_ds\""
# force numeric interpretation, expect fail
log_mustnot zdb -N $hex_ds

View File

@ -40,8 +40,7 @@
# 2. Verify it succeed while upgrade, but fails while the version downgraded.
#
ZFS_VERSION=$(zfs upgrade | head -1 | awk '{print $NF}' \
| sed -e 's/\.//g')
ZFS_VERSION=$(zfs upgrade | grep -wom1 '[[:digit:]]*')
verify_runnable "both"

View File

@ -221,7 +221,7 @@ for (( i = 1; i <= (ZFS_MAXPROPLEN / 200 + 1); i++ )); do
log_must zfs clone ${fs}@snap ${fs}/${TESTCLONE}${xs}.${i}
done
clone_list=$(zfs list -o clones $fs@snap)
char_count=$(echo "$clone_list" | tail -1 | wc | awk '{print $3}')
char_count=$(echo "$clone_list" | tail -1 | wc -c)
[[ $char_count -eq $ZFS_MAXPROPLEN ]] || \
log_fail "Clone list not truncated correctly. Unexpected character count" \
"$char_count"

View File

@ -94,11 +94,9 @@ done
log_note "Verify df(1) can correctly display the space charged."
for val in 1 2 3; do
if is_freebsd; then
used=`df -m /$TESTPOOL/fs_$val | grep $TESTPOOL/fs_$val \
| awk -v fs=fs_$val '$4 ~ fs {print $3}'`
used=`df -m /$TESTPOOL/fs_$val | awk -v pa=$TESTPOOL/fs_$val -v fs=fs_$val '$0 ~ pa && $4 ~ fs {print $3}'`
else
used=`df -F zfs -k /$TESTPOOL/fs_$val/$FILE | grep $TESTPOOL/fs_$val \
| awk '{print $3}'`
used=`df -F zfs -k /$TESTPOOL/fs_$val/$FILE | awk -v pa=$TESTPOOL/fs_$val '$0 ~ pa {print $3}'`
(( used = used * 1024 )) # kb -> bytes
fi
check_used $used $val

View File

@ -62,8 +62,7 @@ function cleanup
# check to see if there is any new fs created during the test
# if so destroy it.
#
for dset in $(zfs list -H | \
awk '{print $1}' | grep / ); do
for dset in $(zfs list -H | awk '$1 ~ /\/ {print $1}'); do
found=false
i=0
while (( $i < ${#existed_fs[*]} )); do
@ -99,7 +98,7 @@ log_assert "Verify 'zfs create <filesystem>' fails with bad <filesystem> argumen
datasetexists $TESTPOOL/$TESTFS || \
log_must zfs create $TESTPOOL/$TESTFS
set -A existed_fs $(zfs list -H | awk '{print $1}' | grep / )
set -A existed_fs $(zfs list -H | awk '$1 ~ /\// {print $1}')
log_mustnot zfs create $TESTPOOL
log_mustnot zfs create $TESTPOOL/$TESTFS

View File

@ -62,8 +62,7 @@ function cleanup
# check to see if there is any new fs created during the test
# if so destroy it.
#
for dset in $(zfs list -H | \
awk '{print $1}' | grep / ); do
for dset in $(zfs list -H | awk '$1 ~ /\// {print $1}'); do
found=false
i=0
while (( $i < ${#existed_fs[*]} )); do
@ -108,7 +107,7 @@ set -A options "" "-s"
datasetexists $TESTPOOL/$TESTVOL || \
log_must zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL
set -A existed_fs $(zfs list -H | awk '{print $1}' | grep / )
set -A existed_fs $(zfs list -H | awk '$1 ~ /\// {print $1}')
log_mustnot zfs create -V $VOLSIZE $TESTPOOL/$TESTVOL
log_mustnot zfs create -s -V $VOLSIZE $TESTPOOL/$TESTVOL

View File

@ -41,8 +41,7 @@
# 2. Verify only the leaf filesystem to be version=1, others use the current version
#
ZFS_VERSION=$(zfs upgrade | head -1 | awk '{print $NF}' \
| sed -e 's/\.//g')
ZFS_VERSION=$(zfs upgrade | grep -wom1 '[[:digit:]]*')
verify_runnable "both"

View File

@ -40,15 +40,12 @@ function propertycheck
{
typeset dtst=$1
typeset propstr=$2
typeset prop expect_value
typeset prop=$(echo $propstr | awk -F= '{print $1}')
typeset expect_value=$(echo $propstr | awk -F= '{print $2}')
typeset value=$(zfs get -H -p -o value $prop $dtst)
IFS='=' read -r prop expect_value <<<"$propstr"
typeset value=$(get_prop $prop $dtst)
if [[ "$expect_value" == "$value" ]]; then
return 0
else
return 1
fi
[ "$expect_value" = "$value" ]
}

View File

@ -98,8 +98,7 @@ log_must zfs set mountpoint=$mntp1 $fs1
log_must zfs set mountpoint=$mntp2 $clone
for arg in "$fs1 $mntp1" "$clone $mntp2"; do
fs=`echo $arg | awk '{print $1}'`
mntp=`echo $arg | awk '{print $2}'`
read -r fs mntp <<<"$arg"
log_note "Verify that 'zfs destroy' fails to" \
"destroy filesystem when it is busy."

View File

@ -47,7 +47,7 @@ function verify_object_change # <path> <change>
change="$2"
log_must eval "zfs diff -F $TESTSNAP1 $TESTSNAP2 > $FILEDIFF"
diffchg="$(awk -v path="$path" '$NF == path { print $1 }' < $FILEDIFF)"
diffchg="$(awk -v path="$path" '$NF == path { print $1 }' $FILEDIFF)"
if [[ "$diffchg" != "$change" ]]; then
log_fail "Unexpected change for $path ('$diffchg' != '$change')"
else

View File

@ -73,10 +73,8 @@ log_must zfs snapshot "$TESTSNAP2"
# 3. Verify 'zfs diff -t' correctly display timestamps
typeset -i count=0
log_must eval "zfs diff -t $TESTSNAP1 $TESTSNAP2 > $FILEDIFF"
awk '{print substr($1,1,index($1,".")-1)" "$NF}' < "$FILEDIFF" | while read line
awk '{print substr($1,1,index($1,".")-1) " " $NF}' "$FILEDIFF" | while read -r ctime file
do
read ctime file <<< "$line"
# If path from 'zfs diff' is not a file (could be xattr object) skip it
if [[ ! -f "$file" ]]; then
continue;

View File

@ -52,7 +52,7 @@ function verify_object_class # <path> <symbol>
symbol="$2"
log_must eval "zfs diff -F $TESTSNAP1 $TESTSNAP2 > $FILEDIFF"
diffsym="$(awk -v path="$path" '$NF == path { print $2 }' < $FILEDIFF)"
diffsym="$(awk -v path="$path" '$NF == path { print $2 }' $FILEDIFF)"
if [[ "$diffsym" != "$symbol" ]]; then
log_fail "Unexpected type for $path ('$diffsym' != '$symbol')"
else

View File

@ -102,16 +102,15 @@ function check_return_value
found=0
while read line; do
typeset item
typeset value
typeset item value _
item=$(echo $line | awk '{print $2}' 2>&1)
read -r _ item _ <<<"$line"
if [[ $item == $p ]]; then
((found += 1))
cols=$(echo $line | awk '{print NF}')
fi
value=$(echo $line | awk '{print $3}' 2>&1)
read -r _ _ value _ <<<"$line"
if [[ $value == $uint64_max ]]; then
log_fail "'zfs get $opt $props $dst' return " \
"UINT64_MAX constant."

View File

@ -55,9 +55,8 @@ log_onexit cleanup
log_must zfs set atime=on $TESTPOOL/$TESTFS
log_must zfs mount -o remount,noatime $TESTPOOL/$TESTFS
value1=$(zfs get -H atime $TESTPOOL/$TESTFS | awk '{print $3}')
value2=$(zfs get -H all $TESTPOOL/$TESTFS | awk '{print $2 " " $3}' | \
grep ^atime | awk '{print $2}')
read -r _ _ value1 _ < <(zfs get -H atime $TESTPOOL/$TESTFS)
read -r _ value2 < <(zfs get -H all $TESTPOOL/$TESTFS | cut -f2,3 | grep ^atime)
if [[ $value1 != $value2 ]]; then
log_fail "value1($value1) != value2($value2)"
fi

View File

@ -163,15 +163,12 @@ while (( i < ${#opts[*]} )); do
log_must eval "zfs get ${opts[i]} all >$propfile"
for ds in $allds; do
grep $ds $propfile >/dev/null 2>&1
(( $? != 0 )) && \
grep -q $ds $propfile || \
log_fail "There is no property for" \
"dataset $ds in 'get all' output."
propnum=`cat $propfile | awk '{print $1}' | \
grep "${ds}$" | wc -l`
ds_type=`zfs get -H -o value type $ds`
case $ds_type in
propnum=$(awk -v ds="${ds}$" '$1 ~ ds {print $1}' $propfile | wc -l)
case $(zfs get -H -o value type $ds) in
filesystem )
(( propnum < fspropnum )) && \
(( failflag += 1 ))

View File

@ -70,7 +70,8 @@ log_must key_available $TESTPOOL/$TESTFS1
log_mustnot eval "echo $PASSPHRASE | zfs load-key $TESTPOOL/$TESTFS1"
typeset DISK2="$(echo $DISKS | awk '{ print $2 }')"
typeset DISK2 _
read -r _ DISK2 _ <<<"$DISKS"
log_must eval "echo $PASSPHRASE | zpool create -O encryption=on" \
"-O keyformat=passphrase -O keylocation=prompt $TESTPOOL1 $DISK2"

View File

@ -56,7 +56,8 @@ log_must zfs create -o encryption=on -o keyformat=passphrase \
log_must zfs create -V 64M -o encryption=on -o keyformat=passphrase \
-o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/zvol
typeset DISK2="$(echo $DISKS | awk '{ print $2}')"
typeset DISK2 _
read -r _ DISK2 _ <<<"$DISKS"
log_must zpool create -O encryption=on -O keyformat=passphrase \
-O keylocation=file:///$TESTPOOL/pkey $TESTPOOL1 $DISK2

View File

@ -35,10 +35,7 @@ function force_unmount #dev
{
typeset dev=$1
ismounted $dev
if (( $? == 0 )); then
log_must zfs $unmountforce $dev
fi
ismounted $dev && log_must zfs $unmountforce $dev
return 0
}

View File

@ -112,7 +112,7 @@ function get_reverse_option
typeset val
typeset -i ind=0
val=$(get_prop $prop $fs) || log_fail "get_prop $prop $fs"
val=$(get_prop $prop $fs)
if [[ $val == "on" ]]; then
(( ind = i * 2 ))
else
@ -127,7 +127,6 @@ cleanup
for property in ${properties[@]}; do
orig_val=$(get_prop $property $fs)
(($? != 0)) && log_fail "get_prop $property $fs"
# Set filesystem property temporarily
reverse_opt=$(get_reverse_option $fs $property)
@ -135,7 +134,6 @@ for property in ${properties[@]}; do
log_must zfs mount -o $reverse_opt $fs
cur_val=$(get_prop $property $fs)
(($? != 0)) && log_fail "get_prop $property $fs"
# In LZ, a user with all zone privileges can never with "devices"
if ! is_global_zone && [[ $property == devices ]] ; then
@ -153,7 +151,6 @@ for property in ${properties[@]}; do
log_must zfs mount $fs
cur_val=$(get_prop $property $fs)
(($? != 0)) && log_fail "get_prop $property $fs"
if [[ $orig_val != $cur_val ]]; then
log_fail "zfs mount -o $reverse_opt " \
"change the property that is stored on disks"

View File

@ -217,12 +217,11 @@ for ds in $datasets; do
sync_pool
done
recursive_output=$(zfs get -p -r written@current $TESTPOOL | \
grep -v $TESTFS1@ | grep -v $TESTFS2@ | grep -v $TESTFS3@ | \
grep -v "VALUE" | grep -v "-")
grep -ve $TESTFS1@ -e $TESTFS2@ -e $TESTFS3@ -e "VALUE" | grep -v "-")
expected="$((20 * mb_block))"
for ds in $datasets; do
writtenat=$(echo "$recursive_output" | grep -v $ds/)
writtenat=$(echo "$writtenat" | grep $ds | awk '{print $3}')
writtenat=$(echo "$writtenat" | awk -v ds="$ds" '$0 ~ ds {print $3}')
within_percent $writtenat $expected 99.5 || \
log_fail "Unexpected written@ value on $ds"
done

View File

@ -62,7 +62,7 @@ log_onexit cleanup
ibackup=$TEST_BASE_DIR/ibackup.$$
fs=$TESTPOOL/$TESTFS; snap1=$fs@snap1; snap2=$fs@snap2
mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs"
mntpnt=$(get_prop mountpoint $fs)
log_must mkfile 10m $mntpnt/file1
log_must zfs snapshot $snap1
log_must mkfile 10m $mntpnt/file2

View File

@ -82,7 +82,7 @@ datasetexists $ancestor_fs || \
log_must zfs create $ancestor_fs
log_must zfs create $fs
mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs"
mntpnt=$(get_prop mountpoint $fs)
log_must mkfile 10m $mntpnt/file1
log_must zfs snapshot $snap1
log_must mkfile 10m $mntpnt/file2

View File

@ -64,7 +64,7 @@ ibackup=$TEST_BASE_DIR/ibackup.$$
datasetexists $fs || log_must zfs create $fs
mntpnt=$(get_prop mountpoint $fs) || log_fail "get_prop mountpoint $fs"
mntpnt=$(get_prop mountpoint $fs)
log_must mkfile 10m $mntpnt/file1
log_must zfs snapshot $snap1
log_must mkfile 10m $mntpnt/file2

View File

@ -86,9 +86,6 @@ for orig_fs in $datasets ; do
typeset mntpnt
mntpnt=$(get_prop mountpoint $orig_fs)
if [[ $? -ne 0 ]] ; then
log_fail "get_prop mountpoint $orig_fs failed"
fi
typeset mnt_file=$mntpnt/file1

View File

@ -52,7 +52,7 @@ log_onexit cleanup
truncate -s 100M $tpoolfile
log_must zpool create $temppool $tpoolfile
log_must zfs create $src_fs
src_mnt=$(get_prop mountpoint $src_fs) || log_fail "get_prop mountpoint $src_fs"
src_mnt=$(get_prop mountpoint $src_fs)
echo blah > $src_mnt/blah
zfs snapshot $src_fs@base

View File

@ -58,27 +58,22 @@ log_note "Randomly selected ZSTD level: $random_level"
log_must zfs create -o compress=zstd-$random_level $TESTPOOL/$TESTFS1
# Make a 5kb compressible file
log_must cat $src_data $src_data $src_data $src_data $src_data \
> /$TESTPOOL/$TESTFS1/$TESTFILE0
log_must eval cat $src_data $src_data $src_data $src_data $src_data \
"> /$TESTPOOL/$TESTFS1/$TESTFILE0"
typeset checksum=$(md5digest /$TESTPOOL/$TESTFS1/$TESTFILE0)
log_must zfs snapshot $snap
# get object number of file
listing=$(ls -i /$TESTPOOL/$TESTFS1/$TESTFILE0)
set -A array $listing
obj=${array[0]}
read -r obj _ < <(ls -i /$TESTPOOL/$TESTFS1/$TESTFILE0)
log_note "file /$TESTPOOL/$TESTFS1/$TESTFILE0 has object number $obj"
output=$(zdb -Zddddddbbbbbb $TESTPOOL/$TESTFS1 $obj 2> /dev/null \
|grep -m 1 "L0 DVA" |head -n1)
| grep -m 1 "L0 DVA")
dva=$(sed -Ene 's/^.+DVA\[0\]=<([^>]+)>.*$/\1/p' <<< "$output")
log_note "block 0 of /$TESTPOOL/$TESTFS1/$TESTFILE0 has a DVA of $dva"
zstd_str=$(sed -Ene 's/^.+ ZSTD:size=([^:]+):version=([^:]+):level=([^:]+):.*$/\1:\2:\3/p' <<< "$output")
zstd_size1=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[1]}')
zstd_version1=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[2]}')
zstd_level1=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[3]}')
read -r zstd_size1 zstd_version1 zstd_level1 < <(sed -Ene 's/^.+ ZSTD:size=([^:]+):version=([^:]+):level=([^:]+):.*$/\1 \2 \3/p' <<< "$output")
log_note "ZSTD src: size=$zstd_size1 version=$zstd_version1 level=$zstd_level1"
log_note "Verify ZFS can receive the ZSTD compressed stream"
@ -89,23 +84,18 @@ typeset cksum1=$(md5digest /$TESTPOOL/$TESTFS2/$TESTFILE0)
log_fail "Checksums differ ($cksum1 != $checksum)"
# get object number of file
listing=$(ls -i /$TESTPOOL/$TESTFS2/$TESTFILE0)
set -A array $listing
obj=${array[0]}
read -r obj _ < <(ls -i /$TESTPOOL/$TESTFS2/$TESTFILE0)
log_note "file /$TESTPOOL/$TESTFS2/$TESTFILE0 has object number $obj"
output=$(zdb -Zddddddbbbbbb $TESTPOOL/$TESTFS2 $obj 2> /dev/null \
|grep -m 1 "L0 DVA" |head -n1)
| grep -m 1 "L0 DVA")
dva=$(sed -Ene 's/^.+DVA\[0\]=<([^>]+)>.*$/\1/p' <<< "$output")
log_note "block 0 of /$TESTPOOL/$TESTFS2/$TESTFILE0 has a DVA of $dva"
zstd_str=$(sed -Ene 's/^.+ ZSTD:size=([^:]+):version=([^:]+):level=([^:]+):.*$/\1:\2:\3/p' <<< "$output")
zstd_size2=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[1]}')
read -r zstd_size2 zstd_version2 zstd_level2 < <(sed -Ene 's/^.+ ZSTD:size=([^:]+):version=([^:]+):level=([^:]+):.*$/\1 \2 \3/p' <<< "$output")
log_note "ZSTD dest: size=$zstd_size2 version=$zstd_version2 level=$zstd_level2"
(( $zstd_size2 != $zstd_size1 )) && log_fail \
"ZFS recv failed: compressed size differs ($zstd_size2 != $zstd_size1)"
zstd_version2=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[2]}')
zstd_level2=$(echo "$zstd_str" |awk '{split($0,array,":")} END{print array[3]}')
log_note "ZSTD dest: size=$zstd_size2 version=$zstd_version2 level=$zstd_level2"
(( $zstd_level2 != $zstd_level1 )) && log_fail \
"ZFS recv failed: compression level did not match header level ($zstd_level2 != $zstd_level1)"

View File

@ -39,7 +39,7 @@ function rename_cleanup
zfs destroy -fR $TESTPOOL/renamed
}
back=$(pwd)
back=$PWD
log_onexit rename_cleanup
log_must zfs create $TESTPOOL/rename_test
@ -72,14 +72,15 @@ log_must zfs list $TESTPOOL/renamed
log_must zfs list $TESTPOOL/renamed/child
log_must zfs list $TESTPOOL/renamed/child/grandchild
missing=$(zfs mount | awk -v pat=$TESTPOOL/renamed '$1 ~ pat' | awk \
missing=$(zfs mount | awk \
-v genpat=$TESTPOOL/renamed \
-v mntp_p=$mntp_p \
-v mntp_c=$mntp_c \
-v mntp_g=$mntp_g '
BEGIN { p = c = g = 0 }
$2 == mntp_p { p = 1 }
$2 == mntp_c { c = 1 }
$2 == mntp_g { g = 1 }
$1 ~ genpat && $2 == mntp_p { p = 1 }
$1 ~ genpat && $2 == mntp_c { c = 1 }
$1 ~ genpat && $2 == mntp_g { g = 1 }
END {
if (p != 1)
print mntp_p

View File

@ -52,7 +52,7 @@ streamfile=$(mktemp $TESTDIR/file.XXXXXX)
vdev=$(mktemp $TEST_BASE_DIR/file.XXXXXX)
test_pool ()
function test_pool
{
POOL=$1
log_must zfs create -o recordsize=512 $POOL/fs
@ -67,10 +67,7 @@ test_pool ()
sync_all_pools
# check if we started reusing objects
object=$(ls -i $mntpnt | sort -n | awk -v object=$object \
'{if ($1 <= object) {exit 1}} END {print $1}')
if [[ $? -ne 0 ]]; then
break
fi
'{if ($1 <= object) {exit 1}} END {print $1}') || break
done
dd if=/dev/urandom of=${mntpnt}/$FILE bs=512 count=1 seek=1 2>/dev/null

View File

@ -81,14 +81,8 @@ function cleanup
log_assert "Setting a valid property of canmount to file system, it must be successful."
log_onexit cleanup
typeset old_fs_canmount="" old_ctr_canmount=""
old_fs_canmount=$(get_prop canmount $TESTPOOL/$TESTFS)
[[ $? != 0 ]] && \
log_fail "Get the $TESTPOOL/$TESTFS canmount error."
old_ctr_canmount=$(get_prop canmount $TESTPOOL/$TESTCTR)
[[ $? != 0 ]] && \
log_fail "Get the $TESTPOOL/$TESTCTR canmount error."
typeset old_fs_canmount=$(get_prop canmount $TESTPOOL/$TESTFS)
typeset old_ctr_canmount=$(get_prop canmount $TESTPOOL/$TESTCTR)
log_must zfs snapshot $TESTPOOL/$TESTFS@$TESTSNAP
log_must zfs snapshot $TESTPOOL/$TESTVOL@$TESTSNAP

View File

@ -69,11 +69,7 @@ log_assert "Setting a valid mountpoint to file system, it must be successful."
log_onexit cleanup
old_fs_mpt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
[[ $? != 0 ]] && \
log_fail "Get the $TESTPOOL/$TESTFS mountpoint error."
old_ctr_mpt=$(get_prop mountpoint $TESTPOOL/$TESTCTR)
[[ $? != 0 ]] && \
log_fail "Get the $TESTPOOL/$TESTCTR mountpoint error."
if [[ ! -d $TESTDIR2 ]]; then
log_must mkdir $TESTDIR2

View File

@ -66,11 +66,7 @@ log_assert "Setting a valid mountpoint for an unmounted file system, \
log_onexit cleanup
old_fs_mpt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
[[ $? != 0 ]] && \
log_fail "Unable to get the mountpoint property for $TESTPOOL/$TESTFS"
old_ctr_mpt=$(get_prop mountpoint $TESTPOOL/$TESTCTR)
[[ $? != 0 ]] && \
log_fail "Unable to get the mountpoint property for $TESTPOOL/$TESTCTR"
if [[ ! -d $TESTDIR2 ]]; then
log_must mkdir $TESTDIR2

View File

@ -109,10 +109,8 @@ while ((i < ${#args[@]})); do
msg=$(mount | grep "$tmpmnt ")
echo $msg | grep "${args[((i))]}" > /dev/null 2>&1
if (($? != 0)) ; then
echo $msg | grep "${args[((i-1))]}" > /dev/null 2>&1
if (($? == 0)) ; then
if ! echo $msg | grep -q "${args[((i))]}"; then
if echo $msg | grep -q "${args[((i-1))]}"; then
log_fail "Expected option: ${args[((i))]} \n" \
"Real option: $msg"
fi
@ -130,8 +128,7 @@ while ((i < ${#args[@]})); do
args[((i+1))]="/nodevices/"
fi
echo $msg | grep "${args[((i+1))]}" > /dev/null 2>&1
if (($? != 0)) ; then
if ! echo $msg | grep -q "${args[((i+1))]}"; then
log_fail "Expected option: ${args[((i+1))]} \n" \
"Real option: $msg"
fi

View File

@ -84,7 +84,7 @@ while (( i < ${#invalid_args[*]} )); do
((i = i + 1))
done
log_note "verify multiple snapshot transaction group"
txg_group=$(zdb -Pd $TESTPOOL | grep snap | awk '{print $7}')
txg_group=$(zdb -Pd $TESTPOOL | awk '/snap/ {print $7}')
for i in 1 2 3; do
txg_tag=$(echo "$txg_group" | nawk -v j=$i 'FNR == j {print}')
[[ $txg_tag != $(echo "$txg_group" | \

View File

@ -54,7 +54,8 @@ log_must zfs create $TESTPOOL/$TESTFS1/child
log_must zfs create -V 64M -o encryption=on -o keyformat=passphrase \
-o keylocation=file:///$TESTPOOL/pkey $TESTPOOL/zvol
typeset DISK2="$(echo $DISKS | awk '{ print $2}')"
typeset DISK2 _
read -r _ DISK2 _ <<<"$DISKS"
log_must zpool create -O encryption=on -O keyformat=passphrase \
-O keylocation=file:///$TESTPOOL/pkey $TESTPOOL1 $DISK2

View File

@ -56,7 +56,6 @@ log_onexit cleanup
# Call cleanup to make sure the file system are mounted.
cleanup
mntpnt=$(get_prop mountpoint $TESTPOOL/$TESTFS)
(($? != 0)) && log_fail "get_prop mountpoint $TESTPOOL/$TESTFS"
typeset -i i=0
while (( i < 10000 )); do

View File

@ -72,7 +72,7 @@ typeset expect_str3="The following filesystems are out of date, and can be upgra
typeset -i COUNT OLDCOUNT
zfs upgrade | nawk '$1 ~ "^[0-9]+$" {print $2}'> $oldoutput
OLDCOUNT=$( wc -l $oldoutput | awk '{print $1}' )
OLDCOUNT=$(wc -l < $oldoutput)
old_datasets=""
for version in $ZFS_ALL_VERSIONS ; do
@ -100,7 +100,7 @@ log_must eval 'zfs upgrade > $output 2>&1'
# of the current ZFS version.
log_must eval 'grep "${expect_str1} $ZFS_VERSION" $output > /dev/null 2>&1'
zfs upgrade | nawk '$1 ~ "^[0-9]+$" {print $2}'> $output
COUNT=$( wc -l $output | awk '{print $1}' )
COUNT=$(wc -l < $output)
typeset -i i=0
for fs in ${old_datasets}; do
@ -125,7 +125,7 @@ else
log_must eval 'grep "${expect_str3}" $output > /dev/null 2>&1'
fi
zfs upgrade | nawk '$1 ~ "^[0-9]+$" {print $2}'> $output
COUNT=$( wc -l $output | awk '{print $1}' )
COUNT=$(wc -l < $output)
if (( COUNT != OLDCOUNT )); then
cat $output

View File

@ -39,8 +39,7 @@ log_onexit cleanup
log_assert "Test colorized zpool status output"
DISK2="$(echo $DISKS | cut -d' ' -f2)"
DISK3="$(echo $DISKS | cut -d' ' -f3)"
read -r _ DISK2 DISK3 _ <<<"$DISKS"
log_must dd if=/dev/urandom of=/$TESTDIR/testfile bs=10M count=1
@ -62,16 +61,15 @@ log_note "$(faketty TERM=xterm-256color ZFS_COLOR=1 zpool status)"
# Replace the escape codes with "ESC" so they're easier to grep
out="$(faketty TERM=xterm-256color ZFS_COLOR=1 zpool status | \
grep -E 'pool:|DEGRADED' | \
sed -r 's/[[:space:]]+//g;'$(echo -e 's/\033/ESC/g'))"
sed -E '/pool:|DEGRADED/!d;s/[[:space:]]+//g;'$(printf 's/\033/ESC/g'))"
log_note "$(echo $out)"
log_note "Look for 'pool:' in bold"
log_must eval "echo \"$out\" | grep -q 'ESC\[1mpool:ESC\[0m' "
log_must grep -q 'ESC\[1mpool:ESC\[0m' <<<"$out"
log_note "Look for 'DEGRADED' in yellow"
log_must eval "echo \"$out\" | grep -q 'ESC\[0;33mDEGRADEDESC\[0m'"
log_must grep -q 'ESC\[0;33mDEGRADEDESC\[0m' <<<"$out"
#
# The escape code for 'FAULTED' is a little more tricky. The line starts like
@ -83,9 +81,11 @@ log_must eval "echo \"$out\" | grep -q 'ESC\[0;33mDEGRADEDESC\[0m'"
# we can easily remove the vdev field to get what we want.
#
out="$(faketty TERM=xterm-256color ZFS_COLOR=1 zpool status \
| awk '/FAULTED/{print $1$3$4}' | sed -r $(echo -e 's/\033/ESC/g'))"
| awk '/FAULTED/ {print $1$3$4}' | sed -E $(printf 's/\033/ESC/g'))"
log_note "$(echo $out)"
log_note "Look for 'FAULTED' in red"
log_must eval "echo \"$out\" | grep -q 'ESC\[0;31mFAULTEDESC\[0m'"
log_must grep -q 'ESC\[0;31mFAULTEDESC\[0m' <<<"$out"
log_pass "zpool status displayed colors"

View File

@ -90,10 +90,8 @@ do
log_must wait_vdev_state $TESTPOOL $REPLACE_DEV "ONLINE" 60
zpool status | awk -v poolname="$TESTPOOL" -v type="$type" 'BEGIN {s=""}
$1 ~ poolname {c=4}; (c && c--) { s=s$1":" }
END { if (s != poolname":"type"-0:spare-0:replacing-0:") exit 1; }'
if [[ $? -ne 0 ]]; then
END { if (s != poolname":"type"-0:spare-0:replacing-0:") exit 1; }' ||
log_fail "Pool does not contain nested replacing/spare vdevs"
fi
# 3. Verify 'zpool add' is able to add new devices
log_must zpool add $TESTPOOL spare $SPARE_DEV2

View File

@ -50,9 +50,8 @@ function find_vfstab_dev
#
function find_mnttab_dev
{
typeset mnttabdev
typeset mnttabdev _
typeset mnttabdevs=""
typeset line
if is_freebsd; then
# FreeBSD doesn't have a mnttab file.
@ -61,21 +60,16 @@ function find_mnttab_dev
return 0
elif is_linux; then
typeset mnttab="/etc/mtab"
typeset tmpfile="$TEST_BASE_DIR/mtab.tmp"
else
typeset mnttab="/etc/mnttab"
typeset tmpfile="$TEST_BASE_DIR/mnttab.tmp"
fi
cat $mnttab | grep "^${DEV_DSKDIR}" >$tmpfile
while read -r line
while read -r mnttabdev _
do
mnttabdev=`echo "$line" | awk '{print $1}'`
mnttabdev=${mnttabdev%%:}
mnttabdevs="$mnttabdev $mnttabdevs"
done <$tmpfile
done < <(grep "^${DEV_DSKDIR}" $mnttab)
rm -f $tmpfile
echo $mnttabdevs
}

View File

@ -90,8 +90,8 @@ done
log_must zpool add -f $TESTPOOL $config
zpool status $TESTPOOL | awk 'NR == 1, /NAME/ { next } /^$/ {exit}
{print $1}' > "$TMPFILE_PREFIX-vdevtree"
cat "$TMPFILE_PREFIX-dryrun" | awk 'NR == 1, /would/ {next}
/^$/ {next} {print $1}' > "$TMPFILE_PREFIX-vdevtree-n"
log_must eval "diff $TMPFILE_PREFIX-vdevtree-n $TMPFILE_PREFIX-vdevtree"
awk 'NR == 1, /would/ {next}
/^$/ {next} {print $1}' "$TMPFILE_PREFIX-dryrun" > "$TMPFILE_PREFIX-vdevtree-n"
log_must diff $TMPFILE_PREFIX-vdevtree-n $TMPFILE_PREFIX-vdevtree
log_pass "'zpool add -n <pool> <vdev> ...' executes successfully."

View File

@ -50,9 +50,7 @@ function cleanup
poolexists $TESTPOOL1 && \
log_must zpool destroy -f $TESTPOOL1
for file in `ls $TEST_BASE_DIR/file.*`; do
log_must rm -f $file
done
log_must rm -f $fbase.{0..2}
}
@ -60,14 +58,8 @@ log_assert "Verify 'zpool clear' can clear errors of a storage pool."
log_onexit cleanup
#make raw files to create various configuration pools
typeset -i i=0
while (( i < 3 )); do
log_must truncate -s $FILESIZE $TEST_BASE_DIR/file.$i
(( i = i + 1 ))
done
fbase=$TEST_BASE_DIR/file
log_must truncate -s $FILESIZE $fbase.{0..2}
set -A poolconf "mirror $fbase.0 $fbase.1 $fbase.2" \
"raidz1 $fbase.0 $fbase.1 $fbase.2" \
"raidz2 $fbase.0 $fbase.1 $fbase.2"
@ -75,59 +67,24 @@ set -A poolconf "mirror $fbase.0 $fbase.1 $fbase.2" \
function check_err # <pool> [<vdev>]
{
typeset pool=$1
shift
if (( $# > 0 )); then
typeset checkvdev=$1
else
typeset checkvdev=""
fi
typeset -i errnum=0
typeset c_read=0
typeset c_write=0
typeset c_cksum=0
typeset tmpfile=$TEST_BASE_DIR/file.$$
typeset healthstr="pool '$pool' is healthy"
typeset output="`zpool status -x $pool`"
typeset checkvdev=$2
[[ "$output" == "$healthstr" ]] && return $errnum
[ "$(zpool status -x $pool)" = "pool '$pool' is healthy" ] && return
zpool status -x $pool | grep -v "^$" | grep -v "pool:" \
| grep -v "state:" | grep -v "config:" \
| grep -v "errors:" > $tmpfile
typeset line
typeset -i fetchbegin=1
while read line; do
if (( $fetchbegin != 0 )); then
echo $line | grep "NAME" >/dev/null 2>&1
(( $? == 0 )) && (( fetchbegin = 0 ))
continue
typeset -i skipstart=1
typeset vdev _ c_read c_write c_cksum rest
while read -r vdev _ c_read c_write c_cksum rest; do
if [ $skipstart -ne 0 ]; then
[ "$vdev" = "NAME" ] && skipstart=0
continue
fi
if [[ -n $checkvdev ]]; then
echo $line | grep $checkvdev >/dev/null 2>&1
(( $? != 0 )) && continue
c_read=`echo $line | awk '{print $3}'`
c_write=`echo $line | awk '{print $4}'`
c_cksum=`echo $line | awk '{print $5}'`
if [ $c_read != 0 ] || [ $c_write != 0 ] || \
[ $c_cksum != 0 ]
then
(( errnum = errnum + 1 ))
fi
break
if [ -n "$checkvdev" ]; then
[ "$vdev" = "$checkvdev" ] || continue
fi
c_read=`echo $line | awk '{print $3}'`
c_write=`echo $line | awk '{print $4}'`
c_cksum=`echo $line | awk '{print $5}'`
if [ $c_read != 0 ] || [ $c_write != 0 ] || \
[ $c_cksum != 0 ]
then
(( errnum = errnum + 1 ))
fi
done <$tmpfile
return $errnum
[ $c_read$c_write$c_cksum = 000 ] || return
done < <(zpool status -x $pool | grep -ve "^$" -e "pool:" -e "state:" -e "config:" -e "errors:")
}
function do_testing #<clear type> <vdevs>
@ -137,6 +94,7 @@ function do_testing #<clear type> <vdevs>
typeset type=$1
shift
typeset vdev="$@"
(( i = $RANDOM % 3 ))
log_must zpool create -f $TESTPOOL1 $vdev
log_must zfs create $FS
@ -146,14 +104,13 @@ function do_testing #<clear type> <vdevs>
#
avail=$(get_prop available $FS)
fill_mb=$(((avail / 1024 / 1024) * 25 / 100))
log_must dd if=/dev/urandom of=$file.$i bs=$BLOCKSZ count=$fill_mb
log_must dd if=/dev/urandom of=$file bs=$BLOCKSZ count=$fill_mb
#
# Make errors to the testing pool by overwrite the vdev device with
# dd command. We do not want to have a full overwrite. That
# may cause the system panic. So, we should skip the vdev label space.
#
(( i = $RANDOM % 3 ))
typeset -i wcount=0
typeset -i size
case $FILESIZE in
@ -173,25 +130,19 @@ function do_testing #<clear type> <vdevs>
(( wcount = FILESIZE/1024 - 512 ))
;;
esac
dd if=/dev/zero of=$fbase.$i seek=512 bs=1024 count=$wcount conv=notrunc \
> /dev/null 2>&1
dd if=/dev/zero of=$fbase.$i seek=512 bs=1024 count=$wcount conv=notrunc 2>/dev/null
sync_all_pools
log_must sync #ensure the vdev files are written out
log_must zpool scrub -w $TESTPOOL1
check_err $TESTPOOL1 && \
log_fail "No error generated."
if [[ $type == "device" ]]; then
log_must zpool clear $TESTPOOL1 $fbase.$i
! check_err $TESTPOOL1 $fbase.$i && \
log_fail "'zpool clear' fails to clear error for $fbase.$i device."
log_mustnot check_err $TESTPOOL1
typeset dev=
if [ "$type" = "device" ]; then
dev=$fbase.$i
fi
if [[ $type == "pool" ]]; then
log_must zpool clear $TESTPOOL1
! check_err $TESTPOOL1 && \
log_fail "'zpool clear' fails to clear error for pool $TESTPOOL1."
fi
log_must zpool clear $TESTPOOL1 $dev
log_must check_err $TESTPOOL1 $dev
log_must zpool destroy $TESTPOOL1
}

View File

@ -83,14 +83,9 @@ function find_vfstab_dev
#
function save_dump_dev
{
typeset dumpdev=""
if is_illumos; then
typeset fnd="Dump device"
dumpdev=`dumpadm | grep "$fnd" | cut -f2 -d : | \
awk '{print $1}'`
dumpadm | grep "Dump device" | cut -f2 -d : | awk '{print $1}'
fi
echo $dumpdev
}
#

View File

@ -90,8 +90,8 @@ do
$file.1 $file.2 $file.3 $file.4
! poolexists $TESTPOOL && \
log_fail "Creating pool with $opt fails."
mpt=`zfs mount | egrep "^$TESTPOOL[^/]" | awk '{print $2}'`
(( ${#mpt} == 0 )) && \
mpt=`zfs mount | awk -v pat="^$TESTPOOL[^/]" '$0 ~ pat {print $2}'`
[ -z "$mpt" ] && \
log_fail "$TESTPOOL created with $opt is not mounted."
mpt_val=$(get_prop "mountpoint" $TESTPOOL)
[[ "$mpt" != "$mpt_val" ]] && \

View File

@ -51,12 +51,11 @@ function cleanup
}
if is_freebsd; then
typeset swap_disks=$(swapinfo -l | grep "/dev" | awk '{print $1}')
typeset swap_disks=$(swapinfo -l | awk '/\/dev/ {print $1}')
elif is_linux; then
typeset swap_disks=`swapon -s | grep "/dev" | awk '{print $1}'`
typeset swap_disks=$(swapon -s | awk '/\/dev/ {print $1}')
else
typeset swap_disks=`swap -l | grep "c[0-9].*d[0-9].*s[0-9]" | \
awk '{print $1}'`
typeset swap_disks=$(swap -l | awk '/c[0-9].*d[0-9].*s[0-9]/ {print $1}')
fi
log_assert "'zpool create' should fail with disk slice in swap."

View File

@ -67,8 +67,8 @@ function cleanup
fi
}
typeset swap_disks=$(swap -l | grep -v "swapfile" | awk '{print $1}')
typeset dump_device=$(dumpadm | grep "Dump device" | awk '{print $3}')
typeset swap_disks=$(swap -l | awk '!/swapfile/ {print $1}')
typeset dump_device=$(dumpadm | awk '/Dump device/ {print $3}')
log_assert "'zpool create' should success with no device in swap."
log_onexit cleanup

View File

@ -55,11 +55,9 @@ for poolprop in "${poolprops[@]}"; do
# 2. Verify the pool is created with the specified temporary name
log_must poolexists $TEMPPOOL
log_mustnot poolexists $TESTPOOL
propname="$(awk -F= '{print $1}' <<< $fsprop)"
propval="$(awk -F= '{print $2}' <<< $fsprop)"
IFS='=' read -r propname propval <<<"$fsprop"
log_must test "$(get_prop $propname $TEMPPOOL)" == "$propval"
propname="$(awk -F= '{print $1}' <<< $poolprop)"
propval="$(awk -F= '{print $2}' <<< $poolprop)"
IFS='=' read -r propname propval <<<"$poolprop"
log_must test "$(get_pool_prop $propname $TEMPPOOL)" == "$propval"
# Cleanup
destroy_pool $TEMPPOOL

View File

@ -80,7 +80,7 @@ function damage_and_repair
log_must zpool wait -t scrub $POOL
log_note "pass $1 observed $($EREPORTS | grep -c checksum) checksum ereports"
repaired=$(zpool status $POOL | grep "scan: scrub repaired" | awk '{print $4}')
repaired=$(zpool status $POOL | awk '/scan: scrub repaired/ {print $4}')
if [ "$repaired" == "0B" ]; then
log_fail "INVALID TEST -- expected scrub to repair some blocks"
else
@ -90,7 +90,7 @@ function damage_and_repair
function checksum_error_count
{
zpool status -p $POOL | grep $VDEV1 | awk '{print $5}'
zpool status -p $POOL | awk -v dev=$VDEV1 '$0 ~ dev {print $5}'
}
assertion="Damage to recently repaired blocks should be reported/counted"

View File

@ -30,9 +30,9 @@
. $STF_SUITE/include/libtest.shlib
export DISK_ARRAY_NUM=$(echo ${DISKS} | nawk '{print NF}')
export DISK1=$(echo $DISKS | awk '{print $1}')
export DISK2=$(echo $DISKS | awk '{print $3}')
export DISK_ARRAY_NUM=$(echo ${DISKS} | awk '{print NF}')
read -r DISK1 _ DISK2 _ <<<"$DISKS"
export DISK1 DISK2
if is_linux; then
set_slice_prefix

View File

@ -88,7 +88,7 @@ done
# increment the counter to include the header line
i=$(( $i + 1 ))
COUNT=$(wc $values | awk '{print $1}')
COUNT=$(wc -l < $values)
if [ $i -ne $COUNT ]
then
log_fail "Found zpool features not in the zpool_get test config $i/$COUNT."

View File

@ -50,14 +50,9 @@ typeset -i i=0
while [[ $i -lt "${#properties[@]}" ]]; do
log_note "Checking for parsable ${properties[$i]} property"
log_must eval "zpool get -p ${properties[$i]} $TESTPOOL >/tmp/value.$$"
grep "${properties[$i]}" /tmp/value.$$ >/dev/null 2>&1
if [[ $? -ne 0 ]]; then
log_fail "${properties[$i]} not seen in output"
fi
log_must grep -q "${properties[$i]}" /tmp/value.$$
typeset v=$(grep "${properties[$i]}" /tmp/value.$$ | awk '{print $3}')
log_note "${properties[$i]} has a value of $v"
typeset v=$(awk -v p="${properties[$i]}" '$0 ~ p {print $3}' /tmp/value.$$)
# Determine if this value is a valid number, result in return code
log_must test -n "$v"

View File

@ -143,13 +143,12 @@ function verify_data_md5sums
return 1
fi
cat $md5file | \
while read digest file; do
while read -r digest file; do
typeset digest1=$(md5digest $file)
if [[ "$digest1" != "$digest" ]]; then
return 1
fi
done
done < $md5file
return 0
}
@ -227,8 +226,7 @@ function check_pool_config
typeset actual=""
typeset began=false
printf "$status\n" | while read line; do
typeset vdev=$(echo "$line" | awk '{printf $1}')
while read -r vdev _; do
if ( ! $began ) && [[ $vdev == NAME ]]; then
began=true
continue
@ -240,7 +238,7 @@ function check_pool_config
vdev=$(_translate_vdev $vdev)
actual="$actual $vdev"
fi
done
done <<<"$status"
expected="$poolname $expected"
@ -295,8 +293,7 @@ function check_pool_healthy
return 1
fi
status=$(echo "$status" | grep "$pool" | grep -v "pool:" | \
awk '{print $2}')
status=$(echo "$status" | awk -v p="$pool" '!/pool:/ && $0 ~ p {print $2}')
if [[ $status != "ONLINE" ]]; then
log_note "Invalid zpool status for '$pool': '$status'" \
@ -314,9 +311,7 @@ function pool_is_replacing
{
typeset pool=$1
zpool status $pool | grep "replacing" | grep "ONLINE" > /dev/null
return $?
zpool status $pool | grep "replacing" | grep -q "ONLINE"
}
function set_vdev_validate_skip

View File

@ -76,11 +76,11 @@ function cleanup_all
#
# Try import individually if 'import -a' failed.
#
for pool in `zpool import | grep "pool:" | awk '{print $2}'`; do
for pool in $(zpool import | awk '/pool:/ {print $2}'); do
zpool import -f $pool
done
for pool in `zpool import -d $DEVICE_DIR | grep "pool:" | awk '{print $2}'`; do
for pool in $(zpool import -d $DEVICE_DIR | awk '/pool:/ {print $2}'); do
log_must zpool import -d $DEVICE_DIR -f $pool
done

View File

@ -65,10 +65,7 @@ log_must zpool export $TESTPOOL
metaslabs=0
bs=512
zdb -p $TESTDIR -Pme $TESTPOOL | awk '/metaslab[ ]+[0-9]+/ { print $4, $8 }' |
while read -r offset_size; do
typeset offset=$(echo $offset_size | cut -d ' ' -f1)
typeset size=$(echo $offset_size | cut -d ' ' -f2)
while read -r offset size; do
log_note "offset: '$offset'"
log_note "size: '$size'"

View File

@ -28,8 +28,8 @@
# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
#
export DISK1=${DISKS%% *}
export DISK2=$(echo $DISKS | awk '{print $2}')
read -r DISK1 DISK2 _ <<<"$DISKS"
export DISK1 DISK2
export ZFS_SCAN_VDEV_LIMIT_SLOW=$((128*1024))
export ZFS_SCAN_VDEV_LIMIT_DEFAULT=$((4*1024*1024))

View File

@ -71,12 +71,11 @@ fi
# Verify we can set a combination of valid property values on the new pool
for prop in "${good_props[@]}"
do
propname="$(awk -F= '{print $1}' <<< $prop)"
propval="$(awk -F= '{print $2}' <<< $prop)"
IFS='=' read -r propname propval <<<"$prop"
setup_mirror
log_must zpool split -o $prop $TESTPOOL $TESTPOOL2
log_must zpool import -N -d $TEST_BASE_DIR $TESTPOOL2
log_must test "$(get_pool_prop $propname $TESTPOOL2)" == "$propval"
log_must test "$(get_pool_prop $propname $TESTPOOL2)" = "$propval"
destroy_pool $TESTPOOL
destroy_pool $TESTPOOL2

View File

@ -122,7 +122,7 @@ typeset altroot="$TESTDIR/altroot-$TESTPOOL2"
for config in "${goodconfs[@]}"
do
create_config="${config%% *}"
add_config="$(awk '{$1= "";print $0}' <<< $config)"
add_config="$(awk '{$1=""; print $0}' <<< $config)"
log_must zpool create $TESTPOOL $(pool_config $create_config)
for vdev in $add_config; do
log_must zpool add -f $TESTPOOL $(pool_config $vdev)
@ -137,7 +137,7 @@ done
for config in "${badconfs[@]}"
do
create_config="${config%% *}"
add_config="$(awk '{$1= "";print $0}' <<< $config)"
add_config="$(awk '{$1=""; print $0}' <<< $config)"
log_must zpool create $TESTPOOL $(pool_config $create_config)
for vdev in $add_config; do
log_must zpool add -f $TESTPOOL $(pool_config $vdev)

View File

@ -132,8 +132,7 @@ function check_poolversion
fi
# check version using zpool upgrade
actual=$(zpool upgrade | grep $pool$ | \
awk '{print $1}' | sed -e 's/ //g')
actual=$(zpool upgrade | awk -v p="$pool$" '$0 ~ p {gsub(/ /, "", $1); print $1}')
if [[ $actual != $vers ]] ; then
log_fail "$pool: zpool reported version $actual, expected $vers"
fi

View File

@ -55,6 +55,6 @@ TEMPFILE="$TEST_BASE_DIR/zfs_001_neg.$$.txt"
zfs > $TEMPFILE 2>&1
log_must grep "usage: zfs command args" "$TEMPFILE"
log_must eval "awk '{if (length(\$0) > 80) exit 1}' < $TEMPFILE"
log_must awk '{if (length($0) > 80) exit 1}' $TEMPFILE
log_pass "zfs shows a usage message when run as a user"

View File

@ -59,6 +59,6 @@ log_assert "zpool shows a usage message when run as a user"
eval "zpool > $TEMPFILE 2>&1"
log_must grep "usage: zpool command args" "$TEMPFILE"
log_must eval "awk '{if (length(\$0) > 80) exit 1}' < $TEMPFILE"
log_must awk '{if (length($0) > 80) exit 1}' $TEMPFILE
log_pass "zpool shows a usage message when run as a user"

View File

@ -54,12 +54,12 @@ while [[ $i -lt ${#args[*]} ]]
do
PROP=${props[$i]}
EXPECTED=${prop_vals[$i]}
ACTUAL=$( zpool get $PROP $TESTPOOL | grep $PROP | awk '{print $1}' )
ACTUAL=$( zpool get $PROP $TESTPOOL | awk -v p=$PROP '$0 ~ p {print $1}' )
if [ "$ACTUAL" != "$EXPECTED" ]
then
log_fail "Property $PROP value was $ACTUAL, expected $EXPECTED"
fi
i=$(( $i + 1 ))
i=$(( $i + 1 ))
done
log_must zpool get all $TESTPOOL

View File

@ -59,7 +59,7 @@ do
log_mustnot $POOL set $PROP=$NEW $TESTPOOL
# Now verify that the above command did nothing
ACTUAL=$( zpool get $PROP $TESTPOOL | grep $PROP | awk '{print $1}' )
ACTUAL=$( zpool get $PROP $TESTPOOL | awk -v p=$PROP '$0 ~ p {print $1}' )
if [ "$ACTUAL" != "$EXPECTED" ]
then
log_fail "Property $PROP was set to $ACTUAL, expected $EXPECTED"

View File

@ -120,7 +120,7 @@ function verify_reverse_sort { # command list name
function is_fs_type_zfs {
typeset dirname=$1
typeset fs="$(df $dirname | tail -1 | awk '{print $NF}')"
typeset fs="$(df $dirname | awk 'END {print $NF}')"
if is_freebsd; then
fs_type=$(mount | awk -v fs=$fs '{if ($3 == fs) print $4}' \

View File

@ -60,8 +60,8 @@ log_must file_write -o $OP -f $TESTDIR/$TESTFILE1 -b $BLOCKSZ \
sleep 60
FILE0_BLKS=`du -k $TESTDIR/$TESTFILE0 | awk '{ print $1}'`
FILE1_BLKS=`du -k $TESTDIR/$TESTFILE1 | awk '{ print $1}'`
FILE0_BLKS=`du -k $TESTDIR/$TESTFILE0 | awk '{print $1}'`
FILE1_BLKS=`du -k $TESTDIR/$TESTFILE1 | awk '{print $1}'`
if [[ $FILE0_BLKS -le $FILE1_BLKS ]]; then
log_fail "$TESTFILE0 is smaller than $TESTFILE1" \

View File

@ -65,8 +65,8 @@ log_must file_write -o $OP -f $TESTDIR1/$TESTFILE1 -b $BLOCKSZ \
sleep 60
FILE0_BLKS=`du -k $TESTDIR1/$TESTFILE0 | awk '{ print $1}'`
FILE1_BLKS=`du -k $TESTDIR1/$TESTFILE1 | awk '{ print $1}'`
FILE0_BLKS=`du -k $TESTDIR1/$TESTFILE0 | awk '{print $1}'`
FILE1_BLKS=`du -k $TESTDIR1/$TESTFILE1 | awk '{print $1}'`
if [[ $FILE0_BLKS -le $FILE1_BLKS ]]; then
log_fail "$TESTFILE0 is smaller than $TESTFILE1" \

View File

@ -391,12 +391,11 @@ function verify_send
user_run $user eval "zfs send $snap > $bak_user"
log_must eval "zfs send $snap > $bak_root"
if [[ $(checksum $bak_user) == $(checksum $bak_root) ]]; then
if [ "$(cksum < $bak_user)" = "$(cksum < $bak_root)" ]; then
ret=0
fi
rm -rf $bak_user > /dev/null
rm -rf $bak_root > /dev/null
rm -rf $bak_user $bak_root
return $ret
}
@ -462,12 +461,11 @@ function verify_fs_receive
log_must eval "zfs receive $dtst < $bak_root"
log_must eval "zfs send $dtstsnap > $bak_root"
log_must_busy zfs destroy -rf $dtst
if [[ $(checksum $bak_user) != $(checksum $bak_root) ]]; then
if [ "$(cksum < $bak_user)" != "$(cksum < $bak_root)" ]; then
return 1
fi
rm -rf $bak_user > /dev/null
rm -rf $bak_root > /dev/null
rm -rf $bak_user $bak_root
done

View File

@ -33,6 +33,4 @@ VDEV4=$TEST_BASE_DIR/vdev4
export TMP_EVENTS=$TEST_BASE_DIR/tmp_events.$$
export TMP_EVENTS_FULL=$TEST_BASE_DIR/tmp_events_full.$$
export TMP_EVENT_FULL=$TEST_BASE_DIR/tmp_event_full.$$
export TMP_EVENTS_ZED=$TEST_BASE_DIR/tmp_events_zed.$$
export TMP_EVENT_ZED=$TEST_BASE_DIR/tmp_event_zed.$$

View File

@ -42,15 +42,8 @@ verify_runnable "both"
function cleanup
{
if poolexists $MPOOL; then
destroy_pool $MPOOL
fi
for file in $VDEV1 $VDEV2; do
[[ -f $file ]] && rm -f $file
done
log_must rm -f $TMP_EVENTS_ZED
poolexists $MPOOL && log_must destroy_pool $MPOOL
log_must rm -f $VDEV1 $VDEV2 $TMP_EVENTS_ZED
log_must zed_stop
}
@ -69,10 +62,9 @@ log_must zed_start
log_must file_wait_event $ZED_DEBUG_LOG 'sysevent\.fs\.zfs\.config_sync' 150
log_must cp $ZED_DEBUG_LOG $TMP_EVENTS_ZED
awk -v event="sysevent.fs.zfs.pool_create" \
'BEGIN{FS="\n"; RS=""} $0 ~ event { print $0 }' \
$TMP_EVENTS_ZED >$TMP_EVENT_ZED
log_must grep -q "^ZEVENT_POOL=$MPOOL" $TMP_EVENT_ZED
log_mustnot awk -v event="sysevent.fs.zfs.pool_create" -v crit="\\nZEVENT_POOL=$MPOOL" \
'BEGIN{FS="\n"; RS=""} $0 ~ event && $0 ~ crit { exit 1 }' \
$TMP_EVENTS_ZED
# 3. Stop the ZED
zed_stop

View File

@ -94,7 +94,7 @@ function run_and_verify
pool=${pool:-$TESTPOOL}
fullcmd="$1"
cmd=$(echo $fullcmd | awk '{print $1}')
read -r cmd _ <<<"$fullcmd"
# If we aren't running zpool or zfs, something is wrong
[[ $cmd == "zpool" || $cmd == "zfs" ]] || \
@ -147,23 +147,20 @@ function run_and_verify
log_must grep -q "$event" $TMP_EVENTS
# Verify the event is in the verbose output with pool name.
awk -v event="$event" \
'BEGIN{FS="\n"; RS=""} $0 ~ event { print $0 }' \
$TMP_EVENTS_FULL >$TMP_EVENT_FULL
log_must grep -q "pool = \"$pool\"" $TMP_EVENT_FULL
log_mustnot awk -v event="$event" -v crit="pool = \"$pool\"" \
'BEGIN{FS="\n"; RS=""} $0 ~ event && $0 ~ crit { exit 1 }' \
$TMP_EVENTS_FULL
# all-debug.sh filters history events (seen in ZED_DEBUG_LOG)
if [[ "$event" == "sysevent.fs.zfs.history_event" ]]; then
if [ "$event" = "sysevent.fs.zfs.history_event" ]; then
continue
fi
# Verify the event was received by the ZED and logged.
awk -v event="$event" \
'BEGIN{FS="\n"; RS=""} $0 ~ event { print $0 }' \
$TMP_EVENTS_ZED >$TMP_EVENT_ZED
log_must grep -q "^ZEVENT_POOL=$pool" $TMP_EVENT_ZED
log_mustnot awk -v event="$event" -v crit="\\nZEVENT_POOL=$pool" \
'BEGIN{FS="\n"; RS=""} $0 ~ event && $0 ~ crit { exit 1 }' \
$TMP_EVENTS_ZED
done
rm -f $TMP_EVENTS $TMP_EVENTS_FULL $TMP_EVENT_FULL \
$TMP_EVENTS_ZED $TMP_EVENT_ZED
rm -f $TMP_EVENTS $TMP_EVENTS_FULL $TMP_EVENTS_ZED
}

View File

@ -96,8 +96,7 @@ do
log_must zpool create -f $TESTPOOL $conf
block_device_wait ${DEV_DSKDIR}/${removedev}
mntpnt=$(get_prop mountpoint /$TESTPOOL) ||
log_fail "get_prop mountpoint /$TESTPOOL"
mntpnt=$(get_prop mountpoint /$TESTPOOL)
# 2. Simulate physical removal of one device
remove_disk $removedev
@ -128,8 +127,7 @@ do
block_device_wait ${DEV_DSKDIR}/${removedev}
log_must zpool add $TESTPOOL spare $sparedev
mntpnt=$(get_prop mountpoint /$TESTPOOL) ||
log_fail "get_prop mountpoint /$TESTPOOL"
mntpnt=$(get_prop mountpoint /$TESTPOOL)
# 2. Simulate physical removal of one device
remove_disk $removedev
@ -161,8 +159,7 @@ do
block_device_wait ${DEV_DSKDIR}/${removedev}
log_must zpool add $TESTPOOL spare $sparedev
mntpnt=$(get_prop mountpoint /$TESTPOOL) ||
log_fail "get_prop mountpoint /$TESTPOOL"
mntpnt=$(get_prop mountpoint /$TESTPOOL)
# 2. Fault the spare device making it unavailable
log_must zpool offline -f $TESTPOOL $sparedev

View File

@ -72,8 +72,8 @@ echo "alias scsidebug /dev/disk/by-id/$SD_DEVICE_ID" >>$VDEVID_CONF
block_device_wait
SD_DEVICE=$(udevadm info -q all -n $DEV_DSKDIR/$SD | \
awk -F'=' '/ID_VDEV=/{print $2; exit}')
[[ -z $SD_DEVICE ]] && log_fail "vdev rule was not registered properly"
awk -F'=' '/ID_VDEV=/ {print $2; exit}')
[ -z $SD_DEVICE ] && log_fail "vdev rule was not registered properly"
log_must zpool events -c
log_must zpool create -f $TESTPOOL raidz1 $SD_DEVICE $DISK1 $DISK2 $DISK3

View File

@ -67,7 +67,7 @@ log_must mkfile 1048576 /$TESTPOOL/testfile
sync_pool $TESTPOOL
log_must zinject -c all
SLOW_IOS=$(zpool status -sp | grep "$DISK" | awk '{print $6}')
SLOW_IOS=$(zpool status -sp | awk -v d="$DISK" '$0 ~ d {print $6}')
DELAY_EVENTS=$(zpool events | grep delay | wc -l)
if [ $SLOW_IOS -gt 0 ] && [ $DELAY_EVENTS -gt 0 ] ; then

View File

@ -73,7 +73,7 @@ log_must zfs umount $TEST_FS
for ((i=0; i < ${#dnsizes[*]}; i++)) ; do
dnsize=$(zdb -dddd $TEST_FS ${inodes[$i]} |
awk '/ZFS plain file/ {print $6}' | tr K k)
awk '/ZFS plain file/ {gsub(/K/, "k", $6); print $6}')
if [[ "$dnsize" != "${dnsizes[$i]}" ]]; then
log_fail "dnode size is $dnsize (expected ${dnsizes[$i]})"
fi

View File

@ -59,7 +59,6 @@ log_assert "Verify zpool sub-commands which modify state are logged."
log_onexit cleanup
mntpnt=$(get_prop mountpoint $TESTPOOL)
(( $? != 0)) && log_fail "get_prop($TESTPOOL mountpoint)"
VDEV1=$mntpnt/vdev1; VDEV2=$mntpnt/vdev2;
VDEV3=$mntpnt/vdev3; VDEV4=$mntpnt/vdev4;

View File

@ -55,7 +55,6 @@ log_assert "zpool history limitation test."
log_onexit cleanup
mntpnt=$(get_prop mountpoint $TESTPOOL)
(( $? != 0 )) && log_fail "get_prop mountpoint $TESTPOOL"
VDEV0=$mntpnt/vdev0
log_must mkfile $MINVDEVSIZE $VDEV0
@ -79,16 +78,16 @@ done
TMPFILE=$TEST_BASE_DIR/spool.$$
zpool history $spool >$TMPFILE
typeset -i entry_count=$(wc -l $TMPFILE | awk '{print $1}')
typeset -i entry_count=$(wc -l < $TMPFILE)
typeset final_md5=$(head -2 $TMPFILE | md5digest)
grep 'zpool create' $TMPFILE >/dev/null 2>&1 ||
grep -q 'zpool create' $TMPFILE ||
log_fail "'zpool create' was not found in pool history"
grep 'zfs create' $TMPFILE >/dev/null 2>&1 &&
grep -q 'zfs create' $TMPFILE &&
log_fail "'zfs create' was found in pool history"
grep 'zfs set compress' $TMPFILE >/dev/null 2>&1 ||
grep -q 'zfs set compress' $TMPFILE ||
log_fail "'zfs set compress' was found in pool history"
# Verify that the creation of the pool was preserved in the history.

View File

@ -46,7 +46,7 @@ verify_runnable "global"
log_assert "'zpool history' can cope with simultaneous commands."
typeset -i orig_count=$(zpool history $spool | wc -l | awk '{print $1}')
typeset -i orig_count=$(zpool history $spool | wc -l)
typeset -i i=0
while ((i < 10)); do
@ -90,7 +90,7 @@ while ((i < 10)); do
((i += 1))
done
typeset -i entry_count=$(zpool history $spool | wc -l | awk '{print $1}')
typeset -i entry_count=$(zpool history $spool | wc -l)
if ((entry_count - orig_count != 200)); then
log_fail "The entries count error: entry_count=$entry_count " \

View File

@ -52,14 +52,12 @@ function run_and_verify
flags="$2"
if is_illumos; then
histcmd=$(echo $fullcmd | sed 's/\/usr\/sbin\///g')
histcmd=$(echo $fullcmd | sed 's=/usr/sbin/==g')
else
histcmd=$(echo $fullcmd | sed 's/^.*\/\(zpool .*\).*$/\1/')
histcmd=$(echo $histcmd | sed 's/^.*\/\(zfs .*\).*$/\1/')
histcmd=$(echo $fullcmd | sed -E 's=^.*/(zpool|zfs)$=\1=')
fi
cmd=$(echo $histcmd | awk '{print $1}')
subcmd=$(echo $histcmd | awk '{print $2}')
read -r cmd subcmd _ <<<"$histcmd"
# If we aren't running zpool or zfs, something is wrong
[[ $cmd == "zpool" || $cmd == "zfs" ]] || \
@ -77,11 +75,10 @@ function run_and_verify
log_must_busy user_run $user "$fullcmd"
fi
zpool history $flags $pool > $TMP_HISTORY 2>/dev/null
diff $OLD_HISTORY $TMP_HISTORY | grep "^> " | sed 's/^> //g' \
> $NEW_HISTORY
diff $OLD_HISTORY $TMP_HISTORY | sed -n 's/^> //gp' > $NEW_HISTORY
# Verify what's common to every case, regardless of zpool history flags.
grep "$histcmd" $NEW_HISTORY >/dev/null 2>&1 || \
grep -q "$histcmd" $NEW_HISTORY || \
log_fail "Didn't find \"$histcmd\" in pool history"
# If 'zpool history' was called without any flags, then we're done.
@ -116,8 +113,7 @@ function verify_long
suffix=":freebsd"
fi
grep -q "$cmd \[user $uid ($user) on $hname$suffix\]" $NEW_HISTORY
if [[ $? != 0 ]]; then
if grep -q "$cmd \[user $uid ($user) on $hname$suffix\]" $NEW_HISTORY; then
log_note "Couldn't find long information for \"$cmd\""
return 1
fi
@ -133,7 +129,8 @@ function verify_hold
[[ $flags =~ "i" ]] || return 1
typeset tag=$(echo $cmd | awk '{print $4}')
typeset tag _
read -r _ _ _ tag _ <<<"$cmd"
typeset fullname=${cmd##* }
typeset dsname=${fullname%%@*}
typeset snapname=${fullname##*@}
@ -141,9 +138,7 @@ function verify_hold
# This works whether or not the hold was recursive
for ds in $(zfs list -r -Ho name -t snapshot $dsname | \
grep "@$snapname"); do
grep "$subcmd $ds ([0-9]*) tag=$tag" $NEW_HISTORY \
>/dev/null 2>&1
if [[ $? != 0 ]]; then
if grep -q "$subcmd $ds ([0-9]*) tag=$tag" $NEW_HISTORY; then
log_note "Didn't find hold on $ds with $tag"
return 1
fi
@ -231,8 +226,7 @@ function verify_allow
# - Whether the operation applies locally or to descendent datasets (or
# both)
#
echo $cmd | awk '{i = NF - 1; print $i}' | grep '@' >/dev/null \
2>&1 && is_set=1
echo $cmd | awk '$(NF - 1) ~ /@/ {exit 1}' || is_set=1
dsname=${cmd##* }
[[ $cmd =~ "-l " ]] && lflag=1
[[ $cmd =~ "-d " ]] && dflag=1
@ -275,7 +269,7 @@ function verify_allow
str="u"
[[ -n $is_set ]] && str="U"
tmp=${cmd##*-u }
opt=$(echo $tmp | awk '{print $2}')
read -r _ opt _ <<<"$opt"
uid=$(id -u ${tmp%% *})
if [[ -n $lflag ]]; then
code="${str}l\$$uid $opt"
@ -299,7 +293,7 @@ function verify_allow
str="g"
[[ -n $is_set ]] && str="G"
tmp=${cmd##*-g }
opt=$(echo $tmp | awk '{print $2}')
read -r _ opt _ <<<"$opt"
gid=$(awk -F: "/^${tmp%% *}:/ {print \$3}" /etc/group)
if [[ -n $lflag ]]; then
code="${str}l\$$gid $opt"

View File

@ -77,7 +77,7 @@ set -A vdevs "" "mirror" "raidz" "raidz1" "raidz2"
typeset -i i=0
PREVDUMPDEV=`dumpadm | grep "Dump device" | awk '{print $3}'`
PREVDUMPDEV=`dumpadm | awk '/Dump device/ {print $3}'`
unset NOINUSE_CHECK
while (( i < ${#vdevs[*]} )); do

View File

@ -82,7 +82,7 @@ set -A vdevs "" "mirror" "raidz" "raidz1" "raidz2"
typeset -i i=0
PREVDUMPDEV=`dumpadm | grep "Dump device" | awk '{print $3}'`
PREVDUMPDEV=`dumpadm | awk '/Dump device/ {print $3}'`
while (( i < ${#vdevs[*]} )); do
typeset spare="spare $sdisks"

Some files were not shown because too many files have changed in this diff Show More