aboutsummaryrefslogtreecommitdiffstats
path: root/module/spl/spl-generic.c
diff options
context:
space:
mode:
authorRichard Yao <[email protected]>2013-03-11 21:16:36 -0400
committerBrian Behlendorf <[email protected]>2014-04-14 09:04:41 -0700
commitacf0ade362cb8b26d67770114ee6fa17816e6b65 (patch)
treefca1cd2bb9cabdfbe11e5daa5d32265ac365be6a /module/spl/spl-generic.c
parent3ceb71e8966e5f1895885eeaaa9354ffd940b490 (diff)
Simplify hostid logic
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 <[email protected]> Signed-off-by: Brian Behlendorf <[email protected]> Closes #224
Diffstat (limited to 'module/spl/spl-generic.c')
-rw-r--r--module/spl/spl-generic.c55
1 files changed, 6 insertions, 49 deletions
diff --git a/module/spl/spl-generic.c b/module/spl/spl-generic.c
index 351f53670..4f0842b1a 100644
--- a/module/spl/spl-generic.c
+++ b/module/spl/spl-generic.c
@@ -52,14 +52,11 @@
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);