[PATCH] Implementing RBD support for QEMU via Storage API (Storage pools)

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

 



---
 src/qemu/qemu_command.c | 11 ++++++---
 src/qemu/qemu_conf.c    | 66 ++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 71 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 966aa0d..1bec983 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3823,9 +3823,14 @@ qemuBuildVolumeString(virConnectPtr conn,
         }
         break;
     case VIR_STORAGE_VOL_NETWORK:
-        /* Keep the compiler quite, qemuTranslateDiskSourcePool already
-         * reported the unsupported error.
-         */
+        if (disk->srcpool->pooltype == VIR_STORAGE_POOL_RBD) {
+            virBufferAddLit(opt, "file=");
+
+            if (qemuBuildRBDString(conn, disk, opt) < 0)
+                goto cleanup;
+
+            virBufferAddChar(opt, ',');
+        }
         break;
     }
 
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 03c9c7d..bcf9548 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1246,6 +1246,45 @@ cleanup:
 }
 
 static int
+qemuAddRBDPoolSourceHost(virDomainDiskDefPtr def,
+                           virStoragePoolDefPtr pooldef)
+{
+    int ret = -1;
+    size_t i = 0;
+    char **tokens = NULL;
+
+    def->nhosts = pooldef->source.nhost;
+
+    if (VIR_ALLOC_N(def->hosts, def->nhosts) < 0)
+        goto cleanup;
+
+    for (i = 0; i < def->nhosts; i++) {
+        if (VIR_STRDUP(def->hosts[i].name, pooldef->source.hosts[i].name) < 0)
+            goto cleanup;
+
+        if (virAsprintf(&def->hosts[i].port, "%d",
+                        pooldef->source.hosts[i].port ?
+                        pooldef->source.hosts[i].port :
+                        6789) < 0)
+            goto cleanup;
+
+        /* Storage pool have not supported these 2 attributes yet,
+         * use the defaults.
+         */
+        def->hosts[i].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP;
+        def->hosts[i].socket = NULL;
+    }
+
+    def->protocol = VIR_DOMAIN_DISK_PROTOCOL_RBD;
+
+    ret = 0;
+
+cleanup:
+    virStringFreeList(tokens);
+    return ret;
+}
+
+static int
 qemuTranslateDiskSourcePoolAuth(virDomainDiskDefPtr def,
                                 virStoragePoolDefPtr pooldef)
 {
@@ -1376,9 +1415,30 @@ qemuTranslateDiskSourcePool(virConnectPtr conn,
 
         break;
     case VIR_STORAGE_VOL_NETWORK:
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                       _("Using network volume as disk source is not supported"));
-        goto cleanup;
+        if (!(poolxml = virStoragePoolGetXMLDesc(pool, 0)))
+            goto cleanup;
+
+        if (!(pooldef = virStoragePoolDefParseString(poolxml)))
+            goto cleanup;
+
+        def->srcpool->pooltype = pooldef->type;
+        if (pooldef->type == VIR_STORAGE_POOL_RBD) {
+            if (!def->srcpool->mode)
+                def->srcpool->mode = VIR_DOMAIN_DISK_SOURCE_POOL_MODE_DIRECT;
+
+            if (qemuAddRBDPoolSourceHost(def, pooldef) < 0)
+                goto cleanup;
+
+            if (!(def->src = virStorageVolGetPath(vol)))
+                goto cleanup;
+
+            if (qemuTranslateDiskSourcePoolAuth(def, pooldef) < 0)
+                goto cleanup;
+        } else {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("Unsupported network volume type"));
+            goto cleanup;
+        }
     }
 
     def->srcpool->voltype = info.type;
-- 
1.8.4.2

--
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]