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