提交 4aae2ed6 编写于 作者: L Laine Stump

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.)
上级 7cb822c2
......@@ -277,6 +277,11 @@ static int qemuCreateInBridgePortWithHelper(virQEMUDriverConfigPtr cfg,
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
qemuNetworkIfaceConnect(virDomainDefPtr def,
virConnectPtr conn,
......@@ -286,39 +291,19 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
int *tapfd,
int *tapfdSize)
{
char *brname = NULL;
const char *brname;
int ret = -1;
unsigned int tap_create_flags = VIR_NETDEV_TAP_CREATE_IFUP;
bool template_ifname = false;
int actualType = virDomainNetGetActualType(net);
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
const char *tunpath = "/dev/net/tun";
if (net->backend.tap)
tunpath = net->backend.tap;
if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
bool fail = false;
virNetworkPtr network = virNetworkLookupByName(conn,
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 (!(brname = virDomainNetGetActualBridgeName(net))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing bridge name"));
goto cleanup;
}
if (!net->ifname ||
......@@ -400,7 +385,6 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
if (template_ifname)
VIR_FREE(net->ifname);
}
VIR_FREE(brname);
virObjectUnref(cfg);
return ret;
......
......@@ -1746,58 +1746,20 @@ static virDomainNetDefPtr *qemuDomainFindNet(virDomainObjPtr vm,
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
qemuDomainChangeNetBridge(virConnectPtr conn,
virDomainObjPtr vm,
qemuDomainChangeNetBridge(virDomainObjPtr vm,
virDomainNetDefPtr olddev,
virDomainNetDefPtr newdev)
{
int ret = -1;
char *oldbridge = NULL, *newbridge = NULL;
const char *oldbridge = virDomainNetGetActualBridgeName(olddev);
const char *newbridge = virDomainNetGetActualBridgeName(newdev);
if (!(oldbridge = qemuDomainNetGetBridgeName(conn, olddev)))
goto cleanup;
if (!(newbridge = qemuDomainNetGetBridgeName(conn, newdev)))
if (!oldbridge || !newbridge) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Missing bridge name"));
goto cleanup;
}
VIR_DEBUG("Change bridge for interface %s: %s -> %s",
olddev->ifname, oldbridge, newbridge);
......@@ -1836,8 +1798,6 @@ qemuDomainChangeNetBridge(virConnectPtr conn,
/* caller will replace entire olddev with newdev in domain nets list */
ret = 0;
cleanup:
VIR_FREE(oldbridge);
VIR_FREE(newbridge);
return ret;
}
......@@ -2231,7 +2191,7 @@ qemuDomainChangeNet(virQEMUDriverPtr driver,
}
if (needBridgeChange) {
if (qemuDomainChangeNetBridge(dom->conn, vm, olddev, newdev) < 0)
if (qemuDomainChangeNetBridge(vm, olddev, newdev) < 0)
goto cleanup;
/* we successfully switched to the new bridge, and we've
* determined that the rest of newdev is equivalent to olddev,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册