summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOlaf Faaland <[email protected]>2017-07-18 18:11:08 -0700
committerBrian Behlendorf <[email protected]>2017-07-25 13:22:03 -0400
commitb9373170e3e346733f5666dd80727cb6e05cd5d3 (patch)
tree943c2d6f5a409170e7e7cd8b5c129d0b9dcab04f /tests
parentffb195c256f8a74a87c3834258ec90c513d66adb (diff)
Add zgenhostid utility script
Turning the multihost property on requires that a hostid be set to allow ZFS to determine when a foreign system is attemping to import a pool. The error message instructing the user to set a hostid refers to genhostid(1). Genhostid(1) is not available on SUSE Linux. This commit adds a script modeled after genhostid(1) for those users. Zgenhostid checks for an /etc/hostid file; if it does not exist, it creates one and stores a value. If the user has provided a hostid as an argument, that value is used. Otherwise, a random hostid is generated and stored. This differs from the CENTOS 6/7 versions of genhostid, which overwrite the /etc/hostid file even though their manpages state otherwise. A man page for zgenhostid is added. The one for genhostid is in (1), but I put zgenhostid in (8) because I believe it's more appropriate. The mmp tests are modified to use zgenhostid to set the hostid instead of using the spl_hostid module parameter. zgenhostid will not replace an existing /etc/hostid file, so new mmp_clear_hostid calls are required. Reviewed-by: Giuseppe Di Natale <[email protected]> Reviewed-by: Andreas Dilger <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Olaf Faaland <[email protected]> Closes #6358 Closes #6379
Diffstat (limited to 'tests')
-rw-r--r--tests/zfs-tests/include/commands.cfg1
-rw-r--r--tests/zfs-tests/tests/functional/mmp/mmp.kshlib10
-rwxr-xr-xtests/zfs-tests/tests/functional/mmp/mmp_active_import.ksh1
-rwxr-xr-xtests/zfs-tests/tests/functional/mmp/mmp_exported_import.ksh2
-rwxr-xr-xtests/zfs-tests/tests/functional/mmp/mmp_inactive_import.ksh2
5 files changed, 10 insertions, 6 deletions
diff --git a/tests/zfs-tests/include/commands.cfg b/tests/zfs-tests/include/commands.cfg
index 57b1bd315..32749028c 100644
--- a/tests/zfs-tests/include/commands.cfg
+++ b/tests/zfs-tests/include/commands.cfg
@@ -141,6 +141,7 @@ export ZFS_FILES='zdb
arcstat.py
dbufstat.py
zed
+ zgenhostid
zstreamdump'
export ZFSTEST_FILES='chg_usr_exec
diff --git a/tests/zfs-tests/tests/functional/mmp/mmp.kshlib b/tests/zfs-tests/tests/functional/mmp/mmp.kshlib
index a81779b0c..ffe26dfde 100644
--- a/tests/zfs-tests/tests/functional/mmp/mmp.kshlib
+++ b/tests/zfs-tests/tests/functional/mmp/mmp.kshlib
@@ -79,12 +79,7 @@ function mmp_set_hostid
{
typeset hostid=$1
- a=${hostid:6:2}
- b=${hostid:4:2}
- c=${hostid:2:2}
- d=${hostid:0:2}
-
- printf "\\x$a\\x$b\\x$c\\x$d" >$HOSTID_FILE
+ zgenhostid $1
if [ $(hostid) != "$hostid" ]; then
return 1
@@ -107,10 +102,12 @@ function mmp_pool_create # pool dir
log_must mkdir -p $dir
log_must truncate -s $MINVDEVSIZE $dir/vdev1 $dir/vdev2
+ log_must mmp_clear_hostid
log_must mmp_set_hostid $HOSTID1
log_must zpool create -f $pool mirror $dir/vdev1 $dir/vdev2
log_must zpool set multihost=on $pool
log_must zpool export $pool
+ log_must mmp_clear_hostid
log_must mmp_set_hostid $HOSTID2
log_note "Starting ztest in the background as hostid $HOSTID1"
@@ -146,6 +143,7 @@ function mmp_pool_set_hostid # pool hostid
typeset pool=$1
typeset hostid=$2
+ log_must mmp_clear_hostid
log_must mmp_set_hostid $hostid
log_must zpool export $pool
log_must zpool import $pool
diff --git a/tests/zfs-tests/tests/functional/mmp/mmp_active_import.ksh b/tests/zfs-tests/tests/functional/mmp/mmp_active_import.ksh
index 92eb9ce2d..e2e30c7ea 100755
--- a/tests/zfs-tests/tests/functional/mmp/mmp_active_import.ksh
+++ b/tests/zfs-tests/tests/functional/mmp/mmp_active_import.ksh
@@ -86,6 +86,7 @@ log_must mmp_set_hostid $HOSTID1
MMP_IMPORTED_MSG="The pool can be imported"
log_must check_pool_import $MMP_POOL "-d $MMP_DIR" "action" $MMP_IMPORTED_MSG
+log_must mmp_clear_hostid
log_must mmp_set_hostid $HOSTID2
MMP_IMPORTED_MSG="The pool was last accessed by another system."
log_must check_pool_import $MMP_POOL "-d $MMP_DIR" "status" $MMP_IMPORTED_MSG
diff --git a/tests/zfs-tests/tests/functional/mmp/mmp_exported_import.ksh b/tests/zfs-tests/tests/functional/mmp/mmp_exported_import.ksh
index d65ca5b3d..6d34f7e77 100755
--- a/tests/zfs-tests/tests/functional/mmp/mmp_exported_import.ksh
+++ b/tests/zfs-tests/tests/functional/mmp/mmp_exported_import.ksh
@@ -62,6 +62,7 @@ done
for opt in "" "-f"; do
log_must mmp_pool_set_hostid $TESTPOOL $HOSTID1
log_must zpool export $TESTPOOL
+ log_must mmp_clear_hostid
log_must mmp_set_hostid $HOSTID2
log_must import_no_activity_check $TESTPOOL $opt
done
@@ -87,6 +88,7 @@ done
for opt in "" "-f"; do
log_must mmp_pool_set_hostid $TESTPOOL $HOSTID1
log_must zpool export $TESTPOOL
+ log_must mmp_clear_hostid
log_must mmp_set_hostid $HOSTID2
log_must import_no_activity_check $TESTPOOL $opt
done
diff --git a/tests/zfs-tests/tests/functional/mmp/mmp_inactive_import.ksh b/tests/zfs-tests/tests/functional/mmp/mmp_inactive_import.ksh
index c944b6b28..71f3af5c5 100755
--- a/tests/zfs-tests/tests/functional/mmp/mmp_inactive_import.ksh
+++ b/tests/zfs-tests/tests/functional/mmp/mmp_inactive_import.ksh
@@ -60,6 +60,7 @@ done
# 3. Verify multihost=off and hostids differ (no activity check)
log_must zpool export -F $TESTPOOL
+log_must mmp_clear_hostid
log_must mmp_set_hostid $HOSTID2
log_mustnot import_no_activity_check $TESTPOOL ""
log_must import_no_activity_check $TESTPOOL "-f"
@@ -81,6 +82,7 @@ done
# 6. Verify multihost=on and hostids differ (activity check)
log_must zpool export -F $TESTPOOL
+log_must mmp_clear_hostid
log_must mmp_set_hostid $HOSTID2
log_mustnot import_activity_check $TESTPOOL ""
log_must import_activity_check $TESTPOOL "-f"