From nobody Mon Sep 8 21:39:49 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=1748508347; cv=none; d=zohomail.com; s=zohoarc; b=cq3r3pbml6HTK/GzKZBCAmHrssysYlqNz1xf3zSRcRRorChYrYNs7PMviukJ58q9drC+bTiWJGK/M2EHvJ+QRTQlQeFRs5USv3hoM1WP8IDPT1/tvzg7h0oTsf7y7qne21yzjttCnkGpgiy5PUy/48FV/nNG3BmEh0VOOJWc0l4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508347; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=33nwIiwfi1ziGn5x4ADWj0Kgdk9s++7x4elH0K+uhDw=; b=R5Bj/6UKK0y84xjBc8lLHJ0oUm4DHKNj6GAAlp3ku5GFilGTgoZNzoo2b9OsBgr/buMzA6DMJwuSKHQ0bKuCz7A7DCC0QuqdDb7CV2JHeJTxLGFHIzqV5Cue1zlaf9nPYtadWNvXhaq3aac0Oj/3rEe0gHSAafAkls0hGz2+g/4= 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 1748508347060481.84655516688736; Thu, 29 May 2025 01:45:47 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D92D11235; Thu, 29 May 2025 04:45:45 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id EE27E14C7; Thu, 29 May 2025 04:43:34 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7714D1427; Thu, 29 May 2025 04:43:28 -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 22ADC14B8 for ; Thu, 29 May 2025 04:43:16 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-66-A_4AM7xUM_GVPRFNdOzxvA-1; Thu, 29 May 2025 04:43:14 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2693E18004A7 for ; Thu, 29 May 2025 08:43:13 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3F45419560AF for ; Thu, 29 May 2025 08:43:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, 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=1748508195; 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=VNJpldCw2UH8NkF7G4e03g/7hQAahAEVoeYY7BowVyI=; b=OF0kJB0a2bg6qQPGiJbtnFkxM0jCtU+5oZtYopz2kMOXYEcZZxNOpSBoB7cjetG2Mc9FGR k2hpjRKlIWcW50I2f4bk7/lCdxw3dL1ts+wEv+FCax/F7meAWTiP+Dj6nVPCbaAPQOIn6c 2w+0hBpfK2OOEuurH2Jtq0y9rFz1LJ8= X-MC-Unique: A_4AM7xUM_GVPRFNdOzxvA-1 X-Mimecast-MFC-AGG-ID: A_4AM7xUM_GVPRFNdOzxvA_1748508193 To: devel@lists.libvirt.org Subject: [PATCH 01/15] qcow2GetExtensions: Add debug logs for interesting fields in qcow2 header extension parser Date: Thu, 29 May 2025 10:42:55 +0200 Message-ID: <87801ab0c65af3afed58ced87ff6c6ef7d8a4ffa.1748507931.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-MFC-PROC-ID: Ru50VzwFYf02X48hya4W8z43K9ufnZNTGPr4RQoste0_1748508193 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ZQF4JA7YZYXOXVBMR2KSDFWJ5W57AXZU X-Message-ID-Hash: ZQF4JA7YZYXOXVBMR2KSDFWJ5W57AXZU 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508348183116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Add debug statements which were useful in figuring out bugs in the qcow2 extension parser. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index f5c50d4597..04a2dcd9aa 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -442,6 +442,10 @@ qcow2GetExtensions(const char *buf, * is stored at QCOW2v3_HDR_SIZE */ extension_end =3D virReadBufInt64BE(buf + QCOWX_HDR_BACKING_FILE_OFFSE= T); + + VIR_DEBUG("extension_start:%zu, extension_end:%zu, buf_size:%zu", + extension_start, extension_end, buf_size); + if (extension_end > buf_size) return -1; @@ -461,6 +465,8 @@ qcow2GetExtensions(const char *buf, unsigned int magic =3D virReadBufInt32BE(buf + offset); unsigned int len =3D virReadBufInt32BE(buf + offset + 4); + VIR_DEBUG("offset:%zu, len:%u, magic:0x%x", offset, len, magic); + offset +=3D 8; if ((offset + len) < offset) --=20 2.49.0 From nobody Mon Sep 8 21:39:49 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=1748508398; cv=none; d=zohomail.com; s=zohoarc; b=QrBjjlqojBLtRJrQTNjOJ3YgvPHMCfxpTpLtw+5YOAvspXnN7sMnenKCm65/2hGq+8PnrwjDR2VXD3q+qRJxyVCJM9EmtU51iN+qcieO+Z0WeQjscr0xk6+YRFqEYNsAE6UD21O6strLxaQdkzRXGOOw1DBKYujsSzD9ouP5q2s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508398; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=f3vsNNbC3wcfiHGyMfn4v03tZjaIr3gi0cbk5W6xnHc=; b=AJ6mhvdKWoVJIC2mXudOuiqBbbsTmo+2jk9e9IJATj1RMMCT17Z3qeFS1zZoa96itDw3nOHl1Wal2Z/26tlvYO3/C5oBNqPDeUwCxrW3IF3ohTjWpLISYCS5qnXYBvW9HtrF/JSC3RFRANmVZS7KR5ThMzr/mfD89wQ7q8Gk0AQ= 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 1748508398565328.82926767545416; Thu, 29 May 2025 01:46:38 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 97EDC1347; Thu, 29 May 2025 04:46:37 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id A27FD13D1; Thu, 29 May 2025 04:43:39 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id ACEC713D1; Thu, 29 May 2025 04:43:35 -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 5ADB51374 for ; Thu, 29 May 2025 04:43:17 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-266-ph4ATGM4Po25234uZGOjdw-1; Thu, 29 May 2025 04:43:15 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id AA3EC180035C for ; Thu, 29 May 2025 08:43:14 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B03FB19560B3 for ; Thu, 29 May 2025 08:43:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,WEIRD_PORT 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=1748508197; 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=jMc8IQwr701p40A1b/o0s3U52o3xfhnCnM9XRznCGkQ=; b=OI7cXSpvRpczgaZxH8GcyXHR19+hEvtsEvgXiT0tXqbLif5ZyPOere446lIP6vo7kQKOnH NfkjPOEj4aM4sc0HLfDWLro5TIEU21et5EQlDbGdkSMZsB4Ka+QyfCLmVJCJpIc/EiitGe VFTORZXPuKmMfy0XULaTyvVpsZVf1Ug= X-MC-Unique: ph4ATGM4Po25234uZGOjdw-1 X-Mimecast-MFC-AGG-ID: ph4ATGM4Po25234uZGOjdw_1748508194 To: devel@lists.libvirt.org Subject: [PATCH 02/15] virstoragetest: Reformat output to hilight dataFile relationship Date: Thu, 29 May 2025 10:42:56 +0200 Message-ID: <6fccf98186dffbab6454857d18132d6792e8a58c.1748507931.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-MFC-PROC-ID: nfW7ZQmLRvamO-IjKcnnQQP3V2-OFj0ZjCmeZdzqWgQ_1748508194 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: U6WOUYJBCRFCIZPA754OL7I7ARXDDOMS X-Message-ID-Hash: U6WOUYJBCRFCIZPA754OL7I7ARXDDOMS 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508399296116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Move the 'dataFileRaw' field to the main block as it's based on the data in the qcow2 header same as 'backingStoreRaw'. Indent and annotate the corresponding dataFile block to show where it belongs. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- tests/virstoragetest.c | 20 ++++++++++--------- tests/virstoragetestdata/out/directory-dir | 1 + tests/virstoragetestdata/out/directory-none | 1 + tests/virstoragetestdata/out/directory-raw | 1 + .../out/qcow2-auto_qcow2-qcow2_raw-raw | 1 + .../out/qcow2-auto_raw-raw-relative | 1 + tests/virstoragetestdata/out/qcow2-datafile | 15 +++++++------- .../out/qcow2-protocol-backing-file | 2 ++ .../out/qcow2-protocol-backing-nbd | 2 ++ .../out/qcow2-qcow2_nbd-raw | 2 ++ .../out/qcow2-qcow2_qcow2-auto | 2 ++ .../out/qcow2-qcow2_qcow2-qcow2_qcow2-auto | 3 +++ .../out/qcow2-qcow2_qcow2-qcow2_raw-auto | 3 +++ .../out/qcow2-qcow2_qcow2-qcow2_raw-raw | 3 +++ .../out/qcow2-qcow2_raw-raw-relative | 2 ++ tests/virstoragetestdata/out/qcow2-symlinks | 3 +++ .../out/qcow2datafile-qcow2_qcow2-datafile | 16 +++++++-------- tests/virstoragetestdata/out/qed-auto_raw | 1 + tests/virstoragetestdata/out/qed-qed_raw | 2 ++ tests/virstoragetestdata/out/raw-auto | 1 + tests/virstoragetestdata/out/raw-raw | 1 + 21 files changed, 58 insertions(+), 25 deletions(-) diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 78dc644637..e568bd3141 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -179,12 +179,14 @@ testStorageChain(const void *args) for (elt =3D meta; virStorageSourceIsBacking(elt); elt =3D elt->backin= gStore) { g_autofree char *strippedPath =3D virTestStablePath(elt->path); g_autofree char *strippedBackingStoreRaw =3D virTestStablePath(elt= ->backingStoreRaw); + g_autofree char *strippedDataFileRaw =3D virTestStablePath(elt->da= taFileRaw); g_autofree char *strippedRelPath =3D virTestStablePath(elt->relPat= h); virBufferAsprintf(&buf, "path:%s\n" "backingStoreRaw: %s\n" "backingStoreRawFormat: %s(%d)\n" + "dataFileRaw: %s\n" "capacity: %lld\n" "encryption: %d\n" "relPath:%s\n" @@ -196,6 +198,7 @@ testStorageChain(const void *args) strippedBackingStoreRaw, NULLSTR(virStorageFileFormatTypeToString(elt->ba= ckingStoreRawFormat)), elt->backingStoreRawFormat, + strippedDataFileRaw, elt->capacity, !!elt->encryption, strippedRelPath, @@ -205,18 +208,17 @@ testStorageChain(const void *args) NULLSTR(elt->nhosts ? elt->hosts[0].name : NULL)= ); if (elt->dataFileStore) { - g_autofree char *strippedPathDataFileRaw =3D virTestStablePath= (elt->dataFileRaw); g_autofree char *strippedPathDataFile =3D virTestStablePath(el= t->dataFileStore->path); virBufferAsprintf(&buf, - "dataFileRaw: %s\n\n\n" - "dataFileStoreSource:\n" - "path: %s\n" - "capacity: %lld\n" - "encryption: %d\n" - "type:%s\n" - "format:%s\n", - strippedPathDataFileRaw, + " dataFileStoreSource for '%s':\n" + " path: %s\n" + " capacity: %lld\n" + " encryption: %d\n" + " type:%s\n" + " format:%s\n" + "\n\n", + strippedPath, strippedPathDataFile, elt->dataFileStore->capacity, !!elt->dataFileStore->encryption, diff --git a/tests/virstoragetestdata/out/directory-dir b/tests/virstoraget= estdata/out/directory-dir index c6a2fa3673..ea3bb90191 100644 --- a/tests/virstoragetestdata/out/directory-dir +++ b/tests/virstoragetestdata/out/directory-dir @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/ backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath: diff --git a/tests/virstoragetestdata/out/directory-none b/tests/virstorage= testdata/out/directory-none index c6a2fa3673..ea3bb90191 100644 --- a/tests/virstoragetestdata/out/directory-none +++ b/tests/virstoragetestdata/out/directory-none @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/ backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath: diff --git a/tests/virstoragetestdata/out/directory-raw b/tests/virstoraget= estdata/out/directory-raw index 6e190c97f4..a0b9f882ed 100644 --- a/tests/virstoragetestdata/out/directory-raw +++ b/tests/virstoragetestdata/out/directory-raw @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/ backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath: diff --git a/tests/virstoragetestdata/out/qcow2-auto_qcow2-qcow2_raw-raw b/= tests/virstoragetestdata/out/qcow2-auto_qcow2-qcow2_raw-raw index 0540be0c09..14d9eb987b 100644 --- a/tests/virstoragetestdata/out/qcow2-auto_qcow2-qcow2_raw-raw +++ b/tests/virstoragetestdata/out/qcow2-auto_qcow2-qcow2_raw-raw @@ -1,6 +1,7 @@ path:ABS_BUILDDIR/virstoragedata/wrap backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath: diff --git a/tests/virstoragetestdata/out/qcow2-auto_raw-raw-relative b/tes= ts/virstoragetestdata/out/qcow2-auto_raw-raw-relative index e145cca417..b99f64ee97 100644 --- a/tests/virstoragetestdata/out/qcow2-auto_raw-raw-relative +++ b/tests/virstoragetestdata/out/qcow2-auto_raw-raw-relative @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2_raw-raw-relative.qcow2 backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath: diff --git a/tests/virstoragetestdata/out/qcow2-datafile b/tests/virstorage= testdata/out/qcow2-datafile index d0f46f7e1b..c395f7f65c 100644 --- a/tests/virstoragetestdata/out/qcow2-datafile +++ b/tests/virstoragetestdata/out/qcow2-datafile @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/datafile.qcow2 backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: raw capacity: 1024 encryption: 0 relPath: @@ -9,12 +10,10 @@ format:qcow2 protocol:none hostname: -dataFileRaw: raw - + dataFileStoreSource for 'ABS_SRCDIR/virstoragetestdata/images/datafile.qc= ow2': + path: ABS_SRCDIR/virstoragetestdata/images/raw + capacity: 0 + encryption: 0 + type:file + format:raw -dataFileStoreSource: -path: ABS_SRCDIR/virstoragetestdata/images/raw -capacity: 0 -encryption: 0 -type:file -format:raw diff --git a/tests/virstoragetestdata/out/qcow2-protocol-backing-file b/tes= ts/virstoragetestdata/out/qcow2-protocol-backing-file index d9d4c1316c..d0bf411552 100644 --- a/tests/virstoragetestdata/out/qcow2-protocol-backing-file +++ b/tests/virstoragetestdata/out/qcow2-protocol-backing-file @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2-protocol-backing-file.qcow2 backingStoreRaw: raw backingStoreRawFormat: raw(1) +dataFileRaw: capacity: 1024 encryption: 0 relPath: @@ -12,6 +13,7 @@ hostname: path:ABS_SRCDIR/virstoragetestdata/images/raw backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath:raw diff --git a/tests/virstoragetestdata/out/qcow2-protocol-backing-nbd b/test= s/virstoragetestdata/out/qcow2-protocol-backing-nbd index 360a496ab0..d41a8538a6 100644 --- a/tests/virstoragetestdata/out/qcow2-protocol-backing-nbd +++ b/tests/virstoragetestdata/out/qcow2-protocol-backing-nbd @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2-protocol-backing-nbd.qcow2 backingStoreRaw: nbd+tcp://example.org:6000/blah backingStoreRawFormat: raw(1) +dataFileRaw: capacity: 10485760 encryption: 0 relPath: @@ -12,6 +13,7 @@ hostname: path:blah backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath: diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_nbd-raw b/tests/virst= oragetestdata/out/qcow2-qcow2_nbd-raw index 0c2bb0ddc4..1ec84d771e 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_nbd-raw +++ b/tests/virstoragetestdata/out/qcow2-qcow2_nbd-raw @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2_nbd-raw.qcow2 backingStoreRaw: nbd+tcp://example.org:6000/blah backingStoreRawFormat: raw(1) +dataFileRaw: capacity: 1024 encryption: 0 relPath: @@ -12,6 +13,7 @@ hostname: path:blah backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath: diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-auto b/tests/vi= rstoragetestdata/out/qcow2-qcow2_qcow2-auto index 58f1dd6d9e..4b6b4e2283 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-auto +++ b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-auto @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2_qcow2-auto.qcow2 backingStoreRaw: qcow2 backingStoreRawFormat: (-1) +dataFileRaw: capacity: 1024 encryption: 0 relPath: @@ -12,6 +13,7 @@ hostname: path:ABS_SRCDIR/virstoragetestdata/images/qcow2 backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 1024 encryption: 0 relPath:qcow2 diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_qcow2-aut= o b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_qcow2-auto index 81263c4bc0..79943f432e 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_qcow2-auto +++ b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_qcow2-auto @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2_qcow2-qcow2_qcow2-auto.qco= w2 backingStoreRaw: qcow2_qcow2-auto.qcow2 backingStoreRawFormat: qcow2(14) +dataFileRaw: capacity: 1024 encryption: 0 relPath: @@ -12,6 +13,7 @@ hostname: path:ABS_SRCDIR/virstoragetestdata/images/qcow2_qcow2-auto.qcow2 backingStoreRaw: qcow2 backingStoreRawFormat: (-1) +dataFileRaw: capacity: 1024 encryption: 0 relPath:qcow2_qcow2-auto.qcow2 @@ -23,6 +25,7 @@ hostname: path:ABS_SRCDIR/virstoragetestdata/images/qcow2 backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 1024 encryption: 0 relPath:qcow2 diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-auto = b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-auto index cbb8d6a33f..02e2c5a966 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-auto +++ b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-auto @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2_qcow2-qcow2_raw-auto.qcow2 backingStoreRaw: qcow2_raw-auto.qcow2 backingStoreRawFormat: qcow2(14) +dataFileRaw: capacity: 1024 encryption: 0 relPath: @@ -12,6 +13,7 @@ hostname: path:ABS_SRCDIR/virstoragetestdata/images/qcow2_raw-auto.qcow2 backingStoreRaw: raw backingStoreRawFormat: (-1) +dataFileRaw: capacity: 1024 encryption: 0 relPath:qcow2_raw-auto.qcow2 @@ -23,6 +25,7 @@ hostname: path:ABS_SRCDIR/virstoragetestdata/images/raw backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath:raw diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-raw b= /tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-raw index de11029922..843a013ef5 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-raw +++ b/tests/virstoragetestdata/out/qcow2-qcow2_qcow2-qcow2_raw-raw @@ -1,6 +1,7 @@ path:ABS_BUILDDIR/virstoragedata/wrap backingStoreRaw: ABS_BUILDDIR/virstoragedata/qcow2 backingStoreRawFormat: qcow2(14) +dataFileRaw: capacity: 1024 encryption: 0 relPath: @@ -12,6 +13,7 @@ hostname: path:ABS_BUILDDIR/virstoragedata/qcow2 backingStoreRaw: ABS_BUILDDIR/virstoragedata/raw backingStoreRawFormat: raw(1) +dataFileRaw: capacity: 1024 encryption: 0 relPath: @@ -23,6 +25,7 @@ hostname: path:ABS_BUILDDIR/virstoragedata/raw backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath: diff --git a/tests/virstoragetestdata/out/qcow2-qcow2_raw-raw-relative b/te= sts/virstoragetestdata/out/qcow2-qcow2_raw-raw-relative index b4bfd432ad..33526cfd48 100644 --- a/tests/virstoragetestdata/out/qcow2-qcow2_raw-raw-relative +++ b/tests/virstoragetestdata/out/qcow2-qcow2_raw-raw-relative @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2_raw-raw-relative.qcow2 backingStoreRaw: raw backingStoreRawFormat: raw(1) +dataFileRaw: capacity: 1024 encryption: 0 relPath: @@ -12,6 +13,7 @@ hostname: path:ABS_SRCDIR/virstoragetestdata/images/raw backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath:raw diff --git a/tests/virstoragetestdata/out/qcow2-symlinks b/tests/virstorage= testdata/out/qcow2-symlinks index f053f95fd7..c74cf6be53 100644 --- a/tests/virstoragetestdata/out/qcow2-symlinks +++ b/tests/virstoragetestdata/out/qcow2-symlinks @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/sub/link2 backingStoreRaw: ../sub/link1 backingStoreRawFormat: qcow2(14) +dataFileRaw: capacity: 1024 encryption: 0 relPath: @@ -12,6 +13,7 @@ hostname: path:ABS_SRCDIR/virstoragetestdata/images/sub/../sub/link1 backingStoreRaw: ../raw backingStoreRawFormat: raw(1) +dataFileRaw: capacity: 1024 encryption: 0 relPath:../sub/link1 @@ -23,6 +25,7 @@ hostname: path:ABS_SRCDIR/virstoragetestdata/images/sub/../sub/../raw backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath:../raw diff --git a/tests/virstoragetestdata/out/qcow2datafile-qcow2_qcow2-datafil= e b/tests/virstoragetestdata/out/qcow2datafile-qcow2_qcow2-datafile index cc8bac3138..c5a5d99e9e 100644 --- a/tests/virstoragetestdata/out/qcow2datafile-qcow2_qcow2-datafile +++ b/tests/virstoragetestdata/out/qcow2datafile-qcow2_qcow2-datafile @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2datafile-datafile.qcow2 backingStoreRaw: datafile.qcow2 backingStoreRawFormat: qcow2(14) +dataFileRaw: capacity: 1024 encryption: 0 relPath: @@ -12,6 +13,7 @@ hostname: path:ABS_SRCDIR/virstoragetestdata/images/datafile.qcow2 backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: raw capacity: 1024 encryption: 0 relPath:datafile.qcow2 @@ -20,12 +22,10 @@ format:qcow2 protocol:none hostname: -dataFileRaw: raw - + dataFileStoreSource for 'ABS_SRCDIR/virstoragetestdata/images/datafile.qc= ow2': + path: ABS_SRCDIR/virstoragetestdata/images/raw + capacity: 0 + encryption: 0 + type:file + format:raw -dataFileStoreSource: -path: ABS_SRCDIR/virstoragetestdata/images/raw -capacity: 0 -encryption: 0 -type:file -format:raw diff --git a/tests/virstoragetestdata/out/qed-auto_raw b/tests/virstoragete= stdata/out/qed-auto_raw index 260c3fbc79..3905398142 100644 --- a/tests/virstoragetestdata/out/qed-auto_raw +++ b/tests/virstoragetestdata/out/qed-auto_raw @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/qed_raw-raw-relative backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath: diff --git a/tests/virstoragetestdata/out/qed-qed_raw b/tests/virstoragetes= tdata/out/qed-qed_raw index a13d407a5f..5ae7fef357 100644 --- a/tests/virstoragetestdata/out/qed-qed_raw +++ b/tests/virstoragetestdata/out/qed-qed_raw @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/qed_raw-raw-relative backingStoreRaw: raw backingStoreRawFormat: raw(1) +dataFileRaw: capacity: 1024 encryption: 0 relPath: @@ -12,6 +13,7 @@ hostname: path:ABS_SRCDIR/virstoragetestdata/images/raw backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath:raw diff --git a/tests/virstoragetestdata/out/raw-auto b/tests/virstoragetestda= ta/out/raw-auto index 70ec22f309..5eb1d71681 100644 --- a/tests/virstoragetestdata/out/raw-auto +++ b/tests/virstoragetestdata/out/raw-auto @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/raw backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath: diff --git a/tests/virstoragetestdata/out/raw-raw b/tests/virstoragetestdat= a/out/raw-raw index 70ec22f309..5eb1d71681 100644 --- a/tests/virstoragetestdata/out/raw-raw +++ b/tests/virstoragetestdata/out/raw-raw @@ -1,6 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/raw backingStoreRaw: backingStoreRawFormat: none(0) +dataFileRaw: capacity: 0 encryption: 0 relPath: --=20 2.49.0 From nobody Mon Sep 8 21:39:50 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=1748508431; cv=none; d=zohomail.com; s=zohoarc; b=CY9fJJPeKiO9GmFCUJHSNljHgEGq+ADlWZmRS9oWypEcM9OnAssq22XtU6QPVV7pecRHIoKKSDg0MdCdGuB/94NAth/Tfshc2/SGGsfmUwUdgilTwLVKkmzhTqr2bGScBt5GVYK4FHwCZvopH5/gFatY71wcBonlrZ19aMplzRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508431; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=k853ewUit1tXtqdh9I+el4UysJSMYSjYfPBourIRcBg=; b=iQ9vDUJhi4kaFp60ZhWBek1JqE7vGY0pRvWggVXweCskPOKxs6P8/plsBDIkRnjpePbVL8Q4M4QjKohuDUrJy4spmh4mPm8wu0JmSfGQFk7RdMfD5Egr385OM08a732PhR6TmjjiwSwnk30Gpd1AK9mVGFHHpvIwli7/DAmBvGU= 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 17485084315471005.1723038533078; Thu, 29 May 2025 01:47:11 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 9B4671385; Thu, 29 May 2025 04:47:10 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 551C914B8; Thu, 29 May 2025 04:43:42 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E68C01396; Thu, 29 May 2025 04:43:35 -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 BB17913C4 for ; Thu, 29 May 2025 04:43:18 -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-281-1-c0VQCFM2Cp2gFyYHW-YQ-1; Thu, 29 May 2025 04:43:16 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EC10E19560A2 for ; Thu, 29 May 2025 08:43:15 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 1EE3D19560AF for ; Thu, 29 May 2025 08:43:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, 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=1748508198; 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=eq8ZgyI3gyrY8aqoZ5BtVEdq6pjyom6rHDVZOoPnMMs=; b=fjXglEdYGkW9Q78JsNYO8ApBhuoaWivEQAwTcQqn7DrA7lW7hdPgxRlYghwDug0KlWsVRt vzEPdMsTd8krOsf6Q+vpK658fQeCVpxDcOthDjDiLy1QBBwrjaZU4YWeBW79XsAaaCVxAh 1pwV3m+ckG9h7rCib773w7jZPI47rRc= X-MC-Unique: 1-c0VQCFM2Cp2gFyYHW-YQ-1 X-Mimecast-MFC-AGG-ID: 1-c0VQCFM2Cp2gFyYHW-YQ_1748508196 To: devel@lists.libvirt.org Subject: [PATCH 03/15] storage_file_probe: qcow2GetExtensions: Fix qcow2 header extension parsing Date: Thu, 29 May 2025 10:42:57 +0200 Message-ID: <6ad5342848029b15f4334059e5b8e35fe56bc9fb.1748507931.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-MFC-PROC-ID: X6Zm7F7ug4btLkqJMGV1izjV9452DlrVVUPrjDeiqX4_1748508196 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: KVYK4UKVMKBNRNX2MTJV74GIPV33WQEG X-Message-ID-Hash: KVYK4UKVMKBNRNX2MTJV74GIPV33WQEG 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508433515116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa There are 3 bugs in the qcow2 header extension parser: 1) Header extension padding not taken into account Per qcow2 documentation (qemu.git/docs/interop/qcow2.txt, also now mirrored in the comment explaining the parser) each header extension entry is padded to a multiple of 8 bytes. Our parser didn't take the padding into account and advanced the current offset only by the 'length', which corresponds to the length of the data. This meant that in vast majority of cases only the first extension would be parsed correctly. For any other one we'd try to fetch the magic and length from wrong place. Luckily this wasn't problem for most of the almost 15 years this bug existed as we only cared about the backing file format string header which was always stored first by qemu. It is now a problem in the very specific case when a qcow2 image has a 'data-file' and also a backing store with format. In such case we'd parse the backing store format properly as it's the first header and 'data-file' being the second would be skipped. The buffer bounds checks were correct so we didn't violate any memory boundaries. 2) Integer underflow in calculation of end of header extension block If the image doesn't have a backing image, the 'backing_file_offset' qcow2 header field is 0. We use that value as 'extensions_end' which is used in the while loop to parse the extension entries. The check was done as "offset < (extensions_end - 8)", thus it unreflows when there's no filename. The design of the loop prevented anything bad from happening though. 3) Off-by-one when determining end of header extension block The aforementioned end of extension check above also has an off-by-one error as it allowed another loop if more than 8 bytes were available. Now the termination entry has data length of 0 bytes so we'd not be able to properly process that one. This wasn't a problem either as for now there's just the terminator having 0 byte lenght. This patch improves documentation by quoting the qcow2 interoperability document and adjusts the loop condition and lenght handling to comply with the specs. Interestingly we also had a test case for this specific scenario but the expected test output was wrong. Fixes: a93402d48b2996e5300754d299ef0d3f646aa098 Resolves: https://issues.redhat.com/browse/RHEL-93775 Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 62 +++++++++---------- .../out/qcow2datafile-qcow2_qcow2-datafile | 10 ++- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index 04a2dcd9aa..f8857fa934 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -415,31 +415,21 @@ qcow2GetExtensions(const char *buf, extension_start =3D virReadBufInt32BE(buf + QCOW2v3_HDR_SIZE); /* - * Traditionally QCow2 files had a layout of - * - * [header] - * [backingStoreName] - * - * Although the backingStoreName typically followed - * the header immediately, this was not required by - * the format. By specifying a higher byte offset for - * the backing file offset in the header, it was - * possible to leave space between the header and - * start of backingStore. - * - * This hack is now used to store extensions to the - * qcow2 format: + * QCow2 header extensions are stored directly after the header before + * the (optional) backing store filename: * * [header] * [extensions] * [backingStoreName] * - * Thus the file region to search for extensions is - * between the end of the header (QCOW2_HDR_TOTAL_SIZE) - * and the start of the backingStoreName (offset) + * For qcow2(v2) the [header] portion has a fixed size (QCOW2_HDR_TOTA= L_SIZE), + * whereas for qcow2v3 the size of the header itself is recorded inside + * the header (at offset QCOW2v3_HDR_SIZE). * - * for qcow2 v3 images, the length of the header - * is stored at QCOW2v3_HDR_SIZE + * Thus the file region to search for header extensions is + * between the end of the header and the start of the backingStoreName + * (QCOWX_HDR_BACKING_FILE_OFFSET) if a backing file is present (as + * otherwise the value at QCOWX_HDR_BACKING_FILE_OFFSET is 0) */ extension_end =3D virReadBufInt64BE(buf + QCOWX_HDR_BACKING_FILE_OFFSE= T); @@ -449,19 +439,28 @@ qcow2GetExtensions(const char *buf, if (extension_end > buf_size) return -1; - /* - * The extensions take format of - * - * int32: magic - * int32: length - * byte[length]: payload - * - * Unknown extensions can be ignored by skipping - * over "length" bytes in the data stream. - */ offset =3D extension_start; while (offset < (buf_size-8) && - offset < (extension_end-8)) { + (extension_end =3D=3D 0 || offset <=3D (extension_end - 8))) { + /** + * Directly after the image header, optional sections called header + * extensions can + * be stored. Each extension has a structure like the following: + * + * Byte 0 - 3: Header extension type: + * 0x00000000 - End of the header extension area + * 0xe2792aca - Backing file format name string + * 0x6803f857 - Feature name table + * 0x23852875 - Bitmaps extension + * 0x0537be77 - Full disk encryption header pointer + * 0x44415441 - External data file name string + * other - Unknown header extension, can be safely ignor= ed + * + * 4 - 7: Length of the header extension data + * 8 - n: Header extension data + * n - m: Padding to round up the header extension size to= the + * next multiple of 8. + */ unsigned int magic =3D virReadBufInt32BE(buf + offset); unsigned int len =3D virReadBufInt32BE(buf + offset + 4); @@ -510,7 +509,8 @@ qcow2GetExtensions(const char *buf, return 0; } - offset +=3D len; + /* take padding into account; see above */ + offset +=3D VIR_ROUND_UP(len, 8); } return 0; diff --git a/tests/virstoragetestdata/out/qcow2datafile-qcow2_qcow2-datafil= e b/tests/virstoragetestdata/out/qcow2datafile-qcow2_qcow2-datafile index c5a5d99e9e..a200ba98fa 100644 --- a/tests/virstoragetestdata/out/qcow2datafile-qcow2_qcow2-datafile +++ b/tests/virstoragetestdata/out/qcow2datafile-qcow2_qcow2-datafile @@ -1,7 +1,7 @@ path:ABS_SRCDIR/virstoragetestdata/images/qcow2datafile-datafile.qcow2 backingStoreRaw: datafile.qcow2 backingStoreRawFormat: qcow2(14) -dataFileRaw: +dataFileRaw: raw capacity: 1024 encryption: 0 relPath: @@ -10,6 +10,14 @@ format:qcow2 protocol:none hostname: + dataFileStoreSource for 'ABS_SRCDIR/virstoragetestdata/images/qcow2datafi= le-datafile.qcow2': + path: ABS_SRCDIR/virstoragetestdata/images/raw + capacity: 0 + encryption: 0 + type:file + format:raw + + path:ABS_SRCDIR/virstoragetestdata/images/datafile.qcow2 backingStoreRaw: backingStoreRawFormat: none(0) --=20 2.49.0 From nobody Mon Sep 8 21:39:50 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=1748508463; cv=none; d=zohomail.com; s=zohoarc; b=YR3ZBOnZZut6OFgp3P+TE+SXPsQaMR2gFBKoA9AFsJBCOUFRHyGeg55UjdEmgRI7jr/GZgg+rS5XYL0YkbpdRPQ3mU/bD56EpYc7v/E3dd1cipgPe4gI4vEWfjarmi/JHy33gHrv4naFr6q1Usu2WjrUuWXIZ3yZTzxzCHl8ATo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508463; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=0s4hR110c3XoJVgzixvKOHt1dXulF5KkqTpFENyplbE=; b=P2i/Z4ae483Z5VcfqCkLReuSNF9BbLsD+aDyWBdBNBC3m089gCH6jsC4IP4a0J8qIZYDfzGv+scI7tVq5hE5ccgjJK4Y2+UTGfRgxoLQ7xlPd179YAeGvz73Q3kD1hvM6Q5yVacBhjqiULQUDf7yavwmLf4OQI4dLKYsZlWFIfs= 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 1748508463827598.6730484793991; Thu, 29 May 2025 01:47:43 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E40A71319; Thu, 29 May 2025 04:47:42 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8308512A3; Thu, 29 May 2025 04:43:44 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 8A8931252; Thu, 29 May 2025 04:43: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 5C14112AF for ; Thu, 29 May 2025 04:43:20 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-471-NkY2WLQXNr-WvHTiFxgXMw-1; Thu, 29 May 2025 04:43:17 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 39A541800263 for ; Thu, 29 May 2025 08:43:17 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6C7DC19560AF for ; Thu, 29 May 2025 08:43:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, 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=1748508200; 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=pLkwngrcfhyCozb4z0uyxLXJYvdzrgFNCLYLlmrDn2I=; b=Pd4u0mqvqOJm31qSKzhMUBdB+ncruktJ/cLQ8mTyWrBWiBwgSHHLy9XINTdhGfXwAAW2jj 1mCucJikTEFZLO31rW8n7aS8KSIwLabq6XocKS7D6z3t0SADxYhoyL0EoydeYFzJvZlZDo I27CZFW+bMlQxk/sT/G/XH8XtXKl9lo= X-MC-Unique: NkY2WLQXNr-WvHTiFxgXMw-1 X-Mimecast-MFC-AGG-ID: NkY2WLQXNr-WvHTiFxgXMw_1748508197 To: devel@lists.libvirt.org Subject: [PATCH 04/15] virstoragetest: Add qcow2 bitmaps to some images Date: Thu, 29 May 2025 10:42:58 +0200 Message-ID: <608e885b1f2c949f7867408fdf3463cea82beb25.1748507931.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-MFC-PROC-ID: sq-rSSkfwpWG_o5Sk7dc7vO2lA9ImajmSXX5jT1FO68_1748508197 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: T2RRLBGWDOFHLT75YUP76UEL6I7HHUNJ X-Message-ID-Hash: T2RRLBGWDOFHLT75YUP76UEL6I7HHUNJ 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508465828116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Add change block tracking bitmaps to some of the qcow2 images, to ensure that they work with our qcow2 header parser even when we don't parse them ourselves. The existing images were modified by running: $ qemu-img bitmap --add qcow2_qcow2-qcow2_qcow2-auto.qcow2 testbitmap $ qemu-img bitmap --add qcow2datafile-datafile.qcow2 testbitmap $ qemu-img bitmap --add datafile.qcow2 testbitmap in tests/virstoragetestdata/images/. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- .../virstoragetestdata/images/datafile.qcow2 | Bin 327680 -> 393256 bytes .../images/qcow2_qcow2-qcow2_qcow2-auto.qcow2 | Bin 196616 -> 327720 bytes .../images/qcow2datafile-datafile.qcow2 | Bin 196616 -> 327720 bytes 3 files changed, 0 insertions(+), 0 deletions(-) diff --git a/tests/virstoragetestdata/images/datafile.qcow2 b/tests/virstor= agetestdata/images/datafile.qcow2 index 32f3acff8600b169311c9a9ea17c2b12f3450e0c..5a8bf617ab622a21e236b2fd12a= 2fe302b7f4657 100644 GIT binary patch delta 109 zcmZo@5LwY6F(ICjd1Jx~MmgnHjZy{%1_=3DfR21W)1&;T>pHh*Ni|F@NuaVjel+g5g_ rum4+^TUa(RvHn}c#H7p$Rs+(-#3;bP1>%*Y7MCPtmgFWDK#T$a1b!9! delta 44 zcmZ3{AkokuG9jLkX=3DB0)#?1~)NB>TCV6tdsWt_^&#J1Up>GI#r4opf+EzB(}0A)Q6 A(EtDd diff --git a/tests/virstoragetestdata/images/qcow2_qcow2-qcow2_qcow2-auto.q= cow2 b/tests/virstoragetestdata/images/qcow2_qcow2-qcow2_qcow2-auto.qcow2 index 8b9c3cedeacf4aef8c7645314ecb68c992d4b51d..44e175552f172244dc82392c07f= a17a12d1197cf 100644 GIT binary patch delta 129 zcmeBZ;91ciA`s~2`I~`(ftdjem<%Qg_%kwYOjyAvr`)Ph%D})N!N9=3D42$2N?4KT^N znT_fG-&R(}sjN&at*lI&9hi>(g%L$8$}C`2Abm`X0t{RrUP)?kNm6D>ZejsgjsXBZ CIv8&N delta 62 zcmZ3{AkxvmBM|83`I~`(ftdjem;@#Y_)iRA*_gbPabf_+W&@_Heebw_%kwYOxVFFr`)Ph%D})N!N9=3D42$2N?4KT^N zS&ZrY-&R(}sjN&at*lI&9hi>(g%L$86aCp_L7JEt1sJ$M8cI@&OOi56auW+6rT_pc COc`qc delta 62 zcmZ3{AkxvmBM|83`I~`(ftdjem=3Dq=3Do_)k2*vN3rpr{+*n_q|nOBIF*%& PWpfbI=3DD(X0n0%N3E4UKc --=20 2.49.0 From nobody Mon Sep 8 21:39:50 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=1748508495; cv=none; d=zohomail.com; s=zohoarc; b=Y5JCgwttlAmKgP7COWucAQOBaCU0hHx4HfMUct8b73cS4ipXZHp03+OY4zWGxl51Je1SNNEFzJKoLp5XoA2whDpZZln+K8bxbaO8B/tsR4rzuBjlwSIbVuqDYNW56tBLHp6luq6Vz1kcZUlGgx//hmzZAlOYJkrTLj42Wid5n1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508495; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=ueqfKTUA8usjqSotOfkQWaIiEJJX41/QHmss2QZU0+Y=; b=Fw6694+ZeqEPYbAJSAhY3yzmm0Zts5KNJojeI6a1ImQdP8YUEl8nNFSrbhUkz+arOzNfl//ifgOuVf0V6xF59xvmg8Bm7HTuqtfVThSv965/MrJgOSNKt1j2KVi9CcjcbdaUD/MZlFAP9vh5nb5j7FIj8bt5dKKBj3sfNR01ED8= 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 1748508495382170.10428812232828; Thu, 29 May 2025 01:48:15 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 719EF13DA; Thu, 29 May 2025 04:48:14 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 9459712DF; Thu, 29 May 2025 04:43:47 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 066E914CD; Thu, 29 May 2025 04:43:39 -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 4BF091392 for ; Thu, 29 May 2025 04:43:21 -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-515-MJBxapY3NZqF_TdT7kGpWw-1; Thu, 29 May 2025 04:43:19 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 759041955DB3 for ; Thu, 29 May 2025 08:43:18 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AE91019560AF for ; Thu, 29 May 2025 08:43:17 +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=1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE,SUBJECT_DRUG_GAP_L 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=1748508200; 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=mkivkvLbarm9P7tlOo1IdMtMhPdh1HFWiX+M9Q/uGzM=; b=Hs73NZw05Cvrq8U/k8ANkxngFNHhJ1m/xNqrosZKueI/6FiRDR/1vJC5WwOQnhyWBjPve1 zx5X2BFpdESKHe5BOT0mYzIkfqxo9ITWTDVZocrz9I/b9cpGXAvB9kv5YDBvlOUlRUM7Nb BfbT+l/6S5yUDk5Fusz13X+6FxKborI= X-MC-Unique: MJBxapY3NZqF_TdT7kGpWw-1 X-Mimecast-MFC-AGG-ID: MJBxapY3NZqF_TdT7kGpWw_1748508198 To: devel@lists.libvirt.org Subject: [PATCH 05/15] storage_file_probe: Add image specific callback taking the whole virStorageSource Date: Thu, 29 May 2025 10:42:59 +0200 Message-ID: <9543a2a1a5d9aaed2831709aff93eea6384b83fd.1748507931.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-MFC-PROC-ID: GQKI1hm4OoaAQZUc4fPNo75E-rUuUWcei6k7D-hFo94_1748508198 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: AQ5ON7GG5GNCVHMTB3IZFHB6H6NE6HJF X-Message-ID-Hash: AQ5ON7GG5GNCVHMTB3IZFHB6H6NE6HJF 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508495941116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa The callbacks getting just some fields are not flexible and in some cases cause the metadata to be probed multiple times. Add a callback that will pass the whole virStorageSource struct being probed so that the code can be written more efficiently. As a first step we add just the callback. The specific format helpers will be refactored and subsequently all the other callbacks will be removed. To simplify the refactors that will convert all the code to the new callbacks the new callback is placed first but the calls to cleanup previous metadata are moved before it. They'll be removed once the refactors are complete together with the other callbacks. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 49 ++++++++++++++++----------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index f8857fa934..29837792e4 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -96,6 +96,9 @@ struct FileTypeInfo { int (*getDataFile)(char **res, virBitmap *features, char *buf, size_t = buf_size); int (*getFeatures)(virBitmap **features, int format, char *buf, ssize_t len); + int (*getImageSpecific)(virStorageSource *meta, + const char *buf, + size_t buf_size); }; @@ -241,18 +244,18 @@ static struct FileEncryptionInfo const qcow2Encryptio= nInfo[] =3D { static struct FileTypeInfo const fileTypeInfo[] =3D { [VIR_STORAGE_FILE_NONE] =3D { 0, NULL, LV_LITTLE_ENDIAN, - -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL, NUL= L, NULL }, + -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL, NUL= L, NULL, NULL }, [VIR_STORAGE_FILE_RAW] =3D { 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, 0, 0, 0, luksEncryptionInfo, - NULL, NULL, NULL, NULL }, + NULL, NULL, NULL, NULL, NULL }, [VIR_STORAGE_FILE_DIR] =3D { 0, NULL, LV_LITTLE_ENDIAN, - -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL, NULL= , NULL }, + -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL, NULL= , NULL, NULL }, [VIR_STORAGE_FILE_BOCHS] =3D { /*"Bochs Virtual HD Image", */ /* Untested */ 0, NULL, LV_LITTLE_ENDIAN, 64, 4, {0x20000}, - 32+16+16+4+4+4+4+4, 8, 1, NULL, NULL, NULL, NULL, NULL + 32+16+16+4+4+4+4+4, 8, 1, NULL, NULL, NULL, NULL, NULL, NULL }, [VIR_STORAGE_FILE_CLOOP] =3D { /* #!/bin/sh @@ -261,7 +264,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { */ /* Untested */ 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, - -1, 0, 0, NULL, NULL, NULL, NULL, NULL + -1, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }, [VIR_STORAGE_FILE_DMG] =3D { /* XXX QEMU says there's no magic for dmg, @@ -269,45 +272,45 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { * would have to match) but then disables that check. */ 0, NULL, 0, -1, 0, {0}, - -1, 0, 0, NULL, NULL, NULL, NULL, NULL + -1, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }, [VIR_STORAGE_FILE_ISO] =3D { 32769, "CD001", LV_LITTLE_ENDIAN, -2, 0, {0}, - -1, 0, 0, NULL, NULL, NULL, NULL, NULL + -1, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }, [VIR_STORAGE_FILE_VPC] =3D { 0, "conectix", LV_BIG_ENDIAN, 12, 4, {0x10000}, - 8 + 4 + 4 + 8 + 4 + 4 + 2 + 2 + 4, 8, 1, NULL, NULL, NULL, NULL, N= ULL + 8 + 4 + 4 + 8 + 4 + 4 + 2 + 2 + 4, 8, 1, NULL, NULL, NULL, NULL, N= ULL, NULL }, /* TODO: add getBackingStore function */ [VIR_STORAGE_FILE_VDI] =3D { 64, "\x7f\x10\xda\xbe", LV_LITTLE_ENDIAN, 68, 4, {0x00010001}, - 64 + 5 * 4 + 256 + 7 * 4, 8, 1, NULL, NULL, NULL, NULL, NULL}, + 64 + 5 * 4 + 256 + 7 * 4, 8, 1, NULL, NULL, NULL, NULL, NULL, NULL= }, /* Not direct file formats, but used for various drivers */ [VIR_STORAGE_FILE_FAT] =3D { 0, NULL, LV_LITTLE_ENDIAN, - -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL, NULL= , NULL }, + -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL, NULL= , NULL, NULL }, [VIR_STORAGE_FILE_VHD] =3D { 0, NULL, LV_LITTLE_ENDIAN, - -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL, NULL= , NULL }, + -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL, NULL= , NULL, NULL }, [VIR_STORAGE_FILE_PLOOP] =3D { 0, "WithouFreSpacExt", LV_LITTLE_ENDIAN, -2, 0, {0}, PLOOP_IMAGE_SIZE_OFFSET, 8, - PLOOP_SIZE_MULTIPLIER, NULL, NULL, NULL, = NULL, NULL }, + PLOOP_SIZE_MULTIPLIER, NULL, NULL, NULL, = NULL, NULL, NULL }, /* All formats with a backing store probe below here */ [VIR_STORAGE_FILE_COW] =3D { 0, "OOOM", LV_BIG_ENDIAN, 4, 4, {2}, - 4+4+1024+4, 8, 1, NULL, NULL, cowGetBackingStore, NULL, NULL + 4+4+1024+4, 8, 1, NULL, NULL, cowGetBackingStore, NULL, NULL, NULL }, [VIR_STORAGE_FILE_QCOW] =3D { 0, "QFI", LV_BIG_ENDIAN, 4, 4, {1}, QCOWX_HDR_IMAGE_SIZE, 8, 1, qcow1EncryptionInfo, - NULL, qcowXGetBackingStore, NULL, NULL + NULL, qcowXGetBackingStore, NULL, NULL, NULL }, [VIR_STORAGE_FILE_QCOW2] =3D { 0, "QFI", @@ -317,18 +320,19 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { qcow2GetClusterSize, qcowXGetBackingStore, qcow2GetDataFile, - qcow2GetFeatures + qcow2GetFeatures, + NULL }, [VIR_STORAGE_FILE_QED] =3D { /* https://wiki.qemu.org/Features/QED */ 0, "QED", LV_LITTLE_ENDIAN, -2, 0, {0}, - QED_HDR_IMAGE_SIZE, 8, 1, NULL, NULL, qedGetBackingStore, NULL, NU= LL + QED_HDR_IMAGE_SIZE, 8, 1, NULL, NULL, qedGetBackingStore, NULL, NU= LL, NULL }, [VIR_STORAGE_FILE_VMDK] =3D { 0, "KDMV", LV_LITTLE_ENDIAN, 4, 4, {1, 2, 3}, - 4+4+4, 8, 512, NULL, NULL, vmdk4GetBackingStore, NULL, NULL + 4+4+4, 8, 512, NULL, NULL, vmdk4GetBackingStore, NULL, NULL, NULL }, }; G_STATIC_ASSERT(G_N_ELEMENTS(fileTypeInfo) =3D=3D VIR_STORAGE_FILE_LAST); @@ -991,22 +995,27 @@ virStorageFileProbeGetMetadata(virStorageSource *meta, meta->capacity *=3D fileTypeInfo[meta->format].sizeMultiplier; } + VIR_FREE(meta->backingStoreRaw); + g_clear_pointer(&meta->features, virBitmapFree); + VIR_FREE(meta->dataFileRaw); + + if (fileTypeInfo[meta->format].getImageSpecific && + fileTypeInfo[meta->format].getImageSpecific(meta, buf, len) < 0) + return -1; + if (fileTypeInfo[meta->format].getClusterSize !=3D NULL) meta->clusterSize =3D fileTypeInfo[meta->format].getClusterSize(bu= f, len); - VIR_FREE(meta->backingStoreRaw); if (fileTypeInfo[meta->format].getBackingStore !=3D NULL) { fileTypeInfo[meta->format].getBackingStore(&meta->backingStoreRaw, &format, buf, len); meta->backingStoreRawFormat =3D format; } - g_clear_pointer(&meta->features, virBitmapFree); if (fileTypeInfo[meta->format].getFeatures !=3D NULL && fileTypeInfo[meta->format].getFeatures(&meta->features, meta->form= at, buf, len) < 0) return -1; - VIR_FREE(meta->dataFileRaw); if (fileTypeInfo[meta->format].getDataFile !=3D NULL) { fileTypeInfo[meta->format].getDataFile(&meta->dataFileRaw, meta->f= eatures, buf, len); --=20 2.49.0 From nobody Mon Sep 8 21:39:50 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=1748508517; cv=none; d=zohomail.com; s=zohoarc; b=LknUIN9PobneaZwwAt7wfASbzB66wnYT5/vMvo5VN2NhxiGBRGp5NggjUqEMyTa1i7lYr8snMBVp9xea+aAgjPzTfwiU6fNC32Jv+Ke2J2OuiZh0E1//aEcnkUdEWQ5DzTLoeSn5JDBBeq71nrNPXwmczwmyyZI0ypPT5LQr26Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508517; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=KFLf1CumIHE2uCuk9QBux/cyoV47yJe3Em/uWLxv0fM=; b=QL7zawwf3+M+nUUxDcbh/KOSqbYkmVAkPf3bTxbe+6I8L4cXyDCawZfEf+vya0HG4RPw7XCWQaOQkuryl1EoNYRrRuJsbW3cdKW3RyuJGQk2/XUXMXX9MGw+6WtxrpF4M1Wfgovopt2LfCJjHQNcGyw08ej8BG4ZJzCXF92G/Jw= 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 1748508517261929.371617365951; Thu, 29 May 2025 01:48:37 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4EED41633; Thu, 29 May 2025 04:48:36 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 4083B1428; Thu, 29 May 2025 04:43:50 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B89E012FF; Thu, 29 May 2025 04:43:42 -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 8E4D513B3 for ; Thu, 29 May 2025 04:43:22 -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-78-kpltcbxQMZ-R3SA9z8MtXA-1; Thu, 29 May 2025 04:43:20 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id B8E61195609E for ; Thu, 29 May 2025 08:43:19 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id ECC2E19560AF for ; Thu, 29 May 2025 08:43:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, 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=1748508202; 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=jei5wN51nilMsGtKbPle4CLFo6AGNRR4mBcNLxicnCY=; b=WHbupnOfq6lWCQubi8k6DBZXj0hJPWir1RHlS2cV5DfIT8Y8ZnUs50lCjUVip810b8Eiat /u4IGHybnoY7CiWUsF9kNgU4Tnp8qL8d7+X0GF0cppAImfZOQFM1f16xZiCHEwNefXXExE obSRpETEUx/dAFS+JpGUPqsDQrytBv0= X-MC-Unique: kpltcbxQMZ-R3SA9z8MtXA-1 X-Mimecast-MFC-AGG-ID: kpltcbxQMZ-R3SA9z8MtXA_1748508199 To: devel@lists.libvirt.org Subject: [PATCH 06/15] storage_file_probe: Refactor cowGetBackingStore into cowGetImageSpecific Date: Thu, 29 May 2025 10:43:00 +0200 Message-ID: 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-MFC-PROC-ID: 7s2nTydMALwtw7W8Nu-H_O39wreFfBBR7Q_hkUDM7-s_1748508199 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: XM5ZVJ6PCPARN27FJHQKVBLL5B7XSDK7 X-Message-ID-Hash: XM5ZVJ6PCPARN27FJHQKVBLL5B7XSDK7 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508518301116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Rename the function, adjust parameters and fix the code to fill the virStorageSource fields directly. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index 29837792e4..08fd3f2265 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -102,8 +102,10 @@ struct FileTypeInfo { }; -static int cowGetBackingStore(char **, int *, - const char *, size_t); +static int +cowGetImageSpecific(virStorageSource *meta, + const char *buf, + size_t buf_size); static unsigned long long qcow2GetClusterSize(const char *buf, size_t buf_size); @@ -303,7 +305,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { [VIR_STORAGE_FILE_COW] =3D { 0, "OOOM", LV_BIG_ENDIAN, 4, 4, {2}, - 4+4+1024+4, 8, 1, NULL, NULL, cowGetBackingStore, NULL, NULL, NULL + 4+4+1024+4, 8, 1, NULL, NULL, NULL, NULL, NULL, cowGetImageSpecific }, [VIR_STORAGE_FILE_QCOW] =3D { 0, "QFI", @@ -375,23 +377,22 @@ G_STATIC_ASSERT(G_N_ELEMENTS(qcow2IncompatibleFeature= Array) =3D=3D QCOW2_INCOMPATIBL static int -cowGetBackingStore(char **res, - int *format, - const char *buf, - size_t buf_size) +cowGetImageSpecific(virStorageSource *meta, + const char *buf, + size_t buf_size) { #define COW_FILENAME_MAXLEN 1024 - *res =3D NULL; - *format =3D VIR_STORAGE_FILE_AUTO; - if (buf_size < 4+4+ COW_FILENAME_MAXLEN) + g_clear_pointer(&meta->backingStoreRaw, g_free); + + if (buf_size < 4 + 4 + COW_FILENAME_MAXLEN) return 0; - if (buf[4+4] =3D=3D '\0') { /* cow_header_v2.backing_file[0] */ - *format =3D VIR_STORAGE_FILE_NONE; + if (buf[4 + 4] =3D=3D '\0') { /* cow_header_v2.backing_file[0] */ + meta->backingStoreRawFormat =3D VIR_STORAGE_FILE_NONE; return 0; } - *res =3D g_strndup((const char *)buf + 4 + 4, COW_FILENAME_MAXLEN); + meta->backingStoreRaw =3D g_strndup((const char *)buf + 4 + 4, COW_FIL= ENAME_MAXLEN); return 0; } --=20 2.49.0 From nobody Mon Sep 8 21:39:50 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=1748508541; cv=none; d=zohomail.com; s=zohoarc; b=IhuAnzlfYdvj3hPhGpqUJC2TfZpSJqrsibZZnUXTSd4VmJnTRMB/cONizRxGF0B9w8S9ISID+vsuPmd/S4g8kAk5HQuF8vVTYkrJeqYAVq8FCRxgHXnqVvWWoOW5+/qPzcCq71T+lSmLvBPEbfzgEr6zZG0Jg2EYn+QBge+DCns= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508541; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=CwZlUqV4m1EDcoHT9v3QGwHqnIj9KNUWTEw22h9Oer4=; b=Jvs8KvdPq35R0/Z6BHqzMhWDKxyO6PcHCJqO5wlzfIf2oneaWj7N6opOzUQERm7NnnaDqqbj55IQYyiU9HtOudFFSm+uN6yrNi0AsALkTvpR5/gT3iDASQpFqjxox/7h+HvzEGYjK8vjuXh7GBFbi/6i4i18RRsKrIA3UFE7ris= 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 1748508541317468.63400813858186; Thu, 29 May 2025 01:49:01 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 6F4151350; Thu, 29 May 2025 04:49:00 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id F1EF813C9; Thu, 29 May 2025 04:43:51 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 9F53512E1; Thu, 29 May 2025 04:43:47 -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 DAD4F153F for ; Thu, 29 May 2025 04:43:23 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-558-S7y5ZYHHPAmt7MA2SjekBA-1; Thu, 29 May 2025 04:43:21 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 254BD18001EA for ; Thu, 29 May 2025 08:43:21 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4270219560AF for ; Thu, 29 May 2025 08:43:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, 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=1748508203; 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=k+RAjtmIVfOyP/MI88q3ZQyyILCGjmzBk5r8IaN+Z+s=; b=M7MdqQ+azeEoCwr4sAF8d7FquKCDxVk00AOK2o9g6SDjOky+MdoVlc37nsADdyB8YaRwf0 cM+ZeL+hR/WAvNoDxT7Lp/CAxtAiaTSPlqhj/7KqGfWI1Sx1k+XXr+5rmXz0fUyKqRGhhB q5OomH3EuvET0uEufWDmXQJqLTnS+Gg= X-MC-Unique: S7y5ZYHHPAmt7MA2SjekBA-1 X-Mimecast-MFC-AGG-ID: S7y5ZYHHPAmt7MA2SjekBA_1748508201 To: devel@lists.libvirt.org Subject: [PATCH 07/15] storage_file_probe: Refactor qedGetBackingStore into qedGetImageSpecific Date: Thu, 29 May 2025 10:43:01 +0200 Message-ID: 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-MFC-PROC-ID: oWCJI3F0U9wbggyvp1DPxD93DRspPCIdzcMlD54lrY4_1748508201 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: Y7XL3VQ4BRSJQICR3TZLZNKSJVIOUXH3 X-Message-ID-Hash: Y7XL3VQ4BRSJQICR3TZLZNKSJVIOUXH3 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508542580116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Change to the new function prototype and adjust the code to fill the fields in virStorageSource directly. The code also converts the copying of the backing file string from 'g_new0' + 'memcpy' to 'g_strndup' as we treat it as a string later on. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 28 ++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index 08fd3f2265..1544dded5c 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -117,7 +117,9 @@ static int qcow2GetFeatures(virBitmap **features, int f= ormat, static int vmdk4GetBackingStore(char **, int *, const char *, size_t); static int -qedGetBackingStore(char **, int *, const char *, size_t); +qedGetImageSpecific(virStorageSource *meta, + const char *buf, + size_t buf_size); #define QCOWX_HDR_VERSION (4) #define QCOWX_HDR_BACKING_FILE_OFFSET (QCOWX_HDR_VERSION+4) @@ -329,7 +331,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { /* https://wiki.qemu.org/Features/QED */ 0, "QED", LV_LITTLE_ENDIAN, -2, 0, {0}, - QED_HDR_IMAGE_SIZE, 8, 1, NULL, NULL, qedGetBackingStore, NULL, NU= LL, NULL + QED_HDR_IMAGE_SIZE, 8, 1, NULL, NULL, NULL, NULL, NULL, qedGetImag= eSpecific }, [VIR_STORAGE_FILE_VMDK] =3D { 0, "KDMV", @@ -656,21 +658,22 @@ vmdk4GetBackingStore(char **res, } static int -qedGetBackingStore(char **res, - int *format, - const char *buf, - size_t buf_size) +qedGetImageSpecific(virStorageSource *meta, + const char *buf, + size_t buf_size) { unsigned long long flags; unsigned long offset, size; - *res =3D NULL; + g_clear_pointer(&meta->backingStoreRaw, g_free); + /* Check if this image has a backing file */ if (buf_size < QED_HDR_FEATURES_OFFSET+8) return 0; + flags =3D virReadBufInt64LE(buf + QED_HDR_FEATURES_OFFSET); if (!(flags & QED_F_BACKING_FILE)) { - *format =3D VIR_STORAGE_FILE_NONE; + meta->backingStoreRawFormat =3D VIR_STORAGE_FILE_NONE; return 0; } @@ -685,14 +688,13 @@ qedGetBackingStore(char **res, return 0; if (offset + size > buf_size || offset + size < offset) return 0; - *res =3D g_new0(char, size + 1); - memcpy(*res, buf + offset, size); - (*res)[size] =3D '\0'; + + meta->backingStoreRaw =3D g_strndup(buf + offset, size); if (flags & QED_F_BACKING_FORMAT_NO_PROBE) - *format =3D VIR_STORAGE_FILE_RAW; + meta->backingStoreRawFormat =3D VIR_STORAGE_FILE_RAW; else - *format =3D VIR_STORAGE_FILE_AUTO_SAFE; + meta->backingStoreRawFormat =3D VIR_STORAGE_FILE_AUTO_SAFE; return 0; } --=20 2.49.0 From nobody Mon Sep 8 21:39:50 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=1748508576; cv=none; d=zohomail.com; s=zohoarc; b=HZjbl7LSzkET22d0bWL2hh63SIDOutvtI4oR43gsBwGCylv9bM5l5VrU45WsI1vicopU1jdn3mFTVczCm0y55CwvBnXfNfZM/e9Yd+CTg20RVPsb8eDiku6iUfjxuUe6cGCVcnQ4nJW2eCcmWMnYb2lAB9T5l84ox7/haipwgTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508576; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=ixzCGLCsaQxSRrZ96PjMo/C3bqjopf5bkbvki4Dq2QI=; b=QT3OV9CVD5Ov5gfSuGtK44oggtNI9XEE8/VRYGQGjP/PV7t9ipXhoc6L0TrFXwXjXiCH6Wx+lpth4Nt2drrLxTVfWBQueM5WmzDyWY1Z19c3Dq3iOv0EVBxmNd6A1tvEA2sCc0fqrnt0ZOJLhYpt+VU/93nx/imh4vrJrt/qq6w= 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 1748508576228598.3236705492144; Thu, 29 May 2025 01:49:36 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3D0D01878; Thu, 29 May 2025 04:49:35 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C5D2B1401; Thu, 29 May 2025 04:43:55 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E50B313C4; Thu, 29 May 2025 04:43:47 -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 762AB13D3 for ; Thu, 29 May 2025 04:43:25 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-531-VYyu4LauNyWPFENFCfMmpw-1; Thu, 29 May 2025 04:43:23 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6453D1800873 for ; Thu, 29 May 2025 08:43:22 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9C6FE19560AF for ; Thu, 29 May 2025 08:43:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, 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=1748508205; 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=YBTv+I3ffhsvr4kWUJt6GQ3gbcm0sMvW7QVGMC5As8Y=; b=gOLGlS9f9q3VNs9MPorbpRxoPx9s2xXS1qxVq7c0zcKhhgGc9YyP5QDLIit8w8agnoLjek ZB55trMWK8RAiXtVv/WC05w4UBvc466HZ8P6/UXzy7qTVFBPqWT9mSaYejRb6jgPeekiq5 pSEae+Ciu3v1TtBM+QDkONUAg2/goo0= X-MC-Unique: VYyu4LauNyWPFENFCfMmpw-1 X-Mimecast-MFC-AGG-ID: VYyu4LauNyWPFENFCfMmpw_1748508202 To: devel@lists.libvirt.org Subject: [PATCH 08/15] storage_file_probe: Refactor vmdk4GetBackingStore into vmdk4GetImageSpecific Date: Thu, 29 May 2025 10:43:02 +0200 Message-ID: <88dd5cdf323ef4e0d224ba599c3a2fcc30d27105.1748507931.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-MFC-PROC-ID: tqb1HhzHGZMqVmbqKOtmvF2himcWBxLCYMzRoIsd37k_1748508202 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ZDUNESHXJHW2FFMWP3ZKLKOM2EJZ7XEY X-Message-ID-Hash: ZDUNESHXJHW2FFMWP3ZKLKOM2EJZ7XEY 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508577052116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Change to the new function prototype and adjust the code to fill the fields in virStorageSource directly. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index 1544dded5c..e741bccd44 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -114,8 +114,10 @@ static int qcowXGetBackingStore(char **, int *, static int qcow2GetDataFile(char **, virBitmap *, char *, size_t); static int qcow2GetFeatures(virBitmap **features, int format, char *buf, ssize_t len); -static int vmdk4GetBackingStore(char **, int *, - const char *, size_t); +static int +vmdk4GetImageSpecific(virStorageSource *meta, + const char *buf, + size_t buf_size); static int qedGetImageSpecific(virStorageSource *meta, const char *buf, @@ -336,7 +338,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { [VIR_STORAGE_FILE_VMDK] =3D { 0, "KDMV", LV_LITTLE_ENDIAN, 4, 4, {1, 2, 3}, - 4+4+4, 8, 512, NULL, NULL, vmdk4GetBackingStore, NULL, NULL, NULL + 4+4+4, 8, 512, NULL, NULL, NULL, NULL, NULL, vmdk4GetImageSpecific }, }; G_STATIC_ASSERT(G_N_ELEMENTS(fileTypeInfo) =3D=3D VIR_STORAGE_FILE_LAST); @@ -607,10 +609,9 @@ qcow2GetDataFile(char **res, static int -vmdk4GetBackingStore(char **res, - int *format, - const char *buf, - size_t buf_size) +vmdk4GetImageSpecific(virStorageSource *meta, + const char *buf, + size_t buf_size) { static const char prefix[] =3D "parentFileNameHint=3D\""; char *start, *end; @@ -619,7 +620,7 @@ vmdk4GetBackingStore(char **res, desc =3D g_new0(char, VIR_STORAGE_MAX_HEADER); - *res =3D NULL; + g_clear_pointer(&meta->backingStoreRaw, g_free); /* * Technically this should have been VMDK, since * VMDK spec / VMware impl only support VMDK backed @@ -627,7 +628,7 @@ vmdk4GetBackingStore(char **res, * does probing on VMDK backing files, hence we set * AUTO */ - *format =3D VIR_STORAGE_FILE_AUTO; + meta->backingStoreRawFormat =3D VIR_STORAGE_FILE_AUTO; if (buf_size <=3D 0x200) return 0; @@ -639,7 +640,7 @@ vmdk4GetBackingStore(char **res, desc[len] =3D '\0'; start =3D strstr(desc, prefix); if (start =3D=3D NULL) { - *format =3D VIR_STORAGE_FILE_NONE; + meta->backingStoreRawFormat =3D VIR_STORAGE_FILE_NONE; return 0; } start +=3D strlen(prefix); @@ -648,11 +649,11 @@ vmdk4GetBackingStore(char **res, return 0; if (end =3D=3D start) { - *format =3D VIR_STORAGE_FILE_NONE; + meta->backingStoreRawFormat =3D VIR_STORAGE_FILE_NONE; return 0; } *end =3D '\0'; - *res =3D g_strdup(start); + meta->backingStoreRaw =3D g_strdup(start); return 0; } --=20 2.49.0 From nobody Mon Sep 8 21:39:50 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=1748508605; cv=none; d=zohomail.com; s=zohoarc; b=B7n8TpnZObVqS16jcLGjfH8ja5fXD9zD3cauPtTciIm/sAVS4+c1xP6P2Rk6PToLNU77jF+yyfGTyo11Jx6Y1a4SJuUmMuFiV1VpOZVmw4/zZUW/eklUAOkAq1tCRWJGqwfVf3joR8EZVpxb40F0kegV71nNiQY6gmDCt1EgRGo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508605; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=dqiZXALuv80nSLrwcKOzTiaoECbKM965gbE/HHdf7io=; b=GaBzdxngvgbbzTt6Hta7x+4PGY+lzo2bpJtyY64XgR3uiSCVdsUbLYFYmm7F+69K+xJLaBOQzmmVHKd0jo1xqMuLen5acmmr8KlmqlWViS7rlYLJveONm3Ah3yhFNajjDfL93sJmOz9CCpmLVeEwnlAIa9C1skoYAXmc+1P5J3M= 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 1748508605933150.33241898917208; Thu, 29 May 2025 01:50:05 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E7B6512B2; Thu, 29 May 2025 04:50:04 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id A9E6815E9; Thu, 29 May 2025 04:43:57 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 217ED1494; Thu, 29 May 2025 04:43:48 -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 21BD215BF for ; Thu, 29 May 2025 04:43:26 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-417-kf-L0vcMO4mkt_y5yAHBWw-1; Thu, 29 May 2025 04:43:24 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A680818004AD for ; Thu, 29 May 2025 08:43:23 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DC56C19560AF for ; Thu, 29 May 2025 08:43:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, 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=1748508205; 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=VdveEZpkreaYpCRkzaALI3rIB/1mCPQUYudFA4xD5WU=; b=ODRhbzJ7Hqzjga9kU8of8xZxTIC7oF5gDhQHKoSrkXWQX8Sp6CsKol+0rgLSU80CRFNlWl iSm6FFHEQzcylwf/jwGALy1n8XbGj6f603yp20xpnO+dL/jk/shWNQ8qM3rpkXvN+FPEzk q7x6PlcxUSLQFTHFPbv3mZR25yXQISA= X-MC-Unique: kf-L0vcMO4mkt_y5yAHBWw-1 X-Mimecast-MFC-AGG-ID: kf-L0vcMO4mkt_y5yAHBWw_1748508203 To: devel@lists.libvirt.org Subject: [PATCH 09/15] storage_file_probe: Refactor qcowXGetBackingStore into specific callbacks for qcow and qcow2 Date: Thu, 29 May 2025 10:43:03 +0200 Message-ID: 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-MFC-PROC-ID: JB1NLbKuRfIXvimabiiRdQH2clamz-EzBGlZLXlxbY8_1748508203 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: JDEIEDTAMCZK33XYF6U2FCD2XICYFBXJ X-Message-ID-Hash: JDEIEDTAMCZK33XYF6U2FCD2XICYFBXJ 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508607381116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Change qcowXGetBackingStore to use the new function prototype which fills virStorageSource directly. Convert the copying of the backing file string from 'g_new0' + 'memcpy' to 'g_strndup' as we treat it as a string. Introduce qcowGetImageSpecific (as a wrapper for qcowXGetBackingStore) and qcow2GetImageSpecific. The latter of the two will be used to collect all the qcow2-specific code later on, but for now it just parses the backing store and the format. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 69 +++++++++++++++++++-------- 1 file changed, 48 insertions(+), 21 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index e741bccd44..ce8ba4b884 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -106,11 +106,17 @@ static int cowGetImageSpecific(virStorageSource *meta, const char *buf, size_t buf_size); +static int +qcowGetImageSpecific(virStorageSource *meta, + const char *buf, + size_t buf_size); +static int +qcow2GetImageSpecific(virStorageSource *meta, + const char *buf, + size_t buf_size); static unsigned long long qcow2GetClusterSize(const char *buf, size_t buf_size); -static int qcowXGetBackingStore(char **, int *, - const char *, size_t); static int qcow2GetDataFile(char **, virBitmap *, char *, size_t); static int qcow2GetFeatures(virBitmap **features, int format, char *buf, ssize_t len); @@ -316,7 +322,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { LV_BIG_ENDIAN, 4, 4, {1}, QCOWX_HDR_IMAGE_SIZE, 8, 1, qcow1EncryptionInfo, - NULL, qcowXGetBackingStore, NULL, NULL, NULL + NULL, NULL, NULL, NULL, qcowGetImageSpecific }, [VIR_STORAGE_FILE_QCOW2] =3D { 0, "QFI", @@ -324,10 +330,10 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { QCOWX_HDR_IMAGE_SIZE, 8, 1, qcow2EncryptionInfo, qcow2GetClusterSize, - qcowXGetBackingStore, + NULL, qcow2GetDataFile, qcow2GetFeatures, - NULL + qcow2GetImageSpecific }, [VIR_STORAGE_FILE_QED] =3D { /* https://wiki.qemu.org/Features/QED */ @@ -545,45 +551,66 @@ qcow2GetClusterSize(const char *buf, static int -qcowXGetBackingStore(char **res, - int *format, +qcowXGetBackingStore(virStorageSource *meta, const char *buf, size_t buf_size) { unsigned long long offset; unsigned int size; - *res =3D NULL; - *format =3D VIR_STORAGE_FILE_AUTO; + g_clear_pointer(&meta->backingStoreRaw, g_free); + meta->backingStoreRawFormat =3D VIR_STORAGE_FILE_AUTO; if (buf_size < QCOWX_HDR_BACKING_FILE_OFFSET+8+4) return 0; offset =3D virReadBufInt64BE(buf + QCOWX_HDR_BACKING_FILE_OFFSET); - if (offset > buf_size) - return 0; + size =3D virReadBufInt32BE(buf + QCOWX_HDR_BACKING_FILE_SIZE); - if (offset =3D=3D 0) { - *format =3D VIR_STORAGE_FILE_NONE; + if (offset =3D=3D 0 || size =3D=3D 0) { + meta->backingStoreRawFormat =3D VIR_STORAGE_FILE_NONE; return 0; } - size =3D virReadBufInt32BE(buf + QCOWX_HDR_BACKING_FILE_SIZE); - if (size =3D=3D 0) { - *format =3D VIR_STORAGE_FILE_NONE; + if (offset > buf_size) return 0; - } if (size > 1023) return 0; if (offset + size > buf_size || offset + size < offset) return 0; - *res =3D g_new0(char, size + 1); - memcpy(*res, buf + offset, size); - (*res)[size] =3D '\0'; - if (qcow2GetExtensions(buf, buf_size, format, NULL) < 0) + meta->backingStoreRaw =3D g_strndup(buf + offset, size); + + return 0; +} + + +static int +qcowGetImageSpecific(virStorageSource *meta, + const char *buf, + size_t buf_size) +{ + return qcowXGetBackingStore(meta, buf, buf_size); +} + + +static int +qcow2GetImageSpecific(virStorageSource *meta, + const char *buf, + size_t buf_size) +{ + int format; + + if (qcowXGetBackingStore(meta, buf, buf_size) < 0) + return -1; + + format =3D meta->backingStoreRawFormat; + + if (qcow2GetExtensions(buf, buf_size, &format, NULL) < 0) return 0; + meta->backingStoreRawFormat =3D format; + return 0; } --=20 2.49.0 From nobody Mon Sep 8 21:39:50 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=1748508632; cv=none; d=zohomail.com; s=zohoarc; b=Z3vT3t0FHIB9U/qnlinS+YySeMHRMqDsCIIrl6NF3mMpevW3uqZnFEcqS7876zUNFPVqTC94S8XGqsYXWw95pwmtI3/L5uDIB5rlEge/mOlLi7j66z+78UH82M1cltnLYNj4usdUJ6dlpVpFfS8H5RabcDZx6imf6RhitsG4qkA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508632; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=tthUZjwXB/WICQz6FwuS6m7Pskv+cJ7ClTx8wjgVEDg=; b=csM4HALdRkG7KkK0uDhOWJH3nCXLdWN62fg9btRwQHI3ePrXsYgZfSx8ERgcC6+5DFC66KaEDtvA6WDPDXdOJIey56lTsKBY+VQn9TJappbNSVYXlESINqAKYzQN8KjbgeRPmM31ZIZ8TDsFPiMhVun74UYeOEPK41WcVeQ9rZk= 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 1748508632154437.49649650770743; Thu, 29 May 2025 01:50:32 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3AEF5164B; Thu, 29 May 2025 04:50:31 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 61AC41711; Thu, 29 May 2025 04:44:00 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id AAACD1406; Thu, 29 May 2025 04:43:48 -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 ADA8914AE for ; Thu, 29 May 2025 04:43:27 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-596-2gsXMBhiPMmlLwJ3RYi3Sw-1; Thu, 29 May 2025 04:43:25 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E6C4F180034A for ; Thu, 29 May 2025 08:43:24 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 269ED19560AF for ; Thu, 29 May 2025 08:43:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, 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=1748508207; 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=yi7REij1Go86Wpa/dSqn8a7dnP1fG04rInbZ5IfLgHg=; b=cKKSrv72VZhZ/YkbHBY1WlkbPPujbjRhYhaEtpFrdAx862BMtmVqlHM8egiNNRXB/OZJxi EU/PlQ3QAnF24XQaHWEDRJNovzy7+nxseiWekTnl++w8VhZry2RcoZka4mk5O3x+b2wX5X FQxmPHaEHsQDtWSy6rrg4hbNF5/Rauo= X-MC-Unique: 2gsXMBhiPMmlLwJ3RYi3Sw-1 X-Mimecast-MFC-AGG-ID: 2gsXMBhiPMmlLwJ3RYi3Sw_1748508205 To: devel@lists.libvirt.org Subject: [PATCH 10/15] storage_file_probe: Move logic from qcow2GetClusterSize to qcow2GetImageSpecific Date: Thu, 29 May 2025 10:43:04 +0200 Message-ID: <1d0603c49173a05bab2d77ac1c6db732aa44cd9a.1748507931.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-MFC-PROC-ID: z2M_40Ir3JtSsPIWmUP3O_xdvKcEF8ZL_FJMt6bKY7Y_1748508205 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: TNSQHQIR4OAGT4NRSDHQFESLUP7A2EW4 X-Message-ID-Hash: TNSQHQIR4OAGT4NRSDHQFESLUP7A2EW4 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508633570116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Move the cluster size parser into the image specific code for qcow2, which will later allow us to remove the callback for cluster size which is not used by any other format. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 31 ++++++++------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index ce8ba4b884..21a1013102 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -114,9 +114,6 @@ static int qcow2GetImageSpecific(virStorageSource *meta, const char *buf, size_t buf_size); -static unsigned long long -qcow2GetClusterSize(const char *buf, - size_t buf_size); static int qcow2GetDataFile(char **, virBitmap *, char *, size_t); static int qcow2GetFeatures(virBitmap **features, int format, char *buf, ssize_t len); @@ -329,7 +326,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { LV_BIG_ENDIAN, 4, 4, {2, 3}, QCOWX_HDR_IMAGE_SIZE, 8, 1, qcow2EncryptionInfo, - qcow2GetClusterSize, + NULL, NULL, qcow2GetDataFile, qcow2GetFeatures, @@ -532,24 +529,6 @@ qcow2GetExtensions(const char *buf, } -static unsigned long long -qcow2GetClusterSize(const char *buf, - size_t buf_size) -{ - int clusterBits =3D 0; - - if ((QCOWX_HDR_CLUSTER_BITS_OFFSET + 4) > buf_size) - return 0; - - clusterBits =3D virReadBufInt32BE(buf + QCOWX_HDR_CLUSTER_BITS_OFFSET); - - if (clusterBits > 0) - return 1ULL << clusterBits; - - return 0; -} - - static int qcowXGetBackingStore(virStorageSource *meta, const char *buf, @@ -601,6 +580,14 @@ qcow2GetImageSpecific(virStorageSource *meta, { int format; + meta->clusterSize =3D 0; + if (buf_size > (QCOWX_HDR_CLUSTER_BITS_OFFSET + 4)) { + int clusterBits =3D virReadBufInt32BE(buf + QCOWX_HDR_CLUSTER_BITS= _OFFSET); + + if (clusterBits > 0) + meta->clusterSize =3D 1ULL << clusterBits; + } + if (qcowXGetBackingStore(meta, buf, buf_size) < 0) return -1; --=20 2.49.0 From nobody Mon Sep 8 21:39:50 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=1748508654; cv=none; d=zohomail.com; s=zohoarc; b=j32/s1xAlgPnTjUF0OldK07pn355NwSPlvKN7NpCINeEMaWTi67gDZaweUKuLsfErKT/8X/KJYUZA7BebqbblI/57S8W6CCz9KNOrlF9aWlTPXpvwv+BDEr6FQB0Ti6UsJCHby3AhPU2UsuTDvL63pPdEgstu9hARp+pcoF82ys= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508654; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=jsoyQdNLamQRi98EM1seAw4GjUuHoYXQHxM+wk6OR6c=; b=Y2EvqutaKoq2demukhTKSaEAcss6wG00kiiW+SyIHty3uvebgqiPVpjtAaUs/zI+WjsN5kSL0S+0i8CNAvcxrw6yh/deNXqp89ZFrTV2D+tcDXUU3j3sRX33zYAN63p26I7ggN1LQU8hmga2M1B+6L6QsB7kQ1iPAkaTxV2Sxq4= 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 1748508654187509.06192369223106; Thu, 29 May 2025 01:50:54 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 37EAE164B; Thu, 29 May 2025 04:50:53 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id E4A84145F; Thu, 29 May 2025 04:44:03 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 023DC12AF; Thu, 29 May 2025 04:43:50 -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 ABA3C1298 for ; Thu, 29 May 2025 04:43:28 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-659-KOPhS7Q3O6yAD3jSLR7ZrQ-1; Thu, 29 May 2025 04:43:26 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 2D60A180045B for ; Thu, 29 May 2025 08:43:26 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 668CB19560AF for ; Thu, 29 May 2025 08:43:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, 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=1748508208; 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=UWyP112frDB6AnJCyO9gIhoJyi7IboNb5Up5jyDKUSw=; b=YwSZqEL27MY6WS8Ge+WLiPLTkzeHwInAqCH2SWZN7f+scidgU9S/DbEE/k3NXhYpoO2xIK Or9ErvnH9XBijx7VRVeWFkCsVDNnoV0PBJa/7utK0igNQL2Mkd+Va7nmndFSfm8BizE3b0 15nR8tHDWkK2GyLLp4WfbSoeuFxDUQo= X-MC-Unique: KOPhS7Q3O6yAD3jSLR7ZrQ-1 X-Mimecast-MFC-AGG-ID: KOPhS7Q3O6yAD3jSLR7ZrQ_1748508206 To: devel@lists.libvirt.org Subject: [PATCH 11/15] storage_file_probe: Move qcow2GetFeatures(ProcessGroup) functions Date: Thu, 29 May 2025 10:43:05 +0200 Message-ID: <782cfcb6853af276d2324b4cf1d65251a47d4f8c.1748507931.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-MFC-PROC-ID: mlAAm5-KhCFuolTIfCW3TKUEiEKXhjrOx7GZFctLhGw_1748508206 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: D3G6LOIXBABVJRZ5XROS6QNLOY3P2CSP X-Message-ID-Hash: D3G6LOIXBABVJRZ5XROS6QNLOY3P2CSP 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508655929116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Move the two functions to where they will be used. Subsequent patches will refactor the control flow so that they will no longer be declared ahead of time. Moving them in a separate patch will make the changes in the refactor more clear to see. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 96 +++++++++++++-------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index 21a1013102..b357fdeb66 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -573,6 +573,54 @@ qcowGetImageSpecific(virStorageSource *meta, } +static void +qcow2GetFeaturesProcessGroup(uint64_t bits, + const virStorageFileFeature *featuremap, + size_t nfeatures, + virBitmap *features) +{ + size_t i; + + for (i =3D 0; i < nfeatures; i++) { + if ((bits & ((uint64_t) 1 << i)) && + featuremap[i] !=3D VIR_STORAGE_FILE_FEATURE_LAST) + ignore_value(virBitmapSetBit(features, featuremap[i])); + } +} + + +static int +qcow2GetFeatures(virBitmap **features, + int format, + char *buf, + ssize_t len) +{ + int version =3D -1; + + version =3D virReadBufInt32BE(buf + fileTypeInfo[format].versionOffset= ); + + if (version =3D=3D 2) + return 0; + + if (len < QCOW2v3_HDR_SIZE) + return -1; + + *features =3D virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST); + + qcow2GetFeaturesProcessGroup(virReadBufInt64BE(buf + QCOW2v3_HDR_FEATU= RES_COMPATIBLE), + qcow2CompatibleFeatureArray, + G_N_ELEMENTS(qcow2CompatibleFeatureArray), + *features); + + qcow2GetFeaturesProcessGroup(virReadBufInt64BE(buf + QCOW2v3_HDR_FEATU= RES_INCOMPATIBLE), + qcow2IncompatibleFeatureArray, + G_N_ELEMENTS(qcow2IncompatibleFeatureArra= y), + *features); + + return 0; +} + + static int qcow2GetImageSpecific(virStorageSource *meta, const char *buf, @@ -832,54 +880,6 @@ virStorageFileProbeFormatFromBuf(const char *path, } -static void -qcow2GetFeaturesProcessGroup(uint64_t bits, - const virStorageFileFeature *featuremap, - size_t nfeatures, - virBitmap *features) -{ - size_t i; - - for (i =3D 0; i < nfeatures; i++) { - if ((bits & ((uint64_t) 1 << i)) && - featuremap[i] !=3D VIR_STORAGE_FILE_FEATURE_LAST) - ignore_value(virBitmapSetBit(features, featuremap[i])); - } -} - - -static int -qcow2GetFeatures(virBitmap **features, - int format, - char *buf, - ssize_t len) -{ - int version =3D -1; - - version =3D virReadBufInt32BE(buf + fileTypeInfo[format].versionOffset= ); - - if (version =3D=3D 2) - return 0; - - if (len < QCOW2v3_HDR_SIZE) - return -1; - - *features =3D virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST); - - qcow2GetFeaturesProcessGroup(virReadBufInt64BE(buf + QCOW2v3_HDR_FEATU= RES_COMPATIBLE), - qcow2CompatibleFeatureArray, - G_N_ELEMENTS(qcow2CompatibleFeatureArray), - *features); - - qcow2GetFeaturesProcessGroup(virReadBufInt64BE(buf + QCOW2v3_HDR_FEATU= RES_INCOMPATIBLE), - qcow2IncompatibleFeatureArray, - G_N_ELEMENTS(qcow2IncompatibleFeatureArra= y), - *features); - - return 0; -} - - static bool virStorageFileHasEncryptionFormat(const struct FileEncryptionInfo *info, char *buf, --=20 2.49.0 From nobody Mon Sep 8 21:39:50 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=1748508682; cv=none; d=zohomail.com; s=zohoarc; b=j9CjPZHfIQxx0K0EJrdRCHE3MY3SZGEYfNiVxJdCdwun9/B9mu3d9mYO/K9rh69YX472lETmaXWNrVmMlkZjLNZwPJ0WvlYheDcYZ2pVydlLJevVu53lDD4Gf3kPj6WQswAIj/UGV52xPfKS+uI/KmqD8+BAjn17HnK/7Fxwf2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508682; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=eJMNCQtWWVwonU/SlehEOIYrf7HKizIMyqeeELygNXE=; b=XmsNQRIDTAIL+mCo8DM1ve6RtApdQTAH0R394Rn2Qv5WP0zUDKtuJZKWTxxxYjxmfe+rz3f0awctZ63PEyVDRjt9kDoJ9tvdQHa9yLMViMvDTSXhK+M08FwtquBIsT1gSmoV72scyyXoydcP0HIuvkrHArD7yy7Sf/NBCTCalJo= 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 174850868207086.59537714729493; Thu, 29 May 2025 01:51:22 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 171F817CE; Thu, 29 May 2025 04:51:21 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2A6381772; Thu, 29 May 2025 04:44:06 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C2CB315E9; Thu, 29 May 2025 04:43:51 -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 36FA912B1 for ; Thu, 29 May 2025 04:43:30 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-648-LPnSYUAoNqq4n_BoF55aOw-1; Thu, 29 May 2025 04:43:28 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 68AD71800DA1 for ; Thu, 29 May 2025 08:43:27 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A15A019560AF for ; Thu, 29 May 2025 08:43:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, 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=1748508209; 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=B8+qeR633nGAZmbCqIWdJe60Z9eYSYA5p+2qKmYQgg8=; b=EbTuna7knjkf1MUV3ZDwwC4v3izu09sB8icRvWwxPynk0WpJxGcUbUqGOmks29u7iQNjpS 0ARLAacS+q9Z+sV/3HciecOK4LY/uzMiXf9242xCMMxn+qssrtKLTydPaZ7d+vA94YYwnV CVvP9FKoUvJzzNT9qe5dUdAsJvgjKas= X-MC-Unique: LPnSYUAoNqq4n_BoF55aOw-1 X-Mimecast-MFC-AGG-ID: LPnSYUAoNqq4n_BoF55aOw_1748508207 To: devel@lists.libvirt.org Subject: [PATCH 12/15] storage_file_probe: Call qcow2GetFeatures from qcow2GetImageSpecific Date: Thu, 29 May 2025 10:43:06 +0200 Message-ID: <7911f8acb712cf4393365b02125a6a47c9bf06eb.1748507931.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-MFC-PROC-ID: ixK_An11RWYrj2Ousq9cP2eHJ3twwxWvN02ncYFn2H0_1748508207 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5RO37AFEQ624JMEHXOBACMJD2MZCZXLW X-Message-ID-Hash: 5RO37AFEQ624JMEHXOBACMJD2MZCZXLW 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508684663116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Parse qcow2 feature flags from qcow2GetImageSpecific. To achieve that qcow2GetFeatures is refactored to take virStorageSource directly and fill the data. To avoid the need to pass 'format' the parsing of the qcow2 version is changed to access the offset directly (same as in qcow2GetExtensions) Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index b357fdeb66..10e159c27b 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -115,8 +115,6 @@ qcow2GetImageSpecific(virStorageSource *meta, const char *buf, size_t buf_size); static int qcow2GetDataFile(char **, virBitmap *, char *, size_t); -static int qcow2GetFeatures(virBitmap **features, int format, - char *buf, ssize_t len); static int vmdk4GetImageSpecific(virStorageSource *meta, const char *buf, @@ -329,7 +327,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { NULL, NULL, qcow2GetDataFile, - qcow2GetFeatures, + NULL, qcow2GetImageSpecific }, [VIR_STORAGE_FILE_QED] =3D { @@ -590,14 +588,13 @@ qcow2GetFeaturesProcessGroup(uint64_t bits, static int -qcow2GetFeatures(virBitmap **features, - int format, - char *buf, +qcow2GetFeatures(virStorageSource *meta, + const char *buf, ssize_t len) { - int version =3D -1; + int version =3D virReadBufInt32BE(buf + QCOWX_HDR_VERSION); - version =3D virReadBufInt32BE(buf + fileTypeInfo[format].versionOffset= ); + g_clear_pointer(&meta->features, virBitmapFree); if (version =3D=3D 2) return 0; @@ -605,17 +602,17 @@ qcow2GetFeatures(virBitmap **features, if (len < QCOW2v3_HDR_SIZE) return -1; - *features =3D virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST); + meta->features =3D virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST); qcow2GetFeaturesProcessGroup(virReadBufInt64BE(buf + QCOW2v3_HDR_FEATU= RES_COMPATIBLE), qcow2CompatibleFeatureArray, G_N_ELEMENTS(qcow2CompatibleFeatureArray), - *features); + meta->features); qcow2GetFeaturesProcessGroup(virReadBufInt64BE(buf + QCOW2v3_HDR_FEATU= RES_INCOMPATIBLE), qcow2IncompatibleFeatureArray, G_N_ELEMENTS(qcow2IncompatibleFeatureArra= y), - *features); + meta->features); return 0; } @@ -639,6 +636,9 @@ qcow2GetImageSpecific(virStorageSource *meta, if (qcowXGetBackingStore(meta, buf, buf_size) < 0) return -1; + if (qcow2GetFeatures(meta, buf, buf_size) < 0) + return -1; + format =3D meta->backingStoreRawFormat; if (qcow2GetExtensions(buf, buf_size, &format, NULL) < 0) --=20 2.49.0 From nobody Mon Sep 8 21:39:50 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=1748508713; cv=none; d=zohomail.com; s=zohoarc; b=Puren+R1oUryufG4oOYb73jHwFur4eZJiGqDnf5SjV5CUDFqi4C4A1pJ4Rn+l0K2lbrB2TeVbHe31NMQLHzzeoATjAnJNRfBKLfqGgsN1mr+lBeoIQgOlQ62xuOEwdrZm2mRTP3kKU1xLNdfWGgWiZskWf3yM7VkoqbGh9NtAsg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508713; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=iiNhMvFObT8ZPes0r2dgPX8WHAzEbORLJoRpa+IPHBw=; b=ehgaHzxdDvSmMaAUAycaEZaICsKkferjpwIEijEEwRkgB3ko24BrZ+ixqsy3hw/NSCbyrhDNkWNkhcLnjk8lTcMzxSGd0FUNYZYyw4Pna8DYyPvXDk9AFFZJVSpvm37RKj8l4QexCV5Sn8S/Rd8aE6zcyJsqldovZACv23HY+eE= 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 1748508712904466.0724351514141; Thu, 29 May 2025 01:51:52 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id DD9D414CD; Thu, 29 May 2025 04:51:51 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 32C8213C4; Thu, 29 May 2025 04:44:08 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id CF87B1629; Thu, 29 May 2025 04:43:52 -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 2757B139D for ; Thu, 29 May 2025 04:43:31 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-290-v31qYHOZNfiCfoN0iiCwaQ-1; Thu, 29 May 2025 04:43:29 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id A678318003FC for ; Thu, 29 May 2025 08:43:28 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id DF83919560AF for ; Thu, 29 May 2025 08:43: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.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, 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=1748508210; 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=qLsMZ63D0gOIPLbnXW8VhTBgsPPu8HOBDAVzR7YAZSU=; b=d1wMUabEWJdbJYf/CNt380q5lABu41unEIsJ3woN+BQCjdmenO16JY26rExIadIF1yAbiM nMr6Jw91CVFEDPSKigWK+/uChr1AIaeDRPTfjzWKXY5TeWJ2OvQ/OXmqUiMlovmhejk1Fu /vwuo/YDODKpCTusZngikptwKoCjoAg= X-MC-Unique: v31qYHOZNfiCfoN0iiCwaQ-1 X-Mimecast-MFC-AGG-ID: v31qYHOZNfiCfoN0iiCwaQ_1748508208 To: devel@lists.libvirt.org Subject: [PATCH 13/15] storage_file_probe: Parse all qcow2 extensions at once Date: Thu, 29 May 2025 10:43:07 +0200 Message-ID: <1cae904c2b55c7792614a0929c2f1f7fea10d3f7.1748507931.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-MFC-PROC-ID: UUqiHe5E6JYAHN_EN_a_7Vi8Bw2pwEEVqqiGaxuvFGc_1748508208 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: QVLUMXLHMSZ2N2EAFNVXE4E4SFP2MKN2 X-Message-ID-Hash: QVLUMXLHMSZ2N2EAFNVXE4E4SFP2MKN2 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508714759116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Refactor qcow2GetExtensions to parse everything at once and directly assign it into fields in the parsed virStorageSource. This removes the need for qcow2GetDataFile as it will be parsed directly. The patch also simplifies the juggling of variables which was needed to parse the backing file format filed, when it was passed via pointer in argument. qcow2GetExtensions is now invoked on qcow2 images so we can remove the version check for qcow(v1) images. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 68 +++++---------------------- 1 file changed, 13 insertions(+), 55 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index 10e159c27b..73751c7a2f 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -114,7 +114,6 @@ static int qcow2GetImageSpecific(virStorageSource *meta, const char *buf, size_t buf_size); -static int qcow2GetDataFile(char **, virBitmap *, char *, size_t); static int vmdk4GetImageSpecific(virStorageSource *meta, const char *buf, @@ -326,7 +325,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { qcow2EncryptionInfo, NULL, NULL, - qcow2GetDataFile, + NULL, NULL, qcow2GetImageSpecific }, @@ -403,21 +402,16 @@ cowGetImageSpecific(virStorageSource *meta, static int -qcow2GetExtensions(const char *buf, - size_t buf_size, - int *backingFormat, - char **dataFilePath) +qcow2GetExtensions(virStorageSource *meta, + const char *buf, + size_t buf_size) { size_t offset; size_t extension_start; size_t extension_end; int version =3D virReadBufInt32BE(buf + QCOWX_HDR_VERSION); - if (version < 2) { - /* QCow1 doesn't have the extensions capability - * used to store backing format */ - return 0; - } + g_clear_pointer(&meta->dataFileRaw, g_free); if (version =3D=3D 2) extension_start =3D QCOW2_HDR_TOTAL_SIZE; @@ -486,13 +480,7 @@ qcow2GetExtensions(const char *buf, switch (magic) { case QCOW2_HDR_EXTENSION_BACKING_FORMAT: { - g_autofree char *tmp =3D NULL; - if (!backingFormat) - break; - - tmp =3D g_new0(char, len + 1); - memcpy(tmp, buf + offset, len); - tmp[len] =3D '\0'; + g_autofree char *tmp =3D g_strndup(buf + offset, len); /* qemu and qemu-img allow using the protocol driver name insi= de * of the format field in cases when the dummy 'raw' driver sh= ould @@ -500,20 +488,16 @@ qcow2GetExtensions(const char *buf, * doesn't look like a format driver name to be a protocol dri= ver * directly and thus the image is in fact still considered raw */ - *backingFormat =3D virStorageFileFormatTypeFromString(tmp); - if (*backingFormat <=3D VIR_STORAGE_FILE_NONE) - *backingFormat =3D VIR_STORAGE_FILE_RAW; + meta->backingStoreRawFormat =3D virStorageFileFormatTypeFromSt= ring(tmp); + if (meta->backingStoreRawFormat <=3D VIR_STORAGE_FILE_NONE) + meta->backingStoreRawFormat =3D VIR_STORAGE_FILE_RAW; break; } - case QCOW2_HDR_EXTENSION_DATA_FILE_NAME: { - if (!dataFilePath) - break; - - *dataFilePath =3D g_new0(char, len + 1); - memcpy(*dataFilePath, buf + offset, len); + case QCOW2_HDR_EXTENSION_DATA_FILE_NAME: + if (virBitmapIsBitSet(meta->features, VIR_STORAGE_FILE_FEATURE= _DATA_FILE)) + meta->dataFileRaw =3D g_strndup(buf + offset, len); break; - } case QCOW2_HDR_EXTENSION_END: return 0; @@ -623,8 +607,6 @@ qcow2GetImageSpecific(virStorageSource *meta, const char *buf, size_t buf_size) { - int format; - meta->clusterSize =3D 0; if (buf_size > (QCOWX_HDR_CLUSTER_BITS_OFFSET + 4)) { int clusterBits =3D virReadBufInt32BE(buf + QCOWX_HDR_CLUSTER_BITS= _OFFSET); @@ -639,33 +621,9 @@ qcow2GetImageSpecific(virStorageSource *meta, if (qcow2GetFeatures(meta, buf, buf_size) < 0) return -1; - format =3D meta->backingStoreRawFormat; - - if (qcow2GetExtensions(buf, buf_size, &format, NULL) < 0) + if (qcow2GetExtensions(meta, buf, buf_size) < 0) return 0; - meta->backingStoreRawFormat =3D format; - - return 0; -} - - -static int -qcow2GetDataFile(char **res, - virBitmap *features, - char *buf, - size_t buf_size) -{ - *res =3D NULL; - - if (buf_size < QCOW2v3_HDR_FEATURES_INCOMPATIBLE + 8) - return 0; - - if (features && virBitmapIsBitSet(features, VIR_STORAGE_FILE_FEATURE_D= ATA_FILE)) { - if (qcow2GetExtensions(buf, buf_size, NULL, res) < 0) - return -1; - } - return 0; } --=20 2.49.0 From nobody Mon Sep 8 21:39:50 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=1748508730; cv=none; d=zohomail.com; s=zohoarc; b=LR2auC14WelhPr6Cu+jOuNqADuRd+WREUFcDxrtoQzwMUJDfmh9Nyi9ckpzAqvnzmiw2E4RoXAx0cu0jBJI3QYS/Jl4oCuaj431Z+7cgmJBfQEZ2eZthy/cMtMHM3BizFF0f9gptc3HEOk7gWrjhMoELH9FY/eIGTVTEIxgHDN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508730; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=Sv+vC2YSv9+YW6hrrIS0q9ZvSffS/2l/zQ78p1N1o18=; b=TLuImQRmMzGzXZZ6QHfRUqF1LDtk4jj3JN+rBQhbn3+kBeoAC3D6SAYmWSGCi+iROC8RNgrubKBt4VQBoqjGGd4zfyXcw51qIEPysTxUM8p0159Q565WotKIz/sEsIG5W9vqtyHmgmO2wX1Xp11gwsQh6v05Co9Lvh2CmRktsjU= 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 1748508730444314.29529765075654; Thu, 29 May 2025 01:52:10 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7AC4B12A2; Thu, 29 May 2025 04:52:09 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 477E4135B; Thu, 29 May 2025 04:44:11 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7C347128C; Thu, 29 May 2025 04:43:54 -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 B23E812A8 for ; Thu, 29 May 2025 04:43:32 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-426-NY-C-ZEVNi6vTVc2YfTzwg-1; Thu, 29 May 2025 04:43:30 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E88731800256 for ; Thu, 29 May 2025 08:43:29 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 28C4019560B3 for ; Thu, 29 May 2025 08:43: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.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, 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=1748508212; 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=G8+Y4xhVovcMB+rPZ3svkV6wo2Zz2eq4Bc9yW5bM0is=; b=YuxmP8WosiLGUaUZm8rsgCl6GYnhlsG6oDS/PnTGv++y0swEOjrXlQQ8muY2j+GNlj4daI 9fUW1ga/VR0MiDt7vQXt9EPok5z3nISLOrt4sB1R2BYHZVxrLs7y0+W//vfmzkuXuvAZK+ /uI1lA15jw1GOVMdqiVmHHCTAgSsegU= X-MC-Unique: NY-C-ZEVNi6vTVc2YfTzwg-1 X-Mimecast-MFC-AGG-ID: NY-C-ZEVNi6vTVc2YfTzwg_1748508210 To: devel@lists.libvirt.org Subject: [PATCH 14/15] storage_file_probe: Move setting of 'compat' attribute to qcow2GetFeatures Date: Thu, 29 May 2025 10:43:08 +0200 Message-ID: <6a7ffb001393eebbd9813892bdead6956c5a5b48.1748507931.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-MFC-PROC-ID: HD2wb8QTuFJ-LGWiHm6f44B3QGo130qxJsjaI79yiZM_1748508210 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: OLUEJHZRV2XXRQL3AMCTJ6B27NUKJOQB X-Message-ID-Hash: OLUEJHZRV2XXRQL3AMCTJ6B27NUKJOQB 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508730886116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Since the 'compat' field is set based on qcow2 features it belongs to the qcow2 code rather than to the main metadata probing function. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index 73751c7a2f..9fcc052ea3 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -579,6 +579,7 @@ qcow2GetFeatures(virStorageSource *meta, int version =3D virReadBufInt32BE(buf + QCOWX_HDR_VERSION); g_clear_pointer(&meta->features, virBitmapFree); + g_clear_pointer(&meta->compat, g_free); if (version =3D=3D 2) return 0; @@ -587,6 +588,7 @@ qcow2GetFeatures(virStorageSource *meta, return -1; meta->features =3D virBitmapNew(VIR_STORAGE_FILE_FEATURE_LAST); + meta->compat =3D g_strdup("1.1"); qcow2GetFeaturesProcessGroup(virReadBufInt64BE(buf + QCOW2v3_HDR_FEATU= RES_COMPATIBLE), qcow2CompatibleFeatureArray, @@ -997,10 +999,6 @@ virStorageFileProbeGetMetadata(virStorageSource *meta, buf, len); } - VIR_FREE(meta->compat); - if (meta->format =3D=3D VIR_STORAGE_FILE_QCOW2 && meta->features) - meta->compat =3D g_strdup("1.1"); - return 0; } --=20 2.49.0 From nobody Mon Sep 8 21:39:50 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=1748508759; cv=none; d=zohomail.com; s=zohoarc; b=WNaiJ8Deln0biKsEcRWi37PCkBGPssXCEpD8dFknIvQU+Hx/swSNQHYIMaYhSWw+E+M51ouZeC9rkKbUwnAER8WS63f9BooGvvjY2s5zFKzJmyCO6LQEOjOfmLLO4q/V4GcTbmJc2+vnP2RBmyOUwxNlKq4Iri5plFKX92tBCYY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748508759; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post: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=AaTnUOIdYVSxXYvvyR23Hci/YV36+CLZ0NDoHf4iqOQ=; b=SUPyhjSlpyzmNFRV6bfWwlb/2HpKK4T3cxBO8z0i/7lqUxBtBC/yv11UQDLETvwvGzcbwEJu/uGV57JBnj0TF2G1q1VpOWDZTRkRl3Pt5gjjRLqIYa7xRcIOArvoUH6cdAd9RTjIRhwT91gFwJ//CJva1PfRmXeQBmnGigm5OGM= 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 1748508759877914.6499960949357; Thu, 29 May 2025 01:52:39 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E7253139F; Thu, 29 May 2025 04:52:38 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 6BE5E1439; Thu, 29 May 2025 04:44:13 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id E9E6C15CC; Thu, 29 May 2025 04:43:56 -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 0229A15CC for ; Thu, 29 May 2025 04:43:33 -0400 (EDT) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-678-6CB6d5q0P0W5_dHUoRWPpA-1; Thu, 29 May 2025 04:43:32 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 313411800360 for ; Thu, 29 May 2025 08:43:31 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 68FEC19560AF for ; Thu, 29 May 2025 08:43:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, 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=1748508213; 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=JgUfPv79y/X7UcdCRPGzqwe7n55FN7dpmDQtFrEHc3k=; b=O4rxbeSY4cpmjiMtWzxM9Rut4tYpL1cVE2rY70J9gwY5bGfY0cn/2A9/POwXOUaGdK44rg vJJ6UUzA9mazIhrYB8m2HEkwpSNzgaMGEAy9dv5uY/LgPSjyncRgTx7XKNKDPUvVAsq3D1 LDOEFEdvSaxFe4uET5nd8L5W7MvrQds= X-MC-Unique: 6CB6d5q0P0W5_dHUoRWPpA-1 X-Mimecast-MFC-AGG-ID: 6CB6d5q0P0W5_dHUoRWPpA_1748508211 To: devel@lists.libvirt.org Subject: [PATCH 15/15] storage_file_probe: Remove unused image probing callbacks Date: Thu, 29 May 2025 10:43:09 +0200 Message-ID: <8bb2f8b6de610ec8c6a1df88b78c3148f1e89f66.1748507931.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-MFC-PROC-ID: mhxTCf0PCVSdasFnAlyNHGutSVFGPXCuwp4iK9RoSuc_1748508211 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: C6VC3PRKEUNYT42TTT3VFOVC3FUFEIOR X-Message-ID-Hash: C6VC3PRKEUNYT42TTT3VFOVC3FUFEIOR 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748508761179116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa Remove the old now-unused infrastructure. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/storage_file/storage_file_probe.c | 66 +++++++-------------------- 1 file changed, 16 insertions(+), 50 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index 9fcc052ea3..26f8d63e9a 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -89,13 +89,6 @@ struct FileTypeInfo { * or NULL if there is no COW base image, to RES; * return BACKING_STORE_* */ const struct FileEncryptionInfo *cryptInfo; /* Encryption info */ - unsigned long long (*getClusterSize)(const char *buf, - size_t buf_size); - int (*getBackingStore)(char **res, int *format, - const char *buf, size_t buf_size); - int (*getDataFile)(char **res, virBitmap *features, char *buf, size_t = buf_size); - int (*getFeatures)(virBitmap **features, int format, - char *buf, ssize_t len); int (*getImageSpecific)(virStorageSource *meta, const char *buf, size_t buf_size); @@ -250,18 +243,18 @@ static struct FileEncryptionInfo const qcow2Encryptio= nInfo[] =3D { static struct FileTypeInfo const fileTypeInfo[] =3D { [VIR_STORAGE_FILE_NONE] =3D { 0, NULL, LV_LITTLE_ENDIAN, - -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL, NUL= L, NULL, NULL }, + -1, 0, {0}, 0, 0, 0, NULL, NULL }, [VIR_STORAGE_FILE_RAW] =3D { 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, 0, 0, 0, luksEncryptionInfo, - NULL, NULL, NULL, NULL, NULL }, + NULL }, [VIR_STORAGE_FILE_DIR] =3D { 0, NULL, LV_LITTLE_ENDIAN, - -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL, NULL= , NULL, NULL }, + -1, 0, {0}, 0, 0, 0, NULL, NULL }, [VIR_STORAGE_FILE_BOCHS] =3D { /*"Bochs Virtual HD Image", */ /* Untested */ 0, NULL, LV_LITTLE_ENDIAN, 64, 4, {0x20000}, - 32+16+16+4+4+4+4+4, 8, 1, NULL, NULL, NULL, NULL, NULL, NULL + 32+16+16+4+4+4+4+4, 8, 1, NULL, NULL }, [VIR_STORAGE_FILE_CLOOP] =3D { /* #!/bin/sh @@ -270,7 +263,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { */ /* Untested */ 0, NULL, LV_LITTLE_ENDIAN, -1, 0, {0}, - -1, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL + -1, 0, 0, NULL, NULL }, [VIR_STORAGE_FILE_DMG] =3D { /* XXX QEMU says there's no magic for dmg, @@ -278,67 +271,63 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { * would have to match) but then disables that check. */ 0, NULL, 0, -1, 0, {0}, - -1, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL + -1, 0, 0, NULL, NULL }, [VIR_STORAGE_FILE_ISO] =3D { 32769, "CD001", LV_LITTLE_ENDIAN, -2, 0, {0}, - -1, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL + -1, 0, 0, NULL, NULL }, [VIR_STORAGE_FILE_VPC] =3D { 0, "conectix", LV_BIG_ENDIAN, 12, 4, {0x10000}, - 8 + 4 + 4 + 8 + 4 + 4 + 2 + 2 + 4, 8, 1, NULL, NULL, NULL, NULL, N= ULL, NULL + 8 + 4 + 4 + 8 + 4 + 4 + 2 + 2 + 4, 8, 1, NULL, NULL }, /* TODO: add getBackingStore function */ [VIR_STORAGE_FILE_VDI] =3D { 64, "\x7f\x10\xda\xbe", LV_LITTLE_ENDIAN, 68, 4, {0x00010001}, - 64 + 5 * 4 + 256 + 7 * 4, 8, 1, NULL, NULL, NULL, NULL, NULL, NULL= }, + 64 + 5 * 4 + 256 + 7 * 4, 8, 1, NULL, NULL }, /* Not direct file formats, but used for various drivers */ [VIR_STORAGE_FILE_FAT] =3D { 0, NULL, LV_LITTLE_ENDIAN, - -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL, NULL= , NULL, NULL }, + -1, 0, {0}, 0, 0, 0, NULL, NULL }, [VIR_STORAGE_FILE_VHD] =3D { 0, NULL, LV_LITTLE_ENDIAN, - -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL, NULL= , NULL, NULL }, + -1, 0, {0}, 0, 0, 0, NULL, NULL }, [VIR_STORAGE_FILE_PLOOP] =3D { 0, "WithouFreSpacExt", LV_LITTLE_ENDIAN, -2, 0, {0}, PLOOP_IMAGE_SIZE_OFFSET, 8, - PLOOP_SIZE_MULTIPLIER, NULL, NULL, NULL, = NULL, NULL, NULL }, + PLOOP_SIZE_MULTIPLIER, NULL, NULL }, /* All formats with a backing store probe below here */ [VIR_STORAGE_FILE_COW] =3D { 0, "OOOM", LV_BIG_ENDIAN, 4, 4, {2}, - 4+4+1024+4, 8, 1, NULL, NULL, NULL, NULL, NULL, cowGetImageSpecific + 4+4+1024+4, 8, 1, NULL, cowGetImageSpecific }, [VIR_STORAGE_FILE_QCOW] =3D { 0, "QFI", LV_BIG_ENDIAN, 4, 4, {1}, QCOWX_HDR_IMAGE_SIZE, 8, 1, qcow1EncryptionInfo, - NULL, NULL, NULL, NULL, qcowGetImageSpecific + qcowGetImageSpecific }, [VIR_STORAGE_FILE_QCOW2] =3D { 0, "QFI", LV_BIG_ENDIAN, 4, 4, {2, 3}, QCOWX_HDR_IMAGE_SIZE, 8, 1, qcow2EncryptionInfo, - NULL, - NULL, - NULL, - NULL, qcow2GetImageSpecific }, [VIR_STORAGE_FILE_QED] =3D { /* https://wiki.qemu.org/Features/QED */ 0, "QED", LV_LITTLE_ENDIAN, -2, 0, {0}, - QED_HDR_IMAGE_SIZE, 8, 1, NULL, NULL, NULL, NULL, NULL, qedGetImag= eSpecific + QED_HDR_IMAGE_SIZE, 8, 1, NULL, qedGetImageSpecific }, [VIR_STORAGE_FILE_VMDK] =3D { 0, "KDMV", LV_LITTLE_ENDIAN, 4, 4, {1, 2, 3}, - 4+4+4, 8, 512, NULL, NULL, NULL, NULL, NULL, vmdk4GetImageSpecific + 4+4+4, 8, 512, NULL, vmdk4GetImageSpecific }, }; G_STATIC_ASSERT(G_N_ELEMENTS(fileTypeInfo) =3D=3D VIR_STORAGE_FILE_LAST); @@ -911,7 +900,6 @@ virStorageFileProbeGetMetadata(virStorageSource *meta, char *buf, size_t len) { - int format; size_t i; VIR_DEBUG("path=3D%s, buf=3D%p, len=3D%zu, meta->format=3D%d", @@ -973,32 +961,10 @@ virStorageFileProbeGetMetadata(virStorageSource *meta, meta->capacity *=3D fileTypeInfo[meta->format].sizeMultiplier; } - VIR_FREE(meta->backingStoreRaw); - g_clear_pointer(&meta->features, virBitmapFree); - VIR_FREE(meta->dataFileRaw); - if (fileTypeInfo[meta->format].getImageSpecific && fileTypeInfo[meta->format].getImageSpecific(meta, buf, len) < 0) return -1; - if (fileTypeInfo[meta->format].getClusterSize !=3D NULL) - meta->clusterSize =3D fileTypeInfo[meta->format].getClusterSize(bu= f, len); - - if (fileTypeInfo[meta->format].getBackingStore !=3D NULL) { - fileTypeInfo[meta->format].getBackingStore(&meta->backingStoreRaw, - &format, buf, len); - meta->backingStoreRawFormat =3D format; - } - - if (fileTypeInfo[meta->format].getFeatures !=3D NULL && - fileTypeInfo[meta->format].getFeatures(&meta->features, meta->form= at, buf, len) < 0) - return -1; - - if (fileTypeInfo[meta->format].getDataFile !=3D NULL) { - fileTypeInfo[meta->format].getDataFile(&meta->dataFileRaw, meta->f= eatures, - buf, len); - } - return 0; } --=20 2.49.0