mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-25 01:34:11 +03:00
util: refactor mdev_types method from PCI to mdev
Extract virPCIGetMdevTypes from PCI as virMediatedDeviceGetMdevTypes into mdev for later reuse. Signed-off-by: Boris Fiuczynski <fiuczy@linux.ibm.com> Reviewed-by: Bjoern Walk <bwalk@linux.ibm.com> Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
689ff3c6c6
commit
65c1f47760
@ -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;
|
||||
|
@ -2509,6 +2509,7 @@ virMediatedDeviceAttrNew;
|
||||
virMediatedDeviceFree;
|
||||
virMediatedDeviceGetIOMMUGroupDev;
|
||||
virMediatedDeviceGetIOMMUGroupNum;
|
||||
virMediatedDeviceGetMdevTypes;
|
||||
virMediatedDeviceGetSysfsPath;
|
||||
virMediatedDeviceGetUsedBy;
|
||||
virMediatedDeviceIsUsed;
|
||||
@ -2845,7 +2846,6 @@ virPCIELinkSpeedTypeFromString;
|
||||
virPCIELinkSpeedTypeToString;
|
||||
virPCIGetDeviceAddressFromSysfsLink;
|
||||
virPCIGetHeaderType;
|
||||
virPCIGetMdevTypes;
|
||||
virPCIGetNetName;
|
||||
virPCIGetPhysicalFunction;
|
||||
virPCIGetVirtualFunctionIndex;
|
||||
|
@ -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__ */
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user