mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
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 <dinatale2@llnl.gov> Reviewed-by: Andreas Dilger <andreas.dilger@intel.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Olaf Faaland <faaland1@llnl.gov> Closes #6358 Closes #6379
This commit is contained in:
committed by
Brian Behlendorf
parent
ffb195c256
commit
b9373170e3
@@ -141,6 +141,7 @@ export ZFS_FILES='zdb
|
||||
arcstat.py
|
||||
dbufstat.py
|
||||
zed
|
||||
zgenhostid
|
||||
zstreamdump'
|
||||
|
||||
export ZFSTEST_FILES='chg_usr_exec
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user