From nobody Tue Oct 28 17:34:05 2025 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1760363263; cv=none; d=zohomail.com; s=zohoarc; b=L0j+6HpvQkXaVWQFZyTFB15LCk4T7AneeXRirBgTthqBKnNa7Kp1ppMQ+T0Q/JHws0POW/X9nCasXoI9I97G2b4VqAwyPTWifI6o2mSq9UGj10vjyqoQcYE/EAhWPLlT69wa1stltxrgGGvgzViFnOwpMK8189mZtBXsWwLXud8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1760363263; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=HuWO4OUNguRjdk5sxs2AE41QF8Xy2xMKeWX+tshuSHk=; b=U+svlpuGVp2BseEHuqc7b+1NezwTnu59pGs7YQfuX+z6VoLF8LXdQgAJRUkDToenk+6K5Tz3bQbyr1lnUlI4b2/rp0bOqM3rrP6VcsVjGUFOeun+Ig2iHzNZwqkuhabC9nl/vBgeHgD5ycVqoFfOMWlG1kbjMjy8o3ORC7jWRW8= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 17603632637201009.9442236648262; Mon, 13 Oct 2025 06:47:43 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 2244844400; Mon, 13 Oct 2025 09:47:38 -0400 (EDT) Received: from [172.19.199.20] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 0764944614; Mon, 13 Oct 2025 09:41:44 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 993) id 59D8A41BE7; Mon, 13 Oct 2025 09:41:10 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 3B9ED43FE4 for ; Mon, 13 Oct 2025 09:41:05 -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-672-7QrbkzlwPZq0O86av3barw-1; Mon, 13 Oct 2025 09:41:02 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 5CA7F19560B0 for ; Mon, 13 Oct 2025 13:41:01 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.15]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9818018004D8 for ; Mon, 13 Oct 2025 13:41:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1760362864; 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=HuWO4OUNguRjdk5sxs2AE41QF8Xy2xMKeWX+tshuSHk=; b=NJ6h/Bfa4Jzllw8wALw2Ga7HYhwQx34oADHbMz1DDDCYHIhciB1moEQPAH8MQdVYAtURd3 a3eHSHAviXCu7Od4Dev2xDZ+4Hvj4eDzyDRfH9hTNIy2IpjPihDApBsEXcJdALUksmfLeq ZmIhNSZsp1gEv7zaDpEz3NU2AHHeTj4= X-MC-Unique: 7QrbkzlwPZq0O86av3barw-1 X-Mimecast-MFC-AGG-ID: 7QrbkzlwPZq0O86av3barw_1760362861 To: devel@lists.libvirt.org Subject: [PATCH 2/7] qemu: block: Introduce helper function to ensure that block nodes are active Date: Mon, 13 Oct 2025 15:40:51 +0200 Message-ID: <697207ca7de116f098c9a2494d2ddbd7fd03f990.1760362814.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: jxqFdmVadUKkjBgvKbowvTCQ5Dk8FdxjytS_SfYMTKg_1760362861 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ZIPPE73LY3LREKH3KK4ZDEI2AFXQGRNY X-Message-ID-Hash: ZIPPE73LY3LREKH3KK4ZDEI2AFXQGRNY X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1760363266440158500 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Upcoming changes to snapshot code will break the assumption that block nodes are always active (if the function is able to acquire a modify job). Introduce qemuBlockNodesEnsureActive that checks if the block graph in qemu contains any inactive nodes and if yes reactivates everything. The function will be used on code paths such as blockjobs which require the nodes to be active. Signed-off-by: Peter Krempa --- src/qemu/qemu_block.c | 52 +++++++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_block.h | 4 ++++ 2 files changed, 56 insertions(+) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 194f8407e3..a7062d3e96 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -4023,3 +4023,55 @@ qemuBlockFinalize(virDomainObj *vm, return ret; } + + +/** + * qemuBlockNodesEnsureActive: + * @vm: domain object + * @asyncJob: asynchronous job ID + * + * Checks if any block nodes are inactive and reactivates them. This is ne= cessary + * to do before any blockjob as the block nodes could have been deactivated + * either by an aborted migration (before the VM switched to running mode)= or + * after a snapshot with 'manual' disks (which deactivates them). + * + * Block nodes need to be reactivated prior to fetching the data + * via 'qemuBlockGetNamedNodeData' as qemu doesn't guarantee that the data + * fetched while nodes are inactive is accurate. + */ +int +qemuBlockNodesEnsureActive(virDomainObj *vm, + virDomainAsyncJob asyncJob) +{ + qemuDomainObjPrivate *priv =3D vm->privateData; + GHashTableIter htitr; + g_autoptr(GHashTable) blockNamedNodeData =3D NULL; + qemuBlockNamedNodeData *node; + bool has_inactive =3D false; + int rc =3D 0; + + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV_SET_ACTIVE)) + return 0; + + if (!(blockNamedNodeData =3D qemuBlockGetNamedNodeData(vm, asyncJob))) + return -1; + + g_hash_table_iter_init(&htitr, blockNamedNodeData); + while (g_hash_table_iter_next(&htitr, NULL, (void *) &node)) { + if (node->inactive) { + has_inactive =3D true; + break; + } + } + + if (!has_inactive) + return 0; + + if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) < 0) + return -1; + + rc =3D qemuMonitorBlockdevSetActive(priv->mon, NULL, true); + qemuDomainObjExitMonitor(vm); + + return rc; +} diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index b9e950e494..ba7e9bbbda 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -376,3 +376,7 @@ int qemuBlockFinalize(virDomainObj *vm, qemuBlockJobData *job, virDomainAsyncJob asyncJob); + +int +qemuBlockNodesEnsureActive(virDomainObj *vm, + virDomainAsyncJob asyncJob); --=20 2.51.0