1 /*******************************************************************************
2 * Filename: target_core_configfs.c
4 * This file contains ConfigFS logic for the Generic Target Engine project.
6 * Copyright (c) 2008-2011 Rising Tide Systems
7 * Copyright (c) 2008-2011 Linux-iSCSI.org
9 * Nicholas A. Bellinger <nab@kernel.org>
11 * based on configfs Copyright (C) 2005 Oracle. All rights reserved.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 ****************************************************************************/
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <generated/utsrelease.h>
27 #include <linux/utsname.h>
28 #include <linux/init.h>
30 #include <linux/namei.h>
31 #include <linux/slab.h>
32 #include <linux/types.h>
33 #include <linux/delay.h>
34 #include <linux/unistd.h>
35 #include <linux/string.h>
36 #include <linux/parser.h>
37 #include <linux/syscalls.h>
38 #include <linux/configfs.h>
39 #include <linux/spinlock.h>
41 #include <target/target_core_base.h>
42 #include <target/target_core_device.h>
43 #include <target/target_core_transport.h>
44 #include <target/target_core_fabric_ops.h>
45 #include <target/target_core_fabric_configfs.h>
46 #include <target/target_core_configfs.h>
47 #include <target/configfs_macros.h>
49 #include "target_core_alua.h"
50 #include "target_core_hba.h"
51 #include "target_core_pr.h"
52 #include "target_core_rd.h"
53 #include "target_core_stat.h"
55 extern struct t10_alua_lu_gp
*default_lu_gp
;
57 static struct list_head g_tf_list
;
58 static struct mutex g_tf_lock
;
60 struct target_core_configfs_attribute
{
61 struct configfs_attribute attr
;
62 ssize_t (*show
)(void *, char *);
63 ssize_t (*store
)(void *, const char *, size_t);
66 static struct config_group target_core_hbagroup
;
67 static struct config_group alua_group
;
68 static struct config_group alua_lu_gps_group
;
70 static DEFINE_SPINLOCK(se_device_lock
);
71 static LIST_HEAD(se_dev_list
);
73 static inline struct se_hba
*
74 item_to_hba(struct config_item
*item
)
76 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
80 * Attributes for /sys/kernel/config/target/
82 static ssize_t
target_core_attr_show(struct config_item
*item
,
83 struct configfs_attribute
*attr
,
86 return sprintf(page
, "Target Engine Core ConfigFS Infrastructure %s"
87 " on %s/%s on "UTS_RELEASE
"\n", TARGET_CORE_CONFIGFS_VERSION
,
88 utsname()->sysname
, utsname()->machine
);
91 static struct configfs_item_operations target_core_fabric_item_ops
= {
92 .show_attribute
= target_core_attr_show
,
95 static struct configfs_attribute target_core_item_attr_version
= {
96 .ca_owner
= THIS_MODULE
,
101 static struct target_fabric_configfs
*target_core_get_fabric(
104 struct target_fabric_configfs
*tf
;
109 mutex_lock(&g_tf_lock
);
110 list_for_each_entry(tf
, &g_tf_list
, tf_list
) {
111 if (!strcmp(tf
->tf_name
, name
)) {
112 atomic_inc(&tf
->tf_access_cnt
);
113 mutex_unlock(&g_tf_lock
);
117 mutex_unlock(&g_tf_lock
);
123 * Called from struct target_core_group_ops->make_group()
125 static struct config_group
*target_core_register_fabric(
126 struct config_group
*group
,
129 struct target_fabric_configfs
*tf
;
132 pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:"
133 " %s\n", group
, name
);
135 * Below are some hardcoded request_module() calls to automatically
136 * local fabric modules when the following is called:
138 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
140 * Note that this does not limit which TCM fabric module can be
141 * registered, but simply provids auto loading logic for modules with
142 * mkdir(2) system calls with known TCM fabric modules.
144 if (!strncmp(name
, "iscsi", 5)) {
146 * Automatically load the LIO Target fabric module when the
147 * following is called:
149 * mkdir -p $CONFIGFS/target/iscsi
151 ret
= request_module("iscsi_target_mod");
153 pr_err("request_module() failed for"
154 " iscsi_target_mod.ko: %d\n", ret
);
155 return ERR_PTR(-EINVAL
);
157 } else if (!strncmp(name
, "loopback", 8)) {
159 * Automatically load the tcm_loop fabric module when the
160 * following is called:
162 * mkdir -p $CONFIGFS/target/loopback
164 ret
= request_module("tcm_loop");
166 pr_err("request_module() failed for"
167 " tcm_loop.ko: %d\n", ret
);
168 return ERR_PTR(-EINVAL
);
172 tf
= target_core_get_fabric(name
);
174 pr_err("target_core_get_fabric() failed for %s\n",
176 return ERR_PTR(-EINVAL
);
178 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
179 " %s\n", tf
->tf_name
);
181 * On a successful target_core_get_fabric() look, the returned
182 * struct target_fabric_configfs *tf will contain a usage reference.
184 pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
185 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
187 tf
->tf_group
.default_groups
= tf
->tf_default_groups
;
188 tf
->tf_group
.default_groups
[0] = &tf
->tf_disc_group
;
189 tf
->tf_group
.default_groups
[1] = NULL
;
191 config_group_init_type_name(&tf
->tf_group
, name
,
192 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
193 config_group_init_type_name(&tf
->tf_disc_group
, "discovery_auth",
194 &TF_CIT_TMPL(tf
)->tfc_discovery_cit
);
196 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
197 " %s\n", tf
->tf_group
.cg_item
.ci_name
);
199 * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item()
201 tf
->tf_ops
.tf_subsys
= tf
->tf_subsys
;
202 tf
->tf_fabric
= &tf
->tf_group
.cg_item
;
203 pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
206 return &tf
->tf_group
;
210 * Called from struct target_core_group_ops->drop_item()
212 static void target_core_deregister_fabric(
213 struct config_group
*group
,
214 struct config_item
*item
)
216 struct target_fabric_configfs
*tf
= container_of(
217 to_config_group(item
), struct target_fabric_configfs
, tf_group
);
218 struct config_group
*tf_group
;
219 struct config_item
*df_item
;
222 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
223 " tf list\n", config_item_name(item
));
225 pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:"
226 " %s\n", tf
->tf_name
);
227 atomic_dec(&tf
->tf_access_cnt
);
229 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing"
230 " tf->tf_fabric for %s\n", tf
->tf_name
);
231 tf
->tf_fabric
= NULL
;
233 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
234 " %s\n", config_item_name(item
));
236 tf_group
= &tf
->tf_group
;
237 for (i
= 0; tf_group
->default_groups
[i
]; i
++) {
238 df_item
= &tf_group
->default_groups
[i
]->cg_item
;
239 tf_group
->default_groups
[i
] = NULL
;
240 config_item_put(df_item
);
242 config_item_put(item
);
245 static struct configfs_group_operations target_core_fabric_group_ops
= {
246 .make_group
= &target_core_register_fabric
,
247 .drop_item
= &target_core_deregister_fabric
,
251 * All item attributes appearing in /sys/kernel/target/ appear here.
253 static struct configfs_attribute
*target_core_fabric_item_attrs
[] = {
254 &target_core_item_attr_version
,
259 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
261 static struct config_item_type target_core_fabrics_item
= {
262 .ct_item_ops
= &target_core_fabric_item_ops
,
263 .ct_group_ops
= &target_core_fabric_group_ops
,
264 .ct_attrs
= target_core_fabric_item_attrs
,
265 .ct_owner
= THIS_MODULE
,
268 static struct configfs_subsystem target_core_fabrics
= {
271 .ci_namebuf
= "target",
272 .ci_type
= &target_core_fabrics_item
,
277 static struct configfs_subsystem
*target_core_subsystem
[] = {
278 &target_core_fabrics
,
282 /*##############################################################################
283 // Start functions called by external Target Fabrics Modules
284 //############################################################################*/
287 * First function called by fabric modules to:
289 * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer.
290 * 2) Add struct target_fabric_configfs to g_tf_list
291 * 3) Return struct target_fabric_configfs to fabric module to be passed
292 * into target_fabric_configfs_register().
294 struct target_fabric_configfs
*target_fabric_configfs_init(
295 struct module
*fabric_mod
,
298 struct target_fabric_configfs
*tf
;
301 pr_err("Unable to locate passed fabric name\n");
302 return ERR_PTR(-EINVAL
);
304 if (strlen(name
) >= TARGET_FABRIC_NAME_SIZE
) {
305 pr_err("Passed name: %s exceeds TARGET_FABRIC"
306 "_NAME_SIZE\n", name
);
307 return ERR_PTR(-EINVAL
);
310 tf
= kzalloc(sizeof(struct target_fabric_configfs
), GFP_KERNEL
);
312 return ERR_PTR(-ENOMEM
);
314 INIT_LIST_HEAD(&tf
->tf_list
);
315 atomic_set(&tf
->tf_access_cnt
, 0);
317 * Setup the default generic struct config_item_type's (cits) in
318 * struct target_fabric_configfs->tf_cit_tmpl
320 tf
->tf_module
= fabric_mod
;
321 target_fabric_setup_cits(tf
);
323 tf
->tf_subsys
= target_core_subsystem
[0];
324 snprintf(tf
->tf_name
, TARGET_FABRIC_NAME_SIZE
, "%s", name
);
326 mutex_lock(&g_tf_lock
);
327 list_add_tail(&tf
->tf_list
, &g_tf_list
);
328 mutex_unlock(&g_tf_lock
);
330 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>"
332 pr_debug("Initialized struct target_fabric_configfs: %p for"
333 " %s\n", tf
, tf
->tf_name
);
336 EXPORT_SYMBOL(target_fabric_configfs_init
);
339 * Called by fabric plugins after FAILED target_fabric_configfs_register() call.
341 void target_fabric_configfs_free(
342 struct target_fabric_configfs
*tf
)
344 mutex_lock(&g_tf_lock
);
345 list_del(&tf
->tf_list
);
346 mutex_unlock(&g_tf_lock
);
350 EXPORT_SYMBOL(target_fabric_configfs_free
);
353 * Perform a sanity check of the passed tf->tf_ops before completing
354 * TCM fabric module registration.
356 static int target_fabric_tf_ops_check(
357 struct target_fabric_configfs
*tf
)
359 struct target_core_fabric_ops
*tfo
= &tf
->tf_ops
;
361 if (!tfo
->get_fabric_name
) {
362 pr_err("Missing tfo->get_fabric_name()\n");
365 if (!tfo
->get_fabric_proto_ident
) {
366 pr_err("Missing tfo->get_fabric_proto_ident()\n");
369 if (!tfo
->tpg_get_wwn
) {
370 pr_err("Missing tfo->tpg_get_wwn()\n");
373 if (!tfo
->tpg_get_tag
) {
374 pr_err("Missing tfo->tpg_get_tag()\n");
377 if (!tfo
->tpg_get_default_depth
) {
378 pr_err("Missing tfo->tpg_get_default_depth()\n");
381 if (!tfo
->tpg_get_pr_transport_id
) {
382 pr_err("Missing tfo->tpg_get_pr_transport_id()\n");
385 if (!tfo
->tpg_get_pr_transport_id_len
) {
386 pr_err("Missing tfo->tpg_get_pr_transport_id_len()\n");
389 if (!tfo
->tpg_check_demo_mode
) {
390 pr_err("Missing tfo->tpg_check_demo_mode()\n");
393 if (!tfo
->tpg_check_demo_mode_cache
) {
394 pr_err("Missing tfo->tpg_check_demo_mode_cache()\n");
397 if (!tfo
->tpg_check_demo_mode_write_protect
) {
398 pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n");
401 if (!tfo
->tpg_check_prod_mode_write_protect
) {
402 pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n");
405 if (!tfo
->tpg_alloc_fabric_acl
) {
406 pr_err("Missing tfo->tpg_alloc_fabric_acl()\n");
409 if (!tfo
->tpg_release_fabric_acl
) {
410 pr_err("Missing tfo->tpg_release_fabric_acl()\n");
413 if (!tfo
->tpg_get_inst_index
) {
414 pr_err("Missing tfo->tpg_get_inst_index()\n");
417 if (!tfo
->release_cmd
) {
418 pr_err("Missing tfo->release_cmd()\n");
421 if (!tfo
->shutdown_session
) {
422 pr_err("Missing tfo->shutdown_session()\n");
425 if (!tfo
->close_session
) {
426 pr_err("Missing tfo->close_session()\n");
429 if (!tfo
->stop_session
) {
430 pr_err("Missing tfo->stop_session()\n");
433 if (!tfo
->fall_back_to_erl0
) {
434 pr_err("Missing tfo->fall_back_to_erl0()\n");
437 if (!tfo
->sess_logged_in
) {
438 pr_err("Missing tfo->sess_logged_in()\n");
441 if (!tfo
->sess_get_index
) {
442 pr_err("Missing tfo->sess_get_index()\n");
445 if (!tfo
->write_pending
) {
446 pr_err("Missing tfo->write_pending()\n");
449 if (!tfo
->write_pending_status
) {
450 pr_err("Missing tfo->write_pending_status()\n");
453 if (!tfo
->set_default_node_attributes
) {
454 pr_err("Missing tfo->set_default_node_attributes()\n");
457 if (!tfo
->get_task_tag
) {
458 pr_err("Missing tfo->get_task_tag()\n");
461 if (!tfo
->get_cmd_state
) {
462 pr_err("Missing tfo->get_cmd_state()\n");
465 if (!tfo
->queue_data_in
) {
466 pr_err("Missing tfo->queue_data_in()\n");
469 if (!tfo
->queue_status
) {
470 pr_err("Missing tfo->queue_status()\n");
473 if (!tfo
->queue_tm_rsp
) {
474 pr_err("Missing tfo->queue_tm_rsp()\n");
477 if (!tfo
->set_fabric_sense_len
) {
478 pr_err("Missing tfo->set_fabric_sense_len()\n");
481 if (!tfo
->get_fabric_sense_len
) {
482 pr_err("Missing tfo->get_fabric_sense_len()\n");
485 if (!tfo
->is_state_remove
) {
486 pr_err("Missing tfo->is_state_remove()\n");
490 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
491 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
492 * target_core_fabric_configfs.c WWN+TPG group context code.
494 if (!tfo
->fabric_make_wwn
) {
495 pr_err("Missing tfo->fabric_make_wwn()\n");
498 if (!tfo
->fabric_drop_wwn
) {
499 pr_err("Missing tfo->fabric_drop_wwn()\n");
502 if (!tfo
->fabric_make_tpg
) {
503 pr_err("Missing tfo->fabric_make_tpg()\n");
506 if (!tfo
->fabric_drop_tpg
) {
507 pr_err("Missing tfo->fabric_drop_tpg()\n");
515 * Called 2nd from fabric module with returned parameter of
516 * struct target_fabric_configfs * from target_fabric_configfs_init().
518 * Upon a successful registration, the new fabric's struct config_item is
519 * return. Also, a pointer to this struct is set in the passed
520 * struct target_fabric_configfs.
522 int target_fabric_configfs_register(
523 struct target_fabric_configfs
*tf
)
528 pr_err("Unable to locate target_fabric_configfs"
532 if (!tf
->tf_subsys
) {
533 pr_err("Unable to target struct config_subsystem"
537 ret
= target_fabric_tf_ops_check(tf
);
541 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>"
545 EXPORT_SYMBOL(target_fabric_configfs_register
);
547 void target_fabric_configfs_deregister(
548 struct target_fabric_configfs
*tf
)
550 struct configfs_subsystem
*su
;
553 pr_err("Unable to locate passed target_fabric_"
559 pr_err("Unable to locate passed tf->tf_subsys"
563 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
565 mutex_lock(&g_tf_lock
);
566 if (atomic_read(&tf
->tf_access_cnt
)) {
567 mutex_unlock(&g_tf_lock
);
568 pr_err("Non zero tf->tf_access_cnt for fabric %s\n",
572 list_del(&tf
->tf_list
);
573 mutex_unlock(&g_tf_lock
);
575 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
576 " %s\n", tf
->tf_name
);
577 tf
->tf_module
= NULL
;
578 tf
->tf_subsys
= NULL
;
581 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
584 EXPORT_SYMBOL(target_fabric_configfs_deregister
);
586 /*##############################################################################
587 // Stop functions called by external Target Fabrics Modules
588 //############################################################################*/
590 /* Start functions for struct config_item_type target_core_dev_attrib_cit */
592 #define DEF_DEV_ATTRIB_SHOW(_name) \
593 static ssize_t target_core_dev_show_attr_##_name( \
594 struct se_dev_attrib *da, \
597 struct se_device *dev; \
598 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
601 spin_lock(&se_dev->se_dev_lock); \
602 dev = se_dev->se_dev_ptr; \
604 spin_unlock(&se_dev->se_dev_lock); \
607 rb = snprintf(page, PAGE_SIZE, "%u\n", \
608 (u32)dev->se_sub_dev->se_dev_attrib._name); \
609 spin_unlock(&se_dev->se_dev_lock); \
614 #define DEF_DEV_ATTRIB_STORE(_name) \
615 static ssize_t target_core_dev_store_attr_##_name( \
616 struct se_dev_attrib *da, \
620 struct se_device *dev; \
621 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
625 spin_lock(&se_dev->se_dev_lock); \
626 dev = se_dev->se_dev_ptr; \
628 spin_unlock(&se_dev->se_dev_lock); \
631 ret = strict_strtoul(page, 0, &val); \
633 spin_unlock(&se_dev->se_dev_lock); \
634 pr_err("strict_strtoul() failed with" \
635 " ret: %d\n", ret); \
638 ret = se_dev_set_##_name(dev, (u32)val); \
639 spin_unlock(&se_dev->se_dev_lock); \
641 return (!ret) ? count : -EINVAL; \
644 #define DEF_DEV_ATTRIB(_name) \
645 DEF_DEV_ATTRIB_SHOW(_name); \
646 DEF_DEV_ATTRIB_STORE(_name);
648 #define DEF_DEV_ATTRIB_RO(_name) \
649 DEF_DEV_ATTRIB_SHOW(_name);
651 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib
, se_dev_attrib
);
652 #define SE_DEV_ATTR(_name, _mode) \
653 static struct target_core_dev_attrib_attribute \
654 target_core_dev_attrib_##_name = \
655 __CONFIGFS_EATTR(_name, _mode, \
656 target_core_dev_show_attr_##_name, \
657 target_core_dev_store_attr_##_name);
659 #define SE_DEV_ATTR_RO(_name); \
660 static struct target_core_dev_attrib_attribute \
661 target_core_dev_attrib_##_name = \
662 __CONFIGFS_EATTR_RO(_name, \
663 target_core_dev_show_attr_##_name);
665 DEF_DEV_ATTRIB(emulate_dpo
);
666 SE_DEV_ATTR(emulate_dpo
, S_IRUGO
| S_IWUSR
);
668 DEF_DEV_ATTRIB(emulate_fua_write
);
669 SE_DEV_ATTR(emulate_fua_write
, S_IRUGO
| S_IWUSR
);
671 DEF_DEV_ATTRIB(emulate_fua_read
);
672 SE_DEV_ATTR(emulate_fua_read
, S_IRUGO
| S_IWUSR
);
674 DEF_DEV_ATTRIB(emulate_write_cache
);
675 SE_DEV_ATTR(emulate_write_cache
, S_IRUGO
| S_IWUSR
);
677 DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl
);
678 SE_DEV_ATTR(emulate_ua_intlck_ctrl
, S_IRUGO
| S_IWUSR
);
680 DEF_DEV_ATTRIB(emulate_tas
);
681 SE_DEV_ATTR(emulate_tas
, S_IRUGO
| S_IWUSR
);
683 DEF_DEV_ATTRIB(emulate_tpu
);
684 SE_DEV_ATTR(emulate_tpu
, S_IRUGO
| S_IWUSR
);
686 DEF_DEV_ATTRIB(emulate_tpws
);
687 SE_DEV_ATTR(emulate_tpws
, S_IRUGO
| S_IWUSR
);
689 DEF_DEV_ATTRIB(enforce_pr_isids
);
690 SE_DEV_ATTR(enforce_pr_isids
, S_IRUGO
| S_IWUSR
);
692 DEF_DEV_ATTRIB(is_nonrot
);
693 SE_DEV_ATTR(is_nonrot
, S_IRUGO
| S_IWUSR
);
695 DEF_DEV_ATTRIB(emulate_rest_reord
);
696 SE_DEV_ATTR(emulate_rest_reord
, S_IRUGO
| S_IWUSR
);
698 DEF_DEV_ATTRIB_RO(hw_block_size
);
699 SE_DEV_ATTR_RO(hw_block_size
);
701 DEF_DEV_ATTRIB(block_size
);
702 SE_DEV_ATTR(block_size
, S_IRUGO
| S_IWUSR
);
704 DEF_DEV_ATTRIB_RO(hw_max_sectors
);
705 SE_DEV_ATTR_RO(hw_max_sectors
);
707 DEF_DEV_ATTRIB(max_sectors
);
708 SE_DEV_ATTR(max_sectors
, S_IRUGO
| S_IWUSR
);
710 DEF_DEV_ATTRIB(optimal_sectors
);
711 SE_DEV_ATTR(optimal_sectors
, S_IRUGO
| S_IWUSR
);
713 DEF_DEV_ATTRIB_RO(hw_queue_depth
);
714 SE_DEV_ATTR_RO(hw_queue_depth
);
716 DEF_DEV_ATTRIB(queue_depth
);
717 SE_DEV_ATTR(queue_depth
, S_IRUGO
| S_IWUSR
);
719 DEF_DEV_ATTRIB(max_unmap_lba_count
);
720 SE_DEV_ATTR(max_unmap_lba_count
, S_IRUGO
| S_IWUSR
);
722 DEF_DEV_ATTRIB(max_unmap_block_desc_count
);
723 SE_DEV_ATTR(max_unmap_block_desc_count
, S_IRUGO
| S_IWUSR
);
725 DEF_DEV_ATTRIB(unmap_granularity
);
726 SE_DEV_ATTR(unmap_granularity
, S_IRUGO
| S_IWUSR
);
728 DEF_DEV_ATTRIB(unmap_granularity_alignment
);
729 SE_DEV_ATTR(unmap_granularity_alignment
, S_IRUGO
| S_IWUSR
);
731 CONFIGFS_EATTR_OPS(target_core_dev_attrib
, se_dev_attrib
, da_group
);
733 static struct configfs_attribute
*target_core_dev_attrib_attrs
[] = {
734 &target_core_dev_attrib_emulate_dpo
.attr
,
735 &target_core_dev_attrib_emulate_fua_write
.attr
,
736 &target_core_dev_attrib_emulate_fua_read
.attr
,
737 &target_core_dev_attrib_emulate_write_cache
.attr
,
738 &target_core_dev_attrib_emulate_ua_intlck_ctrl
.attr
,
739 &target_core_dev_attrib_emulate_tas
.attr
,
740 &target_core_dev_attrib_emulate_tpu
.attr
,
741 &target_core_dev_attrib_emulate_tpws
.attr
,
742 &target_core_dev_attrib_enforce_pr_isids
.attr
,
743 &target_core_dev_attrib_is_nonrot
.attr
,
744 &target_core_dev_attrib_emulate_rest_reord
.attr
,
745 &target_core_dev_attrib_hw_block_size
.attr
,
746 &target_core_dev_attrib_block_size
.attr
,
747 &target_core_dev_attrib_hw_max_sectors
.attr
,
748 &target_core_dev_attrib_max_sectors
.attr
,
749 &target_core_dev_attrib_optimal_sectors
.attr
,
750 &target_core_dev_attrib_hw_queue_depth
.attr
,
751 &target_core_dev_attrib_queue_depth
.attr
,
752 &target_core_dev_attrib_max_unmap_lba_count
.attr
,
753 &target_core_dev_attrib_max_unmap_block_desc_count
.attr
,
754 &target_core_dev_attrib_unmap_granularity
.attr
,
755 &target_core_dev_attrib_unmap_granularity_alignment
.attr
,
759 static struct configfs_item_operations target_core_dev_attrib_ops
= {
760 .show_attribute
= target_core_dev_attrib_attr_show
,
761 .store_attribute
= target_core_dev_attrib_attr_store
,
764 static struct config_item_type target_core_dev_attrib_cit
= {
765 .ct_item_ops
= &target_core_dev_attrib_ops
,
766 .ct_attrs
= target_core_dev_attrib_attrs
,
767 .ct_owner
= THIS_MODULE
,
770 /* End functions for struct config_item_type target_core_dev_attrib_cit */
772 /* Start functions for struct config_item_type target_core_dev_wwn_cit */
774 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn
, t10_wwn
);
775 #define SE_DEV_WWN_ATTR(_name, _mode) \
776 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
777 __CONFIGFS_EATTR(_name, _mode, \
778 target_core_dev_wwn_show_attr_##_name, \
779 target_core_dev_wwn_store_attr_##_name);
781 #define SE_DEV_WWN_ATTR_RO(_name); \
783 static struct target_core_dev_wwn_attribute \
784 target_core_dev_wwn_##_name = \
785 __CONFIGFS_EATTR_RO(_name, \
786 target_core_dev_wwn_show_attr_##_name); \
790 * VPD page 0x80 Unit serial
792 static ssize_t
target_core_dev_wwn_show_attr_vpd_unit_serial(
793 struct t10_wwn
*t10_wwn
,
796 struct se_subsystem_dev
*se_dev
= t10_wwn
->t10_sub_dev
;
797 struct se_device
*dev
;
799 dev
= se_dev
->se_dev_ptr
;
803 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
804 &t10_wwn
->unit_serial
[0]);
807 static ssize_t
target_core_dev_wwn_store_attr_vpd_unit_serial(
808 struct t10_wwn
*t10_wwn
,
812 struct se_subsystem_dev
*su_dev
= t10_wwn
->t10_sub_dev
;
813 struct se_device
*dev
;
814 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
817 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
818 * from the struct scsi_device level firmware, do not allow
819 * VPD Unit Serial to be emulated.
821 * Note this struct scsi_device could also be emulating VPD
822 * information from its drivers/scsi LLD. But for now we assume
823 * it is doing 'the right thing' wrt a world wide unique
824 * VPD Unit Serial Number that OS dependent multipath can depend on.
826 if (su_dev
->su_dev_flags
& SDF_FIRMWARE_VPD_UNIT_SERIAL
) {
827 pr_err("Underlying SCSI device firmware provided VPD"
828 " Unit Serial, ignoring request\n");
832 if (strlen(page
) >= INQUIRY_VPD_SERIAL_LEN
) {
833 pr_err("Emulated VPD Unit Serial exceeds"
834 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
838 * Check to see if any active $FABRIC_MOD exports exist. If they
839 * do exist, fail here as changing this information on the fly
840 * (underneath the initiator side OS dependent multipath code)
841 * could cause negative effects.
843 dev
= su_dev
->se_dev_ptr
;
845 if (atomic_read(&dev
->dev_export_obj
.obj_access_count
)) {
846 pr_err("Unable to set VPD Unit Serial while"
847 " active %d $FABRIC_MOD exports exist\n",
848 atomic_read(&dev
->dev_export_obj
.obj_access_count
));
853 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
855 * Also, strip any newline added from the userspace
856 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
858 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
859 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
860 snprintf(su_dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
861 "%s", strstrip(buf
));
862 su_dev
->su_dev_flags
|= SDF_EMULATED_VPD_UNIT_SERIAL
;
864 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
865 " %s\n", su_dev
->t10_wwn
.unit_serial
);
870 SE_DEV_WWN_ATTR(vpd_unit_serial
, S_IRUGO
| S_IWUSR
);
873 * VPD page 0x83 Protocol Identifier
875 static ssize_t
target_core_dev_wwn_show_attr_vpd_protocol_identifier(
876 struct t10_wwn
*t10_wwn
,
879 struct se_subsystem_dev
*se_dev
= t10_wwn
->t10_sub_dev
;
880 struct se_device
*dev
;
882 unsigned char buf
[VPD_TMP_BUF_SIZE
];
885 dev
= se_dev
->se_dev_ptr
;
889 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
891 spin_lock(&t10_wwn
->t10_vpd_lock
);
892 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
893 if (!vpd
->protocol_identifier_set
)
896 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
898 if (len
+ strlen(buf
) >= PAGE_SIZE
)
901 len
+= sprintf(page
+len
, "%s", buf
);
903 spin_unlock(&t10_wwn
->t10_vpd_lock
);
908 static ssize_t
target_core_dev_wwn_store_attr_vpd_protocol_identifier(
909 struct t10_wwn
*t10_wwn
,
916 SE_DEV_WWN_ATTR(vpd_protocol_identifier
, S_IRUGO
| S_IWUSR
);
919 * Generic wrapper for dumping VPD identifiers by association.
921 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
922 static ssize_t target_core_dev_wwn_show_attr_##_name( \
923 struct t10_wwn *t10_wwn, \
926 struct se_subsystem_dev *se_dev = t10_wwn->t10_sub_dev; \
927 struct se_device *dev; \
928 struct t10_vpd *vpd; \
929 unsigned char buf[VPD_TMP_BUF_SIZE]; \
932 dev = se_dev->se_dev_ptr; \
936 spin_lock(&t10_wwn->t10_vpd_lock); \
937 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
938 if (vpd->association != _assoc) \
941 memset(buf, 0, VPD_TMP_BUF_SIZE); \
942 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
943 if (len + strlen(buf) >= PAGE_SIZE) \
945 len += sprintf(page+len, "%s", buf); \
947 memset(buf, 0, VPD_TMP_BUF_SIZE); \
948 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
949 if (len + strlen(buf) >= PAGE_SIZE) \
951 len += sprintf(page+len, "%s", buf); \
953 memset(buf, 0, VPD_TMP_BUF_SIZE); \
954 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
955 if (len + strlen(buf) >= PAGE_SIZE) \
957 len += sprintf(page+len, "%s", buf); \
959 spin_unlock(&t10_wwn->t10_vpd_lock); \
965 * VPD page 0x83 Association: Logical Unit
967 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
969 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
970 struct t10_wwn
*t10_wwn
,
977 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit
, S_IRUGO
| S_IWUSR
);
980 * VPD page 0x83 Association: Target Port
982 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
984 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_target_port(
985 struct t10_wwn
*t10_wwn
,
992 SE_DEV_WWN_ATTR(vpd_assoc_target_port
, S_IRUGO
| S_IWUSR
);
995 * VPD page 0x83 Association: SCSI Target Device
997 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
999 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
1000 struct t10_wwn
*t10_wwn
,
1007 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device
, S_IRUGO
| S_IWUSR
);
1009 CONFIGFS_EATTR_OPS(target_core_dev_wwn
, t10_wwn
, t10_wwn_group
);
1011 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
1012 &target_core_dev_wwn_vpd_unit_serial
.attr
,
1013 &target_core_dev_wwn_vpd_protocol_identifier
.attr
,
1014 &target_core_dev_wwn_vpd_assoc_logical_unit
.attr
,
1015 &target_core_dev_wwn_vpd_assoc_target_port
.attr
,
1016 &target_core_dev_wwn_vpd_assoc_scsi_target_device
.attr
,
1020 static struct configfs_item_operations target_core_dev_wwn_ops
= {
1021 .show_attribute
= target_core_dev_wwn_attr_show
,
1022 .store_attribute
= target_core_dev_wwn_attr_store
,
1025 static struct config_item_type target_core_dev_wwn_cit
= {
1026 .ct_item_ops
= &target_core_dev_wwn_ops
,
1027 .ct_attrs
= target_core_dev_wwn_attrs
,
1028 .ct_owner
= THIS_MODULE
,
1031 /* End functions for struct config_item_type target_core_dev_wwn_cit */
1033 /* Start functions for struct config_item_type target_core_dev_pr_cit */
1035 CONFIGFS_EATTR_STRUCT(target_core_dev_pr
, se_subsystem_dev
);
1036 #define SE_DEV_PR_ATTR(_name, _mode) \
1037 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1038 __CONFIGFS_EATTR(_name, _mode, \
1039 target_core_dev_pr_show_attr_##_name, \
1040 target_core_dev_pr_store_attr_##_name);
1042 #define SE_DEV_PR_ATTR_RO(_name); \
1043 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1044 __CONFIGFS_EATTR_RO(_name, \
1045 target_core_dev_pr_show_attr_##_name);
1050 static ssize_t
target_core_dev_pr_show_spc3_res(
1051 struct se_device
*dev
,
1055 struct se_node_acl
*se_nacl
;
1056 struct t10_pr_registration
*pr_reg
;
1057 char i_buf
[PR_REG_ISID_ID_LEN
];
1060 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1062 spin_lock(&dev
->dev_reservation_lock
);
1063 pr_reg
= dev
->dev_pr_res_holder
;
1065 *len
+= sprintf(page
+ *len
, "No SPC-3 Reservation holder\n");
1066 spin_unlock(&dev
->dev_reservation_lock
);
1069 se_nacl
= pr_reg
->pr_reg_nacl
;
1070 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1071 PR_REG_ISID_ID_LEN
);
1073 *len
+= sprintf(page
+ *len
, "SPC-3 Reservation: %s Initiator: %s%s\n",
1074 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1075 se_nacl
->initiatorname
, (prf_isid
) ? &i_buf
[0] : "");
1076 spin_unlock(&dev
->dev_reservation_lock
);
1081 static ssize_t
target_core_dev_pr_show_spc2_res(
1082 struct se_device
*dev
,
1086 struct se_node_acl
*se_nacl
;
1088 spin_lock(&dev
->dev_reservation_lock
);
1089 se_nacl
= dev
->dev_reserved_node_acl
;
1091 *len
+= sprintf(page
+ *len
, "No SPC-2 Reservation holder\n");
1092 spin_unlock(&dev
->dev_reservation_lock
);
1095 *len
+= sprintf(page
+ *len
, "SPC-2 Reservation: %s Initiator: %s\n",
1096 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1097 se_nacl
->initiatorname
);
1098 spin_unlock(&dev
->dev_reservation_lock
);
1103 static ssize_t
target_core_dev_pr_show_attr_res_holder(
1104 struct se_subsystem_dev
*su_dev
,
1109 if (!su_dev
->se_dev_ptr
)
1112 switch (su_dev
->t10_pr
.res_type
) {
1113 case SPC3_PERSISTENT_RESERVATIONS
:
1114 target_core_dev_pr_show_spc3_res(su_dev
->se_dev_ptr
,
1117 case SPC2_RESERVATIONS
:
1118 target_core_dev_pr_show_spc2_res(su_dev
->se_dev_ptr
,
1121 case SPC_PASSTHROUGH
:
1122 len
+= sprintf(page
+len
, "Passthrough\n");
1125 len
+= sprintf(page
+len
, "Unknown\n");
1132 SE_DEV_PR_ATTR_RO(res_holder
);
1135 * res_pr_all_tgt_pts
1137 static ssize_t
target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1138 struct se_subsystem_dev
*su_dev
,
1141 struct se_device
*dev
;
1142 struct t10_pr_registration
*pr_reg
;
1145 dev
= su_dev
->se_dev_ptr
;
1149 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1152 spin_lock(&dev
->dev_reservation_lock
);
1153 pr_reg
= dev
->dev_pr_res_holder
;
1155 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1156 spin_unlock(&dev
->dev_reservation_lock
);
1160 * See All Target Ports (ALL_TG_PT) bit in spcr17, section 6.14.3
1161 * Basic PERSISTENT RESERVER OUT parameter list, page 290
1163 if (pr_reg
->pr_reg_all_tg_pt
)
1164 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1165 " Ports registration\n");
1167 len
= sprintf(page
, "SPC-3 Reservation: Single"
1168 " Target Port registration\n");
1169 spin_unlock(&dev
->dev_reservation_lock
);
1174 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts
);
1179 static ssize_t
target_core_dev_pr_show_attr_res_pr_generation(
1180 struct se_subsystem_dev
*su_dev
,
1183 if (!su_dev
->se_dev_ptr
)
1186 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1189 return sprintf(page
, "0x%08x\n", su_dev
->t10_pr
.pr_generation
);
1192 SE_DEV_PR_ATTR_RO(res_pr_generation
);
1195 * res_pr_holder_tg_port
1197 static ssize_t
target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1198 struct se_subsystem_dev
*su_dev
,
1201 struct se_device
*dev
;
1202 struct se_node_acl
*se_nacl
;
1204 struct se_portal_group
*se_tpg
;
1205 struct t10_pr_registration
*pr_reg
;
1206 struct target_core_fabric_ops
*tfo
;
1209 dev
= su_dev
->se_dev_ptr
;
1213 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1216 spin_lock(&dev
->dev_reservation_lock
);
1217 pr_reg
= dev
->dev_pr_res_holder
;
1219 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1220 spin_unlock(&dev
->dev_reservation_lock
);
1223 se_nacl
= pr_reg
->pr_reg_nacl
;
1224 se_tpg
= se_nacl
->se_tpg
;
1225 lun
= pr_reg
->pr_reg_tg_pt_lun
;
1226 tfo
= se_tpg
->se_tpg_tfo
;
1228 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1229 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1230 tfo
->tpg_get_wwn(se_tpg
));
1231 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1232 " Identifer Tag: %hu %s Portal Group Tag: %hu"
1233 " %s Logical Unit: %u\n", lun
->lun_sep
->sep_rtpi
,
1234 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1235 tfo
->get_fabric_name(), lun
->unpacked_lun
);
1236 spin_unlock(&dev
->dev_reservation_lock
);
1241 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port
);
1244 * res_pr_registered_i_pts
1246 static ssize_t
target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1247 struct se_subsystem_dev
*su_dev
,
1250 struct target_core_fabric_ops
*tfo
;
1251 struct t10_pr_registration
*pr_reg
;
1252 unsigned char buf
[384];
1253 char i_buf
[PR_REG_ISID_ID_LEN
];
1255 int reg_count
= 0, prf_isid
;
1257 if (!su_dev
->se_dev_ptr
)
1260 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1263 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1265 spin_lock(&su_dev
->t10_pr
.registration_lock
);
1266 list_for_each_entry(pr_reg
, &su_dev
->t10_pr
.registration_list
,
1269 memset(buf
, 0, 384);
1270 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1271 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1272 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1273 PR_REG_ISID_ID_LEN
);
1274 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1275 tfo
->get_fabric_name(),
1276 pr_reg
->pr_reg_nacl
->initiatorname
, (prf_isid
) ?
1277 &i_buf
[0] : "", pr_reg
->pr_res_key
,
1278 pr_reg
->pr_res_generation
);
1280 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1283 len
+= sprintf(page
+len
, "%s", buf
);
1286 spin_unlock(&su_dev
->t10_pr
.registration_lock
);
1289 len
+= sprintf(page
+len
, "None\n");
1294 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts
);
1299 static ssize_t
target_core_dev_pr_show_attr_res_pr_type(
1300 struct se_subsystem_dev
*su_dev
,
1303 struct se_device
*dev
;
1304 struct t10_pr_registration
*pr_reg
;
1307 dev
= su_dev
->se_dev_ptr
;
1311 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1314 spin_lock(&dev
->dev_reservation_lock
);
1315 pr_reg
= dev
->dev_pr_res_holder
;
1317 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1318 spin_unlock(&dev
->dev_reservation_lock
);
1321 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1322 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1323 spin_unlock(&dev
->dev_reservation_lock
);
1328 SE_DEV_PR_ATTR_RO(res_pr_type
);
1333 static ssize_t
target_core_dev_pr_show_attr_res_type(
1334 struct se_subsystem_dev
*su_dev
,
1339 if (!su_dev
->se_dev_ptr
)
1342 switch (su_dev
->t10_pr
.res_type
) {
1343 case SPC3_PERSISTENT_RESERVATIONS
:
1344 len
= sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1346 case SPC2_RESERVATIONS
:
1347 len
= sprintf(page
, "SPC2_RESERVATIONS\n");
1349 case SPC_PASSTHROUGH
:
1350 len
= sprintf(page
, "SPC_PASSTHROUGH\n");
1353 len
= sprintf(page
, "UNKNOWN\n");
1360 SE_DEV_PR_ATTR_RO(res_type
);
1366 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_active(
1367 struct se_subsystem_dev
*su_dev
,
1370 if (!su_dev
->se_dev_ptr
)
1373 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1376 return sprintf(page
, "APTPL Bit Status: %s\n",
1377 (su_dev
->t10_pr
.pr_aptpl_active
) ? "Activated" : "Disabled");
1380 SE_DEV_PR_ATTR_RO(res_aptpl_active
);
1383 * res_aptpl_metadata
1385 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_metadata(
1386 struct se_subsystem_dev
*su_dev
,
1389 if (!su_dev
->se_dev_ptr
)
1392 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1395 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1399 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1400 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1401 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1402 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1405 static match_table_t tokens
= {
1406 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1407 {Opt_initiator_node
, "initiator_node=%s"},
1408 {Opt_initiator_sid
, "initiator_sid=%s"},
1409 {Opt_sa_res_key
, "sa_res_key=%s"},
1410 {Opt_res_holder
, "res_holder=%d"},
1411 {Opt_res_type
, "res_type=%d"},
1412 {Opt_res_scope
, "res_scope=%d"},
1413 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1414 {Opt_mapped_lun
, "mapped_lun=%d"},
1415 {Opt_target_fabric
, "target_fabric=%s"},
1416 {Opt_target_node
, "target_node=%s"},
1417 {Opt_tpgt
, "tpgt=%d"},
1418 {Opt_port_rtpi
, "port_rtpi=%d"},
1419 {Opt_target_lun
, "target_lun=%d"},
1423 static ssize_t
target_core_dev_pr_store_attr_res_aptpl_metadata(
1424 struct se_subsystem_dev
*su_dev
,
1428 struct se_device
*dev
;
1429 unsigned char *i_fabric
= NULL
, *i_port
= NULL
, *isid
= NULL
;
1430 unsigned char *t_fabric
= NULL
, *t_port
= NULL
;
1431 char *orig
, *ptr
, *arg_p
, *opts
;
1432 substring_t args
[MAX_OPT_ARGS
];
1433 unsigned long long tmp_ll
;
1435 u32 mapped_lun
= 0, target_lun
= 0;
1436 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1437 u16 port_rpti
= 0, tpgt
= 0;
1440 dev
= su_dev
->se_dev_ptr
;
1444 if (su_dev
->t10_pr
.res_type
!= SPC3_PERSISTENT_RESERVATIONS
)
1447 if (atomic_read(&dev
->dev_export_obj
.obj_access_count
)) {
1448 pr_debug("Unable to process APTPL metadata while"
1449 " active fabric exports exist\n");
1453 opts
= kstrdup(page
, GFP_KERNEL
);
1458 while ((ptr
= strsep(&opts
, ",")) != NULL
) {
1462 token
= match_token(ptr
, tokens
, args
);
1464 case Opt_initiator_fabric
:
1465 i_fabric
= match_strdup(&args
[0]);
1471 case Opt_initiator_node
:
1472 i_port
= match_strdup(&args
[0]);
1477 if (strlen(i_port
) >= PR_APTPL_MAX_IPORT_LEN
) {
1478 pr_err("APTPL metadata initiator_node="
1479 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1480 PR_APTPL_MAX_IPORT_LEN
);
1485 case Opt_initiator_sid
:
1486 isid
= match_strdup(&args
[0]);
1491 if (strlen(isid
) >= PR_REG_ISID_LEN
) {
1492 pr_err("APTPL metadata initiator_isid"
1493 "= exceeds PR_REG_ISID_LEN: %d\n",
1499 case Opt_sa_res_key
:
1500 arg_p
= match_strdup(&args
[0]);
1505 ret
= strict_strtoull(arg_p
, 0, &tmp_ll
);
1507 pr_err("strict_strtoull() failed for"
1511 sa_res_key
= (u64
)tmp_ll
;
1514 * PR APTPL Metadata for Reservation
1516 case Opt_res_holder
:
1517 match_int(args
, &arg
);
1521 match_int(args
, &arg
);
1525 match_int(args
, &arg
);
1528 case Opt_res_all_tg_pt
:
1529 match_int(args
, &arg
);
1530 all_tg_pt
= (int)arg
;
1532 case Opt_mapped_lun
:
1533 match_int(args
, &arg
);
1534 mapped_lun
= (u32
)arg
;
1537 * PR APTPL Metadata for Target Port
1539 case Opt_target_fabric
:
1540 t_fabric
= match_strdup(&args
[0]);
1546 case Opt_target_node
:
1547 t_port
= match_strdup(&args
[0]);
1552 if (strlen(t_port
) >= PR_APTPL_MAX_TPORT_LEN
) {
1553 pr_err("APTPL metadata target_node="
1554 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1555 PR_APTPL_MAX_TPORT_LEN
);
1561 match_int(args
, &arg
);
1565 match_int(args
, &arg
);
1566 port_rpti
= (u16
)arg
;
1568 case Opt_target_lun
:
1569 match_int(args
, &arg
);
1570 target_lun
= (u32
)arg
;
1577 if (!i_port
|| !t_port
|| !sa_res_key
) {
1578 pr_err("Illegal parameters for APTPL registration\n");
1583 if (res_holder
&& !(type
)) {
1584 pr_err("Illegal PR type: 0x%02x for reservation"
1590 ret
= core_scsi3_alloc_aptpl_registration(&su_dev
->t10_pr
, sa_res_key
,
1591 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1592 res_holder
, all_tg_pt
, type
);
1600 return (ret
== 0) ? count
: ret
;
1603 SE_DEV_PR_ATTR(res_aptpl_metadata
, S_IRUGO
| S_IWUSR
);
1605 CONFIGFS_EATTR_OPS(target_core_dev_pr
, se_subsystem_dev
, se_dev_pr_group
);
1607 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1608 &target_core_dev_pr_res_holder
.attr
,
1609 &target_core_dev_pr_res_pr_all_tgt_pts
.attr
,
1610 &target_core_dev_pr_res_pr_generation
.attr
,
1611 &target_core_dev_pr_res_pr_holder_tg_port
.attr
,
1612 &target_core_dev_pr_res_pr_registered_i_pts
.attr
,
1613 &target_core_dev_pr_res_pr_type
.attr
,
1614 &target_core_dev_pr_res_type
.attr
,
1615 &target_core_dev_pr_res_aptpl_active
.attr
,
1616 &target_core_dev_pr_res_aptpl_metadata
.attr
,
1620 static struct configfs_item_operations target_core_dev_pr_ops
= {
1621 .show_attribute
= target_core_dev_pr_attr_show
,
1622 .store_attribute
= target_core_dev_pr_attr_store
,
1625 static struct config_item_type target_core_dev_pr_cit
= {
1626 .ct_item_ops
= &target_core_dev_pr_ops
,
1627 .ct_attrs
= target_core_dev_pr_attrs
,
1628 .ct_owner
= THIS_MODULE
,
1631 /* End functions for struct config_item_type target_core_dev_pr_cit */
1633 /* Start functions for struct config_item_type target_core_dev_cit */
1635 static ssize_t
target_core_show_dev_info(void *p
, char *page
)
1637 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1638 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1639 struct se_subsystem_api
*t
= hba
->transport
;
1641 ssize_t read_bytes
= 0;
1643 if (!se_dev
->se_dev_ptr
)
1646 transport_dump_dev_state(se_dev
->se_dev_ptr
, page
, &bl
);
1648 read_bytes
+= t
->show_configfs_dev_params(hba
, se_dev
, page
+read_bytes
);
1652 static struct target_core_configfs_attribute target_core_attr_dev_info
= {
1653 .attr
= { .ca_owner
= THIS_MODULE
,
1655 .ca_mode
= S_IRUGO
},
1656 .show
= target_core_show_dev_info
,
1660 static ssize_t
target_core_store_dev_control(
1665 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1666 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1667 struct se_subsystem_api
*t
= hba
->transport
;
1669 if (!se_dev
->se_dev_su_ptr
) {
1670 pr_err("Unable to locate struct se_subsystem_dev>se"
1675 return t
->set_configfs_dev_params(hba
, se_dev
, page
, count
);
1678 static struct target_core_configfs_attribute target_core_attr_dev_control
= {
1679 .attr
= { .ca_owner
= THIS_MODULE
,
1680 .ca_name
= "control",
1681 .ca_mode
= S_IWUSR
},
1683 .store
= target_core_store_dev_control
,
1686 static ssize_t
target_core_show_dev_alias(void *p
, char *page
)
1688 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1690 if (!(se_dev
->su_dev_flags
& SDF_USING_ALIAS
))
1693 return snprintf(page
, PAGE_SIZE
, "%s\n", se_dev
->se_dev_alias
);
1696 static ssize_t
target_core_store_dev_alias(
1701 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1702 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1705 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1706 pr_err("alias count: %d exceeds"
1707 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1708 SE_DEV_ALIAS_LEN
-1);
1712 se_dev
->su_dev_flags
|= SDF_USING_ALIAS
;
1713 read_bytes
= snprintf(&se_dev
->se_dev_alias
[0], SE_DEV_ALIAS_LEN
,
1716 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
1717 config_item_name(&hba
->hba_group
.cg_item
),
1718 config_item_name(&se_dev
->se_dev_group
.cg_item
),
1719 se_dev
->se_dev_alias
);
1724 static struct target_core_configfs_attribute target_core_attr_dev_alias
= {
1725 .attr
= { .ca_owner
= THIS_MODULE
,
1727 .ca_mode
= S_IRUGO
| S_IWUSR
},
1728 .show
= target_core_show_dev_alias
,
1729 .store
= target_core_store_dev_alias
,
1732 static ssize_t
target_core_show_dev_udev_path(void *p
, char *page
)
1734 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1736 if (!(se_dev
->su_dev_flags
& SDF_USING_UDEV_PATH
))
1739 return snprintf(page
, PAGE_SIZE
, "%s\n", se_dev
->se_dev_udev_path
);
1742 static ssize_t
target_core_store_dev_udev_path(
1747 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1748 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1751 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1752 pr_err("udev_path count: %d exceeds"
1753 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1754 SE_UDEV_PATH_LEN
-1);
1758 se_dev
->su_dev_flags
|= SDF_USING_UDEV_PATH
;
1759 read_bytes
= snprintf(&se_dev
->se_dev_udev_path
[0], SE_UDEV_PATH_LEN
,
1762 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1763 config_item_name(&hba
->hba_group
.cg_item
),
1764 config_item_name(&se_dev
->se_dev_group
.cg_item
),
1765 se_dev
->se_dev_udev_path
);
1770 static struct target_core_configfs_attribute target_core_attr_dev_udev_path
= {
1771 .attr
= { .ca_owner
= THIS_MODULE
,
1772 .ca_name
= "udev_path",
1773 .ca_mode
= S_IRUGO
| S_IWUSR
},
1774 .show
= target_core_show_dev_udev_path
,
1775 .store
= target_core_store_dev_udev_path
,
1778 static ssize_t
target_core_store_dev_enable(
1783 struct se_subsystem_dev
*se_dev
= (struct se_subsystem_dev
*)p
;
1784 struct se_device
*dev
;
1785 struct se_hba
*hba
= se_dev
->se_dev_hba
;
1786 struct se_subsystem_api
*t
= hba
->transport
;
1789 ptr
= strstr(page
, "1");
1791 pr_err("For dev_enable ops, only valid value"
1795 if (se_dev
->se_dev_ptr
) {
1796 pr_err("se_dev->se_dev_ptr already set for storage"
1801 if (t
->check_configfs_dev_params(hba
, se_dev
) < 0)
1804 dev
= t
->create_virtdevice(hba
, se_dev
, se_dev
->se_dev_su_ptr
);
1806 return PTR_ERR(dev
);
1810 se_dev
->se_dev_ptr
= dev
;
1811 pr_debug("Target_Core_ConfigFS: Registered se_dev->se_dev_ptr:"
1812 " %p\n", se_dev
->se_dev_ptr
);
1817 static struct target_core_configfs_attribute target_core_attr_dev_enable
= {
1818 .attr
= { .ca_owner
= THIS_MODULE
,
1819 .ca_name
= "enable",
1820 .ca_mode
= S_IWUSR
},
1822 .store
= target_core_store_dev_enable
,
1825 static ssize_t
target_core_show_alua_lu_gp(void *p
, char *page
)
1827 struct se_device
*dev
;
1828 struct se_subsystem_dev
*su_dev
= (struct se_subsystem_dev
*)p
;
1829 struct config_item
*lu_ci
;
1830 struct t10_alua_lu_gp
*lu_gp
;
1831 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1834 dev
= su_dev
->se_dev_ptr
;
1838 if (su_dev
->t10_alua
.alua_type
!= SPC3_ALUA_EMULATED
)
1841 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1843 pr_err("NULL struct se_device->dev_alua_lu_gp_mem"
1848 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1849 lu_gp
= lu_gp_mem
->lu_gp
;
1851 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1852 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1853 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1855 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1860 static ssize_t
target_core_store_alua_lu_gp(
1865 struct se_device
*dev
;
1866 struct se_subsystem_dev
*su_dev
= (struct se_subsystem_dev
*)p
;
1867 struct se_hba
*hba
= su_dev
->se_dev_hba
;
1868 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1869 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1870 unsigned char buf
[LU_GROUP_NAME_BUF
];
1873 dev
= su_dev
->se_dev_ptr
;
1877 if (su_dev
->t10_alua
.alua_type
!= SPC3_ALUA_EMULATED
) {
1878 pr_warn("SPC3_ALUA_EMULATED not enabled for %s/%s\n",
1879 config_item_name(&hba
->hba_group
.cg_item
),
1880 config_item_name(&su_dev
->se_dev_group
.cg_item
));
1883 if (count
> LU_GROUP_NAME_BUF
) {
1884 pr_err("ALUA LU Group Alias too large!\n");
1887 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1888 memcpy(buf
, page
, count
);
1890 * Any ALUA logical unit alias besides "NULL" means we will be
1891 * making a new group association.
1893 if (strcmp(strstrip(buf
), "NULL")) {
1895 * core_alua_get_lu_gp_by_name() will increment reference to
1896 * struct t10_alua_lu_gp. This reference is released with
1897 * core_alua_get_lu_gp_by_name below().
1899 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
1903 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1906 core_alua_put_lu_gp_from_name(lu_gp_new
);
1907 pr_err("NULL struct se_device->dev_alua_lu_gp_mem"
1912 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1913 lu_gp
= lu_gp_mem
->lu_gp
;
1916 * Clearing an existing lu_gp association, and replacing
1920 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
1921 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1923 config_item_name(&hba
->hba_group
.cg_item
),
1924 config_item_name(&su_dev
->se_dev_group
.cg_item
),
1925 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1928 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1929 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1934 * Removing existing association of lu_gp_mem with lu_gp
1936 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1940 * Associate lu_gp_mem with lu_gp_new.
1942 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
1943 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1945 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1946 " core/alua/lu_gps/%s, ID: %hu\n",
1947 (move
) ? "Moving" : "Adding",
1948 config_item_name(&hba
->hba_group
.cg_item
),
1949 config_item_name(&su_dev
->se_dev_group
.cg_item
),
1950 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
1951 lu_gp_new
->lu_gp_id
);
1953 core_alua_put_lu_gp_from_name(lu_gp_new
);
1957 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp
= {
1958 .attr
= { .ca_owner
= THIS_MODULE
,
1959 .ca_name
= "alua_lu_gp",
1960 .ca_mode
= S_IRUGO
| S_IWUSR
},
1961 .show
= target_core_show_alua_lu_gp
,
1962 .store
= target_core_store_alua_lu_gp
,
1965 static struct configfs_attribute
*lio_core_dev_attrs
[] = {
1966 &target_core_attr_dev_info
.attr
,
1967 &target_core_attr_dev_control
.attr
,
1968 &target_core_attr_dev_alias
.attr
,
1969 &target_core_attr_dev_udev_path
.attr
,
1970 &target_core_attr_dev_enable
.attr
,
1971 &target_core_attr_dev_alua_lu_gp
.attr
,
1975 static void target_core_dev_release(struct config_item
*item
)
1977 struct se_subsystem_dev
*se_dev
= container_of(to_config_group(item
),
1978 struct se_subsystem_dev
, se_dev_group
);
1979 struct se_hba
*hba
= item_to_hba(&se_dev
->se_dev_hba
->hba_group
.cg_item
);
1980 struct se_subsystem_api
*t
= hba
->transport
;
1981 struct config_group
*dev_cg
= &se_dev
->se_dev_group
;
1983 kfree(dev_cg
->default_groups
);
1985 * This pointer will set when the storage is enabled with:
1986 *`echo 1 > $CONFIGFS/core/$HBA/$DEV/dev_enable`
1988 if (se_dev
->se_dev_ptr
) {
1989 pr_debug("Target_Core_ConfigFS: Calling se_free_"
1990 "virtual_device() for se_dev_ptr: %p\n",
1991 se_dev
->se_dev_ptr
);
1993 se_free_virtual_device(se_dev
->se_dev_ptr
, hba
);
1996 * Release struct se_subsystem_dev->se_dev_su_ptr..
1998 pr_debug("Target_Core_ConfigFS: Calling t->free_"
1999 "device() for se_dev_su_ptr: %p\n",
2000 se_dev
->se_dev_su_ptr
);
2002 t
->free_device(se_dev
->se_dev_su_ptr
);
2005 pr_debug("Target_Core_ConfigFS: Deallocating se_subsystem"
2006 "_dev_t: %p\n", se_dev
);
2010 static ssize_t
target_core_dev_show(struct config_item
*item
,
2011 struct configfs_attribute
*attr
,
2014 struct se_subsystem_dev
*se_dev
= container_of(
2015 to_config_group(item
), struct se_subsystem_dev
,
2017 struct target_core_configfs_attribute
*tc_attr
= container_of(
2018 attr
, struct target_core_configfs_attribute
, attr
);
2023 return tc_attr
->show(se_dev
, page
);
2026 static ssize_t
target_core_dev_store(struct config_item
*item
,
2027 struct configfs_attribute
*attr
,
2028 const char *page
, size_t count
)
2030 struct se_subsystem_dev
*se_dev
= container_of(
2031 to_config_group(item
), struct se_subsystem_dev
,
2033 struct target_core_configfs_attribute
*tc_attr
= container_of(
2034 attr
, struct target_core_configfs_attribute
, attr
);
2036 if (!tc_attr
->store
)
2039 return tc_attr
->store(se_dev
, page
, count
);
2042 static struct configfs_item_operations target_core_dev_item_ops
= {
2043 .release
= target_core_dev_release
,
2044 .show_attribute
= target_core_dev_show
,
2045 .store_attribute
= target_core_dev_store
,
2048 static struct config_item_type target_core_dev_cit
= {
2049 .ct_item_ops
= &target_core_dev_item_ops
,
2050 .ct_attrs
= lio_core_dev_attrs
,
2051 .ct_owner
= THIS_MODULE
,
2054 /* End functions for struct config_item_type target_core_dev_cit */
2056 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
2058 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp
, t10_alua_lu_gp
);
2059 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
2060 static struct target_core_alua_lu_gp_attribute \
2061 target_core_alua_lu_gp_##_name = \
2062 __CONFIGFS_EATTR(_name, _mode, \
2063 target_core_alua_lu_gp_show_attr_##_name, \
2064 target_core_alua_lu_gp_store_attr_##_name);
2066 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
2067 static struct target_core_alua_lu_gp_attribute \
2068 target_core_alua_lu_gp_##_name = \
2069 __CONFIGFS_EATTR_RO(_name, \
2070 target_core_alua_lu_gp_show_attr_##_name);
2075 static ssize_t
target_core_alua_lu_gp_show_attr_lu_gp_id(
2076 struct t10_alua_lu_gp
*lu_gp
,
2079 if (!lu_gp
->lu_gp_valid_id
)
2082 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
2085 static ssize_t
target_core_alua_lu_gp_store_attr_lu_gp_id(
2086 struct t10_alua_lu_gp
*lu_gp
,
2090 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2091 unsigned long lu_gp_id
;
2094 ret
= strict_strtoul(page
, 0, &lu_gp_id
);
2096 pr_err("strict_strtoul() returned %d for"
2097 " lu_gp_id\n", ret
);
2100 if (lu_gp_id
> 0x0000ffff) {
2101 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
2102 " 0x0000ffff\n", lu_gp_id
);
2106 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
2110 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
2111 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2112 config_item_name(&alua_lu_gp_cg
->cg_item
),
2118 SE_DEV_ALUA_LU_ATTR(lu_gp_id
, S_IRUGO
| S_IWUSR
);
2123 static ssize_t
target_core_alua_lu_gp_show_attr_members(
2124 struct t10_alua_lu_gp
*lu_gp
,
2127 struct se_device
*dev
;
2129 struct se_subsystem_dev
*su_dev
;
2130 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2131 ssize_t len
= 0, cur_len
;
2132 unsigned char buf
[LU_GROUP_NAME_BUF
];
2134 memset(buf
, 0, LU_GROUP_NAME_BUF
);
2136 spin_lock(&lu_gp
->lu_gp_lock
);
2137 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
2138 dev
= lu_gp_mem
->lu_gp_mem_dev
;
2139 su_dev
= dev
->se_sub_dev
;
2140 hba
= su_dev
->se_dev_hba
;
2142 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
2143 config_item_name(&hba
->hba_group
.cg_item
),
2144 config_item_name(&su_dev
->se_dev_group
.cg_item
));
2145 cur_len
++; /* Extra byte for NULL terminator */
2147 if ((cur_len
+ len
) > PAGE_SIZE
) {
2148 pr_warn("Ran out of lu_gp_show_attr"
2149 "_members buffer\n");
2152 memcpy(page
+len
, buf
, cur_len
);
2155 spin_unlock(&lu_gp
->lu_gp_lock
);
2160 SE_DEV_ALUA_LU_ATTR_RO(members
);
2162 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp
, t10_alua_lu_gp
, lu_gp_group
);
2164 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
2165 &target_core_alua_lu_gp_lu_gp_id
.attr
,
2166 &target_core_alua_lu_gp_members
.attr
,
2170 static void target_core_alua_lu_gp_release(struct config_item
*item
)
2172 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2173 struct t10_alua_lu_gp
, lu_gp_group
);
2175 core_alua_free_lu_gp(lu_gp
);
2178 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
2179 .release
= target_core_alua_lu_gp_release
,
2180 .show_attribute
= target_core_alua_lu_gp_attr_show
,
2181 .store_attribute
= target_core_alua_lu_gp_attr_store
,
2184 static struct config_item_type target_core_alua_lu_gp_cit
= {
2185 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
2186 .ct_attrs
= target_core_alua_lu_gp_attrs
,
2187 .ct_owner
= THIS_MODULE
,
2190 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
2192 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
2194 static struct config_group
*target_core_alua_create_lu_gp(
2195 struct config_group
*group
,
2198 struct t10_alua_lu_gp
*lu_gp
;
2199 struct config_group
*alua_lu_gp_cg
= NULL
;
2200 struct config_item
*alua_lu_gp_ci
= NULL
;
2202 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
2206 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2207 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
2209 config_group_init_type_name(alua_lu_gp_cg
, name
,
2210 &target_core_alua_lu_gp_cit
);
2212 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2213 " Group: core/alua/lu_gps/%s\n",
2214 config_item_name(alua_lu_gp_ci
));
2216 return alua_lu_gp_cg
;
2220 static void target_core_alua_drop_lu_gp(
2221 struct config_group
*group
,
2222 struct config_item
*item
)
2224 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2225 struct t10_alua_lu_gp
, lu_gp_group
);
2227 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2228 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2229 config_item_name(item
), lu_gp
->lu_gp_id
);
2231 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
2232 * -> target_core_alua_lu_gp_release()
2234 config_item_put(item
);
2237 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
2238 .make_group
= &target_core_alua_create_lu_gp
,
2239 .drop_item
= &target_core_alua_drop_lu_gp
,
2242 static struct config_item_type target_core_alua_lu_gps_cit
= {
2243 .ct_item_ops
= NULL
,
2244 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
2245 .ct_owner
= THIS_MODULE
,
2248 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
2250 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2252 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
);
2253 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
2254 static struct target_core_alua_tg_pt_gp_attribute \
2255 target_core_alua_tg_pt_gp_##_name = \
2256 __CONFIGFS_EATTR(_name, _mode, \
2257 target_core_alua_tg_pt_gp_show_attr_##_name, \
2258 target_core_alua_tg_pt_gp_store_attr_##_name);
2260 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2261 static struct target_core_alua_tg_pt_gp_attribute \
2262 target_core_alua_tg_pt_gp_##_name = \
2263 __CONFIGFS_EATTR_RO(_name, \
2264 target_core_alua_tg_pt_gp_show_attr_##_name);
2269 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2270 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2273 return sprintf(page
, "%d\n",
2274 atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
));
2277 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2278 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2282 struct se_subsystem_dev
*su_dev
= tg_pt_gp
->tg_pt_gp_su_dev
;
2286 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2287 pr_err("Unable to do implict ALUA on non valid"
2288 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2292 ret
= strict_strtoul(page
, 0, &tmp
);
2294 pr_err("Unable to extract new ALUA access state from"
2298 new_state
= (int)tmp
;
2300 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICT_ALUA
)) {
2301 pr_err("Unable to process implict configfs ALUA"
2302 " transition while TPGS_IMPLICT_ALUA is diabled\n");
2306 ret
= core_alua_do_port_transition(tg_pt_gp
, su_dev
->se_dev_ptr
,
2307 NULL
, NULL
, new_state
, 0);
2308 return (!ret
) ? count
: -EINVAL
;
2311 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state
, S_IRUGO
| S_IWUSR
);
2314 * alua_access_status
2316 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2317 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2320 return sprintf(page
, "%s\n",
2321 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2324 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2325 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2330 int new_status
, ret
;
2332 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2333 pr_err("Unable to do set ALUA access status on non"
2334 " valid tg_pt_gp ID: %hu\n",
2335 tg_pt_gp
->tg_pt_gp_valid_id
);
2339 ret
= strict_strtoul(page
, 0, &tmp
);
2341 pr_err("Unable to extract new ALUA access status"
2342 " from %s\n", page
);
2345 new_status
= (int)tmp
;
2347 if ((new_status
!= ALUA_STATUS_NONE
) &&
2348 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
) &&
2349 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
)) {
2350 pr_err("Illegal ALUA access status: 0x%02x\n",
2355 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2359 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status
, S_IRUGO
| S_IWUSR
);
2364 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2365 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2368 return core_alua_show_access_type(tg_pt_gp
, page
);
2371 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2372 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2376 return core_alua_store_access_type(tg_pt_gp
, page
, count
);
2379 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type
, S_IRUGO
| S_IWUSR
);
2382 * alua_write_metadata
2384 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2385 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2388 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_write_metadata
);
2391 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2392 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2399 ret
= strict_strtoul(page
, 0, &tmp
);
2401 pr_err("Unable to extract alua_write_metadata\n");
2405 if ((tmp
!= 0) && (tmp
!= 1)) {
2406 pr_err("Illegal value for alua_write_metadata:"
2410 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2415 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata
, S_IRUGO
| S_IWUSR
);
2422 static ssize_t
target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2423 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2426 return core_alua_show_nonop_delay_msecs(tg_pt_gp
, page
);
2430 static ssize_t
target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2431 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2435 return core_alua_store_nonop_delay_msecs(tg_pt_gp
, page
, count
);
2438 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs
, S_IRUGO
| S_IWUSR
);
2443 static ssize_t
target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2444 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2447 return core_alua_show_trans_delay_msecs(tg_pt_gp
, page
);
2450 static ssize_t
target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2451 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2455 return core_alua_store_trans_delay_msecs(tg_pt_gp
, page
, count
);
2458 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs
, S_IRUGO
| S_IWUSR
);
2464 static ssize_t
target_core_alua_tg_pt_gp_show_attr_preferred(
2465 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2468 return core_alua_show_preferred_bit(tg_pt_gp
, page
);
2471 static ssize_t
target_core_alua_tg_pt_gp_store_attr_preferred(
2472 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2476 return core_alua_store_preferred_bit(tg_pt_gp
, page
, count
);
2479 SE_DEV_ALUA_TG_PT_ATTR(preferred
, S_IRUGO
| S_IWUSR
);
2484 static ssize_t
target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2485 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2488 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
2491 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2494 static ssize_t
target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2495 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2499 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2500 unsigned long tg_pt_gp_id
;
2503 ret
= strict_strtoul(page
, 0, &tg_pt_gp_id
);
2505 pr_err("strict_strtoul() returned %d for"
2506 " tg_pt_gp_id\n", ret
);
2509 if (tg_pt_gp_id
> 0x0000ffff) {
2510 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:"
2511 " 0x0000ffff\n", tg_pt_gp_id
);
2515 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2519 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
2520 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2521 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2522 tg_pt_gp
->tg_pt_gp_id
);
2527 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id
, S_IRUGO
| S_IWUSR
);
2532 static ssize_t
target_core_alua_tg_pt_gp_show_attr_members(
2533 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2536 struct se_port
*port
;
2537 struct se_portal_group
*tpg
;
2539 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
2540 ssize_t len
= 0, cur_len
;
2541 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2543 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2545 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2546 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
2547 tg_pt_gp_mem_list
) {
2548 port
= tg_pt_gp_mem
->tg_pt
;
2549 tpg
= port
->sep_tpg
;
2550 lun
= port
->sep_lun
;
2552 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2553 "/%s\n", tpg
->se_tpg_tfo
->get_fabric_name(),
2554 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
2555 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
2556 config_item_name(&lun
->lun_group
.cg_item
));
2557 cur_len
++; /* Extra byte for NULL terminator */
2559 if ((cur_len
+ len
) > PAGE_SIZE
) {
2560 pr_warn("Ran out of lu_gp_show_attr"
2561 "_members buffer\n");
2564 memcpy(page
+len
, buf
, cur_len
);
2567 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2572 SE_DEV_ALUA_TG_PT_ATTR_RO(members
);
2574 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
,
2577 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2578 &target_core_alua_tg_pt_gp_alua_access_state
.attr
,
2579 &target_core_alua_tg_pt_gp_alua_access_status
.attr
,
2580 &target_core_alua_tg_pt_gp_alua_access_type
.attr
,
2581 &target_core_alua_tg_pt_gp_alua_write_metadata
.attr
,
2582 &target_core_alua_tg_pt_gp_nonop_delay_msecs
.attr
,
2583 &target_core_alua_tg_pt_gp_trans_delay_msecs
.attr
,
2584 &target_core_alua_tg_pt_gp_preferred
.attr
,
2585 &target_core_alua_tg_pt_gp_tg_pt_gp_id
.attr
,
2586 &target_core_alua_tg_pt_gp_members
.attr
,
2590 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2592 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2593 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2595 core_alua_free_tg_pt_gp(tg_pt_gp
);
2598 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2599 .release
= target_core_alua_tg_pt_gp_release
,
2600 .show_attribute
= target_core_alua_tg_pt_gp_attr_show
,
2601 .store_attribute
= target_core_alua_tg_pt_gp_attr_store
,
2604 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2605 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2606 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2607 .ct_owner
= THIS_MODULE
,
2610 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2612 /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2614 static struct config_group
*target_core_alua_create_tg_pt_gp(
2615 struct config_group
*group
,
2618 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2619 alua_tg_pt_gps_group
);
2620 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2621 struct se_subsystem_dev
*su_dev
= alua
->t10_sub_dev
;
2622 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2623 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2625 tg_pt_gp
= core_alua_allocate_tg_pt_gp(su_dev
, name
, 0);
2629 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2630 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2632 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2633 &target_core_alua_tg_pt_gp_cit
);
2635 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
2636 " Group: alua/tg_pt_gps/%s\n",
2637 config_item_name(alua_tg_pt_gp_ci
));
2639 return alua_tg_pt_gp_cg
;
2642 static void target_core_alua_drop_tg_pt_gp(
2643 struct config_group
*group
,
2644 struct config_item
*item
)
2646 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2647 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2649 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
2650 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2651 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2653 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2654 * -> target_core_alua_tg_pt_gp_release().
2656 config_item_put(item
);
2659 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2660 .make_group
= &target_core_alua_create_tg_pt_gp
,
2661 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2664 static struct config_item_type target_core_alua_tg_pt_gps_cit
= {
2665 .ct_group_ops
= &target_core_alua_tg_pt_gps_group_ops
,
2666 .ct_owner
= THIS_MODULE
,
2669 /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2671 /* Start functions for struct config_item_type target_core_alua_cit */
2674 * target_core_alua_cit is a ConfigFS group that lives under
2675 * /sys/kernel/config/target/core/alua. There are default groups
2676 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2677 * target_core_alua_cit in target_core_init_configfs() below.
2679 static struct config_item_type target_core_alua_cit
= {
2680 .ct_item_ops
= NULL
,
2682 .ct_owner
= THIS_MODULE
,
2685 /* End functions for struct config_item_type target_core_alua_cit */
2687 /* Start functions for struct config_item_type target_core_stat_cit */
2689 static struct config_group
*target_core_stat_mkdir(
2690 struct config_group
*group
,
2693 return ERR_PTR(-ENOSYS
);
2696 static void target_core_stat_rmdir(
2697 struct config_group
*group
,
2698 struct config_item
*item
)
2703 static struct configfs_group_operations target_core_stat_group_ops
= {
2704 .make_group
= &target_core_stat_mkdir
,
2705 .drop_item
= &target_core_stat_rmdir
,
2708 static struct config_item_type target_core_stat_cit
= {
2709 .ct_group_ops
= &target_core_stat_group_ops
,
2710 .ct_owner
= THIS_MODULE
,
2713 /* End functions for struct config_item_type target_core_stat_cit */
2715 /* Start functions for struct config_item_type target_core_hba_cit */
2717 static struct config_group
*target_core_make_subdev(
2718 struct config_group
*group
,
2721 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2722 struct se_subsystem_dev
*se_dev
;
2723 struct se_subsystem_api
*t
;
2724 struct config_item
*hba_ci
= &group
->cg_item
;
2725 struct se_hba
*hba
= item_to_hba(hba_ci
);
2726 struct config_group
*dev_cg
= NULL
, *tg_pt_gp_cg
= NULL
;
2727 struct config_group
*dev_stat_grp
= NULL
;
2728 int errno
= -ENOMEM
, ret
;
2730 ret
= mutex_lock_interruptible(&hba
->hba_access_mutex
);
2732 return ERR_PTR(ret
);
2734 * Locate the struct se_subsystem_api from parent's struct se_hba.
2738 se_dev
= kzalloc(sizeof(struct se_subsystem_dev
), GFP_KERNEL
);
2740 pr_err("Unable to allocate memory for"
2741 " struct se_subsystem_dev\n");
2744 INIT_LIST_HEAD(&se_dev
->se_dev_node
);
2745 INIT_LIST_HEAD(&se_dev
->t10_wwn
.t10_vpd_list
);
2746 spin_lock_init(&se_dev
->t10_wwn
.t10_vpd_lock
);
2747 INIT_LIST_HEAD(&se_dev
->t10_pr
.registration_list
);
2748 INIT_LIST_HEAD(&se_dev
->t10_pr
.aptpl_reg_list
);
2749 spin_lock_init(&se_dev
->t10_pr
.registration_lock
);
2750 spin_lock_init(&se_dev
->t10_pr
.aptpl_reg_lock
);
2751 INIT_LIST_HEAD(&se_dev
->t10_alua
.tg_pt_gps_list
);
2752 spin_lock_init(&se_dev
->t10_alua
.tg_pt_gps_lock
);
2753 spin_lock_init(&se_dev
->se_dev_lock
);
2754 se_dev
->t10_pr
.pr_aptpl_buf_len
= PR_APTPL_BUF_LEN
;
2755 se_dev
->t10_wwn
.t10_sub_dev
= se_dev
;
2756 se_dev
->t10_alua
.t10_sub_dev
= se_dev
;
2757 se_dev
->se_dev_attrib
.da_sub_dev
= se_dev
;
2759 se_dev
->se_dev_hba
= hba
;
2760 dev_cg
= &se_dev
->se_dev_group
;
2762 dev_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 7,
2764 if (!dev_cg
->default_groups
)
2767 * Set se_dev_su_ptr from struct se_subsystem_api returned void ptr
2768 * for ->allocate_virtdevice()
2770 * se_dev->se_dev_ptr will be set after ->create_virtdev()
2771 * has been called successfully in the next level up in the
2772 * configfs tree for device object's struct config_group.
2774 se_dev
->se_dev_su_ptr
= t
->allocate_virtdevice(hba
, name
);
2775 if (!se_dev
->se_dev_su_ptr
) {
2776 pr_err("Unable to locate subsystem dependent pointer"
2777 " from allocate_virtdevice()\n");
2780 spin_lock(&se_device_lock
);
2781 list_add_tail(&se_dev
->se_dev_node
, &se_dev_list
);
2782 spin_unlock(&se_device_lock
);
2784 config_group_init_type_name(&se_dev
->se_dev_group
, name
,
2785 &target_core_dev_cit
);
2786 config_group_init_type_name(&se_dev
->se_dev_attrib
.da_group
, "attrib",
2787 &target_core_dev_attrib_cit
);
2788 config_group_init_type_name(&se_dev
->se_dev_pr_group
, "pr",
2789 &target_core_dev_pr_cit
);
2790 config_group_init_type_name(&se_dev
->t10_wwn
.t10_wwn_group
, "wwn",
2791 &target_core_dev_wwn_cit
);
2792 config_group_init_type_name(&se_dev
->t10_alua
.alua_tg_pt_gps_group
,
2793 "alua", &target_core_alua_tg_pt_gps_cit
);
2794 config_group_init_type_name(&se_dev
->dev_stat_grps
.stat_group
,
2795 "statistics", &target_core_stat_cit
);
2797 dev_cg
->default_groups
[0] = &se_dev
->se_dev_attrib
.da_group
;
2798 dev_cg
->default_groups
[1] = &se_dev
->se_dev_pr_group
;
2799 dev_cg
->default_groups
[2] = &se_dev
->t10_wwn
.t10_wwn_group
;
2800 dev_cg
->default_groups
[3] = &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2801 dev_cg
->default_groups
[4] = &se_dev
->dev_stat_grps
.stat_group
;
2802 dev_cg
->default_groups
[5] = NULL
;
2804 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
2806 tg_pt_gp
= core_alua_allocate_tg_pt_gp(se_dev
, "default_tg_pt_gp", 1);
2810 tg_pt_gp_cg
= &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2811 tg_pt_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
2813 if (!tg_pt_gp_cg
->default_groups
) {
2814 pr_err("Unable to allocate tg_pt_gp_cg->"
2815 "default_groups\n");
2819 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2820 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2821 tg_pt_gp_cg
->default_groups
[0] = &tg_pt_gp
->tg_pt_gp_group
;
2822 tg_pt_gp_cg
->default_groups
[1] = NULL
;
2823 se_dev
->t10_alua
.default_tg_pt_gp
= tg_pt_gp
;
2825 * Add core/$HBA/$DEV/statistics/ default groups
2827 dev_stat_grp
= &se_dev
->dev_stat_grps
.stat_group
;
2828 dev_stat_grp
->default_groups
= kzalloc(sizeof(struct config_group
) * 4,
2830 if (!dev_stat_grp
->default_groups
) {
2831 pr_err("Unable to allocate dev_stat_grp->default_groups\n");
2834 target_stat_setup_dev_default_groups(se_dev
);
2836 pr_debug("Target_Core_ConfigFS: Allocated struct se_subsystem_dev:"
2837 " %p se_dev_su_ptr: %p\n", se_dev
, se_dev
->se_dev_su_ptr
);
2839 mutex_unlock(&hba
->hba_access_mutex
);
2840 return &se_dev
->se_dev_group
;
2842 if (se_dev
->t10_alua
.default_tg_pt_gp
) {
2843 core_alua_free_tg_pt_gp(se_dev
->t10_alua
.default_tg_pt_gp
);
2844 se_dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2847 kfree(dev_stat_grp
->default_groups
);
2849 kfree(tg_pt_gp_cg
->default_groups
);
2851 kfree(dev_cg
->default_groups
);
2852 if (se_dev
->se_dev_su_ptr
)
2853 t
->free_device(se_dev
->se_dev_su_ptr
);
2856 mutex_unlock(&hba
->hba_access_mutex
);
2857 return ERR_PTR(errno
);
2860 static void target_core_drop_subdev(
2861 struct config_group
*group
,
2862 struct config_item
*item
)
2864 struct se_subsystem_dev
*se_dev
= container_of(to_config_group(item
),
2865 struct se_subsystem_dev
, se_dev_group
);
2867 struct se_subsystem_api
*t
;
2868 struct config_item
*df_item
;
2869 struct config_group
*dev_cg
, *tg_pt_gp_cg
, *dev_stat_grp
;
2872 hba
= item_to_hba(&se_dev
->se_dev_hba
->hba_group
.cg_item
);
2874 mutex_lock(&hba
->hba_access_mutex
);
2877 spin_lock(&se_device_lock
);
2878 list_del(&se_dev
->se_dev_node
);
2879 spin_unlock(&se_device_lock
);
2881 dev_stat_grp
= &se_dev
->dev_stat_grps
.stat_group
;
2882 for (i
= 0; dev_stat_grp
->default_groups
[i
]; i
++) {
2883 df_item
= &dev_stat_grp
->default_groups
[i
]->cg_item
;
2884 dev_stat_grp
->default_groups
[i
] = NULL
;
2885 config_item_put(df_item
);
2887 kfree(dev_stat_grp
->default_groups
);
2889 tg_pt_gp_cg
= &se_dev
->t10_alua
.alua_tg_pt_gps_group
;
2890 for (i
= 0; tg_pt_gp_cg
->default_groups
[i
]; i
++) {
2891 df_item
= &tg_pt_gp_cg
->default_groups
[i
]->cg_item
;
2892 tg_pt_gp_cg
->default_groups
[i
] = NULL
;
2893 config_item_put(df_item
);
2895 kfree(tg_pt_gp_cg
->default_groups
);
2897 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2898 * directly from target_core_alua_tg_pt_gp_release().
2900 se_dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2902 dev_cg
= &se_dev
->se_dev_group
;
2903 for (i
= 0; dev_cg
->default_groups
[i
]; i
++) {
2904 df_item
= &dev_cg
->default_groups
[i
]->cg_item
;
2905 dev_cg
->default_groups
[i
] = NULL
;
2906 config_item_put(df_item
);
2909 * The releasing of se_dev and associated se_dev->se_dev_ptr is done
2910 * from target_core_dev_item_ops->release() ->target_core_dev_release().
2912 config_item_put(item
);
2913 mutex_unlock(&hba
->hba_access_mutex
);
2916 static struct configfs_group_operations target_core_hba_group_ops
= {
2917 .make_group
= target_core_make_subdev
,
2918 .drop_item
= target_core_drop_subdev
,
2921 CONFIGFS_EATTR_STRUCT(target_core_hba
, se_hba
);
2922 #define SE_HBA_ATTR(_name, _mode) \
2923 static struct target_core_hba_attribute \
2924 target_core_hba_##_name = \
2925 __CONFIGFS_EATTR(_name, _mode, \
2926 target_core_hba_show_attr_##_name, \
2927 target_core_hba_store_attr_##_name);
2929 #define SE_HBA_ATTR_RO(_name) \
2930 static struct target_core_hba_attribute \
2931 target_core_hba_##_name = \
2932 __CONFIGFS_EATTR_RO(_name, \
2933 target_core_hba_show_attr_##_name);
2935 static ssize_t
target_core_hba_show_attr_hba_info(
2939 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
2940 hba
->hba_id
, hba
->transport
->name
,
2941 TARGET_CORE_CONFIGFS_VERSION
);
2944 SE_HBA_ATTR_RO(hba_info
);
2946 static ssize_t
target_core_hba_show_attr_hba_mode(struct se_hba
*hba
,
2951 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
2954 return sprintf(page
, "%d\n", hba_mode
);
2957 static ssize_t
target_core_hba_store_attr_hba_mode(struct se_hba
*hba
,
2958 const char *page
, size_t count
)
2960 struct se_subsystem_api
*transport
= hba
->transport
;
2961 unsigned long mode_flag
;
2964 if (transport
->pmode_enable_hba
== NULL
)
2967 ret
= strict_strtoul(page
, 0, &mode_flag
);
2969 pr_err("Unable to extract hba mode flag: %d\n", ret
);
2973 spin_lock(&hba
->device_lock
);
2974 if (!list_empty(&hba
->hba_dev_list
)) {
2975 pr_err("Unable to set hba_mode with active devices\n");
2976 spin_unlock(&hba
->device_lock
);
2979 spin_unlock(&hba
->device_lock
);
2981 ret
= transport
->pmode_enable_hba(hba
, mode_flag
);
2985 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
2987 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
2992 SE_HBA_ATTR(hba_mode
, S_IRUGO
| S_IWUSR
);
2994 CONFIGFS_EATTR_OPS(target_core_hba
, se_hba
, hba_group
);
2996 static void target_core_hba_release(struct config_item
*item
)
2998 struct se_hba
*hba
= container_of(to_config_group(item
),
2999 struct se_hba
, hba_group
);
3000 core_delete_hba(hba
);
3003 static struct configfs_attribute
*target_core_hba_attrs
[] = {
3004 &target_core_hba_hba_info
.attr
,
3005 &target_core_hba_hba_mode
.attr
,
3009 static struct configfs_item_operations target_core_hba_item_ops
= {
3010 .release
= target_core_hba_release
,
3011 .show_attribute
= target_core_hba_attr_show
,
3012 .store_attribute
= target_core_hba_attr_store
,
3015 static struct config_item_type target_core_hba_cit
= {
3016 .ct_item_ops
= &target_core_hba_item_ops
,
3017 .ct_group_ops
= &target_core_hba_group_ops
,
3018 .ct_attrs
= target_core_hba_attrs
,
3019 .ct_owner
= THIS_MODULE
,
3022 static struct config_group
*target_core_call_addhbatotarget(
3023 struct config_group
*group
,
3026 char *se_plugin_str
, *str
, *str2
;
3028 char buf
[TARGET_CORE_NAME_MAX_LEN
];
3029 unsigned long plugin_dep_id
= 0;
3032 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
3033 if (strlen(name
) >= TARGET_CORE_NAME_MAX_LEN
) {
3034 pr_err("Passed *name strlen(): %d exceeds"
3035 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
3036 TARGET_CORE_NAME_MAX_LEN
);
3037 return ERR_PTR(-ENAMETOOLONG
);
3039 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
3041 str
= strstr(buf
, "_");
3043 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
3044 return ERR_PTR(-EINVAL
);
3046 se_plugin_str
= buf
;
3048 * Special case for subsystem plugins that have "_" in their names.
3049 * Namely rd_direct and rd_mcp..
3051 str2
= strstr(str
+1, "_");
3053 *str2
= '\0'; /* Terminate for *se_plugin_str */
3054 str2
++; /* Skip to start of plugin dependent ID */
3057 *str
= '\0'; /* Terminate for *se_plugin_str */
3058 str
++; /* Skip to start of plugin dependent ID */
3061 ret
= strict_strtoul(str
, 0, &plugin_dep_id
);
3063 pr_err("strict_strtoul() returned %d for"
3064 " plugin_dep_id\n", ret
);
3065 return ERR_PTR(-EINVAL
);
3068 * Load up TCM subsystem plugins if they have not already been loaded.
3070 transport_subsystem_check_init();
3072 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
3074 return ERR_CAST(hba
);
3076 config_group_init_type_name(&hba
->hba_group
, name
,
3077 &target_core_hba_cit
);
3079 return &hba
->hba_group
;
3082 static void target_core_call_delhbafromtarget(
3083 struct config_group
*group
,
3084 struct config_item
*item
)
3087 * core_delete_hba() is called from target_core_hba_item_ops->release()
3088 * -> target_core_hba_release()
3090 config_item_put(item
);
3093 static struct configfs_group_operations target_core_group_ops
= {
3094 .make_group
= target_core_call_addhbatotarget
,
3095 .drop_item
= target_core_call_delhbafromtarget
,
3098 static struct config_item_type target_core_cit
= {
3099 .ct_item_ops
= NULL
,
3100 .ct_group_ops
= &target_core_group_ops
,
3102 .ct_owner
= THIS_MODULE
,
3105 /* Stop functions for struct config_item_type target_core_hba_cit */
3107 static int __init
target_core_init_configfs(void)
3109 struct config_group
*target_cg
, *hba_cg
= NULL
, *alua_cg
= NULL
;
3110 struct config_group
*lu_gp_cg
= NULL
;
3111 struct configfs_subsystem
*subsys
;
3112 struct t10_alua_lu_gp
*lu_gp
;
3115 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
3116 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
3117 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
3119 subsys
= target_core_subsystem
[0];
3120 config_group_init(&subsys
->su_group
);
3121 mutex_init(&subsys
->su_mutex
);
3123 INIT_LIST_HEAD(&g_tf_list
);
3124 mutex_init(&g_tf_lock
);
3125 ret
= init_se_kmem_caches();
3129 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
3130 * and ALUA Logical Unit Group and Target Port Group infrastructure.
3132 target_cg
= &subsys
->su_group
;
3133 target_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3135 if (!target_cg
->default_groups
) {
3136 pr_err("Unable to allocate target_cg->default_groups\n");
3140 config_group_init_type_name(&target_core_hbagroup
,
3141 "core", &target_core_cit
);
3142 target_cg
->default_groups
[0] = &target_core_hbagroup
;
3143 target_cg
->default_groups
[1] = NULL
;
3145 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
3147 hba_cg
= &target_core_hbagroup
;
3148 hba_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3150 if (!hba_cg
->default_groups
) {
3151 pr_err("Unable to allocate hba_cg->default_groups\n");
3154 config_group_init_type_name(&alua_group
,
3155 "alua", &target_core_alua_cit
);
3156 hba_cg
->default_groups
[0] = &alua_group
;
3157 hba_cg
->default_groups
[1] = NULL
;
3159 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
3160 * groups under /sys/kernel/config/target/core/alua/
3162 alua_cg
= &alua_group
;
3163 alua_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3165 if (!alua_cg
->default_groups
) {
3166 pr_err("Unable to allocate alua_cg->default_groups\n");
3170 config_group_init_type_name(&alua_lu_gps_group
,
3171 "lu_gps", &target_core_alua_lu_gps_cit
);
3172 alua_cg
->default_groups
[0] = &alua_lu_gps_group
;
3173 alua_cg
->default_groups
[1] = NULL
;
3175 * Add core/alua/lu_gps/default_lu_gp
3177 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
3181 lu_gp_cg
= &alua_lu_gps_group
;
3182 lu_gp_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
3184 if (!lu_gp_cg
->default_groups
) {
3185 pr_err("Unable to allocate lu_gp_cg->default_groups\n");
3189 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
3190 &target_core_alua_lu_gp_cit
);
3191 lu_gp_cg
->default_groups
[0] = &lu_gp
->lu_gp_group
;
3192 lu_gp_cg
->default_groups
[1] = NULL
;
3193 default_lu_gp
= lu_gp
;
3195 * Register the target_core_mod subsystem with configfs.
3197 ret
= configfs_register_subsystem(subsys
);
3199 pr_err("Error %d while registering subsystem %s\n",
3200 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
3203 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
3204 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION
" on %s/%s"
3205 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
3207 * Register built-in RAMDISK subsystem logic for virtual LUN 0
3209 ret
= rd_module_init();
3213 if (core_dev_setup_virtual_lun0() < 0)
3219 configfs_unregister_subsystem(subsys
);
3220 core_dev_release_virtual_lun0();
3223 if (default_lu_gp
) {
3224 core_alua_free_lu_gp(default_lu_gp
);
3225 default_lu_gp
= NULL
;
3228 kfree(lu_gp_cg
->default_groups
);
3230 kfree(alua_cg
->default_groups
);
3232 kfree(hba_cg
->default_groups
);
3233 kfree(target_cg
->default_groups
);
3234 release_se_kmem_caches();
3238 static void __exit
target_core_exit_configfs(void)
3240 struct configfs_subsystem
*subsys
;
3241 struct config_group
*hba_cg
, *alua_cg
, *lu_gp_cg
;
3242 struct config_item
*item
;
3245 subsys
= target_core_subsystem
[0];
3247 lu_gp_cg
= &alua_lu_gps_group
;
3248 for (i
= 0; lu_gp_cg
->default_groups
[i
]; i
++) {
3249 item
= &lu_gp_cg
->default_groups
[i
]->cg_item
;
3250 lu_gp_cg
->default_groups
[i
] = NULL
;
3251 config_item_put(item
);
3253 kfree(lu_gp_cg
->default_groups
);
3254 lu_gp_cg
->default_groups
= NULL
;
3256 alua_cg
= &alua_group
;
3257 for (i
= 0; alua_cg
->default_groups
[i
]; i
++) {
3258 item
= &alua_cg
->default_groups
[i
]->cg_item
;
3259 alua_cg
->default_groups
[i
] = NULL
;
3260 config_item_put(item
);
3262 kfree(alua_cg
->default_groups
);
3263 alua_cg
->default_groups
= NULL
;
3265 hba_cg
= &target_core_hbagroup
;
3266 for (i
= 0; hba_cg
->default_groups
[i
]; i
++) {
3267 item
= &hba_cg
->default_groups
[i
]->cg_item
;
3268 hba_cg
->default_groups
[i
] = NULL
;
3269 config_item_put(item
);
3271 kfree(hba_cg
->default_groups
);
3272 hba_cg
->default_groups
= NULL
;
3274 * We expect subsys->su_group.default_groups to be released
3275 * by configfs subsystem provider logic..
3277 configfs_unregister_subsystem(subsys
);
3278 kfree(subsys
->su_group
.default_groups
);
3280 core_alua_free_lu_gp(default_lu_gp
);
3281 default_lu_gp
= NULL
;
3283 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
3284 " Infrastructure\n");
3286 core_dev_release_virtual_lun0();
3288 release_se_kmem_caches();
3291 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3292 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3293 MODULE_LICENSE("GPL");
3295 module_init(target_core_init_configfs
);
3296 module_exit(target_core_exit_configfs
);