[libvirt] [PATCH 10/10] conf: Add and export wrapper for parsing storage source XML

Peter Krempa posted 10 patches 7 years, 2 months ago
[libvirt] [PATCH 10/10] conf: Add and export wrapper for parsing storage source XML
Posted by Peter Krempa 7 years, 2 months ago
Add a helper that parses a storage source XML node into a new
virStorageSource object. Since there are multiple approaches to store
the 'type' and 'format' attributes, they need to be parsed manually
prior to calling the function.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/conf/domain_conf.c   | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h   |  6 +++++
 src/libvirt_private.syms |  1 +
 3 files changed, 67 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 86fc275116..0b25c6316f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -8650,6 +8650,66 @@ virDomainStorageSourceParse(xmlNodePtr node,
 }


+/**
+ * virDomainStorageSourceParseNew:
+ * @node: XML node object to parse
+ * @ctxt: XML XPath context
+ * @flags: virDomainDefParseFlags
+ *
+ * Parses the XML @node and returns a virStorageSource object with the parsed
+ * data. Note that 'format' and 'type' attributes need to be members of the same
+ * object and need to be provided.
+ */
+virStorageSourcePtr
+virDomainStorageSourceParseNew(xmlNodePtr node,
+                               xmlXPathContextPtr ctxt,
+                               unsigned int flags)
+{
+    virStorageSourcePtr src = NULL;
+    virStorageSourcePtr ret = NULL;
+    char *format = NULL;
+    char *type = NULL;
+
+    if (VIR_ALLOC(src) < 0)
+        return NULL;
+
+    if (!(type = virXMLPropString(node, "type"))) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       _("missing storage source type"));
+        goto cleanup;
+    }
+
+    if (!(format = virXMLPropString(node, "format"))) {
+        virReportError(VIR_ERR_XML_ERROR, "%s",
+                       ("missing storage source format"));
+        goto cleanup;
+    }
+
+    if ((src->type = virStorageTypeFromString(type)) <= 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown storage source type '%s'"), type);
+        goto cleanup;
+    }
+
+    if ((src->format = virStorageFileFormatTypeFromString(format)) <= 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown storage source format '%s'"), format);
+        goto cleanup;
+    }
+
+    if (virDomainStorageSourceParse(node, ctxt, src, flags) < 0)
+        goto cleanup;
+
+    VIR_STEAL_PTR(ret, src);
+
+ cleanup:
+    virStorageSourceFree(src);
+    VIR_FREE(format);
+    VIR_FREE(type);
+    return ret;
+}
+
+
 int
 virDomainDiskSourceParse(xmlNodePtr node,
                          xmlXPathContextPtr ctxt,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 61379e50fe..c82a23d220 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3434,6 +3434,12 @@ int virDomainStorageSourceFormat(virBufferPtr attrBuf,
                                  bool skipSeclabels)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);

+virStorageSourcePtr
+virDomainStorageSourceParseNew(xmlNodePtr node,
+                               xmlXPathContextPtr ctxt,
+                               unsigned int flags)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
 int virDomainDefGetVcpuPinInfoHelper(virDomainDefPtr def,
                                      int maplen,
                                      int ncpumaps,
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index c67bce7389..4dfcbb4230 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -543,6 +543,7 @@ virDomainStateReasonToString;
 virDomainStateTypeFromString;
 virDomainStateTypeToString;
 virDomainStorageSourceFormat;
+virDomainStorageSourceParseNew;
 virDomainTaintTypeFromString;
 virDomainTaintTypeToString;
 virDomainTimerModeTypeFromString;
-- 
2.16.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 10/10] conf: Add and export wrapper for parsing storage source XML
Posted by Michal Privoznik 7 years, 2 months ago
On 03/13/2018 03:37 PM, Peter Krempa wrote:
> Add a helper that parses a storage source XML node into a new
> virStorageSource object. Since there are multiple approaches to store
> the 'type' and 'format' attributes, they need to be parsed manually
> prior to calling the function.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/conf/domain_conf.c   | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
>  src/conf/domain_conf.h   |  6 +++++
>  src/libvirt_private.syms |  1 +
>  3 files changed, 67 insertions(+)

Perhaps you forgot to include next patch that uses
virDomainStorageSourceParseNew()? Because this patch does nothing more
than introducing a function that is never used.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 10/10] conf: Add and export wrapper for parsing storage source XML
Posted by Peter Krempa 7 years, 2 months ago
On Wed, Mar 14, 2018 at 11:00:46 +0100, Michal Privoznik wrote:
> On 03/13/2018 03:37 PM, Peter Krempa wrote:
> > Add a helper that parses a storage source XML node into a new
> > virStorageSource object. Since there are multiple approaches to store
> > the 'type' and 'format' attributes, they need to be parsed manually
> > prior to calling the function.
> > 
> > Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> > ---
> >  src/conf/domain_conf.c   | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
> >  src/conf/domain_conf.h   |  6 +++++
> >  src/libvirt_private.syms |  1 +
> >  3 files changed, 67 insertions(+)
> 
> Perhaps you forgot to include next patch that uses
> virDomainStorageSourceParseNew()? Because this patch does nothing more
> than introducing a function that is never used.

Yes. The patch that uses this function was not posted yet. I'm sending
these sub-series out so that I don't have to send 50+ patches at once.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 10/10] conf: Add and export wrapper for parsing storage source XML
Posted by Michal Privoznik 7 years, 2 months ago
On 03/14/2018 11:57 AM, Peter Krempa wrote:
> On Wed, Mar 14, 2018 at 11:00:46 +0100, Michal Privoznik wrote:
>> On 03/13/2018 03:37 PM, Peter Krempa wrote:
>>> Add a helper that parses a storage source XML node into a new
>>> virStorageSource object. Since there are multiple approaches to store
>>> the 'type' and 'format' attributes, they need to be parsed manually
>>> prior to calling the function.
>>>
>>> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>>> ---
>>>  src/conf/domain_conf.c   | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
>>>  src/conf/domain_conf.h   |  6 +++++
>>>  src/libvirt_private.syms |  1 +
>>>  3 files changed, 67 insertions(+)
>>
>> Perhaps you forgot to include next patch that uses
>> virDomainStorageSourceParseNew()? Because this patch does nothing more
>> than introducing a function that is never used.
> 
> Yes. The patch that uses this function was not posted yet. I'm sending
> these sub-series out so that I don't have to send 50+ patches at once.

Okay. ACK then.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list