[libvirt] [PATCH v4 3/6] util: Add helper APIs to get/verify VF Representor name

2018-06-28 Thread Jai Singh Rana
Introduce new APIs virNetdevHostdevGetVFRIfName and
virNetdevHostdevCheckVFRIfName to fetch/verify VF Representor name
according to switch model for network devices in linux.

Switchdev VF representor interface name on host is queried based on
Bus:Device:Function information of pci SR-IOV device in Domain's
hostdev def and subsequently verifying the required net sysfs
directory and file entries of VF representor.

Signed-off-by: Jai Singh Rana 
---
 po/POTFILES |   1 +
 src/libvirt_private.syms|   7 ++
 src/util/Makefile.inc.am|   2 +
 src/util/virhostdev.c   |   2 +-
 src/util/virhostdev.h   |   8 ++
 src/util/virnetdevhostdev.c | 300 
 src/util/virnetdevhostdev.h |  34 +
 7 files changed, 353 insertions(+), 1 deletion(-)
 create mode 100644 src/util/virnetdevhostdev.c
 create mode 100644 src/util/virnetdevhostdev.h

diff --git a/po/POTFILES b/po/POTFILES
index be2874487c..3f8731f342 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -235,6 +235,7 @@ src/util/virmdev.c
 src/util/virnetdev.c
 src/util/virnetdevbandwidth.c
 src/util/virnetdevbridge.c
+src/util/virnetdevhostdev.c
 src/util/virnetdevip.c
 src/util/virnetdevmacvlan.c
 src/util/virnetdevmidonet.c
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 0ba8cd2a14..5aa8f7ed64 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1968,6 +1968,7 @@ virHostdevFindUSBDevice;
 virHostdevIsMdevDevice;
 virHostdevIsSCSIDevice;
 virHostdevManagerGetDefault;
+virHostdevNetDevice;
 virHostdevPCINodeDeviceDetach;
 virHostdevPCINodeDeviceReAttach;
 virHostdevPCINodeDeviceReset;
@@ -2356,6 +2357,12 @@ virNetDevBridgeSetSTPDelay;
 virNetDevBridgeSetVlanFiltering;
 
 
+# util/virnetdevhostdev.h
+virNetdevHostdevCheckVFRIfName;
+virNetdevHostdevGetVFRIfName;
+virNetdevHostdevVFRIfStats;
+
+
 # util/virnetdevip.h
 virNetDevIPAddrAdd;
 virNetDevIPAddrDel;
diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am
index a22265606c..0846a8e025 100644
--- a/src/util/Makefile.inc.am
+++ b/src/util/Makefile.inc.am
@@ -108,6 +108,8 @@ UTIL_SOURCES = \
util/virnetdevbandwidth.h \
util/virnetdevbridge.c \
util/virnetdevbridge.h \
+   util/virnetdevhostdev.c \
+   util/virnetdevhostdev.h \
util/virnetdevip.c \
util/virnetdevip.h \
util/virnetdevmacvlan.c \
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index f4bd19df64..c6ee725860 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -303,7 +303,7 @@ virHostdevIsVirtualFunction(virDomainHostdevDefPtr hostdev)
 }
 
 
