[PATCH] Remove macvtap dependancy on domain configuration

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

 



Files under src/util must not depend on src/conf
Solve the macvtap problem by moving the definition
of macvtap modes from domain_conf.h into macvtap.h

* src/util/macvtap.c, src/util/macvtap.h: Add enum
  for macvtap modes
* src/conf/domain_conf.c, src/conf/domain_conf.h: Remove
  enum for macvtap modes
---
 src/conf/domain_conf.c |   17 ++++++-----------
 src/conf/domain_conf.h |   15 +--------------
 src/util/macvtap.c     |   40 +++++++++++++++++-----------------------
 src/util/macvtap.h     |   14 +++++++++++++-
 4 files changed, 37 insertions(+), 49 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index b5c0f83..c528960 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -447,12 +447,6 @@ VIR_ENUM_IMPL(virDomainSeclabel, VIR_DOMAIN_SECLABEL_LAST,
               "dynamic",
               "static")
 
-VIR_ENUM_IMPL(virDomainNetdevMacvtap, VIR_DOMAIN_NETDEV_MACVTAP_MODE_LAST,
-              "vepa",
-              "private",
-              "bridge",
-              "passthrough")
-
 VIR_ENUM_IMPL(virVirtualPort, VIR_VIRTUALPORT_TYPE_LAST,
               "none",
               "802.1Qbg",
@@ -1156,7 +1150,7 @@ static virDomainObjPtr virDomainObjNew(virCapsPtr caps)
     }
 
     if (caps->privateDataAllocFunc &&
-        !(domain->privateData = (caps->privateDataAllocFunc)())) {
+        !(domain->privateData = (caps->privateDataAllocFunc)(caps->privateDataOpaque))) {
         virReportOOMError();
         VIR_FREE(domain);
         return NULL;
@@ -2974,14 +2968,14 @@ virDomainNetDefParseXML(virCapsPtr caps,
 
         if (mode != NULL) {
             int m;
-            if ((m = virDomainNetdevMacvtapTypeFromString(mode)) < 0) {
+            if ((m = virMacvtapModeTypeFromString(mode)) < 0) {
                 virDomainReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                                      _("Unkown mode has been specified"));
                 goto error;
             }
             def->data.direct.mode = m;
         } else
-            def->data.direct.mode = VIR_DOMAIN_NETDEV_MACVTAP_MODE_VEPA;
+            def->data.direct.mode = VIR_MACVTAP_MODE_VEPA;
 
         if (virtPortParsed)
             def->data.direct.virtPortProfile = virtPort;
@@ -6737,12 +6731,13 @@ static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps,
         char *str = virXMLPropString(nodes[i], "flag");
         if (str) {
             int flag = virDomainTaintTypeFromString(str);
-            VIR_FREE(str);
             if (flag < 0) {
                 virDomainReportError(VIR_ERR_INTERNAL_ERROR,
                                      _("Unknown taint flag %s"), str);
+                VIR_FREE(str);
                 goto error;
             }
+            VIR_FREE(str);
             virDomainObjTaint(obj, flag);
         }
     }
@@ -8634,7 +8629,7 @@ virDomainNetDefFormat(virBufferPtr buf,
         virBufferEscapeString(buf, "      <source dev='%s'",
                               def->data.direct.linkdev);
         virBufferAsprintf(buf, " mode='%s'",
-                   virDomainNetdevMacvtapTypeToString(def->data.direct.mode));
+                   virMacvtapModeTypeToString(def->data.direct.mode));
         virBufferAddLit(buf, "/>\n");
         virVirtualPortProfileFormat(buf, &def->data.direct.virtPortProfile,
                                     "      ");
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 994ff91..aa25e36 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -348,17 +348,6 @@ enum virDomainNetVirtioTxModeType {
     VIR_DOMAIN_NET_VIRTIO_TX_MODE_LAST,
 };
 
-/* the mode type for macvtap devices */
-enum virDomainNetdevMacvtapType {
-    VIR_DOMAIN_NETDEV_MACVTAP_MODE_VEPA,
-    VIR_DOMAIN_NETDEV_MACVTAP_MODE_PRIVATE,
-    VIR_DOMAIN_NETDEV_MACVTAP_MODE_BRIDGE,
-    VIR_DOMAIN_NETDEV_MACVTAP_MODE_PASSTHRU,
-
-    VIR_DOMAIN_NETDEV_MACVTAP_MODE_LAST,
-};
-
-
 /* Stores the virtual network interface configuration */
 typedef struct _virDomainNetDef virDomainNetDef;
 typedef virDomainNetDef *virDomainNetDefPtr;
@@ -396,7 +385,7 @@ struct _virDomainNetDef {
         } internal;
         struct {
             char *linkdev;
-            int mode;
+            int mode; /* enum virMacvtapMode from util/macvtap.h */
             virVirtualPortProfileParams virtPortProfile;
         } direct;
     } data;
@@ -1615,8 +1604,6 @@ int virDomainStateReasonFromString(virDomainState state, const char *reason);
 VIR_ENUM_DECL(virDomainSeclabel)
 VIR_ENUM_DECL(virDomainClockOffset)
 
