[PATCH] Attach vm-uuid to Open vSwitch interfaces.

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

 



This patch will allow OpenFlow controllers to identify which interface
belongs to a particular VM by using the Domain UUID.

ovs-vsctl get Interface vnet0 external_ids
{attached-mac="52:54:00:8C:55:2C", iface-id="83ce45d6-3639-096e-ab3c-21f66a05f7fa", iface-status=active, vm-uuid="142a90a7-0acc-ab92-511c-586f12da8851"}
---
 src/lxc/lxc_driver.c            |    3 ++-
 src/network/bridge_driver.c     |    2 +-
 src/qemu/qemu_command.c         |    3 ++-
 src/uml/uml_conf.c              |    3 ++-
 src/util/virnetdevopenvswitch.c |   10 ++++++++++
 src/util/virnetdevopenvswitch.h |    1 +
 src/util/virnetdevtap.c         |    3 ++-
 src/util/virnetdevtap.h         |    1 +
 8 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index d9cbd9e..3a55983 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1197,7 +1197,8 @@ static int lxcSetupInterfaceBridged(virConnectPtr conn,
         goto cleanup;
 
     if (vport && vport->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH)
-        ret = virNetDevOpenvswitchAddPort(brname, parentVeth, net->mac, vport);
+        ret = virNetDevOpenvswitchAddPort(brname, parentVeth, net->mac,
+                                          vm->uuid, vport);
     else
         ret = virNetDevBridgeAddPort(brname, parentVeth);
     if (ret < 0)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index cf75d26..d82212f 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -1766,7 +1766,7 @@ networkStartNetworkVirtual(struct network_driver *driver,
         }
         if (virNetDevTapCreateInBridgePort(network->def->bridge,
                                            &macTapIfName, network->def->mac,
-                                           NULL, NULL,
+                                           NULL, NULL, NULL,
                                            VIR_NETDEV_TAP_CREATE_USE_MAC_FOR_BRIDGE) < 0) {
             VIR_FREE(macTapIfName);
             goto err0;
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index acfd38c..5cd70f2 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -244,7 +244,8 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
         tap_create_flags |= VIR_NETDEV_TAP_CREATE_VNET_HDR;
     }
 
-    err = virNetDevTapCreateInBridgePort(brname, &net->ifname, net->mac, &tapfd,
+    err = virNetDevTapCreateInBridgePort(brname, &net->ifname, net->mac,
+                                         def->uuid, &tapfd,
                                          virDomainNetGetActualVirtPortProfile(net),
                                          tap_create_flags);
     virDomainAuditNetDevice(def, net, "/dev/net/tun", tapfd >= 0);
diff --git a/src/uml/uml_conf.c b/src/uml/uml_conf.c
index 89fdd9f..18836f5 100644
--- a/src/uml/uml_conf.c
+++ b/src/uml/uml_conf.c
@@ -138,7 +138,8 @@ umlConnectTapDevice(virConnectPtr conn,
         template_ifname = true;
     }
 
-    if (virNetDevTapCreateInBridgePort(bridge, &net->ifname, net->mac, NULL,
+    if (virNetDevTapCreateInBridgePort(bridge, &net->ifname, net->mac,
+                                       vm->uuid, NULL,
                                        virDomainNetGetActualVirtPortProfile(net),
                                        VIR_NETDEV_TAP_CREATE_IFUP) < 0) {
         if (template_ifname)
diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c
index e427c94..5e40d26 100644
--- a/src/util/virnetdevopenvswitch.c
+++ b/src/util/virnetdevopenvswitch.c
@@ -44,18 +44,22 @@
  */
 int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
                                    const unsigned char *macaddr,
+                                   const unsigned char *vmuuid,
                                    virNetDevVPortProfilePtr ovsport)
 {
     int ret = -1;
     virCommandPtr cmd = NULL;
     char macaddrstr[VIR_MAC_STRING_BUFLEN];
     char uuidstr[VIR_UUID_STRING_BUFLEN];
+    char vmuuidstr[VIR_UUID_STRING_BUFLEN];
     char *attachedmac_ex_id = NULL;
     char *ifaceid_ex_id = NULL;
     char *profile_ex_id = NULL;
+    char *vmuuid_ex_id = NULL;
 
     virMacAddrFormat(macaddr, macaddrstr);
     virUUIDFormat(ovsport->u.openvswitch.interfaceID, uuidstr);
+    virUUIDFormat(vmuuid, vmuuidstr);
 
     if (virAsprintf(&attachedmac_ex_id, "external-ids:attached-mac=\"%s\"",
                     macaddrstr) < 0)
@@ -63,6 +67,9 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
     if (virAsprintf(&ifaceid_ex_id, "external-ids:iface-id=\"%s\"",
                     uuidstr) < 0)
         goto cleanup;
+    if (virAsprintf(&vmuuid_ex_id, "external-ids:vm-uuid=\"%s\"",
+                    vmuuidstr) < 0)
+        goto cleanup;
     if (ovsport->u.openvswitch.profileID[0] != '\0') {
         if (virAsprintf(&profile_ex_id, "external-ids:port-profile=\"%s\"",
                         ovsport->u.openvswitch.profileID) < 0)
@@ -75,6 +82,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
                         brname, ifname,
                         "--", "set", "Interface", ifname, attachedmac_ex_id,
                         "--", "set", "Interface", ifname, ifaceid_ex_id,
+                        "--", "set", "Interface", ifname, vmuuid_ex_id,
                         "--", "set", "Interface", ifname,
                         "external-ids:iface-status=active",
                         NULL);
@@ -83,6 +91,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
                         brname, ifname,
                         "--", "set", "Interface", ifname, attachedmac_ex_id,
                         "--", "set", "Interface", ifname, ifaceid_ex_id,
+                        "--", "set", "Interface", ifname, vmuuid_ex_id,
                         "--", "set", "Interface", ifname, profile_ex_id,
                         "--", "set", "Interface", ifname,
                         "external-ids:iface-status=active",
@@ -100,6 +109,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
     cleanup:
         VIR_FREE(attachedmac_ex_id);
         VIR_FREE(ifaceid_ex_id);
+        VIR_FREE(vmuuid_ex_id);
         VIR_FREE(profile_ex_id);
         virCommandFree(cmd);
         return ret;
diff --git a/src/util/virnetdevopenvswitch.h b/src/util/virnetdevopenvswitch.h
index bca4c3e..8141780 100644
--- a/src/util/virnetdevopenvswitch.h
+++ b/src/util/virnetdevopenvswitch.h
@@ -32,6 +32,7 @@
 int virNetDevOpenvswitchAddPort(const char *brname,
                                 const char *ifname,
                                 const unsigned char *macaddr,
+                                const unsigned char *vmuuid,
                                 virNetDevVPortProfilePtr ovsport)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
     ATTRIBUTE_RETURN_CHECK;
diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c
index fb0a8d2..84a8a1c 100644
--- a/src/util/virnetdevtap.c
+++ b/src/util/virnetdevtap.c
@@ -277,6 +277,7 @@ int virNetDevTapDelete(const char *ifname ATTRIBUTE_UNUSED)
 int virNetDevTapCreateInBridgePort(const char *brname,
                                    char **ifname,
                                    const unsigned char *macaddr,
+                                   const unsigned char *vmuuid,
                                    int *tapfd,
                                    virNetDevVPortProfilePtr virtPortProfile,
                                    unsigned int flags)
@@ -307,7 +308,7 @@ int virNetDevTapCreateInBridgePort(const char *brname,
         goto error;
 
     if (virtPortProfile) {
-        if (virNetDevOpenvswitchAddPort(brname, *ifname, macaddr,
+        if (virNetDevOpenvswitchAddPort(brname, *ifname, macaddr, vmuuid,
                                         virtPortProfile) < 0) {
             goto error;
         }
diff --git a/src/util/virnetdevtap.h b/src/util/virnetdevtap.h
index 971b166..d9a3593 100644
--- a/src/util/virnetdevtap.h
+++ b/src/util/virnetdevtap.h
@@ -47,6 +47,7 @@ typedef enum {
 int virNetDevTapCreateInBridgePort(const char *brname,
                                    char **ifname,
                                    const unsigned char *macaddr,
+                                   const unsigned char *vmuuid,
                                    int *tapfd,
                                    virNetDevVPortProfilePtr virtPortProfile,
                                    unsigned int flags)
-- 
1.7.5.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]