[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] [QEMU] Helper functions to interface with the xenstore and read device information from it.
# HG changeset patch # User kaf24@xxxxxxxxxxxxxxxxxxxxx # Node ID bbcac2aea0e8196cd75a3bf6dbe57bebf8c1e5b2 # Parent dc973fe5633386547ce5bc8fd4cf5f2bb5b55174 [QEMU] Helper functions to interface with the xenstore and read device information from it. - detect what types of devices a domain has or whether a domain has a device of a certain type - read the content of a variable related to a device, i.e., hotplug-status - subscribe to changes of the hotplug status of a device for not having to poll the status Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxx> --- tools/ioemu/vl.h | 19 ++++++ tools/ioemu/xenstore.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) diff -r dc973fe56333 -r bbcac2aea0e8 tools/ioemu/vl.h --- a/tools/ioemu/vl.h Fri Oct 27 18:57:02 2006 +0100 +++ b/tools/ioemu/vl.h Fri Oct 27 19:13:51 2006 +0100 @@ -1213,6 +1213,25 @@ void xenstore_write_vncport(int vnc_disp void xenstore_write_vncport(int vnc_display); int xenstore_read_vncpasswd(int domid); +int xenstore_domain_has_devtype(struct xs_handle *handle, + const char *devtype); +char **xenstore_domain_get_devices(struct xs_handle *handle, + const char *devtype, unsigned int *num); +char *xenstore_read_hotplug_status(struct xs_handle *handle, + const char *devtype, const char *inst); +char *xenstore_backend_read_variable(struct xs_handle *, + const char *devtype, const char *inst, + const char *var); +int xenstore_subscribe_to_hotplug_status(struct xs_handle *handle, + const char *devtype, + const char *inst, + const char *token); +int xenstore_unsubscribe_from_hotplug_status(struct xs_handle *handle, + const char *devtype, + const char *inst, + const char *token); + + /* xen_platform.c */ void pci_xen_platform_init(PCIBus *bus); diff -r dc973fe56333 -r bbcac2aea0e8 tools/ioemu/xenstore.c --- a/tools/ioemu/xenstore.c Fri Oct 27 18:57:02 2006 +0100 +++ b/tools/ioemu/xenstore.c Fri Oct 27 19:13:51 2006 +0100 @@ -264,3 +264,140 @@ int xenstore_read_vncpasswd(int domid) return rc; } + + +/* + * get all device instances of a certain type + */ +char **xenstore_domain_get_devices(struct xs_handle *handle, + const char *devtype, unsigned int *num) +{ + char *path; + char *buf = NULL; + char **e = NULL; + + path = xs_get_domain_path(handle, domid); + if (path == NULL) + goto out; + + if (pasprintf(&buf, "%s/device/%s", path,devtype) == -1) + goto out; + + e = xs_directory(handle, XBT_NULL, buf, num); + + out: + free(path); + free(buf); + return e; +} + +/* + * Check whether a domain has devices of the given type + */ +int xenstore_domain_has_devtype(struct xs_handle *handle, const char *devtype) +{ + int rc = 0; + unsigned int num; + char **e = xenstore_domain_get_devices(handle, devtype, &num); + if (e) + rc = 1; + free(e); + return rc; +} + +/* + * Function that creates a path to a variable of an instance of a + * certain device + */ +static char *get_device_variable_path(const char *devtype, const char *inst, + const char *var) +{ + char *buf = NULL; + if (pasprintf(&buf, "/local/domain/0/backend/%s/%d/%s/%s", + devtype, + domid, + inst, + var) == -1) { + free(buf); + buf = NULL; + } + return buf; +} + +char *xenstore_backend_read_variable(struct xs_handle *handle, + const char *devtype, const char *inst, + const char *var) +{ + char *value = NULL; + char *buf = NULL; + unsigned int len; + + buf = get_device_variable_path(devtype, inst, var); + if (NULL == buf) + goto out; + + value = xs_read(handle, XBT_NULL, buf, &len); + + free(buf); + +out: + return value; +} + +/* + Read the hotplug status variable from the backend given the type + of device and its instance. +*/ +char *xenstore_read_hotplug_status(struct xs_handle *handle, + const char *devtype, const char *inst) +{ + return xenstore_backend_read_variable(handle, devtype, inst, + "hotplug-status"); +} + +/* + Subscribe to the hotplug status of a device given the type of device and + its instance. + In case an error occurrs, a negative number is returned. + */ +int xenstore_subscribe_to_hotplug_status(struct xs_handle *handle, + const char *devtype, + const char *inst, + const char *token) +{ + int rc = 0; + char *path = get_device_variable_path(devtype, inst, "hotplug-status"); + + if (path == NULL) + return -1; + + if (0 == xs_watch(handle, path, token)) + rc = -2; + + free(path); + + return rc; +} + +/* + * Unsubscribe from a subscription to the status of a hotplug variable of + * a device. + */ +int xenstore_unsubscribe_from_hotplug_status(struct xs_handle *handle, + const char *devtype, + const char *inst, + const char *token) +{ + int rc = 0; + char *path; + path = get_device_variable_path(devtype, inst, "hotplug-status"); + if (path == NULL) + return -1; + + if (0 == xs_unwatch(handle, path, token)) + rc = -2; + + free(path); + + return rc; +} _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |