[libvirt] [PATCH 1/2] util: Introduce flags field for macvtap creation

Matthew Rosato mjrosato at linux.vnet.ibm.com
Tue Jul 1 18:00:56 UTC 2014


Currently, there is one flag passed in during macvtap creation
(withTap) -- Let's convert this field to an unsigned int flag
field for future expansion.

Signed-off-by: Matthew Rosato <mjrosato at linux.vnet.ibm.com>
---
 src/lxc/lxc_process.c       |    2 +-
 src/qemu/qemu_command.c     |    3 ++-
 src/util/virnetdevmacvlan.c |   24 +++++++++++++++---------
 src/util/virnetdevmacvlan.h |    8 +++++++-
 4 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 0aef13a..ab0c5d0 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -333,7 +333,7 @@ char *virLXCProcessSetupInterfaceDirect(virConnectPtr conn,
             net->ifname, &net->mac,
             virDomainNetGetActualDirectDev(net),
             virDomainNetGetActualDirectMode(net),
-            false, false, def->uuid,
+            0, false, def->uuid,
             virDomainNetGetActualVirtPortProfile(net),
             &res_ifname,
             VIR_NETDEV_VPORT_PROFILE_OP_CREATE,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 63f322a..314d8a3 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -171,6 +171,7 @@ qemuPhysIfaceConnect(virDomainDefPtr def,
     char *res_ifname = NULL;
     int vnet_hdr = 0;
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+    unsigned int macvlan_create_flags = VIR_NETDEV_MACVLAN_CREATE_WITH_TAP;
 
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VNET_HDR) &&
         net->model && STREQ(net->model, "virtio"))
@@ -180,7 +181,7 @@ qemuPhysIfaceConnect(virDomainDefPtr def,
         net->ifname, &net->mac,
         virDomainNetGetActualDirectDev(net),
         virDomainNetGetActualDirectMode(net),
-        true, vnet_hdr, def->uuid,
+        macvlan_create_flags, vnet_hdr, def->uuid,
         virDomainNetGetActualVirtPortProfile(net),
         &res_ifname,
         vmop, cfg->stateDir,
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index cb85b74..bfbecbf 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -790,6 +790,7 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
  * @macaddress: The MAC address for the macvtap device
  * @linkdev: The interface name of the NIC to connect to the external bridge
  * @mode: int describing the mode for 'bridge', 'vepa', 'private' or 'passthru'.
+ * @flags: OR of virNetDevMacVLanCreateFlags.
  * @vnet_hdr: 1 to enable IFF_VNET_HDR, 0 to disable it
  * @vmuuid: The UUID of the VM the macvtap belongs to
  * @virtPortProfile: pointer to object holding the virtual port profile data
@@ -797,14 +798,15 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
  *     interface will be stored into if everything succeeded. It is up
  *     to the caller to free the string.
  *
- * Returns file descriptor of the tap device in case of success with @withTap,
- * otherwise returns 0; returns -1 on error.
+ * Returns file descriptor of the tap device in case of success with
+ * flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP, otherwise returns 0; returns
+ * -1 on error.
  */
 int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname,
                                            const virMacAddr *macaddress,
                                            const char *linkdev,
                                            virNetDevMacVLanMode mode,
-                                           bool withTap,
+                                           unsigned int flags,
                                            int vnet_hdr,
                                            const unsigned char *vmuuid,
                                            virNetDevVPortProfilePtr virtPortProfile,
@@ -813,9 +815,12 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname,
                                            char *stateDir,
                                            virNetDevBandwidthPtr bandwidth)
 {
-    const char *type = withTap ? "macvtap" : "macvlan";
-    const char *prefix = withTap ? MACVTAP_NAME_PREFIX : MACVLAN_NAME_PREFIX;
-    const char *pattern = withTap ? MACVTAP_NAME_PATTERN : MACVLAN_NAME_PATTERN;
+    const char *type = (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) ?
+        "macvtap" : "macvlan";
+    const char *prefix = (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) ?
+        MACVTAP_NAME_PREFIX : MACVLAN_NAME_PREFIX;
+    const char *pattern = (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) ?
+        MACVTAP_NAME_PATTERN : MACVLAN_NAME_PATTERN;
     int c, rc;
     char ifname[IFNAMSIZ];
     int retries, do_retry = 0;
@@ -903,7 +908,7 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname,
         goto disassociate_exit;
     }
 
-    if (withTap) {
+    if (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP) {
         if ((rc = virNetDevMacVLanTapOpen(cr_ifname, 10)) < 0)
             goto disassociate_exit;
 
@@ -925,7 +930,7 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *tgifname,
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("cannot set bandwidth limits on %s"),
                        cr_ifname);
-        if (withTap)
+        if (flags & VIR_NETDEV_MACVLAN_CREATE_WITH_TAP)
             VIR_FORCE_CLOSE(rc); /* sets rc to -1 */
         else
             rc = -1;
@@ -1069,7 +1074,7 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *ifname ATTRIBUTE_UNUSED,
                                            const virMacAddr *macaddress ATTRIBUTE_UNUSED,
                                            const char *linkdev ATTRIBUTE_UNUSED,
                                            virNetDevMacVLanMode mode ATTRIBUTE_UNUSED,
-                                           bool withTap ATTRIBUTE_UNUSED,
+                                           unsigned int flags,
                                            int vnet_hdr ATTRIBUTE_UNUSED,
                                            const unsigned char *vmuuid ATTRIBUTE_UNUSED,
                                            virNetDevVPortProfilePtr virtPortProfile ATTRIBUTE_UNUSED,
@@ -1078,6 +1083,7 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *ifname ATTRIBUTE_UNUSED,
                                            char *stateDir ATTRIBUTE_UNUSED,
                                            virNetDevBandwidthPtr bandwidth ATTRIBUTE_UNUSED)
 {
+    virCheckFlags(0, NULL);
     virReportSystemError(ENOSYS, "%s",
                          _("Cannot create macvlan devices on this platform"));
     return -1;
diff --git a/src/util/virnetdevmacvlan.h b/src/util/virnetdevmacvlan.h
index 9b15a31..f7895b5 100644
--- a/src/util/virnetdevmacvlan.h
+++ b/src/util/virnetdevmacvlan.h
@@ -40,6 +40,12 @@ typedef enum {
 } virNetDevMacVLanMode;
 VIR_ENUM_DECL(virNetDevMacVLanMode)
 
+typedef enum {
+   VIR_NETDEV_MACVLAN_CREATE_NONE = 0,
+   /* Create with a tap device */
+   VIR_NETDEV_MACVLAN_CREATE_WITH_TAP       = 1 << 0,
+} virNetDevMacVLanCreateFlags;
+
 int virNetDevMacVLanCreate(const char *ifname,
                            const char *type,
                            const virMacAddr *macaddress,
@@ -56,7 +62,7 @@ int virNetDevMacVLanCreateWithVPortProfile(const char *ifname,
                                            const virMacAddr *macaddress,
                                            const char *linkdev,
                                            virNetDevMacVLanMode mode,
-                                           bool withTap,
+                                           unsigned int flags,
                                            int vnet_hdr,
                                            const unsigned char *vmuuid,
                                            virNetDevVPortProfilePtr virtPortProfile,
-- 
1.7.9.5




More information about the libvir-list mailing list