2 # The TCM v4 multi-protocol fabric module generation script for drivers/target/$NEW_MOD
4 # Copyright (c) 2010 Rising Tide Systems
5 # Copyright (c) 2010 Linux-iSCSI.org
7 # Author: nab@kernel.org
10 import subprocess as sub
20 fabric_mod_init_port = ""
26 def tcm_mod_create_module_subdir(fabric_mod_dir_var):
28 if os.path.isdir(fabric_mod_dir_var) == True:
31 print "Creating fabric_mod_dir: " + fabric_mod_dir_var
32 ret = os.mkdir(fabric_mod_dir_var)
34 tcm_mod_err("Unable to mkdir " + fabric_mod_dir_var)
38 def tcm_mod_build_FC_include(fabric_mod_dir_var, fabric_mod_name):
39 global fabric_mod_port
40 global fabric_mod_init_port
43 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
44 print "Writing file: " + f
48 tcm_mod_err("Unable to open file: " + f)
50 buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
51 buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
53 buf += "struct " + fabric_mod_name + "_tpg {\n"
54 buf += " /* FC lport target portal group tag for TCM */\n"
55 buf += " u16 lport_tpgt;\n"
56 buf += " /* Pointer back to " + fabric_mod_name + "_lport */\n"
57 buf += " struct " + fabric_mod_name + "_lport *lport;\n"
58 buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
59 buf += " struct se_portal_group se_tpg;\n"
62 buf += "struct " + fabric_mod_name + "_lport {\n"
63 buf += " /* SCSI protocol the lport is providing */\n"
64 buf += " u8 lport_proto_id;\n"
65 buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n"
66 buf += " u64 lport_wwpn;\n"
67 buf += " /* ASCII formatted WWPN for FC Target Lport */\n"
68 buf += " char lport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
69 buf += " /* Returned by " + fabric_mod_name + "_make_lport() */\n"
70 buf += " struct se_wwn lport_wwn;\n"
75 tcm_mod_err("Unable to write f: " + f)
79 fabric_mod_port = "lport"
80 fabric_mod_init_port = "nport"
84 def tcm_mod_build_SAS_include(fabric_mod_dir_var, fabric_mod_name):
85 global fabric_mod_port
86 global fabric_mod_init_port
89 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
90 print "Writing file: " + f
94 tcm_mod_err("Unable to open file: " + f)
96 buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
97 buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
99 buf += "struct " + fabric_mod_name + "_tpg {\n"
100 buf += " /* SAS port target portal group tag for TCM */\n"
101 buf += " u16 tport_tpgt;\n"
102 buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n"
103 buf += " struct " + fabric_mod_name + "_tport *tport;\n"
104 buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
105 buf += " struct se_portal_group se_tpg;\n"
107 buf += "struct " + fabric_mod_name + "_tport {\n"
108 buf += " /* SCSI protocol the tport is providing */\n"
109 buf += " u8 tport_proto_id;\n"
110 buf += " /* Binary World Wide unique Port Name for SAS Target port */\n"
111 buf += " u64 tport_wwpn;\n"
112 buf += " /* ASCII formatted WWPN for SAS Target port */\n"
113 buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
114 buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n"
115 buf += " struct se_wwn tport_wwn;\n"
120 tcm_mod_err("Unable to write f: " + f)
124 fabric_mod_port = "tport"
125 fabric_mod_init_port = "iport"
129 def tcm_mod_build_iSCSI_include(fabric_mod_dir_var, fabric_mod_name):
130 global fabric_mod_port
131 global fabric_mod_init_port
134 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
135 print "Writing file: " + f
139 tcm_mod_err("Unable to open file: " + f)
141 buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
142 buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
144 buf += "struct " + fabric_mod_name + "_tpg {\n"
145 buf += " /* iSCSI target portal group tag for TCM */\n"
146 buf += " u16 tport_tpgt;\n"
147 buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n"
148 buf += " struct " + fabric_mod_name + "_tport *tport;\n"
149 buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
150 buf += " struct se_portal_group se_tpg;\n"
152 buf += "struct " + fabric_mod_name + "_tport {\n"
153 buf += " /* SCSI protocol the tport is providing */\n"
154 buf += " u8 tport_proto_id;\n"
155 buf += " /* ASCII formatted TargetName for IQN */\n"
156 buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
157 buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n"
158 buf += " struct se_wwn tport_wwn;\n"
163 tcm_mod_err("Unable to write f: " + f)
167 fabric_mod_port = "tport"
168 fabric_mod_init_port = "iport"
172 def tcm_mod_build_base_includes(proto_ident, fabric_mod_dir_val, fabric_mod_name):
174 if proto_ident == "FC":
175 tcm_mod_build_FC_include(fabric_mod_dir_val, fabric_mod_name)
176 elif proto_ident == "SAS":
177 tcm_mod_build_SAS_include(fabric_mod_dir_val, fabric_mod_name)
178 elif proto_ident == "iSCSI":
179 tcm_mod_build_iSCSI_include(fabric_mod_dir_val, fabric_mod_name)
181 print "Unsupported proto_ident: " + proto_ident
186 def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
189 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_configfs.c"
190 print "Writing file: " + f
194 tcm_mod_err("Unable to open file: " + f)
196 buf = "#include <linux/module.h>\n"
197 buf += "#include <linux/moduleparam.h>\n"
198 buf += "#include <linux/version.h>\n"
199 buf += "#include <generated/utsrelease.h>\n"
200 buf += "#include <linux/utsname.h>\n"
201 buf += "#include <linux/init.h>\n"
202 buf += "#include <linux/slab.h>\n"
203 buf += "#include <linux/kthread.h>\n"
204 buf += "#include <linux/types.h>\n"
205 buf += "#include <linux/string.h>\n"
206 buf += "#include <linux/configfs.h>\n"
207 buf += "#include <linux/ctype.h>\n"
208 buf += "#include <asm/unaligned.h>\n\n"
209 buf += "#include <target/target_core_base.h>\n"
210 buf += "#include <target/target_core_fabric.h>\n"
211 buf += "#include <target/target_core_fabric_configfs.h>\n"
212 buf += "#include <target/target_core_configfs.h>\n"
213 buf += "#include <target/configfs_macros.h>\n\n"
214 buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
215 buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
217 buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops;\n\n"
219 buf += "static struct se_portal_group *" + fabric_mod_name + "_make_tpg(\n"
220 buf += " struct se_wwn *wwn,\n"
221 buf += " struct config_group *group,\n"
222 buf += " const char *name)\n"
224 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + "*" + fabric_mod_port + " = container_of(wwn,\n"
225 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n\n"
226 buf += " struct " + fabric_mod_name + "_tpg *tpg;\n"
227 buf += " unsigned long tpgt;\n"
228 buf += " int ret;\n\n"
229 buf += " if (strstr(name, \"tpgt_\") != name)\n"
230 buf += " return ERR_PTR(-EINVAL);\n"
231 buf += " if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)\n"
232 buf += " return ERR_PTR(-EINVAL);\n\n"
233 buf += " tpg = kzalloc(sizeof(struct " + fabric_mod_name + "_tpg), GFP_KERNEL);\n"
234 buf += " if (!tpg) {\n"
235 buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_tpg\");\n"
236 buf += " return ERR_PTR(-ENOMEM);\n"
238 buf += " tpg->" + fabric_mod_port + " = " + fabric_mod_port + ";\n"
239 buf += " tpg->" + fabric_mod_port + "_tpgt = tpgt;\n\n"
240 buf += " ret = core_tpg_register(&" + fabric_mod_name + "_ops, wwn,\n"
241 buf += " &tpg->se_tpg, tpg,\n"
242 buf += " TRANSPORT_TPG_TYPE_NORMAL);\n"
243 buf += " if (ret < 0) {\n"
244 buf += " kfree(tpg);\n"
245 buf += " return NULL;\n"
247 buf += " return &tpg->se_tpg;\n"
249 buf += "static void " + fabric_mod_name + "_drop_tpg(struct se_portal_group *se_tpg)\n"
251 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
252 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n\n"
253 buf += " core_tpg_deregister(se_tpg);\n"
254 buf += " kfree(tpg);\n"
257 buf += "static struct se_wwn *" + fabric_mod_name + "_make_" + fabric_mod_port + "(\n"
258 buf += " struct target_fabric_configfs *tf,\n"
259 buf += " struct config_group *group,\n"
260 buf += " const char *name)\n"
262 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + ";\n"
264 if proto_ident == "FC" or proto_ident == "SAS":
265 buf += " u64 wwpn = 0;\n\n"
267 buf += " /* if (" + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"
268 buf += " return ERR_PTR(-EINVAL); */\n\n"
269 buf += " " + fabric_mod_port + " = kzalloc(sizeof(struct " + fabric_mod_name + "_" + fabric_mod_port + "), GFP_KERNEL);\n"
270 buf += " if (!" + fabric_mod_port + ") {\n"
271 buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_" + fabric_mod_port + "\");\n"
272 buf += " return ERR_PTR(-ENOMEM);\n"
275 if proto_ident == "FC" or proto_ident == "SAS":
276 buf += " " + fabric_mod_port + "->" + fabric_mod_port + "_wwpn = wwpn;\n"
278 buf += " /* " + fabric_mod_name + "_format_wwn(&" + fabric_mod_port + "->" + fabric_mod_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"
279 buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_wwn;\n"
281 buf += "static void " + fabric_mod_name + "_drop_" + fabric_mod_port + "(struct se_wwn *wwn)\n"
283 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = container_of(wwn,\n"
284 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n"
285 buf += " kfree(" + fabric_mod_port + ");\n"
287 buf += "static ssize_t " + fabric_mod_name + "_wwn_show_attr_version(\n"
288 buf += " struct target_fabric_configfs *tf,\n"
289 buf += " char *page)\n"
291 buf += " return sprintf(page, \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"
292 buf += " \"on \"UTS_RELEASE\"\\n\", " + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"
293 buf += " utsname()->machine);\n"
295 buf += "TF_WWN_ATTR_RO(" + fabric_mod_name + ", version);\n\n"
296 buf += "static struct configfs_attribute *" + fabric_mod_name + "_wwn_attrs[] = {\n"
297 buf += " &" + fabric_mod_name + "_wwn_version.attr,\n"
301 buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n"
302 buf += " .module = THIS_MODULE,\n"
303 buf += " .name = " + fabric_mod_name + ",\n"
304 buf += " .get_fabric_proto_ident = " + fabric_mod_name + "_get_fabric_proto_ident,\n"
305 buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n"
306 buf += " .get_fabric_proto_ident = " + fabric_mod_name + "_get_fabric_proto_ident,\n"
307 buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n"
308 buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n"
309 buf += " .tpg_get_pr_transport_id = " + fabric_mod_name + "_get_pr_transport_id,\n"
310 buf += " .tpg_get_pr_transport_id_len = " + fabric_mod_name + "_get_pr_transport_id_len,\n"
311 buf += " .tpg_parse_pr_out_transport_id = " + fabric_mod_name + "_parse_pr_out_transport_id,\n"
312 buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n"
313 buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n"
314 buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n"
315 buf += " .tpg_check_prod_mode_write_protect = " + fabric_mod_name + "_check_false,\n"
316 buf += " .tpg_get_inst_index = " + fabric_mod_name + "_tpg_get_inst_index,\n"
317 buf += " .release_cmd = " + fabric_mod_name + "_release_cmd,\n"
318 buf += " .shutdown_session = " + fabric_mod_name + "_shutdown_session,\n"
319 buf += " .close_session = " + fabric_mod_name + "_close_session,\n"
320 buf += " .sess_get_index = " + fabric_mod_name + "_sess_get_index,\n"
321 buf += " .sess_get_initiator_sid = NULL,\n"
322 buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n"
323 buf += " .write_pending_status = " + fabric_mod_name + "_write_pending_status,\n"
324 buf += " .set_default_node_attributes = " + fabric_mod_name + "_set_default_node_attrs,\n"
325 buf += " .get_task_tag = " + fabric_mod_name + "_get_task_tag,\n"
326 buf += " .get_cmd_state = " + fabric_mod_name + "_get_cmd_state,\n"
327 buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n"
328 buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n"
329 buf += " .queue_tm_rsp = " + fabric_mod_name + "_queue_tm_rsp,\n"
330 buf += " .aborted_task = " + fabric_mod_name + "_aborted_task,\n"
332 buf += " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n"
334 buf += " .fabric_make_wwn = " + fabric_mod_name + "_make_" + fabric_mod_port + ",\n"
335 buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n"
336 buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n"
337 buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n"
339 buf += " .tfc_wwn_attrs = " + fabric_mod_name + "_wwn_attrs;\n"
342 buf += "static int __init " + fabric_mod_name + "_init(void)\n"
344 buf += " return target_register_template(" + fabric_mod_name + "_ops);\n"
347 buf += "static void __exit " + fabric_mod_name + "_exit(void)\n"
349 buf += " target_unregister_template(" + fabric_mod_name + "_ops);\n"
352 buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n"
353 buf += "MODULE_LICENSE(\"GPL\");\n"
354 buf += "module_init(" + fabric_mod_name + "_init);\n"
355 buf += "module_exit(" + fabric_mod_name + "_exit);\n"
359 tcm_mod_err("Unable to write f: " + f)
365 def tcm_mod_scan_fabric_ops(tcm_dir):
367 fabric_ops_api = tcm_dir + "include/target/target_core_fabric.h"
369 print "Using tcm_mod_scan_fabric_ops: " + fabric_ops_api
372 p = open(fabric_ops_api, 'r')
376 if process_fo == 0 and re.search('struct target_core_fabric_ops {', line):
383 # Search for function pointer
384 if not re.search('\(\*', line):
387 fabric_ops.append(line.rstrip())
391 # Search for function pointer
392 if not re.search('\(\*', line):
395 fabric_ops.append(line.rstrip())
400 def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name):
404 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.c"
405 print "Writing file: " + f
409 tcm_mod_err("Unable to open file: " + f)
411 fi = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.h"
412 print "Writing file: " + fi
416 tcm_mod_err("Unable to open file: " + fi)
418 buf = "#include <linux/slab.h>\n"
419 buf += "#include <linux/kthread.h>\n"
420 buf += "#include <linux/types.h>\n"
421 buf += "#include <linux/list.h>\n"
422 buf += "#include <linux/types.h>\n"
423 buf += "#include <linux/string.h>\n"
424 buf += "#include <linux/ctype.h>\n"
425 buf += "#include <asm/unaligned.h>\n"
426 buf += "#include <scsi/scsi.h>\n"
427 buf += "#include <scsi/scsi_host.h>\n"
428 buf += "#include <scsi/scsi_device.h>\n"
429 buf += "#include <scsi/scsi_cmnd.h>\n"
430 buf += "#include <scsi/libfc.h>\n\n"
431 buf += "#include <target/target_core_base.h>\n"
432 buf += "#include <target/target_core_fabric.h>\n"
433 buf += "#include <target/target_core_configfs.h>\n\n"
434 buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
435 buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
437 buf += "int " + fabric_mod_name + "_check_true(struct se_portal_group *se_tpg)\n"
439 buf += " return 1;\n"
441 bufi += "int " + fabric_mod_name + "_check_true(struct se_portal_group *);\n"
443 buf += "int " + fabric_mod_name + "_check_false(struct se_portal_group *se_tpg)\n"
445 buf += " return 0;\n"
447 bufi += "int " + fabric_mod_name + "_check_false(struct se_portal_group *);\n"
449 total_fabric_ops = len(fabric_ops)
452 while i < total_fabric_ops:
455 # print "fabric_ops: " + fo
457 if re.search('get_fabric_name', fo):
458 buf += "char *" + fabric_mod_name + "_get_fabric_name(void)\n"
460 buf += " return \"" + fabric_mod_name + "\";\n"
462 bufi += "char *" + fabric_mod_name + "_get_fabric_name(void);\n"
465 if re.search('get_fabric_proto_ident', fo):
466 buf += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *se_tpg)\n"
468 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
469 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
470 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
471 buf += " u8 proto_id;\n\n"
472 buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
473 if proto_ident == "FC":
474 buf += " case SCSI_PROTOCOL_FCP:\n"
476 buf += " proto_id = fc_get_fabric_proto_ident(se_tpg);\n"
478 elif proto_ident == "SAS":
479 buf += " case SCSI_PROTOCOL_SAS:\n"
481 buf += " proto_id = sas_get_fabric_proto_ident(se_tpg);\n"
483 elif proto_ident == "iSCSI":
484 buf += " case SCSI_PROTOCOL_ISCSI:\n"
486 buf += " proto_id = iscsi_get_fabric_proto_ident(se_tpg);\n"
490 buf += " return proto_id;\n"
492 bufi += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *);\n"
494 if re.search('get_wwn', fo):
495 buf += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *se_tpg)\n"
497 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
498 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
499 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n\n"
500 buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_name[0];\n"
502 bufi += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *);\n"
504 if re.search('get_tag', fo):
505 buf += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *se_tpg)\n"
507 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
508 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
509 buf += " return tpg->" + fabric_mod_port + "_tpgt;\n"
511 bufi += "u16 " + fabric_mod_name + "_get_tag(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"
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"
529 buf += " ret = fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
530 buf += " format_code, buf);\n"
532 elif proto_ident == "SAS":
533 buf += " case SCSI_PROTOCOL_SAS:\n"
535 buf += " ret = sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
536 buf += " format_code, buf);\n"
538 elif proto_ident == "iSCSI":
539 buf += " case SCSI_PROTOCOL_ISCSI:\n"
541 buf += " ret = iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
542 buf += " format_code, buf);\n"
546 buf += " return ret;\n"
548 bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id(struct se_portal_group *,\n"
549 bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"
550 bufi += " int *, unsigned char *);\n"
552 if re.search('get_pr_transport_id_len\)\(', fo):
553 buf += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(\n"
554 buf += " struct se_portal_group *se_tpg,\n"
555 buf += " struct se_node_acl *se_nacl,\n"
556 buf += " struct t10_pr_registration *pr_reg,\n"
557 buf += " int *format_code)\n"
559 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
560 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
561 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
562 buf += " int ret = 0;\n\n"
563 buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
564 if proto_ident == "FC":
565 buf += " case SCSI_PROTOCOL_FCP:\n"
567 buf += " ret = fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
568 buf += " format_code);\n"
570 elif proto_ident == "SAS":
571 buf += " case SCSI_PROTOCOL_SAS:\n"
573 buf += " ret = sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
574 buf += " format_code);\n"
576 elif proto_ident == "iSCSI":
577 buf += " case SCSI_PROTOCOL_ISCSI:\n"
579 buf += " ret = iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
580 buf += " format_code);\n"
585 buf += " return ret;\n"
587 bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(struct se_portal_group *,\n"
588 bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"
591 if re.search('parse_pr_out_transport_id\)\(', fo):
592 buf += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(\n"
593 buf += " struct se_portal_group *se_tpg,\n"
594 buf += " const char *buf,\n"
595 buf += " u32 *out_tid_len,\n"
596 buf += " char **port_nexus_ptr)\n"
598 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
599 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
600 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
601 buf += " char *tid = NULL;\n\n"
602 buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
603 if proto_ident == "FC":
604 buf += " case SCSI_PROTOCOL_FCP:\n"
606 buf += " tid = fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
607 buf += " port_nexus_ptr);\n"
608 elif proto_ident == "SAS":
609 buf += " case SCSI_PROTOCOL_SAS:\n"
611 buf += " tid = sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
612 buf += " port_nexus_ptr);\n"
613 elif proto_ident == "iSCSI":
614 buf += " case SCSI_PROTOCOL_ISCSI:\n"
616 buf += " tid = iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
617 buf += " port_nexus_ptr);\n"
620 buf += " return tid;\n"
622 bufi += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(struct se_portal_group *,\n"
623 bufi += " const char *, u32 *, char **);\n"
625 if re.search('tpg_get_inst_index\)\(', fo):
626 buf += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n"
628 buf += " return 1;\n"
630 bufi += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *);\n"
632 if re.search('\*release_cmd\)\(', fo):
633 buf += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *se_cmd)\n"
637 bufi += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *);\n"
639 if re.search('shutdown_session\)\(', fo):
640 buf += "int " + fabric_mod_name + "_shutdown_session(struct se_session *se_sess)\n"
642 buf += " return 0;\n"
644 bufi += "int " + fabric_mod_name + "_shutdown_session(struct se_session *);\n"
646 if re.search('close_session\)\(', fo):
647 buf += "void " + fabric_mod_name + "_close_session(struct se_session *se_sess)\n"
651 bufi += "void " + fabric_mod_name + "_close_session(struct se_session *);\n"
653 if re.search('sess_get_index\)\(', fo):
654 buf += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *se_sess)\n"
656 buf += " return 0;\n"
658 bufi += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *);\n"
660 if re.search('write_pending\)\(', fo):
661 buf += "int " + fabric_mod_name + "_write_pending(struct se_cmd *se_cmd)\n"
663 buf += " return 0;\n"
665 bufi += "int " + fabric_mod_name + "_write_pending(struct se_cmd *);\n"
667 if re.search('write_pending_status\)\(', fo):
668 buf += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *se_cmd)\n"
670 buf += " return 0;\n"
672 bufi += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *);\n"
674 if re.search('set_default_node_attributes\)\(', fo):
675 buf += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *nacl)\n"
679 bufi += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *);\n"
681 if re.search('get_task_tag\)\(', fo):
682 buf += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *se_cmd)\n"
684 buf += " return 0;\n"
686 bufi += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *);\n"
688 if re.search('get_cmd_state\)\(', fo):
689 buf += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *se_cmd)\n"
691 buf += " return 0;\n"
693 bufi += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *);\n"
695 if re.search('queue_data_in\)\(', fo):
696 buf += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *se_cmd)\n"
698 buf += " return 0;\n"
700 bufi += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *);\n"
702 if re.search('queue_status\)\(', fo):
703 buf += "int " + fabric_mod_name + "_queue_status(struct se_cmd *se_cmd)\n"
705 buf += " return 0;\n"
707 bufi += "int " + fabric_mod_name + "_queue_status(struct se_cmd *);\n"
709 if re.search('queue_tm_rsp\)\(', fo):
710 buf += "void " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *se_cmd)\n"
714 bufi += "void " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *);\n"
716 if re.search('aborted_task\)\(', fo):
717 buf += "void " + fabric_mod_name + "_aborted_task(struct se_cmd *se_cmd)\n"
721 bufi += "void " + fabric_mod_name + "_aborted_task(struct se_cmd *);\n"
725 tcm_mod_err("Unable to write f: " + f)
731 tcm_mod_err("Unable to write fi: " + fi)
736 def tcm_mod_build_kbuild(fabric_mod_dir_var, fabric_mod_name):
739 f = fabric_mod_dir_var + "/Makefile"
740 print "Writing file: " + f
744 tcm_mod_err("Unable to open file: " + f)
746 buf += fabric_mod_name + "-objs := " + fabric_mod_name + "_fabric.o \\\n"
747 buf += " " + fabric_mod_name + "_configfs.o\n"
748 buf += "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name + ".o\n"
752 tcm_mod_err("Unable to write f: " + f)
757 def tcm_mod_build_kconfig(fabric_mod_dir_var, fabric_mod_name):
760 f = fabric_mod_dir_var + "/Kconfig"
761 print "Writing file: " + f
765 tcm_mod_err("Unable to open file: " + f)
767 buf = "config " + fabric_mod_name.upper() + "\n"
768 buf += " tristate \"" + fabric_mod_name.upper() + " fabric module\"\n"
769 buf += " depends on TARGET_CORE && CONFIGFS_FS\n"
770 buf += " default n\n"
771 buf += " ---help---\n"
772 buf += " Say Y here to enable the " + fabric_mod_name.upper() + " fabric module\n"
776 tcm_mod_err("Unable to write f: " + f)
781 def tcm_mod_add_kbuild(tcm_dir, fabric_mod_name):
782 buf = "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name.lower() + "/\n"
783 kbuild = tcm_dir + "/drivers/target/Makefile"
785 f = open(kbuild, 'a')
790 def tcm_mod_add_kconfig(tcm_dir, fabric_mod_name):
791 buf = "source \"drivers/target/" + fabric_mod_name.lower() + "/Kconfig\"\n"
792 kconfig = tcm_dir + "/drivers/target/Kconfig"
794 f = open(kconfig, 'a')
799 def main(modname, proto_ident):
801 # proto_ident = "SAS"
802 # proto_ident = "iSCSI"
804 tcm_dir = os.getcwd();
806 print "tcm_dir: " + tcm_dir
807 fabric_mod_name = modname
808 fabric_mod_dir = tcm_dir + "drivers/target/" + fabric_mod_name
809 print "Set fabric_mod_name: " + fabric_mod_name
810 print "Set fabric_mod_dir: " + fabric_mod_dir
811 print "Using proto_ident: " + proto_ident
813 if proto_ident != "FC" and proto_ident != "SAS" and proto_ident != "iSCSI":
814 print "Unsupported proto_ident: " + proto_ident
817 ret = tcm_mod_create_module_subdir(fabric_mod_dir)
819 print "tcm_mod_create_module_subdir() failed because module already exists!"
822 tcm_mod_build_base_includes(proto_ident, fabric_mod_dir, fabric_mod_name)
823 tcm_mod_scan_fabric_ops(tcm_dir)
824 tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir, fabric_mod_name)
825 tcm_mod_build_configfs(proto_ident, fabric_mod_dir, fabric_mod_name)
826 tcm_mod_build_kbuild(fabric_mod_dir, fabric_mod_name)
827 tcm_mod_build_kconfig(fabric_mod_dir, fabric_mod_name)
829 input = raw_input("Would you like to add " + fabric_mod_name + " to drivers/target/Makefile..? [yes,no]: ")
830 if input == "yes" or input == "y":
831 tcm_mod_add_kbuild(tcm_dir, fabric_mod_name)
833 input = raw_input("Would you like to add " + fabric_mod_name + " to drivers/target/Kconfig..? [yes,no]: ")
834 if input == "yes" or input == "y":
835 tcm_mod_add_kconfig(tcm_dir, fabric_mod_name)
839 parser = optparse.OptionParser()
840 parser.add_option('-m', '--modulename', help='Module name', dest='modname',
841 action='store', nargs=1, type='string')
842 parser.add_option('-p', '--protoident', help='Protocol Ident', dest='protoident',
843 action='store', nargs=1, type='string')
845 (opts, args) = parser.parse_args()
847 mandatories = ['modname', 'protoident']
848 for m in mandatories:
849 if not opts.__dict__[m]:
850 print "mandatory option is missing\n"
854 if __name__ == "__main__":
856 main(str(opts.modname), opts.protoident)