diff options
-rw-r--r-- | extras/mini-os/console/xenbus.c | 6 | ||||
-rw-r--r-- | tools/libxl/libxl.c | 58 | ||||
-rw-r--r-- | tools/libxl/libxl_device.c | 32 | ||||
-rw-r--r-- | tools/libxl/libxl_internal.h | 7 | ||||
-rw-r--r-- | tools/libxl/libxl_pci.c | 3 | ||||
-rw-r--r-- | tools/libxl/libxl_xshelp.c | 14 |
6 files changed, 78 insertions, 42 deletions
diff --git a/extras/mini-os/console/xenbus.c b/extras/mini-os/console/xenbus.c index 77de82a0fa..e65baf75a9 100644 --- a/extras/mini-os/console/xenbus.c +++ b/extras/mini-os/console/xenbus.c @@ -122,12 +122,6 @@ again: goto abort_transaction; } - err = xenbus_printf(xbt, nodename, "type", "%s", "ioemu"); - if (err) { - message = "writing type"; - goto abort_transaction; - } - snprintf(path, sizeof(path), "%s/state", nodename); err = xenbus_switch_state(xbt, path, XenbusStateConnected); if (err) { diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index ee1fa9cf8c..0612d85a24 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -1813,8 +1813,9 @@ void libxl__device_vtpm_add(libxl__egc *egc, uint32_t domid, flexarray_append(front, GCSPRINTF("%d", vtpm->devid)); libxl__device_generic_add(gc, XBT_NULL, device, - libxl__xs_kvs_of_flexarray(gc, back, back->count), - libxl__xs_kvs_of_flexarray(gc, front, front->count)); + libxl__xs_kvs_of_flexarray(gc, back, back->count), + libxl__xs_kvs_of_flexarray(gc, front, front->count), + NULL); aodev->dev = device; aodev->action = LIBXL__DEVICE_ACTION_ADD; @@ -2195,8 +2196,9 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid, } libxl__device_generic_add(gc, t, device, - libxl__xs_kvs_of_flexarray(gc, back, back->count), - libxl__xs_kvs_of_flexarray(gc, front, front->count)); + libxl__xs_kvs_of_flexarray(gc, back, back->count), + libxl__xs_kvs_of_flexarray(gc, front, front->count), + NULL); rc = libxl__xs_transaction_commit(gc, &t); if (!rc) break; @@ -2938,8 +2940,9 @@ void libxl__device_nic_add(libxl__egc *egc, uint32_t domid, flexarray_append(front, libxl__sprintf(gc, LIBXL_MAC_FMT, LIBXL_MAC_BYTES(nic->mac))); libxl__device_generic_add(gc, XBT_NULL, device, - libxl__xs_kvs_of_flexarray(gc, back, back->count), - libxl__xs_kvs_of_flexarray(gc, front, front->count)); + libxl__xs_kvs_of_flexarray(gc, back, back->count), + libxl__xs_kvs_of_flexarray(gc, front, front->count), + NULL); aodev->dev = device; aodev->action = LIBXL__DEVICE_ACTION_ADD; @@ -3132,7 +3135,7 @@ int libxl__device_console_add(libxl__gc *gc, uint32_t domid, libxl__device_console *console, libxl__domain_build_state *state) { - flexarray_t *front; + flexarray_t *front, *ro_front; flexarray_t *back; libxl__device device; int rc; @@ -3143,6 +3146,7 @@ int libxl__device_console_add(libxl__gc *gc, uint32_t domid, } front = flexarray_make(gc, 16, 1); + ro_front = flexarray_make(gc, 16, 1); back = flexarray_make(gc, 16, 1); device.backend_devid = console->devid; @@ -3165,21 +3169,24 @@ int libxl__device_console_add(libxl__gc *gc, uint32_t domid, flexarray_append(front, "backend-id"); flexarray_append(front, libxl__sprintf(gc, "%d", console->backend_domid)); - flexarray_append(front, "limit"); - flexarray_append(front, libxl__sprintf(gc, "%d", LIBXL_XENCONSOLE_LIMIT)); - flexarray_append(front, "type"); + + flexarray_append(ro_front, "limit"); + flexarray_append(ro_front, libxl__sprintf(gc, "%d", LIBXL_XENCONSOLE_LIMIT)); + flexarray_append(ro_front, "type"); if (console->consback == LIBXL__CONSOLE_BACKEND_XENCONSOLED) - flexarray_append(front, "xenconsoled"); + flexarray_append(ro_front, "xenconsoled"); else - flexarray_append(front, "ioemu"); - flexarray_append(front, "output"); - flexarray_append(front, console->output); + flexarray_append(ro_front, "ioemu"); + flexarray_append(ro_front, "output"); + flexarray_append(ro_front, console->output); + flexarray_append(ro_front, "tty"); + flexarray_append(ro_front, ""); if (state) { - flexarray_append(front, "port"); - flexarray_append(front, libxl__sprintf(gc, "%"PRIu32, state->console_port)); - flexarray_append(front, "ring-ref"); - flexarray_append(front, libxl__sprintf(gc, "%lu", state->console_mfn)); + flexarray_append(ro_front, "port"); + flexarray_append(ro_front, libxl__sprintf(gc, "%"PRIu32, state->console_port)); + flexarray_append(ro_front, "ring-ref"); + flexarray_append(ro_front, libxl__sprintf(gc, "%lu", state->console_mfn)); } else { flexarray_append(front, "state"); flexarray_append(front, libxl__sprintf(gc, "%d", 1)); @@ -3188,8 +3195,9 @@ int libxl__device_console_add(libxl__gc *gc, uint32_t domid, } libxl__device_generic_add(gc, XBT_NULL, &device, - libxl__xs_kvs_of_flexarray(gc, back, back->count), - libxl__xs_kvs_of_flexarray(gc, front, front->count)); + libxl__xs_kvs_of_flexarray(gc, back, back->count), + libxl__xs_kvs_of_flexarray(gc, front, front->count), + libxl__xs_kvs_of_flexarray(gc, ro_front, ro_front->count)); rc = 0; out: return rc; @@ -3274,8 +3282,9 @@ int libxl__device_vkb_add(libxl__gc *gc, uint32_t domid, flexarray_append(front, libxl__sprintf(gc, "%d", 1)); libxl__device_generic_add(gc, XBT_NULL, &device, - libxl__xs_kvs_of_flexarray(gc, back, back->count), - libxl__xs_kvs_of_flexarray(gc, front, front->count)); + libxl__xs_kvs_of_flexarray(gc, back, back->count), + libxl__xs_kvs_of_flexarray(gc, front, front->count), + NULL); rc = 0; out: return rc; @@ -3387,8 +3396,9 @@ int libxl__device_vfb_add(libxl__gc *gc, uint32_t domid, libxl_device_vfb *vfb) flexarray_append_pair(front, "state", libxl__sprintf(gc, "%d", 1)); libxl__device_generic_add(gc, XBT_NULL, &device, - libxl__xs_kvs_of_flexarray(gc, back, back->count), - libxl__xs_kvs_of_flexarray(gc, front, front->count)); + libxl__xs_kvs_of_flexarray(gc, back, back->count), + libxl__xs_kvs_of_flexarray(gc, front, front->count), + NULL); rc = 0; out: return rc; diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index bc86648af8..ea845b7334 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -84,11 +84,12 @@ out: } int libxl__device_generic_add(libxl__gc *gc, xs_transaction_t t, - libxl__device *device, char **bents, char **fents) + libxl__device *device, char **bents, char **fents, char **ro_fents) { libxl_ctx *ctx = libxl__gc_owner(gc); char *frontend_path, *backend_path; struct xs_permissions frontend_perms[2]; + struct xs_permissions ro_frontend_perms[2]; struct xs_permissions backend_perms[2]; int create_transaction = t == XBT_NULL; @@ -100,22 +101,37 @@ int libxl__device_generic_add(libxl__gc *gc, xs_transaction_t t, frontend_perms[1].id = device->backend_domid; frontend_perms[1].perms = XS_PERM_READ; - backend_perms[0].id = device->backend_domid; - backend_perms[0].perms = XS_PERM_NONE; - backend_perms[1].id = device->domid; - backend_perms[1].perms = XS_PERM_READ; + ro_frontend_perms[0].id = backend_perms[0].id = device->backend_domid; + ro_frontend_perms[0].perms = backend_perms[0].perms = XS_PERM_NONE; + ro_frontend_perms[1].id = backend_perms[1].id = device->domid; + ro_frontend_perms[1].perms = backend_perms[1].perms = XS_PERM_READ; retry_transaction: if (create_transaction) t = xs_transaction_start(ctx->xsh); /* FIXME: read frontend_path and check state before removing stuff */ - if (fents) { + if (fents || ro_fents) { xs_rm(ctx->xsh, t, frontend_path); xs_mkdir(ctx->xsh, t, frontend_path); - xs_set_permissions(ctx->xsh, t, frontend_path, frontend_perms, ARRAY_SIZE(frontend_perms)); + /* Console 0 is a special case. It doesn't use the regular PV + * state machine but also the frontend directory has + * historically contained other information, such as the + * vnc-port, which we don't want the guest fiddling with. + */ + if (device->kind == LIBXL__DEVICE_KIND_CONSOLE && device->devid == 0) + xs_set_permissions(ctx->xsh, t, frontend_path, + ro_frontend_perms, ARRAY_SIZE(ro_frontend_perms)); + else + xs_set_permissions(ctx->xsh, t, frontend_path, + frontend_perms, ARRAY_SIZE(frontend_perms)); xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/backend", frontend_path), backend_path, strlen(backend_path)); - libxl__xs_writev(gc, t, frontend_path, fents); + if (fents) + libxl__xs_writev_perms(gc, t, frontend_path, fents, + frontend_perms, ARRAY_SIZE(frontend_perms)); + if (ro_fents) + libxl__xs_writev_perms(gc, t, frontend_path, ro_fents, + ro_frontend_perms, ARRAY_SIZE(ro_frontend_perms)); } if (bents) { diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 3ba3a21850..00ff6b96cd 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -519,6 +519,11 @@ _hidden char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int /* treats kvs as pairs of keys and values and writes each to dir. */ _hidden int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t, const char *dir, char **kvs); +/* as writev but also sets the permissions on each path */ +_hidden int libxl__xs_writev_perms(libxl__gc *gc, xs_transaction_t t, + const char *dir, char *kvs[], + struct xs_permissions *perms, + unsigned int num_perms); /* _atonce creates a transaction and writes all keys at once */ _hidden int libxl__xs_writev_atonce(libxl__gc *gc, const char *dir, char **kvs); @@ -933,7 +938,7 @@ _hidden int libxl__device_console_add(libxl__gc *gc, uint32_t domid, libxl__domain_build_state *state); _hidden int libxl__device_generic_add(libxl__gc *gc, xs_transaction_t t, - libxl__device *device, char **bents, char **fents); + libxl__device *device, char **bents, char **fents, char **ro_fents); _hidden char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device); _hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device *device); _hidden int libxl__parse_backend_path(libxl__gc *gc, const char *path, diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index eac35c10f2..2f9f010cb3 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -102,7 +102,8 @@ int libxl__create_pci_backend(libxl__gc *gc, uint32_t domid, libxl__device_generic_add(gc, XBT_NULL, &device, libxl__xs_kvs_of_flexarray(gc, back, back->count), - libxl__xs_kvs_of_flexarray(gc, front, front->count)); + libxl__xs_kvs_of_flexarray(gc, front, front->count), + NULL); return 0; } diff --git a/tools/libxl/libxl_xshelp.c b/tools/libxl/libxl_xshelp.c index 52af4842e4..d7eaa660bb 100644 --- a/tools/libxl/libxl_xshelp.c +++ b/tools/libxl/libxl_xshelp.c @@ -41,8 +41,10 @@ char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int length) return kvs; } -int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t, - const char *dir, char *kvs[]) +int libxl__xs_writev_perms(libxl__gc *gc, xs_transaction_t t, + const char *dir, char *kvs[], + struct xs_permissions *perms, + unsigned int num_perms) { libxl_ctx *ctx = libxl__gc_owner(gc); char *path; @@ -56,11 +58,19 @@ int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t, if (path && kvs[i + 1]) { int length = strlen(kvs[i + 1]); xs_write(ctx->xsh, t, path, kvs[i + 1], length); + if (perms) + xs_set_permissions(ctx->xsh, t, path, perms, num_perms); } } return 0; } +int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t, + const char *dir, char *kvs[]) +{ + return libxl__xs_writev_perms(gc, t, dir, kvs, NULL, 0); +} + int libxl__xs_writev_atonce(libxl__gc *gc, const char *dir, char *kvs[]) { |