[PATCH rdma-next v3 08/10] RDMA/core: Handle compat dev during device rename

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

 



From: Parav Pandit <parav@xxxxxxxxxxxx>

When rdma device is renamed, also rename compat devices in non
init_net namespaces.

Signed-off-by: Parav Pandit <parav@xxxxxxxxxxxx>
Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx>
---
 drivers/infiniband/core/core_priv.h     |  1 +
 drivers/infiniband/core/device.c        |  1 +
 drivers/infiniband/core/net_namespace.c | 33 +++++++++++++++++++++++++
 3 files changed, 35 insertions(+)

diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h
index bb257dedbccf..c72d35e7a1f4 100644
--- a/drivers/infiniband/core/core_priv.h
+++ b/drivers/infiniband/core/core_priv.h
@@ -349,4 +349,5 @@ void __exit rdma_dev_net_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);
 #endif /* _CORE_PRIV_H */
diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index fc4da2d2566a..ea39a4c09774 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -203,6 +203,7 @@ int ib_device_rename(struct ib_device *ibdev, const char *name)
 	if (ret)
 		goto out;
 	strlcpy(ibdev->name, name, IB_DEVICE_NAME_MAX);
+	rdma_compatdev_rename(ibdev);
 out:
 	mutex_unlock(&ib_device_mutex);
 	return ret;
diff --git a/drivers/infiniband/core/net_namespace.c b/drivers/infiniband/core/net_namespace.c
index 71284d9aa0d4..18961d233d02 100644
--- a/drivers/infiniband/core/net_namespace.c
+++ b/drivers/infiniband/core/net_namespace.c
@@ -122,6 +122,39 @@ void rdma_compatdev_remove(struct ib_device *device)
 	up_read(&net_rwsem);
 }
 
+void rdma_compatdev_rename(const struct ib_device *device)
+{
+	struct rdma_dev_net *rdma_net;
+	struct ib_compat_device *cur;
+	struct net *net;
+	int ret;
+
+	/* Hold net_rwsem while adding compat dev entries to synchronize with
+	 * _exit_net()/_init_net.
+	 */
+	down_read(&net_rwsem);
+	for_each_net(net) {
+		rdma_net = net_generic(net, rdma_dev_net_id);
+		down_write(&rdma_net->compat_rwsem);
+		list_for_each_entry(cur, &rdma_net->compatdev_list, list) {
+			if (device != rdma_device_to_ibdev(&cur->coredev.dev))
+				continue;
+
+			/* Found the matching compat device, rename */
+			ret = device_rename(&cur->coredev.dev,
+					    dev_name(&device->dev));
+			if (ret) {
+				dev_warn(&cur->coredev.dev,
+					 "Fail to rename to new name %s\n",
+					 dev_name(&device->dev));
+			}
+			break;
+		}
+		up_write(&rdma_net->compat_rwsem);
+	}
+	up_read(&net_rwsem);
+}
+
 static __net_init int rdma_dev_init_net(struct net *net)
 {
 	struct rdma_dev_net *rdma_net =	net_generic(net, rdma_dev_net_id);
-- 
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