-VIR_ENUM_DECL(virDomainNetdevMacvtap)
-
 VIR_ENUM_DECL(virDomainTimerName)
 VIR_ENUM_DECL(virDomainTimerTrack)
 VIR_ENUM_DECL(virDomainTimerTickpolicy)
diff --git a/src/util/macvtap.c b/src/util/macvtap.c
index 48c7b0e..4e4ed79 100644
--- a/src/util/macvtap.c
+++ b/src/util/macvtap.c
@@ -55,12 +55,17 @@
 #include "util.h"
 #include "macvtap.h"
 
+VIR_ENUM_IMPL(virMacvtapMode, VIR_MACVTAP_MODE_LAST,
+              "vepa",
+              "private",
+              "bridge",
+              "passthrough")
+
 #if WITH_MACVTAP || WITH_VIRTUALPORT
 
 # include "memory.h"
 # include "logging.h"
 # include "interface.h"
-# include "conf/domain_conf.h"
 # include "virterror_internal.h"
 # include "uuid.h"
 # include "files.h"
@@ -468,26 +473,6 @@ int openTap(const char *ifname,
 }
 
 
-static uint32_t
-macvtapModeFromInt(enum virDomainNetdevMacvtapType mode)
-{
-    switch (mode) {
-    case VIR_DOMAIN_NETDEV_MACVTAP_MODE_PRIVATE:
-        return MACVLAN_MODE_PRIVATE;
-
-    case VIR_DOMAIN_NETDEV_MACVTAP_MODE_BRIDGE:
-        return MACVLAN_MODE_BRIDGE;
-
-    case VIR_DOMAIN_NETDEV_MACVTAP_MODE_PASSTHRU:
-        return MACVLAN_MODE_PASSTHRU;
-
-    case VIR_DOMAIN_NETDEV_MACVTAP_MODE_VEPA:
-    default:
-        return MACVLAN_MODE_VEPA;
-    }
-}
-
-
 /**
  * configMacvtapTap:
  * @tapfd: file descriptor of the macvtap tap
@@ -643,6 +628,13 @@ restoreMacAddress(const char *linkdev,
     return 0;
 }
 
+static const uint32_t modeMap[VIR_MACVTAP_MODE_LAST] = {
+    [VIR_MACVTAP_MODE_VEPA] = MACVLAN_MODE_VEPA,
+    [VIR_MACVTAP_MODE_PRIVATE] = MACVLAN_MODE_PRIVATE,
+    [VIR_MACVTAP_MODE_BRIDGE] = MACVLAN_MODE_BRIDGE,
+    [VIR_MACVTAP_MODE_PASSTHRU] = MACVLAN_MODE_PASSTHRU,
+};
+
 /**
  * openMacvtapTap:
  * Create an instance of a macvtap device and open its tap character
@@ -667,7 +659,7 @@ int
 openMacvtapTap(const char *tgifname,
                const unsigned char *macaddress,
                const char *linkdev,
-               int mode,
+               enum virMacvtapMode mode,
                int vnet_hdr,
                const unsigned char *vmuuid,
                virVirtualPortProfileParamsPtr virtPortProfile,
@@ -679,10 +671,12 @@ openMacvtapTap(const char *tgifname,
     int c, rc;
     char ifname[IFNAMSIZ];
     int retries, do_retry = 0;
-    uint32_t macvtapMode = macvtapModeFromInt(mode);
+    uint32_t macvtapMode;
     const char *cr_ifname;
     int ifindex;
 
+    macvtapMode = modeMap[mode];
+
     *res_ifname = NULL;
 
     VIR_DEBUG("%s: VM OPERATION: %s", __FUNCTION__, virVMOperationTypeToString(vmOp));
diff --git a/src/util/macvtap.h b/src/util/macvtap.h
index 2843596..1b85989 100644
--- a/src/util/macvtap.h
+++ b/src/util/macvtap.h
@@ -34,6 +34,17 @@ enum virVirtualPortType {
     VIR_VIRTUALPORT_TYPE_LAST,
 };
 
+/* the mode type for macvtap devices */
+enum virMacvtapMode {
+    VIR_MACVTAP_MODE_VEPA,
+    VIR_MACVTAP_MODE_PRIVATE,
+    VIR_MACVTAP_MODE_BRIDGE,
+    VIR_MACVTAP_MODE_PASSTHRU,
+
+    VIR_MACVTAP_MODE_LAST,
+};
+
+
 # ifdef IFLA_VF_PORT_PROFILE_MAX
 #  define LIBVIRT_IFLA_VF_PORT_PROFILE_MAX IFLA_VF_PORT_PROFILE_MAX
 # else
@@ -78,7 +89,7 @@ enum virVMOperationType {
 int openMacvtapTap(const char *ifname,
                    const unsigned char *macaddress,
                    const char *linkdev,
-                   int mode,
+                   enum virMacvtapMode mode,
                    int vnet_hdr,
                    const unsigned char *vmuuid,
                    virVirtualPortProfileParamsPtr virtPortProfile,
@@ -110,5 +121,6 @@ int vpDisassociatePortProfileId(const char *macvtap_ifname,
 
 VIR_ENUM_DECL(virVirtualPort)
 VIR_ENUM_DECL(virVMOperation)
+VIR_ENUM_DECL(virMacvtapMode)
 
 #endif /* __UTIL_MACVTAP_H__ */
-- 
1.7.4.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]