aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/libiscsi.c
diff options
context:
space:
mode:
authorMike Christie <michaelc@cs.wisc.edu>2006-06-28 13:00:23 -0400
committerJames Bottomley <jejb@mulgrave.il.steeleye.com>2006-06-29 11:07:14 -0400
commita54a52caad4bd6166cb7fa64e4e93031fa2fda5d (patch)
tree728672fae35fd344619129e78213043dabacf099 /drivers/scsi/libiscsi.c
parent01cb225dad8da2e717356fab03240e2f4a8d01bf (diff)
[SCSI] iscsi: fixup set/get param functions
Reduce duplication in the software iscsi_transport modules by adding a libiscsi function to handle the common grunt work. This also has the drivers return specifc -EXXX values for different errors so userspace can finally handle them in a sane way. Also just pass the sysfs buffers to the drivers so HW iscsi can get/set its string values, like targetname, and initiatorname. Signed-off-by: Mike Christie <michaelc@cs.wisc.edu> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi/libiscsi.c')
-rw-r--r--drivers/scsi/libiscsi.c179
1 files changed, 179 insertions, 0 deletions
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 2673a11a9495..7c76a989b218 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -1697,6 +1697,185 @@ int iscsi_conn_bind(struct iscsi_cls_session *cls_session,
1697} 1697}
1698EXPORT_SYMBOL_GPL(iscsi_conn_bind); 1698EXPORT_SYMBOL_GPL(iscsi_conn_bind);
1699 1699
1700
1701int iscsi_set_param(struct iscsi_cls_conn *cls_conn,
1702 enum iscsi_param param, char *buf, int buflen)
1703{
1704 struct iscsi_conn *conn = cls_conn->dd_data;
1705 struct iscsi_session *session = conn->session;
1706 uint32_t value;
1707
1708 switch(param) {
1709 case ISCSI_PARAM_MAX_RECV_DLENGTH:
1710 sscanf(buf, "%d", &conn->max_recv_dlength);
1711 break;
1712 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1713 sscanf(buf, "%d", &conn->max_xmit_dlength);
1714 break;
1715 case ISCSI_PARAM_HDRDGST_EN:
1716 sscanf(buf, "%d", &conn->hdrdgst_en);
1717 break;
1718 case ISCSI_PARAM_DATADGST_EN:
1719 sscanf(buf, "%d", &conn->datadgst_en);
1720 break;
1721 case ISCSI_PARAM_INITIAL_R2T_EN:
1722 sscanf(buf, "%d", &session->initial_r2t_en);
1723 break;
1724 case ISCSI_PARAM_MAX_R2T:
1725 sscanf(buf, "%d", &session->max_r2t);
1726 break;
1727 case ISCSI_PARAM_IMM_DATA_EN:
1728 sscanf(buf, "%d", &session->imm_data_en);
1729 break;
1730 case ISCSI_PARAM_FIRST_BURST:
1731 sscanf(buf, "%d", &session->first_burst);
1732 break;
1733 case ISCSI_PARAM_MAX_BURST:
1734 sscanf(buf, "%d", &session->max_burst);
1735 break;
1736 case ISCSI_PARAM_PDU_INORDER_EN:
1737 sscanf(buf, "%d", &session->pdu_inorder_en);
1738 break;
1739 case ISCSI_PARAM_DATASEQ_INORDER_EN:
1740 sscanf(buf, "%d", &session->dataseq_inorder_en);
1741 break;
1742 case ISCSI_PARAM_ERL:
1743 sscanf(buf, "%d", &session->erl);
1744 break;
1745 case ISCSI_PARAM_IFMARKER_EN:
1746 sscanf(buf, "%d", &value);
1747 BUG_ON(value);
1748 break;
1749 case ISCSI_PARAM_OFMARKER_EN:
1750 sscanf(buf, "%d", &value);
1751 BUG_ON(value);
1752 break;
1753 case ISCSI_PARAM_EXP_STATSN:
1754 sscanf(buf, "%u", &conn->exp_statsn);
1755 break;
1756 case ISCSI_PARAM_TARGET_NAME:
1757 /* this should not change between logins */
1758 if (session->targetname)
1759 break;
1760
1761 session->targetname = kstrdup(buf, GFP_KERNEL);
1762 if (!session->targetname)
1763 return -ENOMEM;
1764 break;
1765 case ISCSI_PARAM_TPGT:
1766 sscanf(buf, "%d", &session->tpgt);
1767 break;
1768 case ISCSI_PARAM_PERSISTENT_PORT:
1769 sscanf(buf, "%d", &conn->persistent_port);
1770 break;
1771 case ISCSI_PARAM_PERSISTENT_ADDRESS:
1772 /*
1773 * this is the address returned in discovery so it should
1774 * not change between logins.
1775 */
1776 if (conn->persistent_address)
1777 break;
1778
1779 conn->persistent_address = kstrdup(buf, GFP_KERNEL);
1780 if (!conn->persistent_address)
1781 return -ENOMEM;
1782 break;
1783 default:
1784 return -ENOSYS;
1785 }
1786
1787 return 0;
1788}
1789EXPORT_SYMBOL_GPL(iscsi_set_param);
1790
1791int iscsi_session_get_param(struct iscsi_cls_session *cls_session,
1792 enum iscsi_param param, char *buf)
1793{
1794 struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
1795 struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
1796 int len;
1797
1798 switch(param) {
1799 case ISCSI_PARAM_INITIAL_R2T_EN:
1800 len = sprintf(buf, "%d\n", session->initial_r2t_en);
1801 break;
1802 case ISCSI_PARAM_MAX_R2T:
1803 len = sprintf(buf, "%hu\n", session->max_r2t);
1804 break;
1805 case ISCSI_PARAM_IMM_DATA_EN:
1806 len = sprintf(buf, "%d\n", session->imm_data_en);
1807 break;
1808 case ISCSI_PARAM_FIRST_BURST:
1809 len = sprintf(buf, "%u\n", session->first_burst);
1810 break;
1811 case ISCSI_PARAM_MAX_BURST:
1812 len = sprintf(buf, "%u\n", session->max_burst);
1813 break;
1814 case ISCSI_PARAM_PDU_INORDER_EN:
1815 len = sprintf(buf, "%d\n", session->pdu_inorder_en);
1816 break;
1817 case ISCSI_PARAM_DATASEQ_INORDER_EN:
1818 len = sprintf(buf, "%d\n", session->dataseq_inorder_en);
1819 break;
1820 case ISCSI_PARAM_ERL:
1821 len = sprintf(buf, "%d\n", session->erl);
1822 break;
1823 case ISCSI_PARAM_TARGET_NAME:
1824 len = sprintf(buf, "%s\n", session->targetname);
1825 break;
1826 case ISCSI_PARAM_TPGT:
1827 len = sprintf(buf, "%d\n", session->tpgt);
1828 break;
1829 default:
1830 return -ENOSYS;
1831 }
1832
1833 return len;
1834}
1835EXPORT_SYMBOL_GPL(iscsi_session_get_param);
1836
1837int iscsi_conn_get_param(struct iscsi_cls_conn *cls_conn,
1838 enum iscsi_param param, char *buf)
1839{
1840 struct iscsi_conn *conn = cls_conn->dd_data;
1841 int len;
1842
1843 switch(param) {
1844 case ISCSI_PARAM_MAX_RECV_DLENGTH:
1845 len = sprintf(buf, "%u\n", conn->max_recv_dlength);
1846 break;
1847 case ISCSI_PARAM_MAX_XMIT_DLENGTH:
1848 len = sprintf(buf, "%u\n", conn->max_xmit_dlength);
1849 break;
1850 case ISCSI_PARAM_HDRDGST_EN:
1851 len = sprintf(buf, "%d\n", conn->hdrdgst_en);
1852 break;
1853 case ISCSI_PARAM_DATADGST_EN:
1854 len = sprintf(buf, "%d\n", conn->datadgst_en);
1855 break;
1856 case ISCSI_PARAM_IFMARKER_EN:
1857 len = sprintf(buf, "%d\n", conn->ifmarker_en);
1858 break;
1859 case ISCSI_PARAM_OFMARKER_EN:
1860 len = sprintf(buf, "%d\n", conn->ofmarker_en);
1861 break;
1862 case ISCSI_PARAM_EXP_STATSN:
1863 len = sprintf(buf, "%u\n", conn->exp_statsn);
1864 break;
1865 case ISCSI_PARAM_PERSISTENT_PORT:
1866 len = sprintf(buf, "%d\n", conn->persistent_port);
1867 break;
1868 case ISCSI_PARAM_PERSISTENT_ADDRESS:
1869 len = sprintf(buf, "%s\n", conn->persistent_address);
1870 break;
1871 default:
1872 return -ENOSYS;
1873 }
1874
1875 return len;
1876}
1877EXPORT_SYMBOL_GPL(iscsi_conn_get_param);
1878
1700MODULE_AUTHOR("Mike Christie"); 1879MODULE_AUTHOR("Mike Christie");
1701MODULE_DESCRIPTION("iSCSI library functions"); 1880MODULE_DESCRIPTION("iSCSI library functions");
1702MODULE_LICENSE("GPL"); 1881MODULE_LICENSE("GPL");