From 0f3198ba5b73dd5be95127f7680e5d2749f5a313 Mon Sep 17 00:00:00 2001 From: vlnb Date: Wed, 21 Apr 2010 18:32:35 +0000 Subject: [PATCH] - Merge of IET r255: cleanup copy & pasted code - Docs update --- iscsi-scst/ToDo | 6 ++--- iscsi-scst/usr/iscsid.c | 57 +++++++++++++++++++++++------------------ 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/iscsi-scst/ToDo b/iscsi-scst/ToDo index e9624d94..0d942d7c 100644 --- a/iscsi-scst/ToDo +++ b/iscsi-scst/ToDo @@ -1,6 +1,3 @@ - - __cmnd_abort() must be called by SCST core through new callback - instead of the driver itself. - - Remove the "poor man solution" suspending. Instead, immediate/unsolicited data for suspended commands should be received in the dummy_page and then, when they are resumed, aborted with BUSY status. All other @@ -14,6 +11,9 @@ - Code beautifying, i.e. make it be written in the same nice looking style. Particularly, all functions and variables names should share the same style. + - __cmnd_abort() should be called by SCST core through new callback + instead of the driver itself. + - Fix support of ranges in parameters negotiation. Are there any initiators who use ranges and, hence, can be used for testing? diff --git a/iscsi-scst/usr/iscsid.c b/iscsi-scst/usr/iscsid.c index cda3b26e..c7c1907e 100644 --- a/iscsi-scst/usr/iscsid.c +++ b/iscsi-scst/usr/iscsid.c @@ -467,10 +467,31 @@ static int init_conn_session_params(struct connection *conn) return res; } +static void login_rsp_ini_err(struct connection *conn, int status_detail) +{ + struct iscsi_login_rsp_hdr * const rsp = + (struct iscsi_login_rsp_hdr * const)&conn->rsp.bhs; + + rsp->status_class = ISCSI_STATUS_INITIATOR_ERR; + rsp->status_detail = status_detail; + conn->state = STATE_EXIT; + return; +} + +static void login_rsp_tgt_err(struct connection *conn, int status_detail) +{ + struct iscsi_login_rsp_hdr * const rsp = + (struct iscsi_login_rsp_hdr * const)&conn->rsp.bhs; + + rsp->status_class = ISCSI_STATUS_TARGET_ERR; + rsp->status_detail = status_detail; + conn->state = STATE_EXIT; + return; +} + static void login_start(struct connection *conn) { struct iscsi_login_req_hdr *req = (struct iscsi_login_req_hdr *)&conn->req.bhs; - struct iscsi_login_rsp_hdr *rsp = (struct iscsi_login_rsp_hdr *)&conn->rsp.bhs; char *name, *alias, *session_type, *target_name; conn->cid = be16_to_cpu(req->cid); @@ -478,18 +499,14 @@ static void login_start(struct connection *conn) name = text_key_find(conn, "InitiatorName"); if (!name) { - rsp->status_class = ISCSI_STATUS_INITIATOR_ERR; - rsp->status_detail = ISCSI_STATUS_MISSING_FIELDS; - conn->state = STATE_EXIT; + login_rsp_ini_err(conn, ISCSI_STATUS_MISSING_FIELDS); return; } conn->initiator = strdup(name); if (conn->initiator == NULL) { log_error("Unable to duplicate initiator's name %s", name); - rsp->status_class = ISCSI_STATUS_TARGET_ERR; - rsp->status_detail = ISCSI_STATUS_NO_RESOURCES; - conn->state = STATE_EXIT; + login_rsp_tgt_err(conn, ISCSI_STATUS_NO_RESOURCES); return; } @@ -504,9 +521,7 @@ static void login_start(struct connection *conn) if (!strcmp(session_type, "Discovery")) { conn->session_type = SESSION_DISCOVERY; } else if (strcmp(session_type, "Normal")) { - rsp->status_class = ISCSI_STATUS_INITIATOR_ERR; - rsp->status_detail = ISCSI_STATUS_INV_SESSION_TYPE; - conn->state = STATE_EXIT; + login_rsp_ini_err(conn, ISCSI_STATUS_INV_SESSION_TYPE); return; } } @@ -516,36 +531,31 @@ static void login_start(struct connection *conn) int err, rc; if (!target_name) { - rsp->status_class = ISCSI_STATUS_INITIATOR_ERR; - rsp->status_detail = ISCSI_STATUS_MISSING_FIELDS; - conn->state = STATE_EXIT; + login_rsp_ini_err(conn, ISCSI_STATUS_MISSING_FIELDS); return; } target = target_find_by_name(target_name); if (target == NULL) { - rsp->status_class = ISCSI_STATUS_INITIATOR_ERR; - rsp->status_detail = ISCSI_STATUS_TGT_NOT_FOUND; - conn->state = STATE_EXIT; + login_rsp_ini_err(conn, ISCSI_STATUS_TGT_NOT_FOUND); return; } if (!target->tgt_enabled) { log_info("Connect from %s to disabled target %s refused", name, target_name); - rsp->status_class = ISCSI_STATUS_TARGET_ERR; + login_rsp_tgt_err(conn, 0); conn->state = STATE_CLOSE; return; } conn->tid = target->tid; + if (config_initiator_access(conn->tid, conn->fd) || isns_scn_access(conn->tid, conn->fd, name)) { log_info("Initiator %s not allowed to connect to " "target %s", name, target_name); - rsp->status_class = ISCSI_STATUS_INITIATOR_ERR; - rsp->status_detail = ISCSI_STATUS_TGT_NOT_FOUND; - conn->state = STATE_EXIT; + login_rsp_ini_err(conn, ISCSI_STATUS_TGT_NOT_FOUND); return; } @@ -554,9 +564,7 @@ static void login_start(struct connection *conn) log_error("Can't get session params for session 0x%" PRIu64 " (err %d): %s\n", conn->sid.id64, err, strerror(-err)); - rsp->status_class = ISCSI_STATUS_TARGET_ERR; - rsp->status_detail = ISCSI_STATUS_TARGET_ERROR; - conn->state = STATE_EXIT; + login_rsp_tgt_err(conn, ISCSI_STATUS_TARGET_ERROR); return; } @@ -574,8 +582,7 @@ static void login_start(struct connection *conn) "target %s - max sessions limit " "reached (%d)", name, target_name, target->target_params[key_max_sessions]); - rsp->status_class = ISCSI_STATUS_TARGET_ERR; - rsp->status_detail = ISCSI_STATUS_NO_RESOURCES; + login_rsp_tgt_err(conn, ISCSI_STATUS_NO_RESOURCES); conn->state = STATE_CLOSE; return; }