提交 ac8bbdbd 编写于 作者: A Ansis Atteka 提交者: Laine Stump

Attach vm-id to Open vSwitch interfaces.

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 ...).
上级 38e56abb
......@@ -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)
......
......@@ -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;
......
......@@ -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);
......
......@@ -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)
......
......@@ -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
......@@ -44,24 +45,31 @@
*/
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;
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册