[PATCH 1/2] qemu: refresh state after reset

Kristina Hanicova posted 2 patches 3 years ago
There is a newer version of this series
[PATCH 1/2] qemu: refresh state after reset
Posted by Kristina Hanicova 3 years ago
Domain state may change during the reset and qemu does not always
send events about it.  In case it happens, the state would be
inconsistent with the internal state of qemu which could cause
additional problems.  The solution is to refresh state after a
successful reset to query qemu about the current domain state.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1824722

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
---
 src/qemu/qemu_driver.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ff5a743716..b2060ee843 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2000,6 +2000,7 @@ qemuDomainReset(virDomainPtr dom, unsigned int flags)
     int ret = -1;
     qemuDomainObjPrivate *priv;
     virDomainState state;
+    virQEMUDriver *driver = dom->conn->privateData;
 
     virCheckFlags(0, -1);
 
@@ -2023,8 +2024,11 @@ qemuDomainReset(virDomainPtr dom, unsigned int flags)
     priv->fakeReboot = false;
 
     state = virDomainObjGetState(vm, NULL);
-    if (state == VIR_DOMAIN_CRASHED)
+    if (state == VIR_DOMAIN_CRASHED) {
         virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_CRASHED);
+    } else if (qemuProcessRefreshState(driver, vm, VIR_ASYNC_JOB_NONE) < 0) {
+        goto cleanup;
+    }
 
  endjob:
     virDomainObjEndJob(vm);
-- 
2.38.1
Re: [PATCH 1/2] qemu: refresh state after reset
Posted by Martin Kletzander 3 years ago
On Wed, Nov 23, 2022 at 02:31:16PM +0100, Kristina Hanicova wrote:
>Domain state may change during the reset and qemu does not always
>send events about it.  In case it happens, the state would be
>inconsistent with the internal state of qemu which could cause
>additional problems.  The solution is to refresh state after a
>successful reset to query qemu about the current domain state.
>

I had to look in the BZ and RefreshState to figure out you did not
actually mean the state (paused, running, crashed) but rather the
internal state of the domain.

>Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1824722
>
>Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
>---
> src/qemu/qemu_driver.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
>diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
>index ff5a743716..b2060ee843 100644
>--- a/src/qemu/qemu_driver.c
>+++ b/src/qemu/qemu_driver.c
>@@ -2000,6 +2000,7 @@ qemuDomainReset(virDomainPtr dom, unsigned int flags)
>     int ret = -1;
>     qemuDomainObjPrivate *priv;
>     virDomainState state;
>+    virQEMUDriver *driver = dom->conn->privateData;
>
>     virCheckFlags(0, -1);
>
>@@ -2023,8 +2024,11 @@ qemuDomainReset(virDomainPtr dom, unsigned int flags)
>     priv->fakeReboot = false;
>
>     state = virDomainObjGetState(vm, NULL);
>-    if (state == VIR_DOMAIN_CRASHED)
>+    if (state == VIR_DOMAIN_CRASHED) {
>         virDomainObjSetState(vm, VIR_DOMAIN_PAUSED, VIR_DOMAIN_PAUSED_CRASHED);
>+    } else if (qemuProcessRefreshState(driver, vm, VIR_ASYNC_JOB_NONE) < 0) {
>+        goto cleanup;

You need to goto endjob here, otherwise the job will not end.  Could we
not call this unconditionally, even for the crashed domain?  Especially
when we do not refresh the state when resuming the domain afterwards?

>+    }
>
>  endjob:
>     virDomainObjEndJob(vm);
>-- 
>2.38.1
>