From nobody Fri Oct 18 06:24:44 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 1718291555861624.2784250052547; Thu, 13 Jun 2024 08:12:35 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id CCCC2E1F; Thu, 13 Jun 2024 11:12:34 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 558A011E7; Thu, 13 Jun 2024 11:11:55 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2CD41A79; Thu, 13 Jun 2024 11:11:51 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 B27F1A64 for ; Thu, 13 Jun 2024 11:11:50 -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-449-O9_i2QtwODugMBt2sfyj4Q-1; Thu, 13 Jun 2024 11:11:49 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 0DFE819560AD for ; Thu, 13 Jun 2024 15:11:48 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2E6E1195605E for ; Thu, 13 Jun 2024 15:11:46 +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=3.0 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,RCVD_IN_SBL_CSS,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718291510; 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: in-reply-to:in-reply-to:references:references; bh=tJ47AAuHsbuXNBRcWbc8ulD+biSDFiqTy5c87d/TNWQ=; b=iY/4bODTuqpRL5DZoEF9ZGgLxtFnhe/h7ytDv5FZwzpRUFigJr/Cqqt5nTxFlX2a3rr/7e L6dGfwt4ecaLqrC5p+E9QvEIK8q3INwFXS7p2y1FCmu7Vi4nhy1xs3kZufE7sGbq6M88xn rNGYZOtJmH7lsPm18o4kGopo1cOsY/c= X-MC-Unique: O9_i2QtwODugMBt2sfyj4Q-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 01/12] qemuBlockJobProcessEventConcludedBackup: Handle potentially NULL 'job->disk' Date: Thu, 13 Jun 2024 17:11:33 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 3IMWBJX4B3SLVVS7MWZ57SZRSBN6DP33 X-Message-ID-Hash: 3IMWBJX4B3SLVVS7MWZ57SZRSBN6DP33 X-MailFrom: pkrempa@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: 1718291557461100001 Content-Type: text/plain; charset="utf-8" Similarly to other blockjob handlers, if there's no disk associated with the blockjob the handler needs to behave correctly. This is needed as the disk might have been de-associated on unplug or other operations. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_backup.c | 6 +++--- src/qemu/qemu_backup.h | 2 +- src/qemu/qemu_blockjob.c | 9 +++++++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_backup.c b/src/qemu/qemu_backup.c index 857709b17e..81391c29f7 100644 --- a/src/qemu/qemu_backup.c +++ b/src/qemu/qemu_backup.c @@ -966,7 +966,7 @@ qemuBackupGetXMLDesc(virDomainObj *vm, void qemuBackupNotifyBlockjobEnd(virDomainObj *vm, - virDomainDiskDef *disk, + const char *diskdst, qemuBlockjobState state, const char *errmsg, unsigned long long cur, @@ -983,7 +983,7 @@ qemuBackupNotifyBlockjobEnd(virDomainObj *vm, size_t i; VIR_DEBUG("vm: '%s', disk:'%s', state:'%d' errmsg:'%s'", - vm->def->name, disk->dst, state, NULLSTR(errmsg)); + vm->def->name, NULLSTR(diskdst), state, NULLSTR(errmsg)); if (!backup) return; @@ -1016,7 +1016,7 @@ qemuBackupNotifyBlockjobEnd(virDomainObj *vm, if (!backupdisk->store) continue; - if (STREQ(disk->dst, backupdisk->name)) { + if (STREQ_NULLABLE(diskdst, backupdisk->name)) { switch (state) { case QEMU_BLOCKJOB_STATE_COMPLETED: backupdisk->state =3D VIR_DOMAIN_BACKUP_DISK_STATE_COMPLET= E; diff --git a/src/qemu/qemu_backup.h b/src/qemu/qemu_backup.h index ec0603026a..768da6cbef 100644 --- a/src/qemu/qemu_backup.h +++ b/src/qemu/qemu_backup.h @@ -36,7 +36,7 @@ qemuBackupJobCancelBlockjobs(virDomainObj *vm, void qemuBackupNotifyBlockjobEnd(virDomainObj *vm, - virDomainDiskDef *disk, + const char *diskdst, qemuBlockjobState state, const char *errmsg, unsigned long long cur, diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c index 4b5b63d287..42856df6d4 100644 --- a/src/qemu/qemu_blockjob.c +++ b/src/qemu/qemu_blockjob.c @@ -1372,8 +1372,12 @@ qemuBlockJobProcessEventConcludedBackup(virQEMUDrive= r *driver, unsigned long long progressTotal) { g_autoptr(qemuBlockStorageSourceAttachData) backend =3D NULL; + const char *diskdst =3D NULL; + + if (job->disk) + diskdst =3D job->disk->dst; - qemuBackupNotifyBlockjobEnd(vm, job->disk, newstate, job->errmsg, + qemuBackupNotifyBlockjobEnd(vm, diskdst, newstate, job->errmsg, progressCurrent, progressTotal, asyncJob); if (job->data.backup.store && @@ -1386,7 +1390,8 @@ qemuBlockJobProcessEventConcludedBackup(virQEMUDriver= *driver, if (backend) qemuBlockStorageSourceAttachRollback(qemuDomainGetMonitor(vm), bac= kend); - if (job->data.backup.bitmap) + if (job->disk && + job->data.backup.bitmap) qemuMonitorBitmapRemove(qemuDomainGetMonitor(vm), qemuBlockStorageSourceGetEffectiveNodename= (job->disk->src), job->data.backup.bitmap); --=20 2.45.2 From nobody Fri Oct 18 06:24:44 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 1718291573059359.8790788651305; Thu, 13 Jun 2024 08:12:53 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 0AC411201; Thu, 13 Jun 2024 11:12:52 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 096F41207; Thu, 13 Jun 2024 11:11:58 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 41BA3B2C; Thu, 13 Jun 2024 11:11:53 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 D57AAA64 for ; Thu, 13 Jun 2024 11:11:52 -0400 (EDT) Received: from mx-prod-mc-02.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-203-2uzD06V4PpWRQEvsPYrqNA-1; Thu, 13 Jun 2024 11:11:50 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4634C1955EA2 for ; Thu, 13 Jun 2024 15:11:49 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5F04F1956050 for ; Thu, 13 Jun 2024 15:11:48 +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=3.0 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,RCVD_IN_SBL_CSS,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718291512; 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: in-reply-to:in-reply-to:references:references; bh=+5xtwMzGxxK9VyYKfXRQbbrU6O9Z8IAOGQNT6BnW4jw=; b=V+IcZPp/Mp1EvSPum4PE8C68d6cp5n9p7Ng4Cmn50Mlp4xB3vxD1PvOJ9ZV0eQeQkEEUwZ 6gLjDsNMHqNuqFQGVhq3JHtY8oF99jEGtuOyA+DQ4Xew+hDZdoQdkz5/4q3VW3kyCLY0el Ox2wUGCee6n03oDdxvwQwKlJDgYviEg= X-MC-Unique: 2uzD06V4PpWRQEvsPYrqNA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 02/12] qemuDomainDiskPrivateDispose: Prevent dangling 'disk' pointer in blockjob data Date: Thu, 13 Jun 2024 17:11:34 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: W7EELBRDJFHS6S4JBRTCFAPPL3FA2MB3 X-Message-ID-Hash: W7EELBRDJFHS6S4JBRTCFAPPL3FA2MB3 X-MailFrom: pkrempa@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: 1718291573542100001 Content-Type: text/plain; charset="utf-8" Clear the 'disk' member of 'blockjob' as we're freeing the disk object at this point. While this should not normally happen it was observed when other bug allowed the VM to be cleared while other threads didn't yet finish. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_domain.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 7ba2ea4a5e..a39f361a64 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -798,7 +798,13 @@ qemuDomainDiskPrivateDispose(void *obj) virObjectUnref(priv->migrSource); g_free(priv->qomName); g_free(priv->nodeCopyOnRead); - virObjectUnref(priv->blockjob); + if (priv->blockjob) { + /* Prevent dangling 'disk' pointer, as the disk object will be fre= ed + * right after this function returns if any of the blockjob instan= ce + * outlives this for any reason. */ + priv->blockjob->disk =3D NULL; + virObjectUnref(priv->blockjob); + } } static virClass *qemuDomainStorageSourcePrivateClass; --=20 2.45.2 From nobody Fri Oct 18 06:24:44 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 1718291590914560.7709593177311; Thu, 13 Jun 2024 08:13:10 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C280E11AF; Thu, 13 Jun 2024 11:13:09 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8F82F121B; Thu, 13 Jun 2024 11:11:59 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 69378A44; Thu, 13 Jun 2024 11:11:53 -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 09AA7A44 for ; Thu, 13 Jun 2024 11:11:53 -0400 (EDT) Received: from mx-prod-mc-02.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-648-KOu0X_auP8ucYnNk9pcguA-1; Thu, 13 Jun 2024 11:11:51 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 85E0B1955F2F for ; Thu, 13 Jun 2024 15:11:50 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9FC8D1956050 for ; Thu, 13 Jun 2024 15:11:49 +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=3.0 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,RCVD_IN_SBL_CSS,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718291512; 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: in-reply-to:in-reply-to:references:references; bh=zJzTyShliamM0ut7y/9RG8WRu+B5ek8nYaeLJK+H4OE=; b=DXi5pPiu1pYfexV4t0HWhaVntJWN9Ft5qmbjX54NNFhnGqFMRA+aXk9lceD077vd1VJIXB eRPtdTUN5lA4SmrOhEwXd3ASCx3AAhqIUBhXEFc5zWdPM8VlxkmXMHOJBBl5UbQkTgbCKz y04EBrbed4DqFGhom0ch5y/6JHvClYs= X-MC-Unique: KOu0X_auP8ucYnNk9pcguA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 03/12] qemuDomainDeviceBackendChardevForeach: Fix typo in comment Date: Thu, 13 Jun 2024 17:11:35 +0200 Message-ID: <85b12b448c809682745360748be8571709294d54.1718291410.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 3UT6AVKTQCG3P6VLP6M6PKCFBAOCXUNI X-Message-ID-Hash: 3UT6AVKTQCG3P6VLP6M6PKCFBAOCXUNI X-MailFrom: pkrempa@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: 1718291591599100001 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_domain.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index a39f361a64..9bbad887e0 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12302,7 +12302,7 @@ qemuDomainDeviceBackendChardevIter(virDomainDef *de= f G_GNUC_UNUSED, /** - * qemuDomainDeviceBackendChardevForeach:a + * qemuDomainDeviceBackendChardevForeach: * @def: domain definition * @cb: callback * @opqaue: data for @cb --=20 2.45.2 From nobody Fri Oct 18 06:24:44 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 171829160823969.07566738838761; Thu, 13 Jun 2024 08:13:28 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E93CF11AC; Thu, 13 Jun 2024 11:13:26 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 52217D3D; Thu, 13 Jun 2024 11:12:11 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id A1815108B; Thu, 13 Jun 2024 11:12:07 -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 9A9531206 for ; Thu, 13 Jun 2024 11:11:56 -0400 (EDT) Received: from mx-prod-mc-01.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-438-WxcVH1dZN_CEhwzkSJHnuA-1; Thu, 13 Jun 2024 11:11:52 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AF0431956055 for ; Thu, 13 Jun 2024 15:11:51 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E131A1956050 for ; Thu, 13 Jun 2024 15:11:50 +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=3.0 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,RCVD_IN_SBL_CSS,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718291516; 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: in-reply-to:in-reply-to:references:references; bh=kLaqCpQg+HsDb93fQcCSebVy1YqPMuncpYXxKggGwdo=; b=J6NTnG5Y9Vqu1jliQ/+ab9n6ie0DlE0Cd+nuDHXZjbF2gfbJgW/21awOWOc01BX6vkYPb2 y8A2pW5D1kDUNoov07h91KsMefEPXuMsI0HiNxOC9WirI7P5/ZZLH+JwKgWhVtnj748sZw KAL+ua+9B4qxxhBqobznxou3VoG2wGs= X-MC-Unique: WxcVH1dZN_CEhwzkSJHnuA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 04/12] qemuDomainObjWait: Add documentation Date: Thu, 13 Jun 2024 17:11:36 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: KVBFCFRS6GF6PQ4PHHN7WI4THX3GI6KF X-Message-ID-Hash: KVBFCFRS6GF6PQ4PHHN7WI4THX3GI6KF X-MailFrom: pkrempa@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: 1718291609682100001 Content-Type: text/plain; charset="utf-8" Document why this function exists and meaning of return values. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_domain.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 9bbad887e0..8fe1b1924d 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12368,6 +12368,18 @@ qemuDomainRemoveLogs(virQEMUDriver *driver, } +/** + * qemuDomainObjWait: + * @vm: domain object + * + * Wait for a signal on the main domain condition. Take into account inter= nal + * qemu state in addition to what virDomainObjWait checks. Code in the qemu + * driver must use this function exclusively instead of virDomainObjWait. + * + * Returns: + * - 0 on successful wait AND VM is guaranteed to be running + * - -1 on failure to wait or VM was terminated while waiting + */ int qemuDomainObjWait(virDomainObj *vm) { --=20 2.45.2 From nobody Fri Oct 18 06:24:44 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 1718291628300619.6614561196662; Thu, 13 Jun 2024 08:13:48 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 480FF1230; Thu, 13 Jun 2024 11:13:47 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 34F781221; Thu, 13 Jun 2024 11:12:13 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id ADE53110A; Thu, 13 Jun 2024 11:12:07 -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 7D98111F0 for ; Thu, 13 Jun 2024 11:11:55 -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-682-0gAs0qZZPO6WkDUkWsPnRA-1; Thu, 13 Jun 2024 11:11:53 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 F102319560B8 for ; Thu, 13 Jun 2024 15:11:52 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2D8651956058 for ; Thu, 13 Jun 2024 15:11:51 +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=3.0 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,RCVD_IN_SBL_CSS,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718291515; 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: in-reply-to:in-reply-to:references:references; bh=dQwnefW1FuddR/FfANPNaLU1iHgn5/y4oZgUDab/SvE=; b=L+ekEaGjMJC/lGrBAYtF8hwJgAC7OrvHA3h9vwRB96uf9YIjtkxaOD79XW4e7tDqdxvRZX TUfWSvbgEofTyT2J9wwi1vMin7wnFi6nUXOYQ2AImI13ulr/a9IX/sc1enHtW/iwVMie0A FzeI55BGpAok2yJD+ZRTh/0hDZxt3m0= X-MC-Unique: 0gAs0qZZPO6WkDUkWsPnRA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 05/12] qemuProcessStop: Prevent crash when qemuDomainObjStopWorker() unlocks the VM Date: Thu, 13 Jun 2024 17:11:37 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LP573DSR36QMJ5OABPUGBVSJQDWBPIXN X-Message-ID-Hash: LP573DSR36QMJ5OABPUGBVSJQDWBPIXN X-MailFrom: pkrempa@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: 1718291629815100001 Content-Type: text/plain; charset="utf-8" 'qemuDomainObjStopWorker()' which is meant to dispose of the event loop thread for the monitor unlocks the VM object while disposing the thread to prevent possible deadlocks with events waiting on the monitor thread. Unfortunately 'qemuDomainObjStopWorker()' is called *before* the VM is marked as inactive by clearing 'vm->def->id', but at the same time it's no longer marked as 'beingDestroyed' when we're inside 'qemuProcessStop()'. If 'vm' would be kept locked this wouldn't be a problem. Same way it's not a problem for anything that uses non-ASYNC VM jobs, or when the monitor is accessed in an async job, as the 'destroy' job interlocks with those. It is a problem for code inside an async job which uses 'qemuDomainObjWait()' though. The API contract of qemuDomainObjWait() ensures the caller that the VM on successful return from it, but in this specific reason it's not the case, as both 'beingDestroyed' is already false, and 'vm->def->id' is not yet cleared. To fix the issue move the 'qemuDomainObjStopWorker()' call *after* clearing 'vm->def->id' and also add a note stating what the function is doing. Fixes: 860a999802d3c82538373bb3f314f92a2e258754 Closes: https://gitlab.com/libvirt/libvirt/-/issues/640 Reported-by: grass-lu Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_process.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7ef7040a85..aef83d2409 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8527,8 +8527,6 @@ void qemuProcessStop(virQEMUDriver *driver, g_clear_pointer(&priv->monConfig, virObjectUnref); } - qemuDomainObjStopWorker(vm); - /* Remove the master key */ qemuDomainMasterKeyRemove(priv); @@ -8562,6 +8560,11 @@ void qemuProcessStop(virQEMUDriver *driver, /* Wake up anything waiting on domain condition */ virDomainObjBroadcast(vm); + /* IMPORTANT: qemuDomainObjStopWorker() unlocks @vm in order to prevent + * deadlocks with the per-VM event loop thread. This MUST be done after + * marking the VM as dead */ + qemuDomainObjStopWorker(vm); + virFileDeleteTree(priv->libDir); virFileDeleteTree(priv->channelTargetDir); --=20 2.45.2 From nobody Fri Oct 18 06:24:44 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 1718291658567549.9393020929678; Thu, 13 Jun 2024 08:14:18 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7E510E66; Thu, 13 Jun 2024 11:14:17 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8A68011C1; Thu, 13 Jun 2024 11:12:15 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 66E631204; Thu, 13 Jun 2024 11:12:08 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 EB87B11F5 for ; Thu, 13 Jun 2024 11:11:56 -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-649-RkxFFM9hNoK8H8X8A28TAw-1; Thu, 13 Jun 2024 11:11:55 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 3BBC51955F02 for ; Thu, 13 Jun 2024 15:11:54 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5DBD31956050 for ; Thu, 13 Jun 2024 15:11:53 +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=3.0 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,RCVD_IN_SBL_CSS,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718291516; 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: in-reply-to:in-reply-to:references:references; bh=EeGIU6d4UKnFJloMkRG0x9Xfks0iWYz71+LLPpYEQJ8=; b=YeRs+hSoLbI3Pw9iK7WJOFpz50pcdMz3XojKgTo4527yFq9CzpR6VJPR77WXpD9AvrL5qs hAP9+xYsMk5GP5/bJIRh+mQE3FfTzZZt/iPoqPis57Z908lhKqALHODpCoJwDSkZEBhezn /1W40RehZ4+Hlc7jFy0QXKBIrOltFgU= X-MC-Unique: RkxFFM9hNoK8H8X8A28TAw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 06/12] qemuProcessStop: Move code not depending on 'vm->def->id' after reset of the ID Date: Thu, 13 Jun 2024 17:11:38 +0200 Message-ID: <4700174e7388c856b9fea0c56dff03110f9ee0aa.1718291410.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: BYRQUWTD7UDFDWUTACF4ZRVKU4OVEXTH X-Message-ID-Hash: BYRQUWTD7UDFDWUTACF4ZRVKU4OVEXTH X-MailFrom: pkrempa@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: 1718291659933100001 Content-Type: text/plain; charset="utf-8" There are few function calls done while cleaning up a stopped VM which do require the old VM id, to e.g. clean up paths containing the 'short' domain name in the path. Anything else, which doesn't strictly require it can be moved after clearing the 'id' in order to decrease likelyhood of potential bugs. This patch moves all the code which does not require the 'id' (except for the log entry and closing the monitor socket) after the statement clearing the id and adds a comment explaining that anything in the section must not unlock the VM object. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_process.c | 85 ++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index aef83d2409..3187f0a9a2 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8482,10 +8482,11 @@ void qemuProcessStop(virQEMUDriver *driver, goto endjob; } - qemuProcessBuildDestroyMemoryPaths(driver, vm, NULL, false); - - if (!!g_atomic_int_dec_and_test(&driver->nactive) && driver->inhibitCa= llback) - driver->inhibitCallback(false, driver->inhibitOpaque); + /* BEWARE: At this point 'vm->def->id' is not cleared yet. Any code th= at + * requires the id (e.g. to call virDomainDefGetShortName()) must be p= laced + * between here (after the VM is killed) and the statement clearing th= e id. + * The code *MUST NOT* unlock vm, otherwise other code might be confus= ed + * about the state of the VM. */ if ((timestamp =3D virTimeStringNow()) !=3D NULL) { qemuDomainLogAppendMessage(driver, vm, "%s: shutting down, reason= =3D%s\n", @@ -8493,6 +8494,47 @@ void qemuProcessStop(virQEMUDriver *driver, virDomainShutoffReasonTypeToString(reas= on)); } + /* shut it off for sure */ + ignore_value(qemuProcessKill(vm, + VIR_QEMU_PROCESS_KILL_FORCE| + VIR_QEMU_PROCESS_KILL_NOCHECK)); + + if (priv->agent) { + g_clear_pointer(&priv->agent, qemuAgentClose); + } + priv->agentError =3D false; + + if (priv->mon) { + g_clear_pointer(&priv->mon, qemuMonitorClose); + } + + qemuProcessBuildDestroyMemoryPaths(driver, vm, NULL, false); + + /* Do this before we delete the tree and remove pidfile. */ + qemuProcessKillManagedPRDaemon(vm); + + qemuDomainCleanupRun(driver, vm); + + outgoingMigration =3D (flags & VIR_QEMU_PROCESS_STOP_MIGRATED) && + (asyncJob =3D=3D VIR_ASYNC_JOB_MIGRATION_OUT); + + qemuExtDevicesStop(driver, vm, outgoingMigration); + + qemuDBusStop(driver, vm); + + vm->def->id =3D -1; + + /* Wake up anything waiting on domain condition */ + virDomainObjBroadcast(vm); + + /* IMPORTANT: qemuDomainObjStopWorker() unlocks @vm in order to prevent + * deadlocks with the per-VM event loop thread. This MUST be done after + * marking the VM as dead */ + qemuDomainObjStopWorker(vm); + + if (!!g_atomic_int_dec_and_test(&driver->nactive) && driver->inhibitCa= llback) + driver->inhibitCallback(false, driver->inhibitOpaque); + /* Clear network bandwidth */ virDomainClearNetBandwidth(vm->def); @@ -8512,15 +8554,6 @@ void qemuProcessStop(virQEMUDriver *driver, virPortAllocatorRelease(priv->nbdPort); priv->nbdPort =3D 0; - if (priv->agent) { - g_clear_pointer(&priv->agent, qemuAgentClose); - } - priv->agentError =3D false; - - if (priv->mon) { - g_clear_pointer(&priv->mon, qemuMonitorClose); - } - if (priv->monConfig) { if (priv->monConfig->type =3D=3D VIR_DOMAIN_CHR_TYPE_UNIX) unlink(priv->monConfig->data.nix.path); @@ -8530,41 +8563,15 @@ void qemuProcessStop(virQEMUDriver *driver, /* Remove the master key */ qemuDomainMasterKeyRemove(priv); - /* Do this before we delete the tree and remove pidfile. */ - qemuProcessKillManagedPRDaemon(vm); - ignore_value(virDomainChrDefForeach(vm->def, false, qemuProcessCleanupChardevDevice, NULL)); - /* shut it off for sure */ - ignore_value(qemuProcessKill(vm, - VIR_QEMU_PROCESS_KILL_FORCE| - VIR_QEMU_PROCESS_KILL_NOCHECK)); - /* Its namespace is also gone then. */ qemuDomainDestroyNamespace(driver, vm); - qemuDomainCleanupRun(driver, vm); - - outgoingMigration =3D (flags & VIR_QEMU_PROCESS_STOP_MIGRATED) && - (asyncJob =3D=3D VIR_ASYNC_JOB_MIGRATION_OUT); - qemuExtDevicesStop(driver, vm, outgoingMigration); - - qemuDBusStop(driver, vm); - - vm->def->id =3D -1; - - /* Wake up anything waiting on domain condition */ - virDomainObjBroadcast(vm); - - /* IMPORTANT: qemuDomainObjStopWorker() unlocks @vm in order to prevent - * deadlocks with the per-VM event loop thread. This MUST be done after - * marking the VM as dead */ - qemuDomainObjStopWorker(vm); - virFileDeleteTree(priv->libDir); virFileDeleteTree(priv->channelTargetDir); --=20 2.45.2 From nobody Fri Oct 18 06:24:44 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 1718291679412483.8251781484091; Thu, 13 Jun 2024 08:14:39 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BECF6121A; Thu, 13 Jun 2024 11:14:37 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5B8BCE8B; Thu, 13 Jun 2024 11:12:17 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id F111511C0; Thu, 13 Jun 2024 11:12:08 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 131911173 for ; Thu, 13 Jun 2024 11:11:59 -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-353-Un3Rx3FKP-SaxcEezi-eBg-1; Thu, 13 Jun 2024 11:11:56 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 696041956080 for ; Thu, 13 Jun 2024 15:11:55 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 82C981956050 for ; Thu, 13 Jun 2024 15:11:54 +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=3.0 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,RCVD_IN_SBL_CSS,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718291518; 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: in-reply-to:in-reply-to:references:references; bh=IrOfKwBIgnuqFu+AFk7V/UfouLfdXfI22/WFGoFynJ0=; b=TupFAUmN6DqDrs8hulye2fkC8g5NwevZfBiNXIrGzUuJbb5UFK7XlY8ZdWsPJfb814avtV iSFj/wp+qfHTMMbPdfKhTovlDc62uOaK6OmD3K1+Om4NCkeoK0JucDHReqGQ9HX7cVewDt t4dZLAxCPtBYabyWmwmL7YWr9ayWUqU= X-MC-Unique: Un3Rx3FKP-SaxcEezi-eBg-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 07/12] qemu: process: Ensure that 'beingDestroyed' gets cleared only after VM id is reset Date: Thu, 13 Jun 2024 17:11:39 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: LAGWFRQPQKUOANFUBGCEFJTP4DON2DVA X-Message-ID-Hash: LAGWFRQPQKUOANFUBGCEFJTP4DON2DVA X-MailFrom: pkrempa@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: 1718291680016100001 Content-Type: text/plain; charset="utf-8" Prevent the possibility that a VM could be considered as alive while inside qemuProcessStop. A recently fixed bug which unlocked the domain object while inside qemuProcessStop showed that there's possibility to confuse the state of the VM to be considered active while 'qemuProcessStop' is processing shutdown of the VM. Ensure that this doesn't happen by clearing the 'beingDestroyed' flag only after the VM id is cleared. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_process.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 3187f0a9a2..8736738a5b 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8413,29 +8413,31 @@ qemuProcessBeginStopJob(virDomainObj *vm, { qemuDomainObjPrivate *priv =3D vm->privateData; unsigned int killFlags =3D forceKill ? VIR_QEMU_PROCESS_KILL_FORCE : 0; - int ret =3D -1; /* We need to prevent monitor EOF callback from doing our work (and * sending misleading events) while the vm is unlocked inside - * BeginJob/ProcessKill API - */ + * BeginJob/ProcessKill API or any other code path before 'vm->def->id= ' is + * cleared inside qemuProcessStop */ priv->beingDestroyed =3D true; if (qemuProcessKill(vm, killFlags) < 0) - goto cleanup; + goto error; /* Wake up anything waiting on domain condition */ VIR_DEBUG("waking up all jobs waiting on the domain condition"); virDomainObjBroadcast(vm); if (virDomainObjBeginJob(vm, job) < 0) - goto cleanup; + goto error; - ret =3D 0; + /* 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 */ + return 0; - cleanup: + error: priv->beingDestroyed =3D false; - return ret; + return -1; } @@ -8522,7 +8524,13 @@ void qemuProcessStop(virQEMUDriver *driver, qemuDBusStop(driver, vm); + /* Only after this point we can reset 'priv->beingDestroyed' so that + * there's no point at which the VM could be considered as alive betwe= en + * entering the destroy job and this point where the active "flag" is + * cleared. + */ vm->def->id =3D -1; + priv->beingDestroyed =3D false; /* Wake up anything waiting on domain condition */ virDomainObjBroadcast(vm); --=20 2.45.2 From nobody Fri Oct 18 06:24:44 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 1718291697661974.1402037025488; Thu, 13 Jun 2024 08:14:57 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 9034111F9; Thu, 13 Jun 2024 11:14:56 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id EB50C123F; Thu, 13 Jun 2024 11:12:18 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 544AB11FD; Thu, 13 Jun 2024 11:12:09 -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 671101217 for ; Thu, 13 Jun 2024 11:11:59 -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-288-zPeZVyVpMAmDcL48HqeBNw-1; Thu, 13 Jun 2024 11:11:57 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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 7FD0119560B2 for ; Thu, 13 Jun 2024 15:11:56 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B11341956050 for ; Thu, 13 Jun 2024 15:11:55 +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=3.0 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,RCVD_IN_SBL_CSS,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718291519; 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: in-reply-to:in-reply-to:references:references; bh=+s4/7xfXO/9Bm7aWrgFP1LuYzky43siqgwD472X9AHU=; b=JBzv+7zLlgZDYR/v93beNsHH4bR4HVvDDS+6XLyjj2Yx5aZTEQPXeaVDxmuyDXQAezdl7n +IWAGHuhYIVizpAhDhRk+/vIDa+Bh6lfsBfn8+2KSVl9PAIK60Pq+FwrzzD7ThnKSFdMCS Pqp2xcgKx9/n1y3Vy6m8PaTuhecqR44= X-MC-Unique: zPeZVyVpMAmDcL48HqeBNw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 08/12] qemu: domain: Introduce qemuDomainObjIsActive helper Date: Thu, 13 Jun 2024 17:11:40 +0200 Message-ID: <51cc5961935b5ae7830d55c7ccf2d89fe5f5f1cb.1718291410.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: H7VYKGIYZT47H7R4FGOCD4OFPSJ7KBVP X-Message-ID-Hash: H7VYKGIYZT47H7R4FGOCD4OFPSJ7KBVP X-MailFrom: pkrempa@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: 1718291698074100001 Content-Type: text/plain; charset="utf-8" The helper checks whether VM is active including the internal qemu state. This helper will become useful in situations when an async job is in use as VIR_JOB_DESTROY can run along async jobs thus both checks are necessary. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_domain.c | 18 ++++++++++++++++++ src/qemu/qemu_domain.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 8fe1b1924d..64fe1abbc5 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -12397,6 +12397,24 @@ qemuDomainObjWait(virDomainObj *vm) } +/** + * qemuDomainObjIsActive: + * @vm: domain object + * + * Return whether @vm is active. Take qemu-driver specifics into account. + */ +bool +qemuDomainObjIsActive(virDomainObj *vm) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + + if (priv->beingDestroyed) + return false; + + return virDomainObjIsActive(vm); +} + + /** * virDomainRefreshStatsSchema: * @driver: qemu driver data diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index a3089ea449..d777559119 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -1113,6 +1113,8 @@ qemuDomainRemoveLogs(virQEMUDriver *driver, int qemuDomainObjWait(virDomainObj *vm); +bool +qemuDomainObjIsActive(virDomainObj *vm); int qemuDomainRefreshStatsSchema(virDomainObj *dom); --=20 2.45.2 From nobody Fri Oct 18 06:24:44 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 1718291716763651.8700369538111; Thu, 13 Jun 2024 08:15:16 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id AFE119CB; Thu, 13 Jun 2024 11:15:15 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8C6FC11E0; Thu, 13 Jun 2024 11:12:21 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 0C8FFA79; Thu, 13 Jun 2024 11:12:18 -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 4871511B0 for ; Thu, 13 Jun 2024 11:12:00 -0400 (EDT) Received: from mx-prod-mc-01.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-272-KdZ8BaXhOxa44MqT3cxZpg-1; Thu, 13 Jun 2024 11:11:58 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ADCA319560BE for ; Thu, 13 Jun 2024 15:11:57 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E6CE91956050 for ; Thu, 13 Jun 2024 15:11:56 +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=3.0 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,RCVD_IN_SBL_CSS,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718291520; 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: in-reply-to:in-reply-to:references:references; bh=bEy43cA/LlYzGIWVpIkV1Cae2RyFioOwqNVZqQENj7k=; b=FqYpTtuxWfHMXgciZg/lxt3RGKRCzNUw/VAAldwjRC7PfQyY2vmOG9Rgtwy9GS9jN3KJRV D1aWFkHV5cDKzYB5TVXEkT5/A8wa9TV6eHKL7bz3b+VTOKQdAVcxrtfbp1dm+66BYE6kE3 dulEINrbP0Ra/YV4FW9uFuAGTx7FzBo= X-MC-Unique: KdZ8BaXhOxa44MqT3cxZpg-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 09/12] qemu: migration: Properly check for live VM after qemuDomainObjWait() Date: Thu, 13 Jun 2024 17:11:41 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5P7CCWBTP5KYYOBPHKYRVPJXJGZDQGDA X-Message-ID-Hash: 5P7CCWBTP5KYYOBPHKYRVPJXJGZDQGDA X-MailFrom: pkrempa@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: 1718291718185100001 Content-Type: text/plain; charset="utf-8" Similarly to the one change in commit 4d1a1fdffda19a62d62fa2457d162362 we should be checking that the VM is not being yet destroyed if we've invoked qemuDomainObjWait(). Use the new helper qemuDomainObjIsActive(). Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_migration.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 1faab5dd23..0d8d3fd94f 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2058,7 +2058,6 @@ qemuMigrationSrcWaitForCompletion(virDomainObj *vm, virConnectPtr dconn, unsigned int flags) { - qemuDomainObjPrivate *priv =3D vm->privateData; virDomainJobData *jobData =3D vm->job->current; int rv; @@ -2069,7 +2068,7 @@ qemuMigrationSrcWaitForCompletion(virDomainObj *vm, return rv; if (qemuDomainObjWait(vm) < 0) { - if (virDomainObjIsActive(vm) && !priv->beingDestroyed) + if (qemuDomainObjIsActive(vm)) jobData->status =3D VIR_DOMAIN_JOB_STATUS_FAILED; return -2; } @@ -5055,7 +5054,7 @@ qemuMigrationSrcRun(virQEMUDriver *driver, error: virErrorPreserveLast(&orig_err); - if (virDomainObjIsActive(vm)) { + if (qemuDomainObjIsActive(vm)) { int reason; virDomainState state =3D virDomainObjGetState(vm, &reason); @@ -6781,7 +6780,7 @@ qemuMigrationDstFinishActive(virQEMUDriver *driver, * overwrites it. */ virErrorPreserveLast(&orig_err); - if (virDomainObjIsActive(vm)) { + if (qemuDomainObjIsActive(vm)) { if (doKill) { qemuProcessStop(driver, vm, VIR_DOMAIN_SHUTOFF_FAILED, VIR_ASYNC_JOB_MIGRATION_IN, @@ -6805,7 +6804,7 @@ qemuMigrationDstFinishActive(virQEMUDriver *driver, jobPriv->migParams, vm->job->apiFlags); } - if (!virDomainObjIsActive(vm)) + if (!qemuDomainObjIsActive(vm)) qemuDomainRemoveInactive(driver, vm, VIR_DOMAIN_UNDEFINE_TPM, fals= e); virErrorRestore(&orig_err); @@ -7050,7 +7049,7 @@ qemuMigrationSrcToFile(virQEMUDriver *driver, virDoma= inObj *vm, virErrorPreserveLast(&orig_err); /* Restore max migration bandwidth */ - if (virDomainObjIsActive(vm)) { + if (qemuDomainObjIsActive(vm)) { if (qemuMigrationParamsSetULL(migParams, QEMU_MIGRATION_PARAM_MAX_BANDWIDTH, saveMigBandwidth * 1024 * 1024) =3D= =3D 0) --=20 2.45.2 From nobody Fri Oct 18 06:24:44 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 171829173254175.16471608005577; Thu, 13 Jun 2024 08:15:32 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 8740F11B0; Thu, 13 Jun 2024 11:15:31 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 7B31C1254; Thu, 13 Jun 2024 11:12:23 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1A3A41171; Thu, 13 Jun 2024 11:12:18 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 85FCFC61 for ; Thu, 13 Jun 2024 11:12:01 -0400 (EDT) Received: from mx-prod-mc-04.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-159-xhMpMLU5NgWcQJbuXwyStA-1; Thu, 13 Jun 2024 11:11:59 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 02E821955DC1 for ; Thu, 13 Jun 2024 15:11:59 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1DC851956050 for ; Thu, 13 Jun 2024 15:11:57 +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=3.0 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,RCVD_IN_SBL_CSS,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718291521; 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: in-reply-to:in-reply-to:references:references; bh=73D0v9uMI8KkCano6+2gfsrcIJryPljxXkUoLKtWKGk=; b=V0i8SgXMbhoNtgc5Hr6OxcrV4//hKm5l0EAO43ielvtOkbI9fxWGiGok0AvOBgxlxS4IM8 XNgMefdMi7bNMuyTRdDVlDNR0TkCv+N6E94/stHERn1MEC0g6+BAKUk7mYT31uRwJ9STVT 1qopkDnqRRY/fERUNVpvVqEpo08FzA8= X-MC-Unique: xhMpMLU5NgWcQJbuXwyStA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 10/12] qemu: migration: Inline 'qemuMigrationDstFinishResume()' Date: Thu, 13 Jun 2024 17:11:42 +0200 Message-ID: <072932d76fab387eb605356afd87c92780d25eab.1718291410.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: AO6JI2L74RRKG6T5RK3I4HGXGWTATSVV X-Message-ID-Hash: AO6JI2L74RRKG6T5RK3I4HGXGWTATSVV X-MailFrom: pkrempa@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: 1718291734540100001 Content-Type: text/plain; charset="utf-8" The function is a pointless wrapper on top of qemuMigrationDstWaitForCompletion. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_migration.c | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 0d8d3fd94f..3524915e9d 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -2098,7 +2098,7 @@ qemuMigrationDstWaitForCompletion(virDomainObj *vm, unsigned int flags =3D 0; int rv; - VIR_DEBUG("Waiting for incoming migration to complete"); + VIR_DEBUG("Waiting for incoming migration to complete (vm=3D'%p')", vm= ); if (postcopy) flags =3D QEMU_MIGRATION_COMPLETED_POSTCOPY; @@ -6689,21 +6689,6 @@ qemuMigrationDstFinishFresh(virQEMUDriver *driver, } -static int -qemuMigrationDstFinishResume(virDomainObj *vm) -{ - VIR_DEBUG("vm=3D%p", vm); - - if (qemuMigrationDstWaitForCompletion(vm, - VIR_ASYNC_JOB_MIGRATION_IN, - false) < 0) { - return -1; - } - - return 0; -} - - static virDomainPtr qemuMigrationDstFinishActive(virQEMUDriver *driver, virConnectPtr dconn, @@ -6753,7 +6738,7 @@ qemuMigrationDstFinishActive(virQEMUDriver *driver, } if (flags & VIR_MIGRATE_POSTCOPY_RESUME) { - rc =3D qemuMigrationDstFinishResume(vm); + rc =3D qemuMigrationDstWaitForCompletion(vm, VIR_ASYNC_JOB_MIGRATI= ON_IN, false); inPostCopy =3D true; } else { rc =3D qemuMigrationDstFinishFresh(driver, vm, mig, flags, v3proto, --=20 2.45.2 From nobody Fri Oct 18 06:24:44 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 1718291748836816.5163883782286; Thu, 13 Jun 2024 08:15:48 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BE1B4CB3; Thu, 13 Jun 2024 11:15:47 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id AF33A1261; Thu, 13 Jun 2024 11:12:25 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 39B99108B; Thu, 13 Jun 2024 11:12:18 -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 B6A5F1228 for ; Thu, 13 Jun 2024 11:12:02 -0400 (EDT) Received: from mx-prod-mc-04.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-516-BgLwJhPCPDqYXRNRVb6fVQ-1; Thu, 13 Jun 2024 11:12:01 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2F95119560A2 for ; Thu, 13 Jun 2024 15:12:00 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4BA161956058 for ; Thu, 13 Jun 2024 15:11:59 +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=3.0 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,RCVD_IN_SBL_CSS,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718291522; 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: in-reply-to:in-reply-to:references:references; bh=0NWQnHi4hbimPhb+z27E7rVAKjOU0YTOeMi3WMJrTKk=; b=BlNNK+jaOTgpkVDR6XZI/y2Ybk3DCp+ieWzWF1ngkA1h40Yl8sFXxFwkd2c6g6S3W2R3Pi 1z64mFjHc5sKxdAI8E7wntXBDZ1eCY6XqW6ADTrJ3XxbFDA5ZcfEg9dx5+qDmOfzM34lWH BS3BYNUyqX544F2KFsfj0MLZjbzrAx4= X-MC-Unique: BgLwJhPCPDqYXRNRVb6fVQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 11/12] qemuMigrationSrcRun: Re-check whether VM is active before accessing job data Date: Thu, 13 Jun 2024 17:11:43 +0200 Message-ID: <4b072305eb2fb98e89501abd8604a486cf73f03e.1718291410.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: Y4KEP526PATUZA53HX7ZRUIHATXMQJNA X-Message-ID-Hash: Y4KEP526PATUZA53HX7ZRUIHATXMQJNA X-MailFrom: pkrempa@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: 1718291750415100001 Content-Type: text/plain; charset="utf-8" 'qemuProcessStop()' clears the 'current' job data. While the code under the 'error' label in 'qemuMigrationSrcRun()' does check that the VM is active before accessing the job, it also invokes multiple helper functions to clean up the migration including 'qemuMigrationSrcNBDCopyCancel()' which calls 'qemuDomainObjWait()' invalidating the result of the liveness check as it unlocks the VM. Duplicate the liveness check and explain why. The rest of the code e.g. accessing the monitor is safe as 'qemuDomainEnterMonitorAsync()' performs a liveness check. The cleanup path just ignores the return values of those functions. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_migration.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 3524915e9d..89ddc586bd 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -5074,7 +5074,13 @@ qemuMigrationSrcRun(virQEMUDriver *driver, dconn); qemuMigrationSrcCancelRemoveTempBitmaps(vm, VIR_ASYNC_JOB_MIGRATIO= N_OUT); + } + /* We need to re-check that the VM is active as functions like + * qemuMigrationSrcCancel/qemuMigrationSrcNBDCopyCancel wait on the VM + * condition unlocking the VM object which can lead to a cleanup of the + * 'current' job via qemuProcessStop */ + if (qemuDomainObjIsActive(vm)) { if (vm->job->current->status !=3D VIR_DOMAIN_JOB_STATUS_CANCELED) vm->job->current->status =3D VIR_DOMAIN_JOB_STATUS_FAILED; } --=20 2.45.2 From nobody Fri Oct 18 06:24:44 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 1718291774268707.2243037884252; Thu, 13 Jun 2024 08:16:14 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 27DF7824; Thu, 13 Jun 2024 11:16:13 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 7E2CB120C; Thu, 13 Jun 2024 11:12:27 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 774DF1242; Thu, 13 Jun 2024 11:12:19 -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 7C15711B4 for ; Thu, 13 Jun 2024 11:12:08 -0400 (EDT) Received: from mx-prod-mc-01.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-326-RqmSiFNlPq-2xVLQWyYznQ-1; Thu, 13 Jun 2024 11:12:05 -0400 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5F288195608B for ; Thu, 13 Jun 2024 15:12:01 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.20]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 790351956050 for ; Thu, 13 Jun 2024 15:12:00 +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=3.0 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,RCVD_IN_SBL_CSS,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718291528; 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: in-reply-to:in-reply-to:references:references; bh=TN4cx0gY0C+VeeRHkeW/S4nGljMPllTW2tAGa5j+sng=; b=IZ7JR7CvNrXFa6/+8tKaCxSekHv/r4AaynxaM4oHE5a4ypRijbGj8CAkpTTn1PfLrY9q0F MprbHIVYYZ6W+/YGIXNHSP6a7Bb0JPuigqAD9AucCfY0oOjbYIrFZ94YUVRqlUHhDdYst8 34iL9tYXAz/5DhuD5prwzlB72Uuu9yA= X-MC-Unique: RqmSiFNlPq-2xVLQWyYznQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 12/12] qemu: migration: Preserve error across qemuDomainSetMaxMemLock() on error paths Date: Thu, 13 Jun 2024 17:11:44 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: NWTG3PE2MDZQ5K7P2ZEWOHU67CDXC73S X-Message-ID-Hash: NWTG3PE2MDZQ5K7P2ZEWOHU67CDXC73S X-MailFrom: pkrempa@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: 1718291774553100001 Content-Type: text/plain; charset="utf-8" When a VM terminates itself while it's being migrated in running state libvirt would report wrong error: error: cannot get locked memory limit of process 2502057: No such file or = directory rather than the proper error: error: operation failed: domain is not running Remember the error on error paths in qemuMigrationSrcConfirmPhase and qemuMigrationSrcPerformPhase. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_migration.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 89ddc586bd..26c082fc08 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -4015,8 +4015,6 @@ qemuMigrationSrcConfirmPhase(virQEMUDriver *driver, qemuMigrationSrcNBDCopyCancel(vm, false, VIR_ASYNC_JOB_MIGRATION_OUT, NULL); - virErrorRestore(&orig_err); - if (virDomainObjGetState(vm, &reason) =3D=3D VIR_DOMAIN_PAUSED && reason =3D=3D VIR_DOMAIN_PAUSED_POSTCOPY) { qemuMigrationSrcPostcopyFailed(vm); @@ -4029,6 +4027,7 @@ qemuMigrationSrcConfirmPhase(virQEMUDriver *driver, } qemuDomainSaveStatus(vm); + virErrorRestore(&orig_err); } return 0; @@ -6230,11 +6229,15 @@ qemuMigrationSrcPerformPhase(virQEMUDriver *driver, cleanup: if (ret < 0 && !virDomainObjIsFailedPostcopy(vm, vm->job)) { + virErrorPtr orig_err; + virErrorPreserveLast(&orig_err); + qemuMigrationSrcRestoreDomainState(driver, vm); qemuMigrationParamsReset(vm, VIR_ASYNC_JOB_MIGRATION_OUT, jobPriv->migParams, vm->job->apiFlags); qemuDomainSetMaxMemLock(vm, 0, &priv->preMigrationMemlock); qemuMigrationJobFinish(vm); + virErrorRestore(&orig_err); } else { if (ret < 0) ignore_value(qemuMigrationJobSetPhase(vm, QEMU_MIGRATION_PHASE= _POSTCOPY_FAILED)); --=20 2.45.2