From: Zhigang Wang Date: Mon, 7 May 2012 20:51:10 +0000 (-0400) Subject: xen: expose host uuid via sysfs. X-Git-Tag: v2.6.39-400.9.0~423^2~15 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a9a2f10cc4b7e07893110dd4f048a4ee481791ae;p=users%2Fjedix%2Flinux-maple.git xen: expose host uuid via sysfs. 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 --- diff --git a/drivers/xen/sys-hypervisor.c b/drivers/xen/sys-hypervisor.c index fdb6d229c9bb..6c5b14ab1d44 100644 --- a/drivers/xen/sys-hypervisor.c +++ b/drivers/xen/sys-hypervisor.c @@ -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();