[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC 5/6] libxl: implementation of PV DRM device interface
From: Pavlo Suikov <pavlo.suikov@xxxxxxxxxxxxxxx> Signed-off-by: Pavlo Suikov <pavlo.suikov@xxxxxxxxxxxxxxx> Signed-off-by: Glib Golubytskyi <glib.golubytskyi@xxxxxxxxxxxxxxx> Signed-off-by: Iurii Konovalenko <iurii.konovalenko@xxxxxxxxxxxxxxx> Signed-off-by: Iurii Mykhalskyi <iurii.mykhalskyi@xxxxxxxxxxxxxxx> --- tools/libxl/libxl.c | 290 +++++++++++++++++++++++++++++++++++ tools/libxl/libxl.h | 18 +++ tools/libxl/libxl_create.c | 42 ++++- tools/libxl/libxl_device.c | 2 + tools/libxl/libxl_internal.h | 13 +- tools/libxl/libxl_types.idl | 21 +++ tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/libxl_utils.h | 3 + tools/libxl/xl.h | 3 + tools/libxl/xl_cmdimpl.c | 164 +++++++++++++++++++- tools/libxl/xl_cmdtable.c | 15 ++ 11 files changed, 567 insertions(+), 5 deletions(-) diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index b64815e..ccb0411 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -2595,6 +2595,284 @@ exit: /******************************************************************************/ +int libxl__device_vdrm_setdefault(libxl__gc *gc, libxl_device_vdrm *vdrm) +{ + int rc; + + rc = libxl__resolve_domid(gc, vdrm->backend_domname, &vdrm->backend_domid); + + return rc; +} + +static int libxl__device_from_vdrm(libxl__gc *gc, uint32_t domid, libxl_device_vdrm *vdrm, libxl__device *device) +{ + device->backend_devid = vdrm->devid; + device->backend_domid = vdrm->backend_domid; + device->backend_kind = LIBXL__DEVICE_KIND_VDRM; + device->devid = vdrm->devid; + device->domid = domid; + device->kind = LIBXL__DEVICE_KIND_VDRM; + + return 0; +} + +static int libxl__device_vdrm_from_xs_be(libxl__gc *gc, + const char *be_path, + libxl_device_vdrm *vdrm) +{ + const char *tmp; + int rc; + + libxl_device_vdrm_init(vdrm); + + tmp = READ_BACKEND(gc, "device-id"); + if (tmp) + vdrm->devid = atoi(tmp); + else + vdrm->devid = 0; + + rc = 0; + out: + return rc; +} + +int libxl_devid_to_device_vdrm(libxl_ctx *ctx, uint32_t domid, + int devid, libxl_device_vdrm *vdrm) +{ + GC_INIT(ctx); + char *dompath, *path; + int rc = ERROR_FAIL; + + libxl_device_vdrm_init(vdrm); + dompath = libxl__xs_get_dompath(gc, domid); + if (!dompath) + goto out; + + path = libxl__xs_read(gc, XBT_NULL, + libxl__sprintf(gc, "%s/device/vdrm/%d/backend", + dompath, devid)); + if (!path) + goto out; + + rc = libxl__device_vdrm_from_xs_be(gc, path, vdrm); + if (rc) goto out; + + rc = 0; +out: + GC_FREE; + return rc; +} + +void libxl__device_vdrm_add(libxl__egc *egc, uint32_t domid, libxl_device_vdrm *vdrm, libxl__ao_device *aodev) +{ + STATE_AO_GC(aodev->ao); + flexarray_t *front; + flexarray_t *back; + libxl__device *device; + int rc; + xs_transaction_t t = XBT_NULL; + libxl_domain_config d_config; + libxl_device_vdrm vdrm_saved; + libxl__domain_userdata_lock *lock = NULL; + + libxl_domain_config_init(&d_config); + libxl_device_vdrm_init(&vdrm_saved); + libxl_device_vdrm_copy(CTX, &vdrm_saved, vdrm); + + rc = libxl__device_vdrm_setdefault(gc, vdrm); + if (rc) goto out; + + front = flexarray_make(gc, 16, 1); + back = flexarray_make(gc, 32, 1); + + if ((vdrm->devid = libxl__device_nextid(gc, domid, "vdrm")) < 0) { + rc = ERROR_FAIL; + goto out; + } + + GCNEW(device); + rc = libxl__device_from_vdrm(gc, domid, vdrm, device); + if ( rc != 0 ) goto out; + + flexarray_append(back, "device-id"); + flexarray_append(back, GCSPRINTF("%d", vdrm->devid)); + flexarray_append(back, "frontend-id"); + flexarray_append(back, GCSPRINTF("%d", domid)); + flexarray_append(back, "device"); + flexarray_append(back, vdrm->device); + flexarray_append(back, "online"); + flexarray_append(back, "1"); + flexarray_append(back, "state"); + flexarray_append(back, GCSPRINTF("%d", 1)); + flexarray_append(back, "mode0"); + flexarray_append(back, vdrm->mode0); + flexarray_append(back, "mode1"); + flexarray_append(back, vdrm->mode1); + + flexarray_append(front, "device-id"); + flexarray_append(front, GCSPRINTF("%d", vdrm->devid)); + flexarray_append(front, "backend-id"); + flexarray_append(front, GCSPRINTF("%d", vdrm->backend_domid)); + flexarray_append(front, "state"); + flexarray_append(front, GCSPRINTF("%d", 1)); + flexarray_append(front, "mode0"); + flexarray_append(front, vdrm->mode0); + flexarray_append(front, "mode1"); + flexarray_append(front, vdrm->mode1); + + if (aodev->update_json) { + lock = libxl__lock_domain_userdata(gc, domid); + if (!lock) { + rc = ERROR_LOCK_FAIL; + goto out; + } + + rc = libxl__get_domain_configuration(gc, domid, &d_config); + LOG(INFO, "aodev updates JSON, libxl__get_domain_configuration returned %d", rc); + if (rc) goto out; + + DEVICE_ADD(vdrm, vdrms, domid, &vdrm_saved, COMPARE_DEVID, &d_config); + } + + for (;;) { + rc = libxl__xs_transaction_start(gc, &t); + if (rc) goto out; + + rc = libxl__device_exists(gc, t, device); + if (rc < 0) goto out; + if (rc == 1) { /* already exists in xenstore */ + LOG(ERROR, "device already exists in xenstore"); + aodev->action = LIBXL__DEVICE_ACTION_ADD; /* for error message */ + rc = ERROR_DEVICE_EXISTS; + goto out; + } + + if (aodev->update_json) { + rc = libxl__set_domain_configuration(gc, domid, &d_config); + if (rc) goto out; + } + + 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), + NULL); + + rc = libxl__xs_transaction_commit(gc, &t); + + if (!rc) break; + if (rc < 0) goto out; + } + + aodev->dev = device; + aodev->action = LIBXL__DEVICE_ACTION_ADD; + libxl__wait_device_connection(egc, aodev); + + rc = 0; +out: + libxl__xs_transaction_abort(gc, &t); + if (lock) libxl__unlock_domain_userdata(lock); + libxl_device_vdrm_dispose(&vdrm_saved); + libxl_domain_config_dispose(&d_config); + aodev->rc = rc; + if(rc) aodev->callback(egc, aodev); + return; + +} + +libxl_device_vdrm *libxl_device_vdrm_list(libxl_ctx *ctx, uint32_t domid, int *num) +{ + GC_INIT(ctx); + + libxl_device_vdrm* vdrms = NULL; + char* fe_path = NULL; + char** dir = NULL; + unsigned int ndirs = 0; + + *num = 0; + + fe_path = libxl__sprintf(gc, "%s/device/vdrm", libxl__xs_get_dompath(gc, domid)); + dir = libxl__xs_directory(gc, XBT_NULL, fe_path, &ndirs); + if (dir && ndirs) { + vdrms = malloc(sizeof(*vdrms) * ndirs); + libxl_device_vdrm* vdrm; + libxl_device_vdrm* end = vdrms + ndirs; + for(vdrm = vdrms; vdrm < end; ++vdrm, ++dir) { + char* tmp; + + libxl_device_vdrm_init(vdrm); + + vdrm->devid = atoi(*dir); + + tmp = libxl__xs_read(gc, XBT_NULL, + GCSPRINTF("%s/%s/backend-id", + fe_path, *dir)); + vdrm->backend_domid = atoi(tmp); + } + } + *num = ndirs; + + GC_FREE; + return vdrms; +} + +int libxl_device_vdrm_getinfo(libxl_ctx *ctx, uint32_t domid, libxl_device_vdrm *vdrm, libxl_vdrminfo *vdrminfo) +{ + GC_INIT(ctx); + char *dompath, *vdrmpath; + char *val; + int rc = 0; + + libxl_vdrminfo_init(vdrminfo); + dompath = libxl__xs_get_dompath(gc, domid); + vdrminfo->devid = vdrm->devid; + + vdrmpath = GCSPRINTF("%s/device/vdrm/%d", dompath, vdrminfo->devid); + vdrminfo->backend = xs_read(ctx->xsh, XBT_NULL, + GCSPRINTF("%s/backend", vdrmpath), NULL); + + if (!vdrminfo->backend) { + goto err; + } + + if(!libxl__xs_read(gc, XBT_NULL, vdrminfo->backend)) { + goto err; + } + + val = libxl__xs_read(gc, XBT_NULL, + GCSPRINTF("%s/backend-id", vdrmpath)); + vdrminfo->backend_id = val ? strtoul(val, NULL, 10) : -1; + + val = libxl__xs_read(gc, XBT_NULL, + GCSPRINTF("%s/state", vdrmpath)); + vdrminfo->state = val ? strtoul(val, NULL, 10) : -1; + + val = libxl__xs_read(gc, XBT_NULL, + GCSPRINTF("%s/event-channel", vdrmpath)); + vdrminfo->evtch = val ? strtoul(val, NULL, 10) : -1; + + val = libxl__xs_read(gc, XBT_NULL, + GCSPRINTF("%s/ring-ref", vdrmpath)); + vdrminfo->rref = val ? strtoul(val, NULL, 10) : -1; + + vdrminfo->frontend = xs_read(ctx->xsh, XBT_NULL, + GCSPRINTF("%s/frontend", vdrminfo->backend), NULL); + + val = libxl__xs_read(gc, XBT_NULL, + GCSPRINTF("%s/frontend-id", vdrminfo->backend)); + vdrminfo->frontend_id = val ? strtoul(val, NULL, 10) : -1; + + goto exit; +err: + rc = ERROR_FAIL; +exit: + GC_FREE; + return rc; +} + +/******************************************************************************/ + int libxl__device_vtty_setdefault(libxl__gc *gc, libxl_device_vtty *vtty) { int rc; @@ -5293,6 +5571,8 @@ exit: * libxl_device_vtpm_destroy * libxl_device_vrtc_remove * libxl_device_vrtc_destroy + * libxl_device_vdrm_remove + * libxl_device_vdrm_destroy * libxl_device_vsnd_remove * libxl_device_vsnd_destroy * libxl_device_vtty_remove @@ -5353,6 +5633,10 @@ DEFINE_DEVICE_REMOVE(vtpm, destroy, 1) DEFINE_DEVICE_REMOVE(vrtc, remove, 0) DEFINE_DEVICE_REMOVE(vrtc, destroy, 1) +/* vdrm */ +DEFINE_DEVICE_REMOVE(vdrm, remove, 0) +DEFINE_DEVICE_REMOVE(vdrm, destroy, 1) + /* vsnd */ DEFINE_DEVICE_REMOVE(vsnd, remove, 0) DEFINE_DEVICE_REMOVE(vsnd, destroy, 1) @@ -5379,6 +5663,7 @@ DEFINE_DEVICE_REMOVE(vevent, destroy, 1) * libxl_device_nic_add * libxl_device_vtpm_add * libxl_device_vrtc_add + * libxl_device_vdrm_add * libxl_device_vsnd_add * libxl_device_vtty_add * libxl_device_vevent_add @@ -5416,6 +5701,9 @@ DEFINE_DEVICE_ADD(vtpm) /* vrtc */ DEFINE_DEVICE_ADD(vrtc) +/* vdrm */ +DEFINE_DEVICE_ADD(vdrm) + /* vsnd */ DEFINE_DEVICE_ADD(vsnd) @@ -7942,6 +8230,8 @@ int libxl_retrieve_domain_configuration(libxl_ctx *ctx, uint32_t domid, MERGE(vrtc, vrtcs, COMPARE_DEVID, {}); + MERGE(vdrm, vdrms, COMPARE_DEVID, {}); + MERGE(vsnd, vsnds, COMPARE_DEVID, {}); MERGE(pci, pcidevs, COMPARE_PCI, {}); diff --git a/tools/libxl/libxl.h b/tools/libxl/libxl.h index 7799374..57f3e03 100644 --- a/tools/libxl/libxl.h +++ b/tools/libxl/libxl.h @@ -1451,6 +1451,24 @@ int libxl_device_vrtc_destroy(libxl_ctx *ctx, uint32_t domid, libxl_device_vrtc *libxl_device_vrtc_list(libxl_ctx *ctx, uint32_t domid, int *num); int libxl_device_vrtc_getinfo(libxl_ctx *ctx, uint32_t domid, libxl_device_vrtc *vrtc, libxl_vrtcinfo *vrtcinfo); + +/* DRM */ +int libxl_device_vdrm_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vdrm *vdrm, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_device_vdrm_remove(libxl_ctx *ctx, uint32_t domid, + libxl_device_vdrm *vdrm, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; +int libxl_device_vdrm_destroy(libxl_ctx *ctx, uint32_t domid, + libxl_device_vdrm *vdrm, + const libxl_asyncop_how *ao_how) + LIBXL_EXTERNAL_CALLERS_ONLY; + +libxl_device_vdrm *libxl_device_vdrm_list(libxl_ctx *ctx, uint32_t domid, int *num); +int libxl_device_vdrm_getinfo(libxl_ctx *ctx, uint32_t domid, + libxl_device_vdrm *vdrm, libxl_vdrminfo *vdrminfo); + /* Audio */ int libxl_device_vsnd_add(libxl_ctx *ctx, uint32_t domid, libxl_device_vsnd *vsnd, const libxl_asyncop_how *ao_how) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 1752499..6e1c0d8 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -736,6 +736,8 @@ static void domcreate_attach_vtpms(libxl__egc *egc, libxl__multidev *multidev, int ret); static void domcreate_attach_vrtcs(libxl__egc *egc, libxl__multidev *multidev, int ret); +static void domcreate_attach_vdrms(libxl__egc *egc, libxl__multidev *multidev, + int ret); static void domcreate_attach_vttys(libxl__egc *egc, libxl__multidev *multidev, int ret); static void domcreate_attach_vsnds(libxl__egc *egc, libxl__multidev *multidev, @@ -1433,12 +1435,45 @@ static void domcreate_attach_vrtcs(libxl__egc *egc, if (d_config->num_vrtcs > 0) { /* Attach vrtcs */ libxl__multidev_begin(ao, &dcs->multidev); - dcs->multidev.callback = domcreate_attach_vttys; + dcs->multidev.callback = domcreate_attach_vdrms; libxl__add_vrtcs(egc, ao, domid, d_config, &dcs->multidev); libxl__multidev_prepared(egc, &dcs->multidev, 0); return; } + domcreate_attach_vdrms(egc, multidev, 0); + return; + +error_out: + assert(ret); + domcreate_complete(egc, dcs, ret); +} + +static void domcreate_attach_vdrms(libxl__egc *egc, + libxl__multidev *multidev, + int ret) +{ + libxl__domain_create_state *dcs = CONTAINER_OF(multidev, *dcs, multidev); + STATE_AO_GC(dcs->ao); + int domid = dcs->guest_domid; + + libxl_domain_config* const d_config = dcs->guest_config; + + if(ret) { + LOG(ERROR, "unable to add vrtc devices"); + goto error_out; + } + + /* Plug vdrm devices */ + if (d_config->num_vdrms > 0) { + /* Attach vdrms */ + libxl__multidev_begin(ao, &dcs->multidev); + dcs->multidev.callback = domcreate_attach_vttys; + libxl__add_vdrms(egc, ao, domid, d_config, &dcs->multidev); + libxl__multidev_prepared(egc, &dcs->multidev, 0); + return; + } + domcreate_attach_vttys(egc, multidev, 0); return; @@ -1447,6 +1482,7 @@ error_out: domcreate_complete(egc, dcs, ret); } + static void domcreate_attach_vttys(libxl__egc *egc, libxl__multidev *multidev, int ret) @@ -1458,7 +1494,7 @@ static void domcreate_attach_vttys(libxl__egc *egc, libxl_domain_config* const d_config = dcs->guest_config; if(ret) { - LOG(ERROR, "unable to add vtty devices"); + LOG(ERROR, "unable to add vdrm devices"); goto error_out; } @@ -1491,7 +1527,7 @@ static void domcreate_attach_vsnds(libxl__egc *egc, libxl_domain_config* const d_config = dcs->guest_config; if(ret) { - LOG(ERROR, "unable to add vrtc devices"); + LOG(ERROR, "unable to add vtty devices"); goto error_out; } diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c index 65569e1..13c4a7b 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -545,6 +545,7 @@ void libxl__multidev_prepared(libxl__egc *egc, * libxl__add_nics * libxl__add_vtpms * libxl__add_vrtcs + * libxl__add_vdrms * libxl__add_vsnds * libxl__add_vttys * libxl__add_vevents @@ -568,6 +569,7 @@ DEFINE_DEVICES_ADD(disk) DEFINE_DEVICES_ADD(nic) DEFINE_DEVICES_ADD(vtpm) DEFINE_DEVICES_ADD(vrtc) +DEFINE_DEVICES_ADD(vdrm) DEFINE_DEVICES_ADD(vsnd) DEFINE_DEVICES_ADD(vtty) DEFINE_DEVICES_ADD(vevent) diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 330d56f..80754df 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -480,7 +480,8 @@ typedef struct { (dev)->backend_kind == LIBXL__DEVICE_KIND_VRTC || \ (dev)->backend_kind == LIBXL__DEVICE_KIND_VSND || \ (dev)->backend_kind == LIBXL__DEVICE_KIND_VTTY || \ - (dev)->backend_kind == LIBXL__DEVICE_KIND_VEVENT) + (dev)->backend_kind == LIBXL__DEVICE_KIND_VEVENT || \ + (dev)->backend_kind == LIBXL__DEVICE_KIND_VDRM) #define XC_PCI_BDF "0x%x, 0x%x, 0x%x, 0x%x" #define PCI_DEVFN(slot, func) ((((slot) & 0x1f) << 3) | ((func) & 0x07)) @@ -1191,6 +1192,7 @@ _hidden int libxl__device_nic_setdefault(libxl__gc *gc, libxl_device_nic *nic, uint32_t domid); _hidden int libxl__device_vtpm_setdefault(libxl__gc *gc, libxl_device_vtpm *vtpm); _hidden int libxl__device_vrtc_setdefault(libxl__gc *gc, libxl_device_vrtc *vrtc); +_hidden int libxl__device_vdrm_setdefault(libxl__gc *gc, libxl_device_vdrm *vdrm); _hidden int libxl__device_vsnd_setdefault(libxl__gc *gc, libxl_device_vsnd *vsnd); _hidden int libxl__device_vtty_setdefault(libxl__gc *gc, libxl_device_vtty *vtty); _hidden int libxl__device_vfb_setdefault(libxl__gc *gc, libxl_device_vfb *vfb); @@ -2578,6 +2580,11 @@ _hidden void libxl__device_vrtc_add(libxl__egc *egc, uint32_t domid, libxl_device_vrtc *vrtc, libxl__ao_device *aodev); +/* AO operation to connect a drm device */ +_hidden void libxl__device_vdrm_add(libxl__egc *egc, uint32_t domid, + libxl_device_vdrm *vdrm, + libxl__ao_device *aodev); + /* AO operation to connect a sound device */ _hidden void libxl__device_vsnd_add(libxl__egc *egc, uint32_t domid, libxl_device_vsnd *vsnd, @@ -3313,6 +3320,10 @@ _hidden void libxl__add_vrtcs(libxl__egc *egc, libxl__ao *ao, uint32_t domid, libxl_domain_config *d_config, libxl__multidev *multidev); +_hidden void libxl__add_vdrms(libxl__egc *egc, libxl__ao *ao, uint32_t domid, + libxl_domain_config *d_config, + libxl__multidev *multidev); + _hidden void libxl__add_vttys(libxl__egc *egc, libxl__ao *ao, uint32_t domid, libxl_domain_config *d_config, libxl__multidev *multidev); diff --git a/tools/libxl/libxl_types.idl b/tools/libxl/libxl_types.idl index 23fcf50..27583cc 100644 --- a/tools/libxl/libxl_types.idl +++ b/tools/libxl/libxl_types.idl @@ -560,6 +560,15 @@ libxl_device_vrtc = Struct("device_vrtc", [ ("device", string), ]) +libxl_device_vdrm = Struct("device_vdrm", [ + ("backend_domid", libxl_domid), + ("backend_domname", string), + ("devid", libxl_devid), + ("device", string), + ("mode0", string), + ("mode1", string), + ]) + libxl_device_vsnd = Struct("device_vsnd", [ ("backend_domid", libxl_domid), ("backend_domname", string), @@ -676,6 +685,7 @@ libxl_domain_config = Struct("domain_config", [ ("vkbs", Array(libxl_device_vkb, "num_vkbs")), ("vtpms", Array(libxl_device_vtpm, "num_vtpms")), ("vrtcs", Array(libxl_device_vrtc, "num_vrtcs")), + ("vdrms", Array(libxl_device_vdrm, "num_vdrms")), ("vsnds", Array(libxl_device_vsnd, "num_vsnds")), ("vttys", Array(libxl_device_vtty, "num_vttys")), # a channel manifests as a console with a name, @@ -734,6 +744,17 @@ libxl_vrtcinfo = Struct("vrtcinfo", [ ("rref", integer), ], dir=DIR_OUT) +libxl_vdrminfo = Struct("vdrminfo", [ + ("backend", string), + ("backend_id", uint32), + ("frontend", string), + ("frontend_id", uint32), + ("devid", libxl_devid), + ("state", integer), + ("evtch", integer), + ("rref", integer), + ], dir=DIR_OUT) + libxl_vsndinfo = Struct("vsndinfo", [ ("backend", string), ("backend_id", uint32), diff --git a/tools/libxl/libxl_types_internal.idl b/tools/libxl/libxl_types_internal.idl index a86325c..9a68700 100644 --- a/tools/libxl/libxl_types_internal.idl +++ b/tools/libxl/libxl_types_internal.idl @@ -26,6 +26,7 @@ libxl__device_kind = Enumeration("device_kind", [ (10, "VSND"), (11, "VTTY"), (12, "VEVENT"), + (13, "VDRM"), ]) libxl__console_backend = Enumeration("console_backend", [ diff --git a/tools/libxl/libxl_utils.h b/tools/libxl/libxl_utils.h index 24a8205..e1532a2 100644 --- a/tools/libxl/libxl_utils.h +++ b/tools/libxl/libxl_utils.h @@ -80,6 +80,9 @@ int libxl_devid_to_device_vtpm(libxl_ctx *ctx, uint32_t domid, int libxl_devid_to_device_vrtc(libxl_ctx *ctx, uint32_t domid, int devid, libxl_device_vrtc *vrtc); +int libxl_devid_to_device_vdrm(libxl_ctx *ctx, uint32_t domid, + int devid, libxl_device_vdrm *vdrm); + int libxl_devid_to_device_vsnd(libxl_ctx *ctx, uint32_t domid, int devid, libxl_device_vsnd *vsnd); diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h index 905276d..7c0082c 100644 --- a/tools/libxl/xl.h +++ b/tools/libxl/xl.h @@ -85,6 +85,9 @@ int main_blockdetach(int argc, char **argv); int main_vrtcattach(int argc, char **argv); int main_vrtclist(int argc, char **argv); int main_vrtcdetach(int argc, char **argv); +int main_vdrmattach(int argc, char **argv); +int main_vdrmlist(int argc, char **argv); +int main_vdrmdetach(int argc, char **argv); int main_vsndattach(int argc, char **argv); int main_vsndlist(int argc, char **argv); int main_vsnddetach(int argc, char **argv); diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index f8f9edf..df9ebd2 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -1272,7 +1272,7 @@ static void parse_config_data(const char *config_source, long l, vcpus = 0; XLU_Config *config; XLU_ConfigList *cpus, *cpuids, *vbds, *nics, *pcis; - XLU_ConfigList *cvfbs, *vevents, *vtpms, *vrtcs, *vttys, *vsnds; + XLU_ConfigList *cvfbs, *vevents, *vtpms, *vrtcs, *vttys, *vsnds, *vdrms; XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian, *dtdevs; int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian; int pci_power_mgmt = 0; @@ -1902,6 +1902,58 @@ static void parse_config_data(const char *config_source, } } + if (!xlu_cfg_get_list(config, "vdrm", &vdrms, 0, 0)) { + d_config->num_vdrms = 0; + d_config->vdrms = NULL; + while ((buf = xlu_cfg_get_listitem(vdrms, d_config->num_vdrms)) != NULL) { + libxl_device_vdrm *vdrm; + libxl_string_list pairs; + char *path = NULL; + int len; + + vdrm = ARRAY_EXTEND_INIT(d_config->vdrms, d_config->num_vdrms, + libxl_device_vdrm_init); + + split_string_into_string_list(buf, ",", &pairs); + len = libxl_string_list_length(&pairs); + + for (i = 0; i < len; i++) { + char *key, *key_untrimmed, *value, *value_untrimmed; + int rc; + rc = split_string_into_pair(pairs[i], "=", + &key_untrimmed, + &value_untrimmed); + if (rc != 0) { + fprintf(stderr, "failed to parse vdrm configuration: %s", + pairs[i]); + exit(1); + } + trim(isspace, key_untrimmed, &key); + trim(isspace, value_untrimmed, &value); + + if (!strcmp(key, "backendid")) { + vdrm->backend_domid = atoi(value); + } else if (!strcmp(key, "backend")) { + replace_string(&vdrm->backend_domname, value); + } else if (!strcmp(key, "devid")) { + vdrm->devid = atoi(value); + } else if (!strcmp(key, "device")) { + replace_string(&vdrm->device, value); + } else if (!strcmp(key, "mode0")) { + replace_string(&vdrm->mode0, value); + } else if (!strcmp(key, "mode1")) { + replace_string(&vdrm->mode1, value); + } + free(key); + free(key_untrimmed); + free(value); + free(value_untrimmed); + } + libxl_string_list_dispose(&pairs); + free(path); + } + } + if (!xlu_cfg_get_list(config, "vtty", &vttys, 0, 0)) { d_config->num_vttys = 0; d_config->vttys = NULL; @@ -7084,6 +7136,116 @@ int main_vrtcdetach(int argc, char **argv) return rc; } +int main_vdrmattach(int argc, char **argv) +{ + + int opt; + uint32_t fe_domid; + libxl_device_vdrm vdrm; + /* XLU_Config *config = 0; */ + + SWITCH_FOREACH_OPT(opt, "", NULL, "vdrm-attach", 2) { + /* No options */ + } + + if (libxl_domain_qualifier_to_domid(ctx, argv[optind], &fe_domid) < 0) { + fprintf(stderr, "%s is an invalid domain identifier\n", argv[optind]); + return 1; + } + optind++; + + if (optind < argc) { + replace_string(&vdrm.device, argv[optind]); + } + optind++; + +/* TODO: fix this temporary hardcode */ + vdrm.backend_domname = "Domain-D"; + vdrm.backend_domid = 1; + + if (dryrun_only) { + char *json = libxl_device_vdrm_to_json(ctx, &vdrm); + printf("vdrm: %s\n", json); + free(json); + if (ferror(stdout) || fflush(stdout)) { perror("stdout"); exit(-1); } + return 0; + } + + if (libxl_device_vdrm_add(ctx, fe_domid, &vdrm, 0)) { + fprintf(stderr, "libxl_device_vdrm_add failed.\n"); + return 1; + } + + return 0; +} + +int main_vdrmlist(int argc, char **argv) +{ + int opt; + int i, nb; + libxl_device_vdrm *vdrms; + libxl_vdrminfo vdrminfo; + + SWITCH_FOREACH_OPT(opt, "", NULL, "vdrm-list", 1) { + /* No options */ + } + + /* vdrminfo.uuid should be outputted too */ + printf("%-5s %-3s %-6s %-5s %-6s %-8s %-40s %-40s\n", + "Vdev", "BE", "handle", "state", "evt-ch", "ring-ref", "BE-path", "FE-path"); + for (argv += optind, argc -= optind; argc > 0; --argc, ++argv) { + uint32_t domid; + if (libxl_domain_qualifier_to_domid(ctx, *argv, &domid) < 0) { + fprintf(stderr, "%s is an invalid domain identifier\n", *argv); + continue; + } + vdrms = libxl_device_vdrm_list(ctx, domid, &nb); + if (!vdrms) { + continue; + } + for (i=0; i<nb; i++) { + if (!libxl_device_vdrm_getinfo(ctx, domid, &vdrms[i], &vdrminfo)) { + /* Vdev BE hdl st evch rref BE-path FE-path UUID */ + printf("%-5d %-3d %-6d %-5d %-6d %-8d %-40s %-40s\n", + vdrminfo.devid, vdrminfo.backend_id, vdrminfo.frontend_id, + vdrminfo.state, vdrminfo.evtch, vdrminfo.rref, vdrminfo.backend, + vdrminfo.frontend); + libxl_vdrminfo_dispose(&vdrminfo); + } + libxl_device_vdrm_dispose(&vdrms[i]); + } + free(vdrms); + } + return 0; +} + +int main_vdrmdetach(int argc, char **argv) +{ + uint32_t domid, devid; + int opt, rc = 0; + libxl_device_vdrm vdrm; + + SWITCH_FOREACH_OPT(opt, "", NULL, "vdrm-detach", 2) { + /* No options */ + } + + domid = find_domain(argv[optind]); + devid = atoi(argv[optind+1]); + + if (libxl_devid_to_device_vdrm(ctx, domid, devid, &vdrm)) { + fprintf(stderr, "Error: Device %s not connected.\n", argv[optind+1]); + return 1; + } + + rc = libxl_device_vdrm_remove(ctx, domid, &vdrm, 0); + if (rc) { + fprintf(stderr, "libxl_device_vdrm_remove failed.\n"); + return 1; + } + + libxl_device_vdrm_dispose(&vdrm); + return rc; +} int main_vsndattach(int argc, char **argv) { diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c index bb410ca..daa07d7 100644 --- a/tools/libxl/xl_cmdtable.c +++ b/tools/libxl/xl_cmdtable.c @@ -366,6 +366,21 @@ struct cmd_spec cmd_table[] = { "Destroy a domain's virtual rtc device", "<Domain> <DevId>", }, + { "vdrm-attach", + &main_vdrmattach, 1, 1, + "Create a new virtual rtc device", + "<Domain> <Device>", + }, + { "vdrm-list", + &main_vdrmlist, 0, 0, + "List virtual rtc devices for a domain", + "<Domain(s)>", + }, + { "vdrm-detach", + &main_vdrmdetach, 0, 1, + "Destroy a domain's virtual rtc device", + "<Domain> <DevId>", + }, { "vsnd-attach", &main_vsndattach, 1, 1, "Create a new virtual audio device", -- 2.8.2 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |