aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/target/tcm_mod_builder.py
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 /Documentation/target/tcm_mod_builder.py
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>
Diffstat (limited to 'Documentation/target/tcm_mod_builder.py')
-rwxr-xr-xDocumentation/target/tcm_mod_builder.py79
1 files changed, 12 insertions, 67 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"