aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2009-02-19 11:26:17 -0800
committerBrian Behlendorf <[email protected]>2009-02-19 11:26:17 -0800
commit99639e4a13306c3809b52e487d4343d756fad2e2 (patch)
tree0baaa1c24c08ee7b51c24dd62d48427b439fd498
parent63a93055fb6cfddebe31c791f7df86b14942ca9d (diff)
Add zone_get_hostid() function
Minimal support added for the zone_get_hostid() function. Only global zones are supported therefore this function must be called with a NULL argumment. Additionally, I've added the HW_HOSTID_LEN define and updated all instances where a hard coded magic value of 11 was used; "A good riddance of bad rubbish!"
-rw-r--r--include/sys/proc.h1
-rw-r--r--include/sys/sysmacros.h1
-rw-r--r--include/sys/systeminfo.h5
-rw-r--r--module/spl/spl-generic.c18
-rw-r--r--module/spl/spl-proc.c3
5 files changed, 26 insertions, 2 deletions
diff --git a/include/sys/proc.h b/include/sys/proc.h
index ab2425ce8..a4b1da55a 100644
--- a/include/sys/proc.h
+++ b/include/sys/proc.h
@@ -33,6 +33,7 @@
#include <linux/sysctl.h>
#include <linux/seq_file.h>
#include <sys/sysmacros.h>
+#include <sys/systeminfo.h>
#include <sys/kmem.h>
#include <sys/mutex.h>
#include <sys/kstat.h>
diff --git a/include/sys/sysmacros.h b/include/sys/sysmacros.h
index 03e72a145..923cc22e7 100644
--- a/include/sys/sysmacros.h
+++ b/include/sys/sysmacros.h
@@ -143,6 +143,7 @@ extern int p0;
/* Missing misc functions */
extern int highbit(unsigned long i);
+extern uint32_t zone_get_hostid(void *zone);
#define makedevice(maj,min) makedev(maj,min)
diff --git a/include/sys/systeminfo.h b/include/sys/systeminfo.h
index e297f2a5a..0e8934554 100644
--- a/include/sys/systeminfo.h
+++ b/include/sys/systeminfo.h
@@ -1,4 +1,9 @@
#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 */
+
#endif /* SPL_SYSTEMINFO_H */
diff --git a/module/spl/spl-generic.c b/module/spl/spl-generic.c
index a15cac41e..96a14c62e 100644
--- a/module/spl/spl-generic.c
+++ b/module/spl/spl-generic.c
@@ -25,6 +25,7 @@
*/
#include <sys/sysmacros.h>
+#include <sys/systeminfo.h>
#include <sys/vmsystm.h>
#include <sys/vnode.h>
#include <sys/kmem.h>
@@ -47,7 +48,7 @@ char spl_version[16] = "SPL v" VERSION;
long spl_hostid = 0;
EXPORT_SYMBOL(spl_hostid);
-char hw_serial[11] = "<none>";
+char hw_serial[HW_HOSTID_LEN] = "<none>";
EXPORT_SYMBOL(hw_serial);
int p0 = 0;
@@ -253,6 +254,21 @@ set_hostid(void)
return call_usermodehelper(sh_path, argv, envp, 1);
}
+uint32_t
+zone_get_hostid(void *zone)
+{
+ unsigned long hostid;
+
+ /* Only the global zone is supported */
+ ASSERT(zone == NULL);
+
+ if (ddi_strtoul(hw_serial, NULL, HW_HOSTID_LEN-1, &hostid) != 0)
+ return HW_INVALID_HOSTID;
+
+ return (uint32_t)hostid;
+}
+EXPORT_SYMBOL(zone_get_hostid);
+
static int __init spl_init(void)
{
int rc = 0;
diff --git a/module/spl/spl-proc.c b/module/spl/spl-proc.c
index 1ae1c129a..90c89ce31 100644
--- a/module/spl/spl-proc.c
+++ b/module/spl/spl-proc.c
@@ -470,7 +470,8 @@ proc_dohostid(struct ctl_table *table, int write, struct file *filp,
RETURN(-EINVAL);
spl_hostid = (long)val;
- (void)snprintf(hw_serial, 11, "%u", (val >= 0) ? val : -val);
+ (void)snprintf(hw_serial, HW_HOSTID_LEN-1, "%u",
+ (val >= 0) ? val : -val);
*ppos += *lenp;
} else {
len = snprintf(str, sizeof(str), "%lx", spl_hostid);