0001
0002
0003
0004
0005
0006
0007
0008
0009 import os, sys
0010 import subprocess as sub
0011 import string
0012 import re
0013 import optparse
0014
0015 tcm_dir = ""
0016
0017 fabric_ops = []
0018 fabric_mod_dir = ""
0019 fabric_mod_port = ""
0020 fabric_mod_init_port = ""
0021
0022 def tcm_mod_err(msg):
0023 print msg
0024 sys.exit(1)
0025
0026 def tcm_mod_create_module_subdir(fabric_mod_dir_var):
0027
0028 if os.path.isdir(fabric_mod_dir_var) == True:
0029 return 1
0030
0031 print "Creating fabric_mod_dir: " + fabric_mod_dir_var
0032 ret = os.mkdir(fabric_mod_dir_var)
0033 if ret:
0034 tcm_mod_err("Unable to mkdir " + fabric_mod_dir_var)
0035
0036 return
0037
0038 def tcm_mod_build_FC_include(fabric_mod_dir_var, fabric_mod_name):
0039 global fabric_mod_port
0040 global fabric_mod_init_port
0041 buf = ""
0042
0043 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
0044 print "Writing file: " + f
0045
0046 p = open(f, 'w');
0047 if not p:
0048 tcm_mod_err("Unable to open file: " + f)
0049
0050 buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
0051 buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
0052 buf += "\n"
0053 buf += "struct " + fabric_mod_name + "_tpg {\n"
0054 buf += " /* FC lport target portal group tag for TCM */\n"
0055 buf += " u16 lport_tpgt;\n"
0056 buf += " /* Pointer back to " + fabric_mod_name + "_lport */\n"
0057 buf += " struct " + fabric_mod_name + "_lport *lport;\n"
0058 buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
0059 buf += " struct se_portal_group se_tpg;\n"
0060 buf += "};\n"
0061 buf += "\n"
0062 buf += "struct " + fabric_mod_name + "_lport {\n"
0063 buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n"
0064 buf += " u64 lport_wwpn;\n"
0065 buf += " /* ASCII formatted WWPN for FC Target Lport */\n"
0066 buf += " char lport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
0067 buf += " /* Returned by " + fabric_mod_name + "_make_lport() */\n"
0068 buf += " struct se_wwn lport_wwn;\n"
0069 buf += "};\n"
0070
0071 ret = p.write(buf)
0072 if ret:
0073 tcm_mod_err("Unable to write f: " + f)
0074
0075 p.close()
0076
0077 fabric_mod_port = "lport"
0078 fabric_mod_init_port = "nport"
0079
0080 return
0081
0082 def tcm_mod_build_SAS_include(fabric_mod_dir_var, fabric_mod_name):
0083 global fabric_mod_port
0084 global fabric_mod_init_port
0085 buf = ""
0086
0087 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
0088 print "Writing file: " + f
0089
0090 p = open(f, 'w');
0091 if not p:
0092 tcm_mod_err("Unable to open file: " + f)
0093
0094 buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
0095 buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
0096 buf += "\n"
0097 buf += "struct " + fabric_mod_name + "_tpg {\n"
0098 buf += " /* SAS port target portal group tag for TCM */\n"
0099 buf += " u16 tport_tpgt;\n"
0100 buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n"
0101 buf += " struct " + fabric_mod_name + "_tport *tport;\n"
0102 buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
0103 buf += " struct se_portal_group se_tpg;\n"
0104 buf += "};\n\n"
0105 buf += "struct " + fabric_mod_name + "_tport {\n"
0106 buf += " /* Binary World Wide unique Port Name for SAS Target port */\n"
0107 buf += " u64 tport_wwpn;\n"
0108 buf += " /* ASCII formatted WWPN for SAS Target port */\n"
0109 buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
0110 buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n"
0111 buf += " struct se_wwn tport_wwn;\n"
0112 buf += "};\n"
0113
0114 ret = p.write(buf)
0115 if ret:
0116 tcm_mod_err("Unable to write f: " + f)
0117
0118 p.close()
0119
0120 fabric_mod_port = "tport"
0121 fabric_mod_init_port = "iport"
0122
0123 return
0124
0125 def tcm_mod_build_iSCSI_include(fabric_mod_dir_var, fabric_mod_name):
0126 global fabric_mod_port
0127 global fabric_mod_init_port
0128 buf = ""
0129
0130 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"
0131 print "Writing file: " + f
0132
0133 p = open(f, 'w');
0134 if not p:
0135 tcm_mod_err("Unable to open file: " + f)
0136
0137 buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n"
0138 buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n"
0139 buf += "\n"
0140 buf += "struct " + fabric_mod_name + "_tpg {\n"
0141 buf += " /* iSCSI target portal group tag for TCM */\n"
0142 buf += " u16 tport_tpgt;\n"
0143 buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n"
0144 buf += " struct " + fabric_mod_name + "_tport *tport;\n"
0145 buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n"
0146 buf += " struct se_portal_group se_tpg;\n"
0147 buf += "};\n\n"
0148 buf += "struct " + fabric_mod_name + "_tport {\n"
0149 buf += " /* ASCII formatted TargetName for IQN */\n"
0150 buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n"
0151 buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n"
0152 buf += " struct se_wwn tport_wwn;\n"
0153 buf += "};\n"
0154
0155 ret = p.write(buf)
0156 if ret:
0157 tcm_mod_err("Unable to write f: " + f)
0158
0159 p.close()
0160
0161 fabric_mod_port = "tport"
0162 fabric_mod_init_port = "iport"
0163
0164 return
0165
0166 def tcm_mod_build_base_includes(proto_ident, fabric_mod_dir_val, fabric_mod_name):
0167
0168 if proto_ident == "FC":
0169 tcm_mod_build_FC_include(fabric_mod_dir_val, fabric_mod_name)
0170 elif proto_ident == "SAS":
0171 tcm_mod_build_SAS_include(fabric_mod_dir_val, fabric_mod_name)
0172 elif proto_ident == "iSCSI":
0173 tcm_mod_build_iSCSI_include(fabric_mod_dir_val, fabric_mod_name)
0174 else:
0175 print "Unsupported proto_ident: " + proto_ident
0176 sys.exit(1)
0177
0178 return
0179
0180 def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
0181 buf = ""
0182
0183 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_configfs.c"
0184 print "Writing file: " + f
0185
0186 p = open(f, 'w');
0187 if not p:
0188 tcm_mod_err("Unable to open file: " + f)
0189
0190 buf = "#include <linux/module.h>\n"
0191 buf += "#include <linux/moduleparam.h>\n"
0192 buf += "#include <linux/version.h>\n"
0193 buf += "#include <generated/utsrelease.h>\n"
0194 buf += "#include <linux/utsname.h>\n"
0195 buf += "#include <linux/init.h>\n"
0196 buf += "#include <linux/slab.h>\n"
0197 buf += "#include <linux/kthread.h>\n"
0198 buf += "#include <linux/types.h>\n"
0199 buf += "#include <linux/string.h>\n"
0200 buf += "#include <linux/configfs.h>\n"
0201 buf += "#include <linux/ctype.h>\n"
0202 buf += "#include <asm/unaligned.h>\n"
0203 buf += "#include <scsi/scsi_proto.h>\n\n"
0204 buf += "#include <target/target_core_base.h>\n"
0205 buf += "#include <target/target_core_fabric.h>\n"
0206 buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
0207 buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
0208
0209 buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops;\n\n"
0210
0211 buf += "static struct se_portal_group *" + fabric_mod_name + "_make_tpg(\n"
0212 buf += " struct se_wwn *wwn,\n"
0213 buf += " struct config_group *group,\n"
0214 buf += " const char *name)\n"
0215 buf += "{\n"
0216 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + "*" + fabric_mod_port + " = container_of(wwn,\n"
0217 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n\n"
0218 buf += " struct " + fabric_mod_name + "_tpg *tpg;\n"
0219 buf += " unsigned long tpgt;\n"
0220 buf += " int ret;\n\n"
0221 buf += " if (strstr(name, \"tpgt_\") != name)\n"
0222 buf += " return ERR_PTR(-EINVAL);\n"
0223 buf += " if (kstrtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)\n"
0224 buf += " return ERR_PTR(-EINVAL);\n\n"
0225 buf += " tpg = kzalloc(sizeof(struct " + fabric_mod_name + "_tpg), GFP_KERNEL);\n"
0226 buf += " if (!tpg) {\n"
0227 buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_tpg\");\n"
0228 buf += " return ERR_PTR(-ENOMEM);\n"
0229 buf += " }\n"
0230 buf += " tpg->" + fabric_mod_port + " = " + fabric_mod_port + ";\n"
0231 buf += " tpg->" + fabric_mod_port + "_tpgt = tpgt;\n\n"
0232
0233 if proto_ident == "FC":
0234 buf += " ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_FCP);\n"
0235 elif proto_ident == "SAS":
0236 buf += " ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_SAS);\n"
0237 elif proto_ident == "iSCSI":
0238 buf += " ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_ISCSI);\n"
0239
0240 buf += " if (ret < 0) {\n"
0241 buf += " kfree(tpg);\n"
0242 buf += " return NULL;\n"
0243 buf += " }\n"
0244 buf += " return &tpg->se_tpg;\n"
0245 buf += "}\n\n"
0246 buf += "static void " + fabric_mod_name + "_drop_tpg(struct se_portal_group *se_tpg)\n"
0247 buf += "{\n"
0248 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
0249 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n\n"
0250 buf += " core_tpg_deregister(se_tpg);\n"
0251 buf += " kfree(tpg);\n"
0252 buf += "}\n\n"
0253
0254 buf += "static struct se_wwn *" + fabric_mod_name + "_make_" + fabric_mod_port + "(\n"
0255 buf += " struct target_fabric_configfs *tf,\n"
0256 buf += " struct config_group *group,\n"
0257 buf += " const char *name)\n"
0258 buf += "{\n"
0259 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + ";\n"
0260
0261 if proto_ident == "FC" or proto_ident == "SAS":
0262 buf += " u64 wwpn = 0;\n\n"
0263
0264 buf += " /* if (" + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"
0265 buf += " return ERR_PTR(-EINVAL); */\n\n"
0266 buf += " " + fabric_mod_port + " = kzalloc(sizeof(struct " + fabric_mod_name + "_" + fabric_mod_port + "), GFP_KERNEL);\n"
0267 buf += " if (!" + fabric_mod_port + ") {\n"
0268 buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_" + fabric_mod_port + "\");\n"
0269 buf += " return ERR_PTR(-ENOMEM);\n"
0270 buf += " }\n"
0271
0272 if proto_ident == "FC" or proto_ident == "SAS":
0273 buf += " " + fabric_mod_port + "->" + fabric_mod_port + "_wwpn = wwpn;\n"
0274
0275 buf += " /* " + fabric_mod_name + "_format_wwn(&" + fabric_mod_port + "->" + fabric_mod_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"
0276 buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_wwn;\n"
0277 buf += "}\n\n"
0278 buf += "static void " + fabric_mod_name + "_drop_" + fabric_mod_port + "(struct se_wwn *wwn)\n"
0279 buf += "{\n"
0280 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = container_of(wwn,\n"
0281 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n"
0282 buf += " kfree(" + fabric_mod_port + ");\n"
0283 buf += "}\n\n"
0284
0285 buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n"
0286 buf += " .module = THIS_MODULE,\n"
0287 buf += " .name = \"" + fabric_mod_name + "\",\n"
0288 buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n"
0289 buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n"
0290 buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n"
0291 buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n"
0292 buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n"
0293 buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n"
0294 buf += " .tpg_check_prod_mode_write_protect = " + fabric_mod_name + "_check_false,\n"
0295 buf += " .tpg_get_inst_index = " + fabric_mod_name + "_tpg_get_inst_index,\n"
0296 buf += " .release_cmd = " + fabric_mod_name + "_release_cmd,\n"
0297 buf += " .sess_get_index = " + fabric_mod_name + "_sess_get_index,\n"
0298 buf += " .sess_get_initiator_sid = NULL,\n"
0299 buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n"
0300 buf += " .set_default_node_attributes = " + fabric_mod_name + "_set_default_node_attrs,\n"
0301 buf += " .get_cmd_state = " + fabric_mod_name + "_get_cmd_state,\n"
0302 buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n"
0303 buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n"
0304 buf += " .queue_tm_rsp = " + fabric_mod_name + "_queue_tm_rsp,\n"
0305 buf += " .aborted_task = " + fabric_mod_name + "_aborted_task,\n"
0306 buf += " /*\n"
0307 buf += " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n"
0308 buf += " */\n"
0309 buf += " .fabric_make_wwn = " + fabric_mod_name + "_make_" + fabric_mod_port + ",\n"
0310 buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n"
0311 buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n"
0312 buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n"
0313 buf += "};\n\n"
0314
0315 buf += "static int __init " + fabric_mod_name + "_init(void)\n"
0316 buf += "{\n"
0317 buf += " return target_register_template(&" + fabric_mod_name + "_ops);\n"
0318 buf += "};\n\n"
0319
0320 buf += "static void __exit " + fabric_mod_name + "_exit(void)\n"
0321 buf += "{\n"
0322 buf += " target_unregister_template(&" + fabric_mod_name + "_ops);\n"
0323 buf += "};\n\n"
0324
0325 buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n"
0326 buf += "MODULE_LICENSE(\"GPL\");\n"
0327 buf += "module_init(" + fabric_mod_name + "_init);\n"
0328 buf += "module_exit(" + fabric_mod_name + "_exit);\n"
0329
0330 ret = p.write(buf)
0331 if ret:
0332 tcm_mod_err("Unable to write f: " + f)
0333
0334 p.close()
0335
0336 return
0337
0338 def tcm_mod_scan_fabric_ops(tcm_dir):
0339
0340 fabric_ops_api = tcm_dir + "include/target/target_core_fabric.h"
0341
0342 print "Using tcm_mod_scan_fabric_ops: " + fabric_ops_api
0343 process_fo = 0;
0344
0345 p = open(fabric_ops_api, 'r')
0346
0347 line = p.readline()
0348 while line:
0349 if process_fo == 0 and re.search('struct target_core_fabric_ops {', line):
0350 line = p.readline()
0351 continue
0352
0353 if process_fo == 0:
0354 process_fo = 1;
0355 line = p.readline()
0356
0357 if not re.search('\(\*', line):
0358 continue
0359
0360 fabric_ops.append(line.rstrip())
0361 continue
0362
0363 line = p.readline()
0364
0365 if not re.search('\(\*', line):
0366 continue
0367
0368 fabric_ops.append(line.rstrip())
0369
0370 p.close()
0371 return
0372
0373 def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name):
0374 buf = ""
0375 bufi = ""
0376
0377 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.c"
0378 print "Writing file: " + f
0379
0380 p = open(f, 'w')
0381 if not p:
0382 tcm_mod_err("Unable to open file: " + f)
0383
0384 fi = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.h"
0385 print "Writing file: " + fi
0386
0387 pi = open(fi, 'w')
0388 if not pi:
0389 tcm_mod_err("Unable to open file: " + fi)
0390
0391 buf = "#include <linux/slab.h>\n"
0392 buf += "#include <linux/kthread.h>\n"
0393 buf += "#include <linux/types.h>\n"
0394 buf += "#include <linux/list.h>\n"
0395 buf += "#include <linux/types.h>\n"
0396 buf += "#include <linux/string.h>\n"
0397 buf += "#include <linux/ctype.h>\n"
0398 buf += "#include <asm/unaligned.h>\n"
0399 buf += "#include <scsi/scsi_common.h>\n"
0400 buf += "#include <scsi/scsi_proto.h>\n"
0401 buf += "#include <target/target_core_base.h>\n"
0402 buf += "#include <target/target_core_fabric.h>\n"
0403 buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
0404 buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
0405
0406 buf += "int " + fabric_mod_name + "_check_true(struct se_portal_group *se_tpg)\n"
0407 buf += "{\n"
0408 buf += " return 1;\n"
0409 buf += "}\n\n"
0410 bufi += "int " + fabric_mod_name + "_check_true(struct se_portal_group *);\n"
0411
0412 buf += "int " + fabric_mod_name + "_check_false(struct se_portal_group *se_tpg)\n"
0413 buf += "{\n"
0414 buf += " return 0;\n"
0415 buf += "}\n\n"
0416 bufi += "int " + fabric_mod_name + "_check_false(struct se_portal_group *);\n"
0417
0418 total_fabric_ops = len(fabric_ops)
0419 i = 0
0420
0421 while i < total_fabric_ops:
0422 fo = fabric_ops[i]
0423 i += 1
0424
0425
0426 if re.search('get_fabric_name', fo):
0427 buf += "char *" + fabric_mod_name + "_get_fabric_name(void)\n"
0428 buf += "{\n"
0429 buf += " return \"" + fabric_mod_name + "\";\n"
0430 buf += "}\n\n"
0431 bufi += "char *" + fabric_mod_name + "_get_fabric_name(void);\n"
0432 continue
0433
0434 if re.search('get_wwn', fo):
0435 buf += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *se_tpg)\n"
0436 buf += "{\n"
0437 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
0438 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
0439 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n\n"
0440 buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_name[0];\n"
0441 buf += "}\n\n"
0442 bufi += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *);\n"
0443
0444 if re.search('get_tag', fo):
0445 buf += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *se_tpg)\n"
0446 buf += "{\n"
0447 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
0448 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
0449 buf += " return tpg->" + fabric_mod_port + "_tpgt;\n"
0450 buf += "}\n\n"
0451 bufi += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *);\n"
0452
0453 if re.search('tpg_get_inst_index\)\(', fo):
0454 buf += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n"
0455 buf += "{\n"
0456 buf += " return 1;\n"
0457 buf += "}\n\n"
0458 bufi += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *);\n"
0459
0460 if re.search('\*release_cmd\)\(', fo):
0461 buf += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *se_cmd)\n"
0462 buf += "{\n"
0463 buf += " return;\n"
0464 buf += "}\n\n"
0465 bufi += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *);\n"
0466
0467 if re.search('sess_get_index\)\(', fo):
0468 buf += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *se_sess)\n"
0469 buf += "{\n"
0470 buf += " return 0;\n"
0471 buf += "}\n\n"
0472 bufi += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *);\n"
0473
0474 if re.search('write_pending\)\(', fo):
0475 buf += "int " + fabric_mod_name + "_write_pending(struct se_cmd *se_cmd)\n"
0476 buf += "{\n"
0477 buf += " return 0;\n"
0478 buf += "}\n\n"
0479 bufi += "int " + fabric_mod_name + "_write_pending(struct se_cmd *);\n"
0480
0481 if re.search('set_default_node_attributes\)\(', fo):
0482 buf += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *nacl)\n"
0483 buf += "{\n"
0484 buf += " return;\n"
0485 buf += "}\n\n"
0486 bufi += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *);\n"
0487
0488 if re.search('get_cmd_state\)\(', fo):
0489 buf += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *se_cmd)\n"
0490 buf += "{\n"
0491 buf += " return 0;\n"
0492 buf += "}\n\n"
0493 bufi += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *);\n"
0494
0495 if re.search('queue_data_in\)\(', fo):
0496 buf += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *se_cmd)\n"
0497 buf += "{\n"
0498 buf += " return 0;\n"
0499 buf += "}\n\n"
0500 bufi += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *);\n"
0501
0502 if re.search('queue_status\)\(', fo):
0503 buf += "int " + fabric_mod_name + "_queue_status(struct se_cmd *se_cmd)\n"
0504 buf += "{\n"
0505 buf += " return 0;\n"
0506 buf += "}\n\n"
0507 bufi += "int " + fabric_mod_name + "_queue_status(struct se_cmd *);\n"
0508
0509 if re.search('queue_tm_rsp\)\(', fo):
0510 buf += "void " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *se_cmd)\n"
0511 buf += "{\n"
0512 buf += " return;\n"
0513 buf += "}\n\n"
0514 bufi += "void " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *);\n"
0515
0516 if re.search('aborted_task\)\(', fo):
0517 buf += "void " + fabric_mod_name + "_aborted_task(struct se_cmd *se_cmd)\n"
0518 buf += "{\n"
0519 buf += " return;\n"
0520 buf += "}\n\n"
0521 bufi += "void " + fabric_mod_name + "_aborted_task(struct se_cmd *);\n"
0522
0523 ret = p.write(buf)
0524 if ret:
0525 tcm_mod_err("Unable to write f: " + f)
0526
0527 p.close()
0528
0529 ret = pi.write(bufi)
0530 if ret:
0531 tcm_mod_err("Unable to write fi: " + fi)
0532
0533 pi.close()
0534 return
0535
0536 def tcm_mod_build_kbuild(fabric_mod_dir_var, fabric_mod_name):
0537
0538 buf = ""
0539 f = fabric_mod_dir_var + "/Makefile"
0540 print "Writing file: " + f
0541
0542 p = open(f, 'w')
0543 if not p:
0544 tcm_mod_err("Unable to open file: " + f)
0545
0546 buf += fabric_mod_name + "-objs := " + fabric_mod_name + "_fabric.o \\\n"
0547 buf += " " + fabric_mod_name + "_configfs.o\n"
0548 buf += "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name + ".o\n"
0549
0550 ret = p.write(buf)
0551 if ret:
0552 tcm_mod_err("Unable to write f: " + f)
0553
0554 p.close()
0555 return
0556
0557 def tcm_mod_build_kconfig(fabric_mod_dir_var, fabric_mod_name):
0558
0559 buf = ""
0560 f = fabric_mod_dir_var + "/Kconfig"
0561 print "Writing file: " + f
0562
0563 p = open(f, 'w')
0564 if not p:
0565 tcm_mod_err("Unable to open file: " + f)
0566
0567 buf = "config " + fabric_mod_name.upper() + "\n"
0568 buf += " tristate \"" + fabric_mod_name.upper() + " fabric module\"\n"
0569 buf += " depends on TARGET_CORE && CONFIGFS_FS\n"
0570 buf += " default n\n"
0571 buf += " help\n"
0572 buf += " Say Y here to enable the " + fabric_mod_name.upper() + " fabric module\n"
0573
0574 ret = p.write(buf)
0575 if ret:
0576 tcm_mod_err("Unable to write f: " + f)
0577
0578 p.close()
0579 return
0580
0581 def tcm_mod_add_kbuild(tcm_dir, fabric_mod_name):
0582 buf = "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name.lower() + "/\n"
0583 kbuild = tcm_dir + "/drivers/target/Makefile"
0584
0585 f = open(kbuild, 'a')
0586 f.write(buf)
0587 f.close()
0588 return
0589
0590 def tcm_mod_add_kconfig(tcm_dir, fabric_mod_name):
0591 buf = "source \"drivers/target/" + fabric_mod_name.lower() + "/Kconfig\"\n"
0592 kconfig = tcm_dir + "/drivers/target/Kconfig"
0593
0594 f = open(kconfig, 'a')
0595 f.write(buf)
0596 f.close()
0597 return
0598
0599 def main(modname, proto_ident):
0600
0601
0602
0603
0604 tcm_dir = os.getcwd();
0605 tcm_dir += "/../../"
0606 print "tcm_dir: " + tcm_dir
0607 fabric_mod_name = modname
0608 fabric_mod_dir = tcm_dir + "drivers/target/" + fabric_mod_name
0609 print "Set fabric_mod_name: " + fabric_mod_name
0610 print "Set fabric_mod_dir: " + fabric_mod_dir
0611 print "Using proto_ident: " + proto_ident
0612
0613 if proto_ident != "FC" and proto_ident != "SAS" and proto_ident != "iSCSI":
0614 print "Unsupported proto_ident: " + proto_ident
0615 sys.exit(1)
0616
0617 ret = tcm_mod_create_module_subdir(fabric_mod_dir)
0618 if ret:
0619 print "tcm_mod_create_module_subdir() failed because module already exists!"
0620 sys.exit(1)
0621
0622 tcm_mod_build_base_includes(proto_ident, fabric_mod_dir, fabric_mod_name)
0623 tcm_mod_scan_fabric_ops(tcm_dir)
0624 tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir, fabric_mod_name)
0625 tcm_mod_build_configfs(proto_ident, fabric_mod_dir, fabric_mod_name)
0626 tcm_mod_build_kbuild(fabric_mod_dir, fabric_mod_name)
0627 tcm_mod_build_kconfig(fabric_mod_dir, fabric_mod_name)
0628
0629 input = raw_input("Would you like to add " + fabric_mod_name + " to drivers/target/Makefile..? [yes,no]: ")
0630 if input == "yes" or input == "y":
0631 tcm_mod_add_kbuild(tcm_dir, fabric_mod_name)
0632
0633 input = raw_input("Would you like to add " + fabric_mod_name + " to drivers/target/Kconfig..? [yes,no]: ")
0634 if input == "yes" or input == "y":
0635 tcm_mod_add_kconfig(tcm_dir, fabric_mod_name)
0636
0637 return
0638
0639 parser = optparse.OptionParser()
0640 parser.add_option('-m', '--modulename', help='Module name', dest='modname',
0641 action='store', nargs=1, type='string')
0642 parser.add_option('-p', '--protoident', help='Protocol Ident', dest='protoident',
0643 action='store', nargs=1, type='string')
0644
0645 (opts, args) = parser.parse_args()
0646
0647 mandatories = ['modname', 'protoident']
0648 for m in mandatories:
0649 if not opts.__dict__[m]:
0650 print "mandatory option is missing\n"
0651 parser.print_help()
0652 exit(-1)
0653
0654 if __name__ == "__main__":
0655
0656 main(str(opts.modname), opts.protoident)