[PATCHv2 3/9] conf: virDomainNetDef points to (rather than contains) virtPortProfile

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

 



The virtPortProfile in the domain interface struct is now a separately
allocated object *pointed to by* (rather than contained in) the main
virDomainNetDef object. This is done to make it easier to figure out
when a virtualPortProfile has/hasn't been specified in a particular
config.
---
 src/conf/domain_conf.c    |   17 ++++++++---------
 src/conf/domain_conf.h    |    2 +-
 src/qemu/qemu_command.c   |    4 ++--
 src/qemu/qemu_hotplug.c   |    2 +-
 src/qemu/qemu_migration.c |    4 ++--
 src/qemu/qemu_process.c   |    2 +-
 src/util/network.c        |   15 ++++++++++++---
 src/util/network.h        |    2 +-
 8 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0af8860..24f9b00 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -770,6 +770,7 @@ void virDomainNetDefFree(virDomainNetDefPtr def)
 
     case VIR_DOMAIN_NET_TYPE_DIRECT:
         VIR_FREE(def->data.direct.linkdev);
+        VIR_FREE(def->data.direct.virtPortProfile);
         break;
 
     case VIR_DOMAIN_NET_TYPE_USER:
@@ -2617,8 +2618,7 @@ virDomainNetDefParseXML(virCapsPtr caps,
     char *devaddr = NULL;
     char *mode = NULL;
     virNWFilterHashTablePtr filterparams = NULL;
-    virVirtualPortProfileParams virtPort;
-    bool virtPortParsed = false;
+    virVirtualPortProfileParamsPtr virtPort = NULL;
     xmlNodePtr oldnode = ctxt->node;
     int ret;
 
@@ -2664,12 +2664,11 @@ virDomainNetDefParseXML(virCapsPtr caps,
                        xmlStrEqual(cur->name, BAD_CAST "source")) {
                 dev  = virXMLPropString(cur, "dev");
                 mode = virXMLPropString(cur, "mode");
-            } else if (!virtPortParsed &&
+            } else if ((virtPort == NULL) &&
                        (def->type == VIR_DOMAIN_NET_TYPE_DIRECT) &&
                        xmlStrEqual(cur->name, BAD_CAST "virtualport")) {
-                if (virVirtualPortProfileParamsParseXML(cur, &virtPort))
+                if (virVirtualPortProfileParamsParseXML(cur, &virtPort) < 0)
                     goto error;
-                virtPortParsed = true;
             } else if ((network == NULL) &&
                        ((def->type == VIR_DOMAIN_NET_TYPE_SERVER) ||
                         (def->type == VIR_DOMAIN_NET_TYPE_CLIENT) ||
@@ -2853,9 +2852,8 @@ virDomainNetDefParseXML(virCapsPtr caps,
         } else
             def->data.direct.mode = VIR_MACVTAP_MODE_VEPA;
 
-        if (virtPortParsed)
-            def->data.direct.virtPortProfile = virtPort;
-
+        def->data.direct.virtPortProfile = virtPort;
+        virtPort = NULL;
         def->data.direct.linkdev = dev;
         dev = NULL;
 
@@ -2962,6 +2960,7 @@ cleanup:
     VIR_FREE(port);
     VIR_FREE(ifname);
     VIR_FREE(dev);
+    VIR_FREE(virtPort);
     VIR_FREE(script);
     VIR_FREE(bridge);
     VIR_FREE(model);
@@ -8601,7 +8600,7 @@ virDomainNetDefFormat(virBufferPtr buf,
         virBufferAsprintf(buf, " mode='%s'",
                    virMacvtapModeTypeToString(def->data.direct.mode));
         virBufferAddLit(buf, "/>\n");
-        virVirtualPortProfileFormat(buf, &def->data.direct.virtPortProfile,
+        virVirtualPortProfileFormat(buf, def->data.direct.virtPortProfile,
                                     "      ");
         break;
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 7a3d72b..69e74dc 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -381,7 +381,7 @@ struct _virDomainNetDef {
         struct {
             char *linkdev;
             int mode; /* enum virMacvtapMode from util/macvtap.h */
-            virVirtualPortProfileParams virtPortProfile;
+            virVirtualPortProfileParamsPtr virtPortProfile;
         } direct;
     } data;
     struct {
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a3bce4a..f456e25 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -127,7 +127,7 @@ qemuPhysIfaceConnect(virDomainDefPtr def,
 
     rc = openMacvtapTap(net->ifname, net->mac, net->data.direct.linkdev,
                         net->data.direct.mode, vnet_hdr, def->uuid,
-                        &net->data.direct.virtPortProfile, &res_ifname,
+                        net->data.direct.virtPortProfile, &res_ifname,
                         vmop, driver->stateDir);
     if (rc >= 0) {
         virDomainAuditNetDevice(def, net, res_ifname, true);
@@ -150,7 +150,7 @@ qemuPhysIfaceConnect(virDomainDefPtr def,
                 VIR_FORCE_CLOSE(rc);
                 delMacvtap(net->ifname, net->mac, net->data.direct.linkdev,
                            net->data.direct.mode,
-                           &net->data.direct.virtPortProfile,
+                           net->data.direct.virtPortProfile,
                            driver->stateDir);
                 VIR_FREE(net->ifname);
             }
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 0eae661..6c22f4c 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1616,7 +1616,7 @@ int qemuDomainDetachNetDevice(struct qemud_driver *driver,
     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,
+                   detach->data.direct.virtPortProfile,
                    driver->stateDir);
         VIR_FREE(detach->ifname);
     }
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index dfa80e3..84fe05a 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -2341,7 +2341,7 @@ qemuMigrationVPAssociatePortProfiles(virDomainDefPtr def) {
             if (vpAssociatePortProfileId(net->ifname,
                                          net->mac,
                                          net->data.direct.linkdev,
-                                         &net->data.direct.virtPortProfile,
+                                         net->data.direct.virtPortProfile,
                                          def->uuid,
                                          VIR_VM_OP_MIGRATE_IN_FINISH) != 0)
                 goto err_exit;
@@ -2358,7 +2358,7 @@ err_exit:
             vpDisassociatePortProfileId(net->ifname,
                                         net->mac,
                                         net->data.direct.linkdev,
-                                        &net->data.direct.virtPortProfile,
+                                        net->data.direct.virtPortProfile,
                                         VIR_VM_OP_MIGRATE_IN_FINISH);
         }
     }
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 448b06e..5121241 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3017,7 +3017,7 @@ void qemuProcessStop(struct qemud_driver *driver,
         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);
+                       net->data.direct.virtPortProfile, driver->stateDir);
             VIR_FREE(net->ifname);
         }
     }
diff --git a/src/util/network.c b/src/util/network.c
index a323b26..c35668d 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -685,7 +685,7 @@ VIR_ENUM_IMPL(virVirtualPort, VIR_VIRTUALPORT_TYPE_LAST,
 
 int
 virVirtualPortProfileParamsParseXML(xmlNodePtr node,
-                                    virVirtualPortProfileParamsPtr virtPort)
+                                    virVirtualPortProfileParamsPtr *def)
 {
     int ret = -1;
     char *virtPortType;
@@ -694,8 +694,14 @@ virVirtualPortProfileParamsParseXML(xmlNodePtr node,
     char *virtPortTypeIDVersion = NULL;
     char *virtPortInstanceID = NULL;
     char *virtPortProfileID = NULL;
+    virVirtualPortProfileParamsPtr virtPort = NULL;
     xmlNodePtr cur = node->children;
 
+    if (VIR_ALLOC(virtPort) < 0) {
+        virReportOOMError();
+        return -1;
+    }
+
     virtPortType = virXMLPropString(node, "type");
     if (!virtPortType) {
         virSocketError(VIR_ERR_XML_ERROR, "%s",
@@ -785,7 +791,7 @@ virVirtualPortProfileParamsParseXML(xmlNodePtr node,
             }
 
             virtPort->virtPortType = VIR_VIRTUALPORT_8021QBG;
-            ret = 0;
+
         } else {
                     virSocketError(VIR_ERR_XML_ERROR, "%s",
                                          _("a parameter is missing for 802.1Qbg description"));
@@ -798,7 +804,6 @@ virVirtualPortProfileParamsParseXML(xmlNodePtr node,
             if (virStrcpyStatic(virtPort->u.virtPort8021Qbh.profileID,
                                 virtPortProfileID) != NULL) {
                 virtPort->virtPortType = VIR_VIRTUALPORT_8021QBH;
-                ret = 0;
             } else {
                 virSocketError(VIR_ERR_XML_ERROR, "%s",
                                      _("profileid parameter too long"));
@@ -821,7 +826,11 @@ virVirtualPortProfileParamsParseXML(xmlNodePtr node,
     break;
     }
 
+    ret = 0;
+    *def = virtPort;
+    virtPort = NULL;
 error:
+    VIR_FREE(virtPort);
     VIR_FREE(virtPortManagerID);
     VIR_FREE(virtPortTypeID);
     VIR_FREE(virtPortTypeIDVersion);
diff --git a/src/util/network.h b/src/util/network.h
index 0a8fc03..b69ee3d 100644
--- a/src/util/network.h
+++ b/src/util/network.h
@@ -130,7 +130,7 @@ struct _virVirtualPortProfileParams {
 
 int
 virVirtualPortProfileParamsParseXML(xmlNodePtr node,
-                                    virVirtualPortProfileParamsPtr virtPort);
+                                    virVirtualPortProfileParamsPtr *virtPort);
 void
 virVirtualPortProfileFormat(virBufferPtr buf,
                             virVirtualPortProfileParamsPtr virtPort,
-- 
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]