* [PATCH-for-4.6 0/6] target: Introduce target_alloc_session helper
@ 2016-01-10 20:44 Nicholas A. Bellinger
2016-01-10 20:44 ` [PATCH-for-4.6 1/6] target: Add target_alloc_session() helper function Nicholas A. Bellinger
` (5 more replies)
0 siblings, 6 replies; 15+ messages in thread
From: Nicholas A. Bellinger @ 2016-01-10 20:44 UTC (permalink / raw)
To: target-devel
Cc: linux-scsi, lkml, Sagi Grimberg, Christoph Hellwig,
Hannes Reinecke, Andy Grover, Vasu Dev, Vu Pham,
Nicholas Bellinger
From: Nicholas Bellinger <nab@linux-iscsi.org>
Hi folks,
As per HCH, consolidating se_session init -> lookup -> register
into a single helper has a number of benefits.
This version of the target_alloc_session() helper supports
percpu-ida tag allocation, and a (*callback)() for allowing
fabric driver code to complete internal setup before target
calls transport_register_session() to complete the operation.
That said, here's a first shot for the tree wide-conversion,
which should be considered post v4.5 material at this point,
considering it's purely a mechanical change.
Please review,
--nab
Christoph Hellwig (1):
target: Convert demo-mode only drivers to target_alloc_session
Nicholas Bellinger (5):
target: Add target_alloc_session() helper function
vhost/scsi: Convert to target_alloc_session usage
tcm_qla2xxx: Convert to target_alloc_session usage
tcm_fc: Convert to target_alloc_session usage
ib_srpt: Convert to target_alloc_session usage
drivers/infiniband/ulp/srpt/ib_srpt.c | 23 +++-----
drivers/scsi/qla2xxx/qla_target.c | 8 +--
drivers/scsi/qla2xxx/qla_target.h | 2 +-
drivers/scsi/qla2xxx/tcm_qla2xxx.c | 79 +++++++++++++--------------
drivers/target/loopback/tcm_loop.c | 35 +++---------
drivers/target/sbp/sbp_target.c | 33 +++---------
drivers/target/target_core_transport.c | 55 +++++++++++++++++++
drivers/target/tcm_fc/tfc_sess.c | 47 ++++++++--------
drivers/usb/gadget/function/f_tcm.c | 45 +++++-----------
drivers/vhost/scsi.c | 99 ++++++++++++++--------------------
drivers/xen/xen-scsiback.c | 51 +++++-------------
include/target/target_core_fabric.h | 6 +++
12 files changed, 218 insertions(+), 265 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH-for-4.6 1/6] target: Add target_alloc_session() helper function
2016-01-10 20:44 [PATCH-for-4.6 0/6] target: Introduce target_alloc_session helper Nicholas A. Bellinger
@ 2016-01-10 20:44 ` Nicholas A. Bellinger
2016-01-11 22:10 ` Bart Van Assche
2016-01-12 15:11 ` Christoph Hellwig
2016-01-10 20:44 ` [PATCH-for-4.6 2/6] target: Convert demo-mode only drivers to target_alloc_session Nicholas A. Bellinger
` (4 subsequent siblings)
5 siblings, 2 replies; 15+ messages in thread
From: Nicholas A. Bellinger @ 2016-01-10 20:44 UTC (permalink / raw)
To: target-devel
Cc: linux-scsi, lkml, Sagi Grimberg, Christoph Hellwig,
Hannes Reinecke, Andy Grover, Vasu Dev, Vu Pham,
Nicholas Bellinger
From: Nicholas Bellinger <nab@linux-iscsi.org>
Based on HCH's original patch, this adds a full version to
support percpu-ida tag pre-allocation and callback function
pointer into fabric driver code to complete session setup.
Reported-by: Christoph Hellwig <hch@lst.de>
Cc: Sagi Grimberg <sagig@mellanox.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Andy Grover <agrover@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
drivers/target/target_core_transport.c | 55 ++++++++++++++++++++++++++++++++++
include/target/target_core_fabric.h | 6 ++++
2 files changed, 61 insertions(+)
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index c5035b9..fd4404f6 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -374,6 +374,61 @@ void transport_register_session(
}
EXPORT_SYMBOL(transport_register_session);
+struct se_session *
+target_alloc_session(struct se_portal_group *tpg,
+ unsigned int tag_num, unsigned int tag_size,
+ enum target_prot_op prot_op,
+ const char *initiatorname, void *private,
+ int (*callback)(struct se_portal_group *,
+ struct se_session *, void *))
+{
+ struct se_session *sess;
+
+ if (tag_num != 0 && !tag_size) {
+ pr_err("target_alloc_session called with percpu-ida tag_num:"
+ " %u, but zero tag_size\n", tag_num);
+ return ERR_PTR(-EINVAL);
+ }
+ if (!tag_num && tag_size) {
+ pr_err("target_alloc_session called with percpu-ida tag_size:"
+ " %u, but zero tag_num\n", tag_size);
+ return ERR_PTR(-EINVAL);
+ }
+ /*
+ * If the fabric driver is using percpu-ida based pre allocation
+ * of I/O descriptor tags, go ahead and perform that setup now..
+ */
+ if (tag_num != 0)
+ sess = transport_init_session_tags(tag_num, tag_size, prot_op);
+ else
+ sess = transport_init_session(prot_op);
+
+ if (IS_ERR(sess))
+ return sess;
+
+ sess->se_node_acl = core_tpg_check_initiator_node_acl(tpg,
+ (unsigned char *)initiatorname);
+ if (!sess->se_node_acl) {
+ transport_free_session(sess);
+ return ERR_PTR(-EACCES);
+ }
+ /*
+ * Go ahead and perform any remaining fabric setup that is
+ * required before transport_register_session().
+ */
+ if (callback != NULL) {
+ int rc = callback(tpg, sess, private);
+ if (rc) {
+ transport_free_session(sess);
+ return ERR_PTR(rc);
+ }
+ }
+
+ transport_register_session(tpg, sess->se_node_acl, sess, private);
+ return sess;
+}
+EXPORT_SYMBOL(target_alloc_session);
+
static void target_release_session(struct kref *kref)
{
struct se_session *se_sess = container_of(kref,
diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h
index dc6b09e..7d59273 100644
--- a/include/target/target_core_fabric.h
+++ b/include/target/target_core_fabric.h
@@ -108,6 +108,12 @@ void target_unregister_template(const struct target_core_fabric_ops *fo);
int target_depend_item(struct config_item *item);
void target_undepend_item(struct config_item *item);
+struct se_session *target_alloc_session(struct se_portal_group *,
+ unsigned int, unsigned int, enum target_prot_op prot_op,
+ const char *, void *,
+ int (*callback)(struct se_portal_group *,
+ struct se_session *, void *));
+
struct se_session *transport_init_session(enum target_prot_op);
int transport_alloc_session_tags(struct se_session *, unsigned int,
unsigned int);
--
1.9.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH-for-4.6 2/6] target: Convert demo-mode only drivers to target_alloc_session
2016-01-10 20:44 [PATCH-for-4.6 0/6] target: Introduce target_alloc_session helper Nicholas A. Bellinger
2016-01-10 20:44 ` [PATCH-for-4.6 1/6] target: Add target_alloc_session() helper function Nicholas A. Bellinger
@ 2016-01-10 20:44 ` Nicholas A. Bellinger
2016-01-10 20:44 ` [PATCH-for-4.6 3/6] vhost/scsi: Convert to target_alloc_session usage Nicholas A. Bellinger
` (3 subsequent siblings)
5 siblings, 0 replies; 15+ messages in thread
From: Nicholas A. Bellinger @ 2016-01-10 20:44 UTC (permalink / raw)
To: target-devel
Cc: linux-scsi, lkml, Sagi Grimberg, Christoph Hellwig,
Hannes Reinecke, Andy Grover, Vasu Dev, Vu Pham
From: Christoph Hellwig <hch@lst.de>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de> # loopback
Cc: Chris Boot <bootc@bootc.net> # sbp-target
Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de> # usb-gadget
Cc: Andrzej Pietrasiewicz <andrzej.p@samsung.com> # usb-gadget
Cc: Juergen Gross <jgross@suse.com> # xen-scsiback
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
drivers/target/loopback/tcm_loop.c | 35 +++++--------------------
drivers/target/sbp/sbp_target.c | 33 ++++++------------------
drivers/usb/gadget/function/f_tcm.c | 45 ++++++++++----------------------
drivers/xen/xen-scsiback.c | 51 ++++++++++---------------------------
4 files changed, 42 insertions(+), 122 deletions(-)
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index d41a5c3..0216c75 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -806,54 +806,33 @@ static int tcm_loop_make_nexus(
struct tcm_loop_tpg *tl_tpg,
const char *name)
{
- struct se_portal_group *se_tpg;
struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
struct tcm_loop_nexus *tl_nexus;
- int ret = -ENOMEM;
if (tl_tpg->tl_nexus) {
pr_debug("tl_tpg->tl_nexus already exists\n");
return -EEXIST;
}
- se_tpg = &tl_tpg->tl_se_tpg;
tl_nexus = kzalloc(sizeof(struct tcm_loop_nexus), GFP_KERNEL);
if (!tl_nexus) {
pr_err("Unable to allocate struct tcm_loop_nexus\n");
return -ENOMEM;
}
- /*
- * Initialize the struct se_session pointer
- */
- tl_nexus->se_sess = transport_init_session(
- TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS);
+
+ tl_nexus->se_sess = target_alloc_session(&tl_tpg->tl_se_tpg, 0, 0,
+ TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS,
+ name, tl_nexus, NULL);
if (IS_ERR(tl_nexus->se_sess)) {
- ret = PTR_ERR(tl_nexus->se_sess);
- goto out;
- }
- /*
- * Since we are running in 'demo mode' this call with generate a
- * struct se_node_acl for the tcm_loop struct se_portal_group with the SCSI
- * Initiator port name of the passed configfs group 'name'.
- */
- tl_nexus->se_sess->se_node_acl = core_tpg_check_initiator_node_acl(
- se_tpg, (unsigned char *)name);
- if (!tl_nexus->se_sess->se_node_acl) {
- transport_free_session(tl_nexus->se_sess);
- goto out;
+ kfree(tl_nexus);
+ return PTR_ERR(tl_nexus->se_sess);
}
- /* Now, register the I_T Nexus as active. */
- transport_register_session(se_tpg, tl_nexus->se_sess->se_node_acl,
- tl_nexus->se_sess, tl_nexus);
+
tl_tpg->tl_nexus = tl_nexus;
pr_debug("TCM_Loop_ConfigFS: Established I_T Nexus to emulated"
" %s Initiator Port: %s\n", tcm_loop_dump_proto_id(tl_hba),
name);
return 0;
-
-out:
- kfree(tl_nexus);
- return ret;
}
static int tcm_loop_drop_nexus(
diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
index 3072f1a..ddd3398 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(
struct sbp_session *sess;
int ret;
char guid_str[17];
- struct se_node_acl *se_nacl;
+
+ snprintf(guid_str, sizeof(guid_str), "%016llx", guid);
sess = kmalloc(sizeof(*sess), GFP_KERNEL);
if (!sess) {
pr_err("failed to allocate session descriptor\n");
return ERR_PTR(-ENOMEM);
}
+ spin_lock_init(&sess->lock);
+ INIT_LIST_HEAD(&sess->login_list);
+ INIT_DELAYED_WORK(&sess->maint_work, session_maintenance_work);
+ sess->guid = guid;
- sess->se_sess = transport_init_session(TARGET_PROT_NORMAL);
+ sess->se_sess = target_alloc_session(&tpg->se_tpg, 0, 0, TARGET_PROT_NORMAL,
+ guid_str, sess, NULL);
if (IS_ERR(sess->se_sess)) {
pr_err("failed to init se_session\n");
-
ret = PTR_ERR(sess->se_sess);
kfree(sess);
return ERR_PTR(ret);
}
- snprintf(guid_str, sizeof(guid_str), "%016llx", guid);
-
- se_nacl = core_tpg_check_initiator_node_acl(&tpg->se_tpg, guid_str);
- if (!se_nacl) {
- pr_warn("Node ACL not found for %s\n", guid_str);
-
- transport_free_session(sess->se_sess);
- kfree(sess);
-
- return ERR_PTR(-EPERM);
- }
-
- sess->se_sess->se_node_acl = se_nacl;
-
- spin_lock_init(&sess->lock);
- INIT_LIST_HEAD(&sess->login_list);
- INIT_DELAYED_WORK(&sess->maint_work, session_maintenance_work);
-
- sess->guid = guid;
-
- transport_register_session(&tpg->se_tpg, se_nacl, sess->se_sess, sess);
-
return sess;
}
diff --git a/drivers/usb/gadget/function/f_tcm.c b/drivers/usb/gadget/function/f_tcm.c
index bad007b5..2e8b91d 100644
--- a/drivers/usb/gadget/function/f_tcm.c
+++ b/drivers/usb/gadget/function/f_tcm.c
@@ -1581,53 +1581,34 @@ out:
static int tcm_usbg_make_nexus(struct usbg_tpg *tpg, char *name)
{
- struct se_portal_group *se_tpg;
struct tcm_usbg_nexus *tv_nexus;
- int ret;
+ int ret = 0;
mutex_lock(&tpg->tpg_mutex);
if (tpg->tpg_nexus) {
ret = -EEXIST;
pr_debug("tpg->tpg_nexus already exists\n");
- goto err_unlock;
+ goto out_unlock;
}
- se_tpg = &tpg->se_tpg;
- ret = -ENOMEM;
tv_nexus = kzalloc(sizeof(*tv_nexus), GFP_KERNEL);
- if (!tv_nexus)
- goto err_unlock;
- tv_nexus->tvn_se_sess = transport_init_session(TARGET_PROT_NORMAL);
- if (IS_ERR(tv_nexus->tvn_se_sess))
- goto err_free;
+ if (!tv_nexus) {
+ ret = -ENOMEM;
+ goto out_unlock;
+ }
- /*
- * Since we are running in 'demo mode' this call with generate a
- * struct se_node_acl for the tcm_vhost struct se_portal_group with
- * the SCSI Initiator port name of the passed configfs group 'name'.
- */
- tv_nexus->tvn_se_sess->se_node_acl = core_tpg_check_initiator_node_acl(
- se_tpg, name);
- if (!tv_nexus->tvn_se_sess->se_node_acl) {
+ tv_nexus->tvn_se_sess = target_alloc_session(&tpg->se_tpg, 0, 0,
+ TARGET_PROT_NORMAL, name,
+ tv_nexus, NULL);
+ if (IS_ERR(tv_nexus->tvn_se_sess)) {
#define MAKE_NEXUS_MSG "core_tpg_check_initiator_node_acl() failed for %s\n"
pr_debug(MAKE_NEXUS_MSG, name);
#undef MAKE_NEXUS_MSG
- goto err_session;
+ kfree(tv_nexus);
+ ret = PTR_ERR(tv_nexus->tvn_se_sess);
}
- /*
- * Now register the TCM vHost virtual I_T Nexus as active.
- */
- transport_register_session(se_tpg, tv_nexus->tvn_se_sess->se_node_acl,
- tv_nexus->tvn_se_sess, tv_nexus);
- tpg->tpg_nexus = tv_nexus;
- mutex_unlock(&tpg->tpg_mutex);
- return 0;
-err_session:
- transport_free_session(tv_nexus->tvn_se_sess);
-err_free:
- kfree(tv_nexus);
-err_unlock:
+out_unlock:
mutex_unlock(&tpg->tpg_mutex);
return ret;
}
diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c
index 43bcae8..594f8a7 100644
--- a/drivers/xen/xen-scsiback.c
+++ b/drivers/xen/xen-scsiback.c
@@ -1485,58 +1485,35 @@ static struct configfs_attribute *scsiback_param_attrs[] = {
static int scsiback_make_nexus(struct scsiback_tpg *tpg,
const char *name)
{
- struct se_portal_group *se_tpg;
- struct se_session *se_sess;
struct scsiback_nexus *tv_nexus;
+ int ret = 0;
mutex_lock(&tpg->tv_tpg_mutex);
if (tpg->tpg_nexus) {
- mutex_unlock(&tpg->tv_tpg_mutex);
pr_debug("tpg->tpg_nexus already exists\n");
- return -EEXIST;
+ ret = -EEXIST;
+ goto out_unlock;
}
- se_tpg = &tpg->se_tpg;
tv_nexus = kzalloc(sizeof(struct scsiback_nexus), GFP_KERNEL);
if (!tv_nexus) {
- mutex_unlock(&tpg->tv_tpg_mutex);
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto out_unlock;
}
- /*
- * Initialize the struct se_session pointer
- */
- tv_nexus->tvn_se_sess = transport_init_session(TARGET_PROT_NORMAL);
+
+ tv_nexus->tvn_se_sess = target_alloc_session(&tpg->se_tpg, 0, 0,
+ TARGET_PROT_NORMAL, name,
+ tv_nexus, NULL);
if (IS_ERR(tv_nexus->tvn_se_sess)) {
- mutex_unlock(&tpg->tv_tpg_mutex);
kfree(tv_nexus);
- return -ENOMEM;
- }
- se_sess = tv_nexus->tvn_se_sess;
- /*
- * Since we are running in 'demo mode' this call with generate a
- * struct se_node_acl for the scsiback struct se_portal_group with
- * the SCSI Initiator port name of the passed configfs group 'name'.
- */
- tv_nexus->tvn_se_sess->se_node_acl = core_tpg_check_initiator_node_acl(
- se_tpg, (unsigned char *)name);
- if (!tv_nexus->tvn_se_sess->se_node_acl) {
- mutex_unlock(&tpg->tv_tpg_mutex);
- pr_debug("core_tpg_check_initiator_node_acl() failed for %s\n",
- name);
- goto out;
+ ret = -ENOMEM;
+ goto out_unlock;
}
- /* Now register the TCM pvscsi virtual I_T Nexus as active. */
- transport_register_session(se_tpg, tv_nexus->tvn_se_sess->se_node_acl,
- tv_nexus->tvn_se_sess, tv_nexus);
- tpg->tpg_nexus = tv_nexus;
+ tpg->tpg_nexus = tv_nexus;
+out_unlock:
mutex_unlock(&tpg->tv_tpg_mutex);
- return 0;
-
-out:
- transport_free_session(se_sess);
- kfree(tv_nexus);
- return -ENOMEM;
+ return ret;
}
static int scsiback_drop_nexus(struct scsiback_tpg *tpg)
--
1.9.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH-for-4.6 3/6] vhost/scsi: Convert to target_alloc_session usage
2016-01-10 20:44 [PATCH-for-4.6 0/6] target: Introduce target_alloc_session helper Nicholas A. Bellinger
2016-01-10 20:44 ` [PATCH-for-4.6 1/6] target: Add target_alloc_session() helper function Nicholas A. Bellinger
2016-01-10 20:44 ` [PATCH-for-4.6 2/6] target: Convert demo-mode only drivers to target_alloc_session Nicholas A. Bellinger
@ 2016-01-10 20:44 ` Nicholas A. Bellinger
2016-01-10 21:32 ` Michael S. Tsirkin
2016-01-10 20:44 ` [PATCH-for-4.6 4/6] tcm_qla2xxx: " Nicholas A. Bellinger
` (2 subsequent siblings)
5 siblings, 1 reply; 15+ messages in thread
From: Nicholas A. Bellinger @ 2016-01-10 20:44 UTC (permalink / raw)
To: target-devel
Cc: linux-scsi, lkml, Sagi Grimberg, Christoph Hellwig,
Hannes Reinecke, Andy Grover, Vasu Dev, Vu Pham,
Nicholas Bellinger, Michael S. Tsirkin
From: Nicholas Bellinger <nab@linux-iscsi.org>
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
drivers/vhost/scsi.c | 99 ++++++++++++++++++++++------------------------------
1 file changed, 41 insertions(+), 58 deletions(-)
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 29cfc57..cd5f20f 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -1664,8 +1664,7 @@ static void vhost_scsi_port_unlink(struct se_portal_group *se_tpg,
mutex_unlock(&vhost_scsi_mutex);
}
-static void vhost_scsi_free_cmd_map_res(struct vhost_scsi_nexus *nexus,
- struct se_session *se_sess)
+static void vhost_scsi_free_cmd_map_res(struct se_session *se_sess)
{
struct vhost_scsi_cmd *tv_cmd;
unsigned int i;
@@ -1721,98 +1720,82 @@ static struct configfs_attribute *vhost_scsi_tpg_attrib_attrs[] = {
NULL,
};
-static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
- const char *name)
+static int vhost_scsi_nexus_cb(struct se_portal_group *se_tpg,
+ struct se_session *se_sess, void *p)
{
- struct se_portal_group *se_tpg;
- struct se_session *se_sess;
- struct vhost_scsi_nexus *tv_nexus;
struct vhost_scsi_cmd *tv_cmd;
unsigned int i;
- mutex_lock(&tpg->tv_tpg_mutex);
- if (tpg->tpg_nexus) {
- mutex_unlock(&tpg->tv_tpg_mutex);
- pr_debug("tpg->tpg_nexus already exists\n");
- return -EEXIST;
- }
- se_tpg = &tpg->se_tpg;
-
- tv_nexus = kzalloc(sizeof(struct vhost_scsi_nexus), GFP_KERNEL);
- if (!tv_nexus) {
- mutex_unlock(&tpg->tv_tpg_mutex);
- pr_err("Unable to allocate struct vhost_scsi_nexus\n");
- return -ENOMEM;
- }
- /*
- * Initialize the struct se_session pointer and setup tagpool
- * for struct vhost_scsi_cmd descriptors
- */
- tv_nexus->tvn_se_sess = transport_init_session_tags(
- VHOST_SCSI_DEFAULT_TAGS,
- sizeof(struct vhost_scsi_cmd),
- TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS);
- if (IS_ERR(tv_nexus->tvn_se_sess)) {
- mutex_unlock(&tpg->tv_tpg_mutex);
- kfree(tv_nexus);
- return -ENOMEM;
- }
- se_sess = tv_nexus->tvn_se_sess;
for (i = 0; i < VHOST_SCSI_DEFAULT_TAGS; i++) {
tv_cmd = &((struct vhost_scsi_cmd *)se_sess->sess_cmd_map)[i];
tv_cmd->tvc_sgl = kzalloc(sizeof(struct scatterlist) *
VHOST_SCSI_PREALLOC_SGLS, GFP_KERNEL);
if (!tv_cmd->tvc_sgl) {
- mutex_unlock(&tpg->tv_tpg_mutex);
pr_err("Unable to allocate tv_cmd->tvc_sgl\n");
goto out;
}
tv_cmd->tvc_upages = kzalloc(sizeof(struct page *) *
- VHOST_SCSI_PREALLOC_UPAGES, GFP_KERNEL);
+ VHOST_SCSI_PREALLOC_UPAGES, GFP_KERNEL);
if (!tv_cmd->tvc_upages) {
- mutex_unlock(&tpg->tv_tpg_mutex);
pr_err("Unable to allocate tv_cmd->tvc_upages\n");
goto out;
}
tv_cmd->tvc_prot_sgl = kzalloc(sizeof(struct scatterlist) *
- VHOST_SCSI_PREALLOC_PROT_SGLS, GFP_KERNEL);
+ VHOST_SCSI_PREALLOC_PROT_SGLS, GFP_KERNEL);
if (!tv_cmd->tvc_prot_sgl) {
- mutex_unlock(&tpg->tv_tpg_mutex);
pr_err("Unable to allocate tv_cmd->tvc_prot_sgl\n");
goto out;
}
}
+ return 0;
+out:
+ vhost_scsi_free_cmd_map_res(se_sess);
+ return -ENOMEM;
+}
+
+static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
+ const char *name)
+{
+ struct se_portal_group *se_tpg;
+ struct vhost_scsi_nexus *tv_nexus;
+
+ mutex_lock(&tpg->tv_tpg_mutex);
+ if (tpg->tpg_nexus) {
+ mutex_unlock(&tpg->tv_tpg_mutex);
+ pr_debug("tpg->tpg_nexus already exists\n");
+ return -EEXIST;
+ }
+ se_tpg = &tpg->se_tpg;
+
+ tv_nexus = kzalloc(sizeof(struct vhost_scsi_nexus), GFP_KERNEL);
+ if (!tv_nexus) {
+ mutex_unlock(&tpg->tv_tpg_mutex);
+ pr_err("Unable to allocate struct vhost_scsi_nexus\n");
+ return -ENOMEM;
+ }
/*
* Since we are running in 'demo mode' this call with generate a
* struct se_node_acl for the vhost_scsi struct se_portal_group with
* the SCSI Initiator port name of the passed configfs group 'name'.
*/
- tv_nexus->tvn_se_sess->se_node_acl = core_tpg_check_initiator_node_acl(
- se_tpg, (unsigned char *)name);
- if (!tv_nexus->tvn_se_sess->se_node_acl) {
+ tv_nexus->tvn_se_sess = target_alloc_session(&tpg->se_tpg,
+ VHOST_SCSI_DEFAULT_TAGS,
+ sizeof(struct vhost_scsi_cmd),
+ TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS,
+ (unsigned char *)name, tv_nexus,
+ vhost_scsi_nexus_cb);
+ if (IS_ERR(tv_nexus->tvn_se_sess)) {
mutex_unlock(&tpg->tv_tpg_mutex);
- pr_debug("core_tpg_check_initiator_node_acl() failed"
- " for %s\n", name);
- goto out;
+ kfree(tv_nexus);
+ return -ENOMEM;
}
- /*
- * Now register the TCM vhost virtual I_T Nexus as active.
- */
- transport_register_session(se_tpg, tv_nexus->tvn_se_sess->se_node_acl,
- tv_nexus->tvn_se_sess, tv_nexus);
tpg->tpg_nexus = tv_nexus;
mutex_unlock(&tpg->tv_tpg_mutex);
return 0;
-
-out:
- vhost_scsi_free_cmd_map_res(tv_nexus, se_sess);
- transport_free_session(se_sess);
- kfree(tv_nexus);
- return -ENOMEM;
}
static int vhost_scsi_drop_nexus(struct vhost_scsi_tpg *tpg)
@@ -1853,7 +1836,7 @@ static int vhost_scsi_drop_nexus(struct vhost_scsi_tpg *tpg)
" %s Initiator Port: %s\n", vhost_scsi_dump_proto_id(tpg->tport),
tv_nexus->tvn_se_sess->se_node_acl->initiatorname);
- vhost_scsi_free_cmd_map_res(tv_nexus, se_sess);
+ vhost_scsi_free_cmd_map_res(se_sess);
/*
* Release the SCSI I_T Nexus to the emulated vhost Target Port
*/
--
1.9.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH-for-4.6 4/6] tcm_qla2xxx: Convert to target_alloc_session usage
2016-01-10 20:44 [PATCH-for-4.6 0/6] target: Introduce target_alloc_session helper Nicholas A. Bellinger
` (2 preceding siblings ...)
2016-01-10 20:44 ` [PATCH-for-4.6 3/6] vhost/scsi: Convert to target_alloc_session usage Nicholas A. Bellinger
@ 2016-01-10 20:44 ` Nicholas A. Bellinger
2016-01-10 20:44 ` [PATCH-for-4.6 5/6] tcm_fc: " Nicholas A. Bellinger
2016-01-10 20:44 ` [PATCH-for-4.6 6/6] ib_srpt: " Nicholas A. Bellinger
5 siblings, 0 replies; 15+ messages in thread
From: Nicholas A. Bellinger @ 2016-01-10 20:44 UTC (permalink / raw)
To: target-devel
Cc: linux-scsi, lkml, Sagi Grimberg, Christoph Hellwig,
Hannes Reinecke, Andy Grover, Vasu Dev, Vu Pham,
Nicholas Bellinger, Himanshu Madhani, Quinn Tran
From: Nicholas Bellinger <nab@linux-iscsi.org>
Cc: Himanshu Madhani <himanshu.madhani@qlogic.com>
Cc: Quinn Tran <quinn.tran@qlogic.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
drivers/scsi/qla2xxx/qla_target.c | 8 +---
drivers/scsi/qla2xxx/qla_target.h | 2 +-
drivers/scsi/qla2xxx/tcm_qla2xxx.c | 79 +++++++++++++++++++-------------------
3 files changed, 43 insertions(+), 46 deletions(-)
diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index c7ab9e6..80ae367 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -879,7 +879,6 @@ static struct qla_tgt_sess *qlt_create_sess(
struct qla_hw_data *ha = vha->hw;
struct qla_tgt_sess *sess;
unsigned long flags;
- unsigned char be_sid[3];
/* Check to avoid double sessions */
spin_lock_irqsave(&ha->tgt.sess_lock, flags);
@@ -948,17 +947,14 @@ static struct qla_tgt_sess *qlt_create_sess(
"Adding sess %p to tgt %p via ->check_initiator_node_acl()\n",
sess, vha->vha_tgt.qla_tgt);
- be_sid[0] = sess->s_id.b.domain;
- be_sid[1] = sess->s_id.b.area;
- be_sid[2] = sess->s_id.b.al_pa;
/*
* Determine if this fc_port->port_name is allowed to access
* target mode using explict NodeACLs+MappedLUNs, or using
* TPG demo mode. If this is successful a target mode FC nexus
* is created.
*/
- if (ha->tgt.tgt_ops->check_initiator_node_acl(vha,
- &fcport->port_name[0], sess, &be_sid[0], fcport->loop_id) < 0) {
+ if (ha->tgt.tgt_ops->check_initiator_node_acl(vha, &fcport->port_name[0],
+ sess)) {
kfree(sess);
return NULL;
}
diff --git a/drivers/scsi/qla2xxx/qla_target.h b/drivers/scsi/qla2xxx/qla_target.h
index 71b2865..409bd5f 100644
--- a/drivers/scsi/qla2xxx/qla_target.h
+++ b/drivers/scsi/qla2xxx/qla_target.h
@@ -731,7 +731,7 @@ struct qla_tgt_func_tmpl {
void (*free_session)(struct qla_tgt_sess *);
int (*check_initiator_node_acl)(struct scsi_qla_host *, unsigned char *,
- void *, uint8_t *, uint16_t);
+ struct qla_tgt_sess *);
void (*update_sess)(struct qla_tgt_sess *, port_id_t, uint16_t, bool);
struct qla_tgt_sess *(*find_sess_by_loop_id)(struct scsi_qla_host *,
const uint16_t);
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index b44f397..bf73c6f 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -1336,6 +1336,39 @@ static void tcm_qla2xxx_free_session(struct qla_tgt_sess *sess)
transport_deregister_session(sess->se_sess);
}
+static int tcm_qla2xxx_session_cb(struct se_portal_group *se_tpg,
+ struct se_session *se_sess, void *p)
+{
+ struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
+ struct tcm_qla2xxx_tpg, se_tpg);
+ struct tcm_qla2xxx_lport *lport = tpg->lport;
+ struct qla_hw_data *ha = lport->qla_vha->hw;
+ struct se_node_acl *se_nacl = se_sess->se_node_acl;
+ struct tcm_qla2xxx_nacl *nacl = container_of(se_nacl,
+ struct tcm_qla2xxx_nacl, se_node_acl);
+ struct qla_tgt_sess *qlat_sess = p;
+ uint16_t loop_id = qlat_sess->loop_id;
+ unsigned long flags;
+ unsigned char be_sid[3];
+
+ be_sid[0] = qlat_sess->s_id.b.domain;
+ be_sid[1] = qlat_sess->s_id.b.area;
+ be_sid[2] = qlat_sess->s_id.b.al_pa;
+
+ /*
+ * And now setup se_nacl and session pointers into HW lport internal
+ * mappings for fabric S_ID and LOOP_ID.
+ */
+ spin_lock_irqsave(&ha->tgt.sess_lock, flags);
+ tcm_qla2xxx_set_sess_by_s_id(lport, se_nacl, nacl,
+ se_sess, qlat_sess, be_sid);
+ tcm_qla2xxx_set_sess_by_loop_id(lport, se_nacl, nacl,
+ se_sess, qlat_sess, loop_id);
+ spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
+
+ return 0;
+}
+
/*
* Called via qlt_create_sess():ha->qla2x_tmpl->check_initiator_node_acl()
* to locate struct se_node_acl
@@ -1343,20 +1376,13 @@ static void tcm_qla2xxx_free_session(struct qla_tgt_sess *sess)
static int tcm_qla2xxx_check_initiator_node_acl(
scsi_qla_host_t *vha,
unsigned char *fc_wwpn,
- void *qla_tgt_sess,
- uint8_t *s_id,
- uint16_t loop_id)
+ struct qla_tgt_sess *qlat_sess)
{
struct qla_hw_data *ha = vha->hw;
struct tcm_qla2xxx_lport *lport;
struct tcm_qla2xxx_tpg *tpg;
- struct tcm_qla2xxx_nacl *nacl;
- struct se_portal_group *se_tpg;
- struct se_node_acl *se_nacl;
struct se_session *se_sess;
- struct qla_tgt_sess *sess = qla_tgt_sess;
unsigned char port_name[36];
- unsigned long flags;
int num_tags = (ha->cur_fw_xcb_count) ? ha->cur_fw_xcb_count :
TCM_QLA2XXX_DEFAULT_TAGS;
@@ -1374,15 +1400,6 @@ static int tcm_qla2xxx_check_initiator_node_acl(
pr_err("Unable to lcoate struct tcm_qla2xxx_lport->tpg_1\n");
return -EINVAL;
}
- se_tpg = &tpg->se_tpg;
-
- se_sess = transport_init_session_tags(num_tags,
- sizeof(struct qla_tgt_cmd),
- TARGET_PROT_ALL);
- if (IS_ERR(se_sess)) {
- pr_err("Unable to initialize struct se_session\n");
- return PTR_ERR(se_sess);
- }
/*
* Format the FCP Initiator port_name into colon seperated values to
* match the format by tcm_qla2xxx explict ConfigFS NodeACLs.
@@ -1393,28 +1410,12 @@ static int tcm_qla2xxx_check_initiator_node_acl(
* Locate our struct se_node_acl either from an explict NodeACL created
* via ConfigFS, or via running in TPG demo mode.
*/
- se_sess->se_node_acl = core_tpg_check_initiator_node_acl(se_tpg,
- port_name);
- if (!se_sess->se_node_acl) {
- transport_free_session(se_sess);
- return -EINVAL;
- }
- se_nacl = se_sess->se_node_acl;
- nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl);
- /*
- * And now setup the new se_nacl and session pointers into our HW lport
- * mappings for fabric S_ID and LOOP_ID.
- */
- spin_lock_irqsave(&ha->tgt.sess_lock, flags);
- tcm_qla2xxx_set_sess_by_s_id(lport, se_nacl, nacl, se_sess,
- qla_tgt_sess, s_id);
- tcm_qla2xxx_set_sess_by_loop_id(lport, se_nacl, nacl, se_sess,
- qla_tgt_sess, loop_id);
- spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
- /*
- * Finally register the new FC Nexus with TCM
- */
- transport_register_session(se_nacl->se_tpg, se_nacl, se_sess, sess);
+ se_sess = target_alloc_session(&tpg->se_tpg, num_tags,
+ sizeof(struct qla_tgt_cmd),
+ TARGET_PROT_ALL, port_name,
+ qlat_sess, tcm_qla2xxx_session_cb);
+ if (IS_ERR(se_sess))
+ return PTR_ERR(se_sess);
return 0;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH-for-4.6 5/6] tcm_fc: Convert to target_alloc_session usage
2016-01-10 20:44 [PATCH-for-4.6 0/6] target: Introduce target_alloc_session helper Nicholas A. Bellinger
` (3 preceding siblings ...)
2016-01-10 20:44 ` [PATCH-for-4.6 4/6] tcm_qla2xxx: " Nicholas A. Bellinger
@ 2016-01-10 20:44 ` Nicholas A. Bellinger
2016-01-10 20:44 ` [PATCH-for-4.6 6/6] ib_srpt: " Nicholas A. Bellinger
5 siblings, 0 replies; 15+ messages in thread
From: Nicholas A. Bellinger @ 2016-01-10 20:44 UTC (permalink / raw)
To: target-devel
Cc: linux-scsi, lkml, Sagi Grimberg, Christoph Hellwig,
Hannes Reinecke, Andy Grover, Vasu Dev, Vu Pham,
Nicholas Bellinger
From: Nicholas Bellinger <nab@linux-iscsi.org>
Cc: Vasu Dev <vasu.dev@linux.intel.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
drivers/target/tcm_fc/tfc_sess.c | 47 +++++++++++++++++++++-------------------
1 file changed, 25 insertions(+), 22 deletions(-)
diff --git a/drivers/target/tcm_fc/tfc_sess.c b/drivers/target/tcm_fc/tfc_sess.c
index b3db638..19bfbda 100644
--- a/drivers/target/tcm_fc/tfc_sess.c
+++ b/drivers/target/tcm_fc/tfc_sess.c
@@ -186,6 +186,20 @@ out:
return NULL;
}
+static int ft_sess_alloc_cb(struct se_portal_group *se_tpg,
+ struct se_session *se_sess, void *p)
+{
+ struct ft_sess *sess = p;
+ struct ft_tport *tport = sess->tport;
+ struct hlist_head *head = &tport->hash[ft_sess_hash(sess->port_id)];
+
+ pr_debug("port_id %x sess %p\n", sess->port_id, sess);
+ hlist_add_head_rcu(&sess->hash, head);
+ tport->sess_count++;
+
+ return 0;
+}
+
/*
* Allocate session and enter it in the hash for the local port.
* Caller holds ft_lport_lock.
@@ -193,9 +207,10 @@ out:
static struct ft_sess *ft_sess_create(struct ft_tport *tport, u32 port_id,
struct fc_rport_priv *rdata)
{
+ struct se_portal_group *se_tpg = &tport->tpg->se_tpg;
struct ft_sess *sess;
- struct ft_node_acl *acl;
struct hlist_head *head;
+ unsigned char iname[TRANSPORT_IQN_LEN];
head = &tport->hash[ft_sess_hash(port_id)];
hlist_for_each_entry_rcu(sess, head, hash)
@@ -206,32 +221,20 @@ static struct ft_sess *ft_sess_create(struct ft_tport *tport, u32 port_id,
if (!sess)
return NULL;
- sess->se_sess = transport_init_session_tags(TCM_FC_DEFAULT_TAGS,
- sizeof(struct ft_cmd),
- TARGET_PROT_NORMAL);
- if (IS_ERR(sess->se_sess)) {
- kfree(sess);
- return NULL;
- }
+ kref_init(&sess->kref); /* ref for table entry */
+ sess->tport = tport;
+ sess->port_id = port_id;
+ ft_format_wwn(&iname[0], TRANSPORT_IQN_LEN, rdata->ids.port_name);
- acl = ft_acl_get(tport->tpg, rdata);
- if (!acl) {
- transport_free_session(sess->se_sess);
+ sess->se_sess = target_alloc_session(se_tpg, TCM_FC_DEFAULT_TAGS,
+ sizeof(struct ft_cmd),
+ TARGET_PROT_NORMAL, &iname[0],
+ sess, ft_sess_alloc_cb);
+ if (IS_ERR(sess->se_sess)) {
kfree(sess);
return NULL;
}
- sess->se_sess->se_node_acl = &acl->se_node_acl;
- sess->tport = tport;
- sess->port_id = port_id;
- kref_init(&sess->kref); /* ref for table entry */
- hlist_add_head_rcu(&sess->hash, head);
- tport->sess_count++;
-
- pr_debug("port_id %x sess %p\n", port_id, sess);
-
- transport_register_session(&tport->tpg->se_tpg, &acl->se_node_acl,
- sess->se_sess, sess);
return sess;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* [PATCH-for-4.6 6/6] ib_srpt: Convert to target_alloc_session usage
2016-01-10 20:44 [PATCH-for-4.6 0/6] target: Introduce target_alloc_session helper Nicholas A. Bellinger
` (4 preceding siblings ...)
2016-01-10 20:44 ` [PATCH-for-4.6 5/6] tcm_fc: " Nicholas A. Bellinger
@ 2016-01-10 20:44 ` Nicholas A. Bellinger
5 siblings, 0 replies; 15+ messages in thread
From: Nicholas A. Bellinger @ 2016-01-10 20:44 UTC (permalink / raw)
To: target-devel
Cc: linux-scsi, lkml, Sagi Grimberg, Christoph Hellwig,
Hannes Reinecke, Andy Grover, Vasu Dev, Vu Pham,
Nicholas Bellinger
From: Nicholas Bellinger <nab@linux-iscsi.org>
Cc: Vu Pham <vu@mellanox.com>
Cc: Sagi Grimberg <sagig@mellanox.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
---
drivers/infiniband/ulp/srpt/ib_srpt.c | 23 ++++++-----------------
1 file changed, 6 insertions(+), 17 deletions(-)
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index 2ef6466..44878a3 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -2387,7 +2387,6 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
struct srp_login_rej *rej;
struct ib_cm_rep_param *rep_param;
struct srpt_rdma_ch *ch, *tmp_ch;
- struct se_node_acl *se_acl;
u32 it_iu_len;
int i, ret = 0;
unsigned char *p;
@@ -2553,19 +2552,12 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id,
pr_debug("registering session %s\n", ch->sess_name);
p = &ch->sess_name[0];
- ch->sess = transport_init_session(TARGET_PROT_NORMAL);
- if (IS_ERR(ch->sess)) {
- rej->reason = cpu_to_be32(
- SRP_LOGIN_REJ_INSUFFICIENT_RESOURCES);
- pr_debug("Failed to create session\n");
- goto destroy_ib;
- }
-
try_again:
- se_acl = core_tpg_get_initiator_node_acl(&sport->port_tpg_1, p);
- if (!se_acl) {
+ ch->sess = target_alloc_session(&sport->port_tpg_1, 0, 0,
+ TARGET_PROT_NORMAL, p, ch, NULL);
+ if (IS_ERR(ch->sess)) {
pr_info("Rejected login because no ACL has been"
- " configured yet for initiator %s.\n", ch->sess_name);
+ " configured yet for initiator %s.\n", p);
/*
* XXX: Hack to retry of ch->i_port_id without leading '0x'
*/
@@ -2573,14 +2565,11 @@ try_again:
p += 2;
goto try_again;
}
- rej->reason = cpu_to_be32(
+ rej->reason = cpu_to_be32((PTR_ERR(ch->sess) == -ENOMEM) ?
+ SRP_LOGIN_REJ_INSUFFICIENT_RESOURCES :
SRP_LOGIN_REJ_CHANNEL_LIMIT_REACHED);
- transport_free_session(ch->sess);
goto destroy_ib;
}
- ch->sess->se_node_acl = se_acl;
-
- transport_register_session(&sport->port_tpg_1, se_acl, ch->sess, ch);
pr_debug("Establish connection sess=%p name=%s cm_id=%p\n", ch->sess,
ch->sess_name, ch->cm_id);
--
1.9.1
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH-for-4.6 3/6] vhost/scsi: Convert to target_alloc_session usage
2016-01-10 20:44 ` [PATCH-for-4.6 3/6] vhost/scsi: Convert to target_alloc_session usage Nicholas A. Bellinger
@ 2016-01-10 21:32 ` Michael S. Tsirkin
0 siblings, 0 replies; 15+ messages in thread
From: Michael S. Tsirkin @ 2016-01-10 21:32 UTC (permalink / raw)
To: Nicholas A. Bellinger
Cc: target-devel, linux-scsi, lkml, Sagi Grimberg, Christoph Hellwig,
Hannes Reinecke, Andy Grover, Vasu Dev, Vu Pham,
Nicholas Bellinger
On Sun, Jan 10, 2016 at 08:44:25PM +0000, Nicholas A. Bellinger wrote:
> From: Nicholas Bellinger <nab@linux-iscsi.org>
>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Pls merge this patch yourself to avoid dependency issues.
> ---
> drivers/vhost/scsi.c | 99 ++++++++++++++++++++++------------------------------
> 1 file changed, 41 insertions(+), 58 deletions(-)
>
> diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
> index 29cfc57..cd5f20f 100644
> --- a/drivers/vhost/scsi.c
> +++ b/drivers/vhost/scsi.c
> @@ -1664,8 +1664,7 @@ static void vhost_scsi_port_unlink(struct se_portal_group *se_tpg,
> mutex_unlock(&vhost_scsi_mutex);
> }
>
> -static void vhost_scsi_free_cmd_map_res(struct vhost_scsi_nexus *nexus,
> - struct se_session *se_sess)
> +static void vhost_scsi_free_cmd_map_res(struct se_session *se_sess)
> {
> struct vhost_scsi_cmd *tv_cmd;
> unsigned int i;
> @@ -1721,98 +1720,82 @@ static struct configfs_attribute *vhost_scsi_tpg_attrib_attrs[] = {
> NULL,
> };
>
> -static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
> - const char *name)
> +static int vhost_scsi_nexus_cb(struct se_portal_group *se_tpg,
> + struct se_session *se_sess, void *p)
> {
> - struct se_portal_group *se_tpg;
> - struct se_session *se_sess;
> - struct vhost_scsi_nexus *tv_nexus;
> struct vhost_scsi_cmd *tv_cmd;
> unsigned int i;
>
> - mutex_lock(&tpg->tv_tpg_mutex);
> - if (tpg->tpg_nexus) {
> - mutex_unlock(&tpg->tv_tpg_mutex);
> - pr_debug("tpg->tpg_nexus already exists\n");
> - return -EEXIST;
> - }
> - se_tpg = &tpg->se_tpg;
> -
> - tv_nexus = kzalloc(sizeof(struct vhost_scsi_nexus), GFP_KERNEL);
> - if (!tv_nexus) {
> - mutex_unlock(&tpg->tv_tpg_mutex);
> - pr_err("Unable to allocate struct vhost_scsi_nexus\n");
> - return -ENOMEM;
> - }
> - /*
> - * Initialize the struct se_session pointer and setup tagpool
> - * for struct vhost_scsi_cmd descriptors
> - */
> - tv_nexus->tvn_se_sess = transport_init_session_tags(
> - VHOST_SCSI_DEFAULT_TAGS,
> - sizeof(struct vhost_scsi_cmd),
> - TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS);
> - if (IS_ERR(tv_nexus->tvn_se_sess)) {
> - mutex_unlock(&tpg->tv_tpg_mutex);
> - kfree(tv_nexus);
> - return -ENOMEM;
> - }
> - se_sess = tv_nexus->tvn_se_sess;
> for (i = 0; i < VHOST_SCSI_DEFAULT_TAGS; i++) {
> tv_cmd = &((struct vhost_scsi_cmd *)se_sess->sess_cmd_map)[i];
>
> tv_cmd->tvc_sgl = kzalloc(sizeof(struct scatterlist) *
> VHOST_SCSI_PREALLOC_SGLS, GFP_KERNEL);
> if (!tv_cmd->tvc_sgl) {
> - mutex_unlock(&tpg->tv_tpg_mutex);
> pr_err("Unable to allocate tv_cmd->tvc_sgl\n");
> goto out;
> }
>
> tv_cmd->tvc_upages = kzalloc(sizeof(struct page *) *
> - VHOST_SCSI_PREALLOC_UPAGES, GFP_KERNEL);
> + VHOST_SCSI_PREALLOC_UPAGES, GFP_KERNEL);
> if (!tv_cmd->tvc_upages) {
> - mutex_unlock(&tpg->tv_tpg_mutex);
> pr_err("Unable to allocate tv_cmd->tvc_upages\n");
> goto out;
> }
>
> tv_cmd->tvc_prot_sgl = kzalloc(sizeof(struct scatterlist) *
> - VHOST_SCSI_PREALLOC_PROT_SGLS, GFP_KERNEL);
> + VHOST_SCSI_PREALLOC_PROT_SGLS, GFP_KERNEL);
> if (!tv_cmd->tvc_prot_sgl) {
> - mutex_unlock(&tpg->tv_tpg_mutex);
> pr_err("Unable to allocate tv_cmd->tvc_prot_sgl\n");
> goto out;
> }
> }
> + return 0;
> +out:
> + vhost_scsi_free_cmd_map_res(se_sess);
> + return -ENOMEM;
> +}
> +
> +static int vhost_scsi_make_nexus(struct vhost_scsi_tpg *tpg,
> + const char *name)
> +{
> + struct se_portal_group *se_tpg;
> + struct vhost_scsi_nexus *tv_nexus;
> +
> + mutex_lock(&tpg->tv_tpg_mutex);
> + if (tpg->tpg_nexus) {
> + mutex_unlock(&tpg->tv_tpg_mutex);
> + pr_debug("tpg->tpg_nexus already exists\n");
> + return -EEXIST;
> + }
> + se_tpg = &tpg->se_tpg;
> +
> + tv_nexus = kzalloc(sizeof(struct vhost_scsi_nexus), GFP_KERNEL);
> + if (!tv_nexus) {
> + mutex_unlock(&tpg->tv_tpg_mutex);
> + pr_err("Unable to allocate struct vhost_scsi_nexus\n");
> + return -ENOMEM;
> + }
> /*
> * Since we are running in 'demo mode' this call with generate a
> * struct se_node_acl for the vhost_scsi struct se_portal_group with
> * the SCSI Initiator port name of the passed configfs group 'name'.
> */
> - tv_nexus->tvn_se_sess->se_node_acl = core_tpg_check_initiator_node_acl(
> - se_tpg, (unsigned char *)name);
> - if (!tv_nexus->tvn_se_sess->se_node_acl) {
> + tv_nexus->tvn_se_sess = target_alloc_session(&tpg->se_tpg,
> + VHOST_SCSI_DEFAULT_TAGS,
> + sizeof(struct vhost_scsi_cmd),
> + TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS,
> + (unsigned char *)name, tv_nexus,
> + vhost_scsi_nexus_cb);
> + if (IS_ERR(tv_nexus->tvn_se_sess)) {
> mutex_unlock(&tpg->tv_tpg_mutex);
> - pr_debug("core_tpg_check_initiator_node_acl() failed"
> - " for %s\n", name);
> - goto out;
> + kfree(tv_nexus);
> + return -ENOMEM;
> }
> - /*
> - * Now register the TCM vhost virtual I_T Nexus as active.
> - */
> - transport_register_session(se_tpg, tv_nexus->tvn_se_sess->se_node_acl,
> - tv_nexus->tvn_se_sess, tv_nexus);
> tpg->tpg_nexus = tv_nexus;
>
> mutex_unlock(&tpg->tv_tpg_mutex);
> return 0;
> -
> -out:
> - vhost_scsi_free_cmd_map_res(tv_nexus, se_sess);
> - transport_free_session(se_sess);
> - kfree(tv_nexus);
> - return -ENOMEM;
> }
>
> static int vhost_scsi_drop_nexus(struct vhost_scsi_tpg *tpg)
> @@ -1853,7 +1836,7 @@ static int vhost_scsi_drop_nexus(struct vhost_scsi_tpg *tpg)
> " %s Initiator Port: %s\n", vhost_scsi_dump_proto_id(tpg->tport),
> tv_nexus->tvn_se_sess->se_node_acl->initiatorname);
>
> - vhost_scsi_free_cmd_map_res(tv_nexus, se_sess);
> + vhost_scsi_free_cmd_map_res(se_sess);
> /*
> * Release the SCSI I_T Nexus to the emulated vhost Target Port
> */
> --
> 1.9.1
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH-for-4.6 1/6] target: Add target_alloc_session() helper function
2016-01-10 20:44 ` [PATCH-for-4.6 1/6] target: Add target_alloc_session() helper function Nicholas A. Bellinger
@ 2016-01-11 22:10 ` Bart Van Assche
2016-01-12 15:11 ` Christoph Hellwig
1 sibling, 0 replies; 15+ messages in thread
From: Bart Van Assche @ 2016-01-11 22:10 UTC (permalink / raw)
To: Nicholas A. Bellinger, target-devel
Cc: linux-scsi, lkml, Sagi Grimberg, Christoph Hellwig,
Hannes Reinecke, Andy Grover, Vasu Dev, Vu Pham,
Nicholas Bellinger
On 01/10/2016 12:44 PM, Nicholas A. Bellinger wrote:
> From: Nicholas Bellinger <nab@linux-iscsi.org>
>
> Based on HCH's original patch, this adds a full version to
> support percpu-ida tag pre-allocation and callback function
> pointer into fabric driver code to complete session setup.
>
> Reported-by: Christoph Hellwig <hch@lst.de>
> Cc: Sagi Grimberg <sagig@mellanox.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Hannes Reinecke <hare@suse.de>
> Cc: Andy Grover <agrover@redhat.com>
> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
> ---
> drivers/target/target_core_transport.c | 55 ++++++++++++++++++++++++++++++++++
> include/target/target_core_fabric.h | 6 ++++
> 2 files changed, 61 insertions(+)
>
> diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
> index c5035b9..fd4404f6 100644
> --- a/drivers/target/target_core_transport.c
> +++ b/drivers/target/target_core_transport.c
> @@ -374,6 +374,61 @@ void transport_register_session(
> }
> EXPORT_SYMBOL(transport_register_session);
>
> +struct se_session *
> +target_alloc_session(struct se_portal_group *tpg,
> + unsigned int tag_num, unsigned int tag_size,
> + enum target_prot_op prot_op,
> + const char *initiatorname, void *private,
> + int (*callback)(struct se_portal_group *,
> + struct se_session *, void *))
Please use a more descriptive name instead of "callback", e.g.
"init_session".
> +{
> + struct se_session *sess;
> +
> + if (tag_num != 0 && !tag_size) {
> + pr_err("target_alloc_session called with percpu-ida tag_num:"
> + " %u, but zero tag_size\n", tag_num);
> + return ERR_PTR(-EINVAL);
> + }
> + if (!tag_num && tag_size) {
> + pr_err("target_alloc_session called with percpu-ida tag_size:"
> + " %u, but zero tag_num\n", tag_size);
> + return ERR_PTR(-EINVAL);
> + }
Please combine the above two tests into a single test, e.g. !!tag_num !=
!!tag_size or (bool)tag_num != (bool)tag_size.
Thanks,
Bart.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH-for-4.6 1/6] target: Add target_alloc_session() helper function
2016-01-10 20:44 ` [PATCH-for-4.6 1/6] target: Add target_alloc_session() helper function Nicholas A. Bellinger
2016-01-11 22:10 ` Bart Van Assche
@ 2016-01-12 15:11 ` Christoph Hellwig
2016-01-13 8:09 ` Nicholas A. Bellinger
1 sibling, 1 reply; 15+ messages in thread
From: Christoph Hellwig @ 2016-01-12 15:11 UTC (permalink / raw)
To: Nicholas A. Bellinger
Cc: target-devel, linux-scsi, lkml, Sagi Grimberg, Christoph Hellwig,
Hannes Reinecke, Andy Grover, Vasu Dev, Vu Pham,
Nicholas Bellinger
> +struct se_session *
> +target_alloc_session(struct se_portal_group *tpg,
> + unsigned int tag_num, unsigned int tag_size,
> + enum target_prot_op prot_op,
> + const char *initiatorname, void *private,
> + int (*callback)(struct se_portal_group *,
> + struct se_session *, void *))
> +{
I'd much rather have the fabrics drivers call transport_alloc_session_tags
directly from the callback than growing even more arguments here.
> + struct se_session *sess;
> +
> + if (tag_num != 0 && !tag_size) {
> + pr_err("target_alloc_session called with percpu-ida tag_num:"
> + " %u, but zero tag_size\n", tag_num);
> + return ERR_PTR(-EINVAL);
> + }
> + if (!tag_num && tag_size) {
> + pr_err("target_alloc_session called with percpu-ida tag_size:"
> + " %u, but zero tag_num\n", tag_size);
> + return ERR_PTR(-EINVAL);
> + }
These checks should be in transport_alloc_session_tags.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH-for-4.6 1/6] target: Add target_alloc_session() helper function
2016-01-12 15:11 ` Christoph Hellwig
@ 2016-01-13 8:09 ` Nicholas A. Bellinger
2016-01-13 8:17 ` Christoph Hellwig
0 siblings, 1 reply; 15+ messages in thread
From: Nicholas A. Bellinger @ 2016-01-13 8:09 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Nicholas A. Bellinger, target-devel, linux-scsi, lkml,
Sagi Grimberg, Hannes Reinecke, Andy Grover, Vasu Dev, Vu Pham
On Tue, 2016-01-12 at 16:11 +0100, Christoph Hellwig wrote:
> > +struct se_session *
> > +target_alloc_session(struct se_portal_group *tpg,
> > + unsigned int tag_num, unsigned int tag_size,
> > + enum target_prot_op prot_op,
> > + const char *initiatorname, void *private,
> > + int (*callback)(struct se_portal_group *,
> > + struct se_session *, void *))
> > +{
>
> I'd much rather have the fabrics drivers call transport_alloc_session_tags
> directly from the callback than growing even more arguments here.
>
What's the point..?
Only vhost-scsi currently needs to allocate extra resources for
se_session percpu-ida tag pre-allocation.
The rest of the consumers can just use this common code.
> > + struct se_session *sess;
> > +
> > + if (tag_num != 0 && !tag_size) {
> > + pr_err("target_alloc_session called with percpu-ida tag_num:"
> > + " %u, but zero tag_size\n", tag_num);
> > + return ERR_PTR(-EINVAL);
> > + }
> > + if (!tag_num && tag_size) {
> > + pr_err("target_alloc_session called with percpu-ida tag_size:"
> > + " %u, but zero tag_num\n", tag_size);
> > + return ERR_PTR(-EINVAL);
> > + }
>
> These checks should be in transport_alloc_session_tags.
>
Done.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH-for-4.6 1/6] target: Add target_alloc_session() helper function
2016-01-13 8:09 ` Nicholas A. Bellinger
@ 2016-01-13 8:17 ` Christoph Hellwig
2016-01-13 9:22 ` Nicholas A. Bellinger
0 siblings, 1 reply; 15+ messages in thread
From: Christoph Hellwig @ 2016-01-13 8:17 UTC (permalink / raw)
To: Nicholas A. Bellinger
Cc: Christoph Hellwig, Nicholas A. Bellinger, target-devel,
linux-scsi, lkml, Sagi Grimberg, Hannes Reinecke, Andy Grover,
Vasu Dev, Vu Pham
On Wed, Jan 13, 2016 at 12:09:26AM -0800, Nicholas A. Bellinger wrote:
> > I'd much rather have the fabrics drivers call transport_alloc_session_tags
> > directly from the callback than growing even more arguments here.
> >
>
> What's the point..?
>
> Only vhost-scsi currently needs to allocate extra resources for
> se_session percpu-ida tag pre-allocation.
The point is that allocating "tags" (or better command structures) isn't
fundamentally related to allocating a session, and in fact not even
used by many drivers. A flow where drivers that need these "tags"
explicitly allocate them is a lot more obvious than forcing more
arguments to a function that already has a lot and isn't related to
these "tags" otherwise.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH-for-4.6 1/6] target: Add target_alloc_session() helper function
2016-01-13 8:17 ` Christoph Hellwig
@ 2016-01-13 9:22 ` Nicholas A. Bellinger
2016-01-13 9:33 ` Christoph Hellwig
0 siblings, 1 reply; 15+ messages in thread
From: Nicholas A. Bellinger @ 2016-01-13 9:22 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Nicholas A. Bellinger, target-devel, linux-scsi, lkml,
Sagi Grimberg, Hannes Reinecke, Andy Grover, Vasu Dev, Vu Pham
On Wed, 2016-01-13 at 09:17 +0100, Christoph Hellwig wrote:
> On Wed, Jan 13, 2016 at 12:09:26AM -0800, Nicholas A. Bellinger wrote:
> > > I'd much rather have the fabrics drivers call transport_alloc_session_tags
> > > directly from the callback than growing even more arguments here.
> > >
> >
> > What's the point..?
> >
> > Only vhost-scsi currently needs to allocate extra resources for
> > se_session percpu-ida tag pre-allocation.
>
> The point is that allocating "tags" (or better command structures) isn't
> fundamentally related to allocating a session, and in fact not even
> used by many drivers.
Huh..? It's used by iscsi-target, ib_isert, tcm_qla2xxx, vhost-scsi and
tcm_fc.
That's the majority of the drivers people care about.
> A flow where drivers that need these "tags"
> explicitly allocate them is a lot more obvious than forcing more
> arguments to a function that already has a lot and isn't related to
> these "tags" otherwise.
The goal is to get to the point where all fabric drivers use tag
pre-allocation, and not vice-versa.
That said, I think it makes sense to leave it as is instead of adding
new callbacks for iscsi-target, ib_isert, and tcm_fc to just handle
se_session tag pre-allocation.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH-for-4.6 1/6] target: Add target_alloc_session() helper function
2016-01-13 9:22 ` Nicholas A. Bellinger
@ 2016-01-13 9:33 ` Christoph Hellwig
2016-01-13 10:14 ` Nicholas A. Bellinger
0 siblings, 1 reply; 15+ messages in thread
From: Christoph Hellwig @ 2016-01-13 9:33 UTC (permalink / raw)
To: Nicholas A. Bellinger
Cc: Christoph Hellwig, Nicholas A. Bellinger, target-devel,
linux-scsi, lkml, Sagi Grimberg, Hannes Reinecke, Andy Grover,
Vasu Dev, Vu Pham
On Wed, Jan 13, 2016 at 01:22:49AM -0800, Nicholas A. Bellinger wrote:
> Huh..? It's used by iscsi-target, ib_isert, tcm_qla2xxx, vhost-scsi and
> tcm_fc.
>
> That's the majority of the drivers people care about.
ib_isert never calls transport_init_session / transport_init_session_tags
directly.
We've got 3 callers to transport_init_session_tags vs 6 to
transport_init_session.
iSCSI already works roughly the way I suggest everything should
work in the future - it uses transport_init_session but manually
allocates the tags.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH-for-4.6 1/6] target: Add target_alloc_session() helper function
2016-01-13 9:33 ` Christoph Hellwig
@ 2016-01-13 10:14 ` Nicholas A. Bellinger
0 siblings, 0 replies; 15+ messages in thread
From: Nicholas A. Bellinger @ 2016-01-13 10:14 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Nicholas A. Bellinger, target-devel, linux-scsi, lkml,
Sagi Grimberg, Hannes Reinecke, Andy Grover, Vasu Dev, Vu Pham
On Wed, 2016-01-13 at 10:33 +0100, Christoph Hellwig wrote:
> On Wed, Jan 13, 2016 at 01:22:49AM -0800, Nicholas A. Bellinger wrote:
> > Huh..? It's used by iscsi-target, ib_isert, tcm_qla2xxx, vhost-scsi and
> > tcm_fc.
> >
> > That's the majority of the drivers people care about.
>
> ib_isert never calls transport_init_session / transport_init_session_tags
> directly.
>
Yes.
Not to mention, there is a new struct iscsit_transport based driver on
the way that assumes percpu-ida tag preallocation using this same
method.
> We've got 3 callers to transport_init_session_tags vs 6 to
> transport_init_session.
>
In that case, I'll look into converting sbp-target, usb-gadget and
xen-scsiback to use percpu-ida like the other consumers here for v4.6
code.
> iSCSI already works roughly the way I suggest everything should
> work in the future - it uses transport_init_session but manually
> allocates the tags.
iscsi-target needs it open-coded for discovery purposes, because
se_node_acl lookup does not occur.
However for the normal session login se_node_acl lookup back, I don't
see a reason why iscsi-target can't use target_alloc_session() here too.
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2016-01-13 10:14 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-10 20:44 [PATCH-for-4.6 0/6] target: Introduce target_alloc_session helper Nicholas A. Bellinger
2016-01-10 20:44 ` [PATCH-for-4.6 1/6] target: Add target_alloc_session() helper function Nicholas A. Bellinger
2016-01-11 22:10 ` Bart Van Assche
2016-01-12 15:11 ` Christoph Hellwig
2016-01-13 8:09 ` Nicholas A. Bellinger
2016-01-13 8:17 ` Christoph Hellwig
2016-01-13 9:22 ` Nicholas A. Bellinger
2016-01-13 9:33 ` Christoph Hellwig
2016-01-13 10:14 ` Nicholas A. Bellinger
2016-01-10 20:44 ` [PATCH-for-4.6 2/6] target: Convert demo-mode only drivers to target_alloc_session Nicholas A. Bellinger
2016-01-10 20:44 ` [PATCH-for-4.6 3/6] vhost/scsi: Convert to target_alloc_session usage Nicholas A. Bellinger
2016-01-10 21:32 ` Michael S. Tsirkin
2016-01-10 20:44 ` [PATCH-for-4.6 4/6] tcm_qla2xxx: " Nicholas A. Bellinger
2016-01-10 20:44 ` [PATCH-for-4.6 5/6] tcm_fc: " Nicholas A. Bellinger
2016-01-10 20:44 ` [PATCH-for-4.6 6/6] ib_srpt: " Nicholas A. Bellinger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).