Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

vhost/scsi: Convert to target_alloc_session usage

This patch converts vhost/scsi pre-allocation of vhost_scsi_cmd
descriptors to use the new alloc_session callback().

Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

+45 -62
+45 -62
drivers/vhost/scsi.c
··· 1664 1664 mutex_unlock(&vhost_scsi_mutex); 1665 1665 } 1666 1666 1667 - static void vhost_scsi_free_cmd_map_res(struct vhost_scsi_nexus *nexus, 1668 - struct se_session *se_sess) 1667 + static void vhost_scsi_free_cmd_map_res(struct se_session *se_sess) 1669 1668 { 1670 1669 struct vhost_scsi_cmd *tv_cmd; 1671 1670 unsigned int i; ··· 1720 1721 NULL, 1721 1722 }; 1722 1723 1724 + static int vhost_scsi_nexus_cb(struct se_portal_group *se_tpg, 1725 + struct se_session *se_sess, void *p) 1726 + { 1727 + struct vhost_scsi_cmd *tv_cmd; 1728 + unsigned int i; 1729 + 1730 + for (i = 0; i < VHOST_SCSI_DEFAULT_TAGS; i++) { 1731 + tv_cmd = &((struct vhost_scsi_cmd *)se_sess->sess_cmd_map)[i]; 1732 + 1733 + tv_cmd->tvc_sgl = kzalloc(sizeof(struct scatterlist) * 1734 + VHOST_SCSI_PREALLOC_SGLS, GFP_KERNEL); 1735 + if (!tv_cmd->tvc_sgl) { 1736 + pr_err("Unable to allocate tv_cmd->tvc_sgl\n"); 1737 + goto out; 1738 + } 1739 + 1740 + tv_cmd->tvc_upages = kzalloc(sizeof(struct page *) * 1741 + VHOST_SCSI_PREALLOC_UPAGES, GFP_KERNEL); 1742 + if (!tv_cmd->tvc_upages) { 1743 + pr_err("Unable to allocate tv_cmd->tvc_upages\n"); 1744 + goto out; 1745 + } 1746 + 1747 + tv_cmd->tvc_prot_sgl = kzalloc(sizeof(struct scatterlist) * 1748 + VHOST_SCSI_PREALLOC_PROT_SGLS, GFP_KERNEL); 1749 + if (!tv_cmd->tvc_prot_sgl) { 1750 + pr_err("Unable to allocate tv_cmd->tvc_prot_sgl\n"); 1751 + goto out; 1752 + } 1753 + } 1754 + return 0; 1755 + out: 1756 + vhost_scsi_free_cmd_map_res(se_sess); 1757 + return -ENOMEM; 1758 + } 1759 + 1723 1760 static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg, 1724 1761 const char *name) 1725 1762 { 1726 1763 struct se_portal_group *se_tpg; 1727 - struct se_session *se_sess; 1728 1764 struct vhost_scsi_nexus *tv_nexus; 1729 - struct vhost_scsi_cmd *tv_cmd; 1730 - unsigned int i; 1731 1765 1732 1766 mutex_lock(&tpg->tv_tpg_mutex); 1733 1767 if (tpg->tpg_nexus) { ··· 1777 1745 return -ENOMEM; 1778 1746 } 1779 1747 /* 1780 - * Initialize the struct se_session pointer and setup tagpool 1781 - * for struct vhost_scsi_cmd descriptors 1748 + * Since we are running in 'demo mode' this call with generate a 1749 + * struct se_node_acl for the vhost_scsi struct se_portal_group with 1750 + * the SCSI Initiator port name of the passed configfs group 'name'. 1782 1751 */ 1783 - tv_nexus->tvn_se_sess = transport_init_session_tags( 1752 + tv_nexus->tvn_se_sess = target_alloc_session(&tpg->se_tpg, 1784 1753 VHOST_SCSI_DEFAULT_TAGS, 1785 1754 sizeof(struct vhost_scsi_cmd), 1786 - TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS); 1755 + TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS, 1756 + (unsigned char *)name, tv_nexus, 1757 + vhost_scsi_nexus_cb); 1787 1758 if (IS_ERR(tv_nexus->tvn_se_sess)) { 1788 1759 mutex_unlock(&tpg->tv_tpg_mutex); 1789 1760 kfree(tv_nexus); 1790 1761 return -ENOMEM; 1791 1762 } 1792 - se_sess = tv_nexus->tvn_se_sess; 1793 - for (i = 0; i < VHOST_SCSI_DEFAULT_TAGS; i++) { 1794 - tv_cmd = &((struct vhost_scsi_cmd *)se_sess->sess_cmd_map)[i]; 1795 - 1796 - tv_cmd->tvc_sgl = kzalloc(sizeof(struct scatterlist) * 1797 - VHOST_SCSI_PREALLOC_SGLS, GFP_KERNEL); 1798 - if (!tv_cmd->tvc_sgl) { 1799 - mutex_unlock(&tpg->tv_tpg_mutex); 1800 - pr_err("Unable to allocate tv_cmd->tvc_sgl\n"); 1801 - goto out; 1802 - } 1803 - 1804 - tv_cmd->tvc_upages = kzalloc(sizeof(struct page *) * 1805 - VHOST_SCSI_PREALLOC_UPAGES, GFP_KERNEL); 1806 - if (!tv_cmd->tvc_upages) { 1807 - mutex_unlock(&tpg->tv_tpg_mutex); 1808 - pr_err("Unable to allocate tv_cmd->tvc_upages\n"); 1809 - goto out; 1810 - } 1811 - 1812 - tv_cmd->tvc_prot_sgl = kzalloc(sizeof(struct scatterlist) * 1813 - VHOST_SCSI_PREALLOC_PROT_SGLS, GFP_KERNEL); 1814 - if (!tv_cmd->tvc_prot_sgl) { 1815 - mutex_unlock(&tpg->tv_tpg_mutex); 1816 - pr_err("Unable to allocate tv_cmd->tvc_prot_sgl\n"); 1817 - goto out; 1818 - } 1819 - } 1820 - /* 1821 - * Since we are running in 'demo mode' this call with generate a 1822 - * struct se_node_acl for the vhost_scsi struct se_portal_group with 1823 - * the SCSI Initiator port name of the passed configfs group 'name'. 1824 - */ 1825 - tv_nexus->tvn_se_sess->se_node_acl = core_tpg_check_initiator_node_acl( 1826 - se_tpg, (unsigned char *)name); 1827 - if (!tv_nexus->tvn_se_sess->se_node_acl) { 1828 - mutex_unlock(&tpg->tv_tpg_mutex); 1829 - pr_debug("core_tpg_check_initiator_node_acl() failed" 1830 - " for %s\n", name); 1831 - goto out; 1832 - } 1833 - /* 1834 - * Now register the TCM vhost virtual I_T Nexus as active. 1835 - */ 1836 - transport_register_session(se_tpg, tv_nexus->tvn_se_sess->se_node_acl, 1837 - tv_nexus->tvn_se_sess, tv_nexus); 1838 1763 tpg->tpg_nexus = tv_nexus; 1839 1764 1840 1765 mutex_unlock(&tpg->tv_tpg_mutex); 1841 1766 return 0; 1842 - 1843 - out: 1844 - vhost_scsi_free_cmd_map_res(tv_nexus, se_sess); 1845 - transport_free_session(se_sess); 1846 - kfree(tv_nexus); 1847 - return -ENOMEM; 1848 1767 } 1849 1768 1850 1769 static int vhost_scsi_drop_nexus(struct vhost_scsi_tpg *tpg) ··· 1836 1853 " %s Initiator Port: %s\n", vhost_scsi_dump_proto_id(tpg->tport), 1837 1854 tv_nexus->tvn_se_sess->se_node_acl->initiatorname); 1838 1855 1839 - vhost_scsi_free_cmd_map_res(tv_nexus, se_sess); 1856 + vhost_scsi_free_cmd_map_res(se_sess); 1840 1857 /* 1841 1858 * Release the SCSI I_T Nexus to the emulated vhost Target Port 1842 1859 */