diff options
author | Ian Campbell <ian.campbell@citrix.com> | 2010-10-05 17:51:28 +0100 |
---|---|---|
committer | Ian Campbell <ian.campbell@citrix.com> | 2010-10-05 17:51:28 +0100 |
commit | 5588033df56a5ac935ded5ae8587bc5841314863 (patch) | |
tree | 0de96be4bfa5f8d3cf3bbf46ea419560cc2fa724 /tools | |
parent | d2cd9d41fdf0d85572c06735ea4202d4969fcd1b (diff) | |
download | xen-5588033df56a5ac935ded5ae8587bc5841314863.tar.gz xen-5588033df56a5ac935ded5ae8587bc5841314863.tar.bz2 xen-5588033df56a5ac935ded5ae8587bc5841314863.zip |
libxl: remove console 0 backend directory from xenstore on devices destroy
The first PV console device has an unusual frontend path for
historical reasons (/local/domain/<domid>/console rather than
/local/domain/<domid>/device/console/0).
Therefore we need to check this additional frontend path as well as
those under /local/domain/<domid>/device when tearing down all
backends or else we miss the backend for the console.
As part of this we need to ensure that the frontend directory has a
valid link to the backend, currently this link does not exist.
Fix this by adding libxl__device_frontend_path to return the correct
frontend path, accounting for the special case, and use it from
libxl__device_add_generic. Also add libxl__device_backend_path for
consistency.
This also allows console 0 setup to follow essentially the same code
path as other consoles within libxl_device_console_add, reducing the
special casing required there.
This also fixes the link from backend to frontend which until now gave
a dangling link to the normal device path instead of the exceptional
one.
Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
committer: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/libxl/libxl.c | 60 | ||||
-rw-r--r-- | tools/libxl/libxl_device.c | 52 |
2 files changed, 59 insertions, 53 deletions
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 54b0ff1d67..540cf1d5ed 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -2331,30 +2331,6 @@ int libxl_device_console_add(libxl_ctx *ctx, uint32_t domid, libxl_device_consol libxl__device device; int rc; - if (console->build_state) { - xs_transaction_t t; - char **ents = (char **) libxl__calloc(&gc, 11, sizeof(char *)); - ents[0] = "console/port"; - ents[1] = libxl__sprintf(&gc, "%"PRIu32, console->build_state->console_port); - ents[2] = "console/ring-ref"; - ents[3] = libxl__sprintf(&gc, "%lu", console->build_state->console_mfn); - ents[4] = "console/limit"; - ents[5] = libxl__sprintf(&gc, "%d", LIBXL_XENCONSOLE_LIMIT); - ents[6] = "console/type"; - if (console->consback == LIBXL_CONSBACK_XENCONSOLED) - ents[7] = "xenconsoled"; - else - ents[7] = "ioemu"; - ents[8] = "console/output"; - ents[9] = console->output; -retry_transaction: - t = xs_transaction_start(ctx->xsh); - libxl__xs_writev(&gc, t, libxl__xs_get_dompath(&gc, console->domid), ents); - if (!xs_transaction_end(ctx->xsh, t, 0)) - if (errno == EAGAIN) - goto retry_transaction; - } - front = flexarray_make(16, 1); if (!front) { rc = ERROR_NOMEM; @@ -2384,24 +2360,32 @@ retry_transaction: flexarray_set(back, boffset++, "protocol"); flexarray_set(back, boffset++, LIBXL_XENCONSOLE_PROTOCOL); - /* if devid == 0 do not add the frontend to device/console/ because - * it has already been added to console/ */ - if (device.devid > 0) { - flexarray_set(front, foffset++, "backend-id"); - flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", console->backend_domid)); + flexarray_set(front, foffset++, "backend-id"); + flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", console->backend_domid)); + flexarray_set(front, foffset++, "limit"); + flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", LIBXL_XENCONSOLE_LIMIT)); + flexarray_set(front, foffset++, "type"); + if (console->consback == LIBXL_CONSBACK_XENCONSOLED) + flexarray_set(front, foffset++, "xenconsoled"); + else + flexarray_set(front, foffset++, "ioemu"); + flexarray_set(front, foffset++, "output"); + flexarray_set(front, foffset++, console->output); + + if (device.devid == 0) { + if (console->build_state == NULL) { + rc = ERROR_INVAL; + goto out_free; + } + flexarray_set(front, foffset++, "port"); + flexarray_set(front, foffset++, libxl__sprintf(&gc, "%"PRIu32, console->build_state->console_port)); + flexarray_set(front, foffset++, "ring-ref"); + flexarray_set(front, foffset++, libxl__sprintf(&gc, "%lu", console->build_state->console_mfn)); + } else { flexarray_set(front, foffset++, "state"); flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", 1)); - flexarray_set(front, foffset++, "limit"); - flexarray_set(front, foffset++, libxl__sprintf(&gc, "%d", LIBXL_XENCONSOLE_LIMIT)); flexarray_set(front, foffset++, "protocol"); flexarray_set(front, foffset++, LIBXL_XENCONSOLE_PROTOCOL); - flexarray_set(front, foffset++, "type"); - if (console->consback == LIBXL_CONSBACK_XENCONSOLED) - flexarray_set(front, foffset++, "xenconsoled"); - else - flexarray_set(front, foffset++, "ioemu"); - flexarray_set(front, foffset++, "output"); - flexarray_set(front, foffset++, console->output); } libxl__device_generic_add(ctx, &device, diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 6509440468..2a4f569e31 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -39,11 +39,32 @@ static const char *string_of_kinds[] = { [DEVICE_CONSOLE] = "console", }; +static char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device) +{ + char *dom_path = libxl__xs_get_dompath(gc, device->domid); + + /* Console 0 is a special case */ + if (device->kind == DEVICE_CONSOLE && device->devid == 0) + return libxl__sprintf(gc, "%s/console", dom_path); + + return libxl__sprintf(gc, "%s/device/%s/%d", dom_path, + string_of_kinds[device->kind], device->devid); +} + +static char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device) +{ + char *dom_path = libxl__xs_get_dompath(gc, device->backend_domid); + + return libxl__sprintf(gc, "%s/backend/%s/%u/%d", dom_path, + string_of_kinds[device->backend_kind], + device->domid, device->devid); +} + int libxl__device_generic_add(libxl_ctx *ctx, libxl__device *device, char **bents, char **fents) { libxl__gc gc = LIBXL_INIT_GC(ctx); - char *dom_path_backend, *dom_path, *frontend_path, *backend_path; + char *frontend_path, *backend_path; xs_transaction_t t; struct xs_permissions frontend_perms[2]; struct xs_permissions backend_perms[2]; @@ -54,13 +75,8 @@ int libxl__device_generic_add(libxl_ctx *ctx, libxl__device *device, goto out; } - dom_path_backend = libxl__xs_get_dompath(&gc, device->backend_domid); - dom_path = libxl__xs_get_dompath(&gc, device->domid); - - frontend_path = libxl__sprintf(&gc, "%s/device/%s/%d", - dom_path, string_of_kinds[device->kind], device->devid); - backend_path = libxl__sprintf(&gc, "%s/backend/%s/%u/%d", - dom_path_backend, string_of_kinds[device->backend_kind], device->domid, device->devid); + frontend_path = libxl__device_frontend_path(&gc, device); + backend_path = libxl__device_backend_path(&gc, device); frontend_perms[0].id = device->domid; frontend_perms[0].perms = XS_PERM_NONE; @@ -326,6 +342,16 @@ int libxl__devices_destroy(libxl_ctx *ctx, uint32_t domid, int force) } } } + + /* console 0 frontend directory is not under /local/domain/<domid>/device */ + fe_path = libxl__sprintf(&gc, "/local/domain/%d/console", domid); + be_path = libxl__xs_read(&gc, XBT_NULL, libxl__sprintf(&gc, "%s/backend", fe_path)); + if (be_path && strcmp(be_path, "")) { + if (libxl__device_destroy(ctx, be_path, force) > 0) + n_watches++; + flexarray_set(toremove, n++, libxl__dirname(&gc, be_path)); + } + if (!force) { /* Linux-ism. Most implementations leave the timeout * untouched after select. Linux, however, will chip @@ -356,15 +382,11 @@ out: int libxl__device_del(libxl_ctx *ctx, libxl__device *dev, int wait) { libxl__gc gc = LIBXL_INIT_GC(ctx); - char *dom_path_backend, *backend_path; + char *backend_path; int rc; - /* Create strings */ - dom_path_backend = libxl__xs_get_dompath(&gc, dev->backend_domid); - backend_path = libxl__sprintf(&gc, "%s/backend/%s/%u/%d", - dom_path_backend, - string_of_kinds[dev->backend_kind], - dev->domid, dev->devid); + backend_path = libxl__device_backend_path(&gc, dev); + rc = libxl__device_destroy(ctx, backend_path, !wait); if (rc == -1) { rc = ERROR_FAIL; |