On 01/25/2018 10:23 AM, Erik Skultety wrote:
> 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/util/virmdev.c | 34 ++++++++++++++++++++++++++++++++++
> src/util/virmdev.h | 5 +++++
> 2 files changed, 39 insertions(+)
>
> diff --git a/src/util/virmdev.c b/src/util/virmdev.c
> index db679b8a6..b57cc3ed9 100644
> --- a/src/util/virmdev.c
> +++ b/src/util/virmdev.c
> @@ -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) \
Drop this backward slash.
> +
> + 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;
> +}
> diff --git a/src/util/virmdev.h b/src/util/virmdev.h
> index 320610ab9..01ab02e75 100644
> --- a/src/util/virmdev.h
> +++ b/src/util/virmdev.h
> @@ -129,4 +129,9 @@ virMediatedDeviceListMarkDevices(virMediatedDeviceListPtr dst,
>
> void
> virMediatedDeviceTypeFree(virMediatedDeviceTypePtr type);
> +
> +int
> +virMediatedDeviceTypeReadAttrs(const char *sysfspath,
> + virMediatedDeviceTypePtr *type);
ACK if you also expose the function in libvirt_private.syms.
Michal
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list