[PATCH] qemuDomainCleanupRun: Actually run cleanup callbacks in reverse order

Michal Privoznik posted 1 patch 3 years, 11 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/8afb786b198c7648cb3ad46928374c6f2556c05e.1588754687.git.mprivozn@redhat.com
src/qemu/qemu_domain.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
[PATCH] qemuDomainCleanupRun: Actually run cleanup callbacks in reverse order
Posted by Michal Privoznik 3 years, 11 months ago
We have a framework to register cleanup callbacks that are run
when a domain is shut down. The idea is to run callbacks in
reverse order than they were registered. However, looking at the
code this is not the case. Fortunately, this framework is used to
register a single callback and a single callback only -
qemuMigrationDstPrepareCleanup() - therefore there was no problem
just yet.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_domain.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 9c629c31a3..7c71b797bc 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8032,18 +8032,14 @@ qemuDomainCleanupRun(virQEMUDriverPtr driver,
                      virDomainObjPtr vm)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    size_t i;
 
     VIR_DEBUG("driver=%p, vm=%s", driver, vm->def->name);
 
     /* run cleanup callbacks in reverse order */
-    for (i = 0; i < priv->ncleanupCallbacks; i++) {
-        if (priv->cleanupCallbacks[priv->ncleanupCallbacks - (i + 1)])
-            priv->cleanupCallbacks[i](driver, vm);
-    }
+    while (priv->ncleanupCallbacks)
+        priv->cleanupCallbacks[--priv->ncleanupCallbacks](driver, vm);
 
     VIR_FREE(priv->cleanupCallbacks);
-    priv->ncleanupCallbacks = 0;
     priv->ncleanupCallbacks_max = 0;
 }
 
-- 
2.26.2

Re: [PATCH] qemuDomainCleanupRun: Actually run cleanup callbacks in reverse order
Posted by Ján Tomko 3 years, 11 months ago
On a Wednesday in 2020, Michal Privoznik wrote:
>We have a framework to register cleanup callbacks that are run
>when a domain is shut down. The idea is to run callbacks in
>reverse order than they were registered. However, looking at the
>code this is not the case. Fortunately, this framework is used to
>register a single callback and a single callback only -
>qemuMigrationDstPrepareCleanup() - therefore there was no problem
>just yet.
>
>Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
>---
> src/qemu/qemu_domain.c | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano