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 <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/378658
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ziye Yang <optimistyzy@gmail.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Daniel Verkamp 2017-09-14 13:15:50 -07:00 committed by Jim Harris
parent dd9fdb0c55
commit 1e33a802b4
2 changed files with 3 additions and 11 deletions

View File

@ -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

View File

@ -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");