]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
xen: expose host uuid via sysfs.
authorZhigang Wang <zhigang.x.wang@oracle.com>
Mon, 7 May 2012 20:51:10 +0000 (16:51 -0400)
committerMaxim Uvarov <maxim.uvarov@oracle.com>
Fri, 1 Jun 2012 10:51:20 +0000 (14:51 +0400)
When 'expose_host_uuid = 1' is specified in vm.cfg, xen will write the physical
host uuid to xenstore. This patch expose the host uuid to userspace via sysfs:

  $ cat /sys/hypervisor/host_uuid
  d51ac6d5-f8f1-416f-b089-17da51beb70d

Signed-off-by: Zhigang Wang <zhigang.x.wang@oracle.com>
drivers/xen/sys-hypervisor.c

index fdb6d229c9bbf5e59198189f95e70502116a6ca2..6c5b14ab1d449b5b960864e66a56db63249453d3 100644 (file)
@@ -147,6 +147,41 @@ static void xen_sysfs_uuid_destroy(void)
        sysfs_remove_file(hypervisor_kobj, &uuid_attr.attr);
 }
 
+/* Host UUID */
+
+static ssize_t host_uuid_show(struct hyp_sysfs_attr *attr, char *buffer)
+{
+       char *vm, *val;
+       int ret;
+       extern int xenstored_ready;
+
+       if (!xenstored_ready)
+               return -EBUSY;
+
+       vm = xenbus_read(XBT_NIL, "vm", "", NULL);
+       if (IS_ERR(vm))
+               return PTR_ERR(vm);
+       val = xenbus_read(XBT_NIL, vm, "host_uuid", NULL);
+       kfree(vm);
+       if (IS_ERR(val))
+               return PTR_ERR(val);
+       ret = sprintf(buffer, "%s\n", val);
+       kfree(val);
+       return ret;
+}
+
+HYPERVISOR_ATTR_RO(host_uuid);
+
+static int __init xen_sysfs_host_uuid_init(void)
+{
+       return sysfs_create_file(hypervisor_kobj, &host_uuid_attr.attr);
+}
+
+static void xen_sysfs_host_uuid_destroy(void)
+{
+       sysfs_remove_file(hypervisor_kobj, &host_uuid_attr.attr);
+}
+
 /* xen compilation attributes */
 
 static ssize_t compiler_show(struct hyp_sysfs_attr *attr, char *buffer)
@@ -374,6 +409,9 @@ static int __init hyper_sysfs_init(void)
        ret = xen_sysfs_uuid_init();
        if (ret)
                goto uuid_out;
+       ret = xen_sysfs_host_uuid_init();
+       if (ret)
+               goto host_uuid_out;
        ret = xen_properties_init();
        if (ret)
                goto prop_out;
@@ -383,6 +421,8 @@ static int __init hyper_sysfs_init(void)
 prop_out:
        xen_sysfs_uuid_destroy();
 uuid_out:
+       xen_sysfs_host_uuid_destroy();
+host_uuid_out:
        xen_compilation_destroy();
 comp_out:
        xen_sysfs_version_destroy();
@@ -397,6 +437,7 @@ static void __exit hyper_sysfs_exit(void)
        xen_properties_destroy();
        xen_compilation_destroy();
        xen_sysfs_uuid_destroy();
+       xen_sysfs_host_uuid_destroy();
        xen_sysfs_version_destroy();
        xen_sysfs_type_destroy();