diff options
Diffstat (limited to 'drivers/scsi/libiscsi.c')
-rw-r--r-- | drivers/scsi/libiscsi.c | 64 |
1 files changed, 27 insertions, 37 deletions
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c index c15fde808c33..da8b61543ee4 100644 --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c | |||
@@ -505,6 +505,7 @@ static void iscsi_free_task(struct iscsi_task *task) | |||
505 | struct iscsi_conn *conn = task->conn; | 505 | struct iscsi_conn *conn = task->conn; |
506 | struct iscsi_session *session = conn->session; | 506 | struct iscsi_session *session = conn->session; |
507 | struct scsi_cmnd *sc = task->sc; | 507 | struct scsi_cmnd *sc = task->sc; |
508 | int oldstate = task->state; | ||
508 | 509 | ||
509 | ISCSI_DBG_SESSION(session, "freeing task itt 0x%x state %d sc %p\n", | 510 | ISCSI_DBG_SESSION(session, "freeing task itt 0x%x state %d sc %p\n", |
510 | task->itt, task->state, task->sc); | 511 | task->itt, task->state, task->sc); |
@@ -525,10 +526,10 @@ static void iscsi_free_task(struct iscsi_task *task) | |||
525 | /* SCSI eh reuses commands to verify us */ | 526 | /* SCSI eh reuses commands to verify us */ |
526 | sc->SCp.ptr = NULL; | 527 | sc->SCp.ptr = NULL; |
527 | /* | 528 | /* |
528 | * queue command may call this to free the task, but | 529 | * queue command may call this to free the task, so |
529 | * not have setup the sc callback | 530 | * it will decide how to return sc to scsi-ml. |
530 | */ | 531 | */ |
531 | if (sc->scsi_done) | 532 | if (oldstate != ISCSI_TASK_REQUEUE_SCSIQ) |
532 | sc->scsi_done(sc); | 533 | sc->scsi_done(sc); |
533 | } | 534 | } |
534 | } | 535 | } |
@@ -539,11 +540,12 @@ void __iscsi_get_task(struct iscsi_task *task) | |||
539 | } | 540 | } |
540 | EXPORT_SYMBOL_GPL(__iscsi_get_task); | 541 | EXPORT_SYMBOL_GPL(__iscsi_get_task); |
541 | 542 | ||
542 | static void __iscsi_put_task(struct iscsi_task *task) | 543 | void __iscsi_put_task(struct iscsi_task *task) |
543 | { | 544 | { |
544 | if (atomic_dec_and_test(&task->refcount)) | 545 | if (atomic_dec_and_test(&task->refcount)) |
545 | iscsi_free_task(task); | 546 | iscsi_free_task(task); |
546 | } | 547 | } |
548 | EXPORT_SYMBOL_GPL(__iscsi_put_task); | ||
547 | 549 | ||
548 | void iscsi_put_task(struct iscsi_task *task) | 550 | void iscsi_put_task(struct iscsi_task *task) |
549 | { | 551 | { |
@@ -571,7 +573,8 @@ static void iscsi_complete_task(struct iscsi_task *task, int state) | |||
571 | task->itt, task->state, task->sc); | 573 | task->itt, task->state, task->sc); |
572 | if (task->state == ISCSI_TASK_COMPLETED || | 574 | if (task->state == ISCSI_TASK_COMPLETED || |
573 | task->state == ISCSI_TASK_ABRT_TMF || | 575 | task->state == ISCSI_TASK_ABRT_TMF || |
574 | task->state == ISCSI_TASK_ABRT_SESS_RECOV) | 576 | task->state == ISCSI_TASK_ABRT_SESS_RECOV || |
577 | task->state == ISCSI_TASK_REQUEUE_SCSIQ) | ||
575 | return; | 578 | return; |
576 | WARN_ON_ONCE(task->state == ISCSI_TASK_FREE); | 579 | WARN_ON_ONCE(task->state == ISCSI_TASK_FREE); |
577 | task->state = state; | 580 | task->state = state; |
@@ -1335,17 +1338,16 @@ void iscsi_session_failure(struct iscsi_session *session, | |||
1335 | { | 1338 | { |
1336 | struct iscsi_conn *conn; | 1339 | struct iscsi_conn *conn; |
1337 | struct device *dev; | 1340 | struct device *dev; |
1338 | unsigned long flags; | ||
1339 | 1341 | ||
1340 | spin_lock_irqsave(&session->lock, flags); | 1342 | spin_lock_bh(&session->lock); |
1341 | conn = session->leadconn; | 1343 | conn = session->leadconn; |
1342 | if (session->state == ISCSI_STATE_TERMINATE || !conn) { | 1344 | if (session->state == ISCSI_STATE_TERMINATE || !conn) { |
1343 | spin_unlock_irqrestore(&session->lock, flags); | 1345 | spin_unlock_bh(&session->lock); |
1344 | return; | 1346 | return; |
1345 | } | 1347 | } |
1346 | 1348 | ||
1347 | dev = get_device(&conn->cls_conn->dev); | 1349 | dev = get_device(&conn->cls_conn->dev); |
1348 | spin_unlock_irqrestore(&session->lock, flags); | 1350 | spin_unlock_bh(&session->lock); |
1349 | if (!dev) | 1351 | if (!dev) |
1350 | return; | 1352 | return; |
1351 | /* | 1353 | /* |
@@ -1364,17 +1366,16 @@ EXPORT_SYMBOL_GPL(iscsi_session_failure); | |||
1364 | void iscsi_conn_failure(struct iscsi_conn *conn, enum iscsi_err err) | 1366 | void iscsi_conn_failure(struct iscsi_conn *conn, enum iscsi_err err) |
1365 | { | 1367 | { |
1366 | struct iscsi_session *session = conn->session; | 1368 | struct iscsi_session *session = conn->session; |
1367 | unsigned long flags; | ||
1368 | 1369 | ||
1369 | spin_lock_irqsave(&session->lock, flags); | 1370 | spin_lock_bh(&session->lock); |
1370 | if (session->state == ISCSI_STATE_FAILED) { | 1371 | if (session->state == ISCSI_STATE_FAILED) { |
1371 | spin_unlock_irqrestore(&session->lock, flags); | 1372 | spin_unlock_bh(&session->lock); |
1372 | return; | 1373 | return; |
1373 | } | 1374 | } |
1374 | 1375 | ||
1375 | if (conn->stop_stage == 0) | 1376 | if (conn->stop_stage == 0) |
1376 | session->state = ISCSI_STATE_FAILED; | 1377 | session->state = ISCSI_STATE_FAILED; |
1377 | spin_unlock_irqrestore(&session->lock, flags); | 1378 | spin_unlock_bh(&session->lock); |
1378 | 1379 | ||
1379 | set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx); | 1380 | set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_tx); |
1380 | set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx); | 1381 | set_bit(ISCSI_SUSPEND_BIT, &conn->suspend_rx); |
@@ -1599,27 +1600,23 @@ enum { | |||
1599 | FAILURE_SESSION_NOT_READY, | 1600 | FAILURE_SESSION_NOT_READY, |
1600 | }; | 1601 | }; |
1601 | 1602 | ||
1602 | static int iscsi_queuecommand_lck(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *)) | 1603 | int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) |
1603 | { | 1604 | { |
1604 | struct iscsi_cls_session *cls_session; | 1605 | struct iscsi_cls_session *cls_session; |
1605 | struct Scsi_Host *host; | ||
1606 | struct iscsi_host *ihost; | 1606 | struct iscsi_host *ihost; |
1607 | int reason = 0; | 1607 | int reason = 0; |
1608 | struct iscsi_session *session; | 1608 | struct iscsi_session *session; |
1609 | struct iscsi_conn *conn; | 1609 | struct iscsi_conn *conn; |
1610 | struct iscsi_task *task = NULL; | 1610 | struct iscsi_task *task = NULL; |
1611 | 1611 | ||
1612 | sc->scsi_done = done; | ||
1613 | sc->result = 0; | 1612 | sc->result = 0; |
1614 | sc->SCp.ptr = NULL; | 1613 | sc->SCp.ptr = NULL; |
1615 | 1614 | ||
1616 | host = sc->device->host; | ||
1617 | ihost = shost_priv(host); | 1615 | ihost = shost_priv(host); |
1618 | spin_unlock(host->host_lock); | ||
1619 | 1616 | ||
1620 | cls_session = starget_to_session(scsi_target(sc->device)); | 1617 | cls_session = starget_to_session(scsi_target(sc->device)); |
1621 | session = cls_session->dd_data; | 1618 | session = cls_session->dd_data; |
1622 | spin_lock(&session->lock); | 1619 | spin_lock_bh(&session->lock); |
1623 | 1620 | ||
1624 | reason = iscsi_session_chkready(cls_session); | 1621 | reason = iscsi_session_chkready(cls_session); |
1625 | if (reason) { | 1622 | if (reason) { |
@@ -1705,25 +1702,21 @@ static int iscsi_queuecommand_lck(struct scsi_cmnd *sc, void (*done)(struct scsi | |||
1705 | } | 1702 | } |
1706 | 1703 | ||
1707 | session->queued_cmdsn++; | 1704 | session->queued_cmdsn++; |
1708 | spin_unlock(&session->lock); | 1705 | spin_unlock_bh(&session->lock); |
1709 | spin_lock(host->host_lock); | ||
1710 | return 0; | 1706 | return 0; |
1711 | 1707 | ||
1712 | prepd_reject: | 1708 | prepd_reject: |
1713 | sc->scsi_done = NULL; | 1709 | iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ); |
1714 | iscsi_complete_task(task, ISCSI_TASK_COMPLETED); | ||
1715 | reject: | 1710 | reject: |
1716 | spin_unlock(&session->lock); | 1711 | spin_unlock_bh(&session->lock); |
1717 | ISCSI_DBG_SESSION(session, "cmd 0x%x rejected (%d)\n", | 1712 | ISCSI_DBG_SESSION(session, "cmd 0x%x rejected (%d)\n", |
1718 | sc->cmnd[0], reason); | 1713 | sc->cmnd[0], reason); |
1719 | spin_lock(host->host_lock); | ||
1720 | return SCSI_MLQUEUE_TARGET_BUSY; | 1714 | return SCSI_MLQUEUE_TARGET_BUSY; |
1721 | 1715 | ||
1722 | prepd_fault: | 1716 | prepd_fault: |
1723 | sc->scsi_done = NULL; | 1717 | iscsi_complete_task(task, ISCSI_TASK_REQUEUE_SCSIQ); |
1724 | iscsi_complete_task(task, ISCSI_TASK_COMPLETED); | ||
1725 | fault: | 1718 | fault: |
1726 | spin_unlock(&session->lock); | 1719 | spin_unlock_bh(&session->lock); |
1727 | ISCSI_DBG_SESSION(session, "iscsi: cmd 0x%x is not queued (%d)\n", | 1720 | ISCSI_DBG_SESSION(session, "iscsi: cmd 0x%x is not queued (%d)\n", |
1728 | sc->cmnd[0], reason); | 1721 | sc->cmnd[0], reason); |
1729 | if (!scsi_bidi_cmnd(sc)) | 1722 | if (!scsi_bidi_cmnd(sc)) |
@@ -1732,12 +1725,9 @@ fault: | |||
1732 | scsi_out(sc)->resid = scsi_out(sc)->length; | 1725 | scsi_out(sc)->resid = scsi_out(sc)->length; |
1733 | scsi_in(sc)->resid = scsi_in(sc)->length; | 1726 | scsi_in(sc)->resid = scsi_in(sc)->length; |
1734 | } | 1727 | } |
1735 | done(sc); | 1728 | sc->scsi_done(sc); |
1736 | spin_lock(host->host_lock); | ||
1737 | return 0; | 1729 | return 0; |
1738 | } | 1730 | } |
1739 | |||
1740 | DEF_SCSI_QCMD(iscsi_queuecommand) | ||
1741 | EXPORT_SYMBOL_GPL(iscsi_queuecommand); | 1731 | EXPORT_SYMBOL_GPL(iscsi_queuecommand); |
1742 | 1732 | ||
1743 | int iscsi_change_queue_depth(struct scsi_device *sdev, int depth, int reason) | 1733 | int iscsi_change_queue_depth(struct scsi_device *sdev, int depth, int reason) |
@@ -1795,9 +1785,9 @@ static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn, | |||
1795 | NULL, 0); | 1785 | NULL, 0); |
1796 | if (!task) { | 1786 | if (!task) { |
1797 | spin_unlock_bh(&session->lock); | 1787 | spin_unlock_bh(&session->lock); |
1788 | iscsi_conn_printk(KERN_ERR, conn, "Could not send TMF.\n"); | ||
1798 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); | 1789 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); |
1799 | spin_lock_bh(&session->lock); | 1790 | spin_lock_bh(&session->lock); |
1800 | ISCSI_DBG_EH(session, "tmf exec failure\n"); | ||
1801 | return -EPERM; | 1791 | return -EPERM; |
1802 | } | 1792 | } |
1803 | conn->tmfcmd_pdus_cnt++; | 1793 | conn->tmfcmd_pdus_cnt++; |
@@ -2202,7 +2192,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc) | |||
2202 | goto success_unlocked; | 2192 | goto success_unlocked; |
2203 | case TMF_TIMEDOUT: | 2193 | case TMF_TIMEDOUT: |
2204 | spin_unlock_bh(&session->lock); | 2194 | spin_unlock_bh(&session->lock); |
2205 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); | 2195 | iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST); |
2206 | goto failed_unlocked; | 2196 | goto failed_unlocked; |
2207 | case TMF_NOT_FOUND: | 2197 | case TMF_NOT_FOUND: |
2208 | if (!sc->SCp.ptr) { | 2198 | if (!sc->SCp.ptr) { |
@@ -2289,7 +2279,7 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc) | |||
2289 | break; | 2279 | break; |
2290 | case TMF_TIMEDOUT: | 2280 | case TMF_TIMEDOUT: |
2291 | spin_unlock_bh(&session->lock); | 2281 | spin_unlock_bh(&session->lock); |
2292 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); | 2282 | iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST); |
2293 | goto done; | 2283 | goto done; |
2294 | default: | 2284 | default: |
2295 | conn->tmf_state = TMF_INITIAL; | 2285 | conn->tmf_state = TMF_INITIAL; |
@@ -2370,7 +2360,7 @@ failed: | |||
2370 | * we drop the lock here but the leadconn cannot be destoyed while | 2360 | * we drop the lock here but the leadconn cannot be destoyed while |
2371 | * we are in the scsi eh | 2361 | * we are in the scsi eh |
2372 | */ | 2362 | */ |
2373 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); | 2363 | iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST); |
2374 | 2364 | ||
2375 | ISCSI_DBG_EH(session, "wait for relogin\n"); | 2365 | ISCSI_DBG_EH(session, "wait for relogin\n"); |
2376 | wait_event_interruptible(conn->ehwait, | 2366 | wait_event_interruptible(conn->ehwait, |
@@ -2452,7 +2442,7 @@ int iscsi_eh_target_reset(struct scsi_cmnd *sc) | |||
2452 | break; | 2442 | break; |
2453 | case TMF_TIMEDOUT: | 2443 | case TMF_TIMEDOUT: |
2454 | spin_unlock_bh(&session->lock); | 2444 | spin_unlock_bh(&session->lock); |
2455 | iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); | 2445 | iscsi_conn_failure(conn, ISCSI_ERR_SCSI_EH_SESSION_RST); |
2456 | goto done; | 2446 | goto done; |
2457 | default: | 2447 | default: |
2458 | conn->tmf_state = TMF_INITIAL; | 2448 | conn->tmf_state = TMF_INITIAL; |