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
+= " /* 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"
73 tcm_mod_err("Unable to write f: " + f
)
77 fabric_mod_port
= "lport"
78 fabric_mod_init_port
= "nport"
82 def tcm_mod_build_SAS_include(fabric_mod_dir_var
, fabric_mod_name
):
83 global fabric_mod_port
84 global fabric_mod_init_port
87 f
= fabric_mod_dir_var
+ "/" + fabric_mod_name
+ "_base.h"
88 print "Writing file: " + f
92 tcm_mod_err("Unable to open file: " + f
)
94 buf
= "#define " + fabric_mod_name
.upper() + "_VERSION \"v0.1\"\n"
95 buf
+= "#define " + fabric_mod_name
.upper() + "_NAMELEN 32\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"
105 buf
+= "struct " + fabric_mod_name
+ "_tport {\n"
106 buf
+= " /* Binary World Wide unique Port Name for SAS Target port */\n"
107 buf
+= " u64 tport_wwpn;\n"
108 buf
+= " /* ASCII formatted WWPN for SAS Target port */\n"
109 buf
+= " char tport_name[" + fabric_mod_name
.upper() + "_NAMELEN];\n"
110 buf
+= " /* Returned by " + fabric_mod_name
+ "_make_tport() */\n"
111 buf
+= " struct se_wwn tport_wwn;\n"
116 tcm_mod_err("Unable to write f: " + f
)
120 fabric_mod_port
= "tport"
121 fabric_mod_init_port
= "iport"
125 def tcm_mod_build_iSCSI_include(fabric_mod_dir_var
, fabric_mod_name
):
126 global fabric_mod_port
127 global fabric_mod_init_port
130 f
= fabric_mod_dir_var
+ "/" + fabric_mod_name
+ "_base.h"
131 print "Writing file: " + f
135 tcm_mod_err("Unable to open file: " + f
)
137 buf
= "#define " + fabric_mod_name
.upper() + "_VERSION \"v0.1\"\n"
138 buf
+= "#define " + fabric_mod_name
.upper() + "_NAMELEN 32\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"
148 buf
+= "struct " + fabric_mod_name
+ "_tport {\n"
149 buf
+= " /* ASCII formatted TargetName for IQN */\n"
150 buf
+= " char tport_name[" + fabric_mod_name
.upper() + "_NAMELEN];\n"
151 buf
+= " /* Returned by " + fabric_mod_name
+ "_make_tport() */\n"
152 buf
+= " struct se_wwn tport_wwn;\n"
157 tcm_mod_err("Unable to write f: " + f
)
161 fabric_mod_port
= "tport"
162 fabric_mod_init_port
= "iport"
166 def tcm_mod_build_base_includes(proto_ident
, fabric_mod_dir_val
, fabric_mod_name
):
168 if proto_ident
== "FC":
169 tcm_mod_build_FC_include(fabric_mod_dir_val
, fabric_mod_name
)
170 elif proto_ident
== "SAS":
171 tcm_mod_build_SAS_include(fabric_mod_dir_val
, fabric_mod_name
)
172 elif proto_ident
== "iSCSI":
173 tcm_mod_build_iSCSI_include(fabric_mod_dir_val
, fabric_mod_name
)
175 print "Unsupported proto_ident: " + proto_ident
180 def tcm_mod_build_configfs(proto_ident
, fabric_mod_dir_var
, fabric_mod_name
):
183 f
= fabric_mod_dir_var
+ "/" + fabric_mod_name
+ "_configfs.c"
184 print "Writing file: " + f
188 tcm_mod_err("Unable to open file: " + f
)
190 buf
= "#include <linux/module.h>\n"
191 buf
+= "#include <linux/moduleparam.h>\n"
192 buf
+= "#include <linux/version.h>\n"
193 buf
+= "#include <generated/utsrelease.h>\n"
194 buf
+= "#include <linux/utsname.h>\n"
195 buf
+= "#include <linux/init.h>\n"
196 buf
+= "#include <linux/slab.h>\n"
197 buf
+= "#include <linux/kthread.h>\n"
198 buf
+= "#include <linux/types.h>\n"
199 buf
+= "#include <linux/string.h>\n"
200 buf
+= "#include <linux/configfs.h>\n"
201 buf
+= "#include <linux/ctype.h>\n"
202 buf
+= "#include <asm/unaligned.h>\n"
203 buf
+= "#include <scsi/scsi_proto.h>\n\n"
204 buf
+= "#include <target/target_core_base.h>\n"
205 buf
+= "#include <target/target_core_fabric.h>\n"
206 buf
+= "#include \"" + fabric_mod_name
+ "_base.h\"\n"
207 buf
+= "#include \"" + fabric_mod_name
+ "_fabric.h\"\n\n"
209 buf
+= "static const struct target_core_fabric_ops " + fabric_mod_name
+ "_ops;\n\n"
211 buf
+= "static struct se_portal_group *" + fabric_mod_name
+ "_make_tpg(\n"
212 buf
+= " struct se_wwn *wwn,\n"
213 buf
+= " struct config_group *group,\n"
214 buf
+= " const char *name)\n"
216 buf
+= " struct " + fabric_mod_name
+ "_" + fabric_mod_port
+ "*" + fabric_mod_port
+ " = container_of(wwn,\n"
217 buf
+= " struct " + fabric_mod_name
+ "_" + fabric_mod_port
+ ", " + fabric_mod_port
+ "_wwn);\n\n"
218 buf
+= " struct " + fabric_mod_name
+ "_tpg *tpg;\n"
219 buf
+= " unsigned long tpgt;\n"
220 buf
+= " int ret;\n\n"
221 buf
+= " if (strstr(name, \"tpgt_\") != name)\n"
222 buf
+= " return ERR_PTR(-EINVAL);\n"
223 buf
+= " if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)\n"
224 buf
+= " return ERR_PTR(-EINVAL);\n\n"
225 buf
+= " tpg = kzalloc(sizeof(struct " + fabric_mod_name
+ "_tpg), GFP_KERNEL);\n"
226 buf
+= " if (!tpg) {\n"
227 buf
+= " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name
+ "_tpg\");\n"
228 buf
+= " return ERR_PTR(-ENOMEM);\n"
230 buf
+= " tpg->" + fabric_mod_port
+ " = " + fabric_mod_port
+ ";\n"
231 buf
+= " tpg->" + fabric_mod_port
+ "_tpgt = tpgt;\n\n"
233 if proto_ident
== "FC":
234 buf
+= " ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_FCP);\n"
235 elif proto_ident
== "SAS":
236 buf
+= " ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_SAS);\n"
237 elif proto_ident
== "iSCSI":
238 buf
+= " ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_ISCSI);\n"
240 buf
+= " if (ret < 0) {\n"
241 buf
+= " kfree(tpg);\n"
242 buf
+= " return NULL;\n"
244 buf
+= " return &tpg->se_tpg;\n"
246 buf
+= "static void " + fabric_mod_name
+ "_drop_tpg(struct se_portal_group *se_tpg)\n"
248 buf
+= " struct " + fabric_mod_name
+ "_tpg *tpg = container_of(se_tpg,\n"
249 buf
+= " struct " + fabric_mod_name
+ "_tpg, se_tpg);\n\n"
250 buf
+= " core_tpg_deregister(se_tpg);\n"
251 buf
+= " kfree(tpg);\n"
254 buf
+= "static struct se_wwn *" + fabric_mod_name
+ "_make_" + fabric_mod_port
+ "(\n"
255 buf
+= " struct target_fabric_configfs *tf,\n"
256 buf
+= " struct config_group *group,\n"
257 buf
+= " const char *name)\n"
259 buf
+= " struct " + fabric_mod_name
+ "_" + fabric_mod_port
+ " *" + fabric_mod_port
+ ";\n"
261 if proto_ident
== "FC" or proto_ident
== "SAS":
262 buf
+= " u64 wwpn = 0;\n\n"
264 buf
+= " /* if (" + fabric_mod_name
+ "_parse_wwn(name, &wwpn, 1) < 0)\n"
265 buf
+= " return ERR_PTR(-EINVAL); */\n\n"
266 buf
+= " " + fabric_mod_port
+ " = kzalloc(sizeof(struct " + fabric_mod_name
+ "_" + fabric_mod_port
+ "), GFP_KERNEL);\n"
267 buf
+= " if (!" + fabric_mod_port
+ ") {\n"
268 buf
+= " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name
+ "_" + fabric_mod_port
+ "\");\n"
269 buf
+= " return ERR_PTR(-ENOMEM);\n"
272 if proto_ident
== "FC" or proto_ident
== "SAS":
273 buf
+= " " + fabric_mod_port
+ "->" + fabric_mod_port
+ "_wwpn = wwpn;\n"
275 buf
+= " /* " + fabric_mod_name
+ "_format_wwn(&" + fabric_mod_port
+ "->" + fabric_mod_port
+ "_name[0], " + fabric_mod_name
.upper() + "_NAMELEN, wwpn); */\n\n"
276 buf
+= " return &" + fabric_mod_port
+ "->" + fabric_mod_port
+ "_wwn;\n"
278 buf
+= "static void " + fabric_mod_name
+ "_drop_" + fabric_mod_port
+ "(struct se_wwn *wwn)\n"
280 buf
+= " struct " + fabric_mod_name
+ "_" + fabric_mod_port
+ " *" + fabric_mod_port
+ " = container_of(wwn,\n"
281 buf
+= " struct " + fabric_mod_name
+ "_" + fabric_mod_port
+ ", " + fabric_mod_port
+ "_wwn);\n"
282 buf
+= " kfree(" + fabric_mod_port
+ ");\n"
285 buf
+= "static const struct target_core_fabric_ops " + fabric_mod_name
+ "_ops = {\n"
286 buf
+= " .module = THIS_MODULE,\n"
287 buf
+= " .name = \"" + fabric_mod_name
+ "\",\n"
288 buf
+= " .get_fabric_name = " + fabric_mod_name
+ "_get_fabric_name,\n"
289 buf
+= " .tpg_get_wwn = " + fabric_mod_name
+ "_get_fabric_wwn,\n"
290 buf
+= " .tpg_get_tag = " + fabric_mod_name
+ "_get_tag,\n"
291 buf
+= " .tpg_check_demo_mode = " + fabric_mod_name
+ "_check_false,\n"
292 buf
+= " .tpg_check_demo_mode_cache = " + fabric_mod_name
+ "_check_true,\n"
293 buf
+= " .tpg_check_demo_mode_write_protect = " + fabric_mod_name
+ "_check_true,\n"
294 buf
+= " .tpg_check_prod_mode_write_protect = " + fabric_mod_name
+ "_check_false,\n"
295 buf
+= " .tpg_get_inst_index = " + fabric_mod_name
+ "_tpg_get_inst_index,\n"
296 buf
+= " .release_cmd = " + fabric_mod_name
+ "_release_cmd,\n"
297 buf
+= " .shutdown_session = " + fabric_mod_name
+ "_shutdown_session,\n"
298 buf
+= " .close_session = " + fabric_mod_name
+ "_close_session,\n"
299 buf
+= " .sess_get_index = " + fabric_mod_name
+ "_sess_get_index,\n"
300 buf
+= " .sess_get_initiator_sid = NULL,\n"
301 buf
+= " .write_pending = " + fabric_mod_name
+ "_write_pending,\n"
302 buf
+= " .write_pending_status = " + fabric_mod_name
+ "_write_pending_status,\n"
303 buf
+= " .set_default_node_attributes = " + fabric_mod_name
+ "_set_default_node_attrs,\n"
304 buf
+= " .get_cmd_state = " + fabric_mod_name
+ "_get_cmd_state,\n"
305 buf
+= " .queue_data_in = " + fabric_mod_name
+ "_queue_data_in,\n"
306 buf
+= " .queue_status = " + fabric_mod_name
+ "_queue_status,\n"
307 buf
+= " .queue_tm_rsp = " + fabric_mod_name
+ "_queue_tm_rsp,\n"
308 buf
+= " .aborted_task = " + fabric_mod_name
+ "_aborted_task,\n"
310 buf
+= " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n"
312 buf
+= " .fabric_make_wwn = " + fabric_mod_name
+ "_make_" + fabric_mod_port
+ ",\n"
313 buf
+= " .fabric_drop_wwn = " + fabric_mod_name
+ "_drop_" + fabric_mod_port
+ ",\n"
314 buf
+= " .fabric_make_tpg = " + fabric_mod_name
+ "_make_tpg,\n"
315 buf
+= " .fabric_drop_tpg = " + fabric_mod_name
+ "_drop_tpg,\n"
318 buf
+= "static int __init " + fabric_mod_name
+ "_init(void)\n"
320 buf
+= " return target_register_template(&" + fabric_mod_name
+ "_ops);\n"
323 buf
+= "static void __exit " + fabric_mod_name
+ "_exit(void)\n"
325 buf
+= " target_unregister_template(&" + fabric_mod_name
+ "_ops);\n"
328 buf
+= "MODULE_DESCRIPTION(\"" + fabric_mod_name
.upper() + " series fabric driver\");\n"
329 buf
+= "MODULE_LICENSE(\"GPL\");\n"
330 buf
+= "module_init(" + fabric_mod_name
+ "_init);\n"
331 buf
+= "module_exit(" + fabric_mod_name
+ "_exit);\n"
335 tcm_mod_err("Unable to write f: " + f
)
341 def tcm_mod_scan_fabric_ops(tcm_dir
):
343 fabric_ops_api
= tcm_dir
+ "include/target/target_core_fabric.h"
345 print "Using tcm_mod_scan_fabric_ops: " + fabric_ops_api
348 p
= open(fabric_ops_api
, 'r')
352 if process_fo
== 0 and re
.search('struct target_core_fabric_ops {', line
):
359 # Search for function pointer
360 if not re
.search('\(\*', line
):
363 fabric_ops
.append(line
.rstrip())
367 # Search for function pointer
368 if not re
.search('\(\*', line
):
371 fabric_ops
.append(line
.rstrip())
376 def tcm_mod_dump_fabric_ops(proto_ident
, fabric_mod_dir_var
, fabric_mod_name
):
380 f
= fabric_mod_dir_var
+ "/" + fabric_mod_name
+ "_fabric.c"
381 print "Writing file: " + f
385 tcm_mod_err("Unable to open file: " + f
)
387 fi
= fabric_mod_dir_var
+ "/" + fabric_mod_name
+ "_fabric.h"
388 print "Writing file: " + fi
392 tcm_mod_err("Unable to open file: " + fi
)
394 buf
= "#include <linux/slab.h>\n"
395 buf
+= "#include <linux/kthread.h>\n"
396 buf
+= "#include <linux/types.h>\n"
397 buf
+= "#include <linux/list.h>\n"
398 buf
+= "#include <linux/types.h>\n"
399 buf
+= "#include <linux/string.h>\n"
400 buf
+= "#include <linux/ctype.h>\n"
401 buf
+= "#include <asm/unaligned.h>\n"
402 buf
+= "#include <scsi/scsi_common.h>\n"
403 buf
+= "#include <scsi/scsi_proto.h>\n"
404 buf
+= "#include <target/target_core_base.h>\n"
405 buf
+= "#include <target/target_core_fabric.h>\n"
406 buf
+= "#include \"" + fabric_mod_name
+ "_base.h\"\n"
407 buf
+= "#include \"" + fabric_mod_name
+ "_fabric.h\"\n\n"
409 buf
+= "int " + fabric_mod_name
+ "_check_true(struct se_portal_group *se_tpg)\n"
411 buf
+= " return 1;\n"
413 bufi
+= "int " + fabric_mod_name
+ "_check_true(struct se_portal_group *);\n"
415 buf
+= "int " + fabric_mod_name
+ "_check_false(struct se_portal_group *se_tpg)\n"
417 buf
+= " return 0;\n"
419 bufi
+= "int " + fabric_mod_name
+ "_check_false(struct se_portal_group *);\n"
421 total_fabric_ops
= len(fabric_ops
)
424 while i
< total_fabric_ops
:
427 # print "fabric_ops: " + fo
429 if re
.search('get_fabric_name', fo
):
430 buf
+= "char *" + fabric_mod_name
+ "_get_fabric_name(void)\n"
432 buf
+= " return \"" + fabric_mod_name
+ "\";\n"
434 bufi
+= "char *" + fabric_mod_name
+ "_get_fabric_name(void);\n"
437 if re
.search('get_wwn', fo
):
438 buf
+= "char *" + fabric_mod_name
+ "_get_fabric_wwn(struct se_portal_group *se_tpg)\n"
440 buf
+= " struct " + fabric_mod_name
+ "_tpg *tpg = container_of(se_tpg,\n"
441 buf
+= " struct " + fabric_mod_name
+ "_tpg, se_tpg);\n"
442 buf
+= " struct " + fabric_mod_name
+ "_" + fabric_mod_port
+ " *" + fabric_mod_port
+ " = tpg->" + fabric_mod_port
+ ";\n\n"
443 buf
+= " return &" + fabric_mod_port
+ "->" + fabric_mod_port
+ "_name[0];\n"
445 bufi
+= "char *" + fabric_mod_name
+ "_get_fabric_wwn(struct se_portal_group *);\n"
447 if re
.search('get_tag', fo
):
448 buf
+= "u16 " + fabric_mod_name
+ "_get_tag(struct se_portal_group *se_tpg)\n"
450 buf
+= " struct " + fabric_mod_name
+ "_tpg *tpg = container_of(se_tpg,\n"
451 buf
+= " struct " + fabric_mod_name
+ "_tpg, se_tpg);\n"
452 buf
+= " return tpg->" + fabric_mod_port
+ "_tpgt;\n"
454 bufi
+= "u16 " + fabric_mod_name
+ "_get_tag(struct se_portal_group *);\n"
456 if re
.search('tpg_get_inst_index\)\(', fo
):
457 buf
+= "u32 " + fabric_mod_name
+ "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n"
459 buf
+= " return 1;\n"
461 bufi
+= "u32 " + fabric_mod_name
+ "_tpg_get_inst_index(struct se_portal_group *);\n"
463 if re
.search('\*release_cmd\)\(', fo
):
464 buf
+= "void " + fabric_mod_name
+ "_release_cmd(struct se_cmd *se_cmd)\n"
468 bufi
+= "void " + fabric_mod_name
+ "_release_cmd(struct se_cmd *);\n"
470 if re
.search('shutdown_session\)\(', fo
):
471 buf
+= "int " + fabric_mod_name
+ "_shutdown_session(struct se_session *se_sess)\n"
473 buf
+= " return 0;\n"
475 bufi
+= "int " + fabric_mod_name
+ "_shutdown_session(struct se_session *);\n"
477 if re
.search('close_session\)\(', fo
):
478 buf
+= "void " + fabric_mod_name
+ "_close_session(struct se_session *se_sess)\n"
482 bufi
+= "void " + fabric_mod_name
+ "_close_session(struct se_session *);\n"
484 if re
.search('sess_get_index\)\(', fo
):
485 buf
+= "u32 " + fabric_mod_name
+ "_sess_get_index(struct se_session *se_sess)\n"
487 buf
+= " return 0;\n"
489 bufi
+= "u32 " + fabric_mod_name
+ "_sess_get_index(struct se_session *);\n"
491 if re
.search('write_pending\)\(', fo
):
492 buf
+= "int " + fabric_mod_name
+ "_write_pending(struct se_cmd *se_cmd)\n"
494 buf
+= " return 0;\n"
496 bufi
+= "int " + fabric_mod_name
+ "_write_pending(struct se_cmd *);\n"
498 if re
.search('write_pending_status\)\(', fo
):
499 buf
+= "int " + fabric_mod_name
+ "_write_pending_status(struct se_cmd *se_cmd)\n"
501 buf
+= " return 0;\n"
503 bufi
+= "int " + fabric_mod_name
+ "_write_pending_status(struct se_cmd *);\n"
505 if re
.search('set_default_node_attributes\)\(', fo
):
506 buf
+= "void " + fabric_mod_name
+ "_set_default_node_attrs(struct se_node_acl *nacl)\n"
510 bufi
+= "void " + fabric_mod_name
+ "_set_default_node_attrs(struct se_node_acl *);\n"
512 if re
.search('get_cmd_state\)\(', fo
):
513 buf
+= "int " + fabric_mod_name
+ "_get_cmd_state(struct se_cmd *se_cmd)\n"
515 buf
+= " return 0;\n"
517 bufi
+= "int " + fabric_mod_name
+ "_get_cmd_state(struct se_cmd *);\n"
519 if re
.search('queue_data_in\)\(', fo
):
520 buf
+= "int " + fabric_mod_name
+ "_queue_data_in(struct se_cmd *se_cmd)\n"
522 buf
+= " return 0;\n"
524 bufi
+= "int " + fabric_mod_name
+ "_queue_data_in(struct se_cmd *);\n"
526 if re
.search('queue_status\)\(', fo
):
527 buf
+= "int " + fabric_mod_name
+ "_queue_status(struct se_cmd *se_cmd)\n"
529 buf
+= " return 0;\n"
531 bufi
+= "int " + fabric_mod_name
+ "_queue_status(struct se_cmd *);\n"
533 if re
.search('queue_tm_rsp\)\(', fo
):
534 buf
+= "void " + fabric_mod_name
+ "_queue_tm_rsp(struct se_cmd *se_cmd)\n"
538 bufi
+= "void " + fabric_mod_name
+ "_queue_tm_rsp(struct se_cmd *);\n"
540 if re
.search('aborted_task\)\(', fo
):
541 buf
+= "void " + fabric_mod_name
+ "_aborted_task(struct se_cmd *se_cmd)\n"
545 bufi
+= "void " + fabric_mod_name
+ "_aborted_task(struct se_cmd *);\n"
549 tcm_mod_err("Unable to write f: " + f
)
555 tcm_mod_err("Unable to write fi: " + fi
)
560 def tcm_mod_build_kbuild(fabric_mod_dir_var
, fabric_mod_name
):
563 f
= fabric_mod_dir_var
+ "/Makefile"
564 print "Writing file: " + f
568 tcm_mod_err("Unable to open file: " + f
)
570 buf
+= fabric_mod_name
+ "-objs := " + fabric_mod_name
+ "_fabric.o \\\n"
571 buf
+= " " + fabric_mod_name
+ "_configfs.o\n"
572 buf
+= "obj-$(CONFIG_" + fabric_mod_name
.upper() + ") += " + fabric_mod_name
+ ".o\n"
576 tcm_mod_err("Unable to write f: " + f
)
581 def tcm_mod_build_kconfig(fabric_mod_dir_var
, fabric_mod_name
):
584 f
= fabric_mod_dir_var
+ "/Kconfig"
585 print "Writing file: " + f
589 tcm_mod_err("Unable to open file: " + f
)
591 buf
= "config " + fabric_mod_name
.upper() + "\n"
592 buf
+= " tristate \"" + fabric_mod_name
.upper() + " fabric module\"\n"
593 buf
+= " depends on TARGET_CORE && CONFIGFS_FS\n"
594 buf
+= " default n\n"
595 buf
+= " ---help---\n"
596 buf
+= " Say Y here to enable the " + fabric_mod_name
.upper() + " fabric module\n"
600 tcm_mod_err("Unable to write f: " + f
)
605 def tcm_mod_add_kbuild(tcm_dir
, fabric_mod_name
):
606 buf
= "obj-$(CONFIG_" + fabric_mod_name
.upper() + ") += " + fabric_mod_name
.lower() + "/\n"
607 kbuild
= tcm_dir
+ "/drivers/target/Makefile"
609 f
= open(kbuild
, 'a')
614 def tcm_mod_add_kconfig(tcm_dir
, fabric_mod_name
):
615 buf
= "source \"drivers/target/" + fabric_mod_name
.lower() + "/Kconfig\"\n"
616 kconfig
= tcm_dir
+ "/drivers/target/Kconfig"
618 f
= open(kconfig
, 'a')
623 def main(modname
, proto_ident
):
625 # proto_ident = "SAS"
626 # proto_ident = "iSCSI"
628 tcm_dir
= os
.getcwd();
630 print "tcm_dir: " + tcm_dir
631 fabric_mod_name
= modname
632 fabric_mod_dir
= tcm_dir
+ "drivers/target/" + fabric_mod_name
633 print "Set fabric_mod_name: " + fabric_mod_name
634 print "Set fabric_mod_dir: " + fabric_mod_dir
635 print "Using proto_ident: " + proto_ident
637 if proto_ident
!= "FC" and proto_ident
!= "SAS" and proto_ident
!= "iSCSI":
638 print "Unsupported proto_ident: " + proto_ident
641 ret
= tcm_mod_create_module_subdir(fabric_mod_dir
)
643 print "tcm_mod_create_module_subdir() failed because module already exists!"
646 tcm_mod_build_base_includes(proto_ident
, fabric_mod_dir
, fabric_mod_name
)
647 tcm_mod_scan_fabric_ops(tcm_dir
)
648 tcm_mod_dump_fabric_ops(proto_ident
, fabric_mod_dir
, fabric_mod_name
)
649 tcm_mod_build_configfs(proto_ident
, fabric_mod_dir
, fabric_mod_name
)
650 tcm_mod_build_kbuild(fabric_mod_dir
, fabric_mod_name
)
651 tcm_mod_build_kconfig(fabric_mod_dir
, fabric_mod_name
)
653 input = raw_input("Would you like to add " + fabric_mod_name
+ " to drivers/target/Makefile..? [yes,no]: ")
654 if input == "yes" or input == "y":
655 tcm_mod_add_kbuild(tcm_dir
, fabric_mod_name
)
657 input = raw_input("Would you like to add " + fabric_mod_name
+ " to drivers/target/Kconfig..? [yes,no]: ")
658 if input == "yes" or input == "y":
659 tcm_mod_add_kconfig(tcm_dir
, fabric_mod_name
)
663 parser
= optparse
.OptionParser()
664 parser
.add_option('-m', '--modulename', help='Module name', dest
='modname',
665 action
='store', nargs
=1, type='string')
666 parser
.add_option('-p', '--protoident', help='Protocol Ident', dest
='protoident',
667 action
='store', nargs
=1, type='string')
669 (opts
, args
) = parser
.parse_args()
671 mandatories
= ['modname', 'protoident']
672 for m
in mandatories
:
673 if not opts
.__dict
__[m
]:
674 print "mandatory option is missing\n"
678 if __name__
== "__main__":
680 main(str(opts
.modname
), opts
.protoident
)