summaryrefslogtreecommitdiff
path: root/usr/discovery.c
diff options
context:
space:
mode:
authorLalit Chandivade <lalit.chandivade@qlogic.com>2011-08-14 15:07:59 -0500
committerMike Christie <michaelc@cs.wisc.edu>2011-08-14 22:12:57 -0500
commit4c46693adcc35a1e2dbe22e1e7bd90254f189bd1 (patch)
treec16b9ad139638c0048a1953e47c6f9d071ad99db /usr/discovery.c
parent2029bf16ca3e3378d9f0f7c747d95f2f3489327e (diff)
downloadopen-iscsi-4c46693adcc35a1e2dbe22e1e7bd90254f189bd1.tar.gz
iscsi tools: manage qla4xxx iscsi sessions with iscsiadm
This patch is based on initial work done by Mike Christie here, http://groups.google.com/group/open-iscsi/browse_thread/thread/193fe9037f3127da# This patch modifies iscsiadm so it can control sessions that are accessed through qla4xxx. To do discovery using the qla4xxx iscsi class interface first check the available qla4xxx iface ./iscsiadm -m iface -P 0 will display the different ifaces like this: qla4xxx.00:0e:1e:04:87:fa qla4xxx,00:0e:1e:04:87:fa,192.168.1.112,\ <empty>,<empty> qla4xxx.00:0e:1e:04:87:fe qla4xxx,00:0e:1e:04:87:fe,<empty>,<empty>,<empty> Issue discovery command ./iscsiadm -m discovery -t sendtargets -I qla4xxx.00:0e:1e:04:87:fa \ -p 192.168.1.10:3260 192.168.1.10:3260,1 iqn.2001-05.com.target:0-7d76ca2b7d54b541-disk2 192.168.1.10:3260,1 iqn.2001-05.com.target:0-46f6ca2b7d84b541-disk3 192.168.1.10:3260,1 iqn.2001-05.com.target:0-4c76ca2b7db4b541-disk4 192.168.1.10:3260,1 iqn.2001-05.com.target:0-7346ca2b6d04b6bb-disk1 To view discovered nodes do ./iscsiadm -m node To login ./iscsiadm -m node -T iqn.2001-05.com.target:0-7346ca2b6d04b6bb-disk1 \ -I qla4xxx.00:0e:1e:04:87:fa -p 192.168.1.10:3260 -l An error or ok message is displayed to indicate login failure or success. To see the sessions use ./iscsiadm -m session And then to logout do ./iscsiadm -m node -T iqn.2001-05.com.target:0-7346ca2b6d04b6bb-disk1 \ -I qla4xxx.00:0e:1e:04:87:fa -p 192.168.1.10:3260 -u An error or a ok message is displayed to indicate logout failure or success. Signed-off-by: Manish Rangankar <manish.rangankar@qlogic.com> Signed-off-by: Lalit Chandivade <lalit.chandivade@qlogic.com> Signed-off-by: Vikas Chaudhary <vikas.chaudhary@qlogic.com> Signed-off-by: Mike Christie <michaelc@cs.wisc.edu>
Diffstat (limited to 'usr/discovery.c')
-rw-r--r--usr/discovery.c93
1 files changed, 91 insertions, 2 deletions
diff --git a/usr/discovery.c b/usr/discovery.c
index a0d073c..1f39002 100644
--- a/usr/discovery.c
+++ b/usr/discovery.c
@@ -1227,7 +1227,7 @@ static int iscsi_sched_ev_context(struct iscsi_ev_context *ev_context,
struct iscsi_conn *conn, unsigned long tmo,
int event)
{
- if (event == EV_CONN_RECV_PDU) {
+ if (event == EV_CONN_RECV_PDU || event == EV_CONN_LOGIN) {
conn->recv_context = ev_context;
return 0;
}
@@ -1241,6 +1241,89 @@ static struct iscsi_ipc_ev_clbk ipc_clbk = {
.sched_ev_context = iscsi_sched_ev_context,
};
+static int iscsi_wait_for_login(struct iscsi_conn *conn)
+{
+ struct iscsi_session *session = conn->session;
+ struct iscsi_transport *t = session->t;
+ struct pollfd pfd;
+ struct timeval connection_timer;
+ int timeout, rc;
+ uint32_t conn_state;
+ int status = 0;
+
+ if (!(t->caps & CAP_LOGIN_OFFLOAD))
+ return 0;
+
+ iscsi_timer_set(&connection_timer, conn->active_timeout);
+
+ /* prepare to poll */
+ memset(&pfd, 0, sizeof(pfd));
+ pfd.fd = conn->socket_fd;
+ pfd.events = POLLIN | POLLPRI;
+
+ timeout = iscsi_timer_msecs_until(&connection_timer);
+
+login_repoll:
+ log_debug(4, "discovery login process polling fd %d, "
+ "timeout in %f seconds", pfd.fd, timeout / 1000.0);
+
+ pfd.revents = 0;
+ rc = poll(&pfd, 1, timeout);
+
+ log_debug(7, "discovery login process returned from poll, rc %d", rc);
+
+ if (iscsi_timer_expired(&connection_timer)) {
+ log_warning("Discovery login session timed out.");
+ rc = ISCSI_ERR_INTERNAL;
+ goto done;
+ }
+
+ if (rc > 0) {
+ if (pfd.revents & (POLLIN | POLLPRI)) {
+ timeout = iscsi_timer_msecs_until(&connection_timer);
+ status = ipc->recv_conn_state(conn, &conn_state);
+ if (status == -EAGAIN)
+ goto login_repoll;
+ else if (status < 0) {
+ rc = ISCSI_ERR_TRANS;
+ goto done;
+ }
+
+ if (conn_state != ISCSI_CONN_STATE_LOGGED_IN)
+ rc = ISCSI_ERR_TRANS;
+ else
+ rc = 0;
+ goto done;
+ }
+
+ if (pfd.revents & POLLHUP) {
+ log_warning("discovery session"
+ "terminating after hangup");
+ rc = ISCSI_ERR_TRANS;
+ goto done;
+ }
+
+ if (pfd.revents & POLLNVAL) {
+ log_warning("discovery POLLNVAL");
+ rc = ISCSI_ERR_INTERNAL;
+ goto done;
+ }
+
+ if (pfd.revents & POLLERR) {
+ log_warning("discovery POLLERR");
+ rc = ISCSI_ERR_INTERNAL;
+ goto done;
+ }
+ } else if (rc < 0) {
+ log_error("Login poll error");
+ rc = ISCSI_ERR_INTERNAL;
+ goto done;
+ }
+
+done:
+ return rc;
+}
+
static int iscsi_create_session(struct iscsi_session *session,
struct iscsi_sendtargets_config *config,
char *data, unsigned int data_len)
@@ -1320,6 +1403,9 @@ redirect_reconnect:
iscsi_copy_operational_params(&session->conn[0], &config->session_conf,
&config->conn_conf);
+ if ((session->t->caps & CAP_LOGIN_OFFLOAD))
+ goto start_conn;
+
status_class = 0;
status_detail = 0;
rc = ISCSI_ERR_LOGIN;
@@ -1422,6 +1508,7 @@ redirect_reconnect:
if (!(t->caps & CAP_TEXT_NEGO))
return 0;
+start_conn:
log_debug(2, "%s discovery set params\n", __FUNCTION__);
rc = iscsi_session_set_params(conn);
if (rc) {
@@ -1439,7 +1526,9 @@ redirect_reconnect:
goto login_failed;
}
- return 0;
+ rc = iscsi_wait_for_login(conn);
+ if (!rc)
+ return 0;
login_failed:
iscsi_destroy_session(session);