Skip to contentSkip to conversation

libxl: remove console 0 backend directory from xenstore on devices destroy

PATCH Applied Ian Campbell 2 participants 2 messages Oct 5, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: remove console 0 backend directory from xenstore on devices destroy

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1286288339 -3600
# Node ID 0788bb897f692681036e33c0047e8cbb63565c35
# Parent a2c40fa3bc6c8471e1988e445f449975cf6f3822
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.

tools/libxl/libxl.c +22 -38
diff -r a2c40fa3bc6c -r 0788bb897f69 tools/libxl/libxl.c
@@ -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,
tools/libxl/libxl_device.c +37 -15

82 lines not on this page · raw message

#1 lore raw
Quoted 23 lines · Ian Campbell

# HG changeset patch
# User Ian Campbell <[email protected]>
# Date 1286288339 -3600
# Node ID 0788bb897f692681036e33c0047e8cbb63565c35
# Parent a2c40fa3bc6c8471e1988e445f449975cf6f3822
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.

Quoted 8 lines

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.

applied, thanks