]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: mdev: Introduce virMediatedDeviceTypeReadAttrs getter
authorErik Skultety <eskultet@redhat.com>
Tue, 23 Jan 2018 08:55:52 +0000 (09:55 +0100)
committerErik Skultety <eskultet@redhat.com>
Mon, 29 Jan 2018 14:34:30 +0000 (15:34 +0100)
This should serve as a replacement for the existing udevFillMdevType
which is responsible for fetching the device type's attributes from the
sysfs interface. The problem with the existing solution is that it's
tied to the udev backend.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
src/libvirt_private.syms
src/util/virmdev.c
src/util/virmdev.h

index fb7635499ff64d9889fbd2aa2683395b7ce3db8d..c52c3ec385c1586873fb57880998ce838a6e3010 100644 (file)
@@ -2182,6 +2182,7 @@ virMediatedDeviceModelTypeToString;
 virMediatedDeviceNew;
 virMediatedDeviceSetUsedBy;
 virMediatedDeviceTypeFree;
+virMediatedDeviceTypeReadAttrs;
 
 
 
index db679b8a6db93ae0102dc2bb4a2fecafe88509e0..1249335067430912a68582762994a21db005be81 100644 (file)
@@ -496,3 +496,37 @@ virMediatedDeviceTypeFree(virMediatedDeviceTypePtr type)
     VIR_FREE(type->device_api);
     VIR_FREE(type);
 }
+
+
+int
+virMediatedDeviceTypeReadAttrs(const char *sysfspath,
+                               virMediatedDeviceTypePtr *type)
+{
+    int ret = -1;
+    virMediatedDeviceTypePtr tmp = NULL;
+
+#define MDEV_GET_SYSFS_ATTR(attr, dst, cb) \
+    do { \
+        if (cb(dst, "%s/%s", sysfspath, attr) < 0) \
+            goto cleanup; \
+    } while (0)
+
+    if (VIR_ALLOC(tmp) < 0)
+        goto cleanup;
+
+    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);
+    MDEV_GET_SYSFS_ATTR("available_instances", &tmp->available_instances,
+                        virFileReadValueUint);
+
+#undef MDEV_GET_SYSFS_ATTR
+
+    VIR_STEAL_PTR(*type, tmp);
+    ret = 0;
+ cleanup:
+    virMediatedDeviceTypeFree(tmp);
+    return ret;
+}
index 320610ab97326a5ed5c293a3b196ca513a209792..01ab02e751b933bdb005014a3455b9e5800dfec6 100644 (file)
@@ -129,4 +129,9 @@ virMediatedDeviceListMarkDevices(virMediatedDeviceListPtr dst,
 
 void
 virMediatedDeviceTypeFree(virMediatedDeviceTypePtr type);
+
+int
+virMediatedDeviceTypeReadAttrs(const char *sysfspath,
+                               virMediatedDeviceTypePtr *type);
+
 #endif /* __VIR_MDEV_H__ */