ipv6: disable GSO on sockets hitting dst_allfrag
[linux-2.6/cjktty.git] / drivers / target / target_core_configfs.c
blobcbb66537d2301b028364c2dbb2fe3049cb9d88be
1 /*******************************************************************************
2 * Filename: target_core_configfs.c
4 * This file contains ConfigFS logic for the Generic Target Engine project.
6 * Copyright (c) 2008-2011 Rising Tide Systems
7 * Copyright (c) 2008-2011 Linux-iSCSI.org
9 * Nicholas A. Bellinger <nab@kernel.org>
11 * based on configfs Copyright (C) 2005 Oracle. All rights reserved.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 ****************************************************************************/
24 #include <linux/module.h>
25 #include <linux/moduleparam.h>
26 #include <generated/utsrelease.h>
27 #include <linux/utsname.h>
28 #include <linux/init.h>
29 #include <linux/fs.h>
30 #include <linux/namei.h>
31 #include <linux/slab.h>
32 #include <linux/types.h>
33 #include <linux/delay.h>
34 #include <linux/unistd.h>
35 #include <linux/string.h>
36 #include <linux/parser.h>
37 #include <linux/syscalls.h>
38 #include <linux/configfs.h>
39 #include <linux/spinlock.h>
41 #include <target/target_core_base.h>
42 #include <target/target_core_backend.h>
43 #include <target/target_core_fabric.h>
44 #include <target/target_core_fabric_configfs.h>
45 #include <target/target_core_configfs.h>
46 #include <target/configfs_macros.h>
48 #include "target_core_internal.h"
49 #include "target_core_alua.h"
50 #include "target_core_pr.h"
51 #include "target_core_rd.h"
53 extern struct t10_alua_lu_gp *default_lu_gp;
55 static LIST_HEAD(g_tf_list);
56 static DEFINE_MUTEX(g_tf_lock);
58 struct target_core_configfs_attribute {
59 struct configfs_attribute attr;
60 ssize_t (*show)(void *, char *);
61 ssize_t (*store)(void *, const char *, size_t);
64 static struct config_group target_core_hbagroup;
65 static struct config_group alua_group;
66 static struct config_group alua_lu_gps_group;
68 static inline struct se_hba *
69 item_to_hba(struct config_item *item)
71 return container_of(to_config_group(item), struct se_hba, hba_group);
75 * Attributes for /sys/kernel/config/target/
77 static ssize_t target_core_attr_show(struct config_item *item,
78 struct configfs_attribute *attr,
79 char *page)
81 return sprintf(page, "Target Engine Core ConfigFS Infrastructure %s"
82 " on %s/%s on "UTS_RELEASE"\n", TARGET_CORE_CONFIGFS_VERSION,
83 utsname()->sysname, utsname()->machine);
86 static struct configfs_item_operations target_core_fabric_item_ops = {
87 .show_attribute = target_core_attr_show,
90 static struct configfs_attribute target_core_item_attr_version = {
91 .ca_owner = THIS_MODULE,
92 .ca_name = "version",
93 .ca_mode = S_IRUGO,
96 static struct target_fabric_configfs *target_core_get_fabric(
97 const char *name)
99 struct target_fabric_configfs *tf;
101 if (!name)
102 return NULL;
104 mutex_lock(&g_tf_lock);
105 list_for_each_entry(tf, &g_tf_list, tf_list) {
106 if (!strcmp(tf->tf_name, name)) {
107 atomic_inc(&tf->tf_access_cnt);
108 mutex_unlock(&g_tf_lock);
109 return tf;
112 mutex_unlock(&g_tf_lock);
114 return NULL;
118 * Called from struct target_core_group_ops->make_group()
120 static struct config_group *target_core_register_fabric(
121 struct config_group *group,
122 const char *name)
124 struct target_fabric_configfs *tf;
125 int ret;
127 pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:"
128 " %s\n", group, name);
130 * Below are some hardcoded request_module() calls to automatically
131 * local fabric modules when the following is called:
133 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
135 * Note that this does not limit which TCM fabric module can be
136 * registered, but simply provids auto loading logic for modules with
137 * mkdir(2) system calls with known TCM fabric modules.
139 if (!strncmp(name, "iscsi", 5)) {
141 * Automatically load the LIO Target fabric module when the
142 * following is called:
144 * mkdir -p $CONFIGFS/target/iscsi
146 ret = request_module("iscsi_target_mod");
147 if (ret < 0) {
148 pr_err("request_module() failed for"
149 " iscsi_target_mod.ko: %d\n", ret);
150 return ERR_PTR(-EINVAL);
152 } else if (!strncmp(name, "loopback", 8)) {
154 * Automatically load the tcm_loop fabric module when the
155 * following is called:
157 * mkdir -p $CONFIGFS/target/loopback
159 ret = request_module("tcm_loop");
160 if (ret < 0) {
161 pr_err("request_module() failed for"
162 " tcm_loop.ko: %d\n", ret);
163 return ERR_PTR(-EINVAL);
167 tf = target_core_get_fabric(name);
168 if (!tf) {
169 pr_err("target_core_get_fabric() failed for %s\n",
170 name);
171 return ERR_PTR(-EINVAL);
173 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
174 " %s\n", tf->tf_name);
176 * On a successful target_core_get_fabric() look, the returned
177 * struct target_fabric_configfs *tf will contain a usage reference.
179 pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
180 &TF_CIT_TMPL(tf)->tfc_wwn_cit);
182 tf->tf_group.default_groups = tf->tf_default_groups;
183 tf->tf_group.default_groups[0] = &tf->tf_disc_group;
184 tf->tf_group.default_groups[1] = NULL;
186 config_group_init_type_name(&tf->tf_group, name,
187 &TF_CIT_TMPL(tf)->tfc_wwn_cit);
188 config_group_init_type_name(&tf->tf_disc_group, "discovery_auth",
189 &TF_CIT_TMPL(tf)->tfc_discovery_cit);
191 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
192 " %s\n", tf->tf_group.cg_item.ci_name);
194 * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item()
196 tf->tf_ops.tf_subsys = tf->tf_subsys;
197 tf->tf_fabric = &tf->tf_group.cg_item;
198 pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
199 " for %s\n", name);
201 return &tf->tf_group;
205 * Called from struct target_core_group_ops->drop_item()
207 static void target_core_deregister_fabric(
208 struct config_group *group,
209 struct config_item *item)
211 struct target_fabric_configfs *tf = container_of(
212 to_config_group(item), struct target_fabric_configfs, tf_group);
213 struct config_group *tf_group;
214 struct config_item *df_item;
215 int i;
217 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
218 " tf list\n", config_item_name(item));
220 pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:"
221 " %s\n", tf->tf_name);
222 atomic_dec(&tf->tf_access_cnt);
224 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing"
225 " tf->tf_fabric for %s\n", tf->tf_name);
226 tf->tf_fabric = NULL;
228 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
229 " %s\n", config_item_name(item));
231 tf_group = &tf->tf_group;
232 for (i = 0; tf_group->default_groups[i]; i++) {
233 df_item = &tf_group->default_groups[i]->cg_item;
234 tf_group->default_groups[i] = NULL;
235 config_item_put(df_item);
237 config_item_put(item);
240 static struct configfs_group_operations target_core_fabric_group_ops = {
241 .make_group = &target_core_register_fabric,
242 .drop_item = &target_core_deregister_fabric,
246 * All item attributes appearing in /sys/kernel/target/ appear here.
248 static struct configfs_attribute *target_core_fabric_item_attrs[] = {
249 &target_core_item_attr_version,
250 NULL,
254 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
256 static struct config_item_type target_core_fabrics_item = {
257 .ct_item_ops = &target_core_fabric_item_ops,
258 .ct_group_ops = &target_core_fabric_group_ops,
259 .ct_attrs = target_core_fabric_item_attrs,
260 .ct_owner = THIS_MODULE,
263 static struct configfs_subsystem target_core_fabrics = {
264 .su_group = {
265 .cg_item = {
266 .ci_namebuf = "target",
267 .ci_type = &target_core_fabrics_item,
272 static struct configfs_subsystem *target_core_subsystem[] = {
273 &target_core_fabrics,
274 NULL,
277 /*##############################################################################
278 // Start functions called by external Target Fabrics Modules
279 //############################################################################*/
282 * First function called by fabric modules to:
284 * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer.
285 * 2) Add struct target_fabric_configfs to g_tf_list
286 * 3) Return struct target_fabric_configfs to fabric module to be passed
287 * into target_fabric_configfs_register().
289 struct target_fabric_configfs *target_fabric_configfs_init(
290 struct module *fabric_mod,
291 const char *name)
293 struct target_fabric_configfs *tf;
295 if (!(name)) {
296 pr_err("Unable to locate passed fabric name\n");
297 return ERR_PTR(-EINVAL);
299 if (strlen(name) >= TARGET_FABRIC_NAME_SIZE) {
300 pr_err("Passed name: %s exceeds TARGET_FABRIC"
301 "_NAME_SIZE\n", name);
302 return ERR_PTR(-EINVAL);
305 tf = kzalloc(sizeof(struct target_fabric_configfs), GFP_KERNEL);
306 if (!tf)
307 return ERR_PTR(-ENOMEM);
309 INIT_LIST_HEAD(&tf->tf_list);
310 atomic_set(&tf->tf_access_cnt, 0);
312 * Setup the default generic struct config_item_type's (cits) in
313 * struct target_fabric_configfs->tf_cit_tmpl
315 tf->tf_module = fabric_mod;
316 target_fabric_setup_cits(tf);
318 tf->tf_subsys = target_core_subsystem[0];
319 snprintf(tf->tf_name, TARGET_FABRIC_NAME_SIZE, "%s", name);
321 mutex_lock(&g_tf_lock);
322 list_add_tail(&tf->tf_list, &g_tf_list);
323 mutex_unlock(&g_tf_lock);
325 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>"
326 ">>>>>>>>>>>>>>\n");
327 pr_debug("Initialized struct target_fabric_configfs: %p for"
328 " %s\n", tf, tf->tf_name);
329 return tf;
331 EXPORT_SYMBOL(target_fabric_configfs_init);
334 * Called by fabric plugins after FAILED target_fabric_configfs_register() call.
336 void target_fabric_configfs_free(
337 struct target_fabric_configfs *tf)
339 mutex_lock(&g_tf_lock);
340 list_del(&tf->tf_list);
341 mutex_unlock(&g_tf_lock);
343 kfree(tf);
345 EXPORT_SYMBOL(target_fabric_configfs_free);
348 * Perform a sanity check of the passed tf->tf_ops before completing
349 * TCM fabric module registration.
351 static int target_fabric_tf_ops_check(
352 struct target_fabric_configfs *tf)
354 struct target_core_fabric_ops *tfo = &tf->tf_ops;
356 if (!tfo->get_fabric_name) {
357 pr_err("Missing tfo->get_fabric_name()\n");
358 return -EINVAL;
360 if (!tfo->get_fabric_proto_ident) {
361 pr_err("Missing tfo->get_fabric_proto_ident()\n");
362 return -EINVAL;
364 if (!tfo->tpg_get_wwn) {
365 pr_err("Missing tfo->tpg_get_wwn()\n");
366 return -EINVAL;
368 if (!tfo->tpg_get_tag) {
369 pr_err("Missing tfo->tpg_get_tag()\n");
370 return -EINVAL;
372 if (!tfo->tpg_get_default_depth) {
373 pr_err("Missing tfo->tpg_get_default_depth()\n");
374 return -EINVAL;
376 if (!tfo->tpg_get_pr_transport_id) {
377 pr_err("Missing tfo->tpg_get_pr_transport_id()\n");
378 return -EINVAL;
380 if (!tfo->tpg_get_pr_transport_id_len) {
381 pr_err("Missing tfo->tpg_get_pr_transport_id_len()\n");
382 return -EINVAL;
384 if (!tfo->tpg_check_demo_mode) {
385 pr_err("Missing tfo->tpg_check_demo_mode()\n");
386 return -EINVAL;
388 if (!tfo->tpg_check_demo_mode_cache) {
389 pr_err("Missing tfo->tpg_check_demo_mode_cache()\n");
390 return -EINVAL;
392 if (!tfo->tpg_check_demo_mode_write_protect) {
393 pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n");
394 return -EINVAL;
396 if (!tfo->tpg_check_prod_mode_write_protect) {
397 pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n");
398 return -EINVAL;
400 if (!tfo->tpg_alloc_fabric_acl) {
401 pr_err("Missing tfo->tpg_alloc_fabric_acl()\n");
402 return -EINVAL;
404 if (!tfo->tpg_release_fabric_acl) {
405 pr_err("Missing tfo->tpg_release_fabric_acl()\n");
406 return -EINVAL;
408 if (!tfo->tpg_get_inst_index) {
409 pr_err("Missing tfo->tpg_get_inst_index()\n");
410 return -EINVAL;
412 if (!tfo->release_cmd) {
413 pr_err("Missing tfo->release_cmd()\n");
414 return -EINVAL;
416 if (!tfo->shutdown_session) {
417 pr_err("Missing tfo->shutdown_session()\n");
418 return -EINVAL;
420 if (!tfo->close_session) {
421 pr_err("Missing tfo->close_session()\n");
422 return -EINVAL;
424 if (!tfo->sess_get_index) {
425 pr_err("Missing tfo->sess_get_index()\n");
426 return -EINVAL;
428 if (!tfo->write_pending) {
429 pr_err("Missing tfo->write_pending()\n");
430 return -EINVAL;
432 if (!tfo->write_pending_status) {
433 pr_err("Missing tfo->write_pending_status()\n");
434 return -EINVAL;
436 if (!tfo->set_default_node_attributes) {
437 pr_err("Missing tfo->set_default_node_attributes()\n");
438 return -EINVAL;
440 if (!tfo->get_task_tag) {
441 pr_err("Missing tfo->get_task_tag()\n");
442 return -EINVAL;
444 if (!tfo->get_cmd_state) {
445 pr_err("Missing tfo->get_cmd_state()\n");
446 return -EINVAL;
448 if (!tfo->queue_data_in) {
449 pr_err("Missing tfo->queue_data_in()\n");
450 return -EINVAL;
452 if (!tfo->queue_status) {
453 pr_err("Missing tfo->queue_status()\n");
454 return -EINVAL;
456 if (!tfo->queue_tm_rsp) {
457 pr_err("Missing tfo->queue_tm_rsp()\n");
458 return -EINVAL;
460 if (!tfo->set_fabric_sense_len) {
461 pr_err("Missing tfo->set_fabric_sense_len()\n");
462 return -EINVAL;
464 if (!tfo->get_fabric_sense_len) {
465 pr_err("Missing tfo->get_fabric_sense_len()\n");
466 return -EINVAL;
469 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
470 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
471 * target_core_fabric_configfs.c WWN+TPG group context code.
473 if (!tfo->fabric_make_wwn) {
474 pr_err("Missing tfo->fabric_make_wwn()\n");
475 return -EINVAL;
477 if (!tfo->fabric_drop_wwn) {
478 pr_err("Missing tfo->fabric_drop_wwn()\n");
479 return -EINVAL;
481 if (!tfo->fabric_make_tpg) {
482 pr_err("Missing tfo->fabric_make_tpg()\n");
483 return -EINVAL;
485 if (!tfo->fabric_drop_tpg) {
486 pr_err("Missing tfo->fabric_drop_tpg()\n");
487 return -EINVAL;
490 return 0;
494 * Called 2nd from fabric module with returned parameter of
495 * struct target_fabric_configfs * from target_fabric_configfs_init().
497 * Upon a successful registration, the new fabric's struct config_item is
498 * return. Also, a pointer to this struct is set in the passed
499 * struct target_fabric_configfs.
501 int target_fabric_configfs_register(
502 struct target_fabric_configfs *tf)
504 int ret;
506 if (!tf) {
507 pr_err("Unable to locate target_fabric_configfs"
508 " pointer\n");
509 return -EINVAL;
511 if (!tf->tf_subsys) {
512 pr_err("Unable to target struct config_subsystem"
513 " pointer\n");
514 return -EINVAL;
516 ret = target_fabric_tf_ops_check(tf);
517 if (ret < 0)
518 return ret;
520 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>"
521 ">>>>>>>>>>\n");
522 return 0;
524 EXPORT_SYMBOL(target_fabric_configfs_register);
526 void target_fabric_configfs_deregister(
527 struct target_fabric_configfs *tf)
529 struct configfs_subsystem *su;
531 if (!tf) {
532 pr_err("Unable to locate passed target_fabric_"
533 "configfs\n");
534 return;
536 su = tf->tf_subsys;
537 if (!su) {
538 pr_err("Unable to locate passed tf->tf_subsys"
539 " pointer\n");
540 return;
542 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
543 ">>>>>>>>>>>>\n");
544 mutex_lock(&g_tf_lock);
545 if (atomic_read(&tf->tf_access_cnt)) {
546 mutex_unlock(&g_tf_lock);
547 pr_err("Non zero tf->tf_access_cnt for fabric %s\n",
548 tf->tf_name);
549 BUG();
551 list_del(&tf->tf_list);
552 mutex_unlock(&g_tf_lock);
554 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
555 " %s\n", tf->tf_name);
556 tf->tf_module = NULL;
557 tf->tf_subsys = NULL;
558 kfree(tf);
560 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
561 ">>>>>\n");
563 EXPORT_SYMBOL(target_fabric_configfs_deregister);
565 /*##############################################################################
566 // Stop functions called by external Target Fabrics Modules
567 //############################################################################*/
569 /* Start functions for struct config_item_type target_core_dev_attrib_cit */
571 #define DEF_DEV_ATTRIB_SHOW(_name) \
572 static ssize_t target_core_dev_show_attr_##_name( \
573 struct se_dev_attrib *da, \
574 char *page) \
576 struct se_device *dev; \
577 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
578 ssize_t rb; \
580 spin_lock(&se_dev->se_dev_lock); \
581 dev = se_dev->se_dev_ptr; \
582 if (!dev) { \
583 spin_unlock(&se_dev->se_dev_lock); \
584 return -ENODEV; \
586 rb = snprintf(page, PAGE_SIZE, "%u\n", \
587 (u32)dev->se_sub_dev->se_dev_attrib._name); \
588 spin_unlock(&se_dev->se_dev_lock); \
590 return rb; \
593 #define DEF_DEV_ATTRIB_STORE(_name) \
594 static ssize_t target_core_dev_store_attr_##_name( \
595 struct se_dev_attrib *da, \
596 const char *page, \
597 size_t count) \
599 struct se_device *dev; \
600 struct se_subsystem_dev *se_dev = da->da_sub_dev; \
601 unsigned long val; \
602 int ret; \
604 spin_lock(&se_dev->se_dev_lock); \
605 dev = se_dev->se_dev_ptr; \
606 if (!dev) { \
607 spin_unlock(&se_dev->se_dev_lock); \
608 return -ENODEV; \
610 ret = strict_strtoul(page, 0, &val); \
611 if (ret < 0) { \
612 spin_unlock(&se_dev->se_dev_lock); \
613 pr_err("strict_strtoul() failed with" \
614 " ret: %d\n", ret); \
615 return -EINVAL; \
617 ret = se_dev_set_##_name(dev, (u32)val); \
618 spin_unlock(&se_dev->se_dev_lock); \
620 return (!ret) ? count : -EINVAL; \
623 #define DEF_DEV_ATTRIB(_name) \
624 DEF_DEV_ATTRIB_SHOW(_name); \
625 DEF_DEV_ATTRIB_STORE(_name);
627 #define DEF_DEV_ATTRIB_RO(_name) \
628 DEF_DEV_ATTRIB_SHOW(_name);
630 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib, se_dev_attrib);
631 #define SE_DEV_ATTR(_name, _mode) \
632 static struct target_core_dev_attrib_attribute \
633 target_core_dev_attrib_##_name = \
634 __CONFIGFS_EATTR(_name, _mode, \
635 target_core_dev_show_attr_##_name, \
636 target_core_dev_store_attr_##_name);
638 #define SE_DEV_ATTR_RO(_name); \
639 static struct target_core_dev_attrib_attribute \
640 target_core_dev_attrib_##_name = \
641 __CONFIGFS_EATTR_RO(_name, \
642 target_core_dev_show_attr_##_name);
644 DEF_DEV_ATTRIB(emulate_dpo);
645 SE_DEV_ATTR(emulate_dpo, S_IRUGO | S_IWUSR);
647 DEF_DEV_ATTRIB(emulate_fua_write);
648 SE_DEV_ATTR(emulate_fua_write, S_IRUGO | S_IWUSR);
650 DEF_DEV_ATTRIB(emulate_fua_read);
651 SE_DEV_ATTR(emulate_fua_read, S_IRUGO | S_IWUSR);
653 DEF_DEV_ATTRIB(emulate_write_cache);
654 SE_DEV_ATTR(emulate_write_cache, S_IRUGO | S_IWUSR);
656 DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl);
657 SE_DEV_ATTR(emulate_ua_intlck_ctrl, S_IRUGO | S_IWUSR);
659 DEF_DEV_ATTRIB(emulate_tas);
660 SE_DEV_ATTR(emulate_tas, S_IRUGO | S_IWUSR);
662 DEF_DEV_ATTRIB(emulate_tpu);
663 SE_DEV_ATTR(emulate_tpu, S_IRUGO | S_IWUSR);
665 DEF_DEV_ATTRIB(emulate_tpws);
666 SE_DEV_ATTR(emulate_tpws, S_IRUGO | S_IWUSR);
668 DEF_DEV_ATTRIB(enforce_pr_isids);
669 SE_DEV_ATTR(enforce_pr_isids, S_IRUGO | S_IWUSR);
671 DEF_DEV_ATTRIB(is_nonrot);
672 SE_DEV_ATTR(is_nonrot, S_IRUGO | S_IWUSR);
674 DEF_DEV_ATTRIB(emulate_rest_reord);
675 SE_DEV_ATTR(emulate_rest_reord, S_IRUGO | S_IWUSR);
677 DEF_DEV_ATTRIB_RO(hw_block_size);
678 SE_DEV_ATTR_RO(hw_block_size);
680 DEF_DEV_ATTRIB(block_size);
681 SE_DEV_ATTR(block_size, S_IRUGO | S_IWUSR);
683 DEF_DEV_ATTRIB_RO(hw_max_sectors);
684 SE_DEV_ATTR_RO(hw_max_sectors);
686 DEF_DEV_ATTRIB(max_sectors);
687 SE_DEV_ATTR(max_sectors, S_IRUGO | S_IWUSR);
689 DEF_DEV_ATTRIB(fabric_max_sectors);
690 SE_DEV_ATTR(fabric_max_sectors, S_IRUGO | S_IWUSR);
692 DEF_DEV_ATTRIB(optimal_sectors);
693 SE_DEV_ATTR(optimal_sectors, S_IRUGO | S_IWUSR);
695 DEF_DEV_ATTRIB_RO(hw_queue_depth);
696 SE_DEV_ATTR_RO(hw_queue_depth);
698 DEF_DEV_ATTRIB(queue_depth);
699 SE_DEV_ATTR(queue_depth, S_IRUGO | S_IWUSR);
701 DEF_DEV_ATTRIB(max_unmap_lba_count);
702 SE_DEV_ATTR(max_unmap_lba_count, S_IRUGO | S_IWUSR);
704 DEF_DEV_ATTRIB(max_unmap_block_desc_count);
705 SE_DEV_ATTR(max_unmap_block_desc_count, S_IRUGO | S_IWUSR);
707 DEF_DEV_ATTRIB(unmap_granularity);
708 SE_DEV_ATTR(unmap_granularity, S_IRUGO | S_IWUSR);
710 DEF_DEV_ATTRIB(unmap_granularity_alignment);
711 SE_DEV_ATTR(unmap_granularity_alignment, S_IRUGO | S_IWUSR);
713 CONFIGFS_EATTR_OPS(target_core_dev_attrib, se_dev_attrib, da_group);
715 static struct configfs_attribute *target_core_dev_attrib_attrs[] = {
716 &target_core_dev_attrib_emulate_dpo.attr,
717 &target_core_dev_attrib_emulate_fua_write.attr,
718 &target_core_dev_attrib_emulate_fua_read.attr,
719 &target_core_dev_attrib_emulate_write_cache.attr,
720 &target_core_dev_attrib_emulate_ua_intlck_ctrl.attr,
721 &target_core_dev_attrib_emulate_tas.attr,
722 &target_core_dev_attrib_emulate_tpu.attr,
723 &target_core_dev_attrib_emulate_tpws.attr,
724 &target_core_dev_attrib_enforce_pr_isids.attr,
725 &target_core_dev_attrib_is_nonrot.attr,
726 &target_core_dev_attrib_emulate_rest_reord.attr,
727 &target_core_dev_attrib_hw_block_size.attr,
728 &target_core_dev_attrib_block_size.attr,
729 &target_core_dev_attrib_hw_max_sectors.attr,
730 &target_core_dev_attrib_max_sectors.attr,
731 &target_core_dev_attrib_fabric_max_sectors.attr,
732 &target_core_dev_attrib_optimal_sectors.attr,
733 &target_core_dev_attrib_hw_queue_depth.attr,
734 &target_core_dev_attrib_queue_depth.attr,
735 &target_core_dev_attrib_max_unmap_lba_count.attr,
736 &target_core_dev_attrib_max_unmap_block_desc_count.attr,
737 &target_core_dev_attrib_unmap_granularity.attr,
738 &target_core_dev_attrib_unmap_granularity_alignment.attr,
739 NULL,
742 static struct configfs_item_operations target_core_dev_attrib_ops = {
743 .show_attribute = target_core_dev_attrib_attr_show,
744 .store_attribute = target_core_dev_attrib_attr_store,
747 static struct config_item_type target_core_dev_attrib_cit = {
748 .ct_item_ops = &target_core_dev_attrib_ops,
749 .ct_attrs = target_core_dev_attrib_attrs,
750 .ct_owner = THIS_MODULE,
753 /* End functions for struct config_item_type target_core_dev_attrib_cit */
755 /* Start functions for struct config_item_type target_core_dev_wwn_cit */
757 CONFIGFS_EATTR_STRUCT(target_core_dev_wwn, t10_wwn);
758 #define SE_DEV_WWN_ATTR(_name, _mode) \
759 static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
760 __CONFIGFS_EATTR(_name, _mode, \
761 target_core_dev_wwn_show_attr_##_name, \
762 target_core_dev_wwn_store_attr_##_name);
764 #define SE_DEV_WWN_ATTR_RO(_name); \
765 do { \
766 static struct target_core_dev_wwn_attribute \
767 target_core_dev_wwn_##_name = \
768 __CONFIGFS_EATTR_RO(_name, \
769 target_core_dev_wwn_show_attr_##_name); \
770 } while (0);
773 * VPD page 0x80 Unit serial
775 static ssize_t target_core_dev_wwn_show_attr_vpd_unit_serial(
776 struct t10_wwn *t10_wwn,
777 char *page)
779 struct se_subsystem_dev *se_dev = t10_wwn->t10_sub_dev;
780 struct se_device *dev;
782 dev = se_dev->se_dev_ptr;
783 if (!dev)
784 return -ENODEV;
786 return sprintf(page, "T10 VPD Unit Serial Number: %s\n",
787 &t10_wwn->unit_serial[0]);
790 static ssize_t target_core_dev_wwn_store_attr_vpd_unit_serial(
791 struct t10_wwn *t10_wwn,
792 const char *page,
793 size_t count)
795 struct se_subsystem_dev *su_dev = t10_wwn->t10_sub_dev;
796 struct se_device *dev;
797 unsigned char buf[INQUIRY_VPD_SERIAL_LEN];
800 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
801 * from the struct scsi_device level firmware, do not allow
802 * VPD Unit Serial to be emulated.
804 * Note this struct scsi_device could also be emulating VPD
805 * information from its drivers/scsi LLD. But for now we assume
806 * it is doing 'the right thing' wrt a world wide unique
807 * VPD Unit Serial Number that OS dependent multipath can depend on.
809 if (su_dev->su_dev_flags & SDF_FIRMWARE_VPD_UNIT_SERIAL) {
810 pr_err("Underlying SCSI device firmware provided VPD"
811 " Unit Serial, ignoring request\n");
812 return -EOPNOTSUPP;
815 if (strlen(page) >= INQUIRY_VPD_SERIAL_LEN) {
816 pr_err("Emulated VPD Unit Serial exceeds"
817 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN);
818 return -EOVERFLOW;
821 * Check to see if any active $FABRIC_MOD exports exist. If they
822 * do exist, fail here as changing this information on the fly
823 * (underneath the initiator side OS dependent multipath code)
824 * could cause negative effects.
826 dev = su_dev->se_dev_ptr;
827 if (dev) {
828 if (atomic_read(&dev->dev_export_obj.obj_access_count)) {
829 pr_err("Unable to set VPD Unit Serial while"
830 " active %d $FABRIC_MOD exports exist\n",
831 atomic_read(&dev->dev_export_obj.obj_access_count));
832 return -EINVAL;
836 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
838 * Also, strip any newline added from the userspace
839 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
841 memset(buf, 0, INQUIRY_VPD_SERIAL_LEN);
842 snprintf(buf, INQUIRY_VPD_SERIAL_LEN, "%s", page);
843 snprintf(su_dev->t10_wwn.unit_serial, INQUIRY_VPD_SERIAL_LEN,
844 "%s", strstrip(buf));
845 su_dev->su_dev_flags |= SDF_EMULATED_VPD_UNIT_SERIAL;
847 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
848 " %s\n", su_dev->t10_wwn.unit_serial);
850 return count;
853 SE_DEV_WWN_ATTR(vpd_unit_serial, S_IRUGO | S_IWUSR);
856 * VPD page 0x83 Protocol Identifier
858 static ssize_t target_core_dev_wwn_show_attr_vpd_protocol_identifier(
859 struct t10_wwn *t10_wwn,
860 char *page)
862 struct se_subsystem_dev *se_dev = t10_wwn->t10_sub_dev;
863 struct se_device *dev;
864 struct t10_vpd *vpd;
865 unsigned char buf[VPD_TMP_BUF_SIZE];
866 ssize_t len = 0;
868 dev = se_dev->se_dev_ptr;
869 if (!dev)
870 return -ENODEV;
872 memset(buf, 0, VPD_TMP_BUF_SIZE);
874 spin_lock(&t10_wwn->t10_vpd_lock);
875 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) {
876 if (!vpd->protocol_identifier_set)
877 continue;
879 transport_dump_vpd_proto_id(vpd, buf, VPD_TMP_BUF_SIZE);
881 if (len + strlen(buf) >= PAGE_SIZE)
882 break;
884 len += sprintf(page+len, "%s", buf);
886 spin_unlock(&t10_wwn->t10_vpd_lock);
888 return len;
891 static ssize_t target_core_dev_wwn_store_attr_vpd_protocol_identifier(
892 struct t10_wwn *t10_wwn,
893 const char *page,
894 size_t count)
896 return -ENOSYS;
899 SE_DEV_WWN_ATTR(vpd_protocol_identifier, S_IRUGO | S_IWUSR);
902 * Generic wrapper for dumping VPD identifiers by association.
904 #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
905 static ssize_t target_core_dev_wwn_show_attr_##_name( \
906 struct t10_wwn *t10_wwn, \
907 char *page) \
909 struct se_subsystem_dev *se_dev = t10_wwn->t10_sub_dev; \
910 struct se_device *dev; \
911 struct t10_vpd *vpd; \
912 unsigned char buf[VPD_TMP_BUF_SIZE]; \
913 ssize_t len = 0; \
915 dev = se_dev->se_dev_ptr; \
916 if (!dev) \
917 return -ENODEV; \
919 spin_lock(&t10_wwn->t10_vpd_lock); \
920 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
921 if (vpd->association != _assoc) \
922 continue; \
924 memset(buf, 0, VPD_TMP_BUF_SIZE); \
925 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
926 if (len + strlen(buf) >= PAGE_SIZE) \
927 break; \
928 len += sprintf(page+len, "%s", buf); \
930 memset(buf, 0, VPD_TMP_BUF_SIZE); \
931 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
932 if (len + strlen(buf) >= PAGE_SIZE) \
933 break; \
934 len += sprintf(page+len, "%s", buf); \
936 memset(buf, 0, VPD_TMP_BUF_SIZE); \
937 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
938 if (len + strlen(buf) >= PAGE_SIZE) \
939 break; \
940 len += sprintf(page+len, "%s", buf); \
942 spin_unlock(&t10_wwn->t10_vpd_lock); \
944 return len; \
948 * VPD page 0x83 Association: Logical Unit
950 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit, 0x00);
952 static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
953 struct t10_wwn *t10_wwn,
954 const char *page,
955 size_t count)
957 return -ENOSYS;
960 SE_DEV_WWN_ATTR(vpd_assoc_logical_unit, S_IRUGO | S_IWUSR);
963 * VPD page 0x83 Association: Target Port
965 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port, 0x10);
967 static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_target_port(
968 struct t10_wwn *t10_wwn,
969 const char *page,
970 size_t count)
972 return -ENOSYS;
975 SE_DEV_WWN_ATTR(vpd_assoc_target_port, S_IRUGO | S_IWUSR);
978 * VPD page 0x83 Association: SCSI Target Device
980 DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device, 0x20);
982 static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
983 struct t10_wwn *t10_wwn,
984 const char *page,
985 size_t count)
987 return -ENOSYS;
990 SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device, S_IRUGO | S_IWUSR);
992 CONFIGFS_EATTR_OPS(target_core_dev_wwn, t10_wwn, t10_wwn_group);
994 static struct configfs_attribute *target_core_dev_wwn_attrs[] = {
995 &target_core_dev_wwn_vpd_unit_serial.attr,
996 &target_core_dev_wwn_vpd_protocol_identifier.attr,
997 &target_core_dev_wwn_vpd_assoc_logical_unit.attr,
998 &target_core_dev_wwn_vpd_assoc_target_port.attr,
999 &target_core_dev_wwn_vpd_assoc_scsi_target_device.attr,
1000 NULL,
1003 static struct configfs_item_operations target_core_dev_wwn_ops = {
1004 .show_attribute = target_core_dev_wwn_attr_show,
1005 .store_attribute = target_core_dev_wwn_attr_store,
1008 static struct config_item_type target_core_dev_wwn_cit = {
1009 .ct_item_ops = &target_core_dev_wwn_ops,
1010 .ct_attrs = target_core_dev_wwn_attrs,
1011 .ct_owner = THIS_MODULE,
1014 /* End functions for struct config_item_type target_core_dev_wwn_cit */
1016 /* Start functions for struct config_item_type target_core_dev_pr_cit */
1018 CONFIGFS_EATTR_STRUCT(target_core_dev_pr, se_subsystem_dev);
1019 #define SE_DEV_PR_ATTR(_name, _mode) \
1020 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1021 __CONFIGFS_EATTR(_name, _mode, \
1022 target_core_dev_pr_show_attr_##_name, \
1023 target_core_dev_pr_store_attr_##_name);
1025 #define SE_DEV_PR_ATTR_RO(_name); \
1026 static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1027 __CONFIGFS_EATTR_RO(_name, \
1028 target_core_dev_pr_show_attr_##_name);
1031 * res_holder
1033 static ssize_t target_core_dev_pr_show_spc3_res(
1034 struct se_device *dev,
1035 char *page,
1036 ssize_t *len)
1038 struct se_node_acl *se_nacl;
1039 struct t10_pr_registration *pr_reg;
1040 char i_buf[PR_REG_ISID_ID_LEN];
1041 int prf_isid;
1043 memset(i_buf, 0, PR_REG_ISID_ID_LEN);
1045 spin_lock(&dev->dev_reservation_lock);
1046 pr_reg = dev->dev_pr_res_holder;
1047 if (!pr_reg) {
1048 *len += sprintf(page + *len, "No SPC-3 Reservation holder\n");
1049 spin_unlock(&dev->dev_reservation_lock);
1050 return *len;
1052 se_nacl = pr_reg->pr_reg_nacl;
1053 prf_isid = core_pr_dump_initiator_port(pr_reg, &i_buf[0],
1054 PR_REG_ISID_ID_LEN);
1056 *len += sprintf(page + *len, "SPC-3 Reservation: %s Initiator: %s%s\n",
1057 se_nacl->se_tpg->se_tpg_tfo->get_fabric_name(),
1058 se_nacl->initiatorname, (prf_isid) ? &i_buf[0] : "");
1059 spin_unlock(&dev->dev_reservation_lock);
1061 return *len;
1064 static ssize_t target_core_dev_pr_show_spc2_res(
1065 struct se_device *dev,
1066 char *page,
1067 ssize_t *len)
1069 struct se_node_acl *se_nacl;
1071 spin_lock(&dev->dev_reservation_lock);
1072 se_nacl = dev->dev_reserved_node_acl;
1073 if (!se_nacl) {
1074 *len += sprintf(page + *len, "No SPC-2 Reservation holder\n");
1075 spin_unlock(&dev->dev_reservation_lock);
1076 return *len;
1078 *len += sprintf(page + *len, "SPC-2 Reservation: %s Initiator: %s\n",
1079 se_nacl->se_tpg->se_tpg_tfo->get_fabric_name(),
1080 se_nacl->initiatorname);
1081 spin_unlock(&dev->dev_reservation_lock);
1083 return *len;
1086 static ssize_t target_core_dev_pr_show_attr_res_holder(
1087 struct se_subsystem_dev *su_dev,
1088 char *page)
1090 ssize_t len = 0;
1092 if (!su_dev->se_dev_ptr)
1093 return -ENODEV;
1095 switch (su_dev->t10_pr.res_type) {
1096 case SPC3_PERSISTENT_RESERVATIONS:
1097 target_core_dev_pr_show_spc3_res(su_dev->se_dev_ptr,
1098 page, &len);
1099 break;
1100 case SPC2_RESERVATIONS:
1101 target_core_dev_pr_show_spc2_res(su_dev->se_dev_ptr,
1102 page, &len);
1103 break;
1104 case SPC_PASSTHROUGH:
1105 len += sprintf(page+len, "Passthrough\n");
1106 break;
1107 default:
1108 len += sprintf(page+len, "Unknown\n");
1109 break;
1112 return len;
1115 SE_DEV_PR_ATTR_RO(res_holder);
1118 * res_pr_all_tgt_pts
1120 static ssize_t target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1121 struct se_subsystem_dev *su_dev,
1122 char *page)
1124 struct se_device *dev;
1125 struct t10_pr_registration *pr_reg;
1126 ssize_t len = 0;
1128 dev = su_dev->se_dev_ptr;
1129 if (!dev)
1130 return -ENODEV;
1132 if (su_dev->t10_pr.res_type != SPC3_PERSISTENT_RESERVATIONS)
1133 return len;
1135 spin_lock(&dev->dev_reservation_lock);
1136 pr_reg = dev->dev_pr_res_holder;
1137 if (!pr_reg) {
1138 len = sprintf(page, "No SPC-3 Reservation holder\n");
1139 spin_unlock(&dev->dev_reservation_lock);
1140 return len;
1143 * See All Target Ports (ALL_TG_PT) bit in spcr17, section 6.14.3
1144 * Basic PERSISTENT RESERVER OUT parameter list, page 290
1146 if (pr_reg->pr_reg_all_tg_pt)
1147 len = sprintf(page, "SPC-3 Reservation: All Target"
1148 " Ports registration\n");
1149 else
1150 len = sprintf(page, "SPC-3 Reservation: Single"
1151 " Target Port registration\n");
1152 spin_unlock(&dev->dev_reservation_lock);
1154 return len;
1157 SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts);
1160 * res_pr_generation
1162 static ssize_t target_core_dev_pr_show_attr_res_pr_generation(
1163 struct se_subsystem_dev *su_dev,
1164 char *page)
1166 if (!su_dev->se_dev_ptr)
1167 return -ENODEV;
1169 if (su_dev->t10_pr.res_type != SPC3_PERSISTENT_RESERVATIONS)
1170 return 0;
1172 return sprintf(page, "0x%08x\n", su_dev->t10_pr.pr_generation);
1175 SE_DEV_PR_ATTR_RO(res_pr_generation);
1178 * res_pr_holder_tg_port
1180 static ssize_t target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1181 struct se_subsystem_dev *su_dev,
1182 char *page)
1184 struct se_device *dev;
1185 struct se_node_acl *se_nacl;
1186 struct se_lun *lun;
1187 struct se_portal_group *se_tpg;
1188 struct t10_pr_registration *pr_reg;
1189 struct target_core_fabric_ops *tfo;
1190 ssize_t len = 0;
1192 dev = su_dev->se_dev_ptr;
1193 if (!dev)
1194 return -ENODEV;
1196 if (su_dev->t10_pr.res_type != SPC3_PERSISTENT_RESERVATIONS)
1197 return len;
1199 spin_lock(&dev->dev_reservation_lock);
1200 pr_reg = dev->dev_pr_res_holder;
1201 if (!pr_reg) {
1202 len = sprintf(page, "No SPC-3 Reservation holder\n");
1203 spin_unlock(&dev->dev_reservation_lock);
1204 return len;
1206 se_nacl = pr_reg->pr_reg_nacl;
1207 se_tpg = se_nacl->se_tpg;
1208 lun = pr_reg->pr_reg_tg_pt_lun;
1209 tfo = se_tpg->se_tpg_tfo;
1211 len += sprintf(page+len, "SPC-3 Reservation: %s"
1212 " Target Node Endpoint: %s\n", tfo->get_fabric_name(),
1213 tfo->tpg_get_wwn(se_tpg));
1214 len += sprintf(page+len, "SPC-3 Reservation: Relative Port"
1215 " Identifer Tag: %hu %s Portal Group Tag: %hu"
1216 " %s Logical Unit: %u\n", lun->lun_sep->sep_rtpi,
1217 tfo->get_fabric_name(), tfo->tpg_get_tag(se_tpg),
1218 tfo->get_fabric_name(), lun->unpacked_lun);
1219 spin_unlock(&dev->dev_reservation_lock);
1221 return len;
1224 SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port);
1227 * res_pr_registered_i_pts
1229 static ssize_t target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1230 struct se_subsystem_dev *su_dev,
1231 char *page)
1233 struct target_core_fabric_ops *tfo;
1234 struct t10_pr_registration *pr_reg;
1235 unsigned char buf[384];
1236 char i_buf[PR_REG_ISID_ID_LEN];
1237 ssize_t len = 0;
1238 int reg_count = 0, prf_isid;
1240 if (!su_dev->se_dev_ptr)
1241 return -ENODEV;
1243 if (su_dev->t10_pr.res_type != SPC3_PERSISTENT_RESERVATIONS)
1244 return len;
1246 len += sprintf(page+len, "SPC-3 PR Registrations:\n");
1248 spin_lock(&su_dev->t10_pr.registration_lock);
1249 list_for_each_entry(pr_reg, &su_dev->t10_pr.registration_list,
1250 pr_reg_list) {
1252 memset(buf, 0, 384);
1253 memset(i_buf, 0, PR_REG_ISID_ID_LEN);
1254 tfo = pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo;
1255 prf_isid = core_pr_dump_initiator_port(pr_reg, &i_buf[0],
1256 PR_REG_ISID_ID_LEN);
1257 sprintf(buf, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1258 tfo->get_fabric_name(),
1259 pr_reg->pr_reg_nacl->initiatorname, (prf_isid) ?
1260 &i_buf[0] : "", pr_reg->pr_res_key,
1261 pr_reg->pr_res_generation);
1263 if (len + strlen(buf) >= PAGE_SIZE)
1264 break;
1266 len += sprintf(page+len, "%s", buf);
1267 reg_count++;
1269 spin_unlock(&su_dev->t10_pr.registration_lock);
1271 if (!reg_count)
1272 len += sprintf(page+len, "None\n");
1274 return len;
1277 SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts);
1280 * res_pr_type
1282 static ssize_t target_core_dev_pr_show_attr_res_pr_type(
1283 struct se_subsystem_dev *su_dev,
1284 char *page)
1286 struct se_device *dev;
1287 struct t10_pr_registration *pr_reg;
1288 ssize_t len = 0;
1290 dev = su_dev->se_dev_ptr;
1291 if (!dev)
1292 return -ENODEV;
1294 if (su_dev->t10_pr.res_type != SPC3_PERSISTENT_RESERVATIONS)
1295 return len;
1297 spin_lock(&dev->dev_reservation_lock);
1298 pr_reg = dev->dev_pr_res_holder;
1299 if (!pr_reg) {
1300 len = sprintf(page, "No SPC-3 Reservation holder\n");
1301 spin_unlock(&dev->dev_reservation_lock);
1302 return len;
1304 len = sprintf(page, "SPC-3 Reservation Type: %s\n",
1305 core_scsi3_pr_dump_type(pr_reg->pr_res_type));
1306 spin_unlock(&dev->dev_reservation_lock);
1308 return len;
1311 SE_DEV_PR_ATTR_RO(res_pr_type);
1314 * res_type
1316 static ssize_t target_core_dev_pr_show_attr_res_type(
1317 struct se_subsystem_dev *su_dev,
1318 char *page)
1320 ssize_t len = 0;
1322 if (!su_dev->se_dev_ptr)
1323 return -ENODEV;
1325 switch (su_dev->t10_pr.res_type) {
1326 case SPC3_PERSISTENT_RESERVATIONS:
1327 len = sprintf(page, "SPC3_PERSISTENT_RESERVATIONS\n");
1328 break;
1329 case SPC2_RESERVATIONS:
1330 len = sprintf(page, "SPC2_RESERVATIONS\n");
1331 break;
1332 case SPC_PASSTHROUGH:
1333 len = sprintf(page, "SPC_PASSTHROUGH\n");
1334 break;
1335 default:
1336 len = sprintf(page, "UNKNOWN\n");
1337 break;
1340 return len;
1343 SE_DEV_PR_ATTR_RO(res_type);
1346 * res_aptpl_active
1349 static ssize_t target_core_dev_pr_show_attr_res_aptpl_active(
1350 struct se_subsystem_dev *su_dev,
1351 char *page)
1353 if (!su_dev->se_dev_ptr)
1354 return -ENODEV;
1356 if (su_dev->t10_pr.res_type != SPC3_PERSISTENT_RESERVATIONS)
1357 return 0;
1359 return sprintf(page, "APTPL Bit Status: %s\n",
1360 (su_dev->t10_pr.pr_aptpl_active) ? "Activated" : "Disabled");
1363 SE_DEV_PR_ATTR_RO(res_aptpl_active);
1366 * res_aptpl_metadata
1368 static ssize_t target_core_dev_pr_show_attr_res_aptpl_metadata(
1369 struct se_subsystem_dev *su_dev,
1370 char *page)
1372 if (!su_dev->se_dev_ptr)
1373 return -ENODEV;
1375 if (su_dev->t10_pr.res_type != SPC3_PERSISTENT_RESERVATIONS)
1376 return 0;
1378 return sprintf(page, "Ready to process PR APTPL metadata..\n");
1381 enum {
1382 Opt_initiator_fabric, Opt_initiator_node, Opt_initiator_sid,
1383 Opt_sa_res_key, Opt_res_holder, Opt_res_type, Opt_res_scope,
1384 Opt_res_all_tg_pt, Opt_mapped_lun, Opt_target_fabric,
1385 Opt_target_node, Opt_tpgt, Opt_port_rtpi, Opt_target_lun, Opt_err
1388 static match_table_t tokens = {
1389 {Opt_initiator_fabric, "initiator_fabric=%s"},
1390 {Opt_initiator_node, "initiator_node=%s"},
1391 {Opt_initiator_sid, "initiator_sid=%s"},
1392 {Opt_sa_res_key, "sa_res_key=%s"},
1393 {Opt_res_holder, "res_holder=%d"},
1394 {Opt_res_type, "res_type=%d"},
1395 {Opt_res_scope, "res_scope=%d"},
1396 {Opt_res_all_tg_pt, "res_all_tg_pt=%d"},
1397 {Opt_mapped_lun, "mapped_lun=%d"},
1398 {Opt_target_fabric, "target_fabric=%s"},
1399 {Opt_target_node, "target_node=%s"},
1400 {Opt_tpgt, "tpgt=%d"},
1401 {Opt_port_rtpi, "port_rtpi=%d"},
1402 {Opt_target_lun, "target_lun=%d"},
1403 {Opt_err, NULL}
1406 static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
1407 struct se_subsystem_dev *su_dev,
1408 const char *page,
1409 size_t count)
1411 struct se_device *dev;
1412 unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL;
1413 unsigned char *t_fabric = NULL, *t_port = NULL;
1414 char *orig, *ptr, *arg_p, *opts;
1415 substring_t args[MAX_OPT_ARGS];
1416 unsigned long long tmp_ll;
1417 u64 sa_res_key = 0;
1418 u32 mapped_lun = 0, target_lun = 0;
1419 int ret = -1, res_holder = 0, all_tg_pt = 0, arg, token;
1420 u16 port_rpti = 0, tpgt = 0;
1421 u8 type = 0, scope;
1423 dev = su_dev->se_dev_ptr;
1424 if (!dev)
1425 return -ENODEV;
1427 if (su_dev->t10_pr.res_type != SPC3_PERSISTENT_RESERVATIONS)
1428 return 0;
1430 if (atomic_read(&dev->dev_export_obj.obj_access_count)) {
1431 pr_debug("Unable to process APTPL metadata while"
1432 " active fabric exports exist\n");
1433 return -EINVAL;
1436 opts = kstrdup(page, GFP_KERNEL);
1437 if (!opts)
1438 return -ENOMEM;
1440 orig = opts;
1441 while ((ptr = strsep(&opts, ",\n")) != NULL) {
1442 if (!*ptr)
1443 continue;
1445 token = match_token(ptr, tokens, args);
1446 switch (token) {
1447 case Opt_initiator_fabric:
1448 i_fabric = match_strdup(&args[0]);
1449 if (!i_fabric) {
1450 ret = -ENOMEM;
1451 goto out;
1453 break;
1454 case Opt_initiator_node:
1455 i_port = match_strdup(&args[0]);
1456 if (!i_port) {
1457 ret = -ENOMEM;
1458 goto out;
1460 if (strlen(i_port) >= PR_APTPL_MAX_IPORT_LEN) {
1461 pr_err("APTPL metadata initiator_node="
1462 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1463 PR_APTPL_MAX_IPORT_LEN);
1464 ret = -EINVAL;
1465 break;
1467 break;
1468 case Opt_initiator_sid:
1469 isid = match_strdup(&args[0]);
1470 if (!isid) {
1471 ret = -ENOMEM;
1472 goto out;
1474 if (strlen(isid) >= PR_REG_ISID_LEN) {
1475 pr_err("APTPL metadata initiator_isid"
1476 "= exceeds PR_REG_ISID_LEN: %d\n",
1477 PR_REG_ISID_LEN);
1478 ret = -EINVAL;
1479 break;
1481 break;
1482 case Opt_sa_res_key:
1483 arg_p = match_strdup(&args[0]);
1484 if (!arg_p) {
1485 ret = -ENOMEM;
1486 goto out;
1488 ret = strict_strtoull(arg_p, 0, &tmp_ll);
1489 if (ret < 0) {
1490 pr_err("strict_strtoull() failed for"
1491 " sa_res_key=\n");
1492 goto out;
1494 sa_res_key = (u64)tmp_ll;
1495 break;
1497 * PR APTPL Metadata for Reservation
1499 case Opt_res_holder:
1500 match_int(args, &arg);
1501 res_holder = arg;
1502 break;
1503 case Opt_res_type:
1504 match_int(args, &arg);
1505 type = (u8)arg;
1506 break;
1507 case Opt_res_scope:
1508 match_int(args, &arg);
1509 scope = (u8)arg;
1510 break;
1511 case Opt_res_all_tg_pt:
1512 match_int(args, &arg);
1513 all_tg_pt = (int)arg;
1514 break;
1515 case Opt_mapped_lun:
1516 match_int(args, &arg);
1517 mapped_lun = (u32)arg;
1518 break;
1520 * PR APTPL Metadata for Target Port
1522 case Opt_target_fabric:
1523 t_fabric = match_strdup(&args[0]);
1524 if (!t_fabric) {
1525 ret = -ENOMEM;
1526 goto out;
1528 break;
1529 case Opt_target_node:
1530 t_port = match_strdup(&args[0]);
1531 if (!t_port) {
1532 ret = -ENOMEM;
1533 goto out;
1535 if (strlen(t_port) >= PR_APTPL_MAX_TPORT_LEN) {
1536 pr_err("APTPL metadata target_node="
1537 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1538 PR_APTPL_MAX_TPORT_LEN);
1539 ret = -EINVAL;
1540 break;
1542 break;
1543 case Opt_tpgt:
1544 match_int(args, &arg);
1545 tpgt = (u16)arg;
1546 break;
1547 case Opt_port_rtpi:
1548 match_int(args, &arg);
1549 port_rpti = (u16)arg;
1550 break;
1551 case Opt_target_lun:
1552 match_int(args, &arg);
1553 target_lun = (u32)arg;
1554 break;
1555 default:
1556 break;
1560 if (!i_port || !t_port || !sa_res_key) {
1561 pr_err("Illegal parameters for APTPL registration\n");
1562 ret = -EINVAL;
1563 goto out;
1566 if (res_holder && !(type)) {
1567 pr_err("Illegal PR type: 0x%02x for reservation"
1568 " holder\n", type);
1569 ret = -EINVAL;
1570 goto out;
1573 ret = core_scsi3_alloc_aptpl_registration(&su_dev->t10_pr, sa_res_key,
1574 i_port, isid, mapped_lun, t_port, tpgt, target_lun,
1575 res_holder, all_tg_pt, type);
1576 out:
1577 kfree(i_fabric);
1578 kfree(i_port);
1579 kfree(isid);
1580 kfree(t_fabric);
1581 kfree(t_port);
1582 kfree(orig);
1583 return (ret == 0) ? count : ret;
1586 SE_DEV_PR_ATTR(res_aptpl_metadata, S_IRUGO | S_IWUSR);
1588 CONFIGFS_EATTR_OPS(target_core_dev_pr, se_subsystem_dev, se_dev_pr_group);
1590 static struct configfs_attribute *target_core_dev_pr_attrs[] = {
1591 &target_core_dev_pr_res_holder.attr,
1592 &target_core_dev_pr_res_pr_all_tgt_pts.attr,
1593 &target_core_dev_pr_res_pr_generation.attr,
1594 &target_core_dev_pr_res_pr_holder_tg_port.attr,
1595 &target_core_dev_pr_res_pr_registered_i_pts.attr,
1596 &target_core_dev_pr_res_pr_type.attr,
1597 &target_core_dev_pr_res_type.attr,
1598 &target_core_dev_pr_res_aptpl_active.attr,
1599 &target_core_dev_pr_res_aptpl_metadata.attr,
1600 NULL,
1603 static struct configfs_item_operations target_core_dev_pr_ops = {
1604 .show_attribute = target_core_dev_pr_attr_show,
1605 .store_attribute = target_core_dev_pr_attr_store,
1608 static struct config_item_type target_core_dev_pr_cit = {
1609 .ct_item_ops = &target_core_dev_pr_ops,
1610 .ct_attrs = target_core_dev_pr_attrs,
1611 .ct_owner = THIS_MODULE,
1614 /* End functions for struct config_item_type target_core_dev_pr_cit */
1616 /* Start functions for struct config_item_type target_core_dev_cit */
1618 static ssize_t target_core_show_dev_info(void *p, char *page)
1620 struct se_subsystem_dev *se_dev = p;
1621 struct se_hba *hba = se_dev->se_dev_hba;
1622 struct se_subsystem_api *t = hba->transport;
1623 int bl = 0;
1624 ssize_t read_bytes = 0;
1626 if (!se_dev->se_dev_ptr)
1627 return -ENODEV;
1629 transport_dump_dev_state(se_dev->se_dev_ptr, page, &bl);
1630 read_bytes += bl;
1631 read_bytes += t->show_configfs_dev_params(hba, se_dev, page+read_bytes);
1632 return read_bytes;
1635 static struct target_core_configfs_attribute target_core_attr_dev_info = {
1636 .attr = { .ca_owner = THIS_MODULE,
1637 .ca_name = "info",
1638 .ca_mode = S_IRUGO },
1639 .show = target_core_show_dev_info,
1640 .store = NULL,
1643 static ssize_t target_core_store_dev_control(
1644 void *p,
1645 const char *page,
1646 size_t count)
1648 struct se_subsystem_dev *se_dev = p;
1649 struct se_hba *hba = se_dev->se_dev_hba;
1650 struct se_subsystem_api *t = hba->transport;
1652 if (!se_dev->se_dev_su_ptr) {
1653 pr_err("Unable to locate struct se_subsystem_dev>se"
1654 "_dev_su_ptr\n");
1655 return -EINVAL;
1658 return t->set_configfs_dev_params(hba, se_dev, page, count);
1661 static struct target_core_configfs_attribute target_core_attr_dev_control = {
1662 .attr = { .ca_owner = THIS_MODULE,
1663 .ca_name = "control",
1664 .ca_mode = S_IWUSR },
1665 .show = NULL,
1666 .store = target_core_store_dev_control,
1669 static ssize_t target_core_show_dev_alias(void *p, char *page)
1671 struct se_subsystem_dev *se_dev = p;
1673 if (!(se_dev->su_dev_flags & SDF_USING_ALIAS))
1674 return 0;
1676 return snprintf(page, PAGE_SIZE, "%s\n", se_dev->se_dev_alias);
1679 static ssize_t target_core_store_dev_alias(
1680 void *p,
1681 const char *page,
1682 size_t count)
1684 struct se_subsystem_dev *se_dev = p;
1685 struct se_hba *hba = se_dev->se_dev_hba;
1686 ssize_t read_bytes;
1688 if (count > (SE_DEV_ALIAS_LEN-1)) {
1689 pr_err("alias count: %d exceeds"
1690 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count,
1691 SE_DEV_ALIAS_LEN-1);
1692 return -EINVAL;
1695 read_bytes = snprintf(&se_dev->se_dev_alias[0], SE_DEV_ALIAS_LEN,
1696 "%s", page);
1697 if (!read_bytes)
1698 return -EINVAL;
1699 if (se_dev->se_dev_alias[read_bytes - 1] == '\n')
1700 se_dev->se_dev_alias[read_bytes - 1] = '\0';
1702 se_dev->su_dev_flags |= SDF_USING_ALIAS;
1704 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
1705 config_item_name(&hba->hba_group.cg_item),
1706 config_item_name(&se_dev->se_dev_group.cg_item),
1707 se_dev->se_dev_alias);
1709 return read_bytes;
1712 static struct target_core_configfs_attribute target_core_attr_dev_alias = {
1713 .attr = { .ca_owner = THIS_MODULE,
1714 .ca_name = "alias",
1715 .ca_mode = S_IRUGO | S_IWUSR },
1716 .show = target_core_show_dev_alias,
1717 .store = target_core_store_dev_alias,
1720 static ssize_t target_core_show_dev_udev_path(void *p, char *page)
1722 struct se_subsystem_dev *se_dev = p;
1724 if (!(se_dev->su_dev_flags & SDF_USING_UDEV_PATH))
1725 return 0;
1727 return snprintf(page, PAGE_SIZE, "%s\n", se_dev->se_dev_udev_path);
1730 static ssize_t target_core_store_dev_udev_path(
1731 void *p,
1732 const char *page,
1733 size_t count)
1735 struct se_subsystem_dev *se_dev = p;
1736 struct se_hba *hba = se_dev->se_dev_hba;
1737 ssize_t read_bytes;
1739 if (count > (SE_UDEV_PATH_LEN-1)) {
1740 pr_err("udev_path count: %d exceeds"
1741 " SE_UDEV_PATH_LEN-1: %u\n", (int)count,
1742 SE_UDEV_PATH_LEN-1);
1743 return -EINVAL;
1746 read_bytes = snprintf(&se_dev->se_dev_udev_path[0], SE_UDEV_PATH_LEN,
1747 "%s", page);
1748 if (!read_bytes)
1749 return -EINVAL;
1750 if (se_dev->se_dev_udev_path[read_bytes - 1] == '\n')
1751 se_dev->se_dev_udev_path[read_bytes - 1] = '\0';
1753 se_dev->su_dev_flags |= SDF_USING_UDEV_PATH;
1755 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
1756 config_item_name(&hba->hba_group.cg_item),
1757 config_item_name(&se_dev->se_dev_group.cg_item),
1758 se_dev->se_dev_udev_path);
1760 return read_bytes;
1763 static struct target_core_configfs_attribute target_core_attr_dev_udev_path = {
1764 .attr = { .ca_owner = THIS_MODULE,
1765 .ca_name = "udev_path",
1766 .ca_mode = S_IRUGO | S_IWUSR },
1767 .show = target_core_show_dev_udev_path,
1768 .store = target_core_store_dev_udev_path,
1771 static ssize_t target_core_store_dev_enable(
1772 void *p,
1773 const char *page,
1774 size_t count)
1776 struct se_subsystem_dev *se_dev = p;
1777 struct se_device *dev;
1778 struct se_hba *hba = se_dev->se_dev_hba;
1779 struct se_subsystem_api *t = hba->transport;
1780 char *ptr;
1782 ptr = strstr(page, "1");
1783 if (!ptr) {
1784 pr_err("For dev_enable ops, only valid value"
1785 " is \"1\"\n");
1786 return -EINVAL;
1788 if (se_dev->se_dev_ptr) {
1789 pr_err("se_dev->se_dev_ptr already set for storage"
1790 " object\n");
1791 return -EEXIST;
1794 if (t->check_configfs_dev_params(hba, se_dev) < 0)
1795 return -EINVAL;
1797 dev = t->create_virtdevice(hba, se_dev, se_dev->se_dev_su_ptr);
1798 if (IS_ERR(dev))
1799 return PTR_ERR(dev);
1800 else if (!dev)
1801 return -EINVAL;
1803 se_dev->se_dev_ptr = dev;
1804 pr_debug("Target_Core_ConfigFS: Registered se_dev->se_dev_ptr:"
1805 " %p\n", se_dev->se_dev_ptr);
1807 return count;
1810 static struct target_core_configfs_attribute target_core_attr_dev_enable = {
1811 .attr = { .ca_owner = THIS_MODULE,
1812 .ca_name = "enable",
1813 .ca_mode = S_IWUSR },
1814 .show = NULL,
1815 .store = target_core_store_dev_enable,
1818 static ssize_t target_core_show_alua_lu_gp(void *p, char *page)
1820 struct se_device *dev;
1821 struct se_subsystem_dev *su_dev = p;
1822 struct config_item *lu_ci;
1823 struct t10_alua_lu_gp *lu_gp;
1824 struct t10_alua_lu_gp_member *lu_gp_mem;
1825 ssize_t len = 0;
1827 dev = su_dev->se_dev_ptr;
1828 if (!dev)
1829 return -ENODEV;
1831 if (su_dev->t10_alua.alua_type != SPC3_ALUA_EMULATED)
1832 return len;
1834 lu_gp_mem = dev->dev_alua_lu_gp_mem;
1835 if (!lu_gp_mem) {
1836 pr_err("NULL struct se_device->dev_alua_lu_gp_mem"
1837 " pointer\n");
1838 return -EINVAL;
1841 spin_lock(&lu_gp_mem->lu_gp_mem_lock);
1842 lu_gp = lu_gp_mem->lu_gp;
1843 if (lu_gp) {
1844 lu_ci = &lu_gp->lu_gp_group.cg_item;
1845 len += sprintf(page, "LU Group Alias: %s\nLU Group ID: %hu\n",
1846 config_item_name(lu_ci), lu_gp->lu_gp_id);
1848 spin_unlock(&lu_gp_mem->lu_gp_mem_lock);
1850 return len;
1853 static ssize_t target_core_store_alua_lu_gp(
1854 void *p,
1855 const char *page,
1856 size_t count)
1858 struct se_device *dev;
1859 struct se_subsystem_dev *su_dev = p;
1860 struct se_hba *hba = su_dev->se_dev_hba;
1861 struct t10_alua_lu_gp *lu_gp = NULL, *lu_gp_new = NULL;
1862 struct t10_alua_lu_gp_member *lu_gp_mem;
1863 unsigned char buf[LU_GROUP_NAME_BUF];
1864 int move = 0;
1866 dev = su_dev->se_dev_ptr;
1867 if (!dev)
1868 return -ENODEV;
1870 if (su_dev->t10_alua.alua_type != SPC3_ALUA_EMULATED) {
1871 pr_warn("SPC3_ALUA_EMULATED not enabled for %s/%s\n",
1872 config_item_name(&hba->hba_group.cg_item),
1873 config_item_name(&su_dev->se_dev_group.cg_item));
1874 return -EINVAL;
1876 if (count > LU_GROUP_NAME_BUF) {
1877 pr_err("ALUA LU Group Alias too large!\n");
1878 return -EINVAL;
1880 memset(buf, 0, LU_GROUP_NAME_BUF);
1881 memcpy(buf, page, count);
1883 * Any ALUA logical unit alias besides "NULL" means we will be
1884 * making a new group association.
1886 if (strcmp(strstrip(buf), "NULL")) {
1888 * core_alua_get_lu_gp_by_name() will increment reference to
1889 * struct t10_alua_lu_gp. This reference is released with
1890 * core_alua_get_lu_gp_by_name below().
1892 lu_gp_new = core_alua_get_lu_gp_by_name(strstrip(buf));
1893 if (!lu_gp_new)
1894 return -ENODEV;
1896 lu_gp_mem = dev->dev_alua_lu_gp_mem;
1897 if (!lu_gp_mem) {
1898 if (lu_gp_new)
1899 core_alua_put_lu_gp_from_name(lu_gp_new);
1900 pr_err("NULL struct se_device->dev_alua_lu_gp_mem"
1901 " pointer\n");
1902 return -EINVAL;
1905 spin_lock(&lu_gp_mem->lu_gp_mem_lock);
1906 lu_gp = lu_gp_mem->lu_gp;
1907 if (lu_gp) {
1909 * Clearing an existing lu_gp association, and replacing
1910 * with NULL
1912 if (!lu_gp_new) {
1913 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
1914 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1915 " %hu\n",
1916 config_item_name(&hba->hba_group.cg_item),
1917 config_item_name(&su_dev->se_dev_group.cg_item),
1918 config_item_name(&lu_gp->lu_gp_group.cg_item),
1919 lu_gp->lu_gp_id);
1921 __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp);
1922 spin_unlock(&lu_gp_mem->lu_gp_mem_lock);
1924 return count;
1927 * Removing existing association of lu_gp_mem with lu_gp
1929 __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp);
1930 move = 1;
1933 * Associate lu_gp_mem with lu_gp_new.
1935 __core_alua_attach_lu_gp_mem(lu_gp_mem, lu_gp_new);
1936 spin_unlock(&lu_gp_mem->lu_gp_mem_lock);
1938 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
1939 " core/alua/lu_gps/%s, ID: %hu\n",
1940 (move) ? "Moving" : "Adding",
1941 config_item_name(&hba->hba_group.cg_item),
1942 config_item_name(&su_dev->se_dev_group.cg_item),
1943 config_item_name(&lu_gp_new->lu_gp_group.cg_item),
1944 lu_gp_new->lu_gp_id);
1946 core_alua_put_lu_gp_from_name(lu_gp_new);
1947 return count;
1950 static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp = {
1951 .attr = { .ca_owner = THIS_MODULE,
1952 .ca_name = "alua_lu_gp",
1953 .ca_mode = S_IRUGO | S_IWUSR },
1954 .show = target_core_show_alua_lu_gp,
1955 .store = target_core_store_alua_lu_gp,
1958 static struct configfs_attribute *lio_core_dev_attrs[] = {
1959 &target_core_attr_dev_info.attr,
1960 &target_core_attr_dev_control.attr,
1961 &target_core_attr_dev_alias.attr,
1962 &target_core_attr_dev_udev_path.attr,
1963 &target_core_attr_dev_enable.attr,
1964 &target_core_attr_dev_alua_lu_gp.attr,
1965 NULL,
1968 static void target_core_dev_release(struct config_item *item)
1970 struct se_subsystem_dev *se_dev = container_of(to_config_group(item),
1971 struct se_subsystem_dev, se_dev_group);
1972 struct se_hba *hba = item_to_hba(&se_dev->se_dev_hba->hba_group.cg_item);
1973 struct se_subsystem_api *t = hba->transport;
1974 struct config_group *dev_cg = &se_dev->se_dev_group;
1976 kfree(dev_cg->default_groups);
1978 * This pointer will set when the storage is enabled with:
1979 *`echo 1 > $CONFIGFS/core/$HBA/$DEV/dev_enable`
1981 if (se_dev->se_dev_ptr) {
1982 pr_debug("Target_Core_ConfigFS: Calling se_free_"
1983 "virtual_device() for se_dev_ptr: %p\n",
1984 se_dev->se_dev_ptr);
1986 se_free_virtual_device(se_dev->se_dev_ptr, hba);
1987 } else {
1989 * Release struct se_subsystem_dev->se_dev_su_ptr..
1991 pr_debug("Target_Core_ConfigFS: Calling t->free_"
1992 "device() for se_dev_su_ptr: %p\n",
1993 se_dev->se_dev_su_ptr);
1995 t->free_device(se_dev->se_dev_su_ptr);
1998 pr_debug("Target_Core_ConfigFS: Deallocating se_subsystem"
1999 "_dev_t: %p\n", se_dev);
2000 kfree(se_dev);
2003 static ssize_t target_core_dev_show(struct config_item *item,
2004 struct configfs_attribute *attr,
2005 char *page)
2007 struct se_subsystem_dev *se_dev = container_of(
2008 to_config_group(item), struct se_subsystem_dev,
2009 se_dev_group);
2010 struct target_core_configfs_attribute *tc_attr = container_of(
2011 attr, struct target_core_configfs_attribute, attr);
2013 if (!tc_attr->show)
2014 return -EINVAL;
2016 return tc_attr->show(se_dev, page);
2019 static ssize_t target_core_dev_store(struct config_item *item,
2020 struct configfs_attribute *attr,
2021 const char *page, size_t count)
2023 struct se_subsystem_dev *se_dev = container_of(
2024 to_config_group(item), struct se_subsystem_dev,
2025 se_dev_group);
2026 struct target_core_configfs_attribute *tc_attr = container_of(
2027 attr, struct target_core_configfs_attribute, attr);
2029 if (!tc_attr->store)
2030 return -EINVAL;
2032 return tc_attr->store(se_dev, page, count);
2035 static struct configfs_item_operations target_core_dev_item_ops = {
2036 .release = target_core_dev_release,
2037 .show_attribute = target_core_dev_show,
2038 .store_attribute = target_core_dev_store,
2041 static struct config_item_type target_core_dev_cit = {
2042 .ct_item_ops = &target_core_dev_item_ops,
2043 .ct_attrs = lio_core_dev_attrs,
2044 .ct_owner = THIS_MODULE,
2047 /* End functions for struct config_item_type target_core_dev_cit */
2049 /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
2051 CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp, t10_alua_lu_gp);
2052 #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
2053 static struct target_core_alua_lu_gp_attribute \
2054 target_core_alua_lu_gp_##_name = \
2055 __CONFIGFS_EATTR(_name, _mode, \
2056 target_core_alua_lu_gp_show_attr_##_name, \
2057 target_core_alua_lu_gp_store_attr_##_name);
2059 #define SE_DEV_ALUA_LU_ATTR_RO(_name) \
2060 static struct target_core_alua_lu_gp_attribute \
2061 target_core_alua_lu_gp_##_name = \
2062 __CONFIGFS_EATTR_RO(_name, \
2063 target_core_alua_lu_gp_show_attr_##_name);
2066 * lu_gp_id
2068 static ssize_t target_core_alua_lu_gp_show_attr_lu_gp_id(
2069 struct t10_alua_lu_gp *lu_gp,
2070 char *page)
2072 if (!lu_gp->lu_gp_valid_id)
2073 return 0;
2075 return sprintf(page, "%hu\n", lu_gp->lu_gp_id);
2078 static ssize_t target_core_alua_lu_gp_store_attr_lu_gp_id(
2079 struct t10_alua_lu_gp *lu_gp,
2080 const char *page,
2081 size_t count)
2083 struct config_group *alua_lu_gp_cg = &lu_gp->lu_gp_group;
2084 unsigned long lu_gp_id;
2085 int ret;
2087 ret = strict_strtoul(page, 0, &lu_gp_id);
2088 if (ret < 0) {
2089 pr_err("strict_strtoul() returned %d for"
2090 " lu_gp_id\n", ret);
2091 return -EINVAL;
2093 if (lu_gp_id > 0x0000ffff) {
2094 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
2095 " 0x0000ffff\n", lu_gp_id);
2096 return -EINVAL;
2099 ret = core_alua_set_lu_gp_id(lu_gp, (u16)lu_gp_id);
2100 if (ret < 0)
2101 return -EINVAL;
2103 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
2104 " Group: core/alua/lu_gps/%s to ID: %hu\n",
2105 config_item_name(&alua_lu_gp_cg->cg_item),
2106 lu_gp->lu_gp_id);
2108 return count;
2111 SE_DEV_ALUA_LU_ATTR(lu_gp_id, S_IRUGO | S_IWUSR);
2114 * members
2116 static ssize_t target_core_alua_lu_gp_show_attr_members(
2117 struct t10_alua_lu_gp *lu_gp,
2118 char *page)
2120 struct se_device *dev;
2121 struct se_hba *hba;
2122 struct se_subsystem_dev *su_dev;
2123 struct t10_alua_lu_gp_member *lu_gp_mem;
2124 ssize_t len = 0, cur_len;
2125 unsigned char buf[LU_GROUP_NAME_BUF];
2127 memset(buf, 0, LU_GROUP_NAME_BUF);
2129 spin_lock(&lu_gp->lu_gp_lock);
2130 list_for_each_entry(lu_gp_mem, &lu_gp->lu_gp_mem_list, lu_gp_mem_list) {
2131 dev = lu_gp_mem->lu_gp_mem_dev;
2132 su_dev = dev->se_sub_dev;
2133 hba = su_dev->se_dev_hba;
2135 cur_len = snprintf(buf, LU_GROUP_NAME_BUF, "%s/%s\n",
2136 config_item_name(&hba->hba_group.cg_item),
2137 config_item_name(&su_dev->se_dev_group.cg_item));
2138 cur_len++; /* Extra byte for NULL terminator */
2140 if ((cur_len + len) > PAGE_SIZE) {
2141 pr_warn("Ran out of lu_gp_show_attr"
2142 "_members buffer\n");
2143 break;
2145 memcpy(page+len, buf, cur_len);
2146 len += cur_len;
2148 spin_unlock(&lu_gp->lu_gp_lock);
2150 return len;
2153 SE_DEV_ALUA_LU_ATTR_RO(members);
2155 CONFIGFS_EATTR_OPS(target_core_alua_lu_gp, t10_alua_lu_gp, lu_gp_group);
2157 static struct configfs_attribute *target_core_alua_lu_gp_attrs[] = {
2158 &target_core_alua_lu_gp_lu_gp_id.attr,
2159 &target_core_alua_lu_gp_members.attr,
2160 NULL,
2163 static void target_core_alua_lu_gp_release(struct config_item *item)
2165 struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item),
2166 struct t10_alua_lu_gp, lu_gp_group);
2168 core_alua_free_lu_gp(lu_gp);
2171 static struct configfs_item_operations target_core_alua_lu_gp_ops = {
2172 .release = target_core_alua_lu_gp_release,
2173 .show_attribute = target_core_alua_lu_gp_attr_show,
2174 .store_attribute = target_core_alua_lu_gp_attr_store,
2177 static struct config_item_type target_core_alua_lu_gp_cit = {
2178 .ct_item_ops = &target_core_alua_lu_gp_ops,
2179 .ct_attrs = target_core_alua_lu_gp_attrs,
2180 .ct_owner = THIS_MODULE,
2183 /* End functions for struct config_item_type target_core_alua_lu_gp_cit */
2185 /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
2187 static struct config_group *target_core_alua_create_lu_gp(
2188 struct config_group *group,
2189 const char *name)
2191 struct t10_alua_lu_gp *lu_gp;
2192 struct config_group *alua_lu_gp_cg = NULL;
2193 struct config_item *alua_lu_gp_ci = NULL;
2195 lu_gp = core_alua_allocate_lu_gp(name, 0);
2196 if (IS_ERR(lu_gp))
2197 return NULL;
2199 alua_lu_gp_cg = &lu_gp->lu_gp_group;
2200 alua_lu_gp_ci = &alua_lu_gp_cg->cg_item;
2202 config_group_init_type_name(alua_lu_gp_cg, name,
2203 &target_core_alua_lu_gp_cit);
2205 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
2206 " Group: core/alua/lu_gps/%s\n",
2207 config_item_name(alua_lu_gp_ci));
2209 return alua_lu_gp_cg;
2213 static void target_core_alua_drop_lu_gp(
2214 struct config_group *group,
2215 struct config_item *item)
2217 struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item),
2218 struct t10_alua_lu_gp, lu_gp_group);
2220 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
2221 " Group: core/alua/lu_gps/%s, ID: %hu\n",
2222 config_item_name(item), lu_gp->lu_gp_id);
2224 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
2225 * -> target_core_alua_lu_gp_release()
2227 config_item_put(item);
2230 static struct configfs_group_operations target_core_alua_lu_gps_group_ops = {
2231 .make_group = &target_core_alua_create_lu_gp,
2232 .drop_item = &target_core_alua_drop_lu_gp,
2235 static struct config_item_type target_core_alua_lu_gps_cit = {
2236 .ct_item_ops = NULL,
2237 .ct_group_ops = &target_core_alua_lu_gps_group_ops,
2238 .ct_owner = THIS_MODULE,
2241 /* End functions for struct config_item_type target_core_alua_lu_gps_cit */
2243 /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2245 CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp, t10_alua_tg_pt_gp);
2246 #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
2247 static struct target_core_alua_tg_pt_gp_attribute \
2248 target_core_alua_tg_pt_gp_##_name = \
2249 __CONFIGFS_EATTR(_name, _mode, \
2250 target_core_alua_tg_pt_gp_show_attr_##_name, \
2251 target_core_alua_tg_pt_gp_store_attr_##_name);
2253 #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2254 static struct target_core_alua_tg_pt_gp_attribute \
2255 target_core_alua_tg_pt_gp_##_name = \
2256 __CONFIGFS_EATTR_RO(_name, \
2257 target_core_alua_tg_pt_gp_show_attr_##_name);
2260 * alua_access_state
2262 static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2263 struct t10_alua_tg_pt_gp *tg_pt_gp,
2264 char *page)
2266 return sprintf(page, "%d\n",
2267 atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state));
2270 static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2271 struct t10_alua_tg_pt_gp *tg_pt_gp,
2272 const char *page,
2273 size_t count)
2275 struct se_subsystem_dev *su_dev = tg_pt_gp->tg_pt_gp_su_dev;
2276 unsigned long tmp;
2277 int new_state, ret;
2279 if (!tg_pt_gp->tg_pt_gp_valid_id) {
2280 pr_err("Unable to do implict ALUA on non valid"
2281 " tg_pt_gp ID: %hu\n", tg_pt_gp->tg_pt_gp_valid_id);
2282 return -EINVAL;
2285 ret = strict_strtoul(page, 0, &tmp);
2286 if (ret < 0) {
2287 pr_err("Unable to extract new ALUA access state from"
2288 " %s\n", page);
2289 return -EINVAL;
2291 new_state = (int)tmp;
2293 if (!(tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_IMPLICT_ALUA)) {
2294 pr_err("Unable to process implict configfs ALUA"
2295 " transition while TPGS_IMPLICT_ALUA is disabled\n");
2296 return -EINVAL;
2299 ret = core_alua_do_port_transition(tg_pt_gp, su_dev->se_dev_ptr,
2300 NULL, NULL, new_state, 0);
2301 return (!ret) ? count : -EINVAL;
2304 SE_DEV_ALUA_TG_PT_ATTR(alua_access_state, S_IRUGO | S_IWUSR);
2307 * alua_access_status
2309 static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2310 struct t10_alua_tg_pt_gp *tg_pt_gp,
2311 char *page)
2313 return sprintf(page, "%s\n",
2314 core_alua_dump_status(tg_pt_gp->tg_pt_gp_alua_access_status));
2317 static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2318 struct t10_alua_tg_pt_gp *tg_pt_gp,
2319 const char *page,
2320 size_t count)
2322 unsigned long tmp;
2323 int new_status, ret;
2325 if (!tg_pt_gp->tg_pt_gp_valid_id) {
2326 pr_err("Unable to do set ALUA access status on non"
2327 " valid tg_pt_gp ID: %hu\n",
2328 tg_pt_gp->tg_pt_gp_valid_id);
2329 return -EINVAL;
2332 ret = strict_strtoul(page, 0, &tmp);
2333 if (ret < 0) {
2334 pr_err("Unable to extract new ALUA access status"
2335 " from %s\n", page);
2336 return -EINVAL;
2338 new_status = (int)tmp;
2340 if ((new_status != ALUA_STATUS_NONE) &&
2341 (new_status != ALUA_STATUS_ALTERED_BY_EXPLICT_STPG) &&
2342 (new_status != ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA)) {
2343 pr_err("Illegal ALUA access status: 0x%02x\n",
2344 new_status);
2345 return -EINVAL;
2348 tg_pt_gp->tg_pt_gp_alua_access_status = new_status;
2349 return count;
2352 SE_DEV_ALUA_TG_PT_ATTR(alua_access_status, S_IRUGO | S_IWUSR);
2355 * alua_access_type
2357 static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2358 struct t10_alua_tg_pt_gp *tg_pt_gp,
2359 char *page)
2361 return core_alua_show_access_type(tg_pt_gp, page);
2364 static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2365 struct t10_alua_tg_pt_gp *tg_pt_gp,
2366 const char *page,
2367 size_t count)
2369 return core_alua_store_access_type(tg_pt_gp, page, count);
2372 SE_DEV_ALUA_TG_PT_ATTR(alua_access_type, S_IRUGO | S_IWUSR);
2375 * alua_write_metadata
2377 static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2378 struct t10_alua_tg_pt_gp *tg_pt_gp,
2379 char *page)
2381 return sprintf(page, "%d\n", tg_pt_gp->tg_pt_gp_write_metadata);
2384 static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2385 struct t10_alua_tg_pt_gp *tg_pt_gp,
2386 const char *page,
2387 size_t count)
2389 unsigned long tmp;
2390 int ret;
2392 ret = strict_strtoul(page, 0, &tmp);
2393 if (ret < 0) {
2394 pr_err("Unable to extract alua_write_metadata\n");
2395 return -EINVAL;
2398 if ((tmp != 0) && (tmp != 1)) {
2399 pr_err("Illegal value for alua_write_metadata:"
2400 " %lu\n", tmp);
2401 return -EINVAL;
2403 tg_pt_gp->tg_pt_gp_write_metadata = (int)tmp;
2405 return count;
2408 SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata, S_IRUGO | S_IWUSR);
2413 * nonop_delay_msecs
2415 static ssize_t target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2416 struct t10_alua_tg_pt_gp *tg_pt_gp,
2417 char *page)
2419 return core_alua_show_nonop_delay_msecs(tg_pt_gp, page);
2423 static ssize_t target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2424 struct t10_alua_tg_pt_gp *tg_pt_gp,
2425 const char *page,
2426 size_t count)
2428 return core_alua_store_nonop_delay_msecs(tg_pt_gp, page, count);
2431 SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs, S_IRUGO | S_IWUSR);
2434 * trans_delay_msecs
2436 static ssize_t target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2437 struct t10_alua_tg_pt_gp *tg_pt_gp,
2438 char *page)
2440 return core_alua_show_trans_delay_msecs(tg_pt_gp, page);
2443 static ssize_t target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2444 struct t10_alua_tg_pt_gp *tg_pt_gp,
2445 const char *page,
2446 size_t count)
2448 return core_alua_store_trans_delay_msecs(tg_pt_gp, page, count);
2451 SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs, S_IRUGO | S_IWUSR);
2454 * preferred
2457 static ssize_t target_core_alua_tg_pt_gp_show_attr_preferred(
2458 struct t10_alua_tg_pt_gp *tg_pt_gp,
2459 char *page)
2461 return core_alua_show_preferred_bit(tg_pt_gp, page);
2464 static ssize_t target_core_alua_tg_pt_gp_store_attr_preferred(
2465 struct t10_alua_tg_pt_gp *tg_pt_gp,
2466 const char *page,
2467 size_t count)
2469 return core_alua_store_preferred_bit(tg_pt_gp, page, count);
2472 SE_DEV_ALUA_TG_PT_ATTR(preferred, S_IRUGO | S_IWUSR);
2475 * tg_pt_gp_id
2477 static ssize_t target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2478 struct t10_alua_tg_pt_gp *tg_pt_gp,
2479 char *page)
2481 if (!tg_pt_gp->tg_pt_gp_valid_id)
2482 return 0;
2484 return sprintf(page, "%hu\n", tg_pt_gp->tg_pt_gp_id);
2487 static ssize_t target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2488 struct t10_alua_tg_pt_gp *tg_pt_gp,
2489 const char *page,
2490 size_t count)
2492 struct config_group *alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group;
2493 unsigned long tg_pt_gp_id;
2494 int ret;
2496 ret = strict_strtoul(page, 0, &tg_pt_gp_id);
2497 if (ret < 0) {
2498 pr_err("strict_strtoul() returned %d for"
2499 " tg_pt_gp_id\n", ret);
2500 return -EINVAL;
2502 if (tg_pt_gp_id > 0x0000ffff) {
2503 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:"
2504 " 0x0000ffff\n", tg_pt_gp_id);
2505 return -EINVAL;
2508 ret = core_alua_set_tg_pt_gp_id(tg_pt_gp, (u16)tg_pt_gp_id);
2509 if (ret < 0)
2510 return -EINVAL;
2512 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
2513 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2514 config_item_name(&alua_tg_pt_gp_cg->cg_item),
2515 tg_pt_gp->tg_pt_gp_id);
2517 return count;
2520 SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id, S_IRUGO | S_IWUSR);
2523 * members
2525 static ssize_t target_core_alua_tg_pt_gp_show_attr_members(
2526 struct t10_alua_tg_pt_gp *tg_pt_gp,
2527 char *page)
2529 struct se_port *port;
2530 struct se_portal_group *tpg;
2531 struct se_lun *lun;
2532 struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem;
2533 ssize_t len = 0, cur_len;
2534 unsigned char buf[TG_PT_GROUP_NAME_BUF];
2536 memset(buf, 0, TG_PT_GROUP_NAME_BUF);
2538 spin_lock(&tg_pt_gp->tg_pt_gp_lock);
2539 list_for_each_entry(tg_pt_gp_mem, &tg_pt_gp->tg_pt_gp_mem_list,
2540 tg_pt_gp_mem_list) {
2541 port = tg_pt_gp_mem->tg_pt;
2542 tpg = port->sep_tpg;
2543 lun = port->sep_lun;
2545 cur_len = snprintf(buf, TG_PT_GROUP_NAME_BUF, "%s/%s/tpgt_%hu"
2546 "/%s\n", tpg->se_tpg_tfo->get_fabric_name(),
2547 tpg->se_tpg_tfo->tpg_get_wwn(tpg),
2548 tpg->se_tpg_tfo->tpg_get_tag(tpg),
2549 config_item_name(&lun->lun_group.cg_item));
2550 cur_len++; /* Extra byte for NULL terminator */
2552 if ((cur_len + len) > PAGE_SIZE) {
2553 pr_warn("Ran out of lu_gp_show_attr"
2554 "_members buffer\n");
2555 break;
2557 memcpy(page+len, buf, cur_len);
2558 len += cur_len;
2560 spin_unlock(&tg_pt_gp->tg_pt_gp_lock);
2562 return len;
2565 SE_DEV_ALUA_TG_PT_ATTR_RO(members);
2567 CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp, t10_alua_tg_pt_gp,
2568 tg_pt_gp_group);
2570 static struct configfs_attribute *target_core_alua_tg_pt_gp_attrs[] = {
2571 &target_core_alua_tg_pt_gp_alua_access_state.attr,
2572 &target_core_alua_tg_pt_gp_alua_access_status.attr,
2573 &target_core_alua_tg_pt_gp_alua_access_type.attr,
2574 &target_core_alua_tg_pt_gp_alua_write_metadata.attr,
2575 &target_core_alua_tg_pt_gp_nonop_delay_msecs.attr,
2576 &target_core_alua_tg_pt_gp_trans_delay_msecs.attr,
2577 &target_core_alua_tg_pt_gp_preferred.attr,
2578 &target_core_alua_tg_pt_gp_tg_pt_gp_id.attr,
2579 &target_core_alua_tg_pt_gp_members.attr,
2580 NULL,
2583 static void target_core_alua_tg_pt_gp_release(struct config_item *item)
2585 struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item),
2586 struct t10_alua_tg_pt_gp, tg_pt_gp_group);
2588 core_alua_free_tg_pt_gp(tg_pt_gp);
2591 static struct configfs_item_operations target_core_alua_tg_pt_gp_ops = {
2592 .release = target_core_alua_tg_pt_gp_release,
2593 .show_attribute = target_core_alua_tg_pt_gp_attr_show,
2594 .store_attribute = target_core_alua_tg_pt_gp_attr_store,
2597 static struct config_item_type target_core_alua_tg_pt_gp_cit = {
2598 .ct_item_ops = &target_core_alua_tg_pt_gp_ops,
2599 .ct_attrs = target_core_alua_tg_pt_gp_attrs,
2600 .ct_owner = THIS_MODULE,
2603 /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2605 /* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2607 static struct config_group *target_core_alua_create_tg_pt_gp(
2608 struct config_group *group,
2609 const char *name)
2611 struct t10_alua *alua = container_of(group, struct t10_alua,
2612 alua_tg_pt_gps_group);
2613 struct t10_alua_tg_pt_gp *tg_pt_gp;
2614 struct se_subsystem_dev *su_dev = alua->t10_sub_dev;
2615 struct config_group *alua_tg_pt_gp_cg = NULL;
2616 struct config_item *alua_tg_pt_gp_ci = NULL;
2618 tg_pt_gp = core_alua_allocate_tg_pt_gp(su_dev, name, 0);
2619 if (!tg_pt_gp)
2620 return NULL;
2622 alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group;
2623 alua_tg_pt_gp_ci = &alua_tg_pt_gp_cg->cg_item;
2625 config_group_init_type_name(alua_tg_pt_gp_cg, name,
2626 &target_core_alua_tg_pt_gp_cit);
2628 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
2629 " Group: alua/tg_pt_gps/%s\n",
2630 config_item_name(alua_tg_pt_gp_ci));
2632 return alua_tg_pt_gp_cg;
2635 static void target_core_alua_drop_tg_pt_gp(
2636 struct config_group *group,
2637 struct config_item *item)
2639 struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item),
2640 struct t10_alua_tg_pt_gp, tg_pt_gp_group);
2642 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
2643 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2644 config_item_name(item), tg_pt_gp->tg_pt_gp_id);
2646 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2647 * -> target_core_alua_tg_pt_gp_release().
2649 config_item_put(item);
2652 static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = {
2653 .make_group = &target_core_alua_create_tg_pt_gp,
2654 .drop_item = &target_core_alua_drop_tg_pt_gp,
2657 static struct config_item_type target_core_alua_tg_pt_gps_cit = {
2658 .ct_group_ops = &target_core_alua_tg_pt_gps_group_ops,
2659 .ct_owner = THIS_MODULE,
2662 /* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2664 /* Start functions for struct config_item_type target_core_alua_cit */
2667 * target_core_alua_cit is a ConfigFS group that lives under
2668 * /sys/kernel/config/target/core/alua. There are default groups
2669 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2670 * target_core_alua_cit in target_core_init_configfs() below.
2672 static struct config_item_type target_core_alua_cit = {
2673 .ct_item_ops = NULL,
2674 .ct_attrs = NULL,
2675 .ct_owner = THIS_MODULE,
2678 /* End functions for struct config_item_type target_core_alua_cit */
2680 /* Start functions for struct config_item_type target_core_stat_cit */
2682 static struct config_group *target_core_stat_mkdir(
2683 struct config_group *group,
2684 const char *name)
2686 return ERR_PTR(-ENOSYS);
2689 static void target_core_stat_rmdir(
2690 struct config_group *group,
2691 struct config_item *item)
2693 return;
2696 static struct configfs_group_operations target_core_stat_group_ops = {
2697 .make_group = &target_core_stat_mkdir,
2698 .drop_item = &target_core_stat_rmdir,
2701 static struct config_item_type target_core_stat_cit = {
2702 .ct_group_ops = &target_core_stat_group_ops,
2703 .ct_owner = THIS_MODULE,
2706 /* End functions for struct config_item_type target_core_stat_cit */
2708 /* Start functions for struct config_item_type target_core_hba_cit */
2710 static struct config_group *target_core_make_subdev(
2711 struct config_group *group,
2712 const char *name)
2714 struct t10_alua_tg_pt_gp *tg_pt_gp;
2715 struct se_subsystem_dev *se_dev;
2716 struct se_subsystem_api *t;
2717 struct config_item *hba_ci = &group->cg_item;
2718 struct se_hba *hba = item_to_hba(hba_ci);
2719 struct config_group *dev_cg = NULL, *tg_pt_gp_cg = NULL;
2720 struct config_group *dev_stat_grp = NULL;
2721 int errno = -ENOMEM, ret;
2723 ret = mutex_lock_interruptible(&hba->hba_access_mutex);
2724 if (ret)
2725 return ERR_PTR(ret);
2727 * Locate the struct se_subsystem_api from parent's struct se_hba.
2729 t = hba->transport;
2731 se_dev = kzalloc(sizeof(struct se_subsystem_dev), GFP_KERNEL);
2732 if (!se_dev) {
2733 pr_err("Unable to allocate memory for"
2734 " struct se_subsystem_dev\n");
2735 goto unlock;
2737 INIT_LIST_HEAD(&se_dev->t10_wwn.t10_vpd_list);
2738 spin_lock_init(&se_dev->t10_wwn.t10_vpd_lock);
2739 INIT_LIST_HEAD(&se_dev->t10_pr.registration_list);
2740 INIT_LIST_HEAD(&se_dev->t10_pr.aptpl_reg_list);
2741 spin_lock_init(&se_dev->t10_pr.registration_lock);
2742 spin_lock_init(&se_dev->t10_pr.aptpl_reg_lock);
2743 INIT_LIST_HEAD(&se_dev->t10_alua.tg_pt_gps_list);
2744 spin_lock_init(&se_dev->t10_alua.tg_pt_gps_lock);
2745 spin_lock_init(&se_dev->se_dev_lock);
2746 se_dev->t10_pr.pr_aptpl_buf_len = PR_APTPL_BUF_LEN;
2747 se_dev->t10_wwn.t10_sub_dev = se_dev;
2748 se_dev->t10_alua.t10_sub_dev = se_dev;
2749 se_dev->se_dev_attrib.da_sub_dev = se_dev;
2751 se_dev->se_dev_hba = hba;
2752 dev_cg = &se_dev->se_dev_group;
2754 dev_cg->default_groups = kzalloc(sizeof(struct config_group) * 7,
2755 GFP_KERNEL);
2756 if (!dev_cg->default_groups)
2757 goto out;
2759 * Set se_dev_su_ptr from struct se_subsystem_api returned void ptr
2760 * for ->allocate_virtdevice()
2762 * se_dev->se_dev_ptr will be set after ->create_virtdev()
2763 * has been called successfully in the next level up in the
2764 * configfs tree for device object's struct config_group.
2766 se_dev->se_dev_su_ptr = t->allocate_virtdevice(hba, name);
2767 if (!se_dev->se_dev_su_ptr) {
2768 pr_err("Unable to locate subsystem dependent pointer"
2769 " from allocate_virtdevice()\n");
2770 goto out;
2773 config_group_init_type_name(&se_dev->se_dev_group, name,
2774 &target_core_dev_cit);
2775 config_group_init_type_name(&se_dev->se_dev_attrib.da_group, "attrib",
2776 &target_core_dev_attrib_cit);
2777 config_group_init_type_name(&se_dev->se_dev_pr_group, "pr",
2778 &target_core_dev_pr_cit);
2779 config_group_init_type_name(&se_dev->t10_wwn.t10_wwn_group, "wwn",
2780 &target_core_dev_wwn_cit);
2781 config_group_init_type_name(&se_dev->t10_alua.alua_tg_pt_gps_group,
2782 "alua", &target_core_alua_tg_pt_gps_cit);
2783 config_group_init_type_name(&se_dev->dev_stat_grps.stat_group,
2784 "statistics", &target_core_stat_cit);
2786 dev_cg->default_groups[0] = &se_dev->se_dev_attrib.da_group;
2787 dev_cg->default_groups[1] = &se_dev->se_dev_pr_group;
2788 dev_cg->default_groups[2] = &se_dev->t10_wwn.t10_wwn_group;
2789 dev_cg->default_groups[3] = &se_dev->t10_alua.alua_tg_pt_gps_group;
2790 dev_cg->default_groups[4] = &se_dev->dev_stat_grps.stat_group;
2791 dev_cg->default_groups[5] = NULL;
2793 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
2795 tg_pt_gp = core_alua_allocate_tg_pt_gp(se_dev, "default_tg_pt_gp", 1);
2796 if (!tg_pt_gp)
2797 goto out;
2799 tg_pt_gp_cg = &se_dev->t10_alua.alua_tg_pt_gps_group;
2800 tg_pt_gp_cg->default_groups = kzalloc(sizeof(struct config_group) * 2,
2801 GFP_KERNEL);
2802 if (!tg_pt_gp_cg->default_groups) {
2803 pr_err("Unable to allocate tg_pt_gp_cg->"
2804 "default_groups\n");
2805 goto out;
2808 config_group_init_type_name(&tg_pt_gp->tg_pt_gp_group,
2809 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit);
2810 tg_pt_gp_cg->default_groups[0] = &tg_pt_gp->tg_pt_gp_group;
2811 tg_pt_gp_cg->default_groups[1] = NULL;
2812 se_dev->t10_alua.default_tg_pt_gp = tg_pt_gp;
2814 * Add core/$HBA/$DEV/statistics/ default groups
2816 dev_stat_grp = &se_dev->dev_stat_grps.stat_group;
2817 dev_stat_grp->default_groups = kzalloc(sizeof(struct config_group) * 4,
2818 GFP_KERNEL);
2819 if (!dev_stat_grp->default_groups) {
2820 pr_err("Unable to allocate dev_stat_grp->default_groups\n");
2821 goto out;
2823 target_stat_setup_dev_default_groups(se_dev);
2825 pr_debug("Target_Core_ConfigFS: Allocated struct se_subsystem_dev:"
2826 " %p se_dev_su_ptr: %p\n", se_dev, se_dev->se_dev_su_ptr);
2828 mutex_unlock(&hba->hba_access_mutex);
2829 return &se_dev->se_dev_group;
2830 out:
2831 if (se_dev->t10_alua.default_tg_pt_gp) {
2832 core_alua_free_tg_pt_gp(se_dev->t10_alua.default_tg_pt_gp);
2833 se_dev->t10_alua.default_tg_pt_gp = NULL;
2835 if (dev_stat_grp)
2836 kfree(dev_stat_grp->default_groups);
2837 if (tg_pt_gp_cg)
2838 kfree(tg_pt_gp_cg->default_groups);
2839 if (dev_cg)
2840 kfree(dev_cg->default_groups);
2841 if (se_dev->se_dev_su_ptr)
2842 t->free_device(se_dev->se_dev_su_ptr);
2843 kfree(se_dev);
2844 unlock:
2845 mutex_unlock(&hba->hba_access_mutex);
2846 return ERR_PTR(errno);
2849 static void target_core_drop_subdev(
2850 struct config_group *group,
2851 struct config_item *item)
2853 struct se_subsystem_dev *se_dev = container_of(to_config_group(item),
2854 struct se_subsystem_dev, se_dev_group);
2855 struct se_hba *hba;
2856 struct config_item *df_item;
2857 struct config_group *dev_cg, *tg_pt_gp_cg, *dev_stat_grp;
2858 int i;
2860 hba = item_to_hba(&se_dev->se_dev_hba->hba_group.cg_item);
2862 mutex_lock(&hba->hba_access_mutex);
2864 dev_stat_grp = &se_dev->dev_stat_grps.stat_group;
2865 for (i = 0; dev_stat_grp->default_groups[i]; i++) {
2866 df_item = &dev_stat_grp->default_groups[i]->cg_item;
2867 dev_stat_grp->default_groups[i] = NULL;
2868 config_item_put(df_item);
2870 kfree(dev_stat_grp->default_groups);
2872 tg_pt_gp_cg = &se_dev->t10_alua.alua_tg_pt_gps_group;
2873 for (i = 0; tg_pt_gp_cg->default_groups[i]; i++) {
2874 df_item = &tg_pt_gp_cg->default_groups[i]->cg_item;
2875 tg_pt_gp_cg->default_groups[i] = NULL;
2876 config_item_put(df_item);
2878 kfree(tg_pt_gp_cg->default_groups);
2880 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2881 * directly from target_core_alua_tg_pt_gp_release().
2883 se_dev->t10_alua.default_tg_pt_gp = NULL;
2885 dev_cg = &se_dev->se_dev_group;
2886 for (i = 0; dev_cg->default_groups[i]; i++) {
2887 df_item = &dev_cg->default_groups[i]->cg_item;
2888 dev_cg->default_groups[i] = NULL;
2889 config_item_put(df_item);
2892 * The releasing of se_dev and associated se_dev->se_dev_ptr is done
2893 * from target_core_dev_item_ops->release() ->target_core_dev_release().
2895 config_item_put(item);
2896 mutex_unlock(&hba->hba_access_mutex);
2899 static struct configfs_group_operations target_core_hba_group_ops = {
2900 .make_group = target_core_make_subdev,
2901 .drop_item = target_core_drop_subdev,
2904 CONFIGFS_EATTR_STRUCT(target_core_hba, se_hba);
2905 #define SE_HBA_ATTR(_name, _mode) \
2906 static struct target_core_hba_attribute \
2907 target_core_hba_##_name = \
2908 __CONFIGFS_EATTR(_name, _mode, \
2909 target_core_hba_show_attr_##_name, \
2910 target_core_hba_store_attr_##_name);
2912 #define SE_HBA_ATTR_RO(_name) \
2913 static struct target_core_hba_attribute \
2914 target_core_hba_##_name = \
2915 __CONFIGFS_EATTR_RO(_name, \
2916 target_core_hba_show_attr_##_name);
2918 static ssize_t target_core_hba_show_attr_hba_info(
2919 struct se_hba *hba,
2920 char *page)
2922 return sprintf(page, "HBA Index: %d plugin: %s version: %s\n",
2923 hba->hba_id, hba->transport->name,
2924 TARGET_CORE_CONFIGFS_VERSION);
2927 SE_HBA_ATTR_RO(hba_info);
2929 static ssize_t target_core_hba_show_attr_hba_mode(struct se_hba *hba,
2930 char *page)
2932 int hba_mode = 0;
2934 if (hba->hba_flags & HBA_FLAGS_PSCSI_MODE)
2935 hba_mode = 1;
2937 return sprintf(page, "%d\n", hba_mode);
2940 static ssize_t target_core_hba_store_attr_hba_mode(struct se_hba *hba,
2941 const char *page, size_t count)
2943 struct se_subsystem_api *transport = hba->transport;
2944 unsigned long mode_flag;
2945 int ret;
2947 if (transport->pmode_enable_hba == NULL)
2948 return -EINVAL;
2950 ret = strict_strtoul(page, 0, &mode_flag);
2951 if (ret < 0) {
2952 pr_err("Unable to extract hba mode flag: %d\n", ret);
2953 return -EINVAL;
2956 spin_lock(&hba->device_lock);
2957 if (!list_empty(&hba->hba_dev_list)) {
2958 pr_err("Unable to set hba_mode with active devices\n");
2959 spin_unlock(&hba->device_lock);
2960 return -EINVAL;
2962 spin_unlock(&hba->device_lock);
2964 ret = transport->pmode_enable_hba(hba, mode_flag);
2965 if (ret < 0)
2966 return -EINVAL;
2967 if (ret > 0)
2968 hba->hba_flags |= HBA_FLAGS_PSCSI_MODE;
2969 else if (ret == 0)
2970 hba->hba_flags &= ~HBA_FLAGS_PSCSI_MODE;
2972 return count;
2975 SE_HBA_ATTR(hba_mode, S_IRUGO | S_IWUSR);
2977 CONFIGFS_EATTR_OPS(target_core_hba, se_hba, hba_group);
2979 static void target_core_hba_release(struct config_item *item)
2981 struct se_hba *hba = container_of(to_config_group(item),
2982 struct se_hba, hba_group);
2983 core_delete_hba(hba);
2986 static struct configfs_attribute *target_core_hba_attrs[] = {
2987 &target_core_hba_hba_info.attr,
2988 &target_core_hba_hba_mode.attr,
2989 NULL,
2992 static struct configfs_item_operations target_core_hba_item_ops = {
2993 .release = target_core_hba_release,
2994 .show_attribute = target_core_hba_attr_show,
2995 .store_attribute = target_core_hba_attr_store,
2998 static struct config_item_type target_core_hba_cit = {
2999 .ct_item_ops = &target_core_hba_item_ops,
3000 .ct_group_ops = &target_core_hba_group_ops,
3001 .ct_attrs = target_core_hba_attrs,
3002 .ct_owner = THIS_MODULE,
3005 static struct config_group *target_core_call_addhbatotarget(
3006 struct config_group *group,
3007 const char *name)
3009 char *se_plugin_str, *str, *str2;
3010 struct se_hba *hba;
3011 char buf[TARGET_CORE_NAME_MAX_LEN];
3012 unsigned long plugin_dep_id = 0;
3013 int ret;
3015 memset(buf, 0, TARGET_CORE_NAME_MAX_LEN);
3016 if (strlen(name) >= TARGET_CORE_NAME_MAX_LEN) {
3017 pr_err("Passed *name strlen(): %d exceeds"
3018 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name),
3019 TARGET_CORE_NAME_MAX_LEN);
3020 return ERR_PTR(-ENAMETOOLONG);
3022 snprintf(buf, TARGET_CORE_NAME_MAX_LEN, "%s", name);
3024 str = strstr(buf, "_");
3025 if (!str) {
3026 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
3027 return ERR_PTR(-EINVAL);
3029 se_plugin_str = buf;
3031 * Special case for subsystem plugins that have "_" in their names.
3032 * Namely rd_direct and rd_mcp..
3034 str2 = strstr(str+1, "_");
3035 if (str2) {
3036 *str2 = '\0'; /* Terminate for *se_plugin_str */
3037 str2++; /* Skip to start of plugin dependent ID */
3038 str = str2;
3039 } else {
3040 *str = '\0'; /* Terminate for *se_plugin_str */
3041 str++; /* Skip to start of plugin dependent ID */
3044 ret = strict_strtoul(str, 0, &plugin_dep_id);
3045 if (ret < 0) {
3046 pr_err("strict_strtoul() returned %d for"
3047 " plugin_dep_id\n", ret);
3048 return ERR_PTR(-EINVAL);
3051 * Load up TCM subsystem plugins if they have not already been loaded.
3053 transport_subsystem_check_init();
3055 hba = core_alloc_hba(se_plugin_str, plugin_dep_id, 0);
3056 if (IS_ERR(hba))
3057 return ERR_CAST(hba);
3059 config_group_init_type_name(&hba->hba_group, name,
3060 &target_core_hba_cit);
3062 return &hba->hba_group;
3065 static void target_core_call_delhbafromtarget(
3066 struct config_group *group,
3067 struct config_item *item)
3070 * core_delete_hba() is called from target_core_hba_item_ops->release()
3071 * -> target_core_hba_release()
3073 config_item_put(item);
3076 static struct configfs_group_operations target_core_group_ops = {
3077 .make_group = target_core_call_addhbatotarget,
3078 .drop_item = target_core_call_delhbafromtarget,
3081 static struct config_item_type target_core_cit = {
3082 .ct_item_ops = NULL,
3083 .ct_group_ops = &target_core_group_ops,
3084 .ct_attrs = NULL,
3085 .ct_owner = THIS_MODULE,
3088 /* Stop functions for struct config_item_type target_core_hba_cit */
3090 static int __init target_core_init_configfs(void)
3092 struct config_group *target_cg, *hba_cg = NULL, *alua_cg = NULL;
3093 struct config_group *lu_gp_cg = NULL;
3094 struct configfs_subsystem *subsys;
3095 struct t10_alua_lu_gp *lu_gp;
3096 int ret;
3098 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
3099 " Engine: %s on %s/%s on "UTS_RELEASE"\n",
3100 TARGET_CORE_VERSION, utsname()->sysname, utsname()->machine);
3102 subsys = target_core_subsystem[0];
3103 config_group_init(&subsys->su_group);
3104 mutex_init(&subsys->su_mutex);
3106 ret = init_se_kmem_caches();
3107 if (ret < 0)
3108 return ret;
3110 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
3111 * and ALUA Logical Unit Group and Target Port Group infrastructure.
3113 target_cg = &subsys->su_group;
3114 target_cg->default_groups = kzalloc(sizeof(struct config_group) * 2,
3115 GFP_KERNEL);
3116 if (!target_cg->default_groups) {
3117 pr_err("Unable to allocate target_cg->default_groups\n");
3118 goto out_global;
3121 config_group_init_type_name(&target_core_hbagroup,
3122 "core", &target_core_cit);
3123 target_cg->default_groups[0] = &target_core_hbagroup;
3124 target_cg->default_groups[1] = NULL;
3126 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
3128 hba_cg = &target_core_hbagroup;
3129 hba_cg->default_groups = kzalloc(sizeof(struct config_group) * 2,
3130 GFP_KERNEL);
3131 if (!hba_cg->default_groups) {
3132 pr_err("Unable to allocate hba_cg->default_groups\n");
3133 goto out_global;
3135 config_group_init_type_name(&alua_group,
3136 "alua", &target_core_alua_cit);
3137 hba_cg->default_groups[0] = &alua_group;
3138 hba_cg->default_groups[1] = NULL;
3140 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
3141 * groups under /sys/kernel/config/target/core/alua/
3143 alua_cg = &alua_group;
3144 alua_cg->default_groups = kzalloc(sizeof(struct config_group) * 2,
3145 GFP_KERNEL);
3146 if (!alua_cg->default_groups) {
3147 pr_err("Unable to allocate alua_cg->default_groups\n");
3148 goto out_global;
3151 config_group_init_type_name(&alua_lu_gps_group,
3152 "lu_gps", &target_core_alua_lu_gps_cit);
3153 alua_cg->default_groups[0] = &alua_lu_gps_group;
3154 alua_cg->default_groups[1] = NULL;
3156 * Add core/alua/lu_gps/default_lu_gp
3158 lu_gp = core_alua_allocate_lu_gp("default_lu_gp", 1);
3159 if (IS_ERR(lu_gp))
3160 goto out_global;
3162 lu_gp_cg = &alua_lu_gps_group;
3163 lu_gp_cg->default_groups = kzalloc(sizeof(struct config_group) * 2,
3164 GFP_KERNEL);
3165 if (!lu_gp_cg->default_groups) {
3166 pr_err("Unable to allocate lu_gp_cg->default_groups\n");
3167 goto out_global;
3170 config_group_init_type_name(&lu_gp->lu_gp_group, "default_lu_gp",
3171 &target_core_alua_lu_gp_cit);
3172 lu_gp_cg->default_groups[0] = &lu_gp->lu_gp_group;
3173 lu_gp_cg->default_groups[1] = NULL;
3174 default_lu_gp = lu_gp;
3176 * Register the target_core_mod subsystem with configfs.
3178 ret = configfs_register_subsystem(subsys);
3179 if (ret < 0) {
3180 pr_err("Error %d while registering subsystem %s\n",
3181 ret, subsys->su_group.cg_item.ci_namebuf);
3182 goto out_global;
3184 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
3185 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION" on %s/%s"
3186 " on "UTS_RELEASE"\n", utsname()->sysname, utsname()->machine);
3188 * Register built-in RAMDISK subsystem logic for virtual LUN 0
3190 ret = rd_module_init();
3191 if (ret < 0)
3192 goto out;
3194 if (core_dev_setup_virtual_lun0() < 0)
3195 goto out;
3197 return 0;
3199 out:
3200 configfs_unregister_subsystem(subsys);
3201 core_dev_release_virtual_lun0();
3202 rd_module_exit();
3203 out_global:
3204 if (default_lu_gp) {
3205 core_alua_free_lu_gp(default_lu_gp);
3206 default_lu_gp = NULL;
3208 if (lu_gp_cg)
3209 kfree(lu_gp_cg->default_groups);
3210 if (alua_cg)
3211 kfree(alua_cg->default_groups);
3212 if (hba_cg)
3213 kfree(hba_cg->default_groups);
3214 kfree(target_cg->default_groups);
3215 release_se_kmem_caches();
3216 return ret;
3219 static void __exit target_core_exit_configfs(void)
3221 struct configfs_subsystem *subsys;
3222 struct config_group *hba_cg, *alua_cg, *lu_gp_cg;
3223 struct config_item *item;
3224 int i;
3226 subsys = target_core_subsystem[0];
3228 lu_gp_cg = &alua_lu_gps_group;
3229 for (i = 0; lu_gp_cg->default_groups[i]; i++) {
3230 item = &lu_gp_cg->default_groups[i]->cg_item;
3231 lu_gp_cg->default_groups[i] = NULL;
3232 config_item_put(item);
3234 kfree(lu_gp_cg->default_groups);
3235 lu_gp_cg->default_groups = NULL;
3237 alua_cg = &alua_group;
3238 for (i = 0; alua_cg->default_groups[i]; i++) {
3239 item = &alua_cg->default_groups[i]->cg_item;
3240 alua_cg->default_groups[i] = NULL;
3241 config_item_put(item);
3243 kfree(alua_cg->default_groups);
3244 alua_cg->default_groups = NULL;
3246 hba_cg = &target_core_hbagroup;
3247 for (i = 0; hba_cg->default_groups[i]; i++) {
3248 item = &hba_cg->default_groups[i]->cg_item;
3249 hba_cg->default_groups[i] = NULL;
3250 config_item_put(item);
3252 kfree(hba_cg->default_groups);
3253 hba_cg->default_groups = NULL;
3255 * We expect subsys->su_group.default_groups to be released
3256 * by configfs subsystem provider logic..
3258 configfs_unregister_subsystem(subsys);
3259 kfree(subsys->su_group.default_groups);
3261 core_alua_free_lu_gp(default_lu_gp);
3262 default_lu_gp = NULL;
3264 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
3265 " Infrastructure\n");
3267 core_dev_release_virtual_lun0();
3268 rd_module_exit();
3269 release_se_kmem_caches();
3272 MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3273 MODULE_AUTHOR("nab@Linux-iSCSI.org");
3274 MODULE_LICENSE("GPL");
3276 module_init(target_core_init_configfs);
3277 module_exit(target_core_exit_configfs);