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>
44 #include "target_core_internal.h"
45 #include "target_core_alua.h"
46 #include "target_core_pr.h"
47 #include "target_core_rd.h"
48 #include "target_core_xcopy.h"
50 #define TB_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \
51 static void target_core_setup_##_name##_cit(struct target_backend *tb) \
53 struct config_item_type *cit = &tb->tb_##_name##_cit; \
55 cit->ct_item_ops = _item_ops; \
56 cit->ct_group_ops = _group_ops; \
57 cit->ct_attrs = _attrs; \
58 cit->ct_owner = tb->ops->owner; \
59 pr_debug("Setup generic %s\n", __stringify(_name)); \
62 #define TB_CIT_SETUP_DRV(_name, _item_ops, _group_ops) \
63 static void target_core_setup_##_name##_cit(struct target_backend *tb) \
65 struct config_item_type *cit = &tb->tb_##_name##_cit; \
67 cit->ct_item_ops = _item_ops; \
68 cit->ct_group_ops = _group_ops; \
69 cit->ct_attrs = tb->ops->tb_##_name##_attrs; \
70 cit->ct_owner = tb->ops->owner; \
71 pr_debug("Setup generic %s\n", __stringify(_name)); \
74 extern struct t10_alua_lu_gp
*default_lu_gp
;
76 static LIST_HEAD(g_tf_list
);
77 static DEFINE_MUTEX(g_tf_lock
);
79 static struct config_group target_core_hbagroup
;
80 static struct config_group alua_group
;
81 static struct config_group alua_lu_gps_group
;
83 static inline struct se_hba
*
84 item_to_hba(struct config_item
*item
)
86 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
90 * Attributes for /sys/kernel/config/target/
92 static ssize_t
target_core_item_version_show(struct config_item
*item
,
95 return sprintf(page
, "Target Engine Core ConfigFS Infrastructure %s"
96 " on %s/%s on "UTS_RELEASE
"\n", TARGET_CORE_VERSION
,
97 utsname()->sysname
, utsname()->machine
);
100 CONFIGFS_ATTR_RO(target_core_item_
, version
);
102 char db_root
[DB_ROOT_LEN
] = DB_ROOT_DEFAULT
;
103 static char db_root_stage
[DB_ROOT_LEN
];
105 static ssize_t
target_core_item_dbroot_show(struct config_item
*item
,
108 return sprintf(page
, "%s\n", db_root
);
111 static ssize_t
target_core_item_dbroot_store(struct config_item
*item
,
112 const char *page
, size_t count
)
117 mutex_lock(&g_tf_lock
);
118 if (!list_empty(&g_tf_list
)) {
119 mutex_unlock(&g_tf_lock
);
120 pr_err("db_root: cannot be changed: target drivers registered");
124 if (count
> (DB_ROOT_LEN
- 1)) {
125 mutex_unlock(&g_tf_lock
);
126 pr_err("db_root: count %d exceeds DB_ROOT_LEN-1: %u\n",
127 (int)count
, DB_ROOT_LEN
- 1);
131 read_bytes
= snprintf(db_root_stage
, DB_ROOT_LEN
, "%s", page
);
133 mutex_unlock(&g_tf_lock
);
136 if (db_root_stage
[read_bytes
- 1] == '\n')
137 db_root_stage
[read_bytes
- 1] = '\0';
139 /* validate new db root before accepting it */
140 fp
= filp_open(db_root_stage
, O_RDONLY
, 0);
142 mutex_unlock(&g_tf_lock
);
143 pr_err("db_root: cannot open: %s\n", db_root_stage
);
146 if (!S_ISDIR(file_inode(fp
)->i_mode
)) {
147 filp_close(fp
, NULL
);
148 mutex_unlock(&g_tf_lock
);
149 pr_err("db_root: not a directory: %s\n", db_root_stage
);
152 filp_close(fp
, NULL
);
154 strncpy(db_root
, db_root_stage
, read_bytes
);
156 mutex_unlock(&g_tf_lock
);
161 CONFIGFS_ATTR(target_core_item_
, dbroot
);
163 static struct target_fabric_configfs
*target_core_get_fabric(
166 struct target_fabric_configfs
*tf
;
171 mutex_lock(&g_tf_lock
);
172 list_for_each_entry(tf
, &g_tf_list
, tf_list
) {
173 if (!strcmp(tf
->tf_ops
->name
, name
)) {
174 atomic_inc(&tf
->tf_access_cnt
);
175 mutex_unlock(&g_tf_lock
);
179 mutex_unlock(&g_tf_lock
);
185 * Called from struct target_core_group_ops->make_group()
187 static struct config_group
*target_core_register_fabric(
188 struct config_group
*group
,
191 struct target_fabric_configfs
*tf
;
194 pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:"
195 " %s\n", group
, name
);
197 tf
= target_core_get_fabric(name
);
199 pr_debug("target_core_register_fabric() trying autoload for %s\n",
203 * Below are some hardcoded request_module() calls to automatically
204 * local fabric modules when the following is called:
206 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
208 * Note that this does not limit which TCM fabric module can be
209 * registered, but simply provids auto loading logic for modules with
210 * mkdir(2) system calls with known TCM fabric modules.
213 if (!strncmp(name
, "iscsi", 5)) {
215 * Automatically load the LIO Target fabric module when the
216 * following is called:
218 * mkdir -p $CONFIGFS/target/iscsi
220 ret
= request_module("iscsi_target_mod");
222 pr_debug("request_module() failed for"
223 " iscsi_target_mod.ko: %d\n", ret
);
224 return ERR_PTR(-EINVAL
);
226 } else if (!strncmp(name
, "loopback", 8)) {
228 * Automatically load the tcm_loop fabric module when the
229 * following is called:
231 * mkdir -p $CONFIGFS/target/loopback
233 ret
= request_module("tcm_loop");
235 pr_debug("request_module() failed for"
236 " tcm_loop.ko: %d\n", ret
);
237 return ERR_PTR(-EINVAL
);
241 tf
= target_core_get_fabric(name
);
245 pr_debug("target_core_get_fabric() failed for %s\n",
247 return ERR_PTR(-EINVAL
);
249 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
250 " %s\n", tf
->tf_ops
->name
);
252 * On a successful target_core_get_fabric() look, the returned
253 * struct target_fabric_configfs *tf will contain a usage reference.
255 pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
258 config_group_init_type_name(&tf
->tf_group
, name
, &tf
->tf_wwn_cit
);
260 config_group_init_type_name(&tf
->tf_disc_group
, "discovery_auth",
261 &tf
->tf_discovery_cit
);
262 configfs_add_default_group(&tf
->tf_disc_group
, &tf
->tf_group
);
264 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
265 " %s\n", tf
->tf_group
.cg_item
.ci_name
);
266 return &tf
->tf_group
;
270 * Called from struct target_core_group_ops->drop_item()
272 static void target_core_deregister_fabric(
273 struct config_group
*group
,
274 struct config_item
*item
)
276 struct target_fabric_configfs
*tf
= container_of(
277 to_config_group(item
), struct target_fabric_configfs
, tf_group
);
279 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
280 " tf list\n", config_item_name(item
));
282 pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:"
283 " %s\n", tf
->tf_ops
->name
);
284 atomic_dec(&tf
->tf_access_cnt
);
286 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
287 " %s\n", config_item_name(item
));
289 configfs_remove_default_groups(&tf
->tf_group
);
290 config_item_put(item
);
293 static struct configfs_group_operations target_core_fabric_group_ops
= {
294 .make_group
= &target_core_register_fabric
,
295 .drop_item
= &target_core_deregister_fabric
,
299 * All item attributes appearing in /sys/kernel/target/ appear here.
301 static struct configfs_attribute
*target_core_fabric_item_attrs
[] = {
302 &target_core_item_attr_version
,
303 &target_core_item_attr_dbroot
,
308 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
310 static const struct config_item_type target_core_fabrics_item
= {
311 .ct_group_ops
= &target_core_fabric_group_ops
,
312 .ct_attrs
= target_core_fabric_item_attrs
,
313 .ct_owner
= THIS_MODULE
,
316 static struct configfs_subsystem target_core_fabrics
= {
319 .ci_namebuf
= "target",
320 .ci_type
= &target_core_fabrics_item
,
325 int target_depend_item(struct config_item
*item
)
327 return configfs_depend_item(&target_core_fabrics
, item
);
329 EXPORT_SYMBOL(target_depend_item
);
331 void target_undepend_item(struct config_item
*item
)
333 return configfs_undepend_item(item
);
335 EXPORT_SYMBOL(target_undepend_item
);
337 /*##############################################################################
338 // Start functions called by external Target Fabrics Modules
339 //############################################################################*/
341 static int target_fabric_tf_ops_check(const struct target_core_fabric_ops
*tfo
)
344 pr_err("Missing tfo->name\n");
347 if (strlen(tfo
->name
) >= TARGET_FABRIC_NAME_SIZE
) {
348 pr_err("Passed name: %s exceeds TARGET_FABRIC"
349 "_NAME_SIZE\n", tfo
->name
);
352 if (!tfo
->get_fabric_name
) {
353 pr_err("Missing tfo->get_fabric_name()\n");
356 if (!tfo
->tpg_get_wwn
) {
357 pr_err("Missing tfo->tpg_get_wwn()\n");
360 if (!tfo
->tpg_get_tag
) {
361 pr_err("Missing tfo->tpg_get_tag()\n");
364 if (!tfo
->tpg_check_demo_mode
) {
365 pr_err("Missing tfo->tpg_check_demo_mode()\n");
368 if (!tfo
->tpg_check_demo_mode_cache
) {
369 pr_err("Missing tfo->tpg_check_demo_mode_cache()\n");
372 if (!tfo
->tpg_check_demo_mode_write_protect
) {
373 pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n");
376 if (!tfo
->tpg_check_prod_mode_write_protect
) {
377 pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n");
380 if (!tfo
->tpg_get_inst_index
) {
381 pr_err("Missing tfo->tpg_get_inst_index()\n");
384 if (!tfo
->release_cmd
) {
385 pr_err("Missing tfo->release_cmd()\n");
388 if (!tfo
->sess_get_index
) {
389 pr_err("Missing tfo->sess_get_index()\n");
392 if (!tfo
->write_pending
) {
393 pr_err("Missing tfo->write_pending()\n");
396 if (!tfo
->write_pending_status
) {
397 pr_err("Missing tfo->write_pending_status()\n");
400 if (!tfo
->set_default_node_attributes
) {
401 pr_err("Missing tfo->set_default_node_attributes()\n");
404 if (!tfo
->get_cmd_state
) {
405 pr_err("Missing tfo->get_cmd_state()\n");
408 if (!tfo
->queue_data_in
) {
409 pr_err("Missing tfo->queue_data_in()\n");
412 if (!tfo
->queue_status
) {
413 pr_err("Missing tfo->queue_status()\n");
416 if (!tfo
->queue_tm_rsp
) {
417 pr_err("Missing tfo->queue_tm_rsp()\n");
420 if (!tfo
->aborted_task
) {
421 pr_err("Missing tfo->aborted_task()\n");
424 if (!tfo
->check_stop_free
) {
425 pr_err("Missing tfo->check_stop_free()\n");
429 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
430 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
431 * target_core_fabric_configfs.c WWN+TPG group context code.
433 if (!tfo
->fabric_make_wwn
) {
434 pr_err("Missing tfo->fabric_make_wwn()\n");
437 if (!tfo
->fabric_drop_wwn
) {
438 pr_err("Missing tfo->fabric_drop_wwn()\n");
441 if (!tfo
->fabric_make_tpg
) {
442 pr_err("Missing tfo->fabric_make_tpg()\n");
445 if (!tfo
->fabric_drop_tpg
) {
446 pr_err("Missing tfo->fabric_drop_tpg()\n");
453 int target_register_template(const struct target_core_fabric_ops
*fo
)
455 struct target_fabric_configfs
*tf
;
458 ret
= target_fabric_tf_ops_check(fo
);
462 tf
= kzalloc(sizeof(struct target_fabric_configfs
), GFP_KERNEL
);
464 pr_err("%s: could not allocate memory!\n", __func__
);
468 INIT_LIST_HEAD(&tf
->tf_list
);
469 atomic_set(&tf
->tf_access_cnt
, 0);
471 target_fabric_setup_cits(tf
);
473 mutex_lock(&g_tf_lock
);
474 list_add_tail(&tf
->tf_list
, &g_tf_list
);
475 mutex_unlock(&g_tf_lock
);
479 EXPORT_SYMBOL(target_register_template
);
481 void target_unregister_template(const struct target_core_fabric_ops
*fo
)
483 struct target_fabric_configfs
*t
;
485 mutex_lock(&g_tf_lock
);
486 list_for_each_entry(t
, &g_tf_list
, tf_list
) {
487 if (!strcmp(t
->tf_ops
->name
, fo
->name
)) {
488 BUG_ON(atomic_read(&t
->tf_access_cnt
));
489 list_del(&t
->tf_list
);
490 mutex_unlock(&g_tf_lock
);
492 * Wait for any outstanding fabric se_deve_entry->rcu_head
493 * callbacks to complete post kfree_rcu(), before allowing
494 * fabric driver unload of TFO->module to proceed.
501 mutex_unlock(&g_tf_lock
);
503 EXPORT_SYMBOL(target_unregister_template
);
505 /*##############################################################################
506 // Stop functions called by external Target Fabrics Modules
507 //############################################################################*/
509 static inline struct se_dev_attrib
*to_attrib(struct config_item
*item
)
511 return container_of(to_config_group(item
), struct se_dev_attrib
,
515 /* Start functions for struct config_item_type tb_dev_attrib_cit */
516 #define DEF_CONFIGFS_ATTRIB_SHOW(_name) \
517 static ssize_t _name##_show(struct config_item *item, char *page) \
519 return snprintf(page, PAGE_SIZE, "%u\n", to_attrib(item)->_name); \
522 DEF_CONFIGFS_ATTRIB_SHOW(emulate_model_alias
);
523 DEF_CONFIGFS_ATTRIB_SHOW(emulate_dpo
);
524 DEF_CONFIGFS_ATTRIB_SHOW(emulate_fua_write
);
525 DEF_CONFIGFS_ATTRIB_SHOW(emulate_fua_read
);
526 DEF_CONFIGFS_ATTRIB_SHOW(emulate_write_cache
);
527 DEF_CONFIGFS_ATTRIB_SHOW(emulate_ua_intlck_ctrl
);
528 DEF_CONFIGFS_ATTRIB_SHOW(emulate_tas
);
529 DEF_CONFIGFS_ATTRIB_SHOW(emulate_tpu
);
530 DEF_CONFIGFS_ATTRIB_SHOW(emulate_tpws
);
531 DEF_CONFIGFS_ATTRIB_SHOW(emulate_caw
);
532 DEF_CONFIGFS_ATTRIB_SHOW(emulate_3pc
);
533 DEF_CONFIGFS_ATTRIB_SHOW(pi_prot_type
);
534 DEF_CONFIGFS_ATTRIB_SHOW(hw_pi_prot_type
);
535 DEF_CONFIGFS_ATTRIB_SHOW(pi_prot_format
);
536 DEF_CONFIGFS_ATTRIB_SHOW(pi_prot_verify
);
537 DEF_CONFIGFS_ATTRIB_SHOW(enforce_pr_isids
);
538 DEF_CONFIGFS_ATTRIB_SHOW(is_nonrot
);
539 DEF_CONFIGFS_ATTRIB_SHOW(emulate_rest_reord
);
540 DEF_CONFIGFS_ATTRIB_SHOW(force_pr_aptpl
);
541 DEF_CONFIGFS_ATTRIB_SHOW(hw_block_size
);
542 DEF_CONFIGFS_ATTRIB_SHOW(block_size
);
543 DEF_CONFIGFS_ATTRIB_SHOW(hw_max_sectors
);
544 DEF_CONFIGFS_ATTRIB_SHOW(optimal_sectors
);
545 DEF_CONFIGFS_ATTRIB_SHOW(hw_queue_depth
);
546 DEF_CONFIGFS_ATTRIB_SHOW(queue_depth
);
547 DEF_CONFIGFS_ATTRIB_SHOW(max_unmap_lba_count
);
548 DEF_CONFIGFS_ATTRIB_SHOW(max_unmap_block_desc_count
);
549 DEF_CONFIGFS_ATTRIB_SHOW(unmap_granularity
);
550 DEF_CONFIGFS_ATTRIB_SHOW(unmap_granularity_alignment
);
551 DEF_CONFIGFS_ATTRIB_SHOW(unmap_zeroes_data
);
552 DEF_CONFIGFS_ATTRIB_SHOW(max_write_same_len
);
554 #define DEF_CONFIGFS_ATTRIB_STORE_U32(_name) \
555 static ssize_t _name##_store(struct config_item *item, const char *page,\
558 struct se_dev_attrib *da = to_attrib(item); \
562 ret = kstrtou32(page, 0, &val); \
569 DEF_CONFIGFS_ATTRIB_STORE_U32(max_unmap_lba_count
);
570 DEF_CONFIGFS_ATTRIB_STORE_U32(max_unmap_block_desc_count
);
571 DEF_CONFIGFS_ATTRIB_STORE_U32(unmap_granularity
);
572 DEF_CONFIGFS_ATTRIB_STORE_U32(unmap_granularity_alignment
);
573 DEF_CONFIGFS_ATTRIB_STORE_U32(max_write_same_len
);
575 #define DEF_CONFIGFS_ATTRIB_STORE_BOOL(_name) \
576 static ssize_t _name##_store(struct config_item *item, const char *page, \
579 struct se_dev_attrib *da = to_attrib(item); \
583 ret = strtobool(page, &flag); \
590 DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_fua_write
);
591 DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_caw
);
592 DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_3pc
);
593 DEF_CONFIGFS_ATTRIB_STORE_BOOL(enforce_pr_isids
);
594 DEF_CONFIGFS_ATTRIB_STORE_BOOL(is_nonrot
);
596 #define DEF_CONFIGFS_ATTRIB_STORE_STUB(_name) \
597 static ssize_t _name##_store(struct config_item *item, const char *page,\
600 printk_once(KERN_WARNING \
601 "ignoring deprecated %s attribute\n", \
602 __stringify(_name)); \
606 DEF_CONFIGFS_ATTRIB_STORE_STUB(emulate_dpo
);
607 DEF_CONFIGFS_ATTRIB_STORE_STUB(emulate_fua_read
);
609 static void dev_set_t10_wwn_model_alias(struct se_device
*dev
)
611 const char *configname
;
613 configname
= config_item_name(&dev
->dev_group
.cg_item
);
614 if (strlen(configname
) >= 16) {
615 pr_warn("dev[%p]: Backstore name '%s' is too long for "
616 "INQUIRY_MODEL, truncating to 16 bytes\n", dev
,
619 snprintf(&dev
->t10_wwn
.model
[0], 16, "%s", configname
);
622 static ssize_t
emulate_model_alias_store(struct config_item
*item
,
623 const char *page
, size_t count
)
625 struct se_dev_attrib
*da
= to_attrib(item
);
626 struct se_device
*dev
= da
->da_dev
;
630 if (dev
->export_count
) {
631 pr_err("dev[%p]: Unable to change model alias"
632 " while export_count is %d\n",
633 dev
, dev
->export_count
);
637 ret
= strtobool(page
, &flag
);
642 dev_set_t10_wwn_model_alias(dev
);
644 strncpy(&dev
->t10_wwn
.model
[0],
645 dev
->transport
->inquiry_prod
, 16);
647 da
->emulate_model_alias
= flag
;
651 static ssize_t
emulate_write_cache_store(struct config_item
*item
,
652 const char *page
, size_t count
)
654 struct se_dev_attrib
*da
= to_attrib(item
);
658 ret
= strtobool(page
, &flag
);
662 if (flag
&& da
->da_dev
->transport
->get_write_cache
) {
663 pr_err("emulate_write_cache not supported for this device\n");
667 da
->emulate_write_cache
= flag
;
668 pr_debug("dev[%p]: SE Device WRITE_CACHE_EMULATION flag: %d\n",
673 static ssize_t
emulate_ua_intlck_ctrl_store(struct config_item
*item
,
674 const char *page
, size_t count
)
676 struct se_dev_attrib
*da
= to_attrib(item
);
680 ret
= kstrtou32(page
, 0, &val
);
684 if (val
!= 0 && val
!= 1 && val
!= 2) {
685 pr_err("Illegal value %d\n", val
);
689 if (da
->da_dev
->export_count
) {
690 pr_err("dev[%p]: Unable to change SE Device"
691 " UA_INTRLCK_CTRL while export_count is %d\n",
692 da
->da_dev
, da
->da_dev
->export_count
);
695 da
->emulate_ua_intlck_ctrl
= val
;
696 pr_debug("dev[%p]: SE Device UA_INTRLCK_CTRL flag: %d\n",
701 static ssize_t
emulate_tas_store(struct config_item
*item
,
702 const char *page
, size_t count
)
704 struct se_dev_attrib
*da
= to_attrib(item
);
708 ret
= strtobool(page
, &flag
);
712 if (da
->da_dev
->export_count
) {
713 pr_err("dev[%p]: Unable to change SE Device TAS while"
714 " export_count is %d\n",
715 da
->da_dev
, da
->da_dev
->export_count
);
718 da
->emulate_tas
= flag
;
719 pr_debug("dev[%p]: SE Device TASK_ABORTED status bit: %s\n",
720 da
->da_dev
, flag
? "Enabled" : "Disabled");
725 static ssize_t
emulate_tpu_store(struct config_item
*item
,
726 const char *page
, size_t count
)
728 struct se_dev_attrib
*da
= to_attrib(item
);
732 ret
= strtobool(page
, &flag
);
737 * We expect this value to be non-zero when generic Block Layer
738 * Discard supported is detected iblock_create_virtdevice().
740 if (flag
&& !da
->max_unmap_block_desc_count
) {
741 pr_err("Generic Block Discard not supported\n");
745 da
->emulate_tpu
= flag
;
746 pr_debug("dev[%p]: SE Device Thin Provisioning UNMAP bit: %d\n",
751 static ssize_t
emulate_tpws_store(struct config_item
*item
,
752 const char *page
, size_t count
)
754 struct se_dev_attrib
*da
= to_attrib(item
);
758 ret
= strtobool(page
, &flag
);
763 * We expect this value to be non-zero when generic Block Layer
764 * Discard supported is detected iblock_create_virtdevice().
766 if (flag
&& !da
->max_unmap_block_desc_count
) {
767 pr_err("Generic Block Discard not supported\n");
771 da
->emulate_tpws
= flag
;
772 pr_debug("dev[%p]: SE Device Thin Provisioning WRITE_SAME: %d\n",
777 static ssize_t
pi_prot_type_store(struct config_item
*item
,
778 const char *page
, size_t count
)
780 struct se_dev_attrib
*da
= to_attrib(item
);
781 int old_prot
= da
->pi_prot_type
, ret
;
782 struct se_device
*dev
= da
->da_dev
;
785 ret
= kstrtou32(page
, 0, &flag
);
789 if (flag
!= 0 && flag
!= 1 && flag
!= 2 && flag
!= 3) {
790 pr_err("Illegal value %d for pi_prot_type\n", flag
);
794 pr_err("DIF TYPE2 protection currently not supported\n");
797 if (da
->hw_pi_prot_type
) {
798 pr_warn("DIF protection enabled on underlying hardware,"
802 if (!dev
->transport
->init_prot
|| !dev
->transport
->free_prot
) {
803 /* 0 is only allowed value for non-supporting backends */
807 pr_err("DIF protection not supported by backend: %s\n",
808 dev
->transport
->name
);
811 if (!(dev
->dev_flags
& DF_CONFIGURED
)) {
812 pr_err("DIF protection requires device to be configured\n");
815 if (dev
->export_count
) {
816 pr_err("dev[%p]: Unable to change SE Device PROT type while"
817 " export_count is %d\n", dev
, dev
->export_count
);
821 da
->pi_prot_type
= flag
;
823 if (flag
&& !old_prot
) {
824 ret
= dev
->transport
->init_prot(dev
);
826 da
->pi_prot_type
= old_prot
;
827 da
->pi_prot_verify
= (bool) da
->pi_prot_type
;
831 } else if (!flag
&& old_prot
) {
832 dev
->transport
->free_prot(dev
);
835 da
->pi_prot_verify
= (bool) da
->pi_prot_type
;
836 pr_debug("dev[%p]: SE Device Protection Type: %d\n", dev
, flag
);
840 static ssize_t
pi_prot_format_store(struct config_item
*item
,
841 const char *page
, size_t count
)
843 struct se_dev_attrib
*da
= to_attrib(item
);
844 struct se_device
*dev
= da
->da_dev
;
848 ret
= strtobool(page
, &flag
);
855 if (!dev
->transport
->format_prot
) {
856 pr_err("DIF protection format not supported by backend %s\n",
857 dev
->transport
->name
);
860 if (!(dev
->dev_flags
& DF_CONFIGURED
)) {
861 pr_err("DIF protection format requires device to be configured\n");
864 if (dev
->export_count
) {
865 pr_err("dev[%p]: Unable to format SE Device PROT type while"
866 " export_count is %d\n", dev
, dev
->export_count
);
870 ret
= dev
->transport
->format_prot(dev
);
874 pr_debug("dev[%p]: SE Device Protection Format complete\n", dev
);
878 static ssize_t
pi_prot_verify_store(struct config_item
*item
,
879 const char *page
, size_t count
)
881 struct se_dev_attrib
*da
= to_attrib(item
);
885 ret
= strtobool(page
, &flag
);
890 da
->pi_prot_verify
= flag
;
893 if (da
->hw_pi_prot_type
) {
894 pr_warn("DIF protection enabled on underlying hardware,"
898 if (!da
->pi_prot_type
) {
899 pr_warn("DIF protection not supported by backend, ignoring\n");
902 da
->pi_prot_verify
= flag
;
907 static ssize_t
force_pr_aptpl_store(struct config_item
*item
,
908 const char *page
, size_t count
)
910 struct se_dev_attrib
*da
= to_attrib(item
);
914 ret
= strtobool(page
, &flag
);
917 if (da
->da_dev
->export_count
) {
918 pr_err("dev[%p]: Unable to set force_pr_aptpl while"
919 " export_count is %d\n",
920 da
->da_dev
, da
->da_dev
->export_count
);
924 da
->force_pr_aptpl
= flag
;
925 pr_debug("dev[%p]: SE Device force_pr_aptpl: %d\n", da
->da_dev
, flag
);
929 static ssize_t
emulate_rest_reord_store(struct config_item
*item
,
930 const char *page
, size_t count
)
932 struct se_dev_attrib
*da
= to_attrib(item
);
936 ret
= strtobool(page
, &flag
);
941 printk(KERN_ERR
"dev[%p]: SE Device emulation of restricted"
942 " reordering not implemented\n", da
->da_dev
);
945 da
->emulate_rest_reord
= flag
;
946 pr_debug("dev[%p]: SE Device emulate_rest_reord: %d\n",
951 static ssize_t
unmap_zeroes_data_store(struct config_item
*item
,
952 const char *page
, size_t count
)
954 struct se_dev_attrib
*da
= to_attrib(item
);
958 ret
= strtobool(page
, &flag
);
962 if (da
->da_dev
->export_count
) {
963 pr_err("dev[%p]: Unable to change SE Device"
964 " unmap_zeroes_data while export_count is %d\n",
965 da
->da_dev
, da
->da_dev
->export_count
);
969 * We expect this value to be non-zero when generic Block Layer
970 * Discard supported is detected iblock_configure_device().
972 if (flag
&& !da
->max_unmap_block_desc_count
) {
973 pr_err("dev[%p]: Thin Provisioning LBPRZ will not be set"
974 " because max_unmap_block_desc_count is zero\n",
978 da
->unmap_zeroes_data
= flag
;
979 pr_debug("dev[%p]: SE Device Thin Provisioning LBPRZ bit: %d\n",
985 * Note, this can only be called on unexported SE Device Object.
987 static ssize_t
queue_depth_store(struct config_item
*item
,
988 const char *page
, size_t count
)
990 struct se_dev_attrib
*da
= to_attrib(item
);
991 struct se_device
*dev
= da
->da_dev
;
995 ret
= kstrtou32(page
, 0, &val
);
999 if (dev
->export_count
) {
1000 pr_err("dev[%p]: Unable to change SE Device TCQ while"
1001 " export_count is %d\n",
1002 dev
, dev
->export_count
);
1006 pr_err("dev[%p]: Illegal ZERO value for queue_depth\n", dev
);
1010 if (val
> dev
->dev_attrib
.queue_depth
) {
1011 if (val
> dev
->dev_attrib
.hw_queue_depth
) {
1012 pr_err("dev[%p]: Passed queue_depth:"
1013 " %u exceeds TCM/SE_Device MAX"
1014 " TCQ: %u\n", dev
, val
,
1015 dev
->dev_attrib
.hw_queue_depth
);
1019 da
->queue_depth
= dev
->queue_depth
= val
;
1020 pr_debug("dev[%p]: SE Device TCQ Depth changed to: %u\n", dev
, val
);
1024 static ssize_t
optimal_sectors_store(struct config_item
*item
,
1025 const char *page
, size_t count
)
1027 struct se_dev_attrib
*da
= to_attrib(item
);
1031 ret
= kstrtou32(page
, 0, &val
);
1035 if (da
->da_dev
->export_count
) {
1036 pr_err("dev[%p]: Unable to change SE Device"
1037 " optimal_sectors while export_count is %d\n",
1038 da
->da_dev
, da
->da_dev
->export_count
);
1041 if (val
> da
->hw_max_sectors
) {
1042 pr_err("dev[%p]: Passed optimal_sectors %u cannot be"
1043 " greater than hw_max_sectors: %u\n",
1044 da
->da_dev
, val
, da
->hw_max_sectors
);
1048 da
->optimal_sectors
= val
;
1049 pr_debug("dev[%p]: SE Device optimal_sectors changed to %u\n",
1054 static ssize_t
block_size_store(struct config_item
*item
,
1055 const char *page
, size_t count
)
1057 struct se_dev_attrib
*da
= to_attrib(item
);
1061 ret
= kstrtou32(page
, 0, &val
);
1065 if (da
->da_dev
->export_count
) {
1066 pr_err("dev[%p]: Unable to change SE Device block_size"
1067 " while export_count is %d\n",
1068 da
->da_dev
, da
->da_dev
->export_count
);
1072 if (val
!= 512 && val
!= 1024 && val
!= 2048 && val
!= 4096) {
1073 pr_err("dev[%p]: Illegal value for block_device: %u"
1074 " for SE device, must be 512, 1024, 2048 or 4096\n",
1079 da
->block_size
= val
;
1080 if (da
->max_bytes_per_io
)
1081 da
->hw_max_sectors
= da
->max_bytes_per_io
/ val
;
1083 pr_debug("dev[%p]: SE Device block_size changed to %u\n",
1088 static ssize_t
alua_support_show(struct config_item
*item
, char *page
)
1090 struct se_dev_attrib
*da
= to_attrib(item
);
1091 u8 flags
= da
->da_dev
->transport
->transport_flags
;
1093 return snprintf(page
, PAGE_SIZE
, "%d\n",
1094 flags
& TRANSPORT_FLAG_PASSTHROUGH_ALUA
? 0 : 1);
1097 static ssize_t
pgr_support_show(struct config_item
*item
, char *page
)
1099 struct se_dev_attrib
*da
= to_attrib(item
);
1100 u8 flags
= da
->da_dev
->transport
->transport_flags
;
1102 return snprintf(page
, PAGE_SIZE
, "%d\n",
1103 flags
& TRANSPORT_FLAG_PASSTHROUGH_PGR
? 0 : 1);
1106 CONFIGFS_ATTR(, emulate_model_alias
);
1107 CONFIGFS_ATTR(, emulate_dpo
);
1108 CONFIGFS_ATTR(, emulate_fua_write
);
1109 CONFIGFS_ATTR(, emulate_fua_read
);
1110 CONFIGFS_ATTR(, emulate_write_cache
);
1111 CONFIGFS_ATTR(, emulate_ua_intlck_ctrl
);
1112 CONFIGFS_ATTR(, emulate_tas
);
1113 CONFIGFS_ATTR(, emulate_tpu
);
1114 CONFIGFS_ATTR(, emulate_tpws
);
1115 CONFIGFS_ATTR(, emulate_caw
);
1116 CONFIGFS_ATTR(, emulate_3pc
);
1117 CONFIGFS_ATTR(, pi_prot_type
);
1118 CONFIGFS_ATTR_RO(, hw_pi_prot_type
);
1119 CONFIGFS_ATTR(, pi_prot_format
);
1120 CONFIGFS_ATTR(, pi_prot_verify
);
1121 CONFIGFS_ATTR(, enforce_pr_isids
);
1122 CONFIGFS_ATTR(, is_nonrot
);
1123 CONFIGFS_ATTR(, emulate_rest_reord
);
1124 CONFIGFS_ATTR(, force_pr_aptpl
);
1125 CONFIGFS_ATTR_RO(, hw_block_size
);
1126 CONFIGFS_ATTR(, block_size
);
1127 CONFIGFS_ATTR_RO(, hw_max_sectors
);
1128 CONFIGFS_ATTR(, optimal_sectors
);
1129 CONFIGFS_ATTR_RO(, hw_queue_depth
);
1130 CONFIGFS_ATTR(, queue_depth
);
1131 CONFIGFS_ATTR(, max_unmap_lba_count
);
1132 CONFIGFS_ATTR(, max_unmap_block_desc_count
);
1133 CONFIGFS_ATTR(, unmap_granularity
);
1134 CONFIGFS_ATTR(, unmap_granularity_alignment
);
1135 CONFIGFS_ATTR(, unmap_zeroes_data
);
1136 CONFIGFS_ATTR(, max_write_same_len
);
1137 CONFIGFS_ATTR_RO(, alua_support
);
1138 CONFIGFS_ATTR_RO(, pgr_support
);
1141 * dev_attrib attributes for devices using the target core SBC/SPC
1142 * interpreter. Any backend using spc_parse_cdb should be using
1145 struct configfs_attribute
*sbc_attrib_attrs
[] = {
1146 &attr_emulate_model_alias
,
1148 &attr_emulate_fua_write
,
1149 &attr_emulate_fua_read
,
1150 &attr_emulate_write_cache
,
1151 &attr_emulate_ua_intlck_ctrl
,
1158 &attr_hw_pi_prot_type
,
1159 &attr_pi_prot_format
,
1160 &attr_pi_prot_verify
,
1161 &attr_enforce_pr_isids
,
1163 &attr_emulate_rest_reord
,
1164 &attr_force_pr_aptpl
,
1165 &attr_hw_block_size
,
1167 &attr_hw_max_sectors
,
1168 &attr_optimal_sectors
,
1169 &attr_hw_queue_depth
,
1171 &attr_max_unmap_lba_count
,
1172 &attr_max_unmap_block_desc_count
,
1173 &attr_unmap_granularity
,
1174 &attr_unmap_granularity_alignment
,
1175 &attr_unmap_zeroes_data
,
1176 &attr_max_write_same_len
,
1181 EXPORT_SYMBOL(sbc_attrib_attrs
);
1184 * Minimal dev_attrib attributes for devices passing through CDBs.
1185 * In this case we only provide a few read-only attributes for
1186 * backwards compatibility.
1188 struct configfs_attribute
*passthrough_attrib_attrs
[] = {
1189 &attr_hw_pi_prot_type
,
1190 &attr_hw_block_size
,
1191 &attr_hw_max_sectors
,
1192 &attr_hw_queue_depth
,
1197 EXPORT_SYMBOL(passthrough_attrib_attrs
);
1199 TB_CIT_SETUP_DRV(dev_attrib
, NULL
, NULL
);
1200 TB_CIT_SETUP_DRV(dev_action
, NULL
, NULL
);
1202 /* End functions for struct config_item_type tb_dev_attrib_cit */
1204 /* Start functions for struct config_item_type tb_dev_wwn_cit */
1206 static struct t10_wwn
*to_t10_wwn(struct config_item
*item
)
1208 return container_of(to_config_group(item
), struct t10_wwn
, t10_wwn_group
);
1212 * VPD page 0x80 Unit serial
1214 static ssize_t
target_wwn_vpd_unit_serial_show(struct config_item
*item
,
1217 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
1218 &to_t10_wwn(item
)->unit_serial
[0]);
1221 static ssize_t
target_wwn_vpd_unit_serial_store(struct config_item
*item
,
1222 const char *page
, size_t count
)
1224 struct t10_wwn
*t10_wwn
= to_t10_wwn(item
);
1225 struct se_device
*dev
= t10_wwn
->t10_dev
;
1226 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
1229 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
1230 * from the struct scsi_device level firmware, do not allow
1231 * VPD Unit Serial to be emulated.
1233 * Note this struct scsi_device could also be emulating VPD
1234 * information from its drivers/scsi LLD. But for now we assume
1235 * it is doing 'the right thing' wrt a world wide unique
1236 * VPD Unit Serial Number that OS dependent multipath can depend on.
1238 if (dev
->dev_flags
& DF_FIRMWARE_VPD_UNIT_SERIAL
) {
1239 pr_err("Underlying SCSI device firmware provided VPD"
1240 " Unit Serial, ignoring request\n");
1244 if (strlen(page
) >= INQUIRY_VPD_SERIAL_LEN
) {
1245 pr_err("Emulated VPD Unit Serial exceeds"
1246 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
1250 * Check to see if any active $FABRIC_MOD exports exist. If they
1251 * do exist, fail here as changing this information on the fly
1252 * (underneath the initiator side OS dependent multipath code)
1253 * could cause negative effects.
1255 if (dev
->export_count
) {
1256 pr_err("Unable to set VPD Unit Serial while"
1257 " active %d $FABRIC_MOD exports exist\n",
1263 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
1265 * Also, strip any newline added from the userspace
1266 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
1268 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
1269 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
1270 snprintf(dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
1271 "%s", strstrip(buf
));
1272 dev
->dev_flags
|= DF_EMULATED_VPD_UNIT_SERIAL
;
1274 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
1275 " %s\n", dev
->t10_wwn
.unit_serial
);
1281 * VPD page 0x83 Protocol Identifier
1283 static ssize_t
target_wwn_vpd_protocol_identifier_show(struct config_item
*item
,
1286 struct t10_wwn
*t10_wwn
= to_t10_wwn(item
);
1287 struct t10_vpd
*vpd
;
1288 unsigned char buf
[VPD_TMP_BUF_SIZE
];
1291 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
1293 spin_lock(&t10_wwn
->t10_vpd_lock
);
1294 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
1295 if (!vpd
->protocol_identifier_set
)
1298 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
1300 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1303 len
+= sprintf(page
+len
, "%s", buf
);
1305 spin_unlock(&t10_wwn
->t10_vpd_lock
);
1311 * Generic wrapper for dumping VPD identifiers by association.
1313 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
1314 static ssize_t target_wwn_##_name##_show(struct config_item *item, \
1317 struct t10_wwn *t10_wwn = to_t10_wwn(item); \
1318 struct t10_vpd *vpd; \
1319 unsigned char buf[VPD_TMP_BUF_SIZE]; \
1322 spin_lock(&t10_wwn->t10_vpd_lock); \
1323 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
1324 if (vpd->association != _assoc) \
1327 memset(buf, 0, VPD_TMP_BUF_SIZE); \
1328 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
1329 if (len + strlen(buf) >= PAGE_SIZE) \
1331 len += sprintf(page+len, "%s", buf); \
1333 memset(buf, 0, VPD_TMP_BUF_SIZE); \
1334 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
1335 if (len + strlen(buf) >= PAGE_SIZE) \
1337 len += sprintf(page+len, "%s", buf); \
1339 memset(buf, 0, VPD_TMP_BUF_SIZE); \
1340 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
1341 if (len + strlen(buf) >= PAGE_SIZE) \
1343 len += sprintf(page+len, "%s", buf); \
1345 spin_unlock(&t10_wwn->t10_vpd_lock); \
1350 /* VPD page 0x83 Association: Logical Unit */
1351 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
1352 /* VPD page 0x83 Association: Target Port */
1353 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
1354 /* VPD page 0x83 Association: SCSI Target Device */
1355 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
1357 CONFIGFS_ATTR(target_wwn_
, vpd_unit_serial
);
1358 CONFIGFS_ATTR_RO(target_wwn_
, vpd_protocol_identifier
);
1359 CONFIGFS_ATTR_RO(target_wwn_
, vpd_assoc_logical_unit
);
1360 CONFIGFS_ATTR_RO(target_wwn_
, vpd_assoc_target_port
);
1361 CONFIGFS_ATTR_RO(target_wwn_
, vpd_assoc_scsi_target_device
);
1363 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
1364 &target_wwn_attr_vpd_unit_serial
,
1365 &target_wwn_attr_vpd_protocol_identifier
,
1366 &target_wwn_attr_vpd_assoc_logical_unit
,
1367 &target_wwn_attr_vpd_assoc_target_port
,
1368 &target_wwn_attr_vpd_assoc_scsi_target_device
,
1372 TB_CIT_SETUP(dev_wwn
, NULL
, NULL
, target_core_dev_wwn_attrs
);
1374 /* End functions for struct config_item_type tb_dev_wwn_cit */
1376 /* Start functions for struct config_item_type tb_dev_pr_cit */
1378 static struct se_device
*pr_to_dev(struct config_item
*item
)
1380 return container_of(to_config_group(item
), struct se_device
,
1384 static ssize_t
target_core_dev_pr_show_spc3_res(struct se_device
*dev
,
1387 struct se_node_acl
*se_nacl
;
1388 struct t10_pr_registration
*pr_reg
;
1389 char i_buf
[PR_REG_ISID_ID_LEN
];
1391 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1393 pr_reg
= dev
->dev_pr_res_holder
;
1395 return sprintf(page
, "No SPC-3 Reservation holder\n");
1397 se_nacl
= pr_reg
->pr_reg_nacl
;
1398 core_pr_dump_initiator_port(pr_reg
, i_buf
, PR_REG_ISID_ID_LEN
);
1400 return sprintf(page
, "SPC-3 Reservation: %s Initiator: %s%s\n",
1401 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1402 se_nacl
->initiatorname
, i_buf
);
1405 static ssize_t
target_core_dev_pr_show_spc2_res(struct se_device
*dev
,
1408 struct se_node_acl
*se_nacl
;
1411 se_nacl
= dev
->dev_reserved_node_acl
;
1414 "SPC-2 Reservation: %s Initiator: %s\n",
1415 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1416 se_nacl
->initiatorname
);
1418 len
= sprintf(page
, "No SPC-2 Reservation holder\n");
1423 static ssize_t
target_pr_res_holder_show(struct config_item
*item
, char *page
)
1425 struct se_device
*dev
= pr_to_dev(item
);
1428 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH_PGR
)
1429 return sprintf(page
, "Passthrough\n");
1431 spin_lock(&dev
->dev_reservation_lock
);
1432 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1433 ret
= target_core_dev_pr_show_spc2_res(dev
, page
);
1435 ret
= target_core_dev_pr_show_spc3_res(dev
, page
);
1436 spin_unlock(&dev
->dev_reservation_lock
);
1440 static ssize_t
target_pr_res_pr_all_tgt_pts_show(struct config_item
*item
,
1443 struct se_device
*dev
= pr_to_dev(item
);
1446 spin_lock(&dev
->dev_reservation_lock
);
1447 if (!dev
->dev_pr_res_holder
) {
1448 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1449 } else if (dev
->dev_pr_res_holder
->pr_reg_all_tg_pt
) {
1450 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1451 " Ports registration\n");
1453 len
= sprintf(page
, "SPC-3 Reservation: Single"
1454 " Target Port registration\n");
1457 spin_unlock(&dev
->dev_reservation_lock
);
1461 static ssize_t
target_pr_res_pr_generation_show(struct config_item
*item
,
1464 return sprintf(page
, "0x%08x\n", pr_to_dev(item
)->t10_pr
.pr_generation
);
1468 static ssize_t
target_pr_res_pr_holder_tg_port_show(struct config_item
*item
,
1471 struct se_device
*dev
= pr_to_dev(item
);
1472 struct se_node_acl
*se_nacl
;
1473 struct se_portal_group
*se_tpg
;
1474 struct t10_pr_registration
*pr_reg
;
1475 const struct target_core_fabric_ops
*tfo
;
1478 spin_lock(&dev
->dev_reservation_lock
);
1479 pr_reg
= dev
->dev_pr_res_holder
;
1481 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1485 se_nacl
= pr_reg
->pr_reg_nacl
;
1486 se_tpg
= se_nacl
->se_tpg
;
1487 tfo
= se_tpg
->se_tpg_tfo
;
1489 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1490 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1491 tfo
->tpg_get_wwn(se_tpg
));
1492 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1493 " Identifier Tag: %hu %s Portal Group Tag: %hu"
1494 " %s Logical Unit: %llu\n", pr_reg
->tg_pt_sep_rtpi
,
1495 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1496 tfo
->get_fabric_name(), pr_reg
->pr_aptpl_target_lun
);
1499 spin_unlock(&dev
->dev_reservation_lock
);
1504 static ssize_t
target_pr_res_pr_registered_i_pts_show(struct config_item
*item
,
1507 struct se_device
*dev
= pr_to_dev(item
);
1508 const struct target_core_fabric_ops
*tfo
;
1509 struct t10_pr_registration
*pr_reg
;
1510 unsigned char buf
[384];
1511 char i_buf
[PR_REG_ISID_ID_LEN
];
1515 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1517 spin_lock(&dev
->t10_pr
.registration_lock
);
1518 list_for_each_entry(pr_reg
, &dev
->t10_pr
.registration_list
,
1521 memset(buf
, 0, 384);
1522 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1523 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1524 core_pr_dump_initiator_port(pr_reg
, i_buf
,
1525 PR_REG_ISID_ID_LEN
);
1526 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1527 tfo
->get_fabric_name(),
1528 pr_reg
->pr_reg_nacl
->initiatorname
, i_buf
, pr_reg
->pr_res_key
,
1529 pr_reg
->pr_res_generation
);
1531 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1534 len
+= sprintf(page
+len
, "%s", buf
);
1537 spin_unlock(&dev
->t10_pr
.registration_lock
);
1540 len
+= sprintf(page
+len
, "None\n");
1545 static ssize_t
target_pr_res_pr_type_show(struct config_item
*item
, char *page
)
1547 struct se_device
*dev
= pr_to_dev(item
);
1548 struct t10_pr_registration
*pr_reg
;
1551 spin_lock(&dev
->dev_reservation_lock
);
1552 pr_reg
= dev
->dev_pr_res_holder
;
1554 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1555 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1557 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1560 spin_unlock(&dev
->dev_reservation_lock
);
1564 static ssize_t
target_pr_res_type_show(struct config_item
*item
, char *page
)
1566 struct se_device
*dev
= pr_to_dev(item
);
1568 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH_PGR
)
1569 return sprintf(page
, "SPC_PASSTHROUGH\n");
1570 else if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1571 return sprintf(page
, "SPC2_RESERVATIONS\n");
1573 return sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1576 static ssize_t
target_pr_res_aptpl_active_show(struct config_item
*item
,
1579 struct se_device
*dev
= pr_to_dev(item
);
1581 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH_PGR
)
1584 return sprintf(page
, "APTPL Bit Status: %s\n",
1585 (dev
->t10_pr
.pr_aptpl_active
) ? "Activated" : "Disabled");
1588 static ssize_t
target_pr_res_aptpl_metadata_show(struct config_item
*item
,
1591 struct se_device
*dev
= pr_to_dev(item
);
1593 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH_PGR
)
1596 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1600 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1601 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1602 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1603 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1606 static match_table_t tokens
= {
1607 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1608 {Opt_initiator_node
, "initiator_node=%s"},
1609 {Opt_initiator_sid
, "initiator_sid=%s"},
1610 {Opt_sa_res_key
, "sa_res_key=%s"},
1611 {Opt_res_holder
, "res_holder=%d"},
1612 {Opt_res_type
, "res_type=%d"},
1613 {Opt_res_scope
, "res_scope=%d"},
1614 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1615 {Opt_mapped_lun
, "mapped_lun=%u"},
1616 {Opt_target_fabric
, "target_fabric=%s"},
1617 {Opt_target_node
, "target_node=%s"},
1618 {Opt_tpgt
, "tpgt=%d"},
1619 {Opt_port_rtpi
, "port_rtpi=%d"},
1620 {Opt_target_lun
, "target_lun=%u"},
1624 static ssize_t
target_pr_res_aptpl_metadata_store(struct config_item
*item
,
1625 const char *page
, size_t count
)
1627 struct se_device
*dev
= pr_to_dev(item
);
1628 unsigned char *i_fabric
= NULL
, *i_port
= NULL
, *isid
= NULL
;
1629 unsigned char *t_fabric
= NULL
, *t_port
= NULL
;
1630 char *orig
, *ptr
, *opts
;
1631 substring_t args
[MAX_OPT_ARGS
];
1632 unsigned long long tmp_ll
;
1634 u64 mapped_lun
= 0, target_lun
= 0;
1635 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1639 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH_PGR
)
1641 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1644 if (dev
->export_count
) {
1645 pr_debug("Unable to process APTPL metadata while"
1646 " active fabric exports exist\n");
1650 opts
= kstrdup(page
, GFP_KERNEL
);
1655 while ((ptr
= strsep(&opts
, ",\n")) != NULL
) {
1659 token
= match_token(ptr
, tokens
, args
);
1661 case Opt_initiator_fabric
:
1662 i_fabric
= match_strdup(args
);
1668 case Opt_initiator_node
:
1669 i_port
= match_strdup(args
);
1674 if (strlen(i_port
) >= PR_APTPL_MAX_IPORT_LEN
) {
1675 pr_err("APTPL metadata initiator_node="
1676 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1677 PR_APTPL_MAX_IPORT_LEN
);
1682 case Opt_initiator_sid
:
1683 isid
= match_strdup(args
);
1688 if (strlen(isid
) >= PR_REG_ISID_LEN
) {
1689 pr_err("APTPL metadata initiator_isid"
1690 "= exceeds PR_REG_ISID_LEN: %d\n",
1696 case Opt_sa_res_key
:
1697 ret
= match_u64(args
, &tmp_ll
);
1699 pr_err("kstrtoull() failed for sa_res_key=\n");
1702 sa_res_key
= (u64
)tmp_ll
;
1705 * PR APTPL Metadata for Reservation
1707 case Opt_res_holder
:
1708 ret
= match_int(args
, &arg
);
1714 ret
= match_int(args
, &arg
);
1720 ret
= match_int(args
, &arg
);
1724 case Opt_res_all_tg_pt
:
1725 ret
= match_int(args
, &arg
);
1728 all_tg_pt
= (int)arg
;
1730 case Opt_mapped_lun
:
1731 ret
= match_u64(args
, &tmp_ll
);
1734 mapped_lun
= (u64
)tmp_ll
;
1737 * PR APTPL Metadata for Target Port
1739 case Opt_target_fabric
:
1740 t_fabric
= match_strdup(args
);
1746 case Opt_target_node
:
1747 t_port
= match_strdup(args
);
1752 if (strlen(t_port
) >= PR_APTPL_MAX_TPORT_LEN
) {
1753 pr_err("APTPL metadata target_node="
1754 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1755 PR_APTPL_MAX_TPORT_LEN
);
1761 ret
= match_int(args
, &arg
);
1767 ret
= match_int(args
, &arg
);
1771 case Opt_target_lun
:
1772 ret
= match_u64(args
, &tmp_ll
);
1775 target_lun
= (u64
)tmp_ll
;
1782 if (!i_port
|| !t_port
|| !sa_res_key
) {
1783 pr_err("Illegal parameters for APTPL registration\n");
1788 if (res_holder
&& !(type
)) {
1789 pr_err("Illegal PR type: 0x%02x for reservation"
1795 ret
= core_scsi3_alloc_aptpl_registration(&dev
->t10_pr
, sa_res_key
,
1796 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1797 res_holder
, all_tg_pt
, type
);
1805 return (ret
== 0) ? count
: ret
;
1809 CONFIGFS_ATTR_RO(target_pr_
, res_holder
);
1810 CONFIGFS_ATTR_RO(target_pr_
, res_pr_all_tgt_pts
);
1811 CONFIGFS_ATTR_RO(target_pr_
, res_pr_generation
);
1812 CONFIGFS_ATTR_RO(target_pr_
, res_pr_holder_tg_port
);
1813 CONFIGFS_ATTR_RO(target_pr_
, res_pr_registered_i_pts
);
1814 CONFIGFS_ATTR_RO(target_pr_
, res_pr_type
);
1815 CONFIGFS_ATTR_RO(target_pr_
, res_type
);
1816 CONFIGFS_ATTR_RO(target_pr_
, res_aptpl_active
);
1817 CONFIGFS_ATTR(target_pr_
, res_aptpl_metadata
);
1819 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1820 &target_pr_attr_res_holder
,
1821 &target_pr_attr_res_pr_all_tgt_pts
,
1822 &target_pr_attr_res_pr_generation
,
1823 &target_pr_attr_res_pr_holder_tg_port
,
1824 &target_pr_attr_res_pr_registered_i_pts
,
1825 &target_pr_attr_res_pr_type
,
1826 &target_pr_attr_res_type
,
1827 &target_pr_attr_res_aptpl_active
,
1828 &target_pr_attr_res_aptpl_metadata
,
1832 TB_CIT_SETUP(dev_pr
, NULL
, NULL
, target_core_dev_pr_attrs
);
1834 /* End functions for struct config_item_type tb_dev_pr_cit */
1836 /* Start functions for struct config_item_type tb_dev_cit */
1838 static inline struct se_device
*to_device(struct config_item
*item
)
1840 return container_of(to_config_group(item
), struct se_device
, dev_group
);
1843 static ssize_t
target_dev_info_show(struct config_item
*item
, char *page
)
1845 struct se_device
*dev
= to_device(item
);
1847 ssize_t read_bytes
= 0;
1849 transport_dump_dev_state(dev
, page
, &bl
);
1851 read_bytes
+= dev
->transport
->show_configfs_dev_params(dev
,
1856 static ssize_t
target_dev_control_store(struct config_item
*item
,
1857 const char *page
, size_t count
)
1859 struct se_device
*dev
= to_device(item
);
1861 return dev
->transport
->set_configfs_dev_params(dev
, page
, count
);
1864 static ssize_t
target_dev_alias_show(struct config_item
*item
, char *page
)
1866 struct se_device
*dev
= to_device(item
);
1868 if (!(dev
->dev_flags
& DF_USING_ALIAS
))
1871 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->dev_alias
);
1874 static ssize_t
target_dev_alias_store(struct config_item
*item
,
1875 const char *page
, size_t count
)
1877 struct se_device
*dev
= to_device(item
);
1878 struct se_hba
*hba
= dev
->se_hba
;
1881 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1882 pr_err("alias count: %d exceeds"
1883 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1884 SE_DEV_ALIAS_LEN
-1);
1888 read_bytes
= snprintf(&dev
->dev_alias
[0], SE_DEV_ALIAS_LEN
, "%s", page
);
1891 if (dev
->dev_alias
[read_bytes
- 1] == '\n')
1892 dev
->dev_alias
[read_bytes
- 1] = '\0';
1894 dev
->dev_flags
|= DF_USING_ALIAS
;
1896 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
1897 config_item_name(&hba
->hba_group
.cg_item
),
1898 config_item_name(&dev
->dev_group
.cg_item
),
1904 static ssize_t
target_dev_udev_path_show(struct config_item
*item
, char *page
)
1906 struct se_device
*dev
= to_device(item
);
1908 if (!(dev
->dev_flags
& DF_USING_UDEV_PATH
))
1911 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->udev_path
);
1914 static ssize_t
target_dev_udev_path_store(struct config_item
*item
,
1915 const char *page
, size_t count
)
1917 struct se_device
*dev
= to_device(item
);
1918 struct se_hba
*hba
= dev
->se_hba
;
1921 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1922 pr_err("udev_path count: %d exceeds"
1923 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1924 SE_UDEV_PATH_LEN
-1);
1928 read_bytes
= snprintf(&dev
->udev_path
[0], SE_UDEV_PATH_LEN
,
1932 if (dev
->udev_path
[read_bytes
- 1] == '\n')
1933 dev
->udev_path
[read_bytes
- 1] = '\0';
1935 dev
->dev_flags
|= DF_USING_UDEV_PATH
;
1937 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1938 config_item_name(&hba
->hba_group
.cg_item
),
1939 config_item_name(&dev
->dev_group
.cg_item
),
1945 static ssize_t
target_dev_enable_show(struct config_item
*item
, char *page
)
1947 struct se_device
*dev
= to_device(item
);
1949 return snprintf(page
, PAGE_SIZE
, "%d\n", !!(dev
->dev_flags
& DF_CONFIGURED
));
1952 static ssize_t
target_dev_enable_store(struct config_item
*item
,
1953 const char *page
, size_t count
)
1955 struct se_device
*dev
= to_device(item
);
1959 ptr
= strstr(page
, "1");
1961 pr_err("For dev_enable ops, only valid value"
1966 ret
= target_configure_device(dev
);
1972 static ssize_t
target_dev_alua_lu_gp_show(struct config_item
*item
, char *page
)
1974 struct se_device
*dev
= to_device(item
);
1975 struct config_item
*lu_ci
;
1976 struct t10_alua_lu_gp
*lu_gp
;
1977 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1980 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1984 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1985 lu_gp
= lu_gp_mem
->lu_gp
;
1987 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1988 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1989 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1991 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1996 static ssize_t
target_dev_alua_lu_gp_store(struct config_item
*item
,
1997 const char *page
, size_t count
)
1999 struct se_device
*dev
= to_device(item
);
2000 struct se_hba
*hba
= dev
->se_hba
;
2001 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
2002 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2003 unsigned char buf
[LU_GROUP_NAME_BUF
];
2006 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
2010 if (count
> LU_GROUP_NAME_BUF
) {
2011 pr_err("ALUA LU Group Alias too large!\n");
2014 memset(buf
, 0, LU_GROUP_NAME_BUF
);
2015 memcpy(buf
, page
, count
);
2017 * Any ALUA logical unit alias besides "NULL" means we will be
2018 * making a new group association.
2020 if (strcmp(strstrip(buf
), "NULL")) {
2022 * core_alua_get_lu_gp_by_name() will increment reference to
2023 * struct t10_alua_lu_gp. This reference is released with
2024 * core_alua_get_lu_gp_by_name below().
2026 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
2031 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
2032 lu_gp
= lu_gp_mem
->lu_gp
;
2035 * Clearing an existing lu_gp association, and replacing
2039 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
2040 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
2042 config_item_name(&hba
->hba_group
.cg_item
),
2043 config_item_name(&dev
->dev_group
.cg_item
),
2044 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
2047 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
2048 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
2053 * Removing existing association of lu_gp_mem with lu_gp
2055 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
2059 * Associate lu_gp_mem with lu_gp_new.
2061 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
2062 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
2064 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
2065 " core/alua/lu_gps/%s, ID: %hu\n",
2066 (move
) ? "Moving" : "Adding",
2067 config_item_name(&hba
->hba_group
.cg_item
),
2068 config_item_name(&dev
->dev_group
.cg_item
),
2069 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
2070 lu_gp_new
->lu_gp_id
);
2072 core_alua_put_lu_gp_from_name(lu_gp_new
);
2076 static ssize_t
target_dev_lba_map_show(struct config_item
*item
, char *page
)
2078 struct se_device
*dev
= to_device(item
);
2079 struct t10_alua_lba_map
*map
;
2080 struct t10_alua_lba_map_member
*mem
;
2085 spin_lock(&dev
->t10_alua
.lba_map_lock
);
2086 if (!list_empty(&dev
->t10_alua
.lba_map_list
))
2087 bl
+= sprintf(b
+ bl
, "%u %u\n",
2088 dev
->t10_alua
.lba_map_segment_size
,
2089 dev
->t10_alua
.lba_map_segment_multiplier
);
2090 list_for_each_entry(map
, &dev
->t10_alua
.lba_map_list
, lba_map_list
) {
2091 bl
+= sprintf(b
+ bl
, "%llu %llu",
2092 map
->lba_map_first_lba
, map
->lba_map_last_lba
);
2093 list_for_each_entry(mem
, &map
->lba_map_mem_list
,
2095 switch (mem
->lba_map_mem_alua_state
) {
2096 case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
:
2099 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
2102 case ALUA_ACCESS_STATE_STANDBY
:
2105 case ALUA_ACCESS_STATE_UNAVAILABLE
:
2112 bl
+= sprintf(b
+ bl
, " %d:%c",
2113 mem
->lba_map_mem_alua_pg_id
, state
);
2115 bl
+= sprintf(b
+ bl
, "\n");
2117 spin_unlock(&dev
->t10_alua
.lba_map_lock
);
2121 static ssize_t
target_dev_lba_map_store(struct config_item
*item
,
2122 const char *page
, size_t count
)
2124 struct se_device
*dev
= to_device(item
);
2125 struct t10_alua_lba_map
*lba_map
= NULL
;
2126 struct list_head lba_list
;
2127 char *map_entries
, *orig
, *ptr
;
2129 int pg_num
= -1, pg
;
2130 int ret
= 0, num
= 0, pg_id
, alua_state
;
2131 unsigned long start_lba
= -1, end_lba
= -1;
2132 unsigned long segment_size
= -1, segment_mult
= -1;
2134 orig
= map_entries
= kstrdup(page
, GFP_KERNEL
);
2138 INIT_LIST_HEAD(&lba_list
);
2139 while ((ptr
= strsep(&map_entries
, "\n")) != NULL
) {
2144 if (sscanf(ptr
, "%lu %lu\n",
2145 &segment_size
, &segment_mult
) != 2) {
2146 pr_err("Invalid line %d\n", num
);
2153 if (sscanf(ptr
, "%lu %lu", &start_lba
, &end_lba
) != 2) {
2154 pr_err("Invalid line %d\n", num
);
2158 ptr
= strchr(ptr
, ' ');
2160 pr_err("Invalid line %d, missing end lba\n", num
);
2165 ptr
= strchr(ptr
, ' ');
2167 pr_err("Invalid line %d, missing state definitions\n",
2173 lba_map
= core_alua_allocate_lba_map(&lba_list
,
2174 start_lba
, end_lba
);
2175 if (IS_ERR(lba_map
)) {
2176 ret
= PTR_ERR(lba_map
);
2180 while (sscanf(ptr
, "%d:%c", &pg_id
, &state
) == 2) {
2183 alua_state
= ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
;
2186 alua_state
= ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
;
2189 alua_state
= ALUA_ACCESS_STATE_STANDBY
;
2192 alua_state
= ALUA_ACCESS_STATE_UNAVAILABLE
;
2195 pr_err("Invalid ALUA state '%c'\n", state
);
2200 ret
= core_alua_allocate_lba_map_mem(lba_map
,
2203 pr_err("Invalid target descriptor %d:%c "
2209 ptr
= strchr(ptr
, ' ');
2217 else if (pg
!= pg_num
) {
2218 pr_err("Only %d from %d port groups definitions "
2219 "at line %d\n", pg
, pg_num
, num
);
2227 core_alua_free_lba_map(&lba_list
);
2230 core_alua_set_lba_map(dev
, &lba_list
,
2231 segment_size
, segment_mult
);
2236 CONFIGFS_ATTR_RO(target_dev_
, info
);
2237 CONFIGFS_ATTR_WO(target_dev_
, control
);
2238 CONFIGFS_ATTR(target_dev_
, alias
);
2239 CONFIGFS_ATTR(target_dev_
, udev_path
);
2240 CONFIGFS_ATTR(target_dev_
, enable
);
2241 CONFIGFS_ATTR(target_dev_
, alua_lu_gp
);
2242 CONFIGFS_ATTR(target_dev_
, lba_map
);
2244 static struct configfs_attribute
*target_core_dev_attrs
[] = {
2245 &target_dev_attr_info
,
2246 &target_dev_attr_control
,
2247 &target_dev_attr_alias
,
2248 &target_dev_attr_udev_path
,
2249 &target_dev_attr_enable
,
2250 &target_dev_attr_alua_lu_gp
,
2251 &target_dev_attr_lba_map
,
2255 static void target_core_dev_release(struct config_item
*item
)
2257 struct config_group
*dev_cg
= to_config_group(item
);
2258 struct se_device
*dev
=
2259 container_of(dev_cg
, struct se_device
, dev_group
);
2261 target_free_device(dev
);
2265 * Used in target_core_fabric_configfs.c to verify valid se_device symlink
2266 * within target_fabric_port_link()
2268 struct configfs_item_operations target_core_dev_item_ops
= {
2269 .release
= target_core_dev_release
,
2272 TB_CIT_SETUP(dev
, &target_core_dev_item_ops
, NULL
, target_core_dev_attrs
);
2274 /* End functions for struct config_item_type tb_dev_cit */
2276 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
2278 static inline struct t10_alua_lu_gp
*to_lu_gp(struct config_item
*item
)
2280 return container_of(to_config_group(item
), struct t10_alua_lu_gp
,
2284 static ssize_t
target_lu_gp_lu_gp_id_show(struct config_item
*item
, char *page
)
2286 struct t10_alua_lu_gp
*lu_gp
= to_lu_gp(item
);
2288 if (!lu_gp
->lu_gp_valid_id
)
2290 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
2293 static ssize_t
target_lu_gp_lu_gp_id_store(struct config_item
*item
,
2294 const char *page
, size_t count
)
2296 struct t10_alua_lu_gp
*lu_gp
= to_lu_gp(item
);
2297 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2298 unsigned long lu_gp_id
;
2301 ret
= kstrtoul(page
, 0, &lu_gp_id
);
2303 pr_err("kstrtoul() returned %d for"
2304 " lu_gp_id\n", ret
);
2307 if (lu_gp_id
> 0x0000ffff) {
2308 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
2309 " 0x0000ffff\n", lu_gp_id
);
2313 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
2317 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
2318 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2319 config_item_name(&alua_lu_gp_cg
->cg_item
),
2325 static ssize_t
target_lu_gp_members_show(struct config_item
*item
, char *page
)
2327 struct t10_alua_lu_gp
*lu_gp
= to_lu_gp(item
);
2328 struct se_device
*dev
;
2330 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2331 ssize_t len
= 0, cur_len
;
2332 unsigned char buf
[LU_GROUP_NAME_BUF
];
2334 memset(buf
, 0, LU_GROUP_NAME_BUF
);
2336 spin_lock(&lu_gp
->lu_gp_lock
);
2337 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
2338 dev
= lu_gp_mem
->lu_gp_mem_dev
;
2341 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
2342 config_item_name(&hba
->hba_group
.cg_item
),
2343 config_item_name(&dev
->dev_group
.cg_item
));
2344 cur_len
++; /* Extra byte for NULL terminator */
2346 if ((cur_len
+ len
) > PAGE_SIZE
) {
2347 pr_warn("Ran out of lu_gp_show_attr"
2348 "_members buffer\n");
2351 memcpy(page
+len
, buf
, cur_len
);
2354 spin_unlock(&lu_gp
->lu_gp_lock
);
2359 CONFIGFS_ATTR(target_lu_gp_
, lu_gp_id
);
2360 CONFIGFS_ATTR_RO(target_lu_gp_
, members
);
2362 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
2363 &target_lu_gp_attr_lu_gp_id
,
2364 &target_lu_gp_attr_members
,
2368 static void target_core_alua_lu_gp_release(struct config_item
*item
)
2370 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2371 struct t10_alua_lu_gp
, lu_gp_group
);
2373 core_alua_free_lu_gp(lu_gp
);
2376 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
2377 .release
= target_core_alua_lu_gp_release
,
2380 static const struct config_item_type target_core_alua_lu_gp_cit
= {
2381 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
2382 .ct_attrs
= target_core_alua_lu_gp_attrs
,
2383 .ct_owner
= THIS_MODULE
,
2386 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
2388 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
2390 static struct config_group
*target_core_alua_create_lu_gp(
2391 struct config_group
*group
,
2394 struct t10_alua_lu_gp
*lu_gp
;
2395 struct config_group
*alua_lu_gp_cg
= NULL
;
2396 struct config_item
*alua_lu_gp_ci
= NULL
;
2398 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
2402 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2403 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
2405 config_group_init_type_name(alua_lu_gp_cg
, name
,
2406 &target_core_alua_lu_gp_cit
);
2408 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2409 " Group: core/alua/lu_gps/%s\n",
2410 config_item_name(alua_lu_gp_ci
));
2412 return alua_lu_gp_cg
;
2416 static void target_core_alua_drop_lu_gp(
2417 struct config_group
*group
,
2418 struct config_item
*item
)
2420 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2421 struct t10_alua_lu_gp
, lu_gp_group
);
2423 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2424 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2425 config_item_name(item
), lu_gp
->lu_gp_id
);
2427 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
2428 * -> target_core_alua_lu_gp_release()
2430 config_item_put(item
);
2433 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
2434 .make_group
= &target_core_alua_create_lu_gp
,
2435 .drop_item
= &target_core_alua_drop_lu_gp
,
2438 static const struct config_item_type target_core_alua_lu_gps_cit
= {
2439 .ct_item_ops
= NULL
,
2440 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
2441 .ct_owner
= THIS_MODULE
,
2444 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
2446 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2448 static inline struct t10_alua_tg_pt_gp
*to_tg_pt_gp(struct config_item
*item
)
2450 return container_of(to_config_group(item
), struct t10_alua_tg_pt_gp
,
2454 static ssize_t
target_tg_pt_gp_alua_access_state_show(struct config_item
*item
,
2457 return sprintf(page
, "%d\n",
2458 to_tg_pt_gp(item
)->tg_pt_gp_alua_access_state
);
2461 static ssize_t
target_tg_pt_gp_alua_access_state_store(struct config_item
*item
,
2462 const char *page
, size_t count
)
2464 struct t10_alua_tg_pt_gp
*tg_pt_gp
= to_tg_pt_gp(item
);
2465 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
2469 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2470 pr_err("Unable to do implicit ALUA on non valid"
2471 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2474 if (!(dev
->dev_flags
& DF_CONFIGURED
)) {
2475 pr_err("Unable to set alua_access_state while device is"
2476 " not configured\n");
2480 ret
= kstrtoul(page
, 0, &tmp
);
2482 pr_err("Unable to extract new ALUA access state from"
2486 new_state
= (int)tmp
;
2488 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICIT_ALUA
)) {
2489 pr_err("Unable to process implicit configfs ALUA"
2490 " transition while TPGS_IMPLICIT_ALUA is disabled\n");
2493 if (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICIT_ALUA
&&
2494 new_state
== ALUA_ACCESS_STATE_LBA_DEPENDENT
) {
2495 /* LBA DEPENDENT is only allowed with implicit ALUA */
2496 pr_err("Unable to process implicit configfs ALUA transition"
2497 " while explicit ALUA management is enabled\n");
2501 ret
= core_alua_do_port_transition(tg_pt_gp
, dev
,
2502 NULL
, NULL
, new_state
, 0);
2503 return (!ret
) ? count
: -EINVAL
;
2506 static ssize_t
target_tg_pt_gp_alua_access_status_show(struct config_item
*item
,
2509 struct t10_alua_tg_pt_gp
*tg_pt_gp
= to_tg_pt_gp(item
);
2510 return sprintf(page
, "%s\n",
2511 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2514 static ssize_t
target_tg_pt_gp_alua_access_status_store(
2515 struct config_item
*item
, const char *page
, size_t count
)
2517 struct t10_alua_tg_pt_gp
*tg_pt_gp
= to_tg_pt_gp(item
);
2519 int new_status
, ret
;
2521 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2522 pr_err("Unable to do set ALUA access status on non"
2523 " valid tg_pt_gp ID: %hu\n",
2524 tg_pt_gp
->tg_pt_gp_valid_id
);
2528 ret
= kstrtoul(page
, 0, &tmp
);
2530 pr_err("Unable to extract new ALUA access status"
2531 " from %s\n", page
);
2534 new_status
= (int)tmp
;
2536 if ((new_status
!= ALUA_STATUS_NONE
) &&
2537 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG
) &&
2538 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA
)) {
2539 pr_err("Illegal ALUA access status: 0x%02x\n",
2544 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2548 static ssize_t
target_tg_pt_gp_alua_access_type_show(struct config_item
*item
,
2551 return core_alua_show_access_type(to_tg_pt_gp(item
), page
);
2554 static ssize_t
target_tg_pt_gp_alua_access_type_store(struct config_item
*item
,
2555 const char *page
, size_t count
)
2557 return core_alua_store_access_type(to_tg_pt_gp(item
), page
, count
);
2560 #define ALUA_SUPPORTED_STATE_ATTR(_name, _bit) \
2561 static ssize_t target_tg_pt_gp_alua_support_##_name##_show( \
2562 struct config_item *item, char *p) \
2564 struct t10_alua_tg_pt_gp *t = to_tg_pt_gp(item); \
2565 return sprintf(p, "%d\n", \
2566 !!(t->tg_pt_gp_alua_supported_states & _bit)); \
2569 static ssize_t target_tg_pt_gp_alua_support_##_name##_store( \
2570 struct config_item *item, const char *p, size_t c) \
2572 struct t10_alua_tg_pt_gp *t = to_tg_pt_gp(item); \
2573 unsigned long tmp; \
2576 if (!t->tg_pt_gp_valid_id) { \
2577 pr_err("Unable to do set " #_name " ALUA state on non" \
2578 " valid tg_pt_gp ID: %hu\n", \
2579 t->tg_pt_gp_valid_id); \
2583 ret = kstrtoul(p, 0, &tmp); \
2585 pr_err("Invalid value '%s', must be '0' or '1'\n", p); \
2589 pr_err("Invalid value '%ld', must be '0' or '1'\n", tmp); \
2593 t->tg_pt_gp_alua_supported_states |= _bit; \
2595 t->tg_pt_gp_alua_supported_states &= ~_bit; \
2600 ALUA_SUPPORTED_STATE_ATTR(transitioning
, ALUA_T_SUP
);
2601 ALUA_SUPPORTED_STATE_ATTR(offline
, ALUA_O_SUP
);
2602 ALUA_SUPPORTED_STATE_ATTR(lba_dependent
, ALUA_LBD_SUP
);
2603 ALUA_SUPPORTED_STATE_ATTR(unavailable
, ALUA_U_SUP
);
2604 ALUA_SUPPORTED_STATE_ATTR(standby
, ALUA_S_SUP
);
2605 ALUA_SUPPORTED_STATE_ATTR(active_optimized
, ALUA_AO_SUP
);
2606 ALUA_SUPPORTED_STATE_ATTR(active_nonoptimized
, ALUA_AN_SUP
);
2608 static ssize_t
target_tg_pt_gp_alua_write_metadata_show(
2609 struct config_item
*item
, char *page
)
2611 return sprintf(page
, "%d\n",
2612 to_tg_pt_gp(item
)->tg_pt_gp_write_metadata
);
2615 static ssize_t
target_tg_pt_gp_alua_write_metadata_store(
2616 struct config_item
*item
, const char *page
, size_t count
)
2618 struct t10_alua_tg_pt_gp
*tg_pt_gp
= to_tg_pt_gp(item
);
2622 ret
= kstrtoul(page
, 0, &tmp
);
2624 pr_err("Unable to extract alua_write_metadata\n");
2628 if ((tmp
!= 0) && (tmp
!= 1)) {
2629 pr_err("Illegal value for alua_write_metadata:"
2633 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2638 static ssize_t
target_tg_pt_gp_nonop_delay_msecs_show(struct config_item
*item
,
2641 return core_alua_show_nonop_delay_msecs(to_tg_pt_gp(item
), page
);
2644 static ssize_t
target_tg_pt_gp_nonop_delay_msecs_store(struct config_item
*item
,
2645 const char *page
, size_t count
)
2647 return core_alua_store_nonop_delay_msecs(to_tg_pt_gp(item
), page
,
2651 static ssize_t
target_tg_pt_gp_trans_delay_msecs_show(struct config_item
*item
,
2654 return core_alua_show_trans_delay_msecs(to_tg_pt_gp(item
), page
);
2657 static ssize_t
target_tg_pt_gp_trans_delay_msecs_store(struct config_item
*item
,
2658 const char *page
, size_t count
)
2660 return core_alua_store_trans_delay_msecs(to_tg_pt_gp(item
), page
,
2664 static ssize_t
target_tg_pt_gp_implicit_trans_secs_show(
2665 struct config_item
*item
, char *page
)
2667 return core_alua_show_implicit_trans_secs(to_tg_pt_gp(item
), page
);
2670 static ssize_t
target_tg_pt_gp_implicit_trans_secs_store(
2671 struct config_item
*item
, const char *page
, size_t count
)
2673 return core_alua_store_implicit_trans_secs(to_tg_pt_gp(item
), page
,
2677 static ssize_t
target_tg_pt_gp_preferred_show(struct config_item
*item
,
2680 return core_alua_show_preferred_bit(to_tg_pt_gp(item
), page
);
2683 static ssize_t
target_tg_pt_gp_preferred_store(struct config_item
*item
,
2684 const char *page
, size_t count
)
2686 return core_alua_store_preferred_bit(to_tg_pt_gp(item
), page
, count
);
2689 static ssize_t
target_tg_pt_gp_tg_pt_gp_id_show(struct config_item
*item
,
2692 struct t10_alua_tg_pt_gp
*tg_pt_gp
= to_tg_pt_gp(item
);
2694 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
2696 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2699 static ssize_t
target_tg_pt_gp_tg_pt_gp_id_store(struct config_item
*item
,
2700 const char *page
, size_t count
)
2702 struct t10_alua_tg_pt_gp
*tg_pt_gp
= to_tg_pt_gp(item
);
2703 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2704 unsigned long tg_pt_gp_id
;
2707 ret
= kstrtoul(page
, 0, &tg_pt_gp_id
);
2709 pr_err("ALUA tg_pt_gp_id: invalid value '%s' for tg_pt_gp_id\n",
2713 if (tg_pt_gp_id
> 0x0000ffff) {
2714 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum: 0x0000ffff\n",
2719 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2723 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
2724 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2725 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2726 tg_pt_gp
->tg_pt_gp_id
);
2731 static ssize_t
target_tg_pt_gp_members_show(struct config_item
*item
,
2734 struct t10_alua_tg_pt_gp
*tg_pt_gp
= to_tg_pt_gp(item
);
2736 ssize_t len
= 0, cur_len
;
2737 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2739 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2741 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2742 list_for_each_entry(lun
, &tg_pt_gp
->tg_pt_gp_lun_list
,
2743 lun_tg_pt_gp_link
) {
2744 struct se_portal_group
*tpg
= lun
->lun_tpg
;
2746 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2747 "/%s\n", tpg
->se_tpg_tfo
->get_fabric_name(),
2748 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
2749 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
2750 config_item_name(&lun
->lun_group
.cg_item
));
2751 cur_len
++; /* Extra byte for NULL terminator */
2753 if ((cur_len
+ len
) > PAGE_SIZE
) {
2754 pr_warn("Ran out of lu_gp_show_attr"
2755 "_members buffer\n");
2758 memcpy(page
+len
, buf
, cur_len
);
2761 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2766 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_access_state
);
2767 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_access_status
);
2768 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_access_type
);
2769 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_support_transitioning
);
2770 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_support_offline
);
2771 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_support_lba_dependent
);
2772 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_support_unavailable
);
2773 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_support_standby
);
2774 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_support_active_optimized
);
2775 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_support_active_nonoptimized
);
2776 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_write_metadata
);
2777 CONFIGFS_ATTR(target_tg_pt_gp_
, nonop_delay_msecs
);
2778 CONFIGFS_ATTR(target_tg_pt_gp_
, trans_delay_msecs
);
2779 CONFIGFS_ATTR(target_tg_pt_gp_
, implicit_trans_secs
);
2780 CONFIGFS_ATTR(target_tg_pt_gp_
, preferred
);
2781 CONFIGFS_ATTR(target_tg_pt_gp_
, tg_pt_gp_id
);
2782 CONFIGFS_ATTR_RO(target_tg_pt_gp_
, members
);
2784 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2785 &target_tg_pt_gp_attr_alua_access_state
,
2786 &target_tg_pt_gp_attr_alua_access_status
,
2787 &target_tg_pt_gp_attr_alua_access_type
,
2788 &target_tg_pt_gp_attr_alua_support_transitioning
,
2789 &target_tg_pt_gp_attr_alua_support_offline
,
2790 &target_tg_pt_gp_attr_alua_support_lba_dependent
,
2791 &target_tg_pt_gp_attr_alua_support_unavailable
,
2792 &target_tg_pt_gp_attr_alua_support_standby
,
2793 &target_tg_pt_gp_attr_alua_support_active_nonoptimized
,
2794 &target_tg_pt_gp_attr_alua_support_active_optimized
,
2795 &target_tg_pt_gp_attr_alua_write_metadata
,
2796 &target_tg_pt_gp_attr_nonop_delay_msecs
,
2797 &target_tg_pt_gp_attr_trans_delay_msecs
,
2798 &target_tg_pt_gp_attr_implicit_trans_secs
,
2799 &target_tg_pt_gp_attr_preferred
,
2800 &target_tg_pt_gp_attr_tg_pt_gp_id
,
2801 &target_tg_pt_gp_attr_members
,
2805 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2807 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2808 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2810 core_alua_free_tg_pt_gp(tg_pt_gp
);
2813 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2814 .release
= target_core_alua_tg_pt_gp_release
,
2817 static const struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2818 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2819 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2820 .ct_owner
= THIS_MODULE
,
2823 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2825 /* Start functions for struct config_item_type tb_alua_tg_pt_gps_cit */
2827 static struct config_group
*target_core_alua_create_tg_pt_gp(
2828 struct config_group
*group
,
2831 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2832 alua_tg_pt_gps_group
);
2833 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2834 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2835 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2837 tg_pt_gp
= core_alua_allocate_tg_pt_gp(alua
->t10_dev
, name
, 0);
2841 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2842 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2844 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2845 &target_core_alua_tg_pt_gp_cit
);
2847 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
2848 " Group: alua/tg_pt_gps/%s\n",
2849 config_item_name(alua_tg_pt_gp_ci
));
2851 return alua_tg_pt_gp_cg
;
2854 static void target_core_alua_drop_tg_pt_gp(
2855 struct config_group
*group
,
2856 struct config_item
*item
)
2858 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2859 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2861 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
2862 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2863 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2865 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2866 * -> target_core_alua_tg_pt_gp_release().
2868 config_item_put(item
);
2871 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2872 .make_group
= &target_core_alua_create_tg_pt_gp
,
2873 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2876 TB_CIT_SETUP(dev_alua_tg_pt_gps
, NULL
, &target_core_alua_tg_pt_gps_group_ops
, NULL
);
2878 /* End functions for struct config_item_type tb_alua_tg_pt_gps_cit */
2880 /* Start functions for struct config_item_type target_core_alua_cit */
2883 * target_core_alua_cit is a ConfigFS group that lives under
2884 * /sys/kernel/config/target/core/alua. There are default groups
2885 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2886 * target_core_alua_cit in target_core_init_configfs() below.
2888 static const struct config_item_type target_core_alua_cit
= {
2889 .ct_item_ops
= NULL
,
2891 .ct_owner
= THIS_MODULE
,
2894 /* End functions for struct config_item_type target_core_alua_cit */
2896 /* Start functions for struct config_item_type tb_dev_stat_cit */
2898 static struct config_group
*target_core_stat_mkdir(
2899 struct config_group
*group
,
2902 return ERR_PTR(-ENOSYS
);
2905 static void target_core_stat_rmdir(
2906 struct config_group
*group
,
2907 struct config_item
*item
)
2912 static struct configfs_group_operations target_core_stat_group_ops
= {
2913 .make_group
= &target_core_stat_mkdir
,
2914 .drop_item
= &target_core_stat_rmdir
,
2917 TB_CIT_SETUP(dev_stat
, NULL
, &target_core_stat_group_ops
, NULL
);
2919 /* End functions for struct config_item_type tb_dev_stat_cit */
2921 /* Start functions for struct config_item_type target_core_hba_cit */
2923 static struct config_group
*target_core_make_subdev(
2924 struct config_group
*group
,
2927 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2928 struct config_item
*hba_ci
= &group
->cg_item
;
2929 struct se_hba
*hba
= item_to_hba(hba_ci
);
2930 struct target_backend
*tb
= hba
->backend
;
2931 struct se_device
*dev
;
2932 int errno
= -ENOMEM
, ret
;
2934 ret
= mutex_lock_interruptible(&hba
->hba_access_mutex
);
2936 return ERR_PTR(ret
);
2938 dev
= target_alloc_device(hba
, name
);
2942 config_group_init_type_name(&dev
->dev_group
, name
, &tb
->tb_dev_cit
);
2944 config_group_init_type_name(&dev
->dev_action_group
, "action",
2945 &tb
->tb_dev_action_cit
);
2946 configfs_add_default_group(&dev
->dev_action_group
, &dev
->dev_group
);
2948 config_group_init_type_name(&dev
->dev_attrib
.da_group
, "attrib",
2949 &tb
->tb_dev_attrib_cit
);
2950 configfs_add_default_group(&dev
->dev_attrib
.da_group
, &dev
->dev_group
);
2952 config_group_init_type_name(&dev
->dev_pr_group
, "pr",
2953 &tb
->tb_dev_pr_cit
);
2954 configfs_add_default_group(&dev
->dev_pr_group
, &dev
->dev_group
);
2956 config_group_init_type_name(&dev
->t10_wwn
.t10_wwn_group
, "wwn",
2957 &tb
->tb_dev_wwn_cit
);
2958 configfs_add_default_group(&dev
->t10_wwn
.t10_wwn_group
,
2961 config_group_init_type_name(&dev
->t10_alua
.alua_tg_pt_gps_group
,
2962 "alua", &tb
->tb_dev_alua_tg_pt_gps_cit
);
2963 configfs_add_default_group(&dev
->t10_alua
.alua_tg_pt_gps_group
,
2966 config_group_init_type_name(&dev
->dev_stat_grps
.stat_group
,
2967 "statistics", &tb
->tb_dev_stat_cit
);
2968 configfs_add_default_group(&dev
->dev_stat_grps
.stat_group
,
2972 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
2974 tg_pt_gp
= core_alua_allocate_tg_pt_gp(dev
, "default_tg_pt_gp", 1);
2976 goto out_free_device
;
2977 dev
->t10_alua
.default_tg_pt_gp
= tg_pt_gp
;
2979 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2980 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2981 configfs_add_default_group(&tg_pt_gp
->tg_pt_gp_group
,
2982 &dev
->t10_alua
.alua_tg_pt_gps_group
);
2985 * Add core/$HBA/$DEV/statistics/ default groups
2987 target_stat_setup_dev_default_groups(dev
);
2989 mutex_unlock(&hba
->hba_access_mutex
);
2990 return &dev
->dev_group
;
2993 target_free_device(dev
);
2995 mutex_unlock(&hba
->hba_access_mutex
);
2996 return ERR_PTR(errno
);
2999 static void target_core_drop_subdev(
3000 struct config_group
*group
,
3001 struct config_item
*item
)
3003 struct config_group
*dev_cg
= to_config_group(item
);
3004 struct se_device
*dev
=
3005 container_of(dev_cg
, struct se_device
, dev_group
);
3008 hba
= item_to_hba(&dev
->se_hba
->hba_group
.cg_item
);
3010 mutex_lock(&hba
->hba_access_mutex
);
3012 configfs_remove_default_groups(&dev
->dev_stat_grps
.stat_group
);
3013 configfs_remove_default_groups(&dev
->t10_alua
.alua_tg_pt_gps_group
);
3016 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
3017 * directly from target_core_alua_tg_pt_gp_release().
3019 dev
->t10_alua
.default_tg_pt_gp
= NULL
;
3021 configfs_remove_default_groups(dev_cg
);
3024 * se_dev is released from target_core_dev_item_ops->release()
3026 config_item_put(item
);
3027 mutex_unlock(&hba
->hba_access_mutex
);
3030 static struct configfs_group_operations target_core_hba_group_ops
= {
3031 .make_group
= target_core_make_subdev
,
3032 .drop_item
= target_core_drop_subdev
,
3036 static inline struct se_hba
*to_hba(struct config_item
*item
)
3038 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
3041 static ssize_t
target_hba_info_show(struct config_item
*item
, char *page
)
3043 struct se_hba
*hba
= to_hba(item
);
3045 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
3046 hba
->hba_id
, hba
->backend
->ops
->name
,
3047 TARGET_CORE_VERSION
);
3050 static ssize_t
target_hba_mode_show(struct config_item
*item
, char *page
)
3052 struct se_hba
*hba
= to_hba(item
);
3055 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
3058 return sprintf(page
, "%d\n", hba_mode
);
3061 static ssize_t
target_hba_mode_store(struct config_item
*item
,
3062 const char *page
, size_t count
)
3064 struct se_hba
*hba
= to_hba(item
);
3065 unsigned long mode_flag
;
3068 if (hba
->backend
->ops
->pmode_enable_hba
== NULL
)
3071 ret
= kstrtoul(page
, 0, &mode_flag
);
3073 pr_err("Unable to extract hba mode flag: %d\n", ret
);
3077 if (hba
->dev_count
) {
3078 pr_err("Unable to set hba_mode with active devices\n");
3082 ret
= hba
->backend
->ops
->pmode_enable_hba(hba
, mode_flag
);
3086 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
3088 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
3093 CONFIGFS_ATTR_RO(target_
, hba_info
);
3094 CONFIGFS_ATTR(target_
, hba_mode
);
3096 static void target_core_hba_release(struct config_item
*item
)
3098 struct se_hba
*hba
= container_of(to_config_group(item
),
3099 struct se_hba
, hba_group
);
3100 core_delete_hba(hba
);
3103 static struct configfs_attribute
*target_core_hba_attrs
[] = {
3104 &target_attr_hba_info
,
3105 &target_attr_hba_mode
,
3109 static struct configfs_item_operations target_core_hba_item_ops
= {
3110 .release
= target_core_hba_release
,
3113 static const struct config_item_type target_core_hba_cit
= {
3114 .ct_item_ops
= &target_core_hba_item_ops
,
3115 .ct_group_ops
= &target_core_hba_group_ops
,
3116 .ct_attrs
= target_core_hba_attrs
,
3117 .ct_owner
= THIS_MODULE
,
3120 static struct config_group
*target_core_call_addhbatotarget(
3121 struct config_group
*group
,
3124 char *se_plugin_str
, *str
, *str2
;
3126 char buf
[TARGET_CORE_NAME_MAX_LEN
];
3127 unsigned long plugin_dep_id
= 0;
3130 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
3131 if (strlen(name
) >= TARGET_CORE_NAME_MAX_LEN
) {
3132 pr_err("Passed *name strlen(): %d exceeds"
3133 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
3134 TARGET_CORE_NAME_MAX_LEN
);
3135 return ERR_PTR(-ENAMETOOLONG
);
3137 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
3139 str
= strstr(buf
, "_");
3141 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
3142 return ERR_PTR(-EINVAL
);
3144 se_plugin_str
= buf
;
3146 * Special case for subsystem plugins that have "_" in their names.
3147 * Namely rd_direct and rd_mcp..
3149 str2
= strstr(str
+1, "_");
3151 *str2
= '\0'; /* Terminate for *se_plugin_str */
3152 str2
++; /* Skip to start of plugin dependent ID */
3155 *str
= '\0'; /* Terminate for *se_plugin_str */
3156 str
++; /* Skip to start of plugin dependent ID */
3159 ret
= kstrtoul(str
, 0, &plugin_dep_id
);
3161 pr_err("kstrtoul() returned %d for"
3162 " plugin_dep_id\n", ret
);
3163 return ERR_PTR(ret
);
3166 * Load up TCM subsystem plugins if they have not already been loaded.
3168 transport_subsystem_check_init();
3170 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
3172 return ERR_CAST(hba
);
3174 config_group_init_type_name(&hba
->hba_group
, name
,
3175 &target_core_hba_cit
);
3177 return &hba
->hba_group
;
3180 static void target_core_call_delhbafromtarget(
3181 struct config_group
*group
,
3182 struct config_item
*item
)
3185 * core_delete_hba() is called from target_core_hba_item_ops->release()
3186 * -> target_core_hba_release()
3188 config_item_put(item
);
3191 static struct configfs_group_operations target_core_group_ops
= {
3192 .make_group
= target_core_call_addhbatotarget
,
3193 .drop_item
= target_core_call_delhbafromtarget
,
3196 static const struct config_item_type target_core_cit
= {
3197 .ct_item_ops
= NULL
,
3198 .ct_group_ops
= &target_core_group_ops
,
3200 .ct_owner
= THIS_MODULE
,
3203 /* Stop functions for struct config_item_type target_core_hba_cit */
3205 void target_setup_backend_cits(struct target_backend
*tb
)
3207 target_core_setup_dev_cit(tb
);
3208 target_core_setup_dev_action_cit(tb
);
3209 target_core_setup_dev_attrib_cit(tb
);
3210 target_core_setup_dev_pr_cit(tb
);
3211 target_core_setup_dev_wwn_cit(tb
);
3212 target_core_setup_dev_alua_tg_pt_gps_cit(tb
);
3213 target_core_setup_dev_stat_cit(tb
);
3216 static int __init
target_core_init_configfs(void)
3218 struct configfs_subsystem
*subsys
= &target_core_fabrics
;
3219 struct t10_alua_lu_gp
*lu_gp
;
3222 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
3223 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
3224 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
3226 config_group_init(&subsys
->su_group
);
3227 mutex_init(&subsys
->su_mutex
);
3229 ret
= init_se_kmem_caches();
3233 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
3234 * and ALUA Logical Unit Group and Target Port Group infrastructure.
3236 config_group_init_type_name(&target_core_hbagroup
, "core",
3238 configfs_add_default_group(&target_core_hbagroup
, &subsys
->su_group
);
3241 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
3243 config_group_init_type_name(&alua_group
, "alua", &target_core_alua_cit
);
3244 configfs_add_default_group(&alua_group
, &target_core_hbagroup
);
3247 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
3248 * groups under /sys/kernel/config/target/core/alua/
3250 config_group_init_type_name(&alua_lu_gps_group
, "lu_gps",
3251 &target_core_alua_lu_gps_cit
);
3252 configfs_add_default_group(&alua_lu_gps_group
, &alua_group
);
3255 * Add core/alua/lu_gps/default_lu_gp
3257 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
3258 if (IS_ERR(lu_gp
)) {
3263 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
3264 &target_core_alua_lu_gp_cit
);
3265 configfs_add_default_group(&lu_gp
->lu_gp_group
, &alua_lu_gps_group
);
3267 default_lu_gp
= lu_gp
;
3270 * Register the target_core_mod subsystem with configfs.
3272 ret
= configfs_register_subsystem(subsys
);
3274 pr_err("Error %d while registering subsystem %s\n",
3275 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
3278 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
3279 " Infrastructure: "TARGET_CORE_VERSION
" on %s/%s"
3280 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
3282 * Register built-in RAMDISK subsystem logic for virtual LUN 0
3284 ret
= rd_module_init();
3288 ret
= core_dev_setup_virtual_lun0();
3292 ret
= target_xcopy_setup_pt();
3299 configfs_unregister_subsystem(subsys
);
3300 core_dev_release_virtual_lun0();
3303 if (default_lu_gp
) {
3304 core_alua_free_lu_gp(default_lu_gp
);
3305 default_lu_gp
= NULL
;
3307 release_se_kmem_caches();
3311 static void __exit
target_core_exit_configfs(void)
3313 configfs_remove_default_groups(&alua_lu_gps_group
);
3314 configfs_remove_default_groups(&alua_group
);
3315 configfs_remove_default_groups(&target_core_hbagroup
);
3318 * We expect subsys->su_group.default_groups to be released
3319 * by configfs subsystem provider logic..
3321 configfs_unregister_subsystem(&target_core_fabrics
);
3323 core_alua_free_lu_gp(default_lu_gp
);
3324 default_lu_gp
= NULL
;
3326 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
3327 " Infrastructure\n");
3329 core_dev_release_virtual_lun0();
3331 target_xcopy_release_pt();
3332 release_se_kmem_caches();
3335 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3336 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3337 MODULE_LICENSE("GPL");
3339 module_init(target_core_init_configfs
);
3340 module_exit(target_core_exit_configfs
);