]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: process: Split out useful parts from qemuBuildNetworkDriveURI
authorPeter Krempa <pkrempa@redhat.com>
Thu, 13 Jul 2017 13:38:50 +0000 (15:38 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 7 Nov 2017 13:57:58 +0000 (14:57 +0100)
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
src/qemu/qemu_block.h
src/qemu/qemu_command.c

index 96db1922690d000953555cbf40e4660b5663f2cd..77e48bed8370a4042844ae18620bcf4e4a803e71 100644 (file)
@@ -390,6 +390,65 @@ qemuBlockGetNodeData(virJSONValuePtr data)
 }
 
 
+/**
+ * qemuBlockStorageSourceGetURI:
+ * @src: disk storage source
+ *
+ * Formats a URI from a virStorageSource.
+ */
+virURIPtr
+qemuBlockStorageSourceGetURI(virStorageSourcePtr src)
+{
+    virURIPtr uri = NULL;
+    virURIPtr ret = NULL;
+
+    if (src->nhosts != 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 == VIR_STORAGE_NET_HOST_TRANS_TCP) {
+        uri->port = 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] == '/' ? "" : "/",
+                            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
index f0a2c9aa7d58135299de6bbbd44a7ce1739d5e5b..b9ee97f488725c2d402c03cfa96359c90890cd03 100644 (file)
@@ -26,6 +26,7 @@
 
 # include "virhash.h"
 # include "virjson.h"
+# include "viruri.h"
 
 typedef struct qemuBlockNodeNameBackingChainData qemuBlockNodeNameBackingChainData;
 typedef qemuBlockNodeNameBackingChainData *qemuBlockNodeNameBackingChainDataPtr;
@@ -56,4 +57,7 @@ qemuBlockGetNodeData(virJSONValuePtr data);
 virJSONValuePtr
 qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src);
 
+virURIPtr
+qemuBlockStorageSourceGetURI(virStorageSourcePtr src);
+
 #endif /* __QEMU_BLOCK_H__ */
index 2fe4ae380a051092d278c1e4286dc17f21152948..429f1a21565b8e7a9cf3e94f57d101aa4014e92a 100644 (file)
@@ -829,41 +829,8 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src,
     virURIPtr uri = NULL;
     char *ret = NULL;
 
-    if (src->nhosts != 1) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("protocol '%s' accepts only one host"),
-                       virStorageNetProtocolTypeToString(src->protocol));
+    if (!(uri = qemuBlockStorageSourceGetURI(src)))
         goto cleanup;
-    }
-
-    if (VIR_ALLOC(uri) < 0)
-        goto cleanup;
-
-    if (src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) {
-        uri->port = 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] == '/' ? "" : "/",
-                            src->path) < 0)
-                goto cleanup;
-        }
-    }
 
     if (src->hosts->socket &&
         virAsprintf(&uri->query, "socket=%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 = virURIFormat(uri);
 
  cleanup: