mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +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,
|
int *nparams,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
int virDomainInterfaceStats (virDomainPtr dom,
|
int virDomainInterfaceStats (virDomainPtr dom,
|
||||||
const char *path,
|
const char *device,
|
||||||
virDomainInterfaceStatsPtr stats,
|
virDomainInterfaceStatsPtr stats,
|
||||||
size_t size);
|
size_t size);
|
||||||
|
|
||||||
|
@ -486,7 +486,7 @@ typedef int
|
|||||||
|
|
||||||
typedef int
|
typedef int
|
||||||
(*virDrvDomainInterfaceStats)(virDomainPtr domain,
|
(*virDrvDomainInterfaceStats)(virDomainPtr domain,
|
||||||
const char *path,
|
const char *device,
|
||||||
virDomainInterfaceStatsPtr stats);
|
virDomainInterfaceStatsPtr stats);
|
||||||
|
|
||||||
typedef int
|
typedef int
|
||||||
|
@ -5507,14 +5507,15 @@ virDomainBlockStatsFlags(virDomainPtr dom,
|
|||||||
/**
|
/**
|
||||||
* virDomainInterfaceStats:
|
* virDomainInterfaceStats:
|
||||||
* @dom: pointer to the domain object
|
* @dom: pointer to the domain object
|
||||||
* @path: path to the interface
|
* @device: the interface name or MAC address
|
||||||
* @stats: network interface stats (returned)
|
* @stats: network interface stats (returned)
|
||||||
* @size: size of stats structure
|
* @size: size of stats structure
|
||||||
*
|
*
|
||||||
* This function returns network interface stats for interfaces
|
* This function returns network interface stats for interfaces
|
||||||
* attached to the domain.
|
* 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
|
* Domains may have more than one network interface. To get stats for
|
||||||
* each you should make multiple calls to this function.
|
* 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.
|
* Returns: 0 in case of success or -1 in case of failure.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virDomainInterfaceStats(virDomainPtr dom, const char *path,
|
virDomainInterfaceStats(virDomainPtr dom, const char *device,
|
||||||
virDomainInterfaceStatsPtr stats, size_t size)
|
virDomainInterfaceStatsPtr stats, size_t size)
|
||||||
{
|
{
|
||||||
virConnectPtr conn;
|
virConnectPtr conn;
|
||||||
virDomainInterfaceStatsStruct stats2 = { -1, -1, -1, -1,
|
virDomainInterfaceStatsStruct stats2 = { -1, -1, -1, -1,
|
||||||
-1, -1, -1, -1 };
|
-1, -1, -1, -1 };
|
||||||
|
|
||||||
VIR_DOMAIN_DEBUG(dom, "path=%s, stats=%p, size=%zi",
|
VIR_DOMAIN_DEBUG(dom, "device=%s, stats=%p, size=%zi",
|
||||||
path, stats, size);
|
device, stats, size);
|
||||||
|
|
||||||
virResetLastError();
|
virResetLastError();
|
||||||
|
|
||||||
virCheckDomainReturn(dom, -1);
|
virCheckDomainReturn(dom, -1);
|
||||||
virCheckNonNullArgGoto(path, error);
|
virCheckNonNullArgGoto(device, error);
|
||||||
virCheckNonNullArgGoto(stats, error);
|
virCheckNonNullArgGoto(stats, error);
|
||||||
if (size > sizeof(stats2)) {
|
if (size > sizeof(stats2)) {
|
||||||
virReportInvalidArg(size,
|
virReportInvalidArg(size,
|
||||||
@ -5553,7 +5554,7 @@ virDomainInterfaceStats(virDomainPtr dom, const char *path,
|
|||||||
conn = dom->conn;
|
conn = dom->conn;
|
||||||
|
|
||||||
if (conn->driver->domainInterfaceStats) {
|
if (conn->driver->domainInterfaceStats) {
|
||||||
if (conn->driver->domainInterfaceStats(dom, path, &stats2) == -1)
|
if (conn->driver->domainInterfaceStats(dom, device, &stats2) == -1)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
memcpy(stats, &stats2, size);
|
memcpy(stats, &stats2, size);
|
||||||
|
@ -4956,7 +4956,7 @@ libxlDomainIsUpdated(virDomainPtr dom)
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
libxlDomainInterfaceStats(virDomainPtr dom,
|
libxlDomainInterfaceStats(virDomainPtr dom,
|
||||||
const char *path,
|
const char *device,
|
||||||
virDomainInterfaceStatsPtr stats)
|
virDomainInterfaceStatsPtr stats)
|
||||||
{
|
{
|
||||||
libxlDriverPrivatePtr driver = dom->conn->privateData;
|
libxlDriverPrivatePtr driver = dom->conn->privateData;
|
||||||
@ -4979,10 +4979,10 @@ libxlDomainInterfaceStats(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(net = virDomainNetFindByName(vm->def, path)))
|
if (!(net = virDomainNetFind(vm->def, device)))
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (virNetDevTapInterfaceStats(path, stats,
|
if (virNetDevTapInterfaceStats(device, stats,
|
||||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
|
@ -2849,7 +2849,7 @@ lxcDomainGetBlkioParameters(virDomainPtr dom,
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
lxcDomainInterfaceStats(virDomainPtr dom,
|
lxcDomainInterfaceStats(virDomainPtr dom,
|
||||||
const char *path,
|
const char *device,
|
||||||
virDomainInterfaceStatsPtr stats)
|
virDomainInterfaceStatsPtr stats)
|
||||||
{
|
{
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
@ -2872,10 +2872,10 @@ lxcDomainInterfaceStats(virDomainPtr dom,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(net = virDomainNetFindByName(vm->def, path)))
|
if (!(net = virDomainNetFind(vm->def, device)))
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (virNetDevTapInterfaceStats(path, stats,
|
if (virNetDevTapInterfaceStats(device, stats,
|
||||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
|
@ -1980,7 +1980,7 @@ openvzGetVEStatus(virDomainObjPtr vm, int *status, int *reason)
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
openvzDomainInterfaceStats(virDomainPtr dom,
|
openvzDomainInterfaceStats(virDomainPtr dom,
|
||||||
const char *path,
|
const char *device,
|
||||||
virDomainInterfaceStatsPtr stats)
|
virDomainInterfaceStatsPtr stats)
|
||||||
{
|
{
|
||||||
struct openvz_driver *driver = dom->conn->privateData;
|
struct openvz_driver *driver = dom->conn->privateData;
|
||||||
@ -2006,10 +2006,10 @@ openvzDomainInterfaceStats(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(net = virDomainNetFindByName(vm->def, path)))
|
if (!(net = virDomainNetFind(vm->def, device)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virNetDevTapInterfaceStats(path, stats,
|
if (virNetDevTapInterfaceStats(device, stats,
|
||||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
@ -11021,7 +11021,7 @@ qemuDomainBlockStatsFlags(virDomainPtr dom,
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainInterfaceStats(virDomainPtr dom,
|
qemuDomainInterfaceStats(virDomainPtr dom,
|
||||||
const char *path,
|
const char *device,
|
||||||
virDomainInterfaceStatsPtr stats)
|
virDomainInterfaceStatsPtr stats)
|
||||||
{
|
{
|
||||||
virDomainObjPtr vm;
|
virDomainObjPtr vm;
|
||||||
@ -11040,14 +11040,14 @@ qemuDomainInterfaceStats(virDomainPtr dom,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(net = virDomainNetFindByName(vm->def, path)))
|
if (!(net = virDomainNetFind(vm->def, device)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
|
if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
|
||||||
if (virNetDevOpenvswitchInterfaceStats(path, stats) < 0)
|
if (virNetDevOpenvswitchInterfaceStats(device, stats) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
if (virNetDevTapInterfaceStats(path, stats,
|
if (virNetDevTapInterfaceStats(device, stats,
|
||||||
!virDomainNetTypeSharesHostView(net)) < 0)
|
!virDomainNetTypeSharesHostView(net)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
@ -682,7 +682,7 @@ struct remote_domain_block_stats_flags_ret {
|
|||||||
|
|
||||||
struct remote_domain_interface_stats_args {
|
struct remote_domain_interface_stats_args {
|
||||||
remote_nonnull_domain dom;
|
remote_nonnull_domain dom;
|
||||||
remote_nonnull_string path;
|
remote_nonnull_string device;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct remote_domain_interface_stats_ret { /* insert@2 */
|
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 {
|
struct remote_domain_interface_stats_args {
|
||||||
remote_nonnull_domain dom;
|
remote_nonnull_domain dom;
|
||||||
remote_nonnull_string path;
|
remote_nonnull_string device;
|
||||||
};
|
};
|
||||||
struct remote_domain_interface_stats_ret {
|
struct remote_domain_interface_stats_ret {
|
||||||
int64_t rx_bytes;
|
int64_t rx_bytes;
|
||||||
|
@ -3160,8 +3160,9 @@ static int testDomainBlockStats(virDomainPtr domain,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int testDomainInterfaceStats(virDomainPtr domain,
|
static int
|
||||||
const char *path,
|
testDomainInterfaceStats(virDomainPtr domain,
|
||||||
|
const char *device,
|
||||||
virDomainInterfaceStatsPtr stats)
|
virDomainInterfaceStatsPtr stats)
|
||||||
{
|
{
|
||||||
virDomainObjPtr privdom;
|
virDomainObjPtr privdom;
|
||||||
@ -3180,7 +3181,7 @@ static int testDomainInterfaceStats(virDomainPtr domain,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(net = virDomainNetFindByName(privdom->def, path)))
|
if (!(net = virDomainNetFind(privdom->def, device)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (gettimeofday(&tv, NULL) < 0) {
|
if (gettimeofday(&tv, NULL) < 0) {
|
||||||
|
@ -1873,7 +1873,7 @@ vzDomainBlockStatsFlags(virDomainPtr domain,
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
vzDomainInterfaceStats(virDomainPtr domain,
|
vzDomainInterfaceStats(virDomainPtr domain,
|
||||||
const char *path,
|
const char *device,
|
||||||
virDomainInterfaceStatsPtr stats)
|
virDomainInterfaceStatsPtr stats)
|
||||||
{
|
{
|
||||||
virDomainObjPtr dom = NULL;
|
virDomainObjPtr dom = NULL;
|
||||||
@ -1888,7 +1888,7 @@ vzDomainInterfaceStats(virDomainPtr domain,
|
|||||||
|
|
||||||
privdom = dom->privateData;
|
privdom = dom->privateData;
|
||||||
|
|
||||||
ret = prlsdkGetNetStats(privdom->stats, privdom->sdkdom, path, stats);
|
ret = prlsdkGetNetStats(privdom->stats, privdom->sdkdom, device, stats);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virDomainObjEndAPI(&dom);
|
virDomainObjEndAPI(&dom);
|
||||||
|
@ -4484,7 +4484,7 @@ prlsdkFindNetByPath(PRL_HANDLE sdkdom, const char *path)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
prlsdkGetNetStats(PRL_HANDLE sdkstats, PRL_HANDLE sdkdom, const char *path,
|
prlsdkGetNetStats(PRL_HANDLE sdkstats, PRL_HANDLE sdkdom, const char *device,
|
||||||
virDomainInterfaceStatsPtr stats)
|
virDomainInterfaceStatsPtr stats)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -4492,8 +4492,13 @@ prlsdkGetNetStats(PRL_HANDLE sdkstats, PRL_HANDLE sdkdom, const char *path,
|
|||||||
char *name = NULL;
|
char *name = NULL;
|
||||||
PRL_RESULT pret;
|
PRL_RESULT pret;
|
||||||
PRL_HANDLE net = PRL_INVALID_HANDLE;
|
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)
|
if (net == PRL_INVALID_HANDLE)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
@ -2109,7 +2109,7 @@ xenUnifiedDomainBlockStats(virDomainPtr dom, const char *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
xenUnifiedDomainInterfaceStats(virDomainPtr dom, const char *path,
|
xenUnifiedDomainInterfaceStats(virDomainPtr dom, const char *device,
|
||||||
virDomainInterfaceStatsPtr stats)
|
virDomainInterfaceStatsPtr stats)
|
||||||
{
|
{
|
||||||
virDomainDefPtr def = NULL;
|
virDomainDefPtr def = NULL;
|
||||||
@ -2122,7 +2122,7 @@ xenUnifiedDomainInterfaceStats(virDomainPtr dom, const char *path,
|
|||||||
if (virDomainInterfaceStatsEnsureACL(dom->conn, def) < 0)
|
if (virDomainInterfaceStatsEnsureACL(dom->conn, def) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(net = virDomainNetFind(def, path)))
|
if (!(net = virDomainNetFind(def, device)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = xenHypervisorDomainInterfaceStats(def, net->ifname, stats);
|
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
|
interface stats are only available for interfaces that have a
|
||||||
physical source interface. This does not include, for example, a
|
physical source interface. This does not include, for example, a
|
||||||
'user' interface type since it is a virtual LAN with NAT to the
|
'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>]
|
=item B<domif-setlink> I<domain> I<interface-device> I<state> [I<--config>]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user