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

[libvirt] [PATCH 9/9] Support network pool for volume disk



The only two network pools we supported are "rbd" and "sheepdog",
and attributes "socket", "transport" are not supported in storage
pool conf yet, this uses the default setting (TCP for 'transport',
and "socket" is not set) temporarily. Future patches will extend
the storage pool conf to support 'transport' and 'socket'.
---
 src/libvirt_private.syms     |    1 +
 src/storage/storage_driver.c |   49 +++++++++++++++++++++++++++++++++++++----
 2 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index a44f3ff..4674bf9 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1153,6 +1153,7 @@ virStoragePoolSourceFree;
 virStoragePoolSourceListFormat;
 virStoragePoolSourceListNewSource;
 virStoragePoolTypeFromString;
+virStoragePoolTypeToString;
 virStorageVolDefFindByKey;
 virStorageVolDefFindByName;
 virStorageVolDefFindByPath;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index f2ca310..115c7a0 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -2406,12 +2406,15 @@ storageTranslateDomainDiskSourcePool(virConnectPtr conn,
                                      virDomainDefPtr def)
 {
     virStoragePoolObjPtr pool = NULL;
-    virStorageVolDefPtr vol = NULL;
     int i;
     int ret = -1;
 
     for (i = 0; i < def->ndisks; i++) {
+        virStorageVolDefPtr vol = NULL;
         virDomainDiskDefPtr disk = def->disks[i];
+        virDomainDiskHostDefPtr hosts = NULL;
+        int nhost;
+        int n;
 
         if (disk->type != VIR_DOMAIN_DISK_TYPE_VOLUME)
             continue;
@@ -2449,10 +2452,46 @@ storageTranslateDomainDiskSourcePool(virConnectPtr conn,
             disk->src = strdup(vol->target.path);
             break;
         case VIR_STORAGE_VOL_NETWORK:
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                           _("Using network volume as disk source is not supported"));
-            goto cleanup;
-        }
+            if (pool->def->type != VIR_STORAGE_POOL_RBD &&
+                pool->def->type != VIR_STORAGE_POOL_SHEEPDOG) {
+                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                               _("Using '%s' pool as disk source is "
+                                 "not supported"),
+                               virStoragePoolTypeToString(pool->def->type));
+                goto cleanup;
+            }
+
+            if (VIR_ALLOC_N(hosts, pool->def->source.nhost) < 0) {
+                virReportOOMError();
+                goto cleanup;
+            }
+
+            nhost = pool->def->source.nhost;
+            for (n = 0; n < pool->def->source.nhost; n++) {
+                hosts[n].name = strdup(pool->def->source.hosts[n].name);
+                if (virAsprintf(&hosts[n].port, "%d",
+                    pool->def->source.hosts[n].port) < 0) {
+                    virReportOOMError();
+                    while (nhost > 0) {
+                        virDomainDiskHostDefFree(&hosts[nhost - 1]);
+                        nhost--;
+                    }
+                    goto cleanup;
+                }
+
+
+                /* XXX: Use the default, as storage pool have not supported
+                 * 'transport' and 'socket' yet.
+                 */
+                hosts[n].transport = VIR_DOMAIN_DISK_PROTO_TRANS_TCP;
+                hosts[n].socket = NULL;
+            }
+
+            disk->hosts = hosts;
+            disk->nhosts = pool->def->source.nhost;
+            disk->src = strdup(vol->name);
+            break;
+       }
 
         virStoragePoolObjUnlock(pool);
         pool = NULL;
-- 
1.7.7.6


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