How to use mod method in Nose

Best Python code snippet using nose

tcm_mod_builder.py

Source:tcm_mod_builder.py Github

copy

Full Screen

1#!/usr/bin/python2# The TCM v4 multi-protocol fabric module generation script for drivers/target/$NEW_MOD3#4# Copyright (c) 2010 Rising Tide Systems5# Copyright (c) 2010 Linux-iSCSI.org6#7# Author: nab@kernel.org8#9import os, sys10import subprocess as sub11import string12import re13import optparse14tcm_dir = ""15fabric_ops = []16fabric_mod_dir = ""17fabric_mod_port = ""18fabric_mod_init_port = ""19def tcm_mod_err(msg):20 print msg21 sys.exit(1)22def tcm_mod_create_module_subdir(fabric_mod_dir_var):23 if os.path.isdir(fabric_mod_dir_var) == True:24 return 125 print "Creating fabric_mod_dir: " + fabric_mod_dir_var26 ret = os.mkdir(fabric_mod_dir_var)27 if ret:28 tcm_mod_err("Unable to mkdir " + fabric_mod_dir_var)29 return30def tcm_mod_build_FC_include(fabric_mod_dir_var, fabric_mod_name):31 global fabric_mod_port32 global fabric_mod_init_port33 buf = ""34 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"35 print "Writing file: " + f36 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 return77def tcm_mod_build_SAS_include(fabric_mod_dir_var, fabric_mod_name):78 global fabric_mod_port79 global fabric_mod_init_port80 buf = ""81 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"82 print "Writing file: " + f83 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 return122def tcm_mod_build_iSCSI_include(fabric_mod_dir_var, fabric_mod_name):123 global fabric_mod_port124 global fabric_mod_init_port125 buf = ""126 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h"127 print "Writing file: " + f128 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 return163def 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_ident172 sys.exit(1)173 return174def 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: " + f178 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 += "/* Local pointer to allocated TCM configfs fabric module */\n"202 buf += "struct target_fabric_configfs *" + fabric_mod_name + "_fabric_configfs;\n\n"203 buf += "static struct se_node_acl *" + fabric_mod_name + "_make_nodeacl(\n"204 buf += " struct se_portal_group *se_tpg,\n"205 buf += " struct config_group *group,\n"206 buf += " const char *name)\n"207 buf += "{\n"208 buf += " struct se_node_acl *se_nacl, *se_nacl_new;\n"209 buf += " struct " + fabric_mod_name + "_nacl *nacl;\n"210 if proto_ident == "FC" or proto_ident == "SAS":211 buf += " u64 wwpn = 0;\n"212 buf += " u32 nexus_depth;\n\n"213 buf += " /* " + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"214 buf += " return ERR_PTR(-EINVAL); */\n"215 buf += " se_nacl_new = " + fabric_mod_name + "_alloc_fabric_acl(se_tpg);\n"216 buf += " if (!se_nacl_new)\n"217 buf += " return ERR_PTR(-ENOMEM);\n"218 buf += "//#warning FIXME: Hardcoded nexus depth in " + fabric_mod_name + "_make_nodeacl()\n"219 buf += " nexus_depth = 1;\n"220 buf += " /*\n"221 buf += " * se_nacl_new may be released by core_tpg_add_initiator_node_acl()\n"222 buf += " * when converting a NodeACL from demo mode -> explict\n"223 buf += " */\n"224 buf += " se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,\n"225 buf += " name, nexus_depth);\n"226 buf += " if (IS_ERR(se_nacl)) {\n"227 buf += " " + fabric_mod_name + "_release_fabric_acl(se_tpg, se_nacl_new);\n"228 buf += " return se_nacl;\n"229 buf += " }\n"230 buf += " /*\n"231 buf += " * Locate our struct " + fabric_mod_name + "_nacl and set the FC Nport WWPN\n"232 buf += " */\n"233 buf += " nacl = container_of(se_nacl, struct " + fabric_mod_name + "_nacl, se_node_acl);\n"234 if proto_ident == "FC" or proto_ident == "SAS":235 buf += " nacl->" + fabric_mod_init_port + "_wwpn = wwpn;\n"236 buf += " /* " + fabric_mod_name + "_format_wwn(&nacl->" + fabric_mod_init_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"237 buf += " return se_nacl;\n"238 buf += "}\n\n"239 buf += "static void " + fabric_mod_name + "_drop_nodeacl(struct se_node_acl *se_acl)\n"240 buf += "{\n"241 buf += " struct " + fabric_mod_name + "_nacl *nacl = container_of(se_acl,\n"242 buf += " struct " + fabric_mod_name + "_nacl, se_node_acl);\n"243 buf += " core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1);\n"244 buf += " kfree(nacl);\n"245 buf += "}\n\n"246 buf += "static struct se_portal_group *" + fabric_mod_name + "_make_tpg(\n"247 buf += " struct se_wwn *wwn,\n"248 buf += " struct config_group *group,\n"249 buf += " const char *name)\n"250 buf += "{\n"251 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + "*" + fabric_mod_port + " = container_of(wwn,\n"252 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n\n"253 buf += " struct " + fabric_mod_name + "_tpg *tpg;\n"254 buf += " unsigned long tpgt;\n"255 buf += " int ret;\n\n"256 buf += " if (strstr(name, \"tpgt_\") != name)\n"257 buf += " return ERR_PTR(-EINVAL);\n"258 buf += " if (strict_strtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)\n"259 buf += " return ERR_PTR(-EINVAL);\n\n"260 buf += " tpg = kzalloc(sizeof(struct " + fabric_mod_name + "_tpg), GFP_KERNEL);\n"261 buf += " if (!tpg) {\n"262 buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_tpg\");\n"263 buf += " return ERR_PTR(-ENOMEM);\n"264 buf += " }\n"265 buf += " tpg->" + fabric_mod_port + " = " + fabric_mod_port + ";\n"266 buf += " tpg->" + fabric_mod_port + "_tpgt = tpgt;\n\n"267 buf += " ret = core_tpg_register(&" + fabric_mod_name + "_fabric_configfs->tf_ops, wwn,\n"268 buf += " &tpg->se_tpg, (void *)tpg,\n"269 buf += " TRANSPORT_TPG_TYPE_NORMAL);\n"270 buf += " if (ret < 0) {\n"271 buf += " kfree(tpg);\n"272 buf += " return NULL;\n"273 buf += " }\n"274 buf += " return &tpg->se_tpg;\n"275 buf += "}\n\n"276 buf += "static void " + fabric_mod_name + "_drop_tpg(struct se_portal_group *se_tpg)\n"277 buf += "{\n"278 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"279 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n\n"280 buf += " core_tpg_deregister(se_tpg);\n"281 buf += " kfree(tpg);\n"282 buf += "}\n\n"283 buf += "static struct se_wwn *" + fabric_mod_name + "_make_" + fabric_mod_port + "(\n"284 buf += " struct target_fabric_configfs *tf,\n"285 buf += " struct config_group *group,\n"286 buf += " const char *name)\n"287 buf += "{\n"288 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + ";\n"289 if proto_ident == "FC" or proto_ident == "SAS":290 buf += " u64 wwpn = 0;\n\n"291 buf += " /* if (" + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"292 buf += " return ERR_PTR(-EINVAL); */\n\n"293 buf += " " + fabric_mod_port + " = kzalloc(sizeof(struct " + fabric_mod_name + "_" + fabric_mod_port + "), GFP_KERNEL);\n"294 buf += " if (!" + fabric_mod_port + ") {\n"295 buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_" + fabric_mod_port + "\");\n"296 buf += " return ERR_PTR(-ENOMEM);\n"297 buf += " }\n"298 if proto_ident == "FC" or proto_ident == "SAS":299 buf += " " + fabric_mod_port + "->" + fabric_mod_port + "_wwpn = wwpn;\n"300 buf += " /* " + fabric_mod_name + "_format_wwn(&" + fabric_mod_port + "->" + fabric_mod_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"301 buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_wwn;\n"302 buf += "}\n\n"303 buf += "static void " + fabric_mod_name + "_drop_" + fabric_mod_port + "(struct se_wwn *wwn)\n"304 buf += "{\n"305 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = container_of(wwn,\n"306 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n"307 buf += " kfree(" + fabric_mod_port + ");\n"308 buf += "}\n\n"309 buf += "static ssize_t " + fabric_mod_name + "_wwn_show_attr_version(\n"310 buf += " struct target_fabric_configfs *tf,\n"311 buf += " char *page)\n"312 buf += "{\n"313 buf += " return sprintf(page, \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"314 buf += " \"on \"UTS_RELEASE\"\\n\", " + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"315 buf += " utsname()->machine);\n"316 buf += "}\n\n"317 buf += "TF_WWN_ATTR_RO(" + fabric_mod_name + ", version);\n\n"318 buf += "static struct configfs_attribute *" + fabric_mod_name + "_wwn_attrs[] = {\n"319 buf += " &" + fabric_mod_name + "_wwn_version.attr,\n"320 buf += " NULL,\n"321 buf += "};\n\n"322 buf += "static struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n"323 buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n"324 buf += " .get_fabric_proto_ident = " + fabric_mod_name + "_get_fabric_proto_ident,\n"325 buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n"326 buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n"327 buf += " .tpg_get_default_depth = " + fabric_mod_name + "_get_default_depth,\n"328 buf += " .tpg_get_pr_transport_id = " + fabric_mod_name + "_get_pr_transport_id,\n"329 buf += " .tpg_get_pr_transport_id_len = " + fabric_mod_name + "_get_pr_transport_id_len,\n"330 buf += " .tpg_parse_pr_out_transport_id = " + fabric_mod_name + "_parse_pr_out_transport_id,\n"331 buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n"332 buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n"333 buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n"334 buf += " .tpg_check_prod_mode_write_protect = " + fabric_mod_name + "_check_false,\n"335 buf += " .tpg_alloc_fabric_acl = " + fabric_mod_name + "_alloc_fabric_acl,\n"336 buf += " .tpg_release_fabric_acl = " + fabric_mod_name + "_release_fabric_acl,\n"337 buf += " .tpg_get_inst_index = " + fabric_mod_name + "_tpg_get_inst_index,\n"338 buf += " .release_cmd = " + fabric_mod_name + "_release_cmd,\n"339 buf += " .shutdown_session = " + fabric_mod_name + "_shutdown_session,\n"340 buf += " .close_session = " + fabric_mod_name + "_close_session,\n"341 buf += " .stop_session = " + fabric_mod_name + "_stop_session,\n"342 buf += " .fall_back_to_erl0 = " + fabric_mod_name + "_reset_nexus,\n"343 buf += " .sess_logged_in = " + fabric_mod_name + "_sess_logged_in,\n"344 buf += " .sess_get_index = " + fabric_mod_name + "_sess_get_index,\n"345 buf += " .sess_get_initiator_sid = NULL,\n"346 buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n"347 buf += " .write_pending_status = " + fabric_mod_name + "_write_pending_status,\n"348 buf += " .set_default_node_attributes = " + fabric_mod_name + "_set_default_node_attrs,\n"349 buf += " .get_task_tag = " + fabric_mod_name + "_get_task_tag,\n"350 buf += " .get_cmd_state = " + fabric_mod_name + "_get_cmd_state,\n"351 buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n"352 buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n"353 buf += " .queue_tm_rsp = " + fabric_mod_name + "_queue_tm_rsp,\n"354 buf += " .get_fabric_sense_len = " + fabric_mod_name + "_get_fabric_sense_len,\n"355 buf += " .set_fabric_sense_len = " + fabric_mod_name + "_set_fabric_sense_len,\n"356 buf += " .is_state_remove = " + fabric_mod_name + "_is_state_remove,\n"357 buf += " /*\n"358 buf += " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n"359 buf += " */\n"360 buf += " .fabric_make_wwn = " + fabric_mod_name + "_make_" + fabric_mod_port + ",\n"361 buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n"362 buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n"363 buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n"364 buf += " .fabric_post_link = NULL,\n"365 buf += " .fabric_pre_unlink = NULL,\n"366 buf += " .fabric_make_np = NULL,\n"367 buf += " .fabric_drop_np = NULL,\n"368 buf += " .fabric_make_nodeacl = " + fabric_mod_name + "_make_nodeacl,\n"369 buf += " .fabric_drop_nodeacl = " + fabric_mod_name + "_drop_nodeacl,\n"370 buf += "};\n\n"371 buf += "static int " + fabric_mod_name + "_register_configfs(void)\n"372 buf += "{\n"373 buf += " struct target_fabric_configfs *fabric;\n"374 buf += " int ret;\n\n"375 buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"376 buf += " \" on \"UTS_RELEASE\"\\n\"," + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"377 buf += " utsname()->machine);\n"378 buf += " /*\n"379 buf += " * Register the top level struct config_item_type with TCM core\n"380 buf += " */\n"381 buf += " fabric = target_fabric_configfs_init(THIS_MODULE, \"" + fabric_mod_name[4:] + "\");\n"382 buf += " if (IS_ERR(fabric)) {\n"383 buf += " printk(KERN_ERR \"target_fabric_configfs_init() failed\\n\");\n"384 buf += " return PTR_ERR(fabric);\n"385 buf += " }\n"386 buf += " /*\n"387 buf += " * Setup fabric->tf_ops from our local " + fabric_mod_name + "_ops\n"388 buf += " */\n"389 buf += " fabric->tf_ops = " + fabric_mod_name + "_ops;\n"390 buf += " /*\n"391 buf += " * Setup default attribute lists for various fabric->tf_cit_tmpl\n"392 buf += " */\n"393 buf += " TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = " + fabric_mod_name + "_wwn_attrs;\n"394 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = NULL;\n"395 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = NULL;\n"396 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = NULL;\n"397 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = NULL;\n"398 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs = NULL;\n"399 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;\n"400 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = NULL;\n"401 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_param_cit.ct_attrs = NULL;\n"402 buf += " /*\n"403 buf += " * Register the fabric for use within TCM\n"404 buf += " */\n"405 buf += " ret = target_fabric_configfs_register(fabric);\n"406 buf += " if (ret < 0) {\n"407 buf += " printk(KERN_ERR \"target_fabric_configfs_register() failed\"\n"408 buf += " \" for " + fabric_mod_name.upper() + "\\n\");\n"409 buf += " return ret;\n"410 buf += " }\n"411 buf += " /*\n"412 buf += " * Setup our local pointer to *fabric\n"413 buf += " */\n"414 buf += " " + fabric_mod_name + "_fabric_configfs = fabric;\n"415 buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + "[0] - Set fabric -> " + fabric_mod_name + "_fabric_configfs\\n\");\n"416 buf += " return 0;\n"417 buf += "};\n\n"418 buf += "static void __exit " + fabric_mod_name + "_deregister_configfs(void)\n"419 buf += "{\n"420 buf += " if (!" + fabric_mod_name + "_fabric_configfs)\n"421 buf += " return;\n\n"422 buf += " target_fabric_configfs_deregister(" + fabric_mod_name + "_fabric_configfs);\n"423 buf += " " + fabric_mod_name + "_fabric_configfs = NULL;\n"424 buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + "[0] - Cleared " + fabric_mod_name + "_fabric_configfs\\n\");\n"425 buf += "};\n\n"426 buf += "static int __init " + fabric_mod_name + "_init(void)\n"427 buf += "{\n"428 buf += " int ret;\n\n"429 buf += " ret = " + fabric_mod_name + "_register_configfs();\n"430 buf += " if (ret < 0)\n"431 buf += " return ret;\n\n"432 buf += " return 0;\n"433 buf += "};\n\n"434 buf += "static void __exit " + fabric_mod_name + "_exit(void)\n"435 buf += "{\n"436 buf += " " + fabric_mod_name + "_deregister_configfs();\n"437 buf += "};\n\n"438 buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n"439 buf += "MODULE_LICENSE(\"GPL\");\n"440 buf += "module_init(" + fabric_mod_name + "_init);\n"441 buf += "module_exit(" + fabric_mod_name + "_exit);\n"442 ret = p.write(buf)443 if ret:444 tcm_mod_err("Unable to write f: " + f)445 p.close()446 return447def tcm_mod_scan_fabric_ops(tcm_dir):448 fabric_ops_api = tcm_dir + "include/target/target_core_fabric.h"449 print "Using tcm_mod_scan_fabric_ops: " + fabric_ops_api450 process_fo = 0;451 p = open(fabric_ops_api, 'r')452 line = p.readline()453 while line:454 if process_fo == 0 and re.search('struct target_core_fabric_ops {', line):455 line = p.readline()456 continue457 if process_fo == 0:458 process_fo = 1;459 line = p.readline()460 # Search for function pointer461 if not re.search('\(\*', line):462 continue463 fabric_ops.append(line.rstrip())464 continue465 line = p.readline()466 # Search for function pointer467 if not re.search('\(\*', line):468 continue469 fabric_ops.append(line.rstrip())470 p.close()471 return472def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name):473 buf = ""474 bufi = ""475 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.c"476 print "Writing file: " + f477 p = open(f, 'w')478 if not p:479 tcm_mod_err("Unable to open file: " + f)480 fi = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.h"481 print "Writing file: " + fi482 pi = open(fi, 'w')483 if not pi:484 tcm_mod_err("Unable to open file: " + fi)485 buf = "#include <linux/slab.h>\n"486 buf += "#include <linux/kthread.h>\n"487 buf += "#include <linux/types.h>\n"488 buf += "#include <linux/list.h>\n"489 buf += "#include <linux/types.h>\n"490 buf += "#include <linux/string.h>\n"491 buf += "#include <linux/ctype.h>\n"492 buf += "#include <asm/unaligned.h>\n"493 buf += "#include <scsi/scsi.h>\n"494 buf += "#include <scsi/scsi_host.h>\n"495 buf += "#include <scsi/scsi_device.h>\n"496 buf += "#include <scsi/scsi_cmnd.h>\n"497 buf += "#include <scsi/libfc.h>\n\n"498 buf += "#include <target/target_core_base.h>\n"499 buf += "#include <target/target_core_fabric.h>\n"500 buf += "#include <target/target_core_configfs.h>\n\n"501 buf += "#include \"" + fabric_mod_name + "_base.h\"\n"502 buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"503 buf += "int " + fabric_mod_name + "_check_true(struct se_portal_group *se_tpg)\n"504 buf += "{\n"505 buf += " return 1;\n"506 buf += "}\n\n"507 bufi += "int " + fabric_mod_name + "_check_true(struct se_portal_group *);\n"508 buf += "int " + fabric_mod_name + "_check_false(struct se_portal_group *se_tpg)\n"509 buf += "{\n"510 buf += " return 0;\n"511 buf += "}\n\n"512 bufi += "int " + fabric_mod_name + "_check_false(struct se_portal_group *);\n"513 total_fabric_ops = len(fabric_ops)514 i = 0515 while i < total_fabric_ops:516 fo = fabric_ops[i]517 i += 1518# print "fabric_ops: " + fo519 if re.search('get_fabric_name', fo):520 buf += "char *" + fabric_mod_name + "_get_fabric_name(void)\n"521 buf += "{\n"522 buf += " return \"" + fabric_mod_name[4:] + "\";\n"523 buf += "}\n\n"524 bufi += "char *" + fabric_mod_name + "_get_fabric_name(void);\n"525 continue526 if re.search('get_fabric_proto_ident', fo):527 buf += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *se_tpg)\n"528 buf += "{\n"529 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"530 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"531 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"532 buf += " u8 proto_id;\n\n"533 buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"534 if proto_ident == "FC":535 buf += " case SCSI_PROTOCOL_FCP:\n"536 buf += " default:\n"537 buf += " proto_id = fc_get_fabric_proto_ident(se_tpg);\n"538 buf += " break;\n"539 elif proto_ident == "SAS":540 buf += " case SCSI_PROTOCOL_SAS:\n"541 buf += " default:\n"542 buf += " proto_id = sas_get_fabric_proto_ident(se_tpg);\n"543 buf += " break;\n"544 elif proto_ident == "iSCSI":545 buf += " case SCSI_PROTOCOL_ISCSI:\n"546 buf += " default:\n"547 buf += " proto_id = iscsi_get_fabric_proto_ident(se_tpg);\n"548 buf += " break;\n"549 buf += " }\n\n"550 buf += " return proto_id;\n"551 buf += "}\n\n"552 bufi += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *);\n"553 if re.search('get_wwn', fo):554 buf += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *se_tpg)\n"555 buf += "{\n"556 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"557 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"558 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n\n"559 buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_name[0];\n"560 buf += "}\n\n"561 bufi += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *);\n"562 if re.search('get_tag', fo):563 buf += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *se_tpg)\n"564 buf += "{\n"565 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"566 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"567 buf += " return tpg->" + fabric_mod_port + "_tpgt;\n"568 buf += "}\n\n"569 bufi += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *);\n"570 if re.search('get_default_depth', fo):571 buf += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *se_tpg)\n"572 buf += "{\n"573 buf += " return 1;\n"574 buf += "}\n\n"575 bufi += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *);\n"576 if re.search('get_pr_transport_id\)\(', fo):577 buf += "u32 " + fabric_mod_name + "_get_pr_transport_id(\n"578 buf += " struct se_portal_group *se_tpg,\n"579 buf += " struct se_node_acl *se_nacl,\n"580 buf += " struct t10_pr_registration *pr_reg,\n"581 buf += " int *format_code,\n"582 buf += " unsigned char *buf)\n"583 buf += "{\n"584 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"585 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"586 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"587 buf += " int ret = 0;\n\n"588 buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"589 if proto_ident == "FC":590 buf += " case SCSI_PROTOCOL_FCP:\n"591 buf += " default:\n"592 buf += " ret = fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"593 buf += " format_code, buf);\n"594 buf += " break;\n"595 elif proto_ident == "SAS":596 buf += " case SCSI_PROTOCOL_SAS:\n"597 buf += " default:\n"598 buf += " ret = sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"599 buf += " format_code, buf);\n"600 buf += " break;\n"601 elif proto_ident == "iSCSI":602 buf += " case SCSI_PROTOCOL_ISCSI:\n"603 buf += " default:\n"604 buf += " ret = iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"605 buf += " format_code, buf);\n"606 buf += " break;\n"607 buf += " }\n\n"608 buf += " return ret;\n"609 buf += "}\n\n"610 bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id(struct se_portal_group *,\n"611 bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"612 bufi += " int *, unsigned char *);\n"613 if re.search('get_pr_transport_id_len\)\(', fo):614 buf += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(\n"615 buf += " struct se_portal_group *se_tpg,\n"616 buf += " struct se_node_acl *se_nacl,\n"617 buf += " struct t10_pr_registration *pr_reg,\n"618 buf += " int *format_code)\n"619 buf += "{\n"620 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"621 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"622 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"623 buf += " int ret = 0;\n\n"624 buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"625 if proto_ident == "FC":626 buf += " case SCSI_PROTOCOL_FCP:\n"627 buf += " default:\n"628 buf += " ret = fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"629 buf += " format_code);\n"630 buf += " break;\n"631 elif proto_ident == "SAS":632 buf += " case SCSI_PROTOCOL_SAS:\n"633 buf += " default:\n"634 buf += " ret = sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"635 buf += " format_code);\n"636 buf += " break;\n"637 elif proto_ident == "iSCSI":638 buf += " case SCSI_PROTOCOL_ISCSI:\n"639 buf += " default:\n"640 buf += " ret = iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"641 buf += " format_code);\n"642 buf += " break;\n"643 buf += " }\n\n"644 buf += " return ret;\n"645 buf += "}\n\n"646 bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(struct se_portal_group *,\n"647 bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"648 bufi += " int *);\n"649 if re.search('parse_pr_out_transport_id\)\(', fo):650 buf += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(\n"651 buf += " struct se_portal_group *se_tpg,\n"652 buf += " const char *buf,\n"653 buf += " u32 *out_tid_len,\n"654 buf += " char **port_nexus_ptr)\n"655 buf += "{\n"656 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"657 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"658 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"659 buf += " char *tid = NULL;\n\n"660 buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"661 if proto_ident == "FC":662 buf += " case SCSI_PROTOCOL_FCP:\n"663 buf += " default:\n"664 buf += " tid = fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"665 buf += " port_nexus_ptr);\n"666 elif proto_ident == "SAS":667 buf += " case SCSI_PROTOCOL_SAS:\n"668 buf += " default:\n"669 buf += " tid = sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"670 buf += " port_nexus_ptr);\n"671 elif proto_ident == "iSCSI":672 buf += " case SCSI_PROTOCOL_ISCSI:\n"673 buf += " default:\n"674 buf += " tid = iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"675 buf += " port_nexus_ptr);\n"676 buf += " }\n\n"677 buf += " return tid;\n"678 buf += "}\n\n"679 bufi += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(struct se_portal_group *,\n"680 bufi += " const char *, u32 *, char **);\n"681 if re.search('alloc_fabric_acl\)\(', fo):682 buf += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *se_tpg)\n"683 buf += "{\n"684 buf += " struct " + fabric_mod_name + "_nacl *nacl;\n\n"685 buf += " nacl = kzalloc(sizeof(struct " + fabric_mod_name + "_nacl), GFP_KERNEL);\n"686 buf += " if (!nacl) {\n"687 buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_nacl\\n\");\n"688 buf += " return NULL;\n"689 buf += " }\n\n"690 buf += " return &nacl->se_node_acl;\n"691 buf += "}\n\n"692 bufi += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *);\n"693 if re.search('release_fabric_acl\)\(', fo):694 buf += "void " + fabric_mod_name + "_release_fabric_acl(\n"695 buf += " struct se_portal_group *se_tpg,\n"696 buf += " struct se_node_acl *se_nacl)\n"697 buf += "{\n"698 buf += " struct " + fabric_mod_name + "_nacl *nacl = container_of(se_nacl,\n"699 buf += " struct " + fabric_mod_name + "_nacl, se_node_acl);\n"700 buf += " kfree(nacl);\n"701 buf += "}\n\n"702 bufi += "void " + fabric_mod_name + "_release_fabric_acl(struct se_portal_group *,\n"703 bufi += " struct se_node_acl *);\n"704 if re.search('tpg_get_inst_index\)\(', fo):705 buf += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n"706 buf += "{\n"707 buf += " return 1;\n"708 buf += "}\n\n"709 bufi += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *);\n"710 if re.search('\*release_cmd\)\(', fo):711 buf += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *se_cmd)\n"712 buf += "{\n"713 buf += " return;\n"714 buf += "}\n\n"715 bufi += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *);\n"716 if re.search('shutdown_session\)\(', fo):717 buf += "int " + fabric_mod_name + "_shutdown_session(struct se_session *se_sess)\n"718 buf += "{\n"719 buf += " return 0;\n"720 buf += "}\n\n"721 bufi += "int " + fabric_mod_name + "_shutdown_session(struct se_session *);\n"722 if re.search('close_session\)\(', fo):723 buf += "void " + fabric_mod_name + "_close_session(struct se_session *se_sess)\n"724 buf += "{\n"725 buf += " return;\n"726 buf += "}\n\n"727 bufi += "void " + fabric_mod_name + "_close_session(struct se_session *);\n"728 if re.search('stop_session\)\(', fo):729 buf += "void " + fabric_mod_name + "_stop_session(struct se_session *se_sess, int sess_sleep , int conn_sleep)\n"730 buf += "{\n"731 buf += " return;\n"732 buf += "}\n\n"733 bufi += "void " + fabric_mod_name + "_stop_session(struct se_session *, int, int);\n"734 if re.search('fall_back_to_erl0\)\(', fo):735 buf += "void " + fabric_mod_name + "_reset_nexus(struct se_session *se_sess)\n"736 buf += "{\n"737 buf += " return;\n"738 buf += "}\n\n"739 bufi += "void " + fabric_mod_name + "_reset_nexus(struct se_session *);\n"740 if re.search('sess_logged_in\)\(', fo):741 buf += "int " + fabric_mod_name + "_sess_logged_in(struct se_session *se_sess)\n"742 buf += "{\n"743 buf += " return 0;\n"744 buf += "}\n\n"745 bufi += "int " + fabric_mod_name + "_sess_logged_in(struct se_session *);\n"746 if re.search('sess_get_index\)\(', fo):747 buf += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *se_sess)\n"748 buf += "{\n"749 buf += " return 0;\n"750 buf += "}\n\n"751 bufi += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *);\n"752 if re.search('write_pending\)\(', fo):753 buf += "int " + fabric_mod_name + "_write_pending(struct se_cmd *se_cmd)\n"754 buf += "{\n"755 buf += " return 0;\n"756 buf += "}\n\n"757 bufi += "int " + fabric_mod_name + "_write_pending(struct se_cmd *);\n"758 if re.search('write_pending_status\)\(', fo):759 buf += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *se_cmd)\n"760 buf += "{\n"761 buf += " return 0;\n"762 buf += "}\n\n"763 bufi += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *);\n"764 if re.search('set_default_node_attributes\)\(', fo):765 buf += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *nacl)\n"766 buf += "{\n"767 buf += " return;\n"768 buf += "}\n\n"769 bufi += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *);\n"770 if re.search('get_task_tag\)\(', fo):771 buf += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *se_cmd)\n"772 buf += "{\n"773 buf += " return 0;\n"774 buf += "}\n\n"775 bufi += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *);\n"776 if re.search('get_cmd_state\)\(', fo):777 buf += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *se_cmd)\n"778 buf += "{\n"779 buf += " return 0;\n"780 buf += "}\n\n"781 bufi += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *);\n"782 if re.search('queue_data_in\)\(', fo):783 buf += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *se_cmd)\n"784 buf += "{\n"785 buf += " return 0;\n"786 buf += "}\n\n"787 bufi += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *);\n"788 if re.search('queue_status\)\(', fo):789 buf += "int " + fabric_mod_name + "_queue_status(struct se_cmd *se_cmd)\n"790 buf += "{\n"791 buf += " return 0;\n"792 buf += "}\n\n"793 bufi += "int " + fabric_mod_name + "_queue_status(struct se_cmd *);\n"794 if re.search('queue_tm_rsp\)\(', fo):795 buf += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *se_cmd)\n"796 buf += "{\n"797 buf += " return 0;\n"798 buf += "}\n\n"799 bufi += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *);\n"800 if re.search('get_fabric_sense_len\)\(', fo):801 buf += "u16 " + fabric_mod_name + "_get_fabric_sense_len(void)\n"802 buf += "{\n"803 buf += " return 0;\n"804 buf += "}\n\n"805 bufi += "u16 " + fabric_mod_name + "_get_fabric_sense_len(void);\n"806 if re.search('set_fabric_sense_len\)\(', fo):807 buf += "u16 " + fabric_mod_name + "_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_length)\n"808 buf += "{\n"809 buf += " return 0;\n"810 buf += "}\n\n"811 bufi += "u16 " + fabric_mod_name + "_set_fabric_sense_len(struct se_cmd *, u32);\n"812 if re.search('is_state_remove\)\(', fo):813 buf += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *se_cmd)\n"814 buf += "{\n"815 buf += " return 0;\n"816 buf += "}\n\n"817 bufi += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *);\n"818 ret = p.write(buf)819 if ret:820 tcm_mod_err("Unable to write f: " + f)821 p.close()822 ret = pi.write(bufi)823 if ret:824 tcm_mod_err("Unable to write fi: " + fi)825 pi.close()826 return827def tcm_mod_build_kbuild(fabric_mod_dir_var, fabric_mod_name):828 buf = ""829 f = fabric_mod_dir_var + "/Makefile"830 print "Writing file: " + f831 p = open(f, 'w')832 if not p:833 tcm_mod_err("Unable to open file: " + f)834 buf += fabric_mod_name + "-objs := " + fabric_mod_name + "_fabric.o \\\n"835 buf += " " + fabric_mod_name + "_configfs.o\n"836 buf += "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name + ".o\n"837 ret = p.write(buf)838 if ret:839 tcm_mod_err("Unable to write f: " + f)840 p.close()841 return842def tcm_mod_build_kconfig(fabric_mod_dir_var, fabric_mod_name):843 buf = ""844 f = fabric_mod_dir_var + "/Kconfig"845 print "Writing file: " + f846 p = open(f, 'w')847 if not p:848 tcm_mod_err("Unable to open file: " + f)849 buf = "config " + fabric_mod_name.upper() + "\n"850 buf += " tristate \"" + fabric_mod_name.upper() + " fabric module\"\n"851 buf += " depends on TARGET_CORE && CONFIGFS_FS\n"852 buf += " default n\n"853 buf += " ---help---\n"854 buf += " Say Y here to enable the " + fabric_mod_name.upper() + " fabric module\n"855 ret = p.write(buf)856 if ret:857 tcm_mod_err("Unable to write f: " + f)858 p.close()859 return860def tcm_mod_add_kbuild(tcm_dir, fabric_mod_name):861 buf = "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name.lower() + "/\n"862 kbuild = tcm_dir + "/drivers/target/Makefile"863 f = open(kbuild, 'a')864 f.write(buf)865 f.close()866 return867def tcm_mod_add_kconfig(tcm_dir, fabric_mod_name):868 buf = "source \"drivers/target/" + fabric_mod_name.lower() + "/Kconfig\"\n"869 kconfig = tcm_dir + "/drivers/target/Kconfig"870 f = open(kconfig, 'a')871 f.write(buf)872 f.close()873 return874def main(modname, proto_ident):875# proto_ident = "FC"876# proto_ident = "SAS"877# proto_ident = "iSCSI"878 tcm_dir = os.getcwd();879 tcm_dir += "/../../"880 print "tcm_dir: " + tcm_dir881 fabric_mod_name = modname882 fabric_mod_dir = tcm_dir + "drivers/target/" + fabric_mod_name883 print "Set fabric_mod_name: " + fabric_mod_name884 print "Set fabric_mod_dir: " + fabric_mod_dir885 print "Using proto_ident: " + proto_ident886 if proto_ident != "FC" and proto_ident != "SAS" and proto_ident != "iSCSI":887 print "Unsupported proto_ident: " + proto_ident888 sys.exit(1)889 ret = tcm_mod_create_module_subdir(fabric_mod_dir)890 if ret:891 print "tcm_mod_create_module_subdir() failed because module already exists!"892 sys.exit(1)893 tcm_mod_build_base_includes(proto_ident, fabric_mod_dir, fabric_mod_name)894 tcm_mod_scan_fabric_ops(tcm_dir)895 tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir, fabric_mod_name)896 tcm_mod_build_configfs(proto_ident, fabric_mod_dir, fabric_mod_name)897 tcm_mod_build_kbuild(fabric_mod_dir, fabric_mod_name)898 tcm_mod_build_kconfig(fabric_mod_dir, fabric_mod_name)899 input = raw_input("Would you like to add " + fabric_mod_name + "to drivers/target/Makefile..? [yes,no]: ")900 if input == "yes" or input == "y":901 tcm_mod_add_kbuild(tcm_dir, fabric_mod_name)902 input = raw_input("Would you like to add " + fabric_mod_name + "to drivers/target/Kconfig..? [yes,no]: ")903 if input == "yes" or input == "y":904 tcm_mod_add_kconfig(tcm_dir, fabric_mod_name)905 return906parser = optparse.OptionParser()907parser.add_option('-m', '--modulename', help='Module name', dest='modname',908 action='store', nargs=1, type='string')909parser.add_option('-p', '--protoident', help='Protocol Ident', dest='protoident',910 action='store', nargs=1, type='string')911(opts, args) = parser.parse_args()912mandatories = ['modname', 'protoident']913for m in mandatories:914 if not opts.__dict__[m]:915 print "mandatory option is missing\n"916 parser.print_help()917 exit(-1)918if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Nose automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful