aboutsummaryrefslogtreecommitdiffstats
path: root/module/spl
diff options
context:
space:
mode:
Diffstat (limited to 'module/spl')
-rw-r--r--module/spl/spl-generic.c73
-rw-r--r--module/spl/spl-proc.c3
2 files changed, 30 insertions, 46 deletions
diff --git a/module/spl/spl-generic.c b/module/spl/spl-generic.c
index a9445eb37..10061620e 100644
--- a/module/spl/spl-generic.c
+++ b/module/spl/spl-generic.c
@@ -499,80 +499,63 @@ module_param(spl_hostid_path, charp, 0444);
MODULE_PARM_DESC(spl_hostid_path, "The system hostid file (/etc/hostid)");
static int
-hostid_read(void)
+hostid_read(uint32_t *hostid)
{
- int result;
uint64_t size;
struct _buf *file;
- uint32_t hostid = 0;
+ uint32_t value = 0;
+ int error;
file = kobj_open_file(spl_hostid_path);
-
if (file == (struct _buf *)-1)
- return -1;
-
- result = kobj_get_filesize(file, &size);
+ return (ENOENT);
- if (result != 0) {
- printk(KERN_WARNING
- "SPL: kobj_get_filesize returned %i on %s\n",
- result, spl_hostid_path);
+ error = kobj_get_filesize(file, &size);
+ if (error) {
kobj_close_file(file);
- return -2;
+ return (error);
}
if (size < sizeof(HW_HOSTID_MASK)) {
- printk(KERN_WARNING
- "SPL: Ignoring the %s file because it is %llu bytes; "
- "expecting %lu bytes instead.\n", spl_hostid_path,
- size, (unsigned long)sizeof(HW_HOSTID_MASK));
kobj_close_file(file);
- return -3;
+ return (EINVAL);
}
- /* Read directly into the variable like eglibc does. */
- /* Short reads are okay; native behavior is preserved. */
- result = kobj_read_file(file, (char *)&hostid, sizeof(hostid), 0);
-
- if (result < 0) {
- printk(KERN_WARNING
- "SPL: kobj_read_file returned %i on %s\n",
- result, spl_hostid_path);
+ /*
+ * Read directly into the variable like eglibc does.
+ * Short reads are okay; native behavior is preserved.
+ */
+ error = kobj_read_file(file, (char *)&value, sizeof(value), 0);
+ if (error < 0) {
kobj_close_file(file);
- return -4;
+ return (EIO);
}
/* Mask down to 32 bits like coreutils does. */
- spl_hostid = hostid & HW_HOSTID_MASK;
+ *hostid = (value & HW_HOSTID_MASK);
kobj_close_file(file);
+
return 0;
}
+/*
+ * Return the system hostid. Preferentially use the spl_hostid module option
+ * when set, otherwise use the value in the /etc/hostid file.
+ */
uint32_t
zone_get_hostid(void *zone)
{
- static int first = 1;
-
- /* Only the global zone is supported */
- ASSERT(zone == NULL);
+ uint32_t hostid;
- if (first) {
- first = 0;
+ ASSERT3P(zone, ==, NULL);
- spl_hostid &= HW_HOSTID_MASK;
- /*
- * Get the hostid if it was not passed as a module parameter.
- * Try reading the /etc/hostid file directly.
- */
- if (spl_hostid == 0 && hostid_read())
- spl_hostid = 0;
+ if (spl_hostid != 0)
+ return ((uint32_t)(spl_hostid & HW_HOSTID_MASK));
+ if (hostid_read(&hostid) == 0)
+ return (hostid);
- printk(KERN_NOTICE "SPL: using hostid 0x%08x\n",
- (unsigned int) spl_hostid);
- }
-
- return spl_hostid;
+ return (0);
}
EXPORT_SYMBOL(zone_get_hostid);
diff --git a/module/spl/spl-proc.c b/module/spl/spl-proc.c
index d6159b4b6..bffbcc607 100644
--- a/module/spl/spl-proc.c
+++ b/module/spl/spl-proc.c
@@ -203,7 +203,8 @@ proc_dohostid(struct ctl_table *table, int write,
return (-EINVAL);
} else {
- len = snprintf(str, sizeof(str), "%lx", spl_hostid);
+ len = snprintf(str, sizeof(str), "%lx",
+ (unsigned long) zone_get_hostid(NULL));
if (*ppos >= len)
rc = 0;
else