From nobody Sat Nov 23 12:52:53 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=1732119382; cv=none; d=zohomail.com; s=zohoarc; b=FJsDhcxSHZ6/2JWb9lv81I884wiXDxdKAeah7EIMibcOXBm/I/bCuNmEkxKSK+BYe7DHqR7O6e4vd4AsfIN2r7gvOgJCEj09pw/IIWDdw6qUndTkxmyOmAaNgnl6UzULm+MPNHx2P4ncPO/lufYCNBkj79vr/LN5LWIjVOQt8H4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1732119382; 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=ENHeXpbwI0l/b8sduXyY8+CnRMgMom8Dwun9yYuTmEs=; b=Bm7T3uvUTrhvdW/CKyJkhjGW5PxyOsevUbC1bX8HlfRY9HlwD2co6yYdv3iBDNAeqA2CoFMLKR9Xd+5RHrH+OY5SIPgyggMnZkuBemgUbBBmc96qvtofcMiqtrdiFUmDg0lAfrpSwcuWhDZoH9C/+cjVGAkxADfnwJycwi7jEjI= 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 173211938283290.53361738932563; Wed, 20 Nov 2024 08:16:22 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id ABC3711D2; Wed, 20 Nov 2024 11:16:21 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id B7AEA165; Wed, 20 Nov 2024 11:14:12 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 10D231085; Wed, 20 Nov 2024 11:14:08 -0500 (EST) Received: from mx1.osci.io (polly.osci.io [8.43.85.229]) (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 BE2131563 for ; Wed, 20 Nov 2024 11:13:34 -0500 (EST) Received: by mx1.osci.io (Postfix, from userid 995) id 7C73027A0B; Wed, 20 Nov 2024 11:13:34 -0500 (EST) Received: from relay.virtuozzo.com (relay.virtuozzo.com [130.117.225.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by mx1.osci.io (Postfix) with ESMTPS id 7F3EA20E04 for ; Wed, 20 Nov 2024 11:13:33 -0500 (EST) 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 1tDn0Z-0005yc-0Q; Wed, 20 Nov 2024 16:52:47 +0100 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_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 X-Greylist: delayed 1255 seconds by postgrey-1.37 at polly.osci.io; Wed, 20 Nov 2024 11:13:33 EST 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=iQgfyIq4F5B3WxNk6NRR7o41zYnjOEbDDF/8IS+71fM=; b=XJzGw/Evj2aJ NaaWE8I3mJQZB907NHFFJV2wvgRiYZw/WmBd4vgtPwJ85pemMTAgs/9L5XaF/uCDszanLwfIOTPN6 B6QejhTkhGKQHhCgFBZm4fPB7aVnaGMJEaJiRXWbw9xuXv7sEIABGIumnzXqaV7p1uBErRjIFE5xl LJJH4R6oRKA1q7U8KaedOziG8w3vX2VVUxlplZwK1RB6/wZyQiQxmNx8ql+Mj8MZSZktw79w0slW5 jvWHn52o4AKoyz1XVb22gMUY7X3Iq54N8ueo6JPspir6ptC/2ev8pgpi27dT+7w2hT8cwCmr2UaPh SQfgRdsXUcrj2yI4GhwoZA==; To: devel@lists.libvirt.org Subject: [PATCH 04/15] conf: implement XML parsing/formating for dataFileStore Date: Wed, 20 Nov 2024 18:48:39 +0300 Message-ID: <20241120155229.1259-5-nikolai.barybin@virtuozzo.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241120155229.1259-1-nikolai.barybin@virtuozzo.com> References: <20241120155229.1259-1-nikolai.barybin@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 5ZX6ILLYQFML35PIMAKLDDT4BMUVZ2QY X-Message-ID-Hash: 5ZX6ILLYQFML35PIMAKLDDT4BMUVZ2QY X-MailFrom: SRS0=E946=SP=virtuozzo.com=nikolai.barybin@osci.io 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: 1732119383744116600 Content-Type: text/plain; charset="utf-8" Data files are simple raw images. Thus, we don't need to parse too much. The main objectives are: - allow only RAW format - forbid storage slices - include this parsing/formatting into backing chain parse/format as well as into top storage source parse/format because data file can belong to backing image Signed-off-by: Nikolai Barybin --- src/conf/domain_conf.c | 100 +++++++++++++++++++++++++++++++++++++++++ src/conf/domain_conf.h | 13 ++++++ 2 files changed, 113 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 295707ec1f..9348c12725 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7670,6 +7670,62 @@ virDomainStorageSourceParse(xmlNodePtr node, } =20 =20 +int +virDomainDiskDataFileStoreParse(xmlXPathContextPtr ctxt, + virStorageSource *src, + unsigned int flags, + virDomainXMLOption *xmlopt) +{ + VIR_XPATH_NODE_AUTORESTORE(ctxt) + xmlNodePtr source; + g_autofree char *type =3D NULL; + g_autofree char *format =3D NULL; + g_autoptr(virStorageSource) dataFileStore =3D NULL; + + if (!(ctxt->node =3D virXPathNode("./dataFileStore", ctxt))) + return 0; + + if (!(type =3D virXMLPropStringRequired(ctxt->node, "type"))) + return -1; + + if (!(format =3D virXPathString("string(./format/@type)", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing data file store format")); + return -1; + } + + if (!(source =3D virXPathNode("./source", ctxt))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("missing disk data file store source")); + return -1; + } + + if (virStorageFileFormatTypeFromString(format) !=3D VIR_STORAGE_FILE_R= AW) { + virReportError(VIR_ERR_XML_ERROR, + _("unexpected disk data file format '%1$s', only ra= w format is supported"), + format); + return -1; + } + + if (!(dataFileStore =3D virDomainStorageSourceParseBase(type, format, = NULL))) + return -1; + + if (virDomainStorageSourceParse(source, ctxt, dataFileStore, flags, xm= lopt) < 0) + return -1; + + if (dataFileStore->sliceStorage) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("slices are not supported for fata file store sou= rce")); + return -1; + } + + dataFileStore->readonly =3D src->readonly; + src->dataFileStore =3D g_steal_pointer(&dataFileStore); + + return 0; +} + + int virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, virStorageSource *src, @@ -7720,6 +7776,7 @@ virDomainDiskBackingStoreParse(xmlXPathContextPtr ctx= t, backingStore->readonly =3D true; =20 if (virDomainStorageSourceParse(source, ctxt, backingStore, flags, xml= opt) < 0 || + virDomainDiskDataFileStoreParse(ctxt, backingStore, flags, xmlopt)= < 0 || virDomainDiskBackingStoreParse(ctxt, backingStore, flags, xmlopt) = < 0) return -1; =20 @@ -8112,6 +8169,9 @@ virDomainDiskDefParseSourceXML(virDomainXMLOption *xm= lopt, return NULL; } =20 + if (virDomainDiskDataFileStoreParse(ctxt, src, flags, xmlopt) < 0) + return NULL; + if (virDomainDiskBackingStoreParse(ctxt, src, flags, xmlopt) < 0) return NULL; =20 @@ -22885,6 +22945,38 @@ virDomainDiskSourceFormat(virBuffer *buf, return 0; } =20 +int +virDomainDiskDataFileStoreFormat(virBuffer *buf, + virStorageSource *src, + virDomainXMLOption *xmlopt, + unsigned int flags) +{ + g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) formatAttrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); + virStorageSource *dataFileStore =3D src->dataFileStore; + bool inactive =3D flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE; + + if (!dataFileStore) + return 0; + + /* don't write detected data file member to inactive xml */ + if (inactive && dataFileStore->detected) + return 0; + + virBufferAsprintf(&attrBuf, " type=3D'%s'", + virStorageTypeToString(dataFileStore->type)); + + virBufferAsprintf(&formatAttrBuf, " type=3D'%s'", "raw"); + virXMLFormatElement(&childBuf, "format", &formatAttrBuf, NULL); + + if (virDomainDiskSourceFormat(&childBuf, dataFileStore, "source", 0, f= alse, + flags, false, false, xmlopt) < 0) + return -1; + + virXMLFormatElement(buf, "dataFileStore", &attrBuf, &childBuf); + return 0; +} =20 int virDomainDiskBackingStoreFormat(virBuffer *buf, @@ -22943,6 +23035,10 @@ virDomainDiskBackingStoreFormat(virBuffer *buf, flags, false, false, xmlopt) < 0) return -1; =20 + if (backingStore->dataFileStore && + virDomainDiskDataFileStoreFormat(&childBuf, backingStore, xmlopt, = flags) < 0) + return -1; + if (virDomainDiskBackingStoreFormat(&childBuf, backingStore, xmlopt, f= lags) < 0) return -1; =20 @@ -23261,6 +23357,10 @@ virDomainDiskDefFormat(virBuffer *buf, if (virDomainDiskBackingStoreFormat(&childBuf, def->src, xmlopt, flags= ) < 0) return -1; =20 + if (def->src->dataFileStore && + virDomainDiskDataFileStoreFormat(&childBuf, def->src, xmlopt, flag= s) < 0) + return -1; + virBufferEscapeString(&childBuf, "\n", def= ->domain_name); =20 virDomainDiskGeometryDefFormat(&childBuf, def); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index a187ab4083..4d1939aa1b 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3909,6 +3909,12 @@ int virDomainDiskSourceFormat(virBuffer *buf, bool skipEnc, virDomainXMLOption *xmlopt); =20 +int +virDomainDiskDataFileStoreFormat(virBuffer *buf, + virStorageSource *src, + virDomainXMLOption *xmlopt, + unsigned int flags); + int virDomainDiskBackingStoreFormat(virBuffer *buf, virStorageSource *src, @@ -4426,6 +4432,13 @@ int virDomainStorageSourceParse(xmlNodePtr node, virDomainXMLOption *xmlopt) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); =20 +int +virDomainDiskDataFileStoreParse(xmlXPathContextPtr ctxt, + virStorageSource *src, + unsigned int flags, + virDomainXMLOption *xmlopt) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) G_GNUC_WARN_UNUSED_RESULT; + int virDomainDiskBackingStoreParse(xmlXPathContextPtr ctxt, virStorageSource *src, --=20 2.43.5