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 struct list_head g_tf_list
;
56 static struct 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
->stop_session
) {
425 pr_err("Missing tfo->stop_session()\n");
428 if (!tfo
->fall_back_to_erl0
) {
429 pr_err("Missing tfo->fall_back_to_erl0()\n");
432 if (!tfo
->sess_logged_in
) {
433 pr_err("Missing tfo->sess_logged_in()\n");
436 if (!tfo
->sess_get_index
) {
437 pr_err("Missing tfo->sess_get_index()\n");
440 if (!tfo
->write_pending
) {
441 pr_err("Missing tfo->write_pending()\n");
444 if (!tfo
->write_pending_status
) {
445 pr_err("Missing tfo->write_pending_status()\n");
448 if (!tfo
->set_default_node_attributes
) {
449 pr_err("Missing tfo->set_default_node_attributes()\n");
452 if (!tfo
->get_task_tag
) {
453 pr_err("Missing tfo->get_task_tag()\n");
456 if (!tfo
->get_cmd_state
) {
457 pr_err("Missing tfo->get_cmd_state()\n");
460 if (!tfo
->queue_data_in
) {
461 pr_err("Missing tfo->queue_data_in()\n");
464 if (!tfo
->queue_status
) {
465 pr_err("Missing tfo->queue_status()\n");
468 if (!tfo
->queue_tm_rsp
) {
469 pr_err("Missing tfo->queue_tm_rsp()\n");
472 if (!tfo
->set_fabric_sense_len
) {
473 pr_err("Missing tfo->set_fabric_sense_len()\n");
476 if (!tfo
->get_fabric_sense_len
) {
477 pr_err("Missing tfo->get_fabric_sense_len()\n");
480 if (!tfo
->is_state_remove
) {
481 pr_err("Missing tfo->is_state_remove()\n");
485 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
486 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
487 * target_core_fabric_configfs.c WWN+TPG group context code.
489 if (!tfo
->fabric_make_wwn
) {
490 pr_err("Missing tfo->fabric_make_wwn()\n");
493 if (!tfo
->fabric_drop_wwn
) {
494 pr_err("Missing tfo->fabric_drop_wwn()\n");
497 if (!tfo
->fabric_make_tpg
) {
498 pr_err("Missing tfo->fabric_make_tpg()\n");
501 if (!tfo
->fabric_drop_tpg
) {
502 pr_err("Missing tfo->fabric_drop_tpg()\n");
510 * Called 2nd from fabric module with returned parameter of
511 * struct target_fabric_configfs * from target_fabric_configfs_init().
513 * Upon a successful registration, the new fabric's struct config_item is
514 * return. Also, a pointer to this struct is set in the passed
515 * struct target_fabric_configfs.
517 int target_fabric_configfs_register(
518 struct target_fabric_configfs
*tf
)
523 pr_err("Unable to locate target_fabric_configfs"
527 if (!tf
->tf_subsys
) {
528 pr_err("Unable to target struct config_subsystem"
532 ret
= target_fabric_tf_ops_check(tf
);
536 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>"
540 EXPORT_SYMBOL(target_fabric_configfs_register
);
542 void target_fabric_configfs_deregister(
543 struct target_fabric_configfs
*tf
)
545 struct configfs_subsystem
*su
;
548 pr_err("Unable to locate passed target_fabric_"
554 pr_err("Unable to locate passed tf->tf_subsys"
558 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
560 mutex_lock(&g_tf_lock
);
561 if (atomic_read(&tf
->tf_access_cnt
)) {
562 mutex_unlock(&g_tf_lock
);
563 pr_err("Non zero tf->tf_access_cnt for fabric %s\n",
567 list_del(&tf
->tf_list
);
568 mutex_unlock(&g_tf_lock
);
570 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
571 " %s\n", tf
->tf_name
);
572 tf
->tf_module
= NULL
;
573 tf
->tf_subsys
= NULL
;
576 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
579 EXPORT_SYMBOL(target_fabric_configfs_deregister
);
581 /*##############################################################################
582 // Stop functions called by external Target Fabrics Modules
583 //############################################################################*/
585 /* Start functions for struct config_item_type target_core_dev_attrib_cit */
587 #define DEF_DEV_ATTRIB_SHOW(_name) \
588 static ssize_t target_core_dev_show_attr_##_name( \
589 struct se_dev_attrib *da, \
592 struct se_device *dev; \
593 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
596 spin_lock(&se_dev->se_dev_lock); \
597 dev = se_dev->se_dev_ptr; \
599 spin_unlock(&se_dev->se_dev_lock); \
602 rb = snprintf(page, PAGE_SIZE, "%u\n", \
603 (u32)dev->se_sub_dev->se_dev_attrib._name); \
604 spin_unlock(&se_dev->se_dev_lock); \
609 #define DEF_DEV_ATTRIB_STORE(_name) \
610 static ssize_t target_core_dev_store_attr_##_name( \
611 struct se_dev_attrib *da, \
615 struct se_device *dev; \
616 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
620 spin_lock(&se_dev->se_dev_lock); \
621 dev = se_dev->se_dev_ptr; \
623 spin_unlock(&se_dev->se_dev_lock); \
626 ret = strict_strtoul(page, 0, &val); \
628 spin_unlock(&se_dev->se_dev_lock); \
629 pr_err("strict_strtoul() failed with" \
630 " ret: %d\n", ret); \
633 ret = se_dev_set_##_name(dev, (u32)val); \
634 spin_unlock(&se_dev->se_dev_lock); \
636 return (!ret) ? count : -EINVAL; \
639 #define DEF_DEV_ATTRIB(_name) \
640 DEF_DEV_ATTRIB_SHOW(_name); \
641 DEF_DEV_ATTRIB_STORE(_name);
643 #define DEF_DEV_ATTRIB_RO(_name) \
644 DEF_DEV_ATTRIB_SHOW(_name);
646 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib
, se_dev_attrib
);
647 #define SE_DEV_ATTR(_name, _mode) \
648 static struct target_core_dev_attrib_attribute \
649 target_core_dev_attrib_##_name = \
650 __CONFIGFS_EATTR(_name, _mode, \
651 target_core_dev_show_attr_##_name, \
652 target_core_dev_store_attr_##_name);
654 #define SE_DEV_ATTR_RO(_name); \
655 static struct target_core_dev_attrib_attribute \
656 target_core_dev_attrib_##_name = \
657 __CONFIGFS_EATTR_RO(_name, \
658 target_core_dev_show_attr_##_name);
660 DEF_DEV_ATTRIB(emulate_dpo
);
661 SE_DEV_ATTR(emulate_dpo
, S_IRUGO
| S_IWUSR
);
663 DEF_DEV_ATTRIB(emulate_fua_write
);
664 SE_DEV_ATTR(emulate_fua_write
, S_IRUGO
| S_IWUSR
);
666 DEF_DEV_ATTRIB(emulate_fua_read
);
667 SE_DEV_ATTR(emulate_fua_read
, S_IRUGO
| S_IWUSR
);
669 DEF_DEV_ATTRIB(emulate_write_cache
);
670 SE_DEV_ATTR(emulate_write_cache
, S_IRUGO
| S_IWUSR
);
672 DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl
);
673 SE_DEV_ATTR(emulate_ua_intlck_ctrl
, S_IRUGO
| S_IWUSR
);
675 DEF_DEV_ATTRIB(emulate_tas
);
676 SE_DEV_ATTR(emulate_tas
, S_IRUGO
| S_IWUSR
);
678 DEF_DEV_ATTRIB(emulate_tpu
);
679 SE_DEV_ATTR(emulate_tpu
, S_IRUGO
| S_IWUSR
);
681 DEF_DEV_ATTRIB(emulate_tpws
);
682 SE_DEV_ATTR(emulate_tpws
, S_IRUGO
| S_IWUSR
);
684 DEF_DEV_ATTRIB(enforce_pr_isids
);
685 SE_DEV_ATTR(enforce_pr_isids
, S_IRUGO
| S_IWUSR
);
687 DEF_DEV_ATTRIB(is_nonrot
);
688 SE_DEV_ATTR(is_nonrot
, S_IRUGO
| S_IWUSR
);
690 DEF_DEV_ATTRIB(emulate_rest_reord
);
691 SE_DEV_ATTR(emulate_rest_reord
, S_IRUGO
| S_IWUSR
);
693 DEF_DEV_ATTRIB_RO(hw_block_size
);
694 SE_DEV_ATTR_RO(hw_block_size
);
696 DEF_DEV_ATTRIB(block_size
);
697 SE_DEV_ATTR(block_size
, S_IRUGO
| S_IWUSR
);
699 DEF_DEV_ATTRIB_RO(hw_max_sectors
);
700 SE_DEV_ATTR_RO(hw_max_sectors
);
702 DEF_DEV_ATTRIB(max_sectors
);
703 SE_DEV_ATTR(max_sectors
, S_IRUGO
| S_IWUSR
);
705 DEF_DEV_ATTRIB(optimal_sectors
);
706 SE_DEV_ATTR(optimal_sectors
, S_IRUGO
| S_IWUSR
);
708 DEF_DEV_ATTRIB_RO(hw_queue_depth
);
709 SE_DEV_ATTR_RO(hw_queue_depth
);
711 DEF_DEV_ATTRIB(queue_depth
);
712 SE_DEV_ATTR(queue_depth
, S_IRUGO
| S_IWUSR
);
714 DEF_DEV_ATTRIB(max_unmap_lba_count
);
715 SE_DEV_ATTR(max_unmap_lba_count
, S_IRUGO
| S_IWUSR
);
717 DEF_DEV_ATTRIB(max_unmap_block_desc_count
);
718 SE_DEV_ATTR(max_unmap_block_desc_count
, S_IRUGO
| S_IWUSR
);
720 DEF_DEV_ATTRIB(unmap_granularity
);
721 SE_DEV_ATTR(unmap_granularity
, S_IRUGO
| S_IWUSR
);
723 DEF_DEV_ATTRIB(unmap_granularity_alignment
);
724 SE_DEV_ATTR(unmap_granularity_alignment
, S_IRUGO
| S_IWUSR
);
726 CONFIGFS_EATTR_OPS(target_core_dev_attrib
, se_dev_attrib
, da_group
);
728 static struct configfs_attribute
*target_core_dev_attrib_attrs
[] = {
729 &target_core_dev_attrib_emulate_dpo
.attr
,
730 &target_core_dev_attrib_emulate_fua_write
.attr
,
731 &target_core_dev_attrib_emulate_fua_read
.attr
,
732 &target_core_dev_attrib_emulate_write_cache
.attr
,
733 &target_core_dev_attrib_emulate_ua_intlck_ctrl
.attr
,
734 &target_core_dev_attrib_emulate_tas
.attr
,
735 &target_core_dev_attrib_emulate_tpu
.attr
,
736 &target_core_dev_attrib_emulate_tpws
.attr
,
737 &target_core_dev_attrib_enforce_pr_isids
.attr
,
738 &target_core_dev_attrib_is_nonrot
.attr
,
739 &target_core_dev_attrib_emulate_rest_reord
.attr
,
740 &target_core_dev_attrib_hw_block_size
.attr
,
741 &target_core_dev_attrib_block_size
.attr
,
742 &target_core_dev_attrib_hw_max_sectors
.attr
,
743 &target_core_dev_attrib_max_sectors
.attr
,
744 &target_core_dev_attrib_optimal_sectors
.attr
,
745 &target_core_dev_attrib_hw_queue_depth
.attr
,
746 &target_core_dev_attrib_queue_depth
.attr
,
747 &target_core_dev_attrib_max_unmap_lba_count
.attr
,
748 &target_core_dev_attrib_max_unmap_block_desc_count
.attr
,
749 &target_core_dev_attrib_unmap_granularity
.attr
,
750 &target_core_dev_attrib_unmap_granularity_alignment
.attr
,
754 static struct configfs_item_operations target_core_dev_attrib_ops
= {
755 .show_attribute
= target_core_dev_attrib_attr_show
,
756 .store_attribute
= target_core_dev_attrib_attr_store
,
759 static struct config_item_type target_core_dev_attrib_cit
= {
760 .ct_item_ops
= &target_core_dev_attrib_ops
,
761 .ct_attrs
= target_core_dev_attrib_attrs
,
762 .ct_owner
= THIS_MODULE
,
765 /* End functions for struct config_item_type target_core_dev_attrib_cit */
767 /* Start functions for struct config_item_type target_core_dev_wwn_cit */
769 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn
, t10_wwn
);
770 #define SE_DEV_WWN_ATTR(_name, _mode) \
771 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
772 __CONFIGFS_EATTR(_name, _mode, \
773 target_core_dev_wwn_show_attr_##_name, \
774 target_core_dev_wwn_store_attr_##_name);
776 #define SE_DEV_WWN_ATTR_RO(_name); \
778 static struct target_core_dev_wwn_attribute \
779 target_core_dev_wwn_##_name = \
780 __CONFIGFS_EATTR_RO(_name, \
781 target_core_dev_wwn_show_attr_##_name); \
785 * VPD page 0x80 Unit serial
787 static ssize_t
target_core_dev_wwn_show_attr_vpd_unit_serial(
788 struct t10_wwn
*t10_wwn
,
791 struct se_subsystem_dev
*se_dev
= t10_wwn
->t10_sub_dev
;
792 struct se_device
*dev
;
794 dev
= se_dev
->se_dev_ptr
;
798 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
799 &t10_wwn
->unit_serial
[0]);
802 static ssize_t
target_core_dev_wwn_store_attr_vpd_unit_serial(
803 struct t10_wwn
*t10_wwn
,
807 struct se_subsystem_dev
*su_dev
= t10_wwn
->t10_sub_dev
;
808 struct se_device
*dev
;
809 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
812 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
813 * from the struct scsi_device level firmware, do not allow
814 * VPD Unit Serial to be emulated.
816 * Note this struct scsi_device could also be emulating VPD
817 * information from its drivers/scsi LLD. But for now we assume
818 * it is doing 'the right thing' wrt a world wide unique
819 * VPD Unit Serial Number that OS dependent multipath can depend on.
821 if (su_dev
->su_dev_flags
& SDF_FIRMWARE_VPD_UNIT_SERIAL
) {
822 pr_err("Underlying SCSI device firmware provided VPD"
823 " Unit Serial, ignoring request\n");
827 if (strlen(page
) >= INQUIRY_VPD_SERIAL_LEN
) {
828 pr_err("Emulated VPD Unit Serial exceeds"
829 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
833 * Check to see if any active $FABRIC_MOD exports exist. If they
834 * do exist, fail here as changing this information on the fly
835 * (underneath the initiator side OS dependent multipath code)
836 * could cause negative effects.
838 dev
= su_dev
->se_dev_ptr
;
840 if (atomic_read(&dev
->dev_export_obj
.obj_access_count
)) {
841 pr_err("Unable to set VPD Unit Serial while"
842 " active %d $FABRIC_MOD exports exist\n",
843 atomic_read(&dev
->dev_export_obj
.obj_access_count
));
848 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
850 * Also, strip any newline added from the userspace
851 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
853 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
854 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
855 snprintf(su_dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
856 "%s", strstrip(buf
));
857 su_dev
->su_dev_flags
|= SDF_EMULATED_VPD_UNIT_SERIAL
;
859 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
860 " %s\n", su_dev
->t10_wwn
.unit_serial
);
865 SE_DEV_WWN_ATTR(vpd_unit_serial
, S_IRUGO
| S_IWUSR
);
868 * VPD page 0x83 Protocol Identifier
870 static ssize_t
target_core_dev_wwn_show_attr_vpd_protocol_identifier(
871 struct t10_wwn
*t10_wwn
,
874 struct se_subsystem_dev
*se_dev
= t10_wwn
->t10_sub_dev
;
875 struct se_device
*dev
;
877 unsigned char buf
[VPD_TMP_BUF_SIZE
];
880 dev
= se_dev
->se_dev_ptr
;
884 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
886 spin_lock(&t10_wwn
->t10_vpd_lock
);
887 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
888 if (!vpd
->protocol_identifier_set
)
891 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
893 if (len
+ strlen(buf
) >= PAGE_SIZE
)
896 len
+= sprintf(page
+len
, "%s", buf
);
898 spin_unlock(&t10_wwn
->t10_vpd_lock
);
903 static ssize_t
target_core_dev_wwn_store_attr_vpd_protocol_identifier(
904 struct t10_wwn
*t10_wwn
,
911 SE_DEV_WWN_ATTR(vpd_protocol_identifier
, S_IRUGO
| S_IWUSR
);
914 * Generic wrapper for dumping VPD identifiers by association.
916 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
917 static ssize_t target_core_dev_wwn_show_attr_##_name( \
918 struct t10_wwn *t10_wwn, \
921 struct se_subsystem_dev *se_dev = t10_wwn->t10_sub_dev; \
922 struct se_device *dev; \
923 struct t10_vpd *vpd; \
924 unsigned char buf[VPD_TMP_BUF_SIZE]; \
927 dev = se_dev->se_dev_ptr; \
931 spin_lock(&t10_wwn->t10_vpd_lock); \
932 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
933 if (vpd->association != _assoc) \
936 memset(buf, 0, VPD_TMP_BUF_SIZE); \
937 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
938 if (len + strlen(buf) >= PAGE_SIZE) \
940 len += sprintf(page+len, "%s", buf); \
942 memset(buf, 0, VPD_TMP_BUF_SIZE); \
943 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
944 if (len + strlen(buf) >= PAGE_SIZE) \
946 len += sprintf(page+len, "%s", buf); \
948 memset(buf, 0, VPD_TMP_BUF_SIZE); \
949 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
950 if (len + strlen(buf) >= PAGE_SIZE) \
952 len += sprintf(page+len, "%s", buf); \
954 spin_unlock(&t10_wwn->t10_vpd_lock); \
960 * VPD page 0x83 Association: Logical Unit
962 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
964 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
965 struct t10_wwn
*t10_wwn
,
972 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit
, S_IRUGO
| S_IWUSR
);
975 * VPD page 0x83 Association: Target Port
977 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
979 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_target_port(
980 struct t10_wwn
*t10_wwn
,
987 SE_DEV_WWN_ATTR(vpd_assoc_target_port
, S_IRUGO
| S_IWUSR
);
990 * VPD page 0x83 Association: SCSI Target Device
992 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
994 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
995 struct t10_wwn
*t10_wwn
,
1002 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device
, S_IRUGO
| S_IWUSR
);
1004 CONFIGFS_EATTR_OPS(target_core_dev_wwn
, t10_wwn
, t10_wwn_group
);
1006 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
1007 &target_core_dev_wwn_vpd_unit_serial
.attr
,
1008 &target_core_dev_wwn_vpd_protocol_identifier
.attr
,
1009 &target_core_dev_wwn_vpd_assoc_logical_unit
.attr
,
1010 &target_core_dev_wwn_vpd_assoc_target_port
.attr
,
1011 &target_core_dev_wwn_vpd_assoc_scsi_target_device
.attr
,
1015 static struct configfs_item_operations target_core_dev_wwn_ops
= {
1016 .show_attribute
= target_core_dev_wwn_attr_show
,
1017 .store_attribute
= target_core_dev_wwn_attr_store
,
1020 static struct config_item_type target_core_dev_wwn_cit
= {
1021 .ct_item_ops
= &target_core_dev_wwn_ops
,
1022 .ct_attrs
= target_core_dev_wwn_attrs
,
1023 .ct_owner
= THIS_MODULE
,
1026 /* End functions for struct config_item_type target_core_dev_wwn_cit */
1028 /* Start functions for struct config_item_type target_core_dev_pr_cit */
1030 CONFIGFS_EATTR_STRUCT(target_core_dev_pr
, se_subsystem_dev
);
1031 #define SE_DEV_PR_ATTR(_name, _mode) \
1032 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1033 __CONFIGFS_EATTR(_name, _mode, \
1034 target_core_dev_pr_show_attr_##_name, \
1035 target_core_dev_pr_store_attr_##_name);
1037 #define SE_DEV_PR_ATTR_RO(_name); \
1038 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1039 __CONFIGFS_EATTR_RO(_name, \
1040 target_core_dev_pr_show_attr_##_name);
1045 static ssize_t
target_core_dev_pr_show_spc3_res(
1046 struct se_device
*dev
,
1050 struct se_node_acl
*se_nacl
;
1051 struct t10_pr_registration
*pr_reg
;
1052 char i_buf
[PR_REG_ISID_ID_LEN
];
1055 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1057 spin_lock(&dev
->dev_reservation_lock
);
1058 pr_reg
= dev
->dev_pr_res_holder
;
1060 *len
+= sprintf(page
+ *len
, "No SPC-3 Reservation holder\n");
1061 spin_unlock(&dev
->dev_reservation_lock
);
1064 se_nacl
= pr_reg
->pr_reg_nacl
;
1065 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1066 PR_REG_ISID_ID_LEN
);
1068 *len
+= sprintf(page
+ *len
, "SPC-3 Reservation: %s Initiator: %s%s\n",
1069 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1070 se_nacl
->initiatorname
, (prf_isid
) ? &i_buf
[0] : "");
1071 spin_unlock(&dev
->dev_reservation_lock
);
1076 static ssize_t
target_core_dev_pr_show_spc2_res(
1077 struct se_device
*dev
,
1081 struct se_node_acl
*se_nacl
;
1083 spin_lock(&dev
->dev_reservation_lock
);
1084 se_nacl
= dev
->dev_reserved_node_acl
;
1086 *len
+= sprintf(page
+ *len
, "No SPC-2 Reservation holder\n");
1087 spin_unlock(&dev
->dev_reservation_lock
);
1090 *len
+= sprintf(page
+ *len
, "SPC-2 Reservation: %s Initiator: %s\n",
1091 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1092 se_nacl
->initiatorname
);
1093 spin_unlock(&dev
->dev_reservation_lock
);
1098 static ssize_t
target_core_dev_pr_show_attr_res_holder(
1099 struct se_subsystem_dev
*su_dev
,
1104 if (!su_dev
->se_dev_ptr
)
1107 switch (su_dev
->t10_pr
.res_type
) {
1108 case SPC3_PERSISTENT_RESERVATIONS
:
1109 target_core_dev_pr_show_spc3_res(su_dev
->se_dev_ptr
,
1112 case SPC2_RESERVATIONS
:
1113 target_core_dev_pr_show_spc2_res(su_dev
->se_dev_ptr
,
1116 case SPC_PASSTHROUGH
:
1117 len
+= sprintf(page
+len
, "Passthrough\n");
1120 len
+= sprintf(page
+len
, "Unknown\n");
1127 SE_DEV_PR_ATTR_RO(res_holder
);
1130 * res_pr_all_tgt_pts
1132 static ssize_t
target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1133 struct se_subsystem_dev
*su_dev
,
1136 struct se_device
*dev
;
1137 struct t10_pr_registration
*pr_reg
;
1140 dev
= su_dev
->se_dev_ptr
;
1144 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1147 spin_lock(&dev
->dev_reservation_lock
);
1148 pr_reg
= dev
->dev_pr_res_holder
;
1150 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1151 spin_unlock(&dev
->dev_reservation_lock
);
1155 * See All Target Ports (ALL_TG_PT) bit in spcr17, section 6.14.3
1156 * Basic PERSISTENT RESERVER OUT parameter list, page 290
1158 if (pr_reg
->pr_reg_all_tg_pt
)
1159 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1160 " Ports registration\n");
1162 len
= sprintf(page
, "SPC-3 Reservation: Single"
1163 " Target Port registration\n");
1164 spin_unlock(&dev
->dev_reservation_lock
);
1169 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts
);
1174 static ssize_t
target_core_dev_pr_show_attr_res_pr_generation(
1175 struct se_subsystem_dev
*su_dev
,
1178 if (!su_dev
->se_dev_ptr
)
1181 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1184 return sprintf(page
, "0x%08x\n", su_dev
->t10_pr
.pr_generation
);
1187 SE_DEV_PR_ATTR_RO(res_pr_generation
);
1190 * res_pr_holder_tg_port
1192 static ssize_t
target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1193 struct se_subsystem_dev
*su_dev
,
1196 struct se_device
*dev
;
1197 struct se_node_acl
*se_nacl
;
1199 struct se_portal_group
*se_tpg
;
1200 struct t10_pr_registration
*pr_reg
;
1201 struct target_core_fabric_ops
*tfo
;
1204 dev
= su_dev
->se_dev_ptr
;
1208 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1211 spin_lock(&dev
->dev_reservation_lock
);
1212 pr_reg
= dev
->dev_pr_res_holder
;
1214 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1215 spin_unlock(&dev
->dev_reservation_lock
);
1218 se_nacl
= pr_reg
->pr_reg_nacl
;
1219 se_tpg
= se_nacl
->se_tpg
;
1220 lun
= pr_reg
->pr_reg_tg_pt_lun
;
1221 tfo
= se_tpg
->se_tpg_tfo
;
1223 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1224 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1225 tfo
->tpg_get_wwn(se_tpg
));
1226 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1227 " Identifer Tag: %hu %s Portal Group Tag: %hu"
1228 " %s Logical Unit: %u\n", lun
->lun_sep
->sep_rtpi
,
1229 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1230 tfo
->get_fabric_name(), lun
->unpacked_lun
);
1231 spin_unlock(&dev
->dev_reservation_lock
);
1236 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port
);
1239 * res_pr_registered_i_pts
1241 static ssize_t
target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1242 struct se_subsystem_dev
*su_dev
,
1245 struct target_core_fabric_ops
*tfo
;
1246 struct t10_pr_registration
*pr_reg
;
1247 unsigned char buf
[384];
1248 char i_buf
[PR_REG_ISID_ID_LEN
];
1250 int reg_count
= 0, prf_isid
;
1252 if (!su_dev
->se_dev_ptr
)
1255 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1258 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1260 spin_lock(&su_dev
->t10_pr
.registration_lock
);
1261 list_for_each_entry(pr_reg
, &su_dev
->t10_pr
.registration_list
,
1264 memset(buf
, 0, 384);
1265 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1266 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1267 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1268 PR_REG_ISID_ID_LEN
);
1269 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1270 tfo
->get_fabric_name(),
1271 pr_reg
->pr_reg_nacl
->initiatorname
, (prf_isid
) ?
1272 &i_buf
[0] : "", pr_reg
->pr_res_key
,
1273 pr_reg
->pr_res_generation
);
1275 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1278 len
+= sprintf(page
+len
, "%s", buf
);
1281 spin_unlock(&su_dev
->t10_pr
.registration_lock
);
1284 len
+= sprintf(page
+len
, "None\n");
1289 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts
);
1294 static ssize_t
target_core_dev_pr_show_attr_res_pr_type(
1295 struct se_subsystem_dev
*su_dev
,
1298 struct se_device
*dev
;
1299 struct t10_pr_registration
*pr_reg
;
1302 dev
= su_dev
->se_dev_ptr
;
1306 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1309 spin_lock(&dev
->dev_reservation_lock
);
1310 pr_reg
= dev
->dev_pr_res_holder
;
1312 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1313 spin_unlock(&dev
->dev_reservation_lock
);
1316 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1317 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1318 spin_unlock(&dev
->dev_reservation_lock
);
1323 SE_DEV_PR_ATTR_RO(res_pr_type
);
1328 static ssize_t
target_core_dev_pr_show_attr_res_type(
1329 struct se_subsystem_dev
*su_dev
,
1334 if (!su_dev
->se_dev_ptr
)
1337 switch (su_dev
->t10_pr
.res_type
) {
1338 case SPC3_PERSISTENT_RESERVATIONS
:
1339 len
= sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1341 case SPC2_RESERVATIONS
:
1342 len
= sprintf(page
, "SPC2_RESERVATIONS\n");
1344 case SPC_PASSTHROUGH
:
1345 len
= sprintf(page
, "SPC_PASSTHROUGH\n");
1348 len
= sprintf(page
, "UNKNOWN\n");
1355 SE_DEV_PR_ATTR_RO(res_type
);
1361 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_active(
1362 struct se_subsystem_dev
*su_dev
,
1365 if (!su_dev
->se_dev_ptr
)
1368 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1371 return sprintf(page
, "APTPL Bit Status: %s\n",
1372 (su_dev
->t10_pr
.pr_aptpl_active
) ? "Activated" : "Disabled");
1375 SE_DEV_PR_ATTR_RO(res_aptpl_active
);
1378 * res_aptpl_metadata
1380 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_metadata(
1381 struct se_subsystem_dev
*su_dev
,
1384 if (!su_dev
->se_dev_ptr
)
1387 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1390 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1394 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1395 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1396 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1397 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1400 static match_table_t tokens
= {
1401 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1402 {Opt_initiator_node
, "initiator_node=%s"},
1403 {Opt_initiator_sid
, "initiator_sid=%s"},
1404 {Opt_sa_res_key
, "sa_res_key=%s"},
1405 {Opt_res_holder
, "res_holder=%d"},
1406 {Opt_res_type
, "res_type=%d"},
1407 {Opt_res_scope
, "res_scope=%d"},
1408 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1409 {Opt_mapped_lun
, "mapped_lun=%d"},
1410 {Opt_target_fabric
, "target_fabric=%s"},
1411 {Opt_target_node
, "target_node=%s"},
1412 {Opt_tpgt
, "tpgt=%d"},
1413 {Opt_port_rtpi
, "port_rtpi=%d"},
1414 {Opt_target_lun
, "target_lun=%d"},
1418 static ssize_t
target_core_dev_pr_store_attr_res_aptpl_metadata(
1419 struct se_subsystem_dev
*su_dev
,
1423 struct se_device
*dev
;
1424 unsigned char *i_fabric
= NULL
, *i_port
= NULL
, *isid
= NULL
;
1425 unsigned char *t_fabric
= NULL
, *t_port
= NULL
;
1426 char *orig
, *ptr
, *arg_p
, *opts
;
1427 substring_t args
[MAX_OPT_ARGS
];
1428 unsigned long long tmp_ll
;
1430 u32 mapped_lun
= 0, target_lun
= 0;
1431 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1432 u16 port_rpti
= 0, tpgt
= 0;
1435 dev
= su_dev
->se_dev_ptr
;
1439 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1442 if (atomic_read(&dev
->dev_export_obj
.obj_access_count
)) {
1443 pr_debug("Unable to process APTPL metadata while"
1444 " active fabric exports exist\n");
1448 opts
= kstrdup(page
, GFP_KERNEL
);
1453 while ((ptr
= strsep(&opts
, ",\n")) != NULL
) {
1457 token
= match_token(ptr
, tokens
, args
);
1459 case Opt_initiator_fabric
:
1460 i_fabric
= match_strdup(&args
[0]);
1466 case Opt_initiator_node
:
1467 i_port
= match_strdup(&args
[0]);
1472 if (strlen(i_port
) >= PR_APTPL_MAX_IPORT_LEN
) {
1473 pr_err("APTPL metadata initiator_node="
1474 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1475 PR_APTPL_MAX_IPORT_LEN
);
1480 case Opt_initiator_sid
:
1481 isid
= match_strdup(&args
[0]);
1486 if (strlen(isid
) >= PR_REG_ISID_LEN
) {
1487 pr_err("APTPL metadata initiator_isid"
1488 "= exceeds PR_REG_ISID_LEN: %d\n",
1494 case Opt_sa_res_key
:
1495 arg_p
= match_strdup(&args
[0]);
1500 ret
= strict_strtoull(arg_p
, 0, &tmp_ll
);
1502 pr_err("strict_strtoull() failed for"
1506 sa_res_key
= (u64
)tmp_ll
;
1509 * PR APTPL Metadata for Reservation
1511 case Opt_res_holder
:
1512 match_int(args
, &arg
);
1516 match_int(args
, &arg
);
1520 match_int(args
, &arg
);
1523 case Opt_res_all_tg_pt
:
1524 match_int(args
, &arg
);
1525 all_tg_pt
= (int)arg
;
1527 case Opt_mapped_lun
:
1528 match_int(args
, &arg
);
1529 mapped_lun
= (u32
)arg
;
1532 * PR APTPL Metadata for Target Port
1534 case Opt_target_fabric
:
1535 t_fabric
= match_strdup(&args
[0]);
1541 case Opt_target_node
:
1542 t_port
= match_strdup(&args
[0]);
1547 if (strlen(t_port
) >= PR_APTPL_MAX_TPORT_LEN
) {
1548 pr_err("APTPL metadata target_node="
1549 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1550 PR_APTPL_MAX_TPORT_LEN
);
1556 match_int(args
, &arg
);
1560 match_int(args
, &arg
);
1561 port_rpti
= (u16
)arg
;
1563 case Opt_target_lun
:
1564 match_int(args
, &arg
);
1565 target_lun
= (u32
)arg
;
1572 if (!i_port
|| !t_port
|| !sa_res_key
) {
1573 pr_err("Illegal parameters for APTPL registration\n");
1578 if (res_holder
&& !(type
)) {
1579 pr_err("Illegal PR type: 0x%02x for reservation"
1585 ret
= core_scsi3_alloc_aptpl_registration(&su_dev
->t10_pr
, sa_res_key
,
1586 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1587 res_holder
, all_tg_pt
, type
);
1595 return (ret
== 0) ? count
: ret
;
1598 SE_DEV_PR_ATTR(res_aptpl_metadata
, S_IRUGO
| S_IWUSR
);
1600 CONFIGFS_EATTR_OPS(target_core_dev_pr
, se_subsystem_dev
, se_dev_pr_group
);
1602 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1603 &target_core_dev_pr_res_holder
.attr
,
1604 &target_core_dev_pr_res_pr_all_tgt_pts
.attr
,
1605 &target_core_dev_pr_res_pr_generation
.attr
,
1606 &target_core_dev_pr_res_pr_holder_tg_port
.attr
,
1607 &target_core_dev_pr_res_pr_registered_i_pts
.attr
,
1608 &target_core_dev_pr_res_pr_type
.attr
,
1609 &target_core_dev_pr_res_type
.attr
,
1610 &target_core_dev_pr_res_aptpl_active
.attr
,
1611 &target_core_dev_pr_res_aptpl_metadata
.attr
,
1615 static struct configfs_item_operations target_core_dev_pr_ops
= {
1616 .show_attribute
= target_core_dev_pr_attr_show
,
1617 .store_attribute
= target_core_dev_pr_attr_store
,
1620 static struct config_item_type target_core_dev_pr_cit
= {
1621 .ct_item_ops
= &target_core_dev_pr_ops
,
1622 .ct_attrs
= target_core_dev_pr_attrs
,
1623 .ct_owner
= THIS_MODULE
,
1626 /* End functions for struct config_item_type target_core_dev_pr_cit */
1628 /* Start functions for struct config_item_type target_core_dev_cit */
1630 static ssize_t
target_core_show_dev_info(void *p
, char *page
)
1632 struct se_subsystem_dev
*se_dev
= p
;
1633 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1634 struct se_subsystem_api
*t
= hba
->transport
;
1636 ssize_t read_bytes
= 0;
1638 if (!se_dev
->se_dev_ptr
)
1641 transport_dump_dev_state(se_dev
->se_dev_ptr
, page
, &bl
);
1643 read_bytes
+= t
->show_configfs_dev_params(hba
, se_dev
, page
+read_bytes
);
1647 static struct target_core_configfs_attribute target_core_attr_dev_info
= {
1648 .attr
= { .ca_owner
= THIS_MODULE
,
1650 .ca_mode
= S_IRUGO
},
1651 .show
= target_core_show_dev_info
,
1655 static ssize_t
target_core_store_dev_control(
1660 struct se_subsystem_dev
*se_dev
= p
;
1661 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1662 struct se_subsystem_api
*t
= hba
->transport
;
1664 if (!se_dev
->se_dev_su_ptr
) {
1665 pr_err("Unable to locate struct se_subsystem_dev>se"
1670 return t
->set_configfs_dev_params(hba
, se_dev
, page
, count
);
1673 static struct target_core_configfs_attribute target_core_attr_dev_control
= {
1674 .attr
= { .ca_owner
= THIS_MODULE
,
1675 .ca_name
= "control",
1676 .ca_mode
= S_IWUSR
},
1678 .store
= target_core_store_dev_control
,
1681 static ssize_t
target_core_show_dev_alias(void *p
, char *page
)
1683 struct se_subsystem_dev
*se_dev
= p
;
1685 if (!(se_dev
->su_dev_flags
& SDF_USING_ALIAS
))
1688 return snprintf(page
, PAGE_SIZE
, "%s\n", se_dev
->se_dev_alias
);
1691 static ssize_t
target_core_store_dev_alias(
1696 struct se_subsystem_dev
*se_dev
= p
;
1697 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1700 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1701 pr_err("alias count: %d exceeds"
1702 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1703 SE_DEV_ALIAS_LEN
-1);
1707 se_dev
->su_dev_flags
|= SDF_USING_ALIAS
;
1708 read_bytes
= snprintf(&se_dev
->se_dev_alias
[0], SE_DEV_ALIAS_LEN
,
1711 if (se_dev
->se_dev_alias
[read_bytes
- 1] == '\n')
1712 se_dev
->se_dev_alias
[read_bytes
- 1] = '\0';
1714 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
1715 config_item_name(&hba
->hba_group
.cg_item
),
1716 config_item_name(&se_dev
->se_dev_group
.cg_item
),
1717 se_dev
->se_dev_alias
);
1722 static struct target_core_configfs_attribute target_core_attr_dev_alias
= {
1723 .attr
= { .ca_owner
= THIS_MODULE
,
1725 .ca_mode
= S_IRUGO
| S_IWUSR
},
1726 .show
= target_core_show_dev_alias
,
1727 .store
= target_core_store_dev_alias
,
1730 static ssize_t
target_core_show_dev_udev_path(void *p
, char *page
)
1732 struct se_subsystem_dev
*se_dev
= p
;
1734 if (!(se_dev
->su_dev_flags
& SDF_USING_UDEV_PATH
))
1737 return snprintf(page
, PAGE_SIZE
, "%s\n", se_dev
->se_dev_udev_path
);
1740 static ssize_t
target_core_store_dev_udev_path(
1745 struct se_subsystem_dev
*se_dev
= p
;
1746 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1749 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1750 pr_err("udev_path count: %d exceeds"
1751 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1752 SE_UDEV_PATH_LEN
-1);
1756 se_dev
->su_dev_flags
|= SDF_USING_UDEV_PATH
;
1757 read_bytes
= snprintf(&se_dev
->se_dev_udev_path
[0], SE_UDEV_PATH_LEN
,
1760 if (se_dev
->se_dev_udev_path
[read_bytes
- 1] == '\n')
1761 se_dev
->se_dev_udev_path
[read_bytes
- 1] = '\0';
1763 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1764 config_item_name(&hba
->hba_group
.cg_item
),
1765 config_item_name(&se_dev
->se_dev_group
.cg_item
),
1766 se_dev
->se_dev_udev_path
);
1771 static struct target_core_configfs_attribute target_core_attr_dev_udev_path
= {
1772 .attr
= { .ca_owner
= THIS_MODULE
,
1773 .ca_name
= "udev_path",
1774 .ca_mode
= S_IRUGO
| S_IWUSR
},
1775 .show
= target_core_show_dev_udev_path
,
1776 .store
= target_core_store_dev_udev_path
,
1779 static ssize_t
target_core_store_dev_enable(
1784 struct se_subsystem_dev
*se_dev
= p
;
1785 struct se_device
*dev
;
1786 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1787 struct se_subsystem_api
*t
= hba
->transport
;
1790 ptr
= strstr(page
, "1");
1792 pr_err("For dev_enable ops, only valid value"
1796 if (se_dev
->se_dev_ptr
) {
1797 pr_err("se_dev->se_dev_ptr already set for storage"
1802 if (t
->check_configfs_dev_params(hba
, se_dev
) < 0)
1805 dev
= t
->create_virtdevice(hba
, se_dev
, se_dev
->se_dev_su_ptr
);
1807 return PTR_ERR(dev
);
1811 se_dev
->se_dev_ptr
= dev
;
1812 pr_debug("Target_Core_ConfigFS: Registered se_dev->se_dev_ptr:"
1813 " %p\n", se_dev
->se_dev_ptr
);
1818 static struct target_core_configfs_attribute target_core_attr_dev_enable
= {
1819 .attr
= { .ca_owner
= THIS_MODULE
,
1820 .ca_name
= "enable",
1821 .ca_mode
= S_IWUSR
},
1823 .store
= target_core_store_dev_enable
,
1826 static ssize_t
target_core_show_alua_lu_gp(void *p
, char *page
)
1828 struct se_device
*dev
;
1829 struct se_subsystem_dev
*su_dev
= p
;
1830 struct config_item
*lu_ci
;
1831 struct t10_alua_lu_gp
*lu_gp
;
1832 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1835 dev
= su_dev
->se_dev_ptr
;
1839 if (su_dev
->t10_alua
.alua_type
!= SPC3_ALUA_EMULATED
)
1842 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1844 pr_err("NULL struct se_device->dev_alua_lu_gp_mem"
1849 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1850 lu_gp
= lu_gp_mem
->lu_gp
;
1852 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1853 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1854 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1856 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1861 static ssize_t
target_core_store_alua_lu_gp(
1866 struct se_device
*dev
;
1867 struct se_subsystem_dev
*su_dev
= p
;
1868 struct se_hba
*hba
= su_dev
->se_dev_hba
;
1869 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1870 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1871 unsigned char buf
[LU_GROUP_NAME_BUF
];
1874 dev
= su_dev
->se_dev_ptr
;
1878 if (su_dev
->t10_alua
.alua_type
!= SPC3_ALUA_EMULATED
) {
1879 pr_warn("SPC3_ALUA_EMULATED not enabled for %s/%s\n",
1880 config_item_name(&hba
->hba_group
.cg_item
),
1881 config_item_name(&su_dev
->se_dev_group
.cg_item
));
1884 if (count
> LU_GROUP_NAME_BUF
) {
1885 pr_err("ALUA LU Group Alias too large!\n");
1888 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1889 memcpy(buf
, page
, count
);
1891 * Any ALUA logical unit alias besides "NULL" means we will be
1892 * making a new group association.
1894 if (strcmp(strstrip(buf
), "NULL")) {
1896 * core_alua_get_lu_gp_by_name() will increment reference to
1897 * struct t10_alua_lu_gp. This reference is released with
1898 * core_alua_get_lu_gp_by_name below().
1900 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
1904 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1907 core_alua_put_lu_gp_from_name(lu_gp_new
);
1908 pr_err("NULL struct se_device->dev_alua_lu_gp_mem"
1913 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1914 lu_gp
= lu_gp_mem
->lu_gp
;
1917 * Clearing an existing lu_gp association, and replacing
1921 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
1922 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1924 config_item_name(&hba
->hba_group
.cg_item
),
1925 config_item_name(&su_dev
->se_dev_group
.cg_item
),
1926 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1929 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1930 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1935 * Removing existing association of lu_gp_mem with lu_gp
1937 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1941 * Associate lu_gp_mem with lu_gp_new.
1943 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
1944 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1946 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1947 " core/alua/lu_gps/%s, ID: %hu\n",
1948 (move
) ? "Moving" : "Adding",
1949 config_item_name(&hba
->hba_group
.cg_item
),
1950 config_item_name(&su_dev
->se_dev_group
.cg_item
),
1951 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
1952 lu_gp_new
->lu_gp_id
);
1954 core_alua_put_lu_gp_from_name(lu_gp_new
);
1958 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp
= {
1959 .attr
= { .ca_owner
= THIS_MODULE
,
1960 .ca_name
= "alua_lu_gp",
1961 .ca_mode
= S_IRUGO
| S_IWUSR
},
1962 .show
= target_core_show_alua_lu_gp
,
1963 .store
= target_core_store_alua_lu_gp
,
1966 static struct configfs_attribute
*lio_core_dev_attrs
[] = {
1967 &target_core_attr_dev_info
.attr
,
1968 &target_core_attr_dev_control
.attr
,
1969 &target_core_attr_dev_alias
.attr
,
1970 &target_core_attr_dev_udev_path
.attr
,
1971 &target_core_attr_dev_enable
.attr
,
1972 &target_core_attr_dev_alua_lu_gp
.attr
,
1976 static void target_core_dev_release(struct config_item
*item
)
1978 struct se_subsystem_dev
*se_dev
= container_of(to_config_group(item
),
1979 struct se_subsystem_dev
, se_dev_group
);
1980 struct se_hba
*hba
= item_to_hba(&se_dev
->se_dev_hba
->hba_group
.cg_item
);
1981 struct se_subsystem_api
*t
= hba
->transport
;
1982 struct config_group
*dev_cg
= &se_dev
->se_dev_group
;
1984 kfree(dev_cg
->default_groups
);
1986 * This pointer will set when the storage is enabled with:
1987 *`echo 1 > $CONFIGFS/core/$HBA/$DEV/dev_enable`
1989 if (se_dev
->se_dev_ptr
) {
1990 pr_debug("Target_Core_ConfigFS: Calling se_free_"
1991 "virtual_device() for se_dev_ptr: %p\n",
1992 se_dev
->se_dev_ptr
);
1994 se_free_virtual_device(se_dev
->se_dev_ptr
, hba
);
1997 * Release struct se_subsystem_dev->se_dev_su_ptr..
1999 pr_debug("Target_Core_ConfigFS: Calling t->free_"
2000 "device() for se_dev_su_ptr: %p\n",
2001 se_dev
->se_dev_su_ptr
);
2003 t
->free_device(se_dev
->se_dev_su_ptr
);
2006 pr_debug("Target_Core_ConfigFS: Deallocating se_subsystem"
2007 "_dev_t: %p\n", se_dev
);
2011 static ssize_t
target_core_dev_show(struct config_item
*item
,
2012 struct configfs_attribute
*attr
,
2015 struct se_subsystem_dev
*se_dev
= container_of(
2016 to_config_group(item
), struct se_subsystem_dev
,
2018 struct target_core_configfs_attribute
*tc_attr
= container_of(
2019 attr
, struct target_core_configfs_attribute
, attr
);
2024 return tc_attr
->show(se_dev
, page
);
2027 static ssize_t
target_core_dev_store(struct config_item
*item
,
2028 struct configfs_attribute
*attr
,
2029 const char *page
, size_t count
)
2031 struct se_subsystem_dev
*se_dev
= container_of(
2032 to_config_group(item
), struct se_subsystem_dev
,
2034 struct target_core_configfs_attribute
*tc_attr
= container_of(
2035 attr
, struct target_core_configfs_attribute
, attr
);
2037 if (!tc_attr
->store
)
2040 return tc_attr
->store(se_dev
, page
, count
);
2043 static struct configfs_item_operations target_core_dev_item_ops
= {
2044 .release
= target_core_dev_release
,
2045 .show_attribute
= target_core_dev_show
,
2046 .store_attribute
= target_core_dev_store
,
2049 static struct config_item_type target_core_dev_cit
= {
2050 .ct_item_ops
= &target_core_dev_item_ops
,
2051 .ct_attrs
= lio_core_dev_attrs
,
2052 .ct_owner
= THIS_MODULE
,
2055 /* End functions for struct config_item_type target_core_dev_cit */
2057 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
2059 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp
, t10_alua_lu_gp
);
2060 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
2061 static struct target_core_alua_lu_gp_attribute \
2062 target_core_alua_lu_gp_##_name = \
2063 __CONFIGFS_EATTR(_name, _mode, \
2064 target_core_alua_lu_gp_show_attr_##_name, \
2065 target_core_alua_lu_gp_store_attr_##_name);
2067 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
2068 static struct target_core_alua_lu_gp_attribute \
2069 target_core_alua_lu_gp_##_name = \
2070 __CONFIGFS_EATTR_RO(_name, \
2071 target_core_alua_lu_gp_show_attr_##_name);
2076 static ssize_t
target_core_alua_lu_gp_show_attr_lu_gp_id(
2077 struct t10_alua_lu_gp
*lu_gp
,
2080 if (!lu_gp
->lu_gp_valid_id
)
2083 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
2086 static ssize_t
target_core_alua_lu_gp_store_attr_lu_gp_id(
2087 struct t10_alua_lu_gp
*lu_gp
,
2091 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2092 unsigned long lu_gp_id
;
2095 ret
= strict_strtoul(page
, 0, &lu_gp_id
);
2097 pr_err("strict_strtoul() returned %d for"
2098 " lu_gp_id\n", ret
);
2101 if (lu_gp_id
> 0x0000ffff) {
2102 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
2103 " 0x0000ffff\n", lu_gp_id
);
2107 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
2111 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
2112 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2113 config_item_name(&alua_lu_gp_cg
->cg_item
),
2119 SE_DEV_ALUA_LU_ATTR(lu_gp_id
, S_IRUGO
| S_IWUSR
);
2124 static ssize_t
target_core_alua_lu_gp_show_attr_members(
2125 struct t10_alua_lu_gp
*lu_gp
,
2128 struct se_device
*dev
;
2130 struct se_subsystem_dev
*su_dev
;
2131 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2132 ssize_t len
= 0, cur_len
;
2133 unsigned char buf
[LU_GROUP_NAME_BUF
];
2135 memset(buf
, 0, LU_GROUP_NAME_BUF
);
2137 spin_lock(&lu_gp
->lu_gp_lock
);
2138 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
2139 dev
= lu_gp_mem
->lu_gp_mem_dev
;
2140 su_dev
= dev
->se_sub_dev
;
2141 hba
= su_dev
->se_dev_hba
;
2143 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
2144 config_item_name(&hba
->hba_group
.cg_item
),
2145 config_item_name(&su_dev
->se_dev_group
.cg_item
));
2146 cur_len
++; /* Extra byte for NULL terminator */
2148 if ((cur_len
+ len
) > PAGE_SIZE
) {
2149 pr_warn("Ran out of lu_gp_show_attr"
2150 "_members buffer\n");
2153 memcpy(page
+len
, buf
, cur_len
);
2156 spin_unlock(&lu_gp
->lu_gp_lock
);
2161 SE_DEV_ALUA_LU_ATTR_RO(members
);
2163 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp
, t10_alua_lu_gp
, lu_gp_group
);
2165 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
2166 &target_core_alua_lu_gp_lu_gp_id
.attr
,
2167 &target_core_alua_lu_gp_members
.attr
,
2171 static void target_core_alua_lu_gp_release(struct config_item
*item
)
2173 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2174 struct t10_alua_lu_gp
, lu_gp_group
);
2176 core_alua_free_lu_gp(lu_gp
);
2179 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
2180 .release
= target_core_alua_lu_gp_release
,
2181 .show_attribute
= target_core_alua_lu_gp_attr_show
,
2182 .store_attribute
= target_core_alua_lu_gp_attr_store
,
2185 static struct config_item_type target_core_alua_lu_gp_cit
= {
2186 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
2187 .ct_attrs
= target_core_alua_lu_gp_attrs
,
2188 .ct_owner
= THIS_MODULE
,
2191 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
2193 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
2195 static struct config_group
*target_core_alua_create_lu_gp(
2196 struct config_group
*group
,
2199 struct t10_alua_lu_gp
*lu_gp
;
2200 struct config_group
*alua_lu_gp_cg
= NULL
;
2201 struct config_item
*alua_lu_gp_ci
= NULL
;
2203 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
2207 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2208 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
2210 config_group_init_type_name(alua_lu_gp_cg
, name
,
2211 &target_core_alua_lu_gp_cit
);
2213 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2214 " Group: core/alua/lu_gps/%s\n",
2215 config_item_name(alua_lu_gp_ci
));
2217 return alua_lu_gp_cg
;
2221 static void target_core_alua_drop_lu_gp(
2222 struct config_group
*group
,
2223 struct config_item
*item
)
2225 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2226 struct t10_alua_lu_gp
, lu_gp_group
);
2228 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2229 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2230 config_item_name(item
), lu_gp
->lu_gp_id
);
2232 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
2233 * -> target_core_alua_lu_gp_release()
2235 config_item_put(item
);
2238 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
2239 .make_group
= &target_core_alua_create_lu_gp
,
2240 .drop_item
= &target_core_alua_drop_lu_gp
,
2243 static struct config_item_type target_core_alua_lu_gps_cit
= {
2244 .ct_item_ops
= NULL
,
2245 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
2246 .ct_owner
= THIS_MODULE
,
2249 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
2251 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2253 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
);
2254 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
2255 static struct target_core_alua_tg_pt_gp_attribute \
2256 target_core_alua_tg_pt_gp_##_name = \
2257 __CONFIGFS_EATTR(_name, _mode, \
2258 target_core_alua_tg_pt_gp_show_attr_##_name, \
2259 target_core_alua_tg_pt_gp_store_attr_##_name);
2261 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2262 static struct target_core_alua_tg_pt_gp_attribute \
2263 target_core_alua_tg_pt_gp_##_name = \
2264 __CONFIGFS_EATTR_RO(_name, \
2265 target_core_alua_tg_pt_gp_show_attr_##_name);
2270 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2271 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2274 return sprintf(page
, "%d\n",
2275 atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
));
2278 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2279 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2283 struct se_subsystem_dev
*su_dev
= tg_pt_gp
->tg_pt_gp_su_dev
;
2287 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2288 pr_err("Unable to do implict ALUA on non valid"
2289 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2293 ret
= strict_strtoul(page
, 0, &tmp
);
2295 pr_err("Unable to extract new ALUA access state from"
2299 new_state
= (int)tmp
;
2301 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICT_ALUA
)) {
2302 pr_err("Unable to process implict configfs ALUA"
2303 " transition while TPGS_IMPLICT_ALUA is diabled\n");
2307 ret
= core_alua_do_port_transition(tg_pt_gp
, su_dev
->se_dev_ptr
,
2308 NULL
, NULL
, new_state
, 0);
2309 return (!ret
) ? count
: -EINVAL
;
2312 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state
, S_IRUGO
| S_IWUSR
);
2315 * alua_access_status
2317 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2318 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2321 return sprintf(page
, "%s\n",
2322 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2325 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2326 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2331 int new_status
, ret
;
2333 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2334 pr_err("Unable to do set ALUA access status on non"
2335 " valid tg_pt_gp ID: %hu\n",
2336 tg_pt_gp
->tg_pt_gp_valid_id
);
2340 ret
= strict_strtoul(page
, 0, &tmp
);
2342 pr_err("Unable to extract new ALUA access status"
2343 " from %s\n", page
);
2346 new_status
= (int)tmp
;
2348 if ((new_status
!= ALUA_STATUS_NONE
) &&
2349 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
) &&
2350 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
)) {
2351 pr_err("Illegal ALUA access status: 0x%02x\n",
2356 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2360 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status
, S_IRUGO
| S_IWUSR
);
2365 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2366 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2369 return core_alua_show_access_type(tg_pt_gp
, page
);
2372 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2373 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2377 return core_alua_store_access_type(tg_pt_gp
, page
, count
);
2380 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type
, S_IRUGO
| S_IWUSR
);
2383 * alua_write_metadata
2385 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2386 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2389 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_write_metadata
);
2392 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2393 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2400 ret
= strict_strtoul(page
, 0, &tmp
);
2402 pr_err("Unable to extract alua_write_metadata\n");
2406 if ((tmp
!= 0) && (tmp
!= 1)) {
2407 pr_err("Illegal value for alua_write_metadata:"
2411 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2416 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata
, S_IRUGO
| S_IWUSR
);
2423 static ssize_t
target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2424 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2427 return core_alua_show_nonop_delay_msecs(tg_pt_gp
, page
);
2431 static ssize_t
target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2432 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2436 return core_alua_store_nonop_delay_msecs(tg_pt_gp
, page
, count
);
2439 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs
, S_IRUGO
| S_IWUSR
);
2444 static ssize_t
target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2445 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2448 return core_alua_show_trans_delay_msecs(tg_pt_gp
, page
);
2451 static ssize_t
target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2452 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2456 return core_alua_store_trans_delay_msecs(tg_pt_gp
, page
, count
);
2459 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs
, S_IRUGO
| S_IWUSR
);
2465 static ssize_t
target_core_alua_tg_pt_gp_show_attr_preferred(
2466 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2469 return core_alua_show_preferred_bit(tg_pt_gp
, page
);
2472 static ssize_t
target_core_alua_tg_pt_gp_store_attr_preferred(
2473 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2477 return core_alua_store_preferred_bit(tg_pt_gp
, page
, count
);
2480 SE_DEV_ALUA_TG_PT_ATTR(preferred
, S_IRUGO
| S_IWUSR
);
2485 static ssize_t
target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2486 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2489 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
2492 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2495 static ssize_t
target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2496 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2500 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2501 unsigned long tg_pt_gp_id
;
2504 ret
= strict_strtoul(page
, 0, &tg_pt_gp_id
);
2506 pr_err("strict_strtoul() returned %d for"
2507 " tg_pt_gp_id\n", ret
);
2510 if (tg_pt_gp_id
> 0x0000ffff) {
2511 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:"
2512 " 0x0000ffff\n", tg_pt_gp_id
);
2516 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2520 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
2521 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2522 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2523 tg_pt_gp
->tg_pt_gp_id
);
2528 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id
, S_IRUGO
| S_IWUSR
);
2533 static ssize_t
target_core_alua_tg_pt_gp_show_attr_members(
2534 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2537 struct se_port
*port
;
2538 struct se_portal_group
*tpg
;
2540 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
2541 ssize_t len
= 0, cur_len
;
2542 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2544 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2546 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2547 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
2548 tg_pt_gp_mem_list
) {
2549 port
= tg_pt_gp_mem
->tg_pt
;
2550 tpg
= port
->sep_tpg
;
2551 lun
= port
->sep_lun
;
2553 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2554 "/%s\n", tpg
->se_tpg_tfo
->get_fabric_name(),
2555 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
2556 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
2557 config_item_name(&lun
->lun_group
.cg_item
));
2558 cur_len
++; /* Extra byte for NULL terminator */
2560 if ((cur_len
+ len
) > PAGE_SIZE
) {
2561 pr_warn("Ran out of lu_gp_show_attr"
2562 "_members buffer\n");
2565 memcpy(page
+len
, buf
, cur_len
);
2568 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2573 SE_DEV_ALUA_TG_PT_ATTR_RO(members
);
2575 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
,
2578 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2579 &target_core_alua_tg_pt_gp_alua_access_state
.attr
,
2580 &target_core_alua_tg_pt_gp_alua_access_status
.attr
,
2581 &target_core_alua_tg_pt_gp_alua_access_type
.attr
,
2582 &target_core_alua_tg_pt_gp_alua_write_metadata
.attr
,
2583 &target_core_alua_tg_pt_gp_nonop_delay_msecs
.attr
,
2584 &target_core_alua_tg_pt_gp_trans_delay_msecs
.attr
,
2585 &target_core_alua_tg_pt_gp_preferred
.attr
,
2586 &target_core_alua_tg_pt_gp_tg_pt_gp_id
.attr
,
2587 &target_core_alua_tg_pt_gp_members
.attr
,
2591 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2593 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2594 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2596 core_alua_free_tg_pt_gp(tg_pt_gp
);
2599 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2600 .release
= target_core_alua_tg_pt_gp_release
,
2601 .show_attribute
= target_core_alua_tg_pt_gp_attr_show
,
2602 .store_attribute
= target_core_alua_tg_pt_gp_attr_store
,
2605 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2606 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2607 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2608 .ct_owner
= THIS_MODULE
,
2611 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2613 /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2615 static struct config_group
*target_core_alua_create_tg_pt_gp(
2616 struct config_group
*group
,
2619 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2620 alua_tg_pt_gps_group
);
2621 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2622 struct se_subsystem_dev
*su_dev
= alua
->t10_sub_dev
;
2623 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2624 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2626 tg_pt_gp
= core_alua_allocate_tg_pt_gp(su_dev
, name
, 0);
2630 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2631 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2633 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2634 &target_core_alua_tg_pt_gp_cit
);
2636 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
2637 " Group: alua/tg_pt_gps/%s\n",
2638 config_item_name(alua_tg_pt_gp_ci
));
2640 return alua_tg_pt_gp_cg
;
2643 static void target_core_alua_drop_tg_pt_gp(
2644 struct config_group
*group
,
2645 struct config_item
*item
)
2647 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2648 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2650 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
2651 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2652 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2654 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2655 * -> target_core_alua_tg_pt_gp_release().
2657 config_item_put(item
);
2660 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2661 .make_group
= &target_core_alua_create_tg_pt_gp
,
2662 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2665 static struct config_item_type target_core_alua_tg_pt_gps_cit
= {
2666 .ct_group_ops
= &target_core_alua_tg_pt_gps_group_ops
,
2667 .ct_owner
= THIS_MODULE
,
2670 /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2672 /* Start functions for struct config_item_type target_core_alua_cit */
2675 * target_core_alua_cit is a ConfigFS group that lives under
2676 * /sys/kernel/config/target/core/alua. There are default groups
2677 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2678 * target_core_alua_cit in target_core_init_configfs() below.
2680 static struct config_item_type target_core_alua_cit
= {
2681 .ct_item_ops
= NULL
,
2683 .ct_owner
= THIS_MODULE
,
2686 /* End functions for struct config_item_type target_core_alua_cit */
2688 /* Start functions for struct config_item_type target_core_stat_cit */
2690 static struct config_group
*target_core_stat_mkdir(
2691 struct config_group
*group
,
2694 return ERR_PTR(-ENOSYS
);
2697 static void target_core_stat_rmdir(
2698 struct config_group
*group
,
2699 struct config_item
*item
)
2704 static struct configfs_group_operations target_core_stat_group_ops
= {
2705 .make_group
= &target_core_stat_mkdir
,
2706 .drop_item
= &target_core_stat_rmdir
,
2709 static struct config_item_type target_core_stat_cit
= {
2710 .ct_group_ops
= &target_core_stat_group_ops
,
2711 .ct_owner
= THIS_MODULE
,
2714 /* End functions for struct config_item_type target_core_stat_cit */
2716 /* Start functions for struct config_item_type target_core_hba_cit */
2718 static struct config_group
*target_core_make_subdev(
2719 struct config_group
*group
,
2722 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2723 struct se_subsystem_dev
*se_dev
;
2724 struct se_subsystem_api
*t
;
2725 struct config_item
*hba_ci
= &group
->cg_item
;
2726 struct se_hba
*hba
= item_to_hba(hba_ci
);
2727 struct config_group
*dev_cg
= NULL
, *tg_pt_gp_cg
= NULL
;
2728 struct config_group
*dev_stat_grp
= NULL
;
2729 int errno
= -ENOMEM
, ret
;
2731 ret
= mutex_lock_interruptible(&hba
->hba_access_mutex
);
2733 return ERR_PTR(ret
);
2735 * Locate the struct se_subsystem_api from parent's struct se_hba.
2739 se_dev
= kzalloc(sizeof(struct se_subsystem_dev
), GFP_KERNEL
);
2741 pr_err("Unable to allocate memory for"
2742 " struct se_subsystem_dev\n");
2745 INIT_LIST_HEAD(&se_dev
->t10_wwn
.t10_vpd_list
);
2746 spin_lock_init(&se_dev
->t10_wwn
.t10_vpd_lock
);
2747 INIT_LIST_HEAD(&se_dev
->t10_pr
.registration_list
);
2748 INIT_LIST_HEAD(&se_dev
->t10_pr
.aptpl_reg_list
);
2749 spin_lock_init(&se_dev
->t10_pr
.registration_lock
);
2750 spin_lock_init(&se_dev
->t10_pr
.aptpl_reg_lock
);
2751 INIT_LIST_HEAD(&se_dev
->t10_alua
.tg_pt_gps_list
);
2752 spin_lock_init(&se_dev
->t10_alua
.tg_pt_gps_lock
);
2753 spin_lock_init(&se_dev
->se_dev_lock
);
2754 se_dev
->t10_pr
.pr_aptpl_buf_len
= PR_APTPL_BUF_LEN
;
2755 se_dev
->t10_wwn
.t10_sub_dev
= se_dev
;
2756 se_dev
->t10_alua
.t10_sub_dev
= se_dev
;
2757 se_dev
->se_dev_attrib
.da_sub_dev
= se_dev
;
2759 se_dev
->se_dev_hba
= hba
;
2760 dev_cg
= &se_dev
->se_dev_group
;
2762 dev_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 7,
2764 if (!dev_cg
->default_groups
)
2767 * Set se_dev_su_ptr from struct se_subsystem_api returned void ptr
2768 * for ->allocate_virtdevice()
2770 * se_dev->se_dev_ptr will be set after ->create_virtdev()
2771 * has been called successfully in the next level up in the
2772 * configfs tree for device object's struct config_group.
2774 se_dev
->se_dev_su_ptr
= t
->allocate_virtdevice(hba
, name
);
2775 if (!se_dev
->se_dev_su_ptr
) {
2776 pr_err("Unable to locate subsystem dependent pointer"
2777 " from allocate_virtdevice()\n");
2781 config_group_init_type_name(&se_dev
->se_dev_group
, name
,
2782 &target_core_dev_cit
);
2783 config_group_init_type_name(&se_dev
->se_dev_attrib
.da_group
, "attrib",
2784 &target_core_dev_attrib_cit
);
2785 config_group_init_type_name(&se_dev
->se_dev_pr_group
, "pr",
2786 &target_core_dev_pr_cit
);
2787 config_group_init_type_name(&se_dev
->t10_wwn
.t10_wwn_group
, "wwn",
2788 &target_core_dev_wwn_cit
);
2789 config_group_init_type_name(&se_dev
->t10_alua
.alua_tg_pt_gps_group
,
2790 "alua", &target_core_alua_tg_pt_gps_cit
);
2791 config_group_init_type_name(&se_dev
->dev_stat_grps
.stat_group
,
2792 "statistics", &target_core_stat_cit
);
2794 dev_cg
->default_groups
[0] = &se_dev
->se_dev_attrib
.da_group
;
2795 dev_cg
->default_groups
[1] = &se_dev
->se_dev_pr_group
;
2796 dev_cg
->default_groups
[2] = &se_dev
->t10_wwn
.t10_wwn_group
;
2797 dev_cg
->default_groups
[3] = &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2798 dev_cg
->default_groups
[4] = &se_dev
->dev_stat_grps
.stat_group
;
2799 dev_cg
->default_groups
[5] = NULL
;
2801 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
2803 tg_pt_gp
= core_alua_allocate_tg_pt_gp(se_dev
, "default_tg_pt_gp", 1);
2807 tg_pt_gp_cg
= &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2808 tg_pt_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
2810 if (!tg_pt_gp_cg
->default_groups
) {
2811 pr_err("Unable to allocate tg_pt_gp_cg->"
2812 "default_groups\n");
2816 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2817 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2818 tg_pt_gp_cg
->default_groups
[0] = &tg_pt_gp
->tg_pt_gp_group
;
2819 tg_pt_gp_cg
->default_groups
[1] = NULL
;
2820 se_dev
->t10_alua
.default_tg_pt_gp
= tg_pt_gp
;
2822 * Add core/$HBA/$DEV/statistics/ default groups
2824 dev_stat_grp
= &se_dev
->dev_stat_grps
.stat_group
;
2825 dev_stat_grp
->default_groups
= kzalloc(sizeof(struct config_group
) * 4,
2827 if (!dev_stat_grp
->default_groups
) {
2828 pr_err("Unable to allocate dev_stat_grp->default_groups\n");
2831 target_stat_setup_dev_default_groups(se_dev
);
2833 pr_debug("Target_Core_ConfigFS: Allocated struct se_subsystem_dev:"
2834 " %p se_dev_su_ptr: %p\n", se_dev
, se_dev
->se_dev_su_ptr
);
2836 mutex_unlock(&hba
->hba_access_mutex
);
2837 return &se_dev
->se_dev_group
;
2839 if (se_dev
->t10_alua
.default_tg_pt_gp
) {
2840 core_alua_free_tg_pt_gp(se_dev
->t10_alua
.default_tg_pt_gp
);
2841 se_dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2844 kfree(dev_stat_grp
->default_groups
);
2846 kfree(tg_pt_gp_cg
->default_groups
);
2848 kfree(dev_cg
->default_groups
);
2849 if (se_dev
->se_dev_su_ptr
)
2850 t
->free_device(se_dev
->se_dev_su_ptr
);
2853 mutex_unlock(&hba
->hba_access_mutex
);
2854 return ERR_PTR(errno
);
2857 static void target_core_drop_subdev(
2858 struct config_group
*group
,
2859 struct config_item
*item
)
2861 struct se_subsystem_dev
*se_dev
= container_of(to_config_group(item
),
2862 struct se_subsystem_dev
, se_dev_group
);
2864 struct se_subsystem_api
*t
;
2865 struct config_item
*df_item
;
2866 struct config_group
*dev_cg
, *tg_pt_gp_cg
, *dev_stat_grp
;
2869 hba
= item_to_hba(&se_dev
->se_dev_hba
->hba_group
.cg_item
);
2871 mutex_lock(&hba
->hba_access_mutex
);
2874 dev_stat_grp
= &se_dev
->dev_stat_grps
.stat_group
;
2875 for (i
= 0; dev_stat_grp
->default_groups
[i
]; i
++) {
2876 df_item
= &dev_stat_grp
->default_groups
[i
]->cg_item
;
2877 dev_stat_grp
->default_groups
[i
] = NULL
;
2878 config_item_put(df_item
);
2880 kfree(dev_stat_grp
->default_groups
);
2882 tg_pt_gp_cg
= &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2883 for (i
= 0; tg_pt_gp_cg
->default_groups
[i
]; i
++) {
2884 df_item
= &tg_pt_gp_cg
->default_groups
[i
]->cg_item
;
2885 tg_pt_gp_cg
->default_groups
[i
] = NULL
;
2886 config_item_put(df_item
);
2888 kfree(tg_pt_gp_cg
->default_groups
);
2890 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2891 * directly from target_core_alua_tg_pt_gp_release().
2893 se_dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2895 dev_cg
= &se_dev
->se_dev_group
;
2896 for (i
= 0; dev_cg
->default_groups
[i
]; i
++) {
2897 df_item
= &dev_cg
->default_groups
[i
]->cg_item
;
2898 dev_cg
->default_groups
[i
] = NULL
;
2899 config_item_put(df_item
);
2902 * The releasing of se_dev and associated se_dev->se_dev_ptr is done
2903 * from target_core_dev_item_ops->release() ->target_core_dev_release().
2905 config_item_put(item
);
2906 mutex_unlock(&hba
->hba_access_mutex
);
2909 static struct configfs_group_operations target_core_hba_group_ops
= {
2910 .make_group
= target_core_make_subdev
,
2911 .drop_item
= target_core_drop_subdev
,
2914 CONFIGFS_EATTR_STRUCT(target_core_hba
, se_hba
);
2915 #define SE_HBA_ATTR(_name, _mode) \
2916 static struct target_core_hba_attribute \
2917 target_core_hba_##_name = \
2918 __CONFIGFS_EATTR(_name, _mode, \
2919 target_core_hba_show_attr_##_name, \
2920 target_core_hba_store_attr_##_name);
2922 #define SE_HBA_ATTR_RO(_name) \
2923 static struct target_core_hba_attribute \
2924 target_core_hba_##_name = \
2925 __CONFIGFS_EATTR_RO(_name, \
2926 target_core_hba_show_attr_##_name);
2928 static ssize_t
target_core_hba_show_attr_hba_info(
2932 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
2933 hba
->hba_id
, hba
->transport
->name
,
2934 TARGET_CORE_CONFIGFS_VERSION
);
2937 SE_HBA_ATTR_RO(hba_info
);
2939 static ssize_t
target_core_hba_show_attr_hba_mode(struct se_hba
*hba
,
2944 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
2947 return sprintf(page
, "%d\n", hba_mode
);
2950 static ssize_t
target_core_hba_store_attr_hba_mode(struct se_hba
*hba
,
2951 const char *page
, size_t count
)
2953 struct se_subsystem_api
*transport
= hba
->transport
;
2954 unsigned long mode_flag
;
2957 if (transport
->pmode_enable_hba
== NULL
)
2960 ret
= strict_strtoul(page
, 0, &mode_flag
);
2962 pr_err("Unable to extract hba mode flag: %d\n", ret
);
2966 spin_lock(&hba
->device_lock
);
2967 if (!list_empty(&hba
->hba_dev_list
)) {
2968 pr_err("Unable to set hba_mode with active devices\n");
2969 spin_unlock(&hba
->device_lock
);
2972 spin_unlock(&hba
->device_lock
);
2974 ret
= transport
->pmode_enable_hba(hba
, mode_flag
);
2978 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
2980 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
2985 SE_HBA_ATTR(hba_mode
, S_IRUGO
| S_IWUSR
);
2987 CONFIGFS_EATTR_OPS(target_core_hba
, se_hba
, hba_group
);
2989 static void target_core_hba_release(struct config_item
*item
)
2991 struct se_hba
*hba
= container_of(to_config_group(item
),
2992 struct se_hba
, hba_group
);
2993 core_delete_hba(hba
);
2996 static struct configfs_attribute
*target_core_hba_attrs
[] = {
2997 &target_core_hba_hba_info
.attr
,
2998 &target_core_hba_hba_mode
.attr
,
3002 static struct configfs_item_operations target_core_hba_item_ops
= {
3003 .release
= target_core_hba_release
,
3004 .show_attribute
= target_core_hba_attr_show
,
3005 .store_attribute
= target_core_hba_attr_store
,
3008 static struct config_item_type target_core_hba_cit
= {
3009 .ct_item_ops
= &target_core_hba_item_ops
,
3010 .ct_group_ops
= &target_core_hba_group_ops
,
3011 .ct_attrs
= target_core_hba_attrs
,
3012 .ct_owner
= THIS_MODULE
,
3015 static struct config_group
*target_core_call_addhbatotarget(
3016 struct config_group
*group
,
3019 char *se_plugin_str
, *str
, *str2
;
3021 char buf
[TARGET_CORE_NAME_MAX_LEN
];
3022 unsigned long plugin_dep_id
= 0;
3025 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
3026 if (strlen(name
) >= TARGET_CORE_NAME_MAX_LEN
) {
3027 pr_err("Passed *name strlen(): %d exceeds"
3028 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
3029 TARGET_CORE_NAME_MAX_LEN
);
3030 return ERR_PTR(-ENAMETOOLONG
);
3032 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
3034 str
= strstr(buf
, "_");
3036 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
3037 return ERR_PTR(-EINVAL
);
3039 se_plugin_str
= buf
;
3041 * Special case for subsystem plugins that have "_" in their names.
3042 * Namely rd_direct and rd_mcp..
3044 str2
= strstr(str
+1, "_");
3046 *str2
= '\0'; /* Terminate for *se_plugin_str */
3047 str2
++; /* Skip to start of plugin dependent ID */
3050 *str
= '\0'; /* Terminate for *se_plugin_str */
3051 str
++; /* Skip to start of plugin dependent ID */
3054 ret
= strict_strtoul(str
, 0, &plugin_dep_id
);
3056 pr_err("strict_strtoul() returned %d for"
3057 " plugin_dep_id\n", ret
);
3058 return ERR_PTR(-EINVAL
);
3061 * Load up TCM subsystem plugins if they have not already been loaded.
3063 transport_subsystem_check_init();
3065 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
3067 return ERR_CAST(hba
);
3069 config_group_init_type_name(&hba
->hba_group
, name
,
3070 &target_core_hba_cit
);
3072 return &hba
->hba_group
;
3075 static void target_core_call_delhbafromtarget(
3076 struct config_group
*group
,
3077 struct config_item
*item
)
3080 * core_delete_hba() is called from target_core_hba_item_ops->release()
3081 * -> target_core_hba_release()
3083 config_item_put(item
);
3086 static struct configfs_group_operations target_core_group_ops
= {
3087 .make_group
= target_core_call_addhbatotarget
,
3088 .drop_item
= target_core_call_delhbafromtarget
,
3091 static struct config_item_type target_core_cit
= {
3092 .ct_item_ops
= NULL
,
3093 .ct_group_ops
= &target_core_group_ops
,
3095 .ct_owner
= THIS_MODULE
,
3098 /* Stop functions for struct config_item_type target_core_hba_cit */
3100 static int __init
target_core_init_configfs(void)
3102 struct config_group
*target_cg
, *hba_cg
= NULL
, *alua_cg
= NULL
;
3103 struct config_group
*lu_gp_cg
= NULL
;
3104 struct configfs_subsystem
*subsys
;
3105 struct t10_alua_lu_gp
*lu_gp
;
3108 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
3109 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
3110 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
3112 subsys
= target_core_subsystem
[0];
3113 config_group_init(&subsys
->su_group
);
3114 mutex_init(&subsys
->su_mutex
);
3116 INIT_LIST_HEAD(&g_tf_list
);
3117 mutex_init(&g_tf_lock
);
3118 ret
= init_se_kmem_caches();
3122 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
3123 * and ALUA Logical Unit Group and Target Port Group infrastructure.
3125 target_cg
= &subsys
->su_group
;
3126 target_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3128 if (!target_cg
->default_groups
) {
3129 pr_err("Unable to allocate target_cg->default_groups\n");
3133 config_group_init_type_name(&target_core_hbagroup
,
3134 "core", &target_core_cit
);
3135 target_cg
->default_groups
[0] = &target_core_hbagroup
;
3136 target_cg
->default_groups
[1] = NULL
;
3138 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
3140 hba_cg
= &target_core_hbagroup
;
3141 hba_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3143 if (!hba_cg
->default_groups
) {
3144 pr_err("Unable to allocate hba_cg->default_groups\n");
3147 config_group_init_type_name(&alua_group
,
3148 "alua", &target_core_alua_cit
);
3149 hba_cg
->default_groups
[0] = &alua_group
;
3150 hba_cg
->default_groups
[1] = NULL
;
3152 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
3153 * groups under /sys/kernel/config/target/core/alua/
3155 alua_cg
= &alua_group
;
3156 alua_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3158 if (!alua_cg
->default_groups
) {
3159 pr_err("Unable to allocate alua_cg->default_groups\n");
3163 config_group_init_type_name(&alua_lu_gps_group
,
3164 "lu_gps", &target_core_alua_lu_gps_cit
);
3165 alua_cg
->default_groups
[0] = &alua_lu_gps_group
;
3166 alua_cg
->default_groups
[1] = NULL
;
3168 * Add core/alua/lu_gps/default_lu_gp
3170 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
3174 lu_gp_cg
= &alua_lu_gps_group
;
3175 lu_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3177 if (!lu_gp_cg
->default_groups
) {
3178 pr_err("Unable to allocate lu_gp_cg->default_groups\n");
3182 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
3183 &target_core_alua_lu_gp_cit
);
3184 lu_gp_cg
->default_groups
[0] = &lu_gp
->lu_gp_group
;
3185 lu_gp_cg
->default_groups
[1] = NULL
;
3186 default_lu_gp
= lu_gp
;
3188 * Register the target_core_mod subsystem with configfs.
3190 ret
= configfs_register_subsystem(subsys
);
3192 pr_err("Error %d while registering subsystem %s\n",
3193 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
3196 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
3197 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION
" on %s/%s"
3198 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
3200 * Register built-in RAMDISK subsystem logic for virtual LUN 0
3202 ret
= rd_module_init();
3206 if (core_dev_setup_virtual_lun0() < 0)
3212 configfs_unregister_subsystem(subsys
);
3213 core_dev_release_virtual_lun0();
3216 if (default_lu_gp
) {
3217 core_alua_free_lu_gp(default_lu_gp
);
3218 default_lu_gp
= NULL
;
3221 kfree(lu_gp_cg
->default_groups
);
3223 kfree(alua_cg
->default_groups
);
3225 kfree(hba_cg
->default_groups
);
3226 kfree(target_cg
->default_groups
);
3227 release_se_kmem_caches();
3231 static void __exit
target_core_exit_configfs(void)
3233 struct configfs_subsystem
*subsys
;
3234 struct config_group
*hba_cg
, *alua_cg
, *lu_gp_cg
;
3235 struct config_item
*item
;
3238 subsys
= target_core_subsystem
[0];
3240 lu_gp_cg
= &alua_lu_gps_group
;
3241 for (i
= 0; lu_gp_cg
->default_groups
[i
]; i
++) {
3242 item
= &lu_gp_cg
->default_groups
[i
]->cg_item
;
3243 lu_gp_cg
->default_groups
[i
] = NULL
;
3244 config_item_put(item
);
3246 kfree(lu_gp_cg
->default_groups
);
3247 lu_gp_cg
->default_groups
= NULL
;
3249 alua_cg
= &alua_group
;
3250 for (i
= 0; alua_cg
->default_groups
[i
]; i
++) {
3251 item
= &alua_cg
->default_groups
[i
]->cg_item
;
3252 alua_cg
->default_groups
[i
] = NULL
;
3253 config_item_put(item
);
3255 kfree(alua_cg
->default_groups
);
3256 alua_cg
->default_groups
= NULL
;
3258 hba_cg
= &target_core_hbagroup
;
3259 for (i
= 0; hba_cg
->default_groups
[i
]; i
++) {
3260 item
= &hba_cg
->default_groups
[i
]->cg_item
;
3261 hba_cg
->default_groups
[i
] = NULL
;
3262 config_item_put(item
);
3264 kfree(hba_cg
->default_groups
);
3265 hba_cg
->default_groups
= NULL
;
3267 * We expect subsys->su_group.default_groups to be released
3268 * by configfs subsystem provider logic..
3270 configfs_unregister_subsystem(subsys
);
3271 kfree(subsys
->su_group
.default_groups
);
3273 core_alua_free_lu_gp(default_lu_gp
);
3274 default_lu_gp
= NULL
;
3276 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
3277 " Infrastructure\n");
3279 core_dev_release_virtual_lun0();
3281 release_se_kmem_caches();
3284 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3285 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3286 MODULE_LICENSE("GPL");
3288 module_init(target_core_init_configfs
);
3289 module_exit(target_core_exit_configfs
);