From patchwork Wed Apr 13 09:15:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Olaf Hering X-Patchwork-Id: 8819871 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 474769F36E for ; Wed, 13 Apr 2016 09:18:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0DBB1201F5 for ; Wed, 13 Apr 2016 09:18:23 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B208D201B9 for ; Wed, 13 Apr 2016 09:18:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aqGuS-0006TN-3a; Wed, 13 Apr 2016 09:16:28 +0000 Received: from mail6.bemta6.messagelabs.com ([85.158.143.247]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1aqGuQ-0006Sa-UB for xen-devel@lists.xen.org; Wed, 13 Apr 2016 09:16:27 +0000 Received: from [85.158.143.35] by server-3.bemta-6.messagelabs.com id 33/16-07120-A6E0E075; Wed, 13 Apr 2016 09:16:26 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOIsWRWlGSWpSXmKPExsUSuHLSQt1MPr5 wgxttMhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8bC3T8YCzoyKo6/nsXawHjYq4uRi4NFYAmz RE/vNsYuRk4OCQFPiY9XDrB0MXIA2SIST/6ngdQICTxkkli08S4rSFxIIF3i4b0KkHI2ASWJv QePg7WKCJhIvPp5kB3EZhZwkHjWs4IJxBYGik+8uYoVxGYRUJX4OxViPK+AncTtg1IQW+UkLk 9/wAZicwrYS8xc+Y8FxBYSKJL48OMQM4jNKyAocXLmExaI8fISzVtnM09gFJiFJDULSWoBI9M qRvXi1KKy1CJdY72kosz0jJLcxMwcXUMDM73c1OLixPTUnMSkYr3k/NxNjMAAZACCHYwd/5wO MUpyMCmJ8k75xRsuxJeUn1KZkVicEV9UmpNafIhRhoNDSYL3Pw9fuJBgUWp6akVaZg4wFmDSE hw8SiK8UrxAad7igsTc4sx0iNQpRkUpcV4LkIQASCKjNA+uDRZ/lxhlpYR5GYEOEeIpSC3KzS xBlX/FKM7BqCTMKwMyhSczrwRu+iugxUxAi8ve8YIsLklESEk1MM66mX82Vy3S1CjqcLErW77 U9b7Ffj9Fmb5GKt28GLzdyKhlynLDY2aPtzRnq2+VjDW6Fq209UU+Z8uJWREMf90n/I9brjbV q/mI/JJghfKAR3fWB2y7/CDup4bmkzc7phpu2FIRLful5sfBxX/lmL8vurPN3ezKl5ALC/x/N xw9feCy3qZVsuFKLMUZiYZazEXFiQCZ5um8ugIAAA== X-Env-Sender: olaf@aepfle.de X-Msg-Ref: server-11.tower-21.messagelabs.com!1460538985!9038099!1 X-Originating-IP: [81.169.146.161] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: QmFkIElQOiA4MS4xNjkuMTQ2LjE2MSA9PiA1ODk3MjY=\n,sa_preprocessor: QmFkIElQOiA4MS4xNjkuMTQ2LjE2MSA9PiA1ODk3MjY=\n X-StarScan-Received: X-StarScan-Version: 8.28; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32959 invoked from network); 13 Apr 2016 09:16:25 -0000 Received: from mo4-p00-ob.smtp.rzone.de (HELO mo4-p00-ob.smtp.rzone.de) (81.169.146.161) by server-11.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 13 Apr 2016 09:16:25 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1460538985; l=11050; s=domk; d=aepfle.de; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Date: Subject:Cc:To:From; bh=sxXkXes6BliaWEU6MGtiUEZhDV8iBi7Vl8+bm23MY8w=; b=BWbXwHuUm+/iPTjMjtrvEUWtd2HdjFGqYkyihPbEl6lsNQiWOEBZtLByqExvKL8EfoN ndoxo1b4vV1DZpmh3py/2q5xn8O4aOBNVJhA1jQUTIiocwLIbYV0ZlC3nmdHhDJlC0yPS Tl9jGpBSA+Pcl0MW5pbNIcbqN2fQ7YN7emE= X-RZG-AUTH: :P2EQZWCpfu+qG7CngxMFH1J+yackYocTD1iAi8x+OWtqWFmrC5F/k8z93bGG X-RZG-CLASS-ID: mo00 Received: from probook (aftr-185-17-206-53.dynamic.mnet-online.de [185.17.206.53]) by smtp.strato.de (RZmta 37.23 DYNA|AUTH) with ESMTPSA id 006b1es3D9GE7Al (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Wed, 13 Apr 2016 11:16:14 +0200 (CEST) Received: by probook (Postfix, from userid 1000) id 6FC8A5093F; Wed, 13 Apr 2016 11:16:14 +0200 (CEST) From: Olaf Hering To: libvir-list@redhat.com, xen-devel@lists.xen.org Date: Wed, 13 Apr 2016 09:15:59 +0000 Message-Id: <1460538959-23584-3-git-send-email-olaf@aepfle.de> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1460538959-23584-1-git-send-email-olaf@aepfle.de> References: <1460537820-15398-1-git-send-email-olaf@aepfle.de> <1460538959-23584-1-git-send-email-olaf@aepfle.de> MIME-Version: 1.0 Cc: Olaf Hering , Jim Fehlig Subject: [Xen-devel] [PATCH libvirt v2 2/2] libxl: support vscsi X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID, 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 This uses the API version of the proposed vscsi support in libxl (v12): http://lists.xenproject.org/archives/html/xen-devel/2016-04/msg01772.html Is there anything else that needs to be done in libvirt? Right now libvirt scsi support is very simple minded, no support at all to describe host devices with persistant names. Example used during testing:
Signed-off-by: Olaf Hering Cc: Jim Fehlig --- src/libxl/libxl_conf.c | 59 +++++++++++++++ src/libxl/libxl_conf.h | 1 + src/libxl/libxl_domain.c | 2 +- src/libxl/libxl_driver.c | 187 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 248 insertions(+), 1 deletion(-) diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index f5ef50f..1e3615e 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -1915,6 +1915,61 @@ libxlMakePCIList(virDomainDefPtr def, libxl_domain_config *d_config) } static int +libxlMakeVscsiList(libxl_ctx *ctx, + XLU_Config *xlu, + virDomainDefPtr def, + libxl_domain_config *d_config) +{ + virDomainHostdevDefPtr *l_hostdevs = def->hostdevs; + size_t i, nhostdevs = def->nhostdevs; + virDomainHostdevDefPtr hostdev; + virDomainHostdevSubsysSCSIPtr scsisrc; + char *str; + int rc = 0; + + if (nhostdevs == 0) + return 0; + + for (i = 0; i < nhostdevs; i++) { + hostdev = l_hostdevs[i]; + if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) + continue; + if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) + continue; + scsisrc = &hostdev->source.subsys.u.scsi; + if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) + continue; +#if defined(LIBXL_HAVE_VSCSI) + if (virAsprintf(&str, "%s:%u:%u:%u,%u:%u:%u:%llu%s", + scsisrc->u.host.adapter + strlen("scsi_host"), + scsisrc->u.host.bus, + scsisrc->u.host.target, + scsisrc->u.host.unit, + hostdev->info->addr.drive.controller, + hostdev->info->addr.drive.bus, + hostdev->info->addr.drive.target, + hostdev->info->addr.drive.unit, + scsisrc->rawio == VIR_TRISTATE_BOOL_YES ? ",feature-host" : "") < 0) { + goto error; + }; + rc = xlu_vscsi_config_add(xlu, ctx, str, &d_config->num_vscsictrls, &d_config->vscsictrls); + VIR_FREE(str); + if (rc) + goto error; +#else + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("This version of libxenlight does not support vscsi")); + goto error; +#endif + } + + return 0; + + error: + return -1; +} + +static int libxlMakeVideo(virDomainDefPtr def, libxl_domain_config *d_config) { @@ -2059,6 +2114,7 @@ int libxlBuildDomainConfig(virPortAllocatorPtr graphicsports, virDomainDefPtr def, libxl_ctx *ctx, + XLU_Config *xlu, libxl_domain_config *d_config) { libxl_domain_config_init(d_config); @@ -2084,6 +2140,9 @@ libxlBuildDomainConfig(virPortAllocatorPtr graphicsports, if (libxlMakePCIList(def, d_config) < 0) return -1; + if (libxlMakeVscsiList(ctx, xlu, def, d_config) < 0) + return -1; + /* * Now that any potential VFBs are defined, update the build info with * the data of the primary display. Some day libxl might implicitely do diff --git a/src/libxl/libxl_conf.h b/src/libxl/libxl_conf.h index b069e45..422c1d6 100644 --- a/src/libxl/libxl_conf.h +++ b/src/libxl/libxl_conf.h @@ -218,6 +218,7 @@ int libxlBuildDomainConfig(virPortAllocatorPtr graphicsports, virDomainDefPtr def, libxl_ctx *ctx, + XLU_Config *xlu, libxl_domain_config *d_config); static inline void diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c index aed904b..02379c9 100644 --- a/src/libxl/libxl_domain.c +++ b/src/libxl/libxl_domain.c @@ -1051,7 +1051,7 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, VIR_FREE(priv->lockState); if (libxlBuildDomainConfig(driver->reservedGraphicsPorts, vm->def, - cfg->ctx, &d_config) < 0) + cfg->ctx, cfg->xlu, &d_config) < 0) goto cleanup_dom; if (cfg->autoballoon && libxlDomainFreeMem(cfg->ctx, &d_config) < 0) diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index bf97c9c..186f9d4 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -3024,6 +3024,117 @@ libxlDomainAttachHostPCIDevice(libxlDriverPrivatePtr driver, } static int +libxlDomainAttachHostSCSIDevice(libxlDriverPrivatePtr driver, + virDomainObjPtr vm, + virDomainHostdevDefPtr hostdev) +{ +#if defined(LIBXL_HAVE_VSCSI) + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); + libxl_device_vscsictrl ctrl, existing; + libxl_device_vscsidev dev; + bool found_existing; + virDomainHostdevDefPtr found; + virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr; + virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi; + char *str = NULL; + int ret = -1; + + if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) + return -1; + + libxl_device_vscsictrl_init(&existing); + libxl_device_vscsictrl_init(&ctrl); + libxl_device_vscsidev_init(&dev); + + if (virDomainHostdevFind(vm->def, hostdev, &found) >= 0) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("target scsi device %u:%u:%u:%llu already exists"), + hostdev->info->addr.drive.controller, + hostdev->info->addr.drive.bus, + hostdev->info->addr.drive.target, + hostdev->info->addr.drive.unit); + goto cleanup; + } + + if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0) + goto cleanup; + + if (virHostdevPrepareSCSIDevices(hostdev_mgr, LIBXL_DRIVER_NAME, + vm->def->name, &hostdev, 1) < 0) + goto cleanup; + + if (virAsprintf(&str, "%s:%u:%u:%u,%u:%u:%u:%llu%s", + scsisrc->u.host.adapter + strlen("scsi_host"), + scsisrc->u.host.bus, + scsisrc->u.host.target, + scsisrc->u.host.unit, + hostdev->info->addr.drive.controller, + hostdev->info->addr.drive.bus, + hostdev->info->addr.drive.target, + hostdev->info->addr.drive.unit, + scsisrc->rawio == VIR_TRISTATE_BOOL_YES ? + ",feature-host" : "") < 0) { + goto error; + }; + + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", str); + + if (xlu_vscsi_get_ctrl(cfg->xlu, cfg->ctx, vm->def->id, str, &ctrl, &dev, &existing, &found_existing) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("libxutil failed to parse scsi device %u:%u:%u:%llu"), + hostdev->info->addr.drive.controller, + hostdev->info->addr.drive.bus, + hostdev->info->addr.drive.target, + hostdev->info->addr.drive.unit); + } + + /* Finally add the device */ + if (found_existing) { + if (libxl_device_vscsidev_add(cfg->ctx, vm->def->id, &dev, NULL)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("libxenlight failed to attach scsi device %u:%u:%u:%llu"), + hostdev->info->addr.drive.controller, + hostdev->info->addr.drive.bus, + hostdev->info->addr.drive.target, + hostdev->info->addr.drive.unit); + goto error; + } + } else { + libxl_device_vscsictrl_append_vscsidev(cfg->ctx, &ctrl, &dev); + if (libxl_device_vscsictrl_add(cfg->ctx, vm->def->id, &ctrl, NULL)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("libxenlight failed to attach scsi device %u:%u:%u:%llu"), + hostdev->info->addr.drive.controller, + hostdev->info->addr.drive.bus, + hostdev->info->addr.drive.target, + hostdev->info->addr.drive.unit); + goto error; + } + } + + vm->def->hostdevs[vm->def->nhostdevs++] = hostdev; + ret = 0; + goto cleanup; + + error: + virHostdevReAttachSCSIDevices(hostdev_mgr, LIBXL_DRIVER_NAME, + vm->def->name, &hostdev, 1); + + cleanup: + VIR_FREE(str); + virObjectUnref(cfg); + libxl_device_vscsictrl_dispose(&existing); + libxl_device_vscsictrl_dispose(&ctrl); + libxl_device_vscsidev_dispose(&dev); + return ret; +#else + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("This version of libxenlight does not support vscsi")); + return -1; +#endif +} + +static int libxlDomainAttachHostDevice(libxlDriverPrivatePtr driver, virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) @@ -3041,6 +3152,11 @@ libxlDomainAttachHostDevice(libxlDriverPrivatePtr driver, return -1; break; + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: + if (libxlDomainAttachHostSCSIDevice(driver, vm, hostdev) < 0) + return -1; + break; + default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("hostdev subsys type '%s' not supported"), @@ -3385,6 +3501,74 @@ libxlDomainDetachHostPCIDevice(libxlDriverPrivatePtr driver, } static int +libxlDomainDetachHostSCSIDevice(libxlDriverPrivatePtr driver, + virDomainObjPtr vm, + virDomainHostdevDefPtr hostdev) +{ +#if defined(LIBXL_HAVE_VSCSI) + libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver); + virDomainHostdevDefPtr detach; + int idx; + virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr; + virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi; + int ret = -1; + char *str = NULL; + + if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) + return -1; + + idx = virDomainHostdevFind(vm->def, hostdev, &detach); + if (idx < 0) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("target scsi device %u:%u:%u:%u not found"), + hostdev->info->addr.drive.controller, + hostdev->info->addr.drive.bus, + hostdev->info->addr.drive.target, + hostdev->info->addr.drive.unit); + goto cleanup; + } + + if (virAsprintf(&str, "%u:%u:%u:%u", + hostdev->info->addr.drive.controller, + hostdev->info->addr.drive.bus, + hostdev->info->addr.drive.target, + hostdev->info->addr.drive.unit) < 0) { + goto error; + }; + + if (xlu_vscsi_detach(cfg->xlu, cfg->ctx, vm->def->id, str) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("libxenlight failed to detach pci device %u:%u:%u:%u"), + hostdev->info->addr.drive.controller, + hostdev->info->addr.drive.bus, + hostdev->info->addr.drive.target, + hostdev->info->addr.drive.unit); + goto error; + } + + + virDomainHostdevRemove(vm->def, idx); + + virHostdevReAttachPCIDevices(hostdev_mgr, LIBXL_DRIVER_NAME, + vm->def->name, &hostdev, 1, NULL); + + ret = 0; + + error: + VIR_FREE(str); + virDomainHostdevDefFree(detach); + + cleanup: + virObjectUnref(cfg); + return ret; +#else + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("This version of libxenlight does not support vscsi")); + return -1; +#endif +} + +static int libxlDomainDetachHostDevice(libxlDriverPrivatePtr driver, virDomainObjPtr vm, virDomainHostdevDefPtr hostdev) @@ -3402,6 +3586,9 @@ libxlDomainDetachHostDevice(libxlDriverPrivatePtr driver, case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI: return libxlDomainDetachHostPCIDevice(driver, vm, hostdev); + case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI: + return libxlDomainDetachHostSCSIDevice(driver, vm, hostdev); + default: virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected hostdev type %d"), subsys->type);