aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi
diff options
context:
space:
mode:
authorMike Christie <michaelc@cs.wisc.edu>2008-05-21 16:53:59 -0400
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2008-07-12 09:22:16 -0400
commit756135215ec743be6fdce2bdebe8cdb9f8a231f6 (patch)
tree7eb0a5a23731fcd974f9e5e5d136fe6944d4761c /drivers/scsi
parent32c6e1b9a2e27076b7070a9ec56a9e5437ebd725 (diff)
[SCSI] iscsi: remove session and host binding in libiscsi
bnx2i allocates a host per netdevice but will use libiscsi, so this unbinds the session from the host in that code. This will also be useful for the iser parent device dma settings fixes. Signed-off-by: Mike Christie <michaelc@cs.wisc.edu> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers/scsi')
-rw-r--r--drivers/scsi/iscsi_tcp.c102
-rw-r--r--drivers/scsi/libiscsi.c213
-rw-r--r--drivers/scsi/qla4xxx/ql4_os.c1
-rw-r--r--drivers/scsi/scsi_transport_iscsi.c5
4 files changed, 152 insertions, 169 deletions
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index aecadbdce9df..8cdcaf33fb4e 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -64,6 +64,10 @@ MODULE_LICENSE("GPL");
64#define BUG_ON(expr) 64#define BUG_ON(expr)
65#endif 65#endif
66 66
67static struct scsi_transport_template *iscsi_tcp_scsi_transport;
68static struct scsi_host_template iscsi_sht;
69static struct iscsi_transport iscsi_tcp_transport;
70
67static unsigned int iscsi_max_lun = 512; 71static unsigned int iscsi_max_lun = 512;
68module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO); 72module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
69 73
@@ -1623,6 +1627,8 @@ iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session,
1623 struct iscsi_cls_conn *cls_conn, uint64_t transport_eph, 1627 struct iscsi_cls_conn *cls_conn, uint64_t transport_eph,
1624 int is_leading) 1628 int is_leading)
1625{ 1629{
1630 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1631 struct iscsi_host *ihost = shost_priv(shost);
1626 struct iscsi_conn *conn = cls_conn->dd_data; 1632 struct iscsi_conn *conn = cls_conn->dd_data;
1627 struct iscsi_tcp_conn *tcp_conn = conn->dd_data; 1633 struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
1628 struct sock *sk; 1634 struct sock *sk;
@@ -1646,8 +1652,8 @@ iscsi_tcp_conn_bind(struct iscsi_cls_session *cls_session,
1646 if (err) 1652 if (err)
1647 goto free_socket; 1653 goto free_socket;
1648 1654
1649 err = iscsi_tcp_get_addr(conn, sock, conn->local_address, 1655 err = iscsi_tcp_get_addr(conn, sock, ihost->local_address,
1650 &conn->local_port, kernel_getsockname); 1656 &ihost->local_port, kernel_getsockname);
1651 if (err) 1657 if (err)
1652 goto free_socket; 1658 goto free_socket;
1653 1659
@@ -1821,29 +1827,6 @@ iscsi_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,
1821 return len; 1827 return len;
1822} 1828}
1823 1829
1824static int
1825iscsi_tcp_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param,
1826 char *buf)
1827{
1828 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
1829 int len;
1830
1831 switch (param) {
1832 case ISCSI_HOST_PARAM_IPADDRESS:
1833 spin_lock_bh(&session->lock);
1834 if (!session->leadconn)
1835 len = -ENODEV;
1836 else
1837 len = sprintf(buf, "%s\n",
1838 session->leadconn->local_address);
1839 spin_unlock_bh(&session->lock);
1840 break;
1841 default:
1842 return iscsi_host_get_param(shost, param, buf);
1843 }
1844 return len;
1845}
1846
1847static void 1830static void
1848iscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats) 1831iscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
1849{ 1832{
@@ -1869,26 +1852,44 @@ iscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn, struct iscsi_stats *stats)
1869} 1852}
1870 1853
1871static struct iscsi_cls_session * 1854static struct iscsi_cls_session *
1872iscsi_tcp_session_create(struct iscsi_transport *iscsit, 1855iscsi_tcp_session_create(struct Scsi_Host *shost, uint16_t cmds_max,
1873 struct scsi_transport_template *scsit,
1874 struct Scsi_Host *shost, uint16_t cmds_max,
1875 uint16_t qdepth, uint32_t initial_cmdsn, 1856 uint16_t qdepth, uint32_t initial_cmdsn,
1876 uint32_t *hostno) 1857 uint32_t *hostno)
1877{ 1858{
1878 struct iscsi_cls_session *cls_session; 1859 struct iscsi_cls_session *cls_session;
1879 struct iscsi_session *session; 1860 struct iscsi_session *session;
1880 uint32_t hn;
1881 int cmd_i; 1861 int cmd_i;
1882 1862
1883 cls_session = iscsi_session_setup(iscsit, scsit, cmds_max, qdepth, 1863 if (shost) {
1884 sizeof(struct iscsi_tcp_cmd_task), 1864 printk(KERN_ERR "iscsi_tcp: invalid shost %d.\n",
1885 sizeof(struct iscsi_tcp_mgmt_task), 1865 shost->host_no);
1886 initial_cmdsn, &hn); 1866 return NULL;
1887 if (!cls_session) 1867 }
1868
1869 shost = scsi_host_alloc(&iscsi_sht, sizeof(struct iscsi_host));
1870 if (!shost)
1888 return NULL; 1871 return NULL;
1889 *hostno = hn; 1872 shost->transportt = iscsi_tcp_scsi_transport;
1873 shost->max_lun = iscsi_max_lun;
1874 shost->max_id = 0;
1875 shost->max_channel = 0;
1876 shost->max_cmd_len = 16;
1877
1878 iscsi_host_setup(shost, qdepth);
1879
1880 if (scsi_add_host(shost, NULL))
1881 goto free_host;
1882 *hostno = shost->host_no;
1883
1884 cls_session = iscsi_session_setup(&iscsi_tcp_transport, shost, cmds_max,
1885 sizeof(struct iscsi_tcp_cmd_task),
1886 sizeof(struct iscsi_tcp_mgmt_task),
1887 initial_cmdsn);
1888 if (!cls_session)
1889 goto remove_host;
1890 session = cls_session->dd_data;
1890 1891
1891 session = class_to_transport_session(cls_session); 1892 shost->can_queue = session->cmds_max;
1892 for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) { 1893 for (cmd_i = 0; cmd_i < session->cmds_max; cmd_i++) {
1893 struct iscsi_cmd_task *ctask = session->cmds[cmd_i]; 1894 struct iscsi_cmd_task *ctask = session->cmds[cmd_i];
1894 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data; 1895 struct iscsi_tcp_cmd_task *tcp_ctask = ctask->dd_data;
@@ -1904,20 +1905,30 @@ iscsi_tcp_session_create(struct iscsi_transport *iscsit,
1904 mtask->hdr = (struct iscsi_hdr *) &tcp_mtask->hdr; 1905 mtask->hdr = (struct iscsi_hdr *) &tcp_mtask->hdr;
1905 } 1906 }
1906 1907
1907 if (iscsi_r2tpool_alloc(class_to_transport_session(cls_session))) 1908 if (iscsi_r2tpool_alloc(session))
1908 goto r2tpool_alloc_fail; 1909 goto remove_session;
1909
1910 return cls_session; 1910 return cls_session;
1911 1911
1912r2tpool_alloc_fail: 1912remove_session:
1913 iscsi_session_teardown(cls_session); 1913 iscsi_session_teardown(cls_session);
1914remove_host:
1915 scsi_remove_host(shost);
1916free_host:
1917 iscsi_host_teardown(shost);
1918 scsi_host_put(shost);
1914 return NULL; 1919 return NULL;
1915} 1920}
1916 1921
1917static void iscsi_tcp_session_destroy(struct iscsi_cls_session *cls_session) 1922static void iscsi_tcp_session_destroy(struct iscsi_cls_session *cls_session)
1918{ 1923{
1919 iscsi_r2tpool_free(class_to_transport_session(cls_session)); 1924 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1925
1926 iscsi_r2tpool_free(cls_session->dd_data);
1920 iscsi_session_teardown(cls_session); 1927 iscsi_session_teardown(cls_session);
1928
1929 scsi_remove_host(shost);
1930 iscsi_host_teardown(shost);
1931 scsi_host_put(shost);
1921} 1932}
1922 1933
1923static int iscsi_tcp_slave_configure(struct scsi_device *sdev) 1934static int iscsi_tcp_slave_configure(struct scsi_device *sdev)
@@ -1976,8 +1987,8 @@ static struct iscsi_transport iscsi_tcp_transport = {
1976 .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS | 1987 .host_param_mask = ISCSI_HOST_HWADDRESS | ISCSI_HOST_IPADDRESS |
1977 ISCSI_HOST_INITIATOR_NAME | 1988 ISCSI_HOST_INITIATOR_NAME |
1978 ISCSI_HOST_NETDEV_NAME, 1989 ISCSI_HOST_NETDEV_NAME,
1979 .host_template = &iscsi_sht,
1980 .conndata_size = sizeof(struct iscsi_conn), 1990 .conndata_size = sizeof(struct iscsi_conn),
1991 .sessiondata_size = sizeof(struct iscsi_session),
1981 /* session management */ 1992 /* session management */
1982 .create_session = iscsi_tcp_session_create, 1993 .create_session = iscsi_tcp_session_create,
1983 .destroy_session = iscsi_tcp_session_destroy, 1994 .destroy_session = iscsi_tcp_session_destroy,
@@ -1991,7 +2002,7 @@ static struct iscsi_transport iscsi_tcp_transport = {
1991 .start_conn = iscsi_conn_start, 2002 .start_conn = iscsi_conn_start,
1992 .stop_conn = iscsi_tcp_conn_stop, 2003 .stop_conn = iscsi_tcp_conn_stop,
1993 /* iscsi host params */ 2004 /* iscsi host params */
1994 .get_host_param = iscsi_tcp_host_get_param, 2005 .get_host_param = iscsi_host_get_param,
1995 .set_host_param = iscsi_host_set_param, 2006 .set_host_param = iscsi_host_set_param,
1996 /* IO */ 2007 /* IO */
1997 .send_pdu = iscsi_conn_send_pdu, 2008 .send_pdu = iscsi_conn_send_pdu,
@@ -2013,9 +2024,10 @@ iscsi_tcp_init(void)
2013 iscsi_max_lun); 2024 iscsi_max_lun);
2014 return -EINVAL; 2025 return -EINVAL;
2015 } 2026 }
2016 iscsi_tcp_transport.max_lun = iscsi_max_lun;
2017 2027
2018 if (!iscsi_register_transport(&iscsi_tcp_transport)) 2028 iscsi_tcp_scsi_transport = iscsi_register_transport(
2029 &iscsi_tcp_transport);
2030 if (!iscsi_tcp_scsi_transport)
2019 return -ENODEV; 2031 return -ENODEV;
2020 2032
2021 return 0; 2033 return 0;
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 01a1a4d36f21..64b1dd827366 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -38,14 +38,6 @@
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
41struct iscsi_session *
42class_to_transport_session(struct iscsi_cls_session *cls_session)
43{
44 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
45 return iscsi_hostdata(shost->hostdata);
46}
47EXPORT_SYMBOL_GPL(class_to_transport_session);
48
49/* Serial Number Arithmetic, 32 bits, less than, RFC1982 */ 41/* Serial Number Arithmetic, 32 bits, less than, RFC1982 */
50#define SNA32_CHECK 2147483648UL 42#define SNA32_CHECK 2147483648UL
51 43
@@ -1096,6 +1088,7 @@ enum {
1096 1088
1097int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *)) 1089int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
1098{ 1090{
1091 struct iscsi_cls_session *cls_session;
1099 struct Scsi_Host *host; 1092 struct Scsi_Host *host;
1100 int reason = 0; 1093 int reason = 0;
1101 struct iscsi_session *session; 1094 struct iscsi_session *session;
@@ -1109,10 +1102,11 @@ int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
1109 host = sc->device->host; 1102 host = sc->device->host;
1110 spin_unlock(host->host_lock); 1103 spin_unlock(host->host_lock);
1111 1104
1112 session = iscsi_hostdata(host->hostdata); 1105 cls_session = starget_to_session(scsi_target(sc->device));
1106 session = cls_session->dd_data;
1113 spin_lock(&session->lock); 1107 spin_lock(&session->lock);
1114 1108
1115 reason = iscsi_session_chkready(session_to_cls(session)); 1109 reason = iscsi_session_chkready(cls_session);
1116 if (reason) { 1110 if (reason) {
1117 sc->result = reason; 1111 sc->result = reason;
1118 goto fault; 1112 goto fault;
@@ -1222,7 +1216,7 @@ EXPORT_SYMBOL_GPL(iscsi_change_queue_depth);
1222 1216
1223void iscsi_session_recovery_timedout(struct iscsi_cls_session *cls_session) 1217void iscsi_session_recovery_timedout(struct iscsi_cls_session *cls_session)
1224{ 1218{
1225 struct iscsi_session *session = class_to_transport_session(cls_session); 1219 struct iscsi_session *session = cls_session->dd_data;
1226 1220
1227 spin_lock_bh(&session->lock); 1221 spin_lock_bh(&session->lock);
1228 if (session->state != ISCSI_STATE_LOGGED_IN) { 1222 if (session->state != ISCSI_STATE_LOGGED_IN) {
@@ -1236,9 +1230,13 @@ EXPORT_SYMBOL_GPL(iscsi_session_recovery_timedout);
1236 1230
1237int iscsi_eh_host_reset(struct scsi_cmnd *sc) 1231int iscsi_eh_host_reset(struct scsi_cmnd *sc)
1238{ 1232{
1239 struct Scsi_Host *host = sc->device->host; 1233 struct iscsi_cls_session *cls_session;
1240 struct iscsi_session *session = iscsi_hostdata(host->hostdata); 1234 struct iscsi_session *session;
1241 struct iscsi_conn *conn = session->leadconn; 1235 struct iscsi_conn *conn;
1236
1237 cls_session = starget_to_session(scsi_target(sc->device));
1238 session = cls_session->dd_data;
1239 conn = session->leadconn;
1242 1240
1243 mutex_lock(&session->eh_mutex); 1241 mutex_lock(&session->eh_mutex);
1244 spin_lock_bh(&session->lock); 1242 spin_lock_bh(&session->lock);
@@ -1405,7 +1403,7 @@ static enum scsi_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd)
1405 enum scsi_eh_timer_return rc = EH_NOT_HANDLED; 1403 enum scsi_eh_timer_return rc = EH_NOT_HANDLED;
1406 1404
1407 cls_session = starget_to_session(scsi_target(scmd->device)); 1405 cls_session = starget_to_session(scsi_target(scmd->device));
1408 session = class_to_transport_session(cls_session); 1406 session = cls_session->dd_data;
1409 1407
1410 debug_scsi("scsi cmd %p timedout\n", scmd); 1408 debug_scsi("scsi cmd %p timedout\n", scmd);
1411 1409
@@ -1507,13 +1505,16 @@ static void iscsi_prep_abort_task_pdu(struct iscsi_cmd_task *ctask,
1507 1505
1508int iscsi_eh_abort(struct scsi_cmnd *sc) 1506int iscsi_eh_abort(struct scsi_cmnd *sc)
1509{ 1507{
1510 struct Scsi_Host *host = sc->device->host; 1508 struct iscsi_cls_session *cls_session;
1511 struct iscsi_session *session = iscsi_hostdata(host->hostdata); 1509 struct iscsi_session *session;
1512 struct iscsi_conn *conn; 1510 struct iscsi_conn *conn;
1513 struct iscsi_cmd_task *ctask; 1511 struct iscsi_cmd_task *ctask;
1514 struct iscsi_tm *hdr; 1512 struct iscsi_tm *hdr;
1515 int rc, age; 1513 int rc, age;
1516 1514
1515 cls_session = starget_to_session(scsi_target(sc->device));
1516 session = cls_session->dd_data;
1517
1517 mutex_lock(&session->eh_mutex); 1518 mutex_lock(&session->eh_mutex);
1518 spin_lock_bh(&session->lock); 1519 spin_lock_bh(&session->lock);
1519 /* 1520 /*
@@ -1630,12 +1631,15 @@ static void iscsi_prep_lun_reset_pdu(struct scsi_cmnd *sc, struct iscsi_tm *hdr)
1630 1631
1631int iscsi_eh_device_reset(struct scsi_cmnd *sc) 1632int iscsi_eh_device_reset(struct scsi_cmnd *sc)
1632{ 1633{
1633 struct Scsi_Host *host = sc->device->host; 1634 struct iscsi_cls_session *cls_session;
1634 struct iscsi_session *session = iscsi_hostdata(host->hostdata); 1635 struct iscsi_session *session;
1635 struct iscsi_conn *conn; 1636 struct iscsi_conn *conn;
1636 struct iscsi_tm *hdr; 1637 struct iscsi_tm *hdr;
1637 int rc = FAILED; 1638 int rc = FAILED;
1638 1639
1640 cls_session = starget_to_session(scsi_target(sc->device));
1641 session = cls_session->dd_data;
1642
1639 debug_scsi("LU Reset [sc %p lun %u]\n", sc, sc->device->lun); 1643 debug_scsi("LU Reset [sc %p lun %u]\n", sc, sc->device->lun);
1640 1644
1641 mutex_lock(&session->eh_mutex); 1645 mutex_lock(&session->eh_mutex);
@@ -1760,55 +1764,53 @@ void iscsi_pool_free(struct iscsi_pool *q)
1760} 1764}
1761EXPORT_SYMBOL_GPL(iscsi_pool_free); 1765EXPORT_SYMBOL_GPL(iscsi_pool_free);
1762 1766
1763/* 1767void iscsi_host_setup(struct Scsi_Host *shost, uint16_t qdepth)
1764 * iSCSI Session's hostdata organization: 1768{
1765 * 1769 if (qdepth > ISCSI_MAX_CMD_PER_LUN || qdepth < 1) {
1766 * *------------------* <== hostdata_session(host->hostdata) 1770 if (qdepth != 0)
1767 * | ptr to class sess| 1771 printk(KERN_ERR "iscsi: invalid queue depth of %d. "
1768 * |------------------| <== iscsi_hostdata(host->hostdata) 1772 "Queue depth must be between 1 and %d.\n",
1769 * | iscsi_session | 1773 qdepth, ISCSI_MAX_CMD_PER_LUN);
1770 * *------------------* 1774 qdepth = ISCSI_DEF_CMD_PER_LUN;
1771 */ 1775 }
1776
1777 shost->transportt->create_work_queue = 1;
1778 shost->transportt->eh_timed_out = iscsi_eh_cmd_timed_out;
1779 shost->cmd_per_lun = qdepth;
1780}
1781EXPORT_SYMBOL_GPL(iscsi_host_setup);
1772 1782
1773#define hostdata_privsize(_sz) (sizeof(unsigned long) + _sz + \ 1783void iscsi_host_teardown(struct Scsi_Host *shost)
1774 _sz % sizeof(unsigned long)) 1784{
1785 struct iscsi_host *ihost = shost_priv(shost);
1775 1786
1776#define hostdata_session(_hostdata) (iscsi_ptr(*(unsigned long *)_hostdata)) 1787 kfree(ihost->netdev);
1788 kfree(ihost->hwaddress);
1789 kfree(ihost->initiatorname);
1790}
1791EXPORT_SYMBOL_GPL(iscsi_host_teardown);
1777 1792
1778/** 1793/**
1779 * iscsi_session_setup - create iscsi cls session and host and session 1794 * iscsi_session_setup - create iscsi cls session and host and session
1780 * @scsit: scsi transport template
1781 * @iscsit: iscsi transport template 1795 * @iscsit: iscsi transport template
1782 * @cmds_max: scsi host can queue 1796 * @shost: scsi host
1783 * @qdepth: scsi host cmds per lun 1797 * @cmds_max: session can queue
1784 * @cmd_task_size: LLD ctask private data size 1798 * @cmd_task_size: LLD ctask private data size
1785 * @mgmt_task_size: LLD mtask private data size 1799 * @mgmt_task_size: LLD mtask private data size
1786 * @initial_cmdsn: initial CmdSN 1800 * @initial_cmdsn: initial CmdSN
1787 * @hostno: host no allocated
1788 * 1801 *
1789 * This can be used by software iscsi_transports that allocate 1802 * This can be used by software iscsi_transports that allocate
1790 * a session per scsi host. 1803 * a session per scsi host.
1791 **/ 1804 */
1792struct iscsi_cls_session * 1805struct iscsi_cls_session *
1793iscsi_session_setup(struct iscsi_transport *iscsit, 1806iscsi_session_setup(struct iscsi_transport *iscsit, struct Scsi_Host *shost,
1794 struct scsi_transport_template *scsit, 1807 uint16_t cmds_max, int cmd_task_size, int mgmt_task_size,
1795 uint16_t cmds_max, uint16_t qdepth, 1808 uint32_t initial_cmdsn)
1796 int cmd_task_size, int mgmt_task_size,
1797 uint32_t initial_cmdsn, uint32_t *hostno)
1798{ 1809{
1799 struct Scsi_Host *shost;
1800 struct iscsi_session *session; 1810 struct iscsi_session *session;
1801 struct iscsi_cls_session *cls_session; 1811 struct iscsi_cls_session *cls_session;
1802 int cmd_i; 1812 int cmd_i;
1803 1813
1804 if (qdepth > ISCSI_MAX_CMD_PER_LUN || qdepth < 1) {
1805 if (qdepth != 0)
1806 printk(KERN_ERR "iscsi: invalid queue depth of %d. "
1807 "Queue depth must be between 1 and %d.\n",
1808 qdepth, ISCSI_MAX_CMD_PER_LUN);
1809 qdepth = ISCSI_DEF_CMD_PER_LUN;
1810 }
1811
1812 if (!is_power_of_2(cmds_max) || cmds_max >= ISCSI_MGMT_ITT_OFFSET || 1814 if (!is_power_of_2(cmds_max) || cmds_max >= ISCSI_MGMT_ITT_OFFSET ||
1813 cmds_max < 2) { 1815 cmds_max < 2) {
1814 if (cmds_max != 0) 1816 if (cmds_max != 0)
@@ -1819,25 +1821,11 @@ iscsi_session_setup(struct iscsi_transport *iscsit,
1819 cmds_max = ISCSI_DEF_XMIT_CMDS_MAX; 1821 cmds_max = ISCSI_DEF_XMIT_CMDS_MAX;
1820 } 1822 }
1821 1823
1822 shost = scsi_host_alloc(iscsit->host_template, 1824 cls_session = iscsi_alloc_session(shost, iscsit);
1823 hostdata_privsize(sizeof(*session))); 1825 if (!cls_session)
1824 if (!shost)
1825 return NULL; 1826 return NULL;
1826 1827 session = cls_session->dd_data;
1827 /* the iscsi layer takes one task for reserve */ 1828 session->cls_session = cls_session;
1828 shost->can_queue = cmds_max - 1;
1829 shost->cmd_per_lun = qdepth;
1830 shost->max_id = 1;
1831 shost->max_channel = 0;
1832 shost->max_lun = iscsit->max_lun;
1833 shost->max_cmd_len = 16;
1834 shost->transportt = scsit;
1835 shost->transportt->create_work_queue = 1;
1836 shost->transportt->eh_timed_out = iscsi_eh_cmd_timed_out;
1837 *hostno = shost->host_no;
1838
1839 session = iscsi_hostdata(shost->hostdata);
1840 memset(session, 0, sizeof(struct iscsi_session));
1841 session->host = shost; 1829 session->host = shost;
1842 session->state = ISCSI_STATE_FREE; 1830 session->state = ISCSI_STATE_FREE;
1843 session->fast_abort = 1; 1831 session->fast_abort = 1;
@@ -1851,6 +1839,7 @@ iscsi_session_setup(struct iscsi_transport *iscsit,
1851 session->max_r2t = 1; 1839 session->max_r2t = 1;
1852 session->tt = iscsit; 1840 session->tt = iscsit;
1853 mutex_init(&session->eh_mutex); 1841 mutex_init(&session->eh_mutex);
1842 spin_lock_init(&session->lock);
1854 1843
1855 /* initialize SCSI PDU commands pool */ 1844 /* initialize SCSI PDU commands pool */
1856 if (iscsi_pool_init(&session->cmdpool, session->cmds_max, 1845 if (iscsi_pool_init(&session->cmdpool, session->cmds_max,
@@ -1868,8 +1857,6 @@ iscsi_session_setup(struct iscsi_transport *iscsit,
1868 INIT_LIST_HEAD(&ctask->running); 1857 INIT_LIST_HEAD(&ctask->running);
1869 } 1858 }
1870 1859
1871 spin_lock_init(&session->lock);
1872
1873 /* initialize immediate command pool */ 1860 /* initialize immediate command pool */
1874 if (iscsi_pool_init(&session->mgmtpool, session->mgmtpool_max, 1861 if (iscsi_pool_init(&session->mgmtpool, session->mgmtpool_max,
1875 (void***)&session->mgmt_cmds, 1862 (void***)&session->mgmt_cmds,
@@ -1887,49 +1874,37 @@ iscsi_session_setup(struct iscsi_transport *iscsit,
1887 INIT_LIST_HEAD(&mtask->running); 1874 INIT_LIST_HEAD(&mtask->running);
1888 } 1875 }
1889 1876
1890 if (scsi_add_host(shost, NULL))
1891 goto add_host_fail;
1892
1893 if (!try_module_get(iscsit->owner)) 1877 if (!try_module_get(iscsit->owner))
1894 goto cls_session_fail; 1878 goto module_get_fail;
1895
1896 cls_session = iscsi_create_session(shost, iscsit, 0);
1897 if (!cls_session)
1898 goto module_put;
1899 *(unsigned long*)shost->hostdata = (unsigned long)cls_session;
1900 1879
1880 if (iscsi_add_session(cls_session, 0))
1881 goto cls_session_fail;
1901 return cls_session; 1882 return cls_session;
1902 1883
1903module_put:
1904 module_put(iscsit->owner);
1905cls_session_fail: 1884cls_session_fail:
1906 scsi_remove_host(shost); 1885 module_put(iscsit->owner);
1907add_host_fail: 1886module_get_fail:
1908 iscsi_pool_free(&session->mgmtpool); 1887 iscsi_pool_free(&session->mgmtpool);
1909mgmtpool_alloc_fail: 1888mgmtpool_alloc_fail:
1910 iscsi_pool_free(&session->cmdpool); 1889 iscsi_pool_free(&session->cmdpool);
1911cmdpool_alloc_fail: 1890cmdpool_alloc_fail:
1912 scsi_host_put(shost); 1891 iscsi_free_session(cls_session);
1913 return NULL; 1892 return NULL;
1914} 1893}
1915EXPORT_SYMBOL_GPL(iscsi_session_setup); 1894EXPORT_SYMBOL_GPL(iscsi_session_setup);
1916 1895
1917/** 1896/**
1918 * iscsi_session_teardown - destroy session, host, and cls_session 1897 * iscsi_session_teardown - destroy session, host, and cls_session
1919 * shost: scsi host 1898 * @cls_session: iscsi session
1920 * 1899 *
1921 * This can be used by software iscsi_transports that allocate 1900 * The driver must have called iscsi_remove_session before
1922 * a session per scsi host. 1901 * calling this.
1923 **/ 1902 */
1924void iscsi_session_teardown(struct iscsi_cls_session *cls_session) 1903void iscsi_session_teardown(struct iscsi_cls_session *cls_session)
1925{ 1904{
1926 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); 1905 struct iscsi_session *session = cls_session->dd_data;
1927 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
1928 struct module *owner = cls_session->transport->owner; 1906 struct module *owner = cls_session->transport->owner;
1929 1907
1930 iscsi_remove_session(cls_session);
1931 scsi_remove_host(shost);
1932
1933 iscsi_pool_free(&session->mgmtpool); 1908 iscsi_pool_free(&session->mgmtpool);
1934 iscsi_pool_free(&session->cmdpool); 1909 iscsi_pool_free(&session->cmdpool);
1935 1910
@@ -1938,12 +1913,8 @@ void iscsi_session_teardown(struct iscsi_cls_session *cls_session)
1938 kfree(session->username); 1913 kfree(session->username);
1939 kfree(session->username_in); 1914 kfree(session->username_in);
1940 kfree(session->targetname); 1915 kfree(session->targetname);
1941 kfree(session->netdev);
1942 kfree(session->hwaddress);
1943 kfree(session->initiatorname);
1944 1916
1945 iscsi_free_session(cls_session); 1917 iscsi_destroy_session(cls_session);
1946 scsi_host_put(shost);
1947 module_put(owner); 1918 module_put(owner);
1948} 1919}
1949EXPORT_SYMBOL_GPL(iscsi_session_teardown); 1920EXPORT_SYMBOL_GPL(iscsi_session_teardown);
@@ -1956,7 +1927,7 @@ EXPORT_SYMBOL_GPL(iscsi_session_teardown);
1956struct iscsi_cls_conn * 1927struct iscsi_cls_conn *
1957iscsi_conn_setup(struct iscsi_cls_session *cls_session, uint32_t conn_idx) 1928iscsi_conn_setup(struct iscsi_cls_session *cls_session, uint32_t conn_idx)
1958{ 1929{
1959 struct iscsi_session *session = class_to_transport_session(cls_session); 1930 struct iscsi_session *session = cls_session->dd_data;
1960 struct iscsi_conn *conn; 1931 struct iscsi_conn *conn;
1961 struct iscsi_cls_conn *cls_conn; 1932 struct iscsi_cls_conn *cls_conn;
1962 char *data; 1933 char *data;
@@ -2140,7 +2111,7 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
2140 } 2111 }
2141 spin_unlock_bh(&session->lock); 2112 spin_unlock_bh(&session->lock);
2142 2113
2143 iscsi_unblock_session(session_to_cls(session)); 2114 iscsi_unblock_session(session->cls_session);
2144 wake_up(&conn->ehwait); 2115 wake_up(&conn->ehwait);
2145 return 0; 2116 return 0;
2146} 2117}
@@ -2225,7 +2196,7 @@ static void iscsi_start_session_recovery(struct iscsi_session *session,
2225 if (session->state == ISCSI_STATE_IN_RECOVERY && 2196 if (session->state == ISCSI_STATE_IN_RECOVERY &&
2226 old_stop_stage != STOP_CONN_RECOVER) { 2197 old_stop_stage != STOP_CONN_RECOVER) {
2227 debug_scsi("blocking session\n"); 2198 debug_scsi("blocking session\n");
2228 iscsi_block_session(session_to_cls(session)); 2199 iscsi_block_session(session->cls_session);
2229 } 2200 }
2230 } 2201 }
2231 2202
@@ -2260,7 +2231,7 @@ EXPORT_SYMBOL_GPL(iscsi_conn_stop);
2260int iscsi_conn_bind(struct iscsi_cls_session *cls_session, 2231int iscsi_conn_bind(struct iscsi_cls_session *cls_session,
2261 struct iscsi_cls_conn *cls_conn, int is_leading) 2232 struct iscsi_cls_conn *cls_conn, int is_leading)
2262{ 2233{
2263 struct iscsi_session *session = class_to_transport_session(cls_session); 2234 struct iscsi_session *session = cls_session->dd_data;
2264 struct iscsi_conn *conn = cls_conn->dd_data; 2235 struct iscsi_conn *conn = cls_conn->dd_data;
2265 2236
2266 spin_lock_bh(&session->lock); 2237 spin_lock_bh(&session->lock);
@@ -2410,8 +2381,7 @@ EXPORT_SYMBOL_GPL(iscsi_set_param);
2410int iscsi_session_get_param(struct iscsi_cls_session *cls_session, 2381int iscsi_session_get_param(struct iscsi_cls_session *cls_session,
2411 enum iscsi_param param, char *buf) 2382 enum iscsi_param param, char *buf)
2412{ 2383{
2413 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session); 2384 struct iscsi_session *session = cls_session->dd_data;
2414 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
2415 int len; 2385 int len;
2416 2386
2417 switch(param) { 2387 switch(param) {
@@ -2525,29 +2495,34 @@ EXPORT_SYMBOL_GPL(iscsi_conn_get_param);
2525int iscsi_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param, 2495int iscsi_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param,
2526 char *buf) 2496 char *buf)
2527{ 2497{
2528 struct iscsi_session *session = iscsi_hostdata(shost->hostdata); 2498 struct iscsi_host *ihost = shost_priv(shost);
2529 int len; 2499 int len;
2530 2500
2531 switch (param) { 2501 switch (param) {
2532 case ISCSI_HOST_PARAM_NETDEV_NAME: 2502 case ISCSI_HOST_PARAM_NETDEV_NAME:
2533 if (!session->netdev) 2503 if (!ihost->netdev)
2534 len = sprintf(buf, "%s\n", "default"); 2504 len = sprintf(buf, "%s\n", "default");
2535 else 2505 else
2536 len = sprintf(buf, "%s\n", session->netdev); 2506 len = sprintf(buf, "%s\n", ihost->netdev);
2537 break; 2507 break;
2538 case ISCSI_HOST_PARAM_HWADDRESS: 2508 case ISCSI_HOST_PARAM_HWADDRESS:
2539 if (!session->hwaddress) 2509 if (!ihost->hwaddress)
2540 len = sprintf(buf, "%s\n", "default"); 2510 len = sprintf(buf, "%s\n", "default");
2541 else 2511 else
2542 len = sprintf(buf, "%s\n", session->hwaddress); 2512 len = sprintf(buf, "%s\n", ihost->hwaddress);
2543 break; 2513 break;
2544 case ISCSI_HOST_PARAM_INITIATOR_NAME: 2514 case ISCSI_HOST_PARAM_INITIATOR_NAME:
2545 if (!session->initiatorname) 2515 if (!ihost->initiatorname)
2546 len = sprintf(buf, "%s\n", "unknown"); 2516 len = sprintf(buf, "%s\n", "unknown");
2547 else 2517 else
2548 len = sprintf(buf, "%s\n", session->initiatorname); 2518 len = sprintf(buf, "%s\n", ihost->initiatorname);
2549 break; 2519 break;
2550 2520 case ISCSI_HOST_PARAM_IPADDRESS:
2521 if (!strlen(ihost->local_address))
2522 len = sprintf(buf, "%s\n", "unknown");
2523 else
2524 len = sprintf(buf, "%s\n",
2525 ihost->local_address);
2551 default: 2526 default:
2552 return -ENOSYS; 2527 return -ENOSYS;
2553 } 2528 }
@@ -2559,20 +2534,20 @@ EXPORT_SYMBOL_GPL(iscsi_host_get_param);
2559int iscsi_host_set_param(struct Scsi_Host *shost, enum iscsi_host_param param, 2534int iscsi_host_set_param(struct Scsi_Host *shost, enum iscsi_host_param param,
2560 char *buf, int buflen) 2535 char *buf, int buflen)
2561{ 2536{
2562 struct iscsi_session *session = iscsi_hostdata(shost->hostdata); 2537 struct iscsi_host *ihost = shost_priv(shost);
2563 2538
2564 switch (param) { 2539 switch (param) {
2565 case ISCSI_HOST_PARAM_NETDEV_NAME: 2540 case ISCSI_HOST_PARAM_NETDEV_NAME:
2566 if (!session->netdev) 2541 if (!ihost->netdev)
2567 session->netdev = kstrdup(buf, GFP_KERNEL); 2542 ihost->netdev = kstrdup(buf, GFP_KERNEL);
2568 break; 2543 break;
2569 case ISCSI_HOST_PARAM_HWADDRESS: 2544 case ISCSI_HOST_PARAM_HWADDRESS:
2570 if (!session->hwaddress) 2545 if (!ihost->hwaddress)
2571 session->hwaddress = kstrdup(buf, GFP_KERNEL); 2546 ihost->hwaddress = kstrdup(buf, GFP_KERNEL);
2572 break; 2547 break;
2573 case ISCSI_HOST_PARAM_INITIATOR_NAME: 2548 case ISCSI_HOST_PARAM_INITIATOR_NAME:
2574 if (!session->initiatorname) 2549 if (!ihost->initiatorname)
2575 session->initiatorname = kstrdup(buf, GFP_KERNEL); 2550 ihost->initiatorname = kstrdup(buf, GFP_KERNEL);
2576 break; 2551 break;
2577 default: 2552 default:
2578 return -ENOSYS; 2553 return -ENOSYS;
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 0c786944d2c2..6c6ee0f34995 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -114,7 +114,6 @@ static struct iscsi_transport qla4xxx_iscsi_transport = {
114 ISCSI_HOST_IPADDRESS | 114 ISCSI_HOST_IPADDRESS |
115 ISCSI_HOST_INITIATOR_NAME, 115 ISCSI_HOST_INITIATOR_NAME,
116 .sessiondata_size = sizeof(struct ddb_entry), 116 .sessiondata_size = sizeof(struct ddb_entry),
117 .host_template = &qla4xxx_driver_template,
118 117
119 .tgt_dscvr = qla4xxx_tgt_dscvr, 118 .tgt_dscvr = qla4xxx_tgt_dscvr,
120 .get_conn_param = qla4xxx_conn_get_param, 119 .get_conn_param = qla4xxx_conn_get_param,
diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
index 5577a60bec4e..9c00a157b485 100644
--- a/drivers/scsi/scsi_transport_iscsi.c
+++ b/drivers/scsi/scsi_transport_iscsi.c
@@ -101,12 +101,10 @@ show_transport_##name(struct device *dev, \
101static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL); 101static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL);
102 102
103show_transport_attr(caps, "0x%x"); 103show_transport_attr(caps, "0x%x");
104show_transport_attr(max_lun, "%d");
105 104
106static struct attribute *iscsi_transport_attrs[] = { 105static struct attribute *iscsi_transport_attrs[] = {
107 &dev_attr_handle.attr, 106 &dev_attr_handle.attr,
108 &dev_attr_caps.attr, 107 &dev_attr_caps.attr,
109 &dev_attr_max_lun.attr,
110 NULL, 108 NULL,
111}; 109};
112 110
@@ -1034,8 +1032,7 @@ iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_uevent *ev,
1034 } 1032 }
1035 } 1033 }
1036 1034
1037 session = transport->create_session(transport, &priv->t, shost, 1035 session = transport->create_session(shost, cmds_max, queue_depth,
1038 cmds_max, queue_depth,
1039 initial_cmdsn, &host_no); 1036 initial_cmdsn, &host_no);
1040 if (shost) 1037 if (shost)
1041 scsi_host_put(shost); 1038 scsi_host_put(shost);