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 <konrad.sztyber@intel.com> Change-Id: I2c2c44feee0821c972aa2a43d8a8ec81f3ce4ef4 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12591 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
This commit is contained in:
parent
6d3506d893
commit
466f9e8b20
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user