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;
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,
[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];
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;
}
}
}
+
+ /* 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
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;