From 466f9e8b2004e39f4e5d0e88b5ce8edd4dbc80a8 Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Mon, 25 Apr 2022 15:45:12 +0200 Subject: [PATCH] sock: extract prepping iovs for a single req to a function It'll make it possible to reuse this code for asynchronous read requests. Signed-off-by: Konrad Sztyber Change-Id: I2c2c44feee0821c972aa2a43d8a8ec81f3ce4ef4 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12591 Tested-by: SPDK CI Jenkins Community-CI: Broadcom CI Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto --- include/spdk_internal/sock.h | 59 ++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/include/spdk_internal/sock.h b/include/spdk_internal/sock.h index e8b083982..1f4653b10 100644 --- a/include/spdk_internal/sock.h +++ b/include/spdk_internal/sock.h @@ -230,13 +230,47 @@ spdk_sock_abort_requests(struct spdk_sock *sock) return rc; } +static inline int +spdk_sock_prep_req(struct spdk_sock_request *req, struct iovec *iovs, int index, + uint64_t *num_bytes) +{ + unsigned int offset; + int iovcnt, i; + + assert(index < IOV_BATCH_SIZE); + offset = req->internal.offset; + iovcnt = index; + + for (i = 0; i < req->iovcnt; i++) { + /* Consume any offset first */ + if (offset >= SPDK_SOCK_REQUEST_IOV(req, i)->iov_len) { + offset -= SPDK_SOCK_REQUEST_IOV(req, i)->iov_len; + continue; + } + + iovs[iovcnt].iov_base = SPDK_SOCK_REQUEST_IOV(req, i)->iov_base + offset; + iovs[iovcnt].iov_len = SPDK_SOCK_REQUEST_IOV(req, i)->iov_len - offset; + if (num_bytes != NULL) { + *num_bytes += iovs[iovcnt].iov_len; + } + + iovcnt++; + offset = 0; + + if (iovcnt >= IOV_BATCH_SIZE) { + break; + } + } + + return iovcnt; +} + static inline int spdk_sock_prep_reqs(struct spdk_sock *_sock, struct iovec *iovs, int index, struct spdk_sock_request **last_req, int *flags) { - int iovcnt, i; + int iovcnt; struct spdk_sock_request *req; - unsigned int offset; uint64_t total = 0; /* Gather an iov */ @@ -252,26 +286,7 @@ spdk_sock_prep_reqs(struct spdk_sock *_sock, struct iovec *iovs, int index, } while (req) { - offset = req->internal.offset; - - for (i = 0; i < req->iovcnt; i++) { - /* Consume any offset first */ - if (offset >= SPDK_SOCK_REQUEST_IOV(req, i)->iov_len) { - offset -= SPDK_SOCK_REQUEST_IOV(req, i)->iov_len; - continue; - } - - iovs[iovcnt].iov_base = SPDK_SOCK_REQUEST_IOV(req, i)->iov_base + offset; - iovs[iovcnt].iov_len = SPDK_SOCK_REQUEST_IOV(req, i)->iov_len - offset; - - total += iovs[iovcnt].iov_len; - iovcnt++; - offset = 0; - - if (iovcnt >= IOV_BATCH_SIZE) { - break; - } - } + iovcnt = spdk_sock_prep_req(req, iovs, iovcnt, &total); if (iovcnt >= IOV_BATCH_SIZE) { break; }