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, it's
assumed that the virDomainActualNetDef is already properly initialized
(it isn't yet).
---
src/qemu/qemu_command.c | 44 ++++++++++++++++++++++++++------------------
src/qemu/qemu_driver.c | 30 ++++++++++++++++++++++++++++--
src/qemu/qemu_hotplug.c | 16 +++++++++-------
src/qemu/qemu_migration.c | 12 ++++++------
src/qemu/qemu_process.c | 10 ++++++----
5 files changed, 75 insertions(+), 37 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index bd47eae..d1ecaf4 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -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) {
qemuAuditNetDevice(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,
@@ -3658,6 +3664,7 @@ qemuBuildCommandLine(virConnectPtr conn,
char vhostfd_name[50] = "";
int vlan;
int bootindex = bootNet;
+ int actualType;
bootNet = 0;
if (!bootindex)
@@ -3670,8 +3677,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)
@@ -3683,7 +3691,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)
@@ -3697,9 +3705,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;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8105910..e552cff 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3935,9 +3935,35 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
for (i = 0 ; i < def->nnets ; i++) {
virDomainNetDefPtr net = def->nets[i];
int bootIndex = net->bootIndex;
- if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK ||
- net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
+ if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
+ int actualType = virDomainNetGetActualType(net);
VIR_FREE(net->data.network.name);
+ VIR_FREE(net->data.network.portgroup);
+ if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
+ char *brname = strdup(virDomainNetGetActualBridgeName(net));
+ virDomainActualNetDefFree(net->data.network.actual);
+
+ memset(net, 0, sizeof *net);
+
+ net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
+ net->data.ethernet.dev = brname;
+ net->data.ethernet.script = NULL;
+ net->data.ethernet.ipaddr = NULL;
+ } else {
+ /* actualType is either NETWORK or DIRECT. In either
+ * case, the best we can do is NULL everything out.
+ */
+ virDomainActualNetDefFree(net->data.network.actual);
+ memset(net, 0, sizeof *net);
+
+ net->type = VIR_DOMAIN_NET_TYPE_ETHERNET;
+ net->data.ethernet.dev = NULL;
+ net->data.ethernet.script = NULL;
+ net->data.ethernet.ipaddr = NULL;
+ }
+ } else if (net->type == VIR_DOMAIN_NET_TYPE_DIRECT) {
+ VIR_FREE(net->data.direct.linkdev);
+ VIR_FREE(net->data.direct.virtPortProfile);
memset(net, 0, sizeof *net);
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 5049f6e..a5fcdc9 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -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)
@@ -1608,10 +1609,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);
}
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 9622021..5d3ae32 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2394,11 +2394,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;
@@ -2411,11 +2411,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);
}
}
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index fa7face..9fec746 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2902,10 +2902,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);
}
}
--
1.7.3.4