]> git.proxmox.com Git - mirror_spl.git/commitdiff
Simplify hostid logic
authorRichard Yao <ryao@cs.stonybrook.edu>
Tue, 12 Mar 2013 01:16:36 +0000 (21:16 -0400)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 14 Apr 2014 16:04:41 +0000 (09:04 -0700)
There is plenty of compatibility code for a hw_hostid
that isn't used by anything. At the same time, there are apparently
issues with the current hostid logic. coredumb in #zfsonlinux on
freenode reported that Fedora 17 changes its hostid on every boot, which
required force importing his pool. A suggestion by wca was to adopt
FreeBSD's behavior, where it treats hostid as zero if /etc/hostid does
not exist

Adopting FreeBSD's behavior permits us to eliminate plenty of code,
including a userland helper that invokes the system's hostid as a
fallback.

Signed-off-by: Richard Yao <ryao@cs.stonybrook.edu>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #224

include/sys/sysmacros.h
include/sys/systeminfo.h
module/spl/spl-generic.c
module/spl/spl-proc.c

index b4778b70e83fc0437879f456edc2c893ada64792..1ac49b4f0c1e9b554e8e77b0965ecd28b0774eae 100644 (file)
 /* Missing globals */
 extern char spl_version[32];
 extern unsigned long spl_hostid;
-extern char hw_serial[11];
 
 /* Missing misc functions */
 extern int highbit(unsigned long i);
index e22a08530d79d46ec6a8ae1398714e96ea43caef..5c0cc4663d8d39baea2e27a79b792a5b5cab03aa 100644 (file)
@@ -25,7 +25,6 @@
 #ifndef _SPL_SYSTEMINFO_H
 #define _SPL_SYSTEMINFO_H
 
-#define HW_INVALID_HOSTID      0xFFFFFFFF      /* an invalid hostid */
 #define HW_HOSTID_LEN          11              /* minimum buffer size needed */
                                                /* to hold a decimal or hex */
                                                /* hostid string */
index 351f53670b8b50f973e26d6439adc59c63c1d45e..4f0842b1a069aa933ff14b350c4ad6a890c03cd6 100644 (file)
 char spl_version[32] = "SPL v" SPL_META_VERSION "-" SPL_META_RELEASE;
 EXPORT_SYMBOL(spl_version);
 
-unsigned long spl_hostid = HW_INVALID_HOSTID;
+unsigned long spl_hostid = 0;
 EXPORT_SYMBOL(spl_hostid);
 module_param(spl_hostid, ulong, 0644);
 MODULE_PARM_DESC(spl_hostid, "The system hostid.");
 
-char hw_serial[HW_HOSTID_LEN] = "<none>";
-EXPORT_SYMBOL(hw_serial);
-
 proc_t p0 = { 0 };
 EXPORT_SYMBOL(p0);
 
@@ -467,7 +464,7 @@ hostid_read(void)
        int result;
        uint64_t size;
        struct _buf *file;
-       unsigned long hostid = 0;
+       uint32_t hostid = 0;
 
        file = kobj_open_file(spl_hostid_path);
 
@@ -511,45 +508,10 @@ hostid_read(void)
        return 0;
 }
 
-#define GET_HOSTID_CMD \
-       "exec 0</dev/null " \
-       "     1>/proc/sys/kernel/spl/hostid " \
-       "     2>/dev/null; " \
-       "hostid"
-
-static int
-hostid_exec(void)
-{
-       char *argv[] = { "/bin/sh",
-                        "-c",
-                        GET_HOSTID_CMD,
-                        NULL };
-       char *envp[] = { "HOME=/",
-                        "TERM=linux",
-                        "PATH=/sbin:/usr/sbin:/bin:/usr/bin",
-                        NULL };
-       int rc;
-
-       /* Doing address resolution in the kernel is tricky and just
-        * not a good idea in general.  So to set the proper 'hw_serial'
-        * use the usermodehelper support to ask '/bin/sh' to run
-        * '/usr/bin/hostid' and redirect the result to /proc/sys/spl/hostid
-        * for us to use.  It's a horrific solution but it will do for now.
-        */
-       rc = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_PROC);
-       if (rc)
-               printk("SPL: Failed user helper '%s %s %s', rc = %d\n",
-                      argv[0], argv[1], argv[2], rc);
-
-       return rc;
-}
-
 uint32_t
 zone_get_hostid(void *zone)
 {
        static int first = 1;
-       unsigned long hostid;
-       int rc;
 
        /* Only the global zone is supported */
        ASSERT(zone == NULL);
@@ -559,21 +521,16 @@ zone_get_hostid(void *zone)
 
                /*
                 * Get the hostid if it was not passed as a module parameter.
-                * Try reading the /etc/hostid file directly, and then fall
-                * back to calling the /usr/bin/hostid utility.
+                * Try reading the /etc/hostid file directly.
                 */
-               if ((spl_hostid == HW_INVALID_HOSTID) &&
-                   (rc = hostid_read()) && (rc = hostid_exec()))
-                       return HW_INVALID_HOSTID;
+               if (hostid_read())
+                       spl_hostid = 0;
 
                printk(KERN_NOTICE "SPL: using hostid 0x%08x\n",
                        (unsigned int) spl_hostid);
        }
 
-       if (ddi_strtoul(hw_serial, NULL, HW_HOSTID_LEN-1, &hostid) != 0)
-               return HW_INVALID_HOSTID;
-
-       return (uint32_t)hostid;
+       return spl_hostid;
 }
 EXPORT_SYMBOL(zone_get_hostid);
 
index f25239aca9c452f3c7535bfa901ca6cce5a0d466..2bbc8d790a85c8db96a8c33b18f49fa926b57118 100644 (file)
@@ -72,7 +72,6 @@ struct proc_dir_entry *proc_spl_kstat = NULL;
 
 #define CTL_VERSION            CTL_UNNUMBERED /* Version */
 #define CTL_HOSTID             CTL_UNNUMBERED /* Host id by /usr/bin/hostid */
-#define CTL_HW_SERIAL          CTL_UNNUMBERED /* HW serial number by hostid */
 #define CTL_KALLSYMS           CTL_UNNUMBERED /* kallsyms_lookup_name addr */
 
 #define CTL_DEBUG_SUBSYS       CTL_UNNUMBERED /* Debug subsystem */
@@ -129,7 +128,6 @@ enum {
 enum {
        CTL_VERSION = 1,                /* Version */
        CTL_HOSTID,                     /* Host id reported by /usr/bin/hostid */
-       CTL_HW_SERIAL,                  /* Hardware serial number from hostid */
        CTL_KALLSYMS,                   /* Address of kallsyms_lookup_name */
 
 #ifdef DEBUG_LOG
@@ -513,9 +511,6 @@ SPL_PROC_HANDLER(proc_dohostid)
                 if (str == end)
                         SRETURN(-EINVAL);
 
-                (void) snprintf(hw_serial, HW_HOSTID_LEN, "%lu", spl_hostid);
-                hw_serial[HW_HOSTID_LEN - 1] = '\0';
-                *ppos += *lenp;
         } else {
                 len = snprintf(str, sizeof(str), "%lx", spl_hostid);
                 if (*ppos >= len)
@@ -1058,14 +1053,6 @@ static struct ctl_table spl_table[] = {
                 .mode     = 0644,
                 .proc_handler = &proc_dohostid,
         },
-        {
-                CTL_NAME    (CTL_HW_SERIAL)
-                .procname = "hw_serial",
-                .data     = hw_serial,
-                .maxlen   = sizeof(hw_serial),
-                .mode     = 0444,
-                .proc_handler = &proc_dostring,
-        },
 #ifndef HAVE_KALLSYMS_LOOKUP_NAME
         {
                 CTL_NAME    (CTL_KALLSYMS)