nvmf/tcp: Simplify spdk_nvmf_tcp_req_parse_sgl()
By passing the pointer to struct spdk_nvmf_transport_poll_group to spdk_nvmf_tcp_req_parse_sgl(), we can remove spdk_nvmf_tcp_req_fill_iovs() and inline spdk_nvmf_request_get_buffers() into spdk_nvmf_tcp_req_parse_sgl(). Pointers to struct spdk_nvmf_request are used in many lines of spdk_nvmf_tcp_req_parse_sgl(). Caching and using them simplifies and improves readability a little for spdk_nvmf_tcp_req_parse_sgl(). We can pass pointer to not struct spdk_nvmf_tcp_transport but struct spdk_nvmf_transport to spdk_nvmf_tcp_req_parse_sgl(). Ordering the pointer to struct spdk_nvmf_tcp_req first in parameters of spdk_nvmf_tcp_req_parse_sgl() matches the function name. Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Change-Id: I9f0d33b48383800c3b0a738eb24b11ffed7e6e60 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/469640 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Ziye Yang <ziye.yang@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Alexey Marchuk <alexeymar@mellanox.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
b6af628671
commit
c8734543bc
@ -2173,49 +2173,33 @@ spdk_nvmf_tcp_req_get_xfer(struct spdk_nvmf_tcp_req *tcp_req) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
spdk_nvmf_tcp_req_fill_iovs(struct spdk_nvmf_tcp_transport *ttransport,
|
spdk_nvmf_tcp_req_parse_sgl(struct spdk_nvmf_tcp_req *tcp_req,
|
||||||
struct spdk_nvmf_tcp_req *tcp_req, uint32_t length)
|
struct spdk_nvmf_transport *transport,
|
||||||
{
|
struct spdk_nvmf_transport_poll_group *group)
|
||||||
struct spdk_nvmf_tcp_qpair *tqpair;
|
|
||||||
struct spdk_nvmf_transport_poll_group *group;
|
|
||||||
|
|
||||||
tqpair = SPDK_CONTAINEROF(tcp_req->req.qpair, struct spdk_nvmf_tcp_qpair, qpair);
|
|
||||||
group = &tqpair->group->group;
|
|
||||||
tcp_req->req.iovcnt = 0;
|
|
||||||
|
|
||||||
if (spdk_nvmf_request_get_buffers(&tcp_req->req, group, &ttransport->transport, length)) {
|
|
||||||
return -ENOMEM;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
spdk_nvmf_tcp_req_parse_sgl(struct spdk_nvmf_tcp_transport *ttransport,
|
|
||||||
struct spdk_nvmf_tcp_req *tcp_req)
|
|
||||||
{
|
{
|
||||||
|
struct spdk_nvmf_request *req = &tcp_req->req;
|
||||||
struct spdk_nvme_cmd *cmd;
|
struct spdk_nvme_cmd *cmd;
|
||||||
struct spdk_nvme_cpl *rsp;
|
struct spdk_nvme_cpl *rsp;
|
||||||
struct spdk_nvme_sgl_descriptor *sgl;
|
struct spdk_nvme_sgl_descriptor *sgl;
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
|
|
||||||
cmd = &tcp_req->req.cmd->nvme_cmd;
|
cmd = &req->cmd->nvme_cmd;
|
||||||
rsp = &tcp_req->req.rsp->nvme_cpl;
|
rsp = &req->rsp->nvme_cpl;
|
||||||
sgl = &cmd->dptr.sgl1;
|
sgl = &cmd->dptr.sgl1;
|
||||||
|
|
||||||
length = sgl->unkeyed.length;
|
length = sgl->unkeyed.length;
|
||||||
|
|
||||||
if (sgl->generic.type == SPDK_NVME_SGL_TYPE_TRANSPORT_DATA_BLOCK &&
|
if (sgl->generic.type == SPDK_NVME_SGL_TYPE_TRANSPORT_DATA_BLOCK &&
|
||||||
sgl->unkeyed.subtype == SPDK_NVME_SGL_SUBTYPE_TRANSPORT) {
|
sgl->unkeyed.subtype == SPDK_NVME_SGL_SUBTYPE_TRANSPORT) {
|
||||||
if (length > ttransport->transport.opts.max_io_size) {
|
if (length > transport->opts.max_io_size) {
|
||||||
SPDK_ERRLOG("SGL length 0x%x exceeds max io size 0x%x\n",
|
SPDK_ERRLOG("SGL length 0x%x exceeds max io size 0x%x\n",
|
||||||
length, ttransport->transport.opts.max_io_size);
|
length, transport->opts.max_io_size);
|
||||||
rsp->status.sc = SPDK_NVME_SC_DATA_SGL_LENGTH_INVALID;
|
rsp->status.sc = SPDK_NVME_SC_DATA_SGL_LENGTH_INVALID;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fill request length and populate iovs */
|
/* fill request length and populate iovs */
|
||||||
tcp_req->req.length = length;
|
req->length = length;
|
||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_NVMF_TCP, "Data requested length= 0x%x\n", length);
|
SPDK_DEBUGLOG(SPDK_LOG_NVMF_TCP, "Data requested length= 0x%x\n", length);
|
||||||
|
|
||||||
@ -2225,7 +2209,7 @@ spdk_nvmf_tcp_req_parse_sgl(struct spdk_nvmf_tcp_transport *ttransport,
|
|||||||
tcp_req->elba_length = length;
|
tcp_req->elba_length = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (spdk_nvmf_tcp_req_fill_iovs(ttransport, tcp_req, length) < 0) {
|
if (spdk_nvmf_request_get_buffers(req, group, transport, length)) {
|
||||||
/* No available buffers. Queue this request up. */
|
/* No available buffers. Queue this request up. */
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_NVMF_TCP, "No available large data buffers. Queueing request %p\n",
|
SPDK_DEBUGLOG(SPDK_LOG_NVMF_TCP, "No available large data buffers. Queueing request %p\n",
|
||||||
tcp_req);
|
tcp_req);
|
||||||
@ -2233,18 +2217,16 @@ spdk_nvmf_tcp_req_parse_sgl(struct spdk_nvmf_tcp_transport *ttransport,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* backward compatible */
|
/* backward compatible */
|
||||||
tcp_req->req.data = tcp_req->req.iov[0].iov_base;
|
req->data = req->iov[0].iov_base;
|
||||||
|
|
||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_NVMF_TCP, "Request %p took %d buffer/s from central pool, and data=%p\n",
|
SPDK_DEBUGLOG(SPDK_LOG_NVMF_TCP, "Request %p took %d buffer/s from central pool, and data=%p\n",
|
||||||
tcp_req,
|
tcp_req, req->iovcnt, req->data);
|
||||||
tcp_req->req.iovcnt, tcp_req->req.data);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else if (sgl->generic.type == SPDK_NVME_SGL_TYPE_DATA_BLOCK &&
|
} else if (sgl->generic.type == SPDK_NVME_SGL_TYPE_DATA_BLOCK &&
|
||||||
sgl->unkeyed.subtype == SPDK_NVME_SGL_SUBTYPE_OFFSET) {
|
sgl->unkeyed.subtype == SPDK_NVME_SGL_SUBTYPE_OFFSET) {
|
||||||
uint64_t offset = sgl->address;
|
uint64_t offset = sgl->address;
|
||||||
uint32_t max_len = ttransport->transport.opts.in_capsule_data_size;
|
uint32_t max_len = transport->opts.in_capsule_data_size;
|
||||||
|
|
||||||
SPDK_DEBUGLOG(SPDK_LOG_NVMF_TCP, "In-capsule data: offset 0x%" PRIx64 ", length 0x%x\n",
|
SPDK_DEBUGLOG(SPDK_LOG_NVMF_TCP, "In-capsule data: offset 0x%" PRIx64 ", length 0x%x\n",
|
||||||
offset, length);
|
offset, length);
|
||||||
@ -2264,18 +2246,18 @@ spdk_nvmf_tcp_req_parse_sgl(struct spdk_nvmf_tcp_transport *ttransport,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
tcp_req->req.data = tcp_req->buf + offset;
|
req->data = tcp_req->buf + offset;
|
||||||
tcp_req->req.data_from_pool = false;
|
req->data_from_pool = false;
|
||||||
tcp_req->req.length = length;
|
req->length = length;
|
||||||
|
|
||||||
if (spdk_unlikely(tcp_req->dif_insert_or_strip)) {
|
if (spdk_unlikely(tcp_req->dif_insert_or_strip)) {
|
||||||
length = spdk_dif_get_length_with_md(length, &tcp_req->dif_ctx);
|
length = spdk_dif_get_length_with_md(length, &tcp_req->dif_ctx);
|
||||||
tcp_req->elba_length = length;
|
tcp_req->elba_length = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
tcp_req->req.iov[0].iov_base = tcp_req->req.data;
|
req->iov[0].iov_base = tcp_req->req.data;
|
||||||
tcp_req->req.iov[0].iov_len = length;
|
req->iov[0].iov_len = length;
|
||||||
tcp_req->req.iovcnt = 1;
|
req->iovcnt = 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2513,6 +2495,7 @@ spdk_nvmf_tcp_req_process(struct spdk_nvmf_tcp_transport *ttransport,
|
|||||||
int rc;
|
int rc;
|
||||||
enum spdk_nvmf_tcp_req_state prev_state;
|
enum spdk_nvmf_tcp_req_state prev_state;
|
||||||
bool progress = false;
|
bool progress = false;
|
||||||
|
struct spdk_nvmf_transport *transport = &ttransport->transport;
|
||||||
struct spdk_nvmf_transport_poll_group *group;
|
struct spdk_nvmf_transport_poll_group *group;
|
||||||
|
|
||||||
tqpair = SPDK_CONTAINEROF(tcp_req->req.qpair, struct spdk_nvmf_tcp_qpair, qpair);
|
tqpair = SPDK_CONTAINEROF(tcp_req->req.qpair, struct spdk_nvmf_tcp_qpair, qpair);
|
||||||
@ -2576,7 +2559,7 @@ spdk_nvmf_tcp_req_process(struct spdk_nvmf_tcp_transport *ttransport,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Try to get a data buffer */
|
/* Try to get a data buffer */
|
||||||
rc = spdk_nvmf_tcp_req_parse_sgl(ttransport, tcp_req);
|
rc = spdk_nvmf_tcp_req_parse_sgl(tcp_req, transport, group);
|
||||||
if (rc < 0) {
|
if (rc < 0) {
|
||||||
STAILQ_REMOVE_HEAD(&group->pending_buf_queue, buf_link);
|
STAILQ_REMOVE_HEAD(&group->pending_buf_queue, buf_link);
|
||||||
rsp->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
|
rsp->status.sc = SPDK_NVME_SC_INTERNAL_DEVICE_ERROR;
|
||||||
@ -2650,7 +2633,7 @@ spdk_nvmf_tcp_req_process(struct spdk_nvmf_tcp_transport *ttransport,
|
|||||||
case TCP_REQUEST_STATE_COMPLETED:
|
case TCP_REQUEST_STATE_COMPLETED:
|
||||||
spdk_trace_record(TRACE_TCP_REQUEST_STATE_COMPLETED, 0, 0, (uintptr_t)tcp_req, 0);
|
spdk_trace_record(TRACE_TCP_REQUEST_STATE_COMPLETED, 0, 0, (uintptr_t)tcp_req, 0);
|
||||||
if (tcp_req->req.data_from_pool) {
|
if (tcp_req->req.data_from_pool) {
|
||||||
spdk_nvmf_request_free_buffers(&tcp_req->req, group, &ttransport->transport);
|
spdk_nvmf_request_free_buffers(&tcp_req->req, group, transport);
|
||||||
}
|
}
|
||||||
tcp_req->req.length = 0;
|
tcp_req->req.length = 0;
|
||||||
tcp_req->req.iovcnt = 0;
|
tcp_req->req.iovcnt = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user