libspl: consult ZFS_HOSTID on FreeBSD as well

get_system_hostid() returns gethostid() on FreeBSD, so ZFS_HOSTID has
no effect there, while on Linux it overrides the SPL hostid.  zloop.sh
exports it for the iterations which need a hostid, and the ztest(1)
ENVIRONMENT VARIABLES section describes it without restricting it to
one platform, so both should read it.

Check ZFS_HOSTID first and fall back to gethostid(), parsing and
masking the value exactly as the Linux implementation does.  A value
which parses as zero is ignored there, so it is ignored here too.

Drop the "On Linux" qualifier from the -M description in ztest(1),
which this change makes untrue.

Suggested-by: Brian Behlendorf <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Michael Heller <[email protected]>
Closes #18918
Closes #18964
This commit is contained in:
Michael Heller authored and Brian Behlendorf committed 2026-08-23 10:38:57 -07:00
1 parent 9ceb4107a8
commit 84aa7e7e09
2 files changed
+15 -1

No files matched your search

+14
View File
@@ -23,5 +23,19 @@
unsigned long
get_system_hostid(void)
{
char *env;
/*
* Allow the hostid to be subverted for testing. A value which
* parses as zero is ignored, as it is on Linux, so that the
* system hostid is used instead.
*/
env = getenv("ZFS_HOSTID");
if (env != NULL) {
unsigned long hostid = strtoull(env, NULL, 0);
if (hostid != 0)
return (hostid & HOSTID_MASK);
}
return (gethostid());
}
+1 -1
View File
@@ -157,7 +157,7 @@ Multi-host; create the pool with the
.Sy multihost
property enabled, so that subsequent imports run the MMP activity check.
Requires a non-zero hostid.
On Linux one may be supplied through
One may be supplied through
.Ev ZFS_HOSTID .
.It Fl E , -use-existing-pool
Use existing pool (use existing pool instead of creating new one).