From nobody Sat May 18 21:00:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1701955284351736.7864503327554; Thu, 7 Dec 2023 05:21:24 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 153361823; Thu, 7 Dec 2023 08:21:23 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3117A1784; Thu, 7 Dec 2023 08:20:04 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4A59A17EF; Thu, 7 Dec 2023 07:55:07 -0500 (EST) Received: from chinatelecom.cn (smtpnm6-09.21cn.com [182.42.152.55]) by lists.libvirt.org (Postfix) with ESMTP id 917D417D7 for ; Thu, 7 Dec 2023 07:55:05 -0500 (EST) Received: from clientip-139.200.108.9 (unknown [192.168.138.117]) by chinatelecom.cn (HERMES) with SMTP id BCF99111070A1; Thu, 7 Dec 2023 20:54:47 +0800 (CST) Received: from ([139.200.108.9]) by gateway-ssl-dep-6799f67c56-xpxbc with ESMTP id df45b8771bed4234a50a2b1eb25cc8f0 for berrange@redhat.com; Thu, 07 Dec 2023 20:54:51 CST X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=FORGED_SPF_HELO, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 HMM_SOURCE_IP: 192.168.138.117:6200.1922835026 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +tugy@chinatelecom.cn X-Transaction-ID: df45b8771bed4234a50a2b1eb25cc8f0 X-Real-From: tugy@chinatelecom.cn X-Receive-IP: 139.200.108.9 X-MEDUSA-Status: 0 Sender: tugy@chinatelecom.cn From: tugy@chinatelecom.cn To: berrange@redhat.com, jtomko@redhat.com, devel@lists.libvirt.org Subject: [PATCH v2] qemu_driver: Don't handle the EOF event if vm get restarted Date: Thu, 7 Dec 2023 20:52:39 +0800 Message-Id: <0a411b2b49eaed61581b5e41af0acea7c199f169.1701953403.git.tugy@chinatelecom.cn> X-Mailer: git-send-email 2.17.1 X-MailFrom: tugy@chinatelecom.cn X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 Message-ID-Hash: UUVP2PSNUC72SCOFUFHXWQXS4VVRZ2YH X-Message-ID-Hash: UUVP2PSNUC72SCOFUFHXWQXS4VVRZ2YH X-Mailman-Approved-At: Thu, 07 Dec 2023 13:20:00 -0500 CC: tugy@chinatelecom.cn, dengpc12@chinatelecom.cn X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1701955286112100001 From: Guoyi Tu Currently, libvirt creates a thread pool with only on thread to handle all qemu monitor events for virtual machines, In the cases that if the thread gets stuck while handling a monitor EOF event, such as unable to kill the virtual machine process or release resources, the events of other virtual machine will be also blocked, which will lead to the abnormal behavior of other virtual machines. For instance, when another virtual machine completes a shutdown operation and the monitor EOF event has been queued but remains unprocessed, we immediately destroy and start the virtual machine again, at a later time when EOF event get processed, the processMonitorEOFEvent() will kill the virtual machine that just started. To address this issue, in the processMonitorEOFEvent(), we check whether the current virtual machine's id is equal to the the one at the time the event was generated. If they do not match, we immediately return. Signed-off-by: Guoyi Tu Signed-off-by: dengpengcheng Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_driver.c | 11 +++++++++-- src/qemu/qemu_process.c | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 953808fcfe..435ee621df 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11470,7 +11470,6 @@ qemuProcessEventFree(struct qemuProcessEvent *event) case QEMU_PROCESS_EVENT_NETDEV_STREAM_DISCONNECTED: case QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED: case QEMU_PROCESS_EVENT_SERIAL_CHANGED: - case QEMU_PROCESS_EVENT_MONITOR_EOF: case QEMU_PROCESS_EVENT_GUEST_CRASHLOADED: g_free(event->data); break; @@ -11484,6 +11483,7 @@ qemuProcessEventFree(struct qemuProcessEvent *event) case QEMU_PROCESS_EVENT_UNATTENDED_MIGRATION: case QEMU_PROCESS_EVENT_RESET: case QEMU_PROCESS_EVENT_NBDKIT_EXITED: + case QEMU_PROCESS_EVENT_MONITOR_EOF: case QEMU_PROCESS_EVENT_LAST: break; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 64afae6450..cfc5b79657 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3854,7 +3854,8 @@ processJobStatusChangeEvent(virDomainObj *vm, =20 static void processMonitorEOFEvent(virQEMUDriver *driver, - virDomainObj *vm) + virDomainObj *vm, + int domid) { qemuDomainObjPrivate *priv =3D vm->privateData; int eventReason =3D VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN; @@ -3863,6 +3864,12 @@ processMonitorEOFEvent(virQEMUDriver *driver, unsigned int stopFlags =3D 0; virObjectEvent *event =3D NULL; =20 + if (vm->def->id !=3D domid) { + VIR_ERROR("Domain %s was restarted, ignoring EOF", + vm->def->name); + return; + } + if (qemuProcessBeginStopJob(vm, VIR_JOB_DESTROY, true) < 0) return; =20 @@ -4082,7 +4089,7 @@ static void qemuProcessEventHandler(void *data, void = *opaque) processJobStatusChangeEvent(vm, processEvent->data); break; case QEMU_PROCESS_EVENT_MONITOR_EOF: - processMonitorEOFEvent(driver, vm); + processMonitorEOFEvent(driver, vm, GPOINTER_TO_INT(processEvent->d= ata)); break; case QEMU_PROCESS_EVENT_PR_DISCONNECT: processPRDisconnectEvent(vm); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index fc05b4b24f..696d526a5d 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -316,7 +316,7 @@ qemuProcessHandleMonitorEOF(qemuMonitor *mon, } =20 qemuProcessEventSubmit(vm, QEMU_PROCESS_EVENT_MONITOR_EOF, - 0, 0, NULL); + 0, 0, GINT_TO_POINTER(vm->def->id)); =20 /* We don't want this EOF handler to be called over and over while the * thread is waiting for a job. --=20 2.17.1 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org