1 /*******************************************************************************
2 * Filename: target_core_configfs.c
4 * This file contains ConfigFS logic for the Generic Target Engine project.
6 * (c) Copyright 2008-2013 Datera, Inc.
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"
51 #include "target_core_xcopy.h"
53 extern struct t10_alua_lu_gp
*default_lu_gp
;
55 static LIST_HEAD(g_tf_list
);
56 static DEFINE_MUTEX(g_tf_lock
);
58 struct target_core_configfs_attribute
{
59 struct configfs_attribute attr
;
60 ssize_t (*show
)(void *, char *);
61 ssize_t (*store
)(void *, const char *, size_t);
64 static struct config_group target_core_hbagroup
;
65 static struct config_group alua_group
;
66 static struct config_group alua_lu_gps_group
;
68 static inline struct se_hba
*
69 item_to_hba(struct config_item
*item
)
71 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
75 * Attributes for /sys/kernel/config/target/
77 static ssize_t
target_core_attr_show(struct config_item
*item
,
78 struct configfs_attribute
*attr
,
81 return sprintf(page
, "Target Engine Core ConfigFS Infrastructure %s"
82 " on %s/%s on "UTS_RELEASE
"\n", TARGET_CORE_CONFIGFS_VERSION
,
83 utsname()->sysname
, utsname()->machine
);
86 static struct configfs_item_operations target_core_fabric_item_ops
= {
87 .show_attribute
= target_core_attr_show
,
90 static struct configfs_attribute target_core_item_attr_version
= {
91 .ca_owner
= THIS_MODULE
,
96 static struct target_fabric_configfs
*target_core_get_fabric(
99 struct target_fabric_configfs
*tf
;
104 mutex_lock(&g_tf_lock
);
105 list_for_each_entry(tf
, &g_tf_list
, tf_list
) {
106 if (!strcmp(tf
->tf_name
, name
)) {
107 atomic_inc(&tf
->tf_access_cnt
);
108 mutex_unlock(&g_tf_lock
);
112 mutex_unlock(&g_tf_lock
);
118 * Called from struct target_core_group_ops->make_group()
120 static struct config_group
*target_core_register_fabric(
121 struct config_group
*group
,
124 struct target_fabric_configfs
*tf
;
127 pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:"
128 " %s\n", group
, name
);
130 * Below are some hardcoded request_module() calls to automatically
131 * local fabric modules when the following is called:
133 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
135 * Note that this does not limit which TCM fabric module can be
136 * registered, but simply provids auto loading logic for modules with
137 * mkdir(2) system calls with known TCM fabric modules.
139 if (!strncmp(name
, "iscsi", 5)) {
141 * Automatically load the LIO Target fabric module when the
142 * following is called:
144 * mkdir -p $CONFIGFS/target/iscsi
146 ret
= request_module("iscsi_target_mod");
148 pr_err("request_module() failed for"
149 " iscsi_target_mod.ko: %d\n", ret
);
150 return ERR_PTR(-EINVAL
);
152 } else if (!strncmp(name
, "loopback", 8)) {
154 * Automatically load the tcm_loop fabric module when the
155 * following is called:
157 * mkdir -p $CONFIGFS/target/loopback
159 ret
= request_module("tcm_loop");
161 pr_err("request_module() failed for"
162 " tcm_loop.ko: %d\n", ret
);
163 return ERR_PTR(-EINVAL
);
167 tf
= target_core_get_fabric(name
);
169 pr_err("target_core_get_fabric() failed for %s\n",
171 return ERR_PTR(-EINVAL
);
173 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
174 " %s\n", tf
->tf_name
);
176 * On a successful target_core_get_fabric() look, the returned
177 * struct target_fabric_configfs *tf will contain a usage reference.
179 pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
180 &tf
->tf_cit_tmpl
.tfc_wwn_cit
);
182 tf
->tf_group
.default_groups
= tf
->tf_default_groups
;
183 tf
->tf_group
.default_groups
[0] = &tf
->tf_disc_group
;
184 tf
->tf_group
.default_groups
[1] = NULL
;
186 config_group_init_type_name(&tf
->tf_group
, name
,
187 &tf
->tf_cit_tmpl
.tfc_wwn_cit
);
188 config_group_init_type_name(&tf
->tf_disc_group
, "discovery_auth",
189 &tf
->tf_cit_tmpl
.tfc_discovery_cit
);
191 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
192 " %s\n", tf
->tf_group
.cg_item
.ci_name
);
194 * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item()
196 tf
->tf_ops
.tf_subsys
= tf
->tf_subsys
;
197 tf
->tf_fabric
= &tf
->tf_group
.cg_item
;
198 pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
201 return &tf
->tf_group
;
205 * Called from struct target_core_group_ops->drop_item()
207 static void target_core_deregister_fabric(
208 struct config_group
*group
,
209 struct config_item
*item
)
211 struct target_fabric_configfs
*tf
= container_of(
212 to_config_group(item
), struct target_fabric_configfs
, tf_group
);
213 struct config_group
*tf_group
;
214 struct config_item
*df_item
;
217 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
218 " tf list\n", config_item_name(item
));
220 pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:"
221 " %s\n", tf
->tf_name
);
222 atomic_dec(&tf
->tf_access_cnt
);
224 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing"
225 " tf->tf_fabric for %s\n", tf
->tf_name
);
226 tf
->tf_fabric
= NULL
;
228 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
229 " %s\n", config_item_name(item
));
231 tf_group
= &tf
->tf_group
;
232 for (i
= 0; tf_group
->default_groups
[i
]; i
++) {
233 df_item
= &tf_group
->default_groups
[i
]->cg_item
;
234 tf_group
->default_groups
[i
] = NULL
;
235 config_item_put(df_item
);
237 config_item_put(item
);
240 static struct configfs_group_operations target_core_fabric_group_ops
= {
241 .make_group
= &target_core_register_fabric
,
242 .drop_item
= &target_core_deregister_fabric
,
246 * All item attributes appearing in /sys/kernel/target/ appear here.
248 static struct configfs_attribute
*target_core_fabric_item_attrs
[] = {
249 &target_core_item_attr_version
,
254 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
256 static struct config_item_type target_core_fabrics_item
= {
257 .ct_item_ops
= &target_core_fabric_item_ops
,
258 .ct_group_ops
= &target_core_fabric_group_ops
,
259 .ct_attrs
= target_core_fabric_item_attrs
,
260 .ct_owner
= THIS_MODULE
,
263 static struct configfs_subsystem target_core_fabrics
= {
266 .ci_namebuf
= "target",
267 .ci_type
= &target_core_fabrics_item
,
272 struct configfs_subsystem
*target_core_subsystem
[] = {
273 &target_core_fabrics
,
277 /*##############################################################################
278 // Start functions called by external Target Fabrics Modules
279 //############################################################################*/
282 * First function called by fabric modules to:
284 * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer.
285 * 2) Add struct target_fabric_configfs to g_tf_list
286 * 3) Return struct target_fabric_configfs to fabric module to be passed
287 * into target_fabric_configfs_register().
289 struct target_fabric_configfs
*target_fabric_configfs_init(
290 struct module
*fabric_mod
,
293 struct target_fabric_configfs
*tf
;
296 pr_err("Unable to locate passed fabric name\n");
297 return ERR_PTR(-EINVAL
);
299 if (strlen(name
) >= TARGET_FABRIC_NAME_SIZE
) {
300 pr_err("Passed name: %s exceeds TARGET_FABRIC"
301 "_NAME_SIZE\n", name
);
302 return ERR_PTR(-EINVAL
);
305 tf
= kzalloc(sizeof(struct target_fabric_configfs
), GFP_KERNEL
);
307 return ERR_PTR(-ENOMEM
);
309 INIT_LIST_HEAD(&tf
->tf_list
);
310 atomic_set(&tf
->tf_access_cnt
, 0);
312 * Setup the default generic struct config_item_type's (cits) in
313 * struct target_fabric_configfs->tf_cit_tmpl
315 tf
->tf_module
= fabric_mod
;
316 target_fabric_setup_cits(tf
);
318 tf
->tf_subsys
= target_core_subsystem
[0];
319 snprintf(tf
->tf_name
, TARGET_FABRIC_NAME_SIZE
, "%s", name
);
321 mutex_lock(&g_tf_lock
);
322 list_add_tail(&tf
->tf_list
, &g_tf_list
);
323 mutex_unlock(&g_tf_lock
);
325 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>"
327 pr_debug("Initialized struct target_fabric_configfs: %p for"
328 " %s\n", tf
, tf
->tf_name
);
331 EXPORT_SYMBOL(target_fabric_configfs_init
);
334 * Called by fabric plugins after FAILED target_fabric_configfs_register() call.
336 void target_fabric_configfs_free(
337 struct target_fabric_configfs
*tf
)
339 mutex_lock(&g_tf_lock
);
340 list_del(&tf
->tf_list
);
341 mutex_unlock(&g_tf_lock
);
345 EXPORT_SYMBOL(target_fabric_configfs_free
);
348 * Perform a sanity check of the passed tf->tf_ops before completing
349 * TCM fabric module registration.
351 static int target_fabric_tf_ops_check(
352 struct target_fabric_configfs
*tf
)
354 struct target_core_fabric_ops
*tfo
= &tf
->tf_ops
;
356 if (!tfo
->get_fabric_name
) {
357 pr_err("Missing tfo->get_fabric_name()\n");
360 if (!tfo
->get_fabric_proto_ident
) {
361 pr_err("Missing tfo->get_fabric_proto_ident()\n");
364 if (!tfo
->tpg_get_wwn
) {
365 pr_err("Missing tfo->tpg_get_wwn()\n");
368 if (!tfo
->tpg_get_tag
) {
369 pr_err("Missing tfo->tpg_get_tag()\n");
372 if (!tfo
->tpg_get_default_depth
) {
373 pr_err("Missing tfo->tpg_get_default_depth()\n");
376 if (!tfo
->tpg_get_pr_transport_id
) {
377 pr_err("Missing tfo->tpg_get_pr_transport_id()\n");
380 if (!tfo
->tpg_get_pr_transport_id_len
) {
381 pr_err("Missing tfo->tpg_get_pr_transport_id_len()\n");
384 if (!tfo
->tpg_check_demo_mode
) {
385 pr_err("Missing tfo->tpg_check_demo_mode()\n");
388 if (!tfo
->tpg_check_demo_mode_cache
) {
389 pr_err("Missing tfo->tpg_check_demo_mode_cache()\n");
392 if (!tfo
->tpg_check_demo_mode_write_protect
) {
393 pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n");
396 if (!tfo
->tpg_check_prod_mode_write_protect
) {
397 pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n");
400 if (!tfo
->tpg_alloc_fabric_acl
) {
401 pr_err("Missing tfo->tpg_alloc_fabric_acl()\n");
404 if (!tfo
->tpg_release_fabric_acl
) {
405 pr_err("Missing tfo->tpg_release_fabric_acl()\n");
408 if (!tfo
->tpg_get_inst_index
) {
409 pr_err("Missing tfo->tpg_get_inst_index()\n");
412 if (!tfo
->release_cmd
) {
413 pr_err("Missing tfo->release_cmd()\n");
416 if (!tfo
->shutdown_session
) {
417 pr_err("Missing tfo->shutdown_session()\n");
420 if (!tfo
->close_session
) {
421 pr_err("Missing tfo->close_session()\n");
424 if (!tfo
->sess_get_index
) {
425 pr_err("Missing tfo->sess_get_index()\n");
428 if (!tfo
->write_pending
) {
429 pr_err("Missing tfo->write_pending()\n");
432 if (!tfo
->write_pending_status
) {
433 pr_err("Missing tfo->write_pending_status()\n");
436 if (!tfo
->set_default_node_attributes
) {
437 pr_err("Missing tfo->set_default_node_attributes()\n");
440 if (!tfo
->get_task_tag
) {
441 pr_err("Missing tfo->get_task_tag()\n");
444 if (!tfo
->get_cmd_state
) {
445 pr_err("Missing tfo->get_cmd_state()\n");
448 if (!tfo
->queue_data_in
) {
449 pr_err("Missing tfo->queue_data_in()\n");
452 if (!tfo
->queue_status
) {
453 pr_err("Missing tfo->queue_status()\n");
456 if (!tfo
->queue_tm_rsp
) {
457 pr_err("Missing tfo->queue_tm_rsp()\n");
460 if (!tfo
->aborted_task
) {
461 pr_err("Missing tfo->aborted_task()\n");
465 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
466 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
467 * target_core_fabric_configfs.c WWN+TPG group context code.
469 if (!tfo
->fabric_make_wwn
) {
470 pr_err("Missing tfo->fabric_make_wwn()\n");
473 if (!tfo
->fabric_drop_wwn
) {
474 pr_err("Missing tfo->fabric_drop_wwn()\n");
477 if (!tfo
->fabric_make_tpg
) {
478 pr_err("Missing tfo->fabric_make_tpg()\n");
481 if (!tfo
->fabric_drop_tpg
) {
482 pr_err("Missing tfo->fabric_drop_tpg()\n");
490 * Called 2nd from fabric module with returned parameter of
491 * struct target_fabric_configfs * from target_fabric_configfs_init().
493 * Upon a successful registration, the new fabric's struct config_item is
494 * return. Also, a pointer to this struct is set in the passed
495 * struct target_fabric_configfs.
497 int target_fabric_configfs_register(
498 struct target_fabric_configfs
*tf
)
503 pr_err("Unable to locate target_fabric_configfs"
507 if (!tf
->tf_subsys
) {
508 pr_err("Unable to target struct config_subsystem"
512 ret
= target_fabric_tf_ops_check(tf
);
516 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>"
520 EXPORT_SYMBOL(target_fabric_configfs_register
);
522 void target_fabric_configfs_deregister(
523 struct target_fabric_configfs
*tf
)
525 struct configfs_subsystem
*su
;
528 pr_err("Unable to locate passed target_fabric_"
534 pr_err("Unable to locate passed tf->tf_subsys"
538 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
540 mutex_lock(&g_tf_lock
);
541 if (atomic_read(&tf
->tf_access_cnt
)) {
542 mutex_unlock(&g_tf_lock
);
543 pr_err("Non zero tf->tf_access_cnt for fabric %s\n",
547 list_del(&tf
->tf_list
);
548 mutex_unlock(&g_tf_lock
);
550 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
551 " %s\n", tf
->tf_name
);
552 tf
->tf_module
= NULL
;
553 tf
->tf_subsys
= NULL
;
556 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
559 EXPORT_SYMBOL(target_fabric_configfs_deregister
);
561 /*##############################################################################
562 // Stop functions called by external Target Fabrics Modules
563 //############################################################################*/
565 /* Start functions for struct config_item_type target_core_dev_attrib_cit */
567 #define DEF_DEV_ATTRIB_SHOW(_name) \
568 static ssize_t target_core_dev_show_attr_##_name( \
569 struct se_dev_attrib *da, \
572 return snprintf(page, PAGE_SIZE, "%u\n", \
573 (u32)da->da_dev->dev_attrib._name); \
576 #define DEF_DEV_ATTRIB_STORE(_name) \
577 static ssize_t target_core_dev_store_attr_##_name( \
578 struct se_dev_attrib *da, \
585 ret = kstrtoul(page, 0, &val); \
587 pr_err("kstrtoul() failed with" \
588 " ret: %d\n", ret); \
591 ret = se_dev_set_##_name(da->da_dev, (u32)val); \
593 return (!ret) ? count : -EINVAL; \
596 #define DEF_DEV_ATTRIB(_name) \
597 DEF_DEV_ATTRIB_SHOW(_name); \
598 DEF_DEV_ATTRIB_STORE(_name);
600 #define DEF_DEV_ATTRIB_RO(_name) \
601 DEF_DEV_ATTRIB_SHOW(_name);
603 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib
, se_dev_attrib
);
604 #define SE_DEV_ATTR(_name, _mode) \
605 static struct target_core_dev_attrib_attribute \
606 target_core_dev_attrib_##_name = \
607 __CONFIGFS_EATTR(_name, _mode, \
608 target_core_dev_show_attr_##_name, \
609 target_core_dev_store_attr_##_name);
611 #define SE_DEV_ATTR_RO(_name); \
612 static struct target_core_dev_attrib_attribute \
613 target_core_dev_attrib_##_name = \
614 __CONFIGFS_EATTR_RO(_name, \
615 target_core_dev_show_attr_##_name);
617 DEF_DEV_ATTRIB(emulate_model_alias
);
618 SE_DEV_ATTR(emulate_model_alias
, S_IRUGO
| S_IWUSR
);
620 DEF_DEV_ATTRIB(emulate_dpo
);
621 SE_DEV_ATTR(emulate_dpo
, S_IRUGO
| S_IWUSR
);
623 DEF_DEV_ATTRIB(emulate_fua_write
);
624 SE_DEV_ATTR(emulate_fua_write
, S_IRUGO
| S_IWUSR
);
626 DEF_DEV_ATTRIB(emulate_fua_read
);
627 SE_DEV_ATTR(emulate_fua_read
, S_IRUGO
| S_IWUSR
);
629 DEF_DEV_ATTRIB(emulate_write_cache
);
630 SE_DEV_ATTR(emulate_write_cache
, S_IRUGO
| S_IWUSR
);
632 DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl
);
633 SE_DEV_ATTR(emulate_ua_intlck_ctrl
, S_IRUGO
| S_IWUSR
);
635 DEF_DEV_ATTRIB(emulate_tas
);
636 SE_DEV_ATTR(emulate_tas
, S_IRUGO
| S_IWUSR
);
638 DEF_DEV_ATTRIB(emulate_tpu
);
639 SE_DEV_ATTR(emulate_tpu
, S_IRUGO
| S_IWUSR
);
641 DEF_DEV_ATTRIB(emulate_tpws
);
642 SE_DEV_ATTR(emulate_tpws
, S_IRUGO
| S_IWUSR
);
644 DEF_DEV_ATTRIB(emulate_caw
);
645 SE_DEV_ATTR(emulate_caw
, S_IRUGO
| S_IWUSR
);
647 DEF_DEV_ATTRIB(emulate_3pc
);
648 SE_DEV_ATTR(emulate_3pc
, S_IRUGO
| S_IWUSR
);
650 DEF_DEV_ATTRIB(pi_prot_type
);
651 SE_DEV_ATTR(pi_prot_type
, S_IRUGO
| S_IWUSR
);
653 DEF_DEV_ATTRIB_RO(hw_pi_prot_type
);
654 SE_DEV_ATTR_RO(hw_pi_prot_type
);
656 DEF_DEV_ATTRIB(pi_prot_format
);
657 SE_DEV_ATTR(pi_prot_format
, S_IRUGO
| S_IWUSR
);
659 DEF_DEV_ATTRIB(enforce_pr_isids
);
660 SE_DEV_ATTR(enforce_pr_isids
, S_IRUGO
| S_IWUSR
);
662 DEF_DEV_ATTRIB(is_nonrot
);
663 SE_DEV_ATTR(is_nonrot
, S_IRUGO
| S_IWUSR
);
665 DEF_DEV_ATTRIB(emulate_rest_reord
);
666 SE_DEV_ATTR(emulate_rest_reord
, S_IRUGO
| S_IWUSR
);
668 DEF_DEV_ATTRIB_RO(hw_block_size
);
669 SE_DEV_ATTR_RO(hw_block_size
);
671 DEF_DEV_ATTRIB(block_size
);
672 SE_DEV_ATTR(block_size
, S_IRUGO
| S_IWUSR
);
674 DEF_DEV_ATTRIB_RO(hw_max_sectors
);
675 SE_DEV_ATTR_RO(hw_max_sectors
);
677 DEF_DEV_ATTRIB(fabric_max_sectors
);
678 SE_DEV_ATTR(fabric_max_sectors
, S_IRUGO
| S_IWUSR
);
680 DEF_DEV_ATTRIB(optimal_sectors
);
681 SE_DEV_ATTR(optimal_sectors
, S_IRUGO
| S_IWUSR
);
683 DEF_DEV_ATTRIB_RO(hw_queue_depth
);
684 SE_DEV_ATTR_RO(hw_queue_depth
);
686 DEF_DEV_ATTRIB(queue_depth
);
687 SE_DEV_ATTR(queue_depth
, S_IRUGO
| S_IWUSR
);
689 DEF_DEV_ATTRIB(max_unmap_lba_count
);
690 SE_DEV_ATTR(max_unmap_lba_count
, S_IRUGO
| S_IWUSR
);
692 DEF_DEV_ATTRIB(max_unmap_block_desc_count
);
693 SE_DEV_ATTR(max_unmap_block_desc_count
, S_IRUGO
| S_IWUSR
);
695 DEF_DEV_ATTRIB(unmap_granularity
);
696 SE_DEV_ATTR(unmap_granularity
, S_IRUGO
| S_IWUSR
);
698 DEF_DEV_ATTRIB(unmap_granularity_alignment
);
699 SE_DEV_ATTR(unmap_granularity_alignment
, S_IRUGO
| S_IWUSR
);
701 DEF_DEV_ATTRIB(max_write_same_len
);
702 SE_DEV_ATTR(max_write_same_len
, S_IRUGO
| S_IWUSR
);
704 CONFIGFS_EATTR_OPS(target_core_dev_attrib
, se_dev_attrib
, da_group
);
706 static struct configfs_attribute
*target_core_dev_attrib_attrs
[] = {
707 &target_core_dev_attrib_emulate_model_alias
.attr
,
708 &target_core_dev_attrib_emulate_dpo
.attr
,
709 &target_core_dev_attrib_emulate_fua_write
.attr
,
710 &target_core_dev_attrib_emulate_fua_read
.attr
,
711 &target_core_dev_attrib_emulate_write_cache
.attr
,
712 &target_core_dev_attrib_emulate_ua_intlck_ctrl
.attr
,
713 &target_core_dev_attrib_emulate_tas
.attr
,
714 &target_core_dev_attrib_emulate_tpu
.attr
,
715 &target_core_dev_attrib_emulate_tpws
.attr
,
716 &target_core_dev_attrib_emulate_caw
.attr
,
717 &target_core_dev_attrib_emulate_3pc
.attr
,
718 &target_core_dev_attrib_pi_prot_type
.attr
,
719 &target_core_dev_attrib_hw_pi_prot_type
.attr
,
720 &target_core_dev_attrib_pi_prot_format
.attr
,
721 &target_core_dev_attrib_enforce_pr_isids
.attr
,
722 &target_core_dev_attrib_is_nonrot
.attr
,
723 &target_core_dev_attrib_emulate_rest_reord
.attr
,
724 &target_core_dev_attrib_hw_block_size
.attr
,
725 &target_core_dev_attrib_block_size
.attr
,
726 &target_core_dev_attrib_hw_max_sectors
.attr
,
727 &target_core_dev_attrib_fabric_max_sectors
.attr
,
728 &target_core_dev_attrib_optimal_sectors
.attr
,
729 &target_core_dev_attrib_hw_queue_depth
.attr
,
730 &target_core_dev_attrib_queue_depth
.attr
,
731 &target_core_dev_attrib_max_unmap_lba_count
.attr
,
732 &target_core_dev_attrib_max_unmap_block_desc_count
.attr
,
733 &target_core_dev_attrib_unmap_granularity
.attr
,
734 &target_core_dev_attrib_unmap_granularity_alignment
.attr
,
735 &target_core_dev_attrib_max_write_same_len
.attr
,
739 static struct configfs_item_operations target_core_dev_attrib_ops
= {
740 .show_attribute
= target_core_dev_attrib_attr_show
,
741 .store_attribute
= target_core_dev_attrib_attr_store
,
744 static struct config_item_type target_core_dev_attrib_cit
= {
745 .ct_item_ops
= &target_core_dev_attrib_ops
,
746 .ct_attrs
= target_core_dev_attrib_attrs
,
747 .ct_owner
= THIS_MODULE
,
750 /* End functions for struct config_item_type target_core_dev_attrib_cit */
752 /* Start functions for struct config_item_type target_core_dev_wwn_cit */
754 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn
, t10_wwn
);
755 #define SE_DEV_WWN_ATTR(_name, _mode) \
756 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
757 __CONFIGFS_EATTR(_name, _mode, \
758 target_core_dev_wwn_show_attr_##_name, \
759 target_core_dev_wwn_store_attr_##_name);
761 #define SE_DEV_WWN_ATTR_RO(_name); \
763 static struct target_core_dev_wwn_attribute \
764 target_core_dev_wwn_##_name = \
765 __CONFIGFS_EATTR_RO(_name, \
766 target_core_dev_wwn_show_attr_##_name); \
770 * VPD page 0x80 Unit serial
772 static ssize_t
target_core_dev_wwn_show_attr_vpd_unit_serial(
773 struct t10_wwn
*t10_wwn
,
776 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
777 &t10_wwn
->unit_serial
[0]);
780 static ssize_t
target_core_dev_wwn_store_attr_vpd_unit_serial(
781 struct t10_wwn
*t10_wwn
,
785 struct se_device
*dev
= t10_wwn
->t10_dev
;
786 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
789 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
790 * from the struct scsi_device level firmware, do not allow
791 * VPD Unit Serial to be emulated.
793 * Note this struct scsi_device could also be emulating VPD
794 * information from its drivers/scsi LLD. But for now we assume
795 * it is doing 'the right thing' wrt a world wide unique
796 * VPD Unit Serial Number that OS dependent multipath can depend on.
798 if (dev
->dev_flags
& DF_FIRMWARE_VPD_UNIT_SERIAL
) {
799 pr_err("Underlying SCSI device firmware provided VPD"
800 " Unit Serial, ignoring request\n");
804 if (strlen(page
) >= INQUIRY_VPD_SERIAL_LEN
) {
805 pr_err("Emulated VPD Unit Serial exceeds"
806 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
810 * Check to see if any active $FABRIC_MOD exports exist. If they
811 * do exist, fail here as changing this information on the fly
812 * (underneath the initiator side OS dependent multipath code)
813 * could cause negative effects.
815 if (dev
->export_count
) {
816 pr_err("Unable to set VPD Unit Serial while"
817 " active %d $FABRIC_MOD exports exist\n",
823 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
825 * Also, strip any newline added from the userspace
826 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
828 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
829 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
830 snprintf(dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
831 "%s", strstrip(buf
));
832 dev
->dev_flags
|= DF_EMULATED_VPD_UNIT_SERIAL
;
834 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
835 " %s\n", dev
->t10_wwn
.unit_serial
);
840 SE_DEV_WWN_ATTR(vpd_unit_serial
, S_IRUGO
| S_IWUSR
);
843 * VPD page 0x83 Protocol Identifier
845 static ssize_t
target_core_dev_wwn_show_attr_vpd_protocol_identifier(
846 struct t10_wwn
*t10_wwn
,
850 unsigned char buf
[VPD_TMP_BUF_SIZE
];
853 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
855 spin_lock(&t10_wwn
->t10_vpd_lock
);
856 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
857 if (!vpd
->protocol_identifier_set
)
860 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
862 if (len
+ strlen(buf
) >= PAGE_SIZE
)
865 len
+= sprintf(page
+len
, "%s", buf
);
867 spin_unlock(&t10_wwn
->t10_vpd_lock
);
872 static ssize_t
target_core_dev_wwn_store_attr_vpd_protocol_identifier(
873 struct t10_wwn
*t10_wwn
,
880 SE_DEV_WWN_ATTR(vpd_protocol_identifier
, S_IRUGO
| S_IWUSR
);
883 * Generic wrapper for dumping VPD identifiers by association.
885 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
886 static ssize_t target_core_dev_wwn_show_attr_##_name( \
887 struct t10_wwn *t10_wwn, \
890 struct t10_vpd *vpd; \
891 unsigned char buf[VPD_TMP_BUF_SIZE]; \
894 spin_lock(&t10_wwn->t10_vpd_lock); \
895 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
896 if (vpd->association != _assoc) \
899 memset(buf, 0, VPD_TMP_BUF_SIZE); \
900 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
901 if (len + strlen(buf) >= PAGE_SIZE) \
903 len += sprintf(page+len, "%s", buf); \
905 memset(buf, 0, VPD_TMP_BUF_SIZE); \
906 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
907 if (len + strlen(buf) >= PAGE_SIZE) \
909 len += sprintf(page+len, "%s", buf); \
911 memset(buf, 0, VPD_TMP_BUF_SIZE); \
912 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
913 if (len + strlen(buf) >= PAGE_SIZE) \
915 len += sprintf(page+len, "%s", buf); \
917 spin_unlock(&t10_wwn->t10_vpd_lock); \
923 * VPD page 0x83 Association: Logical Unit
925 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
927 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
928 struct t10_wwn
*t10_wwn
,
935 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit
, S_IRUGO
| S_IWUSR
);
938 * VPD page 0x83 Association: Target Port
940 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
942 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_target_port(
943 struct t10_wwn
*t10_wwn
,
950 SE_DEV_WWN_ATTR(vpd_assoc_target_port
, S_IRUGO
| S_IWUSR
);
953 * VPD page 0x83 Association: SCSI Target Device
955 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
957 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
958 struct t10_wwn
*t10_wwn
,
965 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device
, S_IRUGO
| S_IWUSR
);
967 CONFIGFS_EATTR_OPS(target_core_dev_wwn
, t10_wwn
, t10_wwn_group
);
969 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
970 &target_core_dev_wwn_vpd_unit_serial
.attr
,
971 &target_core_dev_wwn_vpd_protocol_identifier
.attr
,
972 &target_core_dev_wwn_vpd_assoc_logical_unit
.attr
,
973 &target_core_dev_wwn_vpd_assoc_target_port
.attr
,
974 &target_core_dev_wwn_vpd_assoc_scsi_target_device
.attr
,
978 static struct configfs_item_operations target_core_dev_wwn_ops
= {
979 .show_attribute
= target_core_dev_wwn_attr_show
,
980 .store_attribute
= target_core_dev_wwn_attr_store
,
983 static struct config_item_type target_core_dev_wwn_cit
= {
984 .ct_item_ops
= &target_core_dev_wwn_ops
,
985 .ct_attrs
= target_core_dev_wwn_attrs
,
986 .ct_owner
= THIS_MODULE
,
989 /* End functions for struct config_item_type target_core_dev_wwn_cit */
991 /* Start functions for struct config_item_type target_core_dev_pr_cit */
993 CONFIGFS_EATTR_STRUCT(target_core_dev_pr
, se_device
);
994 #define SE_DEV_PR_ATTR(_name, _mode) \
995 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
996 __CONFIGFS_EATTR(_name, _mode, \
997 target_core_dev_pr_show_attr_##_name, \
998 target_core_dev_pr_store_attr_##_name);
1000 #define SE_DEV_PR_ATTR_RO(_name); \
1001 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1002 __CONFIGFS_EATTR_RO(_name, \
1003 target_core_dev_pr_show_attr_##_name);
1005 static ssize_t
target_core_dev_pr_show_spc3_res(struct se_device
*dev
,
1008 struct se_node_acl
*se_nacl
;
1009 struct t10_pr_registration
*pr_reg
;
1010 char i_buf
[PR_REG_ISID_ID_LEN
];
1012 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1014 pr_reg
= dev
->dev_pr_res_holder
;
1016 return sprintf(page
, "No SPC-3 Reservation holder\n");
1018 se_nacl
= pr_reg
->pr_reg_nacl
;
1019 core_pr_dump_initiator_port(pr_reg
, i_buf
, PR_REG_ISID_ID_LEN
);
1021 return sprintf(page
, "SPC-3 Reservation: %s Initiator: %s%s\n",
1022 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1023 se_nacl
->initiatorname
, i_buf
);
1026 static ssize_t
target_core_dev_pr_show_spc2_res(struct se_device
*dev
,
1029 struct se_node_acl
*se_nacl
;
1032 se_nacl
= dev
->dev_reserved_node_acl
;
1035 "SPC-2 Reservation: %s Initiator: %s\n",
1036 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1037 se_nacl
->initiatorname
);
1039 len
= sprintf(page
, "No SPC-2 Reservation holder\n");
1044 static ssize_t
target_core_dev_pr_show_attr_res_holder(struct se_device
*dev
,
1049 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1050 return sprintf(page
, "Passthrough\n");
1052 spin_lock(&dev
->dev_reservation_lock
);
1053 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1054 ret
= target_core_dev_pr_show_spc2_res(dev
, page
);
1056 ret
= target_core_dev_pr_show_spc3_res(dev
, page
);
1057 spin_unlock(&dev
->dev_reservation_lock
);
1061 SE_DEV_PR_ATTR_RO(res_holder
);
1063 static ssize_t
target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1064 struct se_device
*dev
, char *page
)
1068 spin_lock(&dev
->dev_reservation_lock
);
1069 if (!dev
->dev_pr_res_holder
) {
1070 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1071 } else if (dev
->dev_pr_res_holder
->pr_reg_all_tg_pt
) {
1072 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1073 " Ports registration\n");
1075 len
= sprintf(page
, "SPC-3 Reservation: Single"
1076 " Target Port registration\n");
1079 spin_unlock(&dev
->dev_reservation_lock
);
1083 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts
);
1085 static ssize_t
target_core_dev_pr_show_attr_res_pr_generation(
1086 struct se_device
*dev
, char *page
)
1088 return sprintf(page
, "0x%08x\n", dev
->t10_pr
.pr_generation
);
1091 SE_DEV_PR_ATTR_RO(res_pr_generation
);
1094 * res_pr_holder_tg_port
1096 static ssize_t
target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1097 struct se_device
*dev
, char *page
)
1099 struct se_node_acl
*se_nacl
;
1101 struct se_portal_group
*se_tpg
;
1102 struct t10_pr_registration
*pr_reg
;
1103 struct target_core_fabric_ops
*tfo
;
1106 spin_lock(&dev
->dev_reservation_lock
);
1107 pr_reg
= dev
->dev_pr_res_holder
;
1109 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1113 se_nacl
= pr_reg
->pr_reg_nacl
;
1114 se_tpg
= se_nacl
->se_tpg
;
1115 lun
= pr_reg
->pr_reg_tg_pt_lun
;
1116 tfo
= se_tpg
->se_tpg_tfo
;
1118 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1119 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1120 tfo
->tpg_get_wwn(se_tpg
));
1121 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1122 " Identifier Tag: %hu %s Portal Group Tag: %hu"
1123 " %s Logical Unit: %u\n", lun
->lun_sep
->sep_rtpi
,
1124 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1125 tfo
->get_fabric_name(), lun
->unpacked_lun
);
1128 spin_unlock(&dev
->dev_reservation_lock
);
1132 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port
);
1134 static ssize_t
target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1135 struct se_device
*dev
, char *page
)
1137 struct target_core_fabric_ops
*tfo
;
1138 struct t10_pr_registration
*pr_reg
;
1139 unsigned char buf
[384];
1140 char i_buf
[PR_REG_ISID_ID_LEN
];
1144 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1146 spin_lock(&dev
->t10_pr
.registration_lock
);
1147 list_for_each_entry(pr_reg
, &dev
->t10_pr
.registration_list
,
1150 memset(buf
, 0, 384);
1151 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1152 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1153 core_pr_dump_initiator_port(pr_reg
, i_buf
,
1154 PR_REG_ISID_ID_LEN
);
1155 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1156 tfo
->get_fabric_name(),
1157 pr_reg
->pr_reg_nacl
->initiatorname
, i_buf
, pr_reg
->pr_res_key
,
1158 pr_reg
->pr_res_generation
);
1160 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1163 len
+= sprintf(page
+len
, "%s", buf
);
1166 spin_unlock(&dev
->t10_pr
.registration_lock
);
1169 len
+= sprintf(page
+len
, "None\n");
1174 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts
);
1176 static ssize_t
target_core_dev_pr_show_attr_res_pr_type(
1177 struct se_device
*dev
, char *page
)
1179 struct t10_pr_registration
*pr_reg
;
1182 spin_lock(&dev
->dev_reservation_lock
);
1183 pr_reg
= dev
->dev_pr_res_holder
;
1185 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1186 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1188 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1191 spin_unlock(&dev
->dev_reservation_lock
);
1195 SE_DEV_PR_ATTR_RO(res_pr_type
);
1197 static ssize_t
target_core_dev_pr_show_attr_res_type(
1198 struct se_device
*dev
, char *page
)
1200 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1201 return sprintf(page
, "SPC_PASSTHROUGH\n");
1202 else if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1203 return sprintf(page
, "SPC2_RESERVATIONS\n");
1205 return sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1208 SE_DEV_PR_ATTR_RO(res_type
);
1210 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_active(
1211 struct se_device
*dev
, char *page
)
1213 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1216 return sprintf(page
, "APTPL Bit Status: %s\n",
1217 (dev
->t10_pr
.pr_aptpl_active
) ? "Activated" : "Disabled");
1220 SE_DEV_PR_ATTR_RO(res_aptpl_active
);
1223 * res_aptpl_metadata
1225 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_metadata(
1226 struct se_device
*dev
, char *page
)
1228 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1231 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1235 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1236 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1237 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1238 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1241 static match_table_t tokens
= {
1242 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1243 {Opt_initiator_node
, "initiator_node=%s"},
1244 {Opt_initiator_sid
, "initiator_sid=%s"},
1245 {Opt_sa_res_key
, "sa_res_key=%s"},
1246 {Opt_res_holder
, "res_holder=%d"},
1247 {Opt_res_type
, "res_type=%d"},
1248 {Opt_res_scope
, "res_scope=%d"},
1249 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1250 {Opt_mapped_lun
, "mapped_lun=%d"},
1251 {Opt_target_fabric
, "target_fabric=%s"},
1252 {Opt_target_node
, "target_node=%s"},
1253 {Opt_tpgt
, "tpgt=%d"},
1254 {Opt_port_rtpi
, "port_rtpi=%d"},
1255 {Opt_target_lun
, "target_lun=%d"},
1259 static ssize_t
target_core_dev_pr_store_attr_res_aptpl_metadata(
1260 struct se_device
*dev
,
1264 unsigned char *i_fabric
= NULL
, *i_port
= NULL
, *isid
= NULL
;
1265 unsigned char *t_fabric
= NULL
, *t_port
= NULL
;
1266 char *orig
, *ptr
, *arg_p
, *opts
;
1267 substring_t args
[MAX_OPT_ARGS
];
1268 unsigned long long tmp_ll
;
1270 u32 mapped_lun
= 0, target_lun
= 0;
1271 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1272 u16 port_rpti
= 0, tpgt
= 0;
1275 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1277 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1280 if (dev
->export_count
) {
1281 pr_debug("Unable to process APTPL metadata while"
1282 " active fabric exports exist\n");
1286 opts
= kstrdup(page
, GFP_KERNEL
);
1291 while ((ptr
= strsep(&opts
, ",\n")) != NULL
) {
1295 token
= match_token(ptr
, tokens
, args
);
1297 case Opt_initiator_fabric
:
1298 i_fabric
= match_strdup(&args
[0]);
1304 case Opt_initiator_node
:
1305 i_port
= match_strdup(&args
[0]);
1310 if (strlen(i_port
) >= PR_APTPL_MAX_IPORT_LEN
) {
1311 pr_err("APTPL metadata initiator_node="
1312 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1313 PR_APTPL_MAX_IPORT_LEN
);
1318 case Opt_initiator_sid
:
1319 isid
= match_strdup(&args
[0]);
1324 if (strlen(isid
) >= PR_REG_ISID_LEN
) {
1325 pr_err("APTPL metadata initiator_isid"
1326 "= exceeds PR_REG_ISID_LEN: %d\n",
1332 case Opt_sa_res_key
:
1333 arg_p
= match_strdup(&args
[0]);
1338 ret
= kstrtoull(arg_p
, 0, &tmp_ll
);
1340 pr_err("kstrtoull() failed for"
1344 sa_res_key
= (u64
)tmp_ll
;
1347 * PR APTPL Metadata for Reservation
1349 case Opt_res_holder
:
1350 match_int(args
, &arg
);
1354 match_int(args
, &arg
);
1358 match_int(args
, &arg
);
1361 case Opt_res_all_tg_pt
:
1362 match_int(args
, &arg
);
1363 all_tg_pt
= (int)arg
;
1365 case Opt_mapped_lun
:
1366 match_int(args
, &arg
);
1367 mapped_lun
= (u32
)arg
;
1370 * PR APTPL Metadata for Target Port
1372 case Opt_target_fabric
:
1373 t_fabric
= match_strdup(&args
[0]);
1379 case Opt_target_node
:
1380 t_port
= match_strdup(&args
[0]);
1385 if (strlen(t_port
) >= PR_APTPL_MAX_TPORT_LEN
) {
1386 pr_err("APTPL metadata target_node="
1387 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1388 PR_APTPL_MAX_TPORT_LEN
);
1394 match_int(args
, &arg
);
1398 match_int(args
, &arg
);
1399 port_rpti
= (u16
)arg
;
1401 case Opt_target_lun
:
1402 match_int(args
, &arg
);
1403 target_lun
= (u32
)arg
;
1410 if (!i_port
|| !t_port
|| !sa_res_key
) {
1411 pr_err("Illegal parameters for APTPL registration\n");
1416 if (res_holder
&& !(type
)) {
1417 pr_err("Illegal PR type: 0x%02x for reservation"
1423 ret
= core_scsi3_alloc_aptpl_registration(&dev
->t10_pr
, sa_res_key
,
1424 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1425 res_holder
, all_tg_pt
, type
);
1433 return (ret
== 0) ? count
: ret
;
1436 SE_DEV_PR_ATTR(res_aptpl_metadata
, S_IRUGO
| S_IWUSR
);
1438 CONFIGFS_EATTR_OPS(target_core_dev_pr
, se_device
, dev_pr_group
);
1440 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1441 &target_core_dev_pr_res_holder
.attr
,
1442 &target_core_dev_pr_res_pr_all_tgt_pts
.attr
,
1443 &target_core_dev_pr_res_pr_generation
.attr
,
1444 &target_core_dev_pr_res_pr_holder_tg_port
.attr
,
1445 &target_core_dev_pr_res_pr_registered_i_pts
.attr
,
1446 &target_core_dev_pr_res_pr_type
.attr
,
1447 &target_core_dev_pr_res_type
.attr
,
1448 &target_core_dev_pr_res_aptpl_active
.attr
,
1449 &target_core_dev_pr_res_aptpl_metadata
.attr
,
1453 static struct configfs_item_operations target_core_dev_pr_ops
= {
1454 .show_attribute
= target_core_dev_pr_attr_show
,
1455 .store_attribute
= target_core_dev_pr_attr_store
,
1458 static struct config_item_type target_core_dev_pr_cit
= {
1459 .ct_item_ops
= &target_core_dev_pr_ops
,
1460 .ct_attrs
= target_core_dev_pr_attrs
,
1461 .ct_owner
= THIS_MODULE
,
1464 /* End functions for struct config_item_type target_core_dev_pr_cit */
1466 /* Start functions for struct config_item_type target_core_dev_cit */
1468 static ssize_t
target_core_show_dev_info(void *p
, char *page
)
1470 struct se_device
*dev
= p
;
1471 struct se_subsystem_api
*t
= dev
->transport
;
1473 ssize_t read_bytes
= 0;
1475 transport_dump_dev_state(dev
, page
, &bl
);
1477 read_bytes
+= t
->show_configfs_dev_params(dev
, page
+read_bytes
);
1481 static struct target_core_configfs_attribute target_core_attr_dev_info
= {
1482 .attr
= { .ca_owner
= THIS_MODULE
,
1484 .ca_mode
= S_IRUGO
},
1485 .show
= target_core_show_dev_info
,
1489 static ssize_t
target_core_store_dev_control(
1494 struct se_device
*dev
= p
;
1495 struct se_subsystem_api
*t
= dev
->transport
;
1497 return t
->set_configfs_dev_params(dev
, page
, count
);
1500 static struct target_core_configfs_attribute target_core_attr_dev_control
= {
1501 .attr
= { .ca_owner
= THIS_MODULE
,
1502 .ca_name
= "control",
1503 .ca_mode
= S_IWUSR
},
1505 .store
= target_core_store_dev_control
,
1508 static ssize_t
target_core_show_dev_alias(void *p
, char *page
)
1510 struct se_device
*dev
= p
;
1512 if (!(dev
->dev_flags
& DF_USING_ALIAS
))
1515 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->dev_alias
);
1518 static ssize_t
target_core_store_dev_alias(
1523 struct se_device
*dev
= p
;
1524 struct se_hba
*hba
= dev
->se_hba
;
1527 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1528 pr_err("alias count: %d exceeds"
1529 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1530 SE_DEV_ALIAS_LEN
-1);
1534 read_bytes
= snprintf(&dev
->dev_alias
[0], SE_DEV_ALIAS_LEN
, "%s", page
);
1537 if (dev
->dev_alias
[read_bytes
- 1] == '\n')
1538 dev
->dev_alias
[read_bytes
- 1] = '\0';
1540 dev
->dev_flags
|= DF_USING_ALIAS
;
1542 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
1543 config_item_name(&hba
->hba_group
.cg_item
),
1544 config_item_name(&dev
->dev_group
.cg_item
),
1550 static struct target_core_configfs_attribute target_core_attr_dev_alias
= {
1551 .attr
= { .ca_owner
= THIS_MODULE
,
1553 .ca_mode
= S_IRUGO
| S_IWUSR
},
1554 .show
= target_core_show_dev_alias
,
1555 .store
= target_core_store_dev_alias
,
1558 static ssize_t
target_core_show_dev_udev_path(void *p
, char *page
)
1560 struct se_device
*dev
= p
;
1562 if (!(dev
->dev_flags
& DF_USING_UDEV_PATH
))
1565 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->udev_path
);
1568 static ssize_t
target_core_store_dev_udev_path(
1573 struct se_device
*dev
= p
;
1574 struct se_hba
*hba
= dev
->se_hba
;
1577 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1578 pr_err("udev_path count: %d exceeds"
1579 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1580 SE_UDEV_PATH_LEN
-1);
1584 read_bytes
= snprintf(&dev
->udev_path
[0], SE_UDEV_PATH_LEN
,
1588 if (dev
->udev_path
[read_bytes
- 1] == '\n')
1589 dev
->udev_path
[read_bytes
- 1] = '\0';
1591 dev
->dev_flags
|= DF_USING_UDEV_PATH
;
1593 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1594 config_item_name(&hba
->hba_group
.cg_item
),
1595 config_item_name(&dev
->dev_group
.cg_item
),
1601 static struct target_core_configfs_attribute target_core_attr_dev_udev_path
= {
1602 .attr
= { .ca_owner
= THIS_MODULE
,
1603 .ca_name
= "udev_path",
1604 .ca_mode
= S_IRUGO
| S_IWUSR
},
1605 .show
= target_core_show_dev_udev_path
,
1606 .store
= target_core_store_dev_udev_path
,
1609 static ssize_t
target_core_show_dev_enable(void *p
, char *page
)
1611 struct se_device
*dev
= p
;
1613 return snprintf(page
, PAGE_SIZE
, "%d\n", !!(dev
->dev_flags
& DF_CONFIGURED
));
1616 static ssize_t
target_core_store_dev_enable(
1621 struct se_device
*dev
= p
;
1625 ptr
= strstr(page
, "1");
1627 pr_err("For dev_enable ops, only valid value"
1632 ret
= target_configure_device(dev
);
1638 static struct target_core_configfs_attribute target_core_attr_dev_enable
= {
1639 .attr
= { .ca_owner
= THIS_MODULE
,
1640 .ca_name
= "enable",
1641 .ca_mode
= S_IRUGO
| S_IWUSR
},
1642 .show
= target_core_show_dev_enable
,
1643 .store
= target_core_store_dev_enable
,
1646 static ssize_t
target_core_show_alua_lu_gp(void *p
, char *page
)
1648 struct se_device
*dev
= p
;
1649 struct config_item
*lu_ci
;
1650 struct t10_alua_lu_gp
*lu_gp
;
1651 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1654 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1658 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1659 lu_gp
= lu_gp_mem
->lu_gp
;
1661 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1662 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1663 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1665 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1670 static ssize_t
target_core_store_alua_lu_gp(
1675 struct se_device
*dev
= p
;
1676 struct se_hba
*hba
= dev
->se_hba
;
1677 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1678 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1679 unsigned char buf
[LU_GROUP_NAME_BUF
];
1682 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1686 if (count
> LU_GROUP_NAME_BUF
) {
1687 pr_err("ALUA LU Group Alias too large!\n");
1690 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1691 memcpy(buf
, page
, count
);
1693 * Any ALUA logical unit alias besides "NULL" means we will be
1694 * making a new group association.
1696 if (strcmp(strstrip(buf
), "NULL")) {
1698 * core_alua_get_lu_gp_by_name() will increment reference to
1699 * struct t10_alua_lu_gp. This reference is released with
1700 * core_alua_get_lu_gp_by_name below().
1702 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
1707 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1708 lu_gp
= lu_gp_mem
->lu_gp
;
1711 * Clearing an existing lu_gp association, and replacing
1715 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
1716 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1718 config_item_name(&hba
->hba_group
.cg_item
),
1719 config_item_name(&dev
->dev_group
.cg_item
),
1720 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1723 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1724 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1729 * Removing existing association of lu_gp_mem with lu_gp
1731 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1735 * Associate lu_gp_mem with lu_gp_new.
1737 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
1738 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1740 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1741 " core/alua/lu_gps/%s, ID: %hu\n",
1742 (move
) ? "Moving" : "Adding",
1743 config_item_name(&hba
->hba_group
.cg_item
),
1744 config_item_name(&dev
->dev_group
.cg_item
),
1745 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
1746 lu_gp_new
->lu_gp_id
);
1748 core_alua_put_lu_gp_from_name(lu_gp_new
);
1752 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp
= {
1753 .attr
= { .ca_owner
= THIS_MODULE
,
1754 .ca_name
= "alua_lu_gp",
1755 .ca_mode
= S_IRUGO
| S_IWUSR
},
1756 .show
= target_core_show_alua_lu_gp
,
1757 .store
= target_core_store_alua_lu_gp
,
1760 static ssize_t
target_core_show_dev_lba_map(void *p
, char *page
)
1762 struct se_device
*dev
= p
;
1763 struct t10_alua_lba_map
*map
;
1764 struct t10_alua_lba_map_member
*mem
;
1769 spin_lock(&dev
->t10_alua
.lba_map_lock
);
1770 if (!list_empty(&dev
->t10_alua
.lba_map_list
))
1771 bl
+= sprintf(b
+ bl
, "%u %u\n",
1772 dev
->t10_alua
.lba_map_segment_size
,
1773 dev
->t10_alua
.lba_map_segment_multiplier
);
1774 list_for_each_entry(map
, &dev
->t10_alua
.lba_map_list
, lba_map_list
) {
1775 bl
+= sprintf(b
+ bl
, "%llu %llu",
1776 map
->lba_map_first_lba
, map
->lba_map_last_lba
);
1777 list_for_each_entry(mem
, &map
->lba_map_mem_list
,
1779 switch (mem
->lba_map_mem_alua_state
) {
1780 case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
:
1783 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
1786 case ALUA_ACCESS_STATE_STANDBY
:
1789 case ALUA_ACCESS_STATE_UNAVAILABLE
:
1796 bl
+= sprintf(b
+ bl
, " %d:%c",
1797 mem
->lba_map_mem_alua_pg_id
, state
);
1799 bl
+= sprintf(b
+ bl
, "\n");
1801 spin_unlock(&dev
->t10_alua
.lba_map_lock
);
1805 static ssize_t
target_core_store_dev_lba_map(
1810 struct se_device
*dev
= p
;
1811 struct t10_alua_lba_map
*lba_map
= NULL
;
1812 struct list_head lba_list
;
1813 char *map_entries
, *ptr
;
1815 int pg_num
= -1, pg
;
1816 int ret
= 0, num
= 0, pg_id
, alua_state
;
1817 unsigned long start_lba
= -1, end_lba
= -1;
1818 unsigned long segment_size
= -1, segment_mult
= -1;
1820 map_entries
= kstrdup(page
, GFP_KERNEL
);
1824 INIT_LIST_HEAD(&lba_list
);
1825 while ((ptr
= strsep(&map_entries
, "\n")) != NULL
) {
1830 if (sscanf(ptr
, "%lu %lu\n",
1831 &segment_size
, &segment_mult
) != 2) {
1832 pr_err("Invalid line %d\n", num
);
1839 if (sscanf(ptr
, "%lu %lu", &start_lba
, &end_lba
) != 2) {
1840 pr_err("Invalid line %d\n", num
);
1844 ptr
= strchr(ptr
, ' ');
1846 pr_err("Invalid line %d, missing end lba\n", num
);
1851 ptr
= strchr(ptr
, ' ');
1853 pr_err("Invalid line %d, missing state definitions\n",
1859 lba_map
= core_alua_allocate_lba_map(&lba_list
,
1860 start_lba
, end_lba
);
1861 if (IS_ERR(lba_map
)) {
1862 ret
= PTR_ERR(lba_map
);
1866 while (sscanf(ptr
, "%d:%c", &pg_id
, &state
) == 2) {
1869 alua_state
= ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
;
1872 alua_state
= ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
;
1875 alua_state
= ALUA_ACCESS_STATE_STANDBY
;
1878 alua_state
= ALUA_ACCESS_STATE_UNAVAILABLE
;
1881 pr_err("Invalid ALUA state '%c'\n", state
);
1886 ret
= core_alua_allocate_lba_map_mem(lba_map
,
1889 pr_err("Invalid target descriptor %d:%c "
1895 ptr
= strchr(ptr
, ' ');
1903 else if (pg
!= pg_num
) {
1904 pr_err("Only %d from %d port groups definitions "
1905 "at line %d\n", pg
, pg_num
, num
);
1913 core_alua_free_lba_map(&lba_list
);
1916 core_alua_set_lba_map(dev
, &lba_list
,
1917 segment_size
, segment_mult
);
1922 static struct target_core_configfs_attribute target_core_attr_dev_lba_map
= {
1923 .attr
= { .ca_owner
= THIS_MODULE
,
1924 .ca_name
= "lba_map",
1925 .ca_mode
= S_IRUGO
| S_IWUSR
},
1926 .show
= target_core_show_dev_lba_map
,
1927 .store
= target_core_store_dev_lba_map
,
1930 static struct configfs_attribute
*lio_core_dev_attrs
[] = {
1931 &target_core_attr_dev_info
.attr
,
1932 &target_core_attr_dev_control
.attr
,
1933 &target_core_attr_dev_alias
.attr
,
1934 &target_core_attr_dev_udev_path
.attr
,
1935 &target_core_attr_dev_enable
.attr
,
1936 &target_core_attr_dev_alua_lu_gp
.attr
,
1937 &target_core_attr_dev_lba_map
.attr
,
1941 static void target_core_dev_release(struct config_item
*item
)
1943 struct config_group
*dev_cg
= to_config_group(item
);
1944 struct se_device
*dev
=
1945 container_of(dev_cg
, struct se_device
, dev_group
);
1947 kfree(dev_cg
->default_groups
);
1948 target_free_device(dev
);
1951 static ssize_t
target_core_dev_show(struct config_item
*item
,
1952 struct configfs_attribute
*attr
,
1955 struct config_group
*dev_cg
= to_config_group(item
);
1956 struct se_device
*dev
=
1957 container_of(dev_cg
, struct se_device
, dev_group
);
1958 struct target_core_configfs_attribute
*tc_attr
= container_of(
1959 attr
, struct target_core_configfs_attribute
, attr
);
1964 return tc_attr
->show(dev
, page
);
1967 static ssize_t
target_core_dev_store(struct config_item
*item
,
1968 struct configfs_attribute
*attr
,
1969 const char *page
, size_t count
)
1971 struct config_group
*dev_cg
= to_config_group(item
);
1972 struct se_device
*dev
=
1973 container_of(dev_cg
, struct se_device
, dev_group
);
1974 struct target_core_configfs_attribute
*tc_attr
= container_of(
1975 attr
, struct target_core_configfs_attribute
, attr
);
1977 if (!tc_attr
->store
)
1980 return tc_attr
->store(dev
, page
, count
);
1983 static struct configfs_item_operations target_core_dev_item_ops
= {
1984 .release
= target_core_dev_release
,
1985 .show_attribute
= target_core_dev_show
,
1986 .store_attribute
= target_core_dev_store
,
1989 static struct config_item_type target_core_dev_cit
= {
1990 .ct_item_ops
= &target_core_dev_item_ops
,
1991 .ct_attrs
= lio_core_dev_attrs
,
1992 .ct_owner
= THIS_MODULE
,
1995 /* End functions for struct config_item_type target_core_dev_cit */
1997 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
1999 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp
, t10_alua_lu_gp
);
2000 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
2001 static struct target_core_alua_lu_gp_attribute \
2002 target_core_alua_lu_gp_##_name = \
2003 __CONFIGFS_EATTR(_name, _mode, \
2004 target_core_alua_lu_gp_show_attr_##_name, \
2005 target_core_alua_lu_gp_store_attr_##_name);
2007 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
2008 static struct target_core_alua_lu_gp_attribute \
2009 target_core_alua_lu_gp_##_name = \
2010 __CONFIGFS_EATTR_RO(_name, \
2011 target_core_alua_lu_gp_show_attr_##_name);
2016 static ssize_t
target_core_alua_lu_gp_show_attr_lu_gp_id(
2017 struct t10_alua_lu_gp
*lu_gp
,
2020 if (!lu_gp
->lu_gp_valid_id
)
2023 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
2026 static ssize_t
target_core_alua_lu_gp_store_attr_lu_gp_id(
2027 struct t10_alua_lu_gp
*lu_gp
,
2031 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2032 unsigned long lu_gp_id
;
2035 ret
= kstrtoul(page
, 0, &lu_gp_id
);
2037 pr_err("kstrtoul() returned %d for"
2038 " lu_gp_id\n", ret
);
2041 if (lu_gp_id
> 0x0000ffff) {
2042 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
2043 " 0x0000ffff\n", lu_gp_id
);
2047 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
2051 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
2052 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2053 config_item_name(&alua_lu_gp_cg
->cg_item
),
2059 SE_DEV_ALUA_LU_ATTR(lu_gp_id
, S_IRUGO
| S_IWUSR
);
2064 static ssize_t
target_core_alua_lu_gp_show_attr_members(
2065 struct t10_alua_lu_gp
*lu_gp
,
2068 struct se_device
*dev
;
2070 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2071 ssize_t len
= 0, cur_len
;
2072 unsigned char buf
[LU_GROUP_NAME_BUF
];
2074 memset(buf
, 0, LU_GROUP_NAME_BUF
);
2076 spin_lock(&lu_gp
->lu_gp_lock
);
2077 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
2078 dev
= lu_gp_mem
->lu_gp_mem_dev
;
2081 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
2082 config_item_name(&hba
->hba_group
.cg_item
),
2083 config_item_name(&dev
->dev_group
.cg_item
));
2084 cur_len
++; /* Extra byte for NULL terminator */
2086 if ((cur_len
+ len
) > PAGE_SIZE
) {
2087 pr_warn("Ran out of lu_gp_show_attr"
2088 "_members buffer\n");
2091 memcpy(page
+len
, buf
, cur_len
);
2094 spin_unlock(&lu_gp
->lu_gp_lock
);
2099 SE_DEV_ALUA_LU_ATTR_RO(members
);
2101 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp
, t10_alua_lu_gp
, lu_gp_group
);
2103 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
2104 &target_core_alua_lu_gp_lu_gp_id
.attr
,
2105 &target_core_alua_lu_gp_members
.attr
,
2109 static void target_core_alua_lu_gp_release(struct config_item
*item
)
2111 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2112 struct t10_alua_lu_gp
, lu_gp_group
);
2114 core_alua_free_lu_gp(lu_gp
);
2117 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
2118 .release
= target_core_alua_lu_gp_release
,
2119 .show_attribute
= target_core_alua_lu_gp_attr_show
,
2120 .store_attribute
= target_core_alua_lu_gp_attr_store
,
2123 static struct config_item_type target_core_alua_lu_gp_cit
= {
2124 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
2125 .ct_attrs
= target_core_alua_lu_gp_attrs
,
2126 .ct_owner
= THIS_MODULE
,
2129 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
2131 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
2133 static struct config_group
*target_core_alua_create_lu_gp(
2134 struct config_group
*group
,
2137 struct t10_alua_lu_gp
*lu_gp
;
2138 struct config_group
*alua_lu_gp_cg
= NULL
;
2139 struct config_item
*alua_lu_gp_ci
= NULL
;
2141 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
2145 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2146 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
2148 config_group_init_type_name(alua_lu_gp_cg
, name
,
2149 &target_core_alua_lu_gp_cit
);
2151 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2152 " Group: core/alua/lu_gps/%s\n",
2153 config_item_name(alua_lu_gp_ci
));
2155 return alua_lu_gp_cg
;
2159 static void target_core_alua_drop_lu_gp(
2160 struct config_group
*group
,
2161 struct config_item
*item
)
2163 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2164 struct t10_alua_lu_gp
, lu_gp_group
);
2166 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2167 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2168 config_item_name(item
), lu_gp
->lu_gp_id
);
2170 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
2171 * -> target_core_alua_lu_gp_release()
2173 config_item_put(item
);
2176 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
2177 .make_group
= &target_core_alua_create_lu_gp
,
2178 .drop_item
= &target_core_alua_drop_lu_gp
,
2181 static struct config_item_type target_core_alua_lu_gps_cit
= {
2182 .ct_item_ops
= NULL
,
2183 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
2184 .ct_owner
= THIS_MODULE
,
2187 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
2189 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2191 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
);
2192 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
2193 static struct target_core_alua_tg_pt_gp_attribute \
2194 target_core_alua_tg_pt_gp_##_name = \
2195 __CONFIGFS_EATTR(_name, _mode, \
2196 target_core_alua_tg_pt_gp_show_attr_##_name, \
2197 target_core_alua_tg_pt_gp_store_attr_##_name);
2199 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2200 static struct target_core_alua_tg_pt_gp_attribute \
2201 target_core_alua_tg_pt_gp_##_name = \
2202 __CONFIGFS_EATTR_RO(_name, \
2203 target_core_alua_tg_pt_gp_show_attr_##_name);
2208 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2209 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2212 return sprintf(page
, "%d\n",
2213 atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
));
2216 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2217 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2221 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
2225 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2226 pr_err("Unable to do implicit ALUA on non valid"
2227 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2230 if (!(dev
->dev_flags
& DF_CONFIGURED
)) {
2231 pr_err("Unable to set alua_access_state while device is"
2232 " not configured\n");
2236 ret
= kstrtoul(page
, 0, &tmp
);
2238 pr_err("Unable to extract new ALUA access state from"
2242 new_state
= (int)tmp
;
2244 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICIT_ALUA
)) {
2245 pr_err("Unable to process implicit configfs ALUA"
2246 " transition while TPGS_IMPLICIT_ALUA is disabled\n");
2249 if (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICIT_ALUA
&&
2250 new_state
== ALUA_ACCESS_STATE_LBA_DEPENDENT
) {
2251 /* LBA DEPENDENT is only allowed with implicit ALUA */
2252 pr_err("Unable to process implicit configfs ALUA transition"
2253 " while explicit ALUA management is enabled\n");
2257 ret
= core_alua_do_port_transition(tg_pt_gp
, dev
,
2258 NULL
, NULL
, new_state
, 0);
2259 return (!ret
) ? count
: -EINVAL
;
2262 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state
, S_IRUGO
| S_IWUSR
);
2265 * alua_access_status
2267 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2268 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2271 return sprintf(page
, "%s\n",
2272 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2275 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2276 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2281 int new_status
, ret
;
2283 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2284 pr_err("Unable to do set ALUA access status on non"
2285 " valid tg_pt_gp ID: %hu\n",
2286 tg_pt_gp
->tg_pt_gp_valid_id
);
2290 ret
= kstrtoul(page
, 0, &tmp
);
2292 pr_err("Unable to extract new ALUA access status"
2293 " from %s\n", page
);
2296 new_status
= (int)tmp
;
2298 if ((new_status
!= ALUA_STATUS_NONE
) &&
2299 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG
) &&
2300 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA
)) {
2301 pr_err("Illegal ALUA access status: 0x%02x\n",
2306 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2310 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status
, S_IRUGO
| S_IWUSR
);
2315 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2316 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2319 return core_alua_show_access_type(tg_pt_gp
, page
);
2322 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2323 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2327 return core_alua_store_access_type(tg_pt_gp
, page
, count
);
2330 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type
, S_IRUGO
| S_IWUSR
);
2333 * alua_supported_states
2336 #define SE_DEV_ALUA_SUPPORT_STATE_SHOW(_name, _var, _bit) \
2337 static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_support_##_name( \
2338 struct t10_alua_tg_pt_gp *t, char *p) \
2340 return sprintf(p, "%d\n", !!(t->_var & _bit)); \
2343 #define SE_DEV_ALUA_SUPPORT_STATE_STORE(_name, _var, _bit) \
2344 static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_support_##_name(\
2345 struct t10_alua_tg_pt_gp *t, const char *p, size_t c) \
2347 unsigned long tmp; \
2350 if (!t->tg_pt_gp_valid_id) { \
2351 pr_err("Unable to do set ##_name ALUA state on non" \
2352 " valid tg_pt_gp ID: %hu\n", \
2353 t->tg_pt_gp_valid_id); \
2357 ret = kstrtoul(p, 0, &tmp); \
2359 pr_err("Invalid value '%s', must be '0' or '1'\n", p); \
2363 pr_err("Invalid value '%ld', must be '0' or '1'\n", tmp); \
2374 SE_DEV_ALUA_SUPPORT_STATE_SHOW(transitioning
,
2375 tg_pt_gp_alua_supported_states
, ALUA_T_SUP
);
2376 SE_DEV_ALUA_SUPPORT_STATE_STORE(transitioning
,
2377 tg_pt_gp_alua_supported_states
, ALUA_T_SUP
);
2378 SE_DEV_ALUA_TG_PT_ATTR(alua_support_transitioning
, S_IRUGO
| S_IWUSR
);
2380 SE_DEV_ALUA_SUPPORT_STATE_SHOW(offline
,
2381 tg_pt_gp_alua_supported_states
, ALUA_O_SUP
);
2382 SE_DEV_ALUA_SUPPORT_STATE_STORE(offline
,
2383 tg_pt_gp_alua_supported_states
, ALUA_O_SUP
);
2384 SE_DEV_ALUA_TG_PT_ATTR(alua_support_offline
, S_IRUGO
| S_IWUSR
);
2386 SE_DEV_ALUA_SUPPORT_STATE_SHOW(lba_dependent
,
2387 tg_pt_gp_alua_supported_states
, ALUA_LBD_SUP
);
2388 SE_DEV_ALUA_SUPPORT_STATE_STORE(lba_dependent
,
2389 tg_pt_gp_alua_supported_states
, ALUA_LBD_SUP
);
2390 SE_DEV_ALUA_TG_PT_ATTR(alua_support_lba_dependent
, S_IRUGO
);
2392 SE_DEV_ALUA_SUPPORT_STATE_SHOW(unavailable
,
2393 tg_pt_gp_alua_supported_states
, ALUA_U_SUP
);
2394 SE_DEV_ALUA_SUPPORT_STATE_STORE(unavailable
,
2395 tg_pt_gp_alua_supported_states
, ALUA_U_SUP
);
2396 SE_DEV_ALUA_TG_PT_ATTR(alua_support_unavailable
, S_IRUGO
| S_IWUSR
);
2398 SE_DEV_ALUA_SUPPORT_STATE_SHOW(standby
,
2399 tg_pt_gp_alua_supported_states
, ALUA_S_SUP
);
2400 SE_DEV_ALUA_SUPPORT_STATE_STORE(standby
,
2401 tg_pt_gp_alua_supported_states
, ALUA_S_SUP
);
2402 SE_DEV_ALUA_TG_PT_ATTR(alua_support_standby
, S_IRUGO
| S_IWUSR
);
2404 SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_optimized
,
2405 tg_pt_gp_alua_supported_states
, ALUA_AO_SUP
);
2406 SE_DEV_ALUA_SUPPORT_STATE_STORE(active_optimized
,
2407 tg_pt_gp_alua_supported_states
, ALUA_AO_SUP
);
2408 SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_optimized
, S_IRUGO
| S_IWUSR
);
2410 SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_nonoptimized
,
2411 tg_pt_gp_alua_supported_states
, ALUA_AN_SUP
);
2412 SE_DEV_ALUA_SUPPORT_STATE_STORE(active_nonoptimized
,
2413 tg_pt_gp_alua_supported_states
, ALUA_AN_SUP
);
2414 SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_nonoptimized
, S_IRUGO
| S_IWUSR
);
2417 * alua_write_metadata
2419 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2420 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2423 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_write_metadata
);
2426 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2427 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2434 ret
= kstrtoul(page
, 0, &tmp
);
2436 pr_err("Unable to extract alua_write_metadata\n");
2440 if ((tmp
!= 0) && (tmp
!= 1)) {
2441 pr_err("Illegal value for alua_write_metadata:"
2445 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2450 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata
, S_IRUGO
| S_IWUSR
);
2457 static ssize_t
target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2458 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2461 return core_alua_show_nonop_delay_msecs(tg_pt_gp
, page
);
2465 static ssize_t
target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2466 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2470 return core_alua_store_nonop_delay_msecs(tg_pt_gp
, page
, count
);
2473 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs
, S_IRUGO
| S_IWUSR
);
2478 static ssize_t
target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2479 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2482 return core_alua_show_trans_delay_msecs(tg_pt_gp
, page
);
2485 static ssize_t
target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2486 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2490 return core_alua_store_trans_delay_msecs(tg_pt_gp
, page
, count
);
2493 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs
, S_IRUGO
| S_IWUSR
);
2496 * implicit_trans_secs
2498 static ssize_t
target_core_alua_tg_pt_gp_show_attr_implicit_trans_secs(
2499 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2502 return core_alua_show_implicit_trans_secs(tg_pt_gp
, page
);
2505 static ssize_t
target_core_alua_tg_pt_gp_store_attr_implicit_trans_secs(
2506 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2510 return core_alua_store_implicit_trans_secs(tg_pt_gp
, page
, count
);
2513 SE_DEV_ALUA_TG_PT_ATTR(implicit_trans_secs
, S_IRUGO
| S_IWUSR
);
2519 static ssize_t
target_core_alua_tg_pt_gp_show_attr_preferred(
2520 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2523 return core_alua_show_preferred_bit(tg_pt_gp
, page
);
2526 static ssize_t
target_core_alua_tg_pt_gp_store_attr_preferred(
2527 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2531 return core_alua_store_preferred_bit(tg_pt_gp
, page
, count
);
2534 SE_DEV_ALUA_TG_PT_ATTR(preferred
, S_IRUGO
| S_IWUSR
);
2539 static ssize_t
target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2540 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2543 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
2546 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2549 static ssize_t
target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2550 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2554 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2555 unsigned long tg_pt_gp_id
;
2558 ret
= kstrtoul(page
, 0, &tg_pt_gp_id
);
2560 pr_err("kstrtoul() returned %d for"
2561 " tg_pt_gp_id\n", ret
);
2564 if (tg_pt_gp_id
> 0x0000ffff) {
2565 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:"
2566 " 0x0000ffff\n", tg_pt_gp_id
);
2570 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2574 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
2575 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2576 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2577 tg_pt_gp
->tg_pt_gp_id
);
2582 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id
, S_IRUGO
| S_IWUSR
);
2587 static ssize_t
target_core_alua_tg_pt_gp_show_attr_members(
2588 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2591 struct se_port
*port
;
2592 struct se_portal_group
*tpg
;
2594 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
2595 ssize_t len
= 0, cur_len
;
2596 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2598 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2600 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2601 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
2602 tg_pt_gp_mem_list
) {
2603 port
= tg_pt_gp_mem
->tg_pt
;
2604 tpg
= port
->sep_tpg
;
2605 lun
= port
->sep_lun
;
2607 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2608 "/%s\n", tpg
->se_tpg_tfo
->get_fabric_name(),
2609 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
2610 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
2611 config_item_name(&lun
->lun_group
.cg_item
));
2612 cur_len
++; /* Extra byte for NULL terminator */
2614 if ((cur_len
+ len
) > PAGE_SIZE
) {
2615 pr_warn("Ran out of lu_gp_show_attr"
2616 "_members buffer\n");
2619 memcpy(page
+len
, buf
, cur_len
);
2622 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2627 SE_DEV_ALUA_TG_PT_ATTR_RO(members
);
2629 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
,
2632 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2633 &target_core_alua_tg_pt_gp_alua_access_state
.attr
,
2634 &target_core_alua_tg_pt_gp_alua_access_status
.attr
,
2635 &target_core_alua_tg_pt_gp_alua_access_type
.attr
,
2636 &target_core_alua_tg_pt_gp_alua_support_transitioning
.attr
,
2637 &target_core_alua_tg_pt_gp_alua_support_offline
.attr
,
2638 &target_core_alua_tg_pt_gp_alua_support_lba_dependent
.attr
,
2639 &target_core_alua_tg_pt_gp_alua_support_unavailable
.attr
,
2640 &target_core_alua_tg_pt_gp_alua_support_standby
.attr
,
2641 &target_core_alua_tg_pt_gp_alua_support_active_nonoptimized
.attr
,
2642 &target_core_alua_tg_pt_gp_alua_support_active_optimized
.attr
,
2643 &target_core_alua_tg_pt_gp_alua_write_metadata
.attr
,
2644 &target_core_alua_tg_pt_gp_nonop_delay_msecs
.attr
,
2645 &target_core_alua_tg_pt_gp_trans_delay_msecs
.attr
,
2646 &target_core_alua_tg_pt_gp_implicit_trans_secs
.attr
,
2647 &target_core_alua_tg_pt_gp_preferred
.attr
,
2648 &target_core_alua_tg_pt_gp_tg_pt_gp_id
.attr
,
2649 &target_core_alua_tg_pt_gp_members
.attr
,
2653 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2655 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2656 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2658 core_alua_free_tg_pt_gp(tg_pt_gp
);
2661 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2662 .release
= target_core_alua_tg_pt_gp_release
,
2663 .show_attribute
= target_core_alua_tg_pt_gp_attr_show
,
2664 .store_attribute
= target_core_alua_tg_pt_gp_attr_store
,
2667 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2668 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2669 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2670 .ct_owner
= THIS_MODULE
,
2673 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2675 /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2677 static struct config_group
*target_core_alua_create_tg_pt_gp(
2678 struct config_group
*group
,
2681 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2682 alua_tg_pt_gps_group
);
2683 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2684 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2685 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2687 tg_pt_gp
= core_alua_allocate_tg_pt_gp(alua
->t10_dev
, name
, 0);
2691 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2692 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2694 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2695 &target_core_alua_tg_pt_gp_cit
);
2697 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
2698 " Group: alua/tg_pt_gps/%s\n",
2699 config_item_name(alua_tg_pt_gp_ci
));
2701 return alua_tg_pt_gp_cg
;
2704 static void target_core_alua_drop_tg_pt_gp(
2705 struct config_group
*group
,
2706 struct config_item
*item
)
2708 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2709 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2711 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
2712 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2713 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2715 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2716 * -> target_core_alua_tg_pt_gp_release().
2718 config_item_put(item
);
2721 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2722 .make_group
= &target_core_alua_create_tg_pt_gp
,
2723 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2726 static struct config_item_type target_core_alua_tg_pt_gps_cit
= {
2727 .ct_group_ops
= &target_core_alua_tg_pt_gps_group_ops
,
2728 .ct_owner
= THIS_MODULE
,
2731 /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2733 /* Start functions for struct config_item_type target_core_alua_cit */
2736 * target_core_alua_cit is a ConfigFS group that lives under
2737 * /sys/kernel/config/target/core/alua. There are default groups
2738 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2739 * target_core_alua_cit in target_core_init_configfs() below.
2741 static struct config_item_type target_core_alua_cit
= {
2742 .ct_item_ops
= NULL
,
2744 .ct_owner
= THIS_MODULE
,
2747 /* End functions for struct config_item_type target_core_alua_cit */
2749 /* Start functions for struct config_item_type target_core_stat_cit */
2751 static struct config_group
*target_core_stat_mkdir(
2752 struct config_group
*group
,
2755 return ERR_PTR(-ENOSYS
);
2758 static void target_core_stat_rmdir(
2759 struct config_group
*group
,
2760 struct config_item
*item
)
2765 static struct configfs_group_operations target_core_stat_group_ops
= {
2766 .make_group
= &target_core_stat_mkdir
,
2767 .drop_item
= &target_core_stat_rmdir
,
2770 static struct config_item_type target_core_stat_cit
= {
2771 .ct_group_ops
= &target_core_stat_group_ops
,
2772 .ct_owner
= THIS_MODULE
,
2775 /* End functions for struct config_item_type target_core_stat_cit */
2777 /* Start functions for struct config_item_type target_core_hba_cit */
2779 static struct config_group
*target_core_make_subdev(
2780 struct config_group
*group
,
2783 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2784 struct se_subsystem_api
*t
;
2785 struct config_item
*hba_ci
= &group
->cg_item
;
2786 struct se_hba
*hba
= item_to_hba(hba_ci
);
2787 struct se_device
*dev
;
2788 struct config_group
*dev_cg
= NULL
, *tg_pt_gp_cg
= NULL
;
2789 struct config_group
*dev_stat_grp
= NULL
;
2790 int errno
= -ENOMEM
, ret
;
2792 ret
= mutex_lock_interruptible(&hba
->hba_access_mutex
);
2794 return ERR_PTR(ret
);
2796 * Locate the struct se_subsystem_api from parent's struct se_hba.
2800 dev
= target_alloc_device(hba
, name
);
2804 dev_cg
= &dev
->dev_group
;
2806 dev_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 6,
2808 if (!dev_cg
->default_groups
)
2809 goto out_free_device
;
2811 config_group_init_type_name(dev_cg
, name
, &target_core_dev_cit
);
2812 config_group_init_type_name(&dev
->dev_attrib
.da_group
, "attrib",
2813 &target_core_dev_attrib_cit
);
2814 config_group_init_type_name(&dev
->dev_pr_group
, "pr",
2815 &target_core_dev_pr_cit
);
2816 config_group_init_type_name(&dev
->t10_wwn
.t10_wwn_group
, "wwn",
2817 &target_core_dev_wwn_cit
);
2818 config_group_init_type_name(&dev
->t10_alua
.alua_tg_pt_gps_group
,
2819 "alua", &target_core_alua_tg_pt_gps_cit
);
2820 config_group_init_type_name(&dev
->dev_stat_grps
.stat_group
,
2821 "statistics", &target_core_stat_cit
);
2823 dev_cg
->default_groups
[0] = &dev
->dev_attrib
.da_group
;
2824 dev_cg
->default_groups
[1] = &dev
->dev_pr_group
;
2825 dev_cg
->default_groups
[2] = &dev
->t10_wwn
.t10_wwn_group
;
2826 dev_cg
->default_groups
[3] = &dev
->t10_alua
.alua_tg_pt_gps_group
;
2827 dev_cg
->default_groups
[4] = &dev
->dev_stat_grps
.stat_group
;
2828 dev_cg
->default_groups
[5] = NULL
;
2830 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
2832 tg_pt_gp
= core_alua_allocate_tg_pt_gp(dev
, "default_tg_pt_gp", 1);
2834 goto out_free_dev_cg_default_groups
;
2835 dev
->t10_alua
.default_tg_pt_gp
= tg_pt_gp
;
2837 tg_pt_gp_cg
= &dev
->t10_alua
.alua_tg_pt_gps_group
;
2838 tg_pt_gp_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
2840 if (!tg_pt_gp_cg
->default_groups
) {
2841 pr_err("Unable to allocate tg_pt_gp_cg->"
2842 "default_groups\n");
2843 goto out_free_tg_pt_gp
;
2846 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2847 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2848 tg_pt_gp_cg
->default_groups
[0] = &tg_pt_gp
->tg_pt_gp_group
;
2849 tg_pt_gp_cg
->default_groups
[1] = NULL
;
2851 * Add core/$HBA/$DEV/statistics/ default groups
2853 dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
2854 dev_stat_grp
->default_groups
= kmalloc(sizeof(struct config_group
*) * 4,
2856 if (!dev_stat_grp
->default_groups
) {
2857 pr_err("Unable to allocate dev_stat_grp->default_groups\n");
2858 goto out_free_tg_pt_gp_cg_default_groups
;
2860 target_stat_setup_dev_default_groups(dev
);
2862 mutex_unlock(&hba
->hba_access_mutex
);
2865 out_free_tg_pt_gp_cg_default_groups
:
2866 kfree(tg_pt_gp_cg
->default_groups
);
2868 core_alua_free_tg_pt_gp(tg_pt_gp
);
2869 out_free_dev_cg_default_groups
:
2870 kfree(dev_cg
->default_groups
);
2872 target_free_device(dev
);
2874 mutex_unlock(&hba
->hba_access_mutex
);
2875 return ERR_PTR(errno
);
2878 static void target_core_drop_subdev(
2879 struct config_group
*group
,
2880 struct config_item
*item
)
2882 struct config_group
*dev_cg
= to_config_group(item
);
2883 struct se_device
*dev
=
2884 container_of(dev_cg
, struct se_device
, dev_group
);
2886 struct config_item
*df_item
;
2887 struct config_group
*tg_pt_gp_cg
, *dev_stat_grp
;
2890 hba
= item_to_hba(&dev
->se_hba
->hba_group
.cg_item
);
2892 mutex_lock(&hba
->hba_access_mutex
);
2894 dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
2895 for (i
= 0; dev_stat_grp
->default_groups
[i
]; i
++) {
2896 df_item
= &dev_stat_grp
->default_groups
[i
]->cg_item
;
2897 dev_stat_grp
->default_groups
[i
] = NULL
;
2898 config_item_put(df_item
);
2900 kfree(dev_stat_grp
->default_groups
);
2902 tg_pt_gp_cg
= &dev
->t10_alua
.alua_tg_pt_gps_group
;
2903 for (i
= 0; tg_pt_gp_cg
->default_groups
[i
]; i
++) {
2904 df_item
= &tg_pt_gp_cg
->default_groups
[i
]->cg_item
;
2905 tg_pt_gp_cg
->default_groups
[i
] = NULL
;
2906 config_item_put(df_item
);
2908 kfree(tg_pt_gp_cg
->default_groups
);
2910 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2911 * directly from target_core_alua_tg_pt_gp_release().
2913 dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2915 for (i
= 0; dev_cg
->default_groups
[i
]; i
++) {
2916 df_item
= &dev_cg
->default_groups
[i
]->cg_item
;
2917 dev_cg
->default_groups
[i
] = NULL
;
2918 config_item_put(df_item
);
2921 * se_dev is released from target_core_dev_item_ops->release()
2923 config_item_put(item
);
2924 mutex_unlock(&hba
->hba_access_mutex
);
2927 static struct configfs_group_operations target_core_hba_group_ops
= {
2928 .make_group
= target_core_make_subdev
,
2929 .drop_item
= target_core_drop_subdev
,
2932 CONFIGFS_EATTR_STRUCT(target_core_hba
, se_hba
);
2933 #define SE_HBA_ATTR(_name, _mode) \
2934 static struct target_core_hba_attribute \
2935 target_core_hba_##_name = \
2936 __CONFIGFS_EATTR(_name, _mode, \
2937 target_core_hba_show_attr_##_name, \
2938 target_core_hba_store_attr_##_name);
2940 #define SE_HBA_ATTR_RO(_name) \
2941 static struct target_core_hba_attribute \
2942 target_core_hba_##_name = \
2943 __CONFIGFS_EATTR_RO(_name, \
2944 target_core_hba_show_attr_##_name);
2946 static ssize_t
target_core_hba_show_attr_hba_info(
2950 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
2951 hba
->hba_id
, hba
->transport
->name
,
2952 TARGET_CORE_CONFIGFS_VERSION
);
2955 SE_HBA_ATTR_RO(hba_info
);
2957 static ssize_t
target_core_hba_show_attr_hba_mode(struct se_hba
*hba
,
2962 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
2965 return sprintf(page
, "%d\n", hba_mode
);
2968 static ssize_t
target_core_hba_store_attr_hba_mode(struct se_hba
*hba
,
2969 const char *page
, size_t count
)
2971 struct se_subsystem_api
*transport
= hba
->transport
;
2972 unsigned long mode_flag
;
2975 if (transport
->pmode_enable_hba
== NULL
)
2978 ret
= kstrtoul(page
, 0, &mode_flag
);
2980 pr_err("Unable to extract hba mode flag: %d\n", ret
);
2984 if (hba
->dev_count
) {
2985 pr_err("Unable to set hba_mode with active devices\n");
2989 ret
= transport
->pmode_enable_hba(hba
, mode_flag
);
2993 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
2995 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
3000 SE_HBA_ATTR(hba_mode
, S_IRUGO
| S_IWUSR
);
3002 CONFIGFS_EATTR_OPS(target_core_hba
, se_hba
, hba_group
);
3004 static void target_core_hba_release(struct config_item
*item
)
3006 struct se_hba
*hba
= container_of(to_config_group(item
),
3007 struct se_hba
, hba_group
);
3008 core_delete_hba(hba
);
3011 static struct configfs_attribute
*target_core_hba_attrs
[] = {
3012 &target_core_hba_hba_info
.attr
,
3013 &target_core_hba_hba_mode
.attr
,
3017 static struct configfs_item_operations target_core_hba_item_ops
= {
3018 .release
= target_core_hba_release
,
3019 .show_attribute
= target_core_hba_attr_show
,
3020 .store_attribute
= target_core_hba_attr_store
,
3023 static struct config_item_type target_core_hba_cit
= {
3024 .ct_item_ops
= &target_core_hba_item_ops
,
3025 .ct_group_ops
= &target_core_hba_group_ops
,
3026 .ct_attrs
= target_core_hba_attrs
,
3027 .ct_owner
= THIS_MODULE
,
3030 static struct config_group
*target_core_call_addhbatotarget(
3031 struct config_group
*group
,
3034 char *se_plugin_str
, *str
, *str2
;
3036 char buf
[TARGET_CORE_NAME_MAX_LEN
];
3037 unsigned long plugin_dep_id
= 0;
3040 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
3041 if (strlen(name
) >= TARGET_CORE_NAME_MAX_LEN
) {
3042 pr_err("Passed *name strlen(): %d exceeds"
3043 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
3044 TARGET_CORE_NAME_MAX_LEN
);
3045 return ERR_PTR(-ENAMETOOLONG
);
3047 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
3049 str
= strstr(buf
, "_");
3051 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
3052 return ERR_PTR(-EINVAL
);
3054 se_plugin_str
= buf
;
3056 * Special case for subsystem plugins that have "_" in their names.
3057 * Namely rd_direct and rd_mcp..
3059 str2
= strstr(str
+1, "_");
3061 *str2
= '\0'; /* Terminate for *se_plugin_str */
3062 str2
++; /* Skip to start of plugin dependent ID */
3065 *str
= '\0'; /* Terminate for *se_plugin_str */
3066 str
++; /* Skip to start of plugin dependent ID */
3069 ret
= kstrtoul(str
, 0, &plugin_dep_id
);
3071 pr_err("kstrtoul() returned %d for"
3072 " plugin_dep_id\n", ret
);
3073 return ERR_PTR(ret
);
3076 * Load up TCM subsystem plugins if they have not already been loaded.
3078 transport_subsystem_check_init();
3080 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
3082 return ERR_CAST(hba
);
3084 config_group_init_type_name(&hba
->hba_group
, name
,
3085 &target_core_hba_cit
);
3087 return &hba
->hba_group
;
3090 static void target_core_call_delhbafromtarget(
3091 struct config_group
*group
,
3092 struct config_item
*item
)
3095 * core_delete_hba() is called from target_core_hba_item_ops->release()
3096 * -> target_core_hba_release()
3098 config_item_put(item
);
3101 static struct configfs_group_operations target_core_group_ops
= {
3102 .make_group
= target_core_call_addhbatotarget
,
3103 .drop_item
= target_core_call_delhbafromtarget
,
3106 static struct config_item_type target_core_cit
= {
3107 .ct_item_ops
= NULL
,
3108 .ct_group_ops
= &target_core_group_ops
,
3110 .ct_owner
= THIS_MODULE
,
3113 /* Stop functions for struct config_item_type target_core_hba_cit */
3115 static int __init
target_core_init_configfs(void)
3117 struct config_group
*target_cg
, *hba_cg
= NULL
, *alua_cg
= NULL
;
3118 struct config_group
*lu_gp_cg
= NULL
;
3119 struct configfs_subsystem
*subsys
;
3120 struct t10_alua_lu_gp
*lu_gp
;
3123 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
3124 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
3125 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
3127 subsys
= target_core_subsystem
[0];
3128 config_group_init(&subsys
->su_group
);
3129 mutex_init(&subsys
->su_mutex
);
3131 ret
= init_se_kmem_caches();
3135 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
3136 * and ALUA Logical Unit Group and Target Port Group infrastructure.
3138 target_cg
= &subsys
->su_group
;
3139 target_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3141 if (!target_cg
->default_groups
) {
3142 pr_err("Unable to allocate target_cg->default_groups\n");
3147 config_group_init_type_name(&target_core_hbagroup
,
3148 "core", &target_core_cit
);
3149 target_cg
->default_groups
[0] = &target_core_hbagroup
;
3150 target_cg
->default_groups
[1] = NULL
;
3152 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
3154 hba_cg
= &target_core_hbagroup
;
3155 hba_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3157 if (!hba_cg
->default_groups
) {
3158 pr_err("Unable to allocate hba_cg->default_groups\n");
3162 config_group_init_type_name(&alua_group
,
3163 "alua", &target_core_alua_cit
);
3164 hba_cg
->default_groups
[0] = &alua_group
;
3165 hba_cg
->default_groups
[1] = NULL
;
3167 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
3168 * groups under /sys/kernel/config/target/core/alua/
3170 alua_cg
= &alua_group
;
3171 alua_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3173 if (!alua_cg
->default_groups
) {
3174 pr_err("Unable to allocate alua_cg->default_groups\n");
3179 config_group_init_type_name(&alua_lu_gps_group
,
3180 "lu_gps", &target_core_alua_lu_gps_cit
);
3181 alua_cg
->default_groups
[0] = &alua_lu_gps_group
;
3182 alua_cg
->default_groups
[1] = NULL
;
3184 * Add core/alua/lu_gps/default_lu_gp
3186 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
3187 if (IS_ERR(lu_gp
)) {
3192 lu_gp_cg
= &alua_lu_gps_group
;
3193 lu_gp_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3195 if (!lu_gp_cg
->default_groups
) {
3196 pr_err("Unable to allocate lu_gp_cg->default_groups\n");
3201 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
3202 &target_core_alua_lu_gp_cit
);
3203 lu_gp_cg
->default_groups
[0] = &lu_gp
->lu_gp_group
;
3204 lu_gp_cg
->default_groups
[1] = NULL
;
3205 default_lu_gp
= lu_gp
;
3207 * Register the target_core_mod subsystem with configfs.
3209 ret
= configfs_register_subsystem(subsys
);
3211 pr_err("Error %d while registering subsystem %s\n",
3212 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
3215 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
3216 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION
" on %s/%s"
3217 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
3219 * Register built-in RAMDISK subsystem logic for virtual LUN 0
3221 ret
= rd_module_init();
3225 ret
= core_dev_setup_virtual_lun0();
3229 ret
= target_xcopy_setup_pt();
3236 configfs_unregister_subsystem(subsys
);
3237 core_dev_release_virtual_lun0();
3240 if (default_lu_gp
) {
3241 core_alua_free_lu_gp(default_lu_gp
);
3242 default_lu_gp
= NULL
;
3245 kfree(lu_gp_cg
->default_groups
);
3247 kfree(alua_cg
->default_groups
);
3249 kfree(hba_cg
->default_groups
);
3250 kfree(target_cg
->default_groups
);
3251 release_se_kmem_caches();
3255 static void __exit
target_core_exit_configfs(void)
3257 struct configfs_subsystem
*subsys
;
3258 struct config_group
*hba_cg
, *alua_cg
, *lu_gp_cg
;
3259 struct config_item
*item
;
3262 subsys
= target_core_subsystem
[0];
3264 lu_gp_cg
= &alua_lu_gps_group
;
3265 for (i
= 0; lu_gp_cg
->default_groups
[i
]; i
++) {
3266 item
= &lu_gp_cg
->default_groups
[i
]->cg_item
;
3267 lu_gp_cg
->default_groups
[i
] = NULL
;
3268 config_item_put(item
);
3270 kfree(lu_gp_cg
->default_groups
);
3271 lu_gp_cg
->default_groups
= NULL
;
3273 alua_cg
= &alua_group
;
3274 for (i
= 0; alua_cg
->default_groups
[i
]; i
++) {
3275 item
= &alua_cg
->default_groups
[i
]->cg_item
;
3276 alua_cg
->default_groups
[i
] = NULL
;
3277 config_item_put(item
);
3279 kfree(alua_cg
->default_groups
);
3280 alua_cg
->default_groups
= NULL
;
3282 hba_cg
= &target_core_hbagroup
;
3283 for (i
= 0; hba_cg
->default_groups
[i
]; i
++) {
3284 item
= &hba_cg
->default_groups
[i
]->cg_item
;
3285 hba_cg
->default_groups
[i
] = NULL
;
3286 config_item_put(item
);
3288 kfree(hba_cg
->default_groups
);
3289 hba_cg
->default_groups
= NULL
;
3291 * We expect subsys->su_group.default_groups to be released
3292 * by configfs subsystem provider logic..
3294 configfs_unregister_subsystem(subsys
);
3295 kfree(subsys
->su_group
.default_groups
);
3297 core_alua_free_lu_gp(default_lu_gp
);
3298 default_lu_gp
= NULL
;
3300 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
3301 " Infrastructure\n");
3303 core_dev_release_virtual_lun0();
3305 target_xcopy_release_pt();
3306 release_se_kmem_caches();
3309 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3310 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3311 MODULE_LICENSE("GPL");
3313 module_init(target_core_init_configfs
);
3314 module_exit(target_core_exit_configfs
);