aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2015-04-08 14:01:35 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2015-04-14 15:28:41 -0400
commit9ac8928e6a3e1ed02e632e45aa766129fe6b1802 (patch)
treeea516680cc5f811df862966bb43cfbe3e34dfb26
parent2c336e3a2e1728d9b3116422655832184dc7046c (diff)
target: simplify the target template registration API
Instead of calling target_fabric_configfs_init() + target_fabric_configfs_register() / target_fabric_configfs_deregister() target_fabric_configfs_free() from every target driver, rewrite the API so that we have simple register/unregister functions that operate on a const operations vector. This patch also fixes a memory leak in several target drivers. Several target drivers namely called target_fabric_configfs_deregister() without calling target_fabric_configfs_free(). A large part of this patch is based on earlier changes from Bart Van Assche <bart.vanassche@sandisk.com>. (v2: Add a new TF_CIT_SETUP_DRV macro so that the core configfs code can declare attributes as either core only or for drivers) Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
-rwxr-xr-xDocumentation/target/tcm_mod_builder.py79
-rw-r--r--drivers/infiniband/ulp/srpt/ib_srpt.c49
-rw-r--r--drivers/scsi/qla2xxx/qla_target.c2
-rw-r--r--drivers/scsi/qla2xxx/tcm_qla2xxx.c118
-rw-r--r--drivers/target/iscsi/iscsi_target.c23
-rw-r--r--drivers/target/iscsi/iscsi_target.h2
-rw-r--r--drivers/target/iscsi/iscsi_target_configfs.c180
-rw-r--r--drivers/target/iscsi/iscsi_target_configfs.h7
-rw-r--r--drivers/target/iscsi/iscsi_target_tpg.c6
-rw-r--r--drivers/target/loopback/tcm_loop.c178
-rw-r--r--drivers/target/sbp/sbp_target.c68
-rw-r--r--drivers/target/target_core_configfs.c176
-rw-r--r--drivers/target/target_core_fabric_configfs.c38
-rw-r--r--drivers/target/target_core_pr.c16
-rw-r--r--drivers/target/target_core_tpg.c2
-rw-r--r--drivers/target/target_core_transport.c6
-rw-r--r--drivers/target/target_core_xcopy.c2
-rw-r--r--drivers/target/tcm_fc/tcm_fc.h1
-rw-r--r--drivers/target/tcm_fc/tfc_conf.c89
-rw-r--r--drivers/usb/gadget/legacy/tcm_usb_gadget.c57
-rw-r--r--drivers/vhost/scsi.c76
-rw-r--r--drivers/xen/xen-scsiback.c74
-rw-r--r--include/target/target_core_base.h4
-rw-r--r--include/target/target_core_configfs.h6
-rw-r--r--include/target/target_core_fabric.h24
25 files changed, 356 insertions, 927 deletions
diff --git a/Documentation/target/tcm_mod_builder.py b/Documentation/target/tcm_mod_builder.py
index 2b47704f75cb..27afc033761f 100755
--- a/Documentation/target/tcm_mod_builder.py
+++ b/Documentation/target/tcm_mod_builder.py
@@ -237,8 +237,7 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
237 buf += "#include \"" + fabric_mod_name + "_base.h\"\n" 237 buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
238 buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n" 238 buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
239 239
240 buf += "/* Local pointer to allocated TCM configfs fabric module */\n" 240 buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops;\n\n"
241 buf += "struct target_fabric_configfs *" + fabric_mod_name + "_fabric_configfs;\n\n"
242 241
243 buf += "static struct se_node_acl *" + fabric_mod_name + "_make_nodeacl(\n" 242 buf += "static struct se_node_acl *" + fabric_mod_name + "_make_nodeacl(\n"
244 buf += " struct se_portal_group *se_tpg,\n" 243 buf += " struct se_portal_group *se_tpg,\n"
@@ -309,8 +308,8 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
309 buf += " }\n" 308 buf += " }\n"
310 buf += " tpg->" + fabric_mod_port + " = " + fabric_mod_port + ";\n" 309 buf += " tpg->" + fabric_mod_port + " = " + fabric_mod_port + ";\n"
311 buf += " tpg->" + fabric_mod_port + "_tpgt = tpgt;\n\n" 310 buf += " tpg->" + fabric_mod_port + "_tpgt = tpgt;\n\n"
312 buf += " ret = core_tpg_register(&" + fabric_mod_name + "_fabric_configfs->tf_ops, wwn,\n" 311 buf += " ret = core_tpg_register(&" + fabric_mod_name + "_ops, wwn,\n"
313 buf += " &tpg->se_tpg, (void *)tpg,\n" 312 buf += " &tpg->se_tpg, tpg,\n"
314 buf += " TRANSPORT_TPG_TYPE_NORMAL);\n" 313 buf += " TRANSPORT_TPG_TYPE_NORMAL);\n"
315 buf += " if (ret < 0) {\n" 314 buf += " if (ret < 0) {\n"
316 buf += " kfree(tpg);\n" 315 buf += " kfree(tpg);\n"
@@ -370,7 +369,10 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
370 buf += " NULL,\n" 369 buf += " NULL,\n"
371 buf += "};\n\n" 370 buf += "};\n\n"
372 371
373 buf += "static struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n" 372 buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n"
373 buf += " .module = THIS_MODULE\n",
374 buf += " .name = " + fabric_mod_name + ",\n"
375 buf += " .get_fabric_proto_ident = " + fabric_mod_name + "_get_fabric_proto_ident,\n"
374 buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n" 376 buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n"
375 buf += " .get_fabric_proto_ident = " + fabric_mod_name + "_get_fabric_proto_ident,\n" 377 buf += " .get_fabric_proto_ident = " + fabric_mod_name + "_get_fabric_proto_ident,\n"
376 buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n" 378 buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n"
@@ -413,75 +415,18 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
413 buf += " .fabric_drop_np = NULL,\n" 415 buf += " .fabric_drop_np = NULL,\n"
414 buf += " .fabric_make_nodeacl = " + fabric_mod_name + "_make_nodeacl,\n" 416 buf += " .fabric_make_nodeacl = " + fabric_mod_name + "_make_nodeacl,\n"
415 buf += " .fabric_drop_nodeacl = " + fabric_mod_name + "_drop_nodeacl,\n" 417 buf += " .fabric_drop_nodeacl = " + fabric_mod_name + "_drop_nodeacl,\n"
416 buf += "};\n\n" 418 buf += "\n"
417 419 buf += " .tfc_wwn_attrs = " + fabric_mod_name + "_wwn_attrs;\n"
418 buf += "static int " + fabric_mod_name + "_register_configfs(void)\n"
419 buf += "{\n"
420 buf += " struct target_fabric_configfs *fabric;\n"
421 buf += " int ret;\n\n"
422 buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"
423 buf += " \" on \"UTS_RELEASE\"\\n\"," + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"
424 buf += " utsname()->machine);\n"
425 buf += " /*\n"
426 buf += " * Register the top level struct config_item_type with TCM core\n"
427 buf += " */\n"
428 buf += " fabric = target_fabric_configfs_init(THIS_MODULE, \"" + fabric_mod_name + "\");\n"
429 buf += " if (IS_ERR(fabric)) {\n"
430 buf += " printk(KERN_ERR \"target_fabric_configfs_init() failed\\n\");\n"
431 buf += " return PTR_ERR(fabric);\n"
432 buf += " }\n"
433 buf += " /*\n"
434 buf += " * Setup fabric->tf_ops from our local " + fabric_mod_name + "_ops\n"
435 buf += " */\n"
436 buf += " fabric->tf_ops = " + fabric_mod_name + "_ops;\n"
437 buf += " /*\n"
438 buf += " * Setup default attribute lists for various fabric->tf_cit_tmpl\n"
439 buf += " */\n"
440 buf += " fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = " + fabric_mod_name + "_wwn_attrs;\n"
441 buf += " fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = NULL;\n"
442 buf += " fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL;\n"
443 buf += " fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;\n"
444 buf += " fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;\n"
445 buf += " fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL;\n"
446 buf += " fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;\n"
447 buf += " fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL;\n"
448 buf += " fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL;\n"
449 buf += " /*\n"
450 buf += " * Register the fabric for use within TCM\n"
451 buf += " */\n"
452 buf += " ret = target_fabric_configfs_register(fabric);\n"
453 buf += " if (ret < 0) {\n"
454 buf += " printk(KERN_ERR \"target_fabric_configfs_register() failed\"\n"
455 buf += " \" for " + fabric_mod_name.upper() + "\\n\");\n"
456 buf += " return ret;\n"
457 buf += " }\n"
458 buf += " /*\n"
459 buf += " * Setup our local pointer to *fabric\n"
460 buf += " */\n"
461 buf += " " + fabric_mod_name + "_fabric_configfs = fabric;\n"
462 buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + "[0] - Set fabric -> " + fabric_mod_name + "_fabric_configfs\\n\");\n"
463 buf += " return 0;\n"
464 buf += "};\n\n"
465 buf += "static void __exit " + fabric_mod_name + "_deregister_configfs(void)\n"
466 buf += "{\n"
467 buf += " if (!" + fabric_mod_name + "_fabric_configfs)\n"
468 buf += " return;\n\n"
469 buf += " target_fabric_configfs_deregister(" + fabric_mod_name + "_fabric_configfs);\n"
470 buf += " " + fabric_mod_name + "_fabric_configfs = NULL;\n"
471 buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + "[0] - Cleared " + fabric_mod_name + "_fabric_configfs\\n\");\n"
472 buf += "};\n\n" 420 buf += "};\n\n"
473 421
474 buf += "static int __init " + fabric_mod_name + "_init(void)\n" 422 buf += "static int __init " + fabric_mod_name + "_init(void)\n"
475 buf += "{\n" 423 buf += "{\n"
476 buf += " int ret;\n\n" 424 buf += " return target_register_template(" + fabric_mod_name + "_ops);\n"
477 buf += " ret = " + fabric_mod_name + "_register_configfs();\n"
478 buf += " if (ret < 0)\n"
479 buf += " return ret;\n\n"
480 buf += " return 0;\n"
481 buf += "};\n\n" 425 buf += "};\n\n"
426
482 buf += "static void __exit " + fabric_mod_name + "_exit(void)\n" 427 buf += "static void __exit " + fabric_mod_name + "_exit(void)\n"
483 buf += "{\n" 428 buf += "{\n"
484 buf += " " + fabric_mod_name + "_deregister_configfs();\n" 429 buf += " target_unregister_template(" + fabric_mod_name + "_ops);\n"
485 buf += "};\n\n" 430 buf += "};\n\n"
486 431
487 buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n" 432 buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n"
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index 6e0a477681e9..07015389ee5a 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -93,7 +93,7 @@ MODULE_PARM_DESC(srpt_service_guid,
93 " instead of using the node_guid of the first HCA."); 93 " instead of using the node_guid of the first HCA.");
94 94
95static struct ib_client srpt_client; 95static struct ib_client srpt_client;
96static struct target_fabric_configfs *srpt_target; 96static const struct target_core_fabric_ops srpt_template;
97static void srpt_release_channel(struct srpt_rdma_ch *ch); 97static void srpt_release_channel(struct srpt_rdma_ch *ch);
98static int srpt_queue_status(struct se_cmd *cmd); 98static int srpt_queue_status(struct se_cmd *cmd);
99 99
@@ -3851,7 +3851,7 @@ static struct se_portal_group *srpt_make_tpg(struct se_wwn *wwn,
3851 int res; 3851 int res;
3852 3852
3853 /* Initialize sport->port_wwn and sport->port_tpg_1 */ 3853 /* Initialize sport->port_wwn and sport->port_tpg_1 */
3854 res = core_tpg_register(&srpt_target->tf_ops, &sport->port_wwn, 3854 res = core_tpg_register(&srpt_template, &sport->port_wwn,
3855 &sport->port_tpg_1, sport, TRANSPORT_TPG_TYPE_NORMAL); 3855 &sport->port_tpg_1, sport, TRANSPORT_TPG_TYPE_NORMAL);
3856 if (res) 3856 if (res)
3857 return ERR_PTR(res); 3857 return ERR_PTR(res);
@@ -3919,7 +3919,9 @@ static struct configfs_attribute *srpt_wwn_attrs[] = {
3919 NULL, 3919 NULL,
3920}; 3920};
3921 3921
3922static struct target_core_fabric_ops srpt_template = { 3922static const struct target_core_fabric_ops srpt_template = {
3923 .module = THIS_MODULE,
3924 .name = "srpt",
3923 .get_fabric_name = srpt_get_fabric_name, 3925 .get_fabric_name = srpt_get_fabric_name,
3924 .get_fabric_proto_ident = srpt_get_fabric_proto_ident, 3926 .get_fabric_proto_ident = srpt_get_fabric_proto_ident,
3925 .tpg_get_wwn = srpt_get_fabric_wwn, 3927 .tpg_get_wwn = srpt_get_fabric_wwn,
@@ -3964,6 +3966,10 @@ static struct target_core_fabric_ops srpt_template = {
3964 .fabric_drop_np = NULL, 3966 .fabric_drop_np = NULL,
3965 .fabric_make_nodeacl = srpt_make_nodeacl, 3967 .fabric_make_nodeacl = srpt_make_nodeacl,
3966 .fabric_drop_nodeacl = srpt_drop_nodeacl, 3968 .fabric_drop_nodeacl = srpt_drop_nodeacl,
3969
3970 .tfc_wwn_attrs = srpt_wwn_attrs,
3971 .tfc_tpg_base_attrs = srpt_tpg_attrs,
3972 .tfc_tpg_attrib_attrs = srpt_tpg_attrib_attrs,
3967}; 3973};
3968 3974
3969/** 3975/**
@@ -3994,33 +4000,9 @@ static int __init srpt_init_module(void)
3994 goto out; 4000 goto out;
3995 } 4001 }
3996 4002
3997 srpt_target = target_fabric_configfs_init(THIS_MODULE, "srpt"); 4003 ret = target_register_template(&srpt_template);
3998 if (IS_ERR(srpt_target)) { 4004 if (ret)
3999 printk(KERN_ERR "couldn't register\n");
4000 ret = PTR_ERR(srpt_target);
4001 goto out; 4005 goto out;
4002 }
4003
4004 srpt_target->tf_ops = srpt_template;
4005
4006 /*
4007 * Set up default attribute lists.
4008 */
4009 srpt_target->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = srpt_wwn_attrs;
4010 srpt_target->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = srpt_tpg_attrs;
4011 srpt_target->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = srpt_tpg_attrib_attrs;
4012 srpt_target->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
4013 srpt_target->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
4014 srpt_target->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL;
4015 srpt_target->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
4016 srpt_target->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
4017 srpt_target->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL;
4018
4019 ret = target_fabric_configfs_register(srpt_target);
4020 if (ret < 0) {
4021 printk(KERN_ERR "couldn't register\n");
4022 goto out_free_target;
4023 }
4024 4006
4025 ret = ib_register_client(&srpt_client); 4007 ret = ib_register_client(&srpt_client);
4026 if (ret) { 4008 if (ret) {
@@ -4031,11 +4013,7 @@ static int __init srpt_init_module(void)
4031 return 0; 4013 return 0;
4032 4014
4033out_unregister_target: 4015out_unregister_target:
4034 target_fabric_configfs_deregister(srpt_target); 4016 target_unregister_template(&srpt_template);
4035 srpt_target = NULL;
4036out_free_target:
4037 if (srpt_target)
4038 target_fabric_configfs_free(srpt_target);
4039out: 4017out:
4040 return ret; 4018 return ret;
4041} 4019}
@@ -4043,8 +4021,7 @@ out:
4043static void __exit srpt_cleanup_module(void) 4021static void __exit srpt_cleanup_module(void)
4044{ 4022{
4045 ib_unregister_client(&srpt_client); 4023 ib_unregister_client(&srpt_client);
4046 target_fabric_configfs_deregister(srpt_target); 4024 target_unregister_template(&srpt_template);
4047 srpt_target = NULL;
4048} 4025}
4049 4026
4050module_init(srpt_init_module); 4027module_init(srpt_init_module);
diff --git a/drivers/scsi/qla2xxx/qla_target.c b/drivers/scsi/qla2xxx/qla_target.c
index 57418258c101..fe8a8d157e22 100644
--- a/drivers/scsi/qla2xxx/qla_target.c
+++ b/drivers/scsi/qla2xxx/qla_target.c
@@ -3065,7 +3065,7 @@ static void qlt_do_ctio_completion(struct scsi_qla_host *vha, uint32_t handle,
3065{ 3065{
3066 struct qla_hw_data *ha = vha->hw; 3066 struct qla_hw_data *ha = vha->hw;
3067 struct se_cmd *se_cmd; 3067 struct se_cmd *se_cmd;
3068 struct target_core_fabric_ops *tfo; 3068 const struct target_core_fabric_ops *tfo;
3069 struct qla_tgt_cmd *cmd; 3069 struct qla_tgt_cmd *cmd;
3070 3070
3071 if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) { 3071 if (handle & CTIO_INTERMEDIATE_HANDLE_MARK) {
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index 843b53b0e9f2..acf54cdbca2c 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -53,9 +53,8 @@
53static struct workqueue_struct *tcm_qla2xxx_free_wq; 53static struct workqueue_struct *tcm_qla2xxx_free_wq;
54static struct workqueue_struct *tcm_qla2xxx_cmd_wq; 54static struct workqueue_struct *tcm_qla2xxx_cmd_wq;
55 55
56/* Local pointer to allocated TCM configfs fabric module */ 56static const struct target_core_fabric_ops tcm_qla2xxx_ops;
57static struct target_fabric_configfs *tcm_qla2xxx_fabric_configfs; 57static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops;
58static struct target_fabric_configfs *tcm_qla2xxx_npiv_fabric_configfs;
59 58
60/* 59/*
61 * Parse WWN. 60 * Parse WWN.
@@ -1177,7 +1176,7 @@ static struct se_portal_group *tcm_qla2xxx_make_tpg(
1177 tpg->tpg_attrib.cache_dynamic_acls = 1; 1176 tpg->tpg_attrib.cache_dynamic_acls = 1;
1178 tpg->tpg_attrib.demo_mode_login_only = 1; 1177 tpg->tpg_attrib.demo_mode_login_only = 1;
1179 1178
1180 ret = core_tpg_register(&tcm_qla2xxx_fabric_configfs->tf_ops, wwn, 1179 ret = core_tpg_register(&tcm_qla2xxx_ops, wwn,
1181 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL); 1180 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL);
1182 if (ret < 0) { 1181 if (ret < 0) {
1183 kfree(tpg); 1182 kfree(tpg);
@@ -1297,7 +1296,7 @@ static struct se_portal_group *tcm_qla2xxx_npiv_make_tpg(
1297 tpg->tpg_attrib.cache_dynamic_acls = 1; 1296 tpg->tpg_attrib.cache_dynamic_acls = 1;
1298 tpg->tpg_attrib.demo_mode_login_only = 1; 1297 tpg->tpg_attrib.demo_mode_login_only = 1;
1299 1298
1300 ret = core_tpg_register(&tcm_qla2xxx_npiv_fabric_configfs->tf_ops, wwn, 1299 ret = core_tpg_register(&tcm_qla2xxx_npiv_ops, wwn,
1301 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL); 1300 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL);
1302 if (ret < 0) { 1301 if (ret < 0) {
1303 kfree(tpg); 1302 kfree(tpg);
@@ -1987,7 +1986,9 @@ static struct configfs_attribute *tcm_qla2xxx_wwn_attrs[] = {
1987 NULL, 1986 NULL,
1988}; 1987};
1989 1988
1990static struct target_core_fabric_ops tcm_qla2xxx_ops = { 1989static const struct target_core_fabric_ops tcm_qla2xxx_ops = {
1990 .module = THIS_MODULE,
1991 .name = "qla2xxx",
1991 .get_fabric_name = tcm_qla2xxx_get_fabric_name, 1992 .get_fabric_name = tcm_qla2xxx_get_fabric_name,
1992 .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident, 1993 .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident,
1993 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn, 1994 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn,
@@ -2037,9 +2038,15 @@ static struct target_core_fabric_ops tcm_qla2xxx_ops = {
2037 .fabric_drop_np = NULL, 2038 .fabric_drop_np = NULL,
2038 .fabric_make_nodeacl = tcm_qla2xxx_make_nodeacl, 2039 .fabric_make_nodeacl = tcm_qla2xxx_make_nodeacl,
2039 .fabric_drop_nodeacl = tcm_qla2xxx_drop_nodeacl, 2040 .fabric_drop_nodeacl = tcm_qla2xxx_drop_nodeacl,
2041
2042 .tfc_wwn_attrs = tcm_qla2xxx_wwn_attrs,
2043 .tfc_tpg_base_attrs = tcm_qla2xxx_tpg_attrs,
2044 .tfc_tpg_attrib_attrs = tcm_qla2xxx_tpg_attrib_attrs,
2040}; 2045};
2041 2046
2042static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = { 2047static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = {
2048 .module = THIS_MODULE,
2049 .name = "qla2xxx_npiv",
2043 .get_fabric_name = tcm_qla2xxx_npiv_get_fabric_name, 2050 .get_fabric_name = tcm_qla2xxx_npiv_get_fabric_name,
2044 .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident, 2051 .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident,
2045 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn, 2052 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn,
@@ -2087,94 +2094,26 @@ static struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = {
2087 .fabric_drop_np = NULL, 2094 .fabric_drop_np = NULL,
2088 .fabric_make_nodeacl = tcm_qla2xxx_make_nodeacl, 2095 .fabric_make_nodeacl = tcm_qla2xxx_make_nodeacl,
2089 .fabric_drop_nodeacl = tcm_qla2xxx_drop_nodeacl, 2096 .fabric_drop_nodeacl = tcm_qla2xxx_drop_nodeacl,
2097
2098 .tfc_wwn_attrs = tcm_qla2xxx_wwn_attrs,
2099 .tfc_tpg_base_attrs = tcm_qla2xxx_npiv_tpg_attrs,
2090}; 2100};
2091 2101
2092static int tcm_qla2xxx_register_configfs(void) 2102static int tcm_qla2xxx_register_configfs(void)
2093{ 2103{
2094 struct target_fabric_configfs *fabric, *npiv_fabric;
2095 int ret; 2104 int ret;
2096 2105
2097 pr_debug("TCM QLOGIC QLA2XXX fabric module %s on %s/%s on " 2106 pr_debug("TCM QLOGIC QLA2XXX fabric module %s on %s/%s on "
2098 UTS_RELEASE"\n", TCM_QLA2XXX_VERSION, utsname()->sysname, 2107 UTS_RELEASE"\n", TCM_QLA2XXX_VERSION, utsname()->sysname,
2099 utsname()->machine); 2108 utsname()->machine);
2100 /* 2109
2101 * Register the top level struct config_item_type with TCM core 2110 ret = target_register_template(&tcm_qla2xxx_ops);
2102 */ 2111 if (ret)
2103 fabric = target_fabric_configfs_init(THIS_MODULE, "qla2xxx");
2104 if (IS_ERR(fabric)) {
2105 pr_err("target_fabric_configfs_init() failed\n");
2106 return PTR_ERR(fabric);
2107 }
2108 /*
2109 * Setup fabric->tf_ops from our local tcm_qla2xxx_ops
2110 */
2111 fabric->tf_ops = tcm_qla2xxx_ops;
2112 /*
2113 * Setup default attribute lists for various fabric->tf_cit_tmpl
2114 */
2115 fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_qla2xxx_wwn_attrs;
2116 fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = tcm_qla2xxx_tpg_attrs;
2117 fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs =
2118 tcm_qla2xxx_tpg_attrib_attrs;
2119 fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
2120 fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
2121 fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL;
2122 fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
2123 fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
2124 fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL;
2125 /*
2126 * Register the fabric for use within TCM
2127 */
2128 ret = target_fabric_configfs_register(fabric);
2129 if (ret < 0) {
2130 pr_err("target_fabric_configfs_register() failed for TCM_QLA2XXX\n");
2131 return ret; 2112 return ret;
2132 }
2133 /*
2134 * Setup our local pointer to *fabric
2135 */
2136 tcm_qla2xxx_fabric_configfs = fabric;
2137 pr_debug("TCM_QLA2XXX[0] - Set fabric -> tcm_qla2xxx_fabric_configfs\n");
2138 2113
2139 /* 2114 ret = target_register_template(&tcm_qla2xxx_npiv_ops);
2140 * Register the top level struct config_item_type for NPIV with TCM core 2115 if (ret)
2141 */
2142 npiv_fabric = target_fabric_configfs_init(THIS_MODULE, "qla2xxx_npiv");
2143 if (IS_ERR(npiv_fabric)) {
2144 pr_err("target_fabric_configfs_init() failed\n");
2145 ret = PTR_ERR(npiv_fabric);
2146 goto out_fabric; 2116 goto out_fabric;
2147 }
2148 /*
2149 * Setup fabric->tf_ops from our local tcm_qla2xxx_npiv_ops
2150 */
2151 npiv_fabric->tf_ops = tcm_qla2xxx_npiv_ops;
2152 /*
2153 * Setup default attribute lists for various npiv_fabric->tf_cit_tmpl
2154 */
2155 npiv_fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_qla2xxx_wwn_attrs;
2156 npiv_fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs =
2157 tcm_qla2xxx_npiv_tpg_attrs;
2158 npiv_fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL;
2159 npiv_fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
2160 npiv_fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
2161 npiv_fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL;
2162 npiv_fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
2163 npiv_fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
2164 npiv_fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL;
2165 /*
2166 * Register the npiv_fabric for use within TCM
2167 */
2168 ret = target_fabric_configfs_register(npiv_fabric);
2169 if (ret < 0) {
2170 pr_err("target_fabric_configfs_register() failed for TCM_QLA2XXX\n");
2171 goto out_fabric;
2172 }
2173 /*
2174 * Setup our local pointer to *npiv_fabric
2175 */
2176 tcm_qla2xxx_npiv_fabric_configfs = npiv_fabric;
2177 pr_debug("TCM_QLA2XXX[0] - Set fabric -> tcm_qla2xxx_npiv_fabric_configfs\n");
2178 2117
2179 tcm_qla2xxx_free_wq = alloc_workqueue("tcm_qla2xxx_free", 2118 tcm_qla2xxx_free_wq = alloc_workqueue("tcm_qla2xxx_free",
2180 WQ_MEM_RECLAIM, 0); 2119 WQ_MEM_RECLAIM, 0);
@@ -2194,9 +2133,9 @@ static int tcm_qla2xxx_register_configfs(void)
2194out_free_wq: 2133out_free_wq:
2195 destroy_workqueue(tcm_qla2xxx_free_wq); 2134 destroy_workqueue(tcm_qla2xxx_free_wq);
2196out_fabric_npiv: 2135out_fabric_npiv:
2197 target_fabric_configfs_deregister(tcm_qla2xxx_npiv_fabric_configfs); 2136 target_unregister_template(&tcm_qla2xxx_npiv_ops);
2198out_fabric: 2137out_fabric:
2199 target_fabric_configfs_deregister(tcm_qla2xxx_fabric_configfs); 2138 target_unregister_template(&tcm_qla2xxx_ops);
2200 return ret; 2139 return ret;
2201} 2140}
2202 2141
@@ -2205,13 +2144,8 @@ static void tcm_qla2xxx_deregister_configfs(void)
2205 destroy_workqueue(tcm_qla2xxx_cmd_wq); 2144 destroy_workqueue(tcm_qla2xxx_cmd_wq);
2206 destroy_workqueue(tcm_qla2xxx_free_wq); 2145 destroy_workqueue(tcm_qla2xxx_free_wq);
2207 2146
2208 target_fabric_configfs_deregister(tcm_qla2xxx_fabric_configfs); 2147 target_unregister_template(&tcm_qla2xxx_ops);
2209 tcm_qla2xxx_fabric_configfs = NULL; 2148 target_unregister_template(&tcm_qla2xxx_npiv_ops);
2210 pr_debug("TCM_QLA2XXX[0] - Cleared tcm_qla2xxx_fabric_configfs\n");
2211
2212 target_fabric_configfs_deregister(tcm_qla2xxx_npiv_fabric_configfs);
2213 tcm_qla2xxx_npiv_fabric_configfs = NULL;
2214 pr_debug("TCM_QLA2XXX[0] - Cleared tcm_qla2xxx_npiv_fabric_configfs\n");
2215} 2149}
2216 2150
2217static int __init tcm_qla2xxx_init(void) 2151static int __init tcm_qla2xxx_init(void)
diff --git a/drivers/target/iscsi/iscsi_target.c b/drivers/target/iscsi/iscsi_target.c
index cd611e740de7..5d75bb418696 100644
--- a/drivers/target/iscsi/iscsi_target.c
+++ b/drivers/target/iscsi/iscsi_target.c
@@ -33,7 +33,6 @@
33#include <target/iscsi/iscsi_target_core.h> 33#include <target/iscsi/iscsi_target_core.h>
34#include "iscsi_target_parameters.h" 34#include "iscsi_target_parameters.h"
35#include "iscsi_target_seq_pdu_list.h" 35#include "iscsi_target_seq_pdu_list.h"
36#include "iscsi_target_configfs.h"
37#include "iscsi_target_datain_values.h" 36#include "iscsi_target_datain_values.h"
38#include "iscsi_target_erl0.h" 37#include "iscsi_target_erl0.h"
39#include "iscsi_target_erl1.h" 38#include "iscsi_target_erl1.h"
@@ -551,8 +550,8 @@ static int __init iscsi_target_init_module(void)
551 idr_init(&tiqn_idr); 550 idr_init(&tiqn_idr);
552 idr_init(&sess_idr); 551 idr_init(&sess_idr);
553 552
554 ret = iscsi_target_register_configfs(); 553 ret = target_register_template(&iscsi_ops);
555 if (ret < 0) 554 if (ret)
556 goto out; 555 goto out;
557 556
558 size = BITS_TO_LONGS(ISCSIT_BITMAP_BITS) * sizeof(long); 557 size = BITS_TO_LONGS(ISCSIT_BITMAP_BITS) * sizeof(long);
@@ -616,7 +615,10 @@ qr_out:
616bitmap_out: 615bitmap_out:
617 vfree(iscsit_global->ts_bitmap); 616 vfree(iscsit_global->ts_bitmap);
618configfs_out: 617configfs_out:
619 iscsi_target_deregister_configfs(); 618 /* XXX: this probably wants it to be it's own unwind step.. */
619 if (iscsit_global->discovery_tpg)
620 iscsit_tpg_disable_portal_group(iscsit_global->discovery_tpg, 1);
621 target_unregister_template(&iscsi_ops);
620out: 622out:
621 kfree(iscsit_global); 623 kfree(iscsit_global);
622 return -ENOMEM; 624 return -ENOMEM;
@@ -631,7 +633,13 @@ static void __exit iscsi_target_cleanup_module(void)
631 kmem_cache_destroy(lio_ooo_cache); 633 kmem_cache_destroy(lio_ooo_cache);
632 kmem_cache_destroy(lio_r2t_cache); 634 kmem_cache_destroy(lio_r2t_cache);
633 635
634 iscsi_target_deregister_configfs(); 636 /*
637 * Shutdown discovery sessions and disable discovery TPG
638 */
639 if (iscsit_global->discovery_tpg)
640 iscsit_tpg_disable_portal_group(iscsit_global->discovery_tpg, 1);
641
642 target_unregister_template(&iscsi_ops);
635 643
636 vfree(iscsit_global->ts_bitmap); 644 vfree(iscsit_global->ts_bitmap);
637 kfree(iscsit_global); 645 kfree(iscsit_global);
@@ -983,7 +991,7 @@ int iscsit_setup_scsi_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
983 /* 991 /*
984 * Initialize struct se_cmd descriptor from target_core_mod infrastructure 992 * Initialize struct se_cmd descriptor from target_core_mod infrastructure
985 */ 993 */
986 transport_init_se_cmd(&cmd->se_cmd, &lio_target_fabric_configfs->tf_ops, 994 transport_init_se_cmd(&cmd->se_cmd, &iscsi_ops,
987 conn->sess->se_sess, be32_to_cpu(hdr->data_length), 995 conn->sess->se_sess, be32_to_cpu(hdr->data_length),
988 cmd->data_direction, sam_task_attr, 996 cmd->data_direction, sam_task_attr,
989 cmd->sense_buffer + 2); 997 cmd->sense_buffer + 2);
@@ -1798,8 +1806,7 @@ iscsit_handle_task_mgt_cmd(struct iscsi_conn *conn, struct iscsi_cmd *cmd,
1798 u8 tcm_function; 1806 u8 tcm_function;
1799 int ret; 1807 int ret;
1800 1808
1801 transport_init_se_cmd(&cmd->se_cmd, 1809 transport_init_se_cmd(&cmd->se_cmd, &iscsi_ops,
1802 &lio_target_fabric_configfs->tf_ops,
1803 conn->sess->se_sess, 0, DMA_NONE, 1810 conn->sess->se_sess, 0, DMA_NONE,
1804 TCM_SIMPLE_TAG, cmd->sense_buffer + 2); 1811 TCM_SIMPLE_TAG, cmd->sense_buffer + 2);
1805 1812
diff --git a/drivers/target/iscsi/iscsi_target.h b/drivers/target/iscsi/iscsi_target.h
index e936d56fb523..7d0f9c00d9c2 100644
--- a/drivers/target/iscsi/iscsi_target.h
+++ b/drivers/target/iscsi/iscsi_target.h
@@ -35,7 +35,7 @@ extern void iscsit_stop_session(struct iscsi_session *, int, int);
35extern int iscsit_release_sessions_for_tpg(struct iscsi_portal_group *, int); 35extern int iscsit_release_sessions_for_tpg(struct iscsi_portal_group *, int);
36 36
37extern struct iscsit_global *iscsit_global; 37extern struct iscsit_global *iscsit_global;
38extern struct target_fabric_configfs *lio_target_fabric_configfs; 38extern const struct target_core_fabric_ops iscsi_ops;
39 39
40extern struct kmem_cache *lio_dr_cache; 40extern struct kmem_cache *lio_dr_cache;
41extern struct kmem_cache *lio_ooo_cache; 41extern struct kmem_cache *lio_ooo_cache;
diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c
index 9cb5ab472a52..469fce44ebad 100644
--- a/drivers/target/iscsi/iscsi_target_configfs.c
+++ b/drivers/target/iscsi/iscsi_target_configfs.c
@@ -37,9 +37,6 @@
37#include "iscsi_target_util.h" 37#include "iscsi_target_util.h"
38#include "iscsi_target.h" 38#include "iscsi_target.h"
39#include <target/iscsi/iscsi_target_stat.h> 39#include <target/iscsi/iscsi_target_stat.h>
40#include "iscsi_target_configfs.h"
41
42struct target_fabric_configfs *lio_target_fabric_configfs;
43 40
44struct lio_target_configfs_attribute { 41struct lio_target_configfs_attribute {
45 struct configfs_attribute attr; 42 struct configfs_attribute attr;
@@ -1466,10 +1463,8 @@ static struct se_portal_group *lio_target_tiqn_addtpg(
1466 if (!tpg) 1463 if (!tpg)
1467 return NULL; 1464 return NULL;
1468 1465
1469 ret = core_tpg_register( 1466 ret = core_tpg_register(&iscsi_ops, wwn, &tpg->tpg_se_tpg,
1470 &lio_target_fabric_configfs->tf_ops, 1467 tpg, TRANSPORT_TPG_TYPE_NORMAL);
1471 wwn, &tpg->tpg_se_tpg, tpg,
1472 TRANSPORT_TPG_TYPE_NORMAL);
1473 if (ret < 0) 1468 if (ret < 0)
1474 return NULL; 1469 return NULL;
1475 1470
@@ -1983,117 +1978,60 @@ static void lio_release_cmd(struct se_cmd *se_cmd)
1983 iscsit_release_cmd(cmd); 1978 iscsit_release_cmd(cmd);
1984} 1979}
1985 1980
1986/* End functions for target_core_fabric_ops */ 1981const struct target_core_fabric_ops iscsi_ops = {
1987 1982 .module = THIS_MODULE,
1988int iscsi_target_register_configfs(void) 1983 .name = "iscsi",
1989{ 1984 .get_fabric_name = iscsi_get_fabric_name,
1990 struct target_fabric_configfs *fabric; 1985 .get_fabric_proto_ident = iscsi_get_fabric_proto_ident,
1991 int ret; 1986 .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
1992 1987 .tpg_get_tag = lio_tpg_get_tag,
1993 lio_target_fabric_configfs = NULL; 1988 .tpg_get_default_depth = lio_tpg_get_default_depth,
1994 fabric = target_fabric_configfs_init(THIS_MODULE, "iscsi"); 1989 .tpg_get_pr_transport_id = iscsi_get_pr_transport_id,
1995 if (IS_ERR(fabric)) { 1990 .tpg_get_pr_transport_id_len = iscsi_get_pr_transport_id_len,
1996 pr_err("target_fabric_configfs_init() for" 1991 .tpg_parse_pr_out_transport_id = iscsi_parse_pr_out_transport_id,
1997 " LIO-Target failed!\n"); 1992 .tpg_check_demo_mode = lio_tpg_check_demo_mode,
1998 return PTR_ERR(fabric); 1993 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
1999 } 1994 .tpg_check_demo_mode_write_protect =
2000 /* 1995 lio_tpg_check_demo_mode_write_protect,
2001 * Setup the fabric API of function pointers used by target_core_mod.. 1996 .tpg_check_prod_mode_write_protect =
2002 */ 1997 lio_tpg_check_prod_mode_write_protect,
2003 fabric->tf_ops.get_fabric_name = &iscsi_get_fabric_name; 1998 .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only,
2004 fabric->tf_ops.get_fabric_proto_ident = &iscsi_get_fabric_proto_ident; 1999 .tpg_alloc_fabric_acl = lio_tpg_alloc_fabric_acl,
2005 fabric->tf_ops.tpg_get_wwn = &lio_tpg_get_endpoint_wwn; 2000 .tpg_release_fabric_acl = lio_tpg_release_fabric_acl,
2006 fabric->tf_ops.tpg_get_tag = &lio_tpg_get_tag; 2001 .tpg_get_inst_index = lio_tpg_get_inst_index,
2007 fabric->tf_ops.tpg_get_default_depth = &lio_tpg_get_default_depth; 2002 .check_stop_free = lio_check_stop_free,
2008 fabric->tf_ops.tpg_get_pr_transport_id = &iscsi_get_pr_transport_id; 2003 .release_cmd = lio_release_cmd,
2009 fabric->tf_ops.tpg_get_pr_transport_id_len = 2004 .shutdown_session = lio_tpg_shutdown_session,
2010 &iscsi_get_pr_transport_id_len; 2005 .close_session = lio_tpg_close_session,
2011 fabric->tf_ops.tpg_parse_pr_out_transport_id = 2006 .sess_get_index = lio_sess_get_index,
2012 &iscsi_parse_pr_out_transport_id; 2007 .sess_get_initiator_sid = lio_sess_get_initiator_sid,
2013 fabric->tf_ops.tpg_check_demo_mode = &lio_tpg_check_demo_mode; 2008 .write_pending = lio_write_pending,
2014 fabric->tf_ops.tpg_check_demo_mode_cache = 2009 .write_pending_status = lio_write_pending_status,
2015 &lio_tpg_check_demo_mode_cache; 2010 .set_default_node_attributes = lio_set_default_node_attributes,
2016 fabric->tf_ops.tpg_check_demo_mode_write_protect = 2011 .get_task_tag = iscsi_get_task_tag,
2017 &lio_tpg_check_demo_mode_write_protect; 2012 .get_cmd_state = iscsi_get_cmd_state,
2018 fabric->tf_ops.tpg_check_prod_mode_write_protect = 2013 .queue_data_in = lio_queue_data_in,
2019 &lio_tpg_check_prod_mode_write_protect; 2014 .queue_status = lio_queue_status,
2020 fabric->tf_ops.tpg_check_prot_fabric_only = 2015 .queue_tm_rsp = lio_queue_tm_rsp,
2021 &lio_tpg_check_prot_fabric_only; 2016 .aborted_task = lio_aborted_task,
2022 fabric->tf_ops.tpg_alloc_fabric_acl = &lio_tpg_alloc_fabric_acl; 2017 .fabric_make_wwn = lio_target_call_coreaddtiqn,
2023 fabric->tf_ops.tpg_release_fabric_acl = &lio_tpg_release_fabric_acl; 2018 .fabric_drop_wwn = lio_target_call_coredeltiqn,
2024 fabric->tf_ops.tpg_get_inst_index = &lio_tpg_get_inst_index; 2019 .fabric_make_tpg = lio_target_tiqn_addtpg,
2025 fabric->tf_ops.check_stop_free = &lio_check_stop_free, 2020 .fabric_drop_tpg = lio_target_tiqn_deltpg,
2026 fabric->tf_ops.release_cmd = &lio_release_cmd; 2021 .fabric_make_np = lio_target_call_addnptotpg,
2027 fabric->tf_ops.shutdown_session = &lio_tpg_shutdown_session; 2022 .fabric_drop_np = lio_target_call_delnpfromtpg,
2028 fabric->tf_ops.close_session = &lio_tpg_close_session; 2023 .fabric_make_nodeacl = lio_target_make_nodeacl,
2029 fabric->tf_ops.sess_get_index = &lio_sess_get_index; 2024 .fabric_drop_nodeacl = lio_target_drop_nodeacl,
2030 fabric->tf_ops.sess_get_initiator_sid = &lio_sess_get_initiator_sid; 2025
2031 fabric->tf_ops.write_pending = &lio_write_pending; 2026 .tfc_discovery_attrs = lio_target_discovery_auth_attrs,
2032 fabric->tf_ops.write_pending_status = &lio_write_pending_status; 2027 .tfc_wwn_attrs = lio_target_wwn_attrs,
2033 fabric->tf_ops.set_default_node_attributes = 2028 .tfc_tpg_base_attrs = lio_target_tpg_attrs,
2034 &lio_set_default_node_attributes; 2029 .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs,
2035 fabric->tf_ops.get_task_tag = &iscsi_get_task_tag; 2030 .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs,
2036 fabric->tf_ops.get_cmd_state = &iscsi_get_cmd_state; 2031 .tfc_tpg_param_attrs = lio_target_tpg_param_attrs,
2037 fabric->tf_ops.queue_data_in = &lio_queue_data_in; 2032 .tfc_tpg_np_base_attrs = lio_target_portal_attrs,
2038 fabric->tf_ops.queue_status = &lio_queue_status; 2033 .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs,
2039 fabric->tf_ops.queue_tm_rsp = &lio_queue_tm_rsp; 2034 .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs,
2040 fabric->tf_ops.aborted_task = &lio_aborted_task; 2035 .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs,
2041 /* 2036 .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs,
2042 * Setup function pointers for generic logic in target_core_fabric_configfs.c 2037};
2043 */
2044 fabric->tf_ops.fabric_make_wwn = &lio_target_call_coreaddtiqn;
2045 fabric->tf_ops.fabric_drop_wwn = &lio_target_call_coredeltiqn;
2046 fabric->tf_ops.fabric_make_tpg = &lio_target_tiqn_addtpg;
2047 fabric->tf_ops.fabric_drop_tpg = &lio_target_tiqn_deltpg;
2048 fabric->tf_ops.fabric_post_link = NULL;
2049 fabric->tf_ops.fabric_pre_unlink = NULL;
2050 fabric->tf_ops.fabric_make_np = &lio_target_call_addnptotpg;
2051 fabric->tf_ops.fabric_drop_np = &lio_target_call_delnpfromtpg;
2052 fabric->tf_ops.fabric_make_nodeacl = &lio_target_make_nodeacl;
2053 fabric->tf_ops.fabric_drop_nodeacl = &lio_target_drop_nodeacl;
2054 /*
2055 * Setup default attribute lists for various fabric->tf_cit_tmpl
2056 * sturct config_item_type's
2057 */
2058 fabric->tf_cit_tmpl.tfc_discovery_cit.ct_attrs = lio_target_discovery_auth_attrs;
2059 fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = lio_target_wwn_attrs;
2060 fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = lio_target_tpg_attrs;
2061 fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = lio_target_tpg_attrib_attrs;
2062 fabric->tf_cit_tmpl.tfc_tpg_auth_cit.ct_attrs = lio_target_tpg_auth_attrs;
2063 fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = lio_target_tpg_param_attrs;
2064 fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = lio_target_portal_attrs;
2065 fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = lio_target_initiator_attrs;
2066 fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = lio_target_nacl_attrib_attrs;
2067 fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = lio_target_nacl_auth_attrs;
2068 fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = lio_target_nacl_param_attrs;
2069
2070 ret = target_fabric_configfs_register(fabric);
2071 if (ret < 0) {
2072 pr_err("target_fabric_configfs_register() for"
2073 " LIO-Target failed!\n");
2074 target_fabric_configfs_free(fabric);
2075 return ret;
2076 }
2077
2078 lio_target_fabric_configfs = fabric;
2079 pr_debug("LIO_TARGET[0] - Set fabric ->"
2080 " lio_target_fabric_configfs\n");
2081 return 0;
2082}
2083
2084
2085void iscsi_target_deregister_configfs(void)
2086{
2087 if (!lio_target_fabric_configfs)
2088 return;
2089 /*
2090 * Shutdown discovery sessions and disable discovery TPG
2091 */
2092 if (iscsit_global->discovery_tpg)
2093 iscsit_tpg_disable_portal_group(iscsit_global->discovery_tpg, 1);
2094
2095 target_fabric_configfs_deregister(lio_target_fabric_configfs);
2096 lio_target_fabric_configfs = NULL;
2097 pr_debug("LIO_TARGET[0] - Cleared"
2098 " lio_target_fabric_configfs\n");
2099}
diff --git a/drivers/target/iscsi/iscsi_target_configfs.h b/drivers/target/iscsi/iscsi_target_configfs.h
deleted file mode 100644
index 8cd5a63c4edc..000000000000
--- a/drivers/target/iscsi/iscsi_target_configfs.h
+++ /dev/null
@@ -1,7 +0,0 @@
1#ifndef ISCSI_TARGET_CONFIGFS_H
2#define ISCSI_TARGET_CONFIGFS_H
3
4extern int iscsi_target_register_configfs(void);
5extern void iscsi_target_deregister_configfs(void);
6
7#endif /* ISCSI_TARGET_CONFIGFS_H */
diff --git a/drivers/target/iscsi/iscsi_target_tpg.c b/drivers/target/iscsi/iscsi_target_tpg.c
index 3076e6f3a831..e8a240818353 100644
--- a/drivers/target/iscsi/iscsi_target_tpg.c
+++ b/drivers/target/iscsi/iscsi_target_tpg.c
@@ -68,10 +68,8 @@ int iscsit_load_discovery_tpg(void)
68 return -1; 68 return -1;
69 } 69 }
70 70
71 ret = core_tpg_register( 71 ret = core_tpg_register(&iscsi_ops, NULL, &tpg->tpg_se_tpg,
72 &lio_target_fabric_configfs->tf_ops, 72 tpg, TRANSPORT_TPG_TYPE_DISCOVERY);
73 NULL, &tpg->tpg_se_tpg, tpg,
74 TRANSPORT_TPG_TYPE_DISCOVERY);
75 if (ret < 0) { 73 if (ret < 0) {
76 kfree(tpg); 74 kfree(tpg);
77 return -1; 75 return -1;
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index 2114c1d2c9de..5b143d2c08f7 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -41,8 +41,7 @@
41 41
42#define to_tcm_loop_hba(hba) container_of(hba, struct tcm_loop_hba, dev) 42#define to_tcm_loop_hba(hba) container_of(hba, struct tcm_loop_hba, dev)
43 43
44/* Local pointer to allocated TCM configfs fabric module */ 44static const struct target_core_fabric_ops loop_ops;
45static struct target_fabric_configfs *tcm_loop_fabric_configfs;
46 45
47static struct workqueue_struct *tcm_loop_workqueue; 46static struct workqueue_struct *tcm_loop_workqueue;
48static struct kmem_cache *tcm_loop_cmd_cache; 47static struct kmem_cache *tcm_loop_cmd_cache;
@@ -1238,8 +1237,7 @@ static struct se_portal_group *tcm_loop_make_naa_tpg(
1238 /* 1237 /*
1239 * Register the tl_tpg as a emulated SAS TCM Target Endpoint 1238 * Register the tl_tpg as a emulated SAS TCM Target Endpoint
1240 */ 1239 */
1241 ret = core_tpg_register(&tcm_loop_fabric_configfs->tf_ops, 1240 ret = core_tpg_register(&loop_ops, wwn, &tl_tpg->tl_se_tpg, tl_tpg,
1242 wwn, &tl_tpg->tl_se_tpg, tl_tpg,
1243 TRANSPORT_TPG_TYPE_NORMAL); 1241 TRANSPORT_TPG_TYPE_NORMAL);
1244 if (ret < 0) 1242 if (ret < 0)
1245 return ERR_PTR(-ENOMEM); 1243 return ERR_PTR(-ENOMEM);
@@ -1387,129 +1385,51 @@ static struct configfs_attribute *tcm_loop_wwn_attrs[] = {
1387 1385
1388/* End items for tcm_loop_cit */ 1386/* End items for tcm_loop_cit */
1389 1387
1390static int tcm_loop_register_configfs(void) 1388static const struct target_core_fabric_ops loop_ops = {
1391{ 1389 .module = THIS_MODULE,
1392 struct target_fabric_configfs *fabric; 1390 .name = "loopback",
1393 int ret; 1391 .get_fabric_name = tcm_loop_get_fabric_name,
1394 /* 1392 .get_fabric_proto_ident = tcm_loop_get_fabric_proto_ident,
1395 * Set the TCM Loop HBA counter to zero 1393 .tpg_get_wwn = tcm_loop_get_endpoint_wwn,
1396 */ 1394 .tpg_get_tag = tcm_loop_get_tag,
1397 tcm_loop_hba_no_cnt = 0; 1395 .tpg_get_default_depth = tcm_loop_get_default_depth,
1398 /* 1396 .tpg_get_pr_transport_id = tcm_loop_get_pr_transport_id,
1399 * Register the top level struct config_item_type with TCM core 1397 .tpg_get_pr_transport_id_len = tcm_loop_get_pr_transport_id_len,
1400 */ 1398 .tpg_parse_pr_out_transport_id = tcm_loop_parse_pr_out_transport_id,
1401 fabric = target_fabric_configfs_init(THIS_MODULE, "loopback"); 1399 .tpg_check_demo_mode = tcm_loop_check_demo_mode,
1402 if (IS_ERR(fabric)) { 1400 .tpg_check_demo_mode_cache = tcm_loop_check_demo_mode_cache,
1403 pr_err("tcm_loop_register_configfs() failed!\n"); 1401 .tpg_check_demo_mode_write_protect =
1404 return PTR_ERR(fabric); 1402 tcm_loop_check_demo_mode_write_protect,
1405 } 1403 .tpg_check_prod_mode_write_protect =
1406 /* 1404 tcm_loop_check_prod_mode_write_protect,
1407 * Setup the fabric API of function pointers used by target_core_mod 1405 .tpg_check_prot_fabric_only = tcm_loop_check_prot_fabric_only,
1408 */ 1406 .tpg_alloc_fabric_acl = tcm_loop_tpg_alloc_fabric_acl,
1409 fabric->tf_ops.get_fabric_name = &tcm_loop_get_fabric_name; 1407 .tpg_release_fabric_acl = tcm_loop_tpg_release_fabric_acl,
1410 fabric->tf_ops.get_fabric_proto_ident = &tcm_loop_get_fabric_proto_ident; 1408 .tpg_get_inst_index = tcm_loop_get_inst_index,
1411 fabric->tf_ops.tpg_get_wwn = &tcm_loop_get_endpoint_wwn; 1409 .check_stop_free = tcm_loop_check_stop_free,
1412 fabric->tf_ops.tpg_get_tag = &tcm_loop_get_tag; 1410 .release_cmd = tcm_loop_release_cmd,
1413 fabric->tf_ops.tpg_get_default_depth = &tcm_loop_get_default_depth; 1411 .shutdown_session = tcm_loop_shutdown_session,
1414 fabric->tf_ops.tpg_get_pr_transport_id = &tcm_loop_get_pr_transport_id; 1412 .close_session = tcm_loop_close_session,
1415 fabric->tf_ops.tpg_get_pr_transport_id_len = 1413 .sess_get_index = tcm_loop_sess_get_index,
1416 &tcm_loop_get_pr_transport_id_len; 1414 .write_pending = tcm_loop_write_pending,
1417 fabric->tf_ops.tpg_parse_pr_out_transport_id = 1415 .write_pending_status = tcm_loop_write_pending_status,
1418 &tcm_loop_parse_pr_out_transport_id; 1416 .set_default_node_attributes = tcm_loop_set_default_node_attributes,
1419 fabric->tf_ops.tpg_check_demo_mode = &tcm_loop_check_demo_mode; 1417 .get_task_tag = tcm_loop_get_task_tag,
1420 fabric->tf_ops.tpg_check_demo_mode_cache = 1418 .get_cmd_state = tcm_loop_get_cmd_state,
1421 &tcm_loop_check_demo_mode_cache; 1419 .queue_data_in = tcm_loop_queue_data_in,
1422 fabric->tf_ops.tpg_check_demo_mode_write_protect = 1420 .queue_status = tcm_loop_queue_status,
1423 &tcm_loop_check_demo_mode_write_protect; 1421 .queue_tm_rsp = tcm_loop_queue_tm_rsp,
1424 fabric->tf_ops.tpg_check_prod_mode_write_protect = 1422 .aborted_task = tcm_loop_aborted_task,
1425 &tcm_loop_check_prod_mode_write_protect; 1423 .fabric_make_wwn = tcm_loop_make_scsi_hba,
1426 fabric->tf_ops.tpg_check_prot_fabric_only = 1424 .fabric_drop_wwn = tcm_loop_drop_scsi_hba,
1427 &tcm_loop_check_prot_fabric_only; 1425 .fabric_make_tpg = tcm_loop_make_naa_tpg,
1428 /* 1426 .fabric_drop_tpg = tcm_loop_drop_naa_tpg,
1429 * The TCM loopback fabric module runs in demo-mode to a local 1427 .fabric_post_link = tcm_loop_port_link,
1430 * virtual SCSI device, so fabric dependent initator ACLs are 1428 .fabric_pre_unlink = tcm_loop_port_unlink,
1431 * not required. 1429 .tfc_wwn_attrs = tcm_loop_wwn_attrs,
1432 */ 1430 .tfc_tpg_base_attrs = tcm_loop_tpg_attrs,
1433 fabric->tf_ops.tpg_alloc_fabric_acl = &tcm_loop_tpg_alloc_fabric_acl; 1431 .tfc_tpg_attrib_attrs = tcm_loop_tpg_attrib_attrs,
1434 fabric->tf_ops.tpg_release_fabric_acl = 1432};
1435 &tcm_loop_tpg_release_fabric_acl;
1436 fabric->tf_ops.tpg_get_inst_index = &tcm_loop_get_inst_index;
1437 /*
1438 * Used for setting up remaining TCM resources in process context
1439 */
1440 fabric->tf_ops.check_stop_free = &tcm_loop_check_stop_free;
1441 fabric->tf_ops.release_cmd = &tcm_loop_release_cmd;
1442 fabric->tf_ops.shutdown_session = &tcm_loop_shutdown_session;
1443 fabric->tf_ops.close_session = &tcm_loop_close_session;
1444 fabric->tf_ops.sess_get_index = &tcm_loop_sess_get_index;
1445 fabric->tf_ops.sess_get_initiator_sid = NULL;
1446 fabric->tf_ops.write_pending = &tcm_loop_write_pending;
1447 fabric->tf_ops.write_pending_status = &tcm_loop_write_pending_status;
1448 /*
1449 * Not used for TCM loopback
1450 */
1451 fabric->tf_ops.set_default_node_attributes =
1452 &tcm_loop_set_default_node_attributes;
1453 fabric->tf_ops.get_task_tag = &tcm_loop_get_task_tag;
1454 fabric->tf_ops.get_cmd_state = &tcm_loop_get_cmd_state;
1455 fabric->tf_ops.queue_data_in = &tcm_loop_queue_data_in;
1456 fabric->tf_ops.queue_status = &tcm_loop_queue_status;
1457 fabric->tf_ops.queue_tm_rsp = &tcm_loop_queue_tm_rsp;
1458 fabric->tf_ops.aborted_task = &tcm_loop_aborted_task;
1459
1460 /*
1461 * Setup function pointers for generic logic in target_core_fabric_configfs.c
1462 */
1463 fabric->tf_ops.fabric_make_wwn = &tcm_loop_make_scsi_hba;
1464 fabric->tf_ops.fabric_drop_wwn = &tcm_loop_drop_scsi_hba;
1465 fabric->tf_ops.fabric_make_tpg = &tcm_loop_make_naa_tpg;
1466 fabric->tf_ops.fabric_drop_tpg = &tcm_loop_drop_naa_tpg;
1467 /*
1468 * fabric_post_link() and fabric_pre_unlink() are used for
1469 * registration and release of TCM Loop Virtual SCSI LUNs.
1470 */
1471 fabric->tf_ops.fabric_post_link = &tcm_loop_port_link;
1472 fabric->tf_ops.fabric_pre_unlink = &tcm_loop_port_unlink;
1473 fabric->tf_ops.fabric_make_np = NULL;
1474 fabric->tf_ops.fabric_drop_np = NULL;
1475 /*
1476 * Setup default attribute lists for various fabric->tf_cit_tmpl
1477 */
1478 fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = tcm_loop_wwn_attrs;
1479 fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = tcm_loop_tpg_attrs;
1480 fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = tcm_loop_tpg_attrib_attrs;
1481 fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
1482 fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
1483 /*
1484 * Once fabric->tf_ops has been setup, now register the fabric for
1485 * use within TCM
1486 */
1487 ret = target_fabric_configfs_register(fabric);
1488 if (ret < 0) {
1489 pr_err("target_fabric_configfs_register() for"
1490 " TCM_Loop failed!\n");
1491 target_fabric_configfs_free(fabric);
1492 return -1;
1493 }
1494 /*
1495 * Setup our local pointer to *fabric.
1496 */
1497 tcm_loop_fabric_configfs = fabric;
1498 pr_debug("TCM_LOOP[0] - Set fabric ->"
1499 " tcm_loop_fabric_configfs\n");
1500 return 0;
1501}
1502
1503static void tcm_loop_deregister_configfs(void)
1504{
1505 if (!tcm_loop_fabric_configfs)
1506 return;
1507
1508 target_fabric_configfs_deregister(tcm_loop_fabric_configfs);
1509 tcm_loop_fabric_configfs = NULL;
1510 pr_debug("TCM_LOOP[0] - Cleared"
1511 " tcm_loop_fabric_configfs\n");
1512}
1513 1433
1514static int __init tcm_loop_fabric_init(void) 1434static int __init tcm_loop_fabric_init(void)
1515{ 1435{
@@ -1533,7 +1453,7 @@ static int __init tcm_loop_fabric_init(void)
1533 if (ret) 1453 if (ret)
1534 goto out_destroy_cache; 1454 goto out_destroy_cache;
1535 1455
1536 ret = tcm_loop_register_configfs(); 1456 ret = target_register_template(&loop_ops);
1537 if (ret) 1457 if (ret)
1538 goto out_release_core_bus; 1458 goto out_release_core_bus;
1539 1459
@@ -1551,7 +1471,7 @@ out:
1551 1471
1552static void __exit tcm_loop_fabric_exit(void) 1472static void __exit tcm_loop_fabric_exit(void)
1553{ 1473{
1554 tcm_loop_deregister_configfs(); 1474 target_unregister_template(&loop_ops);
1555 tcm_loop_release_core_bus(); 1475 tcm_loop_release_core_bus();
1556 kmem_cache_destroy(tcm_loop_cmd_cache); 1476 kmem_cache_destroy(tcm_loop_cmd_cache);
1557 destroy_workqueue(tcm_loop_workqueue); 1477 destroy_workqueue(tcm_loop_workqueue);
diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
index 9512af6a8114..18b0f9703ff2 100644
--- a/drivers/target/sbp/sbp_target.c
+++ b/drivers/target/sbp/sbp_target.c
@@ -42,8 +42,7 @@
42 42
43#include "sbp_target.h" 43#include "sbp_target.h"
44 44
45/* Local pointer to allocated TCM configfs fabric module */ 45static const struct target_core_fabric_ops sbp_ops;
46static struct target_fabric_configfs *sbp_fabric_configfs;
47 46
48/* FireWire address region for management and command block address handlers */ 47/* FireWire address region for management and command block address handlers */
49static const struct fw_address_region sbp_register_region = { 48static const struct fw_address_region sbp_register_region = {
@@ -2215,8 +2214,7 @@ static struct se_portal_group *sbp_make_tpg(
2215 goto out_free_tpg; 2214 goto out_free_tpg;
2216 } 2215 }
2217 2216
2218 ret = core_tpg_register(&sbp_fabric_configfs->tf_ops, wwn, 2217 ret = core_tpg_register(&sbp_ops, wwn, &tpg->se_tpg, tpg,
2219 &tpg->se_tpg, (void *)tpg,
2220 TRANSPORT_TPG_TYPE_NORMAL); 2218 TRANSPORT_TPG_TYPE_NORMAL);
2221 if (ret < 0) 2219 if (ret < 0)
2222 goto out_unreg_mgt_agt; 2220 goto out_unreg_mgt_agt;
@@ -2503,7 +2501,9 @@ static struct configfs_attribute *sbp_tpg_attrib_attrs[] = {
2503 NULL, 2501 NULL,
2504}; 2502};
2505 2503
2506static struct target_core_fabric_ops sbp_ops = { 2504static const struct target_core_fabric_ops sbp_ops = {
2505 .module = THIS_MODULE,
2506 .name = "sbp",
2507 .get_fabric_name = sbp_get_fabric_name, 2507 .get_fabric_name = sbp_get_fabric_name,
2508 .get_fabric_proto_ident = sbp_get_fabric_proto_ident, 2508 .get_fabric_proto_ident = sbp_get_fabric_proto_ident,
2509 .tpg_get_wwn = sbp_get_fabric_wwn, 2509 .tpg_get_wwn = sbp_get_fabric_wwn,
@@ -2544,68 +2544,20 @@ static struct target_core_fabric_ops sbp_ops = {
2544 .fabric_drop_np = NULL, 2544 .fabric_drop_np = NULL,
2545 .fabric_make_nodeacl = sbp_make_nodeacl, 2545 .fabric_make_nodeacl = sbp_make_nodeacl,
2546 .fabric_drop_nodeacl = sbp_drop_nodeacl, 2546 .fabric_drop_nodeacl = sbp_drop_nodeacl,
2547};
2548
2549static int sbp_register_configfs(void)
2550{
2551 struct target_fabric_configfs *fabric;
2552 int ret;
2553
2554 fabric = target_fabric_configfs_init(THIS_MODULE, "sbp");
2555 if (IS_ERR(fabric)) {
2556 pr_err("target_fabric_configfs_init() failed\n");
2557 return PTR_ERR(fabric);
2558 }
2559
2560 fabric->tf_ops = sbp_ops;
2561
2562 /*
2563 * Setup default attribute lists for various fabric->tf_cit_tmpl
2564 */
2565 fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = sbp_wwn_attrs;
2566 fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = sbp_tpg_base_attrs;
2567 fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = sbp_tpg_attrib_attrs;
2568 fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
2569 fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
2570 fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL;
2571 fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
2572 fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
2573 fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL;
2574
2575 ret = target_fabric_configfs_register(fabric);
2576 if (ret < 0) {
2577 pr_err("target_fabric_configfs_register() failed for SBP\n");
2578 return ret;
2579 }
2580 2547
2581 sbp_fabric_configfs = fabric; 2548 .tfc_wwn_attrs = sbp_wwn_attrs,
2582 2549 .tfc_tpg_base_attrs = sbp_tpg_base_attrs,
2583 return 0; 2550 .tfc_tpg_attrib_attrs = sbp_tpg_attrib_attrs,
2584};
2585
2586static void sbp_deregister_configfs(void)
2587{
2588 if (!sbp_fabric_configfs)
2589 return;
2590
2591 target_fabric_configfs_deregister(sbp_fabric_configfs);
2592 sbp_fabric_configfs = NULL;
2593}; 2551};
2594 2552
2595static int __init sbp_init(void) 2553static int __init sbp_init(void)
2596{ 2554{
2597 int ret; 2555 return target_register_template(&sbp_ops);
2598
2599 ret = sbp_register_configfs();
2600 if (ret < 0)
2601 return ret;
2602
2603 return 0;
2604}; 2556};
2605 2557
2606static void __exit sbp_exit(void) 2558static void __exit sbp_exit(void)
2607{ 2559{
2608 sbp_deregister_configfs(); 2560 target_unregister_template(&sbp_ops);
2609}; 2561};
2610 2562
2611MODULE_DESCRIPTION("FireWire SBP fabric driver"); 2563MODULE_DESCRIPTION("FireWire SBP fabric driver");
diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index 69baf1c53d99..ddaf76a4ac2a 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -300,81 +300,17 @@ struct configfs_subsystem *target_core_subsystem[] = {
300// Start functions called by external Target Fabrics Modules 300// Start functions called by external Target Fabrics Modules
301//############################################################################*/ 301//############################################################################*/
302 302
303/* 303static int target_fabric_tf_ops_check(const struct target_core_fabric_ops *tfo)
304 * First function called by fabric modules to:
305 *
306 * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer.
307 * 2) Add struct target_fabric_configfs to g_tf_list
308 * 3) Return struct target_fabric_configfs to fabric module to be passed
309 * into target_fabric_configfs_register().
310 */
311struct target_fabric_configfs *target_fabric_configfs_init(
312 struct module *fabric_mod,
313 const char *name)
314{ 304{
315 struct target_fabric_configfs *tf; 305 if (!tfo->name) {
316 306 pr_err("Missing tfo->name\n");
317 if (!(name)) { 307 return -EINVAL;
318 pr_err("Unable to locate passed fabric name\n");
319 return ERR_PTR(-EINVAL);
320 } 308 }
321 if (strlen(name) >= TARGET_FABRIC_NAME_SIZE) { 309 if (strlen(tfo->name) >= TARGET_FABRIC_NAME_SIZE) {
322 pr_err("Passed name: %s exceeds TARGET_FABRIC" 310 pr_err("Passed name: %s exceeds TARGET_FABRIC"
323 "_NAME_SIZE\n", name); 311 "_NAME_SIZE\n", tfo->name);
324 return ERR_PTR(-EINVAL); 312 return -EINVAL;
325 } 313 }
326
327 tf = kzalloc(sizeof(struct target_fabric_configfs), GFP_KERNEL);
328 if (!tf)
329 return ERR_PTR(-ENOMEM);
330
331 INIT_LIST_HEAD(&tf->tf_list);
332 atomic_set(&tf->tf_access_cnt, 0);
333 /*
334 * Setup the default generic struct config_item_type's (cits) in
335 * struct target_fabric_configfs->tf_cit_tmpl
336 */
337 tf->tf_module = fabric_mod;
338 target_fabric_setup_cits(tf);
339
340 tf->tf_subsys = target_core_subsystem[0];
341 snprintf(tf->tf_name, TARGET_FABRIC_NAME_SIZE, "%s", name);
342
343 mutex_lock(&g_tf_lock);
344 list_add_tail(&tf->tf_list, &g_tf_list);
345 mutex_unlock(&g_tf_lock);
346
347 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>"
348 ">>>>>>>>>>>>>>\n");
349 pr_debug("Initialized struct target_fabric_configfs: %p for"
350 " %s\n", tf, tf->tf_name);
351 return tf;
352}
353EXPORT_SYMBOL(target_fabric_configfs_init);
354
355/*
356 * Called by fabric plugins after FAILED target_fabric_configfs_register() call.
357 */
358void target_fabric_configfs_free(
359 struct target_fabric_configfs *tf)
360{
361 mutex_lock(&g_tf_lock);
362 list_del(&tf->tf_list);
363 mutex_unlock(&g_tf_lock);
364
365 kfree(tf);
366}
367EXPORT_SYMBOL(target_fabric_configfs_free);
368
369/*
370 * Perform a sanity check of the passed tf->tf_ops before completing
371 * TCM fabric module registration.
372 */
373static int target_fabric_tf_ops_check(
374 struct target_fabric_configfs *tf)
375{
376 struct target_core_fabric_ops *tfo = &tf->tf_ops;
377
378 if (!tfo->get_fabric_name) { 314 if (!tfo->get_fabric_name) {
379 pr_err("Missing tfo->get_fabric_name()\n"); 315 pr_err("Missing tfo->get_fabric_name()\n");
380 return -EINVAL; 316 return -EINVAL;
@@ -508,77 +444,59 @@ static int target_fabric_tf_ops_check(
508 return 0; 444 return 0;
509} 445}
510 446
511/* 447int target_register_template(const struct target_core_fabric_ops *fo)
512 * Called 2nd from fabric module with returned parameter of
513 * struct target_fabric_configfs * from target_fabric_configfs_init().
514 *
515 * Upon a successful registration, the new fabric's struct config_item is
516 * return. Also, a pointer to this struct is set in the passed
517 * struct target_fabric_configfs.
518 */
519int target_fabric_configfs_register(
520 struct target_fabric_configfs *tf)
521{ 448{
449 struct target_fabric_configfs *tf;
522 int ret; 450 int ret;
523 451
452 ret = target_fabric_tf_ops_check(fo);
453 if (ret)
454 return ret;
455
456 tf = kzalloc(sizeof(struct target_fabric_configfs), GFP_KERNEL);
524 if (!tf) { 457 if (!tf) {
525 pr_err("Unable to locate target_fabric_configfs" 458 pr_err("%s: could not allocate memory!\n", __func__);
526 " pointer\n"); 459 return -ENOMEM;
527 return -EINVAL;
528 }
529 if (!tf->tf_subsys) {
530 pr_err("Unable to target struct config_subsystem"
531 " pointer\n");
532 return -EINVAL;
533 } 460 }
534 ret = target_fabric_tf_ops_check(tf);
535 if (ret < 0)
536 return ret;
537 461
538 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>" 462 INIT_LIST_HEAD(&tf->tf_list);
539 ">>>>>>>>>>\n"); 463 atomic_set(&tf->tf_access_cnt, 0);
464
465 /*
466 * Setup the default generic struct config_item_type's (cits) in
467 * struct target_fabric_configfs->tf_cit_tmpl
468 */
469 tf->tf_module = fo->module;
470 tf->tf_subsys = target_core_subsystem[0];
471 snprintf(tf->tf_name, TARGET_FABRIC_NAME_SIZE, "%s", fo->name);
472
473 tf->tf_ops = *fo;
474 target_fabric_setup_cits(tf);
475
476 mutex_lock(&g_tf_lock);
477 list_add_tail(&tf->tf_list, &g_tf_list);
478 mutex_unlock(&g_tf_lock);
479
540 return 0; 480 return 0;
541} 481}
542EXPORT_SYMBOL(target_fabric_configfs_register); 482EXPORT_SYMBOL(target_register_template);
543 483
544void target_fabric_configfs_deregister( 484void target_unregister_template(const struct target_core_fabric_ops *fo)
545 struct target_fabric_configfs *tf)
546{ 485{
547 struct configfs_subsystem *su; 486 struct target_fabric_configfs *t;
548 487
549 if (!tf) {
550 pr_err("Unable to locate passed target_fabric_"
551 "configfs\n");
552 return;
553 }
554 su = tf->tf_subsys;
555 if (!su) {
556 pr_err("Unable to locate passed tf->tf_subsys"
557 " pointer\n");
558 return;
559 }
560 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
561 ">>>>>>>>>>>>\n");
562 mutex_lock(&g_tf_lock); 488 mutex_lock(&g_tf_lock);
563 if (atomic_read(&tf->tf_access_cnt)) { 489 list_for_each_entry(t, &g_tf_list, tf_list) {
564 mutex_unlock(&g_tf_lock); 490 if (!strcmp(t->tf_name, fo->name)) {
565 pr_err("Non zero tf->tf_access_cnt for fabric %s\n", 491 BUG_ON(atomic_read(&t->tf_access_cnt));
566 tf->tf_name); 492 list_del(&t->tf_list);
567 BUG(); 493 kfree(t);
494 break;
495 }
568 } 496 }
569 list_del(&tf->tf_list);
570 mutex_unlock(&g_tf_lock); 497 mutex_unlock(&g_tf_lock);
571
572 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
573 " %s\n", tf->tf_name);
574 tf->tf_module = NULL;
575 tf->tf_subsys = NULL;
576 kfree(tf);
577
578 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
579 ">>>>>\n");
580} 498}
581EXPORT_SYMBOL(target_fabric_configfs_deregister); 499EXPORT_SYMBOL(target_unregister_template);
582 500
583/*############################################################################## 501/*##############################################################################
584// Stop functions called by external Target Fabrics Modules 502// Stop functions called by external Target Fabrics Modules
@@ -945,7 +863,7 @@ static ssize_t target_core_dev_pr_show_attr_res_pr_holder_tg_port(
945 struct se_lun *lun; 863 struct se_lun *lun;
946 struct se_portal_group *se_tpg; 864 struct se_portal_group *se_tpg;
947 struct t10_pr_registration *pr_reg; 865 struct t10_pr_registration *pr_reg;
948 struct target_core_fabric_ops *tfo; 866 const struct target_core_fabric_ops *tfo;
949 ssize_t len = 0; 867 ssize_t len = 0;
950 868
951 spin_lock(&dev->dev_reservation_lock); 869 spin_lock(&dev->dev_reservation_lock);
@@ -979,7 +897,7 @@ SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port);
979static ssize_t target_core_dev_pr_show_attr_res_pr_registered_i_pts( 897static ssize_t target_core_dev_pr_show_attr_res_pr_registered_i_pts(
980 struct se_device *dev, char *page) 898 struct se_device *dev, char *page)
981{ 899{
982 struct target_core_fabric_ops *tfo; 900 const struct target_core_fabric_ops *tfo;
983 struct t10_pr_registration *pr_reg; 901 struct t10_pr_registration *pr_reg;
984 unsigned char buf[384]; 902 unsigned char buf[384];
985 char i_buf[PR_REG_ISID_ID_LEN]; 903 char i_buf[PR_REG_ISID_ID_LEN];
diff --git a/drivers/target/target_core_fabric_configfs.c b/drivers/target/target_core_fabric_configfs.c
index 0c3f90130b7d..1f7886bb16bf 100644
--- a/drivers/target/target_core_fabric_configfs.c
+++ b/drivers/target/target_core_fabric_configfs.c
@@ -56,6 +56,20 @@ static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf)
56 pr_debug("Setup generic %s\n", __stringify(_name)); \ 56 pr_debug("Setup generic %s\n", __stringify(_name)); \
57} 57}
58 58
59#define TF_CIT_SETUP_DRV(_name, _item_ops, _group_ops) \
60static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \
61{ \
62 struct target_fabric_configfs_template *tfc = &tf->tf_cit_tmpl; \
63 struct config_item_type *cit = &tfc->tfc_##_name##_cit; \
64 struct configfs_attribute **attrs = tf->tf_ops.tfc_##_name##_attrs; \
65 \
66 cit->ct_item_ops = _item_ops; \
67 cit->ct_group_ops = _group_ops; \
68 cit->ct_attrs = attrs; \
69 cit->ct_owner = tf->tf_module; \
70 pr_debug("Setup generic %s\n", __stringify(_name)); \
71}
72
59/* Start of tfc_tpg_mappedlun_cit */ 73/* Start of tfc_tpg_mappedlun_cit */
60 74
61static int target_fabric_mappedlun_link( 75static int target_fabric_mappedlun_link(
@@ -278,7 +292,7 @@ static struct configfs_item_operations target_fabric_nacl_attrib_item_ops = {
278 .store_attribute = target_fabric_nacl_attrib_attr_store, 292 .store_attribute = target_fabric_nacl_attrib_attr_store,
279}; 293};
280 294
281TF_CIT_SETUP(tpg_nacl_attrib, &target_fabric_nacl_attrib_item_ops, NULL, NULL); 295TF_CIT_SETUP_DRV(tpg_nacl_attrib, &target_fabric_nacl_attrib_item_ops, NULL);
282 296
283/* End of tfc_tpg_nacl_attrib_cit */ 297/* End of tfc_tpg_nacl_attrib_cit */
284 298
@@ -291,7 +305,7 @@ static struct configfs_item_operations target_fabric_nacl_auth_item_ops = {
291 .store_attribute = target_fabric_nacl_auth_attr_store, 305 .store_attribute = target_fabric_nacl_auth_attr_store,
292}; 306};
293 307
294TF_CIT_SETUP(tpg_nacl_auth, &target_fabric_nacl_auth_item_ops, NULL, NULL); 308TF_CIT_SETUP_DRV(tpg_nacl_auth, &target_fabric_nacl_auth_item_ops, NULL);
295 309
296/* End of tfc_tpg_nacl_auth_cit */ 310/* End of tfc_tpg_nacl_auth_cit */
297 311
@@ -304,7 +318,7 @@ static struct configfs_item_operations target_fabric_nacl_param_item_ops = {
304 .store_attribute = target_fabric_nacl_param_attr_store, 318 .store_attribute = target_fabric_nacl_param_attr_store,
305}; 319};
306 320
307TF_CIT_SETUP(tpg_nacl_param, &target_fabric_nacl_param_item_ops, NULL, NULL); 321TF_CIT_SETUP_DRV(tpg_nacl_param, &target_fabric_nacl_param_item_ops, NULL);
308 322
309/* End of tfc_tpg_nacl_param_cit */ 323/* End of tfc_tpg_nacl_param_cit */
310 324
@@ -461,8 +475,8 @@ static struct configfs_group_operations target_fabric_nacl_base_group_ops = {
461 .drop_item = target_fabric_drop_mappedlun, 475 .drop_item = target_fabric_drop_mappedlun,
462}; 476};
463 477
464TF_CIT_SETUP(tpg_nacl_base, &target_fabric_nacl_base_item_ops, 478TF_CIT_SETUP_DRV(tpg_nacl_base, &target_fabric_nacl_base_item_ops,
465 &target_fabric_nacl_base_group_ops, NULL); 479 &target_fabric_nacl_base_group_ops);
466 480
467/* End of tfc_tpg_nacl_base_cit */ 481/* End of tfc_tpg_nacl_base_cit */
468 482
@@ -570,7 +584,7 @@ static struct configfs_item_operations target_fabric_np_base_item_ops = {
570 .store_attribute = target_fabric_np_base_attr_store, 584 .store_attribute = target_fabric_np_base_attr_store,
571}; 585};
572 586
573TF_CIT_SETUP(tpg_np_base, &target_fabric_np_base_item_ops, NULL, NULL); 587TF_CIT_SETUP_DRV(tpg_np_base, &target_fabric_np_base_item_ops, NULL);
574 588
575/* End of tfc_tpg_np_base_cit */ 589/* End of tfc_tpg_np_base_cit */
576 590
@@ -966,7 +980,7 @@ static struct configfs_item_operations target_fabric_tpg_attrib_item_ops = {
966 .store_attribute = target_fabric_tpg_attrib_attr_store, 980 .store_attribute = target_fabric_tpg_attrib_attr_store,
967}; 981};
968 982
969TF_CIT_SETUP(tpg_attrib, &target_fabric_tpg_attrib_item_ops, NULL, NULL); 983TF_CIT_SETUP_DRV(tpg_attrib, &target_fabric_tpg_attrib_item_ops, NULL);
970 984
971/* End of tfc_tpg_attrib_cit */ 985/* End of tfc_tpg_attrib_cit */
972 986
@@ -979,7 +993,7 @@ static struct configfs_item_operations target_fabric_tpg_auth_item_ops = {
979 .store_attribute = target_fabric_tpg_auth_attr_store, 993 .store_attribute = target_fabric_tpg_auth_attr_store,
980}; 994};
981 995
982TF_CIT_SETUP(tpg_auth, &target_fabric_tpg_auth_item_ops, NULL, NULL); 996TF_CIT_SETUP_DRV(tpg_auth, &target_fabric_tpg_auth_item_ops, NULL);
983 997
984/* End of tfc_tpg_attrib_cit */ 998/* End of tfc_tpg_attrib_cit */
985 999
@@ -992,7 +1006,7 @@ static struct configfs_item_operations target_fabric_tpg_param_item_ops = {
992 .store_attribute = target_fabric_tpg_param_attr_store, 1006 .store_attribute = target_fabric_tpg_param_attr_store,
993}; 1007};
994 1008
995TF_CIT_SETUP(tpg_param, &target_fabric_tpg_param_item_ops, NULL, NULL); 1009TF_CIT_SETUP_DRV(tpg_param, &target_fabric_tpg_param_item_ops, NULL);
996 1010
997/* End of tfc_tpg_param_cit */ 1011/* End of tfc_tpg_param_cit */
998 1012
@@ -1018,7 +1032,7 @@ static struct configfs_item_operations target_fabric_tpg_base_item_ops = {
1018 .store_attribute = target_fabric_tpg_attr_store, 1032 .store_attribute = target_fabric_tpg_attr_store,
1019}; 1033};
1020 1034
1021TF_CIT_SETUP(tpg_base, &target_fabric_tpg_base_item_ops, NULL, NULL); 1035TF_CIT_SETUP_DRV(tpg_base, &target_fabric_tpg_base_item_ops, NULL);
1022 1036
1023/* End of tfc_tpg_base_cit */ 1037/* End of tfc_tpg_base_cit */
1024 1038
@@ -1192,7 +1206,7 @@ static struct configfs_item_operations target_fabric_wwn_item_ops = {
1192 .store_attribute = target_fabric_wwn_attr_store, 1206 .store_attribute = target_fabric_wwn_attr_store,
1193}; 1207};
1194 1208
1195TF_CIT_SETUP(wwn, &target_fabric_wwn_item_ops, &target_fabric_wwn_group_ops, NULL); 1209TF_CIT_SETUP_DRV(wwn, &target_fabric_wwn_item_ops, &target_fabric_wwn_group_ops);
1196 1210
1197/* End of tfc_wwn_cit */ 1211/* End of tfc_wwn_cit */
1198 1212
@@ -1206,7 +1220,7 @@ static struct configfs_item_operations target_fabric_discovery_item_ops = {
1206 .store_attribute = target_fabric_discovery_attr_store, 1220 .store_attribute = target_fabric_discovery_attr_store,
1207}; 1221};
1208 1222
1209TF_CIT_SETUP(discovery, &target_fabric_discovery_item_ops, NULL, NULL); 1223TF_CIT_SETUP_DRV(discovery, &target_fabric_discovery_item_ops, NULL);
1210 1224
1211/* End of tfc_discovery_cit */ 1225/* End of tfc_discovery_cit */
1212 1226
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 7436fdaaad12..963a67729b65 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -680,7 +680,7 @@ static struct t10_pr_registration *__core_scsi3_alloc_registration(
680 struct se_dev_entry *deve_tmp; 680 struct se_dev_entry *deve_tmp;
681 struct se_node_acl *nacl_tmp; 681 struct se_node_acl *nacl_tmp;
682 struct se_port *port, *port_tmp; 682 struct se_port *port, *port_tmp;
683 struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; 683 const struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo;
684 struct t10_pr_registration *pr_reg, *pr_reg_atp, *pr_reg_tmp, *pr_reg_tmp_safe; 684 struct t10_pr_registration *pr_reg, *pr_reg_atp, *pr_reg_tmp, *pr_reg_tmp_safe;
685 int ret; 685 int ret;
686 /* 686 /*
@@ -979,7 +979,7 @@ int core_scsi3_check_aptpl_registration(
979} 979}
980 980
981static void __core_scsi3_dump_registration( 981static void __core_scsi3_dump_registration(
982 struct target_core_fabric_ops *tfo, 982 const struct target_core_fabric_ops *tfo,
983 struct se_device *dev, 983 struct se_device *dev,
984 struct se_node_acl *nacl, 984 struct se_node_acl *nacl,
985 struct t10_pr_registration *pr_reg, 985 struct t10_pr_registration *pr_reg,
@@ -1020,7 +1020,7 @@ static void __core_scsi3_add_registration(
1020 enum register_type register_type, 1020 enum register_type register_type,
1021 int register_move) 1021 int register_move)
1022{ 1022{
1023 struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; 1023 const struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo;
1024 struct t10_pr_registration *pr_reg_tmp, *pr_reg_tmp_safe; 1024 struct t10_pr_registration *pr_reg_tmp, *pr_reg_tmp_safe;
1025 struct t10_reservation *pr_tmpl = &dev->t10_pr; 1025 struct t10_reservation *pr_tmpl = &dev->t10_pr;
1026 1026
@@ -1237,7 +1237,7 @@ static void __core_scsi3_free_registration(
1237 struct list_head *preempt_and_abort_list, 1237 struct list_head *preempt_and_abort_list,
1238 int dec_holders) 1238 int dec_holders)
1239{ 1239{
1240 struct target_core_fabric_ops *tfo = 1240 const struct target_core_fabric_ops *tfo =
1241 pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo; 1241 pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo;
1242 struct t10_reservation *pr_tmpl = &dev->t10_pr; 1242 struct t10_reservation *pr_tmpl = &dev->t10_pr;
1243 char i_buf[PR_REG_ISID_ID_LEN]; 1243 char i_buf[PR_REG_ISID_ID_LEN];
@@ -1461,7 +1461,7 @@ core_scsi3_decode_spec_i_port(
1461 struct t10_pr_registration *pr_reg_tmp, *pr_reg_tmp_safe; 1461 struct t10_pr_registration *pr_reg_tmp, *pr_reg_tmp_safe;
1462 LIST_HEAD(tid_dest_list); 1462 LIST_HEAD(tid_dest_list);
1463 struct pr_transport_id_holder *tidh_new, *tidh, *tidh_tmp; 1463 struct pr_transport_id_holder *tidh_new, *tidh, *tidh_tmp;
1464 struct target_core_fabric_ops *tmp_tf_ops; 1464 const struct target_core_fabric_ops *tmp_tf_ops;
1465 unsigned char *buf; 1465 unsigned char *buf;
1466 unsigned char *ptr, *i_str = NULL, proto_ident, tmp_proto_ident; 1466 unsigned char *ptr, *i_str = NULL, proto_ident, tmp_proto_ident;
1467 char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN]; 1467 char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN];
@@ -2422,7 +2422,7 @@ static void __core_scsi3_complete_pro_release(
2422 int explicit, 2422 int explicit,
2423 int unreg) 2423 int unreg)
2424{ 2424{
2425 struct target_core_fabric_ops *tfo = se_nacl->se_tpg->se_tpg_tfo; 2425 const struct target_core_fabric_ops *tfo = se_nacl->se_tpg->se_tpg_tfo;
2426 char i_buf[PR_REG_ISID_ID_LEN]; 2426 char i_buf[PR_REG_ISID_ID_LEN];
2427 int pr_res_type = 0, pr_res_scope = 0; 2427 int pr_res_type = 0, pr_res_scope = 0;
2428 2428
@@ -2734,7 +2734,7 @@ static void __core_scsi3_complete_pro_preempt(
2734 enum preempt_type preempt_type) 2734 enum preempt_type preempt_type)
2735{ 2735{
2736 struct se_node_acl *nacl = pr_reg->pr_reg_nacl; 2736 struct se_node_acl *nacl = pr_reg->pr_reg_nacl;
2737 struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; 2737 const struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo;
2738 char i_buf[PR_REG_ISID_ID_LEN]; 2738 char i_buf[PR_REG_ISID_ID_LEN];
2739 2739
2740 memset(i_buf, 0, PR_REG_ISID_ID_LEN); 2740 memset(i_buf, 0, PR_REG_ISID_ID_LEN);
@@ -3119,7 +3119,7 @@ core_scsi3_emulate_pro_register_and_move(struct se_cmd *cmd, u64 res_key,
3119 struct se_node_acl *pr_res_nacl, *pr_reg_nacl, *dest_node_acl = NULL; 3119 struct se_node_acl *pr_res_nacl, *pr_reg_nacl, *dest_node_acl = NULL;
3120 struct se_port *se_port; 3120 struct se_port *se_port;
3121 struct se_portal_group *se_tpg, *dest_se_tpg = NULL; 3121 struct se_portal_group *se_tpg, *dest_se_tpg = NULL;
3122 struct target_core_fabric_ops *dest_tf_ops = NULL, *tf_ops; 3122 const struct target_core_fabric_ops *dest_tf_ops = NULL, *tf_ops;
3123 struct t10_pr_registration *pr_reg, *pr_res_holder, *dest_pr_reg; 3123 struct t10_pr_registration *pr_reg, *pr_res_holder, *dest_pr_reg;
3124 struct t10_reservation *pr_tmpl = &dev->t10_pr; 3124 struct t10_reservation *pr_tmpl = &dev->t10_pr;
3125 unsigned char *buf; 3125 unsigned char *buf;
diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c
index 0696de9553d3..47f064415bf6 100644
--- a/drivers/target/target_core_tpg.c
+++ b/drivers/target/target_core_tpg.c
@@ -672,7 +672,7 @@ static int core_tpg_setup_virtual_lun0(struct se_portal_group *se_tpg)
672} 672}
673 673
674int core_tpg_register( 674int core_tpg_register(
675 struct target_core_fabric_ops *tfo, 675 const struct target_core_fabric_ops *tfo,
676 struct se_wwn *se_wwn, 676 struct se_wwn *se_wwn,
677 struct se_portal_group *se_tpg, 677 struct se_portal_group *se_tpg,
678 void *tpg_fabric_ptr, 678 void *tpg_fabric_ptr,
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index b671ebbe1df6..f884198a8511 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -322,7 +322,7 @@ void __transport_register_session(
322 struct se_session *se_sess, 322 struct se_session *se_sess,
323 void *fabric_sess_ptr) 323 void *fabric_sess_ptr)
324{ 324{
325 struct target_core_fabric_ops *tfo = se_tpg->se_tpg_tfo; 325 const struct target_core_fabric_ops *tfo = se_tpg->se_tpg_tfo;
326 unsigned char buf[PR_REG_ISID_LEN]; 326 unsigned char buf[PR_REG_ISID_LEN];
327 327
328 se_sess->se_tpg = se_tpg; 328 se_sess->se_tpg = se_tpg;
@@ -494,7 +494,7 @@ EXPORT_SYMBOL(transport_free_session);
494void transport_deregister_session(struct se_session *se_sess) 494void transport_deregister_session(struct se_session *se_sess)
495{ 495{
496 struct se_portal_group *se_tpg = se_sess->se_tpg; 496 struct se_portal_group *se_tpg = se_sess->se_tpg;
497 struct target_core_fabric_ops *se_tfo; 497 const struct target_core_fabric_ops *se_tfo;
498 struct se_node_acl *se_nacl; 498 struct se_node_acl *se_nacl;
499 unsigned long flags; 499 unsigned long flags;
500 bool comp_nacl = true; 500 bool comp_nacl = true;
@@ -1150,7 +1150,7 @@ target_cmd_size_check(struct se_cmd *cmd, unsigned int size)
1150 */ 1150 */
1151void transport_init_se_cmd( 1151void transport_init_se_cmd(
1152 struct se_cmd *cmd, 1152 struct se_cmd *cmd,
1153 struct target_core_fabric_ops *tfo, 1153 const struct target_core_fabric_ops *tfo,
1154 struct se_session *se_sess, 1154 struct se_session *se_sess,
1155 u32 data_length, 1155 u32 data_length,
1156 int data_direction, 1156 int data_direction,
diff --git a/drivers/target/target_core_xcopy.c b/drivers/target/target_core_xcopy.c
index 8585acba6fc9..a600ff15dcfd 100644
--- a/drivers/target/target_core_xcopy.c
+++ b/drivers/target/target_core_xcopy.c
@@ -425,7 +425,7 @@ static int xcopy_pt_queue_status(struct se_cmd *se_cmd)
425 return 0; 425 return 0;
426} 426}
427 427
428static struct target_core_fabric_ops xcopy_pt_tfo = { 428static const struct target_core_fabric_ops xcopy_pt_tfo = {
429 .get_fabric_name = xcopy_pt_get_fabric_name, 429 .get_fabric_name = xcopy_pt_get_fabric_name,
430 .get_task_tag = xcopy_pt_get_tag, 430 .get_task_tag = xcopy_pt_get_tag,
431 .get_cmd_state = xcopy_pt_get_cmd_state, 431 .get_cmd_state = xcopy_pt_get_cmd_state,
diff --git a/drivers/target/tcm_fc/tcm_fc.h b/drivers/target/tcm_fc/tcm_fc.h
index a0bcfd3e7e7d..881deb3d499a 100644
--- a/drivers/target/tcm_fc/tcm_fc.h
+++ b/drivers/target/tcm_fc/tcm_fc.h
@@ -129,7 +129,6 @@ struct ft_cmd {
129 129
130extern struct mutex ft_lport_lock; 130extern struct mutex ft_lport_lock;
131extern struct fc4_prov ft_prov; 131extern struct fc4_prov ft_prov;
132extern struct target_fabric_configfs *ft_configfs;
133extern unsigned int ft_debug_logging; 132extern unsigned int ft_debug_logging;
134 133
135/* 134/*
diff --git a/drivers/target/tcm_fc/tfc_conf.c b/drivers/target/tcm_fc/tfc_conf.c
index efdcb9663a1a..65dce1345966 100644
--- a/drivers/target/tcm_fc/tfc_conf.c
+++ b/drivers/target/tcm_fc/tfc_conf.c
@@ -48,7 +48,7 @@
48 48
49#include "tcm_fc.h" 49#include "tcm_fc.h"
50 50
51struct target_fabric_configfs *ft_configfs; 51static const struct target_core_fabric_ops ft_fabric_ops;
52 52
53static LIST_HEAD(ft_wwn_list); 53static LIST_HEAD(ft_wwn_list);
54DEFINE_MUTEX(ft_lport_lock); 54DEFINE_MUTEX(ft_lport_lock);
@@ -337,7 +337,7 @@ static struct se_portal_group *ft_add_tpg(
337 return NULL; 337 return NULL;
338 } 338 }
339 339
340 ret = core_tpg_register(&ft_configfs->tf_ops, wwn, &tpg->se_tpg, 340 ret = core_tpg_register(&ft_fabric_ops, wwn, &tpg->se_tpg,
341 tpg, TRANSPORT_TPG_TYPE_NORMAL); 341 tpg, TRANSPORT_TPG_TYPE_NORMAL);
342 if (ret < 0) { 342 if (ret < 0) {
343 destroy_workqueue(wq); 343 destroy_workqueue(wq);
@@ -507,7 +507,9 @@ static u32 ft_tpg_get_inst_index(struct se_portal_group *se_tpg)
507 return tpg->index; 507 return tpg->index;
508} 508}
509 509
510static struct target_core_fabric_ops ft_fabric_ops = { 510static const struct target_core_fabric_ops ft_fabric_ops = {
511 .module = THIS_MODULE,
512 .name = "fc",
511 .get_fabric_name = ft_get_fabric_name, 513 .get_fabric_name = ft_get_fabric_name,
512 .get_fabric_proto_ident = fc_get_fabric_proto_ident, 514 .get_fabric_proto_ident = fc_get_fabric_proto_ident,
513 .tpg_get_wwn = ft_get_fabric_wwn, 515 .tpg_get_wwn = ft_get_fabric_wwn,
@@ -552,62 +554,10 @@ static struct target_core_fabric_ops ft_fabric_ops = {
552 .fabric_drop_np = NULL, 554 .fabric_drop_np = NULL,
553 .fabric_make_nodeacl = &ft_add_acl, 555 .fabric_make_nodeacl = &ft_add_acl,
554 .fabric_drop_nodeacl = &ft_del_acl, 556 .fabric_drop_nodeacl = &ft_del_acl,
555};
556
557static int ft_register_configfs(void)
558{
559 struct target_fabric_configfs *fabric;
560 int ret;
561
562 /*
563 * Register the top level struct config_item_type with TCM core
564 */
565 fabric = target_fabric_configfs_init(THIS_MODULE, "fc");
566 if (IS_ERR(fabric)) {
567 pr_err("%s: target_fabric_configfs_init() failed!\n",
568 __func__);
569 return PTR_ERR(fabric);
570 }
571 fabric->tf_ops = ft_fabric_ops;
572
573 /*
574 * Setup default attribute lists for various fabric->tf_cit_tmpl
575 */
576 fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = ft_wwn_attrs;
577 fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = NULL;
578 fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL;
579 fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
580 fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
581 fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs =
582 ft_nacl_base_attrs;
583 fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
584 fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
585 fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL;
586 /*
587 * register the fabric for use within TCM
588 */
589 ret = target_fabric_configfs_register(fabric);
590 if (ret < 0) {
591 pr_debug("target_fabric_configfs_register() for"
592 " FC Target failed!\n");
593 target_fabric_configfs_free(fabric);
594 return -1;
595 }
596
597 /*
598 * Setup our local pointer to *fabric.
599 */
600 ft_configfs = fabric;
601 return 0;
602}
603 557
604static void ft_deregister_configfs(void) 558 .tfc_wwn_attrs = ft_wwn_attrs,
605{ 559 .tfc_tpg_nacl_base_attrs = ft_nacl_base_attrs,
606 if (!ft_configfs) 560};
607 return;
608 target_fabric_configfs_deregister(ft_configfs);
609 ft_configfs = NULL;
610}
611 561
612static struct notifier_block ft_notifier = { 562static struct notifier_block ft_notifier = {
613 .notifier_call = ft_lport_notify 563 .notifier_call = ft_lport_notify
@@ -615,15 +565,24 @@ static struct notifier_block ft_notifier = {
615 565
616static int __init ft_init(void) 566static int __init ft_init(void)
617{ 567{
618 if (ft_register_configfs()) 568 int ret;
619 return -1; 569
620 if (fc_fc4_register_provider(FC_TYPE_FCP, &ft_prov)) { 570 ret = target_register_template(&ft_fabric_ops);
621 ft_deregister_configfs(); 571 if (ret)
622 return -1; 572 goto out;
623 } 573
574 ret = fc_fc4_register_provider(FC_TYPE_FCP, &ft_prov);
575 if (ret)
576 goto out_unregister_template;
577
624 blocking_notifier_chain_register(&fc_lport_notifier_head, &ft_notifier); 578 blocking_notifier_chain_register(&fc_lport_notifier_head, &ft_notifier);
625 fc_lport_iterate(ft_lport_add, NULL); 579 fc_lport_iterate(ft_lport_add, NULL);
626 return 0; 580 return 0;
581
582out_unregister_template:
583 target_unregister_template(&ft_fabric_ops);
584out:
585 return ret;
627} 586}
628 587
629static void __exit ft_exit(void) 588static void __exit ft_exit(void)
@@ -632,7 +591,7 @@ static void __exit ft_exit(void)
632 &ft_notifier); 591 &ft_notifier);
633 fc_fc4_deregister_provider(FC_TYPE_FCP, &ft_prov); 592 fc_fc4_deregister_provider(FC_TYPE_FCP, &ft_prov);
634 fc_lport_iterate(ft_lport_del, NULL); 593 fc_lport_iterate(ft_lport_del, NULL);
635 ft_deregister_configfs(); 594 target_unregister_template(&ft_fabric_ops);
636 synchronize_rcu(); 595 synchronize_rcu();
637} 596}
638 597
diff --git a/drivers/usb/gadget/legacy/tcm_usb_gadget.c b/drivers/usb/gadget/legacy/tcm_usb_gadget.c
index 3a494168661e..7ea2a44cb228 100644
--- a/drivers/usb/gadget/legacy/tcm_usb_gadget.c
+++ b/drivers/usb/gadget/legacy/tcm_usb_gadget.c
@@ -29,7 +29,7 @@
29 29
30USB_GADGET_COMPOSITE_OPTIONS(); 30USB_GADGET_COMPOSITE_OPTIONS();
31 31
32static struct target_fabric_configfs *usbg_fabric_configfs; 32static const struct target_core_fabric_ops usbg_ops;
33 33
34static inline struct f_uas *to_f_uas(struct usb_function *f) 34static inline struct f_uas *to_f_uas(struct usb_function *f)
35{ 35{
@@ -1572,8 +1572,7 @@ static struct se_portal_group *usbg_make_tpg(
1572 tpg->tport = tport; 1572 tpg->tport = tport;
1573 tpg->tport_tpgt = tpgt; 1573 tpg->tport_tpgt = tpgt;
1574 1574
1575 ret = core_tpg_register(&usbg_fabric_configfs->tf_ops, wwn, 1575 ret = core_tpg_register(&usbg_ops, wwn, &tpg->se_tpg, tpg,
1576 &tpg->se_tpg, tpg,
1577 TRANSPORT_TPG_TYPE_NORMAL); 1576 TRANSPORT_TPG_TYPE_NORMAL);
1578 if (ret < 0) { 1577 if (ret < 0) {
1579 destroy_workqueue(tpg->workqueue); 1578 destroy_workqueue(tpg->workqueue);
@@ -1865,7 +1864,9 @@ static int usbg_check_stop_free(struct se_cmd *se_cmd)
1865 return 1; 1864 return 1;
1866} 1865}
1867 1866
1868static struct target_core_fabric_ops usbg_ops = { 1867static const struct target_core_fabric_ops usbg_ops = {
1868 .module = THIS_MODULE,
1869 .name = "usb_gadget",
1869 .get_fabric_name = usbg_get_fabric_name, 1870 .get_fabric_name = usbg_get_fabric_name,
1870 .get_fabric_proto_ident = usbg_get_fabric_proto_ident, 1871 .get_fabric_proto_ident = usbg_get_fabric_proto_ident,
1871 .tpg_get_wwn = usbg_get_fabric_wwn, 1872 .tpg_get_wwn = usbg_get_fabric_wwn,
@@ -1907,46 +1908,9 @@ static struct target_core_fabric_ops usbg_ops = {
1907 .fabric_drop_np = NULL, 1908 .fabric_drop_np = NULL,
1908 .fabric_make_nodeacl = usbg_make_nodeacl, 1909 .fabric_make_nodeacl = usbg_make_nodeacl,
1909 .fabric_drop_nodeacl = usbg_drop_nodeacl, 1910 .fabric_drop_nodeacl = usbg_drop_nodeacl,
1910};
1911
1912static int usbg_register_configfs(void)
1913{
1914 struct target_fabric_configfs *fabric;
1915 int ret;
1916
1917 fabric = target_fabric_configfs_init(THIS_MODULE, "usb_gadget");
1918 if (IS_ERR(fabric)) {
1919 printk(KERN_ERR "target_fabric_configfs_init() failed\n");
1920 return PTR_ERR(fabric);
1921 }
1922
1923 fabric->tf_ops = usbg_ops;
1924 fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = usbg_wwn_attrs;
1925 fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = usbg_base_attrs;
1926 fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL;
1927 fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
1928 fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
1929 fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL;
1930 fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
1931 fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
1932 fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL;
1933 ret = target_fabric_configfs_register(fabric);
1934 if (ret < 0) {
1935 printk(KERN_ERR "target_fabric_configfs_register() failed"
1936 " for usb-gadget\n");
1937 return ret;
1938 }
1939 usbg_fabric_configfs = fabric;
1940 return 0;
1941};
1942 1911
1943static void usbg_deregister_configfs(void) 1912 .tfc_wwn_attrs = usbg_wwn_attrs,
1944{ 1913 .tfc_tpg_base_attrs = usbg_base_attrs,
1945 if (!(usbg_fabric_configfs))
1946 return;
1947
1948 target_fabric_configfs_deregister(usbg_fabric_configfs);
1949 usbg_fabric_configfs = NULL;
1950}; 1914};
1951 1915
1952/* Start gadget.c code */ 1916/* Start gadget.c code */
@@ -2455,16 +2419,13 @@ static void usbg_detach(struct usbg_tpg *tpg)
2455 2419
2456static int __init usb_target_gadget_init(void) 2420static int __init usb_target_gadget_init(void)
2457{ 2421{
2458 int ret; 2422 return target_register_template(&usbg_ops);
2459
2460 ret = usbg_register_configfs();
2461 return ret;
2462} 2423}
2463module_init(usb_target_gadget_init); 2424module_init(usb_target_gadget_init);
2464 2425
2465static void __exit usb_target_gadget_exit(void) 2426static void __exit usb_target_gadget_exit(void)
2466{ 2427{
2467 usbg_deregister_configfs(); 2428 target_unregister_template(&usbg_ops);
2468} 2429}
2469module_exit(usb_target_gadget_exit); 2430module_exit(usb_target_gadget_exit);
2470 2431
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index 27ed9642cc21..e8c88b453f79 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -216,9 +216,7 @@ struct vhost_scsi {
216 int vs_events_nr; /* num of pending events, protected by vq->mutex */ 216 int vs_events_nr; /* num of pending events, protected by vq->mutex */
217}; 217};
218 218
219/* Local pointer to allocated TCM configfs fabric module */ 219static struct target_core_fabric_ops vhost_scsi_ops;
220static struct target_fabric_configfs *vhost_scsi_fabric_configfs;
221
222static struct workqueue_struct *vhost_scsi_workqueue; 220static struct workqueue_struct *vhost_scsi_workqueue;
223 221
224/* Global spinlock to protect vhost_scsi TPG list for vhost IOCTL access */ 222/* Global spinlock to protect vhost_scsi TPG list for vhost IOCTL access */
@@ -2205,7 +2203,7 @@ vhost_scsi_make_tpg(struct se_wwn *wwn,
2205 tpg->tport = tport; 2203 tpg->tport = tport;
2206 tpg->tport_tpgt = tpgt; 2204 tpg->tport_tpgt = tpgt;
2207 2205
2208 ret = core_tpg_register(&vhost_scsi_fabric_configfs->tf_ops, wwn, 2206 ret = core_tpg_register(&vhost_scsi_ops, wwn,
2209 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL); 2207 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL);
2210 if (ret < 0) { 2208 if (ret < 0) {
2211 kfree(tpg); 2209 kfree(tpg);
@@ -2327,6 +2325,8 @@ static struct configfs_attribute *vhost_scsi_wwn_attrs[] = {
2327}; 2325};
2328 2326
2329static struct target_core_fabric_ops vhost_scsi_ops = { 2327static struct target_core_fabric_ops vhost_scsi_ops = {
2328 .module = THIS_MODULE,
2329 .name = "vhost",
2330 .get_fabric_name = vhost_scsi_get_fabric_name, 2330 .get_fabric_name = vhost_scsi_get_fabric_name,
2331 .get_fabric_proto_ident = vhost_scsi_get_fabric_proto_ident, 2331 .get_fabric_proto_ident = vhost_scsi_get_fabric_proto_ident,
2332 .tpg_get_wwn = vhost_scsi_get_fabric_wwn, 2332 .tpg_get_wwn = vhost_scsi_get_fabric_wwn,
@@ -2371,70 +2371,20 @@ static struct target_core_fabric_ops vhost_scsi_ops = {
2371 .fabric_drop_np = NULL, 2371 .fabric_drop_np = NULL,
2372 .fabric_make_nodeacl = vhost_scsi_make_nodeacl, 2372 .fabric_make_nodeacl = vhost_scsi_make_nodeacl,
2373 .fabric_drop_nodeacl = vhost_scsi_drop_nodeacl, 2373 .fabric_drop_nodeacl = vhost_scsi_drop_nodeacl,
2374
2375 .tfc_wwn_attrs = vhost_scsi_wwn_attrs,
2376 .tfc_tpg_base_attrs = vhost_scsi_tpg_attrs,
2377 .tfc_tpg_attrib_attrs = vhost_scsi_tpg_attrib_attrs,
2374}; 2378};
2375 2379
2376static int vhost_scsi_register_configfs(void) 2380static int __init vhost_scsi_init(void)
2377{ 2381{
2378 struct target_fabric_configfs *fabric; 2382 int ret = -ENOMEM;
2379 int ret;
2380 2383
2381 pr_debug("vhost-scsi fabric module %s on %s/%s" 2384 pr_debug("TCM_VHOST fabric module %s on %s/%s"
2382 " on "UTS_RELEASE"\n", VHOST_SCSI_VERSION, utsname()->sysname, 2385 " on "UTS_RELEASE"\n", VHOST_SCSI_VERSION, utsname()->sysname,
2383 utsname()->machine); 2386 utsname()->machine);
2384 /*
2385 * Register the top level struct config_item_type with TCM core
2386 */
2387 fabric = target_fabric_configfs_init(THIS_MODULE, "vhost");
2388 if (IS_ERR(fabric)) {
2389 pr_err("target_fabric_configfs_init() failed\n");
2390 return PTR_ERR(fabric);
2391 }
2392 /*
2393 * Setup fabric->tf_ops from our local vhost_scsi_ops
2394 */
2395 fabric->tf_ops = vhost_scsi_ops;
2396 /*
2397 * Setup default attribute lists for various fabric->tf_cit_tmpl
2398 */
2399 fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = vhost_scsi_wwn_attrs;
2400 fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = vhost_scsi_tpg_attrs;
2401 fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = vhost_scsi_tpg_attrib_attrs;
2402 fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = NULL;
2403 fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
2404 fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL;
2405 fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
2406 fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
2407 fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL;
2408 /*
2409 * Register the fabric for use within TCM
2410 */
2411 ret = target_fabric_configfs_register(fabric);
2412 if (ret < 0) {
2413 pr_err("target_fabric_configfs_register() failed"
2414 " for TCM_VHOST\n");
2415 return ret;
2416 }
2417 /*
2418 * Setup our local pointer to *fabric
2419 */
2420 vhost_scsi_fabric_configfs = fabric;
2421 pr_debug("TCM_VHOST[0] - Set fabric -> vhost_scsi_fabric_configfs\n");
2422 return 0;
2423};
2424
2425static void vhost_scsi_deregister_configfs(void)
2426{
2427 if (!vhost_scsi_fabric_configfs)
2428 return;
2429
2430 target_fabric_configfs_deregister(vhost_scsi_fabric_configfs);
2431 vhost_scsi_fabric_configfs = NULL;
2432 pr_debug("TCM_VHOST[0] - Cleared vhost_scsi_fabric_configfs\n");
2433};
2434 2387
2435static int __init vhost_scsi_init(void)
2436{
2437 int ret = -ENOMEM;
2438 /* 2388 /*
2439 * Use our own dedicated workqueue for submitting I/O into 2389 * Use our own dedicated workqueue for submitting I/O into
2440 * target core to avoid contention within system_wq. 2390 * target core to avoid contention within system_wq.
@@ -2447,7 +2397,7 @@ static int __init vhost_scsi_init(void)
2447 if (ret < 0) 2397 if (ret < 0)
2448 goto out_destroy_workqueue; 2398 goto out_destroy_workqueue;
2449 2399
2450 ret = vhost_scsi_register_configfs(); 2400 ret = target_register_template(&vhost_scsi_ops);
2451 if (ret < 0) 2401 if (ret < 0)
2452 goto out_vhost_scsi_deregister; 2402 goto out_vhost_scsi_deregister;
2453 2403
@@ -2463,7 +2413,7 @@ out:
2463 2413
2464static void vhost_scsi_exit(void) 2414static void vhost_scsi_exit(void)
2465{ 2415{
2466 vhost_scsi_deregister_configfs(); 2416 target_unregister_template(&vhost_scsi_ops);
2467 vhost_scsi_deregister(); 2417 vhost_scsi_deregister();
2468 destroy_workqueue(vhost_scsi_workqueue); 2418 destroy_workqueue(vhost_scsi_workqueue);
2469}; 2419};
diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c
index 61653a03a8f5..f8a1bd741b5d 100644
--- a/drivers/xen/xen-scsiback.c
+++ b/drivers/xen/xen-scsiback.c
@@ -205,8 +205,7 @@ static LIST_HEAD(scsiback_free_pages);
205static DEFINE_MUTEX(scsiback_mutex); 205static DEFINE_MUTEX(scsiback_mutex);
206static LIST_HEAD(scsiback_list); 206static LIST_HEAD(scsiback_list);
207 207
208/* Local pointer to allocated TCM configfs fabric module */ 208static const struct target_core_fabric_ops scsiback_ops;
209static struct target_fabric_configfs *scsiback_fabric_configfs;
210 209
211static void scsiback_get(struct vscsibk_info *info) 210static void scsiback_get(struct vscsibk_info *info)
212{ 211{
@@ -1901,7 +1900,7 @@ scsiback_make_tpg(struct se_wwn *wwn,
1901 tpg->tport = tport; 1900 tpg->tport = tport;
1902 tpg->tport_tpgt = tpgt; 1901 tpg->tport_tpgt = tpgt;
1903 1902
1904 ret = core_tpg_register(&scsiback_fabric_configfs->tf_ops, wwn, 1903 ret = core_tpg_register(&scsiback_ops, wwn,
1905 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL); 1904 &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL);
1906 if (ret < 0) { 1905 if (ret < 0) {
1907 kfree(tpg); 1906 kfree(tpg);
@@ -1943,7 +1942,9 @@ static int scsiback_check_false(struct se_portal_group *se_tpg)
1943 return 0; 1942 return 0;
1944} 1943}
1945 1944
1946static struct target_core_fabric_ops scsiback_ops = { 1945static const struct target_core_fabric_ops scsiback_ops = {
1946 .module = THIS_MODULE,
1947 .name = "xen-pvscsi",
1947 .get_fabric_name = scsiback_get_fabric_name, 1948 .get_fabric_name = scsiback_get_fabric_name,
1948 .get_fabric_proto_ident = scsiback_get_fabric_proto_ident, 1949 .get_fabric_proto_ident = scsiback_get_fabric_proto_ident,
1949 .tpg_get_wwn = scsiback_get_fabric_wwn, 1950 .tpg_get_wwn = scsiback_get_fabric_wwn,
@@ -1990,62 +1991,10 @@ static struct target_core_fabric_ops scsiback_ops = {
1990 .fabric_make_nodeacl = scsiback_make_nodeacl, 1991 .fabric_make_nodeacl = scsiback_make_nodeacl,
1991 .fabric_drop_nodeacl = scsiback_drop_nodeacl, 1992 .fabric_drop_nodeacl = scsiback_drop_nodeacl,
1992#endif 1993#endif
1993};
1994
1995static int scsiback_register_configfs(void)
1996{
1997 struct target_fabric_configfs *fabric;
1998 int ret;
1999 1994
2000 pr_debug("xen-pvscsi: fabric module %s on %s/%s on "UTS_RELEASE"\n", 1995 .tfc_wwn_attrs = scsiback_wwn_attrs,
2001 VSCSI_VERSION, utsname()->sysname, utsname()->machine); 1996 .tfc_tpg_base_attrs = scsiback_tpg_attrs,
2002 /* 1997 .tfc_tpg_param_attrs = scsiback_param_attrs,
2003 * Register the top level struct config_item_type with TCM core
2004 */
2005 fabric = target_fabric_configfs_init(THIS_MODULE, "xen-pvscsi");
2006 if (IS_ERR(fabric))
2007 return PTR_ERR(fabric);
2008
2009 /*
2010 * Setup fabric->tf_ops from our local scsiback_ops
2011 */
2012 fabric->tf_ops = scsiback_ops;
2013 /*
2014 * Setup default attribute lists for various fabric->tf_cit_tmpl
2015 */
2016 fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = scsiback_wwn_attrs;
2017 fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = scsiback_tpg_attrs;
2018 fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = NULL;
2019 fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = scsiback_param_attrs;
2020 fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = NULL;
2021 fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = NULL;
2022 fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;
2023 fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = NULL;
2024 fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = NULL;
2025 /*
2026 * Register the fabric for use within TCM
2027 */
2028 ret = target_fabric_configfs_register(fabric);
2029 if (ret < 0) {
2030 target_fabric_configfs_free(fabric);
2031 return ret;
2032 }
2033 /*
2034 * Setup our local pointer to *fabric
2035 */
2036 scsiback_fabric_configfs = fabric;
2037 pr_debug("xen-pvscsi: Set fabric -> scsiback_fabric_configfs\n");
2038 return 0;
2039};
2040
2041static void scsiback_deregister_configfs(void)
2042{
2043 if (!scsiback_fabric_configfs)
2044 return;
2045
2046 target_fabric_configfs_deregister(scsiback_fabric_configfs);
2047 scsiback_fabric_configfs = NULL;
2048 pr_debug("xen-pvscsi: Cleared scsiback_fabric_configfs\n");
2049}; 1998};
2050 1999
2051static const struct xenbus_device_id scsiback_ids[] = { 2000static const struct xenbus_device_id scsiback_ids[] = {
@@ -2077,6 +2026,9 @@ static int __init scsiback_init(void)
2077 if (!xen_domain()) 2026 if (!xen_domain())
2078 return -ENODEV; 2027 return -ENODEV;
2079 2028
2029 pr_debug("xen-pvscsi: fabric module %s on %s/%s on "UTS_RELEASE"\n",
2030 VSCSI_VERSION, utsname()->sysname, utsname()->machine);
2031
2080 scsiback_cachep = kmem_cache_create("vscsiif_cache", 2032 scsiback_cachep = kmem_cache_create("vscsiif_cache",
2081 sizeof(struct vscsibk_pend), 0, 0, scsiback_init_pend); 2033 sizeof(struct vscsibk_pend), 0, 0, scsiback_init_pend);
2082 if (!scsiback_cachep) 2034 if (!scsiback_cachep)
@@ -2086,7 +2038,7 @@ static int __init scsiback_init(void)
2086 if (ret) 2038 if (ret)
2087 goto out_cache_destroy; 2039 goto out_cache_destroy;
2088 2040
2089 ret = scsiback_register_configfs(); 2041 ret = target_register_template(&scsiback_ops);
2090 if (ret) 2042 if (ret)
2091 goto out_unregister_xenbus; 2043 goto out_unregister_xenbus;
2092 2044
@@ -2109,7 +2061,7 @@ static void __exit scsiback_exit(void)
2109 BUG(); 2061 BUG();
2110 gnttab_free_pages(1, &page); 2062 gnttab_free_pages(1, &page);
2111 } 2063 }
2112 scsiback_deregister_configfs(); 2064 target_unregister_template(&scsiback_ops);
2113 xenbus_unregister_driver(&scsiback_driver); 2065 xenbus_unregister_driver(&scsiback_driver);
2114 kmem_cache_destroy(scsiback_cachep); 2066 kmem_cache_destroy(scsiback_cachep);
2115} 2067}
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index 71699cf3cc71..383110d608a0 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -519,7 +519,7 @@ struct se_cmd {
519 struct list_head se_cmd_list; 519 struct list_head se_cmd_list;
520 struct completion cmd_wait_comp; 520 struct completion cmd_wait_comp;
521 struct kref cmd_kref; 521 struct kref cmd_kref;
522 struct target_core_fabric_ops *se_tfo; 522 const struct target_core_fabric_ops *se_tfo;
523 sense_reason_t (*execute_cmd)(struct se_cmd *); 523 sense_reason_t (*execute_cmd)(struct se_cmd *);
524 sense_reason_t (*execute_rw)(struct se_cmd *, struct scatterlist *, 524 sense_reason_t (*execute_rw)(struct se_cmd *, struct scatterlist *,
525 u32, enum dma_data_direction); 525 u32, enum dma_data_direction);
@@ -890,7 +890,7 @@ struct se_portal_group {
890 /* List of TCM sessions associated wth this TPG */ 890 /* List of TCM sessions associated wth this TPG */
891 struct list_head tpg_sess_list; 891 struct list_head tpg_sess_list;
892 /* Pointer to $FABRIC_MOD dependent code */ 892 /* Pointer to $FABRIC_MOD dependent code */
893 struct target_core_fabric_ops *se_tpg_tfo; 893 const struct target_core_fabric_ops *se_tpg_tfo;
894 struct se_wwn *se_tpg_wwn; 894 struct se_wwn *se_tpg_wwn;
895 struct config_group tpg_group; 895 struct config_group tpg_group;
896 struct config_group *tpg_default_groups[7]; 896 struct config_group *tpg_default_groups[7];
diff --git a/include/target/target_core_configfs.h b/include/target/target_core_configfs.h
index e0801386e4dc..25bb04c4209e 100644
--- a/include/target/target_core_configfs.h
+++ b/include/target/target_core_configfs.h
@@ -5,12 +5,6 @@
5#define TARGET_CORE_NAME_MAX_LEN 64 5#define TARGET_CORE_NAME_MAX_LEN 64
6#define TARGET_FABRIC_NAME_SIZE 32 6#define TARGET_FABRIC_NAME_SIZE 32
7 7
8extern struct target_fabric_configfs *target_fabric_configfs_init(
9 struct module *, const char *);
10extern void target_fabric_configfs_free(struct target_fabric_configfs *);
11extern int target_fabric_configfs_register(struct target_fabric_configfs *);
12extern void target_fabric_configfs_deregister(struct target_fabric_configfs *);
13
14struct target_fabric_configfs_template { 8struct target_fabric_configfs_template {
15 struct config_item_type tfc_discovery_cit; 9 struct config_item_type tfc_discovery_cit;
16 struct config_item_type tfc_wwn_cit; 10 struct config_item_type tfc_wwn_cit;
diff --git a/include/target/target_core_fabric.h b/include/target/target_core_fabric.h
index c93cfdf0d8e5..17c7f5ac7ea0 100644
--- a/include/target/target_core_fabric.h
+++ b/include/target/target_core_fabric.h
@@ -2,6 +2,8 @@
2#define TARGET_CORE_FABRIC_H 2#define TARGET_CORE_FABRIC_H
3 3
4struct target_core_fabric_ops { 4struct target_core_fabric_ops {
5 struct module *module;
6 const char *name;
5 struct configfs_subsystem *tf_subsys; 7 struct configfs_subsystem *tf_subsys;
6 char *(*get_fabric_name)(void); 8 char *(*get_fabric_name)(void);
7 u8 (*get_fabric_proto_ident)(struct se_portal_group *); 9 u8 (*get_fabric_proto_ident)(struct se_portal_group *);
@@ -90,8 +92,23 @@ struct target_core_fabric_ops {
90 struct se_node_acl *(*fabric_make_nodeacl)(struct se_portal_group *, 92 struct se_node_acl *(*fabric_make_nodeacl)(struct se_portal_group *,
91 struct config_group *, const char *); 93 struct config_group *, const char *);
92 void (*fabric_drop_nodeacl)(struct se_node_acl *); 94 void (*fabric_drop_nodeacl)(struct se_node_acl *);
95
96 struct configfs_attribute **tfc_discovery_attrs;
97 struct configfs_attribute **tfc_wwn_attrs;
98 struct configfs_attribute **tfc_tpg_base_attrs;
99 struct configfs_attribute **tfc_tpg_np_base_attrs;
100 struct configfs_attribute **tfc_tpg_attrib_attrs;
101 struct configfs_attribute **tfc_tpg_auth_attrs;
102 struct configfs_attribute **tfc_tpg_param_attrs;
103 struct configfs_attribute **tfc_tpg_nacl_base_attrs;
104 struct configfs_attribute **tfc_tpg_nacl_attrib_attrs;
105 struct configfs_attribute **tfc_tpg_nacl_auth_attrs;
106 struct configfs_attribute **tfc_tpg_nacl_param_attrs;
93}; 107};
94 108
109int target_register_template(const struct target_core_fabric_ops *fo);
110void target_unregister_template(const struct target_core_fabric_ops *fo);
111
95struct se_session *transport_init_session(enum target_prot_op); 112struct se_session *transport_init_session(enum target_prot_op);
96int transport_alloc_session_tags(struct se_session *, unsigned int, 113int transport_alloc_session_tags(struct se_session *, unsigned int,
97 unsigned int); 114 unsigned int);
@@ -110,7 +127,8 @@ void transport_deregister_session_configfs(struct se_session *);
110void transport_deregister_session(struct se_session *); 127void transport_deregister_session(struct se_session *);
111 128
112 129
113void transport_init_se_cmd(struct se_cmd *, struct target_core_fabric_ops *, 130void transport_init_se_cmd(struct se_cmd *,
131 const struct target_core_fabric_ops *,
114 struct se_session *, u32, int, int, unsigned char *); 132 struct se_session *, u32, int, int, unsigned char *);
115sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u32); 133sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u32);
116sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *); 134sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *);
@@ -162,8 +180,8 @@ int core_tpg_set_initiator_node_queue_depth(struct se_portal_group *,
162 unsigned char *, u32, int); 180 unsigned char *, u32, int);
163int core_tpg_set_initiator_node_tag(struct se_portal_group *, 181int core_tpg_set_initiator_node_tag(struct se_portal_group *,
164 struct se_node_acl *, const char *); 182 struct se_node_acl *, const char *);
165int core_tpg_register(struct target_core_fabric_ops *, struct se_wwn *, 183int core_tpg_register(const struct target_core_fabric_ops *,
166 struct se_portal_group *, void *, int); 184 struct se_wwn *, struct se_portal_group *, void *, int);
167int core_tpg_deregister(struct se_portal_group *); 185int core_tpg_deregister(struct se_portal_group *);
168 186
169/* SAS helpers */ 187/* SAS helpers */