From: 王鹏钧10288409 <10288409@zte.in...@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.pengj...@zte.com.cn>
Signed-off-by: Yi Wang <wang.y...@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

Reply via email to