[libvirt PATCH] conf: Add support for GlusterFS volumes as disk

Vincent Vanlaer posted 1 patch 3 years, 7 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20200903182847.1369777-1-libvirt@volkihar.be
src/conf/domain_conf.c | 32 +++++++++++++++++++++++++++++++-
1 file changed, 31 insertions(+), 1 deletion(-)
[libvirt PATCH] conf: Add support for GlusterFS volumes as disk
Posted by Vincent Vanlaer 3 years, 7 months ago
While libvirt has support for GlusterFS pools and volumes, they cannot
be added to a domain. This commit adds the necessary translation between
the pool definition and the disk definition, allowing volumes in a domain
to be backed by a gluster pool.

Signed-off-by: Vincent Vanlaer <libvirt@volkihar.be>
---
 src/conf/domain_conf.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 72ac4f4191..c872d02200 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -32620,6 +32620,32 @@ virDomainDiskTranslateISCSIDirect(virStorageSourcePtr src,
 }
 
 
+static int
+virDomainDiskTranslateGluster(virStorageSourcePtr src,
+                              virStoragePoolDefPtr pooldef)
+{
+    size_t i;
+
+    src->srcpool->actualtype = VIR_STORAGE_TYPE_NETWORK;
+    src->protocol = VIR_STORAGE_NET_PROTOCOL_GLUSTER;
+
+    src->nhosts = pooldef->source.nhost;
+    src->hosts = g_new0(virStorageNetHostDef, src->nhosts);
+
+    for (i = 0; i < src->nhosts; i++) {
+        src->hosts[i].socket = NULL;
+        src->hosts[i].transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
+        src->hosts[i].name = g_strdup(pooldef->source.hosts[i].name);
+        src->hosts[i].port = pooldef->source.hosts[i].port;
+    }
+
+    src->volume = g_strdup(pooldef->source.name);
+    src->path = g_strdup_printf("%s/%s", pooldef->source.dir, src->srcpool->volume);
+
+    return 0;
+}
+
+
 static int
 virDomainStorageSourceTranslateSourcePool(virStorageSourcePtr src,
                                           virConnectPtr conn)
@@ -32736,10 +32762,14 @@ virDomainStorageSourceTranslateSourcePool(virStorageSourcePtr src,
        }
        break;
 
+    case VIR_STORAGE_POOL_GLUSTER:
+       if (virDomainDiskTranslateGluster(src, pooldef) < 0)
+           return -1;
+       break;
+
     case VIR_STORAGE_POOL_MPATH:
     case VIR_STORAGE_POOL_RBD:
     case VIR_STORAGE_POOL_SHEEPDOG:
-    case VIR_STORAGE_POOL_GLUSTER:
     case VIR_STORAGE_POOL_LAST:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("using '%s' pools for backing 'volume' disks "
-- 
2.28.0


Re: [libvirt PATCH] conf: Add support for GlusterFS volumes as disk
Posted by Peter Krempa 3 years, 7 months ago
On Thu, Sep 03, 2020 at 20:28:47 +0200, Vincent Vanlaer wrote:
> While libvirt has support for GlusterFS pools and volumes, they cannot
> be added to a domain. This commit adds the necessary translation between
> the pool definition and the disk definition, allowing volumes in a domain
> to be backed by a gluster pool.
> 
> Signed-off-by: Vincent Vanlaer <libvirt@volkihar.be>
> ---
>  src/conf/domain_conf.c | 32 +++++++++++++++++++++++++++++++-
>  1 file changed, 31 insertions(+), 1 deletion(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 72ac4f4191..c872d02200 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -32620,6 +32620,32 @@ virDomainDiskTranslateISCSIDirect(virStorageSourcePtr src,
>  }
>  
>  
> +static int
> +virDomainDiskTranslateGluster(virStorageSourcePtr src,
> +                              virStoragePoolDefPtr pooldef)
> +{
> +    size_t i;
> +
> +    src->srcpool->actualtype = VIR_STORAGE_TYPE_NETWORK;
> +    src->protocol = VIR_STORAGE_NET_PROTOCOL_GLUSTER;
> +
> +    src->nhosts = pooldef->source.nhost;
> +    src->hosts = g_new0(virStorageNetHostDef, src->nhosts);
> +
> +    for (i = 0; i < src->nhosts; i++) {
> +        src->hosts[i].socket = NULL;

This is not required as g_new0 initializes memory to 0.

> +        src->hosts[i].transport = VIR_STORAGE_NET_HOST_TRANS_TCP;
> +        src->hosts[i].name = g_strdup(pooldef->source.hosts[i].name);
> +        src->hosts[i].port = pooldef->source.hosts[i].port;
> +    }
> +
> +    src->volume = g_strdup(pooldef->source.name);
> +    src->path = g_strdup_printf("%s/%s", pooldef->source.dir, src->srcpool->volume);

The source dir seems to be '/' in case when it's not configured, which
would format a wrong path of "//blah.img" if you don't configure it
properly, so you'll probably need to do some special-casing here.