Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Apr 2016 22:07:33 +0000 (UTC)
From:      Alan Somers <asomers@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r297882 - in projects/zfsd/head/tests/sys/cddl/zfs: . include tests/cache tests/cachefile tests/hotspare tests/zfsd
Message-ID:  <201604122207.u3CM7XU0063124@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: asomers
Date: Tue Apr 12 22:07:33 2016
New Revision: 297882
URL: https://svnweb.freebsd.org/changeset/base/297882

Log:
  Fix several intermittent ZFS tests.
  
  tests/sys/cddl/zfs/tests/zfsd/zfsd.kshlib
  tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_003_pos.ksh
  	Fix several intermittent tests.  These tests all disable a disk's
  	phy and wait for the disk to enter the REMOVED state.  However,
  	sometimes the disk enters the UNAVAIL state instead.  I don't know
  	why.  The fix is to accept UNAVAIL disks as well as REMOVED disks in
  	wait_for_pool_removal, because it doesn't make a difference to the
  	logic under test.
  
  tests/sys/cddl/zfs/include/libtest.kshlib
          Remove floating point variables.  Use 64-bit ints instead.
  
          Fix the raidz_dva_to_block_addr function.  It had multiple errors:
          * Used floating point
          * The 4MB offset was not adjusted for ashift
          * Unnecessarily complicated rounding procedure
          * Its caller, corrupt_file, was assuming ashift=9
  
  	Fix occasional failures cleaning up GPT partitions.  The error was
  	EBUSY; debug code caught the geom provider with an active reader
  	(r1w0e0).  Since the test case is single threaded, it is speculated
  	that another process outside of Kyua was probing the device while
  	the test case was attempting to delete the partition table.
  
  	Added a retry wipe_partition_table()'s gpart destroy command.
  
  tests/sys/cddl/zfs/Makefile
  tests/sys/cddl/zfs/include/Makefile
  tests/sys/cddl/zfs/include/libtest_test.kshlib
  	Add unit tests for raidz_dva_to_block_addr
  
  tests/sys/cddl/zfs/tests/cachefile/cachefile_003_pos.ksh
  tests/sys/cddl/zfs/tests/cache/cache_008_neg.ksh
  	Always use "-f" when destroying pools except when testing the
  	functionality of the non -f command.  Fixes intermittency.
  
  tests/sys/cddl/zfs/tests/hotspare/hotspare_scrub_002_pos.ksh
  	After scrubbing the pool with spare attached, detach the original
  	device, clear errors, and scrub again.  Assert that no new errors
  	are found.  I don't know why, but on FreeBSD 11 "zpool scrub" will
  	sometimes find some errors on the spare device even though it
  	doesn't find them all.
  
  Sponsored by:	Spectra Logic Corp

Added:
  projects/zfsd/head/tests/sys/cddl/zfs/include/libtest_test.sh   (contents, props changed)
Modified:
  projects/zfsd/head/tests/sys/cddl/zfs/Makefile
  projects/zfsd/head/tests/sys/cddl/zfs/include/Makefile
  projects/zfsd/head/tests/sys/cddl/zfs/include/libtest.kshlib
  projects/zfsd/head/tests/sys/cddl/zfs/tests/cache/cache_008_neg.ksh
  projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_003_pos.ksh
  projects/zfsd/head/tests/sys/cddl/zfs/tests/hotspare/hotspare_scrub_002_pos.ksh
  projects/zfsd/head/tests/sys/cddl/zfs/tests/zfsd/zfsd.kshlib
  projects/zfsd/head/tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_003_pos.ksh

Modified: projects/zfsd/head/tests/sys/cddl/zfs/Makefile
==============================================================================
--- projects/zfsd/head/tests/sys/cddl/zfs/Makefile	Tue Apr 12 21:47:37 2016	(r297881)
+++ projects/zfsd/head/tests/sys/cddl/zfs/Makefile	Tue Apr 12 22:07:33 2016	(r297882)
@@ -4,9 +4,8 @@
 
 TESTSDIR=	${TESTSBASE}/sys/cddl/zfs
 
-TESTS_SUBDIRS+=	tests
+TESTS_SUBDIRS+=	tests include
 
 SUBDIR+=		bin
-SUBDIR+=		include
 
 .include <bsd.test.mk>

Modified: projects/zfsd/head/tests/sys/cddl/zfs/include/Makefile
==============================================================================
--- projects/zfsd/head/tests/sys/cddl/zfs/include/Makefile	Tue Apr 12 21:47:37 2016	(r297881)
+++ projects/zfsd/head/tests/sys/cddl/zfs/include/Makefile	Tue Apr 12 22:07:33 2016	(r297882)
@@ -24,4 +24,6 @@ CLEANFILES+=	default.cfg
 default.cfg:	default.cfg.in
 	sed "s:%%STFSUITEDIR%%:${STFSUITEDIR}:" ${.ALLSRC} > ${.TARGET}
 
-.include <bsd.prog.mk>
+TESTSDIR=${TESTSBASE}/sys/cddl/zfs/include
+ATF_TESTS_KSH93+=	libtest_test
+.include <bsd.test.mk>

Modified: projects/zfsd/head/tests/sys/cddl/zfs/include/libtest.kshlib
==============================================================================
--- projects/zfsd/head/tests/sys/cddl/zfs/include/libtest.kshlib	Tue Apr 12 21:47:37 2016	(r297881)
+++ projects/zfsd/head/tests/sys/cddl/zfs/include/libtest.kshlib	Tue Apr 12 22:07:33 2016	(r297882)
@@ -631,7 +631,7 @@ function wipe_partition_table #<whole_di
 		typeset diskname=$1
 		[ ! -e $diskname ] && log_fail "ERROR: $diskname doesn't exist"
 		if gpart list $(basename $diskname) >/dev/null 2>&1; then
-			log_must $GPART destroy -F $diskname
+			wait_for 5 1 $GPART destroy -F $diskname
 		else
 			log_note "No GPT partitions detected on $diskname"
 		fi
@@ -1336,17 +1336,18 @@ function wait_for # timeout dt <method> 
 # Verify a given disk is online or offline
 #
 # Return 0 is pool/disk matches expected state, 1 otherwise
+# stateexpr is a regex like ONLINE or REMOVED|UNAVAIL
 #
