]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: refactor mdev_types method from PCI to mdev
authorBoris Fiuczynski <fiuczy@linux.ibm.com>
Fri, 23 Oct 2020 17:31:44 +0000 (19:31 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 4 Nov 2020 18:11:49 +0000 (19:11 +0100)
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>
src/conf/node_device_conf.c
src/libvirt_private.syms
src/util/virmdev.c
src/util/virmdev.h
src/util/virpci.c
src/util/virpci.h

index 77dcd1635923f89fb9d0950ba0927884b58e75ee..dbb87737bb85c229e6c0a4117e8459313fdecfaf 100644 (file)
@@ -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;
index 95e50835ada1bdb1148f23ded242053c9c0b82b7..9029ea4fa242e99a7bacb4cec5eab9ec3c12d51e 100644 (file)
@@ -2509,6 +2509,7 @@ virMediatedDeviceAttrNew;
 virMediatedDeviceFree;
 virMediatedDeviceGetIOMMUGroupDev;
 virMediatedDeviceGetIOMMUGroupNum;
+virMediatedDeviceGetMdevTypes;
 virMediatedDeviceGetSysfsPath;
 virMediatedDeviceGetUsedBy;
 virMediatedDeviceIsUsed;
@@ -2845,7 +2846,6 @@ virPCIELinkSpeedTypeFromString;
 virPCIELinkSpeedTypeToString;
 virPCIGetDeviceAddressFromSysfsLink;
 virPCIGetHeaderType;
-virPCIGetMdevTypes;
 virPCIGetNetName;
 virPCIGetPhysicalFunction;
 virPCIGetVirtualFunctionIndex;
index 31994631eda6bd3c98fe255df72a8fca5d7383f1..3ed65f2abf2cd28e181ee467958ec1479286a971 100644 (file)
@@ -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__ */
index eb167ccb481f93a27436742fdca156481647af05..846e1662e75d90b0914344c918237fceaee05508 100644 (file)
@@ -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);
index a501db6ff7644698148ef6c4dfaf6365a4ef5d4d..b63abac8cc5bfd24cdcc09779bee3b8c226238c9 100644 (file)
@@ -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
index 1f896ca4813b975452b7eae029259f4605ea24df..43828b0a8a2ab181d12b58b07626e5d4229f2a1b 100644 (file)
@@ -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);