From nobody Sun May 12 15:58:19 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 1700471391252604.1234993397626; Mon, 20 Nov 2023 01:09:51 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2BC58176E; Mon, 20 Nov 2023 04:09:50 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 823381898; Mon, 20 Nov 2023 04:03:04 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id A766417F1; Sat, 18 Nov 2023 10:37:49 -0500 (EST) Received: from chinatelecom.cn (smtpnm6-12.21cn.com [182.42.119.59]) by lists.libvirt.org (Postfix) with ESMTP id 6942017EE for ; Sat, 18 Nov 2023 10:37:46 -0500 (EST) Received: from clientip-182.148.59.130 (unknown [192.168.138.117]) by chinatelecom.cn (HERMES) with SMTP id EBF46110001AF; Sat, 18 Nov 2023 23:29:15 +0800 (CST) Received: from ([182.148.59.130]) by gateway-ssl-dep-6799f67c56-xpxbc with ESMTP id bd4f4f20975241f3baeb2d20a0bf40a9 for devel@lists.libvirt.org; Sat, 18 Nov 2023 23:29:17 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 X-Greylist: delayed 502 seconds by postgrey-1.37 at lists.libvirt.org; Sat, 18 Nov 2023 10:37:46 EST HMM_SOURCE_IP: 192.168.138.117:44657.358839575 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +tugy@chinatelecom.cn X-Transaction-ID: bd4f4f20975241f3baeb2d20a0bf40a9 X-Real-From: tugy@chinatelecom.cn X-Receive-IP: 182.148.59.130 X-MEDUSA-Status: 0 Sender: tugy@chinatelecom.cn Message-ID: Date: Sat, 18 Nov 2023 23:29:15 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: devel@lists.libvirt.org From: Guoyi Tu Subject: [PATCH] qemu_driver: Don't handle the EOF event if monitor changed 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: 7JRLH4RYKL4ZL3QZK7P2JCATERBS6VJF X-Message-ID-Hash: 7JRLH4RYKL4ZL3QZK7P2JCATERBS6VJF X-Mailman-Approved-At: Mon, 20 Nov 2023 09:02:31 -0500 CC: tugy@chinatelecom.cn, =?UTF-8?B?6YKT6bmP56iL?= 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: Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1700471394343100001 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 monitor object matches 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 --- 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 ae19ce884b..bc80afdfac 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11500,7 +11500,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; @@ -11514,6 +11513,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 d00d2a27c6..57acafb48b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3854,7 +3854,8 @@ processJobStatusChangeEvent(virDomainObj *vm, static void processMonitorEOFEvent(virQEMUDriver *driver, - virDomainObj *vm) + virDomainObj *vm, + qemuMonitor *mon) { 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; + if (priv->mon !=3D mon) { + VIR_DEBUG("Domain %p '%s' has been shutdown, ignoring EOF", + vm, vm->def->name); + return; + } + if (qemuProcessBeginStopJob(vm, VIR_JOB_DESTROY, true) < 0) return; @@ -4082,7 +4089,7 @@ static void qemuProcessEventHandler(void *data,=20 void *opaque) processJobStatusChangeEvent(vm, processEvent->data); break; case QEMU_PROCESS_EVENT_MONITOR_EOF: - processMonitorEOFEvent(driver, vm); + processMonitorEOFEvent(driver, vm, processEvent->data); break; case QEMU_PROCESS_EVENT_PR_DISCONNECT: processPRDisconnectEvent(vm); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b9267d8699..4de6e5c234 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -316,7 +316,7 @@ qemuProcessHandleMonitorEOF(qemuMonitor *mon, } qemuProcessEventSubmit(vm, QEMU_PROCESS_EVENT_MONITOR_EOF, - 0, 0, NULL); + 0, 0, priv->mon); /* 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