1 /*******************************************************************************
2 * Filename: target_core_configfs.c
4 * This file contains ConfigFS logic for the Generic Target Engine project.
6 * (c) Copyright 2008-2013 Datera, Inc.
8 * Nicholas A. Bellinger <nab@kernel.org>
10 * based on configfs Copyright (C) 2005 Oracle. All rights reserved.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 ****************************************************************************/
23 #include <linux/module.h>
24 #include <linux/moduleparam.h>
25 #include <generated/utsrelease.h>
26 #include <linux/utsname.h>
27 #include <linux/init.h>
29 #include <linux/namei.h>
30 #include <linux/slab.h>
31 #include <linux/types.h>
32 #include <linux/delay.h>
33 #include <linux/unistd.h>
34 #include <linux/string.h>
35 #include <linux/parser.h>
36 #include <linux/syscalls.h>
37 #include <linux/configfs.h>
38 #include <linux/spinlock.h>
40 #include <target/target_core_base.h>
41 #include <target/target_core_backend.h>
42 #include <target/target_core_fabric.h>
43 #include <target/target_core_fabric_configfs.h>
44 #include <target/target_core_configfs.h>
45 #include <target/configfs_macros.h>
47 #include "target_core_internal.h"
48 #include "target_core_alua.h"
49 #include "target_core_pr.h"
50 #include "target_core_rd.h"
51 #include "target_core_xcopy.h"
53 #define TB_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \
54 static void target_core_setup_##_name##_cit(struct se_subsystem_api *sa) \
56 struct target_backend_cits *tbc = &sa->tb_cits; \
57 struct config_item_type *cit = &tbc->tb_##_name##_cit; \
59 cit->ct_item_ops = _item_ops; \
60 cit->ct_group_ops = _group_ops; \
61 cit->ct_attrs = _attrs; \
62 cit->ct_owner = sa->owner; \
63 pr_debug("Setup generic %s\n", __stringify(_name)); \
66 extern struct t10_alua_lu_gp
*default_lu_gp
;
68 static LIST_HEAD(g_tf_list
);
69 static DEFINE_MUTEX(g_tf_lock
);
71 struct target_core_configfs_attribute
{
72 struct configfs_attribute attr
;
73 ssize_t (*show
)(void *, char *);
74 ssize_t (*store
)(void *, const char *, size_t);
77 static struct config_group target_core_hbagroup
;
78 static struct config_group alua_group
;
79 static struct config_group alua_lu_gps_group
;
81 static inline struct se_hba
*
82 item_to_hba(struct config_item
*item
)
84 return container_of(to_config_group(item
), struct se_hba
, hba_group
);
88 * Attributes for /sys/kernel/config/target/
90 static ssize_t
target_core_attr_show(struct config_item
*item
,
91 struct configfs_attribute
*attr
,
94 return sprintf(page
, "Target Engine Core ConfigFS Infrastructure %s"
95 " on %s/%s on "UTS_RELEASE
"\n", TARGET_CORE_CONFIGFS_VERSION
,
96 utsname()->sysname
, utsname()->machine
);
99 static struct configfs_item_operations target_core_fabric_item_ops
= {
100 .show_attribute
= target_core_attr_show
,
103 static struct configfs_attribute target_core_item_attr_version
= {
104 .ca_owner
= THIS_MODULE
,
105 .ca_name
= "version",
109 static struct target_fabric_configfs
*target_core_get_fabric(
112 struct target_fabric_configfs
*tf
;
117 mutex_lock(&g_tf_lock
);
118 list_for_each_entry(tf
, &g_tf_list
, tf_list
) {
119 if (!strcmp(tf
->tf_name
, name
)) {
120 atomic_inc(&tf
->tf_access_cnt
);
121 mutex_unlock(&g_tf_lock
);
125 mutex_unlock(&g_tf_lock
);
131 * Called from struct target_core_group_ops->make_group()
133 static struct config_group
*target_core_register_fabric(
134 struct config_group
*group
,
137 struct target_fabric_configfs
*tf
;
140 pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:"
141 " %s\n", group
, name
);
143 tf
= target_core_get_fabric(name
);
145 pr_debug("target_core_register_fabric() trying autoload for %s\n",
149 * Below are some hardcoded request_module() calls to automatically
150 * local fabric modules when the following is called:
152 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
154 * Note that this does not limit which TCM fabric module can be
155 * registered, but simply provids auto loading logic for modules with
156 * mkdir(2) system calls with known TCM fabric modules.
159 if (!strncmp(name
, "iscsi", 5)) {
161 * Automatically load the LIO Target fabric module when the
162 * following is called:
164 * mkdir -p $CONFIGFS/target/iscsi
166 ret
= request_module("iscsi_target_mod");
168 pr_debug("request_module() failed for"
169 " iscsi_target_mod.ko: %d\n", ret
);
170 return ERR_PTR(-EINVAL
);
172 } else if (!strncmp(name
, "loopback", 8)) {
174 * Automatically load the tcm_loop fabric module when the
175 * following is called:
177 * mkdir -p $CONFIGFS/target/loopback
179 ret
= request_module("tcm_loop");
181 pr_debug("request_module() failed for"
182 " tcm_loop.ko: %d\n", ret
);
183 return ERR_PTR(-EINVAL
);
187 tf
= target_core_get_fabric(name
);
191 pr_debug("target_core_get_fabric() failed for %s\n",
193 return ERR_PTR(-EINVAL
);
195 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
196 " %s\n", tf
->tf_name
);
198 * On a successful target_core_get_fabric() look, the returned
199 * struct target_fabric_configfs *tf will contain a usage reference.
201 pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
202 &tf
->tf_cit_tmpl
.tfc_wwn_cit
);
204 tf
->tf_group
.default_groups
= tf
->tf_default_groups
;
205 tf
->tf_group
.default_groups
[0] = &tf
->tf_disc_group
;
206 tf
->tf_group
.default_groups
[1] = NULL
;
208 config_group_init_type_name(&tf
->tf_group
, name
,
209 &tf
->tf_cit_tmpl
.tfc_wwn_cit
);
210 config_group_init_type_name(&tf
->tf_disc_group
, "discovery_auth",
211 &tf
->tf_cit_tmpl
.tfc_discovery_cit
);
213 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
214 " %s\n", tf
->tf_group
.cg_item
.ci_name
);
215 tf
->tf_fabric
= &tf
->tf_group
.cg_item
;
216 pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
219 return &tf
->tf_group
;
223 * Called from struct target_core_group_ops->drop_item()
225 static void target_core_deregister_fabric(
226 struct config_group
*group
,
227 struct config_item
*item
)
229 struct target_fabric_configfs
*tf
= container_of(
230 to_config_group(item
), struct target_fabric_configfs
, tf_group
);
231 struct config_group
*tf_group
;
232 struct config_item
*df_item
;
235 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
236 " tf list\n", config_item_name(item
));
238 pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:"
239 " %s\n", tf
->tf_name
);
240 atomic_dec(&tf
->tf_access_cnt
);
242 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing"
243 " tf->tf_fabric for %s\n", tf
->tf_name
);
244 tf
->tf_fabric
= NULL
;
246 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
247 " %s\n", config_item_name(item
));
249 tf_group
= &tf
->tf_group
;
250 for (i
= 0; tf_group
->default_groups
[i
]; i
++) {
251 df_item
= &tf_group
->default_groups
[i
]->cg_item
;
252 tf_group
->default_groups
[i
] = NULL
;
253 config_item_put(df_item
);
255 config_item_put(item
);
258 static struct configfs_group_operations target_core_fabric_group_ops
= {
259 .make_group
= &target_core_register_fabric
,
260 .drop_item
= &target_core_deregister_fabric
,
264 * All item attributes appearing in /sys/kernel/target/ appear here.
266 static struct configfs_attribute
*target_core_fabric_item_attrs
[] = {
267 &target_core_item_attr_version
,
272 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
274 static struct config_item_type target_core_fabrics_item
= {
275 .ct_item_ops
= &target_core_fabric_item_ops
,
276 .ct_group_ops
= &target_core_fabric_group_ops
,
277 .ct_attrs
= target_core_fabric_item_attrs
,
278 .ct_owner
= THIS_MODULE
,
281 static struct configfs_subsystem target_core_fabrics
= {
284 .ci_namebuf
= "target",
285 .ci_type
= &target_core_fabrics_item
,
290 int target_depend_item(struct config_item
*item
)
292 return configfs_depend_item(&target_core_fabrics
, item
);
294 EXPORT_SYMBOL(target_depend_item
);
296 void target_undepend_item(struct config_item
*item
)
298 return configfs_undepend_item(&target_core_fabrics
, item
);
300 EXPORT_SYMBOL(target_undepend_item
);
302 /*##############################################################################
303 // Start functions called by external Target Fabrics Modules
304 //############################################################################*/
306 static int target_fabric_tf_ops_check(const struct target_core_fabric_ops
*tfo
)
309 pr_err("Missing tfo->name\n");
312 if (strlen(tfo
->name
) >= TARGET_FABRIC_NAME_SIZE
) {
313 pr_err("Passed name: %s exceeds TARGET_FABRIC"
314 "_NAME_SIZE\n", tfo
->name
);
317 if (!tfo
->get_fabric_name
) {
318 pr_err("Missing tfo->get_fabric_name()\n");
321 if (!tfo
->tpg_get_wwn
) {
322 pr_err("Missing tfo->tpg_get_wwn()\n");
325 if (!tfo
->tpg_get_tag
) {
326 pr_err("Missing tfo->tpg_get_tag()\n");
329 if (!tfo
->tpg_check_demo_mode
) {
330 pr_err("Missing tfo->tpg_check_demo_mode()\n");
333 if (!tfo
->tpg_check_demo_mode_cache
) {
334 pr_err("Missing tfo->tpg_check_demo_mode_cache()\n");
337 if (!tfo
->tpg_check_demo_mode_write_protect
) {
338 pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n");
341 if (!tfo
->tpg_check_prod_mode_write_protect
) {
342 pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n");
345 if (!tfo
->tpg_get_inst_index
) {
346 pr_err("Missing tfo->tpg_get_inst_index()\n");
349 if (!tfo
->release_cmd
) {
350 pr_err("Missing tfo->release_cmd()\n");
353 if (!tfo
->shutdown_session
) {
354 pr_err("Missing tfo->shutdown_session()\n");
357 if (!tfo
->close_session
) {
358 pr_err("Missing tfo->close_session()\n");
361 if (!tfo
->sess_get_index
) {
362 pr_err("Missing tfo->sess_get_index()\n");
365 if (!tfo
->write_pending
) {
366 pr_err("Missing tfo->write_pending()\n");
369 if (!tfo
->write_pending_status
) {
370 pr_err("Missing tfo->write_pending_status()\n");
373 if (!tfo
->set_default_node_attributes
) {
374 pr_err("Missing tfo->set_default_node_attributes()\n");
377 if (!tfo
->get_cmd_state
) {
378 pr_err("Missing tfo->get_cmd_state()\n");
381 if (!tfo
->queue_data_in
) {
382 pr_err("Missing tfo->queue_data_in()\n");
385 if (!tfo
->queue_status
) {
386 pr_err("Missing tfo->queue_status()\n");
389 if (!tfo
->queue_tm_rsp
) {
390 pr_err("Missing tfo->queue_tm_rsp()\n");
393 if (!tfo
->aborted_task
) {
394 pr_err("Missing tfo->aborted_task()\n");
398 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
399 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
400 * target_core_fabric_configfs.c WWN+TPG group context code.
402 if (!tfo
->fabric_make_wwn
) {
403 pr_err("Missing tfo->fabric_make_wwn()\n");
406 if (!tfo
->fabric_drop_wwn
) {
407 pr_err("Missing tfo->fabric_drop_wwn()\n");
410 if (!tfo
->fabric_make_tpg
) {
411 pr_err("Missing tfo->fabric_make_tpg()\n");
414 if (!tfo
->fabric_drop_tpg
) {
415 pr_err("Missing tfo->fabric_drop_tpg()\n");
422 int target_register_template(const struct target_core_fabric_ops
*fo
)
424 struct target_fabric_configfs
*tf
;
427 ret
= target_fabric_tf_ops_check(fo
);
431 tf
= kzalloc(sizeof(struct target_fabric_configfs
), GFP_KERNEL
);
433 pr_err("%s: could not allocate memory!\n", __func__
);
437 INIT_LIST_HEAD(&tf
->tf_list
);
438 atomic_set(&tf
->tf_access_cnt
, 0);
441 * Setup the default generic struct config_item_type's (cits) in
442 * struct target_fabric_configfs->tf_cit_tmpl
444 tf
->tf_module
= fo
->module
;
445 snprintf(tf
->tf_name
, TARGET_FABRIC_NAME_SIZE
, "%s", fo
->name
);
448 target_fabric_setup_cits(tf
);
450 mutex_lock(&g_tf_lock
);
451 list_add_tail(&tf
->tf_list
, &g_tf_list
);
452 mutex_unlock(&g_tf_lock
);
456 EXPORT_SYMBOL(target_register_template
);
458 void target_unregister_template(const struct target_core_fabric_ops
*fo
)
460 struct target_fabric_configfs
*t
;
462 mutex_lock(&g_tf_lock
);
463 list_for_each_entry(t
, &g_tf_list
, tf_list
) {
464 if (!strcmp(t
->tf_name
, fo
->name
)) {
465 BUG_ON(atomic_read(&t
->tf_access_cnt
));
466 list_del(&t
->tf_list
);
471 mutex_unlock(&g_tf_lock
);
473 EXPORT_SYMBOL(target_unregister_template
);
475 /*##############################################################################
476 // Stop functions called by external Target Fabrics Modules
477 //############################################################################*/
479 /* Start functions for struct config_item_type tb_dev_attrib_cit */
481 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib
, se_dev_attrib
);
482 CONFIGFS_EATTR_OPS(target_core_dev_attrib
, se_dev_attrib
, da_group
);
484 static struct configfs_item_operations target_core_dev_attrib_ops
= {
485 .show_attribute
= target_core_dev_attrib_attr_show
,
486 .store_attribute
= target_core_dev_attrib_attr_store
,
489 TB_CIT_SETUP(dev_attrib
, &target_core_dev_attrib_ops
, NULL
, NULL
);
491 /* End functions for struct config_item_type tb_dev_attrib_cit */
493 /* Start functions for struct config_item_type tb_dev_wwn_cit */
495 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn
, t10_wwn
);
496 #define SE_DEV_WWN_ATTR(_name, _mode) \
497 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
498 __CONFIGFS_EATTR(_name, _mode, \
499 target_core_dev_wwn_show_attr_##_name, \
500 target_core_dev_wwn_store_attr_##_name);
502 #define SE_DEV_WWN_ATTR_RO(_name); \
504 static struct target_core_dev_wwn_attribute \
505 target_core_dev_wwn_##_name = \
506 __CONFIGFS_EATTR_RO(_name, \
507 target_core_dev_wwn_show_attr_##_name); \
511 * VPD page 0x80 Unit serial
513 static ssize_t
target_core_dev_wwn_show_attr_vpd_unit_serial(
514 struct t10_wwn
*t10_wwn
,
517 return sprintf(page
, "T10 VPD Unit Serial Number: %s\n",
518 &t10_wwn
->unit_serial
[0]);
521 static ssize_t
target_core_dev_wwn_store_attr_vpd_unit_serial(
522 struct t10_wwn
*t10_wwn
,
526 struct se_device
*dev
= t10_wwn
->t10_dev
;
527 unsigned char buf
[INQUIRY_VPD_SERIAL_LEN
];
530 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
531 * from the struct scsi_device level firmware, do not allow
532 * VPD Unit Serial to be emulated.
534 * Note this struct scsi_device could also be emulating VPD
535 * information from its drivers/scsi LLD. But for now we assume
536 * it is doing 'the right thing' wrt a world wide unique
537 * VPD Unit Serial Number that OS dependent multipath can depend on.
539 if (dev
->dev_flags
& DF_FIRMWARE_VPD_UNIT_SERIAL
) {
540 pr_err("Underlying SCSI device firmware provided VPD"
541 " Unit Serial, ignoring request\n");
545 if (strlen(page
) >= INQUIRY_VPD_SERIAL_LEN
) {
546 pr_err("Emulated VPD Unit Serial exceeds"
547 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN
);
551 * Check to see if any active $FABRIC_MOD exports exist. If they
552 * do exist, fail here as changing this information on the fly
553 * (underneath the initiator side OS dependent multipath code)
554 * could cause negative effects.
556 if (dev
->export_count
) {
557 pr_err("Unable to set VPD Unit Serial while"
558 " active %d $FABRIC_MOD exports exist\n",
564 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
566 * Also, strip any newline added from the userspace
567 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
569 memset(buf
, 0, INQUIRY_VPD_SERIAL_LEN
);
570 snprintf(buf
, INQUIRY_VPD_SERIAL_LEN
, "%s", page
);
571 snprintf(dev
->t10_wwn
.unit_serial
, INQUIRY_VPD_SERIAL_LEN
,
572 "%s", strstrip(buf
));
573 dev
->dev_flags
|= DF_EMULATED_VPD_UNIT_SERIAL
;
575 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
576 " %s\n", dev
->t10_wwn
.unit_serial
);
581 SE_DEV_WWN_ATTR(vpd_unit_serial
, S_IRUGO
| S_IWUSR
);
584 * VPD page 0x83 Protocol Identifier
586 static ssize_t
target_core_dev_wwn_show_attr_vpd_protocol_identifier(
587 struct t10_wwn
*t10_wwn
,
591 unsigned char buf
[VPD_TMP_BUF_SIZE
];
594 memset(buf
, 0, VPD_TMP_BUF_SIZE
);
596 spin_lock(&t10_wwn
->t10_vpd_lock
);
597 list_for_each_entry(vpd
, &t10_wwn
->t10_vpd_list
, vpd_list
) {
598 if (!vpd
->protocol_identifier_set
)
601 transport_dump_vpd_proto_id(vpd
, buf
, VPD_TMP_BUF_SIZE
);
603 if (len
+ strlen(buf
) >= PAGE_SIZE
)
606 len
+= sprintf(page
+len
, "%s", buf
);
608 spin_unlock(&t10_wwn
->t10_vpd_lock
);
613 static ssize_t
target_core_dev_wwn_store_attr_vpd_protocol_identifier(
614 struct t10_wwn
*t10_wwn
,
621 SE_DEV_WWN_ATTR(vpd_protocol_identifier
, S_IRUGO
| S_IWUSR
);
624 * Generic wrapper for dumping VPD identifiers by association.
626 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
627 static ssize_t target_core_dev_wwn_show_attr_##_name( \
628 struct t10_wwn *t10_wwn, \
631 struct t10_vpd *vpd; \
632 unsigned char buf[VPD_TMP_BUF_SIZE]; \
635 spin_lock(&t10_wwn->t10_vpd_lock); \
636 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
637 if (vpd->association != _assoc) \
640 memset(buf, 0, VPD_TMP_BUF_SIZE); \
641 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
642 if (len + strlen(buf) >= PAGE_SIZE) \
644 len += sprintf(page+len, "%s", buf); \
646 memset(buf, 0, VPD_TMP_BUF_SIZE); \
647 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
648 if (len + strlen(buf) >= PAGE_SIZE) \
650 len += sprintf(page+len, "%s", buf); \
652 memset(buf, 0, VPD_TMP_BUF_SIZE); \
653 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
654 if (len + strlen(buf) >= PAGE_SIZE) \
656 len += sprintf(page+len, "%s", buf); \
658 spin_unlock(&t10_wwn->t10_vpd_lock); \
664 * VPD page 0x83 Association: Logical Unit
666 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit
, 0x00);
668 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
669 struct t10_wwn
*t10_wwn
,
676 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit
, S_IRUGO
| S_IWUSR
);
679 * VPD page 0x83 Association: Target Port
681 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port
, 0x10);
683 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_target_port(
684 struct t10_wwn
*t10_wwn
,
691 SE_DEV_WWN_ATTR(vpd_assoc_target_port
, S_IRUGO
| S_IWUSR
);
694 * VPD page 0x83 Association: SCSI Target Device
696 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device
, 0x20);
698 static ssize_t
target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
699 struct t10_wwn
*t10_wwn
,
706 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device
, S_IRUGO
| S_IWUSR
);
708 CONFIGFS_EATTR_OPS(target_core_dev_wwn
, t10_wwn
, t10_wwn_group
);
710 static struct configfs_attribute
*target_core_dev_wwn_attrs
[] = {
711 &target_core_dev_wwn_vpd_unit_serial
.attr
,
712 &target_core_dev_wwn_vpd_protocol_identifier
.attr
,
713 &target_core_dev_wwn_vpd_assoc_logical_unit
.attr
,
714 &target_core_dev_wwn_vpd_assoc_target_port
.attr
,
715 &target_core_dev_wwn_vpd_assoc_scsi_target_device
.attr
,
719 static struct configfs_item_operations target_core_dev_wwn_ops
= {
720 .show_attribute
= target_core_dev_wwn_attr_show
,
721 .store_attribute
= target_core_dev_wwn_attr_store
,
724 TB_CIT_SETUP(dev_wwn
, &target_core_dev_wwn_ops
, NULL
, target_core_dev_wwn_attrs
);
726 /* End functions for struct config_item_type tb_dev_wwn_cit */
728 /* Start functions for struct config_item_type tb_dev_pr_cit */
730 CONFIGFS_EATTR_STRUCT(target_core_dev_pr
, se_device
);
731 #define SE_DEV_PR_ATTR(_name, _mode) \
732 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
733 __CONFIGFS_EATTR(_name, _mode, \
734 target_core_dev_pr_show_attr_##_name, \
735 target_core_dev_pr_store_attr_##_name);
737 #define SE_DEV_PR_ATTR_RO(_name); \
738 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
739 __CONFIGFS_EATTR_RO(_name, \
740 target_core_dev_pr_show_attr_##_name);
742 static ssize_t
target_core_dev_pr_show_spc3_res(struct se_device
*dev
,
745 struct se_node_acl
*se_nacl
;
746 struct t10_pr_registration
*pr_reg
;
747 char i_buf
[PR_REG_ISID_ID_LEN
];
749 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
751 pr_reg
= dev
->dev_pr_res_holder
;
753 return sprintf(page
, "No SPC-3 Reservation holder\n");
755 se_nacl
= pr_reg
->pr_reg_nacl
;
756 core_pr_dump_initiator_port(pr_reg
, i_buf
, PR_REG_ISID_ID_LEN
);
758 return sprintf(page
, "SPC-3 Reservation: %s Initiator: %s%s\n",
759 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
760 se_nacl
->initiatorname
, i_buf
);
763 static ssize_t
target_core_dev_pr_show_spc2_res(struct se_device
*dev
,
766 struct se_node_acl
*se_nacl
;
769 se_nacl
= dev
->dev_reserved_node_acl
;
772 "SPC-2 Reservation: %s Initiator: %s\n",
773 se_nacl
->se_tpg
->se_tpg_tfo
->get_fabric_name(),
774 se_nacl
->initiatorname
);
776 len
= sprintf(page
, "No SPC-2 Reservation holder\n");
781 static ssize_t
target_core_dev_pr_show_attr_res_holder(struct se_device
*dev
,
786 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
787 return sprintf(page
, "Passthrough\n");
789 spin_lock(&dev
->dev_reservation_lock
);
790 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
791 ret
= target_core_dev_pr_show_spc2_res(dev
, page
);
793 ret
= target_core_dev_pr_show_spc3_res(dev
, page
);
794 spin_unlock(&dev
->dev_reservation_lock
);
798 SE_DEV_PR_ATTR_RO(res_holder
);
800 static ssize_t
target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
801 struct se_device
*dev
, char *page
)
805 spin_lock(&dev
->dev_reservation_lock
);
806 if (!dev
->dev_pr_res_holder
) {
807 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
808 } else if (dev
->dev_pr_res_holder
->pr_reg_all_tg_pt
) {
809 len
= sprintf(page
, "SPC-3 Reservation: All Target"
810 " Ports registration\n");
812 len
= sprintf(page
, "SPC-3 Reservation: Single"
813 " Target Port registration\n");
816 spin_unlock(&dev
->dev_reservation_lock
);
820 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts
);
822 static ssize_t
target_core_dev_pr_show_attr_res_pr_generation(
823 struct se_device
*dev
, char *page
)
825 return sprintf(page
, "0x%08x\n", dev
->t10_pr
.pr_generation
);
828 SE_DEV_PR_ATTR_RO(res_pr_generation
);
831 * res_pr_holder_tg_port
833 static ssize_t
target_core_dev_pr_show_attr_res_pr_holder_tg_port(
834 struct se_device
*dev
, char *page
)
836 struct se_node_acl
*se_nacl
;
838 struct se_portal_group
*se_tpg
;
839 struct t10_pr_registration
*pr_reg
;
840 const struct target_core_fabric_ops
*tfo
;
843 spin_lock(&dev
->dev_reservation_lock
);
844 pr_reg
= dev
->dev_pr_res_holder
;
846 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
850 se_nacl
= pr_reg
->pr_reg_nacl
;
851 se_tpg
= se_nacl
->se_tpg
;
852 lun
= pr_reg
->pr_reg_tg_pt_lun
;
853 tfo
= se_tpg
->se_tpg_tfo
;
855 len
+= sprintf(page
+len
, "SPC-3 Reservation: %s"
856 " Target Node Endpoint: %s\n", tfo
->get_fabric_name(),
857 tfo
->tpg_get_wwn(se_tpg
));
858 len
+= sprintf(page
+len
, "SPC-3 Reservation: Relative Port"
859 " Identifier Tag: %hu %s Portal Group Tag: %hu"
860 " %s Logical Unit: %u\n", lun
->lun_sep
->sep_rtpi
,
861 tfo
->get_fabric_name(), tfo
->tpg_get_tag(se_tpg
),
862 tfo
->get_fabric_name(), lun
->unpacked_lun
);
865 spin_unlock(&dev
->dev_reservation_lock
);
869 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port
);
871 static ssize_t
target_core_dev_pr_show_attr_res_pr_registered_i_pts(
872 struct se_device
*dev
, char *page
)
874 const struct target_core_fabric_ops
*tfo
;
875 struct t10_pr_registration
*pr_reg
;
876 unsigned char buf
[384];
877 char i_buf
[PR_REG_ISID_ID_LEN
];
881 len
+= sprintf(page
+len
, "SPC-3 PR Registrations:\n");
883 spin_lock(&dev
->t10_pr
.registration_lock
);
884 list_for_each_entry(pr_reg
, &dev
->t10_pr
.registration_list
,
888 memset(i_buf
, 0, PR_REG_ISID_ID_LEN
);
889 tfo
= pr_reg
->pr_reg_nacl
->se_tpg
->se_tpg_tfo
;
890 core_pr_dump_initiator_port(pr_reg
, i_buf
,
892 sprintf(buf
, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
893 tfo
->get_fabric_name(),
894 pr_reg
->pr_reg_nacl
->initiatorname
, i_buf
, pr_reg
->pr_res_key
,
895 pr_reg
->pr_res_generation
);
897 if (len
+ strlen(buf
) >= PAGE_SIZE
)
900 len
+= sprintf(page
+len
, "%s", buf
);
903 spin_unlock(&dev
->t10_pr
.registration_lock
);
906 len
+= sprintf(page
+len
, "None\n");
911 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts
);
913 static ssize_t
target_core_dev_pr_show_attr_res_pr_type(
914 struct se_device
*dev
, char *page
)
916 struct t10_pr_registration
*pr_reg
;
919 spin_lock(&dev
->dev_reservation_lock
);
920 pr_reg
= dev
->dev_pr_res_holder
;
922 len
= sprintf(page
, "SPC-3 Reservation Type: %s\n",
923 core_scsi3_pr_dump_type(pr_reg
->pr_res_type
));
925 len
= sprintf(page
, "No SPC-3 Reservation holder\n");
928 spin_unlock(&dev
->dev_reservation_lock
);
932 SE_DEV_PR_ATTR_RO(res_pr_type
);
934 static ssize_t
target_core_dev_pr_show_attr_res_type(
935 struct se_device
*dev
, char *page
)
937 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
938 return sprintf(page
, "SPC_PASSTHROUGH\n");
939 else if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
940 return sprintf(page
, "SPC2_RESERVATIONS\n");
942 return sprintf(page
, "SPC3_PERSISTENT_RESERVATIONS\n");
945 SE_DEV_PR_ATTR_RO(res_type
);
947 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_active(
948 struct se_device
*dev
, char *page
)
950 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
953 return sprintf(page
, "APTPL Bit Status: %s\n",
954 (dev
->t10_pr
.pr_aptpl_active
) ? "Activated" : "Disabled");
957 SE_DEV_PR_ATTR_RO(res_aptpl_active
);
962 static ssize_t
target_core_dev_pr_show_attr_res_aptpl_metadata(
963 struct se_device
*dev
, char *page
)
965 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
968 return sprintf(page
, "Ready to process PR APTPL metadata..\n");
972 Opt_initiator_fabric
, Opt_initiator_node
, Opt_initiator_sid
,
973 Opt_sa_res_key
, Opt_res_holder
, Opt_res_type
, Opt_res_scope
,
974 Opt_res_all_tg_pt
, Opt_mapped_lun
, Opt_target_fabric
,
975 Opt_target_node
, Opt_tpgt
, Opt_port_rtpi
, Opt_target_lun
, Opt_err
978 static match_table_t tokens
= {
979 {Opt_initiator_fabric
, "initiator_fabric=%s"},
980 {Opt_initiator_node
, "initiator_node=%s"},
981 {Opt_initiator_sid
, "initiator_sid=%s"},
982 {Opt_sa_res_key
, "sa_res_key=%s"},
983 {Opt_res_holder
, "res_holder=%d"},
984 {Opt_res_type
, "res_type=%d"},
985 {Opt_res_scope
, "res_scope=%d"},
986 {Opt_res_all_tg_pt
, "res_all_tg_pt=%d"},
987 {Opt_mapped_lun
, "mapped_lun=%d"},
988 {Opt_target_fabric
, "target_fabric=%s"},
989 {Opt_target_node
, "target_node=%s"},
990 {Opt_tpgt
, "tpgt=%d"},
991 {Opt_port_rtpi
, "port_rtpi=%d"},
992 {Opt_target_lun
, "target_lun=%d"},
996 static ssize_t
target_core_dev_pr_store_attr_res_aptpl_metadata(
997 struct se_device
*dev
,
1001 unsigned char *i_fabric
= NULL
, *i_port
= NULL
, *isid
= NULL
;
1002 unsigned char *t_fabric
= NULL
, *t_port
= NULL
;
1003 char *orig
, *ptr
, *opts
;
1004 substring_t args
[MAX_OPT_ARGS
];
1005 unsigned long long tmp_ll
;
1007 u32 mapped_lun
= 0, target_lun
= 0;
1008 int ret
= -1, res_holder
= 0, all_tg_pt
= 0, arg
, token
;
1012 if (dev
->transport
->transport_flags
& TRANSPORT_FLAG_PASSTHROUGH
)
1014 if (dev
->dev_reservation_flags
& DRF_SPC2_RESERVATIONS
)
1017 if (dev
->export_count
) {
1018 pr_debug("Unable to process APTPL metadata while"
1019 " active fabric exports exist\n");
1023 opts
= kstrdup(page
, GFP_KERNEL
);
1028 while ((ptr
= strsep(&opts
, ",\n")) != NULL
) {
1032 token
= match_token(ptr
, tokens
, args
);
1034 case Opt_initiator_fabric
:
1035 i_fabric
= match_strdup(args
);
1041 case Opt_initiator_node
:
1042 i_port
= match_strdup(args
);
1047 if (strlen(i_port
) >= PR_APTPL_MAX_IPORT_LEN
) {
1048 pr_err("APTPL metadata initiator_node="
1049 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1050 PR_APTPL_MAX_IPORT_LEN
);
1055 case Opt_initiator_sid
:
1056 isid
= match_strdup(args
);
1061 if (strlen(isid
) >= PR_REG_ISID_LEN
) {
1062 pr_err("APTPL metadata initiator_isid"
1063 "= exceeds PR_REG_ISID_LEN: %d\n",
1069 case Opt_sa_res_key
:
1070 ret
= kstrtoull(args
->from
, 0, &tmp_ll
);
1072 pr_err("kstrtoull() failed for sa_res_key=\n");
1075 sa_res_key
= (u64
)tmp_ll
;
1078 * PR APTPL Metadata for Reservation
1080 case Opt_res_holder
:
1081 match_int(args
, &arg
);
1085 match_int(args
, &arg
);
1089 match_int(args
, &arg
);
1091 case Opt_res_all_tg_pt
:
1092 match_int(args
, &arg
);
1093 all_tg_pt
= (int)arg
;
1095 case Opt_mapped_lun
:
1096 match_int(args
, &arg
);
1097 mapped_lun
= (u32
)arg
;
1100 * PR APTPL Metadata for Target Port
1102 case Opt_target_fabric
:
1103 t_fabric
= match_strdup(args
);
1109 case Opt_target_node
:
1110 t_port
= match_strdup(args
);
1115 if (strlen(t_port
) >= PR_APTPL_MAX_TPORT_LEN
) {
1116 pr_err("APTPL metadata target_node="
1117 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1118 PR_APTPL_MAX_TPORT_LEN
);
1124 match_int(args
, &arg
);
1128 match_int(args
, &arg
);
1130 case Opt_target_lun
:
1131 match_int(args
, &arg
);
1132 target_lun
= (u32
)arg
;
1139 if (!i_port
|| !t_port
|| !sa_res_key
) {
1140 pr_err("Illegal parameters for APTPL registration\n");
1145 if (res_holder
&& !(type
)) {
1146 pr_err("Illegal PR type: 0x%02x for reservation"
1152 ret
= core_scsi3_alloc_aptpl_registration(&dev
->t10_pr
, sa_res_key
,
1153 i_port
, isid
, mapped_lun
, t_port
, tpgt
, target_lun
,
1154 res_holder
, all_tg_pt
, type
);
1162 return (ret
== 0) ? count
: ret
;
1165 SE_DEV_PR_ATTR(res_aptpl_metadata
, S_IRUGO
| S_IWUSR
);
1167 CONFIGFS_EATTR_OPS(target_core_dev_pr
, se_device
, dev_pr_group
);
1169 static struct configfs_attribute
*target_core_dev_pr_attrs
[] = {
1170 &target_core_dev_pr_res_holder
.attr
,
1171 &target_core_dev_pr_res_pr_all_tgt_pts
.attr
,
1172 &target_core_dev_pr_res_pr_generation
.attr
,
1173 &target_core_dev_pr_res_pr_holder_tg_port
.attr
,
1174 &target_core_dev_pr_res_pr_registered_i_pts
.attr
,
1175 &target_core_dev_pr_res_pr_type
.attr
,
1176 &target_core_dev_pr_res_type
.attr
,
1177 &target_core_dev_pr_res_aptpl_active
.attr
,
1178 &target_core_dev_pr_res_aptpl_metadata
.attr
,
1182 static struct configfs_item_operations target_core_dev_pr_ops
= {
1183 .show_attribute
= target_core_dev_pr_attr_show
,
1184 .store_attribute
= target_core_dev_pr_attr_store
,
1187 TB_CIT_SETUP(dev_pr
, &target_core_dev_pr_ops
, NULL
, target_core_dev_pr_attrs
);
1189 /* End functions for struct config_item_type tb_dev_pr_cit */
1191 /* Start functions for struct config_item_type tb_dev_cit */
1193 static ssize_t
target_core_show_dev_info(void *p
, char *page
)
1195 struct se_device
*dev
= p
;
1196 struct se_subsystem_api
*t
= dev
->transport
;
1198 ssize_t read_bytes
= 0;
1200 transport_dump_dev_state(dev
, page
, &bl
);
1202 read_bytes
+= t
->show_configfs_dev_params(dev
, page
+read_bytes
);
1206 static struct target_core_configfs_attribute target_core_attr_dev_info
= {
1207 .attr
= { .ca_owner
= THIS_MODULE
,
1209 .ca_mode
= S_IRUGO
},
1210 .show
= target_core_show_dev_info
,
1214 static ssize_t
target_core_store_dev_control(
1219 struct se_device
*dev
= p
;
1220 struct se_subsystem_api
*t
= dev
->transport
;
1222 return t
->set_configfs_dev_params(dev
, page
, count
);
1225 static struct target_core_configfs_attribute target_core_attr_dev_control
= {
1226 .attr
= { .ca_owner
= THIS_MODULE
,
1227 .ca_name
= "control",
1228 .ca_mode
= S_IWUSR
},
1230 .store
= target_core_store_dev_control
,
1233 static ssize_t
target_core_show_dev_alias(void *p
, char *page
)
1235 struct se_device
*dev
= p
;
1237 if (!(dev
->dev_flags
& DF_USING_ALIAS
))
1240 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->dev_alias
);
1243 static ssize_t
target_core_store_dev_alias(
1248 struct se_device
*dev
= p
;
1249 struct se_hba
*hba
= dev
->se_hba
;
1252 if (count
> (SE_DEV_ALIAS_LEN
-1)) {
1253 pr_err("alias count: %d exceeds"
1254 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count
,
1255 SE_DEV_ALIAS_LEN
-1);
1259 read_bytes
= snprintf(&dev
->dev_alias
[0], SE_DEV_ALIAS_LEN
, "%s", page
);
1262 if (dev
->dev_alias
[read_bytes
- 1] == '\n')
1263 dev
->dev_alias
[read_bytes
- 1] = '\0';
1265 dev
->dev_flags
|= DF_USING_ALIAS
;
1267 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
1268 config_item_name(&hba
->hba_group
.cg_item
),
1269 config_item_name(&dev
->dev_group
.cg_item
),
1275 static struct target_core_configfs_attribute target_core_attr_dev_alias
= {
1276 .attr
= { .ca_owner
= THIS_MODULE
,
1278 .ca_mode
= S_IRUGO
| S_IWUSR
},
1279 .show
= target_core_show_dev_alias
,
1280 .store
= target_core_store_dev_alias
,
1283 static ssize_t
target_core_show_dev_udev_path(void *p
, char *page
)
1285 struct se_device
*dev
= p
;
1287 if (!(dev
->dev_flags
& DF_USING_UDEV_PATH
))
1290 return snprintf(page
, PAGE_SIZE
, "%s\n", dev
->udev_path
);
1293 static ssize_t
target_core_store_dev_udev_path(
1298 struct se_device
*dev
= p
;
1299 struct se_hba
*hba
= dev
->se_hba
;
1302 if (count
> (SE_UDEV_PATH_LEN
-1)) {
1303 pr_err("udev_path count: %d exceeds"
1304 " SE_UDEV_PATH_LEN-1: %u\n", (int)count
,
1305 SE_UDEV_PATH_LEN
-1);
1309 read_bytes
= snprintf(&dev
->udev_path
[0], SE_UDEV_PATH_LEN
,
1313 if (dev
->udev_path
[read_bytes
- 1] == '\n')
1314 dev
->udev_path
[read_bytes
- 1] = '\0';
1316 dev
->dev_flags
|= DF_USING_UDEV_PATH
;
1318 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1319 config_item_name(&hba
->hba_group
.cg_item
),
1320 config_item_name(&dev
->dev_group
.cg_item
),
1326 static struct target_core_configfs_attribute target_core_attr_dev_udev_path
= {
1327 .attr
= { .ca_owner
= THIS_MODULE
,
1328 .ca_name
= "udev_path",
1329 .ca_mode
= S_IRUGO
| S_IWUSR
},
1330 .show
= target_core_show_dev_udev_path
,
1331 .store
= target_core_store_dev_udev_path
,
1334 static ssize_t
target_core_show_dev_enable(void *p
, char *page
)
1336 struct se_device
*dev
= p
;
1338 return snprintf(page
, PAGE_SIZE
, "%d\n", !!(dev
->dev_flags
& DF_CONFIGURED
));
1341 static ssize_t
target_core_store_dev_enable(
1346 struct se_device
*dev
= p
;
1350 ptr
= strstr(page
, "1");
1352 pr_err("For dev_enable ops, only valid value"
1357 ret
= target_configure_device(dev
);
1363 static struct target_core_configfs_attribute target_core_attr_dev_enable
= {
1364 .attr
= { .ca_owner
= THIS_MODULE
,
1365 .ca_name
= "enable",
1366 .ca_mode
= S_IRUGO
| S_IWUSR
},
1367 .show
= target_core_show_dev_enable
,
1368 .store
= target_core_store_dev_enable
,
1371 static ssize_t
target_core_show_alua_lu_gp(void *p
, char *page
)
1373 struct se_device
*dev
= p
;
1374 struct config_item
*lu_ci
;
1375 struct t10_alua_lu_gp
*lu_gp
;
1376 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1379 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1383 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1384 lu_gp
= lu_gp_mem
->lu_gp
;
1386 lu_ci
= &lu_gp
->lu_gp_group
.cg_item
;
1387 len
+= sprintf(page
, "LU Group Alias: %s\nLU Group ID: %hu\n",
1388 config_item_name(lu_ci
), lu_gp
->lu_gp_id
);
1390 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1395 static ssize_t
target_core_store_alua_lu_gp(
1400 struct se_device
*dev
= p
;
1401 struct se_hba
*hba
= dev
->se_hba
;
1402 struct t10_alua_lu_gp
*lu_gp
= NULL
, *lu_gp_new
= NULL
;
1403 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1404 unsigned char buf
[LU_GROUP_NAME_BUF
];
1407 lu_gp_mem
= dev
->dev_alua_lu_gp_mem
;
1411 if (count
> LU_GROUP_NAME_BUF
) {
1412 pr_err("ALUA LU Group Alias too large!\n");
1415 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1416 memcpy(buf
, page
, count
);
1418 * Any ALUA logical unit alias besides "NULL" means we will be
1419 * making a new group association.
1421 if (strcmp(strstrip(buf
), "NULL")) {
1423 * core_alua_get_lu_gp_by_name() will increment reference to
1424 * struct t10_alua_lu_gp. This reference is released with
1425 * core_alua_get_lu_gp_by_name below().
1427 lu_gp_new
= core_alua_get_lu_gp_by_name(strstrip(buf
));
1432 spin_lock(&lu_gp_mem
->lu_gp_mem_lock
);
1433 lu_gp
= lu_gp_mem
->lu_gp
;
1436 * Clearing an existing lu_gp association, and replacing
1440 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
1441 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1443 config_item_name(&hba
->hba_group
.cg_item
),
1444 config_item_name(&dev
->dev_group
.cg_item
),
1445 config_item_name(&lu_gp
->lu_gp_group
.cg_item
),
1448 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1449 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1454 * Removing existing association of lu_gp_mem with lu_gp
1456 __core_alua_drop_lu_gp_mem(lu_gp_mem
, lu_gp
);
1460 * Associate lu_gp_mem with lu_gp_new.
1462 __core_alua_attach_lu_gp_mem(lu_gp_mem
, lu_gp_new
);
1463 spin_unlock(&lu_gp_mem
->lu_gp_mem_lock
);
1465 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1466 " core/alua/lu_gps/%s, ID: %hu\n",
1467 (move
) ? "Moving" : "Adding",
1468 config_item_name(&hba
->hba_group
.cg_item
),
1469 config_item_name(&dev
->dev_group
.cg_item
),
1470 config_item_name(&lu_gp_new
->lu_gp_group
.cg_item
),
1471 lu_gp_new
->lu_gp_id
);
1473 core_alua_put_lu_gp_from_name(lu_gp_new
);
1477 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp
= {
1478 .attr
= { .ca_owner
= THIS_MODULE
,
1479 .ca_name
= "alua_lu_gp",
1480 .ca_mode
= S_IRUGO
| S_IWUSR
},
1481 .show
= target_core_show_alua_lu_gp
,
1482 .store
= target_core_store_alua_lu_gp
,
1485 static ssize_t
target_core_show_dev_lba_map(void *p
, char *page
)
1487 struct se_device
*dev
= p
;
1488 struct t10_alua_lba_map
*map
;
1489 struct t10_alua_lba_map_member
*mem
;
1494 spin_lock(&dev
->t10_alua
.lba_map_lock
);
1495 if (!list_empty(&dev
->t10_alua
.lba_map_list
))
1496 bl
+= sprintf(b
+ bl
, "%u %u\n",
1497 dev
->t10_alua
.lba_map_segment_size
,
1498 dev
->t10_alua
.lba_map_segment_multiplier
);
1499 list_for_each_entry(map
, &dev
->t10_alua
.lba_map_list
, lba_map_list
) {
1500 bl
+= sprintf(b
+ bl
, "%llu %llu",
1501 map
->lba_map_first_lba
, map
->lba_map_last_lba
);
1502 list_for_each_entry(mem
, &map
->lba_map_mem_list
,
1504 switch (mem
->lba_map_mem_alua_state
) {
1505 case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
:
1508 case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
:
1511 case ALUA_ACCESS_STATE_STANDBY
:
1514 case ALUA_ACCESS_STATE_UNAVAILABLE
:
1521 bl
+= sprintf(b
+ bl
, " %d:%c",
1522 mem
->lba_map_mem_alua_pg_id
, state
);
1524 bl
+= sprintf(b
+ bl
, "\n");
1526 spin_unlock(&dev
->t10_alua
.lba_map_lock
);
1530 static ssize_t
target_core_store_dev_lba_map(
1535 struct se_device
*dev
= p
;
1536 struct t10_alua_lba_map
*lba_map
= NULL
;
1537 struct list_head lba_list
;
1538 char *map_entries
, *ptr
;
1540 int pg_num
= -1, pg
;
1541 int ret
= 0, num
= 0, pg_id
, alua_state
;
1542 unsigned long start_lba
= -1, end_lba
= -1;
1543 unsigned long segment_size
= -1, segment_mult
= -1;
1545 map_entries
= kstrdup(page
, GFP_KERNEL
);
1549 INIT_LIST_HEAD(&lba_list
);
1550 while ((ptr
= strsep(&map_entries
, "\n")) != NULL
) {
1555 if (sscanf(ptr
, "%lu %lu\n",
1556 &segment_size
, &segment_mult
) != 2) {
1557 pr_err("Invalid line %d\n", num
);
1564 if (sscanf(ptr
, "%lu %lu", &start_lba
, &end_lba
) != 2) {
1565 pr_err("Invalid line %d\n", num
);
1569 ptr
= strchr(ptr
, ' ');
1571 pr_err("Invalid line %d, missing end lba\n", num
);
1576 ptr
= strchr(ptr
, ' ');
1578 pr_err("Invalid line %d, missing state definitions\n",
1584 lba_map
= core_alua_allocate_lba_map(&lba_list
,
1585 start_lba
, end_lba
);
1586 if (IS_ERR(lba_map
)) {
1587 ret
= PTR_ERR(lba_map
);
1591 while (sscanf(ptr
, "%d:%c", &pg_id
, &state
) == 2) {
1594 alua_state
= ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED
;
1597 alua_state
= ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED
;
1600 alua_state
= ALUA_ACCESS_STATE_STANDBY
;
1603 alua_state
= ALUA_ACCESS_STATE_UNAVAILABLE
;
1606 pr_err("Invalid ALUA state '%c'\n", state
);
1611 ret
= core_alua_allocate_lba_map_mem(lba_map
,
1614 pr_err("Invalid target descriptor %d:%c "
1620 ptr
= strchr(ptr
, ' ');
1628 else if (pg
!= pg_num
) {
1629 pr_err("Only %d from %d port groups definitions "
1630 "at line %d\n", pg
, pg_num
, num
);
1638 core_alua_free_lba_map(&lba_list
);
1641 core_alua_set_lba_map(dev
, &lba_list
,
1642 segment_size
, segment_mult
);
1647 static struct target_core_configfs_attribute target_core_attr_dev_lba_map
= {
1648 .attr
= { .ca_owner
= THIS_MODULE
,
1649 .ca_name
= "lba_map",
1650 .ca_mode
= S_IRUGO
| S_IWUSR
},
1651 .show
= target_core_show_dev_lba_map
,
1652 .store
= target_core_store_dev_lba_map
,
1655 static struct configfs_attribute
*target_core_dev_attrs
[] = {
1656 &target_core_attr_dev_info
.attr
,
1657 &target_core_attr_dev_control
.attr
,
1658 &target_core_attr_dev_alias
.attr
,
1659 &target_core_attr_dev_udev_path
.attr
,
1660 &target_core_attr_dev_enable
.attr
,
1661 &target_core_attr_dev_alua_lu_gp
.attr
,
1662 &target_core_attr_dev_lba_map
.attr
,
1666 static void target_core_dev_release(struct config_item
*item
)
1668 struct config_group
*dev_cg
= to_config_group(item
);
1669 struct se_device
*dev
=
1670 container_of(dev_cg
, struct se_device
, dev_group
);
1672 kfree(dev_cg
->default_groups
);
1673 target_free_device(dev
);
1676 static ssize_t
target_core_dev_show(struct config_item
*item
,
1677 struct configfs_attribute
*attr
,
1680 struct config_group
*dev_cg
= to_config_group(item
);
1681 struct se_device
*dev
=
1682 container_of(dev_cg
, struct se_device
, dev_group
);
1683 struct target_core_configfs_attribute
*tc_attr
= container_of(
1684 attr
, struct target_core_configfs_attribute
, attr
);
1689 return tc_attr
->show(dev
, page
);
1692 static ssize_t
target_core_dev_store(struct config_item
*item
,
1693 struct configfs_attribute
*attr
,
1694 const char *page
, size_t count
)
1696 struct config_group
*dev_cg
= to_config_group(item
);
1697 struct se_device
*dev
=
1698 container_of(dev_cg
, struct se_device
, dev_group
);
1699 struct target_core_configfs_attribute
*tc_attr
= container_of(
1700 attr
, struct target_core_configfs_attribute
, attr
);
1702 if (!tc_attr
->store
)
1705 return tc_attr
->store(dev
, page
, count
);
1708 static struct configfs_item_operations target_core_dev_item_ops
= {
1709 .release
= target_core_dev_release
,
1710 .show_attribute
= target_core_dev_show
,
1711 .store_attribute
= target_core_dev_store
,
1714 TB_CIT_SETUP(dev
, &target_core_dev_item_ops
, NULL
, target_core_dev_attrs
);
1716 /* End functions for struct config_item_type tb_dev_cit */
1718 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
1720 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp
, t10_alua_lu_gp
);
1721 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
1722 static struct target_core_alua_lu_gp_attribute \
1723 target_core_alua_lu_gp_##_name = \
1724 __CONFIGFS_EATTR(_name, _mode, \
1725 target_core_alua_lu_gp_show_attr_##_name, \
1726 target_core_alua_lu_gp_store_attr_##_name);
1728 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
1729 static struct target_core_alua_lu_gp_attribute \
1730 target_core_alua_lu_gp_##_name = \
1731 __CONFIGFS_EATTR_RO(_name, \
1732 target_core_alua_lu_gp_show_attr_##_name);
1737 static ssize_t
target_core_alua_lu_gp_show_attr_lu_gp_id(
1738 struct t10_alua_lu_gp
*lu_gp
,
1741 if (!lu_gp
->lu_gp_valid_id
)
1744 return sprintf(page
, "%hu\n", lu_gp
->lu_gp_id
);
1747 static ssize_t
target_core_alua_lu_gp_store_attr_lu_gp_id(
1748 struct t10_alua_lu_gp
*lu_gp
,
1752 struct config_group
*alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
1753 unsigned long lu_gp_id
;
1756 ret
= kstrtoul(page
, 0, &lu_gp_id
);
1758 pr_err("kstrtoul() returned %d for"
1759 " lu_gp_id\n", ret
);
1762 if (lu_gp_id
> 0x0000ffff) {
1763 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
1764 " 0x0000ffff\n", lu_gp_id
);
1768 ret
= core_alua_set_lu_gp_id(lu_gp
, (u16
)lu_gp_id
);
1772 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
1773 " Group: core/alua/lu_gps/%s to ID: %hu\n",
1774 config_item_name(&alua_lu_gp_cg
->cg_item
),
1780 SE_DEV_ALUA_LU_ATTR(lu_gp_id
, S_IRUGO
| S_IWUSR
);
1785 static ssize_t
target_core_alua_lu_gp_show_attr_members(
1786 struct t10_alua_lu_gp
*lu_gp
,
1789 struct se_device
*dev
;
1791 struct t10_alua_lu_gp_member
*lu_gp_mem
;
1792 ssize_t len
= 0, cur_len
;
1793 unsigned char buf
[LU_GROUP_NAME_BUF
];
1795 memset(buf
, 0, LU_GROUP_NAME_BUF
);
1797 spin_lock(&lu_gp
->lu_gp_lock
);
1798 list_for_each_entry(lu_gp_mem
, &lu_gp
->lu_gp_mem_list
, lu_gp_mem_list
) {
1799 dev
= lu_gp_mem
->lu_gp_mem_dev
;
1802 cur_len
= snprintf(buf
, LU_GROUP_NAME_BUF
, "%s/%s\n",
1803 config_item_name(&hba
->hba_group
.cg_item
),
1804 config_item_name(&dev
->dev_group
.cg_item
));
1805 cur_len
++; /* Extra byte for NULL terminator */
1807 if ((cur_len
+ len
) > PAGE_SIZE
) {
1808 pr_warn("Ran out of lu_gp_show_attr"
1809 "_members buffer\n");
1812 memcpy(page
+len
, buf
, cur_len
);
1815 spin_unlock(&lu_gp
->lu_gp_lock
);
1820 SE_DEV_ALUA_LU_ATTR_RO(members
);
1822 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp
, t10_alua_lu_gp
, lu_gp_group
);
1824 static struct configfs_attribute
*target_core_alua_lu_gp_attrs
[] = {
1825 &target_core_alua_lu_gp_lu_gp_id
.attr
,
1826 &target_core_alua_lu_gp_members
.attr
,
1830 static void target_core_alua_lu_gp_release(struct config_item
*item
)
1832 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
1833 struct t10_alua_lu_gp
, lu_gp_group
);
1835 core_alua_free_lu_gp(lu_gp
);
1838 static struct configfs_item_operations target_core_alua_lu_gp_ops
= {
1839 .release
= target_core_alua_lu_gp_release
,
1840 .show_attribute
= target_core_alua_lu_gp_attr_show
,
1841 .store_attribute
= target_core_alua_lu_gp_attr_store
,
1844 static struct config_item_type target_core_alua_lu_gp_cit
= {
1845 .ct_item_ops
= &target_core_alua_lu_gp_ops
,
1846 .ct_attrs
= target_core_alua_lu_gp_attrs
,
1847 .ct_owner
= THIS_MODULE
,
1850 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
1852 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
1854 static struct config_group
*target_core_alua_create_lu_gp(
1855 struct config_group
*group
,
1858 struct t10_alua_lu_gp
*lu_gp
;
1859 struct config_group
*alua_lu_gp_cg
= NULL
;
1860 struct config_item
*alua_lu_gp_ci
= NULL
;
1862 lu_gp
= core_alua_allocate_lu_gp(name
, 0);
1866 alua_lu_gp_cg
= &lu_gp
->lu_gp_group
;
1867 alua_lu_gp_ci
= &alua_lu_gp_cg
->cg_item
;
1869 config_group_init_type_name(alua_lu_gp_cg
, name
,
1870 &target_core_alua_lu_gp_cit
);
1872 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
1873 " Group: core/alua/lu_gps/%s\n",
1874 config_item_name(alua_lu_gp_ci
));
1876 return alua_lu_gp_cg
;
1880 static void target_core_alua_drop_lu_gp(
1881 struct config_group
*group
,
1882 struct config_item
*item
)
1884 struct t10_alua_lu_gp
*lu_gp
= container_of(to_config_group(item
),
1885 struct t10_alua_lu_gp
, lu_gp_group
);
1887 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
1888 " Group: core/alua/lu_gps/%s, ID: %hu\n",
1889 config_item_name(item
), lu_gp
->lu_gp_id
);
1891 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
1892 * -> target_core_alua_lu_gp_release()
1894 config_item_put(item
);
1897 static struct configfs_group_operations target_core_alua_lu_gps_group_ops
= {
1898 .make_group
= &target_core_alua_create_lu_gp
,
1899 .drop_item
= &target_core_alua_drop_lu_gp
,
1902 static struct config_item_type target_core_alua_lu_gps_cit
= {
1903 .ct_item_ops
= NULL
,
1904 .ct_group_ops
= &target_core_alua_lu_gps_group_ops
,
1905 .ct_owner
= THIS_MODULE
,
1908 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
1910 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
1912 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
);
1913 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
1914 static struct target_core_alua_tg_pt_gp_attribute \
1915 target_core_alua_tg_pt_gp_##_name = \
1916 __CONFIGFS_EATTR(_name, _mode, \
1917 target_core_alua_tg_pt_gp_show_attr_##_name, \
1918 target_core_alua_tg_pt_gp_store_attr_##_name);
1920 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
1921 static struct target_core_alua_tg_pt_gp_attribute \
1922 target_core_alua_tg_pt_gp_##_name = \
1923 __CONFIGFS_EATTR_RO(_name, \
1924 target_core_alua_tg_pt_gp_show_attr_##_name);
1929 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_state(
1930 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1933 return sprintf(page
, "%d\n",
1934 atomic_read(&tg_pt_gp
->tg_pt_gp_alua_access_state
));
1937 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_state(
1938 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1942 struct se_device
*dev
= tg_pt_gp
->tg_pt_gp_dev
;
1946 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
1947 pr_err("Unable to do implicit ALUA on non valid"
1948 " tg_pt_gp ID: %hu\n", tg_pt_gp
->tg_pt_gp_valid_id
);
1951 if (!(dev
->dev_flags
& DF_CONFIGURED
)) {
1952 pr_err("Unable to set alua_access_state while device is"
1953 " not configured\n");
1957 ret
= kstrtoul(page
, 0, &tmp
);
1959 pr_err("Unable to extract new ALUA access state from"
1963 new_state
= (int)tmp
;
1965 if (!(tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_IMPLICIT_ALUA
)) {
1966 pr_err("Unable to process implicit configfs ALUA"
1967 " transition while TPGS_IMPLICIT_ALUA is disabled\n");
1970 if (tg_pt_gp
->tg_pt_gp_alua_access_type
& TPGS_EXPLICIT_ALUA
&&
1971 new_state
== ALUA_ACCESS_STATE_LBA_DEPENDENT
) {
1972 /* LBA DEPENDENT is only allowed with implicit ALUA */
1973 pr_err("Unable to process implicit configfs ALUA transition"
1974 " while explicit ALUA management is enabled\n");
1978 ret
= core_alua_do_port_transition(tg_pt_gp
, dev
,
1979 NULL
, NULL
, new_state
, 0);
1980 return (!ret
) ? count
: -EINVAL
;
1983 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state
, S_IRUGO
| S_IWUSR
);
1986 * alua_access_status
1988 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_status(
1989 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
1992 return sprintf(page
, "%s\n",
1993 core_alua_dump_status(tg_pt_gp
->tg_pt_gp_alua_access_status
));
1996 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_status(
1997 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2002 int new_status
, ret
;
2004 if (!tg_pt_gp
->tg_pt_gp_valid_id
) {
2005 pr_err("Unable to do set ALUA access status on non"
2006 " valid tg_pt_gp ID: %hu\n",
2007 tg_pt_gp
->tg_pt_gp_valid_id
);
2011 ret
= kstrtoul(page
, 0, &tmp
);
2013 pr_err("Unable to extract new ALUA access status"
2014 " from %s\n", page
);
2017 new_status
= (int)tmp
;
2019 if ((new_status
!= ALUA_STATUS_NONE
) &&
2020 (new_status
!= ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG
) &&
2021 (new_status
!= ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA
)) {
2022 pr_err("Illegal ALUA access status: 0x%02x\n",
2027 tg_pt_gp
->tg_pt_gp_alua_access_status
= new_status
;
2031 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status
, S_IRUGO
| S_IWUSR
);
2036 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2037 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2040 return core_alua_show_access_type(tg_pt_gp
, page
);
2043 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2044 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2048 return core_alua_store_access_type(tg_pt_gp
, page
, count
);
2051 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type
, S_IRUGO
| S_IWUSR
);
2054 * alua_supported_states
2057 #define SE_DEV_ALUA_SUPPORT_STATE_SHOW(_name, _var, _bit) \
2058 static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_support_##_name( \
2059 struct t10_alua_tg_pt_gp *t, char *p) \
2061 return sprintf(p, "%d\n", !!(t->_var & _bit)); \
2064 #define SE_DEV_ALUA_SUPPORT_STATE_STORE(_name, _var, _bit) \
2065 static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_support_##_name(\
2066 struct t10_alua_tg_pt_gp *t, const char *p, size_t c) \
2068 unsigned long tmp; \
2071 if (!t->tg_pt_gp_valid_id) { \
2072 pr_err("Unable to do set ##_name ALUA state on non" \
2073 " valid tg_pt_gp ID: %hu\n", \
2074 t->tg_pt_gp_valid_id); \
2078 ret = kstrtoul(p, 0, &tmp); \
2080 pr_err("Invalid value '%s', must be '0' or '1'\n", p); \
2084 pr_err("Invalid value '%ld', must be '0' or '1'\n", tmp); \
2095 SE_DEV_ALUA_SUPPORT_STATE_SHOW(transitioning
,
2096 tg_pt_gp_alua_supported_states
, ALUA_T_SUP
);
2097 SE_DEV_ALUA_SUPPORT_STATE_STORE(transitioning
,
2098 tg_pt_gp_alua_supported_states
, ALUA_T_SUP
);
2099 SE_DEV_ALUA_TG_PT_ATTR(alua_support_transitioning
, S_IRUGO
| S_IWUSR
);
2101 SE_DEV_ALUA_SUPPORT_STATE_SHOW(offline
,
2102 tg_pt_gp_alua_supported_states
, ALUA_O_SUP
);
2103 SE_DEV_ALUA_SUPPORT_STATE_STORE(offline
,
2104 tg_pt_gp_alua_supported_states
, ALUA_O_SUP
);
2105 SE_DEV_ALUA_TG_PT_ATTR(alua_support_offline
, S_IRUGO
| S_IWUSR
);
2107 SE_DEV_ALUA_SUPPORT_STATE_SHOW(lba_dependent
,
2108 tg_pt_gp_alua_supported_states
, ALUA_LBD_SUP
);
2109 SE_DEV_ALUA_SUPPORT_STATE_STORE(lba_dependent
,
2110 tg_pt_gp_alua_supported_states
, ALUA_LBD_SUP
);
2111 SE_DEV_ALUA_TG_PT_ATTR(alua_support_lba_dependent
, S_IRUGO
);
2113 SE_DEV_ALUA_SUPPORT_STATE_SHOW(unavailable
,
2114 tg_pt_gp_alua_supported_states
, ALUA_U_SUP
);
2115 SE_DEV_ALUA_SUPPORT_STATE_STORE(unavailable
,
2116 tg_pt_gp_alua_supported_states
, ALUA_U_SUP
);
2117 SE_DEV_ALUA_TG_PT_ATTR(alua_support_unavailable
, S_IRUGO
| S_IWUSR
);
2119 SE_DEV_ALUA_SUPPORT_STATE_SHOW(standby
,
2120 tg_pt_gp_alua_supported_states
, ALUA_S_SUP
);
2121 SE_DEV_ALUA_SUPPORT_STATE_STORE(standby
,
2122 tg_pt_gp_alua_supported_states
, ALUA_S_SUP
);
2123 SE_DEV_ALUA_TG_PT_ATTR(alua_support_standby
, S_IRUGO
| S_IWUSR
);
2125 SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_optimized
,
2126 tg_pt_gp_alua_supported_states
, ALUA_AO_SUP
);
2127 SE_DEV_ALUA_SUPPORT_STATE_STORE(active_optimized
,
2128 tg_pt_gp_alua_supported_states
, ALUA_AO_SUP
);
2129 SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_optimized
, S_IRUGO
| S_IWUSR
);
2131 SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_nonoptimized
,
2132 tg_pt_gp_alua_supported_states
, ALUA_AN_SUP
);
2133 SE_DEV_ALUA_SUPPORT_STATE_STORE(active_nonoptimized
,
2134 tg_pt_gp_alua_supported_states
, ALUA_AN_SUP
);
2135 SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_nonoptimized
, S_IRUGO
| S_IWUSR
);
2138 * alua_write_metadata
2140 static ssize_t
target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2141 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2144 return sprintf(page
, "%d\n", tg_pt_gp
->tg_pt_gp_write_metadata
);
2147 static ssize_t
target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2148 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2155 ret
= kstrtoul(page
, 0, &tmp
);
2157 pr_err("Unable to extract alua_write_metadata\n");
2161 if ((tmp
!= 0) && (tmp
!= 1)) {
2162 pr_err("Illegal value for alua_write_metadata:"
2166 tg_pt_gp
->tg_pt_gp_write_metadata
= (int)tmp
;
2171 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata
, S_IRUGO
| S_IWUSR
);
2178 static ssize_t
target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2179 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2182 return core_alua_show_nonop_delay_msecs(tg_pt_gp
, page
);
2186 static ssize_t
target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2187 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2191 return core_alua_store_nonop_delay_msecs(tg_pt_gp
, page
, count
);
2194 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs
, S_IRUGO
| S_IWUSR
);
2199 static ssize_t
target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2200 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2203 return core_alua_show_trans_delay_msecs(tg_pt_gp
, page
);
2206 static ssize_t
target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2207 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2211 return core_alua_store_trans_delay_msecs(tg_pt_gp
, page
, count
);
2214 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs
, S_IRUGO
| S_IWUSR
);
2217 * implicit_trans_secs
2219 static ssize_t
target_core_alua_tg_pt_gp_show_attr_implicit_trans_secs(
2220 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2223 return core_alua_show_implicit_trans_secs(tg_pt_gp
, page
);
2226 static ssize_t
target_core_alua_tg_pt_gp_store_attr_implicit_trans_secs(
2227 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2231 return core_alua_store_implicit_trans_secs(tg_pt_gp
, page
, count
);
2234 SE_DEV_ALUA_TG_PT_ATTR(implicit_trans_secs
, S_IRUGO
| S_IWUSR
);
2240 static ssize_t
target_core_alua_tg_pt_gp_show_attr_preferred(
2241 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2244 return core_alua_show_preferred_bit(tg_pt_gp
, page
);
2247 static ssize_t
target_core_alua_tg_pt_gp_store_attr_preferred(
2248 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2252 return core_alua_store_preferred_bit(tg_pt_gp
, page
, count
);
2255 SE_DEV_ALUA_TG_PT_ATTR(preferred
, S_IRUGO
| S_IWUSR
);
2260 static ssize_t
target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2261 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2264 if (!tg_pt_gp
->tg_pt_gp_valid_id
)
2267 return sprintf(page
, "%hu\n", tg_pt_gp
->tg_pt_gp_id
);
2270 static ssize_t
target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2271 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2275 struct config_group
*alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2276 unsigned long tg_pt_gp_id
;
2279 ret
= kstrtoul(page
, 0, &tg_pt_gp_id
);
2281 pr_err("kstrtoul() returned %d for"
2282 " tg_pt_gp_id\n", ret
);
2285 if (tg_pt_gp_id
> 0x0000ffff) {
2286 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:"
2287 " 0x0000ffff\n", tg_pt_gp_id
);
2291 ret
= core_alua_set_tg_pt_gp_id(tg_pt_gp
, (u16
)tg_pt_gp_id
);
2295 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
2296 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2297 config_item_name(&alua_tg_pt_gp_cg
->cg_item
),
2298 tg_pt_gp
->tg_pt_gp_id
);
2303 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id
, S_IRUGO
| S_IWUSR
);
2308 static ssize_t
target_core_alua_tg_pt_gp_show_attr_members(
2309 struct t10_alua_tg_pt_gp
*tg_pt_gp
,
2312 struct se_port
*port
;
2313 struct se_portal_group
*tpg
;
2315 struct t10_alua_tg_pt_gp_member
*tg_pt_gp_mem
;
2316 ssize_t len
= 0, cur_len
;
2317 unsigned char buf
[TG_PT_GROUP_NAME_BUF
];
2319 memset(buf
, 0, TG_PT_GROUP_NAME_BUF
);
2321 spin_lock(&tg_pt_gp
->tg_pt_gp_lock
);
2322 list_for_each_entry(tg_pt_gp_mem
, &tg_pt_gp
->tg_pt_gp_mem_list
,
2323 tg_pt_gp_mem_list
) {
2324 port
= tg_pt_gp_mem
->tg_pt
;
2325 tpg
= port
->sep_tpg
;
2326 lun
= port
->sep_lun
;
2328 cur_len
= snprintf(buf
, TG_PT_GROUP_NAME_BUF
, "%s/%s/tpgt_%hu"
2329 "/%s\n", tpg
->se_tpg_tfo
->get_fabric_name(),
2330 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
2331 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
),
2332 config_item_name(&lun
->lun_group
.cg_item
));
2333 cur_len
++; /* Extra byte for NULL terminator */
2335 if ((cur_len
+ len
) > PAGE_SIZE
) {
2336 pr_warn("Ran out of lu_gp_show_attr"
2337 "_members buffer\n");
2340 memcpy(page
+len
, buf
, cur_len
);
2343 spin_unlock(&tg_pt_gp
->tg_pt_gp_lock
);
2348 SE_DEV_ALUA_TG_PT_ATTR_RO(members
);
2350 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp
, t10_alua_tg_pt_gp
,
2353 static struct configfs_attribute
*target_core_alua_tg_pt_gp_attrs
[] = {
2354 &target_core_alua_tg_pt_gp_alua_access_state
.attr
,
2355 &target_core_alua_tg_pt_gp_alua_access_status
.attr
,
2356 &target_core_alua_tg_pt_gp_alua_access_type
.attr
,
2357 &target_core_alua_tg_pt_gp_alua_support_transitioning
.attr
,
2358 &target_core_alua_tg_pt_gp_alua_support_offline
.attr
,
2359 &target_core_alua_tg_pt_gp_alua_support_lba_dependent
.attr
,
2360 &target_core_alua_tg_pt_gp_alua_support_unavailable
.attr
,
2361 &target_core_alua_tg_pt_gp_alua_support_standby
.attr
,
2362 &target_core_alua_tg_pt_gp_alua_support_active_nonoptimized
.attr
,
2363 &target_core_alua_tg_pt_gp_alua_support_active_optimized
.attr
,
2364 &target_core_alua_tg_pt_gp_alua_write_metadata
.attr
,
2365 &target_core_alua_tg_pt_gp_nonop_delay_msecs
.attr
,
2366 &target_core_alua_tg_pt_gp_trans_delay_msecs
.attr
,
2367 &target_core_alua_tg_pt_gp_implicit_trans_secs
.attr
,
2368 &target_core_alua_tg_pt_gp_preferred
.attr
,
2369 &target_core_alua_tg_pt_gp_tg_pt_gp_id
.attr
,
2370 &target_core_alua_tg_pt_gp_members
.attr
,
2374 static void target_core_alua_tg_pt_gp_release(struct config_item
*item
)
2376 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2377 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2379 core_alua_free_tg_pt_gp(tg_pt_gp
);
2382 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops
= {
2383 .release
= target_core_alua_tg_pt_gp_release
,
2384 .show_attribute
= target_core_alua_tg_pt_gp_attr_show
,
2385 .store_attribute
= target_core_alua_tg_pt_gp_attr_store
,
2388 static struct config_item_type target_core_alua_tg_pt_gp_cit
= {
2389 .ct_item_ops
= &target_core_alua_tg_pt_gp_ops
,
2390 .ct_attrs
= target_core_alua_tg_pt_gp_attrs
,
2391 .ct_owner
= THIS_MODULE
,
2394 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2396 /* Start functions for struct config_item_type tb_alua_tg_pt_gps_cit */
2398 static struct config_group
*target_core_alua_create_tg_pt_gp(
2399 struct config_group
*group
,
2402 struct t10_alua
*alua
= container_of(group
, struct t10_alua
,
2403 alua_tg_pt_gps_group
);
2404 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2405 struct config_group
*alua_tg_pt_gp_cg
= NULL
;
2406 struct config_item
*alua_tg_pt_gp_ci
= NULL
;
2408 tg_pt_gp
= core_alua_allocate_tg_pt_gp(alua
->t10_dev
, name
, 0);
2412 alua_tg_pt_gp_cg
= &tg_pt_gp
->tg_pt_gp_group
;
2413 alua_tg_pt_gp_ci
= &alua_tg_pt_gp_cg
->cg_item
;
2415 config_group_init_type_name(alua_tg_pt_gp_cg
, name
,
2416 &target_core_alua_tg_pt_gp_cit
);
2418 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
2419 " Group: alua/tg_pt_gps/%s\n",
2420 config_item_name(alua_tg_pt_gp_ci
));
2422 return alua_tg_pt_gp_cg
;
2425 static void target_core_alua_drop_tg_pt_gp(
2426 struct config_group
*group
,
2427 struct config_item
*item
)
2429 struct t10_alua_tg_pt_gp
*tg_pt_gp
= container_of(to_config_group(item
),
2430 struct t10_alua_tg_pt_gp
, tg_pt_gp_group
);
2432 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
2433 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2434 config_item_name(item
), tg_pt_gp
->tg_pt_gp_id
);
2436 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2437 * -> target_core_alua_tg_pt_gp_release().
2439 config_item_put(item
);
2442 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops
= {
2443 .make_group
= &target_core_alua_create_tg_pt_gp
,
2444 .drop_item
= &target_core_alua_drop_tg_pt_gp
,
2447 TB_CIT_SETUP(dev_alua_tg_pt_gps
, NULL
, &target_core_alua_tg_pt_gps_group_ops
, NULL
);
2449 /* End functions for struct config_item_type tb_alua_tg_pt_gps_cit */
2451 /* Start functions for struct config_item_type target_core_alua_cit */
2454 * target_core_alua_cit is a ConfigFS group that lives under
2455 * /sys/kernel/config/target/core/alua. There are default groups
2456 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2457 * target_core_alua_cit in target_core_init_configfs() below.
2459 static struct config_item_type target_core_alua_cit
= {
2460 .ct_item_ops
= NULL
,
2462 .ct_owner
= THIS_MODULE
,
2465 /* End functions for struct config_item_type target_core_alua_cit */
2467 /* Start functions for struct config_item_type tb_dev_stat_cit */
2469 static struct config_group
*target_core_stat_mkdir(
2470 struct config_group
*group
,
2473 return ERR_PTR(-ENOSYS
);
2476 static void target_core_stat_rmdir(
2477 struct config_group
*group
,
2478 struct config_item
*item
)
2483 static struct configfs_group_operations target_core_stat_group_ops
= {
2484 .make_group
= &target_core_stat_mkdir
,
2485 .drop_item
= &target_core_stat_rmdir
,
2488 TB_CIT_SETUP(dev_stat
, NULL
, &target_core_stat_group_ops
, NULL
);
2490 /* End functions for struct config_item_type tb_dev_stat_cit */
2492 /* Start functions for struct config_item_type target_core_hba_cit */
2494 static struct config_group
*target_core_make_subdev(
2495 struct config_group
*group
,
2498 struct t10_alua_tg_pt_gp
*tg_pt_gp
;
2499 struct se_subsystem_api
*t
;
2500 struct config_item
*hba_ci
= &group
->cg_item
;
2501 struct se_hba
*hba
= item_to_hba(hba_ci
);
2502 struct se_device
*dev
;
2503 struct config_group
*dev_cg
= NULL
, *tg_pt_gp_cg
= NULL
;
2504 struct config_group
*dev_stat_grp
= NULL
;
2505 int errno
= -ENOMEM
, ret
;
2507 ret
= mutex_lock_interruptible(&hba
->hba_access_mutex
);
2509 return ERR_PTR(ret
);
2511 * Locate the struct se_subsystem_api from parent's struct se_hba.
2515 dev
= target_alloc_device(hba
, name
);
2519 dev_cg
= &dev
->dev_group
;
2521 dev_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 6,
2523 if (!dev_cg
->default_groups
)
2524 goto out_free_device
;
2526 config_group_init_type_name(dev_cg
, name
, &t
->tb_cits
.tb_dev_cit
);
2527 config_group_init_type_name(&dev
->dev_attrib
.da_group
, "attrib",
2528 &t
->tb_cits
.tb_dev_attrib_cit
);
2529 config_group_init_type_name(&dev
->dev_pr_group
, "pr",
2530 &t
->tb_cits
.tb_dev_pr_cit
);
2531 config_group_init_type_name(&dev
->t10_wwn
.t10_wwn_group
, "wwn",
2532 &t
->tb_cits
.tb_dev_wwn_cit
);
2533 config_group_init_type_name(&dev
->t10_alua
.alua_tg_pt_gps_group
,
2534 "alua", &t
->tb_cits
.tb_dev_alua_tg_pt_gps_cit
);
2535 config_group_init_type_name(&dev
->dev_stat_grps
.stat_group
,
2536 "statistics", &t
->tb_cits
.tb_dev_stat_cit
);
2538 dev_cg
->default_groups
[0] = &dev
->dev_attrib
.da_group
;
2539 dev_cg
->default_groups
[1] = &dev
->dev_pr_group
;
2540 dev_cg
->default_groups
[2] = &dev
->t10_wwn
.t10_wwn_group
;
2541 dev_cg
->default_groups
[3] = &dev
->t10_alua
.alua_tg_pt_gps_group
;
2542 dev_cg
->default_groups
[4] = &dev
->dev_stat_grps
.stat_group
;
2543 dev_cg
->default_groups
[5] = NULL
;
2545 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
2547 tg_pt_gp
= core_alua_allocate_tg_pt_gp(dev
, "default_tg_pt_gp", 1);
2549 goto out_free_dev_cg_default_groups
;
2550 dev
->t10_alua
.default_tg_pt_gp
= tg_pt_gp
;
2552 tg_pt_gp_cg
= &dev
->t10_alua
.alua_tg_pt_gps_group
;
2553 tg_pt_gp_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
2555 if (!tg_pt_gp_cg
->default_groups
) {
2556 pr_err("Unable to allocate tg_pt_gp_cg->"
2557 "default_groups\n");
2558 goto out_free_tg_pt_gp
;
2561 config_group_init_type_name(&tg_pt_gp
->tg_pt_gp_group
,
2562 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit
);
2563 tg_pt_gp_cg
->default_groups
[0] = &tg_pt_gp
->tg_pt_gp_group
;
2564 tg_pt_gp_cg
->default_groups
[1] = NULL
;
2566 * Add core/$HBA/$DEV/statistics/ default groups
2568 dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
2569 dev_stat_grp
->default_groups
= kmalloc(sizeof(struct config_group
*) * 4,
2571 if (!dev_stat_grp
->default_groups
) {
2572 pr_err("Unable to allocate dev_stat_grp->default_groups\n");
2573 goto out_free_tg_pt_gp_cg_default_groups
;
2575 target_stat_setup_dev_default_groups(dev
);
2577 mutex_unlock(&hba
->hba_access_mutex
);
2580 out_free_tg_pt_gp_cg_default_groups
:
2581 kfree(tg_pt_gp_cg
->default_groups
);
2583 core_alua_free_tg_pt_gp(tg_pt_gp
);
2584 out_free_dev_cg_default_groups
:
2585 kfree(dev_cg
->default_groups
);
2587 target_free_device(dev
);
2589 mutex_unlock(&hba
->hba_access_mutex
);
2590 return ERR_PTR(errno
);
2593 static void target_core_drop_subdev(
2594 struct config_group
*group
,
2595 struct config_item
*item
)
2597 struct config_group
*dev_cg
= to_config_group(item
);
2598 struct se_device
*dev
=
2599 container_of(dev_cg
, struct se_device
, dev_group
);
2601 struct config_item
*df_item
;
2602 struct config_group
*tg_pt_gp_cg
, *dev_stat_grp
;
2605 hba
= item_to_hba(&dev
->se_hba
->hba_group
.cg_item
);
2607 mutex_lock(&hba
->hba_access_mutex
);
2609 dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
2610 for (i
= 0; dev_stat_grp
->default_groups
[i
]; i
++) {
2611 df_item
= &dev_stat_grp
->default_groups
[i
]->cg_item
;
2612 dev_stat_grp
->default_groups
[i
] = NULL
;
2613 config_item_put(df_item
);
2615 kfree(dev_stat_grp
->default_groups
);
2617 tg_pt_gp_cg
= &dev
->t10_alua
.alua_tg_pt_gps_group
;
2618 for (i
= 0; tg_pt_gp_cg
->default_groups
[i
]; i
++) {
2619 df_item
= &tg_pt_gp_cg
->default_groups
[i
]->cg_item
;
2620 tg_pt_gp_cg
->default_groups
[i
] = NULL
;
2621 config_item_put(df_item
);
2623 kfree(tg_pt_gp_cg
->default_groups
);
2625 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2626 * directly from target_core_alua_tg_pt_gp_release().
2628 dev
->t10_alua
.default_tg_pt_gp
= NULL
;
2630 for (i
= 0; dev_cg
->default_groups
[i
]; i
++) {
2631 df_item
= &dev_cg
->default_groups
[i
]->cg_item
;
2632 dev_cg
->default_groups
[i
] = NULL
;
2633 config_item_put(df_item
);
2636 * se_dev is released from target_core_dev_item_ops->release()
2638 config_item_put(item
);
2639 mutex_unlock(&hba
->hba_access_mutex
);
2642 static struct configfs_group_operations target_core_hba_group_ops
= {
2643 .make_group
= target_core_make_subdev
,
2644 .drop_item
= target_core_drop_subdev
,
2647 CONFIGFS_EATTR_STRUCT(target_core_hba
, se_hba
);
2648 #define SE_HBA_ATTR(_name, _mode) \
2649 static struct target_core_hba_attribute \
2650 target_core_hba_##_name = \
2651 __CONFIGFS_EATTR(_name, _mode, \
2652 target_core_hba_show_attr_##_name, \
2653 target_core_hba_store_attr_##_name);
2655 #define SE_HBA_ATTR_RO(_name) \
2656 static struct target_core_hba_attribute \
2657 target_core_hba_##_name = \
2658 __CONFIGFS_EATTR_RO(_name, \
2659 target_core_hba_show_attr_##_name);
2661 static ssize_t
target_core_hba_show_attr_hba_info(
2665 return sprintf(page
, "HBA Index: %d plugin: %s version: %s\n",
2666 hba
->hba_id
, hba
->transport
->name
,
2667 TARGET_CORE_CONFIGFS_VERSION
);
2670 SE_HBA_ATTR_RO(hba_info
);
2672 static ssize_t
target_core_hba_show_attr_hba_mode(struct se_hba
*hba
,
2677 if (hba
->hba_flags
& HBA_FLAGS_PSCSI_MODE
)
2680 return sprintf(page
, "%d\n", hba_mode
);
2683 static ssize_t
target_core_hba_store_attr_hba_mode(struct se_hba
*hba
,
2684 const char *page
, size_t count
)
2686 struct se_subsystem_api
*transport
= hba
->transport
;
2687 unsigned long mode_flag
;
2690 if (transport
->pmode_enable_hba
== NULL
)
2693 ret
= kstrtoul(page
, 0, &mode_flag
);
2695 pr_err("Unable to extract hba mode flag: %d\n", ret
);
2699 if (hba
->dev_count
) {
2700 pr_err("Unable to set hba_mode with active devices\n");
2704 ret
= transport
->pmode_enable_hba(hba
, mode_flag
);
2708 hba
->hba_flags
|= HBA_FLAGS_PSCSI_MODE
;
2710 hba
->hba_flags
&= ~HBA_FLAGS_PSCSI_MODE
;
2715 SE_HBA_ATTR(hba_mode
, S_IRUGO
| S_IWUSR
);
2717 CONFIGFS_EATTR_OPS(target_core_hba
, se_hba
, hba_group
);
2719 static void target_core_hba_release(struct config_item
*item
)
2721 struct se_hba
*hba
= container_of(to_config_group(item
),
2722 struct se_hba
, hba_group
);
2723 core_delete_hba(hba
);
2726 static struct configfs_attribute
*target_core_hba_attrs
[] = {
2727 &target_core_hba_hba_info
.attr
,
2728 &target_core_hba_hba_mode
.attr
,
2732 static struct configfs_item_operations target_core_hba_item_ops
= {
2733 .release
= target_core_hba_release
,
2734 .show_attribute
= target_core_hba_attr_show
,
2735 .store_attribute
= target_core_hba_attr_store
,
2738 static struct config_item_type target_core_hba_cit
= {
2739 .ct_item_ops
= &target_core_hba_item_ops
,
2740 .ct_group_ops
= &target_core_hba_group_ops
,
2741 .ct_attrs
= target_core_hba_attrs
,
2742 .ct_owner
= THIS_MODULE
,
2745 static struct config_group
*target_core_call_addhbatotarget(
2746 struct config_group
*group
,
2749 char *se_plugin_str
, *str
, *str2
;
2751 char buf
[TARGET_CORE_NAME_MAX_LEN
];
2752 unsigned long plugin_dep_id
= 0;
2755 memset(buf
, 0, TARGET_CORE_NAME_MAX_LEN
);
2756 if (strlen(name
) >= TARGET_CORE_NAME_MAX_LEN
) {
2757 pr_err("Passed *name strlen(): %d exceeds"
2758 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name
),
2759 TARGET_CORE_NAME_MAX_LEN
);
2760 return ERR_PTR(-ENAMETOOLONG
);
2762 snprintf(buf
, TARGET_CORE_NAME_MAX_LEN
, "%s", name
);
2764 str
= strstr(buf
, "_");
2766 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
2767 return ERR_PTR(-EINVAL
);
2769 se_plugin_str
= buf
;
2771 * Special case for subsystem plugins that have "_" in their names.
2772 * Namely rd_direct and rd_mcp..
2774 str2
= strstr(str
+1, "_");
2776 *str2
= '\0'; /* Terminate for *se_plugin_str */
2777 str2
++; /* Skip to start of plugin dependent ID */
2780 *str
= '\0'; /* Terminate for *se_plugin_str */
2781 str
++; /* Skip to start of plugin dependent ID */
2784 ret
= kstrtoul(str
, 0, &plugin_dep_id
);
2786 pr_err("kstrtoul() returned %d for"
2787 " plugin_dep_id\n", ret
);
2788 return ERR_PTR(ret
);
2791 * Load up TCM subsystem plugins if they have not already been loaded.
2793 transport_subsystem_check_init();
2795 hba
= core_alloc_hba(se_plugin_str
, plugin_dep_id
, 0);
2797 return ERR_CAST(hba
);
2799 config_group_init_type_name(&hba
->hba_group
, name
,
2800 &target_core_hba_cit
);
2802 return &hba
->hba_group
;
2805 static void target_core_call_delhbafromtarget(
2806 struct config_group
*group
,
2807 struct config_item
*item
)
2810 * core_delete_hba() is called from target_core_hba_item_ops->release()
2811 * -> target_core_hba_release()
2813 config_item_put(item
);
2816 static struct configfs_group_operations target_core_group_ops
= {
2817 .make_group
= target_core_call_addhbatotarget
,
2818 .drop_item
= target_core_call_delhbafromtarget
,
2821 static struct config_item_type target_core_cit
= {
2822 .ct_item_ops
= NULL
,
2823 .ct_group_ops
= &target_core_group_ops
,
2825 .ct_owner
= THIS_MODULE
,
2828 /* Stop functions for struct config_item_type target_core_hba_cit */
2830 void target_core_setup_sub_cits(struct se_subsystem_api
*sa
)
2832 target_core_setup_dev_cit(sa
);
2833 target_core_setup_dev_attrib_cit(sa
);
2834 target_core_setup_dev_pr_cit(sa
);
2835 target_core_setup_dev_wwn_cit(sa
);
2836 target_core_setup_dev_alua_tg_pt_gps_cit(sa
);
2837 target_core_setup_dev_stat_cit(sa
);
2839 EXPORT_SYMBOL(target_core_setup_sub_cits
);
2841 static int __init
target_core_init_configfs(void)
2843 struct config_group
*target_cg
, *hba_cg
= NULL
, *alua_cg
= NULL
;
2844 struct config_group
*lu_gp_cg
= NULL
;
2845 struct configfs_subsystem
*subsys
= &target_core_fabrics
;
2846 struct t10_alua_lu_gp
*lu_gp
;
2849 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
2850 " Engine: %s on %s/%s on "UTS_RELEASE
"\n",
2851 TARGET_CORE_VERSION
, utsname()->sysname
, utsname()->machine
);
2853 config_group_init(&subsys
->su_group
);
2854 mutex_init(&subsys
->su_mutex
);
2856 ret
= init_se_kmem_caches();
2860 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
2861 * and ALUA Logical Unit Group and Target Port Group infrastructure.
2863 target_cg
= &subsys
->su_group
;
2864 target_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
2866 if (!target_cg
->default_groups
) {
2867 pr_err("Unable to allocate target_cg->default_groups\n");
2872 config_group_init_type_name(&target_core_hbagroup
,
2873 "core", &target_core_cit
);
2874 target_cg
->default_groups
[0] = &target_core_hbagroup
;
2875 target_cg
->default_groups
[1] = NULL
;
2877 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
2879 hba_cg
= &target_core_hbagroup
;
2880 hba_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
2882 if (!hba_cg
->default_groups
) {
2883 pr_err("Unable to allocate hba_cg->default_groups\n");
2887 config_group_init_type_name(&alua_group
,
2888 "alua", &target_core_alua_cit
);
2889 hba_cg
->default_groups
[0] = &alua_group
;
2890 hba_cg
->default_groups
[1] = NULL
;
2892 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
2893 * groups under /sys/kernel/config/target/core/alua/
2895 alua_cg
= &alua_group
;
2896 alua_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
2898 if (!alua_cg
->default_groups
) {
2899 pr_err("Unable to allocate alua_cg->default_groups\n");
2904 config_group_init_type_name(&alua_lu_gps_group
,
2905 "lu_gps", &target_core_alua_lu_gps_cit
);
2906 alua_cg
->default_groups
[0] = &alua_lu_gps_group
;
2907 alua_cg
->default_groups
[1] = NULL
;
2909 * Add core/alua/lu_gps/default_lu_gp
2911 lu_gp
= core_alua_allocate_lu_gp("default_lu_gp", 1);
2912 if (IS_ERR(lu_gp
)) {
2917 lu_gp_cg
= &alua_lu_gps_group
;
2918 lu_gp_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
2920 if (!lu_gp_cg
->default_groups
) {
2921 pr_err("Unable to allocate lu_gp_cg->default_groups\n");
2926 config_group_init_type_name(&lu_gp
->lu_gp_group
, "default_lu_gp",
2927 &target_core_alua_lu_gp_cit
);
2928 lu_gp_cg
->default_groups
[0] = &lu_gp
->lu_gp_group
;
2929 lu_gp_cg
->default_groups
[1] = NULL
;
2930 default_lu_gp
= lu_gp
;
2932 * Register the target_core_mod subsystem with configfs.
2934 ret
= configfs_register_subsystem(subsys
);
2936 pr_err("Error %d while registering subsystem %s\n",
2937 ret
, subsys
->su_group
.cg_item
.ci_namebuf
);
2940 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
2941 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION
" on %s/%s"
2942 " on "UTS_RELEASE
"\n", utsname()->sysname
, utsname()->machine
);
2944 * Register built-in RAMDISK subsystem logic for virtual LUN 0
2946 ret
= rd_module_init();
2950 ret
= core_dev_setup_virtual_lun0();
2954 ret
= target_xcopy_setup_pt();
2961 configfs_unregister_subsystem(subsys
);
2962 core_dev_release_virtual_lun0();
2965 if (default_lu_gp
) {
2966 core_alua_free_lu_gp(default_lu_gp
);
2967 default_lu_gp
= NULL
;
2970 kfree(lu_gp_cg
->default_groups
);
2972 kfree(alua_cg
->default_groups
);
2974 kfree(hba_cg
->default_groups
);
2975 kfree(target_cg
->default_groups
);
2976 release_se_kmem_caches();
2980 static void __exit
target_core_exit_configfs(void)
2982 struct config_group
*hba_cg
, *alua_cg
, *lu_gp_cg
;
2983 struct config_item
*item
;
2986 lu_gp_cg
= &alua_lu_gps_group
;
2987 for (i
= 0; lu_gp_cg
->default_groups
[i
]; i
++) {
2988 item
= &lu_gp_cg
->default_groups
[i
]->cg_item
;
2989 lu_gp_cg
->default_groups
[i
] = NULL
;
2990 config_item_put(item
);
2992 kfree(lu_gp_cg
->default_groups
);
2993 lu_gp_cg
->default_groups
= NULL
;
2995 alua_cg
= &alua_group
;
2996 for (i
= 0; alua_cg
->default_groups
[i
]; i
++) {
2997 item
= &alua_cg
->default_groups
[i
]->cg_item
;
2998 alua_cg
->default_groups
[i
] = NULL
;
2999 config_item_put(item
);
3001 kfree(alua_cg
->default_groups
);
3002 alua_cg
->default_groups
= NULL
;
3004 hba_cg
= &target_core_hbagroup
;
3005 for (i
= 0; hba_cg
->default_groups
[i
]; i
++) {
3006 item
= &hba_cg
->default_groups
[i
]->cg_item
;
3007 hba_cg
->default_groups
[i
] = NULL
;
3008 config_item_put(item
);
3010 kfree(hba_cg
->default_groups
);
3011 hba_cg
->default_groups
= NULL
;
3013 * We expect subsys->su_group.default_groups to be released
3014 * by configfs subsystem provider logic..
3016 configfs_unregister_subsystem(&target_core_fabrics
);
3017 kfree(target_core_fabrics
.su_group
.default_groups
);
3019 core_alua_free_lu_gp(default_lu_gp
);
3020 default_lu_gp
= NULL
;
3022 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
3023 " Infrastructure\n");
3025 core_dev_release_virtual_lun0();
3027 target_xcopy_release_pt();
3028 release_se_kmem_caches();
3031 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3032 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3033 MODULE_LICENSE("GPL");
3035 module_init(target_core_init_configfs
);
3036 module_exit(target_core_exit_configfs
);