From nobody Tue Sep 9 03:20: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