[PATCH 0/2] src: Document virDomainInterfaceStats() limitation

See individual patches. Michal Prívozník (2): conf: Make macvtap ethernet share host view src: Document virDomainInterfaceStats() limitation docs/manpages/virsh.rst | 3 ++- src/conf/domain_conf.c | 6 +++++- src/libvirt-domain.c | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-) -- 2.39.2

When fetching stats for a domain's <interface/>, or when setting up its QoS, we can face two situations: 1) the device "shares" the host view, meaning each packet sent/received on the interface by a domain is accounted for in the same category on the host, or 2) the device is at the other side, and a packet send by a domain, is in fact packet received on the host. This fact affects whether we need to swap RX/TX values when fetching stats, or setting up QoS. We have this convenient helper function (virDomainNetTypeSharesHostView()), which returns to which category given interface type falls into. Now, for unmanaged type='ethernet' our options are quite limited, because it's user's responsibility to set up the host side of the interface. And it can be just anything. Fortunately, we have another convenience function (virNetDevMacVLanIsMacvtap()), which determines whether given interface is a macvtap (which is notoriously known for falling into the first category). Let's use it to help virDomainNetTypeSharesHostView() determine the view more accurately. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2175449 Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/conf/domain_conf.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 34d38f9958..ee74d5ab8a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -29576,8 +29576,12 @@ virDomainNetTypeSharesHostView(const virDomainNetDef *net) switch (actualType) { case VIR_DOMAIN_NET_TYPE_DIRECT: return true; - case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_ETHERNET: + if (net->managed_tap == VIR_TRISTATE_BOOL_NO && + virNetDevMacVLanIsMacvtap(net->ifname)) + return true; + break; + case VIR_DOMAIN_NET_TYPE_USER: case VIR_DOMAIN_NET_TYPE_VHOSTUSER: case VIR_DOMAIN_NET_TYPE_SERVER: case VIR_DOMAIN_NET_TYPE_CLIENT: -- 2.39.2

For unmanaged ethernet <interface/>, it is user's responsibility to set up the interface. And as such it can be just anything. Therefore, it's (almost) impossible for the virDomainInterfaceStats() API to tell whether RX/TX values need to be swapped or copied verbatim into the return structure. Document this limitation. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- docs/manpages/virsh.rst | 3 ++- src/libvirt-domain.c | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index d5b614dc03..26c328d390 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -2012,7 +2012,8 @@ 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. *interface-device* can be the interface target by -name or MAC address. +name or MAC address. Please note, for an unmanaged *ethernet* +type returned stats might have RX/TX swapped. domiftune diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 3199a27065..379057d9a7 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -5965,6 +5965,9 @@ virDomainBlockStatsFlags(virDomainPtr dom, * * The returned stats are from domain's point of view. * + * Please note, for an unmanaged ethernet type, returned stats + * might have RX/TX swapped. + * * Returns: 0 in case of success or -1 in case of failure. * * Since: 0.3.2 -- 2.39.2

On Mon, Mar 06, 2023 at 10:47:22AM +0100, Michal Privoznik wrote:
See individual patches.
Michal Prívozník (2): conf: Make macvtap ethernet share host view src: Document virDomainInterfaceStats() limitation
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
docs/manpages/virsh.rst | 3 ++- src/conf/domain_conf.c | 6 +++++- src/libvirt-domain.c | 3 +++ 3 files changed, 10 insertions(+), 2 deletions(-)
-- 2.39.2
participants (2)
-
Martin Kletzander
-
Michal Privoznik