mirror of https://gitee.com/openkylin/libvirt.git
network: allow to specify timeout for openvswitch calls
This patchs allows to set the timeout value used for all openvswitch calls. The default timeout value remains as before at 5 seconds. Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com> Reviewed-by: Bjoern Walk <bwalk@linux.vnet.ibm.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
66583c0cf7
commit
f4d06ca8fd
|
@ -2078,6 +2078,7 @@ virNetDevOpenvswitchGetVhostuserIfname;
|
||||||
virNetDevOpenvswitchInterfaceStats;
|
virNetDevOpenvswitchInterfaceStats;
|
||||||
virNetDevOpenvswitchRemovePort;
|
virNetDevOpenvswitchRemovePort;
|
||||||
virNetDevOpenvswitchSetMigrateData;
|
virNetDevOpenvswitchSetMigrateData;
|
||||||
|
virNetDevOpenvswitchSetTimeout;
|
||||||
|
|
||||||
|
|
||||||
# util/virnetdevtap.h
|
# util/virnetdevtap.h
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2013 Red Hat, Inc.
|
* Copyright (C) 2013 Red Hat, Inc.
|
||||||
* Copyright (C) 2012 Nicira, Inc.
|
* Copyright (C) 2012 Nicira, Inc.
|
||||||
|
* Copyright (C) 2017 IBM Corporation
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
* Dan Wendlandt <dan@nicira.com>
|
* Dan Wendlandt <dan@nicira.com>
|
||||||
* Kyle Mestery <kmestery@cisco.com>
|
* Kyle Mestery <kmestery@cisco.com>
|
||||||
* Ansis Atteka <aatteka@nicira.com>
|
* Ansis Atteka <aatteka@nicira.com>
|
||||||
|
* Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
@ -38,6 +40,29 @@
|
||||||
|
|
||||||
VIR_LOG_INIT("util.netdevopenvswitch");
|
VIR_LOG_INIT("util.netdevopenvswitch");
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set openvswitch default timout
|
||||||
|
*/
|
||||||
|
static unsigned int virNetDevOpenvswitchTimeout = VIR_NETDEV_OVS_DEFAULT_TIMEOUT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* virNetDevOpenvswitchSetTimeout:
|
||||||
|
* @timeout: the timeout in seconds
|
||||||
|
*
|
||||||
|
* Set the openvswitch timeout
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
virNetDevOpenvswitchSetTimeout(unsigned int timeout)
|
||||||
|
{
|
||||||
|
virNetDevOpenvswitchTimeout = timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
virNetDevOpenvswitchAddTimeout(virCommandPtr cmd)
|
||||||
|
{
|
||||||
|
virCommandAddArgFormat(cmd, "--timeout=%u", virNetDevOpenvswitchTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* virNetDevOpenvswitchAddPort:
|
* virNetDevOpenvswitchAddPort:
|
||||||
* @brname: the bridge name
|
* @brname: the bridge name
|
||||||
|
@ -88,8 +113,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, const char *ifname,
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = virCommandNew(OVSVSCTL);
|
cmd = virCommandNew(OVSVSCTL);
|
||||||
|
virNetDevOpenvswitchAddTimeout(cmd);
|
||||||
virCommandAddArgList(cmd, "--timeout=5", "--", "--if-exists", "del-port",
|
virCommandAddArgList(cmd, "--", "--if-exists", "del-port",
|
||||||
ifname, "--", "add-port", brname, ifname, NULL);
|
ifname, "--", "add-port", brname, ifname, NULL);
|
||||||
|
|
||||||
if (virtVlan && virtVlan->nTags > 0) {
|
if (virtVlan && virtVlan->nTags > 0) {
|
||||||
|
@ -183,7 +208,8 @@ int virNetDevOpenvswitchRemovePort(const char *brname ATTRIBUTE_UNUSED, const ch
|
||||||
virCommandPtr cmd = NULL;
|
virCommandPtr cmd = NULL;
|
||||||
|
|
||||||
cmd = virCommandNew(OVSVSCTL);
|
cmd = virCommandNew(OVSVSCTL);
|
||||||
virCommandAddArgList(cmd, "--timeout=5", "--", "--if-exists", "del-port", ifname, NULL);
|
virNetDevOpenvswitchAddTimeout(cmd);
|
||||||
|
virCommandAddArgList(cmd, "--", "--if-exists", "del-port", ifname, NULL);
|
||||||
|
|
||||||
if (virCommandRun(cmd, NULL) < 0) {
|
if (virCommandRun(cmd, NULL) < 0) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
|
@ -212,8 +238,10 @@ int virNetDevOpenvswitchGetMigrateData(char **migrate, const char *ifname)
|
||||||
size_t len;
|
size_t len;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
cmd = virCommandNewArgList(OVSVSCTL, "--timeout=5", "--if-exists", "get", "Interface",
|
cmd = virCommandNew(OVSVSCTL);
|
||||||
ifname, "external_ids:PortData", NULL);
|
virNetDevOpenvswitchAddTimeout(cmd);
|
||||||
|
virCommandAddArgList(cmd, "--if-exists", "get", "Interface",
|
||||||
|
ifname, "external_ids:PortData", NULL);
|
||||||
|
|
||||||
virCommandSetOutputBuffer(cmd, migrate);
|
virCommandSetOutputBuffer(cmd, migrate);
|
||||||
|
|
||||||
|
@ -255,8 +283,9 @@ int virNetDevOpenvswitchSetMigrateData(char *migrate, const char *ifname)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = virCommandNewArgList(OVSVSCTL, "--timeout=5", "set",
|
cmd = virCommandNew(OVSVSCTL);
|
||||||
"Interface", ifname, NULL);
|
virNetDevOpenvswitchAddTimeout(cmd);
|
||||||
|
virCommandAddArgList(cmd, "set", "Interface", ifname, NULL);
|
||||||
virCommandAddArgFormat(cmd, "external_ids:PortData=%s", migrate);
|
virCommandAddArgFormat(cmd, "external_ids:PortData=%s", migrate);
|
||||||
|
|
||||||
/* Run the command */
|
/* Run the command */
|
||||||
|
@ -299,9 +328,9 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname,
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
/* Just ensure the interface exists in ovs */
|
/* Just ensure the interface exists in ovs */
|
||||||
cmd = virCommandNewArgList(OVSVSCTL, "--timeout=5",
|
cmd = virCommandNew(OVSVSCTL);
|
||||||
"get", "Interface", ifname,
|
virNetDevOpenvswitchAddTimeout(cmd);
|
||||||
"name", NULL);
|
virCommandAddArgList(cmd, "get", "Interface", ifname, "name", NULL);
|
||||||
virCommandSetOutputBuffer(cmd, &output);
|
virCommandSetOutputBuffer(cmd, &output);
|
||||||
|
|
||||||
if (virCommandRun(cmd, NULL) < 0) {
|
if (virCommandRun(cmd, NULL) < 0) {
|
||||||
|
@ -314,12 +343,13 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname,
|
||||||
VIR_FREE(output);
|
VIR_FREE(output);
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
|
|
||||||
cmd = virCommandNewArgList(OVSVSCTL, "--timeout=5",
|
cmd = virCommandNew(OVSVSCTL);
|
||||||
"get", "Interface", ifname,
|
virNetDevOpenvswitchAddTimeout(cmd);
|
||||||
"statistics:rx_bytes",
|
virCommandAddArgList(cmd, "get", "Interface", ifname,
|
||||||
"statistics:rx_packets",
|
"statistics:rx_bytes",
|
||||||
"statistics:tx_bytes",
|
"statistics:rx_packets",
|
||||||
"statistics:tx_packets", NULL);
|
"statistics:tx_bytes",
|
||||||
|
"statistics:tx_packets", NULL);
|
||||||
virCommandSetOutputBuffer(cmd, &output);
|
virCommandSetOutputBuffer(cmd, &output);
|
||||||
|
|
||||||
if (virCommandRun(cmd, NULL) < 0) {
|
if (virCommandRun(cmd, NULL) < 0) {
|
||||||
|
@ -345,12 +375,13 @@ virNetDevOpenvswitchInterfaceStats(const char *ifname,
|
||||||
VIR_FREE(output);
|
VIR_FREE(output);
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
|
|
||||||
cmd = virCommandNewArgList(OVSVSCTL, "--timeout=5",
|
cmd = virCommandNew(OVSVSCTL);
|
||||||
"get", "Interface", ifname,
|
virNetDevOpenvswitchAddTimeout(cmd);
|
||||||
"statistics:rx_errors",
|
virCommandAddArgList(cmd, "get", "Interface", ifname,
|
||||||
"statistics:rx_dropped",
|
"statistics:rx_errors",
|
||||||
"statistics:tx_errors",
|
"statistics:rx_dropped",
|
||||||
"statistics:tx_dropped", NULL);
|
"statistics:tx_errors",
|
||||||
|
"statistics:tx_dropped", NULL);
|
||||||
virCommandSetOutputBuffer(cmd, &output);
|
virCommandSetOutputBuffer(cmd, &output);
|
||||||
if (virCommandRun(cmd, NULL) < 0) {
|
if (virCommandRun(cmd, NULL) < 0) {
|
||||||
/* This interface don't have errors or dropped, so set them to 0 */
|
/* This interface don't have errors or dropped, so set them to 0 */
|
||||||
|
@ -399,6 +430,7 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path,
|
||||||
size_t ntokens = 0;
|
size_t ntokens = 0;
|
||||||
int status;
|
int status;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
char *ovs_timeout = NULL;
|
||||||
|
|
||||||
/* Openvswitch vhostuser path are hardcoded to
|
/* Openvswitch vhostuser path are hardcoded to
|
||||||
* /<runstatedir>/openvswitch/<ifname>
|
* /<runstatedir>/openvswitch/<ifname>
|
||||||
|
@ -412,8 +444,9 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path,
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = virCommandNewArgList(OVSVSCTL, "--timeout=5", "get", "Interface",
|
cmd = virCommandNew(OVSVSCTL);
|
||||||
tmpIfname, "name", NULL);
|
virNetDevOpenvswitchAddTimeout(cmd);
|
||||||
|
virCommandAddArgList(cmd, "get", "Interface", tmpIfname, "name", NULL);
|
||||||
if (virCommandRun(cmd, &status) < 0 ||
|
if (virCommandRun(cmd, &status) < 0 ||
|
||||||
status) {
|
status) {
|
||||||
/* it's not a openvswitch vhostuser interface. */
|
/* it's not a openvswitch vhostuser interface. */
|
||||||
|
@ -428,5 +461,6 @@ virNetDevOpenvswitchGetVhostuserIfname(const char *path,
|
||||||
cleanup:
|
cleanup:
|
||||||
virStringListFreeCount(tokens, ntokens);
|
virStringListFreeCount(tokens, ntokens);
|
||||||
virCommandFree(cmd);
|
virCommandFree(cmd);
|
||||||
|
VIR_FREE(ovs_timeout);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2013 Red Hat, Inc.
|
* Copyright (C) 2013 Red Hat, Inc.
|
||||||
* Copyright (C) 2012 Nicira, Inc.
|
* Copyright (C) 2012 Nicira, Inc.
|
||||||
|
* Copyright (C) 2017 IBM Corporation
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
@ -20,6 +21,7 @@
|
||||||
* Dan Wendlandt <dan@nicira.com>
|
* Dan Wendlandt <dan@nicira.com>
|
||||||
* Kyle Mestery <kmestery@cisco.com>
|
* Kyle Mestery <kmestery@cisco.com>
|
||||||
* Ansis Atteka <aatteka@nicira.com>
|
* Ansis Atteka <aatteka@nicira.com>
|
||||||
|
* Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __VIR_NETDEV_OPENVSWITCH_H__
|
#ifndef __VIR_NETDEV_OPENVSWITCH_H__
|
||||||
|
@ -31,6 +33,8 @@
|
||||||
|
|
||||||
# define VIR_NETDEV_OVS_DEFAULT_TIMEOUT 5
|
# define VIR_NETDEV_OVS_DEFAULT_TIMEOUT 5
|
||||||
|
|
||||||
|
void virNetDevOpenvswitchSetTimeout(unsigned int timeout);
|
||||||
|
|
||||||
int virNetDevOpenvswitchAddPort(const char *brname,
|
int virNetDevOpenvswitchAddPort(const char *brname,
|
||||||
const char *ifname,
|
const char *ifname,
|
||||||
const virMacAddr *macaddr,
|
const virMacAddr *macaddr,
|
||||||
|
|
Loading…
Reference in New Issue