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