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>
40 #include <linux/proc_fs.h>
42 #include <target/target_core_base.h>
43 #include <target/target_core_device.h>
44 #include <target/target_core_transport.h>
45 #include <target/target_core_fabric_ops.h>
46 #include <target/target_core_fabric_configfs.h>
47 #include <target/target_core_configfs.h>
48 #include <target/configfs_macros.h>
50 #include "target_core_alua.h"
51 #include "target_core_hba.h"
52 #include "target_core_pr.h"
53 #include "target_core_rd.h"
55 static struct list_head g_tf_list
;
56 static struct mutex g_tf_lock
;
58 struct target_core_configfs_attribute
{
59 struct configfs_attribute attr
;
60 ssize_t (*show
)(void *, char *);
61 ssize_t (*store
)(void *, const char *, size_t);
64 static inline struct se_hba
*
65 item_to_hba(struct config_item
*item
)
67 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
71 * Attributes for /sys/kernel/config/target/
73 static ssize_t
target_core_attr_show(struct config_item
*item
,
74 struct configfs_attribute
*attr
,
77 return sprintf(page
, "Target Engine Core ConfigFS Infrastructure %s"
78 " on %s/%s on "UTS_RELEASE
"\n", TARGET_CORE_CONFIGFS_VERSION
,
79 utsname()->sysname
, utsname()->machine
);
82 static struct configfs_item_operations target_core_fabric_item_ops
= {
83 .show_attribute
= target_core_attr_show
,
86 static struct configfs_attribute target_core_item_attr_version
= {
87 .ca_owner
= THIS_MODULE
,
92 static struct target_fabric_configfs
*target_core_get_fabric(
95 struct target_fabric_configfs
*tf
;
100 mutex_lock(&g_tf_lock
);
101 list_for_each_entry(tf
, &g_tf_list
, tf_list
) {
102 if (!(strcmp(tf
->tf_name
, name
))) {
103 atomic_inc(&tf
->tf_access_cnt
);
104 mutex_unlock(&g_tf_lock
);
108 mutex_unlock(&g_tf_lock
);
114 * Called from struct target_core_group_ops->make_group()
116 static struct config_group
*target_core_register_fabric(
117 struct config_group
*group
,
120 struct target_fabric_configfs
*tf
;
123 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER -> group: %p name:"
124 " %s\n", group
, name
);
126 * Ensure that TCM subsystem plugins are loaded at this point for
127 * using the RAMDISK_DR virtual LUN 0 and all other struct se_port
130 if (transport_subsystem_check_init() < 0)
131 return ERR_PTR(-EINVAL
);
134 * Below are some hardcoded request_module() calls to automatically
135 * local fabric modules when the following is called:
137 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
139 * Note that this does not limit which TCM fabric module can be
140 * registered, but simply provids auto loading logic for modules with
141 * mkdir(2) system calls with known TCM fabric modules.
143 if (!(strncmp(name
, "iscsi", 5))) {
145 * Automatically load the LIO Target fabric module when the
146 * following is called:
148 * mkdir -p $CONFIGFS/target/iscsi
150 ret
= request_module("iscsi_target_mod");
152 printk(KERN_ERR
"request_module() failed for"
153 " iscsi_target_mod.ko: %d\n", ret
);
154 return ERR_PTR(-EINVAL
);
156 } else if (!(strncmp(name
, "loopback", 8))) {
158 * Automatically load the tcm_loop fabric module when the
159 * following is called:
161 * mkdir -p $CONFIGFS/target/loopback
163 ret
= request_module("tcm_loop");
165 printk(KERN_ERR
"request_module() failed for"
166 " tcm_loop.ko: %d\n", ret
);
167 return ERR_PTR(-EINVAL
);
171 tf
= target_core_get_fabric(name
);
173 printk(KERN_ERR
"target_core_get_fabric() failed for %s\n",
175 return ERR_PTR(-EINVAL
);
177 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER -> Located fabric:"
178 " %s\n", tf
->tf_name
);
180 * On a successful target_core_get_fabric() look, the returned
181 * struct target_fabric_configfs *tf will contain a usage reference.
183 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
184 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
186 tf
->tf_group
.default_groups
= tf
->tf_default_groups
;
187 tf
->tf_group
.default_groups
[0] = &tf
->tf_disc_group
;
188 tf
->tf_group
.default_groups
[1] = NULL
;
190 config_group_init_type_name(&tf
->tf_group
, name
,
191 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
192 config_group_init_type_name(&tf
->tf_disc_group
, "discovery_auth",
193 &TF_CIT_TMPL(tf
)->tfc_discovery_cit
);
195 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
196 " %s\n", tf
->tf_group
.cg_item
.ci_name
);
198 * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item()
200 tf
->tf_ops
.tf_subsys
= tf
->tf_subsys
;
201 tf
->tf_fabric
= &tf
->tf_group
.cg_item
;
202 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
205 return &tf
->tf_group
;
209 * Called from struct target_core_group_ops->drop_item()
211 static void target_core_deregister_fabric(
212 struct config_group
*group
,
213 struct config_item
*item
)
215 struct target_fabric_configfs
*tf
= container_of(
216 to_config_group(item
), struct target_fabric_configfs
, tf_group
);
217 struct config_group
*tf_group
;
218 struct config_item
*df_item
;
221 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
222 " tf list\n", config_item_name(item
));
224 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> located fabric:"
225 " %s\n", tf
->tf_name
);
226 atomic_dec(&tf
->tf_access_cnt
);
228 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> Releasing"
229 " tf->tf_fabric for %s\n", tf
->tf_name
);
230 tf
->tf_fabric
= NULL
;
232 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
233 " %s\n", config_item_name(item
));
235 tf_group
= &tf
->tf_group
;
236 for (i
= 0; tf_group
->default_groups
[i
]; i
++) {
237 df_item
= &tf_group
->default_groups
[i
]->cg_item
;
238 tf_group
->default_groups
[i
] = NULL
;
239 config_item_put(df_item
);
241 config_item_put(item
);
244 static struct configfs_group_operations target_core_fabric_group_ops
= {
245 .make_group
= &target_core_register_fabric
,
246 .drop_item
= &target_core_deregister_fabric
,
250 * All item attributes appearing in /sys/kernel/target/ appear here.
252 static struct configfs_attribute
*target_core_fabric_item_attrs
[] = {
253 &target_core_item_attr_version
,
258 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
260 static struct config_item_type target_core_fabrics_item
= {
261 .ct_item_ops
= &target_core_fabric_item_ops
,
262 .ct_group_ops
= &target_core_fabric_group_ops
,
263 .ct_attrs
= target_core_fabric_item_attrs
,
264 .ct_owner
= THIS_MODULE
,
267 static struct configfs_subsystem target_core_fabrics
= {
270 .ci_namebuf
= "target",
271 .ci_type
= &target_core_fabrics_item
,
276 static struct configfs_subsystem
*target_core_subsystem
[] = {
277 &target_core_fabrics
,
281 /*##############################################################################
282 // Start functions called by external Target Fabrics Modules
283 //############################################################################*/
286 * First function called by fabric modules to:
288 * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer.
289 * 2) Add struct target_fabric_configfs to g_tf_list
290 * 3) Return struct target_fabric_configfs to fabric module to be passed
291 * into target_fabric_configfs_register().
293 struct target_fabric_configfs
*target_fabric_configfs_init(
294 struct module
*fabric_mod
,
297 struct target_fabric_configfs
*tf
;
300 printk(KERN_ERR
"Missing struct module *fabric_mod pointer\n");
304 printk(KERN_ERR
"Unable to locate passed fabric name\n");
307 if (strlen(name
) > TARGET_FABRIC_NAME_SIZE
) {
308 printk(KERN_ERR
"Passed name: %s exceeds TARGET_FABRIC"
309 "_NAME_SIZE\n", name
);
313 tf
= kzalloc(sizeof(struct target_fabric_configfs
), GFP_KERNEL
);
315 return ERR_PTR(-ENOMEM
);
317 INIT_LIST_HEAD(&tf
->tf_list
);
318 atomic_set(&tf
->tf_access_cnt
, 0);
320 * Setup the default generic struct config_item_type's (cits) in
321 * struct target_fabric_configfs->tf_cit_tmpl
323 tf
->tf_module
= fabric_mod
;
324 target_fabric_setup_cits(tf
);
326 tf
->tf_subsys
= target_core_subsystem
[0];
327 snprintf(tf
->tf_name
, TARGET_FABRIC_NAME_SIZE
, "%s", name
);
329 mutex_lock(&g_tf_lock
);
330 list_add_tail(&tf
->tf_list
, &g_tf_list
);
331 mutex_unlock(&g_tf_lock
);
333 printk(KERN_INFO
"<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>"
335 printk(KERN_INFO
"Initialized struct target_fabric_configfs: %p for"
336 " %s\n", tf
, tf
->tf_name
);
339 EXPORT_SYMBOL(target_fabric_configfs_init
);
342 * Called by fabric plugins after FAILED target_fabric_configfs_register() call.
344 void target_fabric_configfs_free(
345 struct target_fabric_configfs
*tf
)
347 mutex_lock(&g_tf_lock
);
348 list_del(&tf
->tf_list
);
349 mutex_unlock(&g_tf_lock
);
353 EXPORT_SYMBOL(target_fabric_configfs_free
);
356 * Perform a sanity check of the passed tf->tf_ops before completing
357 * TCM fabric module registration.
359 static int target_fabric_tf_ops_check(
360 struct target_fabric_configfs
*tf
)
362 struct target_core_fabric_ops
*tfo
= &tf
->tf_ops
;
364 if (!(tfo
->get_fabric_name
)) {
365 printk(KERN_ERR
"Missing tfo->get_fabric_name()\n");
368 if (!(tfo
->get_fabric_proto_ident
)) {
369 printk(KERN_ERR
"Missing tfo->get_fabric_proto_ident()\n");
372 if (!(tfo
->tpg_get_wwn
)) {
373 printk(KERN_ERR
"Missing tfo->tpg_get_wwn()\n");
376 if (!(tfo
->tpg_get_tag
)) {
377 printk(KERN_ERR
"Missing tfo->tpg_get_tag()\n");
380 if (!(tfo
->tpg_get_default_depth
)) {
381 printk(KERN_ERR
"Missing tfo->tpg_get_default_depth()\n");
384 if (!(tfo
->tpg_get_pr_transport_id
)) {
385 printk(KERN_ERR
"Missing tfo->tpg_get_pr_transport_id()\n");
388 if (!(tfo
->tpg_get_pr_transport_id_len
)) {
389 printk(KERN_ERR
"Missing tfo->tpg_get_pr_transport_id_len()\n");
392 if (!(tfo
->tpg_check_demo_mode
)) {
393 printk(KERN_ERR
"Missing tfo->tpg_check_demo_mode()\n");
396 if (!(tfo
->tpg_check_demo_mode_cache
)) {
397 printk(KERN_ERR
"Missing tfo->tpg_check_demo_mode_cache()\n");
400 if (!(tfo
->tpg_check_demo_mode_write_protect
)) {
401 printk(KERN_ERR
"Missing tfo->tpg_check_demo_mode_write_protect()\n");
404 if (!(tfo
->tpg_check_prod_mode_write_protect
)) {
405 printk(KERN_ERR
"Missing tfo->tpg_check_prod_mode_write_protect()\n");
408 if (!(tfo
->tpg_alloc_fabric_acl
)) {
409 printk(KERN_ERR
"Missing tfo->tpg_alloc_fabric_acl()\n");
412 if (!(tfo
->tpg_release_fabric_acl
)) {
413 printk(KERN_ERR
"Missing tfo->tpg_release_fabric_acl()\n");
416 if (!(tfo
->tpg_get_inst_index
)) {
417 printk(KERN_ERR
"Missing tfo->tpg_get_inst_index()\n");
420 if (!(tfo
->release_cmd_to_pool
)) {
421 printk(KERN_ERR
"Missing tfo->release_cmd_to_pool()\n");
424 if (!(tfo
->release_cmd_direct
)) {
425 printk(KERN_ERR
"Missing tfo->release_cmd_direct()\n");
428 if (!(tfo
->shutdown_session
)) {
429 printk(KERN_ERR
"Missing tfo->shutdown_session()\n");
432 if (!(tfo
->close_session
)) {
433 printk(KERN_ERR
"Missing tfo->close_session()\n");
436 if (!(tfo
->stop_session
)) {
437 printk(KERN_ERR
"Missing tfo->stop_session()\n");
440 if (!(tfo
->fall_back_to_erl0
)) {
441 printk(KERN_ERR
"Missing tfo->fall_back_to_erl0()\n");
444 if (!(tfo
->sess_logged_in
)) {
445 printk(KERN_ERR
"Missing tfo->sess_logged_in()\n");
448 if (!(tfo
->sess_get_index
)) {
449 printk(KERN_ERR
"Missing tfo->sess_get_index()\n");
452 if (!(tfo
->write_pending
)) {
453 printk(KERN_ERR
"Missing tfo->write_pending()\n");
456 if (!(tfo
->write_pending_status
)) {
457 printk(KERN_ERR
"Missing tfo->write_pending_status()\n");
460 if (!(tfo
->set_default_node_attributes
)) {
461 printk(KERN_ERR
"Missing tfo->set_default_node_attributes()\n");
464 if (!(tfo
->get_task_tag
)) {
465 printk(KERN_ERR
"Missing tfo->get_task_tag()\n");
468 if (!(tfo
->get_cmd_state
)) {
469 printk(KERN_ERR
"Missing tfo->get_cmd_state()\n");
472 if (!(tfo
->new_cmd_failure
)) {
473 printk(KERN_ERR
"Missing tfo->new_cmd_failure()\n");
476 if (!(tfo
->queue_data_in
)) {
477 printk(KERN_ERR
"Missing tfo->queue_data_in()\n");
480 if (!(tfo
->queue_status
)) {
481 printk(KERN_ERR
"Missing tfo->queue_status()\n");
484 if (!(tfo
->queue_tm_rsp
)) {
485 printk(KERN_ERR
"Missing tfo->queue_tm_rsp()\n");
488 if (!(tfo
->set_fabric_sense_len
)) {
489 printk(KERN_ERR
"Missing tfo->set_fabric_sense_len()\n");
492 if (!(tfo
->get_fabric_sense_len
)) {
493 printk(KERN_ERR
"Missing tfo->get_fabric_sense_len()\n");
496 if (!(tfo
->is_state_remove
)) {
497 printk(KERN_ERR
"Missing tfo->is_state_remove()\n");
500 if (!(tfo
->pack_lun
)) {
501 printk(KERN_ERR
"Missing tfo->pack_lun()\n");
505 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
506 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
507 * target_core_fabric_configfs.c WWN+TPG group context code.
509 if (!(tfo
->fabric_make_wwn
)) {
510 printk(KERN_ERR
"Missing tfo->fabric_make_wwn()\n");
513 if (!(tfo
->fabric_drop_wwn
)) {
514 printk(KERN_ERR
"Missing tfo->fabric_drop_wwn()\n");
517 if (!(tfo
->fabric_make_tpg
)) {
518 printk(KERN_ERR
"Missing tfo->fabric_make_tpg()\n");
521 if (!(tfo
->fabric_drop_tpg
)) {
522 printk(KERN_ERR
"Missing tfo->fabric_drop_tpg()\n");
530 * Called 2nd from fabric module with returned parameter of
531 * struct target_fabric_configfs * from target_fabric_configfs_init().
533 * Upon a successful registration, the new fabric's struct config_item is
534 * return. Also, a pointer to this struct is set in the passed
535 * struct target_fabric_configfs.
537 int target_fabric_configfs_register(
538 struct target_fabric_configfs
*tf
)
540 struct config_group
*su_group
;
544 printk(KERN_ERR
"Unable to locate target_fabric_configfs"
548 if (!(tf
->tf_subsys
)) {
549 printk(KERN_ERR
"Unable to target struct config_subsystem"
553 su_group
= &tf
->tf_subsys
->su_group
;
555 printk(KERN_ERR
"Unable to locate target struct config_group"
559 ret
= target_fabric_tf_ops_check(tf
);
563 printk(KERN_INFO
"<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>"
567 EXPORT_SYMBOL(target_fabric_configfs_register
);
569 void target_fabric_configfs_deregister(
570 struct target_fabric_configfs
*tf
)
572 struct config_group
*su_group
;
573 struct configfs_subsystem
*su
;
576 printk(KERN_ERR
"Unable to locate passed target_fabric_"
582 printk(KERN_ERR
"Unable to locate passed tf->tf_subsys"
586 su_group
= &tf
->tf_subsys
->su_group
;
588 printk(KERN_ERR
"Unable to locate target struct config_group"
593 printk(KERN_INFO
"<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
595 mutex_lock(&g_tf_lock
);
596 if (atomic_read(&tf
->tf_access_cnt
)) {
597 mutex_unlock(&g_tf_lock
);
598 printk(KERN_ERR
"Non zero tf->tf_access_cnt for fabric %s\n",
602 list_del(&tf
->tf_list
);
603 mutex_unlock(&g_tf_lock
);
605 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
606 " %s\n", tf
->tf_name
);
607 tf
->tf_module
= NULL
;
608 tf
->tf_subsys
= NULL
;
611 printk("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
615 EXPORT_SYMBOL(target_fabric_configfs_deregister
);
617 /*##############################################################################
618 // Stop functions called by external Target Fabrics Modules
619 //############################################################################*/
621 /* Start functions for struct config_item_type target_core_dev_attrib_cit */
623 #define DEF_DEV_ATTRIB_SHOW(_name) \
624 static ssize_t target_core_dev_show_attr_##_name( \
625 struct se_dev_attrib *da, \
628 struct se_device *dev; \
629 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
632 spin_lock(&se_dev->se_dev_lock); \
633 dev = se_dev->se_dev_ptr; \
635 spin_unlock(&se_dev->se_dev_lock); \
638 rb = snprintf(page, PAGE_SIZE, "%u\n", (u32)DEV_ATTRIB(dev)->_name); \
639 spin_unlock(&se_dev->se_dev_lock); \
644 #define DEF_DEV_ATTRIB_STORE(_name) \
645 static ssize_t target_core_dev_store_attr_##_name( \
646 struct se_dev_attrib *da, \
650 struct se_device *dev; \
651 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
655 spin_lock(&se_dev->se_dev_lock); \
656 dev = se_dev->se_dev_ptr; \
658 spin_unlock(&se_dev->se_dev_lock); \
661 ret = strict_strtoul(page, 0, &val); \
663 spin_unlock(&se_dev->se_dev_lock); \
664 printk(KERN_ERR "strict_strtoul() failed with" \
665 " ret: %d\n", ret); \
668 ret = se_dev_set_##_name(dev, (u32)val); \
669 spin_unlock(&se_dev->se_dev_lock); \
671 return (!ret) ? count : -EINVAL; \
674 #define DEF_DEV_ATTRIB(_name) \
675 DEF_DEV_ATTRIB_SHOW(_name); \
676 DEF_DEV_ATTRIB_STORE(_name);
678 #define DEF_DEV_ATTRIB_RO(_name) \
679 DEF_DEV_ATTRIB_SHOW(_name);
681 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib
, se_dev_attrib
);
682 #define SE_DEV_ATTR(_name, _mode) \
683 static struct target_core_dev_attrib_attribute \
684 target_core_dev_attrib_##_name = \
685 __CONFIGFS_EATTR(_name, _mode, \
686 target_core_dev_show_attr_##_name, \
687 target_core_dev_store_attr_##_name);
689 #define SE_DEV_ATTR_RO(_name); \
690 static struct target_core_dev_attrib_attribute \
691 target_core_dev_attrib_##_name = \
692 __CONFIGFS_EATTR_RO(_name, \
693 target_core_dev_show_attr_##_name);
695 DEF_DEV_ATTRIB(emulate_dpo
);
696 SE_DEV_ATTR(emulate_dpo
, S_IRUGO
| S_IWUSR
);
698 DEF_DEV_ATTRIB(emulate_fua_write
);
699 SE_DEV_ATTR(emulate_fua_write
, S_IRUGO
| S_IWUSR
);
701 DEF_DEV_ATTRIB(emulate_fua_read
);
702 SE_DEV_ATTR(emulate_fua_read
, S_IRUGO
| S_IWUSR
);
704 DEF_DEV_ATTRIB(emulate_write_cache
);
705 SE_DEV_ATTR(emulate_write_cache
, S_IRUGO
| S_IWUSR
);
707 DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl
);
708 SE_DEV_ATTR(emulate_ua_intlck_ctrl
, S_IRUGO
| S_IWUSR
);
710 DEF_DEV_ATTRIB(emulate_tas
);
711 SE_DEV_ATTR(emulate_tas
, S_IRUGO
| S_IWUSR
);
713 DEF_DEV_ATTRIB(emulate_tpu
);
714 SE_DEV_ATTR(emulate_tpu
, S_IRUGO
| S_IWUSR
);
716 DEF_DEV_ATTRIB(emulate_tpws
);
717 SE_DEV_ATTR(emulate_tpws
, S_IRUGO
| S_IWUSR
);
719 DEF_DEV_ATTRIB(enforce_pr_isids
);
720 SE_DEV_ATTR(enforce_pr_isids
, S_IRUGO
| S_IWUSR
);
722 DEF_DEV_ATTRIB_RO(hw_block_size
);
723 SE_DEV_ATTR_RO(hw_block_size
);
725 DEF_DEV_ATTRIB(block_size
);
726 SE_DEV_ATTR(block_size
, S_IRUGO
| S_IWUSR
);
728 DEF_DEV_ATTRIB_RO(hw_max_sectors
);
729 SE_DEV_ATTR_RO(hw_max_sectors
);
731 DEF_DEV_ATTRIB(max_sectors
);
732 SE_DEV_ATTR(max_sectors
, S_IRUGO
| S_IWUSR
);
734 DEF_DEV_ATTRIB(optimal_sectors
);
735 SE_DEV_ATTR(optimal_sectors
, S_IRUGO
| S_IWUSR
);
737 DEF_DEV_ATTRIB_RO(hw_queue_depth
);
738 SE_DEV_ATTR_RO(hw_queue_depth
);
740 DEF_DEV_ATTRIB(queue_depth
);
741 SE_DEV_ATTR(queue_depth
, S_IRUGO
| S_IWUSR
);
743 DEF_DEV_ATTRIB(task_timeout
);
744 SE_DEV_ATTR(task_timeout
, S_IRUGO
| S_IWUSR
);
746 DEF_DEV_ATTRIB(max_unmap_lba_count
);
747 SE_DEV_ATTR(max_unmap_lba_count
, S_IRUGO
| S_IWUSR
);
749 DEF_DEV_ATTRIB(max_unmap_block_desc_count
);
750 SE_DEV_ATTR(max_unmap_block_desc_count
, S_IRUGO
| S_IWUSR
);
752 DEF_DEV_ATTRIB(unmap_granularity
);
753 SE_DEV_ATTR(unmap_granularity
, S_IRUGO
| S_IWUSR
);
755 DEF_DEV_ATTRIB(unmap_granularity_alignment
);
756 SE_DEV_ATTR(unmap_granularity_alignment
, S_IRUGO
| S_IWUSR
);
758 CONFIGFS_EATTR_OPS(target_core_dev_attrib
, se_dev_attrib
, da_group
);
760 static struct configfs_attribute
*target_core_dev_attrib_attrs
[] = {
761 &target_core_dev_attrib_emulate_dpo
.attr
,
762 &target_core_dev_attrib_emulate_fua_write
.attr
,
763 &target_core_dev_attrib_emulate_fua_read
.attr
,
764 &target_core_dev_attrib_emulate_write_cache
.attr
,
765 &target_core_dev_attrib_emulate_ua_intlck_ctrl
.attr
,
766 &target_core_dev_attrib_emulate_tas
.attr
,
767 &target_core_dev_attrib_emulate_tpu
.attr
,
768 &target_core_dev_attrib_emulate_tpws
.attr
,
769 &target_core_dev_attrib_enforce_pr_isids
.attr
,
770 &target_core_dev_attrib_hw_block_size
.attr
,
771 &target_core_dev_attrib_block_size
.attr
,
772 &target_core_dev_attrib_hw_max_sectors
.attr
,
773 &target_core_dev_attrib_max_sectors
.attr
,
774 &target_core_dev_attrib_optimal_sectors
.attr
,
775 &target_core_dev_attrib_hw_queue_depth
.attr
,
776 &target_core_dev_attrib_queue_depth
.attr
,
777 &target_core_dev_attrib_task_timeout
.attr
,
778 &target_core_dev_attrib_max_unmap_lba_count
.attr
,
779 &target_core_dev_attrib_max_unmap_block_desc_count
.attr
,
780 &target_core_dev_attrib_unmap_granularity
.attr
,
781 &target_core_dev_attrib_unmap_granularity_alignment
.attr
,
785 static struct configfs_item_operations target_core_dev_attrib_ops
= {
786 .show_attribute
= target_core_dev_attrib_attr_show
,
787 .store_attribute
= target_core_dev_attrib_attr_store
,
790 static struct config_item_type target_core_dev_attrib_cit
= {
791 .ct_item_ops
= &target_core_dev_attrib_ops
,
792 .ct_attrs
= target_core_dev_attrib_attrs
,
793 .ct_owner
= THIS_MODULE
,
796 /* End functions for struct config_item_type target_core_dev_attrib_cit */
798 /* Start functions for struct config_item_type target_core_dev_wwn_cit */
800 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn
, t10_wwn
);
801 #define SE_DEV_WWN_ATTR(_name, _mode) \
802 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
803 __CONFIGFS_EATTR(_name, _mode, \
804 target_core_dev_wwn_show_attr_##_name, \
805 target_core_dev_wwn_store_attr_##_name);
807 #define SE_DEV_WWN_ATTR_RO(_name); \
809 static struct target_core_dev_wwn_attribute \
810 target_core_dev_wwn_##_name = \
811 __CONFIGFS_EATTR_RO(_name, \
812 target_core_dev_wwn_show_attr_##_name); \
816 * VPD page 0x80 Unit serial
818 static ssize_t
target_core_dev_wwn_show_attr_vpd_unit_serial(
819 struct t10_wwn
*t10_wwn
,
822 struct se_subsystem_dev
*se_dev
= t10_wwn
->t10_sub_dev
;
823 struct se_device
*dev
;
825 dev
= se_dev
->se_dev_ptr
;
829 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
830 &t10_wwn
->unit_serial
[0]);
833 static ssize_t
target_core_dev_wwn_store_attr_vpd_unit_serial(
834 struct t10_wwn
*t10_wwn
,
838 struct se_subsystem_dev
*su_dev
= t10_wwn
->t10_sub_dev
;
839 struct se_device
*dev
;
840 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
843 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
844 * from the struct scsi_device level firmware, do not allow
845 * VPD Unit Serial to be emulated.
847 * Note this struct scsi_device could also be emulating VPD
848 * information from its drivers/scsi LLD. But for now we assume
849 * it is doing 'the right thing' wrt a world wide unique
850 * VPD Unit Serial Number that OS dependent multipath can depend on.
852 if (su_dev
->su_dev_flags
& SDF_FIRMWARE_VPD_UNIT_SERIAL
) {
853 printk(KERN_ERR
"Underlying SCSI device firmware provided VPD"
854 " Unit Serial, ignoring request\n");
858 if ((strlen(page
) + 1) > INQUIRY_VPD_SERIAL_LEN
) {
859 printk(KERN_ERR
"Emulated VPD Unit Serial exceeds"
860 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
864 * Check to see if any active $FABRIC_MOD exports exist. If they
865 * do exist, fail here as changing this information on the fly
866 * (underneath the initiator side OS dependent multipath code)
867 * could cause negative effects.
869 dev
= su_dev
->se_dev_ptr
;
871 if (atomic_read(&dev
->dev_export_obj
.obj_access_count
)) {
872 printk(KERN_ERR
"Unable to set VPD Unit Serial while"
873 " active %d $FABRIC_MOD exports exist\n",
874 atomic_read(&dev
->dev_export_obj
.obj_access_count
));
879 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
881 * Also, strip any newline added from the userspace
882 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
884 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
885 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
886 snprintf(su_dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
887 "%s", strstrip(buf
));
888 su_dev
->su_dev_flags
|= SDF_EMULATED_VPD_UNIT_SERIAL
;
890 printk(KERN_INFO
"Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
891 " %s\n", su_dev
->t10_wwn
.unit_serial
);
896 SE_DEV_WWN_ATTR(vpd_unit_serial
, S_IRUGO
| S_IWUSR
);
899 * VPD page 0x83 Protocol Identifier
901 static ssize_t
target_core_dev_wwn_show_attr_vpd_protocol_identifier(
902 struct t10_wwn
*t10_wwn
,
905 struct se_subsystem_dev
*se_dev
= t10_wwn
->t10_sub_dev
;
906 struct se_device
*dev
;
908 unsigned char buf
[VPD_TMP_BUF_SIZE
];
911 dev
= se_dev
->se_dev_ptr
;
915 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
917 spin_lock(&t10_wwn
->t10_vpd_lock
);
918 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
919 if (!(vpd
->protocol_identifier_set
))
922 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
924 if ((len
+ strlen(buf
) > PAGE_SIZE
))
927 len
+= sprintf(page
+len
, "%s", buf
);
929 spin_unlock(&t10_wwn
->t10_vpd_lock
);
934 static ssize_t
target_core_dev_wwn_store_attr_vpd_protocol_identifier(
935 struct t10_wwn
*t10_wwn
,
942 SE_DEV_WWN_ATTR(vpd_protocol_identifier
, S_IRUGO
| S_IWUSR
);
945 * Generic wrapper for dumping VPD identifiers by association.
947 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
948 static ssize_t target_core_dev_wwn_show_attr_##_name( \
949 struct t10_wwn *t10_wwn, \
952 struct se_subsystem_dev *se_dev = t10_wwn->t10_sub_dev; \
953 struct se_device *dev; \
954 struct t10_vpd *vpd; \
955 unsigned char buf[VPD_TMP_BUF_SIZE]; \
958 dev = se_dev->se_dev_ptr; \
962 spin_lock(&t10_wwn->t10_vpd_lock); \
963 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
964 if (vpd->association != _assoc) \
967 memset(buf, 0, VPD_TMP_BUF_SIZE); \
968 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
969 if ((len + strlen(buf) > PAGE_SIZE)) \
971 len += sprintf(page+len, "%s", buf); \
973 memset(buf, 0, VPD_TMP_BUF_SIZE); \
974 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
975 if ((len + strlen(buf) > PAGE_SIZE)) \
977 len += sprintf(page+len, "%s", buf); \
979 memset(buf, 0, VPD_TMP_BUF_SIZE); \
980 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
981 if ((len + strlen(buf) > PAGE_SIZE)) \
983 len += sprintf(page+len, "%s", buf); \
985 spin_unlock(&t10_wwn->t10_vpd_lock); \
991 * VPD page 0x83 Assoication: Logical Unit
993 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
995 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
996 struct t10_wwn
*t10_wwn
,
1003 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit
, S_IRUGO
| S_IWUSR
);
1006 * VPD page 0x83 Association: Target Port
1008 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
1010 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_target_port(
1011 struct t10_wwn
*t10_wwn
,
1018 SE_DEV_WWN_ATTR(vpd_assoc_target_port
, S_IRUGO
| S_IWUSR
);
1021 * VPD page 0x83 Association: SCSI Target Device
1023 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
1025 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
1026 struct t10_wwn
*t10_wwn
,
1033 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device
, S_IRUGO
| S_IWUSR
);
1035 CONFIGFS_EATTR_OPS(target_core_dev_wwn
, t10_wwn
, t10_wwn_group
);
1037 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
1038 &target_core_dev_wwn_vpd_unit_serial
.attr
,
1039 &target_core_dev_wwn_vpd_protocol_identifier
.attr
,
1040 &target_core_dev_wwn_vpd_assoc_logical_unit
.attr
,
1041 &target_core_dev_wwn_vpd_assoc_target_port
.attr
,
1042 &target_core_dev_wwn_vpd_assoc_scsi_target_device
.attr
,
1046 static struct configfs_item_operations target_core_dev_wwn_ops
= {
1047 .show_attribute
= target_core_dev_wwn_attr_show
,
1048 .store_attribute
= target_core_dev_wwn_attr_store
,
1051 static struct config_item_type target_core_dev_wwn_cit
= {
1052 .ct_item_ops
= &target_core_dev_wwn_ops
,
1053 .ct_attrs
= target_core_dev_wwn_attrs
,
1054 .ct_owner
= THIS_MODULE
,
1057 /* End functions for struct config_item_type target_core_dev_wwn_cit */
1059 /* Start functions for struct config_item_type target_core_dev_pr_cit */
1061 CONFIGFS_EATTR_STRUCT(target_core_dev_pr
, se_subsystem_dev
);
1062 #define SE_DEV_PR_ATTR(_name, _mode) \
1063 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1064 __CONFIGFS_EATTR(_name, _mode, \
1065 target_core_dev_pr_show_attr_##_name, \
1066 target_core_dev_pr_store_attr_##_name);
1068 #define SE_DEV_PR_ATTR_RO(_name); \
1069 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1070 __CONFIGFS_EATTR_RO(_name, \
1071 target_core_dev_pr_show_attr_##_name);
1076 static ssize_t
target_core_dev_pr_show_spc3_res(
1077 struct se_device
*dev
,
1081 struct se_node_acl
*se_nacl
;
1082 struct t10_pr_registration
*pr_reg
;
1083 char i_buf
[PR_REG_ISID_ID_LEN
];
1086 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1088 spin_lock(&dev
->dev_reservation_lock
);
1089 pr_reg
= dev
->dev_pr_res_holder
;
1091 *len
+= sprintf(page
+ *len
, "No SPC-3 Reservation holder\n");
1092 spin_unlock(&dev
->dev_reservation_lock
);
1095 se_nacl
= pr_reg
->pr_reg_nacl
;
1096 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1097 PR_REG_ISID_ID_LEN
);
1099 *len
+= sprintf(page
+ *len
, "SPC-3 Reservation: %s Initiator: %s%s\n",
1100 TPG_TFO(se_nacl
->se_tpg
)->get_fabric_name(),
1101 se_nacl
->initiatorname
, (prf_isid
) ? &i_buf
[0] : "");
1102 spin_unlock(&dev
->dev_reservation_lock
);
1107 static ssize_t
target_core_dev_pr_show_spc2_res(
1108 struct se_device
*dev
,
1112 struct se_node_acl
*se_nacl
;
1114 spin_lock(&dev
->dev_reservation_lock
);
1115 se_nacl
= dev
->dev_reserved_node_acl
;
1117 *len
+= sprintf(page
+ *len
, "No SPC-2 Reservation holder\n");
1118 spin_unlock(&dev
->dev_reservation_lock
);
1121 *len
+= sprintf(page
+ *len
, "SPC-2 Reservation: %s Initiator: %s\n",
1122 TPG_TFO(se_nacl
->se_tpg
)->get_fabric_name(),
1123 se_nacl
->initiatorname
);
1124 spin_unlock(&dev
->dev_reservation_lock
);
1129 static ssize_t
target_core_dev_pr_show_attr_res_holder(
1130 struct se_subsystem_dev
*su_dev
,
1135 if (!(su_dev
->se_dev_ptr
))
1138 switch (T10_RES(su_dev
)->res_type
) {
1139 case SPC3_PERSISTENT_RESERVATIONS
:
1140 target_core_dev_pr_show_spc3_res(su_dev
->se_dev_ptr
,
1143 case SPC2_RESERVATIONS
:
1144 target_core_dev_pr_show_spc2_res(su_dev
->se_dev_ptr
,
1147 case SPC_PASSTHROUGH
:
1148 len
+= sprintf(page
+len
, "Passthrough\n");
1151 len
+= sprintf(page
+len
, "Unknown\n");
1158 SE_DEV_PR_ATTR_RO(res_holder
);
1161 * res_pr_all_tgt_pts
1163 static ssize_t
target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1164 struct se_subsystem_dev
*su_dev
,
1167 struct se_device
*dev
;
1168 struct t10_pr_registration
*pr_reg
;
1171 dev
= su_dev
->se_dev_ptr
;
1175 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1178 spin_lock(&dev
->dev_reservation_lock
);
1179 pr_reg
= dev
->dev_pr_res_holder
;
1181 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1182 spin_unlock(&dev
->dev_reservation_lock
);
1186 * See All Target Ports (ALL_TG_PT) bit in spcr17, section 6.14.3
1187 * Basic PERSISTENT RESERVER OUT parameter list, page 290
1189 if (pr_reg
->pr_reg_all_tg_pt
)
1190 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1191 " Ports registration\n");
1193 len
= sprintf(page
, "SPC-3 Reservation: Single"
1194 " Target Port registration\n");
1195 spin_unlock(&dev
->dev_reservation_lock
);
1200 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts
);
1205 static ssize_t
target_core_dev_pr_show_attr_res_pr_generation(
1206 struct se_subsystem_dev
*su_dev
,
1209 if (!(su_dev
->se_dev_ptr
))
1212 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1215 return sprintf(page
, "0x%08x\n", T10_RES(su_dev
)->pr_generation
);
1218 SE_DEV_PR_ATTR_RO(res_pr_generation
);
1221 * res_pr_holder_tg_port
1223 static ssize_t
target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1224 struct se_subsystem_dev
*su_dev
,
1227 struct se_device
*dev
;
1228 struct se_node_acl
*se_nacl
;
1230 struct se_portal_group
*se_tpg
;
1231 struct t10_pr_registration
*pr_reg
;
1232 struct target_core_fabric_ops
*tfo
;
1235 dev
= su_dev
->se_dev_ptr
;
1239 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1242 spin_lock(&dev
->dev_reservation_lock
);
1243 pr_reg
= dev
->dev_pr_res_holder
;
1245 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1246 spin_unlock(&dev
->dev_reservation_lock
);
1249 se_nacl
= pr_reg
->pr_reg_nacl
;
1250 se_tpg
= se_nacl
->se_tpg
;
1251 lun
= pr_reg
->pr_reg_tg_pt_lun
;
1252 tfo
= TPG_TFO(se_tpg
);
1254 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1255 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1256 tfo
->tpg_get_wwn(se_tpg
));
1257 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1258 " Identifer Tag: %hu %s Portal Group Tag: %hu"
1259 " %s Logical Unit: %u\n", lun
->lun_sep
->sep_rtpi
,
1260 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1261 tfo
->get_fabric_name(), lun
->unpacked_lun
);
1262 spin_unlock(&dev
->dev_reservation_lock
);
1267 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port
);
1270 * res_pr_registered_i_pts
1272 static ssize_t
target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1273 struct se_subsystem_dev
*su_dev
,
1276 struct target_core_fabric_ops
*tfo
;
1277 struct t10_pr_registration
*pr_reg
;
1278 unsigned char buf
[384];
1279 char i_buf
[PR_REG_ISID_ID_LEN
];
1281 int reg_count
= 0, prf_isid
;
1283 if (!(su_dev
->se_dev_ptr
))
1286 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1289 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1291 spin_lock(&T10_RES(su_dev
)->registration_lock
);
1292 list_for_each_entry(pr_reg
, &T10_RES(su_dev
)->registration_list
,
1295 memset(buf
, 0, 384);
1296 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1297 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1298 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1299 PR_REG_ISID_ID_LEN
);
1300 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1301 tfo
->get_fabric_name(),
1302 pr_reg
->pr_reg_nacl
->initiatorname
, (prf_isid
) ?
1303 &i_buf
[0] : "", pr_reg
->pr_res_key
,
1304 pr_reg
->pr_res_generation
);
1306 if ((len
+ strlen(buf
) > PAGE_SIZE
))
1309 len
+= sprintf(page
+len
, "%s", buf
);
1312 spin_unlock(&T10_RES(su_dev
)->registration_lock
);
1315 len
+= sprintf(page
+len
, "None\n");
1320 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts
);
1325 static ssize_t
target_core_dev_pr_show_attr_res_pr_type(
1326 struct se_subsystem_dev
*su_dev
,
1329 struct se_device
*dev
;
1330 struct t10_pr_registration
*pr_reg
;
1333 dev
= su_dev
->se_dev_ptr
;
1337 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1340 spin_lock(&dev
->dev_reservation_lock
);
1341 pr_reg
= dev
->dev_pr_res_holder
;
1343 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1344 spin_unlock(&dev
->dev_reservation_lock
);
1347 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1348 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1349 spin_unlock(&dev
->dev_reservation_lock
);
1354 SE_DEV_PR_ATTR_RO(res_pr_type
);
1359 static ssize_t
target_core_dev_pr_show_attr_res_type(
1360 struct se_subsystem_dev
*su_dev
,
1365 if (!(su_dev
->se_dev_ptr
))
1368 switch (T10_RES(su_dev
)->res_type
) {
1369 case SPC3_PERSISTENT_RESERVATIONS
:
1370 len
= sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1372 case SPC2_RESERVATIONS
:
1373 len
= sprintf(page
, "SPC2_RESERVATIONS\n");
1375 case SPC_PASSTHROUGH
:
1376 len
= sprintf(page
, "SPC_PASSTHROUGH\n");
1379 len
= sprintf(page
, "UNKNOWN\n");
1386 SE_DEV_PR_ATTR_RO(res_type
);
1392 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_active(
1393 struct se_subsystem_dev
*su_dev
,
1396 if (!(su_dev
->se_dev_ptr
))
1399 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1402 return sprintf(page
, "APTPL Bit Status: %s\n",
1403 (T10_RES(su_dev
)->pr_aptpl_active
) ? "Activated" : "Disabled");
1406 SE_DEV_PR_ATTR_RO(res_aptpl_active
);
1409 * res_aptpl_metadata
1411 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_metadata(
1412 struct se_subsystem_dev
*su_dev
,
1415 if (!(su_dev
->se_dev_ptr
))
1418 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1421 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1425 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1426 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1427 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1428 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1431 static match_table_t tokens
= {
1432 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1433 {Opt_initiator_node
, "initiator_node=%s"},
1434 {Opt_initiator_sid
, "initiator_sid=%s"},
1435 {Opt_sa_res_key
, "sa_res_key=%s"},
1436 {Opt_res_holder
, "res_holder=%d"},
1437 {Opt_res_type
, "res_type=%d"},
1438 {Opt_res_scope
, "res_scope=%d"},
1439 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1440 {Opt_mapped_lun
, "mapped_lun=%d"},
1441 {Opt_target_fabric
, "target_fabric=%s"},
1442 {Opt_target_node
, "target_node=%s"},
1443 {Opt_tpgt
, "tpgt=%d"},
1444 {Opt_port_rtpi
, "port_rtpi=%d"},
1445 {Opt_target_lun
, "target_lun=%d"},
1449 static ssize_t
target_core_dev_pr_store_attr_res_aptpl_metadata(
1450 struct se_subsystem_dev
*su_dev
,
1454 struct se_device
*dev
;
1455 unsigned char *i_fabric
, *t_fabric
, *i_port
= NULL
, *t_port
= NULL
;
1456 unsigned char *isid
= NULL
;
1457 char *orig
, *ptr
, *arg_p
, *opts
;
1458 substring_t args
[MAX_OPT_ARGS
];
1459 unsigned long long tmp_ll
;
1461 u32 mapped_lun
= 0, target_lun
= 0;
1462 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1463 u16 port_rpti
= 0, tpgt
= 0;
1466 dev
= su_dev
->se_dev_ptr
;
1470 if (T10_RES(su_dev
)->res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1473 if (atomic_read(&dev
->dev_export_obj
.obj_access_count
)) {
1474 printk(KERN_INFO
"Unable to process APTPL metadata while"
1475 " active fabric exports exist\n");
1479 opts
= kstrdup(page
, GFP_KERNEL
);
1484 while ((ptr
= strsep(&opts
, ",")) != NULL
) {
1488 token
= match_token(ptr
, tokens
, args
);
1490 case Opt_initiator_fabric
:
1491 i_fabric
= match_strdup(&args
[0]);
1493 case Opt_initiator_node
:
1494 i_port
= match_strdup(&args
[0]);
1495 if (strlen(i_port
) > PR_APTPL_MAX_IPORT_LEN
) {
1496 printk(KERN_ERR
"APTPL metadata initiator_node="
1497 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1498 PR_APTPL_MAX_IPORT_LEN
);
1503 case Opt_initiator_sid
:
1504 isid
= match_strdup(&args
[0]);
1505 if (strlen(isid
) > PR_REG_ISID_LEN
) {
1506 printk(KERN_ERR
"APTPL metadata initiator_isid"
1507 "= exceeds PR_REG_ISID_LEN: %d\n",
1513 case Opt_sa_res_key
:
1514 arg_p
= match_strdup(&args
[0]);
1515 ret
= strict_strtoull(arg_p
, 0, &tmp_ll
);
1517 printk(KERN_ERR
"strict_strtoull() failed for"
1521 sa_res_key
= (u64
)tmp_ll
;
1524 * PR APTPL Metadata for Reservation
1526 case Opt_res_holder
:
1527 match_int(args
, &arg
);
1531 match_int(args
, &arg
);
1535 match_int(args
, &arg
);
1538 case Opt_res_all_tg_pt
:
1539 match_int(args
, &arg
);
1540 all_tg_pt
= (int)arg
;
1542 case Opt_mapped_lun
:
1543 match_int(args
, &arg
);
1544 mapped_lun
= (u32
)arg
;
1547 * PR APTPL Metadata for Target Port
1549 case Opt_target_fabric
:
1550 t_fabric
= match_strdup(&args
[0]);
1552 case Opt_target_node
:
1553 t_port
= match_strdup(&args
[0]);
1554 if (strlen(t_port
) > PR_APTPL_MAX_TPORT_LEN
) {
1555 printk(KERN_ERR
"APTPL metadata target_node="
1556 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1557 PR_APTPL_MAX_TPORT_LEN
);
1563 match_int(args
, &arg
);
1567 match_int(args
, &arg
);
1568 port_rpti
= (u16
)arg
;
1570 case Opt_target_lun
:
1571 match_int(args
, &arg
);
1572 target_lun
= (u32
)arg
;
1579 if (!(i_port
) || !(t_port
) || !(sa_res_key
)) {
1580 printk(KERN_ERR
"Illegal parameters for APTPL registration\n");
1585 if (res_holder
&& !(type
)) {
1586 printk(KERN_ERR
"Illegal PR type: 0x%02x for reservation"
1592 ret
= core_scsi3_alloc_aptpl_registration(T10_RES(su_dev
), sa_res_key
,
1593 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1594 res_holder
, all_tg_pt
, type
);
1597 return (ret
== 0) ? count
: ret
;
1600 SE_DEV_PR_ATTR(res_aptpl_metadata
, S_IRUGO
| S_IWUSR
);
1602 CONFIGFS_EATTR_OPS(target_core_dev_pr
, se_subsystem_dev
, se_dev_pr_group
);
1604 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1605 &target_core_dev_pr_res_holder
.attr
,
1606 &target_core_dev_pr_res_pr_all_tgt_pts
.attr
,
1607 &target_core_dev_pr_res_pr_generation
.attr
,
1608 &target_core_dev_pr_res_pr_holder_tg_port
.attr
,
1609 &target_core_dev_pr_res_pr_registered_i_pts
.attr
,
1610 &target_core_dev_pr_res_pr_type
.attr
,
1611 &target_core_dev_pr_res_type
.attr
,
1612 &target_core_dev_pr_res_aptpl_active
.attr
,
1613 &target_core_dev_pr_res_aptpl_metadata
.attr
,
1617 static struct configfs_item_operations target_core_dev_pr_ops
= {
1618 .show_attribute
= target_core_dev_pr_attr_show
,
1619 .store_attribute
= target_core_dev_pr_attr_store
,
1622 static struct config_item_type target_core_dev_pr_cit
= {
1623 .ct_item_ops
= &target_core_dev_pr_ops
,
1624 .ct_attrs
= target_core_dev_pr_attrs
,
1625 .ct_owner
= THIS_MODULE
,
1628 /* End functions for struct config_item_type target_core_dev_pr_cit */
1630 /* Start functions for struct config_item_type target_core_dev_cit */
1632 static ssize_t
target_core_show_dev_info(void *p
, char *page
)
1634 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1635 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1636 struct se_subsystem_api
*t
= hba
->transport
;
1638 ssize_t read_bytes
= 0;
1640 if (!(se_dev
->se_dev_ptr
))
1643 transport_dump_dev_state(se_dev
->se_dev_ptr
, page
, &bl
);
1645 read_bytes
+= t
->show_configfs_dev_params(hba
, se_dev
, page
+read_bytes
);
1649 static struct target_core_configfs_attribute target_core_attr_dev_info
= {
1650 .attr
= { .ca_owner
= THIS_MODULE
,
1652 .ca_mode
= S_IRUGO
},
1653 .show
= target_core_show_dev_info
,
1657 static ssize_t
target_core_store_dev_control(
1662 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1663 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1664 struct se_subsystem_api
*t
= hba
->transport
;
1666 if (!(se_dev
->se_dev_su_ptr
)) {
1667 printk(KERN_ERR
"Unable to locate struct se_subsystem_dev>se"
1672 return t
->set_configfs_dev_params(hba
, se_dev
, page
, count
);
1675 static struct target_core_configfs_attribute target_core_attr_dev_control
= {
1676 .attr
= { .ca_owner
= THIS_MODULE
,
1677 .ca_name
= "control",
1678 .ca_mode
= S_IWUSR
},
1680 .store
= target_core_store_dev_control
,
1683 static ssize_t
target_core_show_dev_alias(void *p
, char *page
)
1685 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1687 if (!(se_dev
->su_dev_flags
& SDF_USING_ALIAS
))
1690 return snprintf(page
, PAGE_SIZE
, "%s\n", se_dev
->se_dev_alias
);
1693 static ssize_t
target_core_store_dev_alias(
1698 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1699 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1702 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1703 printk(KERN_ERR
"alias count: %d exceeds"
1704 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1705 SE_DEV_ALIAS_LEN
-1);
1709 se_dev
->su_dev_flags
|= SDF_USING_ALIAS
;
1710 read_bytes
= snprintf(&se_dev
->se_dev_alias
[0], SE_DEV_ALIAS_LEN
,
1713 printk(KERN_INFO
"Target_Core_ConfigFS: %s/%s set alias: %s\n",
1714 config_item_name(&hba
->hba_group
.cg_item
),
1715 config_item_name(&se_dev
->se_dev_group
.cg_item
),
1716 se_dev
->se_dev_alias
);
1721 static struct target_core_configfs_attribute target_core_attr_dev_alias
= {
1722 .attr
= { .ca_owner
= THIS_MODULE
,
1724 .ca_mode
= S_IRUGO
| S_IWUSR
},
1725 .show
= target_core_show_dev_alias
,
1726 .store
= target_core_store_dev_alias
,
1729 static ssize_t
target_core_show_dev_udev_path(void *p
, char *page
)
1731 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1733 if (!(se_dev
->su_dev_flags
& SDF_USING_UDEV_PATH
))
1736 return snprintf(page
, PAGE_SIZE
, "%s\n", se_dev
->se_dev_udev_path
);
1739 static ssize_t
target_core_store_dev_udev_path(
1744 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1745 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1748 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1749 printk(KERN_ERR
"udev_path count: %d exceeds"
1750 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1751 SE_UDEV_PATH_LEN
-1);
1755 se_dev
->su_dev_flags
|= SDF_USING_UDEV_PATH
;
1756 read_bytes
= snprintf(&se_dev
->se_dev_udev_path
[0], SE_UDEV_PATH_LEN
,
1759 printk(KERN_INFO
"Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1760 config_item_name(&hba
->hba_group
.cg_item
),
1761 config_item_name(&se_dev
->se_dev_group
.cg_item
),
1762 se_dev
->se_dev_udev_path
);
1767 static struct target_core_configfs_attribute target_core_attr_dev_udev_path
= {
1768 .attr
= { .ca_owner
= THIS_MODULE
,
1769 .ca_name
= "udev_path",
1770 .ca_mode
= S_IRUGO
| S_IWUSR
},
1771 .show
= target_core_show_dev_udev_path
,
1772 .store
= target_core_store_dev_udev_path
,
1775 static ssize_t
target_core_store_dev_enable(
1780 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1781 struct se_device
*dev
;
1782 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1783 struct se_subsystem_api
*t
= hba
->transport
;
1786 ptr
= strstr(page
, "1");
1788 printk(KERN_ERR
"For dev_enable ops, only valid value"
1792 if ((se_dev
->se_dev_ptr
)) {
1793 printk(KERN_ERR
"se_dev->se_dev_ptr already set for storage"
1798 if (t
->check_configfs_dev_params(hba
, se_dev
) < 0)
1801 dev
= t
->create_virtdevice(hba
, se_dev
, se_dev
->se_dev_su_ptr
);
1802 if (!(dev
) || IS_ERR(dev
))
1805 se_dev
->se_dev_ptr
= dev
;
1806 printk(KERN_INFO
"Target_Core_ConfigFS: Registered se_dev->se_dev_ptr:"
1807 " %p\n", se_dev
->se_dev_ptr
);
1812 static struct target_core_configfs_attribute target_core_attr_dev_enable
= {
1813 .attr
= { .ca_owner
= THIS_MODULE
,
1814 .ca_name
= "enable",
1815 .ca_mode
= S_IWUSR
},
1817 .store
= target_core_store_dev_enable
,
1820 static ssize_t
target_core_show_alua_lu_gp(void *p
, char *page
)
1822 struct se_device
*dev
;
1823 struct se_subsystem_dev
*su_dev
= (struct se_subsystem_dev
*)p
;
1824 struct config_item
*lu_ci
;
1825 struct t10_alua_lu_gp
*lu_gp
;
1826 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1829 dev
= su_dev
->se_dev_ptr
;
1833 if (T10_ALUA(su_dev
)->alua_type
!= SPC3_ALUA_EMULATED
)
1836 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1838 printk(KERN_ERR
"NULL struct se_device->dev_alua_lu_gp_mem"
1843 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1844 lu_gp
= lu_gp_mem
->lu_gp
;
1846 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1847 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1848 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1850 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1855 static ssize_t
target_core_store_alua_lu_gp(
1860 struct se_device
*dev
;
1861 struct se_subsystem_dev
*su_dev
= (struct se_subsystem_dev
*)p
;
1862 struct se_hba
*hba
= su_dev
->se_dev_hba
;
1863 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1864 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1865 unsigned char buf
[LU_GROUP_NAME_BUF
];
1868 dev
= su_dev
->se_dev_ptr
;
1872 if (T10_ALUA(su_dev
)->alua_type
!= SPC3_ALUA_EMULATED
) {
1873 printk(KERN_WARNING
"SPC3_ALUA_EMULATED not enabled for %s/%s\n",
1874 config_item_name(&hba
->hba_group
.cg_item
),
1875 config_item_name(&su_dev
->se_dev_group
.cg_item
));
1878 if (count
> LU_GROUP_NAME_BUF
) {
1879 printk(KERN_ERR
"ALUA LU Group Alias too large!\n");
1882 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1883 memcpy(buf
, page
, count
);
1885 * Any ALUA logical unit alias besides "NULL" means we will be
1886 * making a new group association.
1888 if (strcmp(strstrip(buf
), "NULL")) {
1890 * core_alua_get_lu_gp_by_name() will increment reference to
1891 * struct t10_alua_lu_gp. This reference is released with
1892 * core_alua_get_lu_gp_by_name below().
1894 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
1898 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1901 core_alua_put_lu_gp_from_name(lu_gp_new
);
1902 printk(KERN_ERR
"NULL struct se_device->dev_alua_lu_gp_mem"
1907 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1908 lu_gp
= lu_gp_mem
->lu_gp
;
1911 * Clearing an existing lu_gp association, and replacing
1915 printk(KERN_INFO
"Target_Core_ConfigFS: Releasing %s/%s"
1916 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1918 config_item_name(&hba
->hba_group
.cg_item
),
1919 config_item_name(&su_dev
->se_dev_group
.cg_item
),
1920 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1923 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1924 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1929 * Removing existing association of lu_gp_mem with lu_gp
1931 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1935 * Associate lu_gp_mem with lu_gp_new.
1937 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
1938 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1940 printk(KERN_INFO
"Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1941 " core/alua/lu_gps/%s, ID: %hu\n",
1942 (move
) ? "Moving" : "Adding",
1943 config_item_name(&hba
->hba_group
.cg_item
),
1944 config_item_name(&su_dev
->se_dev_group
.cg_item
),
1945 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
1946 lu_gp_new
->lu_gp_id
);
1948 core_alua_put_lu_gp_from_name(lu_gp_new
);
1952 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp
= {
1953 .attr
= { .ca_owner
= THIS_MODULE
,
1954 .ca_name
= "alua_lu_gp",
1955 .ca_mode
= S_IRUGO
| S_IWUSR
},
1956 .show
= target_core_show_alua_lu_gp
,
1957 .store
= target_core_store_alua_lu_gp
,
1960 static struct configfs_attribute
*lio_core_dev_attrs
[] = {
1961 &target_core_attr_dev_info
.attr
,
1962 &target_core_attr_dev_control
.attr
,
1963 &target_core_attr_dev_alias
.attr
,
1964 &target_core_attr_dev_udev_path
.attr
,
1965 &target_core_attr_dev_enable
.attr
,
1966 &target_core_attr_dev_alua_lu_gp
.attr
,
1970 static void target_core_dev_release(struct config_item
*item
)
1972 struct se_subsystem_dev
*se_dev
= container_of(to_config_group(item
),
1973 struct se_subsystem_dev
, se_dev_group
);
1974 struct config_group
*dev_cg
;
1979 dev_cg
= &se_dev
->se_dev_group
;
1980 kfree(dev_cg
->default_groups
);
1983 static ssize_t
target_core_dev_show(struct config_item
*item
,
1984 struct configfs_attribute
*attr
,
1987 struct se_subsystem_dev
*se_dev
= container_of(
1988 to_config_group(item
), struct se_subsystem_dev
,
1990 struct target_core_configfs_attribute
*tc_attr
= container_of(
1991 attr
, struct target_core_configfs_attribute
, attr
);
1993 if (!(tc_attr
->show
))
1996 return tc_attr
->show((void *)se_dev
, page
);
1999 static ssize_t
target_core_dev_store(struct config_item
*item
,
2000 struct configfs_attribute
*attr
,
2001 const char *page
, size_t count
)
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
);
2009 if (!(tc_attr
->store
))
2012 return tc_attr
->store((void *)se_dev
, page
, count
);
2015 static struct configfs_item_operations target_core_dev_item_ops
= {
2016 .release
= target_core_dev_release
,
2017 .show_attribute
= target_core_dev_show
,
2018 .store_attribute
= target_core_dev_store
,
2021 static struct config_item_type target_core_dev_cit
= {
2022 .ct_item_ops
= &target_core_dev_item_ops
,
2023 .ct_attrs
= lio_core_dev_attrs
,
2024 .ct_owner
= THIS_MODULE
,
2027 /* End functions for struct config_item_type target_core_dev_cit */
2029 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
2031 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp
, t10_alua_lu_gp
);
2032 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
2033 static struct target_core_alua_lu_gp_attribute \
2034 target_core_alua_lu_gp_##_name = \
2035 __CONFIGFS_EATTR(_name, _mode, \
2036 target_core_alua_lu_gp_show_attr_##_name, \
2037 target_core_alua_lu_gp_store_attr_##_name);
2039 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
2040 static struct target_core_alua_lu_gp_attribute \
2041 target_core_alua_lu_gp_##_name = \
2042 __CONFIGFS_EATTR_RO(_name, \
2043 target_core_alua_lu_gp_show_attr_##_name);
2048 static ssize_t
target_core_alua_lu_gp_show_attr_lu_gp_id(
2049 struct t10_alua_lu_gp
*lu_gp
,
2052 if (!(lu_gp
->lu_gp_valid_id
))
2055 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
2058 static ssize_t
target_core_alua_lu_gp_store_attr_lu_gp_id(
2059 struct t10_alua_lu_gp
*lu_gp
,
2063 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2064 unsigned long lu_gp_id
;
2067 ret
= strict_strtoul(page
, 0, &lu_gp_id
);
2069 printk(KERN_ERR
"strict_strtoul() returned %d for"
2070 " lu_gp_id\n", ret
);
2073 if (lu_gp_id
> 0x0000ffff) {
2074 printk(KERN_ERR
"ALUA lu_gp_id: %lu exceeds maximum:"
2075 " 0x0000ffff\n", lu_gp_id
);
2079 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
2083 printk(KERN_INFO
"Target_Core_ConfigFS: Set ALUA Logical Unit"
2084 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2085 config_item_name(&alua_lu_gp_cg
->cg_item
),
2091 SE_DEV_ALUA_LU_ATTR(lu_gp_id
, S_IRUGO
| S_IWUSR
);
2096 static ssize_t
target_core_alua_lu_gp_show_attr_members(
2097 struct t10_alua_lu_gp
*lu_gp
,
2100 struct se_device
*dev
;
2102 struct se_subsystem_dev
*su_dev
;
2103 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2104 ssize_t len
= 0, cur_len
;
2105 unsigned char buf
[LU_GROUP_NAME_BUF
];
2107 memset(buf
, 0, LU_GROUP_NAME_BUF
);
2109 spin_lock(&lu_gp
->lu_gp_lock
);
2110 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
2111 dev
= lu_gp_mem
->lu_gp_mem_dev
;
2112 su_dev
= dev
->se_sub_dev
;
2113 hba
= su_dev
->se_dev_hba
;
2115 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
2116 config_item_name(&hba
->hba_group
.cg_item
),
2117 config_item_name(&su_dev
->se_dev_group
.cg_item
));
2118 cur_len
++; /* Extra byte for NULL terminator */
2120 if ((cur_len
+ len
) > PAGE_SIZE
) {
2121 printk(KERN_WARNING
"Ran out of lu_gp_show_attr"
2122 "_members buffer\n");
2125 memcpy(page
+len
, buf
, cur_len
);
2128 spin_unlock(&lu_gp
->lu_gp_lock
);
2133 SE_DEV_ALUA_LU_ATTR_RO(members
);
2135 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp
, t10_alua_lu_gp
, lu_gp_group
);
2137 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
2138 &target_core_alua_lu_gp_lu_gp_id
.attr
,
2139 &target_core_alua_lu_gp_members
.attr
,
2143 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
2144 .show_attribute
= target_core_alua_lu_gp_attr_show
,
2145 .store_attribute
= target_core_alua_lu_gp_attr_store
,
2148 static struct config_item_type target_core_alua_lu_gp_cit
= {
2149 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
2150 .ct_attrs
= target_core_alua_lu_gp_attrs
,
2151 .ct_owner
= THIS_MODULE
,
2154 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
2156 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
2158 static struct config_group
*target_core_alua_create_lu_gp(
2159 struct config_group
*group
,
2162 struct t10_alua_lu_gp
*lu_gp
;
2163 struct config_group
*alua_lu_gp_cg
= NULL
;
2164 struct config_item
*alua_lu_gp_ci
= NULL
;
2166 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
2170 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2171 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
2173 config_group_init_type_name(alua_lu_gp_cg
, name
,
2174 &target_core_alua_lu_gp_cit
);
2176 printk(KERN_INFO
"Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2177 " Group: core/alua/lu_gps/%s\n",
2178 config_item_name(alua_lu_gp_ci
));
2180 return alua_lu_gp_cg
;
2184 static void target_core_alua_drop_lu_gp(
2185 struct config_group
*group
,
2186 struct config_item
*item
)
2188 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2189 struct t10_alua_lu_gp
, lu_gp_group
);
2191 printk(KERN_INFO
"Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2192 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2193 config_item_name(item
), lu_gp
->lu_gp_id
);
2195 config_item_put(item
);
2196 core_alua_free_lu_gp(lu_gp
);
2199 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
2200 .make_group
= &target_core_alua_create_lu_gp
,
2201 .drop_item
= &target_core_alua_drop_lu_gp
,
2204 static struct config_item_type target_core_alua_lu_gps_cit
= {
2205 .ct_item_ops
= NULL
,
2206 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
2207 .ct_owner
= THIS_MODULE
,
2210 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
2212 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2214 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
);
2215 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
2216 static struct target_core_alua_tg_pt_gp_attribute \
2217 target_core_alua_tg_pt_gp_##_name = \
2218 __CONFIGFS_EATTR(_name, _mode, \
2219 target_core_alua_tg_pt_gp_show_attr_##_name, \
2220 target_core_alua_tg_pt_gp_store_attr_##_name);
2222 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2223 static struct target_core_alua_tg_pt_gp_attribute \
2224 target_core_alua_tg_pt_gp_##_name = \
2225 __CONFIGFS_EATTR_RO(_name, \
2226 target_core_alua_tg_pt_gp_show_attr_##_name);
2231 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2232 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2235 return sprintf(page
, "%d\n",
2236 atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
));
2239 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2240 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2244 struct se_subsystem_dev
*su_dev
= tg_pt_gp
->tg_pt_gp_su_dev
;
2248 if (!(tg_pt_gp
->tg_pt_gp_valid_id
)) {
2249 printk(KERN_ERR
"Unable to do implict ALUA on non valid"
2250 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2254 ret
= strict_strtoul(page
, 0, &tmp
);
2256 printk("Unable to extract new ALUA access state from"
2260 new_state
= (int)tmp
;
2262 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICT_ALUA
)) {
2263 printk(KERN_ERR
"Unable to process implict configfs ALUA"
2264 " transition while TPGS_IMPLICT_ALUA is diabled\n");
2268 ret
= core_alua_do_port_transition(tg_pt_gp
, su_dev
->se_dev_ptr
,
2269 NULL
, NULL
, new_state
, 0);
2270 return (!ret
) ? count
: -EINVAL
;
2273 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state
, S_IRUGO
| S_IWUSR
);
2276 * alua_access_status
2278 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2279 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2282 return sprintf(page
, "%s\n",
2283 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2286 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2287 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2292 int new_status
, ret
;
2294 if (!(tg_pt_gp
->tg_pt_gp_valid_id
)) {
2295 printk(KERN_ERR
"Unable to do set ALUA access status on non"
2296 " valid tg_pt_gp ID: %hu\n",
2297 tg_pt_gp
->tg_pt_gp_valid_id
);
2301 ret
= strict_strtoul(page
, 0, &tmp
);
2303 printk(KERN_ERR
"Unable to extract new ALUA access status"
2304 " from %s\n", page
);
2307 new_status
= (int)tmp
;
2309 if ((new_status
!= ALUA_STATUS_NONE
) &&
2310 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
) &&
2311 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
)) {
2312 printk(KERN_ERR
"Illegal ALUA access status: 0x%02x\n",
2317 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2321 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status
, S_IRUGO
| S_IWUSR
);
2326 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2327 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2330 return core_alua_show_access_type(tg_pt_gp
, page
);
2333 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2334 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2338 return core_alua_store_access_type(tg_pt_gp
, page
, count
);
2341 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type
, S_IRUGO
| S_IWUSR
);
2344 * alua_write_metadata
2346 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2347 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2350 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_write_metadata
);
2353 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2354 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2361 ret
= strict_strtoul(page
, 0, &tmp
);
2363 printk(KERN_ERR
"Unable to extract alua_write_metadata\n");
2367 if ((tmp
!= 0) && (tmp
!= 1)) {
2368 printk(KERN_ERR
"Illegal value for alua_write_metadata:"
2372 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2377 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata
, S_IRUGO
| S_IWUSR
);
2384 static ssize_t
target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2385 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2388 return core_alua_show_nonop_delay_msecs(tg_pt_gp
, page
);
2392 static ssize_t
target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2393 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2397 return core_alua_store_nonop_delay_msecs(tg_pt_gp
, page
, count
);
2400 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs
, S_IRUGO
| S_IWUSR
);
2405 static ssize_t
target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2406 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2409 return core_alua_show_trans_delay_msecs(tg_pt_gp
, page
);
2412 static ssize_t
target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2413 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2417 return core_alua_store_trans_delay_msecs(tg_pt_gp
, page
, count
);
2420 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs
, S_IRUGO
| S_IWUSR
);
2426 static ssize_t
target_core_alua_tg_pt_gp_show_attr_preferred(
2427 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2430 return core_alua_show_preferred_bit(tg_pt_gp
, page
);
2433 static ssize_t
target_core_alua_tg_pt_gp_store_attr_preferred(
2434 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2438 return core_alua_store_preferred_bit(tg_pt_gp
, page
, count
);
2441 SE_DEV_ALUA_TG_PT_ATTR(preferred
, S_IRUGO
| S_IWUSR
);
2446 static ssize_t
target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2447 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2450 if (!(tg_pt_gp
->tg_pt_gp_valid_id
))
2453 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2456 static ssize_t
target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2457 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2461 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2462 unsigned long tg_pt_gp_id
;
2465 ret
= strict_strtoul(page
, 0, &tg_pt_gp_id
);
2467 printk(KERN_ERR
"strict_strtoul() returned %d for"
2468 " tg_pt_gp_id\n", ret
);
2471 if (tg_pt_gp_id
> 0x0000ffff) {
2472 printk(KERN_ERR
"ALUA tg_pt_gp_id: %lu exceeds maximum:"
2473 " 0x0000ffff\n", tg_pt_gp_id
);
2477 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2481 printk(KERN_INFO
"Target_Core_ConfigFS: Set ALUA Target Port Group: "
2482 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2483 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2484 tg_pt_gp
->tg_pt_gp_id
);
2489 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id
, S_IRUGO
| S_IWUSR
);
2494 static ssize_t
target_core_alua_tg_pt_gp_show_attr_members(
2495 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2498 struct se_port
*port
;
2499 struct se_portal_group
*tpg
;
2501 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
2502 ssize_t len
= 0, cur_len
;
2503 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2505 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2507 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2508 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
2509 tg_pt_gp_mem_list
) {
2510 port
= tg_pt_gp_mem
->tg_pt
;
2511 tpg
= port
->sep_tpg
;
2512 lun
= port
->sep_lun
;
2514 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2515 "/%s\n", TPG_TFO(tpg
)->get_fabric_name(),
2516 TPG_TFO(tpg
)->tpg_get_wwn(tpg
),
2517 TPG_TFO(tpg
)->tpg_get_tag(tpg
),
2518 config_item_name(&lun
->lun_group
.cg_item
));
2519 cur_len
++; /* Extra byte for NULL terminator */
2521 if ((cur_len
+ len
) > PAGE_SIZE
) {
2522 printk(KERN_WARNING
"Ran out of lu_gp_show_attr"
2523 "_members buffer\n");
2526 memcpy(page
+len
, buf
, cur_len
);
2529 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2534 SE_DEV_ALUA_TG_PT_ATTR_RO(members
);
2536 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
,
2539 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2540 &target_core_alua_tg_pt_gp_alua_access_state
.attr
,
2541 &target_core_alua_tg_pt_gp_alua_access_status
.attr
,
2542 &target_core_alua_tg_pt_gp_alua_access_type
.attr
,
2543 &target_core_alua_tg_pt_gp_alua_write_metadata
.attr
,
2544 &target_core_alua_tg_pt_gp_nonop_delay_msecs
.attr
,
2545 &target_core_alua_tg_pt_gp_trans_delay_msecs
.attr
,
2546 &target_core_alua_tg_pt_gp_preferred
.attr
,
2547 &target_core_alua_tg_pt_gp_tg_pt_gp_id
.attr
,
2548 &target_core_alua_tg_pt_gp_members
.attr
,
2552 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2553 .show_attribute
= target_core_alua_tg_pt_gp_attr_show
,
2554 .store_attribute
= target_core_alua_tg_pt_gp_attr_store
,
2557 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2558 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2559 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2560 .ct_owner
= THIS_MODULE
,
2563 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2565 /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2567 static struct config_group
*target_core_alua_create_tg_pt_gp(
2568 struct config_group
*group
,
2571 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2572 alua_tg_pt_gps_group
);
2573 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2574 struct se_subsystem_dev
*su_dev
= alua
->t10_sub_dev
;
2575 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2576 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2578 tg_pt_gp
= core_alua_allocate_tg_pt_gp(su_dev
, name
, 0);
2582 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2583 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2585 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2586 &target_core_alua_tg_pt_gp_cit
);
2588 printk(KERN_INFO
"Target_Core_ConfigFS: Allocated ALUA Target Port"
2589 " Group: alua/tg_pt_gps/%s\n",
2590 config_item_name(alua_tg_pt_gp_ci
));
2592 return alua_tg_pt_gp_cg
;
2595 static void target_core_alua_drop_tg_pt_gp(
2596 struct config_group
*group
,
2597 struct config_item
*item
)
2599 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2600 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2602 printk(KERN_INFO
"Target_Core_ConfigFS: Releasing ALUA Target Port"
2603 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2604 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2606 config_item_put(item
);
2607 core_alua_free_tg_pt_gp(tg_pt_gp
);
2610 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2611 .make_group
= &target_core_alua_create_tg_pt_gp
,
2612 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2615 static struct config_item_type target_core_alua_tg_pt_gps_cit
= {
2616 .ct_group_ops
= &target_core_alua_tg_pt_gps_group_ops
,
2617 .ct_owner
= THIS_MODULE
,
2620 /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2622 /* Start functions for struct config_item_type target_core_alua_cit */
2625 * target_core_alua_cit is a ConfigFS group that lives under
2626 * /sys/kernel/config/target/core/alua. There are default groups
2627 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2628 * target_core_alua_cit in target_core_init_configfs() below.
2630 static struct config_item_type target_core_alua_cit
= {
2631 .ct_item_ops
= NULL
,
2633 .ct_owner
= THIS_MODULE
,
2636 /* End functions for struct config_item_type target_core_alua_cit */
2638 /* Start functions for struct config_item_type target_core_hba_cit */
2640 static struct config_group
*target_core_make_subdev(
2641 struct config_group
*group
,
2644 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2645 struct se_subsystem_dev
*se_dev
;
2646 struct se_subsystem_api
*t
;
2647 struct config_item
*hba_ci
= &group
->cg_item
;
2648 struct se_hba
*hba
= item_to_hba(hba_ci
);
2649 struct config_group
*dev_cg
= NULL
, *tg_pt_gp_cg
= NULL
;
2651 if (mutex_lock_interruptible(&hba
->hba_access_mutex
))
2655 * Locate the struct se_subsystem_api from parent's struct se_hba.
2659 se_dev
= kzalloc(sizeof(struct se_subsystem_dev
), GFP_KERNEL
);
2661 printk(KERN_ERR
"Unable to allocate memory for"
2662 " struct se_subsystem_dev\n");
2665 INIT_LIST_HEAD(&se_dev
->g_se_dev_list
);
2666 INIT_LIST_HEAD(&se_dev
->t10_wwn
.t10_vpd_list
);
2667 spin_lock_init(&se_dev
->t10_wwn
.t10_vpd_lock
);
2668 INIT_LIST_HEAD(&se_dev
->t10_reservation
.registration_list
);
2669 INIT_LIST_HEAD(&se_dev
->t10_reservation
.aptpl_reg_list
);
2670 spin_lock_init(&se_dev
->t10_reservation
.registration_lock
);
2671 spin_lock_init(&se_dev
->t10_reservation
.aptpl_reg_lock
);
2672 INIT_LIST_HEAD(&se_dev
->t10_alua
.tg_pt_gps_list
);
2673 spin_lock_init(&se_dev
->t10_alua
.tg_pt_gps_lock
);
2674 spin_lock_init(&se_dev
->se_dev_lock
);
2675 se_dev
->t10_reservation
.pr_aptpl_buf_len
= PR_APTPL_BUF_LEN
;
2676 se_dev
->t10_wwn
.t10_sub_dev
= se_dev
;
2677 se_dev
->t10_alua
.t10_sub_dev
= se_dev
;
2678 se_dev
->se_dev_attrib
.da_sub_dev
= se_dev
;
2680 se_dev
->se_dev_hba
= hba
;
2681 dev_cg
= &se_dev
->se_dev_group
;
2683 dev_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 6,
2685 if (!(dev_cg
->default_groups
))
2688 * Set se_dev_su_ptr from struct se_subsystem_api returned void ptr
2689 * for ->allocate_virtdevice()
2691 * se_dev->se_dev_ptr will be set after ->create_virtdev()
2692 * has been called successfully in the next level up in the
2693 * configfs tree for device object's struct config_group.
2695 se_dev
->se_dev_su_ptr
= t
->allocate_virtdevice(hba
, name
);
2696 if (!(se_dev
->se_dev_su_ptr
)) {
2697 printk(KERN_ERR
"Unable to locate subsystem dependent pointer"
2698 " from allocate_virtdevice()\n");
2701 spin_lock(&se_global
->g_device_lock
);
2702 list_add_tail(&se_dev
->g_se_dev_list
, &se_global
->g_se_dev_list
);
2703 spin_unlock(&se_global
->g_device_lock
);
2705 config_group_init_type_name(&se_dev
->se_dev_group
, name
,
2706 &target_core_dev_cit
);
2707 config_group_init_type_name(&se_dev
->se_dev_attrib
.da_group
, "attrib",
2708 &target_core_dev_attrib_cit
);
2709 config_group_init_type_name(&se_dev
->se_dev_pr_group
, "pr",
2710 &target_core_dev_pr_cit
);
2711 config_group_init_type_name(&se_dev
->t10_wwn
.t10_wwn_group
, "wwn",
2712 &target_core_dev_wwn_cit
);
2713 config_group_init_type_name(&se_dev
->t10_alua
.alua_tg_pt_gps_group
,
2714 "alua", &target_core_alua_tg_pt_gps_cit
);
2715 dev_cg
->default_groups
[0] = &se_dev
->se_dev_attrib
.da_group
;
2716 dev_cg
->default_groups
[1] = &se_dev
->se_dev_pr_group
;
2717 dev_cg
->default_groups
[2] = &se_dev
->t10_wwn
.t10_wwn_group
;
2718 dev_cg
->default_groups
[3] = &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2719 dev_cg
->default_groups
[4] = NULL
;
2721 * Add core/$HBA/$DEV/alua/tg_pt_gps/default_tg_pt_gp
2723 tg_pt_gp
= core_alua_allocate_tg_pt_gp(se_dev
, "default_tg_pt_gp", 1);
2727 tg_pt_gp_cg
= &T10_ALUA(se_dev
)->alua_tg_pt_gps_group
;
2728 tg_pt_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
2730 if (!(tg_pt_gp_cg
->default_groups
)) {
2731 printk(KERN_ERR
"Unable to allocate tg_pt_gp_cg->"
2732 "default_groups\n");
2736 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2737 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2738 tg_pt_gp_cg
->default_groups
[0] = &tg_pt_gp
->tg_pt_gp_group
;
2739 tg_pt_gp_cg
->default_groups
[1] = NULL
;
2740 T10_ALUA(se_dev
)->default_tg_pt_gp
= tg_pt_gp
;
2742 printk(KERN_INFO
"Target_Core_ConfigFS: Allocated struct se_subsystem_dev:"
2743 " %p se_dev_su_ptr: %p\n", se_dev
, se_dev
->se_dev_su_ptr
);
2745 mutex_unlock(&hba
->hba_access_mutex
);
2746 return &se_dev
->se_dev_group
;
2748 if (T10_ALUA(se_dev
)->default_tg_pt_gp
) {
2749 core_alua_free_tg_pt_gp(T10_ALUA(se_dev
)->default_tg_pt_gp
);
2750 T10_ALUA(se_dev
)->default_tg_pt_gp
= NULL
;
2753 kfree(tg_pt_gp_cg
->default_groups
);
2755 kfree(dev_cg
->default_groups
);
2756 if (se_dev
->se_dev_su_ptr
)
2757 t
->free_device(se_dev
->se_dev_su_ptr
);
2760 mutex_unlock(&hba
->hba_access_mutex
);
2764 static void target_core_drop_subdev(
2765 struct config_group
*group
,
2766 struct config_item
*item
)
2768 struct se_subsystem_dev
*se_dev
= container_of(to_config_group(item
),
2769 struct se_subsystem_dev
, se_dev_group
);
2771 struct se_subsystem_api
*t
;
2772 struct config_item
*df_item
;
2773 struct config_group
*dev_cg
, *tg_pt_gp_cg
;
2776 hba
= item_to_hba(&se_dev
->se_dev_hba
->hba_group
.cg_item
);
2778 if (mutex_lock_interruptible(&hba
->hba_access_mutex
))
2783 spin_lock(&se_global
->g_device_lock
);
2784 list_del(&se_dev
->g_se_dev_list
);
2785 spin_unlock(&se_global
->g_device_lock
);
2787 tg_pt_gp_cg
= &T10_ALUA(se_dev
)->alua_tg_pt_gps_group
;
2788 for (i
= 0; tg_pt_gp_cg
->default_groups
[i
]; i
++) {
2789 df_item
= &tg_pt_gp_cg
->default_groups
[i
]->cg_item
;
2790 tg_pt_gp_cg
->default_groups
[i
] = NULL
;
2791 config_item_put(df_item
);
2793 kfree(tg_pt_gp_cg
->default_groups
);
2794 core_alua_free_tg_pt_gp(T10_ALUA(se_dev
)->default_tg_pt_gp
);
2795 T10_ALUA(se_dev
)->default_tg_pt_gp
= NULL
;
2797 dev_cg
= &se_dev
->se_dev_group
;
2798 for (i
= 0; dev_cg
->default_groups
[i
]; i
++) {
2799 df_item
= &dev_cg
->default_groups
[i
]->cg_item
;
2800 dev_cg
->default_groups
[i
] = NULL
;
2801 config_item_put(df_item
);
2804 config_item_put(item
);
2806 * This pointer will set when the storage is enabled with:
2807 * `echo 1 > $CONFIGFS/core/$HBA/$DEV/dev_enable`
2809 if (se_dev
->se_dev_ptr
) {
2810 printk(KERN_INFO
"Target_Core_ConfigFS: Calling se_free_"
2811 "virtual_device() for se_dev_ptr: %p\n",
2812 se_dev
->se_dev_ptr
);
2814 ret
= se_free_virtual_device(se_dev
->se_dev_ptr
, hba
);
2819 * Release struct se_subsystem_dev->se_dev_su_ptr..
2821 printk(KERN_INFO
"Target_Core_ConfigFS: Calling t->free_"
2822 "device() for se_dev_su_ptr: %p\n",
2823 se_dev
->se_dev_su_ptr
);
2825 t
->free_device(se_dev
->se_dev_su_ptr
);
2828 printk(KERN_INFO
"Target_Core_ConfigFS: Deallocating se_subsystem"
2829 "_dev_t: %p\n", se_dev
);
2832 mutex_unlock(&hba
->hba_access_mutex
);
2837 static struct configfs_group_operations target_core_hba_group_ops
= {
2838 .make_group
= target_core_make_subdev
,
2839 .drop_item
= target_core_drop_subdev
,
2842 CONFIGFS_EATTR_STRUCT(target_core_hba
, se_hba
);
2843 #define SE_HBA_ATTR(_name, _mode) \
2844 static struct target_core_hba_attribute \
2845 target_core_hba_##_name = \
2846 __CONFIGFS_EATTR(_name, _mode, \
2847 target_core_hba_show_attr_##_name, \
2848 target_core_hba_store_attr_##_name);
2850 #define SE_HBA_ATTR_RO(_name) \
2851 static struct target_core_hba_attribute \
2852 target_core_hba_##_name = \
2853 __CONFIGFS_EATTR_RO(_name, \
2854 target_core_hba_show_attr_##_name);
2856 static ssize_t
target_core_hba_show_attr_hba_info(
2860 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
2861 hba
->hba_id
, hba
->transport
->name
,
2862 TARGET_CORE_CONFIGFS_VERSION
);
2865 SE_HBA_ATTR_RO(hba_info
);
2867 static ssize_t
target_core_hba_show_attr_hba_mode(struct se_hba
*hba
,
2872 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
2875 return sprintf(page
, "%d\n", hba_mode
);
2878 static ssize_t
target_core_hba_store_attr_hba_mode(struct se_hba
*hba
,
2879 const char *page
, size_t count
)
2881 struct se_subsystem_api
*transport
= hba
->transport
;
2882 unsigned long mode_flag
;
2885 if (transport
->pmode_enable_hba
== NULL
)
2888 ret
= strict_strtoul(page
, 0, &mode_flag
);
2890 printk(KERN_ERR
"Unable to extract hba mode flag: %d\n", ret
);
2894 spin_lock(&hba
->device_lock
);
2895 if (!(list_empty(&hba
->hba_dev_list
))) {
2896 printk(KERN_ERR
"Unable to set hba_mode with active devices\n");
2897 spin_unlock(&hba
->device_lock
);
2900 spin_unlock(&hba
->device_lock
);
2902 ret
= transport
->pmode_enable_hba(hba
, mode_flag
);
2906 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
2908 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
2913 SE_HBA_ATTR(hba_mode
, S_IRUGO
| S_IWUSR
);
2915 CONFIGFS_EATTR_OPS(target_core_hba
, se_hba
, hba_group
);
2917 static struct configfs_attribute
*target_core_hba_attrs
[] = {
2918 &target_core_hba_hba_info
.attr
,
2919 &target_core_hba_hba_mode
.attr
,
2923 static struct configfs_item_operations target_core_hba_item_ops
= {
2924 .show_attribute
= target_core_hba_attr_show
,
2925 .store_attribute
= target_core_hba_attr_store
,
2928 static struct config_item_type target_core_hba_cit
= {
2929 .ct_item_ops
= &target_core_hba_item_ops
,
2930 .ct_group_ops
= &target_core_hba_group_ops
,
2931 .ct_attrs
= target_core_hba_attrs
,
2932 .ct_owner
= THIS_MODULE
,
2935 static struct config_group
*target_core_call_addhbatotarget(
2936 struct config_group
*group
,
2939 char *se_plugin_str
, *str
, *str2
;
2941 char buf
[TARGET_CORE_NAME_MAX_LEN
];
2942 unsigned long plugin_dep_id
= 0;
2945 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
2946 if (strlen(name
) > TARGET_CORE_NAME_MAX_LEN
) {
2947 printk(KERN_ERR
"Passed *name strlen(): %d exceeds"
2948 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
2949 TARGET_CORE_NAME_MAX_LEN
);
2950 return ERR_PTR(-ENAMETOOLONG
);
2952 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
2954 str
= strstr(buf
, "_");
2956 printk(KERN_ERR
"Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
2957 return ERR_PTR(-EINVAL
);
2959 se_plugin_str
= buf
;
2961 * Special case for subsystem plugins that have "_" in their names.
2962 * Namely rd_direct and rd_mcp..
2964 str2
= strstr(str
+1, "_");
2966 *str2
= '\0'; /* Terminate for *se_plugin_str */
2967 str2
++; /* Skip to start of plugin dependent ID */
2970 *str
= '\0'; /* Terminate for *se_plugin_str */
2971 str
++; /* Skip to start of plugin dependent ID */
2974 ret
= strict_strtoul(str
, 0, &plugin_dep_id
);
2976 printk(KERN_ERR
"strict_strtoul() returned %d for"
2977 " plugin_dep_id\n", ret
);
2978 return ERR_PTR(-EINVAL
);
2981 * Load up TCM subsystem plugins if they have not already been loaded.
2983 if (transport_subsystem_check_init() < 0)
2984 return ERR_PTR(-EINVAL
);
2986 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
2988 return ERR_CAST(hba
);
2990 config_group_init_type_name(&hba
->hba_group
, name
,
2991 &target_core_hba_cit
);
2993 return &hba
->hba_group
;
2996 static void target_core_call_delhbafromtarget(
2997 struct config_group
*group
,
2998 struct config_item
*item
)
3000 struct se_hba
*hba
= item_to_hba(item
);
3002 config_item_put(item
);
3003 core_delete_hba(hba
);
3006 static struct configfs_group_operations target_core_group_ops
= {
3007 .make_group
= target_core_call_addhbatotarget
,
3008 .drop_item
= target_core_call_delhbafromtarget
,
3011 static struct config_item_type target_core_cit
= {
3012 .ct_item_ops
= NULL
,
3013 .ct_group_ops
= &target_core_group_ops
,
3015 .ct_owner
= THIS_MODULE
,
3018 /* Stop functions for struct config_item_type target_core_hba_cit */
3020 static int target_core_init_configfs(void)
3022 struct config_group
*target_cg
, *hba_cg
= NULL
, *alua_cg
= NULL
;
3023 struct config_group
*lu_gp_cg
= NULL
;
3024 struct configfs_subsystem
*subsys
;
3025 struct proc_dir_entry
*scsi_target_proc
= NULL
;
3026 struct t10_alua_lu_gp
*lu_gp
;
3029 printk(KERN_INFO
"TARGET_CORE[0]: Loading Generic Kernel Storage"
3030 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
3031 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
3033 subsys
= target_core_subsystem
[0];
3034 config_group_init(&subsys
->su_group
);
3035 mutex_init(&subsys
->su_mutex
);
3037 INIT_LIST_HEAD(&g_tf_list
);
3038 mutex_init(&g_tf_lock
);
3039 init_scsi_index_table();
3040 ret
= init_se_global();
3044 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
3045 * and ALUA Logical Unit Group and Target Port Group infrastructure.
3047 target_cg
= &subsys
->su_group
;
3048 target_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3050 if (!(target_cg
->default_groups
)) {
3051 printk(KERN_ERR
"Unable to allocate target_cg->default_groups\n");
3055 config_group_init_type_name(&se_global
->target_core_hbagroup
,
3056 "core", &target_core_cit
);
3057 target_cg
->default_groups
[0] = &se_global
->target_core_hbagroup
;
3058 target_cg
->default_groups
[1] = NULL
;
3060 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
3062 hba_cg
= &se_global
->target_core_hbagroup
;
3063 hba_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3065 if (!(hba_cg
->default_groups
)) {
3066 printk(KERN_ERR
"Unable to allocate hba_cg->default_groups\n");
3069 config_group_init_type_name(&se_global
->alua_group
,
3070 "alua", &target_core_alua_cit
);
3071 hba_cg
->default_groups
[0] = &se_global
->alua_group
;
3072 hba_cg
->default_groups
[1] = NULL
;
3074 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
3075 * groups under /sys/kernel/config/target/core/alua/
3077 alua_cg
= &se_global
->alua_group
;
3078 alua_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3080 if (!(alua_cg
->default_groups
)) {
3081 printk(KERN_ERR
"Unable to allocate alua_cg->default_groups\n");
3085 config_group_init_type_name(&se_global
->alua_lu_gps_group
,
3086 "lu_gps", &target_core_alua_lu_gps_cit
);
3087 alua_cg
->default_groups
[0] = &se_global
->alua_lu_gps_group
;
3088 alua_cg
->default_groups
[1] = NULL
;
3090 * Add core/alua/lu_gps/default_lu_gp
3092 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
3096 lu_gp_cg
= &se_global
->alua_lu_gps_group
;
3097 lu_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3099 if (!(lu_gp_cg
->default_groups
)) {
3100 printk(KERN_ERR
"Unable to allocate lu_gp_cg->default_groups\n");
3104 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
3105 &target_core_alua_lu_gp_cit
);
3106 lu_gp_cg
->default_groups
[0] = &lu_gp
->lu_gp_group
;
3107 lu_gp_cg
->default_groups
[1] = NULL
;
3108 se_global
->default_lu_gp
= lu_gp
;
3110 * Register the target_core_mod subsystem with configfs.
3112 ret
= configfs_register_subsystem(subsys
);
3114 printk(KERN_ERR
"Error %d while registering subsystem %s\n",
3115 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
3118 printk(KERN_INFO
"TARGET_CORE[0]: Initialized ConfigFS Fabric"
3119 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION
" on %s/%s"
3120 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
3122 * Register built-in RAMDISK subsystem logic for virtual LUN 0
3124 ret
= rd_module_init();
3128 if (core_dev_setup_virtual_lun0() < 0)
3131 scsi_target_proc
= proc_mkdir("scsi_target", 0);
3132 if (!(scsi_target_proc
)) {
3133 printk(KERN_ERR
"proc_mkdir(scsi_target, 0) failed\n");
3136 ret
= init_scsi_target_mib();
3143 configfs_unregister_subsystem(subsys
);
3144 if (scsi_target_proc
)
3145 remove_proc_entry("scsi_target", 0);
3146 core_dev_release_virtual_lun0();
3149 if (se_global
->default_lu_gp
) {
3150 core_alua_free_lu_gp(se_global
->default_lu_gp
);
3151 se_global
->default_lu_gp
= NULL
;
3154 kfree(lu_gp_cg
->default_groups
);
3156 kfree(alua_cg
->default_groups
);
3158 kfree(hba_cg
->default_groups
);
3159 kfree(target_cg
->default_groups
);
3160 release_se_global();
3164 static void target_core_exit_configfs(void)
3166 struct configfs_subsystem
*subsys
;
3167 struct config_group
*hba_cg
, *alua_cg
, *lu_gp_cg
;
3168 struct config_item
*item
;
3171 se_global
->in_shutdown
= 1;
3172 subsys
= target_core_subsystem
[0];
3174 lu_gp_cg
= &se_global
->alua_lu_gps_group
;
3175 for (i
= 0; lu_gp_cg
->default_groups
[i
]; i
++) {
3176 item
= &lu_gp_cg
->default_groups
[i
]->cg_item
;
3177 lu_gp_cg
->default_groups
[i
] = NULL
;
3178 config_item_put(item
);
3180 kfree(lu_gp_cg
->default_groups
);
3181 core_alua_free_lu_gp(se_global
->default_lu_gp
);
3182 se_global
->default_lu_gp
= NULL
;
3184 alua_cg
= &se_global
->alua_group
;
3185 for (i
= 0; alua_cg
->default_groups
[i
]; i
++) {
3186 item
= &alua_cg
->default_groups
[i
]->cg_item
;
3187 alua_cg
->default_groups
[i
] = NULL
;
3188 config_item_put(item
);
3190 kfree(alua_cg
->default_groups
);
3192 hba_cg
= &se_global
->target_core_hbagroup
;
3193 for (i
= 0; hba_cg
->default_groups
[i
]; i
++) {
3194 item
= &hba_cg
->default_groups
[i
]->cg_item
;
3195 hba_cg
->default_groups
[i
] = NULL
;
3196 config_item_put(item
);
3198 kfree(hba_cg
->default_groups
);
3200 for (i
= 0; subsys
->su_group
.default_groups
[i
]; i
++) {
3201 item
= &subsys
->su_group
.default_groups
[i
]->cg_item
;
3202 subsys
->su_group
.default_groups
[i
] = NULL
;
3203 config_item_put(item
);
3205 kfree(subsys
->su_group
.default_groups
);
3207 configfs_unregister_subsystem(subsys
);
3208 printk(KERN_INFO
"TARGET_CORE[0]: Released ConfigFS Fabric"
3209 " Infrastructure\n");
3211 remove_scsi_target_mib();
3212 remove_proc_entry("scsi_target", 0);
3213 core_dev_release_virtual_lun0();
3215 release_se_global();
3220 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3221 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3222 MODULE_LICENSE("GPL");
3224 module_init(target_core_init_configfs
);
3225 module_exit(target_core_exit_configfs
);