From nobody Sat Nov 23 15:13:33 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=1723387491; cv=none; d=zohomail.com; s=zohoarc; b=YiBPLQus1qcuVgWAmxhXnHGBv9LvSsw06tUhlA4hZpuhIGJUC3roAnCXHa3Dg187Sc6qQElUp8lWwu5cK1NkcZP2h8q1EkkGD0TywoMmvjkj8L+pZbykFBgblDbvCylW9jfBZP+ceClUVc7CIattzjq+VE3fRAcXS/rPusKGsco= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723387491; 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=P+t5QdraqPsFV9PAEALPPj4psrsX9LeOObCgzoZcW+E=; b=Es2tM/YUyWrhECY1uAFFqc3ybd2+3ErR3IsJFRmkYlo7hVnc8pg9LNbbYe9cBH9SXA/IUzvpLpvHYyl/WJgVv92dd8af9CUkZ7TKkpYSkvMsVHqYCZzW/73DFGPRUX9xvQSrPRKTCO5+VJkIXXAjN8PQ7ZGdMh9bszdH3p3TS48= 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 1723387491942524.659700045498; Sun, 11 Aug 2024 07:44:51 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id D0E8014DC; Sun, 11 Aug 2024 10:44:50 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C16AC1576; Sun, 11 Aug 2024 10:44:12 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 196511441; Sun, 11 Aug 2024 10:44:09 -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 6EAAB1433 for ; Sun, 11 Aug 2024 10:44:08 -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 1sd9m5-00FzIb-14; Sun, 11 Aug 2024 16:44:00 +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=8YOxOMLkGQFSsE7sxmCt4eqb3pNTaGD//ksopiwko8Q=; b=Ok2zpM7+/A5N 1Zsu9KtI0KhUe7enoKCxrkEoZ3pN2QLpkYDFl4BSwPBbRXWZr8ULaSWeTtZHkl/6XhwwgmOlltK1t DdAbpTvZtvQ3cPrio0cCyIIEe2w0nXhlI/SVSWZOOqeSy3YOlEkN+Ixo6pCFf4KzR7/u+gJMlOSQr Jk9Xut5i7Ip1oxDz/EnichE8Nhp9wWOhRddWb493XYE4Io4QbSu+qMpvXOmNwjXBFB1GvMi9KmFRG Lvs4K4rfm5oDLGDbcVyQHWoK0FlnUbYsEzfFmS4H2Wq28ZV3tMQDl1DukCTeyaw04Wx+zed9Av8A4 K+S9APUNDVlCu4xD1cy2AQ==; To: devel@lists.libvirt.org Subject: [PATCH 1/3] conf: add data-file feature and related fields to virStorageSource Date: Sun, 11 Aug 2024 17:34:46 +0300 Message-ID: <20240811144340.60108-2-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: UHDLTZMNOMPOQYBR4ES6W3A4Y7OKD7S6 X-Message-ID-Hash: UHDLTZMNOMPOQYBR4ES6W3A4Y7OKD7S6 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: 1723387492388116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Nikolai Barybin --- src/conf/storage_source_conf.c | 8 ++++++++ src/conf/storage_source_conf.h | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c index 908bc5fab2..d76de058b9 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -69,6 +69,7 @@ VIR_ENUM_IMPL(virStorageFileFeature, VIR_STORAGE_FILE_FEATURE_LAST, "lazy_refcounts", "extended_l2", + "data_file", ); =20 =20 @@ -826,6 +827,7 @@ virStorageSourceCopy(const virStorageSource *src, def->relPath =3D g_strdup(src->relPath); def->backingStoreRaw =3D g_strdup(src->backingStoreRaw); def->backingStoreRawFormat =3D src->backingStoreRawFormat; + def->dataFileRaw =3D g_strdup(src->dataFileRaw); def->snapshot =3D g_strdup(src->snapshot); def->configFile =3D g_strdup(src->configFile); def->nodenameformat =3D g_strdup(src->nodenameformat); @@ -891,6 +893,12 @@ virStorageSourceCopy(const virStorageSource *src, return NULL; } =20 + if (src->dataFileStore) { + if (!(def->dataFileStore =3D virStorageSourceCopy(src->dataFileSto= re, + false))) + return NULL; + } + if (src->fdtuple) def->fdtuple =3D g_object_ref(src->fdtuple); =20 diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h index 05b4bda16c..fa27e61204 100644 --- a/src/conf/storage_source_conf.h +++ b/src/conf/storage_source_conf.h @@ -88,6 +88,7 @@ VIR_ENUM_DECL(virStorageFileFormat); typedef enum { VIR_STORAGE_FILE_FEATURE_LAZY_REFCOUNTS =3D 0, VIR_STORAGE_FILE_FEATURE_EXTENDED_L2, + VIR_STORAGE_FILE_FEATURE_DATA_FILE, =20 VIR_STORAGE_FILE_FEATURE_LAST } virStorageFileFeature; @@ -359,6 +360,9 @@ struct _virStorageSource { /* backing chain of the storage source */ virStorageSource *backingStore; =20 + /* qcow2 data file source */ + virStorageSource *dataFileStore; + /* metadata for storage driver access to remote and local volumes */ void *drv; =20 @@ -369,6 +373,7 @@ struct _virStorageSource { /* Name of the child backing store recorded in metadata of the * current file. */ char *backingStoreRaw; + char *dataFileRaw; virStorageFileFormat backingStoreRawFormat; =20 /* metadata that allows identifying given storage source */ --=20 2.43.5 From nobody Sat Nov 23 15:13:33 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 From nobody Sat Nov 23 15:13:33 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=1723387547; cv=none; d=zohomail.com; s=zohoarc; b=hN1g2UdoZ0ekuekqOL8hPn18JkKTbMQa+m/b+vLaa+l25i+tkq1cHoBkWzcUhgefFLjeKxHWhYZMdxIc68ZkQyE92Om6SIBU0zszc/WlJ44/rnPASUQYDlkEIPo8PvPFxLMT+piyNQlyt5svRoIbe2TM17s3sOX+i4vCz9wJuqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1723387547; 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=KnYOAc/uzMlZqSaNBqZgCrizYNBEsOr2n6Gc+tIGv3Q=; b=gKVScsGSQR/ounftvZiX4ggEOZLPig80BZVM44/mkU5zlRszkYTLktY34E0QaId/qTondf7IdmxNKvcFWOYb5Aqs2uDhcZjDFg/ERZ27zNGiA/F99/8iF5shU0BYpv6UcMrXhmhGF2ermYsVhdm0Zbq0IqNJzZnQT3UgXXGaj6w= 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 1723387547754532.6258812273675; Sun, 11 Aug 2024 07:45:47 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id B420111AD; Sun, 11 Aug 2024 10:45:46 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 01E7615B7; Sun, 11 Aug 2024 10:44:18 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 59A711528; Sun, 11 Aug 2024 10:44:11 -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 95D8312C1 for ; Sun, 11 Aug 2024 10:44:10 -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 1sd9m7-00FzIb-1f; Sun, 11 Aug 2024 16:44:02 +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=sfrCsrUjGwNYnELqoVYYLboi46PacmpKjKrA32CMEXU=; b=Y5lRb4i41dov DcncsNW8wRG7/YDJmWCvfIwIutBEFJUwdy9eH+HFS2JVivGXBoPGVl6Oj8OSe0XkVUSjw1jzr5nl5 T8VrPBr31nLuqs7JZyqe2ZfF053Cli+18LIjjRiv/gi8PpFtE2n5GVgPicUHObjx9e1TU0C0Pfa73 WMDVaLNHqfp7fhR+ihOuf1fsBTenEpnSJAYjWyq5JVtcvWUTvVpPJG/B/E6r4MU0/z9WegmcJP/Mv L8GTePrGq7mjN5ZROWdPovAUp/yj5o9GWNKtVOq1f7z8qz8B9ArpwJlsXx7WzCNYAWOseaYW0vRjH BgCEaAeZbZ1gl8h9rZbFSA==; To: devel@lists.libvirt.org Subject: [PATCH 3/3] qemu: enable qcow2 data-file attach to VM on start Date: Sun, 11 Aug 2024 17:34:48 +0300 Message-ID: <20240811144340.60108-4-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: LZJZCDQZ4KL7QKUIQOQBRFRPENXYDSIM X-Message-ID-Hash: LZJZCDQZ4KL7QKUIQOQBRFRPENXYDSIM 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: 1723387548449116600 Content-Type: text/plain; charset="utf-8" - parse data-file metadata and init src->dataFileStore struct - chown data-file to allow qemu to open it - add data-file path to VM's cgroup and namespace - add data-file option to QEMU process command line Signed-off-by: Nikolai Barybin --- src/qemu/qemu_block.c | 45 +++++++++++++++++++++++++++++++ src/qemu/qemu_cgroup.c | 3 +++ src/qemu/qemu_namespace.c | 6 +++++ src/storage_file/storage_source.c | 38 ++++++++++++++++++++++++-- 4 files changed, 90 insertions(+), 2 deletions(-) diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index d6cdf521c4..38f4717d56 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1271,6 +1271,48 @@ qemuBlockStorageSourceGetFormatQcowGenericProps(virS= torageSource *src, } =20 =20 +static int +qemuBlockStorageGetQcow2DataFileProps(virStorageSource *src, + virJSONValue *props) +{ + g_autoptr(virJSONValue) dataFileDef =3D NULL; + virStorageType actualType; + g_autofree char *driverName =3D NULL; + + if (!src->dataFileRaw) + return 0; + + actualType =3D virStorageSourceGetActualType(src->dataFileStore); + if (actualType !=3D VIR_STORAGE_TYPE_BLOCK && + actualType !=3D VIR_STORAGE_TYPE_FILE) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("%1$s storage type is not supported for qcow2 dat= a-file"), + NULLSTR(virStorageTypeToString(actualType))); + return -1; + } + + if (virStorageSourceIsBlockLocal(src->dataFileStore)) + driverName =3D g_strdup("host_device"); + else + driverName =3D g_strdup("file"); + + if (virJSONValueObjectAdd(&dataFileDef, + "s:driver", driverName, + "b:read-only", src->readonly, + "s:filename", src->dataFileRaw, + NULL) < 0) + return -1; + + if (virJSONValueObjectAdd(&props, + "A:data-file", &dataFileDef, + NULL) < 0) + return -1; + + return 0; +} + + + static int qemuBlockStorageSourceGetFormatQcow2Props(virStorageSource *src, virJSONValue *props) @@ -1301,6 +1343,9 @@ qemuBlockStorageSourceGetFormatQcow2Props(virStorageS= ource *src, NULL) < 0) return -1; =20 + if (qemuBlockStorageGetQcow2DataFileProps(src, props) < 0) + return -1; + return 0; } =20 diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 23b7e6b4e8..84c749b567 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -223,6 +223,9 @@ qemuSetupImageCgroupInternal(virDomainObj *vm, qemuSetupImagePathCgroup(vm, QEMU_DEVICE_MAPPER_CONTROL_PATH, fals= e) < 0) return -1; =20 + if (src->dataFileRaw && qemuSetupImagePathCgroup(vm, src->dataFileRaw,= readonly) < 0) + return -1; + return qemuSetupImagePathCgroup(vm, path, readonly); } =20 diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c index bbe3d5a1f7..32653443ec 100644 --- a/src/qemu/qemu_namespace.c +++ b/src/qemu/qemu_namespace.c @@ -290,6 +290,12 @@ qemuDomainSetupDisk(virStorageSource *src, =20 if (targetPaths) *paths =3D g_slist_concat(g_slist_reverse(targetPaths), *p= aths); + + if (next->dataFileRaw) { + g_autofree char *datafile =3D NULL; + datafile =3D g_strdup(next->dataFileRaw); + *paths =3D g_slist_prepend(*paths, g_steal_pointer(&datafi= le)); + } } =20 *paths =3D g_slist_prepend(*paths, g_steal_pointer(&tmpPath)); diff --git a/src/storage_file/storage_source.c b/src/storage_file/storage_s= ource.c index 2cfe3bc325..0ea11228d4 100644 --- a/src/storage_file/storage_source.c +++ b/src/storage_file/storage_source.c @@ -1378,8 +1378,16 @@ virStorageSourceGetMetadataRecurse(virStorageSource = *src, &buf, &headerLen) < 0) return -1; =20 - if (virStorageFileProbeGetMetadata(src, buf, headerLen) < 0) - return -1; + if (!parent->dataFileRaw) { + if (virStorageFileProbeGetMetadata(src, buf, headerLen) < 0) + return -1; + } else { + if (virStorageSourceInitAs(src, uid, gid) < 0) + return -1; + if (virStorageSourceChown(src, uid, gid) < 0) + return -1; + virStorageSourceDeinit(src); + } =20 /* If we probed the format we MUST ensure that nothing else than the c= urrent * image is considered for security labelling and/or recursion. */ @@ -1417,6 +1425,32 @@ virStorageSourceGetMetadataRecurse(virStorageSource = *src, =20 backingStore->id =3D depth; src->backingStore =3D g_steal_pointer(&backingStore); + + } else if (src->dataFileRaw) { + if ((rv =3D virStorageSourceNewFromChild(src, src->dataFileRaw, &b= ackingStore)) < 0) + return -1; + + if (rv =3D=3D 1) + return 0; + + if ((rv =3D virStorageSourceGetMetadataRecurse(backingStore, paren= t, + uid, gid, + report_broken, + max_depth, depth + 1)= ) < 0) { + if (!report_broken) + return 0; + + if (rv =3D=3D -2) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("format of data file image '%1$s' of imag= e '%2$s' was not specified in the image metadata (See https://libvirt.org/k= base/backing_chains.html for troubleshooting)"), + src->dataFileRaw, NULLSTR(src->path)); + } + + return -1; + } + + backingStore->id =3D depth; + src->dataFileStore =3D g_steal_pointer(&backingStore); } else { /* add terminator */ src->backingStore =3D virStorageSourceNew(); --=20 2.43.5