From nobody Sat Dec 21 15:03:01 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 1727421726635616.4545472012857; Fri, 27 Sep 2024 00:22:06 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 903B811C1; Fri, 27 Sep 2024 03:22:05 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E0E0C1322; Fri, 27 Sep 2024 03:21:35 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D0BE112DF; Fri, 27 Sep 2024 03:21:30 -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 6457D12DF for ; Fri, 27 Sep 2024 03:21:30 -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-158-Fx-7uc01OYGFylYk5vRQpw-1; Fri, 27 Sep 2024 03:21:28 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (unknown [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-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1A65219371ED for ; Fri, 27 Sep 2024 07:21:28 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.12]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4C373195605A for ; Fri, 27 Sep 2024 07:21:27 +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.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,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=1727421690; 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=6DDs1lnJMGNJm4njXvIsOc1QnEpzsiDbw6pVJyv3Tak=; b=PEuxZeT0vlNKgCdWJpw04x1w3EszB8MBIuNqddyU/3TtrJnA9jMwERNyYvlkZP9KmKu+jh eWpBdjjYh6CYpI+7olyHWgSFwQjdjgzPibO2Ln/pKpOSnx6wBXCRhugmrVFXIghCsutWxZ rGT3Ctb6KKvFAfy00IjEX+uiAsTVCow= X-MC-Unique: Fx-7uc01OYGFylYk5vRQpw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 1/2] qemu: blockjob: Update 'mirror' of a copy job before removing images Date: Fri, 27 Sep 2024 09:21:23 +0200 Message-ID: <8a3c8acaac58ba724571450e03619ec60324a071.1727421587.git.pkrempa@redhat.com> In-Reply-To: References: 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: GUJ6FLRMQLYA7OZLU6TEYGE4Q2ZJYBYM X-Message-ID-Hash: GUJ6FLRMQLYA7OZLU6TEYGE4Q2ZJYBYM 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: 1727421727898116600 Content-Type: text/plain; charset="utf-8" When concluding a job with a 'mirror' we first unplugged the appropriate no-longer used images from qemu and then updated the definition. Normally this wouldn't be a problem because for any other thread this is done under the VM lock thus atomic. Unfortunately though, the AppArmor security backend is using a VM XML to pass data to the helper process and the state of the definition at that point was unsuitable to format a valid XML thus making 'virt-aa-helper' report parsing failure. Since we're removing the images the proper state of the VM definition indeed should not include the mirror element any more at the point when the images are removed. Closes: https://gitlab.com/libvirt/libvirt/-/issues/601 Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/qemu/qemu_blockjob.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c index 42856df6d4..9c56d5cb95 100644 --- a/src/qemu/qemu_blockjob.c +++ b/src/qemu/qemu_blockjob.c @@ -1218,6 +1218,8 @@ qemuBlockJobProcessEventConcludedCopyPivot(virQEMUDri= ver *driver, virDomainAsyncJob asyncJob) { qemuDomainObjPrivate *priv =3D vm->privateData; + g_autoptr(virStorageSource) src =3D NULL; + VIR_DEBUG("copy job '%s' on VM '%s' pivoted", job->name, vm->def->name= ); /* mirror may be NULL for copy job corresponding to migration */ @@ -1241,9 +1243,11 @@ qemuBlockJobProcessEventConcludedCopyPivot(virQEMUDr= iver *driver, qemuBlockJobRewriteConfigDiskSource(vm, job->disk, job->disk->mirror); - qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, job= ->disk->src); - virObjectUnref(job->disk->src); + src =3D g_steal_pointer(&job->disk->src); + job->disk->src =3D g_steal_pointer(&job->disk->mirror); + + qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, src= ); } @@ -1254,6 +1258,7 @@ qemuBlockJobProcessEventConcludedCopyAbort(virQEMUDri= ver *driver, virDomainAsyncJob asyncJob) { qemuDomainObjPrivate *priv =3D vm->privateData; + g_autoptr(virStorageSource) mirror =3D NULL; VIR_DEBUG("copy job '%s' on VM '%s' aborted", job->name, vm->def->name= ); @@ -1277,9 +1282,10 @@ qemuBlockJobProcessEventConcludedCopyAbort(virQEMUDr= iver *driver, g_clear_pointer(&job->disk->mirror->backingStore, virObjectUnr= ef); } + mirror =3D g_steal_pointer(&job->disk->mirror); + /* activeWrite bitmap is removed automatically here */ - qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, job= ->disk->mirror); - g_clear_pointer(&job->disk->mirror, virObjectUnref); + qemuBlockJobEventProcessConcludedRemoveChain(driver, vm, asyncJob, mir= ror); } --=20 2.46.0 From nobody Sat Dec 21 15:03:01 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 1727421742806169.72752832783942; Fri, 27 Sep 2024 00:22:22 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id A4ED31171; Fri, 27 Sep 2024 03:22:21 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9CFD614BB; Fri, 27 Sep 2024 03:21:41 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3050D1324; Fri, 27 Sep 2024 03:21:37 -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 55EE81324 for ; Fri, 27 Sep 2024 03:21:32 -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-193-niqLuEltO5-VffoIQRLwmQ-1; Fri, 27 Sep 2024 03:21:30 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (unknown [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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6A3E11943CF6 for ; Fri, 27 Sep 2024 07:21:29 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.12]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 97907195605A for ; Fri, 27 Sep 2024 07:21:28 +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.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,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=1727421692; 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=s6hL5dxAXn2/jrXr0ud9lBfs4pN2nPXYskWIh48wSFc=; b=Tb8Qf+DP1P8qW4TBSeFpCGSWJPURcP7SEhMuO+bMzyYWvNH5Y/ESEI7a2CCIHas5VLnPNc scSnx8+gMGOUZ5mfF4Db8fqKqwe3fPEv4ACGvPgbkHdhM9pZjc1pLNoge6C9PLJEuS1KBT SEbA0CwQyvZA6mUS/syWgg0at5Xk5iM= X-MC-Unique: niqLuEltO5-VffoIQRLwmQ-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 2/2] qemu: blockjob: Clean out disk mirror data after concluding the job Date: Fri, 27 Sep 2024 09:21:24 +0200 Message-ID: <901e679df34b74f3d841683cb56d2d78ddf8a4e2.1727421587.git.pkrempa@redhat.com> In-Reply-To: References: 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: T3ZNVZZNMV4JBXH3FGHRI23WZVCWFND5 X-Message-ID-Hash: T3ZNVZZNMV4JBXH3FGHRI23WZVCWFND5 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: 1727421744256116600 Content-Type: text/plain; charset="utf-8" The 'disk->mirrorJob' and 'disk->mirrorState' fields need to be cleared after a blockjob, but should be kept around while 'disk->mirror' is still in place. As 'disk->mirror' is cleared only after conclusion of the job in 'qemuBlockJobEventProcessConcluded()' we should be resetting them only afterwards. Move the code later, but since the job is unregistered from the disk we need to store the pointer to the disk before concluding the job. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/qemu/qemu_blockjob.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c index 9c56d5cb95..652b25540a 100644 --- a/src/qemu/qemu_blockjob.c +++ b/src/qemu/qemu_blockjob.c @@ -1561,12 +1561,18 @@ qemuBlockJobEventProcess(virQEMUDriver *driver, case QEMU_BLOCKJOB_STATE_COMPLETED: case QEMU_BLOCKJOB_STATE_FAILED: case QEMU_BLOCKJOB_STATE_CANCELLED: - case QEMU_BLOCKJOB_STATE_CONCLUDED: - if (job->disk) { - job->disk->mirrorState =3D VIR_DOMAIN_DISK_MIRROR_STATE_NONE; - job->disk->mirrorJob =3D VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN; - } + case QEMU_BLOCKJOB_STATE_CONCLUDED: { + virDomainDiskDef *disk =3D job->disk; + qemuBlockJobEventProcessConcluded(job, driver, vm, asyncJob); + + /* Job was unregistered from the disk but we must ensure that the + * data is cleared */ + if (disk) { + disk->mirrorState =3D VIR_DOMAIN_DISK_MIRROR_STATE_NONE; + disk->mirrorJob =3D VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN; + } + } break; case QEMU_BLOCKJOB_STATE_READY: --=20 2.46.0