[PATCH 5/8] qemu_domain: Add qemuDomainSetPrivateMemPath()

Martin Kletzander posted 8 patches 1 year, 4 months ago
There is a newer version of this series
[PATCH 5/8] qemu_domain: Add qemuDomainSetPrivateMemPath()
Posted by Martin Kletzander 1 year, 4 months ago
This function sets the memoryBackingDir in qemuDomainObjPrivate struct
so that it is remembered for the whole lifetime of a domain.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
---
 src/qemu/qemu_domain.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index d5c0c4b56834..577c53050651 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1735,6 +1735,27 @@ qemuDomainSecretPrepare(virQEMUDriver *driver,
 }
 
 
+static void
+qemuDomainSetPrivateMemPath(qemuDomainObjPrivate *priv,
+                            virQEMUDriverConfig *cfg,
+                            const char *embedded_root,
+                            const char *short_name)
+{
+    if (priv->memoryBackingDir)
+        return;
+
+    if (embedded_root && !STRPREFIX(cfg->memoryBackingDir, embedded_root)) {
+        g_autofree char *hash = virDomainDriverGenerateRootHash("qemu",
+                                                                embedded_root);
+        priv->memoryBackingDir = g_strdup_printf("%s/%s-%s",
+                                                  cfg->memoryBackingDir,
+                                                  hash, short_name);
+    } else {
+        priv->memoryBackingDir = g_strdup_printf("%s/%s", cfg->memoryBackingDir, short_name);
+    }
+}
+
+
 /* This is the old way of setting up per-domain directories */
 static void
 qemuDomainSetPrivatePathsOld(virQEMUDriver *driver,
-- 
2.46.0
Re: [PATCH 5/8] qemu_domain: Add qemuDomainSetPrivateMemPath()
Posted by Michal Prívozník 1 year, 4 months ago
On 9/18/24 15:42, Martin Kletzander wrote:
> This function sets the memoryBackingDir in qemuDomainObjPrivate struct
> so that it is remembered for the whole lifetime of a domain.
> 
> Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
> ---
>  src/qemu/qemu_domain.c | 21 +++++++++++++++++++++
>  1 file changed, 21 insertions(+)
> 
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index d5c0c4b56834..577c53050651 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -1735,6 +1735,27 @@ qemuDomainSecretPrepare(virQEMUDriver *driver,
>  }
>  
>  
> +static void
> +qemuDomainSetPrivateMemPath(qemuDomainObjPrivate *priv,
> +                            virQEMUDriverConfig *cfg,
> +                            const char *embedded_root,
> +                            const char *short_name)
> +{
> +    if (priv->memoryBackingDir)
> +        return;
> +
> +    if (embedded_root && !STRPREFIX(cfg->memoryBackingDir, embedded_root)) {
> +        g_autofree char *hash = virDomainDriverGenerateRootHash("qemu",
> +                                                                embedded_root);
> +        priv->memoryBackingDir = g_strdup_printf("%s/%s-%s",
> +                                                  cfg->memoryBackingDir,
> +                                                  hash, short_name);
> +    } else {
> +        priv->memoryBackingDir = g_strdup_printf("%s/%s", cfg->memoryBackingDir, short_name);

Long line.

> +    }
> +}
> +

You can't just introduce a static function and not use it - gcc
complains about unused function.

Also, this looks like an almost verbatim copy of
qemuGetMemoryBackingDomainPath() - so maybe just rename it or something?

Alternatively, turn this into a thin wrapper over
qemuGetMemoryBackingDomainPath() for the time being and dissolve it in
the very last patch:


static void
qemuDomainSetPrivateMemPath()
{
  qemuGetMemoryBackingDomainPath(priv, cfg,
                       embedded_root,
                       &priv->memoryBackingDir)
}

> +
>  /* This is the old way of setting up per-domain directories */
>  static void
>  qemuDomainSetPrivatePathsOld(virQEMUDriver *driver,

Michal