]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Add zone_get_hostid() function
authorBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 19 Feb 2009 19:26:17 +0000 (11:26 -0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 19 Feb 2009 19:26:17 +0000 (11:26 -0800)
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!"

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

index ab2425ce8986f201124050152cf1fe639398523e..a4b1da55a42504b61f32ba0bebbc176713483650 100644 (file)
@@ -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>
index 03e72a145818f7c347fee2f0bf79d4cbca72a518..923cc22e7ceed8ef9472c04cf152f0b061c5662e 100644 (file)
@@ -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)
 
index e297f2a5a3e63087d51654a671aef1b17266ff01..0e89345549a8ec86a342e32237babaf401255f6c 100644 (file)
@@ -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 */
index a15cac41ecf7677b0d5a27240bb9a39e88df8b9e..96a14c62e1fab9b63ecc29e4f98e91a96c7db266 100644 (file)
@@ -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;
index 1ae1c129ae51fd01306e33def504b64dfa7d3663..90c89ce31ba44234b17a320a1fd2ff792c5a8da3 100644 (file)
@@ -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);