]> git.proxmox.com Git - mirror_zfs.git/blobdiff - tests/zfs-tests/include/libtest.shlib
Do not iterate through filesystems unnecessarily
[mirror_zfs.git] / tests / zfs-tests / include / libtest.shlib
index e5a3d63a40d3bf98c11651414e7c921b878227c7..ea9448353b68fc0732b9542015ae70310fa63386 100644 (file)
 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 # Copyright (c) 2012, 2017 by Delphix. All rights reserved.
-# Copyright 2016 Nexenta Systems, Inc.
+# Copyright (c) 2017 by Tim Chase. All rights reserved.
+# Copyright (c) 2017 by Nexenta Systems, Inc. All rights reserved.
 # Copyright (c) 2017 Lawrence Livermore National Security, LLC.
 # Copyright (c) 2017 Datto Inc.
 # Copyright (c) 2017 Open-E, Inc. All Rights Reserved.
+# Use is subject to license terms.
 #
 
 . ${STF_TOOLS}/include/logapi.shlib
@@ -642,7 +644,7 @@ function destroy_snapshot
        typeset snap=${1:-$TESTPOOL/$TESTFS@$TESTSNAP}
 
        if ! snapexists $snap; then
-               log_fail "'$snap' does not existed."
+               log_fail "'$snap' does not exist."
        fi
 
        #
@@ -1029,7 +1031,7 @@ function get_endslice #<disk> <slice>
 
                ((endcyl = (endcyl + 1) / ratio))
        fi
-       
+
        echo $endcyl
 }
 
@@ -1092,14 +1094,14 @@ function fill_fs # destdir dirnum filenum bytes num_writes data
        typeset -i filenum=${3:-50}
        typeset -i bytes=${4:-8192}
        typeset -i num_writes=${5:-10240}
-       typeset -i data=${6:-0}
+       typeset data=${6:-0}
 
        typeset -i odirnum=1
        typeset -i idirnum=0
        typeset -i fn=0
        typeset -i retval=0
 
-       log_must mkdir -p $destdir/$idirnum
+       mkdir -p $destdir/$idirnum
        while (($odirnum > 0)); do
                if ((dirnum >= 0 && idirnum >= dirnum)); then
                        odirnum=0
@@ -1115,7 +1117,7 @@ function fill_fs # destdir dirnum filenum bytes num_writes data
                if (($fn >= $filenum)); then
                        fn=0
                        ((idirnum = idirnum + 1))
-                       log_must mkdir -p $destdir/$idirnum
+                       mkdir -p $destdir/$idirnum
                else
                        ((fn = fn + 1))
                fi
@@ -1230,30 +1232,11 @@ function datasetnonexists
        return 0
 }
 
-#
-# Given a mountpoint, or a dataset name, determine if it is shared via NFS.
-#
-# Returns 0 if shared, 1 otherwise.
-#
-function is_shared
+function is_shared_impl
 {
        typeset fs=$1
        typeset mtpt
 
-       if [[ $fs != "/"* ]] ; then
-               if datasetnonexists "$fs" ; then
-                       return 1
-               else
-                       mtpt=$(get_prop mountpoint "$fs")
-                       case $mtpt in
-                               none|legacy|-) return 1
-                                       ;;
-                               *)      fs=$mtpt
-                                       ;;
-                       esac
-               fi
-       fi
-
        if is_linux; then
                for mtpt in `share | awk '{print $1}'` ; do
                        if [[ $mtpt == $fs ]] ; then
@@ -1277,6 +1260,33 @@ function is_shared
        return 1
 }
 
+#
+# Given a mountpoint, or a dataset name, determine if it is shared via NFS.
+#
+# Returns 0 if shared, 1 otherwise.
+#
+function is_shared
+{
+       typeset fs=$1
+       typeset mtpt
+
+       if [[ $fs != "/"* ]] ; then
+               if datasetnonexists "$fs" ; then
+                       return 1
+               else
+                       mtpt=$(get_prop mountpoint "$fs")
+                       case $mtpt in
+                               none|legacy|-) return 1
+                                       ;;
+                               *)      fs=$mtpt
+                                       ;;
+                       esac
+               fi
+       fi
+
+       is_shared_impl "$fs"
+}
+
 #
 # Given a dataset name determine if it is shared via SMB.
 #
@@ -1923,6 +1933,23 @@ function verify_filesys # pool filesystem dir
        log_must rm -rf $zdbout
 }
 
+#
+# Given a pool issue a scrub and verify that no checksum errors are reported.
+#
+function verify_pool
+{
+       typeset pool=${1:-$TESTPOOL}
+
+       log_must zpool scrub $pool
+       log_must wait_scrubbed $pool
+
+       cksum=$(zpool status $pool | awk 'L{print $NF;L=0} /CKSUM$/{L=1}')
+       if [[ $cksum != 0 ]]; then
+               log_must zpool status -v
+               log_fail "Unexpected CKSUM errors found on $pool ($cksum)"
+       fi
+}
+
 #
 # Given a pool, and this function list all disks in the pool
 #
@@ -1932,7 +1959,7 @@ function get_disklist # pool
 
        disklist=$(zpool iostat -v $1 | nawk '(NR >4) {print $1}' | \
            grep -v "\-\-\-\-\-" | \
-           egrep -v -e "^(mirror|raidz1|raidz2|spare|log|cache)$")
+           egrep -v -e "^(mirror|raidz[1-3]|spare|log|cache|special|dedup)$")
 
        echo $disklist
 }
@@ -2567,7 +2594,6 @@ function verify_opt_p_ops
                                        "when ops is $ops."
                        fi
                        log_must datasetexists $dataset
-                       log_mustnot snapexists $dataset
                        ;;
                *)
                        log_fail "$ops is not supported."
@@ -3017,8 +3043,11 @@ function vdevs_in_pool
 
        shift
 
+       # We could use 'zpool list' to only get the vdevs of the pool but we
+       # can't reference a mirror/raidz vdev using its ID (i.e mirror-0),
+       # therefore we use the 'zpool status' output.
        typeset tmpfile=$(mktemp)
-       zpool list -Hv "$pool" >$tmpfile
+       zpool status -v "$pool" | grep -A 1000 "config:" >$tmpfile
        for vdev in $@; do
                grep -w ${vdev##*/} $tmpfile >/dev/null 2>&1
                [[ $? -ne 0 ]] && return 1
@@ -3181,14 +3210,10 @@ function wait_replacing #pool
 function wait_scrubbed
 {
        typeset pool=${1:-$TESTPOOL}
-       typeset iter=${2:-10}
-       for i in {1..$iter} ; do
-               if is_pool_scrubbed $pool ; then
-                       return 0
-               fi
-               sleep 1
+       while true ; do
+               is_pool_scrubbed $pool && break
+               log_must sleep 1
        done
-       return 1
 }
 
 # Backup the zed.rc in our test directory so that we can edit it for our test.
@@ -3323,7 +3348,7 @@ function zed_stop
 
        log_note "Stopping ZED"
        if [[ -f ${ZEDLET_DIR}/zed.pid ]]; then
-               zedpid=$(cat ${ZEDLET_DIR}/zed.pid)
+               zedpid=$(<${ZEDLET_DIR}/zed.pid)
                kill $zedpid
                while ps -p $zedpid > /dev/null; do
                        sleep 1