[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC V2 5/5] domcreate: support pvusb in configuration file
Add code to support pvusb from domain create. One could specify usb in domain's configuration file and create domain, then usb device would be attached to guest automatically. One could specify usb device in config file like this: usb=['2-1.1'] Signed-off-by: Chunyan Liu <cyliu@xxxxxxxx> Signed-off-by: Simon Cao <caobosimon@xxxxxxxxx> --- tools/libxl/libxl_create.c | 41 ++++++++++++++++++++++++++++++++++++++--- tools/libxl/xl_cmdimpl.c | 40 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 6f87d1c..dc09c04 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -730,6 +730,8 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *aodevs, static void domcreate_attach_vtpms(libxl__egc *egc, libxl__multidev *multidev, int ret); +static void domcreate_attach_usbs(libxl__egc *egc, libxl__multidev *multidev, + int ret); static void domcreate_attach_pci(libxl__egc *egc, libxl__multidev *aodevs, int ret); @@ -1367,13 +1369,13 @@ static void domcreate_attach_vtpms(libxl__egc *egc, if (d_config->num_vtpms > 0) { /* Attach vtpms */ libxl__multidev_begin(ao, &dcs->multidev); - dcs->multidev.callback = domcreate_attach_pci; + dcs->multidev.callback = domcreate_attach_usbs; libxl__add_vtpms(egc, ao, domid, d_config, &dcs->multidev); libxl__multidev_prepared(egc, &dcs->multidev, 0); return; } - domcreate_attach_pci(egc, multidev, 0); + domcreate_attach_usbs(egc, multidev, 0); return; error_out: @@ -1381,6 +1383,39 @@ error_out: domcreate_complete(egc, dcs, ret); } +static void domcreate_attach_usbs(libxl__egc *egc, libxl__multidev *multidev, + int ret) +{ + libxl__domain_create_state *dcs = CONTAINER_OF(multidev, *dcs, multidev); + STATE_AO_GC(dcs->ao); + int i; + libxl_ctx *ctx = CTX; + int domid = dcs->guest_domid; + + libxl_domain_config *const d_config = dcs->guest_config; + + if (ret) { + LOG(ERROR, "unable to add vtpm devices"); + goto error_out; + } + + for (i = 0; i < d_config->num_usbs; i++) { + ret = libxl__device_usb_add(gc, domid, &d_config->usbs[i]); + if (ret < 0) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, + "libxl__device_usb_add failed: %d", ret); + goto error_out; + } + } + + domcreate_attach_pci(egc, multidev, 0); + return; + +error_out: + assert(ret); + domcreate_complete(egc, dcs, ret); +} + static void domcreate_attach_pci(libxl__egc *egc, libxl__multidev *multidev, int ret) { @@ -1394,7 +1429,7 @@ static void domcreate_attach_pci(libxl__egc *egc, libxl__multidev *multidev, libxl_domain_config *const d_config = dcs->guest_config; if (ret) { - LOG(ERROR, "unable to add vtpm devices"); + LOG(ERROR, "unable to add usb devices"); goto error_out; } diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index a28f460..d97f382 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -985,7 +985,7 @@ static void parse_config_data(const char *config_source, const char *buf; long l; XLU_Config *config; - XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms; + XLU_ConfigList *cpus, *vbds, *nics, *pcis, *usbs, *cvfbs, *cpuids, *vtpms; XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian; int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian; int pci_power_mgmt = 0; @@ -1745,6 +1745,44 @@ skip_vfb: libxl_defbool_set(&b_info->u.pv.e820_host, true); } + if (!xlu_cfg_get_list (config, "usb", &usbs, 0, 0) ) { + d_config->num_usbs = 0; + d_config->usbs = NULL; + while ((buf = xlu_cfg_get_listitem (usbs, d_config->num_usbs)) != NULL) { + libxl_device_usb *usb; + char *buf2 = strdup(buf); + char *p, *p2; + + d_config->usbs = (libxl_device_usb *) realloc(d_config->usbs, + sizeof (libxl_device_usb) * (d_config->num_usbs+1)); + usb = d_config->usbs + d_config->num_usbs; + libxl_device_usb_init(usb); + + p = strtok(buf2, ","); + if(p) { + usb->port = -1; + usb->ctrl = -1; + do { + while(*p == ' ') + ++p; + if ((p2 = strchr(p, '=')) == NULL) + break; + *p2 = '\0'; + if (!strcmp(p, "type")) { + //Set type in libxl_device_usb + } else if (!strcmp(p, "interface") ){ + usb->intf = strdup(p2 + 1); + } else { + fprintf(stderr, "Unknown string `%s' in usb spec\n", p); + exit(1); + } + } while ((p = strtok(NULL, ",")) != NULL); + } + free(buf2); + d_config->num_usbs++; + } + } + switch (xlu_cfg_get_list(config, "cpuid", &cpuids, 0, 1)) { case 0: { -- 1.8.4.5 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |