[PATCH rdma-next v2 10/10] RDMA/core: Support core port attributes in non init_net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Parav Pandit <parav@xxxxxxxxxxxx>

Now that sysfs compatibility layer for non init_net exists, add
core port attributes such as pkey and gid table to non init_net ns.

Signed-off-by: Parav Pandit <parav@xxxxxxxxxxxx>
Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx>
---
 drivers/infiniband/core/compat_sysfs.c |  6 ++++++
 drivers/infiniband/core/core_priv.h    |  6 ++++++
 drivers/infiniband/core/sysfs.c        | 23 +++++++++++++----------
 3 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/drivers/infiniband/core/compat_sysfs.c b/drivers/infiniband/core/compat_sysfs.c
index 305a898bf97a..8d77e9f86593 100644
--- a/drivers/infiniband/core/compat_sysfs.c
+++ b/drivers/infiniband/core/compat_sysfs.c
@@ -65,6 +65,11 @@ static void rdma_compatdev_create(struct ib_device *device, struct net *net)
 		kfree(cdev);
 		return;
 	}
+	ret = ib_setup_port_attrs(&cdev->coredev, NULL, false);
+	if (ret) {
+		device_unregister(&cdev->coredev.dev);
+		return;
+	}
 
 	down_write(&rdma_net->compat_rwsem);
 	list_add_tail(&cdev->list, &rdma_net->compatdev_list);
@@ -94,6 +99,7 @@ void rdma_compatdev_add(struct ib_device *device)
 static void remove_one_compatdev(struct ib_compat_device *cdev)
 {
 	list_del(&cdev->list);
+	ib_free_port_attrs(&cdev->coredev);
 	device_unregister(&cdev->coredev.dev);
 }
 
diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h
index b586a7ff3275..6311a58a564b 100644
--- a/drivers/infiniband/core/core_priv.h
+++ b/drivers/infiniband/core/core_priv.h
@@ -335,4 +335,10 @@ void __exit rdma_compat_dev_cleanup(void);
 void rdma_compatdev_add(struct ib_device *device);
 void rdma_compatdev_remove(struct ib_device *device);
 void rdma_compatdev_rename(const struct ib_device *device);
+
+void ib_free_port_attrs(struct ib_core_device *coredev);
+int ib_setup_port_attrs(struct ib_core_device *coredev,
+			int (*port_callback)(struct ib_device *,
+					     u8, struct kobject *),
+			bool alloc_hw_stats);
 #endif /* _CORE_PRIV_H */
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 486219cc5ac4..8e582a8a3128 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -1017,7 +1017,8 @@ static void setup_hw_stats(struct ib_device *device, struct ib_port *port,
 
 static int add_port(struct ib_core_device *coredev, int port_num,
 		    int (*port_callback)(struct ib_device *,
-					 u8, struct kobject *))
+					 u8, struct kobject *),
+		    bool alloc_stats)
 {
 	struct ib_device *device = rdma_device_to_ibdev(&coredev->dev);
 	struct ib_port *p;
@@ -1058,7 +1059,7 @@ static int add_port(struct ib_core_device *coredev, int port_num,
 		goto err_put;
 	}
 
-	if (device->process_mad) {
+	if (device->process_mad && alloc_stats) {
 		p->pma_table = get_counter_table(device, port_num);
 		ret = sysfs_create_group(&p->kobj, p->pma_table);
 		if (ret)
@@ -1125,7 +1126,7 @@ static int add_port(struct ib_core_device *coredev, int port_num,
 	 * port, so holder should be device. Therefore skip per port conunter
 	 * initialization.
 	 */
-	if (device->alloc_hw_stats && port_num)
+	if (device->alloc_hw_stats && port_num && alloc_stats)
 		setup_hw_stats(device, p, port_num);
 
 	list_add_tail(&p->kobj.entry, &coredev->port_list);
@@ -1282,7 +1283,7 @@ const struct attribute_group ib_dev_attr_group = {
 	.attrs = ib_dev_attrs,
 };
 
-static void ib_free_port_attrs(struct ib_core_device *coredev)
+void ib_free_port_attrs(struct ib_core_device *coredev)
 {
 	struct kobject *p, *t;
 
@@ -1309,9 +1310,10 @@ static void ib_free_port_attrs(struct ib_core_device *coredev)
 	kobject_put(coredev->ports_kobj);
 }
 
-static int ib_setup_port_attrs(struct ib_core_device *coredev,
-			       int (*port_callback)(struct ib_device *,
-						    u8, struct kobject *))
+int ib_setup_port_attrs(struct ib_core_device *coredev,
+			int (*port_callback)(struct ib_device *,
+					     u8, struct kobject *),
+			bool alloc_stats)
 {
 	struct ib_device *device = rdma_device_to_ibdev(&coredev->dev);
 	int ret;
@@ -1323,12 +1325,13 @@ static int ib_setup_port_attrs(struct ib_core_device *coredev,
 		return -ENOMEM;
 
 	if (rdma_cap_ib_switch(device)) {
-		ret = add_port(coredev, 0, port_callback);
+		ret = add_port(coredev, 0, port_callback, alloc_stats);
 		if (ret)
 			goto err_put;
 	} else {
 		for (i = 1; i <= device->phys_port_cnt; ++i) {
-			ret = add_port(coredev, i, port_callback);
+			ret = add_port(coredev, i, port_callback,
+				       alloc_stats);
 			if (ret)
 				goto err_put;
 		}
@@ -1351,7 +1354,7 @@ int ib_device_register_sysfs(struct ib_device *device,
 	if (ret)
 		return ret;
 
-	ret = ib_setup_port_attrs(&device->coredev, port_callback);
+	ret = ib_setup_port_attrs(&device->coredev, port_callback, true);
 	if (ret) {
 		device_del(&device->dev);
 		return ret;
-- 
2.19.1




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux