1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*******************************************************************************
3 * Filename: target_core_fabric_configfs.c
5 * This file contains generic fabric module configfs infrastructure for
8 * (c) Copyright 2010-2013 Datera, Inc.
10 * Nicholas A. Bellinger <nab@linux-iscsi.org>
12 ****************************************************************************/
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/utsname.h>
17 #include <linux/init.h>
19 #include <linux/namei.h>
20 #include <linux/slab.h>
21 #include <linux/types.h>
22 #include <linux/delay.h>
23 #include <linux/unistd.h>
24 #include <linux/string.h>
25 #include <linux/syscalls.h>
26 #include <linux/configfs.h>
28 #include <target/target_core_base.h>
29 #include <target/target_core_backend.h>
30 #include <target/target_core_fabric.h>
32 #include "target_core_internal.h"
33 #include "target_core_alua.h"
34 #include "target_core_pr.h"
36 #define TF_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \
37 static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \
39 struct config_item_type *cit = &tf->tf_##_name##_cit; \
41 cit->ct_item_ops = _item_ops; \
42 cit->ct_group_ops = _group_ops; \
43 cit->ct_attrs = _attrs; \
44 cit->ct_owner = tf->tf_ops->module; \
45 pr_debug("Setup generic %s\n", __stringify(_name)); \
48 #define TF_CIT_SETUP_DRV(_name, _item_ops, _group_ops) \
49 static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \
51 struct config_item_type *cit = &tf->tf_##_name##_cit; \
52 struct configfs_attribute **attrs = tf->tf_ops->tfc_##_name##_attrs; \
54 cit->ct_item_ops = _item_ops; \
55 cit->ct_group_ops = _group_ops; \
56 cit->ct_attrs = attrs; \
57 cit->ct_owner = tf->tf_ops->module; \
58 pr_debug("Setup generic %s\n", __stringify(_name)); \
61 static struct configfs_item_operations target_fabric_port_item_ops
;
63 /* Start of tfc_tpg_mappedlun_cit */
65 static int target_fabric_mappedlun_link(
66 struct config_item
*lun_acl_ci
,
67 struct config_item
*lun_ci
)
69 struct se_dev_entry
*deve
;
71 struct se_lun_acl
*lacl
= container_of(to_config_group(lun_acl_ci
),
72 struct se_lun_acl
, se_lun_group
);
73 struct se_portal_group
*se_tpg
;
74 struct config_item
*nacl_ci
, *tpg_ci
, *tpg_ci_s
, *wwn_ci
, *wwn_ci_s
;
77 if (!lun_ci
->ci_type
||
78 lun_ci
->ci_type
->ct_item_ops
!= &target_fabric_port_item_ops
) {
79 pr_err("Bad lun_ci, not a valid lun_ci pointer: %p\n", lun_ci
);
82 lun
= container_of(to_config_group(lun_ci
), struct se_lun
, lun_group
);
85 * Ensure that the source port exists
87 if (!lun
->lun_se_dev
) {
88 pr_err("Source se_lun->lun_se_dev does not exist\n");
91 if (lun
->lun_shutdown
) {
92 pr_err("Unable to create mappedlun symlink because"
93 " lun->lun_shutdown=true\n");
96 se_tpg
= lun
->lun_tpg
;
98 nacl_ci
= &lun_acl_ci
->ci_parent
->ci_group
->cg_item
;
99 tpg_ci
= &nacl_ci
->ci_group
->cg_item
;
100 wwn_ci
= &tpg_ci
->ci_group
->cg_item
;
101 tpg_ci_s
= &lun_ci
->ci_parent
->ci_group
->cg_item
;
102 wwn_ci_s
= &tpg_ci_s
->ci_group
->cg_item
;
104 * Make sure the SymLink is going to the same $FABRIC/$WWN/tpgt_$TPGT
106 if (strcmp(config_item_name(wwn_ci
), config_item_name(wwn_ci_s
))) {
107 pr_err("Illegal Initiator ACL SymLink outside of %s\n",
108 config_item_name(wwn_ci
));
111 if (strcmp(config_item_name(tpg_ci
), config_item_name(tpg_ci_s
))) {
112 pr_err("Illegal Initiator ACL Symlink outside of %s"
113 " TPGT: %s\n", config_item_name(wwn_ci
),
114 config_item_name(tpg_ci
));
118 * If this struct se_node_acl was dynamically generated with
119 * tpg_1/attrib/generate_node_acls=1, use the existing
120 * deve->lun_access_ro value, which will be true when
121 * tpg_1/attrib/demo_mode_write_protect=1
124 deve
= target_nacl_find_deve(lacl
->se_lun_nacl
, lacl
->mapped_lun
);
126 lun_access_ro
= deve
->lun_access_ro
;
129 (se_tpg
->se_tpg_tfo
->tpg_check_prod_mode_write_protect(
130 se_tpg
)) ? true : false;
133 * Determine the actual mapped LUN value user wants..
135 * This value is what the SCSI Initiator actually sees the
136 * $FABRIC/$WWPN/$TPGT/lun/lun_* as on their SCSI Initiator Ports.
138 return core_dev_add_initiator_node_lun_acl(se_tpg
, lacl
, lun
, lun_access_ro
);
141 static void target_fabric_mappedlun_unlink(
142 struct config_item
*lun_acl_ci
,
143 struct config_item
*lun_ci
)
145 struct se_lun_acl
*lacl
= container_of(to_config_group(lun_acl_ci
),
146 struct se_lun_acl
, se_lun_group
);
147 struct se_lun
*lun
= container_of(to_config_group(lun_ci
),
148 struct se_lun
, lun_group
);
150 core_dev_del_initiator_node_lun_acl(lun
, lacl
);
153 static struct se_lun_acl
*item_to_lun_acl(struct config_item
*item
)
155 return container_of(to_config_group(item
), struct se_lun_acl
,
159 static ssize_t
target_fabric_mappedlun_write_protect_show(
160 struct config_item
*item
, char *page
)
162 struct se_lun_acl
*lacl
= item_to_lun_acl(item
);
163 struct se_node_acl
*se_nacl
= lacl
->se_lun_nacl
;
164 struct se_dev_entry
*deve
;
168 deve
= target_nacl_find_deve(se_nacl
, lacl
->mapped_lun
);
170 len
= sprintf(page
, "%d\n", deve
->lun_access_ro
);
177 static ssize_t
target_fabric_mappedlun_write_protect_store(
178 struct config_item
*item
, const char *page
, size_t count
)
180 struct se_lun_acl
*lacl
= item_to_lun_acl(item
);
181 struct se_node_acl
*se_nacl
= lacl
->se_lun_nacl
;
182 struct se_portal_group
*se_tpg
= se_nacl
->se_tpg
;
186 ret
= kstrtoul(page
, 0, &wp
);
190 if ((wp
!= 1) && (wp
!= 0))
193 /* wp=1 means lun_access_ro=true */
194 core_update_device_list_access(lacl
->mapped_lun
, wp
, lacl
->se_lun_nacl
);
196 pr_debug("%s_ConfigFS: Changed Initiator ACL: %s"
197 " Mapped LUN: %llu Write Protect bit to %s\n",
198 se_tpg
->se_tpg_tfo
->fabric_name
,
199 se_nacl
->initiatorname
, lacl
->mapped_lun
, (wp
) ? "ON" : "OFF");
205 CONFIGFS_ATTR(target_fabric_mappedlun_
, write_protect
);
207 static struct configfs_attribute
*target_fabric_mappedlun_attrs
[] = {
208 &target_fabric_mappedlun_attr_write_protect
,
212 static void target_fabric_mappedlun_release(struct config_item
*item
)
214 struct se_lun_acl
*lacl
= container_of(to_config_group(item
),
215 struct se_lun_acl
, se_lun_group
);
216 struct se_portal_group
*se_tpg
= lacl
->se_lun_nacl
->se_tpg
;
218 core_dev_free_initiator_node_lun_acl(se_tpg
, lacl
);
221 static struct configfs_item_operations target_fabric_mappedlun_item_ops
= {
222 .release
= target_fabric_mappedlun_release
,
223 .allow_link
= target_fabric_mappedlun_link
,
224 .drop_link
= target_fabric_mappedlun_unlink
,
227 TF_CIT_SETUP(tpg_mappedlun
, &target_fabric_mappedlun_item_ops
, NULL
,
228 target_fabric_mappedlun_attrs
);
230 /* End of tfc_tpg_mappedlun_cit */
232 /* Start of tfc_tpg_mappedlun_port_cit */
234 static struct config_group
*target_core_mappedlun_stat_mkdir(
235 struct config_group
*group
,
238 return ERR_PTR(-ENOSYS
);
241 static void target_core_mappedlun_stat_rmdir(
242 struct config_group
*group
,
243 struct config_item
*item
)
248 static struct configfs_group_operations target_fabric_mappedlun_stat_group_ops
= {
249 .make_group
= target_core_mappedlun_stat_mkdir
,
250 .drop_item
= target_core_mappedlun_stat_rmdir
,
253 TF_CIT_SETUP(tpg_mappedlun_stat
, NULL
, &target_fabric_mappedlun_stat_group_ops
,
256 /* End of tfc_tpg_mappedlun_port_cit */
258 TF_CIT_SETUP_DRV(tpg_nacl_attrib
, NULL
, NULL
);
259 TF_CIT_SETUP_DRV(tpg_nacl_auth
, NULL
, NULL
);
260 TF_CIT_SETUP_DRV(tpg_nacl_param
, NULL
, NULL
);
262 /* Start of tfc_tpg_nacl_base_cit */
264 static struct config_group
*target_fabric_make_mappedlun(
265 struct config_group
*group
,
268 struct se_node_acl
*se_nacl
= container_of(group
,
269 struct se_node_acl
, acl_group
);
270 struct se_portal_group
*se_tpg
= se_nacl
->se_tpg
;
271 struct target_fabric_configfs
*tf
= se_tpg
->se_tpg_wwn
->wwn_tf
;
272 struct se_lun_acl
*lacl
= NULL
;
274 unsigned long long mapped_lun
;
277 buf
= kzalloc(strlen(name
) + 1, GFP_KERNEL
);
279 pr_err("Unable to allocate memory for name buf\n");
280 return ERR_PTR(-ENOMEM
);
282 snprintf(buf
, strlen(name
) + 1, "%s", name
);
284 * Make sure user is creating iscsi/$IQN/$TPGT/acls/$INITIATOR/lun_$ID.
286 if (strstr(buf
, "lun_") != buf
) {
287 pr_err("Unable to locate \"lun_\" from buf: %s"
288 " name: %s\n", buf
, name
);
293 * Determine the Mapped LUN value. This is what the SCSI Initiator
294 * Port will actually see.
296 ret
= kstrtoull(buf
+ 4, 0, &mapped_lun
);
300 lacl
= core_dev_init_initiator_node_lun_acl(se_tpg
, se_nacl
,
307 config_group_init_type_name(&lacl
->se_lun_group
, name
,
308 &tf
->tf_tpg_mappedlun_cit
);
310 config_group_init_type_name(&lacl
->ml_stat_grps
.stat_group
,
311 "statistics", &tf
->tf_tpg_mappedlun_stat_cit
);
312 configfs_add_default_group(&lacl
->ml_stat_grps
.stat_group
,
313 &lacl
->se_lun_group
);
315 target_stat_setup_mappedlun_default_groups(lacl
);
318 return &lacl
->se_lun_group
;
325 static void target_fabric_drop_mappedlun(
326 struct config_group
*group
,
327 struct config_item
*item
)
329 struct se_lun_acl
*lacl
= container_of(to_config_group(item
),
330 struct se_lun_acl
, se_lun_group
);
332 configfs_remove_default_groups(&lacl
->ml_stat_grps
.stat_group
);
333 configfs_remove_default_groups(&lacl
->se_lun_group
);
335 config_item_put(item
);
338 static void target_fabric_nacl_base_release(struct config_item
*item
)
340 struct se_node_acl
*se_nacl
= container_of(to_config_group(item
),
341 struct se_node_acl
, acl_group
);
343 configfs_remove_default_groups(&se_nacl
->acl_fabric_stat_group
);
344 core_tpg_del_initiator_node_acl(se_nacl
);
347 static struct configfs_item_operations target_fabric_nacl_base_item_ops
= {
348 .release
= target_fabric_nacl_base_release
,
351 static struct configfs_group_operations target_fabric_nacl_base_group_ops
= {
352 .make_group
= target_fabric_make_mappedlun
,
353 .drop_item
= target_fabric_drop_mappedlun
,
356 TF_CIT_SETUP_DRV(tpg_nacl_base
, &target_fabric_nacl_base_item_ops
,
357 &target_fabric_nacl_base_group_ops
);
359 /* End of tfc_tpg_nacl_base_cit */
361 /* Start of tfc_node_fabric_stats_cit */
363 * This is used as a placeholder for struct se_node_acl->acl_fabric_stat_group
364 * to allow fabrics access to ->acl_fabric_stat_group->default_groups[]
366 TF_CIT_SETUP(tpg_nacl_stat
, NULL
, NULL
, NULL
);
368 /* End of tfc_wwn_fabric_stats_cit */
370 /* Start of tfc_tpg_nacl_cit */
372 static struct config_group
*target_fabric_make_nodeacl(
373 struct config_group
*group
,
376 struct se_portal_group
*se_tpg
= container_of(group
,
377 struct se_portal_group
, tpg_acl_group
);
378 struct target_fabric_configfs
*tf
= se_tpg
->se_tpg_wwn
->wwn_tf
;
379 struct se_node_acl
*se_nacl
;
381 se_nacl
= core_tpg_add_initiator_node_acl(se_tpg
, name
);
383 return ERR_CAST(se_nacl
);
385 config_group_init_type_name(&se_nacl
->acl_group
, name
,
386 &tf
->tf_tpg_nacl_base_cit
);
388 config_group_init_type_name(&se_nacl
->acl_attrib_group
, "attrib",
389 &tf
->tf_tpg_nacl_attrib_cit
);
390 configfs_add_default_group(&se_nacl
->acl_attrib_group
,
391 &se_nacl
->acl_group
);
393 config_group_init_type_name(&se_nacl
->acl_auth_group
, "auth",
394 &tf
->tf_tpg_nacl_auth_cit
);
395 configfs_add_default_group(&se_nacl
->acl_auth_group
,
396 &se_nacl
->acl_group
);
398 config_group_init_type_name(&se_nacl
->acl_param_group
, "param",
399 &tf
->tf_tpg_nacl_param_cit
);
400 configfs_add_default_group(&se_nacl
->acl_param_group
,
401 &se_nacl
->acl_group
);
403 config_group_init_type_name(&se_nacl
->acl_fabric_stat_group
,
404 "fabric_statistics", &tf
->tf_tpg_nacl_stat_cit
);
405 configfs_add_default_group(&se_nacl
->acl_fabric_stat_group
,
406 &se_nacl
->acl_group
);
408 if (tf
->tf_ops
->fabric_init_nodeacl
) {
409 int ret
= tf
->tf_ops
->fabric_init_nodeacl(se_nacl
, name
);
411 configfs_remove_default_groups(&se_nacl
->acl_fabric_stat_group
);
412 core_tpg_del_initiator_node_acl(se_nacl
);
417 return &se_nacl
->acl_group
;
420 static void target_fabric_drop_nodeacl(
421 struct config_group
*group
,
422 struct config_item
*item
)
424 struct se_node_acl
*se_nacl
= container_of(to_config_group(item
),
425 struct se_node_acl
, acl_group
);
427 configfs_remove_default_groups(&se_nacl
->acl_group
);
430 * struct se_node_acl free is done in target_fabric_nacl_base_release()
432 config_item_put(item
);
435 static struct configfs_group_operations target_fabric_nacl_group_ops
= {
436 .make_group
= target_fabric_make_nodeacl
,
437 .drop_item
= target_fabric_drop_nodeacl
,
440 TF_CIT_SETUP(tpg_nacl
, NULL
, &target_fabric_nacl_group_ops
, NULL
);
442 /* End of tfc_tpg_nacl_cit */
444 /* Start of tfc_tpg_np_base_cit */
446 static void target_fabric_np_base_release(struct config_item
*item
)
448 struct se_tpg_np
*se_tpg_np
= container_of(to_config_group(item
),
449 struct se_tpg_np
, tpg_np_group
);
450 struct se_portal_group
*se_tpg
= se_tpg_np
->tpg_np_parent
;
451 struct target_fabric_configfs
*tf
= se_tpg
->se_tpg_wwn
->wwn_tf
;
453 tf
->tf_ops
->fabric_drop_np(se_tpg_np
);
456 static struct configfs_item_operations target_fabric_np_base_item_ops
= {
457 .release
= target_fabric_np_base_release
,
460 TF_CIT_SETUP_DRV(tpg_np_base
, &target_fabric_np_base_item_ops
, NULL
);
462 /* End of tfc_tpg_np_base_cit */
464 /* Start of tfc_tpg_np_cit */
466 static struct config_group
*target_fabric_make_np(
467 struct config_group
*group
,
470 struct se_portal_group
*se_tpg
= container_of(group
,
471 struct se_portal_group
, tpg_np_group
);
472 struct target_fabric_configfs
*tf
= se_tpg
->se_tpg_wwn
->wwn_tf
;
473 struct se_tpg_np
*se_tpg_np
;
475 if (!tf
->tf_ops
->fabric_make_np
) {
476 pr_err("tf->tf_ops.fabric_make_np is NULL\n");
477 return ERR_PTR(-ENOSYS
);
480 se_tpg_np
= tf
->tf_ops
->fabric_make_np(se_tpg
, group
, name
);
481 if (!se_tpg_np
|| IS_ERR(se_tpg_np
))
482 return ERR_PTR(-EINVAL
);
484 se_tpg_np
->tpg_np_parent
= se_tpg
;
485 config_group_init_type_name(&se_tpg_np
->tpg_np_group
, name
,
486 &tf
->tf_tpg_np_base_cit
);
488 return &se_tpg_np
->tpg_np_group
;
491 static void target_fabric_drop_np(
492 struct config_group
*group
,
493 struct config_item
*item
)
496 * struct se_tpg_np is released via target_fabric_np_base_release()
498 config_item_put(item
);
501 static struct configfs_group_operations target_fabric_np_group_ops
= {
502 .make_group
= &target_fabric_make_np
,
503 .drop_item
= &target_fabric_drop_np
,
506 TF_CIT_SETUP(tpg_np
, NULL
, &target_fabric_np_group_ops
, NULL
);
508 /* End of tfc_tpg_np_cit */
510 /* Start of tfc_tpg_port_cit */
512 static struct se_lun
*item_to_lun(struct config_item
*item
)
514 return container_of(to_config_group(item
), struct se_lun
,
518 static ssize_t
target_fabric_port_alua_tg_pt_gp_show(struct config_item
*item
,
521 struct se_lun
*lun
= item_to_lun(item
);
523 if (!lun
|| !lun
->lun_se_dev
)
526 return core_alua_show_tg_pt_gp_info(lun
, page
);
529 static ssize_t
target_fabric_port_alua_tg_pt_gp_store(struct config_item
*item
,
530 const char *page
, size_t count
)
532 struct se_lun
*lun
= item_to_lun(item
);
534 if (!lun
|| !lun
->lun_se_dev
)
537 return core_alua_store_tg_pt_gp_info(lun
, page
, count
);
540 static ssize_t
target_fabric_port_alua_tg_pt_offline_show(
541 struct config_item
*item
, char *page
)
543 struct se_lun
*lun
= item_to_lun(item
);
545 if (!lun
|| !lun
->lun_se_dev
)
548 return core_alua_show_offline_bit(lun
, page
);
551 static ssize_t
target_fabric_port_alua_tg_pt_offline_store(
552 struct config_item
*item
, const char *page
, size_t count
)
554 struct se_lun
*lun
= item_to_lun(item
);
556 if (!lun
|| !lun
->lun_se_dev
)
559 return core_alua_store_offline_bit(lun
, page
, count
);
562 static ssize_t
target_fabric_port_alua_tg_pt_status_show(
563 struct config_item
*item
, char *page
)
565 struct se_lun
*lun
= item_to_lun(item
);
567 if (!lun
|| !lun
->lun_se_dev
)
570 return core_alua_show_secondary_status(lun
, page
);
573 static ssize_t
target_fabric_port_alua_tg_pt_status_store(
574 struct config_item
*item
, const char *page
, size_t count
)
576 struct se_lun
*lun
= item_to_lun(item
);
578 if (!lun
|| !lun
->lun_se_dev
)
581 return core_alua_store_secondary_status(lun
, page
, count
);
584 static ssize_t
target_fabric_port_alua_tg_pt_write_md_show(
585 struct config_item
*item
, char *page
)
587 struct se_lun
*lun
= item_to_lun(item
);
589 if (!lun
|| !lun
->lun_se_dev
)
592 return core_alua_show_secondary_write_metadata(lun
, page
);
595 static ssize_t
target_fabric_port_alua_tg_pt_write_md_store(
596 struct config_item
*item
, const char *page
, size_t count
)
598 struct se_lun
*lun
= item_to_lun(item
);
600 if (!lun
|| !lun
->lun_se_dev
)
603 return core_alua_store_secondary_write_metadata(lun
, page
, count
);
606 CONFIGFS_ATTR(target_fabric_port_
, alua_tg_pt_gp
);
607 CONFIGFS_ATTR(target_fabric_port_
, alua_tg_pt_offline
);
608 CONFIGFS_ATTR(target_fabric_port_
, alua_tg_pt_status
);
609 CONFIGFS_ATTR(target_fabric_port_
, alua_tg_pt_write_md
);
611 static struct configfs_attribute
*target_fabric_port_attrs
[] = {
612 &target_fabric_port_attr_alua_tg_pt_gp
,
613 &target_fabric_port_attr_alua_tg_pt_offline
,
614 &target_fabric_port_attr_alua_tg_pt_status
,
615 &target_fabric_port_attr_alua_tg_pt_write_md
,
619 static int target_fabric_port_link(
620 struct config_item
*lun_ci
,
621 struct config_item
*se_dev_ci
)
623 struct config_item
*tpg_ci
;
624 struct se_lun
*lun
= container_of(to_config_group(lun_ci
),
625 struct se_lun
, lun_group
);
626 struct se_portal_group
*se_tpg
;
627 struct se_device
*dev
;
628 struct target_fabric_configfs
*tf
;
631 if (!se_dev_ci
->ci_type
||
632 se_dev_ci
->ci_type
->ct_item_ops
!= &target_core_dev_item_ops
) {
633 pr_err("Bad se_dev_ci, not a valid se_dev_ci pointer: %p\n", se_dev_ci
);
636 dev
= container_of(to_config_group(se_dev_ci
), struct se_device
, dev_group
);
638 if (!target_dev_configured(dev
)) {
639 pr_err("se_device not configured yet, cannot port link\n");
643 tpg_ci
= &lun_ci
->ci_parent
->ci_group
->cg_item
;
644 se_tpg
= container_of(to_config_group(tpg_ci
),
645 struct se_portal_group
, tpg_group
);
646 tf
= se_tpg
->se_tpg_wwn
->wwn_tf
;
648 if (lun
->lun_se_dev
!= NULL
) {
649 pr_err("Port Symlink already exists\n");
653 ret
= core_dev_add_lun(se_tpg
, dev
, lun
);
655 pr_err("core_dev_add_lun() failed: %d\n", ret
);
659 if (tf
->tf_ops
->fabric_post_link
) {
661 * Call the optional fabric_post_link() to allow a
662 * fabric module to setup any additional state once
663 * core_dev_add_lun() has been called..
665 tf
->tf_ops
->fabric_post_link(se_tpg
, lun
);
673 static void target_fabric_port_unlink(
674 struct config_item
*lun_ci
,
675 struct config_item
*se_dev_ci
)
677 struct se_lun
*lun
= container_of(to_config_group(lun_ci
),
678 struct se_lun
, lun_group
);
679 struct se_portal_group
*se_tpg
= lun
->lun_tpg
;
680 struct target_fabric_configfs
*tf
= se_tpg
->se_tpg_wwn
->wwn_tf
;
682 if (tf
->tf_ops
->fabric_pre_unlink
) {
684 * Call the optional fabric_pre_unlink() to allow a
685 * fabric module to release any additional stat before
686 * core_dev_del_lun() is called.
688 tf
->tf_ops
->fabric_pre_unlink(se_tpg
, lun
);
691 core_dev_del_lun(se_tpg
, lun
);
694 static void target_fabric_port_release(struct config_item
*item
)
696 struct se_lun
*lun
= container_of(to_config_group(item
),
697 struct se_lun
, lun_group
);
699 kfree_rcu(lun
, rcu_head
);
702 static struct configfs_item_operations target_fabric_port_item_ops
= {
703 .release
= target_fabric_port_release
,
704 .allow_link
= target_fabric_port_link
,
705 .drop_link
= target_fabric_port_unlink
,
708 TF_CIT_SETUP(tpg_port
, &target_fabric_port_item_ops
, NULL
, target_fabric_port_attrs
);
710 /* End of tfc_tpg_port_cit */
712 /* Start of tfc_tpg_port_stat_cit */
714 static struct config_group
*target_core_port_stat_mkdir(
715 struct config_group
*group
,
718 return ERR_PTR(-ENOSYS
);
721 static void target_core_port_stat_rmdir(
722 struct config_group
*group
,
723 struct config_item
*item
)
728 static struct configfs_group_operations target_fabric_port_stat_group_ops
= {
729 .make_group
= target_core_port_stat_mkdir
,
730 .drop_item
= target_core_port_stat_rmdir
,
733 TF_CIT_SETUP(tpg_port_stat
, NULL
, &target_fabric_port_stat_group_ops
, NULL
);
735 /* End of tfc_tpg_port_stat_cit */
737 /* Start of tfc_tpg_lun_cit */
739 static struct config_group
*target_fabric_make_lun(
740 struct config_group
*group
,
744 struct se_portal_group
*se_tpg
= container_of(group
,
745 struct se_portal_group
, tpg_lun_group
);
746 struct target_fabric_configfs
*tf
= se_tpg
->se_tpg_wwn
->wwn_tf
;
747 unsigned long long unpacked_lun
;
750 if (strstr(name
, "lun_") != name
) {
751 pr_err("Unable to locate \'_\" in"
752 " \"lun_$LUN_NUMBER\"\n");
753 return ERR_PTR(-EINVAL
);
755 errno
= kstrtoull(name
+ 4, 0, &unpacked_lun
);
757 return ERR_PTR(errno
);
759 lun
= core_tpg_alloc_lun(se_tpg
, unpacked_lun
);
761 return ERR_CAST(lun
);
763 config_group_init_type_name(&lun
->lun_group
, name
,
764 &tf
->tf_tpg_port_cit
);
766 config_group_init_type_name(&lun
->port_stat_grps
.stat_group
,
767 "statistics", &tf
->tf_tpg_port_stat_cit
);
768 configfs_add_default_group(&lun
->port_stat_grps
.stat_group
,
771 target_stat_setup_port_default_groups(lun
);
773 return &lun
->lun_group
;
776 static void target_fabric_drop_lun(
777 struct config_group
*group
,
778 struct config_item
*item
)
780 struct se_lun
*lun
= container_of(to_config_group(item
),
781 struct se_lun
, lun_group
);
783 configfs_remove_default_groups(&lun
->port_stat_grps
.stat_group
);
784 configfs_remove_default_groups(&lun
->lun_group
);
786 config_item_put(item
);
789 static struct configfs_group_operations target_fabric_lun_group_ops
= {
790 .make_group
= &target_fabric_make_lun
,
791 .drop_item
= &target_fabric_drop_lun
,
794 TF_CIT_SETUP(tpg_lun
, NULL
, &target_fabric_lun_group_ops
, NULL
);
796 /* End of tfc_tpg_lun_cit */
798 TF_CIT_SETUP_DRV(tpg_attrib
, NULL
, NULL
);
799 TF_CIT_SETUP_DRV(tpg_auth
, NULL
, NULL
);
800 TF_CIT_SETUP_DRV(tpg_param
, NULL
, NULL
);
802 /* Start of tfc_tpg_base_cit */
804 static void target_fabric_tpg_release(struct config_item
*item
)
806 struct se_portal_group
*se_tpg
= container_of(to_config_group(item
),
807 struct se_portal_group
, tpg_group
);
808 struct se_wwn
*wwn
= se_tpg
->se_tpg_wwn
;
809 struct target_fabric_configfs
*tf
= wwn
->wwn_tf
;
811 tf
->tf_ops
->fabric_drop_tpg(se_tpg
);
814 static struct configfs_item_operations target_fabric_tpg_base_item_ops
= {
815 .release
= target_fabric_tpg_release
,
818 TF_CIT_SETUP_DRV(tpg_base
, &target_fabric_tpg_base_item_ops
, NULL
);
820 /* End of tfc_tpg_base_cit */
822 /* Start of tfc_tpg_cit */
824 static struct config_group
*target_fabric_make_tpg(
825 struct config_group
*group
,
828 struct se_wwn
*wwn
= container_of(group
, struct se_wwn
, wwn_group
);
829 struct target_fabric_configfs
*tf
= wwn
->wwn_tf
;
830 struct se_portal_group
*se_tpg
;
832 if (!tf
->tf_ops
->fabric_make_tpg
) {
833 pr_err("tf->tf_ops->fabric_make_tpg is NULL\n");
834 return ERR_PTR(-ENOSYS
);
837 se_tpg
= tf
->tf_ops
->fabric_make_tpg(wwn
, name
);
838 if (!se_tpg
|| IS_ERR(se_tpg
))
839 return ERR_PTR(-EINVAL
);
841 config_group_init_type_name(&se_tpg
->tpg_group
, name
,
842 &tf
->tf_tpg_base_cit
);
844 config_group_init_type_name(&se_tpg
->tpg_lun_group
, "lun",
845 &tf
->tf_tpg_lun_cit
);
846 configfs_add_default_group(&se_tpg
->tpg_lun_group
,
849 config_group_init_type_name(&se_tpg
->tpg_np_group
, "np",
851 configfs_add_default_group(&se_tpg
->tpg_np_group
,
854 config_group_init_type_name(&se_tpg
->tpg_acl_group
, "acls",
855 &tf
->tf_tpg_nacl_cit
);
856 configfs_add_default_group(&se_tpg
->tpg_acl_group
,
859 config_group_init_type_name(&se_tpg
->tpg_attrib_group
, "attrib",
860 &tf
->tf_tpg_attrib_cit
);
861 configfs_add_default_group(&se_tpg
->tpg_attrib_group
,
864 config_group_init_type_name(&se_tpg
->tpg_auth_group
, "auth",
865 &tf
->tf_tpg_auth_cit
);
866 configfs_add_default_group(&se_tpg
->tpg_auth_group
,
869 config_group_init_type_name(&se_tpg
->tpg_param_group
, "param",
870 &tf
->tf_tpg_param_cit
);
871 configfs_add_default_group(&se_tpg
->tpg_param_group
,
874 return &se_tpg
->tpg_group
;
877 static void target_fabric_drop_tpg(
878 struct config_group
*group
,
879 struct config_item
*item
)
881 struct se_portal_group
*se_tpg
= container_of(to_config_group(item
),
882 struct se_portal_group
, tpg_group
);
884 configfs_remove_default_groups(&se_tpg
->tpg_group
);
885 config_item_put(item
);
888 static void target_fabric_release_wwn(struct config_item
*item
)
890 struct se_wwn
*wwn
= container_of(to_config_group(item
),
891 struct se_wwn
, wwn_group
);
892 struct target_fabric_configfs
*tf
= wwn
->wwn_tf
;
894 configfs_remove_default_groups(&wwn
->fabric_stat_group
);
895 tf
->tf_ops
->fabric_drop_wwn(wwn
);
898 static struct configfs_item_operations target_fabric_tpg_item_ops
= {
899 .release
= target_fabric_release_wwn
,
902 static struct configfs_group_operations target_fabric_tpg_group_ops
= {
903 .make_group
= target_fabric_make_tpg
,
904 .drop_item
= target_fabric_drop_tpg
,
907 TF_CIT_SETUP(tpg
, &target_fabric_tpg_item_ops
, &target_fabric_tpg_group_ops
,
910 /* End of tfc_tpg_cit */
912 /* Start of tfc_wwn_fabric_stats_cit */
914 * This is used as a placeholder for struct se_wwn->fabric_stat_group
915 * to allow fabrics access to ->fabric_stat_group->default_groups[]
917 TF_CIT_SETUP(wwn_fabric_stats
, NULL
, NULL
, NULL
);
919 /* End of tfc_wwn_fabric_stats_cit */
921 /* Start of tfc_wwn_cit */
923 static struct config_group
*target_fabric_make_wwn(
924 struct config_group
*group
,
927 struct target_fabric_configfs
*tf
= container_of(group
,
928 struct target_fabric_configfs
, tf_group
);
931 if (!tf
->tf_ops
->fabric_make_wwn
) {
932 pr_err("tf->tf_ops.fabric_make_wwn is NULL\n");
933 return ERR_PTR(-ENOSYS
);
936 wwn
= tf
->tf_ops
->fabric_make_wwn(tf
, group
, name
);
937 if (!wwn
|| IS_ERR(wwn
))
938 return ERR_PTR(-EINVAL
);
942 config_group_init_type_name(&wwn
->wwn_group
, name
, &tf
->tf_tpg_cit
);
944 config_group_init_type_name(&wwn
->fabric_stat_group
, "fabric_statistics",
945 &tf
->tf_wwn_fabric_stats_cit
);
946 configfs_add_default_group(&wwn
->fabric_stat_group
, &wwn
->wwn_group
);
948 if (tf
->tf_ops
->add_wwn_groups
)
949 tf
->tf_ops
->add_wwn_groups(wwn
);
950 return &wwn
->wwn_group
;
953 static void target_fabric_drop_wwn(
954 struct config_group
*group
,
955 struct config_item
*item
)
957 struct se_wwn
*wwn
= container_of(to_config_group(item
),
958 struct se_wwn
, wwn_group
);
960 configfs_remove_default_groups(&wwn
->wwn_group
);
961 config_item_put(item
);
964 static struct configfs_group_operations target_fabric_wwn_group_ops
= {
965 .make_group
= target_fabric_make_wwn
,
966 .drop_item
= target_fabric_drop_wwn
,
969 TF_CIT_SETUP_DRV(wwn
, NULL
, &target_fabric_wwn_group_ops
);
970 TF_CIT_SETUP_DRV(discovery
, NULL
, NULL
);
972 int target_fabric_setup_cits(struct target_fabric_configfs
*tf
)
974 target_fabric_setup_discovery_cit(tf
);
975 target_fabric_setup_wwn_cit(tf
);
976 target_fabric_setup_wwn_fabric_stats_cit(tf
);
977 target_fabric_setup_tpg_cit(tf
);
978 target_fabric_setup_tpg_base_cit(tf
);
979 target_fabric_setup_tpg_port_cit(tf
);
980 target_fabric_setup_tpg_port_stat_cit(tf
);
981 target_fabric_setup_tpg_lun_cit(tf
);
982 target_fabric_setup_tpg_np_cit(tf
);
983 target_fabric_setup_tpg_np_base_cit(tf
);
984 target_fabric_setup_tpg_attrib_cit(tf
);
985 target_fabric_setup_tpg_auth_cit(tf
);
986 target_fabric_setup_tpg_param_cit(tf
);
987 target_fabric_setup_tpg_nacl_cit(tf
);
988 target_fabric_setup_tpg_nacl_base_cit(tf
);
989 target_fabric_setup_tpg_nacl_attrib_cit(tf
);
990 target_fabric_setup_tpg_nacl_auth_cit(tf
);
991 target_fabric_setup_tpg_nacl_param_cit(tf
);
992 target_fabric_setup_tpg_nacl_stat_cit(tf
);
993 target_fabric_setup_tpg_mappedlun_cit(tf
);
994 target_fabric_setup_tpg_mappedlun_stat_cit(tf
);