[libvirt] [PATCH v4 5/6] qemu: Network stats support for VF Representor

Jai Singh Rana JaiSingh.Rana at cavium.com
Thu Jun 28 13:22:36 UTC 2018


In case of pci SR-IOV device with interface_type as 'hostdev', return
network stats if it has a VF Representor interface enabled on host for
pci SR-IOV device according to switchdev model.

Signed-off-by: Jai Singh Rana <JaiSingh.Rana at cavium.com>
---
 src/qemu/qemu_driver.c | 34 ++++++++++++++++++++++++++++++----
 1 file changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 4e94b4f095..167807704b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -67,6 +67,7 @@
 #include "virbuffer.h"
 #include "virhostcpu.h"
 #include "virhostmem.h"
+#include "virnetdevhostdev.h"
 #include "virnetdevtap.h"
 #include "virnetdevopenvswitch.h"
 #include "capabilities.h"
@@ -11258,6 +11259,10 @@ qemuDomainInterfaceStats(virDomainPtr dom,
     if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
         if (virNetDevOpenvswitchInterfaceStats(net->ifname, stats) < 0)
             goto cleanup;
+    } else if (virDomainNetGetActualType(net) == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+        bool swapped = virDomainNetTypeSharesHostView(net);
+        if (virNetdevHostdevVFRIfStats(device, stats, !swapped) < 0)
+            goto cleanup;
     } else {
         if (virNetDevTapInterfaceStats(net->ifname, stats,
                                        !virDomainNetTypeSharesHostView(net)) < 0)
@@ -19935,6 +19940,7 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
 {
     size_t i;
     struct _virDomainInterfaceStats tmp;
+    char *vf_ifname = NULL;
     int ret = -1;
 
     if (!virDomainObjIsActive(dom))
@@ -19947,21 +19953,41 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
         virDomainNetDefPtr net = dom->def->nets[i];
         virDomainNetType actualType;
 
-        if (!net->ifname)
+        actualType = virDomainNetGetActualType(net);
+
+        if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+            vf_ifname = virNetdevHostdevGetVFRIfName(dom->def->hostdevs[i]);
+            if (!vf_ifname)
+                continue;
+        }
+        else if (!net->ifname)
             continue;
 
         memset(&tmp, 0, sizeof(tmp));
 
-        actualType = virDomainNetGetActualType(net);
 
-        QEMU_ADD_NAME_PARAM(record, maxparams,
-                            "net", "name", i, net->ifname);
+        if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV)
+            QEMU_ADD_NAME_PARAM(record, maxparams,
+                                "net", "name", i, vf_ifname);
+        else
+            QEMU_ADD_NAME_PARAM(record, maxparams,
+                                "net", "name", i, net->ifname);
 
         if (actualType == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
             if (virNetDevOpenvswitchInterfaceStats(net->ifname, &tmp) < 0) {
                 virResetLastError();
                 continue;
             }
+        } else if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+            int rc;
+            bool swapped = virDomainNetTypeSharesHostView(net);
+
+            rc = virNetdevHostdevVFRIfStats(vf_ifname, &tmp, !swapped);
+            VIR_FREE(vf_ifname);
+            if (rc < 0) {
+                virResetLastError();
+                continue;
+            }
         } else {
             if (virNetDevTapInterfaceStats(net->ifname, &tmp,
                                            !virDomainNetTypeSharesHostView(net)) < 0) {
-- 
2.13.7




More information about the libvir-list mailing list