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.c161
1 files changed, 109 insertions, 52 deletions
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 59908aead531..716cc344c5df 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -38,15 +38,30 @@
38#include <scsi/scsi_transport_iscsi.h> 38#include <scsi/scsi_transport_iscsi.h>
39#include <scsi/libiscsi.h> 39#include <scsi/libiscsi.h>
40 40
41static int iscsi_dbg_lib; 41static int iscsi_dbg_lib_conn;
42module_param_named(debug_libiscsi, iscsi_dbg_lib, int, S_IRUGO | S_IWUSR); 42module_param_named(debug_libiscsi_conn, iscsi_dbg_lib_conn, int,
43MODULE_PARM_DESC(debug_libiscsi, "Turn on debugging for libiscsi module. " 43 S_IRUGO | S_IWUSR);
44 "Set to 1 to turn on, and zero to turn off. Default " 44MODULE_PARM_DESC(debug_libiscsi_conn,
45 "is off."); 45 "Turn on debugging for connections in libiscsi module. "
46 "Set to 1 to turn on, and zero to turn off. Default is off.");
47
48static int iscsi_dbg_lib_session;
49module_param_named(debug_libiscsi_session, iscsi_dbg_lib_session, int,
50 S_IRUGO | S_IWUSR);
51MODULE_PARM_DESC(debug_libiscsi_session,
52 "Turn on debugging for sessions in libiscsi module. "
53 "Set to 1 to turn on, and zero to turn off. Default is off.");
54
55static int iscsi_dbg_lib_eh;
56module_param_named(debug_libiscsi_eh, iscsi_dbg_lib_eh, int,
57 S_IRUGO | S_IWUSR);
58MODULE_PARM_DESC(debug_libiscsi_eh,
59 "Turn on debugging for error handling in libiscsi module. "
60 "Set to 1 to turn on, and zero to turn off. Default is off.");
46 61
47#define ISCSI_DBG_CONN(_conn, dbg_fmt, arg...) \ 62#define ISCSI_DBG_CONN(_conn, dbg_fmt, arg...) \
48 do { \ 63 do { \
49 if (iscsi_dbg_lib) \ 64 if (iscsi_dbg_lib_conn) \
50 iscsi_conn_printk(KERN_INFO, _conn, \ 65 iscsi_conn_printk(KERN_INFO, _conn, \
51 "%s " dbg_fmt, \ 66 "%s " dbg_fmt, \
52 __func__, ##arg); \ 67 __func__, ##arg); \
@@ -54,7 +69,15 @@ MODULE_PARM_DESC(debug_libiscsi, "Turn on debugging for libiscsi module. "
54 69
55#define ISCSI_DBG_SESSION(_session, dbg_fmt, arg...) \ 70#define ISCSI_DBG_SESSION(_session, dbg_fmt, arg...) \
56 do { \ 71 do { \
57 if (iscsi_dbg_lib) \ 72 if (iscsi_dbg_lib_session) \
73 iscsi_session_printk(KERN_INFO, _session, \
74 "%s " dbg_fmt, \
75 __func__, ##arg); \
76 } while (0);
77
78#define ISCSI_DBG_EH(_session, dbg_fmt, arg...) \
79 do { \
80 if (iscsi_dbg_lib_eh) \
58 iscsi_session_printk(KERN_INFO, _session, \ 81 iscsi_session_printk(KERN_INFO, _session, \
59 "%s " dbg_fmt, \ 82 "%s " dbg_fmt, \
60 __func__, ##arg); \ 83 __func__, ##arg); \
@@ -954,6 +977,7 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct iscsi_hdr *hdr,
954 task = iscsi_itt_to_ctask(conn, hdr->itt); 977 task = iscsi_itt_to_ctask(conn, hdr->itt);
955 if (!task) 978 if (!task)
956 return ISCSI_ERR_BAD_ITT; 979 return ISCSI_ERR_BAD_ITT;
980 task->last_xfer = jiffies;
957 break; 981 break;
958 case ISCSI_OP_R2T: 982 case ISCSI_OP_R2T:
959 /* 983 /*
@@ -1192,10 +1216,12 @@ static int iscsi_xmit_task(struct iscsi_conn *conn)
1192 spin_unlock_bh(&conn->session->lock); 1216 spin_unlock_bh(&conn->session->lock);
1193 rc = conn->session->tt->xmit_task(task); 1217 rc = conn->session->tt->xmit_task(task);
1194 spin_lock_bh(&conn->session->lock); 1218 spin_lock_bh(&conn->session->lock);
1195 __iscsi_put_task(task); 1219 if (!rc) {
1196 if (!rc)
1197 /* done with this task */ 1220 /* done with this task */
1221 task->last_xfer = jiffies;
1198 conn->task = NULL; 1222 conn->task = NULL;
1223 }
1224 __iscsi_put_task(task);
1199 return rc; 1225 return rc;
1200} 1226}
1201 1227
@@ -1361,6 +1387,9 @@ static inline struct iscsi_task *iscsi_alloc_task(struct iscsi_conn *conn,
1361 task->state = ISCSI_TASK_PENDING; 1387 task->state = ISCSI_TASK_PENDING;
1362 task->conn = conn; 1388 task->conn = conn;
1363 task->sc = sc; 1389 task->sc = sc;
1390 task->have_checked_conn = false;
1391 task->last_timeout = jiffies;
1392 task->last_xfer = jiffies;
1364 INIT_LIST_HEAD(&task->running); 1393 INIT_LIST_HEAD(&task->running);
1365 return task; 1394 return task;
1366} 1395}
@@ -1555,10 +1584,10 @@ int iscsi_eh_target_reset(struct scsi_cmnd *sc)
1555 spin_lock_bh(&session->lock); 1584 spin_lock_bh(&session->lock);
1556 if (session->state == ISCSI_STATE_TERMINATE) { 1585 if (session->state == ISCSI_STATE_TERMINATE) {
1557failed: 1586failed:
1558 iscsi_session_printk(KERN_INFO, session, 1587 ISCSI_DBG_EH(session,
1559 "failing target reset: Could not log " 1588 "failing target reset: Could not log back into "
1560 "back into target [age %d]\n", 1589 "target [age %d]\n",
1561 session->age); 1590 session->age);
1562 spin_unlock_bh(&session->lock); 1591 spin_unlock_bh(&session->lock);
1563 mutex_unlock(&session->eh_mutex); 1592 mutex_unlock(&session->eh_mutex);
1564 return FAILED; 1593 return FAILED;
@@ -1572,7 +1601,7 @@ failed:
1572 */ 1601 */
1573 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); 1602 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1574 1603
1575 ISCSI_DBG_SESSION(session, "wait for relogin\n"); 1604 ISCSI_DBG_EH(session, "wait for relogin\n");
1576 wait_event_interruptible(conn->ehwait, 1605 wait_event_interruptible(conn->ehwait,
1577 session->state == ISCSI_STATE_TERMINATE || 1606 session->state == ISCSI_STATE_TERMINATE ||
1578 session->state == ISCSI_STATE_LOGGED_IN || 1607 session->state == ISCSI_STATE_LOGGED_IN ||
@@ -1582,10 +1611,10 @@ failed:
1582 1611
1583 mutex_lock(&session->eh_mutex); 1612 mutex_lock(&session->eh_mutex);
1584 spin_lock_bh(&session->lock); 1613 spin_lock_bh(&session->lock);
1585 if (session->state == ISCSI_STATE_LOGGED_IN) 1614 if (session->state == ISCSI_STATE_LOGGED_IN) {
1586 iscsi_session_printk(KERN_INFO, session, 1615 ISCSI_DBG_EH(session,
1587 "target reset succeeded\n"); 1616 "target reset succeeded\n");
1588 else 1617 } else
1589 goto failed; 1618 goto failed;
1590 spin_unlock_bh(&session->lock); 1619 spin_unlock_bh(&session->lock);
1591 mutex_unlock(&session->eh_mutex); 1620 mutex_unlock(&session->eh_mutex);
@@ -1601,7 +1630,7 @@ static void iscsi_tmf_timedout(unsigned long data)
1601 spin_lock(&session->lock); 1630 spin_lock(&session->lock);
1602 if (conn->tmf_state == TMF_QUEUED) { 1631 if (conn->tmf_state == TMF_QUEUED) {
1603 conn->tmf_state = TMF_TIMEDOUT; 1632 conn->tmf_state = TMF_TIMEDOUT;
1604 ISCSI_DBG_SESSION(session, "tmf timedout\n"); 1633 ISCSI_DBG_EH(session, "tmf timedout\n");
1605 /* unblock eh_abort() */ 1634 /* unblock eh_abort() */
1606 wake_up(&conn->ehwait); 1635 wake_up(&conn->ehwait);
1607 } 1636 }
@@ -1621,7 +1650,7 @@ static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn,
1621 spin_unlock_bh(&session->lock); 1650 spin_unlock_bh(&session->lock);
1622 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED); 1651 iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
1623 spin_lock_bh(&session->lock); 1652 spin_lock_bh(&session->lock);
1624 ISCSI_DBG_SESSION(session, "tmf exec failure\n"); 1653 ISCSI_DBG_EH(session, "tmf exec failure\n");
1625 return -EPERM; 1654 return -EPERM;
1626 } 1655 }
1627 conn->tmfcmd_pdus_cnt++; 1656 conn->tmfcmd_pdus_cnt++;
@@ -1629,7 +1658,7 @@ static int iscsi_exec_task_mgmt_fn(struct iscsi_conn *conn,
1629 conn->tmf_timer.function = iscsi_tmf_timedout; 1658 conn->tmf_timer.function = iscsi_tmf_timedout;
1630 conn->tmf_timer.data = (unsigned long)conn; 1659 conn->tmf_timer.data = (unsigned long)conn;
1631 add_timer(&conn->tmf_timer); 1660 add_timer(&conn->tmf_timer);
1632 ISCSI_DBG_SESSION(session, "tmf set timeout\n"); 1661 ISCSI_DBG_EH(session, "tmf set timeout\n");
1633 1662
1634 spin_unlock_bh(&session->lock); 1663 spin_unlock_bh(&session->lock);
1635 mutex_unlock(&session->eh_mutex); 1664 mutex_unlock(&session->eh_mutex);
@@ -1716,17 +1745,18 @@ static int iscsi_has_ping_timed_out(struct iscsi_conn *conn)
1716 return 0; 1745 return 0;
1717} 1746}
1718 1747
1719static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd) 1748static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
1720{ 1749{
1750 enum blk_eh_timer_return rc = BLK_EH_NOT_HANDLED;
1751 struct iscsi_task *task = NULL;
1721 struct iscsi_cls_session *cls_session; 1752 struct iscsi_cls_session *cls_session;
1722 struct iscsi_session *session; 1753 struct iscsi_session *session;
1723 struct iscsi_conn *conn; 1754 struct iscsi_conn *conn;
1724 enum blk_eh_timer_return rc = BLK_EH_NOT_HANDLED;
1725 1755
1726 cls_session = starget_to_session(scsi_target(scmd->device)); 1756 cls_session = starget_to_session(scsi_target(sc->device));
1727 session = cls_session->dd_data; 1757 session = cls_session->dd_data;
1728 1758
1729 ISCSI_DBG_SESSION(session, "scsi cmd %p timedout\n", scmd); 1759 ISCSI_DBG_EH(session, "scsi cmd %p timedout\n", sc);
1730 1760
1731 spin_lock(&session->lock); 1761 spin_lock(&session->lock);
1732 if (session->state != ISCSI_STATE_LOGGED_IN) { 1762 if (session->state != ISCSI_STATE_LOGGED_IN) {
@@ -1745,6 +1775,26 @@ static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd)
1745 goto done; 1775 goto done;
1746 } 1776 }
1747 1777
1778 task = (struct iscsi_task *)sc->SCp.ptr;
1779 if (!task)
1780 goto done;
1781 /*
1782 * If we have sent (at least queued to the network layer) a pdu or
1783 * recvd one for the task since the last timeout ask for
1784 * more time. If on the next timeout we have not made progress
1785 * we can check if it is the task or connection when we send the
1786 * nop as a ping.
1787 */
1788 if (time_after_eq(task->last_xfer, task->last_timeout)) {
1789 ISCSI_DBG_EH(session, "Command making progress. Asking "
1790 "scsi-ml for more time to complete. "
1791 "Last data recv at %lu. Last timeout was at "
1792 "%lu\n.", task->last_xfer, task->last_timeout);
1793 task->have_checked_conn = false;
1794 rc = BLK_EH_RESET_TIMER;
1795 goto done;
1796 }
1797
1748 if (!conn->recv_timeout && !conn->ping_timeout) 1798 if (!conn->recv_timeout && !conn->ping_timeout)
1749 goto done; 1799 goto done;
1750 /* 1800 /*
@@ -1755,23 +1805,32 @@ static enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd)
1755 rc = BLK_EH_RESET_TIMER; 1805 rc = BLK_EH_RESET_TIMER;
1756 goto done; 1806 goto done;
1757 } 1807 }
1808
1809 /* Assumes nop timeout is shorter than scsi cmd timeout */
1810 if (task->have_checked_conn)
1811 goto done;
1812
1758 /* 1813 /*
1759 * if we are about to check the transport then give the command 1814 * Checking the transport already or nop from a cmd timeout still
1760 * more time 1815 * running
1761 */ 1816 */
1762 if (time_before_eq(conn->last_recv + (conn->recv_timeout * HZ), 1817 if (conn->ping_task) {
1763 jiffies)) { 1818 task->have_checked_conn = true;
1764 rc = BLK_EH_RESET_TIMER; 1819 rc = BLK_EH_RESET_TIMER;
1765 goto done; 1820 goto done;
1766 } 1821 }
1767 1822
1768 /* if in the middle of checking the transport then give us more time */ 1823 /* Make sure there is a transport check done */
1769 if (conn->ping_task) 1824 iscsi_send_nopout(conn, NULL);
1770 rc = BLK_EH_RESET_TIMER; 1825 task->have_checked_conn = true;
1826 rc = BLK_EH_RESET_TIMER;
1827
1771done: 1828done:
1829 if (task)
1830 task->last_timeout = jiffies;
1772 spin_unlock(&session->lock); 1831 spin_unlock(&session->lock);
1773 ISCSI_DBG_SESSION(session, "return %s\n", rc == BLK_EH_RESET_TIMER ? 1832 ISCSI_DBG_EH(session, "return %s\n", rc == BLK_EH_RESET_TIMER ?
1774 "timer reset" : "nh"); 1833 "timer reset" : "nh");
1775 return rc; 1834 return rc;
1776} 1835}
1777 1836
@@ -1841,7 +1900,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1841 cls_session = starget_to_session(scsi_target(sc->device)); 1900 cls_session = starget_to_session(scsi_target(sc->device));
1842 session = cls_session->dd_data; 1901 session = cls_session->dd_data;
1843 1902
1844 ISCSI_DBG_SESSION(session, "aborting sc %p\n", sc); 1903 ISCSI_DBG_EH(session, "aborting sc %p\n", sc);
1845 1904
1846 mutex_lock(&session->eh_mutex); 1905 mutex_lock(&session->eh_mutex);
1847 spin_lock_bh(&session->lock); 1906 spin_lock_bh(&session->lock);
@@ -1850,8 +1909,8 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1850 * got the command. 1909 * got the command.
1851 */ 1910 */
1852 if (!sc->SCp.ptr) { 1911 if (!sc->SCp.ptr) {
1853 ISCSI_DBG_SESSION(session, "sc never reached iscsi layer or " 1912 ISCSI_DBG_EH(session, "sc never reached iscsi layer or "
1854 "it completed.\n"); 1913 "it completed.\n");
1855 spin_unlock_bh(&session->lock); 1914 spin_unlock_bh(&session->lock);
1856 mutex_unlock(&session->eh_mutex); 1915 mutex_unlock(&session->eh_mutex);
1857 return SUCCESS; 1916 return SUCCESS;
@@ -1865,7 +1924,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1865 sc->SCp.phase != session->age) { 1924 sc->SCp.phase != session->age) {
1866 spin_unlock_bh(&session->lock); 1925 spin_unlock_bh(&session->lock);
1867 mutex_unlock(&session->eh_mutex); 1926 mutex_unlock(&session->eh_mutex);
1868 ISCSI_DBG_SESSION(session, "failing abort due to dropped " 1927 ISCSI_DBG_EH(session, "failing abort due to dropped "
1869 "session.\n"); 1928 "session.\n");
1870 return FAILED; 1929 return FAILED;
1871 } 1930 }
@@ -1875,13 +1934,12 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1875 age = session->age; 1934 age = session->age;
1876 1935
1877 task = (struct iscsi_task *)sc->SCp.ptr; 1936 task = (struct iscsi_task *)sc->SCp.ptr;
1878 ISCSI_DBG_SESSION(session, "aborting [sc %p itt 0x%x]\n", 1937 ISCSI_DBG_EH(session, "aborting [sc %p itt 0x%x]\n",
1879 sc, task->itt); 1938 sc, task->itt);
1880 1939
1881 /* task completed before time out */ 1940 /* task completed before time out */
1882 if (!task->sc) { 1941 if (!task->sc) {
1883 ISCSI_DBG_SESSION(session, "sc completed while abort in " 1942 ISCSI_DBG_EH(session, "sc completed while abort in progress\n");
1884 "progress\n");
1885 goto success; 1943 goto success;
1886 } 1944 }
1887 1945
@@ -1930,8 +1988,8 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1930 if (!sc->SCp.ptr) { 1988 if (!sc->SCp.ptr) {
1931 conn->tmf_state = TMF_INITIAL; 1989 conn->tmf_state = TMF_INITIAL;
1932 /* task completed before tmf abort response */ 1990 /* task completed before tmf abort response */
1933 ISCSI_DBG_SESSION(session, "sc completed while abort " 1991 ISCSI_DBG_EH(session, "sc completed while abort in "
1934 "in progress\n"); 1992 "progress\n");
1935 goto success; 1993 goto success;
1936 } 1994 }
1937 /* fall through */ 1995 /* fall through */
@@ -1943,16 +2001,16 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
1943success: 2001success:
1944 spin_unlock_bh(&session->lock); 2002 spin_unlock_bh(&session->lock);
1945success_unlocked: 2003success_unlocked:
1946 ISCSI_DBG_SESSION(session, "abort success [sc %p itt 0x%x]\n", 2004 ISCSI_DBG_EH(session, "abort success [sc %p itt 0x%x]\n",
1947 sc, task->itt); 2005 sc, task->itt);
1948 mutex_unlock(&session->eh_mutex); 2006 mutex_unlock(&session->eh_mutex);
1949 return SUCCESS; 2007 return SUCCESS;
1950 2008
1951failed: 2009failed:
1952 spin_unlock_bh(&session->lock); 2010 spin_unlock_bh(&session->lock);
1953failed_unlocked: 2011failed_unlocked:
1954 ISCSI_DBG_SESSION(session, "abort failed [sc %p itt 0x%x]\n", sc, 2012 ISCSI_DBG_EH(session, "abort failed [sc %p itt 0x%x]\n", sc,
1955 task ? task->itt : 0); 2013 task ? task->itt : 0);
1956 mutex_unlock(&session->eh_mutex); 2014 mutex_unlock(&session->eh_mutex);
1957 return FAILED; 2015 return FAILED;
1958} 2016}
@@ -1979,8 +2037,7 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc)
1979 cls_session = starget_to_session(scsi_target(sc->device)); 2037 cls_session = starget_to_session(scsi_target(sc->device));
1980 session = cls_session->dd_data; 2038 session = cls_session->dd_data;
1981 2039
1982 ISCSI_DBG_SESSION(session, "LU Reset [sc %p lun %u]\n", 2040 ISCSI_DBG_EH(session, "LU Reset [sc %p lun %u]\n", sc, sc->device->lun);
1983 sc, sc->device->lun);
1984 2041
1985 mutex_lock(&session->eh_mutex); 2042 mutex_lock(&session->eh_mutex);
1986 spin_lock_bh(&session->lock); 2043 spin_lock_bh(&session->lock);
@@ -2034,8 +2091,8 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc)
2034unlock: 2091unlock:
2035 spin_unlock_bh(&session->lock); 2092 spin_unlock_bh(&session->lock);
2036done: 2093done:
2037 ISCSI_DBG_SESSION(session, "dev reset result = %s\n", 2094 ISCSI_DBG_EH(session, "dev reset result = %s\n",
2038 rc == SUCCESS ? "SUCCESS" : "FAILED"); 2095 rc == SUCCESS ? "SUCCESS" : "FAILED");
2039 mutex_unlock(&session->eh_mutex); 2096 mutex_unlock(&session->eh_mutex);
2040 return rc; 2097 return rc;
2041} 2098}