]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
target: Drop unnecessary core_tpg_register TFO parameter
authorNicholas Bellinger <nab@linux-iscsi.org>
Thu, 21 May 2015 04:48:03 +0000 (21:48 -0700)
committerNicholas Bellinger <nab@linux-iscsi.org>
Tue, 16 Jun 2015 06:23:22 +0000 (23:23 -0700)
This patch drops unnecessary target_core_fabric_ops parameter usage
for core_tpg_register() during fabric driver TFO->fabric_make_tpg()
se_portal_group creation callback execution.

Instead, use the existing se_wwn->wwn_tf->tf_ops pointer to ensure
fabric driver is really using the same TFO provided at module_init
time.

Also go ahead and drop the forward TFO declarations tree-wide, and
handling the special case for iscsi-target discovery TPG.

Cc: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
12 files changed:
drivers/infiniband/ulp/srpt/ib_srpt.c
drivers/scsi/qla2xxx/tcm_qla2xxx.c
drivers/target/iscsi/iscsi_target_configfs.c
drivers/target/iscsi/iscsi_target_tpg.c
drivers/target/loopback/tcm_loop.c
drivers/target/sbp/sbp_target.c
drivers/target/target_core_tpg.c
drivers/target/tcm_fc/tfc_conf.c
drivers/usb/gadget/legacy/tcm_usb_gadget.c
drivers/vhost/scsi.c
drivers/xen/xen-scsiback.c
include/target/target_core_fabric.h

index dbad5c67a294def9204d3a190eb3d3882880e995..cea207e8b5d2a5d76346b07d906d2ce98e1f4bee 100644 (file)
@@ -92,7 +92,6 @@ MODULE_PARM_DESC(srpt_service_guid,
                 " instead of using the node_guid of the first HCA.");
 
 static struct ib_client srpt_client;
-static const struct target_core_fabric_ops srpt_template;
 static void srpt_release_channel(struct srpt_rdma_ch *ch);
 static int srpt_queue_status(struct se_cmd *cmd);
 
