From e17851314ef0021fb021462e39ad35b5f3a03aa4 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Fri, 1 Mar 2019 14:25:35 +0900 Subject: [PATCH] iscsi: Hold size of buffer to store PDU data segment in struct spdk_iscsi_pdu Upcoming patches will store larger data in the data buffer than iSCSI Initiator transfers, and size of metadata is not known until asking to SCSI layer. This addition will be used to avoid overflow in them. Change-Id: I43e15d0cfbfddcf01342325b134d90e3d7dae038 Signed-off-by: Shuhei Matsumoto Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/446378 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Ziye Yang Reviewed-by: Jim Harris --- lib/iscsi/iscsi.c | 3 +++ lib/iscsi/iscsi.h | 1 + 2 files changed, 4 insertions(+) diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 7c652ddc3..d100b4405 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -468,8 +468,10 @@ spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu **_pdu) if (pdu->data_buf == NULL) { if (data_len <= spdk_get_immediate_data_buffer_size()) { pool = g_spdk_iscsi.pdu_immediate_data_pool; + pdu->data_buf_len = spdk_get_immediate_data_buffer_size(); } else if (data_len <= SPDK_ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH) { pool = g_spdk_iscsi.pdu_data_out_pool; + pdu->data_buf_len = SPDK_ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH; } else { SPDK_ERRLOG("Data(%d) > MaxSegment(%d)\n", data_len, SPDK_ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH); @@ -2595,6 +2597,7 @@ spdk_iscsi_send_datain(struct spdk_iscsi_conn *conn, rsp_pdu = spdk_get_pdu(); rsph = (struct iscsi_bhs_data_in *)&rsp_pdu->bhs; rsp_pdu->data = task->scsi.iovs[0].iov_base + offset; + rsp_pdu->data_buf_len = task->scsi.iovs[0].iov_len - offset; rsp_pdu->data_from_mempool = true; task_tag = task->tag; diff --git a/lib/iscsi/iscsi.h b/lib/iscsi/iscsi.h index 401d7ea5d..2ed6b9fe6 100644 --- a/lib/iscsi/iscsi.h +++ b/lib/iscsi/iscsi.h @@ -172,6 +172,7 @@ struct spdk_iscsi_pdu { struct spdk_iscsi_task *task; /* data tied to a task buffer */ uint32_t cmd_sn; uint32_t writev_offset; + uint32_t data_buf_len; TAILQ_ENTRY(spdk_iscsi_pdu) tailq;