]> xenbits.xensource.com Git - libvirt.git/commitdiff
Attach vm-id to Open vSwitch interfaces.
authorAnsis Atteka <aatteka@nicira.com>
Wed, 7 Mar 2012 07:15:36 +0000 (23:15 -0800)
committerLaine Stump <laine@laine.org>
Thu, 8 Mar 2012 19:44:15 +0000 (14:44 -0500)
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-id="142a90a7-0acc-ab92-511c-586f12da8851"}

V2 changes:
Replaced vm-uuid with vm-id. There was a discussion in Open vSwitch
mailinglist that we should stick with the same DB key postfixes for the
sake of consistency (e.g iface-id, vm-id ...).

src/lxc/lxc_driver.c
src/network/bridge_driver.c
src/qemu/qemu_command.c
src/uml/uml_conf.c
src/util/virnetdevopenvswitch.c
src/util/virnetdevopenvswitch.h
src/util/virnetdevtap.c
src/util/virnetdevtap.h

index 1a0e4586fe2cd83098bfa4a59c64e1f7a5441ab5..3af8084e7a4eb388d228cc00ac7a209e602a3136 100644 (file)
@@ -1199,7 +1199,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)
index cf75d2614bf59e2a8126c0df0af13bb9078a65fd..d82212f91d5c8e5499f4685dfbdbab92393cce11 100644 (file)
@@ -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;
index de2d4a1bd16575a3b06a0efd56fa1c231d3ca5b5..d95064f85aabb8f7e8c9e48c78a5fe3a53658fb6 100644 (file)
@@ -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);
index 7bd97083c4e4b30e79bbeb7636a0018c37aa2b5b..79b249d82ed967ded555b80872e5a8ffe3a41cb2 100644 (file)
@@ -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)
index 9d6d924ac7be4a57c748d6464047726485eb65bc..e2d5124b80285b2e5f1f2586b8e0550b47d199f0 100644 (file)
@@ -36,6 +36,7 @@
  * @brname: the bridge name
  * @ifname: the network interface name
  * @macaddr: the mac address of the virtual interface
+ * @vmuuid: the Domain UUID that has this interface
  * @ovsport: the ovs specific fields
  *
  * Add an interface to the OVS bridge
  */
 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 ifuuidstr[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 *vmid_ex_id = NULL;
 
     virMacAddrFormat(macaddr, macaddrstr);
-    virUUIDFormat(ovsport->u.openvswitch.interfaceID, uuidstr);
+    virUUIDFormat(ovsport->u.openvswitch.interfaceID, ifuuidstr);
+    virUUIDFormat(vmuuid, vmuuidstr);
 
     if (virAsprintf(&attachedmac_ex_id, "external-ids:attached-mac=\"%s\"",
                     macaddrstr) < 0)
         goto cleanup;
     if (virAsprintf(&ifaceid_ex_id, "external-ids:iface-id=\"%s\"",
-                    uuidstr) < 0)
+                    ifuuidstr) < 0)
+        goto cleanup;
+    if (virAsprintf(&vmid_ex_id, "external-ids:vm-id=\"%s\"",
+                    vmuuidstr) < 0)
         goto cleanup;
     if (ovsport->u.openvswitch.profileID[0] != '\0') {
         if (virAsprintf(&profile_ex_id, "external-ids:port-profile=\"%s\"",
@@ -75,6 +83,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, vmid_ex_id,
                         "--", "set", "Interface", ifname,
                         "external-ids:iface-status=active",
                         NULL);
@@ -83,6 +92,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, vmid_ex_id,
                         "--", "set", "Interface", ifname, profile_ex_id,
                         "--", "set", "Interface", ifname,
                         "external-ids:iface-status=active",
@@ -100,6 +110,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
 cleanup:
     VIR_FREE(attachedmac_ex_id);
     VIR_FREE(ifaceid_ex_id);
+    VIR_FREE(vmid_ex_id);
     VIR_FREE(profile_ex_id);
     virCommandFree(cmd);
     return ret;
index bca4c3ef6718112ee5b6f87e6a3d1676c56379fe..8141780cc138d1b67934b83b3dd34a695c07d4d3 100644 (file)
@@ -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;
index fb0a8d244b3259452c0a0e4930036db7682d7403..84a8a1ccd073689e9bb3e213b5ad21e7c642bfd4 100644 (file)
@@ -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;
         }
index 971b166460c845511b30a40ca2ed64e7a07f0327..d9a3593407687d96f123a4181021a08300433029 100644 (file)
@@ -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)