-static int
+int
 virHostdevNetDevice(virDomainHostdevDefPtr hostdev,
 int pfNetDevIdx,
 char **linkdev,
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index 8f77c00221..7412a20aa9 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -60,6 +60,14 @@ struct _virHostdevManager {
 };
 
 virHostdevManagerPtr virHostdevManagerGetDefault(void);
+
+int
+virHostdevNetDevice(virDomainHostdevDefPtr hostdev,
+int pfNetDevIdx,
+char **linkdev,
+int *vf)
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
+
 int
 virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr,
 const char *drv_name,
diff --git a/src/util/virnetdevhostdev.c b/src/util/virnetdevhostdev.c
new file mode 100644
index 00..2d3e46c81f
--- /dev/null
+++ b/src/util/virnetdevhostdev.c
@@ -0,0 +1,300 @@
+/*
+ * virnetdevhostdev.c: utilities to get/verify Switchdev VF Representor
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "virhostdev.h"
+#include "virnetdev.h"
+#include "virnetdevhostdev.h"
+#include "viralloc.h"
+#include "virstring.h"
+#include "virfile.h"
+#include "virerror.h"
+#include "virlog.h"
+#include "c-ctype.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+VIR_LOG_INIT("util.netdevhostdev");
+
+#ifndef IFNAMSIZ
+# define IFNAMSIZ 16
+#endif
+
+#define IFSWITCHIDSIZ 20
+
+#ifdef __linux__
+/**
+ * virNetdevHostdevNetSysfsPath
+ *
+ * @pf_name: netdev name of the physical function (PF)
+

[libvirt] [PATCH v4 6/6] docs: Update news about Network stats support for VF Representor

2018-06-28 Thread Jai Singh Rana
Signed-off-by: Jai Singh Rana 
---
 docs/news.xml | 9 +
 1 file changed, 9 insertions(+)

diff --git a/docs/news.xml b/docs/news.xml
index 468d34093a..c6394a8f0f 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -130,6 +130,15 @@
   or virStorageVolCreateXMLFrom.
 
   
+  
+
+  qemu: Support interface network stats for VF Representors
+
+
+  Interface network stats are supported now for SR-IOV device(hostdev)
+  if this interface has VF representor on host in switchdev mode.
+
+  
 
 
   
-- 
2.13.7

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v4 4/6] conf: util: Add API to find net def given its domain's hostdev

2018-06-28 Thread Jai Singh Rana
Introduce API virDomainNetFindByHostdev which retrieves net def in
given domain for the given hostdev def. This API will now be used by
virDomainNetFind to further probe net for hostdev network devices.

Signed-off-by: Jai Singh Rana 
---
 src/conf/domain_conf.c   | 43 +++
 src/conf/domain_conf.h   |  2 ++
 src/libvirt_private.syms |  2 ++
 src/util/virhostdev.c|  2 +-
 src/util/virhostdev.h|  3 +++
 5 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d8cb7f37f3..8432215d19 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -56,6 +56,7 @@
 #include "virsecret.h"
 #include "virstring.h"
 #include "virnetdev.h"
+#include "virnetdevhostdev.h"
 #include "virnetdevmacvlan.h"
 #include "virhostdev.h"
 #include "virmdev.h"
@@ -29064,6 +29065,37 @@ virDomainNetFind(virDomainDefPtr def, const char 
*device)
 
 
 /**
+ * virDomainNetFindByHostdev:
+ * @def: domain's def
+ * @hostdev: hostdev whose net def if exists to be retrieved
+ *
+ * Finds net def in domain given the domain's hostdev.
+ *
+ * Returns a pointer to the net def or NULL if not found.
+ */
+virDomainNetDefPtr
+virDomainNetFindByHostdev(virDomainDefPtr def,
+  virDomainHostdevDefPtr hostdev)
+{
+size_t i;
+virDomainNetType actualType;
+virDomainHostdevDefPtr hostdef = NULL;
+
+for (i = 0; i < def->nnets; i++) {
+ actualType = virDomainNetGetActualType(def->nets[i]);
+ if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV)
+ hostdef = virDomainNetGetActualHostdev(def->nets[i]);
+ else
+ continue;
+ if  (!memcmp(hostdev, hostdef, sizeof(virDomainHostdevDef)))
+  return def->nets[i];
+}
+
+return NULL;
+}
+
+
+/**
  * virDomainNetFindByName:
  * @def: domain's def
  * @ifname: interface name
@@ -29077,12 +29109,23 @@ virDomainNetFindByName(virDomainDefPtr def,
const char *ifname)
 {
 size_t i;
+virDomainNetDefPtr net = NULL;
 
 for (i = 0; i < def->nnets; i++) {
 if (STREQ_NULLABLE(ifname, def->nets[i]->ifname))
 return def->nets[i];
 }
 
+/* Give a try to hostdev if its a switchdev network device*/
+for (i = 0; i < def->nhostdevs; i++) {
+ if (!virHostdevIsPCINetDevice(def->hostdevs[i]))
+ continue;
+ if (virNetdevHostdevCheckVFRIfName(def->hostdevs[i], ifname)) {
+ if ((net = virDomainNetFindByHostdev(def, def->hostdevs[i])))
+ return net;
+ }
+}
+
 return NULL;
 }
 
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 0924fc4f3c..ccec74e51d 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3146,6 +3146,8 @@ int virDomainDiskSourceParse(xmlNodePtr node,
 
 int virDomainNetFindIdx(virDomainDefPtr def, virDomainNetDefPtr net);
 virDomainNetDefPtr virDomainNetFind(virDomainDefPtr def, const char *device);
+virDomainNetDefPtr virDomainNetFindByHostdev(virDomainDefPtr def,
+ virDomainHostdevDefPtr hostdev);
 virDomainNetDefPtr virDomainNetFindByName(virDomainDefPtr def, const char 
*ifname);
 bool virDomainHasNet(virDomainDefPtr def, virDomainNetDefPtr net);
 int virDomainNetInsert(virDomainDefPtr def, virDomainNetDefPtr net);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5aa8f7ed64..e4d8583d41 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -449,6 +449,7 @@ virDomainNetDefClear;
 virDomainNetDefFormat;
 virDomainNetDefFree;
 virDomainNetFind;
+virDomainNetFindByHostdev;
 virDomainNetFindByName;
 virDomainNetFindIdx;
 virDomainNetGenerateMAC;
@@ -1966,6 +1967,7 @@ virHostCPUStatsAssign;
 # util/virhostdev.h
 virHostdevFindUSBDevice;
 virHostdevIsMdevDevice;
+virHostdevIsPCINetDevice;
 virHostdevIsSCSIDevice;
 virHostdevManagerGetDefault;
 virHostdevNetDevice;
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index c6ee725860..2b8ecb9649 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -348,7 +348,7 @@ virHostdevNetDevice(virDomainHostdevDefPtr hostdev,
 }
 
 
-static bool
+bool
 virHostdevIsPCINetDevice(virDomainHostdevDefPtr hostdev)
 {
 return hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index 7412a20aa9..71faaf4e7a 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -197,6 +197,9 @@ virHostdevReAttachDomainDevices(virHostdevManagerPtr mgr,
 const char *oldStateDir)
 ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
 bool
+virHostdevIsPCINetDevice(virDomainHostdevDefPtr hostdev)
+ATTRIBUTE_NONNULL(1);
+bool
 virHostdevIsSCSIDevice(virDomainHostdevDefPtr hostdev)
 ATTRIBUTE_NONNULL(1);
 bool
-- 
2.13.7

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v4 0/6] Support network stats for VF representor interface

2018-06-28 Thread Jai Singh Rana
With availability of switchdev model in linux, it is possible to capture
stats for SR-IOV device with interface_type as 'hostdev' provided device
supports VF represontor in switchdev mode on host.

These stats are supported by adding helper APIs for getting/verifying VF
representor name based on PCI Bus:Device:Function information in domains
'hostdev' structure and querying required net sysfs directory and file
entries on host according to switchdev model. These helper APIs are then
used in qemu/conf to get the interface stats for VF representor of
pci SR-IOV device.

V4 includes changes based on feedback received for v3 patchset. Added new
generic API for linux is added to fetch stats from /proc/net/dev which 
will be used by tap and hostdev devices. Also introduced new API to retrieve
net def from given domain based on the given hostdev which supports network.

[1] https://www.kernel.org/doc/Documentation/networking/switchdev.txt
V3: https://www.redhat.com/archives/libvir-list/2018-April/msg00306.html

Jai Singh Rana (6):
  util: Add helper function to clean extra spaces in string
  util: Add generic API to fetch network stats from procfs
  util: Add helper APIs to get/verify VF Representor name
  conf: util: Add API to find net def given its domain's hostdev
  qemu: Network stats support for VF Representor
  docs: Update news about Network stats support for VF Representor

 docs/news.xml   |   9 ++
 po/POTFILES |   1 +
 src/conf/domain_conf.c  |  43 +++
 src/conf/domain_conf.h  |   2 +
 src/libvirt_private.syms|  11 ++
 src/qemu/qemu_driver.c  |  34 -
 src/util/Makefile.inc.am|   2 +
 src/util/virhostdev.c   |   4 +-
 src/util/virhostdev.h   |  11 ++
 src/util/virnetdev.c| 202 -
 src/util/virnetdev.h|   5 +
 src/util/virnetdevhostdev.c | 300 
 src/util/virnetdevhostdev.h |  34 +
 src/util/virnetdevtap.c |  71 +--
 src/util/virstring.c|  36 ++
 src/util/virstring.h|   3 +
 16 files changed, 691 insertions(+), 77 deletions(-)
 create mode 100644 src/util/virnetdevhostdev.c
 create mode 100644 src/util/virnetdevhostdev.h

-- 
2.13.7

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v4 1/6] util: Add helper function to clean extra spaces

2018-06-28 Thread Jai Singh Rana
This patch adds string manupulation helper function which takes
string as input and returns string with all but one space removed
between letters, numbers or words.

Signed-off-by: Jai Singh Rana 
---
 src/libvirt_private.syms |  1 +
 src/util/virstring.c | 36 
 src/util/virstring.h |  3 +++
 3 files changed, 40 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 5499a368c0..272e7426dd 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2891,6 +2891,7 @@ virSkipSpacesBackwards;
 virStrcpy;
 virStrdup;
 virStringBufferIsPrintable;
+virStringCleanExtraSpaces;
 virStringEncodeBase64;
 virStringFilterChars;
 virStringHasChars;
