tcm_mod_builder.py 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965
  1. #!/usr/bin/python
  2. # The TCM v4 multi-protocol fabric module generation script for drivers/target/$NEW_MOD
  3. #
  4. # Copyright (c) 2010 Rising Tide Systems
  5. # Copyright (c) 2010 Linux-iSCSI.org
  6. #
  7. # Author: nab@kernel.org
  8. #
  9. import os, sys
  10. import subprocess as sub
  11. import string
  12. import re
  13. import optparse
  14. tcm_dir = ""
  15. fabric_ops = []
  16. fabric_mod_dir = ""
  17. fabric_mod_port = ""
  18. fabric_mod_init_port = ""
  19. def tcm_mod_err(msg):
  20. print msg
  21. sys.exit(1)
  22. def tcm_mod_create_module_subdir(fabric_mod_dir_var):
  23. if os.path.isdir(fabric_mod_dir_var) == True:
  24. return 1
  25. print "Creating fabric_mod_dir: " + fabric_mod_dir_var
  26. ret = os.mkdir(fabric_mod_dir_var)
  27. if ret:
  28. tcm_mod_err("Unable to mkdir " + fabric_mod_dir_var)
  29. return
  30. def tcm_mod_build_FC_include(fabric_mod_dir_var, fabric_mod_name):
  31. global fabric_mod_port
  32. global fabric_mod_init_port
  33. buf = ""
  34. f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
  35. print "Writing file: " + f
  36. p = open(f, 'w');
  37. if not p:
  38. tcm_mod_err("Unable to open file: " + f)
  39. buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
  40. buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
  41. buf += "\n"
  42. buf += "struct " + fabric_mod_name + "_nacl {\n"
  43. buf += " /* Binary World Wide unique Port Name for FC Initiator Nport */\n"
  44. buf += " u64 nport_wwpn;\n"
  45. buf += " /* ASCII formatted WWPN for FC Initiator Nport */\n"
  46. buf += " char nport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
  47. buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
  48. buf += " struct se_node_acl se_node_acl;\n"
  49. buf += "};\n"
  50. buf += "\n"
  51. buf += "struct " + fabric_mod_name + "_tpg {\n"
  52. buf += " /* FC lport target portal group tag for TCM */\n"
  53. buf += " u16 lport_tpgt;\n"
  54. buf += " /* Pointer back to " + fabric_mod_name + "_lport */\n"
  55. buf += " struct " + fabric_mod_name + "_lport *lport;\n"
  56. buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
  57. buf += " struct se_portal_group se_tpg;\n"
  58. buf += "};\n"
  59. buf += "\n"
  60. buf += "struct " + fabric_mod_name + "_lport {\n"
  61. buf += " /* SCSI protocol the lport is providing */\n"
  62. buf += " u8 lport_proto_id;\n"
  63. buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n"
  64. buf += " u64 lport_wwpn;\n"
  65. buf += " /* ASCII formatted WWPN for FC Target Lport */\n"
  66. buf += " char lport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
  67. buf += " /* Returned by " + fabric_mod_name + "_make_lport() */\n"
  68. buf += " struct se_wwn lport_wwn;\n"
  69. buf += "};\n"
  70. ret = p.write(buf)
  71. if ret:
  72. tcm_mod_err("Unable to write f: " + f)
  73. p.close()
  74. fabric_mod_port = "lport"
  75. fabric_mod_init_port = "nport"
  76. return
  77. def tcm_mod_build_SAS_include(fabric_mod_dir_var, fabric_mod_name):
  78. global fabric_mod_port
  79. global fabric_mod_init_port
  80. buf = ""
  81. f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
  82. print "Writing file: " + f
  83. p = open(f, 'w');
  84. if not p:
  85. tcm_mod_err("Unable to open file: " + f)
  86. buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
  87. buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
  88. buf += "\n"
  89. buf += "struct " + fabric_mod_name + "_nacl {\n"
  90. buf += " /* Binary World Wide unique Port Name for SAS Initiator port */\n"
  91. buf += " u64 iport_wwpn;\n"
  92. buf += " /* ASCII formatted WWPN for Sas Initiator port */\n"
  93. buf += " char iport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
  94. buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
  95. buf += " struct se_node_acl se_node_acl;\n"
  96. buf += "};\n\n"
  97. buf += "struct " + fabric_mod_name + "_tpg {\n"
  98. buf += " /* SAS port target portal group tag for TCM */\n"
  99. buf += " u16 tport_tpgt;\n"
  100. buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n"
  101. buf += " struct " + fabric_mod_name + "_tport *tport;\n"
  102. buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
  103. buf += " struct se_portal_group se_tpg;\n"
  104. buf += "};\n\n"
  105. buf += "struct " + fabric_mod_name + "_tport {\n"
  106. buf += " /* SCSI protocol the tport is providing */\n"
  107. buf += " u8 tport_proto_id;\n"
  108. buf += " /* Binary World Wide unique Port Name for SAS Target port */\n"
  109. buf += " u64 tport_wwpn;\n"
  110. buf += " /* ASCII formatted WWPN for SAS Target port */\n"
  111. buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
  112. buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n"
  113. buf += " struct se_wwn tport_wwn;\n"
  114. buf += "};\n"
  115. ret = p.write(buf)
  116. if ret:
  117. tcm_mod_err("Unable to write f: " + f)
  118. p.close()
  119. fabric_mod_port = "tport"
  120. fabric_mod_init_port = "iport"
  121. return
  122. def tcm_mod_build_iSCSI_include(fabric_mod_dir_var, fabric_mod_name):
  123. global fabric_mod_port
  124. global fabric_mod_init_port
  125. buf = ""
  126. f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
  127. print "Writing file: " + f
  128. p = open(f, 'w');
  129. if not p:
  130. tcm_mod_err("Unable to open file: " + f)
  131. buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
  132. buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
  133. buf += "\n"
  134. buf += "struct " + fabric_mod_name + "_nacl {\n"
  135. buf += " /* ASCII formatted InitiatorName */\n"
  136. buf += " char iport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
  137. buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n"
  138. buf += " struct se_node_acl se_node_acl;\n"
  139. buf += "};\n\n"
  140. buf += "struct " + fabric_mod_name + "_tpg {\n"
  141. buf += " /* iSCSI target portal group tag for TCM */\n"
  142. buf += " u16 tport_tpgt;\n"
  143. buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n"
  144. buf += " struct " + fabric_mod_name + "_tport *tport;\n"
  145. buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
  146. buf += " struct se_portal_group se_tpg;\n"
  147. buf += "};\n\n"
  148. buf += "struct " + fabric_mod_name + "_tport {\n"
  149. buf += " /* SCSI protocol the tport is providing */\n"
  150. buf += " u8 tport_proto_id;\n"
  151. buf += " /* ASCII formatted TargetName for IQN */\n"
  152. buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
  153. buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n"
  154. buf += " struct se_wwn tport_wwn;\n"
  155. buf += "};\n"
  156. ret = p.write(buf)
  157. if ret:
  158. tcm_mod_err("Unable to write f: " + f)
  159. p.close()
  160. fabric_mod_port = "tport"
  161. fabric_mod_init_port = "iport"
  162. return
  163. def tcm_mod_build_base_includes(proto_ident, fabric_mod_dir_val, fabric_mod_name):
  164. if proto_ident == "FC":
  165. tcm_mod_build_FC_include(fabric_mod_dir_val, fabric_mod_name)
  166. elif proto_ident == "SAS":
  167. tcm_mod_build_SAS_include(fabric_mod_dir_val, fabric_mod_name)
  168. elif proto_ident == "iSCSI":
  169. tcm_mod_build_iSCSI_include(fabric_mod_dir_val, fabric_mod_name)
  170. else:
  171. print "Unsupported proto_ident: " + proto_ident
  172. sys.exit(1)
  173. return
  174. def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
  175. buf = ""
  176. f = fabric_mod_dir_var + "/" + fabric_mod_name + "_configfs.c"
  177. print "Writing file: " + f
  178. p = open(f, 'w');
  179. if not p:
  180. tcm_mod_err("Unable to open file: " + f)
  181. buf = "#include <linux/module.h>\n"
  182. buf += "#include <linux/moduleparam.h>\n"
  183. buf += "#include <linux/version.h>\n"
  184. buf += "#include <generated/utsrelease.h>\n"
  185. buf += "#include <linux/utsname.h>\n"
  186. buf += "#include <linux/init.h>\n"
  187. buf += "#include <linux/slab.h>\n"
  188. buf += "#include <linux/kthread.h>\n"
  189. buf += "#include <linux/types.h>\n"
  190. buf += "#include <linux/string.h>\n"
  191. buf += "#include <linux/configfs.h>\n"
  192. buf += "#include <linux/ctype.h>\n"
  193. buf += "#include <asm/unaligned.h>\n\n"
  194. buf += "#include <target/target_core_base.h>\n"
  195. buf += "#include <target/target_core_fabric.h>\n"
  196. buf += "#include <target/target_core_fabric_configfs.h>\n"
  197. buf += "#include <target/target_core_configfs.h>\n"
  198. buf += "#include <target/configfs_macros.h>\n\n"
  199. buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
  200. buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
  201. buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops;\n\n"
  202. buf += "static struct se_node_acl *" + fabric_mod_name + "_make_nodeacl(\n"
  203. buf += " struct se_portal_group *se_tpg,\n"
  204. buf += " struct config_group *group,\n"
  205. buf += " const char *name)\n"
  206. buf += "{\n"
  207. buf += " struct se_node_acl *se_nacl, *se_nacl_new;\n"
  208. buf += " struct " + fabric_mod_name + "_nacl *nacl;\n"
  209. if proto_ident == "FC" or proto_ident == "SAS":
  210. buf += " u64 wwpn = 0;\n"
  211. buf += " u32 nexus_depth;\n\n"
  212. buf += " /* " + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"
  213. buf += " return ERR_PTR(-EINVAL); */\n"
  214. buf += " se_nacl_new = " + fabric_mod_name + "_alloc_fabric_acl(se_tpg);\n"
  215. buf += " if (!se_nacl_new)\n"
  216. buf += " return ERR_PTR(-ENOMEM);\n"
  217. buf += "//#warning FIXME: Hardcoded nexus depth in " + fabric_mod_name + "_make_nodeacl()\n"
  218. buf += " nexus_depth = 1;\n"
  219. buf += " /*\n"
  220. buf += " * se_nacl_new may be released by core_tpg_add_initiator_node_acl()\n"
  221. buf += " * when converting a NodeACL from demo mode -> explict\n"
  222. buf += " */\n"
  223. buf += " se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,\n"
  224. buf += " name, nexus_depth);\n"
  225. buf += " if (IS_ERR(se_nacl)) {\n"
  226. buf += " " + fabric_mod_name + "_release_fabric_acl(se_tpg, se_nacl_new);\n"
  227. buf += " return se_nacl;\n"
  228. buf += " }\n"
  229. buf += " /*\n"
  230. buf += " * Locate our struct " + fabric_mod_name + "_nacl and set the FC Nport WWPN\n"
  231. buf += " */\n"
  232. buf += " nacl = container_of(se_nacl, struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
  233. if proto_ident == "FC" or proto_ident == "SAS":
  234. buf += " nacl->" + fabric_mod_init_port + "_wwpn = wwpn;\n"
  235. buf += " /* " + fabric_mod_name + "_format_wwn(&nacl->" + fabric_mod_init_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"
  236. buf += " return se_nacl;\n"
  237. buf += "}\n\n"
  238. buf += "static void " + fabric_mod_name + "_drop_nodeacl(struct se_node_acl *se_acl)\n"
  239. buf += "{\n"
  240. buf += " struct " + fabric_mod_name + "_nacl *nacl = container_of(se_acl,\n"
  241. buf += " struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
  242. buf += " core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1);\n"
  243. buf += " kfree(nacl);\n"
  244. buf += "}\n\n"
  245. buf += "static struct se_portal_group *" + fabric_mod_name + "_make_tpg(\n"
  246. buf += " struct se_wwn *wwn,\n"
  247. buf += " struct config_group *group,\n"
  248. buf += " const char *name)\n"
  249. buf += "{\n"
  250. buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + "*" + fabric_mod_port + " = container_of(wwn,\n"
  251. buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n\n"
  252. buf += " struct " + fabric_mod_name + "_tpg *tpg;\n"
  253. buf += " unsigned long tpgt;\n"
  254. buf += " int ret;\n\n"
  255. buf += " if (strstr(name, \"tpgt_\") != name)\n"
  256. buf += " return ERR_PTR(-EINVAL);\n"
  257. buf += " if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)\n"
  258. buf += " return ERR_PTR(-EINVAL);\n\n"
  259. buf += " tpg = kzalloc(sizeof(struct " + fabric_mod_name + "_tpg), GFP_KERNEL);\n"
  260. buf += " if (!tpg) {\n"
  261. buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_tpg\");\n"
  262. buf += " return ERR_PTR(-ENOMEM);\n"
  263. buf += " }\n"
  264. buf += " tpg->" + fabric_mod_port + " = " + fabric_mod_port + ";\n"
  265. buf += " tpg->" + fabric_mod_port + "_tpgt = tpgt;\n\n"
  266. buf += " ret = core_tpg_register(&" + fabric_mod_name + "_ops, wwn,\n"
  267. buf += " &tpg->se_tpg, tpg,\n"
  268. buf += " TRANSPORT_TPG_TYPE_NORMAL);\n"
  269. buf += " if (ret < 0) {\n"
  270. buf += " kfree(tpg);\n"
  271. buf += " return NULL;\n"
  272. buf += " }\n"
  273. buf += " return &tpg->se_tpg;\n"
  274. buf += "}\n\n"
  275. buf += "static void " + fabric_mod_name + "_drop_tpg(struct se_portal_group *se_tpg)\n"
  276. buf += "{\n"
  277. buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
  278. buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n\n"
  279. buf += " core_tpg_deregister(se_tpg);\n"
  280. buf += " kfree(tpg);\n"
  281. buf += "}\n\n"
  282. buf += "static struct se_wwn *" + fabric_mod_name + "_make_" + fabric_mod_port + "(\n"
  283. buf += " struct target_fabric_configfs *tf,\n"
  284. buf += " struct config_group *group,\n"
  285. buf += " const char *name)\n"
  286. buf += "{\n"
  287. buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + ";\n"
  288. if proto_ident == "FC" or proto_ident == "SAS":
  289. buf += " u64 wwpn = 0;\n\n"
  290. buf += " /* if (" + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"
  291. buf += " return ERR_PTR(-EINVAL); */\n\n"
  292. buf += " " + fabric_mod_port + " = kzalloc(sizeof(struct " + fabric_mod_name + "_" + fabric_mod_port + "), GFP_KERNEL);\n"
  293. buf += " if (!" + fabric_mod_port + ") {\n"
  294. buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_" + fabric_mod_port + "\");\n"
  295. buf += " return ERR_PTR(-ENOMEM);\n"
  296. buf += " }\n"
  297. if proto_ident == "FC" or proto_ident == "SAS":
  298. buf += " " + fabric_mod_port + "->" + fabric_mod_port + "_wwpn = wwpn;\n"
  299. buf += " /* " + fabric_mod_name + "_format_wwn(&" + fabric_mod_port + "->" + fabric_mod_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"
  300. buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_wwn;\n"
  301. buf += "}\n\n"
  302. buf += "static void " + fabric_mod_name + "_drop_" + fabric_mod_port + "(struct se_wwn *wwn)\n"
  303. buf += "{\n"
  304. buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = container_of(wwn,\n"
  305. buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n"
  306. buf += " kfree(" + fabric_mod_port + ");\n"
  307. buf += "}\n\n"
  308. buf += "static ssize_t " + fabric_mod_name + "_wwn_show_attr_version(\n"
  309. buf += " struct target_fabric_configfs *tf,\n"
  310. buf += " char *page)\n"
  311. buf += "{\n"
  312. buf += " return sprintf(page, \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"
  313. buf += " \"on \"UTS_RELEASE\"\\n\", " + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"
  314. buf += " utsname()->machine);\n"
  315. buf += "}\n\n"
  316. buf += "TF_WWN_ATTR_RO(" + fabric_mod_name + ", version);\n\n"
  317. buf += "static struct configfs_attribute *" + fabric_mod_name + "_wwn_attrs[] = {\n"
  318. buf += " &" + fabric_mod_name + "_wwn_version.attr,\n"
  319. buf += " NULL,\n"
  320. buf += "};\n\n"
  321. buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n"
  322. buf += " .module = THIS_MODULE,\n"
  323. buf += " .name = " + fabric_mod_name + ",\n"
  324. buf += " .get_fabric_proto_ident = " + fabric_mod_name + "_get_fabric_proto_ident,\n"
  325. buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n"
  326. buf += " .get_fabric_proto_ident = " + fabric_mod_name + "_get_fabric_proto_ident,\n"
  327. buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n"
  328. buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n"
  329. buf += " .tpg_get_default_depth = " + fabric_mod_name + "_get_default_depth,\n"
  330. buf += " .tpg_get_pr_transport_id = " + fabric_mod_name + "_get_pr_transport_id,\n"
  331. buf += " .tpg_get_pr_transport_id_len = " + fabric_mod_name + "_get_pr_transport_id_len,\n"
  332. buf += " .tpg_parse_pr_out_transport_id = " + fabric_mod_name + "_parse_pr_out_transport_id,\n"
  333. buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n"
  334. buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n"
  335. buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n"
  336. buf += " .tpg_check_prod_mode_write_protect = " + fabric_mod_name + "_check_false,\n"
  337. buf += " .tpg_alloc_fabric_acl = " + fabric_mod_name + "_alloc_fabric_acl,\n"
  338. buf += " .tpg_release_fabric_acl = " + fabric_mod_name + "_release_fabric_acl,\n"
  339. buf += " .tpg_get_inst_index = " + fabric_mod_name + "_tpg_get_inst_index,\n"
  340. buf += " .release_cmd = " + fabric_mod_name + "_release_cmd,\n"
  341. buf += " .shutdown_session = " + fabric_mod_name + "_shutdown_session,\n"
  342. buf += " .close_session = " + fabric_mod_name + "_close_session,\n"
  343. buf += " .sess_get_index = " + fabric_mod_name + "_sess_get_index,\n"
  344. buf += " .sess_get_initiator_sid = NULL,\n"
  345. buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n"
  346. buf += " .write_pending_status = " + fabric_mod_name + "_write_pending_status,\n"
  347. buf += " .set_default_node_attributes = " + fabric_mod_name + "_set_default_node_attrs,\n"
  348. buf += " .get_task_tag = " + fabric_mod_name + "_get_task_tag,\n"
  349. buf += " .get_cmd_state = " + fabric_mod_name + "_get_cmd_state,\n"
  350. buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n"
  351. buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n"
  352. buf += " .queue_tm_rsp = " + fabric_mod_name + "_queue_tm_rsp,\n"
  353. buf += " .aborted_task = " + fabric_mod_name + "_aborted_task,\n"
  354. buf += " /*\n"
  355. buf += " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n"
  356. buf += " */\n"
  357. buf += " .fabric_make_wwn = " + fabric_mod_name + "_make_" + fabric_mod_port + ",\n"
  358. buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n"
  359. buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n"
  360. buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n"
  361. buf += " .fabric_post_link = NULL,\n"
  362. buf += " .fabric_pre_unlink = NULL,\n"
  363. buf += " .fabric_make_np = NULL,\n"
  364. buf += " .fabric_drop_np = NULL,\n"
  365. buf += " .fabric_make_nodeacl = " + fabric_mod_name + "_make_nodeacl,\n"
  366. buf += " .fabric_drop_nodeacl = " + fabric_mod_name + "_drop_nodeacl,\n"
  367. buf += "\n"
  368. buf += " .tfc_wwn_attrs = " + fabric_mod_name + "_wwn_attrs;\n"
  369. buf += "};\n\n"
  370. buf += "static int __init " + fabric_mod_name + "_init(void)\n"
  371. buf += "{\n"
  372. buf += " return target_register_template(" + fabric_mod_name + "_ops);\n"
  373. buf += "};\n\n"
  374. buf += "static void __exit " + fabric_mod_name + "_exit(void)\n"
  375. buf += "{\n"
  376. buf += " target_unregister_template(" + fabric_mod_name + "_ops);\n"
  377. buf += "};\n\n"
  378. buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n"
  379. buf += "MODULE_LICENSE(\"GPL\");\n"
  380. buf += "module_init(" + fabric_mod_name + "_init);\n"
  381. buf += "module_exit(" + fabric_mod_name + "_exit);\n"
  382. ret = p.write(buf)
  383. if ret:
  384. tcm_mod_err("Unable to write f: " + f)
  385. p.close()
  386. return
  387. def tcm_mod_scan_fabric_ops(tcm_dir):
  388. fabric_ops_api = tcm_dir + "include/target/target_core_fabric.h"
  389. print "Using tcm_mod_scan_fabric_ops: " + fabric_ops_api
  390. process_fo = 0;
  391. p = open(fabric_ops_api, 'r')
  392. line = p.readline()
  393. while line:
  394. if process_fo == 0 and re.search('struct target_core_fabric_ops {', line):
  395. line = p.readline()
  396. continue
  397. if process_fo == 0:
  398. process_fo = 1;
  399. line = p.readline()
  400. # Search for function pointer
  401. if not re.search('\(\*', line):
  402. continue
  403. fabric_ops.append(line.rstrip())
  404. continue
  405. line = p.readline()
  406. # Search for function pointer
  407. if not re.search('\(\*', line):
  408. continue
  409. fabric_ops.append(line.rstrip())
  410. p.close()
  411. return
  412. def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name):
  413. buf = ""
  414. bufi = ""
  415. f = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.c"
  416. print "Writing file: " + f
  417. p = open(f, 'w')
  418. if not p:
  419. tcm_mod_err("Unable to open file: " + f)
  420. fi = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.h"
  421. print "Writing file: " + fi
  422. pi = open(fi, 'w')
  423. if not pi:
  424. tcm_mod_err("Unable to open file: " + fi)
  425. buf = "#include <linux/slab.h>\n"
  426. buf += "#include <linux/kthread.h>\n"
  427. buf += "#include <linux/types.h>\n"
  428. buf += "#include <linux/list.h>\n"
  429. buf += "#include <linux/types.h>\n"
  430. buf += "#include <linux/string.h>\n"
  431. buf += "#include <linux/ctype.h>\n"
  432. buf += "#include <asm/unaligned.h>\n"
  433. buf += "#include <scsi/scsi_common.h>\n"
  434. buf += "#include <scsi/scsi_proto.h>\n"
  435. buf += "#include <target/target_core_base.h>\n"
  436. buf += "#include <target/target_core_fabric.h>\n"
  437. buf += "#include <target/target_core_configfs.h>\n\n"
  438. buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
  439. buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
  440. buf += "int " + fabric_mod_name + "_check_true(struct se_portal_group *se_tpg)\n"
  441. buf += "{\n"
  442. buf += " return 1;\n"
  443. buf += "}\n\n"
  444. bufi += "int " + fabric_mod_name + "_check_true(struct se_portal_group *);\n"
  445. buf += "int " + fabric_mod_name + "_check_false(struct se_portal_group *se_tpg)\n"
  446. buf += "{\n"
  447. buf += " return 0;\n"
  448. buf += "}\n\n"
  449. bufi += "int " + fabric_mod_name + "_check_false(struct se_portal_group *);\n"
  450. total_fabric_ops = len(fabric_ops)
  451. i = 0
  452. while i < total_fabric_ops:
  453. fo = fabric_ops[i]
  454. i += 1
  455. # print "fabric_ops: " + fo
  456. if re.search('get_fabric_name', fo):
  457. buf += "char *" + fabric_mod_name + "_get_fabric_name(void)\n"
  458. buf += "{\n"
  459. buf += " return \"" + fabric_mod_name + "\";\n"
  460. buf += "}\n\n"
  461. bufi += "char *" + fabric_mod_name + "_get_fabric_name(void);\n"
  462. continue
  463. if re.search('get_fabric_proto_ident', fo):
  464. buf += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *se_tpg)\n"
  465. buf += "{\n"
  466. buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
  467. buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
  468. buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
  469. buf += " u8 proto_id;\n\n"
  470. buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
  471. if proto_ident == "FC":
  472. buf += " case SCSI_PROTOCOL_FCP:\n"
  473. buf += " default:\n"
  474. buf += " proto_id = fc_get_fabric_proto_ident(se_tpg);\n"
  475. buf += " break;\n"
  476. elif proto_ident == "SAS":
  477. buf += " case SCSI_PROTOCOL_SAS:\n"
  478. buf += " default:\n"
  479. buf += " proto_id = sas_get_fabric_proto_ident(se_tpg);\n"
  480. buf += " break;\n"
  481. elif proto_ident == "iSCSI":
  482. buf += " case SCSI_PROTOCOL_ISCSI:\n"
  483. buf += " default:\n"
  484. buf += " proto_id = iscsi_get_fabric_proto_ident(se_tpg);\n"
  485. buf += " break;\n"
  486. buf += " }\n\n"
  487. buf += " return proto_id;\n"
  488. buf += "}\n\n"
  489. bufi += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *);\n"
  490. if re.search('get_wwn', fo):
  491. buf += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *se_tpg)\n"
  492. buf += "{\n"
  493. buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
  494. buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
  495. buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n\n"
  496. buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_name[0];\n"
  497. buf += "}\n\n"
  498. bufi += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *);\n"
  499. if re.search('get_tag', fo):
  500. buf += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *se_tpg)\n"
  501. buf += "{\n"
  502. buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
  503. buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
  504. buf += " return tpg->" + fabric_mod_port + "_tpgt;\n"
  505. buf += "}\n\n"
  506. bufi += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *);\n"
  507. if re.search('get_default_depth', fo):
  508. buf += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *se_tpg)\n"
  509. buf += "{\n"
  510. buf += " return 1;\n"
  511. buf += "}\n\n"
  512. bufi += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *);\n"
  513. if re.search('get_pr_transport_id\)\(', fo):
  514. buf += "u32 " + fabric_mod_name + "_get_pr_transport_id(\n"
  515. buf += " struct se_portal_group *se_tpg,\n"
  516. buf += " struct se_node_acl *se_nacl,\n"
  517. buf += " struct t10_pr_registration *pr_reg,\n"
  518. buf += " int *format_code,\n"
  519. buf += " unsigned char *buf)\n"
  520. buf += "{\n"
  521. buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
  522. buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
  523. buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
  524. buf += " int ret = 0;\n\n"
  525. buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
  526. if proto_ident == "FC":
  527. buf += " case SCSI_PROTOCOL_FCP:\n"
  528. buf += " default:\n"
  529. buf += " ret = fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
  530. buf += " format_code, buf);\n"
  531. buf += " break;\n"
  532. elif proto_ident == "SAS":
  533. buf += " case SCSI_PROTOCOL_SAS:\n"
  534. buf += " default:\n"
  535. buf += " ret = sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
  536. buf += " format_code, buf);\n"
  537. buf += " break;\n"
  538. elif proto_ident == "iSCSI":
  539. buf += " case SCSI_PROTOCOL_ISCSI:\n"
  540. buf += " default:\n"
  541. buf += " ret = iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
  542. buf += " format_code, buf);\n"
  543. buf += " break;\n"
  544. buf += " }\n\n"
  545. buf += " return ret;\n"
  546. buf += "}\n\n"
  547. bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id(struct se_portal_group *,\n"
  548. bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"
  549. bufi += " int *, unsigned char *);\n"
  550. if re.search('get_pr_transport_id_len\)\(', fo):
  551. buf += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(\n"
  552. buf += " struct se_portal_group *se_tpg,\n"
  553. buf += " struct se_node_acl *se_nacl,\n"
  554. buf += " struct t10_pr_registration *pr_reg,\n"
  555. buf += " int *format_code)\n"
  556. buf += "{\n"
  557. buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
  558. buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
  559. buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
  560. buf += " int ret = 0;\n\n"
  561. buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
  562. if proto_ident == "FC":
  563. buf += " case SCSI_PROTOCOL_FCP:\n"
  564. buf += " default:\n"
  565. buf += " ret = fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
  566. buf += " format_code);\n"
  567. buf += " break;\n"
  568. elif proto_ident == "SAS":
  569. buf += " case SCSI_PROTOCOL_SAS:\n"
  570. buf += " default:\n"
  571. buf += " ret = sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
  572. buf += " format_code);\n"
  573. buf += " break;\n"
  574. elif proto_ident == "iSCSI":
  575. buf += " case SCSI_PROTOCOL_ISCSI:\n"
  576. buf += " default:\n"
  577. buf += " ret = iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
  578. buf += " format_code);\n"
  579. buf += " break;\n"
  580. buf += " }\n\n"
  581. buf += " return ret;\n"
  582. buf += "}\n\n"
  583. bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(struct se_portal_group *,\n"
  584. bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"
  585. bufi += " int *);\n"
  586. if re.search('parse_pr_out_transport_id\)\(', fo):
  587. buf += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(\n"
  588. buf += " struct se_portal_group *se_tpg,\n"
  589. buf += " const char *buf,\n"
  590. buf += " u32 *out_tid_len,\n"
  591. buf += " char **port_nexus_ptr)\n"
  592. buf += "{\n"
  593. buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
  594. buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
  595. buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
  596. buf += " char *tid = NULL;\n\n"
  597. buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
  598. if proto_ident == "FC":
  599. buf += " case SCSI_PROTOCOL_FCP:\n"
  600. buf += " default:\n"
  601. buf += " tid = fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
  602. buf += " port_nexus_ptr);\n"
  603. elif proto_ident == "SAS":
  604. buf += " case SCSI_PROTOCOL_SAS:\n"
  605. buf += " default:\n"
  606. buf += " tid = sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
  607. buf += " port_nexus_ptr);\n"
  608. elif proto_ident == "iSCSI":
  609. buf += " case SCSI_PROTOCOL_ISCSI:\n"
  610. buf += " default:\n"
  611. buf += " tid = iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
  612. buf += " port_nexus_ptr);\n"
  613. buf += " }\n\n"
  614. buf += " return tid;\n"
  615. buf += "}\n\n"
  616. bufi += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(struct se_portal_group *,\n"
  617. bufi += " const char *, u32 *, char **);\n"
  618. if re.search('alloc_fabric_acl\)\(', fo):
  619. buf += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *se_tpg)\n"
  620. buf += "{\n"
  621. buf += " struct " + fabric_mod_name + "_nacl *nacl;\n\n"
  622. buf += " nacl = kzalloc(sizeof(struct " + fabric_mod_name + "_nacl), GFP_KERNEL);\n"
  623. buf += " if (!nacl) {\n"
  624. buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_nacl\\n\");\n"
  625. buf += " return NULL;\n"
  626. buf += " }\n\n"
  627. buf += " return &nacl->se_node_acl;\n"
  628. buf += "}\n\n"
  629. bufi += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *);\n"
  630. if re.search('release_fabric_acl\)\(', fo):
  631. buf += "void " + fabric_mod_name + "_release_fabric_acl(\n"
  632. buf += " struct se_portal_group *se_tpg,\n"
  633. buf += " struct se_node_acl *se_nacl)\n"
  634. buf += "{\n"
  635. buf += " struct " + fabric_mod_name + "_nacl *nacl = container_of(se_nacl,\n"
  636. buf += " struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
  637. buf += " kfree(nacl);\n"
  638. buf += "}\n\n"
  639. bufi += "void " + fabric_mod_name + "_release_fabric_acl(struct se_portal_group *,\n"
  640. bufi += " struct se_node_acl *);\n"
  641. if re.search('tpg_get_inst_index\)\(', fo):
  642. buf += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n"
  643. buf += "{\n"
  644. buf += " return 1;\n"
  645. buf += "}\n\n"
  646. bufi += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *);\n"
  647. if re.search('\*release_cmd\)\(', fo):
  648. buf += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *se_cmd)\n"
  649. buf += "{\n"
  650. buf += " return;\n"
  651. buf += "}\n\n"
  652. bufi += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *);\n"
  653. if re.search('shutdown_session\)\(', fo):
  654. buf += "int " + fabric_mod_name + "_shutdown_session(struct se_session *se_sess)\n"
  655. buf += "{\n"
  656. buf += " return 0;\n"
  657. buf += "}\n\n"
  658. bufi += "int " + fabric_mod_name + "_shutdown_session(struct se_session *);\n"
  659. if re.search('close_session\)\(', fo):
  660. buf += "void " + fabric_mod_name + "_close_session(struct se_session *se_sess)\n"
  661. buf += "{\n"
  662. buf += " return;\n"
  663. buf += "}\n\n"
  664. bufi += "void " + fabric_mod_name + "_close_session(struct se_session *);\n"
  665. if re.search('sess_get_index\)\(', fo):
  666. buf += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *se_sess)\n"
  667. buf += "{\n"
  668. buf += " return 0;\n"
  669. buf += "}\n\n"
  670. bufi += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *);\n"
  671. if re.search('write_pending\)\(', fo):
  672. buf += "int " + fabric_mod_name + "_write_pending(struct se_cmd *se_cmd)\n"
  673. buf += "{\n"
  674. buf += " return 0;\n"
  675. buf += "}\n\n"
  676. bufi += "int " + fabric_mod_name + "_write_pending(struct se_cmd *);\n"
  677. if re.search('write_pending_status\)\(', fo):
  678. buf += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *se_cmd)\n"
  679. buf += "{\n"
  680. buf += " return 0;\n"
  681. buf += "}\n\n"
  682. bufi += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *);\n"
  683. if re.search('set_default_node_attributes\)\(', fo):
  684. buf += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *nacl)\n"
  685. buf += "{\n"
  686. buf += " return;\n"
  687. buf += "}\n\n"
  688. bufi += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *);\n"
  689. if re.search('get_task_tag\)\(', fo):
  690. buf += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *se_cmd)\n"
  691. buf += "{\n"
  692. buf += " return 0;\n"
  693. buf += "}\n\n"
  694. bufi += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *);\n"
  695. if re.search('get_cmd_state\)\(', fo):
  696. buf += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *se_cmd)\n"
  697. buf += "{\n"
  698. buf += " return 0;\n"
  699. buf += "}\n\n"
  700. bufi += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *);\n"
  701. if re.search('queue_data_in\)\(', fo):
  702. buf += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *se_cmd)\n"
  703. buf += "{\n"
  704. buf += " return 0;\n"
  705. buf += "}\n\n"
  706. bufi += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *);\n"
  707. if re.search('queue_status\)\(', fo):
  708. buf += "int " + fabric_mod_name + "_queue_status(struct se_cmd *se_cmd)\n"
  709. buf += "{\n"
  710. buf += " return 0;\n"
  711. buf += "}\n\n"
  712. bufi += "int " + fabric_mod_name + "_queue_status(struct se_cmd *);\n"
  713. if re.search('queue_tm_rsp\)\(', fo):
  714. buf += "void " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *se_cmd)\n"
  715. buf += "{\n"
  716. buf += " return;\n"
  717. buf += "}\n\n"
  718. bufi += "void " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *);\n"
  719. if re.search('aborted_task\)\(', fo):
  720. buf += "void " + fabric_mod_name + "_aborted_task(struct se_cmd *se_cmd)\n"
  721. buf += "{\n"
  722. buf += " return;\n"
  723. buf += "}\n\n"
  724. bufi += "void " + fabric_mod_name + "_aborted_task(struct se_cmd *);\n"
  725. ret = p.write(buf)
  726. if ret:
  727. tcm_mod_err("Unable to write f: " + f)
  728. p.close()
  729. ret = pi.write(bufi)
  730. if ret:
  731. tcm_mod_err("Unable to write fi: " + fi)
  732. pi.close()
  733. return
  734. def tcm_mod_build_kbuild(fabric_mod_dir_var, fabric_mod_name):
  735. buf = ""
  736. f = fabric_mod_dir_var + "/Makefile"
  737. print "Writing file: " + f
  738. p = open(f, 'w')
  739. if not p:
  740. tcm_mod_err("Unable to open file: " + f)
  741. buf += fabric_mod_name + "-objs := " + fabric_mod_name + "_fabric.o \\\n"
  742. buf += " " + fabric_mod_name + "_configfs.o\n"
  743. buf += "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name + ".o\n"
  744. ret = p.write(buf)
  745. if ret:
  746. tcm_mod_err("Unable to write f: " + f)
  747. p.close()
  748. return
  749. def tcm_mod_build_kconfig(fabric_mod_dir_var, fabric_mod_name):
  750. buf = ""
  751. f = fabric_mod_dir_var + "/Kconfig"
  752. print "Writing file: " + f
  753. p = open(f, 'w')
  754. if not p:
  755. tcm_mod_err("Unable to open file: " + f)
  756. buf = "config " + fabric_mod_name.upper() + "\n"
  757. buf += " tristate \"" + fabric_mod_name.upper() + " fabric module\"\n"
  758. buf += " depends on TARGET_CORE && CONFIGFS_FS\n"
  759. buf += " default n\n"
  760. buf += " ---help---\n"
  761. buf += " Say Y here to enable the " + fabric_mod_name.upper() + " fabric module\n"
  762. ret = p.write(buf)
  763. if ret:
  764. tcm_mod_err("Unable to write f: " + f)
  765. p.close()
  766. return
  767. def tcm_mod_add_kbuild(tcm_dir, fabric_mod_name):
  768. buf = "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name.lower() + "/\n"
  769. kbuild = tcm_dir + "/drivers/target/Makefile"
  770. f = open(kbuild, 'a')
  771. f.write(buf)
  772. f.close()
  773. return
  774. def tcm_mod_add_kconfig(tcm_dir, fabric_mod_name):
  775. buf = "source \"drivers/target/" + fabric_mod_name.lower() + "/Kconfig\"\n"
  776. kconfig = tcm_dir + "/drivers/target/Kconfig"
  777. f = open(kconfig, 'a')
  778. f.write(buf)
  779. f.close()
  780. return
  781. def main(modname, proto_ident):
  782. # proto_ident = "FC"
  783. # proto_ident = "SAS"
  784. # proto_ident = "iSCSI"
  785. tcm_dir = os.getcwd();
  786. tcm_dir += "/../../"
  787. print "tcm_dir: " + tcm_dir
  788. fabric_mod_name = modname
  789. fabric_mod_dir = tcm_dir + "drivers/target/" + fabric_mod_name
  790. print "Set fabric_mod_name: " + fabric_mod_name
  791. print "Set fabric_mod_dir: " + fabric_mod_dir
  792. print "Using proto_ident: " + proto_ident
  793. if proto_ident != "FC" and proto_ident != "SAS" and proto_ident != "iSCSI":
  794. print "Unsupported proto_ident: " + proto_ident
  795. sys.exit(1)
  796. ret = tcm_mod_create_module_subdir(fabric_mod_dir)
  797. if ret:
  798. print "tcm_mod_create_module_subdir() failed because module already exists!"
  799. sys.exit(1)
  800. tcm_mod_build_base_includes(proto_ident, fabric_mod_dir, fabric_mod_name)
  801. tcm_mod_scan_fabric_ops(tcm_dir)
  802. tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir, fabric_mod_name)
  803. tcm_mod_build_configfs(proto_ident, fabric_mod_dir, fabric_mod_name)
  804. tcm_mod_build_kbuild(fabric_mod_dir, fabric_mod_name)
  805. tcm_mod_build_kconfig(fabric_mod_dir, fabric_mod_name)
  806. input = raw_input("Would you like to add " + fabric_mod_name + " to drivers/target/Makefile..? [yes,no]: ")
  807. if input == "yes" or input == "y":
  808. tcm_mod_add_kbuild(tcm_dir, fabric_mod_name)
  809. input = raw_input("Would you like to add " + fabric_mod_name + " to drivers/target/Kconfig..? [yes,no]: ")
  810. if input == "yes" or input == "y":
  811. tcm_mod_add_kconfig(tcm_dir, fabric_mod_name)
  812. return
  813. parser = optparse.OptionParser()
  814. parser.add_option('-m', '--modulename', help='Module name', dest='modname',
  815. action='store', nargs=1, type='string')
  816. parser.add_option('-p', '--protoident', help='Protocol Ident', dest='protoident',
  817. action='store', nargs=1, type='string')
  818. (opts, args) = parser.parse_args()
  819. mandatories = ['modname', 'protoident']
  820. for m in mandatories:
  821. if not opts.__dict__[m]:
  822. print "mandatory option is missing\n"
  823. parser.print_help()
  824. exit(-1)
  825. if __name__ == "__main__":
  826. main(str(opts.modname), opts.protoident)