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