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