Thread (5 messages) flat view 5 messages, 4 authors, 2021-12-24

RE: [PATCH] vdpa: regist vhost-vdpa dev class

From: Longpeng (Mike, Cloud Infrastructure Service Product Dept.) <hidden>
Date: 2021-12-23 15:53:13
Also in: kvm, lkml

quoted hunk ↗ jump to hunk
-----Original Message-----
From: Yi Wang [mailto:wang.yi59@zte.com.cn]
Sent: Thursday, December 23, 2021 3:32 PM
To: mst@redhat.com
Cc: jasowang@redhat.com; kvm@vger.kernel.org;
virtualization@lists.linux-foundation.org; netdev@vger.kernel.org;
linux-kernel@vger.kernel.org; xue.zhihong@zte.com.cn; wang.yi59@zte.com.cn;
wang.liang82@zte.com.cn; Zhang Min [off-list ref]
Subject: [PATCH] vdpa: regist vhost-vdpa dev class

From: Zhang Min <redacted>

Some applications like kata-containers need to acquire MAJOR/MINOR/DEVNAME
for devInfo [1], so regist vhost-vdpa dev class to expose uevent.

1.
https://github.com/kata-containers/kata-containers/blob/main/src/runtime/vi
rtcontainers/device/config/config.go

Signed-off-by: Zhang Min <redacted>
Signed-off-by: Yi Wang <redacted>
---
 drivers/vhost/vdpa.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c
index fb41db3da611..90fbad93e7a2 100644
--- a/drivers/vhost/vdpa.c
+++ b/drivers/vhost/vdpa.c
@@ -1012,6 +1012,7 @@ static void vhost_vdpa_release_dev(struct device *device)
 	kfree(v);
 }

+static struct class *vhost_vdpa_class;
 static int vhost_vdpa_probe(struct vdpa_device *vdpa)
 {
 	const struct vdpa_config_ops *ops = vdpa->config;
@@ -1040,6 +1041,7 @@ static int vhost_vdpa_probe(struct vdpa_device *vdpa)
 	v->dev.release = vhost_vdpa_release_dev;
 	v->dev.parent = &vdpa->dev;
 	v->dev.devt = MKDEV(MAJOR(vhost_vdpa_major), minor);
+	v->dev.class = vhost_vdpa_class;
 	v->vqs = kmalloc_array(v->nvqs, sizeof(struct vhost_virtqueue),
 			       GFP_KERNEL);
 	if (!v->vqs) {
@@ -1097,6 +1099,14 @@ static int __init vhost_vdpa_init(void)
 {
 	int r;

+	vhost_vdpa_class = class_create(THIS_MODULE, "vhost-vdpa");
+	if (IS_ERR(vhost_vdpa_class)) {
+		r = PTR_ERR(vhost_vdpa_class);
+		pr_warn("vhost vdpa class create error %d,  maybe mod reinserted\n", r);
+		vhost_vdpa_class = NULL;
Unnecessary to reset?
quoted hunk ↗ jump to hunk
+		return r;
+	}
+
 	r = alloc_chrdev_region(&vhost_vdpa_major, 0, VHOST_VDPA_DEV_MAX,
 				"vhost-vdpa");
 	if (r)
@@ -1111,6 +1121,7 @@ static int __init vhost_vdpa_init(void)
 err_vdpa_register_driver:
 	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
 err_alloc_chrdev:
+	class_destroy(vhost_vdpa_class);
 	return r;
 }
 module_init(vhost_vdpa_init);
@@ -1118,6 +1129,7 @@ module_init(vhost_vdpa_init);
 static void __exit vhost_vdpa_exit(void)
 {
 	vdpa_unregister_driver(&vhost_vdpa_driver);
+	class_destroy(vhost_vdpa_class);
 	unregister_chrdev_region(vhost_vdpa_major, VHOST_VDPA_DEV_MAX);
 }
 module_exit(vhost_vdpa_exit);
--
2.27.0
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help