提交 aa985af2 编写于 作者: P Pavel Mores 提交者: Michal Privoznik

qemu: check if 'floor' is supported for given interface and network

Even if an interface of type 'network', setting 'floor' is only supported
if the network's forward type is nat, route, open or none.
Signed-off-by: NPavel Mores <pmores@redhat.com>
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
上级 92a71456
...@@ -304,3 +304,23 @@ virNetDevBandwidthHasFloor(const virNetDevBandwidth *b) ...@@ -304,3 +304,23 @@ virNetDevBandwidthHasFloor(const virNetDevBandwidth *b)
{ {
return b && b->in && b->in->floor != 0; return b && b->in && b->in->floor != 0;
} }
bool virNetDevBandwidthSupportsFloor(virNetworkForwardType type)
{
switch (type) {
case VIR_NETWORK_FORWARD_NONE:
case VIR_NETWORK_FORWARD_NAT:
case VIR_NETWORK_FORWARD_ROUTE:
case VIR_NETWORK_FORWARD_OPEN:
return true;
case VIR_NETWORK_FORWARD_BRIDGE:
case VIR_NETWORK_FORWARD_PRIVATE:
case VIR_NETWORK_FORWARD_VEPA:
case VIR_NETWORK_FORWARD_PASSTHROUGH:
case VIR_NETWORK_FORWARD_HOSTDEV:
case VIR_NETWORK_FORWARD_LAST:
break;
}
return false;
}
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "virbuffer.h" #include "virbuffer.h"
#include "virxml.h" #include "virxml.h"
#include "domain_conf.h" #include "domain_conf.h"
#include "network_conf.h"
int virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth, int virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
unsigned int *class_id, unsigned int *class_id,
...@@ -60,3 +61,4 @@ static inline bool virNetDevSupportBandwidth(virDomainNetType type) ...@@ -60,3 +61,4 @@ static inline bool virNetDevSupportBandwidth(virDomainNetType type)
bool virNetDevBandwidthHasFloor(const virNetDevBandwidth *b); bool virNetDevBandwidthHasFloor(const virNetDevBandwidth *b);
bool virNetDevBandwidthSupportsFloor(virNetworkForwardType type);
...@@ -735,6 +735,7 @@ virDomainClearNetBandwidth; ...@@ -735,6 +735,7 @@ virDomainClearNetBandwidth;
virNetDevBandwidthFormat; virNetDevBandwidthFormat;
virNetDevBandwidthHasFloor; virNetDevBandwidthHasFloor;
virNetDevBandwidthParse; virNetDevBandwidthParse;
virNetDevBandwidthSupportsFloor;
# conf/netdev_vlan_conf.h # conf/netdev_vlan_conf.h
......
...@@ -5065,6 +5065,15 @@ networkCheckBandwidth(virNetworkObjPtr obj, ...@@ -5065,6 +5065,15 @@ networkCheckBandwidth(virNetworkObjPtr obj,
virMacAddrFormat(ifaceMac, ifmac); virMacAddrFormat(ifaceMac, ifmac);
if (virNetDevBandwidthHasFloor(ifaceBand) &&
!virNetDevBandwidthSupportsFloor(def->forward.type)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("Invalid use of 'floor' on interface with MAC address %s "
"- 'floor' is only supported for interface type 'network' with forward type 'nat', 'route', 'open' or none"),
ifmac);
return -1;
}
if (virNetDevBandwidthHasFloor(ifaceBand) && if (virNetDevBandwidthHasFloor(ifaceBand) &&
!(netBand && netBand->in)) { !(netBand && netBand->in)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册