diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 77dcd16359..dbb87737bb 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2598,7 +2598,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..3ed65f2abf 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; + g_autoptr(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); + return ret; +} + +#else +static const char *unsupported = N_("not supported on non-linux platforms"); + +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 a501db6ff7..b63abac8cc 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -2506,56 +2506,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; - g_autoptr(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); - return ret; -} - #else static const char *unsupported = N_("not supported on non-linux platforms"); @@ -2630,15 +2580,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);