]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - Documentation/target/tcm_mod_builder.py
target: Remove unused target_core_fabric_ops.get_fabric_sense_len method
[mirror_ubuntu-artful-kernel.git] / Documentation / target / tcm_mod_builder.py
CommitLineData
c66ac9db
NB
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#
9import os, sys
10import subprocess as sub
11import string
12import re
13import optparse
14
15tcm_dir = ""
16
17fabric_ops = []
18fabric_mod_dir = ""
19fabric_mod_port = ""
20fabric_mod_init_port = ""
21
22def tcm_mod_err(msg):
23 print msg
24 sys.exit(1)
25
26def 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
38def 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
93def 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
146def 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
195def 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
209def 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"
c4795fb2 233 buf += "#include <target/target_core_fabric.h>\n"
c66ac9db 234 buf += "#include <target/target_core_fabric_configfs.h>\n"
c66ac9db 235 buf += "#include <target/target_core_configfs.h>\n"
c66ac9db 236 buf += "#include <target/configfs_macros.h>\n\n"
10635c8b
NB
237 buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
238 buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
c66ac9db
NB
239
240 buf += "/* Local pointer to allocated TCM configfs fabric module */\n"
241 buf += "struct target_fabric_configfs *" + fabric_mod_name + "_fabric_configfs;\n\n"
242
243 buf += "static struct se_node_acl *" + fabric_mod_name + "_make_nodeacl(\n"
244 buf += " struct se_portal_group *se_tpg,\n"
245 buf += " struct config_group *group,\n"
246 buf += " const char *name)\n"
247 buf += "{\n"
248 buf += " struct se_node_acl *se_nacl, *se_nacl_new;\n"
249 buf += " struct " + fabric_mod_name + "_nacl *nacl;\n"
250
251 if proto_ident == "FC" or proto_ident == "SAS":
252 buf += " u64 wwpn = 0;\n"
253
254 buf += " u32 nexus_depth;\n\n"
255 buf += " /* " + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"
256 buf += " return ERR_PTR(-EINVAL); */\n"
257 buf += " se_nacl_new = " + fabric_mod_name + "_alloc_fabric_acl(se_tpg);\n"
ced38c8c 258 buf += " if (!se_nacl_new)\n"
c66ac9db
NB
259 buf += " return ERR_PTR(-ENOMEM);\n"
260 buf += "//#warning FIXME: Hardcoded nexus depth in " + fabric_mod_name + "_make_nodeacl()\n"
261 buf += " nexus_depth = 1;\n"
262 buf += " /*\n"
263 buf += " * se_nacl_new may be released by core_tpg_add_initiator_node_acl()\n"
264 buf += " * when converting a NodeACL from demo mode -> explict\n"
265 buf += " */\n"
266 buf += " se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,\n"
267 buf += " name, nexus_depth);\n"
268 buf += " if (IS_ERR(se_nacl)) {\n"
269 buf += " " + fabric_mod_name + "_release_fabric_acl(se_tpg, se_nacl_new);\n"
270 buf += " return se_nacl;\n"
271 buf += " }\n"
272 buf += " /*\n"
273 buf += " * Locate our struct " + fabric_mod_name + "_nacl and set the FC Nport WWPN\n"
274 buf += " */\n"
275 buf += " nacl = container_of(se_nacl, struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
276
277 if proto_ident == "FC" or proto_ident == "SAS":
278 buf += " nacl->" + fabric_mod_init_port + "_wwpn = wwpn;\n"
279
280 buf += " /* " + fabric_mod_name + "_format_wwn(&nacl->" + fabric_mod_init_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"
281 buf += " return se_nacl;\n"
282 buf += "}\n\n"
283 buf += "static void " + fabric_mod_name + "_drop_nodeacl(struct se_node_acl *se_acl)\n"
284 buf += "{\n"
285 buf += " struct " + fabric_mod_name + "_nacl *nacl = container_of(se_acl,\n"
286 buf += " struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
f45934e0 287 buf += " core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1);\n"
c66ac9db
NB
288 buf += " kfree(nacl);\n"
289 buf += "}\n\n"
290
291 buf += "static struct se_portal_group *" + fabric_mod_name + "_make_tpg(\n"
292 buf += " struct se_wwn *wwn,\n"
293 buf += " struct config_group *group,\n"
294 buf += " const char *name)\n"
295 buf += "{\n"
296 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + "*" + fabric_mod_port + " = container_of(wwn,\n"
297 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n\n"
298 buf += " struct " + fabric_mod_name + "_tpg *tpg;\n"
299 buf += " unsigned long tpgt;\n"
300 buf += " int ret;\n\n"
301 buf += " if (strstr(name, \"tpgt_\") != name)\n"
302 buf += " return ERR_PTR(-EINVAL);\n"
303 buf += " if (strict_strtoul(name + 5, 10, &tpgt) || tpgt > UINT_MAX)\n"
304 buf += " return ERR_PTR(-EINVAL);\n\n"
305 buf += " tpg = kzalloc(sizeof(struct " + fabric_mod_name + "_tpg), GFP_KERNEL);\n"
ced38c8c 306 buf += " if (!tpg) {\n"
c66ac9db
NB
307 buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_tpg\");\n"
308 buf += " return ERR_PTR(-ENOMEM);\n"
309 buf += " }\n"
310 buf += " tpg->" + fabric_mod_port + " = " + fabric_mod_port + ";\n"
311 buf += " tpg->" + fabric_mod_port + "_tpgt = tpgt;\n\n"
312 buf += " ret = core_tpg_register(&" + fabric_mod_name + "_fabric_configfs->tf_ops, wwn,\n"
313 buf += " &tpg->se_tpg, (void *)tpg,\n"
314 buf += " TRANSPORT_TPG_TYPE_NORMAL);\n"
315 buf += " if (ret < 0) {\n"
316 buf += " kfree(tpg);\n"
317 buf += " return NULL;\n"
318 buf += " }\n"
319 buf += " return &tpg->se_tpg;\n"
320 buf += "}\n\n"
321 buf += "static void " + fabric_mod_name + "_drop_tpg(struct se_portal_group *se_tpg)\n"
322 buf += "{\n"
323 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
324 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n\n"
325 buf += " core_tpg_deregister(se_tpg);\n"
326 buf += " kfree(tpg);\n"
327 buf += "}\n\n"
328
329 buf += "static struct se_wwn *" + fabric_mod_name + "_make_" + fabric_mod_port + "(\n"
330 buf += " struct target_fabric_configfs *tf,\n"
331 buf += " struct config_group *group,\n"
332 buf += " const char *name)\n"
333 buf += "{\n"
334 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + ";\n"
335
336 if proto_ident == "FC" or proto_ident == "SAS":
337 buf += " u64 wwpn = 0;\n\n"
338
339 buf += " /* if (" + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n"
340 buf += " return ERR_PTR(-EINVAL); */\n\n"
341 buf += " " + fabric_mod_port + " = kzalloc(sizeof(struct " + fabric_mod_name + "_" + fabric_mod_port + "), GFP_KERNEL);\n"
ced38c8c 342 buf += " if (!" + fabric_mod_port + ") {\n"
c66ac9db
NB
343 buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_" + fabric_mod_port + "\");\n"
344 buf += " return ERR_PTR(-ENOMEM);\n"
345 buf += " }\n"
346
347 if proto_ident == "FC" or proto_ident == "SAS":
348 buf += " " + fabric_mod_port + "->" + fabric_mod_port + "_wwpn = wwpn;\n"
349
ced38c8c 350 buf += " /* " + fabric_mod_name + "_format_wwn(&" + fabric_mod_port + "->" + fabric_mod_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"
c66ac9db
NB
351 buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_wwn;\n"
352 buf += "}\n\n"
353 buf += "static void " + fabric_mod_name + "_drop_" + fabric_mod_port + "(struct se_wwn *wwn)\n"
354 buf += "{\n"
355 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = container_of(wwn,\n"
356 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n"
357 buf += " kfree(" + fabric_mod_port + ");\n"
358 buf += "}\n\n"
359 buf += "static ssize_t " + fabric_mod_name + "_wwn_show_attr_version(\n"
360 buf += " struct target_fabric_configfs *tf,\n"
361 buf += " char *page)\n"
362 buf += "{\n"
363 buf += " return sprintf(page, \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"
364 buf += " \"on \"UTS_RELEASE\"\\n\", " + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"
365 buf += " utsname()->machine);\n"
366 buf += "}\n\n"
367 buf += "TF_WWN_ATTR_RO(" + fabric_mod_name + ", version);\n\n"
368 buf += "static struct configfs_attribute *" + fabric_mod_name + "_wwn_attrs[] = {\n"
369 buf += " &" + fabric_mod_name + "_wwn_version.attr,\n"
370 buf += " NULL,\n"
371 buf += "};\n\n"
372
373 buf += "static struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n"
374 buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n"
375 buf += " .get_fabric_proto_ident = " + fabric_mod_name + "_get_fabric_proto_ident,\n"
376 buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n"
377 buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n"
378 buf += " .tpg_get_default_depth = " + fabric_mod_name + "_get_default_depth,\n"
379 buf += " .tpg_get_pr_transport_id = " + fabric_mod_name + "_get_pr_transport_id,\n"
380 buf += " .tpg_get_pr_transport_id_len = " + fabric_mod_name + "_get_pr_transport_id_len,\n"
381 buf += " .tpg_parse_pr_out_transport_id = " + fabric_mod_name + "_parse_pr_out_transport_id,\n"
382 buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n"
383 buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n"
384 buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n"
385 buf += " .tpg_check_prod_mode_write_protect = " + fabric_mod_name + "_check_false,\n"
386 buf += " .tpg_alloc_fabric_acl = " + fabric_mod_name + "_alloc_fabric_acl,\n"
387 buf += " .tpg_release_fabric_acl = " + fabric_mod_name + "_release_fabric_acl,\n"
388 buf += " .tpg_get_inst_index = " + fabric_mod_name + "_tpg_get_inst_index,\n"
77271de6 389 buf += " .release_cmd = " + fabric_mod_name + "_release_cmd,\n"
c66ac9db
NB
390 buf += " .shutdown_session = " + fabric_mod_name + "_shutdown_session,\n"
391 buf += " .close_session = " + fabric_mod_name + "_close_session,\n"
392 buf += " .stop_session = " + fabric_mod_name + "_stop_session,\n"
393 buf += " .fall_back_to_erl0 = " + fabric_mod_name + "_reset_nexus,\n"
394 buf += " .sess_logged_in = " + fabric_mod_name + "_sess_logged_in,\n"
395 buf += " .sess_get_index = " + fabric_mod_name + "_sess_get_index,\n"
396 buf += " .sess_get_initiator_sid = NULL,\n"
397 buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n"
398 buf += " .write_pending_status = " + fabric_mod_name + "_write_pending_status,\n"
399 buf += " .set_default_node_attributes = " + fabric_mod_name + "_set_default_node_attrs,\n"
400 buf += " .get_task_tag = " + fabric_mod_name + "_get_task_tag,\n"
401 buf += " .get_cmd_state = " + fabric_mod_name + "_get_cmd_state,\n"
c66ac9db
NB
402 buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n"
403 buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n"
404 buf += " .queue_tm_rsp = " + fabric_mod_name + "_queue_tm_rsp,\n"
c66ac9db
NB
405 buf += " .set_fabric_sense_len = " + fabric_mod_name + "_set_fabric_sense_len,\n"
406 buf += " .is_state_remove = " + fabric_mod_name + "_is_state_remove,\n"
c66ac9db
NB
407 buf += " /*\n"
408 buf += " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n"
409 buf += " */\n"
410 buf += " .fabric_make_wwn = " + fabric_mod_name + "_make_" + fabric_mod_port + ",\n"
411 buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n"
412 buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n"
413 buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n"
414 buf += " .fabric_post_link = NULL,\n"
415 buf += " .fabric_pre_unlink = NULL,\n"
416 buf += " .fabric_make_np = NULL,\n"
417 buf += " .fabric_drop_np = NULL,\n"
418 buf += " .fabric_make_nodeacl = " + fabric_mod_name + "_make_nodeacl,\n"
419 buf += " .fabric_drop_nodeacl = " + fabric_mod_name + "_drop_nodeacl,\n"
420 buf += "};\n\n"
421
422 buf += "static int " + fabric_mod_name + "_register_configfs(void)\n"
423 buf += "{\n"
424 buf += " struct target_fabric_configfs *fabric;\n"
425 buf += " int ret;\n\n"
426 buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"
427 buf += " \" on \"UTS_RELEASE\"\\n\"," + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"
428 buf += " utsname()->machine);\n"
429 buf += " /*\n"
430 buf += " * Register the top level struct config_item_type with TCM core\n"
431 buf += " */\n"
432 buf += " fabric = target_fabric_configfs_init(THIS_MODULE, \"" + fabric_mod_name[4:] + "\");\n"
ced38c8c 433 buf += " if (IS_ERR(fabric)) {\n"
c66ac9db 434 buf += " printk(KERN_ERR \"target_fabric_configfs_init() failed\\n\");\n"
ced38c8c 435 buf += " return PTR_ERR(fabric);\n"
c66ac9db
NB
436 buf += " }\n"
437 buf += " /*\n"
438 buf += " * Setup fabric->tf_ops from our local " + fabric_mod_name + "_ops\n"
439 buf += " */\n"
440 buf += " fabric->tf_ops = " + fabric_mod_name + "_ops;\n"
441 buf += " /*\n"
442 buf += " * Setup default attribute lists for various fabric->tf_cit_tmpl\n"
443 buf += " */\n"
444 buf += " TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = " + fabric_mod_name + "_wwn_attrs;\n"
445 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = NULL;\n"
446 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = NULL;\n"
447 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = NULL;\n"
448 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = NULL;\n"
449 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs = NULL;\n"
450 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;\n"
451 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = NULL;\n"
452 buf += " TF_CIT_TMPL(fabric)->tfc_tpg_nacl_param_cit.ct_attrs = NULL;\n"
453 buf += " /*\n"
454 buf += " * Register the fabric for use within TCM\n"
455 buf += " */\n"
456 buf += " ret = target_fabric_configfs_register(fabric);\n"
457 buf += " if (ret < 0) {\n"
458 buf += " printk(KERN_ERR \"target_fabric_configfs_register() failed\"\n"
459 buf += " \" for " + fabric_mod_name.upper() + "\\n\");\n"
460 buf += " return ret;\n"
461 buf += " }\n"
462 buf += " /*\n"
463 buf += " * Setup our local pointer to *fabric\n"
464 buf += " */\n"
465 buf += " " + fabric_mod_name + "_fabric_configfs = fabric;\n"
466 buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + "[0] - Set fabric -> " + fabric_mod_name + "_fabric_configfs\\n\");\n"
467 buf += " return 0;\n"
468 buf += "};\n\n"
ced38c8c 469 buf += "static void __exit " + fabric_mod_name + "_deregister_configfs(void)\n"
c66ac9db 470 buf += "{\n"
ced38c8c 471 buf += " if (!" + fabric_mod_name + "_fabric_configfs)\n"
c66ac9db
NB
472 buf += " return;\n\n"
473 buf += " target_fabric_configfs_deregister(" + fabric_mod_name + "_fabric_configfs);\n"
474 buf += " " + fabric_mod_name + "_fabric_configfs = NULL;\n"
475 buf += " printk(KERN_INFO \"" + fabric_mod_name.upper() + "[0] - Cleared " + fabric_mod_name + "_fabric_configfs\\n\");\n"
476 buf += "};\n\n"
477
478 buf += "static int __init " + fabric_mod_name + "_init(void)\n"
479 buf += "{\n"
480 buf += " int ret;\n\n"
481 buf += " ret = " + fabric_mod_name + "_register_configfs();\n"
482 buf += " if (ret < 0)\n"
483 buf += " return ret;\n\n"
484 buf += " return 0;\n"
485 buf += "};\n\n"
ced38c8c 486 buf += "static void __exit " + fabric_mod_name + "_exit(void)\n"
c66ac9db
NB
487 buf += "{\n"
488 buf += " " + fabric_mod_name + "_deregister_configfs();\n"
489 buf += "};\n\n"
490
c66ac9db
NB
491 buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n"
492 buf += "MODULE_LICENSE(\"GPL\");\n"
493 buf += "module_init(" + fabric_mod_name + "_init);\n"
494 buf += "module_exit(" + fabric_mod_name + "_exit);\n"
c66ac9db
NB
495
496 ret = p.write(buf)
497 if ret:
498 tcm_mod_err("Unable to write f: " + f)
499
500 p.close()
501
502 return
503
504def tcm_mod_scan_fabric_ops(tcm_dir):
505
c4795fb2 506 fabric_ops_api = tcm_dir + "include/target/target_core_fabric.h"
c66ac9db
NB
507
508 print "Using tcm_mod_scan_fabric_ops: " + fabric_ops_api
509 process_fo = 0;
510
511 p = open(fabric_ops_api, 'r')
512
513 line = p.readline()
514 while line:
515 if process_fo == 0 and re.search('struct target_core_fabric_ops {', line):
516 line = p.readline()
517 continue
518
519 if process_fo == 0:
520 process_fo = 1;
521 line = p.readline()
522 # Search for function pointer
523 if not re.search('\(\*', line):
524 continue
525
526 fabric_ops.append(line.rstrip())
527 continue
528
529 line = p.readline()
530 # Search for function pointer
531 if not re.search('\(\*', line):
532 continue
533
534 fabric_ops.append(line.rstrip())
535
536 p.close()
537 return
538
539def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name):
540 buf = ""
541 bufi = ""
542
543 f = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.c"
544 print "Writing file: " + f
545
546 p = open(f, 'w')
547 if not p:
548 tcm_mod_err("Unable to open file: " + f)
549
550 fi = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.h"
551 print "Writing file: " + fi
552
553 pi = open(fi, 'w')
554 if not pi:
555 tcm_mod_err("Unable to open file: " + fi)
556
557 buf = "#include <linux/slab.h>\n"
558 buf += "#include <linux/kthread.h>\n"
559 buf += "#include <linux/types.h>\n"
560 buf += "#include <linux/list.h>\n"
561 buf += "#include <linux/types.h>\n"
562 buf += "#include <linux/string.h>\n"
563 buf += "#include <linux/ctype.h>\n"
564 buf += "#include <asm/unaligned.h>\n"
565 buf += "#include <scsi/scsi.h>\n"
566 buf += "#include <scsi/scsi_host.h>\n"
567 buf += "#include <scsi/scsi_device.h>\n"
568 buf += "#include <scsi/scsi_cmnd.h>\n"
569 buf += "#include <scsi/libfc.h>\n\n"
570 buf += "#include <target/target_core_base.h>\n"
c4795fb2 571 buf += "#include <target/target_core_fabric.h>\n"
10635c8b
NB
572 buf += "#include <target/target_core_configfs.h>\n\n"
573 buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
574 buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
c66ac9db
NB
575
576 buf += "int " + fabric_mod_name + "_check_true(struct se_portal_group *se_tpg)\n"
577 buf += "{\n"
578 buf += " return 1;\n"
579 buf += "}\n\n"
580 bufi += "int " + fabric_mod_name + "_check_true(struct se_portal_group *);\n"
581
582 buf += "int " + fabric_mod_name + "_check_false(struct se_portal_group *se_tpg)\n"
583 buf += "{\n"
584 buf += " return 0;\n"
585 buf += "}\n\n"
586 bufi += "int " + fabric_mod_name + "_check_false(struct se_portal_group *);\n"
587
588 total_fabric_ops = len(fabric_ops)
589 i = 0
590
591 while i < total_fabric_ops:
592 fo = fabric_ops[i]
593 i += 1
594# print "fabric_ops: " + fo
595
596 if re.search('get_fabric_name', fo):
597 buf += "char *" + fabric_mod_name + "_get_fabric_name(void)\n"
598 buf += "{\n"
599 buf += " return \"" + fabric_mod_name[4:] + "\";\n"
600 buf += "}\n\n"
601 bufi += "char *" + fabric_mod_name + "_get_fabric_name(void);\n"
602 continue
603
604 if re.search('get_fabric_proto_ident', fo):
605 buf += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *se_tpg)\n"
606 buf += "{\n"
607 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
608 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
609 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
610 buf += " u8 proto_id;\n\n"
611 buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
612 if proto_ident == "FC":
613 buf += " case SCSI_PROTOCOL_FCP:\n"
614 buf += " default:\n"
615 buf += " proto_id = fc_get_fabric_proto_ident(se_tpg);\n"
616 buf += " break;\n"
617 elif proto_ident == "SAS":
618 buf += " case SCSI_PROTOCOL_SAS:\n"
619 buf += " default:\n"
620 buf += " proto_id = sas_get_fabric_proto_ident(se_tpg);\n"
621 buf += " break;\n"
622 elif proto_ident == "iSCSI":
623 buf += " case SCSI_PROTOCOL_ISCSI:\n"
624 buf += " default:\n"
625 buf += " proto_id = iscsi_get_fabric_proto_ident(se_tpg);\n"
626 buf += " break;\n"
627
628 buf += " }\n\n"
629 buf += " return proto_id;\n"
630 buf += "}\n\n"
631 bufi += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *);\n"
632
633 if re.search('get_wwn', fo):
634 buf += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *se_tpg)\n"
635 buf += "{\n"
636 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
637 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
638 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n\n"
639 buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_name[0];\n"
640 buf += "}\n\n"
641 bufi += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *);\n"
642
643 if re.search('get_tag', fo):
644 buf += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *se_tpg)\n"
645 buf += "{\n"
646 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
647 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
648 buf += " return tpg->" + fabric_mod_port + "_tpgt;\n"
649 buf += "}\n\n"
650 bufi += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *);\n"
651
652 if re.search('get_default_depth', fo):
653 buf += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *se_tpg)\n"
654 buf += "{\n"
655 buf += " return 1;\n"
656 buf += "}\n\n"
657 bufi += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *);\n"
658
659 if re.search('get_pr_transport_id\)\(', fo):
660 buf += "u32 " + fabric_mod_name + "_get_pr_transport_id(\n"
661 buf += " struct se_portal_group *se_tpg,\n"
662 buf += " struct se_node_acl *se_nacl,\n"
663 buf += " struct t10_pr_registration *pr_reg,\n"
664 buf += " int *format_code,\n"
665 buf += " unsigned char *buf)\n"
666 buf += "{\n"
667 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
668 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
669 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
670 buf += " int ret = 0;\n\n"
671 buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
672 if proto_ident == "FC":
673 buf += " case SCSI_PROTOCOL_FCP:\n"
674 buf += " default:\n"
675 buf += " ret = fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
676 buf += " format_code, buf);\n"
677 buf += " break;\n"
678 elif proto_ident == "SAS":
679 buf += " case SCSI_PROTOCOL_SAS:\n"
680 buf += " default:\n"
681 buf += " ret = sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
682 buf += " format_code, buf);\n"
683 buf += " break;\n"
684 elif proto_ident == "iSCSI":
685 buf += " case SCSI_PROTOCOL_ISCSI:\n"
686 buf += " default:\n"
687 buf += " ret = iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
688 buf += " format_code, buf);\n"
689 buf += " break;\n"
690
691 buf += " }\n\n"
692 buf += " return ret;\n"
693 buf += "}\n\n"
694 bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id(struct se_portal_group *,\n"
695 bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"
696 bufi += " int *, unsigned char *);\n"
697
698 if re.search('get_pr_transport_id_len\)\(', fo):
699 buf += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(\n"
700 buf += " struct se_portal_group *se_tpg,\n"
701 buf += " struct se_node_acl *se_nacl,\n"
702 buf += " struct t10_pr_registration *pr_reg,\n"
703 buf += " int *format_code)\n"
704 buf += "{\n"
705 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
706 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
707 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
708 buf += " int ret = 0;\n\n"
709 buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
710 if proto_ident == "FC":
711 buf += " case SCSI_PROTOCOL_FCP:\n"
712 buf += " default:\n"
713 buf += " ret = fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
714 buf += " format_code);\n"
715 buf += " break;\n"
716 elif proto_ident == "SAS":
717 buf += " case SCSI_PROTOCOL_SAS:\n"
718 buf += " default:\n"
719 buf += " ret = sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
720 buf += " format_code);\n"
721 buf += " break;\n"
722 elif proto_ident == "iSCSI":
723 buf += " case SCSI_PROTOCOL_ISCSI:\n"
724 buf += " default:\n"
725 buf += " ret = iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
726 buf += " format_code);\n"
727 buf += " break;\n"
728
729
730 buf += " }\n\n"
731 buf += " return ret;\n"
732 buf += "}\n\n"
733 bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(struct se_portal_group *,\n"
734 bufi += " struct se_node_acl *, struct t10_pr_registration *,\n"
735 bufi += " int *);\n"
736
737 if re.search('parse_pr_out_transport_id\)\(', fo):
738 buf += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(\n"
739 buf += " struct se_portal_group *se_tpg,\n"
740 buf += " const char *buf,\n"
741 buf += " u32 *out_tid_len,\n"
742 buf += " char **port_nexus_ptr)\n"
743 buf += "{\n"
744 buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
745 buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n"
746 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
747 buf += " char *tid = NULL;\n\n"
748 buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
749 if proto_ident == "FC":
750 buf += " case SCSI_PROTOCOL_FCP:\n"
751 buf += " default:\n"
752 buf += " tid = fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
753 buf += " port_nexus_ptr);\n"
754 elif proto_ident == "SAS":
755 buf += " case SCSI_PROTOCOL_SAS:\n"
756 buf += " default:\n"
757 buf += " tid = sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
758 buf += " port_nexus_ptr);\n"
759 elif proto_ident == "iSCSI":
760 buf += " case SCSI_PROTOCOL_ISCSI:\n"
761 buf += " default:\n"
762 buf += " tid = iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
763 buf += " port_nexus_ptr);\n"
764
765 buf += " }\n\n"
766 buf += " return tid;\n"
767 buf += "}\n\n"
768 bufi += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(struct se_portal_group *,\n"
769 bufi += " const char *, u32 *, char **);\n"
770
771 if re.search('alloc_fabric_acl\)\(', fo):
772 buf += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *se_tpg)\n"
773 buf += "{\n"
774 buf += " struct " + fabric_mod_name + "_nacl *nacl;\n\n"
775 buf += " nacl = kzalloc(sizeof(struct " + fabric_mod_name + "_nacl), GFP_KERNEL);\n"
ced38c8c 776 buf += " if (!nacl) {\n"
26725f2a 777 buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_nacl\\n\");\n"
c66ac9db
NB
778 buf += " return NULL;\n"
779 buf += " }\n\n"
780 buf += " return &nacl->se_node_acl;\n"
781 buf += "}\n\n"
782 bufi += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *);\n"
783
784 if re.search('release_fabric_acl\)\(', fo):
785 buf += "void " + fabric_mod_name + "_release_fabric_acl(\n"
786 buf += " struct se_portal_group *se_tpg,\n"
787 buf += " struct se_node_acl *se_nacl)\n"
788 buf += "{\n"
789 buf += " struct " + fabric_mod_name + "_nacl *nacl = container_of(se_nacl,\n"
790 buf += " struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
791 buf += " kfree(nacl);\n"
792 buf += "}\n\n"
793 bufi += "void " + fabric_mod_name + "_release_fabric_acl(struct se_portal_group *,\n"
794 bufi += " struct se_node_acl *);\n"
795
796 if re.search('tpg_get_inst_index\)\(', fo):
797 buf += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n"
798 buf += "{\n"
799 buf += " return 1;\n"
800 buf += "}\n\n"
801 bufi += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *);\n"
802
77271de6 803 if re.search('\*release_cmd\)\(', fo):
c66ac9db
NB
804 buf += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *se_cmd)\n"
805 buf += "{\n"
806 buf += " return;\n"
807 buf += "}\n\n"
808 bufi += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *);\n"
809
810 if re.search('shutdown_session\)\(', fo):
811 buf += "int " + fabric_mod_name + "_shutdown_session(struct se_session *se_sess)\n"
812 buf += "{\n"
813 buf += " return 0;\n"
814 buf += "}\n\n"
815 bufi += "int " + fabric_mod_name + "_shutdown_session(struct se_session *);\n"
816
817 if re.search('close_session\)\(', fo):
818 buf += "void " + fabric_mod_name + "_close_session(struct se_session *se_sess)\n"
819 buf += "{\n"
820 buf += " return;\n"
821 buf += "}\n\n"
822 bufi += "void " + fabric_mod_name + "_close_session(struct se_session *);\n"
823
824 if re.search('stop_session\)\(', fo):
825 buf += "void " + fabric_mod_name + "_stop_session(struct se_session *se_sess, int sess_sleep , int conn_sleep)\n"
826 buf += "{\n"
827 buf += " return;\n"
828 buf += "}\n\n"
829 bufi += "void " + fabric_mod_name + "_stop_session(struct se_session *, int, int);\n"
830
831 if re.search('fall_back_to_erl0\)\(', fo):
832 buf += "void " + fabric_mod_name + "_reset_nexus(struct se_session *se_sess)\n"
833 buf += "{\n"
834 buf += " return;\n"
835 buf += "}\n\n"
836 bufi += "void " + fabric_mod_name + "_reset_nexus(struct se_session *);\n"
837
838 if re.search('sess_logged_in\)\(', fo):
839 buf += "int " + fabric_mod_name + "_sess_logged_in(struct se_session *se_sess)\n"
840 buf += "{\n"
841 buf += " return 0;\n"
842 buf += "}\n\n"
843 bufi += "int " + fabric_mod_name + "_sess_logged_in(struct se_session *);\n"
844
845 if re.search('sess_get_index\)\(', fo):
846 buf += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *se_sess)\n"
847 buf += "{\n"
848 buf += " return 0;\n"
849 buf += "}\n\n"
850 bufi += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *);\n"
851
852 if re.search('write_pending\)\(', fo):
853 buf += "int " + fabric_mod_name + "_write_pending(struct se_cmd *se_cmd)\n"
854 buf += "{\n"
855 buf += " return 0;\n"
856 buf += "}\n\n"
857 bufi += "int " + fabric_mod_name + "_write_pending(struct se_cmd *);\n"
858
859 if re.search('write_pending_status\)\(', fo):
860 buf += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *se_cmd)\n"
861 buf += "{\n"
862 buf += " return 0;\n"
863 buf += "}\n\n"
864 bufi += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *);\n"
865
866 if re.search('set_default_node_attributes\)\(', fo):
867 buf += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *nacl)\n"
868 buf += "{\n"
869 buf += " return;\n"
870 buf += "}\n\n"
871 bufi += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *);\n"
872
873 if re.search('get_task_tag\)\(', fo):
874 buf += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *se_cmd)\n"
875 buf += "{\n"
876 buf += " return 0;\n"
877 buf += "}\n\n"
878 bufi += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *);\n"
879
880 if re.search('get_cmd_state\)\(', fo):
881 buf += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *se_cmd)\n"
882 buf += "{\n"
883 buf += " return 0;\n"
884 buf += "}\n\n"
885 bufi += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *);\n"
886
c66ac9db
NB
887 if re.search('queue_data_in\)\(', fo):
888 buf += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *se_cmd)\n"
889 buf += "{\n"
890 buf += " return 0;\n"
891 buf += "}\n\n"
892 bufi += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *);\n"
893
894 if re.search('queue_status\)\(', fo):
895 buf += "int " + fabric_mod_name + "_queue_status(struct se_cmd *se_cmd)\n"
896 buf += "{\n"
897 buf += " return 0;\n"
898 buf += "}\n\n"
899 bufi += "int " + fabric_mod_name + "_queue_status(struct se_cmd *);\n"
900
901 if re.search('queue_tm_rsp\)\(', fo):
902 buf += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *se_cmd)\n"
903 buf += "{\n"
904 buf += " return 0;\n"
905 buf += "}\n\n"
906 bufi += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *);\n"
907
c66ac9db
NB
908 if re.search('set_fabric_sense_len\)\(', fo):
909 buf += "u16 " + fabric_mod_name + "_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_length)\n"
910 buf += "{\n"
911 buf += " return 0;\n"
912 buf += "}\n\n"
913 bufi += "u16 " + fabric_mod_name + "_set_fabric_sense_len(struct se_cmd *, u32);\n"
914
915 if re.search('is_state_remove\)\(', fo):
916 buf += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *se_cmd)\n"
917 buf += "{\n"
918 buf += " return 0;\n"
919 buf += "}\n\n"
920 bufi += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *);\n"
921
c66ac9db
NB
922
923 ret = p.write(buf)
924 if ret:
925 tcm_mod_err("Unable to write f: " + f)
926
927 p.close()
928
929 ret = pi.write(bufi)
930 if ret:
931 tcm_mod_err("Unable to write fi: " + fi)
932
933 pi.close()
934 return
935
936def tcm_mod_build_kbuild(fabric_mod_dir_var, fabric_mod_name):
937
938 buf = ""
10635c8b 939 f = fabric_mod_dir_var + "/Makefile"
c66ac9db
NB
940 print "Writing file: " + f
941
942 p = open(f, 'w')
943 if not p:
944 tcm_mod_err("Unable to open file: " + f)
945
c66ac9db
NB
946 buf += fabric_mod_name + "-objs := " + fabric_mod_name + "_fabric.o \\\n"
947 buf += " " + fabric_mod_name + "_configfs.o\n"
948 buf += "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name + ".o\n"
949
950 ret = p.write(buf)
951 if ret:
952 tcm_mod_err("Unable to write f: " + f)
953
954 p.close()
955 return
956
957def tcm_mod_build_kconfig(fabric_mod_dir_var, fabric_mod_name):
958
959 buf = ""
960 f = fabric_mod_dir_var + "/Kconfig"
961 print "Writing file: " + f
962
963 p = open(f, 'w')
964 if not p:
965 tcm_mod_err("Unable to open file: " + f)
966
967 buf = "config " + fabric_mod_name.upper() + "\n"
968 buf += " tristate \"" + fabric_mod_name.upper() + " fabric module\"\n"
969 buf += " depends on TARGET_CORE && CONFIGFS_FS\n"
970 buf += " default n\n"
971 buf += " ---help---\n"
972 buf += " Say Y here to enable the " + fabric_mod_name.upper() + " fabric module\n"
973
974 ret = p.write(buf)
975 if ret:
976 tcm_mod_err("Unable to write f: " + f)
977
978 p.close()
979 return
980
981def tcm_mod_add_kbuild(tcm_dir, fabric_mod_name):
982 buf = "obj-$(CONFIG_" + fabric_mod_name.upper() + ") += " + fabric_mod_name.lower() + "/\n"
10635c8b 983 kbuild = tcm_dir + "/drivers/target/Makefile"
c66ac9db
NB
984
985 f = open(kbuild, 'a')
986 f.write(buf)
987 f.close()
988 return
989
990def tcm_mod_add_kconfig(tcm_dir, fabric_mod_name):
991 buf = "source \"drivers/target/" + fabric_mod_name.lower() + "/Kconfig\"\n"
992 kconfig = tcm_dir + "/drivers/target/Kconfig"
993
994 f = open(kconfig, 'a')
995 f.write(buf)
996 f.close()
997 return
998
999def main(modname, proto_ident):
1000# proto_ident = "FC"
1001# proto_ident = "SAS"
1002# proto_ident = "iSCSI"
1003
1004 tcm_dir = os.getcwd();
1005 tcm_dir += "/../../"
1006 print "tcm_dir: " + tcm_dir
1007 fabric_mod_name = modname
1008 fabric_mod_dir = tcm_dir + "drivers/target/" + fabric_mod_name
1009 print "Set fabric_mod_name: " + fabric_mod_name
1010 print "Set fabric_mod_dir: " + fabric_mod_dir
1011 print "Using proto_ident: " + proto_ident
1012
1013 if proto_ident != "FC" and proto_ident != "SAS" and proto_ident != "iSCSI":
1014 print "Unsupported proto_ident: " + proto_ident
1015 sys.exit(1)
1016
1017 ret = tcm_mod_create_module_subdir(fabric_mod_dir)
1018 if ret:
1019 print "tcm_mod_create_module_subdir() failed because module already exists!"
1020 sys.exit(1)
1021
1022 tcm_mod_build_base_includes(proto_ident, fabric_mod_dir, fabric_mod_name)
1023 tcm_mod_scan_fabric_ops(tcm_dir)
1024 tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir, fabric_mod_name)
1025 tcm_mod_build_configfs(proto_ident, fabric_mod_dir, fabric_mod_name)
1026 tcm_mod_build_kbuild(fabric_mod_dir, fabric_mod_name)
1027 tcm_mod_build_kconfig(fabric_mod_dir, fabric_mod_name)
1028
10635c8b 1029 input = raw_input("Would you like to add " + fabric_mod_name + "to drivers/target/Makefile..? [yes,no]: ")
c66ac9db
NB
1030 if input == "yes" or input == "y":
1031 tcm_mod_add_kbuild(tcm_dir, fabric_mod_name)
1032
1033 input = raw_input("Would you like to add " + fabric_mod_name + "to drivers/target/Kconfig..? [yes,no]: ")
1034 if input == "yes" or input == "y":
1035 tcm_mod_add_kconfig(tcm_dir, fabric_mod_name)
1036
1037 return
1038
1039parser = optparse.OptionParser()
1040parser.add_option('-m', '--modulename', help='Module name', dest='modname',
1041 action='store', nargs=1, type='string')
1042parser.add_option('-p', '--protoident', help='Protocol Ident', dest='protoident',
1043 action='store', nargs=1, type='string')
1044
1045(opts, args) = parser.parse_args()
1046
1047mandatories = ['modname', 'protoident']
1048for m in mandatories:
1049 if not opts.__dict__[m]:
1050 print "mandatory option is missing\n"
1051 parser.print_help()
1052 exit(-1)
1053
1054if __name__ == "__main__":
1055
1056 main(str(opts.modname), opts.protoident)