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