mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
virnetdevopenvswitch: Simplify OVS_VSCTL cmd creation
Every time we create new virCommand of OVS_VSCTL it must be followed by virNetDevOpenvswitchAddTimeout() call which adds the --timeout=X argument to freshly created cmd. Instead of having this as two separate function calls it can be just one. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
e4c29e2904
commit
2d5b106cf8
@ -51,10 +51,12 @@ virNetDevOpenvswitchSetTimeout(unsigned int timeout)
|
|||||||
virNetDevOpenvswitchTimeout = timeout;
|
virNetDevOpenvswitchTimeout = timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static virCommandPtr
|
||||||
virNetDevOpenvswitchAddTimeout(virCommandPtr cmd)
|
virNetDevOpenvswitchCreateCmd(void)
|
||||||
{
|
{
|
||||||
|
virCommandPtr cmd = virCommandNew(OVS_VSCTL);
|
||||||
virCommandAddArgFormat(cmd, "--timeout=%u", virNetDevOpenvswitchTimeout);
|
virCommandAddArgFormat(cmd, "--timeout=%u", virNetDevOpenvswitchTimeout);
|
||||||
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -151,8 +153,7 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
|
|||||||
ovsport->profileID);
|
ovsport->profileID);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = virCommandNew(OVS_VSCTL);
|
cmd = virNetDevOpenvswitchCreateCmd();
|
||||||
virNetDevOpenvswitchAddTimeout(cmd);
|
|
||||||
virCommandAddArgList(cmd, "--", "--if-exists", "del-port",
|
virCommandAddArgList(cmd, "--", "--if-exists", "del-port",
|
||||||
ifname, "--", "add-port", brname, ifname, NULL);
|
ifname, "--", "add-port", brname, ifname, NULL);
|
||||||
|
|
||||||
@ -197,10 +198,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
|
|||||||
*/
|
*/
|
||||||
int virNetDevOpenvswitchRemovePort(const char *brname G_GNUC_UNUSED, const char *ifname)
|
int virNetDevOpenvswitchRemovePort(const char *brname G_GNUC_UNUSED, const char *ifname)
|
||||||
{
|
{
|
||||||
g_autoptr(virCommand) cmd = NULL;
|
g_autoptr(virCommand) cmd = virNetDevOpenvswitchCreateCmd();
|
||||||
|
|
||||||
cmd = virCommandNew(OVS_VSCTL);
|
|
||||||
virNetDevOpenvswitchAddTimeout(cmd);
|
|
||||||
virCommandAddArgList(cmd, "--", "--if-exists", "del-port", ifname, NULL);
|
virCommandAddArgList(cmd, "--", "--if-exists", "del-port", ifname, NULL);
|
||||||
|
|
||||||
if (virCommandRun(cmd, NULL) < 0) {
|
if (virCommandRun(cmd, NULL) < 0) {
|
||||||
@ -224,10 +223,8 @@ int virNetDevOpenvswitchRemovePort(const char *brname G_GNUC_UNUSED, const char
|
|||||||
int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname)
|
int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
g_autoptr(virCommand) cmd = NULL;
|
g_autoptr(virCommand) cmd = virNetDevOpenvswitchCreateCmd();
|
||||||
|
|
||||||
cmd = virCommandNew(OVS_VSCTL);
|
|
||||||
virNetDevOpenvswitchAddTimeout(cmd);
|
|
||||||
virCommandAddArgList(cmd, "--if-exists", "get", "Interface",
|
virCommandAddArgList(cmd, "--if-exists", "get", "Interface",
|
||||||
ifname, "external_ids:PortData", NULL);
|
ifname, "external_ids:PortData", NULL);
|
||||||
|
|
||||||
@ -267,8 +264,7 @@ int virNetDevOpenvswitchSetMigrateData(char *migrate, const char *ifname)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = virCommandNew(OVS_VSCTL);
|
cmd = virNetDevOpenvswitchCreateCmd();
|
||||||
virNetDevOpenvswitchAddTimeout(cmd);
|
|
||||||
virCommandAddArgList(cmd, "set", "Interface", ifname, NULL);
|
virCommandAddArgList(cmd, "set", "Interface", ifname, NULL);
|
||||||
virCommandAddArgFormat(cmd, "external_ids:PortData=%s", migrate);
|
virCommandAddArgFormat(cmd, "external_ids:PortData=%s", migrate);
|
||||||
|
|
||||||
@ -370,11 +366,9 @@ int
|
|||||||
virNetDevOpenvswitchInterfaceStats(const char *ifname,
|
virNetDevOpenvswitchInterfaceStats(const char *ifname,
|
||||||
virDomainInterfaceStatsPtr stats)
|
virDomainInterfaceStatsPtr stats)
|
||||||
{
|
{
|
||||||
g_autoptr(virCommand) cmd = NULL;
|
g_autoptr(virCommand) cmd = virNetDevOpenvswitchCreateCmd();
|
||||||
g_autofree char *output = NULL;
|
g_autofree char *output = NULL;
|
||||||
|
|
||||||
cmd = virCommandNew(OVS_VSCTL);
|
|
||||||
virNetDevOpenvswitchAddTimeout(cmd);
|
|
||||||
virCommandAddArgList(cmd, "--if-exists", "--format=list", "--data=json",
|
virCommandAddArgList(cmd, "--if-exists", "--format=list", "--data=json",
|
||||||
"--no-headings", "--columns=statistics", "list",
|
"--no-headings", "--columns=statistics", "list",
|
||||||
"Interface", ifname, NULL);
|
"Interface", ifname, NULL);
|
||||||
@ -434,13 +428,11 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname,
|
|||||||
int
|
int
|
||||||
virNetDevOpenvswitchInterfaceGetMaster(const char *ifname, char **master)
|
virNetDevOpenvswitchInterfaceGetMaster(const char *ifname, char **master)
|
||||||
{
|
{
|
||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = virNetDevOpenvswitchCreateCmd();
|
||||||
int exitstatus;
|
int exitstatus;
|
||||||
|
|
||||||
*master = NULL;
|
*master = NULL;
|
||||||
|
|
||||||
cmd = virCommandNew(OVS_VSCTL);
|
|
||||||
virNetDevOpenvswitchAddTimeout(cmd);
|
|
||||||
virCommandAddArgList(cmd, "iface-to-br", ifname, NULL);
|
virCommandAddArgList(cmd, "iface-to-br", ifname, NULL);
|
||||||
virCommandSetOutputBuffer(cmd, master);
|
virCommandSetOutputBuffer(cmd, master);
|
||||||
|
|
||||||
@ -495,11 +487,9 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path,
|
|||||||
bool server,
|
bool server,
|
||||||
char **ifname)
|
char **ifname)
|
||||||
{
|
{
|
||||||
g_autoptr(virCommand) cmd = NULL;
|
g_autoptr(virCommand) cmd = virNetDevOpenvswitchCreateCmd();
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
cmd = virCommandNew(OVS_VSCTL);
|
|
||||||
virNetDevOpenvswitchAddTimeout(cmd);
|
|
||||||
|
|
||||||
if (server) {
|
if (server) {
|
||||||
virCommandAddArgList(cmd, "--no-headings", "--columns=name", "find",
|
virCommandAddArgList(cmd, "--no-headings", "--columns=name", "find",
|
||||||
@ -547,10 +537,8 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path,
|
|||||||
int virNetDevOpenvswitchUpdateVlan(const char *ifname,
|
int virNetDevOpenvswitchUpdateVlan(const char *ifname,
|
||||||
const virNetDevVlan *virtVlan)
|
const virNetDevVlan *virtVlan)
|
||||||
{
|
{
|
||||||
g_autoptr(virCommand) cmd = NULL;
|
g_autoptr(virCommand) cmd = virNetDevOpenvswitchCreateCmd();
|
||||||
|
|
||||||
cmd = virCommandNew(OVS_VSCTL);
|
|
||||||
virNetDevOpenvswitchAddTimeout(cmd);
|
|
||||||
virCommandAddArgList(cmd,
|
virCommandAddArgList(cmd,
|
||||||
"--", "--if-exists", "clear", "Port", ifname, "tag",
|
"--", "--if-exists", "clear", "Port", ifname, "tag",
|
||||||
"--", "--if-exists", "clear", "Port", ifname, "trunk",
|
"--", "--if-exists", "clear", "Port", ifname, "trunk",
|
||||||
|
Loading…
Reference in New Issue
Block a user