Skip to content

Commit b7c7be6

Browse files
sagigrimbergChristoph Hellwig
authored andcommitted
nvme-fabrics: move controller options matching to fabrics
IP transports will most likely use the same controller options matching when detecting a duplicate connect. Move it to fabrics. Signed-off-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent bb59b8e commit b7c7be6

File tree

3 files changed

+33
-34
lines changed

3 files changed

+33
-34
lines changed

drivers/nvme/host/fabrics.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,36 @@ static int nvmf_check_required_opts(struct nvmf_ctrl_options *opts,
868868
return 0;
869869
}
870870

871+
bool nvmf_ip_options_match(struct nvme_ctrl *ctrl,
872+
struct nvmf_ctrl_options *opts)
873+
{
874+
if (!nvmf_ctlr_matches_baseopts(ctrl, opts) ||
875+
strcmp(opts->traddr, ctrl->opts->traddr) ||
876+
strcmp(opts->trsvcid, ctrl->opts->trsvcid))
877+
return false;
878+
879+
/*
880+
* Checking the local address is rough. In most cases, none is specified
881+
* and the host port is selected by the stack.
882+
*
883+
* Assume no match if:
884+
* - local address is specified and address is not the same
885+
* - local address is not specified but remote is, or vice versa
886+
* (admin using specific host_traddr when it matters).
887+
*/
888+
if ((opts->mask & NVMF_OPT_HOST_TRADDR) &&
889+
(ctrl->opts->mask & NVMF_OPT_HOST_TRADDR)) {
890+
if (strcmp(opts->host_traddr, ctrl->opts->host_traddr))
891+
return false;
892+
} else if ((opts->mask & NVMF_OPT_HOST_TRADDR) ||
893+
(ctrl->opts->mask & NVMF_OPT_HOST_TRADDR)) {
894+
return false;
895+
}
896+
897+
return true;
898+
}
899+
EXPORT_SYMBOL_GPL(nvmf_ip_options_match);
900+
871901
static int nvmf_check_allowed_opts(struct nvmf_ctrl_options *opts,
872902
unsigned int allowed_opts)
873903
{

drivers/nvme/host/fabrics.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ blk_status_t nvmf_fail_nonready_command(struct nvme_ctrl *ctrl,
166166
struct request *rq);
167167
bool __nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
168168
bool queue_live);
169+
bool nvmf_ip_options_match(struct nvme_ctrl *ctrl,
170+
struct nvmf_ctrl_options *opts);
169171

170172
static inline bool nvmf_check_ready(struct nvme_ctrl *ctrl, struct request *rq,
171173
bool queue_live)

drivers/nvme/host/rdma.c

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,39 +1856,6 @@ static const struct nvme_ctrl_ops nvme_rdma_ctrl_ops = {
18561856
.stop_ctrl = nvme_rdma_stop_ctrl,
18571857
};
18581858

1859-
static inline bool
1860-
__nvme_rdma_options_match(struct nvme_rdma_ctrl *ctrl,
1861-
struct nvmf_ctrl_options *opts)
1862-
{
1863-
if (!nvmf_ctlr_matches_baseopts(&ctrl->ctrl, opts) ||
1864-
strcmp(opts->traddr, ctrl->ctrl.opts->traddr) ||
1865-
strcmp(opts->trsvcid, ctrl->ctrl.opts->trsvcid))
1866-
return false;
1867-
1868-
/*
1869-
* checking the local address is rough. In most cases, one
1870-
* is not specified and the host port is selected by the stack.
1871-
*
1872-
* Assume no match if:
1873-
* local address is specified and address is not the same
1874-
* local address is not specified but remote is, or vice versa
1875-
* (admin using specific host_traddr when it matters).
1876-
*/
1877-
if (opts->mask & NVMF_OPT_HOST_TRADDR &&
1878-
ctrl->ctrl.opts->mask & NVMF_OPT_HOST_TRADDR) {
1879-
if (strcmp(opts->host_traddr, ctrl->ctrl.opts->host_traddr))
1880-
return false;
1881-
} else if (opts->mask & NVMF_OPT_HOST_TRADDR ||
1882-
ctrl->ctrl.opts->mask & NVMF_OPT_HOST_TRADDR)
1883-
return false;
1884-
/*
1885-
* if neither controller had an host port specified, assume it's
1886-
* a match as everything else matched.
1887-
*/
1888-
1889-
return true;
1890-
}
1891-
18921859
/*
18931860
* Fails a connection request if it matches an existing controller
18941861
* (association) with the same tuple:
@@ -1909,7 +1876,7 @@ nvme_rdma_existing_controller(struct nvmf_ctrl_options *opts)
19091876

19101877
mutex_lock(&nvme_rdma_ctrl_mutex);
19111878
list_for_each_entry(ctrl, &nvme_rdma_ctrl_list, list) {
1912-
found = __nvme_rdma_options_match(ctrl, opts);
1879+
found = nvmf_ip_options_match(&ctrl->ctrl, opts);
19131880
if (found)
19141881
break;
19151882
}

0 commit comments

Comments
 (0)