mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 21:55:25 +00:00
virDomainInterfaceStats: Accept MAC address too
https://bugzilla.redhat.com/show_bug.cgi?id=1497396 The other APIs accept both, ifname and MAC address. There's no reason virDomainInterfaceStats can't do the same. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
e3909729d2
commit
0d3d020ba6
@ -1571,7 +1571,7 @@ int virDomainBlockStatsFlags (virDomainPtr dom,
|
||||
int *nparams,
|
||||
unsigned int flags);
|
||||
int virDomainInterfaceStats (virDomainPtr dom,
|
||||
const char *path,
|
||||
const char *device,
|
||||
virDomainInterfaceStatsPtr stats,
|
||||
size_t size);
|
||||
|
||||
|
@ -486,7 +486,7 @@ typedef int
|
||||
|
||||
typedef int
|
||||
(*virDrvDomainInterfaceStats)(virDomainPtr domain,
|
||||
const char *path,
|
||||
const char *device,
|
||||
virDomainInterfaceStatsPtr stats);
|
||||
|
||||
typedef int
|
||||
|
@ -5507,14 +5507,15 @@ virDomainBlockStatsFlags(virDomainPtr dom,
|
||||
/**
|
||||
* virDomainInterfaceStats:
|
||||
* @dom: pointer to the domain object
|
||||
* @path: path to the interface
|
||||
* @device: the interface name or MAC address
|
||||
* @stats: network interface stats (returned)
|
||||
* @size: size of stats structure
|
||||
*
|
||||
* This function returns network interface stats for interfaces
|
||||
* attached to the domain.
|
||||
*
|
||||
* The path parameter is the name of the network interface.
|
||||
* The @device parameter is the network interface either by name or MAC
|
||||
* address.
|
||||
*
|
||||
* Domains may have more than one network interface. To get stats for
|
||||
* each you should make multiple calls to this function.
|
||||
@ -5528,20 +5529,20 @@ virDomainBlockStatsFlags(virDomainPtr dom,
|
||||
* Returns: 0 in case of success or -1 in case of failure.
|
||||
*/
|
||||
int
|
||||
virDomainInterfaceStats(virDomainPtr dom, const char *path,
|
||||
virDomainInterfaceStats(virDomainPtr dom, const char *device,
|
||||
virDomainInterfaceStatsPtr stats, size_t size)
|
||||
{
|
||||
virConnectPtr conn;
|
||||
virDomainInterfaceStatsStruct stats2 = { -1, -1, -1, -1,
|
||||
-1, -1, -1, -1 };
|
||||
|
||||
VIR_DOMAIN_DEBUG(dom, "path=%s, stats=%p, size=%zi",
|
||||
path, stats, size);
|
||||
VIR_DOMAIN_DEBUG(dom, "device=%s, stats=%p, size=%zi",
|
||||
device, stats, size);
|
||||
|
||||
virResetLastError();
|
||||
|
||||
virCheckDomainReturn(dom, -1);
|
||||
virCheckNonNullArgGoto(path, error);
|
||||
virCheckNonNullArgGoto(device, error);
|
||||
virCheckNonNullArgGoto(stats, error);
|
||||
if (size > sizeof(stats2)) {
|
||||
virReportInvalidArg(size,
|
||||
@ -5553,7 +5554,7 @@ virDomainInterfaceStats(virDomainPtr dom, const char *path,
|
||||
conn = dom->conn;
|
||||
|
||||
if (conn->driver->domainInterfaceStats) {
|
||||
if (conn->driver->domainInterfaceStats(dom, path, &stats2) == -1)
|
||||
if (conn->driver->domainInterfaceStats(dom, device, &stats2) == -1)
|
||||
goto error;
|
||||
|
||||
memcpy(stats, &stats2, size);
|
||||
|
@ -4956,7 +4956,7 @@ libxlDomainIsUpdated(virDomainPtr dom)
|
||||
|
||||
static int
|
||||
libxlDomainInterfaceStats(virDomainPtr dom,
|
||||
const char *path,
|
||||
const char *device,
|
||||
virDomainInterfaceStatsPtr stats)
|
||||
{
|
||||
libxlDriverPrivatePtr driver = dom->conn->privateData;
|
||||
@ -4979,10 +4979,10 @@ libxlDomainInterfaceStats(virDomainPtr dom,
|
||||
goto endjob;
|
||||
}
|
||||
|
||||
if (!(net = virDomainNetFindByName(vm->def, path)))
|
||||
if (!(net = virDomainNetFind(vm->def, device)))
|
||||
goto endjob;
|
||||
|
||||
if (virNetDevTapInterfaceStats(path, stats,
|
||||
if (virNetDevTapInterfaceStats(device, stats,
|
||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||
goto endjob;
|
||||
|
||||
|
@ -2849,7 +2849,7 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
|
||||
|
||||
static int
|
||||
lxcDomainInterfaceStats(virDomainPtr dom,
|
||||
const char *path,
|
||||
const char *device,
|
||||
virDomainInterfaceStatsPtr stats)
|
||||
{
|
||||
virDomainObjPtr vm;
|
||||
@ -2872,10 +2872,10 @@ lxcDomainInterfaceStats(virDomainPtr dom,
|
||||
goto endjob;
|
||||
}
|
||||
|
||||
if (!(net = virDomainNetFindByName(vm->def, path)))
|
||||
if (!(net = virDomainNetFind(vm->def, device)))
|
||||
goto endjob;
|
||||
|
||||
if (virNetDevTapInterfaceStats(path, stats,
|
||||
if (virNetDevTapInterfaceStats(device, stats,
|
||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||
goto endjob;
|
||||
|
||||
|
@ -1980,7 +1980,7 @@ openvzGetVEStatus(virDomainObjPtr vm, int *status, int *reason)
|
||||
|
||||
static int
|
||||
openvzDomainInterfaceStats(virDomainPtr dom,
|
||||
const char *path,
|
||||
const char *device,
|
||||
virDomainInterfaceStatsPtr stats)
|
||||
{
|
||||
struct openvz_driver *driver = dom->conn->privateData;
|
||||
@ -2006,10 +2006,10 @@ openvzDomainInterfaceStats(virDomainPtr dom,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(net = virDomainNetFindByName(vm->def, path)))
|
||||
if (!(net = virDomainNetFind(vm->def, device)))
|
||||
goto cleanup;
|
||||
|
||||
if (virNetDevTapInterfaceStats(path, stats,
|
||||
if (virNetDevTapInterfaceStats(device, stats,
|
||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
|
@ -11021,7 +11021,7 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
|
||||
|
||||
static int
|
||||
qemuDomainInterfaceStats(virDomainPtr dom,
|
||||
const char *path,
|
||||
const char *device,
|
||||
virDomainInterfaceStatsPtr stats)
|
||||
{
|
||||
virDomainObjPtr vm;
|
||||
@ -11040,14 +11040,14 @@ qemuDomainInterfaceStats(virDomainPtr dom,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (!(net = virDomainNetFindByName(vm->def, path)))
|
||||
if (!(net = virDomainNetFind(vm->def, device)))
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
|
||||
if (virNetDevOpenvswitchInterfaceStats(path, stats) < 0)
|
||||
if (virNetDevOpenvswitchInterfaceStats(device, stats) < 0)
|
||||
goto cleanup;
|
||||
} else {
|
||||
if (virNetDevTapInterfaceStats(path, stats,
|
||||
if (virNetDevTapInterfaceStats(device, stats,
|
||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
@ -682,7 +682,7 @@ struct remote_domain_block_stats_flags_ret {
|
||||
|
||||
struct remote_domain_interface_stats_args {
|
||||
remote_nonnull_domain dom;
|
||||
remote_nonnull_string path;
|
||||
remote_nonnull_string device;
|
||||
};
|
||||
|
||||
struct remote_domain_interface_stats_ret { /* insert@2 */
|
||||
|
@ -348,7 +348,7 @@ struct remote_domain_block_stats_flags_ret {
|
||||
};
|
||||
struct remote_domain_interface_stats_args {
|
||||
remote_nonnull_domain dom;
|
||||
remote_nonnull_string path;
|
||||
remote_nonnull_string device;
|
||||
};
|
||||
struct remote_domain_interface_stats_ret {
|
||||
int64_t rx_bytes;
|
||||
|
@ -3160,8 +3160,9 @@ static int testDomainBlockStats(virDomainPtr domain,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int testDomainInterfaceStats(virDomainPtr domain,
|
||||
const char *path,
|
||||
static int
|
||||
testDomainInterfaceStats(virDomainPtr domain,
|
||||
const char *device,
|
||||
virDomainInterfaceStatsPtr stats)
|
||||
{
|
||||
virDomainObjPtr privdom;
|
||||
@ -3180,7 +3181,7 @@ static int testDomainInterfaceStats(virDomainPtr domain,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (!(net = virDomainNetFindByName(privdom->def, path)))
|
||||
if (!(net = virDomainNetFind(privdom->def, device)))
|
||||
goto error;
|
||||
|
||||
if (gettimeofday(&tv, NULL) < 0) {
|
||||
|
@ -1873,7 +1873,7 @@ vzDomainBlockStatsFlags(virDomainPtr domain,
|
||||
|
||||
static int
|
||||
vzDomainInterfaceStats(virDomainPtr domain,
|
||||
const char *path,
|
||||
const char *device,
|
||||
virDomainInterfaceStatsPtr stats)
|
||||
{
|
||||
virDomainObjPtr dom = NULL;
|
||||
@ -1888,7 +1888,7 @@ vzDomainInterfaceStats(virDomainPtr domain,
|
||||
|
||||
privdom = dom->privateData;
|
||||
|
||||
ret = prlsdkGetNetStats(privdom->stats, privdom->sdkdom, path, stats);
|
||||
ret = prlsdkGetNetStats(privdom->stats, privdom->sdkdom, device, stats);
|
||||
|
||||
cleanup:
|
||||
virDomainObjEndAPI(&dom);
|
||||
|
@ -4484,7 +4484,7 @@ prlsdkFindNetByPath(PRL_HANDLE sdkdom, const char *path)
|
||||
}
|
||||
|
||||
int
|
||||
prlsdkGetNetStats(PRL_HANDLE sdkstats, PRL_HANDLE sdkdom, const char *path,
|
||||
prlsdkGetNetStats(PRL_HANDLE sdkstats, PRL_HANDLE sdkdom, const char *device,
|
||||
virDomainInterfaceStatsPtr stats)
|
||||
{
|
||||
int ret = -1;
|
||||
@ -4492,8 +4492,13 @@ prlsdkGetNetStats(PRL_HANDLE sdkstats, PRL_HANDLE sdkdom, const char *path,
|
||||
char *name = NULL;
|
||||
PRL_RESULT pret;
|
||||
PRL_HANDLE net = PRL_INVALID_HANDLE;
|
||||
virMacAddr mac;
|
||||
|
||||
if (virMacAddrParse(device, &mac) == 0)
|
||||
net = prlsdkFindNetByMAC(sdkdom, device);
|
||||
else
|
||||
net = prlsdkFindNetByPath(sdkdom, device);
|
||||
|
||||
net = prlsdkFindNetByPath(sdkdom, path);
|
||||
if (net == PRL_INVALID_HANDLE)
|
||||
goto cleanup;
|
||||
|
||||
|
@ -2109,7 +2109,7 @@ xenUnifiedDomainBlockStats(virDomainPtr dom, const char *path,
|
||||
}
|
||||
|
||||
static int
|
||||
xenUnifiedDomainInterfaceStats(virDomainPtr dom, const char *path,
|
||||
xenUnifiedDomainInterfaceStats(virDomainPtr dom, const char *device,
|
||||
virDomainInterfaceStatsPtr stats)
|
||||
{
|
||||
virDomainDefPtr def = NULL;
|
||||
@ -2122,7 +2122,7 @@ xenUnifiedDomainInterfaceStats(virDomainPtr dom, const char *path,
|
||||
if (virDomainInterfaceStatsEnsureACL(dom->conn, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(net = virDomainNetFind(def, path)))
|
||||
if (!(net = virDomainNetFind(def, device)))
|
||||
goto cleanup;
|
||||
|
||||
ret = xenHypervisorDomainInterfaceStats(def, net->ifname, stats);
|
||||
|
@ -779,7 +779,8 @@ Get network interface stats for a running domain. The network
|
||||
interface stats are only available for interfaces that have a
|
||||
physical source interface. This does not include, for example, a
|
||||
'user' interface type since it is a virtual LAN with NAT to the
|
||||
outside world.
|
||||
outside world. I<interface-device> can be the interface target by
|
||||
name or MAC address.
|
||||
|
||||
=item B<domif-setlink> I<domain> I<interface-device> I<state> [I<--config>]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user