[PATCH rdma-next v1 06/10] RDMA/core: Prefix ib_ to device_mutex, lists_rwsem, device_list

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

 



From: Parav Pandit <parav@xxxxxxxxxxxx>

Add ib_ prefix to device_mutex, lists_rwsem and device_list to have
unique name and also to represent rdma/ib subsystem, such that
it can be shared using core_priv.h with multiple files of ib_core
module.

Signed-off-by: Parav Pandit <parav@xxxxxxxxxxxx>
Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx>
---
 drivers/infiniband/core/device.c | 118 ++++++++++++++++---------------
 1 file changed, 60 insertions(+), 58 deletions(-)

diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 1b1eba3884d6..e8ae8699cb87 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -65,25 +65,25 @@ struct workqueue_struct *ib_comp_unbound_wq;
 struct workqueue_struct *ib_wq;
 EXPORT_SYMBOL_GPL(ib_wq);
 
-/* The device_list and client_list contain devices and clients after their
+/* The ib_device_list and client_list contain devices and clients after their
  * registration has completed, and the devices and clients are removed
  * during unregistration. */
-static LIST_HEAD(device_list);
+static LIST_HEAD(ib_device_list);
 static LIST_HEAD(client_list);
 
 /*
- * device_mutex and lists_rwsem protect access to both device_list and
- * client_list.  device_mutex protects writer access by device and client
- * registration / de-registration.  lists_rwsem protects reader access to
+ * ib_device_mutex and ib_lists_rwsem protect access to both ib_device_list and
+ * client_list.  ib_device_mutex protects writer access by device and client
+ * registration / de-registration.  ib_lists_rwsem protects reader access to
  * these lists.  Iterators of these lists must lock it for read, while updates
  * to the lists must be done with a write lock. A special case is when the
- * device_mutex is locked. In this case locking the lists for read access is
- * not necessary as the device_mutex implies it.
+ * ib_device_mutex is locked. In this case locking the lists for read access is
+ * not necessary as the ib_device_mutex implies it.
  *
- * lists_rwsem also protects access to the client data list.
+ * ib_lists_rwsem also protects access to the client data list.
  */
-static DEFINE_MUTEX(device_mutex);
-static DECLARE_RWSEM(lists_rwsem);
+static DEFINE_MUTEX(ib_device_mutex);
+static DECLARE_RWSEM(ib_lists_rwsem);
 
 static int ib_security_change(struct notifier_block *nb, unsigned long event,
 			      void *lsm_data);
