1 /*******************************************************************************
2 * Filename: target_core_fabric_configfs.c
3  *
4  * This file contains generic fabric module configfs infrastructure for
5  * TCM v4.x code
6  *
7  * (c) Copyright 2010-2013 Datera, Inc.
8  *
9  * Nicholas A. Bellinger <nab@linux-iscsi.org>
10 *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  ****************************************************************************/
21 
22 #include <linux/module.h>
23 #include <linux/moduleparam.h>
24 #include <linux/utsname.h>
25 #include <linux/init.h>
26 #include <linux/fs.h>
27 #include <linux/namei.h>
28 #include <linux/slab.h>
29 #include <linux/types.h>
30 #include <linux/delay.h>
31 #include <linux/unistd.h>
32 #include <linux/string.h>
33 #include <linux/syscalls.h>
34 #include <linux/configfs.h>
35 
36 #include <target/target_core_base.h>
37 #include <target/target_core_fabric.h>
38 #include <target/target_core_fabric_configfs.h>
39 #include <target/target_core_configfs.h>
40 #include <target/configfs_macros.h>
41 
42 #include "target_core_internal.h"
43 #include "target_core_alua.h"
44 #include "target_core_pr.h"
45 
46 #define TF_CIT_SETUP(_name, _item_ops, _group_ops, _attrs)		\
47 static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \
48 {									\
49 	struct config_item_type *cit = &tf->tf_##_name##_cit;		\
50 									\
51 	cit->ct_item_ops = _item_ops;					\
52 	cit->ct_group_ops = _group_ops;					\
53 	cit->ct_attrs = _attrs;						\
54 	cit->ct_owner = tf->tf_ops->module;				\
55 	pr_debug("Setup generic %s\n", __stringify(_name));		\
56 }
57 
58 #define TF_CIT_SETUP_DRV(_name, _item_ops, _group_ops)		\
59 static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \
60 {									\
61 	struct config_item_type *cit = &tf->tf_##_name##_cit;		\
62 	struct configfs_attribute **attrs = tf->tf_ops->tfc_##_name##_attrs; \
63 									\
64 	cit->ct_item_ops = _item_ops;					\
65 	cit->ct_group_ops = _group_ops;					\
66 	cit->ct_attrs = attrs;						\
67 	cit->ct_owner = tf->tf_ops->module;				\
68 	pr_debug("Setup generic %s\n", __stringify(_name));		\
69 }
70 
71 /* Start of tfc_tpg_mappedlun_cit */
72 
73 static int target_fabric_mappedlun_link(
74 	struct config_item *lun_acl_ci,
75 	struct config_item *lun_ci)
76 {
77 	struct se_dev_entry *deve;
78 	struct se_lun *lun = container_of(to_config_group(lun_ci),
79 			struct se_lun, lun_group);
80 	struct se_lun_acl *lacl = container_of(to_config_group(lun_acl_ci),
81 			struct se_lun_acl, se_lun_group);
82 	struct se_portal_group *se_tpg;
83 	struct config_item *nacl_ci, *tpg_ci, *tpg_ci_s, *wwn_ci, *wwn_ci_s;
84 	int lun_access;
85 
86 	if (lun->lun_link_magic != SE_LUN_LINK_MAGIC) {
87 		pr_err("Bad lun->lun_link_magic, not a valid lun_ci pointer:"
88 			" %p to struct lun: %p\n", lun_ci, lun);
89 		return -EFAULT;
90 	}
91 	/*
92 	 * Ensure that the source port exists
93 	 */
94 	if (!lun->lun_se_dev) {
95 		pr_err("Source se_lun->lun_se_dev does not exist\n");
96 		return -EINVAL;
97 	}
98 	se_tpg = lun->lun_tpg;
99 
100 	nacl_ci = &lun_acl_ci->ci_parent->ci_group->cg_item;
101 	tpg_ci = &nacl_ci->ci_group->cg_item;
102 	wwn_ci = &tpg_ci->ci_group->cg_item;
103 	tpg_ci_s = &lun_ci->ci_parent->ci_group->cg_item;
104 	wwn_ci_s = &tpg_ci_s->ci_group->cg_item;
105 	/*
106 	 * Make sure the SymLink is going to the same $FABRIC/$WWN/tpgt_$TPGT
107 	 */
108 	if (strcmp(config_item_name(wwn_ci), config_item_name(wwn_ci_s))) {
109 		pr_err("Illegal Initiator ACL SymLink outside of %s\n",
110 			config_item_name(wwn_ci));
111 		return -EINVAL;
112 	}
113 	if (strcmp(config_item_name(tpg_ci), config_item_name(tpg_ci_s))) {
114 		pr_err("Illegal Initiator ACL Symlink outside of %s"
115 			" TPGT: %s\n", config_item_name(wwn_ci),
116 			config_item_name(tpg_ci));
117 		return -EINVAL;
118 	}
119 	/*
120 	 * If this struct se_node_acl was dynamically generated with
121 	 * tpg_1/attrib/generate_node_acls=1, use the existing deve->lun_flags,
122 	 * which be will write protected (READ-ONLY) when
123 	 * tpg_1/attrib/demo_mode_write_protect=1
124 	 */
125 	rcu_read_lock();
126 	deve = target_nacl_find_deve(lacl->se_lun_nacl, lacl->mapped_lun);
127 	if (deve)
128 		lun_access = deve->lun_flags;
129 	else
130 		lun_access =
131 			(se_tpg->se_tpg_tfo->tpg_check_prod_mode_write_protect(
132 				se_tpg)) ? TRANSPORT_LUNFLAGS_READ_ONLY :
133 					   TRANSPORT_LUNFLAGS_READ_WRITE;
134 	rcu_read_unlock();
135 	/*
136 	 * Determine the actual mapped LUN value user wants..
137 	 *
138 	 * This value is what the SCSI Initiator actually sees the
139 	 * $FABRIC/$WWPN/$TPGT/lun/lun_* as on their SCSI Initiator Ports.
140 	 */
141 	return core_dev_add_initiator_node_lun_acl(se_tpg, lacl, lun, lun_access);
142 }
143 
144 static int target_fabric_mappedlun_unlink(
145 	struct config_item *lun_acl_ci,
146 	struct config_item *lun_ci)
147 {
148 	struct se_lun_acl *lacl = container_of(to_config_group(lun_acl_ci),
149 			struct se_lun_acl, se_lun_group);
150 	struct se_lun *lun = container_of(to_config_group(lun_ci),
151 			struct se_lun, lun_group);
152 
153 	return core_dev_del_initiator_node_lun_acl(lun, lacl);
154 }
155 
156 CONFIGFS_EATTR_STRUCT(target_fabric_mappedlun, se_lun_acl);
157 #define TCM_MAPPEDLUN_ATTR(_name, _mode)				\
158 static struct target_fabric_mappedlun_attribute target_fabric_mappedlun_##_name = \
159 	__CONFIGFS_EATTR(_name, _mode,					\
160 	target_fabric_mappedlun_show_##_name,				\
161 	target_fabric_mappedlun_store_##_name);
162 
163 static ssize_t target_fabric_mappedlun_show_write_protect(
164 	struct se_lun_acl *lacl,
165 	char *page)
166 {
167 	struct se_node_acl *se_nacl = lacl->se_lun_nacl;
168 	struct se_dev_entry *deve;
169 	ssize_t len = 0;
170 
171 	rcu_read_lock();
172 	deve = target_nacl_find_deve(se_nacl, lacl->mapped_lun);
173 	if (deve) {
174 		len = sprintf(page, "%d\n",
175 			(deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY) ? 1 : 0);
176 	}
177 	rcu_read_unlock();
178 
179 	return len;
180 }
181 
182 static ssize_t target_fabric_mappedlun_store_write_protect(
183 	struct se_lun_acl *lacl,
184 	const char *page,
185 	size_t count)
186 {
187 	struct se_node_acl *se_nacl = lacl->se_lun_nacl;
188 	struct se_portal_group *se_tpg = se_nacl->se_tpg;
189 	unsigned long op;
190 	int ret;
191 
192 	ret = kstrtoul(page, 0, &op);
193 	if (ret)
194 		return ret;
195 
196 	if ((op != 1) && (op != 0))
197 		return -EINVAL;
198 
199 	core_update_device_list_access(lacl->mapped_lun, (op) ?
200 			TRANSPORT_LUNFLAGS_READ_ONLY :
201 			TRANSPORT_LUNFLAGS_READ_WRITE,
202 			lacl->se_lun_nacl);
203 
204 	pr_debug("%s_ConfigFS: Changed Initiator ACL: %s"
205 		" Mapped LUN: %llu Write Protect bit to %s\n",
206 		se_tpg->se_tpg_tfo->get_fabric_name(),
207 		lacl->initiatorname, lacl->mapped_lun, (op) ? "ON" : "OFF");
208 
209 	return count;
210 
211 }
212 
213 TCM_MAPPEDLUN_ATTR(write_protect, S_IRUGO | S_IWUSR);
214 
215 CONFIGFS_EATTR_OPS(target_fabric_mappedlun, se_lun_acl, se_lun_group);
216 
217 static void target_fabric_mappedlun_release(struct config_item *item)
218 {
219 	struct se_lun_acl *lacl = container_of(to_config_group(item),
220 				struct se_lun_acl, se_lun_group);
221 	struct se_portal_group *se_tpg = lacl->se_lun_nacl->se_tpg;
222 
223 	core_dev_free_initiator_node_lun_acl(se_tpg, lacl);
224 }
225 
226 static struct configfs_attribute *target_fabric_mappedlun_attrs[] = {
227 	&target_fabric_mappedlun_write_protect.attr,
228 	NULL,
229 };
230 
231 static struct configfs_item_operations target_fabric_mappedlun_item_ops = {
232 	.release		= target_fabric_mappedlun_release,
233 	.show_attribute		= target_fabric_mappedlun_attr_show,
234 	.store_attribute	= target_fabric_mappedlun_attr_store,
235 	.allow_link		= target_fabric_mappedlun_link,
236 	.drop_link		= target_fabric_mappedlun_unlink,
237 };
238 
239 TF_CIT_SETUP(tpg_mappedlun, &target_fabric_mappedlun_item_ops, NULL,
240 		target_fabric_mappedlun_attrs);
241 
242 /* End of tfc_tpg_mappedlun_cit */
243 
244 /* Start of tfc_tpg_mappedlun_port_cit */
245 
246 static struct config_group *target_core_mappedlun_stat_mkdir(
247 	struct config_group *group,
248 	const char *name)
249 {
250 	return ERR_PTR(-ENOSYS);
251 }
252 
253 static void target_core_mappedlun_stat_rmdir(
254 	struct config_group *group,
255 	struct config_item *item)
256 {
257 	return;
258 }
259 
260 static struct configfs_group_operations target_fabric_mappedlun_stat_group_ops = {
261 	.make_group		= target_core_mappedlun_stat_mkdir,
262 	.drop_item		= target_core_mappedlun_stat_rmdir,
263 };
264 
265 TF_CIT_SETUP(tpg_mappedlun_stat, NULL, &target_fabric_mappedlun_stat_group_ops,
266 		NULL);
267 
268 /* End of tfc_tpg_mappedlun_port_cit */
269 
270 /* Start of tfc_tpg_nacl_attrib_cit */
271 
272 CONFIGFS_EATTR_OPS(target_fabric_nacl_attrib, se_node_acl, acl_attrib_group);
273 
274 static struct configfs_item_operations target_fabric_nacl_attrib_item_ops = {
275 	.show_attribute		= target_fabric_nacl_attrib_attr_show,
276 	.store_attribute	= target_fabric_nacl_attrib_attr_store,
277 };
278 
279 TF_CIT_SETUP_DRV(tpg_nacl_attrib, &target_fabric_nacl_attrib_item_ops, NULL);
280 
281 /* End of tfc_tpg_nacl_attrib_cit */
282 
283 /* Start of tfc_tpg_nacl_auth_cit */
284 
285 CONFIGFS_EATTR_OPS(target_fabric_nacl_auth, se_node_acl, acl_auth_group);
286 
287 static struct configfs_item_operations target_fabric_nacl_auth_item_ops = {
288 	.show_attribute		= target_fabric_nacl_auth_attr_show,
289 	.store_attribute	= target_fabric_nacl_auth_attr_store,
290 };
291 
292 TF_CIT_SETUP_DRV(tpg_nacl_auth, &target_fabric_nacl_auth_item_ops, NULL);
293 
294 /* End of tfc_tpg_nacl_auth_cit */
295 
296 /* Start of tfc_tpg_nacl_param_cit */
297 
298 CONFIGFS_EATTR_OPS(target_fabric_nacl_param, se_node_acl, acl_param_group);
299 
300 static struct configfs_item_operations target_fabric_nacl_param_item_ops = {
301 	.show_attribute		= target_fabric_nacl_param_attr_show,
302 	.store_attribute	= target_fabric_nacl_param_attr_store,
303 };
304 
305 TF_CIT_SETUP_DRV(tpg_nacl_param, &target_fabric_nacl_param_item_ops, NULL);
306 
307 /* End of tfc_tpg_nacl_param_cit */
308 
309 /* Start of tfc_tpg_nacl_base_cit */
310 
311 CONFIGFS_EATTR_OPS(target_fabric_nacl_base, se_node_acl, acl_group);
312 
313 static struct config_group *target_fabric_make_mappedlun(
314 	struct config_group *group,
315 	const char *name)
316 {
317 	struct se_node_acl *se_nacl = container_of(group,
318 			struct se_node_acl, acl_group);
319 	struct se_portal_group *se_tpg = se_nacl->se_tpg;
320 	struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
321 	struct se_lun_acl *lacl = NULL;
322 	struct config_item *acl_ci;
323 	struct config_group *lacl_cg = NULL, *ml_stat_grp = NULL;
324 	char *buf;
325 	unsigned long long mapped_lun;
326 	int ret = 0;
327 
328 	acl_ci = &group->cg_item;
329 	if (!acl_ci) {
330 		pr_err("Unable to locatel acl_ci\n");
331 		return NULL;
332 	}
333 
334 	buf = kzalloc(strlen(name) + 1, GFP_KERNEL);
335 	if (!buf) {
336 		pr_err("Unable to allocate memory for name buf\n");
337 		return ERR_PTR(-ENOMEM);
338 	}
339 	snprintf(buf, strlen(name) + 1, "%s", name);
340 	/*
341 	 * Make sure user is creating iscsi/$IQN/$TPGT/acls/$INITIATOR/lun_$ID.
342 	 */
343 	if (strstr(buf, "lun_") != buf) {
344 		pr_err("Unable to locate \"lun_\" from buf: %s"
345 			" name: %s\n", buf, name);
346 		ret = -EINVAL;
347 		goto out;
348 	}
349 	/*
350 	 * Determine the Mapped LUN value.  This is what the SCSI Initiator
351 	 * Port will actually see.
352 	 */
353 	ret = kstrtoull(buf + 4, 0, &mapped_lun);
354 	if (ret)
355 		goto out;
356 
357 	lacl = core_dev_init_initiator_node_lun_acl(se_tpg, se_nacl,
358 			mapped_lun, &ret);
359 	if (!lacl) {
360 		ret = -EINVAL;
361 		goto out;
362 	}
363 
364 	lacl_cg = &lacl->se_lun_group;
365 	lacl_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2,
366 				GFP_KERNEL);
367 	if (!lacl_cg->default_groups) {
368 		pr_err("Unable to allocate lacl_cg->default_groups\n");
369 		ret = -ENOMEM;
370 		goto out;
371 	}
372 
373 	config_group_init_type_name(&lacl->se_lun_group, name,
374 			&tf->tf_tpg_mappedlun_cit);
375 	config_group_init_type_name(&lacl->ml_stat_grps.stat_group,
376 			"statistics", &tf->tf_tpg_mappedlun_stat_cit);
377 	lacl_cg->default_groups[0] = &lacl->ml_stat_grps.stat_group;
378 	lacl_cg->default_groups[1] = NULL;
379 
380 	ml_stat_grp = &lacl->ml_stat_grps.stat_group;
381 	ml_stat_grp->default_groups = kmalloc(sizeof(struct config_group *) * 3,
382 				GFP_KERNEL);
383 	if (!ml_stat_grp->default_groups) {
384 		pr_err("Unable to allocate ml_stat_grp->default_groups\n");
385 		ret = -ENOMEM;
386 		goto out;
387 	}
388 	target_stat_setup_mappedlun_default_groups(lacl);
389 
390 	kfree(buf);
391 	return &lacl->se_lun_group;
392 out:
393 	if (lacl_cg)
394 		kfree(lacl_cg->default_groups);
395 	kfree(lacl);
396 	kfree(buf);
397 	return ERR_PTR(ret);
398 }
399 
400 static void target_fabric_drop_mappedlun(
401 	struct config_group *group,
402 	struct config_item *item)
403 {
404 	struct se_lun_acl *lacl = container_of(to_config_group(item),
405 			struct se_lun_acl, se_lun_group);
406 	struct config_item *df_item;
407 	struct config_group *lacl_cg = NULL, *ml_stat_grp = NULL;
408 	int i;
409 
410 	ml_stat_grp = &lacl->ml_stat_grps.stat_group;
411 	for (i = 0; ml_stat_grp->default_groups[i]; i++) {
412 		df_item = &ml_stat_grp->default_groups[i]->cg_item;
413 		ml_stat_grp->default_groups[i] = NULL;
414 		config_item_put(df_item);
415 	}
416 	kfree(ml_stat_grp->default_groups);
417 
418 	lacl_cg = &lacl->se_lun_group;
419 	for (i = 0; lacl_cg->default_groups[i]; i++) {
420 		df_item = &lacl_cg->default_groups[i]->cg_item;
421 		lacl_cg->default_groups[i] = NULL;
422 		config_item_put(df_item);
423 	}
424 	kfree(lacl_cg->default_groups);
425 
426 	config_item_put(item);
427 }
428 
429 static void target_fabric_nacl_base_release(struct config_item *item)
430 {
431 	struct se_node_acl *se_nacl = container_of(to_config_group(item),
432 			struct se_node_acl, acl_group);
433 	struct target_fabric_configfs *tf = se_nacl->se_tpg->se_tpg_wwn->wwn_tf;
434 
435 	if (tf->tf_ops->fabric_cleanup_nodeacl)
436 		tf->tf_ops->fabric_cleanup_nodeacl(se_nacl);
437 	core_tpg_del_initiator_node_acl(se_nacl);
438 }
439 
440 static struct configfs_item_operations target_fabric_nacl_base_item_ops = {
441 	.release		= target_fabric_nacl_base_release,
442 	.show_attribute		= target_fabric_nacl_base_attr_show,
443 	.store_attribute	= target_fabric_nacl_base_attr_store,
444 };
445 
446 static struct configfs_group_operations target_fabric_nacl_base_group_ops = {
447 	.make_group		= target_fabric_make_mappedlun,
448 	.drop_item		= target_fabric_drop_mappedlun,
449 };
450 
451 TF_CIT_SETUP_DRV(tpg_nacl_base, &target_fabric_nacl_base_item_ops,
452 		&target_fabric_nacl_base_group_ops);
453 
454 /* End of tfc_tpg_nacl_base_cit */
455 
456 /* Start of tfc_node_fabric_stats_cit */
457 /*
458  * This is used as a placeholder for struct se_node_acl->acl_fabric_stat_group
459  * to allow fabrics access to ->acl_fabric_stat_group->default_groups[]
460  */
461 TF_CIT_SETUP(tpg_nacl_stat, NULL, NULL, NULL);
462 
463 /* End of tfc_wwn_fabric_stats_cit */
464 
465 /* Start of tfc_tpg_nacl_cit */
466 
467 static struct config_group *target_fabric_make_nodeacl(
468 	struct config_group *group,
469 	const char *name)
470 {
471 	struct se_portal_group *se_tpg = container_of(group,
472 			struct se_portal_group, tpg_acl_group);
473 	struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
474 	struct se_node_acl *se_nacl;
475 	struct config_group *nacl_cg;
476 
477 	se_nacl = core_tpg_add_initiator_node_acl(se_tpg, name);
478 	if (IS_ERR(se_nacl))
479 		return ERR_CAST(se_nacl);
480 
481 	if (tf->tf_ops->fabric_init_nodeacl) {
482 		int ret = tf->tf_ops->fabric_init_nodeacl(se_nacl, name);
483 		if (ret) {
484 			core_tpg_del_initiator_node_acl(se_nacl);
485 			return ERR_PTR(ret);
486 		}
487 	}
488 
489 	nacl_cg = &se_nacl->acl_group;
490 	nacl_cg->default_groups = se_nacl->acl_default_groups;
491 	nacl_cg->default_groups[0] = &se_nacl->acl_attrib_group;
492 	nacl_cg->default_groups[1] = &se_nacl->acl_auth_group;
493 	nacl_cg->default_groups[2] = &se_nacl->acl_param_group;
494 	nacl_cg->default_groups[3] = &se_nacl->acl_fabric_stat_group;
495 	nacl_cg->default_groups[4] = NULL;
496 
497 	config_group_init_type_name(&se_nacl->acl_group, name,
498 			&tf->tf_tpg_nacl_base_cit);
499 	config_group_init_type_name(&se_nacl->acl_attrib_group, "attrib",
500 			&tf->tf_tpg_nacl_attrib_cit);
501 	config_group_init_type_name(&se_nacl->acl_auth_group, "auth",
502 			&tf->tf_tpg_nacl_auth_cit);
503 	config_group_init_type_name(&se_nacl->acl_param_group, "param",
504 			&tf->tf_tpg_nacl_param_cit);
505 	config_group_init_type_name(&se_nacl->acl_fabric_stat_group,
506 			"fabric_statistics", &tf->tf_tpg_nacl_stat_cit);
507 
508 	return &se_nacl->acl_group;
509 }
510 
511 static void target_fabric_drop_nodeacl(
512 	struct config_group *group,
513 	struct config_item *item)
514 {
515 	struct se_node_acl *se_nacl = container_of(to_config_group(item),
516 			struct se_node_acl, acl_group);
517 	struct config_item *df_item;
518 	struct config_group *nacl_cg;
519 	int i;
520 
521 	nacl_cg = &se_nacl->acl_group;
522 	for (i = 0; nacl_cg->default_groups[i]; i++) {
523 		df_item = &nacl_cg->default_groups[i]->cg_item;
524 		nacl_cg->default_groups[i] = NULL;
525 		config_item_put(df_item);
526 	}
527 	/*
528 	 * struct se_node_acl free is done in target_fabric_nacl_base_release()
529 	 */
530 	config_item_put(item);
531 }
532 
533 static struct configfs_group_operations target_fabric_nacl_group_ops = {
534 	.make_group	= target_fabric_make_nodeacl,
535 	.drop_item	= target_fabric_drop_nodeacl,
536 };
537 
538 TF_CIT_SETUP(tpg_nacl, NULL, &target_fabric_nacl_group_ops, NULL);
539 
540 /* End of tfc_tpg_nacl_cit */
541 
542 /* Start of tfc_tpg_np_base_cit */
543 
544 CONFIGFS_EATTR_OPS(target_fabric_np_base, se_tpg_np, tpg_np_group);
545 
546 static void target_fabric_np_base_release(struct config_item *item)
547 {
548 	struct se_tpg_np *se_tpg_np = container_of(to_config_group(item),
549 				struct se_tpg_np, tpg_np_group);
550 	struct se_portal_group *se_tpg = se_tpg_np->tpg_np_parent;
551 	struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
552 
553 	tf->tf_ops->fabric_drop_np(se_tpg_np);
554 }
555 
556 static struct configfs_item_operations target_fabric_np_base_item_ops = {
557 	.release		= target_fabric_np_base_release,
558 	.show_attribute		= target_fabric_np_base_attr_show,
559 	.store_attribute	= target_fabric_np_base_attr_store,
560 };
561 
562 TF_CIT_SETUP_DRV(tpg_np_base, &target_fabric_np_base_item_ops, NULL);
563 
564 /* End of tfc_tpg_np_base_cit */
565 
566 /* Start of tfc_tpg_np_cit */
567 
568 static struct config_group *target_fabric_make_np(
569 	struct config_group *group,
570 	const char *name)
571 {
572 	struct se_portal_group *se_tpg = container_of(group,
573 				struct se_portal_group, tpg_np_group);
574 	struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
575 	struct se_tpg_np *se_tpg_np;
576 
577 	if (!tf->tf_ops->fabric_make_np) {
578 		pr_err("tf->tf_ops.fabric_make_np is NULL\n");
579 		return ERR_PTR(-ENOSYS);
580 	}
581 
582 	se_tpg_np = tf->tf_ops->fabric_make_np(se_tpg, group, name);
583 	if (!se_tpg_np || IS_ERR(se_tpg_np))
584 		return ERR_PTR(-EINVAL);
585 
586 	se_tpg_np->tpg_np_parent = se_tpg;
587 	config_group_init_type_name(&se_tpg_np->tpg_np_group, name,
588 			&tf->tf_tpg_np_base_cit);
589 
590 	return &se_tpg_np->tpg_np_group;
591 }
592 
593 static void target_fabric_drop_np(
594 	struct config_group *group,
595 	struct config_item *item)
596 {
597 	/*
598 	 * struct se_tpg_np is released via target_fabric_np_base_release()
599 	 */
600 	config_item_put(item);
601 }
602 
603 static struct configfs_group_operations target_fabric_np_group_ops = {
604 	.make_group	= &target_fabric_make_np,
605 	.drop_item	= &target_fabric_drop_np,
606 };
607 
608 TF_CIT_SETUP(tpg_np, NULL, &target_fabric_np_group_ops, NULL);
609 
610 /* End of tfc_tpg_np_cit */
611 
612 /* Start of tfc_tpg_port_cit */
613 
614 CONFIGFS_EATTR_STRUCT(target_fabric_port, se_lun);
615 #define TCM_PORT_ATTR(_name, _mode)					\
616 static struct target_fabric_port_attribute target_fabric_port_##_name =	\
617 	__CONFIGFS_EATTR(_name, _mode,					\
618 	target_fabric_port_show_attr_##_name,				\
619 	target_fabric_port_store_attr_##_name);
620 
621 #define TCM_PORT_ATTOR_RO(_name)					\
622 	__CONFIGFS_EATTR_RO(_name,					\
623 	target_fabric_port_show_attr_##_name);
624 
625 /*
626  * alua_tg_pt_gp
627  */
628 static ssize_t target_fabric_port_show_attr_alua_tg_pt_gp(
629 	struct se_lun *lun,
630 	char *page)
631 {
632 	if (!lun || !lun->lun_se_dev)
633 		return -ENODEV;
634 
635 	return core_alua_show_tg_pt_gp_info(lun, page);
636 }
637 
638 static ssize_t target_fabric_port_store_attr_alua_tg_pt_gp(
639 	struct se_lun *lun,
640 	const char *page,
641 	size_t count)
642 {
643 	if (!lun || !lun->lun_se_dev)
644 		return -ENODEV;
645 
646 	return core_alua_store_tg_pt_gp_info(lun, page, count);
647 }
648 
649 TCM_PORT_ATTR(alua_tg_pt_gp, S_IRUGO | S_IWUSR);
650 
651 /*
652  * alua_tg_pt_offline
653  */
654 static ssize_t target_fabric_port_show_attr_alua_tg_pt_offline(
655 	struct se_lun *lun,
656 	char *page)
657 {
658 	if (!lun || !lun->lun_se_dev)
659 		return -ENODEV;
660 
661 	return core_alua_show_offline_bit(lun, page);
662 }
663 
664 static ssize_t target_fabric_port_store_attr_alua_tg_pt_offline(
665 	struct se_lun *lun,
666 	const char *page,
667 	size_t count)
668 {
669 	if (!lun || !lun->lun_se_dev)
670 		return -ENODEV;
671 
672 	return core_alua_store_offline_bit(lun, page, count);
673 }
674 
675 TCM_PORT_ATTR(alua_tg_pt_offline, S_IRUGO | S_IWUSR);
676 
677 /*
678  * alua_tg_pt_status
679  */
680 static ssize_t target_fabric_port_show_attr_alua_tg_pt_status(
681 	struct se_lun *lun,
682 	char *page)
683 {
684 	if (!lun || !lun->lun_se_dev)
685 		return -ENODEV;
686 
687 	return core_alua_show_secondary_status(lun, page);
688 }
689 
690 static ssize_t target_fabric_port_store_attr_alua_tg_pt_status(
691 	struct se_lun *lun,
692 	const char *page,
693 	size_t count)
694 {
695 	if (!lun || !lun->lun_se_dev)
696 		return -ENODEV;
697 
698 	return core_alua_store_secondary_status(lun, page, count);
699 }
700 
701 TCM_PORT_ATTR(alua_tg_pt_status, S_IRUGO | S_IWUSR);
702 
703 /*
704  * alua_tg_pt_write_md
705  */
706 static ssize_t target_fabric_port_show_attr_alua_tg_pt_write_md(
707 	struct se_lun *lun,
708 	char *page)
709 {
710 	if (!lun || !lun->lun_se_dev)
711 		return -ENODEV;
712 
713 	return core_alua_show_secondary_write_metadata(lun, page);
714 }
715 
716 static ssize_t target_fabric_port_store_attr_alua_tg_pt_write_md(
717 	struct se_lun *lun,
718 	const char *page,
719 	size_t count)
720 {
721 	if (!lun || !lun->lun_se_dev)
722 		return -ENODEV;
723 
724 	return core_alua_store_secondary_write_metadata(lun, page, count);
725 }
726 
727 TCM_PORT_ATTR(alua_tg_pt_write_md, S_IRUGO | S_IWUSR);
728 
729 
730 static struct configfs_attribute *target_fabric_port_attrs[] = {
731 	&target_fabric_port_alua_tg_pt_gp.attr,
732 	&target_fabric_port_alua_tg_pt_offline.attr,
733 	&target_fabric_port_alua_tg_pt_status.attr,
734 	&target_fabric_port_alua_tg_pt_write_md.attr,
735 	NULL,
736 };
737 
738 CONFIGFS_EATTR_OPS(target_fabric_port, se_lun, lun_group);
739 
740 static int target_fabric_port_link(
741 	struct config_item *lun_ci,
742 	struct config_item *se_dev_ci)
743 {
744 	struct config_item *tpg_ci;
745 	struct se_lun *lun = container_of(to_config_group(lun_ci),
746 				struct se_lun, lun_group);
747 	struct se_portal_group *se_tpg;
748 	struct se_device *dev =
749 		container_of(to_config_group(se_dev_ci), struct se_device, dev_group);
750 	struct target_fabric_configfs *tf;
751 	int ret;
752 
753 	if (dev->dev_link_magic != SE_DEV_LINK_MAGIC) {
754 		pr_err("Bad dev->dev_link_magic, not a valid se_dev_ci pointer:"
755 			" %p to struct se_device: %p\n", se_dev_ci, dev);
756 		return -EFAULT;
757 	}
758 
759 	if (!(dev->dev_flags & DF_CONFIGURED)) {
760 		pr_err("se_device not configured yet, cannot port link\n");
761 		return -ENODEV;
762 	}
763 
764 	tpg_ci = &lun_ci->ci_parent->ci_group->cg_item;
765 	se_tpg = container_of(to_config_group(tpg_ci),
766 				struct se_portal_group, tpg_group);
767 	tf = se_tpg->se_tpg_wwn->wwn_tf;
768 
769 	if (lun->lun_se_dev !=  NULL) {
770 		pr_err("Port Symlink already exists\n");
771 		return -EEXIST;
772 	}
773 
774 	ret = core_dev_add_lun(se_tpg, dev, lun);
775 	if (ret) {
776 		pr_err("core_dev_add_lun() failed: %d\n", ret);
777 		goto out;
778 	}
779 
780 	if (tf->tf_ops->fabric_post_link) {
781 		/*
782 		 * Call the optional fabric_post_link() to allow a
783 		 * fabric module to setup any additional state once
784 		 * core_dev_add_lun() has been called..
785 		 */
786 		tf->tf_ops->fabric_post_link(se_tpg, lun);
787 	}
788 
789 	return 0;
790 out:
791 	return ret;
792 }
793 
794 static int target_fabric_port_unlink(
795 	struct config_item *lun_ci,
796 	struct config_item *se_dev_ci)
797 {
798 	struct se_lun *lun = container_of(to_config_group(lun_ci),
799 				struct se_lun, lun_group);
800 	struct se_portal_group *se_tpg = lun->lun_tpg;
801 	struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
802 
803 	if (tf->tf_ops->fabric_pre_unlink) {
804 		/*
805 		 * Call the optional fabric_pre_unlink() to allow a
806 		 * fabric module to release any additional stat before
807 		 * core_dev_del_lun() is called.
808 		*/
809 		tf->tf_ops->fabric_pre_unlink(se_tpg, lun);
810 	}
811 
812 	core_dev_del_lun(se_tpg, lun);
813 	return 0;
814 }
815 
816 static void target_fabric_port_release(struct config_item *item)
817 {
818 	struct se_lun *lun = container_of(to_config_group(item),
819 					  struct se_lun, lun_group);
820 
821 	kfree_rcu(lun, rcu_head);
822 }
823 
824 static struct configfs_item_operations target_fabric_port_item_ops = {
825 	.show_attribute		= target_fabric_port_attr_show,
826 	.store_attribute	= target_fabric_port_attr_store,
827 	.release		= target_fabric_port_release,
828 	.allow_link		= target_fabric_port_link,
829 	.drop_link		= target_fabric_port_unlink,
830 };
831 
832 TF_CIT_SETUP(tpg_port, &target_fabric_port_item_ops, NULL, target_fabric_port_attrs);
833 
834 /* End of tfc_tpg_port_cit */
835 
836 /* Start of tfc_tpg_port_stat_cit */
837 
838 static struct config_group *target_core_port_stat_mkdir(
839 	struct config_group *group,
840 	const char *name)
841 {
842 	return ERR_PTR(-ENOSYS);
843 }
844 
845 static void target_core_port_stat_rmdir(
846 	struct config_group *group,
847 	struct config_item *item)
848 {
849 	return;
850 }
851 
852 static struct configfs_group_operations target_fabric_port_stat_group_ops = {
853 	.make_group		= target_core_port_stat_mkdir,
854 	.drop_item		= target_core_port_stat_rmdir,
855 };
856 
857 TF_CIT_SETUP(tpg_port_stat, NULL, &target_fabric_port_stat_group_ops, NULL);
858 
859 /* End of tfc_tpg_port_stat_cit */
860 
861 /* Start of tfc_tpg_lun_cit */
862 
863 static struct config_group *target_fabric_make_lun(
864 	struct config_group *group,
865 	const char *name)
866 {
867 	struct se_lun *lun;
868 	struct se_portal_group *se_tpg = container_of(group,
869 			struct se_portal_group, tpg_lun_group);
870 	struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
871 	struct config_group *lun_cg = NULL, *port_stat_grp = NULL;
872 	unsigned long long unpacked_lun;
873 	int errno;
874 
875 	if (strstr(name, "lun_") != name) {
876 		pr_err("Unable to locate \'_\" in"
877 				" \"lun_$LUN_NUMBER\"\n");
878 		return ERR_PTR(-EINVAL);
879 	}
880 	errno = kstrtoull(name + 4, 0, &unpacked_lun);
881 	if (errno)
882 		return ERR_PTR(errno);
883 
884 	lun = core_tpg_alloc_lun(se_tpg, unpacked_lun);
885 	if (IS_ERR(lun))
886 		return ERR_CAST(lun);
887 
888 	lun_cg = &lun->lun_group;
889 	lun_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2,
890 				GFP_KERNEL);
891 	if (!lun_cg->default_groups) {
892 		pr_err("Unable to allocate lun_cg->default_groups\n");
893 		kfree(lun);
894 		return ERR_PTR(-ENOMEM);
895 	}
896 
897 	config_group_init_type_name(&lun->lun_group, name,
898 			&tf->tf_tpg_port_cit);
899 	config_group_init_type_name(&lun->port_stat_grps.stat_group,
900 			"statistics", &tf->tf_tpg_port_stat_cit);
901 	lun_cg->default_groups[0] = &lun->port_stat_grps.stat_group;
902 	lun_cg->default_groups[1] = NULL;
903 
904 	port_stat_grp = &lun->port_stat_grps.stat_group;
905 	port_stat_grp->default_groups =  kzalloc(sizeof(struct config_group *) * 4,
906 				GFP_KERNEL);
907 	if (!port_stat_grp->default_groups) {
908 		pr_err("Unable to allocate port_stat_grp->default_groups\n");
909 		kfree(lun_cg->default_groups);
910 		kfree(lun);
911 		return ERR_PTR(-ENOMEM);
912 	}
913 	target_stat_setup_port_default_groups(lun);
914 
915 	return &lun->lun_group;
916 }
917 
918 static void target_fabric_drop_lun(
919 	struct config_group *group,
920 	struct config_item *item)
921 {
922 	struct se_lun *lun = container_of(to_config_group(item),
923 				struct se_lun, lun_group);
924 	struct config_item *df_item;
925 	struct config_group *lun_cg, *port_stat_grp;
926 	int i;
927 
928 	port_stat_grp = &lun->port_stat_grps.stat_group;
929 	for (i = 0; port_stat_grp->default_groups[i]; i++) {
930 		df_item = &port_stat_grp->default_groups[i]->cg_item;
931 		port_stat_grp->default_groups[i] = NULL;
932 		config_item_put(df_item);
933 	}
934 	kfree(port_stat_grp->default_groups);
935 
936 	lun_cg = &lun->lun_group;
937 	for (i = 0; lun_cg->default_groups[i]; i++) {
938 		df_item = &lun_cg->default_groups[i]->cg_item;
939 		lun_cg->default_groups[i] = NULL;
940 		config_item_put(df_item);
941 	}
942 	kfree(lun_cg->default_groups);
943 
944 	config_item_put(item);
945 }
946 
947 static struct configfs_group_operations target_fabric_lun_group_ops = {
948 	.make_group	= &target_fabric_make_lun,
949 	.drop_item	= &target_fabric_drop_lun,
950 };
951 
952 TF_CIT_SETUP(tpg_lun, NULL, &target_fabric_lun_group_ops, NULL);
953 
954 /* End of tfc_tpg_lun_cit */
955 
956 /* Start of tfc_tpg_attrib_cit */
957 
958 CONFIGFS_EATTR_OPS(target_fabric_tpg_attrib, se_portal_group, tpg_attrib_group);
959 
960 static struct configfs_item_operations target_fabric_tpg_attrib_item_ops = {
961 	.show_attribute		= target_fabric_tpg_attrib_attr_show,
962 	.store_attribute	= target_fabric_tpg_attrib_attr_store,
963 };
964 
965 TF_CIT_SETUP_DRV(tpg_attrib, &target_fabric_tpg_attrib_item_ops, NULL);
966 
967 /* End of tfc_tpg_attrib_cit */
968 
969 /* Start of tfc_tpg_auth_cit */
970 
971 CONFIGFS_EATTR_OPS(target_fabric_tpg_auth, se_portal_group, tpg_auth_group);
972 
973 static struct configfs_item_operations target_fabric_tpg_auth_item_ops = {
974 	.show_attribute		= target_fabric_tpg_auth_attr_show,
975 	.store_attribute	= target_fabric_tpg_auth_attr_store,
976 };
977 
978 TF_CIT_SETUP_DRV(tpg_auth, &target_fabric_tpg_auth_item_ops, NULL);
979 
980 /* End of tfc_tpg_attrib_cit */
981 
982 /* Start of tfc_tpg_param_cit */
983 
984 CONFIGFS_EATTR_OPS(target_fabric_tpg_param, se_portal_group, tpg_param_group);
985 
986 static struct configfs_item_operations target_fabric_tpg_param_item_ops = {
987 	.show_attribute		= target_fabric_tpg_param_attr_show,
988 	.store_attribute	= target_fabric_tpg_param_attr_store,
989 };
990 
991 TF_CIT_SETUP_DRV(tpg_param, &target_fabric_tpg_param_item_ops, NULL);
992 
993 /* End of tfc_tpg_param_cit */
994 
995 /* Start of tfc_tpg_base_cit */
996 /*
997  * For use with TF_TPG_ATTR() and TF_TPG_ATTR_RO()
998  */
999 CONFIGFS_EATTR_OPS(target_fabric_tpg, se_portal_group, tpg_group);
1000 
1001 static void target_fabric_tpg_release(struct config_item *item)
1002 {
1003 	struct se_portal_group *se_tpg = container_of(to_config_group(item),
1004 			struct se_portal_group, tpg_group);
1005 	struct se_wwn *wwn = se_tpg->se_tpg_wwn;
1006 	struct target_fabric_configfs *tf = wwn->wwn_tf;
1007 
1008 	tf->tf_ops->fabric_drop_tpg(se_tpg);
1009 }
1010 
1011 static struct configfs_item_operations target_fabric_tpg_base_item_ops = {
1012 	.release		= target_fabric_tpg_release,
1013 	.show_attribute		= target_fabric_tpg_attr_show,
1014 	.store_attribute	= target_fabric_tpg_attr_store,
1015 };
1016 
1017 TF_CIT_SETUP_DRV(tpg_base, &target_fabric_tpg_base_item_ops, NULL);
1018 
1019 /* End of tfc_tpg_base_cit */
1020 
1021 /* Start of tfc_tpg_cit */
1022 
1023 static struct config_group *target_fabric_make_tpg(
1024 	struct config_group *group,
1025 	const char *name)
1026 {
1027 	struct se_wwn *wwn = container_of(group, struct se_wwn, wwn_group);
1028 	struct target_fabric_configfs *tf = wwn->wwn_tf;
1029 	struct se_portal_group *se_tpg;
1030 
1031 	if (!tf->tf_ops->fabric_make_tpg) {
1032 		pr_err("tf->tf_ops->fabric_make_tpg is NULL\n");
1033 		return ERR_PTR(-ENOSYS);
1034 	}
1035 
1036 	se_tpg = tf->tf_ops->fabric_make_tpg(wwn, group, name);
1037 	if (!se_tpg || IS_ERR(se_tpg))
1038 		return ERR_PTR(-EINVAL);
1039 	/*
1040 	 * Setup default groups from pre-allocated se_tpg->tpg_default_groups
1041 	 */
1042 	se_tpg->tpg_group.default_groups = se_tpg->tpg_default_groups;
1043 	se_tpg->tpg_group.default_groups[0] = &se_tpg->tpg_lun_group;
1044 	se_tpg->tpg_group.default_groups[1] = &se_tpg->tpg_np_group;
1045 	se_tpg->tpg_group.default_groups[2] = &se_tpg->tpg_acl_group;
1046 	se_tpg->tpg_group.default_groups[3] = &se_tpg->tpg_attrib_group;
1047 	se_tpg->tpg_group.default_groups[4] = &se_tpg->tpg_auth_group;
1048 	se_tpg->tpg_group.default_groups[5] = &se_tpg->tpg_param_group;
1049 	se_tpg->tpg_group.default_groups[6] = NULL;
1050 
1051 	config_group_init_type_name(&se_tpg->tpg_group, name,
1052 			&tf->tf_tpg_base_cit);
1053 	config_group_init_type_name(&se_tpg->tpg_lun_group, "lun",
1054 			&tf->tf_tpg_lun_cit);
1055 	config_group_init_type_name(&se_tpg->tpg_np_group, "np",
1056 			&tf->tf_tpg_np_cit);
1057 	config_group_init_type_name(&se_tpg->tpg_acl_group, "acls",
1058 			&tf->tf_tpg_nacl_cit);
1059 	config_group_init_type_name(&se_tpg->tpg_attrib_group, "attrib",
1060 			&tf->tf_tpg_attrib_cit);
1061 	config_group_init_type_name(&se_tpg->tpg_auth_group, "auth",
1062 			&tf->tf_tpg_auth_cit);
1063 	config_group_init_type_name(&se_tpg->tpg_param_group, "param",
1064 			&tf->tf_tpg_param_cit);
1065 
1066 	return &se_tpg->tpg_group;
1067 }
1068 
1069 static void target_fabric_drop_tpg(
1070 	struct config_group *group,
1071 	struct config_item *item)
1072 {
1073 	struct se_portal_group *se_tpg = container_of(to_config_group(item),
1074 				struct se_portal_group, tpg_group);
1075 	struct config_group *tpg_cg = &se_tpg->tpg_group;
1076 	struct config_item *df_item;
1077 	int i;
1078 	/*
1079 	 * Release default groups, but do not release tpg_cg->default_groups
1080 	 * memory as it is statically allocated at se_tpg->tpg_default_groups.
1081 	 */
1082 	for (i = 0; tpg_cg->default_groups[i]; i++) {
1083 		df_item = &tpg_cg->default_groups[i]->cg_item;
1084 		tpg_cg->default_groups[i] = NULL;
1085 		config_item_put(df_item);
1086 	}
1087 
1088 	config_item_put(item);
1089 }
1090 
1091 static void target_fabric_release_wwn(struct config_item *item)
1092 {
1093 	struct se_wwn *wwn = container_of(to_config_group(item),
1094 				struct se_wwn, wwn_group);
1095 	struct target_fabric_configfs *tf = wwn->wwn_tf;
1096 
1097 	tf->tf_ops->fabric_drop_wwn(wwn);
1098 }
1099 
1100 static struct configfs_item_operations target_fabric_tpg_item_ops = {
1101 	.release	= target_fabric_release_wwn,
1102 };
1103 
1104 static struct configfs_group_operations target_fabric_tpg_group_ops = {
1105 	.make_group	= target_fabric_make_tpg,
1106 	.drop_item	= target_fabric_drop_tpg,
1107 };
1108 
1109 TF_CIT_SETUP(tpg, &target_fabric_tpg_item_ops, &target_fabric_tpg_group_ops,
1110 		NULL);
1111 
1112 /* End of tfc_tpg_cit */
1113 
1114 /* Start of tfc_wwn_fabric_stats_cit */
1115 /*
1116  * This is used as a placeholder for struct se_wwn->fabric_stat_group
1117  * to allow fabrics access to ->fabric_stat_group->default_groups[]
1118  */
1119 TF_CIT_SETUP(wwn_fabric_stats, NULL, NULL, NULL);
1120 
1121 /* End of tfc_wwn_fabric_stats_cit */
1122 
1123 /* Start of tfc_wwn_cit */
1124 
1125 static struct config_group *target_fabric_make_wwn(
1126 	struct config_group *group,
1127 	const char *name)
1128 {
1129 	struct target_fabric_configfs *tf = container_of(group,
1130 				struct target_fabric_configfs, tf_group);
1131 	struct se_wwn *wwn;
1132 
1133 	if (!tf->tf_ops->fabric_make_wwn) {
1134 		pr_err("tf->tf_ops.fabric_make_wwn is NULL\n");
1135 		return ERR_PTR(-ENOSYS);
1136 	}
1137 
1138 	wwn = tf->tf_ops->fabric_make_wwn(tf, group, name);
1139 	if (!wwn || IS_ERR(wwn))
1140 		return ERR_PTR(-EINVAL);
1141 
1142 	wwn->wwn_tf = tf;
1143 	/*
1144 	 * Setup default groups from pre-allocated wwn->wwn_default_groups
1145 	 */
1146 	wwn->wwn_group.default_groups = wwn->wwn_default_groups;
1147 	wwn->wwn_group.default_groups[0] = &wwn->fabric_stat_group;
1148 	wwn->wwn_group.default_groups[1] = NULL;
1149 
1150 	config_group_init_type_name(&wwn->wwn_group, name, &tf->tf_tpg_cit);
1151 	config_group_init_type_name(&wwn->fabric_stat_group, "fabric_statistics",
1152 			&tf->tf_wwn_fabric_stats_cit);
1153 
1154 	return &wwn->wwn_group;
1155 }
1156 
1157 static void target_fabric_drop_wwn(
1158 	struct config_group *group,
1159 	struct config_item *item)
1160 {
1161 	struct se_wwn *wwn = container_of(to_config_group(item),
1162 				struct se_wwn, wwn_group);
1163 	struct config_item *df_item;
1164 	struct config_group *cg = &wwn->wwn_group;
1165 	int i;
1166 
1167 	for (i = 0; cg->default_groups[i]; i++) {
1168 		df_item = &cg->default_groups[i]->cg_item;
1169 		cg->default_groups[i] = NULL;
1170 		config_item_put(df_item);
1171 	}
1172 
1173 	config_item_put(item);
1174 }
1175 
1176 static struct configfs_group_operations target_fabric_wwn_group_ops = {
1177 	.make_group	= target_fabric_make_wwn,
1178 	.drop_item	= target_fabric_drop_wwn,
1179 };
1180 /*
1181  * For use with TF_WWN_ATTR() and TF_WWN_ATTR_RO()
1182  */
1183 CONFIGFS_EATTR_OPS(target_fabric_wwn, target_fabric_configfs, tf_group);
1184 
1185 static struct configfs_item_operations target_fabric_wwn_item_ops = {
1186 	.show_attribute		= target_fabric_wwn_attr_show,
1187 	.store_attribute	= target_fabric_wwn_attr_store,
1188 };
1189 
1190 TF_CIT_SETUP_DRV(wwn, &target_fabric_wwn_item_ops, &target_fabric_wwn_group_ops);
1191 
1192 /* End of tfc_wwn_cit */
1193 
1194 /* Start of tfc_discovery_cit */
1195 
1196 CONFIGFS_EATTR_OPS(target_fabric_discovery, target_fabric_configfs,
1197 		tf_disc_group);
1198 
1199 static struct configfs_item_operations target_fabric_discovery_item_ops = {
1200 	.show_attribute		= target_fabric_discovery_attr_show,
1201 	.store_attribute	= target_fabric_discovery_attr_store,
1202 };
1203 
1204 TF_CIT_SETUP_DRV(discovery, &target_fabric_discovery_item_ops, NULL);
1205 
1206 /* End of tfc_discovery_cit */
1207 
1208 int target_fabric_setup_cits(struct target_fabric_configfs *tf)
1209 {
1210 	target_fabric_setup_discovery_cit(tf);
1211 	target_fabric_setup_wwn_cit(tf);
1212 	target_fabric_setup_wwn_fabric_stats_cit(tf);
1213 	target_fabric_setup_tpg_cit(tf);
1214 	target_fabric_setup_tpg_base_cit(tf);
1215 	target_fabric_setup_tpg_port_cit(tf);
1216 	target_fabric_setup_tpg_port_stat_cit(tf);
1217 	target_fabric_setup_tpg_lun_cit(tf);
1218 	target_fabric_setup_tpg_np_cit(tf);
1219 	target_fabric_setup_tpg_np_base_cit(tf);
1220 	target_fabric_setup_tpg_attrib_cit(tf);
1221 	target_fabric_setup_tpg_auth_cit(tf);
1222 	target_fabric_setup_tpg_param_cit(tf);
1223 	target_fabric_setup_tpg_nacl_cit(tf);
1224 	target_fabric_setup_tpg_nacl_base_cit(tf);
1225 	target_fabric_setup_tpg_nacl_attrib_cit(tf);
1226 	target_fabric_setup_tpg_nacl_auth_cit(tf);
1227 	target_fabric_setup_tpg_nacl_param_cit(tf);
1228 	target_fabric_setup_tpg_nacl_stat_cit(tf);
1229 	target_fabric_setup_tpg_mappedlun_cit(tf);
1230 	target_fabric_setup_tpg_mappedlun_stat_cit(tf);
1231 
1232 	return 0;
1233 }
1234