Skip to content

Commit bb59b8e

Browse files
sagigrimbergChristoph Hellwig
authored andcommitted
nvme-rdma: always have a valid trsvcid
If not passed, we set the default trsvcid. We can rely on having trsvcid and can simplify the controller matching logic. Signed-off-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 3045c0d commit bb59b8e

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

drivers/nvme/host/rdma.c

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,26 +1860,11 @@ static inline bool
18601860
__nvme_rdma_options_match(struct nvme_rdma_ctrl *ctrl,
18611861
struct nvmf_ctrl_options *opts)
18621862
{
1863-
char *stdport = __stringify(NVME_RDMA_IP_PORT);
1864-
1865-
18661863
if (!nvmf_ctlr_matches_baseopts(&ctrl->ctrl, opts) ||
1867-
strcmp(opts->traddr, ctrl->ctrl.opts->traddr))
1864+
strcmp(opts->traddr, ctrl->ctrl.opts->traddr) ||
1865+
strcmp(opts->trsvcid, ctrl->ctrl.opts->trsvcid))
18681866
return false;
18691867

1870-
if (opts->mask & NVMF_OPT_TRSVCID &&
1871-
ctrl->ctrl.opts->mask & NVMF_OPT_TRSVCID) {
1872-
if (strcmp(opts->trsvcid, ctrl->ctrl.opts->trsvcid))
1873-
return false;
1874-
} else if (opts->mask & NVMF_OPT_TRSVCID) {
1875-
if (strcmp(opts->trsvcid, stdport))
1876-
return false;
1877-
} else if (ctrl->ctrl.opts->mask & NVMF_OPT_TRSVCID) {
1878-
if (strcmp(stdport, ctrl->ctrl.opts->trsvcid))
1879-
return false;
1880-
}
1881-
/* else, it's a match as both have stdport. Fall to next checks */
1882-
18831868
/*
18841869
* checking the local address is rough. In most cases, one
18851870
* is not specified and the host port is selected by the stack.
@@ -1939,23 +1924,28 @@ static struct nvme_ctrl *nvme_rdma_create_ctrl(struct device *dev,
19391924
struct nvme_rdma_ctrl *ctrl;
19401925
int ret;
19411926
bool changed;
1942-
char *port;
19431927

19441928
ctrl = kzalloc(sizeof(*ctrl), GFP_KERNEL);
19451929
if (!ctrl)
19461930
return ERR_PTR(-ENOMEM);
19471931
ctrl->ctrl.opts = opts;
19481932
INIT_LIST_HEAD(&ctrl->list);
19491933

1950-
if (opts->mask & NVMF_OPT_TRSVCID)
1951-
port = opts->trsvcid;
1952-
else
1953-
port = __stringify(NVME_RDMA_IP_PORT);
1934+
if (!(opts->mask & NVMF_OPT_TRSVCID)) {
1935+
opts->trsvcid =
1936+
kstrdup(__stringify(NVME_RDMA_IP_PORT), GFP_KERNEL);
1937+
if (!opts->trsvcid) {
1938+
ret = -ENOMEM;
1939+
goto out_free_ctrl;
1940+
}
1941+
opts->mask |= NVMF_OPT_TRSVCID;
1942+
}
19541943

19551944
ret = inet_pton_with_scope(&init_net, AF_UNSPEC,
1956-
opts->traddr, port, &ctrl->addr);
1945+
opts->traddr, opts->trsvcid, &ctrl->addr);
19571946
if (ret) {
1958-
pr_err("malformed address passed: %s:%s\n", opts->traddr, port);
1947+
pr_err("malformed address passed: %s:%s\n",
1948+
opts->traddr, opts->trsvcid);
19591949
goto out_free_ctrl;
19601950
}
19611951

0 commit comments

Comments
 (0)