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