Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Filename: target_core_fabric_configfs.c |
| 3 | * |
| 4 | * This file contains generic fabric module configfs infrastructure for |
| 5 | * TCM v4.x code |
| 6 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 7 | * (c) Copyright 2010-2013 Datera, Inc. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 8 | * |
Nicholas Bellinger | fd9a11d | 2012-11-09 14:51:48 -0800 | [diff] [blame] | 9 | * Nicholas A. Bellinger <nab@linux-iscsi.org> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | #include <linux/module.h> |
| 23 | #include <linux/moduleparam.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 24 | #include <linux/utsname.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/fs.h> |
| 27 | #include <linux/namei.h> |
| 28 | #include <linux/slab.h> |
| 29 | #include <linux/types.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/unistd.h> |
| 32 | #include <linux/string.h> |
| 33 | #include <linux/syscalls.h> |
| 34 | #include <linux/configfs.h> |
| 35 | |
| 36 | #include <target/target_core_base.h> |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 37 | #include <target/target_core_fabric.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 38 | |
Christoph Hellwig | e26d99a | 2011-11-14 12:30:30 -0500 | [diff] [blame] | 39 | #include "target_core_internal.h" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 40 | #include "target_core_alua.h" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 41 | #include "target_core_pr.h" |
| 42 | |
| 43 | #define TF_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \ |
| 44 | static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \ |
| 45 | { \ |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 46 | struct config_item_type *cit = &tf->tf_##_name##_cit; \ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 47 | \ |
| 48 | cit->ct_item_ops = _item_ops; \ |
| 49 | cit->ct_group_ops = _group_ops; \ |
| 50 | cit->ct_attrs = _attrs; \ |
Christoph Hellwig | 0dc2e8d | 2015-05-03 08:50:54 +0200 | [diff] [blame] | 51 | cit->ct_owner = tf->tf_ops->module; \ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 52 | pr_debug("Setup generic %s\n", __stringify(_name)); \ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 55 | #define TF_CIT_SETUP_DRV(_name, _item_ops, _group_ops) \ |
| 56 | static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \ |
| 57 | { \ |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 58 | struct config_item_type *cit = &tf->tf_##_name##_cit; \ |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 59 | struct configfs_attribute **attrs = tf->tf_ops->tfc_##_name##_attrs; \ |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 60 | \ |
| 61 | cit->ct_item_ops = _item_ops; \ |
| 62 | cit->ct_group_ops = _group_ops; \ |
| 63 | cit->ct_attrs = attrs; \ |
Christoph Hellwig | 0dc2e8d | 2015-05-03 08:50:54 +0200 | [diff] [blame] | 64 | cit->ct_owner = tf->tf_ops->module; \ |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 65 | pr_debug("Setup generic %s\n", __stringify(_name)); \ |
| 66 | } |
| 67 | |
Nicholas Bellinger | 9ae0e9ad | 2017-06-01 03:11:18 -0700 | [diff] [blame] | 68 | static struct configfs_item_operations target_fabric_port_item_ops; |
| 69 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 70 | /* Start of tfc_tpg_mappedlun_cit */ |
| 71 | |
| 72 | static int target_fabric_mappedlun_link( |
| 73 | struct config_item *lun_acl_ci, |
| 74 | struct config_item *lun_ci) |
| 75 | { |
| 76 | struct se_dev_entry *deve; |
Nicholas Bellinger | 9ae0e9ad | 2017-06-01 03:11:18 -0700 | [diff] [blame] | 77 | struct se_lun *lun; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 78 | struct se_lun_acl *lacl = container_of(to_config_group(lun_acl_ci), |
| 79 | struct se_lun_acl, se_lun_group); |
| 80 | struct se_portal_group *se_tpg; |
| 81 | struct config_item *nacl_ci, *tpg_ci, *tpg_ci_s, *wwn_ci, *wwn_ci_s; |
Andy Grover | 03a68b4 | 2016-02-25 15:14:32 -0800 | [diff] [blame] | 82 | bool lun_access_ro; |
Nicholas Bellinger | 0ff8754 | 2012-12-04 23:43:57 -0800 | [diff] [blame] | 83 | |
Nicholas Bellinger | 9ae0e9ad | 2017-06-01 03:11:18 -0700 | [diff] [blame] | 84 | if (!lun_ci->ci_type || |
| 85 | lun_ci->ci_type->ct_item_ops != &target_fabric_port_item_ops) { |
| 86 | pr_err("Bad lun_ci, not a valid lun_ci pointer: %p\n", lun_ci); |
Nicholas Bellinger | 0ff8754 | 2012-12-04 23:43:57 -0800 | [diff] [blame] | 87 | return -EFAULT; |
| 88 | } |
Nicholas Bellinger | 9ae0e9ad | 2017-06-01 03:11:18 -0700 | [diff] [blame] | 89 | lun = container_of(to_config_group(lun_ci), struct se_lun, lun_group); |
| 90 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 91 | /* |
| 92 | * Ensure that the source port exists |
| 93 | */ |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 94 | if (!lun->lun_se_dev) { |
| 95 | pr_err("Source se_lun->lun_se_dev does not exist\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 96 | return -EINVAL; |
| 97 | } |
Nicholas Bellinger | 49cb77e | 2017-03-27 16:12:43 -0700 | [diff] [blame] | 98 | if (lun->lun_shutdown) { |
| 99 | pr_err("Unable to create mappedlun symlink because" |
| 100 | " lun->lun_shutdown=true\n"); |
| 101 | return -EINVAL; |
| 102 | } |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 103 | se_tpg = lun->lun_tpg; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 104 | |
| 105 | nacl_ci = &lun_acl_ci->ci_parent->ci_group->cg_item; |
| 106 | tpg_ci = &nacl_ci->ci_group->cg_item; |
| 107 | wwn_ci = &tpg_ci->ci_group->cg_item; |
| 108 | tpg_ci_s = &lun_ci->ci_parent->ci_group->cg_item; |
| 109 | wwn_ci_s = &tpg_ci_s->ci_group->cg_item; |
| 110 | /* |
| 111 | * Make sure the SymLink is going to the same $FABRIC/$WWN/tpgt_$TPGT |
| 112 | */ |
| 113 | if (strcmp(config_item_name(wwn_ci), config_item_name(wwn_ci_s))) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 114 | pr_err("Illegal Initiator ACL SymLink outside of %s\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 115 | config_item_name(wwn_ci)); |
| 116 | return -EINVAL; |
| 117 | } |
| 118 | if (strcmp(config_item_name(tpg_ci), config_item_name(tpg_ci_s))) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 119 | pr_err("Illegal Initiator ACL Symlink outside of %s" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 120 | " TPGT: %s\n", config_item_name(wwn_ci), |
| 121 | config_item_name(tpg_ci)); |
| 122 | return -EINVAL; |
| 123 | } |
| 124 | /* |
| 125 | * If this struct se_node_acl was dynamically generated with |
Andy Grover | 03a68b4 | 2016-02-25 15:14:32 -0800 | [diff] [blame] | 126 | * tpg_1/attrib/generate_node_acls=1, use the existing |
| 127 | * deve->lun_access_ro value, which will be true when |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 128 | * tpg_1/attrib/demo_mode_write_protect=1 |
| 129 | */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 130 | rcu_read_lock(); |
| 131 | deve = target_nacl_find_deve(lacl->se_lun_nacl, lacl->mapped_lun); |
| 132 | if (deve) |
Andy Grover | 03a68b4 | 2016-02-25 15:14:32 -0800 | [diff] [blame] | 133 | lun_access_ro = deve->lun_access_ro; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 134 | else |
Andy Grover | 03a68b4 | 2016-02-25 15:14:32 -0800 | [diff] [blame] | 135 | lun_access_ro = |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 136 | (se_tpg->se_tpg_tfo->tpg_check_prod_mode_write_protect( |
Andy Grover | 03a68b4 | 2016-02-25 15:14:32 -0800 | [diff] [blame] | 137 | se_tpg)) ? true : false; |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 138 | rcu_read_unlock(); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 139 | /* |
| 140 | * Determine the actual mapped LUN value user wants.. |
| 141 | * |
| 142 | * This value is what the SCSI Initiator actually sees the |
Nicholas Bellinger | 6bb8261 | 2015-05-10 19:31:10 -0700 | [diff] [blame] | 143 | * $FABRIC/$WWPN/$TPGT/lun/lun_* as on their SCSI Initiator Ports. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 144 | */ |
Andy Grover | 03a68b4 | 2016-02-25 15:14:32 -0800 | [diff] [blame] | 145 | return core_dev_add_initiator_node_lun_acl(se_tpg, lacl, lun, lun_access_ro); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 146 | } |
| 147 | |
Andrzej Pietrasiewicz | e16769d | 2016-11-28 13:22:42 +0100 | [diff] [blame] | 148 | static void target_fabric_mappedlun_unlink( |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 149 | struct config_item *lun_acl_ci, |
| 150 | struct config_item *lun_ci) |
| 151 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 152 | struct se_lun_acl *lacl = container_of(to_config_group(lun_acl_ci), |
| 153 | struct se_lun_acl, se_lun_group); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 154 | struct se_lun *lun = container_of(to_config_group(lun_ci), |
| 155 | struct se_lun, lun_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 156 | |
Andrzej Pietrasiewicz | e16769d | 2016-11-28 13:22:42 +0100 | [diff] [blame] | 157 | core_dev_del_initiator_node_lun_acl(lun, lacl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 160 | static struct se_lun_acl *item_to_lun_acl(struct config_item *item) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 161 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 162 | return container_of(to_config_group(item), struct se_lun_acl, |
| 163 | se_lun_group); |
| 164 | } |
| 165 | |
| 166 | static ssize_t target_fabric_mappedlun_write_protect_show( |
| 167 | struct config_item *item, char *page) |
| 168 | { |
| 169 | struct se_lun_acl *lacl = item_to_lun_acl(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 170 | struct se_node_acl *se_nacl = lacl->se_lun_nacl; |
| 171 | struct se_dev_entry *deve; |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 172 | ssize_t len = 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 173 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 174 | rcu_read_lock(); |
| 175 | deve = target_nacl_find_deve(se_nacl, lacl->mapped_lun); |
| 176 | if (deve) { |
Andy Grover | 03a68b4 | 2016-02-25 15:14:32 -0800 | [diff] [blame] | 177 | len = sprintf(page, "%d\n", deve->lun_access_ro); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 178 | } |
| 179 | rcu_read_unlock(); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 180 | |
| 181 | return len; |
| 182 | } |
| 183 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 184 | static ssize_t target_fabric_mappedlun_write_protect_store( |
| 185 | struct config_item *item, const char *page, size_t count) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 186 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 187 | struct se_lun_acl *lacl = item_to_lun_acl(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 188 | struct se_node_acl *se_nacl = lacl->se_lun_nacl; |
| 189 | struct se_portal_group *se_tpg = se_nacl->se_tpg; |
Andy Grover | 03a68b4 | 2016-02-25 15:14:32 -0800 | [diff] [blame] | 190 | unsigned long wp; |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 191 | int ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 192 | |
Andy Grover | 03a68b4 | 2016-02-25 15:14:32 -0800 | [diff] [blame] | 193 | ret = kstrtoul(page, 0, &wp); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 194 | if (ret) |
| 195 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 196 | |
Andy Grover | 03a68b4 | 2016-02-25 15:14:32 -0800 | [diff] [blame] | 197 | if ((wp != 1) && (wp != 0)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 198 | return -EINVAL; |
| 199 | |
Andy Grover | 03a68b4 | 2016-02-25 15:14:32 -0800 | [diff] [blame] | 200 | /* wp=1 means lun_access_ro=true */ |
| 201 | core_update_device_list_access(lacl->mapped_lun, wp, lacl->se_lun_nacl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 202 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 203 | pr_debug("%s_ConfigFS: Changed Initiator ACL: %s" |
Hannes Reinecke | f2d3068 | 2015-06-10 08:41:22 +0200 | [diff] [blame] | 204 | " Mapped LUN: %llu Write Protect bit to %s\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 205 | se_tpg->se_tpg_tfo->get_fabric_name(), |
Andy Grover | 03a68b4 | 2016-02-25 15:14:32 -0800 | [diff] [blame] | 206 | se_nacl->initiatorname, lacl->mapped_lun, (wp) ? "ON" : "OFF"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 207 | |
| 208 | return count; |
| 209 | |
| 210 | } |
| 211 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 212 | CONFIGFS_ATTR(target_fabric_mappedlun_, write_protect); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 213 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 214 | static struct configfs_attribute *target_fabric_mappedlun_attrs[] = { |
| 215 | &target_fabric_mappedlun_attr_write_protect, |
| 216 | NULL, |
| 217 | }; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 218 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 219 | static void target_fabric_mappedlun_release(struct config_item *item) |
| 220 | { |
| 221 | struct se_lun_acl *lacl = container_of(to_config_group(item), |
| 222 | struct se_lun_acl, se_lun_group); |
| 223 | struct se_portal_group *se_tpg = lacl->se_lun_nacl->se_tpg; |
| 224 | |
| 225 | core_dev_free_initiator_node_lun_acl(se_tpg, lacl); |
| 226 | } |
| 227 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 228 | static struct configfs_item_operations target_fabric_mappedlun_item_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 229 | .release = target_fabric_mappedlun_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 230 | .allow_link = target_fabric_mappedlun_link, |
| 231 | .drop_link = target_fabric_mappedlun_unlink, |
| 232 | }; |
| 233 | |
| 234 | TF_CIT_SETUP(tpg_mappedlun, &target_fabric_mappedlun_item_ops, NULL, |
| 235 | target_fabric_mappedlun_attrs); |
| 236 | |
| 237 | /* End of tfc_tpg_mappedlun_cit */ |
| 238 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 239 | /* Start of tfc_tpg_mappedlun_port_cit */ |
| 240 | |
| 241 | static struct config_group *target_core_mappedlun_stat_mkdir( |
| 242 | struct config_group *group, |
| 243 | const char *name) |
| 244 | { |
| 245 | return ERR_PTR(-ENOSYS); |
| 246 | } |
| 247 | |
| 248 | static void target_core_mappedlun_stat_rmdir( |
| 249 | struct config_group *group, |
| 250 | struct config_item *item) |
| 251 | { |
| 252 | return; |
| 253 | } |
| 254 | |
| 255 | static struct configfs_group_operations target_fabric_mappedlun_stat_group_ops = { |
| 256 | .make_group = target_core_mappedlun_stat_mkdir, |
| 257 | .drop_item = target_core_mappedlun_stat_rmdir, |
| 258 | }; |
| 259 | |
| 260 | TF_CIT_SETUP(tpg_mappedlun_stat, NULL, &target_fabric_mappedlun_stat_group_ops, |
| 261 | NULL); |
| 262 | |
| 263 | /* End of tfc_tpg_mappedlun_port_cit */ |
| 264 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 265 | TF_CIT_SETUP_DRV(tpg_nacl_attrib, NULL, NULL); |
| 266 | TF_CIT_SETUP_DRV(tpg_nacl_auth, NULL, NULL); |
| 267 | TF_CIT_SETUP_DRV(tpg_nacl_param, NULL, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 268 | |
| 269 | /* Start of tfc_tpg_nacl_base_cit */ |
| 270 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 271 | static struct config_group *target_fabric_make_mappedlun( |
| 272 | struct config_group *group, |
| 273 | const char *name) |
| 274 | { |
| 275 | struct se_node_acl *se_nacl = container_of(group, |
| 276 | struct se_node_acl, acl_group); |
| 277 | struct se_portal_group *se_tpg = se_nacl->se_tpg; |
| 278 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
Joern Engel | da0abae | 2014-09-02 17:49:57 -0400 | [diff] [blame] | 279 | struct se_lun_acl *lacl = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 280 | char *buf; |
Hannes Reinecke | f2d3068 | 2015-06-10 08:41:22 +0200 | [diff] [blame] | 281 | unsigned long long mapped_lun; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 282 | int ret = 0; |
| 283 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 284 | buf = kzalloc(strlen(name) + 1, GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 285 | if (!buf) { |
| 286 | pr_err("Unable to allocate memory for name buf\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 287 | return ERR_PTR(-ENOMEM); |
| 288 | } |
| 289 | snprintf(buf, strlen(name) + 1, "%s", name); |
| 290 | /* |
| 291 | * Make sure user is creating iscsi/$IQN/$TPGT/acls/$INITIATOR/lun_$ID. |
| 292 | */ |
| 293 | if (strstr(buf, "lun_") != buf) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 294 | pr_err("Unable to locate \"lun_\" from buf: %s" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 295 | " name: %s\n", buf, name); |
| 296 | ret = -EINVAL; |
| 297 | goto out; |
| 298 | } |
| 299 | /* |
| 300 | * Determine the Mapped LUN value. This is what the SCSI Initiator |
| 301 | * Port will actually see. |
| 302 | */ |
Hannes Reinecke | f2d3068 | 2015-06-10 08:41:22 +0200 | [diff] [blame] | 303 | ret = kstrtoull(buf + 4, 0, &mapped_lun); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 304 | if (ret) |
| 305 | goto out; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 306 | |
Nicholas Bellinger | fcf2948 | 2013-02-18 18:00:33 -0800 | [diff] [blame] | 307 | lacl = core_dev_init_initiator_node_lun_acl(se_tpg, se_nacl, |
| 308 | mapped_lun, &ret); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 309 | if (!lacl) { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 310 | ret = -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 311 | goto out; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 314 | config_group_init_type_name(&lacl->se_lun_group, name, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 315 | &tf->tf_tpg_mappedlun_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 316 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 317 | config_group_init_type_name(&lacl->ml_stat_grps.stat_group, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 318 | "statistics", &tf->tf_tpg_mappedlun_stat_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 319 | configfs_add_default_group(&lacl->ml_stat_grps.stat_group, |
| 320 | &lacl->se_lun_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 321 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 322 | target_stat_setup_mappedlun_default_groups(lacl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 323 | |
| 324 | kfree(buf); |
| 325 | return &lacl->se_lun_group; |
| 326 | out: |
Joern Engel | da0abae | 2014-09-02 17:49:57 -0400 | [diff] [blame] | 327 | kfree(lacl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 328 | kfree(buf); |
| 329 | return ERR_PTR(ret); |
| 330 | } |
| 331 | |
| 332 | static void target_fabric_drop_mappedlun( |
| 333 | struct config_group *group, |
| 334 | struct config_item *item) |
| 335 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 336 | struct se_lun_acl *lacl = container_of(to_config_group(item), |
| 337 | struct se_lun_acl, se_lun_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 338 | |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 339 | configfs_remove_default_groups(&lacl->ml_stat_grps.stat_group); |
| 340 | configfs_remove_default_groups(&lacl->se_lun_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 341 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 342 | config_item_put(item); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | static void target_fabric_nacl_base_release(struct config_item *item) |
| 346 | { |
| 347 | struct se_node_acl *se_nacl = container_of(to_config_group(item), |
| 348 | struct se_node_acl, acl_group); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 349 | |
Christoph Hellwig | ce7043f | 2016-03-29 13:03:33 +0200 | [diff] [blame] | 350 | configfs_remove_default_groups(&se_nacl->acl_fabric_stat_group); |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 351 | core_tpg_del_initiator_node_acl(se_nacl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | static struct configfs_item_operations target_fabric_nacl_base_item_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 355 | .release = target_fabric_nacl_base_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 356 | }; |
| 357 | |
| 358 | static struct configfs_group_operations target_fabric_nacl_base_group_ops = { |
| 359 | .make_group = target_fabric_make_mappedlun, |
| 360 | .drop_item = target_fabric_drop_mappedlun, |
| 361 | }; |
| 362 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 363 | TF_CIT_SETUP_DRV(tpg_nacl_base, &target_fabric_nacl_base_item_ops, |
| 364 | &target_fabric_nacl_base_group_ops); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 365 | |
| 366 | /* End of tfc_tpg_nacl_base_cit */ |
| 367 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 368 | /* Start of tfc_node_fabric_stats_cit */ |
| 369 | /* |
| 370 | * This is used as a placeholder for struct se_node_acl->acl_fabric_stat_group |
| 371 | * to allow fabrics access to ->acl_fabric_stat_group->default_groups[] |
| 372 | */ |
| 373 | TF_CIT_SETUP(tpg_nacl_stat, NULL, NULL, NULL); |
| 374 | |
| 375 | /* End of tfc_wwn_fabric_stats_cit */ |
| 376 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 377 | /* Start of tfc_tpg_nacl_cit */ |
| 378 | |
| 379 | static struct config_group *target_fabric_make_nodeacl( |
| 380 | struct config_group *group, |
| 381 | const char *name) |
| 382 | { |
| 383 | struct se_portal_group *se_tpg = container_of(group, |
| 384 | struct se_portal_group, tpg_acl_group); |
| 385 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 386 | struct se_node_acl *se_nacl; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 387 | |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 388 | se_nacl = core_tpg_add_initiator_node_acl(se_tpg, name); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 389 | if (IS_ERR(se_nacl)) |
Thomas Meyer | e1750ba | 2011-08-01 23:58:18 +0200 | [diff] [blame] | 390 | return ERR_CAST(se_nacl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 391 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 392 | config_group_init_type_name(&se_nacl->acl_group, name, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 393 | &tf->tf_tpg_nacl_base_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 394 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 395 | config_group_init_type_name(&se_nacl->acl_attrib_group, "attrib", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 396 | &tf->tf_tpg_nacl_attrib_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 397 | configfs_add_default_group(&se_nacl->acl_attrib_group, |
| 398 | &se_nacl->acl_group); |
| 399 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 400 | config_group_init_type_name(&se_nacl->acl_auth_group, "auth", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 401 | &tf->tf_tpg_nacl_auth_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 402 | configfs_add_default_group(&se_nacl->acl_auth_group, |
| 403 | &se_nacl->acl_group); |
| 404 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 405 | config_group_init_type_name(&se_nacl->acl_param_group, "param", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 406 | &tf->tf_tpg_nacl_param_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 407 | configfs_add_default_group(&se_nacl->acl_param_group, |
| 408 | &se_nacl->acl_group); |
| 409 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 410 | config_group_init_type_name(&se_nacl->acl_fabric_stat_group, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 411 | "fabric_statistics", &tf->tf_tpg_nacl_stat_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 412 | configfs_add_default_group(&se_nacl->acl_fabric_stat_group, |
| 413 | &se_nacl->acl_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 414 | |
Christoph Hellwig | e6e202e | 2016-03-29 13:03:34 +0200 | [diff] [blame] | 415 | if (tf->tf_ops->fabric_init_nodeacl) { |
| 416 | int ret = tf->tf_ops->fabric_init_nodeacl(se_nacl, name); |
| 417 | if (ret) { |
| 418 | configfs_remove_default_groups(&se_nacl->acl_fabric_stat_group); |
| 419 | core_tpg_del_initiator_node_acl(se_nacl); |
| 420 | return ERR_PTR(ret); |
| 421 | } |
| 422 | } |
| 423 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 424 | return &se_nacl->acl_group; |
| 425 | } |
| 426 | |
| 427 | static void target_fabric_drop_nodeacl( |
| 428 | struct config_group *group, |
| 429 | struct config_item *item) |
| 430 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 431 | struct se_node_acl *se_nacl = container_of(to_config_group(item), |
| 432 | struct se_node_acl, acl_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 433 | |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 434 | configfs_remove_default_groups(&se_nacl->acl_group); |
| 435 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 436 | /* |
| 437 | * struct se_node_acl free is done in target_fabric_nacl_base_release() |
| 438 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 439 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | static struct configfs_group_operations target_fabric_nacl_group_ops = { |
| 443 | .make_group = target_fabric_make_nodeacl, |
| 444 | .drop_item = target_fabric_drop_nodeacl, |
| 445 | }; |
| 446 | |
| 447 | TF_CIT_SETUP(tpg_nacl, NULL, &target_fabric_nacl_group_ops, NULL); |
| 448 | |
| 449 | /* End of tfc_tpg_nacl_cit */ |
| 450 | |
| 451 | /* Start of tfc_tpg_np_base_cit */ |
| 452 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 453 | static void target_fabric_np_base_release(struct config_item *item) |
| 454 | { |
| 455 | struct se_tpg_np *se_tpg_np = container_of(to_config_group(item), |
| 456 | struct se_tpg_np, tpg_np_group); |
| 457 | struct se_portal_group *se_tpg = se_tpg_np->tpg_np_parent; |
| 458 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 459 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 460 | tf->tf_ops->fabric_drop_np(se_tpg_np); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 461 | } |
| 462 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 463 | static struct configfs_item_operations target_fabric_np_base_item_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 464 | .release = target_fabric_np_base_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 465 | }; |
| 466 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 467 | TF_CIT_SETUP_DRV(tpg_np_base, &target_fabric_np_base_item_ops, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 468 | |
| 469 | /* End of tfc_tpg_np_base_cit */ |
| 470 | |
| 471 | /* Start of tfc_tpg_np_cit */ |
| 472 | |
| 473 | static struct config_group *target_fabric_make_np( |
| 474 | struct config_group *group, |
| 475 | const char *name) |
| 476 | { |
| 477 | struct se_portal_group *se_tpg = container_of(group, |
| 478 | struct se_portal_group, tpg_np_group); |
| 479 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 480 | struct se_tpg_np *se_tpg_np; |
| 481 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 482 | if (!tf->tf_ops->fabric_make_np) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 483 | pr_err("tf->tf_ops.fabric_make_np is NULL\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 484 | return ERR_PTR(-ENOSYS); |
| 485 | } |
| 486 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 487 | se_tpg_np = tf->tf_ops->fabric_make_np(se_tpg, group, name); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 488 | if (!se_tpg_np || IS_ERR(se_tpg_np)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 489 | return ERR_PTR(-EINVAL); |
| 490 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 491 | se_tpg_np->tpg_np_parent = se_tpg; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 492 | config_group_init_type_name(&se_tpg_np->tpg_np_group, name, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 493 | &tf->tf_tpg_np_base_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 494 | |
| 495 | return &se_tpg_np->tpg_np_group; |
| 496 | } |
| 497 | |
| 498 | static void target_fabric_drop_np( |
| 499 | struct config_group *group, |
| 500 | struct config_item *item) |
| 501 | { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 502 | /* |
| 503 | * struct se_tpg_np is released via target_fabric_np_base_release() |
| 504 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 505 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 506 | } |
| 507 | |
| 508 | static struct configfs_group_operations target_fabric_np_group_ops = { |
| 509 | .make_group = &target_fabric_make_np, |
| 510 | .drop_item = &target_fabric_drop_np, |
| 511 | }; |
| 512 | |
| 513 | TF_CIT_SETUP(tpg_np, NULL, &target_fabric_np_group_ops, NULL); |
| 514 | |
| 515 | /* End of tfc_tpg_np_cit */ |
| 516 | |
| 517 | /* Start of tfc_tpg_port_cit */ |
| 518 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 519 | static struct se_lun *item_to_lun(struct config_item *item) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 520 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 521 | return container_of(to_config_group(item), struct se_lun, |
| 522 | lun_group); |
| 523 | } |
| 524 | |
| 525 | static ssize_t target_fabric_port_alua_tg_pt_gp_show(struct config_item *item, |
| 526 | char *page) |
| 527 | { |
| 528 | struct se_lun *lun = item_to_lun(item); |
| 529 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 530 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 531 | return -ENODEV; |
| 532 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 533 | return core_alua_show_tg_pt_gp_info(lun, page); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 534 | } |
| 535 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 536 | static ssize_t target_fabric_port_alua_tg_pt_gp_store(struct config_item *item, |
| 537 | const char *page, size_t count) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 538 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 539 | struct se_lun *lun = item_to_lun(item); |
| 540 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 541 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 542 | return -ENODEV; |
| 543 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 544 | return core_alua_store_tg_pt_gp_info(lun, page, count); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 547 | static ssize_t target_fabric_port_alua_tg_pt_offline_show( |
| 548 | struct config_item *item, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 549 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 550 | struct se_lun *lun = item_to_lun(item); |
| 551 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 552 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 553 | return -ENODEV; |
| 554 | |
| 555 | return core_alua_show_offline_bit(lun, page); |
| 556 | } |
| 557 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 558 | static ssize_t target_fabric_port_alua_tg_pt_offline_store( |
| 559 | struct config_item *item, const char *page, size_t count) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 560 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 561 | struct se_lun *lun = item_to_lun(item); |
| 562 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 563 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 564 | return -ENODEV; |
| 565 | |
| 566 | return core_alua_store_offline_bit(lun, page, count); |
| 567 | } |
| 568 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 569 | static ssize_t target_fabric_port_alua_tg_pt_status_show( |
| 570 | struct config_item *item, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 571 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 572 | struct se_lun *lun = item_to_lun(item); |
| 573 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 574 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 575 | return -ENODEV; |
| 576 | |
| 577 | return core_alua_show_secondary_status(lun, page); |
| 578 | } |
| 579 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 580 | static ssize_t target_fabric_port_alua_tg_pt_status_store( |
| 581 | struct config_item *item, const char *page, size_t count) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 582 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 583 | struct se_lun *lun = item_to_lun(item); |
| 584 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 585 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 586 | return -ENODEV; |
| 587 | |
| 588 | return core_alua_store_secondary_status(lun, page, count); |
| 589 | } |
| 590 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 591 | static ssize_t target_fabric_port_alua_tg_pt_write_md_show( |
| 592 | struct config_item *item, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 593 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 594 | struct se_lun *lun = item_to_lun(item); |
| 595 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 596 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 597 | return -ENODEV; |
| 598 | |
| 599 | return core_alua_show_secondary_write_metadata(lun, page); |
| 600 | } |
| 601 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 602 | static ssize_t target_fabric_port_alua_tg_pt_write_md_store( |
| 603 | struct config_item *item, const char *page, size_t count) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 604 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 605 | struct se_lun *lun = item_to_lun(item); |
| 606 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 607 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 608 | return -ENODEV; |
| 609 | |
| 610 | return core_alua_store_secondary_write_metadata(lun, page, count); |
| 611 | } |
| 612 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 613 | CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_gp); |
| 614 | CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_offline); |
| 615 | CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_status); |
| 616 | CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_write_md); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 617 | |
| 618 | static struct configfs_attribute *target_fabric_port_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 619 | &target_fabric_port_attr_alua_tg_pt_gp, |
| 620 | &target_fabric_port_attr_alua_tg_pt_offline, |
| 621 | &target_fabric_port_attr_alua_tg_pt_status, |
| 622 | &target_fabric_port_attr_alua_tg_pt_write_md, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 623 | NULL, |
| 624 | }; |
| 625 | |
Nicholas Bellinger | c17cd24 | 2017-06-01 03:10:53 -0700 | [diff] [blame] | 626 | extern struct configfs_item_operations target_core_dev_item_ops; |
| 627 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 628 | static int target_fabric_port_link( |
| 629 | struct config_item *lun_ci, |
| 630 | struct config_item *se_dev_ci) |
| 631 | { |
| 632 | struct config_item *tpg_ci; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 633 | struct se_lun *lun = container_of(to_config_group(lun_ci), |
| 634 | struct se_lun, lun_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 635 | struct se_portal_group *se_tpg; |
Nicholas Bellinger | c17cd24 | 2017-06-01 03:10:53 -0700 | [diff] [blame] | 636 | struct se_device *dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 637 | struct target_fabric_configfs *tf; |
| 638 | int ret; |
| 639 | |
Nicholas Bellinger | c17cd24 | 2017-06-01 03:10:53 -0700 | [diff] [blame] | 640 | if (!se_dev_ci->ci_type || |
| 641 | se_dev_ci->ci_type->ct_item_ops != &target_core_dev_item_ops) { |
| 642 | pr_err("Bad se_dev_ci, not a valid se_dev_ci pointer: %p\n", se_dev_ci); |
Nicholas Bellinger | 0ff8754 | 2012-12-04 23:43:57 -0800 | [diff] [blame] | 643 | return -EFAULT; |
| 644 | } |
Nicholas Bellinger | c17cd24 | 2017-06-01 03:10:53 -0700 | [diff] [blame] | 645 | dev = container_of(to_config_group(se_dev_ci), struct se_device, dev_group); |
Nicholas Bellinger | 0ff8754 | 2012-12-04 23:43:57 -0800 | [diff] [blame] | 646 | |
Nicholas Bellinger | faa06ab | 2013-01-31 14:56:12 -0800 | [diff] [blame] | 647 | if (!(dev->dev_flags & DF_CONFIGURED)) { |
| 648 | pr_err("se_device not configured yet, cannot port link\n"); |
| 649 | return -ENODEV; |
| 650 | } |
| 651 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 652 | tpg_ci = &lun_ci->ci_parent->ci_group->cg_item; |
| 653 | se_tpg = container_of(to_config_group(tpg_ci), |
| 654 | struct se_portal_group, tpg_group); |
| 655 | tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 656 | |
| 657 | if (lun->lun_se_dev != NULL) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 658 | pr_err("Port Symlink already exists\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 659 | return -EEXIST; |
| 660 | } |
| 661 | |
Nicholas Bellinger | 6bb8261 | 2015-05-10 19:31:10 -0700 | [diff] [blame] | 662 | ret = core_dev_add_lun(se_tpg, dev, lun); |
| 663 | if (ret) { |
| 664 | pr_err("core_dev_add_lun() failed: %d\n", ret); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 665 | goto out; |
| 666 | } |
| 667 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 668 | if (tf->tf_ops->fabric_post_link) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 669 | /* |
| 670 | * Call the optional fabric_post_link() to allow a |
| 671 | * fabric module to setup any additional state once |
| 672 | * core_dev_add_lun() has been called.. |
| 673 | */ |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 674 | tf->tf_ops->fabric_post_link(se_tpg, lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | return 0; |
| 678 | out: |
| 679 | return ret; |
| 680 | } |
| 681 | |
Andrzej Pietrasiewicz | e16769d | 2016-11-28 13:22:42 +0100 | [diff] [blame] | 682 | static void target_fabric_port_unlink( |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 683 | struct config_item *lun_ci, |
| 684 | struct config_item *se_dev_ci) |
| 685 | { |
| 686 | struct se_lun *lun = container_of(to_config_group(lun_ci), |
| 687 | struct se_lun, lun_group); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 688 | struct se_portal_group *se_tpg = lun->lun_tpg; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 689 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 690 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 691 | if (tf->tf_ops->fabric_pre_unlink) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 692 | /* |
| 693 | * Call the optional fabric_pre_unlink() to allow a |
| 694 | * fabric module to release any additional stat before |
| 695 | * core_dev_del_lun() is called. |
| 696 | */ |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 697 | tf->tf_ops->fabric_pre_unlink(se_tpg, lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 698 | } |
| 699 | |
Andy Grover | cd9d7cb | 2014-06-30 16:39:44 -0700 | [diff] [blame] | 700 | core_dev_del_lun(se_tpg, lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 701 | } |
| 702 | |
Nicholas Bellinger | 6bb8261 | 2015-05-10 19:31:10 -0700 | [diff] [blame] | 703 | static void target_fabric_port_release(struct config_item *item) |
| 704 | { |
| 705 | struct se_lun *lun = container_of(to_config_group(item), |
| 706 | struct se_lun, lun_group); |
| 707 | |
| 708 | kfree_rcu(lun, rcu_head); |
| 709 | } |
| 710 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 711 | static struct configfs_item_operations target_fabric_port_item_ops = { |
Nicholas Bellinger | 6bb8261 | 2015-05-10 19:31:10 -0700 | [diff] [blame] | 712 | .release = target_fabric_port_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 713 | .allow_link = target_fabric_port_link, |
| 714 | .drop_link = target_fabric_port_unlink, |
| 715 | }; |
| 716 | |
| 717 | TF_CIT_SETUP(tpg_port, &target_fabric_port_item_ops, NULL, target_fabric_port_attrs); |
| 718 | |
| 719 | /* End of tfc_tpg_port_cit */ |
| 720 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 721 | /* Start of tfc_tpg_port_stat_cit */ |
| 722 | |
| 723 | static struct config_group *target_core_port_stat_mkdir( |
| 724 | struct config_group *group, |
| 725 | const char *name) |
| 726 | { |
| 727 | return ERR_PTR(-ENOSYS); |
| 728 | } |
| 729 | |
| 730 | static void target_core_port_stat_rmdir( |
| 731 | struct config_group *group, |
| 732 | struct config_item *item) |
| 733 | { |
| 734 | return; |
| 735 | } |
| 736 | |
| 737 | static struct configfs_group_operations target_fabric_port_stat_group_ops = { |
| 738 | .make_group = target_core_port_stat_mkdir, |
| 739 | .drop_item = target_core_port_stat_rmdir, |
| 740 | }; |
| 741 | |
| 742 | TF_CIT_SETUP(tpg_port_stat, NULL, &target_fabric_port_stat_group_ops, NULL); |
| 743 | |
| 744 | /* End of tfc_tpg_port_stat_cit */ |
| 745 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 746 | /* Start of tfc_tpg_lun_cit */ |
| 747 | |
| 748 | static struct config_group *target_fabric_make_lun( |
| 749 | struct config_group *group, |
| 750 | const char *name) |
| 751 | { |
| 752 | struct se_lun *lun; |
| 753 | struct se_portal_group *se_tpg = container_of(group, |
| 754 | struct se_portal_group, tpg_lun_group); |
| 755 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
Hannes Reinecke | f2d3068 | 2015-06-10 08:41:22 +0200 | [diff] [blame] | 756 | unsigned long long unpacked_lun; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 757 | int errno; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 758 | |
| 759 | if (strstr(name, "lun_") != name) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 760 | pr_err("Unable to locate \'_\" in" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 761 | " \"lun_$LUN_NUMBER\"\n"); |
| 762 | return ERR_PTR(-EINVAL); |
| 763 | } |
Hannes Reinecke | f2d3068 | 2015-06-10 08:41:22 +0200 | [diff] [blame] | 764 | errno = kstrtoull(name + 4, 0, &unpacked_lun); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 765 | if (errno) |
| 766 | return ERR_PTR(errno); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 767 | |
Nicholas Bellinger | 6bb8261 | 2015-05-10 19:31:10 -0700 | [diff] [blame] | 768 | lun = core_tpg_alloc_lun(se_tpg, unpacked_lun); |
| 769 | if (IS_ERR(lun)) |
| 770 | return ERR_CAST(lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 771 | |
| 772 | config_group_init_type_name(&lun->lun_group, name, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 773 | &tf->tf_tpg_port_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 774 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 775 | config_group_init_type_name(&lun->port_stat_grps.stat_group, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 776 | "statistics", &tf->tf_tpg_port_stat_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 777 | configfs_add_default_group(&lun->port_stat_grps.stat_group, |
| 778 | &lun->lun_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 779 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 780 | target_stat_setup_port_default_groups(lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 781 | |
| 782 | return &lun->lun_group; |
| 783 | } |
| 784 | |
| 785 | static void target_fabric_drop_lun( |
| 786 | struct config_group *group, |
| 787 | struct config_item *item) |
| 788 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 789 | struct se_lun *lun = container_of(to_config_group(item), |
| 790 | struct se_lun, lun_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 791 | |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 792 | configfs_remove_default_groups(&lun->port_stat_grps.stat_group); |
| 793 | configfs_remove_default_groups(&lun->lun_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 794 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 795 | config_item_put(item); |
| 796 | } |
| 797 | |
| 798 | static struct configfs_group_operations target_fabric_lun_group_ops = { |
| 799 | .make_group = &target_fabric_make_lun, |
| 800 | .drop_item = &target_fabric_drop_lun, |
| 801 | }; |
| 802 | |
| 803 | TF_CIT_SETUP(tpg_lun, NULL, &target_fabric_lun_group_ops, NULL); |
| 804 | |
| 805 | /* End of tfc_tpg_lun_cit */ |
| 806 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 807 | TF_CIT_SETUP_DRV(tpg_attrib, NULL, NULL); |
| 808 | TF_CIT_SETUP_DRV(tpg_auth, NULL, NULL); |
| 809 | TF_CIT_SETUP_DRV(tpg_param, NULL, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 810 | |
| 811 | /* Start of tfc_tpg_base_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 812 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 813 | static void target_fabric_tpg_release(struct config_item *item) |
| 814 | { |
| 815 | struct se_portal_group *se_tpg = container_of(to_config_group(item), |
| 816 | struct se_portal_group, tpg_group); |
| 817 | struct se_wwn *wwn = se_tpg->se_tpg_wwn; |
| 818 | struct target_fabric_configfs *tf = wwn->wwn_tf; |
| 819 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 820 | tf->tf_ops->fabric_drop_tpg(se_tpg); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 821 | } |
| 822 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 823 | static struct configfs_item_operations target_fabric_tpg_base_item_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 824 | .release = target_fabric_tpg_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 825 | }; |
| 826 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 827 | TF_CIT_SETUP_DRV(tpg_base, &target_fabric_tpg_base_item_ops, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 828 | |
| 829 | /* End of tfc_tpg_base_cit */ |
| 830 | |
| 831 | /* Start of tfc_tpg_cit */ |
| 832 | |
| 833 | static struct config_group *target_fabric_make_tpg( |
| 834 | struct config_group *group, |
| 835 | const char *name) |
| 836 | { |
| 837 | struct se_wwn *wwn = container_of(group, struct se_wwn, wwn_group); |
| 838 | struct target_fabric_configfs *tf = wwn->wwn_tf; |
| 839 | struct se_portal_group *se_tpg; |
| 840 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 841 | if (!tf->tf_ops->fabric_make_tpg) { |
| 842 | pr_err("tf->tf_ops->fabric_make_tpg is NULL\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 843 | return ERR_PTR(-ENOSYS); |
| 844 | } |
| 845 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 846 | se_tpg = tf->tf_ops->fabric_make_tpg(wwn, group, name); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 847 | if (!se_tpg || IS_ERR(se_tpg)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 848 | return ERR_PTR(-EINVAL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 849 | |
| 850 | config_group_init_type_name(&se_tpg->tpg_group, name, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 851 | &tf->tf_tpg_base_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 852 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 853 | config_group_init_type_name(&se_tpg->tpg_lun_group, "lun", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 854 | &tf->tf_tpg_lun_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 855 | configfs_add_default_group(&se_tpg->tpg_lun_group, |
| 856 | &se_tpg->tpg_group); |
| 857 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 858 | config_group_init_type_name(&se_tpg->tpg_np_group, "np", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 859 | &tf->tf_tpg_np_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 860 | configfs_add_default_group(&se_tpg->tpg_np_group, |
| 861 | &se_tpg->tpg_group); |
| 862 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 863 | config_group_init_type_name(&se_tpg->tpg_acl_group, "acls", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 864 | &tf->tf_tpg_nacl_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 865 | configfs_add_default_group(&se_tpg->tpg_acl_group, |
| 866 | &se_tpg->tpg_group); |
| 867 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 868 | config_group_init_type_name(&se_tpg->tpg_attrib_group, "attrib", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 869 | &tf->tf_tpg_attrib_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 870 | configfs_add_default_group(&se_tpg->tpg_attrib_group, |
| 871 | &se_tpg->tpg_group); |
| 872 | |
Nicholas Bellinger | e4b512e | 2013-06-19 18:37:00 -0700 | [diff] [blame] | 873 | config_group_init_type_name(&se_tpg->tpg_auth_group, "auth", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 874 | &tf->tf_tpg_auth_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 875 | configfs_add_default_group(&se_tpg->tpg_auth_group, |
| 876 | &se_tpg->tpg_group); |
| 877 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 878 | config_group_init_type_name(&se_tpg->tpg_param_group, "param", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 879 | &tf->tf_tpg_param_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 880 | configfs_add_default_group(&se_tpg->tpg_param_group, |
| 881 | &se_tpg->tpg_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 882 | |
| 883 | return &se_tpg->tpg_group; |
| 884 | } |
| 885 | |
| 886 | static void target_fabric_drop_tpg( |
| 887 | struct config_group *group, |
| 888 | struct config_item *item) |
| 889 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 890 | struct se_portal_group *se_tpg = container_of(to_config_group(item), |
| 891 | struct se_portal_group, tpg_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 892 | |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 893 | configfs_remove_default_groups(&se_tpg->tpg_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 894 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 895 | } |
| 896 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 897 | static void target_fabric_release_wwn(struct config_item *item) |
| 898 | { |
| 899 | struct se_wwn *wwn = container_of(to_config_group(item), |
| 900 | struct se_wwn, wwn_group); |
| 901 | struct target_fabric_configfs *tf = wwn->wwn_tf; |
| 902 | |
Christoph Hellwig | 839559e | 2016-03-29 13:03:35 +0200 | [diff] [blame] | 903 | configfs_remove_default_groups(&wwn->fabric_stat_group); |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 904 | tf->tf_ops->fabric_drop_wwn(wwn); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | static struct configfs_item_operations target_fabric_tpg_item_ops = { |
| 908 | .release = target_fabric_release_wwn, |
| 909 | }; |
| 910 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 911 | static struct configfs_group_operations target_fabric_tpg_group_ops = { |
| 912 | .make_group = target_fabric_make_tpg, |
| 913 | .drop_item = target_fabric_drop_tpg, |
| 914 | }; |
| 915 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 916 | TF_CIT_SETUP(tpg, &target_fabric_tpg_item_ops, &target_fabric_tpg_group_ops, |
| 917 | NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 918 | |
| 919 | /* End of tfc_tpg_cit */ |
| 920 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 921 | /* Start of tfc_wwn_fabric_stats_cit */ |
| 922 | /* |
| 923 | * This is used as a placeholder for struct se_wwn->fabric_stat_group |
| 924 | * to allow fabrics access to ->fabric_stat_group->default_groups[] |
| 925 | */ |
| 926 | TF_CIT_SETUP(wwn_fabric_stats, NULL, NULL, NULL); |
| 927 | |
| 928 | /* End of tfc_wwn_fabric_stats_cit */ |
| 929 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 930 | /* Start of tfc_wwn_cit */ |
| 931 | |
| 932 | static struct config_group *target_fabric_make_wwn( |
| 933 | struct config_group *group, |
| 934 | const char *name) |
| 935 | { |
| 936 | struct target_fabric_configfs *tf = container_of(group, |
| 937 | struct target_fabric_configfs, tf_group); |
| 938 | struct se_wwn *wwn; |
| 939 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 940 | if (!tf->tf_ops->fabric_make_wwn) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 941 | pr_err("tf->tf_ops.fabric_make_wwn is NULL\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 942 | return ERR_PTR(-ENOSYS); |
| 943 | } |
| 944 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 945 | wwn = tf->tf_ops->fabric_make_wwn(tf, group, name); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 946 | if (!wwn || IS_ERR(wwn)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 947 | return ERR_PTR(-EINVAL); |
| 948 | |
| 949 | wwn->wwn_tf = tf; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 950 | |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 951 | config_group_init_type_name(&wwn->wwn_group, name, &tf->tf_tpg_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 952 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 953 | config_group_init_type_name(&wwn->fabric_stat_group, "fabric_statistics", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 954 | &tf->tf_wwn_fabric_stats_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 955 | configfs_add_default_group(&wwn->fabric_stat_group, &wwn->wwn_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 956 | |
Christoph Hellwig | 839559e | 2016-03-29 13:03:35 +0200 | [diff] [blame] | 957 | if (tf->tf_ops->add_wwn_groups) |
| 958 | tf->tf_ops->add_wwn_groups(wwn); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 959 | return &wwn->wwn_group; |
| 960 | } |
| 961 | |
| 962 | static void target_fabric_drop_wwn( |
| 963 | struct config_group *group, |
| 964 | struct config_item *item) |
| 965 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 966 | struct se_wwn *wwn = container_of(to_config_group(item), |
| 967 | struct se_wwn, wwn_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 968 | |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 969 | configfs_remove_default_groups(&wwn->wwn_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 970 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | static struct configfs_group_operations target_fabric_wwn_group_ops = { |
| 974 | .make_group = target_fabric_make_wwn, |
| 975 | .drop_item = target_fabric_drop_wwn, |
| 976 | }; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 977 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 978 | TF_CIT_SETUP_DRV(wwn, NULL, &target_fabric_wwn_group_ops); |
| 979 | TF_CIT_SETUP_DRV(discovery, NULL, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 980 | |
| 981 | int target_fabric_setup_cits(struct target_fabric_configfs *tf) |
| 982 | { |
| 983 | target_fabric_setup_discovery_cit(tf); |
| 984 | target_fabric_setup_wwn_cit(tf); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 985 | target_fabric_setup_wwn_fabric_stats_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 986 | target_fabric_setup_tpg_cit(tf); |
| 987 | target_fabric_setup_tpg_base_cit(tf); |
| 988 | target_fabric_setup_tpg_port_cit(tf); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 989 | target_fabric_setup_tpg_port_stat_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 990 | target_fabric_setup_tpg_lun_cit(tf); |
| 991 | target_fabric_setup_tpg_np_cit(tf); |
| 992 | target_fabric_setup_tpg_np_base_cit(tf); |
| 993 | target_fabric_setup_tpg_attrib_cit(tf); |
Nicholas Bellinger | e4b512e | 2013-06-19 18:37:00 -0700 | [diff] [blame] | 994 | target_fabric_setup_tpg_auth_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 995 | target_fabric_setup_tpg_param_cit(tf); |
| 996 | target_fabric_setup_tpg_nacl_cit(tf); |
| 997 | target_fabric_setup_tpg_nacl_base_cit(tf); |
| 998 | target_fabric_setup_tpg_nacl_attrib_cit(tf); |
| 999 | target_fabric_setup_tpg_nacl_auth_cit(tf); |
| 1000 | target_fabric_setup_tpg_nacl_param_cit(tf); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1001 | target_fabric_setup_tpg_nacl_stat_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1002 | target_fabric_setup_tpg_mappedlun_cit(tf); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1003 | target_fabric_setup_tpg_mappedlun_stat_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1004 | |
| 1005 | return 0; |
| 1006 | } |