@@ -137,7 +137,7 @@ static struct ib_device *__ib_device_get_by_index(u32 index)
 {
 	struct ib_device *device;
 
-	list_for_each_entry(device, &device_list, core_list)
+	list_for_each_entry(device, &ib_device_list, core_list)
 		if (device->index == index)
 			return device;
 
@@ -152,14 +152,14 @@ struct ib_device *ib_device_get_by_index(u32 index)
 {
 	struct ib_device *device;
 
-	down_read(&lists_rwsem);
+	down_read(&ib_lists_rwsem);
 	device = __ib_device_get_by_index(index);
 	if (device) {
 		/* Do not return a device if unregistration has started. */
 		if (!refcount_inc_not_zero(&device->refcount))
 			device = NULL;
 	}
-	up_read(&lists_rwsem);
+	up_read(&ib_lists_rwsem);
 	return device;
 }
 
@@ -173,7 +173,7 @@ static struct ib_device *__ib_device_get_by_name(const char *name)
 {
 	struct ib_device *device;
 
-	list_for_each_entry(device, &device_list, core_list)
+	list_for_each_entry(device, &ib_device_list, core_list)
 		if (!strcmp(name, dev_name(&device->dev)))
 			return device;
 
@@ -185,11 +185,13 @@ int ib_device_rename(struct ib_device *ibdev, const char *name)
 	struct ib_device *device;
 	int ret = 0;
 
+	/* If old and new name are same, nothing more to be done */
 	if (!strcmp(name, dev_name(&ibdev->dev)))
 		return ret;
 
-	mutex_lock(&device_mutex);
-	list_for_each_entry(device, &device_list, core_list) {
+	mutex_lock(&ib_device_mutex);
+	/* Make sure no other device with same name exists */
+	list_for_each_entry(device, &ib_device_list, core_list) {
 		if (!strcmp(name, dev_name(&device->dev))) {
 			ret = -EEXIST;
 			goto out;
@@ -201,7 +203,7 @@ int ib_device_rename(struct ib_device *ibdev, const char *name)
 		goto out;
 	strlcpy(ibdev->name, name, IB_DEVICE_NAME_MAX);
 out:
-	mutex_unlock(&device_mutex);
+	mutex_unlock(&ib_device_mutex);
 	return ret;
 }
 
@@ -215,7 +217,7 @@ static int alloc_name(struct ib_device *ibdev, const char *name)
 	if (!inuse)
 		return -ENOMEM;
 
-	list_for_each_entry(device, &device_list, core_list) {
+	list_for_each_entry(device, &ib_device_list, core_list) {
 		char buf[IB_DEVICE_NAME_MAX];
 
 		if (sscanf(dev_name(&device->dev), name, &i) != 1)
@@ -358,11 +360,11 @@ static int add_client_context(struct ib_device *device, struct ib_client *client
 	context->data   = NULL;
 	context->going_down = false;
 
-	down_write(&lists_rwsem);
+	down_write(&ib_lists_rwsem);
 	write_lock_irq(&device->client_data_lock);
 	list_add(&context->list, &device->client_data_list);
 	write_unlock_irq(&device->client_data_lock);
-	up_write(&lists_rwsem);
+	up_write(&ib_lists_rwsem);
 
 	return 0;
 }
@@ -442,8 +444,8 @@ static void ib_policy_change_task(struct work_struct *work)
 {
 	struct ib_device *dev;
 
-	down_read(&lists_rwsem);
-	list_for_each_entry(dev, &device_list, core_list) {
+	down_read(&ib_lists_rwsem);
+	list_for_each_entry(dev, &ib_device_list, core_list) {
 		int i;
 
 		for (i = rdma_start_port(dev); i <= rdma_end_port(dev); i++) {
@@ -459,7 +461,7 @@ static void ib_policy_change_task(struct work_struct *work)
 				ib_security_cache_change(dev, i, sp);
 		}
 	}
-	up_read(&lists_rwsem);
+	up_read(&ib_lists_rwsem);
 }
 
 static int ib_security_change(struct notifier_block *nb, unsigned long event,
@@ -603,7 +605,7 @@ int ib_register_device(struct ib_device *device, const char *name,
 
 	setup_dma_device(device);
 
-	mutex_lock(&device_mutex);
+	mutex_lock(&ib_device_mutex);
 
 	if (strchr(name, '%')) {
 		ret = alloc_name(device, name);
@@ -646,10 +648,10 @@ int ib_register_device(struct ib_device *device, const char *name,
 		if (!add_client_context(device, client) && client->add)
 			client->add(device);
 
-	down_write(&lists_rwsem);
-	list_add_tail(&device->core_list, &device_list);
-	up_write(&lists_rwsem);
-	mutex_unlock(&device_mutex);
+	down_write(&ib_lists_rwsem);
+	list_add_tail(&device->core_list, &ib_device_list);
+	up_write(&ib_lists_rwsem);
+	mutex_unlock(&ib_device_mutex);
 	return 0;
 
 cg_cleanup:
@@ -657,7 +659,7 @@ int ib_register_device(struct ib_device *device, const char *name,
 dev_cleanup:
 	cleanup_device(device);
 out:
-	mutex_unlock(&device_mutex);
+	mutex_unlock(&ib_device_mutex);
 	return ret;
 }
 EXPORT_SYMBOL(ib_register_device);
@@ -680,33 +682,33 @@ void ib_unregister_device(struct ib_device *device)
 	ib_device_put(device);
 	wait_for_completion(&device->unreg_completion);
 
-	mutex_lock(&device_mutex);
+	mutex_lock(&ib_device_mutex);
 
-	down_write(&lists_rwsem);
+	down_write(&ib_lists_rwsem);
 	list_del(&device->core_list);
 	write_lock_irq(&device->client_data_lock);
 	list_for_each_entry(context, &device->client_data_list, list)
 		context->going_down = true;
 	write_unlock_irq(&device->client_data_lock);
-	downgrade_write(&lists_rwsem);
+	downgrade_write(&ib_lists_rwsem);
 
 	list_for_each_entry(context, &device->client_data_list, list) {
 		if (context->client->remove)
 			context->client->remove(device, context->data);
 	}
-	up_read(&lists_rwsem);
+	up_read(&ib_lists_rwsem);
 
 	ib_device_unregister_sysfs(device);
 	ib_device_unregister_rdmacg(device);
 
-	mutex_unlock(&device_mutex);
+	mutex_unlock(&ib_device_mutex);
 
 	ib_cache_cleanup_one(device);
 
 	ib_security_destroy_port_pkey_list(device);
 	kfree(device->port_pkey_list);
 
-	down_write(&lists_rwsem);
+	down_write(&ib_lists_rwsem);
 	write_lock_irqsave(&device->client_data_lock, flags);
 	list_for_each_entry_safe(context, tmp, &device->client_data_list,
 				 list) {
@@ -714,7 +716,7 @@ void ib_unregister_device(struct ib_device *device)
 		kfree(context);
 	}
 	write_unlock_irqrestore(&device->client_data_lock, flags);
-	up_write(&lists_rwsem);
+	up_write(&ib_lists_rwsem);
 
 	device->reg_state = IB_DEV_UNREGISTERED;
 }
@@ -737,17 +739,17 @@ int ib_register_client(struct ib_client *client)
 {
 	struct ib_device *device;
 
-	mutex_lock(&device_mutex);
+	mutex_lock(&ib_device_mutex);
 
-	list_for_each_entry(device, &device_list, core_list)
+	list_for_each_entry(device, &ib_device_list, core_list)
 		if (!add_client_context(device, client) && client->add)
 			client->add(device);
 
-	down_write(&lists_rwsem);
+	down_write(&ib_lists_rwsem);
 	list_add_tail(&client->list, &client_list);
-	up_write(&lists_rwsem);
+	up_write(&ib_lists_rwsem);
 
-	mutex_unlock(&device_mutex);
+	mutex_unlock(&ib_device_mutex);
 
 	return 0;
 }
@@ -766,16 +768,16 @@ void ib_unregister_client(struct ib_client *client)
 	struct ib_client_data *context;
 	struct ib_device *device;
 
-	mutex_lock(&device_mutex);
+	mutex_lock(&ib_device_mutex);
 
-	down_write(&lists_rwsem);
+	down_write(&ib_lists_rwsem);
 	list_del(&client->list);
-	up_write(&lists_rwsem);
+	up_write(&ib_lists_rwsem);
 
-	list_for_each_entry(device, &device_list, core_list) {
+	list_for_each_entry(device, &ib_device_list, core_list) {
 		struct ib_client_data *found_context = NULL;
 
-		down_write(&lists_rwsem);
+		down_write(&ib_lists_rwsem);
 		write_lock_irq(&device->client_data_lock);
 		list_for_each_entry(context, &device->client_data_list, list)
 			if (context->client == client) {
@@ -784,7 +786,7 @@ void ib_unregister_client(struct ib_client *client)
 				break;
 			}
 		write_unlock_irq(&device->client_data_lock);
-		up_write(&lists_rwsem);
+		up_write(&ib_lists_rwsem);
 
 		if (client->remove)
 			client->remove(device, found_context ?
@@ -797,15 +799,15 @@ void ib_unregister_client(struct ib_client *client)
 			continue;
 		}
 
-		down_write(&lists_rwsem);
+		down_write(&ib_lists_rwsem);
 		write_lock_irq(&device->client_data_lock);
 		list_del(&found_context->list);
 		write_unlock_irq(&device->client_data_lock);
-		up_write(&lists_rwsem);
+		up_write(&ib_lists_rwsem);
 		kfree(found_context);
 	}
 
-	mutex_unlock(&device_mutex);
+	mutex_unlock(&ib_device_mutex);
 }
 EXPORT_SYMBOL(ib_unregister_client);
 
@@ -1020,10 +1022,10 @@ void ib_enum_all_roce_netdevs(roce_netdev_filter filter,
 {
 	struct ib_device *dev;
 
-	down_read(&lists_rwsem);
-	list_for_each_entry(dev, &device_list, core_list)
+	down_read(&ib_lists_rwsem);
+	list_for_each_entry(dev, &ib_device_list, core_list)
 		ib_enum_roce_netdev(dev, filter, filter_cookie, cb, cookie);
-	up_read(&lists_rwsem);
+	up_read(&ib_lists_rwsem);
 }
 
 /**
@@ -1039,15 +1041,15 @@ int ib_enum_all_devs(nldev_callback nldev_cb, struct sk_buff *skb,
 	unsigned int idx = 0;
 	int ret = 0;
 
-	down_read(&lists_rwsem);
-	list_for_each_entry(dev, &device_list, core_list) {
+	down_read(&ib_lists_rwsem);
+	list_for_each_entry(dev, &ib_device_list, core_list) {
 		ret = nldev_cb(dev, skb, cb, idx);
 		if (ret)
 			break;
 		idx++;
 	}
 
-	up_read(&lists_rwsem);
+	up_read(&ib_lists_rwsem);
 	return ret;
 }
 
@@ -1214,7 +1216,7 @@ struct net_device *ib_get_net_dev_by_params(struct ib_device *dev,
 	if (!rdma_protocol_ib(dev, port))
 		return NULL;
 
-	down_read(&lists_rwsem);
+	down_read(&ib_lists_rwsem);
 
 	list_for_each_entry(context, &dev->client_data_list, list) {
 		struct ib_client *client = context->client;
@@ -1231,7 +1233,7 @@ struct net_device *ib_get_net_dev_by_params(struct ib_device *dev,
 		}
 	}
 
-	up_read(&lists_rwsem);
+	up_read(&ib_lists_rwsem);
 
 	return net_dev;
 }
-- 
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