Commit b86d6595 authored by Max Gurtovoy's avatar Max Gurtovoy Committed by Keith Busch

nvme-fabrics: unify common code in admin and io queue connect

To simplify code maintenance, it is recommended to avoid duplicating
code.
Tested-by: default avatarNoam Gottlieb <ngottlieb@nvidia.com>
Reviewed-by: default avatarIsrael Rukshin <israelr@nvidia.com>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarMax Gurtovoy <mgurtovoy@nvidia.com>
Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
parent 92bbe551
......@@ -349,6 +349,45 @@ static void nvmf_log_connect_error(struct nvme_ctrl *ctrl,
}
}
static struct nvmf_connect_data *nvmf_connect_data_prep(struct nvme_ctrl *ctrl,
u16 cntlid)
{
struct nvmf_connect_data *data;
data = kzalloc(sizeof(*data), GFP_KERNEL);
if (!data)
return NULL;
uuid_copy(&data->hostid, &ctrl->opts->host->id);
data->cntlid = cpu_to_le16(cntlid);
strncpy(data->subsysnqn, ctrl->opts->subsysnqn, NVMF_NQN_SIZE);
strncpy(data->hostnqn, ctrl->opts->host->nqn, NVMF_NQN_SIZE);
return data;
}
static void nvmf_connect_cmd_prep(struct nvme_ctrl *ctrl, u16 qid,
struct nvme_command *cmd)
{
cmd->connect.opcode = nvme_fabrics_command;
cmd->connect.fctype = nvme_fabrics_type_connect;
cmd->connect.qid = cpu_to_le16(qid);
if (qid) {
cmd->connect.sqsize = cpu_to_le16(ctrl->sqsize);
} else {
cmd->connect.sqsize = cpu_to_le16(NVME_AQ_DEPTH - 1);
/*
* set keep-alive timeout in seconds granularity (ms * 1000)
*/
cmd->connect.kato = cpu_to_le32(ctrl->kato * 1000);
}
if (ctrl->opts->disable_sqflow)
cmd->connect.cattr |= NVME_CONNECT_DISABLE_SQFLOW;
}
/**
* nvmf_connect_admin_queue() - NVMe Fabrics Admin Queue "Connect"
* API function.
......@@ -377,28 +416,12 @@ int nvmf_connect_admin_queue(struct nvme_ctrl *ctrl)
int ret;
u32 result;
cmd.connect.opcode = nvme_fabrics_command;
cmd.connect.fctype = nvme_fabrics_type_connect;
cmd.connect.qid = 0;
cmd.connect.sqsize = cpu_to_le16(NVME_AQ_DEPTH - 1);
/*
* Set keep-alive timeout in seconds granularity (ms * 1000)
*/
cmd.connect.kato = cpu_to_le32(ctrl->kato * 1000);
if (ctrl->opts->disable_sqflow)
cmd.connect.cattr |= NVME_CONNECT_DISABLE_SQFLOW;
nvmf_connect_cmd_prep(ctrl, 0, &cmd);
data = kzalloc(sizeof(*data), GFP_KERNEL);
data = nvmf_connect_data_prep(ctrl, 0xffff);
if (!data)
return -ENOMEM;
uuid_copy(&data->hostid, &ctrl->opts->host->id);
data->cntlid = cpu_to_le16(0xffff);
strncpy(data->subsysnqn, ctrl->opts->subsysnqn, NVMF_NQN_SIZE);
strncpy(data->hostnqn, ctrl->opts->host->nqn, NVMF_NQN_SIZE);
ret = __nvme_submit_sync_cmd(ctrl->fabrics_q, &cmd, &res,
data, sizeof(*data), NVME_QID_ANY, 1,
BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT);
......@@ -468,23 +491,12 @@ int nvmf_connect_io_queue(struct nvme_ctrl *ctrl, u16 qid)
int ret;
u32 result;
cmd.connect.opcode = nvme_fabrics_command;
cmd.connect.fctype = nvme_fabrics_type_connect;
cmd.connect.qid = cpu_to_le16(qid);
cmd.connect.sqsize = cpu_to_le16(ctrl->sqsize);
if (ctrl->opts->disable_sqflow)
cmd.connect.cattr |= NVME_CONNECT_DISABLE_SQFLOW;
nvmf_connect_cmd_prep(ctrl, qid, &cmd);
data = kzalloc(sizeof(*data), GFP_KERNEL);
data = nvmf_connect_data_prep(ctrl, ctrl->cntlid);
if (!data)
return -ENOMEM;
uuid_copy(&data->hostid, &ctrl->opts->host->id);
data->cntlid = cpu_to_le16(ctrl->cntlid);
strncpy(data->subsysnqn, ctrl->opts->subsysnqn, NVMF_NQN_SIZE);
strncpy(data->hostnqn, ctrl->opts->host->nqn, NVMF_NQN_SIZE);
ret = __nvme_submit_sync_cmd(ctrl->connect_q, &cmd, &res,
data, sizeof(*data), qid, 1,
BLK_MQ_REQ_RESERVED | BLK_MQ_REQ_NOWAIT);
......
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