]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: don't pass interface type into virNetDevBandwidthParse
authorDaniel P. Berrangé <berrange@redhat.com>
Tue, 29 Jan 2019 17:26:40 +0000 (17:26 +0000)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 18 Apr 2019 10:27:09 +0000 (11:27 +0100)
The virNetDevBandwidthParse method uses the interface type to decide
whether to allow use of the "floor" parameter. Using the interface
type is not convenient as callers may not have that available, but
still wish to allow use of "floor". Switch to an explicit boolean
to control its usage.

Reviewed-by: Laine Stump <laine@laine.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
src/conf/domain_conf.c
src/conf/netdev_bandwidth_conf.c
src/conf/netdev_bandwidth_conf.h
src/conf/network_conf.c
tests/virnetdevbandwidthtest.c

index 51aa48f4211b2359e783b0b888435df62ec33576..c158a039043f8a342fe93a0a0b6ca86e843855f5 100644 (file)
@@ -11270,7 +11270,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node,
     if (bandwidth_node &&
         virNetDevBandwidthParse(&actual->bandwidth,
                                 bandwidth_node,
-                                actual->type) < 0)
+                                actual->type == VIR_DOMAIN_NET_TYPE_NETWORK) < 0)
         goto error;
 
     vlanNode = virXPathNode("./vlan", ctxt);
@@ -11609,7 +11609,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
             } else if (virXMLNodeNameEqual(cur, "bandwidth")) {
                 if (virNetDevBandwidthParse(&def->bandwidth,
                                             cur,
-                                            def->type) < 0)
+                                            def->type == VIR_DOMAIN_NET_TYPE_NETWORK) < 0)
                     goto error;
             } else if (virXMLNodeNameEqual(cur, "vlan")) {
                 if (virNetDevVlanParse(cur, ctxt, &def->vlan) < 0)
index 3113cde888c90a58a02e85a3e35a9a4841fd38c9..014941836d2ecb0831b6ba63cc746015e3af07e5 100644 (file)
@@ -100,18 +100,18 @@ virNetDevBandwidthParseRate(xmlNodePtr node, virNetDevBandwidthRatePtr rate)
  * virNetDevBandwidthParse:
  * @bandwidth: parsed bandwidth
  * @node: XML node
- * @net_type: one of virDomainNetType
+ * @allowFloor: whether "floor" setting is supported
  *
  * Parse bandwidth XML and return pointer to structure.
- * @net_type tell to which type will/is interface connected to.
- * Pass -1 if this is not called on interface.
+ * The @allowFloor attribute indicates whether the caller
+ * is able to support use of the "floor" setting.
  *
  * Returns !NULL on success, NULL on error.
  */
 int
 virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
                         xmlNodePtr node,
-                        int net_type)
+                        bool allowFloor)
 {
     int ret = -1;
     virNetDevBandwidthPtr def = NULL;
@@ -162,17 +162,9 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
             goto cleanup;
         }
 
-        if (def->in->floor && net_type != VIR_DOMAIN_NET_TYPE_NETWORK) {
-            if (net_type == -1) {
-                /* 'floor' on network isn't supported */
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("floor attribute isn't supported for "
-                                 "network's bandwidth yet"));
-            } else {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
-                               _("floor attribute is supported only for "
-                                 "interfaces of type network"));
-            }
+        if (def->in->floor && !allowFloor) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                           _("floor attribute is not supported for this config"));
             goto cleanup;
         }
     }
index cb1ffd29e02e33fb5775000ba753386abc3b5e55..7fe750ce27b114c04f8f72a119605886aa6ba4f7 100644 (file)
@@ -27,7 +27,7 @@
 
 int virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
                             xmlNodePtr node,
-                            int net_type)
+                            bool allowFloor)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
 int virNetDevBandwidthFormat(virNetDevBandwidthPtr def,
                              virBufferPtr buf);
index 78bff6f687e9d82969a26fc8530be1e63776f826..91562de269668f7f2fc2c4a424b42ead592d8ec6 100644 (file)
@@ -1188,7 +1188,7 @@ virNetworkPortGroupParseXML(virPortGroupDefPtr def,
 
     bandwidth_node = virXPathNode("./bandwidth", ctxt);
     if (bandwidth_node &&
-        virNetDevBandwidthParse(&def->bandwidth, bandwidth_node, -1) < 0)
+        virNetDevBandwidthParse(&def->bandwidth, bandwidth_node, false) < 0)
         goto cleanup;
 
     vlanNode = virXPathNode("./vlan", ctxt);
@@ -1682,7 +1682,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
     }
 
     if ((bandwidthNode = virXPathNode("./bandwidth", ctxt)) &&
-        virNetDevBandwidthParse(&def->bandwidth, bandwidthNode, -1) < 0)
+        virNetDevBandwidthParse(&def->bandwidth, bandwidthNode, false) < 0)
         goto error;
 
     vlanNode = virXPathNode("./vlan", ctxt);
index 96776fa033490cce66a1535392b15a214c5992f5..23788b4164736086862a15abc94b37840236037c 100644 (file)
@@ -55,7 +55,7 @@ struct testSetStruct {
  \
         rc = virNetDevBandwidthParse(&(var), \
                                      ctxt->node, \
-                                     VIR_DOMAIN_NET_TYPE_NETWORK); \
+                                     true); \
         xmlFreeDoc(doc); \
         xmlXPathFreeContext(ctxt); \
         if (rc < 0) \