diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 500419c177..46051a1048 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2397,7 +2397,7 @@ virSocketAddrSetIPv6AddrNetOrder; virSocketAddrSetPort; # util/virstats.h -virNetInterfaceStats; +virNetDevTapInterfaceStats; # util/virstorageencryption.h virStorageEncryptionFormat; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 3efa91eee8..e0cb14740a 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -4985,7 +4985,7 @@ libxlDomainInterfaceStats(virDomainPtr dom, } if (ret == 0) - ret = virNetInterfaceStats(path, stats); + ret = virNetDevTapInterfaceStats(path, stats); else virReportError(VIR_ERR_INVALID_ARG, _("'%s' is not a known interface"), path); diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index a6776a1933..64ff83dd30 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2896,7 +2896,7 @@ lxcDomainInterfaceStats(virDomainPtr dom, } if (ret == 0) - ret = virNetInterfaceStats(path, stats); + ret = virNetDevTapInterfaceStats(path, stats); else virReportError(VIR_ERR_INVALID_ARG, _("Invalid path, '%s' is not a known interface"), path); diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 1dfb1ccf49..cdf39275b5 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -2027,7 +2027,7 @@ openvzDomainInterfaceStats(virDomainPtr dom, } if (ret == 0) - ret = virNetInterfaceStats(path, stats); + ret = virNetDevTapInterfaceStats(path, stats); else virReportError(VIR_ERR_INVALID_ARG, _("invalid path, '%s' is not a known interface"), path); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d86d301a91..54841a074d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -11009,7 +11009,7 @@ qemuDomainInterfaceStats(virDomainPtr dom, if (virNetDevOpenvswitchInterfaceStats(path, stats) < 0) goto cleanup; } else { - if (virNetInterfaceStats(path, stats) < 0) + if (virNetDevTapInterfaceStats(path, stats) < 0) goto cleanup; } @@ -19204,7 +19204,7 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driver ATTRIBUTE_UNUSED, continue; } } else { - if (virNetInterfaceStats(dom->def->nets[i]->ifname, &tmp) < 0) { + if (virNetDevTapInterfaceStats(dom->def->nets[i]->ifname, &tmp) < 0) { virResetLastError(); continue; } diff --git a/src/util/virstats.c b/src/util/virstats.c index c4725edbd7..eadb3c9788 100644 --- a/src/util/virstats.c +++ b/src/util/virstats.c @@ -50,10 +50,10 @@ */ #ifdef __linux__ int -virNetInterfaceStats(const char *path, - virDomainInterfaceStatsPtr stats) +virNetDevTapInterfaceStats(const char *ifname, + virDomainInterfaceStatsPtr stats) { - int path_len; + int ifname_len; FILE *fp; char line[256], *colon; @@ -64,7 +64,7 @@ virNetInterfaceStats(const char *path, return -1; } - path_len = strlen(path); + ifname_len = strlen(ifname); while (fgets(line, sizeof(line), fp)) { long long dummy; @@ -84,15 +84,15 @@ virNetInterfaceStats(const char *path, colon = strchr(line, ':'); if (!colon) continue; *colon = '\0'; - if (colon-path_len >= line && - STREQ(colon-path_len, path)) { + if (colon - ifname_len >= line && + STREQ(colon - ifname_len, ifname)) { /* IMPORTANT NOTE! * /proc/net/dev vif.nn sees the network from the point * of view of dom0 / hypervisor. So bytes TRANSMITTED by dom0 * are bytes RECEIVED by the domain. That's why the TX/RX fields * appear to be swapped here. */ - if (sscanf(colon+1, + if (sscanf(colon + 1, "%lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld %lld", &tx_bytes, &tx_packets, &tx_errs, &tx_drop, &dummy, &dummy, &dummy, &dummy, @@ -121,8 +121,8 @@ virNetInterfaceStats(const char *path, } #elif defined(HAVE_GETIFADDRS) && defined(AF_LINK) int -virNetInterfaceStats(const char *path, - virDomainInterfaceStatsPtr stats) +virNetDevTapInterfaceStats(const char *ifname, + virDomainInterfaceStatsPtr stats) { struct ifaddrs *ifap, *ifa; struct if_data *ifd; @@ -138,7 +138,7 @@ virNetInterfaceStats(const char *path, if (ifa->ifa_addr->sa_family != AF_LINK) continue; - if (STREQ(ifa->ifa_name, path)) { + if (STREQ(ifa->ifa_name, ifname)) { ifd = (struct if_data *)ifa->ifa_data; stats->tx_bytes = ifd->ifi_ibytes; stats->tx_packets = ifd->ifi_ipackets; @@ -167,8 +167,8 @@ virNetInterfaceStats(const char *path, } #else int -virNetInterfaceStats(const char *path ATTRIBUTE_UNUSED, - virDomainInterfaceStatsPtr stats ATTRIBUTE_UNUSED) +virNetDevTapInterfaceStats(const char *ifname ATTRIBUTE_UNUSED, + virDomainInterfaceStatsPtr stats ATTRIBUTE_UNUSED) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("interface stats not implemented on this platform")); diff --git a/src/util/virstats.h b/src/util/virstats.h index 69f4cf1402..5b771976bd 100644 --- a/src/util/virstats.h +++ b/src/util/virstats.h @@ -25,7 +25,8 @@ # include "internal.h" -int virNetInterfaceStats(const char *path, - virDomainInterfaceStatsPtr stats); +int virNetDevTapInterfaceStats(const char *ifname, + virDomainInterfaceStatsPtr stats) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; #endif /* __STATS_LINUX_H__ */ diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index 0177f83a0d..efe5a8f977 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -1466,7 +1466,7 @@ xenHypervisorDomainInterfaceStats(virDomainDefPtr def, return -1; } - return virNetInterfaceStats(path, stats); + return virNetDevTapInterfaceStats(path, stats); #else virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("/proc/net/dev: Interface not found"));