Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Filename: target_core_configfs.c |
| 3 | * |
| 4 | * This file contains ConfigFS logic for the Generic Target Engine project. |
| 5 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 6 | * (c) Copyright 2008-2013 Datera, Inc. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 7 | * |
| 8 | * Nicholas A. Bellinger <nab@kernel.org> |
| 9 | * |
| 10 | * based on configfs Copyright (C) 2005 Oracle. All rights reserved. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | ****************************************************************************/ |
| 22 | |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/moduleparam.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 25 | #include <generated/utsrelease.h> |
| 26 | #include <linux/utsname.h> |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/fs.h> |
| 29 | #include <linux/namei.h> |
| 30 | #include <linux/slab.h> |
| 31 | #include <linux/types.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/unistd.h> |
| 34 | #include <linux/string.h> |
| 35 | #include <linux/parser.h> |
| 36 | #include <linux/syscalls.h> |
| 37 | #include <linux/configfs.h> |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 38 | #include <linux/spinlock.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 39 | |
| 40 | #include <target/target_core_base.h> |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 41 | #include <target/target_core_backend.h> |
| 42 | #include <target/target_core_fabric.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 43 | #include <target/target_core_fabric_configfs.h> |
| 44 | #include <target/target_core_configfs.h> |
| 45 | #include <target/configfs_macros.h> |
| 46 | |
Christoph Hellwig | e26d99a | 2011-11-14 12:30:30 -0500 | [diff] [blame] | 47 | #include "target_core_internal.h" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 48 | #include "target_core_alua.h" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 49 | #include "target_core_pr.h" |
| 50 | #include "target_core_rd.h" |
Nicholas Bellinger | f99715a | 2013-08-22 12:48:53 -0700 | [diff] [blame] | 51 | #include "target_core_xcopy.h" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 52 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 53 | #define TB_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \ |
| 54 | static void target_core_setup_##_name##_cit(struct se_subsystem_api *sa) \ |
| 55 | { \ |
| 56 | struct target_backend_cits *tbc = &sa->tb_cits; \ |
| 57 | struct config_item_type *cit = &tbc->tb_##_name##_cit; \ |
| 58 | \ |
| 59 | cit->ct_item_ops = _item_ops; \ |
| 60 | cit->ct_group_ops = _group_ops; \ |
| 61 | cit->ct_attrs = _attrs; \ |
| 62 | cit->ct_owner = sa->owner; \ |
| 63 | pr_debug("Setup generic %s\n", __stringify(_name)); \ |
| 64 | } |
| 65 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 66 | extern struct t10_alua_lu_gp *default_lu_gp; |
| 67 | |
Roland Dreier | d0f474e | 2012-01-12 10:41:18 -0800 | [diff] [blame] | 68 | static LIST_HEAD(g_tf_list); |
| 69 | static DEFINE_MUTEX(g_tf_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 70 | |
| 71 | struct target_core_configfs_attribute { |
| 72 | struct configfs_attribute attr; |
| 73 | ssize_t (*show)(void *, char *); |
| 74 | ssize_t (*store)(void *, const char *, size_t); |
| 75 | }; |
| 76 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 77 | static struct config_group target_core_hbagroup; |
| 78 | static struct config_group alua_group; |
| 79 | static struct config_group alua_lu_gps_group; |
| 80 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 81 | static inline struct se_hba * |
| 82 | item_to_hba(struct config_item *item) |
| 83 | { |
| 84 | return container_of(to_config_group(item), struct se_hba, hba_group); |
| 85 | } |
| 86 | |
| 87 | /* |
| 88 | * Attributes for /sys/kernel/config/target/ |
| 89 | */ |
| 90 | static ssize_t target_core_attr_show(struct config_item *item, |
| 91 | struct configfs_attribute *attr, |
| 92 | char *page) |
| 93 | { |
| 94 | return sprintf(page, "Target Engine Core ConfigFS Infrastructure %s" |
| 95 | " on %s/%s on "UTS_RELEASE"\n", TARGET_CORE_CONFIGFS_VERSION, |
| 96 | utsname()->sysname, utsname()->machine); |
| 97 | } |
| 98 | |
| 99 | static struct configfs_item_operations target_core_fabric_item_ops = { |
| 100 | .show_attribute = target_core_attr_show, |
| 101 | }; |
| 102 | |
| 103 | static struct configfs_attribute target_core_item_attr_version = { |
| 104 | .ca_owner = THIS_MODULE, |
| 105 | .ca_name = "version", |
| 106 | .ca_mode = S_IRUGO, |
| 107 | }; |
| 108 | |
| 109 | static struct target_fabric_configfs *target_core_get_fabric( |
| 110 | const char *name) |
| 111 | { |
| 112 | struct target_fabric_configfs *tf; |
| 113 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 114 | if (!name) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 115 | return NULL; |
| 116 | |
| 117 | mutex_lock(&g_tf_lock); |
| 118 | list_for_each_entry(tf, &g_tf_list, tf_list) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 119 | if (!strcmp(tf->tf_name, name)) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 120 | atomic_inc(&tf->tf_access_cnt); |
| 121 | mutex_unlock(&g_tf_lock); |
| 122 | return tf; |
| 123 | } |
| 124 | } |
| 125 | mutex_unlock(&g_tf_lock); |
| 126 | |
| 127 | return NULL; |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Called from struct target_core_group_ops->make_group() |
| 132 | */ |
| 133 | static struct config_group *target_core_register_fabric( |
| 134 | struct config_group *group, |
| 135 | const char *name) |
| 136 | { |
| 137 | struct target_fabric_configfs *tf; |
| 138 | int ret; |
| 139 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 140 | pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 141 | " %s\n", group, name); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 142 | |
| 143 | tf = target_core_get_fabric(name); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 144 | if (!tf) { |
Nicholas Bellinger | 6255491 | 2015-03-20 11:36:50 -0700 | [diff] [blame] | 145 | pr_debug("target_core_register_fabric() trying autoload for %s\n", |
| 146 | name); |
Roland Dreier | e7b7af6 | 2014-11-14 12:54:36 -0800 | [diff] [blame] | 147 | |
| 148 | /* |
| 149 | * Below are some hardcoded request_module() calls to automatically |
| 150 | * local fabric modules when the following is called: |
| 151 | * |
| 152 | * mkdir -p /sys/kernel/config/target/$MODULE_NAME |
| 153 | * |
| 154 | * Note that this does not limit which TCM fabric module can be |
| 155 | * registered, but simply provids auto loading logic for modules with |
| 156 | * mkdir(2) system calls with known TCM fabric modules. |
| 157 | */ |
| 158 | |
| 159 | if (!strncmp(name, "iscsi", 5)) { |
| 160 | /* |
| 161 | * Automatically load the LIO Target fabric module when the |
| 162 | * following is called: |
| 163 | * |
| 164 | * mkdir -p $CONFIGFS/target/iscsi |
| 165 | */ |
| 166 | ret = request_module("iscsi_target_mod"); |
| 167 | if (ret < 0) { |
Nicholas Bellinger | 6255491 | 2015-03-20 11:36:50 -0700 | [diff] [blame] | 168 | pr_debug("request_module() failed for" |
| 169 | " iscsi_target_mod.ko: %d\n", ret); |
Roland Dreier | e7b7af6 | 2014-11-14 12:54:36 -0800 | [diff] [blame] | 170 | return ERR_PTR(-EINVAL); |
| 171 | } |
| 172 | } else if (!strncmp(name, "loopback", 8)) { |
| 173 | /* |
| 174 | * Automatically load the tcm_loop fabric module when the |
| 175 | * following is called: |
| 176 | * |
| 177 | * mkdir -p $CONFIGFS/target/loopback |
| 178 | */ |
| 179 | ret = request_module("tcm_loop"); |
| 180 | if (ret < 0) { |
Nicholas Bellinger | 6255491 | 2015-03-20 11:36:50 -0700 | [diff] [blame] | 181 | pr_debug("request_module() failed for" |
| 182 | " tcm_loop.ko: %d\n", ret); |
Roland Dreier | e7b7af6 | 2014-11-14 12:54:36 -0800 | [diff] [blame] | 183 | return ERR_PTR(-EINVAL); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | tf = target_core_get_fabric(name); |
| 188 | } |
| 189 | |
| 190 | if (!tf) { |
Nicholas Bellinger | 6255491 | 2015-03-20 11:36:50 -0700 | [diff] [blame] | 191 | pr_debug("target_core_get_fabric() failed for %s\n", |
| 192 | name); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 193 | return ERR_PTR(-EINVAL); |
| 194 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 195 | pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 196 | " %s\n", tf->tf_name); |
| 197 | /* |
| 198 | * On a successful target_core_get_fabric() look, the returned |
| 199 | * struct target_fabric_configfs *tf will contain a usage reference. |
| 200 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 201 | pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n", |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 202 | &tf->tf_cit_tmpl.tfc_wwn_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 203 | |
| 204 | tf->tf_group.default_groups = tf->tf_default_groups; |
| 205 | tf->tf_group.default_groups[0] = &tf->tf_disc_group; |
| 206 | tf->tf_group.default_groups[1] = NULL; |
| 207 | |
| 208 | config_group_init_type_name(&tf->tf_group, name, |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 209 | &tf->tf_cit_tmpl.tfc_wwn_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 210 | config_group_init_type_name(&tf->tf_disc_group, "discovery_auth", |
Andy Grover | d80e224d | 2013-10-09 11:05:56 -0700 | [diff] [blame] | 211 | &tf->tf_cit_tmpl.tfc_discovery_cit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 212 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 213 | pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 214 | " %s\n", tf->tf_group.cg_item.ci_name); |
| 215 | /* |
| 216 | * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item() |
| 217 | */ |
| 218 | tf->tf_ops.tf_subsys = tf->tf_subsys; |
| 219 | tf->tf_fabric = &tf->tf_group.cg_item; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 220 | pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 221 | " for %s\n", name); |
| 222 | |
| 223 | return &tf->tf_group; |
| 224 | } |
| 225 | |
| 226 | /* |
| 227 | * Called from struct target_core_group_ops->drop_item() |
| 228 | */ |
| 229 | static void target_core_deregister_fabric( |
| 230 | struct config_group *group, |
| 231 | struct config_item *item) |
| 232 | { |
| 233 | struct target_fabric_configfs *tf = container_of( |
| 234 | to_config_group(item), struct target_fabric_configfs, tf_group); |
| 235 | struct config_group *tf_group; |
| 236 | struct config_item *df_item; |
| 237 | int i; |
| 238 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 239 | pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 240 | " tf list\n", config_item_name(item)); |
| 241 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 242 | pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 243 | " %s\n", tf->tf_name); |
| 244 | atomic_dec(&tf->tf_access_cnt); |
| 245 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 246 | pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 247 | " tf->tf_fabric for %s\n", tf->tf_name); |
| 248 | tf->tf_fabric = NULL; |
| 249 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 250 | pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 251 | " %s\n", config_item_name(item)); |
| 252 | |
| 253 | tf_group = &tf->tf_group; |
| 254 | for (i = 0; tf_group->default_groups[i]; i++) { |
| 255 | df_item = &tf_group->default_groups[i]->cg_item; |
| 256 | tf_group->default_groups[i] = NULL; |
| 257 | config_item_put(df_item); |
| 258 | } |
| 259 | config_item_put(item); |
| 260 | } |
| 261 | |
| 262 | static struct configfs_group_operations target_core_fabric_group_ops = { |
| 263 | .make_group = &target_core_register_fabric, |
| 264 | .drop_item = &target_core_deregister_fabric, |
| 265 | }; |
| 266 | |
| 267 | /* |
| 268 | * All item attributes appearing in /sys/kernel/target/ appear here. |
| 269 | */ |
| 270 | static struct configfs_attribute *target_core_fabric_item_attrs[] = { |
| 271 | &target_core_item_attr_version, |
| 272 | NULL, |
| 273 | }; |
| 274 | |
| 275 | /* |
| 276 | * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/ |
| 277 | */ |
| 278 | static struct config_item_type target_core_fabrics_item = { |
| 279 | .ct_item_ops = &target_core_fabric_item_ops, |
| 280 | .ct_group_ops = &target_core_fabric_group_ops, |
| 281 | .ct_attrs = target_core_fabric_item_attrs, |
| 282 | .ct_owner = THIS_MODULE, |
| 283 | }; |
| 284 | |
| 285 | static struct configfs_subsystem target_core_fabrics = { |
| 286 | .su_group = { |
| 287 | .cg_item = { |
| 288 | .ci_namebuf = "target", |
| 289 | .ci_type = &target_core_fabrics_item, |
| 290 | }, |
| 291 | }, |
| 292 | }; |
| 293 | |
Nicholas Bellinger | 56d128f | 2013-08-22 11:32:31 -0700 | [diff] [blame] | 294 | struct configfs_subsystem *target_core_subsystem[] = { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 295 | &target_core_fabrics, |
| 296 | NULL, |
| 297 | }; |
| 298 | |
| 299 | /*############################################################################## |
| 300 | // Start functions called by external Target Fabrics Modules |
| 301 | //############################################################################*/ |
| 302 | |
| 303 | /* |
| 304 | * First function called by fabric modules to: |
| 305 | * |
| 306 | * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer. |
| 307 | * 2) Add struct target_fabric_configfs to g_tf_list |
| 308 | * 3) Return struct target_fabric_configfs to fabric module to be passed |
| 309 | * into target_fabric_configfs_register(). |
| 310 | */ |
| 311 | struct target_fabric_configfs *target_fabric_configfs_init( |
| 312 | struct module *fabric_mod, |
| 313 | const char *name) |
| 314 | { |
| 315 | struct target_fabric_configfs *tf; |
| 316 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 317 | if (!(name)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 318 | pr_err("Unable to locate passed fabric name\n"); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 319 | return ERR_PTR(-EINVAL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 320 | } |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 321 | if (strlen(name) >= TARGET_FABRIC_NAME_SIZE) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 322 | pr_err("Passed name: %s exceeds TARGET_FABRIC" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 323 | "_NAME_SIZE\n", name); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 324 | return ERR_PTR(-EINVAL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | tf = kzalloc(sizeof(struct target_fabric_configfs), GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 328 | if (!tf) |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 329 | return ERR_PTR(-ENOMEM); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 330 | |
| 331 | INIT_LIST_HEAD(&tf->tf_list); |
| 332 | atomic_set(&tf->tf_access_cnt, 0); |
| 333 | /* |
| 334 | * Setup the default generic struct config_item_type's (cits) in |
| 335 | * struct target_fabric_configfs->tf_cit_tmpl |
| 336 | */ |
| 337 | tf->tf_module = fabric_mod; |
| 338 | target_fabric_setup_cits(tf); |
| 339 | |
| 340 | tf->tf_subsys = target_core_subsystem[0]; |
| 341 | snprintf(tf->tf_name, TARGET_FABRIC_NAME_SIZE, "%s", name); |
| 342 | |
| 343 | mutex_lock(&g_tf_lock); |
| 344 | list_add_tail(&tf->tf_list, &g_tf_list); |
| 345 | mutex_unlock(&g_tf_lock); |
| 346 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 347 | pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 348 | ">>>>>>>>>>>>>>\n"); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 349 | pr_debug("Initialized struct target_fabric_configfs: %p for" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 350 | " %s\n", tf, tf->tf_name); |
| 351 | return tf; |
| 352 | } |
| 353 | EXPORT_SYMBOL(target_fabric_configfs_init); |
| 354 | |
| 355 | /* |
| 356 | * Called by fabric plugins after FAILED target_fabric_configfs_register() call. |
| 357 | */ |
| 358 | void target_fabric_configfs_free( |
| 359 | struct target_fabric_configfs *tf) |
| 360 | { |
| 361 | mutex_lock(&g_tf_lock); |
| 362 | list_del(&tf->tf_list); |
| 363 | mutex_unlock(&g_tf_lock); |
| 364 | |
| 365 | kfree(tf); |
| 366 | } |
| 367 | EXPORT_SYMBOL(target_fabric_configfs_free); |
| 368 | |
| 369 | /* |
| 370 | * Perform a sanity check of the passed tf->tf_ops before completing |
| 371 | * TCM fabric module registration. |
| 372 | */ |
| 373 | static int target_fabric_tf_ops_check( |
| 374 | struct target_fabric_configfs *tf) |
| 375 | { |
| 376 | struct target_core_fabric_ops *tfo = &tf->tf_ops; |
| 377 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 378 | if (!tfo->get_fabric_name) { |
| 379 | pr_err("Missing tfo->get_fabric_name()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 380 | return -EINVAL; |
| 381 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 382 | if (!tfo->get_fabric_proto_ident) { |
| 383 | pr_err("Missing tfo->get_fabric_proto_ident()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 384 | return -EINVAL; |
| 385 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 386 | if (!tfo->tpg_get_wwn) { |
| 387 | pr_err("Missing tfo->tpg_get_wwn()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 388 | return -EINVAL; |
| 389 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 390 | if (!tfo->tpg_get_tag) { |
| 391 | pr_err("Missing tfo->tpg_get_tag()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 392 | return -EINVAL; |
| 393 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 394 | if (!tfo->tpg_get_default_depth) { |
| 395 | pr_err("Missing tfo->tpg_get_default_depth()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 396 | return -EINVAL; |
| 397 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 398 | if (!tfo->tpg_get_pr_transport_id) { |
| 399 | pr_err("Missing tfo->tpg_get_pr_transport_id()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 400 | return -EINVAL; |
| 401 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 402 | if (!tfo->tpg_get_pr_transport_id_len) { |
| 403 | pr_err("Missing tfo->tpg_get_pr_transport_id_len()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 404 | return -EINVAL; |
| 405 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 406 | if (!tfo->tpg_check_demo_mode) { |
| 407 | pr_err("Missing tfo->tpg_check_demo_mode()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 408 | return -EINVAL; |
| 409 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 410 | if (!tfo->tpg_check_demo_mode_cache) { |
| 411 | pr_err("Missing tfo->tpg_check_demo_mode_cache()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 412 | return -EINVAL; |
| 413 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 414 | if (!tfo->tpg_check_demo_mode_write_protect) { |
| 415 | pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 416 | return -EINVAL; |
| 417 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 418 | if (!tfo->tpg_check_prod_mode_write_protect) { |
| 419 | pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 420 | return -EINVAL; |
| 421 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 422 | if (!tfo->tpg_alloc_fabric_acl) { |
| 423 | pr_err("Missing tfo->tpg_alloc_fabric_acl()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 424 | return -EINVAL; |
| 425 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 426 | if (!tfo->tpg_release_fabric_acl) { |
| 427 | pr_err("Missing tfo->tpg_release_fabric_acl()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 428 | return -EINVAL; |
| 429 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 430 | if (!tfo->tpg_get_inst_index) { |
| 431 | pr_err("Missing tfo->tpg_get_inst_index()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 432 | return -EINVAL; |
| 433 | } |
Christoph Hellwig | 3546297 | 2011-05-31 23:56:57 -0400 | [diff] [blame] | 434 | if (!tfo->release_cmd) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 435 | pr_err("Missing tfo->release_cmd()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 436 | return -EINVAL; |
| 437 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 438 | if (!tfo->shutdown_session) { |
| 439 | pr_err("Missing tfo->shutdown_session()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 440 | return -EINVAL; |
| 441 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 442 | if (!tfo->close_session) { |
| 443 | pr_err("Missing tfo->close_session()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 444 | return -EINVAL; |
| 445 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 446 | if (!tfo->sess_get_index) { |
| 447 | pr_err("Missing tfo->sess_get_index()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 448 | return -EINVAL; |
| 449 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 450 | if (!tfo->write_pending) { |
| 451 | pr_err("Missing tfo->write_pending()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 452 | return -EINVAL; |
| 453 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 454 | if (!tfo->write_pending_status) { |
| 455 | pr_err("Missing tfo->write_pending_status()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 456 | return -EINVAL; |
| 457 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 458 | if (!tfo->set_default_node_attributes) { |
| 459 | pr_err("Missing tfo->set_default_node_attributes()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 460 | return -EINVAL; |
| 461 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 462 | if (!tfo->get_task_tag) { |
| 463 | pr_err("Missing tfo->get_task_tag()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 464 | return -EINVAL; |
| 465 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 466 | if (!tfo->get_cmd_state) { |
| 467 | pr_err("Missing tfo->get_cmd_state()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 468 | return -EINVAL; |
| 469 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 470 | if (!tfo->queue_data_in) { |
| 471 | pr_err("Missing tfo->queue_data_in()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 472 | return -EINVAL; |
| 473 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 474 | if (!tfo->queue_status) { |
| 475 | pr_err("Missing tfo->queue_status()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 476 | return -EINVAL; |
| 477 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 478 | if (!tfo->queue_tm_rsp) { |
| 479 | pr_err("Missing tfo->queue_tm_rsp()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 480 | return -EINVAL; |
| 481 | } |
Nicholas Bellinger | 131e6ab | 2014-03-22 14:55:56 -0700 | [diff] [blame] | 482 | if (!tfo->aborted_task) { |
| 483 | pr_err("Missing tfo->aborted_task()\n"); |
| 484 | return -EINVAL; |
| 485 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 486 | /* |
| 487 | * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn() |
| 488 | * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in |
| 489 | * target_core_fabric_configfs.c WWN+TPG group context code. |
| 490 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 491 | if (!tfo->fabric_make_wwn) { |
| 492 | pr_err("Missing tfo->fabric_make_wwn()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 493 | return -EINVAL; |
| 494 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 495 | if (!tfo->fabric_drop_wwn) { |
| 496 | pr_err("Missing tfo->fabric_drop_wwn()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 497 | return -EINVAL; |
| 498 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 499 | if (!tfo->fabric_make_tpg) { |
| 500 | pr_err("Missing tfo->fabric_make_tpg()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 501 | return -EINVAL; |
| 502 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 503 | if (!tfo->fabric_drop_tpg) { |
| 504 | pr_err("Missing tfo->fabric_drop_tpg()\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 505 | return -EINVAL; |
| 506 | } |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | /* |
| 512 | * Called 2nd from fabric module with returned parameter of |
| 513 | * struct target_fabric_configfs * from target_fabric_configfs_init(). |
| 514 | * |
| 515 | * Upon a successful registration, the new fabric's struct config_item is |
| 516 | * return. Also, a pointer to this struct is set in the passed |
| 517 | * struct target_fabric_configfs. |
| 518 | */ |
| 519 | int target_fabric_configfs_register( |
| 520 | struct target_fabric_configfs *tf) |
| 521 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 522 | int ret; |
| 523 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 524 | if (!tf) { |
| 525 | pr_err("Unable to locate target_fabric_configfs" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 526 | " pointer\n"); |
| 527 | return -EINVAL; |
| 528 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 529 | if (!tf->tf_subsys) { |
| 530 | pr_err("Unable to target struct config_subsystem" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 531 | " pointer\n"); |
| 532 | return -EINVAL; |
| 533 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 534 | ret = target_fabric_tf_ops_check(tf); |
| 535 | if (ret < 0) |
| 536 | return ret; |
| 537 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 538 | pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 539 | ">>>>>>>>>>\n"); |
| 540 | return 0; |
| 541 | } |
| 542 | EXPORT_SYMBOL(target_fabric_configfs_register); |
| 543 | |
| 544 | void target_fabric_configfs_deregister( |
| 545 | struct target_fabric_configfs *tf) |
| 546 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 547 | struct configfs_subsystem *su; |
| 548 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 549 | if (!tf) { |
| 550 | pr_err("Unable to locate passed target_fabric_" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 551 | "configfs\n"); |
| 552 | return; |
| 553 | } |
| 554 | su = tf->tf_subsys; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 555 | if (!su) { |
| 556 | pr_err("Unable to locate passed tf->tf_subsys" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 557 | " pointer\n"); |
| 558 | return; |
| 559 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 560 | pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 561 | ">>>>>>>>>>>>\n"); |
| 562 | mutex_lock(&g_tf_lock); |
| 563 | if (atomic_read(&tf->tf_access_cnt)) { |
| 564 | mutex_unlock(&g_tf_lock); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 565 | pr_err("Non zero tf->tf_access_cnt for fabric %s\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 566 | tf->tf_name); |
| 567 | BUG(); |
| 568 | } |
| 569 | list_del(&tf->tf_list); |
| 570 | mutex_unlock(&g_tf_lock); |
| 571 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 572 | pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing tf:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 573 | " %s\n", tf->tf_name); |
| 574 | tf->tf_module = NULL; |
| 575 | tf->tf_subsys = NULL; |
| 576 | kfree(tf); |
| 577 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 578 | pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 579 | ">>>>>\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 580 | } |
| 581 | EXPORT_SYMBOL(target_fabric_configfs_deregister); |
| 582 | |
| 583 | /*############################################################################## |
| 584 | // Stop functions called by external Target Fabrics Modules |
| 585 | //############################################################################*/ |
| 586 | |
Nicholas Bellinger | f79a897 | 2014-11-27 14:51:14 -0800 | [diff] [blame] | 587 | /* Start functions for struct config_item_type tb_dev_attrib_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 588 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 589 | CONFIGFS_EATTR_STRUCT(target_core_dev_attrib, se_dev_attrib); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 590 | CONFIGFS_EATTR_OPS(target_core_dev_attrib, se_dev_attrib, da_group); |
| 591 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 592 | static struct configfs_item_operations target_core_dev_attrib_ops = { |
| 593 | .show_attribute = target_core_dev_attrib_attr_show, |
| 594 | .store_attribute = target_core_dev_attrib_attr_store, |
| 595 | }; |
| 596 | |
Nicholas Bellinger | 43cf208 | 2014-11-28 05:34:39 +0000 | [diff] [blame] | 597 | TB_CIT_SETUP(dev_attrib, &target_core_dev_attrib_ops, NULL, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 598 | |
Nicholas Bellinger | f79a897 | 2014-11-27 14:51:14 -0800 | [diff] [blame] | 599 | /* End functions for struct config_item_type tb_dev_attrib_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 600 | |
Nicholas Bellinger | f8d389c | 2014-11-27 15:01:12 -0800 | [diff] [blame] | 601 | /* Start functions for struct config_item_type tb_dev_wwn_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 602 | |
| 603 | CONFIGFS_EATTR_STRUCT(target_core_dev_wwn, t10_wwn); |
| 604 | #define SE_DEV_WWN_ATTR(_name, _mode) \ |
| 605 | static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \ |
| 606 | __CONFIGFS_EATTR(_name, _mode, \ |
| 607 | target_core_dev_wwn_show_attr_##_name, \ |
| 608 | target_core_dev_wwn_store_attr_##_name); |
| 609 | |
| 610 | #define SE_DEV_WWN_ATTR_RO(_name); \ |
| 611 | do { \ |
| 612 | static struct target_core_dev_wwn_attribute \ |
| 613 | target_core_dev_wwn_##_name = \ |
| 614 | __CONFIGFS_EATTR_RO(_name, \ |
| 615 | target_core_dev_wwn_show_attr_##_name); \ |
| 616 | } while (0); |
| 617 | |
| 618 | /* |
| 619 | * VPD page 0x80 Unit serial |
| 620 | */ |
| 621 | static ssize_t target_core_dev_wwn_show_attr_vpd_unit_serial( |
| 622 | struct t10_wwn *t10_wwn, |
| 623 | char *page) |
| 624 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 625 | return sprintf(page, "T10 VPD Unit Serial Number: %s\n", |
| 626 | &t10_wwn->unit_serial[0]); |
| 627 | } |
| 628 | |
| 629 | static ssize_t target_core_dev_wwn_store_attr_vpd_unit_serial( |
| 630 | struct t10_wwn *t10_wwn, |
| 631 | const char *page, |
| 632 | size_t count) |
| 633 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 634 | struct se_device *dev = t10_wwn->t10_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 635 | unsigned char buf[INQUIRY_VPD_SERIAL_LEN]; |
| 636 | |
| 637 | /* |
| 638 | * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial |
| 639 | * from the struct scsi_device level firmware, do not allow |
| 640 | * VPD Unit Serial to be emulated. |
| 641 | * |
| 642 | * Note this struct scsi_device could also be emulating VPD |
| 643 | * information from its drivers/scsi LLD. But for now we assume |
| 644 | * it is doing 'the right thing' wrt a world wide unique |
| 645 | * VPD Unit Serial Number that OS dependent multipath can depend on. |
| 646 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 647 | if (dev->dev_flags & DF_FIRMWARE_VPD_UNIT_SERIAL) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 648 | pr_err("Underlying SCSI device firmware provided VPD" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 649 | " Unit Serial, ignoring request\n"); |
| 650 | return -EOPNOTSUPP; |
| 651 | } |
| 652 | |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 653 | if (strlen(page) >= INQUIRY_VPD_SERIAL_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 654 | pr_err("Emulated VPD Unit Serial exceeds" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 655 | " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN); |
| 656 | return -EOVERFLOW; |
| 657 | } |
| 658 | /* |
| 659 | * Check to see if any active $FABRIC_MOD exports exist. If they |
| 660 | * do exist, fail here as changing this information on the fly |
| 661 | * (underneath the initiator side OS dependent multipath code) |
| 662 | * could cause negative effects. |
| 663 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 664 | if (dev->export_count) { |
| 665 | pr_err("Unable to set VPD Unit Serial while" |
| 666 | " active %d $FABRIC_MOD exports exist\n", |
| 667 | dev->export_count); |
| 668 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 669 | } |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 670 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 671 | /* |
| 672 | * This currently assumes ASCII encoding for emulated VPD Unit Serial. |
| 673 | * |
| 674 | * Also, strip any newline added from the userspace |
| 675 | * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial |
| 676 | */ |
| 677 | memset(buf, 0, INQUIRY_VPD_SERIAL_LEN); |
| 678 | snprintf(buf, INQUIRY_VPD_SERIAL_LEN, "%s", page); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 679 | snprintf(dev->t10_wwn.unit_serial, INQUIRY_VPD_SERIAL_LEN, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 680 | "%s", strstrip(buf)); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 681 | dev->dev_flags |= DF_EMULATED_VPD_UNIT_SERIAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 682 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 683 | pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:" |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 684 | " %s\n", dev->t10_wwn.unit_serial); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 685 | |
| 686 | return count; |
| 687 | } |
| 688 | |
| 689 | SE_DEV_WWN_ATTR(vpd_unit_serial, S_IRUGO | S_IWUSR); |
| 690 | |
| 691 | /* |
| 692 | * VPD page 0x83 Protocol Identifier |
| 693 | */ |
| 694 | static ssize_t target_core_dev_wwn_show_attr_vpd_protocol_identifier( |
| 695 | struct t10_wwn *t10_wwn, |
| 696 | char *page) |
| 697 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 698 | struct t10_vpd *vpd; |
| 699 | unsigned char buf[VPD_TMP_BUF_SIZE]; |
| 700 | ssize_t len = 0; |
| 701 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 702 | memset(buf, 0, VPD_TMP_BUF_SIZE); |
| 703 | |
| 704 | spin_lock(&t10_wwn->t10_vpd_lock); |
| 705 | list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 706 | if (!vpd->protocol_identifier_set) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 707 | continue; |
| 708 | |
| 709 | transport_dump_vpd_proto_id(vpd, buf, VPD_TMP_BUF_SIZE); |
| 710 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 711 | if (len + strlen(buf) >= PAGE_SIZE) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 712 | break; |
| 713 | |
| 714 | len += sprintf(page+len, "%s", buf); |
| 715 | } |
| 716 | spin_unlock(&t10_wwn->t10_vpd_lock); |
| 717 | |
| 718 | return len; |
| 719 | } |
| 720 | |
| 721 | static ssize_t target_core_dev_wwn_store_attr_vpd_protocol_identifier( |
| 722 | struct t10_wwn *t10_wwn, |
| 723 | const char *page, |
| 724 | size_t count) |
| 725 | { |
| 726 | return -ENOSYS; |
| 727 | } |
| 728 | |
| 729 | SE_DEV_WWN_ATTR(vpd_protocol_identifier, S_IRUGO | S_IWUSR); |
| 730 | |
| 731 | /* |
| 732 | * Generic wrapper for dumping VPD identifiers by association. |
| 733 | */ |
| 734 | #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \ |
| 735 | static ssize_t target_core_dev_wwn_show_attr_##_name( \ |
| 736 | struct t10_wwn *t10_wwn, \ |
| 737 | char *page) \ |
| 738 | { \ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 739 | struct t10_vpd *vpd; \ |
| 740 | unsigned char buf[VPD_TMP_BUF_SIZE]; \ |
| 741 | ssize_t len = 0; \ |
| 742 | \ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 743 | spin_lock(&t10_wwn->t10_vpd_lock); \ |
| 744 | list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \ |
| 745 | if (vpd->association != _assoc) \ |
| 746 | continue; \ |
| 747 | \ |
| 748 | memset(buf, 0, VPD_TMP_BUF_SIZE); \ |
| 749 | transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 750 | if (len + strlen(buf) >= PAGE_SIZE) \ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 751 | break; \ |
| 752 | len += sprintf(page+len, "%s", buf); \ |
| 753 | \ |
| 754 | memset(buf, 0, VPD_TMP_BUF_SIZE); \ |
| 755 | transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 756 | if (len + strlen(buf) >= PAGE_SIZE) \ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 757 | break; \ |
| 758 | len += sprintf(page+len, "%s", buf); \ |
| 759 | \ |
| 760 | memset(buf, 0, VPD_TMP_BUF_SIZE); \ |
| 761 | transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 762 | if (len + strlen(buf) >= PAGE_SIZE) \ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 763 | break; \ |
| 764 | len += sprintf(page+len, "%s", buf); \ |
| 765 | } \ |
| 766 | spin_unlock(&t10_wwn->t10_vpd_lock); \ |
| 767 | \ |
| 768 | return len; \ |
| 769 | } |
| 770 | |
| 771 | /* |
Andy Shevchenko | 163cd5f | 2011-07-18 22:17:43 -0700 | [diff] [blame] | 772 | * VPD page 0x83 Association: Logical Unit |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 773 | */ |
| 774 | DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit, 0x00); |
| 775 | |
| 776 | static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_logical_unit( |
| 777 | struct t10_wwn *t10_wwn, |
| 778 | const char *page, |
| 779 | size_t count) |
| 780 | { |
| 781 | return -ENOSYS; |
| 782 | } |
| 783 | |
| 784 | SE_DEV_WWN_ATTR(vpd_assoc_logical_unit, S_IRUGO | S_IWUSR); |
| 785 | |
| 786 | /* |
| 787 | * VPD page 0x83 Association: Target Port |
| 788 | */ |
| 789 | DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port, 0x10); |
| 790 | |
| 791 | static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_target_port( |
| 792 | struct t10_wwn *t10_wwn, |
| 793 | const char *page, |
| 794 | size_t count) |
| 795 | { |
| 796 | return -ENOSYS; |
| 797 | } |
| 798 | |
| 799 | SE_DEV_WWN_ATTR(vpd_assoc_target_port, S_IRUGO | S_IWUSR); |
| 800 | |
| 801 | /* |
| 802 | * VPD page 0x83 Association: SCSI Target Device |
| 803 | */ |
| 804 | DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device, 0x20); |
| 805 | |
| 806 | static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device( |
| 807 | struct t10_wwn *t10_wwn, |
| 808 | const char *page, |
| 809 | size_t count) |
| 810 | { |
| 811 | return -ENOSYS; |
| 812 | } |
| 813 | |
| 814 | SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device, S_IRUGO | S_IWUSR); |
| 815 | |
| 816 | CONFIGFS_EATTR_OPS(target_core_dev_wwn, t10_wwn, t10_wwn_group); |
| 817 | |
| 818 | static struct configfs_attribute *target_core_dev_wwn_attrs[] = { |
| 819 | &target_core_dev_wwn_vpd_unit_serial.attr, |
| 820 | &target_core_dev_wwn_vpd_protocol_identifier.attr, |
| 821 | &target_core_dev_wwn_vpd_assoc_logical_unit.attr, |
| 822 | &target_core_dev_wwn_vpd_assoc_target_port.attr, |
| 823 | &target_core_dev_wwn_vpd_assoc_scsi_target_device.attr, |
| 824 | NULL, |
| 825 | }; |
| 826 | |
| 827 | static struct configfs_item_operations target_core_dev_wwn_ops = { |
| 828 | .show_attribute = target_core_dev_wwn_attr_show, |
| 829 | .store_attribute = target_core_dev_wwn_attr_store, |
| 830 | }; |
| 831 | |
Nicholas Bellinger | f8d389c | 2014-11-27 15:01:12 -0800 | [diff] [blame] | 832 | TB_CIT_SETUP(dev_wwn, &target_core_dev_wwn_ops, NULL, target_core_dev_wwn_attrs); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 833 | |
Nicholas Bellinger | f8d389c | 2014-11-27 15:01:12 -0800 | [diff] [blame] | 834 | /* End functions for struct config_item_type tb_dev_wwn_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 835 | |
Nicholas Bellinger | 91e2e39 | 2014-11-27 14:57:01 -0800 | [diff] [blame] | 836 | /* Start functions for struct config_item_type tb_dev_pr_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 837 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 838 | CONFIGFS_EATTR_STRUCT(target_core_dev_pr, se_device); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 839 | #define SE_DEV_PR_ATTR(_name, _mode) \ |
| 840 | static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \ |
| 841 | __CONFIGFS_EATTR(_name, _mode, \ |
| 842 | target_core_dev_pr_show_attr_##_name, \ |
| 843 | target_core_dev_pr_store_attr_##_name); |
| 844 | |
| 845 | #define SE_DEV_PR_ATTR_RO(_name); \ |
| 846 | static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \ |
| 847 | __CONFIGFS_EATTR_RO(_name, \ |
| 848 | target_core_dev_pr_show_attr_##_name); |
| 849 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 850 | static ssize_t target_core_dev_pr_show_spc3_res(struct se_device *dev, |
| 851 | char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 852 | { |
| 853 | struct se_node_acl *se_nacl; |
| 854 | struct t10_pr_registration *pr_reg; |
| 855 | char i_buf[PR_REG_ISID_ID_LEN]; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 856 | |
| 857 | memset(i_buf, 0, PR_REG_ISID_ID_LEN); |
| 858 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 859 | pr_reg = dev->dev_pr_res_holder; |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 860 | if (!pr_reg) |
| 861 | return sprintf(page, "No SPC-3 Reservation holder\n"); |
| 862 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 863 | se_nacl = pr_reg->pr_reg_nacl; |
Andy Grover | d2843c1 | 2013-05-16 10:40:55 -0700 | [diff] [blame] | 864 | core_pr_dump_initiator_port(pr_reg, i_buf, PR_REG_ISID_ID_LEN); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 865 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 866 | return sprintf(page, "SPC-3 Reservation: %s Initiator: %s%s\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 867 | se_nacl->se_tpg->se_tpg_tfo->get_fabric_name(), |
Andy Grover | d2843c1 | 2013-05-16 10:40:55 -0700 | [diff] [blame] | 868 | se_nacl->initiatorname, i_buf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 869 | } |
| 870 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 871 | static ssize_t target_core_dev_pr_show_spc2_res(struct se_device *dev, |
| 872 | char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 873 | { |
| 874 | struct se_node_acl *se_nacl; |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 875 | ssize_t len; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 876 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 877 | se_nacl = dev->dev_reserved_node_acl; |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 878 | if (se_nacl) { |
| 879 | len = sprintf(page, |
| 880 | "SPC-2 Reservation: %s Initiator: %s\n", |
| 881 | se_nacl->se_tpg->se_tpg_tfo->get_fabric_name(), |
| 882 | se_nacl->initiatorname); |
| 883 | } else { |
| 884 | len = sprintf(page, "No SPC-2 Reservation holder\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 885 | } |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 886 | return len; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 887 | } |
| 888 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 889 | static ssize_t target_core_dev_pr_show_attr_res_holder(struct se_device *dev, |
| 890 | char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 891 | { |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 892 | int ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 893 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 894 | if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) |
| 895 | return sprintf(page, "Passthrough\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 896 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 897 | spin_lock(&dev->dev_reservation_lock); |
| 898 | if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) |
| 899 | ret = target_core_dev_pr_show_spc2_res(dev, page); |
| 900 | else |
| 901 | ret = target_core_dev_pr_show_spc3_res(dev, page); |
| 902 | spin_unlock(&dev->dev_reservation_lock); |
| 903 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | SE_DEV_PR_ATTR_RO(res_holder); |
| 907 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 908 | static ssize_t target_core_dev_pr_show_attr_res_pr_all_tgt_pts( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 909 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 910 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 911 | ssize_t len = 0; |
| 912 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 913 | spin_lock(&dev->dev_reservation_lock); |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 914 | if (!dev->dev_pr_res_holder) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 915 | len = sprintf(page, "No SPC-3 Reservation holder\n"); |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 916 | } else if (dev->dev_pr_res_holder->pr_reg_all_tg_pt) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 917 | len = sprintf(page, "SPC-3 Reservation: All Target" |
| 918 | " Ports registration\n"); |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 919 | } else { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 920 | len = sprintf(page, "SPC-3 Reservation: Single" |
| 921 | " Target Port registration\n"); |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 922 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 923 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 924 | spin_unlock(&dev->dev_reservation_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 925 | return len; |
| 926 | } |
| 927 | |
| 928 | SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts); |
| 929 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 930 | static ssize_t target_core_dev_pr_show_attr_res_pr_generation( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 931 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 932 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 933 | return sprintf(page, "0x%08x\n", dev->t10_pr.pr_generation); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | SE_DEV_PR_ATTR_RO(res_pr_generation); |
| 937 | |
| 938 | /* |
| 939 | * res_pr_holder_tg_port |
| 940 | */ |
| 941 | static ssize_t target_core_dev_pr_show_attr_res_pr_holder_tg_port( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 942 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 943 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 944 | struct se_node_acl *se_nacl; |
| 945 | struct se_lun *lun; |
| 946 | struct se_portal_group *se_tpg; |
| 947 | struct t10_pr_registration *pr_reg; |
| 948 | struct target_core_fabric_ops *tfo; |
| 949 | ssize_t len = 0; |
| 950 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 951 | spin_lock(&dev->dev_reservation_lock); |
| 952 | pr_reg = dev->dev_pr_res_holder; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 953 | if (!pr_reg) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 954 | len = sprintf(page, "No SPC-3 Reservation holder\n"); |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 955 | goto out_unlock; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 956 | } |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 957 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 958 | se_nacl = pr_reg->pr_reg_nacl; |
| 959 | se_tpg = se_nacl->se_tpg; |
| 960 | lun = pr_reg->pr_reg_tg_pt_lun; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 961 | tfo = se_tpg->se_tpg_tfo; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 962 | |
| 963 | len += sprintf(page+len, "SPC-3 Reservation: %s" |
| 964 | " Target Node Endpoint: %s\n", tfo->get_fabric_name(), |
| 965 | tfo->tpg_get_wwn(se_tpg)); |
| 966 | len += sprintf(page+len, "SPC-3 Reservation: Relative Port" |
Masanari Iida | 35d1efe | 2012-08-16 22:43:13 +0900 | [diff] [blame] | 967 | " Identifier Tag: %hu %s Portal Group Tag: %hu" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 968 | " %s Logical Unit: %u\n", lun->lun_sep->sep_rtpi, |
| 969 | tfo->get_fabric_name(), tfo->tpg_get_tag(se_tpg), |
| 970 | tfo->get_fabric_name(), lun->unpacked_lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 971 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 972 | out_unlock: |
| 973 | spin_unlock(&dev->dev_reservation_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 974 | return len; |
| 975 | } |
| 976 | |
| 977 | SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port); |
| 978 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 979 | static ssize_t target_core_dev_pr_show_attr_res_pr_registered_i_pts( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 980 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 981 | { |
| 982 | struct target_core_fabric_ops *tfo; |
| 983 | struct t10_pr_registration *pr_reg; |
| 984 | unsigned char buf[384]; |
| 985 | char i_buf[PR_REG_ISID_ID_LEN]; |
| 986 | ssize_t len = 0; |
Andy Grover | d2843c1 | 2013-05-16 10:40:55 -0700 | [diff] [blame] | 987 | int reg_count = 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 988 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 989 | len += sprintf(page+len, "SPC-3 PR Registrations:\n"); |
| 990 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 991 | spin_lock(&dev->t10_pr.registration_lock); |
| 992 | list_for_each_entry(pr_reg, &dev->t10_pr.registration_list, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 993 | pr_reg_list) { |
| 994 | |
| 995 | memset(buf, 0, 384); |
| 996 | memset(i_buf, 0, PR_REG_ISID_ID_LEN); |
| 997 | tfo = pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo; |
Andy Grover | d2843c1 | 2013-05-16 10:40:55 -0700 | [diff] [blame] | 998 | core_pr_dump_initiator_port(pr_reg, i_buf, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 999 | PR_REG_ISID_ID_LEN); |
| 1000 | sprintf(buf, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n", |
| 1001 | tfo->get_fabric_name(), |
Andy Grover | d2843c1 | 2013-05-16 10:40:55 -0700 | [diff] [blame] | 1002 | pr_reg->pr_reg_nacl->initiatorname, i_buf, pr_reg->pr_res_key, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1003 | pr_reg->pr_res_generation); |
| 1004 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1005 | if (len + strlen(buf) >= PAGE_SIZE) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1006 | break; |
| 1007 | |
| 1008 | len += sprintf(page+len, "%s", buf); |
| 1009 | reg_count++; |
| 1010 | } |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1011 | spin_unlock(&dev->t10_pr.registration_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1012 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1013 | if (!reg_count) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1014 | len += sprintf(page+len, "None\n"); |
| 1015 | |
| 1016 | return len; |
| 1017 | } |
| 1018 | |
| 1019 | SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts); |
| 1020 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1021 | static ssize_t target_core_dev_pr_show_attr_res_pr_type( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1022 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1023 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1024 | struct t10_pr_registration *pr_reg; |
| 1025 | ssize_t len = 0; |
| 1026 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1027 | spin_lock(&dev->dev_reservation_lock); |
| 1028 | pr_reg = dev->dev_pr_res_holder; |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1029 | if (pr_reg) { |
| 1030 | len = sprintf(page, "SPC-3 Reservation Type: %s\n", |
| 1031 | core_scsi3_pr_dump_type(pr_reg->pr_res_type)); |
| 1032 | } else { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1033 | len = sprintf(page, "No SPC-3 Reservation holder\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1034 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1035 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1036 | spin_unlock(&dev->dev_reservation_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1037 | return len; |
| 1038 | } |
| 1039 | |
| 1040 | SE_DEV_PR_ATTR_RO(res_pr_type); |
| 1041 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1042 | static ssize_t target_core_dev_pr_show_attr_res_type( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1043 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1044 | { |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1045 | if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) |
| 1046 | return sprintf(page, "SPC_PASSTHROUGH\n"); |
| 1047 | else if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) |
| 1048 | return sprintf(page, "SPC2_RESERVATIONS\n"); |
| 1049 | else |
| 1050 | return sprintf(page, "SPC3_PERSISTENT_RESERVATIONS\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | SE_DEV_PR_ATTR_RO(res_type); |
| 1054 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1055 | static ssize_t target_core_dev_pr_show_attr_res_aptpl_active( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1056 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1057 | { |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1058 | if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1059 | return 0; |
| 1060 | |
| 1061 | return sprintf(page, "APTPL Bit Status: %s\n", |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1062 | (dev->t10_pr.pr_aptpl_active) ? "Activated" : "Disabled"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | SE_DEV_PR_ATTR_RO(res_aptpl_active); |
| 1066 | |
| 1067 | /* |
| 1068 | * res_aptpl_metadata |
| 1069 | */ |
| 1070 | static ssize_t target_core_dev_pr_show_attr_res_aptpl_metadata( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1071 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1072 | { |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1073 | if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1074 | return 0; |
| 1075 | |
| 1076 | return sprintf(page, "Ready to process PR APTPL metadata..\n"); |
| 1077 | } |
| 1078 | |
| 1079 | enum { |
| 1080 | Opt_initiator_fabric, Opt_initiator_node, Opt_initiator_sid, |
| 1081 | Opt_sa_res_key, Opt_res_holder, Opt_res_type, Opt_res_scope, |
| 1082 | Opt_res_all_tg_pt, Opt_mapped_lun, Opt_target_fabric, |
| 1083 | Opt_target_node, Opt_tpgt, Opt_port_rtpi, Opt_target_lun, Opt_err |
| 1084 | }; |
| 1085 | |
| 1086 | static match_table_t tokens = { |
| 1087 | {Opt_initiator_fabric, "initiator_fabric=%s"}, |
| 1088 | {Opt_initiator_node, "initiator_node=%s"}, |
| 1089 | {Opt_initiator_sid, "initiator_sid=%s"}, |
| 1090 | {Opt_sa_res_key, "sa_res_key=%s"}, |
| 1091 | {Opt_res_holder, "res_holder=%d"}, |
| 1092 | {Opt_res_type, "res_type=%d"}, |
| 1093 | {Opt_res_scope, "res_scope=%d"}, |
| 1094 | {Opt_res_all_tg_pt, "res_all_tg_pt=%d"}, |
| 1095 | {Opt_mapped_lun, "mapped_lun=%d"}, |
| 1096 | {Opt_target_fabric, "target_fabric=%s"}, |
| 1097 | {Opt_target_node, "target_node=%s"}, |
| 1098 | {Opt_tpgt, "tpgt=%d"}, |
| 1099 | {Opt_port_rtpi, "port_rtpi=%d"}, |
| 1100 | {Opt_target_lun, "target_lun=%d"}, |
| 1101 | {Opt_err, NULL} |
| 1102 | }; |
| 1103 | |
| 1104 | static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1105 | struct se_device *dev, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1106 | const char *page, |
| 1107 | size_t count) |
| 1108 | { |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1109 | unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL; |
| 1110 | unsigned char *t_fabric = NULL, *t_port = NULL; |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1111 | char *orig, *ptr, *opts; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1112 | substring_t args[MAX_OPT_ARGS]; |
| 1113 | unsigned long long tmp_ll; |
| 1114 | u64 sa_res_key = 0; |
| 1115 | u32 mapped_lun = 0, target_lun = 0; |
| 1116 | int ret = -1, res_holder = 0, all_tg_pt = 0, arg, token; |
| 1117 | u16 port_rpti = 0, tpgt = 0; |
| 1118 | u8 type = 0, scope; |
| 1119 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1120 | if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) |
| 1121 | return 0; |
| 1122 | if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1123 | return 0; |
| 1124 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1125 | if (dev->export_count) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1126 | pr_debug("Unable to process APTPL metadata while" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1127 | " active fabric exports exist\n"); |
| 1128 | return -EINVAL; |
| 1129 | } |
| 1130 | |
| 1131 | opts = kstrdup(page, GFP_KERNEL); |
| 1132 | if (!opts) |
| 1133 | return -ENOMEM; |
| 1134 | |
| 1135 | orig = opts; |
Sebastian Andrzej Siewior | 90c161b | 2011-11-23 20:53:17 +0100 | [diff] [blame] | 1136 | while ((ptr = strsep(&opts, ",\n")) != NULL) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1137 | if (!*ptr) |
| 1138 | continue; |
| 1139 | |
| 1140 | token = match_token(ptr, tokens, args); |
| 1141 | switch (token) { |
| 1142 | case Opt_initiator_fabric: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1143 | i_fabric = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1144 | if (!i_fabric) { |
| 1145 | ret = -ENOMEM; |
| 1146 | goto out; |
| 1147 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1148 | break; |
| 1149 | case Opt_initiator_node: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1150 | i_port = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1151 | if (!i_port) { |
| 1152 | ret = -ENOMEM; |
| 1153 | goto out; |
| 1154 | } |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 1155 | if (strlen(i_port) >= PR_APTPL_MAX_IPORT_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1156 | pr_err("APTPL metadata initiator_node=" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1157 | " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n", |
| 1158 | PR_APTPL_MAX_IPORT_LEN); |
| 1159 | ret = -EINVAL; |
| 1160 | break; |
| 1161 | } |
| 1162 | break; |
| 1163 | case Opt_initiator_sid: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1164 | isid = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1165 | if (!isid) { |
| 1166 | ret = -ENOMEM; |
| 1167 | goto out; |
| 1168 | } |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 1169 | if (strlen(isid) >= PR_REG_ISID_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1170 | pr_err("APTPL metadata initiator_isid" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1171 | "= exceeds PR_REG_ISID_LEN: %d\n", |
| 1172 | PR_REG_ISID_LEN); |
| 1173 | ret = -EINVAL; |
| 1174 | break; |
| 1175 | } |
| 1176 | break; |
| 1177 | case Opt_sa_res_key: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1178 | ret = kstrtoull(args->from, 0, &tmp_ll); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1179 | if (ret < 0) { |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1180 | pr_err("kstrtoull() failed for sa_res_key=\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1181 | goto out; |
| 1182 | } |
| 1183 | sa_res_key = (u64)tmp_ll; |
| 1184 | break; |
| 1185 | /* |
| 1186 | * PR APTPL Metadata for Reservation |
| 1187 | */ |
| 1188 | case Opt_res_holder: |
| 1189 | match_int(args, &arg); |
| 1190 | res_holder = arg; |
| 1191 | break; |
| 1192 | case Opt_res_type: |
| 1193 | match_int(args, &arg); |
| 1194 | type = (u8)arg; |
| 1195 | break; |
| 1196 | case Opt_res_scope: |
| 1197 | match_int(args, &arg); |
| 1198 | scope = (u8)arg; |
| 1199 | break; |
| 1200 | case Opt_res_all_tg_pt: |
| 1201 | match_int(args, &arg); |
| 1202 | all_tg_pt = (int)arg; |
| 1203 | break; |
| 1204 | case Opt_mapped_lun: |
| 1205 | match_int(args, &arg); |
| 1206 | mapped_lun = (u32)arg; |
| 1207 | break; |
| 1208 | /* |
| 1209 | * PR APTPL Metadata for Target Port |
| 1210 | */ |
| 1211 | case Opt_target_fabric: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1212 | t_fabric = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1213 | if (!t_fabric) { |
| 1214 | ret = -ENOMEM; |
| 1215 | goto out; |
| 1216 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1217 | break; |
| 1218 | case Opt_target_node: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1219 | t_port = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1220 | if (!t_port) { |
| 1221 | ret = -ENOMEM; |
| 1222 | goto out; |
| 1223 | } |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 1224 | if (strlen(t_port) >= PR_APTPL_MAX_TPORT_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1225 | pr_err("APTPL metadata target_node=" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1226 | " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n", |
| 1227 | PR_APTPL_MAX_TPORT_LEN); |
| 1228 | ret = -EINVAL; |
| 1229 | break; |
| 1230 | } |
| 1231 | break; |
| 1232 | case Opt_tpgt: |
| 1233 | match_int(args, &arg); |
| 1234 | tpgt = (u16)arg; |
| 1235 | break; |
| 1236 | case Opt_port_rtpi: |
| 1237 | match_int(args, &arg); |
| 1238 | port_rpti = (u16)arg; |
| 1239 | break; |
| 1240 | case Opt_target_lun: |
| 1241 | match_int(args, &arg); |
| 1242 | target_lun = (u32)arg; |
| 1243 | break; |
| 1244 | default: |
| 1245 | break; |
| 1246 | } |
| 1247 | } |
| 1248 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1249 | if (!i_port || !t_port || !sa_res_key) { |
| 1250 | pr_err("Illegal parameters for APTPL registration\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1251 | ret = -EINVAL; |
| 1252 | goto out; |
| 1253 | } |
| 1254 | |
| 1255 | if (res_holder && !(type)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1256 | pr_err("Illegal PR type: 0x%02x for reservation" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1257 | " holder\n", type); |
| 1258 | ret = -EINVAL; |
| 1259 | goto out; |
| 1260 | } |
| 1261 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1262 | ret = core_scsi3_alloc_aptpl_registration(&dev->t10_pr, sa_res_key, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1263 | i_port, isid, mapped_lun, t_port, tpgt, target_lun, |
| 1264 | res_holder, all_tg_pt, type); |
| 1265 | out: |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1266 | kfree(i_fabric); |
| 1267 | kfree(i_port); |
| 1268 | kfree(isid); |
| 1269 | kfree(t_fabric); |
| 1270 | kfree(t_port); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1271 | kfree(orig); |
| 1272 | return (ret == 0) ? count : ret; |
| 1273 | } |
| 1274 | |
| 1275 | SE_DEV_PR_ATTR(res_aptpl_metadata, S_IRUGO | S_IWUSR); |
| 1276 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1277 | CONFIGFS_EATTR_OPS(target_core_dev_pr, se_device, dev_pr_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1278 | |
| 1279 | static struct configfs_attribute *target_core_dev_pr_attrs[] = { |
| 1280 | &target_core_dev_pr_res_holder.attr, |
| 1281 | &target_core_dev_pr_res_pr_all_tgt_pts.attr, |
| 1282 | &target_core_dev_pr_res_pr_generation.attr, |
| 1283 | &target_core_dev_pr_res_pr_holder_tg_port.attr, |
| 1284 | &target_core_dev_pr_res_pr_registered_i_pts.attr, |
| 1285 | &target_core_dev_pr_res_pr_type.attr, |
| 1286 | &target_core_dev_pr_res_type.attr, |
| 1287 | &target_core_dev_pr_res_aptpl_active.attr, |
| 1288 | &target_core_dev_pr_res_aptpl_metadata.attr, |
| 1289 | NULL, |
| 1290 | }; |
| 1291 | |
| 1292 | static struct configfs_item_operations target_core_dev_pr_ops = { |
| 1293 | .show_attribute = target_core_dev_pr_attr_show, |
| 1294 | .store_attribute = target_core_dev_pr_attr_store, |
| 1295 | }; |
| 1296 | |
Nicholas Bellinger | 91e2e39 | 2014-11-27 14:57:01 -0800 | [diff] [blame] | 1297 | TB_CIT_SETUP(dev_pr, &target_core_dev_pr_ops, NULL, target_core_dev_pr_attrs); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1298 | |
Nicholas Bellinger | 91e2e39 | 2014-11-27 14:57:01 -0800 | [diff] [blame] | 1299 | /* End functions for struct config_item_type tb_dev_pr_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1300 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 1301 | /* Start functions for struct config_item_type tb_dev_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1302 | |
| 1303 | static ssize_t target_core_show_dev_info(void *p, char *page) |
| 1304 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1305 | struct se_device *dev = p; |
| 1306 | struct se_subsystem_api *t = dev->transport; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1307 | int bl = 0; |
| 1308 | ssize_t read_bytes = 0; |
| 1309 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1310 | transport_dump_dev_state(dev, page, &bl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1311 | read_bytes += bl; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1312 | read_bytes += t->show_configfs_dev_params(dev, page+read_bytes); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1313 | return read_bytes; |
| 1314 | } |
| 1315 | |
| 1316 | static struct target_core_configfs_attribute target_core_attr_dev_info = { |
| 1317 | .attr = { .ca_owner = THIS_MODULE, |
| 1318 | .ca_name = "info", |
| 1319 | .ca_mode = S_IRUGO }, |
| 1320 | .show = target_core_show_dev_info, |
| 1321 | .store = NULL, |
| 1322 | }; |
| 1323 | |
| 1324 | static ssize_t target_core_store_dev_control( |
| 1325 | void *p, |
| 1326 | const char *page, |
| 1327 | size_t count) |
| 1328 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1329 | struct se_device *dev = p; |
| 1330 | struct se_subsystem_api *t = dev->transport; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1331 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1332 | return t->set_configfs_dev_params(dev, page, count); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | static struct target_core_configfs_attribute target_core_attr_dev_control = { |
| 1336 | .attr = { .ca_owner = THIS_MODULE, |
| 1337 | .ca_name = "control", |
| 1338 | .ca_mode = S_IWUSR }, |
| 1339 | .show = NULL, |
| 1340 | .store = target_core_store_dev_control, |
| 1341 | }; |
| 1342 | |
| 1343 | static ssize_t target_core_show_dev_alias(void *p, char *page) |
| 1344 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1345 | struct se_device *dev = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1346 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1347 | if (!(dev->dev_flags & DF_USING_ALIAS)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1348 | return 0; |
| 1349 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1350 | return snprintf(page, PAGE_SIZE, "%s\n", dev->dev_alias); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | static ssize_t target_core_store_dev_alias( |
| 1354 | void *p, |
| 1355 | const char *page, |
| 1356 | size_t count) |
| 1357 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1358 | struct se_device *dev = p; |
| 1359 | struct se_hba *hba = dev->se_hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1360 | ssize_t read_bytes; |
| 1361 | |
| 1362 | if (count > (SE_DEV_ALIAS_LEN-1)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1363 | pr_err("alias count: %d exceeds" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1364 | " SE_DEV_ALIAS_LEN-1: %u\n", (int)count, |
| 1365 | SE_DEV_ALIAS_LEN-1); |
| 1366 | return -EINVAL; |
| 1367 | } |
| 1368 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1369 | read_bytes = snprintf(&dev->dev_alias[0], SE_DEV_ALIAS_LEN, "%s", page); |
Dan Carpenter | 3011684 | 2012-01-27 15:50:55 +0300 | [diff] [blame] | 1370 | if (!read_bytes) |
| 1371 | return -EINVAL; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1372 | if (dev->dev_alias[read_bytes - 1] == '\n') |
| 1373 | dev->dev_alias[read_bytes - 1] = '\0'; |
Sebastian Andrzej Siewior | 0877eafd | 2011-11-28 13:57:25 +0100 | [diff] [blame] | 1374 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1375 | dev->dev_flags |= DF_USING_ALIAS; |
Dan Carpenter | 3011684 | 2012-01-27 15:50:55 +0300 | [diff] [blame] | 1376 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1377 | pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1378 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1379 | config_item_name(&dev->dev_group.cg_item), |
| 1380 | dev->dev_alias); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1381 | |
| 1382 | return read_bytes; |
| 1383 | } |
| 1384 | |
| 1385 | static struct target_core_configfs_attribute target_core_attr_dev_alias = { |
| 1386 | .attr = { .ca_owner = THIS_MODULE, |
| 1387 | .ca_name = "alias", |
| 1388 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 1389 | .show = target_core_show_dev_alias, |
| 1390 | .store = target_core_store_dev_alias, |
| 1391 | }; |
| 1392 | |
| 1393 | static ssize_t target_core_show_dev_udev_path(void *p, char *page) |
| 1394 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1395 | struct se_device *dev = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1396 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1397 | if (!(dev->dev_flags & DF_USING_UDEV_PATH)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1398 | return 0; |
| 1399 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1400 | return snprintf(page, PAGE_SIZE, "%s\n", dev->udev_path); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | static ssize_t target_core_store_dev_udev_path( |
| 1404 | void *p, |
| 1405 | const char *page, |
| 1406 | size_t count) |
| 1407 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1408 | struct se_device *dev = p; |
| 1409 | struct se_hba *hba = dev->se_hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1410 | ssize_t read_bytes; |
| 1411 | |
| 1412 | if (count > (SE_UDEV_PATH_LEN-1)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1413 | pr_err("udev_path count: %d exceeds" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1414 | " SE_UDEV_PATH_LEN-1: %u\n", (int)count, |
| 1415 | SE_UDEV_PATH_LEN-1); |
| 1416 | return -EINVAL; |
| 1417 | } |
| 1418 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1419 | read_bytes = snprintf(&dev->udev_path[0], SE_UDEV_PATH_LEN, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1420 | "%s", page); |
Dan Carpenter | 3011684 | 2012-01-27 15:50:55 +0300 | [diff] [blame] | 1421 | if (!read_bytes) |
| 1422 | return -EINVAL; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1423 | if (dev->udev_path[read_bytes - 1] == '\n') |
| 1424 | dev->udev_path[read_bytes - 1] = '\0'; |
Sebastian Andrzej Siewior | 0877eafd | 2011-11-28 13:57:25 +0100 | [diff] [blame] | 1425 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1426 | dev->dev_flags |= DF_USING_UDEV_PATH; |
Dan Carpenter | 3011684 | 2012-01-27 15:50:55 +0300 | [diff] [blame] | 1427 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1428 | pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1429 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1430 | config_item_name(&dev->dev_group.cg_item), |
| 1431 | dev->udev_path); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1432 | |
| 1433 | return read_bytes; |
| 1434 | } |
| 1435 | |
| 1436 | static struct target_core_configfs_attribute target_core_attr_dev_udev_path = { |
| 1437 | .attr = { .ca_owner = THIS_MODULE, |
| 1438 | .ca_name = "udev_path", |
| 1439 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 1440 | .show = target_core_show_dev_udev_path, |
| 1441 | .store = target_core_store_dev_udev_path, |
| 1442 | }; |
| 1443 | |
Andy Grover | 64146db | 2013-04-30 11:59:15 -0700 | [diff] [blame] | 1444 | static ssize_t target_core_show_dev_enable(void *p, char *page) |
| 1445 | { |
| 1446 | struct se_device *dev = p; |
| 1447 | |
| 1448 | return snprintf(page, PAGE_SIZE, "%d\n", !!(dev->dev_flags & DF_CONFIGURED)); |
| 1449 | } |
| 1450 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1451 | static ssize_t target_core_store_dev_enable( |
| 1452 | void *p, |
| 1453 | const char *page, |
| 1454 | size_t count) |
| 1455 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1456 | struct se_device *dev = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1457 | char *ptr; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1458 | int ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1459 | |
| 1460 | ptr = strstr(page, "1"); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1461 | if (!ptr) { |
| 1462 | pr_err("For dev_enable ops, only valid value" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1463 | " is \"1\"\n"); |
| 1464 | return -EINVAL; |
| 1465 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1466 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1467 | ret = target_configure_device(dev); |
| 1468 | if (ret) |
| 1469 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1470 | return count; |
| 1471 | } |
| 1472 | |
| 1473 | static struct target_core_configfs_attribute target_core_attr_dev_enable = { |
| 1474 | .attr = { .ca_owner = THIS_MODULE, |
| 1475 | .ca_name = "enable", |
Andy Grover | 64146db | 2013-04-30 11:59:15 -0700 | [diff] [blame] | 1476 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 1477 | .show = target_core_show_dev_enable, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1478 | .store = target_core_store_dev_enable, |
| 1479 | }; |
| 1480 | |
| 1481 | static ssize_t target_core_show_alua_lu_gp(void *p, char *page) |
| 1482 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1483 | struct se_device *dev = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1484 | struct config_item *lu_ci; |
| 1485 | struct t10_alua_lu_gp *lu_gp; |
| 1486 | struct t10_alua_lu_gp_member *lu_gp_mem; |
| 1487 | ssize_t len = 0; |
| 1488 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1489 | lu_gp_mem = dev->dev_alua_lu_gp_mem; |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 1490 | if (!lu_gp_mem) |
| 1491 | return 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1492 | |
| 1493 | spin_lock(&lu_gp_mem->lu_gp_mem_lock); |
| 1494 | lu_gp = lu_gp_mem->lu_gp; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1495 | if (lu_gp) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1496 | lu_ci = &lu_gp->lu_gp_group.cg_item; |
| 1497 | len += sprintf(page, "LU Group Alias: %s\nLU Group ID: %hu\n", |
| 1498 | config_item_name(lu_ci), lu_gp->lu_gp_id); |
| 1499 | } |
| 1500 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); |
| 1501 | |
| 1502 | return len; |
| 1503 | } |
| 1504 | |
| 1505 | static ssize_t target_core_store_alua_lu_gp( |
| 1506 | void *p, |
| 1507 | const char *page, |
| 1508 | size_t count) |
| 1509 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1510 | struct se_device *dev = p; |
| 1511 | struct se_hba *hba = dev->se_hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1512 | struct t10_alua_lu_gp *lu_gp = NULL, *lu_gp_new = NULL; |
| 1513 | struct t10_alua_lu_gp_member *lu_gp_mem; |
| 1514 | unsigned char buf[LU_GROUP_NAME_BUF]; |
| 1515 | int move = 0; |
| 1516 | |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 1517 | lu_gp_mem = dev->dev_alua_lu_gp_mem; |
| 1518 | if (!lu_gp_mem) |
| 1519 | return 0; |
| 1520 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1521 | if (count > LU_GROUP_NAME_BUF) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1522 | pr_err("ALUA LU Group Alias too large!\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1523 | return -EINVAL; |
| 1524 | } |
| 1525 | memset(buf, 0, LU_GROUP_NAME_BUF); |
| 1526 | memcpy(buf, page, count); |
| 1527 | /* |
| 1528 | * Any ALUA logical unit alias besides "NULL" means we will be |
| 1529 | * making a new group association. |
| 1530 | */ |
| 1531 | if (strcmp(strstrip(buf), "NULL")) { |
| 1532 | /* |
| 1533 | * core_alua_get_lu_gp_by_name() will increment reference to |
| 1534 | * struct t10_alua_lu_gp. This reference is released with |
| 1535 | * core_alua_get_lu_gp_by_name below(). |
| 1536 | */ |
| 1537 | lu_gp_new = core_alua_get_lu_gp_by_name(strstrip(buf)); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1538 | if (!lu_gp_new) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1539 | return -ENODEV; |
| 1540 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1541 | |
| 1542 | spin_lock(&lu_gp_mem->lu_gp_mem_lock); |
| 1543 | lu_gp = lu_gp_mem->lu_gp; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1544 | if (lu_gp) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1545 | /* |
| 1546 | * Clearing an existing lu_gp association, and replacing |
| 1547 | * with NULL |
| 1548 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1549 | if (!lu_gp_new) { |
| 1550 | pr_debug("Target_Core_ConfigFS: Releasing %s/%s" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1551 | " from ALUA LU Group: core/alua/lu_gps/%s, ID:" |
| 1552 | " %hu\n", |
| 1553 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1554 | config_item_name(&dev->dev_group.cg_item), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1555 | config_item_name(&lu_gp->lu_gp_group.cg_item), |
| 1556 | lu_gp->lu_gp_id); |
| 1557 | |
| 1558 | __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp); |
| 1559 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); |
| 1560 | |
| 1561 | return count; |
| 1562 | } |
| 1563 | /* |
| 1564 | * Removing existing association of lu_gp_mem with lu_gp |
| 1565 | */ |
| 1566 | __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp); |
| 1567 | move = 1; |
| 1568 | } |
| 1569 | /* |
| 1570 | * Associate lu_gp_mem with lu_gp_new. |
| 1571 | */ |
| 1572 | __core_alua_attach_lu_gp_mem(lu_gp_mem, lu_gp_new); |
| 1573 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); |
| 1574 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1575 | pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1576 | " core/alua/lu_gps/%s, ID: %hu\n", |
| 1577 | (move) ? "Moving" : "Adding", |
| 1578 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1579 | config_item_name(&dev->dev_group.cg_item), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1580 | config_item_name(&lu_gp_new->lu_gp_group.cg_item), |
| 1581 | lu_gp_new->lu_gp_id); |
| 1582 | |
| 1583 | core_alua_put_lu_gp_from_name(lu_gp_new); |
| 1584 | return count; |
| 1585 | } |
| 1586 | |
| 1587 | static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp = { |
| 1588 | .attr = { .ca_owner = THIS_MODULE, |
| 1589 | .ca_name = "alua_lu_gp", |
| 1590 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 1591 | .show = target_core_show_alua_lu_gp, |
| 1592 | .store = target_core_store_alua_lu_gp, |
| 1593 | }; |
| 1594 | |
Hannes Reinecke | 229d4f1 | 2013-12-17 09:18:50 +0100 | [diff] [blame] | 1595 | static ssize_t target_core_show_dev_lba_map(void *p, char *page) |
| 1596 | { |
| 1597 | struct se_device *dev = p; |
| 1598 | struct t10_alua_lba_map *map; |
| 1599 | struct t10_alua_lba_map_member *mem; |
| 1600 | char *b = page; |
| 1601 | int bl = 0; |
| 1602 | char state; |
| 1603 | |
| 1604 | spin_lock(&dev->t10_alua.lba_map_lock); |
| 1605 | if (!list_empty(&dev->t10_alua.lba_map_list)) |
| 1606 | bl += sprintf(b + bl, "%u %u\n", |
| 1607 | dev->t10_alua.lba_map_segment_size, |
| 1608 | dev->t10_alua.lba_map_segment_multiplier); |
| 1609 | list_for_each_entry(map, &dev->t10_alua.lba_map_list, lba_map_list) { |
| 1610 | bl += sprintf(b + bl, "%llu %llu", |
| 1611 | map->lba_map_first_lba, map->lba_map_last_lba); |
| 1612 | list_for_each_entry(mem, &map->lba_map_mem_list, |
| 1613 | lba_map_mem_list) { |
| 1614 | switch (mem->lba_map_mem_alua_state) { |
| 1615 | case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED: |
| 1616 | state = 'O'; |
| 1617 | break; |
| 1618 | case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED: |
| 1619 | state = 'A'; |
| 1620 | break; |
| 1621 | case ALUA_ACCESS_STATE_STANDBY: |
| 1622 | state = 'S'; |
| 1623 | break; |
| 1624 | case ALUA_ACCESS_STATE_UNAVAILABLE: |
| 1625 | state = 'U'; |
| 1626 | break; |
| 1627 | default: |
| 1628 | state = '.'; |
| 1629 | break; |
| 1630 | } |
| 1631 | bl += sprintf(b + bl, " %d:%c", |
| 1632 | mem->lba_map_mem_alua_pg_id, state); |
| 1633 | } |
| 1634 | bl += sprintf(b + bl, "\n"); |
| 1635 | } |
| 1636 | spin_unlock(&dev->t10_alua.lba_map_lock); |
| 1637 | return bl; |
| 1638 | } |
| 1639 | |
| 1640 | static ssize_t target_core_store_dev_lba_map( |
| 1641 | void *p, |
| 1642 | const char *page, |
| 1643 | size_t count) |
| 1644 | { |
| 1645 | struct se_device *dev = p; |
| 1646 | struct t10_alua_lba_map *lba_map = NULL; |
| 1647 | struct list_head lba_list; |
| 1648 | char *map_entries, *ptr; |
| 1649 | char state; |
| 1650 | int pg_num = -1, pg; |
| 1651 | int ret = 0, num = 0, pg_id, alua_state; |
| 1652 | unsigned long start_lba = -1, end_lba = -1; |
| 1653 | unsigned long segment_size = -1, segment_mult = -1; |
| 1654 | |
| 1655 | map_entries = kstrdup(page, GFP_KERNEL); |
| 1656 | if (!map_entries) |
| 1657 | return -ENOMEM; |
| 1658 | |
| 1659 | INIT_LIST_HEAD(&lba_list); |
| 1660 | while ((ptr = strsep(&map_entries, "\n")) != NULL) { |
| 1661 | if (!*ptr) |
| 1662 | continue; |
| 1663 | |
| 1664 | if (num == 0) { |
| 1665 | if (sscanf(ptr, "%lu %lu\n", |
| 1666 | &segment_size, &segment_mult) != 2) { |
| 1667 | pr_err("Invalid line %d\n", num); |
| 1668 | ret = -EINVAL; |
| 1669 | break; |
| 1670 | } |
| 1671 | num++; |
| 1672 | continue; |
| 1673 | } |
| 1674 | if (sscanf(ptr, "%lu %lu", &start_lba, &end_lba) != 2) { |
| 1675 | pr_err("Invalid line %d\n", num); |
| 1676 | ret = -EINVAL; |
| 1677 | break; |
| 1678 | } |
| 1679 | ptr = strchr(ptr, ' '); |
| 1680 | if (!ptr) { |
| 1681 | pr_err("Invalid line %d, missing end lba\n", num); |
| 1682 | ret = -EINVAL; |
| 1683 | break; |
| 1684 | } |
| 1685 | ptr++; |
| 1686 | ptr = strchr(ptr, ' '); |
| 1687 | if (!ptr) { |
| 1688 | pr_err("Invalid line %d, missing state definitions\n", |
| 1689 | num); |
| 1690 | ret = -EINVAL; |
| 1691 | break; |
| 1692 | } |
| 1693 | ptr++; |
| 1694 | lba_map = core_alua_allocate_lba_map(&lba_list, |
| 1695 | start_lba, end_lba); |
| 1696 | if (IS_ERR(lba_map)) { |
| 1697 | ret = PTR_ERR(lba_map); |
| 1698 | break; |
| 1699 | } |
| 1700 | pg = 0; |
| 1701 | while (sscanf(ptr, "%d:%c", &pg_id, &state) == 2) { |
| 1702 | switch (state) { |
| 1703 | case 'O': |
| 1704 | alua_state = ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED; |
| 1705 | break; |
| 1706 | case 'A': |
| 1707 | alua_state = ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED; |
| 1708 | break; |
| 1709 | case 'S': |
| 1710 | alua_state = ALUA_ACCESS_STATE_STANDBY; |
| 1711 | break; |
| 1712 | case 'U': |
| 1713 | alua_state = ALUA_ACCESS_STATE_UNAVAILABLE; |
| 1714 | break; |
| 1715 | default: |
| 1716 | pr_err("Invalid ALUA state '%c'\n", state); |
| 1717 | ret = -EINVAL; |
| 1718 | goto out; |
| 1719 | } |
| 1720 | |
| 1721 | ret = core_alua_allocate_lba_map_mem(lba_map, |
| 1722 | pg_id, alua_state); |
| 1723 | if (ret) { |
| 1724 | pr_err("Invalid target descriptor %d:%c " |
| 1725 | "at line %d\n", |
| 1726 | pg_id, state, num); |
| 1727 | break; |
| 1728 | } |
| 1729 | pg++; |
| 1730 | ptr = strchr(ptr, ' '); |
| 1731 | if (ptr) |
| 1732 | ptr++; |
| 1733 | else |
| 1734 | break; |
| 1735 | } |
| 1736 | if (pg_num == -1) |
| 1737 | pg_num = pg; |
| 1738 | else if (pg != pg_num) { |
| 1739 | pr_err("Only %d from %d port groups definitions " |
| 1740 | "at line %d\n", pg, pg_num, num); |
| 1741 | ret = -EINVAL; |
| 1742 | break; |
| 1743 | } |
| 1744 | num++; |
| 1745 | } |
| 1746 | out: |
| 1747 | if (ret) { |
| 1748 | core_alua_free_lba_map(&lba_list); |
| 1749 | count = ret; |
| 1750 | } else |
| 1751 | core_alua_set_lba_map(dev, &lba_list, |
| 1752 | segment_size, segment_mult); |
| 1753 | kfree(map_entries); |
| 1754 | return count; |
| 1755 | } |
| 1756 | |
| 1757 | static struct target_core_configfs_attribute target_core_attr_dev_lba_map = { |
| 1758 | .attr = { .ca_owner = THIS_MODULE, |
| 1759 | .ca_name = "lba_map", |
| 1760 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 1761 | .show = target_core_show_dev_lba_map, |
| 1762 | .store = target_core_store_dev_lba_map, |
| 1763 | }; |
| 1764 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 1765 | static struct configfs_attribute *target_core_dev_attrs[] = { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1766 | &target_core_attr_dev_info.attr, |
| 1767 | &target_core_attr_dev_control.attr, |
| 1768 | &target_core_attr_dev_alias.attr, |
| 1769 | &target_core_attr_dev_udev_path.attr, |
| 1770 | &target_core_attr_dev_enable.attr, |
| 1771 | &target_core_attr_dev_alua_lu_gp.attr, |
Hannes Reinecke | 229d4f1 | 2013-12-17 09:18:50 +0100 | [diff] [blame] | 1772 | &target_core_attr_dev_lba_map.attr, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1773 | NULL, |
| 1774 | }; |
| 1775 | |
| 1776 | static void target_core_dev_release(struct config_item *item) |
| 1777 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1778 | struct config_group *dev_cg = to_config_group(item); |
| 1779 | struct se_device *dev = |
| 1780 | container_of(dev_cg, struct se_device, dev_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1781 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1782 | kfree(dev_cg->default_groups); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1783 | target_free_device(dev); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | static ssize_t target_core_dev_show(struct config_item *item, |
| 1787 | struct configfs_attribute *attr, |
| 1788 | char *page) |
| 1789 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1790 | struct config_group *dev_cg = to_config_group(item); |
| 1791 | struct se_device *dev = |
| 1792 | container_of(dev_cg, struct se_device, dev_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1793 | struct target_core_configfs_attribute *tc_attr = container_of( |
| 1794 | attr, struct target_core_configfs_attribute, attr); |
| 1795 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1796 | if (!tc_attr->show) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1797 | return -EINVAL; |
| 1798 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1799 | return tc_attr->show(dev, page); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | static ssize_t target_core_dev_store(struct config_item *item, |
| 1803 | struct configfs_attribute *attr, |
| 1804 | const char *page, size_t count) |
| 1805 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1806 | struct config_group *dev_cg = to_config_group(item); |
| 1807 | struct se_device *dev = |
| 1808 | container_of(dev_cg, struct se_device, dev_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1809 | struct target_core_configfs_attribute *tc_attr = container_of( |
| 1810 | attr, struct target_core_configfs_attribute, attr); |
| 1811 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1812 | if (!tc_attr->store) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1813 | return -EINVAL; |
| 1814 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1815 | return tc_attr->store(dev, page, count); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | static struct configfs_item_operations target_core_dev_item_ops = { |
| 1819 | .release = target_core_dev_release, |
| 1820 | .show_attribute = target_core_dev_show, |
| 1821 | .store_attribute = target_core_dev_store, |
| 1822 | }; |
| 1823 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 1824 | TB_CIT_SETUP(dev, &target_core_dev_item_ops, NULL, target_core_dev_attrs); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1825 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 1826 | /* End functions for struct config_item_type tb_dev_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1827 | |
| 1828 | /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */ |
| 1829 | |
| 1830 | CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp, t10_alua_lu_gp); |
| 1831 | #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \ |
| 1832 | static struct target_core_alua_lu_gp_attribute \ |
| 1833 | target_core_alua_lu_gp_##_name = \ |
| 1834 | __CONFIGFS_EATTR(_name, _mode, \ |
| 1835 | target_core_alua_lu_gp_show_attr_##_name, \ |
| 1836 | target_core_alua_lu_gp_store_attr_##_name); |
| 1837 | |
| 1838 | #define SE_DEV_ALUA_LU_ATTR_RO(_name) \ |
| 1839 | static struct target_core_alua_lu_gp_attribute \ |
| 1840 | target_core_alua_lu_gp_##_name = \ |
| 1841 | __CONFIGFS_EATTR_RO(_name, \ |
| 1842 | target_core_alua_lu_gp_show_attr_##_name); |
| 1843 | |
| 1844 | /* |
| 1845 | * lu_gp_id |
| 1846 | */ |
| 1847 | static ssize_t target_core_alua_lu_gp_show_attr_lu_gp_id( |
| 1848 | struct t10_alua_lu_gp *lu_gp, |
| 1849 | char *page) |
| 1850 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1851 | if (!lu_gp->lu_gp_valid_id) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1852 | return 0; |
| 1853 | |
| 1854 | return sprintf(page, "%hu\n", lu_gp->lu_gp_id); |
| 1855 | } |
| 1856 | |
| 1857 | static ssize_t target_core_alua_lu_gp_store_attr_lu_gp_id( |
| 1858 | struct t10_alua_lu_gp *lu_gp, |
| 1859 | const char *page, |
| 1860 | size_t count) |
| 1861 | { |
| 1862 | struct config_group *alua_lu_gp_cg = &lu_gp->lu_gp_group; |
| 1863 | unsigned long lu_gp_id; |
| 1864 | int ret; |
| 1865 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 1866 | ret = kstrtoul(page, 0, &lu_gp_id); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1867 | if (ret < 0) { |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 1868 | pr_err("kstrtoul() returned %d for" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1869 | " lu_gp_id\n", ret); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 1870 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1871 | } |
| 1872 | if (lu_gp_id > 0x0000ffff) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1873 | pr_err("ALUA lu_gp_id: %lu exceeds maximum:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1874 | " 0x0000ffff\n", lu_gp_id); |
| 1875 | return -EINVAL; |
| 1876 | } |
| 1877 | |
| 1878 | ret = core_alua_set_lu_gp_id(lu_gp, (u16)lu_gp_id); |
| 1879 | if (ret < 0) |
| 1880 | return -EINVAL; |
| 1881 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1882 | pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1883 | " Group: core/alua/lu_gps/%s to ID: %hu\n", |
| 1884 | config_item_name(&alua_lu_gp_cg->cg_item), |
| 1885 | lu_gp->lu_gp_id); |
| 1886 | |
| 1887 | return count; |
| 1888 | } |
| 1889 | |
| 1890 | SE_DEV_ALUA_LU_ATTR(lu_gp_id, S_IRUGO | S_IWUSR); |
| 1891 | |
| 1892 | /* |
| 1893 | * members |
| 1894 | */ |
| 1895 | static ssize_t target_core_alua_lu_gp_show_attr_members( |
| 1896 | struct t10_alua_lu_gp *lu_gp, |
| 1897 | char *page) |
| 1898 | { |
| 1899 | struct se_device *dev; |
| 1900 | struct se_hba *hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1901 | struct t10_alua_lu_gp_member *lu_gp_mem; |
| 1902 | ssize_t len = 0, cur_len; |
| 1903 | unsigned char buf[LU_GROUP_NAME_BUF]; |
| 1904 | |
| 1905 | memset(buf, 0, LU_GROUP_NAME_BUF); |
| 1906 | |
| 1907 | spin_lock(&lu_gp->lu_gp_lock); |
| 1908 | list_for_each_entry(lu_gp_mem, &lu_gp->lu_gp_mem_list, lu_gp_mem_list) { |
| 1909 | dev = lu_gp_mem->lu_gp_mem_dev; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1910 | hba = dev->se_hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1911 | |
| 1912 | cur_len = snprintf(buf, LU_GROUP_NAME_BUF, "%s/%s\n", |
| 1913 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1914 | config_item_name(&dev->dev_group.cg_item)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1915 | cur_len++; /* Extra byte for NULL terminator */ |
| 1916 | |
| 1917 | if ((cur_len + len) > PAGE_SIZE) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1918 | pr_warn("Ran out of lu_gp_show_attr" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1919 | "_members buffer\n"); |
| 1920 | break; |
| 1921 | } |
| 1922 | memcpy(page+len, buf, cur_len); |
| 1923 | len += cur_len; |
| 1924 | } |
| 1925 | spin_unlock(&lu_gp->lu_gp_lock); |
| 1926 | |
| 1927 | return len; |
| 1928 | } |
| 1929 | |
| 1930 | SE_DEV_ALUA_LU_ATTR_RO(members); |
| 1931 | |
| 1932 | CONFIGFS_EATTR_OPS(target_core_alua_lu_gp, t10_alua_lu_gp, lu_gp_group); |
| 1933 | |
| 1934 | static struct configfs_attribute *target_core_alua_lu_gp_attrs[] = { |
| 1935 | &target_core_alua_lu_gp_lu_gp_id.attr, |
| 1936 | &target_core_alua_lu_gp_members.attr, |
| 1937 | NULL, |
| 1938 | }; |
| 1939 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 1940 | static void target_core_alua_lu_gp_release(struct config_item *item) |
| 1941 | { |
| 1942 | struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item), |
| 1943 | struct t10_alua_lu_gp, lu_gp_group); |
| 1944 | |
| 1945 | core_alua_free_lu_gp(lu_gp); |
| 1946 | } |
| 1947 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1948 | static struct configfs_item_operations target_core_alua_lu_gp_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 1949 | .release = target_core_alua_lu_gp_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1950 | .show_attribute = target_core_alua_lu_gp_attr_show, |
| 1951 | .store_attribute = target_core_alua_lu_gp_attr_store, |
| 1952 | }; |
| 1953 | |
| 1954 | static struct config_item_type target_core_alua_lu_gp_cit = { |
| 1955 | .ct_item_ops = &target_core_alua_lu_gp_ops, |
| 1956 | .ct_attrs = target_core_alua_lu_gp_attrs, |
| 1957 | .ct_owner = THIS_MODULE, |
| 1958 | }; |
| 1959 | |
| 1960 | /* End functions for struct config_item_type target_core_alua_lu_gp_cit */ |
| 1961 | |
| 1962 | /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */ |
| 1963 | |
| 1964 | static struct config_group *target_core_alua_create_lu_gp( |
| 1965 | struct config_group *group, |
| 1966 | const char *name) |
| 1967 | { |
| 1968 | struct t10_alua_lu_gp *lu_gp; |
| 1969 | struct config_group *alua_lu_gp_cg = NULL; |
| 1970 | struct config_item *alua_lu_gp_ci = NULL; |
| 1971 | |
| 1972 | lu_gp = core_alua_allocate_lu_gp(name, 0); |
| 1973 | if (IS_ERR(lu_gp)) |
| 1974 | return NULL; |
| 1975 | |
| 1976 | alua_lu_gp_cg = &lu_gp->lu_gp_group; |
| 1977 | alua_lu_gp_ci = &alua_lu_gp_cg->cg_item; |
| 1978 | |
| 1979 | config_group_init_type_name(alua_lu_gp_cg, name, |
| 1980 | &target_core_alua_lu_gp_cit); |
| 1981 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1982 | pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1983 | " Group: core/alua/lu_gps/%s\n", |
| 1984 | config_item_name(alua_lu_gp_ci)); |
| 1985 | |
| 1986 | return alua_lu_gp_cg; |
| 1987 | |
| 1988 | } |
| 1989 | |
| 1990 | static void target_core_alua_drop_lu_gp( |
| 1991 | struct config_group *group, |
| 1992 | struct config_item *item) |
| 1993 | { |
| 1994 | struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item), |
| 1995 | struct t10_alua_lu_gp, lu_gp_group); |
| 1996 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1997 | pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1998 | " Group: core/alua/lu_gps/%s, ID: %hu\n", |
| 1999 | config_item_name(item), lu_gp->lu_gp_id); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2000 | /* |
| 2001 | * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release() |
| 2002 | * -> target_core_alua_lu_gp_release() |
| 2003 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2004 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | static struct configfs_group_operations target_core_alua_lu_gps_group_ops = { |
| 2008 | .make_group = &target_core_alua_create_lu_gp, |
| 2009 | .drop_item = &target_core_alua_drop_lu_gp, |
| 2010 | }; |
| 2011 | |
| 2012 | static struct config_item_type target_core_alua_lu_gps_cit = { |
| 2013 | .ct_item_ops = NULL, |
| 2014 | .ct_group_ops = &target_core_alua_lu_gps_group_ops, |
| 2015 | .ct_owner = THIS_MODULE, |
| 2016 | }; |
| 2017 | |
| 2018 | /* End functions for struct config_item_type target_core_alua_lu_gps_cit */ |
| 2019 | |
| 2020 | /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */ |
| 2021 | |
| 2022 | CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp, t10_alua_tg_pt_gp); |
| 2023 | #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \ |
| 2024 | static struct target_core_alua_tg_pt_gp_attribute \ |
| 2025 | target_core_alua_tg_pt_gp_##_name = \ |
| 2026 | __CONFIGFS_EATTR(_name, _mode, \ |
| 2027 | target_core_alua_tg_pt_gp_show_attr_##_name, \ |
| 2028 | target_core_alua_tg_pt_gp_store_attr_##_name); |
| 2029 | |
| 2030 | #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \ |
| 2031 | static struct target_core_alua_tg_pt_gp_attribute \ |
| 2032 | target_core_alua_tg_pt_gp_##_name = \ |
| 2033 | __CONFIGFS_EATTR_RO(_name, \ |
| 2034 | target_core_alua_tg_pt_gp_show_attr_##_name); |
| 2035 | |
| 2036 | /* |
| 2037 | * alua_access_state |
| 2038 | */ |
| 2039 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_state( |
| 2040 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2041 | char *page) |
| 2042 | { |
| 2043 | return sprintf(page, "%d\n", |
| 2044 | atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state)); |
| 2045 | } |
| 2046 | |
| 2047 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_state( |
| 2048 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2049 | const char *page, |
| 2050 | size_t count) |
| 2051 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2052 | struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2053 | unsigned long tmp; |
| 2054 | int new_state, ret; |
| 2055 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2056 | if (!tg_pt_gp->tg_pt_gp_valid_id) { |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2057 | pr_err("Unable to do implicit ALUA on non valid" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2058 | " tg_pt_gp ID: %hu\n", tg_pt_gp->tg_pt_gp_valid_id); |
| 2059 | return -EINVAL; |
| 2060 | } |
Nicholas Bellinger | f145377 | 2014-06-06 00:52:57 -0700 | [diff] [blame] | 2061 | if (!(dev->dev_flags & DF_CONFIGURED)) { |
| 2062 | pr_err("Unable to set alua_access_state while device is" |
| 2063 | " not configured\n"); |
| 2064 | return -ENODEV; |
| 2065 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2066 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2067 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2068 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2069 | pr_err("Unable to extract new ALUA access state from" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2070 | " %s\n", page); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2071 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2072 | } |
| 2073 | new_state = (int)tmp; |
| 2074 | |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2075 | if (!(tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_IMPLICIT_ALUA)) { |
| 2076 | pr_err("Unable to process implicit configfs ALUA" |
| 2077 | " transition while TPGS_IMPLICIT_ALUA is disabled\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2078 | return -EINVAL; |
| 2079 | } |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 2080 | if (tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_EXPLICIT_ALUA && |
| 2081 | new_state == ALUA_ACCESS_STATE_LBA_DEPENDENT) { |
| 2082 | /* LBA DEPENDENT is only allowed with implicit ALUA */ |
| 2083 | pr_err("Unable to process implicit configfs ALUA transition" |
| 2084 | " while explicit ALUA management is enabled\n"); |
| 2085 | return -EINVAL; |
| 2086 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2087 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2088 | ret = core_alua_do_port_transition(tg_pt_gp, dev, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2089 | NULL, NULL, new_state, 0); |
| 2090 | return (!ret) ? count : -EINVAL; |
| 2091 | } |
| 2092 | |
| 2093 | SE_DEV_ALUA_TG_PT_ATTR(alua_access_state, S_IRUGO | S_IWUSR); |
| 2094 | |
| 2095 | /* |
| 2096 | * alua_access_status |
| 2097 | */ |
| 2098 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_status( |
| 2099 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2100 | char *page) |
| 2101 | { |
| 2102 | return sprintf(page, "%s\n", |
| 2103 | core_alua_dump_status(tg_pt_gp->tg_pt_gp_alua_access_status)); |
| 2104 | } |
| 2105 | |
| 2106 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_status( |
| 2107 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2108 | const char *page, |
| 2109 | size_t count) |
| 2110 | { |
| 2111 | unsigned long tmp; |
| 2112 | int new_status, ret; |
| 2113 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2114 | if (!tg_pt_gp->tg_pt_gp_valid_id) { |
| 2115 | pr_err("Unable to do set ALUA access status on non" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2116 | " valid tg_pt_gp ID: %hu\n", |
| 2117 | tg_pt_gp->tg_pt_gp_valid_id); |
| 2118 | return -EINVAL; |
| 2119 | } |
| 2120 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2121 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2122 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2123 | pr_err("Unable to extract new ALUA access status" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2124 | " from %s\n", page); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2125 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2126 | } |
| 2127 | new_status = (int)tmp; |
| 2128 | |
| 2129 | if ((new_status != ALUA_STATUS_NONE) && |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2130 | (new_status != ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG) && |
| 2131 | (new_status != ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2132 | pr_err("Illegal ALUA access status: 0x%02x\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2133 | new_status); |
| 2134 | return -EINVAL; |
| 2135 | } |
| 2136 | |
| 2137 | tg_pt_gp->tg_pt_gp_alua_access_status = new_status; |
| 2138 | return count; |
| 2139 | } |
| 2140 | |
| 2141 | SE_DEV_ALUA_TG_PT_ATTR(alua_access_status, S_IRUGO | S_IWUSR); |
| 2142 | |
| 2143 | /* |
| 2144 | * alua_access_type |
| 2145 | */ |
| 2146 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_type( |
| 2147 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2148 | char *page) |
| 2149 | { |
| 2150 | return core_alua_show_access_type(tg_pt_gp, page); |
| 2151 | } |
| 2152 | |
| 2153 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_type( |
| 2154 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2155 | const char *page, |
| 2156 | size_t count) |
| 2157 | { |
| 2158 | return core_alua_store_access_type(tg_pt_gp, page, count); |
| 2159 | } |
| 2160 | |
| 2161 | SE_DEV_ALUA_TG_PT_ATTR(alua_access_type, S_IRUGO | S_IWUSR); |
| 2162 | |
| 2163 | /* |
Hannes Reinecke | 6be526c | 2013-11-19 09:07:50 +0100 | [diff] [blame] | 2164 | * alua_supported_states |
| 2165 | */ |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2166 | |
| 2167 | #define SE_DEV_ALUA_SUPPORT_STATE_SHOW(_name, _var, _bit) \ |
| 2168 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_support_##_name( \ |
| 2169 | struct t10_alua_tg_pt_gp *t, char *p) \ |
| 2170 | { \ |
| 2171 | return sprintf(p, "%d\n", !!(t->_var & _bit)); \ |
Hannes Reinecke | 6be526c | 2013-11-19 09:07:50 +0100 | [diff] [blame] | 2172 | } |
| 2173 | |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2174 | #define SE_DEV_ALUA_SUPPORT_STATE_STORE(_name, _var, _bit) \ |
| 2175 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_support_##_name(\ |
| 2176 | struct t10_alua_tg_pt_gp *t, const char *p, size_t c) \ |
| 2177 | { \ |
| 2178 | unsigned long tmp; \ |
| 2179 | int ret; \ |
| 2180 | \ |
| 2181 | if (!t->tg_pt_gp_valid_id) { \ |
| 2182 | pr_err("Unable to do set ##_name ALUA state on non" \ |
| 2183 | " valid tg_pt_gp ID: %hu\n", \ |
| 2184 | t->tg_pt_gp_valid_id); \ |
| 2185 | return -EINVAL; \ |
| 2186 | } \ |
| 2187 | \ |
| 2188 | ret = kstrtoul(p, 0, &tmp); \ |
| 2189 | if (ret < 0) { \ |
| 2190 | pr_err("Invalid value '%s', must be '0' or '1'\n", p); \ |
| 2191 | return -EINVAL; \ |
| 2192 | } \ |
| 2193 | if (tmp > 1) { \ |
| 2194 | pr_err("Invalid value '%ld', must be '0' or '1'\n", tmp); \ |
| 2195 | return -EINVAL; \ |
| 2196 | } \ |
Sebastian Herbszt | 1f0b030 | 2014-09-01 00:17:53 +0200 | [diff] [blame] | 2197 | if (tmp) \ |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2198 | t->_var |= _bit; \ |
| 2199 | else \ |
| 2200 | t->_var &= ~_bit; \ |
| 2201 | \ |
| 2202 | return c; \ |
Hannes Reinecke | 6be526c | 2013-11-19 09:07:50 +0100 | [diff] [blame] | 2203 | } |
| 2204 | |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2205 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(transitioning, |
| 2206 | tg_pt_gp_alua_supported_states, ALUA_T_SUP); |
| 2207 | SE_DEV_ALUA_SUPPORT_STATE_STORE(transitioning, |
| 2208 | tg_pt_gp_alua_supported_states, ALUA_T_SUP); |
| 2209 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_transitioning, S_IRUGO | S_IWUSR); |
| 2210 | |
| 2211 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(offline, |
| 2212 | tg_pt_gp_alua_supported_states, ALUA_O_SUP); |
| 2213 | SE_DEV_ALUA_SUPPORT_STATE_STORE(offline, |
| 2214 | tg_pt_gp_alua_supported_states, ALUA_O_SUP); |
| 2215 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_offline, S_IRUGO | S_IWUSR); |
| 2216 | |
| 2217 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(lba_dependent, |
| 2218 | tg_pt_gp_alua_supported_states, ALUA_LBD_SUP); |
| 2219 | SE_DEV_ALUA_SUPPORT_STATE_STORE(lba_dependent, |
| 2220 | tg_pt_gp_alua_supported_states, ALUA_LBD_SUP); |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 2221 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_lba_dependent, S_IRUGO); |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2222 | |
| 2223 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(unavailable, |
| 2224 | tg_pt_gp_alua_supported_states, ALUA_U_SUP); |
| 2225 | SE_DEV_ALUA_SUPPORT_STATE_STORE(unavailable, |
| 2226 | tg_pt_gp_alua_supported_states, ALUA_U_SUP); |
| 2227 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_unavailable, S_IRUGO | S_IWUSR); |
| 2228 | |
| 2229 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(standby, |
| 2230 | tg_pt_gp_alua_supported_states, ALUA_S_SUP); |
| 2231 | SE_DEV_ALUA_SUPPORT_STATE_STORE(standby, |
| 2232 | tg_pt_gp_alua_supported_states, ALUA_S_SUP); |
| 2233 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_standby, S_IRUGO | S_IWUSR); |
| 2234 | |
| 2235 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_optimized, |
| 2236 | tg_pt_gp_alua_supported_states, ALUA_AO_SUP); |
| 2237 | SE_DEV_ALUA_SUPPORT_STATE_STORE(active_optimized, |
| 2238 | tg_pt_gp_alua_supported_states, ALUA_AO_SUP); |
| 2239 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_optimized, S_IRUGO | S_IWUSR); |
| 2240 | |
| 2241 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_nonoptimized, |
| 2242 | tg_pt_gp_alua_supported_states, ALUA_AN_SUP); |
| 2243 | SE_DEV_ALUA_SUPPORT_STATE_STORE(active_nonoptimized, |
| 2244 | tg_pt_gp_alua_supported_states, ALUA_AN_SUP); |
| 2245 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_nonoptimized, S_IRUGO | S_IWUSR); |
Hannes Reinecke | 6be526c | 2013-11-19 09:07:50 +0100 | [diff] [blame] | 2246 | |
| 2247 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2248 | * alua_write_metadata |
| 2249 | */ |
| 2250 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_write_metadata( |
| 2251 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2252 | char *page) |
| 2253 | { |
| 2254 | return sprintf(page, "%d\n", tg_pt_gp->tg_pt_gp_write_metadata); |
| 2255 | } |
| 2256 | |
| 2257 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_write_metadata( |
| 2258 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2259 | const char *page, |
| 2260 | size_t count) |
| 2261 | { |
| 2262 | unsigned long tmp; |
| 2263 | int ret; |
| 2264 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2265 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2266 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2267 | pr_err("Unable to extract alua_write_metadata\n"); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2268 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | if ((tmp != 0) && (tmp != 1)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2272 | pr_err("Illegal value for alua_write_metadata:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2273 | " %lu\n", tmp); |
| 2274 | return -EINVAL; |
| 2275 | } |
| 2276 | tg_pt_gp->tg_pt_gp_write_metadata = (int)tmp; |
| 2277 | |
| 2278 | return count; |
| 2279 | } |
| 2280 | |
| 2281 | SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata, S_IRUGO | S_IWUSR); |
| 2282 | |
| 2283 | |
| 2284 | |
| 2285 | /* |
| 2286 | * nonop_delay_msecs |
| 2287 | */ |
| 2288 | static ssize_t target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs( |
| 2289 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2290 | char *page) |
| 2291 | { |
| 2292 | return core_alua_show_nonop_delay_msecs(tg_pt_gp, page); |
| 2293 | |
| 2294 | } |
| 2295 | |
| 2296 | static ssize_t target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs( |
| 2297 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2298 | const char *page, |
| 2299 | size_t count) |
| 2300 | { |
| 2301 | return core_alua_store_nonop_delay_msecs(tg_pt_gp, page, count); |
| 2302 | } |
| 2303 | |
| 2304 | SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs, S_IRUGO | S_IWUSR); |
| 2305 | |
| 2306 | /* |
| 2307 | * trans_delay_msecs |
| 2308 | */ |
| 2309 | static ssize_t target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs( |
| 2310 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2311 | char *page) |
| 2312 | { |
| 2313 | return core_alua_show_trans_delay_msecs(tg_pt_gp, page); |
| 2314 | } |
| 2315 | |
| 2316 | static ssize_t target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs( |
| 2317 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2318 | const char *page, |
| 2319 | size_t count) |
| 2320 | { |
| 2321 | return core_alua_store_trans_delay_msecs(tg_pt_gp, page, count); |
| 2322 | } |
| 2323 | |
| 2324 | SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs, S_IRUGO | S_IWUSR); |
| 2325 | |
| 2326 | /* |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2327 | * implicit_trans_secs |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2328 | */ |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2329 | static ssize_t target_core_alua_tg_pt_gp_show_attr_implicit_trans_secs( |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2330 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2331 | char *page) |
| 2332 | { |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2333 | return core_alua_show_implicit_trans_secs(tg_pt_gp, page); |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2334 | } |
| 2335 | |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2336 | static ssize_t target_core_alua_tg_pt_gp_store_attr_implicit_trans_secs( |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2337 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2338 | const char *page, |
| 2339 | size_t count) |
| 2340 | { |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2341 | return core_alua_store_implicit_trans_secs(tg_pt_gp, page, count); |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2342 | } |
| 2343 | |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2344 | SE_DEV_ALUA_TG_PT_ATTR(implicit_trans_secs, S_IRUGO | S_IWUSR); |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2345 | |
| 2346 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2347 | * preferred |
| 2348 | */ |
| 2349 | |
| 2350 | static ssize_t target_core_alua_tg_pt_gp_show_attr_preferred( |
| 2351 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2352 | char *page) |
| 2353 | { |
| 2354 | return core_alua_show_preferred_bit(tg_pt_gp, page); |
| 2355 | } |
| 2356 | |
| 2357 | static ssize_t target_core_alua_tg_pt_gp_store_attr_preferred( |
| 2358 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2359 | const char *page, |
| 2360 | size_t count) |
| 2361 | { |
| 2362 | return core_alua_store_preferred_bit(tg_pt_gp, page, count); |
| 2363 | } |
| 2364 | |
| 2365 | SE_DEV_ALUA_TG_PT_ATTR(preferred, S_IRUGO | S_IWUSR); |
| 2366 | |
| 2367 | /* |
| 2368 | * tg_pt_gp_id |
| 2369 | */ |
| 2370 | static ssize_t target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id( |
| 2371 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2372 | char *page) |
| 2373 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2374 | if (!tg_pt_gp->tg_pt_gp_valid_id) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2375 | return 0; |
| 2376 | |
| 2377 | return sprintf(page, "%hu\n", tg_pt_gp->tg_pt_gp_id); |
| 2378 | } |
| 2379 | |
| 2380 | static ssize_t target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id( |
| 2381 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2382 | const char *page, |
| 2383 | size_t count) |
| 2384 | { |
| 2385 | struct config_group *alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group; |
| 2386 | unsigned long tg_pt_gp_id; |
| 2387 | int ret; |
| 2388 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2389 | ret = kstrtoul(page, 0, &tg_pt_gp_id); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2390 | if (ret < 0) { |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2391 | pr_err("kstrtoul() returned %d for" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2392 | " tg_pt_gp_id\n", ret); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2393 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2394 | } |
| 2395 | if (tg_pt_gp_id > 0x0000ffff) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2396 | pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2397 | " 0x0000ffff\n", tg_pt_gp_id); |
| 2398 | return -EINVAL; |
| 2399 | } |
| 2400 | |
| 2401 | ret = core_alua_set_tg_pt_gp_id(tg_pt_gp, (u16)tg_pt_gp_id); |
| 2402 | if (ret < 0) |
| 2403 | return -EINVAL; |
| 2404 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2405 | pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: " |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2406 | "core/alua/tg_pt_gps/%s to ID: %hu\n", |
| 2407 | config_item_name(&alua_tg_pt_gp_cg->cg_item), |
| 2408 | tg_pt_gp->tg_pt_gp_id); |
| 2409 | |
| 2410 | return count; |
| 2411 | } |
| 2412 | |
| 2413 | SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id, S_IRUGO | S_IWUSR); |
| 2414 | |
| 2415 | /* |
| 2416 | * members |
| 2417 | */ |
| 2418 | static ssize_t target_core_alua_tg_pt_gp_show_attr_members( |
| 2419 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2420 | char *page) |
| 2421 | { |
| 2422 | struct se_port *port; |
| 2423 | struct se_portal_group *tpg; |
| 2424 | struct se_lun *lun; |
| 2425 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; |
| 2426 | ssize_t len = 0, cur_len; |
| 2427 | unsigned char buf[TG_PT_GROUP_NAME_BUF]; |
| 2428 | |
| 2429 | memset(buf, 0, TG_PT_GROUP_NAME_BUF); |
| 2430 | |
| 2431 | spin_lock(&tg_pt_gp->tg_pt_gp_lock); |
| 2432 | list_for_each_entry(tg_pt_gp_mem, &tg_pt_gp->tg_pt_gp_mem_list, |
| 2433 | tg_pt_gp_mem_list) { |
| 2434 | port = tg_pt_gp_mem->tg_pt; |
| 2435 | tpg = port->sep_tpg; |
| 2436 | lun = port->sep_lun; |
| 2437 | |
| 2438 | cur_len = snprintf(buf, TG_PT_GROUP_NAME_BUF, "%s/%s/tpgt_%hu" |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2439 | "/%s\n", tpg->se_tpg_tfo->get_fabric_name(), |
| 2440 | tpg->se_tpg_tfo->tpg_get_wwn(tpg), |
| 2441 | tpg->se_tpg_tfo->tpg_get_tag(tpg), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2442 | config_item_name(&lun->lun_group.cg_item)); |
| 2443 | cur_len++; /* Extra byte for NULL terminator */ |
| 2444 | |
| 2445 | if ((cur_len + len) > PAGE_SIZE) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2446 | pr_warn("Ran out of lu_gp_show_attr" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2447 | "_members buffer\n"); |
| 2448 | break; |
| 2449 | } |
| 2450 | memcpy(page+len, buf, cur_len); |
| 2451 | len += cur_len; |
| 2452 | } |
| 2453 | spin_unlock(&tg_pt_gp->tg_pt_gp_lock); |
| 2454 | |
| 2455 | return len; |
| 2456 | } |
| 2457 | |
| 2458 | SE_DEV_ALUA_TG_PT_ATTR_RO(members); |
| 2459 | |
| 2460 | CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp, t10_alua_tg_pt_gp, |
| 2461 | tg_pt_gp_group); |
| 2462 | |
| 2463 | static struct configfs_attribute *target_core_alua_tg_pt_gp_attrs[] = { |
| 2464 | &target_core_alua_tg_pt_gp_alua_access_state.attr, |
| 2465 | &target_core_alua_tg_pt_gp_alua_access_status.attr, |
| 2466 | &target_core_alua_tg_pt_gp_alua_access_type.attr, |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2467 | &target_core_alua_tg_pt_gp_alua_support_transitioning.attr, |
| 2468 | &target_core_alua_tg_pt_gp_alua_support_offline.attr, |
| 2469 | &target_core_alua_tg_pt_gp_alua_support_lba_dependent.attr, |
| 2470 | &target_core_alua_tg_pt_gp_alua_support_unavailable.attr, |
| 2471 | &target_core_alua_tg_pt_gp_alua_support_standby.attr, |
| 2472 | &target_core_alua_tg_pt_gp_alua_support_active_nonoptimized.attr, |
| 2473 | &target_core_alua_tg_pt_gp_alua_support_active_optimized.attr, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2474 | &target_core_alua_tg_pt_gp_alua_write_metadata.attr, |
| 2475 | &target_core_alua_tg_pt_gp_nonop_delay_msecs.attr, |
| 2476 | &target_core_alua_tg_pt_gp_trans_delay_msecs.attr, |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2477 | &target_core_alua_tg_pt_gp_implicit_trans_secs.attr, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2478 | &target_core_alua_tg_pt_gp_preferred.attr, |
| 2479 | &target_core_alua_tg_pt_gp_tg_pt_gp_id.attr, |
| 2480 | &target_core_alua_tg_pt_gp_members.attr, |
| 2481 | NULL, |
| 2482 | }; |
| 2483 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2484 | static void target_core_alua_tg_pt_gp_release(struct config_item *item) |
| 2485 | { |
| 2486 | struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item), |
| 2487 | struct t10_alua_tg_pt_gp, tg_pt_gp_group); |
| 2488 | |
| 2489 | core_alua_free_tg_pt_gp(tg_pt_gp); |
| 2490 | } |
| 2491 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2492 | static struct configfs_item_operations target_core_alua_tg_pt_gp_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2493 | .release = target_core_alua_tg_pt_gp_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2494 | .show_attribute = target_core_alua_tg_pt_gp_attr_show, |
| 2495 | .store_attribute = target_core_alua_tg_pt_gp_attr_store, |
| 2496 | }; |
| 2497 | |
| 2498 | static struct config_item_type target_core_alua_tg_pt_gp_cit = { |
| 2499 | .ct_item_ops = &target_core_alua_tg_pt_gp_ops, |
| 2500 | .ct_attrs = target_core_alua_tg_pt_gp_attrs, |
| 2501 | .ct_owner = THIS_MODULE, |
| 2502 | }; |
| 2503 | |
| 2504 | /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */ |
| 2505 | |
Nicholas Bellinger | 72aca57 | 2014-11-27 15:06:23 -0800 | [diff] [blame] | 2506 | /* Start functions for struct config_item_type tb_alua_tg_pt_gps_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2507 | |
| 2508 | static struct config_group *target_core_alua_create_tg_pt_gp( |
| 2509 | struct config_group *group, |
| 2510 | const char *name) |
| 2511 | { |
| 2512 | struct t10_alua *alua = container_of(group, struct t10_alua, |
| 2513 | alua_tg_pt_gps_group); |
| 2514 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2515 | struct config_group *alua_tg_pt_gp_cg = NULL; |
| 2516 | struct config_item *alua_tg_pt_gp_ci = NULL; |
| 2517 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2518 | tg_pt_gp = core_alua_allocate_tg_pt_gp(alua->t10_dev, name, 0); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2519 | if (!tg_pt_gp) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2520 | return NULL; |
| 2521 | |
| 2522 | alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group; |
| 2523 | alua_tg_pt_gp_ci = &alua_tg_pt_gp_cg->cg_item; |
| 2524 | |
| 2525 | config_group_init_type_name(alua_tg_pt_gp_cg, name, |
| 2526 | &target_core_alua_tg_pt_gp_cit); |
| 2527 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2528 | pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2529 | " Group: alua/tg_pt_gps/%s\n", |
| 2530 | config_item_name(alua_tg_pt_gp_ci)); |
| 2531 | |
| 2532 | return alua_tg_pt_gp_cg; |
| 2533 | } |
| 2534 | |
| 2535 | static void target_core_alua_drop_tg_pt_gp( |
| 2536 | struct config_group *group, |
| 2537 | struct config_item *item) |
| 2538 | { |
| 2539 | struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item), |
| 2540 | struct t10_alua_tg_pt_gp, tg_pt_gp_group); |
| 2541 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2542 | pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2543 | " Group: alua/tg_pt_gps/%s, ID: %hu\n", |
| 2544 | config_item_name(item), tg_pt_gp->tg_pt_gp_id); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2545 | /* |
| 2546 | * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release() |
| 2547 | * -> target_core_alua_tg_pt_gp_release(). |
| 2548 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2549 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2550 | } |
| 2551 | |
| 2552 | static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = { |
| 2553 | .make_group = &target_core_alua_create_tg_pt_gp, |
| 2554 | .drop_item = &target_core_alua_drop_tg_pt_gp, |
| 2555 | }; |
| 2556 | |
Nicholas Bellinger | 72aca57 | 2014-11-27 15:06:23 -0800 | [diff] [blame] | 2557 | TB_CIT_SETUP(dev_alua_tg_pt_gps, NULL, &target_core_alua_tg_pt_gps_group_ops, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2558 | |
Nicholas Bellinger | 72aca57 | 2014-11-27 15:06:23 -0800 | [diff] [blame] | 2559 | /* End functions for struct config_item_type tb_alua_tg_pt_gps_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2560 | |
| 2561 | /* Start functions for struct config_item_type target_core_alua_cit */ |
| 2562 | |
| 2563 | /* |
| 2564 | * target_core_alua_cit is a ConfigFS group that lives under |
| 2565 | * /sys/kernel/config/target/core/alua. There are default groups |
| 2566 | * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to |
| 2567 | * target_core_alua_cit in target_core_init_configfs() below. |
| 2568 | */ |
| 2569 | static struct config_item_type target_core_alua_cit = { |
| 2570 | .ct_item_ops = NULL, |
| 2571 | .ct_attrs = NULL, |
| 2572 | .ct_owner = THIS_MODULE, |
| 2573 | }; |
| 2574 | |
| 2575 | /* End functions for struct config_item_type target_core_alua_cit */ |
| 2576 | |
Nicholas Bellinger | d23ab57 | 2014-11-27 15:09:32 -0800 | [diff] [blame] | 2577 | /* Start functions for struct config_item_type tb_dev_stat_cit */ |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2578 | |
| 2579 | static struct config_group *target_core_stat_mkdir( |
| 2580 | struct config_group *group, |
| 2581 | const char *name) |
| 2582 | { |
| 2583 | return ERR_PTR(-ENOSYS); |
| 2584 | } |
| 2585 | |
| 2586 | static void target_core_stat_rmdir( |
| 2587 | struct config_group *group, |
| 2588 | struct config_item *item) |
| 2589 | { |
| 2590 | return; |
| 2591 | } |
| 2592 | |
| 2593 | static struct configfs_group_operations target_core_stat_group_ops = { |
| 2594 | .make_group = &target_core_stat_mkdir, |
| 2595 | .drop_item = &target_core_stat_rmdir, |
| 2596 | }; |
| 2597 | |
Nicholas Bellinger | d23ab57 | 2014-11-27 15:09:32 -0800 | [diff] [blame] | 2598 | TB_CIT_SETUP(dev_stat, NULL, &target_core_stat_group_ops, NULL); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2599 | |
Nicholas Bellinger | d23ab57 | 2014-11-27 15:09:32 -0800 | [diff] [blame] | 2600 | /* End functions for struct config_item_type tb_dev_stat_cit */ |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2601 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2602 | /* Start functions for struct config_item_type target_core_hba_cit */ |
| 2603 | |
| 2604 | static struct config_group *target_core_make_subdev( |
| 2605 | struct config_group *group, |
| 2606 | const char *name) |
| 2607 | { |
| 2608 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2609 | struct se_subsystem_api *t; |
| 2610 | struct config_item *hba_ci = &group->cg_item; |
| 2611 | struct se_hba *hba = item_to_hba(hba_ci); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2612 | struct se_device *dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2613 | struct config_group *dev_cg = NULL, *tg_pt_gp_cg = NULL; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2614 | struct config_group *dev_stat_grp = NULL; |
| 2615 | int errno = -ENOMEM, ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2616 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2617 | ret = mutex_lock_interruptible(&hba->hba_access_mutex); |
| 2618 | if (ret) |
| 2619 | return ERR_PTR(ret); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2620 | /* |
| 2621 | * Locate the struct se_subsystem_api from parent's struct se_hba. |
| 2622 | */ |
| 2623 | t = hba->transport; |
| 2624 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2625 | dev = target_alloc_device(hba, name); |
| 2626 | if (!dev) |
| 2627 | goto out_unlock; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2628 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2629 | dev_cg = &dev->dev_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2630 | |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 2631 | dev_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2632 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2633 | if (!dev_cg->default_groups) |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2634 | goto out_free_device; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2635 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 2636 | config_group_init_type_name(dev_cg, name, &t->tb_cits.tb_dev_cit); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2637 | config_group_init_type_name(&dev->dev_attrib.da_group, "attrib", |
Nicholas Bellinger | f79a897 | 2014-11-27 14:51:14 -0800 | [diff] [blame] | 2638 | &t->tb_cits.tb_dev_attrib_cit); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2639 | config_group_init_type_name(&dev->dev_pr_group, "pr", |
Nicholas Bellinger | 91e2e39 | 2014-11-27 14:57:01 -0800 | [diff] [blame] | 2640 | &t->tb_cits.tb_dev_pr_cit); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2641 | config_group_init_type_name(&dev->t10_wwn.t10_wwn_group, "wwn", |
Nicholas Bellinger | f8d389c | 2014-11-27 15:01:12 -0800 | [diff] [blame] | 2642 | &t->tb_cits.tb_dev_wwn_cit); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2643 | config_group_init_type_name(&dev->t10_alua.alua_tg_pt_gps_group, |
Nicholas Bellinger | 72aca57 | 2014-11-27 15:06:23 -0800 | [diff] [blame] | 2644 | "alua", &t->tb_cits.tb_dev_alua_tg_pt_gps_cit); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2645 | config_group_init_type_name(&dev->dev_stat_grps.stat_group, |
Nicholas Bellinger | d23ab57 | 2014-11-27 15:09:32 -0800 | [diff] [blame] | 2646 | "statistics", &t->tb_cits.tb_dev_stat_cit); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2647 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2648 | dev_cg->default_groups[0] = &dev->dev_attrib.da_group; |
| 2649 | dev_cg->default_groups[1] = &dev->dev_pr_group; |
| 2650 | dev_cg->default_groups[2] = &dev->t10_wwn.t10_wwn_group; |
| 2651 | dev_cg->default_groups[3] = &dev->t10_alua.alua_tg_pt_gps_group; |
| 2652 | dev_cg->default_groups[4] = &dev->dev_stat_grps.stat_group; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2653 | dev_cg->default_groups[5] = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2654 | /* |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2655 | * Add core/$HBA/$DEV/alua/default_tg_pt_gp |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2656 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2657 | tg_pt_gp = core_alua_allocate_tg_pt_gp(dev, "default_tg_pt_gp", 1); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2658 | if (!tg_pt_gp) |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2659 | goto out_free_dev_cg_default_groups; |
| 2660 | dev->t10_alua.default_tg_pt_gp = tg_pt_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2661 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2662 | tg_pt_gp_cg = &dev->t10_alua.alua_tg_pt_gps_group; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 2663 | tg_pt_gp_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2664 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2665 | if (!tg_pt_gp_cg->default_groups) { |
| 2666 | pr_err("Unable to allocate tg_pt_gp_cg->" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2667 | "default_groups\n"); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2668 | goto out_free_tg_pt_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | config_group_init_type_name(&tg_pt_gp->tg_pt_gp_group, |
| 2672 | "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit); |
| 2673 | tg_pt_gp_cg->default_groups[0] = &tg_pt_gp->tg_pt_gp_group; |
| 2674 | tg_pt_gp_cg->default_groups[1] = NULL; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2675 | /* |
| 2676 | * Add core/$HBA/$DEV/statistics/ default groups |
| 2677 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2678 | dev_stat_grp = &dev->dev_stat_grps.stat_group; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 2679 | dev_stat_grp->default_groups = kmalloc(sizeof(struct config_group *) * 4, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2680 | GFP_KERNEL); |
| 2681 | if (!dev_stat_grp->default_groups) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2682 | pr_err("Unable to allocate dev_stat_grp->default_groups\n"); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2683 | goto out_free_tg_pt_gp_cg_default_groups; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2684 | } |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2685 | target_stat_setup_dev_default_groups(dev); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2686 | |
| 2687 | mutex_unlock(&hba->hba_access_mutex); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2688 | return dev_cg; |
| 2689 | |
| 2690 | out_free_tg_pt_gp_cg_default_groups: |
| 2691 | kfree(tg_pt_gp_cg->default_groups); |
| 2692 | out_free_tg_pt_gp: |
| 2693 | core_alua_free_tg_pt_gp(tg_pt_gp); |
| 2694 | out_free_dev_cg_default_groups: |
| 2695 | kfree(dev_cg->default_groups); |
| 2696 | out_free_device: |
| 2697 | target_free_device(dev); |
| 2698 | out_unlock: |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2699 | mutex_unlock(&hba->hba_access_mutex); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2700 | return ERR_PTR(errno); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | static void target_core_drop_subdev( |
| 2704 | struct config_group *group, |
| 2705 | struct config_item *item) |
| 2706 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2707 | struct config_group *dev_cg = to_config_group(item); |
| 2708 | struct se_device *dev = |
| 2709 | container_of(dev_cg, struct se_device, dev_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2710 | struct se_hba *hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2711 | struct config_item *df_item; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2712 | struct config_group *tg_pt_gp_cg, *dev_stat_grp; |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2713 | int i; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2714 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2715 | hba = item_to_hba(&dev->se_hba->hba_group.cg_item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2716 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2717 | mutex_lock(&hba->hba_access_mutex); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2718 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2719 | dev_stat_grp = &dev->dev_stat_grps.stat_group; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2720 | for (i = 0; dev_stat_grp->default_groups[i]; i++) { |
| 2721 | df_item = &dev_stat_grp->default_groups[i]->cg_item; |
| 2722 | dev_stat_grp->default_groups[i] = NULL; |
| 2723 | config_item_put(df_item); |
| 2724 | } |
| 2725 | kfree(dev_stat_grp->default_groups); |
| 2726 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2727 | tg_pt_gp_cg = &dev->t10_alua.alua_tg_pt_gps_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2728 | for (i = 0; tg_pt_gp_cg->default_groups[i]; i++) { |
| 2729 | df_item = &tg_pt_gp_cg->default_groups[i]->cg_item; |
| 2730 | tg_pt_gp_cg->default_groups[i] = NULL; |
| 2731 | config_item_put(df_item); |
| 2732 | } |
| 2733 | kfree(tg_pt_gp_cg->default_groups); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2734 | /* |
| 2735 | * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp |
| 2736 | * directly from target_core_alua_tg_pt_gp_release(). |
| 2737 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2738 | dev->t10_alua.default_tg_pt_gp = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2739 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2740 | for (i = 0; dev_cg->default_groups[i]; i++) { |
| 2741 | df_item = &dev_cg->default_groups[i]->cg_item; |
| 2742 | dev_cg->default_groups[i] = NULL; |
| 2743 | config_item_put(df_item); |
| 2744 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2745 | /* |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2746 | * se_dev is released from target_core_dev_item_ops->release() |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2747 | */ |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2748 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2749 | mutex_unlock(&hba->hba_access_mutex); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | static struct configfs_group_operations target_core_hba_group_ops = { |
| 2753 | .make_group = target_core_make_subdev, |
| 2754 | .drop_item = target_core_drop_subdev, |
| 2755 | }; |
| 2756 | |
| 2757 | CONFIGFS_EATTR_STRUCT(target_core_hba, se_hba); |
| 2758 | #define SE_HBA_ATTR(_name, _mode) \ |
| 2759 | static struct target_core_hba_attribute \ |
| 2760 | target_core_hba_##_name = \ |
| 2761 | __CONFIGFS_EATTR(_name, _mode, \ |
| 2762 | target_core_hba_show_attr_##_name, \ |
| 2763 | target_core_hba_store_attr_##_name); |
| 2764 | |
| 2765 | #define SE_HBA_ATTR_RO(_name) \ |
| 2766 | static struct target_core_hba_attribute \ |
| 2767 | target_core_hba_##_name = \ |
| 2768 | __CONFIGFS_EATTR_RO(_name, \ |
| 2769 | target_core_hba_show_attr_##_name); |
| 2770 | |
| 2771 | static ssize_t target_core_hba_show_attr_hba_info( |
| 2772 | struct se_hba *hba, |
| 2773 | char *page) |
| 2774 | { |
| 2775 | return sprintf(page, "HBA Index: %d plugin: %s version: %s\n", |
| 2776 | hba->hba_id, hba->transport->name, |
| 2777 | TARGET_CORE_CONFIGFS_VERSION); |
| 2778 | } |
| 2779 | |
| 2780 | SE_HBA_ATTR_RO(hba_info); |
| 2781 | |
| 2782 | static ssize_t target_core_hba_show_attr_hba_mode(struct se_hba *hba, |
| 2783 | char *page) |
| 2784 | { |
| 2785 | int hba_mode = 0; |
| 2786 | |
| 2787 | if (hba->hba_flags & HBA_FLAGS_PSCSI_MODE) |
| 2788 | hba_mode = 1; |
| 2789 | |
| 2790 | return sprintf(page, "%d\n", hba_mode); |
| 2791 | } |
| 2792 | |
| 2793 | static ssize_t target_core_hba_store_attr_hba_mode(struct se_hba *hba, |
| 2794 | const char *page, size_t count) |
| 2795 | { |
| 2796 | struct se_subsystem_api *transport = hba->transport; |
| 2797 | unsigned long mode_flag; |
| 2798 | int ret; |
| 2799 | |
| 2800 | if (transport->pmode_enable_hba == NULL) |
| 2801 | return -EINVAL; |
| 2802 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2803 | ret = kstrtoul(page, 0, &mode_flag); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2804 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2805 | pr_err("Unable to extract hba mode flag: %d\n", ret); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2806 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2807 | } |
| 2808 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2809 | if (hba->dev_count) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2810 | pr_err("Unable to set hba_mode with active devices\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2811 | return -EINVAL; |
| 2812 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2813 | |
| 2814 | ret = transport->pmode_enable_hba(hba, mode_flag); |
| 2815 | if (ret < 0) |
| 2816 | return -EINVAL; |
| 2817 | if (ret > 0) |
| 2818 | hba->hba_flags |= HBA_FLAGS_PSCSI_MODE; |
| 2819 | else if (ret == 0) |
| 2820 | hba->hba_flags &= ~HBA_FLAGS_PSCSI_MODE; |
| 2821 | |
| 2822 | return count; |
| 2823 | } |
| 2824 | |
| 2825 | SE_HBA_ATTR(hba_mode, S_IRUGO | S_IWUSR); |
| 2826 | |
| 2827 | CONFIGFS_EATTR_OPS(target_core_hba, se_hba, hba_group); |
| 2828 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2829 | static void target_core_hba_release(struct config_item *item) |
| 2830 | { |
| 2831 | struct se_hba *hba = container_of(to_config_group(item), |
| 2832 | struct se_hba, hba_group); |
| 2833 | core_delete_hba(hba); |
| 2834 | } |
| 2835 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2836 | static struct configfs_attribute *target_core_hba_attrs[] = { |
| 2837 | &target_core_hba_hba_info.attr, |
| 2838 | &target_core_hba_hba_mode.attr, |
| 2839 | NULL, |
| 2840 | }; |
| 2841 | |
| 2842 | static struct configfs_item_operations target_core_hba_item_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2843 | .release = target_core_hba_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2844 | .show_attribute = target_core_hba_attr_show, |
| 2845 | .store_attribute = target_core_hba_attr_store, |
| 2846 | }; |
| 2847 | |
| 2848 | static struct config_item_type target_core_hba_cit = { |
| 2849 | .ct_item_ops = &target_core_hba_item_ops, |
| 2850 | .ct_group_ops = &target_core_hba_group_ops, |
| 2851 | .ct_attrs = target_core_hba_attrs, |
| 2852 | .ct_owner = THIS_MODULE, |
| 2853 | }; |
| 2854 | |
| 2855 | static struct config_group *target_core_call_addhbatotarget( |
| 2856 | struct config_group *group, |
| 2857 | const char *name) |
| 2858 | { |
| 2859 | char *se_plugin_str, *str, *str2; |
| 2860 | struct se_hba *hba; |
| 2861 | char buf[TARGET_CORE_NAME_MAX_LEN]; |
| 2862 | unsigned long plugin_dep_id = 0; |
| 2863 | int ret; |
| 2864 | |
| 2865 | memset(buf, 0, TARGET_CORE_NAME_MAX_LEN); |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 2866 | if (strlen(name) >= TARGET_CORE_NAME_MAX_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2867 | pr_err("Passed *name strlen(): %d exceeds" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2868 | " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name), |
| 2869 | TARGET_CORE_NAME_MAX_LEN); |
| 2870 | return ERR_PTR(-ENAMETOOLONG); |
| 2871 | } |
| 2872 | snprintf(buf, TARGET_CORE_NAME_MAX_LEN, "%s", name); |
| 2873 | |
| 2874 | str = strstr(buf, "_"); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2875 | if (!str) { |
| 2876 | pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2877 | return ERR_PTR(-EINVAL); |
| 2878 | } |
| 2879 | se_plugin_str = buf; |
| 2880 | /* |
| 2881 | * Special case for subsystem plugins that have "_" in their names. |
| 2882 | * Namely rd_direct and rd_mcp.. |
| 2883 | */ |
| 2884 | str2 = strstr(str+1, "_"); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2885 | if (str2) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2886 | *str2 = '\0'; /* Terminate for *se_plugin_str */ |
| 2887 | str2++; /* Skip to start of plugin dependent ID */ |
| 2888 | str = str2; |
| 2889 | } else { |
| 2890 | *str = '\0'; /* Terminate for *se_plugin_str */ |
| 2891 | str++; /* Skip to start of plugin dependent ID */ |
| 2892 | } |
| 2893 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2894 | ret = kstrtoul(str, 0, &plugin_dep_id); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2895 | if (ret < 0) { |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2896 | pr_err("kstrtoul() returned %d for" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2897 | " plugin_dep_id\n", ret); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2898 | return ERR_PTR(ret); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2899 | } |
| 2900 | /* |
| 2901 | * Load up TCM subsystem plugins if they have not already been loaded. |
| 2902 | */ |
Nicholas Bellinger | dbc5623 | 2011-10-22 01:03:54 -0700 | [diff] [blame] | 2903 | transport_subsystem_check_init(); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2904 | |
| 2905 | hba = core_alloc_hba(se_plugin_str, plugin_dep_id, 0); |
| 2906 | if (IS_ERR(hba)) |
| 2907 | return ERR_CAST(hba); |
| 2908 | |
| 2909 | config_group_init_type_name(&hba->hba_group, name, |
| 2910 | &target_core_hba_cit); |
| 2911 | |
| 2912 | return &hba->hba_group; |
| 2913 | } |
| 2914 | |
| 2915 | static void target_core_call_delhbafromtarget( |
| 2916 | struct config_group *group, |
| 2917 | struct config_item *item) |
| 2918 | { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2919 | /* |
| 2920 | * core_delete_hba() is called from target_core_hba_item_ops->release() |
| 2921 | * -> target_core_hba_release() |
| 2922 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2923 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | static struct configfs_group_operations target_core_group_ops = { |
| 2927 | .make_group = target_core_call_addhbatotarget, |
| 2928 | .drop_item = target_core_call_delhbafromtarget, |
| 2929 | }; |
| 2930 | |
| 2931 | static struct config_item_type target_core_cit = { |
| 2932 | .ct_item_ops = NULL, |
| 2933 | .ct_group_ops = &target_core_group_ops, |
| 2934 | .ct_attrs = NULL, |
| 2935 | .ct_owner = THIS_MODULE, |
| 2936 | }; |
| 2937 | |
| 2938 | /* Stop functions for struct config_item_type target_core_hba_cit */ |
| 2939 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 2940 | void target_core_setup_sub_cits(struct se_subsystem_api *sa) |
| 2941 | { |
| 2942 | target_core_setup_dev_cit(sa); |
Nicholas Bellinger | f79a897 | 2014-11-27 14:51:14 -0800 | [diff] [blame] | 2943 | target_core_setup_dev_attrib_cit(sa); |
Nicholas Bellinger | 91e2e39 | 2014-11-27 14:57:01 -0800 | [diff] [blame] | 2944 | target_core_setup_dev_pr_cit(sa); |
Nicholas Bellinger | f8d389c | 2014-11-27 15:01:12 -0800 | [diff] [blame] | 2945 | target_core_setup_dev_wwn_cit(sa); |
Nicholas Bellinger | 72aca57 | 2014-11-27 15:06:23 -0800 | [diff] [blame] | 2946 | target_core_setup_dev_alua_tg_pt_gps_cit(sa); |
Nicholas Bellinger | d23ab57 | 2014-11-27 15:09:32 -0800 | [diff] [blame] | 2947 | target_core_setup_dev_stat_cit(sa); |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 2948 | } |
| 2949 | EXPORT_SYMBOL(target_core_setup_sub_cits); |
| 2950 | |
Axel Lin | 54550fa | 2011-03-14 04:06:09 -0700 | [diff] [blame] | 2951 | static int __init target_core_init_configfs(void) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2952 | { |
| 2953 | struct config_group *target_cg, *hba_cg = NULL, *alua_cg = NULL; |
| 2954 | struct config_group *lu_gp_cg = NULL; |
| 2955 | struct configfs_subsystem *subsys; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2956 | struct t10_alua_lu_gp *lu_gp; |
| 2957 | int ret; |
| 2958 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2959 | pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2960 | " Engine: %s on %s/%s on "UTS_RELEASE"\n", |
| 2961 | TARGET_CORE_VERSION, utsname()->sysname, utsname()->machine); |
| 2962 | |
| 2963 | subsys = target_core_subsystem[0]; |
| 2964 | config_group_init(&subsys->su_group); |
| 2965 | mutex_init(&subsys->su_mutex); |
| 2966 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2967 | ret = init_se_kmem_caches(); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2968 | if (ret < 0) |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2969 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2970 | /* |
| 2971 | * Create $CONFIGFS/target/core default group for HBA <-> Storage Object |
| 2972 | * and ALUA Logical Unit Group and Target Port Group infrastructure. |
| 2973 | */ |
| 2974 | target_cg = &subsys->su_group; |
Andy Grover | ab6dae8 | 2013-12-09 14:27:36 -0800 | [diff] [blame] | 2975 | target_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2976 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2977 | if (!target_cg->default_groups) { |
| 2978 | pr_err("Unable to allocate target_cg->default_groups\n"); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 2979 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2980 | goto out_global; |
| 2981 | } |
| 2982 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2983 | config_group_init_type_name(&target_core_hbagroup, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2984 | "core", &target_core_cit); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2985 | target_cg->default_groups[0] = &target_core_hbagroup; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2986 | target_cg->default_groups[1] = NULL; |
| 2987 | /* |
| 2988 | * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/ |
| 2989 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2990 | hba_cg = &target_core_hbagroup; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 2991 | hba_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2992 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2993 | if (!hba_cg->default_groups) { |
| 2994 | pr_err("Unable to allocate hba_cg->default_groups\n"); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 2995 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2996 | goto out_global; |
| 2997 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2998 | config_group_init_type_name(&alua_group, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2999 | "alua", &target_core_alua_cit); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3000 | hba_cg->default_groups[0] = &alua_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3001 | hba_cg->default_groups[1] = NULL; |
| 3002 | /* |
| 3003 | * Add ALUA Logical Unit Group and Target Port Group ConfigFS |
| 3004 | * groups under /sys/kernel/config/target/core/alua/ |
| 3005 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3006 | alua_cg = &alua_group; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 3007 | alua_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3008 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3009 | if (!alua_cg->default_groups) { |
| 3010 | pr_err("Unable to allocate alua_cg->default_groups\n"); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 3011 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3012 | goto out_global; |
| 3013 | } |
| 3014 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3015 | config_group_init_type_name(&alua_lu_gps_group, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3016 | "lu_gps", &target_core_alua_lu_gps_cit); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3017 | alua_cg->default_groups[0] = &alua_lu_gps_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3018 | alua_cg->default_groups[1] = NULL; |
| 3019 | /* |
| 3020 | * Add core/alua/lu_gps/default_lu_gp |
| 3021 | */ |
| 3022 | lu_gp = core_alua_allocate_lu_gp("default_lu_gp", 1); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 3023 | if (IS_ERR(lu_gp)) { |
| 3024 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3025 | goto out_global; |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 3026 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3027 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3028 | lu_gp_cg = &alua_lu_gps_group; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 3029 | lu_gp_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3030 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3031 | if (!lu_gp_cg->default_groups) { |
| 3032 | pr_err("Unable to allocate lu_gp_cg->default_groups\n"); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 3033 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3034 | goto out_global; |
| 3035 | } |
| 3036 | |
| 3037 | config_group_init_type_name(&lu_gp->lu_gp_group, "default_lu_gp", |
| 3038 | &target_core_alua_lu_gp_cit); |
| 3039 | lu_gp_cg->default_groups[0] = &lu_gp->lu_gp_group; |
| 3040 | lu_gp_cg->default_groups[1] = NULL; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3041 | default_lu_gp = lu_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3042 | /* |
| 3043 | * Register the target_core_mod subsystem with configfs. |
| 3044 | */ |
| 3045 | ret = configfs_register_subsystem(subsys); |
| 3046 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3047 | pr_err("Error %d while registering subsystem %s\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3048 | ret, subsys->su_group.cg_item.ci_namebuf); |
| 3049 | goto out_global; |
| 3050 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3051 | pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3052 | " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION" on %s/%s" |
| 3053 | " on "UTS_RELEASE"\n", utsname()->sysname, utsname()->machine); |
| 3054 | /* |
| 3055 | * Register built-in RAMDISK subsystem logic for virtual LUN 0 |
| 3056 | */ |
| 3057 | ret = rd_module_init(); |
| 3058 | if (ret < 0) |
| 3059 | goto out; |
| 3060 | |
Roland Dreier | 0d0f9df | 2012-10-31 09:16:44 -0700 | [diff] [blame] | 3061 | ret = core_dev_setup_virtual_lun0(); |
| 3062 | if (ret < 0) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3063 | goto out; |
| 3064 | |
Nicholas Bellinger | f99715a | 2013-08-22 12:48:53 -0700 | [diff] [blame] | 3065 | ret = target_xcopy_setup_pt(); |
| 3066 | if (ret < 0) |
| 3067 | goto out; |
| 3068 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3069 | return 0; |
| 3070 | |
| 3071 | out: |
| 3072 | configfs_unregister_subsystem(subsys); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3073 | core_dev_release_virtual_lun0(); |
| 3074 | rd_module_exit(); |
| 3075 | out_global: |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3076 | if (default_lu_gp) { |
| 3077 | core_alua_free_lu_gp(default_lu_gp); |
| 3078 | default_lu_gp = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3079 | } |
| 3080 | if (lu_gp_cg) |
| 3081 | kfree(lu_gp_cg->default_groups); |
| 3082 | if (alua_cg) |
| 3083 | kfree(alua_cg->default_groups); |
| 3084 | if (hba_cg) |
| 3085 | kfree(hba_cg->default_groups); |
| 3086 | kfree(target_cg->default_groups); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3087 | release_se_kmem_caches(); |
| 3088 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3089 | } |
| 3090 | |
Axel Lin | 54550fa | 2011-03-14 04:06:09 -0700 | [diff] [blame] | 3091 | static void __exit target_core_exit_configfs(void) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3092 | { |
| 3093 | struct configfs_subsystem *subsys; |
| 3094 | struct config_group *hba_cg, *alua_cg, *lu_gp_cg; |
| 3095 | struct config_item *item; |
| 3096 | int i; |
| 3097 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3098 | subsys = target_core_subsystem[0]; |
| 3099 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3100 | lu_gp_cg = &alua_lu_gps_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3101 | for (i = 0; lu_gp_cg->default_groups[i]; i++) { |
| 3102 | item = &lu_gp_cg->default_groups[i]->cg_item; |
| 3103 | lu_gp_cg->default_groups[i] = NULL; |
| 3104 | config_item_put(item); |
| 3105 | } |
| 3106 | kfree(lu_gp_cg->default_groups); |
Nicholas Bellinger | 7c2bf6e | 2011-02-09 15:34:53 -0800 | [diff] [blame] | 3107 | lu_gp_cg->default_groups = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3108 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3109 | alua_cg = &alua_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3110 | for (i = 0; alua_cg->default_groups[i]; i++) { |
| 3111 | item = &alua_cg->default_groups[i]->cg_item; |
| 3112 | alua_cg->default_groups[i] = NULL; |
| 3113 | config_item_put(item); |
| 3114 | } |
| 3115 | kfree(alua_cg->default_groups); |
Nicholas Bellinger | 7c2bf6e | 2011-02-09 15:34:53 -0800 | [diff] [blame] | 3116 | alua_cg->default_groups = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3117 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3118 | hba_cg = &target_core_hbagroup; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3119 | for (i = 0; hba_cg->default_groups[i]; i++) { |
| 3120 | item = &hba_cg->default_groups[i]->cg_item; |
| 3121 | hba_cg->default_groups[i] = NULL; |
| 3122 | config_item_put(item); |
| 3123 | } |
| 3124 | kfree(hba_cg->default_groups); |
Nicholas Bellinger | 7c2bf6e | 2011-02-09 15:34:53 -0800 | [diff] [blame] | 3125 | hba_cg->default_groups = NULL; |
| 3126 | /* |
| 3127 | * We expect subsys->su_group.default_groups to be released |
| 3128 | * by configfs subsystem provider logic.. |
| 3129 | */ |
| 3130 | configfs_unregister_subsystem(subsys); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3131 | kfree(subsys->su_group.default_groups); |
| 3132 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3133 | core_alua_free_lu_gp(default_lu_gp); |
| 3134 | default_lu_gp = NULL; |
Nicholas Bellinger | 7c2bf6e | 2011-02-09 15:34:53 -0800 | [diff] [blame] | 3135 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3136 | pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3137 | " Infrastructure\n"); |
| 3138 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3139 | core_dev_release_virtual_lun0(); |
| 3140 | rd_module_exit(); |
Nicholas Bellinger | f99715a | 2013-08-22 12:48:53 -0700 | [diff] [blame] | 3141 | target_xcopy_release_pt(); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3142 | release_se_kmem_caches(); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3143 | } |
| 3144 | |
| 3145 | MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS"); |
| 3146 | MODULE_AUTHOR("nab@Linux-iSCSI.org"); |
| 3147 | MODULE_LICENSE("GPL"); |
| 3148 | |
| 3149 | module_init(target_core_init_configfs); |
| 3150 | module_exit(target_core_exit_configfs); |