[PATCH 08/12] qemu: block: Add JSON props generator for RBD storage backing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/qemu/qemu_block.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 451d04694..8a1ce8262 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -593,6 +593,47 @@ qemuBlockStorageSourceBuildJSONInetSocketAddress(virStorageNetHostDefPtr host)
 }


+/**
+ * qemuBlockStorageSourceBuildHostsJSONInetSocketAddress:
+ * @src: disk storage source
+ *
+ * Formats src->hosts into a json object conforming to the 'InetSocketAddress'
+ * type in qemu.
+ */
+static virJSONValuePtr
+qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(virStorageSourcePtr src)
+{
+    virJSONValuePtr servers = NULL;
+    virJSONValuePtr server = NULL;
+    virJSONValuePtr ret = NULL;
+    virStorageNetHostDefPtr host;
+    size_t i;
+
+    if (!(servers = virJSONValueNewArray()))
+        goto cleanup;
+
+    for (i = 0; i < src->nhosts; i++) {
+        host = src->hosts + i;
+
+        if (!(server = qemuBlockStorageSourceBuildJSONInetSocketAddress(host)))
+              goto cleanup;
+
+        if (virJSONValueArrayAppend(servers, server) < 0)
+            goto cleanup;
+
+        server = NULL;
+    }
+
+    VIR_STEAL_PTR(ret, servers);
+
+ cleanup:
+    virJSONValueFree(servers);
+    virJSONValueFree(server);
+
+    return ret;
+}
+
+
 static virJSONValuePtr
 qemuBlockStorageSourceGetGlusterProps(virStorageSourcePtr src)
 {
@@ -795,6 +836,35 @@ qemuBlockStorageSourceGetNBDProps(virStorageSourcePtr src)
 }


+static virJSONValuePtr
+qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr src)
+{
+    qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
+    virJSONValuePtr servers = NULL;
+    virJSONValuePtr ret = NULL;
+    const char *username = NULL;
+
+    if (src->nhosts > 0 &&
+        !(servers = qemuBlockStorageSourceBuildHostsJSONInetSocketAddress(src)))
+        return NULL;
+
+    if (src->auth)
+        username = srcPriv->secinfo->s.aes.username;
+
+    ignore_value(virJSONValueObjectCreate(&ret,
+                                          "s:driver", "rbd",
+                                          "s:pool", src->volume,
+                                          "s:image", src->path,
+                                          "S:snapshot", src->snapshot,
+                                          "S:conf", src->configFile,
+                                          "A:server", servers,
+                                          "S:user", username,
+                                          NULL));
+
+    return ret;
+}
+
+
 /**
  * qemuBlockStorageSourceGetBackendProps:
  * @src: disk source
@@ -855,6 +925,10 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src)
             break;

         case VIR_STORAGE_NET_PROTOCOL_RBD:
+            if (!(fileprops = qemuBlockStorageSourceGetRBDProps(src)))
+                return NULL;
+            break;
+
         case VIR_STORAGE_NET_PROTOCOL_SHEEPDOG:
         case VIR_STORAGE_NET_PROTOCOL_SSH:
         case VIR_STORAGE_NET_PROTOCOL_NONE:
-- 
2.14.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux