|
|
6ae9ed |
From 16c4218bf97f70a5f9e66fef4fda18126fc05653 Mon Sep 17 00:00:00 2001
|
|
|
6ae9ed |
Message-Id: <16c4218bf97f70a5f9e66fef4fda18126fc05653@dist-git>
|
|
|
6ae9ed |
From: Peter Krempa <pkrempa@redhat.com>
|
|
|
6ae9ed |
Date: Tue, 2 Aug 2016 13:41:58 +0200
|
|
|
6ae9ed |
Subject: [PATCH] qemu: command: Split out network disk URI building
|
|
|
6ae9ed |
|
|
|
6ae9ed |
Extract the code so that it can be called from multiple places. This
|
|
|
6ae9ed |
also removes a tricky fallthrough in the large switch in
|
|
|
6ae9ed |
qemuBuildNetworkDriveStr.
|
|
|
6ae9ed |
|
|
|
6ae9ed |
(cherry picked from commit ccaaad62a8b0ffb48d91ad572933a1c605465242)
|
|
|
6ae9ed |
https://bugzilla.redhat.com/show_bug.cgi?id=1247521 [gluster multi-host]
|
|
|
6ae9ed |
---
|
|
|
6ae9ed |
src/qemu/qemu_command.c | 122 +++++++++++++++++++++++++++---------------------
|
|
|
6ae9ed |
1 file changed, 68 insertions(+), 54 deletions(-)
|
|
|
6ae9ed |
|
|
|
6ae9ed |
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
|
|
|
6ae9ed |
index b691743..32f8384 100644
|
|
|
6ae9ed |
--- a/src/qemu/qemu_command.c
|
|
|
6ae9ed |
+++ b/src/qemu/qemu_command.c
|
|
|
6ae9ed |
@@ -690,13 +690,76 @@ qemuBuildRBDSecinfoURI(virBufferPtr buf,
|
|
|
6ae9ed |
|
|
|
6ae9ed |
#define QEMU_DEFAULT_NBD_PORT "10809"
|
|
|
6ae9ed |
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+static char *
|
|
|
6ae9ed |
+qemuBuildNetworkDriveURI(virStorageSourcePtr src,
|
|
|
6ae9ed |
+ qemuDomainSecretInfoPtr secinfo)
|
|
|
6ae9ed |
+{
|
|
|
6ae9ed |
+ virURIPtr uri = NULL;
|
|
|
6ae9ed |
+ char *ret = NULL;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (src->nhosts != 1) {
|
|
|
6ae9ed |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
6ae9ed |
+ _("protocol '%s' accepts only one host"),
|
|
|
6ae9ed |
+ virStorageNetProtocolTypeToString(src->protocol));
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (VIR_ALLOC(uri) < 0)
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
|
|
|
6ae9ed |
+ if (VIR_STRDUP(uri->scheme,
|
|
|
6ae9ed |
+ virStorageNetProtocolTypeToString(src->protocol)) < 0)
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+ } else {
|
|
|
6ae9ed |
+ if (virAsprintf(&uri->scheme, "%s+%s",
|
|
|
6ae9ed |
+ virStorageNetProtocolTypeToString(src->protocol),
|
|
|
6ae9ed |
+ virStorageNetHostTransportTypeToString(src->hosts->transport)) < 0)
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if ((uri->port = qemuNetworkDriveGetPort(src->protocol,
|
|
|
6ae9ed |
+ src->hosts->port)) < 0)
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (src->path) {
|
|
|
6ae9ed |
+ if (src->volume) {
|
|
|
6ae9ed |
+ if (virAsprintf(&uri->path, "/%s%s",
|
|
|
6ae9ed |
+ src->volume, src->path) < 0)
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+ } else {
|
|
|
6ae9ed |
+ if (virAsprintf(&uri->path, "%s%s",
|
|
|
6ae9ed |
+ src->path[0] == '/' ? "" : "/",
|
|
|
6ae9ed |
+ src->path) < 0)
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+ }
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (src->hosts->socket &&
|
|
|
6ae9ed |
+ virAsprintf(&uri->query, "socket=%s", src->hosts->socket) < 0)
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (qemuBuildGeneralSecinfoURI(uri, secinfo) < 0)
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ if (VIR_STRDUP(uri->server, src->hosts->name) < 0)
|
|
|
6ae9ed |
+ goto cleanup;
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ ret = virURIFormat(uri);
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+ cleanup:
|
|
|
6ae9ed |
+ virURIFree(uri);
|
|
|
6ae9ed |
+ return ret;
|
|
|
6ae9ed |
+}
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
+
|
|
|
6ae9ed |
static char *
|
|
|
6ae9ed |
qemuBuildNetworkDriveStr(virStorageSourcePtr src,
|
|
|
6ae9ed |
qemuDomainSecretInfoPtr secinfo)
|
|
|
6ae9ed |
{
|
|
|
6ae9ed |
char *ret = NULL;
|
|
|
6ae9ed |
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
|
|
6ae9ed |
- virURIPtr uri = NULL;
|
|
|
6ae9ed |
size_t i;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
switch ((virStorageNetProtocol) src->protocol) {
|
|
|
6ae9ed |
@@ -752,8 +815,9 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src,
|
|
|
6ae9ed |
ret = virBufferContentAndReset(&buf;;
|
|
|
6ae9ed |
goto cleanup;
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
- /* fallthrough */
|
|
|
6ae9ed |
- /* NBD code uses same formatting scheme as others in some cases */
|
|
|
6ae9ed |
+ /* NBD code uses URI formatting scheme as others in some cases */
|
|
|
6ae9ed |
+ ret = qemuBuildNetworkDriveURI(src, secinfo);
|
|
|
6ae9ed |
+ break;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
case VIR_STORAGE_NET_PROTOCOL_HTTP:
|
|
|
6ae9ed |
case VIR_STORAGE_NET_PROTOCOL_HTTPS:
|
|
|
6ae9ed |
@@ -762,56 +826,7 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src,
|
|
|
6ae9ed |
case VIR_STORAGE_NET_PROTOCOL_TFTP:
|
|
|
6ae9ed |
case VIR_STORAGE_NET_PROTOCOL_ISCSI:
|
|
|
6ae9ed |
case VIR_STORAGE_NET_PROTOCOL_GLUSTER:
|
|
|
6ae9ed |
- if (src->nhosts != 1) {
|
|
|
6ae9ed |
- virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
6ae9ed |
- _("protocol '%s' accepts only one host"),
|
|
|
6ae9ed |
- virStorageNetProtocolTypeToString(src->protocol));
|
|
|
6ae9ed |
- goto cleanup;
|
|
|
6ae9ed |
- }
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- if (VIR_ALLOC(uri) < 0)
|
|
|
6ae9ed |
- goto cleanup;
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- if (src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
|
|
|
6ae9ed |
- if (VIR_STRDUP(uri->scheme,
|
|
|
6ae9ed |
- virStorageNetProtocolTypeToString(src->protocol)) < 0)
|
|
|
6ae9ed |
- goto cleanup;
|
|
|
6ae9ed |
- } else {
|
|
|
6ae9ed |
- if (virAsprintf(&uri->scheme, "%s+%s",
|
|
|
6ae9ed |
- virStorageNetProtocolTypeToString(src->protocol),
|
|
|
6ae9ed |
- virStorageNetHostTransportTypeToString(src->hosts->transport)) < 0)
|
|
|
6ae9ed |
- goto cleanup;
|
|
|
6ae9ed |
- }
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- if ((uri->port = qemuNetworkDriveGetPort(src->protocol,
|
|
|
6ae9ed |
- src->hosts->port)) < 0)
|
|
|
6ae9ed |
- goto cleanup;
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- if (src->path) {
|
|
|
6ae9ed |
- if (src->volume) {
|
|
|
6ae9ed |
- if (virAsprintf(&uri->path, "/%s%s",
|
|
|
6ae9ed |
- src->volume, src->path) < 0)
|
|
|
6ae9ed |
- goto cleanup;
|
|
|
6ae9ed |
- } else {
|
|
|
6ae9ed |
- if (virAsprintf(&uri->path, "%s%s",
|
|
|
6ae9ed |
- src->path[0] == '/' ? "" : "/",
|
|
|
6ae9ed |
- src->path) < 0)
|
|
|
6ae9ed |
- goto cleanup;
|
|
|
6ae9ed |
- }
|
|
|
6ae9ed |
- }
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- if (src->hosts->socket &&
|
|
|
6ae9ed |
- virAsprintf(&uri->query, "socket=%s", src->hosts->socket) < 0)
|
|
|
6ae9ed |
- goto cleanup;
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- if (qemuBuildGeneralSecinfoURI(uri, secinfo) < 0)
|
|
|
6ae9ed |
- goto cleanup;
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- if (VIR_STRDUP(uri->server, src->hosts->name) < 0)
|
|
|
6ae9ed |
- goto cleanup;
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
- ret = virURIFormat(uri);
|
|
|
6ae9ed |
-
|
|
|
6ae9ed |
+ ret = qemuBuildNetworkDriveURI(src, secinfo);
|
|
|
6ae9ed |
break;
|
|
|
6ae9ed |
|
|
|
6ae9ed |
case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
|
|
|
6ae9ed |
@@ -896,7 +911,6 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src,
|
|
|
6ae9ed |
|
|
|
6ae9ed |
cleanup:
|
|
|
6ae9ed |
virBufferFreeAndReset(&buf;;
|
|
|
6ae9ed |
- virURIFree(uri);
|
|
|
6ae9ed |
|
|
|
6ae9ed |
return ret;
|
|
|
6ae9ed |
}
|
|
|
6ae9ed |
--
|
|
|
6ae9ed |
2.9.2
|
|
|
6ae9ed |
|