From patchwork Wed Dec 23 02:24:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chunyan Liu X-Patchwork-Id: 7908601 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5AAD39F32E for ; Wed, 23 Dec 2015 02:28:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 244AC20425 for ; Wed, 23 Dec 2015 02:28:08 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D47442041C for ; Wed, 23 Dec 2015 02:28:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aBZ7D-0001kV-GD; Wed, 23 Dec 2015 02:25:23 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aBZ7B-0001ix-8V for xen-devel@lists.xen.org; Wed, 23 Dec 2015 02:25:21 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id 4B/65-03235-0160A765; Wed, 23 Dec 2015 02:25:20 +0000 X-Env-Sender: cyliu@suse.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1450837517!12047704!1 X-Originating-IP: [137.65.250.26] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 24706 invoked from network); 23 Dec 2015 02:25:19 -0000 Received: from prv3-mh.provo.novell.com (HELO prv3-mh.provo.novell.com) (137.65.250.26) by server-6.tower-206.messagelabs.com with DHE-RSA-AES256-SHA encrypted SMTP; 23 Dec 2015 02:25:19 -0000 Received: from linux-3hvf.site (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (TLS encrypted); Tue, 22 Dec 2015 19:25:10 -0700 From: Chunyan Liu To: xen-devel@lists.xen.org Date: Wed, 23 Dec 2015 10:24:42 +0800 Message-Id: <1450837482-5074-6-git-send-email-cyliu@suse.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1450837482-5074-1-git-send-email-cyliu@suse.com> References: <1450837482-5074-1-git-send-email-cyliu@suse.com> Cc: jgross@suse.com, wei.liu2@citrix.com, ian.campbell@citrix.com, george.dunlap@eu.citrix.com, Ian.Jackson@eu.citrix.com, Chunyan Liu , jfehlig@suse.com, Simon Cao Subject: [Xen-devel] [PATCH V12 5/5] domcreate: support pvusb in configuration file X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add code to support pvusb in domain config file. One could specify usbctrl and usb in domain's configuration file and create domain, then usb controllers will be created and usb device would be attached to guest automatically. One could specify usb controllers and usb devices in config file like this: usbctrl=['version=2,ports=4', 'version=1, ports=4', ] usbdev=['hostbus=2, hostaddr=1, controller=0,port=1', ] Signed-off-by: Chunyan Liu Signed-off-by: Simon Cao Reviewed-by: George Dunlap --- docs/man/xl.cfg.pod.5 | 84 ++++++++++++++++++++++++++++++++++++++++++++ tools/libxl/libxl_create.c | 73 ++++++++++++++++++++++++++++++++++++-- tools/libxl/libxl_device.c | 4 +++ tools/libxl/libxl_internal.h | 8 +++++ tools/libxl/xl_cmdimpl.c | 55 ++++++++++++++++++++++++++++- 5 files changed, 220 insertions(+), 4 deletions(-) diff --git a/docs/man/xl.cfg.pod.5 b/docs/man/xl.cfg.pod.5 index 8899f75..99ef9ca 100644 --- a/docs/man/xl.cfg.pod.5 +++ b/docs/man/xl.cfg.pod.5 @@ -722,6 +722,90 @@ Note this may be overridden by rdm_policy option in PCI device configuration. =back +=item B + +Specifies the USB controllers created for this guest. Each +B has the form C where: + +=over 4 + +=item B + +Possible Bs are: + +=over 4 + +=item B + +Specifies the usb controller type. Currently only 'pv' and 'auto' +are supported. + +=item B + +Specifies the usb controller version. Possible values include +1 (USB1.1) and 2 (USB2.0). Default is 2 (USB2.0). + +=item B + +Specifies the total ports of the usb controller. The maximum +number is 31. Default is 8. + +USB controler ids start from 0. In line with the USB spec, however, +ports on a controller start from 1. + +E.g. +usbctrl=["version=1,ports=4", "version=2,ports=8",] +The first controller has: +controller id = 0, and port 1,2,3,4. +The second controller has: +controller id = 1, and port 1,2,3,4,5,6,7,8. + +=back + +=back + +=item B + +Specifies the USB devices to be attached to the guest at boot. Each +B has the form C where: + +=over 4 + +=item B + +Possible Bs are: + +=over 4 + +=item B + +Specifies USB device type. Currently only support 'hostdev'. + +=item B + +Specifies busnum of the USB device from the host perspective. + +=item B + +Specifies devnum of the USB device from the host perspective. + +=item B + +Specifies USB controller id, to which controller the USB device is attached. + +=item B + +Specifies USB port, to which port the USB device is attached. B +is valid only when B is specified. + +=back + +If no controller is specified, an available controller:port combination +will be used. If there are no available controller:port options, +a new controller will be created. + +=back + =item B Specifies the host PCI devices to passthrough to this guest. Each B diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 261816a..7c87c34 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -733,6 +733,10 @@ 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_usbctrls(libxl__egc *egc, + libxl__multidev *multidev, int ret); +static void domcreate_attach_usbdevs(libxl__egc *egc, libxl__multidev *multidev, + int ret); static void domcreate_attach_pci(libxl__egc *egc, libxl__multidev *aodevs, int ret); static void domcreate_attach_dtdev(libxl__egc *egc, @@ -1398,13 +1402,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_usbctrls; 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_usbctrls(egc, multidev, 0); return; error_out: @@ -1412,6 +1416,69 @@ error_out: domcreate_complete(egc, dcs, ret); } +static void domcreate_attach_usbctrls(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 vtpm devices"); + goto error_out; + } + + if (d_config->num_usbctrls > 0) { + /* Attach usbctrls */ + libxl__multidev_begin(ao, &dcs->multidev); + dcs->multidev.callback = domcreate_attach_usbdevs; + libxl__add_usbctrls(egc, ao, domid, d_config, &dcs->multidev); + libxl__multidev_prepared(egc, &dcs->multidev, 0); + return; + } + + domcreate_attach_usbdevs(egc, multidev, 0); + return; + +error_out: + assert(ret); + domcreate_complete(egc, dcs, ret); +} + + +static void domcreate_attach_usbdevs(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 usbctrl devices"); + goto error_out; + } + + if (d_config->num_usbdevs > 0) { + /* Attach usbctrls */ + libxl__multidev_begin(ao, &dcs->multidev); + dcs->multidev.callback = domcreate_attach_pci; + libxl__add_usbdevs(egc, ao, domid, d_config, &dcs->multidev); + libxl__multidev_prepared(egc, &dcs->multidev, 0); + return; + } + + 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) { @@ -1424,7 +1491,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/libxl_device.c b/tools/libxl/libxl_device.c index b7a6a13..4ced9b6 100644 --- a/tools/libxl/libxl_device.c +++ b/tools/libxl/libxl_device.c @@ -544,6 +544,8 @@ void libxl__multidev_prepared(libxl__egc *egc, * libxl__add_disks * libxl__add_nics * libxl__add_vtpms + * libxl__add_usbctrls + * libxl__add_usbs */ #define DEFINE_DEVICES_ADD(type) \ @@ -563,6 +565,8 @@ void libxl__multidev_prepared(libxl__egc *egc, DEFINE_DEVICES_ADD(disk) DEFINE_DEVICES_ADD(nic) DEFINE_DEVICES_ADD(vtpm) +DEFINE_DEVICES_ADD(usbctrl) +DEFINE_DEVICES_ADD(usbdev) #undef DEFINE_DEVICES_ADD diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 0ccad9a..64925b1 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -3319,6 +3319,14 @@ _hidden void libxl__add_vtpms(libxl__egc *egc, libxl__ao *ao, uint32_t domid, libxl_domain_config *d_config, libxl__multidev *multidev); +_hidden void libxl__add_usbctrls(libxl__egc *egc, libxl__ao *ao, + uint32_t domid, libxl_domain_config *d_config, + libxl__multidev *multidev); + +_hidden void libxl__add_usbdevs(libxl__egc *egc, libxl__ao *ao, + uint32_t domid, libxl_domain_config *d_config, + libxl__multidev *multidev); + /*----- device model creation -----*/ /* First layer; wraps libxl__spawn_spawn. */ diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c index b84ec98d..ab76367 100644 --- a/tools/libxl/xl_cmdimpl.c +++ b/tools/libxl/xl_cmdimpl.c @@ -1315,7 +1315,8 @@ static void parse_config_data(const char *config_source, const char *buf; long l, vcpus = 0; XLU_Config *config; - XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms; + XLU_ConfigList *cpus, *vbds, *nics, *pcis, *cvfbs, *cpuids, *vtpms, + *usbctrls, *usbdevs; XLU_ConfigList *channels, *ioports, *irqs, *iomem, *viridian, *dtdevs; int num_ioports, num_irqs, num_iomem, num_cpus, num_viridian; int pci_power_mgmt = 0; @@ -2132,6 +2133,58 @@ skip_vfb: } } + if (!xlu_cfg_get_list(config, "usbctrl", &usbctrls, 0, 0)) { + d_config->num_usbctrls = 0; + d_config->usbctrls = NULL; + while ((buf = xlu_cfg_get_listitem(usbctrls, d_config->num_usbctrls)) + != NULL) { + libxl_device_usbctrl *usbctrl; + char *buf2 = strdup(buf); + char *p; + + usbctrl = ARRAY_EXTEND_INIT(d_config->usbctrls, + d_config->num_usbctrls, + libxl_device_usbctrl_init); + p = strtok(buf2, ","); + if (!p) + goto skip_usbctrl; + do { + while (*p == ' ') + p++; + if (parse_usbctrl_config(usbctrl, p)) + exit(1); + } while ((p = strtok(NULL, ",")) != NULL); +skip_usbctrl: + free(buf2); + } + } + + if (!xlu_cfg_get_list(config, "usbdev", &usbdevs, 0, 0)) { + d_config->num_usbdevs = 0; + d_config->usbdevs = NULL; + while ((buf = xlu_cfg_get_listitem(usbdevs, d_config->num_usbdevs)) + != NULL) { + libxl_device_usbdev *usbdev; + char *buf2 = strdup(buf); + char *p; + + usbdev = ARRAY_EXTEND_INIT_NODEVID(d_config->usbdevs, + d_config->num_usbdevs, + libxl_device_usbdev_init); + p = strtok(buf2, ","); + if (!p) + goto skip_usbdev; + do { + while (*p == ' ') + p++; + if (parse_usbdev_config(usbdev, p)) + exit(1); + } while ((p = strtok(NULL, ",")) != NULL); +skip_usbdev: + free(buf2); + } + } + switch (xlu_cfg_get_list(config, "cpuid", &cpuids, 0, 1)) { case 0: {