From ea05be3ff043efd44256283d968fa1bb9a371568 Mon Sep 17 00:00:00 2001
From: Mike Christie <michaelc@cs.wisc.edu>
Date: Thu, 13 Feb 2014 12:37:09 -0600
Subject: [PATCH] iscsi tools: set non negotiated params early.
This patch has the iscsi tools pass down the non-negotiated
iscsi settings before doing iscsi login. This allows the
drivers to get info that might be neede to setup the session
early.
This patch also adds the missing discovery_sess param to
the non negotiated params.
---
usr/discovery.c | 15 +++++++++--
usr/initiator.c | 22 +++++++++++-----
usr/initiator.h | 1 +
usr/initiator_common.c | 69 ++++++++++++++++++++++++++++++++++++++++++++------
4 files changed, 91 insertions(+), 16 deletions(-)
diff --git a/usr/discovery.c b/usr/discovery.c
index afce6c0..635ec8d 100644
--- a/usr/discovery.c
+++ b/usr/discovery.c
@@ -1403,6 +1403,17 @@ redirect_reconnect:
iscsi_copy_operational_params(&session->conn[0], &config->session_conf,
&config->conn_conf);
+ if (t->caps & CAP_TEXT_NEGO) {
+ log_debug(2, "%s discovery set params\n", __FUNCTION__);
+ rc = iscsi_session_set_params(conn);
+ if (rc) {
+ log_error("Could not set iscsi params for conn %d:%d "
+ "(err %d)\n", session->id, conn->id, rc);
+ rc = ISCSI_ERR_INTERNAL;
+ goto login_failed;
+ }
+ }
+
if ((session->t->caps & CAP_LOGIN_OFFLOAD))
goto start_conn;
@@ -1509,8 +1520,8 @@ redirect_reconnect:
return 0;
start_conn:
- log_debug(2, "%s discovery set params\n", __FUNCTION__);
- rc = iscsi_session_set_params(conn);
+ log_debug(2, "%s discovery set neg params\n", __FUNCTION__);
+ rc = iscsi_session_set_neg_params(conn);
if (rc) {
log_error("Could not set iscsi params for conn %d:%d (err "
"%d)\n", session->id, conn->id, rc);
diff --git a/usr/initiator.c b/usr/initiator.c
index 79d1779..05a5b19 100644
--- a/usr/initiator.c
+++ b/usr/initiator.c
@@ -1048,12 +1048,7 @@ setup_full_feature_phase(iscsi_conn_t *conn)
actor_delete(&conn->login_timer);
- if (iscsi_session_set_params(conn)) {
- iscsi_login_eh(conn, c->qtask, ISCSI_ERR_LOGIN);
- return;
- }
-
- if (iscsi_host_set_params(session)) {
+ if (iscsi_session_set_neg_params(conn)) {
iscsi_login_eh(conn, c->qtask, ISCSI_ERR_LOGIN);
return;
}
@@ -1507,6 +1502,11 @@ static void setup_offload_login_phase(iscsi_conn_t *conn)
return;
}
+ if (iscsi_session_set_neg_params(conn)) {
+ iscsi_login_eh(conn, c->qtask, ISCSI_ERR_LOGIN);
+ return;
+ }
+
if (iscsi_host_set_params(session)) {
iscsi_login_eh(conn, c->qtask, ISCSI_ERR_LOGIN);
return;
@@ -1618,6 +1618,16 @@ static void session_conn_poll(void *data)
return;
}
+ if (iscsi_session_set_params(conn)) {
+ iscsi_login_eh(conn, qtask, ISCSI_ERR_LOGIN);
+ return;
+ }
+
+ if (iscsi_host_set_params(session)) {
+ iscsi_login_eh(conn, qtask, ISCSI_ERR_LOGIN);
+ return;
+ }
+
if (iscsi_login_begin(session, c)) {
iscsi_login_eh(conn, qtask, ISCSI_ERR_LOGIN);
return;
diff --git a/usr/initiator.h b/usr/initiator.h
index 680640c..c34625b 100644
--- a/usr/initiator.h
+++ b/usr/initiator.h
@@ -344,6 +344,7 @@ extern void free_initiator(void);
extern void iscsi_initiator_init(void);
/* initiator code common to discovery and normal sessions */
+extern int iscsi_session_set_neg_params(struct iscsi_conn *conn);
extern int iscsi_session_set_params(struct iscsi_conn *conn);
extern int iscsi_host_set_params(struct iscsi_session *session);
extern int iscsi_host_set_net_params(struct iface_rec *iface,
diff --git a/usr/initiator_common.c b/usr/initiator_common.c
index e2e87a1..109e8d7 100644
--- a/usr/initiator_common.c
+++ b/usr/initiator_common.c
@@ -345,9 +345,9 @@ void iscsi_session_init_params(struct iscsi_session *session)
}
}
-#define MAX_SESSION_PARAMS 35
+#define MAX_SESSION_NEG_PARAMS 16
-int iscsi_session_set_params(struct iscsi_conn *conn)
+int iscsi_session_set_neg_params(struct iscsi_conn *conn)
{
struct iscsi_session *session = conn->session;
int i, rc;
@@ -357,7 +357,7 @@ int iscsi_session_set_params(struct iscsi_conn *conn)
int type;
void *value;
int conn_only;
- } conntbl[MAX_SESSION_PARAMS] = {
+ } conntbl[MAX_SESSION_NEG_PARAMS] = {
{
.param = ISCSI_PARAM_MAX_RECV_DLENGTH,
.value = &conn->max_recv_dlength,
@@ -434,15 +434,58 @@ int iscsi_session_set_params(struct iscsi_conn *conn)
.type = ISCSI_INT,
.conn_only = 1,
}, {
- .param = ISCSI_PARAM_TARGET_NAME,
- .conn_only = 0,
- .type = ISCSI_STRING,
- .value = session->target_name,
- }, {
.param = ISCSI_PARAM_TPGT,
.value = &session->portal_group_tag,
.type = ISCSI_INT,
.conn_only = 0,
+ },
+ };
+
+ iscsi_session_init_params(session);
+
+ /* Entered full-feature phase! */
+ for (i = 0; i < MAX_SESSION_NEG_PARAMS; i++) {
+ if (conn->id != 0 && !conntbl[i].conn_only)
+ continue;
+
+ if (!(session->param_mask & (1ULL << conntbl[i].param)))
+ continue;
+
+ rc = ipc->set_param(session->t->handle, session->id,
+ conn->id, conntbl[i].param, conntbl[i].value,
+ conntbl[i].type);
+ if (rc && rc != -ENOSYS) {
+ log_error("can't set operational parameter %d for "
+ "connection %d:%d, retcode %d (%d)",
+ conntbl[i].param, session->id, conn->id,
+ rc, errno);
+ return EPERM;
+ }
+
+ print_param_value(conntbl[i].param, conntbl[i].value,
+ conntbl[i].type);
+ }
+
+ return 0;
+}
+
+#define MAX_SESSION_PARAMS 20
+
+int iscsi_session_set_params(struct iscsi_conn *conn)
+{
+ struct iscsi_session *session = conn->session;
+ int i, rc;
+ struct connparam {
+ int param;
+ int type;
+ void *value;
+ int conn_only;
+ } conntbl[MAX_SESSION_PARAMS] = {
+ {
+ .param = ISCSI_PARAM_TARGET_NAME,
+ .conn_only = 0,
+ .type = ISCSI_STRING,
+ .value = session->target_name,
}, {
.param = ISCSI_PARAM_PERSISTENT_ADDRESS,
.value = session->nrec.conn[conn->id].address,
@@ -512,22 +555,32 @@ int iscsi_session_set_params(struct iscsi_conn *conn)
.param = ISCSI_PARAM_IFACE_NAME,
.value = session->nrec.iface.name,
.type = ISCSI_STRING,
+ .conn_only = 0,
}, {
.param = ISCSI_PARAM_INITIATOR_NAME,
.value = session->initiator_name,
.type = ISCSI_STRING,
+ .conn_only = 0,
}, {
.param = ISCSI_PARAM_BOOT_ROOT,
.value = session->nrec.session.boot_root,
.type = ISCSI_STRING,
+ .conn_only = 0,
}, {
.param = ISCSI_PARAM_BOOT_NIC,
.value = session->nrec.session.boot_nic,
.type = ISCSI_STRING,
+ .conn_only = 0,
}, {
.param = ISCSI_PARAM_BOOT_TARGET,
.value = session->nrec.session.boot_target,
.type = ISCSI_STRING,
+ .conn_only = 0,
+ }, {
+ .param = ISCSI_PARAM_DISCOVERY_SESS,
+ .value = &session->type,
+ .type = ISCSI_INT,
+ .conn_only = 0,
},
};
--
1.8.3.1