[PATCH][RESEND] processMonitorEOFEvent:fix delet Domain object about the new VM in processMonitorEOFEvent()

Yi Wang posted 1 patch 2 years ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20220426085803.2879-1-wang.yi59@zte.com.cn
src/qemu/qemu_driver.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
[PATCH][RESEND] processMonitorEOFEvent:fix delet Domain object about the new VM in processMonitorEOFEvent()
Posted by Yi Wang 2 years ago
From: 王鹏钧10288409 <10288409@zte.intra@LIN-184C297BAE7.zte.com.cn>

Virsh shutdown is executed firstly, virsh destroy is executed later,
and VM is recreated again. In this process, due to will delet Domain
object about the new VM in processMonitorEOFEvent(), which
virDomainObjListRemove is called to remove objlist, the new VM
cannot be found through virsh list command and qemu process is still
running. Therefore, add virDomainObjListFindByName function checks
to avoid delet Domain object about the new VM in objlist.

This process chart of problem is as follows

         shutdown           |      destroy     |       create
============================+==================+===================
              qemuMonitorIO |                  |
qemuProcessHandleMonitorEOF |                  |
                            | virDomainDestroy |
                            |  qemuProcessStop |
                            |                  | qemuDomainCreateXML
                            |                  |     qemuProcessInit
     processMonitorEOFEvent |                  |
   qemuDomainRemoveInactive |                  |
                            |                  |   qemuProcessLaunch

Signed-off-by: Wang PengJun <wang.pengjun1@zte.com.cn>
Signed-off-by: Yi Wang <wang.yi59@zte.com.cn>
---
 src/qemu/qemu_driver.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ee0963c30d..a504f89724 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4024,6 +4024,7 @@ processMonitorEOFEvent(virQEMUDriver *driver,
     const char *auditReason = "shutdown";
     unsigned int stopFlags = 0;
     virObjectEvent *event = NULL;
+    virDomainObj *obj;
 
     if (qemuProcessBeginStopJob(driver, vm, VIR_JOB_DESTROY, true) < 0)
         return;
@@ -4055,7 +4056,12 @@ processMonitorEOFEvent(virQEMUDriver *driver,
     virObjectEventStateQueue(driver->domainEventState, event);
 
  endjob:
-    qemuDomainRemoveInactive(driver, vm);
+    virObjectUnlock(vm);
+    obj = virDomainObjListFindByName(driver->domains, vm->def->name);
+    if (vm == obj)
+        qemuDomainRemoveInactive(driver, vm);
+    virDomainObjEndAPI(&obj);
+    virObjectLock(vm);
     qemuDomainObjEndJob(vm);
 }
 
-- 
2.27.0