[PATCHv2 7/9] qemu: use virDomainNetGetActual*() functions where appropriate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 the
virDomainActualNetDef is 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 these GetActual
functions cannot be used without extra additional code; that file will
be treated in a separate patch.
---

Changes from V1: This and the next patch were previously a single
patch. I separated them so that this patch would be 100% replacement
of direct data access with calls to (currently NOP) helper functions.

Some comments on what's changed here:

  https://www.redhat.com/archives/libvir-list/2011-July/msg00568.html

(the most important change is in the wording of the commit log message
so that it is no longer misleading.)


 src/qemu/qemu_command.c   |   44 ++++++++++++++++++++++++++------------------
 src/qemu/qemu_hotplug.c   |   16 +++++++++-------
 src/qemu/qemu_migration.c |   12 ++++++------
 src/qemu/qemu_process.c   |   10 ++++++----
 4 files changed, 47 insertions(+), 35 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index f456e25..172e394 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) {
         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;
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 6c22f4c..128b9ea 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)
@@ -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);
     }
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index 84fe05a..721e031 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2337,11 +2337,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;
@@ -2354,11 +2354,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 5121241..3c57a2a 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3014,10 +3014,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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]