From: "Daniel P. Berrange" <berrange(a)redhat.com>
Move virNetDevIsVirtualFunction, virNetDevGetVirtualFunctionIndex
and virNetDevGetPhysicalFunction to virnetdev.c
* src/util/interface.c, src/util/interface.h, src/util/virnetdev.c,
src/util/virnetdev.h: Move APIs
---
src/util/interface.c | 146 -------------------------------------------------
src/util/interface.h | 13 -----
src/util/virnetdev.c | 148 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/util/virnetdev.h | 10 ++++
4 files changed, 158 insertions(+), 159 deletions(-)
diff --git a/src/util/interface.c b/src/util/interface.c
index 2882511..00a873e 100644
--- a/src/util/interface.c
+++ b/src/util/interface.c
@@ -45,7 +45,6 @@
#include "virfile.h"
#include "memory.h"
#include "netlink.h"
-#include "pci.h"
#include "logging.h"
#include "virnetdev.h"
@@ -295,148 +294,3 @@ ifaceGetNthParent(int ifindex ATTRIBUTE_UNUSED,
}
#endif
-
-
-#ifdef __linux__
-static int
-virNetDevSysfsFile(char **pf_sysfs_device_link, const char *ifname,
- const char *file)
-{
-
- if (virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/%s",
- ifname, file) < 0) {
- virReportOOMError();
- return -1;
- }
-
- return 0;
-}
-
-static int
-virNetDevSysfsDeviceFile(char **pf_sysfs_device_link, const char *ifname,
- const char *file)
-{
-
- if (virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/device/%s",
- ifname, file) < 0) {
- virReportOOMError();
- return -1;
- }
-
- return 0;
-}
-
-/**
- * virNetDevIsVirtualFunction:
- * @ifname : name of the interface
- *
- * Checks if an interface is a SRIOV virtual function.
- *
- * Returns 1 if interface is SRIOV virtual function, 0 if not and -1 if error
- *
- */
-int
-virNetDevIsVirtualFunction(const char *ifname)
-{
- char *if_sysfs_device_link = NULL;
- int ret = -1;
-
- if (virNetDevSysfsFile(&if_sysfs_device_link, ifname, "device") <
0)
- return ret;
-
- ret = pciDeviceIsVirtualFunction(if_sysfs_device_link);
-
- VIR_FREE(if_sysfs_device_link);
-
- return ret;
-}
-
-/**
- * virNetDevGetVirtualFunctionIndex
- *
- * @pfname : name of the physical function interface name
- * @vfname : name of the virtual function interface name
- * @vf_index : Pointer to int. Contains vf index of interface upon successful
- * return
- *
- * Returns 0 on success, -1 on failure
- *
- */
-int
-virNetDevGetVirtualFunctionIndex(const char *pfname, const char *vfname,
- int *vf_index)
-{
- char *pf_sysfs_device_link = NULL, *vf_sysfs_device_link = NULL;
- int ret = -1;
-
- if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") <
0)
- return ret;
-
- if (virNetDevSysfsFile(&vf_sysfs_device_link, vfname, "device") < 0)
{
- VIR_FREE(pf_sysfs_device_link);
- return ret;
- }
-
- ret = pciGetVirtualFunctionIndex(pf_sysfs_device_link,
- vf_sysfs_device_link,
- vf_index);
-
- VIR_FREE(pf_sysfs_device_link);
- VIR_FREE(vf_sysfs_device_link);
-
- return ret;
-}
-
-/**
- * virNetDevGetPhysicalFunction
- *
- * @ifname : name of the physical function interface name
- * @pfname : Contains sriov physical function for interface ifname
- * upon successful return
- *
- * Returns 0 on success, -1 on failure
- *
- */
-int
-virNetDevGetPhysicalFunction(const char *ifname, char **pfname)
-{
- char *physfn_sysfs_path = NULL;
- int ret = -1;
-
- if (virNetDevSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn") <
0)
- return ret;
-
- ret = pciDeviceNetName(physfn_sysfs_path, pfname);
-
- VIR_FREE(physfn_sysfs_path);
-
- return ret;
-}
-#else /* !__linux__ */
-int
-virNetDevIsVirtualFunction(const char *ifname ATTRIBUTE_UNUSED)
-{
- virReportSystemError(ENOSYS, "%s",
- _("Unable to check virtual function status on this
platfornm"));
- return -1;
-}
-
-int
-virNetDevGetVirtualFunctionIndex(const char *pfname ATTRIBUTE_UNUSED,
- const char *vfname ATTRIBUTE_UNUSED,
- int *vf_index ATTRIBUTE_UNUSED)
-{
- virReportSystemError(ENOSYS, "%s",
- _("Unable to get virtual function index on this
platfornm"));
- return -1;
-}
-
-int
-virNetDevGetPhysicalFunction(const char *ifname ATTRIBUTE_UNUSED,
- char **pfname ATTRIBUTE_UNUSED)
-{
- virReportSystemError(ENOSYS, "%s",
- _("Unable to get physical function status on this
platfornm"));
- return -1;
-}
-#endif /* !__linux__ */
diff --git a/src/util/interface.h b/src/util/interface.h
index 86f9aac..141d19c 100644
--- a/src/util/interface.h
+++ b/src/util/interface.h
@@ -27,8 +27,6 @@ struct nlattr;
# include "datatypes.h"
# include "virsocketaddr.h"
-# define NET_SYSFS "/sys/class/net/"
-
int ifaceMacvtapLinkDump(bool nltarget_kernel, const char *ifname, int ifindex,
struct nlattr **tb, unsigned char **recvbuf,
@@ -40,15 +38,4 @@ int ifaceGetNthParent(int ifindex, const char *ifname, unsigned int
nthParent,
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5)
ATTRIBUTE_NONNULL(6);
-int virNetDevIsVirtualFunction(const char *ifname)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
-
-int virNetDevGetVirtualFunctionIndex(const char *pfname, const char *vfname,
- int *vf_index)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
- ATTRIBUTE_RETURN_CHECK;
-
-int virNetDevGetPhysicalFunction(const char *ifname, char **pfname)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
-
#endif /* __VIR_INTERFACE_H__ */
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 4ad7883..86196a1 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -27,6 +27,7 @@
#include "virterror_internal.h"
#include "command.h"
#include "memory.h"
+#include "pci.h"
#include <sys/ioctl.h>
#ifdef HAVE_NET_IF_H
@@ -933,3 +934,150 @@ int virNetDevValidateConfig(const char *ifname ATTRIBUTE_UNUSED,
return -1;
}
#endif /* ! __linux__ */
+
+
+#ifdef __linux__
+# define NET_SYSFS "/sys/class/net/"
+
+static int
+virNetDevSysfsFile(char **pf_sysfs_device_link, const char *ifname,
+ const char *file)
+{
+
+ if (virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/%s",
+ ifname, file) < 0) {
+ virReportOOMError();
+ return -1;
+ }
+
+ return 0;
+}
+
+static int
+virNetDevSysfsDeviceFile(char **pf_sysfs_device_link, const char *ifname,
+ const char *file)
+{
+
+ if (virAsprintf(pf_sysfs_device_link, NET_SYSFS "%s/device/%s",
+ ifname, file) < 0) {
+ virReportOOMError();
+ return -1;
+ }
+
+ return 0;
+}
+
+/**
+ * virNetDevIsVirtualFunction:
+ * @ifname : name of the interface
+ *
+ * Checks if an interface is a SRIOV virtual function.
+ *
+ * Returns 1 if interface is SRIOV virtual function, 0 if not and -1 if error
+ *
+ */
+int
+virNetDevIsVirtualFunction(const char *ifname)
+{
+ char *if_sysfs_device_link = NULL;
+ int ret = -1;
+
+ if (virNetDevSysfsFile(&if_sysfs_device_link, ifname, "device") <
0)
+ return ret;
+
+ ret = pciDeviceIsVirtualFunction(if_sysfs_device_link);
+
+ VIR_FREE(if_sysfs_device_link);
+
+ return ret;
+}
+
+/**
+ * virNetDevGetVirtualFunctionIndex
+ *
+ * @pfname : name of the physical function interface name
+ * @vfname : name of the virtual function interface name
+ * @vf_index : Pointer to int. Contains vf index of interface upon successful
+ * return
+ *
+ * Returns 0 on success, -1 on failure
+ *
+ */
+int
+virNetDevGetVirtualFunctionIndex(const char *pfname, const char *vfname,
+ int *vf_index)
+{
+ char *pf_sysfs_device_link = NULL, *vf_sysfs_device_link = NULL;
+ int ret = -1;
+
+ if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") <
0)
+ return ret;
+
+ if (virNetDevSysfsFile(&vf_sysfs_device_link, vfname, "device") < 0)
{
+ VIR_FREE(pf_sysfs_device_link);
+ return ret;
+ }
+
+ ret = pciGetVirtualFunctionIndex(pf_sysfs_device_link,
+ vf_sysfs_device_link,
+ vf_index);
+
+ VIR_FREE(pf_sysfs_device_link);
+ VIR_FREE(vf_sysfs_device_link);
+
+ return ret;
+}
+
+/**
+ * virNetDevGetPhysicalFunction
+ *
+ * @ifname : name of the physical function interface name
+ * @pfname : Contains sriov physical function for interface ifname
+ * upon successful return
+ *
+ * Returns 0 on success, -1 on failure
+ *
+ */
+int
+virNetDevGetPhysicalFunction(const char *ifname, char **pfname)
+{
+ char *physfn_sysfs_path = NULL;
+ int ret = -1;
+
+ if (virNetDevSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn") <
0)
+ return ret;
+
+ ret = pciDeviceNetName(physfn_sysfs_path, pfname);
+
+ VIR_FREE(physfn_sysfs_path);
+
+ return ret;
+}
+#else /* !__linux__ */
+int
+virNetDevIsVirtualFunction(const char *ifname ATTRIBUTE_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Unable to check virtual function status on this
platfornm"));
+ return -1;
+}
+
+int
+virNetDevGetVirtualFunctionIndex(const char *pfname ATTRIBUTE_UNUSED,
+ const char *vfname ATTRIBUTE_UNUSED,
+ int *vf_index ATTRIBUTE_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Unable to get virtual function index on this
platfornm"));
+ return -1;
+}
+
+int
+virNetDevGetPhysicalFunction(const char *ifname ATTRIBUTE_UNUSED,
+ char **pfname ATTRIBUTE_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Unable to get physical function status on this
platfornm"));
+ return -1;
+}
+#endif /* !__linux__ */
diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h
index 8628072..13ba1da 100644
--- a/src/util/virnetdev.h
+++ b/src/util/virnetdev.h
@@ -88,5 +88,15 @@ int virNetDevValidateConfig(const char *ifname,
const unsigned char *macaddr, int ifindex)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+int virNetDevIsVirtualFunction(const char *ifname)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+
+int virNetDevGetVirtualFunctionIndex(const char *pfname, const char *vfname,
+ int *vf_index)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3)
+ ATTRIBUTE_RETURN_CHECK;
+
+int virNetDevGetPhysicalFunction(const char *ifname, char **pfname)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
#endif /* __VIR_NETDEV_H__ */
--
1.7.6.4