From 85e6f154b8ff8c8cdee10c727cb28bfe31d8a2d1 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 4 Jun 2019 16:06:54 +0900 Subject: [PATCH] iscsi: Get DIF context once when allocating data buffer DIF context had been got for every read of data segment but DIF context is not changed and so getting DIF context once when allocating data buffer is enough and is done in this patch. Signed-off-by: Shuhei Matsumoto Change-Id: I0f386ab594a0d9076fa0206d5fc240f5c790181d Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/456772 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris Reviewed-by: Ziye Yang --- lib/iscsi/iscsi.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index c551d2343..4a1a49bdc 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -365,27 +365,25 @@ iscsi_conn_read_data_segment(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu, uint32_t segment_len) { - struct spdk_dif_ctx dif_ctx; struct iovec buf_iov, iovs[32]; int rc, _rc; - if (spdk_likely(!spdk_iscsi_get_dif_ctx(conn, pdu, &dif_ctx))) { + if (spdk_likely(!pdu->dif_insert_or_strip)) { return spdk_iscsi_conn_read_data(conn, segment_len - pdu->data_valid_bytes, pdu->data_buf + pdu->data_valid_bytes); } else { - pdu->dif_insert_or_strip = true; buf_iov.iov_base = pdu->data_buf; buf_iov.iov_len = pdu->data_buf_len; rc = spdk_dif_set_md_interleave_iovs(iovs, 32, &buf_iov, 1, pdu->data_valid_bytes, segment_len, NULL, - &dif_ctx); + &pdu->dif_ctx); if (rc > 0) { rc = spdk_iscsi_conn_readv_data(conn, iovs, rc); if (rc > 0) { _rc = spdk_dif_generate_stream(&buf_iov, 1, pdu->data_valid_bytes, rc, - &dif_ctx); + &pdu->dif_ctx); if (_rc != 0) { SPDK_ERRLOG("DIF generate failed\n"); rc = _rc; @@ -484,6 +482,10 @@ spdk_iscsi_read_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu **_pdu) return 0; } pdu->data_buf = pdu->mobj->buf; + + if (spdk_unlikely(spdk_iscsi_get_dif_ctx(conn, pdu, &pdu->dif_ctx))) { + pdu->dif_insert_or_strip = true; + } } rc = iscsi_conn_read_data_segment(conn, pdu, data_len);