Extract virPCIGetMdevTypes from PCI as virMediatedDeviceGetMdevTypes
into mdev for later reuse.
Signed-off-by: Boris Fiuczynski <fiuczy(a)linux.ibm.com>
Reviewed-by: Bjoern Walk <bwalk(a)linux.ibm.com>
---
src/conf/node_device_conf.c | 2 +-
src/libvirt_private.syms | 2 +-
src/util/virmdev.c | 65 +++++++++++++++++++++++++++++++++++++
src/util/virmdev.h | 4 +++
src/util/virpci.c | 60 ----------------------------------
src/util/virpci.h | 3 --
6 files changed, 71 insertions(+), 65 deletions(-)
diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 3fbe9338ee..db1258436a 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -2584,7 +2584,7 @@ virNodeDeviceGetPCIMdevTypesCaps(const char *sysfspath,
pci_dev->nmdev_types = 0;
pci_dev->flags &= ~VIR_NODE_DEV_CAP_FLAG_PCI_MDEV;
- rc = virPCIGetMdevTypes(sysfspath, &types);
+ rc = virMediatedDeviceGetMdevTypes(sysfspath, &types);
if (rc <= 0)
return rc;
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 95e50835ad..9029ea4fa2 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -2509,6 +2509,7 @@ virMediatedDeviceAttrNew;
virMediatedDeviceFree;
virMediatedDeviceGetIOMMUGroupDev;
virMediatedDeviceGetIOMMUGroupNum;
+virMediatedDeviceGetMdevTypes;
virMediatedDeviceGetSysfsPath;
virMediatedDeviceGetUsedBy;
virMediatedDeviceIsUsed;
@@ -2845,7 +2846,6 @@ virPCIELinkSpeedTypeFromString;
virPCIELinkSpeedTypeToString;
virPCIGetDeviceAddressFromSysfsLink;
virPCIGetHeaderType;
-virPCIGetMdevTypes;
virPCIGetNetName;
virPCIGetPhysicalFunction;
virPCIGetVirtualFunctionIndex;
diff --git a/src/util/virmdev.c b/src/util/virmdev.c
index 31994631ed..80f5f2a767 100644
--- a/src/util/virmdev.c
+++ b/src/util/virmdev.c
@@ -522,3 +522,68 @@ void virMediatedDeviceAttrFree(virMediatedDeviceAttrPtr attr)
g_free(attr->value);
g_free(attr);
}
+
+
+#ifdef __linux__
+
+ssize_t
+virMediatedDeviceGetMdevTypes(const char *sysfspath,
+ virMediatedDeviceTypePtr **types)
+{
+ ssize_t ret = -1;
+ int dirret = -1;
+ DIR *dir = NULL;
+ struct dirent *entry;
+ g_autofree char *types_path = NULL;
+ g_autoptr(virMediatedDeviceType) mdev_type = NULL;
+ virMediatedDeviceTypePtr *mdev_types = NULL;
+ size_t ntypes = 0;
+ size_t i;
+
+ types_path = g_strdup_printf("%s/mdev_supported_types", sysfspath);
+
+ if ((dirret = virDirOpenIfExists(&dir, types_path)) < 0)
+ goto cleanup;
+
+ if (dirret == 0) {
+ ret = 0;
+ goto cleanup;
+ }
+
+ while ((dirret = virDirRead(dir, &entry, types_path)) > 0) {
+ g_autofree char *tmppath = NULL;
+ /* append the type id to the path and read the attributes from there */
+ tmppath = g_strdup_printf("%s/%s", types_path, entry->d_name);
+
+ if (virMediatedDeviceTypeReadAttrs(tmppath, &mdev_type) < 0)
+ goto cleanup;
+
+ if (VIR_APPEND_ELEMENT(mdev_types, ntypes, mdev_type) < 0)
+ goto cleanup;
+ }
+
+ if (dirret < 0)
+ goto cleanup;
+
+ *types = g_steal_pointer(&mdev_types);
+ ret = ntypes;
+ ntypes = 0;
+ cleanup:
+ for (i = 0; i < ntypes; i++)
+ virMediatedDeviceTypeFree(mdev_types[i]);
+ VIR_FREE(mdev_types);
+ VIR_DIR_CLOSE(dir);
+ return ret;
+}
+
+#else
+
+ssize_t
+virMediatedDeviceGetMdevTypes(const char *sysfspath G_GNUC_UNUSED,
+ virMediatedDeviceTypePtr **types G_GNUC_UNUSED)
+{
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
+ return -1;
+}
+
+#endif /* __linux__ */
diff --git a/src/util/virmdev.h b/src/util/virmdev.h
index eb167ccb48..846e1662e7 100644
--- a/src/util/virmdev.h
+++ b/src/util/virmdev.h
@@ -149,5 +149,9 @@ int
virMediatedDeviceTypeReadAttrs(const char *sysfspath,
virMediatedDeviceTypePtr *type);
+ssize_t
+virMediatedDeviceGetMdevTypes(const char *sysfspath,
+ virMediatedDeviceTypePtr **types);
+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDevice, virMediatedDeviceFree);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virMediatedDeviceType, virMediatedDeviceTypeFree);
diff --git a/src/util/virpci.c b/src/util/virpci.c
index 1f679a7b45..2086a4270b 100644
--- a/src/util/virpci.c
+++ b/src/util/virpci.c
@@ -2528,57 +2528,6 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
return 0;
}
-
-ssize_t
-virPCIGetMdevTypes(const char *sysfspath,
- virMediatedDeviceTypePtr **types)
-{
- ssize_t ret = -1;
- int dirret = -1;
- DIR *dir = NULL;
- struct dirent *entry;
- g_autofree char *types_path = NULL;
- g_autoptr(virMediatedDeviceType) mdev_type = NULL;
- virMediatedDeviceTypePtr *mdev_types = NULL;
- size_t ntypes = 0;
- size_t i;
-
- types_path = g_strdup_printf("%s/mdev_supported_types", sysfspath);
-
- if ((dirret = virDirOpenIfExists(&dir, types_path)) < 0)
- goto cleanup;
-
- if (dirret == 0) {
- ret = 0;
- goto cleanup;
- }
-
- while ((dirret = virDirRead(dir, &entry, types_path)) > 0) {
- g_autofree char *tmppath = NULL;
- /* append the type id to the path and read the attributes from there */
- tmppath = g_strdup_printf("%s/%s", types_path, entry->d_name);
-
- if (virMediatedDeviceTypeReadAttrs(tmppath, &mdev_type) < 0)
- goto cleanup;
-
- if (VIR_APPEND_ELEMENT(mdev_types, ntypes, mdev_type) < 0)
- goto cleanup;
- }
-
- if (dirret < 0)
- goto cleanup;
-
- *types = g_steal_pointer(&mdev_types);
- ret = ntypes;
- ntypes = 0;
- cleanup:
- for (i = 0; i < ntypes; i++)
- virMediatedDeviceTypeFree(mdev_types[i]);
- VIR_FREE(mdev_types);
- VIR_DIR_CLOSE(dir);
- return ret;
-}
-
#else
static const char *unsupported = N_("not supported on non-linux platforms");
@@ -2653,15 +2602,6 @@ virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path
G_GNUC_UNUSED,
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return -1;
}
-
-
-ssize_t
-virPCIGetMdevTypes(const char *sysfspath G_GNUC_UNUSED,
- virMediatedDeviceTypePtr **types G_GNUC_UNUSED)
-{
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
- return -1;
-}
#endif /* __linux__ */
int
diff --git a/src/util/virpci.h b/src/util/virpci.h
index 1f896ca481..43828b0a8a 100644
--- a/src/util/virpci.h
+++ b/src/util/virpci.h
@@ -275,9 +275,6 @@ int virPCIGetHeaderType(virPCIDevicePtr dev, int *hdrType);
void virPCIEDeviceInfoFree(virPCIEDeviceInfoPtr dev);
-ssize_t virPCIGetMdevTypes(const char *sysfspath,
- virMediatedDeviceType ***types);
-
void virPCIDeviceAddressFree(virPCIDeviceAddressPtr address);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virPCIDevice, virPCIDeviceFree);
--
2.25.1