Merge tag 'scsi-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi
[sfrench/cifs-2.6.git] / drivers / infiniband / ulp / srp / ib_srp.c
index 9c5b406019488af8b61912a3caa0efad3d540673..b5960351bec088739d45d933bf9bd6b3e7f244cb 100644 (file)
@@ -148,6 +148,7 @@ MODULE_PARM_DESC(ch_count,
 
 static void srp_add_one(struct ib_device *device);
 static void srp_remove_one(struct ib_device *device, void *client_data);
+static void srp_rename_dev(struct ib_device *device, void *client_data);
 static void srp_recv_done(struct ib_cq *cq, struct ib_wc *wc);
 static void srp_handle_qp_err(struct ib_cq *cq, struct ib_wc *wc,
                const char *opname);
@@ -162,7 +163,8 @@ static struct workqueue_struct *srp_remove_wq;
 static struct ib_client srp_client = {
        .name   = "srp",
        .add    = srp_add_one,
-       .remove = srp_remove_one
+       .remove = srp_remove_one,
+       .rename = srp_rename_dev
 };
 
 static struct ib_sa_client srp_sa_client;
@@ -3449,13 +3451,14 @@ static const match_table_t srp_opt_tokens = {
  * @net:          [in]  Network namespace.
  * @sa:                   [out] Address family, IP address and port number.
  * @addr_port_str: [in]  IP address and port number.
+ * @has_port:     [out] Whether or not @addr_port_str includes a port number.
  *
  * Parse the following address formats:
  * - IPv4: <ip_address>:<port>, e.g. 1.2.3.4:5.
  * - IPv6: \[<ipv6_address>\]:<port>, e.g. [1::2:3%4]:5.
  */
 static int srp_parse_in(struct net *net, struct sockaddr_storage *sa,
-                       const char *addr_port_str)
+                       const char *addr_port_str, bool *has_port)
 {
        char *addr_end, *addr = kstrdup(addr_port_str, GFP_KERNEL);
        char *port_str;
@@ -3464,9 +3467,12 @@ static int srp_parse_in(struct net *net, struct sockaddr_storage *sa,
        if (!addr)
                return -ENOMEM;
        port_str = strrchr(addr, ':');
-       if (!port_str)
-               return -EINVAL;
-       *port_str++ = '\0';
+       if (port_str && strchr(port_str, ']'))
+               port_str = NULL;
+       if (port_str)
+               *port_str++ = '\0';
+       if (has_port)
+               *has_port = port_str != NULL;
        ret = inet_pton_with_scope(net, AF_INET, addr, port_str, sa);
        if (ret && addr[0]) {
                addr_end = addr + strlen(addr) - 1;
@@ -3488,6 +3494,7 @@ static int srp_parse_options(struct net *net, const char *buf,
        char *p;
        substring_t args[MAX_OPT_ARGS];
        unsigned long long ull;
+       bool has_port;
        int opt_mask = 0;
        int token;
        int ret = -EINVAL;
@@ -3586,7 +3593,8 @@ static int srp_parse_options(struct net *net, const char *buf,
                                ret = -ENOMEM;
                                goto out;
                        }
-                       ret = srp_parse_in(net, &target->rdma_cm.src.ss, p);
+                       ret = srp_parse_in(net, &target->rdma_cm.src.ss, p,
+                                          NULL);
                        if (ret < 0) {
                                pr_warn("bad source parameter '%s'\n", p);
                                kfree(p);
@@ -3602,7 +3610,10 @@ static int srp_parse_options(struct net *net, const char *buf,
                                ret = -ENOMEM;
                                goto out;
                        }
-                       ret = srp_parse_in(net, &target->rdma_cm.dst.ss, p);
+                       ret = srp_parse_in(net, &target->rdma_cm.dst.ss, p,
+                                          &has_port);
+                       if (!has_port)
+                               ret = -EINVAL;
                        if (ret < 0) {
                                pr_warn("bad dest parameter '%s'\n", p);
                                kfree(p);
@@ -4083,6 +4094,20 @@ free_host:
        return NULL;
 }
 
+static void srp_rename_dev(struct ib_device *device, void *client_data)
+{
+       struct srp_device *srp_dev = client_data;
+       struct srp_host *host, *tmp_host;
+
+       list_for_each_entry_safe(host, tmp_host, &srp_dev->dev_list, list) {
+               char name[IB_DEVICE_NAME_MAX + 8];
+
+               snprintf(name, sizeof(name), "srp-%s-%d",
+                        dev_name(&device->dev), host->port);
+               device_rename(&host->dev, name);
+       }
+}
+
 static void srp_add_one(struct ib_device *device)
 {
        struct srp_device *srp_dev;