[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [Xen-devel] [PATCH 25 of 29 RFC] libxl: add libxl_hotplug_dispatch
2012/2/2 Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>: > On Thu, 2 Feb 2012, Roger Pau Monne wrote: >> # HG changeset patch >> # User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx> >> # Date 1328179686 -3600 >> # Node ID 94532199f647fc03816fc5ae50ab53c8c5b80cd8 >> # Parent Â1506b1f2ab0fe5f4cd5bcd86a566d5a7be5f838b >> libxl: add libxl_hotplug_dispatch >> >> Added a new function to libxl API to handle device hotplug. Actions to >> execute upon hotplug device state changes are handled using the >> libxl_device_disk_hotplug_actions and libxl_device_nic_hotplug_actions >> depending on the type of device. Currently only VIF and VBD devices >> are handled by the hotplug mechanism. >> >> Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx> >> >> diff -r 1506b1f2ab0f -r 94532199f647 tools/libxl/libxl.c >> --- a/tools/libxl/libxl.c    Thu Feb 02 11:45:03 2012 +0100 >> +++ b/tools/libxl/libxl.c    Thu Feb 02 11:48:06 2012 +0100 >> @@ -982,6 +982,188 @@ out: >>   Âreturn rc; >> Â} >> >> +static int libxl__hotplug_generic_dispatcher(libxl__gc *gc, char *path, >> +                Âuint32_t domid, >> +                Âlibxl__hotplug_status state, >> +                Âlibxl__device_generic_hotplug_actions >> *action, >> +                Âvoid *device) >> +{ >> +  Âlibxl_ctx *ctx = libxl__gc_owner(gc); >> +  Âchar *spath = libxl__sprintf(gc, "%s/state", path); >> +  Âint rc = 0; >> + >> +  ÂLIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "processing device %s with state %d", >> +                   Âpath, state); >> +  Âswitch(state) { >> +  Âcase HOTPLUG_DEVICE_INIT: >> +    Âif (action->init) { >> +      Ârc = action->init(ctx, domid, device); >> +      Âif (rc < 0) { >> +        ÂLIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to init" >> +                         Â" device %s", path); >> +        Âlibxl__xs_write(gc, XBT_NULL, spath, "%d", >> +                ÂHOTPLUG_DEVICE_ERROR); >> +        Âbreak; >> +      Â} >> +    Â} >> +    Âlibxl__xs_write(gc, XBT_NULL, spath, "%d", HOTPLUG_DEVICE_CONNECT); >> +    Âbreak; >> +  Âcase HOTPLUG_DEVICE_CONNECT: >> +    Âif (action->connect) { >> +      Ârc = action->connect(ctx, domid, device); >> +      Âif (rc < 0) { >> +        ÂLIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to connect" >> +                         Â" device %s", path); >> +        Âlibxl__xs_write(gc, XBT_NULL, spath, "%d", >> +                ÂHOTPLUG_DEVICE_ERROR); >> +        Âbreak; >> +      Â} >> +    Â} >> +    Âlibxl__xs_write(gc, XBT_NULL, spath, "%d", >> HOTPLUG_DEVICE_CONNECTED); >> +    Âbreak; >> +  Âcase HOTPLUG_DEVICE_CONNECTED: >> +    Âif (action->connected) { >> +      Ârc = action->connected(ctx, domid, device); >> +      Âif (rc < 0) { >> +        ÂLIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to execute " >> +                         Â"connected action on" >> +                         Â" device %s", path); >> +        Âlibxl__xs_write(gc, XBT_NULL, spath, "%d", >> +                ÂHOTPLUG_DEVICE_ERROR); >> +        Âbreak; >> +      Â} >> +    Â} >> +    Âbreak; >> +  Âcase HOTPLUG_DEVICE_DISCONNECT: >> +    Âif (action->disconnect) { >> +      Ârc = action->disconnect(ctx, domid, device); >> +      Âif (rc < 0) { >> +        ÂLIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to unplug" >> +                         Â" device %s", path); >> +        Âlibxl__xs_write(gc, XBT_NULL, spath, "%d", >> +                ÂHOTPLUG_DEVICE_ERROR); >> +        Âbreak; >> +      Â} >> +    Â} >> +    Âlibxl__xs_write(gc, XBT_NULL, spath, "%d", >> +            ÂHOTPLUG_DEVICE_DISCONNECTED); >> +    Âbreak; >> +  Âcase HOTPLUG_DEVICE_DISCONNECTED: >> +    Âif (action->disconnected) { >> +      Ârc = action->disconnected(ctx, domid, device); >> +      Âif (rc < 0) { >> +        ÂLIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to execute " >> +                         Â"unpluged action on" >> +                         Â" device %s", path); >> +        Âlibxl__xs_write(gc, XBT_NULL, spath, "%d", >> +                ÂHOTPLUG_DEVICE_ERROR); >> +        Âbreak; >> +      Â} >> +    Â} >> +    Âbreak; >> +  Âcase HOTPLUG_DEVICE_FORCE_DISCONNECT: >> +    Âif (action->force_disconnect) { >> +      Ârc = action->force_disconnect(ctx, domid, device); >> +      Âif (rc < 0) { >> +        ÂLIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unable to force " >> +                         Â"disconnect device " >> +                         Â"%s", path); >> +        Âlibxl__xs_write(gc, XBT_NULL, spath, "%d", >> +                ÂHOTPLUG_DEVICE_ERROR); >> +        Âbreak; >> +      Â} >> +    Â} >> +    Âlibxl__xs_write(gc, XBT_NULL, spath, "%d", >> +            ÂHOTPLUG_DEVICE_DISCONNECTED); >> +    Âbreak; >> +  Âcase HOTPLUG_DEVICE_ERROR: >> +    Âif (action->error) >> +      Ârc = action->error(ctx, domid, device); >> +    Âbreak; >> +  Â} >> +  Âreturn rc; > > I can see that we are writing an error code to xenstore in case of > errors, but I fail to see where we are writing back a positive response. > Of course the caller of libxl_device_disk/nic_hotplug_add could watch > the backend state waiting for it to come up, but I think that having an > explicit ACK under /hotplug would be much better. The Sequence is the following, but I'm not really sure this is the most correct way. All states can go to HOTPLUG_DEVICE_ERROR, and the following state changes: HOTPLUG_DEVICE_INIT no state change HOTPLUG_DEVICE_CONNECT -> HOTPLUG_DEVICE_CONNECTED (on success) HOTPLUG_DEVICE_CONNECTED no change HOTPLUG_DEVICE_DISCONNECT -> HOTPLUG_DEVICE_DISCONNECTED (on success) HOTPLUG_DEVICE_FORCE_DISCONNECT -> HOTPLUG_DEVICE_DISCONNECTED (on success) > I haven't reviewed all the patches in detail but I think that this > series is going in the right thing direction, from the architectural > point of view. > The main requests for changes will probably be regarding event handling > and the usage of the new APIs. I guess so, when Ian Jackson event API is all in I will probably have to rewrite some parts of the code. _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |