summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlek P <[email protected]>2017-05-19 12:33:11 -0700
committerBrian Behlendorf <[email protected]>2017-05-19 12:33:11 -0700
commitbec1067d54a004cb52a4a6762bfa1d4a30300865 (patch)
treea464efb9e42d172cabbe66e7c2fb5296c5e6023d /tests
parent4a283c7f77eb5065e9f03b122bf8ead4f4a1e2be (diff)
Implemented zpool sync command
This addition will enable us to sync an open TXG to the main pool on demand. The functionality is similar to 'sync(2)' but 'zpool sync' will return when data has hit the main storage instead of potentially just the ZIL as is the case with the 'sync(2)' cmd. Reviewed-by: Brian Behlendorf <[email protected]> Reviewed by: Matthew Ahrens <[email protected]> Signed-off-by: Alek Pinchuk <[email protected]> Closes #6122
Diffstat (limited to 'tests')
-rw-r--r--tests/runfiles/linux.run3
-rw-r--r--tests/zfs-tests/include/libtest.shlib29
-rw-r--r--tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_common.kshlib28
-rw-r--r--tests/zfs-tests/tests/functional/cli_root/Makefile.am1
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zpool_create/create-o_ashift.ksh19
-rw-r--r--tests/zfs-tests/tests/functional/cli_root/zpool_sync/Makefile.am6
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zpool_sync/cleanup.ksh32
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zpool_sync/setup.ksh34
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zpool_sync/zpool_sync_001_pos.ksh88
-rwxr-xr-xtests/zfs-tests/tests/functional/cli_root/zpool_sync/zpool_sync_002_neg.ksh44
-rwxr-xr-xtests/zfs-tests/tests/functional/upgrade/upgrade_userobj_001_pos.ksh6
11 files changed, 232 insertions, 58 deletions
diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run
index 0e4622023..d2148d7ad 100644
--- a/tests/runfiles/linux.run
+++ b/tests/runfiles/linux.run
@@ -319,6 +319,9 @@ tests = ['zpool_upgrade_001_pos', 'zpool_upgrade_002_pos',
'zpool_upgrade_007_pos', 'zpool_upgrade_008_pos',
'zpool_upgrade_009_neg']
+[tests/functional/cli_root/zpool_sync]
+tests = ['zpool_sync_001_pos', 'zpool_sync_002_neg']
+
# DISABLED:
# zfs_share_001_neg - requires additional dependencies
# zfs_unshare_001_neg - requires additional dependencies
diff --git a/tests/zfs-tests/include/libtest.shlib b/tests/zfs-tests/include/libtest.shlib
index 4ad375e9d..5a9da2735 100644
--- a/tests/zfs-tests/include/libtest.shlib
+++ b/tests/zfs-tests/include/libtest.shlib
@@ -26,6 +26,7 @@
# Copyright (c) 2012, 2016 by Delphix. All rights reserved.
# Copyright 2016 Nexenta Systems, Inc.
# Copyright (c) 2017 Lawrence Livermore National Security, LLC.
+# Copyright (c) 2017 Datto Inc.
#
. ${STF_TOOLS}/include/logapi.shlib
@@ -3203,29 +3204,23 @@ function get_objnum
}
#
-# Synchronize all the data in pool
+# Sync data to the pool
#
# $1 pool name
+# $2 boolean to force uberblock (and config including zpool cache file) update
#
-function sync_pool #pool
+function sync_pool #pool <force>
{
typeset pool=${1:-$TESTPOOL}
+ typeset force=${2:-false}
- log_must $SYNC
- log_must sleep 2
- # Flush all the pool data.
- typeset -i ret
- zpool scrub $pool >/dev/null 2>&1
- ret=$?
- (( $ret != 0 )) && \
- log_fail "zpool scrub $pool failed."
-
- while ! is_pool_scrubbed $pool; do
- if is_pool_resilvered $pool ; then
- log_fail "$pool should not be resilver completed."
- fi
- log_must sleep 2
- done
+ if [[ $force == true ]]; then
+ log_must zpool sync -f $pool
+ else
+ log_must zpool sync $pool
+ fi
+
+ return 0
}
#
diff --git a/tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_common.kshlib b/tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_common.kshlib
index 7703c1241..3d371e614 100644
--- a/tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_common.kshlib
+++ b/tests/zfs-tests/tests/functional/clean_mirror/clean_mirror_common.kshlib
@@ -26,8 +26,10 @@
#
# Copyright (c) 2013, 2016 by Delphix. All rights reserved.
+# Copyright (c) 2017 Datto Inc.
#
+. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/clean_mirror/default.cfg
# Most of the code related to the clearing of mirrors is duplicated in all
@@ -36,32 +38,6 @@
# the contents of the mirror.
# This code is sourced into each of these test cases.
-#
-# Synchronize all the data in pool
-#
-# $1 pool name
-#
-function sync_pool #pool
-{
- typeset pool=$1
-
- log_must sync
- log_must sleep 2
- # Flush all the pool data.
- typeset -i ret
- zpool scrub $pool >/dev/null 2>&1
- ret=$?
- (( $ret != 0 )) && \
- log_fail "zpool scrub $pool failed."
-
- while ! is_pool_scrubbed $pool; do
- if is_pool_resilvered $pool ; then
- log_fail "$pool should not be resilver completed."
- fi
- log_must sleep 2
- done
-}
-
function overwrite_verify_mirror
{
typeset AFFECTED_DEVICE=$1
diff --git a/tests/zfs-tests/tests/functional/cli_root/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/Makefile.am
index f2e3fd0df..ff0951485 100644
--- a/tests/zfs-tests/tests/functional/cli_root/Makefile.am
+++ b/tests/zfs-tests/tests/functional/cli_root/Makefile.am
@@ -45,4 +45,5 @@ SUBDIRS = \
zpool_scrub \
zpool_set \
zpool_status \
+ zpool_sync \
zpool_upgrade
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_create/create-o_ashift.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_create/create-o_ashift.ksh
index 33ff4534d..6449c8a91 100755
--- a/tests/zfs-tests/tests/functional/cli_root/zpool_create/create-o_ashift.ksh
+++ b/tests/zfs-tests/tests/functional/cli_root/zpool_create/create-o_ashift.ksh
@@ -22,6 +22,7 @@
#
# Copyright 2016, loli10K. All rights reserved.
+# Copyright (c) 2017 Datto Inc.
#
. $STF_SUITE/include/libtest.shlib
@@ -48,30 +49,22 @@ function cleanup
}
#
-# FIXME: Ugly hack to force a $1 number of txg syncs.
-# This is used on Linux because we can't force it via sync(1) like on Illumos.
-# This could eventually (an hopefully) be replaced by a 'zpool sync' command.
+# Commit the specified number of TXGs to the provided pool
+# We use 'zpool sync' here because we can't force it via sync(1) like on illumos
# $1 pool name
# $2 number of txg syncs
#
function txg_sync
{
typeset pool=$1
- typeset count=$2
+ typeset -i count=$2
typeset -i i=0;
while [ $i -lt $count ]
do
- zfs snapshot $pool@sync$$$i
- if [[ $? -ne 0 ]]
- then
- log_fail "Failed to sync pool $pool (snapshot $i)"
- return 1
- fi
+ log_must sync_pool $pool true
((i = i + 1))
done
-
- return 0
}
#
@@ -118,7 +111,7 @@ do
"$ashift (current = $pprop)"
fi
# force 128 txg sync to fill the uberblock ring
- log_must eval "txg_sync $TESTPOOL 128"
+ txg_sync $TESTPOOL 128
verify_device_uberblocks $disk ${ubcount[$i]}
if [[ $? -ne 0 ]]
then
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_sync/Makefile.am b/tests/zfs-tests/tests/functional/cli_root/zpool_sync/Makefile.am
new file mode 100644
index 000000000..7f5f67d1f
--- /dev/null
+++ b/tests/zfs-tests/tests/functional/cli_root/zpool_sync/Makefile.am
@@ -0,0 +1,6 @@
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_sync
+dist_pkgdata_SCRIPTS = \
+ cleanup.ksh \
+ setup.ksh \
+ zpool_sync_001_pos.ksh \
+ zpool_sync_002_neg.ksh
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_sync/cleanup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_sync/cleanup.ksh
new file mode 100755
index 000000000..89c146249
--- /dev/null
+++ b/tests/zfs-tests/tests/functional/cli_root/zpool_sync/cleanup.ksh
@@ -0,0 +1,32 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+default_cleanup
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_sync/setup.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_sync/setup.ksh
new file mode 100755
index 000000000..181e62b11
--- /dev/null
+++ b/tests/zfs-tests/tests/functional/cli_root/zpool_sync/setup.ksh
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# 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 2007 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+verify_runnable "global"
+
+DISK=${DISKS%% *}
+
+default_setup $DISK
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_sync/zpool_sync_001_pos.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_sync/zpool_sync_001_pos.ksh
new file mode 100755
index 000000000..4761bacff
--- /dev/null
+++ b/tests/zfs-tests/tests/functional/cli_root/zpool_sync/zpool_sync_001_pos.ksh
@@ -0,0 +1,88 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+# CDDL HEADER END
+#
+# Copyright (c) 2017 Datto Inc.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Verify 'zpool sync' can sync txgs to the pool(s) main vdevs.
+#
+# STRATEGY:
+# 1. Create a pool
+# 2. Use zdb to obtain current txg
+# 3. Create a file in the pool if we're not using force sync
+# 4. Use zpool sync to sync pool
+# 5. Verify the new txg is now bigger than the saved one
+#
+
+verify_runnable "global"
+
+function get_txg {
+ typeset -i txg=$(zdb -u $1 | sed -n 's/^.*txg = \(.*\)$/\1/p')
+ echo $txg
+}
+
+set -A args "sync $TESTPOOL" "sync -f $TESTPOOL" "sync" "sync -f"
+
+log_assert "Verify 'zpool sync' can sync a pool"
+
+typeset -i i=0
+typeset -i orig_txg=0
+typeset -i new_txg=0
+while [[ $i -lt ${#args[*]} ]]; do
+ orig_txg=$(get_txg $TESTPOOL)
+ if ! [[ "${args[i]}" =~ "-f" ]]; then
+ log_must touch /$TESTPOOL/$i
+ fi
+ log_must zpool ${args[i]}
+ new_txg=$(get_txg $TESTPOOL)
+ if [[ $orig_txg -ge $new_txg ]]; then
+ log_fail "'zpool ${args[i]}' failed: txg $orig_txg >= $new_txg"
+ fi
+ ((i = i + 1))
+done
+
+# sync_pool is implemented using 'zpool sync' so let's test it as well
+
+# make sure we can use sync_pool with force sync explicitly not used
+orig_txg=$(get_txg $TESTPOOL)
+log_must touch /$TESTPOOL/$i
+log_must sync_pool $TESTPOOL false
+new_txg=$(get_txg $TESTPOOL)
+if [[ $orig_txg -ge $new_txg ]]; then
+ log_fail "'sync_pool $TESTPOOL false' failed: txg $orig_txg >= $new_txg"
+fi
+
+# make sure we can use sync_pool with force sync explicitly enabled
+orig_txg=$(get_txg $TESTPOOL)
+log_must sync_pool $TESTPOOL true
+new_txg=$(get_txg $TESTPOOL)
+if [[ $orig_txg -ge $new_txg ]]; then
+ log_fail "'sync_pool $TESTPOOL true' failed: txg $orig_txg >= $new_txg"
+fi
+
+# make sure we can use sync_pool with force sync implicitly not used
+orig_txg=$(get_txg $TESTPOOL)
+log_must touch /$TESTPOOL/$i
+log_must sync_pool $TESTPOOL
+new_txg=$(get_txg $TESTPOOL)
+if [[ $orig_txg -ge $new_txg ]]; then
+ log_fail "'sync_pool $TESTPOOL' failed: txg $orig_txg >= $new_txg"
+fi
+
+log_pass "'zpool sync' syncs pool as expected."
diff --git a/tests/zfs-tests/tests/functional/cli_root/zpool_sync/zpool_sync_002_neg.ksh b/tests/zfs-tests/tests/functional/cli_root/zpool_sync/zpool_sync_002_neg.ksh
new file mode 100755
index 000000000..e35a29130
--- /dev/null
+++ b/tests/zfs-tests/tests/functional/cli_root/zpool_sync/zpool_sync_002_neg.ksh
@@ -0,0 +1,44 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+# CDDL HEADER END
+#
+# Copyright (c) 2017 Datto Inc.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# A badly formed parameter passed to 'zpool sync' should
+# return an error.
+#
+# STRATEGY:
+# 1. Create an array containing bad 'zpool sync' parameters.
+# 2. For each element, execute the sub-command.
+# 3. Verify it returns an error.
+#
+
+verify_runnable "global"
+
+set -A args "1" "-a" "-?" "--%" "-123456" "0.5" "-o" "-b" "-b no" "-z 2"
+
+log_assert "Execute 'zpool sync' using invalid parameters."
+
+typeset -i i=0
+while [[ $i -lt ${#args[*]} ]]; do
+ log_mustnot zpool sync ${args[i]}
+ ((i = i + 1))
+done
+
+log_pass "Invalid parameters to 'zpool sync' fail as expected."
diff --git a/tests/zfs-tests/tests/functional/upgrade/upgrade_userobj_001_pos.ksh b/tests/zfs-tests/tests/functional/upgrade/upgrade_userobj_001_pos.ksh
index 49b6d1822..dda594f4e 100755
--- a/tests/zfs-tests/tests/functional/upgrade/upgrade_userobj_001_pos.ksh
+++ b/tests/zfs-tests/tests/functional/upgrade/upgrade_userobj_001_pos.ksh
@@ -22,6 +22,7 @@
#
# Copyright (c) 2013 by Jinshan Xiong. No rights reserved.
+# Copyright (c) 2017 Datto Inc.
#
. $STF_SUITE/include/libtest.shlib
@@ -71,7 +72,7 @@ zfs userspace -o objused -H $TESTPOOL | head -n 1 | grep -q "-" ||
# Create a file in fs1 should trigger dataset upgrade
log_must mkfile 1m $TESTDIR/fs1/tf
-sync_pool
+log_must sleep 1 # upgrade done in the background so let's give it a sec
# Make sure userobj accounting is working for fs1
zfs userspace -o objused -H $TESTPOOL/fs1 | head -n 1 | grep -q "-" &&
@@ -79,7 +80,7 @@ zfs userspace -o objused -H $TESTPOOL/fs1 | head -n 1 | grep -q "-" &&
# Mount a dataset should trigger upgrade
log_must zfs mount $TESTPOOL/fs2
-sync_pool
+log_must sleep 1 # upgrade done in the background so let's give it a sec
# Make sure userobj accounting is working for fs2
zfs userspace -o objused -H $TESTPOOL/fs2 | head -n 1 | grep -q "-" &&
@@ -91,6 +92,7 @@ zfs userspace -o objused -H $TESTPOOL | head -n 1 | grep -q "-" ||
log_fail "userobj accounting should be disabled for $TESTPOOL"
# Manual upgrade root dataset
+# uses an ioctl which will wait for the upgrade to be done before returning
log_must zfs set version=current $TESTPOOL
zfs userspace -o objused -H $TESTPOOL | head -n 1 | grep -q "-" &&
log_fail "userobj accounting should be enabled for $TESTPOOL"