提交 670c2a3a 编写于 作者: S Sagi Grimberg 提交者: Jens Axboe

nvmet-rdma: use generic inet_pton_with_scope

Instead of parsing address strings, use a generic
helper. This also adds ipv6 (with address scopes)
support.
Reviewed-by: NChristoph Hellwig <hch@lst.de>
Signed-off-by: NSagi Grimberg <sagi@grimberg.me>
Signed-off-by: NJens Axboe <axboe@fb.com>
上级 b1a951fe
...@@ -1432,12 +1432,16 @@ static void nvmet_rdma_delete_ctrl(struct nvmet_ctrl *ctrl) ...@@ -1432,12 +1432,16 @@ static void nvmet_rdma_delete_ctrl(struct nvmet_ctrl *ctrl)
static int nvmet_rdma_add_port(struct nvmet_port *port) static int nvmet_rdma_add_port(struct nvmet_port *port)
{ {
struct rdma_cm_id *cm_id; struct rdma_cm_id *cm_id;
struct sockaddr_in addr_in; struct sockaddr_storage addr = { };
u16 port_in; __kernel_sa_family_t af;
int ret; int ret;
switch (port->disc_addr.adrfam) { switch (port->disc_addr.adrfam) {
case NVMF_ADDR_FAMILY_IP4: case NVMF_ADDR_FAMILY_IP4:
af = AF_INET;
break;
case NVMF_ADDR_FAMILY_IP6:
af = AF_INET6;
break; break;
default: default:
pr_err("address family %d not supported\n", pr_err("address family %d not supported\n",
...@@ -1445,13 +1449,13 @@ static int nvmet_rdma_add_port(struct nvmet_port *port) ...@@ -1445,13 +1449,13 @@ static int nvmet_rdma_add_port(struct nvmet_port *port)
return -EINVAL; return -EINVAL;
} }
ret = kstrtou16(port->disc_addr.trsvcid, 0, &port_in); ret = inet_pton_with_scope(&init_net, af, port->disc_addr.traddr,
if (ret) port->disc_addr.trsvcid, &addr);
if (ret) {
pr_err("malformed ip/port passed: %s:%s\n",
port->disc_addr.traddr, port->disc_addr.trsvcid);
return ret; return ret;
}
addr_in.sin_family = AF_INET;
addr_in.sin_addr.s_addr = in_aton(port->disc_addr.traddr);
addr_in.sin_port = htons(port_in);
cm_id = rdma_create_id(&init_net, nvmet_rdma_cm_handler, port, cm_id = rdma_create_id(&init_net, nvmet_rdma_cm_handler, port,
RDMA_PS_TCP, IB_QPT_RC); RDMA_PS_TCP, IB_QPT_RC);
...@@ -1460,20 +1464,32 @@ static int nvmet_rdma_add_port(struct nvmet_port *port) ...@@ -1460,20 +1464,32 @@ static int nvmet_rdma_add_port(struct nvmet_port *port)
return PTR_ERR(cm_id); return PTR_ERR(cm_id);
} }
ret = rdma_bind_addr(cm_id, (struct sockaddr *)&addr_in); /*
* Allow both IPv4 and IPv6 sockets to bind a single port
* at the same time.
*/
ret = rdma_set_afonly(cm_id, 1);
if (ret) {
pr_err("rdma_set_afonly failed (%d)\n", ret);
goto out_destroy_id;
}
ret = rdma_bind_addr(cm_id, (struct sockaddr *)&addr);
if (ret) { if (ret) {
pr_err("binding CM ID to %pISpc failed (%d)\n", &addr_in, ret); pr_err("binding CM ID to %pISpcs failed (%d)\n",
(struct sockaddr *)&addr, ret);
goto out_destroy_id; goto out_destroy_id;
} }
ret = rdma_listen(cm_id, 128); ret = rdma_listen(cm_id, 128);
if (ret) { if (ret) {
pr_err("listening to %pISpc failed (%d)\n", &addr_in, ret); pr_err("listening to %pISpcs failed (%d)\n",
(struct sockaddr *)&addr, ret);
goto out_destroy_id; goto out_destroy_id;
} }
pr_info("enabling port %d (%pISpc)\n", pr_info("enabling port %d (%pISpcs)\n",
le16_to_cpu(port->disc_addr.portid), &addr_in); le16_to_cpu(port->disc_addr.portid), (struct sockaddr *)&addr);
port->priv = cm_id; port->priv = cm_id;
return 0; return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册