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