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