From mboxrd@z Thu Jan 1 00:00:00 1970 From: Zhenyu Wang Subject: [libvirt] [PATCH v3 3/6] vfio/mdev: Add "aggregated_instances" attribute for supported mdev device Date: Wed, 17 Oct 2018 17:00:05 +0800 Message-ID: <20181017090008.16282-4-zhenyuw@linux.intel.com> References: <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 , Kirti Wankhede , Cornelia Huck , intel-gvt-dev@lists.freedesktop.org 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 created by "aggregate" parameter, this creates new mdev device attribute "aggregated_instances" to show number of aggregated instances allocated. v2: - change attribute name as "aggregated_instances" v3: - create only for aggregated allocation Cc: Kirti Wankhede Cc: Alex Williamson Cc: Kevin Tian Cc: Cornelia Huck Signed-off-by: Zhenyu Wang --- drivers/vfio/mdev/mdev_sysfs.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/vfio/mdev/mdev_sysfs.c b/drivers/vfio/mdev/mdev_sysfs.c index a329d6ab6cb9..f03bdfbf5a42 100644 --- a/drivers/vfio/mdev/mdev_sysfs.c +++ b/drivers/vfio/mdev/mdev_sysfs.c @@ -292,7 +292,17 @@ static ssize_t remove_store(struct device *dev, struct device_attribute *attr, return count; } +static ssize_t +aggregated_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(aggregated_instances); static const struct attribute *mdev_device_attrs[] = { &dev_attr_remove.attr, @@ -301,6 +311,7 @@ static const struct attribute *mdev_device_attrs[] = { int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type) { + struct mdev_device *mdev = to_mdev_device(dev); int ret; ret = sysfs_create_link(type->devices_kobj, &dev->kobj, dev_name(dev)); @@ -315,8 +326,17 @@ int mdev_create_sysfs_files(struct device *dev, struct mdev_type *type) if (ret) goto create_files_failed; + if (mdev->type_instances > 1) { + ret = sysfs_create_file(&dev->kobj, + &dev_attr_aggregated_instances.attr); + if (ret) + goto create_aggregated_failed; + } + return ret; +create_aggregated_failed: + sysfs_remove_files(&dev->kobj, mdev_device_attrs); create_files_failed: sysfs_remove_link(&dev->kobj, "mdev_type"); type_link_failed: -- 2.19.1