From patchwork Tue Feb 16 21:45:58 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Fehlig X-Patchwork-Id: 8332591 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 182D49F6E7 for ; Tue, 16 Feb 2016 21:48:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DD1A8202E5 for ; Tue, 16 Feb 2016 21:48:36 +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 8C04C202BE for ; Tue, 16 Feb 2016 21:48:35 +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 1aVnRJ-0001fg-MH; Tue, 16 Feb 2016 21:45:45 +0000 Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aVnRI-0001f0-5L for xen-devel@lists.xen.org; Tue, 16 Feb 2016 21:45:44 +0000 Received: from [193.109.254.147] by server-11.bemta-14.messagelabs.com id 98/E1-28228-78893C65; Tue, 16 Feb 2016 21:45:43 +0000 X-Env-Sender: jfehlig@suse.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1455659140!24349544!1 X-Originating-IP: [137.65.250.81] 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 3898 invoked from network); 16 Feb 2016 21:45:42 -0000 Received: from smtp2.provo.novell.com (HELO smtp2.provo.novell.com) (137.65.250.81) by server-7.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 16 Feb 2016 21:45:42 -0000 Received: from jfehlig2.provo.novell.com (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (NOT encrypted); Tue, 16 Feb 2016 14:45:39 -0700 From: Jim Fehlig To: libvir-list@redhat.com Date: Tue, 16 Feb 2016 14:45:58 -0700 Message-Id: <1455659159-11931-4-git-send-email-jfehlig@suse.com> X-Mailer: git-send-email 2.6.1 In-Reply-To: <1455659159-11931-1-git-send-email-jfehlig@suse.com> References: <1455659159-11931-1-git-send-email-jfehlig@suse.com> Cc: Jim Fehlig , xen-devel@lists.xen.org Subject: [Xen-devel] [PATCH 3/4] xenconfig: support xl<->xml conversion of rbd disk devices 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 The target= setting in xl disk configuration can be used to encode meta info that is meaningful to a backend. Leverage this fact to support qdisk network disk types such as rbd. E.g. xl disk config containing disk = [ "format=raw,vdev=hdb,access=rw,backendtype=qdisk, target=rbd:pool/image:auth_supported=none:\ mon_host=mon1.example.org\:6321\;mon2.example.org\:6322\;\ mon3.example.org\:6322" ] can be converted to the following XML (and vice versa)
Note that conversion of config is not handled in this patch, but can be done in a follow-up patch. Also add a test for the conversions. Signed-off-by: Jim Fehlig --- src/xenconfig/xen_xl.c | 145 +++++++++++++++++++++-- tests/xlconfigdata/test-rbd-multihost-noauth.cfg | 26 ++++ tests/xlconfigdata/test-rbd-multihost-noauth.xml | 51 ++++++++ tests/xlconfigtest.c | 1 + 4 files changed, 216 insertions(+), 7 deletions(-) diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index f3e8b55..fadfe71 100644 --- a/src/xenconfig/xen_xl.c +++ b/src/xenconfig/xen_xl.c @@ -246,6 +246,24 @@ xenParseXLSpice(virConfPtr conf, virDomainDefPtr def) return -1; } + +static int +xenParseXLDiskSrc(virDomainDiskDefPtr disk, char *srcstr) +{ + if (STRPREFIX(srcstr, "rbd:")) { + virDomainDiskSetType(disk, VIR_STORAGE_TYPE_NETWORK); + disk->src->protocol = VIR_STORAGE_NET_PROTOCOL_RBD; + return virStorageSourceParseRBDColonString(srcstr + strlen("rbd:"), + disk->src); + } else { + if (virDomainDiskSetSource(disk, srcstr) < 0) + return -1; + } + + return 0; +} + + /* * For details on xl disk config syntax, see * docs/misc/xl-disk-configuration.txt in the Xen sources. The important @@ -311,12 +329,12 @@ xenParseXLDisk(virConfPtr conf, virDomainDefPtr def) if (!(disk = virDomainDiskDefNew(NULL))) goto fail; + if (xenParseXLDiskSrc(disk, libxldisk->pdev_path) < 0) + goto fail; + if (VIR_STRDUP(disk->dst, libxldisk->vdev) < 0) goto fail; - if (virDomainDiskSetSource(disk, libxldisk->pdev_path) < 0) - goto fail; - disk->src->readonly = !libxldisk->readwrite; disk->removable = libxldisk->removable; @@ -358,7 +376,8 @@ xenParseXLDisk(virConfPtr conf, virDomainDefPtr def) case LIBXL_DISK_BACKEND_UNKNOWN: if (virDomainDiskSetDriver(disk, "qemu") < 0) goto fail; - virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); + if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_NONE) + virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); break; case LIBXL_DISK_BACKEND_TAP: @@ -578,14 +597,115 @@ xenFormatXLOS(virConfPtr conf, virDomainDefPtr def) } +static char * +xenFormatXLDiskSrcNet(virStorageSourcePtr src) +{ + char *ret = NULL; + virBuffer buf = VIR_BUFFER_INITIALIZER; + size_t i; + + switch ((virStorageNetProtocol) src->protocol) { + case VIR_STORAGE_NET_PROTOCOL_NBD: + case VIR_STORAGE_NET_PROTOCOL_HTTP: + case VIR_STORAGE_NET_PROTOCOL_HTTPS: + case VIR_STORAGE_NET_PROTOCOL_FTP: + case VIR_STORAGE_NET_PROTOCOL_FTPS: + case VIR_STORAGE_NET_PROTOCOL_TFTP: + case VIR_STORAGE_NET_PROTOCOL_ISCSI: + case VIR_STORAGE_NET_PROTOCOL_GLUSTER: + case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG: + case VIR_STORAGE_NET_PROTOCOL_LAST: + case VIR_STORAGE_NET_PROTOCOL_NONE: + virReportError(VIR_ERR_NO_SUPPORT, + _("Unsupported network block protocol '%s'"), + virStorageNetProtocolTypeToString(src->protocol)); + goto cleanup; + + case VIR_STORAGE_NET_PROTOCOL_RBD: + if (strchr(src->path, ':')) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("':' not allowed in RBD source volume name '%s'"), + src->path); + goto cleanup; + } + + virBufferStrcat(&buf, "rbd:", src->path, NULL); + + virBufferAddLit(&buf, ":auth_supported=none"); + + if (src->nhosts > 0) { + virBufferAddLit(&buf, ":mon_host="); + for (i = 0; i < src->nhosts; i++) { + if (i) + virBufferAddLit(&buf, "\\;"); + + /* assume host containing : is ipv6 */ + if (strchr(src->hosts[i].name, ':')) + virBufferEscape(&buf, '\\', ":", "[%s]", + src->hosts[i].name); + else + virBufferAsprintf(&buf, "%s", src->hosts[i].name); + + if (src->hosts[i].port) + virBufferAsprintf(&buf, "\\:%s", src->hosts[i].port); + } + } + + if (virBufferCheckError(&buf) < 0) + goto cleanup; + + ret = virBufferContentAndReset(&buf); + break; + } + + cleanup: + virBufferFreeAndReset(&buf); + + return ret; +} + + +static int +xenFormatXLDiskSrc(virStorageSourcePtr src, char **srcstr) +{ + int actualType = virStorageSourceGetActualType(src); + + *srcstr = NULL; + + if (virStorageSourceIsEmpty(src)) + return 0; + + switch ((virStorageType) actualType) { + case VIR_STORAGE_TYPE_BLOCK: + case VIR_STORAGE_TYPE_FILE: + case VIR_STORAGE_TYPE_DIR: + if (VIR_STRDUP(*srcstr, src->path) < 0) + return -1; + break; + + case VIR_STORAGE_TYPE_NETWORK: + if (!(*srcstr = xenFormatXLDiskSrcNet(src))) + return -1; + break; + + case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NONE: + case VIR_STORAGE_TYPE_LAST: + break; + } + + return 0; +} + + static int xenFormatXLDisk(virConfValuePtr list, virDomainDiskDefPtr disk) { virBuffer buf = VIR_BUFFER_INITIALIZER; virConfValuePtr val, tmp; - const char *src = virDomainDiskGetSource(disk); int format = virDomainDiskGetFormat(disk); const char *driver = virDomainDiskGetDriver(disk); + char *target = NULL; /* format */ virBufferAddLit(&buf, "format="); @@ -637,8 +757,18 @@ xenFormatXLDisk(virConfValuePtr list, virDomainDiskDefPtr disk) if (disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) virBufferAddLit(&buf, "devtype=cdrom,"); - /* target */ - virBufferAsprintf(&buf, "target=%s", src); + /* + * target + * From $xensrc/docs/misc/xl-disk-configuration.txt: + * When this parameter is specified by name, ie with the "target=" + * syntax in the configuration file, it consumes the whole rest of the + * including trailing whitespaces. Therefore in that case + * it must come last. + */ + if (xenFormatXLDiskSrc(disk->src, &target) < 0) + goto cleanup; + + virBufferAsprintf(&buf, "target=%s", target); if (virBufferCheckError(&buf) < 0) goto cleanup; @@ -658,6 +788,7 @@ xenFormatXLDisk(virConfValuePtr list, virDomainDiskDefPtr disk) return 0; cleanup: + VIR_FREE(target); virBufferFreeAndReset(&buf); return -1; } diff --git a/tests/xlconfigdata/test-rbd-multihost-noauth.cfg b/tests/xlconfigdata/test-rbd-multihost-noauth.cfg new file mode 100644 index 0000000..e233e14 --- /dev/null +++ b/tests/xlconfigdata/test-rbd-multihost-noauth.cfg @@ -0,0 +1,26 @@ +name = "XenGuest2" +uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" +maxmem = 579 +memory = 394 +vcpus = 1 +pae = 1 +acpi = 1 +apic = 1 +hap = 0 +viridian = 0 +rtc_timeoffset = 0 +localtime = 0 +on_poweroff = "destroy" +on_reboot = "restart" +on_crash = "restart" +device_model = "/usr/lib/xen/bin/qemu-dm" +sdl = 0 +vnc = 1 +vncunused = 1 +vnclisten = "127.0.0.1" +vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000" ] +parallel = "none" +serial = "none" +builder = "hvm" +boot = "d" +disk = [ "format=raw,vdev=hda,access=rw,backendtype=phy,target=/dev/HostVG/XenGuest2", "format=raw,vdev=hdb,access=rw,backendtype=qdisk,target=rbd:pool/image:auth_supported=none:mon_host=mon1.example.org\:6321\;mon2.example.org\:6322\;mon3.example.org\:6322" ] diff --git a/tests/xlconfigdata/test-rbd-multihost-noauth.xml b/tests/xlconfigdata/test-rbd-multihost-noauth.xml new file mode 100644 index 0000000..720265e --- /dev/null +++ b/tests/xlconfigdata/test-rbd-multihost-noauth.xml @@ -0,0 +1,51 @@ + + XenGuest2 + c7a5fdb2-cdaf-9455-926a-d65c16db1809 + 592896 + 403456 + 1 + + hvm + /usr/lib/xen/boot/hvmloader + + + + + + + + + destroy + restart + restart + + /usr/lib/xen/bin/qemu-dm + + + + +
+ + + + + + + + + +
+ + + + +