From nobody Sun Feb 8 21:17: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=1725719517; cv=none; d=zohomail.com; s=zohoarc; b=XYYgrkBsCtl+xJ0nIbhROoIggcQWZVt4kosD37J6gJCUNeO0Z7AR4RQ45xUifAd6al/JRDTG129v/ZZqkmNpZwdz0LShEfKn3u26adVGOpc05o+TYXQTBrAFZioj9UuEgOyEPnlyfuW18LM3MXIvNd/leK65ZM3QGV/TO4Gd3oI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1725719517; h=Content-Transfer-Encoding:Cc:Cc: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; bh=f1Bk1tlup8ygKP1Wy3i2ty0TQ8XBPKR3UMwn3qCa4rQ=; b=FXK0KxDHR26iKwDknk6Mr5lmzhxolpG8Aqp0vZM9Hf5kJkBASh0Kcd5+yA8aA+cX8bRGV9FyvAYNxJAXZJtMT3U1JPe0LLS1BxSQdoot0i1jIlA6G3HROEUqecItuKWstMH594LeCyBC604ypkMzuQA/9eUHEKx3ONtU2cuNJzE= 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 1725719517367429.68078067782255; Sat, 7 Sep 2024 07:31:57 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4428D18F4; Sat, 7 Sep 2024 10:31:56 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3736618FE; Sat, 7 Sep 2024 10:31:05 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 5AA751805; Sat, 7 Sep 2024 10:31:01 -0400 (EDT) Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) (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 0F89D1805 for ; Sat, 7 Sep 2024 10:30:57 -0400 (EDT) Received: from [130.117.225.1] (helo=vz9-barybin-2.ch-qa.vzint.dev) by relay.virtuozzo.com with esmtp (Exim 4.96) (envelope-from ) id 1smwQG-001ZxE-0f; Sat, 07 Sep 2024 16:30:51 +0200 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=MIME-Version:Message-ID:Date:Subject:From: Content-Type; bh=FGKYA0Y+HLscL2zZcepVvnHuGL98gxH1VnGS4UL9f7Q=; b=Z/bZrIl5ikL/ T90s3pbt9dXDi0dmAVeiJRDwfmFluDPAKIC3cI0c1CclYB7V9jNzOLSdLp8R0JT/d4T4Cxs2UznNA MrP3019F3A3nnbh3N+Q/aGkgvKgfruNoMNl7AzzMObn6cXdLqoOCnkehgiOwYwXMzyB0FWKxkFDf5 DchQ0fwAPYD6oki3zaSsqGD+FPqa5JLi9wJVeMfQfDaGjUOfqDW4iV1NSNwoXB3bRNrhQ6zya/NDq 5fZNjtc+wsmBb/craoWYEoDIf45lgzg4mPrBkvAEdQJE/dBOHL5zHT3Xi13urE7fvvOcNyP3AXOAB Iwyi77uR1r7ZSmq68GW2ew==; To: devel@lists.libvirt.org Subject: [PATCH v2 03/13] storage file: add qcow2 data-file path parsing from header Date: Sat, 7 Sep 2024 17:15:21 +0300 Message-ID: <20240907143006.50677-7-nikolai.barybin@virtuozzo.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240907143006.50677-1-nikolai.barybin@virtuozzo.com> References: <20240907143006.50677-1-nikolai.barybin@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5KZQ4W2MPEOQJFXDNWSTHUZGSWX47LXR X-Message-ID-Hash: 5KZQ4W2MPEOQJFXDNWSTHUZGSWX47LXR X-MailFrom: nikolai.barybin@virtuozzo.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 CC: den@openvz.org, Nikolai Barybin 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: Nikolai Barybin via Devel Reply-To: Nikolai Barybin X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1725719518820116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Nikolai Barybin --- src/storage_file/storage_file_probe.c | 53 +++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index 4792b9fdff..21430d18aa 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -106,6 +106,7 @@ qcow2GetClusterSize(const char *buf, size_t buf_size); static int qcowXGetBackingStore(char **, int *, const char *, size_t); +static int qcowXGetDataFile(char **, char *, int, size_t); static int qcow2GetFeatures(virBitmap **features, int format, char *buf, ssize_t len); static int vmdk4GetBackingStore(char **, int *, @@ -127,6 +128,7 @@ qedGetBackingStore(char **, int *, const char *, size_t= ); =20 #define QCOW2_HDR_EXTENSION_END 0 #define QCOW2_HDR_EXTENSION_BACKING_FORMAT 0xE2792ACA +#define QCOW2_HDR_EXTENSION_DATA_FILE_NAME 0x44415441 =20 #define QCOW2v3_HDR_FEATURES_INCOMPATIBLE (QCOW2_HDR_TOTAL_SIZE) #define QCOW2v3_HDR_FEATURES_COMPATIBLE (QCOW2v3_HDR_FEATURES_INCOMPATIBLE= +8) @@ -314,7 +316,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { qcow2EncryptionInfo, qcow2GetClusterSize, qcowXGetBackingStore, - NULL, + qcowXGetDataFile, qcow2GetFeatures }, [VIR_STORAGE_FILE_QED] =3D { @@ -361,7 +363,7 @@ enum qcow2IncompatibleFeature { static const virStorageFileFeature qcow2IncompatibleFeatureArray[] =3D { VIR_STORAGE_FILE_FEATURE_LAST, /* QCOW2_INCOMPATIBLE_FEATURE_DIRTY */ VIR_STORAGE_FILE_FEATURE_LAST, /* QCOW2_INCOMPATIBLE_FEATURE_CORRUPT */ - VIR_STORAGE_FILE_FEATURE_LAST, /* QCOW2_INCOMPATIBLE_FEATURE_DATA_FILE= */ + VIR_STORAGE_FILE_FEATURE_DATA_FILE, /* QCOW2_INCOMPATIBLE_FEATURE_DATA= _FILE */ VIR_STORAGE_FILE_FEATURE_LAST, /* QCOW2_INCOMPATIBLE_FEATURE_COMPRESSI= ON */ VIR_STORAGE_FILE_FEATURE_EXTENDED_L2, /* QCOW2_INCOMPATIBLE_FEATURE_EX= TL2 */ }; @@ -393,7 +395,8 @@ cowGetBackingStore(char **res, static int qcow2GetExtensions(const char *buf, size_t buf_size, - int *backingFormat) + int *backingFormat, + char **dataFilePath) { size_t offset; size_t extension_start; @@ -488,6 +491,17 @@ qcow2GetExtensions(const char *buf, break; } =20 + case QCOW2_HDR_EXTENSION_DATA_FILE_NAME: { + g_autofree char *tmp =3D NULL; + if (!dataFilePath) + break; + + *(char **)dataFilePath =3D g_new0(char, len + 1); + memcpy(*(char **)dataFilePath, buf + offset, len); + (*((char **)dataFilePath))[len] =3D '\0'; + break; + } + case QCOW2_HDR_EXTENSION_END: return 0; } @@ -554,9 +568,34 @@ qcowXGetBackingStore(char **res, memcpy(*res, buf + offset, size); (*res)[size] =3D '\0'; =20 - if (qcow2GetExtensions(buf, buf_size, format) < 0) + if (qcow2GetExtensions(buf, buf_size, format, NULL) < 0) + return 0; + + return 0; +} + + +static int +qcowXGetDataFile(char **res, + char *buf, + int format, + size_t buf_size) +{ + virBitmap *features =3D NULL; + char *filename =3D NULL; + *res =3D NULL; + + if (buf_size < QCOW2v3_HDR_FEATURES_INCOMPATIBLE + 8) return 0; =20 + ignore_value(qcow2GetFeatures(&features, format, buf, buf_size)); + if (features && virBitmapIsBitSet(features, VIR_STORAGE_FILE_FEATURE_D= ATA_FILE)) { + if (qcow2GetExtensions(buf, buf_size, NULL, &filename) < 0) + return 0; + + *res =3D g_strdup(filename); + } + return 0; } =20 @@ -963,6 +1002,12 @@ virStorageFileProbeGetMetadata(virStorageSource *meta, meta->backingStoreRawFormat =3D format; } =20 + VIR_FREE(meta->dataFileRaw); + if (fileTypeInfo[meta->format].getDataFile !=3D NULL) { + fileTypeInfo[meta->format].getDataFile(&meta->dataFileRaw, + buf, meta->format, len); + } + 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) --=20 2.43.5