Commit 2d1e0096 authored by Shuhei Matsumoto's avatar Shuhei Matsumoto Committed by Jim Harris
Browse files

lib/iscsi: Store and use rsp_pdu->data_buf_len for login



A local variable alloc_len had been used to hold the data buffer
length of the response PDU. But it's more intuitive to use
rsp_pdu->data_buf_len instead.

The subsequent two patches will replace related functions accordingly.

Signed-off-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I48f96a542d6c177ba1d8409ff0230fa61c11e154
Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/471468


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarZiye Yang <ziye.yang@intel.com>
parent 71f8a7d7
Loading
Loading
Loading
Loading
+9 −14
Original line number Diff line number Diff line
@@ -1790,10 +1790,11 @@ iscsi_op_login_phase_none(struct spdk_iscsi_conn *conn,
static int
iscsi_op_login_rsp_init(struct spdk_iscsi_conn *conn,
			struct spdk_iscsi_pdu *pdu, struct spdk_iscsi_pdu *rsp_pdu,
			int *alloc_len, int *cid)
			int *cid)
{
	struct iscsi_bhs_login_req *reqh;
	struct iscsi_bhs_login_rsp *rsph;
	uint32_t alloc_len;

	rsph = (struct iscsi_bhs_login_rsp *)&rsp_pdu->bhs;
	rsph->opcode = ISCSI_OP_LOGIN_RSP;
@@ -1803,18 +1804,19 @@ iscsi_op_login_rsp_init(struct spdk_iscsi_conn *conn,

	/* Default MaxRecvDataSegmentLength - RFC3720(12.12) */
	if (conn->MaxRecvDataSegmentLength < 8192) {
		*alloc_len = 8192;
		alloc_len = 8192;
	} else {
		*alloc_len = conn->MaxRecvDataSegmentLength;
		alloc_len = conn->MaxRecvDataSegmentLength;
	}

	rsp_pdu->data = calloc(1, *alloc_len);
	rsp_pdu->data = calloc(1, alloc_len);
	if (!rsp_pdu->data) {
		SPDK_ERRLOG("calloc() failed for data segment\n");
		rsph->status_class = ISCSI_CLASS_TARGET_ERROR;
		rsph->status_detail = ISCSI_LOGIN_STATUS_NO_RESOURCES;
		return SPDK_ISCSI_LOGIN_ERROR_RESPONSE;
	}
	rsp_pdu->data_buf_len = alloc_len;

	reqh = (struct iscsi_bhs_login_req *)&pdu->bhs;
	rsph->flags |= (reqh->flags & ISCSI_LOGIN_TRANSIT);
@@ -2167,7 +2169,6 @@ iscsi_op_login(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
	struct iscsi_bhs_login_req *reqh;
	struct spdk_iscsi_pdu *rsp_pdu;
	struct iscsi_param *params = NULL;
	int alloc_len;
	int cid;

	if (conn->full_feature && conn->sess != NULL &&
@@ -2189,7 +2190,7 @@ iscsi_op_login(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
	if (rsp_pdu == NULL) {
		return SPDK_ISCSI_CONNECTION_FATAL;
	}
	rc = iscsi_op_login_rsp_init(conn, pdu, rsp_pdu, &alloc_len, &cid);
	rc = iscsi_op_login_rsp_init(conn, pdu, rsp_pdu, &cid);
	if (rc < 0) {
		iscsi_op_login_response(conn, rsp_pdu, NULL);
		return rc;
@@ -2201,22 +2202,16 @@ iscsi_op_login(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
		return rc;
	}

	/* For other values, we need to directly return */
	if (rc < 0) {
		spdk_put_pdu(rsp_pdu);
		return rc;
	}

	if (conn->state == ISCSI_CONN_STATE_INVALID) {
		rc = iscsi_op_login_phase_none(conn, rsp_pdu, params,
					       alloc_len, cid);
					       rsp_pdu->data_buf_len, cid);
		if (rc == SPDK_ISCSI_LOGIN_ERROR_RESPONSE || rc == SPDK_ISCSI_LOGIN_ERROR_PARAMETER) {
			iscsi_op_login_response(conn, rsp_pdu, params);
			return rc;
		}
	}

	rc = iscsi_op_login_rsp_handle(conn, rsp_pdu, &params, alloc_len);
	rc = iscsi_op_login_rsp_handle(conn, rsp_pdu, &params, rsp_pdu->data_buf_len);
	if (rc == SPDK_ISCSI_LOGIN_ERROR_RESPONSE) {
		iscsi_op_login_response(conn, rsp_pdu, params);
		return rc;