Commit 0928f9b4 authored by Sagi Grimberg's avatar Sagi Grimberg Committed by Jens Axboe

nvme-rdma: use inet_pton_with_scope helper

Both the destination and the host addresses are now
parsed using inet_pton_with_scope helper. We also
get ipv6 (with address scopes support).
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarSagi Grimberg <sagi@grimberg.me>
Signed-off-by: default avatarJens Axboe <axboe@fb.com>
parent 670c2a3a
...@@ -129,14 +129,8 @@ struct nvme_rdma_ctrl { ...@@ -129,14 +129,8 @@ struct nvme_rdma_ctrl {
u64 cap; u64 cap;
u32 max_fr_pages; u32 max_fr_pages;
union { struct sockaddr_storage addr;
struct sockaddr addr; struct sockaddr_storage src_addr;
struct sockaddr_in addr_in;
};
union {
struct sockaddr src_addr;
struct sockaddr_in src_addr_in;
};
struct nvme_ctrl ctrl; struct nvme_ctrl ctrl;
}; };
...@@ -569,11 +563,12 @@ static int nvme_rdma_init_queue(struct nvme_rdma_ctrl *ctrl, ...@@ -569,11 +563,12 @@ static int nvme_rdma_init_queue(struct nvme_rdma_ctrl *ctrl,
return PTR_ERR(queue->cm_id); return PTR_ERR(queue->cm_id);
} }
queue->cm_error = -ETIMEDOUT;
if (ctrl->ctrl.opts->mask & NVMF_OPT_HOST_TRADDR) if (ctrl->ctrl.opts->mask & NVMF_OPT_HOST_TRADDR)
src_addr = &ctrl->src_addr; src_addr = (struct sockaddr *)&ctrl->src_addr;
ret = rdma_resolve_addr(queue->cm_id, src_addr, &ctrl->addr, queue->cm_error = -ETIMEDOUT;
ret = rdma_resolve_addr(queue->cm_id, src_addr,
(struct sockaddr *)&ctrl->addr,
NVME_RDMA_CONNECT_TIMEOUT_MS); NVME_RDMA_CONNECT_TIMEOUT_MS);
if (ret) { if (ret) {
dev_info(ctrl->ctrl.device, dev_info(ctrl->ctrl.device,
...@@ -1857,27 +1852,13 @@ static int nvme_rdma_create_io_queues(struct nvme_rdma_ctrl *ctrl) ...@@ -1857,27 +1852,13 @@ static int nvme_rdma_create_io_queues(struct nvme_rdma_ctrl *ctrl)
return ret; return ret;
} }
static int nvme_rdma_parse_ipaddr(struct sockaddr_in *in_addr, char *p)
{
u8 *addr = (u8 *)&in_addr->sin_addr.s_addr;
size_t buflen = strlen(p);
/* XXX: handle IPv6 addresses */
if (buflen > INET_ADDRSTRLEN)
return -EINVAL;
if (in4_pton(p, buflen, addr, '\0', NULL) == 0)
return -EINVAL;
in_addr->sin_family = AF_INET;
return 0;
}
static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev, static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
struct nvmf_ctrl_options *opts) struct nvmf_ctrl_options *opts)
{ {
struct nvme_rdma_ctrl *ctrl; struct nvme_rdma_ctrl *ctrl;
int ret; int ret;
bool changed; bool changed;
char *port;
ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL); ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
if (!ctrl) if (!ctrl)
...@@ -1885,34 +1866,28 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev, ...@@ -1885,34 +1866,28 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
ctrl->ctrl.opts = opts; ctrl->ctrl.opts = opts;
INIT_LIST_HEAD(&ctrl->list); INIT_LIST_HEAD(&ctrl->list);
ret = nvme_rdma_parse_ipaddr(&ctrl->addr_in, opts->traddr); if (opts->mask & NVMF_OPT_TRSVCID)
port = opts->trsvcid;
else
port = __stringify(NVME_RDMA_IP_PORT);
ret = inet_pton_with_scope(&init_net, AF_UNSPEC,
opts->traddr, port, &ctrl->addr);
if (ret) { if (ret) {
pr_err("malformed IP address passed: %s\n", opts->traddr); pr_err("malformed address passed: %s:%s\n", opts->traddr, port);
goto out_free_ctrl; goto out_free_ctrl;
} }
if (opts->mask & NVMF_OPT_HOST_TRADDR) { if (opts->mask & NVMF_OPT_HOST_TRADDR) {
ret = nvme_rdma_parse_ipaddr(&ctrl->src_addr_in, ret = inet_pton_with_scope(&init_net, AF_UNSPEC,
opts->host_traddr); opts->host_traddr, NULL, &ctrl->src_addr);
if (ret) { if (ret) {
pr_err("malformed src IP address passed: %s\n", pr_err("malformed src address passed: %s\n",
opts->host_traddr); opts->host_traddr);
goto out_free_ctrl; goto out_free_ctrl;
} }
} }
if (opts->mask & NVMF_OPT_TRSVCID) {
u16 port;
ret = kstrtou16(opts->trsvcid, 0, &port);
if (ret)
goto out_free_ctrl;
ctrl->addr_in.sin_port = cpu_to_be16(port);
} else {
ctrl->addr_in.sin_port = cpu_to_be16(NVME_RDMA_IP_PORT);
}
ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_rdma_ctrl_ops, ret = nvme_init_ctrl(&ctrl->ctrl, dev, &nvme_rdma_ctrl_ops,
0 /* no quirks, we're perfect! */); 0 /* no quirks, we're perfect! */);
if (ret) if (ret)
...@@ -1977,7 +1952,7 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev, ...@@ -1977,7 +1952,7 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE); changed = nvme_change_ctrl_state(&ctrl->ctrl, NVME_CTRL_LIVE);
WARN_ON_ONCE(!changed); WARN_ON_ONCE(!changed);
dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISp\n", dev_info(ctrl->ctrl.device, "new ctrl: NQN \"%s\", addr %pISpcs\n",
ctrl->ctrl.opts->subsysnqn, &ctrl->addr); ctrl->ctrl.opts->subsysnqn, &ctrl->addr);
kref_get(&ctrl->ctrl.kref); kref_get(&ctrl->ctrl.kref);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment