diff options
author | Christoph Hellwig <hch@lst.de> | 2016-01-09 08:30:45 -0500 |
---|---|---|
committer | Nicholas Bellinger <nab@linux-iscsi.org> | 2016-03-11 00:44:28 -0500 |
commit | fb444abe61f5a943a41870d71eab8c4402bd46ab (patch) | |
tree | fed0a4e17519cb91a6b85b8de1857891202a1c50 | |
parent | 7861728d42338e1efac9d400c39319c1b5efd05c (diff) |
target: Convert demo-mode only drivers to target_alloc_session
This patch converts existing loopback, usb-gadget, and
xen-scsiback demo-mode only fabric drivers to use the
new target_alloc_session API caller.
This includes adding a new alloc_session callback for
fabric driver internal nexus pointer assignments.
(Fixes for early for-next nexus breakage - Dan Carpenter)
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Acked-by: Juergen Gross <jgross@suse.com>
Tested-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Tested-by: Chris Boot <bootc@bootc.net>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
-rw-r--r-- | drivers/target/loopback/tcm_loop.c | 46 | ||||
-rw-r--r-- | drivers/target/sbp/sbp_target.c | 33 | ||||
-rw-r--r-- | drivers/usb/gadget/function/f_tcm.c | 55 | ||||
-rw-r--r-- | drivers/xen/xen-scsiback.c | 60 |
4 files changed, 72 insertions, 122 deletions
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c index d41a5c300e31..0ad5ac541a7f 100644 --- a/drivers/target/loopback/tcm_loop.c +++ b/drivers/target/loopback/tcm_loop.c | |||
@@ -802,58 +802,48 @@ static struct configfs_attribute *tcm_loop_tpg_attrib_attrs[] = { | |||
802 | 802 | ||
803 | /* Start items for tcm_loop_nexus_cit */ | 803 | /* Start items for tcm_loop_nexus_cit */ |
804 | 804 | ||
805 | static int tcm_loop_alloc_sess_cb(struct se_portal_group *se_tpg, | ||
806 | struct se_session *se_sess, void *p) | ||
807 | { | ||
808 | struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, | ||
809 | struct tcm_loop_tpg, tl_se_tpg); | ||
810 | |||
811 | tl_tpg->tl_nexus = p; | ||
812 | return 0; | ||
813 | } | ||
814 | |||
805 | static int tcm_loop_make_nexus( | 815 | static int tcm_loop_make_nexus( |
806 | struct tcm_loop_tpg *tl_tpg, | 816 | struct tcm_loop_tpg *tl_tpg, |
807 | const char *name) | 817 | const char *name) |
808 | { | 818 | { |
809 | struct se_portal_group *se_tpg; | ||
810 | struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba; | 819 | struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba; |
811 | struct tcm_loop_nexus *tl_nexus; | 820 | struct tcm_loop_nexus *tl_nexus; |
812 | int ret = -ENOMEM; | 821 | int ret; |
813 | 822 | ||
814 | if (tl_tpg->tl_nexus) { | 823 | if (tl_tpg->tl_nexus) { |
815 | pr_debug("tl_tpg->tl_nexus already exists\n"); | 824 | pr_debug("tl_tpg->tl_nexus already exists\n"); |
816 | return -EEXIST; | 825 | return -EEXIST; |
817 | } | 826 | } |
818 | se_tpg = &tl_tpg->tl_se_tpg; | ||
819 | 827 | ||
820 | tl_nexus = kzalloc(sizeof(struct tcm_loop_nexus), GFP_KERNEL); | 828 | tl_nexus = kzalloc(sizeof(struct tcm_loop_nexus), GFP_KERNEL); |
821 | if (!tl_nexus) { | 829 | if (!tl_nexus) { |
822 | pr_err("Unable to allocate struct tcm_loop_nexus\n"); | 830 | pr_err("Unable to allocate struct tcm_loop_nexus\n"); |
823 | return -ENOMEM; | 831 | return -ENOMEM; |
824 | } | 832 | } |
825 | /* | 833 | |
826 | * Initialize the struct se_session pointer | 834 | tl_nexus->se_sess = target_alloc_session(&tl_tpg->tl_se_tpg, 0, 0, |
827 | */ | 835 | TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS, |
828 | tl_nexus->se_sess = transport_init_session( | 836 | name, tl_nexus, tcm_loop_alloc_sess_cb); |
829 | TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS); | ||
830 | if (IS_ERR(tl_nexus->se_sess)) { | 837 | if (IS_ERR(tl_nexus->se_sess)) { |
831 | ret = PTR_ERR(tl_nexus->se_sess); | 838 | ret = PTR_ERR(tl_nexus->se_sess); |
832 | goto out; | 839 | kfree(tl_nexus); |
833 | } | 840 | return ret; |
834 | /* | ||
835 | * Since we are running in 'demo mode' this call with generate a | ||
836 | * struct se_node_acl for the tcm_loop struct se_portal_group with the SCSI | ||
837 | * Initiator port name of the passed configfs group 'name'. | ||
838 | */ | ||
839 | tl_nexus->se_sess->se_node_acl = core_tpg_check_initiator_node_acl( | ||
840 | se_tpg, (unsigned char *)name); | ||
841 | if (!tl_nexus->se_sess->se_node_acl) { | ||
842 | transport_free_session(tl_nexus->se_sess); | ||
843 | goto out; | ||
844 | } | 841 | } |
845 | /* Now, register the I_T Nexus as active. */ | 842 | |
846 | transport_register_session(se_tpg, tl_nexus->se_sess->se_node_acl, | ||
847 | tl_nexus->se_sess, tl_nexus); | ||
848 | tl_tpg->tl_nexus = tl_nexus; | ||
849 | pr_debug("TCM_Loop_ConfigFS: Established I_T Nexus to emulated" | 843 | pr_debug("TCM_Loop_ConfigFS: Established I_T Nexus to emulated" |
850 | " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba), | 844 | " %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba), |
851 | name); | 845 | name); |
852 | return 0; | 846 | return 0; |
853 | |||
854 | out: | ||
855 | kfree(tl_nexus); | ||
856 | return ret; | ||
857 | } | 847 | } |
858 | 848 | ||
859 | static int tcm_loop_drop_nexus( | 849 | static int tcm_loop_drop_nexus( |
diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c index 3072f1aca8ec..ddd3398c1561 100644 --- a/drivers/target/sbp/sbp_target.c +++ b/drivers/target/sbp/sbp_target.c | |||
@@ -196,45 +196,28 @@ static struct sbp_session *sbp_session_create( | |||
196 | struct sbp_session *sess; | 196 | struct sbp_session *sess; |
197 | int ret; | 197 | int ret; |
198 | char guid_str[17]; | 198 | char guid_str[17]; |
199 | struct se_node_acl *se_nacl; | 199 | |
200 | snprintf(guid_str, sizeof(guid_str), "%016llx", guid); | ||
200 | 201 | ||
201 | sess = kmalloc(sizeof(*sess), GFP_KERNEL); | 202 | sess = kmalloc(sizeof(*sess), GFP_KERNEL); |
202 | if (!sess) { | 203 | if (!sess) { |
203 | pr_err("failed to allocate session descriptor\n"); | 204 | pr_err("failed to allocate session descriptor\n"); |
204 | return ERR_PTR(-ENOMEM); | 205 | return ERR_PTR(-ENOMEM); |
205 | } | 206 | } |
207 | spin_lock_init(&sess->lock); | ||
208 | INIT_LIST_HEAD(&sess->login_list); | ||
209 | INIT_DELAYED_WORK(&sess->maint_work, session_maintenance_work); | ||
210 | sess->guid = guid; | ||
206 | 211 | ||
207 | sess->se_sess = transport_init_session(TARGET_PROT_NORMAL); | 212 | sess->se_sess = target_alloc_session(&tpg->se_tpg, 0, 0, TARGET_PROT_NORMAL, |
213 | guid_str, sess, NULL); | ||
208 | if (IS_ERR(sess->se_sess)) { | 214 | if (IS_ERR(sess->se_sess)) { |
209 | pr_err("failed to init se_session\n"); | 215 | pr_err("failed to init se_session\n"); |
210 | |||
211 | ret = PTR_ERR(sess->se_sess); | 216 | ret = PTR_ERR(sess->se_sess); |
212 | kfree(sess); | 217 | kfree(sess); |
213 | return ERR_PTR(ret); | 218 | return ERR_PTR(ret); |
214 | } | 219 | } |
215 | 220 | ||
216 | snprintf(guid_str, sizeof(guid_str), "%016llx", guid); | ||
217 | |||
218 | se_nacl = core_tpg_check_initiator_node_acl(&tpg->se_tpg, guid_str); | ||
219 | if (!se_nacl) { | ||
220 | pr_warn("Node ACL not found for %s\n", guid_str); | ||
221 | |||
222 | transport_free_session(sess->se_sess); | ||
223 | kfree(sess); | ||
224 | |||
225 | return ERR_PTR(-EPERM); | ||
226 | } | ||
227 | |||
228 | sess->se_sess->se_node_acl = se_nacl; | ||
229 | |||
230 | spin_lock_init(&sess->lock); | ||
231 | INIT_LIST_HEAD(&sess->login_list); | ||
232 | INIT_DELAYED_WORK(&sess->maint_work, session_maintenance_work); | ||
233 | |||
234 | sess->guid = guid; | ||
235 | |||
236 | transport_register_session(&tpg->se_tpg, se_nacl, sess->se_sess, sess); | ||
237 | |||
238 | return sess; | 221 | return sess; |
239 | } | 222 | } |
240 | 223 | ||
diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c index bad007b5a190..e803724c7ee3 100644 --- a/drivers/usb/gadget/function/f_tcm.c +++ b/drivers/usb/gadget/function/f_tcm.c | |||
@@ -1579,55 +1579,46 @@ out: | |||
1579 | return ret; | 1579 | return ret; |
1580 | } | 1580 | } |
1581 | 1581 | ||
1582 | static int usbg_alloc_sess_cb(struct se_portal_group *se_tpg, | ||
1583 | struct se_session *se_sess, void *p) | ||
1584 | { | ||
1585 | struct usbg_tpg *tpg = container_of(se_tpg, | ||
1586 | struct usbg_tpg, se_tpg); | ||
1587 | |||
1588 | tpg->tpg_nexus = p; | ||
1589 | return 0; | ||
1590 | } | ||
1591 | |||
1582 | static int tcm_usbg_make_nexus(struct usbg_tpg *tpg, char *name) | 1592 | static int tcm_usbg_make_nexus(struct usbg_tpg *tpg, char *name) |
1583 | { | 1593 | { |
1584 | struct se_portal_group *se_tpg; | ||
1585 | struct tcm_usbg_nexus *tv_nexus; | 1594 | struct tcm_usbg_nexus *tv_nexus; |
1586 | int ret; | 1595 | int ret = 0; |
1587 | 1596 | ||
1588 | mutex_lock(&tpg->tpg_mutex); | 1597 | mutex_lock(&tpg->tpg_mutex); |
1589 | if (tpg->tpg_nexus) { | 1598 | if (tpg->tpg_nexus) { |
1590 | ret = -EEXIST; | 1599 | ret = -EEXIST; |
1591 | pr_debug("tpg->tpg_nexus already exists\n"); | 1600 | pr_debug("tpg->tpg_nexus already exists\n"); |
1592 | goto err_unlock; | 1601 | goto out_unlock; |
1593 | } | 1602 | } |
1594 | se_tpg = &tpg->se_tpg; | ||
1595 | 1603 | ||
1596 | ret = -ENOMEM; | ||
1597 | tv_nexus = kzalloc(sizeof(*tv_nexus), GFP_KERNEL); | 1604 | tv_nexus = kzalloc(sizeof(*tv_nexus), GFP_KERNEL); |
1598 | if (!tv_nexus) | 1605 | if (!tv_nexus) { |
1599 | goto err_unlock; | 1606 | ret = -ENOMEM; |
1600 | tv_nexus->tvn_se_sess = transport_init_session(TARGET_PROT_NORMAL); | 1607 | goto out_unlock; |
1601 | if (IS_ERR(tv_nexus->tvn_se_sess)) | 1608 | } |
1602 | goto err_free; | ||
1603 | 1609 | ||
1604 | /* | 1610 | tv_nexus->tvn_se_sess = target_alloc_session(&tpg->se_tpg, 0, 0, |
1605 | * Since we are running in 'demo mode' this call with generate a | 1611 | TARGET_PROT_NORMAL, name, |
1606 | * struct se_node_acl for the tcm_vhost struct se_portal_group with | 1612 | tv_nexus, usbg_alloc_sess_cb); |
1607 | * the SCSI Initiator port name of the passed configfs group 'name'. | 1613 | if (IS_ERR(tv_nexus->tvn_se_sess)) { |
1608 | */ | ||
1609 | tv_nexus->tvn_se_sess->se_node_acl = core_tpg_check_initiator_node_acl( | ||
1610 | se_tpg, name); | ||
1611 | if (!tv_nexus->tvn_se_sess->se_node_acl) { | ||
1612 | #define MAKE_NEXUS_MSG "core_tpg_check_initiator_node_acl() failed for %s\n" | 1614 | #define MAKE_NEXUS_MSG "core_tpg_check_initiator_node_acl() failed for %s\n" |
1613 | pr_debug(MAKE_NEXUS_MSG, name); | 1615 | pr_debug(MAKE_NEXUS_MSG, name); |
1614 | #undef MAKE_NEXUS_MSG | 1616 | #undef MAKE_NEXUS_MSG |
1615 | goto err_session; | 1617 | ret = PTR_ERR(tv_nexus->tvn_se_sess); |
1618 | kfree(tv_nexus); | ||
1616 | } | 1619 | } |
1617 | /* | ||
1618 | * Now register the TCM vHost virtual I_T Nexus as active. | ||
1619 | */ | ||
1620 | transport_register_session(se_tpg, tv_nexus->tvn_se_sess->se_node_acl, | ||
1621 | tv_nexus->tvn_se_sess, tv_nexus); | ||
1622 | tpg->tpg_nexus = tv_nexus; | ||
1623 | mutex_unlock(&tpg->tpg_mutex); | ||
1624 | return 0; | ||
1625 | 1620 | ||
1626 | err_session: | 1621 | out_unlock: |
1627 | transport_free_session(tv_nexus->tvn_se_sess); | ||
1628 | err_free: | ||
1629 | kfree(tv_nexus); | ||
1630 | err_unlock: | ||
1631 | mutex_unlock(&tpg->tpg_mutex); | 1622 | mutex_unlock(&tpg->tpg_mutex); |
1632 | return ret; | 1623 | return ret; |
1633 | } | 1624 | } |
diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c index ad4eb1024d1f..077993fcc203 100644 --- a/drivers/xen/xen-scsiback.c +++ b/drivers/xen/xen-scsiback.c | |||
@@ -1482,61 +1482,47 @@ static struct configfs_attribute *scsiback_param_attrs[] = { | |||
1482 | NULL, | 1482 | NULL, |
1483 | }; | 1483 | }; |
1484 | 1484 | ||
1485 | static int scsiback_alloc_sess_cb(struct se_portal_group *se_tpg, | ||
1486 | struct se_session *se_sess, void *p) | ||
1487 | { | ||
1488 | struct scsiback_tpg *tpg = container_of(se_tpg, | ||
1489 | struct scsiback_tpg, se_tpg); | ||
1490 | |||
1491 | tpg->tpg_nexus = p; | ||
1492 | return 0; | ||
1493 | } | ||
1494 | |||
1485 | static int scsiback_make_nexus(struct scsiback_tpg *tpg, | 1495 | static int scsiback_make_nexus(struct scsiback_tpg *tpg, |
1486 | const char *name) | 1496 | const char *name) |
1487 | { | 1497 | { |
1488 | struct se_portal_group *se_tpg; | ||
1489 | struct se_session *se_sess; | ||
1490 | struct scsiback_nexus *tv_nexus; | 1498 | struct scsiback_nexus *tv_nexus; |
1499 | int ret = 0; | ||
1491 | 1500 | ||
1492 | mutex_lock(&tpg->tv_tpg_mutex); | 1501 | mutex_lock(&tpg->tv_tpg_mutex); |
1493 | if (tpg->tpg_nexus) { | 1502 | if (tpg->tpg_nexus) { |
1494 | mutex_unlock(&tpg->tv_tpg_mutex); | ||
1495 | pr_debug("tpg->tpg_nexus already exists\n"); | 1503 | pr_debug("tpg->tpg_nexus already exists\n"); |
1496 | return -EEXIST; | 1504 | ret = -EEXIST; |
1505 | goto out_unlock; | ||
1497 | } | 1506 | } |
1498 | se_tpg = &tpg->se_tpg; | ||
1499 | 1507 | ||
1500 | tv_nexus = kzalloc(sizeof(struct scsiback_nexus), GFP_KERNEL); | 1508 | tv_nexus = kzalloc(sizeof(struct scsiback_nexus), GFP_KERNEL); |
1501 | if (!tv_nexus) { | 1509 | if (!tv_nexus) { |
1502 | mutex_unlock(&tpg->tv_tpg_mutex); | 1510 | ret = -ENOMEM; |
1503 | return -ENOMEM; | 1511 | goto out_unlock; |
1504 | } | 1512 | } |
1505 | /* | 1513 | |
1506 | * Initialize the struct se_session pointer | 1514 | tv_nexus->tvn_se_sess = target_alloc_session(&tpg->se_tpg, 0, 0, |
1507 | */ | 1515 | TARGET_PROT_NORMAL, name, |
1508 | tv_nexus->tvn_se_sess = transport_init_session(TARGET_PROT_NORMAL); | 1516 | tv_nexus, scsiback_alloc_sess_cb); |
1509 | if (IS_ERR(tv_nexus->tvn_se_sess)) { | 1517 | if (IS_ERR(tv_nexus->tvn_se_sess)) { |
1510 | mutex_unlock(&tpg->tv_tpg_mutex); | ||
1511 | kfree(tv_nexus); | 1518 | kfree(tv_nexus); |
1512 | return -ENOMEM; | 1519 | ret = -ENOMEM; |
1520 | goto out_unlock; | ||
1513 | } | 1521 | } |
1514 | se_sess = tv_nexus->tvn_se_sess; | ||
1515 | /* | ||
1516 | * Since we are running in 'demo mode' this call with generate a | ||
1517 | * struct se_node_acl for the scsiback struct se_portal_group with | ||
1518 | * the SCSI Initiator port name of the passed configfs group 'name'. | ||
1519 | */ | ||
1520 | tv_nexus->tvn_se_sess->se_node_acl = core_tpg_check_initiator_node_acl( | ||
1521 | se_tpg, (unsigned char *)name); | ||
1522 | if (!tv_nexus->tvn_se_sess->se_node_acl) { | ||
1523 | mutex_unlock(&tpg->tv_tpg_mutex); | ||
1524 | pr_debug("core_tpg_check_initiator_node_acl() failed for %s\n", | ||
1525 | name); | ||
1526 | goto out; | ||
1527 | } | ||
1528 | /* Now register the TCM pvscsi virtual I_T Nexus as active. */ | ||
1529 | transport_register_session(se_tpg, tv_nexus->tvn_se_sess->se_node_acl, | ||
1530 | tv_nexus->tvn_se_sess, tv_nexus); | ||
1531 | tpg->tpg_nexus = tv_nexus; | ||
1532 | 1522 | ||
1523 | out_unlock: | ||
1533 | mutex_unlock(&tpg->tv_tpg_mutex); | 1524 | mutex_unlock(&tpg->tv_tpg_mutex); |
1534 | return 0; | 1525 | return ret; |
1535 | |||
1536 | out: | ||
1537 | transport_free_session(se_sess); | ||
1538 | kfree(tv_nexus); | ||
1539 | return -ENOMEM; | ||
1540 | } | 1526 | } |
1541 | 1527 | ||
1542 | static int scsiback_drop_nexus(struct scsiback_tpg *tpg) | 1528 | static int scsiback_drop_nexus(struct scsiback_tpg *tpg) |