[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH 20 of 29 RFC] libxl: introduce libxl hotplug public API functions
# HG changeset patch # User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx> # Date 1328178807 -3600 # Node ID bc38aa2e11e21b34dbc29a81f069133a3276848a # Parent 937bbe68a1942e22c40aa18c8bb66490aec56945 libxl: introduce libxl hotplug public API functions These functions mimic the name used by the local device functions, following the nomenclature: libxl_device_<type>_hotplug_<action> They also take the same parameters as they local counterparts (ctx, domid and libxl_device_<type>). The list of added functions: libxl_device_disk_hotplug_add libxl_device_disk_hotplug_remove libxl_device_disk_hotplug_destroy libxl_device_nic_hotplug_add libxl_device_nic_hotplug_remove libxl_device_nic_hotplug_destroy The xenstore structure used by vbd disk entries: /hotplug/<backend_domid>/<frontend_domid>/vbd/<devid> /hotplug/<backend_domid>/<frontend_domid>/vbd/<devid>/pdev_path /hotplug/<backend_domid>/<frontend_domid>/vbd/<devid>/vdev /hotplug/<backend_domid>/<frontend_domid>/vbd/<devid>/script /hotplug/<backend_domid>/<frontend_domid>/vbd/<devid>/removable /hotplug/<backend_domid>/<frontend_domid>/vbd/<devid>/readwrite /hotplug/<backend_domid>/<frontend_domid>/vbd/<devid>/is_cdrom /hotplug/<backend_domid>/<frontend_domid>/vbd/<devid>/state and vif devices use the following: /hotplug/<backend_domid>/<frontend_domid>/vif/<devid> /hotplug/<backend_domid>/<frontend_domid>/vif/<devid>/mtu /hotplug/<backend_domid>/<frontend_domid>/vif/<devid>/model /hotplug/<backend_domid>/<frontend_domid>/vif/<devid>/mac /hotplug/<backend_domid>/<frontend_domid>/vif/<devid>/ip /hotplug/<backend_domid>/<frontend_domid>/vif/<devid>/bridge /hotplug/<backend_domid>/<frontend_domid>/vif/<devid>/ifname /hotplug/<backend_domid>/<frontend_domid>/vif/<devid>/script /hotplug/<backend_domid>/<frontend_domid>/vif/<devid>/nictype This will allow us to pass the libxl_device_disk and libxl_device_nic struct from Dom0 to driver domain, and execute the necessary backends there. Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx> diff -r 937bbe68a194 -r bc38aa2e11e2 tools/libxl/libxl.c --- a/tools/libxl/libxl.c Thu Feb 02 11:30:27 2012 +0100 +++ b/tools/libxl/libxl.c Thu Feb 02 11:33:27 2012 +0100 @@ -996,6 +996,85 @@ static int libxl__device_from_disk(libxl return 0; } +int libxl_device_disk_hotplug_add(libxl_ctx *ctx, uint32_t domid, + libxl_device_disk *disk) +{ + GC_INIT(ctx); + flexarray_t *hotplug; + libxl__device device; + char *h_path, *state_path, *state; + struct timeval tv; + int rc; + + /* + * Always set backend to PHY and let the driver domain decide the most + * suitable backend to use + */ + disk->backend = LIBXL_DISK_BACKEND_PHY; + + hotplug = flexarray_make(14, 1); + if (!hotplug) { + rc = ERROR_NOMEM; + goto out; + } + + rc = libxl__device_from_disk(gc, domid, disk, &device); + if (rc != 0) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Invalid or unsupported" + " virtual disk identifier %s", disk->vdev); + goto out_free; + } + + flexarray_append(hotplug, "pdev_path"); + flexarray_append(hotplug, libxl__strdup(gc, disk->pdev_path)); + flexarray_append(hotplug, "vdev"); + flexarray_append(hotplug, libxl__strdup(gc, disk->vdev)); + if (disk->script) { + flexarray_append(hotplug, "script"); + flexarray_append(hotplug, libxl__strdup(gc, disk->script)); + } + flexarray_append(hotplug, "removable"); + flexarray_append(hotplug, libxl__sprintf(gc, "%d", disk->removable)); + flexarray_append(hotplug, "readwrite"); + flexarray_append(hotplug, libxl__sprintf(gc, "%d", disk->readwrite)); + flexarray_append(hotplug, "is_cdrom"); + flexarray_append(hotplug, libxl__sprintf(gc, "%d", disk->is_cdrom)); + flexarray_append(hotplug, "format"); + flexarray_append(hotplug, libxl__sprintf(gc, "%d", disk->format)); + flexarray_append(hotplug, "state"); + flexarray_append(hotplug, "1"); + + libxl__device_generic_hotplug_add(gc, &device, + libxl__xs_kvs_of_flexarray(gc, hotplug, hotplug->count)); + + /* Wait for device init or error */ + h_path = libxl__device_hotplug_path(gc, &device); + state_path = libxl__sprintf(gc, "%s/state", h_path); + state = libxl__xs_read(gc, XBT_NULL, state_path); + + if (atoi(state) != HOTPLUG_DEVICE_CONNECTED) { + xs_watch(ctx->xsh, state_path, h_path); + tv.tv_sec = LIBXL_DESTROY_TIMEOUT; + tv.tv_usec = 0; + rc = libxl__wait_for_device_state(gc, &tv, HOTPLUG_DEVICE_CONNECTED, + NULL); + xs_unwatch(ctx->xsh, state_path, h_path); + if (rc < 0) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, + "unable to initialize disk device: %s", + disk->pdev_path); + goto out_free; + } + } + + rc = 0; +out_free: + flexarray_free(hotplug); +out: + GC_FREE; + return rc; +} + int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk) { GC_INIT(ctx); @@ -1174,6 +1253,23 @@ out: return rc; } +int libxl_device_disk_hotplug_remove(libxl_ctx *ctx, uint32_t domid, + libxl_device_disk *disk) +{ + GC_INIT(ctx); + libxl__device device; + int rc; + + rc = libxl__device_from_disk(gc, domid, disk, &device); + if (rc != 0) goto out; + + rc = libxl__device_hotplug_disconnect(gc, &device, + HOTPLUG_DEVICE_DISCONNECT); +out: + GC_FREE; + return rc; +} + int libxl_device_disk_destroy(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk) { @@ -1190,6 +1286,23 @@ out: return rc; } +int libxl_device_disk_hotplug_destroy(libxl_ctx *ctx, uint32_t domid, + libxl_device_disk *disk) +{ + GC_INIT(ctx); + libxl__device device; + int rc; + + rc = libxl__device_from_disk(gc, domid, disk, &device); + if (rc != 0) goto out; + + rc = libxl__device_hotplug_disconnect(gc, &device, + HOTPLUG_DEVICE_FORCE_DISCONNECT); +out: + GC_FREE; + return rc; +} + static void libxl__device_disk_from_xs_be(libxl__gc *gc, const char *be_path, libxl_device_disk *disk) @@ -1516,6 +1629,85 @@ static int libxl__device_from_nic(libxl_ return 0; } +int libxl_device_nic_hotplug_add(libxl_ctx *ctx, uint32_t domid, + libxl_device_nic *nic) +{ + GC_INIT(ctx); + flexarray_t *hotplug; + libxl__device device; + char *h_path, *state_path, *state; + struct timeval tv; + int rc; + + hotplug = flexarray_make(18, 1); + if (!hotplug) { + rc = ERROR_NOMEM; + goto out; + } + + rc = libxl__device_from_nic(gc, domid, nic, &device); + if (rc != 0) + goto out_free; + + flexarray_append(hotplug, "mtu"); + flexarray_append(hotplug, libxl__sprintf(gc, "%d", nic->mtu)); + if (nic->model) { + flexarray_append(hotplug, "model"); + flexarray_append(hotplug, libxl__strdup(gc, nic->model)); + } + flexarray_append(hotplug, "mac"); + flexarray_append(hotplug, libxl__sprintf(gc, + LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac))); + if (nic->ip) { + flexarray_append(hotplug, "ip"); + flexarray_append(hotplug, libxl__strdup(gc, nic->ip)); + } + flexarray_append(hotplug, "bridge"); + flexarray_append(hotplug, libxl__strdup(gc, nic->bridge)); + if (nic->ifname) { + flexarray_append(hotplug, "ifname"); + flexarray_append(hotplug, libxl__strdup(gc, nic->ifname)); + } + if (nic->script) { + flexarray_append(hotplug, "script"); + flexarray_append(hotplug, libxl__strdup(gc, nic->script)); + } + flexarray_append(hotplug, "nictype"); + flexarray_append(hotplug, libxl__sprintf(gc, "%d", nic->nictype)); + flexarray_append(hotplug, "state"); + flexarray_append(hotplug, "1"); + + libxl__device_generic_hotplug_add(gc, &device, + libxl__xs_kvs_of_flexarray(gc, hotplug, hotplug->count)); + + /* Wait for device init or error */ + h_path = libxl__device_hotplug_path(gc, &device); + state_path = libxl__sprintf(gc, "%s/state", h_path); + state = libxl__xs_read(gc, XBT_NULL, state_path); + + if (atoi(state) != HOTPLUG_DEVICE_CONNECTED) { + xs_watch(ctx->xsh, state_path, h_path); + tv.tv_sec = LIBXL_DESTROY_TIMEOUT; + tv.tv_usec = 0; + rc = libxl__wait_for_device_state(gc, &tv, HOTPLUG_DEVICE_CONNECTED, + NULL); + xs_unwatch(ctx->xsh, state_path, h_path); + if (rc < 0) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, + "unable to initialize nic device: %s", + nic->ifname); + goto out_free; + } + } + + rc = 0; +out_free: + flexarray_free(hotplug); +out: + GC_FREE; + return rc; +} + int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic) { GC_INIT(ctx); @@ -1652,6 +1844,22 @@ out: return rc; } +int libxl_device_nic_hotplug_remove(libxl_ctx *ctx, uint32_t domid, + libxl_device_nic *nic) +{ + GC_INIT(ctx); + libxl__device device; + int rc; + + rc = libxl__device_from_nic(gc, domid, nic, &device); + if (rc != 0) goto out; + + rc = libxl__device_hotplug_disconnect(gc, &device, HOTPLUG_DEVICE_DISCONNECT); +out: + GC_FREE; + return rc; +} + int libxl_device_nic_destroy(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic) { @@ -1668,6 +1876,23 @@ out: return rc; } +int libxl_device_nic_hotplug_destroy(libxl_ctx *ctx, uint32_t domid, + libxl_device_nic *nic) +{ + GC_INIT(ctx); + libxl__device device; + int rc; + + rc = libxl__device_from_nic(gc, domid, nic, &device); + if (rc != 0) goto out; + + rc = libxl__device_hotplug_disconnect(gc, &device, + HOTPLUG_DEVICE_FORCE_DISCONNECT); +out: + GC_FREE; + return rc; +} + static void libxl__device_nic_from_xs_be(libxl__gc *gc, const char *be_path, libxl_device_nic *nic) diff -r 937bbe68a194 -r bc38aa2e11e2 tools/libxl/libxl.h --- a/tools/libxl/libxl.h Thu Feb 02 11:30:27 2012 +0100 +++ b/tools/libxl/libxl.h Thu Feb 02 11:33:27 2012 +0100 @@ -416,6 +416,11 @@ libxl_vminfo * libxl_list_vm(libxl_ctx * * * Initalises device to a default configuration. * + * libxl_device_<type>_hotplug_add(ctx, domid, device): + * + * Creates the necessary xenstore entries to trigger the execution of + * a device addition, possibly on a different domain. + * * libxl_device_<type>_add(ctx, domid, device): * * Adds the given device to the specified domain. This can be called @@ -425,6 +430,10 @@ libxl_vminfo * libxl_list_vm(libxl_ctx * * domain to connect to the device and therefore cannot block on the * guest. * + * libxl_device_<type>_hotplug_remove(ctx, domid, device): + * + * Request the removal of the given device and waits for the result. + * * libxl_device_<type>_remove(ctx, domid, device): * * Removes the given device from the specified domain by performing @@ -442,14 +451,25 @@ libxl_vminfo * libxl_list_vm(libxl_ctx * * * This function does not interact with the guest and therefore * cannot block on the guest. + * + * libxl_device_<type>_hotplug_destroy(ctx, domid, device): + * + * Requests de destruction of the given device and waits for the result. + * */ /* Disks */ int libxl_device_disk_init(libxl_ctx *ctx, libxl_device_disk *disk); +int libxl_device_disk_hotplug_add(libxl_ctx *ctx, uint32_t domid, + libxl_device_disk *disk); int libxl_device_disk_add(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk); int libxl_device_disk_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk); +int libxl_device_disk_hotplug_remove(libxl_ctx *ctx, uint32_t domid, + libxl_device_disk *disk); int libxl_device_disk_destroy(libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk); +int libxl_device_disk_hotplug_destroy(libxl_ctx *ctx, uint32_t domid, + libxl_device_disk *disk); libxl_device_disk *libxl_device_disk_list(libxl_ctx *ctx, uint32_t domid, int *num); int libxl_device_disk_getinfo(libxl_ctx *ctx, uint32_t domid, @@ -470,9 +490,15 @@ int libxl_device_disk_local_detach(libxl /* Network Interfaces */ int libxl_device_nic_init(libxl_ctx *ctx, libxl_device_nic *nic); +int libxl_device_nic_hotplug_add(libxl_ctx *ctx, uint32_t domid, + libxl_device_nic *nic); int libxl_device_nic_add(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic); int libxl_device_nic_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic); +int libxl_device_nic_hotplug_remove(libxl_ctx *ctx, uint32_t domid, + libxl_device_nic *nic); int libxl_device_nic_destroy(libxl_ctx *ctx, uint32_t domid, libxl_device_nic *nic); +int libxl_device_nic_hotplug_destroy(libxl_ctx *ctx, uint32_t domid, + libxl_device_nic *nic); libxl_device_nic *libxl_device_nic_list(libxl_ctx *ctx, uint32_t domid, int *num); int libxl_device_nic_getinfo(libxl_ctx *ctx, uint32_t domid, _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |