1 /*******************************************************************************
2 * Filename: target_core_configfs.c
4 * This file contains ConfigFS logic for the Generic Target Engine project.
6 * (c) Copyright 2008-2012 RisingTide Systems LLC.
8 * Nicholas A. Bellinger <nab@kernel.org>
10 * based on configfs Copyright (C) 2005 Oracle. All rights reserved.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 ****************************************************************************/
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <generated/utsrelease.h>
26 #include <linux/utsname.h>
27 #include <linux/init.h>
29 #include <linux/namei.h>
30 #include <linux/slab.h>
31 #include <linux/types.h>
32 #include <linux/delay.h>
33 #include <linux/unistd.h>
34 #include <linux/string.h>
35 #include <linux/parser.h>
36 #include <linux/syscalls.h>
37 #include <linux/configfs.h>
38 #include <linux/spinlock.h>
40 #include <target/target_core_base.h>
41 #include <target/target_core_backend.h>
42 #include <target/target_core_fabric.h>
43 #include <target/target_core_fabric_configfs.h>
44 #include <target/target_core_configfs.h>
45 #include <target/configfs_macros.h>
47 #include "target_core_internal.h"
48 #include "target_core_alua.h"
49 #include "target_core_pr.h"
50 #include "target_core_rd.h"
52 extern struct t10_alua_lu_gp
*default_lu_gp
;
54 static LIST_HEAD(g_tf_list
);
55 static DEFINE_MUTEX(g_tf_lock
);
57 struct target_core_configfs_attribute
{
58 struct configfs_attribute attr
;
59 ssize_t (*show
)(void *, char *);
60 ssize_t (*store
)(void *, const char *, size_t);
63 static struct config_group target_core_hbagroup
;
64 static struct config_group alua_group
;
65 static struct config_group alua_lu_gps_group
;
67 static inline struct se_hba
*
68 item_to_hba(struct config_item
*item
)
70 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
74 * Attributes for /sys/kernel/config/target/
76 static ssize_t
target_core_attr_show(struct config_item
*item
,
77 struct configfs_attribute
*attr
,
80 return sprintf(page
, "Target Engine Core ConfigFS Infrastructure %s"
81 " on %s/%s on "UTS_RELEASE
"\n", TARGET_CORE_CONFIGFS_VERSION
,
82 utsname()->sysname
, utsname()->machine
);
85 static struct configfs_item_operations target_core_fabric_item_ops
= {
86 .show_attribute
= target_core_attr_show
,
89 static struct configfs_attribute target_core_item_attr_version
= {
90 .ca_owner
= THIS_MODULE
,
95 static struct target_fabric_configfs
*target_core_get_fabric(
98 struct target_fabric_configfs
*tf
;
103 mutex_lock(&g_tf_lock
);
104 list_for_each_entry(tf
, &g_tf_list
, tf_list
) {
105 if (!strcmp(tf
->tf_name
, name
)) {
106 atomic_inc(&tf
->tf_access_cnt
);
107 mutex_unlock(&g_tf_lock
);
111 mutex_unlock(&g_tf_lock
);
117 * Called from struct target_core_group_ops->make_group()
119 static struct config_group
*target_core_register_fabric(
120 struct config_group
*group
,
123 struct target_fabric_configfs
*tf
;
126 pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:"
127 " %s\n", group
, name
);
129 * Below are some hardcoded request_module() calls to automatically
130 * local fabric modules when the following is called:
132 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
134 * Note that this does not limit which TCM fabric module can be
135 * registered, but simply provids auto loading logic for modules with
136 * mkdir(2) system calls with known TCM fabric modules.
138 if (!strncmp(name
, "iscsi", 5)) {
140 * Automatically load the LIO Target fabric module when the
141 * following is called:
143 * mkdir -p $CONFIGFS/target/iscsi
145 ret
= request_module("iscsi_target_mod");
147 pr_err("request_module() failed for"
148 " iscsi_target_mod.ko: %d\n", ret
);
149 return ERR_PTR(-EINVAL
);
151 } else if (!strncmp(name
, "loopback", 8)) {
153 * Automatically load the tcm_loop fabric module when the
154 * following is called:
156 * mkdir -p $CONFIGFS/target/loopback
158 ret
= request_module("tcm_loop");
160 pr_err("request_module() failed for"
161 " tcm_loop.ko: %d\n", ret
);
162 return ERR_PTR(-EINVAL
);
166 tf
= target_core_get_fabric(name
);
168 pr_err("target_core_get_fabric() failed for %s\n",
170 return ERR_PTR(-EINVAL
);
172 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
173 " %s\n", tf
->tf_name
);
175 * On a successful target_core_get_fabric() look, the returned
176 * struct target_fabric_configfs *tf will contain a usage reference.
178 pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
179 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
181 tf
->tf_group
.default_groups
= tf
->tf_default_groups
;
182 tf
->tf_group
.default_groups
[0] = &tf
->tf_disc_group
;
183 tf
->tf_group
.default_groups
[1] = NULL
;
185 config_group_init_type_name(&tf
->tf_group
, name
,
186 &TF_CIT_TMPL(tf
)->tfc_wwn_cit
);
187 config_group_init_type_name(&tf
->tf_disc_group
, "discovery_auth",
188 &TF_CIT_TMPL(tf
)->tfc_discovery_cit
);
190 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
191 " %s\n", tf
->tf_group
.cg_item
.ci_name
);
193 * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item()
195 tf
->tf_ops
.tf_subsys
= tf
->tf_subsys
;
196 tf
->tf_fabric
= &tf
->tf_group
.cg_item
;
197 pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
200 return &tf
->tf_group
;
204 * Called from struct target_core_group_ops->drop_item()
206 static void target_core_deregister_fabric(
207 struct config_group
*group
,
208 struct config_item
*item
)
210 struct target_fabric_configfs
*tf
= container_of(
211 to_config_group(item
), struct target_fabric_configfs
, tf_group
);
212 struct config_group
*tf_group
;
213 struct config_item
*df_item
;
216 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
217 " tf list\n", config_item_name(item
));
219 pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:"
220 " %s\n", tf
->tf_name
);
221 atomic_dec(&tf
->tf_access_cnt
);
223 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing"
224 " tf->tf_fabric for %s\n", tf
->tf_name
);
225 tf
->tf_fabric
= NULL
;
227 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
228 " %s\n", config_item_name(item
));
230 tf_group
= &tf
->tf_group
;
231 for (i
= 0; tf_group
->default_groups
[i
]; i
++) {
232 df_item
= &tf_group
->default_groups
[i
]->cg_item
;
233 tf_group
->default_groups
[i
] = NULL
;
234 config_item_put(df_item
);
236 config_item_put(item
);
239 static struct configfs_group_operations target_core_fabric_group_ops
= {
240 .make_group
= &target_core_register_fabric
,
241 .drop_item
= &target_core_deregister_fabric
,
245 * All item attributes appearing in /sys/kernel/target/ appear here.
247 static struct configfs_attribute
*target_core_fabric_item_attrs
[] = {
248 &target_core_item_attr_version
,
253 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
255 static struct config_item_type target_core_fabrics_item
= {
256 .ct_item_ops
= &target_core_fabric_item_ops
,
257 .ct_group_ops
= &target_core_fabric_group_ops
,
258 .ct_attrs
= target_core_fabric_item_attrs
,
259 .ct_owner
= THIS_MODULE
,
262 static struct configfs_subsystem target_core_fabrics
= {
265 .ci_namebuf
= "target",
266 .ci_type
= &target_core_fabrics_item
,
271 static struct configfs_subsystem
*target_core_subsystem
[] = {
272 &target_core_fabrics
,
276 /*##############################################################################
277 // Start functions called by external Target Fabrics Modules
278 //############################################################################*/
281 * First function called by fabric modules to:
283 * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer.
284 * 2) Add struct target_fabric_configfs to g_tf_list
285 * 3) Return struct target_fabric_configfs to fabric module to be passed
286 * into target_fabric_configfs_register().
288 struct target_fabric_configfs
*target_fabric_configfs_init(
289 struct module
*fabric_mod
,
292 struct target_fabric_configfs
*tf
;
295 pr_err("Unable to locate passed fabric name\n");
296 return ERR_PTR(-EINVAL
);
298 if (strlen(name
) >= TARGET_FABRIC_NAME_SIZE
) {
299 pr_err("Passed name: %s exceeds TARGET_FABRIC"
300 "_NAME_SIZE\n", name
);
301 return ERR_PTR(-EINVAL
);
304 tf
= kzalloc(sizeof(struct target_fabric_configfs
), GFP_KERNEL
);
306 return ERR_PTR(-ENOMEM
);
308 INIT_LIST_HEAD(&tf
->tf_list
);
309 atomic_set(&tf
->tf_access_cnt
, 0);
311 * Setup the default generic struct config_item_type's (cits) in
312 * struct target_fabric_configfs->tf_cit_tmpl
314 tf
->tf_module
= fabric_mod
;
315 target_fabric_setup_cits(tf
);
317 tf
->tf_subsys
= target_core_subsystem
[0];
318 snprintf(tf
->tf_name
, TARGET_FABRIC_NAME_SIZE
, "%s", name
);
320 mutex_lock(&g_tf_lock
);
321 list_add_tail(&tf
->tf_list
, &g_tf_list
);
322 mutex_unlock(&g_tf_lock
);
324 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>"
326 pr_debug("Initialized struct target_fabric_configfs: %p for"
327 " %s\n", tf
, tf
->tf_name
);
330 EXPORT_SYMBOL(target_fabric_configfs_init
);
333 * Called by fabric plugins after FAILED target_fabric_configfs_register() call.
335 void target_fabric_configfs_free(
336 struct target_fabric_configfs
*tf
)
338 mutex_lock(&g_tf_lock
);
339 list_del(&tf
->tf_list
);
340 mutex_unlock(&g_tf_lock
);
344 EXPORT_SYMBOL(target_fabric_configfs_free
);
347 * Perform a sanity check of the passed tf->tf_ops before completing
348 * TCM fabric module registration.
350 static int target_fabric_tf_ops_check(
351 struct target_fabric_configfs
*tf
)
353 struct target_core_fabric_ops
*tfo
= &tf
->tf_ops
;
355 if (!tfo
->get_fabric_name
) {
356 pr_err("Missing tfo->get_fabric_name()\n");
359 if (!tfo
->get_fabric_proto_ident
) {
360 pr_err("Missing tfo->get_fabric_proto_ident()\n");
363 if (!tfo
->tpg_get_wwn
) {
364 pr_err("Missing tfo->tpg_get_wwn()\n");
367 if (!tfo
->tpg_get_tag
) {
368 pr_err("Missing tfo->tpg_get_tag()\n");
371 if (!tfo
->tpg_get_default_depth
) {
372 pr_err("Missing tfo->tpg_get_default_depth()\n");
375 if (!tfo
->tpg_get_pr_transport_id
) {
376 pr_err("Missing tfo->tpg_get_pr_transport_id()\n");
379 if (!tfo
->tpg_get_pr_transport_id_len
) {
380 pr_err("Missing tfo->tpg_get_pr_transport_id_len()\n");
383 if (!tfo
->tpg_check_demo_mode
) {
384 pr_err("Missing tfo->tpg_check_demo_mode()\n");
387 if (!tfo
->tpg_check_demo_mode_cache
) {
388 pr_err("Missing tfo->tpg_check_demo_mode_cache()\n");
391 if (!tfo
->tpg_check_demo_mode_write_protect
) {
392 pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n");
395 if (!tfo
->tpg_check_prod_mode_write_protect
) {
396 pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n");
399 if (!tfo
->tpg_alloc_fabric_acl
) {
400 pr_err("Missing tfo->tpg_alloc_fabric_acl()\n");
403 if (!tfo
->tpg_release_fabric_acl
) {
404 pr_err("Missing tfo->tpg_release_fabric_acl()\n");
407 if (!tfo
->tpg_get_inst_index
) {
408 pr_err("Missing tfo->tpg_get_inst_index()\n");
411 if (!tfo
->release_cmd
) {
412 pr_err("Missing tfo->release_cmd()\n");
415 if (!tfo
->shutdown_session
) {
416 pr_err("Missing tfo->shutdown_session()\n");
419 if (!tfo
->close_session
) {
420 pr_err("Missing tfo->close_session()\n");
423 if (!tfo
->sess_get_index
) {
424 pr_err("Missing tfo->sess_get_index()\n");
427 if (!tfo
->write_pending
) {
428 pr_err("Missing tfo->write_pending()\n");
431 if (!tfo
->write_pending_status
) {
432 pr_err("Missing tfo->write_pending_status()\n");
435 if (!tfo
->set_default_node_attributes
) {
436 pr_err("Missing tfo->set_default_node_attributes()\n");
439 if (!tfo
->get_task_tag
) {
440 pr_err("Missing tfo->get_task_tag()\n");
443 if (!tfo
->get_cmd_state
) {
444 pr_err("Missing tfo->get_cmd_state()\n");
447 if (!tfo
->queue_data_in
) {
448 pr_err("Missing tfo->queue_data_in()\n");
451 if (!tfo
->queue_status
) {
452 pr_err("Missing tfo->queue_status()\n");
455 if (!tfo
->queue_tm_rsp
) {
456 pr_err("Missing tfo->queue_tm_rsp()\n");
460 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
461 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
462 * target_core_fabric_configfs.c WWN+TPG group context code.
464 if (!tfo
->fabric_make_wwn
) {
465 pr_err("Missing tfo->fabric_make_wwn()\n");
468 if (!tfo
->fabric_drop_wwn
) {
469 pr_err("Missing tfo->fabric_drop_wwn()\n");
472 if (!tfo
->fabric_make_tpg
) {
473 pr_err("Missing tfo->fabric_make_tpg()\n");
476 if (!tfo
->fabric_drop_tpg
) {
477 pr_err("Missing tfo->fabric_drop_tpg()\n");
485 * Called 2nd from fabric module with returned parameter of
486 * struct target_fabric_configfs * from target_fabric_configfs_init().
488 * Upon a successful registration, the new fabric's struct config_item is
489 * return. Also, a pointer to this struct is set in the passed
490 * struct target_fabric_configfs.
492 int target_fabric_configfs_register(
493 struct target_fabric_configfs
*tf
)
498 pr_err("Unable to locate target_fabric_configfs"
502 if (!tf
->tf_subsys
) {
503 pr_err("Unable to target struct config_subsystem"
507 ret
= target_fabric_tf_ops_check(tf
);
511 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>"
515 EXPORT_SYMBOL(target_fabric_configfs_register
);
517 void target_fabric_configfs_deregister(
518 struct target_fabric_configfs
*tf
)
520 struct configfs_subsystem
*su
;
523 pr_err("Unable to locate passed target_fabric_"
529 pr_err("Unable to locate passed tf->tf_subsys"
533 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
535 mutex_lock(&g_tf_lock
);
536 if (atomic_read(&tf
->tf_access_cnt
)) {
537 mutex_unlock(&g_tf_lock
);
538 pr_err("Non zero tf->tf_access_cnt for fabric %s\n",
542 list_del(&tf
->tf_list
);
543 mutex_unlock(&g_tf_lock
);
545 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
546 " %s\n", tf
->tf_name
);
547 tf
->tf_module
= NULL
;
548 tf
->tf_subsys
= NULL
;
551 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
554 EXPORT_SYMBOL(target_fabric_configfs_deregister
);
556 /*##############################################################################
557 // Stop functions called by external Target Fabrics Modules
558 //############################################################################*/
560 /* Start functions for struct config_item_type target_core_dev_attrib_cit */
562 #define DEF_DEV_ATTRIB_SHOW(_name) \
563 static ssize_t target_core_dev_show_attr_##_name( \
564 struct se_dev_attrib *da, \
567 return snprintf(page, PAGE_SIZE, "%u\n", \
568 (u32)da->da_dev->dev_attrib._name); \
571 #define DEF_DEV_ATTRIB_STORE(_name) \
572 static ssize_t target_core_dev_store_attr_##_name( \
573 struct se_dev_attrib *da, \
580 ret = strict_strtoul(page, 0, &val); \
582 pr_err("strict_strtoul() failed with" \
583 " ret: %d\n", ret); \
586 ret = se_dev_set_##_name(da->da_dev, (u32)val); \
588 return (!ret) ? count : -EINVAL; \
591 #define DEF_DEV_ATTRIB(_name) \
592 DEF_DEV_ATTRIB_SHOW(_name); \
593 DEF_DEV_ATTRIB_STORE(_name);
595 #define DEF_DEV_ATTRIB_RO(_name) \
596 DEF_DEV_ATTRIB_SHOW(_name);
598 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib
, se_dev_attrib
);
599 #define SE_DEV_ATTR(_name, _mode) \
600 static struct target_core_dev_attrib_attribute \
601 target_core_dev_attrib_##_name = \
602 __CONFIGFS_EATTR(_name, _mode, \
603 target_core_dev_show_attr_##_name, \
604 target_core_dev_store_attr_##_name);
606 #define SE_DEV_ATTR_RO(_name); \
607 static struct target_core_dev_attrib_attribute \
608 target_core_dev_attrib_##_name = \
609 __CONFIGFS_EATTR_RO(_name, \
610 target_core_dev_show_attr_##_name);
612 DEF_DEV_ATTRIB(emulate_dpo
);
613 SE_DEV_ATTR(emulate_dpo
, S_IRUGO
| S_IWUSR
);
615 DEF_DEV_ATTRIB(emulate_fua_write
);
616 SE_DEV_ATTR(emulate_fua_write
, S_IRUGO
| S_IWUSR
);
618 DEF_DEV_ATTRIB(emulate_fua_read
);
619 SE_DEV_ATTR(emulate_fua_read
, S_IRUGO
| S_IWUSR
);
621 DEF_DEV_ATTRIB(emulate_write_cache
);
622 SE_DEV_ATTR(emulate_write_cache
, S_IRUGO
| S_IWUSR
);
624 DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl
);
625 SE_DEV_ATTR(emulate_ua_intlck_ctrl
, S_IRUGO
| S_IWUSR
);
627 DEF_DEV_ATTRIB(emulate_tas
);
628 SE_DEV_ATTR(emulate_tas
, S_IRUGO
| S_IWUSR
);
630 DEF_DEV_ATTRIB(emulate_tpu
);
631 SE_DEV_ATTR(emulate_tpu
, S_IRUGO
| S_IWUSR
);
633 DEF_DEV_ATTRIB(emulate_tpws
);
634 SE_DEV_ATTR(emulate_tpws
, S_IRUGO
| S_IWUSR
);
636 DEF_DEV_ATTRIB(enforce_pr_isids
);
637 SE_DEV_ATTR(enforce_pr_isids
, S_IRUGO
| S_IWUSR
);
639 DEF_DEV_ATTRIB(is_nonrot
);
640 SE_DEV_ATTR(is_nonrot
, S_IRUGO
| S_IWUSR
);
642 DEF_DEV_ATTRIB(emulate_rest_reord
);
643 SE_DEV_ATTR(emulate_rest_reord
, S_IRUGO
| S_IWUSR
);
645 DEF_DEV_ATTRIB_RO(hw_block_size
);
646 SE_DEV_ATTR_RO(hw_block_size
);
648 DEF_DEV_ATTRIB(block_size
);
649 SE_DEV_ATTR(block_size
, S_IRUGO
| S_IWUSR
);
651 DEF_DEV_ATTRIB_RO(hw_max_sectors
);
652 SE_DEV_ATTR_RO(hw_max_sectors
);
654 DEF_DEV_ATTRIB(fabric_max_sectors
);
655 SE_DEV_ATTR(fabric_max_sectors
, S_IRUGO
| S_IWUSR
);
657 DEF_DEV_ATTRIB(optimal_sectors
);
658 SE_DEV_ATTR(optimal_sectors
, S_IRUGO
| S_IWUSR
);
660 DEF_DEV_ATTRIB_RO(hw_queue_depth
);
661 SE_DEV_ATTR_RO(hw_queue_depth
);
663 DEF_DEV_ATTRIB(queue_depth
);
664 SE_DEV_ATTR(queue_depth
, S_IRUGO
| S_IWUSR
);
666 DEF_DEV_ATTRIB(max_unmap_lba_count
);
667 SE_DEV_ATTR(max_unmap_lba_count
, S_IRUGO
| S_IWUSR
);
669 DEF_DEV_ATTRIB(max_unmap_block_desc_count
);
670 SE_DEV_ATTR(max_unmap_block_desc_count
, S_IRUGO
| S_IWUSR
);
672 DEF_DEV_ATTRIB(unmap_granularity
);
673 SE_DEV_ATTR(unmap_granularity
, S_IRUGO
| S_IWUSR
);
675 DEF_DEV_ATTRIB(unmap_granularity_alignment
);
676 SE_DEV_ATTR(unmap_granularity_alignment
, S_IRUGO
| S_IWUSR
);
678 DEF_DEV_ATTRIB(max_write_same_len
);
679 SE_DEV_ATTR(max_write_same_len
, S_IRUGO
| S_IWUSR
);
681 CONFIGFS_EATTR_OPS(target_core_dev_attrib
, se_dev_attrib
, da_group
);
683 static struct configfs_attribute
*target_core_dev_attrib_attrs
[] = {
684 &target_core_dev_attrib_emulate_dpo
.attr
,
685 &target_core_dev_attrib_emulate_fua_write
.attr
,
686 &target_core_dev_attrib_emulate_fua_read
.attr
,
687 &target_core_dev_attrib_emulate_write_cache
.attr
,
688 &target_core_dev_attrib_emulate_ua_intlck_ctrl
.attr
,
689 &target_core_dev_attrib_emulate_tas
.attr
,
690 &target_core_dev_attrib_emulate_tpu
.attr
,
691 &target_core_dev_attrib_emulate_tpws
.attr
,
692 &target_core_dev_attrib_enforce_pr_isids
.attr
,
693 &target_core_dev_attrib_is_nonrot
.attr
,
694 &target_core_dev_attrib_emulate_rest_reord
.attr
,
695 &target_core_dev_attrib_hw_block_size
.attr
,
696 &target_core_dev_attrib_block_size
.attr
,
697 &target_core_dev_attrib_hw_max_sectors
.attr
,
698 &target_core_dev_attrib_fabric_max_sectors
.attr
,
699 &target_core_dev_attrib_optimal_sectors
.attr
,
700 &target_core_dev_attrib_hw_queue_depth
.attr
,
701 &target_core_dev_attrib_queue_depth
.attr
,
702 &target_core_dev_attrib_max_unmap_lba_count
.attr
,
703 &target_core_dev_attrib_max_unmap_block_desc_count
.attr
,
704 &target_core_dev_attrib_unmap_granularity
.attr
,
705 &target_core_dev_attrib_unmap_granularity_alignment
.attr
,
706 &target_core_dev_attrib_max_write_same_len
.attr
,
710 static struct configfs_item_operations target_core_dev_attrib_ops
= {
711 .show_attribute
= target_core_dev_attrib_attr_show
,
712 .store_attribute
= target_core_dev_attrib_attr_store
,
715 static struct config_item_type target_core_dev_attrib_cit
= {
716 .ct_item_ops
= &target_core_dev_attrib_ops
,
717 .ct_attrs
= target_core_dev_attrib_attrs
,
718 .ct_owner
= THIS_MODULE
,
721 /* End functions for struct config_item_type target_core_dev_attrib_cit */
723 /* Start functions for struct config_item_type target_core_dev_wwn_cit */
725 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn
, t10_wwn
);
726 #define SE_DEV_WWN_ATTR(_name, _mode) \
727 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
728 __CONFIGFS_EATTR(_name, _mode, \
729 target_core_dev_wwn_show_attr_##_name, \
730 target_core_dev_wwn_store_attr_##_name);
732 #define SE_DEV_WWN_ATTR_RO(_name); \
734 static struct target_core_dev_wwn_attribute \
735 target_core_dev_wwn_##_name = \
736 __CONFIGFS_EATTR_RO(_name, \
737 target_core_dev_wwn_show_attr_##_name); \
741 * VPD page 0x80 Unit serial
743 static ssize_t
target_core_dev_wwn_show_attr_vpd_unit_serial(
744 struct t10_wwn
*t10_wwn
,
747 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
748 &t10_wwn
->unit_serial
[0]);
751 static ssize_t
target_core_dev_wwn_store_attr_vpd_unit_serial(
752 struct t10_wwn
*t10_wwn
,
756 struct se_device
*dev
= t10_wwn
->t10_dev
;
757 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
760 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
761 * from the struct scsi_device level firmware, do not allow
762 * VPD Unit Serial to be emulated.
764 * Note this struct scsi_device could also be emulating VPD
765 * information from its drivers/scsi LLD. But for now we assume
766 * it is doing 'the right thing' wrt a world wide unique
767 * VPD Unit Serial Number that OS dependent multipath can depend on.
769 if (dev
->dev_flags
& DF_FIRMWARE_VPD_UNIT_SERIAL
) {
770 pr_err("Underlying SCSI device firmware provided VPD"
771 " Unit Serial, ignoring request\n");
775 if (strlen(page
) >= INQUIRY_VPD_SERIAL_LEN
) {
776 pr_err("Emulated VPD Unit Serial exceeds"
777 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
781 * Check to see if any active $FABRIC_MOD exports exist. If they
782 * do exist, fail here as changing this information on the fly
783 * (underneath the initiator side OS dependent multipath code)
784 * could cause negative effects.
786 if (dev
->export_count
) {
787 pr_err("Unable to set VPD Unit Serial while"
788 " active %d $FABRIC_MOD exports exist\n",
794 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
796 * Also, strip any newline added from the userspace
797 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
799 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
800 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
801 snprintf(dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
802 "%s", strstrip(buf
));
803 dev
->dev_flags
|= DF_EMULATED_VPD_UNIT_SERIAL
;
805 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
806 " %s\n", dev
->t10_wwn
.unit_serial
);
811 SE_DEV_WWN_ATTR(vpd_unit_serial
, S_IRUGO
| S_IWUSR
);
814 * VPD page 0x83 Protocol Identifier
816 static ssize_t
target_core_dev_wwn_show_attr_vpd_protocol_identifier(
817 struct t10_wwn
*t10_wwn
,
821 unsigned char buf
[VPD_TMP_BUF_SIZE
];
824 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
826 spin_lock(&t10_wwn
->t10_vpd_lock
);
827 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
828 if (!vpd
->protocol_identifier_set
)
831 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
833 if (len
+ strlen(buf
) >= PAGE_SIZE
)
836 len
+= sprintf(page
+len
, "%s", buf
);
838 spin_unlock(&t10_wwn
->t10_vpd_lock
);
843 static ssize_t
target_core_dev_wwn_store_attr_vpd_protocol_identifier(
844 struct t10_wwn
*t10_wwn
,
851 SE_DEV_WWN_ATTR(vpd_protocol_identifier
, S_IRUGO
| S_IWUSR
);
854 * Generic wrapper for dumping VPD identifiers by association.
856 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
857 static ssize_t target_core_dev_wwn_show_attr_##_name( \
858 struct t10_wwn *t10_wwn, \
861 struct t10_vpd *vpd; \
862 unsigned char buf[VPD_TMP_BUF_SIZE]; \
865 spin_lock(&t10_wwn->t10_vpd_lock); \
866 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
867 if (vpd->association != _assoc) \
870 memset(buf, 0, VPD_TMP_BUF_SIZE); \
871 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
872 if (len + strlen(buf) >= PAGE_SIZE) \
874 len += sprintf(page+len, "%s", buf); \
876 memset(buf, 0, VPD_TMP_BUF_SIZE); \
877 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
878 if (len + strlen(buf) >= PAGE_SIZE) \
880 len += sprintf(page+len, "%s", buf); \
882 memset(buf, 0, VPD_TMP_BUF_SIZE); \
883 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
884 if (len + strlen(buf) >= PAGE_SIZE) \
886 len += sprintf(page+len, "%s", buf); \
888 spin_unlock(&t10_wwn->t10_vpd_lock); \
894 * VPD page 0x83 Association: Logical Unit
896 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
898 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
899 struct t10_wwn
*t10_wwn
,
906 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit
, S_IRUGO
| S_IWUSR
);
909 * VPD page 0x83 Association: Target Port
911 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
913 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_target_port(
914 struct t10_wwn
*t10_wwn
,
921 SE_DEV_WWN_ATTR(vpd_assoc_target_port
, S_IRUGO
| S_IWUSR
);
924 * VPD page 0x83 Association: SCSI Target Device
926 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
928 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
929 struct t10_wwn
*t10_wwn
,
936 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device
, S_IRUGO
| S_IWUSR
);
938 CONFIGFS_EATTR_OPS(target_core_dev_wwn
, t10_wwn
, t10_wwn_group
);
940 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
941 &target_core_dev_wwn_vpd_unit_serial
.attr
,
942 &target_core_dev_wwn_vpd_protocol_identifier
.attr
,
943 &target_core_dev_wwn_vpd_assoc_logical_unit
.attr
,
944 &target_core_dev_wwn_vpd_assoc_target_port
.attr
,
945 &target_core_dev_wwn_vpd_assoc_scsi_target_device
.attr
,
949 static struct configfs_item_operations target_core_dev_wwn_ops
= {
950 .show_attribute
= target_core_dev_wwn_attr_show
,
951 .store_attribute
= target_core_dev_wwn_attr_store
,
954 static struct config_item_type target_core_dev_wwn_cit
= {
955 .ct_item_ops
= &target_core_dev_wwn_ops
,
956 .ct_attrs
= target_core_dev_wwn_attrs
,
957 .ct_owner
= THIS_MODULE
,
960 /* End functions for struct config_item_type target_core_dev_wwn_cit */
962 /* Start functions for struct config_item_type target_core_dev_pr_cit */
964 CONFIGFS_EATTR_STRUCT(target_core_dev_pr
, se_device
);
965 #define SE_DEV_PR_ATTR(_name, _mode) \
966 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
967 __CONFIGFS_EATTR(_name, _mode, \
968 target_core_dev_pr_show_attr_##_name, \
969 target_core_dev_pr_store_attr_##_name);
971 #define SE_DEV_PR_ATTR_RO(_name); \
972 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
973 __CONFIGFS_EATTR_RO(_name, \
974 target_core_dev_pr_show_attr_##_name);
976 static ssize_t
target_core_dev_pr_show_spc3_res(struct se_device
*dev
,
979 struct se_node_acl
*se_nacl
;
980 struct t10_pr_registration
*pr_reg
;
981 char i_buf
[PR_REG_ISID_ID_LEN
];
984 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
986 pr_reg
= dev
->dev_pr_res_holder
;
988 return sprintf(page
, "No SPC-3 Reservation holder\n");
990 se_nacl
= pr_reg
->pr_reg_nacl
;
991 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
994 return sprintf(page
, "SPC-3 Reservation: %s Initiator: %s%s\n",
995 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
996 se_nacl
->initiatorname
, (prf_isid
) ? &i_buf
[0] : "");
999 static ssize_t
target_core_dev_pr_show_spc2_res(struct se_device
*dev
,
1002 struct se_node_acl
*se_nacl
;
1005 se_nacl
= dev
->dev_reserved_node_acl
;
1008 "SPC-2 Reservation: %s Initiator: %s\n",
1009 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1010 se_nacl
->initiatorname
);
1012 len
= sprintf(page
, "No SPC-2 Reservation holder\n");
1017 static ssize_t
target_core_dev_pr_show_attr_res_holder(struct se_device
*dev
,
1022 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1023 return sprintf(page
, "Passthrough\n");
1025 spin_lock(&dev
->dev_reservation_lock
);
1026 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1027 ret
= target_core_dev_pr_show_spc2_res(dev
, page
);
1029 ret
= target_core_dev_pr_show_spc3_res(dev
, page
);
1030 spin_unlock(&dev
->dev_reservation_lock
);
1034 SE_DEV_PR_ATTR_RO(res_holder
);
1036 static ssize_t
target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1037 struct se_device
*dev
, char *page
)
1041 spin_lock(&dev
->dev_reservation_lock
);
1042 if (!dev
->dev_pr_res_holder
) {
1043 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1044 } else if (dev
->dev_pr_res_holder
->pr_reg_all_tg_pt
) {
1045 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1046 " Ports registration\n");
1048 len
= sprintf(page
, "SPC-3 Reservation: Single"
1049 " Target Port registration\n");
1052 spin_unlock(&dev
->dev_reservation_lock
);
1056 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts
);
1058 static ssize_t
target_core_dev_pr_show_attr_res_pr_generation(
1059 struct se_device
*dev
, char *page
)
1061 return sprintf(page
, "0x%08x\n", dev
->t10_pr
.pr_generation
);
1064 SE_DEV_PR_ATTR_RO(res_pr_generation
);
1067 * res_pr_holder_tg_port
1069 static ssize_t
target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1070 struct se_device
*dev
, char *page
)
1072 struct se_node_acl
*se_nacl
;
1074 struct se_portal_group
*se_tpg
;
1075 struct t10_pr_registration
*pr_reg
;
1076 struct target_core_fabric_ops
*tfo
;
1079 spin_lock(&dev
->dev_reservation_lock
);
1080 pr_reg
= dev
->dev_pr_res_holder
;
1082 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1086 se_nacl
= pr_reg
->pr_reg_nacl
;
1087 se_tpg
= se_nacl
->se_tpg
;
1088 lun
= pr_reg
->pr_reg_tg_pt_lun
;
1089 tfo
= se_tpg
->se_tpg_tfo
;
1091 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1092 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1093 tfo
->tpg_get_wwn(se_tpg
));
1094 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1095 " Identifier Tag: %hu %s Portal Group Tag: %hu"
1096 " %s Logical Unit: %u\n", lun
->lun_sep
->sep_rtpi
,
1097 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1098 tfo
->get_fabric_name(), lun
->unpacked_lun
);
1101 spin_unlock(&dev
->dev_reservation_lock
);
1105 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port
);
1107 static ssize_t
target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1108 struct se_device
*dev
, char *page
)
1110 struct target_core_fabric_ops
*tfo
;
1111 struct t10_pr_registration
*pr_reg
;
1112 unsigned char buf
[384];
1113 char i_buf
[PR_REG_ISID_ID_LEN
];
1115 int reg_count
= 0, prf_isid
;
1117 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1119 spin_lock(&dev
->t10_pr
.registration_lock
);
1120 list_for_each_entry(pr_reg
, &dev
->t10_pr
.registration_list
,
1123 memset(buf
, 0, 384);
1124 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1125 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1126 prf_isid
= core_pr_dump_initiator_port(pr_reg
, &i_buf
[0],
1127 PR_REG_ISID_ID_LEN
);
1128 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1129 tfo
->get_fabric_name(),
1130 pr_reg
->pr_reg_nacl
->initiatorname
, (prf_isid
) ?
1131 &i_buf
[0] : "", pr_reg
->pr_res_key
,
1132 pr_reg
->pr_res_generation
);
1134 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1137 len
+= sprintf(page
+len
, "%s", buf
);
1140 spin_unlock(&dev
->t10_pr
.registration_lock
);
1143 len
+= sprintf(page
+len
, "None\n");
1148 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts
);
1150 static ssize_t
target_core_dev_pr_show_attr_res_pr_type(
1151 struct se_device
*dev
, char *page
)
1153 struct t10_pr_registration
*pr_reg
;
1156 spin_lock(&dev
->dev_reservation_lock
);
1157 pr_reg
= dev
->dev_pr_res_holder
;
1159 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1160 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1162 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1165 spin_unlock(&dev
->dev_reservation_lock
);
1169 SE_DEV_PR_ATTR_RO(res_pr_type
);
1171 static ssize_t
target_core_dev_pr_show_attr_res_type(
1172 struct se_device
*dev
, char *page
)
1174 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1175 return sprintf(page
, "SPC_PASSTHROUGH\n");
1176 else if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1177 return sprintf(page
, "SPC2_RESERVATIONS\n");
1179 return sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1182 SE_DEV_PR_ATTR_RO(res_type
);
1184 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_active(
1185 struct se_device
*dev
, char *page
)
1187 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1190 return sprintf(page
, "APTPL Bit Status: %s\n",
1191 (dev
->t10_pr
.pr_aptpl_active
) ? "Activated" : "Disabled");
1194 SE_DEV_PR_ATTR_RO(res_aptpl_active
);
1197 * res_aptpl_metadata
1199 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_metadata(
1200 struct se_device
*dev
, char *page
)
1202 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1205 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1209 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1210 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1211 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1212 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1215 static match_table_t tokens
= {
1216 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1217 {Opt_initiator_node
, "initiator_node=%s"},
1218 {Opt_initiator_sid
, "initiator_sid=%s"},
1219 {Opt_sa_res_key
, "sa_res_key=%s"},
1220 {Opt_res_holder
, "res_holder=%d"},
1221 {Opt_res_type
, "res_type=%d"},
1222 {Opt_res_scope
, "res_scope=%d"},
1223 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1224 {Opt_mapped_lun
, "mapped_lun=%d"},
1225 {Opt_target_fabric
, "target_fabric=%s"},
1226 {Opt_target_node
, "target_node=%s"},
1227 {Opt_tpgt
, "tpgt=%d"},
1228 {Opt_port_rtpi
, "port_rtpi=%d"},
1229 {Opt_target_lun
, "target_lun=%d"},
1233 static ssize_t
target_core_dev_pr_store_attr_res_aptpl_metadata(
1234 struct se_device
*dev
,
1238 unsigned char *i_fabric
= NULL
, *i_port
= NULL
, *isid
= NULL
;
1239 unsigned char *t_fabric
= NULL
, *t_port
= NULL
;
1240 char *orig
, *ptr
, *arg_p
, *opts
;
1241 substring_t args
[MAX_OPT_ARGS
];
1242 unsigned long long tmp_ll
;
1244 u32 mapped_lun
= 0, target_lun
= 0;
1245 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1246 u16 port_rpti
= 0, tpgt
= 0;
1249 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1251 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1254 if (dev
->export_count
) {
1255 pr_debug("Unable to process APTPL metadata while"
1256 " active fabric exports exist\n");
1260 opts
= kstrdup(page
, GFP_KERNEL
);
1265 while ((ptr
= strsep(&opts
, ",\n")) != NULL
) {
1269 token
= match_token(ptr
, tokens
, args
);
1271 case Opt_initiator_fabric
:
1272 i_fabric
= match_strdup(&args
[0]);
1278 case Opt_initiator_node
:
1279 i_port
= match_strdup(&args
[0]);
1284 if (strlen(i_port
) >= PR_APTPL_MAX_IPORT_LEN
) {
1285 pr_err("APTPL metadata initiator_node="
1286 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1287 PR_APTPL_MAX_IPORT_LEN
);
1292 case Opt_initiator_sid
:
1293 isid
= match_strdup(&args
[0]);
1298 if (strlen(isid
) >= PR_REG_ISID_LEN
) {
1299 pr_err("APTPL metadata initiator_isid"
1300 "= exceeds PR_REG_ISID_LEN: %d\n",
1306 case Opt_sa_res_key
:
1307 arg_p
= match_strdup(&args
[0]);
1312 ret
= strict_strtoull(arg_p
, 0, &tmp_ll
);
1314 pr_err("strict_strtoull() failed for"
1318 sa_res_key
= (u64
)tmp_ll
;
1321 * PR APTPL Metadata for Reservation
1323 case Opt_res_holder
:
1324 match_int(args
, &arg
);
1328 match_int(args
, &arg
);
1332 match_int(args
, &arg
);
1335 case Opt_res_all_tg_pt
:
1336 match_int(args
, &arg
);
1337 all_tg_pt
= (int)arg
;
1339 case Opt_mapped_lun
:
1340 match_int(args
, &arg
);
1341 mapped_lun
= (u32
)arg
;
1344 * PR APTPL Metadata for Target Port
1346 case Opt_target_fabric
:
1347 t_fabric
= match_strdup(&args
[0]);
1353 case Opt_target_node
:
1354 t_port
= match_strdup(&args
[0]);
1359 if (strlen(t_port
) >= PR_APTPL_MAX_TPORT_LEN
) {
1360 pr_err("APTPL metadata target_node="
1361 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1362 PR_APTPL_MAX_TPORT_LEN
);
1368 match_int(args
, &arg
);
1372 match_int(args
, &arg
);
1373 port_rpti
= (u16
)arg
;
1375 case Opt_target_lun
:
1376 match_int(args
, &arg
);
1377 target_lun
= (u32
)arg
;
1384 if (!i_port
|| !t_port
|| !sa_res_key
) {
1385 pr_err("Illegal parameters for APTPL registration\n");
1390 if (res_holder
&& !(type
)) {
1391 pr_err("Illegal PR type: 0x%02x for reservation"
1397 ret
= core_scsi3_alloc_aptpl_registration(&dev
->t10_pr
, sa_res_key
,
1398 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1399 res_holder
, all_tg_pt
, type
);
1407 return (ret
== 0) ? count
: ret
;
1410 SE_DEV_PR_ATTR(res_aptpl_metadata
, S_IRUGO
| S_IWUSR
);
1412 CONFIGFS_EATTR_OPS(target_core_dev_pr
, se_device
, dev_pr_group
);
1414 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1415 &target_core_dev_pr_res_holder
.attr
,
1416 &target_core_dev_pr_res_pr_all_tgt_pts
.attr
,
1417 &target_core_dev_pr_res_pr_generation
.attr
,
1418 &target_core_dev_pr_res_pr_holder_tg_port
.attr
,
1419 &target_core_dev_pr_res_pr_registered_i_pts
.attr
,
1420 &target_core_dev_pr_res_pr_type
.attr
,
1421 &target_core_dev_pr_res_type
.attr
,
1422 &target_core_dev_pr_res_aptpl_active
.attr
,
1423 &target_core_dev_pr_res_aptpl_metadata
.attr
,
1427 static struct configfs_item_operations target_core_dev_pr_ops
= {
1428 .show_attribute
= target_core_dev_pr_attr_show
,
1429 .store_attribute
= target_core_dev_pr_attr_store
,
1432 static struct config_item_type target_core_dev_pr_cit
= {
1433 .ct_item_ops
= &target_core_dev_pr_ops
,
1434 .ct_attrs
= target_core_dev_pr_attrs
,
1435 .ct_owner
= THIS_MODULE
,
1438 /* End functions for struct config_item_type target_core_dev_pr_cit */
1440 /* Start functions for struct config_item_type target_core_dev_cit */
1442 static ssize_t
target_core_show_dev_info(void *p
, char *page
)
1444 struct se_device
*dev
= p
;
1445 struct se_subsystem_api
*t
= dev
->transport
;
1447 ssize_t read_bytes
= 0;
1449 transport_dump_dev_state(dev
, page
, &bl
);
1451 read_bytes
+= t
->show_configfs_dev_params(dev
, page
+read_bytes
);
1455 static struct target_core_configfs_attribute target_core_attr_dev_info
= {
1456 .attr
= { .ca_owner
= THIS_MODULE
,
1458 .ca_mode
= S_IRUGO
},
1459 .show
= target_core_show_dev_info
,
1463 static ssize_t
target_core_store_dev_control(
1468 struct se_device
*dev
= p
;
1469 struct se_subsystem_api
*t
= dev
->transport
;
1471 return t
->set_configfs_dev_params(dev
, page
, count
);
1474 static struct target_core_configfs_attribute target_core_attr_dev_control
= {
1475 .attr
= { .ca_owner
= THIS_MODULE
,
1476 .ca_name
= "control",
1477 .ca_mode
= S_IWUSR
},
1479 .store
= target_core_store_dev_control
,
1482 static ssize_t
target_core_show_dev_alias(void *p
, char *page
)
1484 struct se_device
*dev
= p
;
1486 if (!(dev
->dev_flags
& DF_USING_ALIAS
))
1489 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->dev_alias
);
1492 static ssize_t
target_core_store_dev_alias(
1497 struct se_device
*dev
= p
;
1498 struct se_hba
*hba
= dev
->se_hba
;
1501 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1502 pr_err("alias count: %d exceeds"
1503 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1504 SE_DEV_ALIAS_LEN
-1);
1508 read_bytes
= snprintf(&dev
->dev_alias
[0], SE_DEV_ALIAS_LEN
, "%s", page
);
1511 if (dev
->dev_alias
[read_bytes
- 1] == '\n')
1512 dev
->dev_alias
[read_bytes
- 1] = '\0';
1514 dev
->dev_flags
|= DF_USING_ALIAS
;
1516 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
1517 config_item_name(&hba
->hba_group
.cg_item
),
1518 config_item_name(&dev
->dev_group
.cg_item
),
1524 static struct target_core_configfs_attribute target_core_attr_dev_alias
= {
1525 .attr
= { .ca_owner
= THIS_MODULE
,
1527 .ca_mode
= S_IRUGO
| S_IWUSR
},
1528 .show
= target_core_show_dev_alias
,
1529 .store
= target_core_store_dev_alias
,
1532 static ssize_t
target_core_show_dev_udev_path(void *p
, char *page
)
1534 struct se_device
*dev
= p
;
1536 if (!(dev
->dev_flags
& DF_USING_UDEV_PATH
))
1539 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->udev_path
);
1542 static ssize_t
target_core_store_dev_udev_path(
1547 struct se_device
*dev
= p
;
1548 struct se_hba
*hba
= dev
->se_hba
;
1551 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1552 pr_err("udev_path count: %d exceeds"
1553 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1554 SE_UDEV_PATH_LEN
-1);
1558 read_bytes
= snprintf(&dev
->udev_path
[0], SE_UDEV_PATH_LEN
,
1562 if (dev
->udev_path
[read_bytes
- 1] == '\n')
1563 dev
->udev_path
[read_bytes
- 1] = '\0';
1565 dev
->dev_flags
|= DF_USING_UDEV_PATH
;
1567 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1568 config_item_name(&hba
->hba_group
.cg_item
),
1569 config_item_name(&dev
->dev_group
.cg_item
),
1575 static struct target_core_configfs_attribute target_core_attr_dev_udev_path
= {
1576 .attr
= { .ca_owner
= THIS_MODULE
,
1577 .ca_name
= "udev_path",
1578 .ca_mode
= S_IRUGO
| S_IWUSR
},
1579 .show
= target_core_show_dev_udev_path
,
1580 .store
= target_core_store_dev_udev_path
,
1583 static ssize_t
target_core_store_dev_enable(
1588 struct se_device
*dev
= p
;
1592 ptr
= strstr(page
, "1");
1594 pr_err("For dev_enable ops, only valid value"
1599 ret
= target_configure_device(dev
);
1605 static struct target_core_configfs_attribute target_core_attr_dev_enable
= {
1606 .attr
= { .ca_owner
= THIS_MODULE
,
1607 .ca_name
= "enable",
1608 .ca_mode
= S_IWUSR
},
1610 .store
= target_core_store_dev_enable
,
1613 static ssize_t
target_core_show_alua_lu_gp(void *p
, char *page
)
1615 struct se_device
*dev
= p
;
1616 struct config_item
*lu_ci
;
1617 struct t10_alua_lu_gp
*lu_gp
;
1618 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1621 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1625 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1626 lu_gp
= lu_gp_mem
->lu_gp
;
1628 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1629 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1630 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1632 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1637 static ssize_t
target_core_store_alua_lu_gp(
1642 struct se_device
*dev
= p
;
1643 struct se_hba
*hba
= dev
->se_hba
;
1644 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1645 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1646 unsigned char buf
[LU_GROUP_NAME_BUF
];
1649 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1653 if (count
> LU_GROUP_NAME_BUF
) {
1654 pr_err("ALUA LU Group Alias too large!\n");
1657 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1658 memcpy(buf
, page
, count
);
1660 * Any ALUA logical unit alias besides "NULL" means we will be
1661 * making a new group association.
1663 if (strcmp(strstrip(buf
), "NULL")) {
1665 * core_alua_get_lu_gp_by_name() will increment reference to
1666 * struct t10_alua_lu_gp. This reference is released with
1667 * core_alua_get_lu_gp_by_name below().
1669 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
1674 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1675 lu_gp
= lu_gp_mem
->lu_gp
;
1678 * Clearing an existing lu_gp association, and replacing
1682 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
1683 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1685 config_item_name(&hba
->hba_group
.cg_item
),
1686 config_item_name(&dev
->dev_group
.cg_item
),
1687 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1690 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1691 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1696 * Removing existing association of lu_gp_mem with lu_gp
1698 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1702 * Associate lu_gp_mem with lu_gp_new.
1704 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
1705 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1707 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1708 " core/alua/lu_gps/%s, ID: %hu\n",
1709 (move
) ? "Moving" : "Adding",
1710 config_item_name(&hba
->hba_group
.cg_item
),
1711 config_item_name(&dev
->dev_group
.cg_item
),
1712 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
1713 lu_gp_new
->lu_gp_id
);
1715 core_alua_put_lu_gp_from_name(lu_gp_new
);
1719 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp
= {
1720 .attr
= { .ca_owner
= THIS_MODULE
,
1721 .ca_name
= "alua_lu_gp",
1722 .ca_mode
= S_IRUGO
| S_IWUSR
},
1723 .show
= target_core_show_alua_lu_gp
,
1724 .store
= target_core_store_alua_lu_gp
,
1727 static struct configfs_attribute
*lio_core_dev_attrs
[] = {
1728 &target_core_attr_dev_info
.attr
,
1729 &target_core_attr_dev_control
.attr
,
1730 &target_core_attr_dev_alias
.attr
,
1731 &target_core_attr_dev_udev_path
.attr
,
1732 &target_core_attr_dev_enable
.attr
,
1733 &target_core_attr_dev_alua_lu_gp
.attr
,
1737 static void target_core_dev_release(struct config_item
*item
)
1739 struct config_group
*dev_cg
= to_config_group(item
);
1740 struct se_device
*dev
=
1741 container_of(dev_cg
, struct se_device
, dev_group
);
1743 kfree(dev_cg
->default_groups
);
1744 target_free_device(dev
);
1747 static ssize_t
target_core_dev_show(struct config_item
*item
,
1748 struct configfs_attribute
*attr
,
1751 struct config_group
*dev_cg
= to_config_group(item
);
1752 struct se_device
*dev
=
1753 container_of(dev_cg
, struct se_device
, dev_group
);
1754 struct target_core_configfs_attribute
*tc_attr
= container_of(
1755 attr
, struct target_core_configfs_attribute
, attr
);
1760 return tc_attr
->show(dev
, page
);
1763 static ssize_t
target_core_dev_store(struct config_item
*item
,
1764 struct configfs_attribute
*attr
,
1765 const char *page
, size_t count
)
1767 struct config_group
*dev_cg
= to_config_group(item
);
1768 struct se_device
*dev
=
1769 container_of(dev_cg
, struct se_device
, dev_group
);
1770 struct target_core_configfs_attribute
*tc_attr
= container_of(
1771 attr
, struct target_core_configfs_attribute
, attr
);
1773 if (!tc_attr
->store
)
1776 return tc_attr
->store(dev
, page
, count
);
1779 static struct configfs_item_operations target_core_dev_item_ops
= {
1780 .release
= target_core_dev_release
,
1781 .show_attribute
= target_core_dev_show
,
1782 .store_attribute
= target_core_dev_store
,
1785 static struct config_item_type target_core_dev_cit
= {
1786 .ct_item_ops
= &target_core_dev_item_ops
,
1787 .ct_attrs
= lio_core_dev_attrs
,
1788 .ct_owner
= THIS_MODULE
,
1791 /* End functions for struct config_item_type target_core_dev_cit */
1793 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
1795 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp
, t10_alua_lu_gp
);
1796 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
1797 static struct target_core_alua_lu_gp_attribute \
1798 target_core_alua_lu_gp_##_name = \
1799 __CONFIGFS_EATTR(_name, _mode, \
1800 target_core_alua_lu_gp_show_attr_##_name, \
1801 target_core_alua_lu_gp_store_attr_##_name);
1803 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
1804 static struct target_core_alua_lu_gp_attribute \
1805 target_core_alua_lu_gp_##_name = \
1806 __CONFIGFS_EATTR_RO(_name, \
1807 target_core_alua_lu_gp_show_attr_##_name);
1812 static ssize_t
target_core_alua_lu_gp_show_attr_lu_gp_id(
1813 struct t10_alua_lu_gp
*lu_gp
,
1816 if (!lu_gp
->lu_gp_valid_id
)
1819 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
1822 static ssize_t
target_core_alua_lu_gp_store_attr_lu_gp_id(
1823 struct t10_alua_lu_gp
*lu_gp
,
1827 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
1828 unsigned long lu_gp_id
;
1831 ret
= strict_strtoul(page
, 0, &lu_gp_id
);
1833 pr_err("strict_strtoul() returned %d for"
1834 " lu_gp_id\n", ret
);
1837 if (lu_gp_id
> 0x0000ffff) {
1838 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
1839 " 0x0000ffff\n", lu_gp_id
);
1843 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
1847 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
1848 " Group: core/alua/lu_gps/%s to ID: %hu\n",
1849 config_item_name(&alua_lu_gp_cg
->cg_item
),
1855 SE_DEV_ALUA_LU_ATTR(lu_gp_id
, S_IRUGO
| S_IWUSR
);
1860 static ssize_t
target_core_alua_lu_gp_show_attr_members(
1861 struct t10_alua_lu_gp
*lu_gp
,
1864 struct se_device
*dev
;
1866 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1867 ssize_t len
= 0, cur_len
;
1868 unsigned char buf
[LU_GROUP_NAME_BUF
];
1870 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1872 spin_lock(&lu_gp
->lu_gp_lock
);
1873 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
1874 dev
= lu_gp_mem
->lu_gp_mem_dev
;
1877 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
1878 config_item_name(&hba
->hba_group
.cg_item
),
1879 config_item_name(&dev
->dev_group
.cg_item
));
1880 cur_len
++; /* Extra byte for NULL terminator */
1882 if ((cur_len
+ len
) > PAGE_SIZE
) {
1883 pr_warn("Ran out of lu_gp_show_attr"
1884 "_members buffer\n");
1887 memcpy(page
+len
, buf
, cur_len
);
1890 spin_unlock(&lu_gp
->lu_gp_lock
);
1895 SE_DEV_ALUA_LU_ATTR_RO(members
);
1897 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp
, t10_alua_lu_gp
, lu_gp_group
);
1899 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
1900 &target_core_alua_lu_gp_lu_gp_id
.attr
,
1901 &target_core_alua_lu_gp_members
.attr
,
1905 static void target_core_alua_lu_gp_release(struct config_item
*item
)
1907 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
1908 struct t10_alua_lu_gp
, lu_gp_group
);
1910 core_alua_free_lu_gp(lu_gp
);
1913 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
1914 .release
= target_core_alua_lu_gp_release
,
1915 .show_attribute
= target_core_alua_lu_gp_attr_show
,
1916 .store_attribute
= target_core_alua_lu_gp_attr_store
,
1919 static struct config_item_type target_core_alua_lu_gp_cit
= {
1920 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
1921 .ct_attrs
= target_core_alua_lu_gp_attrs
,
1922 .ct_owner
= THIS_MODULE
,
1925 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
1927 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
1929 static struct config_group
*target_core_alua_create_lu_gp(
1930 struct config_group
*group
,
1933 struct t10_alua_lu_gp
*lu_gp
;
1934 struct config_group
*alua_lu_gp_cg
= NULL
;
1935 struct config_item
*alua_lu_gp_ci
= NULL
;
1937 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
1941 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
1942 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
1944 config_group_init_type_name(alua_lu_gp_cg
, name
,
1945 &target_core_alua_lu_gp_cit
);
1947 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
1948 " Group: core/alua/lu_gps/%s\n",
1949 config_item_name(alua_lu_gp_ci
));
1951 return alua_lu_gp_cg
;
1955 static void target_core_alua_drop_lu_gp(
1956 struct config_group
*group
,
1957 struct config_item
*item
)
1959 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
1960 struct t10_alua_lu_gp
, lu_gp_group
);
1962 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
1963 " Group: core/alua/lu_gps/%s, ID: %hu\n",
1964 config_item_name(item
), lu_gp
->lu_gp_id
);
1966 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
1967 * -> target_core_alua_lu_gp_release()
1969 config_item_put(item
);
1972 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
1973 .make_group
= &target_core_alua_create_lu_gp
,
1974 .drop_item
= &target_core_alua_drop_lu_gp
,
1977 static struct config_item_type target_core_alua_lu_gps_cit
= {
1978 .ct_item_ops
= NULL
,
1979 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
1980 .ct_owner
= THIS_MODULE
,
1983 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
1985 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
1987 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
);
1988 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
1989 static struct target_core_alua_tg_pt_gp_attribute \
1990 target_core_alua_tg_pt_gp_##_name = \
1991 __CONFIGFS_EATTR(_name, _mode, \
1992 target_core_alua_tg_pt_gp_show_attr_##_name, \
1993 target_core_alua_tg_pt_gp_store_attr_##_name);
1995 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
1996 static struct target_core_alua_tg_pt_gp_attribute \
1997 target_core_alua_tg_pt_gp_##_name = \
1998 __CONFIGFS_EATTR_RO(_name, \
1999 target_core_alua_tg_pt_gp_show_attr_##_name);
2004 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2005 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2008 return sprintf(page
, "%d\n",
2009 atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
));
2012 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2013 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2017 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
2021 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2022 pr_err("Unable to do implict ALUA on non valid"
2023 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2027 ret
= strict_strtoul(page
, 0, &tmp
);
2029 pr_err("Unable to extract new ALUA access state from"
2033 new_state
= (int)tmp
;
2035 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICT_ALUA
)) {
2036 pr_err("Unable to process implict configfs ALUA"
2037 " transition while TPGS_IMPLICT_ALUA is disabled\n");
2041 ret
= core_alua_do_port_transition(tg_pt_gp
, dev
,
2042 NULL
, NULL
, new_state
, 0);
2043 return (!ret
) ? count
: -EINVAL
;
2046 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state
, S_IRUGO
| S_IWUSR
);
2049 * alua_access_status
2051 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2052 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2055 return sprintf(page
, "%s\n",
2056 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2059 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2060 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2065 int new_status
, ret
;
2067 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2068 pr_err("Unable to do set ALUA access status on non"
2069 " valid tg_pt_gp ID: %hu\n",
2070 tg_pt_gp
->tg_pt_gp_valid_id
);
2074 ret
= strict_strtoul(page
, 0, &tmp
);
2076 pr_err("Unable to extract new ALUA access status"
2077 " from %s\n", page
);
2080 new_status
= (int)tmp
;
2082 if ((new_status
!= ALUA_STATUS_NONE
) &&
2083 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICT_STPG
) &&
2084 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA
)) {
2085 pr_err("Illegal ALUA access status: 0x%02x\n",
2090 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2094 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status
, S_IRUGO
| S_IWUSR
);
2099 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2100 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2103 return core_alua_show_access_type(tg_pt_gp
, page
);
2106 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2107 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2111 return core_alua_store_access_type(tg_pt_gp
, page
, count
);
2114 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type
, S_IRUGO
| S_IWUSR
);
2117 * alua_write_metadata
2119 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2120 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2123 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_write_metadata
);
2126 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2127 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2134 ret
= strict_strtoul(page
, 0, &tmp
);
2136 pr_err("Unable to extract alua_write_metadata\n");
2140 if ((tmp
!= 0) && (tmp
!= 1)) {
2141 pr_err("Illegal value for alua_write_metadata:"
2145 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2150 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata
, S_IRUGO
| S_IWUSR
);
2157 static ssize_t
target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2158 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2161 return core_alua_show_nonop_delay_msecs(tg_pt_gp
, page
);
2165 static ssize_t
target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2166 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2170 return core_alua_store_nonop_delay_msecs(tg_pt_gp
, page
, count
);
2173 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs
, S_IRUGO
| S_IWUSR
);
2178 static ssize_t
target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2179 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2182 return core_alua_show_trans_delay_msecs(tg_pt_gp
, page
);
2185 static ssize_t
target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2186 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2190 return core_alua_store_trans_delay_msecs(tg_pt_gp
, page
, count
);
2193 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs
, S_IRUGO
| S_IWUSR
);
2196 * implict_trans_secs
2198 static ssize_t
target_core_alua_tg_pt_gp_show_attr_implict_trans_secs(
2199 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2202 return core_alua_show_implict_trans_secs(tg_pt_gp
, page
);
2205 static ssize_t
target_core_alua_tg_pt_gp_store_attr_implict_trans_secs(
2206 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2210 return core_alua_store_implict_trans_secs(tg_pt_gp
, page
, count
);
2213 SE_DEV_ALUA_TG_PT_ATTR(implict_trans_secs
, S_IRUGO
| S_IWUSR
);
2219 static ssize_t
target_core_alua_tg_pt_gp_show_attr_preferred(
2220 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2223 return core_alua_show_preferred_bit(tg_pt_gp
, page
);
2226 static ssize_t
target_core_alua_tg_pt_gp_store_attr_preferred(
2227 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2231 return core_alua_store_preferred_bit(tg_pt_gp
, page
, count
);
2234 SE_DEV_ALUA_TG_PT_ATTR(preferred
, S_IRUGO
| S_IWUSR
);
2239 static ssize_t
target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2240 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2243 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
2246 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2249 static ssize_t
target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2250 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2254 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2255 unsigned long tg_pt_gp_id
;
2258 ret
= strict_strtoul(page
, 0, &tg_pt_gp_id
);
2260 pr_err("strict_strtoul() returned %d for"
2261 " tg_pt_gp_id\n", ret
);
2264 if (tg_pt_gp_id
> 0x0000ffff) {
2265 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:"
2266 " 0x0000ffff\n", tg_pt_gp_id
);
2270 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2274 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
2275 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2276 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2277 tg_pt_gp
->tg_pt_gp_id
);
2282 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id
, S_IRUGO
| S_IWUSR
);
2287 static ssize_t
target_core_alua_tg_pt_gp_show_attr_members(
2288 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2291 struct se_port
*port
;
2292 struct se_portal_group
*tpg
;
2294 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
2295 ssize_t len
= 0, cur_len
;
2296 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2298 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2300 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2301 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
2302 tg_pt_gp_mem_list
) {
2303 port
= tg_pt_gp_mem
->tg_pt
;
2304 tpg
= port
->sep_tpg
;
2305 lun
= port
->sep_lun
;
2307 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2308 "/%s\n", tpg
->se_tpg_tfo
->get_fabric_name(),
2309 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
2310 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
2311 config_item_name(&lun
->lun_group
.cg_item
));
2312 cur_len
++; /* Extra byte for NULL terminator */
2314 if ((cur_len
+ len
) > PAGE_SIZE
) {
2315 pr_warn("Ran out of lu_gp_show_attr"
2316 "_members buffer\n");
2319 memcpy(page
+len
, buf
, cur_len
);
2322 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2327 SE_DEV_ALUA_TG_PT_ATTR_RO(members
);
2329 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
,
2332 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2333 &target_core_alua_tg_pt_gp_alua_access_state
.attr
,
2334 &target_core_alua_tg_pt_gp_alua_access_status
.attr
,
2335 &target_core_alua_tg_pt_gp_alua_access_type
.attr
,
2336 &target_core_alua_tg_pt_gp_alua_write_metadata
.attr
,
2337 &target_core_alua_tg_pt_gp_nonop_delay_msecs
.attr
,
2338 &target_core_alua_tg_pt_gp_trans_delay_msecs
.attr
,
2339 &target_core_alua_tg_pt_gp_implict_trans_secs
.attr
,
2340 &target_core_alua_tg_pt_gp_preferred
.attr
,
2341 &target_core_alua_tg_pt_gp_tg_pt_gp_id
.attr
,
2342 &target_core_alua_tg_pt_gp_members
.attr
,
2346 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2348 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2349 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2351 core_alua_free_tg_pt_gp(tg_pt_gp
);
2354 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2355 .release
= target_core_alua_tg_pt_gp_release
,
2356 .show_attribute
= target_core_alua_tg_pt_gp_attr_show
,
2357 .store_attribute
= target_core_alua_tg_pt_gp_attr_store
,
2360 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2361 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2362 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2363 .ct_owner
= THIS_MODULE
,
2366 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2368 /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2370 static struct config_group
*target_core_alua_create_tg_pt_gp(
2371 struct config_group
*group
,
2374 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2375 alua_tg_pt_gps_group
);
2376 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2377 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2378 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2380 tg_pt_gp
= core_alua_allocate_tg_pt_gp(alua
->t10_dev
, name
, 0);
2384 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2385 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2387 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2388 &target_core_alua_tg_pt_gp_cit
);
2390 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
2391 " Group: alua/tg_pt_gps/%s\n",
2392 config_item_name(alua_tg_pt_gp_ci
));
2394 return alua_tg_pt_gp_cg
;
2397 static void target_core_alua_drop_tg_pt_gp(
2398 struct config_group
*group
,
2399 struct config_item
*item
)
2401 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2402 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2404 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
2405 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2406 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2408 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2409 * -> target_core_alua_tg_pt_gp_release().
2411 config_item_put(item
);
2414 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2415 .make_group
= &target_core_alua_create_tg_pt_gp
,
2416 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2419 static struct config_item_type target_core_alua_tg_pt_gps_cit
= {
2420 .ct_group_ops
= &target_core_alua_tg_pt_gps_group_ops
,
2421 .ct_owner
= THIS_MODULE
,
2424 /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2426 /* Start functions for struct config_item_type target_core_alua_cit */
2429 * target_core_alua_cit is a ConfigFS group that lives under
2430 * /sys/kernel/config/target/core/alua. There are default groups
2431 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2432 * target_core_alua_cit in target_core_init_configfs() below.
2434 static struct config_item_type target_core_alua_cit
= {
2435 .ct_item_ops
= NULL
,
2437 .ct_owner
= THIS_MODULE
,
2440 /* End functions for struct config_item_type target_core_alua_cit */
2442 /* Start functions for struct config_item_type target_core_stat_cit */
2444 static struct config_group
*target_core_stat_mkdir(
2445 struct config_group
*group
,
2448 return ERR_PTR(-ENOSYS
);
2451 static void target_core_stat_rmdir(
2452 struct config_group
*group
,
2453 struct config_item
*item
)
2458 static struct configfs_group_operations target_core_stat_group_ops
= {
2459 .make_group
= &target_core_stat_mkdir
,
2460 .drop_item
= &target_core_stat_rmdir
,
2463 static struct config_item_type target_core_stat_cit
= {
2464 .ct_group_ops
= &target_core_stat_group_ops
,
2465 .ct_owner
= THIS_MODULE
,
2468 /* End functions for struct config_item_type target_core_stat_cit */
2470 /* Start functions for struct config_item_type target_core_hba_cit */
2472 static struct config_group
*target_core_make_subdev(
2473 struct config_group
*group
,
2476 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2477 struct se_subsystem_api
*t
;
2478 struct config_item
*hba_ci
= &group
->cg_item
;
2479 struct se_hba
*hba
= item_to_hba(hba_ci
);
2480 struct se_device
*dev
;
2481 struct config_group
*dev_cg
= NULL
, *tg_pt_gp_cg
= NULL
;
2482 struct config_group
*dev_stat_grp
= NULL
;
2483 int errno
= -ENOMEM
, ret
;
2485 ret
= mutex_lock_interruptible(&hba
->hba_access_mutex
);
2487 return ERR_PTR(ret
);
2489 * Locate the struct se_subsystem_api from parent's struct se_hba.
2493 dev
= target_alloc_device(hba
, name
);
2497 dev_cg
= &dev
->dev_group
;
2499 dev_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 6,
2501 if (!dev_cg
->default_groups
)
2502 goto out_free_device
;
2504 config_group_init_type_name(dev_cg
, name
, &target_core_dev_cit
);
2505 config_group_init_type_name(&dev
->dev_attrib
.da_group
, "attrib",
2506 &target_core_dev_attrib_cit
);
2507 config_group_init_type_name(&dev
->dev_pr_group
, "pr",
2508 &target_core_dev_pr_cit
);
2509 config_group_init_type_name(&dev
->t10_wwn
.t10_wwn_group
, "wwn",
2510 &target_core_dev_wwn_cit
);
2511 config_group_init_type_name(&dev
->t10_alua
.alua_tg_pt_gps_group
,
2512 "alua", &target_core_alua_tg_pt_gps_cit
);
2513 config_group_init_type_name(&dev
->dev_stat_grps
.stat_group
,
2514 "statistics", &target_core_stat_cit
);
2516 dev_cg
->default_groups
[0] = &dev
->dev_attrib
.da_group
;
2517 dev_cg
->default_groups
[1] = &dev
->dev_pr_group
;
2518 dev_cg
->default_groups
[2] = &dev
->t10_wwn
.t10_wwn_group
;
2519 dev_cg
->default_groups
[3] = &dev
->t10_alua
.alua_tg_pt_gps_group
;
2520 dev_cg
->default_groups
[4] = &dev
->dev_stat_grps
.stat_group
;
2521 dev_cg
->default_groups
[5] = NULL
;
2523 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
2525 tg_pt_gp
= core_alua_allocate_tg_pt_gp(dev
, "default_tg_pt_gp", 1);
2527 goto out_free_dev_cg_default_groups
;
2528 dev
->t10_alua
.default_tg_pt_gp
= tg_pt_gp
;
2530 tg_pt_gp_cg
= &dev
->t10_alua
.alua_tg_pt_gps_group
;
2531 tg_pt_gp_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
2533 if (!tg_pt_gp_cg
->default_groups
) {
2534 pr_err("Unable to allocate tg_pt_gp_cg->"
2535 "default_groups\n");
2536 goto out_free_tg_pt_gp
;
2539 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2540 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2541 tg_pt_gp_cg
->default_groups
[0] = &tg_pt_gp
->tg_pt_gp_group
;
2542 tg_pt_gp_cg
->default_groups
[1] = NULL
;
2544 * Add core/$HBA/$DEV/statistics/ default groups
2546 dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
2547 dev_stat_grp
->default_groups
= kmalloc(sizeof(struct config_group
*) * 4,
2549 if (!dev_stat_grp
->default_groups
) {
2550 pr_err("Unable to allocate dev_stat_grp->default_groups\n");
2551 goto out_free_tg_pt_gp_cg_default_groups
;
2553 target_stat_setup_dev_default_groups(dev
);
2555 mutex_unlock(&hba
->hba_access_mutex
);
2558 out_free_tg_pt_gp_cg_default_groups
:
2559 kfree(tg_pt_gp_cg
->default_groups
);
2561 core_alua_free_tg_pt_gp(tg_pt_gp
);
2562 out_free_dev_cg_default_groups
:
2563 kfree(dev_cg
->default_groups
);
2565 target_free_device(dev
);
2567 mutex_unlock(&hba
->hba_access_mutex
);
2568 return ERR_PTR(errno
);
2571 static void target_core_drop_subdev(
2572 struct config_group
*group
,
2573 struct config_item
*item
)
2575 struct config_group
*dev_cg
= to_config_group(item
);
2576 struct se_device
*dev
=
2577 container_of(dev_cg
, struct se_device
, dev_group
);
2579 struct config_item
*df_item
;
2580 struct config_group
*tg_pt_gp_cg
, *dev_stat_grp
;
2583 hba
= item_to_hba(&dev
->se_hba
->hba_group
.cg_item
);
2585 mutex_lock(&hba
->hba_access_mutex
);
2587 dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
2588 for (i
= 0; dev_stat_grp
->default_groups
[i
]; i
++) {
2589 df_item
= &dev_stat_grp
->default_groups
[i
]->cg_item
;
2590 dev_stat_grp
->default_groups
[i
] = NULL
;
2591 config_item_put(df_item
);
2593 kfree(dev_stat_grp
->default_groups
);
2595 tg_pt_gp_cg
= &dev
->t10_alua
.alua_tg_pt_gps_group
;
2596 for (i
= 0; tg_pt_gp_cg
->default_groups
[i
]; i
++) {
2597 df_item
= &tg_pt_gp_cg
->default_groups
[i
]->cg_item
;
2598 tg_pt_gp_cg
->default_groups
[i
] = NULL
;
2599 config_item_put(df_item
);
2601 kfree(tg_pt_gp_cg
->default_groups
);
2603 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2604 * directly from target_core_alua_tg_pt_gp_release().
2606 dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2608 for (i
= 0; dev_cg
->default_groups
[i
]; i
++) {
2609 df_item
= &dev_cg
->default_groups
[i
]->cg_item
;
2610 dev_cg
->default_groups
[i
] = NULL
;
2611 config_item_put(df_item
);
2614 * se_dev is released from target_core_dev_item_ops->release()
2616 config_item_put(item
);
2617 mutex_unlock(&hba
->hba_access_mutex
);
2620 static struct configfs_group_operations target_core_hba_group_ops
= {
2621 .make_group
= target_core_make_subdev
,
2622 .drop_item
= target_core_drop_subdev
,
2625 CONFIGFS_EATTR_STRUCT(target_core_hba
, se_hba
);
2626 #define SE_HBA_ATTR(_name, _mode) \
2627 static struct target_core_hba_attribute \
2628 target_core_hba_##_name = \
2629 __CONFIGFS_EATTR(_name, _mode, \
2630 target_core_hba_show_attr_##_name, \
2631 target_core_hba_store_attr_##_name);
2633 #define SE_HBA_ATTR_RO(_name) \
2634 static struct target_core_hba_attribute \
2635 target_core_hba_##_name = \
2636 __CONFIGFS_EATTR_RO(_name, \
2637 target_core_hba_show_attr_##_name);
2639 static ssize_t
target_core_hba_show_attr_hba_info(
2643 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
2644 hba
->hba_id
, hba
->transport
->name
,
2645 TARGET_CORE_CONFIGFS_VERSION
);
2648 SE_HBA_ATTR_RO(hba_info
);
2650 static ssize_t
target_core_hba_show_attr_hba_mode(struct se_hba
*hba
,
2655 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
2658 return sprintf(page
, "%d\n", hba_mode
);
2661 static ssize_t
target_core_hba_store_attr_hba_mode(struct se_hba
*hba
,
2662 const char *page
, size_t count
)
2664 struct se_subsystem_api
*transport
= hba
->transport
;
2665 unsigned long mode_flag
;
2668 if (transport
->pmode_enable_hba
== NULL
)
2671 ret
= strict_strtoul(page
, 0, &mode_flag
);
2673 pr_err("Unable to extract hba mode flag: %d\n", ret
);
2677 if (hba
->dev_count
) {
2678 pr_err("Unable to set hba_mode with active devices\n");
2682 ret
= transport
->pmode_enable_hba(hba
, mode_flag
);
2686 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
2688 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
2693 SE_HBA_ATTR(hba_mode
, S_IRUGO
| S_IWUSR
);
2695 CONFIGFS_EATTR_OPS(target_core_hba
, se_hba
, hba_group
);
2697 static void target_core_hba_release(struct config_item
*item
)
2699 struct se_hba
*hba
= container_of(to_config_group(item
),
2700 struct se_hba
, hba_group
);
2701 core_delete_hba(hba
);
2704 static struct configfs_attribute
*target_core_hba_attrs
[] = {
2705 &target_core_hba_hba_info
.attr
,
2706 &target_core_hba_hba_mode
.attr
,
2710 static struct configfs_item_operations target_core_hba_item_ops
= {
2711 .release
= target_core_hba_release
,
2712 .show_attribute
= target_core_hba_attr_show
,
2713 .store_attribute
= target_core_hba_attr_store
,
2716 static struct config_item_type target_core_hba_cit
= {
2717 .ct_item_ops
= &target_core_hba_item_ops
,
2718 .ct_group_ops
= &target_core_hba_group_ops
,
2719 .ct_attrs
= target_core_hba_attrs
,
2720 .ct_owner
= THIS_MODULE
,
2723 static struct config_group
*target_core_call_addhbatotarget(
2724 struct config_group
*group
,
2727 char *se_plugin_str
, *str
, *str2
;
2729 char buf
[TARGET_CORE_NAME_MAX_LEN
];
2730 unsigned long plugin_dep_id
= 0;
2733 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
2734 if (strlen(name
) >= TARGET_CORE_NAME_MAX_LEN
) {
2735 pr_err("Passed *name strlen(): %d exceeds"
2736 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
2737 TARGET_CORE_NAME_MAX_LEN
);
2738 return ERR_PTR(-ENAMETOOLONG
);
2740 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
2742 str
= strstr(buf
, "_");
2744 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
2745 return ERR_PTR(-EINVAL
);
2747 se_plugin_str
= buf
;
2749 * Special case for subsystem plugins that have "_" in their names.
2750 * Namely rd_direct and rd_mcp..
2752 str2
= strstr(str
+1, "_");
2754 *str2
= '\0'; /* Terminate for *se_plugin_str */
2755 str2
++; /* Skip to start of plugin dependent ID */
2758 *str
= '\0'; /* Terminate for *se_plugin_str */
2759 str
++; /* Skip to start of plugin dependent ID */
2762 ret
= strict_strtoul(str
, 0, &plugin_dep_id
);
2764 pr_err("strict_strtoul() returned %d for"
2765 " plugin_dep_id\n", ret
);
2766 return ERR_PTR(-EINVAL
);
2769 * Load up TCM subsystem plugins if they have not already been loaded.
2771 transport_subsystem_check_init();
2773 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
2775 return ERR_CAST(hba
);
2777 config_group_init_type_name(&hba
->hba_group
, name
,
2778 &target_core_hba_cit
);
2780 return &hba
->hba_group
;
2783 static void target_core_call_delhbafromtarget(
2784 struct config_group
*group
,
2785 struct config_item
*item
)
2788 * core_delete_hba() is called from target_core_hba_item_ops->release()
2789 * -> target_core_hba_release()
2791 config_item_put(item
);
2794 static struct configfs_group_operations target_core_group_ops
= {
2795 .make_group
= target_core_call_addhbatotarget
,
2796 .drop_item
= target_core_call_delhbafromtarget
,
2799 static struct config_item_type target_core_cit
= {
2800 .ct_item_ops
= NULL
,
2801 .ct_group_ops
= &target_core_group_ops
,
2803 .ct_owner
= THIS_MODULE
,
2806 /* Stop functions for struct config_item_type target_core_hba_cit */
2808 static int __init
target_core_init_configfs(void)
2810 struct config_group
*target_cg
, *hba_cg
= NULL
, *alua_cg
= NULL
;
2811 struct config_group
*lu_gp_cg
= NULL
;
2812 struct configfs_subsystem
*subsys
;
2813 struct t10_alua_lu_gp
*lu_gp
;
2816 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
2817 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
2818 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
2820 subsys
= target_core_subsystem
[0];
2821 config_group_init(&subsys
->su_group
);
2822 mutex_init(&subsys
->su_mutex
);
2824 ret
= init_se_kmem_caches();
2828 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
2829 * and ALUA Logical Unit Group and Target Port Group infrastructure.
2831 target_cg
= &subsys
->su_group
;
2832 target_cg
->default_groups
= kmalloc(sizeof(struct config_group
) * 2,
2834 if (!target_cg
->default_groups
) {
2835 pr_err("Unable to allocate target_cg->default_groups\n");
2840 config_group_init_type_name(&target_core_hbagroup
,
2841 "core", &target_core_cit
);
2842 target_cg
->default_groups
[0] = &target_core_hbagroup
;
2843 target_cg
->default_groups
[1] = NULL
;
2845 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
2847 hba_cg
= &target_core_hbagroup
;
2848 hba_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
2850 if (!hba_cg
->default_groups
) {
2851 pr_err("Unable to allocate hba_cg->default_groups\n");
2855 config_group_init_type_name(&alua_group
,
2856 "alua", &target_core_alua_cit
);
2857 hba_cg
->default_groups
[0] = &alua_group
;
2858 hba_cg
->default_groups
[1] = NULL
;
2860 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
2861 * groups under /sys/kernel/config/target/core/alua/
2863 alua_cg
= &alua_group
;
2864 alua_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
2866 if (!alua_cg
->default_groups
) {
2867 pr_err("Unable to allocate alua_cg->default_groups\n");
2872 config_group_init_type_name(&alua_lu_gps_group
,
2873 "lu_gps", &target_core_alua_lu_gps_cit
);
2874 alua_cg
->default_groups
[0] = &alua_lu_gps_group
;
2875 alua_cg
->default_groups
[1] = NULL
;
2877 * Add core/alua/lu_gps/default_lu_gp
2879 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
2880 if (IS_ERR(lu_gp
)) {
2885 lu_gp_cg
= &alua_lu_gps_group
;
2886 lu_gp_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
2888 if (!lu_gp_cg
->default_groups
) {
2889 pr_err("Unable to allocate lu_gp_cg->default_groups\n");
2894 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
2895 &target_core_alua_lu_gp_cit
);
2896 lu_gp_cg
->default_groups
[0] = &lu_gp
->lu_gp_group
;
2897 lu_gp_cg
->default_groups
[1] = NULL
;
2898 default_lu_gp
= lu_gp
;
2900 * Register the target_core_mod subsystem with configfs.
2902 ret
= configfs_register_subsystem(subsys
);
2904 pr_err("Error %d while registering subsystem %s\n",
2905 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
2908 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
2909 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION
" on %s/%s"
2910 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
2912 * Register built-in RAMDISK subsystem logic for virtual LUN 0
2914 ret
= rd_module_init();
2918 ret
= core_dev_setup_virtual_lun0();
2925 configfs_unregister_subsystem(subsys
);
2926 core_dev_release_virtual_lun0();
2929 if (default_lu_gp
) {
2930 core_alua_free_lu_gp(default_lu_gp
);
2931 default_lu_gp
= NULL
;
2934 kfree(lu_gp_cg
->default_groups
);
2936 kfree(alua_cg
->default_groups
);
2938 kfree(hba_cg
->default_groups
);
2939 kfree(target_cg
->default_groups
);
2940 release_se_kmem_caches();
2944 static void __exit
target_core_exit_configfs(void)
2946 struct configfs_subsystem
*subsys
;
2947 struct config_group
*hba_cg
, *alua_cg
, *lu_gp_cg
;
2948 struct config_item
*item
;
2951 subsys
= target_core_subsystem
[0];
2953 lu_gp_cg
= &alua_lu_gps_group
;
2954 for (i
= 0; lu_gp_cg
->default_groups
[i
]; i
++) {
2955 item
= &lu_gp_cg
->default_groups
[i
]->cg_item
;
2956 lu_gp_cg
->default_groups
[i
] = NULL
;
2957 config_item_put(item
);
2959 kfree(lu_gp_cg
->default_groups
);
2960 lu_gp_cg
->default_groups
= NULL
;
2962 alua_cg
= &alua_group
;
2963 for (i
= 0; alua_cg
->default_groups
[i
]; i
++) {
2964 item
= &alua_cg
->default_groups
[i
]->cg_item
;
2965 alua_cg
->default_groups
[i
] = NULL
;
2966 config_item_put(item
);
2968 kfree(alua_cg
->default_groups
);
2969 alua_cg
->default_groups
= NULL
;
2971 hba_cg
= &target_core_hbagroup
;
2972 for (i
= 0; hba_cg
->default_groups
[i
]; i
++) {
2973 item
= &hba_cg
->default_groups
[i
]->cg_item
;
2974 hba_cg
->default_groups
[i
] = NULL
;
2975 config_item_put(item
);
2977 kfree(hba_cg
->default_groups
);
2978 hba_cg
->default_groups
= NULL
;
2980 * We expect subsys->su_group.default_groups to be released
2981 * by configfs subsystem provider logic..
2983 configfs_unregister_subsystem(subsys
);
2984 kfree(subsys
->su_group
.default_groups
);
2986 core_alua_free_lu_gp(default_lu_gp
);
2987 default_lu_gp
= NULL
;
2989 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
2990 " Infrastructure\n");
2992 core_dev_release_virtual_lun0();
2994 release_se_kmem_caches();
2997 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
2998 MODULE_AUTHOR("nab@Linux-iSCSI.org");
2999 MODULE_LICENSE("GPL");
3001 module_init(target_core_init_configfs
);
3002 module_exit(target_core_exit_configfs
);