How to use mod method in Nose

Best Python code snippet using nose

Run Nose automation tests on LambdaTest cloud grid

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

tcm_mod_builder.py

Source: tcm_mod_builder.py Github

copy
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: [email protected]
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"
233	buf += "#include <target/target_core_fabric.h>\n"
234	buf += "#include <target/target_core_fabric_configfs.h>\n"
235	buf += "#include <target/target_core_configfs.h>\n"
236	buf += "#include <target/configfs_macros.h>\n\n"
237	buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
238	buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
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"
258	buf += "	if (!se_nacl_new)\n"
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"
287	buf += "	core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1);\n"
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"
306	buf += "	if (!tpg) {\n"
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"
342	buf += "	if (!" + fabric_mod_port + ") {\n"
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
350	buf += "	/* " + fabric_mod_name + "_format_wwn(&" + fabric_mod_port + "->" + fabric_mod_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n"
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"
389	buf += "	.release_cmd			= " + fabric_mod_name + "_release_cmd,\n"
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"
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"
405	buf += "	.get_fabric_sense_len		= " + fabric_mod_name + "_get_fabric_sense_len,\n"
406	buf += "	.set_fabric_sense_len		= " + fabric_mod_name + "_set_fabric_sense_len,\n"
407	buf += "	.is_state_remove		= " + fabric_mod_name + "_is_state_remove,\n"
408	buf += "	/*\n"
409	buf += "	 * Setup function pointers for generic logic in target_core_fabric_configfs.c\n"
410	buf += "	 */\n"
411	buf += "	.fabric_make_wwn		= " + fabric_mod_name + "_make_" + fabric_mod_port + ",\n"
412	buf += "	.fabric_drop_wwn		= " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n"
413	buf += "	.fabric_make_tpg		= " + fabric_mod_name + "_make_tpg,\n"
414	buf += "	.fabric_drop_tpg		= " + fabric_mod_name + "_drop_tpg,\n"
415	buf += "	.fabric_post_link		= NULL,\n"
416	buf += "	.fabric_pre_unlink		= NULL,\n"
417	buf += "	.fabric_make_np			= NULL,\n"
418	buf += "	.fabric_drop_np			= NULL,\n"
419	buf += "	.fabric_make_nodeacl		= " + fabric_mod_name + "_make_nodeacl,\n"
420	buf += "	.fabric_drop_nodeacl		= " + fabric_mod_name + "_drop_nodeacl,\n"
421	buf += "};\n\n"
422
423	buf += "static int " + fabric_mod_name + "_register_configfs(void)\n"
424	buf += "{\n"
425	buf += "	struct target_fabric_configfs *fabric;\n"
426	buf += "	int ret;\n\n"
427	buf += "	printk(KERN_INFO \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"
428	buf += "		\" on \"UTS_RELEASE\"\\n\"," + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"
429	buf += "		utsname()->machine);\n"
430	buf += "	/*\n"
431	buf += "	 * Register the top level struct config_item_type with TCM core\n"
432	buf += "	 */\n"
433	buf += "	fabric = target_fabric_configfs_init(THIS_MODULE, \"" + fabric_mod_name[4:] + "\");\n"
434	buf += "	if (IS_ERR(fabric)) {\n"
435	buf += "		printk(KERN_ERR \"target_fabric_configfs_init() failed\\n\");\n"
436	buf += "		return PTR_ERR(fabric);\n"
437	buf += "	}\n"
438	buf += "	/*\n"
439	buf += "	 * Setup fabric->tf_ops from our local " + fabric_mod_name + "_ops\n"
440	buf += "	 */\n"
441	buf += "	fabric->tf_ops = " + fabric_mod_name + "_ops;\n"
442	buf += "	/*\n"
443	buf += "	 * Setup default attribute lists for various fabric->tf_cit_tmpl\n"
444	buf += "	 */\n"
445	buf += "	TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = " + fabric_mod_name + "_wwn_attrs;\n"
446	buf += "	TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = NULL;\n"
447	buf += "	TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = NULL;\n"
448	buf += "	TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = NULL;\n"
449	buf += "	TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = NULL;\n"
450	buf += "	TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs = NULL;\n"
451	buf += "	TF_CIT_TMPL(fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = NULL;\n"
452	buf += "	TF_CIT_TMPL(fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = NULL;\n"
453	buf += "	TF_CIT_TMPL(fabric)->tfc_tpg_nacl_param_cit.ct_attrs = NULL;\n"
454	buf += "	/*\n"
455	buf += "	 * Register the fabric for use within TCM\n"
456	buf += "	 */\n"
457	buf += "	ret = target_fabric_configfs_register(fabric);\n"
458	buf += "	if (ret < 0) {\n"
459	buf += "		printk(KERN_ERR \"target_fabric_configfs_register() failed\"\n"
460	buf += "				\" for " + fabric_mod_name.upper() + "\\n\");\n"
461	buf += "		return ret;\n"
462	buf += "	}\n"
463	buf += "	/*\n"
464	buf += "	 * Setup our local pointer to *fabric\n"
465	buf += "	 */\n"
466	buf += "	" + fabric_mod_name + "_fabric_configfs = fabric;\n"
467	buf += "	printk(KERN_INFO \"" +  fabric_mod_name.upper() + "[0] - Set fabric -> " + fabric_mod_name + "_fabric_configfs\\n\");\n"
468	buf += "	return 0;\n"
469	buf += "};\n\n"
470	buf += "static void __exit " + fabric_mod_name + "_deregister_configfs(void)\n"
471	buf += "{\n"
472	buf += "	if (!" + fabric_mod_name + "_fabric_configfs)\n"
473	buf += "		return;\n\n"
474	buf += "	target_fabric_configfs_deregister(" + fabric_mod_name + "_fabric_configfs);\n"
475	buf += "	" + fabric_mod_name + "_fabric_configfs = NULL;\n"
476	buf += "	printk(KERN_INFO \"" +  fabric_mod_name.upper() + "[0] - Cleared " + fabric_mod_name + "_fabric_configfs\\n\");\n"
477	buf += "};\n\n"
478
479	buf += "static int __init " + fabric_mod_name + "_init(void)\n"
480	buf += "{\n"
481	buf += "	int ret;\n\n"
482	buf += "	ret = " + fabric_mod_name + "_register_configfs();\n"
483	buf += "	if (ret < 0)\n"
484	buf += "		return ret;\n\n"
485	buf += "	return 0;\n"
486	buf += "};\n\n"
487	buf += "static void __exit " + fabric_mod_name + "_exit(void)\n"
488	buf += "{\n"
489	buf += "	" + fabric_mod_name + "_deregister_configfs();\n"
490	buf += "};\n\n"
491
492	buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n"
493	buf += "MODULE_LICENSE(\"GPL\");\n"
494	buf += "module_init(" + fabric_mod_name + "_init);\n"
495	buf += "module_exit(" + fabric_mod_name + "_exit);\n"
496
497	ret = p.write(buf)
498	if ret:
499		tcm_mod_err("Unable to write f: " + f)
500
501	p.close()
502
503	return
504
505def tcm_mod_scan_fabric_ops(tcm_dir):
506
507	fabric_ops_api = tcm_dir + "include/target/target_core_fabric.h"
508
509	print "Using tcm_mod_scan_fabric_ops: " + fabric_ops_api
510	process_fo = 0;
511
512	p = open(fabric_ops_api, 'r')
513
514	line = p.readline()
515	while line:
516		if process_fo == 0 and re.search('struct target_core_fabric_ops {', line):
517			line = p.readline()
518			continue
519
520		if process_fo == 0:
521			process_fo = 1;
522			line = p.readline()
523			# Search for function pointer
524			if not re.search('\(\*', line):
525				continue
526
527			fabric_ops.append(line.rstrip())
528			continue
529
530		line = p.readline()
531		# Search for function pointer
532		if not re.search('\(\*', line):
533			continue
534
535		fabric_ops.append(line.rstrip())
536
537	p.close()
538	return
539
540def tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir_var, fabric_mod_name):
541	buf = ""
542	bufi = ""
543
544	f = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.c"
545	print "Writing file: " + f
546
547	p = open(f, 'w')
548	if not p:
549		tcm_mod_err("Unable to open file: " + f)
550
551	fi = fabric_mod_dir_var + "/" + fabric_mod_name + "_fabric.h"
552	print "Writing file: " + fi
553
554	pi = open(fi, 'w')
555	if not pi:
556		tcm_mod_err("Unable to open file: " + fi)
557
558	buf = "#include <linux/slab.h>\n"
559	buf += "#include <linux/kthread.h>\n"
560	buf += "#include <linux/types.h>\n"
561	buf += "#include <linux/list.h>\n"
562	buf += "#include <linux/types.h>\n"
563	buf += "#include <linux/string.h>\n"
564	buf += "#include <linux/ctype.h>\n"
565	buf += "#include <asm/unaligned.h>\n"
566	buf += "#include <scsi/scsi.h>\n"
567	buf += "#include <scsi/scsi_host.h>\n"
568	buf += "#include <scsi/scsi_device.h>\n"
569	buf += "#include <scsi/scsi_cmnd.h>\n"
570	buf += "#include <scsi/libfc.h>\n\n"
571	buf += "#include <target/target_core_base.h>\n"
572	buf += "#include <target/target_core_fabric.h>\n"
573	buf += "#include <target/target_core_configfs.h>\n\n"
574	buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
575	buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
576
577	buf += "int " + fabric_mod_name + "_check_true(struct se_portal_group *se_tpg)\n"
578	buf += "{\n"
579	buf += "	return 1;\n"
580	buf += "}\n\n"
581	bufi += "int " + fabric_mod_name + "_check_true(struct se_portal_group *);\n"
582
583	buf += "int " + fabric_mod_name + "_check_false(struct se_portal_group *se_tpg)\n"
584	buf += "{\n"
585	buf += "	return 0;\n"
586	buf += "}\n\n"
587	bufi += "int " + fabric_mod_name + "_check_false(struct se_portal_group *);\n"
588
589	total_fabric_ops = len(fabric_ops)
590	i = 0
591
592	while i < total_fabric_ops:
593		fo = fabric_ops[i]
594		i += 1
595#		print "fabric_ops: " + fo
596
597		if re.search('get_fabric_name', fo):
598			buf += "char *" + fabric_mod_name + "_get_fabric_name(void)\n"
599			buf += "{\n"
600			buf += "	return \"" + fabric_mod_name[4:] + "\";\n"
601			buf += "}\n\n"
602			bufi += "char *" + fabric_mod_name + "_get_fabric_name(void);\n"
603			continue
604
605		if re.search('get_fabric_proto_ident', fo):
606			buf += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *se_tpg)\n"
607			buf += "{\n"
608			buf += "	struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
609			buf += "				struct " + fabric_mod_name + "_tpg, se_tpg);\n"
610			buf += "	struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
611			buf += "	u8 proto_id;\n\n"
612			buf += "	switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
613			if proto_ident == "FC":
614				buf += "	case SCSI_PROTOCOL_FCP:\n"
615				buf += "	default:\n"
616				buf += "		proto_id = fc_get_fabric_proto_ident(se_tpg);\n"
617				buf += "		break;\n"
618			elif proto_ident == "SAS":
619				buf += "	case SCSI_PROTOCOL_SAS:\n"
620				buf += "	default:\n"
621				buf += "		proto_id = sas_get_fabric_proto_ident(se_tpg);\n"
622				buf += "		break;\n"
623			elif proto_ident == "iSCSI":
624				buf += "	case SCSI_PROTOCOL_ISCSI:\n"
625				buf += "	default:\n"
626				buf += "		proto_id = iscsi_get_fabric_proto_ident(se_tpg);\n"
627				buf += "		break;\n"
628
629			buf += "	}\n\n"
630			buf += "	return proto_id;\n"
631			buf += "}\n\n"
632			bufi += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *);\n"
633
634		if re.search('get_wwn', fo):
635			buf += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *se_tpg)\n"
636			buf += "{\n"
637			buf += "	struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
638			buf += "				struct " + fabric_mod_name + "_tpg, se_tpg);\n"
639			buf += "	struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n\n"
640			buf += "	return &" + fabric_mod_port + "->" + fabric_mod_port + "_name[0];\n"
641			buf += "}\n\n"
642			bufi += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *);\n"
643
644		if re.search('get_tag', fo):
645			buf += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *se_tpg)\n"
646			buf += "{\n"
647			buf += "	struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
648			buf += "				struct " + fabric_mod_name + "_tpg, se_tpg);\n"
649			buf += "	return tpg->" + fabric_mod_port + "_tpgt;\n"
650			buf += "}\n\n"
651			bufi += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *);\n"
652
653		if re.search('get_default_depth', fo):
654			buf += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *se_tpg)\n"
655			buf += "{\n"
656			buf += "	return 1;\n"
657			buf += "}\n\n"
658			bufi += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *);\n"
659
660		if re.search('get_pr_transport_id\)\(', fo):
661			buf += "u32 " + fabric_mod_name + "_get_pr_transport_id(\n"
662			buf += "	struct se_portal_group *se_tpg,\n"
663			buf += "	struct se_node_acl *se_nacl,\n"
664			buf += "	struct t10_pr_registration *pr_reg,\n"
665			buf += "	int *format_code,\n"
666			buf += "	unsigned char *buf)\n"
667			buf += "{\n"
668			buf += "	struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
669			buf += "				struct " + fabric_mod_name + "_tpg, se_tpg);\n"
670			buf += "	struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
671			buf += "	int ret = 0;\n\n"
672			buf += "	switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
673			if proto_ident == "FC":
674				buf += "	case SCSI_PROTOCOL_FCP:\n"
675				buf += "	default:\n"
676				buf += "		ret = fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
677				buf += "					format_code, buf);\n"
678				buf += "		break;\n"
679			elif proto_ident == "SAS":
680				buf += "	case SCSI_PROTOCOL_SAS:\n"
681				buf += "	default:\n"
682				buf += "		ret = sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
683				buf += "					format_code, buf);\n"
684				buf += "		break;\n"
685			elif proto_ident == "iSCSI":
686				buf += "	case SCSI_PROTOCOL_ISCSI:\n"
687				buf += "	default:\n"
688				buf += "		ret = iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n"
689				buf += "					format_code, buf);\n"
690				buf += "		break;\n"
691
692			buf += "	}\n\n"
693			buf += "	return ret;\n"
694			buf += "}\n\n"
695			bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id(struct se_portal_group *,\n"
696			bufi += "			struct se_node_acl *, struct t10_pr_registration *,\n"
697			bufi += "			int *, unsigned char *);\n"
698
699		if re.search('get_pr_transport_id_len\)\(', fo):
700			buf += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(\n"
701			buf += "	struct se_portal_group *se_tpg,\n"
702			buf += "	struct se_node_acl *se_nacl,\n"
703			buf += "	struct t10_pr_registration *pr_reg,\n"
704			buf += "	int *format_code)\n"
705			buf += "{\n"
706			buf += "	struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
707			buf += "				struct " + fabric_mod_name + "_tpg, se_tpg);\n"
708			buf += "	struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
709			buf += "	int ret = 0;\n\n"
710			buf += "	switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
711			if proto_ident == "FC":
712				buf += "	case SCSI_PROTOCOL_FCP:\n"
713				buf += "	default:\n"
714				buf += "		ret = fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
715				buf += "					format_code);\n"
716				buf += "		break;\n"
717			elif proto_ident == "SAS":
718				buf += "	case SCSI_PROTOCOL_SAS:\n"
719				buf += "	default:\n"
720				buf += "		ret = sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
721				buf += "					format_code);\n"
722				buf += "		break;\n"
723			elif proto_ident == "iSCSI":
724				buf += "	case SCSI_PROTOCOL_ISCSI:\n"
725				buf += "	default:\n"
726				buf += "		ret = iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n"
727				buf += "					format_code);\n"
728				buf += "		break;\n"
729
730
731			buf += "	}\n\n"
732			buf += "	return ret;\n"
733			buf += "}\n\n"
734			bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(struct se_portal_group *,\n"
735			bufi += "			struct se_node_acl *, struct t10_pr_registration *,\n"
736			bufi += "			int *);\n"
737
738		if re.search('parse_pr_out_transport_id\)\(', fo):
739			buf += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(\n"
740			buf += "	struct se_portal_group *se_tpg,\n"
741			buf += "	const char *buf,\n"
742			buf += "	u32 *out_tid_len,\n"
743			buf += "	char **port_nexus_ptr)\n"
744			buf += "{\n"
745			buf += "	struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n"
746			buf += "				struct " + fabric_mod_name + "_tpg, se_tpg);\n"
747			buf += "	struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n"
748			buf += "	char *tid = NULL;\n\n"
749			buf += "	switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n"
750			if proto_ident == "FC":
751				buf += "	case SCSI_PROTOCOL_FCP:\n"
752				buf += "	default:\n"
753				buf += "		tid = fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
754				buf += "					port_nexus_ptr);\n"
755			elif proto_ident == "SAS":
756				buf += "	case SCSI_PROTOCOL_SAS:\n"
757				buf += "	default:\n"
758				buf += "		tid = sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
759				buf += "					port_nexus_ptr);\n"
760			elif proto_ident == "iSCSI":
761				buf += "	case SCSI_PROTOCOL_ISCSI:\n"
762				buf += "	default:\n"
763				buf += "		tid = iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n"
764				buf += "					port_nexus_ptr);\n"
765
766			buf += "	}\n\n"
767			buf += "	return tid;\n"
768			buf += "}\n\n"
769			bufi += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(struct se_portal_group *,\n"
770			bufi +=	"			const char *, u32 *, char **);\n"
771
772		if re.search('alloc_fabric_acl\)\(', fo):
773			buf += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *se_tpg)\n"
774			buf += "{\n"
775			buf += "	struct " + fabric_mod_name + "_nacl *nacl;\n\n"
776			buf += "	nacl = kzalloc(sizeof(struct " + fabric_mod_name + "_nacl), GFP_KERNEL);\n"
777			buf += "	if (!nacl) {\n"
778			buf += "		printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_nacl\\n\");\n"
779			buf += "		return NULL;\n"
780			buf += "	}\n\n"
781			buf += "	return &nacl->se_node_acl;\n"
782			buf += "}\n\n"
783			bufi += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *);\n"
784
785		if re.search('release_fabric_acl\)\(', fo):
786			buf += "void " + fabric_mod_name + "_release_fabric_acl(\n"
787			buf += "	struct se_portal_group *se_tpg,\n"
788			buf += "	struct se_node_acl *se_nacl)\n"
789			buf += "{\n"
790			buf += "	struct " + fabric_mod_name + "_nacl *nacl = container_of(se_nacl,\n"
791			buf += "			struct " + fabric_mod_name + "_nacl, se_node_acl);\n"
792			buf += "	kfree(nacl);\n"
793			buf += "}\n\n"
794			bufi += "void " + fabric_mod_name + "_release_fabric_acl(struct se_portal_group *,\n"
795			bufi +=	"			struct se_node_acl *);\n"
796
797		if re.search('tpg_get_inst_index\)\(', fo):
798			buf += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n"
799			buf += "{\n"
800			buf += "	return 1;\n"
801			buf += "}\n\n"
802			bufi += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *);\n"
803
804		if re.search('\*release_cmd\)\(', fo):
805			buf += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *se_cmd)\n"
806			buf += "{\n"
807			buf += "	return;\n"
808			buf += "}\n\n"
809			bufi += "void " + fabric_mod_name + "_release_cmd(struct se_cmd *);\n"
810
811		if re.search('shutdown_session\)\(', fo):
812			buf += "int " + fabric_mod_name + "_shutdown_session(struct se_session *se_sess)\n"
813			buf += "{\n"
814			buf += "	return 0;\n"
815			buf += "}\n\n"
816			bufi += "int " + fabric_mod_name + "_shutdown_session(struct se_session *);\n"
817
818		if re.search('close_session\)\(', fo):
819			buf += "void " + fabric_mod_name + "_close_session(struct se_session *se_sess)\n"
820			buf += "{\n"
821			buf += "	return;\n"
822			buf += "}\n\n"
823			bufi += "void " + fabric_mod_name + "_close_session(struct se_session *);\n"
824
825		if re.search('stop_session\)\(', fo):
826			buf += "void " + fabric_mod_name + "_stop_session(struct se_session *se_sess, int sess_sleep , int conn_sleep)\n"
827			buf += "{\n"
828			buf += "	return;\n"
829			buf += "}\n\n"
830			bufi += "void " + fabric_mod_name + "_stop_session(struct se_session *, int, int);\n"
831
832		if re.search('fall_back_to_erl0\)\(', fo):
833			buf += "void " + fabric_mod_name + "_reset_nexus(struct se_session *se_sess)\n"
834			buf += "{\n"
835			buf += "	return;\n"
836			buf += "}\n\n"
837			bufi += "void " + fabric_mod_name + "_reset_nexus(struct se_session *);\n"
838
839		if re.search('sess_logged_in\)\(', fo):
840			buf += "int " + fabric_mod_name + "_sess_logged_in(struct se_session *se_sess)\n"
841			buf += "{\n"
842			buf += "	return 0;\n"
843			buf += "}\n\n"
844			bufi += "int " + fabric_mod_name + "_sess_logged_in(struct se_session *);\n"
845
846		if re.search('sess_get_index\)\(', fo):
847			buf += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *se_sess)\n"
848			buf += "{\n"
849			buf += "	return 0;\n"
850			buf += "}\n\n"
851			bufi += "u32 " + fabric_mod_name + "_sess_get_index(struct se_session *);\n"
852
853		if re.search('write_pending\)\(', fo):
854			buf += "int " + fabric_mod_name + "_write_pending(struct se_cmd *se_cmd)\n"
855			buf += "{\n"
856			buf += "	return 0;\n"
857			buf += "}\n\n"
858			bufi += "int " + fabric_mod_name + "_write_pending(struct se_cmd *);\n"
859
860		if re.search('write_pending_status\)\(', fo):
861			buf += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *se_cmd)\n"
862			buf += "{\n"
863			buf += "	return 0;\n"
864			buf += "}\n\n"
865			bufi += "int " + fabric_mod_name + "_write_pending_status(struct se_cmd *);\n"
866
867		if re.search('set_default_node_attributes\)\(', fo):
868			buf += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *nacl)\n"
869			buf += "{\n"
870			buf += "	return;\n"
871			buf += "}\n\n"
872			bufi += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *);\n"
873
874		if re.search('get_task_tag\)\(', fo):
875			buf += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *se_cmd)\n"
876			buf += "{\n"
877			buf += "	return 0;\n"
878			buf += "}\n\n"
879			bufi += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *);\n"
880
881		if re.search('get_cmd_state\)\(', fo):
882			buf += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *se_cmd)\n"
883			buf += "{\n"
884			buf += "	return 0;\n"
885			buf += "}\n\n"
886			bufi += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *);\n"
887
888		if re.search('queue_data_in\)\(', fo):
889			buf += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *se_cmd)\n"
890			buf += "{\n"
891			buf += "	return 0;\n"
892			buf += "}\n\n"
893			bufi += "int " + fabric_mod_name + "_queue_data_in(struct se_cmd *);\n"
894
895		if re.search('queue_status\)\(', fo):
896			buf += "int " + fabric_mod_name + "_queue_status(struct se_cmd *se_cmd)\n"
897			buf += "{\n"
898			buf += "	return 0;\n"
899			buf += "}\n\n"
900			bufi += "int " + fabric_mod_name + "_queue_status(struct se_cmd *);\n"
901
902		if re.search('queue_tm_rsp\)\(', fo):
903			buf += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *se_cmd)\n"
904			buf += "{\n"
905			buf += "	return 0;\n"
906			buf += "}\n\n"
907			bufi += "int " + fabric_mod_name + "_queue_tm_rsp(struct se_cmd *);\n"
908
909		if re.search('get_fabric_sense_len\)\(', fo):
910			buf += "u16 " + fabric_mod_name + "_get_fabric_sense_len(void)\n"
911			buf += "{\n"
912			buf += "	return 0;\n"
913			buf += "}\n\n"
914			bufi += "u16 " + fabric_mod_name + "_get_fabric_sense_len(void);\n"
915
916		if re.search('set_fabric_sense_len\)\(', fo):
917			buf += "u16 " + fabric_mod_name + "_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_length)\n"
918			buf += "{\n"
919			buf += "	return 0;\n"
920			buf += "}\n\n"
921			bufi += "u16 " + fabric_mod_name + "_set_fabric_sense_len(struct se_cmd *, u32);\n"
922
923		if re.search('is_state_remove\)\(', fo):
924			buf += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *se_cmd)\n"
925			buf += "{\n"
926			buf += "	return 0;\n"
927			buf += "}\n\n"
928			bufi += "int " + fabric_mod_name + "_is_state_remove(struct se_cmd *);\n"
929
930
931	ret = p.write(buf)
932	if ret:
933		tcm_mod_err("Unable to write f: " + f)
934
935	p.close()
936
937	ret = pi.write(bufi)
938	if ret:
939		tcm_mod_err("Unable to write fi: " + fi)
940
941	pi.close()
942	return
943
944def tcm_mod_build_kbuild(fabric_mod_dir_var, fabric_mod_name):
945
946	buf = ""
947	f = fabric_mod_dir_var + "/Makefile"
948	print "Writing file: " + f
949
950	p = open(f, 'w')
951	if not p:
952		tcm_mod_err("Unable to open file: " + f)
953
954	buf += fabric_mod_name + "-objs			:= " + fabric_mod_name + "_fabric.o \\\n"
955	buf += "					   " + fabric_mod_name + "_configfs.o\n"
956	buf += "obj-$(CONFIG_" + fabric_mod_name.upper() + ")		+= " + fabric_mod_name + ".o\n"
957
958	ret = p.write(buf)
959	if ret:
960		tcm_mod_err("Unable to write f: " + f)
961
962	p.close()
963	return
964
965def tcm_mod_build_kconfig(fabric_mod_dir_var, fabric_mod_name):
966
967	buf = ""
968	f = fabric_mod_dir_var + "/Kconfig"
969	print "Writing file: " + f
970
971	p = open(f, 'w')
972	if not p:
973		tcm_mod_err("Unable to open file: " + f)
974
975	buf = "config " + fabric_mod_name.upper() + "\n"
976	buf += "	tristate \"" + fabric_mod_name.upper() + " fabric module\"\n"
977	buf += "	depends on TARGET_CORE && CONFIGFS_FS\n"
978	buf += "	default n\n"
979	buf += "	---help---\n"
980	buf += "	Say Y here to enable the " + fabric_mod_name.upper() + " fabric module\n"
981
982	ret = p.write(buf)
983	if ret:
984		tcm_mod_err("Unable to write f: " + f)
985
986	p.close()
987	return
988
989def tcm_mod_add_kbuild(tcm_dir, fabric_mod_name):
990	buf = "obj-$(CONFIG_" + fabric_mod_name.upper() + ")	+= " + fabric_mod_name.lower() + "/\n"
991	kbuild = tcm_dir + "/drivers/target/Makefile"
992
993	f = open(kbuild, 'a')
994	f.write(buf)
995	f.close()
996	return
997
998def tcm_mod_add_kconfig(tcm_dir, fabric_mod_name):
999	buf = "source \"drivers/target/" + fabric_mod_name.lower() + "/Kconfig\"\n"
1000	kconfig = tcm_dir + "/drivers/target/Kconfig"
1001
1002	f = open(kconfig, 'a')
1003	f.write(buf)
1004	f.close()
1005	return
1006
1007def main(modname, proto_ident):
1008#	proto_ident = "FC"
1009#	proto_ident = "SAS"
1010#	proto_ident = "iSCSI"
1011
1012	tcm_dir = os.getcwd();
1013	tcm_dir += "/../../"
1014	print "tcm_dir: " + tcm_dir
1015	fabric_mod_name = modname
1016	fabric_mod_dir = tcm_dir + "drivers/target/" + fabric_mod_name
1017	print "Set fabric_mod_name: " + fabric_mod_name
1018	print "Set fabric_mod_dir: " + fabric_mod_dir
1019	print "Using proto_ident: " + proto_ident
1020
1021	if proto_ident != "FC" and proto_ident != "SAS" and proto_ident != "iSCSI":
1022		print "Unsupported proto_ident: " + proto_ident
1023		sys.exit(1)
1024
1025	ret = tcm_mod_create_module_subdir(fabric_mod_dir)
1026	if ret:
1027		print "tcm_mod_create_module_subdir() failed because module already exists!"
1028		sys.exit(1)
1029
1030	tcm_mod_build_base_includes(proto_ident, fabric_mod_dir, fabric_mod_name)
1031	tcm_mod_scan_fabric_ops(tcm_dir)
1032	tcm_mod_dump_fabric_ops(proto_ident, fabric_mod_dir, fabric_mod_name)
1033	tcm_mod_build_configfs(proto_ident, fabric_mod_dir, fabric_mod_name)
1034	tcm_mod_build_kbuild(fabric_mod_dir, fabric_mod_name)
1035	tcm_mod_build_kconfig(fabric_mod_dir, fabric_mod_name)
1036
1037	input = raw_input("Would you like to add " + fabric_mod_name + "to drivers/target/Makefile..? [yes,no]: ")
1038	if input == "yes" or input == "y":
1039		tcm_mod_add_kbuild(tcm_dir, fabric_mod_name)
1040
1041	input = raw_input("Would you like to add " + fabric_mod_name + "to drivers/target/Kconfig..? [yes,no]: ")
1042	if input == "yes" or input == "y":
1043		tcm_mod_add_kconfig(tcm_dir, fabric_mod_name)
1044
1045	return
1046
1047parser = optparse.OptionParser()
1048parser.add_option('-m', '--modulename', help='Module name', dest='modname',
1049		action='store', nargs=1, type='string')
1050parser.add_option('-p', '--protoident', help='Protocol Ident', dest='protoident',
1051		action='store', nargs=1, type='string')
1052
1053(opts, args) = parser.parse_args()
1054
1055mandatories = ['modname', 'protoident']
1056for m in mandatories:
1057	if not opts.__dict__[m]:
1058		print "mandatory option is missing\n"
1059		parser.print_help()
1060		exit(-1)
1061
1062if __name__ == "__main__":
1063
1064	main(str(opts.modname), opts.protoident)
1065
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run Python Tests on LambdaTest Cloud Grid

Execute automation tests with Nose on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)