<br><br><div class="gmail_quote">On Thu, Mar 1, 2012 at 12:48 PM, Laine Stump <span dir="ltr"><<a href="mailto:laine@laine.org">laine@laine.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
With an additional new bool added to determine whether or not to<br>
discourage the use of the supplied MAC address by the bridge itself,<br>
virNetDevTapCreateInBridgePort had three booleans (well, 2 bools and<br>
an int used as a bool) in the arg list, which made it increasingly<br>
difficult to follow what was going on. This patch combines those three<br>
into a single flags arg, which not only shortens the arg list, but<br>
makes it more self-documenting.<br>
---<br>
<br>
Does this make more sense as a PATCH 2/1 to be associated with the<br>
first patch in this thread:<br>
<br>
  <a href="http://www.redhat.com/archives/libvir-list/2012-February/msg00760.html" target="_blank">http://www.redhat.com/archives/libvir-list/2012-February/msg00760.html</a><br>
<br>
or should I squash them both together? (I'm leaning towards two<br>
separate patches, but could be convinced either way)<br>
<br>
<br>
 src/network/bridge_driver.c |    3 +-<br>
 src/qemu/qemu_command.c     |   13 ++++++-----<br>
 src/uml/uml_conf.c          |    8 +++---<br>
 src/util/virnetdevtap.c     |   46 +++++++++++++++++++++++++-----------------<br>
 src/util/virnetdevtap.h     |   20 +++++++++++++-----<br>
 5 files changed, 54 insertions(+), 36 deletions(-)<br>
<br>
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c<br>
index 3e1e031..cf75d26 100644<br>
--- a/src/network/bridge_driver.c<br>
+++ b/src/network/bridge_driver.c<br>
@@ -1766,7 +1766,8 @@ networkStartNetworkVirtual(struct network_driver *driver,<br>
         }<br>
         if (virNetDevTapCreateInBridgePort(network->def->bridge,<br>
                                            &macTapIfName, network->def->mac,<br>
-                                           false, 0, false, NULL, NULL) < 0) {<br>
+                                           NULL, NULL,<br>
+                                           VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE) < 0) {<br>
             VIR_FREE(macTapIfName);<br>
             goto err0;<br>
         }<br>
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c<br>
index 7e121c7..acfd38c 100644<br>
--- a/src/qemu/qemu_command.c<br>
+++ b/src/qemu/qemu_command.c<br>
@@ -178,7 +178,7 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,<br>
     char *brname = NULL;<br>
     int err;<br>
     int tapfd = -1;<br>
-    int vnet_hdr = 0;<br>
+    unsigned int tap_create_flags = VIR_NETDEV_TAP_CREATE_IFUP;<br>
     bool template_ifname = false;<br>
     int actualType = virDomainNetGetActualType(net);<br>
<br>
@@ -240,12 +240,13 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,<br>
     }<br>
