[libvirt] [PATCH 2/5] macvtap support for libvirt -- parse new interface XML

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

 



This part adds support to domain_conf.{c|h} for parsing the new
interface XML of type 'direct'.

Signed-off-by: Stefan Berger <stefanb@xxxxxxxxxx>




Index: libvirt-macvtap/src/conf/domain_conf.c
===================================================================
--- libvirt-macvtap.orig/src/conf/domain_conf.c
+++ libvirt-macvtap/src/conf/domain_conf.c
@@ -41,6 +41,7 @@
 #include "c-ctype.h"
 #include "logging.h"
 #include "network.h"
+#include "macvtap.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
@@ -140,7 +141,8 @@ VIR_ENUM_IMPL(virDomainNet, VIR_DOMAIN_N
               "mcast",
               "network",
               "bridge",
-              "internal")
+              "internal",
+              "direct")
 
 VIR_ENUM_IMPL(virDomainChrTarget, VIR_DOMAIN_CHR_TARGET_TYPE_LAST,
               "null",
@@ -222,6 +224,12 @@ VIR_ENUM_IMPL(virDomainSeclabel, VIR_DOM
               "dynamic",
               "static")
 
+VIR_ENUM_IMPL(virDomainNetdevMacvtap, VIR_DOMAIN_NETDEV_MACVTAP_MODE_LAST,
+              MACVTAP_MODE_PRIVATE_STR,
+              MACVTAP_MODE_VEPA_STR,
+              MACVTAP_MODE_BRIDGE_STR)
+
+
 #define virDomainReportError(conn, code, fmt...)                           \
         virReportErrorHelper(conn, VIR_FROM_DOMAIN, code, __FILE__,        \
                                __FUNCTION__, __LINE__, fmt)
@@ -430,6 +438,11 @@ void virDomainNetDefFree(virDomainNetDef
     case VIR_DOMAIN_NET_TYPE_INTERNAL:
         VIR_FREE(def->data.internal.name);
         break;
+
+    case VIR_DOMAIN_NET_TYPE_DIRECT:
+        VIR_FREE(def->data.direct.linkdev);
+        VIR_FREE(def->data.direct.mode);
+        break;
     }
 
     VIR_FREE(def->ifname);
@@ -1631,6 +1644,7 @@ virDomainNetDefParseXML(virConnectPtr co
     char *model = NULL;
     char *internal = NULL;
     char *devaddr = NULL;
+    char *mode = NULL;
 
     if (VIR_ALLOC(def) < 0) {
         virReportOOMError(conn);
@@ -1667,9 +1681,11 @@ virDomainNetDefParseXML(virConnectPtr co
                        (xmlStrEqual(cur->name, BAD_CAST "source"))) {
                 bridge = virXMLPropString(cur, "bridge");
             } else if ((dev == NULL) &&
-                       (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET) &&
+                       (def->type == VIR_DOMAIN_NET_TYPE_ETHERNET ||
+                        def->type == VIR_DOMAIN_NET_TYPE_DIRECT) &&
                        xmlStrEqual(cur->name, BAD_CAST "source")) {
-                dev = virXMLPropString(cur, "dev");
+                dev  = virXMLPropString(cur, "dev");
+                mode = virXMLPropString(cur, "mode");
             } else if ((network == NULL) &&
                        ((def->type == VIR_DOMAIN_NET_TYPE_SERVER) ||
                         (def->type == VIR_DOMAIN_NET_TYPE_CLIENT) ||
@@ -1823,6 +1839,27 @@ virDomainNetDefParseXML(virConnectPtr co
         def->data.internal.name = internal;
         internal = NULL;
         break;
+
+    case VIR_DOMAIN_NET_TYPE_DIRECT:
+        if (dev == NULL) {
+            virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s",
+        _("No <source> 'dev' attribute specified with <interface type='direct'/>"));
+            goto error;
+        }
+
+        if (mode != NULL) {
+            if (virDomainNetdevMacvtapTypeFromString(mode) < 0) {
+                virDomainReportError(conn, VIR_ERR_INTERNAL_ERROR, "%s",
+                                     _("Unkown mode has been specified"));
+                goto error;
+            }
+        }
+
+        def->data.direct.linkdev = dev;
+        dev = NULL;
+        def->data.direct.mode = mode;
+        mode = NULL;
+        break;
     }
 
     if (ifname != NULL) {
@@ -1862,6 +1899,7 @@ cleanup:
     VIR_FREE(type);
     VIR_FREE(internal);
     VIR_FREE(devaddr);
+    VIR_FREE(mode);
 
     return def;
 
@@ -4795,6 +4833,14 @@ virDomainNetDefFormat(virConnectPtr conn
                               def->data.internal.name);
         break;
 
+    case VIR_DOMAIN_NET_TYPE_DIRECT:
+        virBufferEscapeString(buf, "      <source dev='%s'",
+                              def->data.direct.linkdev);
+        if (def->data.direct.mode)
+            virBufferEscapeString(buf, " mode='%s'",
+                                  def->data.direct.mode);
+        virBufferAddLit(buf, "/>\n");
+        break;
     }
 
     if (def->ifname)
Index: libvirt-macvtap/src/conf/domain_conf.h
===================================================================
--- libvirt-macvtap.orig/src/conf/domain_conf.h
+++ libvirt-macvtap/src/conf/domain_conf.h
@@ -211,6 +211,7 @@ enum virDomainNetType {
     VIR_DOMAIN_NET_TYPE_NETWORK,
     VIR_DOMAIN_NET_TYPE_BRIDGE,
     VIR_DOMAIN_NET_TYPE_INTERNAL,
+    VIR_DOMAIN_NET_TYPE_DIRECT,
 
     VIR_DOMAIN_NET_TYPE_LAST,
 };
@@ -244,6 +245,10 @@ struct _virDomainNetDef {
         struct {
             char *name;
         } internal;
+        struct {
+            char *linkdev;
+            char *mode;
+        } direct;
     } data;
     char *ifname;
     virDomainDeviceInfo info;
@@ -594,6 +599,15 @@ struct _virSecurityLabelDef {
     int type;
 };
 
+enum virDomainNetdevMacvtapType {
+    VIR_DOMAIN_NETDEV_MACVTAP_MODE_PRIVATE,
+    VIR_DOMAIN_NETDEV_MACVTAP_MODE_VEPA,
+    VIR_DOMAIN_NETDEV_MACVTAP_MODE_BRIDGE,
+
+    VIR_DOMAIN_NETDEV_MACVTAP_MODE_LAST,
+};
+
+
 #define VIR_DOMAIN_CPUMASK_LEN 1024
 
 /* Guest VM main configuration */
@@ -915,4 +929,6 @@ VIR_ENUM_DECL(virDomainGraphics)
 VIR_ENUM_DECL(virDomainState)
 VIR_ENUM_DECL(virDomainSeclabel)
 
+VIR_ENUM_DECL(virDomainNetdevMacvtap)
+
 #endif /* __DOMAIN_CONF_H */
--
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]