From nobody Sun Feb 8 20:47:10 2026 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 --- 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