[PATCH] util: mdev: Treat the 'name' sysfs attribute as optional

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

 



When commit 3545cbef moved the sysfs attribute reading logic from
_udev.c module to virmdev.c, it had to replace our udev read wrappers
with the ones available from virfile.c. The problem is that the original
logic worked correctly with udev read wrappers which don't return an
error code for a missing attribute, virfile.c readers however - not so
much. Therefore add another parameter to the macro, so we can again
accept the fact that optional attributes may be missing.

Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
---
 src/util/virmdev.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/util/virmdev.c b/src/util/virmdev.c
index 124933506..688f2efb5 100644
--- a/src/util/virmdev.c
+++ b/src/util/virmdev.c
@@ -505,10 +505,13 @@ virMediatedDeviceTypeReadAttrs(const char *sysfspath,
     int ret = -1;
     virMediatedDeviceTypePtr tmp = NULL;
 
-#define MDEV_GET_SYSFS_ATTR(attr, dst, cb) \
+#define MDEV_GET_SYSFS_ATTR(attr, dst, cb, optional) \
     do { \
-        if (cb(dst, "%s/%s", sysfspath, attr) < 0) \
-            goto cleanup; \
+        errno = 0; \
+        if (cb(dst, "%s/%s", sysfspath, attr) < 0) { \
+            if (errno != ENOENT || !optional) \
+                goto cleanup; \
+        } \
     } while (0)
 
     if (VIR_ALLOC(tmp) < 0)
@@ -517,10 +520,12 @@ virMediatedDeviceTypeReadAttrs(const char *sysfspath,
     if (VIR_STRDUP(tmp->id, last_component(sysfspath)) < 0)
         goto cleanup;
 
-    MDEV_GET_SYSFS_ATTR("name", &tmp->name, virFileReadValueString);
-    MDEV_GET_SYSFS_ATTR("device_api", &tmp->device_api, virFileReadValueString);
+    /* @name sysfs attribute is optional, so getting ENOENT is fine */
+    MDEV_GET_SYSFS_ATTR("name", &tmp->name, virFileReadValueString, true);
+    MDEV_GET_SYSFS_ATTR("device_api", &tmp->device_api,
+                        virFileReadValueString, false);
     MDEV_GET_SYSFS_ATTR("available_instances", &tmp->available_instances,
-                        virFileReadValueUint);
+                        virFileReadValueUint, false);
 
 #undef MDEV_GET_SYSFS_ATTR
 
-- 
2.13.6

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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