Skip to content

Commit

Permalink
scsi: iscsi: Fix iSCSI cls conn state
Browse files Browse the repository at this point in the history
commit 0dcf8fe upstream.

In commit 9e67600 ("scsi: iscsi: Fix race condition between login and
sync thread") I missed that libiscsi was now setting the iSCSI class state,
and that patch ended up resetting the state during conn stoppage and using
the wrong state value during ep_disconnect. This patch moves the setting of
the class state to the class module and then fixes the two issues above.

Link: https://lore.kernel.org/r/20210406171746.5016-1-michael.christie@oracle.com
Fixes: 9e67600 ("scsi: iscsi: Fix race condition between login and sync thread")
Cc: Gulam Mohamed <gulam.mohamed@oracle.com>
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Hanjun Guo <guohanjun@huawei.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
mikechristie authored and gregkh committed Jul 19, 2021
1 parent 221b7e1 commit 4ad382b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
26 changes: 3 additions & 23 deletions drivers/scsi/libiscsi.c
Expand Up @@ -3089,9 +3089,10 @@ fail_mgmt_tasks(struct iscsi_session *session, struct iscsi_conn *conn)
}
}

static void iscsi_start_session_recovery(struct iscsi_session *session,
struct iscsi_conn *conn, int flag)
void iscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
{
struct iscsi_conn *conn = cls_conn->dd_data;
struct iscsi_session *session = conn->session;
int old_stop_stage;

mutex_lock(&session->eh_mutex);
Expand Down Expand Up @@ -3149,27 +3150,6 @@ static void iscsi_start_session_recovery(struct iscsi_session *session,
spin_unlock_bh(&session->frwd_lock);
mutex_unlock(&session->eh_mutex);
}

void iscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
{
struct iscsi_conn *conn = cls_conn->dd_data;
struct iscsi_session *session = conn->session;

switch (flag) {
case STOP_CONN_RECOVER:
cls_conn->state = ISCSI_CONN_FAILED;
break;
case STOP_CONN_TERM:
cls_conn->state = ISCSI_CONN_DOWN;
break;
default:
iscsi_conn_printk(KERN_ERR, conn,
"invalid stop flag %d\n", flag);
return;
}

iscsi_start_session_recovery(session, conn, flag);
}
EXPORT_SYMBOL_GPL(iscsi_conn_stop);

int iscsi_conn_bind(struct iscsi_cls_session *cls_session,
Expand Down
18 changes: 15 additions & 3 deletions drivers/scsi/scsi_transport_iscsi.c
Expand Up @@ -2479,10 +2479,22 @@ static void iscsi_if_stop_conn(struct iscsi_cls_conn *conn, int flag)
* it works.
*/
mutex_lock(&conn_mutex);
switch (flag) {
case STOP_CONN_RECOVER:
conn->state = ISCSI_CONN_FAILED;
break;
case STOP_CONN_TERM:
conn->state = ISCSI_CONN_DOWN;
break;
default:
iscsi_cls_conn_printk(KERN_ERR, conn,
"invalid stop flag %d\n", flag);
goto unlock;
}

conn->transport->stop_conn(conn, flag);
conn->state = ISCSI_CONN_DOWN;
unlock:
mutex_unlock(&conn_mutex);

}

static void stop_conn_work_fn(struct work_struct *work)
Expand Down Expand Up @@ -2973,7 +2985,7 @@ static int iscsi_if_ep_disconnect(struct iscsi_transport *transport,
mutex_lock(&conn->ep_mutex);
conn->ep = NULL;
mutex_unlock(&conn->ep_mutex);
conn->state = ISCSI_CONN_DOWN;
conn->state = ISCSI_CONN_FAILED;
}

transport->ep_disconnect(ep);
Expand Down

0 comments on commit 4ad382b

Please sign in to comment.