From mboxrd@z Thu Jan 1 00:00:00 1970 From: Zhenyu Wang Subject: [libvirt] [PATCH v2 2/4] vfio/mdev: Add mdev device instances attribute Date: Fri, 20 Jul 2018 10:19:26 +0800 Message-ID: <20180720021928.15343-3-zhenyuw@linux.intel.com> References: <20180620074039.10539-1-zhenyuw@linux.intel.com> <20180720021928.15343-1-zhenyuw@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: kevin.tian@intel.com, intel-gvt-dev@lists.freedesktop.org, kwankhede@nvidia.com To: libvirt-list@redhat.com, kvm@vger.kernel.org Return-path: In-Reply-To: <20180720021928.15343-1-zhenyuw@linux.intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com List-Id: kvm.vger.kernel.org For mdev device, create new sysfs attribute "instances" to show number of instances allocated for possible aggregation type. For compatibility default or without aggregated allocation, the number is 1. Cc: Kirti Wankhede Cc: Alex Williamson Cc: Kevin Tian Signed-off-by: Zhenyu Wang --- drivers/vfio/mdev/mdev_core.c | 1 + drivers/vfio/mdev/mdev_private.h | 1 + drivers/vfio/mdev/mdev_sysfs.c | 8 ++++++++ 3 files changed, 10 insertions(+) diff --git a/drivers/vfio/mdev/mdev_core.c b/drivers/vfio/mdev/mdev_core.c index e69db302a4f2..f0478fc372d8 100644 --- a/drivers/vfio/mdev/mdev_core.c +++ b/drivers/vfio/mdev/mdev_core.c @@ -326,6 +326,7 @@ int mdev_device_create(struct kobject *kobj, struct device *dev, uuid_le uuid, mdev->dev.bus = &mdev_bus_type; mdev->dev.release = mdev_device_release; dev_set_name(&mdev->dev, "%pUl", uuid.b); + mdev->type_instances = instances; ret = device_register(&mdev->dev); if (ret) { diff --git a/drivers/vfio/mdev/mdev_private.h b/drivers/vfio/mdev/mdev_private.h index c9d3fe04e273..aa0b4b64c503 100644 --- a/drivers/vfio/mdev/mdev_private.h +++ b/drivers/vfio/mdev/mdev_private.h @@ -33,6 +33,7 @@ struct mdev_device { struct kref ref; struct list_head next; struct kobject *type_kobj; + unsigned int type_instances; bool active; }; diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index a06e5b7c69d3..5a417a20e774 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -268,10 +268,18 @@ static ssize_t remove_store(struct device *dev, struct device_attribute *attr, return count; } +static ssize_t instances_show(struct device *dev, struct device_attribute *attr, char *buf) +{ + struct mdev_device *mdev = to_mdev_device(dev); + return sprintf(buf, "%u\n", mdev->type_instances); +} + static DEVICE_ATTR_WO(remove); +static DEVICE_ATTR_RO(instances); static const struct attribute *mdev_device_attrs[] = { &dev_attr_remove.attr, + &dev_attr_instances.attr, NULL, }; -- 2.18.0