iscsi: Unify calculate mapped length and build iovecs to flush PDUs

To know the mapped length by iovecs, pdu length was got first and
then the size of partial written was reduced separately.

This patch unifies these two operations into spdk_iscsi_build_iovs().

Change-Id: Ic6f5eecc902b8e209ef00c010915f476ca16c002
Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/446175
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ziye Yang <ziye.yang@intel.com>
This commit is contained in:
Shuhei Matsumoto 2019-02-26 11:26:42 +09:00 committed by Jim Harris
parent 879386d759
commit ca0022f9da
5 changed files with 36 additions and 21 deletions

View File

@ -1153,8 +1153,8 @@ spdk_iscsi_conn_flush_pdus_internal(struct spdk_iscsi_conn *conn)
struct iovec *iov = iovs;
int iovcnt = 0;
int bytes = 0;
int total_length = 0;
uint32_t writev_offset;
uint32_t total_length = 0;
uint32_t mapped_length = 0;
struct spdk_iscsi_pdu *pdu;
int pdu_length;
@ -1173,17 +1173,12 @@ spdk_iscsi_conn_flush_pdus_internal(struct spdk_iscsi_conn *conn)
* But extra overhead is negligible.
*/
while (pdu != NULL && ((num_iovs - iovcnt) >= 5)) {
pdu_length = spdk_iscsi_get_pdu_length(pdu,
conn->header_digest,
conn->data_digest);
iovcnt += spdk_iscsi_build_iovs(conn, &iovs[iovcnt], pdu);
total_length += pdu_length;
iovcnt += spdk_iscsi_build_iovs(conn, &iovs[iovcnt], pdu,
&mapped_length);
total_length += mapped_length;
pdu = TAILQ_NEXT(pdu, tailq);
}
writev_offset = TAILQ_FIRST(&conn->write_pdu_list)->writev_offset;
total_length -= writev_offset;
spdk_trace_record(TRACE_ISCSI_FLUSH_WRITEBUF_START, conn->id, total_length, 0, iovcnt);
bytes = spdk_sock_writev(conn->sock, iov, iovcnt);

View File

@ -565,13 +565,14 @@ spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu **_pdu)
int
spdk_iscsi_build_iovs(struct spdk_iscsi_conn *conn, struct iovec *iovs,
struct spdk_iscsi_pdu *pdu)
struct spdk_iscsi_pdu *pdu, uint32_t *_mapped_length)
{
int iovcnt = 0;
int enable_digest;
uint32_t total_ahs_len;
uint32_t data_len;
uint32_t iov_offset;
uint32_t mapped_length = 0;
total_ahs_len = pdu->bhs.total_ahs_len;
data_len = DGET24(pdu->bhs.data_segment_len);
@ -591,6 +592,7 @@ spdk_iscsi_build_iovs(struct spdk_iscsi_conn *conn, struct iovec *iovs,
} else {
iovs[iovcnt].iov_base = (uint8_t *)&pdu->bhs + iov_offset;
iovs[iovcnt].iov_len = ISCSI_BHS_LEN - iov_offset;
mapped_length += ISCSI_BHS_LEN - iov_offset;
iov_offset = 0;
iovcnt++;
}
@ -601,6 +603,7 @@ spdk_iscsi_build_iovs(struct spdk_iscsi_conn *conn, struct iovec *iovs,
} else {
iovs[iovcnt].iov_base = pdu->ahs + iov_offset;
iovs[iovcnt].iov_len = 4 * total_ahs_len - iov_offset;
mapped_length += 4 * total_ahs_len - iov_offset;
iov_offset = 0;
iovcnt++;
}
@ -613,6 +616,7 @@ spdk_iscsi_build_iovs(struct spdk_iscsi_conn *conn, struct iovec *iovs,
} else {
iovs[iovcnt].iov_base = pdu->header_digest + iov_offset;
iovs[iovcnt].iov_len = ISCSI_DIGEST_LEN - iov_offset;
mapped_length += ISCSI_DIGEST_LEN - iov_offset;
iov_offset = 0;
iovcnt++;
}
@ -625,6 +629,7 @@ spdk_iscsi_build_iovs(struct spdk_iscsi_conn *conn, struct iovec *iovs,
} else {
iovs[iovcnt].iov_base = pdu->data + iov_offset;
iovs[iovcnt].iov_len = data_len - iov_offset;
mapped_length += data_len - iov_offset;
iov_offset = 0;
iovcnt++;
}
@ -635,10 +640,15 @@ spdk_iscsi_build_iovs(struct spdk_iscsi_conn *conn, struct iovec *iovs,
if (iov_offset < ISCSI_DIGEST_LEN) {
iovs[iovcnt].iov_base = pdu->data_digest + iov_offset;
iovs[iovcnt].iov_len = ISCSI_DIGEST_LEN - iov_offset;
mapped_length += ISCSI_DIGEST_LEN - iov_offset;
iovcnt++;
}
}
if (_mapped_length != NULL) {
*_mapped_length = mapped_length;
}
return iovcnt;
}

