mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 19:32:19 +00:00
qemu: use virDomainNetGetActual*() functions where appropriate
The qemu driver accesses fields in the virDomainNetDef directly, but with the advent of the virDomainActualNetDef, some pieces of information may be found in a different place (the ActualNetDef) if the network connection is of type='network' and that network is of forward type='bridge|private|vepa|passthrough'. The previous patch added functions to mask this difference from callers - they hide the decision making process and just pick the value from the proper place. This patch uses those functions in the qemu driver as a first step in making qemu work with the new network types. At this point, the virDomainActualNetDef is guaranteed always NULL, so the GetActualX() function will return exactly what the def->X that's being replaced would have returned (ie bisecting is not compromised). There is one place (in qemu_driver.c) where the internal details of the NetDef are directly manipulated by the code, so the GetActual functions cannot be used there without extra additional code; that file will be treated in a separate patch.
This commit is contained in:
parent
b48e81bf94
commit
03caa988a6
@ -125,9 +125,12 @@ qemuPhysIfaceConnect(virDomainDefPtr def,
|
||||
net->model && STREQ(net->model, "virtio"))
|
||||
vnet_hdr = 1;
|
||||
|
||||
rc = openMacvtapTap(net->ifname, net->mac, net->data.direct.linkdev,
|
||||
net->data.direct.mode, vnet_hdr, def->uuid,
|
||||
net->data.direct.virtPortProfile, &res_ifname,
|
||||
rc = openMacvtapTap(net->ifname, net->mac,
|
||||
virDomainNetGetActualDirectDev(net),
|
||||
virDomainNetGetActualDirectMode(net),
|
||||
vnet_hdr, def->uuid,
|
||||
virDomainNetGetActualDirectVirtPortProfile(net),
|
||||
&res_ifname,
|
||||
vmop, driver->stateDir);
|
||||
if (rc >= 0) {
|
||||
virDomainAuditNetDevice(def, net, res_ifname, true);
|
||||
@ -148,9 +151,10 @@ qemuPhysIfaceConnect(virDomainDefPtr def,
|
||||
err = virDomainConfNWFilterInstantiate(conn, net);
|
||||
if (err) {
|
||||
VIR_FORCE_CLOSE(rc);
|
||||
delMacvtap(net->ifname, net->mac, net->data.direct.linkdev,
|
||||
net->data.direct.mode,
|
||||
net->data.direct.virtPortProfile,
|
||||
delMacvtap(net->ifname, net->mac,
|
||||
virDomainNetGetActualDirectDev(net),
|
||||
virDomainNetGetActualDirectMode(net),
|
||||
virDomainNetGetActualDirectVirtPortProfile(net),
|
||||
driver->stateDir);
|
||||
VIR_FREE(net->ifname);
|
||||
}
|
||||
@ -184,8 +188,9 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
|
||||
int vnet_hdr = 0;
|
||||
int template_ifname = 0;
|
||||
unsigned char tapmac[VIR_MAC_BUFLEN];
|
||||
int actualType = virDomainNetGetActualType(net);
|
||||
|
||||
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
||||
if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
||||
int active, fail = 0;
|
||||
virErrorPtr errobj;
|
||||
virNetworkPtr network = virNetworkLookupByName(conn,
|
||||
@ -218,14 +223,15 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
|
||||
if (fail)
|
||||
return -1;
|
||||
|
||||
} else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
||||
if (!(brname = strdup(net->data.bridge.brname))) {
|
||||
} else if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
||||
if (!(brname = strdup(virDomainNetGetActualBridgeName(net)))) {
|
||||
virReportOOMError();
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Network type %d is not supported"), net->type);
|
||||
_("Network type %d is not supported"),
|
||||
virDomainNetGetActualType(net));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -1829,7 +1835,7 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
|
||||
bool is_tap = false;
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
|
||||
switch (net->type) {
|
||||
switch (virDomainNetGetActualType(net)) {
|
||||
case VIR_DOMAIN_NET_TYPE_NETWORK:
|
||||
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
||||
case VIR_DOMAIN_NET_TYPE_DIRECT:
|
||||
@ -1857,7 +1863,7 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
|
||||
case VIR_DOMAIN_NET_TYPE_SERVER:
|
||||
case VIR_DOMAIN_NET_TYPE_MCAST:
|
||||
virBufferAddLit(&buf, "socket");
|
||||
switch (net->type) {
|
||||
switch (virDomainNetGetActualType(net)) {
|
||||
case VIR_DOMAIN_NET_TYPE_CLIENT:
|
||||
virBufferAsprintf(&buf, "%cconnect=%s:%d",
|
||||
type_sep,
|
||||
@ -3678,6 +3684,7 @@ qemuBuildCommandLine(virConnectPtr conn,
|
||||
char vhostfd_name[50] = "";
|
||||
int vlan;
|
||||
int bootindex = bootNet;
|
||||
int actualType;
|
||||
|
||||
bootNet = 0;
|
||||
if (!bootindex)
|
||||
@ -3690,8 +3697,9 @@ qemuBuildCommandLine(virConnectPtr conn,
|
||||
else
|
||||
vlan = i;
|
||||
|
||||
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK ||
|
||||
net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
||||
actualType = virDomainNetGetActualType(net);
|
||||
if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
|
||||
actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
||||
int tapfd = qemuNetworkIfaceConnect(def, conn, driver, net,
|
||||
qemuCaps);
|
||||
if (tapfd < 0)
|
||||
@ -3703,7 +3711,7 @@ qemuBuildCommandLine(virConnectPtr conn,
|
||||
if (snprintf(tapfd_name, sizeof(tapfd_name), "%d",
|
||||
tapfd) >= sizeof(tapfd_name))
|
||||
goto no_memory;
|
||||
} else if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
} else if (actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
int tapfd = qemuPhysIfaceConnect(def, conn, driver, net,
|
||||
qemuCaps, vmop);
|
||||
if (tapfd < 0)
|
||||
@ -3717,9 +3725,9 @@ qemuBuildCommandLine(virConnectPtr conn,
|
||||
goto no_memory;
|
||||
}
|
||||
|
||||
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK ||
|
||||
net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
||||
net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
|
||||
actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
||||
actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
/* Attempt to use vhost-net mode for these types of
|
||||
network device */
|
||||
int vhostfd;
|
||||
|
@ -603,6 +603,7 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
|
||||
virDomainDevicePCIAddress guestAddr;
|
||||
int vlan;
|
||||
bool releaseaddr = false;
|
||||
int actualType = virDomainNetGetActualType(net);
|
||||
|
||||
if (!qemuCapsGet(priv->qemuCaps, QEMU_CAPS_HOST_NET_ADD)) {
|
||||
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||
@ -610,14 +611,14 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
||||
net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
||||
if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
||||
actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
||||
if ((tapfd = qemuNetworkIfaceConnect(vm->def, conn, driver, net,
|
||||
priv->qemuCaps)) < 0)
|
||||
return -1;
|
||||
if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, &vhostfd) < 0)
|
||||
goto cleanup;
|
||||
} else if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
} else if (actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
if ((tapfd = qemuPhysIfaceConnect(vm->def, conn, driver, net,
|
||||
priv->qemuCaps,
|
||||
VIR_VM_OP_CREATE)) < 0)
|
||||
@ -1613,10 +1614,11 @@ int qemuDomainDetachNetDevice(struct qemud_driver *driver,
|
||||
virDomainConfNWFilterTeardown(detach);
|
||||
|
||||
#if WITH_MACVTAP
|
||||
if (detach->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
delMacvtap(detach->ifname, detach->mac, detach->data.direct.linkdev,
|
||||
detach->data.direct.mode,
|
||||
detach->data.direct.virtPortProfile,
|
||||
if (virDomainNetGetActualType(detach) == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
delMacvtap(detach->ifname, detach->mac,
|
||||
virDomainNetGetActualDirectDev(detach),
|
||||
virDomainNetGetActualDirectMode(detach),
|
||||
virDomainNetGetActualDirectVirtPortProfile(detach),
|
||||
driver->stateDir);
|
||||
VIR_FREE(detach->ifname);
|
||||
}
|
||||
|
@ -2343,11 +2343,11 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def) {
|
||||
|
||||
for (i = 0; i < def->nnets; i++) {
|
||||
net = def->nets[i];
|
||||
if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
if (vpAssociatePortProfileId(net->ifname,
|
||||
net->mac,
|
||||
net->data.direct.linkdev,
|
||||
net->data.direct.virtPortProfile,
|
||||
virDomainNetGetActualDirectDev(net),
|
||||
virDomainNetGetActualDirectVirtPortProfile(net),
|
||||
def->uuid,
|
||||
VIR_VM_OP_MIGRATE_IN_FINISH) != 0)
|
||||
goto err_exit;
|
||||
@ -2360,11 +2360,11 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def) {
|
||||
err_exit:
|
||||
for (i = 0; i < last_good_net; i++) {
|
||||
net = def->nets[i];
|
||||
if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
vpDisassociatePortProfileId(net->ifname,
|
||||
net->mac,
|
||||
net->data.direct.linkdev,
|
||||
net->data.direct.virtPortProfile,
|
||||
virDomainNetGetActualDirectDev(net),
|
||||
virDomainNetGetActualDirectVirtPortProfile(net),
|
||||
VIR_VM_OP_MIGRATE_IN_FINISH);
|
||||
}
|
||||
}
|
||||
|
@ -3018,10 +3018,12 @@ void qemuProcessStop(struct qemud_driver *driver,
|
||||
def = vm->def;
|
||||
for (i = 0; i < def->nnets; i++) {
|
||||
virDomainNetDefPtr net = def->nets[i];
|
||||
if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
delMacvtap(net->ifname, net->mac, net->data.direct.linkdev,
|
||||
net->data.direct.mode,
|
||||
net->data.direct.virtPortProfile, driver->stateDir);
|
||||
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
delMacvtap(net->ifname, net->mac,
|
||||
virDomainNetGetActualDirectDev(net),
|
||||
virDomainNetGetActualDirectMode(net),
|
||||
virDomainNetGetActualDirectVirtPortProfile(net),
|
||||
driver->stateDir);
|
||||
VIR_FREE(net->ifname);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user