<br>
     if (qemuCapsGet(qemuCaps, QEMU_CAPS_VNET_HDR) &&<br>
-        net->model && STREQ(net->model, "virtio"))<br>
-        vnet_hdr = 1;<br>
+        net->model && STREQ(net->model, "virtio")) {<br>
+        tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;<br>
+    }<br>
<br>
-    err = virNetDevTapCreateInBridgePort(brname, &net->ifname, net->mac, true,<br>
-                                         vnet_hdr, true, &tapfd,<br>
-                                         virDomainNetGetActualVirtPortProfile(net));<br>
+    err = virNetDevTapCreateInBridgePort(brname, &net->ifname, net->mac, &tapfd,<br>
+                                         virDomainNetGetActualVirtPortProfile(net),<br>
+                                         tap_create_flags);<br>
     virDomainAuditNetDevice(def, net, "/dev/net/tun", tapfd >= 0);<br>
     if (err < 0) {<br>
         if (template_ifname)<br>
diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c<br>
index c7b29a0..89fdd9f 100644<br>
--- a/src/uml/uml_conf.c<br>
+++ b/src/uml/uml_conf.c<br>
@@ -1,7 +1,7 @@<br>
 /*<br>
  * uml_conf.c: UML driver configuration<br>
  *<br>
- * Copyright (C) <a href="tel:2006-2011" value="+37120062011">2006-2011</a> Red Hat, Inc.<br>
+ * Copyright (C) <a href="tel:2006-2012" value="+37120062012">2006-2012</a> Red Hat, Inc.<br>
  * Copyright (C) 2006 Daniel P. Berrange<br>
  *<br>
  * This library is free software; you can redistribute it and/or<br>
@@ -138,9 +138,9 @@ umlConnectTapDevice(virConnectPtr conn,<br>
         template_ifname = true;<br>
     }<br>
<br>
-    if (virNetDevTapCreateInBridgePort(bridge, &net->ifname, net->mac, true,<br>
-                                       0, true, NULL,<br>
-                                       virDomainNetGetActualVirtPortProfile(net)) < 0) {<br>
+    if (virNetDevTapCreateInBridgePort(bridge, &net->ifname, net->mac, NULL,<br>
+                                       virDomainNetGetActualVirtPortProfile(net),<br>
+                                       VIR_NETDEV_TAP_CREATE_IFUP) < 0) {<br>
         if (template_ifname)<br>
             VIR_FREE(net->ifname);<br>
         goto error;<br>
diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c<br>
index 868ba57..fb0a8d2 100644<br>
--- a/src/util/virnetdevtap.c<br>
+++ b/src/util/virnetdevtap.c<br>
@@ -107,22 +107,25 @@ virNetDevProbeVnetHdr(int tapfd)<br>
<br>
 #ifdef TUNSETIFF<br>
 /**<br>
- * brCreateTap:<br>
+ * virNetDevTapCreate:<br>
  * @ifname: the interface name<br>
- * @vnet_hr: whether to try enabling IFF_VNET_HDR<br>
  * @tapfd: file descriptor return value for the new tap device<br>
+ * @flags: OR of virNetDevTapCreateFlags. Only one flag is recognized:<br>
+ *<br>
+ *   VIR_NETDEV_TAP_CREATE_VNET_HDR<br>
+ *     - Enable IFF_VNET_HDR on the tap device<br>
  *<br>
  * Creates a tap interface.<br>
  * If the @tapfd parameter is supplied, the open tap device file<br>
  * descriptor will be returned, otherwise the TAP device will be made<br>
- * persistent and closed. The caller must use brDeleteTap to remove<br>
- * a persistent TAP devices when it is no longer needed.<br>
+ * persistent and closed. The caller must use virNetDevTapDelete to<br>
+ * remove a persistent TAP devices when it is no longer needed.<br>
  *<br>
  * Returns 0 in case of success or an errno code in case of failure.<br>
  */<br>
 int virNetDevTapCreate(char **ifname,<br>
-                       int vnet_hdr ATTRIBUTE_UNUSED,<br>
-                       int *tapfd)<br>
+                       int *tapfd,<br>
+                       unsigned int flags ATTRIBUTE_UNUSED)<br>
 {<br>
     int fd;<br>
     struct ifreq ifr;<br>
@@ -139,7 +142,8 @@ int virNetDevTapCreate(char **ifname,<br>
     ifr.ifr_flags = IFF_TAP|IFF_NO_PI;<br>
<br>
 # ifdef IFF_VNET_HDR<br>
-    if (vnet_hdr && virNetDevProbeVnetHdr(fd))<br>
+    if ((flags &  VIR_NETDEV_TAP_CREATE_VNET_HDR) &&<br>
+        virNetDevProbeVnetHdr(fd))<br>
         ifr.ifr_flags |= IFF_VNET_HDR;<br>
 # endif<br>
<br>
@@ -228,8 +232,8 @@ cleanup:<br>
 }<br>
 #else /* ! TUNSETIFF */<br>
 int virNetDevTapCreate(char **ifname ATTRIBUTE_UNUSED,<br>
-                       int vnet_hdr ATTRIBUTE_UNUSED,<br>
-                       int *tapfd ATTRIBUTE_UNUSED)<br>
+                       int *tapfd ATTRIBUTE_UNUSED,<br>
+                       unsigned int flags ATTRIBUTE_UNUSED)<br>
 {<br>
     virReportSystemError(ENOSYS, "%s",<br>
                          _("Unable to create TAP devices on this platform"));<br>
@@ -249,17 +253,23 @@ int virNetDevTapDelete(const char *ifname ATTRIBUTE_UNUSED)<br>
  * @brname: the bridge name<br>
  * @ifname: the interface name (or name template)<br>
  * @macaddr: desired MAC address (VIR_MAC_BUFLEN long)<br>
- * @discourage: whether bridge should be discouraged from using macaddr<br>
- * @vnet_hdr: whether to try enabling IFF_VNET_HDR<br>
  * @tapfd: file descriptor return value for the new tap device<br>
  * @virtPortProfile: bridge/port specific configuration<br>
+ * @flags: OR of virNetDevTapCreateFlags:<br>
+<br>
+ *   VIR_NETDEV_TAP_CREATE_IFUP<br>
+ *     - Bring the interface up<br>
+ *   VIR_NETDEV_TAP_CREATE_VNET_HDR<br>
+ *     - Enable IFF_VNET_HDR on the tap device<br>
+ *   VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE<br>
+ *     - Set this interface's MAC as the bridge's MAC address<br>
  *<br>
  * This function creates a new tap device on a bridge. @ifname can be either<br>
  * a fixed name or a name template with '%d' for dynamic name allocation.<br>
  * in either case the final name for the bridge will be stored in @ifname.<br>
  * If the @tapfd parameter is supplied, the open tap device file<br>
  * descriptor will be returned, otherwise the TAP device will be made<br>
- * persistent and closed. The caller must use brDeleteTap to remove<br>
+ * persistent and closed. The caller must use virNetDevTapDelete to remove<br>
  * a persistent TAP devices when it is no longer needed.<br>
  *<br>
  * Returns 0 in case of success or -1 on failure<br>
@@ -267,15 +277,13 @@ int virNetDevTapDelete(const char *ifname ATTRIBUTE_UNUSED)<br>
 int virNetDevTapCreateInBridgePort(const char *brname,<br>
                                    char **ifname,<br>
                                    const unsigned char *macaddr,<br>
-                                   bool discourage,<br>
-                                   int vnet_hdr,<br>
-                                   bool up,<br>
                                    int *tapfd,<br>
-                                   virNetDevVPortProfilePtr virtPortProfile)<br>
+                                   virNetDevVPortProfilePtr virtPortProfile,<br>
+                                   unsigned int flags)<br>
 {<br>
     unsigned char tapmac[VIR_MAC_BUFLEN];<br>
<br>
-    if (virNetDevTapCreate(ifname, vnet_hdr, tapfd) < 0)<br>
+    if (virNetDevTapCreate(ifname, tapfd, flags) < 0)<br>
         return -1;<br>
<br>
     /* We need to set the interface MAC before adding it<br>
@@ -285,7 +293,7 @@ int virNetDevTapCreateInBridgePort(const char *brname,<br>
      * device before we set our static MAC.<br>
      */<br>
     memcpy(tapmac, macaddr, VIR_MAC_BUFLEN);<br>
-    if (discourage)<br>
+    if (!(flags & VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE))<br>
         tapmac[0] = 0xFE; /* Discourage bridge from using TAP dev MAC */<br>
<br>
     if (virNetDevSetMAC(*ifname, tapmac) < 0)<br>
@@ -308,7 +316,7 @@ int virNetDevTapCreateInBridgePort(const char *brname,<br>
             goto error;<br>
     }<br>
<br>
-    if (virNetDevSetOnline(*ifname, up) < 0)<br>
+    if (virNetDevSetOnline(*ifname, !!(flags & VIR_NETDEV_TAP_CREATE_IFUP)) < 0)<br>
         goto error;<br>
<br>
     return 0;<br>
diff --git a/src/util/virnetdevtap.h b/src/util/virnetdevtap.h<br>
index fc50e22..971b166 100644<br>
--- a/src/util/virnetdevtap.h<br>
+++ b/src/util/virnetdevtap.h<br>
@@ -27,21 +27,29 @@<br>
 # include "virnetdevvportprofile.h"<br>
<br>
 int virNetDevTapCreate(char **ifname,<br>
-                       int vnet_hdr,<br>
-                       int *tapfd)<br>
+                       int *tapfd,<br>
+                       unsigned int flags)<br>
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;<br>
<br>
 int virNetDevTapDelete(const char *ifname)<br>
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;<br>
<br>
+typedef enum {<br>
+   VIR_NETDEV_TAP_CREATE_NONE = 0,<br>
+   /* Bring the interface up */<br>
+   VIR_NETDEV_TAP_CREATE_IFUP               = 1 << 0,<br>
+   /* Enable IFF_VNET_HDR on the tap device */<br>
+   VIR_NETDEV_TAP_CREATE_VNET_HDR           = 1 << 1,<br>
+   /* Set this interface's MAC as the bridge's MAC address */<br>
+   VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE = 1 << 2,<br>
+} virNetDevTapCreateFlags;<br>
+<br>
 int virNetDevTapCreateInBridgePort(const char *brname,<br>
                                    char **ifname,<br>
                                    const unsigned char *macaddr,<br>
-                                   bool discourage,<br>
-                                   int vnet_hdr,<br>
-                                   bool up,<br>
                                    int *tapfd,<br>
-                                   virNetDevVPortProfilePtr virtPortProfile)<br>
+                                   virNetDevVPortProfilePtr virtPortProfile,<br>
+                                   unsigned int flags)<br>
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)<br>
     ATTRIBUTE_RETURN_CHECK;<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
1.7.7.6<br>
<br>
--<br>
libvir-list mailing list<br>
<a href="mailto:libvir-list@redhat.com">libvir-list@redhat.com</a><br>
<a href="https://www.redhat.com/mailman/listinfo/libvir-list" target="_blank">https://www.redhat.com/mailman/listinfo/libvir-list</a><br>
</font></span></blockquote></div><div>Tested this patch together with 2/1 and it works fine for me. I will soon send out the 3/1 patch</div><div>that sets the vm-uuid.</div>