diff mbox series

[v3,3/5] mdev: Expose mdev alias in sysfs tree

Message ID 20190902042436.23294-4-parav@mellanox.com
State Not Applicable
Delegated to: David Miller
Headers show
Series Introduce variable length mdev alias | expand

Commit Message

Parav Pandit Sept. 2, 2019, 4:24 a.m. UTC
Expose the optional alias for an mdev device as a sysfs attribute.
This way, userspace tools such as udev may make use of the alias, for
example to create a netdevice name for the mdev.

Updated documentation for optional read only sysfs attribute.

Signed-off-by: Parav Pandit <parav@mellanox.com>

---
Changelog:
v2->v3:
 - Merged sysfs documentation patch with sysfs addition
 - Added more description for alias return value
v0->v1:
 - Addressed comments from Cornelia Huck
 - Updated commit description
---
 Documentation/driver-api/vfio-mediated-device.rst |  9 +++++++++
 drivers/vfio/mdev/mdev_sysfs.c                    | 13 +++++++++++++
 2 files changed, 22 insertions(+)

Comments

Cornelia Huck Sept. 17, 2019, 10:08 a.m. UTC | #1
On Sun,  1 Sep 2019 23:24:34 -0500
Parav Pandit <parav@mellanox.com> wrote:

> Expose the optional alias for an mdev device as a sysfs attribute.
> This way, userspace tools such as udev may make use of the alias, for
> example to create a netdevice name for the mdev.
> 
> Updated documentation for optional read only sysfs attribute.
> 
> Signed-off-by: Parav Pandit <parav@mellanox.com>
> 
> ---
> Changelog:
> v2->v3:
>  - Merged sysfs documentation patch with sysfs addition
>  - Added more description for alias return value
> v0->v1:
>  - Addressed comments from Cornelia Huck
>  - Updated commit description
> ---
>  Documentation/driver-api/vfio-mediated-device.rst |  9 +++++++++
>  drivers/vfio/mdev/mdev_sysfs.c                    | 13 +++++++++++++
>  2 files changed, 22 insertions(+)
> 

(...)

> @@ -281,6 +282,14 @@ Example::
>  
>  	# echo 1 > /sys/bus/mdev/devices/$mdev_UUID/remove
>  
> +* alias (read only, optional)
> +Whenever a parent requested to generate an alias, each mdev device of such

s/such/that/

> +parent is assigned unique alias by the mdev core.

s/unique alias/a unique alias/

> +This file shows the alias of the mdev device.
> +
> +Reading file either returns valid alias when assigned or returns error code

s/file/this file/
s/valid alias/a valid alias/
s/error code/the error code/

> +-EOPNOTSUPP when unsupported.
> +
>  Mediated device Hot plug
>  ------------------------

With the nits above fixed,
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
diff mbox series

Patch

diff --git a/Documentation/driver-api/vfio-mediated-device.rst b/Documentation/driver-api/vfio-mediated-device.rst
index 25eb7d5b834b..0b7d2bf843b6 100644
--- a/Documentation/driver-api/vfio-mediated-device.rst
+++ b/Documentation/driver-api/vfio-mediated-device.rst
@@ -270,6 +270,7 @@  Directories and Files Under the sysfs for Each mdev Device
          |--- remove
          |--- mdev_type {link to its type}
          |--- vendor-specific-attributes [optional]
+         |--- alias
 
 * remove (write only)
 
@@ -281,6 +282,14 @@  Example::
 
 	# echo 1 > /sys/bus/mdev/devices/$mdev_UUID/remove
 
+* alias (read only, optional)
+Whenever a parent requested to generate an alias, each mdev device of such
+parent is assigned unique alias by the mdev core.
+This file shows the alias of the mdev device.
+
+Reading file either returns valid alias when assigned or returns error code
+-EOPNOTSUPP when unsupported.
+
 Mediated device Hot plug
 ------------------------
 
diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c
index 43afe0e80b76..59f4e3cc5233 100644
--- a/drivers/vfio/mdev/mdev_sysfs.c
+++ b/drivers/vfio/mdev/mdev_sysfs.c
@@ -246,7 +246,20 @@  static ssize_t remove_store(struct device *dev, struct device_attribute *attr,
 
 static DEVICE_ATTR_WO(remove);
 
+static ssize_t alias_show(struct device *device,
+			  struct device_attribute *attr, char *buf)
+{
+	struct mdev_device *dev = mdev_from_dev(device);
+
+	if (!dev->alias)
+		return -EOPNOTSUPP;
+
+	return sprintf(buf, "%s\n", dev->alias);
+}
+static DEVICE_ATTR_RO(alias);
+
 static const struct attribute *mdev_device_attrs[] = {
+	&dev_attr_alias.attr,
 	&dev_attr_remove.attr,
 	NULL,
 };