View File

@ -405,7 +405,8 @@ void spdk_iscsi_task_response(struct spdk_iscsi_conn *conn,
struct spdk_iscsi_task *task);
int spdk_iscsi_execute(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu);
int spdk_iscsi_build_iovs(struct spdk_iscsi_conn *conn,
struct iovec *iovs, struct spdk_iscsi_pdu *pdu);
struct iovec *iovs, struct spdk_iscsi_pdu *pdu,
uint32_t *mapped_length);
int spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu **_pdu);
void spdk_iscsi_task_mgmt_response(struct spdk_iscsi_conn *conn,
struct spdk_iscsi_task *task);

View File

@ -139,7 +139,7 @@ DEFINE_STUB_V(spdk_clear_all_transfer_task,
DEFINE_STUB(spdk_iscsi_build_iovs, int,
(struct spdk_iscsi_conn *conn, struct iovec *iov,
struct spdk_iscsi_pdu *pdu),
struct spdk_iscsi_pdu *pdu, uint32_t *mapped_length),
0);
DEFINE_STUB(spdk_iscsi_is_deferred_free_pdu, bool,

View File

@ -1209,6 +1209,7 @@ build_iovs_test(void)
struct spdk_iscsi_pdu pdu = {};
struct iovec iovs[5] = {};
uint8_t *data;
uint32_t mapped_length = 0;
int rc;
conn.header_digest = true;
@ -1223,7 +1224,7 @@ build_iovs_test(void)
pdu.bhs.opcode = ISCSI_OP_SCSI;
pdu.writev_offset = 0;
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu);
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu, &mapped_length);
CU_ASSERT(rc == 4);
CU_ASSERT(iovs[0].iov_base == (void *)&pdu.bhs);
CU_ASSERT(iovs[0].iov_len == ISCSI_BHS_LEN);
@ -1233,9 +1234,10 @@ build_iovs_test(void)
CU_ASSERT(iovs[2].iov_len == 512);
CU_ASSERT(iovs[3].iov_base == (void *)pdu.data_digest);
CU_ASSERT(iovs[3].iov_len == ISCSI_DIGEST_LEN);
CU_ASSERT(mapped_length == ISCSI_BHS_LEN + ISCSI_DIGEST_LEN + 512 + ISCSI_DIGEST_LEN);
pdu.writev_offset = ISCSI_BHS_LEN / 2;
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu);
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu, &mapped_length);
CU_ASSERT(rc == 4);
CU_ASSERT(iovs[0].iov_base == (void *)((uint8_t *)&pdu.bhs + ISCSI_BHS_LEN / 2));
CU_ASSERT(iovs[0].iov_len == ISCSI_BHS_LEN / 2);
@ -1245,9 +1247,10 @@ build_iovs_test(void)
CU_ASSERT(iovs[2].iov_len == 512);
CU_ASSERT(iovs[3].iov_base == (void *)pdu.data_digest);
CU_ASSERT(iovs[3].iov_len == ISCSI_DIGEST_LEN);
CU_ASSERT(mapped_length == ISCSI_BHS_LEN / 2 + ISCSI_DIGEST_LEN + 512 + ISCSI_DIGEST_LEN);
pdu.writev_offset = ISCSI_BHS_LEN;
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu);
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu, &mapped_length);
CU_ASSERT(rc == 3);
CU_ASSERT(iovs[0].iov_base == (void *)pdu.header_digest);
CU_ASSERT(iovs[0].iov_len == ISCSI_DIGEST_LEN);
@ -1255,9 +1258,10 @@ build_iovs_test(void)
CU_ASSERT(iovs[1].iov_len == 512);
CU_ASSERT(iovs[2].iov_base == (void *)pdu.data_digest);
CU_ASSERT(iovs[2].iov_len == ISCSI_DIGEST_LEN);
CU_ASSERT(mapped_length == ISCSI_DIGEST_LEN + 512 + ISCSI_DIGEST_LEN);
pdu.writev_offset = ISCSI_BHS_LEN + ISCSI_DIGEST_LEN / 2;
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu);
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu, &mapped_length);
CU_ASSERT(rc == 3);
CU_ASSERT(iovs[0].iov_base == (void *)((uint8_t *)pdu.header_digest + ISCSI_DIGEST_LEN / 2));
CU_ASSERT(iovs[0].iov_len == ISCSI_DIGEST_LEN / 2);
@ -1265,30 +1269,35 @@ build_iovs_test(void)
CU_ASSERT(iovs[1].iov_len == 512);
CU_ASSERT(iovs[2].iov_base == (void *)pdu.data_digest);
CU_ASSERT(iovs[2].iov_len == ISCSI_DIGEST_LEN);
CU_ASSERT(mapped_length == ISCSI_DIGEST_LEN / 2 + 512 + ISCSI_DIGEST_LEN);
pdu.writev_offset = ISCSI_BHS_LEN + ISCSI_DIGEST_LEN;
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu);
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu, &mapped_length);
CU_ASSERT(rc == 2);
CU_ASSERT(iovs[0].iov_base == (void *)pdu.data);
CU_ASSERT(iovs[0].iov_len == 512);
CU_ASSERT(iovs[1].iov_base == (void *)pdu.data_digest);
CU_ASSERT(iovs[1].iov_len == ISCSI_DIGEST_LEN);
CU_ASSERT(mapped_length == 512 + ISCSI_DIGEST_LEN);
pdu.writev_offset = ISCSI_BHS_LEN + ISCSI_DIGEST_LEN + 512;
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu);
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu, &mapped_length);
CU_ASSERT(rc == 1);
CU_ASSERT(iovs[0].iov_base == (void *)pdu.data_digest);
CU_ASSERT(iovs[0].iov_len == ISCSI_DIGEST_LEN);
CU_ASSERT(mapped_length == ISCSI_DIGEST_LEN);
pdu.writev_offset = ISCSI_BHS_LEN + ISCSI_DIGEST_LEN + 512 + ISCSI_DIGEST_LEN / 2;
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu);
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu, &mapped_length);
CU_ASSERT(rc == 1);
CU_ASSERT(iovs[0].iov_base == (void *)((uint8_t *)pdu.data_digest + ISCSI_DIGEST_LEN / 2));
CU_ASSERT(iovs[0].iov_len == ISCSI_DIGEST_LEN / 2);
CU_ASSERT(mapped_length == ISCSI_DIGEST_LEN / 2);
pdu.writev_offset = ISCSI_BHS_LEN + ISCSI_DIGEST_LEN + 512 + ISCSI_DIGEST_LEN;
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu);
rc = spdk_iscsi_build_iovs(&conn, iovs, &pdu, &mapped_length);
CU_ASSERT(rc == 0);
CU_ASSERT(mapped_length == 0);
free(data);
}