[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] libxl: remove console 0 backend directory from xenstore on devices destroy



# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1286297488 -3600
# Node ID 368957d8b063273d3bad38b122d15b5b8fda29ec
# Parent  83a97418d9cd6c67b0f1befc9b7b4c4385125c5f
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@xxxxxxxxxx>
Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
committer: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
---
 tools/libxl/libxl.c        |   60 ++++++++++++++++-----------------------------
 tools/libxl/libxl_device.c |   52 +++++++++++++++++++++++++++------------
 2 files changed, 59 insertions(+), 53 deletions(-)

diff -r 83a97418d9cd -r 368957d8b063 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Tue Oct 05 14:22:19 2010 +0100
+++ b/tools/libxl/libxl.c       Tue Oct 05 17:51:28 2010 +0100
@@ -2331,30 +2331,6 @@ int libxl_device_console_add(libxl_ctx *
     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 -r 83a97418d9cd -r 368957d8b063 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c        Tue Oct 05 14:22:19 2010 +0100
+++ b/tools/libxl/libxl_device.c        Tue Oct 05 17:51:28 2010 +0100
@@ -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 
         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 *ct
             }
         }
     }
+
+    /* 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 @@ int libxl__device_del(libxl_ctx *ctx, li
 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;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.