[libvirt PATCH v2 2/3] nodedev: refactor virMediatedDeviceGetIOMMUGroupNum()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently virMediatedDeviceGetIOMMUGroupDev() looks up the iommu group
number and uses that to construct a path to the iommu group device.
virMediatedDeviceGetIOMMUGroupNum() then uses that device path and takes
the basename to get the group number. That's unnecessary extra string
manipulation for *GroupNum(). Reverse the implementations and make
*GroupDev() call *GroupNum().

Signed-off-by: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
Reviewed-by: Laine Stump <laine@xxxxxxxxxx>
---
 src/util/virmdev.c | 38 +++++++++++++++++---------------------
 1 file changed, 17 insertions(+), 21 deletions(-)

diff --git a/src/util/virmdev.c b/src/util/virmdev.c
index 5f112c775f..fb89b80da4 100644
--- a/src/util/virmdev.c
+++ b/src/util/virmdev.c
@@ -201,42 +201,38 @@ virMediatedDeviceGetPath(virMediatedDevice *dev)
 char *
 virMediatedDeviceGetIOMMUGroupDev(const char *uuidstr)
 {
-    g_autofree char *result_path = NULL;
-    g_autofree char *result_file = NULL;
-    g_autofree char *iommu_path = NULL;
-    g_autofree char *dev_path = virMediatedDeviceGetSysfsPath(uuidstr);
-
-    iommu_path = g_strdup_printf("%s/iommu_group", dev_path);
-
-    if (!virFileExists(iommu_path)) {
-        virReportSystemError(errno, _("failed to access '%s'"), iommu_path);
-        return NULL;
-    }
+    int group_num = virMediatedDeviceGetIOMMUGroupNum(uuidstr);
 
-    if (virFileResolveLink(iommu_path, &result_path) < 0) {
-        virReportSystemError(errno, _("failed to resolve '%s'"), iommu_path);
+    if (group_num < 0)
         return NULL;
-    }
-
-    result_file = g_path_get_basename(result_path);
 
-    return g_strdup_printf("/dev/vfio/%s", result_file);
+    return g_strdup_printf("/dev/vfio/%i", group_num);
 }
 
 
 int
 virMediatedDeviceGetIOMMUGroupNum(const char *uuidstr)
 {
-    g_autofree char *vfio_path = NULL;
+    g_autofree char *result_path = NULL;
     g_autofree char *group_num_str = NULL;
+    g_autofree char *iommu_path = NULL;
+    g_autofree char *dev_path = virMediatedDeviceGetSysfsPath(uuidstr);
     unsigned int group_num = -1;
 
-    if (!(vfio_path = virMediatedDeviceGetIOMMUGroupDev(uuidstr)))
+    iommu_path = g_strdup_printf("%s/iommu_group", dev_path);
+
+    if (!virFileExists(iommu_path)) {
+        virReportSystemError(errno, _("failed to access '%s'"), iommu_path);
+        return -1;
+    }
+
+    if (virFileResolveLink(iommu_path, &result_path) < 0) {
+        virReportSystemError(errno, _("failed to resolve '%s'"), iommu_path);
         return -1;
+    }
 
-    group_num_str = g_path_get_basename(vfio_path);
+    group_num_str = g_path_get_basename(result_path);
     ignore_value(virStrToLong_ui(group_num_str, NULL, 10, &group_num));
-
     return group_num;
 }
 
-- 
2.26.3




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux