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"))
|
net->model && STREQ(net->model, "virtio"))
|
||||||
vnet_hdr = 1;
|
vnet_hdr = 1;
|
||||||
|
|
||||||
rc = openMacvtapTap(net->ifname, net->mac, net->data.direct.linkdev,
|
rc = openMacvtapTap(net->ifname, net->mac,
|
||||||
net->data.direct.mode, vnet_hdr, def->uuid,
|
virDomainNetGetActualDirectDev(net),
|
||||||
net->data.direct.virtPortProfile, &res_ifname,
|
virDomainNetGetActualDirectMode(net),
|
||||||
|
vnet_hdr, def->uuid,
|
||||||
|
virDomainNetGetActualDirectVirtPortProfile(net),
|
||||||
|
&res_ifname,
|
||||||
vmop, driver->stateDir);
|
vmop, driver->stateDir);
|
||||||
if (rc >= 0) {
|
if (rc >= 0) {
|
||||||
virDomainAuditNetDevice(def, net, res_ifname, true);
|
virDomainAuditNetDevice(def, net, res_ifname, true);
|
||||||
@ -148,9 +151,10 @@ qemuPhysIfaceConnect(virDomainDefPtr def,
|
|||||||
err = virDomainConfNWFilterInstantiate(conn, net);
|
err = virDomainConfNWFilterInstantiate(conn, net);
|
||||||
if (err) {
|
if (err) {
|
||||||
VIR_FORCE_CLOSE(rc);
|
VIR_FORCE_CLOSE(rc);
|
||||||
delMacvtap(net->ifname, net->mac, net->data.direct.linkdev,
|
delMacvtap(net->ifname, net->mac,
|
||||||
net->data.direct.mode,
|
virDomainNetGetActualDirectDev(net),
|
||||||
net->data.direct.virtPortProfile,
|
virDomainNetGetActualDirectMode(net),
|
||||||
|
virDomainNetGetActualDirectVirtPortProfile(net),
|
||||||
driver->stateDir);
|
driver->stateDir);
|
||||||
VIR_FREE(net->ifname);
|
VIR_FREE(net->ifname);
|
||||||
}
|
}
|
||||||
@ -184,8 +188,9 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
|
|||||||
int vnet_hdr = 0;
|
int vnet_hdr = 0;
|
||||||
int template_ifname = 0;
|
int template_ifname = 0;
|
||||||
unsigned char tapmac[VIR_MAC_BUFLEN];
|
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;
|
int active, fail = 0;
|
||||||
virErrorPtr errobj;
|
virErrorPtr errobj;
|
||||||
virNetworkPtr network = virNetworkLookupByName(conn,
|
virNetworkPtr network = virNetworkLookupByName(conn,
|
||||||
@ -218,14 +223,15 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
|
|||||||
if (fail)
|
if (fail)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
} else if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
} else if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
||||||
if (!(brname = strdup(net->data.bridge.brname))) {
|
if (!(brname = strdup(virDomainNetGetActualBridgeName(net)))) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
qemuReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("Network type %d is not supported"), net->type);
|
_("Network type %d is not supported"),
|
||||||
|
virDomainNetGetActualType(net));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1829,7 +1835,7 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
|
|||||||
bool is_tap = false;
|
bool is_tap = false;
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||||
|
|
||||||
switch (net->type) {
|
switch (virDomainNetGetActualType(net)) {
|
||||||
case VIR_DOMAIN_NET_TYPE_NETWORK:
|
case VIR_DOMAIN_NET_TYPE_NETWORK:
|
||||||
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
case VIR_DOMAIN_NET_TYPE_BRIDGE:
|
||||||
case VIR_DOMAIN_NET_TYPE_DIRECT:
|
case VIR_DOMAIN_NET_TYPE_DIRECT:
|
||||||
@ -1857,7 +1863,7 @@ qemuBuildHostNetStr(virDomainNetDefPtr net,
|
|||||||
case VIR_DOMAIN_NET_TYPE_SERVER:
|
case VIR_DOMAIN_NET_TYPE_SERVER:
|
||||||
case VIR_DOMAIN_NET_TYPE_MCAST:
|
case VIR_DOMAIN_NET_TYPE_MCAST:
|
||||||
virBufferAddLit(&buf, "socket");
|
virBufferAddLit(&buf, "socket");
|
||||||
switch (net->type) {
|
switch (virDomainNetGetActualType(net)) {
|
||||||
case VIR_DOMAIN_NET_TYPE_CLIENT:
|
case VIR_DOMAIN_NET_TYPE_CLIENT:
|
||||||
virBufferAsprintf(&buf, "%cconnect=%s:%d",
|
virBufferAsprintf(&buf, "%cconnect=%s:%d",
|
||||||
type_sep,
|
type_sep,
|
||||||
@ -3678,6 +3684,7 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||||||
char vhostfd_name[50] = "";
|
char vhostfd_name[50] = "";
|
||||||
int vlan;
|
int vlan;
|
||||||
int bootindex = bootNet;
|
int bootindex = bootNet;
|
||||||
|
int actualType;
|
||||||
|
|
||||||
bootNet = 0;
|
bootNet = 0;
|
||||||
if (!bootindex)
|
if (!bootindex)
|
||||||
@ -3690,8 +3697,9 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||||||
else
|
else
|
||||||
vlan = i;
|
vlan = i;
|
||||||
|
|
||||||
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK ||
|
actualType = virDomainNetGetActualType(net);
|
||||||
net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
|
||||||
|
actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
|
||||||
int tapfd = qemuNetworkIfaceConnect(def, conn, driver, net,
|
int tapfd = qemuNetworkIfaceConnect(def, conn, driver, net,
|
||||||
qemuCaps);
|
qemuCaps);
|
||||||
if (tapfd < 0)
|
if (tapfd < 0)
|
||||||
@ -3703,7 +3711,7 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||||||
if (snprintf(tapfd_name, sizeof(tapfd_name), "%d",
|
if (snprintf(tapfd_name, sizeof(tapfd_name), "%d",
|
||||||
tapfd) >= sizeof(tapfd_name))
|
tapfd) >= sizeof(tapfd_name))
|
||||||
goto no_memory;
|
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,
|
int tapfd = qemuPhysIfaceConnect(def, conn, driver, net,
|
||||||
qemuCaps, vmop);
|
qemuCaps, vmop);
|
||||||
if (tapfd < 0)
|
if (tapfd < 0)
|
||||||
@ -3717,9 +3725,9 @@ qemuBuildCommandLine(virConnectPtr conn,
|
|||||||
goto no_memory;
|
goto no_memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK ||
|
if (actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
|
||||||
net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
||||||
net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||||
/* Attempt to use vhost-net mode for these types of
|
/* Attempt to use vhost-net mode for these types of
|
||||||
network device */
|
network device */
|
||||||
int vhostfd;
|
int vhostfd;
|
||||||
|
@ -603,6 +603,7 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
|
|||||||
virDomainDevicePCIAddress guestAddr;
|
virDomainDevicePCIAddress guestAddr;
|
||||||
int vlan;
|
int vlan;
|
||||||
bool releaseaddr = false;
|
bool releaseaddr = false;
|
||||||
|
int actualType = virDomainNetGetActualType(net);
|
||||||
|
|
||||||
if (!qemuCapsGet(priv->qemuCaps, QEMU_CAPS_HOST_NET_ADD)) {
|
if (!qemuCapsGet(priv->qemuCaps, QEMU_CAPS_HOST_NET_ADD)) {
|
||||||
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
@ -610,14 +611,14 @@ int qemuDomainAttachNetDevice(virConnectPtr conn,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
||||||
net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
actualType == VIR_DOMAIN_NET_TYPE_NETWORK) {
|
||||||
if ((tapfd = qemuNetworkIfaceConnect(vm->def, conn, driver, net,
|
if ((tapfd = qemuNetworkIfaceConnect(vm->def, conn, driver, net,
|
||||||
priv->qemuCaps)) < 0)
|
priv->qemuCaps)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, &vhostfd) < 0)
|
if (qemuOpenVhostNet(vm->def, net, priv->qemuCaps, &vhostfd) < 0)
|
||||||
goto cleanup;
|
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,
|
if ((tapfd = qemuPhysIfaceConnect(vm->def, conn, driver, net,
|
||||||
priv->qemuCaps,
|
priv->qemuCaps,
|
||||||
VIR_VM_OP_CREATE)) < 0)
|
VIR_VM_OP_CREATE)) < 0)
|
||||||
@ -1613,10 +1614,11 @@ int qemuDomainDetachNetDevice(struct qemud_driver *driver,
|
|||||||
virDomainConfNWFilterTeardown(detach);
|
virDomainConfNWFilterTeardown(detach);
|
||||||
|
|
||||||
#if WITH_MACVTAP
|
#if WITH_MACVTAP
|
||||||
if (detach->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
if (virDomainNetGetActualType(detach) == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||||
delMacvtap(detach->ifname, detach->mac, detach->data.direct.linkdev,
|
delMacvtap(detach->ifname, detach->mac,
|
||||||
detach->data.direct.mode,
|
virDomainNetGetActualDirectDev(detach),
|
||||||
detach->data.direct.virtPortProfile,
|
virDomainNetGetActualDirectMode(detach),
|
||||||
|
virDomainNetGetActualDirectVirtPortProfile(detach),
|
||||||
driver->stateDir);
|
driver->stateDir);
|
||||||
VIR_FREE(detach->ifname);
|
VIR_FREE(detach->ifname);
|
||||||
}
|
}
|
||||||
|
@ -2343,11 +2343,11 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def) {
|
|||||||
|
|
||||||
for (i = 0; i < def->nnets; i++) {
|
for (i = 0; i < def->nnets; i++) {
|
||||||
net = def->nets[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,
|
if (vpAssociatePortProfileId(net->ifname,
|
||||||
net->mac,
|
net->mac,
|
||||||
net->data.direct.linkdev,
|
virDomainNetGetActualDirectDev(net),
|
||||||
net->data.direct.virtPortProfile,
|
virDomainNetGetActualDirectVirtPortProfile(net),
|
||||||
def->uuid,
|
def->uuid,
|
||||||
VIR_VM_OP_MIGRATE_IN_FINISH) != 0)
|
VIR_VM_OP_MIGRATE_IN_FINISH) != 0)
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
@ -2360,11 +2360,11 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def) {
|
|||||||
err_exit:
|
err_exit:
|
||||||
for (i = 0; i < last_good_net; i++) {
|
for (i = 0; i < last_good_net; i++) {
|
||||||
net = def->nets[i];
|
net = def->nets[i];
|
||||||
if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||||
vpDisassociatePortProfileId(net->ifname,
|
vpDisassociatePortProfileId(net->ifname,
|
||||||
net->mac,
|
net->mac,
|
||||||
net->data.direct.linkdev,
|
virDomainNetGetActualDirectDev(net),
|
||||||
net->data.direct.virtPortProfile,
|
virDomainNetGetActualDirectVirtPortProfile(net),
|
||||||
VIR_VM_OP_MIGRATE_IN_FINISH);
|
VIR_VM_OP_MIGRATE_IN_FINISH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3018,10 +3018,12 @@ void qemuProcessStop(struct qemud_driver *driver,
|
|||||||
def = vm->def;
|
def = vm->def;
|
||||||
for (i = 0; i < def->nnets; i++) {
|
for (i = 0; i < def->nnets; i++) {
|
||||||
virDomainNetDefPtr net = def->nets[i];
|
virDomainNetDefPtr net = def->nets[i];
|
||||||
if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||||
delMacvtap(net->ifname, net->mac, net->data.direct.linkdev,
|
delMacvtap(net->ifname, net->mac,
|
||||||
net->data.direct.mode,
|
virDomainNetGetActualDirectDev(net),
|
||||||
net->data.direct.virtPortProfile, driver->stateDir);
|
virDomainNetGetActualDirectMode(net),
|
||||||
|
virDomainNetGetActualDirectVirtPortProfile(net),
|
||||||
|
driver->stateDir);
|
||||||
VIR_FREE(net->ifname);
|
VIR_FREE(net->ifname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user