aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libiscsi.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/libiscsi.c')
-rw-r--r--drivers/scsi/libiscsi.c65
1 files changed, 52 insertions, 13 deletions
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 5606d1e62978..efceed451b46 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -737,12 +737,19 @@ check_mgmt:
737 */ 737 */
738 conn->ctask = list_entry(conn->xmitqueue.next, 738 conn->ctask = list_entry(conn->xmitqueue.next,
739 struct iscsi_cmd_task, running); 739 struct iscsi_cmd_task, running);
740 if (conn->ctask->state == ISCSI_TASK_PENDING) { 740 switch (conn->ctask->state) {
741 case ISCSI_TASK_ABORTING:
742 break;
743 case ISCSI_TASK_PENDING:
741 iscsi_prep_scsi_cmd_pdu(conn->ctask); 744 iscsi_prep_scsi_cmd_pdu(conn->ctask);
742 conn->session->tt->init_cmd_task(conn->ctask); 745 conn->session->tt->init_cmd_task(conn->ctask);
746 /* fall through */
747 default:
748 conn->ctask->state = ISCSI_TASK_RUNNING;
749 break;
743 } 750 }
744 conn->ctask->state = ISCSI_TASK_RUNNING;
745 list_move_tail(conn->xmitqueue.next, &conn->run_list); 751 list_move_tail(conn->xmitqueue.next, &conn->run_list);
752
746 rc = iscsi_xmit_ctask(conn); 753 rc = iscsi_xmit_ctask(conn);
747 if (rc) 754 if (rc)
748 goto again; 755 goto again;
@@ -1049,7 +1056,9 @@ static int iscsi_exec_abort_task(struct scsi_cmnd *sc,
1049 ctask->mtask = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)hdr, 1056 ctask->mtask = __iscsi_conn_send_pdu(conn, (struct iscsi_hdr *)hdr,
1050 NULL, 0); 1057 NULL, 0);
1051 if (!ctask->mtask) { 1058 if (!ctask->mtask) {
1059 spin_unlock_bh(&session->lock);
1052 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); 1060 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1061 spin_lock_bh(&session->lock)
1053 debug_scsi("abort sent failure [itt 0x%x]\n", ctask->itt); 1062 debug_scsi("abort sent failure [itt 0x%x]\n", ctask->itt);
1054 return -EPERM; 1063 return -EPERM;
1055 } 1064 }
@@ -1066,6 +1075,7 @@ static int iscsi_exec_abort_task(struct scsi_cmnd *sc,
1066 debug_scsi("abort set timeout [itt 0x%x]\n", ctask->itt); 1075 debug_scsi("abort set timeout [itt 0x%x]\n", ctask->itt);
1067 } 1076 }
1068 spin_unlock_bh(&session->lock); 1077 spin_unlock_bh(&session->lock);
1078 mutex_unlock(&session->eh_mutex);
1069 scsi_queue_work(session->host, &conn->xmitwork); 1079 scsi_queue_work(session->host, &conn->xmitwork);
1070 1080
1071 /* 1081 /*
@@ -1083,6 +1093,7 @@ static int iscsi_exec_abort_task(struct scsi_cmnd *sc,
1083 if (signal_pending(current)) 1093 if (signal_pending(current))
1084 flush_signals(current); 1094 flush_signals(current);
1085 del_timer_sync(&conn->tmabort_timer); 1095 del_timer_sync(&conn->tmabort_timer);
1096 mutex_lock(&session->eh_mutex);
1086 spin_lock_bh(&session->lock); 1097 spin_lock_bh(&session->lock);
1087 return 0; 1098 return 0;
1088} 1099}
@@ -1158,31 +1169,45 @@ static void fail_command(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
1158 __iscsi_put_ctask(ctask); 1169 __iscsi_put_ctask(ctask);
1159} 1170}
1160 1171
1172static void iscsi_suspend_tx(struct iscsi_conn *conn)
1173{
1174 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
1175 scsi_flush_work(conn->session->host);
1176}
1177
1178static void iscsi_start_tx(struct iscsi_conn *conn)
1179{
1180 clear_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
1181 scsi_queue_work(conn->session->host, &conn->xmitwork);
1182}
1183
1161int iscsi_eh_abort(struct scsi_cmnd *sc) 1184int iscsi_eh_abort(struct scsi_cmnd *sc)
1162{ 1185{
1186 struct Scsi_Host *host = sc->device->host;
1187 struct iscsi_session *session = iscsi_hostdata(host->hostdata);
1163 struct iscsi_cmd_task *ctask; 1188 struct iscsi_cmd_task *ctask;
1164 struct iscsi_conn *conn; 1189 struct iscsi_conn *conn;
1165 struct iscsi_session *session;
1166 int rc; 1190 int rc;
1167 1191
1192 mutex_lock(&session->eh_mutex);
1193 spin_lock_bh(&session->lock);
1168 /* 1194 /*
1169 * if session was ISCSI_STATE_IN_RECOVERY then we may not have 1195 * if session was ISCSI_STATE_IN_RECOVERY then we may not have
1170 * got the command. 1196 * got the command.
1171 */ 1197 */
1172 if (!sc->SCp.ptr) { 1198 if (!sc->SCp.ptr) {
1173 debug_scsi("sc never reached iscsi layer or it completed.\n"); 1199 debug_scsi("sc never reached iscsi layer or it completed.\n");
1200 spin_unlock_bh(&session->lock);
1201 mutex_unlock(&session->eh_mutex);
1174 return SUCCESS; 1202 return SUCCESS;
1175 } 1203 }
1176 1204
1177 ctask = (struct iscsi_cmd_task *)sc->SCp.ptr; 1205 ctask = (struct iscsi_cmd_task *)sc->SCp.ptr;
1178 conn = ctask->conn; 1206 conn = ctask->conn;
1179 session = conn->session;
1180 1207
1181 conn->eh_abort_cnt++; 1208 conn->eh_abort_cnt++;
1182 debug_scsi("aborting [sc %p itt 0x%x]\n", sc, ctask->itt); 1209 debug_scsi("aborting [sc %p itt 0x%x]\n", sc, ctask->itt);
1183 1210
1184 spin_lock_bh(&session->lock);
1185
1186 /* 1211 /*
1187 * If we are not logged in or we have started a new session 1212 * If we are not logged in or we have started a new session
1188 * then let the host reset code handle this 1213 * then let the host reset code handle this
@@ -1219,6 +1244,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1219 switch (conn->tmabort_state) { 1244 switch (conn->tmabort_state) {
1220 case TMABORT_SUCCESS: 1245 case TMABORT_SUCCESS:
1221 spin_unlock_bh(&session->lock); 1246 spin_unlock_bh(&session->lock);
1247 iscsi_suspend_tx(conn);
1222 /* 1248 /*
1223 * clean up task if aborted. grab the recv lock as a writer 1249 * clean up task if aborted. grab the recv lock as a writer
1224 */ 1250 */
@@ -1227,11 +1253,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1227 fail_command(conn, ctask, DID_ABORT << 16); 1253 fail_command(conn, ctask, DID_ABORT << 16);
1228 spin_unlock(&session->lock); 1254 spin_unlock(&session->lock);
1229 write_unlock_bh(conn->recv_lock); 1255 write_unlock_bh(conn->recv_lock);
1230 /* 1256 iscsi_start_tx(conn);
1231 * make sure xmit thread is not still touching the
1232 * ctask/scsi_cmnd
1233 */
1234 scsi_flush_work(session->host);
1235 goto success_unlocked; 1257 goto success_unlocked;
1236 case TMABORT_NOT_FOUND: 1258 case TMABORT_NOT_FOUND:
1237 if (!ctask->sc) { 1259 if (!ctask->sc) {
@@ -1251,12 +1273,14 @@ success:
1251 spin_unlock_bh(&session->lock); 1273 spin_unlock_bh(&session->lock);
1252success_unlocked: 1274success_unlocked:
1253 debug_scsi("abort success [sc %lx itt 0x%x]\n", (long)sc, ctask->itt); 1275 debug_scsi("abort success [sc %lx itt 0x%x]\n", (long)sc, ctask->itt);
1276 mutex_unlock(&session->eh_mutex);
1254 return SUCCESS; 1277 return SUCCESS;
1255 1278
1256failed: 1279failed:
1257 spin_unlock_bh(&session->lock); 1280 spin_unlock_bh(&session->lock);
1258failed_unlocked: 1281failed_unlocked:
1259 debug_scsi("abort failed [sc %lx itt 0x%x]\n", (long)sc, ctask->itt); 1282 debug_scsi("abort failed [sc %lx itt 0x%x]\n", (long)sc, ctask->itt);
1283 mutex_unlock(&session->eh_mutex);
1260 return FAILED; 1284 return FAILED;
1261} 1285}
1262EXPORT_SYMBOL_GPL(iscsi_eh_abort); 1286EXPORT_SYMBOL_GPL(iscsi_eh_abort);
@@ -1403,6 +1427,7 @@ iscsi_session_setup(struct iscsi_transport *iscsit,
1403 session->max_cmdsn = initial_cmdsn + 1; 1427 session->max_cmdsn = initial_cmdsn + 1;
1404 session->max_r2t = 1; 1428 session->max_r2t = 1;
1405 session->tt = iscsit; 1429 session->tt = iscsit;
1430 mutex_init(&session->eh_mutex);
1406 1431
1407 /* initialize SCSI PDU commands pool */ 1432 /* initialize SCSI PDU commands pool */
1408 if (iscsi_pool_init(&session->cmdpool, session->cmds_max, 1433 if (iscsi_pool_init(&session->cmdpool, session->cmds_max,
@@ -1736,9 +1761,22 @@ static void iscsi_start_session_recovery(struct iscsi_session *session,
1736{ 1761{
1737 int old_stop_stage; 1762 int old_stop_stage;
1738 1763
1764 mutex_lock(&session->eh_mutex);
1739 spin_lock_bh(&session->lock); 1765 spin_lock_bh(&session->lock);
1740 if (conn->stop_stage == STOP_CONN_TERM) { 1766 if (conn->stop_stage == STOP_CONN_TERM) {
1741 spin_unlock_bh(&session->lock); 1767 spin_unlock_bh(&session->lock);
1768 mutex_unlock(&session->eh_mutex);
1769 return;
1770 }
1771
1772 /*
1773 * The LLD either freed/unset the lock on us, or userspace called
1774 * stop but did not create a proper connection (connection was never
1775 * bound or it was unbound then stop was called).
1776 */
1777 if (!conn->recv_lock) {
1778 spin_unlock_bh(&session->lock);
1779 mutex_unlock(&session->eh_mutex);
1742 return; 1780 return;
1743 } 1781 }
1744 1782
@@ -1755,9 +1793,9 @@ static void iscsi_start_session_recovery(struct iscsi_session *session,
1755 old_stop_stage = conn->stop_stage; 1793 old_stop_stage = conn->stop_stage;
1756 conn->stop_stage = flag; 1794 conn->stop_stage = flag;
1757 conn->c_stage = ISCSI_CONN_STOPPED; 1795 conn->c_stage = ISCSI_CONN_STOPPED;
1758 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx);
1759 spin_unlock_bh(&session->lock); 1796 spin_unlock_bh(&session->lock);
1760 scsi_flush_work(session->host); 1797
1798 iscsi_suspend_tx(conn);
1761 1799
1762 write_lock_bh(conn->recv_lock); 1800 write_lock_bh(conn->recv_lock);
1763 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx); 1801 set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx);
@@ -1786,6 +1824,7 @@ static void iscsi_start_session_recovery(struct iscsi_session *session,
1786 fail_all_commands(conn); 1824 fail_all_commands(conn);
1787 flush_control_queues(session, conn); 1825 flush_control_queues(session, conn);
1788 spin_unlock_bh(&session->lock); 1826 spin_unlock_bh(&session->lock);
1827 mutex_unlock(&session->eh_mutex);
1789} 1828}
1790 1829
1791void iscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag) 1830void iscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)