-function check_state # pool disk state{online,offline}
+function check_state # pool disk stateexpr
 {
 	typeset pool=$1
 	typeset disk=${2#/dev/dsk/}
 	disk=${disk#/dev/rdsk/}
 	disk=${disk#/dev/}
-	typeset state=$3
+	typeset stateexpr=$3
 
 	$ZPOOL status -v $pool | grep "$disk"  \
-	    | grep -i "$state" > /dev/null 2>&1
+	    | egrep -i "$stateexpr" > /dev/null 2>&1
 
 	return $?
 }
@@ -3212,32 +3213,24 @@ function dva_to_block_addr # dva
 
 #
 # Convert a RAIDZ DVA into a physical block address.  This has the same
-# output as dva_to_block_addr, but is more complicated due to RAIDZ.  ashift
-# is normally always 9, but RAIDZ uses the actual tvd ashift instead.
-# Furthermore, the number of vdevs changes the actual block for each device.
-# This is also tricky because ksh93 requires special effort to round up.
+# output as dva_to_block_addr (number of blocks from beginning of device), but
+# is more complicated due to RAIDZ.  ashift is normally always 9, but RAIDZ
+# uses the actual tvd ashift instead.  Furthermore, the number of vdevs changes
+# the actual block for each device.
 #
 function raidz_dva_to_block_addr # dva ncols ashift
 {
 	typeset dva=$1
-	typeset -F ncols="${2}.0"
-	typeset -i ashift=$3
+	typeset -i ncols=$2
+        typeset -i ashift=$3
 
 	typeset -i offset=0x$(echo $dva | cut -f2 -d:)
 	(( offset >>= ashift ))
 
-	# Calculate the floating point offset after dividing by #columns.
-	typeset -F foff=$offset
-	(( foff /= ncols ))
-
-	# Convert the calculation to integer, then figure out if the
-	# remainder requires rounding up the integer calculation.
-	typeset -i ioff=$foff
-	(( foff -= ioff ))
-	[[ $foff -ge 0.5 ]] && (( ioff += 1 ))
+	typeset -i ioff=$(( (offset + ncols - 1) / ncols  ))
 
 	# Now add the front 4MB and return.
-	(( ioff += 8192 ))
+	(( ioff += ( 4194304 >> $ashift ) ))
 	echo "$ioff"
 }
 
@@ -3313,10 +3306,10 @@ function vdevs_for_tvd # pool tvd
 }
 
 #
-# Get a vdev path & offset for a given pool/dataset and DVA.
+# Get a vdev path, ashift & offset for a given pool/dataset and DVA.
 # If desired, can also select the toplevel vdev child number.
 #
-function dva_to_vdev_off # pool/dataset dva [leaf_vdev_num]
+function dva_to_vdev_ashift_off # pool/dataset dva [leaf_vdev_num]
 {
 	typeset poollike=$1
 	typeset dva=$2
@@ -3343,10 +3336,11 @@ function dva_to_vdev_off # pool/dataset 
 		off=$(raidz_dva_to_block_addr $dva $nchildren $ashift)
 		;;
 	*)
+		ashift=9
 		off=$(dva_to_block_addr $dva)
 		;;
 	esac
-	echo "${lvd}:${off}"
+	echo "${lvd}:${ashift}:${off}"
 }
 
 #
@@ -3357,14 +3351,14 @@ function file_dva # dataset filepath [le
 	typeset dataset=$1
 	typeset filepath=$2
 	typeset -i level=$3
-	typeset -F offset=$4
+	typeset -i offset=$4
 	typeset -i dva_num=$5
 
 	# A lot of these numbers can be larger than 32-bit, so we have to
 	# use floats to manage them...  :(
-	typeset -F blksz=0
+	typeset -i blksz=0
 	typeset -i blknum=0
-	typeset -F startoff
+	typeset -i startoff
 
 	# The inner match is for 'DVA[0]=<0:1b412600:200>', in which the
 	# text surrounding the actual DVA is a fixed size with 8 characters
@@ -3401,7 +3395,7 @@ function file_dva # dataset filepath [le
 			# Calculate the actual desired block starting offset.
 			if (( level > 0 )); then
 				typeset -i nbps_per_level
-				typeset -F indsz
+				typeset -i indsz
 				typeset -i i=0
 
 				(( nbps_per_level = iblksz / 128 ))
@@ -3419,7 +3413,7 @@ function file_dva # dataset filepath [le
 		fi
 
 		typeset lineoffstr=$(echo $line | cut -d " " -f1)
-		typeset -F lineoff=$(printf "%d" "0x${lineoffstr}")
+		typeset -i lineoff=$(printf "%d" "0x${lineoffstr}")
 		typeset dva="$(echo $line | cut -d " " -f2)"
 		log_debug "str='$lineoffstr' lineoff='$lineoff' dva='$dva'"
 		if [[ -n "$dva" ]] && (( lineoff == startoff )); then
@@ -3443,12 +3437,14 @@ function corrupt_file # dataset filepath
 	dva=$(file_dva $dataset $filepath)
 	[ $? -ne 0 ] && log_fail "ERROR: Can't find file $filepath on $dataset"
 
-	vdoff=$(dva_to_vdev_off $dataset $dva $leaf_vdev_num)
+	vdoff=$(dva_to_vdev_ashift_off $dataset $dva $leaf_vdev_num)
 	vdev=$(echo $vdoff | cut -d: -f1)
-	off=$(echo $vdoff | cut -d: -f2)
+	ashift=$(echo $vdoff | cut -d: -f2)
+	off=$(echo $vdoff | cut -d: -f3)
+	blocksize=$(( 1 << $ashift ))
 
-	log_note "Corrupting ${dataset}'s $filepath on $vdev at DVA $dva"
-	log_must $DD if=/dev/urandom of=$vdev seek=$off count=1 conv=notrunc
+	log_note "Corrupting ${dataset}'s $filepath on $vdev at DVA $dva with ashift $ashift"
+	log_must $DD if=/dev/urandom bs=$blocksize of=$vdev seek=$off count=1 conv=notrunc
 }
 
 #

Added: projects/zfsd/head/tests/sys/cddl/zfs/include/libtest_test.sh
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/zfsd/head/tests/sys/cddl/zfs/include/libtest_test.sh	Tue Apr 12 22:07:33 2016	(r297882)
@@ -0,0 +1,42 @@
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2016 Spectra Logic.  All rights reserved.
+# Use is subject to license terms.
+#
+
+atf_test_case raidz_dva_to_block_addr
+raidz_dva_to_block_addr_head()
+{
+	atf_set "descr" "Unit tests for raidz_dva_to_block_addr"
+}
+raidz_dva_to_block_addr_body()
+{
+	. $(atf_get_srcdir)/default.cfg
+
+	# These test cases were determined by hand on an actual filesystem
+	atf_check_equal 3211 `raidz_dva_to_block_addr 0:3f40000:4000 3 13`
+}
+
+atf_init_test_cases()
+{
+	atf_add_test_case raidz_dva_to_block_addr
+}

Modified: projects/zfsd/head/tests/sys/cddl/zfs/tests/cache/cache_008_neg.ksh
==============================================================================
--- projects/zfsd/head/tests/sys/cddl/zfs/tests/cache/cache_008_neg.ksh	Tue Apr 12 21:47:37 2016	(r297881)
+++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cache/cache_008_neg.ksh	Tue Apr 12 22:07:33 2016	(r297882)
@@ -71,7 +71,7 @@ do
 		log_mustnot verify_cache_device \
 			$TESTPOOL $ldev 'ONLINE' $cachetype
 