diff --git a/src/util/virstring.c b/src/util/virstring.c
index 15f367af7c..1f45b2b553 100644
--- a/src/util/virstring.c
+++ b/src/util/virstring.c
@@ -139,6 +139,42 @@ virStringSplit(const char *string,
 
 
 /**
+ * virCleanExtraSpacesInString:
+ * @src: original null terminated string
+ *
+ * Returns string with all spaces but one removed between words in @src
+ * string. Caller is responsible for freeing the returned string.
+ * Returns NULL if new string could not be allocated.
+ *
+ */
+char *
+virStringCleanExtraSpaces(char *src)
+{
+char *dst;
+size_t dstlen;
+int src_at = 0;
+int dst_at;
+
+dstlen = strlen(src);
+if (VIR_ALLOC_N(dst, dstlen) < 0)
+return NULL;
+
+while (src[src_at] == ' ')
+src_at++;
+
+for (dst_at = 0; src[src_at] != '\0'; src_at++) {
+if (src[src_at + 1] == ' ' && src[src_at] == ' ')
+continue;
+dst[dst_at] = src[src_at];
+dst_at++;
+}
+dst[dst_at] = '\0';
+
+return dst;
+}
+
+
+/**
  * virStringListJoin:
  * @strings: a NULL-terminated array of strings to join
  * @delim: a string to insert between each of the strings
diff --git a/src/util/virstring.h b/src/util/virstring.h
index 607ae66e99..0778bc45c8 100644
--- a/src/util/virstring.h
+++ b/src/util/virstring.h
@@ -37,6 +37,9 @@ char **virStringSplit(const char *string,
   size_t max_tokens)
 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
+char *virStringCleanExtraSpaces(char *src)
+ATTRIBUTE_NONNULL(1);
+
 char *virStringListJoin(const char **strings,
 const char *delim)
 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
-- 
2.13.7

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v4 2/6] util: Add generic API to fetch network stats from procfs

2018-06-28 Thread Jai Singh Rana
This patch introduces virNetDevGetProcNetdevStats API for linux
which returns stats for the given interface from /proc/net/dev by
properly mapping stats entries in probed column to column header.

Tap and hostdev network devices will now be using this API.
Currently function virNetDevTapInterfaceStats which earlier fetched
stats for tap devies is modified to use above API accordingly.

Signed-off-by: Jai Singh Rana 
---
 src/libvirt_private.syms |   1 +
 src/util/virnetdev.c | 202 ++-
 src/util/virnetdev.h |   5 ++
 src/util/virnetdevtap.c  |  71 +
 4 files changed, 208 insertions(+), 71 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 272e7426dd..0ba8cd2a14 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2289,6 +2289,7 @@ virNetDevGetName;
 virNetDevGetOnline;
 virNetDevGetPhysicalFunction;
 virNetDevGetPhysPortID;
+virNetDevGetProcNetdevStats;
 virNetDevGetPromiscuous;
 virNetDevGetRcvAllMulti;
 virNetDevGetRcvMulti;
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index b250af9e2c..69875c2e04 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -1541,6 +1541,198 @@ virNetDevGetVirtualFunctionInfo(const char *vfname, 
char **pfname,
 return ret;
 }
 
+
+/**
+ * virNetDevGetProcNetdevStats:
+ * @ifname: interface
+ * @stats: where to store statistics
+ * @swapped: whether to swap RX/TX fields
+ *
+ * Fetch RX/TX statistics for given named interface (@ifname) and
+ * store them at @stats. The returned statistics are always from
+ * domain POV. Because in some cases this means swapping RX/TX in
+ * the stats and in others this means no swapping (consider TAP
+ * vs macvtap) caller might choose if the returned stats should
+ * be @swapped or not.
+ *
+ * Returns 0 on success, -1 otherwise (with error reported).
+ */
+
+int
+virNetDevGetProcNetdevStats(const char *ifname,
+virDomainInterfaceStatsPtr stats,
+bool swapped)
+{
+int ifname_len;
+FILE *fp;
+char line[256];
+size_t i;
+char *hdr1 = NULL;
+char *hdr2 = NULL;
+char *stats_row = NULL;
+char **components_hdr1 = NULL;
+char **components_hdr2 = NULL;
+char **components_stats = NULL;
+size_t ncomponents_hdr1 = 0;
+size_t ncomponents_hdr2 = 0;
+size_t ncomponents_stats = 0;
+char **rx_hdr = NULL;
+char **tx_hdr = NULL;
+size_t rx_nentries, tx_nentries;
+int rx_bytes_index = 0;
+int rx_packets_index = 0;
+int rx_drop_index = 0;
+int rx_errs_index = 0;
+int tx_bytes_index = 0;
+int tx_packets_index = 0;
+int tx_drop_index = 0;
+int tx_errs_index = 0;
+int tx_offset = 0;
+int rx_offset = 0;
+int ret = -1;
+
+fp = fopen("/proc/net/dev", "r");
+if (!fp) {
+virReportSystemError(errno, "%s",
+ _("Could not open /proc/net/dev"));
+return ret;
+}
+
+ifname_len = strlen(ifname);
+
+/* First two lines contains headers.
+ * Process headers to match with correspondings stats.
+ */
+if (!fgets(line, sizeof(line), fp)) {
+virReportError(VIR_ERR_INTERNAL_ERROR,
+   _("Interface %s not found in /proc/net/dev"), ifname);
+VIR_FORCE_FCLOSE(fp);
+return ret;
+}
+
+if (!(hdr1 = virStringCleanExtraSpaces(line)))
+goto cleanup;
+
+if (!(components_hdr1 = virStringSplitCount(hdr1, "|", 0,
+_hdr1)))
+goto cleanup;
+
+if (!fgets(line, sizeof(line), fp))
+goto cleanup;
+
+if (!(hdr2 = virStringCleanExtraSpaces(line)))
+goto cleanup;
+
+if (!(components_hdr2 = virStringSplitCount(hdr2, "|", 0,
+_hdr2)))
+goto cleanup;
+
+if (!(rx_hdr = virStringSplitCount(components_hdr2[1], " ", 0,
+   _nentries)))
+goto cleanup;
+
+if (!(tx_hdr = virStringSplitCount(components_hdr2[2], " ", 0,
+   _nentries)))
+goto cleanup;
+
+if (STREQ(components_hdr1[1], "Receive")) {
+rx_offset = 0;
+tx_offset = rx_nentries;
+} else {
+rx_offset = tx_nentries;
+tx_offset = 0;
+}
+
+for (i = 0; i < rx_nentries; i++) {
+ if (STREQ(rx_hdr[i], "bytes"))
+rx_bytes_index = i + rx_offset;
+ else if (STREQ(rx_hdr[i], "packets"))
+rx_packets_index = i + rx_offset;
+ else if (STREQ(rx_hdr[i], "errs"))
+rx_errs_index = i + rx_offset;
+ else if (STREQ(rx_hdr[i], "drop"))
+rx_drop_index = i + rx_offset;
+}
+
+for (i = 0; i < tx_nentries; i++) {
+ if (STREQ(t

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

2018-06-28 Thread Jai Singh Rana
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 
---
 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(, 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, ) < 0) {
 virResetLastError();
 continue;
 }
+} else if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+int rc;
+bool swapped = virDomainNetTypeSharesHostView(net);
+
+rc = virNetdevHostdevVFRIfStats(vf_ifname, , !swapped);
+VIR_FREE(vf_ifname);
+if (rc < 0) {
+virResetLastError();
+continue;
+}
 } else {
 if (virNetDevTapInterfaceStats(net->ifname, ,

!virDomainNetTypeSharesHostView(net)) < 0) {
-- 
2.13.7

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v3 1/2] util: Add helper APIs to get/verify VF Representor name

2018-04-04 Thread Jai Singh Rana
Switchdev VF representor interface name on host is queried based on
Bus:Device:Function information of pci SR-IOV device in Domain's
'hostdev' structure and subsequently verifying the required net sysfs
directory and file entries of VF representor according to switchdev
model.
---
v3 includes changes based on v2's[1] feedback and suggestions. Fixes
warnings reported by syntax-check.
[1] https://www.redhat.com/archives/libvir-list/2018-February/msg00562.html

 po/POTFILES.in  |   1 +
 src/libvirt_private.syms|   7 +
 src/util/Makefile.inc.am|   2 +
 src/util/virhostdev.c   |   2 +-
 src/util/virhostdev.h   |   8 +
 src/util/virnetdevhostdev.c | 374 
 src/util/virnetdevhostdev.h |  35 +
 7 files changed, 428 insertions(+), 1 deletion(-)
 create mode 100644 src/util/virnetdevhostdev.c
 create mode 100644 src/util/virnetdevhostdev.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index d84859a4e..8cd6b86e8 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -234,6 +234,7 @@ src/util/virmdev.c
 src/util/virnetdev.c
 src/util/virnetdevbandwidth.c
 src/util/virnetdevbridge.c
+src/util/virnetdevhostdev.c
 src/util/virnetdevip.c
 src/util/virnetdevmacvlan.c
 src/util/virnetdevmidonet.c
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index f6897915c..fad235206 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1923,6 +1923,7 @@ virHostCPUStatsAssign;
 virHostdevFindUSBDevice;
 virHostdevIsSCSIDevice;
 virHostdevManagerGetDefault;
+virHostdevNetDevice;
 virHostdevPCINodeDeviceDetach;
 virHostdevPCINodeDeviceReAttach;
 virHostdevPCINodeDeviceReset;
@@ -2306,6 +2307,12 @@ virNetDevBridgeSetSTPDelay;
 virNetDevBridgeSetVlanFiltering;
 
 
+# util/virnetdevhostdev.h
+virNetdevHostdevCheckVFRIfName;
+virNetdevHostdevGetVFRIfName;
+virNetdevHostdevVFRIfStats;
+
+
 # util/virnetdevip.h
 virNetDevIPAddrAdd;
 virNetDevIPAddrDel;
diff --git a/src/util/Makefile.inc.am b/src/util/Makefile.inc.am
index a3c3b711f..31fe11c68 100644
--- a/src/util/Makefile.inc.am
+++ b/src/util/Makefile.inc.am
@@ -104,6 +104,8 @@ UTIL_SOURCES = \
util/virnetdevbandwidth.h \
util/virnetdevbridge.c \
util/virnetdevbridge.h \
+   util/virnetdevhostdev.c \
+   util/virnetdevhostdev.h \
util/virnetdevip.c \
util/virnetdevip.h \
util/virnetdevmacvlan.c \
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index a12224c58..4f7b46a04 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -306,7 +306,7 @@ virHostdevIsVirtualFunction(virDomainHostdevDefPtr hostdev)
 }
 
 
-static int
+int
 virHostdevNetDevice(virDomainHostdevDefPtr hostdev,
 int pfNetDevIdx,
 char **linkdev,
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index 54e1c66be..735220add 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -60,6 +60,14 @@ struct _virHostdevManager {
 };
 
 virHostdevManagerPtr virHostdevManagerGetDefault(void);
+
+int
+virHostdevNetDevice(virDomainHostdevDefPtr hostdev,
+int pfNetDevIdx,
+char **linkdev,
+int *vf)
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
+
 int
 virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr,
 const char *drv_name,
diff --git a/src/util/virnetdevhostdev.c b/src/util/virnetdevhostdev.c
new file mode 100644
index 0..19f95bfdd
--- /dev/null
+++ b/src/util/virnetdevhostdev.c
@@ -0,0 +1,374 @@
+/*
+ * virnetdevhostdev.c: utilities to get/verify Switchdev VF Representor
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "virhostdev.h"
+#include "virnetdev.h"
+#include "virnetdevhostdev.h"
+#include "viralloc.h"
+#include "virstring.h"
+#include "virfile.h"
+#include "virerror.h"
+#include "virlog.h"
+#include "c-ctype.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+VIR_LOG_INIT("util.netdevhostdev");
+
+#ifndef IFNAMSIZ
+#define IFNAMSIZ 16
+#endif
+
+#define IFSWITCHIDSIZ 20
+
+#ifdef __linux__
+/**
+ * virNetdevHostdevNetSysfsPath
+ *
+ * @pf_name: netdev name of the physical function (PF)
+ * @vf: virtual function (VF) number for the device of interest
+ * @vf_ifname: name of the VF 

[libvirt] [PATCH v3 2/2] qemu: conf: Network stats support for VF Representors

2018-04-04 Thread Jai Singh Rana
In case of pci SR-IOV device with interface_type as 'hostdev', return
network stats if it has a VF Representor interface on host for
pci SR-IOV device according to switchdev model.
---
v3 includes changes based on v2's[1] feedback and suggestions. Includes
fix for hostdev to net mapping in a given domain.
[1] https://www.redhat.com/archives/libvir-list/2018-February/msg00563.html

 docs/news.xml  |  9 +
 src/conf/domain_conf.c | 15 +++
 src/qemu/qemu_driver.c | 33 +
 3 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/docs/news.xml b/docs/news.xml
index 87f52e83e..04c18495f 100644
--- a/docs/news.xml
+++ b/docs/news.xml
@@ -47,6 +47,15 @@
   supported. In fact, kernel has been supporting this since 4.10.
 
   
+  
+
+  qemu: Support interface network stats for VF Representors
+
+
+  Interface network stats are supported now for SR-IOV device(hostdev)
+  if this interface has VF representor on host in switchdev mode.
+
+  
 
 
 
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index ef16431aa..50813701c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -56,6 +56,7 @@
 #include "virsecret.h"
 #include "virstring.h"
 #include "virnetdev.h"
+#include "virnetdevhostdev.h"
 #include "virnetdevmacvlan.h"
 #include "virhostdev.h"
 #include "virmdev.h"
@@ -28264,12 +28265,26 @@ virDomainNetFindByName(virDomainDefPtr def,
const char *ifname)
 {
 size_t i;
+size_t j;
 
 for (i = 0; i < def->nnets; i++) {
 if (STREQ_NULLABLE(ifname, def->nets[i]->ifname))
 return def->nets[i];
 }
 
+/* Give a try to hostdev */
+for (i = 0; i < def->nhostdevs; i++) {
+if (virNetdevHostdevCheckVFRIfName(def->hostdevs[i], ifname)) {
+for (j = 0; j < def->nnets; j++) {
+if (def->nets[j]->type != VIR_DOMAIN_NET_TYPE_HOSTDEV)
+continue;
+if (memcmp(def->hostdevs[i], >nets[j]->data.hostdev,
+   sizeof(virDomainHostdevDef)) == 0)
+return def->nets[j];
+}
+}
+}
+
 return NULL;
 }
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 5c31dfdd5..f2f9d290b 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -66,6 +66,7 @@
 #include "virbuffer.h"
 #include "virhostcpu.h"
 #include "virhostmem.h"
+#include "virnetdevhostdev.h"
 #include "virnetdevtap.h"
 #include "virnetdevopenvswitch.h"
 #include "capabilities.h"
@@ -11156,6 +11157,11 @@ 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) {
+if (virNetdevHostdevVFRIfStats(device, stats,
+   !virDomainNetTypeSharesHostView(net))
+   < 0)
+goto cleanup;
 } else {
 if (virNetDevTapInterfaceStats(net->ifname, stats,
!virDomainNetTypeSharesHostView(net)) < 
0)
@@ -19818,6 +19824,7 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driver 
ATTRIBUTE_UNUSED,
 {
 size_t i;
 struct _virDomainInterfaceStats tmp;
+char *vf_ifname = NULL;
 int ret = -1;
 
 if (!virDomainObjIsActive(dom))
@@ -19830,21 +19837,39 @@ 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(, 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, net->ifname);
+else
+QEMU_ADD_NAME_PARAM(record, maxparams,
+"net", "name", i, vf_ifname);
 
 if (actualType == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
 if (virNetDevOpenvswitchInterfaceStats(net->ifname, ) < 0) {
 virResetLastError();
 continue;
 }
+} else if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+if (virNetdevHostdevVFRIfStats(vf_ifname, ,
+ 

[libvirt] [PATCH v3 0/2] Support network stats for VF representor interface

2018-04-04 Thread Jai Singh Rana
With availability of switchdev model in linux, it is possible to capture
stats for SR-IOV device with interface_type as 'hostdev' provided device
supports VF represontor in switchdev mode[1] on host.

These stats are supported by adding helper APIs for getting/verifying VF
representor name based on PCI Bus:Device:Function information in domains
'hostdev' structure and querying required net sysfs directory and file
entries on host according to switchdev model. These helper APIs are then
used in qemu/conf to get the interface stats for VF representor on host
of pci SR-IOV device.

[1]  https://www.kernel.org/doc/Documentation/networking/switchdev.txt
V2   https://www.redhat.com/archives/libvir-list/2018-February/msg00561.html

Jai Singh Rana (2):
  util: Add helper APIs to get/verify VF Representor name
  qemu: conf: Network stats support for VF Representors

 docs/news.xml   |   9 ++
 po/POTFILES.in  |   1 +
 src/conf/domain_conf.c  |  15 ++
 src/libvirt_private.syms|   7 +
 src/qemu/qemu_driver.c  |  33 +++-
 src/util/Makefile.inc.am|   2 +
 src/util/virhostdev.c   |   2 +-
 src/util/virhostdev.h   |   8 +
 src/util/virnetdevhostdev.c | 374 
 src/util/virnetdevhostdev.h |  35 +
 10 files changed, 481 insertions(+), 5 deletions(-)
 create mode 100644 src/util/virnetdevhostdev.c
 create mode 100644 src/util/virnetdevhostdev.h

-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2 2/2] qemu: conf: Network stats support for hostdev VF Representor

2018-02-21 Thread Jai Singh Rana
Again thanks for the feedback for this patch set. Helps me a lot. Will
take care feedback
 in v3.

On Wed, Feb 21, 2018 at 4:00 AM, John Ferlan <jfer...@redhat.com> wrote:
>
>
> On 02/12/2018 03:07 AM, Jai Singh Rana wrote:
>> In case of , return stats if its a Switchdev
>> VF Representor interface of pci SR-IOV device.
>> ---
>> v2 fixes bracket spacing in domain_conf.c
>>
>>  src/conf/domain_conf.c |  7 +++
>>  src/qemu/qemu_driver.c | 34 ++
>>  2 files changed, 37 insertions(+), 4 deletions(-)
>>
>> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
>> index fb732a0c2..b553c5a2f 100644
>> --- a/src/conf/domain_conf.c
>> +++ b/src/conf/domain_conf.c
>> @@ -58,6 +58,7 @@
>>  #include "virnetdev.h"
>>  #include "virnetdevmacvlan.h"
>>  #include "virhostdev.h"
>> +#include "virnetdevhostdev.h"
>>  #include "virmdev.h"
>>
>>  #define VIR_FROM_THIS VIR_FROM_DOMAIN
>> @@ -28112,6 +28113,12 @@ virDomainNetFind(virDomainDefPtr def, const char 
>> *device)
>>  return net;
>>  }
>>
>> +/* Give a try to hostdev */
>> +for (i = 0; i < def->nnets; i++) {
>
> If there's 10 nnets and 1 nhostdev, things are not going to end well.
>
>> +if (!virNetdevHostdevCheckVFRepIFName(def->hostdevs[i], device))
>> +return def->nets[i];
>
> Wait, what?
>
>> +}
>> +
>

Agree. I need to iterate over nhostdevs as well to map prpoerly.

> Even w/ the correct usage - there's more than just one caller that could
> get an answer it wasn't expecting... Limit your usage to where you need
> this type of check...
>
>>  virReportError(VIR_ERR_INVALID_ARG,
>> _("'%s' is not a known interface"), device);
>>  return NULL;
>> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
>> index bbce5bd81..24484ab92 100644
>> --- a/src/qemu/qemu_driver.c
>> +++ b/src/qemu/qemu_driver.c
>> @@ -67,6 +67,7 @@
>>  #include "virhostcpu.h"
>>  #include "virhostmem.h"
>>  #include "virnetdevtap.h"
>> +#include "virnetdevhostdev.h"
>>  #include "virnetdevopenvswitch.h"
>>  #include "capabilities.h"
>>  #include "viralloc.h"
>> @@ -11153,6 +11154,11 @@ 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) {
>> +if (virNetdevHostdevVFRepInterfaceStats(device, stats,
>> +
>> !virDomainNetTypeSharesHostView
>> +(net)) < 0)
>> +goto cleanup;
>
> So you've hidden virNetdevHostdevVFRepInterfaceStats as a call to
> virNetDevTapInterfaceStats via the #define in virnetdevhostdev.h
>
> You need to figure out a different, better, more standard, non-hack
> mechanism for this.  Rather than the virDomainNetFind adjustment above,
> this is where you should be more explicit.

Yes it doesn't look good. I wasn't sure whether this was even allowed
but used it to avoid
duplicate code for virNetDevTapInterfaceStats in virnetdevhostdev.c
Need to take care of this in v3.

>
>>  } else {
>>  if (virNetDevTapInterfaceStats(net->ifname, stats,
>> 
>> !virDomainNetTypeSharesHostView(net)) < 0)
>> @@ -19794,6 +19800,7 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driver 
>> ATTRIBUTE_UNUSED,
>>  {
>>  size_t i;
>>  struct _virDomainInterfaceStats tmp;
>> +char *vf_representor_ifname = NULL;
>
> Can we go with just vf_ifname?
>
>>  int ret = -1;
>>
>>  if (!virDomainObjIsActive(dom))
>> @@ -19806,21 +19813,40 @@ 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) {
>> +if (virNetdevHostdevGetVFRepIFName(dom->def->hostdevs[i],
>> +   _representor_ifname))
>
> Ei

Re: [libvirt] [PATCH v2 1/2] util: Add helper APIs to get/verify VF Representor name

2018-02-21 Thread Jai Singh Rana
Thanks John for a very detailed review and feedback for this patch set.  As this
is my first patch submission to libvirt, I was really looking for the review
from the community and this review is really helpful and informing. I agree
with concerns and suggestions highlighted and will prepare v3 to address them.

-Jai

On Wed, Feb 21, 2018 at 4:00 AM, John Ferlan <jfer...@redhat.com> wrote:
>
>
> On 02/12/2018 03:07 AM, Jai Singh Rana wrote:
>> Switchdev VF Representor interface name on host is derived based on BDF
>> of pci SR-IOV device in 'hostdev' and querying required net sysfs
>> entries on host.
>
> Really short for what's being added here.
>
> Not sure what BDF is...
>
> s/pci/PCI

>
> Essentially this seems to be an interface for certain hostdev's with
> certain attributes in order to be able to return specific attributes.
> Please try to describe a few more details.
>
> Oh and you need a patch 3 to adjust the "docs/news.xml" to describe the
> enhancement.
>

BDF refers to BUS:DEVICE:FUNCTION in pci address. Will surely prepare a
more informed description in v3 for this feature.

>> ---
>> v2 includes commented code cleanup in virnetdevhostdev.c
>>
>>  po/POTFILES.in  |   1 +
>>  src/Makefile.am |   1 +
>>  src/libvirt_private.syms|   5 +
>>  src/util/virhostdev.c   |  11 +++
>>  src/util/virhostdev.h   |   6 ++
>>  src/util/virnetdevhostdev.c | 224 
>> 
>>  src/util/virnetdevhostdev.h |  33 +++
>>  7 files changed, 281 insertions(+)
>>  create mode 100644 src/util/virnetdevhostdev.c
>>  create mode 100644 src/util/virnetdevhostdev.h
>>
>
> Not in my wheelhouse of knowledge, but I do have some comments...
>
>> diff --git a/po/POTFILES.in b/po/POTFILES.in
>> index 285955469..73ce73397 100644
>> --- a/po/POTFILES.in
>> +++ b/po/POTFILES.in
>> @@ -237,6 +237,7 @@ src/util/virnetdevmacvlan.c
>>  src/util/virnetdevmidonet.c
>>  src/util/virnetdevopenvswitch.c
>>  src/util/virnetdevtap.c
>> +src/util/virnetdevhostdev.c
>>  src/util/virnetdevveth.c
>>  src/util/virnetdevvportprofile.c
>>  src/util/virnetlink.c
>> diff --git a/src/Makefile.am b/src/Makefile.am
>> index db68e01db..0f3c3f1bc 100644
>> --- a/src/Makefile.am
>> +++ b/src/Makefile.am
>> @@ -148,6 +148,7 @@ UTIL_SOURCES = \
>>   util/virnetdev.h util/virnetdev.c \
>>   util/virnetdevbandwidth.h util/virnetdevbandwidth.c \
>>   util/virnetdevbridge.h util/virnetdevbridge.c \
>> + util/virnetdevhostdev.h util/virnetdevhostdev.c \
>>   util/virnetdevip.h util/virnetdevip.c \
>>   util/virnetdevmacvlan.c util/virnetdevmacvlan.h \
>>   util/virnetdevmidonet.h util/virnetdevmidonet.c \
>> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
>> index 3b14d7d15..d9bc8ad72 100644
>> --- a/src/libvirt_private.syms
>> +++ b/src/libvirt_private.syms
>> @@ -2288,6 +2288,11 @@ virNetDevBridgeSetSTPDelay;
>>  virNetDevBridgeSetVlanFiltering;
>>
>>
>> +# util/virnetdevhostdev.h
>> +virNetdevHostdevCheckVFRepIFName;
>> +virNetdevHostdevGetVFRepIFName;
>> +
>> +
>>  # util/virnetdevip.h
>>  virNetDevIPAddrAdd;
>>  virNetDevIPAddrDel;
>> diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
>> index a12224c58..b6d824d07 100644
>> --- a/src/util/virhostdev.c
>> +++ b/src/util/virhostdev.c
>> @@ -351,6 +351,17 @@ virHostdevNetDevice(virDomainHostdevDefPtr hostdev,
>>  }
>>
>>
>> +/* Non static wrapper for virHostdevNetDevice to use outside virhostdev */
>> +int
>> +virHostdevNetDeviceWrapper(virDomainHostdevDefPtr hostdev,
>> +int pfNetDevIdx,
>> +char **linkdev,
>> +int *vf)
>
> 1. Arguments have incorrect indentation
>
> 2. Why not remove static from virHostdevNetDevice instead? and add it to
> libvirt_private.syms and add prototype in virhostdev.h?
>
> IOW: I see no need for this wrapper.
>

I agree this doesn't look good. I was not sure whether removing static
from above
mentioned function in virhostdev.c is allowed.

>> +{
>> +return virHostdevNetDevice(hostdev, pfNetDevIdx, linkdev, vf);
>> +}
>> +
>> +
>>  static bool
>>  virHostdevIsPCINetDevice(virDomainHostdevDefPtr hostdev)
>>  {
>> diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
>> index 54e1c66be..7dc860a85 100644
>> --- a/src/util/virhostdev.h
>> +++ b/s

[libvirt] [PATCH v2 0/2] Support network stats for hostdev(SR-IOV) in Switchdev mode

2018-02-12 Thread Jai Singh Rana
With availability of switchdev model in linux, it is possible to capture
stats for hostdev SR-IOV VFs using its VF representor interface name on
host for nics supporting switchdev model.

These stats are supported by adding helper APIs for getting VF
Representor name based on BDF info in 'hostdev' and querying required
net sysfs entries on host. These helper APIs are then used in
qemu_driver to get the hostdev interface stats for pci SR-IOV device.

[1] https://www.kernel.org/doc/Documentation/networking/switchdev.txt

Jai Singh Rana (2):
  util: Add helper APIs to get/verify VF Representor name
  qemu: conf: Network stats support for hostdev VF Representor

 po/POTFILES.in  |   1 +
 src/Makefile.am |   1 +
 src/conf/domain_conf.c  |   7 ++
 src/libvirt_private.syms|   5 +
 src/qemu/qemu_driver.c  |  34 ++-
 src/util/virhostdev.c   |  11 +++
 src/util/virhostdev.h   |   6 ++
 src/util/virnetdevhostdev.c | 224 
 src/util/virnetdevhostdev.h |  33 +++
 9 files changed, 318 insertions(+), 4 deletions(-)
 create mode 100644 src/util/virnetdevhostdev.c
 create mode 100644 src/util/virnetdevhostdev.h

-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 2/2] qemu: conf: Network stats support for hostdev VF Representor

2018-02-12 Thread Jai Singh Rana
In case of , return stats if its a Switchdev
VF Representor interface of pci SR-IOV device.
---
v2 fixes bracket spacing in domain_conf.c

 src/conf/domain_conf.c |  7 +++
 src/qemu/qemu_driver.c | 34 ++
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fb732a0c2..b553c5a2f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -58,6 +58,7 @@
 #include "virnetdev.h"
 #include "virnetdevmacvlan.h"
 #include "virhostdev.h"
+#include "virnetdevhostdev.h"
 #include "virmdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
@@ -28112,6 +28113,12 @@ virDomainNetFind(virDomainDefPtr def, const char 
*device)
 return net;
 }
 
+/* Give a try to hostdev */
+for (i = 0; i < def->nnets; i++) {
+if (!virNetdevHostdevCheckVFRepIFName(def->hostdevs[i], device))
+return def->nets[i];
+}
+
 virReportError(VIR_ERR_INVALID_ARG,
_("'%s' is not a known interface"), device);
 return NULL;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index bbce5bd81..24484ab92 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -67,6 +67,7 @@
 #include "virhostcpu.h"
 #include "virhostmem.h"
 #include "virnetdevtap.h"
+#include "virnetdevhostdev.h"
 #include "virnetdevopenvswitch.h"
 #include "capabilities.h"
 #include "viralloc.h"
@@ -11153,6 +11154,11 @@ 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) {
+if (virNetdevHostdevVFRepInterfaceStats(device, stats,
+!virDomainNetTypeSharesHostView
+(net)) < 0)
+goto cleanup;
 } else {
 if (virNetDevTapInterfaceStats(net->ifname, stats,
!virDomainNetTypeSharesHostView(net)) < 
0)
@@ -19794,6 +19800,7 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driver 
ATTRIBUTE_UNUSED,
 {
 size_t i;
 struct _virDomainInterfaceStats tmp;
+char *vf_representor_ifname = NULL;
 int ret = -1;
 
 if (!virDomainObjIsActive(dom))
@@ -19806,21 +19813,40 @@ 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) {
+if (virNetdevHostdevGetVFRepIFName(dom->def->hostdevs[i],
+   _representor_ifname))
+continue;
+}
+else if (!net->ifname)
 continue;
 
 memset(, 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, net->ifname);
+else
+QEMU_ADD_NAME_PARAM(record, maxparams,
+"net", "name", i, vf_representor_ifname);
 
 if (actualType == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
 if (virNetDevOpenvswitchInterfaceStats(net->ifname, ) < 0) {
 virResetLastError();
 continue;
 }
+} else if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+if (virNetdevHostdevVFRepInterfaceStats
+(vf_representor_ifname, ,
+ !virDomainNetTypeSharesHostView(net)) < 0) {
+VIR_FREE(vf_representor_ifname);
+virResetLastError();
+continue;
+}
+VIR_FREE(vf_representor_ifname);
 } else {
 if (virNetDevTapInterfaceStats(net->ifname, ,

!virDomainNetTypeSharesHostView(net)) < 0) {
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v2 1/2] util: Add helper APIs to get/verify VF Representor name

2018-02-12 Thread Jai Singh Rana
Switchdev VF Representor interface name on host is derived based on BDF
of pci SR-IOV device in 'hostdev' and querying required net sysfs
entries on host.
---
v2 includes commented code cleanup in virnetdevhostdev.c

 po/POTFILES.in  |   1 +
 src/Makefile.am |   1 +
 src/libvirt_private.syms|   5 +
 src/util/virhostdev.c   |  11 +++
 src/util/virhostdev.h   |   6 ++
 src/util/virnetdevhostdev.c | 224 
 src/util/virnetdevhostdev.h |  33 +++
 7 files changed, 281 insertions(+)
 create mode 100644 src/util/virnetdevhostdev.c
 create mode 100644 src/util/virnetdevhostdev.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 285955469..73ce73397 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -237,6 +237,7 @@ src/util/virnetdevmacvlan.c
 src/util/virnetdevmidonet.c
 src/util/virnetdevopenvswitch.c
 src/util/virnetdevtap.c
+src/util/virnetdevhostdev.c
 src/util/virnetdevveth.c
 src/util/virnetdevvportprofile.c
 src/util/virnetlink.c
diff --git a/src/Makefile.am b/src/Makefile.am
index db68e01db..0f3c3f1bc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -148,6 +148,7 @@ UTIL_SOURCES = \
util/virnetdev.h util/virnetdev.c \
util/virnetdevbandwidth.h util/virnetdevbandwidth.c \
util/virnetdevbridge.h util/virnetdevbridge.c \
+   util/virnetdevhostdev.h util/virnetdevhostdev.c \
util/virnetdevip.h util/virnetdevip.c \
util/virnetdevmacvlan.c util/virnetdevmacvlan.h \
util/virnetdevmidonet.h util/virnetdevmidonet.c \
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 3b14d7d15..d9bc8ad72 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2288,6 +2288,11 @@ virNetDevBridgeSetSTPDelay;
 virNetDevBridgeSetVlanFiltering;
 
 
+# util/virnetdevhostdev.h
+virNetdevHostdevCheckVFRepIFName;
+virNetdevHostdevGetVFRepIFName;
+
+
 # util/virnetdevip.h
 virNetDevIPAddrAdd;
 virNetDevIPAddrDel;
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index a12224c58..b6d824d07 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -351,6 +351,17 @@ virHostdevNetDevice(virDomainHostdevDefPtr hostdev,
 }
 
 
+/* Non static wrapper for virHostdevNetDevice to use outside virhostdev */
+int
+virHostdevNetDeviceWrapper(virDomainHostdevDefPtr hostdev,
+int pfNetDevIdx,
+char **linkdev,
+int *vf)
+{
+return virHostdevNetDevice(hostdev, pfNetDevIdx, linkdev, vf);
+}
+
+
 static bool
 virHostdevIsPCINetDevice(virDomainHostdevDefPtr hostdev)
 {
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index 54e1c66be..7dc860a85 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -202,5 +202,11 @@ int virHostdevPCINodeDeviceReAttach(virHostdevManagerPtr 
mgr,
 int virHostdevPCINodeDeviceReset(virHostdevManagerPtr mgr,
  virPCIDevicePtr pci)
 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+int
+virHostdevNetDeviceWrapper(virDomainHostdevDefPtr hostdev,
+int pfNetDevIdx,
+char **linkdev,
+int *vf)
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
 
 #endif /* __VIR_HOSTDEV_H__ */
diff --git a/src/util/virnetdevhostdev.c b/src/util/virnetdevhostdev.c
new file mode 100644
index 0..243c78a97
--- /dev/null
+++ b/src/util/virnetdevhostdev.c
@@ -0,0 +1,224 @@
+/*
+ * virnetdevhostdev.c: utilities to get/verify Switchdev VF Representor
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "virhostdev.h"
+#include "virnetdevhostdev.h"
+#include "viralloc.h"
+#include "virstring.h"
+#include "virfile.h"
+#include "virerror.h"
+#include "virlog.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+VIR_LOG_INIT("util.netdevhostdev");
+
+#ifndef IFNAMSIZ
+#define IFNAMSIZ 16
+#endif
+
+#define IFSWITCHIDSIZ 20
+
+#ifndef SYSFS_NET_DIR
+#define SYSFS_NET_DIR "/sys/class/net/"
+#endif
+
+
+/**
+ * virNetdevHostdevNetSysfsPath
+ *
+ * @pf_name: netdev name of the physical function (PF)
+ * @vf: virtual function (VF) number for the device of interest
+ * @vf_representor: name of the VF representor interface
+ *
+ * Finds the VF representor name 

[libvirt] [PATCH 2/2] qemu: conf: Network stats support for hostdev VF Representor

2018-02-09 Thread Jai Singh Rana
In case of , return stats if its a Switchdev
VF Representor interface of pci SR-IOV device.
---
 src/conf/domain_conf.c |  7 +++
 src/qemu/qemu_driver.c | 34 ++
 2 files changed, 37 insertions(+), 4 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fb732a0c2..649fc2eb8 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -58,6 +58,7 @@
 #include "virnetdev.h"
 #include "virnetdevmacvlan.h"
 #include "virhostdev.h"
+#include "virnetdevhostdev.h"
 #include "virmdev.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
@@ -28112,6 +28113,12 @@ virDomainNetFind(virDomainDefPtr def, const char 
*device)
 return net;
 }
 
+/* Give a try to hostdev */
+for (i = 0; i < def->nnets; i++) {
+if(!virNetdevHostdevCheckVFRepIFName(def->hostdevs[i], device))
+return def->nets[i];
+}
+
 virReportError(VIR_ERR_INVALID_ARG,
_("'%s' is not a known interface"), device);
 return NULL;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 978ecd4e0..3a3a9c986 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -67,6 +67,7 @@
 #include "virhostcpu.h"
 #include "virhostmem.h"
 #include "virnetdevtap.h"
+#include "virnetdevhostdev.h"
 #include "virnetdevopenvswitch.h"
 #include "capabilities.h"
 #include "viralloc.h"
@@ -11153,6 +11154,11 @@ 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) {
+if (virNetdevHostdevVFRepInterfaceStats(device, stats,
+!virDomainNetTypeSharesHostView
+(net)) < 0)
+goto cleanup;
 } else {
 if (virNetDevTapInterfaceStats(net->ifname, stats,
!virDomainNetTypeSharesHostView(net)) < 
0)
@@ -19794,6 +19800,7 @@ qemuDomainGetStatsInterface(virQEMUDriverPtr driver 
ATTRIBUTE_UNUSED,
 {
 size_t i;
 struct _virDomainInterfaceStats tmp;
+char *vf_representor_ifname = NULL;
 int ret = -1;
 
 if (!virDomainObjIsActive(dom))
@@ -19806,21 +19813,40 @@ 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) {
+if (virNetdevHostdevGetVFRepIFName(dom->def->hostdevs[i],
+   _representor_ifname))
+continue;
+}
+else if (!net->ifname)
 continue;
 
 memset(, 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, net->ifname);
+else
+QEMU_ADD_NAME_PARAM(record, maxparams,
+"net", "name", i, vf_representor_ifname);
 
 if (actualType == VIR_DOMAIN_NET_TYPE_VHOSTUSER) {
 if (virNetDevOpenvswitchInterfaceStats(net->ifname, ) < 0) {
 virResetLastError();
 continue;
 }
+} else if (actualType == VIR_DOMAIN_NET_TYPE_HOSTDEV) {
+if (virNetdevHostdevVFRepInterfaceStats
+(vf_representor_ifname, ,
+ !virDomainNetTypeSharesHostView(net)) < 0) {
+VIR_FREE(vf_representor_ifname);
+virResetLastError();
+continue;
+}
+VIR_FREE(vf_representor_ifname);
 } else {
 if (virNetDevTapInterfaceStats(net->ifname, ,

!virDomainNetTypeSharesHostView(net)) < 0) {
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH 1/2] util: Add helper APIs to get/verify VF Representor name

2018-02-09 Thread Jai Singh Rana
Switchdev VF Representor interface name on host is derived based on BDF
of pci SR-IOV device in 'hostdev' and querying required net sysfs
entries on host.
---
 po/POTFILES.in  |   1 +
 src/Makefile.am |   1 +
 src/libvirt_private.syms|   5 +
 src/util/virhostdev.c   |  10 ++
 src/util/virhostdev.h   |   6 +
 src/util/virnetdevhostdev.c | 284 
 src/util/virnetdevhostdev.h |  33 +
 7 files changed, 340 insertions(+)
 create mode 100644 src/util/virnetdevhostdev.c
 create mode 100644 src/util/virnetdevhostdev.h

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 285955469..73ce73397 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -237,6 +237,7 @@ src/util/virnetdevmacvlan.c
 src/util/virnetdevmidonet.c
 src/util/virnetdevopenvswitch.c
 src/util/virnetdevtap.c
+src/util/virnetdevhostdev.c
 src/util/virnetdevveth.c
 src/util/virnetdevvportprofile.c
 src/util/virnetlink.c
diff --git a/src/Makefile.am b/src/Makefile.am
index db68e01db..0f3c3f1bc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -148,6 +148,7 @@ UTIL_SOURCES = \
util/virnetdev.h util/virnetdev.c \
util/virnetdevbandwidth.h util/virnetdevbandwidth.c \
util/virnetdevbridge.h util/virnetdevbridge.c \
+   util/virnetdevhostdev.h util/virnetdevhostdev.c \
util/virnetdevip.h util/virnetdevip.c \
util/virnetdevmacvlan.c util/virnetdevmacvlan.h \
util/virnetdevmidonet.h util/virnetdevmidonet.c \
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 3b14d7d15..d9bc8ad72 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2288,6 +2288,11 @@ virNetDevBridgeSetSTPDelay;
 virNetDevBridgeSetVlanFiltering;
 
 
+# util/virnetdevhostdev.h
+virNetdevHostdevCheckVFRepIFName;
+virNetdevHostdevGetVFRepIFName;
+
+
 # util/virnetdevip.h
 virNetDevIPAddrAdd;
 virNetDevIPAddrDel;
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index a12224c58..7a90779f0 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -350,6 +350,16 @@ virHostdevNetDevice(virDomainHostdevDefPtr hostdev,
 return ret;
 }
 
+/* Non static wrapper for virHostdevNetDevice to use outside filescope */
+int
+virHostdevNetDeviceWrapper(virDomainHostdevDefPtr hostdev,
+int pfNetDevIdx,
+char **linkdev,
+int *vf)
+{
+return virHostdevNetDevice(hostdev, pfNetDevIdx, linkdev, vf);
+}
+
 
 static bool
 virHostdevIsPCINetDevice(virDomainHostdevDefPtr hostdev)
diff --git a/src/util/virhostdev.h b/src/util/virhostdev.h
index 54e1c66be..7dc860a85 100644
--- a/src/util/virhostdev.h
+++ b/src/util/virhostdev.h
@@ -202,5 +202,11 @@ int virHostdevPCINodeDeviceReAttach(virHostdevManagerPtr 
mgr,
 int virHostdevPCINodeDeviceReset(virHostdevManagerPtr mgr,
  virPCIDevicePtr pci)
 ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+int
+virHostdevNetDeviceWrapper(virDomainHostdevDefPtr hostdev,
+int pfNetDevIdx,
+char **linkdev,
+int *vf)
+ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
 
 #endif /* __VIR_HOSTDEV_H__ */
diff --git a/src/util/virnetdevhostdev.c b/src/util/virnetdevhostdev.c
new file mode 100644
index 0..ecf4b7d8f
--- /dev/null
+++ b/src/util/virnetdevhostdev.c
@@ -0,0 +1,284 @@
+/* 
+ * virnetdevhostdev.c: utilities to get/verify Switchdev VF Representor
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * .
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include "virhostdev.h"
+#include "virnetdevhostdev.h"
+#include "viralloc.h"
+#include "virstring.h"
+#include "virfile.h"
+#include "virerror.h"
+#include "virlog.h"
+
+#define VIR_FROM_THIS VIR_FROM_NONE
+
+VIR_LOG_INIT("util.netdevhostdev");
+
+#ifndef IFNAMSIZ
+#define IFNAMSIZ 16
+#endif
+
+#define IFSWITCHIDSIZ 20
+
+#ifndef SYSFS_NET_DIR
+#define SYSFS_NET_DIR "/sys/class/net/"
+#endif
+
+#if 0
+static int
+virNetdevHostdevPCISysfsPath(virDomainHostdevDefPtr hostdev,
+ char **sysfs_path)
+{
+virPCIDeviceAddress config_address;
+
+config_address.domain = hostdev->source.subsys.u.pci.addr.domain;
+config_address.bus = hostdev->source.subsys.u.pci.addr.bus;

[libvirt] [PATCH 0/2] Support network stats for hostdev(SR-IOV) in Switchdev mode

2018-02-09 Thread Jai Singh Rana
With availability of switchdev model in linux, it is possible to capture
stats for hostdev SR-IOV VFs using its VF representor interface name on
host for nics supporting switchdev model.

These stats are supported by adding helper APIs for getting VF
Representor name based on BDF info in 'hostdev' and querying required
net sysfs entries on host. These helper APIs are then used in
qemu_driver to get the hostdev interface stats for pci SR-IOV device.

[1] https://www.kernel.org/doc/Documentation/networking/switchdev.txt

Jai Singh Rana (2):
  util: Add helper APIs to get/verify VF Representor name
  qemu: conf: Network stats support for hostdev VF Representor

 po/POTFILES.in  |   1 +
 src/Makefile.am |   1 +
 src/conf/domain_conf.c  |   7 ++
 src/libvirt_private.syms|   5 +
 src/qemu/qemu_driver.c  |  34 +-
 src/util/virhostdev.c   |  10 ++
 src/util/virhostdev.h   |   6 +
 src/util/virnetdevhostdev.c | 284 
 src/util/virnetdevhostdev.h |  33 +
 9 files changed, 377 insertions(+), 4 deletions(-)
 create mode 100644 src/util/virnetdevhostdev.c
 create mode 100644 src/util/virnetdevhostdev.h

-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] Support interface network stats for SR-IOV in Switchdev mode(VF representors)

2018-02-07 Thread Jai Singh Rana
After deriving VF representor name on host based on BDF info in
'hostdev' and querying net sysfs entries, virNetDevTapInterfaceStats
defined in virnetdevtap.c already serves the purpose for returning
stats based on interface name.

Is it ok to define a macro as follows to avoid duplicate code or shall
I copy this  function definition as
virNetdevHostdevVFRepInterfaceStats in new file virNetdevhostdev.c to
rule out any dependency on virnetdevtap.

#define virNetdevHostdevVFRepInterfaceStats virNetDevTapInterfaceStats

Thanks,

Jai

On Wed, Jan 31, 2018 at 5:20 PM, Jai Singh Rana <jai.r...@gmail.com> wrote:
> Thanks Daniel for the feedback.
>
> On Wed, Jan 31, 2018 at 5:07 PM, Daniel P. Berrangé <berra...@redhat.com> 
> wrote:
>> On Wed, Jan 31, 2018 at 05:02:59PM +0530, Jai Singh Rana wrote:
>>> Hi All,
>>>
>>> Currently libvirt does not support networks interface stats for
>>> .
>>>
>>> With availability of switchdev model in linux, it is possible to
>>> capture stats for SR-IOV VFs on host using its VF representor
>>> interface on host for nics supporting switchdev model.
>>>
>>> https://github.com/torvalds/linux/blob/master/Documentation/networking/switchdev.txt
>>>
>>> I want to preapre a patch supporting this feature for hostdev and
>>> write some function like
>>> 'virHostdevSwitchdevVfRepresentorInterfaceStats' for returning stats.
>>> Should I include this function and supporting methods in
>>> src/util/virhostdev.c or should i include it in new file something
>>> like src/util/virswitchdev.c .
>>
>> It is probably best as  src/util/virnetdevhostdev.c
>>
>> Regards,
>> Daniel
>> --
>> |: https://berrange.com  -o-https://www.flickr.com/photos/dberrange 
>> :|
>> |: https://libvirt.org -o-https://fstop138.berrange.com 
>> :|
>> |: https://entangle-photo.org-o-https://www.instagram.com/dberrange 
>> :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] Support interface network stats for SR-IOV in Switchdev mode(VF representors)

2018-01-31 Thread Jai Singh Rana
Thanks Daniel for the feedback.

On Wed, Jan 31, 2018 at 5:07 PM, Daniel P. Berrangé <berra...@redhat.com> wrote:
> On Wed, Jan 31, 2018 at 05:02:59PM +0530, Jai Singh Rana wrote:
>> Hi All,
>>
>> Currently libvirt does not support networks interface stats for
>> .
>>
>> With availability of switchdev model in linux, it is possible to
>> capture stats for SR-IOV VFs on host using its VF representor
>> interface on host for nics supporting switchdev model.
>>
>> https://github.com/torvalds/linux/blob/master/Documentation/networking/switchdev.txt
>>
>> I want to preapre a patch supporting this feature for hostdev and
>> write some function like
>> 'virHostdevSwitchdevVfRepresentorInterfaceStats' for returning stats.
>> Should I include this function and supporting methods in
>> src/util/virhostdev.c or should i include it in new file something
>> like src/util/virswitchdev.c .
>
> It is probably best as  src/util/virnetdevhostdev.c
>
> Regards,
> Daniel
> --
> |: https://berrange.com  -o-https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org -o-https://fstop138.berrange.com :|
> |: https://entangle-photo.org-o-https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] Support interface network stats for SR-IOV in Switchdev mode(VF representors)

2018-01-31 Thread Jai Singh Rana
Hi All,

Currently libvirt does not support networks interface stats for
.

With availability of switchdev model in linux, it is possible to
capture stats for SR-IOV VFs on host using its VF representor
interface on host for nics supporting switchdev model.

https://github.com/torvalds/linux/blob/master/Documentation/networking/switchdev.txt

I want to preapre a patch supporting this feature for hostdev and
write some function like
'virHostdevSwitchdevVfRepresentorInterfaceStats' for returning stats.
Should I include this function and supporting methods in
src/util/virhostdev.c or should i include it in new file something
like src/util/virswitchdev.c .


Thanks,
Jai

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list