]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Move qemuGetDriveSourceProps to qemu_block
authorPeter Krempa <pkrempa@redhat.com>
Fri, 7 Jul 2017 14:29:01 +0000 (16:29 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 14 Jul 2017 14:05:46 +0000 (16:05 +0200)
Pure code movement except for the tweaks necessary for cross-usage.

po/POTFILES.in
src/qemu/qemu_block.c
src/qemu/qemu_block.h
src/qemu/qemu_command.c

index 87634d228b5977c3fd7738bcdabb1c1f199e27bf..b3891b58773233fd9e1c59e0041a5b35bb7f9287 100644 (file)
@@ -129,6 +129,7 @@ src/openvz/openvz_util.c
 src/phyp/phyp_driver.c
 src/qemu/qemu_agent.c
 src/qemu/qemu_alias.c
+src/qemu/qemu_block.c
 src/qemu/qemu_capabilities.c
 src/qemu/qemu_cgroup.c
 src/qemu/qemu_command.c
index 29b5c4756e9bd8d691bb650d7d592f2cf68aba8d..e6b9090151324d8625b2e6c556c937980ec9a7ab 100644 (file)
@@ -428,3 +428,129 @@ qemuBlockGetNodeData(virJSONValuePtr data)
     virHashFree(ret);
     return NULL;
 }
+
+
+/* builds the hosts array */
+static virJSONValuePtr
+qemuBuildGlusterDriveJSONHosts(virStorageSourcePtr src)
+{
+    virJSONValuePtr servers = NULL;
+    virJSONValuePtr server = NULL;
+    virJSONValuePtr ret = NULL;
+    virStorageNetHostDefPtr host;
+    const char *transport;
+    size_t i;
+
+    if (!(servers = virJSONValueNewArray()))
+        goto cleanup;
+
+    for (i = 0; i < src->nhosts; i++) {
+        host = src->hosts + i;
+        transport = virStorageNetHostTransportTypeToString(host->transport);
+
+        if (virJSONValueObjectCreate(&server, "s:type", transport, NULL) < 0)
+            goto cleanup;
+
+        switch ((virStorageNetHostTransport) host->transport) {
+        case VIR_STORAGE_NET_HOST_TRANS_TCP:
+            if (virJSONValueObjectAdd(server,
+                                      "s:host", host->name,
+                                      "s:port", host->port,
+                                      NULL) < 0)
+                goto cleanup;
+            break;
+
+        case VIR_STORAGE_NET_HOST_TRANS_UNIX:
+            if (virJSONValueObjectAdd(server,
+                                      "s:socket", host->socket,
+                                      NULL) < 0)
+                goto cleanup;
+            break;
+
+        case VIR_STORAGE_NET_HOST_TRANS_RDMA:
+        case VIR_STORAGE_NET_HOST_TRANS_LAST:
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("transport protocol '%s' is not yet supported"),
+                           transport);
+            goto cleanup;
+        }
+
+        if (virJSONValueArrayAppend(servers, server) < 0)
+            goto cleanup;
+
+        server = NULL;
+    }
+
+    ret = servers;
+    servers = NULL;
+
+ cleanup:
+    virJSONValueFree(servers);
+    virJSONValueFree(server);
+
+    return ret;
+}
+
+
+static virJSONValuePtr
+qemuBuildGlusterDriveJSON(virStorageSourcePtr src)
+{
+    const char *protocol = virStorageNetProtocolTypeToString(src->protocol);
+    virJSONValuePtr servers = NULL;
+    virJSONValuePtr ret = NULL;
+
+    if (!(servers = qemuBuildGlusterDriveJSONHosts(src)))
+        return NULL;
+
+     /* { driver:"gluster",
+      *   volume:"testvol",
+      *   path:"/a.img",
+      *   server :[{type:"tcp", host:"1.2.3.4", port:24007},
+      *            {type:"unix", socket:"/tmp/glusterd.socket"}, ...]}
+      */
+    if (virJSONValueObjectCreate(&ret,
+                                 "s:driver", protocol,
+                                 "s:volume", src->volume,
+                                 "s:path", src->path,
+                                 "a:server", servers, NULL) < 0)
+          virJSONValueFree(servers);
+
+    return ret;
+}
+
+
+int
+qemuGetDriveSourceProps(virStorageSourcePtr src,
+                        virJSONValuePtr *props)
+{
+    int actualType = virStorageSourceGetActualType(src);
+    virJSONValuePtr fileprops = NULL;
+
+    *props = NULL;
+
+    switch ((virStorageType) actualType) {
+    case VIR_STORAGE_TYPE_BLOCK:
+    case VIR_STORAGE_TYPE_FILE:
+    case VIR_STORAGE_TYPE_DIR:
+    case VIR_STORAGE_TYPE_VOLUME:
+    case VIR_STORAGE_TYPE_NONE:
+    case VIR_STORAGE_TYPE_LAST:
+        break;
+
+    case VIR_STORAGE_TYPE_NETWORK:
+        if (src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER &&
+            src->nhosts > 1) {
+            if (!(fileprops = qemuBuildGlusterDriveJSON(src)))
+                return -1;
+        }
+        break;
+    }
+
+    if (fileprops &&
+        virJSONValueObjectCreate(props, "a:file", fileprops, NULL) < 0) {
+        virJSONValueFree(fileprops);
+        return -1;
+    }
+
+    return 0;
+}
index 2af15a65a0d4d6eabea59c6e0e2a9368ad98117d..3a8950b1385f14569269491662d17b4f8116fe63 100644 (file)
@@ -53,4 +53,9 @@ qemuBlockNodeNamesDetect(virQEMUDriverPtr driver,
 virHashTablePtr
 qemuBlockGetNodeData(virJSONValuePtr data);
 
+
+int
+qemuGetDriveSourceProps(virStorageSourcePtr src,
+                        virJSONValuePtr *props);
+
 #endif /* __QEMU_BLOCK_H__ */
index b69ff4ae5dc7dc772fa8543f48bfd6909a94dbb1..ebf24361b678305f52e5160e36fd40bd16f9b5df 100644 (file)
@@ -29,6 +29,7 @@
 #include "qemu_interface.h"
 #include "qemu_alias.h"
 #include "qemu_security.h"
+#include "qemu_block.h"
 #include "cpu/cpu.h"
 #include "dirname.h"
 #include "viralloc.h"
@@ -792,95 +793,6 @@ qemuBuildTLSx509CommandLine(virCommandPtr cmd,
 }
 
 
-/* builds the hosts array */
-static virJSONValuePtr
-qemuBuildGlusterDriveJSONHosts(virStorageSourcePtr src)
-{
-    virJSONValuePtr servers = NULL;
-    virJSONValuePtr server = NULL;
-    virJSONValuePtr ret = NULL;
-    virStorageNetHostDefPtr host;
-    const char *transport;
-    size_t i;
-
-    if (!(servers = virJSONValueNewArray()))
-        goto cleanup;
-
-    for (i = 0; i < src->nhosts; i++) {
-        host = src->hosts + i;
-        transport = virStorageNetHostTransportTypeToString(host->transport);
-
-        if (virJSONValueObjectCreate(&server, "s:type", transport, NULL) < 0)
-            goto cleanup;
-
-        switch ((virStorageNetHostTransport) host->transport) {
-        case VIR_STORAGE_NET_HOST_TRANS_TCP:
-            if (virJSONValueObjectAdd(server,
-                                      "s:host", host->name,
-                                      "s:port", host->port,
-                                      NULL) < 0)
-                goto cleanup;
-            break;
-
-        case VIR_STORAGE_NET_HOST_TRANS_UNIX:
-            if (virJSONValueObjectAdd(server,
-                                      "s:socket", host->socket,
-                                      NULL) < 0)
-                goto cleanup;
-            break;
-
-        case VIR_STORAGE_NET_HOST_TRANS_RDMA:
-        case VIR_STORAGE_NET_HOST_TRANS_LAST:
-            virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("transport protocol '%s' is not yet supported"),
-                           transport);
-            goto cleanup;
-        }
-
-        if (virJSONValueArrayAppend(servers, server) < 0)
-            goto cleanup;
-
-        server = NULL;
-    }
-
-    ret = servers;
-    servers = NULL;
-
- cleanup:
-    virJSONValueFree(servers);
-    virJSONValueFree(server);
-
-    return ret;
-}
-
-
-static virJSONValuePtr
-qemuBuildGlusterDriveJSON(virStorageSourcePtr src)
-{
-    const char *protocol = virStorageNetProtocolTypeToString(src->protocol);
-    virJSONValuePtr servers = NULL;
-    virJSONValuePtr ret = NULL;
-
-    if (!(servers = qemuBuildGlusterDriveJSONHosts(src)))
-        return NULL;
-
-     /* { driver:"gluster",
-      *   volume:"testvol",
-      *   path:"/a.img",
-      *   server :[{type:"tcp", host:"1.2.3.4", port:24007},
-      *            {type:"unix", socket:"/tmp/glusterd.socket"}, ...]}
-      */
-    if (virJSONValueObjectCreate(&ret,
-                                 "s:driver", protocol,
-                                 "s:volume", src->volume,
-                                 "s:path", src->path,
-                                 "a:server", servers, NULL) < 0)
-          virJSONValueFree(servers);
-
-    return ret;
-}
-
-
 static char *
 qemuBuildNetworkDriveURI(virStorageSourcePtr src,
                          qemuDomainSecretInfoPtr secinfo)
