From bb61fabf26960091b94300640943a4b174167ac6 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Tue, 29 Oct 2019 07:24:28 +0900 Subject: [PATCH] lib/iscsi: Clarify only logout with reason "close the session" is acceptable on discovery session Based on the following description in Chapter 4.3 "iSCSI Session Types in iSCSI specification b) Discovery session - a session only opened for target discovery. The target MUST ONLY accept Text Requests with the SendTargets key and a Logout Request with reason "close the session". All other requests MUST be rejected. update the comment slightly, add macro constants for iSCSI logout reason, and change the ordering of checks to be session type and then logout reason. Signed-off-by: Shuhei Matsumoto Change-Id: Ifc2ecc5b6dde546700662d3cda59d8cc465fd83a Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/472672 Tested-by: SPDK CI Jenkins Reviewed-by: Changpeng Liu Reviewed-by: Jim Harris Reviewed-by: Ziye Yang --- lib/iscsi/iscsi.c | 7 +++++-- lib/iscsi/iscsi.h | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 615977771..f54d01b1f 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -2484,8 +2484,11 @@ iscsi_pdu_hdr_op_logout(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu reqh->reason, task_tag, cid); if (conn->sess != NULL) { - 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\n"); + if (conn->sess->session_type == SESSION_TYPE_DISCOVERY && + reqh->reason != ISCSI_LOGOUT_REASON_CLOSE_SESSION) { + SPDK_ERRLOG("Target can accept logout only with reason \"close the session\" " + "on discovery session. %d is not acceptable reason.\n", + reqh->reason); return SPDK_ISCSI_CONNECTION_FATAL; } diff --git a/lib/iscsi/iscsi.h b/lib/iscsi/iscsi.h index 863fa434e..3de512b7a 100644 --- a/lib/iscsi/iscsi.h +++ b/lib/iscsi/iscsi.h @@ -358,6 +358,11 @@ struct spdk_iscsi_globals { #define ISCSI_NSG_RESERVED_CODE 2 #define ISCSI_FULL_FEATURE_PHASE 3 +/* logout reason */ +#define ISCSI_LOGOUT_REASON_CLOSE_SESSION 0 +#define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION 1 +#define ISCSI_LOGOUT_REASON_REMOVE_CONN_FOR_RECOVERY 2 + enum spdk_error_codes { SPDK_ISCSI_CONNECTION_FATAL = -1, SPDK_PDU_FATAL = -2,