[PATCH v2 1/4] bhyve: implement domainInterfaceStats

Roman Bogorodskiy posted 4 patches 3 months, 1 week ago
[PATCH v2 1/4] bhyve: implement domainInterfaceStats
Posted by Roman Bogorodskiy 3 months, 1 week ago
The virNetDevTapInterfaceStats() function already works on FreeBSD, so
it's just a matter of wrapping that for domainInterfaceStats.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
 src/bhyve/bhyve_driver.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index db7d440a97..e4698b71bf 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -55,6 +55,7 @@
 #include "conf/domain_capabilities.h"
 #include "virutil.h"
 #include "domain_driver.h"
+#include "virnetdevtap.h"
 
 #include "bhyve_conf.h"
 #include "bhyve_device.h"
@@ -1625,6 +1626,38 @@ bhyveConnectGetDomainCapabilities(virConnectPtr conn,
     return ret;
 }
 
+static int
+bhyveDomainInterfaceStats(virDomainPtr domain,
+                          const char *device,
+                          virDomainInterfaceStatsPtr stats)
+{
+    virDomainObj *vm;
+    int ret = -1;
+    virDomainNetDef *net = NULL;
+
+    if (!(vm = bhyveDomObjFromDomain(domain)))
+        goto cleanup;
+
+    if (virDomainInterfaceStatsEnsureACL(domain->conn, vm->def) < 0)
+        goto cleanup;
+
+    if (virDomainObjCheckActive(vm) < 0)
+        goto cleanup;
+
+    if (!(net = virDomainNetFind(vm->def, device)))
+        goto cleanup;
+
+    if (virNetDevTapInterfaceStats(net->ifname, stats,
+                                   !virDomainNetTypeSharesHostView(net)) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
 static virHypervisorDriver bhyveHypervisorDriver = {
     .name = "bhyve",
     .connectURIProbe = bhyveConnectURIProbe,
@@ -1685,6 +1718,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
     .connectIsEncrypted = bhyveConnectIsEncrypted, /* 1.3.5 */
     .connectDomainXMLFromNative = bhyveConnectDomainXMLFromNative, /* 2.1.0 */
     .connectGetDomainCapabilities = bhyveConnectGetDomainCapabilities, /* 2.1.0 */
+    .domainInterfaceStats = bhyveDomainInterfaceStats, /* 11.5.0 */
 };
 
 
-- 
2.49.0
Re: [PATCH v2 1/4] bhyve: implement domainInterfaceStats
Posted by Michal Prívozník via Devel 3 weeks, 1 day ago
On 6/1/25 07:40, Roman Bogorodskiy wrote:
> The virNetDevTapInterfaceStats() function already works on FreeBSD, so
> it's just a matter of wrapping that for domainInterfaceStats.
> 
> Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> ---
>  src/bhyve/bhyve_driver.c | 34 ++++++++++++++++++++++++++++++++++
>  1 file changed, 34 insertions(+)
> 
> diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
> index db7d440a97..e4698b71bf 100644
> --- a/src/bhyve/bhyve_driver.c
> +++ b/src/bhyve/bhyve_driver.c
> @@ -55,6 +55,7 @@
>  #include "conf/domain_capabilities.h"
>  #include "virutil.h"
>  #include "domain_driver.h"
> +#include "virnetdevtap.h"
>  
>  #include "bhyve_conf.h"
>  #include "bhyve_device.h"
> @@ -1625,6 +1626,38 @@ bhyveConnectGetDomainCapabilities(virConnectPtr conn,
>      return ret;
>  }
>  
> +static int
> +bhyveDomainInterfaceStats(virDomainPtr domain,
> +                          const char *device,
> +                          virDomainInterfaceStatsPtr stats)
> +{
> +    virDomainObj *vm;
> +    int ret = -1;
> +    virDomainNetDef *net = NULL;
> +
> +    if (!(vm = bhyveDomObjFromDomain(domain)))
> +        goto cleanup;
> +
> +    if (virDomainInterfaceStatsEnsureACL(domain->conn, vm->def) < 0)
> +        goto cleanup;
> +
> +    if (virDomainObjCheckActive(vm) < 0)
> +        goto cleanup;
> +
> +    if (!(net = virDomainNetFind(vm->def, device)))
> +        goto cleanup;
> +
> +    if (virNetDevTapInterfaceStats(net->ifname, stats,
> +                                   !virDomainNetTypeSharesHostView(net)) < 0)
> +        goto cleanup;
> +
> +    ret = 0;
> +
> + cleanup:
> +    virDomainObjEndAPI(&vm);
> +    return ret;
> +}
> +
>  static virHypervisorDriver bhyveHypervisorDriver = {
>      .name = "bhyve",
>      .connectURIProbe = bhyveConnectURIProbe,
> @@ -1685,6 +1718,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
>      .connectIsEncrypted = bhyveConnectIsEncrypted, /* 1.3.5 */
>      .connectDomainXMLFromNative = bhyveConnectDomainXMLFromNative, /* 2.1.0 */
>      .connectGetDomainCapabilities = bhyveConnectGetDomainCapabilities, /* 2.1.0 */
> +    .domainInterfaceStats = bhyveDomainInterfaceStats, /* 11.5.0 */

This has to be 11.7.0 now; Sorry for letting this slip review this long.

>  };
>  
>  

Michal