1 /*******************************************************************************
2 * Filename: target_core_configfs.c
4 * This file contains ConfigFS logic for the Generic Target Engine project.
6 * (c) Copyright 2008-2013 Datera, Inc.
8 * Nicholas A. Bellinger <nab@kernel.org>
10 * based on configfs Copyright (C) 2005 Oracle. All rights reserved.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 ****************************************************************************/
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <generated/utsrelease.h>
26 #include <linux/utsname.h>
27 #include <linux/init.h>
29 #include <linux/namei.h>
30 #include <linux/slab.h>
31 #include <linux/types.h>
32 #include <linux/delay.h>
33 #include <linux/unistd.h>
34 #include <linux/string.h>
35 #include <linux/parser.h>
36 #include <linux/syscalls.h>
37 #include <linux/configfs.h>
38 #include <linux/spinlock.h>
40 #include <target/target_core_base.h>
41 #include <target/target_core_backend.h>
42 #include <target/target_core_fabric.h>
43 #include <target/target_core_fabric_configfs.h>
44 #include <target/target_core_configfs.h>
45 #include <target/configfs_macros.h>
47 #include "target_core_internal.h"
48 #include "target_core_alua.h"
49 #include "target_core_pr.h"
50 #include "target_core_rd.h"
51 #include "target_core_xcopy.h"
53 #define TB_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \
54 static void target_core_setup_##_name##_cit(struct target_backend *tb) \
56 struct config_item_type *cit = &tb->tb_##_name##_cit; \
58 cit->ct_item_ops = _item_ops; \
59 cit->ct_group_ops = _group_ops; \
60 cit->ct_attrs = _attrs; \
61 cit->ct_owner = tb->ops->owner; \
62 pr_debug("Setup generic %s\n", __stringify(_name)); \
65 #define TB_CIT_SETUP_DRV(_name, _item_ops, _group_ops) \
66 static void target_core_setup_##_name##_cit(struct target_backend *tb) \
68 struct config_item_type *cit = &tb->tb_##_name##_cit; \
70 cit->ct_item_ops = _item_ops; \
71 cit->ct_group_ops = _group_ops; \
72 cit->ct_attrs = tb->ops->tb_##_name##_attrs; \
73 cit->ct_owner = tb->ops->owner; \
74 pr_debug("Setup generic %s\n", __stringify(_name)); \
77 extern struct t10_alua_lu_gp
*default_lu_gp
;
79 static LIST_HEAD(g_tf_list
);
80 static DEFINE_MUTEX(g_tf_lock
);
82 struct target_core_configfs_attribute
{
83 struct configfs_attribute attr
;
84 ssize_t (*show
)(void *, char *);
85 ssize_t (*store
)(void *, const char *, size_t);
88 static struct config_group target_core_hbagroup
;
89 static struct config_group alua_group
;
90 static struct config_group alua_lu_gps_group
;
92 static inline struct se_hba
*
93 item_to_hba(struct config_item
*item
)
95 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
99 * Attributes for /sys/kernel/config/target/
101 static ssize_t
target_core_attr_show(struct config_item
*item
,
102 struct configfs_attribute
*attr
,
105 return sprintf(page
, "Target Engine Core ConfigFS Infrastructure %s"
106 " on %s/%s on "UTS_RELEASE
"\n", TARGET_CORE_CONFIGFS_VERSION
,
107 utsname()->sysname
, utsname()->machine
);
110 static struct configfs_item_operations target_core_fabric_item_ops
= {
111 .show_attribute
= target_core_attr_show
,
114 static struct configfs_attribute target_core_item_attr_version
= {
115 .ca_owner
= THIS_MODULE
,
116 .ca_name
= "version",
120 static struct target_fabric_configfs
*target_core_get_fabric(
123 struct target_fabric_configfs
*tf
;
128 mutex_lock(&g_tf_lock
);
129 list_for_each_entry(tf
, &g_tf_list
, tf_list
) {
130 if (!strcmp(tf
->tf_ops
->name
, name
)) {
131 atomic_inc(&tf
->tf_access_cnt
);
132 mutex_unlock(&g_tf_lock
);
136 mutex_unlock(&g_tf_lock
);
142 * Called from struct target_core_group_ops->make_group()
144 static struct config_group
*target_core_register_fabric(
145 struct config_group
*group
,
148 struct target_fabric_configfs
*tf
;
151 pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:"
152 " %s\n", group
, name
);
154 tf
= target_core_get_fabric(name
);
156 pr_debug("target_core_register_fabric() trying autoload for %s\n",
160 * Below are some hardcoded request_module() calls to automatically
161 * local fabric modules when the following is called:
163 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
165 * Note that this does not limit which TCM fabric module can be
166 * registered, but simply provids auto loading logic for modules with
167 * mkdir(2) system calls with known TCM fabric modules.
170 if (!strncmp(name
, "iscsi", 5)) {
172 * Automatically load the LIO Target fabric module when the
173 * following is called:
175 * mkdir -p $CONFIGFS/target/iscsi
177 ret
= request_module("iscsi_target_mod");
179 pr_debug("request_module() failed for"
180 " iscsi_target_mod.ko: %d\n", ret
);
181 return ERR_PTR(-EINVAL
);
183 } else if (!strncmp(name
, "loopback", 8)) {
185 * Automatically load the tcm_loop fabric module when the
186 * following is called:
188 * mkdir -p $CONFIGFS/target/loopback
190 ret
= request_module("tcm_loop");
192 pr_debug("request_module() failed for"
193 " tcm_loop.ko: %d\n", ret
);
194 return ERR_PTR(-EINVAL
);
198 tf
= target_core_get_fabric(name
);
202 pr_debug("target_core_get_fabric() failed for %s\n",
204 return ERR_PTR(-EINVAL
);
206 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
207 " %s\n", tf
->tf_ops
->name
);
209 * On a successful target_core_get_fabric() look, the returned
210 * struct target_fabric_configfs *tf will contain a usage reference.
212 pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
215 tf
->tf_group
.default_groups
= tf
->tf_default_groups
;
216 tf
->tf_group
.default_groups
[0] = &tf
->tf_disc_group
;
217 tf
->tf_group
.default_groups
[1] = NULL
;
219 config_group_init_type_name(&tf
->tf_group
, name
, &tf
->tf_wwn_cit
);
220 config_group_init_type_name(&tf
->tf_disc_group
, "discovery_auth",
221 &tf
->tf_discovery_cit
);
223 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
224 " %s\n", tf
->tf_group
.cg_item
.ci_name
);
225 return &tf
->tf_group
;
229 * Called from struct target_core_group_ops->drop_item()
231 static void target_core_deregister_fabric(
232 struct config_group
*group
,
233 struct config_item
*item
)
235 struct target_fabric_configfs
*tf
= container_of(
236 to_config_group(item
), struct target_fabric_configfs
, tf_group
);
237 struct config_group
*tf_group
;
238 struct config_item
*df_item
;
241 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
242 " tf list\n", config_item_name(item
));
244 pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:"
245 " %s\n", tf
->tf_ops
->name
);
246 atomic_dec(&tf
->tf_access_cnt
);
248 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
249 " %s\n", config_item_name(item
));
251 tf_group
= &tf
->tf_group
;
252 for (i
= 0; tf_group
->default_groups
[i
]; i
++) {
253 df_item
= &tf_group
->default_groups
[i
]->cg_item
;
254 tf_group
->default_groups
[i
] = NULL
;
255 config_item_put(df_item
);
257 config_item_put(item
);
260 static struct configfs_group_operations target_core_fabric_group_ops
= {
261 .make_group
= &target_core_register_fabric
,
262 .drop_item
= &target_core_deregister_fabric
,
266 * All item attributes appearing in /sys/kernel/target/ appear here.
268 static struct configfs_attribute
*target_core_fabric_item_attrs
[] = {
269 &target_core_item_attr_version
,
274 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
276 static struct config_item_type target_core_fabrics_item
= {
277 .ct_item_ops
= &target_core_fabric_item_ops
,
278 .ct_group_ops
= &target_core_fabric_group_ops
,
279 .ct_attrs
= target_core_fabric_item_attrs
,
280 .ct_owner
= THIS_MODULE
,
283 static struct configfs_subsystem target_core_fabrics
= {
286 .ci_namebuf
= "target",
287 .ci_type
= &target_core_fabrics_item
,
292 int target_depend_item(struct config_item
*item
)
294 return configfs_depend_item(&target_core_fabrics
, item
);
296 EXPORT_SYMBOL(target_depend_item
);
298 void target_undepend_item(struct config_item
*item
)
300 return configfs_undepend_item(&target_core_fabrics
, item
);
302 EXPORT_SYMBOL(target_undepend_item
);
304 /*##############################################################################
305 // Start functions called by external Target Fabrics Modules
306 //############################################################################*/
308 static int target_fabric_tf_ops_check(const struct target_core_fabric_ops
*tfo
)
311 pr_err("Missing tfo->name\n");
314 if (strlen(tfo
->name
) >= TARGET_FABRIC_NAME_SIZE
) {
315 pr_err("Passed name: %s exceeds TARGET_FABRIC"
316 "_NAME_SIZE\n", tfo
->name
);
319 if (!tfo
->get_fabric_name
) {
320 pr_err("Missing tfo->get_fabric_name()\n");
323 if (!tfo
->tpg_get_wwn
) {
324 pr_err("Missing tfo->tpg_get_wwn()\n");
327 if (!tfo
->tpg_get_tag
) {
328 pr_err("Missing tfo->tpg_get_tag()\n");
331 if (!tfo
->tpg_check_demo_mode
) {
332 pr_err("Missing tfo->tpg_check_demo_mode()\n");
335 if (!tfo
->tpg_check_demo_mode_cache
) {
336 pr_err("Missing tfo->tpg_check_demo_mode_cache()\n");
339 if (!tfo
->tpg_check_demo_mode_write_protect
) {
340 pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n");
343 if (!tfo
->tpg_check_prod_mode_write_protect
) {
344 pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n");
347 if (!tfo
->tpg_get_inst_index
) {
348 pr_err("Missing tfo->tpg_get_inst_index()\n");
351 if (!tfo
->release_cmd
) {
352 pr_err("Missing tfo->release_cmd()\n");
355 if (!tfo
->shutdown_session
) {
356 pr_err("Missing tfo->shutdown_session()\n");
359 if (!tfo
->close_session
) {
360 pr_err("Missing tfo->close_session()\n");
363 if (!tfo
->sess_get_index
) {
364 pr_err("Missing tfo->sess_get_index()\n");
367 if (!tfo
->write_pending
) {
368 pr_err("Missing tfo->write_pending()\n");
371 if (!tfo
->write_pending_status
) {
372 pr_err("Missing tfo->write_pending_status()\n");
375 if (!tfo
->set_default_node_attributes
) {
376 pr_err("Missing tfo->set_default_node_attributes()\n");
379 if (!tfo
->get_cmd_state
) {
380 pr_err("Missing tfo->get_cmd_state()\n");
383 if (!tfo
->queue_data_in
) {
384 pr_err("Missing tfo->queue_data_in()\n");
387 if (!tfo
->queue_status
) {
388 pr_err("Missing tfo->queue_status()\n");
391 if (!tfo
->queue_tm_rsp
) {
392 pr_err("Missing tfo->queue_tm_rsp()\n");
395 if (!tfo
->aborted_task
) {
396 pr_err("Missing tfo->aborted_task()\n");
400 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
401 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
402 * target_core_fabric_configfs.c WWN+TPG group context code.
404 if (!tfo
->fabric_make_wwn
) {
405 pr_err("Missing tfo->fabric_make_wwn()\n");
408 if (!tfo
->fabric_drop_wwn
) {
409 pr_err("Missing tfo->fabric_drop_wwn()\n");
412 if (!tfo
->fabric_make_tpg
) {
413 pr_err("Missing tfo->fabric_make_tpg()\n");
416 if (!tfo
->fabric_drop_tpg
) {
417 pr_err("Missing tfo->fabric_drop_tpg()\n");
424 int target_register_template(const struct target_core_fabric_ops
*fo
)
426 struct target_fabric_configfs
*tf
;
429 ret
= target_fabric_tf_ops_check(fo
);
433 tf
= kzalloc(sizeof(struct target_fabric_configfs
), GFP_KERNEL
);
435 pr_err("%s: could not allocate memory!\n", __func__
);
439 INIT_LIST_HEAD(&tf
->tf_list
);
440 atomic_set(&tf
->tf_access_cnt
, 0);
442 target_fabric_setup_cits(tf
);
444 mutex_lock(&g_tf_lock
);
445 list_add_tail(&tf
->tf_list
, &g_tf_list
);
446 mutex_unlock(&g_tf_lock
);
450 EXPORT_SYMBOL(target_register_template
);
452 void target_unregister_template(const struct target_core_fabric_ops
*fo
)
454 struct target_fabric_configfs
*t
;
456 mutex_lock(&g_tf_lock
);
457 list_for_each_entry(t
, &g_tf_list
, tf_list
) {
458 if (!strcmp(t
->tf_ops
->name
, fo
->name
)) {
459 BUG_ON(atomic_read(&t
->tf_access_cnt
));
460 list_del(&t
->tf_list
);
465 mutex_unlock(&g_tf_lock
);
467 EXPORT_SYMBOL(target_unregister_template
);
469 /*##############################################################################
470 // Stop functions called by external Target Fabrics Modules
471 //############################################################################*/
473 /* Start functions for struct config_item_type tb_dev_attrib_cit */
474 #define DEF_TB_DEV_ATTRIB_SHOW(_name) \
475 static ssize_t show_##_name(struct se_dev_attrib *da, char *page) \
477 return snprintf(page, PAGE_SIZE, "%u\n", da->_name); \
480 DEF_TB_DEV_ATTRIB_SHOW(emulate_model_alias
);
481 DEF_TB_DEV_ATTRIB_SHOW(emulate_dpo
);
482 DEF_TB_DEV_ATTRIB_SHOW(emulate_fua_write
);
483 DEF_TB_DEV_ATTRIB_SHOW(emulate_fua_read
);
484 DEF_TB_DEV_ATTRIB_SHOW(emulate_write_cache
);
485 DEF_TB_DEV_ATTRIB_SHOW(emulate_ua_intlck_ctrl
);
486 DEF_TB_DEV_ATTRIB_SHOW(emulate_tas
);
487 DEF_TB_DEV_ATTRIB_SHOW(emulate_tpu
);
488 DEF_TB_DEV_ATTRIB_SHOW(emulate_tpws
);
489 DEF_TB_DEV_ATTRIB_SHOW(emulate_caw
);
490 DEF_TB_DEV_ATTRIB_SHOW(emulate_3pc
);
491 DEF_TB_DEV_ATTRIB_SHOW(pi_prot_type
);
492 DEF_TB_DEV_ATTRIB_SHOW(hw_pi_prot_type
);
493 DEF_TB_DEV_ATTRIB_SHOW(pi_prot_format
);
494 DEF_TB_DEV_ATTRIB_SHOW(enforce_pr_isids
);
495 DEF_TB_DEV_ATTRIB_SHOW(is_nonrot
);
496 DEF_TB_DEV_ATTRIB_SHOW(emulate_rest_reord
);
497 DEF_TB_DEV_ATTRIB_SHOW(force_pr_aptpl
);
498 DEF_TB_DEV_ATTRIB_SHOW(hw_block_size
);
499 DEF_TB_DEV_ATTRIB_SHOW(block_size
);
500 DEF_TB_DEV_ATTRIB_SHOW(hw_max_sectors
);
501 DEF_TB_DEV_ATTRIB_SHOW(optimal_sectors
);
502 DEF_TB_DEV_ATTRIB_SHOW(hw_queue_depth
);
503 DEF_TB_DEV_ATTRIB_SHOW(queue_depth
);
504 DEF_TB_DEV_ATTRIB_SHOW(max_unmap_lba_count
);
505 DEF_TB_DEV_ATTRIB_SHOW(max_unmap_block_desc_count
);
506 DEF_TB_DEV_ATTRIB_SHOW(unmap_granularity
);
507 DEF_TB_DEV_ATTRIB_SHOW(unmap_granularity_alignment
);
508 DEF_TB_DEV_ATTRIB_SHOW(max_write_same_len
);
510 #define DEF_TB_DEV_ATTRIB_STORE_U32(_name) \
511 static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\
517 ret = kstrtou32(page, 0, &val); \
524 DEF_TB_DEV_ATTRIB_STORE_U32(max_unmap_lba_count
);
525 DEF_TB_DEV_ATTRIB_STORE_U32(max_unmap_block_desc_count
);
526 DEF_TB_DEV_ATTRIB_STORE_U32(unmap_granularity
);
527 DEF_TB_DEV_ATTRIB_STORE_U32(unmap_granularity_alignment
);
528 DEF_TB_DEV_ATTRIB_STORE_U32(max_write_same_len
);
530 #define DEF_TB_DEV_ATTRIB_STORE_BOOL(_name) \
531 static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\
537 ret = strtobool(page, &flag); \
544 DEF_TB_DEV_ATTRIB_STORE_BOOL(emulate_fua_write
);
545 DEF_TB_DEV_ATTRIB_STORE_BOOL(emulate_caw
);
546 DEF_TB_DEV_ATTRIB_STORE_BOOL(emulate_3pc
);
547 DEF_TB_DEV_ATTRIB_STORE_BOOL(enforce_pr_isids
);
548 DEF_TB_DEV_ATTRIB_STORE_BOOL(is_nonrot
);
550 #define DEF_TB_DEV_ATTRIB_STORE_STUB(_name) \
551 static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\
554 printk_once(KERN_WARNING \
555 "ignoring deprecated ##_name## attribute\n"); \
559 DEF_TB_DEV_ATTRIB_STORE_STUB(emulate_dpo
);
560 DEF_TB_DEV_ATTRIB_STORE_STUB(emulate_fua_read
);
562 static void dev_set_t10_wwn_model_alias(struct se_device
*dev
)
564 const char *configname
;
566 configname
= config_item_name(&dev
->dev_group
.cg_item
);
567 if (strlen(configname
) >= 16) {
568 pr_warn("dev[%p]: Backstore name '%s' is too long for "
569 "INQUIRY_MODEL, truncating to 16 bytes\n", dev
,
572 snprintf(&dev
->t10_wwn
.model
[0], 16, "%s", configname
);
575 static ssize_t
store_emulate_model_alias(struct se_dev_attrib
*da
,
576 const char *page
, size_t count
)
578 struct se_device
*dev
= da
->da_dev
;
582 if (dev
->export_count
) {
583 pr_err("dev[%p]: Unable to change model alias"
584 " while export_count is %d\n",
585 dev
, dev
->export_count
);
589 ret
= strtobool(page
, &flag
);
594 dev_set_t10_wwn_model_alias(dev
);
596 strncpy(&dev
->t10_wwn
.model
[0],
597 dev
->transport
->inquiry_prod
, 16);
599 da
->emulate_model_alias
= flag
;
603 static ssize_t
store_emulate_write_cache(struct se_dev_attrib
*da
,
604 const char *page
, size_t count
)
609 ret
= strtobool(page
, &flag
);
613 if (flag
&& da
->da_dev
->transport
->get_write_cache
) {
614 pr_err("emulate_write_cache not supported for this device\n");
618 da
->emulate_write_cache
= flag
;
619 pr_debug("dev[%p]: SE Device WRITE_CACHE_EMULATION flag: %d\n",
624 static ssize_t
store_emulate_ua_intlck_ctrl(struct se_dev_attrib
*da
,
625 const char *page
, size_t count
)
630 ret
= kstrtou32(page
, 0, &val
);
634 if (val
!= 0 && val
!= 1 && val
!= 2) {
635 pr_err("Illegal value %d\n", val
);
639 if (da
->da_dev
->export_count
) {
640 pr_err("dev[%p]: Unable to change SE Device"
641 " UA_INTRLCK_CTRL while export_count is %d\n",
642 da
->da_dev
, da
->da_dev
->export_count
);
645 da
->emulate_ua_intlck_ctrl
= val
;
646 pr_debug("dev[%p]: SE Device UA_INTRLCK_CTRL flag: %d\n",
651 static ssize_t
store_emulate_tas(struct se_dev_attrib
*da
,
652 const char *page
, size_t count
)
657 ret
= strtobool(page
, &flag
);
661 if (da
->da_dev
->export_count
) {
662 pr_err("dev[%p]: Unable to change SE Device TAS while"
663 " export_count is %d\n",
664 da
->da_dev
, da
->da_dev
->export_count
);
667 da
->emulate_tas
= flag
;
668 pr_debug("dev[%p]: SE Device TASK_ABORTED status bit: %s\n",
669 da
->da_dev
, flag
? "Enabled" : "Disabled");
674 static ssize_t
store_emulate_tpu(struct se_dev_attrib
*da
,
675 const char *page
, size_t count
)
680 ret
= strtobool(page
, &flag
);
685 * We expect this value to be non-zero when generic Block Layer
686 * Discard supported is detected iblock_create_virtdevice().
688 if (flag
&& !da
->max_unmap_block_desc_count
) {
689 pr_err("Generic Block Discard not supported\n");
693 da
->emulate_tpu
= flag
;
694 pr_debug("dev[%p]: SE Device Thin Provisioning UNMAP bit: %d\n",
699 static ssize_t
store_emulate_tpws(struct se_dev_attrib
*da
,
700 const char *page
, size_t count
)
705 ret
= strtobool(page
, &flag
);
710 * We expect this value to be non-zero when generic Block Layer
711 * Discard supported is detected iblock_create_virtdevice().
713 if (flag
&& !da
->max_unmap_block_desc_count
) {
714 pr_err("Generic Block Discard not supported\n");
718 da
->emulate_tpws
= flag
;
719 pr_debug("dev[%p]: SE Device Thin Provisioning WRITE_SAME: %d\n",
724 static ssize_t
store_pi_prot_type(struct se_dev_attrib
*da
,
725 const char *page
, size_t count
)
727 int old_prot
= da
->pi_prot_type
, ret
;
728 struct se_device
*dev
= da
->da_dev
;
731 ret
= kstrtou32(page
, 0, &flag
);
735 if (flag
!= 0 && flag
!= 1 && flag
!= 2 && flag
!= 3) {
736 pr_err("Illegal value %d for pi_prot_type\n", flag
);
740 pr_err("DIF TYPE2 protection currently not supported\n");
743 if (da
->hw_pi_prot_type
) {
744 pr_warn("DIF protection enabled on underlying hardware,"
748 if (!dev
->transport
->init_prot
|| !dev
->transport
->free_prot
) {
749 /* 0 is only allowed value for non-supporting backends */
753 pr_err("DIF protection not supported by backend: %s\n",
754 dev
->transport
->name
);
757 if (!(dev
->dev_flags
& DF_CONFIGURED
)) {
758 pr_err("DIF protection requires device to be configured\n");
761 if (dev
->export_count
) {
762 pr_err("dev[%p]: Unable to change SE Device PROT type while"
763 " export_count is %d\n", dev
, dev
->export_count
);
767 da
->pi_prot_type
= flag
;
769 if (flag
&& !old_prot
) {
770 ret
= dev
->transport
->init_prot(dev
);
772 da
->pi_prot_type
= old_prot
;
776 } else if (!flag
&& old_prot
) {
777 dev
->transport
->free_prot(dev
);
780 pr_debug("dev[%p]: SE Device Protection Type: %d\n", dev
, flag
);
784 static ssize_t
store_pi_prot_format(struct se_dev_attrib
*da
,
785 const char *page
, size_t count
)
787 struct se_device
*dev
= da
->da_dev
;
791 ret
= strtobool(page
, &flag
);
798 if (!dev
->transport
->format_prot
) {
799 pr_err("DIF protection format not supported by backend %s\n",
800 dev
->transport
->name
);
803 if (!(dev
->dev_flags
& DF_CONFIGURED
)) {
804 pr_err("DIF protection format requires device to be configured\n");
807 if (dev
->export_count
) {
808 pr_err("dev[%p]: Unable to format SE Device PROT type while"
809 " export_count is %d\n", dev
, dev
->export_count
);
813 ret
= dev
->transport
->format_prot(dev
);
817 pr_debug("dev[%p]: SE Device Protection Format complete\n", dev
);
821 static ssize_t
store_force_pr_aptpl(struct se_dev_attrib
*da
,
822 const char *page
, size_t count
)
827 ret
= strtobool(page
, &flag
);
830 if (da
->da_dev
->export_count
) {
831 pr_err("dev[%p]: Unable to set force_pr_aptpl while"
832 " export_count is %d\n",
833 da
->da_dev
, da
->da_dev
->export_count
);
837 da
->force_pr_aptpl
= flag
;
838 pr_debug("dev[%p]: SE Device force_pr_aptpl: %d\n", da
->da_dev
, flag
);
842 static ssize_t
store_emulate_rest_reord(struct se_dev_attrib
*da
,
843 const char *page
, size_t count
)
848 ret
= strtobool(page
, &flag
);
853 printk(KERN_ERR
"dev[%p]: SE Device emulation of restricted"
854 " reordering not implemented\n", da
->da_dev
);
857 da
->emulate_rest_reord
= flag
;
858 pr_debug("dev[%p]: SE Device emulate_rest_reord: %d\n",
864 * Note, this can only be called on unexported SE Device Object.
866 static ssize_t
store_queue_depth(struct se_dev_attrib
*da
,
867 const char *page
, size_t count
)
869 struct se_device
*dev
= da
->da_dev
;
873 ret
= kstrtou32(page
, 0, &val
);
877 if (dev
->export_count
) {
878 pr_err("dev[%p]: Unable to change SE Device TCQ while"
879 " export_count is %d\n",
880 dev
, dev
->export_count
);
884 pr_err("dev[%p]: Illegal ZERO value for queue_depth\n", dev
);
888 if (val
> dev
->dev_attrib
.queue_depth
) {
889 if (val
> dev
->dev_attrib
.hw_queue_depth
) {
890 pr_err("dev[%p]: Passed queue_depth:"
891 " %u exceeds TCM/SE_Device MAX"
892 " TCQ: %u\n", dev
, val
,
893 dev
->dev_attrib
.hw_queue_depth
);
897 da
->queue_depth
= dev
->queue_depth
= val
;
898 pr_debug("dev[%p]: SE Device TCQ Depth changed to: %u\n", dev
, val
);
902 static ssize_t
store_optimal_sectors(struct se_dev_attrib
*da
,
903 const char *page
, size_t count
)
908 ret
= kstrtou32(page
, 0, &val
);
912 if (da
->da_dev
->export_count
) {
913 pr_err("dev[%p]: Unable to change SE Device"
914 " optimal_sectors while export_count is %d\n",
915 da
->da_dev
, da
->da_dev
->export_count
);
918 if (val
> da
->hw_max_sectors
) {
919 pr_err("dev[%p]: Passed optimal_sectors %u cannot be"
920 " greater than hw_max_sectors: %u\n",
921 da
->da_dev
, val
, da
->hw_max_sectors
);
925 da
->optimal_sectors
= val
;
926 pr_debug("dev[%p]: SE Device optimal_sectors changed to %u\n",
931 static ssize_t
store_block_size(struct se_dev_attrib
*da
,
932 const char *page
, size_t count
)
937 ret
= kstrtou32(page
, 0, &val
);
941 if (da
->da_dev
->export_count
) {
942 pr_err("dev[%p]: Unable to change SE Device block_size"
943 " while export_count is %d\n",
944 da
->da_dev
, da
->da_dev
->export_count
);
948 if (val
!= 512 && val
!= 1024 && val
!= 2048 && val
!= 4096) {
949 pr_err("dev[%p]: Illegal value for block_device: %u"
950 " for SE device, must be 512, 1024, 2048 or 4096\n",
955 da
->block_size
= val
;
956 if (da
->max_bytes_per_io
)
957 da
->hw_max_sectors
= da
->max_bytes_per_io
/ val
;
959 pr_debug("dev[%p]: SE Device block_size changed to %u\n",
964 CONFIGFS_EATTR_STRUCT(target_backend_dev_attrib
, se_dev_attrib
);
965 #define TB_DEV_ATTR(_backend, _name, _mode) \
966 static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name = \
967 __CONFIGFS_EATTR(_name, _mode, \
971 #define TB_DEV_ATTR_RO(_backend, _name) \
972 static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name = \
973 __CONFIGFS_EATTR_RO(_name, \
976 TB_DEV_ATTR(target_core
, emulate_model_alias
, S_IRUGO
| S_IWUSR
);
977 TB_DEV_ATTR(target_core
, emulate_dpo
, S_IRUGO
| S_IWUSR
);
978 TB_DEV_ATTR(target_core
, emulate_fua_write
, S_IRUGO
| S_IWUSR
);
979 TB_DEV_ATTR(target_core
, emulate_fua_read
, S_IRUGO
| S_IWUSR
);
980 TB_DEV_ATTR(target_core
, emulate_write_cache
, S_IRUGO
| S_IWUSR
);
981 TB_DEV_ATTR(target_core
, emulate_ua_intlck_ctrl
, S_IRUGO
| S_IWUSR
);
982 TB_DEV_ATTR(target_core
, emulate_tas
, S_IRUGO
| S_IWUSR
);
983 TB_DEV_ATTR(target_core
, emulate_tpu
, S_IRUGO
| S_IWUSR
);
984 TB_DEV_ATTR(target_core
, emulate_tpws
, S_IRUGO
| S_IWUSR
);
985 TB_DEV_ATTR(target_core
, emulate_caw
, S_IRUGO
| S_IWUSR
);
986 TB_DEV_ATTR(target_core
, emulate_3pc
, S_IRUGO
| S_IWUSR
);
987 TB_DEV_ATTR(target_core
, pi_prot_type
, S_IRUGO
| S_IWUSR
);
988 TB_DEV_ATTR_RO(target_core
, hw_pi_prot_type
);
989 TB_DEV_ATTR(target_core
, pi_prot_format
, S_IRUGO
| S_IWUSR
);
990 TB_DEV_ATTR(target_core
, enforce_pr_isids
, S_IRUGO
| S_IWUSR
);
991 TB_DEV_ATTR(target_core
, is_nonrot
, S_IRUGO
| S_IWUSR
);
992 TB_DEV_ATTR(target_core
, emulate_rest_reord
, S_IRUGO
| S_IWUSR
);
993 TB_DEV_ATTR(target_core
, force_pr_aptpl
, S_IRUGO
| S_IWUSR
)
994 TB_DEV_ATTR_RO(target_core
, hw_block_size
);
995 TB_DEV_ATTR(target_core
, block_size
, S_IRUGO
| S_IWUSR
)
996 TB_DEV_ATTR_RO(target_core
, hw_max_sectors
);
997 TB_DEV_ATTR(target_core
, optimal_sectors
, S_IRUGO
| S_IWUSR
);
998 TB_DEV_ATTR_RO(target_core
, hw_queue_depth
);
999 TB_DEV_ATTR(target_core
, queue_depth
, S_IRUGO
| S_IWUSR
);
1000 TB_DEV_ATTR(target_core
, max_unmap_lba_count
, S_IRUGO
| S_IWUSR
);
1001 TB_DEV_ATTR(target_core
, max_unmap_block_desc_count
, S_IRUGO
| S_IWUSR
);
1002 TB_DEV_ATTR(target_core
, unmap_granularity
, S_IRUGO
| S_IWUSR
);
1003 TB_DEV_ATTR(target_core
, unmap_granularity_alignment
, S_IRUGO
| S_IWUSR
);
1004 TB_DEV_ATTR(target_core
, max_write_same_len
, S_IRUGO
| S_IWUSR
);
1006 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib
, se_dev_attrib
);
1007 CONFIGFS_EATTR_OPS(target_core_dev_attrib
, se_dev_attrib
, da_group
);
1010 * dev_attrib attributes for devices using the target core SBC/SPC
1011 * interpreter. Any backend using spc_parse_cdb should be using
1014 struct configfs_attribute
*sbc_attrib_attrs
[] = {
1015 &target_core_dev_attrib_emulate_model_alias
.attr
,
1016 &target_core_dev_attrib_emulate_dpo
.attr
,
1017 &target_core_dev_attrib_emulate_fua_write
.attr
,
1018 &target_core_dev_attrib_emulate_fua_read
.attr
,
1019 &target_core_dev_attrib_emulate_write_cache
.attr
,
1020 &target_core_dev_attrib_emulate_ua_intlck_ctrl
.attr
,
1021 &target_core_dev_attrib_emulate_tas
.attr
,
1022 &target_core_dev_attrib_emulate_tpu
.attr
,
1023 &target_core_dev_attrib_emulate_tpws
.attr
,
1024 &target_core_dev_attrib_emulate_caw
.attr
,
1025 &target_core_dev_attrib_emulate_3pc
.attr
,
1026 &target_core_dev_attrib_pi_prot_type
.attr
,
1027 &target_core_dev_attrib_hw_pi_prot_type
.attr
,
1028 &target_core_dev_attrib_pi_prot_format
.attr
,
1029 &target_core_dev_attrib_enforce_pr_isids
.attr
,
1030 &target_core_dev_attrib_is_nonrot
.attr
,
1031 &target_core_dev_attrib_emulate_rest_reord
.attr
,
1032 &target_core_dev_attrib_force_pr_aptpl
.attr
,
1033 &target_core_dev_attrib_hw_block_size
.attr
,
1034 &target_core_dev_attrib_block_size
.attr
,
1035 &target_core_dev_attrib_hw_max_sectors
.attr
,
1036 &target_core_dev_attrib_optimal_sectors
.attr
,
1037 &target_core_dev_attrib_hw_queue_depth
.attr
,
1038 &target_core_dev_attrib_queue_depth
.attr
,
1039 &target_core_dev_attrib_max_unmap_lba_count
.attr
,
1040 &target_core_dev_attrib_max_unmap_block_desc_count
.attr
,
1041 &target_core_dev_attrib_unmap_granularity
.attr
,
1042 &target_core_dev_attrib_unmap_granularity_alignment
.attr
,
1043 &target_core_dev_attrib_max_write_same_len
.attr
,
1046 EXPORT_SYMBOL(sbc_attrib_attrs
);
1048 TB_DEV_ATTR_RO(target_pt
, hw_pi_prot_type
);
1049 TB_DEV_ATTR_RO(target_pt
, hw_block_size
);
1050 TB_DEV_ATTR_RO(target_pt
, hw_max_sectors
);
1051 TB_DEV_ATTR_RO(target_pt
, hw_queue_depth
);
1054 * Minimal dev_attrib attributes for devices passing through CDBs.
1055 * In this case we only provide a few read-only attributes for
1056 * backwards compatibility.
1058 struct configfs_attribute
*passthrough_attrib_attrs
[] = {
1059 &target_pt_dev_attrib_hw_pi_prot_type
.attr
,
1060 &target_pt_dev_attrib_hw_block_size
.attr
,
1061 &target_pt_dev_attrib_hw_max_sectors
.attr
,
1062 &target_pt_dev_attrib_hw_queue_depth
.attr
,
1065 EXPORT_SYMBOL(passthrough_attrib_attrs
);
1067 static struct configfs_item_operations target_core_dev_attrib_ops
= {
1068 .show_attribute
= target_core_dev_attrib_attr_show
,
1069 .store_attribute
= target_core_dev_attrib_attr_store
,
1072 TB_CIT_SETUP_DRV(dev_attrib
, &target_core_dev_attrib_ops
, NULL
);
1074 /* End functions for struct config_item_type tb_dev_attrib_cit */
1076 /* Start functions for struct config_item_type tb_dev_wwn_cit */
1078 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn
, t10_wwn
);
1079 #define SE_DEV_WWN_ATTR(_name, _mode) \
1080 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
1081 __CONFIGFS_EATTR(_name, _mode, \
1082 target_core_dev_wwn_show_attr_##_name, \
1083 target_core_dev_wwn_store_attr_##_name);
1085 #define SE_DEV_WWN_ATTR_RO(_name); \
1087 static struct target_core_dev_wwn_attribute \
1088 target_core_dev_wwn_##_name = \
1089 __CONFIGFS_EATTR_RO(_name, \
1090 target_core_dev_wwn_show_attr_##_name); \
1094 * VPD page 0x80 Unit serial
1096 static ssize_t
target_core_dev_wwn_show_attr_vpd_unit_serial(
1097 struct t10_wwn
*t10_wwn
,
1100 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
1101 &t10_wwn
->unit_serial
[0]);
1104 static ssize_t
target_core_dev_wwn_store_attr_vpd_unit_serial(
1105 struct t10_wwn
*t10_wwn
,
1109 struct se_device
*dev
= t10_wwn
->t10_dev
;
1110 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
1113 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
1114 * from the struct scsi_device level firmware, do not allow
1115 * VPD Unit Serial to be emulated.
1117 * Note this struct scsi_device could also be emulating VPD
1118 * information from its drivers/scsi LLD. But for now we assume
1119 * it is doing 'the right thing' wrt a world wide unique
1120 * VPD Unit Serial Number that OS dependent multipath can depend on.
1122 if (dev
->dev_flags
& DF_FIRMWARE_VPD_UNIT_SERIAL
) {
1123 pr_err("Underlying SCSI device firmware provided VPD"
1124 " Unit Serial, ignoring request\n");
1128 if (strlen(page
) >= INQUIRY_VPD_SERIAL_LEN
) {
1129 pr_err("Emulated VPD Unit Serial exceeds"
1130 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
1134 * Check to see if any active $FABRIC_MOD exports exist. If they
1135 * do exist, fail here as changing this information on the fly
1136 * (underneath the initiator side OS dependent multipath code)
1137 * could cause negative effects.
1139 if (dev
->export_count
) {
1140 pr_err("Unable to set VPD Unit Serial while"
1141 " active %d $FABRIC_MOD exports exist\n",
1147 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
1149 * Also, strip any newline added from the userspace
1150 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
1152 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
1153 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
1154 snprintf(dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
1155 "%s", strstrip(buf
));
1156 dev
->dev_flags
|= DF_EMULATED_VPD_UNIT_SERIAL
;
1158 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
1159 " %s\n", dev
->t10_wwn
.unit_serial
);
1164 SE_DEV_WWN_ATTR(vpd_unit_serial
, S_IRUGO
| S_IWUSR
);
1167 * VPD page 0x83 Protocol Identifier
1169 static ssize_t
target_core_dev_wwn_show_attr_vpd_protocol_identifier(
1170 struct t10_wwn
*t10_wwn
,
1173 struct t10_vpd
*vpd
;
1174 unsigned char buf
[VPD_TMP_BUF_SIZE
];
1177 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
1179 spin_lock(&t10_wwn
->t10_vpd_lock
);
1180 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
1181 if (!vpd
->protocol_identifier_set
)
1184 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
1186 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1189 len
+= sprintf(page
+len
, "%s", buf
);
1191 spin_unlock(&t10_wwn
->t10_vpd_lock
);
1196 static ssize_t
target_core_dev_wwn_store_attr_vpd_protocol_identifier(
1197 struct t10_wwn
*t10_wwn
,
1204 SE_DEV_WWN_ATTR(vpd_protocol_identifier
, S_IRUGO
| S_IWUSR
);
1207 * Generic wrapper for dumping VPD identifiers by association.
1209 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
1210 static ssize_t target_core_dev_wwn_show_attr_##_name( \
1211 struct t10_wwn *t10_wwn, \
1214 struct t10_vpd *vpd; \
1215 unsigned char buf[VPD_TMP_BUF_SIZE]; \
1218 spin_lock(&t10_wwn->t10_vpd_lock); \
1219 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
1220 if (vpd->association != _assoc) \
1223 memset(buf, 0, VPD_TMP_BUF_SIZE); \
1224 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
1225 if (len + strlen(buf) >= PAGE_SIZE) \
1227 len += sprintf(page+len, "%s", buf); \
1229 memset(buf, 0, VPD_TMP_BUF_SIZE); \
1230 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
1231 if (len + strlen(buf) >= PAGE_SIZE) \
1233 len += sprintf(page+len, "%s", buf); \
1235 memset(buf, 0, VPD_TMP_BUF_SIZE); \
1236 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
1237 if (len + strlen(buf) >= PAGE_SIZE) \
1239 len += sprintf(page+len, "%s", buf); \
1241 spin_unlock(&t10_wwn->t10_vpd_lock); \
1247 * VPD page 0x83 Association: Logical Unit
1249 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
1251 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
1252 struct t10_wwn
*t10_wwn
,
1259 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit
, S_IRUGO
| S_IWUSR
);
1262 * VPD page 0x83 Association: Target Port
1264 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
1266 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_target_port(
1267 struct t10_wwn
*t10_wwn
,
1274 SE_DEV_WWN_ATTR(vpd_assoc_target_port
, S_IRUGO
| S_IWUSR
);
1277 * VPD page 0x83 Association: SCSI Target Device
1279 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
1281 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
1282 struct t10_wwn
*t10_wwn
,
1289 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device
, S_IRUGO
| S_IWUSR
);
1291 CONFIGFS_EATTR_OPS(target_core_dev_wwn
, t10_wwn
, t10_wwn_group
);
1293 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
1294 &target_core_dev_wwn_vpd_unit_serial
.attr
,
1295 &target_core_dev_wwn_vpd_protocol_identifier
.attr
,
1296 &target_core_dev_wwn_vpd_assoc_logical_unit
.attr
,
1297 &target_core_dev_wwn_vpd_assoc_target_port
.attr
,
1298 &target_core_dev_wwn_vpd_assoc_scsi_target_device
.attr
,
1302 static struct configfs_item_operations target_core_dev_wwn_ops
= {
1303 .show_attribute
= target_core_dev_wwn_attr_show
,
1304 .store_attribute
= target_core_dev_wwn_attr_store
,
1307 TB_CIT_SETUP(dev_wwn
, &target_core_dev_wwn_ops
, NULL
, target_core_dev_wwn_attrs
);
1309 /* End functions for struct config_item_type tb_dev_wwn_cit */
1311 /* Start functions for struct config_item_type tb_dev_pr_cit */
1313 CONFIGFS_EATTR_STRUCT(target_core_dev_pr
, se_device
);
1314 #define SE_DEV_PR_ATTR(_name, _mode) \
1315 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1316 __CONFIGFS_EATTR(_name, _mode, \
1317 target_core_dev_pr_show_attr_##_name, \
1318 target_core_dev_pr_store_attr_##_name);
1320 #define SE_DEV_PR_ATTR_RO(_name); \
1321 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1322 __CONFIGFS_EATTR_RO(_name, \
1323 target_core_dev_pr_show_attr_##_name);
1325 static ssize_t
target_core_dev_pr_show_spc3_res(struct se_device
*dev
,
1328 struct se_node_acl
*se_nacl
;
1329 struct t10_pr_registration
*pr_reg
;
1330 char i_buf
[PR_REG_ISID_ID_LEN
];
1332 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1334 pr_reg
= dev
->dev_pr_res_holder
;
1336 return sprintf(page
, "No SPC-3 Reservation holder\n");
1338 se_nacl
= pr_reg
->pr_reg_nacl
;
1339 core_pr_dump_initiator_port(pr_reg
, i_buf
, PR_REG_ISID_ID_LEN
);
1341 return sprintf(page
, "SPC-3 Reservation: %s Initiator: %s%s\n",
1342 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1343 se_nacl
->initiatorname
, i_buf
);
1346 static ssize_t
target_core_dev_pr_show_spc2_res(struct se_device
*dev
,
1349 struct se_node_acl
*se_nacl
;
1352 se_nacl
= dev
->dev_reserved_node_acl
;
1355 "SPC-2 Reservation: %s Initiator: %s\n",
1356 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
1357 se_nacl
->initiatorname
);
1359 len
= sprintf(page
, "No SPC-2 Reservation holder\n");
1364 static ssize_t
target_core_dev_pr_show_attr_res_holder(struct se_device
*dev
,
1369 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
1370 return sprintf(page
, "Passthrough\n");
1372 spin_lock(&dev
->dev_reservation_lock
);
1373 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1374 ret
= target_core_dev_pr_show_spc2_res(dev
, page
);
1376 ret
= target_core_dev_pr_show_spc3_res(dev
, page
);
1377 spin_unlock(&dev
->dev_reservation_lock
);
1381 SE_DEV_PR_ATTR_RO(res_holder
);
1383 static ssize_t
target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1384 struct se_device
*dev
, char *page
)
1388 spin_lock(&dev
->dev_reservation_lock
);
1389 if (!dev
->dev_pr_res_holder
) {
1390 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1391 } else if (dev
->dev_pr_res_holder
->pr_reg_all_tg_pt
) {
1392 len
= sprintf(page
, "SPC-3 Reservation: All Target"
1393 " Ports registration\n");
1395 len
= sprintf(page
, "SPC-3 Reservation: Single"
1396 " Target Port registration\n");
1399 spin_unlock(&dev
->dev_reservation_lock
);
1403 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts
);
1405 static ssize_t
target_core_dev_pr_show_attr_res_pr_generation(
1406 struct se_device
*dev
, char *page
)
1408 return sprintf(page
, "0x%08x\n", dev
->t10_pr
.pr_generation
);
1411 SE_DEV_PR_ATTR_RO(res_pr_generation
);
1414 * res_pr_holder_tg_port
1416 static ssize_t
target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1417 struct se_device
*dev
, char *page
)
1419 struct se_node_acl
*se_nacl
;
1420 struct se_portal_group
*se_tpg
;
1421 struct t10_pr_registration
*pr_reg
;
1422 const struct target_core_fabric_ops
*tfo
;
1425 spin_lock(&dev
->dev_reservation_lock
);
1426 pr_reg
= dev
->dev_pr_res_holder
;
1428 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1432 se_nacl
= pr_reg
->pr_reg_nacl
;
1433 se_tpg
= se_nacl
->se_tpg
;
1434 tfo
= se_tpg
->se_tpg_tfo
;
1436 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
1437 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
1438 tfo
->tpg_get_wwn(se_tpg
));
1439 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
1440 " Identifier Tag: %hu %s Portal Group Tag: %hu"
1441 " %s Logical Unit: %u\n", pr_reg
->tg_pt_sep_rtpi
,
1442 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
1443 tfo
->get_fabric_name(), pr_reg
->pr_aptpl_target_lun
);
1446 spin_unlock(&dev
->dev_reservation_lock
);
1450 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port
);
1452 static ssize_t
target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1453 struct se_device
*dev
, char *page
)
1455 const struct target_core_fabric_ops
*tfo
;
1456 struct t10_pr_registration
*pr_reg
;
1457 unsigned char buf
[384];
1458 char i_buf
[PR_REG_ISID_ID_LEN
];
1462 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
1464 spin_lock(&dev
->t10_pr
.registration_lock
);
1465 list_for_each_entry(pr_reg
, &dev
->t10_pr
.registration_list
,
1468 memset(buf
, 0, 384);
1469 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
1470 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
1471 core_pr_dump_initiator_port(pr_reg
, i_buf
,
1472 PR_REG_ISID_ID_LEN
);
1473 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1474 tfo
->get_fabric_name(),
1475 pr_reg
->pr_reg_nacl
->initiatorname
, i_buf
, pr_reg
->pr_res_key
,
1476 pr_reg
->pr_res_generation
);
1478 if (len
+ strlen(buf
) >= PAGE_SIZE
)
1481 len
+= sprintf(page
+len
, "%s", buf
);
1484 spin_unlock(&dev
->t10_pr
.registration_lock
);
1487 len
+= sprintf(page
+len
, "None\n");
1492 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts
);
1494 static ssize_t
target_core_dev_pr_show_attr_res_pr_type(
1495 struct se_device
*dev
, char *page
)
1497 struct t10_pr_registration
*pr_reg
;
1500 spin_lock(&dev
->dev_reservation_lock
);
1501 pr_reg
= dev
->dev_pr_res_holder
;
1503 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
1504 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
1506 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
1509 spin_unlock(&dev
->dev_reservation_lock
);
1513 SE_DEV_PR_ATTR_RO(res_pr_type
);
1515 static ssize_t
target_core_dev_pr_show_attr_res_type(
1516 struct se_device
*dev
, char *page
)
1518 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
1519 return sprintf(page
, "SPC_PASSTHROUGH\n");
1520 else if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1521 return sprintf(page
, "SPC2_RESERVATIONS\n");
1523 return sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
1526 SE_DEV_PR_ATTR_RO(res_type
);
1528 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_active(
1529 struct se_device
*dev
, char *page
)
1531 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
1534 return sprintf(page
, "APTPL Bit Status: %s\n",
1535 (dev
->t10_pr
.pr_aptpl_active
) ? "Activated" : "Disabled");
1538 SE_DEV_PR_ATTR_RO(res_aptpl_active
);
1541 * res_aptpl_metadata
1543 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_metadata(
1544 struct se_device
*dev
, char *page
)
1546 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
1549 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
1553 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
1554 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
1555 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
1556 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
1559 static match_table_t tokens
= {
1560 {Opt_initiator_fabric
, "initiator_fabric=%s"},
1561 {Opt_initiator_node
, "initiator_node=%s"},
1562 {Opt_initiator_sid
, "initiator_sid=%s"},
1563 {Opt_sa_res_key
, "sa_res_key=%s"},
1564 {Opt_res_holder
, "res_holder=%d"},
1565 {Opt_res_type
, "res_type=%d"},
1566 {Opt_res_scope
, "res_scope=%d"},
1567 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
1568 {Opt_mapped_lun
, "mapped_lun=%d"},
1569 {Opt_target_fabric
, "target_fabric=%s"},
1570 {Opt_target_node
, "target_node=%s"},
1571 {Opt_tpgt
, "tpgt=%d"},
1572 {Opt_port_rtpi
, "port_rtpi=%d"},
1573 {Opt_target_lun
, "target_lun=%d"},
1577 static ssize_t
target_core_dev_pr_store_attr_res_aptpl_metadata(
1578 struct se_device
*dev
,
1582 unsigned char *i_fabric
= NULL
, *i_port
= NULL
, *isid
= NULL
;
1583 unsigned char *t_fabric
= NULL
, *t_port
= NULL
;
1584 char *orig
, *ptr
, *opts
;
1585 substring_t args
[MAX_OPT_ARGS
];
1586 unsigned long long tmp_ll
;
1588 u32 mapped_lun
= 0, target_lun
= 0;
1589 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1593 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
1595 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1598 if (dev
->export_count
) {
1599 pr_debug("Unable to process APTPL metadata while"
1600 " active fabric exports exist\n");
1604 opts
= kstrdup(page
, GFP_KERNEL
);
1609 while ((ptr
= strsep(&opts
, ",\n")) != NULL
) {
1613 token
= match_token(ptr
, tokens
, args
);
1615 case Opt_initiator_fabric
:
1616 i_fabric
= match_strdup(args
);
1622 case Opt_initiator_node
:
1623 i_port
= match_strdup(args
);
1628 if (strlen(i_port
) >= PR_APTPL_MAX_IPORT_LEN
) {
1629 pr_err("APTPL metadata initiator_node="
1630 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1631 PR_APTPL_MAX_IPORT_LEN
);
1636 case Opt_initiator_sid
:
1637 isid
= match_strdup(args
);
1642 if (strlen(isid
) >= PR_REG_ISID_LEN
) {
1643 pr_err("APTPL metadata initiator_isid"
1644 "= exceeds PR_REG_ISID_LEN: %d\n",
1650 case Opt_sa_res_key
:
1651 ret
= kstrtoull(args
->from
, 0, &tmp_ll
);
1653 pr_err("kstrtoull() failed for sa_res_key=\n");
1656 sa_res_key
= (u64
)tmp_ll
;
1659 * PR APTPL Metadata for Reservation
1661 case Opt_res_holder
:
1662 match_int(args
, &arg
);
1666 match_int(args
, &arg
);
1670 match_int(args
, &arg
);
1672 case Opt_res_all_tg_pt
:
1673 match_int(args
, &arg
);
1674 all_tg_pt
= (int)arg
;
1676 case Opt_mapped_lun
:
1677 match_int(args
, &arg
);
1678 mapped_lun
= (u32
)arg
;
1681 * PR APTPL Metadata for Target Port
1683 case Opt_target_fabric
:
1684 t_fabric
= match_strdup(args
);
1690 case Opt_target_node
:
1691 t_port
= match_strdup(args
);
1696 if (strlen(t_port
) >= PR_APTPL_MAX_TPORT_LEN
) {
1697 pr_err("APTPL metadata target_node="
1698 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1699 PR_APTPL_MAX_TPORT_LEN
);
1705 match_int(args
, &arg
);
1709 match_int(args
, &arg
);
1711 case Opt_target_lun
:
1712 match_int(args
, &arg
);
1713 target_lun
= (u32
)arg
;
1720 if (!i_port
|| !t_port
|| !sa_res_key
) {
1721 pr_err("Illegal parameters for APTPL registration\n");
1726 if (res_holder
&& !(type
)) {
1727 pr_err("Illegal PR type: 0x%02x for reservation"
1733 ret
= core_scsi3_alloc_aptpl_registration(&dev
->t10_pr
, sa_res_key
,
1734 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1735 res_holder
, all_tg_pt
, type
);
1743 return (ret
== 0) ? count
: ret
;
1746 SE_DEV_PR_ATTR(res_aptpl_metadata
, S_IRUGO
| S_IWUSR
);
1748 CONFIGFS_EATTR_OPS(target_core_dev_pr
, se_device
, dev_pr_group
);
1750 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1751 &target_core_dev_pr_res_holder
.attr
,
1752 &target_core_dev_pr_res_pr_all_tgt_pts
.attr
,
1753 &target_core_dev_pr_res_pr_generation
.attr
,
1754 &target_core_dev_pr_res_pr_holder_tg_port
.attr
,
1755 &target_core_dev_pr_res_pr_registered_i_pts
.attr
,
1756 &target_core_dev_pr_res_pr_type
.attr
,
1757 &target_core_dev_pr_res_type
.attr
,
1758 &target_core_dev_pr_res_aptpl_active
.attr
,
1759 &target_core_dev_pr_res_aptpl_metadata
.attr
,
1763 static struct configfs_item_operations target_core_dev_pr_ops
= {
1764 .show_attribute
= target_core_dev_pr_attr_show
,
1765 .store_attribute
= target_core_dev_pr_attr_store
,
1768 TB_CIT_SETUP(dev_pr
, &target_core_dev_pr_ops
, NULL
, target_core_dev_pr_attrs
);
1770 /* End functions for struct config_item_type tb_dev_pr_cit */
1772 /* Start functions for struct config_item_type tb_dev_cit */
1774 static ssize_t
target_core_show_dev_info(void *p
, char *page
)
1776 struct se_device
*dev
= p
;
1778 ssize_t read_bytes
= 0;
1780 transport_dump_dev_state(dev
, page
, &bl
);
1782 read_bytes
+= dev
->transport
->show_configfs_dev_params(dev
,
1787 static struct target_core_configfs_attribute target_core_attr_dev_info
= {
1788 .attr
= { .ca_owner
= THIS_MODULE
,
1790 .ca_mode
= S_IRUGO
},
1791 .show
= target_core_show_dev_info
,
1795 static ssize_t
target_core_store_dev_control(
1800 struct se_device
*dev
= p
;
1802 return dev
->transport
->set_configfs_dev_params(dev
, page
, count
);
1805 static struct target_core_configfs_attribute target_core_attr_dev_control
= {
1806 .attr
= { .ca_owner
= THIS_MODULE
,
1807 .ca_name
= "control",
1808 .ca_mode
= S_IWUSR
},
1810 .store
= target_core_store_dev_control
,
1813 static ssize_t
target_core_show_dev_alias(void *p
, char *page
)
1815 struct se_device
*dev
= p
;
1817 if (!(dev
->dev_flags
& DF_USING_ALIAS
))
1820 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->dev_alias
);
1823 static ssize_t
target_core_store_dev_alias(
1828 struct se_device
*dev
= p
;
1829 struct se_hba
*hba
= dev
->se_hba
;
1832 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1833 pr_err("alias count: %d exceeds"
1834 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1835 SE_DEV_ALIAS_LEN
-1);
1839 read_bytes
= snprintf(&dev
->dev_alias
[0], SE_DEV_ALIAS_LEN
, "%s", page
);
1842 if (dev
->dev_alias
[read_bytes
- 1] == '\n')
1843 dev
->dev_alias
[read_bytes
- 1] = '\0';
1845 dev
->dev_flags
|= DF_USING_ALIAS
;
1847 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
1848 config_item_name(&hba
->hba_group
.cg_item
),
1849 config_item_name(&dev
->dev_group
.cg_item
),
1855 static struct target_core_configfs_attribute target_core_attr_dev_alias
= {
1856 .attr
= { .ca_owner
= THIS_MODULE
,
1858 .ca_mode
= S_IRUGO
| S_IWUSR
},
1859 .show
= target_core_show_dev_alias
,
1860 .store
= target_core_store_dev_alias
,
1863 static ssize_t
target_core_show_dev_udev_path(void *p
, char *page
)
1865 struct se_device
*dev
= p
;
1867 if (!(dev
->dev_flags
& DF_USING_UDEV_PATH
))
1870 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->udev_path
);
1873 static ssize_t
target_core_store_dev_udev_path(
1878 struct se_device
*dev
= p
;
1879 struct se_hba
*hba
= dev
->se_hba
;
1882 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1883 pr_err("udev_path count: %d exceeds"
1884 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1885 SE_UDEV_PATH_LEN
-1);
1889 read_bytes
= snprintf(&dev
->udev_path
[0], SE_UDEV_PATH_LEN
,
1893 if (dev
->udev_path
[read_bytes
- 1] == '\n')
1894 dev
->udev_path
[read_bytes
- 1] = '\0';
1896 dev
->dev_flags
|= DF_USING_UDEV_PATH
;
1898 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1899 config_item_name(&hba
->hba_group
.cg_item
),
1900 config_item_name(&dev
->dev_group
.cg_item
),
1906 static struct target_core_configfs_attribute target_core_attr_dev_udev_path
= {
1907 .attr
= { .ca_owner
= THIS_MODULE
,
1908 .ca_name
= "udev_path",
1909 .ca_mode
= S_IRUGO
| S_IWUSR
},
1910 .show
= target_core_show_dev_udev_path
,
1911 .store
= target_core_store_dev_udev_path
,
1914 static ssize_t
target_core_show_dev_enable(void *p
, char *page
)
1916 struct se_device
*dev
= p
;
1918 return snprintf(page
, PAGE_SIZE
, "%d\n", !!(dev
->dev_flags
& DF_CONFIGURED
));
1921 static ssize_t
target_core_store_dev_enable(
1926 struct se_device
*dev
= p
;
1930 ptr
= strstr(page
, "1");
1932 pr_err("For dev_enable ops, only valid value"
1937 ret
= target_configure_device(dev
);
1943 static struct target_core_configfs_attribute target_core_attr_dev_enable
= {
1944 .attr
= { .ca_owner
= THIS_MODULE
,
1945 .ca_name
= "enable",
1946 .ca_mode
= S_IRUGO
| S_IWUSR
},
1947 .show
= target_core_show_dev_enable
,
1948 .store
= target_core_store_dev_enable
,
1951 static ssize_t
target_core_show_alua_lu_gp(void *p
, char *page
)
1953 struct se_device
*dev
= p
;
1954 struct config_item
*lu_ci
;
1955 struct t10_alua_lu_gp
*lu_gp
;
1956 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1959 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1963 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1964 lu_gp
= lu_gp_mem
->lu_gp
;
1966 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1967 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1968 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1970 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1975 static ssize_t
target_core_store_alua_lu_gp(
1980 struct se_device
*dev
= p
;
1981 struct se_hba
*hba
= dev
->se_hba
;
1982 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1983 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1984 unsigned char buf
[LU_GROUP_NAME_BUF
];
1987 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1991 if (count
> LU_GROUP_NAME_BUF
) {
1992 pr_err("ALUA LU Group Alias too large!\n");
1995 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1996 memcpy(buf
, page
, count
);
1998 * Any ALUA logical unit alias besides "NULL" means we will be
1999 * making a new group association.
2001 if (strcmp(strstrip(buf
), "NULL")) {
2003 * core_alua_get_lu_gp_by_name() will increment reference to
2004 * struct t10_alua_lu_gp. This reference is released with
2005 * core_alua_get_lu_gp_by_name below().
2007 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
2012 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
2013 lu_gp
= lu_gp_mem
->lu_gp
;
2016 * Clearing an existing lu_gp association, and replacing
2020 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
2021 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
2023 config_item_name(&hba
->hba_group
.cg_item
),
2024 config_item_name(&dev
->dev_group
.cg_item
),
2025 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
2028 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
2029 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
2034 * Removing existing association of lu_gp_mem with lu_gp
2036 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
2040 * Associate lu_gp_mem with lu_gp_new.
2042 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
2043 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
2045 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
2046 " core/alua/lu_gps/%s, ID: %hu\n",
2047 (move
) ? "Moving" : "Adding",
2048 config_item_name(&hba
->hba_group
.cg_item
),
2049 config_item_name(&dev
->dev_group
.cg_item
),
2050 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
2051 lu_gp_new
->lu_gp_id
);
2053 core_alua_put_lu_gp_from_name(lu_gp_new
);
2057 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp
= {
2058 .attr
= { .ca_owner
= THIS_MODULE
,
2059 .ca_name
= "alua_lu_gp",
2060 .ca_mode
= S_IRUGO
| S_IWUSR
},
2061 .show
= target_core_show_alua_lu_gp
,
2062 .store
= target_core_store_alua_lu_gp
,
2065 static ssize_t
target_core_show_dev_lba_map(void *p
, char *page
)
2067 struct se_device
*dev
= p
;
2068 struct t10_alua_lba_map
*map
;
2069 struct t10_alua_lba_map_member
*mem
;
2074 spin_lock(&dev
->t10_alua
.lba_map_lock
);
2075 if (!list_empty(&dev
->t10_alua
.lba_map_list
))
2076 bl
+= sprintf(b
+ bl
, "%u %u\n",
2077 dev
->t10_alua
.lba_map_segment_size
,
2078 dev
->t10_alua
.lba_map_segment_multiplier
);
2079 list_for_each_entry(map
, &dev
->t10_alua
.lba_map_list
, lba_map_list
) {
2080 bl
+= sprintf(b
+ bl
, "%llu %llu",
2081 map
->lba_map_first_lba
, map
->lba_map_last_lba
);
2082 list_for_each_entry(mem
, &map
->lba_map_mem_list
,
2084 switch (mem
->lba_map_mem_alua_state
) {
2085 case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
:
2088 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
2091 case ALUA_ACCESS_STATE_STANDBY
:
2094 case ALUA_ACCESS_STATE_UNAVAILABLE
:
2101 bl
+= sprintf(b
+ bl
, " %d:%c",
2102 mem
->lba_map_mem_alua_pg_id
, state
);
2104 bl
+= sprintf(b
+ bl
, "\n");
2106 spin_unlock(&dev
->t10_alua
.lba_map_lock
);
2110 static ssize_t
target_core_store_dev_lba_map(
2115 struct se_device
*dev
= p
;
2116 struct t10_alua_lba_map
*lba_map
= NULL
;
2117 struct list_head lba_list
;
2118 char *map_entries
, *ptr
;
2120 int pg_num
= -1, pg
;
2121 int ret
= 0, num
= 0, pg_id
, alua_state
;
2122 unsigned long start_lba
= -1, end_lba
= -1;
2123 unsigned long segment_size
= -1, segment_mult
= -1;
2125 map_entries
= kstrdup(page
, GFP_KERNEL
);
2129 INIT_LIST_HEAD(&lba_list
);
2130 while ((ptr
= strsep(&map_entries
, "\n")) != NULL
) {
2135 if (sscanf(ptr
, "%lu %lu\n",
2136 &segment_size
, &segment_mult
) != 2) {
2137 pr_err("Invalid line %d\n", num
);
2144 if (sscanf(ptr
, "%lu %lu", &start_lba
, &end_lba
) != 2) {
2145 pr_err("Invalid line %d\n", num
);
2149 ptr
= strchr(ptr
, ' ');
2151 pr_err("Invalid line %d, missing end lba\n", num
);
2156 ptr
= strchr(ptr
, ' ');
2158 pr_err("Invalid line %d, missing state definitions\n",
2164 lba_map
= core_alua_allocate_lba_map(&lba_list
,
2165 start_lba
, end_lba
);
2166 if (IS_ERR(lba_map
)) {
2167 ret
= PTR_ERR(lba_map
);
2171 while (sscanf(ptr
, "%d:%c", &pg_id
, &state
) == 2) {
2174 alua_state
= ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
;
2177 alua_state
= ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
;
2180 alua_state
= ALUA_ACCESS_STATE_STANDBY
;
2183 alua_state
= ALUA_ACCESS_STATE_UNAVAILABLE
;
2186 pr_err("Invalid ALUA state '%c'\n", state
);
2191 ret
= core_alua_allocate_lba_map_mem(lba_map
,
2194 pr_err("Invalid target descriptor %d:%c "
2200 ptr
= strchr(ptr
, ' ');
2208 else if (pg
!= pg_num
) {
2209 pr_err("Only %d from %d port groups definitions "
2210 "at line %d\n", pg
, pg_num
, num
);
2218 core_alua_free_lba_map(&lba_list
);
2221 core_alua_set_lba_map(dev
, &lba_list
,
2222 segment_size
, segment_mult
);
2227 static struct target_core_configfs_attribute target_core_attr_dev_lba_map
= {
2228 .attr
= { .ca_owner
= THIS_MODULE
,
2229 .ca_name
= "lba_map",
2230 .ca_mode
= S_IRUGO
| S_IWUSR
},
2231 .show
= target_core_show_dev_lba_map
,
2232 .store
= target_core_store_dev_lba_map
,
2235 static struct configfs_attribute
*target_core_dev_attrs
[] = {
2236 &target_core_attr_dev_info
.attr
,
2237 &target_core_attr_dev_control
.attr
,
2238 &target_core_attr_dev_alias
.attr
,
2239 &target_core_attr_dev_udev_path
.attr
,
2240 &target_core_attr_dev_enable
.attr
,
2241 &target_core_attr_dev_alua_lu_gp
.attr
,
2242 &target_core_attr_dev_lba_map
.attr
,
2246 static void target_core_dev_release(struct config_item
*item
)
2248 struct config_group
*dev_cg
= to_config_group(item
);
2249 struct se_device
*dev
=
2250 container_of(dev_cg
, struct se_device
, dev_group
);
2252 kfree(dev_cg
->default_groups
);
2253 target_free_device(dev
);
2256 static ssize_t
target_core_dev_show(struct config_item
*item
,
2257 struct configfs_attribute
*attr
,
2260 struct config_group
*dev_cg
= to_config_group(item
);
2261 struct se_device
*dev
=
2262 container_of(dev_cg
, struct se_device
, dev_group
);
2263 struct target_core_configfs_attribute
*tc_attr
= container_of(
2264 attr
, struct target_core_configfs_attribute
, attr
);
2269 return tc_attr
->show(dev
, page
);
2272 static ssize_t
target_core_dev_store(struct config_item
*item
,
2273 struct configfs_attribute
*attr
,
2274 const char *page
, size_t count
)
2276 struct config_group
*dev_cg
= to_config_group(item
);
2277 struct se_device
*dev
=
2278 container_of(dev_cg
, struct se_device
, dev_group
);
2279 struct target_core_configfs_attribute
*tc_attr
= container_of(
2280 attr
, struct target_core_configfs_attribute
, attr
);
2282 if (!tc_attr
->store
)
2285 return tc_attr
->store(dev
, page
, count
);
2288 static struct configfs_item_operations target_core_dev_item_ops
= {
2289 .release
= target_core_dev_release
,
2290 .show_attribute
= target_core_dev_show
,
2291 .store_attribute
= target_core_dev_store
,
2294 TB_CIT_SETUP(dev
, &target_core_dev_item_ops
, NULL
, target_core_dev_attrs
);
2296 /* End functions for struct config_item_type tb_dev_cit */
2298 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
2300 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp
, t10_alua_lu_gp
);
2301 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
2302 static struct target_core_alua_lu_gp_attribute \
2303 target_core_alua_lu_gp_##_name = \
2304 __CONFIGFS_EATTR(_name, _mode, \
2305 target_core_alua_lu_gp_show_attr_##_name, \
2306 target_core_alua_lu_gp_store_attr_##_name);
2308 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
2309 static struct target_core_alua_lu_gp_attribute \
2310 target_core_alua_lu_gp_##_name = \
2311 __CONFIGFS_EATTR_RO(_name, \
2312 target_core_alua_lu_gp_show_attr_##_name);
2317 static ssize_t
target_core_alua_lu_gp_show_attr_lu_gp_id(
2318 struct t10_alua_lu_gp
*lu_gp
,
2321 if (!lu_gp
->lu_gp_valid_id
)
2324 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
2327 static ssize_t
target_core_alua_lu_gp_store_attr_lu_gp_id(
2328 struct t10_alua_lu_gp
*lu_gp
,
2332 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2333 unsigned long lu_gp_id
;
2336 ret
= kstrtoul(page
, 0, &lu_gp_id
);
2338 pr_err("kstrtoul() returned %d for"
2339 " lu_gp_id\n", ret
);
2342 if (lu_gp_id
> 0x0000ffff) {
2343 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
2344 " 0x0000ffff\n", lu_gp_id
);
2348 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
2352 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
2353 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2354 config_item_name(&alua_lu_gp_cg
->cg_item
),
2360 SE_DEV_ALUA_LU_ATTR(lu_gp_id
, S_IRUGO
| S_IWUSR
);
2365 static ssize_t
target_core_alua_lu_gp_show_attr_members(
2366 struct t10_alua_lu_gp
*lu_gp
,
2369 struct se_device
*dev
;
2371 struct t10_alua_lu_gp_member
*lu_gp_mem
;
2372 ssize_t len
= 0, cur_len
;
2373 unsigned char buf
[LU_GROUP_NAME_BUF
];
2375 memset(buf
, 0, LU_GROUP_NAME_BUF
);
2377 spin_lock(&lu_gp
->lu_gp_lock
);
2378 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
2379 dev
= lu_gp_mem
->lu_gp_mem_dev
;
2382 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
2383 config_item_name(&hba
->hba_group
.cg_item
),
2384 config_item_name(&dev
->dev_group
.cg_item
));
2385 cur_len
++; /* Extra byte for NULL terminator */
2387 if ((cur_len
+ len
) > PAGE_SIZE
) {
2388 pr_warn("Ran out of lu_gp_show_attr"
2389 "_members buffer\n");
2392 memcpy(page
+len
, buf
, cur_len
);
2395 spin_unlock(&lu_gp
->lu_gp_lock
);
2400 SE_DEV_ALUA_LU_ATTR_RO(members
);
2402 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp
, t10_alua_lu_gp
, lu_gp_group
);
2404 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
2405 &target_core_alua_lu_gp_lu_gp_id
.attr
,
2406 &target_core_alua_lu_gp_members
.attr
,
2410 static void target_core_alua_lu_gp_release(struct config_item
*item
)
2412 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2413 struct t10_alua_lu_gp
, lu_gp_group
);
2415 core_alua_free_lu_gp(lu_gp
);
2418 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
2419 .release
= target_core_alua_lu_gp_release
,
2420 .show_attribute
= target_core_alua_lu_gp_attr_show
,
2421 .store_attribute
= target_core_alua_lu_gp_attr_store
,
2424 static struct config_item_type target_core_alua_lu_gp_cit
= {
2425 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
2426 .ct_attrs
= target_core_alua_lu_gp_attrs
,
2427 .ct_owner
= THIS_MODULE
,
2430 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
2432 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
2434 static struct config_group
*target_core_alua_create_lu_gp(
2435 struct config_group
*group
,
2438 struct t10_alua_lu_gp
*lu_gp
;
2439 struct config_group
*alua_lu_gp_cg
= NULL
;
2440 struct config_item
*alua_lu_gp_ci
= NULL
;
2442 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
2446 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
2447 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
2449 config_group_init_type_name(alua_lu_gp_cg
, name
,
2450 &target_core_alua_lu_gp_cit
);
2452 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2453 " Group: core/alua/lu_gps/%s\n",
2454 config_item_name(alua_lu_gp_ci
));
2456 return alua_lu_gp_cg
;
2460 static void target_core_alua_drop_lu_gp(
2461 struct config_group
*group
,
2462 struct config_item
*item
)
2464 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
2465 struct t10_alua_lu_gp
, lu_gp_group
);
2467 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2468 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2469 config_item_name(item
), lu_gp
->lu_gp_id
);
2471 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
2472 * -> target_core_alua_lu_gp_release()
2474 config_item_put(item
);
2477 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
2478 .make_group
= &target_core_alua_create_lu_gp
,
2479 .drop_item
= &target_core_alua_drop_lu_gp
,
2482 static struct config_item_type target_core_alua_lu_gps_cit
= {
2483 .ct_item_ops
= NULL
,
2484 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
2485 .ct_owner
= THIS_MODULE
,
2488 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
2490 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2492 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
);
2493 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
2494 static struct target_core_alua_tg_pt_gp_attribute \
2495 target_core_alua_tg_pt_gp_##_name = \
2496 __CONFIGFS_EATTR(_name, _mode, \
2497 target_core_alua_tg_pt_gp_show_attr_##_name, \
2498 target_core_alua_tg_pt_gp_store_attr_##_name);
2500 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2501 static struct target_core_alua_tg_pt_gp_attribute \
2502 target_core_alua_tg_pt_gp_##_name = \
2503 __CONFIGFS_EATTR_RO(_name, \
2504 target_core_alua_tg_pt_gp_show_attr_##_name);
2509 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2510 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2513 return sprintf(page
, "%d\n",
2514 atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
));
2517 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2518 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2522 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
2526 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2527 pr_err("Unable to do implicit ALUA on non valid"
2528 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
2531 if (!(dev
->dev_flags
& DF_CONFIGURED
)) {
2532 pr_err("Unable to set alua_access_state while device is"
2533 " not configured\n");
2537 ret
= kstrtoul(page
, 0, &tmp
);
2539 pr_err("Unable to extract new ALUA access state from"
2543 new_state
= (int)tmp
;
2545 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICIT_ALUA
)) {
2546 pr_err("Unable to process implicit configfs ALUA"
2547 " transition while TPGS_IMPLICIT_ALUA is disabled\n");
2550 if (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICIT_ALUA
&&
2551 new_state
== ALUA_ACCESS_STATE_LBA_DEPENDENT
) {
2552 /* LBA DEPENDENT is only allowed with implicit ALUA */
2553 pr_err("Unable to process implicit configfs ALUA transition"
2554 " while explicit ALUA management is enabled\n");
2558 ret
= core_alua_do_port_transition(tg_pt_gp
, dev
,
2559 NULL
, NULL
, new_state
, 0);
2560 return (!ret
) ? count
: -EINVAL
;
2563 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state
, S_IRUGO
| S_IWUSR
);
2566 * alua_access_status
2568 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2569 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2572 return sprintf(page
, "%s\n",
2573 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
2576 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2577 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2582 int new_status
, ret
;
2584 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2585 pr_err("Unable to do set ALUA access status on non"
2586 " valid tg_pt_gp ID: %hu\n",
2587 tg_pt_gp
->tg_pt_gp_valid_id
);
2591 ret
= kstrtoul(page
, 0, &tmp
);
2593 pr_err("Unable to extract new ALUA access status"
2594 " from %s\n", page
);
2597 new_status
= (int)tmp
;
2599 if ((new_status
!= ALUA_STATUS_NONE
) &&
2600 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG
) &&
2601 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA
)) {
2602 pr_err("Illegal ALUA access status: 0x%02x\n",
2607 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2611 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status
, S_IRUGO
| S_IWUSR
);
2616 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2617 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2620 return core_alua_show_access_type(tg_pt_gp
, page
);
2623 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2624 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2628 return core_alua_store_access_type(tg_pt_gp
, page
, count
);
2631 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type
, S_IRUGO
| S_IWUSR
);
2634 * alua_supported_states
2637 #define SE_DEV_ALUA_SUPPORT_STATE_SHOW(_name, _var, _bit) \
2638 static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_support_##_name( \
2639 struct t10_alua_tg_pt_gp *t, char *p) \
2641 return sprintf(p, "%d\n", !!(t->_var & _bit)); \
2644 #define SE_DEV_ALUA_SUPPORT_STATE_STORE(_name, _var, _bit) \
2645 static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_support_##_name(\
2646 struct t10_alua_tg_pt_gp *t, const char *p, size_t c) \
2648 unsigned long tmp; \
2651 if (!t->tg_pt_gp_valid_id) { \
2652 pr_err("Unable to do set ##_name ALUA state on non" \
2653 " valid tg_pt_gp ID: %hu\n", \
2654 t->tg_pt_gp_valid_id); \
2658 ret = kstrtoul(p, 0, &tmp); \
2660 pr_err("Invalid value '%s', must be '0' or '1'\n", p); \
2664 pr_err("Invalid value '%ld', must be '0' or '1'\n", tmp); \
2675 SE_DEV_ALUA_SUPPORT_STATE_SHOW(transitioning
,
2676 tg_pt_gp_alua_supported_states
, ALUA_T_SUP
);
2677 SE_DEV_ALUA_SUPPORT_STATE_STORE(transitioning
,
2678 tg_pt_gp_alua_supported_states
, ALUA_T_SUP
);
2679 SE_DEV_ALUA_TG_PT_ATTR(alua_support_transitioning
, S_IRUGO
| S_IWUSR
);
2681 SE_DEV_ALUA_SUPPORT_STATE_SHOW(offline
,
2682 tg_pt_gp_alua_supported_states
, ALUA_O_SUP
);
2683 SE_DEV_ALUA_SUPPORT_STATE_STORE(offline
,
2684 tg_pt_gp_alua_supported_states
, ALUA_O_SUP
);
2685 SE_DEV_ALUA_TG_PT_ATTR(alua_support_offline
, S_IRUGO
| S_IWUSR
);
2687 SE_DEV_ALUA_SUPPORT_STATE_SHOW(lba_dependent
,
2688 tg_pt_gp_alua_supported_states
, ALUA_LBD_SUP
);
2689 SE_DEV_ALUA_SUPPORT_STATE_STORE(lba_dependent
,
2690 tg_pt_gp_alua_supported_states
, ALUA_LBD_SUP
);
2691 SE_DEV_ALUA_TG_PT_ATTR(alua_support_lba_dependent
, S_IRUGO
);
2693 SE_DEV_ALUA_SUPPORT_STATE_SHOW(unavailable
,
2694 tg_pt_gp_alua_supported_states
, ALUA_U_SUP
);
2695 SE_DEV_ALUA_SUPPORT_STATE_STORE(unavailable
,
2696 tg_pt_gp_alua_supported_states
, ALUA_U_SUP
);
2697 SE_DEV_ALUA_TG_PT_ATTR(alua_support_unavailable
, S_IRUGO
| S_IWUSR
);
2699 SE_DEV_ALUA_SUPPORT_STATE_SHOW(standby
,
2700 tg_pt_gp_alua_supported_states
, ALUA_S_SUP
);
2701 SE_DEV_ALUA_SUPPORT_STATE_STORE(standby
,
2702 tg_pt_gp_alua_supported_states
, ALUA_S_SUP
);
2703 SE_DEV_ALUA_TG_PT_ATTR(alua_support_standby
, S_IRUGO
| S_IWUSR
);
2705 SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_optimized
,
2706 tg_pt_gp_alua_supported_states
, ALUA_AO_SUP
);
2707 SE_DEV_ALUA_SUPPORT_STATE_STORE(active_optimized
,
2708 tg_pt_gp_alua_supported_states
, ALUA_AO_SUP
);
2709 SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_optimized
, S_IRUGO
| S_IWUSR
);
2711 SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_nonoptimized
,
2712 tg_pt_gp_alua_supported_states
, ALUA_AN_SUP
);
2713 SE_DEV_ALUA_SUPPORT_STATE_STORE(active_nonoptimized
,
2714 tg_pt_gp_alua_supported_states
, ALUA_AN_SUP
);
2715 SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_nonoptimized
, S_IRUGO
| S_IWUSR
);
2718 * alua_write_metadata
2720 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2721 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2724 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_write_metadata
);
2727 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2728 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2735 ret
= kstrtoul(page
, 0, &tmp
);
2737 pr_err("Unable to extract alua_write_metadata\n");
2741 if ((tmp
!= 0) && (tmp
!= 1)) {
2742 pr_err("Illegal value for alua_write_metadata:"
2746 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2751 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata
, S_IRUGO
| S_IWUSR
);
2758 static ssize_t
target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2759 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2762 return core_alua_show_nonop_delay_msecs(tg_pt_gp
, page
);
2766 static ssize_t
target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2767 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2771 return core_alua_store_nonop_delay_msecs(tg_pt_gp
, page
, count
);
2774 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs
, S_IRUGO
| S_IWUSR
);
2779 static ssize_t
target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2780 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2783 return core_alua_show_trans_delay_msecs(tg_pt_gp
, page
);
2786 static ssize_t
target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2787 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2791 return core_alua_store_trans_delay_msecs(tg_pt_gp
, page
, count
);
2794 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs
, S_IRUGO
| S_IWUSR
);
2797 * implicit_trans_secs
2799 static ssize_t
target_core_alua_tg_pt_gp_show_attr_implicit_trans_secs(
2800 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2803 return core_alua_show_implicit_trans_secs(tg_pt_gp
, page
);
2806 static ssize_t
target_core_alua_tg_pt_gp_store_attr_implicit_trans_secs(
2807 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2811 return core_alua_store_implicit_trans_secs(tg_pt_gp
, page
, count
);
2814 SE_DEV_ALUA_TG_PT_ATTR(implicit_trans_secs
, S_IRUGO
| S_IWUSR
);
2820 static ssize_t
target_core_alua_tg_pt_gp_show_attr_preferred(
2821 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2824 return core_alua_show_preferred_bit(tg_pt_gp
, page
);
2827 static ssize_t
target_core_alua_tg_pt_gp_store_attr_preferred(
2828 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2832 return core_alua_store_preferred_bit(tg_pt_gp
, page
, count
);
2835 SE_DEV_ALUA_TG_PT_ATTR(preferred
, S_IRUGO
| S_IWUSR
);
2840 static ssize_t
target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2841 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2844 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
2847 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2850 static ssize_t
target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2851 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2855 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2856 unsigned long tg_pt_gp_id
;
2859 ret
= kstrtoul(page
, 0, &tg_pt_gp_id
);
2861 pr_err("kstrtoul() returned %d for"
2862 " tg_pt_gp_id\n", ret
);
2865 if (tg_pt_gp_id
> 0x0000ffff) {
2866 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:"
2867 " 0x0000ffff\n", tg_pt_gp_id
);
2871 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2875 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
2876 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2877 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2878 tg_pt_gp
->tg_pt_gp_id
);
2883 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id
, S_IRUGO
| S_IWUSR
);
2888 static ssize_t
target_core_alua_tg_pt_gp_show_attr_members(
2889 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2893 ssize_t len
= 0, cur_len
;
2894 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2896 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2898 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2899 list_for_each_entry(lun
, &tg_pt_gp
->tg_pt_gp_lun_list
,
2900 lun_tg_pt_gp_link
) {
2901 struct se_portal_group
*tpg
= lun
->lun_tpg
;
2903 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2904 "/%s\n", tpg
->se_tpg_tfo
->get_fabric_name(),
2905 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
2906 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
2907 config_item_name(&lun
->lun_group
.cg_item
));
2908 cur_len
++; /* Extra byte for NULL terminator */
2910 if ((cur_len
+ len
) > PAGE_SIZE
) {
2911 pr_warn("Ran out of lu_gp_show_attr"
2912 "_members buffer\n");
2915 memcpy(page
+len
, buf
, cur_len
);
2918 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2923 SE_DEV_ALUA_TG_PT_ATTR_RO(members
);
2925 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
,
2928 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2929 &target_core_alua_tg_pt_gp_alua_access_state
.attr
,
2930 &target_core_alua_tg_pt_gp_alua_access_status
.attr
,
2931 &target_core_alua_tg_pt_gp_alua_access_type
.attr
,
2932 &target_core_alua_tg_pt_gp_alua_support_transitioning
.attr
,
2933 &target_core_alua_tg_pt_gp_alua_support_offline
.attr
,
2934 &target_core_alua_tg_pt_gp_alua_support_lba_dependent
.attr
,
2935 &target_core_alua_tg_pt_gp_alua_support_unavailable
.attr
,
2936 &target_core_alua_tg_pt_gp_alua_support_standby
.attr
,
2937 &target_core_alua_tg_pt_gp_alua_support_active_nonoptimized
.attr
,
2938 &target_core_alua_tg_pt_gp_alua_support_active_optimized
.attr
,
2939 &target_core_alua_tg_pt_gp_alua_write_metadata
.attr
,
2940 &target_core_alua_tg_pt_gp_nonop_delay_msecs
.attr
,
2941 &target_core_alua_tg_pt_gp_trans_delay_msecs
.attr
,
2942 &target_core_alua_tg_pt_gp_implicit_trans_secs
.attr
,
2943 &target_core_alua_tg_pt_gp_preferred
.attr
,
2944 &target_core_alua_tg_pt_gp_tg_pt_gp_id
.attr
,
2945 &target_core_alua_tg_pt_gp_members
.attr
,
2949 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2951 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2952 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2954 core_alua_free_tg_pt_gp(tg_pt_gp
);
2957 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2958 .release
= target_core_alua_tg_pt_gp_release
,
2959 .show_attribute
= target_core_alua_tg_pt_gp_attr_show
,
2960 .store_attribute
= target_core_alua_tg_pt_gp_attr_store
,
2963 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2964 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2965 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2966 .ct_owner
= THIS_MODULE
,
2969 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2971 /* Start functions for struct config_item_type tb_alua_tg_pt_gps_cit */
2973 static struct config_group
*target_core_alua_create_tg_pt_gp(
2974 struct config_group
*group
,
2977 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2978 alua_tg_pt_gps_group
);
2979 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2980 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2981 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2983 tg_pt_gp
= core_alua_allocate_tg_pt_gp(alua
->t10_dev
, name
, 0);
2987 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2988 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2990 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2991 &target_core_alua_tg_pt_gp_cit
);
2993 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
2994 " Group: alua/tg_pt_gps/%s\n",
2995 config_item_name(alua_tg_pt_gp_ci
));
2997 return alua_tg_pt_gp_cg
;
3000 static void target_core_alua_drop_tg_pt_gp(
3001 struct config_group
*group
,
3002 struct config_item
*item
)
3004 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
3005 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
3007 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
3008 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
3009 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
3011 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
3012 * -> target_core_alua_tg_pt_gp_release().
3014 config_item_put(item
);
3017 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
3018 .make_group
= &target_core_alua_create_tg_pt_gp
,
3019 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
3022 TB_CIT_SETUP(dev_alua_tg_pt_gps
, NULL
, &target_core_alua_tg_pt_gps_group_ops
, NULL
);
3024 /* End functions for struct config_item_type tb_alua_tg_pt_gps_cit */
3026 /* Start functions for struct config_item_type target_core_alua_cit */
3029 * target_core_alua_cit is a ConfigFS group that lives under
3030 * /sys/kernel/config/target/core/alua. There are default groups
3031 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
3032 * target_core_alua_cit in target_core_init_configfs() below.
3034 static struct config_item_type target_core_alua_cit
= {
3035 .ct_item_ops
= NULL
,
3037 .ct_owner
= THIS_MODULE
,
3040 /* End functions for struct config_item_type target_core_alua_cit */
3042 /* Start functions for struct config_item_type tb_dev_stat_cit */
3044 static struct config_group
*target_core_stat_mkdir(
3045 struct config_group
*group
,
3048 return ERR_PTR(-ENOSYS
);
3051 static void target_core_stat_rmdir(
3052 struct config_group
*group
,
3053 struct config_item
*item
)
3058 static struct configfs_group_operations target_core_stat_group_ops
= {
3059 .make_group
= &target_core_stat_mkdir
,
3060 .drop_item
= &target_core_stat_rmdir
,
3063 TB_CIT_SETUP(dev_stat
, NULL
, &target_core_stat_group_ops
, NULL
);
3065 /* End functions for struct config_item_type tb_dev_stat_cit */
3067 /* Start functions for struct config_item_type target_core_hba_cit */
3069 static struct config_group
*target_core_make_subdev(
3070 struct config_group
*group
,
3073 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
3074 struct config_item
*hba_ci
= &group
->cg_item
;
3075 struct se_hba
*hba
= item_to_hba(hba_ci
);
3076 struct target_backend
*tb
= hba
->backend
;
3077 struct se_device
*dev
;
3078 struct config_group
*dev_cg
= NULL
, *tg_pt_gp_cg
= NULL
;
3079 struct config_group
*dev_stat_grp
= NULL
;
3080 int errno
= -ENOMEM
, ret
;
3082 ret
= mutex_lock_interruptible(&hba
->hba_access_mutex
);
3084 return ERR_PTR(ret
);
3086 dev
= target_alloc_device(hba
, name
);
3090 dev_cg
= &dev
->dev_group
;
3092 dev_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 6,
3094 if (!dev_cg
->default_groups
)
3095 goto out_free_device
;
3097 config_group_init_type_name(dev_cg
, name
, &tb
->tb_dev_cit
);
3098 config_group_init_type_name(&dev
->dev_attrib
.da_group
, "attrib",
3099 &tb
->tb_dev_attrib_cit
);
3100 config_group_init_type_name(&dev
->dev_pr_group
, "pr",
3101 &tb
->tb_dev_pr_cit
);
3102 config_group_init_type_name(&dev
->t10_wwn
.t10_wwn_group
, "wwn",
3103 &tb
->tb_dev_wwn_cit
);
3104 config_group_init_type_name(&dev
->t10_alua
.alua_tg_pt_gps_group
,
3105 "alua", &tb
->tb_dev_alua_tg_pt_gps_cit
);
3106 config_group_init_type_name(&dev
->dev_stat_grps
.stat_group
,
3107 "statistics", &tb
->tb_dev_stat_cit
);
3109 dev_cg
->default_groups
[0] = &dev
->dev_attrib
.da_group
;
3110 dev_cg
->default_groups
[1] = &dev
->dev_pr_group
;
3111 dev_cg
->default_groups
[2] = &dev
->t10_wwn
.t10_wwn_group
;
3112 dev_cg
->default_groups
[3] = &dev
->t10_alua
.alua_tg_pt_gps_group
;
3113 dev_cg
->default_groups
[4] = &dev
->dev_stat_grps
.stat_group
;
3114 dev_cg
->default_groups
[5] = NULL
;
3116 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
3118 tg_pt_gp
= core_alua_allocate_tg_pt_gp(dev
, "default_tg_pt_gp", 1);
3120 goto out_free_dev_cg_default_groups
;
3121 dev
->t10_alua
.default_tg_pt_gp
= tg_pt_gp
;
3123 tg_pt_gp_cg
= &dev
->t10_alua
.alua_tg_pt_gps_group
;
3124 tg_pt_gp_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3126 if (!tg_pt_gp_cg
->default_groups
) {
3127 pr_err("Unable to allocate tg_pt_gp_cg->"
3128 "default_groups\n");
3129 goto out_free_tg_pt_gp
;
3132 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
3133 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
3134 tg_pt_gp_cg
->default_groups
[0] = &tg_pt_gp
->tg_pt_gp_group
;
3135 tg_pt_gp_cg
->default_groups
[1] = NULL
;
3137 * Add core/$HBA/$DEV/statistics/ default groups
3139 dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
3140 dev_stat_grp
->default_groups
= kmalloc(sizeof(struct config_group
*) * 4,
3142 if (!dev_stat_grp
->default_groups
) {
3143 pr_err("Unable to allocate dev_stat_grp->default_groups\n");
3144 goto out_free_tg_pt_gp_cg_default_groups
;
3146 target_stat_setup_dev_default_groups(dev
);
3148 mutex_unlock(&hba
->hba_access_mutex
);
3151 out_free_tg_pt_gp_cg_default_groups
:
3152 kfree(tg_pt_gp_cg
->default_groups
);
3154 core_alua_free_tg_pt_gp(tg_pt_gp
);
3155 out_free_dev_cg_default_groups
:
3156 kfree(dev_cg
->default_groups
);
3158 target_free_device(dev
);
3160 mutex_unlock(&hba
->hba_access_mutex
);
3161 return ERR_PTR(errno
);
3164 static void target_core_drop_subdev(
3165 struct config_group
*group
,
3166 struct config_item
*item
)
3168 struct config_group
*dev_cg
= to_config_group(item
);
3169 struct se_device
*dev
=
3170 container_of(dev_cg
, struct se_device
, dev_group
);
3172 struct config_item
*df_item
;
3173 struct config_group
*tg_pt_gp_cg
, *dev_stat_grp
;
3176 hba
= item_to_hba(&dev
->se_hba
->hba_group
.cg_item
);
3178 mutex_lock(&hba
->hba_access_mutex
);
3180 dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
3181 for (i
= 0; dev_stat_grp
->default_groups
[i
]; i
++) {
3182 df_item
= &dev_stat_grp
->default_groups
[i
]->cg_item
;
3183 dev_stat_grp
->default_groups
[i
] = NULL
;
3184 config_item_put(df_item
);
3186 kfree(dev_stat_grp
->default_groups
);
3188 tg_pt_gp_cg
= &dev
->t10_alua
.alua_tg_pt_gps_group
;
3189 for (i
= 0; tg_pt_gp_cg
->default_groups
[i
]; i
++) {
3190 df_item
= &tg_pt_gp_cg
->default_groups
[i
]->cg_item
;
3191 tg_pt_gp_cg
->default_groups
[i
] = NULL
;
3192 config_item_put(df_item
);
3194 kfree(tg_pt_gp_cg
->default_groups
);
3196 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
3197 * directly from target_core_alua_tg_pt_gp_release().
3199 dev
->t10_alua
.default_tg_pt_gp
= NULL
;
3201 for (i
= 0; dev_cg
->default_groups
[i
]; i
++) {
3202 df_item
= &dev_cg
->default_groups
[i
]->cg_item
;
3203 dev_cg
->default_groups
[i
] = NULL
;
3204 config_item_put(df_item
);
3207 * se_dev is released from target_core_dev_item_ops->release()
3209 config_item_put(item
);
3210 mutex_unlock(&hba
->hba_access_mutex
);
3213 static struct configfs_group_operations target_core_hba_group_ops
= {
3214 .make_group
= target_core_make_subdev
,
3215 .drop_item
= target_core_drop_subdev
,
3218 CONFIGFS_EATTR_STRUCT(target_core_hba
, se_hba
);
3219 #define SE_HBA_ATTR(_name, _mode) \
3220 static struct target_core_hba_attribute \
3221 target_core_hba_##_name = \
3222 __CONFIGFS_EATTR(_name, _mode, \
3223 target_core_hba_show_attr_##_name, \
3224 target_core_hba_store_attr_##_name);
3226 #define SE_HBA_ATTR_RO(_name) \
3227 static struct target_core_hba_attribute \
3228 target_core_hba_##_name = \
3229 __CONFIGFS_EATTR_RO(_name, \
3230 target_core_hba_show_attr_##_name);
3232 static ssize_t
target_core_hba_show_attr_hba_info(
3236 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
3237 hba
->hba_id
, hba
->backend
->ops
->name
,
3238 TARGET_CORE_CONFIGFS_VERSION
);
3241 SE_HBA_ATTR_RO(hba_info
);
3243 static ssize_t
target_core_hba_show_attr_hba_mode(struct se_hba
*hba
,
3248 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
3251 return sprintf(page
, "%d\n", hba_mode
);
3254 static ssize_t
target_core_hba_store_attr_hba_mode(struct se_hba
*hba
,
3255 const char *page
, size_t count
)
3257 unsigned long mode_flag
;
3260 if (hba
->backend
->ops
->pmode_enable_hba
== NULL
)
3263 ret
= kstrtoul(page
, 0, &mode_flag
);
3265 pr_err("Unable to extract hba mode flag: %d\n", ret
);
3269 if (hba
->dev_count
) {
3270 pr_err("Unable to set hba_mode with active devices\n");
3274 ret
= hba
->backend
->ops
->pmode_enable_hba(hba
, mode_flag
);
3278 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
3280 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
3285 SE_HBA_ATTR(hba_mode
, S_IRUGO
| S_IWUSR
);
3287 CONFIGFS_EATTR_OPS(target_core_hba
, se_hba
, hba_group
);
3289 static void target_core_hba_release(struct config_item
*item
)
3291 struct se_hba
*hba
= container_of(to_config_group(item
),
3292 struct se_hba
, hba_group
);
3293 core_delete_hba(hba
);
3296 static struct configfs_attribute
*target_core_hba_attrs
[] = {
3297 &target_core_hba_hba_info
.attr
,
3298 &target_core_hba_hba_mode
.attr
,
3302 static struct configfs_item_operations target_core_hba_item_ops
= {
3303 .release
= target_core_hba_release
,
3304 .show_attribute
= target_core_hba_attr_show
,
3305 .store_attribute
= target_core_hba_attr_store
,
3308 static struct config_item_type target_core_hba_cit
= {
3309 .ct_item_ops
= &target_core_hba_item_ops
,
3310 .ct_group_ops
= &target_core_hba_group_ops
,
3311 .ct_attrs
= target_core_hba_attrs
,
3312 .ct_owner
= THIS_MODULE
,
3315 static struct config_group
*target_core_call_addhbatotarget(
3316 struct config_group
*group
,
3319 char *se_plugin_str
, *str
, *str2
;
3321 char buf
[TARGET_CORE_NAME_MAX_LEN
];
3322 unsigned long plugin_dep_id
= 0;
3325 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
3326 if (strlen(name
) >= TARGET_CORE_NAME_MAX_LEN
) {
3327 pr_err("Passed *name strlen(): %d exceeds"
3328 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
3329 TARGET_CORE_NAME_MAX_LEN
);
3330 return ERR_PTR(-ENAMETOOLONG
);
3332 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
3334 str
= strstr(buf
, "_");
3336 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
3337 return ERR_PTR(-EINVAL
);
3339 se_plugin_str
= buf
;
3341 * Special case for subsystem plugins that have "_" in their names.
3342 * Namely rd_direct and rd_mcp..
3344 str2
= strstr(str
+1, "_");
3346 *str2
= '\0'; /* Terminate for *se_plugin_str */
3347 str2
++; /* Skip to start of plugin dependent ID */
3350 *str
= '\0'; /* Terminate for *se_plugin_str */
3351 str
++; /* Skip to start of plugin dependent ID */
3354 ret
= kstrtoul(str
, 0, &plugin_dep_id
);
3356 pr_err("kstrtoul() returned %d for"
3357 " plugin_dep_id\n", ret
);
3358 return ERR_PTR(ret
);
3361 * Load up TCM subsystem plugins if they have not already been loaded.
3363 transport_subsystem_check_init();
3365 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
3367 return ERR_CAST(hba
);
3369 config_group_init_type_name(&hba
->hba_group
, name
,
3370 &target_core_hba_cit
);
3372 return &hba
->hba_group
;
3375 static void target_core_call_delhbafromtarget(
3376 struct config_group
*group
,
3377 struct config_item
*item
)
3380 * core_delete_hba() is called from target_core_hba_item_ops->release()
3381 * -> target_core_hba_release()
3383 config_item_put(item
);
3386 static struct configfs_group_operations target_core_group_ops
= {
3387 .make_group
= target_core_call_addhbatotarget
,
3388 .drop_item
= target_core_call_delhbafromtarget
,
3391 static struct config_item_type target_core_cit
= {
3392 .ct_item_ops
= NULL
,
3393 .ct_group_ops
= &target_core_group_ops
,
3395 .ct_owner
= THIS_MODULE
,
3398 /* Stop functions for struct config_item_type target_core_hba_cit */
3400 void target_setup_backend_cits(struct target_backend
*tb
)
3402 target_core_setup_dev_cit(tb
);
3403 target_core_setup_dev_attrib_cit(tb
);
3404 target_core_setup_dev_pr_cit(tb
);
3405 target_core_setup_dev_wwn_cit(tb
);
3406 target_core_setup_dev_alua_tg_pt_gps_cit(tb
);
3407 target_core_setup_dev_stat_cit(tb
);
3410 static int __init
target_core_init_configfs(void)
3412 struct config_group
*target_cg
, *hba_cg
= NULL
, *alua_cg
= NULL
;
3413 struct config_group
*lu_gp_cg
= NULL
;
3414 struct configfs_subsystem
*subsys
= &target_core_fabrics
;
3415 struct t10_alua_lu_gp
*lu_gp
;
3418 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
3419 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
3420 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
3422 config_group_init(&subsys
->su_group
);
3423 mutex_init(&subsys
->su_mutex
);
3425 ret
= init_se_kmem_caches();
3429 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
3430 * and ALUA Logical Unit Group and Target Port Group infrastructure.
3432 target_cg
= &subsys
->su_group
;
3433 target_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3435 if (!target_cg
->default_groups
) {
3436 pr_err("Unable to allocate target_cg->default_groups\n");
3441 config_group_init_type_name(&target_core_hbagroup
,
3442 "core", &target_core_cit
);
3443 target_cg
->default_groups
[0] = &target_core_hbagroup
;
3444 target_cg
->default_groups
[1] = NULL
;
3446 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
3448 hba_cg
= &target_core_hbagroup
;
3449 hba_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3451 if (!hba_cg
->default_groups
) {
3452 pr_err("Unable to allocate hba_cg->default_groups\n");
3456 config_group_init_type_name(&alua_group
,
3457 "alua", &target_core_alua_cit
);
3458 hba_cg
->default_groups
[0] = &alua_group
;
3459 hba_cg
->default_groups
[1] = NULL
;
3461 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
3462 * groups under /sys/kernel/config/target/core/alua/
3464 alua_cg
= &alua_group
;
3465 alua_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3467 if (!alua_cg
->default_groups
) {
3468 pr_err("Unable to allocate alua_cg->default_groups\n");
3473 config_group_init_type_name(&alua_lu_gps_group
,
3474 "lu_gps", &target_core_alua_lu_gps_cit
);
3475 alua_cg
->default_groups
[0] = &alua_lu_gps_group
;
3476 alua_cg
->default_groups
[1] = NULL
;
3478 * Add core/alua/lu_gps/default_lu_gp
3480 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
3481 if (IS_ERR(lu_gp
)) {
3486 lu_gp_cg
= &alua_lu_gps_group
;
3487 lu_gp_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
3489 if (!lu_gp_cg
->default_groups
) {
3490 pr_err("Unable to allocate lu_gp_cg->default_groups\n");
3495 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
3496 &target_core_alua_lu_gp_cit
);
3497 lu_gp_cg
->default_groups
[0] = &lu_gp
->lu_gp_group
;
3498 lu_gp_cg
->default_groups
[1] = NULL
;
3499 default_lu_gp
= lu_gp
;
3501 * Register the target_core_mod subsystem with configfs.
3503 ret
= configfs_register_subsystem(subsys
);
3505 pr_err("Error %d while registering subsystem %s\n",
3506 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
3509 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
3510 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION
" on %s/%s"
3511 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
3513 * Register built-in RAMDISK subsystem logic for virtual LUN 0
3515 ret
= rd_module_init();
3519 ret
= core_dev_setup_virtual_lun0();
3523 ret
= target_xcopy_setup_pt();
3530 configfs_unregister_subsystem(subsys
);
3531 core_dev_release_virtual_lun0();
3534 if (default_lu_gp
) {
3535 core_alua_free_lu_gp(default_lu_gp
);
3536 default_lu_gp
= NULL
;
3539 kfree(lu_gp_cg
->default_groups
);
3541 kfree(alua_cg
->default_groups
);
3543 kfree(hba_cg
->default_groups
);
3544 kfree(target_cg
->default_groups
);
3545 release_se_kmem_caches();
3549 static void __exit
target_core_exit_configfs(void)
3551 struct config_group
*hba_cg
, *alua_cg
, *lu_gp_cg
;
3552 struct config_item
*item
;
3555 lu_gp_cg
= &alua_lu_gps_group
;
3556 for (i
= 0; lu_gp_cg
->default_groups
[i
]; i
++) {
3557 item
= &lu_gp_cg
->default_groups
[i
]->cg_item
;
3558 lu_gp_cg
->default_groups
[i
] = NULL
;
3559 config_item_put(item
);
3561 kfree(lu_gp_cg
->default_groups
);
3562 lu_gp_cg
->default_groups
= NULL
;
3564 alua_cg
= &alua_group
;
3565 for (i
= 0; alua_cg
->default_groups
[i
]; i
++) {
3566 item
= &alua_cg
->default_groups
[i
]->cg_item
;
3567 alua_cg
->default_groups
[i
] = NULL
;
3568 config_item_put(item
);
3570 kfree(alua_cg
->default_groups
);
3571 alua_cg
->default_groups
= NULL
;
3573 hba_cg
= &target_core_hbagroup
;
3574 for (i
= 0; hba_cg
->default_groups
[i
]; i
++) {
3575 item
= &hba_cg
->default_groups
[i
]->cg_item
;
3576 hba_cg
->default_groups
[i
] = NULL
;
3577 config_item_put(item
);
3579 kfree(hba_cg
->default_groups
);
3580 hba_cg
->default_groups
= NULL
;
3582 * We expect subsys->su_group.default_groups to be released
3583 * by configfs subsystem provider logic..
3585 configfs_unregister_subsystem(&target_core_fabrics
);
3586 kfree(target_core_fabrics
.su_group
.default_groups
);
3588 core_alua_free_lu_gp(default_lu_gp
);
3589 default_lu_gp
= NULL
;
3591 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
3592 " Infrastructure\n");
3594 core_dev_release_virtual_lun0();
3596 target_xcopy_release_pt();
3597 release_se_kmem_caches();
3600 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3601 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3602 MODULE_LICENSE("GPL");
3604 module_init(target_core_init_configfs
);
3605 module_exit(target_core_exit_configfs
);