1 /*******************************************************************************
2 * Filename: target_core_configfs.c
4 * This file contains ConfigFS logic for the Generic Target Engine project.
6 * Copyright (c) 2008-2011 Rising Tide Systems
7 * Copyright (c) 2008-2011 Linux-iSCSI.org
9 * Nicholas A. Bellinger <nab@kernel.org>
11 * based on configfs Copyright (C) 2005 Oracle. All rights reserved.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 ****************************************************************************/
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <generated/utsrelease.h>
27 #include <linux/utsname.h>
28 #include <linux/init.h>
30 #include <linux/namei.h>
31 #include <linux/slab.h>
32 #include <linux/types.h>
33 #include <linux/delay.h>
34 #include <linux/unistd.h>
35 #include <linux/string.h>
36 #include <linux/parser.h>
37 #include <linux/syscalls.h>
38 #include <linux/configfs.h>
39 #include <linux/spinlock.h>
41 #include <target/target_core_base.h>
42 #include <target/target_core_backend.h>
43 #include <target/target_core_fabric.h>
44 #include <target/target_core_fabric_configfs.h>
45 #include <target/target_core_configfs.h>
46 #include <target/configfs_macros.h>
48 #include "target_core_internal.h"
49 #include "target_core_alua.h"
50 #include "target_core_pr.h"
51 #include "target_core_rd.h"
53 extern struct t10_alua_lu_gp
*default_lu_gp
;
55 static LIST_HEAD(g_tf_list
);
56 static DEFINE_MUTEX(g_tf_lock
);
58 struct target_core_configfs_attribute
{
59 struct configfs_attribute attr
;
60 ssize_t (*show
)(void *, char *);
61 ssize_t (*store
)(void *, const char *, size_t);
64 static struct config_group target_core_hbagroup
;
65 static struct config_group alua_group
;
66 static struct config_group alua_lu_gps_group
;
68 static inline struct se_hba
*
69 item_to_hba(struct config_item
*item
)
71 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
75 * Attributes for /sys/kernel/config/target/
77 static ssize_t
target_core_attr_show(struct config_item
*item
,
78 struct configfs_attribute
*attr
,
81 return sprintf(page
, "Target Engine Core ConfigFS Infrastructure %s"
82 " on %s/%s on "UTS_RELEASE
"\n", TARGET_CORE_CONFIGFS_VERSION
,
83 utsname()->sysname
, utsname()->machine
);
86 static struct configfs_item_operations target_core_fabric_item_ops
= {
87 .show_attribute
= target_core_attr_show
,
90 static struct configfs_attribute target_core_item_attr_version
= {
91 .ca_owner
= THIS_MODULE
,
96 static struct target_fabric_configfs
*target_core_get_fabric(
99 struct target_fabric_configfs
*tf
;
104 mutex_lock(&g_tf_lock
);
105 list_for_each_entry(tf
, &g_tf_list
, tf_list
) {
106 if (!strcmp(tf
->tf_name
, name
)) {
107 atomic_inc(&tf
->tf_access_cnt
);
108 mutex_unlock(&g_tf_lock
);
112 mutex_unlock(&g_tf_lock
);
118 * Called from struct target_core_group_ops->make_group()
120 static struct config_group
*target_core_register_fabric(
121 struct config_group
*group
,
124 struct target_fabric_configfs
*tf
;
127 pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:"
128 " %s\n", group
, name
);
130 * Below are some hardcoded request_module() calls to automatically
131 * local fabric modules when the following is called:
133 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
135 * Note that this does not limit which TCM fabric module can be
136 * registered, but simply provids auto loading logic for modules with
137 * mkdir(2) system calls with known TCM fabric modules.
139 if (!strncmp(name
, "iscsi", 5)) {
141 * Automatically load the LIO Target fabric module when the
142 * following is called:
144 * mkdir -p $CONFIGFS/target/iscsi
146 ret
= request_module("iscsi_target_mod");
148 pr_err("request_module() failed for"
149 " iscsi_target_mod.ko: %d\n", ret
);
150 return ERR_PTR(-EINVAL
);
152 } else if (!strncmp(name
, "loopback", 8)) {
154 * Automatically load the tcm_loop fabric module when the
155 * following is called:
157 * mkdir -p $CONFIGFS/target/loopback
159 ret
= request_module("tcm_loop");
161 pr_err("request_module() failed for"
162 " tcm_loop.ko: %d\n", ret
);
163 return ERR_PTR(-EINVAL
);
167 tf
= target_core_get_fabric(name
);
169 pr_err("target_core_get_fabric() failed for %s\n",
171 return ERR_PTR(-EINVAL
);
173 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
174 " %s\n", tf
->tf_name
);
176 * On a successful target_core_get_fabric() look, the returned
177 * struct target_fabric_configfs *tf will contain a usage reference.
179 pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
180 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
182 tf
->tf_group
.default_groups
= tf
->tf_default_groups
;
183 tf
->tf_group
.default_groups
[0] = &tf
->tf_disc_group
;
184 tf
->tf_group
.default_groups
[1] = NULL
;
186 config_group_init_type_name(&tf
->tf_group
, name
,
187 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
188 config_group_init_type_name(&tf
->tf_disc_group
, "discovery_auth",
189 &TF_CIT_TMPL(tf
)->tfc_discovery_cit
);
191 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
192 " %s\n", tf
->tf_group
.cg_item
.ci_name
);
194 * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item()
196 tf
->tf_ops
.tf_subsys
= tf
->tf_subsys
;
197 tf
->tf_fabric
= &tf
->tf_group
.cg_item
;
198 pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
201 return &tf
->tf_group
;
205 * Called from struct target_core_group_ops->drop_item()
207 static void target_core_deregister_fabric(
208 struct config_group
*group
,
209 struct config_item
*item
)
211 struct target_fabric_configfs
*tf
= container_of(
212 to_config_group(item
), struct target_fabric_configfs
, tf_group
);
213 struct config_group
*tf_group
;
214 struct config_item
*df_item
;
217 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
218 " tf list\n", config_item_name(item
));
220 pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:"
221 " %s\n", tf
->tf_name
);
222 atomic_dec(&tf
->tf_access_cnt
);
224 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing"
225 " tf->tf_fabric for %s\n", tf
->tf_name
);
226 tf
->tf_fabric
= NULL
;
228 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
229 " %s\n", config_item_name(item
));
231 tf_group
= &tf
->tf_group
;
232 for (i
= 0; tf_group
->default_groups
[i
]; i
++) {
233 df_item
= &tf_group
->default_groups
[i
]->cg_item
;
234 tf_group
->default_groups
[i
] = NULL
;
235 config_item_put(df_item
);
237 config_item_put(item
);
240 static struct configfs_group_operations target_core_fabric_group_ops
= {
241 .make_group
= &target_core_register_fabric
,
242 .drop_item
= &target_core_deregister_fabric
,
246 * All item attributes appearing in /sys/kernel/target/ appear here.
248 static struct configfs_attribute
*target_core_fabric_item_attrs
[] = {
249 &target_core_item_attr_version
,
254 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
256 static struct config_item_type target_core_fabrics_item
= {
257 .ct_item_ops
= &target_core_fabric_item_ops
,
258 .ct_group_ops
= &target_core_fabric_group_ops
,
259 .ct_attrs
= target_core_fabric_item_attrs
,
260 .ct_owner
= THIS_MODULE
,
263 static struct configfs_subsystem target_core_fabrics
= {
266 .ci_namebuf
= "target",
267 .ci_type
= &target_core_fabrics_item
,
272 static struct configfs_subsystem
*target_core_subsystem
[] = {
273 &target_core_fabrics
,
277 /*##############################################################################
278 // Start functions called by external Target Fabrics Modules
279 //############################################################################*/
282 * First function called by fabric modules to:
284 * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer.
285 * 2) Add struct target_fabric_configfs to g_tf_list
286 * 3) Return struct target_fabric_configfs to fabric module to be passed
287 * into target_fabric_configfs_register().
289 struct target_fabric_configfs
*target_fabric_configfs_init(
290 struct module
*fabric_mod
,
293 struct target_fabric_configfs
*tf
;
296 pr_err("Unable to locate passed fabric name\n");
297 return ERR_PTR(-EINVAL
);
299 if (strlen(name
) >= TARGET_FABRIC_NAME_SIZE
) {
300 pr_err("Passed name: %s exceeds TARGET_FABRIC"
301 "_NAME_SIZE\n", name
);
302 return ERR_PTR(-EINVAL
);
305 tf
= kzalloc(sizeof(struct target_fabric_configfs
), GFP_KERNEL
);
307 return ERR_PTR(-ENOMEM
);
309 INIT_LIST_HEAD(&tf
->tf_list
);
310 atomic_set(&tf
->tf_access_cnt
, 0);
312 * Setup the default generic struct config_item_type's (cits) in
313 * struct target_fabric_configfs->tf_cit_tmpl
315 tf
->tf_module
= fabric_mod
;
316 target_fabric_setup_cits(tf
);
318 tf
->tf_subsys
= target_core_subsystem
[0];
319 snprintf(tf
->tf_name
, TARGET_FABRIC_NAME_SIZE
, "%s", name
);
321 mutex_lock(&g_tf_lock
);
322 list_add_tail(&tf
->tf_list
, &g_tf_list
);
323 mutex_unlock(&g_tf_lock
);
325 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>"
327 pr_debug("Initialized struct target_fabric_configfs: %p for"
328 " %s\n", tf
, tf
->tf_name
);
331 EXPORT_SYMBOL(target_fabric_configfs_init
);
334 * Called by fabric plugins after FAILED target_fabric_configfs_register() call.
336 void target_fabric_configfs_free(
337 struct target_fabric_configfs
*tf
)
339 mutex_lock(&g_tf_lock
);
340 list_del(&tf
->tf_list
);
341 mutex_unlock(&g_tf_lock
);
345 EXPORT_SYMBOL(target_fabric_configfs_free
);
348 * Perform a sanity check of the passed tf->tf_ops before completing
349 * TCM fabric module registration.
351 static int target_fabric_tf_ops_check(
352 struct target_fabric_configfs
*tf
)
354 struct target_core_fabric_ops
*tfo
= &tf
->tf_ops
;
356 if (!tfo
->get_fabric_name
) {
357 pr_err("Missing tfo->get_fabric_name()\n");
360 if (!tfo
->get_fabric_proto_ident
) {
361 pr_err("Missing tfo->get_fabric_proto_ident()\n");
364 if (!tfo
->tpg_get_wwn
) {
365 pr_err("Missing tfo->tpg_get_wwn()\n");
368 if (!tfo
->tpg_get_tag
) {
369 pr_err("Missing tfo->tpg_get_tag()\n");
372 if (!tfo
->tpg_get_default_depth
) {
373 pr_err("Missing tfo->tpg_get_default_depth()\n");
376 if (!tfo
->tpg_get_pr_transport_id
) {
377 pr_err("Missing tfo->tpg_get_pr_transport_id()\n");
380 if (!tfo
->tpg_get_pr_transport_id_len
) {
381 pr_err("Missing tfo->tpg_get_pr_transport_id_len()\n");
384 if (!tfo
->tpg_check_demo_mode
) {
385 pr_err("Missing tfo->tpg_check_demo_mode()\n");
388 if (!tfo
->tpg_check_demo_mode_cache
) {
389 pr_err("Missing tfo->tpg_check_demo_mode_cache()\n");
392 if (!tfo
->tpg_check_demo_mode_write_protect
) {
393 pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n");
396 if (!tfo
->tpg_check_prod_mode_write_protect
) {
397 pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n");
400 if (!tfo
->tpg_alloc_fabric_acl
) {
401 pr_err("Missing tfo->tpg_alloc_fabric_acl()\n");
404 if (!tfo
->tpg_release_fabric_acl
) {
405 pr_err("Missing tfo->tpg_release_fabric_acl()\n");
408 if (!tfo
->tpg_get_inst_index
) {
409 pr_err("Missing tfo->tpg_get_inst_index()\n");
412 if (!tfo
->release_cmd
) {
413 pr_err("Missing tfo->release_cmd()\n");
416 if (!tfo
->shutdown_session
) {
417 pr_err("Missing tfo->shutdown_session()\n");
420 if (!tfo
->close_session
) {
421 pr_err("Missing tfo->close_session()\n");
424 if (!tfo
->sess_get_index
) {
425 pr_err("Missing tfo->sess_get_index()\n");
428 if (!tfo
->write_pending
) {
429 pr_err("Missing tfo->write_pending()\n");
432 if (!tfo
->write_pending_status
) {
433 pr_err("Missing tfo->write_pending_status()\n");
436 if (!tfo
->set_default_node_attributes
) {
437 pr_err("Missing tfo->set_default_node_attributes()\n");
440 if (!tfo
->get_task_tag
) {
441 pr_err("Missing tfo->get_task_tag()\n");
444 if (!tfo
->get_cmd_state
) {
445 pr_err("Missing tfo->get_cmd_state()\n");
448 if (!tfo
->queue_data_in
) {
449 pr_err("Missing tfo->queue_data_in()\n");
452 if (!tfo
->queue_status
) {
453 pr_err("Missing tfo->queue_status()\n");
456 if (!tfo
->queue_tm_rsp
) {
457 pr_err("Missing tfo->queue_tm_rsp()\n");
461 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
462 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
463 * target_core_fabric_configfs.c WWN+TPG group context code.
465 if (!tfo
->fabric_make_wwn
) {
466 pr_err("Missing tfo->fabric_make_wwn()\n");
469 if (!tfo
->fabric_drop_wwn
) {
470 pr_err("Missing tfo->fabric_drop_wwn()\n");
473 if (!tfo
->fabric_make_tpg
) {
474 pr_err("Missing tfo->fabric_make_tpg()\n");
477 if (!tfo
->fabric_drop_tpg
) {
478 pr_err("Missing tfo->fabric_drop_tpg()\n");
486 * Called 2nd from fabric module with returned parameter of
487 * struct target_fabric_configfs * from target_fabric_configfs_init().
489 * Upon a successful registration, the new fabric's struct config_item is
490 * return. Also, a pointer to this struct is set in the passed
491 * struct target_fabric_configfs.
493 int target_fabric_configfs_register(
494 struct target_fabric_configfs
*tf
)
499 pr_err("Unable to locate target_fabric_configfs"
503 if (!tf
->tf_subsys
) {
504 pr_err("Unable to target struct config_subsystem"
508 ret
= target_fabric_tf_ops_check(tf
);
512 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>"
516 EXPORT_SYMBOL(target_fabric_configfs_register
);
518 void target_fabric_configfs_deregister(
519 struct target_fabric_configfs
*tf
)
521 struct configfs_subsystem
*su
;
524 pr_err("Unable to locate passed target_fabric_"
530 pr_err("Unable to locate passed tf->tf_subsys"
534 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
536 mutex_lock(&g_tf_lock
);
537 if (atomic_read(&tf
->tf_access_cnt
)) {
538 mutex_unlock(&g_tf_lock
);
539 pr_err("Non zero tf->tf_access_cnt for fabric %s\n",
543 list_del(&tf
->tf_list
);
544 mutex_unlock(&g_tf_lock
);
546 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
547 " %s\n", tf
->tf_name
);
548 tf
->tf_module
= NULL
;
549 tf
->tf_subsys
= NULL
;
552 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
555 EXPORT_SYMBOL(target_fabric_configfs_deregister
);
557 /*##############################################################################
558 // Stop functions called by external Target Fabrics Modules
559 //############################################################################*/
561 /* Start functions for struct config_item_type target_core_dev_attrib_cit */
563 #define DEF_DEV_ATTRIB_SHOW(_name) \
564 static ssize_t target_core_dev_show_attr_##_name( \
565 struct se_dev_attrib *da, \
568 return snprintf(page, PAGE_SIZE, "%u\n", \
569 (u32)da->da_dev->dev_attrib._name); \
572 #define DEF_DEV_ATTRIB_STORE(_name) \
573 static ssize_t target_core_dev_store_attr_##_name( \
574 struct se_dev_attrib *da, \
581 ret = strict_strtoul(page, 0, &val); \
583 pr_err("strict_strtoul() failed with" \
584 " ret: %d\n", ret); \
587 ret = se_dev_set_##_name(da->da_dev, (u32)val); \
589 return (!ret) ? count : -EINVAL; \
592 #define DEF_DEV_ATTRIB(_name) \
593 DEF_DEV_ATTRIB_SHOW(_name); \
594 DEF_DEV_ATTRIB_STORE(_name);
596 #define DEF_DEV_ATTRIB_RO(_name) \
597 DEF_DEV_ATTRIB_SHOW(_name);
599 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib
, se_dev_attrib
);
600 #define SE_DEV_ATTR(_name, _mode) \
601 static struct target_core_dev_attrib_attribute \
602 target_core_dev_attrib_##_name = \
603 __CONFIGFS_EATTR(_name, _mode, \
604 target_core_dev_show_attr_##_name, \
605 target_core_dev_store_attr_##_name);
607 #define SE_DEV_ATTR_RO(_name); \
608 static struct target_core_dev_attrib_attribute \
609 target_core_dev_attrib_##_name = \
610 __CONFIGFS_EATTR_RO(_name, \
611 target_core_dev_show_attr_##_name);
613 DEF_DEV_ATTRIB(emulate_dpo
);
614 SE_DEV_ATTR(emulate_dpo
, S_IRUGO
| S_IWUSR
);
616 DEF_DEV_ATTRIB(emulate_fua_write
);
617 SE_DEV_ATTR(emulate_fua_write
, S_IRUGO
| S_IWUSR
);
619 DEF_DEV_ATTRIB(emulate_fua_read
);
620 SE_DEV_ATTR(emulate_fua_read
, S_IRUGO
| S_IWUSR
);
622 DEF_DEV_ATTRIB(emulate_write_cache
);
623 SE_DEV_ATTR(emulate_write_cache
, S_IRUGO
| S_IWUSR
);
625 DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl
);
626 SE_DEV_ATTR(emulate_ua_intlck_ctrl
, S_IRUGO
| S_IWUSR
);
628 DEF_DEV_ATTRIB(emulate_tas
);
629 SE_DEV_ATTR(emulate_tas
, S_IRUGO
| S_IWUSR
);
631 DEF_DEV_ATTRIB(emulate_tpu
);
632 SE_DEV_ATTR(emulate_tpu
, S_IRUGO
| S_IWUSR
);
634 DEF_DEV_ATTRIB(emulate_tpws
);
635 SE_DEV_ATTR(emulate_tpws
, S_IRUGO
| S_IWUSR
);
637 DEF_DEV_ATTRIB(enforce_pr_isids
);
638 SE_DEV_ATTR(enforce_pr_isids
, S_IRUGO
| S_IWUSR
);
640 DEF_DEV_ATTRIB(is_nonrot
);
641 SE_DEV_ATTR(is_nonrot
, S_IRUGO
| S_IWUSR
);
643 DEF_DEV_ATTRIB(emulate_rest_reord
);
644 SE_DEV_ATTR(emulate_rest_reord
, S_IRUGO
| S_IWUSR
);
646 DEF_DEV_ATTRIB_RO(hw_block_size
);
647 SE_DEV_ATTR_RO(hw_block_size
);
649 DEF_DEV_ATTRIB(block_size
);
650 SE_DEV_ATTR(block_size
, S_IRUGO
| S_IWUSR
);
652 DEF_DEV_ATTRIB_RO(hw_max_sectors
);
653 SE_DEV_ATTR_RO(hw_max_sectors
);
655 DEF_DEV_ATTRIB(fabric_max_sectors
);
656 SE_DEV_ATTR(fabric_max_sectors
, S_IRUGO
| S_IWUSR
);
658 DEF_DEV_ATTRIB(optimal_sectors
);
659 SE_DEV_ATTR(optimal_sectors
, S_IRUGO
| S_IWUSR
);
661 DEF_DEV_ATTRIB_RO(hw_queue_depth
);
662 SE_DEV_ATTR_RO(hw_queue_depth
);
664 DEF_DEV_ATTRIB(queue_depth
);
665 SE_DEV_ATTR(queue_depth
, S_IRUGO
| S_IWUSR
);
667 DEF_DEV_ATTRIB(max_unmap_lba_count
);
668 SE_DEV_ATTR(max_unmap_lba_count
, S_IRUGO
| S_IWUSR
);
670 DEF_DEV_ATTRIB(max_unmap_block_desc_count
);
671 SE_DEV_ATTR(max_unmap_block_desc_count
, S_IRUGO
| S_IWUSR
);
673 DEF_DEV_ATTRIB(unmap_granularity
);
674 SE_DEV_ATTR(unmap_granularity
, S_IRUGO
| S_IWUSR
);
676 DEF_DEV_ATTRIB(unmap_granularity_alignment
);
677 SE_DEV_ATTR(unmap_granularity_alignment
, S_IRUGO
| S_IWUSR
);
679 CONFIGFS_EATTR_OPS(target_core_dev_attrib
, se_dev_attrib
, da_group
);
681 static struct configfs_attribute
*target_core_dev_attrib_attrs
[] = {
682 &target_core_dev_attrib_emulate_dpo
.attr
,
683 &target_core_dev_attrib_emulate_fua_write
.attr
,
684 &target_core_dev_attrib_emulate_fua_read
.attr
,
685 &target_core_dev_attrib_emulate_write_cache
.attr
,
686 &target_core_dev_attrib_emulate_ua_intlck_ctrl
.attr
,
687 &target_core_dev_attrib_emulate_tas
.attr
,
688 &target_core_dev_attrib_emulate_tpu
.attr
,
689 &target_core_dev_attrib_emulate_tpws
.attr
,
690 &target_core_dev_attrib_enforce_pr_isids
.attr
,
691 &target_core_dev_attrib_is_nonrot
.attr
,
692 &target_core_dev_attrib_emulate_rest_reord
.attr
,
693 &target_core_dev_attrib_hw_block_size
.attr
,
694 &target_core_dev_attrib_block_size
.attr
,
695 &target_core_dev_attrib_hw_max_sectors
.attr
,
696 &target_core_dev_attrib_fabric_max_sectors
.attr
,
697 &target_core_dev_attrib_optimal_sectors
.attr
,
698 &target_core_dev_attrib_hw_queue_depth
.attr
,
699 &target_core_dev_attrib_queue_depth
.attr
,
700 &target_core_dev_attrib_max_unmap_lba_count
.attr
,
701 &target_core_dev_attrib_max_unmap_block_desc_count
.attr
,
702 &target_core_dev_attrib_unmap_granularity
.attr
,
703 &target_core_dev_attrib_unmap_granularity_alignment
.attr
,
707 static struct configfs_item_operations target_core_dev_attrib_ops
= {
708 .show_attribute
= target_core_dev_attrib_attr_show
,
709 .store_attribute
= target_core_dev_attrib_attr_store
,
712 static struct config_item_type target_core_dev_attrib_cit
= {
713 .ct_item_ops
= &target_core_dev_attrib_ops
,
714 .ct_attrs
= target_core_dev_attrib_attrs
,
715 .ct_owner
= THIS_MODULE
,
718 /* End functions for struct config_item_type target_core_dev_attrib_cit */
720 /* Start functions for struct config_item_type target_core_dev_wwn_cit */
722 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn
, t10_wwn
);
723 #define SE_DEV_WWN_ATTR(_name, _mode) \
724 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
725 __CONFIGFS_EATTR(_name, _mode, \
726 target_core_dev_wwn_show_attr_##_name, \
727 target_core_dev_wwn_store_attr_##_name);
729 #define SE_DEV_WWN_ATTR_RO(_name); \
731 static struct target_core_dev_wwn_attribute \
732 target_core_dev_wwn_##_name = \
733 __CONFIGFS_EATTR_RO(_name, \
734 target_core_dev_wwn_show_attr_##_name); \
738 * VPD page 0x80 Unit serial
740 static ssize_t
target_core_dev_wwn_show_attr_vpd_unit_serial(
741 struct t10_wwn
*t10_wwn
,
744 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
745 &t10_wwn
->unit_serial
[0]);
748 static ssize_t
target_core_dev_wwn_store_attr_vpd_unit_serial(
749 struct t10_wwn
*t10_wwn
,
753 struct se_device
*dev
= t10_wwn
->t10_dev
;
754 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
757 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
758 * from the struct scsi_device level firmware, do not allow
759 * VPD Unit Serial to be emulated.
761 * Note this struct scsi_device could also be emulating VPD
762 * information from its drivers/scsi LLD. But for now we assume
763 * it is doing 'the right thing' wrt a world wide unique
764 * VPD Unit Serial Number that OS dependent multipath can depend on.
766 if (dev
->dev_flags
& DF_FIRMWARE_VPD_UNIT_SERIAL
) {
767 pr_err("Underlying SCSI device firmware provided VPD"
768 " Unit Serial, ignoring request\n");
772 if (strlen(page
) >= INQUIRY_VPD_SERIAL_LEN
) {
773 pr_err("Emulated VPD Unit Serial exceeds"
774 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
778 * Check to see if any active $FABRIC_MOD exports exist. If they
779 * do exist, fail here as changing this information on the fly
780 * (underneath the initiator side OS dependent multipath code)
781 * could cause negative effects.
783 if (dev
->export_count
) {
784 pr_err("Unable to set VPD Unit Serial while"
785 " active %d $FABRIC_MOD exports exist\n",
791 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
793 * Also, strip any newline added from the userspace
794 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
796 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
797 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
798 snprintf(dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
799 "%s", strstrip(buf
));
800 dev
->dev_flags
|= DF_EMULATED_VPD_UNIT_SERIAL
;
802 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
803 " %s\n", dev
->t10_wwn
.unit_serial
);
808 SE_DEV_WWN_ATTR(vpd_unit_serial
, S_IRUGO
| S_IWUSR
);
811 * VPD page 0x83 Protocol Identifier
813 static ssize_t
target_core_dev_wwn_show_attr_vpd_protocol_identifier(
814 struct t10_wwn
*t10_wwn
,
818 unsigned char buf
[VPD_TMP_BUF_SIZE
];
821 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
823 spin_lock(&t10_wwn
->t10_vpd_lock
);
824 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
825 if (!vpd
->protocol_identifier_set
)
828 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
830 if (len
+ strlen(buf
) >= PAGE_SIZE
)
833 len
+= sprintf(page
+len
, "%s", buf
);
835 spin_unlock(&t10_wwn
->t10_vpd_lock
);
840 static ssize_t
target_core_dev_wwn_store_attr_vpd_protocol_identifier(
841 struct t10_wwn
*t10_wwn
,
848 SE_DEV_WWN_ATTR(vpd_protocol_identifier
, S_IRUGO
| S_IWUSR
);
851 * Generic wrapper for dumping VPD identifiers by association.
853 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
854 static ssize_t target_core_dev_wwn_show_attr_##_name( \
855 struct t10_wwn *t10_wwn, \
858 struct t10_vpd *vpd; \
859 unsigned char buf[VPD_TMP_BUF_SIZE]; \
862 spin_lock(&t10_wwn->t10_vpd_lock); \
863 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
864 if (vpd->association != _assoc) \
867 memset(buf, 0, VPD_TMP_BUF_SIZE); \
868 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
869 if (len + strlen(buf) >= PAGE_SIZE) \
871 len += sprintf(page+len, "%s", buf); \
873 memset(buf, 0, VPD_TMP_BUF_SIZE); \
874 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
875 if (len + strlen(buf) >= PAGE_SIZE) \
877 len += sprintf(page+len, "%s", buf); \
879 memset(buf, 0, VPD_TMP_BUF_SIZE); \
880 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
881 if (len + strlen(buf) >= PAGE_SIZE) \
883 len += sprintf(page+len, "%s", buf); \
885 spin_unlock(&t10_wwn->t10_vpd_lock); \
891 * VPD page 0x83 Association: Logical Unit
893 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
895 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
896 struct t10_wwn
*t10_wwn
,
903 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit
, S_IRUGO
| S_IWUSR
);
906 * VPD page 0x83 Association: Target Port
908 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
910 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_target_port(
911 struct t10_wwn
*t10_wwn
,
918 SE_DEV_WWN_ATTR(vpd_assoc_target_port
, S_IRUGO
| S_IWUSR
);
921 * VPD page 0x83 Association: SCSI Target Device
923 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
925 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
926 struct t10_wwn
*t10_wwn
,
933 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device
, S_IRUGO
| S_IWUSR
);
935 CONFIGFS_EATTR_OPS(target_core_dev_wwn
, t10_wwn
, t10_wwn_group
);
937 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
938 &target_core_dev_wwn_vpd_unit_serial
.attr
,
939 &target_core_dev_wwn_vpd_protocol_identifier
.attr
,
940 &target_core_dev_wwn_vpd_assoc_logical_unit
.attr
,
941 &target_core_dev_wwn_vpd_assoc_target_port
.attr
,
942 &target_core_dev_wwn_vpd_assoc_scsi_target_device
.attr
,
946 static struct configfs_item_operations target_core_dev_wwn_ops
= {
947 .show_attribute
= target_core_dev_wwn_attr_show
,
948 .store_attribute
= target_core_dev_wwn_attr_store
,
951 static struct config_item_type target_core_dev_wwn_cit
= {
952 .ct_item_ops
= &target_core_dev_wwn_ops
,
953 .ct_attrs
= target_core_dev_wwn_attrs
,
954 .ct_owner
= THIS_MODULE
,
957 /* End functions for struct config_item_type target_core_dev_wwn_cit */
959 /* Start functions for struct config_item_type target_core_dev_pr_cit */
961 CONFIGFS_EATTR_STRUCT(target_core_dev_pr
, se_device
);
962 #define SE_DEV_PR_ATTR(_name, _mode) \
963 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
964 __CONFIGFS_EATTR(_name, _mode, \
965 target_core_dev_pr_show_attr_##_name, \
966 target_core_dev_pr_store_attr_##_name);
968 #define SE_DEV_PR_ATTR_RO(_name); \
969 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
970 __CONFIGFS_EATTR_RO(_name, \
971 target_core_dev_pr_show_attr_##_name);
973 static ssize_t
target_core_dev_pr_show_spc3_res(struct se_device
*dev
,
976 struct se_node_acl
*se_nacl
;
977 struct t10_pr_registration
*pr_reg
;
978 char i_buf
[PR_REG_ISID_ID_LEN
];
981 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
983 pr_reg
= dev
->dev_pr_res_holder
;
985 return sprintf(page
, "No SPC-3 Reservation holder\n");
987 se_nacl
= pr_reg
->pr_reg_nacl
;
988 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
991 return sprintf(page
, "SPC-3 Reservation: %s Initiator: %s%s\n",
992 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
993 se_nacl
->initiatorname
, (prf_isid
) ? &i_buf
[0] : "");
996 static ssize_t
target_core_dev_pr_show_spc2_res(struct se_device
*dev
,
999 struct se_node_acl
*se_nacl
;
1002 se_nacl
= dev
->dev_reserved_node_acl
;
1005 "SPC-2 Reservation: %s Initiator: %s\n",
1006 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1007 se_nacl
->initiatorname
);
1009 len
= sprintf(page
, "No SPC-2 Reservation holder\n");
1014 static ssize_t
target_core_dev_pr_show_attr_res_holder(struct se_device
*dev
,
1019 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1020 return sprintf(page
, "Passthrough\n");
1022 spin_lock(&dev
->dev_reservation_lock
);
1023 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1024 ret
= target_core_dev_pr_show_spc2_res(dev
, page
);
1026 ret
= target_core_dev_pr_show_spc3_res(dev
, page
);
1027 spin_unlock(&dev
->dev_reservation_lock
);
1031 SE_DEV_PR_ATTR_RO(res_holder
);
1033 static ssize_t
target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1034 struct se_device
*dev
, char *page
)
1038 spin_lock(&dev
->dev_reservation_lock
);
1039 if (!dev
->dev_pr_res_holder
) {
1040 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1041 } else if (dev
->dev_pr_res_holder
->pr_reg_all_tg_pt
) {
1042 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1043 " Ports registration\n");
1045 len
= sprintf(page
, "SPC-3 Reservation: Single"
1046 " Target Port registration\n");
1049 spin_unlock(&dev
->dev_reservation_lock
);
1053 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts
);
1055 static ssize_t
target_core_dev_pr_show_attr_res_pr_generation(
1056 struct se_device
*dev
, char *page
)
1058 return sprintf(page
, "0x%08x\n", dev
->t10_pr
.pr_generation
);
1061 SE_DEV_PR_ATTR_RO(res_pr_generation
);
1064 * res_pr_holder_tg_port
1066 static ssize_t
target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1067 struct se_device
*dev
, char *page
)
1069 struct se_node_acl
*se_nacl
;
1071 struct se_portal_group
*se_tpg
;
1072 struct t10_pr_registration
*pr_reg
;
1073 struct target_core_fabric_ops
*tfo
;
1076 spin_lock(&dev
->dev_reservation_lock
);
1077 pr_reg
= dev
->dev_pr_res_holder
;
1079 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1083 se_nacl
= pr_reg
->pr_reg_nacl
;
1084 se_tpg
= se_nacl
->se_tpg
;
1085 lun
= pr_reg
->pr_reg_tg_pt_lun
;
1086 tfo
= se_tpg
->se_tpg_tfo
;
1088 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1089 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1090 tfo
->tpg_get_wwn(se_tpg
));
1091 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1092 " Identifier Tag: %hu %s Portal Group Tag: %hu"
1093 " %s Logical Unit: %u\n", lun
->lun_sep
->sep_rtpi
,
1094 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1095 tfo
->get_fabric_name(), lun
->unpacked_lun
);
1098 spin_unlock(&dev
->dev_reservation_lock
);
1102 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port
);
1104 static ssize_t
target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1105 struct se_device
*dev
, char *page
)
1107 struct target_core_fabric_ops
*tfo
;
1108 struct t10_pr_registration
*pr_reg
;
1109 unsigned char buf
[384];
1110 char i_buf
[PR_REG_ISID_ID_LEN
];
1112 int reg_count
= 0, prf_isid
;
1114 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1116 spin_lock(&dev
->t10_pr
.registration_lock
);
1117 list_for_each_entry(pr_reg
, &dev
->t10_pr
.registration_list
,
1120 memset(buf
, 0, 384);
1121 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1122 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1123 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1124 PR_REG_ISID_ID_LEN
);
1125 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1126 tfo
->get_fabric_name(),
1127 pr_reg
->pr_reg_nacl
->initiatorname
, (prf_isid
) ?
1128 &i_buf
[0] : "", pr_reg
->pr_res_key
,
1129 pr_reg
->pr_res_generation
);
1131 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1134 len
+= sprintf(page
+len
, "%s", buf
);
1137 spin_unlock(&dev
->t10_pr
.registration_lock
);
1140 len
+= sprintf(page
+len
, "None\n");
1145 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts
);
1147 static ssize_t
target_core_dev_pr_show_attr_res_pr_type(
1148 struct se_device
*dev
, char *page
)
1150 struct t10_pr_registration
*pr_reg
;
1153 spin_lock(&dev
->dev_reservation_lock
);
1154 pr_reg
= dev
->dev_pr_res_holder
;
1156 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1157 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1159 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1162 spin_unlock(&dev
->dev_reservation_lock
);
1166 SE_DEV_PR_ATTR_RO(res_pr_type
);
1168 static ssize_t
target_core_dev_pr_show_attr_res_type(
1169 struct se_device
*dev
, char *page
)
1171 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1172 return sprintf(page
, "SPC_PASSTHROUGH\n");
1173 else if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1174 return sprintf(page
, "SPC2_RESERVATIONS\n");
1176 return sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1179 SE_DEV_PR_ATTR_RO(res_type
);
1181 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_active(
1182 struct se_device
*dev
, char *page
)
1184 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1187 return sprintf(page
, "APTPL Bit Status: %s\n",
1188 (dev
->t10_pr
.pr_aptpl_active
) ? "Activated" : "Disabled");
1191 SE_DEV_PR_ATTR_RO(res_aptpl_active
);
1194 * res_aptpl_metadata
1196 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_metadata(
1197 struct se_device
*dev
, char *page
)
1199 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1202 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1206 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1207 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1208 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1209 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1212 static match_table_t tokens
= {
1213 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1214 {Opt_initiator_node
, "initiator_node=%s"},
1215 {Opt_initiator_sid
, "initiator_sid=%s"},
1216 {Opt_sa_res_key
, "sa_res_key=%s"},
1217 {Opt_res_holder
, "res_holder=%d"},
1218 {Opt_res_type
, "res_type=%d"},
1219 {Opt_res_scope
, "res_scope=%d"},
1220 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1221 {Opt_mapped_lun
, "mapped_lun=%d"},
1222 {Opt_target_fabric
, "target_fabric=%s"},
1223 {Opt_target_node
, "target_node=%s"},
1224 {Opt_tpgt
, "tpgt=%d"},
1225 {Opt_port_rtpi
, "port_rtpi=%d"},
1226 {Opt_target_lun
, "target_lun=%d"},
1230 static ssize_t
target_core_dev_pr_store_attr_res_aptpl_metadata(
1231 struct se_device
*dev
,
1235 unsigned char *i_fabric
= NULL
, *i_port
= NULL
, *isid
= NULL
;
1236 unsigned char *t_fabric
= NULL
, *t_port
= NULL
;
1237 char *orig
, *ptr
, *arg_p
, *opts
;
1238 substring_t args
[MAX_OPT_ARGS
];
1239 unsigned long long tmp_ll
;
1241 u32 mapped_lun
= 0, target_lun
= 0;
1242 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1243 u16 port_rpti
= 0, tpgt
= 0;
1246 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1248 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1251 if (dev
->export_count
) {
1252 pr_debug("Unable to process APTPL metadata while"
1253 " active fabric exports exist\n");
1257 opts
= kstrdup(page
, GFP_KERNEL
);
1262 while ((ptr
= strsep(&opts
, ",\n")) != NULL
) {
1266 token
= match_token(ptr
, tokens
, args
);
1268 case Opt_initiator_fabric
:
1269 i_fabric
= match_strdup(&args
[0]);
1275 case Opt_initiator_node
:
1276 i_port
= match_strdup(&args
[0]);
1281 if (strlen(i_port
) >= PR_APTPL_MAX_IPORT_LEN
) {
1282 pr_err("APTPL metadata initiator_node="
1283 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1284 PR_APTPL_MAX_IPORT_LEN
);
1289 case Opt_initiator_sid
:
1290 isid
= match_strdup(&args
[0]);
1295 if (strlen(isid
) >= PR_REG_ISID_LEN
) {
1296 pr_err("APTPL metadata initiator_isid"
1297 "= exceeds PR_REG_ISID_LEN: %d\n",
1303 case Opt_sa_res_key
:
1304 arg_p
= match_strdup(&args
[0]);
1309 ret
= strict_strtoull(arg_p
, 0, &tmp_ll
);
1311 pr_err("strict_strtoull() failed for"
1315 sa_res_key
= (u64
)tmp_ll
;
1318 * PR APTPL Metadata for Reservation
1320 case Opt_res_holder
:
1321 match_int(args
, &arg
);
1325 match_int(args
, &arg
);
1329 match_int(args
, &arg
);
1332 case Opt_res_all_tg_pt
:
1333 match_int(args
, &arg
);
1334 all_tg_pt
= (int)arg
;
1336 case Opt_mapped_lun
:
1337 match_int(args
, &arg
);
1338 mapped_lun
= (u32
)arg
;
1341 * PR APTPL Metadata for Target Port
1343 case Opt_target_fabric
:
1344 t_fabric
= match_strdup(&args
[0]);
1350 case Opt_target_node
:
1351 t_port
= match_strdup(&args
[0]);
1356 if (strlen(t_port
) >= PR_APTPL_MAX_TPORT_LEN
) {
1357 pr_err("APTPL metadata target_node="
1358 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1359 PR_APTPL_MAX_TPORT_LEN
);
1365 match_int(args
, &arg
);
1369 match_int(args
, &arg
);
1370 port_rpti
= (u16
)arg
;
1372 case Opt_target_lun
:
1373 match_int(args
, &arg
);
1374 target_lun
= (u32
)arg
;
1381 if (!i_port
|| !t_port
|| !sa_res_key
) {
1382 pr_err("Illegal parameters for APTPL registration\n");
1387 if (res_holder
&& !(type
)) {
1388 pr_err("Illegal PR type: 0x%02x for reservation"
1394 ret
= core_scsi3_alloc_aptpl_registration(&dev
->t10_pr
, sa_res_key
,
1395 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1396 res_holder
, all_tg_pt
, type
);
1404 return (ret
== 0) ? count
: ret
;
1407 SE_DEV_PR_ATTR(res_aptpl_metadata
, S_IRUGO
| S_IWUSR
);
1409 CONFIGFS_EATTR_OPS(target_core_dev_pr
, se_device
, dev_pr_group
);
1411 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1412 &target_core_dev_pr_res_holder
.attr
,
1413 &target_core_dev_pr_res_pr_all_tgt_pts
.attr
,
1414 &target_core_dev_pr_res_pr_generation
.attr
,
1415 &target_core_dev_pr_res_pr_holder_tg_port
.attr
,
1416 &target_core_dev_pr_res_pr_registered_i_pts
.attr
,
1417 &target_core_dev_pr_res_pr_type
.attr
,
1418 &target_core_dev_pr_res_type
.attr
,
1419 &target_core_dev_pr_res_aptpl_active
.attr
,
1420 &target_core_dev_pr_res_aptpl_metadata
.attr
,
1424 static struct configfs_item_operations target_core_dev_pr_ops
= {
1425 .show_attribute
= target_core_dev_pr_attr_show
,
1426 .store_attribute
= target_core_dev_pr_attr_store
,
1429 static struct config_item_type target_core_dev_pr_cit
= {
1430 .ct_item_ops
= &target_core_dev_pr_ops
,
1431 .ct_attrs
= target_core_dev_pr_attrs
,
1432 .ct_owner
= THIS_MODULE
,
1435 /* End functions for struct config_item_type target_core_dev_pr_cit */
1437 /* Start functions for struct config_item_type target_core_dev_cit */
1439 static ssize_t
target_core_show_dev_info(void *p
, char *page
)
1441 struct se_device
*dev
= p
;
1442 struct se_subsystem_api
*t
= dev
->transport
;
1444 ssize_t read_bytes
= 0;
1446 transport_dump_dev_state(dev
, page
, &bl
);
1448 read_bytes
+= t
->show_configfs_dev_params(dev
, page
+read_bytes
);
1452 static struct target_core_configfs_attribute target_core_attr_dev_info
= {
1453 .attr
= { .ca_owner
= THIS_MODULE
,
1455 .ca_mode
= S_IRUGO
},
1456 .show
= target_core_show_dev_info
,
1460 static ssize_t
target_core_store_dev_control(
1465 struct se_device
*dev
= p
;
1466 struct se_subsystem_api
*t
= dev
->transport
;
1468 return t
->set_configfs_dev_params(dev
, page
, count
);
1471 static struct target_core_configfs_attribute target_core_attr_dev_control
= {
1472 .attr
= { .ca_owner
= THIS_MODULE
,
1473 .ca_name
= "control",
1474 .ca_mode
= S_IWUSR
},
1476 .store
= target_core_store_dev_control
,
1479 static ssize_t
target_core_show_dev_alias(void *p
, char *page
)
1481 struct se_device
*dev
= p
;
1483 if (!(dev
->dev_flags
& DF_USING_ALIAS
))
1486 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->dev_alias
);
1489 static ssize_t
target_core_store_dev_alias(
1494 struct se_device
*dev
= p
;
1495 struct se_hba
*hba
= dev
->se_hba
;
1498 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1499 pr_err("alias count: %d exceeds"
1500 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1501 SE_DEV_ALIAS_LEN
-1);
1505 read_bytes
= snprintf(&dev
->dev_alias
[0], SE_DEV_ALIAS_LEN
, "%s", page
);
1508 if (dev
->dev_alias
[read_bytes
- 1] == '\n')
1509 dev
->dev_alias
[read_bytes
- 1] = '\0';
1511 dev
->dev_flags
|= DF_USING_ALIAS
;
1513 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
1514 config_item_name(&hba
->hba_group
.cg_item
),
1515 config_item_name(&dev
->dev_group
.cg_item
),
1521 static struct target_core_configfs_attribute target_core_attr_dev_alias
= {
1522 .attr
= { .ca_owner
= THIS_MODULE
,
1524 .ca_mode
= S_IRUGO
| S_IWUSR
},
1525 .show
= target_core_show_dev_alias
,
1526 .store
= target_core_store_dev_alias
,
1529 static ssize_t
target_core_show_dev_udev_path(void *p
, char *page
)
1531 struct se_device
*dev
= p
;
1533 if (!(dev
->dev_flags
& DF_USING_UDEV_PATH
))
1536 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->udev_path
);
1539 static ssize_t
target_core_store_dev_udev_path(
1544 struct se_device
*dev
= p
;
1545 struct se_hba
*hba
= dev
->se_hba
;
1548 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1549 pr_err("udev_path count: %d exceeds"
1550 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1551 SE_UDEV_PATH_LEN
-1);
1555 read_bytes
= snprintf(&dev
->udev_path
[0], SE_UDEV_PATH_LEN
,
1559 if (dev
->udev_path
[read_bytes
- 1] == '\n')
1560 dev
->udev_path
[read_bytes
- 1] = '\0';
1562 dev
->dev_flags
|= DF_USING_UDEV_PATH
;
1564 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1565 config_item_name(&hba
->hba_group
.cg_item
),
1566 config_item_name(&dev
->dev_group
.cg_item
),
1572 static struct target_core_configfs_attribute target_core_attr_dev_udev_path
= {
1573 .attr
= { .ca_owner
= THIS_MODULE
,
1574 .ca_name
= "udev_path",
1575 .ca_mode
= S_IRUGO
| S_IWUSR
},
1576 .show
= target_core_show_dev_udev_path
,
1577 .store
= target_core_store_dev_udev_path
,
1580 static ssize_t
target_core_store_dev_enable(
1585 struct se_device
*dev
= p
;
1589 ptr
= strstr(page
, "1");
1591 pr_err("For dev_enable ops, only valid value"
1596 ret
= target_configure_device(dev
);
1602 static struct target_core_configfs_attribute target_core_attr_dev_enable
= {
1603 .attr
= { .ca_owner
= THIS_MODULE
,
1604 .ca_name
= "enable",
1605 .ca_mode
= S_IWUSR
},
1607 .store
= target_core_store_dev_enable
,
1610 static ssize_t
target_core_show_alua_lu_gp(void *p
, char *page
)
1612 struct se_device
*dev
= p
;
1613 struct config_item
*lu_ci
;
1614 struct t10_alua_lu_gp
*lu_gp
;
1615 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1618 if (dev
->t10_alua
.alua_type
!= SPC3_ALUA_EMULATED
)
1621 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1623 pr_err("NULL struct se_device->dev_alua_lu_gp_mem"
1628 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1629 lu_gp
= lu_gp_mem
->lu_gp
;
1631 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1632 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1633 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1635 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1640 static ssize_t
target_core_store_alua_lu_gp(
1645 struct se_device
*dev
= p
;
1646 struct se_hba
*hba
= dev
->se_hba
;
1647 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1648 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1649 unsigned char buf
[LU_GROUP_NAME_BUF
];
1652 if (dev
->t10_alua
.alua_type
!= SPC3_ALUA_EMULATED
) {
1653 pr_warn("SPC3_ALUA_EMULATED not enabled for %s/%s\n",
1654 config_item_name(&hba
->hba_group
.cg_item
),
1655 config_item_name(&dev
->dev_group
.cg_item
));
1658 if (count
> LU_GROUP_NAME_BUF
) {
1659 pr_err("ALUA LU Group Alias too large!\n");
1662 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1663 memcpy(buf
, page
, count
);
1665 * Any ALUA logical unit alias besides "NULL" means we will be
1666 * making a new group association.
1668 if (strcmp(strstrip(buf
), "NULL")) {
1670 * core_alua_get_lu_gp_by_name() will increment reference to
1671 * struct t10_alua_lu_gp. This reference is released with
1672 * core_alua_get_lu_gp_by_name below().
1674 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
1678 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1681 core_alua_put_lu_gp_from_name(lu_gp_new
);
1682 pr_err("NULL struct se_device->dev_alua_lu_gp_mem"
1687 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1688 lu_gp
= lu_gp_mem
->lu_gp
;
1691 * Clearing an existing lu_gp association, and replacing
1695 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
1696 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1698 config_item_name(&hba
->hba_group
.cg_item
),
1699 config_item_name(&dev
->dev_group
.cg_item
),
1700 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1703 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1704 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1709 * Removing existing association of lu_gp_mem with lu_gp
1711 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1715 * Associate lu_gp_mem with lu_gp_new.
1717 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
1718 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1720 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1721 " core/alua/lu_gps/%s, ID: %hu\n",
1722 (move
) ? "Moving" : "Adding",
1723 config_item_name(&hba
->hba_group
.cg_item
),
1724 config_item_name(&dev
->dev_group
.cg_item
),
1725 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
1726 lu_gp_new
->lu_gp_id
);
1728 core_alua_put_lu_gp_from_name(lu_gp_new
);
1732 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp
= {
1733 .attr
= { .ca_owner
= THIS_MODULE
,
1734 .ca_name
= "alua_lu_gp",
1735 .ca_mode
= S_IRUGO
| S_IWUSR
},
1736 .show
= target_core_show_alua_lu_gp
,
1737 .store
= target_core_store_alua_lu_gp
,
1740 static struct configfs_attribute
*lio_core_dev_attrs
[] = {
1741 &target_core_attr_dev_info
.attr
,
1742 &target_core_attr_dev_control
.attr
,
1743 &target_core_attr_dev_alias
.attr
,
1744 &target_core_attr_dev_udev_path
.attr
,
1745 &target_core_attr_dev_enable
.attr
,
1746 &target_core_attr_dev_alua_lu_gp
.attr
,
1750 static void target_core_dev_release(struct config_item
*item
)
1752 struct config_group
*dev_cg
= to_config_group(item
);
1753 struct se_device
*dev
=
1754 container_of(dev_cg
, struct se_device
, dev_group
);
1756 kfree(dev_cg
->default_groups
);
1757 target_free_device(dev
);
1760 static ssize_t
target_core_dev_show(struct config_item
*item
,
1761 struct configfs_attribute
*attr
,
1764 struct config_group
*dev_cg
= to_config_group(item
);
1765 struct se_device
*dev
=
1766 container_of(dev_cg
, struct se_device
, dev_group
);
1767 struct target_core_configfs_attribute
*tc_attr
= container_of(
1768 attr
, struct target_core_configfs_attribute
, attr
);
1773 return tc_attr
->show(dev
, page
);
1776 static ssize_t
target_core_dev_store(struct config_item
*item
,
1777 struct configfs_attribute
*attr
,
1778 const char *page
, size_t count
)
1780 struct config_group
*dev_cg
= to_config_group(item
);
1781 struct se_device
*dev
=
1782 container_of(dev_cg
, struct se_device
, dev_group
);
1783 struct target_core_configfs_attribute
*tc_attr
= container_of(
1784 attr
, struct target_core_configfs_attribute
, attr
);
1786 if (!tc_attr
->store
)
1789 return tc_attr
->store(dev
, page
, count
);
1792 static struct configfs_item_operations target_core_dev_item_ops
= {
1793 .release
= target_core_dev_release
,
1794 .show_attribute
= target_core_dev_show
,
1795 .store_attribute
= target_core_dev_store
,
1798 static struct config_item_type target_core_dev_cit
= {
1799 .ct_item_ops
= &target_core_dev_item_ops
,
1800 .ct_attrs
= lio_core_dev_attrs
,
1801 .ct_owner
= THIS_MODULE
,
1804 /* End functions for struct config_item_type target_core_dev_cit */
1806 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
1808 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp
, t10_alua_lu_gp
);
1809 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
1810 static struct target_core_alua_lu_gp_attribute \
1811 target_core_alua_lu_gp_##_name = \
1812 __CONFIGFS_EATTR(_name, _mode, \
1813 target_core_alua_lu_gp_show_attr_##_name, \
1814 target_core_alua_lu_gp_store_attr_##_name);
1816 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
1817 static struct target_core_alua_lu_gp_attribute \
1818 target_core_alua_lu_gp_##_name = \
1819 __CONFIGFS_EATTR_RO(_name, \
1820 target_core_alua_lu_gp_show_attr_##_name);
1825 static ssize_t
target_core_alua_lu_gp_show_attr_lu_gp_id(
1826 struct t10_alua_lu_gp
*lu_gp
,
1829 if (!lu_gp
->lu_gp_valid_id
)
1832 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
1835 static ssize_t
target_core_alua_lu_gp_store_attr_lu_gp_id(
1836 struct t10_alua_lu_gp
*lu_gp
,
1840 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
1841 unsigned long lu_gp_id
;
1844 ret
= strict_strtoul(page
, 0, &lu_gp_id
);
1846 pr_err("strict_strtoul() returned %d for"
1847 " lu_gp_id\n", ret
);
1850 if (lu_gp_id
> 0x0000ffff) {
1851 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
1852 " 0x0000ffff\n", lu_gp_id
);
1856 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
1860 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
1861 " Group: core/alua/lu_gps/%s to ID: %hu\n",
1862 config_item_name(&alua_lu_gp_cg
->cg_item
),
1868 SE_DEV_ALUA_LU_ATTR(lu_gp_id
, S_IRUGO
| S_IWUSR
);
1873 static ssize_t
target_core_alua_lu_gp_show_attr_members(
1874 struct t10_alua_lu_gp
*lu_gp
,
1877 struct se_device
*dev
;
1879 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1880 ssize_t len
= 0, cur_len
;
1881 unsigned char buf
[LU_GROUP_NAME_BUF
];
1883 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1885 spin_lock(&lu_gp
->lu_gp_lock
);
1886 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
1887 dev
= lu_gp_mem
->lu_gp_mem_dev
;
1890 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
1891 config_item_name(&hba
->hba_group
.cg_item
),
1892 config_item_name(&dev
->dev_group
.cg_item
));
1893 cur_len
++; /* Extra byte for NULL terminator */
1895 if ((cur_len
+ len
) > PAGE_SIZE
) {
1896 pr_warn("Ran out of lu_gp_show_attr"
1897 "_members buffer\n");
1900 memcpy(page
+len
, buf
, cur_len
);
1903 spin_unlock(&lu_gp
->lu_gp_lock
);
1908 SE_DEV_ALUA_LU_ATTR_RO(members
);
1910 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp
, t10_alua_lu_gp
, lu_gp_group
);
1912 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
1913 &target_core_alua_lu_gp_lu_gp_id
.attr
,
1914 &target_core_alua_lu_gp_members
.attr
,
1918 static void target_core_alua_lu_gp_release(struct config_item
*item
)
1920 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
1921 struct t10_alua_lu_gp
, lu_gp_group
);
1923 core_alua_free_lu_gp(lu_gp
);
1926 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
1927 .release
= target_core_alua_lu_gp_release
,
1928 .show_attribute
= target_core_alua_lu_gp_attr_show
,
1929 .store_attribute
= target_core_alua_lu_gp_attr_store
,
1932 static struct config_item_type target_core_alua_lu_gp_cit
= {
1933 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
1934 .ct_attrs
= target_core_alua_lu_gp_attrs
,
1935 .ct_owner
= THIS_MODULE
,
1938 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
1940 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
1942 static struct config_group
*target_core_alua_create_lu_gp(
1943 struct config_group
*group
,
1946 struct t10_alua_lu_gp
*lu_gp
;
1947 struct config_group
*alua_lu_gp_cg
= NULL
;
1948 struct config_item
*alua_lu_gp_ci
= NULL
;
1950 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
1954 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
1955 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
1957 config_group_init_type_name(alua_lu_gp_cg
, name
,
1958 &target_core_alua_lu_gp_cit
);
1960 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
1961 " Group: core/alua/lu_gps/%s\n",
1962 config_item_name(alua_lu_gp_ci
));
1964 return alua_lu_gp_cg
;
1968 static void target_core_alua_drop_lu_gp(
1969 struct config_group
*group
,
1970 struct config_item
*item
)
1972 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
1973 struct t10_alua_lu_gp
, lu_gp_group
);
1975 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
1976 " Group: core/alua/lu_gps/%s, ID: %hu\n",
1977 config_item_name(item
), lu_gp
->lu_gp_id
);
1979 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
1980 * -> target_core_alua_lu_gp_release()
1982 config_item_put(item
);
1985 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
1986 .make_group
= &target_core_alua_create_lu_gp
,
1987 .drop_item
= &target_core_alua_drop_lu_gp
,
1990 static struct config_item_type target_core_alua_lu_gps_cit
= {
1991 .ct_item_ops
= NULL
,
1992 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
1993 .ct_owner
= THIS_MODULE
,
1996 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
1998 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2000 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
);
2001 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
2002 static struct target_core_alua_tg_pt_gp_attribute \
2003 target_core_alua_tg_pt_gp_##_name = \
2004 __CONFIGFS_EATTR(_name, _mode, \
2005 target_core_alua_tg_pt_gp_show_attr_##_name, \
2006 target_core_alua_tg_pt_gp_store_attr_##_name);
2008 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2009 static struct target_core_alua_tg_pt_gp_attribute \
2010 target_core_alua_tg_pt_gp_##_name = \
2011 __CONFIGFS_EATTR_RO(_name, \
2012 target_core_alua_tg_pt_gp_show_attr_##_name);
2017 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2018 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2021 return sprintf(page
, "%d\n",
2022 atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
));
2025 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2026 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2030 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
2034 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2035 pr_err("Unable to do implict ALUA on non valid"
2036 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2040 ret
= strict_strtoul(page
, 0, &tmp
);
2042 pr_err("Unable to extract new ALUA access state from"
2046 new_state
= (int)tmp
;
2048 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICT_ALUA
)) {
2049 pr_err("Unable to process implict configfs ALUA"
2050 " transition while TPGS_IMPLICT_ALUA is disabled\n");
2054 ret
= core_alua_do_port_transition(tg_pt_gp
, dev
,
2055 NULL
, NULL
, new_state
, 0);
2056 return (!ret
) ? count
: -EINVAL
;
2059 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state
, S_IRUGO
| S_IWUSR
);
2062 * alua_access_status
2064 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2065 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2068 return sprintf(page
, "%s\n",
2069 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2072 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2073 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2078 int new_status
, ret
;
2080 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2081 pr_err("Unable to do set ALUA access status on non"
2082 " valid tg_pt_gp ID: %hu\n",
2083 tg_pt_gp
->tg_pt_gp_valid_id
);
2087 ret
= strict_strtoul(page
, 0, &tmp
);
2089 pr_err("Unable to extract new ALUA access status"
2090 " from %s\n", page
);
2093 new_status
= (int)tmp
;
2095 if ((new_status
!= ALUA_STATUS_NONE
) &&
2096 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
) &&
2097 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
)) {
2098 pr_err("Illegal ALUA access status: 0x%02x\n",
2103 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2107 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status
, S_IRUGO
| S_IWUSR
);
2112 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2113 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2116 return core_alua_show_access_type(tg_pt_gp
, page
);
2119 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2120 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2124 return core_alua_store_access_type(tg_pt_gp
, page
, count
);
2127 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type
, S_IRUGO
| S_IWUSR
);
2130 * alua_write_metadata
2132 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2133 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2136 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_write_metadata
);
2139 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2140 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2147 ret
= strict_strtoul(page
, 0, &tmp
);
2149 pr_err("Unable to extract alua_write_metadata\n");
2153 if ((tmp
!= 0) && (tmp
!= 1)) {
2154 pr_err("Illegal value for alua_write_metadata:"
2158 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2163 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata
, S_IRUGO
| S_IWUSR
);
2170 static ssize_t
target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2171 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2174 return core_alua_show_nonop_delay_msecs(tg_pt_gp
, page
);
2178 static ssize_t
target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2179 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2183 return core_alua_store_nonop_delay_msecs(tg_pt_gp
, page
, count
);
2186 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs
, S_IRUGO
| S_IWUSR
);
2191 static ssize_t
target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2192 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2195 return core_alua_show_trans_delay_msecs(tg_pt_gp
, page
);
2198 static ssize_t
target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2199 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2203 return core_alua_store_trans_delay_msecs(tg_pt_gp
, page
, count
);
2206 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs
, S_IRUGO
| S_IWUSR
);
2209 * implict_trans_secs
2211 static ssize_t
target_core_alua_tg_pt_gp_show_attr_implict_trans_secs(
2212 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2215 return core_alua_show_implict_trans_secs(tg_pt_gp
, page
);
2218 static ssize_t
target_core_alua_tg_pt_gp_store_attr_implict_trans_secs(
2219 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2223 return core_alua_store_implict_trans_secs(tg_pt_gp
, page
, count
);
2226 SE_DEV_ALUA_TG_PT_ATTR(implict_trans_secs
, S_IRUGO
| S_IWUSR
);
2232 static ssize_t
target_core_alua_tg_pt_gp_show_attr_preferred(
2233 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2236 return core_alua_show_preferred_bit(tg_pt_gp
, page
);
2239 static ssize_t
target_core_alua_tg_pt_gp_store_attr_preferred(
2240 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2244 return core_alua_store_preferred_bit(tg_pt_gp
, page
, count
);
2247 SE_DEV_ALUA_TG_PT_ATTR(preferred
, S_IRUGO
| S_IWUSR
);
2252 static ssize_t
target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2253 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2256 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
2259 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2262 static ssize_t
target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2263 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2267 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2268 unsigned long tg_pt_gp_id
;
2271 ret
= strict_strtoul(page
, 0, &tg_pt_gp_id
);
2273 pr_err("strict_strtoul() returned %d for"
2274 " tg_pt_gp_id\n", ret
);
2277 if (tg_pt_gp_id
> 0x0000ffff) {
2278 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:"
2279 " 0x0000ffff\n", tg_pt_gp_id
);
2283 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2287 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
2288 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2289 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2290 tg_pt_gp
->tg_pt_gp_id
);
2295 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id
, S_IRUGO
| S_IWUSR
);
2300 static ssize_t
target_core_alua_tg_pt_gp_show_attr_members(
2301 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2304 struct se_port
*port
;
2305 struct se_portal_group
*tpg
;
2307 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
2308 ssize_t len
= 0, cur_len
;
2309 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2311 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2313 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2314 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
2315 tg_pt_gp_mem_list
) {
2316 port
= tg_pt_gp_mem
->tg_pt
;
2317 tpg
= port
->sep_tpg
;
2318 lun
= port
->sep_lun
;
2320 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2321 "/%s\n", tpg
->se_tpg_tfo
->get_fabric_name(),
2322 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
2323 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
2324 config_item_name(&lun
->lun_group
.cg_item
));
2325 cur_len
++; /* Extra byte for NULL terminator */
2327 if ((cur_len
+ len
) > PAGE_SIZE
) {
2328 pr_warn("Ran out of lu_gp_show_attr"
2329 "_members buffer\n");
2332 memcpy(page
+len
, buf
, cur_len
);
2335 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2340 SE_DEV_ALUA_TG_PT_ATTR_RO(members
);
2342 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
,
2345 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2346 &target_core_alua_tg_pt_gp_alua_access_state
.attr
,
2347 &target_core_alua_tg_pt_gp_alua_access_status
.attr
,
2348 &target_core_alua_tg_pt_gp_alua_access_type
.attr
,
2349 &target_core_alua_tg_pt_gp_alua_write_metadata
.attr
,
2350 &target_core_alua_tg_pt_gp_nonop_delay_msecs
.attr
,
2351 &target_core_alua_tg_pt_gp_trans_delay_msecs
.attr
,
2352 &target_core_alua_tg_pt_gp_implict_trans_secs
.attr
,
2353 &target_core_alua_tg_pt_gp_preferred
.attr
,
2354 &target_core_alua_tg_pt_gp_tg_pt_gp_id
.attr
,
2355 &target_core_alua_tg_pt_gp_members
.attr
,
2359 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2361 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2362 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2364 core_alua_free_tg_pt_gp(tg_pt_gp
);
2367 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2368 .release
= target_core_alua_tg_pt_gp_release
,
2369 .show_attribute
= target_core_alua_tg_pt_gp_attr_show
,
2370 .store_attribute
= target_core_alua_tg_pt_gp_attr_store
,
2373 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2374 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2375 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2376 .ct_owner
= THIS_MODULE
,
2379 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2381 /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2383 static struct config_group
*target_core_alua_create_tg_pt_gp(
2384 struct config_group
*group
,
2387 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2388 alua_tg_pt_gps_group
);
2389 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2390 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2391 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2393 tg_pt_gp
= core_alua_allocate_tg_pt_gp(alua
->t10_dev
, name
, 0);
2397 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2398 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2400 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2401 &target_core_alua_tg_pt_gp_cit
);
2403 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
2404 " Group: alua/tg_pt_gps/%s\n",
2405 config_item_name(alua_tg_pt_gp_ci
));
2407 return alua_tg_pt_gp_cg
;
2410 static void target_core_alua_drop_tg_pt_gp(
2411 struct config_group
*group
,
2412 struct config_item
*item
)
2414 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2415 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2417 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
2418 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2419 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2421 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2422 * -> target_core_alua_tg_pt_gp_release().
2424 config_item_put(item
);
2427 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2428 .make_group
= &target_core_alua_create_tg_pt_gp
,
2429 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2432 static struct config_item_type target_core_alua_tg_pt_gps_cit
= {
2433 .ct_group_ops
= &target_core_alua_tg_pt_gps_group_ops
,
2434 .ct_owner
= THIS_MODULE
,
2437 /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2439 /* Start functions for struct config_item_type target_core_alua_cit */
2442 * target_core_alua_cit is a ConfigFS group that lives under
2443 * /sys/kernel/config/target/core/alua. There are default groups
2444 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2445 * target_core_alua_cit in target_core_init_configfs() below.
2447 static struct config_item_type target_core_alua_cit
= {
2448 .ct_item_ops
= NULL
,
2450 .ct_owner
= THIS_MODULE
,
2453 /* End functions for struct config_item_type target_core_alua_cit */
2455 /* Start functions for struct config_item_type target_core_stat_cit */
2457 static struct config_group
*target_core_stat_mkdir(
2458 struct config_group
*group
,
2461 return ERR_PTR(-ENOSYS
);
2464 static void target_core_stat_rmdir(
2465 struct config_group
*group
,
2466 struct config_item
*item
)
2471 static struct configfs_group_operations target_core_stat_group_ops
= {
2472 .make_group
= &target_core_stat_mkdir
,
2473 .drop_item
= &target_core_stat_rmdir
,
2476 static struct config_item_type target_core_stat_cit
= {
2477 .ct_group_ops
= &target_core_stat_group_ops
,
2478 .ct_owner
= THIS_MODULE
,
2481 /* End functions for struct config_item_type target_core_stat_cit */
2483 /* Start functions for struct config_item_type target_core_hba_cit */
2485 static struct config_group
*target_core_make_subdev(
2486 struct config_group
*group
,
2489 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2490 struct se_subsystem_api
*t
;
2491 struct config_item
*hba_ci
= &group
->cg_item
;
2492 struct se_hba
*hba
= item_to_hba(hba_ci
);
2493 struct se_device
*dev
;
2494 struct config_group
*dev_cg
= NULL
, *tg_pt_gp_cg
= NULL
;
2495 struct config_group
*dev_stat_grp
= NULL
;
2496 int errno
= -ENOMEM
, ret
;
2498 ret
= mutex_lock_interruptible(&hba
->hba_access_mutex
);
2500 return ERR_PTR(ret
);
2502 * Locate the struct se_subsystem_api from parent's struct se_hba.
2506 dev
= target_alloc_device(hba
, name
);
2510 dev_cg
= &dev
->dev_group
;
2512 dev_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 7,
2514 if (!dev_cg
->default_groups
)
2515 goto out_free_device
;
2517 config_group_init_type_name(dev_cg
, name
, &target_core_dev_cit
);
2518 config_group_init_type_name(&dev
->dev_attrib
.da_group
, "attrib",
2519 &target_core_dev_attrib_cit
);
2520 config_group_init_type_name(&dev
->dev_pr_group
, "pr",
2521 &target_core_dev_pr_cit
);
2522 config_group_init_type_name(&dev
->t10_wwn
.t10_wwn_group
, "wwn",
2523 &target_core_dev_wwn_cit
);
2524 config_group_init_type_name(&dev
->t10_alua
.alua_tg_pt_gps_group
,
2525 "alua", &target_core_alua_tg_pt_gps_cit
);
2526 config_group_init_type_name(&dev
->dev_stat_grps
.stat_group
,
2527 "statistics", &target_core_stat_cit
);
2529 dev_cg
->default_groups
[0] = &dev
->dev_attrib
.da_group
;
2530 dev_cg
->default_groups
[1] = &dev
->dev_pr_group
;
2531 dev_cg
->default_groups
[2] = &dev
->t10_wwn
.t10_wwn_group
;
2532 dev_cg
->default_groups
[3] = &dev
->t10_alua
.alua_tg_pt_gps_group
;
2533 dev_cg
->default_groups
[4] = &dev
->dev_stat_grps
.stat_group
;
2534 dev_cg
->default_groups
[5] = NULL
;
2536 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
2538 tg_pt_gp
= core_alua_allocate_tg_pt_gp(dev
, "default_tg_pt_gp", 1);
2540 goto out_free_dev_cg_default_groups
;
2541 dev
->t10_alua
.default_tg_pt_gp
= tg_pt_gp
;
2543 tg_pt_gp_cg
= &dev
->t10_alua
.alua_tg_pt_gps_group
;
2544 tg_pt_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
2546 if (!tg_pt_gp_cg
->default_groups
) {
2547 pr_err("Unable to allocate tg_pt_gp_cg->"
2548 "default_groups\n");
2549 goto out_free_tg_pt_gp
;
2552 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2553 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2554 tg_pt_gp_cg
->default_groups
[0] = &tg_pt_gp
->tg_pt_gp_group
;
2555 tg_pt_gp_cg
->default_groups
[1] = NULL
;
2557 * Add core/$HBA/$DEV/statistics/ default groups
2559 dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
2560 dev_stat_grp
->default_groups
= kzalloc(sizeof(struct config_group
) * 4,
2562 if (!dev_stat_grp
->default_groups
) {
2563 pr_err("Unable to allocate dev_stat_grp->default_groups\n");
2564 goto out_free_tg_pt_gp_cg_default_groups
;
2566 target_stat_setup_dev_default_groups(dev
);
2568 mutex_unlock(&hba
->hba_access_mutex
);
2571 out_free_tg_pt_gp_cg_default_groups
:
2572 kfree(tg_pt_gp_cg
->default_groups
);
2574 core_alua_free_tg_pt_gp(tg_pt_gp
);
2575 out_free_dev_cg_default_groups
:
2576 kfree(dev_cg
->default_groups
);
2578 target_free_device(dev
);
2580 mutex_unlock(&hba
->hba_access_mutex
);
2581 return ERR_PTR(errno
);
2584 static void target_core_drop_subdev(
2585 struct config_group
*group
,
2586 struct config_item
*item
)
2588 struct config_group
*dev_cg
= to_config_group(item
);
2589 struct se_device
*dev
=
2590 container_of(dev_cg
, struct se_device
, dev_group
);
2592 struct config_item
*df_item
;
2593 struct config_group
*tg_pt_gp_cg
, *dev_stat_grp
;
2596 hba
= item_to_hba(&dev
->se_hba
->hba_group
.cg_item
);
2598 mutex_lock(&hba
->hba_access_mutex
);
2600 dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
2601 for (i
= 0; dev_stat_grp
->default_groups
[i
]; i
++) {
2602 df_item
= &dev_stat_grp
->default_groups
[i
]->cg_item
;
2603 dev_stat_grp
->default_groups
[i
] = NULL
;
2604 config_item_put(df_item
);
2606 kfree(dev_stat_grp
->default_groups
);
2608 tg_pt_gp_cg
= &dev
->t10_alua
.alua_tg_pt_gps_group
;
2609 for (i
= 0; tg_pt_gp_cg
->default_groups
[i
]; i
++) {
2610 df_item
= &tg_pt_gp_cg
->default_groups
[i
]->cg_item
;
2611 tg_pt_gp_cg
->default_groups
[i
] = NULL
;
2612 config_item_put(df_item
);
2614 kfree(tg_pt_gp_cg
->default_groups
);
2616 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2617 * directly from target_core_alua_tg_pt_gp_release().
2619 dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2621 for (i
= 0; dev_cg
->default_groups
[i
]; i
++) {
2622 df_item
= &dev_cg
->default_groups
[i
]->cg_item
;
2623 dev_cg
->default_groups
[i
] = NULL
;
2624 config_item_put(df_item
);
2627 * se_dev is released from target_core_dev_item_ops->release()
2629 config_item_put(item
);
2630 mutex_unlock(&hba
->hba_access_mutex
);
2633 static struct configfs_group_operations target_core_hba_group_ops
= {
2634 .make_group
= target_core_make_subdev
,
2635 .drop_item
= target_core_drop_subdev
,
2638 CONFIGFS_EATTR_STRUCT(target_core_hba
, se_hba
);
2639 #define SE_HBA_ATTR(_name, _mode) \
2640 static struct target_core_hba_attribute \
2641 target_core_hba_##_name = \
2642 __CONFIGFS_EATTR(_name, _mode, \
2643 target_core_hba_show_attr_##_name, \
2644 target_core_hba_store_attr_##_name);
2646 #define SE_HBA_ATTR_RO(_name) \
2647 static struct target_core_hba_attribute \
2648 target_core_hba_##_name = \
2649 __CONFIGFS_EATTR_RO(_name, \
2650 target_core_hba_show_attr_##_name);
2652 static ssize_t
target_core_hba_show_attr_hba_info(
2656 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
2657 hba
->hba_id
, hba
->transport
->name
,
2658 TARGET_CORE_CONFIGFS_VERSION
);
2661 SE_HBA_ATTR_RO(hba_info
);
2663 static ssize_t
target_core_hba_show_attr_hba_mode(struct se_hba
*hba
,
2668 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
2671 return sprintf(page
, "%d\n", hba_mode
);
2674 static ssize_t
target_core_hba_store_attr_hba_mode(struct se_hba
*hba
,
2675 const char *page
, size_t count
)
2677 struct se_subsystem_api
*transport
= hba
->transport
;
2678 unsigned long mode_flag
;
2681 if (transport
->pmode_enable_hba
== NULL
)
2684 ret
= strict_strtoul(page
, 0, &mode_flag
);
2686 pr_err("Unable to extract hba mode flag: %d\n", ret
);
2690 if (hba
->dev_count
) {
2691 pr_err("Unable to set hba_mode with active devices\n");
2695 ret
= transport
->pmode_enable_hba(hba
, mode_flag
);
2699 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
2701 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
2706 SE_HBA_ATTR(hba_mode
, S_IRUGO
| S_IWUSR
);
2708 CONFIGFS_EATTR_OPS(target_core_hba
, se_hba
, hba_group
);
2710 static void target_core_hba_release(struct config_item
*item
)
2712 struct se_hba
*hba
= container_of(to_config_group(item
),
2713 struct se_hba
, hba_group
);
2714 core_delete_hba(hba
);
2717 static struct configfs_attribute
*target_core_hba_attrs
[] = {
2718 &target_core_hba_hba_info
.attr
,
2719 &target_core_hba_hba_mode
.attr
,
2723 static struct configfs_item_operations target_core_hba_item_ops
= {
2724 .release
= target_core_hba_release
,
2725 .show_attribute
= target_core_hba_attr_show
,
2726 .store_attribute
= target_core_hba_attr_store
,
2729 static struct config_item_type target_core_hba_cit
= {
2730 .ct_item_ops
= &target_core_hba_item_ops
,
2731 .ct_group_ops
= &target_core_hba_group_ops
,
2732 .ct_attrs
= target_core_hba_attrs
,
2733 .ct_owner
= THIS_MODULE
,
2736 static struct config_group
*target_core_call_addhbatotarget(
2737 struct config_group
*group
,
2740 char *se_plugin_str
, *str
, *str2
;
2742 char buf
[TARGET_CORE_NAME_MAX_LEN
];
2743 unsigned long plugin_dep_id
= 0;
2746 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
2747 if (strlen(name
) >= TARGET_CORE_NAME_MAX_LEN
) {
2748 pr_err("Passed *name strlen(): %d exceeds"
2749 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
2750 TARGET_CORE_NAME_MAX_LEN
);
2751 return ERR_PTR(-ENAMETOOLONG
);
2753 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
2755 str
= strstr(buf
, "_");
2757 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
2758 return ERR_PTR(-EINVAL
);
2760 se_plugin_str
= buf
;
2762 * Special case for subsystem plugins that have "_" in their names.
2763 * Namely rd_direct and rd_mcp..
2765 str2
= strstr(str
+1, "_");
2767 *str2
= '\0'; /* Terminate for *se_plugin_str */
2768 str2
++; /* Skip to start of plugin dependent ID */
2771 *str
= '\0'; /* Terminate for *se_plugin_str */
2772 str
++; /* Skip to start of plugin dependent ID */
2775 ret
= strict_strtoul(str
, 0, &plugin_dep_id
);
2777 pr_err("strict_strtoul() returned %d for"
2778 " plugin_dep_id\n", ret
);
2779 return ERR_PTR(-EINVAL
);
2782 * Load up TCM subsystem plugins if they have not already been loaded.
2784 transport_subsystem_check_init();
2786 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
2788 return ERR_CAST(hba
);
2790 config_group_init_type_name(&hba
->hba_group
, name
,
2791 &target_core_hba_cit
);
2793 return &hba
->hba_group
;
2796 static void target_core_call_delhbafromtarget(
2797 struct config_group
*group
,
2798 struct config_item
*item
)
2801 * core_delete_hba() is called from target_core_hba_item_ops->release()
2802 * -> target_core_hba_release()
2804 config_item_put(item
);
2807 static struct configfs_group_operations target_core_group_ops
= {
2808 .make_group
= target_core_call_addhbatotarget
,
2809 .drop_item
= target_core_call_delhbafromtarget
,
2812 static struct config_item_type target_core_cit
= {
2813 .ct_item_ops
= NULL
,
2814 .ct_group_ops
= &target_core_group_ops
,
2816 .ct_owner
= THIS_MODULE
,
2819 /* Stop functions for struct config_item_type target_core_hba_cit */
2821 static int __init
target_core_init_configfs(void)
2823 struct config_group
*target_cg
, *hba_cg
= NULL
, *alua_cg
= NULL
;
2824 struct config_group
*lu_gp_cg
= NULL
;
2825 struct configfs_subsystem
*subsys
;
2826 struct t10_alua_lu_gp
*lu_gp
;
2829 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
2830 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
2831 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
2833 subsys
= target_core_subsystem
[0];
2834 config_group_init(&subsys
->su_group
);
2835 mutex_init(&subsys
->su_mutex
);
2837 ret
= init_se_kmem_caches();
2841 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
2842 * and ALUA Logical Unit Group and Target Port Group infrastructure.
2844 target_cg
= &subsys
->su_group
;
2845 target_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
2847 if (!target_cg
->default_groups
) {
2848 pr_err("Unable to allocate target_cg->default_groups\n");
2853 config_group_init_type_name(&target_core_hbagroup
,
2854 "core", &target_core_cit
);
2855 target_cg
->default_groups
[0] = &target_core_hbagroup
;
2856 target_cg
->default_groups
[1] = NULL
;
2858 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
2860 hba_cg
= &target_core_hbagroup
;
2861 hba_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
2863 if (!hba_cg
->default_groups
) {
2864 pr_err("Unable to allocate hba_cg->default_groups\n");
2868 config_group_init_type_name(&alua_group
,
2869 "alua", &target_core_alua_cit
);
2870 hba_cg
->default_groups
[0] = &alua_group
;
2871 hba_cg
->default_groups
[1] = NULL
;
2873 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
2874 * groups under /sys/kernel/config/target/core/alua/
2876 alua_cg
= &alua_group
;
2877 alua_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
2879 if (!alua_cg
->default_groups
) {
2880 pr_err("Unable to allocate alua_cg->default_groups\n");
2885 config_group_init_type_name(&alua_lu_gps_group
,
2886 "lu_gps", &target_core_alua_lu_gps_cit
);
2887 alua_cg
->default_groups
[0] = &alua_lu_gps_group
;
2888 alua_cg
->default_groups
[1] = NULL
;
2890 * Add core/alua/lu_gps/default_lu_gp
2892 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
2893 if (IS_ERR(lu_gp
)) {
2898 lu_gp_cg
= &alua_lu_gps_group
;
2899 lu_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
2901 if (!lu_gp_cg
->default_groups
) {
2902 pr_err("Unable to allocate lu_gp_cg->default_groups\n");
2907 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
2908 &target_core_alua_lu_gp_cit
);
2909 lu_gp_cg
->default_groups
[0] = &lu_gp
->lu_gp_group
;
2910 lu_gp_cg
->default_groups
[1] = NULL
;
2911 default_lu_gp
= lu_gp
;
2913 * Register the target_core_mod subsystem with configfs.
2915 ret
= configfs_register_subsystem(subsys
);
2917 pr_err("Error %d while registering subsystem %s\n",
2918 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
2921 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
2922 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION
" on %s/%s"
2923 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
2925 * Register built-in RAMDISK subsystem logic for virtual LUN 0
2927 ret
= rd_module_init();
2931 ret
= core_dev_setup_virtual_lun0();
2938 configfs_unregister_subsystem(subsys
);
2939 core_dev_release_virtual_lun0();
2942 if (default_lu_gp
) {
2943 core_alua_free_lu_gp(default_lu_gp
);
2944 default_lu_gp
= NULL
;
2947 kfree(lu_gp_cg
->default_groups
);
2949 kfree(alua_cg
->default_groups
);
2951 kfree(hba_cg
->default_groups
);
2952 kfree(target_cg
->default_groups
);
2953 release_se_kmem_caches();
2957 static void __exit
target_core_exit_configfs(void)
2959 struct configfs_subsystem
*subsys
;
2960 struct config_group
*hba_cg
, *alua_cg
, *lu_gp_cg
;
2961 struct config_item
*item
;
2964 subsys
= target_core_subsystem
[0];
2966 lu_gp_cg
= &alua_lu_gps_group
;
2967 for (i
= 0; lu_gp_cg
->default_groups
[i
]; i
++) {
2968 item
= &lu_gp_cg
->default_groups
[i
]->cg_item
;
2969 lu_gp_cg
->default_groups
[i
] = NULL
;
2970 config_item_put(item
);
2972 kfree(lu_gp_cg
->default_groups
);
2973 lu_gp_cg
->default_groups
= NULL
;
2975 alua_cg
= &alua_group
;
2976 for (i
= 0; alua_cg
->default_groups
[i
]; i
++) {
2977 item
= &alua_cg
->default_groups
[i
]->cg_item
;
2978 alua_cg
->default_groups
[i
] = NULL
;
2979 config_item_put(item
);
2981 kfree(alua_cg
->default_groups
);
2982 alua_cg
->default_groups
= NULL
;
2984 hba_cg
= &target_core_hbagroup
;
2985 for (i
= 0; hba_cg
->default_groups
[i
]; i
++) {
2986 item
= &hba_cg
->default_groups
[i
]->cg_item
;
2987 hba_cg
->default_groups
[i
] = NULL
;
2988 config_item_put(item
);
2990 kfree(hba_cg
->default_groups
);
2991 hba_cg
->default_groups
= NULL
;
2993 * We expect subsys->su_group.default_groups to be released
2994 * by configfs subsystem provider logic..
2996 configfs_unregister_subsystem(subsys
);
2997 kfree(subsys
->su_group
.default_groups
);
2999 core_alua_free_lu_gp(default_lu_gp
);
3000 default_lu_gp
= NULL
;
3002 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
3003 " Infrastructure\n");
3005 core_dev_release_virtual_lun0();
3007 release_se_kmem_caches();
3010 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3011 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3012 MODULE_LICENSE("GPL");
3014 module_init(target_core_init_configfs
);
3015 module_exit(target_core_exit_configfs
);