RDMA/core: Implement IB device rename function
authorLeon Romanovsky <leonro@mellanox.com>
Wed, 10 Oct 2018 06:19:11 +0000 (09:19 +0300)
committerDoug Ledford <dledford@redhat.com>
Tue, 16 Oct 2018 17:37:16 +0000 (13:37 -0400)
Generic implementation of IB device rename function.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/core/core_priv.h
drivers/infiniband/core/device.c

index d7399d5b1cb680c6e93df846bc84330740d3ffd4..c5881756b799a0253b3500846dfb96d4f20dbe3b 100644 (file)
@@ -87,6 +87,7 @@ int  ib_device_register_sysfs(struct ib_device *device,
                              int (*port_callback)(struct ib_device *,
                                                   u8, struct kobject *));
 void ib_device_unregister_sysfs(struct ib_device *device);
+int ib_device_rename(struct ib_device *ibdev, const char *name);
 
 typedef void (*roce_netdev_callback)(struct ib_device *device, u8 port,
              struct net_device *idev, void *cookie);
index d105b9b2d11864f2128e2c9a67e0681be903ac09..5e70f5e1cfd983d309cc281ac94fe4b815de45cd 100644 (file)
@@ -171,6 +171,31 @@ static struct ib_device *__ib_device_get_by_name(const char *name)
        return NULL;
 }
 
+int ib_device_rename(struct ib_device *ibdev, const char *name)
+{
+       struct ib_device *device;
+       int ret = 0;
+
+       if (!strcmp(name, dev_name(&ibdev->dev)))
+               return ret;
+
+       mutex_lock(&device_mutex);
+       list_for_each_entry(device, &device_list, core_list) {
+               if (!strcmp(name, dev_name(&device->dev))) {
+                       ret = -EEXIST;
+                       goto out;
+               }
+       }
+
+       ret = device_rename(&ibdev->dev, name);
+       if (ret)
+               goto out;
+       strlcpy(ibdev->name, name, IB_DEVICE_NAME_MAX);
+out:
+       mutex_unlock(&device_mutex);
+       return ret;
+}
+
 static int alloc_name(struct ib_device *ibdev, const char *name)
 {
        unsigned long *inuse;