@@ -3733,8 +3732,7 @@ static struct se_portal_group *srpt_make_tpg(struct se_wwn *wwn,
        int res;
 
        /* Initialize sport->port_wwn and sport->port_tpg_1 */
-       res = core_tpg_register(&srpt_template, &sport->port_wwn,
-                       &sport->port_tpg_1, SCSI_PROTOCOL_SRP);
+       res = core_tpg_register(&sport->port_wwn, &sport->port_tpg_1, SCSI_PROTOCOL_SRP);
        if (res)
                return ERR_PTR(res);
 
index cb53144c72d0998cc5a5d0c9a99ae5670392ceff..e14a7fd7d8103d65cb7693ee8b48b0c01c92db9e 100644 (file)
@@ -52,9 +52,6 @@
 static struct workqueue_struct *tcm_qla2xxx_free_wq;
 static struct workqueue_struct *tcm_qla2xxx_cmd_wq;
 
-static const struct target_core_fabric_ops tcm_qla2xxx_ops;
-static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops;
-
 /*
  * Parse WWN.
  * If strict, we require lower-case hex and colon separators to be sure
@@ -1004,8 +1001,7 @@ static struct se_portal_group *tcm_qla2xxx_make_tpg(
        tpg->tpg_attrib.cache_dynamic_acls = 1;
        tpg->tpg_attrib.demo_mode_login_only = 1;
 
-       ret = core_tpg_register(&tcm_qla2xxx_ops, wwn, &tpg->se_tpg,
-                               SCSI_PROTOCOL_FCP);
+       ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_FCP);
        if (ret < 0) {
                kfree(tpg);
                return NULL;
@@ -1124,8 +1120,7 @@ static struct se_portal_group *tcm_qla2xxx_npiv_make_tpg(
        tpg->tpg_attrib.cache_dynamic_acls = 1;
        tpg->tpg_attrib.demo_mode_login_only = 1;
 
-       ret = core_tpg_register(&tcm_qla2xxx_npiv_ops, wwn, &tpg->se_tpg,
-                               SCSI_PROTOCOL_FCP);
+       ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_FCP);
        if (ret < 0) {
                kfree(tpg);
                return NULL;
index 523ae556e22cbba449de59f46b923b624c9e09d4..c1898c84b3d25e3630c012d97d9cfa6270e7d414 100644 (file)
@@ -1419,8 +1419,7 @@ static struct se_portal_group *lio_target_tiqn_addtpg(
        if (!tpg)
                return NULL;
 
-       ret = core_tpg_register(&iscsi_ops, wwn, &tpg->tpg_se_tpg,
-                               SCSI_PROTOCOL_ISCSI);
+       ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
        if (ret < 0)
                return NULL;
 
index de8829102ab4cd76bacc4e12ee66e8d4c4cb6d9d..968068ffcb1c87a7ce7d218f8faf0a900dbc517b 100644 (file)
@@ -66,8 +66,12 @@ int iscsit_load_discovery_tpg(void)
                pr_err("Unable to allocate struct iscsi_portal_group\n");
                return -1;
        }
-
-       ret = core_tpg_register(&iscsi_ops, NULL, &tpg->tpg_se_tpg, -1);
+       /*
+        * Save iscsi_ops pointer for special case discovery TPG that
+        * doesn't exist as se_wwn->wwn_group within configfs.
+        */
+       tpg->tpg_se_tpg.se_tpg_tfo = &iscsi_ops;
+       ret = core_tpg_register(NULL, &tpg->tpg_se_tpg, -1);
        if (ret < 0) {
                kfree(tpg);
                return -1;
index b0c17614493eead7e527de7c98a56707a7d0a35c..bd9d11a6f823d4bf1a759354cb70447c7a0f771e 100644 (file)
@@ -40,8 +40,6 @@
 
 #define to_tcm_loop_hba(hba)   container_of(hba, struct tcm_loop_hba, dev)
 
-static const struct target_core_fabric_ops loop_ops;
-
 static struct workqueue_struct *tcm_loop_workqueue;
 static struct kmem_cache *tcm_loop_cmd_cache;
 
@@ -1081,8 +1079,7 @@ static struct se_portal_group *tcm_loop_make_naa_tpg(
        /*
         * Register the tl_tpg as a emulated SAS TCM Target Endpoint
         */
-       ret = core_tpg_register(&loop_ops, wwn, &tl_tpg->tl_se_tpg,
-                               tl_hba->tl_proto_id);
+       ret = core_tpg_register(wwn, &tl_tpg->tl_se_tpg, tl_hba->tl_proto_id);
        if (ret < 0)
                return ERR_PTR(-ENOMEM);
 
index 28e3adf1eb853b121617aeb9d276a4adeb0b7071..42f82d32ca859062b93d375718605ec117494fef 100644 (file)
@@ -2055,7 +2055,7 @@ static struct se_portal_group *sbp_make_tpg(
                goto out_free_tpg;
        }
 
-       ret = core_tpg_register(&sbp_ops, wwn, &tpg->se_tpg, SCSI_PROTOCOL_SBP);
+       ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_SBP);
        if (ret < 0)
                goto out_unreg_mgt_agt;
 
index b9fcf2c4898ea023252a3a9e4f0f720ad8e1c5fe..2e77eebe167122069c15c94960054202e6a446c9 100644 (file)
@@ -37,6 +37,7 @@
 
 #include <target/target_core_base.h>
 #include <target/target_core_backend.h>
+#include <target/target_core_configfs.h>
 #include <target/target_core_fabric.h>
 
 #include "target_core_internal.h"
@@ -487,16 +488,34 @@ static void core_tpg_lun_ref_release(struct percpu_ref *ref)
 }
 
 int core_tpg_register(
-       const struct target_core_fabric_ops *tfo,
        struct se_wwn *se_wwn,
        struct se_portal_group *se_tpg,
        int proto_id)
 {
        int ret;
 
+       if (!se_tpg)
+               return -EINVAL;
+       /*
+        * For the typical case where core_tpg_register() is called by a
+        * fabric driver from target_core_fabric_ops->fabric_make_tpg()
+        * configfs context, use the original tf_ops pointer already saved
+        * by target-core in target_fabric_make_wwn().
+        *
+        * Otherwise, for special cases like iscsi-target discovery TPGs
+        * the caller is responsible for setting ->se_tpg_tfo ahead of
+        * calling core_tpg_register().
+        */
+       if (se_wwn)
+               se_tpg->se_tpg_tfo = se_wwn->wwn_tf->tf_ops;
+
+       if (!se_tpg->se_tpg_tfo) {
+               pr_err("Unable to locate se_tpg->se_tpg_tfo pointer\n");
+               return -EINVAL;
+       }
+
        INIT_HLIST_HEAD(&se_tpg->tpg_lun_hlist);
        se_tpg->proto_id = proto_id;
-       se_tpg->se_tpg_tfo = tfo;
        se_tpg->se_tpg_wwn = se_wwn;
        atomic_set(&se_tpg->tpg_pr_ref_count, 0);
        INIT_LIST_HEAD(&se_tpg->acl_node_list);
@@ -524,9 +543,10 @@ int core_tpg_register(
        spin_unlock_bh(&tpg_lock);
 
        pr_debug("TARGET_CORE[%s]: Allocated portal_group for endpoint: %s, "
-                "Proto: %d, Portal Tag: %u\n", tfo->get_fabric_name(),
-               tfo->tpg_get_wwn(se_tpg) ? tfo->tpg_get_wwn(se_tpg) : NULL,
-               se_tpg->proto_id, tfo->tpg_get_tag(se_tpg));
+                "Proto: %d, Portal Tag: %u\n", se_tpg->se_tpg_tfo->get_fabric_name(),
+               se_tpg->se_tpg_tfo->tpg_get_wwn(se_tpg) ?
+               se_tpg->se_tpg_tfo->tpg_get_wwn(se_tpg) : NULL,
+               se_tpg->proto_id, se_tpg->se_tpg_tfo->tpg_get_tag(se_tpg));
 
        return 0;
 }
index 8e1a54f2642cb65054a6f41075b2c0c903147da2..80a4477fa7ee135a503345cc5f618dd66975931a 100644 (file)
@@ -47,8 +47,6 @@
 
 #include "tcm_fc.h"
 
-static const struct target_core_fabric_ops ft_fabric_ops;
-
 static LIST_HEAD(ft_wwn_list);
 DEFINE_MUTEX(ft_lport_lock);
 
@@ -282,8 +280,7 @@ static struct se_portal_group *ft_add_tpg(
                return NULL;
        }
 
-       ret = core_tpg_register(&ft_fabric_ops, wwn, &tpg->se_tpg,
-                               SCSI_PROTOCOL_FCP);
+       ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_FCP);
        if (ret < 0) {
                destroy_workqueue(wq);
                kfree(tpg);
index 16b9a16678fe58375bd56d343fa14f41af27a187..4ff426edf22a0cf39875d8444214b8bb2e116115 100644 (file)
@@ -28,8 +28,6 @@
 
 USB_GADGET_COMPOSITE_OPTIONS();
 
-static const struct target_core_fabric_ops usbg_ops;
-
 static inline struct f_uas *to_f_uas(struct usb_function *f)
 {
        return container_of(f, struct f_uas, function);
@@ -1418,8 +1416,7 @@ static struct se_portal_group *usbg_make_tpg(
         * SPC doesn't assign a protocol identifier for USB-SCSI, so we
         * pretend to be SAS..
         */
-       ret = core_tpg_register(&usbg_ops, wwn, &tpg->se_tpg,
-                               SCSI_PROTOCOL_SAS);
+       ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_SAS);
        if (ret < 0) {
                destroy_workqueue(tpg->workqueue);
                kfree(tpg);
index dcd228b59ded37d8edd03d1cad348dbd5921d62c..450aece0227c2738a8cc4848f3d3868b290c3e5e 100644 (file)
@@ -206,7 +206,6 @@ struct vhost_scsi {
        int vs_events_nr; /* num of pending events, protected by vq->mutex */
 };
 
-static struct target_core_fabric_ops vhost_scsi_ops;
 static struct workqueue_struct *vhost_scsi_workqueue;
 
 /* Global spinlock to protect vhost_scsi TPG list for vhost IOCTL access */
@@ -2001,8 +2000,7 @@ vhost_scsi_make_tpg(struct se_wwn *wwn,
        tpg->tport = tport;
        tpg->tport_tpgt = tpgt;
 
-       ret = core_tpg_register(&vhost_scsi_ops, wwn, &tpg->se_tpg,
-                               tport->tport_proto_id);
+       ret = core_tpg_register(wwn, &tpg->se_tpg, tport->tport_proto_id);
        if (ret < 0) {
                kfree(tpg);
                return NULL;
index 555033bd92391dbbd45dd7b6caa40fd9f1b6aa4a..25144a0ff07cbad45bd00828c419a4b9dd4f63cd 100644 (file)
@@ -203,8 +203,6 @@ static LIST_HEAD(scsiback_free_pages);
 static DEFINE_MUTEX(scsiback_mutex);
 static LIST_HEAD(scsiback_list);
 
-static const struct target_core_fabric_ops scsiback_ops;
-
 static void scsiback_get(struct vscsibk_info *info)
 {
        atomic_inc(&info->nr_unreplied_reqs);
@@ -1765,8 +1763,7 @@ scsiback_make_tpg(struct se_wwn *wwn,
        tpg->tport = tport;
        tpg->tport_tpgt = tpgt;
 
-       ret = core_tpg_register(&scsiback_ops, wwn, &tpg->se_tpg,
-                               tport->tport_proto_id);
+       ret = core_tpg_register(wwn, &tpg->se_tpg, tport->tport_proto_id);
        if (ret < 0) {
                kfree(tpg);
                return NULL;
index b1e00a7d66de066c663bad770ed42bd440598e05..d6216b7613338dd783897a6ae0947222b3854da3 100644 (file)
@@ -161,8 +161,7 @@ int core_tpg_set_initiator_node_queue_depth(struct se_portal_group *,
                unsigned char *, u32, int);
 int    core_tpg_set_initiator_node_tag(struct se_portal_group *,
                struct se_node_acl *, const char *);
-int    core_tpg_register(const struct target_core_fabric_ops *,
-               struct se_wwn *, struct se_portal_group *, int);
+int    core_tpg_register(struct se_wwn *, struct se_portal_group *, int);
 int    core_tpg_deregister(struct se_portal_group *);
 
 /*