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 #define TB_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \
54 static void target_core_setup_##_name##_cit(struct se_subsystem_api *sa) \
56 struct target_backend_cits *tbc = &sa->tb_cits; \
57 struct config_item_type *cit = &tbc->tb_##_name##_cit; \
59 cit->ct_item_ops = _item_ops; \
60 cit->ct_group_ops = _group_ops; \
61 cit->ct_attrs = _attrs; \
62 cit->ct_owner = sa->owner; \
63 pr_debug("Setup generic %s\n", __stringify(_name)); \
66 extern struct t10_alua_lu_gp
*default_lu_gp
;
68 static LIST_HEAD(g_tf_list
);
69 static DEFINE_MUTEX(g_tf_lock
);
71 struct target_core_configfs_attribute
{
72 struct configfs_attribute attr
;
73 ssize_t (*show
)(void *, char *);
74 ssize_t (*store
)(void *, const char *, size_t);
77 static struct config_group target_core_hbagroup
;
78 static struct config_group alua_group
;
79 static struct config_group alua_lu_gps_group
;
81 static inline struct se_hba
*
82 item_to_hba(struct config_item
*item
)
84 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
88 * Attributes for /sys/kernel/config/target/
90 static ssize_t
target_core_attr_show(struct config_item
*item
,
91 struct configfs_attribute
*attr
,
94 return sprintf(page
, "Target Engine Core ConfigFS Infrastructure %s"
95 " on %s/%s on "UTS_RELEASE
"\n", TARGET_CORE_CONFIGFS_VERSION
,
96 utsname()->sysname
, utsname()->machine
);
99 static struct configfs_item_operations target_core_fabric_item_ops
= {
100 .show_attribute
= target_core_attr_show
,
103 static struct configfs_attribute target_core_item_attr_version
= {
104 .ca_owner
= THIS_MODULE
,
105 .ca_name
= "version",
109 static struct target_fabric_configfs
*target_core_get_fabric(
112 struct target_fabric_configfs
*tf
;
117 mutex_lock(&g_tf_lock
);
118 list_for_each_entry(tf
, &g_tf_list
, tf_list
) {
119 if (!strcmp(tf
->tf_name
, name
)) {
120 atomic_inc(&tf
->tf_access_cnt
);
121 mutex_unlock(&g_tf_lock
);
125 mutex_unlock(&g_tf_lock
);
131 * Called from struct target_core_group_ops->make_group()
133 static struct config_group
*target_core_register_fabric(
134 struct config_group
*group
,
137 struct target_fabric_configfs
*tf
;
140 pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:"
141 " %s\n", group
, name
);
143 tf
= target_core_get_fabric(name
);
145 pr_err("target_core_register_fabric() trying autoload for %s\n",
149 * Below are some hardcoded request_module() calls to automatically
150 * local fabric modules when the following is called:
152 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
154 * Note that this does not limit which TCM fabric module can be
155 * registered, but simply provids auto loading logic for modules with
156 * mkdir(2) system calls with known TCM fabric modules.
159 if (!strncmp(name
, "iscsi", 5)) {
161 * Automatically load the LIO Target fabric module when the
162 * following is called:
164 * mkdir -p $CONFIGFS/target/iscsi
166 ret
= request_module("iscsi_target_mod");
168 pr_err("request_module() failed for"
169 " iscsi_target_mod.ko: %d\n", ret
);
170 return ERR_PTR(-EINVAL
);
172 } else if (!strncmp(name
, "loopback", 8)) {
174 * Automatically load the tcm_loop fabric module when the
175 * following is called:
177 * mkdir -p $CONFIGFS/target/loopback
179 ret
= request_module("tcm_loop");
181 pr_err("request_module() failed for"
182 " tcm_loop.ko: %d\n", ret
);
183 return ERR_PTR(-EINVAL
);
187 tf
= target_core_get_fabric(name
);
191 pr_err("target_core_get_fabric() failed for %s\n",
193 return ERR_PTR(-EINVAL
);
195 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
196 " %s\n", tf
->tf_name
);
198 * On a successful target_core_get_fabric() look, the returned
199 * struct target_fabric_configfs *tf will contain a usage reference.
201 pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
202 &tf
->tf_cit_tmpl
.tfc_wwn_cit
);
204 tf
->tf_group
.default_groups
= tf
->tf_default_groups
;
205 tf
->tf_group
.default_groups
[0] = &tf
->tf_disc_group
;
206 tf
->tf_group
.default_groups
[1] = NULL
;
208 config_group_init_type_name(&tf
->tf_group
, name
,
209 &tf
->tf_cit_tmpl
.tfc_wwn_cit
);
210 config_group_init_type_name(&tf
->tf_disc_group
, "discovery_auth",
211 &tf
->tf_cit_tmpl
.tfc_discovery_cit
);
213 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
214 " %s\n", tf
->tf_group
.cg_item
.ci_name
);
216 * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item()
218 tf
->tf_ops
.tf_subsys
= tf
->tf_subsys
;
219 tf
->tf_fabric
= &tf
->tf_group
.cg_item
;
220 pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
223 return &tf
->tf_group
;
227 * Called from struct target_core_group_ops->drop_item()
229 static void target_core_deregister_fabric(
230 struct config_group
*group
,
231 struct config_item
*item
)
233 struct target_fabric_configfs
*tf
= container_of(
234 to_config_group(item
), struct target_fabric_configfs
, tf_group
);
235 struct config_group
*tf_group
;
236 struct config_item
*df_item
;
239 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
240 " tf list\n", config_item_name(item
));
242 pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:"
243 " %s\n", tf
->tf_name
);
244 atomic_dec(&tf
->tf_access_cnt
);
246 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing"
247 " tf->tf_fabric for %s\n", tf
->tf_name
);
248 tf
->tf_fabric
= NULL
;
250 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
251 " %s\n", config_item_name(item
));
253 tf_group
= &tf
->tf_group
;
254 for (i
= 0; tf_group
->default_groups
[i
]; i
++) {
255 df_item
= &tf_group
->default_groups
[i
]->cg_item
;
256 tf_group
->default_groups
[i
] = NULL
;
257 config_item_put(df_item
);
259 config_item_put(item
);
262 static struct configfs_group_operations target_core_fabric_group_ops
= {
263 .make_group
= &target_core_register_fabric
,
264 .drop_item
= &target_core_deregister_fabric
,
268 * All item attributes appearing in /sys/kernel/target/ appear here.
270 static struct configfs_attribute
*target_core_fabric_item_attrs
[] = {
271 &target_core_item_attr_version
,
276 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
278 static struct config_item_type target_core_fabrics_item
= {
279 .ct_item_ops
= &target_core_fabric_item_ops
,
280 .ct_group_ops
= &target_core_fabric_group_ops
,
281 .ct_attrs
= target_core_fabric_item_attrs
,
282 .ct_owner
= THIS_MODULE
,
285 static struct configfs_subsystem target_core_fabrics
= {
288 .ci_namebuf
= "target",
289 .ci_type
= &target_core_fabrics_item
,
294 struct configfs_subsystem
*target_core_subsystem
[] = {
295 &target_core_fabrics
,
299 /*##############################################################################
300 // Start functions called by external Target Fabrics Modules
301 //############################################################################*/
304 * First function called by fabric modules to:
306 * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer.
307 * 2) Add struct target_fabric_configfs to g_tf_list
308 * 3) Return struct target_fabric_configfs to fabric module to be passed
309 * into target_fabric_configfs_register().
311 struct target_fabric_configfs
*target_fabric_configfs_init(
312 struct module
*fabric_mod
,
315 struct target_fabric_configfs
*tf
;
318 pr_err("Unable to locate passed fabric name\n");
319 return ERR_PTR(-EINVAL
);
321 if (strlen(name
) >= TARGET_FABRIC_NAME_SIZE
) {
322 pr_err("Passed name: %s exceeds TARGET_FABRIC"
323 "_NAME_SIZE\n", name
);
324 return ERR_PTR(-EINVAL
);
327 tf
= kzalloc(sizeof(struct target_fabric_configfs
), GFP_KERNEL
);
329 return ERR_PTR(-ENOMEM
);
331 INIT_LIST_HEAD(&tf
->tf_list
);
332 atomic_set(&tf
->tf_access_cnt
, 0);
334 * Setup the default generic struct config_item_type's (cits) in
335 * struct target_fabric_configfs->tf_cit_tmpl
337 tf
->tf_module
= fabric_mod
;
338 target_fabric_setup_cits(tf
);
340 tf
->tf_subsys
= target_core_subsystem
[0];
341 snprintf(tf
->tf_name
, TARGET_FABRIC_NAME_SIZE
, "%s", name
);
343 mutex_lock(&g_tf_lock
);
344 list_add_tail(&tf
->tf_list
, &g_tf_list
);
345 mutex_unlock(&g_tf_lock
);
347 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>"
349 pr_debug("Initialized struct target_fabric_configfs: %p for"
350 " %s\n", tf
, tf
->tf_name
);
353 EXPORT_SYMBOL(target_fabric_configfs_init
);
356 * Called by fabric plugins after FAILED target_fabric_configfs_register() call.
358 void target_fabric_configfs_free(
359 struct target_fabric_configfs
*tf
)
361 mutex_lock(&g_tf_lock
);
362 list_del(&tf
->tf_list
);
363 mutex_unlock(&g_tf_lock
);
367 EXPORT_SYMBOL(target_fabric_configfs_free
);
370 * Perform a sanity check of the passed tf->tf_ops before completing
371 * TCM fabric module registration.
373 static int target_fabric_tf_ops_check(
374 struct target_fabric_configfs
*tf
)
376 struct target_core_fabric_ops
*tfo
= &tf
->tf_ops
;
378 if (!tfo
->get_fabric_name
) {
379 pr_err("Missing tfo->get_fabric_name()\n");
382 if (!tfo
->get_fabric_proto_ident
) {
383 pr_err("Missing tfo->get_fabric_proto_ident()\n");
386 if (!tfo
->tpg_get_wwn
) {
387 pr_err("Missing tfo->tpg_get_wwn()\n");
390 if (!tfo
->tpg_get_tag
) {
391 pr_err("Missing tfo->tpg_get_tag()\n");
394 if (!tfo
->tpg_get_default_depth
) {
395 pr_err("Missing tfo->tpg_get_default_depth()\n");
398 if (!tfo
->tpg_get_pr_transport_id
) {
399 pr_err("Missing tfo->tpg_get_pr_transport_id()\n");
402 if (!tfo
->tpg_get_pr_transport_id_len
) {
403 pr_err("Missing tfo->tpg_get_pr_transport_id_len()\n");
406 if (!tfo
->tpg_check_demo_mode
) {
407 pr_err("Missing tfo->tpg_check_demo_mode()\n");
410 if (!tfo
->tpg_check_demo_mode_cache
) {
411 pr_err("Missing tfo->tpg_check_demo_mode_cache()\n");
414 if (!tfo
->tpg_check_demo_mode_write_protect
) {
415 pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n");
418 if (!tfo
->tpg_check_prod_mode_write_protect
) {
419 pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n");
422 if (!tfo
->tpg_alloc_fabric_acl
) {
423 pr_err("Missing tfo->tpg_alloc_fabric_acl()\n");
426 if (!tfo
->tpg_release_fabric_acl
) {
427 pr_err("Missing tfo->tpg_release_fabric_acl()\n");
430 if (!tfo
->tpg_get_inst_index
) {
431 pr_err("Missing tfo->tpg_get_inst_index()\n");
434 if (!tfo
->release_cmd
) {
435 pr_err("Missing tfo->release_cmd()\n");
438 if (!tfo
->shutdown_session
) {
439 pr_err("Missing tfo->shutdown_session()\n");
442 if (!tfo
->close_session
) {
443 pr_err("Missing tfo->close_session()\n");
446 if (!tfo
->sess_get_index
) {
447 pr_err("Missing tfo->sess_get_index()\n");
450 if (!tfo
->write_pending
) {
451 pr_err("Missing tfo->write_pending()\n");
454 if (!tfo
->write_pending_status
) {
455 pr_err("Missing tfo->write_pending_status()\n");
458 if (!tfo
->set_default_node_attributes
) {
459 pr_err("Missing tfo->set_default_node_attributes()\n");
462 if (!tfo
->get_task_tag
) {
463 pr_err("Missing tfo->get_task_tag()\n");
466 if (!tfo
->get_cmd_state
) {
467 pr_err("Missing tfo->get_cmd_state()\n");
470 if (!tfo
->queue_data_in
) {
471 pr_err("Missing tfo->queue_data_in()\n");
474 if (!tfo
->queue_status
) {
475 pr_err("Missing tfo->queue_status()\n");
478 if (!tfo
->queue_tm_rsp
) {
479 pr_err("Missing tfo->queue_tm_rsp()\n");
482 if (!tfo
->aborted_task
) {
483 pr_err("Missing tfo->aborted_task()\n");
487 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
488 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
489 * target_core_fabric_configfs.c WWN+TPG group context code.
491 if (!tfo
->fabric_make_wwn
) {
492 pr_err("Missing tfo->fabric_make_wwn()\n");
495 if (!tfo
->fabric_drop_wwn
) {
496 pr_err("Missing tfo->fabric_drop_wwn()\n");
499 if (!tfo
->fabric_make_tpg
) {
500 pr_err("Missing tfo->fabric_make_tpg()\n");
503 if (!tfo
->fabric_drop_tpg
) {
504 pr_err("Missing tfo->fabric_drop_tpg()\n");
512 * Called 2nd from fabric module with returned parameter of
513 * struct target_fabric_configfs * from target_fabric_configfs_init().
515 * Upon a successful registration, the new fabric's struct config_item is
516 * return. Also, a pointer to this struct is set in the passed
517 * struct target_fabric_configfs.
519 int target_fabric_configfs_register(
520 struct target_fabric_configfs
*tf
)
525 pr_err("Unable to locate target_fabric_configfs"
529 if (!tf
->tf_subsys
) {
530 pr_err("Unable to target struct config_subsystem"
534 ret
= target_fabric_tf_ops_check(tf
);
538 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>"
542 EXPORT_SYMBOL(target_fabric_configfs_register
);
544 void target_fabric_configfs_deregister(
545 struct target_fabric_configfs
*tf
)
547 struct configfs_subsystem
*su
;
550 pr_err("Unable to locate passed target_fabric_"
556 pr_err("Unable to locate passed tf->tf_subsys"
560 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
562 mutex_lock(&g_tf_lock
);
563 if (atomic_read(&tf
->tf_access_cnt
)) {
564 mutex_unlock(&g_tf_lock
);
565 pr_err("Non zero tf->tf_access_cnt for fabric %s\n",
569 list_del(&tf
->tf_list
);
570 mutex_unlock(&g_tf_lock
);
572 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
573 " %s\n", tf
->tf_name
);
574 tf
->tf_module
= NULL
;
575 tf
->tf_subsys
= NULL
;
578 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
581 EXPORT_SYMBOL(target_fabric_configfs_deregister
);
583 /*##############################################################################
584 // Stop functions called by external Target Fabrics Modules
585 //############################################################################*/
587 /* Start functions for struct config_item_type tb_dev_attrib_cit */
589 #define DEF_DEV_ATTRIB_SHOW(_name) \
590 static ssize_t target_core_dev_show_attr_##_name( \
591 struct se_dev_attrib *da, \
594 return snprintf(page, PAGE_SIZE, "%u\n", \
595 (u32)da->da_dev->dev_attrib._name); \
598 #define DEF_DEV_ATTRIB_STORE(_name) \
599 static ssize_t target_core_dev_store_attr_##_name( \
600 struct se_dev_attrib *da, \
607 ret = kstrtoul(page, 0, &val); \
609 pr_err("kstrtoul() failed with" \
610 " ret: %d\n", ret); \
613 ret = se_dev_set_##_name(da->da_dev, (u32)val); \
615 return (!ret) ? count : -EINVAL; \
618 #define DEF_DEV_ATTRIB(_name) \
619 DEF_DEV_ATTRIB_SHOW(_name); \
620 DEF_DEV_ATTRIB_STORE(_name);
622 #define DEF_DEV_ATTRIB_RO(_name) \
623 DEF_DEV_ATTRIB_SHOW(_name);
625 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib
, se_dev_attrib
);
626 #define SE_DEV_ATTR(_name, _mode) \
627 static struct target_core_dev_attrib_attribute \
628 target_core_dev_attrib_##_name = \
629 __CONFIGFS_EATTR(_name, _mode, \
630 target_core_dev_show_attr_##_name, \
631 target_core_dev_store_attr_##_name);
633 #define SE_DEV_ATTR_RO(_name); \
634 static struct target_core_dev_attrib_attribute \
635 target_core_dev_attrib_##_name = \
636 __CONFIGFS_EATTR_RO(_name, \
637 target_core_dev_show_attr_##_name);
639 DEF_DEV_ATTRIB(emulate_model_alias
);
640 SE_DEV_ATTR(emulate_model_alias
, S_IRUGO
| S_IWUSR
);
642 DEF_DEV_ATTRIB(emulate_dpo
);
643 SE_DEV_ATTR(emulate_dpo
, S_IRUGO
| S_IWUSR
);
645 DEF_DEV_ATTRIB(emulate_fua_write
);
646 SE_DEV_ATTR(emulate_fua_write
, S_IRUGO
| S_IWUSR
);
648 DEF_DEV_ATTRIB(emulate_fua_read
);
649 SE_DEV_ATTR(emulate_fua_read
, S_IRUGO
| S_IWUSR
);
651 DEF_DEV_ATTRIB(emulate_write_cache
);
652 SE_DEV_ATTR(emulate_write_cache
, S_IRUGO
| S_IWUSR
);
654 DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl
);
655 SE_DEV_ATTR(emulate_ua_intlck_ctrl
, S_IRUGO
| S_IWUSR
);
657 DEF_DEV_ATTRIB(emulate_tas
);
658 SE_DEV_ATTR(emulate_tas
, S_IRUGO
| S_IWUSR
);
660 DEF_DEV_ATTRIB(emulate_tpu
);
661 SE_DEV_ATTR(emulate_tpu
, S_IRUGO
| S_IWUSR
);
663 DEF_DEV_ATTRIB(emulate_tpws
);
664 SE_DEV_ATTR(emulate_tpws
, S_IRUGO
| S_IWUSR
);
666 DEF_DEV_ATTRIB(emulate_caw
);
667 SE_DEV_ATTR(emulate_caw
, S_IRUGO
| S_IWUSR
);
669 DEF_DEV_ATTRIB(emulate_3pc
);
670 SE_DEV_ATTR(emulate_3pc
, S_IRUGO
| S_IWUSR
);
672 DEF_DEV_ATTRIB(pi_prot_type
);
673 SE_DEV_ATTR(pi_prot_type
, S_IRUGO
| S_IWUSR
);
675 DEF_DEV_ATTRIB_RO(hw_pi_prot_type
);
676 SE_DEV_ATTR_RO(hw_pi_prot_type
);
678 DEF_DEV_ATTRIB(pi_prot_format
);
679 SE_DEV_ATTR(pi_prot_format
, S_IRUGO
| S_IWUSR
);
681 DEF_DEV_ATTRIB(enforce_pr_isids
);
682 SE_DEV_ATTR(enforce_pr_isids
, S_IRUGO
| S_IWUSR
);
684 DEF_DEV_ATTRIB(is_nonrot
);
685 SE_DEV_ATTR(is_nonrot
, S_IRUGO
| S_IWUSR
);
687 DEF_DEV_ATTRIB(emulate_rest_reord
);
688 SE_DEV_ATTR(emulate_rest_reord
, S_IRUGO
| S_IWUSR
);
690 DEF_DEV_ATTRIB(force_pr_aptpl
);
691 SE_DEV_ATTR(force_pr_aptpl
, S_IRUGO
| S_IWUSR
);
693 DEF_DEV_ATTRIB_RO(hw_block_size
);
694 SE_DEV_ATTR_RO(hw_block_size
);
696 DEF_DEV_ATTRIB(block_size
);
697 SE_DEV_ATTR(block_size
, S_IRUGO
| S_IWUSR
);
699 DEF_DEV_ATTRIB_RO(hw_max_sectors
);
700 SE_DEV_ATTR_RO(hw_max_sectors
);
702 DEF_DEV_ATTRIB(fabric_max_sectors
);
703 SE_DEV_ATTR(fabric_max_sectors
, S_IRUGO
| S_IWUSR
);
705 DEF_DEV_ATTRIB(optimal_sectors
);
706 SE_DEV_ATTR(optimal_sectors
, S_IRUGO
| S_IWUSR
);
708 DEF_DEV_ATTRIB_RO(hw_queue_depth
);
709 SE_DEV_ATTR_RO(hw_queue_depth
);
711 DEF_DEV_ATTRIB(queue_depth
);
712 SE_DEV_ATTR(queue_depth
, S_IRUGO
| S_IWUSR
);
714 DEF_DEV_ATTRIB(max_unmap_lba_count
);
715 SE_DEV_ATTR(max_unmap_lba_count
, S_IRUGO
| S_IWUSR
);
717 DEF_DEV_ATTRIB(max_unmap_block_desc_count
);
718 SE_DEV_ATTR(max_unmap_block_desc_count
, S_IRUGO
| S_IWUSR
);
720 DEF_DEV_ATTRIB(unmap_granularity
);
721 SE_DEV_ATTR(unmap_granularity
, S_IRUGO
| S_IWUSR
);
723 DEF_DEV_ATTRIB(unmap_granularity_alignment
);
724 SE_DEV_ATTR(unmap_granularity_alignment
, S_IRUGO
| S_IWUSR
);
726 DEF_DEV_ATTRIB(max_write_same_len
);
727 SE_DEV_ATTR(max_write_same_len
, S_IRUGO
| S_IWUSR
);
729 CONFIGFS_EATTR_OPS(target_core_dev_attrib
, se_dev_attrib
, da_group
);
731 static struct configfs_attribute
*target_core_dev_attrib_attrs
[] = {
732 &target_core_dev_attrib_emulate_model_alias
.attr
,
733 &target_core_dev_attrib_emulate_dpo
.attr
,
734 &target_core_dev_attrib_emulate_fua_write
.attr
,
735 &target_core_dev_attrib_emulate_fua_read
.attr
,
736 &target_core_dev_attrib_emulate_write_cache
.attr
,
737 &target_core_dev_attrib_emulate_ua_intlck_ctrl
.attr
,
738 &target_core_dev_attrib_emulate_tas
.attr
,
739 &target_core_dev_attrib_emulate_tpu
.attr
,
740 &target_core_dev_attrib_emulate_tpws
.attr
,
741 &target_core_dev_attrib_emulate_caw
.attr
,
742 &target_core_dev_attrib_emulate_3pc
.attr
,
743 &target_core_dev_attrib_pi_prot_type
.attr
,
744 &target_core_dev_attrib_hw_pi_prot_type
.attr
,
745 &target_core_dev_attrib_pi_prot_format
.attr
,
746 &target_core_dev_attrib_enforce_pr_isids
.attr
,
747 &target_core_dev_attrib_force_pr_aptpl
.attr
,
748 &target_core_dev_attrib_is_nonrot
.attr
,
749 &target_core_dev_attrib_emulate_rest_reord
.attr
,
750 &target_core_dev_attrib_hw_block_size
.attr
,
751 &target_core_dev_attrib_block_size
.attr
,
752 &target_core_dev_attrib_hw_max_sectors
.attr
,
753 &target_core_dev_attrib_fabric_max_sectors
.attr
,
754 &target_core_dev_attrib_optimal_sectors
.attr
,
755 &target_core_dev_attrib_hw_queue_depth
.attr
,
756 &target_core_dev_attrib_queue_depth
.attr
,
757 &target_core_dev_attrib_max_unmap_lba_count
.attr
,
758 &target_core_dev_attrib_max_unmap_block_desc_count
.attr
,
759 &target_core_dev_attrib_unmap_granularity
.attr
,
760 &target_core_dev_attrib_unmap_granularity_alignment
.attr
,
761 &target_core_dev_attrib_max_write_same_len
.attr
,
765 static struct configfs_item_operations target_core_dev_attrib_ops
= {
766 .show_attribute
= target_core_dev_attrib_attr_show
,
767 .store_attribute
= target_core_dev_attrib_attr_store
,
770 TB_CIT_SETUP(dev_attrib
, &target_core_dev_attrib_ops
, NULL
,
771 target_core_dev_attrib_attrs
);
773 /* End functions for struct config_item_type tb_dev_attrib_cit */
775 /* Start functions for struct config_item_type tb_dev_wwn_cit */
777 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn
, t10_wwn
);
778 #define SE_DEV_WWN_ATTR(_name, _mode) \
779 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
780 __CONFIGFS_EATTR(_name, _mode, \
781 target_core_dev_wwn_show_attr_##_name, \
782 target_core_dev_wwn_store_attr_##_name);
784 #define SE_DEV_WWN_ATTR_RO(_name); \
786 static struct target_core_dev_wwn_attribute \
787 target_core_dev_wwn_##_name = \
788 __CONFIGFS_EATTR_RO(_name, \
789 target_core_dev_wwn_show_attr_##_name); \
793 * VPD page 0x80 Unit serial
795 static ssize_t
target_core_dev_wwn_show_attr_vpd_unit_serial(
796 struct t10_wwn
*t10_wwn
,
799 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
800 &t10_wwn
->unit_serial
[0]);
803 static ssize_t
target_core_dev_wwn_store_attr_vpd_unit_serial(
804 struct t10_wwn
*t10_wwn
,
808 struct se_device
*dev
= t10_wwn
->t10_dev
;
809 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
812 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
813 * from the struct scsi_device level firmware, do not allow
814 * VPD Unit Serial to be emulated.
816 * Note this struct scsi_device could also be emulating VPD
817 * information from its drivers/scsi LLD. But for now we assume
818 * it is doing 'the right thing' wrt a world wide unique
819 * VPD Unit Serial Number that OS dependent multipath can depend on.
821 if (dev
->dev_flags
& DF_FIRMWARE_VPD_UNIT_SERIAL
) {
822 pr_err("Underlying SCSI device firmware provided VPD"
823 " Unit Serial, ignoring request\n");
827 if (strlen(page
) >= INQUIRY_VPD_SERIAL_LEN
) {
828 pr_err("Emulated VPD Unit Serial exceeds"
829 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
833 * Check to see if any active $FABRIC_MOD exports exist. If they
834 * do exist, fail here as changing this information on the fly
835 * (underneath the initiator side OS dependent multipath code)
836 * could cause negative effects.
838 if (dev
->export_count
) {
839 pr_err("Unable to set VPD Unit Serial while"
840 " active %d $FABRIC_MOD exports exist\n",
846 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
848 * Also, strip any newline added from the userspace
849 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
851 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
852 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
853 snprintf(dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
854 "%s", strstrip(buf
));
855 dev
->dev_flags
|= DF_EMULATED_VPD_UNIT_SERIAL
;
857 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
858 " %s\n", dev
->t10_wwn
.unit_serial
);
863 SE_DEV_WWN_ATTR(vpd_unit_serial
, S_IRUGO
| S_IWUSR
);
866 * VPD page 0x83 Protocol Identifier
868 static ssize_t
target_core_dev_wwn_show_attr_vpd_protocol_identifier(
869 struct t10_wwn
*t10_wwn
,
873 unsigned char buf
[VPD_TMP_BUF_SIZE
];
876 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
878 spin_lock(&t10_wwn
->t10_vpd_lock
);
879 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
880 if (!vpd
->protocol_identifier_set
)
883 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
885 if (len
+ strlen(buf
) >= PAGE_SIZE
)
888 len
+= sprintf(page
+len
, "%s", buf
);
890 spin_unlock(&t10_wwn
->t10_vpd_lock
);
895 static ssize_t
target_core_dev_wwn_store_attr_vpd_protocol_identifier(
896 struct t10_wwn
*t10_wwn
,
903 SE_DEV_WWN_ATTR(vpd_protocol_identifier
, S_IRUGO
| S_IWUSR
);
906 * Generic wrapper for dumping VPD identifiers by association.
908 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
909 static ssize_t target_core_dev_wwn_show_attr_##_name( \
910 struct t10_wwn *t10_wwn, \
913 struct t10_vpd *vpd; \
914 unsigned char buf[VPD_TMP_BUF_SIZE]; \
917 spin_lock(&t10_wwn->t10_vpd_lock); \
918 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
919 if (vpd->association != _assoc) \
922 memset(buf, 0, VPD_TMP_BUF_SIZE); \
923 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
924 if (len + strlen(buf) >= PAGE_SIZE) \
926 len += sprintf(page+len, "%s", buf); \
928 memset(buf, 0, VPD_TMP_BUF_SIZE); \
929 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
930 if (len + strlen(buf) >= PAGE_SIZE) \
932 len += sprintf(page+len, "%s", buf); \
934 memset(buf, 0, VPD_TMP_BUF_SIZE); \
935 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
936 if (len + strlen(buf) >= PAGE_SIZE) \
938 len += sprintf(page+len, "%s", buf); \
940 spin_unlock(&t10_wwn->t10_vpd_lock); \
946 * VPD page 0x83 Association: Logical Unit
948 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
950 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
951 struct t10_wwn
*t10_wwn
,
958 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit
, S_IRUGO
| S_IWUSR
);
961 * VPD page 0x83 Association: Target Port
963 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
965 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_target_port(
966 struct t10_wwn
*t10_wwn
,
973 SE_DEV_WWN_ATTR(vpd_assoc_target_port
, S_IRUGO
| S_IWUSR
);
976 * VPD page 0x83 Association: SCSI Target Device
978 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
980 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
981 struct t10_wwn
*t10_wwn
,
988 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device
, S_IRUGO
| S_IWUSR
);
990 CONFIGFS_EATTR_OPS(target_core_dev_wwn
, t10_wwn
, t10_wwn_group
);
992 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
993 &target_core_dev_wwn_vpd_unit_serial
.attr
,
994 &target_core_dev_wwn_vpd_protocol_identifier
.attr
,
995 &target_core_dev_wwn_vpd_assoc_logical_unit
.attr
,
996 &target_core_dev_wwn_vpd_assoc_target_port
.attr
,
997 &target_core_dev_wwn_vpd_assoc_scsi_target_device
.attr
,
1001 static struct configfs_item_operations target_core_dev_wwn_ops
= {
1002 .show_attribute
= target_core_dev_wwn_attr_show
,
1003 .store_attribute
= target_core_dev_wwn_attr_store
,
1006 TB_CIT_SETUP(dev_wwn
, &target_core_dev_wwn_ops
, NULL
, target_core_dev_wwn_attrs
);
1008 /* End functions for struct config_item_type tb_dev_wwn_cit */
1010 /* Start functions for struct config_item_type tb_dev_pr_cit */
1012 CONFIGFS_EATTR_STRUCT(target_core_dev_pr
, se_device
);
1013 #define SE_DEV_PR_ATTR(_name, _mode) \
1014 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1015 __CONFIGFS_EATTR(_name, _mode, \
1016 target_core_dev_pr_show_attr_##_name, \
1017 target_core_dev_pr_store_attr_##_name);
1019 #define SE_DEV_PR_ATTR_RO(_name); \
1020 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1021 __CONFIGFS_EATTR_RO(_name, \
1022 target_core_dev_pr_show_attr_##_name);
1024 static ssize_t
target_core_dev_pr_show_spc3_res(struct se_device
*dev
,
1027 struct se_node_acl
*se_nacl
;
1028 struct t10_pr_registration
*pr_reg
;
1029 char i_buf
[PR_REG_ISID_ID_LEN
];
1031 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1033 pr_reg
= dev
->dev_pr_res_holder
;
1035 return sprintf(page
, "No SPC-3 Reservation holder\n");
1037 se_nacl
= pr_reg
->pr_reg_nacl
;
1038 core_pr_dump_initiator_port(pr_reg
, i_buf
, PR_REG_ISID_ID_LEN
);
1040 return sprintf(page
, "SPC-3 Reservation: %s Initiator: %s%s\n",
1041 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1042 se_nacl
->initiatorname
, i_buf
);
1045 static ssize_t
target_core_dev_pr_show_spc2_res(struct se_device
*dev
,
1048 struct se_node_acl
*se_nacl
;
1051 se_nacl
= dev
->dev_reserved_node_acl
;
1054 "SPC-2 Reservation: %s Initiator: %s\n",
1055 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1056 se_nacl
->initiatorname
);
1058 len
= sprintf(page
, "No SPC-2 Reservation holder\n");
1063 static ssize_t
target_core_dev_pr_show_attr_res_holder(struct se_device
*dev
,
1068 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1069 return sprintf(page
, "Passthrough\n");
1071 spin_lock(&dev
->dev_reservation_lock
);
1072 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1073 ret
= target_core_dev_pr_show_spc2_res(dev
, page
);
1075 ret
= target_core_dev_pr_show_spc3_res(dev
, page
);
1076 spin_unlock(&dev
->dev_reservation_lock
);
1080 SE_DEV_PR_ATTR_RO(res_holder
);
1082 static ssize_t
target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1083 struct se_device
*dev
, char *page
)
1087 spin_lock(&dev
->dev_reservation_lock
);
1088 if (!dev
->dev_pr_res_holder
) {
1089 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1090 } else if (dev
->dev_pr_res_holder
->pr_reg_all_tg_pt
) {
1091 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1092 " Ports registration\n");
1094 len
= sprintf(page
, "SPC-3 Reservation: Single"
1095 " Target Port registration\n");
1098 spin_unlock(&dev
->dev_reservation_lock
);
1102 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts
);
1104 static ssize_t
target_core_dev_pr_show_attr_res_pr_generation(
1105 struct se_device
*dev
, char *page
)
1107 return sprintf(page
, "0x%08x\n", dev
->t10_pr
.pr_generation
);
1110 SE_DEV_PR_ATTR_RO(res_pr_generation
);
1113 * res_pr_holder_tg_port
1115 static ssize_t
target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1116 struct se_device
*dev
, char *page
)
1118 struct se_node_acl
*se_nacl
;
1120 struct se_portal_group
*se_tpg
;
1121 struct t10_pr_registration
*pr_reg
;
1122 struct target_core_fabric_ops
*tfo
;
1125 spin_lock(&dev
->dev_reservation_lock
);
1126 pr_reg
= dev
->dev_pr_res_holder
;
1128 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1132 se_nacl
= pr_reg
->pr_reg_nacl
;
1133 se_tpg
= se_nacl
->se_tpg
;
1134 lun
= pr_reg
->pr_reg_tg_pt_lun
;
1135 tfo
= se_tpg
->se_tpg_tfo
;
1137 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1138 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1139 tfo
->tpg_get_wwn(se_tpg
));
1140 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1141 " Identifier Tag: %hu %s Portal Group Tag: %hu"
1142 " %s Logical Unit: %u\n", lun
->lun_sep
->sep_rtpi
,
1143 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1144 tfo
->get_fabric_name(), lun
->unpacked_lun
);
1147 spin_unlock(&dev
->dev_reservation_lock
);
1151 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port
);
1153 static ssize_t
target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1154 struct se_device
*dev
, char *page
)
1156 struct target_core_fabric_ops
*tfo
;
1157 struct t10_pr_registration
*pr_reg
;
1158 unsigned char buf
[384];
1159 char i_buf
[PR_REG_ISID_ID_LEN
];
1163 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1165 spin_lock(&dev
->t10_pr
.registration_lock
);
1166 list_for_each_entry(pr_reg
, &dev
->t10_pr
.registration_list
,
1169 memset(buf
, 0, 384);
1170 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1171 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1172 core_pr_dump_initiator_port(pr_reg
, i_buf
,
1173 PR_REG_ISID_ID_LEN
);
1174 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1175 tfo
->get_fabric_name(),
1176 pr_reg
->pr_reg_nacl
->initiatorname
, i_buf
, pr_reg
->pr_res_key
,
1177 pr_reg
->pr_res_generation
);
1179 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1182 len
+= sprintf(page
+len
, "%s", buf
);
1185 spin_unlock(&dev
->t10_pr
.registration_lock
);
1188 len
+= sprintf(page
+len
, "None\n");
1193 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts
);
1195 static ssize_t
target_core_dev_pr_show_attr_res_pr_type(
1196 struct se_device
*dev
, char *page
)
1198 struct t10_pr_registration
*pr_reg
;
1201 spin_lock(&dev
->dev_reservation_lock
);
1202 pr_reg
= dev
->dev_pr_res_holder
;
1204 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1205 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1207 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1210 spin_unlock(&dev
->dev_reservation_lock
);
1214 SE_DEV_PR_ATTR_RO(res_pr_type
);
1216 static ssize_t
target_core_dev_pr_show_attr_res_type(
1217 struct se_device
*dev
, char *page
)
1219 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1220 return sprintf(page
, "SPC_PASSTHROUGH\n");
1221 else if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1222 return sprintf(page
, "SPC2_RESERVATIONS\n");
1224 return sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1227 SE_DEV_PR_ATTR_RO(res_type
);
1229 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_active(
1230 struct se_device
*dev
, char *page
)
1232 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1235 return sprintf(page
, "APTPL Bit Status: %s\n",
1236 (dev
->t10_pr
.pr_aptpl_active
) ? "Activated" : "Disabled");
1239 SE_DEV_PR_ATTR_RO(res_aptpl_active
);
1242 * res_aptpl_metadata
1244 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_metadata(
1245 struct se_device
*dev
, char *page
)
1247 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1250 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1254 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1255 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1256 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1257 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1260 static match_table_t tokens
= {
1261 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1262 {Opt_initiator_node
, "initiator_node=%s"},
1263 {Opt_initiator_sid
, "initiator_sid=%s"},
1264 {Opt_sa_res_key
, "sa_res_key=%s"},
1265 {Opt_res_holder
, "res_holder=%d"},
1266 {Opt_res_type
, "res_type=%d"},
1267 {Opt_res_scope
, "res_scope=%d"},
1268 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1269 {Opt_mapped_lun
, "mapped_lun=%d"},
1270 {Opt_target_fabric
, "target_fabric=%s"},
1271 {Opt_target_node
, "target_node=%s"},
1272 {Opt_tpgt
, "tpgt=%d"},
1273 {Opt_port_rtpi
, "port_rtpi=%d"},
1274 {Opt_target_lun
, "target_lun=%d"},
1278 static ssize_t
target_core_dev_pr_store_attr_res_aptpl_metadata(
1279 struct se_device
*dev
,
1283 unsigned char *i_fabric
= NULL
, *i_port
= NULL
, *isid
= NULL
;
1284 unsigned char *t_fabric
= NULL
, *t_port
= NULL
;
1285 char *orig
, *ptr
, *opts
;
1286 substring_t args
[MAX_OPT_ARGS
];
1287 unsigned long long tmp_ll
;
1289 u32 mapped_lun
= 0, target_lun
= 0;
1290 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1291 u16 port_rpti
= 0, tpgt
= 0;
1294 if (dev
->transport
->transport_type
== TRANSPORT_PLUGIN_PHBA_PDEV
)
1296 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1299 if (dev
->export_count
) {
1300 pr_debug("Unable to process APTPL metadata while"
1301 " active fabric exports exist\n");
1305 opts
= kstrdup(page
, GFP_KERNEL
);
1310 while ((ptr
= strsep(&opts
, ",\n")) != NULL
) {
1314 token
= match_token(ptr
, tokens
, args
);
1316 case Opt_initiator_fabric
:
1317 i_fabric
= match_strdup(args
);
1323 case Opt_initiator_node
:
1324 i_port
= match_strdup(args
);
1329 if (strlen(i_port
) >= PR_APTPL_MAX_IPORT_LEN
) {
1330 pr_err("APTPL metadata initiator_node="
1331 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1332 PR_APTPL_MAX_IPORT_LEN
);
1337 case Opt_initiator_sid
:
1338 isid
= match_strdup(args
);
1343 if (strlen(isid
) >= PR_REG_ISID_LEN
) {
1344 pr_err("APTPL metadata initiator_isid"
1345 "= exceeds PR_REG_ISID_LEN: %d\n",
1351 case Opt_sa_res_key
:
1352 ret
= kstrtoull(args
->from
, 0, &tmp_ll
);
1354 pr_err("kstrtoull() failed for sa_res_key=\n");
1357 sa_res_key
= (u64
)tmp_ll
;
1360 * PR APTPL Metadata for Reservation
1362 case Opt_res_holder
:
1363 match_int(args
, &arg
);
1367 match_int(args
, &arg
);
1371 match_int(args
, &arg
);
1374 case Opt_res_all_tg_pt
:
1375 match_int(args
, &arg
);
1376 all_tg_pt
= (int)arg
;
1378 case Opt_mapped_lun
:
1379 match_int(args
, &arg
);
1380 mapped_lun
= (u32
)arg
;
1383 * PR APTPL Metadata for Target Port
1385 case Opt_target_fabric
:
1386 t_fabric
= match_strdup(args
);
1392 case Opt_target_node
:
1393 t_port
= match_strdup(args
);
1398 if (strlen(t_port
) >= PR_APTPL_MAX_TPORT_LEN
) {
1399 pr_err("APTPL metadata target_node="
1400 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1401 PR_APTPL_MAX_TPORT_LEN
);
1407 match_int(args
, &arg
);
1411 match_int(args
, &arg
);
1412 port_rpti
= (u16
)arg
;
1414 case Opt_target_lun
:
1415 match_int(args
, &arg
);
1416 target_lun
= (u32
)arg
;
1423 if (!i_port
|| !t_port
|| !sa_res_key
) {
1424 pr_err("Illegal parameters for APTPL registration\n");
1429 if (res_holder
&& !(type
)) {
1430 pr_err("Illegal PR type: 0x%02x for reservation"
1436 ret
= core_scsi3_alloc_aptpl_registration(&dev
->t10_pr
, sa_res_key
,
1437 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1438 res_holder
, all_tg_pt
, type
);
1446 return (ret
== 0) ? count
: ret
;
1449 SE_DEV_PR_ATTR(res_aptpl_metadata
, S_IRUGO
| S_IWUSR
);
1451 CONFIGFS_EATTR_OPS(target_core_dev_pr
, se_device
, dev_pr_group
);
1453 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1454 &target_core_dev_pr_res_holder
.attr
,
1455 &target_core_dev_pr_res_pr_all_tgt_pts
.attr
,
1456 &target_core_dev_pr_res_pr_generation
.attr
,
1457 &target_core_dev_pr_res_pr_holder_tg_port
.attr
,
1458 &target_core_dev_pr_res_pr_registered_i_pts
.attr
,
1459 &target_core_dev_pr_res_pr_type
.attr
,
1460 &target_core_dev_pr_res_type
.attr
,
1461 &target_core_dev_pr_res_aptpl_active
.attr
,
1462 &target_core_dev_pr_res_aptpl_metadata
.attr
,
1466 static struct configfs_item_operations target_core_dev_pr_ops
= {
1467 .show_attribute
= target_core_dev_pr_attr_show
,
1468 .store_attribute
= target_core_dev_pr_attr_store
,
1471 TB_CIT_SETUP(dev_pr
, &target_core_dev_pr_ops
, NULL
, target_core_dev_pr_attrs
);
1473 /* End functions for struct config_item_type tb_dev_pr_cit */
1475 /* Start functions for struct config_item_type tb_dev_cit */
1477 static ssize_t
target_core_show_dev_info(void *p
, char *page
)
1479 struct se_device
*dev
= p
;
1480 struct se_subsystem_api
*t
= dev
->transport
;
1482 ssize_t read_bytes
= 0;
1484 transport_dump_dev_state(dev
, page
, &bl
);
1486 read_bytes
+= t
->show_configfs_dev_params(dev
, page
+read_bytes
);
1490 static struct target_core_configfs_attribute target_core_attr_dev_info
= {
1491 .attr
= { .ca_owner
= THIS_MODULE
,
1493 .ca_mode
= S_IRUGO
},
1494 .show
= target_core_show_dev_info
,
1498 static ssize_t
target_core_store_dev_control(
1503 struct se_device
*dev
= p
;
1504 struct se_subsystem_api
*t
= dev
->transport
;
1506 return t
->set_configfs_dev_params(dev
, page
, count
);
1509 static struct target_core_configfs_attribute target_core_attr_dev_control
= {
1510 .attr
= { .ca_owner
= THIS_MODULE
,
1511 .ca_name
= "control",
1512 .ca_mode
= S_IWUSR
},
1514 .store
= target_core_store_dev_control
,
1517 static ssize_t
target_core_show_dev_alias(void *p
, char *page
)
1519 struct se_device
*dev
= p
;
1521 if (!(dev
->dev_flags
& DF_USING_ALIAS
))
1524 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->dev_alias
);
1527 static ssize_t
target_core_store_dev_alias(
1532 struct se_device
*dev
= p
;
1533 struct se_hba
*hba
= dev
->se_hba
;
1536 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1537 pr_err("alias count: %d exceeds"
1538 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1539 SE_DEV_ALIAS_LEN
-1);
1543 read_bytes
= snprintf(&dev
->dev_alias
[0], SE_DEV_ALIAS_LEN
, "%s", page
);
1546 if (dev
->dev_alias
[read_bytes
- 1] == '\n')
1547 dev
->dev_alias
[read_bytes
- 1] = '\0';
1549 dev
->dev_flags
|= DF_USING_ALIAS
;
1551 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
1552 config_item_name(&hba
->hba_group
.cg_item
),
1553 config_item_name(&dev
->dev_group
.cg_item
),
1559 static struct target_core_configfs_attribute target_core_attr_dev_alias
= {
1560 .attr
= { .ca_owner
= THIS_MODULE
,
1562 .ca_mode
= S_IRUGO
| S_IWUSR
},
1563 .show
= target_core_show_dev_alias
,
1564 .store
= target_core_store_dev_alias
,
1567 static ssize_t
target_core_show_dev_udev_path(void *p
, char *page
)
1569 struct se_device
*dev
= p
;
1571 if (!(dev
->dev_flags
& DF_USING_UDEV_PATH
))
1574 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->udev_path
);
1577 static ssize_t
target_core_store_dev_udev_path(
1582 struct se_device
*dev
= p
;
1583 struct se_hba
*hba
= dev
->se_hba
;
1586 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1587 pr_err("udev_path count: %d exceeds"
1588 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1589 SE_UDEV_PATH_LEN
-1);
1593 read_bytes
= snprintf(&dev
->udev_path
[0], SE_UDEV_PATH_LEN
,
1597 if (dev
->udev_path
[read_bytes
- 1] == '\n')
1598 dev
->udev_path
[read_bytes
- 1] = '\0';
1600 dev
->dev_flags
|= DF_USING_UDEV_PATH
;
1602 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1603 config_item_name(&hba
->hba_group
.cg_item
),
1604 config_item_name(&dev
->dev_group
.cg_item
),
1610 static struct target_core_configfs_attribute target_core_attr_dev_udev_path
= {
1611 .attr
= { .ca_owner
= THIS_MODULE
,
1612 .ca_name
= "udev_path",
1613 .ca_mode
= S_IRUGO
| S_IWUSR
},
1614 .show
= target_core_show_dev_udev_path
,
1615 .store
= target_core_store_dev_udev_path
,
1618 static ssize_t
target_core_show_dev_enable(void *p
, char *page
)
1620 struct se_device
*dev
= p
;
1622 return snprintf(page
, PAGE_SIZE
, "%d\n", !!(dev
->dev_flags
& DF_CONFIGURED
));
1625 static ssize_t
target_core_store_dev_enable(
1630 struct se_device
*dev
= p
;
1634 ptr
= strstr(page
, "1");
1636 pr_err("For dev_enable ops, only valid value"
1641 ret
= target_configure_device(dev
);
1647 static struct target_core_configfs_attribute target_core_attr_dev_enable
= {
1648 .attr
= { .ca_owner
= THIS_MODULE
,
1649 .ca_name
= "enable",
1650 .ca_mode
= S_IRUGO
| S_IWUSR
},
1651 .show
= target_core_show_dev_enable
,
1652 .store
= target_core_store_dev_enable
,
1655 static ssize_t
target_core_show_alua_lu_gp(void *p
, char *page
)
1657 struct se_device
*dev
= p
;
1658 struct config_item
*lu_ci
;
1659 struct t10_alua_lu_gp
*lu_gp
;
1660 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1663 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1667 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1668 lu_gp
= lu_gp_mem
->lu_gp
;
1670 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1671 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1672 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1674 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1679 static ssize_t
target_core_store_alua_lu_gp(
1684 struct se_device
*dev
= p
;
1685 struct se_hba
*hba
= dev
->se_hba
;
1686 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1687 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1688 unsigned char buf
[LU_GROUP_NAME_BUF
];
1691 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1695 if (count
> LU_GROUP_NAME_BUF
) {
1696 pr_err("ALUA LU Group Alias too large!\n");
1699 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1700 memcpy(buf
, page
, count
);
1702 * Any ALUA logical unit alias besides "NULL" means we will be
1703 * making a new group association.
1705 if (strcmp(strstrip(buf
), "NULL")) {
1707 * core_alua_get_lu_gp_by_name() will increment reference to
1708 * struct t10_alua_lu_gp. This reference is released with
1709 * core_alua_get_lu_gp_by_name below().
1711 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
1716 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1717 lu_gp
= lu_gp_mem
->lu_gp
;
1720 * Clearing an existing lu_gp association, and replacing
1724 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
1725 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1727 config_item_name(&hba
->hba_group
.cg_item
),
1728 config_item_name(&dev
->dev_group
.cg_item
),
1729 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1732 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1733 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1738 * Removing existing association of lu_gp_mem with lu_gp
1740 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1744 * Associate lu_gp_mem with lu_gp_new.
1746 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
1747 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1749 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1750 " core/alua/lu_gps/%s, ID: %hu\n",
1751 (move
) ? "Moving" : "Adding",
1752 config_item_name(&hba
->hba_group
.cg_item
),
1753 config_item_name(&dev
->dev_group
.cg_item
),
1754 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
1755 lu_gp_new
->lu_gp_id
);
1757 core_alua_put_lu_gp_from_name(lu_gp_new
);
1761 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp
= {
1762 .attr
= { .ca_owner
= THIS_MODULE
,
1763 .ca_name
= "alua_lu_gp",
1764 .ca_mode
= S_IRUGO
| S_IWUSR
},
1765 .show
= target_core_show_alua_lu_gp
,
1766 .store
= target_core_store_alua_lu_gp
,
1769 static ssize_t
target_core_show_dev_lba_map(void *p
, char *page
)
1771 struct se_device
*dev
= p
;
1772 struct t10_alua_lba_map
*map
;
1773 struct t10_alua_lba_map_member
*mem
;
1778 spin_lock(&dev
->t10_alua
.lba_map_lock
);
1779 if (!list_empty(&dev
->t10_alua
.lba_map_list
))
1780 bl
+= sprintf(b
+ bl
, "%u %u\n",
1781 dev
->t10_alua
.lba_map_segment_size
,
1782 dev
->t10_alua
.lba_map_segment_multiplier
);
1783 list_for_each_entry(map
, &dev
->t10_alua
.lba_map_list
, lba_map_list
) {
1784 bl
+= sprintf(b
+ bl
, "%llu %llu",
1785 map
->lba_map_first_lba
, map
->lba_map_last_lba
);
1786 list_for_each_entry(mem
, &map
->lba_map_mem_list
,
1788 switch (mem
->lba_map_mem_alua_state
) {
1789 case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
:
1792 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
1795 case ALUA_ACCESS_STATE_STANDBY
:
1798 case ALUA_ACCESS_STATE_UNAVAILABLE
:
1805 bl
+= sprintf(b
+ bl
, " %d:%c",
1806 mem
->lba_map_mem_alua_pg_id
, state
);
1808 bl
+= sprintf(b
+ bl
, "\n");
1810 spin_unlock(&dev
->t10_alua
.lba_map_lock
);
1814 static ssize_t
target_core_store_dev_lba_map(
1819 struct se_device
*dev
= p
;
1820 struct t10_alua_lba_map
*lba_map
= NULL
;
1821 struct list_head lba_list
;
1822 char *map_entries
, *ptr
;
1824 int pg_num
= -1, pg
;
1825 int ret
= 0, num
= 0, pg_id
, alua_state
;
1826 unsigned long start_lba
= -1, end_lba
= -1;
1827 unsigned long segment_size
= -1, segment_mult
= -1;
1829 map_entries
= kstrdup(page
, GFP_KERNEL
);
1833 INIT_LIST_HEAD(&lba_list
);
1834 while ((ptr
= strsep(&map_entries
, "\n")) != NULL
) {
1839 if (sscanf(ptr
, "%lu %lu\n",
1840 &segment_size
, &segment_mult
) != 2) {
1841 pr_err("Invalid line %d\n", num
);
1848 if (sscanf(ptr
, "%lu %lu", &start_lba
, &end_lba
) != 2) {
1849 pr_err("Invalid line %d\n", num
);
1853 ptr
= strchr(ptr
, ' ');
1855 pr_err("Invalid line %d, missing end lba\n", num
);
1860 ptr
= strchr(ptr
, ' ');
1862 pr_err("Invalid line %d, missing state definitions\n",
1868 lba_map
= core_alua_allocate_lba_map(&lba_list
,
1869 start_lba
, end_lba
);
1870 if (IS_ERR(lba_map
)) {
1871 ret
= PTR_ERR(lba_map
);
1875 while (sscanf(ptr
, "%d:%c", &pg_id
, &state
) == 2) {
1878 alua_state
= ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
;
1881 alua_state
= ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
;
1884 alua_state
= ALUA_ACCESS_STATE_STANDBY
;
1887 alua_state
= ALUA_ACCESS_STATE_UNAVAILABLE
;
1890 pr_err("Invalid ALUA state '%c'\n", state
);
1895 ret
= core_alua_allocate_lba_map_mem(lba_map
,
1898 pr_err("Invalid target descriptor %d:%c "
1904 ptr
= strchr(ptr
, ' ');
1912 else if (pg
!= pg_num
) {
1913 pr_err("Only %d from %d port groups definitions "
1914 "at line %d\n", pg
, pg_num
, num
);
1922 core_alua_free_lba_map(&lba_list
);
1925 core_alua_set_lba_map(dev
, &lba_list
,
1926 segment_size
, segment_mult
);
1931 static struct target_core_configfs_attribute target_core_attr_dev_lba_map
= {
1932 .attr
= { .ca_owner
= THIS_MODULE
,
1933 .ca_name
= "lba_map",
1934 .ca_mode
= S_IRUGO
| S_IWUSR
},
1935 .show
= target_core_show_dev_lba_map
,
1936 .store
= target_core_store_dev_lba_map
,
1939 static struct configfs_attribute
*target_core_dev_attrs
[] = {
1940 &target_core_attr_dev_info
.attr
,
1941 &target_core_attr_dev_control
.attr
,
1942 &target_core_attr_dev_alias
.attr
,
1943 &target_core_attr_dev_udev_path
.attr
,
1944 &target_core_attr_dev_enable
.attr
,
1945 &target_core_attr_dev_alua_lu_gp
.attr
,
1946 &target_core_attr_dev_lba_map
.attr
,
1950 static void target_core_dev_release(struct config_item
*item
)
1952 struct config_group
*dev_cg
= to_config_group(item
);
1953 struct se_device
*dev
=
1954 container_of(dev_cg
, struct se_device
, dev_group
);
1956 kfree(dev_cg
->default_groups
);
1957 target_free_device(dev
);
1960 static ssize_t
target_core_dev_show(struct config_item
*item
,
1961 struct configfs_attribute
*attr
,
1964 struct config_group
*dev_cg
= to_config_group(item
);
1965 struct se_device
*dev
=
1966 container_of(dev_cg
, struct se_device
, dev_group
);
1967 struct target_core_configfs_attribute
*tc_attr
= container_of(
1968 attr
, struct target_core_configfs_attribute
, attr
);
1973 return tc_attr
->show(dev
, page
);
1976 static ssize_t
target_core_dev_store(struct config_item
*item
,
1977 struct configfs_attribute
*attr
,
1978 const char *page
, size_t count
)
1980 struct config_group
*dev_cg
= to_config_group(item
);
1981 struct se_device
*dev
=
1982 container_of(dev_cg
, struct se_device
, dev_group
);
1983 struct target_core_configfs_attribute
*tc_attr
= container_of(
1984 attr
, struct target_core_configfs_attribute
, attr
);
1986 if (!tc_attr
->store
)
1989 return tc_attr
->store(dev
, page
, count
);
1992 static struct configfs_item_operations target_core_dev_item_ops
= {
1993 .release
= target_core_dev_release
,
1994 .show_attribute
= target_core_dev_show
,
1995 .store_attribute
= target_core_dev_store
,
1998 TB_CIT_SETUP(dev
, &target_core_dev_item_ops
, NULL
, target_core_dev_attrs
);
2000 /* End functions for struct config_item_type tb_dev_cit */
2002 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
2004 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp
, t10_alua_lu_gp
);
2005 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
2006 static struct target_core_alua_lu_gp_attribute \
2007 target_core_alua_lu_gp_##_name = \
2008 __CONFIGFS_EATTR(_name, _mode, \
2009 target_core_alua_lu_gp_show_attr_##_name, \
2010 target_core_alua_lu_gp_store_attr_##_name);
2012 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
2013 static struct target_core_alua_lu_gp_attribute \
2014 target_core_alua_lu_gp_##_name = \
2015 __CONFIGFS_EATTR_RO(_name, \
2016 target_core_alua_lu_gp_show_attr_##_name);
2021 static ssize_t
target_core_alua_lu_gp_show_attr_lu_gp_id(
2022 struct t10_alua_lu_gp
*lu_gp
,
2025 if (!lu_gp
->lu_gp_valid_id
)
2028 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
2031 static ssize_t
target_core_alua_lu_gp_store_attr_lu_gp_id(
2032 struct t10_alua_lu_gp
*lu_gp
,
2036 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2037 unsigned long lu_gp_id
;
2040 ret
= kstrtoul(page
, 0, &lu_gp_id
);
2042 pr_err("kstrtoul() returned %d for"
2043 " lu_gp_id\n", ret
);
2046 if (lu_gp_id
> 0x0000ffff) {
2047 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
2048 " 0x0000ffff\n", lu_gp_id
);
2052 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
2056 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
2057 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2058 config_item_name(&alua_lu_gp_cg
->cg_item
),
2064 SE_DEV_ALUA_LU_ATTR(lu_gp_id
, S_IRUGO
| S_IWUSR
);
2069 static ssize_t
target_core_alua_lu_gp_show_attr_members(
2070 struct t10_alua_lu_gp
*lu_gp
,
2073 struct se_device
*dev
;
2075 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2076 ssize_t len
= 0, cur_len
;
2077 unsigned char buf
[LU_GROUP_NAME_BUF
];
2079 memset(buf
, 0, LU_GROUP_NAME_BUF
);
2081 spin_lock(&lu_gp
->lu_gp_lock
);
2082 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
2083 dev
= lu_gp_mem
->lu_gp_mem_dev
;
2086 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
2087 config_item_name(&hba
->hba_group
.cg_item
),
2088 config_item_name(&dev
->dev_group
.cg_item
));
2089 cur_len
++; /* Extra byte for NULL terminator */
2091 if ((cur_len
+ len
) > PAGE_SIZE
) {
2092 pr_warn("Ran out of lu_gp_show_attr"
2093 "_members buffer\n");
2096 memcpy(page
+len
, buf
, cur_len
);
2099 spin_unlock(&lu_gp
->lu_gp_lock
);
2104 SE_DEV_ALUA_LU_ATTR_RO(members
);
2106 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp
, t10_alua_lu_gp
, lu_gp_group
);
2108 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
2109 &target_core_alua_lu_gp_lu_gp_id
.attr
,
2110 &target_core_alua_lu_gp_members
.attr
,
2114 static void target_core_alua_lu_gp_release(struct config_item
*item
)
2116 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2117 struct t10_alua_lu_gp
, lu_gp_group
);
2119 core_alua_free_lu_gp(lu_gp
);
2122 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
2123 .release
= target_core_alua_lu_gp_release
,
2124 .show_attribute
= target_core_alua_lu_gp_attr_show
,
2125 .store_attribute
= target_core_alua_lu_gp_attr_store
,
2128 static struct config_item_type target_core_alua_lu_gp_cit
= {
2129 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
2130 .ct_attrs
= target_core_alua_lu_gp_attrs
,
2131 .ct_owner
= THIS_MODULE
,
2134 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
2136 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
2138 static struct config_group
*target_core_alua_create_lu_gp(
2139 struct config_group
*group
,
2142 struct t10_alua_lu_gp
*lu_gp
;
2143 struct config_group
*alua_lu_gp_cg
= NULL
;
2144 struct config_item
*alua_lu_gp_ci
= NULL
;
2146 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
2150 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2151 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
2153 config_group_init_type_name(alua_lu_gp_cg
, name
,
2154 &target_core_alua_lu_gp_cit
);
2156 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2157 " Group: core/alua/lu_gps/%s\n",
2158 config_item_name(alua_lu_gp_ci
));
2160 return alua_lu_gp_cg
;
2164 static void target_core_alua_drop_lu_gp(
2165 struct config_group
*group
,
2166 struct config_item
*item
)
2168 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2169 struct t10_alua_lu_gp
, lu_gp_group
);
2171 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2172 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2173 config_item_name(item
), lu_gp
->lu_gp_id
);
2175 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
2176 * -> target_core_alua_lu_gp_release()
2178 config_item_put(item
);
2181 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
2182 .make_group
= &target_core_alua_create_lu_gp
,
2183 .drop_item
= &target_core_alua_drop_lu_gp
,
2186 static struct config_item_type target_core_alua_lu_gps_cit
= {
2187 .ct_item_ops
= NULL
,
2188 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
2189 .ct_owner
= THIS_MODULE
,
2192 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
2194 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2196 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
);
2197 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
2198 static struct target_core_alua_tg_pt_gp_attribute \
2199 target_core_alua_tg_pt_gp_##_name = \
2200 __CONFIGFS_EATTR(_name, _mode, \
2201 target_core_alua_tg_pt_gp_show_attr_##_name, \
2202 target_core_alua_tg_pt_gp_store_attr_##_name);
2204 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2205 static struct target_core_alua_tg_pt_gp_attribute \
2206 target_core_alua_tg_pt_gp_##_name = \
2207 __CONFIGFS_EATTR_RO(_name, \
2208 target_core_alua_tg_pt_gp_show_attr_##_name);
2213 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2214 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2217 return sprintf(page
, "%d\n",
2218 atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
));
2221 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2222 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2226 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
2230 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2231 pr_err("Unable to do implicit ALUA on non valid"
2232 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2235 if (!(dev
->dev_flags
& DF_CONFIGURED
)) {
2236 pr_err("Unable to set alua_access_state while device is"
2237 " not configured\n");
2241 ret
= kstrtoul(page
, 0, &tmp
);
2243 pr_err("Unable to extract new ALUA access state from"
2247 new_state
= (int)tmp
;
2249 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICIT_ALUA
)) {
2250 pr_err("Unable to process implicit configfs ALUA"
2251 " transition while TPGS_IMPLICIT_ALUA is disabled\n");
2254 if (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICIT_ALUA
&&
2255 new_state
== ALUA_ACCESS_STATE_LBA_DEPENDENT
) {
2256 /* LBA DEPENDENT is only allowed with implicit ALUA */
2257 pr_err("Unable to process implicit configfs ALUA transition"
2258 " while explicit ALUA management is enabled\n");
2262 ret
= core_alua_do_port_transition(tg_pt_gp
, dev
,
2263 NULL
, NULL
, new_state
, 0);
2264 return (!ret
) ? count
: -EINVAL
;
2267 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state
, S_IRUGO
| S_IWUSR
);
2270 * alua_access_status
2272 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2273 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2276 return sprintf(page
, "%s\n",
2277 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2280 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2281 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2286 int new_status
, ret
;
2288 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2289 pr_err("Unable to do set ALUA access status on non"
2290 " valid tg_pt_gp ID: %hu\n",
2291 tg_pt_gp
->tg_pt_gp_valid_id
);
2295 ret
= kstrtoul(page
, 0, &tmp
);
2297 pr_err("Unable to extract new ALUA access status"
2298 " from %s\n", page
);
2301 new_status
= (int)tmp
;
2303 if ((new_status
!= ALUA_STATUS_NONE
) &&
2304 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG
) &&
2305 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA
)) {
2306 pr_err("Illegal ALUA access status: 0x%02x\n",
2311 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2315 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status
, S_IRUGO
| S_IWUSR
);
2320 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2321 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2324 return core_alua_show_access_type(tg_pt_gp
, page
);
2327 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2328 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2332 return core_alua_store_access_type(tg_pt_gp
, page
, count
);
2335 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type
, S_IRUGO
| S_IWUSR
);
2338 * alua_supported_states
2341 #define SE_DEV_ALUA_SUPPORT_STATE_SHOW(_name, _var, _bit) \
2342 static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_support_##_name( \
2343 struct t10_alua_tg_pt_gp *t, char *p) \
2345 return sprintf(p, "%d\n", !!(t->_var & _bit)); \
2348 #define SE_DEV_ALUA_SUPPORT_STATE_STORE(_name, _var, _bit) \
2349 static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_support_##_name(\
2350 struct t10_alua_tg_pt_gp *t, const char *p, size_t c) \
2352 unsigned long tmp; \
2355 if (!t->tg_pt_gp_valid_id) { \
2356 pr_err("Unable to do set ##_name ALUA state on non" \
2357 " valid tg_pt_gp ID: %hu\n", \
2358 t->tg_pt_gp_valid_id); \
2362 ret = kstrtoul(p, 0, &tmp); \
2364 pr_err("Invalid value '%s', must be '0' or '1'\n", p); \
2368 pr_err("Invalid value '%ld', must be '0' or '1'\n", tmp); \
2379 SE_DEV_ALUA_SUPPORT_STATE_SHOW(transitioning
,
2380 tg_pt_gp_alua_supported_states
, ALUA_T_SUP
);
2381 SE_DEV_ALUA_SUPPORT_STATE_STORE(transitioning
,
2382 tg_pt_gp_alua_supported_states
, ALUA_T_SUP
);
2383 SE_DEV_ALUA_TG_PT_ATTR(alua_support_transitioning
, S_IRUGO
| S_IWUSR
);
2385 SE_DEV_ALUA_SUPPORT_STATE_SHOW(offline
,
2386 tg_pt_gp_alua_supported_states
, ALUA_O_SUP
);
2387 SE_DEV_ALUA_SUPPORT_STATE_STORE(offline
,
2388 tg_pt_gp_alua_supported_states
, ALUA_O_SUP
);
2389 SE_DEV_ALUA_TG_PT_ATTR(alua_support_offline
, S_IRUGO
| S_IWUSR
);
2391 SE_DEV_ALUA_SUPPORT_STATE_SHOW(lba_dependent
,
2392 tg_pt_gp_alua_supported_states
, ALUA_LBD_SUP
);
2393 SE_DEV_ALUA_SUPPORT_STATE_STORE(lba_dependent
,
2394 tg_pt_gp_alua_supported_states
, ALUA_LBD_SUP
);
2395 SE_DEV_ALUA_TG_PT_ATTR(alua_support_lba_dependent
, S_IRUGO
);
2397 SE_DEV_ALUA_SUPPORT_STATE_SHOW(unavailable
,
2398 tg_pt_gp_alua_supported_states
, ALUA_U_SUP
);
2399 SE_DEV_ALUA_SUPPORT_STATE_STORE(unavailable
,
2400 tg_pt_gp_alua_supported_states
, ALUA_U_SUP
);
2401 SE_DEV_ALUA_TG_PT_ATTR(alua_support_unavailable
, S_IRUGO
| S_IWUSR
);
2403 SE_DEV_ALUA_SUPPORT_STATE_SHOW(standby
,
2404 tg_pt_gp_alua_supported_states
, ALUA_S_SUP
);
2405 SE_DEV_ALUA_SUPPORT_STATE_STORE(standby
,
2406 tg_pt_gp_alua_supported_states
, ALUA_S_SUP
);
2407 SE_DEV_ALUA_TG_PT_ATTR(alua_support_standby
, S_IRUGO
| S_IWUSR
);
2409 SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_optimized
,
2410 tg_pt_gp_alua_supported_states
, ALUA_AO_SUP
);
2411 SE_DEV_ALUA_SUPPORT_STATE_STORE(active_optimized
,
2412 tg_pt_gp_alua_supported_states
, ALUA_AO_SUP
);
2413 SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_optimized
, S_IRUGO
| S_IWUSR
);
2415 SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_nonoptimized
,
2416 tg_pt_gp_alua_supported_states
, ALUA_AN_SUP
);
2417 SE_DEV_ALUA_SUPPORT_STATE_STORE(active_nonoptimized
,
2418 tg_pt_gp_alua_supported_states
, ALUA_AN_SUP
);
2419 SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_nonoptimized
, S_IRUGO
| S_IWUSR
);
2422 * alua_write_metadata
2424 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2425 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2428 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_write_metadata
);
2431 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2432 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2439 ret
= kstrtoul(page
, 0, &tmp
);
2441 pr_err("Unable to extract alua_write_metadata\n");
2445 if ((tmp
!= 0) && (tmp
!= 1)) {
2446 pr_err("Illegal value for alua_write_metadata:"
2450 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2455 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata
, S_IRUGO
| S_IWUSR
);
2462 static ssize_t
target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2463 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2466 return core_alua_show_nonop_delay_msecs(tg_pt_gp
, page
);
2470 static ssize_t
target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2471 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2475 return core_alua_store_nonop_delay_msecs(tg_pt_gp
, page
, count
);
2478 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs
, S_IRUGO
| S_IWUSR
);
2483 static ssize_t
target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2484 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2487 return core_alua_show_trans_delay_msecs(tg_pt_gp
, page
);
2490 static ssize_t
target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2491 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2495 return core_alua_store_trans_delay_msecs(tg_pt_gp
, page
, count
);
2498 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs
, S_IRUGO
| S_IWUSR
);
2501 * implicit_trans_secs
2503 static ssize_t
target_core_alua_tg_pt_gp_show_attr_implicit_trans_secs(
2504 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2507 return core_alua_show_implicit_trans_secs(tg_pt_gp
, page
);
2510 static ssize_t
target_core_alua_tg_pt_gp_store_attr_implicit_trans_secs(
2511 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2515 return core_alua_store_implicit_trans_secs(tg_pt_gp
, page
, count
);
2518 SE_DEV_ALUA_TG_PT_ATTR(implicit_trans_secs
, S_IRUGO
| S_IWUSR
);
2524 static ssize_t
target_core_alua_tg_pt_gp_show_attr_preferred(
2525 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2528 return core_alua_show_preferred_bit(tg_pt_gp
, page
);
2531 static ssize_t
target_core_alua_tg_pt_gp_store_attr_preferred(
2532 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2536 return core_alua_store_preferred_bit(tg_pt_gp
, page
, count
);
2539 SE_DEV_ALUA_TG_PT_ATTR(preferred
, S_IRUGO
| S_IWUSR
);
2544 static ssize_t
target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2545 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2548 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
2551 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2554 static ssize_t
target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2555 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2559 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2560 unsigned long tg_pt_gp_id
;
2563 ret
= kstrtoul(page
, 0, &tg_pt_gp_id
);
2565 pr_err("kstrtoul() returned %d for"
2566 " tg_pt_gp_id\n", ret
);
2569 if (tg_pt_gp_id
> 0x0000ffff) {
2570 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:"
2571 " 0x0000ffff\n", tg_pt_gp_id
);
2575 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2579 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
2580 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2581 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2582 tg_pt_gp
->tg_pt_gp_id
);
2587 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id
, S_IRUGO
| S_IWUSR
);
2592 static ssize_t
target_core_alua_tg_pt_gp_show_attr_members(
2593 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2596 struct se_port
*port
;
2597 struct se_portal_group
*tpg
;
2599 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
2600 ssize_t len
= 0, cur_len
;
2601 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2603 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2605 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2606 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
2607 tg_pt_gp_mem_list
) {
2608 port
= tg_pt_gp_mem
->tg_pt
;
2609 tpg
= port
->sep_tpg
;
2610 lun
= port
->sep_lun
;
2612 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2613 "/%s\n", tpg
->se_tpg_tfo
->get_fabric_name(),
2614 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
2615 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
2616 config_item_name(&lun
->lun_group
.cg_item
));
2617 cur_len
++; /* Extra byte for NULL terminator */
2619 if ((cur_len
+ len
) > PAGE_SIZE
) {
2620 pr_warn("Ran out of lu_gp_show_attr"
2621 "_members buffer\n");
2624 memcpy(page
+len
, buf
, cur_len
);
2627 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2632 SE_DEV_ALUA_TG_PT_ATTR_RO(members
);
2634 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
,
2637 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2638 &target_core_alua_tg_pt_gp_alua_access_state
.attr
,
2639 &target_core_alua_tg_pt_gp_alua_access_status
.attr
,
2640 &target_core_alua_tg_pt_gp_alua_access_type
.attr
,
2641 &target_core_alua_tg_pt_gp_alua_support_transitioning
.attr
,
2642 &target_core_alua_tg_pt_gp_alua_support_offline
.attr
,
2643 &target_core_alua_tg_pt_gp_alua_support_lba_dependent
.attr
,
2644 &target_core_alua_tg_pt_gp_alua_support_unavailable
.attr
,
2645 &target_core_alua_tg_pt_gp_alua_support_standby
.attr
,
2646 &target_core_alua_tg_pt_gp_alua_support_active_nonoptimized
.attr
,
2647 &target_core_alua_tg_pt_gp_alua_support_active_optimized
.attr
,
2648 &target_core_alua_tg_pt_gp_alua_write_metadata
.attr
,
2649 &target_core_alua_tg_pt_gp_nonop_delay_msecs
.attr
,
2650 &target_core_alua_tg_pt_gp_trans_delay_msecs
.attr
,
2651 &target_core_alua_tg_pt_gp_implicit_trans_secs
.attr
,
2652 &target_core_alua_tg_pt_gp_preferred
.attr
,
2653 &target_core_alua_tg_pt_gp_tg_pt_gp_id
.attr
,
2654 &target_core_alua_tg_pt_gp_members
.attr
,
2658 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2660 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2661 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2663 core_alua_free_tg_pt_gp(tg_pt_gp
);
2666 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2667 .release
= target_core_alua_tg_pt_gp_release
,
2668 .show_attribute
= target_core_alua_tg_pt_gp_attr_show
,
2669 .store_attribute
= target_core_alua_tg_pt_gp_attr_store
,
2672 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2673 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2674 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2675 .ct_owner
= THIS_MODULE
,
2678 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2680 /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2682 static struct config_group
*target_core_alua_create_tg_pt_gp(
2683 struct config_group
*group
,
2686 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2687 alua_tg_pt_gps_group
);
2688 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2689 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2690 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2692 tg_pt_gp
= core_alua_allocate_tg_pt_gp(alua
->t10_dev
, name
, 0);
2696 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2697 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2699 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2700 &target_core_alua_tg_pt_gp_cit
);
2702 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
2703 " Group: alua/tg_pt_gps/%s\n",
2704 config_item_name(alua_tg_pt_gp_ci
));
2706 return alua_tg_pt_gp_cg
;
2709 static void target_core_alua_drop_tg_pt_gp(
2710 struct config_group
*group
,
2711 struct config_item
*item
)
2713 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2714 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2716 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
2717 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2718 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2720 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2721 * -> target_core_alua_tg_pt_gp_release().
2723 config_item_put(item
);
2726 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2727 .make_group
= &target_core_alua_create_tg_pt_gp
,
2728 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2731 static struct config_item_type target_core_alua_tg_pt_gps_cit
= {
2732 .ct_group_ops
= &target_core_alua_tg_pt_gps_group_ops
,
2733 .ct_owner
= THIS_MODULE
,
2736 /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2738 /* Start functions for struct config_item_type target_core_alua_cit */
2741 * target_core_alua_cit is a ConfigFS group that lives under
2742 * /sys/kernel/config/target/core/alua. There are default groups
2743 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2744 * target_core_alua_cit in target_core_init_configfs() below.
2746 static struct config_item_type target_core_alua_cit
= {
2747 .ct_item_ops
= NULL
,
2749 .ct_owner
= THIS_MODULE
,
2752 /* End functions for struct config_item_type target_core_alua_cit */
2754 /* Start functions for struct config_item_type target_core_stat_cit */
2756 static struct config_group
*target_core_stat_mkdir(
2757 struct config_group
*group
,
2760 return ERR_PTR(-ENOSYS
);
2763 static void target_core_stat_rmdir(
2764 struct config_group
*group
,
2765 struct config_item
*item
)
2770 static struct configfs_group_operations target_core_stat_group_ops
= {
2771 .make_group
= &target_core_stat_mkdir
,
2772 .drop_item
= &target_core_stat_rmdir
,
2775 static struct config_item_type target_core_stat_cit
= {
2776 .ct_group_ops
= &target_core_stat_group_ops
,
2777 .ct_owner
= THIS_MODULE
,
2780 /* End functions for struct config_item_type target_core_stat_cit */
2782 /* Start functions for struct config_item_type target_core_hba_cit */
2784 static struct config_group
*target_core_make_subdev(
2785 struct config_group
*group
,
2788 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2789 struct se_subsystem_api
*t
;
2790 struct config_item
*hba_ci
= &group
->cg_item
;
2791 struct se_hba
*hba
= item_to_hba(hba_ci
);
2792 struct se_device
*dev
;
2793 struct config_group
*dev_cg
= NULL
, *tg_pt_gp_cg
= NULL
;
2794 struct config_group
*dev_stat_grp
= NULL
;
2795 int errno
= -ENOMEM
, ret
;
2797 ret
= mutex_lock_interruptible(&hba
->hba_access_mutex
);
2799 return ERR_PTR(ret
);
2801 * Locate the struct se_subsystem_api from parent's struct se_hba.
2805 dev
= target_alloc_device(hba
, name
);
2809 dev_cg
= &dev
->dev_group
;
2811 dev_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 6,
2813 if (!dev_cg
->default_groups
)
2814 goto out_free_device
;
2816 config_group_init_type_name(dev_cg
, name
, &t
->tb_cits
.tb_dev_cit
);
2817 config_group_init_type_name(&dev
->dev_attrib
.da_group
, "attrib",
2818 &t
->tb_cits
.tb_dev_attrib_cit
);
2819 config_group_init_type_name(&dev
->dev_pr_group
, "pr",
2820 &t
->tb_cits
.tb_dev_pr_cit
);
2821 config_group_init_type_name(&dev
->t10_wwn
.t10_wwn_group
, "wwn",
2822 &t
->tb_cits
.tb_dev_wwn_cit
);
2823 config_group_init_type_name(&dev
->t10_alua
.alua_tg_pt_gps_group
,
2824 "alua", &target_core_alua_tg_pt_gps_cit
);
2825 config_group_init_type_name(&dev
->dev_stat_grps
.stat_group
,
2826 "statistics", &target_core_stat_cit
);
2828 dev_cg
->default_groups
[0] = &dev
->dev_attrib
.da_group
;
2829 dev_cg
->default_groups
[1] = &dev
->dev_pr_group
;
2830 dev_cg
->default_groups
[2] = &dev
->t10_wwn
.t10_wwn_group
;
2831 dev_cg
->default_groups
[3] = &dev
->t10_alua
.alua_tg_pt_gps_group
;
2832 dev_cg
->default_groups
[4] = &dev
->dev_stat_grps
.stat_group
;
2833 dev_cg
->default_groups
[5] = NULL
;
2835 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
2837 tg_pt_gp
= core_alua_allocate_tg_pt_gp(dev
, "default_tg_pt_gp", 1);
2839 goto out_free_dev_cg_default_groups
;
2840 dev
->t10_alua
.default_tg_pt_gp
= tg_pt_gp
;
2842 tg_pt_gp_cg
= &dev
->t10_alua
.alua_tg_pt_gps_group
;
2843 tg_pt_gp_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
2845 if (!tg_pt_gp_cg
->default_groups
) {
2846 pr_err("Unable to allocate tg_pt_gp_cg->"
2847 "default_groups\n");
2848 goto out_free_tg_pt_gp
;
2851 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2852 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2853 tg_pt_gp_cg
->default_groups
[0] = &tg_pt_gp
->tg_pt_gp_group
;
2854 tg_pt_gp_cg
->default_groups
[1] = NULL
;
2856 * Add core/$HBA/$DEV/statistics/ default groups
2858 dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
2859 dev_stat_grp
->default_groups
= kmalloc(sizeof(struct config_group
*) * 4,
2861 if (!dev_stat_grp
->default_groups
) {
2862 pr_err("Unable to allocate dev_stat_grp->default_groups\n");
2863 goto out_free_tg_pt_gp_cg_default_groups
;
2865 target_stat_setup_dev_default_groups(dev
);
2867 mutex_unlock(&hba
->hba_access_mutex
);
2870 out_free_tg_pt_gp_cg_default_groups
:
2871 kfree(tg_pt_gp_cg
->default_groups
);
2873 core_alua_free_tg_pt_gp(tg_pt_gp
);
2874 out_free_dev_cg_default_groups
:
2875 kfree(dev_cg
->default_groups
);
2877 target_free_device(dev
);
2879 mutex_unlock(&hba
->hba_access_mutex
);
2880 return ERR_PTR(errno
);
2883 static void target_core_drop_subdev(
2884 struct config_group
*group
,
2885 struct config_item
*item
)
2887 struct config_group
*dev_cg
= to_config_group(item
);
2888 struct se_device
*dev
=
2889 container_of(dev_cg
, struct se_device
, dev_group
);
2891 struct config_item
*df_item
;
2892 struct config_group
*tg_pt_gp_cg
, *dev_stat_grp
;
2895 hba
= item_to_hba(&dev
->se_hba
->hba_group
.cg_item
);
2897 mutex_lock(&hba
->hba_access_mutex
);
2899 dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
2900 for (i
= 0; dev_stat_grp
->default_groups
[i
]; i
++) {
2901 df_item
= &dev_stat_grp
->default_groups
[i
]->cg_item
;
2902 dev_stat_grp
->default_groups
[i
] = NULL
;
2903 config_item_put(df_item
);
2905 kfree(dev_stat_grp
->default_groups
);
2907 tg_pt_gp_cg
= &dev
->t10_alua
.alua_tg_pt_gps_group
;
2908 for (i
= 0; tg_pt_gp_cg
->default_groups
[i
]; i
++) {
2909 df_item
= &tg_pt_gp_cg
->default_groups
[i
]->cg_item
;
2910 tg_pt_gp_cg
->default_groups
[i
] = NULL
;
2911 config_item_put(df_item
);
2913 kfree(tg_pt_gp_cg
->default_groups
);
2915 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2916 * directly from target_core_alua_tg_pt_gp_release().
2918 dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2920 for (i
= 0; dev_cg
->default_groups
[i
]; i
++) {
2921 df_item
= &dev_cg
->default_groups
[i
]->cg_item
;
2922 dev_cg
->default_groups
[i
] = NULL
;
2923 config_item_put(df_item
);
2926 * se_dev is released from target_core_dev_item_ops->release()
2928 config_item_put(item
);
2929 mutex_unlock(&hba
->hba_access_mutex
);
2932 static struct configfs_group_operations target_core_hba_group_ops
= {
2933 .make_group
= target_core_make_subdev
,
2934 .drop_item
= target_core_drop_subdev
,
2937 CONFIGFS_EATTR_STRUCT(target_core_hba
, se_hba
);
2938 #define SE_HBA_ATTR(_name, _mode) \
2939 static struct target_core_hba_attribute \
2940 target_core_hba_##_name = \
2941 __CONFIGFS_EATTR(_name, _mode, \
2942 target_core_hba_show_attr_##_name, \
2943 target_core_hba_store_attr_##_name);
2945 #define SE_HBA_ATTR_RO(_name) \
2946 static struct target_core_hba_attribute \
2947 target_core_hba_##_name = \
2948 __CONFIGFS_EATTR_RO(_name, \
2949 target_core_hba_show_attr_##_name);
2951 static ssize_t
target_core_hba_show_attr_hba_info(
2955 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
2956 hba
->hba_id
, hba
->transport
->name
,
2957 TARGET_CORE_CONFIGFS_VERSION
);
2960 SE_HBA_ATTR_RO(hba_info
);
2962 static ssize_t
target_core_hba_show_attr_hba_mode(struct se_hba
*hba
,
2967 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
2970 return sprintf(page
, "%d\n", hba_mode
);
2973 static ssize_t
target_core_hba_store_attr_hba_mode(struct se_hba
*hba
,
2974 const char *page
, size_t count
)
2976 struct se_subsystem_api
*transport
= hba
->transport
;
2977 unsigned long mode_flag
;
2980 if (transport
->pmode_enable_hba
== NULL
)
2983 ret
= kstrtoul(page
, 0, &mode_flag
);
2985 pr_err("Unable to extract hba mode flag: %d\n", ret
);
2989 if (hba
->dev_count
) {
2990 pr_err("Unable to set hba_mode with active devices\n");
2994 ret
= transport
->pmode_enable_hba(hba
, mode_flag
);
2998 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
3000 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
3005 SE_HBA_ATTR(hba_mode
, S_IRUGO
| S_IWUSR
);
3007 CONFIGFS_EATTR_OPS(target_core_hba
, se_hba
, hba_group
);
3009 static void target_core_hba_release(struct config_item
*item
)
3011 struct se_hba
*hba
= container_of(to_config_group(item
),
3012 struct se_hba
, hba_group
);
3013 core_delete_hba(hba
);
3016 static struct configfs_attribute
*target_core_hba_attrs
[] = {
3017 &target_core_hba_hba_info
.attr
,
3018 &target_core_hba_hba_mode
.attr
,
3022 static struct configfs_item_operations target_core_hba_item_ops
= {
3023 .release
= target_core_hba_release
,
3024 .show_attribute
= target_core_hba_attr_show
,
3025 .store_attribute
= target_core_hba_attr_store
,
3028 static struct config_item_type target_core_hba_cit
= {
3029 .ct_item_ops
= &target_core_hba_item_ops
,
3030 .ct_group_ops
= &target_core_hba_group_ops
,
3031 .ct_attrs
= target_core_hba_attrs
,
3032 .ct_owner
= THIS_MODULE
,
3035 static struct config_group
*target_core_call_addhbatotarget(
3036 struct config_group
*group
,
3039 char *se_plugin_str
, *str
, *str2
;
3041 char buf
[TARGET_CORE_NAME_MAX_LEN
];
3042 unsigned long plugin_dep_id
= 0;
3045 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
3046 if (strlen(name
) >= TARGET_CORE_NAME_MAX_LEN
) {
3047 pr_err("Passed *name strlen(): %d exceeds"
3048 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
3049 TARGET_CORE_NAME_MAX_LEN
);
3050 return ERR_PTR(-ENAMETOOLONG
);
3052 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
3054 str
= strstr(buf
, "_");
3056 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
3057 return ERR_PTR(-EINVAL
);
3059 se_plugin_str
= buf
;
3061 * Special case for subsystem plugins that have "_" in their names.
3062 * Namely rd_direct and rd_mcp..
3064 str2
= strstr(str
+1, "_");
3066 *str2
= '\0'; /* Terminate for *se_plugin_str */
3067 str2
++; /* Skip to start of plugin dependent ID */
3070 *str
= '\0'; /* Terminate for *se_plugin_str */
3071 str
++; /* Skip to start of plugin dependent ID */
3074 ret
= kstrtoul(str
, 0, &plugin_dep_id
);
3076 pr_err("kstrtoul() returned %d for"
3077 " plugin_dep_id\n", ret
);
3078 return ERR_PTR(ret
);
3081 * Load up TCM subsystem plugins if they have not already been loaded.
3083 transport_subsystem_check_init();
3085 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
3087 return ERR_CAST(hba
);
3089 config_group_init_type_name(&hba
->hba_group
, name
,
3090 &target_core_hba_cit
);
3092 return &hba
->hba_group
;
3095 static void target_core_call_delhbafromtarget(
3096 struct config_group
*group
,
3097 struct config_item
*item
)
3100 * core_delete_hba() is called from target_core_hba_item_ops->release()
3101 * -> target_core_hba_release()
3103 config_item_put(item
);
3106 static struct configfs_group_operations target_core_group_ops
= {
3107 .make_group
= target_core_call_addhbatotarget
,
3108 .drop_item
= target_core_call_delhbafromtarget
,
3111 static struct config_item_type target_core_cit
= {
3112 .ct_item_ops
= NULL
,
3113 .ct_group_ops
= &target_core_group_ops
,
3115 .ct_owner
= THIS_MODULE
,
3118 /* Stop functions for struct config_item_type target_core_hba_cit */
3120 void target_core_setup_sub_cits(struct se_subsystem_api
*sa
)
3122 target_core_setup_dev_cit(sa
);
3123 target_core_setup_dev_attrib_cit(sa
);
3124 target_core_setup_dev_pr_cit(sa
);
3125 target_core_setup_dev_wwn_cit(sa
);
3127 EXPORT_SYMBOL(target_core_setup_sub_cits
);
3129 static int __init
target_core_init_configfs(void)
3131 struct config_group
*target_cg
, *hba_cg
= NULL
, *alua_cg
= NULL
;
3132 struct config_group
*lu_gp_cg
= NULL
;
3133 struct configfs_subsystem
*subsys
;
3134 struct t10_alua_lu_gp
*lu_gp
;
3137 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
3138 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
3139 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
3141 subsys
= target_core_subsystem
[0];
3142 config_group_init(&subsys
->su_group
);
3143 mutex_init(&subsys
->su_mutex
);
3145 ret
= init_se_kmem_caches();
3149 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
3150 * and ALUA Logical Unit Group and Target Port Group infrastructure.
3152 target_cg
= &subsys
->su_group
;
3153 target_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3155 if (!target_cg
->default_groups
) {
3156 pr_err("Unable to allocate target_cg->default_groups\n");
3161 config_group_init_type_name(&target_core_hbagroup
,
3162 "core", &target_core_cit
);
3163 target_cg
->default_groups
[0] = &target_core_hbagroup
;
3164 target_cg
->default_groups
[1] = NULL
;
3166 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
3168 hba_cg
= &target_core_hbagroup
;
3169 hba_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3171 if (!hba_cg
->default_groups
) {
3172 pr_err("Unable to allocate hba_cg->default_groups\n");
3176 config_group_init_type_name(&alua_group
,
3177 "alua", &target_core_alua_cit
);
3178 hba_cg
->default_groups
[0] = &alua_group
;
3179 hba_cg
->default_groups
[1] = NULL
;
3181 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
3182 * groups under /sys/kernel/config/target/core/alua/
3184 alua_cg
= &alua_group
;
3185 alua_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3187 if (!alua_cg
->default_groups
) {
3188 pr_err("Unable to allocate alua_cg->default_groups\n");
3193 config_group_init_type_name(&alua_lu_gps_group
,
3194 "lu_gps", &target_core_alua_lu_gps_cit
);
3195 alua_cg
->default_groups
[0] = &alua_lu_gps_group
;
3196 alua_cg
->default_groups
[1] = NULL
;
3198 * Add core/alua/lu_gps/default_lu_gp
3200 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
3201 if (IS_ERR(lu_gp
)) {
3206 lu_gp_cg
= &alua_lu_gps_group
;
3207 lu_gp_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3209 if (!lu_gp_cg
->default_groups
) {
3210 pr_err("Unable to allocate lu_gp_cg->default_groups\n");
3215 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
3216 &target_core_alua_lu_gp_cit
);
3217 lu_gp_cg
->default_groups
[0] = &lu_gp
->lu_gp_group
;
3218 lu_gp_cg
->default_groups
[1] = NULL
;
3219 default_lu_gp
= lu_gp
;
3221 * Register the target_core_mod subsystem with configfs.
3223 ret
= configfs_register_subsystem(subsys
);
3225 pr_err("Error %d while registering subsystem %s\n",
3226 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
3229 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
3230 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION
" on %s/%s"
3231 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
3233 * Register built-in RAMDISK subsystem logic for virtual LUN 0
3235 ret
= rd_module_init();
3239 ret
= core_dev_setup_virtual_lun0();
3243 ret
= target_xcopy_setup_pt();
3250 configfs_unregister_subsystem(subsys
);
3251 core_dev_release_virtual_lun0();
3254 if (default_lu_gp
) {
3255 core_alua_free_lu_gp(default_lu_gp
);
3256 default_lu_gp
= NULL
;
3259 kfree(lu_gp_cg
->default_groups
);
3261 kfree(alua_cg
->default_groups
);
3263 kfree(hba_cg
->default_groups
);
3264 kfree(target_cg
->default_groups
);
3265 release_se_kmem_caches();
3269 static void __exit
target_core_exit_configfs(void)
3271 struct configfs_subsystem
*subsys
;
3272 struct config_group
*hba_cg
, *alua_cg
, *lu_gp_cg
;
3273 struct config_item
*item
;
3276 subsys
= target_core_subsystem
[0];
3278 lu_gp_cg
= &alua_lu_gps_group
;
3279 for (i
= 0; lu_gp_cg
->default_groups
[i
]; i
++) {
3280 item
= &lu_gp_cg
->default_groups
[i
]->cg_item
;
3281 lu_gp_cg
->default_groups
[i
] = NULL
;
3282 config_item_put(item
);
3284 kfree(lu_gp_cg
->default_groups
);
3285 lu_gp_cg
->default_groups
= NULL
;
3287 alua_cg
= &alua_group
;
3288 for (i
= 0; alua_cg
->default_groups
[i
]; i
++) {
3289 item
= &alua_cg
->default_groups
[i
]->cg_item
;
3290 alua_cg
->default_groups
[i
] = NULL
;
3291 config_item_put(item
);
3293 kfree(alua_cg
->default_groups
);
3294 alua_cg
->default_groups
= NULL
;
3296 hba_cg
= &target_core_hbagroup
;
3297 for (i
= 0; hba_cg
->default_groups
[i
]; i
++) {
3298 item
= &hba_cg
->default_groups
[i
]->cg_item
;
3299 hba_cg
->default_groups
[i
] = NULL
;
3300 config_item_put(item
);
3302 kfree(hba_cg
->default_groups
);
3303 hba_cg
->default_groups
= NULL
;
3305 * We expect subsys->su_group.default_groups to be released
3306 * by configfs subsystem provider logic..
3308 configfs_unregister_subsystem(subsys
);
3309 kfree(subsys
->su_group
.default_groups
);
3311 core_alua_free_lu_gp(default_lu_gp
);
3312 default_lu_gp
= NULL
;
3314 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
3315 " Infrastructure\n");
3317 core_dev_release_virtual_lun0();
3319 target_xcopy_release_pt();
3320 release_se_kmem_caches();
3323 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3324 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3325 MODULE_LICENSE("GPL");
3327 module_init(target_core_init_configfs
);
3328 module_exit(target_core_exit_configfs
);