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 static struct target_fabric_configfs
*target_core_get_fabric(
105 struct target_fabric_configfs
*tf
;
110 mutex_lock(&g_tf_lock
);
111 list_for_each_entry(tf
, &g_tf_list
, tf_list
) {
112 if (!strcmp(tf
->tf_ops
->name
, name
)) {
113 atomic_inc(&tf
->tf_access_cnt
);
114 mutex_unlock(&g_tf_lock
);
118 mutex_unlock(&g_tf_lock
);
124 * Called from struct target_core_group_ops->make_group()
126 static struct config_group
*target_core_register_fabric(
127 struct config_group
*group
,
130 struct target_fabric_configfs
*tf
;
133 pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:"
134 " %s\n", group
, name
);
136 tf
= target_core_get_fabric(name
);
138 pr_debug("target_core_register_fabric() trying autoload for %s\n",
142 * Below are some hardcoded request_module() calls to automatically
143 * local fabric modules when the following is called:
145 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
147 * Note that this does not limit which TCM fabric module can be
148 * registered, but simply provids auto loading logic for modules with
149 * mkdir(2) system calls with known TCM fabric modules.
152 if (!strncmp(name
, "iscsi", 5)) {
154 * Automatically load the LIO Target fabric module when the
155 * following is called:
157 * mkdir -p $CONFIGFS/target/iscsi
159 ret
= request_module("iscsi_target_mod");
161 pr_debug("request_module() failed for"
162 " iscsi_target_mod.ko: %d\n", ret
);
163 return ERR_PTR(-EINVAL
);
165 } else if (!strncmp(name
, "loopback", 8)) {
167 * Automatically load the tcm_loop fabric module when the
168 * following is called:
170 * mkdir -p $CONFIGFS/target/loopback
172 ret
= request_module("tcm_loop");
174 pr_debug("request_module() failed for"
175 " tcm_loop.ko: %d\n", ret
);
176 return ERR_PTR(-EINVAL
);
180 tf
= target_core_get_fabric(name
);
184 pr_debug("target_core_get_fabric() failed for %s\n",
186 return ERR_PTR(-EINVAL
);
188 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
189 " %s\n", tf
->tf_ops
->name
);
191 * On a successful target_core_get_fabric() look, the returned
192 * struct target_fabric_configfs *tf will contain a usage reference.
194 pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
197 config_group_init_type_name(&tf
->tf_group
, name
, &tf
->tf_wwn_cit
);
199 config_group_init_type_name(&tf
->tf_disc_group
, "discovery_auth",
200 &tf
->tf_discovery_cit
);
201 configfs_add_default_group(&tf
->tf_disc_group
, &tf
->tf_group
);
203 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
204 " %s\n", tf
->tf_group
.cg_item
.ci_name
);
205 return &tf
->tf_group
;
209 * Called from struct target_core_group_ops->drop_item()
211 static void target_core_deregister_fabric(
212 struct config_group
*group
,
213 struct config_item
*item
)
215 struct target_fabric_configfs
*tf
= container_of(
216 to_config_group(item
), struct target_fabric_configfs
, tf_group
);
218 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
219 " tf list\n", config_item_name(item
));
221 pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:"
222 " %s\n", tf
->tf_ops
->name
);
223 atomic_dec(&tf
->tf_access_cnt
);
225 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
226 " %s\n", config_item_name(item
));
228 configfs_remove_default_groups(&tf
->tf_group
);
229 config_item_put(item
);
232 static struct configfs_group_operations target_core_fabric_group_ops
= {
233 .make_group
= &target_core_register_fabric
,
234 .drop_item
= &target_core_deregister_fabric
,
238 * All item attributes appearing in /sys/kernel/target/ appear here.
240 static struct configfs_attribute
*target_core_fabric_item_attrs
[] = {
241 &target_core_item_attr_version
,
246 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
248 static struct config_item_type target_core_fabrics_item
= {
249 .ct_group_ops
= &target_core_fabric_group_ops
,
250 .ct_attrs
= target_core_fabric_item_attrs
,
251 .ct_owner
= THIS_MODULE
,
254 static struct configfs_subsystem target_core_fabrics
= {
257 .ci_namebuf
= "target",
258 .ci_type
= &target_core_fabrics_item
,
263 int target_depend_item(struct config_item
*item
)
265 return configfs_depend_item(&target_core_fabrics
, item
);
267 EXPORT_SYMBOL(target_depend_item
);
269 void target_undepend_item(struct config_item
*item
)
271 return configfs_undepend_item(item
);
273 EXPORT_SYMBOL(target_undepend_item
);
275 /*##############################################################################
276 // Start functions called by external Target Fabrics Modules
277 //############################################################################*/
279 static int target_fabric_tf_ops_check(const struct target_core_fabric_ops
*tfo
)
282 pr_err("Missing tfo->name\n");
285 if (strlen(tfo
->name
) >= TARGET_FABRIC_NAME_SIZE
) {
286 pr_err("Passed name: %s exceeds TARGET_FABRIC"
287 "_NAME_SIZE\n", tfo
->name
);
290 if (!tfo
->get_fabric_name
) {
291 pr_err("Missing tfo->get_fabric_name()\n");
294 if (!tfo
->tpg_get_wwn
) {
295 pr_err("Missing tfo->tpg_get_wwn()\n");
298 if (!tfo
->tpg_get_tag
) {
299 pr_err("Missing tfo->tpg_get_tag()\n");
302 if (!tfo
->tpg_check_demo_mode
) {
303 pr_err("Missing tfo->tpg_check_demo_mode()\n");
306 if (!tfo
->tpg_check_demo_mode_cache
) {
307 pr_err("Missing tfo->tpg_check_demo_mode_cache()\n");
310 if (!tfo
->tpg_check_demo_mode_write_protect
) {
311 pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n");
314 if (!tfo
->tpg_check_prod_mode_write_protect
) {
315 pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n");
318 if (!tfo
->tpg_get_inst_index
) {
319 pr_err("Missing tfo->tpg_get_inst_index()\n");
322 if (!tfo
->release_cmd
) {
323 pr_err("Missing tfo->release_cmd()\n");
326 if (!tfo
->shutdown_session
) {
327 pr_err("Missing tfo->shutdown_session()\n");
330 if (!tfo
->close_session
) {
331 pr_err("Missing tfo->close_session()\n");
334 if (!tfo
->sess_get_index
) {
335 pr_err("Missing tfo->sess_get_index()\n");
338 if (!tfo
->write_pending
) {
339 pr_err("Missing tfo->write_pending()\n");
342 if (!tfo
->write_pending_status
) {
343 pr_err("Missing tfo->write_pending_status()\n");
346 if (!tfo
->set_default_node_attributes
) {
347 pr_err("Missing tfo->set_default_node_attributes()\n");
350 if (!tfo
->get_cmd_state
) {
351 pr_err("Missing tfo->get_cmd_state()\n");
354 if (!tfo
->queue_data_in
) {
355 pr_err("Missing tfo->queue_data_in()\n");
358 if (!tfo
->queue_status
) {
359 pr_err("Missing tfo->queue_status()\n");
362 if (!tfo
->queue_tm_rsp
) {
363 pr_err("Missing tfo->queue_tm_rsp()\n");
366 if (!tfo
->aborted_task
) {
367 pr_err("Missing tfo->aborted_task()\n");
371 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
372 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
373 * target_core_fabric_configfs.c WWN+TPG group context code.
375 if (!tfo
->fabric_make_wwn
) {
376 pr_err("Missing tfo->fabric_make_wwn()\n");
379 if (!tfo
->fabric_drop_wwn
) {
380 pr_err("Missing tfo->fabric_drop_wwn()\n");
383 if (!tfo
->fabric_make_tpg
) {
384 pr_err("Missing tfo->fabric_make_tpg()\n");
387 if (!tfo
->fabric_drop_tpg
) {
388 pr_err("Missing tfo->fabric_drop_tpg()\n");
395 int target_register_template(const struct target_core_fabric_ops
*fo
)
397 struct target_fabric_configfs
*tf
;
400 ret
= target_fabric_tf_ops_check(fo
);
404 tf
= kzalloc(sizeof(struct target_fabric_configfs
), GFP_KERNEL
);
406 pr_err("%s: could not allocate memory!\n", __func__
);
410 INIT_LIST_HEAD(&tf
->tf_list
);
411 atomic_set(&tf
->tf_access_cnt
, 0);
413 target_fabric_setup_cits(tf
);
415 mutex_lock(&g_tf_lock
);
416 list_add_tail(&tf
->tf_list
, &g_tf_list
);
417 mutex_unlock(&g_tf_lock
);
421 EXPORT_SYMBOL(target_register_template
);
423 void target_unregister_template(const struct target_core_fabric_ops
*fo
)
425 struct target_fabric_configfs
*t
;
427 mutex_lock(&g_tf_lock
);
428 list_for_each_entry(t
, &g_tf_list
, tf_list
) {
429 if (!strcmp(t
->tf_ops
->name
, fo
->name
)) {
430 BUG_ON(atomic_read(&t
->tf_access_cnt
));
431 list_del(&t
->tf_list
);
432 mutex_unlock(&g_tf_lock
);
434 * Wait for any outstanding fabric se_deve_entry->rcu_head
435 * callbacks to complete post kfree_rcu(), before allowing
436 * fabric driver unload of TFO->module to proceed.
443 mutex_unlock(&g_tf_lock
);
445 EXPORT_SYMBOL(target_unregister_template
);
447 /*##############################################################################
448 // Stop functions called by external Target Fabrics Modules
449 //############################################################################*/
451 static inline struct se_dev_attrib
*to_attrib(struct config_item
*item
)
453 return container_of(to_config_group(item
), struct se_dev_attrib
,
457 /* Start functions for struct config_item_type tb_dev_attrib_cit */
458 #define DEF_CONFIGFS_ATTRIB_SHOW(_name) \
459 static ssize_t _name##_show(struct config_item *item, char *page) \
461 return snprintf(page, PAGE_SIZE, "%u\n", to_attrib(item)->_name); \
464 DEF_CONFIGFS_ATTRIB_SHOW(emulate_model_alias
);
465 DEF_CONFIGFS_ATTRIB_SHOW(emulate_dpo
);
466 DEF_CONFIGFS_ATTRIB_SHOW(emulate_fua_write
);
467 DEF_CONFIGFS_ATTRIB_SHOW(emulate_fua_read
);
468 DEF_CONFIGFS_ATTRIB_SHOW(emulate_write_cache
);
469 DEF_CONFIGFS_ATTRIB_SHOW(emulate_ua_intlck_ctrl
);
470 DEF_CONFIGFS_ATTRIB_SHOW(emulate_tas
);
471 DEF_CONFIGFS_ATTRIB_SHOW(emulate_tpu
);
472 DEF_CONFIGFS_ATTRIB_SHOW(emulate_tpws
);
473 DEF_CONFIGFS_ATTRIB_SHOW(emulate_caw
);
474 DEF_CONFIGFS_ATTRIB_SHOW(emulate_3pc
);
475 DEF_CONFIGFS_ATTRIB_SHOW(pi_prot_type
);
476 DEF_CONFIGFS_ATTRIB_SHOW(hw_pi_prot_type
);
477 DEF_CONFIGFS_ATTRIB_SHOW(pi_prot_format
);
478 DEF_CONFIGFS_ATTRIB_SHOW(enforce_pr_isids
);
479 DEF_CONFIGFS_ATTRIB_SHOW(is_nonrot
);
480 DEF_CONFIGFS_ATTRIB_SHOW(emulate_rest_reord
);
481 DEF_CONFIGFS_ATTRIB_SHOW(force_pr_aptpl
);
482 DEF_CONFIGFS_ATTRIB_SHOW(hw_block_size
);
483 DEF_CONFIGFS_ATTRIB_SHOW(block_size
);
484 DEF_CONFIGFS_ATTRIB_SHOW(hw_max_sectors
);
485 DEF_CONFIGFS_ATTRIB_SHOW(optimal_sectors
);
486 DEF_CONFIGFS_ATTRIB_SHOW(hw_queue_depth
);
487 DEF_CONFIGFS_ATTRIB_SHOW(queue_depth
);
488 DEF_CONFIGFS_ATTRIB_SHOW(max_unmap_lba_count
);
489 DEF_CONFIGFS_ATTRIB_SHOW(max_unmap_block_desc_count
);
490 DEF_CONFIGFS_ATTRIB_SHOW(unmap_granularity
);
491 DEF_CONFIGFS_ATTRIB_SHOW(unmap_granularity_alignment
);
492 DEF_CONFIGFS_ATTRIB_SHOW(unmap_zeroes_data
);
493 DEF_CONFIGFS_ATTRIB_SHOW(max_write_same_len
);
495 #define DEF_CONFIGFS_ATTRIB_STORE_U32(_name) \
496 static ssize_t _name##_store(struct config_item *item, const char *page,\
499 struct se_dev_attrib *da = to_attrib(item); \
503 ret = kstrtou32(page, 0, &val); \
510 DEF_CONFIGFS_ATTRIB_STORE_U32(max_unmap_lba_count
);
511 DEF_CONFIGFS_ATTRIB_STORE_U32(max_unmap_block_desc_count
);
512 DEF_CONFIGFS_ATTRIB_STORE_U32(unmap_granularity
);
513 DEF_CONFIGFS_ATTRIB_STORE_U32(unmap_granularity_alignment
);
514 DEF_CONFIGFS_ATTRIB_STORE_U32(max_write_same_len
);
516 #define DEF_CONFIGFS_ATTRIB_STORE_BOOL(_name) \
517 static ssize_t _name##_store(struct config_item *item, const char *page, \
520 struct se_dev_attrib *da = to_attrib(item); \
524 ret = strtobool(page, &flag); \
531 DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_fua_write
);
532 DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_caw
);
533 DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_3pc
);
534 DEF_CONFIGFS_ATTRIB_STORE_BOOL(enforce_pr_isids
);
535 DEF_CONFIGFS_ATTRIB_STORE_BOOL(is_nonrot
);
537 #define DEF_CONFIGFS_ATTRIB_STORE_STUB(_name) \
538 static ssize_t _name##_store(struct config_item *item, const char *page,\
541 printk_once(KERN_WARNING \
542 "ignoring deprecated %s attribute\n", \
543 __stringify(_name)); \
547 DEF_CONFIGFS_ATTRIB_STORE_STUB(emulate_dpo
);
548 DEF_CONFIGFS_ATTRIB_STORE_STUB(emulate_fua_read
);
550 static void dev_set_t10_wwn_model_alias(struct se_device
*dev
)
552 const char *configname
;
554 configname
= config_item_name(&dev
->dev_group
.cg_item
);
555 if (strlen(configname
) >= 16) {
556 pr_warn("dev[%p]: Backstore name '%s' is too long for "
557 "INQUIRY_MODEL, truncating to 16 bytes\n", dev
,
560 snprintf(&dev
->t10_wwn
.model
[0], 16, "%s", configname
);
563 static ssize_t
emulate_model_alias_store(struct config_item
*item
,
564 const char *page
, size_t count
)
566 struct se_dev_attrib
*da
= to_attrib(item
);
567 struct se_device
*dev
= da
->da_dev
;
571 if (dev
->export_count
) {
572 pr_err("dev[%p]: Unable to change model alias"
573 " while export_count is %d\n",
574 dev
, dev
->export_count
);
578 ret
= strtobool(page
, &flag
);
583 dev_set_t10_wwn_model_alias(dev
);
585 strncpy(&dev
->t10_wwn
.model
[0],
586 dev
->transport
->inquiry_prod
, 16);
588 da
->emulate_model_alias
= flag
;
592 static ssize_t
emulate_write_cache_store(struct config_item
*item
,
593 const char *page
, size_t count
)
595 struct se_dev_attrib
*da
= to_attrib(item
);
599 ret
= strtobool(page
, &flag
);
603 if (flag
&& da
->da_dev
->transport
->get_write_cache
) {
604 pr_err("emulate_write_cache not supported for this device\n");
608 da
->emulate_write_cache
= flag
;
609 pr_debug("dev[%p]: SE Device WRITE_CACHE_EMULATION flag: %d\n",
614 static ssize_t
emulate_ua_intlck_ctrl_store(struct config_item
*item
,
615 const char *page
, size_t count
)
617 struct se_dev_attrib
*da
= to_attrib(item
);
621 ret
= kstrtou32(page
, 0, &val
);
625 if (val
!= 0 && val
!= 1 && val
!= 2) {
626 pr_err("Illegal value %d\n", val
);
630 if (da
->da_dev
->export_count
) {
631 pr_err("dev[%p]: Unable to change SE Device"
632 " UA_INTRLCK_CTRL while export_count is %d\n",
633 da
->da_dev
, da
->da_dev
->export_count
);
636 da
->emulate_ua_intlck_ctrl
= val
;
637 pr_debug("dev[%p]: SE Device UA_INTRLCK_CTRL flag: %d\n",
642 static ssize_t
emulate_tas_store(struct config_item
*item
,
643 const char *page
, size_t count
)
645 struct se_dev_attrib
*da
= to_attrib(item
);
649 ret
= strtobool(page
, &flag
);
653 if (da
->da_dev
->export_count
) {
654 pr_err("dev[%p]: Unable to change SE Device TAS while"
655 " export_count is %d\n",
656 da
->da_dev
, da
->da_dev
->export_count
);
659 da
->emulate_tas
= flag
;
660 pr_debug("dev[%p]: SE Device TASK_ABORTED status bit: %s\n",
661 da
->da_dev
, flag
? "Enabled" : "Disabled");
666 static ssize_t
emulate_tpu_store(struct config_item
*item
,
667 const char *page
, size_t count
)
669 struct se_dev_attrib
*da
= to_attrib(item
);
673 ret
= strtobool(page
, &flag
);
678 * We expect this value to be non-zero when generic Block Layer
679 * Discard supported is detected iblock_create_virtdevice().
681 if (flag
&& !da
->max_unmap_block_desc_count
) {
682 pr_err("Generic Block Discard not supported\n");
686 da
->emulate_tpu
= flag
;
687 pr_debug("dev[%p]: SE Device Thin Provisioning UNMAP bit: %d\n",
692 static ssize_t
emulate_tpws_store(struct config_item
*item
,
693 const char *page
, size_t count
)
695 struct se_dev_attrib
*da
= to_attrib(item
);
699 ret
= strtobool(page
, &flag
);
704 * We expect this value to be non-zero when generic Block Layer
705 * Discard supported is detected iblock_create_virtdevice().
707 if (flag
&& !da
->max_unmap_block_desc_count
) {
708 pr_err("Generic Block Discard not supported\n");
712 da
->emulate_tpws
= flag
;
713 pr_debug("dev[%p]: SE Device Thin Provisioning WRITE_SAME: %d\n",
718 static ssize_t
pi_prot_type_store(struct config_item
*item
,
719 const char *page
, size_t count
)
721 struct se_dev_attrib
*da
= to_attrib(item
);
722 int old_prot
= da
->pi_prot_type
, ret
;
723 struct se_device
*dev
= da
->da_dev
;
726 ret
= kstrtou32(page
, 0, &flag
);
730 if (flag
!= 0 && flag
!= 1 && flag
!= 2 && flag
!= 3) {
731 pr_err("Illegal value %d for pi_prot_type\n", flag
);
735 pr_err("DIF TYPE2 protection currently not supported\n");
738 if (da
->hw_pi_prot_type
) {
739 pr_warn("DIF protection enabled on underlying hardware,"
743 if (!dev
->transport
->init_prot
|| !dev
->transport
->free_prot
) {
744 /* 0 is only allowed value for non-supporting backends */
748 pr_err("DIF protection not supported by backend: %s\n",
749 dev
->transport
->name
);
752 if (!(dev
->dev_flags
& DF_CONFIGURED
)) {
753 pr_err("DIF protection requires device to be configured\n");
756 if (dev
->export_count
) {
757 pr_err("dev[%p]: Unable to change SE Device PROT type while"
758 " export_count is %d\n", dev
, dev
->export_count
);
762 da
->pi_prot_type
= flag
;
764 if (flag
&& !old_prot
) {
765 ret
= dev
->transport
->init_prot(dev
);
767 da
->pi_prot_type
= old_prot
;
771 } else if (!flag
&& old_prot
) {
772 dev
->transport
->free_prot(dev
);
775 pr_debug("dev[%p]: SE Device Protection Type: %d\n", dev
, flag
);
779 static ssize_t
pi_prot_format_store(struct config_item
*item
,
780 const char *page
, size_t count
)
782 struct se_dev_attrib
*da
= to_attrib(item
);
783 struct se_device
*dev
= da
->da_dev
;
787 ret
= strtobool(page
, &flag
);
794 if (!dev
->transport
->format_prot
) {
795 pr_err("DIF protection format not supported by backend %s\n",
796 dev
->transport
->name
);
799 if (!(dev
->dev_flags
& DF_CONFIGURED
)) {
800 pr_err("DIF protection format requires device to be configured\n");
803 if (dev
->export_count
) {
804 pr_err("dev[%p]: Unable to format SE Device PROT type while"
805 " export_count is %d\n", dev
, dev
->export_count
);
809 ret
= dev
->transport
->format_prot(dev
);
813 pr_debug("dev[%p]: SE Device Protection Format complete\n", dev
);
817 static ssize_t
force_pr_aptpl_store(struct config_item
*item
,
818 const char *page
, size_t count
)
820 struct se_dev_attrib
*da
= to_attrib(item
);
824 ret
= strtobool(page
, &flag
);
827 if (da
->da_dev
->export_count
) {
828 pr_err("dev[%p]: Unable to set force_pr_aptpl while"
829 " export_count is %d\n",
830 da
->da_dev
, da
->da_dev
->export_count
);
834 da
->force_pr_aptpl
= flag
;
835 pr_debug("dev[%p]: SE Device force_pr_aptpl: %d\n", da
->da_dev
, flag
);
839 static ssize_t
emulate_rest_reord_store(struct config_item
*item
,
840 const char *page
, size_t count
)
842 struct se_dev_attrib
*da
= to_attrib(item
);
846 ret
= strtobool(page
, &flag
);
851 printk(KERN_ERR
"dev[%p]: SE Device emulation of restricted"
852 " reordering not implemented\n", da
->da_dev
);
855 da
->emulate_rest_reord
= flag
;
856 pr_debug("dev[%p]: SE Device emulate_rest_reord: %d\n",
861 static ssize_t
unmap_zeroes_data_store(struct config_item
*item
,
862 const char *page
, size_t count
)
864 struct se_dev_attrib
*da
= to_attrib(item
);
868 ret
= strtobool(page
, &flag
);
872 if (da
->da_dev
->export_count
) {
873 pr_err("dev[%p]: Unable to change SE Device"
874 " unmap_zeroes_data while export_count is %d\n",
875 da
->da_dev
, da
->da_dev
->export_count
);
879 * We expect this value to be non-zero when generic Block Layer
880 * Discard supported is detected iblock_configure_device().
882 if (flag
&& !da
->max_unmap_block_desc_count
) {
883 pr_err("dev[%p]: Thin Provisioning LBPRZ will not be set"
884 " because max_unmap_block_desc_count is zero\n",
888 da
->unmap_zeroes_data
= flag
;
889 pr_debug("dev[%p]: SE Device Thin Provisioning LBPRZ bit: %d\n",
895 * Note, this can only be called on unexported SE Device Object.
897 static ssize_t
queue_depth_store(struct config_item
*item
,
898 const char *page
, size_t count
)
900 struct se_dev_attrib
*da
= to_attrib(item
);
901 struct se_device
*dev
= da
->da_dev
;
905 ret
= kstrtou32(page
, 0, &val
);
909 if (dev
->export_count
) {
910 pr_err("dev[%p]: Unable to change SE Device TCQ while"
911 " export_count is %d\n",
912 dev
, dev
->export_count
);
916 pr_err("dev[%p]: Illegal ZERO value for queue_depth\n", dev
);
920 if (val
> dev
->dev_attrib
.queue_depth
) {
921 if (val
> dev
->dev_attrib
.hw_queue_depth
) {
922 pr_err("dev[%p]: Passed queue_depth:"
923 " %u exceeds TCM/SE_Device MAX"
924 " TCQ: %u\n", dev
, val
,
925 dev
->dev_attrib
.hw_queue_depth
);
929 da
->queue_depth
= dev
->queue_depth
= val
;
930 pr_debug("dev[%p]: SE Device TCQ Depth changed to: %u\n", dev
, val
);
934 static ssize_t
optimal_sectors_store(struct config_item
*item
,
935 const char *page
, size_t count
)
937 struct se_dev_attrib
*da
= to_attrib(item
);
941 ret
= kstrtou32(page
, 0, &val
);
945 if (da
->da_dev
->export_count
) {
946 pr_err("dev[%p]: Unable to change SE Device"
947 " optimal_sectors while export_count is %d\n",
948 da
->da_dev
, da
->da_dev
->export_count
);
951 if (val
> da
->hw_max_sectors
) {
952 pr_err("dev[%p]: Passed optimal_sectors %u cannot be"
953 " greater than hw_max_sectors: %u\n",
954 da
->da_dev
, val
, da
->hw_max_sectors
);
958 da
->optimal_sectors
= val
;
959 pr_debug("dev[%p]: SE Device optimal_sectors changed to %u\n",
964 static ssize_t
block_size_store(struct config_item
*item
,
965 const char *page
, size_t count
)
967 struct se_dev_attrib
*da
= to_attrib(item
);
971 ret
= kstrtou32(page
, 0, &val
);
975 if (da
->da_dev
->export_count
) {
976 pr_err("dev[%p]: Unable to change SE Device block_size"
977 " while export_count is %d\n",
978 da
->da_dev
, da
->da_dev
->export_count
);
982 if (val
!= 512 && val
!= 1024 && val
!= 2048 && val
!= 4096) {
983 pr_err("dev[%p]: Illegal value for block_device: %u"
984 " for SE device, must be 512, 1024, 2048 or 4096\n",
989 da
->block_size
= val
;
990 if (da
->max_bytes_per_io
)
991 da
->hw_max_sectors
= da
->max_bytes_per_io
/ val
;
993 pr_debug("dev[%p]: SE Device block_size changed to %u\n",
998 CONFIGFS_ATTR(, emulate_model_alias
);
999 CONFIGFS_ATTR(, emulate_dpo
);
1000 CONFIGFS_ATTR(, emulate_fua_write
);
1001 CONFIGFS_ATTR(, emulate_fua_read
);
1002 CONFIGFS_ATTR(, emulate_write_cache
);
1003 CONFIGFS_ATTR(, emulate_ua_intlck_ctrl
);
1004 CONFIGFS_ATTR(, emulate_tas
);
1005 CONFIGFS_ATTR(, emulate_tpu
);
1006 CONFIGFS_ATTR(, emulate_tpws
);
1007 CONFIGFS_ATTR(, emulate_caw
);
1008 CONFIGFS_ATTR(, emulate_3pc
);
1009 CONFIGFS_ATTR(, pi_prot_type
);
1010 CONFIGFS_ATTR_RO(, hw_pi_prot_type
);
1011 CONFIGFS_ATTR(, pi_prot_format
);
1012 CONFIGFS_ATTR(, enforce_pr_isids
);
1013 CONFIGFS_ATTR(, is_nonrot
);
1014 CONFIGFS_ATTR(, emulate_rest_reord
);
1015 CONFIGFS_ATTR(, force_pr_aptpl
);
1016 CONFIGFS_ATTR_RO(, hw_block_size
);
1017 CONFIGFS_ATTR(, block_size
);
1018 CONFIGFS_ATTR_RO(, hw_max_sectors
);
1019 CONFIGFS_ATTR(, optimal_sectors
);
1020 CONFIGFS_ATTR_RO(, hw_queue_depth
);
1021 CONFIGFS_ATTR(, queue_depth
);
1022 CONFIGFS_ATTR(, max_unmap_lba_count
);
1023 CONFIGFS_ATTR(, max_unmap_block_desc_count
);
1024 CONFIGFS_ATTR(, unmap_granularity
);
1025 CONFIGFS_ATTR(, unmap_granularity_alignment
);
1026 CONFIGFS_ATTR(, unmap_zeroes_data
);
1027 CONFIGFS_ATTR(, max_write_same_len
);
1030 * dev_attrib attributes for devices using the target core SBC/SPC
1031 * interpreter. Any backend using spc_parse_cdb should be using
1034 struct configfs_attribute
*sbc_attrib_attrs
[] = {
1035 &attr_emulate_model_alias
,
1037 &attr_emulate_fua_write
,
1038 &attr_emulate_fua_read
,
1039 &attr_emulate_write_cache
,
1040 &attr_emulate_ua_intlck_ctrl
,
1047 &attr_hw_pi_prot_type
,
1048 &attr_pi_prot_format
,
1049 &attr_enforce_pr_isids
,
1051 &attr_emulate_rest_reord
,
1052 &attr_force_pr_aptpl
,
1053 &attr_hw_block_size
,
1055 &attr_hw_max_sectors
,
1056 &attr_optimal_sectors
,
1057 &attr_hw_queue_depth
,
1059 &attr_max_unmap_lba_count
,
1060 &attr_max_unmap_block_desc_count
,
1061 &attr_unmap_granularity
,
1062 &attr_unmap_granularity_alignment
,
1063 &attr_unmap_zeroes_data
,
1064 &attr_max_write_same_len
,
1067 EXPORT_SYMBOL(sbc_attrib_attrs
);
1070 * Minimal dev_attrib attributes for devices passing through CDBs.
1071 * In this case we only provide a few read-only attributes for
1072 * backwards compatibility.
1074 struct configfs_attribute
*passthrough_attrib_attrs
[] = {
1075 &attr_hw_pi_prot_type
,
1076 &attr_hw_block_size
,
1077 &attr_hw_max_sectors
,
1078 &attr_hw_queue_depth
,
1081 EXPORT_SYMBOL(passthrough_attrib_attrs
);
1083 TB_CIT_SETUP_DRV(dev_attrib
, NULL
, NULL
);
1085 /* End functions for struct config_item_type tb_dev_attrib_cit */
1087 /* Start functions for struct config_item_type tb_dev_wwn_cit */
1089 static struct t10_wwn
*to_t10_wwn(struct config_item
*item
)
1091 return container_of(to_config_group(item
), struct t10_wwn
, t10_wwn_group
);
1095 * VPD page 0x80 Unit serial
1097 static ssize_t
target_wwn_vpd_unit_serial_show(struct config_item
*item
,
1100 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
1101 &to_t10_wwn(item
)->unit_serial
[0]);
1104 static ssize_t
target_wwn_vpd_unit_serial_store(struct config_item
*item
,
1105 const char *page
, size_t count
)
1107 struct t10_wwn
*t10_wwn
= to_t10_wwn(item
);
1108 struct se_device
*dev
= t10_wwn
->t10_dev
;
1109 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
1112 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
1113 * from the struct scsi_device level firmware, do not allow
1114 * VPD Unit Serial to be emulated.
1116 * Note this struct scsi_device could also be emulating VPD
1117 * information from its drivers/scsi LLD. But for now we assume
1118 * it is doing 'the right thing' wrt a world wide unique
1119 * VPD Unit Serial Number that OS dependent multipath can depend on.
1121 if (dev
->dev_flags
& DF_FIRMWARE_VPD_UNIT_SERIAL
) {
1122 pr_err("Underlying SCSI device firmware provided VPD"
1123 " Unit Serial, ignoring request\n");
1127 if (strlen(page
) >= INQUIRY_VPD_SERIAL_LEN
) {
1128 pr_err("Emulated VPD Unit Serial exceeds"
1129 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
1133 * Check to see if any active $FABRIC_MOD exports exist. If they
1134 * do exist, fail here as changing this information on the fly
1135 * (underneath the initiator side OS dependent multipath code)
1136 * could cause negative effects.
1138 if (dev
->export_count
) {
1139 pr_err("Unable to set VPD Unit Serial while"
1140 " active %d $FABRIC_MOD exports exist\n",
1146 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
1148 * Also, strip any newline added from the userspace
1149 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
1151 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
1152 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
1153 snprintf(dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
1154 "%s", strstrip(buf
));
1155 dev
->dev_flags
|= DF_EMULATED_VPD_UNIT_SERIAL
;
1157 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
1158 " %s\n", dev
->t10_wwn
.unit_serial
);
1164 * VPD page 0x83 Protocol Identifier
1166 static ssize_t
target_wwn_vpd_protocol_identifier_show(struct config_item
*item
,
1169 struct t10_wwn
*t10_wwn
= to_t10_wwn(item
);
1170 struct t10_vpd
*vpd
;
1171 unsigned char buf
[VPD_TMP_BUF_SIZE
];
1174 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
1176 spin_lock(&t10_wwn
->t10_vpd_lock
);
1177 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
1178 if (!vpd
->protocol_identifier_set
)
1181 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
1183 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1186 len
+= sprintf(page
+len
, "%s", buf
);
1188 spin_unlock(&t10_wwn
->t10_vpd_lock
);
1194 * Generic wrapper for dumping VPD identifiers by association.
1196 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
1197 static ssize_t target_wwn_##_name##_show(struct config_item *item, \
1200 struct t10_wwn *t10_wwn = to_t10_wwn(item); \
1201 struct t10_vpd *vpd; \
1202 unsigned char buf[VPD_TMP_BUF_SIZE]; \
1205 spin_lock(&t10_wwn->t10_vpd_lock); \
1206 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
1207 if (vpd->association != _assoc) \
1210 memset(buf, 0, VPD_TMP_BUF_SIZE); \
1211 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
1212 if (len + strlen(buf) >= PAGE_SIZE) \
1214 len += sprintf(page+len, "%s", buf); \
1216 memset(buf, 0, VPD_TMP_BUF_SIZE); \
1217 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
1218 if (len + strlen(buf) >= PAGE_SIZE) \
1220 len += sprintf(page+len, "%s", buf); \
1222 memset(buf, 0, VPD_TMP_BUF_SIZE); \
1223 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
1224 if (len + strlen(buf) >= PAGE_SIZE) \
1226 len += sprintf(page+len, "%s", buf); \
1228 spin_unlock(&t10_wwn->t10_vpd_lock); \
1233 /* VPD page 0x83 Association: Logical Unit */
1234 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
1235 /* VPD page 0x83 Association: Target Port */
1236 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
1237 /* VPD page 0x83 Association: SCSI Target Device */
1238 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
1240 CONFIGFS_ATTR(target_wwn_
, vpd_unit_serial
);
1241 CONFIGFS_ATTR_RO(target_wwn_
, vpd_protocol_identifier
);
1242 CONFIGFS_ATTR_RO(target_wwn_
, vpd_assoc_logical_unit
);
1243 CONFIGFS_ATTR_RO(target_wwn_
, vpd_assoc_target_port
);
1244 CONFIGFS_ATTR_RO(target_wwn_
, vpd_assoc_scsi_target_device
);
1246 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
1247 &target_wwn_attr_vpd_unit_serial
,
1248 &target_wwn_attr_vpd_protocol_identifier
,
1249 &target_wwn_attr_vpd_assoc_logical_unit
,
1250 &target_wwn_attr_vpd_assoc_target_port
,
1251 &target_wwn_attr_vpd_assoc_scsi_target_device
,
1255 TB_CIT_SETUP(dev_wwn
, NULL
, NULL
, target_core_dev_wwn_attrs
);
1257 /* End functions for struct config_item_type tb_dev_wwn_cit */
1259 /* Start functions for struct config_item_type tb_dev_pr_cit */
1261 static struct se_device
*pr_to_dev(struct config_item
*item
)
1263 return container_of(to_config_group(item
), struct se_device
,
1267 static ssize_t
target_core_dev_pr_show_spc3_res(struct se_device
*dev
,
1270 struct se_node_acl
*se_nacl
;
1271 struct t10_pr_registration
*pr_reg
;
1272 char i_buf
[PR_REG_ISID_ID_LEN
];
1274 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1276 pr_reg
= dev
->dev_pr_res_holder
;
1278 return sprintf(page
, "No SPC-3 Reservation holder\n");
1280 se_nacl
= pr_reg
->pr_reg_nacl
;
1281 core_pr_dump_initiator_port(pr_reg
, i_buf
, PR_REG_ISID_ID_LEN
);
1283 return sprintf(page
, "SPC-3 Reservation: %s Initiator: %s%s\n",
1284 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1285 se_nacl
->initiatorname
, i_buf
);
1288 static ssize_t
target_core_dev_pr_show_spc2_res(struct se_device
*dev
,
1291 struct se_node_acl
*se_nacl
;
1294 se_nacl
= dev
->dev_reserved_node_acl
;
1297 "SPC-2 Reservation: %s Initiator: %s\n",
1298 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1299 se_nacl
->initiatorname
);
1301 len
= sprintf(page
, "No SPC-2 Reservation holder\n");
1306 static ssize_t
target_pr_res_holder_show(struct config_item
*item
, char *page
)
1308 struct se_device
*dev
= pr_to_dev(item
);
1311 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
1312 return sprintf(page
, "Passthrough\n");
1314 spin_lock(&dev
->dev_reservation_lock
);
1315 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1316 ret
= target_core_dev_pr_show_spc2_res(dev
, page
);
1318 ret
= target_core_dev_pr_show_spc3_res(dev
, page
);
1319 spin_unlock(&dev
->dev_reservation_lock
);
1323 static ssize_t
target_pr_res_pr_all_tgt_pts_show(struct config_item
*item
,
1326 struct se_device
*dev
= pr_to_dev(item
);
1329 spin_lock(&dev
->dev_reservation_lock
);
1330 if (!dev
->dev_pr_res_holder
) {
1331 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1332 } else if (dev
->dev_pr_res_holder
->pr_reg_all_tg_pt
) {
1333 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1334 " Ports registration\n");
1336 len
= sprintf(page
, "SPC-3 Reservation: Single"
1337 " Target Port registration\n");
1340 spin_unlock(&dev
->dev_reservation_lock
);
1344 static ssize_t
target_pr_res_pr_generation_show(struct config_item
*item
,
1347 return sprintf(page
, "0x%08x\n", pr_to_dev(item
)->t10_pr
.pr_generation
);
1351 static ssize_t
target_pr_res_pr_holder_tg_port_show(struct config_item
*item
,
1354 struct se_device
*dev
= pr_to_dev(item
);
1355 struct se_node_acl
*se_nacl
;
1356 struct se_portal_group
*se_tpg
;
1357 struct t10_pr_registration
*pr_reg
;
1358 const struct target_core_fabric_ops
*tfo
;
1361 spin_lock(&dev
->dev_reservation_lock
);
1362 pr_reg
= dev
->dev_pr_res_holder
;
1364 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1368 se_nacl
= pr_reg
->pr_reg_nacl
;
1369 se_tpg
= se_nacl
->se_tpg
;
1370 tfo
= se_tpg
->se_tpg_tfo
;
1372 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1373 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1374 tfo
->tpg_get_wwn(se_tpg
));
1375 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1376 " Identifier Tag: %hu %s Portal Group Tag: %hu"
1377 " %s Logical Unit: %llu\n", pr_reg
->tg_pt_sep_rtpi
,
1378 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1379 tfo
->get_fabric_name(), pr_reg
->pr_aptpl_target_lun
);
1382 spin_unlock(&dev
->dev_reservation_lock
);
1387 static ssize_t
target_pr_res_pr_registered_i_pts_show(struct config_item
*item
,
1390 struct se_device
*dev
= pr_to_dev(item
);
1391 const struct target_core_fabric_ops
*tfo
;
1392 struct t10_pr_registration
*pr_reg
;
1393 unsigned char buf
[384];
1394 char i_buf
[PR_REG_ISID_ID_LEN
];
1398 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1400 spin_lock(&dev
->t10_pr
.registration_lock
);
1401 list_for_each_entry(pr_reg
, &dev
->t10_pr
.registration_list
,
1404 memset(buf
, 0, 384);
1405 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1406 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1407 core_pr_dump_initiator_port(pr_reg
, i_buf
,
1408 PR_REG_ISID_ID_LEN
);
1409 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1410 tfo
->get_fabric_name(),
1411 pr_reg
->pr_reg_nacl
->initiatorname
, i_buf
, pr_reg
->pr_res_key
,
1412 pr_reg
->pr_res_generation
);
1414 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1417 len
+= sprintf(page
+len
, "%s", buf
);
1420 spin_unlock(&dev
->t10_pr
.registration_lock
);
1423 len
+= sprintf(page
+len
, "None\n");
1428 static ssize_t
target_pr_res_pr_type_show(struct config_item
*item
, char *page
)
1430 struct se_device
*dev
= pr_to_dev(item
);
1431 struct t10_pr_registration
*pr_reg
;
1434 spin_lock(&dev
->dev_reservation_lock
);
1435 pr_reg
= dev
->dev_pr_res_holder
;
1437 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1438 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1440 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1443 spin_unlock(&dev
->dev_reservation_lock
);
1447 static ssize_t
target_pr_res_type_show(struct config_item
*item
, char *page
)
1449 struct se_device
*dev
= pr_to_dev(item
);
1451 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
1452 return sprintf(page
, "SPC_PASSTHROUGH\n");
1453 else if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1454 return sprintf(page
, "SPC2_RESERVATIONS\n");
1456 return sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1459 static ssize_t
target_pr_res_aptpl_active_show(struct config_item
*item
,
1462 struct se_device
*dev
= pr_to_dev(item
);
1464 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
1467 return sprintf(page
, "APTPL Bit Status: %s\n",
1468 (dev
->t10_pr
.pr_aptpl_active
) ? "Activated" : "Disabled");
1471 static ssize_t
target_pr_res_aptpl_metadata_show(struct config_item
*item
,
1474 struct se_device
*dev
= pr_to_dev(item
);
1476 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
1479 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1483 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1484 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1485 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1486 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1489 static match_table_t tokens
= {
1490 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1491 {Opt_initiator_node
, "initiator_node=%s"},
1492 {Opt_initiator_sid
, "initiator_sid=%s"},
1493 {Opt_sa_res_key
, "sa_res_key=%s"},
1494 {Opt_res_holder
, "res_holder=%d"},
1495 {Opt_res_type
, "res_type=%d"},
1496 {Opt_res_scope
, "res_scope=%d"},
1497 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1498 {Opt_mapped_lun
, "mapped_lun=%lld"},
1499 {Opt_target_fabric
, "target_fabric=%s"},
1500 {Opt_target_node
, "target_node=%s"},
1501 {Opt_tpgt
, "tpgt=%d"},
1502 {Opt_port_rtpi
, "port_rtpi=%d"},
1503 {Opt_target_lun
, "target_lun=%lld"},
1507 static ssize_t
target_pr_res_aptpl_metadata_store(struct config_item
*item
,
1508 const char *page
, size_t count
)
1510 struct se_device
*dev
= pr_to_dev(item
);
1511 unsigned char *i_fabric
= NULL
, *i_port
= NULL
, *isid
= NULL
;
1512 unsigned char *t_fabric
= NULL
, *t_port
= NULL
;
1513 char *orig
, *ptr
, *opts
;
1514 substring_t args
[MAX_OPT_ARGS
];
1515 unsigned long long tmp_ll
;
1517 u64 mapped_lun
= 0, target_lun
= 0;
1518 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1522 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
1524 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1527 if (dev
->export_count
) {
1528 pr_debug("Unable to process APTPL metadata while"
1529 " active fabric exports exist\n");
1533 opts
= kstrdup(page
, GFP_KERNEL
);
1538 while ((ptr
= strsep(&opts
, ",\n")) != NULL
) {
1542 token
= match_token(ptr
, tokens
, args
);
1544 case Opt_initiator_fabric
:
1545 i_fabric
= match_strdup(args
);
1551 case Opt_initiator_node
:
1552 i_port
= match_strdup(args
);
1557 if (strlen(i_port
) >= PR_APTPL_MAX_IPORT_LEN
) {
1558 pr_err("APTPL metadata initiator_node="
1559 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1560 PR_APTPL_MAX_IPORT_LEN
);
1565 case Opt_initiator_sid
:
1566 isid
= match_strdup(args
);
1571 if (strlen(isid
) >= PR_REG_ISID_LEN
) {
1572 pr_err("APTPL metadata initiator_isid"
1573 "= exceeds PR_REG_ISID_LEN: %d\n",
1579 case Opt_sa_res_key
:
1580 ret
= kstrtoull(args
->from
, 0, &tmp_ll
);
1582 pr_err("kstrtoull() failed for sa_res_key=\n");
1585 sa_res_key
= (u64
)tmp_ll
;
1588 * PR APTPL Metadata for Reservation
1590 case Opt_res_holder
:
1591 ret
= match_int(args
, &arg
);
1597 ret
= match_int(args
, &arg
);
1603 ret
= match_int(args
, &arg
);
1607 case Opt_res_all_tg_pt
:
1608 ret
= match_int(args
, &arg
);
1611 all_tg_pt
= (int)arg
;
1613 case Opt_mapped_lun
:
1614 ret
= match_int(args
, &arg
);
1617 mapped_lun
= (u64
)arg
;
1620 * PR APTPL Metadata for Target Port
1622 case Opt_target_fabric
:
1623 t_fabric
= match_strdup(args
);
1629 case Opt_target_node
:
1630 t_port
= match_strdup(args
);
1635 if (strlen(t_port
) >= PR_APTPL_MAX_TPORT_LEN
) {
1636 pr_err("APTPL metadata target_node="
1637 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1638 PR_APTPL_MAX_TPORT_LEN
);
1644 ret
= match_int(args
, &arg
);
1650 ret
= match_int(args
, &arg
);
1654 case Opt_target_lun
:
1655 ret
= match_int(args
, &arg
);
1658 target_lun
= (u64
)arg
;
1665 if (!i_port
|| !t_port
|| !sa_res_key
) {
1666 pr_err("Illegal parameters for APTPL registration\n");
1671 if (res_holder
&& !(type
)) {
1672 pr_err("Illegal PR type: 0x%02x for reservation"
1678 ret
= core_scsi3_alloc_aptpl_registration(&dev
->t10_pr
, sa_res_key
,
1679 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1680 res_holder
, all_tg_pt
, type
);
1688 return (ret
== 0) ? count
: ret
;
1692 CONFIGFS_ATTR_RO(target_pr_
, res_holder
);
1693 CONFIGFS_ATTR_RO(target_pr_
, res_pr_all_tgt_pts
);
1694 CONFIGFS_ATTR_RO(target_pr_
, res_pr_generation
);
1695 CONFIGFS_ATTR_RO(target_pr_
, res_pr_holder_tg_port
);
1696 CONFIGFS_ATTR_RO(target_pr_
, res_pr_registered_i_pts
);
1697 CONFIGFS_ATTR_RO(target_pr_
, res_pr_type
);
1698 CONFIGFS_ATTR_RO(target_pr_
, res_type
);
1699 CONFIGFS_ATTR_RO(target_pr_
, res_aptpl_active
);
1700 CONFIGFS_ATTR(target_pr_
, res_aptpl_metadata
);
1702 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1703 &target_pr_attr_res_holder
,
1704 &target_pr_attr_res_pr_all_tgt_pts
,
1705 &target_pr_attr_res_pr_generation
,
1706 &target_pr_attr_res_pr_holder_tg_port
,
1707 &target_pr_attr_res_pr_registered_i_pts
,
1708 &target_pr_attr_res_pr_type
,
1709 &target_pr_attr_res_type
,
1710 &target_pr_attr_res_aptpl_active
,
1711 &target_pr_attr_res_aptpl_metadata
,
1715 TB_CIT_SETUP(dev_pr
, NULL
, NULL
, target_core_dev_pr_attrs
);
1717 /* End functions for struct config_item_type tb_dev_pr_cit */
1719 /* Start functions for struct config_item_type tb_dev_cit */
1721 static inline struct se_device
*to_device(struct config_item
*item
)
1723 return container_of(to_config_group(item
), struct se_device
, dev_group
);
1726 static ssize_t
target_dev_info_show(struct config_item
*item
, char *page
)
1728 struct se_device
*dev
= to_device(item
);
1730 ssize_t read_bytes
= 0;
1732 transport_dump_dev_state(dev
, page
, &bl
);
1734 read_bytes
+= dev
->transport
->show_configfs_dev_params(dev
,
1739 static ssize_t
target_dev_control_store(struct config_item
*item
,
1740 const char *page
, size_t count
)
1742 struct se_device
*dev
= to_device(item
);
1744 return dev
->transport
->set_configfs_dev_params(dev
, page
, count
);
1747 static ssize_t
target_dev_alias_show(struct config_item
*item
, char *page
)
1749 struct se_device
*dev
= to_device(item
);
1751 if (!(dev
->dev_flags
& DF_USING_ALIAS
))
1754 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->dev_alias
);
1757 static ssize_t
target_dev_alias_store(struct config_item
*item
,
1758 const char *page
, size_t count
)
1760 struct se_device
*dev
= to_device(item
);
1761 struct se_hba
*hba
= dev
->se_hba
;
1764 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1765 pr_err("alias count: %d exceeds"
1766 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1767 SE_DEV_ALIAS_LEN
-1);
1771 read_bytes
= snprintf(&dev
->dev_alias
[0], SE_DEV_ALIAS_LEN
, "%s", page
);
1774 if (dev
->dev_alias
[read_bytes
- 1] == '\n')
1775 dev
->dev_alias
[read_bytes
- 1] = '\0';
1777 dev
->dev_flags
|= DF_USING_ALIAS
;
1779 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
1780 config_item_name(&hba
->hba_group
.cg_item
),
1781 config_item_name(&dev
->dev_group
.cg_item
),
1787 static ssize_t
target_dev_udev_path_show(struct config_item
*item
, char *page
)
1789 struct se_device
*dev
= to_device(item
);
1791 if (!(dev
->dev_flags
& DF_USING_UDEV_PATH
))
1794 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->udev_path
);
1797 static ssize_t
target_dev_udev_path_store(struct config_item
*item
,
1798 const char *page
, size_t count
)
1800 struct se_device
*dev
= to_device(item
);
1801 struct se_hba
*hba
= dev
->se_hba
;
1804 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1805 pr_err("udev_path count: %d exceeds"
1806 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1807 SE_UDEV_PATH_LEN
-1);
1811 read_bytes
= snprintf(&dev
->udev_path
[0], SE_UDEV_PATH_LEN
,
1815 if (dev
->udev_path
[read_bytes
- 1] == '\n')
1816 dev
->udev_path
[read_bytes
- 1] = '\0';
1818 dev
->dev_flags
|= DF_USING_UDEV_PATH
;
1820 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1821 config_item_name(&hba
->hba_group
.cg_item
),
1822 config_item_name(&dev
->dev_group
.cg_item
),
1828 static ssize_t
target_dev_enable_show(struct config_item
*item
, char *page
)
1830 struct se_device
*dev
= to_device(item
);
1832 return snprintf(page
, PAGE_SIZE
, "%d\n", !!(dev
->dev_flags
& DF_CONFIGURED
));
1835 static ssize_t
target_dev_enable_store(struct config_item
*item
,
1836 const char *page
, size_t count
)
1838 struct se_device
*dev
= to_device(item
);
1842 ptr
= strstr(page
, "1");
1844 pr_err("For dev_enable ops, only valid value"
1849 ret
= target_configure_device(dev
);
1855 static ssize_t
target_dev_alua_lu_gp_show(struct config_item
*item
, char *page
)
1857 struct se_device
*dev
= to_device(item
);
1858 struct config_item
*lu_ci
;
1859 struct t10_alua_lu_gp
*lu_gp
;
1860 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1863 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1867 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1868 lu_gp
= lu_gp_mem
->lu_gp
;
1870 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1871 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1872 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1874 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1879 static ssize_t
target_dev_alua_lu_gp_store(struct config_item
*item
,
1880 const char *page
, size_t count
)
1882 struct se_device
*dev
= to_device(item
);
1883 struct se_hba
*hba
= dev
->se_hba
;
1884 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1885 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1886 unsigned char buf
[LU_GROUP_NAME_BUF
];
1889 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1893 if (count
> LU_GROUP_NAME_BUF
) {
1894 pr_err("ALUA LU Group Alias too large!\n");
1897 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1898 memcpy(buf
, page
, count
);
1900 * Any ALUA logical unit alias besides "NULL" means we will be
1901 * making a new group association.
1903 if (strcmp(strstrip(buf
), "NULL")) {
1905 * core_alua_get_lu_gp_by_name() will increment reference to
1906 * struct t10_alua_lu_gp. This reference is released with
1907 * core_alua_get_lu_gp_by_name below().
1909 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
1914 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1915 lu_gp
= lu_gp_mem
->lu_gp
;
1918 * Clearing an existing lu_gp association, and replacing
1922 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
1923 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1925 config_item_name(&hba
->hba_group
.cg_item
),
1926 config_item_name(&dev
->dev_group
.cg_item
),
1927 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1930 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1931 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1936 * Removing existing association of lu_gp_mem with lu_gp
1938 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1942 * Associate lu_gp_mem with lu_gp_new.
1944 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
1945 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1947 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1948 " core/alua/lu_gps/%s, ID: %hu\n",
1949 (move
) ? "Moving" : "Adding",
1950 config_item_name(&hba
->hba_group
.cg_item
),
1951 config_item_name(&dev
->dev_group
.cg_item
),
1952 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
1953 lu_gp_new
->lu_gp_id
);
1955 core_alua_put_lu_gp_from_name(lu_gp_new
);
1959 static ssize_t
target_dev_lba_map_show(struct config_item
*item
, char *page
)
1961 struct se_device
*dev
= to_device(item
);
1962 struct t10_alua_lba_map
*map
;
1963 struct t10_alua_lba_map_member
*mem
;
1968 spin_lock(&dev
->t10_alua
.lba_map_lock
);
1969 if (!list_empty(&dev
->t10_alua
.lba_map_list
))
1970 bl
+= sprintf(b
+ bl
, "%u %u\n",
1971 dev
->t10_alua
.lba_map_segment_size
,
1972 dev
->t10_alua
.lba_map_segment_multiplier
);
1973 list_for_each_entry(map
, &dev
->t10_alua
.lba_map_list
, lba_map_list
) {
1974 bl
+= sprintf(b
+ bl
, "%llu %llu",
1975 map
->lba_map_first_lba
, map
->lba_map_last_lba
);
1976 list_for_each_entry(mem
, &map
->lba_map_mem_list
,
1978 switch (mem
->lba_map_mem_alua_state
) {
1979 case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
:
1982 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
1985 case ALUA_ACCESS_STATE_STANDBY
:
1988 case ALUA_ACCESS_STATE_UNAVAILABLE
:
1995 bl
+= sprintf(b
+ bl
, " %d:%c",
1996 mem
->lba_map_mem_alua_pg_id
, state
);
1998 bl
+= sprintf(b
+ bl
, "\n");
2000 spin_unlock(&dev
->t10_alua
.lba_map_lock
);
2004 static ssize_t
target_dev_lba_map_store(struct config_item
*item
,
2005 const char *page
, size_t count
)
2007 struct se_device
*dev
= to_device(item
);
2008 struct t10_alua_lba_map
*lba_map
= NULL
;
2009 struct list_head lba_list
;
2010 char *map_entries
, *orig
, *ptr
;
2012 int pg_num
= -1, pg
;
2013 int ret
= 0, num
= 0, pg_id
, alua_state
;
2014 unsigned long start_lba
= -1, end_lba
= -1;
2015 unsigned long segment_size
= -1, segment_mult
= -1;
2017 orig
= map_entries
= kstrdup(page
, GFP_KERNEL
);
2021 INIT_LIST_HEAD(&lba_list
);
2022 while ((ptr
= strsep(&map_entries
, "\n")) != NULL
) {
2027 if (sscanf(ptr
, "%lu %lu\n",
2028 &segment_size
, &segment_mult
) != 2) {
2029 pr_err("Invalid line %d\n", num
);
2036 if (sscanf(ptr
, "%lu %lu", &start_lba
, &end_lba
) != 2) {
2037 pr_err("Invalid line %d\n", num
);
2041 ptr
= strchr(ptr
, ' ');
2043 pr_err("Invalid line %d, missing end lba\n", num
);
2048 ptr
= strchr(ptr
, ' ');
2050 pr_err("Invalid line %d, missing state definitions\n",
2056 lba_map
= core_alua_allocate_lba_map(&lba_list
,
2057 start_lba
, end_lba
);
2058 if (IS_ERR(lba_map
)) {
2059 ret
= PTR_ERR(lba_map
);
2063 while (sscanf(ptr
, "%d:%c", &pg_id
, &state
) == 2) {
2066 alua_state
= ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
;
2069 alua_state
= ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
;
2072 alua_state
= ALUA_ACCESS_STATE_STANDBY
;
2075 alua_state
= ALUA_ACCESS_STATE_UNAVAILABLE
;
2078 pr_err("Invalid ALUA state '%c'\n", state
);
2083 ret
= core_alua_allocate_lba_map_mem(lba_map
,
2086 pr_err("Invalid target descriptor %d:%c "
2092 ptr
= strchr(ptr
, ' ');
2100 else if (pg
!= pg_num
) {
2101 pr_err("Only %d from %d port groups definitions "
2102 "at line %d\n", pg
, pg_num
, num
);
2110 core_alua_free_lba_map(&lba_list
);
2113 core_alua_set_lba_map(dev
, &lba_list
,
2114 segment_size
, segment_mult
);
2119 CONFIGFS_ATTR_RO(target_dev_
, info
);
2120 CONFIGFS_ATTR_WO(target_dev_
, control
);
2121 CONFIGFS_ATTR(target_dev_
, alias
);
2122 CONFIGFS_ATTR(target_dev_
, udev_path
);
2123 CONFIGFS_ATTR(target_dev_
, enable
);
2124 CONFIGFS_ATTR(target_dev_
, alua_lu_gp
);
2125 CONFIGFS_ATTR(target_dev_
, lba_map
);
2127 static struct configfs_attribute
*target_core_dev_attrs
[] = {
2128 &target_dev_attr_info
,
2129 &target_dev_attr_control
,
2130 &target_dev_attr_alias
,
2131 &target_dev_attr_udev_path
,
2132 &target_dev_attr_enable
,
2133 &target_dev_attr_alua_lu_gp
,
2134 &target_dev_attr_lba_map
,
2138 static void target_core_dev_release(struct config_item
*item
)
2140 struct config_group
*dev_cg
= to_config_group(item
);
2141 struct se_device
*dev
=
2142 container_of(dev_cg
, struct se_device
, dev_group
);
2144 target_free_device(dev
);
2147 static struct configfs_item_operations target_core_dev_item_ops
= {
2148 .release
= target_core_dev_release
,
2151 TB_CIT_SETUP(dev
, &target_core_dev_item_ops
, NULL
, target_core_dev_attrs
);
2153 /* End functions for struct config_item_type tb_dev_cit */
2155 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
2157 static inline struct t10_alua_lu_gp
*to_lu_gp(struct config_item
*item
)
2159 return container_of(to_config_group(item
), struct t10_alua_lu_gp
,
2163 static ssize_t
target_lu_gp_lu_gp_id_show(struct config_item
*item
, char *page
)
2165 struct t10_alua_lu_gp
*lu_gp
= to_lu_gp(item
);
2167 if (!lu_gp
->lu_gp_valid_id
)
2169 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
2172 static ssize_t
target_lu_gp_lu_gp_id_store(struct config_item
*item
,
2173 const char *page
, size_t count
)
2175 struct t10_alua_lu_gp
*lu_gp
= to_lu_gp(item
);
2176 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2177 unsigned long lu_gp_id
;
2180 ret
= kstrtoul(page
, 0, &lu_gp_id
);
2182 pr_err("kstrtoul() returned %d for"
2183 " lu_gp_id\n", ret
);
2186 if (lu_gp_id
> 0x0000ffff) {
2187 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
2188 " 0x0000ffff\n", lu_gp_id
);
2192 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
2196 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
2197 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2198 config_item_name(&alua_lu_gp_cg
->cg_item
),
2204 static ssize_t
target_lu_gp_members_show(struct config_item
*item
, char *page
)
2206 struct t10_alua_lu_gp
*lu_gp
= to_lu_gp(item
);
2207 struct se_device
*dev
;
2209 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2210 ssize_t len
= 0, cur_len
;
2211 unsigned char buf
[LU_GROUP_NAME_BUF
];
2213 memset(buf
, 0, LU_GROUP_NAME_BUF
);
2215 spin_lock(&lu_gp
->lu_gp_lock
);
2216 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
2217 dev
= lu_gp_mem
->lu_gp_mem_dev
;
2220 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
2221 config_item_name(&hba
->hba_group
.cg_item
),
2222 config_item_name(&dev
->dev_group
.cg_item
));
2223 cur_len
++; /* Extra byte for NULL terminator */
2225 if ((cur_len
+ len
) > PAGE_SIZE
) {
2226 pr_warn("Ran out of lu_gp_show_attr"
2227 "_members buffer\n");
2230 memcpy(page
+len
, buf
, cur_len
);
2233 spin_unlock(&lu_gp
->lu_gp_lock
);
2238 CONFIGFS_ATTR(target_lu_gp_
, lu_gp_id
);
2239 CONFIGFS_ATTR_RO(target_lu_gp_
, members
);
2241 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
2242 &target_lu_gp_attr_lu_gp_id
,
2243 &target_lu_gp_attr_members
,
2247 static void target_core_alua_lu_gp_release(struct config_item
*item
)
2249 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2250 struct t10_alua_lu_gp
, lu_gp_group
);
2252 core_alua_free_lu_gp(lu_gp
);
2255 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
2256 .release
= target_core_alua_lu_gp_release
,
2259 static struct config_item_type target_core_alua_lu_gp_cit
= {
2260 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
2261 .ct_attrs
= target_core_alua_lu_gp_attrs
,
2262 .ct_owner
= THIS_MODULE
,
2265 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
2267 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
2269 static struct config_group
*target_core_alua_create_lu_gp(
2270 struct config_group
*group
,
2273 struct t10_alua_lu_gp
*lu_gp
;
2274 struct config_group
*alua_lu_gp_cg
= NULL
;
2275 struct config_item
*alua_lu_gp_ci
= NULL
;
2277 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
2281 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2282 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
2284 config_group_init_type_name(alua_lu_gp_cg
, name
,
2285 &target_core_alua_lu_gp_cit
);
2287 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2288 " Group: core/alua/lu_gps/%s\n",
2289 config_item_name(alua_lu_gp_ci
));
2291 return alua_lu_gp_cg
;
2295 static void target_core_alua_drop_lu_gp(
2296 struct config_group
*group
,
2297 struct config_item
*item
)
2299 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2300 struct t10_alua_lu_gp
, lu_gp_group
);
2302 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2303 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2304 config_item_name(item
), lu_gp
->lu_gp_id
);
2306 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
2307 * -> target_core_alua_lu_gp_release()
2309 config_item_put(item
);
2312 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
2313 .make_group
= &target_core_alua_create_lu_gp
,
2314 .drop_item
= &target_core_alua_drop_lu_gp
,
2317 static struct config_item_type target_core_alua_lu_gps_cit
= {
2318 .ct_item_ops
= NULL
,
2319 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
2320 .ct_owner
= THIS_MODULE
,
2323 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
2325 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2327 static inline struct t10_alua_tg_pt_gp
*to_tg_pt_gp(struct config_item
*item
)
2329 return container_of(to_config_group(item
), struct t10_alua_tg_pt_gp
,
2333 static ssize_t
target_tg_pt_gp_alua_access_state_show(struct config_item
*item
,
2336 return sprintf(page
, "%d\n",
2337 atomic_read(&to_tg_pt_gp(item
)->tg_pt_gp_alua_access_state
));
2340 static ssize_t
target_tg_pt_gp_alua_access_state_store(struct config_item
*item
,
2341 const char *page
, size_t count
)
2343 struct t10_alua_tg_pt_gp
*tg_pt_gp
= to_tg_pt_gp(item
);
2344 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
2348 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2349 pr_err("Unable to do implicit ALUA on non valid"
2350 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2353 if (!(dev
->dev_flags
& DF_CONFIGURED
)) {
2354 pr_err("Unable to set alua_access_state while device is"
2355 " not configured\n");
2359 ret
= kstrtoul(page
, 0, &tmp
);
2361 pr_err("Unable to extract new ALUA access state from"
2365 new_state
= (int)tmp
;
2367 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICIT_ALUA
)) {
2368 pr_err("Unable to process implicit configfs ALUA"
2369 " transition while TPGS_IMPLICIT_ALUA is disabled\n");
2372 if (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICIT_ALUA
&&
2373 new_state
== ALUA_ACCESS_STATE_LBA_DEPENDENT
) {
2374 /* LBA DEPENDENT is only allowed with implicit ALUA */
2375 pr_err("Unable to process implicit configfs ALUA transition"
2376 " while explicit ALUA management is enabled\n");
2380 ret
= core_alua_do_port_transition(tg_pt_gp
, dev
,
2381 NULL
, NULL
, new_state
, 0);
2382 return (!ret
) ? count
: -EINVAL
;
2385 static ssize_t
target_tg_pt_gp_alua_access_status_show(struct config_item
*item
,
2388 struct t10_alua_tg_pt_gp
*tg_pt_gp
= to_tg_pt_gp(item
);
2389 return sprintf(page
, "%s\n",
2390 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2393 static ssize_t
target_tg_pt_gp_alua_access_status_store(
2394 struct config_item
*item
, const char *page
, size_t count
)
2396 struct t10_alua_tg_pt_gp
*tg_pt_gp
= to_tg_pt_gp(item
);
2398 int new_status
, ret
;
2400 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2401 pr_err("Unable to do set ALUA access status on non"
2402 " valid tg_pt_gp ID: %hu\n",
2403 tg_pt_gp
->tg_pt_gp_valid_id
);
2407 ret
= kstrtoul(page
, 0, &tmp
);
2409 pr_err("Unable to extract new ALUA access status"
2410 " from %s\n", page
);
2413 new_status
= (int)tmp
;
2415 if ((new_status
!= ALUA_STATUS_NONE
) &&
2416 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG
) &&
2417 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA
)) {
2418 pr_err("Illegal ALUA access status: 0x%02x\n",
2423 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2427 static ssize_t
target_tg_pt_gp_alua_access_type_show(struct config_item
*item
,
2430 return core_alua_show_access_type(to_tg_pt_gp(item
), page
);
2433 static ssize_t
target_tg_pt_gp_alua_access_type_store(struct config_item
*item
,
2434 const char *page
, size_t count
)
2436 return core_alua_store_access_type(to_tg_pt_gp(item
), page
, count
);
2439 #define ALUA_SUPPORTED_STATE_ATTR(_name, _bit) \
2440 static ssize_t target_tg_pt_gp_alua_support_##_name##_show( \
2441 struct config_item *item, char *p) \
2443 struct t10_alua_tg_pt_gp *t = to_tg_pt_gp(item); \
2444 return sprintf(p, "%d\n", \
2445 !!(t->tg_pt_gp_alua_supported_states & _bit)); \
2448 static ssize_t target_tg_pt_gp_alua_support_##_name##_store( \
2449 struct config_item *item, const char *p, size_t c) \
2451 struct t10_alua_tg_pt_gp *t = to_tg_pt_gp(item); \
2452 unsigned long tmp; \
2455 if (!t->tg_pt_gp_valid_id) { \
2456 pr_err("Unable to do set ##_name ALUA state on non" \
2457 " valid tg_pt_gp ID: %hu\n", \
2458 t->tg_pt_gp_valid_id); \
2462 ret = kstrtoul(p, 0, &tmp); \
2464 pr_err("Invalid value '%s', must be '0' or '1'\n", p); \
2468 pr_err("Invalid value '%ld', must be '0' or '1'\n", tmp); \
2472 t->tg_pt_gp_alua_supported_states |= _bit; \
2474 t->tg_pt_gp_alua_supported_states &= ~_bit; \
2479 ALUA_SUPPORTED_STATE_ATTR(transitioning
, ALUA_T_SUP
);
2480 ALUA_SUPPORTED_STATE_ATTR(offline
, ALUA_O_SUP
);
2481 ALUA_SUPPORTED_STATE_ATTR(lba_dependent
, ALUA_LBD_SUP
);
2482 ALUA_SUPPORTED_STATE_ATTR(unavailable
, ALUA_U_SUP
);
2483 ALUA_SUPPORTED_STATE_ATTR(standby
, ALUA_S_SUP
);
2484 ALUA_SUPPORTED_STATE_ATTR(active_optimized
, ALUA_AO_SUP
);
2485 ALUA_SUPPORTED_STATE_ATTR(active_nonoptimized
, ALUA_AN_SUP
);
2487 static ssize_t
target_tg_pt_gp_alua_write_metadata_show(
2488 struct config_item
*item
, char *page
)
2490 return sprintf(page
, "%d\n",
2491 to_tg_pt_gp(item
)->tg_pt_gp_write_metadata
);
2494 static ssize_t
target_tg_pt_gp_alua_write_metadata_store(
2495 struct config_item
*item
, const char *page
, size_t count
)
2497 struct t10_alua_tg_pt_gp
*tg_pt_gp
= to_tg_pt_gp(item
);
2501 ret
= kstrtoul(page
, 0, &tmp
);
2503 pr_err("Unable to extract alua_write_metadata\n");
2507 if ((tmp
!= 0) && (tmp
!= 1)) {
2508 pr_err("Illegal value for alua_write_metadata:"
2512 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2517 static ssize_t
target_tg_pt_gp_nonop_delay_msecs_show(struct config_item
*item
,
2520 return core_alua_show_nonop_delay_msecs(to_tg_pt_gp(item
), page
);
2523 static ssize_t
target_tg_pt_gp_nonop_delay_msecs_store(struct config_item
*item
,
2524 const char *page
, size_t count
)
2526 return core_alua_store_nonop_delay_msecs(to_tg_pt_gp(item
), page
,
2530 static ssize_t
target_tg_pt_gp_trans_delay_msecs_show(struct config_item
*item
,
2533 return core_alua_show_trans_delay_msecs(to_tg_pt_gp(item
), page
);
2536 static ssize_t
target_tg_pt_gp_trans_delay_msecs_store(struct config_item
*item
,
2537 const char *page
, size_t count
)
2539 return core_alua_store_trans_delay_msecs(to_tg_pt_gp(item
), page
,
2543 static ssize_t
target_tg_pt_gp_implicit_trans_secs_show(
2544 struct config_item
*item
, char *page
)
2546 return core_alua_show_implicit_trans_secs(to_tg_pt_gp(item
), page
);
2549 static ssize_t
target_tg_pt_gp_implicit_trans_secs_store(
2550 struct config_item
*item
, const char *page
, size_t count
)
2552 return core_alua_store_implicit_trans_secs(to_tg_pt_gp(item
), page
,
2556 static ssize_t
target_tg_pt_gp_preferred_show(struct config_item
*item
,
2559 return core_alua_show_preferred_bit(to_tg_pt_gp(item
), page
);
2562 static ssize_t
target_tg_pt_gp_preferred_store(struct config_item
*item
,
2563 const char *page
, size_t count
)
2565 return core_alua_store_preferred_bit(to_tg_pt_gp(item
), page
, count
);
2568 static ssize_t
target_tg_pt_gp_tg_pt_gp_id_show(struct config_item
*item
,
2571 struct t10_alua_tg_pt_gp
*tg_pt_gp
= to_tg_pt_gp(item
);
2573 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
2575 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2578 static ssize_t
target_tg_pt_gp_tg_pt_gp_id_store(struct config_item
*item
,
2579 const char *page
, size_t count
)
2581 struct t10_alua_tg_pt_gp
*tg_pt_gp
= to_tg_pt_gp(item
);
2582 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2583 unsigned long tg_pt_gp_id
;
2586 ret
= kstrtoul(page
, 0, &tg_pt_gp_id
);
2588 pr_err("kstrtoul() returned %d for"
2589 " tg_pt_gp_id\n", ret
);
2592 if (tg_pt_gp_id
> 0x0000ffff) {
2593 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:"
2594 " 0x0000ffff\n", tg_pt_gp_id
);
2598 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2602 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
2603 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2604 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2605 tg_pt_gp
->tg_pt_gp_id
);
2610 static ssize_t
target_tg_pt_gp_members_show(struct config_item
*item
,
2613 struct t10_alua_tg_pt_gp
*tg_pt_gp
= to_tg_pt_gp(item
);
2615 ssize_t len
= 0, cur_len
;
2616 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2618 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2620 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2621 list_for_each_entry(lun
, &tg_pt_gp
->tg_pt_gp_lun_list
,
2622 lun_tg_pt_gp_link
) {
2623 struct se_portal_group
*tpg
= lun
->lun_tpg
;
2625 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2626 "/%s\n", tpg
->se_tpg_tfo
->get_fabric_name(),
2627 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
2628 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
2629 config_item_name(&lun
->lun_group
.cg_item
));
2630 cur_len
++; /* Extra byte for NULL terminator */
2632 if ((cur_len
+ len
) > PAGE_SIZE
) {
2633 pr_warn("Ran out of lu_gp_show_attr"
2634 "_members buffer\n");
2637 memcpy(page
+len
, buf
, cur_len
);
2640 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2645 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_access_state
);
2646 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_access_status
);
2647 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_access_type
);
2648 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_support_transitioning
);
2649 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_support_offline
);
2650 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_support_lba_dependent
);
2651 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_support_unavailable
);
2652 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_support_standby
);
2653 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_support_active_optimized
);
2654 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_support_active_nonoptimized
);
2655 CONFIGFS_ATTR(target_tg_pt_gp_
, alua_write_metadata
);
2656 CONFIGFS_ATTR(target_tg_pt_gp_
, nonop_delay_msecs
);
2657 CONFIGFS_ATTR(target_tg_pt_gp_
, trans_delay_msecs
);
2658 CONFIGFS_ATTR(target_tg_pt_gp_
, implicit_trans_secs
);
2659 CONFIGFS_ATTR(target_tg_pt_gp_
, preferred
);
2660 CONFIGFS_ATTR(target_tg_pt_gp_
, tg_pt_gp_id
);
2661 CONFIGFS_ATTR_RO(target_tg_pt_gp_
, members
);
2663 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2664 &target_tg_pt_gp_attr_alua_access_state
,
2665 &target_tg_pt_gp_attr_alua_access_status
,
2666 &target_tg_pt_gp_attr_alua_access_type
,
2667 &target_tg_pt_gp_attr_alua_support_transitioning
,
2668 &target_tg_pt_gp_attr_alua_support_offline
,
2669 &target_tg_pt_gp_attr_alua_support_lba_dependent
,
2670 &target_tg_pt_gp_attr_alua_support_unavailable
,
2671 &target_tg_pt_gp_attr_alua_support_standby
,
2672 &target_tg_pt_gp_attr_alua_support_active_nonoptimized
,
2673 &target_tg_pt_gp_attr_alua_support_active_optimized
,
2674 &target_tg_pt_gp_attr_alua_write_metadata
,
2675 &target_tg_pt_gp_attr_nonop_delay_msecs
,
2676 &target_tg_pt_gp_attr_trans_delay_msecs
,
2677 &target_tg_pt_gp_attr_implicit_trans_secs
,
2678 &target_tg_pt_gp_attr_preferred
,
2679 &target_tg_pt_gp_attr_tg_pt_gp_id
,
2680 &target_tg_pt_gp_attr_members
,
2684 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2686 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2687 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2689 core_alua_free_tg_pt_gp(tg_pt_gp
);
2692 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2693 .release
= target_core_alua_tg_pt_gp_release
,
2696 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2697 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2698 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2699 .ct_owner
= THIS_MODULE
,
2702 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2704 /* Start functions for struct config_item_type tb_alua_tg_pt_gps_cit */
2706 static struct config_group
*target_core_alua_create_tg_pt_gp(
2707 struct config_group
*group
,
2710 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2711 alua_tg_pt_gps_group
);
2712 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2713 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2714 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2716 tg_pt_gp
= core_alua_allocate_tg_pt_gp(alua
->t10_dev
, name
, 0);
2720 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2721 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2723 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2724 &target_core_alua_tg_pt_gp_cit
);
2726 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
2727 " Group: alua/tg_pt_gps/%s\n",
2728 config_item_name(alua_tg_pt_gp_ci
));
2730 return alua_tg_pt_gp_cg
;
2733 static void target_core_alua_drop_tg_pt_gp(
2734 struct config_group
*group
,
2735 struct config_item
*item
)
2737 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2738 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2740 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
2741 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2742 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2744 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2745 * -> target_core_alua_tg_pt_gp_release().
2747 config_item_put(item
);
2750 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2751 .make_group
= &target_core_alua_create_tg_pt_gp
,
2752 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2755 TB_CIT_SETUP(dev_alua_tg_pt_gps
, NULL
, &target_core_alua_tg_pt_gps_group_ops
, NULL
);
2757 /* End functions for struct config_item_type tb_alua_tg_pt_gps_cit */
2759 /* Start functions for struct config_item_type target_core_alua_cit */
2762 * target_core_alua_cit is a ConfigFS group that lives under
2763 * /sys/kernel/config/target/core/alua. There are default groups
2764 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2765 * target_core_alua_cit in target_core_init_configfs() below.
2767 static struct config_item_type target_core_alua_cit
= {
2768 .ct_item_ops
= NULL
,
2770 .ct_owner
= THIS_MODULE
,
2773 /* End functions for struct config_item_type target_core_alua_cit */
2775 /* Start functions for struct config_item_type tb_dev_stat_cit */
2777 static struct config_group
*target_core_stat_mkdir(
2778 struct config_group
*group
,
2781 return ERR_PTR(-ENOSYS
);
2784 static void target_core_stat_rmdir(
2785 struct config_group
*group
,
2786 struct config_item
*item
)
2791 static struct configfs_group_operations target_core_stat_group_ops
= {
2792 .make_group
= &target_core_stat_mkdir
,
2793 .drop_item
= &target_core_stat_rmdir
,
2796 TB_CIT_SETUP(dev_stat
, NULL
, &target_core_stat_group_ops
, NULL
);
2798 /* End functions for struct config_item_type tb_dev_stat_cit */
2800 /* Start functions for struct config_item_type target_core_hba_cit */
2802 static struct config_group
*target_core_make_subdev(
2803 struct config_group
*group
,
2806 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2807 struct config_item
*hba_ci
= &group
->cg_item
;
2808 struct se_hba
*hba
= item_to_hba(hba_ci
);
2809 struct target_backend
*tb
= hba
->backend
;
2810 struct se_device
*dev
;
2811 int errno
= -ENOMEM
, ret
;
2813 ret
= mutex_lock_interruptible(&hba
->hba_access_mutex
);
2815 return ERR_PTR(ret
);
2817 dev
= target_alloc_device(hba
, name
);
2821 config_group_init_type_name(&dev
->dev_group
, name
, &tb
->tb_dev_cit
);
2823 config_group_init_type_name(&dev
->dev_attrib
.da_group
, "attrib",
2824 &tb
->tb_dev_attrib_cit
);
2825 configfs_add_default_group(&dev
->dev_attrib
.da_group
, &dev
->dev_group
);
2827 config_group_init_type_name(&dev
->dev_pr_group
, "pr",
2828 &tb
->tb_dev_pr_cit
);
2829 configfs_add_default_group(&dev
->dev_pr_group
, &dev
->dev_group
);
2831 config_group_init_type_name(&dev
->t10_wwn
.t10_wwn_group
, "wwn",
2832 &tb
->tb_dev_wwn_cit
);
2833 configfs_add_default_group(&dev
->t10_wwn
.t10_wwn_group
,
2836 config_group_init_type_name(&dev
->t10_alua
.alua_tg_pt_gps_group
,
2837 "alua", &tb
->tb_dev_alua_tg_pt_gps_cit
);
2838 configfs_add_default_group(&dev
->t10_alua
.alua_tg_pt_gps_group
,
2841 config_group_init_type_name(&dev
->dev_stat_grps
.stat_group
,
2842 "statistics", &tb
->tb_dev_stat_cit
);
2843 configfs_add_default_group(&dev
->dev_stat_grps
.stat_group
,
2847 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
2849 tg_pt_gp
= core_alua_allocate_tg_pt_gp(dev
, "default_tg_pt_gp", 1);
2851 goto out_free_device
;
2852 dev
->t10_alua
.default_tg_pt_gp
= tg_pt_gp
;
2854 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2855 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2856 configfs_add_default_group(&tg_pt_gp
->tg_pt_gp_group
,
2857 &dev
->t10_alua
.alua_tg_pt_gps_group
);
2860 * Add core/$HBA/$DEV/statistics/ default groups
2862 target_stat_setup_dev_default_groups(dev
);
2864 mutex_unlock(&hba
->hba_access_mutex
);
2865 return &dev
->dev_group
;
2868 target_free_device(dev
);
2870 mutex_unlock(&hba
->hba_access_mutex
);
2871 return ERR_PTR(errno
);
2874 static void target_core_drop_subdev(
2875 struct config_group
*group
,
2876 struct config_item
*item
)
2878 struct config_group
*dev_cg
= to_config_group(item
);
2879 struct se_device
*dev
=
2880 container_of(dev_cg
, struct se_device
, dev_group
);
2883 hba
= item_to_hba(&dev
->se_hba
->hba_group
.cg_item
);
2885 mutex_lock(&hba
->hba_access_mutex
);
2887 configfs_remove_default_groups(&dev
->dev_stat_grps
.stat_group
);
2888 configfs_remove_default_groups(&dev
->t10_alua
.alua_tg_pt_gps_group
);
2891 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2892 * directly from target_core_alua_tg_pt_gp_release().
2894 dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2896 configfs_remove_default_groups(dev_cg
);
2899 * se_dev is released from target_core_dev_item_ops->release()
2901 config_item_put(item
);
2902 mutex_unlock(&hba
->hba_access_mutex
);
2905 static struct configfs_group_operations target_core_hba_group_ops
= {
2906 .make_group
= target_core_make_subdev
,
2907 .drop_item
= target_core_drop_subdev
,
2911 static inline struct se_hba
*to_hba(struct config_item
*item
)
2913 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
2916 static ssize_t
target_hba_info_show(struct config_item
*item
, char *page
)
2918 struct se_hba
*hba
= to_hba(item
);
2920 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
2921 hba
->hba_id
, hba
->backend
->ops
->name
,
2922 TARGET_CORE_VERSION
);
2925 static ssize_t
target_hba_mode_show(struct config_item
*item
, char *page
)
2927 struct se_hba
*hba
= to_hba(item
);
2930 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
2933 return sprintf(page
, "%d\n", hba_mode
);
2936 static ssize_t
target_hba_mode_store(struct config_item
*item
,
2937 const char *page
, size_t count
)
2939 struct se_hba
*hba
= to_hba(item
);
2940 unsigned long mode_flag
;
2943 if (hba
->backend
->ops
->pmode_enable_hba
== NULL
)
2946 ret
= kstrtoul(page
, 0, &mode_flag
);
2948 pr_err("Unable to extract hba mode flag: %d\n", ret
);
2952 if (hba
->dev_count
) {
2953 pr_err("Unable to set hba_mode with active devices\n");
2957 ret
= hba
->backend
->ops
->pmode_enable_hba(hba
, mode_flag
);
2961 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
2963 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
2968 CONFIGFS_ATTR_RO(target_
, hba_info
);
2969 CONFIGFS_ATTR(target_
, hba_mode
);
2971 static void target_core_hba_release(struct config_item
*item
)
2973 struct se_hba
*hba
= container_of(to_config_group(item
),
2974 struct se_hba
, hba_group
);
2975 core_delete_hba(hba
);
2978 static struct configfs_attribute
*target_core_hba_attrs
[] = {
2979 &target_attr_hba_info
,
2980 &target_attr_hba_mode
,
2984 static struct configfs_item_operations target_core_hba_item_ops
= {
2985 .release
= target_core_hba_release
,
2988 static struct config_item_type target_core_hba_cit
= {
2989 .ct_item_ops
= &target_core_hba_item_ops
,
2990 .ct_group_ops
= &target_core_hba_group_ops
,
2991 .ct_attrs
= target_core_hba_attrs
,
2992 .ct_owner
= THIS_MODULE
,
2995 static struct config_group
*target_core_call_addhbatotarget(
2996 struct config_group
*group
,
2999 char *se_plugin_str
, *str
, *str2
;
3001 char buf
[TARGET_CORE_NAME_MAX_LEN
];
3002 unsigned long plugin_dep_id
= 0;
3005 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
3006 if (strlen(name
) >= TARGET_CORE_NAME_MAX_LEN
) {
3007 pr_err("Passed *name strlen(): %d exceeds"
3008 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
3009 TARGET_CORE_NAME_MAX_LEN
);
3010 return ERR_PTR(-ENAMETOOLONG
);
3012 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
3014 str
= strstr(buf
, "_");
3016 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
3017 return ERR_PTR(-EINVAL
);
3019 se_plugin_str
= buf
;
3021 * Special case for subsystem plugins that have "_" in their names.
3022 * Namely rd_direct and rd_mcp..
3024 str2
= strstr(str
+1, "_");
3026 *str2
= '\0'; /* Terminate for *se_plugin_str */
3027 str2
++; /* Skip to start of plugin dependent ID */
3030 *str
= '\0'; /* Terminate for *se_plugin_str */
3031 str
++; /* Skip to start of plugin dependent ID */
3034 ret
= kstrtoul(str
, 0, &plugin_dep_id
);
3036 pr_err("kstrtoul() returned %d for"
3037 " plugin_dep_id\n", ret
);
3038 return ERR_PTR(ret
);
3041 * Load up TCM subsystem plugins if they have not already been loaded.
3043 transport_subsystem_check_init();
3045 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
3047 return ERR_CAST(hba
);
3049 config_group_init_type_name(&hba
->hba_group
, name
,
3050 &target_core_hba_cit
);
3052 return &hba
->hba_group
;
3055 static void target_core_call_delhbafromtarget(
3056 struct config_group
*group
,
3057 struct config_item
*item
)
3060 * core_delete_hba() is called from target_core_hba_item_ops->release()
3061 * -> target_core_hba_release()
3063 config_item_put(item
);
3066 static struct configfs_group_operations target_core_group_ops
= {
3067 .make_group
= target_core_call_addhbatotarget
,
3068 .drop_item
= target_core_call_delhbafromtarget
,
3071 static struct config_item_type target_core_cit
= {
3072 .ct_item_ops
= NULL
,
3073 .ct_group_ops
= &target_core_group_ops
,
3075 .ct_owner
= THIS_MODULE
,
3078 /* Stop functions for struct config_item_type target_core_hba_cit */
3080 void target_setup_backend_cits(struct target_backend
*tb
)
3082 target_core_setup_dev_cit(tb
);
3083 target_core_setup_dev_attrib_cit(tb
);
3084 target_core_setup_dev_pr_cit(tb
);
3085 target_core_setup_dev_wwn_cit(tb
);
3086 target_core_setup_dev_alua_tg_pt_gps_cit(tb
);
3087 target_core_setup_dev_stat_cit(tb
);
3090 static int __init
target_core_init_configfs(void)
3092 struct configfs_subsystem
*subsys
= &target_core_fabrics
;
3093 struct t10_alua_lu_gp
*lu_gp
;
3096 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
3097 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
3098 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
3100 config_group_init(&subsys
->su_group
);
3101 mutex_init(&subsys
->su_mutex
);
3103 ret
= init_se_kmem_caches();
3107 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
3108 * and ALUA Logical Unit Group and Target Port Group infrastructure.
3110 config_group_init_type_name(&target_core_hbagroup
, "core",
3112 configfs_add_default_group(&target_core_hbagroup
, &subsys
->su_group
);
3115 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
3117 config_group_init_type_name(&alua_group
, "alua", &target_core_alua_cit
);
3118 configfs_add_default_group(&alua_group
, &target_core_hbagroup
);
3121 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
3122 * groups under /sys/kernel/config/target/core/alua/
3124 config_group_init_type_name(&alua_lu_gps_group
, "lu_gps",
3125 &target_core_alua_lu_gps_cit
);
3126 configfs_add_default_group(&alua_lu_gps_group
, &alua_group
);
3129 * Add core/alua/lu_gps/default_lu_gp
3131 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
3132 if (IS_ERR(lu_gp
)) {
3137 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
3138 &target_core_alua_lu_gp_cit
);
3139 configfs_add_default_group(&lu_gp
->lu_gp_group
, &alua_lu_gps_group
);
3141 default_lu_gp
= lu_gp
;
3144 * Register the target_core_mod subsystem with configfs.
3146 ret
= configfs_register_subsystem(subsys
);
3148 pr_err("Error %d while registering subsystem %s\n",
3149 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
3152 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
3153 " Infrastructure: "TARGET_CORE_VERSION
" on %s/%s"
3154 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
3156 * Register built-in RAMDISK subsystem logic for virtual LUN 0
3158 ret
= rd_module_init();
3162 ret
= core_dev_setup_virtual_lun0();
3166 ret
= target_xcopy_setup_pt();
3173 configfs_unregister_subsystem(subsys
);
3174 core_dev_release_virtual_lun0();
3177 if (default_lu_gp
) {
3178 core_alua_free_lu_gp(default_lu_gp
);
3179 default_lu_gp
= NULL
;
3181 release_se_kmem_caches();
3185 static void __exit
target_core_exit_configfs(void)
3187 configfs_remove_default_groups(&alua_lu_gps_group
);
3188 configfs_remove_default_groups(&alua_group
);
3189 configfs_remove_default_groups(&target_core_hbagroup
);
3192 * We expect subsys->su_group.default_groups to be released
3193 * by configfs subsystem provider logic..
3195 configfs_unregister_subsystem(&target_core_fabrics
);
3197 core_alua_free_lu_gp(default_lu_gp
);
3198 default_lu_gp
= NULL
;
3200 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
3201 " Infrastructure\n");
3203 core_dev_release_virtual_lun0();
3205 target_xcopy_release_pt();
3206 release_se_kmem_caches();
3209 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3210 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3211 MODULE_LICENSE("GPL");
3213 module_init(target_core_init_configfs
);
3214 module_exit(target_core_exit_configfs
);