summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChunwei Chen <tuxoko@gmail.com>2015-01-23 16:05:04 +0800
committerBrian Behlendorf <behlendorf1@llnl.gov>2015-02-04 16:44:53 -0800
commit53698a453d1cc318f99477fef596c476b4b0cb47 (patch)
treedf07069d67116be61722e8c8713e500a61c43fd2 /lib
parentaa2ef419e46b3ad7c2ad8848b7a308a5a949aba7 (diff)
Read spl_hostid module parameter before gethostid()
If spl_hostid is set via module parameter, it's likely different from gethostid(). Therefore, the userspace tool should read it first before falling back to gethostid(). Signed-off-by: Chunwei Chen <tuxoko@gmail.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #3034
Diffstat (limited to 'lib')
-rw-r--r--lib/libzfs/libzfs_status.c2
-rw-r--r--lib/libzpool/kernel.c26
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/libzfs/libzfs_status.c b/lib/libzfs/libzfs_status.c
index 534ff853a..f69bd4544 100644
--- a/lib/libzfs/libzfs_status.c
+++ b/lib/libzfs/libzfs_status.c
@@ -195,7 +195,7 @@ check_status(nvlist_t *config, boolean_t isimport, zpool_errata_t *erratap)
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);
diff --git a/lib/libzpool/kernel.c b/lib/libzpool/kernel.c
index db50352c5..325cb3cea 100644
--- a/lib/libzpool/kernel.c
+++ b/lib/libzpool/kernel.c
@@ -1107,6 +1107,30 @@ umem_out_of_memory(void)
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)
{
@@ -1120,7 +1144,7 @@ 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);