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(force_pr_aptpl
);
669 SE_DEV_ATTR(force_pr_aptpl
, S_IRUGO
| S_IWUSR
);
671 DEF_DEV_ATTRIB_RO(hw_block_size
);
672 SE_DEV_ATTR_RO(hw_block_size
);
674 DEF_DEV_ATTRIB(block_size
);
675 SE_DEV_ATTR(block_size
, S_IRUGO
| S_IWUSR
);
677 DEF_DEV_ATTRIB_RO(hw_max_sectors
);
678 SE_DEV_ATTR_RO(hw_max_sectors
);
680 DEF_DEV_ATTRIB(fabric_max_sectors
);
681 SE_DEV_ATTR(fabric_max_sectors
, S_IRUGO
| S_IWUSR
);
683 DEF_DEV_ATTRIB(optimal_sectors
);
684 SE_DEV_ATTR(optimal_sectors
, S_IRUGO
| S_IWUSR
);
686 DEF_DEV_ATTRIB_RO(hw_queue_depth
);
687 SE_DEV_ATTR_RO(hw_queue_depth
);
689 DEF_DEV_ATTRIB(queue_depth
);
690 SE_DEV_ATTR(queue_depth
, S_IRUGO
| S_IWUSR
);
692 DEF_DEV_ATTRIB(max_unmap_lba_count
);
693 SE_DEV_ATTR(max_unmap_lba_count
, S_IRUGO
| S_IWUSR
);
695 DEF_DEV_ATTRIB(max_unmap_block_desc_count
);
696 SE_DEV_ATTR(max_unmap_block_desc_count
, S_IRUGO
| S_IWUSR
);
698 DEF_DEV_ATTRIB(unmap_granularity
);
699 SE_DEV_ATTR(unmap_granularity
, S_IRUGO
| S_IWUSR
);
701 DEF_DEV_ATTRIB(unmap_granularity_alignment
);
702 SE_DEV_ATTR(unmap_granularity_alignment
, S_IRUGO
| S_IWUSR
);
704 DEF_DEV_ATTRIB(max_write_same_len
);
705 SE_DEV_ATTR(max_write_same_len
, S_IRUGO
| S_IWUSR
);
707 CONFIGFS_EATTR_OPS(target_core_dev_attrib
, se_dev_attrib
, da_group
);
709 static struct configfs_attribute
*target_core_dev_attrib_attrs
[] = {
710 &target_core_dev_attrib_emulate_model_alias
.attr
,
711 &target_core_dev_attrib_emulate_dpo
.attr
,
712 &target_core_dev_attrib_emulate_fua_write
.attr
,
713 &target_core_dev_attrib_emulate_fua_read
.attr
,
714 &target_core_dev_attrib_emulate_write_cache
.attr
,
715 &target_core_dev_attrib_emulate_ua_intlck_ctrl
.attr
,
716 &target_core_dev_attrib_emulate_tas
.attr
,
717 &target_core_dev_attrib_emulate_tpu
.attr
,
718 &target_core_dev_attrib_emulate_tpws
.attr
,
719 &target_core_dev_attrib_emulate_caw
.attr
,
720 &target_core_dev_attrib_emulate_3pc
.attr
,
721 &target_core_dev_attrib_pi_prot_type
.attr
,
722 &target_core_dev_attrib_hw_pi_prot_type
.attr
,
723 &target_core_dev_attrib_pi_prot_format
.attr
,
724 &target_core_dev_attrib_enforce_pr_isids
.attr
,
725 &target_core_dev_attrib_force_pr_aptpl
.attr
,
726 &target_core_dev_attrib_is_nonrot
.attr
,
727 &target_core_dev_attrib_emulate_rest_reord
.attr
,
728 &target_core_dev_attrib_hw_block_size
.attr
,
729 &target_core_dev_attrib_block_size
.attr
,
730 &target_core_dev_attrib_hw_max_sectors
.attr
,
731 &target_core_dev_attrib_fabric_max_sectors
.attr
,
732 &target_core_dev_attrib_optimal_sectors
.attr
,
733 &target_core_dev_attrib_hw_queue_depth
.attr
,
734 &target_core_dev_attrib_queue_depth
.attr
,
735 &target_core_dev_attrib_max_unmap_lba_count
.attr
,
736 &target_core_dev_attrib_max_unmap_block_desc_count
.attr
,
737 &target_core_dev_attrib_unmap_granularity
.attr
,
738 &target_core_dev_attrib_unmap_granularity_alignment
.attr
,
739 &target_core_dev_attrib_max_write_same_len
.attr
,
743 static struct configfs_item_operations target_core_dev_attrib_ops
= {
744 .show_attribute
= target_core_dev_attrib_attr_show
,
745 .store_attribute
= target_core_dev_attrib_attr_store
,
748 static struct config_item_type target_core_dev_attrib_cit
= {
749 .ct_item_ops
= &target_core_dev_attrib_ops
,
750 .ct_attrs
= target_core_dev_attrib_attrs
,
751 .ct_owner
= THIS_MODULE
,
754 /* End functions for struct config_item_type target_core_dev_attrib_cit */
756 /* Start functions for struct config_item_type target_core_dev_wwn_cit */
758 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn
, t10_wwn
);
759 #define SE_DEV_WWN_ATTR(_name, _mode) \
760 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
761 __CONFIGFS_EATTR(_name, _mode, \
762 target_core_dev_wwn_show_attr_##_name, \
763 target_core_dev_wwn_store_attr_##_name);
765 #define SE_DEV_WWN_ATTR_RO(_name); \
767 static struct target_core_dev_wwn_attribute \
768 target_core_dev_wwn_##_name = \
769 __CONFIGFS_EATTR_RO(_name, \
770 target_core_dev_wwn_show_attr_##_name); \
774 * VPD page 0x80 Unit serial
776 static ssize_t
target_core_dev_wwn_show_attr_vpd_unit_serial(
777 struct t10_wwn
*t10_wwn
,
780 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
781 &t10_wwn
->unit_serial
[0]);
784 static ssize_t
target_core_dev_wwn_store_attr_vpd_unit_serial(
785 struct t10_wwn
*t10_wwn
,
789 struct se_device
*dev
= t10_wwn
->t10_dev
;
790 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
793 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
794 * from the struct scsi_device level firmware, do not allow
795 * VPD Unit Serial to be emulated.
797 * Note this struct scsi_device could also be emulating VPD
798 * information from its drivers/scsi LLD. But for now we assume
799 * it is doing 'the right thing' wrt a world wide unique
800 * VPD Unit Serial Number that OS dependent multipath can depend on.
802 if (dev
->dev_flags
& DF_FIRMWARE_VPD_UNIT_SERIAL
) {
803 pr_err("Underlying SCSI device firmware provided VPD"
804 " Unit Serial, ignoring request\n");
808 if (strlen(page
) >= INQUIRY_VPD_SERIAL_LEN
) {
809 pr_err("Emulated VPD Unit Serial exceeds"
810 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
814 * Check to see if any active $FABRIC_MOD exports exist. If they
815 * do exist, fail here as changing this information on the fly
816 * (underneath the initiator side OS dependent multipath code)
817 * could cause negative effects.
819 if (dev
->export_count
) {
820 pr_err("Unable to set VPD Unit Serial while"
821 " active %d $FABRIC_MOD exports exist\n",
827 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
829 * Also, strip any newline added from the userspace
830 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
832 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
833 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
834 snprintf(dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
835 "%s", strstrip(buf
));
836 dev
->dev_flags
|= DF_EMULATED_VPD_UNIT_SERIAL
;
838 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
839 " %s\n", dev
->t10_wwn
.unit_serial
);
844 SE_DEV_WWN_ATTR(vpd_unit_serial
, S_IRUGO
| S_IWUSR
);
847 * VPD page 0x83 Protocol Identifier
849 static ssize_t
target_core_dev_wwn_show_attr_vpd_protocol_identifier(
850 struct t10_wwn
*t10_wwn
,
854 unsigned char buf
[VPD_TMP_BUF_SIZE
];
857 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
859 spin_lock(&t10_wwn
->t10_vpd_lock
);
860 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
861 if (!vpd
->protocol_identifier_set
)
864 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
866 if (len
+ strlen(buf
) >= PAGE_SIZE
)
869 len
+= sprintf(page
+len
, "%s", buf
);
871 spin_unlock(&t10_wwn
->t10_vpd_lock
);
876 static ssize_t
target_core_dev_wwn_store_attr_vpd_protocol_identifier(
877 struct t10_wwn
*t10_wwn
,
884 SE_DEV_WWN_ATTR(vpd_protocol_identifier
, S_IRUGO
| S_IWUSR
);
887 * Generic wrapper for dumping VPD identifiers by association.
889 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
890 static ssize_t target_core_dev_wwn_show_attr_##_name( \
891 struct t10_wwn *t10_wwn, \
894 struct t10_vpd *vpd; \
895 unsigned char buf[VPD_TMP_BUF_SIZE]; \
898 spin_lock(&t10_wwn->t10_vpd_lock); \
899 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
900 if (vpd->association != _assoc) \
903 memset(buf, 0, VPD_TMP_BUF_SIZE); \
904 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
905 if (len + strlen(buf) >= PAGE_SIZE) \
907 len += sprintf(page+len, "%s", buf); \
909 memset(buf, 0, VPD_TMP_BUF_SIZE); \
910 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
911 if (len + strlen(buf) >= PAGE_SIZE) \
913 len += sprintf(page+len, "%s", buf); \
915 memset(buf, 0, VPD_TMP_BUF_SIZE); \
916 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
917 if (len + strlen(buf) >= PAGE_SIZE) \
919 len += sprintf(page+len, "%s", buf); \
921 spin_unlock(&t10_wwn->t10_vpd_lock); \
927 * VPD page 0x83 Association: Logical Unit
929 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
931 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
932 struct t10_wwn
*t10_wwn
,
939 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit
, S_IRUGO
| S_IWUSR
);
942 * VPD page 0x83 Association: Target Port
944 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
946 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_target_port(
947 struct t10_wwn
*t10_wwn
,
954 SE_DEV_WWN_ATTR(vpd_assoc_target_port
, S_IRUGO
| S_IWUSR
);
957 * VPD page 0x83 Association: SCSI Target Device
959 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
961 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
962 struct t10_wwn
*t10_wwn
,
969 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device
, S_IRUGO
| S_IWUSR
);
971 CONFIGFS_EATTR_OPS(target_core_dev_wwn
, t10_wwn
, t10_wwn_group
);
973 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
974 &target_core_dev_wwn_vpd_unit_serial
.attr
,
975 &target_core_dev_wwn_vpd_protocol_identifier
.attr
,
976 &target_core_dev_wwn_vpd_assoc_logical_unit
.attr
,
977 &target_core_dev_wwn_vpd_assoc_target_port
.attr
,
978 &target_core_dev_wwn_vpd_assoc_scsi_target_device
.attr
,
982 static struct configfs_item_operations target_core_dev_wwn_ops
= {
983 .show_attribute
= target_core_dev_wwn_attr_show
,
984 .store_attribute
= target_core_dev_wwn_attr_store
,
987 static struct config_item_type target_core_dev_wwn_cit
= {
988 .ct_item_ops
= &target_core_dev_wwn_ops
,
989 .ct_attrs
= target_core_dev_wwn_attrs
,
990 .ct_owner
= THIS_MODULE
,
993 /* End functions for struct config_item_type target_core_dev_wwn_cit */
995 /* Start functions for struct config_item_type target_core_dev_pr_cit */
997 CONFIGFS_EATTR_STRUCT(target_core_dev_pr
, se_device
);
998 #define SE_DEV_PR_ATTR(_name, _mode) \
999 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1000 __CONFIGFS_EATTR(_name, _mode, \
1001 target_core_dev_pr_show_attr_##_name, \
1002 target_core_dev_pr_store_attr_##_name);
1004 #define SE_DEV_PR_ATTR_RO(_name); \
1005 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1006 __CONFIGFS_EATTR_RO(_name, \
1007 target_core_dev_pr_show_attr_##_name);
1009 static ssize_t
target_core_dev_pr_show_spc3_res(struct se_device
*dev
,
1012 struct se_node_acl
*se_nacl
;
1013 struct t10_pr_registration
*pr_reg
;
1014 char i_buf
[PR_REG_ISID_ID_LEN
];
1016 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1018 pr_reg
= dev
->dev_pr_res_holder
;
1020 return sprintf(page
, "No SPC-3 Reservation holder\n");
1022 se_nacl
= pr_reg
->pr_reg_nacl
;
1023 core_pr_dump_initiator_port(pr_reg
, i_buf
, PR_REG_ISID_ID_LEN
);
1025 return sprintf(page
, "SPC-3 Reservation: %s Initiator: %s%s\n",
1026 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1027 se_nacl
->initiatorname
, i_buf
);
1030 static ssize_t
target_core_dev_pr_show_spc2_res(struct se_device
*dev
,
1033 struct se_node_acl
*se_nacl
;
1036 se_nacl
= dev
->dev_reserved_node_acl
;
1039 "SPC-2 Reservation: %s Initiator: %s\n",
1040 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1041 se_nacl
->initiatorname
);
1043 len
= sprintf(page
, "No SPC-2 Reservation holder\n");
1048 static ssize_t
target_core_dev_pr_show_attr_res_holder(struct se_device
*dev
,
1053 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1054 return sprintf(page
, "Passthrough\n");
1056 spin_lock(&dev
->dev_reservation_lock
);
1057 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1058 ret
= target_core_dev_pr_show_spc2_res(dev
, page
);
1060 ret
= target_core_dev_pr_show_spc3_res(dev
, page
);
1061 spin_unlock(&dev
->dev_reservation_lock
);
1065 SE_DEV_PR_ATTR_RO(res_holder
);
1067 static ssize_t
target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1068 struct se_device
*dev
, char *page
)
1072 spin_lock(&dev
->dev_reservation_lock
);
1073 if (!dev
->dev_pr_res_holder
) {
1074 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1075 } else if (dev
->dev_pr_res_holder
->pr_reg_all_tg_pt
) {
1076 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1077 " Ports registration\n");
1079 len
= sprintf(page
, "SPC-3 Reservation: Single"
1080 " Target Port registration\n");
1083 spin_unlock(&dev
->dev_reservation_lock
);
1087 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts
);
1089 static ssize_t
target_core_dev_pr_show_attr_res_pr_generation(
1090 struct se_device
*dev
, char *page
)
1092 return sprintf(page
, "0x%08x\n", dev
->t10_pr
.pr_generation
);
1095 SE_DEV_PR_ATTR_RO(res_pr_generation
);
1098 * res_pr_holder_tg_port
1100 static ssize_t
target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1101 struct se_device
*dev
, char *page
)
1103 struct se_node_acl
*se_nacl
;
1105 struct se_portal_group
*se_tpg
;
1106 struct t10_pr_registration
*pr_reg
;
1107 struct target_core_fabric_ops
*tfo
;
1110 spin_lock(&dev
->dev_reservation_lock
);
1111 pr_reg
= dev
->dev_pr_res_holder
;
1113 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1117 se_nacl
= pr_reg
->pr_reg_nacl
;
1118 se_tpg
= se_nacl
->se_tpg
;
1119 lun
= pr_reg
->pr_reg_tg_pt_lun
;
1120 tfo
= se_tpg
->se_tpg_tfo
;
1122 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1123 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1124 tfo
->tpg_get_wwn(se_tpg
));
1125 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1126 " Identifier Tag: %hu %s Portal Group Tag: %hu"
1127 " %s Logical Unit: %u\n", lun
->lun_sep
->sep_rtpi
,
1128 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1129 tfo
->get_fabric_name(), lun
->unpacked_lun
);
1132 spin_unlock(&dev
->dev_reservation_lock
);
1136 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port
);
1138 static ssize_t
target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1139 struct se_device
*dev
, char *page
)
1141 struct target_core_fabric_ops
*tfo
;
1142 struct t10_pr_registration
*pr_reg
;
1143 unsigned char buf
[384];
1144 char i_buf
[PR_REG_ISID_ID_LEN
];
1148 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1150 spin_lock(&dev
->t10_pr
.registration_lock
);
1151 list_for_each_entry(pr_reg
, &dev
->t10_pr
.registration_list
,
1154 memset(buf
, 0, 384);
1155 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1156 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1157 core_pr_dump_initiator_port(pr_reg
, i_buf
,
1158 PR_REG_ISID_ID_LEN
);
1159 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1160 tfo
->get_fabric_name(),
1161 pr_reg
->pr_reg_nacl
->initiatorname
, i_buf
, pr_reg
->pr_res_key
,
1162 pr_reg
->pr_res_generation
);
1164 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1167 len
+= sprintf(page
+len
, "%s", buf
);
1170 spin_unlock(&dev
->t10_pr
.registration_lock
);
1173 len
+= sprintf(page
+len
, "None\n");
1178 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts
);
1180 static ssize_t
target_core_dev_pr_show_attr_res_pr_type(
1181 struct se_device
*dev
, char *page
)
1183 struct t10_pr_registration
*pr_reg
;
1186 spin_lock(&dev
->dev_reservation_lock
);
1187 pr_reg
= dev
->dev_pr_res_holder
;
1189 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1190 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1192 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1195 spin_unlock(&dev
->dev_reservation_lock
);
1199 SE_DEV_PR_ATTR_RO(res_pr_type
);
1201 static ssize_t
target_core_dev_pr_show_attr_res_type(
1202 struct se_device
*dev
, char *page
)
1204 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1205 return sprintf(page
, "SPC_PASSTHROUGH\n");
1206 else if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1207 return sprintf(page
, "SPC2_RESERVATIONS\n");
1209 return sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1212 SE_DEV_PR_ATTR_RO(res_type
);
1214 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_active(
1215 struct se_device
*dev
, char *page
)
1217 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1220 return sprintf(page
, "APTPL Bit Status: %s\n",
1221 (dev
->t10_pr
.pr_aptpl_active
) ? "Activated" : "Disabled");
1224 SE_DEV_PR_ATTR_RO(res_aptpl_active
);
1227 * res_aptpl_metadata
1229 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_metadata(
1230 struct se_device
*dev
, char *page
)
1232 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1235 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1239 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1240 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1241 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1242 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1245 static match_table_t tokens
= {
1246 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1247 {Opt_initiator_node
, "initiator_node=%s"},
1248 {Opt_initiator_sid
, "initiator_sid=%s"},
1249 {Opt_sa_res_key
, "sa_res_key=%s"},
1250 {Opt_res_holder
, "res_holder=%d"},
1251 {Opt_res_type
, "res_type=%d"},
1252 {Opt_res_scope
, "res_scope=%d"},
1253 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1254 {Opt_mapped_lun
, "mapped_lun=%d"},
1255 {Opt_target_fabric
, "target_fabric=%s"},
1256 {Opt_target_node
, "target_node=%s"},
1257 {Opt_tpgt
, "tpgt=%d"},
1258 {Opt_port_rtpi
, "port_rtpi=%d"},
1259 {Opt_target_lun
, "target_lun=%d"},
1263 static ssize_t
target_core_dev_pr_store_attr_res_aptpl_metadata(
1264 struct se_device
*dev
,
1268 unsigned char *i_fabric
= NULL
, *i_port
= NULL
, *isid
= NULL
;
1269 unsigned char *t_fabric
= NULL
, *t_port
= NULL
;
1270 char *orig
, *ptr
, *opts
;
1271 substring_t args
[MAX_OPT_ARGS
];
1272 unsigned long long tmp_ll
;
1274 u32 mapped_lun
= 0, target_lun
= 0;
1275 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1276 u16 port_rpti
= 0, tpgt
= 0;
1279 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1281 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1284 if (dev
->export_count
) {
1285 pr_debug("Unable to process APTPL metadata while"
1286 " active fabric exports exist\n");
1290 opts
= kstrdup(page
, GFP_KERNEL
);
1295 while ((ptr
= strsep(&opts
, ",\n")) != NULL
) {
1299 token
= match_token(ptr
, tokens
, args
);
1301 case Opt_initiator_fabric
:
1302 i_fabric
= match_strdup(args
);
1308 case Opt_initiator_node
:
1309 i_port
= match_strdup(args
);
1314 if (strlen(i_port
) >= PR_APTPL_MAX_IPORT_LEN
) {
1315 pr_err("APTPL metadata initiator_node="
1316 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1317 PR_APTPL_MAX_IPORT_LEN
);
1322 case Opt_initiator_sid
:
1323 isid
= match_strdup(args
);
1328 if (strlen(isid
) >= PR_REG_ISID_LEN
) {
1329 pr_err("APTPL metadata initiator_isid"
1330 "= exceeds PR_REG_ISID_LEN: %d\n",
1336 case Opt_sa_res_key
:
1337 ret
= kstrtoull(args
->from
, 0, &tmp_ll
);
1339 pr_err("kstrtoull() failed for sa_res_key=\n");
1342 sa_res_key
= (u64
)tmp_ll
;
1345 * PR APTPL Metadata for Reservation
1347 case Opt_res_holder
:
1348 match_int(args
, &arg
);
1352 match_int(args
, &arg
);
1356 match_int(args
, &arg
);
1359 case Opt_res_all_tg_pt
:
1360 match_int(args
, &arg
);
1361 all_tg_pt
= (int)arg
;
1363 case Opt_mapped_lun
:
1364 match_int(args
, &arg
);
1365 mapped_lun
= (u32
)arg
;
1368 * PR APTPL Metadata for Target Port
1370 case Opt_target_fabric
:
1371 t_fabric
= match_strdup(args
);
1377 case Opt_target_node
:
1378 t_port
= match_strdup(args
);
1383 if (strlen(t_port
) >= PR_APTPL_MAX_TPORT_LEN
) {
1384 pr_err("APTPL metadata target_node="
1385 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1386 PR_APTPL_MAX_TPORT_LEN
);
1392 match_int(args
, &arg
);
1396 match_int(args
, &arg
);
1397 port_rpti
= (u16
)arg
;
1399 case Opt_target_lun
:
1400 match_int(args
, &arg
);
1401 target_lun
= (u32
)arg
;
1408 if (!i_port
|| !t_port
|| !sa_res_key
) {
1409 pr_err("Illegal parameters for APTPL registration\n");
1414 if (res_holder
&& !(type
)) {
1415 pr_err("Illegal PR type: 0x%02x for reservation"
1421 ret
= core_scsi3_alloc_aptpl_registration(&dev
->t10_pr
, sa_res_key
,
1422 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1423 res_holder
, all_tg_pt
, type
);
1431 return (ret
== 0) ? count
: ret
;
1434 SE_DEV_PR_ATTR(res_aptpl_metadata
, S_IRUGO
| S_IWUSR
);
1436 CONFIGFS_EATTR_OPS(target_core_dev_pr
, se_device
, dev_pr_group
);
1438 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1439 &target_core_dev_pr_res_holder
.attr
,
1440 &target_core_dev_pr_res_pr_all_tgt_pts
.attr
,
1441 &target_core_dev_pr_res_pr_generation
.attr
,
1442 &target_core_dev_pr_res_pr_holder_tg_port
.attr
,
1443 &target_core_dev_pr_res_pr_registered_i_pts
.attr
,
1444 &target_core_dev_pr_res_pr_type
.attr
,
1445 &target_core_dev_pr_res_type
.attr
,
1446 &target_core_dev_pr_res_aptpl_active
.attr
,
1447 &target_core_dev_pr_res_aptpl_metadata
.attr
,
1451 static struct configfs_item_operations target_core_dev_pr_ops
= {
1452 .show_attribute
= target_core_dev_pr_attr_show
,
1453 .store_attribute
= target_core_dev_pr_attr_store
,
1456 static struct config_item_type target_core_dev_pr_cit
= {
1457 .ct_item_ops
= &target_core_dev_pr_ops
,
1458 .ct_attrs
= target_core_dev_pr_attrs
,
1459 .ct_owner
= THIS_MODULE
,
1462 /* End functions for struct config_item_type target_core_dev_pr_cit */
1464 /* Start functions for struct config_item_type target_core_dev_cit */
1466 static ssize_t
target_core_show_dev_info(void *p
, char *page
)
1468 struct se_device
*dev
= p
;
1469 struct se_subsystem_api
*t
= dev
->transport
;
1471 ssize_t read_bytes
= 0;
1473 transport_dump_dev_state(dev
, page
, &bl
);
1475 read_bytes
+= t
->show_configfs_dev_params(dev
, page
+read_bytes
);
1479 static struct target_core_configfs_attribute target_core_attr_dev_info
= {
1480 .attr
= { .ca_owner
= THIS_MODULE
,
1482 .ca_mode
= S_IRUGO
},
1483 .show
= target_core_show_dev_info
,
1487 static ssize_t
target_core_store_dev_control(
1492 struct se_device
*dev
= p
;
1493 struct se_subsystem_api
*t
= dev
->transport
;
1495 return t
->set_configfs_dev_params(dev
, page
, count
);
1498 static struct target_core_configfs_attribute target_core_attr_dev_control
= {
1499 .attr
= { .ca_owner
= THIS_MODULE
,
1500 .ca_name
= "control",
1501 .ca_mode
= S_IWUSR
},
1503 .store
= target_core_store_dev_control
,
1506 static ssize_t
target_core_show_dev_alias(void *p
, char *page
)
1508 struct se_device
*dev
= p
;
1510 if (!(dev
->dev_flags
& DF_USING_ALIAS
))
1513 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->dev_alias
);
1516 static ssize_t
target_core_store_dev_alias(
1521 struct se_device
*dev
= p
;
1522 struct se_hba
*hba
= dev
->se_hba
;
1525 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1526 pr_err("alias count: %d exceeds"
1527 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1528 SE_DEV_ALIAS_LEN
-1);
1532 read_bytes
= snprintf(&dev
->dev_alias
[0], SE_DEV_ALIAS_LEN
, "%s", page
);
1535 if (dev
->dev_alias
[read_bytes
- 1] == '\n')
1536 dev
->dev_alias
[read_bytes
- 1] = '\0';
1538 dev
->dev_flags
|= DF_USING_ALIAS
;
1540 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
1541 config_item_name(&hba
->hba_group
.cg_item
),
1542 config_item_name(&dev
->dev_group
.cg_item
),
1548 static struct target_core_configfs_attribute target_core_attr_dev_alias
= {
1549 .attr
= { .ca_owner
= THIS_MODULE
,
1551 .ca_mode
= S_IRUGO
| S_IWUSR
},
1552 .show
= target_core_show_dev_alias
,
1553 .store
= target_core_store_dev_alias
,
1556 static ssize_t
target_core_show_dev_udev_path(void *p
, char *page
)
1558 struct se_device
*dev
= p
;
1560 if (!(dev
->dev_flags
& DF_USING_UDEV_PATH
))
1563 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->udev_path
);
1566 static ssize_t
target_core_store_dev_udev_path(
1571 struct se_device
*dev
= p
;
1572 struct se_hba
*hba
= dev
->se_hba
;
1575 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1576 pr_err("udev_path count: %d exceeds"
1577 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1578 SE_UDEV_PATH_LEN
-1);
1582 read_bytes
= snprintf(&dev
->udev_path
[0], SE_UDEV_PATH_LEN
,
1586 if (dev
->udev_path
[read_bytes
- 1] == '\n')
1587 dev
->udev_path
[read_bytes
- 1] = '\0';
1589 dev
->dev_flags
|= DF_USING_UDEV_PATH
;
1591 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1592 config_item_name(&hba
->hba_group
.cg_item
),
1593 config_item_name(&dev
->dev_group
.cg_item
),
1599 static struct target_core_configfs_attribute target_core_attr_dev_udev_path
= {
1600 .attr
= { .ca_owner
= THIS_MODULE
,
1601 .ca_name
= "udev_path",
1602 .ca_mode
= S_IRUGO
| S_IWUSR
},
1603 .show
= target_core_show_dev_udev_path
,
1604 .store
= target_core_store_dev_udev_path
,
1607 static ssize_t
target_core_show_dev_enable(void *p
, char *page
)
1609 struct se_device
*dev
= p
;
1611 return snprintf(page
, PAGE_SIZE
, "%d\n", !!(dev
->dev_flags
& DF_CONFIGURED
));
1614 static ssize_t
target_core_store_dev_enable(
1619 struct se_device
*dev
= p
;
1623 ptr
= strstr(page
, "1");
1625 pr_err("For dev_enable ops, only valid value"
1630 ret
= target_configure_device(dev
);
1636 static struct target_core_configfs_attribute target_core_attr_dev_enable
= {
1637 .attr
= { .ca_owner
= THIS_MODULE
,
1638 .ca_name
= "enable",
1639 .ca_mode
= S_IRUGO
| S_IWUSR
},
1640 .show
= target_core_show_dev_enable
,
1641 .store
= target_core_store_dev_enable
,
1644 static ssize_t
target_core_show_alua_lu_gp(void *p
, char *page
)
1646 struct se_device
*dev
= p
;
1647 struct config_item
*lu_ci
;
1648 struct t10_alua_lu_gp
*lu_gp
;
1649 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1652 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1656 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1657 lu_gp
= lu_gp_mem
->lu_gp
;
1659 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1660 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1661 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1663 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1668 static ssize_t
target_core_store_alua_lu_gp(
1673 struct se_device
*dev
= p
;
1674 struct se_hba
*hba
= dev
->se_hba
;
1675 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1676 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1677 unsigned char buf
[LU_GROUP_NAME_BUF
];
1680 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1684 if (count
> LU_GROUP_NAME_BUF
) {
1685 pr_err("ALUA LU Group Alias too large!\n");
1688 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1689 memcpy(buf
, page
, count
);
1691 * Any ALUA logical unit alias besides "NULL" means we will be
1692 * making a new group association.
1694 if (strcmp(strstrip(buf
), "NULL")) {
1696 * core_alua_get_lu_gp_by_name() will increment reference to
1697 * struct t10_alua_lu_gp. This reference is released with
1698 * core_alua_get_lu_gp_by_name below().
1700 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
1705 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1706 lu_gp
= lu_gp_mem
->lu_gp
;
1709 * Clearing an existing lu_gp association, and replacing
1713 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
1714 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1716 config_item_name(&hba
->hba_group
.cg_item
),
1717 config_item_name(&dev
->dev_group
.cg_item
),
1718 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1721 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1722 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1727 * Removing existing association of lu_gp_mem with lu_gp
1729 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1733 * Associate lu_gp_mem with lu_gp_new.
1735 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
1736 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1738 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1739 " core/alua/lu_gps/%s, ID: %hu\n",
1740 (move
) ? "Moving" : "Adding",
1741 config_item_name(&hba
->hba_group
.cg_item
),
1742 config_item_name(&dev
->dev_group
.cg_item
),
1743 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
1744 lu_gp_new
->lu_gp_id
);
1746 core_alua_put_lu_gp_from_name(lu_gp_new
);
1750 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp
= {
1751 .attr
= { .ca_owner
= THIS_MODULE
,
1752 .ca_name
= "alua_lu_gp",
1753 .ca_mode
= S_IRUGO
| S_IWUSR
},
1754 .show
= target_core_show_alua_lu_gp
,
1755 .store
= target_core_store_alua_lu_gp
,
1758 static ssize_t
target_core_show_dev_lba_map(void *p
, char *page
)
1760 struct se_device
*dev
= p
;
1761 struct t10_alua_lba_map
*map
;
1762 struct t10_alua_lba_map_member
*mem
;
1767 spin_lock(&dev
->t10_alua
.lba_map_lock
);
1768 if (!list_empty(&dev
->t10_alua
.lba_map_list
))
1769 bl
+= sprintf(b
+ bl
, "%u %u\n",
1770 dev
->t10_alua
.lba_map_segment_size
,
1771 dev
->t10_alua
.lba_map_segment_multiplier
);
1772 list_for_each_entry(map
, &dev
->t10_alua
.lba_map_list
, lba_map_list
) {
1773 bl
+= sprintf(b
+ bl
, "%llu %llu",
1774 map
->lba_map_first_lba
, map
->lba_map_last_lba
);
1775 list_for_each_entry(mem
, &map
->lba_map_mem_list
,
1777 switch (mem
->lba_map_mem_alua_state
) {
1778 case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
:
1781 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
1784 case ALUA_ACCESS_STATE_STANDBY
:
1787 case ALUA_ACCESS_STATE_UNAVAILABLE
:
1794 bl
+= sprintf(b
+ bl
, " %d:%c",
1795 mem
->lba_map_mem_alua_pg_id
, state
);
1797 bl
+= sprintf(b
+ bl
, "\n");
1799 spin_unlock(&dev
->t10_alua
.lba_map_lock
);
1803 static ssize_t
target_core_store_dev_lba_map(
1808 struct se_device
*dev
= p
;
1809 struct t10_alua_lba_map
*lba_map
= NULL
;
1810 struct list_head lba_list
;
1811 char *map_entries
, *ptr
;
1813 int pg_num
= -1, pg
;
1814 int ret
= 0, num
= 0, pg_id
, alua_state
;
1815 unsigned long start_lba
= -1, end_lba
= -1;
1816 unsigned long segment_size
= -1, segment_mult
= -1;
1818 map_entries
= kstrdup(page
, GFP_KERNEL
);
1822 INIT_LIST_HEAD(&lba_list
);
1823 while ((ptr
= strsep(&map_entries
, "\n")) != NULL
) {
1828 if (sscanf(ptr
, "%lu %lu\n",
1829 &segment_size
, &segment_mult
) != 2) {
1830 pr_err("Invalid line %d\n", num
);
1837 if (sscanf(ptr
, "%lu %lu", &start_lba
, &end_lba
) != 2) {
1838 pr_err("Invalid line %d\n", num
);
1842 ptr
= strchr(ptr
, ' ');
1844 pr_err("Invalid line %d, missing end lba\n", num
);
1849 ptr
= strchr(ptr
, ' ');
1851 pr_err("Invalid line %d, missing state definitions\n",
1857 lba_map
= core_alua_allocate_lba_map(&lba_list
,
1858 start_lba
, end_lba
);
1859 if (IS_ERR(lba_map
)) {
1860 ret
= PTR_ERR(lba_map
);
1864 while (sscanf(ptr
, "%d:%c", &pg_id
, &state
) == 2) {
1867 alua_state
= ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
;
1870 alua_state
= ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
;
1873 alua_state
= ALUA_ACCESS_STATE_STANDBY
;
1876 alua_state
= ALUA_ACCESS_STATE_UNAVAILABLE
;
1879 pr_err("Invalid ALUA state '%c'\n", state
);
1884 ret
= core_alua_allocate_lba_map_mem(lba_map
,
1887 pr_err("Invalid target descriptor %d:%c "
1893 ptr
= strchr(ptr
, ' ');
1901 else if (pg
!= pg_num
) {
1902 pr_err("Only %d from %d port groups definitions "
1903 "at line %d\n", pg
, pg_num
, num
);
1911 core_alua_free_lba_map(&lba_list
);
1914 core_alua_set_lba_map(dev
, &lba_list
,
1915 segment_size
, segment_mult
);
1920 static struct target_core_configfs_attribute target_core_attr_dev_lba_map
= {
1921 .attr
= { .ca_owner
= THIS_MODULE
,
1922 .ca_name
= "lba_map",
1923 .ca_mode
= S_IRUGO
| S_IWUSR
},
1924 .show
= target_core_show_dev_lba_map
,
1925 .store
= target_core_store_dev_lba_map
,
1928 static struct configfs_attribute
*lio_core_dev_attrs
[] = {
1929 &target_core_attr_dev_info
.attr
,
1930 &target_core_attr_dev_control
.attr
,
1931 &target_core_attr_dev_alias
.attr
,
1932 &target_core_attr_dev_udev_path
.attr
,
1933 &target_core_attr_dev_enable
.attr
,
1934 &target_core_attr_dev_alua_lu_gp
.attr
,
1935 &target_core_attr_dev_lba_map
.attr
,
1939 static void target_core_dev_release(struct config_item
*item
)
1941 struct config_group
*dev_cg
= to_config_group(item
);
1942 struct se_device
*dev
=
1943 container_of(dev_cg
, struct se_device
, dev_group
);
1945 kfree(dev_cg
->default_groups
);
1946 target_free_device(dev
);
1949 static ssize_t
target_core_dev_show(struct config_item
*item
,
1950 struct configfs_attribute
*attr
,
1953 struct config_group
*dev_cg
= to_config_group(item
);
1954 struct se_device
*dev
=
1955 container_of(dev_cg
, struct se_device
, dev_group
);
1956 struct target_core_configfs_attribute
*tc_attr
= container_of(
1957 attr
, struct target_core_configfs_attribute
, attr
);
1962 return tc_attr
->show(dev
, page
);
1965 static ssize_t
target_core_dev_store(struct config_item
*item
,
1966 struct configfs_attribute
*attr
,
1967 const char *page
, size_t count
)
1969 struct config_group
*dev_cg
= to_config_group(item
);
1970 struct se_device
*dev
=
1971 container_of(dev_cg
, struct se_device
, dev_group
);
1972 struct target_core_configfs_attribute
*tc_attr
= container_of(
1973 attr
, struct target_core_configfs_attribute
, attr
);
1975 if (!tc_attr
->store
)
1978 return tc_attr
->store(dev
, page
, count
);
1981 static struct configfs_item_operations target_core_dev_item_ops
= {
1982 .release
= target_core_dev_release
,
1983 .show_attribute
= target_core_dev_show
,
1984 .store_attribute
= target_core_dev_store
,
1987 static struct config_item_type target_core_dev_cit
= {
1988 .ct_item_ops
= &target_core_dev_item_ops
,
1989 .ct_attrs
= lio_core_dev_attrs
,
1990 .ct_owner
= THIS_MODULE
,
1993 /* End functions for struct config_item_type target_core_dev_cit */
1995 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
1997 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp
, t10_alua_lu_gp
);
1998 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
1999 static struct target_core_alua_lu_gp_attribute \
2000 target_core_alua_lu_gp_##_name = \
2001 __CONFIGFS_EATTR(_name, _mode, \
2002 target_core_alua_lu_gp_show_attr_##_name, \
2003 target_core_alua_lu_gp_store_attr_##_name);
2005 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
2006 static struct target_core_alua_lu_gp_attribute \
2007 target_core_alua_lu_gp_##_name = \
2008 __CONFIGFS_EATTR_RO(_name, \
2009 target_core_alua_lu_gp_show_attr_##_name);
2014 static ssize_t
target_core_alua_lu_gp_show_attr_lu_gp_id(
2015 struct t10_alua_lu_gp
*lu_gp
,
2018 if (!lu_gp
->lu_gp_valid_id
)
2021 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
2024 static ssize_t
target_core_alua_lu_gp_store_attr_lu_gp_id(
2025 struct t10_alua_lu_gp
*lu_gp
,
2029 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2030 unsigned long lu_gp_id
;
2033 ret
= kstrtoul(page
, 0, &lu_gp_id
);
2035 pr_err("kstrtoul() returned %d for"
2036 " lu_gp_id\n", ret
);
2039 if (lu_gp_id
> 0x0000ffff) {
2040 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
2041 " 0x0000ffff\n", lu_gp_id
);
2045 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
2049 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
2050 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2051 config_item_name(&alua_lu_gp_cg
->cg_item
),
2057 SE_DEV_ALUA_LU_ATTR(lu_gp_id
, S_IRUGO
| S_IWUSR
);
2062 static ssize_t
target_core_alua_lu_gp_show_attr_members(
2063 struct t10_alua_lu_gp
*lu_gp
,
2066 struct se_device
*dev
;
2068 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2069 ssize_t len
= 0, cur_len
;
2070 unsigned char buf
[LU_GROUP_NAME_BUF
];
2072 memset(buf
, 0, LU_GROUP_NAME_BUF
);
2074 spin_lock(&lu_gp
->lu_gp_lock
);
2075 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
2076 dev
= lu_gp_mem
->lu_gp_mem_dev
;
2079 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
2080 config_item_name(&hba
->hba_group
.cg_item
),
2081 config_item_name(&dev
->dev_group
.cg_item
));
2082 cur_len
++; /* Extra byte for NULL terminator */
2084 if ((cur_len
+ len
) > PAGE_SIZE
) {
2085 pr_warn("Ran out of lu_gp_show_attr"
2086 "_members buffer\n");
2089 memcpy(page
+len
, buf
, cur_len
);
2092 spin_unlock(&lu_gp
->lu_gp_lock
);
2097 SE_DEV_ALUA_LU_ATTR_RO(members
);
2099 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp
, t10_alua_lu_gp
, lu_gp_group
);
2101 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
2102 &target_core_alua_lu_gp_lu_gp_id
.attr
,
2103 &target_core_alua_lu_gp_members
.attr
,
2107 static void target_core_alua_lu_gp_release(struct config_item
*item
)
2109 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2110 struct t10_alua_lu_gp
, lu_gp_group
);
2112 core_alua_free_lu_gp(lu_gp
);
2115 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
2116 .release
= target_core_alua_lu_gp_release
,
2117 .show_attribute
= target_core_alua_lu_gp_attr_show
,
2118 .store_attribute
= target_core_alua_lu_gp_attr_store
,
2121 static struct config_item_type target_core_alua_lu_gp_cit
= {
2122 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
2123 .ct_attrs
= target_core_alua_lu_gp_attrs
,
2124 .ct_owner
= THIS_MODULE
,
2127 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
2129 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
2131 static struct config_group
*target_core_alua_create_lu_gp(
2132 struct config_group
*group
,
2135 struct t10_alua_lu_gp
*lu_gp
;
2136 struct config_group
*alua_lu_gp_cg
= NULL
;
2137 struct config_item
*alua_lu_gp_ci
= NULL
;
2139 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
2143 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2144 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
2146 config_group_init_type_name(alua_lu_gp_cg
, name
,
2147 &target_core_alua_lu_gp_cit
);
2149 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2150 " Group: core/alua/lu_gps/%s\n",
2151 config_item_name(alua_lu_gp_ci
));
2153 return alua_lu_gp_cg
;
2157 static void target_core_alua_drop_lu_gp(
2158 struct config_group
*group
,
2159 struct config_item
*item
)
2161 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2162 struct t10_alua_lu_gp
, lu_gp_group
);
2164 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2165 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2166 config_item_name(item
), lu_gp
->lu_gp_id
);
2168 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
2169 * -> target_core_alua_lu_gp_release()
2171 config_item_put(item
);
2174 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
2175 .make_group
= &target_core_alua_create_lu_gp
,
2176 .drop_item
= &target_core_alua_drop_lu_gp
,
2179 static struct config_item_type target_core_alua_lu_gps_cit
= {
2180 .ct_item_ops
= NULL
,
2181 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
2182 .ct_owner
= THIS_MODULE
,
2185 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
2187 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2189 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
);
2190 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
2191 static struct target_core_alua_tg_pt_gp_attribute \
2192 target_core_alua_tg_pt_gp_##_name = \
2193 __CONFIGFS_EATTR(_name, _mode, \
2194 target_core_alua_tg_pt_gp_show_attr_##_name, \
2195 target_core_alua_tg_pt_gp_store_attr_##_name);
2197 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2198 static struct target_core_alua_tg_pt_gp_attribute \
2199 target_core_alua_tg_pt_gp_##_name = \
2200 __CONFIGFS_EATTR_RO(_name, \
2201 target_core_alua_tg_pt_gp_show_attr_##_name);
2206 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2207 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2210 return sprintf(page
, "%d\n",
2211 atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
));
2214 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2215 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2219 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
2223 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2224 pr_err("Unable to do implicit ALUA on non valid"
2225 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2228 if (!(dev
->dev_flags
& DF_CONFIGURED
)) {
2229 pr_err("Unable to set alua_access_state while device is"
2230 " not configured\n");
2234 ret
= kstrtoul(page
, 0, &tmp
);
2236 pr_err("Unable to extract new ALUA access state from"
2240 new_state
= (int)tmp
;
2242 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICIT_ALUA
)) {
2243 pr_err("Unable to process implicit configfs ALUA"
2244 " transition while TPGS_IMPLICIT_ALUA is disabled\n");
2247 if (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICIT_ALUA
&&
2248 new_state
== ALUA_ACCESS_STATE_LBA_DEPENDENT
) {
2249 /* LBA DEPENDENT is only allowed with implicit ALUA */
2250 pr_err("Unable to process implicit configfs ALUA transition"
2251 " while explicit ALUA management is enabled\n");
2255 ret
= core_alua_do_port_transition(tg_pt_gp
, dev
,
2256 NULL
, NULL
, new_state
, 0);
2257 return (!ret
) ? count
: -EINVAL
;
2260 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state
, S_IRUGO
| S_IWUSR
);
2263 * alua_access_status
2265 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2266 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2269 return sprintf(page
, "%s\n",
2270 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2273 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2274 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2279 int new_status
, ret
;
2281 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2282 pr_err("Unable to do set ALUA access status on non"
2283 " valid tg_pt_gp ID: %hu\n",
2284 tg_pt_gp
->tg_pt_gp_valid_id
);
2288 ret
= kstrtoul(page
, 0, &tmp
);
2290 pr_err("Unable to extract new ALUA access status"
2291 " from %s\n", page
);
2294 new_status
= (int)tmp
;
2296 if ((new_status
!= ALUA_STATUS_NONE
) &&
2297 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG
) &&
2298 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA
)) {
2299 pr_err("Illegal ALUA access status: 0x%02x\n",
2304 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2308 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status
, S_IRUGO
| S_IWUSR
);
2313 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2314 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2317 return core_alua_show_access_type(tg_pt_gp
, page
);
2320 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2321 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2325 return core_alua_store_access_type(tg_pt_gp
, page
, count
);
2328 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type
, S_IRUGO
| S_IWUSR
);
2331 * alua_supported_states
2334 #define SE_DEV_ALUA_SUPPORT_STATE_SHOW(_name, _var, _bit) \
2335 static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_support_##_name( \
2336 struct t10_alua_tg_pt_gp *t, char *p) \
2338 return sprintf(p, "%d\n", !!(t->_var & _bit)); \
2341 #define SE_DEV_ALUA_SUPPORT_STATE_STORE(_name, _var, _bit) \
2342 static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_support_##_name(\
2343 struct t10_alua_tg_pt_gp *t, const char *p, size_t c) \
2345 unsigned long tmp; \
2348 if (!t->tg_pt_gp_valid_id) { \
2349 pr_err("Unable to do set ##_name ALUA state on non" \
2350 " valid tg_pt_gp ID: %hu\n", \
2351 t->tg_pt_gp_valid_id); \
2355 ret = kstrtoul(p, 0, &tmp); \
2357 pr_err("Invalid value '%s', must be '0' or '1'\n", p); \
2361 pr_err("Invalid value '%ld', must be '0' or '1'\n", tmp); \
2372 SE_DEV_ALUA_SUPPORT_STATE_SHOW(transitioning
,
2373 tg_pt_gp_alua_supported_states
, ALUA_T_SUP
);
2374 SE_DEV_ALUA_SUPPORT_STATE_STORE(transitioning
,
2375 tg_pt_gp_alua_supported_states
, ALUA_T_SUP
);
2376 SE_DEV_ALUA_TG_PT_ATTR(alua_support_transitioning
, S_IRUGO
| S_IWUSR
);
2378 SE_DEV_ALUA_SUPPORT_STATE_SHOW(offline
,
2379 tg_pt_gp_alua_supported_states
, ALUA_O_SUP
);
2380 SE_DEV_ALUA_SUPPORT_STATE_STORE(offline
,
2381 tg_pt_gp_alua_supported_states
, ALUA_O_SUP
);
2382 SE_DEV_ALUA_TG_PT_ATTR(alua_support_offline
, S_IRUGO
| S_IWUSR
);
2384 SE_DEV_ALUA_SUPPORT_STATE_SHOW(lba_dependent
,
2385 tg_pt_gp_alua_supported_states
, ALUA_LBD_SUP
);
2386 SE_DEV_ALUA_SUPPORT_STATE_STORE(lba_dependent
,
2387 tg_pt_gp_alua_supported_states
, ALUA_LBD_SUP
);
2388 SE_DEV_ALUA_TG_PT_ATTR(alua_support_lba_dependent
, S_IRUGO
);
2390 SE_DEV_ALUA_SUPPORT_STATE_SHOW(unavailable
,
2391 tg_pt_gp_alua_supported_states
, ALUA_U_SUP
);
2392 SE_DEV_ALUA_SUPPORT_STATE_STORE(unavailable
,
2393 tg_pt_gp_alua_supported_states
, ALUA_U_SUP
);
2394 SE_DEV_ALUA_TG_PT_ATTR(alua_support_unavailable
, S_IRUGO
| S_IWUSR
);
2396 SE_DEV_ALUA_SUPPORT_STATE_SHOW(standby
,
2397 tg_pt_gp_alua_supported_states
, ALUA_S_SUP
);
2398 SE_DEV_ALUA_SUPPORT_STATE_STORE(standby
,
2399 tg_pt_gp_alua_supported_states
, ALUA_S_SUP
);
2400 SE_DEV_ALUA_TG_PT_ATTR(alua_support_standby
, S_IRUGO
| S_IWUSR
);
2402 SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_optimized
,
2403 tg_pt_gp_alua_supported_states
, ALUA_AO_SUP
);
2404 SE_DEV_ALUA_SUPPORT_STATE_STORE(active_optimized
,
2405 tg_pt_gp_alua_supported_states
, ALUA_AO_SUP
);
2406 SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_optimized
, S_IRUGO
| S_IWUSR
);
2408 SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_nonoptimized
,
2409 tg_pt_gp_alua_supported_states
, ALUA_AN_SUP
);
2410 SE_DEV_ALUA_SUPPORT_STATE_STORE(active_nonoptimized
,
2411 tg_pt_gp_alua_supported_states
, ALUA_AN_SUP
);
2412 SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_nonoptimized
, S_IRUGO
| S_IWUSR
);
2415 * alua_write_metadata
2417 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2418 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2421 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_write_metadata
);
2424 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2425 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2432 ret
= kstrtoul(page
, 0, &tmp
);
2434 pr_err("Unable to extract alua_write_metadata\n");
2438 if ((tmp
!= 0) && (tmp
!= 1)) {
2439 pr_err("Illegal value for alua_write_metadata:"
2443 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2448 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata
, S_IRUGO
| S_IWUSR
);
2455 static ssize_t
target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2456 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2459 return core_alua_show_nonop_delay_msecs(tg_pt_gp
, page
);
2463 static ssize_t
target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2464 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2468 return core_alua_store_nonop_delay_msecs(tg_pt_gp
, page
, count
);
2471 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs
, S_IRUGO
| S_IWUSR
);
2476 static ssize_t
target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2477 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2480 return core_alua_show_trans_delay_msecs(tg_pt_gp
, page
);
2483 static ssize_t
target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2484 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2488 return core_alua_store_trans_delay_msecs(tg_pt_gp
, page
, count
);
2491 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs
, S_IRUGO
| S_IWUSR
);
2494 * implicit_trans_secs
2496 static ssize_t
target_core_alua_tg_pt_gp_show_attr_implicit_trans_secs(
2497 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2500 return core_alua_show_implicit_trans_secs(tg_pt_gp
, page
);
2503 static ssize_t
target_core_alua_tg_pt_gp_store_attr_implicit_trans_secs(
2504 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2508 return core_alua_store_implicit_trans_secs(tg_pt_gp
, page
, count
);
2511 SE_DEV_ALUA_TG_PT_ATTR(implicit_trans_secs
, S_IRUGO
| S_IWUSR
);
2517 static ssize_t
target_core_alua_tg_pt_gp_show_attr_preferred(
2518 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2521 return core_alua_show_preferred_bit(tg_pt_gp
, page
);
2524 static ssize_t
target_core_alua_tg_pt_gp_store_attr_preferred(
2525 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2529 return core_alua_store_preferred_bit(tg_pt_gp
, page
, count
);
2532 SE_DEV_ALUA_TG_PT_ATTR(preferred
, S_IRUGO
| S_IWUSR
);
2537 static ssize_t
target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2538 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2541 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
2544 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2547 static ssize_t
target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2548 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2552 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2553 unsigned long tg_pt_gp_id
;
2556 ret
= kstrtoul(page
, 0, &tg_pt_gp_id
);
2558 pr_err("kstrtoul() returned %d for"
2559 " tg_pt_gp_id\n", ret
);
2562 if (tg_pt_gp_id
> 0x0000ffff) {
2563 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:"
2564 " 0x0000ffff\n", tg_pt_gp_id
);
2568 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2572 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
2573 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2574 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2575 tg_pt_gp
->tg_pt_gp_id
);
2580 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id
, S_IRUGO
| S_IWUSR
);
2585 static ssize_t
target_core_alua_tg_pt_gp_show_attr_members(
2586 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2589 struct se_port
*port
;
2590 struct se_portal_group
*tpg
;
2592 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
2593 ssize_t len
= 0, cur_len
;
2594 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2596 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2598 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2599 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
2600 tg_pt_gp_mem_list
) {
2601 port
= tg_pt_gp_mem
->tg_pt
;
2602 tpg
= port
->sep_tpg
;
2603 lun
= port
->sep_lun
;
2605 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2606 "/%s\n", tpg
->se_tpg_tfo
->get_fabric_name(),
2607 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
2608 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
2609 config_item_name(&lun
->lun_group
.cg_item
));
2610 cur_len
++; /* Extra byte for NULL terminator */
2612 if ((cur_len
+ len
) > PAGE_SIZE
) {
2613 pr_warn("Ran out of lu_gp_show_attr"
2614 "_members buffer\n");
2617 memcpy(page
+len
, buf
, cur_len
);
2620 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2625 SE_DEV_ALUA_TG_PT_ATTR_RO(members
);
2627 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
,
2630 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2631 &target_core_alua_tg_pt_gp_alua_access_state
.attr
,
2632 &target_core_alua_tg_pt_gp_alua_access_status
.attr
,
2633 &target_core_alua_tg_pt_gp_alua_access_type
.attr
,
2634 &target_core_alua_tg_pt_gp_alua_support_transitioning
.attr
,
2635 &target_core_alua_tg_pt_gp_alua_support_offline
.attr
,
2636 &target_core_alua_tg_pt_gp_alua_support_lba_dependent
.attr
,
2637 &target_core_alua_tg_pt_gp_alua_support_unavailable
.attr
,
2638 &target_core_alua_tg_pt_gp_alua_support_standby
.attr
,
2639 &target_core_alua_tg_pt_gp_alua_support_active_nonoptimized
.attr
,
2640 &target_core_alua_tg_pt_gp_alua_support_active_optimized
.attr
,
2641 &target_core_alua_tg_pt_gp_alua_write_metadata
.attr
,
2642 &target_core_alua_tg_pt_gp_nonop_delay_msecs
.attr
,
2643 &target_core_alua_tg_pt_gp_trans_delay_msecs
.attr
,
2644 &target_core_alua_tg_pt_gp_implicit_trans_secs
.attr
,
2645 &target_core_alua_tg_pt_gp_preferred
.attr
,
2646 &target_core_alua_tg_pt_gp_tg_pt_gp_id
.attr
,
2647 &target_core_alua_tg_pt_gp_members
.attr
,
2651 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2653 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2654 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2656 core_alua_free_tg_pt_gp(tg_pt_gp
);
2659 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2660 .release
= target_core_alua_tg_pt_gp_release
,
2661 .show_attribute
= target_core_alua_tg_pt_gp_attr_show
,
2662 .store_attribute
= target_core_alua_tg_pt_gp_attr_store
,
2665 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2666 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2667 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2668 .ct_owner
= THIS_MODULE
,
2671 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2673 /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2675 static struct config_group
*target_core_alua_create_tg_pt_gp(
2676 struct config_group
*group
,
2679 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2680 alua_tg_pt_gps_group
);
2681 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2682 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2683 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2685 tg_pt_gp
= core_alua_allocate_tg_pt_gp(alua
->t10_dev
, name
, 0);
2689 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2690 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2692 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2693 &target_core_alua_tg_pt_gp_cit
);
2695 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
2696 " Group: alua/tg_pt_gps/%s\n",
2697 config_item_name(alua_tg_pt_gp_ci
));
2699 return alua_tg_pt_gp_cg
;
2702 static void target_core_alua_drop_tg_pt_gp(
2703 struct config_group
*group
,
2704 struct config_item
*item
)
2706 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2707 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2709 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
2710 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2711 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2713 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2714 * -> target_core_alua_tg_pt_gp_release().
2716 config_item_put(item
);
2719 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2720 .make_group
= &target_core_alua_create_tg_pt_gp
,
2721 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2724 static struct config_item_type target_core_alua_tg_pt_gps_cit
= {
2725 .ct_group_ops
= &target_core_alua_tg_pt_gps_group_ops
,
2726 .ct_owner
= THIS_MODULE
,
2729 /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2731 /* Start functions for struct config_item_type target_core_alua_cit */
2734 * target_core_alua_cit is a ConfigFS group that lives under
2735 * /sys/kernel/config/target/core/alua. There are default groups
2736 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2737 * target_core_alua_cit in target_core_init_configfs() below.
2739 static struct config_item_type target_core_alua_cit
= {
2740 .ct_item_ops
= NULL
,
2742 .ct_owner
= THIS_MODULE
,
2745 /* End functions for struct config_item_type target_core_alua_cit */
2747 /* Start functions for struct config_item_type target_core_stat_cit */
2749 static struct config_group
*target_core_stat_mkdir(
2750 struct config_group
*group
,
2753 return ERR_PTR(-ENOSYS
);
2756 static void target_core_stat_rmdir(
2757 struct config_group
*group
,
2758 struct config_item
*item
)
2763 static struct configfs_group_operations target_core_stat_group_ops
= {
2764 .make_group
= &target_core_stat_mkdir
,
2765 .drop_item
= &target_core_stat_rmdir
,
2768 static struct config_item_type target_core_stat_cit
= {
2769 .ct_group_ops
= &target_core_stat_group_ops
,
2770 .ct_owner
= THIS_MODULE
,
2773 /* End functions for struct config_item_type target_core_stat_cit */
2775 /* Start functions for struct config_item_type target_core_hba_cit */
2777 static struct config_group
*target_core_make_subdev(
2778 struct config_group
*group
,
2781 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2782 struct se_subsystem_api
*t
;
2783 struct config_item
*hba_ci
= &group
->cg_item
;
2784 struct se_hba
*hba
= item_to_hba(hba_ci
);
2785 struct se_device
*dev
;
2786 struct config_group
*dev_cg
= NULL
, *tg_pt_gp_cg
= NULL
;
2787 struct config_group
*dev_stat_grp
= NULL
;
2788 int errno
= -ENOMEM
, ret
;
2790 ret
= mutex_lock_interruptible(&hba
->hba_access_mutex
);
2792 return ERR_PTR(ret
);
2794 * Locate the struct se_subsystem_api from parent's struct se_hba.
2798 dev
= target_alloc_device(hba
, name
);
2802 dev_cg
= &dev
->dev_group
;
2804 dev_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 6,
2806 if (!dev_cg
->default_groups
)
2807 goto out_free_device
;
2809 config_group_init_type_name(dev_cg
, name
, &target_core_dev_cit
);
2810 config_group_init_type_name(&dev
->dev_attrib
.da_group
, "attrib",
2811 &target_core_dev_attrib_cit
);
2812 config_group_init_type_name(&dev
->dev_pr_group
, "pr",
2813 &target_core_dev_pr_cit
);
2814 config_group_init_type_name(&dev
->t10_wwn
.t10_wwn_group
, "wwn",
2815 &target_core_dev_wwn_cit
);
2816 config_group_init_type_name(&dev
->t10_alua
.alua_tg_pt_gps_group
,
2817 "alua", &target_core_alua_tg_pt_gps_cit
);
2818 config_group_init_type_name(&dev
->dev_stat_grps
.stat_group
,
2819 "statistics", &target_core_stat_cit
);
2821 dev_cg
->default_groups
[0] = &dev
->dev_attrib
.da_group
;
2822 dev_cg
->default_groups
[1] = &dev
->dev_pr_group
;
2823 dev_cg
->default_groups
[2] = &dev
->t10_wwn
.t10_wwn_group
;
2824 dev_cg
->default_groups
[3] = &dev
->t10_alua
.alua_tg_pt_gps_group
;
2825 dev_cg
->default_groups
[4] = &dev
->dev_stat_grps
.stat_group
;
2826 dev_cg
->default_groups
[5] = NULL
;
2828 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
2830 tg_pt_gp
= core_alua_allocate_tg_pt_gp(dev
, "default_tg_pt_gp", 1);
2832 goto out_free_dev_cg_default_groups
;
2833 dev
->t10_alua
.default_tg_pt_gp
= tg_pt_gp
;
2835 tg_pt_gp_cg
= &dev
->t10_alua
.alua_tg_pt_gps_group
;
2836 tg_pt_gp_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
2838 if (!tg_pt_gp_cg
->default_groups
) {
2839 pr_err("Unable to allocate tg_pt_gp_cg->"
2840 "default_groups\n");
2841 goto out_free_tg_pt_gp
;
2844 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2845 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2846 tg_pt_gp_cg
->default_groups
[0] = &tg_pt_gp
->tg_pt_gp_group
;
2847 tg_pt_gp_cg
->default_groups
[1] = NULL
;
2849 * Add core/$HBA/$DEV/statistics/ default groups
2851 dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
2852 dev_stat_grp
->default_groups
= kmalloc(sizeof(struct config_group
*) * 4,
2854 if (!dev_stat_grp
->default_groups
) {
2855 pr_err("Unable to allocate dev_stat_grp->default_groups\n");
2856 goto out_free_tg_pt_gp_cg_default_groups
;
2858 target_stat_setup_dev_default_groups(dev
);
2860 mutex_unlock(&hba
->hba_access_mutex
);
2863 out_free_tg_pt_gp_cg_default_groups
:
2864 kfree(tg_pt_gp_cg
->default_groups
);
2866 core_alua_free_tg_pt_gp(tg_pt_gp
);
2867 out_free_dev_cg_default_groups
:
2868 kfree(dev_cg
->default_groups
);
2870 target_free_device(dev
);
2872 mutex_unlock(&hba
->hba_access_mutex
);
2873 return ERR_PTR(errno
);
2876 static void target_core_drop_subdev(
2877 struct config_group
*group
,
2878 struct config_item
*item
)
2880 struct config_group
*dev_cg
= to_config_group(item
);
2881 struct se_device
*dev
=
2882 container_of(dev_cg
, struct se_device
, dev_group
);
2884 struct config_item
*df_item
;
2885 struct config_group
*tg_pt_gp_cg
, *dev_stat_grp
;
2888 hba
= item_to_hba(&dev
->se_hba
->hba_group
.cg_item
);
2890 mutex_lock(&hba
->hba_access_mutex
);
2892 dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
2893 for (i
= 0; dev_stat_grp
->default_groups
[i
]; i
++) {
2894 df_item
= &dev_stat_grp
->default_groups
[i
]->cg_item
;
2895 dev_stat_grp
->default_groups
[i
] = NULL
;
2896 config_item_put(df_item
);
2898 kfree(dev_stat_grp
->default_groups
);
2900 tg_pt_gp_cg
= &dev
->t10_alua
.alua_tg_pt_gps_group
;
2901 for (i
= 0; tg_pt_gp_cg
->default_groups
[i
]; i
++) {
2902 df_item
= &tg_pt_gp_cg
->default_groups
[i
]->cg_item
;
2903 tg_pt_gp_cg
->default_groups
[i
] = NULL
;
2904 config_item_put(df_item
);
2906 kfree(tg_pt_gp_cg
->default_groups
);
2908 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2909 * directly from target_core_alua_tg_pt_gp_release().
2911 dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2913 for (i
= 0; dev_cg
->default_groups
[i
]; i
++) {
2914 df_item
= &dev_cg
->default_groups
[i
]->cg_item
;
2915 dev_cg
->default_groups
[i
] = NULL
;
2916 config_item_put(df_item
);
2919 * se_dev is released from target_core_dev_item_ops->release()
2921 config_item_put(item
);
2922 mutex_unlock(&hba
->hba_access_mutex
);
2925 static struct configfs_group_operations target_core_hba_group_ops
= {
2926 .make_group
= target_core_make_subdev
,
2927 .drop_item
= target_core_drop_subdev
,
2930 CONFIGFS_EATTR_STRUCT(target_core_hba
, se_hba
);
2931 #define SE_HBA_ATTR(_name, _mode) \
2932 static struct target_core_hba_attribute \
2933 target_core_hba_##_name = \
2934 __CONFIGFS_EATTR(_name, _mode, \
2935 target_core_hba_show_attr_##_name, \
2936 target_core_hba_store_attr_##_name);
2938 #define SE_HBA_ATTR_RO(_name) \
2939 static struct target_core_hba_attribute \
2940 target_core_hba_##_name = \
2941 __CONFIGFS_EATTR_RO(_name, \
2942 target_core_hba_show_attr_##_name);
2944 static ssize_t
target_core_hba_show_attr_hba_info(
2948 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
2949 hba
->hba_id
, hba
->transport
->name
,
2950 TARGET_CORE_CONFIGFS_VERSION
);
2953 SE_HBA_ATTR_RO(hba_info
);
2955 static ssize_t
target_core_hba_show_attr_hba_mode(struct se_hba
*hba
,
2960 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
2963 return sprintf(page
, "%d\n", hba_mode
);
2966 static ssize_t
target_core_hba_store_attr_hba_mode(struct se_hba
*hba
,
2967 const char *page
, size_t count
)
2969 struct se_subsystem_api
*transport
= hba
->transport
;
2970 unsigned long mode_flag
;
2973 if (transport
->pmode_enable_hba
== NULL
)
2976 ret
= kstrtoul(page
, 0, &mode_flag
);
2978 pr_err("Unable to extract hba mode flag: %d\n", ret
);
2982 if (hba
->dev_count
) {
2983 pr_err("Unable to set hba_mode with active devices\n");
2987 ret
= transport
->pmode_enable_hba(hba
, mode_flag
);
2991 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
2993 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
2998 SE_HBA_ATTR(hba_mode
, S_IRUGO
| S_IWUSR
);
3000 CONFIGFS_EATTR_OPS(target_core_hba
, se_hba
, hba_group
);
3002 static void target_core_hba_release(struct config_item
*item
)
3004 struct se_hba
*hba
= container_of(to_config_group(item
),
3005 struct se_hba
, hba_group
);
3006 core_delete_hba(hba
);
3009 static struct configfs_attribute
*target_core_hba_attrs
[] = {
3010 &target_core_hba_hba_info
.attr
,
3011 &target_core_hba_hba_mode
.attr
,
3015 static struct configfs_item_operations target_core_hba_item_ops
= {
3016 .release
= target_core_hba_release
,
3017 .show_attribute
= target_core_hba_attr_show
,
3018 .store_attribute
= target_core_hba_attr_store
,
3021 static struct config_item_type target_core_hba_cit
= {
3022 .ct_item_ops
= &target_core_hba_item_ops
,
3023 .ct_group_ops
= &target_core_hba_group_ops
,
3024 .ct_attrs
= target_core_hba_attrs
,
3025 .ct_owner
= THIS_MODULE
,
3028 static struct config_group
*target_core_call_addhbatotarget(
3029 struct config_group
*group
,
3032 char *se_plugin_str
, *str
, *str2
;
3034 char buf
[TARGET_CORE_NAME_MAX_LEN
];
3035 unsigned long plugin_dep_id
= 0;
3038 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
3039 if (strlen(name
) >= TARGET_CORE_NAME_MAX_LEN
) {
3040 pr_err("Passed *name strlen(): %d exceeds"
3041 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
3042 TARGET_CORE_NAME_MAX_LEN
);
3043 return ERR_PTR(-ENAMETOOLONG
);
3045 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
3047 str
= strstr(buf
, "_");
3049 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
3050 return ERR_PTR(-EINVAL
);
3052 se_plugin_str
= buf
;
3054 * Special case for subsystem plugins that have "_" in their names.
3055 * Namely rd_direct and rd_mcp..
3057 str2
= strstr(str
+1, "_");
3059 *str2
= '\0'; /* Terminate for *se_plugin_str */
3060 str2
++; /* Skip to start of plugin dependent ID */
3063 *str
= '\0'; /* Terminate for *se_plugin_str */
3064 str
++; /* Skip to start of plugin dependent ID */
3067 ret
= kstrtoul(str
, 0, &plugin_dep_id
);
3069 pr_err("kstrtoul() returned %d for"
3070 " plugin_dep_id\n", ret
);
3071 return ERR_PTR(ret
);
3074 * Load up TCM subsystem plugins if they have not already been loaded.
3076 transport_subsystem_check_init();
3078 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
3080 return ERR_CAST(hba
);
3082 config_group_init_type_name(&hba
->hba_group
, name
,
3083 &target_core_hba_cit
);
3085 return &hba
->hba_group
;
3088 static void target_core_call_delhbafromtarget(
3089 struct config_group
*group
,
3090 struct config_item
*item
)
3093 * core_delete_hba() is called from target_core_hba_item_ops->release()
3094 * -> target_core_hba_release()
3096 config_item_put(item
);
3099 static struct configfs_group_operations target_core_group_ops
= {
3100 .make_group
= target_core_call_addhbatotarget
,
3101 .drop_item
= target_core_call_delhbafromtarget
,
3104 static struct config_item_type target_core_cit
= {
3105 .ct_item_ops
= NULL
,
3106 .ct_group_ops
= &target_core_group_ops
,
3108 .ct_owner
= THIS_MODULE
,
3111 /* Stop functions for struct config_item_type target_core_hba_cit */
3113 static int __init
target_core_init_configfs(void)
3115 struct config_group
*target_cg
, *hba_cg
= NULL
, *alua_cg
= NULL
;
3116 struct config_group
*lu_gp_cg
= NULL
;
3117 struct configfs_subsystem
*subsys
;
3118 struct t10_alua_lu_gp
*lu_gp
;
3121 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
3122 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
3123 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
3125 subsys
= target_core_subsystem
[0];
3126 config_group_init(&subsys
->su_group
);
3127 mutex_init(&subsys
->su_mutex
);
3129 ret
= init_se_kmem_caches();
3133 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
3134 * and ALUA Logical Unit Group and Target Port Group infrastructure.
3136 target_cg
= &subsys
->su_group
;
3137 target_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3139 if (!target_cg
->default_groups
) {
3140 pr_err("Unable to allocate target_cg->default_groups\n");
3145 config_group_init_type_name(&target_core_hbagroup
,
3146 "core", &target_core_cit
);
3147 target_cg
->default_groups
[0] = &target_core_hbagroup
;
3148 target_cg
->default_groups
[1] = NULL
;
3150 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
3152 hba_cg
= &target_core_hbagroup
;
3153 hba_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3155 if (!hba_cg
->default_groups
) {
3156 pr_err("Unable to allocate hba_cg->default_groups\n");
3160 config_group_init_type_name(&alua_group
,
3161 "alua", &target_core_alua_cit
);
3162 hba_cg
->default_groups
[0] = &alua_group
;
3163 hba_cg
->default_groups
[1] = NULL
;
3165 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
3166 * groups under /sys/kernel/config/target/core/alua/
3168 alua_cg
= &alua_group
;
3169 alua_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3171 if (!alua_cg
->default_groups
) {
3172 pr_err("Unable to allocate alua_cg->default_groups\n");
3177 config_group_init_type_name(&alua_lu_gps_group
,
3178 "lu_gps", &target_core_alua_lu_gps_cit
);
3179 alua_cg
->default_groups
[0] = &alua_lu_gps_group
;
3180 alua_cg
->default_groups
[1] = NULL
;
3182 * Add core/alua/lu_gps/default_lu_gp
3184 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
3185 if (IS_ERR(lu_gp
)) {
3190 lu_gp_cg
= &alua_lu_gps_group
;
3191 lu_gp_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3193 if (!lu_gp_cg
->default_groups
) {
3194 pr_err("Unable to allocate lu_gp_cg->default_groups\n");
3199 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
3200 &target_core_alua_lu_gp_cit
);
3201 lu_gp_cg
->default_groups
[0] = &lu_gp
->lu_gp_group
;
3202 lu_gp_cg
->default_groups
[1] = NULL
;
3203 default_lu_gp
= lu_gp
;
3205 * Register the target_core_mod subsystem with configfs.
3207 ret
= configfs_register_subsystem(subsys
);
3209 pr_err("Error %d while registering subsystem %s\n",
3210 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
3213 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
3214 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION
" on %s/%s"
3215 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
3217 * Register built-in RAMDISK subsystem logic for virtual LUN 0
3219 ret
= rd_module_init();
3223 ret
= core_dev_setup_virtual_lun0();
3227 ret
= target_xcopy_setup_pt();
3234 configfs_unregister_subsystem(subsys
);
3235 core_dev_release_virtual_lun0();
3238 if (default_lu_gp
) {
3239 core_alua_free_lu_gp(default_lu_gp
);
3240 default_lu_gp
= NULL
;
3243 kfree(lu_gp_cg
->default_groups
);
3245 kfree(alua_cg
->default_groups
);
3247 kfree(hba_cg
->default_groups
);
3248 kfree(target_cg
->default_groups
);
3249 release_se_kmem_caches();
3253 static void __exit
target_core_exit_configfs(void)
3255 struct configfs_subsystem
*subsys
;
3256 struct config_group
*hba_cg
, *alua_cg
, *lu_gp_cg
;
3257 struct config_item
*item
;
3260 subsys
= target_core_subsystem
[0];
3262 lu_gp_cg
= &alua_lu_gps_group
;
3263 for (i
= 0; lu_gp_cg
->default_groups
[i
]; i
++) {
3264 item
= &lu_gp_cg
->default_groups
[i
]->cg_item
;
3265 lu_gp_cg
->default_groups
[i
] = NULL
;
3266 config_item_put(item
);
3268 kfree(lu_gp_cg
->default_groups
);
3269 lu_gp_cg
->default_groups
= NULL
;
3271 alua_cg
= &alua_group
;
3272 for (i
= 0; alua_cg
->default_groups
[i
]; i
++) {
3273 item
= &alua_cg
->default_groups
[i
]->cg_item
;
3274 alua_cg
->default_groups
[i
] = NULL
;
3275 config_item_put(item
);
3277 kfree(alua_cg
->default_groups
);
3278 alua_cg
->default_groups
= NULL
;
3280 hba_cg
= &target_core_hbagroup
;
3281 for (i
= 0; hba_cg
->default_groups
[i
]; i
++) {
3282 item
= &hba_cg
->default_groups
[i
]->cg_item
;
3283 hba_cg
->default_groups
[i
] = NULL
;
3284 config_item_put(item
);
3286 kfree(hba_cg
->default_groups
);
3287 hba_cg
->default_groups
= NULL
;
3289 * We expect subsys->su_group.default_groups to be released
3290 * by configfs subsystem provider logic..
3292 configfs_unregister_subsystem(subsys
);
3293 kfree(subsys
->su_group
.default_groups
);
3295 core_alua_free_lu_gp(default_lu_gp
);
3296 default_lu_gp
= NULL
;
3298 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
3299 " Infrastructure\n");
3301 core_dev_release_virtual_lun0();
3303 target_xcopy_release_pt();
3304 release_se_kmem_caches();
3307 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3308 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3309 MODULE_LICENSE("GPL");
3311 module_init(target_core_init_configfs
);
3312 module_exit(target_core_exit_configfs
);