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 | char *buf; |
Hannes Reinecke | f2d3068 | 2015-06-10 08:41:22 +0200 | [diff] [blame] | 277 | unsigned long long mapped_lun; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 278 | int ret = 0; |
| 279 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 280 | buf = kzalloc(strlen(name) + 1, GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 281 | if (!buf) { |
| 282 | pr_err("Unable to allocate memory for name buf\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 283 | return ERR_PTR(-ENOMEM); |
| 284 | } |
| 285 | snprintf(buf, strlen(name) + 1, "%s", name); |
| 286 | /* |
| 287 | * Make sure user is creating iscsi/$IQN/$TPGT/acls/$INITIATOR/lun_$ID. |
| 288 | */ |
| 289 | if (strstr(buf, "lun_") != buf) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 290 | pr_err("Unable to locate \"lun_\" from buf: %s" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 291 | " name: %s\n", buf, name); |
| 292 | ret = -EINVAL; |
| 293 | goto out; |
| 294 | } |
| 295 | /* |
| 296 | * Determine the Mapped LUN value. This is what the SCSI Initiator |
| 297 | * Port will actually see. |
| 298 | */ |
Hannes Reinecke | f2d3068 | 2015-06-10 08:41:22 +0200 | [diff] [blame] | 299 | ret = kstrtoull(buf + 4, 0, &mapped_lun); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 300 | if (ret) |
| 301 | goto out; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 302 | |
Nicholas Bellinger | fcf2948 | 2013-02-18 18:00:33 -0800 | [diff] [blame] | 303 | lacl = core_dev_init_initiator_node_lun_acl(se_tpg, se_nacl, |
| 304 | mapped_lun, &ret); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 305 | if (!lacl) { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 306 | ret = -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 307 | goto out; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 310 | config_group_init_type_name(&lacl->se_lun_group, name, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 311 | &tf->tf_tpg_mappedlun_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 312 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 313 | config_group_init_type_name(&lacl->ml_stat_grps.stat_group, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 314 | "statistics", &tf->tf_tpg_mappedlun_stat_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 315 | configfs_add_default_group(&lacl->ml_stat_grps.stat_group, |
| 316 | &lacl->se_lun_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 317 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 318 | target_stat_setup_mappedlun_default_groups(lacl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 319 | |
| 320 | kfree(buf); |
| 321 | return &lacl->se_lun_group; |
| 322 | out: |
Joern Engel | da0abae | 2014-09-02 17:49:57 -0400 | [diff] [blame] | 323 | kfree(lacl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 324 | kfree(buf); |
| 325 | return ERR_PTR(ret); |
| 326 | } |
| 327 | |
| 328 | static void target_fabric_drop_mappedlun( |
| 329 | struct config_group *group, |
| 330 | struct config_item *item) |
| 331 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 332 | struct se_lun_acl *lacl = container_of(to_config_group(item), |
| 333 | struct se_lun_acl, se_lun_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 334 | |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 335 | configfs_remove_default_groups(&lacl->ml_stat_grps.stat_group); |
| 336 | configfs_remove_default_groups(&lacl->se_lun_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 337 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 338 | config_item_put(item); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | static void target_fabric_nacl_base_release(struct config_item *item) |
| 342 | { |
| 343 | struct se_node_acl *se_nacl = container_of(to_config_group(item), |
| 344 | struct se_node_acl, acl_group); |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 345 | 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] | 346 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 347 | if (tf->tf_ops->fabric_cleanup_nodeacl) |
| 348 | tf->tf_ops->fabric_cleanup_nodeacl(se_nacl); |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 349 | core_tpg_del_initiator_node_acl(se_nacl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | static struct configfs_item_operations target_fabric_nacl_base_item_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 353 | .release = target_fabric_nacl_base_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 354 | }; |
| 355 | |
| 356 | static struct configfs_group_operations target_fabric_nacl_base_group_ops = { |
| 357 | .make_group = target_fabric_make_mappedlun, |
| 358 | .drop_item = target_fabric_drop_mappedlun, |
| 359 | }; |
| 360 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 361 | TF_CIT_SETUP_DRV(tpg_nacl_base, &target_fabric_nacl_base_item_ops, |
| 362 | &target_fabric_nacl_base_group_ops); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 363 | |
| 364 | /* End of tfc_tpg_nacl_base_cit */ |
| 365 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 366 | /* Start of tfc_node_fabric_stats_cit */ |
| 367 | /* |
| 368 | * This is used as a placeholder for struct se_node_acl->acl_fabric_stat_group |
| 369 | * to allow fabrics access to ->acl_fabric_stat_group->default_groups[] |
| 370 | */ |
| 371 | TF_CIT_SETUP(tpg_nacl_stat, NULL, NULL, NULL); |
| 372 | |
| 373 | /* End of tfc_wwn_fabric_stats_cit */ |
| 374 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 375 | /* Start of tfc_tpg_nacl_cit */ |
| 376 | |
| 377 | static struct config_group *target_fabric_make_nodeacl( |
| 378 | struct config_group *group, |
| 379 | const char *name) |
| 380 | { |
| 381 | struct se_portal_group *se_tpg = container_of(group, |
| 382 | struct se_portal_group, tpg_acl_group); |
| 383 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 384 | struct se_node_acl *se_nacl; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 385 | |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 386 | se_nacl = core_tpg_add_initiator_node_acl(se_tpg, name); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 387 | if (IS_ERR(se_nacl)) |
Thomas Meyer | e1750ba | 2011-08-01 23:58:18 +0200 | [diff] [blame] | 388 | return ERR_CAST(se_nacl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 389 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 390 | if (tf->tf_ops->fabric_init_nodeacl) { |
| 391 | int ret = tf->tf_ops->fabric_init_nodeacl(se_nacl, name); |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 392 | if (ret) { |
| 393 | core_tpg_del_initiator_node_acl(se_nacl); |
| 394 | return ERR_PTR(ret); |
| 395 | } |
| 396 | } |
| 397 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 398 | config_group_init_type_name(&se_nacl->acl_group, name, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 399 | &tf->tf_tpg_nacl_base_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 400 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 401 | config_group_init_type_name(&se_nacl->acl_attrib_group, "attrib", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 402 | &tf->tf_tpg_nacl_attrib_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 403 | configfs_add_default_group(&se_nacl->acl_attrib_group, |
| 404 | &se_nacl->acl_group); |
| 405 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 406 | config_group_init_type_name(&se_nacl->acl_auth_group, "auth", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 407 | &tf->tf_tpg_nacl_auth_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 408 | configfs_add_default_group(&se_nacl->acl_auth_group, |
| 409 | &se_nacl->acl_group); |
| 410 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 411 | config_group_init_type_name(&se_nacl->acl_param_group, "param", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 412 | &tf->tf_tpg_nacl_param_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 413 | configfs_add_default_group(&se_nacl->acl_param_group, |
| 414 | &se_nacl->acl_group); |
| 415 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 416 | config_group_init_type_name(&se_nacl->acl_fabric_stat_group, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 417 | "fabric_statistics", &tf->tf_tpg_nacl_stat_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 418 | configfs_add_default_group(&se_nacl->acl_fabric_stat_group, |
| 419 | &se_nacl->acl_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 420 | |
| 421 | return &se_nacl->acl_group; |
| 422 | } |
| 423 | |
| 424 | static void target_fabric_drop_nodeacl( |
| 425 | struct config_group *group, |
| 426 | struct config_item *item) |
| 427 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 428 | struct se_node_acl *se_nacl = container_of(to_config_group(item), |
| 429 | struct se_node_acl, acl_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 430 | |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 431 | configfs_remove_default_groups(&se_nacl->acl_group); |
| 432 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 433 | /* |
| 434 | * struct se_node_acl free is done in target_fabric_nacl_base_release() |
| 435 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 436 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | static struct configfs_group_operations target_fabric_nacl_group_ops = { |
| 440 | .make_group = target_fabric_make_nodeacl, |
| 441 | .drop_item = target_fabric_drop_nodeacl, |
| 442 | }; |
| 443 | |
| 444 | TF_CIT_SETUP(tpg_nacl, NULL, &target_fabric_nacl_group_ops, NULL); |
| 445 | |
| 446 | /* End of tfc_tpg_nacl_cit */ |
| 447 | |
| 448 | /* Start of tfc_tpg_np_base_cit */ |
| 449 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 450 | static void target_fabric_np_base_release(struct config_item *item) |
| 451 | { |
| 452 | struct se_tpg_np *se_tpg_np = container_of(to_config_group(item), |
| 453 | struct se_tpg_np, tpg_np_group); |
| 454 | struct se_portal_group *se_tpg = se_tpg_np->tpg_np_parent; |
| 455 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 456 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 457 | tf->tf_ops->fabric_drop_np(se_tpg_np); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 458 | } |
| 459 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 460 | static struct configfs_item_operations target_fabric_np_base_item_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 461 | .release = target_fabric_np_base_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 462 | }; |
| 463 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 464 | 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] | 465 | |
| 466 | /* End of tfc_tpg_np_base_cit */ |
| 467 | |
| 468 | /* Start of tfc_tpg_np_cit */ |
| 469 | |
| 470 | static struct config_group *target_fabric_make_np( |
| 471 | struct config_group *group, |
| 472 | const char *name) |
| 473 | { |
| 474 | struct se_portal_group *se_tpg = container_of(group, |
| 475 | struct se_portal_group, tpg_np_group); |
| 476 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 477 | struct se_tpg_np *se_tpg_np; |
| 478 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 479 | if (!tf->tf_ops->fabric_make_np) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 480 | pr_err("tf->tf_ops.fabric_make_np is NULL\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 481 | return ERR_PTR(-ENOSYS); |
| 482 | } |
| 483 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 484 | 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] | 485 | if (!se_tpg_np || IS_ERR(se_tpg_np)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 486 | return ERR_PTR(-EINVAL); |
| 487 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 488 | se_tpg_np->tpg_np_parent = se_tpg; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 489 | config_group_init_type_name(&se_tpg_np->tpg_np_group, name, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 490 | &tf->tf_tpg_np_base_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 491 | |
| 492 | return &se_tpg_np->tpg_np_group; |
| 493 | } |
| 494 | |
| 495 | static void target_fabric_drop_np( |
| 496 | struct config_group *group, |
| 497 | struct config_item *item) |
| 498 | { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 499 | /* |
| 500 | * struct se_tpg_np is released via target_fabric_np_base_release() |
| 501 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 502 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | static struct configfs_group_operations target_fabric_np_group_ops = { |
| 506 | .make_group = &target_fabric_make_np, |
| 507 | .drop_item = &target_fabric_drop_np, |
| 508 | }; |
| 509 | |
| 510 | TF_CIT_SETUP(tpg_np, NULL, &target_fabric_np_group_ops, NULL); |
| 511 | |
| 512 | /* End of tfc_tpg_np_cit */ |
| 513 | |
| 514 | /* Start of tfc_tpg_port_cit */ |
| 515 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 516 | static struct se_lun *item_to_lun(struct config_item *item) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 517 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 518 | return container_of(to_config_group(item), struct se_lun, |
| 519 | lun_group); |
| 520 | } |
| 521 | |
| 522 | static ssize_t target_fabric_port_alua_tg_pt_gp_show(struct config_item *item, |
| 523 | char *page) |
| 524 | { |
| 525 | struct se_lun *lun = item_to_lun(item); |
| 526 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 527 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 528 | return -ENODEV; |
| 529 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 530 | return core_alua_show_tg_pt_gp_info(lun, page); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 531 | } |
| 532 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 533 | static ssize_t target_fabric_port_alua_tg_pt_gp_store(struct config_item *item, |
| 534 | const char *page, size_t count) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 535 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 536 | struct se_lun *lun = item_to_lun(item); |
| 537 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 538 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 539 | return -ENODEV; |
| 540 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 541 | return core_alua_store_tg_pt_gp_info(lun, page, count); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 542 | } |
| 543 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 544 | static ssize_t target_fabric_port_alua_tg_pt_offline_show( |
| 545 | struct config_item *item, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 546 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 547 | struct se_lun *lun = item_to_lun(item); |
| 548 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 549 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 550 | return -ENODEV; |
| 551 | |
| 552 | return core_alua_show_offline_bit(lun, page); |
| 553 | } |
| 554 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 555 | static ssize_t target_fabric_port_alua_tg_pt_offline_store( |
| 556 | struct config_item *item, const char *page, size_t count) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 557 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 558 | struct se_lun *lun = item_to_lun(item); |
| 559 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 560 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 561 | return -ENODEV; |
| 562 | |
| 563 | return core_alua_store_offline_bit(lun, page, count); |
| 564 | } |
| 565 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 566 | static ssize_t target_fabric_port_alua_tg_pt_status_show( |
| 567 | struct config_item *item, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 568 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 569 | struct se_lun *lun = item_to_lun(item); |
| 570 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 571 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 572 | return -ENODEV; |
| 573 | |
| 574 | return core_alua_show_secondary_status(lun, page); |
| 575 | } |
| 576 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 577 | static ssize_t target_fabric_port_alua_tg_pt_status_store( |
| 578 | struct config_item *item, const char *page, size_t count) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 579 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 580 | struct se_lun *lun = item_to_lun(item); |
| 581 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 582 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 583 | return -ENODEV; |
| 584 | |
| 585 | return core_alua_store_secondary_status(lun, page, count); |
| 586 | } |
| 587 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 588 | static ssize_t target_fabric_port_alua_tg_pt_write_md_show( |
| 589 | struct config_item *item, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 590 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 591 | struct se_lun *lun = item_to_lun(item); |
| 592 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 593 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 594 | return -ENODEV; |
| 595 | |
| 596 | return core_alua_show_secondary_write_metadata(lun, page); |
| 597 | } |
| 598 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 599 | static ssize_t target_fabric_port_alua_tg_pt_write_md_store( |
| 600 | struct config_item *item, const char *page, size_t count) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 601 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 602 | struct se_lun *lun = item_to_lun(item); |
| 603 | |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 604 | if (!lun || !lun->lun_se_dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 605 | return -ENODEV; |
| 606 | |
| 607 | return core_alua_store_secondary_write_metadata(lun, page, count); |
| 608 | } |
| 609 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 610 | CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_gp); |
| 611 | CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_offline); |
| 612 | CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_status); |
| 613 | CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_write_md); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 614 | |
| 615 | static struct configfs_attribute *target_fabric_port_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 616 | &target_fabric_port_attr_alua_tg_pt_gp, |
| 617 | &target_fabric_port_attr_alua_tg_pt_offline, |
| 618 | &target_fabric_port_attr_alua_tg_pt_status, |
| 619 | &target_fabric_port_attr_alua_tg_pt_write_md, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 620 | NULL, |
| 621 | }; |
| 622 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 623 | static int target_fabric_port_link( |
| 624 | struct config_item *lun_ci, |
| 625 | struct config_item *se_dev_ci) |
| 626 | { |
| 627 | struct config_item *tpg_ci; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 628 | struct se_lun *lun = container_of(to_config_group(lun_ci), |
| 629 | struct se_lun, lun_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 630 | struct se_portal_group *se_tpg; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 631 | struct se_device *dev = |
| 632 | 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] | 633 | struct target_fabric_configfs *tf; |
| 634 | int ret; |
| 635 | |
Nicholas Bellinger | 0ff8754 | 2012-12-04 23:43:57 -0800 | [diff] [blame] | 636 | if (dev->dev_link_magic != SE_DEV_LINK_MAGIC) { |
| 637 | pr_err("Bad dev->dev_link_magic, not a valid se_dev_ci pointer:" |
| 638 | " %p to struct se_device: %p\n", se_dev_ci, dev); |
| 639 | return -EFAULT; |
| 640 | } |
| 641 | |
Nicholas Bellinger | faa06ab | 2013-01-31 14:56:12 -0800 | [diff] [blame] | 642 | if (!(dev->dev_flags & DF_CONFIGURED)) { |
| 643 | pr_err("se_device not configured yet, cannot port link\n"); |
| 644 | return -ENODEV; |
| 645 | } |
| 646 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 647 | tpg_ci = &lun_ci->ci_parent->ci_group->cg_item; |
| 648 | se_tpg = container_of(to_config_group(tpg_ci), |
| 649 | struct se_portal_group, tpg_group); |
| 650 | tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 651 | |
| 652 | if (lun->lun_se_dev != NULL) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 653 | pr_err("Port Symlink already exists\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 654 | return -EEXIST; |
| 655 | } |
| 656 | |
Nicholas Bellinger | 6bb8261 | 2015-05-10 19:31:10 -0700 | [diff] [blame] | 657 | ret = core_dev_add_lun(se_tpg, dev, lun); |
| 658 | if (ret) { |
| 659 | pr_err("core_dev_add_lun() failed: %d\n", ret); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 660 | goto out; |
| 661 | } |
| 662 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 663 | if (tf->tf_ops->fabric_post_link) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 664 | /* |
| 665 | * Call the optional fabric_post_link() to allow a |
| 666 | * fabric module to setup any additional state once |
| 667 | * core_dev_add_lun() has been called.. |
| 668 | */ |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 669 | tf->tf_ops->fabric_post_link(se_tpg, lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | return 0; |
| 673 | out: |
| 674 | return ret; |
| 675 | } |
| 676 | |
| 677 | static int target_fabric_port_unlink( |
| 678 | struct config_item *lun_ci, |
| 679 | struct config_item *se_dev_ci) |
| 680 | { |
| 681 | struct se_lun *lun = container_of(to_config_group(lun_ci), |
| 682 | struct se_lun, lun_group); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 683 | struct se_portal_group *se_tpg = lun->lun_tpg; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 684 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
| 685 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 686 | if (tf->tf_ops->fabric_pre_unlink) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 687 | /* |
| 688 | * Call the optional fabric_pre_unlink() to allow a |
| 689 | * fabric module to release any additional stat before |
| 690 | * core_dev_del_lun() is called. |
| 691 | */ |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 692 | tf->tf_ops->fabric_pre_unlink(se_tpg, lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 693 | } |
| 694 | |
Andy Grover | cd9d7cb | 2014-06-30 16:39:44 -0700 | [diff] [blame] | 695 | core_dev_del_lun(se_tpg, lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 696 | return 0; |
| 697 | } |
| 698 | |
Nicholas Bellinger | 6bb8261 | 2015-05-10 19:31:10 -0700 | [diff] [blame] | 699 | static void target_fabric_port_release(struct config_item *item) |
| 700 | { |
| 701 | struct se_lun *lun = container_of(to_config_group(item), |
| 702 | struct se_lun, lun_group); |
| 703 | |
| 704 | kfree_rcu(lun, rcu_head); |
| 705 | } |
| 706 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 707 | static struct configfs_item_operations target_fabric_port_item_ops = { |
Nicholas Bellinger | 6bb8261 | 2015-05-10 19:31:10 -0700 | [diff] [blame] | 708 | .release = target_fabric_port_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 709 | .allow_link = target_fabric_port_link, |
| 710 | .drop_link = target_fabric_port_unlink, |
| 711 | }; |
| 712 | |
| 713 | TF_CIT_SETUP(tpg_port, &target_fabric_port_item_ops, NULL, target_fabric_port_attrs); |
| 714 | |
| 715 | /* End of tfc_tpg_port_cit */ |
| 716 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 717 | /* Start of tfc_tpg_port_stat_cit */ |
| 718 | |
| 719 | static struct config_group *target_core_port_stat_mkdir( |
| 720 | struct config_group *group, |
| 721 | const char *name) |
| 722 | { |
| 723 | return ERR_PTR(-ENOSYS); |
| 724 | } |
| 725 | |
| 726 | static void target_core_port_stat_rmdir( |
| 727 | struct config_group *group, |
| 728 | struct config_item *item) |
| 729 | { |
| 730 | return; |
| 731 | } |
| 732 | |
| 733 | static struct configfs_group_operations target_fabric_port_stat_group_ops = { |
| 734 | .make_group = target_core_port_stat_mkdir, |
| 735 | .drop_item = target_core_port_stat_rmdir, |
| 736 | }; |
| 737 | |
| 738 | TF_CIT_SETUP(tpg_port_stat, NULL, &target_fabric_port_stat_group_ops, NULL); |
| 739 | |
| 740 | /* End of tfc_tpg_port_stat_cit */ |
| 741 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 742 | /* Start of tfc_tpg_lun_cit */ |
| 743 | |
| 744 | static struct config_group *target_fabric_make_lun( |
| 745 | struct config_group *group, |
| 746 | const char *name) |
| 747 | { |
| 748 | struct se_lun *lun; |
| 749 | struct se_portal_group *se_tpg = container_of(group, |
| 750 | struct se_portal_group, tpg_lun_group); |
| 751 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; |
Hannes Reinecke | f2d3068 | 2015-06-10 08:41:22 +0200 | [diff] [blame] | 752 | unsigned long long unpacked_lun; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 753 | int errno; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 754 | |
| 755 | if (strstr(name, "lun_") != name) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 756 | pr_err("Unable to locate \'_\" in" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 757 | " \"lun_$LUN_NUMBER\"\n"); |
| 758 | return ERR_PTR(-EINVAL); |
| 759 | } |
Hannes Reinecke | f2d3068 | 2015-06-10 08:41:22 +0200 | [diff] [blame] | 760 | errno = kstrtoull(name + 4, 0, &unpacked_lun); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 761 | if (errno) |
| 762 | return ERR_PTR(errno); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 763 | |
Nicholas Bellinger | 6bb8261 | 2015-05-10 19:31:10 -0700 | [diff] [blame] | 764 | lun = core_tpg_alloc_lun(se_tpg, unpacked_lun); |
| 765 | if (IS_ERR(lun)) |
| 766 | return ERR_CAST(lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 767 | |
| 768 | config_group_init_type_name(&lun->lun_group, name, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 769 | &tf->tf_tpg_port_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 770 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 771 | config_group_init_type_name(&lun->port_stat_grps.stat_group, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 772 | "statistics", &tf->tf_tpg_port_stat_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 773 | configfs_add_default_group(&lun->port_stat_grps.stat_group, |
| 774 | &lun->lun_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 775 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 776 | target_stat_setup_port_default_groups(lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 777 | |
| 778 | return &lun->lun_group; |
| 779 | } |
| 780 | |
| 781 | static void target_fabric_drop_lun( |
| 782 | struct config_group *group, |
| 783 | struct config_item *item) |
| 784 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 785 | struct se_lun *lun = container_of(to_config_group(item), |
| 786 | struct se_lun, lun_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 787 | |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 788 | configfs_remove_default_groups(&lun->port_stat_grps.stat_group); |
| 789 | configfs_remove_default_groups(&lun->lun_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 790 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 791 | config_item_put(item); |
| 792 | } |
| 793 | |
| 794 | static struct configfs_group_operations target_fabric_lun_group_ops = { |
| 795 | .make_group = &target_fabric_make_lun, |
| 796 | .drop_item = &target_fabric_drop_lun, |
| 797 | }; |
| 798 | |
| 799 | TF_CIT_SETUP(tpg_lun, NULL, &target_fabric_lun_group_ops, NULL); |
| 800 | |
| 801 | /* End of tfc_tpg_lun_cit */ |
| 802 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 803 | TF_CIT_SETUP_DRV(tpg_attrib, NULL, NULL); |
| 804 | TF_CIT_SETUP_DRV(tpg_auth, NULL, NULL); |
| 805 | TF_CIT_SETUP_DRV(tpg_param, NULL, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 806 | |
| 807 | /* Start of tfc_tpg_base_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 808 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 809 | static void target_fabric_tpg_release(struct config_item *item) |
| 810 | { |
| 811 | struct se_portal_group *se_tpg = container_of(to_config_group(item), |
| 812 | struct se_portal_group, tpg_group); |
| 813 | struct se_wwn *wwn = se_tpg->se_tpg_wwn; |
| 814 | struct target_fabric_configfs *tf = wwn->wwn_tf; |
| 815 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 816 | tf->tf_ops->fabric_drop_tpg(se_tpg); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 817 | } |
| 818 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 819 | static struct configfs_item_operations target_fabric_tpg_base_item_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 820 | .release = target_fabric_tpg_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 821 | }; |
| 822 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 823 | 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] | 824 | |
| 825 | /* End of tfc_tpg_base_cit */ |
| 826 | |
| 827 | /* Start of tfc_tpg_cit */ |
| 828 | |
| 829 | static struct config_group *target_fabric_make_tpg( |
| 830 | struct config_group *group, |
| 831 | const char *name) |
| 832 | { |
| 833 | struct se_wwn *wwn = container_of(group, struct se_wwn, wwn_group); |
| 834 | struct target_fabric_configfs *tf = wwn->wwn_tf; |
| 835 | struct se_portal_group *se_tpg; |
| 836 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 837 | if (!tf->tf_ops->fabric_make_tpg) { |
| 838 | pr_err("tf->tf_ops->fabric_make_tpg is NULL\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 839 | return ERR_PTR(-ENOSYS); |
| 840 | } |
| 841 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 842 | se_tpg = tf->tf_ops->fabric_make_tpg(wwn, group, name); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 843 | if (!se_tpg || IS_ERR(se_tpg)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 844 | return ERR_PTR(-EINVAL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 845 | |
| 846 | config_group_init_type_name(&se_tpg->tpg_group, name, |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 847 | &tf->tf_tpg_base_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 848 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 849 | config_group_init_type_name(&se_tpg->tpg_lun_group, "lun", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 850 | &tf->tf_tpg_lun_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 851 | configfs_add_default_group(&se_tpg->tpg_lun_group, |
| 852 | &se_tpg->tpg_group); |
| 853 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 854 | config_group_init_type_name(&se_tpg->tpg_np_group, "np", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 855 | &tf->tf_tpg_np_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 856 | configfs_add_default_group(&se_tpg->tpg_np_group, |
| 857 | &se_tpg->tpg_group); |
| 858 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 859 | config_group_init_type_name(&se_tpg->tpg_acl_group, "acls", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 860 | &tf->tf_tpg_nacl_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 861 | configfs_add_default_group(&se_tpg->tpg_acl_group, |
| 862 | &se_tpg->tpg_group); |
| 863 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 864 | config_group_init_type_name(&se_tpg->tpg_attrib_group, "attrib", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 865 | &tf->tf_tpg_attrib_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 866 | configfs_add_default_group(&se_tpg->tpg_attrib_group, |
| 867 | &se_tpg->tpg_group); |
| 868 | |
Nicholas Bellinger | e4b512e | 2013-06-19 18:37:00 -0700 | [diff] [blame] | 869 | config_group_init_type_name(&se_tpg->tpg_auth_group, "auth", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 870 | &tf->tf_tpg_auth_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 871 | configfs_add_default_group(&se_tpg->tpg_auth_group, |
| 872 | &se_tpg->tpg_group); |
| 873 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 874 | config_group_init_type_name(&se_tpg->tpg_param_group, "param", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 875 | &tf->tf_tpg_param_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 876 | configfs_add_default_group(&se_tpg->tpg_param_group, |
| 877 | &se_tpg->tpg_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 878 | |
| 879 | return &se_tpg->tpg_group; |
| 880 | } |
| 881 | |
| 882 | static void target_fabric_drop_tpg( |
| 883 | struct config_group *group, |
| 884 | struct config_item *item) |
| 885 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 886 | struct se_portal_group *se_tpg = container_of(to_config_group(item), |
| 887 | struct se_portal_group, tpg_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 888 | |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 889 | configfs_remove_default_groups(&se_tpg->tpg_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 890 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 891 | } |
| 892 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 893 | static void target_fabric_release_wwn(struct config_item *item) |
| 894 | { |
| 895 | struct se_wwn *wwn = container_of(to_config_group(item), |
| 896 | struct se_wwn, wwn_group); |
| 897 | struct target_fabric_configfs *tf = wwn->wwn_tf; |
| 898 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 899 | tf->tf_ops->fabric_drop_wwn(wwn); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | static struct configfs_item_operations target_fabric_tpg_item_ops = { |
| 903 | .release = target_fabric_release_wwn, |
| 904 | }; |
| 905 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 906 | static struct configfs_group_operations target_fabric_tpg_group_ops = { |
| 907 | .make_group = target_fabric_make_tpg, |
| 908 | .drop_item = target_fabric_drop_tpg, |
| 909 | }; |
| 910 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 911 | TF_CIT_SETUP(tpg, &target_fabric_tpg_item_ops, &target_fabric_tpg_group_ops, |
| 912 | NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 913 | |
| 914 | /* End of tfc_tpg_cit */ |
| 915 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 916 | /* Start of tfc_wwn_fabric_stats_cit */ |
| 917 | /* |
| 918 | * This is used as a placeholder for struct se_wwn->fabric_stat_group |
| 919 | * to allow fabrics access to ->fabric_stat_group->default_groups[] |
| 920 | */ |
| 921 | TF_CIT_SETUP(wwn_fabric_stats, NULL, NULL, NULL); |
| 922 | |
| 923 | /* End of tfc_wwn_fabric_stats_cit */ |
| 924 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 925 | /* Start of tfc_wwn_cit */ |
| 926 | |
| 927 | static struct config_group *target_fabric_make_wwn( |
| 928 | struct config_group *group, |
| 929 | const char *name) |
| 930 | { |
| 931 | struct target_fabric_configfs *tf = container_of(group, |
| 932 | struct target_fabric_configfs, tf_group); |
| 933 | struct se_wwn *wwn; |
| 934 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 935 | if (!tf->tf_ops->fabric_make_wwn) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 936 | pr_err("tf->tf_ops.fabric_make_wwn is NULL\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 937 | return ERR_PTR(-ENOSYS); |
| 938 | } |
| 939 | |
Christoph Hellwig | ef0caf8 | 2015-05-03 08:50:53 +0200 | [diff] [blame] | 940 | wwn = tf->tf_ops->fabric_make_wwn(tf, group, name); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 941 | if (!wwn || IS_ERR(wwn)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 942 | return ERR_PTR(-EINVAL); |
| 943 | |
| 944 | wwn->wwn_tf = tf; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 945 | |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 946 | config_group_init_type_name(&wwn->wwn_group, name, &tf->tf_tpg_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 947 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 948 | config_group_init_type_name(&wwn->fabric_stat_group, "fabric_statistics", |
Christoph Hellwig | 968ebe7 | 2015-05-03 08:50:55 +0200 | [diff] [blame] | 949 | &tf->tf_wwn_fabric_stats_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 950 | configfs_add_default_group(&wwn->fabric_stat_group, &wwn->wwn_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 951 | |
| 952 | return &wwn->wwn_group; |
| 953 | } |
| 954 | |
| 955 | static void target_fabric_drop_wwn( |
| 956 | struct config_group *group, |
| 957 | struct config_item *item) |
| 958 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 959 | struct se_wwn *wwn = container_of(to_config_group(item), |
| 960 | struct se_wwn, wwn_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 961 | |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 962 | configfs_remove_default_groups(&wwn->wwn_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 963 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | static struct configfs_group_operations target_fabric_wwn_group_ops = { |
| 967 | .make_group = target_fabric_make_wwn, |
| 968 | .drop_item = target_fabric_drop_wwn, |
| 969 | }; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 970 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 971 | TF_CIT_SETUP_DRV(wwn, NULL, &target_fabric_wwn_group_ops); |
| 972 | TF_CIT_SETUP_DRV(discovery, NULL, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 973 | |
| 974 | int target_fabric_setup_cits(struct target_fabric_configfs *tf) |
| 975 | { |
| 976 | target_fabric_setup_discovery_cit(tf); |
| 977 | target_fabric_setup_wwn_cit(tf); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 978 | target_fabric_setup_wwn_fabric_stats_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 979 | target_fabric_setup_tpg_cit(tf); |
| 980 | target_fabric_setup_tpg_base_cit(tf); |
| 981 | target_fabric_setup_tpg_port_cit(tf); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 982 | target_fabric_setup_tpg_port_stat_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 983 | target_fabric_setup_tpg_lun_cit(tf); |
| 984 | target_fabric_setup_tpg_np_cit(tf); |
| 985 | target_fabric_setup_tpg_np_base_cit(tf); |
| 986 | target_fabric_setup_tpg_attrib_cit(tf); |
Nicholas Bellinger | e4b512e | 2013-06-19 18:37:00 -0700 | [diff] [blame] | 987 | target_fabric_setup_tpg_auth_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 988 | target_fabric_setup_tpg_param_cit(tf); |
| 989 | target_fabric_setup_tpg_nacl_cit(tf); |
| 990 | target_fabric_setup_tpg_nacl_base_cit(tf); |
| 991 | target_fabric_setup_tpg_nacl_attrib_cit(tf); |
| 992 | target_fabric_setup_tpg_nacl_auth_cit(tf); |
| 993 | target_fabric_setup_tpg_nacl_param_cit(tf); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 994 | target_fabric_setup_tpg_nacl_stat_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 995 | target_fabric_setup_tpg_mappedlun_cit(tf); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 996 | target_fabric_setup_tpg_mappedlun_stat_cit(tf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 997 | |
| 998 | return 0; |
| 999 | } |