From 1e33a802b408ed72fa9c2d3ce9080759184dc419 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 14 Sep 2017 13:15:50 -0700 Subject: [PATCH] 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: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/378658 Tested-by: SPDK Automated Test System Reviewed-by: Ziye Yang Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris --- include/spdk/iscsi_spec.h | 6 ++---- lib/iscsi/iscsi.c | 8 +------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/include/spdk/iscsi_spec.h b/include/spdk/iscsi_spec.h index c81a812417..06e5678650 100644 --- a/include/spdk/iscsi_spec.h +++ b/include/spdk/iscsi_spec.h @@ -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 diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 77a493dee3..0b2c56f008 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -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");