From nobody Sun Feb 8 19:55:04 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1547760176421585.291266171912; Thu, 17 Jan 2019 13:22:56 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DF15DC0C6C34; Thu, 17 Jan 2019 21:22:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A5303608E8; Thu, 17 Jan 2019 21:22:53 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 45F8A18033CB; Thu, 17 Jan 2019 21:22:53 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0HLMPqC004118 for ; Thu, 17 Jan 2019 16:22:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id 29AF560BE8; Thu, 17 Jan 2019 21:22:25 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-116-60.phx2.redhat.com [10.3.116.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id D8C3A60BE5 for ; Thu, 17 Jan 2019 21:22:24 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Thu, 17 Jan 2019 16:22:12 -0500 Message-Id: <20190117212216.28316-7-jferlan@redhat.com> In-Reply-To: <20190117212216.28316-1-jferlan@redhat.com> References: <20190117212216.28316-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v4 06/10] conf: Introduce virStoragePoolXMLNamespace X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 17 Jan 2019 21:22:54 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Introduce the infrastructure necessary to manage a Storage Pool XML Namespace. The general concept is similar to virDomainXMLNamespace, except that for Storage Pools the storage backend specific details can be stored within the _virStoragePoolOptions unlike the domain processing code which manages its xmlopt's via the virDomainXMLOption which is allocated/passed around for each domain. This patch defines the add the parse, format, free, and href methods required to process the XML and callout from the Storage Pool Def parse, format, and free API's to perform the action on the XML data for/from the backend. Signed-off-by: John Ferlan Reviewed-by: Daniel P. Berrang=C3=A9 --- src/conf/storage_conf.c | 51 +++++++++++++++++++++++++++++++++++++++- src/conf/storage_conf.h | 24 +++++++++++++++++++ src/libvirt_private.syms | 1 + 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 76e0bb987b..a7298381ef 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -124,6 +124,9 @@ typedef virStoragePoolOptions *virStoragePoolOptionsPtr; struct _virStoragePoolOptions { unsigned int flags; int defaultFormat; + + virStoragePoolXMLNamespace ns; + virStoragePoolFormatToString formatToString; virStoragePoolFormatFromString formatFromString; }; @@ -318,6 +321,34 @@ virStoragePoolOptionsForPoolType(int type) } =20 =20 +/* virStoragePoolOptionsPoolTypeSetXMLNamespace: + * @type: virStoragePoolType + * @ns: xmlopt namespace pointer + * + * Store the @ns in the pool options for the particular backend. + * This allows the parse/format code to then directly call the Namespace + * method space (parse, format, href, free) as needed during processing. + * + * Returns: 0 on success, -1 on failure. + */ +int +virStoragePoolOptionsPoolTypeSetXMLNamespace(int type, + virStoragePoolXMLNamespacePtr= ns) +{ + int ret =3D -1; + virStoragePoolTypeInfoPtr backend =3D virStoragePoolTypeInfoLookup(typ= e); + + if (!backend) + goto cleanup; + + backend->poolOptions.ns =3D *ns; + ret =3D 0; + + cleanup: + return ret; +} + + static virStorageVolOptionsPtr virStorageVolOptionsForPoolType(int type) { @@ -401,6 +432,8 @@ virStoragePoolDefFree(virStoragePoolDefPtr def) =20 VIR_FREE(def->target.path); VIR_FREE(def->target.perms.label); + if (def->namespaceData && def->ns.free) + (def->ns.free)(def->namespaceData); VIR_FREE(def); } =20 @@ -835,6 +868,13 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) goto error; } =20 + /* Make a copy of all the callback pointers here for easier use, + * especially during the virStoragePoolSourceClear method */ + ret->ns =3D options->ns; + if (ret->ns.parse && + (ret->ns.parse)(ctxt, &ret->namespaceData) < 0) + goto error; + cleanup: VIR_FREE(uuid); VIR_FREE(type); @@ -1011,7 +1051,10 @@ virStoragePoolDefFormatBuf(virBufferPtr buf, _("unexpected pool type")); return -1; } - virBufferAsprintf(buf, "\n", type); + virBufferAsprintf(buf, "namespaceData && def->ns.href) + virBufferAsprintf(buf, " %s", (def->ns.href)()); + virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); virBufferEscapeString(buf, "%s\n", def->name); =20 @@ -1064,6 +1107,12 @@ virStoragePoolDefFormatBuf(virBufferPtr buf, virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); } + + if (def->namespaceData && def->ns.format) { + if ((def->ns.format)(buf, def->namespaceData) < 0) + return -1; + } + virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "\n"); =20 diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h index a6763447a7..24217eb401 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -33,6 +33,26 @@ =20 # include =20 +/* Various callbacks needed to parse/create Storage Pool XML's using + * a private namespace */ +typedef int (*virStoragePoolDefNamespaceParse)(xmlXPathContextPtr, void **= ); +typedef void (*virStoragePoolDefNamespaceFree)(void *); +typedef int (*virStoragePoolDefNamespaceXMLFormat)(virBufferPtr, void *); +typedef const char *(*virStoragePoolDefNamespaceHref)(void); + +typedef struct _virStoragePoolXMLNamespace virStoragePoolXMLNamespace; +typedef virStoragePoolXMLNamespace *virStoragePoolXMLNamespacePtr; +struct _virStoragePoolXMLNamespace { + virStoragePoolDefNamespaceParse parse; + virStoragePoolDefNamespaceFree free; + virStoragePoolDefNamespaceXMLFormat format; + virStoragePoolDefNamespaceHref href; +}; + +int +virStoragePoolOptionsPoolTypeSetXMLNamespace(int type, + virStoragePoolXMLNamespacePtr= ns); + /* * How the volume's data is stored on underlying * physical devices - can potentially span many @@ -222,6 +242,10 @@ struct _virStoragePoolDef { =20 virStoragePoolSource source; virStoragePoolTarget target; + + /* Pool backend specific XML namespace data */ + void *namespaceData; + virStoragePoolXMLNamespace ns; }; =20 typedef struct _virStoragePoolSourceList virStoragePoolSourceList; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c3d6306809..4d82797ee1 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -919,6 +919,7 @@ virStoragePoolFormatDiskTypeToString; virStoragePoolFormatFileSystemNetTypeToString; virStoragePoolFormatFileSystemTypeToString; virStoragePoolFormatLogicalTypeToString; +virStoragePoolOptionsPoolTypeSetXMLNamespace; virStoragePoolSaveConfig; virStoragePoolSaveState; virStoragePoolSourceClear; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list