Index: sys/dev/iscsi/iscsi.c =================================================================== --- sys/dev/iscsi/iscsi.c +++ sys/dev/iscsi/iscsi.c @@ -473,12 +473,7 @@ STAILQ_EMPTY(&is->is_postponed)) cv_wait(&is->is_maintenance_cv, &is->is_lock); - if (is->is_reconnecting) { - ISCSI_SESSION_UNLOCK(is); - iscsi_maintenance_thread_reconnect(is); - continue; - } - + /* Terminate supersedes reconnect. */ if (is->is_terminating) { ISCSI_SESSION_UNLOCK(is); iscsi_maintenance_thread_terminate(is); @@ -486,6 +481,12 @@ return; } + if (is->is_reconnecting) { + ISCSI_SESSION_UNLOCK(is); + iscsi_maintenance_thread_reconnect(is); + continue; + } + iscsi_session_send_postponed(is); ISCSI_SESSION_UNLOCK(is); } @@ -2322,23 +2323,16 @@ { struct iscsi_session *is; + ISCSI_DEBUG("removing all sessions due to shutdown"); + /* * Trying to reconnect during system shutdown would lead to hang. */ fail_on_disconnection = 1; - /* - * If we have any sessions waiting for reconnection, request - * maintenance thread to fail them immediately instead of waiting - * for reconnect timeout. - */ sx_slock(&sc->sc_lock); - TAILQ_FOREACH(is, &sc->sc_sessions, is_next) { - ISCSI_SESSION_LOCK(is); - if (is->is_waiting_for_iscsid) - iscsi_session_reconnect(is); - ISCSI_SESSION_UNLOCK(is); - } + TAILQ_FOREACH(is, &sc->sc_sessions, is_next) + iscsi_session_terminate(is); sx_sunlock(&sc->sc_lock); } @@ -2364,8 +2358,14 @@ } sc->sc_cdev->si_drv1 = sc; - sc->sc_shutdown_eh = EVENTHANDLER_REGISTER(shutdown_pre_sync, - iscsi_shutdown, sc, SHUTDOWN_PRI_DEFAULT-1); + /* + * Note that this needs to get run after filesystem shutdown and before + * CAM shutdown otherwise when rebooting with an iSCSI session that is + * disconnected but has outstanding requests, dashutdown() will hang on + * cam_periph_runccb(). + */ + sc->sc_shutdown_eh = EVENTHANDLER_REGISTER(shutdown_post_sync, + iscsi_shutdown, sc, SHUTDOWN_PRI_DEFAULT - 1); return (0); } @@ -2382,7 +2382,7 @@ } if (sc->sc_shutdown_eh != NULL) - EVENTHANDLER_DEREGISTER(shutdown_pre_sync, sc->sc_shutdown_eh); + EVENTHANDLER_DEREGISTER(shutdown_post_sync, sc->sc_shutdown_eh); sx_slock(&sc->sc_lock); TAILQ_FOREACH_SAFE(is, &sc->sc_sessions, is_next, tmp)