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 | #include <target/target_core_fabric_configfs.h> |
| 39 | #include <target/target_core_configfs.h> |
| 40 | #include <target/configfs_macros.h> |
| 41 | |
Christoph Hellwig | e26d99a | 2011-11-14 12:30:30 -0500 | [diff] [blame] | 42 | #include "target_core_internal.h" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 43 | #include "target_core_alua.h" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 44 | #include "target_core_pr.h" |
| 45 | |
| 46 | #define TF_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \ |
| 47 | static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \ |
| 48 | { \ |
| 49 | struct target_fabric_configfs_template *tfc = &tf->tf_cit_tmpl; \ |
| 50 | struct config_item_type *cit = &tfc->tfc_##_name##_cit; \ |
| 51 | \ |
| 52 | cit->ct_item_ops = _item_ops; \ |
| 53 | cit->ct_group_ops = _group_ops; \ |
| 54 | cit->ct_attrs = _attrs; \ |
| 55 | cit->ct_owner = tf->tf_module; \ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 56 | pr_debug("Setup generic %s\n", __stringify(_name)); \ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 59 | #define TF_CIT_SETUP_DRV(_name, _item_ops, _group_ops) \ |
| 60 | static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \ |
| 61 | { \ |
| 62 | struct target_fabric_configfs_template *tfc = &tf->tf_cit_tmpl; \ |
| 63 | struct config_item_type *cit = &tfc->tfc_##_name##_cit; \ |
| 64 | struct configfs_attribute **attrs = tf->tf_ops.tfc_##_name##_attrs; \ |
| 65 | \ |
| 66 | cit->ct_item_ops = _item_ops; \ |
| 67 | cit->ct_group_ops = _group_ops; \ |
| 68 | cit->ct_attrs = attrs; \ |
| 69 | cit->ct_owner = tf->tf_module; \ |
| 70 | pr_debug("Setup generic %s\n", __stringify(_name)); \ |
| 71 | } |
| 72 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 73 | /* Start of tfc_tpg_mappedlun_cit */ |
| 74 | |
| 75 | static int target_fabric_mappedlun_link( |
| 76 | struct config_item *lun_acl_ci, |
| 77 | struct config_item *lun_ci) |
| 78 | { |
| 79 | struct se_dev_entry *deve; |
| 80 | struct se_lun *lun = container_of(to_config_group(lun_ci), |
| 81 | struct se_lun, lun_group); |
| 82 | struct se_lun_acl *lacl = container_of(to_config_group(lun_acl_ci), |
| 83 | struct se_lun_acl, se_lun_group); |
| 84 | struct se_portal_group *se_tpg; |
| 85 | struct config_item *nacl_ci, *tpg_ci, *tpg_ci_s, *wwn_ci, *wwn_ci_s; |
| 86 | int ret = 0, lun_access; |
Nicholas Bellinger | 0ff8754 | 2012-12-04 23:43:57 -0800 | [diff] [blame] | 87 | |
| 88 | if (lun->lun_link_magic != SE_LUN_LINK_MAGIC) { |
| 89 | pr_err("Bad lun->lun_link_magic, not a valid lun_ci pointer:" |
| 90 | " %p to struct lun: %p\n", lun_ci, lun); |
| 91 | return -EFAULT; |
| 92 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 93 | /* |
| 94 | * Ensure that the source port exists |
| 95 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 96 | if (!lun->lun_sep || !lun->lun_sep->sep_tpg) { |
| 97 | pr_err("Source se_lun->lun_sep or lun->lun_sep->sep" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 98 | "_tpg does not exist\n"); |
| 99 | return -EINVAL; |
| 100 | } |
| 101 | se_tpg = lun->lun_sep->sep_tpg; |
| 102 | |
| 103 | nacl_ci = &lun_acl_ci->ci_parent->ci_group->cg_item; |
| 104 | tpg_ci = &nacl_ci->ci_group->cg_item; |
| 105 | wwn_ci = &tpg_ci->ci_group->cg_item; |
| 106 | tpg_ci_s = &lun_ci->ci_parent->ci_group->cg_item; |
| 107 | wwn_ci_s = &tpg_ci_s->ci_group->cg_item; |
| 108 | /* |
| 109 | * Make sure the SymLink is going to the same $FABRIC/$WWN/tpgt_$TPGT |
| 110 | */ |
| 111 | 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] | 112 | pr_err("Illegal Initiator ACL SymLink outside of %s\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 113 | config_item_name(wwn_ci)); |
| 114 | return -EINVAL; |
| 115 | } |
| 116 | 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] | 117 | pr_err("Illegal Initiator ACL Symlink outside of %s" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 118 | " TPGT: %s\n", config_item_name(wwn_ci), |
| 119 | config_item_name(tpg_ci)); |
| 120 | return -EINVAL; |
| 121 | } |
| 122 | /* |
| 123 | * If this struct se_node_acl was dynamically generated with |
| 124 | * tpg_1/attrib/generate_node_acls=1, use the existing deve->lun_flags, |
| 125 | * which be will write protected (READ-ONLY) when |
| 126 | * tpg_1/attrib/demo_mode_write_protect=1 |
| 127 | */ |
| 128 | spin_lock_irq(&lacl->se_lun_nacl->device_list_lock); |
Jörn Engel | f208324 | 2012-03-15 15:05:40 -0400 | [diff] [blame] | 129 | deve = lacl->se_lun_nacl->device_list[lacl->mapped_lun]; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 130 | if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) |
| 131 | lun_access = deve->lun_flags; |
| 132 | else |
| 133 | lun_access = |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 134 | (se_tpg->se_tpg_tfo->tpg_check_prod_mode_write_protect( |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 135 | se_tpg)) ? TRANSPORT_LUNFLAGS_READ_ONLY : |
| 136 | TRANSPORT_LUNFLAGS_READ_WRITE; |
| 137 | spin_unlock_irq(&lacl->se_lun_nacl->device_list_lock); |
| 138 | /* |
| 139 | * Determine the actual mapped LUN value user wants.. |
| 140 | * |
| 141 | * This value is what the SCSI Initiator actually sees the |
| 142 | * iscsi/$IQN/$TPGT/lun/lun_* as on their SCSI Initiator Ports. |
| 143 | */ |
| 144 | ret = core_dev_add_initiator_node_lun_acl(se_tpg, lacl, |
| 145 | lun->unpacked_lun, lun_access); |
| 146 | |
| 147 | return (ret < 0) ? -EINVAL : 0; |
| 148 | } |
| 149 | |
| 150 | static int target_fabric_mappedlun_unlink( |
| 151 | struct config_item *lun_acl_ci, |
| 152 | struct config_item *lun_ci) |
| 153 | { |
| 154 | struct se_lun *lun; |
| 155 | struct se_lun_acl *lacl = container_of(to_config_group(lun_acl_ci), |
| 156 | struct se_lun_acl, se_lun_group); |
| 157 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
Jörn Engel | f208324 | 2012-03-15 15:05:40 -0400 | [diff] [blame] | 158 | struct se_dev_entry *deve = nacl->device_list[lacl->mapped_lun]; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 159 | struct se_portal_group *se_tpg; |
| 160 | /* |
| 161 | * Determine if the underlying MappedLUN has already been released.. |
| 162 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 163 | if (!deve->se_lun) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 164 | return 0; |
| 165 | |
| 166 | lun = container_of(to_config_group(lun_ci), struct se_lun, lun_group); |
| 167 | se_tpg = lun->lun_sep->sep_tpg; |
| 168 | |
| 169 | core_dev_del_initiator_node_lun_acl(se_tpg, lun, lacl); |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | CONFIGFS_EATTR_STRUCT(target_fabric_mappedlun, se_lun_acl); |
| 174 | #define TCM_MAPPEDLUN_ATTR(_name, _mode) \ |
| 175 | static struct target_fabric_mappedlun_attribute target_fabric_mappedlun_##_name = \ |
| 176 | __CONFIGFS_EATTR(_name, _mode, \ |
| 177 | target_fabric_mappedlun_show_##_name, \ |
| 178 | target_fabric_mappedlun_store_##_name); |
| 179 | |
| 180 | static ssize_t target_fabric_mappedlun_show_write_protect( |
| 181 | struct se_lun_acl *lacl, |
| 182 | char *page) |
| 183 | { |
| 184 | struct se_node_acl *se_nacl = lacl->se_lun_nacl; |
| 185 | struct se_dev_entry *deve; |
| 186 | ssize_t len; |
| 187 | |
| 188 | spin_lock_irq(&se_nacl->device_list_lock); |
Jörn Engel | f208324 | 2012-03-15 15:05:40 -0400 | [diff] [blame] | 189 | deve = se_nacl->device_list[lacl->mapped_lun]; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 190 | len = sprintf(page, "%d\n", |
| 191 | (deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY) ? |
| 192 | 1 : 0); |
| 193 | spin_unlock_irq(&se_nacl->device_list_lock); |
| 194 | |
| 195 | return len; |
| 196 | } |
| 197 | |
| 198 | static ssize_t target_fabric_mappedlun_store_write_protect( |
| 199 | struct se_lun_acl *lacl, |
| 200 | const char *page, |
| 201 | size_t count) |
| 202 | { |
| 203 | struct se_node_acl *se_nacl = lacl->se_lun_nacl; |
| 204 | struct se_portal_group *se_tpg = se_nacl->se_tpg; |
| 205 | unsigned long op; |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 206 | int ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 207 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 208 | ret = kstrtoul(page, 0, &op); |
| 209 | if (ret) |
| 210 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 211 | |
| 212 | if ((op != 1) && (op != 0)) |
| 213 | return -EINVAL; |
| 214 | |
| 215 | core_update_device_list_access(lacl->mapped_lun, (op) ? |
| 216 | TRANSPORT_LUNFLAGS_READ_ONLY : |
| 217 | TRANSPORT_LUNFLAGS_READ_WRITE, |
| 218 | lacl->se_lun_nacl); |
| 219 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 220 | pr_debug("%s_ConfigFS: Changed Initiator ACL: %s" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 221 | " Mapped LUN: %u Write Protect bit to %s\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 222 | se_tpg->se_tpg_tfo->get_fabric_name(), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 223 | lacl->initiatorname, lacl->mapped_lun, (op) ? "ON" : "OFF"); |
| 224 | |
| 225 | return count; |
| 226 | |
| 227 | } |
| 228 | |
| 229 | TCM_MAPPEDLUN_ATTR(write_protect, S_IRUGO | S_IWUSR); |
| 230 | |
| 231 | CONFIGFS_EATTR_OPS(target_fabric_mappedlun, se_lun_acl, se_lun_group); |
| 232 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 233 | static void target_fabric_mappedlun_release(struct config_item *item) |
| 234 | { |
| 235 | struct se_lun_acl *lacl = container_of(to_config_group(item), |
| 236 | struct se_lun_acl, se_lun_group); |
| 237 | struct se_portal_group *se_tpg = lacl->se_lun_nacl->se_tpg; |
| 238 | |
| 239 | core_dev_free_initiator_node_lun_acl(se_tpg, lacl); |
| 240 | } |
| 241 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 242 | static struct configfs_attribute *target_fabric_mappedlun_attrs[] = { |
| 243 | &target_fabric_mappedlun_write_protect.attr, |
| 244 | NULL, |
| 245 | }; |
| 246 | |
| 247 | static struct configfs_item_operations target_fabric_mappedlun_item_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 248 | .release = target_fabric_mappedlun_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 249 | .show_attribute = target_fabric_mappedlun_attr_show, |
| 250 | .store_attribute = target_fabric_mappedlun_attr_store, |
| 251 | .allow_link = target_fabric_mappedlun_link, |
| 252 | .drop_link = target_fabric_mappedlun_unlink, |
| 253 | }; |
| 254 | |
| 255 | TF_CIT_SETUP(tpg_mappedlun, &target_fabric_mappedlun_item_ops, NULL, |
| 256 | target_fabric_mappedlun_attrs); |
| 257 | |
| 258 | /* End of tfc_tpg_mappedlun_cit */ |
| 259 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 260 | /* Start of tfc_tpg_mappedlun_port_cit */ |
| 261 | |
| 262 | static struct config_group *target_core_mappedlun_stat_mkdir( |
| 263 | struct config_group *group, |
| 264 | const char *name) |
| 265 | { |
| 266 | return ERR_PTR(-ENOSYS); |
| 267 | } |
| 268 | |
| 269 | static void target_core_mappedlun_stat_rmdir( |
| 270 | struct config_group *group, |
| 271 | struct config_item *item) |
| 272 | { |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | static struct configfs_group_operations target_fabric_mappedlun_stat_group_ops = { |
| 277 | .make_group = target_core_mappedlun_stat_mkdir, |
| 278 | .drop_item = target_core_mappedlun_stat_rmdir, |
| 279 | }; |
| 280 | |
| 281 | TF_CIT_SETUP(tpg_mappedlun_stat, NULL, &target_fabric_mappedlun_stat_group_ops, |
| 282 | NULL); |
| 283 | |
| 284 | /* End of tfc_tpg_mappedlun_port_cit */ |
| 285 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 286 | /* Start of tfc_tpg_nacl_attrib_cit */ |
| 287 | |
| 288 | CONFIGFS_EATTR_OPS(target_fabric_nacl_attrib, se_node_acl, acl_attrib_group); |
| 289 | |
| 290 | static struct configfs_item_operations target_fabric_nacl_attrib_item_ops = { |
| 291 | .show_attribute = target_fabric_nacl_attrib_attr_show, |
| 292 | .store_attribute = target_fabric_nacl_attrib_attr_store, |
| 293 | }; |
| 294 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 295 | TF_CIT_SETUP_DRV(tpg_nacl_attrib, &target_fabric_nacl_attrib_item_ops, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 296 | |
| 297 | /* End of tfc_tpg_nacl_attrib_cit */ |
| 298 | |
| 299 | /* Start of tfc_tpg_nacl_auth_cit */ |
| 300 | |
| 301 | CONFIGFS_EATTR_OPS(target_fabric_nacl_auth, se_node_acl, acl_auth_group); |
| 302 | |
| 303 | static struct configfs_item_operations target_fabric_nacl_auth_item_ops = { |
| 304 | .show_attribute = target_fabric_nacl_auth_attr_show, |
| 305 | .store_attribute = target_fabric_nacl_auth_attr_store, |
| 306 | }; |
| 307 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 308 | TF_CIT_SETUP_DRV(tpg_nacl_auth, &target_fabric_nacl_auth_item_ops, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 309 | |
| 310 | /* End of tfc_tpg_nacl_auth_cit */ |
| 311 | |
| 312 | /* Start of tfc_tpg_nacl_param_cit */ |
| 313 | |
| 314 | CONFIGFS_EATTR_OPS(target_fabric_nacl_param, se_node_acl, acl_param_group); |
| 315 | |
| 316 | static struct configfs_item_operations target_fabric_nacl_param_item_ops = { |
| 317 | .show_attribute = target_fabric_nacl_param_attr_show, |
| 318 | .store_attribute = target_fabric_nacl_param_attr_store, |
| 319 | }; |
| 320 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 321 | TF_CIT_SETUP_DRV(tpg_nacl_param, &target_fabric_nacl_param_item_ops, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 322 | |
| 323 | /* End of tfc_tpg_nacl_param_cit */ |
| 324 | |
| 325 | /* Start of tfc_tpg_nacl_base_cit */ |
| 326 | |
| 327 | CONFIGFS_EATTR_OPS(target_fabric_nacl_base, se_node_acl, acl_group); |
| 328 | |
| 329 | static struct config_group *target_fabric_make_mappedlun( |
| 330 | struct config_group *group, |
| 331 | const char *name) |
| 332 | { |
| 333 | struct se_node_acl *se_nacl = container_of(group, |
| 334 | struct se_node_acl, acl_group); |
| 335 | struct se_portal_group *se_tpg = se_nacl->se_tpg; |
| 336 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
Joern Engel | da0abae | 2014-09-02 17:49:57 -0400 | [diff] [blame] | 337 | struct se_lun_acl *lacl = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 338 | struct config_item *acl_ci; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 339 | struct config_group *lacl_cg = NULL, *ml_stat_grp = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 340 | char *buf; |
| 341 | unsigned long mapped_lun; |
| 342 | int ret = 0; |
| 343 | |
| 344 | acl_ci = &group->cg_item; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 345 | if (!acl_ci) { |
| 346 | pr_err("Unable to locatel acl_ci\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 347 | return NULL; |
| 348 | } |
| 349 | |
| 350 | buf = kzalloc(strlen(name) + 1, GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 351 | if (!buf) { |
| 352 | pr_err("Unable to allocate memory for name buf\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 353 | return ERR_PTR(-ENOMEM); |
| 354 | } |
| 355 | snprintf(buf, strlen(name) + 1, "%s", name); |
| 356 | /* |
| 357 | * Make sure user is creating iscsi/$IQN/$TPGT/acls/$INITIATOR/lun_$ID. |
| 358 | */ |
| 359 | if (strstr(buf, "lun_") != buf) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 360 | pr_err("Unable to locate \"lun_\" from buf: %s" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 361 | " name: %s\n", buf, name); |
| 362 | ret = -EINVAL; |
| 363 | goto out; |
| 364 | } |
| 365 | /* |
| 366 | * Determine the Mapped LUN value. This is what the SCSI Initiator |
| 367 | * Port will actually see. |
| 368 | */ |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 369 | ret = kstrtoul(buf + 4, 0, &mapped_lun); |
| 370 | if (ret) |
| 371 | goto out; |
| 372 | if (mapped_lun > UINT_MAX) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 373 | ret = -EINVAL; |
| 374 | goto out; |
| 375 | } |
Nicholas Bellinger | fbbf855 | 2013-02-18 18:31:37 -0800 | [diff] [blame] | 376 | if (mapped_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) { |
| 377 | pr_err("Mapped LUN: %lu exceeds TRANSPORT_MAX_LUNS_PER_TPG" |
| 378 | "-1: %u for Target Portal Group: %u\n", mapped_lun, |
| 379 | TRANSPORT_MAX_LUNS_PER_TPG-1, |
| 380 | se_tpg->se_tpg_tfo->tpg_get_tag(se_tpg)); |
| 381 | ret = -EINVAL; |
| 382 | goto out; |
| 383 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 384 | |
Nicholas Bellinger | fcf2948 | 2013-02-18 18:00:33 -0800 | [diff] [blame] | 385 | lacl = core_dev_init_initiator_node_lun_acl(se_tpg, se_nacl, |
| 386 | mapped_lun, &ret); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 387 | if (!lacl) { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 388 | ret = -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 389 | goto out; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | lacl_cg = &lacl->se_lun_group; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 393 | lacl_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 394 | GFP_KERNEL); |
| 395 | if (!lacl_cg->default_groups) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 396 | pr_err("Unable to allocate lacl_cg->default_groups\n"); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 397 | ret = -ENOMEM; |
| 398 | goto out; |
| 399 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 400 | |
| 401 | config_group_init_type_name(&lacl->se_lun_group, name, |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 402 | &tf->tf_cit_tmpl.tfc_tpg_mappedlun_cit); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 403 | config_group_init_type_name(&lacl->ml_stat_grps.stat_group, |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 404 | "statistics", &tf->tf_cit_tmpl.tfc_tpg_mappedlun_stat_cit); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 405 | lacl_cg->default_groups[0] = &lacl->ml_stat_grps.stat_group; |
| 406 | lacl_cg->default_groups[1] = NULL; |
| 407 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 408 | ml_stat_grp = &lacl->ml_stat_grps.stat_group; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 409 | ml_stat_grp->default_groups = kmalloc(sizeof(struct config_group *) * 3, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 410 | GFP_KERNEL); |
| 411 | if (!ml_stat_grp->default_groups) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 412 | pr_err("Unable to allocate ml_stat_grp->default_groups\n"); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 413 | ret = -ENOMEM; |
| 414 | goto out; |
| 415 | } |
| 416 | target_stat_setup_mappedlun_default_groups(lacl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 417 | |
| 418 | kfree(buf); |
| 419 | return &lacl->se_lun_group; |
| 420 | out: |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 421 | if (lacl_cg) |
| 422 | kfree(lacl_cg->default_groups); |
Joern Engel | da0abae | 2014-09-02 17:49:57 -0400 | [diff] [blame] | 423 | kfree(lacl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 424 | kfree(buf); |
| 425 | return ERR_PTR(ret); |
| 426 | } |
| 427 | |
| 428 | static void target_fabric_drop_mappedlun( |
| 429 | struct config_group *group, |
| 430 | struct config_item *item) |
| 431 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 432 | struct se_lun_acl *lacl = container_of(to_config_group(item), |
| 433 | struct se_lun_acl, se_lun_group); |
| 434 | struct config_item *df_item; |
| 435 | struct config_group *lacl_cg = NULL, *ml_stat_grp = NULL; |
| 436 | int i; |
| 437 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 438 | ml_stat_grp = &lacl->ml_stat_grps.stat_group; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 439 | for (i = 0; ml_stat_grp->default_groups[i]; i++) { |
| 440 | df_item = &ml_stat_grp->default_groups[i]->cg_item; |
| 441 | ml_stat_grp->default_groups[i] = NULL; |
| 442 | config_item_put(df_item); |
| 443 | } |
| 444 | kfree(ml_stat_grp->default_groups); |
| 445 | |
| 446 | lacl_cg = &lacl->se_lun_group; |
| 447 | for (i = 0; lacl_cg->default_groups[i]; i++) { |
| 448 | df_item = &lacl_cg->default_groups[i]->cg_item; |
| 449 | lacl_cg->default_groups[i] = NULL; |
| 450 | config_item_put(df_item); |
| 451 | } |
| 452 | kfree(lacl_cg->default_groups); |
| 453 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 454 | config_item_put(item); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | static void target_fabric_nacl_base_release(struct config_item *item) |
| 458 | { |
| 459 | struct se_node_acl *se_nacl = container_of(to_config_group(item), |
| 460 | struct se_node_acl, acl_group); |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame^] | 461 | struct target_fabric_configfs *tf = se_nacl->se_tpg->se_tpg_wwn->wwn_tf; |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 462 | |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame^] | 463 | if (tf->tf_ops.fabric_cleanup_nodeacl) |
| 464 | tf->tf_ops.fabric_cleanup_nodeacl(se_nacl); |
| 465 | core_tpg_del_initiator_node_acl(se_nacl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | static struct configfs_item_operations target_fabric_nacl_base_item_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 469 | .release = target_fabric_nacl_base_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 470 | .show_attribute = target_fabric_nacl_base_attr_show, |
| 471 | .store_attribute = target_fabric_nacl_base_attr_store, |
| 472 | }; |
| 473 | |
| 474 | static struct configfs_group_operations target_fabric_nacl_base_group_ops = { |
| 475 | .make_group = target_fabric_make_mappedlun, |
| 476 | .drop_item = target_fabric_drop_mappedlun, |
| 477 | }; |
| 478 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 479 | TF_CIT_SETUP_DRV(tpg_nacl_base, &target_fabric_nacl_base_item_ops, |
| 480 | &target_fabric_nacl_base_group_ops); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 481 | |
| 482 | /* End of tfc_tpg_nacl_base_cit */ |
| 483 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 484 | /* Start of tfc_node_fabric_stats_cit */ |
| 485 | /* |
| 486 | * This is used as a placeholder for struct se_node_acl->acl_fabric_stat_group |
| 487 | * to allow fabrics access to ->acl_fabric_stat_group->default_groups[] |
| 488 | */ |
| 489 | TF_CIT_SETUP(tpg_nacl_stat, NULL, NULL, NULL); |
| 490 | |
| 491 | /* End of tfc_wwn_fabric_stats_cit */ |
| 492 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 493 | /* Start of tfc_tpg_nacl_cit */ |
| 494 | |
| 495 | static struct config_group *target_fabric_make_nodeacl( |
| 496 | struct config_group *group, |
| 497 | const char *name) |
| 498 | { |
| 499 | struct se_portal_group *se_tpg = container_of(group, |
| 500 | struct se_portal_group, tpg_acl_group); |
| 501 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 502 | struct se_node_acl *se_nacl; |
| 503 | struct config_group *nacl_cg; |
| 504 | |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame^] | 505 | se_nacl = core_tpg_add_initiator_node_acl(se_tpg, name); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 506 | if (IS_ERR(se_nacl)) |
Thomas Meyer | e1750ba | 2011-08-01 23:58:18 +0200 | [diff] [blame] | 507 | return ERR_CAST(se_nacl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 508 | |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame^] | 509 | if (tf->tf_ops.fabric_init_nodeacl) { |
| 510 | int ret = tf->tf_ops.fabric_init_nodeacl(se_nacl, name); |
| 511 | if (ret) { |
| 512 | core_tpg_del_initiator_node_acl(se_nacl); |
| 513 | return ERR_PTR(ret); |
| 514 | } |
| 515 | } |
| 516 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 517 | nacl_cg = &se_nacl->acl_group; |
| 518 | nacl_cg->default_groups = se_nacl->acl_default_groups; |
| 519 | nacl_cg->default_groups[0] = &se_nacl->acl_attrib_group; |
| 520 | nacl_cg->default_groups[1] = &se_nacl->acl_auth_group; |
| 521 | nacl_cg->default_groups[2] = &se_nacl->acl_param_group; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 522 | nacl_cg->default_groups[3] = &se_nacl->acl_fabric_stat_group; |
| 523 | nacl_cg->default_groups[4] = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 524 | |
| 525 | config_group_init_type_name(&se_nacl->acl_group, name, |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 526 | &tf->tf_cit_tmpl.tfc_tpg_nacl_base_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 527 | config_group_init_type_name(&se_nacl->acl_attrib_group, "attrib", |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 528 | &tf->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 529 | config_group_init_type_name(&se_nacl->acl_auth_group, "auth", |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 530 | &tf->tf_cit_tmpl.tfc_tpg_nacl_auth_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 531 | config_group_init_type_name(&se_nacl->acl_param_group, "param", |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 532 | &tf->tf_cit_tmpl.tfc_tpg_nacl_param_cit); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 533 | config_group_init_type_name(&se_nacl->acl_fabric_stat_group, |
| 534 | "fabric_statistics", |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 535 | &tf->tf_cit_tmpl.tfc_tpg_nacl_stat_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 536 | |
| 537 | return &se_nacl->acl_group; |
| 538 | } |
| 539 | |
| 540 | static void target_fabric_drop_nodeacl( |
| 541 | struct config_group *group, |
| 542 | struct config_item *item) |
| 543 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 544 | struct se_node_acl *se_nacl = container_of(to_config_group(item), |
| 545 | struct se_node_acl, acl_group); |
| 546 | struct config_item *df_item; |
| 547 | struct config_group *nacl_cg; |
| 548 | int i; |
| 549 | |
| 550 | nacl_cg = &se_nacl->acl_group; |
| 551 | for (i = 0; nacl_cg->default_groups[i]; i++) { |
| 552 | df_item = &nacl_cg->default_groups[i]->cg_item; |
| 553 | nacl_cg->default_groups[i] = NULL; |
| 554 | config_item_put(df_item); |
| 555 | } |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 556 | /* |
| 557 | * struct se_node_acl free is done in target_fabric_nacl_base_release() |
| 558 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 559 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | static struct configfs_group_operations target_fabric_nacl_group_ops = { |
| 563 | .make_group = target_fabric_make_nodeacl, |
| 564 | .drop_item = target_fabric_drop_nodeacl, |
| 565 | }; |
| 566 | |
| 567 | TF_CIT_SETUP(tpg_nacl, NULL, &target_fabric_nacl_group_ops, NULL); |
| 568 | |
| 569 | /* End of tfc_tpg_nacl_cit */ |
| 570 | |
| 571 | /* Start of tfc_tpg_np_base_cit */ |
| 572 | |
| 573 | CONFIGFS_EATTR_OPS(target_fabric_np_base, se_tpg_np, tpg_np_group); |
| 574 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 575 | static void target_fabric_np_base_release(struct config_item *item) |
| 576 | { |
| 577 | struct se_tpg_np *se_tpg_np = container_of(to_config_group(item), |
| 578 | struct se_tpg_np, tpg_np_group); |
| 579 | struct se_portal_group *se_tpg = se_tpg_np->tpg_np_parent; |
| 580 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 581 | |
| 582 | tf->tf_ops.fabric_drop_np(se_tpg_np); |
| 583 | } |
| 584 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 585 | static struct configfs_item_operations target_fabric_np_base_item_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 586 | .release = target_fabric_np_base_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 587 | .show_attribute = target_fabric_np_base_attr_show, |
| 588 | .store_attribute = target_fabric_np_base_attr_store, |
| 589 | }; |
| 590 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 591 | 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] | 592 | |
| 593 | /* End of tfc_tpg_np_base_cit */ |
| 594 | |
| 595 | /* Start of tfc_tpg_np_cit */ |
| 596 | |
| 597 | static struct config_group *target_fabric_make_np( |
| 598 | struct config_group *group, |
| 599 | const char *name) |
| 600 | { |
| 601 | struct se_portal_group *se_tpg = container_of(group, |
| 602 | struct se_portal_group, tpg_np_group); |
| 603 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 604 | struct se_tpg_np *se_tpg_np; |
| 605 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 606 | if (!tf->tf_ops.fabric_make_np) { |
| 607 | pr_err("tf->tf_ops.fabric_make_np is NULL\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 608 | return ERR_PTR(-ENOSYS); |
| 609 | } |
| 610 | |
| 611 | 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] | 612 | if (!se_tpg_np || IS_ERR(se_tpg_np)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 613 | return ERR_PTR(-EINVAL); |
| 614 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 615 | se_tpg_np->tpg_np_parent = se_tpg; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 616 | config_group_init_type_name(&se_tpg_np->tpg_np_group, name, |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 617 | &tf->tf_cit_tmpl.tfc_tpg_np_base_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 618 | |
| 619 | return &se_tpg_np->tpg_np_group; |
| 620 | } |
| 621 | |
| 622 | static void target_fabric_drop_np( |
| 623 | struct config_group *group, |
| 624 | struct config_item *item) |
| 625 | { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 626 | /* |
| 627 | * struct se_tpg_np is released via target_fabric_np_base_release() |
| 628 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 629 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | static struct configfs_group_operations target_fabric_np_group_ops = { |
| 633 | .make_group = &target_fabric_make_np, |
| 634 | .drop_item = &target_fabric_drop_np, |
| 635 | }; |
| 636 | |
| 637 | TF_CIT_SETUP(tpg_np, NULL, &target_fabric_np_group_ops, NULL); |
| 638 | |
| 639 | /* End of tfc_tpg_np_cit */ |
| 640 | |
| 641 | /* Start of tfc_tpg_port_cit */ |
| 642 | |
| 643 | CONFIGFS_EATTR_STRUCT(target_fabric_port, se_lun); |
| 644 | #define TCM_PORT_ATTR(_name, _mode) \ |
| 645 | static struct target_fabric_port_attribute target_fabric_port_##_name = \ |
| 646 | __CONFIGFS_EATTR(_name, _mode, \ |
| 647 | target_fabric_port_show_attr_##_name, \ |
| 648 | target_fabric_port_store_attr_##_name); |
| 649 | |
| 650 | #define TCM_PORT_ATTOR_RO(_name) \ |
| 651 | __CONFIGFS_EATTR_RO(_name, \ |
| 652 | target_fabric_port_show_attr_##_name); |
| 653 | |
| 654 | /* |
| 655 | * alua_tg_pt_gp |
| 656 | */ |
| 657 | static ssize_t target_fabric_port_show_attr_alua_tg_pt_gp( |
| 658 | struct se_lun *lun, |
| 659 | char *page) |
| 660 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 661 | if (!lun || !lun->lun_sep) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 662 | return -ENODEV; |
| 663 | |
| 664 | return core_alua_show_tg_pt_gp_info(lun->lun_sep, page); |
| 665 | } |
| 666 | |
| 667 | static ssize_t target_fabric_port_store_attr_alua_tg_pt_gp( |
| 668 | struct se_lun *lun, |
| 669 | const char *page, |
| 670 | size_t count) |
| 671 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 672 | if (!lun || !lun->lun_sep) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 673 | return -ENODEV; |
| 674 | |
| 675 | return core_alua_store_tg_pt_gp_info(lun->lun_sep, page, count); |
| 676 | } |
| 677 | |
| 678 | TCM_PORT_ATTR(alua_tg_pt_gp, S_IRUGO | S_IWUSR); |
| 679 | |
| 680 | /* |
| 681 | * alua_tg_pt_offline |
| 682 | */ |
| 683 | static ssize_t target_fabric_port_show_attr_alua_tg_pt_offline( |
| 684 | struct se_lun *lun, |
| 685 | char *page) |
| 686 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 687 | if (!lun || !lun->lun_sep) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 688 | return -ENODEV; |
| 689 | |
| 690 | return core_alua_show_offline_bit(lun, page); |
| 691 | } |
| 692 | |
| 693 | static ssize_t target_fabric_port_store_attr_alua_tg_pt_offline( |
| 694 | struct se_lun *lun, |
| 695 | const char *page, |
| 696 | size_t count) |
| 697 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 698 | if (!lun || !lun->lun_sep) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 699 | return -ENODEV; |
| 700 | |
| 701 | return core_alua_store_offline_bit(lun, page, count); |
| 702 | } |
| 703 | |
| 704 | TCM_PORT_ATTR(alua_tg_pt_offline, S_IRUGO | S_IWUSR); |
| 705 | |
| 706 | /* |
| 707 | * alua_tg_pt_status |
| 708 | */ |
| 709 | static ssize_t target_fabric_port_show_attr_alua_tg_pt_status( |
| 710 | struct se_lun *lun, |
| 711 | char *page) |
| 712 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 713 | if (!lun || !lun->lun_sep) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 714 | return -ENODEV; |
| 715 | |
| 716 | return core_alua_show_secondary_status(lun, page); |
| 717 | } |
| 718 | |
| 719 | static ssize_t target_fabric_port_store_attr_alua_tg_pt_status( |
| 720 | struct se_lun *lun, |
| 721 | const char *page, |
| 722 | size_t count) |
| 723 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 724 | if (!lun || !lun->lun_sep) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 725 | return -ENODEV; |
| 726 | |
| 727 | return core_alua_store_secondary_status(lun, page, count); |
| 728 | } |
| 729 | |
| 730 | TCM_PORT_ATTR(alua_tg_pt_status, S_IRUGO | S_IWUSR); |
| 731 | |
| 732 | /* |
| 733 | * alua_tg_pt_write_md |
| 734 | */ |
| 735 | static ssize_t target_fabric_port_show_attr_alua_tg_pt_write_md( |
| 736 | struct se_lun *lun, |
| 737 | char *page) |
| 738 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 739 | if (!lun || !lun->lun_sep) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 740 | return -ENODEV; |
| 741 | |
| 742 | return core_alua_show_secondary_write_metadata(lun, page); |
| 743 | } |
| 744 | |
| 745 | static ssize_t target_fabric_port_store_attr_alua_tg_pt_write_md( |
| 746 | struct se_lun *lun, |
| 747 | const char *page, |
| 748 | size_t count) |
| 749 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 750 | if (!lun || !lun->lun_sep) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 751 | return -ENODEV; |
| 752 | |
| 753 | return core_alua_store_secondary_write_metadata(lun, page, count); |
| 754 | } |
| 755 | |
| 756 | TCM_PORT_ATTR(alua_tg_pt_write_md, S_IRUGO | S_IWUSR); |
| 757 | |
| 758 | |
| 759 | static struct configfs_attribute *target_fabric_port_attrs[] = { |
| 760 | &target_fabric_port_alua_tg_pt_gp.attr, |
| 761 | &target_fabric_port_alua_tg_pt_offline.attr, |
| 762 | &target_fabric_port_alua_tg_pt_status.attr, |
| 763 | &target_fabric_port_alua_tg_pt_write_md.attr, |
| 764 | NULL, |
| 765 | }; |
| 766 | |
| 767 | CONFIGFS_EATTR_OPS(target_fabric_port, se_lun, lun_group); |
| 768 | |
| 769 | static int target_fabric_port_link( |
| 770 | struct config_item *lun_ci, |
| 771 | struct config_item *se_dev_ci) |
| 772 | { |
| 773 | struct config_item *tpg_ci; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 774 | struct se_lun *lun = container_of(to_config_group(lun_ci), |
| 775 | struct se_lun, lun_group); |
| 776 | struct se_lun *lun_p; |
| 777 | struct se_portal_group *se_tpg; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 778 | struct se_device *dev = |
| 779 | container_of(to_config_group(se_dev_ci), struct se_device, dev_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 780 | struct target_fabric_configfs *tf; |
| 781 | int ret; |
| 782 | |
Nicholas Bellinger | 0ff8754 | 2012-12-04 23:43:57 -0800 | [diff] [blame] | 783 | if (dev->dev_link_magic != SE_DEV_LINK_MAGIC) { |
| 784 | pr_err("Bad dev->dev_link_magic, not a valid se_dev_ci pointer:" |
| 785 | " %p to struct se_device: %p\n", se_dev_ci, dev); |
| 786 | return -EFAULT; |
| 787 | } |
| 788 | |
Nicholas Bellinger | faa06ab | 2013-01-31 14:56:12 -0800 | [diff] [blame] | 789 | if (!(dev->dev_flags & DF_CONFIGURED)) { |
| 790 | pr_err("se_device not configured yet, cannot port link\n"); |
| 791 | return -ENODEV; |
| 792 | } |
| 793 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 794 | tpg_ci = &lun_ci->ci_parent->ci_group->cg_item; |
| 795 | se_tpg = container_of(to_config_group(tpg_ci), |
| 796 | struct se_portal_group, tpg_group); |
| 797 | tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 798 | |
| 799 | if (lun->lun_se_dev != NULL) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 800 | pr_err("Port Symlink already exists\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 801 | return -EEXIST; |
| 802 | } |
| 803 | |
Andy Grover | 2dca673 | 2012-07-12 17:34:55 -0700 | [diff] [blame] | 804 | lun_p = core_dev_add_lun(se_tpg, dev, lun->unpacked_lun); |
Sebastian Andrzej Siewior | 8d9efe5 | 2012-01-11 21:43:38 +0100 | [diff] [blame] | 805 | if (IS_ERR(lun_p)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 806 | pr_err("core_dev_add_lun() failed\n"); |
Sebastian Andrzej Siewior | 8d9efe5 | 2012-01-11 21:43:38 +0100 | [diff] [blame] | 807 | ret = PTR_ERR(lun_p); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 808 | goto out; |
| 809 | } |
| 810 | |
| 811 | if (tf->tf_ops.fabric_post_link) { |
| 812 | /* |
| 813 | * Call the optional fabric_post_link() to allow a |
| 814 | * fabric module to setup any additional state once |
| 815 | * core_dev_add_lun() has been called.. |
| 816 | */ |
| 817 | tf->tf_ops.fabric_post_link(se_tpg, lun); |
| 818 | } |
| 819 | |
| 820 | return 0; |
| 821 | out: |
| 822 | return ret; |
| 823 | } |
| 824 | |
| 825 | static int target_fabric_port_unlink( |
| 826 | struct config_item *lun_ci, |
| 827 | struct config_item *se_dev_ci) |
| 828 | { |
| 829 | struct se_lun *lun = container_of(to_config_group(lun_ci), |
| 830 | struct se_lun, lun_group); |
| 831 | struct se_portal_group *se_tpg = lun->lun_sep->sep_tpg; |
| 832 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 833 | |
| 834 | if (tf->tf_ops.fabric_pre_unlink) { |
| 835 | /* |
| 836 | * Call the optional fabric_pre_unlink() to allow a |
| 837 | * fabric module to release any additional stat before |
| 838 | * core_dev_del_lun() is called. |
| 839 | */ |
| 840 | tf->tf_ops.fabric_pre_unlink(se_tpg, lun); |
| 841 | } |
| 842 | |
Andy Grover | cd9d7cb | 2014-06-30 16:39:44 -0700 | [diff] [blame] | 843 | core_dev_del_lun(se_tpg, lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 844 | return 0; |
| 845 | } |
| 846 | |
| 847 | static struct configfs_item_operations target_fabric_port_item_ops = { |
| 848 | .show_attribute = target_fabric_port_attr_show, |
| 849 | .store_attribute = target_fabric_port_attr_store, |
| 850 | .allow_link = target_fabric_port_link, |
| 851 | .drop_link = target_fabric_port_unlink, |
| 852 | }; |
| 853 | |
| 854 | TF_CIT_SETUP(tpg_port, &target_fabric_port_item_ops, NULL, target_fabric_port_attrs); |
| 855 | |
| 856 | /* End of tfc_tpg_port_cit */ |
| 857 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 858 | /* Start of tfc_tpg_port_stat_cit */ |
| 859 | |
| 860 | static struct config_group *target_core_port_stat_mkdir( |
| 861 | struct config_group *group, |
| 862 | const char *name) |
| 863 | { |
| 864 | return ERR_PTR(-ENOSYS); |
| 865 | } |
| 866 | |
| 867 | static void target_core_port_stat_rmdir( |
| 868 | struct config_group *group, |
| 869 | struct config_item *item) |
| 870 | { |
| 871 | return; |
| 872 | } |
| 873 | |
| 874 | static struct configfs_group_operations target_fabric_port_stat_group_ops = { |
| 875 | .make_group = target_core_port_stat_mkdir, |
| 876 | .drop_item = target_core_port_stat_rmdir, |
| 877 | }; |
| 878 | |
| 879 | TF_CIT_SETUP(tpg_port_stat, NULL, &target_fabric_port_stat_group_ops, NULL); |
| 880 | |
| 881 | /* End of tfc_tpg_port_stat_cit */ |
| 882 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 883 | /* Start of tfc_tpg_lun_cit */ |
| 884 | |
| 885 | static struct config_group *target_fabric_make_lun( |
| 886 | struct config_group *group, |
| 887 | const char *name) |
| 888 | { |
| 889 | struct se_lun *lun; |
| 890 | struct se_portal_group *se_tpg = container_of(group, |
| 891 | struct se_portal_group, tpg_lun_group); |
| 892 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 893 | struct config_group *lun_cg = NULL, *port_stat_grp = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 894 | unsigned long unpacked_lun; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 895 | int errno; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 896 | |
| 897 | if (strstr(name, "lun_") != name) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 898 | pr_err("Unable to locate \'_\" in" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 899 | " \"lun_$LUN_NUMBER\"\n"); |
| 900 | return ERR_PTR(-EINVAL); |
| 901 | } |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 902 | errno = kstrtoul(name + 4, 0, &unpacked_lun); |
| 903 | if (errno) |
| 904 | return ERR_PTR(errno); |
| 905 | if (unpacked_lun > UINT_MAX) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 906 | return ERR_PTR(-EINVAL); |
| 907 | |
| 908 | lun = core_get_lun_from_tpg(se_tpg, unpacked_lun); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 909 | if (!lun) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 910 | return ERR_PTR(-EINVAL); |
| 911 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 912 | lun_cg = &lun->lun_group; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 913 | lun_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 914 | GFP_KERNEL); |
| 915 | if (!lun_cg->default_groups) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 916 | pr_err("Unable to allocate lun_cg->default_groups\n"); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 917 | return ERR_PTR(-ENOMEM); |
| 918 | } |
| 919 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 920 | config_group_init_type_name(&lun->lun_group, name, |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 921 | &tf->tf_cit_tmpl.tfc_tpg_port_cit); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 922 | config_group_init_type_name(&lun->port_stat_grps.stat_group, |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 923 | "statistics", &tf->tf_cit_tmpl.tfc_tpg_port_stat_cit); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 924 | lun_cg->default_groups[0] = &lun->port_stat_grps.stat_group; |
| 925 | lun_cg->default_groups[1] = NULL; |
| 926 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 927 | port_stat_grp = &lun->port_stat_grps.stat_group; |
Andy Grover | ab6dae8 | 2013-12-09 14:27:36 -0800 | [diff] [blame] | 928 | port_stat_grp->default_groups = kzalloc(sizeof(struct config_group *) * 4, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 929 | GFP_KERNEL); |
| 930 | if (!port_stat_grp->default_groups) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 931 | pr_err("Unable to allocate port_stat_grp->default_groups\n"); |
Joern Engel | 1481473b | 2014-09-17 15:11:28 -0700 | [diff] [blame] | 932 | kfree(lun_cg->default_groups); |
| 933 | return ERR_PTR(-ENOMEM); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 934 | } |
| 935 | target_stat_setup_port_default_groups(lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 936 | |
| 937 | return &lun->lun_group; |
| 938 | } |
| 939 | |
| 940 | static void target_fabric_drop_lun( |
| 941 | struct config_group *group, |
| 942 | struct config_item *item) |
| 943 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 944 | struct se_lun *lun = container_of(to_config_group(item), |
| 945 | struct se_lun, lun_group); |
| 946 | struct config_item *df_item; |
| 947 | struct config_group *lun_cg, *port_stat_grp; |
| 948 | int i; |
| 949 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 950 | port_stat_grp = &lun->port_stat_grps.stat_group; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 951 | for (i = 0; port_stat_grp->default_groups[i]; i++) { |
| 952 | df_item = &port_stat_grp->default_groups[i]->cg_item; |
| 953 | port_stat_grp->default_groups[i] = NULL; |
| 954 | config_item_put(df_item); |
| 955 | } |
| 956 | kfree(port_stat_grp->default_groups); |
| 957 | |
| 958 | lun_cg = &lun->lun_group; |
| 959 | for (i = 0; lun_cg->default_groups[i]; i++) { |
| 960 | df_item = &lun_cg->default_groups[i]->cg_item; |
| 961 | lun_cg->default_groups[i] = NULL; |
| 962 | config_item_put(df_item); |
| 963 | } |
| 964 | kfree(lun_cg->default_groups); |
| 965 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 966 | config_item_put(item); |
| 967 | } |
| 968 | |
| 969 | static struct configfs_group_operations target_fabric_lun_group_ops = { |
| 970 | .make_group = &target_fabric_make_lun, |
| 971 | .drop_item = &target_fabric_drop_lun, |
| 972 | }; |
| 973 | |
| 974 | TF_CIT_SETUP(tpg_lun, NULL, &target_fabric_lun_group_ops, NULL); |
| 975 | |
| 976 | /* End of tfc_tpg_lun_cit */ |
| 977 | |
| 978 | /* Start of tfc_tpg_attrib_cit */ |
| 979 | |
| 980 | CONFIGFS_EATTR_OPS(target_fabric_tpg_attrib, se_portal_group, tpg_attrib_group); |
| 981 | |
| 982 | static struct configfs_item_operations target_fabric_tpg_attrib_item_ops = { |
| 983 | .show_attribute = target_fabric_tpg_attrib_attr_show, |
| 984 | .store_attribute = target_fabric_tpg_attrib_attr_store, |
| 985 | }; |
| 986 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 987 | TF_CIT_SETUP_DRV(tpg_attrib, &target_fabric_tpg_attrib_item_ops, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 988 | |
| 989 | /* End of tfc_tpg_attrib_cit */ |
| 990 | |
Nicholas Bellinger | e4b512e | 2013-06-19 18:37:00 -0700 | [diff] [blame] | 991 | /* Start of tfc_tpg_auth_cit */ |
| 992 | |
| 993 | CONFIGFS_EATTR_OPS(target_fabric_tpg_auth, se_portal_group, tpg_auth_group); |
| 994 | |
| 995 | static struct configfs_item_operations target_fabric_tpg_auth_item_ops = { |
| 996 | .show_attribute = target_fabric_tpg_auth_attr_show, |
| 997 | .store_attribute = target_fabric_tpg_auth_attr_store, |
| 998 | }; |
| 999 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1000 | TF_CIT_SETUP_DRV(tpg_auth, &target_fabric_tpg_auth_item_ops, NULL); |
Nicholas Bellinger | e4b512e | 2013-06-19 18:37:00 -0700 | [diff] [blame] | 1001 | |
| 1002 | /* End of tfc_tpg_attrib_cit */ |
| 1003 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1004 | /* Start of tfc_tpg_param_cit */ |
| 1005 | |
| 1006 | CONFIGFS_EATTR_OPS(target_fabric_tpg_param, se_portal_group, tpg_param_group); |
| 1007 | |
| 1008 | static struct configfs_item_operations target_fabric_tpg_param_item_ops = { |
| 1009 | .show_attribute = target_fabric_tpg_param_attr_show, |
| 1010 | .store_attribute = target_fabric_tpg_param_attr_store, |
| 1011 | }; |
| 1012 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1013 | TF_CIT_SETUP_DRV(tpg_param, &target_fabric_tpg_param_item_ops, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1014 | |
| 1015 | /* End of tfc_tpg_param_cit */ |
| 1016 | |
| 1017 | /* Start of tfc_tpg_base_cit */ |
| 1018 | /* |
| 1019 | * For use with TF_TPG_ATTR() and TF_TPG_ATTR_RO() |
| 1020 | */ |
| 1021 | CONFIGFS_EATTR_OPS(target_fabric_tpg, se_portal_group, tpg_group); |
| 1022 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 1023 | static void target_fabric_tpg_release(struct config_item *item) |
| 1024 | { |
| 1025 | struct se_portal_group *se_tpg = container_of(to_config_group(item), |
| 1026 | struct se_portal_group, tpg_group); |
| 1027 | struct se_wwn *wwn = se_tpg->se_tpg_wwn; |
| 1028 | struct target_fabric_configfs *tf = wwn->wwn_tf; |
| 1029 | |
| 1030 | tf->tf_ops.fabric_drop_tpg(se_tpg); |
| 1031 | } |
| 1032 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1033 | static struct configfs_item_operations target_fabric_tpg_base_item_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 1034 | .release = target_fabric_tpg_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1035 | .show_attribute = target_fabric_tpg_attr_show, |
| 1036 | .store_attribute = target_fabric_tpg_attr_store, |
| 1037 | }; |
| 1038 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1039 | 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] | 1040 | |
| 1041 | /* End of tfc_tpg_base_cit */ |
| 1042 | |
| 1043 | /* Start of tfc_tpg_cit */ |
| 1044 | |
| 1045 | static struct config_group *target_fabric_make_tpg( |
| 1046 | struct config_group *group, |
| 1047 | const char *name) |
| 1048 | { |
| 1049 | struct se_wwn *wwn = container_of(group, struct se_wwn, wwn_group); |
| 1050 | struct target_fabric_configfs *tf = wwn->wwn_tf; |
| 1051 | struct se_portal_group *se_tpg; |
| 1052 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1053 | if (!tf->tf_ops.fabric_make_tpg) { |
| 1054 | pr_err("tf->tf_ops.fabric_make_tpg is NULL\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1055 | return ERR_PTR(-ENOSYS); |
| 1056 | } |
| 1057 | |
| 1058 | se_tpg = tf->tf_ops.fabric_make_tpg(wwn, group, name); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1059 | if (!se_tpg || IS_ERR(se_tpg)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1060 | return ERR_PTR(-EINVAL); |
| 1061 | /* |
| 1062 | * Setup default groups from pre-allocated se_tpg->tpg_default_groups |
| 1063 | */ |
| 1064 | se_tpg->tpg_group.default_groups = se_tpg->tpg_default_groups; |
| 1065 | se_tpg->tpg_group.default_groups[0] = &se_tpg->tpg_lun_group; |
| 1066 | se_tpg->tpg_group.default_groups[1] = &se_tpg->tpg_np_group; |
| 1067 | se_tpg->tpg_group.default_groups[2] = &se_tpg->tpg_acl_group; |
| 1068 | se_tpg->tpg_group.default_groups[3] = &se_tpg->tpg_attrib_group; |
Nicholas Bellinger | e4b512e | 2013-06-19 18:37:00 -0700 | [diff] [blame] | 1069 | se_tpg->tpg_group.default_groups[4] = &se_tpg->tpg_auth_group; |
| 1070 | se_tpg->tpg_group.default_groups[5] = &se_tpg->tpg_param_group; |
| 1071 | se_tpg->tpg_group.default_groups[6] = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1072 | |
| 1073 | config_group_init_type_name(&se_tpg->tpg_group, name, |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 1074 | &tf->tf_cit_tmpl.tfc_tpg_base_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1075 | config_group_init_type_name(&se_tpg->tpg_lun_group, "lun", |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 1076 | &tf->tf_cit_tmpl.tfc_tpg_lun_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1077 | config_group_init_type_name(&se_tpg->tpg_np_group, "np", |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 1078 | &tf->tf_cit_tmpl.tfc_tpg_np_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1079 | config_group_init_type_name(&se_tpg->tpg_acl_group, "acls", |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 1080 | &tf->tf_cit_tmpl.tfc_tpg_nacl_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1081 | config_group_init_type_name(&se_tpg->tpg_attrib_group, "attrib", |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 1082 | &tf->tf_cit_tmpl.tfc_tpg_attrib_cit); |
Nicholas Bellinger | e4b512e | 2013-06-19 18:37:00 -0700 | [diff] [blame] | 1083 | config_group_init_type_name(&se_tpg->tpg_auth_group, "auth", |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 1084 | &tf->tf_cit_tmpl.tfc_tpg_auth_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1085 | config_group_init_type_name(&se_tpg->tpg_param_group, "param", |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 1086 | &tf->tf_cit_tmpl.tfc_tpg_param_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1087 | |
| 1088 | return &se_tpg->tpg_group; |
| 1089 | } |
| 1090 | |
| 1091 | static void target_fabric_drop_tpg( |
| 1092 | struct config_group *group, |
| 1093 | struct config_item *item) |
| 1094 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1095 | struct se_portal_group *se_tpg = container_of(to_config_group(item), |
| 1096 | struct se_portal_group, tpg_group); |
| 1097 | struct config_group *tpg_cg = &se_tpg->tpg_group; |
| 1098 | struct config_item *df_item; |
| 1099 | int i; |
| 1100 | /* |
| 1101 | * Release default groups, but do not release tpg_cg->default_groups |
| 1102 | * memory as it is statically allocated at se_tpg->tpg_default_groups. |
| 1103 | */ |
| 1104 | for (i = 0; tpg_cg->default_groups[i]; i++) { |
| 1105 | df_item = &tpg_cg->default_groups[i]->cg_item; |
| 1106 | tpg_cg->default_groups[i] = NULL; |
| 1107 | config_item_put(df_item); |
| 1108 | } |
| 1109 | |
| 1110 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1111 | } |
| 1112 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 1113 | static void target_fabric_release_wwn(struct config_item *item) |
| 1114 | { |
| 1115 | struct se_wwn *wwn = container_of(to_config_group(item), |
| 1116 | struct se_wwn, wwn_group); |
| 1117 | struct target_fabric_configfs *tf = wwn->wwn_tf; |
| 1118 | |
| 1119 | tf->tf_ops.fabric_drop_wwn(wwn); |
| 1120 | } |
| 1121 | |
| 1122 | static struct configfs_item_operations target_fabric_tpg_item_ops = { |
| 1123 | .release = target_fabric_release_wwn, |
| 1124 | }; |
| 1125 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1126 | static struct configfs_group_operations target_fabric_tpg_group_ops = { |
| 1127 | .make_group = target_fabric_make_tpg, |
| 1128 | .drop_item = target_fabric_drop_tpg, |
| 1129 | }; |
| 1130 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 1131 | TF_CIT_SETUP(tpg, &target_fabric_tpg_item_ops, &target_fabric_tpg_group_ops, |
| 1132 | NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1133 | |
| 1134 | /* End of tfc_tpg_cit */ |
| 1135 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1136 | /* Start of tfc_wwn_fabric_stats_cit */ |
| 1137 | /* |
| 1138 | * This is used as a placeholder for struct se_wwn->fabric_stat_group |
| 1139 | * to allow fabrics access to ->fabric_stat_group->default_groups[] |
| 1140 | */ |
| 1141 | TF_CIT_SETUP(wwn_fabric_stats, NULL, NULL, NULL); |
| 1142 | |
| 1143 | /* End of tfc_wwn_fabric_stats_cit */ |
| 1144 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1145 | /* Start of tfc_wwn_cit */ |
| 1146 | |
| 1147 | static struct config_group *target_fabric_make_wwn( |
| 1148 | struct config_group *group, |
| 1149 | const char *name) |
| 1150 | { |
| 1151 | struct target_fabric_configfs *tf = container_of(group, |
| 1152 | struct target_fabric_configfs, tf_group); |
| 1153 | struct se_wwn *wwn; |
| 1154 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1155 | if (!tf->tf_ops.fabric_make_wwn) { |
| 1156 | pr_err("tf->tf_ops.fabric_make_wwn is NULL\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1157 | return ERR_PTR(-ENOSYS); |
| 1158 | } |
| 1159 | |
| 1160 | wwn = tf->tf_ops.fabric_make_wwn(tf, group, name); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1161 | if (!wwn || IS_ERR(wwn)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1162 | return ERR_PTR(-EINVAL); |
| 1163 | |
| 1164 | wwn->wwn_tf = tf; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1165 | /* |
| 1166 | * Setup default groups from pre-allocated wwn->wwn_default_groups |
| 1167 | */ |
| 1168 | wwn->wwn_group.default_groups = wwn->wwn_default_groups; |
| 1169 | wwn->wwn_group.default_groups[0] = &wwn->fabric_stat_group; |
| 1170 | wwn->wwn_group.default_groups[1] = NULL; |
| 1171 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1172 | config_group_init_type_name(&wwn->wwn_group, name, |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 1173 | &tf->tf_cit_tmpl.tfc_tpg_cit); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1174 | config_group_init_type_name(&wwn->fabric_stat_group, "fabric_statistics", |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 1175 | &tf->tf_cit_tmpl.tfc_wwn_fabric_stats_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1176 | |
| 1177 | return &wwn->wwn_group; |
| 1178 | } |
| 1179 | |
| 1180 | static void target_fabric_drop_wwn( |
| 1181 | struct config_group *group, |
| 1182 | struct config_item *item) |
| 1183 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1184 | struct se_wwn *wwn = container_of(to_config_group(item), |
| 1185 | struct se_wwn, wwn_group); |
| 1186 | struct config_item *df_item; |
| 1187 | struct config_group *cg = &wwn->wwn_group; |
| 1188 | int i; |
| 1189 | |
| 1190 | for (i = 0; cg->default_groups[i]; i++) { |
| 1191 | df_item = &cg->default_groups[i]->cg_item; |
| 1192 | cg->default_groups[i] = NULL; |
| 1193 | config_item_put(df_item); |
| 1194 | } |
| 1195 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1196 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | static struct configfs_group_operations target_fabric_wwn_group_ops = { |
| 1200 | .make_group = target_fabric_make_wwn, |
| 1201 | .drop_item = target_fabric_drop_wwn, |
| 1202 | }; |
| 1203 | /* |
| 1204 | * For use with TF_WWN_ATTR() and TF_WWN_ATTR_RO() |
| 1205 | */ |
| 1206 | CONFIGFS_EATTR_OPS(target_fabric_wwn, target_fabric_configfs, tf_group); |
| 1207 | |
| 1208 | static struct configfs_item_operations target_fabric_wwn_item_ops = { |
| 1209 | .show_attribute = target_fabric_wwn_attr_show, |
| 1210 | .store_attribute = target_fabric_wwn_attr_store, |
| 1211 | }; |
| 1212 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1213 | TF_CIT_SETUP_DRV(wwn, &target_fabric_wwn_item_ops, &target_fabric_wwn_group_ops); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1214 | |
| 1215 | /* End of tfc_wwn_cit */ |
| 1216 | |
| 1217 | /* Start of tfc_discovery_cit */ |
| 1218 | |
| 1219 | CONFIGFS_EATTR_OPS(target_fabric_discovery, target_fabric_configfs, |
| 1220 | tf_disc_group); |
| 1221 | |
| 1222 | static struct configfs_item_operations target_fabric_discovery_item_ops = { |
| 1223 | .show_attribute = target_fabric_discovery_attr_show, |
| 1224 | .store_attribute = target_fabric_discovery_attr_store, |
| 1225 | }; |
| 1226 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1227 | TF_CIT_SETUP_DRV(discovery, &target_fabric_discovery_item_ops, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1228 | |
| 1229 | /* End of tfc_discovery_cit */ |
| 1230 | |
| 1231 | int target_fabric_setup_cits(struct target_fabric_configfs *tf) |
| 1232 | { |
| 1233 | target_fabric_setup_discovery_cit(tf); |
| 1234 | target_fabric_setup_wwn_cit(tf); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1235 | target_fabric_setup_wwn_fabric_stats_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1236 | target_fabric_setup_tpg_cit(tf); |
| 1237 | target_fabric_setup_tpg_base_cit(tf); |
| 1238 | target_fabric_setup_tpg_port_cit(tf); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1239 | target_fabric_setup_tpg_port_stat_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1240 | target_fabric_setup_tpg_lun_cit(tf); |
| 1241 | target_fabric_setup_tpg_np_cit(tf); |
| 1242 | target_fabric_setup_tpg_np_base_cit(tf); |
| 1243 | target_fabric_setup_tpg_attrib_cit(tf); |
Nicholas Bellinger | e4b512e | 2013-06-19 18:37:00 -0700 | [diff] [blame] | 1244 | target_fabric_setup_tpg_auth_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1245 | target_fabric_setup_tpg_param_cit(tf); |
| 1246 | target_fabric_setup_tpg_nacl_cit(tf); |
| 1247 | target_fabric_setup_tpg_nacl_base_cit(tf); |
| 1248 | target_fabric_setup_tpg_nacl_attrib_cit(tf); |
| 1249 | target_fabric_setup_tpg_nacl_auth_cit(tf); |
| 1250 | target_fabric_setup_tpg_nacl_param_cit(tf); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1251 | target_fabric_setup_tpg_nacl_stat_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1252 | target_fabric_setup_tpg_mappedlun_cit(tf); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1253 | target_fabric_setup_tpg_mappedlun_stat_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1254 | |
| 1255 | return 0; |
| 1256 | } |