]> granicus.if.org Git - zfs/commitdiff
Read spl_hostid module parameter before gethostid()
authorChunwei Chen <tuxoko@gmail.com>
Fri, 23 Jan 2015 08:05:04 +0000 (16:05 +0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 5 Feb 2015 00:44:53 +0000 (16:44 -0800)
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

cmd/zpool/zpool_main.c
include/libzfs.h
lib/libzfs/libzfs_status.c
lib/libzpool/kernel.c

index db5805bcf66a035233317296b3288138cca6b1ed..0f2bab6e925c724c46dfb975447afb15fdb3e367 100644 (file)
@@ -1917,7 +1917,7 @@ do_import(nvlist_t *config, const char *newname, const char *mntopts,
        } 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);
index df38d29e1863c768f6d5e165b4499a66e3924d2f..108b75f5eb3cb43940a3fb4ea8fdf4dec1202a20 100644 (file)
@@ -350,6 +350,7 @@ typedef enum {
        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 **,
index 534ff853a5bcdd484b47692e6156a4e28995a517..f69bd4544f36970e330bc20e9c2af331c26b4461 100644 (file)
@@ -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);
index db50352c5191a04dd9cfaf77788b29ffa35c96a9..325cb3ceaa79cb8cbe7c03570cbfd5e799648a8c 100644 (file)
@@ -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);