1 /*******************************************************************************
2 * Filename: target_core_configfs.c
4 * This file contains ConfigFS logic for the Generic Target Engine project.
6 * Copyright (c) 2008-2011 Rising Tide Systems
7 * Copyright (c) 2008-2011 Linux-iSCSI.org
9 * Nicholas A. Bellinger <nab@kernel.org>
11 * based on configfs Copyright (C) 2005 Oracle. All rights reserved.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 ****************************************************************************/
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <generated/utsrelease.h>
27 #include <linux/utsname.h>
28 #include <linux/init.h>
30 #include <linux/namei.h>
31 #include <linux/slab.h>
32 #include <linux/types.h>
33 #include <linux/delay.h>
34 #include <linux/unistd.h>
35 #include <linux/string.h>
36 #include <linux/parser.h>
37 #include <linux/syscalls.h>
38 #include <linux/configfs.h>
39 #include <linux/spinlock.h>
41 #include <target/target_core_base.h>
42 #include <target/target_core_backend.h>
43 #include <target/target_core_fabric.h>
44 #include <target/target_core_fabric_configfs.h>
45 #include <target/target_core_configfs.h>
46 #include <target/configfs_macros.h>
48 #include "target_core_internal.h"
49 #include "target_core_alua.h"
50 #include "target_core_pr.h"
51 #include "target_core_rd.h"
53 extern struct t10_alua_lu_gp
*default_lu_gp
;
55 static LIST_HEAD(g_tf_list
);
56 static DEFINE_MUTEX(g_tf_lock
);
58 struct target_core_configfs_attribute
{
59 struct configfs_attribute attr
;
60 ssize_t (*show
)(void *, char *);
61 ssize_t (*store
)(void *, const char *, size_t);
64 static struct config_group target_core_hbagroup
;
65 static struct config_group alua_group
;
66 static struct config_group alua_lu_gps_group
;
68 static inline struct se_hba
*
69 item_to_hba(struct config_item
*item
)
71 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
75 * Attributes for /sys/kernel/config/target/
77 static ssize_t
target_core_attr_show(struct config_item
*item
,
78 struct configfs_attribute
*attr
,
81 return sprintf(page
, "Target Engine Core ConfigFS Infrastructure %s"
82 " on %s/%s on "UTS_RELEASE
"\n", TARGET_CORE_CONFIGFS_VERSION
,
83 utsname()->sysname
, utsname()->machine
);
86 static struct configfs_item_operations target_core_fabric_item_ops
= {
87 .show_attribute
= target_core_attr_show
,
90 static struct configfs_attribute target_core_item_attr_version
= {
91 .ca_owner
= THIS_MODULE
,
96 static struct target_fabric_configfs
*target_core_get_fabric(
99 struct target_fabric_configfs
*tf
;
104 mutex_lock(&g_tf_lock
);
105 list_for_each_entry(tf
, &g_tf_list
, tf_list
) {
106 if (!strcmp(tf
->tf_name
, name
)) {
107 atomic_inc(&tf
->tf_access_cnt
);
108 mutex_unlock(&g_tf_lock
);
112 mutex_unlock(&g_tf_lock
);
118 * Called from struct target_core_group_ops->make_group()
120 static struct config_group
*target_core_register_fabric(
121 struct config_group
*group
,
124 struct target_fabric_configfs
*tf
;
127 pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:"
128 " %s\n", group
, name
);
130 * Below are some hardcoded request_module() calls to automatically
131 * local fabric modules when the following is called:
133 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
135 * Note that this does not limit which TCM fabric module can be
136 * registered, but simply provids auto loading logic for modules with
137 * mkdir(2) system calls with known TCM fabric modules.
139 if (!strncmp(name
, "iscsi", 5)) {
141 * Automatically load the LIO Target fabric module when the
142 * following is called:
144 * mkdir -p $CONFIGFS/target/iscsi
146 ret
= request_module("iscsi_target_mod");
148 pr_err("request_module() failed for"
149 " iscsi_target_mod.ko: %d\n", ret
);
150 return ERR_PTR(-EINVAL
);
152 } else if (!strncmp(name
, "loopback", 8)) {
154 * Automatically load the tcm_loop fabric module when the
155 * following is called:
157 * mkdir -p $CONFIGFS/target/loopback
159 ret
= request_module("tcm_loop");
161 pr_err("request_module() failed for"
162 " tcm_loop.ko: %d\n", ret
);
163 return ERR_PTR(-EINVAL
);
167 tf
= target_core_get_fabric(name
);
169 pr_err("target_core_get_fabric() failed for %s\n",
171 return ERR_PTR(-EINVAL
);
173 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
174 " %s\n", tf
->tf_name
);
176 * On a successful target_core_get_fabric() look, the returned
177 * struct target_fabric_configfs *tf will contain a usage reference.
179 pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
180 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
182 tf
->tf_group
.default_groups
= tf
->tf_default_groups
;
183 tf
->tf_group
.default_groups
[0] = &tf
->tf_disc_group
;
184 tf
->tf_group
.default_groups
[1] = NULL
;
186 config_group_init_type_name(&tf
->tf_group
, name
,
187 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
188 config_group_init_type_name(&tf
->tf_disc_group
, "discovery_auth",
189 &TF_CIT_TMPL(tf
)->tfc_discovery_cit
);
191 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
192 " %s\n", tf
->tf_group
.cg_item
.ci_name
);
194 * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item()
196 tf
->tf_ops
.tf_subsys
= tf
->tf_subsys
;
197 tf
->tf_fabric
= &tf
->tf_group
.cg_item
;
198 pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
201 return &tf
->tf_group
;
205 * Called from struct target_core_group_ops->drop_item()
207 static void target_core_deregister_fabric(
208 struct config_group
*group
,
209 struct config_item
*item
)
211 struct target_fabric_configfs
*tf
= container_of(
212 to_config_group(item
), struct target_fabric_configfs
, tf_group
);
213 struct config_group
*tf_group
;
214 struct config_item
*df_item
;
217 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
218 " tf list\n", config_item_name(item
));
220 pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:"
221 " %s\n", tf
->tf_name
);
222 atomic_dec(&tf
->tf_access_cnt
);
224 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing"
225 " tf->tf_fabric for %s\n", tf
->tf_name
);
226 tf
->tf_fabric
= NULL
;
228 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
229 " %s\n", config_item_name(item
));
231 tf_group
= &tf
->tf_group
;
232 for (i
= 0; tf_group
->default_groups
[i
]; i
++) {
233 df_item
= &tf_group
->default_groups
[i
]->cg_item
;
234 tf_group
->default_groups
[i
] = NULL
;
235 config_item_put(df_item
);
237 config_item_put(item
);
240 static struct configfs_group_operations target_core_fabric_group_ops
= {
241 .make_group
= &target_core_register_fabric
,
242 .drop_item
= &target_core_deregister_fabric
,
246 * All item attributes appearing in /sys/kernel/target/ appear here.
248 static struct configfs_attribute
*target_core_fabric_item_attrs
[] = {
249 &target_core_item_attr_version
,
254 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
256 static struct config_item_type target_core_fabrics_item
= {
257 .ct_item_ops
= &target_core_fabric_item_ops
,
258 .ct_group_ops
= &target_core_fabric_group_ops
,
259 .ct_attrs
= target_core_fabric_item_attrs
,
260 .ct_owner
= THIS_MODULE
,
263 static struct configfs_subsystem target_core_fabrics
= {
266 .ci_namebuf
= "target",
267 .ci_type
= &target_core_fabrics_item
,
272 static struct configfs_subsystem
*target_core_subsystem
[] = {
273 &target_core_fabrics
,
277 /*##############################################################################
278 // Start functions called by external Target Fabrics Modules
279 //############################################################################*/
282 * First function called by fabric modules to:
284 * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer.
285 * 2) Add struct target_fabric_configfs to g_tf_list
286 * 3) Return struct target_fabric_configfs to fabric module to be passed
287 * into target_fabric_configfs_register().
289 struct target_fabric_configfs
*target_fabric_configfs_init(
290 struct module
*fabric_mod
,
293 struct target_fabric_configfs
*tf
;
296 pr_err("Unable to locate passed fabric name\n");
297 return ERR_PTR(-EINVAL
);
299 if (strlen(name
) >= TARGET_FABRIC_NAME_SIZE
) {
300 pr_err("Passed name: %s exceeds TARGET_FABRIC"
301 "_NAME_SIZE\n", name
);
302 return ERR_PTR(-EINVAL
);
305 tf
= kzalloc(sizeof(struct target_fabric_configfs
), GFP_KERNEL
);
307 return ERR_PTR(-ENOMEM
);
309 INIT_LIST_HEAD(&tf
->tf_list
);
310 atomic_set(&tf
->tf_access_cnt
, 0);
312 * Setup the default generic struct config_item_type's (cits) in
313 * struct target_fabric_configfs->tf_cit_tmpl
315 tf
->tf_module
= fabric_mod
;
316 target_fabric_setup_cits(tf
);
318 tf
->tf_subsys
= target_core_subsystem
[0];
319 snprintf(tf
->tf_name
, TARGET_FABRIC_NAME_SIZE
, "%s", name
);
321 mutex_lock(&g_tf_lock
);
322 list_add_tail(&tf
->tf_list
, &g_tf_list
);
323 mutex_unlock(&g_tf_lock
);
325 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>"
327 pr_debug("Initialized struct target_fabric_configfs: %p for"
328 " %s\n", tf
, tf
->tf_name
);
331 EXPORT_SYMBOL(target_fabric_configfs_init
);
334 * Called by fabric plugins after FAILED target_fabric_configfs_register() call.
336 void target_fabric_configfs_free(
337 struct target_fabric_configfs
*tf
)
339 mutex_lock(&g_tf_lock
);
340 list_del(&tf
->tf_list
);
341 mutex_unlock(&g_tf_lock
);
345 EXPORT_SYMBOL(target_fabric_configfs_free
);
348 * Perform a sanity check of the passed tf->tf_ops before completing
349 * TCM fabric module registration.
351 static int target_fabric_tf_ops_check(
352 struct target_fabric_configfs
*tf
)
354 struct target_core_fabric_ops
*tfo
= &tf
->tf_ops
;
356 if (!tfo
->get_fabric_name
) {
357 pr_err("Missing tfo->get_fabric_name()\n");
360 if (!tfo
->get_fabric_proto_ident
) {
361 pr_err("Missing tfo->get_fabric_proto_ident()\n");
364 if (!tfo
->tpg_get_wwn
) {
365 pr_err("Missing tfo->tpg_get_wwn()\n");
368 if (!tfo
->tpg_get_tag
) {
369 pr_err("Missing tfo->tpg_get_tag()\n");
372 if (!tfo
->tpg_get_default_depth
) {
373 pr_err("Missing tfo->tpg_get_default_depth()\n");
376 if (!tfo
->tpg_get_pr_transport_id
) {
377 pr_err("Missing tfo->tpg_get_pr_transport_id()\n");
380 if (!tfo
->tpg_get_pr_transport_id_len
) {
381 pr_err("Missing tfo->tpg_get_pr_transport_id_len()\n");
384 if (!tfo
->tpg_check_demo_mode
) {
385 pr_err("Missing tfo->tpg_check_demo_mode()\n");
388 if (!tfo
->tpg_check_demo_mode_cache
) {
389 pr_err("Missing tfo->tpg_check_demo_mode_cache()\n");
392 if (!tfo
->tpg_check_demo_mode_write_protect
) {
393 pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n");
396 if (!tfo
->tpg_check_prod_mode_write_protect
) {
397 pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n");
400 if (!tfo
->tpg_alloc_fabric_acl
) {
401 pr_err("Missing tfo->tpg_alloc_fabric_acl()\n");
404 if (!tfo
->tpg_release_fabric_acl
) {
405 pr_err("Missing tfo->tpg_release_fabric_acl()\n");
408 if (!tfo
->tpg_get_inst_index
) {
409 pr_err("Missing tfo->tpg_get_inst_index()\n");
412 if (!tfo
->release_cmd
) {
413 pr_err("Missing tfo->release_cmd()\n");
416 if (!tfo
->shutdown_session
) {
417 pr_err("Missing tfo->shutdown_session()\n");
420 if (!tfo
->close_session
) {
421 pr_err("Missing tfo->close_session()\n");
424 if (!tfo
->sess_get_index
) {
425 pr_err("Missing tfo->sess_get_index()\n");
428 if (!tfo
->write_pending
) {
429 pr_err("Missing tfo->write_pending()\n");
432 if (!tfo
->write_pending_status
) {
433 pr_err("Missing tfo->write_pending_status()\n");
436 if (!tfo
->set_default_node_attributes
) {
437 pr_err("Missing tfo->set_default_node_attributes()\n");
440 if (!tfo
->get_task_tag
) {
441 pr_err("Missing tfo->get_task_tag()\n");
444 if (!tfo
->get_cmd_state
) {
445 pr_err("Missing tfo->get_cmd_state()\n");
448 if (!tfo
->queue_data_in
) {
449 pr_err("Missing tfo->queue_data_in()\n");
452 if (!tfo
->queue_status
) {
453 pr_err("Missing tfo->queue_status()\n");
456 if (!tfo
->queue_tm_rsp
) {
457 pr_err("Missing tfo->queue_tm_rsp()\n");
460 if (!tfo
->set_fabric_sense_len
) {
461 pr_err("Missing tfo->set_fabric_sense_len()\n");
464 if (!tfo
->get_fabric_sense_len
) {
465 pr_err("Missing tfo->get_fabric_sense_len()\n");
469 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
470 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
471 * target_core_fabric_configfs.c WWN+TPG group context code.
473 if (!tfo
->fabric_make_wwn
) {
474 pr_err("Missing tfo->fabric_make_wwn()\n");
477 if (!tfo
->fabric_drop_wwn
) {
478 pr_err("Missing tfo->fabric_drop_wwn()\n");
481 if (!tfo
->fabric_make_tpg
) {
482 pr_err("Missing tfo->fabric_make_tpg()\n");
485 if (!tfo
->fabric_drop_tpg
) {
486 pr_err("Missing tfo->fabric_drop_tpg()\n");
494 * Called 2nd from fabric module with returned parameter of
495 * struct target_fabric_configfs * from target_fabric_configfs_init().
497 * Upon a successful registration, the new fabric's struct config_item is
498 * return. Also, a pointer to this struct is set in the passed
499 * struct target_fabric_configfs.
501 int target_fabric_configfs_register(
502 struct target_fabric_configfs
*tf
)
507 pr_err("Unable to locate target_fabric_configfs"
511 if (!tf
->tf_subsys
) {
512 pr_err("Unable to target struct config_subsystem"
516 ret
= target_fabric_tf_ops_check(tf
);
520 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>"
524 EXPORT_SYMBOL(target_fabric_configfs_register
);
526 void target_fabric_configfs_deregister(
527 struct target_fabric_configfs
*tf
)
529 struct configfs_subsystem
*su
;
532 pr_err("Unable to locate passed target_fabric_"
538 pr_err("Unable to locate passed tf->tf_subsys"
542 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
544 mutex_lock(&g_tf_lock
);
545 if (atomic_read(&tf
->tf_access_cnt
)) {
546 mutex_unlock(&g_tf_lock
);
547 pr_err("Non zero tf->tf_access_cnt for fabric %s\n",
551 list_del(&tf
->tf_list
);
552 mutex_unlock(&g_tf_lock
);
554 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
555 " %s\n", tf
->tf_name
);
556 tf
->tf_module
= NULL
;
557 tf
->tf_subsys
= NULL
;
560 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
563 EXPORT_SYMBOL(target_fabric_configfs_deregister
);
565 /*##############################################################################
566 // Stop functions called by external Target Fabrics Modules
567 //############################################################################*/
569 /* Start functions for struct config_item_type target_core_dev_attrib_cit */
571 #define DEF_DEV_ATTRIB_SHOW(_name) \
572 static ssize_t target_core_dev_show_attr_##_name( \
573 struct se_dev_attrib *da, \
576 struct se_device *dev; \
577 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
580 spin_lock(&se_dev->se_dev_lock); \
581 dev = se_dev->se_dev_ptr; \
583 spin_unlock(&se_dev->se_dev_lock); \
586 rb = snprintf(page, PAGE_SIZE, "%u\n", \
587 (u32)dev->se_sub_dev->se_dev_attrib._name); \
588 spin_unlock(&se_dev->se_dev_lock); \
593 #define DEF_DEV_ATTRIB_STORE(_name) \
594 static ssize_t target_core_dev_store_attr_##_name( \
595 struct se_dev_attrib *da, \
599 struct se_device *dev; \
600 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
604 spin_lock(&se_dev->se_dev_lock); \
605 dev = se_dev->se_dev_ptr; \
607 spin_unlock(&se_dev->se_dev_lock); \
610 ret = strict_strtoul(page, 0, &val); \
612 spin_unlock(&se_dev->se_dev_lock); \
613 pr_err("strict_strtoul() failed with" \
614 " ret: %d\n", ret); \
617 ret = se_dev_set_##_name(dev, (u32)val); \
618 spin_unlock(&se_dev->se_dev_lock); \
620 return (!ret) ? count : -EINVAL; \
623 #define DEF_DEV_ATTRIB(_name) \
624 DEF_DEV_ATTRIB_SHOW(_name); \
625 DEF_DEV_ATTRIB_STORE(_name);
627 #define DEF_DEV_ATTRIB_RO(_name) \
628 DEF_DEV_ATTRIB_SHOW(_name);
630 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib
, se_dev_attrib
);
631 #define SE_DEV_ATTR(_name, _mode) \
632 static struct target_core_dev_attrib_attribute \
633 target_core_dev_attrib_##_name = \
634 __CONFIGFS_EATTR(_name, _mode, \
635 target_core_dev_show_attr_##_name, \
636 target_core_dev_store_attr_##_name);
638 #define SE_DEV_ATTR_RO(_name); \
639 static struct target_core_dev_attrib_attribute \
640 target_core_dev_attrib_##_name = \
641 __CONFIGFS_EATTR_RO(_name, \
642 target_core_dev_show_attr_##_name);
644 DEF_DEV_ATTRIB(emulate_dpo
);
645 SE_DEV_ATTR(emulate_dpo
, S_IRUGO
| S_IWUSR
);
647 DEF_DEV_ATTRIB(emulate_fua_write
);
648 SE_DEV_ATTR(emulate_fua_write
, S_IRUGO
| S_IWUSR
);
650 DEF_DEV_ATTRIB(emulate_fua_read
);
651 SE_DEV_ATTR(emulate_fua_read
, S_IRUGO
| S_IWUSR
);
653 DEF_DEV_ATTRIB(emulate_write_cache
);
654 SE_DEV_ATTR(emulate_write_cache
, S_IRUGO
| S_IWUSR
);
656 DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl
);
657 SE_DEV_ATTR(emulate_ua_intlck_ctrl
, S_IRUGO
| S_IWUSR
);
659 DEF_DEV_ATTRIB(emulate_tas
);
660 SE_DEV_ATTR(emulate_tas
, S_IRUGO
| S_IWUSR
);
662 DEF_DEV_ATTRIB(emulate_tpu
);
663 SE_DEV_ATTR(emulate_tpu
, S_IRUGO
| S_IWUSR
);
665 DEF_DEV_ATTRIB(emulate_tpws
);
666 SE_DEV_ATTR(emulate_tpws
, S_IRUGO
| S_IWUSR
);
668 DEF_DEV_ATTRIB(enforce_pr_isids
);
669 SE_DEV_ATTR(enforce_pr_isids
, S_IRUGO
| S_IWUSR
);
671 DEF_DEV_ATTRIB(is_nonrot
);
672 SE_DEV_ATTR(is_nonrot
, S_IRUGO
| S_IWUSR
);
674 DEF_DEV_ATTRIB(emulate_rest_reord
);
675 SE_DEV_ATTR(emulate_rest_reord
, S_IRUGO
| S_IWUSR
);
677 DEF_DEV_ATTRIB_RO(hw_block_size
);
678 SE_DEV_ATTR_RO(hw_block_size
);
680 DEF_DEV_ATTRIB(block_size
);
681 SE_DEV_ATTR(block_size
, S_IRUGO
| S_IWUSR
);
683 DEF_DEV_ATTRIB_RO(hw_max_sectors
);
684 SE_DEV_ATTR_RO(hw_max_sectors
);
686 DEF_DEV_ATTRIB(fabric_max_sectors
);
687 SE_DEV_ATTR(fabric_max_sectors
, S_IRUGO
| S_IWUSR
);
689 DEF_DEV_ATTRIB(optimal_sectors
);
690 SE_DEV_ATTR(optimal_sectors
, S_IRUGO
| S_IWUSR
);
692 DEF_DEV_ATTRIB_RO(hw_queue_depth
);
693 SE_DEV_ATTR_RO(hw_queue_depth
);
695 DEF_DEV_ATTRIB(queue_depth
);
696 SE_DEV_ATTR(queue_depth
, S_IRUGO
| S_IWUSR
);
698 DEF_DEV_ATTRIB(max_unmap_lba_count
);
699 SE_DEV_ATTR(max_unmap_lba_count
, S_IRUGO
| S_IWUSR
);
701 DEF_DEV_ATTRIB(max_unmap_block_desc_count
);
702 SE_DEV_ATTR(max_unmap_block_desc_count
, S_IRUGO
| S_IWUSR
);
704 DEF_DEV_ATTRIB(unmap_granularity
);
705 SE_DEV_ATTR(unmap_granularity
, S_IRUGO
| S_IWUSR
);
707 DEF_DEV_ATTRIB(unmap_granularity_alignment
);
708 SE_DEV_ATTR(unmap_granularity_alignment
, S_IRUGO
| S_IWUSR
);
710 CONFIGFS_EATTR_OPS(target_core_dev_attrib
, se_dev_attrib
, da_group
);
712 static struct configfs_attribute
*target_core_dev_attrib_attrs
[] = {
713 &target_core_dev_attrib_emulate_dpo
.attr
,
714 &target_core_dev_attrib_emulate_fua_write
.attr
,
715 &target_core_dev_attrib_emulate_fua_read
.attr
,
716 &target_core_dev_attrib_emulate_write_cache
.attr
,
717 &target_core_dev_attrib_emulate_ua_intlck_ctrl
.attr
,
718 &target_core_dev_attrib_emulate_tas
.attr
,
719 &target_core_dev_attrib_emulate_tpu
.attr
,
720 &target_core_dev_attrib_emulate_tpws
.attr
,
721 &target_core_dev_attrib_enforce_pr_isids
.attr
,
722 &target_core_dev_attrib_is_nonrot
.attr
,
723 &target_core_dev_attrib_emulate_rest_reord
.attr
,
724 &target_core_dev_attrib_hw_block_size
.attr
,
725 &target_core_dev_attrib_block_size
.attr
,
726 &target_core_dev_attrib_hw_max_sectors
.attr
,
727 &target_core_dev_attrib_fabric_max_sectors
.attr
,
728 &target_core_dev_attrib_optimal_sectors
.attr
,
729 &target_core_dev_attrib_hw_queue_depth
.attr
,
730 &target_core_dev_attrib_queue_depth
.attr
,
731 &target_core_dev_attrib_max_unmap_lba_count
.attr
,
732 &target_core_dev_attrib_max_unmap_block_desc_count
.attr
,
733 &target_core_dev_attrib_unmap_granularity
.attr
,
734 &target_core_dev_attrib_unmap_granularity_alignment
.attr
,
738 static struct configfs_item_operations target_core_dev_attrib_ops
= {
739 .show_attribute
= target_core_dev_attrib_attr_show
,
740 .store_attribute
= target_core_dev_attrib_attr_store
,
743 static struct config_item_type target_core_dev_attrib_cit
= {
744 .ct_item_ops
= &target_core_dev_attrib_ops
,
745 .ct_attrs
= target_core_dev_attrib_attrs
,
746 .ct_owner
= THIS_MODULE
,
749 /* End functions for struct config_item_type target_core_dev_attrib_cit */
751 /* Start functions for struct config_item_type target_core_dev_wwn_cit */
753 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn
, t10_wwn
);
754 #define SE_DEV_WWN_ATTR(_name, _mode) \
755 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
756 __CONFIGFS_EATTR(_name, _mode, \
757 target_core_dev_wwn_show_attr_##_name, \
758 target_core_dev_wwn_store_attr_##_name);
760 #define SE_DEV_WWN_ATTR_RO(_name); \
762 static struct target_core_dev_wwn_attribute \
763 target_core_dev_wwn_##_name = \
764 __CONFIGFS_EATTR_RO(_name, \
765 target_core_dev_wwn_show_attr_##_name); \
769 * VPD page 0x80 Unit serial
771 static ssize_t
target_core_dev_wwn_show_attr_vpd_unit_serial(
772 struct t10_wwn
*t10_wwn
,
775 struct se_subsystem_dev
*se_dev
= t10_wwn
->t10_sub_dev
;
776 struct se_device
*dev
;
778 dev
= se_dev
->se_dev_ptr
;
782 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
783 &t10_wwn
->unit_serial
[0]);
786 static ssize_t
target_core_dev_wwn_store_attr_vpd_unit_serial(
787 struct t10_wwn
*t10_wwn
,
791 struct se_subsystem_dev
*su_dev
= t10_wwn
->t10_sub_dev
;
792 struct se_device
*dev
;
793 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
796 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
797 * from the struct scsi_device level firmware, do not allow
798 * VPD Unit Serial to be emulated.
800 * Note this struct scsi_device could also be emulating VPD
801 * information from its drivers/scsi LLD. But for now we assume
802 * it is doing 'the right thing' wrt a world wide unique
803 * VPD Unit Serial Number that OS dependent multipath can depend on.
805 if (su_dev
->su_dev_flags
& SDF_FIRMWARE_VPD_UNIT_SERIAL
) {
806 pr_err("Underlying SCSI device firmware provided VPD"
807 " Unit Serial, ignoring request\n");
811 if (strlen(page
) >= INQUIRY_VPD_SERIAL_LEN
) {
812 pr_err("Emulated VPD Unit Serial exceeds"
813 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
817 * Check to see if any active $FABRIC_MOD exports exist. If they
818 * do exist, fail here as changing this information on the fly
819 * (underneath the initiator side OS dependent multipath code)
820 * could cause negative effects.
822 dev
= su_dev
->se_dev_ptr
;
824 if (atomic_read(&dev
->dev_export_obj
.obj_access_count
)) {
825 pr_err("Unable to set VPD Unit Serial while"
826 " active %d $FABRIC_MOD exports exist\n",
827 atomic_read(&dev
->dev_export_obj
.obj_access_count
));
832 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
834 * Also, strip any newline added from the userspace
835 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
837 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
838 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
839 snprintf(su_dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
840 "%s", strstrip(buf
));
841 su_dev
->su_dev_flags
|= SDF_EMULATED_VPD_UNIT_SERIAL
;
843 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
844 " %s\n", su_dev
->t10_wwn
.unit_serial
);
849 SE_DEV_WWN_ATTR(vpd_unit_serial
, S_IRUGO
| S_IWUSR
);
852 * VPD page 0x83 Protocol Identifier
854 static ssize_t
target_core_dev_wwn_show_attr_vpd_protocol_identifier(
855 struct t10_wwn
*t10_wwn
,
858 struct se_subsystem_dev
*se_dev
= t10_wwn
->t10_sub_dev
;
859 struct se_device
*dev
;
861 unsigned char buf
[VPD_TMP_BUF_SIZE
];
864 dev
= se_dev
->se_dev_ptr
;
868 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
870 spin_lock(&t10_wwn
->t10_vpd_lock
);
871 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
872 if (!vpd
->protocol_identifier_set
)
875 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
877 if (len
+ strlen(buf
) >= PAGE_SIZE
)
880 len
+= sprintf(page
+len
, "%s", buf
);
882 spin_unlock(&t10_wwn
->t10_vpd_lock
);
887 static ssize_t
target_core_dev_wwn_store_attr_vpd_protocol_identifier(
888 struct t10_wwn
*t10_wwn
,
895 SE_DEV_WWN_ATTR(vpd_protocol_identifier
, S_IRUGO
| S_IWUSR
);
898 * Generic wrapper for dumping VPD identifiers by association.
900 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
901 static ssize_t target_core_dev_wwn_show_attr_##_name( \
902 struct t10_wwn *t10_wwn, \
905 struct se_subsystem_dev *se_dev = t10_wwn->t10_sub_dev; \
906 struct se_device *dev; \
907 struct t10_vpd *vpd; \
908 unsigned char buf[VPD_TMP_BUF_SIZE]; \
911 dev = se_dev->se_dev_ptr; \
915 spin_lock(&t10_wwn->t10_vpd_lock); \
916 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
917 if (vpd->association != _assoc) \
920 memset(buf, 0, VPD_TMP_BUF_SIZE); \
921 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
922 if (len + strlen(buf) >= PAGE_SIZE) \
924 len += sprintf(page+len, "%s", buf); \
926 memset(buf, 0, VPD_TMP_BUF_SIZE); \
927 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
928 if (len + strlen(buf) >= PAGE_SIZE) \
930 len += sprintf(page+len, "%s", buf); \
932 memset(buf, 0, VPD_TMP_BUF_SIZE); \
933 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
934 if (len + strlen(buf) >= PAGE_SIZE) \
936 len += sprintf(page+len, "%s", buf); \
938 spin_unlock(&t10_wwn->t10_vpd_lock); \
944 * VPD page 0x83 Association: Logical Unit
946 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
948 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
949 struct t10_wwn
*t10_wwn
,
956 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit
, S_IRUGO
| S_IWUSR
);
959 * VPD page 0x83 Association: Target Port
961 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
963 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_target_port(
964 struct t10_wwn
*t10_wwn
,
971 SE_DEV_WWN_ATTR(vpd_assoc_target_port
, S_IRUGO
| S_IWUSR
);
974 * VPD page 0x83 Association: SCSI Target Device
976 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
978 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
979 struct t10_wwn
*t10_wwn
,
986 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device
, S_IRUGO
| S_IWUSR
);
988 CONFIGFS_EATTR_OPS(target_core_dev_wwn
, t10_wwn
, t10_wwn_group
);
990 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
991 &target_core_dev_wwn_vpd_unit_serial
.attr
,
992 &target_core_dev_wwn_vpd_protocol_identifier
.attr
,
993 &target_core_dev_wwn_vpd_assoc_logical_unit
.attr
,
994 &target_core_dev_wwn_vpd_assoc_target_port
.attr
,
995 &target_core_dev_wwn_vpd_assoc_scsi_target_device
.attr
,
999 static struct configfs_item_operations target_core_dev_wwn_ops
= {
1000 .show_attribute
= target_core_dev_wwn_attr_show
,
1001 .store_attribute
= target_core_dev_wwn_attr_store
,
1004 static struct config_item_type target_core_dev_wwn_cit
= {
1005 .ct_item_ops
= &target_core_dev_wwn_ops
,
1006 .ct_attrs
= target_core_dev_wwn_attrs
,
1007 .ct_owner
= THIS_MODULE
,
1010 /* End functions for struct config_item_type target_core_dev_wwn_cit */
1012 /* Start functions for struct config_item_type target_core_dev_pr_cit */
1014 CONFIGFS_EATTR_STRUCT(target_core_dev_pr
, se_subsystem_dev
);
1015 #define SE_DEV_PR_ATTR(_name, _mode) \
1016 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1017 __CONFIGFS_EATTR(_name, _mode, \
1018 target_core_dev_pr_show_attr_##_name, \
1019 target_core_dev_pr_store_attr_##_name);
1021 #define SE_DEV_PR_ATTR_RO(_name); \
1022 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1023 __CONFIGFS_EATTR_RO(_name, \
1024 target_core_dev_pr_show_attr_##_name);
1029 static ssize_t
target_core_dev_pr_show_spc3_res(
1030 struct se_device
*dev
,
1034 struct se_node_acl
*se_nacl
;
1035 struct t10_pr_registration
*pr_reg
;
1036 char i_buf
[PR_REG_ISID_ID_LEN
];
1039 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1041 spin_lock(&dev
->dev_reservation_lock
);
1042 pr_reg
= dev
->dev_pr_res_holder
;
1044 *len
+= sprintf(page
+ *len
, "No SPC-3 Reservation holder\n");
1045 spin_unlock(&dev
->dev_reservation_lock
);
1048 se_nacl
= pr_reg
->pr_reg_nacl
;
1049 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1050 PR_REG_ISID_ID_LEN
);
1052 *len
+= sprintf(page
+ *len
, "SPC-3 Reservation: %s Initiator: %s%s\n",
1053 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1054 se_nacl
->initiatorname
, (prf_isid
) ? &i_buf
[0] : "");
1055 spin_unlock(&dev
->dev_reservation_lock
);
1060 static ssize_t
target_core_dev_pr_show_spc2_res(
1061 struct se_device
*dev
,
1065 struct se_node_acl
*se_nacl
;
1067 spin_lock(&dev
->dev_reservation_lock
);
1068 se_nacl
= dev
->dev_reserved_node_acl
;
1070 *len
+= sprintf(page
+ *len
, "No SPC-2 Reservation holder\n");
1071 spin_unlock(&dev
->dev_reservation_lock
);
1074 *len
+= sprintf(page
+ *len
, "SPC-2 Reservation: %s Initiator: %s\n",
1075 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1076 se_nacl
->initiatorname
);
1077 spin_unlock(&dev
->dev_reservation_lock
);
1082 static ssize_t
target_core_dev_pr_show_attr_res_holder(
1083 struct se_subsystem_dev
*su_dev
,
1088 if (!su_dev
->se_dev_ptr
)
1091 switch (su_dev
->t10_pr
.res_type
) {
1092 case SPC3_PERSISTENT_RESERVATIONS
:
1093 target_core_dev_pr_show_spc3_res(su_dev
->se_dev_ptr
,
1096 case SPC2_RESERVATIONS
:
1097 target_core_dev_pr_show_spc2_res(su_dev
->se_dev_ptr
,
1100 case SPC_PASSTHROUGH
:
1101 len
+= sprintf(page
+len
, "Passthrough\n");
1104 len
+= sprintf(page
+len
, "Unknown\n");
1111 SE_DEV_PR_ATTR_RO(res_holder
);
1114 * res_pr_all_tgt_pts
1116 static ssize_t
target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1117 struct se_subsystem_dev
*su_dev
,
1120 struct se_device
*dev
;
1121 struct t10_pr_registration
*pr_reg
;
1124 dev
= su_dev
->se_dev_ptr
;
1128 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1131 spin_lock(&dev
->dev_reservation_lock
);
1132 pr_reg
= dev
->dev_pr_res_holder
;
1134 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1135 spin_unlock(&dev
->dev_reservation_lock
);
1139 * See All Target Ports (ALL_TG_PT) bit in spcr17, section 6.14.3
1140 * Basic PERSISTENT RESERVER OUT parameter list, page 290
1142 if (pr_reg
->pr_reg_all_tg_pt
)
1143 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1144 " Ports registration\n");
1146 len
= sprintf(page
, "SPC-3 Reservation: Single"
1147 " Target Port registration\n");
1148 spin_unlock(&dev
->dev_reservation_lock
);
1153 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts
);
1158 static ssize_t
target_core_dev_pr_show_attr_res_pr_generation(
1159 struct se_subsystem_dev
*su_dev
,
1162 if (!su_dev
->se_dev_ptr
)
1165 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1168 return sprintf(page
, "0x%08x\n", su_dev
->t10_pr
.pr_generation
);
1171 SE_DEV_PR_ATTR_RO(res_pr_generation
);
1174 * res_pr_holder_tg_port
1176 static ssize_t
target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1177 struct se_subsystem_dev
*su_dev
,
1180 struct se_device
*dev
;
1181 struct se_node_acl
*se_nacl
;
1183 struct se_portal_group
*se_tpg
;
1184 struct t10_pr_registration
*pr_reg
;
1185 struct target_core_fabric_ops
*tfo
;
1188 dev
= su_dev
->se_dev_ptr
;
1192 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1195 spin_lock(&dev
->dev_reservation_lock
);
1196 pr_reg
= dev
->dev_pr_res_holder
;
1198 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1199 spin_unlock(&dev
->dev_reservation_lock
);
1202 se_nacl
= pr_reg
->pr_reg_nacl
;
1203 se_tpg
= se_nacl
->se_tpg
;
1204 lun
= pr_reg
->pr_reg_tg_pt_lun
;
1205 tfo
= se_tpg
->se_tpg_tfo
;
1207 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1208 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1209 tfo
->tpg_get_wwn(se_tpg
));
1210 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1211 " Identifer Tag: %hu %s Portal Group Tag: %hu"
1212 " %s Logical Unit: %u\n", lun
->lun_sep
->sep_rtpi
,
1213 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1214 tfo
->get_fabric_name(), lun
->unpacked_lun
);
1215 spin_unlock(&dev
->dev_reservation_lock
);
1220 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port
);
1223 * res_pr_registered_i_pts
1225 static ssize_t
target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1226 struct se_subsystem_dev
*su_dev
,
1229 struct target_core_fabric_ops
*tfo
;
1230 struct t10_pr_registration
*pr_reg
;
1231 unsigned char buf
[384];
1232 char i_buf
[PR_REG_ISID_ID_LEN
];
1234 int reg_count
= 0, prf_isid
;
1236 if (!su_dev
->se_dev_ptr
)
1239 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1242 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1244 spin_lock(&su_dev
->t10_pr
.registration_lock
);
1245 list_for_each_entry(pr_reg
, &su_dev
->t10_pr
.registration_list
,
1248 memset(buf
, 0, 384);
1249 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1250 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1251 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1252 PR_REG_ISID_ID_LEN
);
1253 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1254 tfo
->get_fabric_name(),
1255 pr_reg
->pr_reg_nacl
->initiatorname
, (prf_isid
) ?
1256 &i_buf
[0] : "", pr_reg
->pr_res_key
,
1257 pr_reg
->pr_res_generation
);
1259 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1262 len
+= sprintf(page
+len
, "%s", buf
);
1265 spin_unlock(&su_dev
->t10_pr
.registration_lock
);
1268 len
+= sprintf(page
+len
, "None\n");
1273 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts
);
1278 static ssize_t
target_core_dev_pr_show_attr_res_pr_type(
1279 struct se_subsystem_dev
*su_dev
,
1282 struct se_device
*dev
;
1283 struct t10_pr_registration
*pr_reg
;
1286 dev
= su_dev
->se_dev_ptr
;
1290 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1293 spin_lock(&dev
->dev_reservation_lock
);
1294 pr_reg
= dev
->dev_pr_res_holder
;
1296 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1297 spin_unlock(&dev
->dev_reservation_lock
);
1300 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1301 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1302 spin_unlock(&dev
->dev_reservation_lock
);
1307 SE_DEV_PR_ATTR_RO(res_pr_type
);
1312 static ssize_t
target_core_dev_pr_show_attr_res_type(
1313 struct se_subsystem_dev
*su_dev
,
1318 if (!su_dev
->se_dev_ptr
)
1321 switch (su_dev
->t10_pr
.res_type
) {
1322 case SPC3_PERSISTENT_RESERVATIONS
:
1323 len
= sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1325 case SPC2_RESERVATIONS
:
1326 len
= sprintf(page
, "SPC2_RESERVATIONS\n");
1328 case SPC_PASSTHROUGH
:
1329 len
= sprintf(page
, "SPC_PASSTHROUGH\n");
1332 len
= sprintf(page
, "UNKNOWN\n");
1339 SE_DEV_PR_ATTR_RO(res_type
);
1345 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_active(
1346 struct se_subsystem_dev
*su_dev
,
1349 if (!su_dev
->se_dev_ptr
)
1352 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1355 return sprintf(page
, "APTPL Bit Status: %s\n",
1356 (su_dev
->t10_pr
.pr_aptpl_active
) ? "Activated" : "Disabled");
1359 SE_DEV_PR_ATTR_RO(res_aptpl_active
);
1362 * res_aptpl_metadata
1364 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_metadata(
1365 struct se_subsystem_dev
*su_dev
,
1368 if (!su_dev
->se_dev_ptr
)
1371 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1374 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1378 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1379 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1380 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1381 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1384 static match_table_t tokens
= {
1385 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1386 {Opt_initiator_node
, "initiator_node=%s"},
1387 {Opt_initiator_sid
, "initiator_sid=%s"},
1388 {Opt_sa_res_key
, "sa_res_key=%s"},
1389 {Opt_res_holder
, "res_holder=%d"},
1390 {Opt_res_type
, "res_type=%d"},
1391 {Opt_res_scope
, "res_scope=%d"},
1392 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1393 {Opt_mapped_lun
, "mapped_lun=%d"},
1394 {Opt_target_fabric
, "target_fabric=%s"},
1395 {Opt_target_node
, "target_node=%s"},
1396 {Opt_tpgt
, "tpgt=%d"},
1397 {Opt_port_rtpi
, "port_rtpi=%d"},
1398 {Opt_target_lun
, "target_lun=%d"},
1402 static ssize_t
target_core_dev_pr_store_attr_res_aptpl_metadata(
1403 struct se_subsystem_dev
*su_dev
,
1407 struct se_device
*dev
;
1408 unsigned char *i_fabric
= NULL
, *i_port
= NULL
, *isid
= NULL
;
1409 unsigned char *t_fabric
= NULL
, *t_port
= NULL
;
1410 char *orig
, *ptr
, *arg_p
, *opts
;
1411 substring_t args
[MAX_OPT_ARGS
];
1412 unsigned long long tmp_ll
;
1414 u32 mapped_lun
= 0, target_lun
= 0;
1415 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1416 u16 port_rpti
= 0, tpgt
= 0;
1419 dev
= su_dev
->se_dev_ptr
;
1423 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1426 if (atomic_read(&dev
->dev_export_obj
.obj_access_count
)) {
1427 pr_debug("Unable to process APTPL metadata while"
1428 " active fabric exports exist\n");
1432 opts
= kstrdup(page
, GFP_KERNEL
);
1437 while ((ptr
= strsep(&opts
, ",\n")) != NULL
) {
1441 token
= match_token(ptr
, tokens
, args
);
1443 case Opt_initiator_fabric
:
1444 i_fabric
= match_strdup(&args
[0]);
1450 case Opt_initiator_node
:
1451 i_port
= match_strdup(&args
[0]);
1456 if (strlen(i_port
) >= PR_APTPL_MAX_IPORT_LEN
) {
1457 pr_err("APTPL metadata initiator_node="
1458 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1459 PR_APTPL_MAX_IPORT_LEN
);
1464 case Opt_initiator_sid
:
1465 isid
= match_strdup(&args
[0]);
1470 if (strlen(isid
) >= PR_REG_ISID_LEN
) {
1471 pr_err("APTPL metadata initiator_isid"
1472 "= exceeds PR_REG_ISID_LEN: %d\n",
1478 case Opt_sa_res_key
:
1479 arg_p
= match_strdup(&args
[0]);
1484 ret
= strict_strtoull(arg_p
, 0, &tmp_ll
);
1486 pr_err("strict_strtoull() failed for"
1490 sa_res_key
= (u64
)tmp_ll
;
1493 * PR APTPL Metadata for Reservation
1495 case Opt_res_holder
:
1496 match_int(args
, &arg
);
1500 match_int(args
, &arg
);
1504 match_int(args
, &arg
);
1507 case Opt_res_all_tg_pt
:
1508 match_int(args
, &arg
);
1509 all_tg_pt
= (int)arg
;
1511 case Opt_mapped_lun
:
1512 match_int(args
, &arg
);
1513 mapped_lun
= (u32
)arg
;
1516 * PR APTPL Metadata for Target Port
1518 case Opt_target_fabric
:
1519 t_fabric
= match_strdup(&args
[0]);
1525 case Opt_target_node
:
1526 t_port
= match_strdup(&args
[0]);
1531 if (strlen(t_port
) >= PR_APTPL_MAX_TPORT_LEN
) {
1532 pr_err("APTPL metadata target_node="
1533 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1534 PR_APTPL_MAX_TPORT_LEN
);
1540 match_int(args
, &arg
);
1544 match_int(args
, &arg
);
1545 port_rpti
= (u16
)arg
;
1547 case Opt_target_lun
:
1548 match_int(args
, &arg
);
1549 target_lun
= (u32
)arg
;
1556 if (!i_port
|| !t_port
|| !sa_res_key
) {
1557 pr_err("Illegal parameters for APTPL registration\n");
1562 if (res_holder
&& !(type
)) {
1563 pr_err("Illegal PR type: 0x%02x for reservation"
1569 ret
= core_scsi3_alloc_aptpl_registration(&su_dev
->t10_pr
, sa_res_key
,
1570 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1571 res_holder
, all_tg_pt
, type
);
1579 return (ret
== 0) ? count
: ret
;
1582 SE_DEV_PR_ATTR(res_aptpl_metadata
, S_IRUGO
| S_IWUSR
);
1584 CONFIGFS_EATTR_OPS(target_core_dev_pr
, se_subsystem_dev
, se_dev_pr_group
);
1586 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1587 &target_core_dev_pr_res_holder
.attr
,
1588 &target_core_dev_pr_res_pr_all_tgt_pts
.attr
,
1589 &target_core_dev_pr_res_pr_generation
.attr
,
1590 &target_core_dev_pr_res_pr_holder_tg_port
.attr
,
1591 &target_core_dev_pr_res_pr_registered_i_pts
.attr
,
1592 &target_core_dev_pr_res_pr_type
.attr
,
1593 &target_core_dev_pr_res_type
.attr
,
1594 &target_core_dev_pr_res_aptpl_active
.attr
,
1595 &target_core_dev_pr_res_aptpl_metadata
.attr
,
1599 static struct configfs_item_operations target_core_dev_pr_ops
= {
1600 .show_attribute
= target_core_dev_pr_attr_show
,
1601 .store_attribute
= target_core_dev_pr_attr_store
,
1604 static struct config_item_type target_core_dev_pr_cit
= {
1605 .ct_item_ops
= &target_core_dev_pr_ops
,
1606 .ct_attrs
= target_core_dev_pr_attrs
,
1607 .ct_owner
= THIS_MODULE
,
1610 /* End functions for struct config_item_type target_core_dev_pr_cit */
1612 /* Start functions for struct config_item_type target_core_dev_cit */
1614 static ssize_t
target_core_show_dev_info(void *p
, char *page
)
1616 struct se_subsystem_dev
*se_dev
= p
;
1617 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1618 struct se_subsystem_api
*t
= hba
->transport
;
1620 ssize_t read_bytes
= 0;
1622 if (!se_dev
->se_dev_ptr
)
1625 transport_dump_dev_state(se_dev
->se_dev_ptr
, page
, &bl
);
1627 read_bytes
+= t
->show_configfs_dev_params(hba
, se_dev
, page
+read_bytes
);
1631 static struct target_core_configfs_attribute target_core_attr_dev_info
= {
1632 .attr
= { .ca_owner
= THIS_MODULE
,
1634 .ca_mode
= S_IRUGO
},
1635 .show
= target_core_show_dev_info
,
1639 static ssize_t
target_core_store_dev_control(
1644 struct se_subsystem_dev
*se_dev
= p
;
1645 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1646 struct se_subsystem_api
*t
= hba
->transport
;
1648 if (!se_dev
->se_dev_su_ptr
) {
1649 pr_err("Unable to locate struct se_subsystem_dev>se"
1654 return t
->set_configfs_dev_params(hba
, se_dev
, page
, count
);
1657 static struct target_core_configfs_attribute target_core_attr_dev_control
= {
1658 .attr
= { .ca_owner
= THIS_MODULE
,
1659 .ca_name
= "control",
1660 .ca_mode
= S_IWUSR
},
1662 .store
= target_core_store_dev_control
,
1665 static ssize_t
target_core_show_dev_alias(void *p
, char *page
)
1667 struct se_subsystem_dev
*se_dev
= p
;
1669 if (!(se_dev
->su_dev_flags
& SDF_USING_ALIAS
))
1672 return snprintf(page
, PAGE_SIZE
, "%s\n", se_dev
->se_dev_alias
);
1675 static ssize_t
target_core_store_dev_alias(
1680 struct se_subsystem_dev
*se_dev
= p
;
1681 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1684 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1685 pr_err("alias count: %d exceeds"
1686 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1687 SE_DEV_ALIAS_LEN
-1);
1691 read_bytes
= snprintf(&se_dev
->se_dev_alias
[0], SE_DEV_ALIAS_LEN
,
1695 if (se_dev
->se_dev_alias
[read_bytes
- 1] == '\n')
1696 se_dev
->se_dev_alias
[read_bytes
- 1] = '\0';
1698 se_dev
->su_dev_flags
|= SDF_USING_ALIAS
;
1700 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
1701 config_item_name(&hba
->hba_group
.cg_item
),
1702 config_item_name(&se_dev
->se_dev_group
.cg_item
),
1703 se_dev
->se_dev_alias
);
1708 static struct target_core_configfs_attribute target_core_attr_dev_alias
= {
1709 .attr
= { .ca_owner
= THIS_MODULE
,
1711 .ca_mode
= S_IRUGO
| S_IWUSR
},
1712 .show
= target_core_show_dev_alias
,
1713 .store
= target_core_store_dev_alias
,
1716 static ssize_t
target_core_show_dev_udev_path(void *p
, char *page
)
1718 struct se_subsystem_dev
*se_dev
= p
;
1720 if (!(se_dev
->su_dev_flags
& SDF_USING_UDEV_PATH
))
1723 return snprintf(page
, PAGE_SIZE
, "%s\n", se_dev
->se_dev_udev_path
);
1726 static ssize_t
target_core_store_dev_udev_path(
1731 struct se_subsystem_dev
*se_dev
= p
;
1732 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1735 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1736 pr_err("udev_path count: %d exceeds"
1737 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1738 SE_UDEV_PATH_LEN
-1);
1742 read_bytes
= snprintf(&se_dev
->se_dev_udev_path
[0], SE_UDEV_PATH_LEN
,
1746 if (se_dev
->se_dev_udev_path
[read_bytes
- 1] == '\n')
1747 se_dev
->se_dev_udev_path
[read_bytes
- 1] = '\0';
1749 se_dev
->su_dev_flags
|= SDF_USING_UDEV_PATH
;
1751 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1752 config_item_name(&hba
->hba_group
.cg_item
),
1753 config_item_name(&se_dev
->se_dev_group
.cg_item
),
1754 se_dev
->se_dev_udev_path
);
1759 static struct target_core_configfs_attribute target_core_attr_dev_udev_path
= {
1760 .attr
= { .ca_owner
= THIS_MODULE
,
1761 .ca_name
= "udev_path",
1762 .ca_mode
= S_IRUGO
| S_IWUSR
},
1763 .show
= target_core_show_dev_udev_path
,
1764 .store
= target_core_store_dev_udev_path
,
1767 static ssize_t
target_core_store_dev_enable(
1772 struct se_subsystem_dev
*se_dev
= p
;
1773 struct se_device
*dev
;
1774 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1775 struct se_subsystem_api
*t
= hba
->transport
;
1778 ptr
= strstr(page
, "1");
1780 pr_err("For dev_enable ops, only valid value"
1784 if (se_dev
->se_dev_ptr
) {
1785 pr_err("se_dev->se_dev_ptr already set for storage"
1790 if (t
->check_configfs_dev_params(hba
, se_dev
) < 0)
1793 dev
= t
->create_virtdevice(hba
, se_dev
, se_dev
->se_dev_su_ptr
);
1795 return PTR_ERR(dev
);
1799 se_dev
->se_dev_ptr
= dev
;
1800 pr_debug("Target_Core_ConfigFS: Registered se_dev->se_dev_ptr:"
1801 " %p\n", se_dev
->se_dev_ptr
);
1806 static struct target_core_configfs_attribute target_core_attr_dev_enable
= {
1807 .attr
= { .ca_owner
= THIS_MODULE
,
1808 .ca_name
= "enable",
1809 .ca_mode
= S_IWUSR
},
1811 .store
= target_core_store_dev_enable
,
1814 static ssize_t
target_core_show_alua_lu_gp(void *p
, char *page
)
1816 struct se_device
*dev
;
1817 struct se_subsystem_dev
*su_dev
= p
;
1818 struct config_item
*lu_ci
;
1819 struct t10_alua_lu_gp
*lu_gp
;
1820 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1823 dev
= su_dev
->se_dev_ptr
;
1827 if (su_dev
->t10_alua
.alua_type
!= SPC3_ALUA_EMULATED
)
1830 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1832 pr_err("NULL struct se_device->dev_alua_lu_gp_mem"
1837 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1838 lu_gp
= lu_gp_mem
->lu_gp
;
1840 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1841 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1842 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1844 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1849 static ssize_t
target_core_store_alua_lu_gp(
1854 struct se_device
*dev
;
1855 struct se_subsystem_dev
*su_dev
= p
;
1856 struct se_hba
*hba
= su_dev
->se_dev_hba
;
1857 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1858 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1859 unsigned char buf
[LU_GROUP_NAME_BUF
];
1862 dev
= su_dev
->se_dev_ptr
;
1866 if (su_dev
->t10_alua
.alua_type
!= SPC3_ALUA_EMULATED
) {
1867 pr_warn("SPC3_ALUA_EMULATED not enabled for %s/%s\n",
1868 config_item_name(&hba
->hba_group
.cg_item
),
1869 config_item_name(&su_dev
->se_dev_group
.cg_item
));
1872 if (count
> LU_GROUP_NAME_BUF
) {
1873 pr_err("ALUA LU Group Alias too large!\n");
1876 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1877 memcpy(buf
, page
, count
);
1879 * Any ALUA logical unit alias besides "NULL" means we will be
1880 * making a new group association.
1882 if (strcmp(strstrip(buf
), "NULL")) {
1884 * core_alua_get_lu_gp_by_name() will increment reference to
1885 * struct t10_alua_lu_gp. This reference is released with
1886 * core_alua_get_lu_gp_by_name below().
1888 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
1892 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1895 core_alua_put_lu_gp_from_name(lu_gp_new
);
1896 pr_err("NULL struct se_device->dev_alua_lu_gp_mem"
1901 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1902 lu_gp
= lu_gp_mem
->lu_gp
;
1905 * Clearing an existing lu_gp association, and replacing
1909 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
1910 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1912 config_item_name(&hba
->hba_group
.cg_item
),
1913 config_item_name(&su_dev
->se_dev_group
.cg_item
),
1914 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1917 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1918 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1923 * Removing existing association of lu_gp_mem with lu_gp
1925 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1929 * Associate lu_gp_mem with lu_gp_new.
1931 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
1932 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1934 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1935 " core/alua/lu_gps/%s, ID: %hu\n",
1936 (move
) ? "Moving" : "Adding",
1937 config_item_name(&hba
->hba_group
.cg_item
),
1938 config_item_name(&su_dev
->se_dev_group
.cg_item
),
1939 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
1940 lu_gp_new
->lu_gp_id
);
1942 core_alua_put_lu_gp_from_name(lu_gp_new
);
1946 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp
= {
1947 .attr
= { .ca_owner
= THIS_MODULE
,
1948 .ca_name
= "alua_lu_gp",
1949 .ca_mode
= S_IRUGO
| S_IWUSR
},
1950 .show
= target_core_show_alua_lu_gp
,
1951 .store
= target_core_store_alua_lu_gp
,
1954 static struct configfs_attribute
*lio_core_dev_attrs
[] = {
1955 &target_core_attr_dev_info
.attr
,
1956 &target_core_attr_dev_control
.attr
,
1957 &target_core_attr_dev_alias
.attr
,
1958 &target_core_attr_dev_udev_path
.attr
,
1959 &target_core_attr_dev_enable
.attr
,
1960 &target_core_attr_dev_alua_lu_gp
.attr
,
1964 static void target_core_dev_release(struct config_item
*item
)
1966 struct se_subsystem_dev
*se_dev
= container_of(to_config_group(item
),
1967 struct se_subsystem_dev
, se_dev_group
);
1968 struct se_hba
*hba
= item_to_hba(&se_dev
->se_dev_hba
->hba_group
.cg_item
);
1969 struct se_subsystem_api
*t
= hba
->transport
;
1970 struct config_group
*dev_cg
= &se_dev
->se_dev_group
;
1972 kfree(dev_cg
->default_groups
);
1974 * This pointer will set when the storage is enabled with:
1975 *`echo 1 > $CONFIGFS/core/$HBA/$DEV/dev_enable`
1977 if (se_dev
->se_dev_ptr
) {
1978 pr_debug("Target_Core_ConfigFS: Calling se_free_"
1979 "virtual_device() for se_dev_ptr: %p\n",
1980 se_dev
->se_dev_ptr
);
1982 se_free_virtual_device(se_dev
->se_dev_ptr
, hba
);
1985 * Release struct se_subsystem_dev->se_dev_su_ptr..
1987 pr_debug("Target_Core_ConfigFS: Calling t->free_"
1988 "device() for se_dev_su_ptr: %p\n",
1989 se_dev
->se_dev_su_ptr
);
1991 t
->free_device(se_dev
->se_dev_su_ptr
);
1994 pr_debug("Target_Core_ConfigFS: Deallocating se_subsystem"
1995 "_dev_t: %p\n", se_dev
);
1999 static ssize_t
target_core_dev_show(struct config_item
*item
,
2000 struct configfs_attribute
*attr
,
2003 struct se_subsystem_dev
*se_dev
= container_of(
2004 to_config_group(item
), struct se_subsystem_dev
,
2006 struct target_core_configfs_attribute
*tc_attr
= container_of(
2007 attr
, struct target_core_configfs_attribute
, attr
);
2012 return tc_attr
->show(se_dev
, page
);
2015 static ssize_t
target_core_dev_store(struct config_item
*item
,
2016 struct configfs_attribute
*attr
,
2017 const char *page
, size_t count
)
2019 struct se_subsystem_dev
*se_dev
= container_of(
2020 to_config_group(item
), struct se_subsystem_dev
,
2022 struct target_core_configfs_attribute
*tc_attr
= container_of(
2023 attr
, struct target_core_configfs_attribute
, attr
);
2025 if (!tc_attr
->store
)
2028 return tc_attr
->store(se_dev
, page
, count
);
2031 static struct configfs_item_operations target_core_dev_item_ops
= {
2032 .release
= target_core_dev_release
,
2033 .show_attribute
= target_core_dev_show
,
2034 .store_attribute
= target_core_dev_store
,
2037 static struct config_item_type target_core_dev_cit
= {
2038 .ct_item_ops
= &target_core_dev_item_ops
,
2039 .ct_attrs
= lio_core_dev_attrs
,
2040 .ct_owner
= THIS_MODULE
,
2043 /* End functions for struct config_item_type target_core_dev_cit */
2045 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
2047 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp
, t10_alua_lu_gp
);
2048 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
2049 static struct target_core_alua_lu_gp_attribute \
2050 target_core_alua_lu_gp_##_name = \
2051 __CONFIGFS_EATTR(_name, _mode, \
2052 target_core_alua_lu_gp_show_attr_##_name, \
2053 target_core_alua_lu_gp_store_attr_##_name);
2055 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
2056 static struct target_core_alua_lu_gp_attribute \
2057 target_core_alua_lu_gp_##_name = \
2058 __CONFIGFS_EATTR_RO(_name, \
2059 target_core_alua_lu_gp_show_attr_##_name);
2064 static ssize_t
target_core_alua_lu_gp_show_attr_lu_gp_id(
2065 struct t10_alua_lu_gp
*lu_gp
,
2068 if (!lu_gp
->lu_gp_valid_id
)
2071 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
2074 static ssize_t
target_core_alua_lu_gp_store_attr_lu_gp_id(
2075 struct t10_alua_lu_gp
*lu_gp
,
2079 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2080 unsigned long lu_gp_id
;
2083 ret
= strict_strtoul(page
, 0, &lu_gp_id
);
2085 pr_err("strict_strtoul() returned %d for"
2086 " lu_gp_id\n", ret
);
2089 if (lu_gp_id
> 0x0000ffff) {
2090 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
2091 " 0x0000ffff\n", lu_gp_id
);
2095 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
2099 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
2100 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2101 config_item_name(&alua_lu_gp_cg
->cg_item
),
2107 SE_DEV_ALUA_LU_ATTR(lu_gp_id
, S_IRUGO
| S_IWUSR
);
2112 static ssize_t
target_core_alua_lu_gp_show_attr_members(
2113 struct t10_alua_lu_gp
*lu_gp
,
2116 struct se_device
*dev
;
2118 struct se_subsystem_dev
*su_dev
;
2119 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2120 ssize_t len
= 0, cur_len
;
2121 unsigned char buf
[LU_GROUP_NAME_BUF
];
2123 memset(buf
, 0, LU_GROUP_NAME_BUF
);
2125 spin_lock(&lu_gp
->lu_gp_lock
);
2126 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
2127 dev
= lu_gp_mem
->lu_gp_mem_dev
;
2128 su_dev
= dev
->se_sub_dev
;
2129 hba
= su_dev
->se_dev_hba
;
2131 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
2132 config_item_name(&hba
->hba_group
.cg_item
),
2133 config_item_name(&su_dev
->se_dev_group
.cg_item
));
2134 cur_len
++; /* Extra byte for NULL terminator */
2136 if ((cur_len
+ len
) > PAGE_SIZE
) {
2137 pr_warn("Ran out of lu_gp_show_attr"
2138 "_members buffer\n");
2141 memcpy(page
+len
, buf
, cur_len
);
2144 spin_unlock(&lu_gp
->lu_gp_lock
);
2149 SE_DEV_ALUA_LU_ATTR_RO(members
);
2151 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp
, t10_alua_lu_gp
, lu_gp_group
);
2153 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
2154 &target_core_alua_lu_gp_lu_gp_id
.attr
,
2155 &target_core_alua_lu_gp_members
.attr
,
2159 static void target_core_alua_lu_gp_release(struct config_item
*item
)
2161 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2162 struct t10_alua_lu_gp
, lu_gp_group
);
2164 core_alua_free_lu_gp(lu_gp
);
2167 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
2168 .release
= target_core_alua_lu_gp_release
,
2169 .show_attribute
= target_core_alua_lu_gp_attr_show
,
2170 .store_attribute
= target_core_alua_lu_gp_attr_store
,
2173 static struct config_item_type target_core_alua_lu_gp_cit
= {
2174 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
2175 .ct_attrs
= target_core_alua_lu_gp_attrs
,
2176 .ct_owner
= THIS_MODULE
,
2179 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
2181 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
2183 static struct config_group
*target_core_alua_create_lu_gp(
2184 struct config_group
*group
,
2187 struct t10_alua_lu_gp
*lu_gp
;
2188 struct config_group
*alua_lu_gp_cg
= NULL
;
2189 struct config_item
*alua_lu_gp_ci
= NULL
;
2191 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
2195 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2196 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
2198 config_group_init_type_name(alua_lu_gp_cg
, name
,
2199 &target_core_alua_lu_gp_cit
);
2201 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2202 " Group: core/alua/lu_gps/%s\n",
2203 config_item_name(alua_lu_gp_ci
));
2205 return alua_lu_gp_cg
;
2209 static void target_core_alua_drop_lu_gp(
2210 struct config_group
*group
,
2211 struct config_item
*item
)
2213 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2214 struct t10_alua_lu_gp
, lu_gp_group
);
2216 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2217 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2218 config_item_name(item
), lu_gp
->lu_gp_id
);
2220 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
2221 * -> target_core_alua_lu_gp_release()
2223 config_item_put(item
);
2226 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
2227 .make_group
= &target_core_alua_create_lu_gp
,
2228 .drop_item
= &target_core_alua_drop_lu_gp
,
2231 static struct config_item_type target_core_alua_lu_gps_cit
= {
2232 .ct_item_ops
= NULL
,
2233 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
2234 .ct_owner
= THIS_MODULE
,
2237 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
2239 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2241 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
);
2242 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
2243 static struct target_core_alua_tg_pt_gp_attribute \
2244 target_core_alua_tg_pt_gp_##_name = \
2245 __CONFIGFS_EATTR(_name, _mode, \
2246 target_core_alua_tg_pt_gp_show_attr_##_name, \
2247 target_core_alua_tg_pt_gp_store_attr_##_name);
2249 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2250 static struct target_core_alua_tg_pt_gp_attribute \
2251 target_core_alua_tg_pt_gp_##_name = \
2252 __CONFIGFS_EATTR_RO(_name, \
2253 target_core_alua_tg_pt_gp_show_attr_##_name);
2258 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2259 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2262 return sprintf(page
, "%d\n",
2263 atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
));
2266 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2267 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2271 struct se_subsystem_dev
*su_dev
= tg_pt_gp
->tg_pt_gp_su_dev
;
2275 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2276 pr_err("Unable to do implict ALUA on non valid"
2277 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2281 ret
= strict_strtoul(page
, 0, &tmp
);
2283 pr_err("Unable to extract new ALUA access state from"
2287 new_state
= (int)tmp
;
2289 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICT_ALUA
)) {
2290 pr_err("Unable to process implict configfs ALUA"
2291 " transition while TPGS_IMPLICT_ALUA is disabled\n");
2295 ret
= core_alua_do_port_transition(tg_pt_gp
, su_dev
->se_dev_ptr
,
2296 NULL
, NULL
, new_state
, 0);
2297 return (!ret
) ? count
: -EINVAL
;
2300 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state
, S_IRUGO
| S_IWUSR
);
2303 * alua_access_status
2305 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2306 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2309 return sprintf(page
, "%s\n",
2310 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2313 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2314 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2319 int new_status
, ret
;
2321 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2322 pr_err("Unable to do set ALUA access status on non"
2323 " valid tg_pt_gp ID: %hu\n",
2324 tg_pt_gp
->tg_pt_gp_valid_id
);
2328 ret
= strict_strtoul(page
, 0, &tmp
);
2330 pr_err("Unable to extract new ALUA access status"
2331 " from %s\n", page
);
2334 new_status
= (int)tmp
;
2336 if ((new_status
!= ALUA_STATUS_NONE
) &&
2337 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
) &&
2338 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
)) {
2339 pr_err("Illegal ALUA access status: 0x%02x\n",
2344 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2348 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status
, S_IRUGO
| S_IWUSR
);
2353 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2354 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2357 return core_alua_show_access_type(tg_pt_gp
, page
);
2360 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2361 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2365 return core_alua_store_access_type(tg_pt_gp
, page
, count
);
2368 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type
, S_IRUGO
| S_IWUSR
);
2371 * alua_write_metadata
2373 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2374 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2377 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_write_metadata
);
2380 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2381 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2388 ret
= strict_strtoul(page
, 0, &tmp
);
2390 pr_err("Unable to extract alua_write_metadata\n");
2394 if ((tmp
!= 0) && (tmp
!= 1)) {
2395 pr_err("Illegal value for alua_write_metadata:"
2399 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2404 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata
, S_IRUGO
| S_IWUSR
);
2411 static ssize_t
target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2412 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2415 return core_alua_show_nonop_delay_msecs(tg_pt_gp
, page
);
2419 static ssize_t
target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2420 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2424 return core_alua_store_nonop_delay_msecs(tg_pt_gp
, page
, count
);
2427 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs
, S_IRUGO
| S_IWUSR
);
2432 static ssize_t
target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2433 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2436 return core_alua_show_trans_delay_msecs(tg_pt_gp
, page
);
2439 static ssize_t
target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2440 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2444 return core_alua_store_trans_delay_msecs(tg_pt_gp
, page
, count
);
2447 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs
, S_IRUGO
| S_IWUSR
);
2450 * implict_trans_secs
2452 static ssize_t
target_core_alua_tg_pt_gp_show_attr_implict_trans_secs(
2453 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2456 return core_alua_show_implict_trans_secs(tg_pt_gp
, page
);
2459 static ssize_t
target_core_alua_tg_pt_gp_store_attr_implict_trans_secs(
2460 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2464 return core_alua_store_implict_trans_secs(tg_pt_gp
, page
, count
);
2467 SE_DEV_ALUA_TG_PT_ATTR(implict_trans_secs
, S_IRUGO
| S_IWUSR
);
2473 static ssize_t
target_core_alua_tg_pt_gp_show_attr_preferred(
2474 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2477 return core_alua_show_preferred_bit(tg_pt_gp
, page
);
2480 static ssize_t
target_core_alua_tg_pt_gp_store_attr_preferred(
2481 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2485 return core_alua_store_preferred_bit(tg_pt_gp
, page
, count
);
2488 SE_DEV_ALUA_TG_PT_ATTR(preferred
, S_IRUGO
| S_IWUSR
);
2493 static ssize_t
target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2494 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2497 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
2500 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2503 static ssize_t
target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2504 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2508 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2509 unsigned long tg_pt_gp_id
;
2512 ret
= strict_strtoul(page
, 0, &tg_pt_gp_id
);
2514 pr_err("strict_strtoul() returned %d for"
2515 " tg_pt_gp_id\n", ret
);
2518 if (tg_pt_gp_id
> 0x0000ffff) {
2519 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:"
2520 " 0x0000ffff\n", tg_pt_gp_id
);
2524 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2528 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
2529 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2530 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2531 tg_pt_gp
->tg_pt_gp_id
);
2536 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id
, S_IRUGO
| S_IWUSR
);
2541 static ssize_t
target_core_alua_tg_pt_gp_show_attr_members(
2542 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2545 struct se_port
*port
;
2546 struct se_portal_group
*tpg
;
2548 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
2549 ssize_t len
= 0, cur_len
;
2550 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2552 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2554 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2555 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
2556 tg_pt_gp_mem_list
) {
2557 port
= tg_pt_gp_mem
->tg_pt
;
2558 tpg
= port
->sep_tpg
;
2559 lun
= port
->sep_lun
;
2561 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2562 "/%s\n", tpg
->se_tpg_tfo
->get_fabric_name(),
2563 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
2564 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
2565 config_item_name(&lun
->lun_group
.cg_item
));
2566 cur_len
++; /* Extra byte for NULL terminator */
2568 if ((cur_len
+ len
) > PAGE_SIZE
) {
2569 pr_warn("Ran out of lu_gp_show_attr"
2570 "_members buffer\n");
2573 memcpy(page
+len
, buf
, cur_len
);
2576 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2581 SE_DEV_ALUA_TG_PT_ATTR_RO(members
);
2583 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
,
2586 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2587 &target_core_alua_tg_pt_gp_alua_access_state
.attr
,
2588 &target_core_alua_tg_pt_gp_alua_access_status
.attr
,
2589 &target_core_alua_tg_pt_gp_alua_access_type
.attr
,
2590 &target_core_alua_tg_pt_gp_alua_write_metadata
.attr
,
2591 &target_core_alua_tg_pt_gp_nonop_delay_msecs
.attr
,
2592 &target_core_alua_tg_pt_gp_trans_delay_msecs
.attr
,
2593 &target_core_alua_tg_pt_gp_implict_trans_secs
.attr
,
2594 &target_core_alua_tg_pt_gp_preferred
.attr
,
2595 &target_core_alua_tg_pt_gp_tg_pt_gp_id
.attr
,
2596 &target_core_alua_tg_pt_gp_members
.attr
,
2600 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2602 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2603 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2605 core_alua_free_tg_pt_gp(tg_pt_gp
);
2608 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2609 .release
= target_core_alua_tg_pt_gp_release
,
2610 .show_attribute
= target_core_alua_tg_pt_gp_attr_show
,
2611 .store_attribute
= target_core_alua_tg_pt_gp_attr_store
,
2614 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2615 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2616 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2617 .ct_owner
= THIS_MODULE
,
2620 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2622 /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2624 static struct config_group
*target_core_alua_create_tg_pt_gp(
2625 struct config_group
*group
,
2628 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2629 alua_tg_pt_gps_group
);
2630 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2631 struct se_subsystem_dev
*su_dev
= alua
->t10_sub_dev
;
2632 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2633 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2635 tg_pt_gp
= core_alua_allocate_tg_pt_gp(su_dev
, name
, 0);
2639 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2640 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2642 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2643 &target_core_alua_tg_pt_gp_cit
);
2645 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
2646 " Group: alua/tg_pt_gps/%s\n",
2647 config_item_name(alua_tg_pt_gp_ci
));
2649 return alua_tg_pt_gp_cg
;
2652 static void target_core_alua_drop_tg_pt_gp(
2653 struct config_group
*group
,
2654 struct config_item
*item
)
2656 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2657 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2659 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
2660 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2661 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2663 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2664 * -> target_core_alua_tg_pt_gp_release().
2666 config_item_put(item
);
2669 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2670 .make_group
= &target_core_alua_create_tg_pt_gp
,
2671 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2674 static struct config_item_type target_core_alua_tg_pt_gps_cit
= {
2675 .ct_group_ops
= &target_core_alua_tg_pt_gps_group_ops
,
2676 .ct_owner
= THIS_MODULE
,
2679 /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2681 /* Start functions for struct config_item_type target_core_alua_cit */
2684 * target_core_alua_cit is a ConfigFS group that lives under
2685 * /sys/kernel/config/target/core/alua. There are default groups
2686 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2687 * target_core_alua_cit in target_core_init_configfs() below.
2689 static struct config_item_type target_core_alua_cit
= {
2690 .ct_item_ops
= NULL
,
2692 .ct_owner
= THIS_MODULE
,
2695 /* End functions for struct config_item_type target_core_alua_cit */
2697 /* Start functions for struct config_item_type target_core_stat_cit */
2699 static struct config_group
*target_core_stat_mkdir(
2700 struct config_group
*group
,
2703 return ERR_PTR(-ENOSYS
);
2706 static void target_core_stat_rmdir(
2707 struct config_group
*group
,
2708 struct config_item
*item
)
2713 static struct configfs_group_operations target_core_stat_group_ops
= {
2714 .make_group
= &target_core_stat_mkdir
,
2715 .drop_item
= &target_core_stat_rmdir
,
2718 static struct config_item_type target_core_stat_cit
= {
2719 .ct_group_ops
= &target_core_stat_group_ops
,
2720 .ct_owner
= THIS_MODULE
,
2723 /* End functions for struct config_item_type target_core_stat_cit */
2725 /* Start functions for struct config_item_type target_core_hba_cit */
2727 static struct config_group
*target_core_make_subdev(
2728 struct config_group
*group
,
2731 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2732 struct se_subsystem_dev
*se_dev
;
2733 struct se_subsystem_api
*t
;
2734 struct config_item
*hba_ci
= &group
->cg_item
;
2735 struct se_hba
*hba
= item_to_hba(hba_ci
);
2736 struct config_group
*dev_cg
= NULL
, *tg_pt_gp_cg
= NULL
;
2737 struct config_group
*dev_stat_grp
= NULL
;
2738 int errno
= -ENOMEM
, ret
;
2740 ret
= mutex_lock_interruptible(&hba
->hba_access_mutex
);
2742 return ERR_PTR(ret
);
2744 * Locate the struct se_subsystem_api from parent's struct se_hba.
2748 se_dev
= kzalloc(sizeof(struct se_subsystem_dev
), GFP_KERNEL
);
2750 pr_err("Unable to allocate memory for"
2751 " struct se_subsystem_dev\n");
2754 INIT_LIST_HEAD(&se_dev
->t10_wwn
.t10_vpd_list
);
2755 spin_lock_init(&se_dev
->t10_wwn
.t10_vpd_lock
);
2756 INIT_LIST_HEAD(&se_dev
->t10_pr
.registration_list
);
2757 INIT_LIST_HEAD(&se_dev
->t10_pr
.aptpl_reg_list
);
2758 spin_lock_init(&se_dev
->t10_pr
.registration_lock
);
2759 spin_lock_init(&se_dev
->t10_pr
.aptpl_reg_lock
);
2760 INIT_LIST_HEAD(&se_dev
->t10_alua
.tg_pt_gps_list
);
2761 spin_lock_init(&se_dev
->t10_alua
.tg_pt_gps_lock
);
2762 spin_lock_init(&se_dev
->se_dev_lock
);
2763 se_dev
->t10_pr
.pr_aptpl_buf_len
= PR_APTPL_BUF_LEN
;
2764 se_dev
->t10_wwn
.t10_sub_dev
= se_dev
;
2765 se_dev
->t10_alua
.t10_sub_dev
= se_dev
;
2766 se_dev
->se_dev_attrib
.da_sub_dev
= se_dev
;
2768 se_dev
->se_dev_hba
= hba
;
2769 dev_cg
= &se_dev
->se_dev_group
;
2771 dev_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 7,
2773 if (!dev_cg
->default_groups
)
2776 * Set se_dev_su_ptr from struct se_subsystem_api returned void ptr
2777 * for ->allocate_virtdevice()
2779 * se_dev->se_dev_ptr will be set after ->create_virtdev()
2780 * has been called successfully in the next level up in the
2781 * configfs tree for device object's struct config_group.
2783 se_dev
->se_dev_su_ptr
= t
->allocate_virtdevice(hba
, name
);
2784 if (!se_dev
->se_dev_su_ptr
) {
2785 pr_err("Unable to locate subsystem dependent pointer"
2786 " from allocate_virtdevice()\n");
2790 config_group_init_type_name(&se_dev
->se_dev_group
, name
,
2791 &target_core_dev_cit
);
2792 config_group_init_type_name(&se_dev
->se_dev_attrib
.da_group
, "attrib",
2793 &target_core_dev_attrib_cit
);
2794 config_group_init_type_name(&se_dev
->se_dev_pr_group
, "pr",
2795 &target_core_dev_pr_cit
);
2796 config_group_init_type_name(&se_dev
->t10_wwn
.t10_wwn_group
, "wwn",
2797 &target_core_dev_wwn_cit
);
2798 config_group_init_type_name(&se_dev
->t10_alua
.alua_tg_pt_gps_group
,
2799 "alua", &target_core_alua_tg_pt_gps_cit
);
2800 config_group_init_type_name(&se_dev
->dev_stat_grps
.stat_group
,
2801 "statistics", &target_core_stat_cit
);
2803 dev_cg
->default_groups
[0] = &se_dev
->se_dev_attrib
.da_group
;
2804 dev_cg
->default_groups
[1] = &se_dev
->se_dev_pr_group
;
2805 dev_cg
->default_groups
[2] = &se_dev
->t10_wwn
.t10_wwn_group
;
2806 dev_cg
->default_groups
[3] = &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2807 dev_cg
->default_groups
[4] = &se_dev
->dev_stat_grps
.stat_group
;
2808 dev_cg
->default_groups
[5] = NULL
;
2810 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
2812 tg_pt_gp
= core_alua_allocate_tg_pt_gp(se_dev
, "default_tg_pt_gp", 1);
2816 tg_pt_gp_cg
= &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2817 tg_pt_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
2819 if (!tg_pt_gp_cg
->default_groups
) {
2820 pr_err("Unable to allocate tg_pt_gp_cg->"
2821 "default_groups\n");
2825 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2826 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2827 tg_pt_gp_cg
->default_groups
[0] = &tg_pt_gp
->tg_pt_gp_group
;
2828 tg_pt_gp_cg
->default_groups
[1] = NULL
;
2829 se_dev
->t10_alua
.default_tg_pt_gp
= tg_pt_gp
;
2831 * Add core/$HBA/$DEV/statistics/ default groups
2833 dev_stat_grp
= &se_dev
->dev_stat_grps
.stat_group
;
2834 dev_stat_grp
->default_groups
= kzalloc(sizeof(struct config_group
) * 4,
2836 if (!dev_stat_grp
->default_groups
) {
2837 pr_err("Unable to allocate dev_stat_grp->default_groups\n");
2840 target_stat_setup_dev_default_groups(se_dev
);
2842 pr_debug("Target_Core_ConfigFS: Allocated struct se_subsystem_dev:"
2843 " %p se_dev_su_ptr: %p\n", se_dev
, se_dev
->se_dev_su_ptr
);
2845 mutex_unlock(&hba
->hba_access_mutex
);
2846 return &se_dev
->se_dev_group
;
2848 if (se_dev
->t10_alua
.default_tg_pt_gp
) {
2849 core_alua_free_tg_pt_gp(se_dev
->t10_alua
.default_tg_pt_gp
);
2850 se_dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2853 kfree(dev_stat_grp
->default_groups
);
2855 kfree(tg_pt_gp_cg
->default_groups
);
2857 kfree(dev_cg
->default_groups
);
2858 if (se_dev
->se_dev_su_ptr
)
2859 t
->free_device(se_dev
->se_dev_su_ptr
);
2862 mutex_unlock(&hba
->hba_access_mutex
);
2863 return ERR_PTR(errno
);
2866 static void target_core_drop_subdev(
2867 struct config_group
*group
,
2868 struct config_item
*item
)
2870 struct se_subsystem_dev
*se_dev
= container_of(to_config_group(item
),
2871 struct se_subsystem_dev
, se_dev_group
);
2873 struct config_item
*df_item
;
2874 struct config_group
*dev_cg
, *tg_pt_gp_cg
, *dev_stat_grp
;
2877 hba
= item_to_hba(&se_dev
->se_dev_hba
->hba_group
.cg_item
);
2879 mutex_lock(&hba
->hba_access_mutex
);
2881 dev_stat_grp
= &se_dev
->dev_stat_grps
.stat_group
;
2882 for (i
= 0; dev_stat_grp
->default_groups
[i
]; i
++) {
2883 df_item
= &dev_stat_grp
->default_groups
[i
]->cg_item
;
2884 dev_stat_grp
->default_groups
[i
] = NULL
;
2885 config_item_put(df_item
);
2887 kfree(dev_stat_grp
->default_groups
);
2889 tg_pt_gp_cg
= &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2890 for (i
= 0; tg_pt_gp_cg
->default_groups
[i
]; i
++) {
2891 df_item
= &tg_pt_gp_cg
->default_groups
[i
]->cg_item
;
2892 tg_pt_gp_cg
->default_groups
[i
] = NULL
;
2893 config_item_put(df_item
);
2895 kfree(tg_pt_gp_cg
->default_groups
);
2897 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2898 * directly from target_core_alua_tg_pt_gp_release().
2900 se_dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2902 dev_cg
= &se_dev
->se_dev_group
;
2903 for (i
= 0; dev_cg
->default_groups
[i
]; i
++) {
2904 df_item
= &dev_cg
->default_groups
[i
]->cg_item
;
2905 dev_cg
->default_groups
[i
] = NULL
;
2906 config_item_put(df_item
);
2909 * The releasing of se_dev and associated se_dev->se_dev_ptr is done
2910 * from target_core_dev_item_ops->release() ->target_core_dev_release().
2912 config_item_put(item
);
2913 mutex_unlock(&hba
->hba_access_mutex
);
2916 static struct configfs_group_operations target_core_hba_group_ops
= {
2917 .make_group
= target_core_make_subdev
,
2918 .drop_item
= target_core_drop_subdev
,
2921 CONFIGFS_EATTR_STRUCT(target_core_hba
, se_hba
);
2922 #define SE_HBA_ATTR(_name, _mode) \
2923 static struct target_core_hba_attribute \
2924 target_core_hba_##_name = \
2925 __CONFIGFS_EATTR(_name, _mode, \
2926 target_core_hba_show_attr_##_name, \
2927 target_core_hba_store_attr_##_name);
2929 #define SE_HBA_ATTR_RO(_name) \
2930 static struct target_core_hba_attribute \
2931 target_core_hba_##_name = \
2932 __CONFIGFS_EATTR_RO(_name, \
2933 target_core_hba_show_attr_##_name);
2935 static ssize_t
target_core_hba_show_attr_hba_info(
2939 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
2940 hba
->hba_id
, hba
->transport
->name
,
2941 TARGET_CORE_CONFIGFS_VERSION
);
2944 SE_HBA_ATTR_RO(hba_info
);
2946 static ssize_t
target_core_hba_show_attr_hba_mode(struct se_hba
*hba
,
2951 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
2954 return sprintf(page
, "%d\n", hba_mode
);
2957 static ssize_t
target_core_hba_store_attr_hba_mode(struct se_hba
*hba
,
2958 const char *page
, size_t count
)
2960 struct se_subsystem_api
*transport
= hba
->transport
;
2961 unsigned long mode_flag
;
2964 if (transport
->pmode_enable_hba
== NULL
)
2967 ret
= strict_strtoul(page
, 0, &mode_flag
);
2969 pr_err("Unable to extract hba mode flag: %d\n", ret
);
2973 spin_lock(&hba
->device_lock
);
2974 if (!list_empty(&hba
->hba_dev_list
)) {
2975 pr_err("Unable to set hba_mode with active devices\n");
2976 spin_unlock(&hba
->device_lock
);
2979 spin_unlock(&hba
->device_lock
);
2981 ret
= transport
->pmode_enable_hba(hba
, mode_flag
);
2985 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
2987 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
2992 SE_HBA_ATTR(hba_mode
, S_IRUGO
| S_IWUSR
);
2994 CONFIGFS_EATTR_OPS(target_core_hba
, se_hba
, hba_group
);
2996 static void target_core_hba_release(struct config_item
*item
)
2998 struct se_hba
*hba
= container_of(to_config_group(item
),
2999 struct se_hba
, hba_group
);
3000 core_delete_hba(hba
);
3003 static struct configfs_attribute
*target_core_hba_attrs
[] = {
3004 &target_core_hba_hba_info
.attr
,
3005 &target_core_hba_hba_mode
.attr
,
3009 static struct configfs_item_operations target_core_hba_item_ops
= {
3010 .release
= target_core_hba_release
,
3011 .show_attribute
= target_core_hba_attr_show
,
3012 .store_attribute
= target_core_hba_attr_store
,
3015 static struct config_item_type target_core_hba_cit
= {
3016 .ct_item_ops
= &target_core_hba_item_ops
,
3017 .ct_group_ops
= &target_core_hba_group_ops
,
3018 .ct_attrs
= target_core_hba_attrs
,
3019 .ct_owner
= THIS_MODULE
,
3022 static struct config_group
*target_core_call_addhbatotarget(
3023 struct config_group
*group
,
3026 char *se_plugin_str
, *str
, *str2
;
3028 char buf
[TARGET_CORE_NAME_MAX_LEN
];
3029 unsigned long plugin_dep_id
= 0;
3032 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
3033 if (strlen(name
) >= TARGET_CORE_NAME_MAX_LEN
) {
3034 pr_err("Passed *name strlen(): %d exceeds"
3035 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
3036 TARGET_CORE_NAME_MAX_LEN
);
3037 return ERR_PTR(-ENAMETOOLONG
);
3039 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
3041 str
= strstr(buf
, "_");
3043 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
3044 return ERR_PTR(-EINVAL
);
3046 se_plugin_str
= buf
;
3048 * Special case for subsystem plugins that have "_" in their names.
3049 * Namely rd_direct and rd_mcp..
3051 str2
= strstr(str
+1, "_");
3053 *str2
= '\0'; /* Terminate for *se_plugin_str */
3054 str2
++; /* Skip to start of plugin dependent ID */
3057 *str
= '\0'; /* Terminate for *se_plugin_str */
3058 str
++; /* Skip to start of plugin dependent ID */
3061 ret
= strict_strtoul(str
, 0, &plugin_dep_id
);
3063 pr_err("strict_strtoul() returned %d for"
3064 " plugin_dep_id\n", ret
);
3065 return ERR_PTR(-EINVAL
);
3068 * Load up TCM subsystem plugins if they have not already been loaded.
3070 transport_subsystem_check_init();
3072 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
3074 return ERR_CAST(hba
);
3076 config_group_init_type_name(&hba
->hba_group
, name
,
3077 &target_core_hba_cit
);
3079 return &hba
->hba_group
;
3082 static void target_core_call_delhbafromtarget(
3083 struct config_group
*group
,
3084 struct config_item
*item
)
3087 * core_delete_hba() is called from target_core_hba_item_ops->release()
3088 * -> target_core_hba_release()
3090 config_item_put(item
);
3093 static struct configfs_group_operations target_core_group_ops
= {
3094 .make_group
= target_core_call_addhbatotarget
,
3095 .drop_item
= target_core_call_delhbafromtarget
,
3098 static struct config_item_type target_core_cit
= {
3099 .ct_item_ops
= NULL
,
3100 .ct_group_ops
= &target_core_group_ops
,
3102 .ct_owner
= THIS_MODULE
,
3105 /* Stop functions for struct config_item_type target_core_hba_cit */
3107 static int __init
target_core_init_configfs(void)
3109 struct config_group
*target_cg
, *hba_cg
= NULL
, *alua_cg
= NULL
;
3110 struct config_group
*lu_gp_cg
= NULL
;
3111 struct configfs_subsystem
*subsys
;
3112 struct t10_alua_lu_gp
*lu_gp
;
3115 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
3116 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
3117 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
3119 subsys
= target_core_subsystem
[0];
3120 config_group_init(&subsys
->su_group
);
3121 mutex_init(&subsys
->su_mutex
);
3123 ret
= init_se_kmem_caches();
3127 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
3128 * and ALUA Logical Unit Group and Target Port Group infrastructure.
3130 target_cg
= &subsys
->su_group
;
3131 target_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3133 if (!target_cg
->default_groups
) {
3134 pr_err("Unable to allocate target_cg->default_groups\n");
3139 config_group_init_type_name(&target_core_hbagroup
,
3140 "core", &target_core_cit
);
3141 target_cg
->default_groups
[0] = &target_core_hbagroup
;
3142 target_cg
->default_groups
[1] = NULL
;
3144 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
3146 hba_cg
= &target_core_hbagroup
;
3147 hba_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3149 if (!hba_cg
->default_groups
) {
3150 pr_err("Unable to allocate hba_cg->default_groups\n");
3154 config_group_init_type_name(&alua_group
,
3155 "alua", &target_core_alua_cit
);
3156 hba_cg
->default_groups
[0] = &alua_group
;
3157 hba_cg
->default_groups
[1] = NULL
;
3159 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
3160 * groups under /sys/kernel/config/target/core/alua/
3162 alua_cg
= &alua_group
;
3163 alua_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3165 if (!alua_cg
->default_groups
) {
3166 pr_err("Unable to allocate alua_cg->default_groups\n");
3171 config_group_init_type_name(&alua_lu_gps_group
,
3172 "lu_gps", &target_core_alua_lu_gps_cit
);
3173 alua_cg
->default_groups
[0] = &alua_lu_gps_group
;
3174 alua_cg
->default_groups
[1] = NULL
;
3176 * Add core/alua/lu_gps/default_lu_gp
3178 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
3179 if (IS_ERR(lu_gp
)) {
3184 lu_gp_cg
= &alua_lu_gps_group
;
3185 lu_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3187 if (!lu_gp_cg
->default_groups
) {
3188 pr_err("Unable to allocate lu_gp_cg->default_groups\n");
3193 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
3194 &target_core_alua_lu_gp_cit
);
3195 lu_gp_cg
->default_groups
[0] = &lu_gp
->lu_gp_group
;
3196 lu_gp_cg
->default_groups
[1] = NULL
;
3197 default_lu_gp
= lu_gp
;
3199 * Register the target_core_mod subsystem with configfs.
3201 ret
= configfs_register_subsystem(subsys
);
3203 pr_err("Error %d while registering subsystem %s\n",
3204 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
3207 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
3208 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION
" on %s/%s"
3209 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
3211 * Register built-in RAMDISK subsystem logic for virtual LUN 0
3213 ret
= rd_module_init();
3217 ret
= core_dev_setup_virtual_lun0();
3224 configfs_unregister_subsystem(subsys
);
3225 core_dev_release_virtual_lun0();
3228 if (default_lu_gp
) {
3229 core_alua_free_lu_gp(default_lu_gp
);
3230 default_lu_gp
= NULL
;
3233 kfree(lu_gp_cg
->default_groups
);
3235 kfree(alua_cg
->default_groups
);
3237 kfree(hba_cg
->default_groups
);
3238 kfree(target_cg
->default_groups
);
3239 release_se_kmem_caches();
3243 static void __exit
target_core_exit_configfs(void)
3245 struct configfs_subsystem
*subsys
;
3246 struct config_group
*hba_cg
, *alua_cg
, *lu_gp_cg
;
3247 struct config_item
*item
;
3250 subsys
= target_core_subsystem
[0];
3252 lu_gp_cg
= &alua_lu_gps_group
;
3253 for (i
= 0; lu_gp_cg
->default_groups
[i
]; i
++) {
3254 item
= &lu_gp_cg
->default_groups
[i
]->cg_item
;
3255 lu_gp_cg
->default_groups
[i
] = NULL
;
3256 config_item_put(item
);
3258 kfree(lu_gp_cg
->default_groups
);
3259 lu_gp_cg
->default_groups
= NULL
;
3261 alua_cg
= &alua_group
;
3262 for (i
= 0; alua_cg
->default_groups
[i
]; i
++) {
3263 item
= &alua_cg
->default_groups
[i
]->cg_item
;
3264 alua_cg
->default_groups
[i
] = NULL
;
3265 config_item_put(item
);
3267 kfree(alua_cg
->default_groups
);
3268 alua_cg
->default_groups
= NULL
;
3270 hba_cg
= &target_core_hbagroup
;
3271 for (i
= 0; hba_cg
->default_groups
[i
]; i
++) {
3272 item
= &hba_cg
->default_groups
[i
]->cg_item
;
3273 hba_cg
->default_groups
[i
] = NULL
;
3274 config_item_put(item
);
3276 kfree(hba_cg
->default_groups
);
3277 hba_cg
->default_groups
= NULL
;
3279 * We expect subsys->su_group.default_groups to be released
3280 * by configfs subsystem provider logic..
3282 configfs_unregister_subsystem(subsys
);
3283 kfree(subsys
->su_group
.default_groups
);
3285 core_alua_free_lu_gp(default_lu_gp
);
3286 default_lu_gp
= NULL
;
3288 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
3289 " Infrastructure\n");
3291 core_dev_release_virtual_lun0();
3293 release_se_kmem_caches();
3296 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3297 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3298 MODULE_LICENSE("GPL");
3300 module_init(target_core_init_configfs
);
3301 module_exit(target_core_exit_configfs
);