-		log_must $ZPOOL destroy $TESTPOOL
+		log_must $ZPOOL destroy -f $TESTPOOL
 	done
 done
 

Modified: projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_003_pos.ksh
==============================================================================
--- projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_003_pos.ksh	Tue Apr 12 21:47:37 2016	(r297881)
+++ projects/zfsd/head/tests/sys/cddl/zfs/tests/cachefile/cachefile_003_pos.ksh	Tue Apr 12 22:07:33 2016	(r297882)
@@ -103,7 +103,7 @@ while (( i < ${#opts[*]} )); do
 		log_fail "cachefile property not set as expected. " \
 			"Expect: ${opts[((i+1))]}, Current: $PROP"
 	fi
-	log_must $ZPOOL destroy $TESTPOOL
+	log_must $ZPOOL destroy -f $TESTPOOL
 	(( i = i + 2 ))
 done
 

Modified: projects/zfsd/head/tests/sys/cddl/zfs/tests/hotspare/hotspare_scrub_002_pos.ksh
==============================================================================
--- projects/zfsd/head/tests/sys/cddl/zfs/tests/hotspare/hotspare_scrub_002_pos.ksh	Tue Apr 12 21:47:37 2016	(r297881)
+++ projects/zfsd/head/tests/sys/cddl/zfs/tests/hotspare/hotspare_scrub_002_pos.ksh	Tue Apr 12 22:07:33 2016	(r297882)
@@ -97,6 +97,19 @@ function verify_assertion # odev
 	[[ $(get_cksum $TESTPOOL "spare-0") > 0 ]]
 	spare0_errors=$?
 	log_must [ $sdev_errors -o $spare0_errors ]
+
+	# Now clear the old errors, remove the original device and scrub again.
+	# No new errors should be found, because the scrub should've found and
+	# fixed all errors
+	log_must $ZPOOL clear $TESTPOOL
+	log_must $ZPOOL detach $TESTPOOL $odev
+	$ZPOOL scrub $TESTPOOL
+	while is_pool_scrubbing $TESTPOOL ; do
+		$SLEEP 2
+	done
+	if [ $(get_cksum $TESTPOOL $sdev) -ne 0 ]; then
+		log_fail "ERROR: Scrub missed cksum errors on a spare vdev"
+	fi
 }
 
 log_assert "'zpool scrub' scans spare vdevs"

Modified: projects/zfsd/head/tests/sys/cddl/zfs/tests/zfsd/zfsd.kshlib
==============================================================================
--- projects/zfsd/head/tests/sys/cddl/zfs/tests/zfsd/zfsd.kshlib	Tue Apr 12 21:47:37 2016	(r297881)
+++ projects/zfsd/head/tests/sys/cddl/zfs/tests/zfsd/zfsd.kshlib	Tue Apr 12 22:07:33 2016	(r297882)
@@ -60,7 +60,7 @@ function wait_for_pool_dev_state_change
 function wait_for_pool_removal
 {
 	typeset -i timeout=$1
-	wait_for_pool_dev_state_change $timeout $REMOVAL_DISK REMOVED
+	wait_for_pool_dev_state_change $timeout $REMOVAL_DISK "REMOVED|UNAVAIL"
 }
 
 function wait_until_scrubbed
@@ -122,6 +122,7 @@ function do_autoreplace
 			check_state $TESTPOOL $SPARE_DISK "ONLINE" && break
 			$SLEEP 6
 		done
+		zpool status $TESTPOOL
 		log_must check_state $TESTPOOL "$SPARE_DISK" "ONLINE"
 
 		wait_until_resilvered

Modified: projects/zfsd/head/tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_003_pos.ksh
==============================================================================
--- projects/zfsd/head/tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_003_pos.ksh	Tue Apr 12 21:47:37 2016	(r297881)
+++ projects/zfsd/head/tests/sys/cddl/zfs/tests/zfsd/zfsd_replace_003_pos.ksh	Tue Apr 12 22:07:33 2016	(r297882)
@@ -69,7 +69,7 @@ function remove_disk
 	[ -n "$FOUNDDISK" ] && log_fail "Disk \"$DISK\" was not removed"
 
 	# Check to make sure ZFS sees the disk as removed
-	wait_for_pool_dev_state_change 20 $DISK REMOVED
+	wait_for_pool_dev_state_change 20 $DISK "REMOVED|UNAVAIL"
 }
 
 # arg1: disk's old devname



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201604122207.u3CM7XU0063124>