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/compat_sysfs.c | 33 ++++++++++++++++++++++++++ drivers/infiniband/core/core_priv.h | 1 + drivers/infiniband/core/device.c | 1 + 3 files changed, 35 insertions(+) diff --git a/drivers/infiniband/core/compat_sysfs.c b/drivers/infiniband/core/compat_sysfs.c index 6fa330678063..305a898bf97a 100644 --- a/drivers/infiniband/core/compat_sysfs.c +++ b/drivers/infiniband/core/compat_sysfs.c @@ -123,6 +123,39 @@ void rdma_compatdev_remove(struct ib_device *device) up_read(&net_rwsem); } +void rdma_compatdev_rename(const struct ib_device *device) +{ + struct rdma_compatdev_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_compatdev_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_compatdev_init_net(struct net *net) { struct rdma_compatdev_net *rdma_net = diff --git a/drivers/infiniband/core/core_priv.h b/drivers/infiniband/core/core_priv.h index ea04926f6b0c..b586a7ff3275 100644 --- a/drivers/infiniband/core/core_priv.h +++ b/drivers/infiniband/core/core_priv.h @@ -334,4 +334,5 @@ 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); #endif /* _CORE_PRIV_H */ diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c index 2d3939dc6d22..9e3d4d9289fd 100644 --- a/drivers/infiniband/core/device.c +++ b/drivers/infiniband/core/device.c @@ -202,6 +202,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; -- 2.19.1