} else if (state != POOL_STATE_EXPORTED &&
!(flags & ZFS_IMPORT_ANY_HOST)) {
uint64_t hostid = 0;
- unsigned long system_hostid = gethostid() & 0xffffffff;
+ unsigned long system_hostid = get_system_hostid();
(void) nvlist_lookup_uint64(config, ZPOOL_CONFIG_HOSTID,
&hostid);
ZPOOL_STATUS_OK
} zpool_status_t;
+extern unsigned long get_system_hostid(void);
extern zpool_status_t zpool_get_status(zpool_handle_t *, char **,
zpool_errata_t *);
extern zpool_status_t zpool_import_status(nvlist_t *, char **,
uint64_t suspended;
uint64_t hostid = 0;
uint64_t errata = 0;
- unsigned long system_hostid = gethostid() & 0xffffffff;
+ unsigned long system_hostid = get_system_hostid();
verify(nvlist_lookup_uint64(config, ZPOOL_CONFIG_VERSION,
&version) == 0);
return (0);
}
+static unsigned long
+get_spl_hostid(void)
+{
+ FILE *f;
+ unsigned long hostid;
+
+ f = fopen("/sys/module/spl/parameters/spl_hostid", "r");
+ if (!f)
+ return (0);
+ if (fscanf(f, "%lu", &hostid) != 1)
+ hostid = 0;
+ fclose(f);
+ return (hostid & 0xffffffff);
+}
+
+unsigned long
+get_system_hostid(void)
+{
+ unsigned long system_hostid = get_spl_hostid();
+ if (system_hostid == 0)
+ system_hostid = gethostid() & 0xffffffff;
+ return (system_hostid);
+}
+
void
kernel_init(int mode)
{
(double)physmem * sysconf(_SC_PAGE_SIZE) / (1ULL << 30));
(void) snprintf(hw_serial, sizeof (hw_serial), "%ld",
- (mode & FWRITE) ? gethostid() : 0);
+ (mode & FWRITE) ? get_system_hostid() : 0);
VERIFY((random_fd = open("/dev/random", O_RDONLY)) != -1);
VERIFY((urandom_fd = open("/dev/urandom", O_RDONLY)) != -1);