[PATCH v2] qemu: don't raise error upon interface update without <frames/> for <rx/> in coalesce

Kristina Hanicova khanicov at redhat.com
Wed Mar 10 17:01:17 UTC 2021


With this, incomplete XML without <frames/> for <rx/> in coalesce
won't raise error as before. It will leave the coalesce parameter
empty, thanks to passing it as a parameter and return an integer
to indicate error state - previously it returned pointer (or NULL
for both error and incomplete XML).
I also added a test case to test this functionality in the
qemuxml2xmltest.

The code went through some refactoring:
* change of a condition
* addition of a parameter
* change of order, that allowed removal of VIR_FREE
* removal of redundant labels and variables

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1535930
Signed-off-by: Kristina Hanicova <khanicov at redhat.com>
---

diff to v1:
- Added qemuxml2xmlout testcase, per Martin's review

 src/conf/domain_conf.c                    | 25 +++++++++--------------
 tests/qemuxml2argvdata/net-coalesce.xml   |  9 ++++++++
 tests/qemuxml2xmloutdata/net-coalesce.xml |  8 +++++++-
 3 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b731744f04..798594f520 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7516,11 +7516,11 @@ virDomainNetIPInfoParseXML(const char *source,
 }
 
 
-static virNetDevCoalescePtr
+static int
 virDomainNetDefCoalesceParseXML(xmlNodePtr node,
-                                xmlXPathContextPtr ctxt)
+                                xmlXPathContextPtr ctxt,
+                                virNetDevCoalescePtr *coalesce)
 {
-    virNetDevCoalescePtr ret = NULL;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     unsigned long long tmp = 0;
     g_autofree char *str = NULL;
@@ -7529,15 +7529,13 @@ virDomainNetDefCoalesceParseXML(xmlNodePtr node,
 
     str = virXPathString("string(./rx/frames/@max)", ctxt);
     if (!str)
-        return NULL;
-
-    ret = g_new0(virNetDevCoalesce, 1);
+        return 0;
 
     if (virStrToLong_ullp(str, NULL, 10, &tmp) < 0) {
         virReportError(VIR_ERR_XML_DETAIL,
                        _("cannot parse value '%s' for coalesce parameter"),
                        str);
-        goto error;
+        return -1;
     }
 
     if (tmp > UINT32_MAX) {
@@ -7545,15 +7543,13 @@ virDomainNetDefCoalesceParseXML(xmlNodePtr node,
                        _("value '%llu' is too big for coalesce "
                          "parameter, maximum is '%lu'"),
                        tmp, (unsigned long) UINT32_MAX);
-        goto error;
+        return -1;
     }
-    ret->rx_max_coalesced_frames = tmp;
 
-    return ret;
+    *coalesce = g_new0(virNetDevCoalesce, 1);
+    (*coalesce)->rx_max_coalesced_frames = tmp;
 
- error:
-    VIR_FREE(ret);
-    return NULL;
+    return 0;
 }
 
 static void
@@ -11517,8 +11513,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
 
     node = virXPathNode("./coalesce", ctxt);
     if (node) {
-        def->coalesce = virDomainNetDefCoalesceParseXML(node, ctxt);
-        if (!def->coalesce)
+        if (virDomainNetDefCoalesceParseXML(node, ctxt, &def->coalesce) < 0)
             goto error;
     }
 
diff --git a/tests/qemuxml2argvdata/net-coalesce.xml b/tests/qemuxml2argvdata/net-coalesce.xml
index bdcf786429..6fa3641e7d 100644
--- a/tests/qemuxml2argvdata/net-coalesce.xml
+++ b/tests/qemuxml2argvdata/net-coalesce.xml
@@ -55,6 +55,15 @@
         </rx>
       </coalesce>
     </interface>
+    <interface type='network'>
+      <source network='default'/>
+      <mac address='52:54:00:e5:48:60'/>
+      <model type='virtio'/>
+      <coalesce>
+        <rx>
+        </rx>
+      </coalesce>
+    </interface>
     <serial type='pty'>
       <target port='0'/>
     </serial>
diff --git a/tests/qemuxml2xmloutdata/net-coalesce.xml b/tests/qemuxml2xmloutdata/net-coalesce.xml
index 3a37587dde..452ed94de3 100644
--- a/tests/qemuxml2xmloutdata/net-coalesce.xml
+++ b/tests/qemuxml2xmloutdata/net-coalesce.xml
@@ -56,6 +56,12 @@
       <model type='virtio'/>
       <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
     </interface>
+    <interface type='network'>
+      <mac address='52:54:00:e5:48:60'/>
+      <source network='default'/>
+      <model type='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
+    </interface>
     <serial type='pty'>
       <target type='isa-serial' port='0'>
         <model name='isa-serial'/>
@@ -67,7 +73,7 @@
     <input type='mouse' bus='ps2'/>
     <input type='keyboard' bus='ps2'/>
     <memballoon model='virtio'>
-      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x08' function='0x0'/>
     </memballoon>
   </devices>
 </domain>
-- 
2.29.2




More information about the libvir-list mailing list