From: Jiri Pirko <[email protected]>

Prepare for per-netns RDMA device names by passing the target net
namespace through the name lookup and allocation helpers. Keep current
global uniqueness behaviour.

Signed-off-by: Jiri Pirko <[email protected]>
---
 drivers/infiniband/core/device.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index b8193e077a74..de610f52c9b2 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -351,7 +351,8 @@ void ib_device_put(struct ib_device *device)
 }
 EXPORT_SYMBOL(ib_device_put);
 
-static struct ib_device *__ib_device_get_by_name(const char *name)
+static struct ib_device *__ib_device_get_by_name(const char *name,
+                                                const struct net *net)
 {
        struct ib_device *device;
        unsigned long index;
@@ -395,7 +396,7 @@ int ib_device_rename(struct ib_device *ibdev, const char 
*name)
                return 0;
        }
 
-       if (__ib_device_get_by_name(name)) {
+       if (__ib_device_get_by_name(name, rdma_dev_net(ibdev))) {
                up_write(&devices_rwsem);
                return -EEXIST;
        }
@@ -435,7 +436,8 @@ int ib_device_set_dim(struct ib_device *ibdev, u8 use_dim)
        return 0;
 }
 
-static int alloc_name(struct ib_device *ibdev, const char *name)
+/* Pick a free index for the '%d' style @name pattern. */
+static int alloc_name_id(struct net *net, const char *name)
 {
        struct ib_device *device;
        unsigned long index;
@@ -462,15 +464,22 @@ static int alloc_name(struct ib_device *ibdev, const char 
*name)
        }
 
        rc = ida_alloc(&inuse, GFP_KERNEL);
-       if (rc < 0)
-               goto out;
-
-       rc = dev_set_name(&ibdev->dev, name, rc);
 out:
        ida_destroy(&inuse);
        return rc;
 }
 
+static int alloc_name(struct ib_device *ibdev, const char *name)
+{
+       int id;
+
+       id = alloc_name_id(rdma_dev_net(ibdev), name);
+       if (id < 0)
+               return id;
+
+       return dev_set_name(&ibdev->dev, name, id);
+}
+
 static void ib_device_release(struct device *device)
 {
        struct ib_device *dev = container_of(device, struct ib_device, dev);
@@ -1223,7 +1232,8 @@ static int assign_name(struct ib_device *device, const 
char *name)
        if (ret)
                goto out;
 
-       if (__ib_device_get_by_name(dev_name(&device->dev))) {
+       if (__ib_device_get_by_name(dev_name(&device->dev),
+                                   rdma_dev_net(device))) {
                ret = -ENFILE;
                goto out;
        }
-- 
2.54.0


Reply via email to