From nobody Thu May 15 10:08:39 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1509719463471954.2413346980625; Fri, 3 Nov 2017 07:31:03 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C4E596A09; Fri, 3 Nov 2017 14:31:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8FCE05D973; Fri, 3 Nov 2017 14:31:01 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 4803C1800BD1; Fri, 3 Nov 2017 14:31:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id vA3ETqHb028715 for ; Fri, 3 Nov 2017 10:29:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 693AC60618; Fri, 3 Nov 2017 14:29:52 +0000 (UTC) Received: from angien.brq.redhat.com (unknown [10.43.2.136]) by smtp.corp.redhat.com (Postfix) with ESMTP id E55BE60619 for ; Fri, 3 Nov 2017 14:29:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C4E596A09 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Peter Krempa To: libvir-list@redhat.com Date: Fri, 3 Nov 2017 15:29:19 +0100 Message-Id: <685f5c1976dafdf7c85e524b9ef89d1604cb1785.1509719227.git.pkrempa@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 02/12] qemu: process: Split out useful parts from qemuBuildNetworkDriveURI X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 03 Nov 2017 14:31:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Extract the part formatting the basic URI part so that it can be reused to format JSON backing definitions. Parts specific to the command line format will remain in qemuBuildNetworkDriveURI. The new function is called qemuBlockStorageSourceGetURI. --- src/qemu/qemu_block.c | 58 +++++++++++++++++++++++++++++++++++++++++++++= ++++ src/qemu/qemu_block.h | 4 ++++ src/qemu/qemu_command.c | 38 +------------------------------- 3 files changed, 63 insertions(+), 37 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 96db19226..018d7c7ec 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -390,6 +390,64 @@ qemuBlockGetNodeData(virJSONValuePtr data) } +/** + * qemuBlockStorageSourceGetURI: + * @src: disk storage source + * + * Formats a URI from a virStorageSource */ +virURIPtr +qemuBlockStorageSourceGetURI(virStorageSourcePtr src) +{ + virURIPtr uri =3D NULL; + virURIPtr ret =3D NULL; + + if (src->nhosts !=3D 1) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("protocol '%s' accepts only one host"), + virStorageNetProtocolTypeToString(src->protocol)); + goto cleanup; + } + + if (VIR_ALLOC(uri) < 0) + goto cleanup; + + if (src->hosts->transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_TCP) { + uri->port =3D src->hosts->port; + + if (VIR_STRDUP(uri->scheme, + virStorageNetProtocolTypeToString(src->protocol)) <= 0) + goto cleanup; + } else { + if (virAsprintf(&uri->scheme, "%s+%s", + virStorageNetProtocolTypeToString(src->protocol), + virStorageNetHostTransportTypeToString(src->hosts-= >transport)) < 0) + goto cleanup; + } + + if (src->path) { + if (src->volume) { + if (virAsprintf(&uri->path, "/%s%s", + src->volume, src->path) < 0) + goto cleanup; + } else { + if (virAsprintf(&uri->path, "%s%s", + src->path[0] =3D=3D '/' ? "" : "/", + src->path) < 0) + goto cleanup; + } + } + + if (VIR_STRDUP(uri->server, src->hosts->name) < 0) + goto cleanup; + + VIR_STEAL_PTR(ret, uri); + + cleanup: + virURIFree(uri); + return ret; +} + + /** * qemuBlockStorageSourceBuildJSONSocketAddress * @host: the virStorageNetHostDefPtr definition to build diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index f0a2c9aa7..b9ee97f48 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -26,6 +26,7 @@ # include "virhash.h" # include "virjson.h" +# include "viruri.h" typedef struct qemuBlockNodeNameBackingChainData qemuBlockNodeNameBackingC= hainData; typedef qemuBlockNodeNameBackingChainData *qemuBlockNodeNameBackingChainDa= taPtr; @@ -56,4 +57,7 @@ qemuBlockGetNodeData(virJSONValuePtr data); virJSONValuePtr qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src); +virURIPtr +qemuBlockStorageSourceGetURI(virStorageSourcePtr src); + #endif /* __QEMU_BLOCK_H__ */ diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index b1cfafa79..25d5fdf18 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -829,41 +829,8 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src, virURIPtr uri =3D NULL; char *ret =3D NULL; - if (src->nhosts !=3D 1) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("protocol '%s' accepts only one host"), - virStorageNetProtocolTypeToString(src->protocol)); + if (!(uri =3D qemuBlockStorageSourceGetURI(src))) goto cleanup; - } - - if (VIR_ALLOC(uri) < 0) - goto cleanup; - - if (src->hosts->transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_TCP) { - uri->port =3D src->hosts->port; - - if (VIR_STRDUP(uri->scheme, - virStorageNetProtocolTypeToString(src->protocol)) <= 0) - goto cleanup; - } else { - if (virAsprintf(&uri->scheme, "%s+%s", - virStorageNetProtocolTypeToString(src->protocol), - virStorageNetHostTransportTypeToString(src->hosts-= >transport)) < 0) - goto cleanup; - } - - if (src->path) { - if (src->volume) { - if (virAsprintf(&uri->path, "/%s%s", - src->volume, src->path) < 0) - goto cleanup; - } else { - if (virAsprintf(&uri->path, "%s%s", - src->path[0] =3D=3D '/' ? "" : "/", - src->path) < 0) - goto cleanup; - } - } if (src->hosts->socket && virAsprintf(&uri->query, "socket=3D%s", src->hosts->socket) < 0) @@ -872,9 +839,6 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src, if (qemuBuildGeneralSecinfoURI(uri, secinfo) < 0) goto cleanup; - if (VIR_STRDUP(uri->server, src->hosts->name) < 0) - goto cleanup; - ret =3D virURIFormat(uri); cleanup: --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list