mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 17:34:18 +03:00
virnetdev: move virNetDevSetRootQDisc to virnetdevbandwidth
The function in question uses "tc" binary so virnetdevbandwidth feels like better place for it. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
50a021df33
commit
18882ea776
@ -2714,7 +2714,6 @@ virNetDevSetOnline;
|
||||
virNetDevSetPromiscuous;
|
||||
virNetDevSetRcvAllMulti;
|
||||
virNetDevSetRcvMulti;
|
||||
virNetDevSetRootQDisc;
|
||||
virNetDevSetupControl;
|
||||
virNetDevSysfsFile;
|
||||
virNetDevValidateConfig;
|
||||
@ -2728,6 +2727,7 @@ virNetDevBandwidthEqual;
|
||||
virNetDevBandwidthFree;
|
||||
virNetDevBandwidthPlug;
|
||||
virNetDevBandwidthSet;
|
||||
virNetDevBandwidthSetRootQDisc;
|
||||
virNetDevBandwidthUnplug;
|
||||
virNetDevBandwidthUpdateFilter;
|
||||
virNetDevBandwidthUpdateRate;
|
||||
|
@ -50,6 +50,7 @@
|
||||
#include "domain_event.h"
|
||||
#include "domain_validate.h"
|
||||
#include "virtime.h"
|
||||
#include "virnetdevbandwidth.h"
|
||||
#include "virnetdevopenvswitch.h"
|
||||
#include "virstoragefile.h"
|
||||
#include "storage_source.h"
|
||||
@ -11571,7 +11572,7 @@ qemuDomainInterfaceSetDefaultQDisc(virQEMUDriver *driver,
|
||||
actualType == VIR_DOMAIN_NET_TYPE_NETWORK ||
|
||||
actualType == VIR_DOMAIN_NET_TYPE_BRIDGE ||
|
||||
actualType == VIR_DOMAIN_NET_TYPE_DIRECT) {
|
||||
if (virNetDevSetRootQDisc(net->ifname, "noqueue") < 0)
|
||||
if (virNetDevBandwidthSetRootQDisc(net->ifname, "noqueue") < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -3507,52 +3507,6 @@ virNetDevRunEthernetScript(const char *ifname, const char *script)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virNetDevSetRootQDisc:
|
||||
* @ifname: the interface name
|
||||
* @qdisc: queueing discipline to set
|
||||
*
|
||||
* For given interface @ifname set its root queueing discipline
|
||||
* to @qdisc. This can be used to replace the default qdisc
|
||||
* (usually pfifo_fast or whatever is set in
|
||||
* /proc/sys/net/core/default_qdisc) with different qdisc.
|
||||
*
|
||||
* Returns: 0 on success,
|
||||
* -1 if failed to exec tc (with error reported)
|
||||
* -2 if tc failed (with no error reported)
|
||||
*/
|
||||
int
|
||||
virNetDevSetRootQDisc(const char *ifname,
|
||||
const char *qdisc)
|
||||
{
|
||||
g_autoptr(virCommand) cmd = NULL;
|
||||
g_autofree char *outbuf = NULL;
|
||||
g_autofree char *errbuf = NULL;
|
||||
int status;
|
||||
|
||||
/* Ideally, we would have a netlink implementation and just
|
||||
* call it here. But honestly, I tried and failed miserably.
|
||||
* Fallback to spawning tc. */
|
||||
cmd = virCommandNewArgList(TC, "qdisc", "add", "dev", ifname,
|
||||
"root", "handle", "0:", qdisc,
|
||||
NULL);
|
||||
|
||||
virCommandAddEnvString(cmd, "LC_ALL=C");
|
||||
virCommandSetOutputBuffer(cmd, &outbuf);
|
||||
virCommandSetErrorBuffer(cmd, &errbuf);
|
||||
|
||||
if (virCommandRun(cmd, &status) < 0)
|
||||
return -1;
|
||||
|
||||
if (status != 0) {
|
||||
VIR_DEBUG("Setting qdisc failed: output='%s' err='%s'", outbuf, errbuf);
|
||||
return -2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* virNetDevReserveName:
|
||||
* @name: name of an existing network device
|
||||
|
@ -333,10 +333,6 @@ int virNetDevSysfsFile(char **pf_sysfs_device_link,
|
||||
int virNetDevRunEthernetScript(const char *ifname, const char *script)
|
||||
G_GNUC_NO_INLINE;
|
||||
|
||||
int virNetDevSetRootQDisc(const char *ifname,
|
||||
const char *qdisc)
|
||||
G_GNUC_NO_INLINE;
|
||||
|
||||
int virNetDevVFInterfaceStats(virPCIDeviceAddress *vfAddr,
|
||||
virDomainInterfaceStatsPtr stats)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
|
||||
|
@ -23,11 +23,14 @@
|
||||
#include "vircommand.h"
|
||||
#include "viralloc.h"
|
||||
#include "virerror.h"
|
||||
#include "virlog.h"
|
||||
#include "virstring.h"
|
||||
#include "virutil.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_NONE
|
||||
|
||||
VIR_LOG_INIT("util.netdevbandwidth");
|
||||
|
||||
void
|
||||
virNetDevBandwidthFree(virNetDevBandwidth *def)
|
||||
{
|
||||
@ -749,3 +752,50 @@ virNetDevBandwidthUpdateFilter(const char *ifname,
|
||||
VIR_FREE(class_id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* virNetDevBandwidthSetRootQDisc:
|
||||
* @ifname: the interface name
|
||||
* @qdisc: queueing discipline to set
|
||||
*
|
||||
* For given interface @ifname set its root queueing discipline
|
||||
* to @qdisc. This can be used to replace the default qdisc
|
||||
* (usually pfifo_fast or whatever is set in
|
||||
* /proc/sys/net/core/default_qdisc) with different qdisc.
|
||||
*
|
||||
* Returns: 0 on success,
|
||||
* -1 if failed to exec tc (with error reported)
|
||||
* -2 if tc failed (with no error reported)
|
||||
*/
|
||||
int
|
||||
virNetDevBandwidthSetRootQDisc(const char *ifname,
|
||||
const char *qdisc)
|
||||
{
|
||||
g_autoptr(virCommand) cmd = NULL;
|
||||
g_autofree char *outbuf = NULL;
|
||||
g_autofree char *errbuf = NULL;
|
||||
int status;
|
||||
|
||||
/* Ideally, we would have a netlink implementation and just
|
||||
* call it here. But honestly, I tried and failed miserably.
|
||||
* Fallback to spawning tc. */
|
||||
cmd = virCommandNewArgList(TC, "qdisc", "add", "dev", ifname,
|
||||
"root", "handle", "0:", qdisc,
|
||||
NULL);
|
||||
|
||||
virCommandAddEnvString(cmd, "LC_ALL=C");
|
||||
virCommandSetOutputBuffer(cmd, &outbuf);
|
||||
virCommandSetErrorBuffer(cmd, &errbuf);
|
||||
|
||||
if (virCommandRun(cmd, &status) < 0)
|
||||
return -1;
|
||||
|
||||
if (status != 0) {
|
||||
VIR_DEBUG("Setting qdisc failed: output='%s' err='%s'", outbuf, errbuf);
|
||||
return -2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -74,3 +74,7 @@ int virNetDevBandwidthUpdateFilter(const char *ifname,
|
||||
unsigned int id)
|
||||
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
|
||||
G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
int virNetDevBandwidthSetRootQDisc(const char *ifname,
|
||||
const char *qdisc)
|
||||
G_GNUC_NO_INLINE;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include "virmock.h"
|
||||
#include "virlog.h"
|
||||
#include "virnetdev.h"
|
||||
#include "virnetdevbandwidth.h"
|
||||
#include "virnetdevip.h"
|
||||
#include "virnetdevtap.h"
|
||||
#include "virnetdevopenvswitch.h"
|
||||
@ -277,8 +278,8 @@ qemuBuildTPMOpenBackendFDs(const char *tpmdev G_GNUC_UNUSED,
|
||||
|
||||
|
||||
int
|
||||
virNetDevSetRootQDisc(const char *ifname G_GNUC_UNUSED,
|
||||
const char *qdisc G_GNUC_UNUSED)
|
||||
virNetDevBandwidthSetRootQDisc(const char *ifname G_GNUC_UNUSED,
|
||||
const char *qdisc G_GNUC_UNUSED)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user