[PATCH rdma-next 06/16] RDMA/core: Simplify restrack interface

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

 



From: Leon Romanovsky <leonro@xxxxxxxxxxxx>

In current implementation, we have one restrack root per-device and
all users are simply proving it as is. Let's simplify the interface and
allow them to provide Ib device and internally access restrack_root.

Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx>
---
 drivers/infiniband/core/device.c   |  4 ++--
 drivers/infiniband/core/nldev.c    |  4 ++--
 drivers/infiniband/core/restrack.c | 12 ++++++------
 include/rdma/restrack.h            | 13 +++++++------
 4 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 8db61372b7c4..4527db43d4f5 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -291,7 +291,7 @@ struct ib_device *ib_alloc_device(size_t size)
 	if (!device)
 		return NULL;
 
-	rdma_restrack_init(&device->res);
+	rdma_restrack_init(device);
 
 	device->dev.class = &ib_class;
 	device_initialize(&device->dev);
@@ -321,7 +321,7 @@ void ib_dealloc_device(struct ib_device *device)
 	WARN_ON(!list_empty(&device->client_data_list));
 	WARN_ON(device->reg_state != IB_DEV_UNREGISTERED &&
 		device->reg_state != IB_DEV_UNINITIALIZED);
-	rdma_restrack_clean(&device->res);
+	rdma_restrack_clean(device);
 	put_device(&device->dev);
 }
 EXPORT_SYMBOL(ib_dealloc_device);
diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index 0869285e8949..7f9d0be47122 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -314,7 +314,6 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device)
 		[RDMA_RESTRACK_CTX] = "ctx",
 	};
 
-	struct rdma_restrack_root *res = &device->res;
 	struct nlattr *table_attr;
 	int ret, i, curr;
 
@@ -328,7 +327,8 @@ static int fill_res_info(struct sk_buff *msg, struct ib_device *device)
 	for (i = 0; i < RDMA_RESTRACK_MAX; i++) {
 		if (!names[i])
 			continue;
-		curr = rdma_restrack_count(res, i, task_active_pid_ns(current));
+		curr = rdma_restrack_count(device, i,
+					   task_active_pid_ns(current));
 		ret = fill_res_info_entry(msg, names[i], curr);
 		if (ret)
 			goto err;
diff --git a/drivers/infiniband/core/restrack.c b/drivers/infiniband/core/restrack.c
index 2812c18c0fd3..a4f0432cf774 100644
--- a/drivers/infiniband/core/restrack.c
+++ b/drivers/infiniband/core/restrack.c
@@ -18,8 +18,9 @@ static int fill_res_noop(struct sk_buff *msg,
 	return 0;
 }
 
-void rdma_restrack_init(struct rdma_restrack_root *res)
+void rdma_restrack_init(struct ib_device *dev)
 {
+	struct rdma_restrack_root *res = &dev->res;
 	int i;
 
 	for (i = 0 ; i < RDMA_RESTRACK_MAX; i++)
@@ -43,11 +44,11 @@ static const char *type2str(enum rdma_restrack_type type)
 	return names[type];
 };
 
-void rdma_restrack_clean(struct rdma_restrack_root *res)
+void rdma_restrack_clean(struct ib_device *dev)
 {
+	struct rdma_restrack_root *res = &dev->res;
 	struct rdma_restrack_entry *e;
 	char buf[TASK_COMM_LEN];
-	struct ib_device *dev;
 	bool found = false;
 	const char *owner;
 	int i;
@@ -57,7 +58,6 @@ void rdma_restrack_clean(struct rdma_restrack_root *res)
 			unsigned long index = 0;
 
 			if (!found) {
-				dev = container_of(res, struct ib_device, res);
 				pr_err("restrack: %s", CUT_HERE);
 				dev_err(&dev->dev, "BUG: RESTRACK detected leak of resources\n");
 			}
@@ -87,10 +87,10 @@ void rdma_restrack_clean(struct rdma_restrack_root *res)
 		pr_err("restrack: %s", CUT_HERE);
 }
 
-int rdma_restrack_count(struct rdma_restrack_root *res,
-			enum rdma_restrack_type type,
+int rdma_restrack_count(struct ib_device *dev, enum rdma_restrack_type type,
 			struct pid_namespace *ns)
 {
+	struct rdma_restrack_root *res = &dev->res;
 	struct rdma_restrack_entry *e;
 	unsigned long index = 0;
 	u32 cnt = 0;
diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h
index 4b7a9634ca52..d8d7ea48a91b 100644
--- a/include/rdma/restrack.h
+++ b/include/rdma/restrack.h
@@ -49,6 +49,7 @@ enum rdma_restrack_type {
 	RDMA_RESTRACK_MAX
 };
 
+struct ib_device;
 struct rdma_restrack_entry;
 
 /**
@@ -124,23 +125,23 @@ struct rdma_restrack_entry {
 
 /**
  * rdma_restrack_init() - initialize resource tracking
- * @res:  resource tracking root
+ * @dev:  IB device
  */
-void rdma_restrack_init(struct rdma_restrack_root *res);
+void rdma_restrack_init(struct ib_device *dev);
 
 /**
  * rdma_restrack_clean() - clean resource tracking
- * @res:  resource tracking root
+ * @dev:  IB device
  */
-void rdma_restrack_clean(struct rdma_restrack_root *res);
+void rdma_restrack_clean(struct ib_device *dev);
 
 /**
  * rdma_restrack_count() - the current usage of specific object
- * @res:  resource entry
+ * @dev:  IB device
  * @type: actual type of object to operate
  * @ns:   PID namespace
  */
-int rdma_restrack_count(struct rdma_restrack_root *res,
+int rdma_restrack_count(struct ib_device *dev,
 			enum rdma_restrack_type type,
 			struct pid_namespace *ns);
 
-- 
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