aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Heller <75820586+mkhllr@users.noreply.github.com>2026-08-21 21:26:48 +0000
committerBrian Behlendorf <behlendorf1@llnl.gov>2026-08-23 17:38:57 +0000
commit84aa7e7e09f6a4ddad9ec40dbe9498d50184ed07 (patch)
treebde0ab11213e07000363f2e953350d2905db93dd
parent9ceb4107a84837d2bfe04c3fa84da844ed1becd7 (diff)
libspl: consult ZFS_HOSTID on FreeBSD as wellvendor/openzfs/master
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 <behlendorf1@llnl.gov> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Michael Heller <michael.heller@gmail.com> Closes #18918 Closes #18964
-rw-r--r--lib/libspl/os/freebsd/gethostid.c14
-rw-r--r--man/man1/ztest.12
2 files changed, 15 insertions, 1 deletions
diff --git a/lib/libspl/os/freebsd/gethostid.c b/lib/libspl/os/freebsd/gethostid.c
index a47a86882205..e2993e99c22e 100644
--- a/lib/libspl/os/freebsd/gethostid.c
+++ b/lib/libspl/os/freebsd/gethostid.c
@@ -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());
}
diff --git a/man/man1/ztest.1 b/man/man1/ztest.1
index e8537375cc86..845e174c6b14 100644
--- a/man/man1/ztest.1
+++ b/man/man1/ztest.1
@@ -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).