Commit 1e33a802 authored by Daniel Verkamp's avatar Daniel Verkamp Committed by Jim Harris
Browse files

iscsi: fix layout of logout request reason field



The Logout Request reason field is the low 7 bits of byte byte 1; the
last bit of byte 1 is specified to be always 1, and we shouldn't
consider it to be part of the reason field.

The existing debug print code was parsing the reason field correctly (by
masking it against 0x7f), but it's simpler to just make the reason field
into a bitfield of the proper size; this fixes the real bug in the
reqh->reason != 0 check, which did not use the 0x7f mask.

Fixes GitHub issue #198.

Change-Id: I4813da2236c70dc1761e303b34d321750ee36626
Signed-off-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/378658


Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarZiye Yang <optimistyzy@gmail.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent dd9fdb0c
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -203,7 +203,8 @@ struct iscsi_bhs_logout_req {
	uint8_t opcode		: 6;	/* opcode = 0x06 */
	uint8_t immediate	: 1;
	uint8_t reserved	: 1;
	uint8_t reason;
	uint8_t reason		: 7;
	uint8_t reason_1	: 1;
	uint8_t res[2];
	uint8_t total_ahs_len;
	uint8_t data_segment_len[3];
@@ -482,9 +483,6 @@ struct iscsi_bhs_text_resp {
/* text flags */
#define ISCSI_TEXT_CONTINUE			0x40

/* logout flags */
#define ISCSI_LOGOUT_REASON_MASK		0x7f

/* datain flags */
#define ISCSI_DATAIN_ACKNOLWEDGE		0x40
#define ISCSI_DATAIN_OVERFLOW			0x04
+1 −7
Original line number Diff line number Diff line
@@ -2439,15 +2439,9 @@ spdk_iscsi_op_logout(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
	struct iscsi_bhs_logout_req *reqh;
	struct iscsi_bhs_logout_resp *rsph;
	uint16_t cid;
#ifdef DEBUG
	int reason;
#endif

	reqh = (struct iscsi_bhs_logout_req *)&pdu->bhs;

#ifdef DEBUG
	reason = reqh->reason & ISCSI_LOGOUT_REASON_MASK;
#endif
	cid = from_be16(&reqh->cid);
	task_tag = from_be32(&reqh->itt);
	CmdSN = from_be32(&reqh->cmd_sn);
@@ -2455,7 +2449,7 @@ spdk_iscsi_op_logout(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
	ExpStatSN = from_be32(&reqh->exp_stat_sn);

	SPDK_DEBUGLOG(SPDK_TRACE_ISCSI, "reason=%d, ITT=%x, cid=%d\n",
		      reason, task_tag, cid);
		      reqh->reason, task_tag, cid);

	if (reqh->reason != 0 && conn->sess->session_type == SESSION_TYPE_DISCOVERY) {
		SPDK_ERRLOG("only logout with close the session reason can be in discovery session");