mirror of https://gitee.com/openkylin/libvirt.git
openvswitch: Add utility functions for getting and setting Open vSwitch per-port data
Add utility functions for Open vSwitch to both save per-port data before a live migration, and restore the per-port data after a live migration. Signed-off-by: Kyle Mestery <kmestery@cisco.com>
This commit is contained in:
parent
694d0c520b
commit
f6a2f97eb9
|
@ -1500,7 +1500,9 @@ virNetDevMacVLanVPortProfileRegisterCallback;
|
||||||
|
|
||||||
# virnetdevopenvswitch.h
|
# virnetdevopenvswitch.h
|
||||||
virNetDevOpenvswitchAddPort;
|
virNetDevOpenvswitchAddPort;
|
||||||
|
virNetDevOpenvswitchGetMigrateData;
|
||||||
virNetDevOpenvswitchRemovePort;
|
virNetDevOpenvswitchRemovePort;
|
||||||
|
virNetDevOpenvswitchSetMigrateData;
|
||||||
|
|
||||||
|
|
||||||
# virnetdevtap.h
|
# virnetdevtap.h
|
||||||
|
|
|
@ -173,9 +173,74 @@ int virNetDevOpenvswitchRemovePort(const char *brname ATTRIBUTE_UNUSED, const ch
|
||||||
_("Unable to delete port %s from OVS"), ifname);
|
_("Unable to delete port %s from OVS"), ifname);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
ret = 0;
|
||||||
virCommandFree(cmd);
|
cleanup:
|
||||||
return ret;
|
virCommandFree(cmd);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virNetDevOpenvswitchGetMigrateData:
|
||||||
|
* @migrate: a pointer to store the data into, allocated by this function
|
||||||
|
* @ifname: name of the interface for which data is being migrated
|
||||||
|
*
|
||||||
|
* Allocates data to be migrated specific to Open vSwitch
|
||||||
|
*
|
||||||
|
* Returns 0 in case of success or -1 in case of failure
|
||||||
|
*/
|
||||||
|
int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname)
|
||||||
|
{
|
||||||
|
virCommandPtr cmd = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
cmd = virCommandNewArgList(OVSVSCTL, "--timeout=5", "get", "Interface",
|
||||||
|
ifname, "external_ids:PortData", NULL);
|
||||||
|
|
||||||
|
virCommandSetOutputBuffer(cmd, migrate);
|
||||||
|
|
||||||
|
/* Run the command */
|
||||||
|
if (virCommandRun(cmd, NULL) < 0) {
|
||||||
|
virReportSystemError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Unable to run command to get OVS port data for "
|
||||||
|
"interface %s"), ifname);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wipeout the newline */
|
||||||
|
(*migrate)[strlen(*migrate) - 1] = '\0';
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virNetDevOpenvswitchSetMigrateData:
|
||||||
|
* @migrate: the data which was transferred during migration
|
||||||
|
* @ifname: the name of the interface the data is associated with
|
||||||
|
*
|
||||||
|
* Repopulates OVS per-port data on destination host
|
||||||
|
*
|
||||||
|
* Returns 0 in case of success or -1 in case of failure
|
||||||
|
*/
|
||||||
|
int virNetDevOpenvswitchSetMigrateData(char *migrate, const char *ifname)
|
||||||
|
{
|
||||||
|
virCommandPtr cmd = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
cmd = virCommandNewArgList(OVSVSCTL, "--timeout=5", "set",
|
||||||
|
"Interface", ifname, NULL);
|
||||||
|
virCommandAddArgFormat(cmd, "external_ids:PortData=%s", migrate);
|
||||||
|
|
||||||
|
/* Run the command */
|
||||||
|
if (virCommandRun(cmd, NULL) < 0) {
|
||||||
|
virReportSystemError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
_("Unable to run command to set OVS port data for "
|
||||||
|
"interface %s"), ifname);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
cleanup:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,4 +42,10 @@ int virNetDevOpenvswitchAddPort(const char *brname,
|
||||||
int virNetDevOpenvswitchRemovePort(const char *brname, const char *ifname)
|
int virNetDevOpenvswitchRemovePort(const char *brname, const char *ifname)
|
||||||
ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
|
int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
|
int virNetDevOpenvswitchSetMigrateData(char *migrate, const char *ifname)
|
||||||
|
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
|
||||||
|
|
||||||
#endif /* __VIR_NETDEV_OPENVSWITCH_H__ */
|
#endif /* __VIR_NETDEV_OPENVSWITCH_H__ */
|
||||||
|
|
Loading…
Reference in New Issue