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.c187
1 files changed, 186 insertions, 1 deletions
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 2673a11a9495..7e6e031cc41b 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -1287,13 +1287,18 @@ iscsi_session_setup(struct iscsi_transport *iscsit,
1287 if (scsi_add_host(shost, NULL)) 1287 if (scsi_add_host(shost, NULL))
1288 goto add_host_fail; 1288 goto add_host_fail;
1289 1289
1290 if (!try_module_get(iscsit->owner))
1291 goto cls_session_fail;
1292
1290 cls_session = iscsi_create_session(shost, iscsit, 0); 1293 cls_session = iscsi_create_session(shost, iscsit, 0);
1291 if (!cls_session) 1294 if (!cls_session)
1292 goto cls_session_fail; 1295 goto module_put;
1293 *(unsigned long*)shost->hostdata = (unsigned long)cls_session; 1296 *(unsigned long*)shost->hostdata = (unsigned long)cls_session;
1294 1297
1295 return cls_session; 1298 return cls_session;
1296 1299
1300module_put:
1301 module_put(iscsit->owner);
1297cls_session_fail: 1302cls_session_fail:
1298 scsi_remove_host(shost); 1303 scsi_remove_host(shost);
1299add_host_fail: 1304add_host_fail:
@@ -1325,6 +1330,7 @@ void iscsi_session_teardown(struct iscsi_cls_session *cls_session)
1325 1330
1326 iscsi_destroy_session(cls_session); 1331 iscsi_destroy_session(cls_session);
1327 scsi_host_put(shost); 1332 scsi_host_put(shost);
1333 module_put(cls_session->transport->owner);
1328} 1334}
1329EXPORT_SYMBOL_GPL(iscsi_session_teardown); 1335EXPORT_SYMBOL_GPL(iscsi_session_teardown);
1330 1336
@@ -1697,6 +1703,185 @@ int iscsi_conn_bind(struct iscsi_cls_session *cls_session,
1697} 1703}
1698EXPORT_SYMBOL_GPL(iscsi_conn_bind); 1704EXPORT_SYMBOL_GPL(iscsi_conn_bind);
1699 1705
1706
1707int iscsi_set_param(struct iscsi_cls_conn *cls_conn,
1708 enum iscsi_param param, char *buf, int buflen)
1709{
1710 struct iscsi_conn *conn = cls_conn->dd_data;
1711 struct iscsi_session *session = conn->session;
1712 uint32_t value;
1713
1714 switch(param) {
1715 case ISCSI_PARAM_MAX_RECV_DLENGTH:
1716 sscanf(buf, "%d", &conn->max_recv_dlength);
1717 break;
1718 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1719 sscanf(buf, "%d", &conn->max_xmit_dlength);
1720 break;
1721 case ISCSI_PARAM_HDRDGST_EN:
1722 sscanf(buf, "%d", &conn->hdrdgst_en);
1723 break;
1724 case ISCSI_PARAM_DATADGST_EN:
1725 sscanf(buf, "%d", &conn->datadgst_en);
1726 break;
1727 case ISCSI_PARAM_INITIAL_R2T_EN:
1728 sscanf(buf, "%d", &session->initial_r2t_en);
1729 break;
1730 case ISCSI_PARAM_MAX_R2T:
1731 sscanf(buf, "%d", &session->max_r2t);
1732 break;
1733 case ISCSI_PARAM_IMM_DATA_EN:
1734 sscanf(buf, "%d", &session->imm_data_en);
1735 break;
1736 case ISCSI_PARAM_FIRST_BURST:
1737 sscanf(buf, "%d", &session->first_burst);
1738 break;
1739 case ISCSI_PARAM_MAX_BURST:
1740 sscanf(buf, "%d", &session->max_burst);
1741 break;
1742 case ISCSI_PARAM_PDU_INORDER_EN:
1743 sscanf(buf, "%d", &session->pdu_inorder_en);
1744 break;
1745 case ISCSI_PARAM_DATASEQ_INORDER_EN:
1746 sscanf(buf, "%d", &session->dataseq_inorder_en);
1747 break;
1748 case ISCSI_PARAM_ERL:
1749 sscanf(buf, "%d", &session->erl);
1750 break;
1751 case ISCSI_PARAM_IFMARKER_EN:
1752 sscanf(buf, "%d", &value);
1753 BUG_ON(value);
1754 break;
1755 case ISCSI_PARAM_OFMARKER_EN:
1756 sscanf(buf, "%d", &value);
1757 BUG_ON(value);
1758 break;
1759 case ISCSI_PARAM_EXP_STATSN:
1760 sscanf(buf, "%u", &conn->exp_statsn);
1761 break;
1762 case ISCSI_PARAM_TARGET_NAME:
1763 /* this should not change between logins */
1764 if (session->targetname)
1765 break;
1766
1767 session->targetname = kstrdup(buf, GFP_KERNEL);
1768 if (!session->targetname)
1769 return -ENOMEM;
1770 break;
1771 case ISCSI_PARAM_TPGT:
1772 sscanf(buf, "%d", &session->tpgt);
1773 break;
1774 case ISCSI_PARAM_PERSISTENT_PORT:
1775 sscanf(buf, "%d", &conn->persistent_port);
1776 break;
1777 case ISCSI_PARAM_PERSISTENT_ADDRESS:
1778 /*
1779 * this is the address returned in discovery so it should
1780 * not change between logins.
1781 */
1782 if (conn->persistent_address)
1783 break;
1784
1785 conn->persistent_address = kstrdup(buf, GFP_KERNEL);
1786 if (!conn->persistent_address)
1787 return -ENOMEM;
1788 break;
1789 default:
1790 return -ENOSYS;
1791 }
1792
1793 return 0;
1794}
1795EXPORT_SYMBOL_GPL(iscsi_set_param);
1796
1797int iscsi_session_get_param(struct iscsi_cls_session *cls_session,
1798 enum iscsi_param param, char *buf)
1799{
1800 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1801 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
1802 int len;
1803
1804 switch(param) {
1805 case ISCSI_PARAM_INITIAL_R2T_EN:
1806 len = sprintf(buf, "%d\n", session->initial_r2t_en);
1807 break;
1808 case ISCSI_PARAM_MAX_R2T:
1809 len = sprintf(buf, "%hu\n", session->max_r2t);
1810 break;
1811 case ISCSI_PARAM_IMM_DATA_EN:
1812 len = sprintf(buf, "%d\n", session->imm_data_en);
1813 break;
1814 case ISCSI_PARAM_FIRST_BURST:
1815 len = sprintf(buf, "%u\n", session->first_burst);
1816 break;
1817 case ISCSI_PARAM_MAX_BURST:
1818 len = sprintf(buf, "%u\n", session->max_burst);
1819 break;
1820 case ISCSI_PARAM_PDU_INORDER_EN:
1821 len = sprintf(buf, "%d\n", session->pdu_inorder_en);
1822 break;
1823 case ISCSI_PARAM_DATASEQ_INORDER_EN:
1824 len = sprintf(buf, "%d\n", session->dataseq_inorder_en);
1825 break;
1826 case ISCSI_PARAM_ERL:
1827 len = sprintf(buf, "%d\n", session->erl);
1828 break;
1829 case ISCSI_PARAM_TARGET_NAME:
1830 len = sprintf(buf, "%s\n", session->targetname);
1831 break;
1832 case ISCSI_PARAM_TPGT:
1833 len = sprintf(buf, "%d\n", session->tpgt);
1834 break;
1835 default:
1836 return -ENOSYS;
1837 }
1838
1839 return len;
1840}
1841EXPORT_SYMBOL_GPL(iscsi_session_get_param);
1842
1843int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
1844 enum iscsi_param param, char *buf)
1845{
1846 struct iscsi_conn *conn = cls_conn->dd_data;
1847 int len;
1848
1849 switch(param) {
1850 case ISCSI_PARAM_MAX_RECV_DLENGTH:
1851 len = sprintf(buf, "%u\n", conn->max_recv_dlength);
1852 break;
1853 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1854 len = sprintf(buf, "%u\n", conn->max_xmit_dlength);
1855 break;
1856 case ISCSI_PARAM_HDRDGST_EN:
1857 len = sprintf(buf, "%d\n", conn->hdrdgst_en);
1858 break;
1859 case ISCSI_PARAM_DATADGST_EN:
1860 len = sprintf(buf, "%d\n", conn->datadgst_en);
1861 break;
1862 case ISCSI_PARAM_IFMARKER_EN:
1863 len = sprintf(buf, "%d\n", conn->ifmarker_en);
1864 break;
1865 case ISCSI_PARAM_OFMARKER_EN:
1866 len = sprintf(buf, "%d\n", conn->ofmarker_en);
1867 break;
1868 case ISCSI_PARAM_EXP_STATSN:
1869 len = sprintf(buf, "%u\n", conn->exp_statsn);
1870 break;
1871 case ISCSI_PARAM_PERSISTENT_PORT:
1872 len = sprintf(buf, "%d\n", conn->persistent_port);
1873 break;
1874 case ISCSI_PARAM_PERSISTENT_ADDRESS:
1875 len = sprintf(buf, "%s\n", conn->persistent_address);
1876 break;
1877 default:
1878 return -ENOSYS;
1879 }
1880
1881 return len;
1882}
1883EXPORT_SYMBOL_GPL(iscsi_conn_get_param);
1884
1700MODULE_AUTHOR("Mike Christie"); 1885MODULE_AUTHOR("Mike Christie");
1701MODULE_DESCRIPTION("iSCSI library functions"); 1886MODULE_DESCRIPTION("iSCSI library functions");
1702MODULE_LICENSE("GPL"); 1887MODULE_LICENSE("GPL");