[libvirt] [PATCH 3/4] test_driver: implement virDomainFSThaw

Ilias Stamatis posted 4 patches 6 years, 7 months ago
There is a newer version of this series
[libvirt] [PATCH 3/4] test_driver: implement virDomainFSThaw
Posted by Ilias Stamatis 6 years, 7 months ago
Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
---
 src/test/test_driver.c | 66 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 8c25c679a5..097720bb0a 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3496,6 +3496,71 @@ testDomainFSFreeze(virDomainPtr dom,
 }


+static int
+testDomainFSThaw(virDomainPtr dom,
+                   const char **mountpoints,
+                   unsigned int nmountpoints,
+                   unsigned int flags)
+{
+    virDomainObjPtr vm;
+    testDomainObjPrivatePtr priv;
+    size_t i;
+    int slash = 0, slash_boot = 0;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    if (!(vm = testDomObjFromDomain(dom)))
+        goto cleanup;
+
+    if (virDomainObjCheckActive(vm) < 0)
+        goto cleanup;
+
+    priv = vm->privateData;
+
+    if (nmountpoints == 0) {
+        ret = priv->frozen[0] + priv->frozen[1];
+        priv->frozen[0] = priv->frozen[1] = false;
+    } else {
+        for (i = 0; i < nmountpoints; i++) {
+            if (STREQ(mountpoints[i], "/")) {
+                if (priv->frozen[0]) {
+                    slash = 1;
+                } else {
+                    virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                                   _("mount point is not frozen: /"));
+                    goto cleanup;
+                }
+            } else if (STREQ(mountpoints[i], "/boot")) {
+                if (priv->frozen[1]) {
+                    slash_boot = 1;
+                } else {
+                    virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                                   _("mount point is not frozen: /boot"));
+                    goto cleanup;
+                }
+            } else {
+                virReportError(VIR_ERR_OPERATION_INVALID,
+                               _("mount point not found: %s"),
+                               mountpoints[i]);
+                goto cleanup;
+            }
+        }
+
+        if (slash)
+            priv->frozen[0] = false;
+        if (slash_boot)
+            priv->frozen[1] = false;
+
+        ret = slash + slash_boot;
+    }
+
+ cleanup:
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
+
 static int testDomainGetAutostart(virDomainPtr domain,
                                   int *autostart)
 {
@@ -7739,6 +7804,7 @@ static virHypervisorDriver testHypervisorDriver = {
     .domainUndefine = testDomainUndefine, /* 0.1.11 */
     .domainUndefineFlags = testDomainUndefineFlags, /* 0.9.4 */
     .domainFSFreeze = testDomainFSFreeze, /* 5.6.0 */
+    .domainFSThaw = testDomainFSThaw, /* 5.6.0 */
     .domainGetAutostart = testDomainGetAutostart, /* 0.3.2 */
     .domainSetAutostart = testDomainSetAutostart, /* 0.3.2 */
     .domainGetDiskErrors = testDomainGetDiskErrors, /* 5.4.0 */
--
2.22.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/4] test_driver: implement virDomainFSThaw
Posted by Erik Skultety 6 years, 6 months ago
On Tue, Jul 09, 2019 at 09:23:23PM +0200, Ilias Stamatis wrote:
> Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
> ---
>  src/test/test_driver.c | 66 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 66 insertions(+)
>
> diff --git a/src/test/test_driver.c b/src/test/test_driver.c
> index 8c25c679a5..097720bb0a 100644
> --- a/src/test/test_driver.c
> +++ b/src/test/test_driver.c
> @@ -3496,6 +3496,71 @@ testDomainFSFreeze(virDomainPtr dom,
>  }
>
>
> +static int
> +testDomainFSThaw(virDomainPtr dom,
> +                   const char **mountpoints,
> +                   unsigned int nmountpoints,
> +                   unsigned int flags)
> +{
> +    virDomainObjPtr vm;
> +    testDomainObjPrivatePtr priv;
> +    size_t i;
> +    int slash = 0, slash_boot = 0;

One declaration per line...

> +    int ret = -1;
> +
> +    virCheckFlags(0, -1);
> +
> +    if (!(vm = testDomObjFromDomain(dom)))
> +        goto cleanup;
> +
> +    if (virDomainObjCheckActive(vm) < 0)
> +        goto cleanup;
> +
> +    priv = vm->privateData;
> +
> +    if (nmountpoints == 0) {
> +        ret = priv->frozen[0] + priv->frozen[1];
> +        priv->frozen[0] = priv->frozen[1] = false;
> +    } else {
> +        for (i = 0; i < nmountpoints; i++) {
> +            if (STREQ(mountpoints[i], "/")) {
> +                if (priv->frozen[0]) {
> +                    slash = 1;
> +                } else {
> +                    virReportError(VIR_ERR_OPERATION_INVALID, "%s",
> +                                   _("mount point is not frozen: /"));
> +                    goto cleanup;
> +                }

I don't think ^this is an error per se, instead we can silently ignore the
mountpoint if it's already been thawed prior to calling this API.

> +            } else if (STREQ(mountpoints[i], "/boot")) {
> +                if (priv->frozen[1]) {
> +                    slash_boot = 1;
> +                } else {
> +                    virReportError(VIR_ERR_OPERATION_INVALID, "%s",
> +                                   _("mount point is not frozen: /boot"));
> +                    goto cleanup;
> +                }

Same here...

> +            } else {
> +                virReportError(VIR_ERR_OPERATION_INVALID,
> +                               _("mount point not found: %s"),
> +                               mountpoints[i]);
> +                goto cleanup;
> +            }
> +        }
> +
> +        if (slash)
> +            priv->frozen[0] = false;
> +        if (slash_boot)
> +            priv->frozen[1] = false;
> +
> +        ret = slash + slash_boot;
> +    }

Consider the alternative implementation I hinted in comments to 2/4

Erik

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