1 /*******************************************************************************
2 * Filename: target_core_configfs.c
4 * This file contains ConfigFS logic for the Generic Target Engine project.
6 * Copyright (c) 2008-2010 Rising Tide Systems
7 * Copyright (c) 2008-2010 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 <linux/version.h>
27 #include <generated/utsrelease.h>
28 #include <linux/utsname.h>
29 #include <linux/init.h>
31 #include <linux/namei.h>
32 #include <linux/slab.h>
33 #include <linux/types.h>
34 #include <linux/delay.h>
35 #include <linux/unistd.h>
36 #include <linux/string.h>
37 #include <linux/parser.h>
38 #include <linux/syscalls.h>
39 #include <linux/configfs.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"
54 static struct list_head g_tf_list
;
55 static struct mutex g_tf_lock
;
57 struct target_core_configfs_attribute
{
58 struct configfs_attribute attr
;
59 ssize_t (*show
)(void *, char *);
60 ssize_t (*store
)(void *, const char *, size_t);
63 static inline struct se_hba
*
64 item_to_hba(struct config_item
*item
)
66 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
70 * Attributes for /sys/kernel/config/target/
72 static ssize_t
target_core_attr_show(struct config_item
*item
,
73 struct configfs_attribute
*attr
,
76 return sprintf(page
, "Target Engine Core ConfigFS Infrastructure %s"
77 " on %s/%s on "UTS_RELEASE
"\n", TARGET_CORE_CONFIGFS_VERSION
,
78 utsname()->sysname
, utsname()->machine
);
81 static struct configfs_item_operations target_core_fabric_item_ops
= {
82 .show_attribute
= target_core_attr_show
,
85 static struct configfs_attribute target_core_item_attr_version
= {
86 .ca_owner
= THIS_MODULE
,
91 static struct target_fabric_configfs
*target_core_get_fabric(
94 struct target_fabric_configfs
*tf
;
99 mutex_lock(&g_tf_lock
);
100 list_for_each_entry(tf
, &g_tf_list
, tf_list
) {
101 if (!(strcmp(tf
->tf_name
, name
))) {
102 atomic_inc(&tf
->tf_access_cnt
);
103 mutex_unlock(&g_tf_lock
);
107 mutex_unlock(&g_tf_lock
);
113 * Called from struct target_core_group_ops->make_group()
115 static struct config_group
*target_core_register_fabric(
116 struct config_group
*group
,
119 struct target_fabric_configfs
*tf
;
122 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER -> group: %p name:"
123 " %s\n", group
, name
);
125 * Ensure that TCM subsystem plugins are loaded at this point for
126 * using the RAMDISK_DR virtual LUN 0 and all other struct se_port
129 if (transport_subsystem_check_init() < 0)
130 return ERR_PTR(-EINVAL
);
133 * Below are some hardcoded request_module() calls to automatically
134 * local fabric modules when the following is called:
136 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
138 * Note that this does not limit which TCM fabric module can be
139 * registered, but simply provids auto loading logic for modules with
140 * mkdir(2) system calls with known TCM fabric modules.
142 if (!(strncmp(name
, "iscsi", 5))) {
144 * Automatically load the LIO Target fabric module when the
145 * following is called:
147 * mkdir -p $CONFIGFS/target/iscsi
149 ret
= request_module("iscsi_target_mod");
151 printk(KERN_ERR
"request_module() failed for"
152 " iscsi_target_mod.ko: %d\n", ret
);
153 return ERR_PTR(-EINVAL
);
155 } else if (!(strncmp(name
, "loopback", 8))) {
157 * Automatically load the tcm_loop fabric module when the
158 * following is called:
160 * mkdir -p $CONFIGFS/target/loopback
162 ret
= request_module("tcm_loop");
164 printk(KERN_ERR
"request_module() failed for"
165 " tcm_loop.ko: %d\n", ret
);
166 return ERR_PTR(-EINVAL
);
170 tf
= target_core_get_fabric(name
);
172 printk(KERN_ERR
"target_core_get_fabric() failed for %s\n",
174 return ERR_PTR(-EINVAL
);
176 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER -> Located fabric:"
177 " %s\n", tf
->tf_name
);
179 * On a successful target_core_get_fabric() look, the returned
180 * struct target_fabric_configfs *tf will contain a usage reference.
182 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
183 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
185 tf
->tf_group
.default_groups
= tf
->tf_default_groups
;
186 tf
->tf_group
.default_groups
[0] = &tf
->tf_disc_group
;
187 tf
->tf_group
.default_groups
[1] = NULL
;
189 config_group_init_type_name(&tf
->tf_group
, name
,
190 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
191 config_group_init_type_name(&tf
->tf_disc_group
, "discovery_auth",
192 &TF_CIT_TMPL(tf
)->tfc_discovery_cit
);
194 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
195 " %s\n", tf
->tf_group
.cg_item
.ci_name
);
197 * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item()
199 tf
->tf_ops
.tf_subsys
= tf
->tf_subsys
;
200 tf
->tf_fabric
= &tf
->tf_group
.cg_item
;
201 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
204 return &tf
->tf_group
;
208 * Called from struct target_core_group_ops->drop_item()
210 static void target_core_deregister_fabric(
211 struct config_group
*group
,
212 struct config_item
*item
)
214 struct target_fabric_configfs
*tf
= container_of(
215 to_config_group(item
), struct target_fabric_configfs
, tf_group
);
216 struct config_group
*tf_group
;
217 struct config_item
*df_item
;
220 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
221 " tf list\n", config_item_name(item
));
223 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> located fabric:"
224 " %s\n", tf
->tf_name
);
225 atomic_dec(&tf
->tf_access_cnt
);
227 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> Releasing"
228 " tf->tf_fabric for %s\n", tf
->tf_name
);
229 tf
->tf_fabric
= NULL
;
231 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
232 " %s\n", config_item_name(item
));
234 tf_group
= &tf
->tf_group
;
235 for (i
= 0; tf_group
->default_groups
[i
]; i
++) {
236 df_item
= &tf_group
->default_groups
[i
]->cg_item
;
237 tf_group
->default_groups
[i
] = NULL
;
238 config_item_put(df_item
);
240 config_item_put(item
);
243 static struct configfs_group_operations target_core_fabric_group_ops
= {
244 .make_group
= &target_core_register_fabric
,
245 .drop_item
= &target_core_deregister_fabric
,
249 * All item attributes appearing in /sys/kernel/target/ appear here.
251 static struct configfs_attribute
*target_core_fabric_item_attrs
[] = {
252 &target_core_item_attr_version
,
257 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
259 static struct config_item_type target_core_fabrics_item
= {
260 .ct_item_ops
= &target_core_fabric_item_ops
,
261 .ct_group_ops
= &target_core_fabric_group_ops
,
262 .ct_attrs
= target_core_fabric_item_attrs
,
263 .ct_owner
= THIS_MODULE
,
266 static struct configfs_subsystem target_core_fabrics
= {
269 .ci_namebuf
= "target",
270 .ci_type
= &target_core_fabrics_item
,
275 static struct configfs_subsystem
*target_core_subsystem
[] = {
276 &target_core_fabrics
,
280 /*##############################################################################
281 // Start functions called by external Target Fabrics Modules
282 //############################################################################*/
285 * First function called by fabric modules to:
287 * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer.
288 * 2) Add struct target_fabric_configfs to g_tf_list
289 * 3) Return struct target_fabric_configfs to fabric module to be passed
290 * into target_fabric_configfs_register().
292 struct target_fabric_configfs
*target_fabric_configfs_init(
293 struct module
*fabric_mod
,
296 struct target_fabric_configfs
*tf
;
299 printk(KERN_ERR
"Missing struct module *fabric_mod pointer\n");
303 printk(KERN_ERR
"Unable to locate passed fabric name\n");
306 if (strlen(name
) > TARGET_FABRIC_NAME_SIZE
) {
307 printk(KERN_ERR
"Passed name: %s exceeds TARGET_FABRIC"
308 "_NAME_SIZE\n", name
);
312 tf
= kzalloc(sizeof(struct target_fabric_configfs
), GFP_KERNEL
);
314 return ERR_PTR(-ENOMEM
);
316 INIT_LIST_HEAD(&tf
->tf_list
);
317 atomic_set(&tf
->tf_access_cnt
, 0);
319 * Setup the default generic struct config_item_type's (cits) in
320 * struct target_fabric_configfs->tf_cit_tmpl
322 tf
->tf_module
= fabric_mod
;
323 target_fabric_setup_cits(tf
);
325 tf
->tf_subsys
= target_core_subsystem
[0];
326 snprintf(tf
->tf_name
, TARGET_FABRIC_NAME_SIZE
, "%s", name
);
328 mutex_lock(&g_tf_lock
);
329 list_add_tail(&tf
->tf_list
, &g_tf_list
);
330 mutex_unlock(&g_tf_lock
);
332 printk(KERN_INFO
"<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>"
334 printk(KERN_INFO
"Initialized struct target_fabric_configfs: %p for"
335 " %s\n", tf
, tf
->tf_name
);
338 EXPORT_SYMBOL(target_fabric_configfs_init
);
341 * Called by fabric plugins after FAILED target_fabric_configfs_register() call.
343 void target_fabric_configfs_free(
344 struct target_fabric_configfs
*tf
)
346 mutex_lock(&g_tf_lock
);
347 list_del(&tf
->tf_list
);
348 mutex_unlock(&g_tf_lock
);
352 EXPORT_SYMBOL(target_fabric_configfs_free
);
355 * Perform a sanity check of the passed tf->tf_ops before completing
356 * TCM fabric module registration.
358 static int target_fabric_tf_ops_check(
359 struct target_fabric_configfs
*tf
)
361 struct target_core_fabric_ops
*tfo
= &tf
->tf_ops
;
363 if (!(tfo
->get_fabric_name
)) {
364 printk(KERN_ERR
"Missing tfo->get_fabric_name()\n");
367 if (!(tfo
->get_fabric_proto_ident
)) {
368 printk(KERN_ERR
"Missing tfo->get_fabric_proto_ident()\n");
371 if (!(tfo
->tpg_get_wwn
)) {
372 printk(KERN_ERR
"Missing tfo->tpg_get_wwn()\n");
375 if (!(tfo
->tpg_get_tag
)) {
376 printk(KERN_ERR
"Missing tfo->tpg_get_tag()\n");
379 if (!(tfo
->tpg_get_default_depth
)) {
380 printk(KERN_ERR
"Missing tfo->tpg_get_default_depth()\n");
383 if (!(tfo
->tpg_get_pr_transport_id
)) {
384 printk(KERN_ERR
"Missing tfo->tpg_get_pr_transport_id()\n");
387 if (!(tfo
->tpg_get_pr_transport_id_len
)) {
388 printk(KERN_ERR
"Missing tfo->tpg_get_pr_transport_id_len()\n");
391 if (!(tfo
->tpg_check_demo_mode
)) {
392 printk(KERN_ERR
"Missing tfo->tpg_check_demo_mode()\n");
395 if (!(tfo
->tpg_check_demo_mode_cache
)) {
396 printk(KERN_ERR
"Missing tfo->tpg_check_demo_mode_cache()\n");
399 if (!(tfo
->tpg_check_demo_mode_write_protect
)) {
400 printk(KERN_ERR
"Missing tfo->tpg_check_demo_mode_write_protect()\n");
403 if (!(tfo
->tpg_check_prod_mode_write_protect
)) {
404 printk(KERN_ERR
"Missing tfo->tpg_check_prod_mode_write_protect()\n");
407 if (!(tfo
->tpg_alloc_fabric_acl
)) {
408 printk(KERN_ERR
"Missing tfo->tpg_alloc_fabric_acl()\n");
411 if (!(tfo
->tpg_release_fabric_acl
)) {
412 printk(KERN_ERR
"Missing tfo->tpg_release_fabric_acl()\n");
415 if (!(tfo
->tpg_get_inst_index
)) {
416 printk(KERN_ERR
"Missing tfo->tpg_get_inst_index()\n");
419 if (!(tfo
->release_cmd_to_pool
)) {
420 printk(KERN_ERR
"Missing tfo->release_cmd_to_pool()\n");
423 if (!(tfo
->release_cmd_direct
)) {
424 printk(KERN_ERR
"Missing tfo->release_cmd_direct()\n");
427 if (!(tfo
->shutdown_session
)) {
428 printk(KERN_ERR
"Missing tfo->shutdown_session()\n");
431 if (!(tfo
->close_session
)) {
432 printk(KERN_ERR
"Missing tfo->close_session()\n");
435 if (!(tfo
->stop_session
)) {
436 printk(KERN_ERR
"Missing tfo->stop_session()\n");
439 if (!(tfo
->fall_back_to_erl0
)) {
440 printk(KERN_ERR
"Missing tfo->fall_back_to_erl0()\n");
443 if (!(tfo
->sess_logged_in
)) {
444 printk(KERN_ERR
"Missing tfo->sess_logged_in()\n");
447 if (!(tfo
->sess_get_index
)) {
448 printk(KERN_ERR
"Missing tfo->sess_get_index()\n");
451 if (!(tfo
->write_pending
)) {
452 printk(KERN_ERR
"Missing tfo->write_pending()\n");
455 if (!(tfo
->write_pending_status
)) {
456 printk(KERN_ERR
"Missing tfo->write_pending_status()\n");
459 if (!(tfo
->set_default_node_attributes
)) {
460 printk(KERN_ERR
"Missing tfo->set_default_node_attributes()\n");
463 if (!(tfo
->get_task_tag
)) {
464 printk(KERN_ERR
"Missing tfo->get_task_tag()\n");
467 if (!(tfo
->get_cmd_state
)) {
468 printk(KERN_ERR
"Missing tfo->get_cmd_state()\n");
471 if (!(tfo
->new_cmd_failure
)) {
472 printk(KERN_ERR
"Missing tfo->new_cmd_failure()\n");
475 if (!(tfo
->queue_data_in
)) {
476 printk(KERN_ERR
"Missing tfo->queue_data_in()\n");
479 if (!(tfo
->queue_status
)) {
480 printk(KERN_ERR
"Missing tfo->queue_status()\n");
483 if (!(tfo
->queue_tm_rsp
)) {
484 printk(KERN_ERR
"Missing tfo->queue_tm_rsp()\n");
487 if (!(tfo
->set_fabric_sense_len
)) {
488 printk(KERN_ERR
"Missing tfo->set_fabric_sense_len()\n");
491 if (!(tfo
->get_fabric_sense_len
)) {
492 printk(KERN_ERR
"Missing tfo->get_fabric_sense_len()\n");
495 if (!(tfo
->is_state_remove
)) {
496 printk(KERN_ERR
"Missing tfo->is_state_remove()\n");
499 if (!(tfo
->pack_lun
)) {
500 printk(KERN_ERR
"Missing tfo->pack_lun()\n");
504 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
505 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
506 * target_core_fabric_configfs.c WWN+TPG group context code.
508 if (!(tfo
->fabric_make_wwn
)) {
509 printk(KERN_ERR
"Missing tfo->fabric_make_wwn()\n");
512 if (!(tfo
->fabric_drop_wwn
)) {
513 printk(KERN_ERR
"Missing tfo->fabric_drop_wwn()\n");
516 if (!(tfo
->fabric_make_tpg
)) {
517 printk(KERN_ERR
"Missing tfo->fabric_make_tpg()\n");
520 if (!(tfo
->fabric_drop_tpg
)) {
521 printk(KERN_ERR
"Missing tfo->fabric_drop_tpg()\n");
529 * Called 2nd from fabric module with returned parameter of
530 * struct target_fabric_configfs * from target_fabric_configfs_init().
532 * Upon a successful registration, the new fabric's struct config_item is
533 * return. Also, a pointer to this struct is set in the passed
534 * struct target_fabric_configfs.
536 int target_fabric_configfs_register(
537 struct target_fabric_configfs
*tf
)
539 struct config_group
*su_group
;
543 printk(KERN_ERR
"Unable to locate target_fabric_configfs"
547 if (!(tf
->tf_subsys
)) {
548 printk(KERN_ERR
"Unable to target struct config_subsystem"
552 su_group
= &tf
->tf_subsys
->su_group
;
554 printk(KERN_ERR
"Unable to locate target struct config_group"
558 ret
= target_fabric_tf_ops_check(tf
);
562 printk(KERN_INFO
"<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>"
566 EXPORT_SYMBOL(target_fabric_configfs_register
);
568 void target_fabric_configfs_deregister(
569 struct target_fabric_configfs
*tf
)
571 struct config_group
*su_group
;
572 struct configfs_subsystem
*su
;
575 printk(KERN_ERR
"Unable to locate passed target_fabric_"
581 printk(KERN_ERR
"Unable to locate passed tf->tf_subsys"
585 su_group
= &tf
->tf_subsys
->su_group
;
587 printk(KERN_ERR
"Unable to locate target struct config_group"
592 printk(KERN_INFO
"<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
594 mutex_lock(&g_tf_lock
);
595 if (atomic_read(&tf
->tf_access_cnt
)) {
596 mutex_unlock(&g_tf_lock
);
597 printk(KERN_ERR
"Non zero tf->tf_access_cnt for fabric %s\n",
601 list_del(&tf
->tf_list
);
602 mutex_unlock(&g_tf_lock
);
604 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
605 " %s\n", tf
->tf_name
);
606 tf
->tf_module
= NULL
;
607 tf
->tf_subsys
= NULL
;
610 printk("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
614 EXPORT_SYMBOL(target_fabric_configfs_deregister
);
616 /*##############################################################################
617 // Stop functions called by external Target Fabrics Modules
618 //############################################################################*/
620 /* Start functions for struct config_item_type target_core_dev_attrib_cit */
622 #define DEF_DEV_ATTRIB_SHOW(_name) \
623 static ssize_t target_core_dev_show_attr_##_name( \
624 struct se_dev_attrib *da, \
627 struct se_device *dev; \
628 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
631 spin_lock(&se_dev->se_dev_lock); \
632 dev = se_dev->se_dev_ptr; \
634 spin_unlock(&se_dev->se_dev_lock); \
637 rb = snprintf(page, PAGE_SIZE, "%u\n", (u32)DEV_ATTRIB(dev)->_name); \
638 spin_unlock(&se_dev->se_dev_lock); \
643 #define DEF_DEV_ATTRIB_STORE(_name) \
644 static ssize_t target_core_dev_store_attr_##_name( \
645 struct se_dev_attrib *da, \
649 struct se_device *dev; \
650 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
654 spin_lock(&se_dev->se_dev_lock); \
655 dev = se_dev->se_dev_ptr; \
657 spin_unlock(&se_dev->se_dev_lock); \
660 ret = strict_strtoul(page, 0, &val); \
662 spin_unlock(&se_dev->se_dev_lock); \
663 printk(KERN_ERR "strict_strtoul() failed with" \
664 " ret: %d\n", ret); \
667 ret = se_dev_set_##_name(dev, (u32)val); \
668 spin_unlock(&se_dev->se_dev_lock); \
670 return (!ret) ? count : -EINVAL; \
673 #define DEF_DEV_ATTRIB(_name) \
674 DEF_DEV_ATTRIB_SHOW(_name); \
675 DEF_DEV_ATTRIB_STORE(_name);
677 #define DEF_DEV_ATTRIB_RO(_name) \
678 DEF_DEV_ATTRIB_SHOW(_name);
680 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib
, se_dev_attrib
);
681 #define SE_DEV_ATTR(_name, _mode) \
682 static struct target_core_dev_attrib_attribute \
683 target_core_dev_attrib_##_name = \
684 __CONFIGFS_EATTR(_name, _mode, \
685 target_core_dev_show_attr_##_name, \
686 target_core_dev_store_attr_##_name);
688 #define SE_DEV_ATTR_RO(_name); \
689 static struct target_core_dev_attrib_attribute \
690 target_core_dev_attrib_##_name = \
691 __CONFIGFS_EATTR_RO(_name, \
692 target_core_dev_show_attr_##_name);
694 DEF_DEV_ATTRIB(emulate_dpo
);
695 SE_DEV_ATTR(emulate_dpo
, S_IRUGO
| S_IWUSR
);
697 DEF_DEV_ATTRIB(emulate_fua_write
);
698 SE_DEV_ATTR(emulate_fua_write
, S_IRUGO
| S_IWUSR
);
700 DEF_DEV_ATTRIB(emulate_fua_read
);
701 SE_DEV_ATTR(emulate_fua_read
, S_IRUGO
| S_IWUSR
);
703 DEF_DEV_ATTRIB(emulate_write_cache
);
704 SE_DEV_ATTR(emulate_write_cache
, S_IRUGO
| S_IWUSR
);
706 DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl
);
707 SE_DEV_ATTR(emulate_ua_intlck_ctrl
, S_IRUGO
| S_IWUSR
);
709 DEF_DEV_ATTRIB(emulate_tas
);
710 SE_DEV_ATTR(emulate_tas
, S_IRUGO
| S_IWUSR
);
712 DEF_DEV_ATTRIB(emulate_tpu
);
713 SE_DEV_ATTR(emulate_tpu
, S_IRUGO
| S_IWUSR
);
715 DEF_DEV_ATTRIB(emulate_tpws
);
716 SE_DEV_ATTR(emulate_tpws
, S_IRUGO
| S_IWUSR
);
718 DEF_DEV_ATTRIB(enforce_pr_isids
);
719 SE_DEV_ATTR(enforce_pr_isids
, S_IRUGO
| S_IWUSR
);
721 DEF_DEV_ATTRIB_RO(hw_block_size
);
722 SE_DEV_ATTR_RO(hw_block_size
);
724 DEF_DEV_ATTRIB(block_size
);
725 SE_DEV_ATTR(block_size
, S_IRUGO
| S_IWUSR
);
727 DEF_DEV_ATTRIB_RO(hw_max_sectors
);
728 SE_DEV_ATTR_RO(hw_max_sectors
);
730 DEF_DEV_ATTRIB(max_sectors
);
731 SE_DEV_ATTR(max_sectors
, S_IRUGO
| S_IWUSR
);
733 DEF_DEV_ATTRIB(optimal_sectors
);
734 SE_DEV_ATTR(optimal_sectors
, S_IRUGO
| S_IWUSR
);
736 DEF_DEV_ATTRIB_RO(hw_queue_depth
);
737 SE_DEV_ATTR_RO(hw_queue_depth
);
739 DEF_DEV_ATTRIB(queue_depth
);
740 SE_DEV_ATTR(queue_depth
, S_IRUGO
| S_IWUSR
);
742 DEF_DEV_ATTRIB(task_timeout
);
743 SE_DEV_ATTR(task_timeout
, S_IRUGO
| S_IWUSR
);
745 DEF_DEV_ATTRIB(max_unmap_lba_count
);
746 SE_DEV_ATTR(max_unmap_lba_count
, S_IRUGO
| S_IWUSR
);
748 DEF_DEV_ATTRIB(max_unmap_block_desc_count
);
749 SE_DEV_ATTR(max_unmap_block_desc_count
, S_IRUGO
| S_IWUSR
);
751 DEF_DEV_ATTRIB(unmap_granularity
);
752 SE_DEV_ATTR(unmap_granularity
, S_IRUGO
| S_IWUSR
);
754 DEF_DEV_ATTRIB(unmap_granularity_alignment
);
755 SE_DEV_ATTR(unmap_granularity_alignment
, S_IRUGO
| S_IWUSR
);
757 CONFIGFS_EATTR_OPS(target_core_dev_attrib
, se_dev_attrib
, da_group
);
759 static struct configfs_attribute
*target_core_dev_attrib_attrs
[] = {
760 &target_core_dev_attrib_emulate_dpo
.attr
,
761 &target_core_dev_attrib_emulate_fua_write
.attr
,
762 &target_core_dev_attrib_emulate_fua_read
.attr
,
763 &target_core_dev_attrib_emulate_write_cache
.attr
,
764 &target_core_dev_attrib_emulate_ua_intlck_ctrl
.attr
,
765 &target_core_dev_attrib_emulate_tas
.attr
,
766 &target_core_dev_attrib_emulate_tpu
.attr
,
767 &target_core_dev_attrib_emulate_tpws
.attr
,
768 &target_core_dev_attrib_enforce_pr_isids
.attr
,
769 &target_core_dev_attrib_hw_block_size
.attr
,
770 &target_core_dev_attrib_block_size
.attr
,
771 &target_core_dev_attrib_hw_max_sectors
.attr
,
772 &target_core_dev_attrib_max_sectors
.attr
,
773 &target_core_dev_attrib_optimal_sectors
.attr
,
774 &target_core_dev_attrib_hw_queue_depth
.attr
,
775 &target_core_dev_attrib_queue_depth
.attr
,
776 &target_core_dev_attrib_task_timeout
.attr
,
777 &target_core_dev_attrib_max_unmap_lba_count
.attr
,
778 &target_core_dev_attrib_max_unmap_block_desc_count
.attr
,
779 &target_core_dev_attrib_unmap_granularity
.attr
,
780 &target_core_dev_attrib_unmap_granularity_alignment
.attr
,
784 static struct configfs_item_operations target_core_dev_attrib_ops
= {
785 .show_attribute
= target_core_dev_attrib_attr_show
,
786 .store_attribute
= target_core_dev_attrib_attr_store
,
789 static struct config_item_type target_core_dev_attrib_cit
= {
790 .ct_item_ops
= &target_core_dev_attrib_ops
,
791 .ct_attrs
= target_core_dev_attrib_attrs
,
792 .ct_owner
= THIS_MODULE
,
795 /* End functions for struct config_item_type target_core_dev_attrib_cit */
797 /* Start functions for struct config_item_type target_core_dev_wwn_cit */
799 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn
, t10_wwn
);
800 #define SE_DEV_WWN_ATTR(_name, _mode) \
801 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
802 __CONFIGFS_EATTR(_name, _mode, \
803 target_core_dev_wwn_show_attr_##_name, \
804 target_core_dev_wwn_store_attr_##_name);
806 #define SE_DEV_WWN_ATTR_RO(_name); \
808 static struct target_core_dev_wwn_attribute \
809 target_core_dev_wwn_##_name = \
810 __CONFIGFS_EATTR_RO(_name, \
811 target_core_dev_wwn_show_attr_##_name); \
815 * VPD page 0x80 Unit serial
817 static ssize_t
target_core_dev_wwn_show_attr_vpd_unit_serial(
818 struct t10_wwn
*t10_wwn
,
821 struct se_subsystem_dev
*se_dev
= t10_wwn
->t10_sub_dev
;
822 struct se_device
*dev
;
824 dev
= se_dev
->se_dev_ptr
;
828 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
829 &t10_wwn
->unit_serial
[0]);
832 static ssize_t
target_core_dev_wwn_store_attr_vpd_unit_serial(
833 struct t10_wwn
*t10_wwn
,
837 struct se_subsystem_dev
*su_dev
= t10_wwn
->t10_sub_dev
;
838 struct se_device
*dev
;
839 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
842 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
843 * from the struct scsi_device level firmware, do not allow
844 * VPD Unit Serial to be emulated.
846 * Note this struct scsi_device could also be emulating VPD
847 * information from its drivers/scsi LLD. But for now we assume
848 * it is doing 'the right thing' wrt a world wide unique
849 * VPD Unit Serial Number that OS dependent multipath can depend on.
851 if (su_dev
->su_dev_flags
& SDF_FIRMWARE_VPD_UNIT_SERIAL
) {
852 printk(KERN_ERR
"Underlying SCSI device firmware provided VPD"
853 " Unit Serial, ignoring request\n");
857 if ((strlen(page
) + 1) > INQUIRY_VPD_SERIAL_LEN
) {
858 printk(KERN_ERR
"Emulated VPD Unit Serial exceeds"
859 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
863 * Check to see if any active $FABRIC_MOD exports exist. If they
864 * do exist, fail here as changing this information on the fly
865 * (underneath the initiator side OS dependent multipath code)
866 * could cause negative effects.
868 dev
= su_dev
->se_dev_ptr
;
870 if (atomic_read(&dev
->dev_export_obj
.obj_access_count
)) {
871 printk(KERN_ERR
"Unable to set VPD Unit Serial while"
872 " active %d $FABRIC_MOD exports exist\n",
873 atomic_read(&dev
->dev_export_obj
.obj_access_count
));
878 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
880 * Also, strip any newline added from the userspace
881 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
883 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
884 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
885 snprintf(su_dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
886 "%s", strstrip(buf
));
887 su_dev
->su_dev_flags
|= SDF_EMULATED_VPD_UNIT_SERIAL
;
889 printk(KERN_INFO
"Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
890 " %s\n", su_dev
->t10_wwn
.unit_serial
);
895 SE_DEV_WWN_ATTR(vpd_unit_serial
, S_IRUGO
| S_IWUSR
);
898 * VPD page 0x83 Protocol Identifier
900 static ssize_t
target_core_dev_wwn_show_attr_vpd_protocol_identifier(
901 struct t10_wwn
*t10_wwn
,
904 struct se_subsystem_dev
*se_dev
= t10_wwn
->t10_sub_dev
;
905 struct se_device
*dev
;
907 unsigned char buf
[VPD_TMP_BUF_SIZE
];
910 dev
= se_dev
->se_dev_ptr
;
914 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
916 spin_lock(&t10_wwn
->t10_vpd_lock
);
917 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
918 if (!(vpd
->protocol_identifier_set
))
921 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
923 if ((len
+ strlen(buf
) > PAGE_SIZE
))
926 len
+= sprintf(page
+len
, "%s", buf
);
928 spin_unlock(&t10_wwn
->t10_vpd_lock
);
933 static ssize_t
target_core_dev_wwn_store_attr_vpd_protocol_identifier(
934 struct t10_wwn
*t10_wwn
,
941 SE_DEV_WWN_ATTR(vpd_protocol_identifier
, S_IRUGO
| S_IWUSR
);
944 * Generic wrapper for dumping VPD identifiers by association.
946 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
947 static ssize_t target_core_dev_wwn_show_attr_##_name( \
948 struct t10_wwn *t10_wwn, \
951 struct se_subsystem_dev *se_dev = t10_wwn->t10_sub_dev; \
952 struct se_device *dev; \
953 struct t10_vpd *vpd; \
954 unsigned char buf[VPD_TMP_BUF_SIZE]; \
957 dev = se_dev->se_dev_ptr; \
961 spin_lock(&t10_wwn->t10_vpd_lock); \
962 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
963 if (vpd->association != _assoc) \
966 memset(buf, 0, VPD_TMP_BUF_SIZE); \
967 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
968 if ((len + strlen(buf) > PAGE_SIZE)) \
970 len += sprintf(page+len, "%s", buf); \
972 memset(buf, 0, VPD_TMP_BUF_SIZE); \
973 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
974 if ((len + strlen(buf) > PAGE_SIZE)) \
976 len += sprintf(page+len, "%s", buf); \
978 memset(buf, 0, VPD_TMP_BUF_SIZE); \
979 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
980 if ((len + strlen(buf) > PAGE_SIZE)) \
982 len += sprintf(page+len, "%s", buf); \
984 spin_unlock(&t10_wwn->t10_vpd_lock); \
990 * VPD page 0x83 Assoication: Logical Unit
992 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
994 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
995 struct t10_wwn
*t10_wwn
,
1002 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit
, S_IRUGO
| S_IWUSR
);
1005 * VPD page 0x83 Association: Target Port
1007 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
1009 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_target_port(
1010 struct t10_wwn
*t10_wwn
,
1017 SE_DEV_WWN_ATTR(vpd_assoc_target_port
, S_IRUGO
| S_IWUSR
);
1020 * VPD page 0x83 Association: SCSI Target Device
1022 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
1024 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
1025 struct t10_wwn
*t10_wwn
,
1032 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device
, S_IRUGO
| S_IWUSR
);
1034 CONFIGFS_EATTR_OPS(target_core_dev_wwn
, t10_wwn
, t10_wwn_group
);
1036 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
1037 &target_core_dev_wwn_vpd_unit_serial
.attr
,
1038 &target_core_dev_wwn_vpd_protocol_identifier
.attr
,
1039 &target_core_dev_wwn_vpd_assoc_logical_unit
.attr
,
1040 &target_core_dev_wwn_vpd_assoc_target_port
.attr
,
1041 &target_core_dev_wwn_vpd_assoc_scsi_target_device
.attr
,
1045 static struct configfs_item_operations target_core_dev_wwn_ops
= {
1046 .show_attribute
= target_core_dev_wwn_attr_show
,
1047 .store_attribute
= target_core_dev_wwn_attr_store
,
1050 static struct config_item_type target_core_dev_wwn_cit
= {
1051 .ct_item_ops
= &target_core_dev_wwn_ops
,
1052 .ct_attrs
= target_core_dev_wwn_attrs
,
1053 .ct_owner
= THIS_MODULE
,
1056 /* End functions for struct config_item_type target_core_dev_wwn_cit */
1058 /* Start functions for struct config_item_type target_core_dev_pr_cit */
1060 CONFIGFS_EATTR_STRUCT(target_core_dev_pr
, se_subsystem_dev
);
1061 #define SE_DEV_PR_ATTR(_name, _mode) \
1062 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1063 __CONFIGFS_EATTR(_name, _mode, \
1064 target_core_dev_pr_show_attr_##_name, \
1065 target_core_dev_pr_store_attr_##_name);
1067 #define SE_DEV_PR_ATTR_RO(_name); \
1068 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1069 __CONFIGFS_EATTR_RO(_name, \
1070 target_core_dev_pr_show_attr_##_name);
1075 static ssize_t
target_core_dev_pr_show_spc3_res(
1076 struct se_device
*dev
,
1080 struct se_node_acl
*se_nacl
;
1081 struct t10_pr_registration
*pr_reg
;
1082 char i_buf
[PR_REG_ISID_ID_LEN
];
1085 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1087 spin_lock(&dev
->dev_reservation_lock
);
1088 pr_reg
= dev
->dev_pr_res_holder
;
1090 *len
+= sprintf(page
+ *len
, "No SPC-3 Reservation holder\n");
1091 spin_unlock(&dev
->dev_reservation_lock
);
1094 se_nacl
= pr_reg
->pr_reg_nacl
;
1095 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1096 PR_REG_ISID_ID_LEN
);
1098 *len
+= sprintf(page
+ *len
, "SPC-3 Reservation: %s Initiator: %s%s\n",
1099 TPG_TFO(se_nacl
->se_tpg
)->get_fabric_name(),
1100 se_nacl
->initiatorname
, (prf_isid
) ? &i_buf
[0] : "");
1101 spin_unlock(&dev
->dev_reservation_lock
);
1106 static ssize_t
target_core_dev_pr_show_spc2_res(
1107 struct se_device
*dev
,
1111 struct se_node_acl
*se_nacl
;
1113 spin_lock(&dev
->dev_reservation_lock
);
1114 se_nacl
= dev
->dev_reserved_node_acl
;
1116 *len
+= sprintf(page
+ *len
, "No SPC-2 Reservation holder\n");
1117 spin_unlock(&dev
->dev_reservation_lock
);
1120 *len
+= sprintf(page
+ *len
, "SPC-2 Reservation: %s Initiator: %s\n",
1121 TPG_TFO(se_nacl
->se_tpg
)->get_fabric_name(),
1122 se_nacl
->initiatorname
);
1123 spin_unlock(&dev
->dev_reservation_lock
);
1128 static ssize_t
target_core_dev_pr_show_attr_res_holder(
1129 struct se_subsystem_dev
*su_dev
,
1134 if (!(su_dev
->se_dev_ptr
))
1137 switch (T10_RES(su_dev
)->res_type
) {
1138 case SPC3_PERSISTENT_RESERVATIONS
:
1139 target_core_dev_pr_show_spc3_res(su_dev
->se_dev_ptr
,
1142 case SPC2_RESERVATIONS
:
1143 target_core_dev_pr_show_spc2_res(su_dev
->se_dev_ptr
,
1146 case SPC_PASSTHROUGH
:
1147 len
+= sprintf(page
+len
, "Passthrough\n");
1150 len
+= sprintf(page
+len
, "Unknown\n");
1157 SE_DEV_PR_ATTR_RO(res_holder
);
1160 * res_pr_all_tgt_pts
1162 static ssize_t
target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1163 struct se_subsystem_dev
*su_dev
,
1166 struct se_device
*dev
;
1167 struct t10_pr_registration
*pr_reg
;
1170 dev
= su_dev
->se_dev_ptr
;
1174 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1177 spin_lock(&dev
->dev_reservation_lock
);
1178 pr_reg
= dev
->dev_pr_res_holder
;
1180 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1181 spin_unlock(&dev
->dev_reservation_lock
);
1185 * See All Target Ports (ALL_TG_PT) bit in spcr17, section 6.14.3
1186 * Basic PERSISTENT RESERVER OUT parameter list, page 290
1188 if (pr_reg
->pr_reg_all_tg_pt
)
1189 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1190 " Ports registration\n");
1192 len
= sprintf(page
, "SPC-3 Reservation: Single"
1193 " Target Port registration\n");
1194 spin_unlock(&dev
->dev_reservation_lock
);
1199 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts
);
1204 static ssize_t
target_core_dev_pr_show_attr_res_pr_generation(
1205 struct se_subsystem_dev
*su_dev
,
1208 if (!(su_dev
->se_dev_ptr
))
1211 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1214 return sprintf(page
, "0x%08x\n", T10_RES(su_dev
)->pr_generation
);
1217 SE_DEV_PR_ATTR_RO(res_pr_generation
);
1220 * res_pr_holder_tg_port
1222 static ssize_t
target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1223 struct se_subsystem_dev
*su_dev
,
1226 struct se_device
*dev
;
1227 struct se_node_acl
*se_nacl
;
1229 struct se_portal_group
*se_tpg
;
1230 struct t10_pr_registration
*pr_reg
;
1231 struct target_core_fabric_ops
*tfo
;
1234 dev
= su_dev
->se_dev_ptr
;
1238 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1241 spin_lock(&dev
->dev_reservation_lock
);
1242 pr_reg
= dev
->dev_pr_res_holder
;
1244 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1245 spin_unlock(&dev
->dev_reservation_lock
);
1248 se_nacl
= pr_reg
->pr_reg_nacl
;
1249 se_tpg
= se_nacl
->se_tpg
;
1250 lun
= pr_reg
->pr_reg_tg_pt_lun
;
1251 tfo
= TPG_TFO(se_tpg
);
1253 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1254 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1255 tfo
->tpg_get_wwn(se_tpg
));
1256 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1257 " Identifer Tag: %hu %s Portal Group Tag: %hu"
1258 " %s Logical Unit: %u\n", lun
->lun_sep
->sep_rtpi
,
1259 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1260 tfo
->get_fabric_name(), lun
->unpacked_lun
);
1261 spin_unlock(&dev
->dev_reservation_lock
);
1266 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port
);
1269 * res_pr_registered_i_pts
1271 static ssize_t
target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1272 struct se_subsystem_dev
*su_dev
,
1275 struct target_core_fabric_ops
*tfo
;
1276 struct t10_pr_registration
*pr_reg
;
1277 unsigned char buf
[384];
1278 char i_buf
[PR_REG_ISID_ID_LEN
];
1280 int reg_count
= 0, prf_isid
;
1282 if (!(su_dev
->se_dev_ptr
))
1285 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1288 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1290 spin_lock(&T10_RES(su_dev
)->registration_lock
);
1291 list_for_each_entry(pr_reg
, &T10_RES(su_dev
)->registration_list
,
1294 memset(buf
, 0, 384);
1295 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1296 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1297 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1298 PR_REG_ISID_ID_LEN
);
1299 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1300 tfo
->get_fabric_name(),
1301 pr_reg
->pr_reg_nacl
->initiatorname
, (prf_isid
) ?
1302 &i_buf
[0] : "", pr_reg
->pr_res_key
,
1303 pr_reg
->pr_res_generation
);
1305 if ((len
+ strlen(buf
) > PAGE_SIZE
))
1308 len
+= sprintf(page
+len
, "%s", buf
);
1311 spin_unlock(&T10_RES(su_dev
)->registration_lock
);
1314 len
+= sprintf(page
+len
, "None\n");
1319 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts
);
1324 static ssize_t
target_core_dev_pr_show_attr_res_pr_type(
1325 struct se_subsystem_dev
*su_dev
,
1328 struct se_device
*dev
;
1329 struct t10_pr_registration
*pr_reg
;
1332 dev
= su_dev
->se_dev_ptr
;
1336 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1339 spin_lock(&dev
->dev_reservation_lock
);
1340 pr_reg
= dev
->dev_pr_res_holder
;
1342 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1343 spin_unlock(&dev
->dev_reservation_lock
);
1346 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1347 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1348 spin_unlock(&dev
->dev_reservation_lock
);
1353 SE_DEV_PR_ATTR_RO(res_pr_type
);
1358 static ssize_t
target_core_dev_pr_show_attr_res_type(
1359 struct se_subsystem_dev
*su_dev
,
1364 if (!(su_dev
->se_dev_ptr
))
1367 switch (T10_RES(su_dev
)->res_type
) {
1368 case SPC3_PERSISTENT_RESERVATIONS
:
1369 len
= sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1371 case SPC2_RESERVATIONS
:
1372 len
= sprintf(page
, "SPC2_RESERVATIONS\n");
1374 case SPC_PASSTHROUGH
:
1375 len
= sprintf(page
, "SPC_PASSTHROUGH\n");
1378 len
= sprintf(page
, "UNKNOWN\n");
1385 SE_DEV_PR_ATTR_RO(res_type
);
1391 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_active(
1392 struct se_subsystem_dev
*su_dev
,
1395 if (!(su_dev
->se_dev_ptr
))
1398 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1401 return sprintf(page
, "APTPL Bit Status: %s\n",
1402 (T10_RES(su_dev
)->pr_aptpl_active
) ? "Activated" : "Disabled");
1405 SE_DEV_PR_ATTR_RO(res_aptpl_active
);
1408 * res_aptpl_metadata
1410 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_metadata(
1411 struct se_subsystem_dev
*su_dev
,
1414 if (!(su_dev
->se_dev_ptr
))
1417 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1420 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1424 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1425 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1426 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1427 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1430 static match_table_t tokens
= {
1431 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1432 {Opt_initiator_node
, "initiator_node=%s"},
1433 {Opt_initiator_sid
, "initiator_sid=%s"},
1434 {Opt_sa_res_key
, "sa_res_key=%s"},
1435 {Opt_res_holder
, "res_holder=%d"},
1436 {Opt_res_type
, "res_type=%d"},
1437 {Opt_res_scope
, "res_scope=%d"},
1438 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1439 {Opt_mapped_lun
, "mapped_lun=%d"},
1440 {Opt_target_fabric
, "target_fabric=%s"},
1441 {Opt_target_node
, "target_node=%s"},
1442 {Opt_tpgt
, "tpgt=%d"},
1443 {Opt_port_rtpi
, "port_rtpi=%d"},
1444 {Opt_target_lun
, "target_lun=%d"},
1448 static ssize_t
target_core_dev_pr_store_attr_res_aptpl_metadata(
1449 struct se_subsystem_dev
*su_dev
,
1453 struct se_device
*dev
;
1454 unsigned char *i_fabric
, *t_fabric
, *i_port
= NULL
, *t_port
= NULL
;
1455 unsigned char *isid
= NULL
;
1456 char *orig
, *ptr
, *arg_p
, *opts
;
1457 substring_t args
[MAX_OPT_ARGS
];
1458 unsigned long long tmp_ll
;
1460 u32 mapped_lun
= 0, target_lun
= 0;
1461 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1462 u16 port_rpti
= 0, tpgt
= 0;
1465 dev
= su_dev
->se_dev_ptr
;
1469 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1472 if (atomic_read(&dev
->dev_export_obj
.obj_access_count
)) {
1473 printk(KERN_INFO
"Unable to process APTPL metadata while"
1474 " active fabric exports exist\n");
1478 opts
= kstrdup(page
, GFP_KERNEL
);
1483 while ((ptr
= strsep(&opts
, ",")) != NULL
) {
1487 token
= match_token(ptr
, tokens
, args
);
1489 case Opt_initiator_fabric
:
1490 i_fabric
= match_strdup(&args
[0]);
1492 case Opt_initiator_node
:
1493 i_port
= match_strdup(&args
[0]);
1494 if (strlen(i_port
) > PR_APTPL_MAX_IPORT_LEN
) {
1495 printk(KERN_ERR
"APTPL metadata initiator_node="
1496 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1497 PR_APTPL_MAX_IPORT_LEN
);
1502 case Opt_initiator_sid
:
1503 isid
= match_strdup(&args
[0]);
1504 if (strlen(isid
) > PR_REG_ISID_LEN
) {
1505 printk(KERN_ERR
"APTPL metadata initiator_isid"
1506 "= exceeds PR_REG_ISID_LEN: %d\n",
1512 case Opt_sa_res_key
:
1513 arg_p
= match_strdup(&args
[0]);
1514 ret
= strict_strtoull(arg_p
, 0, &tmp_ll
);
1516 printk(KERN_ERR
"strict_strtoull() failed for"
1520 sa_res_key
= (u64
)tmp_ll
;
1523 * PR APTPL Metadata for Reservation
1525 case Opt_res_holder
:
1526 match_int(args
, &arg
);
1530 match_int(args
, &arg
);
1534 match_int(args
, &arg
);
1537 case Opt_res_all_tg_pt
:
1538 match_int(args
, &arg
);
1539 all_tg_pt
= (int)arg
;
1541 case Opt_mapped_lun
:
1542 match_int(args
, &arg
);
1543 mapped_lun
= (u32
)arg
;
1546 * PR APTPL Metadata for Target Port
1548 case Opt_target_fabric
:
1549 t_fabric
= match_strdup(&args
[0]);
1551 case Opt_target_node
:
1552 t_port
= match_strdup(&args
[0]);
1553 if (strlen(t_port
) > PR_APTPL_MAX_TPORT_LEN
) {
1554 printk(KERN_ERR
"APTPL metadata target_node="
1555 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1556 PR_APTPL_MAX_TPORT_LEN
);
1562 match_int(args
, &arg
);
1566 match_int(args
, &arg
);
1567 port_rpti
= (u16
)arg
;
1569 case Opt_target_lun
:
1570 match_int(args
, &arg
);
1571 target_lun
= (u32
)arg
;
1578 if (!(i_port
) || !(t_port
) || !(sa_res_key
)) {
1579 printk(KERN_ERR
"Illegal parameters for APTPL registration\n");
1584 if (res_holder
&& !(type
)) {
1585 printk(KERN_ERR
"Illegal PR type: 0x%02x for reservation"
1591 ret
= core_scsi3_alloc_aptpl_registration(T10_RES(su_dev
), sa_res_key
,
1592 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1593 res_holder
, all_tg_pt
, type
);
1596 return (ret
== 0) ? count
: ret
;
1599 SE_DEV_PR_ATTR(res_aptpl_metadata
, S_IRUGO
| S_IWUSR
);
1601 CONFIGFS_EATTR_OPS(target_core_dev_pr
, se_subsystem_dev
, se_dev_pr_group
);
1603 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1604 &target_core_dev_pr_res_holder
.attr
,
1605 &target_core_dev_pr_res_pr_all_tgt_pts
.attr
,
1606 &target_core_dev_pr_res_pr_generation
.attr
,
1607 &target_core_dev_pr_res_pr_holder_tg_port
.attr
,
1608 &target_core_dev_pr_res_pr_registered_i_pts
.attr
,
1609 &target_core_dev_pr_res_pr_type
.attr
,
1610 &target_core_dev_pr_res_type
.attr
,
1611 &target_core_dev_pr_res_aptpl_active
.attr
,
1612 &target_core_dev_pr_res_aptpl_metadata
.attr
,
1616 static struct configfs_item_operations target_core_dev_pr_ops
= {
1617 .show_attribute
= target_core_dev_pr_attr_show
,
1618 .store_attribute
= target_core_dev_pr_attr_store
,
1621 static struct config_item_type target_core_dev_pr_cit
= {
1622 .ct_item_ops
= &target_core_dev_pr_ops
,
1623 .ct_attrs
= target_core_dev_pr_attrs
,
1624 .ct_owner
= THIS_MODULE
,
1627 /* End functions for struct config_item_type target_core_dev_pr_cit */
1629 /* Start functions for struct config_item_type target_core_dev_cit */
1631 static ssize_t
target_core_show_dev_info(void *p
, char *page
)
1633 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1634 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1635 struct se_subsystem_api
*t
= hba
->transport
;
1637 ssize_t read_bytes
= 0;
1639 if (!(se_dev
->se_dev_ptr
))
1642 transport_dump_dev_state(se_dev
->se_dev_ptr
, page
, &bl
);
1644 read_bytes
+= t
->show_configfs_dev_params(hba
, se_dev
, page
+read_bytes
);
1648 static struct target_core_configfs_attribute target_core_attr_dev_info
= {
1649 .attr
= { .ca_owner
= THIS_MODULE
,
1651 .ca_mode
= S_IRUGO
},
1652 .show
= target_core_show_dev_info
,
1656 static ssize_t
target_core_store_dev_control(
1661 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1662 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1663 struct se_subsystem_api
*t
= hba
->transport
;
1665 if (!(se_dev
->se_dev_su_ptr
)) {
1666 printk(KERN_ERR
"Unable to locate struct se_subsystem_dev>se"
1671 return t
->set_configfs_dev_params(hba
, se_dev
, page
, count
);
1674 static struct target_core_configfs_attribute target_core_attr_dev_control
= {
1675 .attr
= { .ca_owner
= THIS_MODULE
,
1676 .ca_name
= "control",
1677 .ca_mode
= S_IWUSR
},
1679 .store
= target_core_store_dev_control
,
1682 static ssize_t
target_core_show_dev_alias(void *p
, char *page
)
1684 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1686 if (!(se_dev
->su_dev_flags
& SDF_USING_ALIAS
))
1689 return snprintf(page
, PAGE_SIZE
, "%s\n", se_dev
->se_dev_alias
);
1692 static ssize_t
target_core_store_dev_alias(
1697 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1698 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1701 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1702 printk(KERN_ERR
"alias count: %d exceeds"
1703 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1704 SE_DEV_ALIAS_LEN
-1);
1708 se_dev
->su_dev_flags
|= SDF_USING_ALIAS
;
1709 read_bytes
= snprintf(&se_dev
->se_dev_alias
[0], SE_DEV_ALIAS_LEN
,
1712 printk(KERN_INFO
"Target_Core_ConfigFS: %s/%s set alias: %s\n",
1713 config_item_name(&hba
->hba_group
.cg_item
),
1714 config_item_name(&se_dev
->se_dev_group
.cg_item
),
1715 se_dev
->se_dev_alias
);
1720 static struct target_core_configfs_attribute target_core_attr_dev_alias
= {
1721 .attr
= { .ca_owner
= THIS_MODULE
,
1723 .ca_mode
= S_IRUGO
| S_IWUSR
},
1724 .show
= target_core_show_dev_alias
,
1725 .store
= target_core_store_dev_alias
,
1728 static ssize_t
target_core_show_dev_udev_path(void *p
, char *page
)
1730 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1732 if (!(se_dev
->su_dev_flags
& SDF_USING_UDEV_PATH
))
1735 return snprintf(page
, PAGE_SIZE
, "%s\n", se_dev
->se_dev_udev_path
);
1738 static ssize_t
target_core_store_dev_udev_path(
1743 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1744 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1747 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1748 printk(KERN_ERR
"udev_path count: %d exceeds"
1749 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1750 SE_UDEV_PATH_LEN
-1);
1754 se_dev
->su_dev_flags
|= SDF_USING_UDEV_PATH
;
1755 read_bytes
= snprintf(&se_dev
->se_dev_udev_path
[0], SE_UDEV_PATH_LEN
,
1758 printk(KERN_INFO
"Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1759 config_item_name(&hba
->hba_group
.cg_item
),
1760 config_item_name(&se_dev
->se_dev_group
.cg_item
),
1761 se_dev
->se_dev_udev_path
);
1766 static struct target_core_configfs_attribute target_core_attr_dev_udev_path
= {
1767 .attr
= { .ca_owner
= THIS_MODULE
,
1768 .ca_name
= "udev_path",
1769 .ca_mode
= S_IRUGO
| S_IWUSR
},
1770 .show
= target_core_show_dev_udev_path
,
1771 .store
= target_core_store_dev_udev_path
,
1774 static ssize_t
target_core_store_dev_enable(
1779 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1780 struct se_device
*dev
;
1781 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1782 struct se_subsystem_api
*t
= hba
->transport
;
1785 ptr
= strstr(page
, "1");
1787 printk(KERN_ERR
"For dev_enable ops, only valid value"
1791 if ((se_dev
->se_dev_ptr
)) {
1792 printk(KERN_ERR
"se_dev->se_dev_ptr already set for storage"
1797 if (t
->check_configfs_dev_params(hba
, se_dev
) < 0)
1800 dev
= t
->create_virtdevice(hba
, se_dev
, se_dev
->se_dev_su_ptr
);
1801 if (!(dev
) || IS_ERR(dev
))
1804 se_dev
->se_dev_ptr
= dev
;
1805 printk(KERN_INFO
"Target_Core_ConfigFS: Registered se_dev->se_dev_ptr:"
1806 " %p\n", se_dev
->se_dev_ptr
);
1811 static struct target_core_configfs_attribute target_core_attr_dev_enable
= {
1812 .attr
= { .ca_owner
= THIS_MODULE
,
1813 .ca_name
= "enable",
1814 .ca_mode
= S_IWUSR
},
1816 .store
= target_core_store_dev_enable
,
1819 static ssize_t
target_core_show_alua_lu_gp(void *p
, char *page
)
1821 struct se_device
*dev
;
1822 struct se_subsystem_dev
*su_dev
= (struct se_subsystem_dev
*)p
;
1823 struct config_item
*lu_ci
;
1824 struct t10_alua_lu_gp
*lu_gp
;
1825 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1828 dev
= su_dev
->se_dev_ptr
;
1832 if (T10_ALUA(su_dev
)->alua_type
!= SPC3_ALUA_EMULATED
)
1835 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1837 printk(KERN_ERR
"NULL struct se_device->dev_alua_lu_gp_mem"
1842 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1843 lu_gp
= lu_gp_mem
->lu_gp
;
1845 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1846 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1847 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1849 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1854 static ssize_t
target_core_store_alua_lu_gp(
1859 struct se_device
*dev
;
1860 struct se_subsystem_dev
*su_dev
= (struct se_subsystem_dev
*)p
;
1861 struct se_hba
*hba
= su_dev
->se_dev_hba
;
1862 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1863 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1864 unsigned char buf
[LU_GROUP_NAME_BUF
];
1867 dev
= su_dev
->se_dev_ptr
;
1871 if (T10_ALUA(su_dev
)->alua_type
!= SPC3_ALUA_EMULATED
) {
1872 printk(KERN_WARNING
"SPC3_ALUA_EMULATED not enabled for %s/%s\n",
1873 config_item_name(&hba
->hba_group
.cg_item
),
1874 config_item_name(&su_dev
->se_dev_group
.cg_item
));
1877 if (count
> LU_GROUP_NAME_BUF
) {
1878 printk(KERN_ERR
"ALUA LU Group Alias too large!\n");
1881 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1882 memcpy(buf
, page
, count
);
1884 * Any ALUA logical unit alias besides "NULL" means we will be
1885 * making a new group association.
1887 if (strcmp(strstrip(buf
), "NULL")) {
1889 * core_alua_get_lu_gp_by_name() will increment reference to
1890 * struct t10_alua_lu_gp. This reference is released with
1891 * core_alua_get_lu_gp_by_name below().
1893 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
1897 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1900 core_alua_put_lu_gp_from_name(lu_gp_new
);
1901 printk(KERN_ERR
"NULL struct se_device->dev_alua_lu_gp_mem"
1906 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1907 lu_gp
= lu_gp_mem
->lu_gp
;
1910 * Clearing an existing lu_gp association, and replacing
1914 printk(KERN_INFO
"Target_Core_ConfigFS: Releasing %s/%s"
1915 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1917 config_item_name(&hba
->hba_group
.cg_item
),
1918 config_item_name(&su_dev
->se_dev_group
.cg_item
),
1919 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1922 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1923 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1928 * Removing existing association of lu_gp_mem with lu_gp
1930 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1934 * Associate lu_gp_mem with lu_gp_new.
1936 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
1937 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1939 printk(KERN_INFO
"Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1940 " core/alua/lu_gps/%s, ID: %hu\n",
1941 (move
) ? "Moving" : "Adding",
1942 config_item_name(&hba
->hba_group
.cg_item
),
1943 config_item_name(&su_dev
->se_dev_group
.cg_item
),
1944 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
1945 lu_gp_new
->lu_gp_id
);
1947 core_alua_put_lu_gp_from_name(lu_gp_new
);
1951 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp
= {
1952 .attr
= { .ca_owner
= THIS_MODULE
,
1953 .ca_name
= "alua_lu_gp",
1954 .ca_mode
= S_IRUGO
| S_IWUSR
},
1955 .show
= target_core_show_alua_lu_gp
,
1956 .store
= target_core_store_alua_lu_gp
,
1959 static struct configfs_attribute
*lio_core_dev_attrs
[] = {
1960 &target_core_attr_dev_info
.attr
,
1961 &target_core_attr_dev_control
.attr
,
1962 &target_core_attr_dev_alias
.attr
,
1963 &target_core_attr_dev_udev_path
.attr
,
1964 &target_core_attr_dev_enable
.attr
,
1965 &target_core_attr_dev_alua_lu_gp
.attr
,
1969 static void target_core_dev_release(struct config_item
*item
)
1971 struct se_subsystem_dev
*se_dev
= container_of(to_config_group(item
),
1972 struct se_subsystem_dev
, se_dev_group
);
1973 struct se_hba
*hba
= item_to_hba(&se_dev
->se_dev_hba
->hba_group
.cg_item
);
1974 struct se_subsystem_api
*t
= hba
->transport
;
1975 struct config_group
*dev_cg
= &se_dev
->se_dev_group
;
1977 kfree(dev_cg
->default_groups
);
1979 * This pointer will set when the storage is enabled with:
1980 *`echo 1 > $CONFIGFS/core/$HBA/$DEV/dev_enable`
1982 if (se_dev
->se_dev_ptr
) {
1983 printk(KERN_INFO
"Target_Core_ConfigFS: Calling se_free_"
1984 "virtual_device() for se_dev_ptr: %p\n",
1985 se_dev
->se_dev_ptr
);
1987 se_free_virtual_device(se_dev
->se_dev_ptr
, hba
);
1990 * Release struct se_subsystem_dev->se_dev_su_ptr..
1992 printk(KERN_INFO
"Target_Core_ConfigFS: Calling t->free_"
1993 "device() for se_dev_su_ptr: %p\n",
1994 se_dev
->se_dev_su_ptr
);
1996 t
->free_device(se_dev
->se_dev_su_ptr
);
1999 printk(KERN_INFO
"Target_Core_ConfigFS: Deallocating se_subsystem"
2000 "_dev_t: %p\n", se_dev
);
2004 static ssize_t
target_core_dev_show(struct config_item
*item
,
2005 struct configfs_attribute
*attr
,
2008 struct se_subsystem_dev
*se_dev
= container_of(
2009 to_config_group(item
), struct se_subsystem_dev
,
2011 struct target_core_configfs_attribute
*tc_attr
= container_of(
2012 attr
, struct target_core_configfs_attribute
, attr
);
2014 if (!(tc_attr
->show
))
2017 return tc_attr
->show((void *)se_dev
, page
);
2020 static ssize_t
target_core_dev_store(struct config_item
*item
,
2021 struct configfs_attribute
*attr
,
2022 const char *page
, size_t count
)
2024 struct se_subsystem_dev
*se_dev
= container_of(
2025 to_config_group(item
), struct se_subsystem_dev
,
2027 struct target_core_configfs_attribute
*tc_attr
= container_of(
2028 attr
, struct target_core_configfs_attribute
, attr
);
2030 if (!(tc_attr
->store
))
2033 return tc_attr
->store((void *)se_dev
, page
, count
);
2036 static struct configfs_item_operations target_core_dev_item_ops
= {
2037 .release
= target_core_dev_release
,
2038 .show_attribute
= target_core_dev_show
,
2039 .store_attribute
= target_core_dev_store
,
2042 static struct config_item_type target_core_dev_cit
= {
2043 .ct_item_ops
= &target_core_dev_item_ops
,
2044 .ct_attrs
= lio_core_dev_attrs
,
2045 .ct_owner
= THIS_MODULE
,
2048 /* End functions for struct config_item_type target_core_dev_cit */
2050 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
2052 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp
, t10_alua_lu_gp
);
2053 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
2054 static struct target_core_alua_lu_gp_attribute \
2055 target_core_alua_lu_gp_##_name = \
2056 __CONFIGFS_EATTR(_name, _mode, \
2057 target_core_alua_lu_gp_show_attr_##_name, \
2058 target_core_alua_lu_gp_store_attr_##_name);
2060 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
2061 static struct target_core_alua_lu_gp_attribute \
2062 target_core_alua_lu_gp_##_name = \
2063 __CONFIGFS_EATTR_RO(_name, \
2064 target_core_alua_lu_gp_show_attr_##_name);
2069 static ssize_t
target_core_alua_lu_gp_show_attr_lu_gp_id(
2070 struct t10_alua_lu_gp
*lu_gp
,
2073 if (!(lu_gp
->lu_gp_valid_id
))
2076 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
2079 static ssize_t
target_core_alua_lu_gp_store_attr_lu_gp_id(
2080 struct t10_alua_lu_gp
*lu_gp
,
2084 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2085 unsigned long lu_gp_id
;
2088 ret
= strict_strtoul(page
, 0, &lu_gp_id
);
2090 printk(KERN_ERR
"strict_strtoul() returned %d for"
2091 " lu_gp_id\n", ret
);
2094 if (lu_gp_id
> 0x0000ffff) {
2095 printk(KERN_ERR
"ALUA lu_gp_id: %lu exceeds maximum:"
2096 " 0x0000ffff\n", lu_gp_id
);
2100 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
2104 printk(KERN_INFO
"Target_Core_ConfigFS: Set ALUA Logical Unit"
2105 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2106 config_item_name(&alua_lu_gp_cg
->cg_item
),
2112 SE_DEV_ALUA_LU_ATTR(lu_gp_id
, S_IRUGO
| S_IWUSR
);
2117 static ssize_t
target_core_alua_lu_gp_show_attr_members(
2118 struct t10_alua_lu_gp
*lu_gp
,
2121 struct se_device
*dev
;
2123 struct se_subsystem_dev
*su_dev
;
2124 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2125 ssize_t len
= 0, cur_len
;
2126 unsigned char buf
[LU_GROUP_NAME_BUF
];
2128 memset(buf
, 0, LU_GROUP_NAME_BUF
);
2130 spin_lock(&lu_gp
->lu_gp_lock
);
2131 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
2132 dev
= lu_gp_mem
->lu_gp_mem_dev
;
2133 su_dev
= dev
->se_sub_dev
;
2134 hba
= su_dev
->se_dev_hba
;
2136 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
2137 config_item_name(&hba
->hba_group
.cg_item
),
2138 config_item_name(&su_dev
->se_dev_group
.cg_item
));
2139 cur_len
++; /* Extra byte for NULL terminator */
2141 if ((cur_len
+ len
) > PAGE_SIZE
) {
2142 printk(KERN_WARNING
"Ran out of lu_gp_show_attr"
2143 "_members buffer\n");
2146 memcpy(page
+len
, buf
, cur_len
);
2149 spin_unlock(&lu_gp
->lu_gp_lock
);
2154 SE_DEV_ALUA_LU_ATTR_RO(members
);
2156 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp
, t10_alua_lu_gp
, lu_gp_group
);
2158 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
2159 &target_core_alua_lu_gp_lu_gp_id
.attr
,
2160 &target_core_alua_lu_gp_members
.attr
,
2164 static void target_core_alua_lu_gp_release(struct config_item
*item
)
2166 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2167 struct t10_alua_lu_gp
, lu_gp_group
);
2169 core_alua_free_lu_gp(lu_gp
);
2172 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
2173 .release
= target_core_alua_lu_gp_release
,
2174 .show_attribute
= target_core_alua_lu_gp_attr_show
,
2175 .store_attribute
= target_core_alua_lu_gp_attr_store
,
2178 static struct config_item_type target_core_alua_lu_gp_cit
= {
2179 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
2180 .ct_attrs
= target_core_alua_lu_gp_attrs
,
2181 .ct_owner
= THIS_MODULE
,
2184 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
2186 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
2188 static struct config_group
*target_core_alua_create_lu_gp(
2189 struct config_group
*group
,
2192 struct t10_alua_lu_gp
*lu_gp
;
2193 struct config_group
*alua_lu_gp_cg
= NULL
;
2194 struct config_item
*alua_lu_gp_ci
= NULL
;
2196 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
2200 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2201 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
2203 config_group_init_type_name(alua_lu_gp_cg
, name
,
2204 &target_core_alua_lu_gp_cit
);
2206 printk(KERN_INFO
"Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2207 " Group: core/alua/lu_gps/%s\n",
2208 config_item_name(alua_lu_gp_ci
));
2210 return alua_lu_gp_cg
;
2214 static void target_core_alua_drop_lu_gp(
2215 struct config_group
*group
,
2216 struct config_item
*item
)
2218 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2219 struct t10_alua_lu_gp
, lu_gp_group
);
2221 printk(KERN_INFO
"Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2222 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2223 config_item_name(item
), lu_gp
->lu_gp_id
);
2225 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
2226 * -> target_core_alua_lu_gp_release()
2228 config_item_put(item
);
2231 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
2232 .make_group
= &target_core_alua_create_lu_gp
,
2233 .drop_item
= &target_core_alua_drop_lu_gp
,
2236 static struct config_item_type target_core_alua_lu_gps_cit
= {
2237 .ct_item_ops
= NULL
,
2238 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
2239 .ct_owner
= THIS_MODULE
,
2242 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
2244 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2246 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
);
2247 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
2248 static struct target_core_alua_tg_pt_gp_attribute \
2249 target_core_alua_tg_pt_gp_##_name = \
2250 __CONFIGFS_EATTR(_name, _mode, \
2251 target_core_alua_tg_pt_gp_show_attr_##_name, \
2252 target_core_alua_tg_pt_gp_store_attr_##_name);
2254 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2255 static struct target_core_alua_tg_pt_gp_attribute \
2256 target_core_alua_tg_pt_gp_##_name = \
2257 __CONFIGFS_EATTR_RO(_name, \
2258 target_core_alua_tg_pt_gp_show_attr_##_name);
2263 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2264 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2267 return sprintf(page
, "%d\n",
2268 atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
));
2271 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2272 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2276 struct se_subsystem_dev
*su_dev
= tg_pt_gp
->tg_pt_gp_su_dev
;
2280 if (!(tg_pt_gp
->tg_pt_gp_valid_id
)) {
2281 printk(KERN_ERR
"Unable to do implict ALUA on non valid"
2282 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2286 ret
= strict_strtoul(page
, 0, &tmp
);
2288 printk("Unable to extract new ALUA access state from"
2292 new_state
= (int)tmp
;
2294 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICT_ALUA
)) {
2295 printk(KERN_ERR
"Unable to process implict configfs ALUA"
2296 " transition while TPGS_IMPLICT_ALUA is diabled\n");
2300 ret
= core_alua_do_port_transition(tg_pt_gp
, su_dev
->se_dev_ptr
,
2301 NULL
, NULL
, new_state
, 0);
2302 return (!ret
) ? count
: -EINVAL
;
2305 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state
, S_IRUGO
| S_IWUSR
);
2308 * alua_access_status
2310 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2311 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2314 return sprintf(page
, "%s\n",
2315 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2318 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2319 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2324 int new_status
, ret
;
2326 if (!(tg_pt_gp
->tg_pt_gp_valid_id
)) {
2327 printk(KERN_ERR
"Unable to do set ALUA access status on non"
2328 " valid tg_pt_gp ID: %hu\n",
2329 tg_pt_gp
->tg_pt_gp_valid_id
);
2333 ret
= strict_strtoul(page
, 0, &tmp
);
2335 printk(KERN_ERR
"Unable to extract new ALUA access status"
2336 " from %s\n", page
);
2339 new_status
= (int)tmp
;
2341 if ((new_status
!= ALUA_STATUS_NONE
) &&
2342 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
) &&
2343 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
)) {
2344 printk(KERN_ERR
"Illegal ALUA access status: 0x%02x\n",
2349 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2353 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status
, S_IRUGO
| S_IWUSR
);
2358 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2359 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2362 return core_alua_show_access_type(tg_pt_gp
, page
);
2365 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2366 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2370 return core_alua_store_access_type(tg_pt_gp
, page
, count
);
2373 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type
, S_IRUGO
| S_IWUSR
);
2376 * alua_write_metadata
2378 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2379 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2382 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_write_metadata
);
2385 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2386 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2393 ret
= strict_strtoul(page
, 0, &tmp
);
2395 printk(KERN_ERR
"Unable to extract alua_write_metadata\n");
2399 if ((tmp
!= 0) && (tmp
!= 1)) {
2400 printk(KERN_ERR
"Illegal value for alua_write_metadata:"
2404 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2409 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata
, S_IRUGO
| S_IWUSR
);
2416 static ssize_t
target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2417 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2420 return core_alua_show_nonop_delay_msecs(tg_pt_gp
, page
);
2424 static ssize_t
target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2425 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2429 return core_alua_store_nonop_delay_msecs(tg_pt_gp
, page
, count
);
2432 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs
, S_IRUGO
| S_IWUSR
);
2437 static ssize_t
target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2438 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2441 return core_alua_show_trans_delay_msecs(tg_pt_gp
, page
);
2444 static ssize_t
target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2445 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2449 return core_alua_store_trans_delay_msecs(tg_pt_gp
, page
, count
);
2452 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs
, S_IRUGO
| S_IWUSR
);
2458 static ssize_t
target_core_alua_tg_pt_gp_show_attr_preferred(
2459 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2462 return core_alua_show_preferred_bit(tg_pt_gp
, page
);
2465 static ssize_t
target_core_alua_tg_pt_gp_store_attr_preferred(
2466 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2470 return core_alua_store_preferred_bit(tg_pt_gp
, page
, count
);
2473 SE_DEV_ALUA_TG_PT_ATTR(preferred
, S_IRUGO
| S_IWUSR
);
2478 static ssize_t
target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2479 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2482 if (!(tg_pt_gp
->tg_pt_gp_valid_id
))
2485 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2488 static ssize_t
target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2489 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2493 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2494 unsigned long tg_pt_gp_id
;
2497 ret
= strict_strtoul(page
, 0, &tg_pt_gp_id
);
2499 printk(KERN_ERR
"strict_strtoul() returned %d for"
2500 " tg_pt_gp_id\n", ret
);
2503 if (tg_pt_gp_id
> 0x0000ffff) {
2504 printk(KERN_ERR
"ALUA tg_pt_gp_id: %lu exceeds maximum:"
2505 " 0x0000ffff\n", tg_pt_gp_id
);
2509 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2513 printk(KERN_INFO
"Target_Core_ConfigFS: Set ALUA Target Port Group: "
2514 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2515 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2516 tg_pt_gp
->tg_pt_gp_id
);
2521 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id
, S_IRUGO
| S_IWUSR
);
2526 static ssize_t
target_core_alua_tg_pt_gp_show_attr_members(
2527 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2530 struct se_port
*port
;
2531 struct se_portal_group
*tpg
;
2533 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
2534 ssize_t len
= 0, cur_len
;
2535 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2537 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2539 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2540 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
2541 tg_pt_gp_mem_list
) {
2542 port
= tg_pt_gp_mem
->tg_pt
;
2543 tpg
= port
->sep_tpg
;
2544 lun
= port
->sep_lun
;
2546 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2547 "/%s\n", TPG_TFO(tpg
)->get_fabric_name(),
2548 TPG_TFO(tpg
)->tpg_get_wwn(tpg
),
2549 TPG_TFO(tpg
)->tpg_get_tag(tpg
),
2550 config_item_name(&lun
->lun_group
.cg_item
));
2551 cur_len
++; /* Extra byte for NULL terminator */
2553 if ((cur_len
+ len
) > PAGE_SIZE
) {
2554 printk(KERN_WARNING
"Ran out of lu_gp_show_attr"
2555 "_members buffer\n");
2558 memcpy(page
+len
, buf
, cur_len
);
2561 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2566 SE_DEV_ALUA_TG_PT_ATTR_RO(members
);
2568 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
,
2571 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2572 &target_core_alua_tg_pt_gp_alua_access_state
.attr
,
2573 &target_core_alua_tg_pt_gp_alua_access_status
.attr
,
2574 &target_core_alua_tg_pt_gp_alua_access_type
.attr
,
2575 &target_core_alua_tg_pt_gp_alua_write_metadata
.attr
,
2576 &target_core_alua_tg_pt_gp_nonop_delay_msecs
.attr
,
2577 &target_core_alua_tg_pt_gp_trans_delay_msecs
.attr
,
2578 &target_core_alua_tg_pt_gp_preferred
.attr
,
2579 &target_core_alua_tg_pt_gp_tg_pt_gp_id
.attr
,
2580 &target_core_alua_tg_pt_gp_members
.attr
,
2584 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2586 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2587 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2589 core_alua_free_tg_pt_gp(tg_pt_gp
);
2592 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2593 .release
= target_core_alua_tg_pt_gp_release
,
2594 .show_attribute
= target_core_alua_tg_pt_gp_attr_show
,
2595 .store_attribute
= target_core_alua_tg_pt_gp_attr_store
,
2598 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2599 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2600 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2601 .ct_owner
= THIS_MODULE
,
2604 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2606 /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2608 static struct config_group
*target_core_alua_create_tg_pt_gp(
2609 struct config_group
*group
,
2612 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2613 alua_tg_pt_gps_group
);
2614 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2615 struct se_subsystem_dev
*su_dev
= alua
->t10_sub_dev
;
2616 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2617 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2619 tg_pt_gp
= core_alua_allocate_tg_pt_gp(su_dev
, name
, 0);
2623 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2624 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2626 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2627 &target_core_alua_tg_pt_gp_cit
);
2629 printk(KERN_INFO
"Target_Core_ConfigFS: Allocated ALUA Target Port"
2630 " Group: alua/tg_pt_gps/%s\n",
2631 config_item_name(alua_tg_pt_gp_ci
));
2633 return alua_tg_pt_gp_cg
;
2636 static void target_core_alua_drop_tg_pt_gp(
2637 struct config_group
*group
,
2638 struct config_item
*item
)
2640 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2641 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2643 printk(KERN_INFO
"Target_Core_ConfigFS: Releasing ALUA Target Port"
2644 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2645 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2647 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2648 * -> target_core_alua_tg_pt_gp_release().
2650 config_item_put(item
);
2653 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2654 .make_group
= &target_core_alua_create_tg_pt_gp
,
2655 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2658 static struct config_item_type target_core_alua_tg_pt_gps_cit
= {
2659 .ct_group_ops
= &target_core_alua_tg_pt_gps_group_ops
,
2660 .ct_owner
= THIS_MODULE
,
2663 /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2665 /* Start functions for struct config_item_type target_core_alua_cit */
2668 * target_core_alua_cit is a ConfigFS group that lives under
2669 * /sys/kernel/config/target/core/alua. There are default groups
2670 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2671 * target_core_alua_cit in target_core_init_configfs() below.
2673 static struct config_item_type target_core_alua_cit
= {
2674 .ct_item_ops
= NULL
,
2676 .ct_owner
= THIS_MODULE
,
2679 /* End functions for struct config_item_type target_core_alua_cit */
2681 /* Start functions for struct config_item_type target_core_hba_cit */
2683 static struct config_group
*target_core_make_subdev(
2684 struct config_group
*group
,
2687 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2688 struct se_subsystem_dev
*se_dev
;
2689 struct se_subsystem_api
*t
;
2690 struct config_item
*hba_ci
= &group
->cg_item
;
2691 struct se_hba
*hba
= item_to_hba(hba_ci
);
2692 struct config_group
*dev_cg
= NULL
, *tg_pt_gp_cg
= NULL
;
2694 if (mutex_lock_interruptible(&hba
->hba_access_mutex
))
2698 * Locate the struct se_subsystem_api from parent's struct se_hba.
2702 se_dev
= kzalloc(sizeof(struct se_subsystem_dev
), GFP_KERNEL
);
2704 printk(KERN_ERR
"Unable to allocate memory for"
2705 " struct se_subsystem_dev\n");
2708 INIT_LIST_HEAD(&se_dev
->g_se_dev_list
);
2709 INIT_LIST_HEAD(&se_dev
->t10_wwn
.t10_vpd_list
);
2710 spin_lock_init(&se_dev
->t10_wwn
.t10_vpd_lock
);
2711 INIT_LIST_HEAD(&se_dev
->t10_reservation
.registration_list
);
2712 INIT_LIST_HEAD(&se_dev
->t10_reservation
.aptpl_reg_list
);
2713 spin_lock_init(&se_dev
->t10_reservation
.registration_lock
);
2714 spin_lock_init(&se_dev
->t10_reservation
.aptpl_reg_lock
);
2715 INIT_LIST_HEAD(&se_dev
->t10_alua
.tg_pt_gps_list
);
2716 spin_lock_init(&se_dev
->t10_alua
.tg_pt_gps_lock
);
2717 spin_lock_init(&se_dev
->se_dev_lock
);
2718 se_dev
->t10_reservation
.pr_aptpl_buf_len
= PR_APTPL_BUF_LEN
;
2719 se_dev
->t10_wwn
.t10_sub_dev
= se_dev
;
2720 se_dev
->t10_alua
.t10_sub_dev
= se_dev
;
2721 se_dev
->se_dev_attrib
.da_sub_dev
= se_dev
;
2723 se_dev
->se_dev_hba
= hba
;
2724 dev_cg
= &se_dev
->se_dev_group
;
2726 dev_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 6,
2728 if (!(dev_cg
->default_groups
))
2731 * Set se_dev_su_ptr from struct se_subsystem_api returned void ptr
2732 * for ->allocate_virtdevice()
2734 * se_dev->se_dev_ptr will be set after ->create_virtdev()
2735 * has been called successfully in the next level up in the
2736 * configfs tree for device object's struct config_group.
2738 se_dev
->se_dev_su_ptr
= t
->allocate_virtdevice(hba
, name
);
2739 if (!(se_dev
->se_dev_su_ptr
)) {
2740 printk(KERN_ERR
"Unable to locate subsystem dependent pointer"
2741 " from allocate_virtdevice()\n");
2744 spin_lock(&se_global
->g_device_lock
);
2745 list_add_tail(&se_dev
->g_se_dev_list
, &se_global
->g_se_dev_list
);
2746 spin_unlock(&se_global
->g_device_lock
);
2748 config_group_init_type_name(&se_dev
->se_dev_group
, name
,
2749 &target_core_dev_cit
);
2750 config_group_init_type_name(&se_dev
->se_dev_attrib
.da_group
, "attrib",
2751 &target_core_dev_attrib_cit
);
2752 config_group_init_type_name(&se_dev
->se_dev_pr_group
, "pr",
2753 &target_core_dev_pr_cit
);
2754 config_group_init_type_name(&se_dev
->t10_wwn
.t10_wwn_group
, "wwn",
2755 &target_core_dev_wwn_cit
);
2756 config_group_init_type_name(&se_dev
->t10_alua
.alua_tg_pt_gps_group
,
2757 "alua", &target_core_alua_tg_pt_gps_cit
);
2758 dev_cg
->default_groups
[0] = &se_dev
->se_dev_attrib
.da_group
;
2759 dev_cg
->default_groups
[1] = &se_dev
->se_dev_pr_group
;
2760 dev_cg
->default_groups
[2] = &se_dev
->t10_wwn
.t10_wwn_group
;
2761 dev_cg
->default_groups
[3] = &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2762 dev_cg
->default_groups
[4] = NULL
;
2764 * Add core/$HBA/$DEV/alua/tg_pt_gps/default_tg_pt_gp
2766 tg_pt_gp
= core_alua_allocate_tg_pt_gp(se_dev
, "default_tg_pt_gp", 1);
2770 tg_pt_gp_cg
= &T10_ALUA(se_dev
)->alua_tg_pt_gps_group
;
2771 tg_pt_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
2773 if (!(tg_pt_gp_cg
->default_groups
)) {
2774 printk(KERN_ERR
"Unable to allocate tg_pt_gp_cg->"
2775 "default_groups\n");
2779 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2780 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2781 tg_pt_gp_cg
->default_groups
[0] = &tg_pt_gp
->tg_pt_gp_group
;
2782 tg_pt_gp_cg
->default_groups
[1] = NULL
;
2783 T10_ALUA(se_dev
)->default_tg_pt_gp
= tg_pt_gp
;
2785 printk(KERN_INFO
"Target_Core_ConfigFS: Allocated struct se_subsystem_dev:"
2786 " %p se_dev_su_ptr: %p\n", se_dev
, se_dev
->se_dev_su_ptr
);
2788 mutex_unlock(&hba
->hba_access_mutex
);
2789 return &se_dev
->se_dev_group
;
2791 if (T10_ALUA(se_dev
)->default_tg_pt_gp
) {
2792 core_alua_free_tg_pt_gp(T10_ALUA(se_dev
)->default_tg_pt_gp
);
2793 T10_ALUA(se_dev
)->default_tg_pt_gp
= NULL
;
2796 kfree(tg_pt_gp_cg
->default_groups
);
2798 kfree(dev_cg
->default_groups
);
2799 if (se_dev
->se_dev_su_ptr
)
2800 t
->free_device(se_dev
->se_dev_su_ptr
);
2803 mutex_unlock(&hba
->hba_access_mutex
);
2807 static void target_core_drop_subdev(
2808 struct config_group
*group
,
2809 struct config_item
*item
)
2811 struct se_subsystem_dev
*se_dev
= container_of(to_config_group(item
),
2812 struct se_subsystem_dev
, se_dev_group
);
2814 struct se_subsystem_api
*t
;
2815 struct config_item
*df_item
;
2816 struct config_group
*dev_cg
, *tg_pt_gp_cg
;
2819 hba
= item_to_hba(&se_dev
->se_dev_hba
->hba_group
.cg_item
);
2821 mutex_lock(&hba
->hba_access_mutex
);
2824 spin_lock(&se_global
->g_device_lock
);
2825 list_del(&se_dev
->g_se_dev_list
);
2826 spin_unlock(&se_global
->g_device_lock
);
2828 tg_pt_gp_cg
= &T10_ALUA(se_dev
)->alua_tg_pt_gps_group
;
2829 for (i
= 0; tg_pt_gp_cg
->default_groups
[i
]; i
++) {
2830 df_item
= &tg_pt_gp_cg
->default_groups
[i
]->cg_item
;
2831 tg_pt_gp_cg
->default_groups
[i
] = NULL
;
2832 config_item_put(df_item
);
2834 kfree(tg_pt_gp_cg
->default_groups
);
2836 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2837 * directly from target_core_alua_tg_pt_gp_release().
2839 T10_ALUA(se_dev
)->default_tg_pt_gp
= NULL
;
2841 dev_cg
= &se_dev
->se_dev_group
;
2842 for (i
= 0; dev_cg
->default_groups
[i
]; i
++) {
2843 df_item
= &dev_cg
->default_groups
[i
]->cg_item
;
2844 dev_cg
->default_groups
[i
] = NULL
;
2845 config_item_put(df_item
);
2848 * The releasing of se_dev and associated se_dev->se_dev_ptr is done
2849 * from target_core_dev_item_ops->release() ->target_core_dev_release().
2851 config_item_put(item
);
2852 mutex_unlock(&hba
->hba_access_mutex
);
2855 static struct configfs_group_operations target_core_hba_group_ops
= {
2856 .make_group
= target_core_make_subdev
,
2857 .drop_item
= target_core_drop_subdev
,
2860 CONFIGFS_EATTR_STRUCT(target_core_hba
, se_hba
);
2861 #define SE_HBA_ATTR(_name, _mode) \
2862 static struct target_core_hba_attribute \
2863 target_core_hba_##_name = \
2864 __CONFIGFS_EATTR(_name, _mode, \
2865 target_core_hba_show_attr_##_name, \
2866 target_core_hba_store_attr_##_name);
2868 #define SE_HBA_ATTR_RO(_name) \
2869 static struct target_core_hba_attribute \
2870 target_core_hba_##_name = \
2871 __CONFIGFS_EATTR_RO(_name, \
2872 target_core_hba_show_attr_##_name);
2874 static ssize_t
target_core_hba_show_attr_hba_info(
2878 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
2879 hba
->hba_id
, hba
->transport
->name
,
2880 TARGET_CORE_CONFIGFS_VERSION
);
2883 SE_HBA_ATTR_RO(hba_info
);
2885 static ssize_t
target_core_hba_show_attr_hba_mode(struct se_hba
*hba
,
2890 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
2893 return sprintf(page
, "%d\n", hba_mode
);
2896 static ssize_t
target_core_hba_store_attr_hba_mode(struct se_hba
*hba
,
2897 const char *page
, size_t count
)
2899 struct se_subsystem_api
*transport
= hba
->transport
;
2900 unsigned long mode_flag
;
2903 if (transport
->pmode_enable_hba
== NULL
)
2906 ret
= strict_strtoul(page
, 0, &mode_flag
);
2908 printk(KERN_ERR
"Unable to extract hba mode flag: %d\n", ret
);
2912 spin_lock(&hba
->device_lock
);
2913 if (!(list_empty(&hba
->hba_dev_list
))) {
2914 printk(KERN_ERR
"Unable to set hba_mode with active devices\n");
2915 spin_unlock(&hba
->device_lock
);
2918 spin_unlock(&hba
->device_lock
);
2920 ret
= transport
->pmode_enable_hba(hba
, mode_flag
);
2924 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
2926 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
2931 SE_HBA_ATTR(hba_mode
, S_IRUGO
| S_IWUSR
);
2933 CONFIGFS_EATTR_OPS(target_core_hba
, se_hba
, hba_group
);
2935 static void target_core_hba_release(struct config_item
*item
)
2937 struct se_hba
*hba
= container_of(to_config_group(item
),
2938 struct se_hba
, hba_group
);
2939 core_delete_hba(hba
);
2942 static struct configfs_attribute
*target_core_hba_attrs
[] = {
2943 &target_core_hba_hba_info
.attr
,
2944 &target_core_hba_hba_mode
.attr
,
2948 static struct configfs_item_operations target_core_hba_item_ops
= {
2949 .release
= target_core_hba_release
,
2950 .show_attribute
= target_core_hba_attr_show
,
2951 .store_attribute
= target_core_hba_attr_store
,
2954 static struct config_item_type target_core_hba_cit
= {
2955 .ct_item_ops
= &target_core_hba_item_ops
,
2956 .ct_group_ops
= &target_core_hba_group_ops
,
2957 .ct_attrs
= target_core_hba_attrs
,
2958 .ct_owner
= THIS_MODULE
,
2961 static struct config_group
*target_core_call_addhbatotarget(
2962 struct config_group
*group
,
2965 char *se_plugin_str
, *str
, *str2
;
2967 char buf
[TARGET_CORE_NAME_MAX_LEN
];
2968 unsigned long plugin_dep_id
= 0;
2971 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
2972 if (strlen(name
) > TARGET_CORE_NAME_MAX_LEN
) {
2973 printk(KERN_ERR
"Passed *name strlen(): %d exceeds"
2974 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
2975 TARGET_CORE_NAME_MAX_LEN
);
2976 return ERR_PTR(-ENAMETOOLONG
);
2978 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
2980 str
= strstr(buf
, "_");
2982 printk(KERN_ERR
"Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
2983 return ERR_PTR(-EINVAL
);
2985 se_plugin_str
= buf
;
2987 * Special case for subsystem plugins that have "_" in their names.
2988 * Namely rd_direct and rd_mcp..
2990 str2
= strstr(str
+1, "_");
2992 *str2
= '\0'; /* Terminate for *se_plugin_str */
2993 str2
++; /* Skip to start of plugin dependent ID */
2996 *str
= '\0'; /* Terminate for *se_plugin_str */
2997 str
++; /* Skip to start of plugin dependent ID */
3000 ret
= strict_strtoul(str
, 0, &plugin_dep_id
);
3002 printk(KERN_ERR
"strict_strtoul() returned %d for"
3003 " plugin_dep_id\n", ret
);
3004 return ERR_PTR(-EINVAL
);
3007 * Load up TCM subsystem plugins if they have not already been loaded.
3009 if (transport_subsystem_check_init() < 0)
3010 return ERR_PTR(-EINVAL
);
3012 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
3014 return ERR_CAST(hba
);
3016 config_group_init_type_name(&hba
->hba_group
, name
,
3017 &target_core_hba_cit
);
3019 return &hba
->hba_group
;
3022 static void target_core_call_delhbafromtarget(
3023 struct config_group
*group
,
3024 struct config_item
*item
)
3027 * core_delete_hba() is called from target_core_hba_item_ops->release()
3028 * -> target_core_hba_release()
3030 config_item_put(item
);
3033 static struct configfs_group_operations target_core_group_ops
= {
3034 .make_group
= target_core_call_addhbatotarget
,
3035 .drop_item
= target_core_call_delhbafromtarget
,
3038 static struct config_item_type target_core_cit
= {
3039 .ct_item_ops
= NULL
,
3040 .ct_group_ops
= &target_core_group_ops
,
3042 .ct_owner
= THIS_MODULE
,
3045 /* Stop functions for struct config_item_type target_core_hba_cit */
3047 static int target_core_init_configfs(void)
3049 struct config_group
*target_cg
, *hba_cg
= NULL
, *alua_cg
= NULL
;
3050 struct config_group
*lu_gp_cg
= NULL
;
3051 struct configfs_subsystem
*subsys
;
3052 struct t10_alua_lu_gp
*lu_gp
;
3055 printk(KERN_INFO
"TARGET_CORE[0]: Loading Generic Kernel Storage"
3056 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
3057 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
3059 subsys
= target_core_subsystem
[0];
3060 config_group_init(&subsys
->su_group
);
3061 mutex_init(&subsys
->su_mutex
);
3063 INIT_LIST_HEAD(&g_tf_list
);
3064 mutex_init(&g_tf_lock
);
3065 init_scsi_index_table();
3066 ret
= init_se_global();
3070 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
3071 * and ALUA Logical Unit Group and Target Port Group infrastructure.
3073 target_cg
= &subsys
->su_group
;
3074 target_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3076 if (!(target_cg
->default_groups
)) {
3077 printk(KERN_ERR
"Unable to allocate target_cg->default_groups\n");
3081 config_group_init_type_name(&se_global
->target_core_hbagroup
,
3082 "core", &target_core_cit
);
3083 target_cg
->default_groups
[0] = &se_global
->target_core_hbagroup
;
3084 target_cg
->default_groups
[1] = NULL
;
3086 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
3088 hba_cg
= &se_global
->target_core_hbagroup
;
3089 hba_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3091 if (!(hba_cg
->default_groups
)) {
3092 printk(KERN_ERR
"Unable to allocate hba_cg->default_groups\n");
3095 config_group_init_type_name(&se_global
->alua_group
,
3096 "alua", &target_core_alua_cit
);
3097 hba_cg
->default_groups
[0] = &se_global
->alua_group
;
3098 hba_cg
->default_groups
[1] = NULL
;
3100 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
3101 * groups under /sys/kernel/config/target/core/alua/
3103 alua_cg
= &se_global
->alua_group
;
3104 alua_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3106 if (!(alua_cg
->default_groups
)) {
3107 printk(KERN_ERR
"Unable to allocate alua_cg->default_groups\n");
3111 config_group_init_type_name(&se_global
->alua_lu_gps_group
,
3112 "lu_gps", &target_core_alua_lu_gps_cit
);
3113 alua_cg
->default_groups
[0] = &se_global
->alua_lu_gps_group
;
3114 alua_cg
->default_groups
[1] = NULL
;
3116 * Add core/alua/lu_gps/default_lu_gp
3118 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
3122 lu_gp_cg
= &se_global
->alua_lu_gps_group
;
3123 lu_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3125 if (!(lu_gp_cg
->default_groups
)) {
3126 printk(KERN_ERR
"Unable to allocate lu_gp_cg->default_groups\n");
3130 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
3131 &target_core_alua_lu_gp_cit
);
3132 lu_gp_cg
->default_groups
[0] = &lu_gp
->lu_gp_group
;
3133 lu_gp_cg
->default_groups
[1] = NULL
;
3134 se_global
->default_lu_gp
= lu_gp
;
3136 * Register the target_core_mod subsystem with configfs.
3138 ret
= configfs_register_subsystem(subsys
);
3140 printk(KERN_ERR
"Error %d while registering subsystem %s\n",
3141 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
3144 printk(KERN_INFO
"TARGET_CORE[0]: Initialized ConfigFS Fabric"
3145 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION
" on %s/%s"
3146 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
3148 * Register built-in RAMDISK subsystem logic for virtual LUN 0
3150 ret
= rd_module_init();
3154 if (core_dev_setup_virtual_lun0() < 0)
3160 configfs_unregister_subsystem(subsys
);
3161 core_dev_release_virtual_lun0();
3164 if (se_global
->default_lu_gp
) {
3165 core_alua_free_lu_gp(se_global
->default_lu_gp
);
3166 se_global
->default_lu_gp
= NULL
;
3169 kfree(lu_gp_cg
->default_groups
);
3171 kfree(alua_cg
->default_groups
);
3173 kfree(hba_cg
->default_groups
);
3174 kfree(target_cg
->default_groups
);
3175 release_se_global();
3179 static void target_core_exit_configfs(void)
3181 struct configfs_subsystem
*subsys
;
3182 struct config_group
*hba_cg
, *alua_cg
, *lu_gp_cg
;
3183 struct config_item
*item
;
3186 se_global
->in_shutdown
= 1;
3187 subsys
= target_core_subsystem
[0];
3189 lu_gp_cg
= &se_global
->alua_lu_gps_group
;
3190 for (i
= 0; lu_gp_cg
->default_groups
[i
]; i
++) {
3191 item
= &lu_gp_cg
->default_groups
[i
]->cg_item
;
3192 lu_gp_cg
->default_groups
[i
] = NULL
;
3193 config_item_put(item
);
3195 kfree(lu_gp_cg
->default_groups
);
3196 lu_gp_cg
->default_groups
= NULL
;
3198 alua_cg
= &se_global
->alua_group
;
3199 for (i
= 0; alua_cg
->default_groups
[i
]; i
++) {
3200 item
= &alua_cg
->default_groups
[i
]->cg_item
;
3201 alua_cg
->default_groups
[i
] = NULL
;
3202 config_item_put(item
);
3204 kfree(alua_cg
->default_groups
);
3205 alua_cg
->default_groups
= NULL
;
3207 hba_cg
= &se_global
->target_core_hbagroup
;
3208 for (i
= 0; hba_cg
->default_groups
[i
]; i
++) {
3209 item
= &hba_cg
->default_groups
[i
]->cg_item
;
3210 hba_cg
->default_groups
[i
] = NULL
;
3211 config_item_put(item
);
3213 kfree(hba_cg
->default_groups
);
3214 hba_cg
->default_groups
= NULL
;
3216 * We expect subsys->su_group.default_groups to be released
3217 * by configfs subsystem provider logic..
3219 configfs_unregister_subsystem(subsys
);
3220 kfree(subsys
->su_group
.default_groups
);
3222 core_alua_free_lu_gp(se_global
->default_lu_gp
);
3223 se_global
->default_lu_gp
= NULL
;
3225 printk(KERN_INFO
"TARGET_CORE[0]: Released ConfigFS Fabric"
3226 " Infrastructure\n");
3228 core_dev_release_virtual_lun0();
3230 release_se_global();
3235 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3236 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3237 MODULE_LICENSE("GPL");
3239 module_init(target_core_init_configfs
);
3240 module_exit(target_core_exit_configfs
);