@@ -1103,43 +1015,6 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src,
 }
 
 
-static int
-qemuGetDriveSourceProps(virStorageSourcePtr src,
-                        virJSONValuePtr *props)
-{
-    int actualType = virStorageSourceGetActualType(src);
-    virJSONValuePtr fileprops = NULL;
-
-    *props = NULL;
-
-    switch ((virStorageType) actualType) {
-    case VIR_STORAGE_TYPE_BLOCK:
-    case VIR_STORAGE_TYPE_FILE:
-    case VIR_STORAGE_TYPE_DIR:
-    case VIR_STORAGE_TYPE_VOLUME:
-    case VIR_STORAGE_TYPE_NONE:
-    case VIR_STORAGE_TYPE_LAST:
-        break;
-
-    case VIR_STORAGE_TYPE_NETWORK:
-        if (src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER &&
-            src->nhosts > 1) {
-            if (!(fileprops = qemuBuildGlusterDriveJSON(src)))
-                return -1;
-        }
-        break;
-    }
-
-    if (fileprops &&
-        virJSONValueObjectCreate(props, "a:file", fileprops, NULL) < 0) {
-        virJSONValueFree(fileprops);
-        return -1;
-    }
-
-    return 0;
-}
-
-
 int
 qemuGetDriveSourceString(virStorageSourcePtr src,
                          qemuDomainSecretInfoPtr secinfo,