From nobody Sat Nov 23 18:22:57 2024 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=1723387516; cv=none; d=zohomail.com; s=zohoarc; b=UelZoewP3qYTG8JtAj1bQXGmi0bLJtu1uBI4SMDGdJJTKundHUJsVzIfHdQIuO2x8IDw5VaxhLObu57NA8Ikc0OGKf+CiNArDQ/MLjVoNTp0bn7ZFnK4d0lUXAEzB/R5An8LTmCgOGCNzF2ZMUxd51T6YyPHAafM4LzSzX0myT4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723387516; 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=uLybCkJXwyCHm5M09QHhlpP2xHqWAvL6JW4vjB9CiEQ=; b=a6cCZ+hlxJzkz4wwEpznP+QZQzjF0oWWiWX84mm4Ibby/yDkwfmjdCcuHohwAOg2Fn8//k7LpcL4JsRgwbmfCd/knivTw98G6X/7sxPxnmqAAbRNG081a/YBAqQS1+rW6NBfxJYZEEOf5aVkWG13UtKupLYJ0e1ffrtevS8PegM= 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 1723387516244970.4534823279565; Sun, 11 Aug 2024 07:45:16 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 2EB9A157B; Sun, 11 Aug 2024 10:45:15 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id BBA7C15A4; Sun, 11 Aug 2024 10:44:15 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3E20B143A; Sun, 11 Aug 2024 10:44:10 -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 9DB4C1433 for ; Sun, 11 Aug 2024 10:44:09 -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 1sd9m6-00FzIb-1o; Sun, 11 Aug 2024 16:44:01 +0200 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_LOW,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE 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=Vq5Njnu6PcSN00zTR6tJ8W0G/9y8YC5JUCJrqxBlJ+E=; b=Vj7PgxpdsV5+ IDwkQ5cWFZAjIs5qxTTiEMx7xSZ7YX7dZUP3IWw6Bm+W/3ir5ntAwrPdYxrR+s7rqwrANVdTjBdMn oiIRZQsPshcq4DtW1G8A7IDmcpUSI2oTuxj33hvc7Pe8eN6AIeBRwXz4+synvsVxfRVMLMtgsggIj s4ALFi2lfTd/OV/R5nJUa+CjNkKoNOHOjuEFhC5ZrFhorTXegjkpzHkGqxMMXsTqJmVRm0yf6JEXn HHo3Tif9jB5mZkX8Pqf4v9SQWarOZO38mA5khiEguKlweeNO66l0ACYEqmo8FcE9EXcaElzwpBDVo zKz/eWOvcBKTFRCb/6RHXA==; To: devel@lists.libvirt.org Subject: [PATCH 2/3] storage: add qcow2 filename parsing from header Date: Sun, 11 Aug 2024 17:34:47 +0300 Message-ID: <20240811144340.60108-3-nikolai.barybin@virtuozzo.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240811144340.60108-1-nikolai.barybin@virtuozzo.com> References: <20240811144340.60108-1-nikolai.barybin@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: YTQ5ZIVOEAJQSYNK7BUJSTWXMOKMMHNO X-Message-ID-Hash: YTQ5ZIVOEAJQSYNK7BUJSTWXMOKMMHNO 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: 1723387518259116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Nikolai Barybin --- src/storage_file/storage_file_probe.c | 66 +++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 9 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/stora= ge_file_probe.c index 243927d50a..c7ff743c87 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -93,8 +93,9 @@ struct FileTypeInfo { size_t buf_size); int (*getBackingStore)(char **res, int *format, const char *buf, size_t buf_size); + int (*getDataFile)(char **res, const char *buf, int format, size_t buf= _size); int (*getFeatures)(virBitmap **features, int format, - char *buf, ssize_t len); + const char *buf, ssize_t len); }; =20 =20 @@ -105,8 +106,9 @@ qcow2GetClusterSize(const char *buf, size_t buf_size); static int qcowXGetBackingStore(char **, int *, const char *, size_t); +static int qcowXGetDataFile(char **, const char *, int, size_t); static int qcow2GetFeatures(virBitmap **features, int format, - char *buf, ssize_t len); + const char *buf, ssize_t len); static int vmdk4GetBackingStore(char **, int *, const char *, size_t); static int @@ -126,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) @@ -313,6 +316,7 @@ static struct FileTypeInfo const fileTypeInfo[] =3D { qcow2EncryptionInfo, qcow2GetClusterSize, qcowXGetBackingStore, + qcowXGetDataFile, qcow2GetFeatures }, [VIR_STORAGE_FILE_QED] =3D { @@ -359,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 */ }; @@ -391,7 +395,7 @@ cowGetBackingStore(char **res, static int qcow2GetExtensions(const char *buf, size_t buf_size, - int *backingFormat) + void *data) { size_t offset; size_t extension_start; @@ -467,7 +471,7 @@ qcow2GetExtensions(const char *buf, switch (magic) { case QCOW2_HDR_EXTENSION_BACKING_FORMAT: { g_autofree char *tmp =3D NULL; - if (!backingFormat) + if (!data) break; =20 tmp =3D g_new0(char, len + 1); @@ -480,9 +484,20 @@ 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; + *(int *)data =3D virStorageFileFormatTypeFromString(tmp); + if (*(int *)data <=3D VIR_STORAGE_FILE_NONE) + *(int *)data =3D VIR_STORAGE_FILE_RAW; + break; + } + + case QCOW2_HDR_EXTENSION_DATA_FILE_NAME: { + g_autofree char *tmp =3D NULL; + if (!data) + break; + + *(char **)data =3D g_new0(char, len + 1); + memcpy(*(char **)data, buf + offset, len); + (*((char **)data))[len] =3D '\0'; break; } =20 @@ -559,6 +574,33 @@ qcowXGetBackingStore(char **res, } =20 =20 +static int +qcowXGetDataFile(char **res, + const char *buf, + int format, + size_t buf_size) +{ + virBitmap *features =3D NULL; + char *filename =3D NULL; + size_t namelen =3D 0; + *res =3D NULL; + + if (buf_size < QCOW2v3_HDR_FEATURES_INCOMPATIBLE + 8) + return 0; + + ignore_value(qcow2GetFeatures(&features, format, buf, buf_size)); + if (features && virBitmapIsBitSet(features, VIR_STORAGE_FILE_FEATURE_D= ATA_FILE)) { + if (qcow2GetExtensions(buf, buf_size, &filename) < 0) + return 0; + + namelen =3D strlen(filename) + 1; + *res =3D g_new0(char, namelen); + memcpy(*res, filename, namelen); + } + + return 0; +} + static int vmdk4GetBackingStore(char **res, int *format, @@ -789,7 +831,7 @@ qcow2GetFeaturesProcessGroup(uint64_t bits, static int qcow2GetFeatures(virBitmap **features, int format, - char *buf, + const char *buf, ssize_t len) { int version =3D -1; @@ -961,6 +1003,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