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