mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-12 13:17:58 +03:00
qemu: always use virDomainNetGetActualBridgeName to get interface's bridge
qemuNetworkIfaceConnect() used to have a special case for actualType='network' (a network with forward mode of route, nat, or isolated) to call the libvirt public API to retrieve the bridge being used by a network. That is no longer necessary - since all network types that use a bridge and tap device now get the bridge name stored in the ActualNetDef, we can just always use virDomainNetGetActualBridgeName() instead. (an audit of the two callers to qemuNetworkIfaceConnect() confirms that it is never called for any other type of network, so the dead code in the else statement (logging an internal error if it is called for any other type of network) is eliminated in the process.)
This commit is contained in:
parent
7cb822c2a5
commit
4aae2ed6fb
@ -277,6 +277,11 @@ static int qemuCreateInBridgePortWithHelper(virQEMUDriverConfigPtr cfg,
|
|||||||
return *tapfd < 0 ? -1 : 0;
|
return *tapfd < 0 ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* qemuNetworkIfaceConnect - *only* called if actualType is
|
||||||
|
* VIR_DOMAIN_NET_TYPE_NETWORK or VIR_DOMAIN_NET_TYPE_BRIDGE (i.e. if
|
||||||
|
* the connection is made with a tap device connecting to a bridge
|
||||||
|
* device)
|
||||||
|
*/
|
||||||
int
|
int
|
||||||
qemuNetworkIfaceConnect(virDomainDefPtr def,
|
qemuNetworkIfaceConnect(virDomainDefPtr def,
|
||||||
virConnectPtr conn,
|
virConnectPtr conn,
|
||||||
@ -286,39 +291,19 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
|
|||||||
int *tapfd,
|
int *tapfd,
|
||||||
int *tapfdSize)
|
int *tapfdSize)
|
||||||
{
|
{
|
||||||
char *brname = NULL;
|
const char *brname;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
unsigned int tap_create_flags = VIR_NETDEV_TAP_CREATE_IFUP;
|
unsigned int tap_create_flags = VIR_NETDEV_TAP_CREATE_IFUP;
|
||||||
bool template_ifname = false;
|
bool template_ifname = false;
|
||||||
int actualType = virDomainNetGetActualType(net);
|
|
||||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||||
const char *tunpath = "/dev/net/tun";
|
const char *tunpath = "/dev/net/tun";
|
||||||
|
|
||||||
if (net->backend.tap)
|
if (net->backend.tap)
|
||||||
tunpath = net->backend.tap;
|
tunpath = net->backend.tap;
|
||||||
|
|
||||||
if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
if (!(brname = virDomainNetGetActualBridgeName(net))) {
|
||||||
bool fail = false;
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing bridge name"));
|
||||||
virNetworkPtr network = virNetworkLookupByName(conn,
|
goto cleanup;
|
||||||
net->data.network.name);
|
|
||||||
if (!network)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (!(brname = virNetworkGetBridgeName(network)))
|
|
||||||
fail = true;
|
|
||||||
|
|
||||||
virObjectUnref(network);
|
|
||||||
if (fail)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
} else if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
|
||||||
if (VIR_STRDUP(brname, virDomainNetGetActualBridgeName(net)) < 0)
|
|
||||||
return ret;
|
|
||||||
} else {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Network type %d is not supported"),
|
|
||||||
virDomainNetGetActualType(net));
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!net->ifname ||
|
if (!net->ifname ||
|
||||||
@ -400,7 +385,6 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
|
|||||||
if (template_ifname)
|
if (template_ifname)
|
||||||
VIR_FREE(net->ifname);
|
VIR_FREE(net->ifname);
|
||||||
}
|
}
|
||||||
VIR_FREE(brname);
|
|
||||||
virObjectUnref(cfg);
|
virObjectUnref(cfg);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1746,58 +1746,20 @@ static virDomainNetDefPtr *qemuDomainFindNet(virDomainObjPtr vm,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
|
||||||
qemuDomainNetGetBridgeName(virConnectPtr conn, virDomainNetDefPtr net)
|
|
||||||
{
|
|
||||||
char *brname = NULL;
|
|
||||||
int actualType = virDomainNetGetActualType(net);
|
|
||||||
|
|
||||||
if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
|
||||||
const char *tmpbr = virDomainNetGetActualBridgeName(net);
|
|
||||||
if (!tmpbr) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("interface is missing bridge name"));
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
/* we need a copy, not just a pointer to the original */
|
|
||||||
if (VIR_STRDUP(brname, tmpbr) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
} else if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
|
||||||
virNetworkPtr network;
|
|
||||||
|
|
||||||
if (!(network = virNetworkLookupByName(conn, net->data.network.name))) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Couldn't find network '%s'"),
|
|
||||||
net->data.network.name);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
brname = virNetworkGetBridgeName(network);
|
|
||||||
|
|
||||||
virObjectUnref(network);
|
|
||||||
} else {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("Interface type %d has no bridge name"),
|
|
||||||
virDomainNetGetActualType(net));
|
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
|
||||||
return brname;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainChangeNetBridge(virConnectPtr conn,
|
qemuDomainChangeNetBridge(virDomainObjPtr vm,
|
||||||
virDomainObjPtr vm,
|
|
||||||
virDomainNetDefPtr olddev,
|
virDomainNetDefPtr olddev,
|
||||||
virDomainNetDefPtr newdev)
|
virDomainNetDefPtr newdev)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
char *oldbridge = NULL, *newbridge = NULL;
|
const char *oldbridge = virDomainNetGetActualBridgeName(olddev);
|
||||||
|
const char *newbridge = virDomainNetGetActualBridgeName(newdev);
|
||||||
|
|
||||||
if (!(oldbridge = qemuDomainNetGetBridgeName(conn, olddev)))
|
if (!oldbridge || !newbridge) {
|
||||||
goto cleanup;
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing bridge name"));
|
||||||
|
|
||||||
if (!(newbridge = qemuDomainNetGetBridgeName(conn, newdev)))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
VIR_DEBUG("Change bridge for interface %s: %s -> %s",
|
VIR_DEBUG("Change bridge for interface %s: %s -> %s",
|
||||||
olddev->ifname, oldbridge, newbridge);
|
olddev->ifname, oldbridge, newbridge);
|
||||||
@ -1836,8 +1798,6 @@ qemuDomainChangeNetBridge(virConnectPtr conn,
|
|||||||
/* caller will replace entire olddev with newdev in domain nets list */
|
/* caller will replace entire olddev with newdev in domain nets list */
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(oldbridge);
|
|
||||||
VIR_FREE(newbridge);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2231,7 +2191,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (needBridgeChange) {
|
if (needBridgeChange) {
|
||||||
if (qemuDomainChangeNetBridge(dom->conn, vm, olddev, newdev) < 0)
|
if (qemuDomainChangeNetBridge(vm, olddev, newdev) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
/* we successfully switched to the new bridge, and we've
|
/* we successfully switched to the new bridge, and we've
|
||||||
* determined that the rest of newdev is equivalent to olddev,
|
* determined that the rest of newdev is equivalent to olddev,
|
||||||
|
Loading…
Reference in New Issue
Block a user