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