[libvirt] [PATCHv2] replace 'if' type conditions with 'switch' for VIR_NETWORK_FORWARD_
by Shi Lei
v1 patch here: https://www.redhat.com/archives/libvir-list/2018-July/msg01314.html
since v1:
1. Change the type declaration of _virNetworkForwardDef.type
from int to virNetworkForwardType
2. use the default case to report out of range error with
virReportEnumRangeError
Signed-off-by: Shi Lei <shilei.massclouds(a)gmx.com>
---
src/conf/domain_conf.c | 49 ++++---
src/conf/network_conf.c | 73 +++++++---
src/conf/network_conf.h | 2 +-
src/conf/virnetworkobj.c | 24 +++-
src/esx/esx_network_driver.c | 19 ++-
src/libvirt_private.syms | 1 +
src/network/bridge_driver.c | 309 ++++++++++++++++++++++++++++---------------
src/qemu/qemu_process.c | 8 ++
8 files changed, 329 insertions(+), 156 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 178c6d2..de08788 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -29975,40 +29975,49 @@ virDomainNetResolveActualType(virDomainNetDefPtr iface)
if (!(def = virNetworkDefParseString(xml)))
goto cleanup;
- if ((def->forward.type == VIR_NETWORK_FORWARD_NONE) ||
- (def->forward.type == VIR_NETWORK_FORWARD_NAT) ||
- (def->forward.type == VIR_NETWORK_FORWARD_ROUTE) ||
- (def->forward.type == VIR_NETWORK_FORWARD_OPEN)) {
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
/* for these forward types, the actual net type really *is*
* NETWORK; we just keep the info from the portgroup in
* iface->data.network.actual
*/
ret = VIR_DOMAIN_NET_TYPE_NETWORK;
+ break;
- } else if ((def->forward.type == VIR_NETWORK_FORWARD_BRIDGE) &&
- def->bridge) {
-
- /* <forward type='bridge'/> <bridge name='xxx'/>
- * is VIR_DOMAIN_NET_TYPE_BRIDGE
- */
-
- ret = VIR_DOMAIN_NET_TYPE_BRIDGE;
-
- } else if (def->forward.type == VIR_NETWORK_FORWARD_HOSTDEV) {
-
+ case VIR_NETWORK_FORWARD_HOSTDEV:
ret = VIR_DOMAIN_NET_TYPE_HOSTDEV;
+ break;
- } else if ((def->forward.type == VIR_NETWORK_FORWARD_BRIDGE) ||
- (def->forward.type == VIR_NETWORK_FORWARD_PRIVATE) ||
- (def->forward.type == VIR_NETWORK_FORWARD_VEPA) ||
- (def->forward.type == VIR_NETWORK_FORWARD_PASSTHROUGH)) {
+ case VIR_NETWORK_FORWARD_BRIDGE:
+ if (def->bridge) {
+ /* <forward type='bridge'/> <bridge name='xxx'/>
+ * is VIR_DOMAIN_NET_TYPE_BRIDGE
+ */
+ ret = VIR_DOMAIN_NET_TYPE_BRIDGE;
+ break;
+ }
+
+ /* intentionally fall through to the direct case for
+ * VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined
+ */
+ ATTRIBUTE_FALLTHROUGH;
+ case VIR_NETWORK_FORWARD_PRIVATE:
+ case VIR_NETWORK_FORWARD_VEPA:
+ case VIR_NETWORK_FORWARD_PASSTHROUGH:
/* <forward type='bridge|private|vepa|passthrough'> are all
* VIR_DOMAIN_NET_TYPE_DIRECT.
*/
-
ret = VIR_DOMAIN_NET_TYPE_DIRECT;
+ break;
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, def->forward.type);
+ goto cleanup;
}
cleanup:
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 630a87f..526291c 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1955,21 +1955,40 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
goto error;
}
break;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, def->forward.type);
+ goto error;
}
VIR_FREE(stp);
- if (def->mtu &&
- (def->forward.type != VIR_NETWORK_FORWARD_NONE &&
- def->forward.type != VIR_NETWORK_FORWARD_NAT &&
- def->forward.type != VIR_NETWORK_FORWARD_ROUTE &&
- def->forward.type != VIR_NETWORK_FORWARD_OPEN)) {
- virReportError(VIR_ERR_XML_ERROR,
- _("mtu size only allowed in open, route, nat, "
- "and isolated mode, not in %s (network '%s')"),
- virNetworkForwardTypeToString(def->forward.type),
- def->name);
- goto error;
+ if (def->mtu) {
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
+ break;
+
+ 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:
+ virReportError(VIR_ERR_XML_ERROR,
+ _("mtu size only allowed in open, route, nat, "
+ "and isolated mode, not in %s (network '%s')"),
+ virNetworkForwardTypeToString(def->forward.type),
+ def->name);
+ goto error;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, def->forward.type);
+ goto error;
+ }
}
/* Extract custom metadata */
@@ -2349,6 +2368,7 @@ virNetworkDefFormatBuf(virBufferPtr buf,
char uuidstr[VIR_UUID_STRING_BUFLEN];
size_t i;
bool shortforward;
+ bool hasbridge = false;
virBufferAddLit(buf, "<network");
if (!(flags & VIR_NETWORK_XML_INACTIVE) && (def->connections > 0))
@@ -2469,22 +2489,33 @@ virNetworkDefFormatBuf(virBufferPtr buf,
virBufferAddLit(buf, "</forward>\n");
}
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
+ hasbridge = true;
+ break;
+
+ 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:
+ break;
- if (def->forward.type == VIR_NETWORK_FORWARD_NONE ||
- def->forward.type == VIR_NETWORK_FORWARD_NAT ||
- def->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
- def->forward.type == VIR_NETWORK_FORWARD_OPEN ||
- def->bridge || def->macTableManager) {
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, def->forward.type);
+ goto error;
+ }
+ if (hasbridge || def->bridge || def->macTableManager) {
virBufferAddLit(buf, "<bridge");
virBufferEscapeString(buf, " name='%s'", def->bridge);
- if (def->forward.type == VIR_NETWORK_FORWARD_NONE ||
- def->forward.type == VIR_NETWORK_FORWARD_NAT ||
- def->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
- def->forward.type == VIR_NETWORK_FORWARD_OPEN) {
+ if (hasbridge)
virBufferAsprintf(buf, " stp='%s' delay='%ld'",
def->stp ? "on" : "off", def->delay);
- }
if (def->macTableManager) {
virBufferAsprintf(buf, " macTableManager='%s'",
virNetworkBridgeMACTableManagerTypeToString(def->macTableManager));
diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
index 54c8ed1..8fa8114 100644
--- a/src/conf/network_conf.h
+++ b/src/conf/network_conf.h
@@ -199,7 +199,7 @@ struct _virNetworkForwardPfDef {
typedef struct _virNetworkForwardDef virNetworkForwardDef;
typedef virNetworkForwardDef *virNetworkForwardDefPtr;
struct _virNetworkForwardDef {
- int type; /* One of virNetworkForwardType constants */
+ virNetworkForwardType type;
bool managed; /* managed attribute for hostdev mode */
int driverName; /* enum virNetworkForwardDriverNameType */
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index e00c8a7..81b53e8 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -1009,19 +1009,31 @@ virNetworkLoadConfig(virNetworkObjListPtr nets,
goto error;
}
- if (def->forward.type == VIR_NETWORK_FORWARD_NONE ||
- def->forward.type == VIR_NETWORK_FORWARD_NAT ||
- def->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
- def->forward.type == VIR_NETWORK_FORWARD_OPEN) {
-
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
if (!def->mac_specified) {
virNetworkSetBridgeMacAddr(def);
virNetworkSaveConfig(configDir, def);
}
- } else {
+ break;
+
+ 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:
/* Throw away MAC address for other forward types,
* which could have been generated by older libvirt RPMs */
def->mac_specified = false;
+ break;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, def->forward.type);
+ goto error;
}
if (!(obj = virNetworkObjAssignDef(nets, def, 0)))
diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c
index 04118b4..4d1b3cd 100644
--- a/src/esx/esx_network_driver.c
+++ b/src/esx/esx_network_driver.c
@@ -326,12 +326,27 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml)
}
/* FIXME: Add support for NAT */
- if (def->forward.type != VIR_NETWORK_FORWARD_NONE &&
- def->forward.type != VIR_NETWORK_FORWARD_BRIDGE) {
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_BRIDGE:
+ break;
+
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
+ case VIR_NETWORK_FORWARD_PRIVATE:
+ case VIR_NETWORK_FORWARD_VEPA:
+ case VIR_NETWORK_FORWARD_PASSTHROUGH:
+ case VIR_NETWORK_FORWARD_HOSTDEV:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported forward mode '%s'"),
virNetworkForwardTypeToString(def->forward.type));
goto cleanup;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, def->forward.type);
+ goto cleanup;
}
/* Verify that specified HostPortGroups don't exist already */
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1a4cf98..fc386e1 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2369,6 +2369,7 @@ virNetDevMacVLanCreate;
virNetDevMacVLanCreateWithVPortProfile;
virNetDevMacVLanDelete;
virNetDevMacVLanDeleteWithVPortProfile;
+virNetDevMacVLanModeTypeFromString;
virNetDevMacVLanReleaseName;
virNetDevMacVLanReserveName;
virNetDevMacVLanRestartWithVPortProfile;
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index da3c32e..a6c9111 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -485,6 +485,11 @@ networkUpdateState(virNetworkObjPtr obj,
case VIR_NETWORK_FORWARD_HOSTDEV:
/* so far no extra checks */
break;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, def->forward.type);
+ goto cleanup;
}
/* Try and read dnsmasq/radvd pids of active networks */
@@ -2088,20 +2093,37 @@ networkRefreshDaemonsHelper(virNetworkObjPtr obj,
virObjectLock(obj);
def = virNetworkObjGetDef(obj);
- if (virNetworkObjIsActive(obj) &&
- ((def->forward.type == VIR_NETWORK_FORWARD_NONE) ||
- (def->forward.type == VIR_NETWORK_FORWARD_NAT) ||
- (def->forward.type == VIR_NETWORK_FORWARD_ROUTE) ||
- (def->forward.type == VIR_NETWORK_FORWARD_OPEN))) {
- /* Only the three L3 network types that are configured by
- * libvirt will have a dnsmasq or radvd daemon associated
- * with them. Here we send a SIGHUP to an existing
- * dnsmasq and/or radvd, or restart them if they've
- * disappeared.
- */
- networkRefreshDhcpDaemon(driver, obj);
- networkRefreshRadvd(driver, obj);
+ if (virNetworkObjIsActive(obj)) {
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
+ /* Only the three L3 network types that are configured by
+ * libvirt will have a dnsmasq or radvd daemon associated
+ * with them. Here we send a SIGHUP to an existing
+ * dnsmasq and/or radvd, or restart them if they've
+ * disappeared.
+ */
+ networkRefreshDhcpDaemon(driver, obj);
+ networkRefreshRadvd(driver, obj);
+ break;
+
+ 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:
+ break;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, def->forward.type);
+ goto cleanup;
+ }
}
+
+ cleanup:
virObjectUnlock(obj);
return 0;
}
@@ -2128,20 +2150,37 @@ networkReloadFirewallRulesHelper(virNetworkObjPtr obj,
virObjectLock(obj);
def = virNetworkObjGetDef(obj);
- if (virNetworkObjIsActive(obj) &&
- ((def->forward.type == VIR_NETWORK_FORWARD_NONE) ||
- (def->forward.type == VIR_NETWORK_FORWARD_NAT) ||
- (def->forward.type == VIR_NETWORK_FORWARD_ROUTE))) {
- /* Only three of the L3 network types that are configured by
- * libvirt need to have iptables rules reloaded. The 4th L3
- * network type, forward='open', doesn't need this because it
- * has no iptables rules.
- */
- networkRemoveFirewallRules(def);
- if (networkAddFirewallRules(def) < 0) {
- /* failed to add but already logged */
+ if (virNetworkObjIsActive(obj)) {
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ /* Only three of the L3 network types that are configured by
+ * libvirt need to have iptables rules reloaded. The 4th L3
+ * network type, forward='open', doesn't need this because it
+ * has no iptables rules.
+ */
+ networkRemoveFirewallRules(def);
+ /* No need to check return value since already logged internally */
+ ignore_value(networkAddFirewallRules(def));
+ break;
+
+ case VIR_NETWORK_FORWARD_OPEN:
+ 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:
+ break;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, def->forward.type);
+ goto cleanup;
}
}
+
+ cleanup:
virObjectUnlock(obj);
return 0;
}
@@ -2719,9 +2758,13 @@ networkCreateInterfacePool(virNetworkDefPtr netdef)
case VIR_NETWORK_FORWARD_NAT:
case VIR_NETWORK_FORWARD_ROUTE:
case VIR_NETWORK_FORWARD_OPEN:
- case VIR_NETWORK_FORWARD_LAST:
/* by definition these will never be encountered here */
break;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, netdef->forward.type);
+ goto cleanup;
}
}
@@ -2840,6 +2883,11 @@ networkStartNetwork(virNetworkDriverStatePtr driver,
if (networkStartNetworkExternal(obj) < 0)
goto cleanup;
break;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, def->forward.type);
+ goto cleanup;
}
/* finally we can call the 'started' hook script if any */
@@ -2919,6 +2967,11 @@ networkShutdownNetwork(virNetworkDriverStatePtr driver,
case VIR_NETWORK_FORWARD_HOSTDEV:
ret = networkShutdownNetworkExternal(obj);
break;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, def->forward.type);
+ return -1;
}
/* now that we know it's stopped call the hook if present */
@@ -3273,11 +3326,11 @@ networkValidate(virNetworkDriverStatePtr driver,
/* Only the three L3 network types that are configured by libvirt
* need to have a bridge device name / mac address provided
*/
- if (def->forward.type == VIR_NETWORK_FORWARD_NONE ||
- def->forward.type == VIR_NETWORK_FORWARD_NAT ||
- def->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
- def->forward.type == VIR_NETWORK_FORWARD_OPEN) {
-
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
/* if no bridge name was given in the config, find a name
* unused by any other libvirt networks and assign it.
*/
@@ -3285,7 +3338,13 @@ networkValidate(virNetworkDriverStatePtr driver,
return -1;
virNetworkSetBridgeMacAddr(def);
- } else {
+ break;
+
+ 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:
/* They are also the only types that currently support setting
* a MAC or IP address for the host-side device (bridge), DNS
* configuration, or network-wide bandwidth limits.
@@ -3331,6 +3390,12 @@ networkValidate(virNetworkDriverStatePtr driver,
return -1;
}
bandwidthAllowed = false;
+ break;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, def->forward.type);
+ return -1;
}
/* we support configs with a single PF defined:
@@ -3755,9 +3820,10 @@ networkUpdate(virNetworkPtr net,
/* Take care of anything that must be done before updating the
* live NetworkDef.
*/
- if (def->forward.type == VIR_NETWORK_FORWARD_NONE ||
- def->forward.type == VIR_NETWORK_FORWARD_NAT ||
- def->forward.type == VIR_NETWORK_FORWARD_ROUTE) {
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
switch (section) {
case VIR_NETWORK_SECTION_FORWARD:
case VIR_NETWORK_SECTION_FORWARD_INTERFACE:
@@ -3768,14 +3834,26 @@ networkUpdate(virNetworkPtr net,
* old rules (and remember to load new ones after the
* update).
*/
- if (def->forward.type != VIR_NETWORK_FORWARD_OPEN) {
- networkRemoveFirewallRules(def);
- needFirewallRefresh = true;
- }
+ networkRemoveFirewallRules(def);
+ needFirewallRefresh = true;
break;
default:
break;
}
+ break;
+
+ case VIR_NETWORK_FORWARD_OPEN:
+ 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:
+ break;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, def->forward.type);
+ goto cleanup;
}
}
@@ -4440,10 +4518,11 @@ networkAllocateActualDevice(virDomainDefPtr dom,
iface->data.network.actual->trustGuestRxFilters
= netdef->trustGuestRxFilters;
- if ((netdef->forward.type == VIR_NETWORK_FORWARD_NONE) ||
- (netdef->forward.type == VIR_NETWORK_FORWARD_NAT) ||
- (netdef->forward.type == VIR_NETWORK_FORWARD_ROUTE) ||
- (netdef->forward.type == VIR_NETWORK_FORWARD_OPEN)) {
+ switch (netdef->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
/* for these forward types, the actual net type really *is*
* NETWORK; we just keep the info from the portgroup in
* iface->data.network.actual
@@ -4463,46 +4542,9 @@ networkAllocateActualDevice(virDomainDefPtr dom,
if (networkPlugBandwidth(obj, iface) < 0)
goto error;
+ break;
- } else if ((netdef->forward.type == VIR_NETWORK_FORWARD_BRIDGE) &&
- netdef->bridge) {
-
- /* <forward type='bridge'/> <bridge name='xxx'/>
- * is VIR_DOMAIN_NET_TYPE_BRIDGE
- */
-
- iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_BRIDGE;
- if (VIR_STRDUP(iface->data.network.actual->data.bridge.brname,
- netdef->bridge) < 0)
- goto error;
- iface->data.network.actual->data.bridge.macTableManager
- = netdef->macTableManager;
-
- /* merge virtualports from interface, network, and portgroup to
- * arrive at actual virtualport to use
- */
- if (virNetDevVPortProfileMerge3(&iface->data.network.actual->virtPortProfile,
- iface->virtPortProfile,
- netdef->virtPortProfile,
- portgroup
- ? portgroup->virtPortProfile : NULL) < 0) {
- goto error;
- }
- virtport = iface->data.network.actual->virtPortProfile;
- if (virtport) {
- /* only type='openvswitch' is allowed for bridges */
- if (virtport->virtPortType != VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("<virtualport type='%s'> not supported for network "
- "'%s' which uses a bridge device"),
- virNetDevVPortTypeToString(virtport->virtPortType),
- netdef->name);
- goto error;
- }
- }
-
- } else if (netdef->forward.type == VIR_NETWORK_FORWARD_HOSTDEV) {
-
+ case VIR_NETWORK_FORWARD_HOSTDEV: {
virDomainHostdevSubsysPCIBackendType backend;
iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_HOSTDEV;
@@ -4575,32 +4617,67 @@ networkAllocateActualDevice(virDomainDefPtr dom,
goto error;
}
}
+ break;
+ }
- } else if ((netdef->forward.type == VIR_NETWORK_FORWARD_BRIDGE) ||
- (netdef->forward.type == VIR_NETWORK_FORWARD_PRIVATE) ||
- (netdef->forward.type == VIR_NETWORK_FORWARD_VEPA) ||
- (netdef->forward.type == VIR_NETWORK_FORWARD_PASSTHROUGH)) {
+ case VIR_NETWORK_FORWARD_BRIDGE:
+ if (netdef->bridge) {
+ /* <forward type='bridge'/> <bridge name='xxx'/>
+ * is VIR_DOMAIN_NET_TYPE_BRIDGE
+ */
+ iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_BRIDGE;
+ if (VIR_STRDUP(iface->data.network.actual->data.bridge.brname,
+ netdef->bridge) < 0)
+ goto error;
+ iface->data.network.actual->data.bridge.macTableManager
+ = netdef->macTableManager;
+
+ /* merge virtualports from interface, network, and portgroup to
+ * arrive at actual virtualport to use
+ */
+ if (virNetDevVPortProfileMerge3(&iface->data.network.actual->virtPortProfile,
+ iface->virtPortProfile,
+ netdef->virtPortProfile,
+ portgroup
+ ? portgroup->virtPortProfile : NULL) < 0) {
+ goto error;
+ }
+ virtport = iface->data.network.actual->virtPortProfile;
+ if (virtport) {
+ /* only type='openvswitch' is allowed for bridges */
+ if (virtport->virtPortType != VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("<virtualport type='%s'> not supported for network "
+ "'%s' which uses a bridge device"),
+ virNetDevVPortTypeToString(virtport->virtPortType),
+ netdef->name);
+ goto error;
+ }
+ }
+ break;
+ }
+
+ /* intentionally fall through to the direct case for
+ * VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined
+ */
+ ATTRIBUTE_FALLTHROUGH;
+
+ case VIR_NETWORK_FORWARD_PRIVATE:
+ case VIR_NETWORK_FORWARD_VEPA:
+ case VIR_NETWORK_FORWARD_PASSTHROUGH:
/* <forward type='bridge|private|vepa|passthrough'> are all
* VIR_DOMAIN_NET_TYPE_DIRECT.
*/
/* Set type=direct and appropriate <source mode='xxx'/> */
iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_DIRECT;
- switch (netdef->forward.type) {
- case VIR_NETWORK_FORWARD_BRIDGE:
- iface->data.network.actual->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_BRIDGE;
- break;
- case VIR_NETWORK_FORWARD_PRIVATE:
- iface->data.network.actual->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_PRIVATE;
- break;
- case VIR_NETWORK_FORWARD_VEPA:
- iface->data.network.actual->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_VEPA;
- break;
- case VIR_NETWORK_FORWARD_PASSTHROUGH:
- iface->data.network.actual->data.direct.mode = VIR_NETDEV_MACVLAN_MODE_PASSTHRU;
- break;
- }
+
+ /* NO need to check the value returned from virNetDevMacVLanModeTypeFromString
+ * it must be valid for these forward type(bridge|private|vepa|passthrough)
+ */
+ iface->data.network.actual->data.direct.mode =
+ virNetDevMacVLanModeTypeFromString(virNetworkForwardTypeToString(netdef->forward.type));
/* merge virtualports from interface, network, and portgroup to
* arrive at actual virtualport to use
@@ -4680,6 +4757,12 @@ networkAllocateActualDevice(virDomainDefPtr dom,
dev->device.dev) < 0)
goto error;
}
+ break;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, netdef->forward.type);
+ goto error;
}
if (virNetworkObjMacMgrAdd(obj, driver->dnsmasqStateDir,
@@ -5037,13 +5120,27 @@ networkReleaseActualDevice(virDomainDefPtr dom,
}
netdef = virNetworkObjGetDef(obj);
- if (iface->data.network.actual &&
- (netdef->forward.type == VIR_NETWORK_FORWARD_NONE ||
- netdef->forward.type == VIR_NETWORK_FORWARD_NAT ||
- netdef->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
- netdef->forward.type == VIR_NETWORK_FORWARD_OPEN) &&
- networkUnplugBandwidth(obj, iface) < 0)
+ switch (netdef->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
+ if (iface->data.network.actual && networkUnplugBandwidth(obj, iface) < 0)
+ goto error;
+ break;
+
+ 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:
+ break;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, netdef->forward.type);
goto error;
+ }
if ((!iface->data.network.actual) ||
((actualType != VIR_DOMAIN_NET_TYPE_DIRECT) &&
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index bba157b..1946a28 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4582,6 +4582,14 @@ qemuProcessGetNetworkAddress(const char *netname,
goto cleanup;
}
break;
+
+ case VIR_NETWORK_FORWARD_HOSTDEV:
+ break;
+
+ case VIR_NETWORK_FORWARD_LAST:
+ default:
+ virReportEnumRangeError(virNetworkForwardType, netdef->forward.type);
+ goto cleanup;
}
if (dev_name) {
--
2.7.4
6 years, 5 months
[libvirt] [PATCH v2 0/6] Fixes for segfault and deadlock
by Marc Hartmayer
One way to reproduce the bugs is to set admin_max_workers=0 in
libvirtd.conf, restart libvirtd, and then call:
$ virt-admin server-threadpool-info admin
Changelog:
v1->v2:
- Worked in Daniel Berrangé's comments that:
1. max_workers=0 should not be allowed for the libvirtd (patch 3)
2. it shouldn't be allowed to switch between zero and non-zero
max_workers (patch 4)
- Changed the deadlock fix (patch 1)
- Added two small fixes (patch 5 and 6)
Marc Hartmayer (6):
rpc: Fix deadlock if there is no worker pool available
rpc: Initialize a worker pool for max_workers=0 as well
virThreadPool: Prevent switching between zero and non-zero maxWorkers
daemon: Raise an error if 'max_workers' < 1 in libvirtd.conf
virt-admin: Fix two error messages
rpc: Fix name of include guard
src/libvirt_private.syms | 4 ++
src/remote/remote_daemon_config.c | 5 +++
src/rpc/virnetserver.c | 28 ++++++++------
src/rpc/virnetserverprogram.h | 4 +-
src/util/virthreadpool.c | 81 ++++++++++++++++++++++++++++++---------
src/util/virthreadpool.h | 8 ++++
tools/virt-admin.c | 5 ++-
7 files changed, 101 insertions(+), 34 deletions(-)
--
2.13.4
6 years, 5 months
[libvirt] [PATCH 00/10] qemu: hotplug: Refactor for -blockdev support (blockdev-add saga)
by Peter Krempa
A bunch of refactors which could be separated from my blockdev add
branch.
The patches modify the disk hotplug/unplug and media change code so that
we can easily add support for -blockdev later on.
Peter Krempa (10):
qemu: hotplug: Reuse qemuHotplugPrepareDiskAccess in
qemuDomainRemoveDiskDevice
qemu: hotplug: Remove pointless variable
qemu: hotplug: Don't format NULL in %s in qemuHotplugPrepareDiskAccess
qemu: hotplug: Prepare for multiple backing chain member hotplug
qemu: hotplug: Don't leak 'disk' if VM crashes during unplug finishing
qemu: hotplug: Reuse qemuHotplugDiskSourceRemove for disk backend
removal
qemu: hotplug: Simplify removal of managed PR infrastructure on unplug
qemu: hotplug: Refactor/simplify PR managed addition to VM
qemu: hotplug: Extract legacy disk media changing bits
qemu: hotplug: Make qemuHotplugWaitForTrayEject reusable
src/qemu/qemu_hotplug.c | 508 ++++++++++++++++++++++++++++++++++--------------
1 file changed, 358 insertions(+), 150 deletions(-)
--
2.16.2
6 years, 5 months
[libvirt] [PATCH] src: Fix memory leak in virNWFilterBindingDispose
by John Ferlan
https://bugzilla.redhat.com/show_bug.cgi?id=1603025
Commit b57a9aec neglected to VIR_FREE(binding->filtername) as seen
in the following valgrind report
==6423== 17,328 bytes in 1,083 blocks are definitely lost in loss record 2,275 of 2,297
==6423== at 0x4C29BC3: malloc (vg_replace_malloc.c:299)
==6423== by 0x83B20C9: strdup (in /usr/lib64/libc-2.17.so)
==6423== by 0x533C144: virStrdup (virstring.c:977)
==6423== by 0x54BDD53: virGetNWFilterBinding (datatypes.c:865)
==6423== by 0x318D633C: nwfilterBindingCreateXML (nwfilter_driver.c:767)
==6423== by 0x54F3FC5: virNWFilterBindingCreateXML (libvirt-nwfilter.c:701)
==6423== by 0x539CE29: virDomainConfNWFilterInstantiate (domain_nwfilter.c:116)
==6423== by 0x31E516C2: qemuInterfaceBridgeConnect (qemu_interface.c:589)
==6423== by 0x31D98B56: qemuBuildInterfaceCommandLine (qemu_command.c:8418)
==6423== by 0x31D9F783: qemuBuildNetCommandLine (qemu_command.c:8673)
==6423== by 0x31D9F783: qemuBuildCommandLine (qemu_command.c:10354)
==6423== by 0x31DE355F: qemuProcessLaunch (qemu_process.c:6292)
==6423== by 0x31DE7881: qemuProcessStart (qemu_process.c:6686)
and
==6423== 17,328 bytes in 1,083 blocks are definitely lost in loss record 2,276 of 2,297
==6423== at 0x4C29BC3: malloc (vg_replace_malloc.c:299)
==6423== by 0x83B20C9: strdup (in /usr/lib64/libc-2.17.so)
==6423== by 0x533C144: virStrdup (virstring.c:977)
==6423== by 0x54BDD53: virGetNWFilterBinding (datatypes.c:865)
==6423== by 0x318D641F: nwfilterBindingLookupByPortDev (nwfilter_driver.c:678)
==6423== by 0x54F3B63: virNWFilterBindingLookupByPortDev (libvirt-nwfilter.c:593)
==6423== by 0x539CBC5: virDomainConfNWFilterTeardownImpl.isra.0 (domain_nwfilter.c:136)
==6423== by 0x539CFA5: virDomainConfVMNWFilterTeardown (domain_nwfilter.c:170)
==6423== by 0x31DE5651: qemuProcessStop (qemu_process.c:6912)
==6423== by 0x31E37974: qemuDomainDestroyFlags (qemu_driver.c:2229)
==6423== by 0x54C24BB: virDomainDestroy (libvirt-domain.c:475)
==6423== by 0x1589A2: remoteDispatchDomainDestroy (remote_daemon_dispatch_stubs.h:4827)
==6423== by 0x1589A2: remoteDispatchDomainDestroyHelper (remote_daemon_dispatch_stubs.h:4803)
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/datatypes.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/datatypes.c b/src/datatypes.c
index 878a1c5b5f..caf035f178 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -893,6 +893,7 @@ virNWFilterBindingDispose(void *obj)
VIR_DEBUG("release binding %p %s", binding, binding->portdev);
VIR_FREE(binding->portdev);
+ VIR_FREE(binding->filtername);
virObjectUnref(binding->conn);
}
--
2.17.1
6 years, 5 months
[libvirt] [PATCH 0/2] rpm: modernize the spec file for RHEL
by Daniel P. Berrangé
Drop conditionals for RHEL-6 and assume systemd is present
Daniel P. Berrangé (2):
rpm: increase min required RHEL to 7
rpm: remove conditionals for systemd
libvirt.spec.in | 246 ++++--------------------------------------------
1 file changed, 20 insertions(+), 226 deletions(-)
--
2.17.1
6 years, 5 months
[libvirt] [PATCH 0/9] qemu: stats/misc refactors (blockdev-add saga)
by Peter Krempa
Last lot of refactors which could be split of prior to starting it for
real.
Peter Krempa (9):
qemu: driver: Reuse qemuDomainBlocksStatsGather in
qemuDomainGetBlockInfo
qemu: domain: Move out clearing of backing chain in
qemuDomainDetermineDiskChain
qemu: domain: Add helper for getting the disk backend alias
qemu: command: use qemuDomainDiskGetBackendAlias in commandline
building
qemu: monitor: Add the 'query-nodes' argument for query-blockstats
qemu: json: Extract gathering of block statistics
qemu: monitor: Split out code to gather data from 'query-block'
utils: storage: Add helper for checking if storage source is the same
qemu: Replace qemuDomainDiskSourceDiffers by
virStorageSourceIsSameLocation
src/libvirt_private.syms | 1 +
src/qemu/qemu_block.c | 2 +-
src/qemu/qemu_blockjob.c | 4 +-
src/qemu/qemu_command.c | 24 ++++++----
src/qemu/qemu_domain.c | 66 ++++++++++++---------------
src/qemu/qemu_domain.h | 10 +++--
src/qemu/qemu_driver.c | 47 +++++++-------------
src/qemu/qemu_hotplug.c | 2 +-
src/qemu/qemu_monitor.c | 8 +++-
src/qemu/qemu_monitor.h | 3 +-
src/qemu/qemu_monitor_json.c | 103 ++++++++++++++++++++++++++++---------------
src/qemu/qemu_monitor_json.h | 3 +-
src/qemu/qemu_process.c | 7 ++-
src/util/virstoragefile.c | 43 ++++++++++++++++++
src/util/virstoragefile.h | 3 ++
15 files changed, 198 insertions(+), 128 deletions(-)
--
2.16.2
6 years, 5 months
[libvirt] [PATCH] utils: storage: Add copying of PR definition to virStorageSource
by Peter Krempa
Despite the warning that virStorageSourceCopy needs to be populated on
additions to the structure commit 687730540e4 neglected to implement the
copy function.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/util/virstoragefile.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 58f67278da..b6a2b415e9 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -2041,6 +2041,29 @@ virStorageSourceChainHasManagedPR(virStorageSourcePtr src)
}
+static virStoragePRDefPtr
+virStoragePRDefCopy(virStoragePRDefPtr src)
+{
+ virStoragePRDefPtr copy = NULL;
+ virStoragePRDefPtr ret = NULL;
+
+ if (VIR_ALLOC(copy) < 0)
+ return NULL;
+
+ copy->managed = src->managed;
+
+ if (VIR_STRDUP(copy->path, src->path) < 0 ||
+ VIR_STRDUP(copy->mgralias, src->mgralias) < 0)
+ goto cleanup;
+
+ VIR_STEAL_PTR(ret, copy);
+
+ cleanup:
+ virStoragePRDefFree(copy);
+ return ret;
+}
+
+
virSecurityDeviceLabelDefPtr
virStorageSourceGetSecurityLabelDef(virStorageSourcePtr src,
const char *model)
@@ -2245,6 +2268,10 @@ virStorageSourceCopy(const virStorageSource *src,
!(ret->auth = virStorageAuthDefCopy(src->auth)))
goto error;
+ if (src->pr &&
+ !(ret->pr = virStoragePRDefCopy(src->pr)))
+ goto error;
+
if (backingChain && src->backingStore) {
if (!(ret->backingStore = virStorageSourceCopy(src->backingStore,
true)))
--
2.16.2
6 years, 5 months
[libvirt] [PATCH] replace 'if' type conditions with 'switch' for VIR_NETWORK_FORWARD_*
by Shi Lei
Hi, everyone!
For VIR_NETWORK_FORWARD_*, I try to replace 'if' type conditions
with typed 'switch()'.
It might be more clear.
Signed-off-by: Shi Lei <shilei.massclouds(a)gmx.com>
---
src/conf/domain_conf.c | 46 +++++-----
src/conf/network_conf.c | 49 ++++++-----
src/conf/virnetworkobj.c | 15 ++--
src/esx/esx_network_driver.c | 8 +-
src/network/bridge_driver.c | 203 +++++++++++++++++++++++--------------------
5 files changed, 178 insertions(+), 143 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 178c6d2..c02543f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -29975,40 +29975,44 @@ virDomainNetResolveActualType(virDomainNetDefPtr iface)
if (!(def = virNetworkDefParseString(xml)))
goto cleanup;
- if ((def->forward.type == VIR_NETWORK_FORWARD_NONE) ||
- (def->forward.type == VIR_NETWORK_FORWARD_NAT) ||
- (def->forward.type == VIR_NETWORK_FORWARD_ROUTE) ||
- (def->forward.type == VIR_NETWORK_FORWARD_OPEN)) {
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
/* for these forward types, the actual net type really *is*
* NETWORK; we just keep the info from the portgroup in
* iface->data.network.actual
*/
ret = VIR_DOMAIN_NET_TYPE_NETWORK;
+ break;
- } else if ((def->forward.type == VIR_NETWORK_FORWARD_BRIDGE) &&
- def->bridge) {
-
- /* <forward type='bridge'/> <bridge name='xxx'/>
- * is VIR_DOMAIN_NET_TYPE_BRIDGE
- */
-
- ret = VIR_DOMAIN_NET_TYPE_BRIDGE;
-
- } else if (def->forward.type == VIR_NETWORK_FORWARD_HOSTDEV) {
-
+ case VIR_NETWORK_FORWARD_HOSTDEV:
ret = VIR_DOMAIN_NET_TYPE_HOSTDEV;
+ break;
+
+ case VIR_NETWORK_FORWARD_BRIDGE:
+ if (def->bridge) {
+ /* <forward type='bridge'/> <bridge name='xxx'/>
+ * is VIR_DOMAIN_NET_TYPE_BRIDGE
+ */
+ ret = VIR_DOMAIN_NET_TYPE_BRIDGE;
+ break;
+ }
- } else if ((def->forward.type == VIR_NETWORK_FORWARD_BRIDGE) ||
- (def->forward.type == VIR_NETWORK_FORWARD_PRIVATE) ||
- (def->forward.type == VIR_NETWORK_FORWARD_VEPA) ||
- (def->forward.type == VIR_NETWORK_FORWARD_PASSTHROUGH)) {
+ /* intentionally fall through to the direct case for
+ * VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined
+ */
+ ATTRIBUTE_FALLTHROUGH;
+ case VIR_NETWORK_FORWARD_PRIVATE:
+ case VIR_NETWORK_FORWARD_VEPA:
+ case VIR_NETWORK_FORWARD_PASSTHROUGH:
/* <forward type='bridge|private|vepa|passthrough'> are all
* VIR_DOMAIN_NET_TYPE_DIRECT.
*/
-
ret = VIR_DOMAIN_NET_TYPE_DIRECT;
-
+ break;
}
cleanup:
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 630a87f..bafc1d3 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1959,17 +1959,22 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
VIR_FREE(stp);
- if (def->mtu &&
- (def->forward.type != VIR_NETWORK_FORWARD_NONE &&
- def->forward.type != VIR_NETWORK_FORWARD_NAT &&
- def->forward.type != VIR_NETWORK_FORWARD_ROUTE &&
- def->forward.type != VIR_NETWORK_FORWARD_OPEN)) {
- virReportError(VIR_ERR_XML_ERROR,
- _("mtu size only allowed in open, route, nat, "
- "and isolated mode, not in %s (network '%s')"),
- virNetworkForwardTypeToString(def->forward.type),
- def->name);
- goto error;
+ if (def->mtu) {
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
+ break;
+
+ default:
+ virReportError(VIR_ERR_XML_ERROR,
+ _("mtu size only allowed in open, route, nat, "
+ "and isolated mode, not in %s (network '%s')"),
+ virNetworkForwardTypeToString(def->forward.type),
+ def->name);
+ goto error;
+ }
}
/* Extract custom metadata */
@@ -2349,6 +2354,7 @@ virNetworkDefFormatBuf(virBufferPtr buf,
char uuidstr[VIR_UUID_STRING_BUFLEN];
size_t i;
bool shortforward;
+ bool hasbridge = false;
virBufferAddLit(buf, "<network");
if (!(flags & VIR_NETWORK_XML_INACTIVE) && (def->connections > 0))
@@ -2469,22 +2475,21 @@ virNetworkDefFormatBuf(virBufferPtr buf,
virBufferAddLit(buf, "</forward>\n");
}
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
+ hasbridge = true;
+ break;
+ }
- if (def->forward.type == VIR_NETWORK_FORWARD_NONE ||
- def->forward.type == VIR_NETWORK_FORWARD_NAT ||
- def->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
- def->forward.type == VIR_NETWORK_FORWARD_OPEN ||
- def->bridge || def->macTableManager) {
-
+ if (hasbridge || def->bridge || def->macTableManager) {
virBufferAddLit(buf, "<bridge");
virBufferEscapeString(buf, " name='%s'", def->bridge);
- if (def->forward.type == VIR_NETWORK_FORWARD_NONE ||
- def->forward.type == VIR_NETWORK_FORWARD_NAT ||
- def->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
- def->forward.type == VIR_NETWORK_FORWARD_OPEN) {
+ if (hasbridge)
virBufferAsprintf(buf, " stp='%s' delay='%ld'",
def->stp ? "on" : "off", def->delay);
- }
if (def->macTableManager) {
virBufferAsprintf(buf, " macTableManager='%s'",
virNetworkBridgeMACTableManagerTypeToString(def->macTableManager));
diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c
index e00c8a7..7706817 100644
--- a/src/conf/virnetworkobj.c
+++ b/src/conf/virnetworkobj.c
@@ -1009,19 +1009,22 @@ virNetworkLoadConfig(virNetworkObjListPtr nets,
goto error;
}
- if (def->forward.type == VIR_NETWORK_FORWARD_NONE ||
- def->forward.type == VIR_NETWORK_FORWARD_NAT ||
- def->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
- def->forward.type == VIR_NETWORK_FORWARD_OPEN) {
-
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
if (!def->mac_specified) {
virNetworkSetBridgeMacAddr(def);
virNetworkSaveConfig(configDir, def);
}
- } else {
+ break;
+
+ default:
/* Throw away MAC address for other forward types,
* which could have been generated by older libvirt RPMs */
def->mac_specified = false;
+ break;
}
if (!(obj = virNetworkObjAssignDef(nets, def, 0)))
diff --git a/src/esx/esx_network_driver.c b/src/esx/esx_network_driver.c
index 04118b4..8ea1079 100644
--- a/src/esx/esx_network_driver.c
+++ b/src/esx/esx_network_driver.c
@@ -326,8 +326,12 @@ esxNetworkDefineXML(virConnectPtr conn, const char *xml)
}
/* FIXME: Add support for NAT */
- if (def->forward.type != VIR_NETWORK_FORWARD_NONE &&
- def->forward.type != VIR_NETWORK_FORWARD_BRIDGE) {
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_BRIDGE:
+ break;
+
+ default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unsupported forward mode '%s'"),
virNetworkForwardTypeToString(def->forward.type));
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index da3c32e..5e885b5 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2088,19 +2088,22 @@ networkRefreshDaemonsHelper(virNetworkObjPtr obj,
virObjectLock(obj);
def = virNetworkObjGetDef(obj);
- if (virNetworkObjIsActive(obj) &&
- ((def->forward.type == VIR_NETWORK_FORWARD_NONE) ||
- (def->forward.type == VIR_NETWORK_FORWARD_NAT) ||
- (def->forward.type == VIR_NETWORK_FORWARD_ROUTE) ||
- (def->forward.type == VIR_NETWORK_FORWARD_OPEN))) {
- /* Only the three L3 network types that are configured by
- * libvirt will have a dnsmasq or radvd daemon associated
- * with them. Here we send a SIGHUP to an existing
- * dnsmasq and/or radvd, or restart them if they've
- * disappeared.
- */
- networkRefreshDhcpDaemon(driver, obj);
- networkRefreshRadvd(driver, obj);
+ if (virNetworkObjIsActive(obj)) {
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
+ /* Only the three L3 network types that are configured by
+ * libvirt will have a dnsmasq or radvd daemon associated
+ * with them. Here we send a SIGHUP to an existing
+ * dnsmasq and/or radvd, or restart them if they've
+ * disappeared.
+ */
+ networkRefreshDhcpDaemon(driver, obj);
+ networkRefreshRadvd(driver, obj);
+ break;
+ }
}
virObjectUnlock(obj);
return 0;
@@ -2128,18 +2131,21 @@ networkReloadFirewallRulesHelper(virNetworkObjPtr obj,
virObjectLock(obj);
def = virNetworkObjGetDef(obj);
- if (virNetworkObjIsActive(obj) &&
- ((def->forward.type == VIR_NETWORK_FORWARD_NONE) ||
- (def->forward.type == VIR_NETWORK_FORWARD_NAT) ||
- (def->forward.type == VIR_NETWORK_FORWARD_ROUTE))) {
- /* Only three of the L3 network types that are configured by
- * libvirt need to have iptables rules reloaded. The 4th L3
- * network type, forward='open', doesn't need this because it
- * has no iptables rules.
- */
- networkRemoveFirewallRules(def);
- if (networkAddFirewallRules(def) < 0) {
- /* failed to add but already logged */
+ if (virNetworkObjIsActive(obj)) {
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ /* Only three of the L3 network types that are configured by
+ * libvirt need to have iptables rules reloaded. The 4th L3
+ * network type, forward='open', doesn't need this because it
+ * has no iptables rules.
+ */
+ networkRemoveFirewallRules(def);
+ if (networkAddFirewallRules(def) < 0) {
+ /* failed to add but already logged */
+ }
+ break;
}
}
virObjectUnlock(obj);
@@ -3273,11 +3279,11 @@ networkValidate(virNetworkDriverStatePtr driver,
/* Only the three L3 network types that are configured by libvirt
* need to have a bridge device name / mac address provided
*/
- if (def->forward.type == VIR_NETWORK_FORWARD_NONE ||
- def->forward.type == VIR_NETWORK_FORWARD_NAT ||
- def->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
- def->forward.type == VIR_NETWORK_FORWARD_OPEN) {
-
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
/* if no bridge name was given in the config, find a name
* unused by any other libvirt networks and assign it.
*/
@@ -3285,7 +3291,9 @@ networkValidate(virNetworkDriverStatePtr driver,
return -1;
virNetworkSetBridgeMacAddr(def);
- } else {
+ break;
+
+ default:
/* They are also the only types that currently support setting
* a MAC or IP address for the host-side device (bridge), DNS
* configuration, or network-wide bandwidth limits.
@@ -3331,6 +3339,7 @@ networkValidate(virNetworkDriverStatePtr driver,
return -1;
}
bandwidthAllowed = false;
+ break;
}
/* we support configs with a single PF defined:
@@ -3755,9 +3764,10 @@ networkUpdate(virNetworkPtr net,
/* Take care of anything that must be done before updating the
* live NetworkDef.
*/
- if (def->forward.type == VIR_NETWORK_FORWARD_NONE ||
- def->forward.type == VIR_NETWORK_FORWARD_NAT ||
- def->forward.type == VIR_NETWORK_FORWARD_ROUTE) {
+ switch (def->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
switch (section) {
case VIR_NETWORK_SECTION_FORWARD:
case VIR_NETWORK_SECTION_FORWARD_INTERFACE:
@@ -3768,14 +3778,13 @@ networkUpdate(virNetworkPtr net,
* old rules (and remember to load new ones after the
* update).
*/
- if (def->forward.type != VIR_NETWORK_FORWARD_OPEN) {
- networkRemoveFirewallRules(def);
- needFirewallRefresh = true;
- }
+ networkRemoveFirewallRules(def);
+ needFirewallRefresh = true;
break;
default:
break;
}
+ break;
}
}
@@ -4440,10 +4449,11 @@ networkAllocateActualDevice(virDomainDefPtr dom,
iface->data.network.actual->trustGuestRxFilters
= netdef->trustGuestRxFilters;
- if ((netdef->forward.type == VIR_NETWORK_FORWARD_NONE) ||
- (netdef->forward.type == VIR_NETWORK_FORWARD_NAT) ||
- (netdef->forward.type == VIR_NETWORK_FORWARD_ROUTE) ||
- (netdef->forward.type == VIR_NETWORK_FORWARD_OPEN)) {
+ switch (netdef->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
/* for these forward types, the actual net type really *is*
* NETWORK; we just keep the info from the portgroup in
* iface->data.network.actual
@@ -4463,46 +4473,9 @@ networkAllocateActualDevice(virDomainDefPtr dom,
if (networkPlugBandwidth(obj, iface) < 0)
goto error;
+ break;
- } else if ((netdef->forward.type == VIR_NETWORK_FORWARD_BRIDGE) &&
- netdef->bridge) {
-
- /* <forward type='bridge'/> <bridge name='xxx'/>
- * is VIR_DOMAIN_NET_TYPE_BRIDGE
- */
-
- iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_BRIDGE;
- if (VIR_STRDUP(iface->data.network.actual->data.bridge.brname,
- netdef->bridge) < 0)
- goto error;
- iface->data.network.actual->data.bridge.macTableManager
- = netdef->macTableManager;
-
- /* merge virtualports from interface, network, and portgroup to
- * arrive at actual virtualport to use
- */
- if (virNetDevVPortProfileMerge3(&iface->data.network.actual->virtPortProfile,
- iface->virtPortProfile,
- netdef->virtPortProfile,
- portgroup
- ? portgroup->virtPortProfile : NULL) < 0) {
- goto error;
- }
- virtport = iface->data.network.actual->virtPortProfile;
- if (virtport) {
- /* only type='openvswitch' is allowed for bridges */
- if (virtport->virtPortType != VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("<virtualport type='%s'> not supported for network "
- "'%s' which uses a bridge device"),
- virNetDevVPortTypeToString(virtport->virtPortType),
- netdef->name);
- goto error;
- }
- }
-
- } else if (netdef->forward.type == VIR_NETWORK_FORWARD_HOSTDEV) {
-
+ case VIR_NETWORK_FORWARD_HOSTDEV: {
virDomainHostdevSubsysPCIBackendType backend;
iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_HOSTDEV;
@@ -4575,12 +4548,55 @@ networkAllocateActualDevice(virDomainDefPtr dom,
goto error;
}
}
+ break;
+ }
+
+ case VIR_NETWORK_FORWARD_BRIDGE:
+ if (netdef->bridge) {
+ /* <forward type='bridge'/> <bridge name='xxx'/>
+ * is VIR_DOMAIN_NET_TYPE_BRIDGE
+ */
+
+ iface->data.network.actual->type = actualType = VIR_DOMAIN_NET_TYPE_BRIDGE;
+ if (VIR_STRDUP(iface->data.network.actual->data.bridge.brname,
+ netdef->bridge) < 0)
+ goto error;
+ iface->data.network.actual->data.bridge.macTableManager
+ = netdef->macTableManager;
+
+ /* merge virtualports from interface, network, and portgroup to
+ * arrive at actual virtualport to use
+ */
+ if (virNetDevVPortProfileMerge3(&iface->data.network.actual->virtPortProfile,
+ iface->virtPortProfile,
+ netdef->virtPortProfile,
+ portgroup
+ ? portgroup->virtPortProfile : NULL) < 0) {
+ goto error;
+ }
+ virtport = iface->data.network.actual->virtPortProfile;
+ if (virtport) {
+ /* only type='openvswitch' is allowed for bridges */
+ if (virtport->virtPortType != VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("<virtualport type='%s'> not supported for network "
+ "'%s' which uses a bridge device"),
+ virNetDevVPortTypeToString(virtport->virtPortType),
+ netdef->name);
+ goto error;
+ }
+ }
+ break;
+ }
- } else if ((netdef->forward.type == VIR_NETWORK_FORWARD_BRIDGE) ||
- (netdef->forward.type == VIR_NETWORK_FORWARD_PRIVATE) ||
- (netdef->forward.type == VIR_NETWORK_FORWARD_VEPA) ||
- (netdef->forward.type == VIR_NETWORK_FORWARD_PASSTHROUGH)) {
+ /* intentionally fall through to the direct case for
+ * VIR_NETWORK_FORWARD_BRIDGE with no bridge device defined
+ */
+ ATTRIBUTE_FALLTHROUGH;
+ case VIR_NETWORK_FORWARD_PRIVATE:
+ case VIR_NETWORK_FORWARD_VEPA:
+ case VIR_NETWORK_FORWARD_PASSTHROUGH:
/* <forward type='bridge|private|vepa|passthrough'> are all
* VIR_DOMAIN_NET_TYPE_DIRECT.
*/
@@ -4680,6 +4696,7 @@ networkAllocateActualDevice(virDomainDefPtr dom,
dev->device.dev) < 0)
goto error;
}
+ break;
}
if (virNetworkObjMacMgrAdd(obj, driver->dnsmasqStateDir,
@@ -5037,13 +5054,15 @@ networkReleaseActualDevice(virDomainDefPtr dom,
}
netdef = virNetworkObjGetDef(obj);
- if (iface->data.network.actual &&
- (netdef->forward.type == VIR_NETWORK_FORWARD_NONE ||
- netdef->forward.type == VIR_NETWORK_FORWARD_NAT ||
- netdef->forward.type == VIR_NETWORK_FORWARD_ROUTE ||
- netdef->forward.type == VIR_NETWORK_FORWARD_OPEN) &&
- networkUnplugBandwidth(obj, iface) < 0)
- goto error;
+ switch (netdef->forward.type) {
+ case VIR_NETWORK_FORWARD_NONE:
+ case VIR_NETWORK_FORWARD_NAT:
+ case VIR_NETWORK_FORWARD_ROUTE:
+ case VIR_NETWORK_FORWARD_OPEN:
+ if (iface->data.network.actual && networkUnplugBandwidth(obj, iface) < 0)
+ goto error;
+ break;
+ }
if ((!iface->data.network.actual) ||
((actualType != VIR_DOMAIN_NET_TYPE_DIRECT) &&
--
2.7.4
6 years, 5 months
[libvirt] [PATCH] tools: Fix typo generating adapter_wwpn field
by John Ferlan
https://bugzilla.redhat.com/show_bug.cgi?id=1601377
Fix typo from commit id d45bee449 for the parent_wwpn field
resulting in parent_wwnn being printed twice.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
tools/virsh-pool.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index cc49a5b96d..6faff781b2 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -371,7 +371,7 @@ virshBuildPoolXML(vshControl *ctl,
if (adapterParent)
virBufferAsprintf(&buf, " parent='%s'", adapterParent);
else if (adapterParentWwnn && adapterParentWwpn)
- virBufferAsprintf(&buf, " parent_wwnn='%s' parent_wwnn='%s'",
+ virBufferAsprintf(&buf, " parent_wwnn='%s' parent_wwpn='%s'",
adapterParentWwnn, adapterParentWwpn);
else if (adapterParentFabricWwn)
virBufferAsprintf(&buf, " parent_fabric_wwn='%s'",
--
2.17.1
6 years, 5 months
[libvirt] [PATCH v2] util: set OOM in virCopyLastError if error is not set
by Nikolay Shirokovskiy
virCopyLastError is intended to be used after last error is set.
However due to virLastErrorObject failures (very unlikely through
as thread local error is allocated on first use) we can have zero
fields in a copy as a result. In particular code field can be set
to VIR_ERR_OK.
In some places (qemu monitor, qemu agent and qemu migaration code
for example) we use copy result as a flag and this leads to bugs.
Let's set OOM-like error in copy in case of virLastErrorObject failures.
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy(a)virtuozzo.com>
---
Changes from v1:
- check @to
- set OMM error instead of using virErrorGenericFailure
src/util/virerror.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/util/virerror.c b/src/util/virerror.c
index f198f27..737ea92 100644
--- a/src/util/virerror.c
+++ b/src/util/virerror.c
@@ -366,19 +366,25 @@ virSetError(virErrorPtr newerr)
*
* One will need to free the result with virResetError()
*
- * Returns 0 if no error was found and the error code otherwise and -1 in case
- * of parameter error.
+ * Returns error code or -1 in case of parameter error.
*/
int
virCopyLastError(virErrorPtr to)
{
virErrorPtr err = virLastErrorObject();
+
+ if (!to)
+ return -1;
+
/* We can't guarantee caller has initialized it to zero */
memset(to, 0, sizeof(*to));
- if (err)
+ if (err) {
virCopyError(err, to);
- else
- virResetError(to);
+ } else {
+ to->code = VIR_ERR_NO_MEMORY;
+ to->domain = VIR_FROM_NONE;
+ to->level = VIR_ERR_ERROR;
+ }
return to->code;
}
--
1.8.3.1
6 years, 5 months