From 93967961c8ce1d8ba5faae12884ca668126e4709 Mon Sep 17 00:00:00 2001 From: lizengwu <786436671@qq.com> Date: Thu, 24 Nov 2022 17:16:48 +0800 Subject: [PATCH] iscsi: fix the abnormal connection exit the mobj is allocating from pdu_data_out_pool, if pdu_data_out_pool is exhausted, when the pdu is polled next time, because data_buf_len is modified, iscsi_pdu_payload_read return -1, and the connection will be released. Signed-off-by: lizengwu <786436671@qq.com> Change-Id: I3ee65472f7ddaa357d7952a5b734540f0bc0b216 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15626 Reviewed-by: Changpeng Liu Reviewed-by: Shuhei Matsumoto Reviewed-by: Jim Harris Reviewed-by: Konrad Sztyber Tested-by: SPDK CI Jenkins --- lib/iscsi/iscsi.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 8e427e43e..6bc373341 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -4614,18 +4614,20 @@ iscsi_pdu_payload_read(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu) uint32_t read_len; uint32_t crc32c; int rc; + uint32_t data_buf_len; data_len = pdu->data_segment_len; read_len = data_len - pdu->data_valid_bytes; + data_buf_len = pdu->data_buf_len; mobj = pdu->mobj[0]; if (mobj == NULL) { - if (pdu->data_buf_len <= iscsi_get_max_immediate_data_size()) { + if (data_buf_len <= iscsi_get_max_immediate_data_size()) { pool = g_iscsi.pdu_immediate_data_pool; - pdu->data_buf_len = SPDK_BDEV_BUF_SIZE_WITH_MD(iscsi_get_max_immediate_data_size()); - } else if (pdu->data_buf_len <= SPDK_ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH) { + data_buf_len = SPDK_BDEV_BUF_SIZE_WITH_MD(iscsi_get_max_immediate_data_size()); + } else if (data_buf_len <= SPDK_ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH) { pool = g_iscsi.pdu_data_out_pool; - pdu->data_buf_len = SPDK_BDEV_BUF_SIZE_WITH_MD(SPDK_ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH); + data_buf_len = SPDK_BDEV_BUF_SIZE_WITH_MD(SPDK_ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH); } else { SPDK_ERRLOG("Data(%d) > MaxSegment(%d)\n", data_len, SPDK_ISCSI_MAX_RECV_DATA_SEGMENT_LENGTH); @@ -4635,6 +4637,9 @@ iscsi_pdu_payload_read(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu) if (mobj == NULL) { return 1; } + + pdu->data_buf_len = data_buf_len; + pdu->mobj[0] = mobj; pdu->data = mobj->buf; pdu->data_from_mempool = true;