From nobody Mon Sep 16 19:24:00 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 17207025501751010.9323311967911; Thu, 11 Jul 2024 05:55:50 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id CB6DBD8F; Thu, 11 Jul 2024 08:55:48 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id B6012E98; Thu, 11 Jul 2024 08:55:28 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id CA737D8F; Thu, 11 Jul 2024 08:55:25 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 4BFAFD83 for ; Thu, 11 Jul 2024 08:55:25 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-572-z3lmIewqNlSXMG1lsebJWw-1; Thu, 11 Jul 2024 08:55:23 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 84F0A1956080 for ; Thu, 11 Jul 2024 12:55:22 +0000 (UTC) Received: from orkuz (unknown [10.43.3.115]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 01C9519560AA for ; Thu, 11 Jul 2024 12:55:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720702525; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pFjXaC5tLKoUIvsHT1BDPacDu/DryC7fD36pERdisjM=; b=ZcQ5Ci4kGrOpyibi/VRrTMB68m4qQ42fdJmI4J3K5uWkN3tHBKG/37wBPwmUHh+HG8SGWJ GIelnWE3Ae4gN0YgSijMJB199a2iKL/Z0O+kZeepztkHxAkjd+xArlzGwTF3Oppccm8wxD nHj1oEOZbY3cvxkMEvig3s2PT8E2Uu8= X-MC-Unique: z3lmIewqNlSXMG1lsebJWw-1 From: Jiri Denemark To: devel@lists.libvirt.org Subject: [PATCH] qemu: Don't leave beingDestroyed=true on inactive domain Date: Thu, 11 Jul 2024 14:55:17 +0200 Message-ID: <608dd0249bb47c05f6b92330d62a0f784f0fcbe1.1720702517.git.jdenemar@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 64BAW5DXT46X7KEQP3MKMRKPVBZPOENC X-Message-ID-Hash: 64BAW5DXT46X7KEQP3MKMRKPVBZPOENC X-MailFrom: jdenemar@redhat.com 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; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header 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: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1720702551985116600 Content-Type: text/plain; charset="utf-8" Recent commit v10.4.0-87-gd9935a5c4f made a reasonable change to only reset beingDestroyed back to false when vm->def->id is reset to make sure other code can detect a domain is (about to become) inactive. It even added a comment saying any caller of qemuProcessBeginStopJob is supposed to call qemuProcessStop to clear beingDestroyed. But not every caller really does so because they first call qemuProcessBeginStopJob and then check whether a domain is still running. If not the qemuProcessStop call is skipped leaving beingDestroyed=3Dtrue. In case of a persistent domain this may block incoming migrations of such domain as the migration code would think the domain died unexpectedly (even though it's still running). The qemuProcessBeginStopJob function is a wrapper around virDomainObjBeginJob, but virDomainObjEndJob was used directly for cleanup. This patch introduces a new qemuProcessEndStopJob wrapper around virDomainObjEndJob to properly undo everything qemuProcessBeginStopJob did. https://issues.redhat.com/browse/RHEL-43309 Signed-off-by: Jiri Denemark Reviewed-by: Peter Krempa --- src/qemu/qemu_driver.c | 4 ++-- src/qemu/qemu_process.c | 20 ++++++++++++++++---- src/qemu/qemu_process.h | 1 + 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f898d85667..9f3013e231 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -2102,7 +2102,7 @@ qemuDomainDestroyFlags(virDomainPtr dom, endjob: if (ret =3D=3D 0) qemuDomainRemoveInactive(driver, vm, 0, false); - virDomainObjEndJob(vm); + qemuProcessEndStopJob(vm); =20 cleanup: virDomainObjEndAPI(&vm); @@ -3888,7 +3888,7 @@ processMonitorEOFEvent(virQEMUDriver *driver, =20 endjob: qemuDomainRemoveInactive(driver, vm, 0, false); - virDomainObjEndJob(vm); + qemuProcessEndStopJob(vm); } =20 =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7cbe521a6e..25dfd04272 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8421,7 +8421,8 @@ qemuProcessKill(virDomainObj *vm, unsigned int flags) * qemuProcessBeginStopJob: * * Stop all current jobs by killing the domain and start a new one for - * qemuProcessStop. + * qemuProcessStop. The caller has to make sure qemuProcessEndStopJob is + * called to properly cleanup the job. */ int qemuProcessBeginStopJob(virDomainObj *vm, @@ -8448,8 +8449,9 @@ qemuProcessBeginStopJob(virDomainObj *vm, goto error; =20 /* priv->beingDestroyed is deliberately left set to 'true' here. Caller - * is supposed to call qemuProcessStop, which will reset it after - * 'vm->def->id' is set to -1 */ + * is supposed to call qemuProcessStop (which will reset it after + * 'vm->def->id' is set to -1) and/or qemuProcessEndStopJob to do prop= er + * cleanup. */ return 0; =20 error: @@ -8458,6 +8460,16 @@ qemuProcessBeginStopJob(virDomainObj *vm, } =20 =20 +void +qemuProcessEndStopJob(virDomainObj *vm) +{ + if (!virDomainObjIsActive(vm)) + QEMU_DOMAIN_PRIVATE(vm)->beingDestroyed =3D false; + + virDomainObjEndJob(vm); +} + + void qemuProcessStop(virQEMUDriver *driver, virDomainObj *vm, virDomainShutoffReason reason, @@ -8800,7 +8812,7 @@ qemuProcessAutoDestroy(virDomainObj *dom, =20 qemuDomainRemoveInactive(driver, dom, 0, false); =20 - virDomainObjEndJob(dom); + qemuProcessEndStopJob(dom); =20 virObjectEventStateQueue(driver->domainEventState, event); } diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index c1ea949215..cb67bfcd2d 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -169,6 +169,7 @@ typedef enum { int qemuProcessBeginStopJob(virDomainObj *vm, virDomainJob job, bool forceKill); +void qemuProcessEndStopJob(virDomainObj *vm); void qemuProcessStop(virQEMUDriver *driver, virDomainObj *vm, virDomainShutoffReason reason, --=20 2.45.2