[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] libxl: introduce libxl__wait_for_device_state
# HG changeset patch # User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx> # Date 1323971745 -3600 # Node ID 4a9ec5fd34bcf46a0e08abe62c268b73e061cd2a # Parent e0effa7c04f57a9622490392e8f07e2e0788f321 libxl: introduce libxl__wait_for_device_state This is a generic function, that waits for xs watches to reach a certain state and then executes the passed helper function. Removed wait_for_dev_destroy and used this new function instead. This function will also be used by future patches that need to wait for the initialization of devices before executing hotplug scripts. Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx> Acked-by: Ian Jackson <ian.jackson.citrix.com> Committed-by: Ian Jackson <ian.jackson.citrix.com> Acked-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx> --- diff -r e0effa7c04f5 -r 4a9ec5fd34bc tools/libxl/libxl_device.c --- a/tools/libxl/libxl_device.c Fri Sep 30 14:38:55 2011 +0200 +++ b/tools/libxl/libxl_device.c Thu Dec 15 18:55:45 2011 +0100 @@ -369,7 +369,9 @@ * Returns 0 if a device is removed, ERROR_* if an error * or timeout occurred. */ -static int wait_for_dev_destroy(libxl__gc *gc, struct timeval *tv) +int libxl__wait_for_device_state(libxl__gc *gc, struct timeval *tv, + XenbusState state, + libxl__device_state_handler handler) { libxl_ctx *ctx = libxl__gc_owner(gc); int nfds, rc; @@ -394,17 +396,14 @@ default: l1 = xs_read_watch(ctx->xsh, &n); if (l1 != NULL) { - char *state = libxl__xs_read(gc, XBT_NULL, + char *sstate = libxl__xs_read(gc, XBT_NULL, l1[XS_WATCH_PATH]); - if (!state || atoi(state) == 6) { - xs_unwatch(ctx->xsh, l1[0], l1[1]); - xs_rm(ctx->xsh, XBT_NULL, l1[XS_WATCH_TOKEN]); - LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, - "Destroyed device backend at %s", - l1[XS_WATCH_TOKEN]); - rc = 0; + if (!sstate || atoi(sstate) == state) { + /* Call handler function if present */ + if (handler) + rc = handler(gc, l1, sstate); } else { - /* State is not "disconnected", continue waiting... */ + /* State is different than expected, continue waiting... */ goto start; } free(l1); @@ -417,6 +416,23 @@ } /* + * Handler function for device destruction to be passed to + * libxl__wait_for_device_state + */ +static int destroy_device(libxl__gc *gc, char **l1, char *state) +{ + libxl_ctx *ctx = libxl__gc_owner(gc); + + xs_unwatch(ctx->xsh, l1[0], l1[1]); + xs_rm(ctx->xsh, XBT_NULL, l1[XS_WATCH_TOKEN]); + LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, + "Destroyed device backend at %s", + l1[XS_WATCH_TOKEN]); + + return 0; +} + +/* * Returns 0 (device already destroyed) or 1 (caller must * wait_for_dev_destroy) on success, ERROR_* on fail. */ @@ -457,7 +473,8 @@ struct timeval tv; tv.tv_sec = LIBXL_DESTROY_TIMEOUT; tv.tv_usec = 0; - rc = wait_for_dev_destroy(gc, &tv); + rc = libxl__wait_for_device_state(gc, &tv, XenbusStateClosed, + destroy_device); if (rc < 0) /* an error or timeout occurred, clear watches */ xs_unwatch(ctx->xsh, state_path, be_path); xs_rm(ctx->xsh, XBT_NULL, libxl__device_frontend_path(gc, dev)); @@ -565,7 +582,8 @@ tv.tv_sec = LIBXL_DESTROY_TIMEOUT; tv.tv_usec = 0; while (n_watches > 0) { - if (wait_for_dev_destroy(gc, &tv) < 0) { + if (libxl__wait_for_device_state(gc, &tv, XenbusStateClosed, + destroy_device) < 0) { /* function returned ERROR_* */ break; } else { diff -r e0effa7c04f5 -r 4a9ec5fd34bc tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Fri Sep 30 14:38:55 2011 +0200 +++ b/tools/libxl/libxl_internal.h Thu Dec 15 18:55:45 2011 +0100 @@ -24,11 +24,14 @@ #include <stdlib.h> #include <string.h> #include <pthread.h> +#include <sys/time.h> #include <xs.h> #include <xenctrl.h> #include "xentoollog.h" +#include <xen/io/xenbus.h> + #include "libxl.h" #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) @@ -271,6 +274,31 @@ _hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force); _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state); +/* Handler for the libxl__wait_for_device_state callback */ +/* + * libxl__device_state_handler - Handler for the libxl__wait_for_device_state + * gc: allocation pool + * l1: array containing the path and token + * state: string that contains the state of the device + * + * Returns 0 on success, and < 0 on error. + */ +typedef int libxl__device_state_handler(libxl__gc *gc, char **l1, char *state); + +/* + * libxl__wait_for_device_state - waits a given time for a device to + * reach a given state + * gc: allocation pool + * tv: timeval struct containing the maximum time to wait + * state: state to wait for (check xen/io/xenbus.h) + * handler: callback function to execute when state is reached + * + * Returns 0 on success, and < 0 on error. + */ +_hidden int libxl__wait_for_device_state(libxl__gc *gc, struct timeval *tv, + XenbusState state, + libxl__device_state_handler handler); + /* * libxl__try_phy_backend - Check if there's support for the passed * type of file using the PHY backend _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |