1 /*******************************************************************************
2 * Filename: target_core_configfs.c
4 * This file contains ConfigFS logic for the Generic Target Engine project.
6 * Copyright (c) 2008-2011 Rising Tide Systems
7 * Copyright (c) 2008-2011 Linux-iSCSI.org
9 * Nicholas A. Bellinger <nab@kernel.org>
11 * based on configfs Copyright (C) 2005 Oracle. All rights reserved.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 ****************************************************************************/
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <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/spinlock.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"
54 #include "target_core_stat.h"
56 extern struct t10_alua_lu_gp
*default_lu_gp
;
58 static struct list_head g_tf_list
;
59 static struct mutex g_tf_lock
;
61 struct target_core_configfs_attribute
{
62 struct configfs_attribute attr
;
63 ssize_t (*show
)(void *, char *);
64 ssize_t (*store
)(void *, const char *, size_t);
67 static struct config_group target_core_hbagroup
;
68 static struct config_group alua_group
;
69 static struct config_group alua_lu_gps_group
;
71 static DEFINE_SPINLOCK(se_device_lock
);
72 static LIST_HEAD(se_dev_list
);
74 static inline struct se_hba
*
75 item_to_hba(struct config_item
*item
)
77 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
81 * Attributes for /sys/kernel/config/target/
83 static ssize_t
target_core_attr_show(struct config_item
*item
,
84 struct configfs_attribute
*attr
,
87 return sprintf(page
, "Target Engine Core ConfigFS Infrastructure %s"
88 " on %s/%s on "UTS_RELEASE
"\n", TARGET_CORE_CONFIGFS_VERSION
,
89 utsname()->sysname
, utsname()->machine
);
92 static struct configfs_item_operations target_core_fabric_item_ops
= {
93 .show_attribute
= target_core_attr_show
,
96 static struct configfs_attribute target_core_item_attr_version
= {
97 .ca_owner
= THIS_MODULE
,
102 static struct target_fabric_configfs
*target_core_get_fabric(
105 struct target_fabric_configfs
*tf
;
110 mutex_lock(&g_tf_lock
);
111 list_for_each_entry(tf
, &g_tf_list
, tf_list
) {
112 if (!(strcmp(tf
->tf_name
, name
))) {
113 atomic_inc(&tf
->tf_access_cnt
);
114 mutex_unlock(&g_tf_lock
);
118 mutex_unlock(&g_tf_lock
);
124 * Called from struct target_core_group_ops->make_group()
126 static struct config_group
*target_core_register_fabric(
127 struct config_group
*group
,
130 struct target_fabric_configfs
*tf
;
133 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER -> group: %p name:"
134 " %s\n", group
, name
);
136 * Ensure that TCM subsystem plugins are loaded at this point for
137 * using the RAMDISK_DR virtual LUN 0 and all other struct se_port
140 if (transport_subsystem_check_init() < 0)
141 return ERR_PTR(-EINVAL
);
144 * Below are some hardcoded request_module() calls to automatically
145 * local fabric modules when the following is called:
147 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
149 * Note that this does not limit which TCM fabric module can be
150 * registered, but simply provids auto loading logic for modules with
151 * mkdir(2) system calls with known TCM fabric modules.
153 if (!(strncmp(name
, "iscsi", 5))) {
155 * Automatically load the LIO Target fabric module when the
156 * following is called:
158 * mkdir -p $CONFIGFS/target/iscsi
160 ret
= request_module("iscsi_target_mod");
162 printk(KERN_ERR
"request_module() failed for"
163 " iscsi_target_mod.ko: %d\n", ret
);
164 return ERR_PTR(-EINVAL
);
166 } else if (!(strncmp(name
, "loopback", 8))) {
168 * Automatically load the tcm_loop fabric module when the
169 * following is called:
171 * mkdir -p $CONFIGFS/target/loopback
173 ret
= request_module("tcm_loop");
175 printk(KERN_ERR
"request_module() failed for"
176 " tcm_loop.ko: %d\n", ret
);
177 return ERR_PTR(-EINVAL
);
181 tf
= target_core_get_fabric(name
);
183 printk(KERN_ERR
"target_core_get_fabric() failed for %s\n",
185 return ERR_PTR(-EINVAL
);
187 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER -> Located fabric:"
188 " %s\n", tf
->tf_name
);
190 * On a successful target_core_get_fabric() look, the returned
191 * struct target_fabric_configfs *tf will contain a usage reference.
193 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
194 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
196 tf
->tf_group
.default_groups
= tf
->tf_default_groups
;
197 tf
->tf_group
.default_groups
[0] = &tf
->tf_disc_group
;
198 tf
->tf_group
.default_groups
[1] = NULL
;
200 config_group_init_type_name(&tf
->tf_group
, name
,
201 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
202 config_group_init_type_name(&tf
->tf_disc_group
, "discovery_auth",
203 &TF_CIT_TMPL(tf
)->tfc_discovery_cit
);
205 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
206 " %s\n", tf
->tf_group
.cg_item
.ci_name
);
208 * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item()
210 tf
->tf_ops
.tf_subsys
= tf
->tf_subsys
;
211 tf
->tf_fabric
= &tf
->tf_group
.cg_item
;
212 printk(KERN_INFO
"Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
215 return &tf
->tf_group
;
219 * Called from struct target_core_group_ops->drop_item()
221 static void target_core_deregister_fabric(
222 struct config_group
*group
,
223 struct config_item
*item
)
225 struct target_fabric_configfs
*tf
= container_of(
226 to_config_group(item
), struct target_fabric_configfs
, tf_group
);
227 struct config_group
*tf_group
;
228 struct config_item
*df_item
;
231 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
232 " tf list\n", config_item_name(item
));
234 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> located fabric:"
235 " %s\n", tf
->tf_name
);
236 atomic_dec(&tf
->tf_access_cnt
);
238 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> Releasing"
239 " tf->tf_fabric for %s\n", tf
->tf_name
);
240 tf
->tf_fabric
= NULL
;
242 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
243 " %s\n", config_item_name(item
));
245 tf_group
= &tf
->tf_group
;
246 for (i
= 0; tf_group
->default_groups
[i
]; i
++) {
247 df_item
= &tf_group
->default_groups
[i
]->cg_item
;
248 tf_group
->default_groups
[i
] = NULL
;
249 config_item_put(df_item
);
251 config_item_put(item
);
254 static struct configfs_group_operations target_core_fabric_group_ops
= {
255 .make_group
= &target_core_register_fabric
,
256 .drop_item
= &target_core_deregister_fabric
,
260 * All item attributes appearing in /sys/kernel/target/ appear here.
262 static struct configfs_attribute
*target_core_fabric_item_attrs
[] = {
263 &target_core_item_attr_version
,
268 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
270 static struct config_item_type target_core_fabrics_item
= {
271 .ct_item_ops
= &target_core_fabric_item_ops
,
272 .ct_group_ops
= &target_core_fabric_group_ops
,
273 .ct_attrs
= target_core_fabric_item_attrs
,
274 .ct_owner
= THIS_MODULE
,
277 static struct configfs_subsystem target_core_fabrics
= {
280 .ci_namebuf
= "target",
281 .ci_type
= &target_core_fabrics_item
,
286 static struct configfs_subsystem
*target_core_subsystem
[] = {
287 &target_core_fabrics
,
291 /*##############################################################################
292 // Start functions called by external Target Fabrics Modules
293 //############################################################################*/
296 * First function called by fabric modules to:
298 * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer.
299 * 2) Add struct target_fabric_configfs to g_tf_list
300 * 3) Return struct target_fabric_configfs to fabric module to be passed
301 * into target_fabric_configfs_register().
303 struct target_fabric_configfs
*target_fabric_configfs_init(
304 struct module
*fabric_mod
,
307 struct target_fabric_configfs
*tf
;
310 printk(KERN_ERR
"Unable to locate passed fabric name\n");
311 return ERR_PTR(-EINVAL
);
313 if (strlen(name
) >= TARGET_FABRIC_NAME_SIZE
) {
314 printk(KERN_ERR
"Passed name: %s exceeds TARGET_FABRIC"
315 "_NAME_SIZE\n", name
);
316 return ERR_PTR(-EINVAL
);
319 tf
= kzalloc(sizeof(struct target_fabric_configfs
), GFP_KERNEL
);
321 return ERR_PTR(-ENOMEM
);
323 INIT_LIST_HEAD(&tf
->tf_list
);
324 atomic_set(&tf
->tf_access_cnt
, 0);
326 * Setup the default generic struct config_item_type's (cits) in
327 * struct target_fabric_configfs->tf_cit_tmpl
329 tf
->tf_module
= fabric_mod
;
330 target_fabric_setup_cits(tf
);
332 tf
->tf_subsys
= target_core_subsystem
[0];
333 snprintf(tf
->tf_name
, TARGET_FABRIC_NAME_SIZE
, "%s", name
);
335 mutex_lock(&g_tf_lock
);
336 list_add_tail(&tf
->tf_list
, &g_tf_list
);
337 mutex_unlock(&g_tf_lock
);
339 printk(KERN_INFO
"<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>"
341 printk(KERN_INFO
"Initialized struct target_fabric_configfs: %p for"
342 " %s\n", tf
, tf
->tf_name
);
345 EXPORT_SYMBOL(target_fabric_configfs_init
);
348 * Called by fabric plugins after FAILED target_fabric_configfs_register() call.
350 void target_fabric_configfs_free(
351 struct target_fabric_configfs
*tf
)
353 mutex_lock(&g_tf_lock
);
354 list_del(&tf
->tf_list
);
355 mutex_unlock(&g_tf_lock
);
359 EXPORT_SYMBOL(target_fabric_configfs_free
);
362 * Perform a sanity check of the passed tf->tf_ops before completing
363 * TCM fabric module registration.
365 static int target_fabric_tf_ops_check(
366 struct target_fabric_configfs
*tf
)
368 struct target_core_fabric_ops
*tfo
= &tf
->tf_ops
;
370 if (!(tfo
->get_fabric_name
)) {
371 printk(KERN_ERR
"Missing tfo->get_fabric_name()\n");
374 if (!(tfo
->get_fabric_proto_ident
)) {
375 printk(KERN_ERR
"Missing tfo->get_fabric_proto_ident()\n");
378 if (!(tfo
->tpg_get_wwn
)) {
379 printk(KERN_ERR
"Missing tfo->tpg_get_wwn()\n");
382 if (!(tfo
->tpg_get_tag
)) {
383 printk(KERN_ERR
"Missing tfo->tpg_get_tag()\n");
386 if (!(tfo
->tpg_get_default_depth
)) {
387 printk(KERN_ERR
"Missing tfo->tpg_get_default_depth()\n");
390 if (!(tfo
->tpg_get_pr_transport_id
)) {
391 printk(KERN_ERR
"Missing tfo->tpg_get_pr_transport_id()\n");
394 if (!(tfo
->tpg_get_pr_transport_id_len
)) {
395 printk(KERN_ERR
"Missing tfo->tpg_get_pr_transport_id_len()\n");
398 if (!(tfo
->tpg_check_demo_mode
)) {
399 printk(KERN_ERR
"Missing tfo->tpg_check_demo_mode()\n");
402 if (!(tfo
->tpg_check_demo_mode_cache
)) {
403 printk(KERN_ERR
"Missing tfo->tpg_check_demo_mode_cache()\n");
406 if (!(tfo
->tpg_check_demo_mode_write_protect
)) {
407 printk(KERN_ERR
"Missing tfo->tpg_check_demo_mode_write_protect()\n");
410 if (!(tfo
->tpg_check_prod_mode_write_protect
)) {
411 printk(KERN_ERR
"Missing tfo->tpg_check_prod_mode_write_protect()\n");
414 if (!(tfo
->tpg_alloc_fabric_acl
)) {
415 printk(KERN_ERR
"Missing tfo->tpg_alloc_fabric_acl()\n");
418 if (!(tfo
->tpg_release_fabric_acl
)) {
419 printk(KERN_ERR
"Missing tfo->tpg_release_fabric_acl()\n");
422 if (!(tfo
->tpg_get_inst_index
)) {
423 printk(KERN_ERR
"Missing tfo->tpg_get_inst_index()\n");
426 if (!tfo
->release_cmd
) {
427 printk(KERN_ERR
"Missing tfo->release_cmd()\n");
430 if (!(tfo
->shutdown_session
)) {
431 printk(KERN_ERR
"Missing tfo->shutdown_session()\n");
434 if (!(tfo
->close_session
)) {
435 printk(KERN_ERR
"Missing tfo->close_session()\n");
438 if (!(tfo
->stop_session
)) {
439 printk(KERN_ERR
"Missing tfo->stop_session()\n");
442 if (!(tfo
->fall_back_to_erl0
)) {
443 printk(KERN_ERR
"Missing tfo->fall_back_to_erl0()\n");
446 if (!(tfo
->sess_logged_in
)) {
447 printk(KERN_ERR
"Missing tfo->sess_logged_in()\n");
450 if (!(tfo
->sess_get_index
)) {
451 printk(KERN_ERR
"Missing tfo->sess_get_index()\n");
454 if (!(tfo
->write_pending
)) {
455 printk(KERN_ERR
"Missing tfo->write_pending()\n");
458 if (!(tfo
->write_pending_status
)) {
459 printk(KERN_ERR
"Missing tfo->write_pending_status()\n");
462 if (!(tfo
->set_default_node_attributes
)) {
463 printk(KERN_ERR
"Missing tfo->set_default_node_attributes()\n");
466 if (!(tfo
->get_task_tag
)) {
467 printk(KERN_ERR
"Missing tfo->get_task_tag()\n");
470 if (!(tfo
->get_cmd_state
)) {
471 printk(KERN_ERR
"Missing tfo->get_cmd_state()\n");
474 if (!(tfo
->queue_data_in
)) {
475 printk(KERN_ERR
"Missing tfo->queue_data_in()\n");
478 if (!(tfo
->queue_status
)) {
479 printk(KERN_ERR
"Missing tfo->queue_status()\n");
482 if (!(tfo
->queue_tm_rsp
)) {
483 printk(KERN_ERR
"Missing tfo->queue_tm_rsp()\n");
486 if (!(tfo
->set_fabric_sense_len
)) {
487 printk(KERN_ERR
"Missing tfo->set_fabric_sense_len()\n");
490 if (!(tfo
->get_fabric_sense_len
)) {
491 printk(KERN_ERR
"Missing tfo->get_fabric_sense_len()\n");
494 if (!(tfo
->is_state_remove
)) {
495 printk(KERN_ERR
"Missing tfo->is_state_remove()\n");
499 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
500 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
501 * target_core_fabric_configfs.c WWN+TPG group context code.
503 if (!(tfo
->fabric_make_wwn
)) {
504 printk(KERN_ERR
"Missing tfo->fabric_make_wwn()\n");
507 if (!(tfo
->fabric_drop_wwn
)) {
508 printk(KERN_ERR
"Missing tfo->fabric_drop_wwn()\n");
511 if (!(tfo
->fabric_make_tpg
)) {
512 printk(KERN_ERR
"Missing tfo->fabric_make_tpg()\n");
515 if (!(tfo
->fabric_drop_tpg
)) {
516 printk(KERN_ERR
"Missing tfo->fabric_drop_tpg()\n");
524 * Called 2nd from fabric module with returned parameter of
525 * struct target_fabric_configfs * from target_fabric_configfs_init().
527 * Upon a successful registration, the new fabric's struct config_item is
528 * return. Also, a pointer to this struct is set in the passed
529 * struct target_fabric_configfs.
531 int target_fabric_configfs_register(
532 struct target_fabric_configfs
*tf
)
537 printk(KERN_ERR
"Unable to locate target_fabric_configfs"
541 if (!(tf
->tf_subsys
)) {
542 printk(KERN_ERR
"Unable to target struct config_subsystem"
546 ret
= target_fabric_tf_ops_check(tf
);
550 printk(KERN_INFO
"<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>"
554 EXPORT_SYMBOL(target_fabric_configfs_register
);
556 void target_fabric_configfs_deregister(
557 struct target_fabric_configfs
*tf
)
559 struct configfs_subsystem
*su
;
562 printk(KERN_ERR
"Unable to locate passed target_fabric_"
568 printk(KERN_ERR
"Unable to locate passed tf->tf_subsys"
572 printk(KERN_INFO
"<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
574 mutex_lock(&g_tf_lock
);
575 if (atomic_read(&tf
->tf_access_cnt
)) {
576 mutex_unlock(&g_tf_lock
);
577 printk(KERN_ERR
"Non zero tf->tf_access_cnt for fabric %s\n",
581 list_del(&tf
->tf_list
);
582 mutex_unlock(&g_tf_lock
);
584 printk(KERN_INFO
"Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
585 " %s\n", tf
->tf_name
);
586 tf
->tf_module
= NULL
;
587 tf
->tf_subsys
= NULL
;
590 printk("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
593 EXPORT_SYMBOL(target_fabric_configfs_deregister
);
595 /*##############################################################################
596 // Stop functions called by external Target Fabrics Modules
597 //############################################################################*/
599 /* Start functions for struct config_item_type target_core_dev_attrib_cit */
601 #define DEF_DEV_ATTRIB_SHOW(_name) \
602 static ssize_t target_core_dev_show_attr_##_name( \
603 struct se_dev_attrib *da, \
606 struct se_device *dev; \
607 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
610 spin_lock(&se_dev->se_dev_lock); \
611 dev = se_dev->se_dev_ptr; \
613 spin_unlock(&se_dev->se_dev_lock); \
616 rb = snprintf(page, PAGE_SIZE, "%u\n", \
617 (u32)dev->se_sub_dev->se_dev_attrib._name); \
618 spin_unlock(&se_dev->se_dev_lock); \
623 #define DEF_DEV_ATTRIB_STORE(_name) \
624 static ssize_t target_core_dev_store_attr_##_name( \
625 struct se_dev_attrib *da, \
629 struct se_device *dev; \
630 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
634 spin_lock(&se_dev->se_dev_lock); \
635 dev = se_dev->se_dev_ptr; \
637 spin_unlock(&se_dev->se_dev_lock); \
640 ret = strict_strtoul(page, 0, &val); \
642 spin_unlock(&se_dev->se_dev_lock); \
643 printk(KERN_ERR "strict_strtoul() failed with" \
644 " ret: %d\n", ret); \
647 ret = se_dev_set_##_name(dev, (u32)val); \
648 spin_unlock(&se_dev->se_dev_lock); \
650 return (!ret) ? count : -EINVAL; \
653 #define DEF_DEV_ATTRIB(_name) \
654 DEF_DEV_ATTRIB_SHOW(_name); \
655 DEF_DEV_ATTRIB_STORE(_name);
657 #define DEF_DEV_ATTRIB_RO(_name) \
658 DEF_DEV_ATTRIB_SHOW(_name);
660 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib
, se_dev_attrib
);
661 #define SE_DEV_ATTR(_name, _mode) \
662 static struct target_core_dev_attrib_attribute \
663 target_core_dev_attrib_##_name = \
664 __CONFIGFS_EATTR(_name, _mode, \
665 target_core_dev_show_attr_##_name, \
666 target_core_dev_store_attr_##_name);
668 #define SE_DEV_ATTR_RO(_name); \
669 static struct target_core_dev_attrib_attribute \
670 target_core_dev_attrib_##_name = \
671 __CONFIGFS_EATTR_RO(_name, \
672 target_core_dev_show_attr_##_name);
674 DEF_DEV_ATTRIB(emulate_dpo
);
675 SE_DEV_ATTR(emulate_dpo
, S_IRUGO
| S_IWUSR
);
677 DEF_DEV_ATTRIB(emulate_fua_write
);
678 SE_DEV_ATTR(emulate_fua_write
, S_IRUGO
| S_IWUSR
);
680 DEF_DEV_ATTRIB(emulate_fua_read
);
681 SE_DEV_ATTR(emulate_fua_read
, S_IRUGO
| S_IWUSR
);
683 DEF_DEV_ATTRIB(emulate_write_cache
);
684 SE_DEV_ATTR(emulate_write_cache
, S_IRUGO
| S_IWUSR
);
686 DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl
);
687 SE_DEV_ATTR(emulate_ua_intlck_ctrl
, S_IRUGO
| S_IWUSR
);
689 DEF_DEV_ATTRIB(emulate_tas
);
690 SE_DEV_ATTR(emulate_tas
, S_IRUGO
| S_IWUSR
);
692 DEF_DEV_ATTRIB(emulate_tpu
);
693 SE_DEV_ATTR(emulate_tpu
, S_IRUGO
| S_IWUSR
);
695 DEF_DEV_ATTRIB(emulate_tpws
);
696 SE_DEV_ATTR(emulate_tpws
, S_IRUGO
| S_IWUSR
);
698 DEF_DEV_ATTRIB(enforce_pr_isids
);
699 SE_DEV_ATTR(enforce_pr_isids
, S_IRUGO
| S_IWUSR
);
701 DEF_DEV_ATTRIB_RO(hw_block_size
);
702 SE_DEV_ATTR_RO(hw_block_size
);
704 DEF_DEV_ATTRIB(block_size
);
705 SE_DEV_ATTR(block_size
, S_IRUGO
| S_IWUSR
);
707 DEF_DEV_ATTRIB_RO(hw_max_sectors
);
708 SE_DEV_ATTR_RO(hw_max_sectors
);
710 DEF_DEV_ATTRIB(max_sectors
);
711 SE_DEV_ATTR(max_sectors
, S_IRUGO
| S_IWUSR
);
713 DEF_DEV_ATTRIB(optimal_sectors
);
714 SE_DEV_ATTR(optimal_sectors
, S_IRUGO
| S_IWUSR
);
716 DEF_DEV_ATTRIB_RO(hw_queue_depth
);
717 SE_DEV_ATTR_RO(hw_queue_depth
);
719 DEF_DEV_ATTRIB(queue_depth
);
720 SE_DEV_ATTR(queue_depth
, S_IRUGO
| S_IWUSR
);
722 DEF_DEV_ATTRIB(task_timeout
);
723 SE_DEV_ATTR(task_timeout
, S_IRUGO
| S_IWUSR
);
725 DEF_DEV_ATTRIB(max_unmap_lba_count
);
726 SE_DEV_ATTR(max_unmap_lba_count
, S_IRUGO
| S_IWUSR
);
728 DEF_DEV_ATTRIB(max_unmap_block_desc_count
);
729 SE_DEV_ATTR(max_unmap_block_desc_count
, S_IRUGO
| S_IWUSR
);
731 DEF_DEV_ATTRIB(unmap_granularity
);
732 SE_DEV_ATTR(unmap_granularity
, S_IRUGO
| S_IWUSR
);
734 DEF_DEV_ATTRIB(unmap_granularity_alignment
);
735 SE_DEV_ATTR(unmap_granularity_alignment
, S_IRUGO
| S_IWUSR
);
737 CONFIGFS_EATTR_OPS(target_core_dev_attrib
, se_dev_attrib
, da_group
);
739 static struct configfs_attribute
*target_core_dev_attrib_attrs
[] = {
740 &target_core_dev_attrib_emulate_dpo
.attr
,
741 &target_core_dev_attrib_emulate_fua_write
.attr
,
742 &target_core_dev_attrib_emulate_fua_read
.attr
,
743 &target_core_dev_attrib_emulate_write_cache
.attr
,
744 &target_core_dev_attrib_emulate_ua_intlck_ctrl
.attr
,
745 &target_core_dev_attrib_emulate_tas
.attr
,
746 &target_core_dev_attrib_emulate_tpu
.attr
,
747 &target_core_dev_attrib_emulate_tpws
.attr
,
748 &target_core_dev_attrib_enforce_pr_isids
.attr
,
749 &target_core_dev_attrib_hw_block_size
.attr
,
750 &target_core_dev_attrib_block_size
.attr
,
751 &target_core_dev_attrib_hw_max_sectors
.attr
,
752 &target_core_dev_attrib_max_sectors
.attr
,
753 &target_core_dev_attrib_optimal_sectors
.attr
,
754 &target_core_dev_attrib_hw_queue_depth
.attr
,
755 &target_core_dev_attrib_queue_depth
.attr
,
756 &target_core_dev_attrib_task_timeout
.attr
,
757 &target_core_dev_attrib_max_unmap_lba_count
.attr
,
758 &target_core_dev_attrib_max_unmap_block_desc_count
.attr
,
759 &target_core_dev_attrib_unmap_granularity
.attr
,
760 &target_core_dev_attrib_unmap_granularity_alignment
.attr
,
764 static struct configfs_item_operations target_core_dev_attrib_ops
= {
765 .show_attribute
= target_core_dev_attrib_attr_show
,
766 .store_attribute
= target_core_dev_attrib_attr_store
,
769 static struct config_item_type target_core_dev_attrib_cit
= {
770 .ct_item_ops
= &target_core_dev_attrib_ops
,
771 .ct_attrs
= target_core_dev_attrib_attrs
,
772 .ct_owner
= THIS_MODULE
,
775 /* End functions for struct config_item_type target_core_dev_attrib_cit */
777 /* Start functions for struct config_item_type target_core_dev_wwn_cit */
779 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn
, t10_wwn
);
780 #define SE_DEV_WWN_ATTR(_name, _mode) \
781 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
782 __CONFIGFS_EATTR(_name, _mode, \
783 target_core_dev_wwn_show_attr_##_name, \
784 target_core_dev_wwn_store_attr_##_name);
786 #define SE_DEV_WWN_ATTR_RO(_name); \
788 static struct target_core_dev_wwn_attribute \
789 target_core_dev_wwn_##_name = \
790 __CONFIGFS_EATTR_RO(_name, \
791 target_core_dev_wwn_show_attr_##_name); \
795 * VPD page 0x80 Unit serial
797 static ssize_t
target_core_dev_wwn_show_attr_vpd_unit_serial(
798 struct t10_wwn
*t10_wwn
,
801 struct se_subsystem_dev
*se_dev
= t10_wwn
->t10_sub_dev
;
802 struct se_device
*dev
;
804 dev
= se_dev
->se_dev_ptr
;
808 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
809 &t10_wwn
->unit_serial
[0]);
812 static ssize_t
target_core_dev_wwn_store_attr_vpd_unit_serial(
813 struct t10_wwn
*t10_wwn
,
817 struct se_subsystem_dev
*su_dev
= t10_wwn
->t10_sub_dev
;
818 struct se_device
*dev
;
819 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
822 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
823 * from the struct scsi_device level firmware, do not allow
824 * VPD Unit Serial to be emulated.
826 * Note this struct scsi_device could also be emulating VPD
827 * information from its drivers/scsi LLD. But for now we assume
828 * it is doing 'the right thing' wrt a world wide unique
829 * VPD Unit Serial Number that OS dependent multipath can depend on.
831 if (su_dev
->su_dev_flags
& SDF_FIRMWARE_VPD_UNIT_SERIAL
) {
832 printk(KERN_ERR
"Underlying SCSI device firmware provided VPD"
833 " Unit Serial, ignoring request\n");
837 if (strlen(page
) >= INQUIRY_VPD_SERIAL_LEN
) {
838 printk(KERN_ERR
"Emulated VPD Unit Serial exceeds"
839 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
843 * Check to see if any active $FABRIC_MOD exports exist. If they
844 * do exist, fail here as changing this information on the fly
845 * (underneath the initiator side OS dependent multipath code)
846 * could cause negative effects.
848 dev
= su_dev
->se_dev_ptr
;
850 if (atomic_read(&dev
->dev_export_obj
.obj_access_count
)) {
851 printk(KERN_ERR
"Unable to set VPD Unit Serial while"
852 " active %d $FABRIC_MOD exports exist\n",
853 atomic_read(&dev
->dev_export_obj
.obj_access_count
));
858 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
860 * Also, strip any newline added from the userspace
861 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
863 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
864 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
865 snprintf(su_dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
866 "%s", strstrip(buf
));
867 su_dev
->su_dev_flags
|= SDF_EMULATED_VPD_UNIT_SERIAL
;
869 printk(KERN_INFO
"Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
870 " %s\n", su_dev
->t10_wwn
.unit_serial
);
875 SE_DEV_WWN_ATTR(vpd_unit_serial
, S_IRUGO
| S_IWUSR
);
878 * VPD page 0x83 Protocol Identifier
880 static ssize_t
target_core_dev_wwn_show_attr_vpd_protocol_identifier(
881 struct t10_wwn
*t10_wwn
,
884 struct se_subsystem_dev
*se_dev
= t10_wwn
->t10_sub_dev
;
885 struct se_device
*dev
;
887 unsigned char buf
[VPD_TMP_BUF_SIZE
];
890 dev
= se_dev
->se_dev_ptr
;
894 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
896 spin_lock(&t10_wwn
->t10_vpd_lock
);
897 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
898 if (!(vpd
->protocol_identifier_set
))
901 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
903 if ((len
+ strlen(buf
) >= PAGE_SIZE
))
906 len
+= sprintf(page
+len
, "%s", buf
);
908 spin_unlock(&t10_wwn
->t10_vpd_lock
);
913 static ssize_t
target_core_dev_wwn_store_attr_vpd_protocol_identifier(
914 struct t10_wwn
*t10_wwn
,
921 SE_DEV_WWN_ATTR(vpd_protocol_identifier
, S_IRUGO
| S_IWUSR
);
924 * Generic wrapper for dumping VPD identifiers by association.
926 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
927 static ssize_t target_core_dev_wwn_show_attr_##_name( \
928 struct t10_wwn *t10_wwn, \
931 struct se_subsystem_dev *se_dev = t10_wwn->t10_sub_dev; \
932 struct se_device *dev; \
933 struct t10_vpd *vpd; \
934 unsigned char buf[VPD_TMP_BUF_SIZE]; \
937 dev = se_dev->se_dev_ptr; \
941 spin_lock(&t10_wwn->t10_vpd_lock); \
942 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
943 if (vpd->association != _assoc) \
946 memset(buf, 0, VPD_TMP_BUF_SIZE); \
947 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
948 if ((len + strlen(buf) >= PAGE_SIZE)) \
950 len += sprintf(page+len, "%s", buf); \
952 memset(buf, 0, VPD_TMP_BUF_SIZE); \
953 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
954 if ((len + strlen(buf) >= PAGE_SIZE)) \
956 len += sprintf(page+len, "%s", buf); \
958 memset(buf, 0, VPD_TMP_BUF_SIZE); \
959 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
960 if ((len + strlen(buf) >= PAGE_SIZE)) \
962 len += sprintf(page+len, "%s", buf); \
964 spin_unlock(&t10_wwn->t10_vpd_lock); \
970 * VPD page 0x83 Assoication: Logical Unit
972 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
974 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
975 struct t10_wwn
*t10_wwn
,
982 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit
, S_IRUGO
| S_IWUSR
);
985 * VPD page 0x83 Association: Target Port
987 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
989 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_target_port(
990 struct t10_wwn
*t10_wwn
,
997 SE_DEV_WWN_ATTR(vpd_assoc_target_port
, S_IRUGO
| S_IWUSR
);
1000 * VPD page 0x83 Association: SCSI Target Device
1002 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
1004 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
1005 struct t10_wwn
*t10_wwn
,
1012 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device
, S_IRUGO
| S_IWUSR
);
1014 CONFIGFS_EATTR_OPS(target_core_dev_wwn
, t10_wwn
, t10_wwn_group
);
1016 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
1017 &target_core_dev_wwn_vpd_unit_serial
.attr
,
1018 &target_core_dev_wwn_vpd_protocol_identifier
.attr
,
1019 &target_core_dev_wwn_vpd_assoc_logical_unit
.attr
,
1020 &target_core_dev_wwn_vpd_assoc_target_port
.attr
,
1021 &target_core_dev_wwn_vpd_assoc_scsi_target_device
.attr
,
1025 static struct configfs_item_operations target_core_dev_wwn_ops
= {
1026 .show_attribute
= target_core_dev_wwn_attr_show
,
1027 .store_attribute
= target_core_dev_wwn_attr_store
,
1030 static struct config_item_type target_core_dev_wwn_cit
= {
1031 .ct_item_ops
= &target_core_dev_wwn_ops
,
1032 .ct_attrs
= target_core_dev_wwn_attrs
,
1033 .ct_owner
= THIS_MODULE
,
1036 /* End functions for struct config_item_type target_core_dev_wwn_cit */
1038 /* Start functions for struct config_item_type target_core_dev_pr_cit */
1040 CONFIGFS_EATTR_STRUCT(target_core_dev_pr
, se_subsystem_dev
);
1041 #define SE_DEV_PR_ATTR(_name, _mode) \
1042 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1043 __CONFIGFS_EATTR(_name, _mode, \
1044 target_core_dev_pr_show_attr_##_name, \
1045 target_core_dev_pr_store_attr_##_name);
1047 #define SE_DEV_PR_ATTR_RO(_name); \
1048 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1049 __CONFIGFS_EATTR_RO(_name, \
1050 target_core_dev_pr_show_attr_##_name);
1055 static ssize_t
target_core_dev_pr_show_spc3_res(
1056 struct se_device
*dev
,
1060 struct se_node_acl
*se_nacl
;
1061 struct t10_pr_registration
*pr_reg
;
1062 char i_buf
[PR_REG_ISID_ID_LEN
];
1065 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1067 spin_lock(&dev
->dev_reservation_lock
);
1068 pr_reg
= dev
->dev_pr_res_holder
;
1070 *len
+= sprintf(page
+ *len
, "No SPC-3 Reservation holder\n");
1071 spin_unlock(&dev
->dev_reservation_lock
);
1074 se_nacl
= pr_reg
->pr_reg_nacl
;
1075 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1076 PR_REG_ISID_ID_LEN
);
1078 *len
+= sprintf(page
+ *len
, "SPC-3 Reservation: %s Initiator: %s%s\n",
1079 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1080 se_nacl
->initiatorname
, (prf_isid
) ? &i_buf
[0] : "");
1081 spin_unlock(&dev
->dev_reservation_lock
);
1086 static ssize_t
target_core_dev_pr_show_spc2_res(
1087 struct se_device
*dev
,
1091 struct se_node_acl
*se_nacl
;
1093 spin_lock(&dev
->dev_reservation_lock
);
1094 se_nacl
= dev
->dev_reserved_node_acl
;
1096 *len
+= sprintf(page
+ *len
, "No SPC-2 Reservation holder\n");
1097 spin_unlock(&dev
->dev_reservation_lock
);
1100 *len
+= sprintf(page
+ *len
, "SPC-2 Reservation: %s Initiator: %s\n",
1101 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1102 se_nacl
->initiatorname
);
1103 spin_unlock(&dev
->dev_reservation_lock
);
1108 static ssize_t
target_core_dev_pr_show_attr_res_holder(
1109 struct se_subsystem_dev
*su_dev
,
1114 if (!(su_dev
->se_dev_ptr
))
1117 switch (su_dev
->t10_pr
.res_type
) {
1118 case SPC3_PERSISTENT_RESERVATIONS
:
1119 target_core_dev_pr_show_spc3_res(su_dev
->se_dev_ptr
,
1122 case SPC2_RESERVATIONS
:
1123 target_core_dev_pr_show_spc2_res(su_dev
->se_dev_ptr
,
1126 case SPC_PASSTHROUGH
:
1127 len
+= sprintf(page
+len
, "Passthrough\n");
1130 len
+= sprintf(page
+len
, "Unknown\n");
1137 SE_DEV_PR_ATTR_RO(res_holder
);
1140 * res_pr_all_tgt_pts
1142 static ssize_t
target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1143 struct se_subsystem_dev
*su_dev
,
1146 struct se_device
*dev
;
1147 struct t10_pr_registration
*pr_reg
;
1150 dev
= su_dev
->se_dev_ptr
;
1154 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1157 spin_lock(&dev
->dev_reservation_lock
);
1158 pr_reg
= dev
->dev_pr_res_holder
;
1160 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1161 spin_unlock(&dev
->dev_reservation_lock
);
1165 * See All Target Ports (ALL_TG_PT) bit in spcr17, section 6.14.3
1166 * Basic PERSISTENT RESERVER OUT parameter list, page 290
1168 if (pr_reg
->pr_reg_all_tg_pt
)
1169 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1170 " Ports registration\n");
1172 len
= sprintf(page
, "SPC-3 Reservation: Single"
1173 " Target Port registration\n");
1174 spin_unlock(&dev
->dev_reservation_lock
);
1179 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts
);
1184 static ssize_t
target_core_dev_pr_show_attr_res_pr_generation(
1185 struct se_subsystem_dev
*su_dev
,
1188 if (!(su_dev
->se_dev_ptr
))
1191 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1194 return sprintf(page
, "0x%08x\n", su_dev
->t10_pr
.pr_generation
);
1197 SE_DEV_PR_ATTR_RO(res_pr_generation
);
1200 * res_pr_holder_tg_port
1202 static ssize_t
target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1203 struct se_subsystem_dev
*su_dev
,
1206 struct se_device
*dev
;
1207 struct se_node_acl
*se_nacl
;
1209 struct se_portal_group
*se_tpg
;
1210 struct t10_pr_registration
*pr_reg
;
1211 struct target_core_fabric_ops
*tfo
;
1214 dev
= su_dev
->se_dev_ptr
;
1218 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1221 spin_lock(&dev
->dev_reservation_lock
);
1222 pr_reg
= dev
->dev_pr_res_holder
;
1224 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1225 spin_unlock(&dev
->dev_reservation_lock
);
1228 se_nacl
= pr_reg
->pr_reg_nacl
;
1229 se_tpg
= se_nacl
->se_tpg
;
1230 lun
= pr_reg
->pr_reg_tg_pt_lun
;
1231 tfo
= se_tpg
->se_tpg_tfo
;
1233 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1234 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1235 tfo
->tpg_get_wwn(se_tpg
));
1236 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1237 " Identifer Tag: %hu %s Portal Group Tag: %hu"
1238 " %s Logical Unit: %u\n", lun
->lun_sep
->sep_rtpi
,
1239 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1240 tfo
->get_fabric_name(), lun
->unpacked_lun
);
1241 spin_unlock(&dev
->dev_reservation_lock
);
1246 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port
);
1249 * res_pr_registered_i_pts
1251 static ssize_t
target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1252 struct se_subsystem_dev
*su_dev
,
1255 struct target_core_fabric_ops
*tfo
;
1256 struct t10_pr_registration
*pr_reg
;
1257 unsigned char buf
[384];
1258 char i_buf
[PR_REG_ISID_ID_LEN
];
1260 int reg_count
= 0, prf_isid
;
1262 if (!(su_dev
->se_dev_ptr
))
1265 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1268 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1270 spin_lock(&su_dev
->t10_pr
.registration_lock
);
1271 list_for_each_entry(pr_reg
, &su_dev
->t10_pr
.registration_list
,
1274 memset(buf
, 0, 384);
1275 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1276 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1277 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1278 PR_REG_ISID_ID_LEN
);
1279 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1280 tfo
->get_fabric_name(),
1281 pr_reg
->pr_reg_nacl
->initiatorname
, (prf_isid
) ?
1282 &i_buf
[0] : "", pr_reg
->pr_res_key
,
1283 pr_reg
->pr_res_generation
);
1285 if ((len
+ strlen(buf
) >= PAGE_SIZE
))
1288 len
+= sprintf(page
+len
, "%s", buf
);
1291 spin_unlock(&su_dev
->t10_pr
.registration_lock
);
1294 len
+= sprintf(page
+len
, "None\n");
1299 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts
);
1304 static ssize_t
target_core_dev_pr_show_attr_res_pr_type(
1305 struct se_subsystem_dev
*su_dev
,
1308 struct se_device
*dev
;
1309 struct t10_pr_registration
*pr_reg
;
1312 dev
= su_dev
->se_dev_ptr
;
1316 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1319 spin_lock(&dev
->dev_reservation_lock
);
1320 pr_reg
= dev
->dev_pr_res_holder
;
1322 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1323 spin_unlock(&dev
->dev_reservation_lock
);
1326 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1327 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1328 spin_unlock(&dev
->dev_reservation_lock
);
1333 SE_DEV_PR_ATTR_RO(res_pr_type
);
1338 static ssize_t
target_core_dev_pr_show_attr_res_type(
1339 struct se_subsystem_dev
*su_dev
,
1344 if (!(su_dev
->se_dev_ptr
))
1347 switch (su_dev
->t10_pr
.res_type
) {
1348 case SPC3_PERSISTENT_RESERVATIONS
:
1349 len
= sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1351 case SPC2_RESERVATIONS
:
1352 len
= sprintf(page
, "SPC2_RESERVATIONS\n");
1354 case SPC_PASSTHROUGH
:
1355 len
= sprintf(page
, "SPC_PASSTHROUGH\n");
1358 len
= sprintf(page
, "UNKNOWN\n");
1365 SE_DEV_PR_ATTR_RO(res_type
);
1371 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_active(
1372 struct se_subsystem_dev
*su_dev
,
1375 if (!(su_dev
->se_dev_ptr
))
1378 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1381 return sprintf(page
, "APTPL Bit Status: %s\n",
1382 (su_dev
->t10_pr
.pr_aptpl_active
) ? "Activated" : "Disabled");
1385 SE_DEV_PR_ATTR_RO(res_aptpl_active
);
1388 * res_aptpl_metadata
1390 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_metadata(
1391 struct se_subsystem_dev
*su_dev
,
1394 if (!(su_dev
->se_dev_ptr
))
1397 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1400 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1404 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1405 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1406 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1407 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1410 static match_table_t tokens
= {
1411 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1412 {Opt_initiator_node
, "initiator_node=%s"},
1413 {Opt_initiator_sid
, "initiator_sid=%s"},
1414 {Opt_sa_res_key
, "sa_res_key=%s"},
1415 {Opt_res_holder
, "res_holder=%d"},
1416 {Opt_res_type
, "res_type=%d"},
1417 {Opt_res_scope
, "res_scope=%d"},
1418 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1419 {Opt_mapped_lun
, "mapped_lun=%d"},
1420 {Opt_target_fabric
, "target_fabric=%s"},
1421 {Opt_target_node
, "target_node=%s"},
1422 {Opt_tpgt
, "tpgt=%d"},
1423 {Opt_port_rtpi
, "port_rtpi=%d"},
1424 {Opt_target_lun
, "target_lun=%d"},
1428 static ssize_t
target_core_dev_pr_store_attr_res_aptpl_metadata(
1429 struct se_subsystem_dev
*su_dev
,
1433 struct se_device
*dev
;
1434 unsigned char *i_fabric
= NULL
, *i_port
= NULL
, *isid
= NULL
;
1435 unsigned char *t_fabric
= NULL
, *t_port
= NULL
;
1436 char *orig
, *ptr
, *arg_p
, *opts
;
1437 substring_t args
[MAX_OPT_ARGS
];
1438 unsigned long long tmp_ll
;
1440 u32 mapped_lun
= 0, target_lun
= 0;
1441 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1442 u16 port_rpti
= 0, tpgt
= 0;
1445 dev
= su_dev
->se_dev_ptr
;
1449 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1452 if (atomic_read(&dev
->dev_export_obj
.obj_access_count
)) {
1453 printk(KERN_INFO
"Unable to process APTPL metadata while"
1454 " active fabric exports exist\n");
1458 opts
= kstrdup(page
, GFP_KERNEL
);
1463 while ((ptr
= strsep(&opts
, ",")) != NULL
) {
1467 token
= match_token(ptr
, tokens
, args
);
1469 case Opt_initiator_fabric
:
1470 i_fabric
= match_strdup(&args
[0]);
1476 case Opt_initiator_node
:
1477 i_port
= match_strdup(&args
[0]);
1482 if (strlen(i_port
) >= PR_APTPL_MAX_IPORT_LEN
) {
1483 printk(KERN_ERR
"APTPL metadata initiator_node="
1484 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1485 PR_APTPL_MAX_IPORT_LEN
);
1490 case Opt_initiator_sid
:
1491 isid
= match_strdup(&args
[0]);
1496 if (strlen(isid
) >= PR_REG_ISID_LEN
) {
1497 printk(KERN_ERR
"APTPL metadata initiator_isid"
1498 "= exceeds PR_REG_ISID_LEN: %d\n",
1504 case Opt_sa_res_key
:
1505 arg_p
= match_strdup(&args
[0]);
1510 ret
= strict_strtoull(arg_p
, 0, &tmp_ll
);
1512 printk(KERN_ERR
"strict_strtoull() failed for"
1516 sa_res_key
= (u64
)tmp_ll
;
1519 * PR APTPL Metadata for Reservation
1521 case Opt_res_holder
:
1522 match_int(args
, &arg
);
1526 match_int(args
, &arg
);
1530 match_int(args
, &arg
);
1533 case Opt_res_all_tg_pt
:
1534 match_int(args
, &arg
);
1535 all_tg_pt
= (int)arg
;
1537 case Opt_mapped_lun
:
1538 match_int(args
, &arg
);
1539 mapped_lun
= (u32
)arg
;
1542 * PR APTPL Metadata for Target Port
1544 case Opt_target_fabric
:
1545 t_fabric
= match_strdup(&args
[0]);
1551 case Opt_target_node
:
1552 t_port
= match_strdup(&args
[0]);
1557 if (strlen(t_port
) >= PR_APTPL_MAX_TPORT_LEN
) {
1558 printk(KERN_ERR
"APTPL metadata target_node="
1559 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1560 PR_APTPL_MAX_TPORT_LEN
);
1566 match_int(args
, &arg
);
1570 match_int(args
, &arg
);
1571 port_rpti
= (u16
)arg
;
1573 case Opt_target_lun
:
1574 match_int(args
, &arg
);
1575 target_lun
= (u32
)arg
;
1582 if (!(i_port
) || !(t_port
) || !(sa_res_key
)) {
1583 printk(KERN_ERR
"Illegal parameters for APTPL registration\n");
1588 if (res_holder
&& !(type
)) {
1589 printk(KERN_ERR
"Illegal PR type: 0x%02x for reservation"
1595 ret
= core_scsi3_alloc_aptpl_registration(&su_dev
->t10_pr
, sa_res_key
,
1596 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1597 res_holder
, all_tg_pt
, type
);
1605 return (ret
== 0) ? count
: ret
;
1608 SE_DEV_PR_ATTR(res_aptpl_metadata
, S_IRUGO
| S_IWUSR
);
1610 CONFIGFS_EATTR_OPS(target_core_dev_pr
, se_subsystem_dev
, se_dev_pr_group
);
1612 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1613 &target_core_dev_pr_res_holder
.attr
,
1614 &target_core_dev_pr_res_pr_all_tgt_pts
.attr
,
1615 &target_core_dev_pr_res_pr_generation
.attr
,
1616 &target_core_dev_pr_res_pr_holder_tg_port
.attr
,
1617 &target_core_dev_pr_res_pr_registered_i_pts
.attr
,
1618 &target_core_dev_pr_res_pr_type
.attr
,
1619 &target_core_dev_pr_res_type
.attr
,
1620 &target_core_dev_pr_res_aptpl_active
.attr
,
1621 &target_core_dev_pr_res_aptpl_metadata
.attr
,
1625 static struct configfs_item_operations target_core_dev_pr_ops
= {
1626 .show_attribute
= target_core_dev_pr_attr_show
,
1627 .store_attribute
= target_core_dev_pr_attr_store
,
1630 static struct config_item_type target_core_dev_pr_cit
= {
1631 .ct_item_ops
= &target_core_dev_pr_ops
,
1632 .ct_attrs
= target_core_dev_pr_attrs
,
1633 .ct_owner
= THIS_MODULE
,
1636 /* End functions for struct config_item_type target_core_dev_pr_cit */
1638 /* Start functions for struct config_item_type target_core_dev_cit */
1640 static ssize_t
target_core_show_dev_info(void *p
, char *page
)
1642 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1643 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1644 struct se_subsystem_api
*t
= hba
->transport
;
1646 ssize_t read_bytes
= 0;
1648 if (!(se_dev
->se_dev_ptr
))
1651 transport_dump_dev_state(se_dev
->se_dev_ptr
, page
, &bl
);
1653 read_bytes
+= t
->show_configfs_dev_params(hba
, se_dev
, page
+read_bytes
);
1657 static struct target_core_configfs_attribute target_core_attr_dev_info
= {
1658 .attr
= { .ca_owner
= THIS_MODULE
,
1660 .ca_mode
= S_IRUGO
},
1661 .show
= target_core_show_dev_info
,
1665 static ssize_t
target_core_store_dev_control(
1670 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1671 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1672 struct se_subsystem_api
*t
= hba
->transport
;
1674 if (!(se_dev
->se_dev_su_ptr
)) {
1675 printk(KERN_ERR
"Unable to locate struct se_subsystem_dev>se"
1680 return t
->set_configfs_dev_params(hba
, se_dev
, page
, count
);
1683 static struct target_core_configfs_attribute target_core_attr_dev_control
= {
1684 .attr
= { .ca_owner
= THIS_MODULE
,
1685 .ca_name
= "control",
1686 .ca_mode
= S_IWUSR
},
1688 .store
= target_core_store_dev_control
,
1691 static ssize_t
target_core_show_dev_alias(void *p
, char *page
)
1693 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1695 if (!(se_dev
->su_dev_flags
& SDF_USING_ALIAS
))
1698 return snprintf(page
, PAGE_SIZE
, "%s\n", se_dev
->se_dev_alias
);
1701 static ssize_t
target_core_store_dev_alias(
1706 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1707 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1710 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1711 printk(KERN_ERR
"alias count: %d exceeds"
1712 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1713 SE_DEV_ALIAS_LEN
-1);
1717 se_dev
->su_dev_flags
|= SDF_USING_ALIAS
;
1718 read_bytes
= snprintf(&se_dev
->se_dev_alias
[0], SE_DEV_ALIAS_LEN
,
1721 printk(KERN_INFO
"Target_Core_ConfigFS: %s/%s set alias: %s\n",
1722 config_item_name(&hba
->hba_group
.cg_item
),
1723 config_item_name(&se_dev
->se_dev_group
.cg_item
),
1724 se_dev
->se_dev_alias
);
1729 static struct target_core_configfs_attribute target_core_attr_dev_alias
= {
1730 .attr
= { .ca_owner
= THIS_MODULE
,
1732 .ca_mode
= S_IRUGO
| S_IWUSR
},
1733 .show
= target_core_show_dev_alias
,
1734 .store
= target_core_store_dev_alias
,
1737 static ssize_t
target_core_show_dev_udev_path(void *p
, char *page
)
1739 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1741 if (!(se_dev
->su_dev_flags
& SDF_USING_UDEV_PATH
))
1744 return snprintf(page
, PAGE_SIZE
, "%s\n", se_dev
->se_dev_udev_path
);
1747 static ssize_t
target_core_store_dev_udev_path(
1752 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1753 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1756 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1757 printk(KERN_ERR
"udev_path count: %d exceeds"
1758 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1759 SE_UDEV_PATH_LEN
-1);
1763 se_dev
->su_dev_flags
|= SDF_USING_UDEV_PATH
;
1764 read_bytes
= snprintf(&se_dev
->se_dev_udev_path
[0], SE_UDEV_PATH_LEN
,
1767 printk(KERN_INFO
"Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1768 config_item_name(&hba
->hba_group
.cg_item
),
1769 config_item_name(&se_dev
->se_dev_group
.cg_item
),
1770 se_dev
->se_dev_udev_path
);
1775 static struct target_core_configfs_attribute target_core_attr_dev_udev_path
= {
1776 .attr
= { .ca_owner
= THIS_MODULE
,
1777 .ca_name
= "udev_path",
1778 .ca_mode
= S_IRUGO
| S_IWUSR
},
1779 .show
= target_core_show_dev_udev_path
,
1780 .store
= target_core_store_dev_udev_path
,
1783 static ssize_t
target_core_store_dev_enable(
1788 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1789 struct se_device
*dev
;
1790 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1791 struct se_subsystem_api
*t
= hba
->transport
;
1794 ptr
= strstr(page
, "1");
1796 printk(KERN_ERR
"For dev_enable ops, only valid value"
1800 if ((se_dev
->se_dev_ptr
)) {
1801 printk(KERN_ERR
"se_dev->se_dev_ptr already set for storage"
1806 if (t
->check_configfs_dev_params(hba
, se_dev
) < 0)
1809 dev
= t
->create_virtdevice(hba
, se_dev
, se_dev
->se_dev_su_ptr
);
1811 return PTR_ERR(dev
);
1815 se_dev
->se_dev_ptr
= dev
;
1816 printk(KERN_INFO
"Target_Core_ConfigFS: Registered se_dev->se_dev_ptr:"
1817 " %p\n", se_dev
->se_dev_ptr
);
1822 static struct target_core_configfs_attribute target_core_attr_dev_enable
= {
1823 .attr
= { .ca_owner
= THIS_MODULE
,
1824 .ca_name
= "enable",
1825 .ca_mode
= S_IWUSR
},
1827 .store
= target_core_store_dev_enable
,
1830 static ssize_t
target_core_show_alua_lu_gp(void *p
, char *page
)
1832 struct se_device
*dev
;
1833 struct se_subsystem_dev
*su_dev
= (struct se_subsystem_dev
*)p
;
1834 struct config_item
*lu_ci
;
1835 struct t10_alua_lu_gp
*lu_gp
;
1836 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1839 dev
= su_dev
->se_dev_ptr
;
1843 if (su_dev
->t10_alua
.alua_type
!= SPC3_ALUA_EMULATED
)
1846 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1848 printk(KERN_ERR
"NULL struct se_device->dev_alua_lu_gp_mem"
1853 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1854 lu_gp
= lu_gp_mem
->lu_gp
;
1856 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1857 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1858 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1860 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1865 static ssize_t
target_core_store_alua_lu_gp(
1870 struct se_device
*dev
;
1871 struct se_subsystem_dev
*su_dev
= (struct se_subsystem_dev
*)p
;
1872 struct se_hba
*hba
= su_dev
->se_dev_hba
;
1873 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1874 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1875 unsigned char buf
[LU_GROUP_NAME_BUF
];
1878 dev
= su_dev
->se_dev_ptr
;
1882 if (su_dev
->t10_alua
.alua_type
!= SPC3_ALUA_EMULATED
) {
1883 printk(KERN_WARNING
"SPC3_ALUA_EMULATED not enabled for %s/%s\n",
1884 config_item_name(&hba
->hba_group
.cg_item
),
1885 config_item_name(&su_dev
->se_dev_group
.cg_item
));
1888 if (count
> LU_GROUP_NAME_BUF
) {
1889 printk(KERN_ERR
"ALUA LU Group Alias too large!\n");
1892 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1893 memcpy(buf
, page
, count
);
1895 * Any ALUA logical unit alias besides "NULL" means we will be
1896 * making a new group association.
1898 if (strcmp(strstrip(buf
), "NULL")) {
1900 * core_alua_get_lu_gp_by_name() will increment reference to
1901 * struct t10_alua_lu_gp. This reference is released with
1902 * core_alua_get_lu_gp_by_name below().
1904 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
1908 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1911 core_alua_put_lu_gp_from_name(lu_gp_new
);
1912 printk(KERN_ERR
"NULL struct se_device->dev_alua_lu_gp_mem"
1917 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1918 lu_gp
= lu_gp_mem
->lu_gp
;
1921 * Clearing an existing lu_gp association, and replacing
1925 printk(KERN_INFO
"Target_Core_ConfigFS: Releasing %s/%s"
1926 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1928 config_item_name(&hba
->hba_group
.cg_item
),
1929 config_item_name(&su_dev
->se_dev_group
.cg_item
),
1930 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1933 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1934 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1939 * Removing existing association of lu_gp_mem with lu_gp
1941 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1945 * Associate lu_gp_mem with lu_gp_new.
1947 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
1948 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1950 printk(KERN_INFO
"Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1951 " core/alua/lu_gps/%s, ID: %hu\n",
1952 (move
) ? "Moving" : "Adding",
1953 config_item_name(&hba
->hba_group
.cg_item
),
1954 config_item_name(&su_dev
->se_dev_group
.cg_item
),
1955 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
1956 lu_gp_new
->lu_gp_id
);
1958 core_alua_put_lu_gp_from_name(lu_gp_new
);
1962 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp
= {
1963 .attr
= { .ca_owner
= THIS_MODULE
,
1964 .ca_name
= "alua_lu_gp",
1965 .ca_mode
= S_IRUGO
| S_IWUSR
},
1966 .show
= target_core_show_alua_lu_gp
,
1967 .store
= target_core_store_alua_lu_gp
,
1970 static struct configfs_attribute
*lio_core_dev_attrs
[] = {
1971 &target_core_attr_dev_info
.attr
,
1972 &target_core_attr_dev_control
.attr
,
1973 &target_core_attr_dev_alias
.attr
,
1974 &target_core_attr_dev_udev_path
.attr
,
1975 &target_core_attr_dev_enable
.attr
,
1976 &target_core_attr_dev_alua_lu_gp
.attr
,
1980 static void target_core_dev_release(struct config_item
*item
)
1982 struct se_subsystem_dev
*se_dev
= container_of(to_config_group(item
),
1983 struct se_subsystem_dev
, se_dev_group
);
1984 struct se_hba
*hba
= item_to_hba(&se_dev
->se_dev_hba
->hba_group
.cg_item
);
1985 struct se_subsystem_api
*t
= hba
->transport
;
1986 struct config_group
*dev_cg
= &se_dev
->se_dev_group
;
1988 kfree(dev_cg
->default_groups
);
1990 * This pointer will set when the storage is enabled with:
1991 *`echo 1 > $CONFIGFS/core/$HBA/$DEV/dev_enable`
1993 if (se_dev
->se_dev_ptr
) {
1994 printk(KERN_INFO
"Target_Core_ConfigFS: Calling se_free_"
1995 "virtual_device() for se_dev_ptr: %p\n",
1996 se_dev
->se_dev_ptr
);
1998 se_free_virtual_device(se_dev
->se_dev_ptr
, hba
);
2001 * Release struct se_subsystem_dev->se_dev_su_ptr..
2003 printk(KERN_INFO
"Target_Core_ConfigFS: Calling t->free_"
2004 "device() for se_dev_su_ptr: %p\n",
2005 se_dev
->se_dev_su_ptr
);
2007 t
->free_device(se_dev
->se_dev_su_ptr
);
2010 printk(KERN_INFO
"Target_Core_ConfigFS: Deallocating se_subsystem"
2011 "_dev_t: %p\n", se_dev
);
2015 static ssize_t
target_core_dev_show(struct config_item
*item
,
2016 struct configfs_attribute
*attr
,
2019 struct se_subsystem_dev
*se_dev
= container_of(
2020 to_config_group(item
), struct se_subsystem_dev
,
2022 struct target_core_configfs_attribute
*tc_attr
= container_of(
2023 attr
, struct target_core_configfs_attribute
, attr
);
2025 if (!(tc_attr
->show
))
2028 return tc_attr
->show(se_dev
, page
);
2031 static ssize_t
target_core_dev_store(struct config_item
*item
,
2032 struct configfs_attribute
*attr
,
2033 const char *page
, size_t count
)
2035 struct se_subsystem_dev
*se_dev
= container_of(
2036 to_config_group(item
), struct se_subsystem_dev
,
2038 struct target_core_configfs_attribute
*tc_attr
= container_of(
2039 attr
, struct target_core_configfs_attribute
, attr
);
2041 if (!(tc_attr
->store
))
2044 return tc_attr
->store(se_dev
, page
, count
);
2047 static struct configfs_item_operations target_core_dev_item_ops
= {
2048 .release
= target_core_dev_release
,
2049 .show_attribute
= target_core_dev_show
,
2050 .store_attribute
= target_core_dev_store
,
2053 static struct config_item_type target_core_dev_cit
= {
2054 .ct_item_ops
= &target_core_dev_item_ops
,
2055 .ct_attrs
= lio_core_dev_attrs
,
2056 .ct_owner
= THIS_MODULE
,
2059 /* End functions for struct config_item_type target_core_dev_cit */
2061 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
2063 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp
, t10_alua_lu_gp
);
2064 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
2065 static struct target_core_alua_lu_gp_attribute \
2066 target_core_alua_lu_gp_##_name = \
2067 __CONFIGFS_EATTR(_name, _mode, \
2068 target_core_alua_lu_gp_show_attr_##_name, \
2069 target_core_alua_lu_gp_store_attr_##_name);
2071 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
2072 static struct target_core_alua_lu_gp_attribute \
2073 target_core_alua_lu_gp_##_name = \
2074 __CONFIGFS_EATTR_RO(_name, \
2075 target_core_alua_lu_gp_show_attr_##_name);
2080 static ssize_t
target_core_alua_lu_gp_show_attr_lu_gp_id(
2081 struct t10_alua_lu_gp
*lu_gp
,
2084 if (!(lu_gp
->lu_gp_valid_id
))
2087 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
2090 static ssize_t
target_core_alua_lu_gp_store_attr_lu_gp_id(
2091 struct t10_alua_lu_gp
*lu_gp
,
2095 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2096 unsigned long lu_gp_id
;
2099 ret
= strict_strtoul(page
, 0, &lu_gp_id
);
2101 printk(KERN_ERR
"strict_strtoul() returned %d for"
2102 " lu_gp_id\n", ret
);
2105 if (lu_gp_id
> 0x0000ffff) {
2106 printk(KERN_ERR
"ALUA lu_gp_id: %lu exceeds maximum:"
2107 " 0x0000ffff\n", lu_gp_id
);
2111 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
2115 printk(KERN_INFO
"Target_Core_ConfigFS: Set ALUA Logical Unit"
2116 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2117 config_item_name(&alua_lu_gp_cg
->cg_item
),
2123 SE_DEV_ALUA_LU_ATTR(lu_gp_id
, S_IRUGO
| S_IWUSR
);
2128 static ssize_t
target_core_alua_lu_gp_show_attr_members(
2129 struct t10_alua_lu_gp
*lu_gp
,
2132 struct se_device
*dev
;
2134 struct se_subsystem_dev
*su_dev
;
2135 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2136 ssize_t len
= 0, cur_len
;
2137 unsigned char buf
[LU_GROUP_NAME_BUF
];
2139 memset(buf
, 0, LU_GROUP_NAME_BUF
);
2141 spin_lock(&lu_gp
->lu_gp_lock
);
2142 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
2143 dev
= lu_gp_mem
->lu_gp_mem_dev
;
2144 su_dev
= dev
->se_sub_dev
;
2145 hba
= su_dev
->se_dev_hba
;
2147 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
2148 config_item_name(&hba
->hba_group
.cg_item
),
2149 config_item_name(&su_dev
->se_dev_group
.cg_item
));
2150 cur_len
++; /* Extra byte for NULL terminator */
2152 if ((cur_len
+ len
) > PAGE_SIZE
) {
2153 printk(KERN_WARNING
"Ran out of lu_gp_show_attr"
2154 "_members buffer\n");
2157 memcpy(page
+len
, buf
, cur_len
);
2160 spin_unlock(&lu_gp
->lu_gp_lock
);
2165 SE_DEV_ALUA_LU_ATTR_RO(members
);
2167 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp
, t10_alua_lu_gp
, lu_gp_group
);
2169 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
2170 &target_core_alua_lu_gp_lu_gp_id
.attr
,
2171 &target_core_alua_lu_gp_members
.attr
,
2175 static void target_core_alua_lu_gp_release(struct config_item
*item
)
2177 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2178 struct t10_alua_lu_gp
, lu_gp_group
);
2180 core_alua_free_lu_gp(lu_gp
);
2183 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
2184 .release
= target_core_alua_lu_gp_release
,
2185 .show_attribute
= target_core_alua_lu_gp_attr_show
,
2186 .store_attribute
= target_core_alua_lu_gp_attr_store
,
2189 static struct config_item_type target_core_alua_lu_gp_cit
= {
2190 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
2191 .ct_attrs
= target_core_alua_lu_gp_attrs
,
2192 .ct_owner
= THIS_MODULE
,
2195 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
2197 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
2199 static struct config_group
*target_core_alua_create_lu_gp(
2200 struct config_group
*group
,
2203 struct t10_alua_lu_gp
*lu_gp
;
2204 struct config_group
*alua_lu_gp_cg
= NULL
;
2205 struct config_item
*alua_lu_gp_ci
= NULL
;
2207 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
2211 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2212 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
2214 config_group_init_type_name(alua_lu_gp_cg
, name
,
2215 &target_core_alua_lu_gp_cit
);
2217 printk(KERN_INFO
"Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2218 " Group: core/alua/lu_gps/%s\n",
2219 config_item_name(alua_lu_gp_ci
));
2221 return alua_lu_gp_cg
;
2225 static void target_core_alua_drop_lu_gp(
2226 struct config_group
*group
,
2227 struct config_item
*item
)
2229 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2230 struct t10_alua_lu_gp
, lu_gp_group
);
2232 printk(KERN_INFO
"Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2233 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2234 config_item_name(item
), lu_gp
->lu_gp_id
);
2236 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
2237 * -> target_core_alua_lu_gp_release()
2239 config_item_put(item
);
2242 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
2243 .make_group
= &target_core_alua_create_lu_gp
,
2244 .drop_item
= &target_core_alua_drop_lu_gp
,
2247 static struct config_item_type target_core_alua_lu_gps_cit
= {
2248 .ct_item_ops
= NULL
,
2249 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
2250 .ct_owner
= THIS_MODULE
,
2253 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
2255 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2257 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
);
2258 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
2259 static struct target_core_alua_tg_pt_gp_attribute \
2260 target_core_alua_tg_pt_gp_##_name = \
2261 __CONFIGFS_EATTR(_name, _mode, \
2262 target_core_alua_tg_pt_gp_show_attr_##_name, \
2263 target_core_alua_tg_pt_gp_store_attr_##_name);
2265 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2266 static struct target_core_alua_tg_pt_gp_attribute \
2267 target_core_alua_tg_pt_gp_##_name = \
2268 __CONFIGFS_EATTR_RO(_name, \
2269 target_core_alua_tg_pt_gp_show_attr_##_name);
2274 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2275 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2278 return sprintf(page
, "%d\n",
2279 atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
));
2282 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2283 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2287 struct se_subsystem_dev
*su_dev
= tg_pt_gp
->tg_pt_gp_su_dev
;
2291 if (!(tg_pt_gp
->tg_pt_gp_valid_id
)) {
2292 printk(KERN_ERR
"Unable to do implict ALUA on non valid"
2293 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2297 ret
= strict_strtoul(page
, 0, &tmp
);
2299 printk("Unable to extract new ALUA access state from"
2303 new_state
= (int)tmp
;
2305 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICT_ALUA
)) {
2306 printk(KERN_ERR
"Unable to process implict configfs ALUA"
2307 " transition while TPGS_IMPLICT_ALUA is diabled\n");
2311 ret
= core_alua_do_port_transition(tg_pt_gp
, su_dev
->se_dev_ptr
,
2312 NULL
, NULL
, new_state
, 0);
2313 return (!ret
) ? count
: -EINVAL
;
2316 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state
, S_IRUGO
| S_IWUSR
);
2319 * alua_access_status
2321 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2322 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2325 return sprintf(page
, "%s\n",
2326 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2329 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2330 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2335 int new_status
, ret
;
2337 if (!(tg_pt_gp
->tg_pt_gp_valid_id
)) {
2338 printk(KERN_ERR
"Unable to do set ALUA access status on non"
2339 " valid tg_pt_gp ID: %hu\n",
2340 tg_pt_gp
->tg_pt_gp_valid_id
);
2344 ret
= strict_strtoul(page
, 0, &tmp
);
2346 printk(KERN_ERR
"Unable to extract new ALUA access status"
2347 " from %s\n", page
);
2350 new_status
= (int)tmp
;
2352 if ((new_status
!= ALUA_STATUS_NONE
) &&
2353 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
) &&
2354 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
)) {
2355 printk(KERN_ERR
"Illegal ALUA access status: 0x%02x\n",
2360 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2364 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status
, S_IRUGO
| S_IWUSR
);
2369 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2370 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2373 return core_alua_show_access_type(tg_pt_gp
, page
);
2376 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2377 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2381 return core_alua_store_access_type(tg_pt_gp
, page
, count
);
2384 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type
, S_IRUGO
| S_IWUSR
);
2387 * alua_write_metadata
2389 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2390 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2393 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_write_metadata
);
2396 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2397 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2404 ret
= strict_strtoul(page
, 0, &tmp
);
2406 printk(KERN_ERR
"Unable to extract alua_write_metadata\n");
2410 if ((tmp
!= 0) && (tmp
!= 1)) {
2411 printk(KERN_ERR
"Illegal value for alua_write_metadata:"
2415 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2420 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata
, S_IRUGO
| S_IWUSR
);
2427 static ssize_t
target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2428 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2431 return core_alua_show_nonop_delay_msecs(tg_pt_gp
, page
);
2435 static ssize_t
target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2436 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2440 return core_alua_store_nonop_delay_msecs(tg_pt_gp
, page
, count
);
2443 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs
, S_IRUGO
| S_IWUSR
);
2448 static ssize_t
target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2449 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2452 return core_alua_show_trans_delay_msecs(tg_pt_gp
, page
);
2455 static ssize_t
target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2456 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2460 return core_alua_store_trans_delay_msecs(tg_pt_gp
, page
, count
);
2463 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs
, S_IRUGO
| S_IWUSR
);
2469 static ssize_t
target_core_alua_tg_pt_gp_show_attr_preferred(
2470 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2473 return core_alua_show_preferred_bit(tg_pt_gp
, page
);
2476 static ssize_t
target_core_alua_tg_pt_gp_store_attr_preferred(
2477 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2481 return core_alua_store_preferred_bit(tg_pt_gp
, page
, count
);
2484 SE_DEV_ALUA_TG_PT_ATTR(preferred
, S_IRUGO
| S_IWUSR
);
2489 static ssize_t
target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2490 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2493 if (!(tg_pt_gp
->tg_pt_gp_valid_id
))
2496 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2499 static ssize_t
target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2500 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2504 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2505 unsigned long tg_pt_gp_id
;
2508 ret
= strict_strtoul(page
, 0, &tg_pt_gp_id
);
2510 printk(KERN_ERR
"strict_strtoul() returned %d for"
2511 " tg_pt_gp_id\n", ret
);
2514 if (tg_pt_gp_id
> 0x0000ffff) {
2515 printk(KERN_ERR
"ALUA tg_pt_gp_id: %lu exceeds maximum:"
2516 " 0x0000ffff\n", tg_pt_gp_id
);
2520 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2524 printk(KERN_INFO
"Target_Core_ConfigFS: Set ALUA Target Port Group: "
2525 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2526 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2527 tg_pt_gp
->tg_pt_gp_id
);
2532 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id
, S_IRUGO
| S_IWUSR
);
2537 static ssize_t
target_core_alua_tg_pt_gp_show_attr_members(
2538 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2541 struct se_port
*port
;
2542 struct se_portal_group
*tpg
;
2544 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
2545 ssize_t len
= 0, cur_len
;
2546 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2548 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2550 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2551 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
2552 tg_pt_gp_mem_list
) {
2553 port
= tg_pt_gp_mem
->tg_pt
;
2554 tpg
= port
->sep_tpg
;
2555 lun
= port
->sep_lun
;
2557 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2558 "/%s\n", tpg
->se_tpg_tfo
->get_fabric_name(),
2559 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
2560 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
2561 config_item_name(&lun
->lun_group
.cg_item
));
2562 cur_len
++; /* Extra byte for NULL terminator */
2564 if ((cur_len
+ len
) > PAGE_SIZE
) {
2565 printk(KERN_WARNING
"Ran out of lu_gp_show_attr"
2566 "_members buffer\n");
2569 memcpy(page
+len
, buf
, cur_len
);
2572 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2577 SE_DEV_ALUA_TG_PT_ATTR_RO(members
);
2579 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
,
2582 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2583 &target_core_alua_tg_pt_gp_alua_access_state
.attr
,
2584 &target_core_alua_tg_pt_gp_alua_access_status
.attr
,
2585 &target_core_alua_tg_pt_gp_alua_access_type
.attr
,
2586 &target_core_alua_tg_pt_gp_alua_write_metadata
.attr
,
2587 &target_core_alua_tg_pt_gp_nonop_delay_msecs
.attr
,
2588 &target_core_alua_tg_pt_gp_trans_delay_msecs
.attr
,
2589 &target_core_alua_tg_pt_gp_preferred
.attr
,
2590 &target_core_alua_tg_pt_gp_tg_pt_gp_id
.attr
,
2591 &target_core_alua_tg_pt_gp_members
.attr
,
2595 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2597 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2598 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2600 core_alua_free_tg_pt_gp(tg_pt_gp
);
2603 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2604 .release
= target_core_alua_tg_pt_gp_release
,
2605 .show_attribute
= target_core_alua_tg_pt_gp_attr_show
,
2606 .store_attribute
= target_core_alua_tg_pt_gp_attr_store
,
2609 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2610 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2611 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2612 .ct_owner
= THIS_MODULE
,
2615 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2617 /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2619 static struct config_group
*target_core_alua_create_tg_pt_gp(
2620 struct config_group
*group
,
2623 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2624 alua_tg_pt_gps_group
);
2625 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2626 struct se_subsystem_dev
*su_dev
= alua
->t10_sub_dev
;
2627 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2628 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2630 tg_pt_gp
= core_alua_allocate_tg_pt_gp(su_dev
, name
, 0);
2634 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2635 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2637 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2638 &target_core_alua_tg_pt_gp_cit
);
2640 printk(KERN_INFO
"Target_Core_ConfigFS: Allocated ALUA Target Port"
2641 " Group: alua/tg_pt_gps/%s\n",
2642 config_item_name(alua_tg_pt_gp_ci
));
2644 return alua_tg_pt_gp_cg
;
2647 static void target_core_alua_drop_tg_pt_gp(
2648 struct config_group
*group
,
2649 struct config_item
*item
)
2651 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2652 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2654 printk(KERN_INFO
"Target_Core_ConfigFS: Releasing ALUA Target Port"
2655 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2656 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2658 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2659 * -> target_core_alua_tg_pt_gp_release().
2661 config_item_put(item
);
2664 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2665 .make_group
= &target_core_alua_create_tg_pt_gp
,
2666 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2669 static struct config_item_type target_core_alua_tg_pt_gps_cit
= {
2670 .ct_group_ops
= &target_core_alua_tg_pt_gps_group_ops
,
2671 .ct_owner
= THIS_MODULE
,
2674 /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2676 /* Start functions for struct config_item_type target_core_alua_cit */
2679 * target_core_alua_cit is a ConfigFS group that lives under
2680 * /sys/kernel/config/target/core/alua. There are default groups
2681 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2682 * target_core_alua_cit in target_core_init_configfs() below.
2684 static struct config_item_type target_core_alua_cit
= {
2685 .ct_item_ops
= NULL
,
2687 .ct_owner
= THIS_MODULE
,
2690 /* End functions for struct config_item_type target_core_alua_cit */
2692 /* Start functions for struct config_item_type target_core_stat_cit */
2694 static struct config_group
*target_core_stat_mkdir(
2695 struct config_group
*group
,
2698 return ERR_PTR(-ENOSYS
);
2701 static void target_core_stat_rmdir(
2702 struct config_group
*group
,
2703 struct config_item
*item
)
2708 static struct configfs_group_operations target_core_stat_group_ops
= {
2709 .make_group
= &target_core_stat_mkdir
,
2710 .drop_item
= &target_core_stat_rmdir
,
2713 static struct config_item_type target_core_stat_cit
= {
2714 .ct_group_ops
= &target_core_stat_group_ops
,
2715 .ct_owner
= THIS_MODULE
,
2718 /* End functions for struct config_item_type target_core_stat_cit */
2720 /* Start functions for struct config_item_type target_core_hba_cit */
2722 static struct config_group
*target_core_make_subdev(
2723 struct config_group
*group
,
2726 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2727 struct se_subsystem_dev
*se_dev
;
2728 struct se_subsystem_api
*t
;
2729 struct config_item
*hba_ci
= &group
->cg_item
;
2730 struct se_hba
*hba
= item_to_hba(hba_ci
);
2731 struct config_group
*dev_cg
= NULL
, *tg_pt_gp_cg
= NULL
;
2732 struct config_group
*dev_stat_grp
= NULL
;
2733 int errno
= -ENOMEM
, ret
;
2735 ret
= mutex_lock_interruptible(&hba
->hba_access_mutex
);
2737 return ERR_PTR(ret
);
2739 * Locate the struct se_subsystem_api from parent's struct se_hba.
2743 se_dev
= kzalloc(sizeof(struct se_subsystem_dev
), GFP_KERNEL
);
2745 printk(KERN_ERR
"Unable to allocate memory for"
2746 " struct se_subsystem_dev\n");
2749 INIT_LIST_HEAD(&se_dev
->se_dev_node
);
2750 INIT_LIST_HEAD(&se_dev
->t10_wwn
.t10_vpd_list
);
2751 spin_lock_init(&se_dev
->t10_wwn
.t10_vpd_lock
);
2752 INIT_LIST_HEAD(&se_dev
->t10_pr
.registration_list
);
2753 INIT_LIST_HEAD(&se_dev
->t10_pr
.aptpl_reg_list
);
2754 spin_lock_init(&se_dev
->t10_pr
.registration_lock
);
2755 spin_lock_init(&se_dev
->t10_pr
.aptpl_reg_lock
);
2756 INIT_LIST_HEAD(&se_dev
->t10_alua
.tg_pt_gps_list
);
2757 spin_lock_init(&se_dev
->t10_alua
.tg_pt_gps_lock
);
2758 spin_lock_init(&se_dev
->se_dev_lock
);
2759 se_dev
->t10_pr
.pr_aptpl_buf_len
= PR_APTPL_BUF_LEN
;
2760 se_dev
->t10_wwn
.t10_sub_dev
= se_dev
;
2761 se_dev
->t10_alua
.t10_sub_dev
= se_dev
;
2762 se_dev
->se_dev_attrib
.da_sub_dev
= se_dev
;
2764 se_dev
->se_dev_hba
= hba
;
2765 dev_cg
= &se_dev
->se_dev_group
;
2767 dev_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 7,
2769 if (!(dev_cg
->default_groups
))
2772 * Set se_dev_su_ptr from struct se_subsystem_api returned void ptr
2773 * for ->allocate_virtdevice()
2775 * se_dev->se_dev_ptr will be set after ->create_virtdev()
2776 * has been called successfully in the next level up in the
2777 * configfs tree for device object's struct config_group.
2779 se_dev
->se_dev_su_ptr
= t
->allocate_virtdevice(hba
, name
);
2780 if (!(se_dev
->se_dev_su_ptr
)) {
2781 printk(KERN_ERR
"Unable to locate subsystem dependent pointer"
2782 " from allocate_virtdevice()\n");
2785 spin_lock(&se_device_lock
);
2786 list_add_tail(&se_dev
->se_dev_node
, &se_dev_list
);
2787 spin_unlock(&se_device_lock
);
2789 config_group_init_type_name(&se_dev
->se_dev_group
, name
,
2790 &target_core_dev_cit
);
2791 config_group_init_type_name(&se_dev
->se_dev_attrib
.da_group
, "attrib",
2792 &target_core_dev_attrib_cit
);
2793 config_group_init_type_name(&se_dev
->se_dev_pr_group
, "pr",
2794 &target_core_dev_pr_cit
);
2795 config_group_init_type_name(&se_dev
->t10_wwn
.t10_wwn_group
, "wwn",
2796 &target_core_dev_wwn_cit
);
2797 config_group_init_type_name(&se_dev
->t10_alua
.alua_tg_pt_gps_group
,
2798 "alua", &target_core_alua_tg_pt_gps_cit
);
2799 config_group_init_type_name(&se_dev
->dev_stat_grps
.stat_group
,
2800 "statistics", &target_core_stat_cit
);
2802 dev_cg
->default_groups
[0] = &se_dev
->se_dev_attrib
.da_group
;
2803 dev_cg
->default_groups
[1] = &se_dev
->se_dev_pr_group
;
2804 dev_cg
->default_groups
[2] = &se_dev
->t10_wwn
.t10_wwn_group
;
2805 dev_cg
->default_groups
[3] = &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2806 dev_cg
->default_groups
[4] = &se_dev
->dev_stat_grps
.stat_group
;
2807 dev_cg
->default_groups
[5] = NULL
;
2809 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
2811 tg_pt_gp
= core_alua_allocate_tg_pt_gp(se_dev
, "default_tg_pt_gp", 1);
2815 tg_pt_gp_cg
= &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2816 tg_pt_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
2818 if (!(tg_pt_gp_cg
->default_groups
)) {
2819 printk(KERN_ERR
"Unable to allocate tg_pt_gp_cg->"
2820 "default_groups\n");
2824 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2825 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2826 tg_pt_gp_cg
->default_groups
[0] = &tg_pt_gp
->tg_pt_gp_group
;
2827 tg_pt_gp_cg
->default_groups
[1] = NULL
;
2828 se_dev
->t10_alua
.default_tg_pt_gp
= tg_pt_gp
;
2830 * Add core/$HBA/$DEV/statistics/ default groups
2832 dev_stat_grp
= &se_dev
->dev_stat_grps
.stat_group
;
2833 dev_stat_grp
->default_groups
= kzalloc(sizeof(struct config_group
) * 4,
2835 if (!dev_stat_grp
->default_groups
) {
2836 printk(KERN_ERR
"Unable to allocate dev_stat_grp->default_groups\n");
2839 target_stat_setup_dev_default_groups(se_dev
);
2841 printk(KERN_INFO
"Target_Core_ConfigFS: Allocated struct se_subsystem_dev:"
2842 " %p se_dev_su_ptr: %p\n", se_dev
, se_dev
->se_dev_su_ptr
);
2844 mutex_unlock(&hba
->hba_access_mutex
);
2845 return &se_dev
->se_dev_group
;
2847 if (se_dev
->t10_alua
.default_tg_pt_gp
) {
2848 core_alua_free_tg_pt_gp(se_dev
->t10_alua
.default_tg_pt_gp
);
2849 se_dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2852 kfree(dev_stat_grp
->default_groups
);
2854 kfree(tg_pt_gp_cg
->default_groups
);
2856 kfree(dev_cg
->default_groups
);
2857 if (se_dev
->se_dev_su_ptr
)
2858 t
->free_device(se_dev
->se_dev_su_ptr
);
2861 mutex_unlock(&hba
->hba_access_mutex
);
2862 return ERR_PTR(errno
);
2865 static void target_core_drop_subdev(
2866 struct config_group
*group
,
2867 struct config_item
*item
)
2869 struct se_subsystem_dev
*se_dev
= container_of(to_config_group(item
),
2870 struct se_subsystem_dev
, se_dev_group
);
2872 struct se_subsystem_api
*t
;
2873 struct config_item
*df_item
;
2874 struct config_group
*dev_cg
, *tg_pt_gp_cg
, *dev_stat_grp
;
2877 hba
= item_to_hba(&se_dev
->se_dev_hba
->hba_group
.cg_item
);
2879 mutex_lock(&hba
->hba_access_mutex
);
2882 spin_lock(&se_device_lock
);
2883 list_del(&se_dev
->se_dev_node
);
2884 spin_unlock(&se_device_lock
);
2886 dev_stat_grp
= &se_dev
->dev_stat_grps
.stat_group
;
2887 for (i
= 0; dev_stat_grp
->default_groups
[i
]; i
++) {
2888 df_item
= &dev_stat_grp
->default_groups
[i
]->cg_item
;
2889 dev_stat_grp
->default_groups
[i
] = NULL
;
2890 config_item_put(df_item
);
2892 kfree(dev_stat_grp
->default_groups
);
2894 tg_pt_gp_cg
= &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2895 for (i
= 0; tg_pt_gp_cg
->default_groups
[i
]; i
++) {
2896 df_item
= &tg_pt_gp_cg
->default_groups
[i
]->cg_item
;
2897 tg_pt_gp_cg
->default_groups
[i
] = NULL
;
2898 config_item_put(df_item
);
2900 kfree(tg_pt_gp_cg
->default_groups
);
2902 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2903 * directly from target_core_alua_tg_pt_gp_release().
2905 se_dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2907 dev_cg
= &se_dev
->se_dev_group
;
2908 for (i
= 0; dev_cg
->default_groups
[i
]; i
++) {
2909 df_item
= &dev_cg
->default_groups
[i
]->cg_item
;
2910 dev_cg
->default_groups
[i
] = NULL
;
2911 config_item_put(df_item
);
2914 * The releasing of se_dev and associated se_dev->se_dev_ptr is done
2915 * from target_core_dev_item_ops->release() ->target_core_dev_release().
2917 config_item_put(item
);
2918 mutex_unlock(&hba
->hba_access_mutex
);
2921 static struct configfs_group_operations target_core_hba_group_ops
= {
2922 .make_group
= target_core_make_subdev
,
2923 .drop_item
= target_core_drop_subdev
,
2926 CONFIGFS_EATTR_STRUCT(target_core_hba
, se_hba
);
2927 #define SE_HBA_ATTR(_name, _mode) \
2928 static struct target_core_hba_attribute \
2929 target_core_hba_##_name = \
2930 __CONFIGFS_EATTR(_name, _mode, \
2931 target_core_hba_show_attr_##_name, \
2932 target_core_hba_store_attr_##_name);
2934 #define SE_HBA_ATTR_RO(_name) \
2935 static struct target_core_hba_attribute \
2936 target_core_hba_##_name = \
2937 __CONFIGFS_EATTR_RO(_name, \
2938 target_core_hba_show_attr_##_name);
2940 static ssize_t
target_core_hba_show_attr_hba_info(
2944 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
2945 hba
->hba_id
, hba
->transport
->name
,
2946 TARGET_CORE_CONFIGFS_VERSION
);
2949 SE_HBA_ATTR_RO(hba_info
);
2951 static ssize_t
target_core_hba_show_attr_hba_mode(struct se_hba
*hba
,
2956 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
2959 return sprintf(page
, "%d\n", hba_mode
);
2962 static ssize_t
target_core_hba_store_attr_hba_mode(struct se_hba
*hba
,
2963 const char *page
, size_t count
)
2965 struct se_subsystem_api
*transport
= hba
->transport
;
2966 unsigned long mode_flag
;
2969 if (transport
->pmode_enable_hba
== NULL
)
2972 ret
= strict_strtoul(page
, 0, &mode_flag
);
2974 printk(KERN_ERR
"Unable to extract hba mode flag: %d\n", ret
);
2978 spin_lock(&hba
->device_lock
);
2979 if (!(list_empty(&hba
->hba_dev_list
))) {
2980 printk(KERN_ERR
"Unable to set hba_mode with active devices\n");
2981 spin_unlock(&hba
->device_lock
);
2984 spin_unlock(&hba
->device_lock
);
2986 ret
= transport
->pmode_enable_hba(hba
, mode_flag
);
2990 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
2992 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
2997 SE_HBA_ATTR(hba_mode
, S_IRUGO
| S_IWUSR
);
2999 CONFIGFS_EATTR_OPS(target_core_hba
, se_hba
, hba_group
);
3001 static void target_core_hba_release(struct config_item
*item
)
3003 struct se_hba
*hba
= container_of(to_config_group(item
),
3004 struct se_hba
, hba_group
);
3005 core_delete_hba(hba
);
3008 static struct configfs_attribute
*target_core_hba_attrs
[] = {
3009 &target_core_hba_hba_info
.attr
,
3010 &target_core_hba_hba_mode
.attr
,
3014 static struct configfs_item_operations target_core_hba_item_ops
= {
3015 .release
= target_core_hba_release
,
3016 .show_attribute
= target_core_hba_attr_show
,
3017 .store_attribute
= target_core_hba_attr_store
,
3020 static struct config_item_type target_core_hba_cit
= {
3021 .ct_item_ops
= &target_core_hba_item_ops
,
3022 .ct_group_ops
= &target_core_hba_group_ops
,
3023 .ct_attrs
= target_core_hba_attrs
,
3024 .ct_owner
= THIS_MODULE
,
3027 static struct config_group
*target_core_call_addhbatotarget(
3028 struct config_group
*group
,
3031 char *se_plugin_str
, *str
, *str2
;
3033 char buf
[TARGET_CORE_NAME_MAX_LEN
];
3034 unsigned long plugin_dep_id
= 0;
3037 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
3038 if (strlen(name
) >= TARGET_CORE_NAME_MAX_LEN
) {
3039 printk(KERN_ERR
"Passed *name strlen(): %d exceeds"
3040 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
3041 TARGET_CORE_NAME_MAX_LEN
);
3042 return ERR_PTR(-ENAMETOOLONG
);
3044 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
3046 str
= strstr(buf
, "_");
3048 printk(KERN_ERR
"Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
3049 return ERR_PTR(-EINVAL
);
3051 se_plugin_str
= buf
;
3053 * Special case for subsystem plugins that have "_" in their names.
3054 * Namely rd_direct and rd_mcp..
3056 str2
= strstr(str
+1, "_");
3058 *str2
= '\0'; /* Terminate for *se_plugin_str */
3059 str2
++; /* Skip to start of plugin dependent ID */
3062 *str
= '\0'; /* Terminate for *se_plugin_str */
3063 str
++; /* Skip to start of plugin dependent ID */
3066 ret
= strict_strtoul(str
, 0, &plugin_dep_id
);
3068 printk(KERN_ERR
"strict_strtoul() returned %d for"
3069 " plugin_dep_id\n", ret
);
3070 return ERR_PTR(-EINVAL
);
3073 * Load up TCM subsystem plugins if they have not already been loaded.
3075 if (transport_subsystem_check_init() < 0)
3076 return ERR_PTR(-EINVAL
);
3078 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
3080 return ERR_CAST(hba
);
3082 config_group_init_type_name(&hba
->hba_group
, name
,
3083 &target_core_hba_cit
);
3085 return &hba
->hba_group
;
3088 static void target_core_call_delhbafromtarget(
3089 struct config_group
*group
,
3090 struct config_item
*item
)
3093 * core_delete_hba() is called from target_core_hba_item_ops->release()
3094 * -> target_core_hba_release()
3096 config_item_put(item
);
3099 static struct configfs_group_operations target_core_group_ops
= {
3100 .make_group
= target_core_call_addhbatotarget
,
3101 .drop_item
= target_core_call_delhbafromtarget
,
3104 static struct config_item_type target_core_cit
= {
3105 .ct_item_ops
= NULL
,
3106 .ct_group_ops
= &target_core_group_ops
,
3108 .ct_owner
= THIS_MODULE
,
3111 /* Stop functions for struct config_item_type target_core_hba_cit */
3113 static int __init
target_core_init_configfs(void)
3115 struct config_group
*target_cg
, *hba_cg
= NULL
, *alua_cg
= NULL
;
3116 struct config_group
*lu_gp_cg
= NULL
;
3117 struct configfs_subsystem
*subsys
;
3118 struct t10_alua_lu_gp
*lu_gp
;
3121 printk(KERN_INFO
"TARGET_CORE[0]: Loading Generic Kernel Storage"
3122 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
3123 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
3125 subsys
= target_core_subsystem
[0];
3126 config_group_init(&subsys
->su_group
);
3127 mutex_init(&subsys
->su_mutex
);
3129 INIT_LIST_HEAD(&g_tf_list
);
3130 mutex_init(&g_tf_lock
);
3131 ret
= init_se_kmem_caches();
3135 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
3136 * and ALUA Logical Unit Group and Target Port Group infrastructure.
3138 target_cg
= &subsys
->su_group
;
3139 target_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3141 if (!(target_cg
->default_groups
)) {
3142 printk(KERN_ERR
"Unable to allocate target_cg->default_groups\n");
3146 config_group_init_type_name(&target_core_hbagroup
,
3147 "core", &target_core_cit
);
3148 target_cg
->default_groups
[0] = &target_core_hbagroup
;
3149 target_cg
->default_groups
[1] = NULL
;
3151 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
3153 hba_cg
= &target_core_hbagroup
;
3154 hba_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3156 if (!(hba_cg
->default_groups
)) {
3157 printk(KERN_ERR
"Unable to allocate hba_cg->default_groups\n");
3160 config_group_init_type_name(&alua_group
,
3161 "alua", &target_core_alua_cit
);
3162 hba_cg
->default_groups
[0] = &alua_group
;
3163 hba_cg
->default_groups
[1] = NULL
;
3165 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
3166 * groups under /sys/kernel/config/target/core/alua/
3168 alua_cg
= &alua_group
;
3169 alua_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3171 if (!(alua_cg
->default_groups
)) {
3172 printk(KERN_ERR
"Unable to allocate alua_cg->default_groups\n");
3176 config_group_init_type_name(&alua_lu_gps_group
,
3177 "lu_gps", &target_core_alua_lu_gps_cit
);
3178 alua_cg
->default_groups
[0] = &alua_lu_gps_group
;
3179 alua_cg
->default_groups
[1] = NULL
;
3181 * Add core/alua/lu_gps/default_lu_gp
3183 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
3187 lu_gp_cg
= &alua_lu_gps_group
;
3188 lu_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3190 if (!(lu_gp_cg
->default_groups
)) {
3191 printk(KERN_ERR
"Unable to allocate lu_gp_cg->default_groups\n");
3195 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
3196 &target_core_alua_lu_gp_cit
);
3197 lu_gp_cg
->default_groups
[0] = &lu_gp
->lu_gp_group
;
3198 lu_gp_cg
->default_groups
[1] = NULL
;
3199 default_lu_gp
= lu_gp
;
3201 * Register the target_core_mod subsystem with configfs.
3203 ret
= configfs_register_subsystem(subsys
);
3205 printk(KERN_ERR
"Error %d while registering subsystem %s\n",
3206 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
3209 printk(KERN_INFO
"TARGET_CORE[0]: Initialized ConfigFS Fabric"
3210 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION
" on %s/%s"
3211 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
3213 * Register built-in RAMDISK subsystem logic for virtual LUN 0
3215 ret
= rd_module_init();
3219 if (core_dev_setup_virtual_lun0() < 0)
3225 configfs_unregister_subsystem(subsys
);
3226 core_dev_release_virtual_lun0();
3229 if (default_lu_gp
) {
3230 core_alua_free_lu_gp(default_lu_gp
);
3231 default_lu_gp
= NULL
;
3234 kfree(lu_gp_cg
->default_groups
);
3236 kfree(alua_cg
->default_groups
);
3238 kfree(hba_cg
->default_groups
);
3239 kfree(target_cg
->default_groups
);
3240 release_se_kmem_caches();
3244 static void __exit
target_core_exit_configfs(void)
3246 struct configfs_subsystem
*subsys
;
3247 struct config_group
*hba_cg
, *alua_cg
, *lu_gp_cg
;
3248 struct config_item
*item
;
3251 subsys
= target_core_subsystem
[0];
3253 lu_gp_cg
= &alua_lu_gps_group
;
3254 for (i
= 0; lu_gp_cg
->default_groups
[i
]; i
++) {
3255 item
= &lu_gp_cg
->default_groups
[i
]->cg_item
;
3256 lu_gp_cg
->default_groups
[i
] = NULL
;
3257 config_item_put(item
);
3259 kfree(lu_gp_cg
->default_groups
);
3260 lu_gp_cg
->default_groups
= NULL
;
3262 alua_cg
= &alua_group
;
3263 for (i
= 0; alua_cg
->default_groups
[i
]; i
++) {
3264 item
= &alua_cg
->default_groups
[i
]->cg_item
;
3265 alua_cg
->default_groups
[i
] = NULL
;
3266 config_item_put(item
);
3268 kfree(alua_cg
->default_groups
);
3269 alua_cg
->default_groups
= NULL
;
3271 hba_cg
= &target_core_hbagroup
;
3272 for (i
= 0; hba_cg
->default_groups
[i
]; i
++) {
3273 item
= &hba_cg
->default_groups
[i
]->cg_item
;
3274 hba_cg
->default_groups
[i
] = NULL
;
3275 config_item_put(item
);
3277 kfree(hba_cg
->default_groups
);
3278 hba_cg
->default_groups
= NULL
;
3280 * We expect subsys->su_group.default_groups to be released
3281 * by configfs subsystem provider logic..
3283 configfs_unregister_subsystem(subsys
);
3284 kfree(subsys
->su_group
.default_groups
);
3286 core_alua_free_lu_gp(default_lu_gp
);
3287 default_lu_gp
= NULL
;
3289 printk(KERN_INFO
"TARGET_CORE[0]: Released ConfigFS Fabric"
3290 " Infrastructure\n");
3292 core_dev_release_virtual_lun0();
3294 release_se_kmem_caches();
3297 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3298 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3299 MODULE_LICENSE("GPL");
3301 module_init(target_core_init_configfs
);
3302 module_exit(target_core_exit_configfs
);