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_device.h>
43 #include <target/target_core_transport.h>
44 #include <target/target_core_fabric_ops.h>
45 #include <target/target_core_fabric_configfs.h>
46 #include <target/target_core_configfs.h>
47 #include <target/configfs_macros.h>
49 #include "target_core_alua.h"
50 #include "target_core_hba.h"
51 #include "target_core_pr.h"
52 #include "target_core_rd.h"
53 #include "target_core_stat.h"
55 extern struct t10_alua_lu_gp
*default_lu_gp
;
57 static struct list_head g_tf_list
;
58 static struct mutex g_tf_lock
;
60 struct target_core_configfs_attribute
{
61 struct configfs_attribute attr
;
62 ssize_t (*show
)(void *, char *);
63 ssize_t (*store
)(void *, const char *, size_t);
66 static struct config_group target_core_hbagroup
;
67 static struct config_group alua_group
;
68 static struct config_group alua_lu_gps_group
;
70 static DEFINE_SPINLOCK(se_device_lock
);
71 static LIST_HEAD(se_dev_list
);
73 static inline struct se_hba
*
74 item_to_hba(struct config_item
*item
)
76 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
80 * Attributes for /sys/kernel/config/target/
82 static ssize_t
target_core_attr_show(struct config_item
*item
,
83 struct configfs_attribute
*attr
,
86 return sprintf(page
, "Target Engine Core ConfigFS Infrastructure %s"
87 " on %s/%s on "UTS_RELEASE
"\n", TARGET_CORE_CONFIGFS_VERSION
,
88 utsname()->sysname
, utsname()->machine
);
91 static struct configfs_item_operations target_core_fabric_item_ops
= {
92 .show_attribute
= target_core_attr_show
,
95 static struct configfs_attribute target_core_item_attr_version
= {
96 .ca_owner
= THIS_MODULE
,
101 static struct target_fabric_configfs
*target_core_get_fabric(
104 struct target_fabric_configfs
*tf
;
109 mutex_lock(&g_tf_lock
);
110 list_for_each_entry(tf
, &g_tf_list
, tf_list
) {
111 if (!strcmp(tf
->tf_name
, name
)) {
112 atomic_inc(&tf
->tf_access_cnt
);
113 mutex_unlock(&g_tf_lock
);
117 mutex_unlock(&g_tf_lock
);
123 * Called from struct target_core_group_ops->make_group()
125 static struct config_group
*target_core_register_fabric(
126 struct config_group
*group
,
129 struct target_fabric_configfs
*tf
;
132 pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:"
133 " %s\n", group
, name
);
135 * Ensure that TCM subsystem plugins are loaded at this point for
136 * using the RAMDISK_DR virtual LUN 0 and all other struct se_port
139 if (transport_subsystem_check_init() < 0)
140 return ERR_PTR(-EINVAL
);
143 * Below are some hardcoded request_module() calls to automatically
144 * local fabric modules when the following is called:
146 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
148 * Note that this does not limit which TCM fabric module can be
149 * registered, but simply provids auto loading logic for modules with
150 * mkdir(2) system calls with known TCM fabric modules.
152 if (!strncmp(name
, "iscsi", 5)) {
154 * Automatically load the LIO Target fabric module when the
155 * following is called:
157 * mkdir -p $CONFIGFS/target/iscsi
159 ret
= request_module("iscsi_target_mod");
161 pr_err("request_module() failed for"
162 " iscsi_target_mod.ko: %d\n", ret
);
163 return ERR_PTR(-EINVAL
);
165 } else if (!strncmp(name
, "loopback", 8)) {
167 * Automatically load the tcm_loop fabric module when the
168 * following is called:
170 * mkdir -p $CONFIGFS/target/loopback
172 ret
= request_module("tcm_loop");
174 pr_err("request_module() failed for"
175 " tcm_loop.ko: %d\n", ret
);
176 return ERR_PTR(-EINVAL
);
180 tf
= target_core_get_fabric(name
);
182 pr_err("target_core_get_fabric() failed for %s\n",
184 return ERR_PTR(-EINVAL
);
186 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
187 " %s\n", tf
->tf_name
);
189 * On a successful target_core_get_fabric() look, the returned
190 * struct target_fabric_configfs *tf will contain a usage reference.
192 pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
193 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
195 tf
->tf_group
.default_groups
= tf
->tf_default_groups
;
196 tf
->tf_group
.default_groups
[0] = &tf
->tf_disc_group
;
197 tf
->tf_group
.default_groups
[1] = NULL
;
199 config_group_init_type_name(&tf
->tf_group
, name
,
200 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
201 config_group_init_type_name(&tf
->tf_disc_group
, "discovery_auth",
202 &TF_CIT_TMPL(tf
)->tfc_discovery_cit
);
204 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
205 " %s\n", tf
->tf_group
.cg_item
.ci_name
);
207 * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item()
209 tf
->tf_ops
.tf_subsys
= tf
->tf_subsys
;
210 tf
->tf_fabric
= &tf
->tf_group
.cg_item
;
211 pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
214 return &tf
->tf_group
;
218 * Called from struct target_core_group_ops->drop_item()
220 static void target_core_deregister_fabric(
221 struct config_group
*group
,
222 struct config_item
*item
)
224 struct target_fabric_configfs
*tf
= container_of(
225 to_config_group(item
), struct target_fabric_configfs
, tf_group
);
226 struct config_group
*tf_group
;
227 struct config_item
*df_item
;
230 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
231 " tf list\n", config_item_name(item
));
233 pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:"
234 " %s\n", tf
->tf_name
);
235 atomic_dec(&tf
->tf_access_cnt
);
237 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing"
238 " tf->tf_fabric for %s\n", tf
->tf_name
);
239 tf
->tf_fabric
= NULL
;
241 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
242 " %s\n", config_item_name(item
));
244 tf_group
= &tf
->tf_group
;
245 for (i
= 0; tf_group
->default_groups
[i
]; i
++) {
246 df_item
= &tf_group
->default_groups
[i
]->cg_item
;
247 tf_group
->default_groups
[i
] = NULL
;
248 config_item_put(df_item
);
250 config_item_put(item
);
253 static struct configfs_group_operations target_core_fabric_group_ops
= {
254 .make_group
= &target_core_register_fabric
,
255 .drop_item
= &target_core_deregister_fabric
,
259 * All item attributes appearing in /sys/kernel/target/ appear here.
261 static struct configfs_attribute
*target_core_fabric_item_attrs
[] = {
262 &target_core_item_attr_version
,
267 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
269 static struct config_item_type target_core_fabrics_item
= {
270 .ct_item_ops
= &target_core_fabric_item_ops
,
271 .ct_group_ops
= &target_core_fabric_group_ops
,
272 .ct_attrs
= target_core_fabric_item_attrs
,
273 .ct_owner
= THIS_MODULE
,
276 static struct configfs_subsystem target_core_fabrics
= {
279 .ci_namebuf
= "target",
280 .ci_type
= &target_core_fabrics_item
,
285 static struct configfs_subsystem
*target_core_subsystem
[] = {
286 &target_core_fabrics
,
290 /*##############################################################################
291 // Start functions called by external Target Fabrics Modules
292 //############################################################################*/
295 * First function called by fabric modules to:
297 * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer.
298 * 2) Add struct target_fabric_configfs to g_tf_list
299 * 3) Return struct target_fabric_configfs to fabric module to be passed
300 * into target_fabric_configfs_register().
302 struct target_fabric_configfs
*target_fabric_configfs_init(
303 struct module
*fabric_mod
,
306 struct target_fabric_configfs
*tf
;
309 pr_err("Unable to locate passed fabric name\n");
310 return ERR_PTR(-EINVAL
);
312 if (strlen(name
) >= TARGET_FABRIC_NAME_SIZE
) {
313 pr_err("Passed name: %s exceeds TARGET_FABRIC"
314 "_NAME_SIZE\n", name
);
315 return ERR_PTR(-EINVAL
);
318 tf
= kzalloc(sizeof(struct target_fabric_configfs
), GFP_KERNEL
);
320 return ERR_PTR(-ENOMEM
);
322 INIT_LIST_HEAD(&tf
->tf_list
);
323 atomic_set(&tf
->tf_access_cnt
, 0);
325 * Setup the default generic struct config_item_type's (cits) in
326 * struct target_fabric_configfs->tf_cit_tmpl
328 tf
->tf_module
= fabric_mod
;
329 target_fabric_setup_cits(tf
);
331 tf
->tf_subsys
= target_core_subsystem
[0];
332 snprintf(tf
->tf_name
, TARGET_FABRIC_NAME_SIZE
, "%s", name
);
334 mutex_lock(&g_tf_lock
);
335 list_add_tail(&tf
->tf_list
, &g_tf_list
);
336 mutex_unlock(&g_tf_lock
);
338 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>"
340 pr_debug("Initialized struct target_fabric_configfs: %p for"
341 " %s\n", tf
, tf
->tf_name
);
344 EXPORT_SYMBOL(target_fabric_configfs_init
);
347 * Called by fabric plugins after FAILED target_fabric_configfs_register() call.
349 void target_fabric_configfs_free(
350 struct target_fabric_configfs
*tf
)
352 mutex_lock(&g_tf_lock
);
353 list_del(&tf
->tf_list
);
354 mutex_unlock(&g_tf_lock
);
358 EXPORT_SYMBOL(target_fabric_configfs_free
);
361 * Perform a sanity check of the passed tf->tf_ops before completing
362 * TCM fabric module registration.
364 static int target_fabric_tf_ops_check(
365 struct target_fabric_configfs
*tf
)
367 struct target_core_fabric_ops
*tfo
= &tf
->tf_ops
;
369 if (!tfo
->get_fabric_name
) {
370 pr_err("Missing tfo->get_fabric_name()\n");
373 if (!tfo
->get_fabric_proto_ident
) {
374 pr_err("Missing tfo->get_fabric_proto_ident()\n");
377 if (!tfo
->tpg_get_wwn
) {
378 pr_err("Missing tfo->tpg_get_wwn()\n");
381 if (!tfo
->tpg_get_tag
) {
382 pr_err("Missing tfo->tpg_get_tag()\n");
385 if (!tfo
->tpg_get_default_depth
) {
386 pr_err("Missing tfo->tpg_get_default_depth()\n");
389 if (!tfo
->tpg_get_pr_transport_id
) {
390 pr_err("Missing tfo->tpg_get_pr_transport_id()\n");
393 if (!tfo
->tpg_get_pr_transport_id_len
) {
394 pr_err("Missing tfo->tpg_get_pr_transport_id_len()\n");
397 if (!tfo
->tpg_check_demo_mode
) {
398 pr_err("Missing tfo->tpg_check_demo_mode()\n");
401 if (!tfo
->tpg_check_demo_mode_cache
) {
402 pr_err("Missing tfo->tpg_check_demo_mode_cache()\n");
405 if (!tfo
->tpg_check_demo_mode_write_protect
) {
406 pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n");
409 if (!tfo
->tpg_check_prod_mode_write_protect
) {
410 pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n");
413 if (!tfo
->tpg_alloc_fabric_acl
) {
414 pr_err("Missing tfo->tpg_alloc_fabric_acl()\n");
417 if (!tfo
->tpg_release_fabric_acl
) {
418 pr_err("Missing tfo->tpg_release_fabric_acl()\n");
421 if (!tfo
->tpg_get_inst_index
) {
422 pr_err("Missing tfo->tpg_get_inst_index()\n");
425 if (!tfo
->release_cmd
) {
426 pr_err("Missing tfo->release_cmd()\n");
429 if (!tfo
->shutdown_session
) {
430 pr_err("Missing tfo->shutdown_session()\n");
433 if (!tfo
->close_session
) {
434 pr_err("Missing tfo->close_session()\n");
437 if (!tfo
->stop_session
) {
438 pr_err("Missing tfo->stop_session()\n");
441 if (!tfo
->fall_back_to_erl0
) {
442 pr_err("Missing tfo->fall_back_to_erl0()\n");
445 if (!tfo
->sess_logged_in
) {
446 pr_err("Missing tfo->sess_logged_in()\n");
449 if (!tfo
->sess_get_index
) {
450 pr_err("Missing tfo->sess_get_index()\n");
453 if (!tfo
->write_pending
) {
454 pr_err("Missing tfo->write_pending()\n");
457 if (!tfo
->write_pending_status
) {
458 pr_err("Missing tfo->write_pending_status()\n");
461 if (!tfo
->set_default_node_attributes
) {
462 pr_err("Missing tfo->set_default_node_attributes()\n");
465 if (!tfo
->get_task_tag
) {
466 pr_err("Missing tfo->get_task_tag()\n");
469 if (!tfo
->get_cmd_state
) {
470 pr_err("Missing tfo->get_cmd_state()\n");
473 if (!tfo
->queue_data_in
) {
474 pr_err("Missing tfo->queue_data_in()\n");
477 if (!tfo
->queue_status
) {
478 pr_err("Missing tfo->queue_status()\n");
481 if (!tfo
->queue_tm_rsp
) {
482 pr_err("Missing tfo->queue_tm_rsp()\n");
485 if (!tfo
->set_fabric_sense_len
) {
486 pr_err("Missing tfo->set_fabric_sense_len()\n");
489 if (!tfo
->get_fabric_sense_len
) {
490 pr_err("Missing tfo->get_fabric_sense_len()\n");
493 if (!tfo
->is_state_remove
) {
494 pr_err("Missing tfo->is_state_remove()\n");
498 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
499 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
500 * target_core_fabric_configfs.c WWN+TPG group context code.
502 if (!tfo
->fabric_make_wwn
) {
503 pr_err("Missing tfo->fabric_make_wwn()\n");
506 if (!tfo
->fabric_drop_wwn
) {
507 pr_err("Missing tfo->fabric_drop_wwn()\n");
510 if (!tfo
->fabric_make_tpg
) {
511 pr_err("Missing tfo->fabric_make_tpg()\n");
514 if (!tfo
->fabric_drop_tpg
) {
515 pr_err("Missing tfo->fabric_drop_tpg()\n");
523 * Called 2nd from fabric module with returned parameter of
524 * struct target_fabric_configfs * from target_fabric_configfs_init().
526 * Upon a successful registration, the new fabric's struct config_item is
527 * return. Also, a pointer to this struct is set in the passed
528 * struct target_fabric_configfs.
530 int target_fabric_configfs_register(
531 struct target_fabric_configfs
*tf
)
536 pr_err("Unable to locate target_fabric_configfs"
540 if (!tf
->tf_subsys
) {
541 pr_err("Unable to target struct config_subsystem"
545 ret
= target_fabric_tf_ops_check(tf
);
549 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>"
553 EXPORT_SYMBOL(target_fabric_configfs_register
);
555 void target_fabric_configfs_deregister(
556 struct target_fabric_configfs
*tf
)
558 struct configfs_subsystem
*su
;
561 pr_err("Unable to locate passed target_fabric_"
567 pr_err("Unable to locate passed tf->tf_subsys"
571 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
573 mutex_lock(&g_tf_lock
);
574 if (atomic_read(&tf
->tf_access_cnt
)) {
575 mutex_unlock(&g_tf_lock
);
576 pr_err("Non zero tf->tf_access_cnt for fabric %s\n",
580 list_del(&tf
->tf_list
);
581 mutex_unlock(&g_tf_lock
);
583 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
584 " %s\n", tf
->tf_name
);
585 tf
->tf_module
= NULL
;
586 tf
->tf_subsys
= NULL
;
589 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
592 EXPORT_SYMBOL(target_fabric_configfs_deregister
);
594 /*##############################################################################
595 // Stop functions called by external Target Fabrics Modules
596 //############################################################################*/
598 /* Start functions for struct config_item_type target_core_dev_attrib_cit */
600 #define DEF_DEV_ATTRIB_SHOW(_name) \
601 static ssize_t target_core_dev_show_attr_##_name( \
602 struct se_dev_attrib *da, \
605 struct se_device *dev; \
606 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
609 spin_lock(&se_dev->se_dev_lock); \
610 dev = se_dev->se_dev_ptr; \
612 spin_unlock(&se_dev->se_dev_lock); \
615 rb = snprintf(page, PAGE_SIZE, "%u\n", \
616 (u32)dev->se_sub_dev->se_dev_attrib._name); \
617 spin_unlock(&se_dev->se_dev_lock); \
622 #define DEF_DEV_ATTRIB_STORE(_name) \
623 static ssize_t target_core_dev_store_attr_##_name( \
624 struct se_dev_attrib *da, \
628 struct se_device *dev; \
629 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
633 spin_lock(&se_dev->se_dev_lock); \
634 dev = se_dev->se_dev_ptr; \
636 spin_unlock(&se_dev->se_dev_lock); \
639 ret = strict_strtoul(page, 0, &val); \
641 spin_unlock(&se_dev->se_dev_lock); \
642 pr_err("strict_strtoul() failed with" \
643 " ret: %d\n", ret); \
646 ret = se_dev_set_##_name(dev, (u32)val); \
647 spin_unlock(&se_dev->se_dev_lock); \
649 return (!ret) ? count : -EINVAL; \
652 #define DEF_DEV_ATTRIB(_name) \
653 DEF_DEV_ATTRIB_SHOW(_name); \
654 DEF_DEV_ATTRIB_STORE(_name);
656 #define DEF_DEV_ATTRIB_RO(_name) \
657 DEF_DEV_ATTRIB_SHOW(_name);
659 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib
, se_dev_attrib
);
660 #define SE_DEV_ATTR(_name, _mode) \
661 static struct target_core_dev_attrib_attribute \
662 target_core_dev_attrib_##_name = \
663 __CONFIGFS_EATTR(_name, _mode, \
664 target_core_dev_show_attr_##_name, \
665 target_core_dev_store_attr_##_name);
667 #define SE_DEV_ATTR_RO(_name); \
668 static struct target_core_dev_attrib_attribute \
669 target_core_dev_attrib_##_name = \
670 __CONFIGFS_EATTR_RO(_name, \
671 target_core_dev_show_attr_##_name);
673 DEF_DEV_ATTRIB(emulate_dpo
);
674 SE_DEV_ATTR(emulate_dpo
, S_IRUGO
| S_IWUSR
);
676 DEF_DEV_ATTRIB(emulate_fua_write
);
677 SE_DEV_ATTR(emulate_fua_write
, S_IRUGO
| S_IWUSR
);
679 DEF_DEV_ATTRIB(emulate_fua_read
);
680 SE_DEV_ATTR(emulate_fua_read
, S_IRUGO
| S_IWUSR
);
682 DEF_DEV_ATTRIB(emulate_write_cache
);
683 SE_DEV_ATTR(emulate_write_cache
, S_IRUGO
| S_IWUSR
);
685 DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl
);
686 SE_DEV_ATTR(emulate_ua_intlck_ctrl
, S_IRUGO
| S_IWUSR
);
688 DEF_DEV_ATTRIB(emulate_tas
);
689 SE_DEV_ATTR(emulate_tas
, S_IRUGO
| S_IWUSR
);
691 DEF_DEV_ATTRIB(emulate_tpu
);
692 SE_DEV_ATTR(emulate_tpu
, S_IRUGO
| S_IWUSR
);
694 DEF_DEV_ATTRIB(emulate_tpws
);
695 SE_DEV_ATTR(emulate_tpws
, S_IRUGO
| S_IWUSR
);
697 DEF_DEV_ATTRIB(enforce_pr_isids
);
698 SE_DEV_ATTR(enforce_pr_isids
, S_IRUGO
| S_IWUSR
);
700 DEF_DEV_ATTRIB(is_nonrot
);
701 SE_DEV_ATTR(is_nonrot
, S_IRUGO
| S_IWUSR
);
703 DEF_DEV_ATTRIB(emulate_rest_reord
);
704 SE_DEV_ATTR(emulate_rest_reord
, S_IRUGO
| S_IWUSR
);
706 DEF_DEV_ATTRIB_RO(hw_block_size
);
707 SE_DEV_ATTR_RO(hw_block_size
);
709 DEF_DEV_ATTRIB(block_size
);
710 SE_DEV_ATTR(block_size
, S_IRUGO
| S_IWUSR
);
712 DEF_DEV_ATTRIB_RO(hw_max_sectors
);
713 SE_DEV_ATTR_RO(hw_max_sectors
);
715 DEF_DEV_ATTRIB(max_sectors
);
716 SE_DEV_ATTR(max_sectors
, S_IRUGO
| S_IWUSR
);
718 DEF_DEV_ATTRIB(optimal_sectors
);
719 SE_DEV_ATTR(optimal_sectors
, S_IRUGO
| S_IWUSR
);
721 DEF_DEV_ATTRIB_RO(hw_queue_depth
);
722 SE_DEV_ATTR_RO(hw_queue_depth
);
724 DEF_DEV_ATTRIB(queue_depth
);
725 SE_DEV_ATTR(queue_depth
, S_IRUGO
| S_IWUSR
);
727 DEF_DEV_ATTRIB(task_timeout
);
728 SE_DEV_ATTR(task_timeout
, S_IRUGO
| S_IWUSR
);
730 DEF_DEV_ATTRIB(max_unmap_lba_count
);
731 SE_DEV_ATTR(max_unmap_lba_count
, S_IRUGO
| S_IWUSR
);
733 DEF_DEV_ATTRIB(max_unmap_block_desc_count
);
734 SE_DEV_ATTR(max_unmap_block_desc_count
, S_IRUGO
| S_IWUSR
);
736 DEF_DEV_ATTRIB(unmap_granularity
);
737 SE_DEV_ATTR(unmap_granularity
, S_IRUGO
| S_IWUSR
);
739 DEF_DEV_ATTRIB(unmap_granularity_alignment
);
740 SE_DEV_ATTR(unmap_granularity_alignment
, S_IRUGO
| S_IWUSR
);
742 CONFIGFS_EATTR_OPS(target_core_dev_attrib
, se_dev_attrib
, da_group
);
744 static struct configfs_attribute
*target_core_dev_attrib_attrs
[] = {
745 &target_core_dev_attrib_emulate_dpo
.attr
,
746 &target_core_dev_attrib_emulate_fua_write
.attr
,
747 &target_core_dev_attrib_emulate_fua_read
.attr
,
748 &target_core_dev_attrib_emulate_write_cache
.attr
,
749 &target_core_dev_attrib_emulate_ua_intlck_ctrl
.attr
,
750 &target_core_dev_attrib_emulate_tas
.attr
,
751 &target_core_dev_attrib_emulate_tpu
.attr
,
752 &target_core_dev_attrib_emulate_tpws
.attr
,
753 &target_core_dev_attrib_enforce_pr_isids
.attr
,
754 &target_core_dev_attrib_is_nonrot
.attr
,
755 &target_core_dev_attrib_emulate_rest_reord
.attr
,
756 &target_core_dev_attrib_hw_block_size
.attr
,
757 &target_core_dev_attrib_block_size
.attr
,
758 &target_core_dev_attrib_hw_max_sectors
.attr
,
759 &target_core_dev_attrib_max_sectors
.attr
,
760 &target_core_dev_attrib_optimal_sectors
.attr
,
761 &target_core_dev_attrib_hw_queue_depth
.attr
,
762 &target_core_dev_attrib_queue_depth
.attr
,
763 &target_core_dev_attrib_task_timeout
.attr
,
764 &target_core_dev_attrib_max_unmap_lba_count
.attr
,
765 &target_core_dev_attrib_max_unmap_block_desc_count
.attr
,
766 &target_core_dev_attrib_unmap_granularity
.attr
,
767 &target_core_dev_attrib_unmap_granularity_alignment
.attr
,
771 static struct configfs_item_operations target_core_dev_attrib_ops
= {
772 .show_attribute
= target_core_dev_attrib_attr_show
,
773 .store_attribute
= target_core_dev_attrib_attr_store
,
776 static struct config_item_type target_core_dev_attrib_cit
= {
777 .ct_item_ops
= &target_core_dev_attrib_ops
,
778 .ct_attrs
= target_core_dev_attrib_attrs
,
779 .ct_owner
= THIS_MODULE
,
782 /* End functions for struct config_item_type target_core_dev_attrib_cit */
784 /* Start functions for struct config_item_type target_core_dev_wwn_cit */
786 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn
, t10_wwn
);
787 #define SE_DEV_WWN_ATTR(_name, _mode) \
788 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
789 __CONFIGFS_EATTR(_name, _mode, \
790 target_core_dev_wwn_show_attr_##_name, \
791 target_core_dev_wwn_store_attr_##_name);
793 #define SE_DEV_WWN_ATTR_RO(_name); \
795 static struct target_core_dev_wwn_attribute \
796 target_core_dev_wwn_##_name = \
797 __CONFIGFS_EATTR_RO(_name, \
798 target_core_dev_wwn_show_attr_##_name); \
802 * VPD page 0x80 Unit serial
804 static ssize_t
target_core_dev_wwn_show_attr_vpd_unit_serial(
805 struct t10_wwn
*t10_wwn
,
808 struct se_subsystem_dev
*se_dev
= t10_wwn
->t10_sub_dev
;
809 struct se_device
*dev
;
811 dev
= se_dev
->se_dev_ptr
;
815 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
816 &t10_wwn
->unit_serial
[0]);
819 static ssize_t
target_core_dev_wwn_store_attr_vpd_unit_serial(
820 struct t10_wwn
*t10_wwn
,
824 struct se_subsystem_dev
*su_dev
= t10_wwn
->t10_sub_dev
;
825 struct se_device
*dev
;
826 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
829 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
830 * from the struct scsi_device level firmware, do not allow
831 * VPD Unit Serial to be emulated.
833 * Note this struct scsi_device could also be emulating VPD
834 * information from its drivers/scsi LLD. But for now we assume
835 * it is doing 'the right thing' wrt a world wide unique
836 * VPD Unit Serial Number that OS dependent multipath can depend on.
838 if (su_dev
->su_dev_flags
& SDF_FIRMWARE_VPD_UNIT_SERIAL
) {
839 pr_err("Underlying SCSI device firmware provided VPD"
840 " Unit Serial, ignoring request\n");
844 if (strlen(page
) >= INQUIRY_VPD_SERIAL_LEN
) {
845 pr_err("Emulated VPD Unit Serial exceeds"
846 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
850 * Check to see if any active $FABRIC_MOD exports exist. If they
851 * do exist, fail here as changing this information on the fly
852 * (underneath the initiator side OS dependent multipath code)
853 * could cause negative effects.
855 dev
= su_dev
->se_dev_ptr
;
857 if (atomic_read(&dev
->dev_export_obj
.obj_access_count
)) {
858 pr_err("Unable to set VPD Unit Serial while"
859 " active %d $FABRIC_MOD exports exist\n",
860 atomic_read(&dev
->dev_export_obj
.obj_access_count
));
865 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
867 * Also, strip any newline added from the userspace
868 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
870 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
871 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
872 snprintf(su_dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
873 "%s", strstrip(buf
));
874 su_dev
->su_dev_flags
|= SDF_EMULATED_VPD_UNIT_SERIAL
;
876 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
877 " %s\n", su_dev
->t10_wwn
.unit_serial
);
882 SE_DEV_WWN_ATTR(vpd_unit_serial
, S_IRUGO
| S_IWUSR
);
885 * VPD page 0x83 Protocol Identifier
887 static ssize_t
target_core_dev_wwn_show_attr_vpd_protocol_identifier(
888 struct t10_wwn
*t10_wwn
,
891 struct se_subsystem_dev
*se_dev
= t10_wwn
->t10_sub_dev
;
892 struct se_device
*dev
;
894 unsigned char buf
[VPD_TMP_BUF_SIZE
];
897 dev
= se_dev
->se_dev_ptr
;
901 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
903 spin_lock(&t10_wwn
->t10_vpd_lock
);
904 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
905 if (!vpd
->protocol_identifier_set
)
908 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
910 if (len
+ strlen(buf
) >= PAGE_SIZE
)
913 len
+= sprintf(page
+len
, "%s", buf
);
915 spin_unlock(&t10_wwn
->t10_vpd_lock
);
920 static ssize_t
target_core_dev_wwn_store_attr_vpd_protocol_identifier(
921 struct t10_wwn
*t10_wwn
,
928 SE_DEV_WWN_ATTR(vpd_protocol_identifier
, S_IRUGO
| S_IWUSR
);
931 * Generic wrapper for dumping VPD identifiers by association.
933 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
934 static ssize_t target_core_dev_wwn_show_attr_##_name( \
935 struct t10_wwn *t10_wwn, \
938 struct se_subsystem_dev *se_dev = t10_wwn->t10_sub_dev; \
939 struct se_device *dev; \
940 struct t10_vpd *vpd; \
941 unsigned char buf[VPD_TMP_BUF_SIZE]; \
944 dev = se_dev->se_dev_ptr; \
948 spin_lock(&t10_wwn->t10_vpd_lock); \
949 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
950 if (vpd->association != _assoc) \
953 memset(buf, 0, VPD_TMP_BUF_SIZE); \
954 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
955 if (len + strlen(buf) >= PAGE_SIZE) \
957 len += sprintf(page+len, "%s", buf); \
959 memset(buf, 0, VPD_TMP_BUF_SIZE); \
960 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
961 if (len + strlen(buf) >= PAGE_SIZE) \
963 len += sprintf(page+len, "%s", buf); \
965 memset(buf, 0, VPD_TMP_BUF_SIZE); \
966 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
967 if (len + strlen(buf) >= PAGE_SIZE) \
969 len += sprintf(page+len, "%s", buf); \
971 spin_unlock(&t10_wwn->t10_vpd_lock); \
977 * VPD page 0x83 Association: Logical Unit
979 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
981 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
982 struct t10_wwn
*t10_wwn
,
989 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit
, S_IRUGO
| S_IWUSR
);
992 * VPD page 0x83 Association: Target Port
994 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
996 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_target_port(
997 struct t10_wwn
*t10_wwn
,
1004 SE_DEV_WWN_ATTR(vpd_assoc_target_port
, S_IRUGO
| S_IWUSR
);
1007 * VPD page 0x83 Association: SCSI Target Device
1009 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
1011 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
1012 struct t10_wwn
*t10_wwn
,
1019 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device
, S_IRUGO
| S_IWUSR
);
1021 CONFIGFS_EATTR_OPS(target_core_dev_wwn
, t10_wwn
, t10_wwn_group
);
1023 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
1024 &target_core_dev_wwn_vpd_unit_serial
.attr
,
1025 &target_core_dev_wwn_vpd_protocol_identifier
.attr
,
1026 &target_core_dev_wwn_vpd_assoc_logical_unit
.attr
,
1027 &target_core_dev_wwn_vpd_assoc_target_port
.attr
,
1028 &target_core_dev_wwn_vpd_assoc_scsi_target_device
.attr
,
1032 static struct configfs_item_operations target_core_dev_wwn_ops
= {
1033 .show_attribute
= target_core_dev_wwn_attr_show
,
1034 .store_attribute
= target_core_dev_wwn_attr_store
,
1037 static struct config_item_type target_core_dev_wwn_cit
= {
1038 .ct_item_ops
= &target_core_dev_wwn_ops
,
1039 .ct_attrs
= target_core_dev_wwn_attrs
,
1040 .ct_owner
= THIS_MODULE
,
1043 /* End functions for struct config_item_type target_core_dev_wwn_cit */
1045 /* Start functions for struct config_item_type target_core_dev_pr_cit */
1047 CONFIGFS_EATTR_STRUCT(target_core_dev_pr
, se_subsystem_dev
);
1048 #define SE_DEV_PR_ATTR(_name, _mode) \
1049 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1050 __CONFIGFS_EATTR(_name, _mode, \
1051 target_core_dev_pr_show_attr_##_name, \
1052 target_core_dev_pr_store_attr_##_name);
1054 #define SE_DEV_PR_ATTR_RO(_name); \
1055 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1056 __CONFIGFS_EATTR_RO(_name, \
1057 target_core_dev_pr_show_attr_##_name);
1062 static ssize_t
target_core_dev_pr_show_spc3_res(
1063 struct se_device
*dev
,
1067 struct se_node_acl
*se_nacl
;
1068 struct t10_pr_registration
*pr_reg
;
1069 char i_buf
[PR_REG_ISID_ID_LEN
];
1072 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1074 spin_lock(&dev
->dev_reservation_lock
);
1075 pr_reg
= dev
->dev_pr_res_holder
;
1077 *len
+= sprintf(page
+ *len
, "No SPC-3 Reservation holder\n");
1078 spin_unlock(&dev
->dev_reservation_lock
);
1081 se_nacl
= pr_reg
->pr_reg_nacl
;
1082 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1083 PR_REG_ISID_ID_LEN
);
1085 *len
+= sprintf(page
+ *len
, "SPC-3 Reservation: %s Initiator: %s%s\n",
1086 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1087 se_nacl
->initiatorname
, (prf_isid
) ? &i_buf
[0] : "");
1088 spin_unlock(&dev
->dev_reservation_lock
);
1093 static ssize_t
target_core_dev_pr_show_spc2_res(
1094 struct se_device
*dev
,
1098 struct se_node_acl
*se_nacl
;
1100 spin_lock(&dev
->dev_reservation_lock
);
1101 se_nacl
= dev
->dev_reserved_node_acl
;
1103 *len
+= sprintf(page
+ *len
, "No SPC-2 Reservation holder\n");
1104 spin_unlock(&dev
->dev_reservation_lock
);
1107 *len
+= sprintf(page
+ *len
, "SPC-2 Reservation: %s Initiator: %s\n",
1108 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1109 se_nacl
->initiatorname
);
1110 spin_unlock(&dev
->dev_reservation_lock
);
1115 static ssize_t
target_core_dev_pr_show_attr_res_holder(
1116 struct se_subsystem_dev
*su_dev
,
1121 if (!su_dev
->se_dev_ptr
)
1124 switch (su_dev
->t10_pr
.res_type
) {
1125 case SPC3_PERSISTENT_RESERVATIONS
:
1126 target_core_dev_pr_show_spc3_res(su_dev
->se_dev_ptr
,
1129 case SPC2_RESERVATIONS
:
1130 target_core_dev_pr_show_spc2_res(su_dev
->se_dev_ptr
,
1133 case SPC_PASSTHROUGH
:
1134 len
+= sprintf(page
+len
, "Passthrough\n");
1137 len
+= sprintf(page
+len
, "Unknown\n");
1144 SE_DEV_PR_ATTR_RO(res_holder
);
1147 * res_pr_all_tgt_pts
1149 static ssize_t
target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1150 struct se_subsystem_dev
*su_dev
,
1153 struct se_device
*dev
;
1154 struct t10_pr_registration
*pr_reg
;
1157 dev
= su_dev
->se_dev_ptr
;
1161 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1164 spin_lock(&dev
->dev_reservation_lock
);
1165 pr_reg
= dev
->dev_pr_res_holder
;
1167 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1168 spin_unlock(&dev
->dev_reservation_lock
);
1172 * See All Target Ports (ALL_TG_PT) bit in spcr17, section 6.14.3
1173 * Basic PERSISTENT RESERVER OUT parameter list, page 290
1175 if (pr_reg
->pr_reg_all_tg_pt
)
1176 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1177 " Ports registration\n");
1179 len
= sprintf(page
, "SPC-3 Reservation: Single"
1180 " Target Port registration\n");
1181 spin_unlock(&dev
->dev_reservation_lock
);
1186 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts
);
1191 static ssize_t
target_core_dev_pr_show_attr_res_pr_generation(
1192 struct se_subsystem_dev
*su_dev
,
1195 if (!su_dev
->se_dev_ptr
)
1198 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1201 return sprintf(page
, "0x%08x\n", su_dev
->t10_pr
.pr_generation
);
1204 SE_DEV_PR_ATTR_RO(res_pr_generation
);
1207 * res_pr_holder_tg_port
1209 static ssize_t
target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1210 struct se_subsystem_dev
*su_dev
,
1213 struct se_device
*dev
;
1214 struct se_node_acl
*se_nacl
;
1216 struct se_portal_group
*se_tpg
;
1217 struct t10_pr_registration
*pr_reg
;
1218 struct target_core_fabric_ops
*tfo
;
1221 dev
= su_dev
->se_dev_ptr
;
1225 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1228 spin_lock(&dev
->dev_reservation_lock
);
1229 pr_reg
= dev
->dev_pr_res_holder
;
1231 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1232 spin_unlock(&dev
->dev_reservation_lock
);
1235 se_nacl
= pr_reg
->pr_reg_nacl
;
1236 se_tpg
= se_nacl
->se_tpg
;
1237 lun
= pr_reg
->pr_reg_tg_pt_lun
;
1238 tfo
= se_tpg
->se_tpg_tfo
;
1240 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1241 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1242 tfo
->tpg_get_wwn(se_tpg
));
1243 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1244 " Identifer Tag: %hu %s Portal Group Tag: %hu"
1245 " %s Logical Unit: %u\n", lun
->lun_sep
->sep_rtpi
,
1246 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1247 tfo
->get_fabric_name(), lun
->unpacked_lun
);
1248 spin_unlock(&dev
->dev_reservation_lock
);
1253 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port
);
1256 * res_pr_registered_i_pts
1258 static ssize_t
target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1259 struct se_subsystem_dev
*su_dev
,
1262 struct target_core_fabric_ops
*tfo
;
1263 struct t10_pr_registration
*pr_reg
;
1264 unsigned char buf
[384];
1265 char i_buf
[PR_REG_ISID_ID_LEN
];
1267 int reg_count
= 0, prf_isid
;
1269 if (!su_dev
->se_dev_ptr
)
1272 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1275 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1277 spin_lock(&su_dev
->t10_pr
.registration_lock
);
1278 list_for_each_entry(pr_reg
, &su_dev
->t10_pr
.registration_list
,
1281 memset(buf
, 0, 384);
1282 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1283 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1284 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1285 PR_REG_ISID_ID_LEN
);
1286 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1287 tfo
->get_fabric_name(),
1288 pr_reg
->pr_reg_nacl
->initiatorname
, (prf_isid
) ?
1289 &i_buf
[0] : "", pr_reg
->pr_res_key
,
1290 pr_reg
->pr_res_generation
);
1292 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1295 len
+= sprintf(page
+len
, "%s", buf
);
1298 spin_unlock(&su_dev
->t10_pr
.registration_lock
);
1301 len
+= sprintf(page
+len
, "None\n");
1306 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts
);
1311 static ssize_t
target_core_dev_pr_show_attr_res_pr_type(
1312 struct se_subsystem_dev
*su_dev
,
1315 struct se_device
*dev
;
1316 struct t10_pr_registration
*pr_reg
;
1319 dev
= su_dev
->se_dev_ptr
;
1323 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1326 spin_lock(&dev
->dev_reservation_lock
);
1327 pr_reg
= dev
->dev_pr_res_holder
;
1329 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1330 spin_unlock(&dev
->dev_reservation_lock
);
1333 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1334 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1335 spin_unlock(&dev
->dev_reservation_lock
);
1340 SE_DEV_PR_ATTR_RO(res_pr_type
);
1345 static ssize_t
target_core_dev_pr_show_attr_res_type(
1346 struct se_subsystem_dev
*su_dev
,
1351 if (!su_dev
->se_dev_ptr
)
1354 switch (su_dev
->t10_pr
.res_type
) {
1355 case SPC3_PERSISTENT_RESERVATIONS
:
1356 len
= sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1358 case SPC2_RESERVATIONS
:
1359 len
= sprintf(page
, "SPC2_RESERVATIONS\n");
1361 case SPC_PASSTHROUGH
:
1362 len
= sprintf(page
, "SPC_PASSTHROUGH\n");
1365 len
= sprintf(page
, "UNKNOWN\n");
1372 SE_DEV_PR_ATTR_RO(res_type
);
1378 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_active(
1379 struct se_subsystem_dev
*su_dev
,
1382 if (!su_dev
->se_dev_ptr
)
1385 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1388 return sprintf(page
, "APTPL Bit Status: %s\n",
1389 (su_dev
->t10_pr
.pr_aptpl_active
) ? "Activated" : "Disabled");
1392 SE_DEV_PR_ATTR_RO(res_aptpl_active
);
1395 * res_aptpl_metadata
1397 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_metadata(
1398 struct se_subsystem_dev
*su_dev
,
1401 if (!su_dev
->se_dev_ptr
)
1404 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1407 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1411 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1412 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1413 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1414 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1417 static match_table_t tokens
= {
1418 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1419 {Opt_initiator_node
, "initiator_node=%s"},
1420 {Opt_initiator_sid
, "initiator_sid=%s"},
1421 {Opt_sa_res_key
, "sa_res_key=%s"},
1422 {Opt_res_holder
, "res_holder=%d"},
1423 {Opt_res_type
, "res_type=%d"},
1424 {Opt_res_scope
, "res_scope=%d"},
1425 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1426 {Opt_mapped_lun
, "mapped_lun=%d"},
1427 {Opt_target_fabric
, "target_fabric=%s"},
1428 {Opt_target_node
, "target_node=%s"},
1429 {Opt_tpgt
, "tpgt=%d"},
1430 {Opt_port_rtpi
, "port_rtpi=%d"},
1431 {Opt_target_lun
, "target_lun=%d"},
1435 static ssize_t
target_core_dev_pr_store_attr_res_aptpl_metadata(
1436 struct se_subsystem_dev
*su_dev
,
1440 struct se_device
*dev
;
1441 unsigned char *i_fabric
= NULL
, *i_port
= NULL
, *isid
= NULL
;
1442 unsigned char *t_fabric
= NULL
, *t_port
= NULL
;
1443 char *orig
, *ptr
, *arg_p
, *opts
;
1444 substring_t args
[MAX_OPT_ARGS
];
1445 unsigned long long tmp_ll
;
1447 u32 mapped_lun
= 0, target_lun
= 0;
1448 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1449 u16 port_rpti
= 0, tpgt
= 0;
1452 dev
= su_dev
->se_dev_ptr
;
1456 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1459 if (atomic_read(&dev
->dev_export_obj
.obj_access_count
)) {
1460 pr_debug("Unable to process APTPL metadata while"
1461 " active fabric exports exist\n");
1465 opts
= kstrdup(page
, GFP_KERNEL
);
1470 while ((ptr
= strsep(&opts
, ",")) != NULL
) {
1474 token
= match_token(ptr
, tokens
, args
);
1476 case Opt_initiator_fabric
:
1477 i_fabric
= match_strdup(&args
[0]);
1483 case Opt_initiator_node
:
1484 i_port
= match_strdup(&args
[0]);
1489 if (strlen(i_port
) >= PR_APTPL_MAX_IPORT_LEN
) {
1490 pr_err("APTPL metadata initiator_node="
1491 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1492 PR_APTPL_MAX_IPORT_LEN
);
1497 case Opt_initiator_sid
:
1498 isid
= match_strdup(&args
[0]);
1503 if (strlen(isid
) >= PR_REG_ISID_LEN
) {
1504 pr_err("APTPL metadata initiator_isid"
1505 "= exceeds PR_REG_ISID_LEN: %d\n",
1511 case Opt_sa_res_key
:
1512 arg_p
= match_strdup(&args
[0]);
1517 ret
= strict_strtoull(arg_p
, 0, &tmp_ll
);
1519 pr_err("strict_strtoull() failed for"
1523 sa_res_key
= (u64
)tmp_ll
;
1526 * PR APTPL Metadata for Reservation
1528 case Opt_res_holder
:
1529 match_int(args
, &arg
);
1533 match_int(args
, &arg
);
1537 match_int(args
, &arg
);
1540 case Opt_res_all_tg_pt
:
1541 match_int(args
, &arg
);
1542 all_tg_pt
= (int)arg
;
1544 case Opt_mapped_lun
:
1545 match_int(args
, &arg
);
1546 mapped_lun
= (u32
)arg
;
1549 * PR APTPL Metadata for Target Port
1551 case Opt_target_fabric
:
1552 t_fabric
= match_strdup(&args
[0]);
1558 case Opt_target_node
:
1559 t_port
= match_strdup(&args
[0]);
1564 if (strlen(t_port
) >= PR_APTPL_MAX_TPORT_LEN
) {
1565 pr_err("APTPL metadata target_node="
1566 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1567 PR_APTPL_MAX_TPORT_LEN
);
1573 match_int(args
, &arg
);
1577 match_int(args
, &arg
);
1578 port_rpti
= (u16
)arg
;
1580 case Opt_target_lun
:
1581 match_int(args
, &arg
);
1582 target_lun
= (u32
)arg
;
1589 if (!i_port
|| !t_port
|| !sa_res_key
) {
1590 pr_err("Illegal parameters for APTPL registration\n");
1595 if (res_holder
&& !(type
)) {
1596 pr_err("Illegal PR type: 0x%02x for reservation"
1602 ret
= core_scsi3_alloc_aptpl_registration(&su_dev
->t10_pr
, sa_res_key
,
1603 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1604 res_holder
, all_tg_pt
, type
);
1612 return (ret
== 0) ? count
: ret
;
1615 SE_DEV_PR_ATTR(res_aptpl_metadata
, S_IRUGO
| S_IWUSR
);
1617 CONFIGFS_EATTR_OPS(target_core_dev_pr
, se_subsystem_dev
, se_dev_pr_group
);
1619 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1620 &target_core_dev_pr_res_holder
.attr
,
1621 &target_core_dev_pr_res_pr_all_tgt_pts
.attr
,
1622 &target_core_dev_pr_res_pr_generation
.attr
,
1623 &target_core_dev_pr_res_pr_holder_tg_port
.attr
,
1624 &target_core_dev_pr_res_pr_registered_i_pts
.attr
,
1625 &target_core_dev_pr_res_pr_type
.attr
,
1626 &target_core_dev_pr_res_type
.attr
,
1627 &target_core_dev_pr_res_aptpl_active
.attr
,
1628 &target_core_dev_pr_res_aptpl_metadata
.attr
,
1632 static struct configfs_item_operations target_core_dev_pr_ops
= {
1633 .show_attribute
= target_core_dev_pr_attr_show
,
1634 .store_attribute
= target_core_dev_pr_attr_store
,
1637 static struct config_item_type target_core_dev_pr_cit
= {
1638 .ct_item_ops
= &target_core_dev_pr_ops
,
1639 .ct_attrs
= target_core_dev_pr_attrs
,
1640 .ct_owner
= THIS_MODULE
,
1643 /* End functions for struct config_item_type target_core_dev_pr_cit */
1645 /* Start functions for struct config_item_type target_core_dev_cit */
1647 static ssize_t
target_core_show_dev_info(void *p
, char *page
)
1649 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1650 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1651 struct se_subsystem_api
*t
= hba
->transport
;
1653 ssize_t read_bytes
= 0;
1655 if (!se_dev
->se_dev_ptr
)
1658 transport_dump_dev_state(se_dev
->se_dev_ptr
, page
, &bl
);
1660 read_bytes
+= t
->show_configfs_dev_params(hba
, se_dev
, page
+read_bytes
);
1664 static struct target_core_configfs_attribute target_core_attr_dev_info
= {
1665 .attr
= { .ca_owner
= THIS_MODULE
,
1667 .ca_mode
= S_IRUGO
},
1668 .show
= target_core_show_dev_info
,
1672 static ssize_t
target_core_store_dev_control(
1677 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1678 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1679 struct se_subsystem_api
*t
= hba
->transport
;
1681 if (!se_dev
->se_dev_su_ptr
) {
1682 pr_err("Unable to locate struct se_subsystem_dev>se"
1687 return t
->set_configfs_dev_params(hba
, se_dev
, page
, count
);
1690 static struct target_core_configfs_attribute target_core_attr_dev_control
= {
1691 .attr
= { .ca_owner
= THIS_MODULE
,
1692 .ca_name
= "control",
1693 .ca_mode
= S_IWUSR
},
1695 .store
= target_core_store_dev_control
,
1698 static ssize_t
target_core_show_dev_alias(void *p
, char *page
)
1700 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1702 if (!(se_dev
->su_dev_flags
& SDF_USING_ALIAS
))
1705 return snprintf(page
, PAGE_SIZE
, "%s\n", se_dev
->se_dev_alias
);
1708 static ssize_t
target_core_store_dev_alias(
1713 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1714 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1717 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1718 pr_err("alias count: %d exceeds"
1719 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1720 SE_DEV_ALIAS_LEN
-1);
1724 se_dev
->su_dev_flags
|= SDF_USING_ALIAS
;
1725 read_bytes
= snprintf(&se_dev
->se_dev_alias
[0], SE_DEV_ALIAS_LEN
,
1728 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
1729 config_item_name(&hba
->hba_group
.cg_item
),
1730 config_item_name(&se_dev
->se_dev_group
.cg_item
),
1731 se_dev
->se_dev_alias
);
1736 static struct target_core_configfs_attribute target_core_attr_dev_alias
= {
1737 .attr
= { .ca_owner
= THIS_MODULE
,
1739 .ca_mode
= S_IRUGO
| S_IWUSR
},
1740 .show
= target_core_show_dev_alias
,
1741 .store
= target_core_store_dev_alias
,
1744 static ssize_t
target_core_show_dev_udev_path(void *p
, char *page
)
1746 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1748 if (!(se_dev
->su_dev_flags
& SDF_USING_UDEV_PATH
))
1751 return snprintf(page
, PAGE_SIZE
, "%s\n", se_dev
->se_dev_udev_path
);
1754 static ssize_t
target_core_store_dev_udev_path(
1759 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1760 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1763 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1764 pr_err("udev_path count: %d exceeds"
1765 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1766 SE_UDEV_PATH_LEN
-1);
1770 se_dev
->su_dev_flags
|= SDF_USING_UDEV_PATH
;
1771 read_bytes
= snprintf(&se_dev
->se_dev_udev_path
[0], SE_UDEV_PATH_LEN
,
1774 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1775 config_item_name(&hba
->hba_group
.cg_item
),
1776 config_item_name(&se_dev
->se_dev_group
.cg_item
),
1777 se_dev
->se_dev_udev_path
);
1782 static struct target_core_configfs_attribute target_core_attr_dev_udev_path
= {
1783 .attr
= { .ca_owner
= THIS_MODULE
,
1784 .ca_name
= "udev_path",
1785 .ca_mode
= S_IRUGO
| S_IWUSR
},
1786 .show
= target_core_show_dev_udev_path
,
1787 .store
= target_core_store_dev_udev_path
,
1790 static ssize_t
target_core_store_dev_enable(
1795 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1796 struct se_device
*dev
;
1797 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1798 struct se_subsystem_api
*t
= hba
->transport
;
1801 ptr
= strstr(page
, "1");
1803 pr_err("For dev_enable ops, only valid value"
1807 if (se_dev
->se_dev_ptr
) {
1808 pr_err("se_dev->se_dev_ptr already set for storage"
1813 if (t
->check_configfs_dev_params(hba
, se_dev
) < 0)
1816 dev
= t
->create_virtdevice(hba
, se_dev
, se_dev
->se_dev_su_ptr
);
1818 return PTR_ERR(dev
);
1822 se_dev
->se_dev_ptr
= dev
;
1823 pr_debug("Target_Core_ConfigFS: Registered se_dev->se_dev_ptr:"
1824 " %p\n", se_dev
->se_dev_ptr
);
1829 static struct target_core_configfs_attribute target_core_attr_dev_enable
= {
1830 .attr
= { .ca_owner
= THIS_MODULE
,
1831 .ca_name
= "enable",
1832 .ca_mode
= S_IWUSR
},
1834 .store
= target_core_store_dev_enable
,
1837 static ssize_t
target_core_show_alua_lu_gp(void *p
, char *page
)
1839 struct se_device
*dev
;
1840 struct se_subsystem_dev
*su_dev
= (struct se_subsystem_dev
*)p
;
1841 struct config_item
*lu_ci
;
1842 struct t10_alua_lu_gp
*lu_gp
;
1843 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1846 dev
= su_dev
->se_dev_ptr
;
1850 if (su_dev
->t10_alua
.alua_type
!= SPC3_ALUA_EMULATED
)
1853 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1855 pr_err("NULL struct se_device->dev_alua_lu_gp_mem"
1860 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1861 lu_gp
= lu_gp_mem
->lu_gp
;
1863 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1864 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1865 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1867 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1872 static ssize_t
target_core_store_alua_lu_gp(
1877 struct se_device
*dev
;
1878 struct se_subsystem_dev
*su_dev
= (struct se_subsystem_dev
*)p
;
1879 struct se_hba
*hba
= su_dev
->se_dev_hba
;
1880 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1881 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1882 unsigned char buf
[LU_GROUP_NAME_BUF
];
1885 dev
= su_dev
->se_dev_ptr
;
1889 if (su_dev
->t10_alua
.alua_type
!= SPC3_ALUA_EMULATED
) {
1890 pr_warn("SPC3_ALUA_EMULATED not enabled for %s/%s\n",
1891 config_item_name(&hba
->hba_group
.cg_item
),
1892 config_item_name(&su_dev
->se_dev_group
.cg_item
));
1895 if (count
> LU_GROUP_NAME_BUF
) {
1896 pr_err("ALUA LU Group Alias too large!\n");
1899 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1900 memcpy(buf
, page
, count
);
1902 * Any ALUA logical unit alias besides "NULL" means we will be
1903 * making a new group association.
1905 if (strcmp(strstrip(buf
), "NULL")) {
1907 * core_alua_get_lu_gp_by_name() will increment reference to
1908 * struct t10_alua_lu_gp. This reference is released with
1909 * core_alua_get_lu_gp_by_name below().
1911 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
1915 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1918 core_alua_put_lu_gp_from_name(lu_gp_new
);
1919 pr_err("NULL struct se_device->dev_alua_lu_gp_mem"
1924 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1925 lu_gp
= lu_gp_mem
->lu_gp
;
1928 * Clearing an existing lu_gp association, and replacing
1932 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
1933 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1935 config_item_name(&hba
->hba_group
.cg_item
),
1936 config_item_name(&su_dev
->se_dev_group
.cg_item
),
1937 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1940 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1941 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1946 * Removing existing association of lu_gp_mem with lu_gp
1948 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1952 * Associate lu_gp_mem with lu_gp_new.
1954 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
1955 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1957 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1958 " core/alua/lu_gps/%s, ID: %hu\n",
1959 (move
) ? "Moving" : "Adding",
1960 config_item_name(&hba
->hba_group
.cg_item
),
1961 config_item_name(&su_dev
->se_dev_group
.cg_item
),
1962 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
1963 lu_gp_new
->lu_gp_id
);
1965 core_alua_put_lu_gp_from_name(lu_gp_new
);
1969 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp
= {
1970 .attr
= { .ca_owner
= THIS_MODULE
,
1971 .ca_name
= "alua_lu_gp",
1972 .ca_mode
= S_IRUGO
| S_IWUSR
},
1973 .show
= target_core_show_alua_lu_gp
,
1974 .store
= target_core_store_alua_lu_gp
,
1977 static struct configfs_attribute
*lio_core_dev_attrs
[] = {
1978 &target_core_attr_dev_info
.attr
,
1979 &target_core_attr_dev_control
.attr
,
1980 &target_core_attr_dev_alias
.attr
,
1981 &target_core_attr_dev_udev_path
.attr
,
1982 &target_core_attr_dev_enable
.attr
,
1983 &target_core_attr_dev_alua_lu_gp
.attr
,
1987 static void target_core_dev_release(struct config_item
*item
)
1989 struct se_subsystem_dev
*se_dev
= container_of(to_config_group(item
),
1990 struct se_subsystem_dev
, se_dev_group
);
1991 struct se_hba
*hba
= item_to_hba(&se_dev
->se_dev_hba
->hba_group
.cg_item
);
1992 struct se_subsystem_api
*t
= hba
->transport
;
1993 struct config_group
*dev_cg
= &se_dev
->se_dev_group
;
1995 kfree(dev_cg
->default_groups
);
1997 * This pointer will set when the storage is enabled with:
1998 *`echo 1 > $CONFIGFS/core/$HBA/$DEV/dev_enable`
2000 if (se_dev
->se_dev_ptr
) {
2001 pr_debug("Target_Core_ConfigFS: Calling se_free_"
2002 "virtual_device() for se_dev_ptr: %p\n",
2003 se_dev
->se_dev_ptr
);
2005 se_free_virtual_device(se_dev
->se_dev_ptr
, hba
);
2008 * Release struct se_subsystem_dev->se_dev_su_ptr..
2010 pr_debug("Target_Core_ConfigFS: Calling t->free_"
2011 "device() for se_dev_su_ptr: %p\n",
2012 se_dev
->se_dev_su_ptr
);
2014 t
->free_device(se_dev
->se_dev_su_ptr
);
2017 pr_debug("Target_Core_ConfigFS: Deallocating se_subsystem"
2018 "_dev_t: %p\n", se_dev
);
2022 static ssize_t
target_core_dev_show(struct config_item
*item
,
2023 struct configfs_attribute
*attr
,
2026 struct se_subsystem_dev
*se_dev
= container_of(
2027 to_config_group(item
), struct se_subsystem_dev
,
2029 struct target_core_configfs_attribute
*tc_attr
= container_of(
2030 attr
, struct target_core_configfs_attribute
, attr
);
2035 return tc_attr
->show(se_dev
, page
);
2038 static ssize_t
target_core_dev_store(struct config_item
*item
,
2039 struct configfs_attribute
*attr
,
2040 const char *page
, size_t count
)
2042 struct se_subsystem_dev
*se_dev
= container_of(
2043 to_config_group(item
), struct se_subsystem_dev
,
2045 struct target_core_configfs_attribute
*tc_attr
= container_of(
2046 attr
, struct target_core_configfs_attribute
, attr
);
2048 if (!tc_attr
->store
)
2051 return tc_attr
->store(se_dev
, page
, count
);
2054 static struct configfs_item_operations target_core_dev_item_ops
= {
2055 .release
= target_core_dev_release
,
2056 .show_attribute
= target_core_dev_show
,
2057 .store_attribute
= target_core_dev_store
,
2060 static struct config_item_type target_core_dev_cit
= {
2061 .ct_item_ops
= &target_core_dev_item_ops
,
2062 .ct_attrs
= lio_core_dev_attrs
,
2063 .ct_owner
= THIS_MODULE
,
2066 /* End functions for struct config_item_type target_core_dev_cit */
2068 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
2070 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp
, t10_alua_lu_gp
);
2071 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
2072 static struct target_core_alua_lu_gp_attribute \
2073 target_core_alua_lu_gp_##_name = \
2074 __CONFIGFS_EATTR(_name, _mode, \
2075 target_core_alua_lu_gp_show_attr_##_name, \
2076 target_core_alua_lu_gp_store_attr_##_name);
2078 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
2079 static struct target_core_alua_lu_gp_attribute \
2080 target_core_alua_lu_gp_##_name = \
2081 __CONFIGFS_EATTR_RO(_name, \
2082 target_core_alua_lu_gp_show_attr_##_name);
2087 static ssize_t
target_core_alua_lu_gp_show_attr_lu_gp_id(
2088 struct t10_alua_lu_gp
*lu_gp
,
2091 if (!lu_gp
->lu_gp_valid_id
)
2094 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
2097 static ssize_t
target_core_alua_lu_gp_store_attr_lu_gp_id(
2098 struct t10_alua_lu_gp
*lu_gp
,
2102 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2103 unsigned long lu_gp_id
;
2106 ret
= strict_strtoul(page
, 0, &lu_gp_id
);
2108 pr_err("strict_strtoul() returned %d for"
2109 " lu_gp_id\n", ret
);
2112 if (lu_gp_id
> 0x0000ffff) {
2113 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
2114 " 0x0000ffff\n", lu_gp_id
);
2118 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
2122 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
2123 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2124 config_item_name(&alua_lu_gp_cg
->cg_item
),
2130 SE_DEV_ALUA_LU_ATTR(lu_gp_id
, S_IRUGO
| S_IWUSR
);
2135 static ssize_t
target_core_alua_lu_gp_show_attr_members(
2136 struct t10_alua_lu_gp
*lu_gp
,
2139 struct se_device
*dev
;
2141 struct se_subsystem_dev
*su_dev
;
2142 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2143 ssize_t len
= 0, cur_len
;
2144 unsigned char buf
[LU_GROUP_NAME_BUF
];
2146 memset(buf
, 0, LU_GROUP_NAME_BUF
);
2148 spin_lock(&lu_gp
->lu_gp_lock
);
2149 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
2150 dev
= lu_gp_mem
->lu_gp_mem_dev
;
2151 su_dev
= dev
->se_sub_dev
;
2152 hba
= su_dev
->se_dev_hba
;
2154 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
2155 config_item_name(&hba
->hba_group
.cg_item
),
2156 config_item_name(&su_dev
->se_dev_group
.cg_item
));
2157 cur_len
++; /* Extra byte for NULL terminator */
2159 if ((cur_len
+ len
) > PAGE_SIZE
) {
2160 pr_warn("Ran out of lu_gp_show_attr"
2161 "_members buffer\n");
2164 memcpy(page
+len
, buf
, cur_len
);
2167 spin_unlock(&lu_gp
->lu_gp_lock
);
2172 SE_DEV_ALUA_LU_ATTR_RO(members
);
2174 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp
, t10_alua_lu_gp
, lu_gp_group
);
2176 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
2177 &target_core_alua_lu_gp_lu_gp_id
.attr
,
2178 &target_core_alua_lu_gp_members
.attr
,
2182 static void target_core_alua_lu_gp_release(struct config_item
*item
)
2184 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2185 struct t10_alua_lu_gp
, lu_gp_group
);
2187 core_alua_free_lu_gp(lu_gp
);
2190 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
2191 .release
= target_core_alua_lu_gp_release
,
2192 .show_attribute
= target_core_alua_lu_gp_attr_show
,
2193 .store_attribute
= target_core_alua_lu_gp_attr_store
,
2196 static struct config_item_type target_core_alua_lu_gp_cit
= {
2197 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
2198 .ct_attrs
= target_core_alua_lu_gp_attrs
,
2199 .ct_owner
= THIS_MODULE
,
2202 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
2204 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
2206 static struct config_group
*target_core_alua_create_lu_gp(
2207 struct config_group
*group
,
2210 struct t10_alua_lu_gp
*lu_gp
;
2211 struct config_group
*alua_lu_gp_cg
= NULL
;
2212 struct config_item
*alua_lu_gp_ci
= NULL
;
2214 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
2218 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2219 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
2221 config_group_init_type_name(alua_lu_gp_cg
, name
,
2222 &target_core_alua_lu_gp_cit
);
2224 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2225 " Group: core/alua/lu_gps/%s\n",
2226 config_item_name(alua_lu_gp_ci
));
2228 return alua_lu_gp_cg
;
2232 static void target_core_alua_drop_lu_gp(
2233 struct config_group
*group
,
2234 struct config_item
*item
)
2236 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2237 struct t10_alua_lu_gp
, lu_gp_group
);
2239 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2240 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2241 config_item_name(item
), lu_gp
->lu_gp_id
);
2243 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
2244 * -> target_core_alua_lu_gp_release()
2246 config_item_put(item
);
2249 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
2250 .make_group
= &target_core_alua_create_lu_gp
,
2251 .drop_item
= &target_core_alua_drop_lu_gp
,
2254 static struct config_item_type target_core_alua_lu_gps_cit
= {
2255 .ct_item_ops
= NULL
,
2256 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
2257 .ct_owner
= THIS_MODULE
,
2260 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
2262 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2264 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
);
2265 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
2266 static struct target_core_alua_tg_pt_gp_attribute \
2267 target_core_alua_tg_pt_gp_##_name = \
2268 __CONFIGFS_EATTR(_name, _mode, \
2269 target_core_alua_tg_pt_gp_show_attr_##_name, \
2270 target_core_alua_tg_pt_gp_store_attr_##_name);
2272 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2273 static struct target_core_alua_tg_pt_gp_attribute \
2274 target_core_alua_tg_pt_gp_##_name = \
2275 __CONFIGFS_EATTR_RO(_name, \
2276 target_core_alua_tg_pt_gp_show_attr_##_name);
2281 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2282 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2285 return sprintf(page
, "%d\n",
2286 atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
));
2289 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2290 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2294 struct se_subsystem_dev
*su_dev
= tg_pt_gp
->tg_pt_gp_su_dev
;
2298 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2299 pr_err("Unable to do implict ALUA on non valid"
2300 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2304 ret
= strict_strtoul(page
, 0, &tmp
);
2306 pr_err("Unable to extract new ALUA access state from"
2310 new_state
= (int)tmp
;
2312 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICT_ALUA
)) {
2313 pr_err("Unable to process implict configfs ALUA"
2314 " transition while TPGS_IMPLICT_ALUA is diabled\n");
2318 ret
= core_alua_do_port_transition(tg_pt_gp
, su_dev
->se_dev_ptr
,
2319 NULL
, NULL
, new_state
, 0);
2320 return (!ret
) ? count
: -EINVAL
;
2323 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state
, S_IRUGO
| S_IWUSR
);
2326 * alua_access_status
2328 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2329 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2332 return sprintf(page
, "%s\n",
2333 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2336 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2337 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2342 int new_status
, ret
;
2344 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2345 pr_err("Unable to do set ALUA access status on non"
2346 " valid tg_pt_gp ID: %hu\n",
2347 tg_pt_gp
->tg_pt_gp_valid_id
);
2351 ret
= strict_strtoul(page
, 0, &tmp
);
2353 pr_err("Unable to extract new ALUA access status"
2354 " from %s\n", page
);
2357 new_status
= (int)tmp
;
2359 if ((new_status
!= ALUA_STATUS_NONE
) &&
2360 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
) &&
2361 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
)) {
2362 pr_err("Illegal ALUA access status: 0x%02x\n",
2367 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2371 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status
, S_IRUGO
| S_IWUSR
);
2376 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2377 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2380 return core_alua_show_access_type(tg_pt_gp
, page
);
2383 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2384 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2388 return core_alua_store_access_type(tg_pt_gp
, page
, count
);
2391 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type
, S_IRUGO
| S_IWUSR
);
2394 * alua_write_metadata
2396 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2397 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2400 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_write_metadata
);
2403 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2404 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2411 ret
= strict_strtoul(page
, 0, &tmp
);
2413 pr_err("Unable to extract alua_write_metadata\n");
2417 if ((tmp
!= 0) && (tmp
!= 1)) {
2418 pr_err("Illegal value for alua_write_metadata:"
2422 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2427 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata
, S_IRUGO
| S_IWUSR
);
2434 static ssize_t
target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2435 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2438 return core_alua_show_nonop_delay_msecs(tg_pt_gp
, page
);
2442 static ssize_t
target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2443 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2447 return core_alua_store_nonop_delay_msecs(tg_pt_gp
, page
, count
);
2450 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs
, S_IRUGO
| S_IWUSR
);
2455 static ssize_t
target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2456 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2459 return core_alua_show_trans_delay_msecs(tg_pt_gp
, page
);
2462 static ssize_t
target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2463 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2467 return core_alua_store_trans_delay_msecs(tg_pt_gp
, page
, count
);
2470 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs
, S_IRUGO
| S_IWUSR
);
2476 static ssize_t
target_core_alua_tg_pt_gp_show_attr_preferred(
2477 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2480 return core_alua_show_preferred_bit(tg_pt_gp
, page
);
2483 static ssize_t
target_core_alua_tg_pt_gp_store_attr_preferred(
2484 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2488 return core_alua_store_preferred_bit(tg_pt_gp
, page
, count
);
2491 SE_DEV_ALUA_TG_PT_ATTR(preferred
, S_IRUGO
| S_IWUSR
);
2496 static ssize_t
target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2497 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2500 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
2503 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2506 static ssize_t
target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2507 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2511 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2512 unsigned long tg_pt_gp_id
;
2515 ret
= strict_strtoul(page
, 0, &tg_pt_gp_id
);
2517 pr_err("strict_strtoul() returned %d for"
2518 " tg_pt_gp_id\n", ret
);
2521 if (tg_pt_gp_id
> 0x0000ffff) {
2522 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:"
2523 " 0x0000ffff\n", tg_pt_gp_id
);
2527 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2531 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
2532 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2533 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2534 tg_pt_gp
->tg_pt_gp_id
);
2539 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id
, S_IRUGO
| S_IWUSR
);
2544 static ssize_t
target_core_alua_tg_pt_gp_show_attr_members(
2545 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2548 struct se_port
*port
;
2549 struct se_portal_group
*tpg
;
2551 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
2552 ssize_t len
= 0, cur_len
;
2553 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2555 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2557 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2558 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
2559 tg_pt_gp_mem_list
) {
2560 port
= tg_pt_gp_mem
->tg_pt
;
2561 tpg
= port
->sep_tpg
;
2562 lun
= port
->sep_lun
;
2564 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2565 "/%s\n", tpg
->se_tpg_tfo
->get_fabric_name(),
2566 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
2567 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
2568 config_item_name(&lun
->lun_group
.cg_item
));
2569 cur_len
++; /* Extra byte for NULL terminator */
2571 if ((cur_len
+ len
) > PAGE_SIZE
) {
2572 pr_warn("Ran out of lu_gp_show_attr"
2573 "_members buffer\n");
2576 memcpy(page
+len
, buf
, cur_len
);
2579 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2584 SE_DEV_ALUA_TG_PT_ATTR_RO(members
);
2586 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
,
2589 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2590 &target_core_alua_tg_pt_gp_alua_access_state
.attr
,
2591 &target_core_alua_tg_pt_gp_alua_access_status
.attr
,
2592 &target_core_alua_tg_pt_gp_alua_access_type
.attr
,
2593 &target_core_alua_tg_pt_gp_alua_write_metadata
.attr
,
2594 &target_core_alua_tg_pt_gp_nonop_delay_msecs
.attr
,
2595 &target_core_alua_tg_pt_gp_trans_delay_msecs
.attr
,
2596 &target_core_alua_tg_pt_gp_preferred
.attr
,
2597 &target_core_alua_tg_pt_gp_tg_pt_gp_id
.attr
,
2598 &target_core_alua_tg_pt_gp_members
.attr
,
2602 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2604 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2605 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2607 core_alua_free_tg_pt_gp(tg_pt_gp
);
2610 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2611 .release
= target_core_alua_tg_pt_gp_release
,
2612 .show_attribute
= target_core_alua_tg_pt_gp_attr_show
,
2613 .store_attribute
= target_core_alua_tg_pt_gp_attr_store
,
2616 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2617 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2618 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2619 .ct_owner
= THIS_MODULE
,
2622 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2624 /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2626 static struct config_group
*target_core_alua_create_tg_pt_gp(
2627 struct config_group
*group
,
2630 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2631 alua_tg_pt_gps_group
);
2632 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2633 struct se_subsystem_dev
*su_dev
= alua
->t10_sub_dev
;
2634 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2635 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2637 tg_pt_gp
= core_alua_allocate_tg_pt_gp(su_dev
, name
, 0);
2641 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2642 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2644 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2645 &target_core_alua_tg_pt_gp_cit
);
2647 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
2648 " Group: alua/tg_pt_gps/%s\n",
2649 config_item_name(alua_tg_pt_gp_ci
));
2651 return alua_tg_pt_gp_cg
;
2654 static void target_core_alua_drop_tg_pt_gp(
2655 struct config_group
*group
,
2656 struct config_item
*item
)
2658 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2659 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2661 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
2662 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2663 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2665 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2666 * -> target_core_alua_tg_pt_gp_release().
2668 config_item_put(item
);
2671 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2672 .make_group
= &target_core_alua_create_tg_pt_gp
,
2673 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2676 static struct config_item_type target_core_alua_tg_pt_gps_cit
= {
2677 .ct_group_ops
= &target_core_alua_tg_pt_gps_group_ops
,
2678 .ct_owner
= THIS_MODULE
,
2681 /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2683 /* Start functions for struct config_item_type target_core_alua_cit */
2686 * target_core_alua_cit is a ConfigFS group that lives under
2687 * /sys/kernel/config/target/core/alua. There are default groups
2688 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2689 * target_core_alua_cit in target_core_init_configfs() below.
2691 static struct config_item_type target_core_alua_cit
= {
2692 .ct_item_ops
= NULL
,
2694 .ct_owner
= THIS_MODULE
,
2697 /* End functions for struct config_item_type target_core_alua_cit */
2699 /* Start functions for struct config_item_type target_core_stat_cit */
2701 static struct config_group
*target_core_stat_mkdir(
2702 struct config_group
*group
,
2705 return ERR_PTR(-ENOSYS
);
2708 static void target_core_stat_rmdir(
2709 struct config_group
*group
,
2710 struct config_item
*item
)
2715 static struct configfs_group_operations target_core_stat_group_ops
= {
2716 .make_group
= &target_core_stat_mkdir
,
2717 .drop_item
= &target_core_stat_rmdir
,
2720 static struct config_item_type target_core_stat_cit
= {
2721 .ct_group_ops
= &target_core_stat_group_ops
,
2722 .ct_owner
= THIS_MODULE
,
2725 /* End functions for struct config_item_type target_core_stat_cit */
2727 /* Start functions for struct config_item_type target_core_hba_cit */
2729 static struct config_group
*target_core_make_subdev(
2730 struct config_group
*group
,
2733 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2734 struct se_subsystem_dev
*se_dev
;
2735 struct se_subsystem_api
*t
;
2736 struct config_item
*hba_ci
= &group
->cg_item
;
2737 struct se_hba
*hba
= item_to_hba(hba_ci
);
2738 struct config_group
*dev_cg
= NULL
, *tg_pt_gp_cg
= NULL
;
2739 struct config_group
*dev_stat_grp
= NULL
;
2740 int errno
= -ENOMEM
, ret
;
2742 ret
= mutex_lock_interruptible(&hba
->hba_access_mutex
);
2744 return ERR_PTR(ret
);
2746 * Locate the struct se_subsystem_api from parent's struct se_hba.
2750 se_dev
= kzalloc(sizeof(struct se_subsystem_dev
), GFP_KERNEL
);
2752 pr_err("Unable to allocate memory for"
2753 " struct se_subsystem_dev\n");
2756 INIT_LIST_HEAD(&se_dev
->se_dev_node
);
2757 INIT_LIST_HEAD(&se_dev
->t10_wwn
.t10_vpd_list
);
2758 spin_lock_init(&se_dev
->t10_wwn
.t10_vpd_lock
);
2759 INIT_LIST_HEAD(&se_dev
->t10_pr
.registration_list
);
2760 INIT_LIST_HEAD(&se_dev
->t10_pr
.aptpl_reg_list
);
2761 spin_lock_init(&se_dev
->t10_pr
.registration_lock
);
2762 spin_lock_init(&se_dev
->t10_pr
.aptpl_reg_lock
);
2763 INIT_LIST_HEAD(&se_dev
->t10_alua
.tg_pt_gps_list
);
2764 spin_lock_init(&se_dev
->t10_alua
.tg_pt_gps_lock
);
2765 spin_lock_init(&se_dev
->se_dev_lock
);
2766 se_dev
->t10_pr
.pr_aptpl_buf_len
= PR_APTPL_BUF_LEN
;
2767 se_dev
->t10_wwn
.t10_sub_dev
= se_dev
;
2768 se_dev
->t10_alua
.t10_sub_dev
= se_dev
;
2769 se_dev
->se_dev_attrib
.da_sub_dev
= se_dev
;
2771 se_dev
->se_dev_hba
= hba
;
2772 dev_cg
= &se_dev
->se_dev_group
;
2774 dev_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 7,
2776 if (!dev_cg
->default_groups
)
2779 * Set se_dev_su_ptr from struct se_subsystem_api returned void ptr
2780 * for ->allocate_virtdevice()
2782 * se_dev->se_dev_ptr will be set after ->create_virtdev()
2783 * has been called successfully in the next level up in the
2784 * configfs tree for device object's struct config_group.
2786 se_dev
->se_dev_su_ptr
= t
->allocate_virtdevice(hba
, name
);
2787 if (!se_dev
->se_dev_su_ptr
) {
2788 pr_err("Unable to locate subsystem dependent pointer"
2789 " from allocate_virtdevice()\n");
2792 spin_lock(&se_device_lock
);
2793 list_add_tail(&se_dev
->se_dev_node
, &se_dev_list
);
2794 spin_unlock(&se_device_lock
);
2796 config_group_init_type_name(&se_dev
->se_dev_group
, name
,
2797 &target_core_dev_cit
);
2798 config_group_init_type_name(&se_dev
->se_dev_attrib
.da_group
, "attrib",
2799 &target_core_dev_attrib_cit
);
2800 config_group_init_type_name(&se_dev
->se_dev_pr_group
, "pr",
2801 &target_core_dev_pr_cit
);
2802 config_group_init_type_name(&se_dev
->t10_wwn
.t10_wwn_group
, "wwn",
2803 &target_core_dev_wwn_cit
);
2804 config_group_init_type_name(&se_dev
->t10_alua
.alua_tg_pt_gps_group
,
2805 "alua", &target_core_alua_tg_pt_gps_cit
);
2806 config_group_init_type_name(&se_dev
->dev_stat_grps
.stat_group
,
2807 "statistics", &target_core_stat_cit
);
2809 dev_cg
->default_groups
[0] = &se_dev
->se_dev_attrib
.da_group
;
2810 dev_cg
->default_groups
[1] = &se_dev
->se_dev_pr_group
;
2811 dev_cg
->default_groups
[2] = &se_dev
->t10_wwn
.t10_wwn_group
;
2812 dev_cg
->default_groups
[3] = &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2813 dev_cg
->default_groups
[4] = &se_dev
->dev_stat_grps
.stat_group
;
2814 dev_cg
->default_groups
[5] = NULL
;
2816 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
2818 tg_pt_gp
= core_alua_allocate_tg_pt_gp(se_dev
, "default_tg_pt_gp", 1);
2822 tg_pt_gp_cg
= &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2823 tg_pt_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
2825 if (!tg_pt_gp_cg
->default_groups
) {
2826 pr_err("Unable to allocate tg_pt_gp_cg->"
2827 "default_groups\n");
2831 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2832 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2833 tg_pt_gp_cg
->default_groups
[0] = &tg_pt_gp
->tg_pt_gp_group
;
2834 tg_pt_gp_cg
->default_groups
[1] = NULL
;
2835 se_dev
->t10_alua
.default_tg_pt_gp
= tg_pt_gp
;
2837 * Add core/$HBA/$DEV/statistics/ default groups
2839 dev_stat_grp
= &se_dev
->dev_stat_grps
.stat_group
;
2840 dev_stat_grp
->default_groups
= kzalloc(sizeof(struct config_group
) * 4,
2842 if (!dev_stat_grp
->default_groups
) {
2843 pr_err("Unable to allocate dev_stat_grp->default_groups\n");
2846 target_stat_setup_dev_default_groups(se_dev
);
2848 pr_debug("Target_Core_ConfigFS: Allocated struct se_subsystem_dev:"
2849 " %p se_dev_su_ptr: %p\n", se_dev
, se_dev
->se_dev_su_ptr
);
2851 mutex_unlock(&hba
->hba_access_mutex
);
2852 return &se_dev
->se_dev_group
;
2854 if (se_dev
->t10_alua
.default_tg_pt_gp
) {
2855 core_alua_free_tg_pt_gp(se_dev
->t10_alua
.default_tg_pt_gp
);
2856 se_dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2859 kfree(dev_stat_grp
->default_groups
);
2861 kfree(tg_pt_gp_cg
->default_groups
);
2863 kfree(dev_cg
->default_groups
);
2864 if (se_dev
->se_dev_su_ptr
)
2865 t
->free_device(se_dev
->se_dev_su_ptr
);
2868 mutex_unlock(&hba
->hba_access_mutex
);
2869 return ERR_PTR(errno
);
2872 static void target_core_drop_subdev(
2873 struct config_group
*group
,
2874 struct config_item
*item
)
2876 struct se_subsystem_dev
*se_dev
= container_of(to_config_group(item
),
2877 struct se_subsystem_dev
, se_dev_group
);
2879 struct se_subsystem_api
*t
;
2880 struct config_item
*df_item
;
2881 struct config_group
*dev_cg
, *tg_pt_gp_cg
, *dev_stat_grp
;
2884 hba
= item_to_hba(&se_dev
->se_dev_hba
->hba_group
.cg_item
);
2886 mutex_lock(&hba
->hba_access_mutex
);
2889 spin_lock(&se_device_lock
);
2890 list_del(&se_dev
->se_dev_node
);
2891 spin_unlock(&se_device_lock
);
2893 dev_stat_grp
= &se_dev
->dev_stat_grps
.stat_group
;
2894 for (i
= 0; dev_stat_grp
->default_groups
[i
]; i
++) {
2895 df_item
= &dev_stat_grp
->default_groups
[i
]->cg_item
;
2896 dev_stat_grp
->default_groups
[i
] = NULL
;
2897 config_item_put(df_item
);
2899 kfree(dev_stat_grp
->default_groups
);
2901 tg_pt_gp_cg
= &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2902 for (i
= 0; tg_pt_gp_cg
->default_groups
[i
]; i
++) {
2903 df_item
= &tg_pt_gp_cg
->default_groups
[i
]->cg_item
;
2904 tg_pt_gp_cg
->default_groups
[i
] = NULL
;
2905 config_item_put(df_item
);
2907 kfree(tg_pt_gp_cg
->default_groups
);
2909 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2910 * directly from target_core_alua_tg_pt_gp_release().
2912 se_dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2914 dev_cg
= &se_dev
->se_dev_group
;
2915 for (i
= 0; dev_cg
->default_groups
[i
]; i
++) {
2916 df_item
= &dev_cg
->default_groups
[i
]->cg_item
;
2917 dev_cg
->default_groups
[i
] = NULL
;
2918 config_item_put(df_item
);
2921 * The releasing of se_dev and associated se_dev->se_dev_ptr is done
2922 * from target_core_dev_item_ops->release() ->target_core_dev_release().
2924 config_item_put(item
);
2925 mutex_unlock(&hba
->hba_access_mutex
);
2928 static struct configfs_group_operations target_core_hba_group_ops
= {
2929 .make_group
= target_core_make_subdev
,
2930 .drop_item
= target_core_drop_subdev
,
2933 CONFIGFS_EATTR_STRUCT(target_core_hba
, se_hba
);
2934 #define SE_HBA_ATTR(_name, _mode) \
2935 static struct target_core_hba_attribute \
2936 target_core_hba_##_name = \
2937 __CONFIGFS_EATTR(_name, _mode, \
2938 target_core_hba_show_attr_##_name, \
2939 target_core_hba_store_attr_##_name);
2941 #define SE_HBA_ATTR_RO(_name) \
2942 static struct target_core_hba_attribute \
2943 target_core_hba_##_name = \
2944 __CONFIGFS_EATTR_RO(_name, \
2945 target_core_hba_show_attr_##_name);
2947 static ssize_t
target_core_hba_show_attr_hba_info(
2951 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
2952 hba
->hba_id
, hba
->transport
->name
,
2953 TARGET_CORE_CONFIGFS_VERSION
);
2956 SE_HBA_ATTR_RO(hba_info
);
2958 static ssize_t
target_core_hba_show_attr_hba_mode(struct se_hba
*hba
,
2963 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
2966 return sprintf(page
, "%d\n", hba_mode
);
2969 static ssize_t
target_core_hba_store_attr_hba_mode(struct se_hba
*hba
,
2970 const char *page
, size_t count
)
2972 struct se_subsystem_api
*transport
= hba
->transport
;
2973 unsigned long mode_flag
;
2976 if (transport
->pmode_enable_hba
== NULL
)
2979 ret
= strict_strtoul(page
, 0, &mode_flag
);
2981 pr_err("Unable to extract hba mode flag: %d\n", ret
);
2985 spin_lock(&hba
->device_lock
);
2986 if (!list_empty(&hba
->hba_dev_list
)) {
2987 pr_err("Unable to set hba_mode with active devices\n");
2988 spin_unlock(&hba
->device_lock
);
2991 spin_unlock(&hba
->device_lock
);
2993 ret
= transport
->pmode_enable_hba(hba
, mode_flag
);
2997 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
2999 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
3004 SE_HBA_ATTR(hba_mode
, S_IRUGO
| S_IWUSR
);
3006 CONFIGFS_EATTR_OPS(target_core_hba
, se_hba
, hba_group
);
3008 static void target_core_hba_release(struct config_item
*item
)
3010 struct se_hba
*hba
= container_of(to_config_group(item
),
3011 struct se_hba
, hba_group
);
3012 core_delete_hba(hba
);
3015 static struct configfs_attribute
*target_core_hba_attrs
[] = {
3016 &target_core_hba_hba_info
.attr
,
3017 &target_core_hba_hba_mode
.attr
,
3021 static struct configfs_item_operations target_core_hba_item_ops
= {
3022 .release
= target_core_hba_release
,
3023 .show_attribute
= target_core_hba_attr_show
,
3024 .store_attribute
= target_core_hba_attr_store
,
3027 static struct config_item_type target_core_hba_cit
= {
3028 .ct_item_ops
= &target_core_hba_item_ops
,
3029 .ct_group_ops
= &target_core_hba_group_ops
,
3030 .ct_attrs
= target_core_hba_attrs
,
3031 .ct_owner
= THIS_MODULE
,
3034 static struct config_group
*target_core_call_addhbatotarget(
3035 struct config_group
*group
,
3038 char *se_plugin_str
, *str
, *str2
;
3040 char buf
[TARGET_CORE_NAME_MAX_LEN
];
3041 unsigned long plugin_dep_id
= 0;
3044 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
3045 if (strlen(name
) >= TARGET_CORE_NAME_MAX_LEN
) {
3046 pr_err("Passed *name strlen(): %d exceeds"
3047 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
3048 TARGET_CORE_NAME_MAX_LEN
);
3049 return ERR_PTR(-ENAMETOOLONG
);
3051 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
3053 str
= strstr(buf
, "_");
3055 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
3056 return ERR_PTR(-EINVAL
);
3058 se_plugin_str
= buf
;
3060 * Special case for subsystem plugins that have "_" in their names.
3061 * Namely rd_direct and rd_mcp..
3063 str2
= strstr(str
+1, "_");
3065 *str2
= '\0'; /* Terminate for *se_plugin_str */
3066 str2
++; /* Skip to start of plugin dependent ID */
3069 *str
= '\0'; /* Terminate for *se_plugin_str */
3070 str
++; /* Skip to start of plugin dependent ID */
3073 ret
= strict_strtoul(str
, 0, &plugin_dep_id
);
3075 pr_err("strict_strtoul() returned %d for"
3076 " plugin_dep_id\n", ret
);
3077 return ERR_PTR(-EINVAL
);
3080 * Load up TCM subsystem plugins if they have not already been loaded.
3082 if (transport_subsystem_check_init() < 0)
3083 return ERR_PTR(-EINVAL
);
3085 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
3087 return ERR_CAST(hba
);
3089 config_group_init_type_name(&hba
->hba_group
, name
,
3090 &target_core_hba_cit
);
3092 return &hba
->hba_group
;
3095 static void target_core_call_delhbafromtarget(
3096 struct config_group
*group
,
3097 struct config_item
*item
)
3100 * core_delete_hba() is called from target_core_hba_item_ops->release()
3101 * -> target_core_hba_release()
3103 config_item_put(item
);
3106 static struct configfs_group_operations target_core_group_ops
= {
3107 .make_group
= target_core_call_addhbatotarget
,
3108 .drop_item
= target_core_call_delhbafromtarget
,
3111 static struct config_item_type target_core_cit
= {
3112 .ct_item_ops
= NULL
,
3113 .ct_group_ops
= &target_core_group_ops
,
3115 .ct_owner
= THIS_MODULE
,
3118 /* Stop functions for struct config_item_type target_core_hba_cit */
3120 static int __init
target_core_init_configfs(void)
3122 struct config_group
*target_cg
, *hba_cg
= NULL
, *alua_cg
= NULL
;
3123 struct config_group
*lu_gp_cg
= NULL
;
3124 struct configfs_subsystem
*subsys
;
3125 struct t10_alua_lu_gp
*lu_gp
;
3128 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
3129 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
3130 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
3132 subsys
= target_core_subsystem
[0];
3133 config_group_init(&subsys
->su_group
);
3134 mutex_init(&subsys
->su_mutex
);
3136 INIT_LIST_HEAD(&g_tf_list
);
3137 mutex_init(&g_tf_lock
);
3138 ret
= init_se_kmem_caches();
3142 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
3143 * and ALUA Logical Unit Group and Target Port Group infrastructure.
3145 target_cg
= &subsys
->su_group
;
3146 target_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3148 if (!target_cg
->default_groups
) {
3149 pr_err("Unable to allocate target_cg->default_groups\n");
3153 config_group_init_type_name(&target_core_hbagroup
,
3154 "core", &target_core_cit
);
3155 target_cg
->default_groups
[0] = &target_core_hbagroup
;
3156 target_cg
->default_groups
[1] = NULL
;
3158 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
3160 hba_cg
= &target_core_hbagroup
;
3161 hba_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3163 if (!hba_cg
->default_groups
) {
3164 pr_err("Unable to allocate hba_cg->default_groups\n");
3167 config_group_init_type_name(&alua_group
,
3168 "alua", &target_core_alua_cit
);
3169 hba_cg
->default_groups
[0] = &alua_group
;
3170 hba_cg
->default_groups
[1] = NULL
;
3172 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
3173 * groups under /sys/kernel/config/target/core/alua/
3175 alua_cg
= &alua_group
;
3176 alua_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3178 if (!alua_cg
->default_groups
) {
3179 pr_err("Unable to allocate alua_cg->default_groups\n");
3183 config_group_init_type_name(&alua_lu_gps_group
,
3184 "lu_gps", &target_core_alua_lu_gps_cit
);
3185 alua_cg
->default_groups
[0] = &alua_lu_gps_group
;
3186 alua_cg
->default_groups
[1] = NULL
;
3188 * Add core/alua/lu_gps/default_lu_gp
3190 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
3194 lu_gp_cg
= &alua_lu_gps_group
;
3195 lu_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3197 if (!lu_gp_cg
->default_groups
) {
3198 pr_err("Unable to allocate lu_gp_cg->default_groups\n");
3202 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
3203 &target_core_alua_lu_gp_cit
);
3204 lu_gp_cg
->default_groups
[0] = &lu_gp
->lu_gp_group
;
3205 lu_gp_cg
->default_groups
[1] = NULL
;
3206 default_lu_gp
= lu_gp
;
3208 * Register the target_core_mod subsystem with configfs.
3210 ret
= configfs_register_subsystem(subsys
);
3212 pr_err("Error %d while registering subsystem %s\n",
3213 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
3216 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
3217 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION
" on %s/%s"
3218 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
3220 * Register built-in RAMDISK subsystem logic for virtual LUN 0
3222 ret
= rd_module_init();
3226 if (core_dev_setup_virtual_lun0() < 0)
3232 configfs_unregister_subsystem(subsys
);
3233 core_dev_release_virtual_lun0();
3236 if (default_lu_gp
) {
3237 core_alua_free_lu_gp(default_lu_gp
);
3238 default_lu_gp
= NULL
;
3241 kfree(lu_gp_cg
->default_groups
);
3243 kfree(alua_cg
->default_groups
);
3245 kfree(hba_cg
->default_groups
);
3246 kfree(target_cg
->default_groups
);
3247 release_se_kmem_caches();
3251 static void __exit
target_core_exit_configfs(void)
3253 struct configfs_subsystem
*subsys
;
3254 struct config_group
*hba_cg
, *alua_cg
, *lu_gp_cg
;
3255 struct config_item
*item
;
3258 subsys
= target_core_subsystem
[0];
3260 lu_gp_cg
= &alua_lu_gps_group
;
3261 for (i
= 0; lu_gp_cg
->default_groups
[i
]; i
++) {
3262 item
= &lu_gp_cg
->default_groups
[i
]->cg_item
;
3263 lu_gp_cg
->default_groups
[i
] = NULL
;
3264 config_item_put(item
);
3266 kfree(lu_gp_cg
->default_groups
);
3267 lu_gp_cg
->default_groups
= NULL
;
3269 alua_cg
= &alua_group
;
3270 for (i
= 0; alua_cg
->default_groups
[i
]; i
++) {
3271 item
= &alua_cg
->default_groups
[i
]->cg_item
;
3272 alua_cg
->default_groups
[i
] = NULL
;
3273 config_item_put(item
);
3275 kfree(alua_cg
->default_groups
);
3276 alua_cg
->default_groups
= NULL
;
3278 hba_cg
= &target_core_hbagroup
;
3279 for (i
= 0; hba_cg
->default_groups
[i
]; i
++) {
3280 item
= &hba_cg
->default_groups
[i
]->cg_item
;
3281 hba_cg
->default_groups
[i
] = NULL
;
3282 config_item_put(item
);
3284 kfree(hba_cg
->default_groups
);
3285 hba_cg
->default_groups
= NULL
;
3287 * We expect subsys->su_group.default_groups to be released
3288 * by configfs subsystem provider logic..
3290 configfs_unregister_subsystem(subsys
);
3291 kfree(subsys
->su_group
.default_groups
);
3293 core_alua_free_lu_gp(default_lu_gp
);
3294 default_lu_gp
= NULL
;
3296 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
3297 " Infrastructure\n");
3299 core_dev_release_virtual_lun0();
3301 release_se_kmem_caches();
3304 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3305 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3306 MODULE_LICENSE("GPL");
3308 module_init(target_core_init_configfs
);
3309 module_exit(target_core_exit_configfs
);