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