Since connect in iscsi_io_tcp_connect() is nonblocking, that fn will
return -1, errno=EINPROGRESS and schedule an immediate poll. This calls
session_conn_poll, and the ep_poll() returns 0, which then results in
scheduling another EV_CONN_POLL (session_conn_poll) immediately, and
repeat forever because the connection will never be established and
never have any data.

Instead, change iscsi_conn_connect to first look for data one second after
the nonblocking connect() is attempted, and change session_conn_poll to
wait three seconds before polling the socket fd again if no data.
(Values picked from the air.)

Finally, iscsi_sched_ev_context needs to be modified to use the timeout
(tmo) value for EV_CONN_POLL events.

One future enhancement we might consider is figuring out how to fold
polling these connecting socket fds into the outer poll loop in
event_loop(), which would let us handle connections in a more event-driven
model.

Signed-off-by: Andy Grover <[email protected]>
---
 usr/initiator.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/usr/initiator.c b/usr/initiator.c
index 1aadc9b..83bbdbf 100644
--- a/usr/initiator.c
+++ b/usr/initiator.c
@@ -562,7 +562,7 @@ static int iscsi_conn_connect(struct iscsi_conn *conn, 
queue_task_t *qtask)
                return ENOTCONN;
        }
 
-       iscsi_sched_ev_context(ev_context, conn, 0, EV_CONN_POLL);
+       iscsi_sched_ev_context(ev_context, conn, 1, EV_CONN_POLL);
        log_debug(3, "Setting login timer %p timeout %d", &conn->login_timer,
                  conn->login_timeout);
        actor_timer(&conn->login_timer, conn->login_timeout,
@@ -1571,7 +1571,6 @@ static void session_conn_poll(void *data)
        rc = session->t->template->ep_poll(conn, 1);
        if (rc == 0) {
                log_debug(4, "poll not connected %d", rc);
-               /* timedout: Poll again. */
                ev_context = iscsi_ev_context_get(conn, 0);
                if (!ev_context) {
                        /* while polling the recv pool should be full */
@@ -1581,7 +1580,8 @@ static void session_conn_poll(void *data)
                        return;
                }
                ev_context->data = qtask;
-               iscsi_sched_ev_context(ev_context, conn, 0, EV_CONN_POLL);
+               /* not connected yet, check later */
+               iscsi_sched_ev_context(ev_context, conn, 3, EV_CONN_POLL);
        } else if (rc > 0) {
                /* connected! */
                memset(c, 0, sizeof(iscsi_login_context_t));
@@ -1824,9 +1824,8 @@ static int iscsi_sched_ev_context(struct iscsi_ev_context 
*ev_context,
                actor_schedule(&ev_context->actor);
                break;
        case EV_CONN_POLL:
-               actor_init(&ev_context->actor, session_conn_poll,
-                         ev_context);
-               actor_schedule(&ev_context->actor);
+               actor_timer(&ev_context->actor, tmo,
+                           session_conn_poll, ev_context);
                break;
        case EV_UIO_POLL:
                actor_init(&ev_context->actor, session_conn_uio_poll,
-- 
2.1.0

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/open-iscsi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to