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; |
| 820 | struct se_lun *lun; |
| 821 | struct se_portal_group *se_tpg; |
| 822 | struct t10_pr_registration *pr_reg; |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 823 | const struct target_core_fabric_ops *tfo; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 824 | ssize_t len = 0; |
| 825 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 826 | spin_lock(&dev->dev_reservation_lock); |
| 827 | pr_reg = dev->dev_pr_res_holder; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 828 | if (!pr_reg) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 829 | len = sprintf(page, "No SPC-3 Reservation holder\n"); |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 830 | goto out_unlock; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 831 | } |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 832 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 833 | se_nacl = pr_reg->pr_reg_nacl; |
| 834 | se_tpg = se_nacl->se_tpg; |
| 835 | lun = pr_reg->pr_reg_tg_pt_lun; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 836 | tfo = se_tpg->se_tpg_tfo; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 837 | |
| 838 | len += sprintf(page+len, "SPC-3 Reservation: %s" |
| 839 | " Target Node Endpoint: %s\n", tfo->get_fabric_name(), |
| 840 | tfo->tpg_get_wwn(se_tpg)); |
| 841 | len += sprintf(page+len, "SPC-3 Reservation: Relative Port" |
Masanari Iida | 35d1efe | 2012-08-16 22:43:13 +0900 | [diff] [blame] | 842 | " Identifier Tag: %hu %s Portal Group Tag: %hu" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 843 | " %s Logical Unit: %u\n", lun->lun_sep->sep_rtpi, |
| 844 | tfo->get_fabric_name(), tfo->tpg_get_tag(se_tpg), |
| 845 | tfo->get_fabric_name(), lun->unpacked_lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 846 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 847 | out_unlock: |
| 848 | spin_unlock(&dev->dev_reservation_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 849 | return len; |
| 850 | } |
| 851 | |
| 852 | SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port); |
| 853 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 854 | 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] | 855 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 856 | { |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 857 | const struct target_core_fabric_ops *tfo; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 858 | struct t10_pr_registration *pr_reg; |
| 859 | unsigned char buf[384]; |
| 860 | char i_buf[PR_REG_ISID_ID_LEN]; |
| 861 | ssize_t len = 0; |
Andy Grover | d2843c1 | 2013-05-16 10:40:55 -0700 | [diff] [blame] | 862 | int reg_count = 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 863 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 864 | len += sprintf(page+len, "SPC-3 PR Registrations:\n"); |
| 865 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 866 | spin_lock(&dev->t10_pr.registration_lock); |
| 867 | list_for_each_entry(pr_reg, &dev->t10_pr.registration_list, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 868 | pr_reg_list) { |
| 869 | |
| 870 | memset(buf, 0, 384); |
| 871 | memset(i_buf, 0, PR_REG_ISID_ID_LEN); |
| 872 | tfo = pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo; |
Andy Grover | d2843c1 | 2013-05-16 10:40:55 -0700 | [diff] [blame] | 873 | core_pr_dump_initiator_port(pr_reg, i_buf, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 874 | PR_REG_ISID_ID_LEN); |
| 875 | sprintf(buf, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n", |
| 876 | tfo->get_fabric_name(), |
Andy Grover | d2843c1 | 2013-05-16 10:40:55 -0700 | [diff] [blame] | 877 | 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] | 878 | pr_reg->pr_res_generation); |
| 879 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 880 | if (len + strlen(buf) >= PAGE_SIZE) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 881 | break; |
| 882 | |
| 883 | len += sprintf(page+len, "%s", buf); |
| 884 | reg_count++; |
| 885 | } |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 886 | spin_unlock(&dev->t10_pr.registration_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 887 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 888 | if (!reg_count) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 889 | len += sprintf(page+len, "None\n"); |
| 890 | |
| 891 | return len; |
| 892 | } |
| 893 | |
| 894 | SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts); |
| 895 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 896 | static ssize_t target_core_dev_pr_show_attr_res_pr_type( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 897 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 898 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 899 | struct t10_pr_registration *pr_reg; |
| 900 | ssize_t len = 0; |
| 901 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 902 | spin_lock(&dev->dev_reservation_lock); |
| 903 | pr_reg = dev->dev_pr_res_holder; |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 904 | if (pr_reg) { |
| 905 | len = sprintf(page, "SPC-3 Reservation Type: %s\n", |
| 906 | core_scsi3_pr_dump_type(pr_reg->pr_res_type)); |
| 907 | } else { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 908 | len = sprintf(page, "No SPC-3 Reservation holder\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 909 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 910 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 911 | spin_unlock(&dev->dev_reservation_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 912 | return len; |
| 913 | } |
| 914 | |
| 915 | SE_DEV_PR_ATTR_RO(res_pr_type); |
| 916 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 917 | static ssize_t target_core_dev_pr_show_attr_res_type( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 918 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 919 | { |
Andy Grover | a354170 | 2015-05-19 14:44:41 -0700 | [diff] [blame] | 920 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 921 | return sprintf(page, "SPC_PASSTHROUGH\n"); |
| 922 | else if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) |
| 923 | return sprintf(page, "SPC2_RESERVATIONS\n"); |
| 924 | else |
| 925 | return sprintf(page, "SPC3_PERSISTENT_RESERVATIONS\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | SE_DEV_PR_ATTR_RO(res_type); |
| 929 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 930 | static ssize_t target_core_dev_pr_show_attr_res_aptpl_active( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 931 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 932 | { |
Andy Grover | a354170 | 2015-05-19 14:44:41 -0700 | [diff] [blame] | 933 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 934 | return 0; |
| 935 | |
| 936 | return sprintf(page, "APTPL Bit Status: %s\n", |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 937 | (dev->t10_pr.pr_aptpl_active) ? "Activated" : "Disabled"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | SE_DEV_PR_ATTR_RO(res_aptpl_active); |
| 941 | |
| 942 | /* |
| 943 | * res_aptpl_metadata |
| 944 | */ |
| 945 | static ssize_t target_core_dev_pr_show_attr_res_aptpl_metadata( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 946 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 947 | { |
Andy Grover | a354170 | 2015-05-19 14:44:41 -0700 | [diff] [blame] | 948 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 949 | return 0; |
| 950 | |
| 951 | return sprintf(page, "Ready to process PR APTPL metadata..\n"); |
| 952 | } |
| 953 | |
| 954 | enum { |
| 955 | Opt_initiator_fabric, Opt_initiator_node, Opt_initiator_sid, |
| 956 | Opt_sa_res_key, Opt_res_holder, Opt_res_type, Opt_res_scope, |
| 957 | Opt_res_all_tg_pt, Opt_mapped_lun, Opt_target_fabric, |
| 958 | Opt_target_node, Opt_tpgt, Opt_port_rtpi, Opt_target_lun, Opt_err |
| 959 | }; |
| 960 | |
| 961 | static match_table_t tokens = { |
| 962 | {Opt_initiator_fabric, "initiator_fabric=%s"}, |
| 963 | {Opt_initiator_node, "initiator_node=%s"}, |
| 964 | {Opt_initiator_sid, "initiator_sid=%s"}, |
| 965 | {Opt_sa_res_key, "sa_res_key=%s"}, |
| 966 | {Opt_res_holder, "res_holder=%d"}, |
| 967 | {Opt_res_type, "res_type=%d"}, |
| 968 | {Opt_res_scope, "res_scope=%d"}, |
| 969 | {Opt_res_all_tg_pt, "res_all_tg_pt=%d"}, |
| 970 | {Opt_mapped_lun, "mapped_lun=%d"}, |
| 971 | {Opt_target_fabric, "target_fabric=%s"}, |
| 972 | {Opt_target_node, "target_node=%s"}, |
| 973 | {Opt_tpgt, "tpgt=%d"}, |
| 974 | {Opt_port_rtpi, "port_rtpi=%d"}, |
| 975 | {Opt_target_lun, "target_lun=%d"}, |
| 976 | {Opt_err, NULL} |
| 977 | }; |
| 978 | |
| 979 | static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 980 | struct se_device *dev, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 981 | const char *page, |
| 982 | size_t count) |
| 983 | { |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 984 | unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL; |
| 985 | unsigned char *t_fabric = NULL, *t_port = NULL; |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 986 | char *orig, *ptr, *opts; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 987 | substring_t args[MAX_OPT_ARGS]; |
| 988 | unsigned long long tmp_ll; |
| 989 | u64 sa_res_key = 0; |
| 990 | u32 mapped_lun = 0, target_lun = 0; |
| 991 | 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] | 992 | u16 tpgt = 0; |
| 993 | u8 type = 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 994 | |
Andy Grover | a354170 | 2015-05-19 14:44:41 -0700 | [diff] [blame] | 995 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 996 | return 0; |
| 997 | if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 998 | return 0; |
| 999 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1000 | if (dev->export_count) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1001 | pr_debug("Unable to process APTPL metadata while" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1002 | " active fabric exports exist\n"); |
| 1003 | return -EINVAL; |
| 1004 | } |
| 1005 | |
| 1006 | opts = kstrdup(page, GFP_KERNEL); |
| 1007 | if (!opts) |
| 1008 | return -ENOMEM; |
| 1009 | |
| 1010 | orig = opts; |
Sebastian Andrzej Siewior | 90c161b | 2011-11-23 20:53:17 +0100 | [diff] [blame] | 1011 | while ((ptr = strsep(&opts, ",\n")) != NULL) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1012 | if (!*ptr) |
| 1013 | continue; |
| 1014 | |
| 1015 | token = match_token(ptr, tokens, args); |
| 1016 | switch (token) { |
| 1017 | case Opt_initiator_fabric: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1018 | i_fabric = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1019 | if (!i_fabric) { |
| 1020 | ret = -ENOMEM; |
| 1021 | goto out; |
| 1022 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1023 | break; |
| 1024 | case Opt_initiator_node: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1025 | i_port = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1026 | if (!i_port) { |
| 1027 | ret = -ENOMEM; |
| 1028 | goto out; |
| 1029 | } |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 1030 | if (strlen(i_port) >= PR_APTPL_MAX_IPORT_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1031 | pr_err("APTPL metadata initiator_node=" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1032 | " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n", |
| 1033 | PR_APTPL_MAX_IPORT_LEN); |
| 1034 | ret = -EINVAL; |
| 1035 | break; |
| 1036 | } |
| 1037 | break; |
| 1038 | case Opt_initiator_sid: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1039 | isid = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1040 | if (!isid) { |
| 1041 | ret = -ENOMEM; |
| 1042 | goto out; |
| 1043 | } |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 1044 | if (strlen(isid) >= PR_REG_ISID_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1045 | pr_err("APTPL metadata initiator_isid" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1046 | "= exceeds PR_REG_ISID_LEN: %d\n", |
| 1047 | PR_REG_ISID_LEN); |
| 1048 | ret = -EINVAL; |
| 1049 | break; |
| 1050 | } |
| 1051 | break; |
| 1052 | case Opt_sa_res_key: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1053 | ret = kstrtoull(args->from, 0, &tmp_ll); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1054 | if (ret < 0) { |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1055 | pr_err("kstrtoull() failed for sa_res_key=\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1056 | goto out; |
| 1057 | } |
| 1058 | sa_res_key = (u64)tmp_ll; |
| 1059 | break; |
| 1060 | /* |
| 1061 | * PR APTPL Metadata for Reservation |
| 1062 | */ |
| 1063 | case Opt_res_holder: |
| 1064 | match_int(args, &arg); |
| 1065 | res_holder = arg; |
| 1066 | break; |
| 1067 | case Opt_res_type: |
| 1068 | match_int(args, &arg); |
| 1069 | type = (u8)arg; |
| 1070 | break; |
| 1071 | case Opt_res_scope: |
| 1072 | match_int(args, &arg); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1073 | break; |
| 1074 | case Opt_res_all_tg_pt: |
| 1075 | match_int(args, &arg); |
| 1076 | all_tg_pt = (int)arg; |
| 1077 | break; |
| 1078 | case Opt_mapped_lun: |
| 1079 | match_int(args, &arg); |
| 1080 | mapped_lun = (u32)arg; |
| 1081 | break; |
| 1082 | /* |
| 1083 | * PR APTPL Metadata for Target Port |
| 1084 | */ |
| 1085 | case Opt_target_fabric: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1086 | t_fabric = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1087 | if (!t_fabric) { |
| 1088 | ret = -ENOMEM; |
| 1089 | goto out; |
| 1090 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1091 | break; |
| 1092 | case Opt_target_node: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1093 | t_port = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1094 | if (!t_port) { |
| 1095 | ret = -ENOMEM; |
| 1096 | goto out; |
| 1097 | } |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 1098 | if (strlen(t_port) >= PR_APTPL_MAX_TPORT_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1099 | pr_err("APTPL metadata target_node=" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1100 | " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n", |
| 1101 | PR_APTPL_MAX_TPORT_LEN); |
| 1102 | ret = -EINVAL; |
| 1103 | break; |
| 1104 | } |
| 1105 | break; |
| 1106 | case Opt_tpgt: |
| 1107 | match_int(args, &arg); |
| 1108 | tpgt = (u16)arg; |
| 1109 | break; |
| 1110 | case Opt_port_rtpi: |
| 1111 | match_int(args, &arg); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1112 | break; |
| 1113 | case Opt_target_lun: |
| 1114 | match_int(args, &arg); |
| 1115 | target_lun = (u32)arg; |
| 1116 | break; |
| 1117 | default: |
| 1118 | break; |
| 1119 | } |
| 1120 | } |
| 1121 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1122 | if (!i_port || !t_port || !sa_res_key) { |
| 1123 | pr_err("Illegal parameters for APTPL registration\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1124 | ret = -EINVAL; |
| 1125 | goto out; |
| 1126 | } |
| 1127 | |
| 1128 | if (res_holder && !(type)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1129 | pr_err("Illegal PR type: 0x%02x for reservation" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1130 | " holder\n", type); |
| 1131 | ret = -EINVAL; |
| 1132 | goto out; |
| 1133 | } |
| 1134 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1135 | ret = core_scsi3_alloc_aptpl_registration(&dev->t10_pr, sa_res_key, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1136 | i_port, isid, mapped_lun, t_port, tpgt, target_lun, |
| 1137 | res_holder, all_tg_pt, type); |
| 1138 | out: |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1139 | kfree(i_fabric); |
| 1140 | kfree(i_port); |
| 1141 | kfree(isid); |
| 1142 | kfree(t_fabric); |
| 1143 | kfree(t_port); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1144 | kfree(orig); |
| 1145 | return (ret == 0) ? count : ret; |
| 1146 | } |
| 1147 | |
| 1148 | SE_DEV_PR_ATTR(res_aptpl_metadata, S_IRUGO | S_IWUSR); |
| 1149 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1150 | CONFIGFS_EATTR_OPS(target_core_dev_pr, se_device, dev_pr_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1151 | |
| 1152 | static struct configfs_attribute *target_core_dev_pr_attrs[] = { |
| 1153 | &target_core_dev_pr_res_holder.attr, |
| 1154 | &target_core_dev_pr_res_pr_all_tgt_pts.attr, |
| 1155 | &target_core_dev_pr_res_pr_generation.attr, |
| 1156 | &target_core_dev_pr_res_pr_holder_tg_port.attr, |
| 1157 | &target_core_dev_pr_res_pr_registered_i_pts.attr, |
| 1158 | &target_core_dev_pr_res_pr_type.attr, |
| 1159 | &target_core_dev_pr_res_type.attr, |
| 1160 | &target_core_dev_pr_res_aptpl_active.attr, |
| 1161 | &target_core_dev_pr_res_aptpl_metadata.attr, |
| 1162 | NULL, |
| 1163 | }; |
| 1164 | |
| 1165 | static struct configfs_item_operations target_core_dev_pr_ops = { |
| 1166 | .show_attribute = target_core_dev_pr_attr_show, |
| 1167 | .store_attribute = target_core_dev_pr_attr_store, |
| 1168 | }; |
| 1169 | |
Nicholas Bellinger | 91e2e39 | 2014-11-27 14:57:01 -0800 | [diff] [blame] | 1170 | 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] | 1171 | |
Nicholas Bellinger | 91e2e39 | 2014-11-27 14:57:01 -0800 | [diff] [blame] | 1172 | /* End functions for struct config_item_type tb_dev_pr_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1173 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 1174 | /* Start functions for struct config_item_type tb_dev_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1175 | |
| 1176 | static ssize_t target_core_show_dev_info(void *p, char *page) |
| 1177 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1178 | struct se_device *dev = p; |
| 1179 | struct se_subsystem_api *t = dev->transport; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1180 | int bl = 0; |
| 1181 | ssize_t read_bytes = 0; |
| 1182 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1183 | transport_dump_dev_state(dev, page, &bl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1184 | read_bytes += bl; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1185 | read_bytes += t->show_configfs_dev_params(dev, page+read_bytes); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1186 | return read_bytes; |
| 1187 | } |
| 1188 | |
| 1189 | static struct target_core_configfs_attribute target_core_attr_dev_info = { |
| 1190 | .attr = { .ca_owner = THIS_MODULE, |
| 1191 | .ca_name = "info", |
| 1192 | .ca_mode = S_IRUGO }, |
| 1193 | .show = target_core_show_dev_info, |
| 1194 | .store = NULL, |
| 1195 | }; |
| 1196 | |
| 1197 | static ssize_t target_core_store_dev_control( |
| 1198 | void *p, |
| 1199 | const char *page, |
| 1200 | size_t count) |
| 1201 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1202 | struct se_device *dev = p; |
| 1203 | struct se_subsystem_api *t = dev->transport; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1204 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1205 | return t->set_configfs_dev_params(dev, page, count); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1206 | } |
| 1207 | |
| 1208 | static struct target_core_configfs_attribute target_core_attr_dev_control = { |
| 1209 | .attr = { .ca_owner = THIS_MODULE, |
| 1210 | .ca_name = "control", |
| 1211 | .ca_mode = S_IWUSR }, |
| 1212 | .show = NULL, |
| 1213 | .store = target_core_store_dev_control, |
| 1214 | }; |
| 1215 | |
| 1216 | static ssize_t target_core_show_dev_alias(void *p, char *page) |
| 1217 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1218 | struct se_device *dev = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1219 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1220 | if (!(dev->dev_flags & DF_USING_ALIAS)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1221 | return 0; |
| 1222 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1223 | return snprintf(page, PAGE_SIZE, "%s\n", dev->dev_alias); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1224 | } |
| 1225 | |
| 1226 | static ssize_t target_core_store_dev_alias( |
| 1227 | void *p, |
| 1228 | const char *page, |
| 1229 | size_t count) |
| 1230 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1231 | struct se_device *dev = p; |
| 1232 | struct se_hba *hba = dev->se_hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1233 | ssize_t read_bytes; |
| 1234 | |
| 1235 | if (count > (SE_DEV_ALIAS_LEN-1)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1236 | pr_err("alias count: %d exceeds" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1237 | " SE_DEV_ALIAS_LEN-1: %u\n", (int)count, |
| 1238 | SE_DEV_ALIAS_LEN-1); |
| 1239 | return -EINVAL; |
| 1240 | } |
| 1241 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1242 | 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] | 1243 | if (!read_bytes) |
| 1244 | return -EINVAL; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1245 | if (dev->dev_alias[read_bytes - 1] == '\n') |
| 1246 | dev->dev_alias[read_bytes - 1] = '\0'; |
Sebastian Andrzej Siewior | 0877eafd | 2011-11-28 13:57:25 +0100 | [diff] [blame] | 1247 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1248 | dev->dev_flags |= DF_USING_ALIAS; |
Dan Carpenter | 3011684 | 2012-01-27 15:50:55 +0300 | [diff] [blame] | 1249 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1250 | pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1251 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1252 | config_item_name(&dev->dev_group.cg_item), |
| 1253 | dev->dev_alias); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1254 | |
| 1255 | return read_bytes; |
| 1256 | } |
| 1257 | |
| 1258 | static struct target_core_configfs_attribute target_core_attr_dev_alias = { |
| 1259 | .attr = { .ca_owner = THIS_MODULE, |
| 1260 | .ca_name = "alias", |
| 1261 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 1262 | .show = target_core_show_dev_alias, |
| 1263 | .store = target_core_store_dev_alias, |
| 1264 | }; |
| 1265 | |
| 1266 | static ssize_t target_core_show_dev_udev_path(void *p, char *page) |
| 1267 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1268 | struct se_device *dev = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1269 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1270 | if (!(dev->dev_flags & DF_USING_UDEV_PATH)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1271 | return 0; |
| 1272 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1273 | return snprintf(page, PAGE_SIZE, "%s\n", dev->udev_path); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | static ssize_t target_core_store_dev_udev_path( |
| 1277 | void *p, |
| 1278 | const char *page, |
| 1279 | size_t count) |
| 1280 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1281 | struct se_device *dev = p; |
| 1282 | struct se_hba *hba = dev->se_hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1283 | ssize_t read_bytes; |
| 1284 | |
| 1285 | if (count > (SE_UDEV_PATH_LEN-1)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1286 | pr_err("udev_path count: %d exceeds" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1287 | " SE_UDEV_PATH_LEN-1: %u\n", (int)count, |
| 1288 | SE_UDEV_PATH_LEN-1); |
| 1289 | return -EINVAL; |
| 1290 | } |
| 1291 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1292 | read_bytes = snprintf(&dev->udev_path[0], SE_UDEV_PATH_LEN, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1293 | "%s", page); |
Dan Carpenter | 3011684 | 2012-01-27 15:50:55 +0300 | [diff] [blame] | 1294 | if (!read_bytes) |
| 1295 | return -EINVAL; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1296 | if (dev->udev_path[read_bytes - 1] == '\n') |
| 1297 | dev->udev_path[read_bytes - 1] = '\0'; |
Sebastian Andrzej Siewior | 0877eafd | 2011-11-28 13:57:25 +0100 | [diff] [blame] | 1298 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1299 | dev->dev_flags |= DF_USING_UDEV_PATH; |
Dan Carpenter | 3011684 | 2012-01-27 15:50:55 +0300 | [diff] [blame] | 1300 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1301 | pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1302 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1303 | config_item_name(&dev->dev_group.cg_item), |
| 1304 | dev->udev_path); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1305 | |
| 1306 | return read_bytes; |
| 1307 | } |
| 1308 | |
| 1309 | static struct target_core_configfs_attribute target_core_attr_dev_udev_path = { |
| 1310 | .attr = { .ca_owner = THIS_MODULE, |
| 1311 | .ca_name = "udev_path", |
| 1312 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 1313 | .show = target_core_show_dev_udev_path, |
| 1314 | .store = target_core_store_dev_udev_path, |
| 1315 | }; |
| 1316 | |
Andy Grover | 64146db | 2013-04-30 11:59:15 -0700 | [diff] [blame] | 1317 | static ssize_t target_core_show_dev_enable(void *p, char *page) |
| 1318 | { |
| 1319 | struct se_device *dev = p; |
| 1320 | |
| 1321 | return snprintf(page, PAGE_SIZE, "%d\n", !!(dev->dev_flags & DF_CONFIGURED)); |
| 1322 | } |
| 1323 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1324 | static ssize_t target_core_store_dev_enable( |
| 1325 | void *p, |
| 1326 | const char *page, |
| 1327 | size_t count) |
| 1328 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1329 | struct se_device *dev = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1330 | char *ptr; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1331 | int ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1332 | |
| 1333 | ptr = strstr(page, "1"); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1334 | if (!ptr) { |
| 1335 | pr_err("For dev_enable ops, only valid value" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1336 | " is \"1\"\n"); |
| 1337 | return -EINVAL; |
| 1338 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1339 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1340 | ret = target_configure_device(dev); |
| 1341 | if (ret) |
| 1342 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1343 | return count; |
| 1344 | } |
| 1345 | |
| 1346 | static struct target_core_configfs_attribute target_core_attr_dev_enable = { |
| 1347 | .attr = { .ca_owner = THIS_MODULE, |
| 1348 | .ca_name = "enable", |
Andy Grover | 64146db | 2013-04-30 11:59:15 -0700 | [diff] [blame] | 1349 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 1350 | .show = target_core_show_dev_enable, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1351 | .store = target_core_store_dev_enable, |
| 1352 | }; |
| 1353 | |
| 1354 | static ssize_t target_core_show_alua_lu_gp(void *p, char *page) |
| 1355 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1356 | struct se_device *dev = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1357 | struct config_item *lu_ci; |
| 1358 | struct t10_alua_lu_gp *lu_gp; |
| 1359 | struct t10_alua_lu_gp_member *lu_gp_mem; |
| 1360 | ssize_t len = 0; |
| 1361 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1362 | lu_gp_mem = dev->dev_alua_lu_gp_mem; |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 1363 | if (!lu_gp_mem) |
| 1364 | return 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1365 | |
| 1366 | spin_lock(&lu_gp_mem->lu_gp_mem_lock); |
| 1367 | lu_gp = lu_gp_mem->lu_gp; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1368 | if (lu_gp) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1369 | lu_ci = &lu_gp->lu_gp_group.cg_item; |
| 1370 | len += sprintf(page, "LU Group Alias: %s\nLU Group ID: %hu\n", |
| 1371 | config_item_name(lu_ci), lu_gp->lu_gp_id); |
| 1372 | } |
| 1373 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); |
| 1374 | |
| 1375 | return len; |
| 1376 | } |
| 1377 | |
| 1378 | static ssize_t target_core_store_alua_lu_gp( |
| 1379 | void *p, |
| 1380 | const char *page, |
| 1381 | size_t count) |
| 1382 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1383 | struct se_device *dev = p; |
| 1384 | struct se_hba *hba = dev->se_hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1385 | struct t10_alua_lu_gp *lu_gp = NULL, *lu_gp_new = NULL; |
| 1386 | struct t10_alua_lu_gp_member *lu_gp_mem; |
| 1387 | unsigned char buf[LU_GROUP_NAME_BUF]; |
| 1388 | int move = 0; |
| 1389 | |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 1390 | lu_gp_mem = dev->dev_alua_lu_gp_mem; |
| 1391 | if (!lu_gp_mem) |
| 1392 | return 0; |
| 1393 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1394 | if (count > LU_GROUP_NAME_BUF) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1395 | pr_err("ALUA LU Group Alias too large!\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1396 | return -EINVAL; |
| 1397 | } |
| 1398 | memset(buf, 0, LU_GROUP_NAME_BUF); |
| 1399 | memcpy(buf, page, count); |
| 1400 | /* |
| 1401 | * Any ALUA logical unit alias besides "NULL" means we will be |
| 1402 | * making a new group association. |
| 1403 | */ |
| 1404 | if (strcmp(strstrip(buf), "NULL")) { |
| 1405 | /* |
| 1406 | * core_alua_get_lu_gp_by_name() will increment reference to |
| 1407 | * struct t10_alua_lu_gp. This reference is released with |
| 1408 | * core_alua_get_lu_gp_by_name below(). |
| 1409 | */ |
| 1410 | lu_gp_new = core_alua_get_lu_gp_by_name(strstrip(buf)); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1411 | if (!lu_gp_new) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1412 | return -ENODEV; |
| 1413 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1414 | |
| 1415 | spin_lock(&lu_gp_mem->lu_gp_mem_lock); |
| 1416 | lu_gp = lu_gp_mem->lu_gp; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1417 | if (lu_gp) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1418 | /* |
| 1419 | * Clearing an existing lu_gp association, and replacing |
| 1420 | * with NULL |
| 1421 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1422 | if (!lu_gp_new) { |
| 1423 | pr_debug("Target_Core_ConfigFS: Releasing %s/%s" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1424 | " from ALUA LU Group: core/alua/lu_gps/%s, ID:" |
| 1425 | " %hu\n", |
| 1426 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1427 | config_item_name(&dev->dev_group.cg_item), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1428 | config_item_name(&lu_gp->lu_gp_group.cg_item), |
| 1429 | lu_gp->lu_gp_id); |
| 1430 | |
| 1431 | __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp); |
| 1432 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); |
| 1433 | |
| 1434 | return count; |
| 1435 | } |
| 1436 | /* |
| 1437 | * Removing existing association of lu_gp_mem with lu_gp |
| 1438 | */ |
| 1439 | __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp); |
| 1440 | move = 1; |
| 1441 | } |
| 1442 | /* |
| 1443 | * Associate lu_gp_mem with lu_gp_new. |
| 1444 | */ |
| 1445 | __core_alua_attach_lu_gp_mem(lu_gp_mem, lu_gp_new); |
| 1446 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); |
| 1447 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1448 | pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1449 | " core/alua/lu_gps/%s, ID: %hu\n", |
| 1450 | (move) ? "Moving" : "Adding", |
| 1451 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1452 | config_item_name(&dev->dev_group.cg_item), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1453 | config_item_name(&lu_gp_new->lu_gp_group.cg_item), |
| 1454 | lu_gp_new->lu_gp_id); |
| 1455 | |
| 1456 | core_alua_put_lu_gp_from_name(lu_gp_new); |
| 1457 | return count; |
| 1458 | } |
| 1459 | |
| 1460 | static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp = { |
| 1461 | .attr = { .ca_owner = THIS_MODULE, |
| 1462 | .ca_name = "alua_lu_gp", |
| 1463 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 1464 | .show = target_core_show_alua_lu_gp, |
| 1465 | .store = target_core_store_alua_lu_gp, |
| 1466 | }; |
| 1467 | |
Hannes Reinecke | 229d4f1 | 2013-12-17 09:18:50 +0100 | [diff] [blame] | 1468 | static ssize_t target_core_show_dev_lba_map(void *p, char *page) |
| 1469 | { |
| 1470 | struct se_device *dev = p; |
| 1471 | struct t10_alua_lba_map *map; |
| 1472 | struct t10_alua_lba_map_member *mem; |
| 1473 | char *b = page; |
| 1474 | int bl = 0; |
| 1475 | char state; |
| 1476 | |
| 1477 | spin_lock(&dev->t10_alua.lba_map_lock); |
| 1478 | if (!list_empty(&dev->t10_alua.lba_map_list)) |
| 1479 | bl += sprintf(b + bl, "%u %u\n", |
| 1480 | dev->t10_alua.lba_map_segment_size, |
| 1481 | dev->t10_alua.lba_map_segment_multiplier); |
| 1482 | list_for_each_entry(map, &dev->t10_alua.lba_map_list, lba_map_list) { |
| 1483 | bl += sprintf(b + bl, "%llu %llu", |
| 1484 | map->lba_map_first_lba, map->lba_map_last_lba); |
| 1485 | list_for_each_entry(mem, &map->lba_map_mem_list, |
| 1486 | lba_map_mem_list) { |
| 1487 | switch (mem->lba_map_mem_alua_state) { |
| 1488 | case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED: |
| 1489 | state = 'O'; |
| 1490 | break; |
| 1491 | case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED: |
| 1492 | state = 'A'; |
| 1493 | break; |
| 1494 | case ALUA_ACCESS_STATE_STANDBY: |
| 1495 | state = 'S'; |
| 1496 | break; |
| 1497 | case ALUA_ACCESS_STATE_UNAVAILABLE: |
| 1498 | state = 'U'; |
| 1499 | break; |
| 1500 | default: |
| 1501 | state = '.'; |
| 1502 | break; |
| 1503 | } |
| 1504 | bl += sprintf(b + bl, " %d:%c", |
| 1505 | mem->lba_map_mem_alua_pg_id, state); |
| 1506 | } |
| 1507 | bl += sprintf(b + bl, "\n"); |
| 1508 | } |
| 1509 | spin_unlock(&dev->t10_alua.lba_map_lock); |
| 1510 | return bl; |
| 1511 | } |
| 1512 | |
| 1513 | static ssize_t target_core_store_dev_lba_map( |
| 1514 | void *p, |
| 1515 | const char *page, |
| 1516 | size_t count) |
| 1517 | { |
| 1518 | struct se_device *dev = p; |
| 1519 | struct t10_alua_lba_map *lba_map = NULL; |
| 1520 | struct list_head lba_list; |
| 1521 | char *map_entries, *ptr; |
| 1522 | char state; |
| 1523 | int pg_num = -1, pg; |
| 1524 | int ret = 0, num = 0, pg_id, alua_state; |
| 1525 | unsigned long start_lba = -1, end_lba = -1; |
| 1526 | unsigned long segment_size = -1, segment_mult = -1; |
| 1527 | |
| 1528 | map_entries = kstrdup(page, GFP_KERNEL); |
| 1529 | if (!map_entries) |
| 1530 | return -ENOMEM; |
| 1531 | |
| 1532 | INIT_LIST_HEAD(&lba_list); |
| 1533 | while ((ptr = strsep(&map_entries, "\n")) != NULL) { |
| 1534 | if (!*ptr) |
| 1535 | continue; |
| 1536 | |
| 1537 | if (num == 0) { |
| 1538 | if (sscanf(ptr, "%lu %lu\n", |
| 1539 | &segment_size, &segment_mult) != 2) { |
| 1540 | pr_err("Invalid line %d\n", num); |
| 1541 | ret = -EINVAL; |
| 1542 | break; |
| 1543 | } |
| 1544 | num++; |
| 1545 | continue; |
| 1546 | } |
| 1547 | if (sscanf(ptr, "%lu %lu", &start_lba, &end_lba) != 2) { |
| 1548 | pr_err("Invalid line %d\n", num); |
| 1549 | ret = -EINVAL; |
| 1550 | break; |
| 1551 | } |
| 1552 | ptr = strchr(ptr, ' '); |
| 1553 | if (!ptr) { |
| 1554 | pr_err("Invalid line %d, missing end lba\n", num); |
| 1555 | ret = -EINVAL; |
| 1556 | break; |
| 1557 | } |
| 1558 | ptr++; |
| 1559 | ptr = strchr(ptr, ' '); |
| 1560 | if (!ptr) { |
| 1561 | pr_err("Invalid line %d, missing state definitions\n", |
| 1562 | num); |
| 1563 | ret = -EINVAL; |
| 1564 | break; |
| 1565 | } |
| 1566 | ptr++; |
| 1567 | lba_map = core_alua_allocate_lba_map(&lba_list, |
| 1568 | start_lba, end_lba); |
| 1569 | if (IS_ERR(lba_map)) { |
| 1570 | ret = PTR_ERR(lba_map); |
| 1571 | break; |
| 1572 | } |
| 1573 | pg = 0; |
| 1574 | while (sscanf(ptr, "%d:%c", &pg_id, &state) == 2) { |
| 1575 | switch (state) { |
| 1576 | case 'O': |
| 1577 | alua_state = ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED; |
| 1578 | break; |
| 1579 | case 'A': |
| 1580 | alua_state = ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED; |
| 1581 | break; |
| 1582 | case 'S': |
| 1583 | alua_state = ALUA_ACCESS_STATE_STANDBY; |
| 1584 | break; |
| 1585 | case 'U': |
| 1586 | alua_state = ALUA_ACCESS_STATE_UNAVAILABLE; |
| 1587 | break; |
| 1588 | default: |
| 1589 | pr_err("Invalid ALUA state '%c'\n", state); |
| 1590 | ret = -EINVAL; |
| 1591 | goto out; |
| 1592 | } |
| 1593 | |
| 1594 | ret = core_alua_allocate_lba_map_mem(lba_map, |
| 1595 | pg_id, alua_state); |
| 1596 | if (ret) { |
| 1597 | pr_err("Invalid target descriptor %d:%c " |
| 1598 | "at line %d\n", |
| 1599 | pg_id, state, num); |
| 1600 | break; |
| 1601 | } |
| 1602 | pg++; |
| 1603 | ptr = strchr(ptr, ' '); |
| 1604 | if (ptr) |
| 1605 | ptr++; |
| 1606 | else |
| 1607 | break; |
| 1608 | } |
| 1609 | if (pg_num == -1) |
| 1610 | pg_num = pg; |
| 1611 | else if (pg != pg_num) { |
| 1612 | pr_err("Only %d from %d port groups definitions " |
| 1613 | "at line %d\n", pg, pg_num, num); |
| 1614 | ret = -EINVAL; |
| 1615 | break; |
| 1616 | } |
| 1617 | num++; |
| 1618 | } |
| 1619 | out: |
| 1620 | if (ret) { |
| 1621 | core_alua_free_lba_map(&lba_list); |
| 1622 | count = ret; |
| 1623 | } else |
| 1624 | core_alua_set_lba_map(dev, &lba_list, |
| 1625 | segment_size, segment_mult); |
| 1626 | kfree(map_entries); |
| 1627 | return count; |
| 1628 | } |
| 1629 | |
| 1630 | static struct target_core_configfs_attribute target_core_attr_dev_lba_map = { |
| 1631 | .attr = { .ca_owner = THIS_MODULE, |
| 1632 | .ca_name = "lba_map", |
| 1633 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 1634 | .show = target_core_show_dev_lba_map, |
| 1635 | .store = target_core_store_dev_lba_map, |
| 1636 | }; |
| 1637 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 1638 | static struct configfs_attribute *target_core_dev_attrs[] = { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1639 | &target_core_attr_dev_info.attr, |
| 1640 | &target_core_attr_dev_control.attr, |
| 1641 | &target_core_attr_dev_alias.attr, |
| 1642 | &target_core_attr_dev_udev_path.attr, |
| 1643 | &target_core_attr_dev_enable.attr, |
| 1644 | &target_core_attr_dev_alua_lu_gp.attr, |
Hannes Reinecke | 229d4f1 | 2013-12-17 09:18:50 +0100 | [diff] [blame] | 1645 | &target_core_attr_dev_lba_map.attr, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1646 | NULL, |
| 1647 | }; |
| 1648 | |
| 1649 | static void target_core_dev_release(struct config_item *item) |
| 1650 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1651 | struct config_group *dev_cg = to_config_group(item); |
| 1652 | struct se_device *dev = |
| 1653 | container_of(dev_cg, struct se_device, dev_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1654 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1655 | kfree(dev_cg->default_groups); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1656 | target_free_device(dev); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | static ssize_t target_core_dev_show(struct config_item *item, |
| 1660 | struct configfs_attribute *attr, |
| 1661 | char *page) |
| 1662 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1663 | struct config_group *dev_cg = to_config_group(item); |
| 1664 | struct se_device *dev = |
| 1665 | container_of(dev_cg, struct se_device, dev_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1666 | struct target_core_configfs_attribute *tc_attr = container_of( |
| 1667 | attr, struct target_core_configfs_attribute, attr); |
| 1668 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1669 | if (!tc_attr->show) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1670 | return -EINVAL; |
| 1671 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1672 | return tc_attr->show(dev, page); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | static ssize_t target_core_dev_store(struct config_item *item, |
| 1676 | struct configfs_attribute *attr, |
| 1677 | const char *page, size_t count) |
| 1678 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1679 | struct config_group *dev_cg = to_config_group(item); |
| 1680 | struct se_device *dev = |
| 1681 | container_of(dev_cg, struct se_device, dev_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1682 | struct target_core_configfs_attribute *tc_attr = container_of( |
| 1683 | attr, struct target_core_configfs_attribute, attr); |
| 1684 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1685 | if (!tc_attr->store) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1686 | return -EINVAL; |
| 1687 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1688 | return tc_attr->store(dev, page, count); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1689 | } |
| 1690 | |
| 1691 | static struct configfs_item_operations target_core_dev_item_ops = { |
| 1692 | .release = target_core_dev_release, |
| 1693 | .show_attribute = target_core_dev_show, |
| 1694 | .store_attribute = target_core_dev_store, |
| 1695 | }; |
| 1696 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 1697 | 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] | 1698 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 1699 | /* End functions for struct config_item_type tb_dev_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1700 | |
| 1701 | /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */ |
| 1702 | |
| 1703 | CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp, t10_alua_lu_gp); |
| 1704 | #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \ |
| 1705 | static struct target_core_alua_lu_gp_attribute \ |
| 1706 | target_core_alua_lu_gp_##_name = \ |
| 1707 | __CONFIGFS_EATTR(_name, _mode, \ |
| 1708 | target_core_alua_lu_gp_show_attr_##_name, \ |
| 1709 | target_core_alua_lu_gp_store_attr_##_name); |
| 1710 | |
| 1711 | #define SE_DEV_ALUA_LU_ATTR_RO(_name) \ |
| 1712 | static struct target_core_alua_lu_gp_attribute \ |
| 1713 | target_core_alua_lu_gp_##_name = \ |
| 1714 | __CONFIGFS_EATTR_RO(_name, \ |
| 1715 | target_core_alua_lu_gp_show_attr_##_name); |
| 1716 | |
| 1717 | /* |
| 1718 | * lu_gp_id |
| 1719 | */ |
| 1720 | static ssize_t target_core_alua_lu_gp_show_attr_lu_gp_id( |
| 1721 | struct t10_alua_lu_gp *lu_gp, |
| 1722 | char *page) |
| 1723 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1724 | if (!lu_gp->lu_gp_valid_id) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1725 | return 0; |
| 1726 | |
| 1727 | return sprintf(page, "%hu\n", lu_gp->lu_gp_id); |
| 1728 | } |
| 1729 | |
| 1730 | static ssize_t target_core_alua_lu_gp_store_attr_lu_gp_id( |
| 1731 | struct t10_alua_lu_gp *lu_gp, |
| 1732 | const char *page, |
| 1733 | size_t count) |
| 1734 | { |
| 1735 | struct config_group *alua_lu_gp_cg = &lu_gp->lu_gp_group; |
| 1736 | unsigned long lu_gp_id; |
| 1737 | int ret; |
| 1738 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 1739 | ret = kstrtoul(page, 0, &lu_gp_id); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1740 | if (ret < 0) { |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 1741 | pr_err("kstrtoul() returned %d for" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1742 | " lu_gp_id\n", ret); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 1743 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1744 | } |
| 1745 | if (lu_gp_id > 0x0000ffff) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1746 | pr_err("ALUA lu_gp_id: %lu exceeds maximum:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1747 | " 0x0000ffff\n", lu_gp_id); |
| 1748 | return -EINVAL; |
| 1749 | } |
| 1750 | |
| 1751 | ret = core_alua_set_lu_gp_id(lu_gp, (u16)lu_gp_id); |
| 1752 | if (ret < 0) |
| 1753 | return -EINVAL; |
| 1754 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1755 | pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1756 | " Group: core/alua/lu_gps/%s to ID: %hu\n", |
| 1757 | config_item_name(&alua_lu_gp_cg->cg_item), |
| 1758 | lu_gp->lu_gp_id); |
| 1759 | |
| 1760 | return count; |
| 1761 | } |
| 1762 | |
| 1763 | SE_DEV_ALUA_LU_ATTR(lu_gp_id, S_IRUGO | S_IWUSR); |
| 1764 | |
| 1765 | /* |
| 1766 | * members |
| 1767 | */ |
| 1768 | static ssize_t target_core_alua_lu_gp_show_attr_members( |
| 1769 | struct t10_alua_lu_gp *lu_gp, |
| 1770 | char *page) |
| 1771 | { |
| 1772 | struct se_device *dev; |
| 1773 | struct se_hba *hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1774 | struct t10_alua_lu_gp_member *lu_gp_mem; |
| 1775 | ssize_t len = 0, cur_len; |
| 1776 | unsigned char buf[LU_GROUP_NAME_BUF]; |
| 1777 | |
| 1778 | memset(buf, 0, LU_GROUP_NAME_BUF); |
| 1779 | |
| 1780 | spin_lock(&lu_gp->lu_gp_lock); |
| 1781 | list_for_each_entry(lu_gp_mem, &lu_gp->lu_gp_mem_list, lu_gp_mem_list) { |
| 1782 | dev = lu_gp_mem->lu_gp_mem_dev; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1783 | hba = dev->se_hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1784 | |
| 1785 | cur_len = snprintf(buf, LU_GROUP_NAME_BUF, "%s/%s\n", |
| 1786 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1787 | config_item_name(&dev->dev_group.cg_item)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1788 | cur_len++; /* Extra byte for NULL terminator */ |
| 1789 | |
| 1790 | if ((cur_len + len) > PAGE_SIZE) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1791 | pr_warn("Ran out of lu_gp_show_attr" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1792 | "_members buffer\n"); |
| 1793 | break; |
| 1794 | } |
| 1795 | memcpy(page+len, buf, cur_len); |
| 1796 | len += cur_len; |
| 1797 | } |
| 1798 | spin_unlock(&lu_gp->lu_gp_lock); |
| 1799 | |
| 1800 | return len; |
| 1801 | } |
| 1802 | |
| 1803 | SE_DEV_ALUA_LU_ATTR_RO(members); |
| 1804 | |
| 1805 | CONFIGFS_EATTR_OPS(target_core_alua_lu_gp, t10_alua_lu_gp, lu_gp_group); |
| 1806 | |
| 1807 | static struct configfs_attribute *target_core_alua_lu_gp_attrs[] = { |
| 1808 | &target_core_alua_lu_gp_lu_gp_id.attr, |
| 1809 | &target_core_alua_lu_gp_members.attr, |
| 1810 | NULL, |
| 1811 | }; |
| 1812 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 1813 | static void target_core_alua_lu_gp_release(struct config_item *item) |
| 1814 | { |
| 1815 | struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item), |
| 1816 | struct t10_alua_lu_gp, lu_gp_group); |
| 1817 | |
| 1818 | core_alua_free_lu_gp(lu_gp); |
| 1819 | } |
| 1820 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1821 | static struct configfs_item_operations target_core_alua_lu_gp_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 1822 | .release = target_core_alua_lu_gp_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1823 | .show_attribute = target_core_alua_lu_gp_attr_show, |
| 1824 | .store_attribute = target_core_alua_lu_gp_attr_store, |
| 1825 | }; |
| 1826 | |
| 1827 | static struct config_item_type target_core_alua_lu_gp_cit = { |
| 1828 | .ct_item_ops = &target_core_alua_lu_gp_ops, |
| 1829 | .ct_attrs = target_core_alua_lu_gp_attrs, |
| 1830 | .ct_owner = THIS_MODULE, |
| 1831 | }; |
| 1832 | |
| 1833 | /* End functions for struct config_item_type target_core_alua_lu_gp_cit */ |
| 1834 | |
| 1835 | /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */ |
| 1836 | |
| 1837 | static struct config_group *target_core_alua_create_lu_gp( |
| 1838 | struct config_group *group, |
| 1839 | const char *name) |
| 1840 | { |
| 1841 | struct t10_alua_lu_gp *lu_gp; |
| 1842 | struct config_group *alua_lu_gp_cg = NULL; |
| 1843 | struct config_item *alua_lu_gp_ci = NULL; |
| 1844 | |
| 1845 | lu_gp = core_alua_allocate_lu_gp(name, 0); |
| 1846 | if (IS_ERR(lu_gp)) |
| 1847 | return NULL; |
| 1848 | |
| 1849 | alua_lu_gp_cg = &lu_gp->lu_gp_group; |
| 1850 | alua_lu_gp_ci = &alua_lu_gp_cg->cg_item; |
| 1851 | |
| 1852 | config_group_init_type_name(alua_lu_gp_cg, name, |
| 1853 | &target_core_alua_lu_gp_cit); |
| 1854 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1855 | pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1856 | " Group: core/alua/lu_gps/%s\n", |
| 1857 | config_item_name(alua_lu_gp_ci)); |
| 1858 | |
| 1859 | return alua_lu_gp_cg; |
| 1860 | |
| 1861 | } |
| 1862 | |
| 1863 | static void target_core_alua_drop_lu_gp( |
| 1864 | struct config_group *group, |
| 1865 | struct config_item *item) |
| 1866 | { |
| 1867 | struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item), |
| 1868 | struct t10_alua_lu_gp, lu_gp_group); |
| 1869 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1870 | pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1871 | " Group: core/alua/lu_gps/%s, ID: %hu\n", |
| 1872 | config_item_name(item), lu_gp->lu_gp_id); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 1873 | /* |
| 1874 | * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release() |
| 1875 | * -> target_core_alua_lu_gp_release() |
| 1876 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1877 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1878 | } |
| 1879 | |
| 1880 | static struct configfs_group_operations target_core_alua_lu_gps_group_ops = { |
| 1881 | .make_group = &target_core_alua_create_lu_gp, |
| 1882 | .drop_item = &target_core_alua_drop_lu_gp, |
| 1883 | }; |
| 1884 | |
| 1885 | static struct config_item_type target_core_alua_lu_gps_cit = { |
| 1886 | .ct_item_ops = NULL, |
| 1887 | .ct_group_ops = &target_core_alua_lu_gps_group_ops, |
| 1888 | .ct_owner = THIS_MODULE, |
| 1889 | }; |
| 1890 | |
| 1891 | /* End functions for struct config_item_type target_core_alua_lu_gps_cit */ |
| 1892 | |
| 1893 | /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */ |
| 1894 | |
| 1895 | CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp, t10_alua_tg_pt_gp); |
| 1896 | #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \ |
| 1897 | static struct target_core_alua_tg_pt_gp_attribute \ |
| 1898 | target_core_alua_tg_pt_gp_##_name = \ |
| 1899 | __CONFIGFS_EATTR(_name, _mode, \ |
| 1900 | target_core_alua_tg_pt_gp_show_attr_##_name, \ |
| 1901 | target_core_alua_tg_pt_gp_store_attr_##_name); |
| 1902 | |
| 1903 | #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \ |
| 1904 | static struct target_core_alua_tg_pt_gp_attribute \ |
| 1905 | target_core_alua_tg_pt_gp_##_name = \ |
| 1906 | __CONFIGFS_EATTR_RO(_name, \ |
| 1907 | target_core_alua_tg_pt_gp_show_attr_##_name); |
| 1908 | |
| 1909 | /* |
| 1910 | * alua_access_state |
| 1911 | */ |
| 1912 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_state( |
| 1913 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 1914 | char *page) |
| 1915 | { |
| 1916 | return sprintf(page, "%d\n", |
| 1917 | atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state)); |
| 1918 | } |
| 1919 | |
| 1920 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_state( |
| 1921 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 1922 | const char *page, |
| 1923 | size_t count) |
| 1924 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1925 | struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1926 | unsigned long tmp; |
| 1927 | int new_state, ret; |
| 1928 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1929 | if (!tg_pt_gp->tg_pt_gp_valid_id) { |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 1930 | pr_err("Unable to do implicit ALUA on non valid" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1931 | " tg_pt_gp ID: %hu\n", tg_pt_gp->tg_pt_gp_valid_id); |
| 1932 | return -EINVAL; |
| 1933 | } |
Nicholas Bellinger | f145377 | 2014-06-06 00:52:57 -0700 | [diff] [blame] | 1934 | if (!(dev->dev_flags & DF_CONFIGURED)) { |
| 1935 | pr_err("Unable to set alua_access_state while device is" |
| 1936 | " not configured\n"); |
| 1937 | return -ENODEV; |
| 1938 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1939 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 1940 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1941 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1942 | pr_err("Unable to extract new ALUA access state from" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1943 | " %s\n", page); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 1944 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1945 | } |
| 1946 | new_state = (int)tmp; |
| 1947 | |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 1948 | if (!(tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_IMPLICIT_ALUA)) { |
| 1949 | pr_err("Unable to process implicit configfs ALUA" |
| 1950 | " transition while TPGS_IMPLICIT_ALUA is disabled\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1951 | return -EINVAL; |
| 1952 | } |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 1953 | if (tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_EXPLICIT_ALUA && |
| 1954 | new_state == ALUA_ACCESS_STATE_LBA_DEPENDENT) { |
| 1955 | /* LBA DEPENDENT is only allowed with implicit ALUA */ |
| 1956 | pr_err("Unable to process implicit configfs ALUA transition" |
| 1957 | " while explicit ALUA management is enabled\n"); |
| 1958 | return -EINVAL; |
| 1959 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1960 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1961 | ret = core_alua_do_port_transition(tg_pt_gp, dev, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1962 | NULL, NULL, new_state, 0); |
| 1963 | return (!ret) ? count : -EINVAL; |
| 1964 | } |
| 1965 | |
| 1966 | SE_DEV_ALUA_TG_PT_ATTR(alua_access_state, S_IRUGO | S_IWUSR); |
| 1967 | |
| 1968 | /* |
| 1969 | * alua_access_status |
| 1970 | */ |
| 1971 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_status( |
| 1972 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 1973 | char *page) |
| 1974 | { |
| 1975 | return sprintf(page, "%s\n", |
| 1976 | core_alua_dump_status(tg_pt_gp->tg_pt_gp_alua_access_status)); |
| 1977 | } |
| 1978 | |
| 1979 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_status( |
| 1980 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 1981 | const char *page, |
| 1982 | size_t count) |
| 1983 | { |
| 1984 | unsigned long tmp; |
| 1985 | int new_status, ret; |
| 1986 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1987 | if (!tg_pt_gp->tg_pt_gp_valid_id) { |
| 1988 | pr_err("Unable to do set ALUA access status on non" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1989 | " valid tg_pt_gp ID: %hu\n", |
| 1990 | tg_pt_gp->tg_pt_gp_valid_id); |
| 1991 | return -EINVAL; |
| 1992 | } |
| 1993 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 1994 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1995 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1996 | pr_err("Unable to extract new ALUA access status" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1997 | " from %s\n", page); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 1998 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1999 | } |
| 2000 | new_status = (int)tmp; |
| 2001 | |
| 2002 | if ((new_status != ALUA_STATUS_NONE) && |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2003 | (new_status != ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG) && |
| 2004 | (new_status != ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2005 | pr_err("Illegal ALUA access status: 0x%02x\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2006 | new_status); |
| 2007 | return -EINVAL; |
| 2008 | } |
| 2009 | |
| 2010 | tg_pt_gp->tg_pt_gp_alua_access_status = new_status; |
| 2011 | return count; |
| 2012 | } |
| 2013 | |
| 2014 | SE_DEV_ALUA_TG_PT_ATTR(alua_access_status, S_IRUGO | S_IWUSR); |
| 2015 | |
| 2016 | /* |
| 2017 | * alua_access_type |
| 2018 | */ |
| 2019 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_type( |
| 2020 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2021 | char *page) |
| 2022 | { |
| 2023 | return core_alua_show_access_type(tg_pt_gp, page); |
| 2024 | } |
| 2025 | |
| 2026 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_type( |
| 2027 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2028 | const char *page, |
| 2029 | size_t count) |
| 2030 | { |
| 2031 | return core_alua_store_access_type(tg_pt_gp, page, count); |
| 2032 | } |
| 2033 | |
| 2034 | SE_DEV_ALUA_TG_PT_ATTR(alua_access_type, S_IRUGO | S_IWUSR); |
| 2035 | |
| 2036 | /* |
Hannes Reinecke | 6be526c | 2013-11-19 09:07:50 +0100 | [diff] [blame] | 2037 | * alua_supported_states |
| 2038 | */ |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2039 | |
| 2040 | #define SE_DEV_ALUA_SUPPORT_STATE_SHOW(_name, _var, _bit) \ |
| 2041 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_support_##_name( \ |
| 2042 | struct t10_alua_tg_pt_gp *t, char *p) \ |
| 2043 | { \ |
| 2044 | return sprintf(p, "%d\n", !!(t->_var & _bit)); \ |
Hannes Reinecke | 6be526c | 2013-11-19 09:07:50 +0100 | [diff] [blame] | 2045 | } |
| 2046 | |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2047 | #define SE_DEV_ALUA_SUPPORT_STATE_STORE(_name, _var, _bit) \ |
| 2048 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_support_##_name(\ |
| 2049 | struct t10_alua_tg_pt_gp *t, const char *p, size_t c) \ |
| 2050 | { \ |
| 2051 | unsigned long tmp; \ |
| 2052 | int ret; \ |
| 2053 | \ |
| 2054 | if (!t->tg_pt_gp_valid_id) { \ |
| 2055 | pr_err("Unable to do set ##_name ALUA state on non" \ |
| 2056 | " valid tg_pt_gp ID: %hu\n", \ |
| 2057 | t->tg_pt_gp_valid_id); \ |
| 2058 | return -EINVAL; \ |
| 2059 | } \ |
| 2060 | \ |
| 2061 | ret = kstrtoul(p, 0, &tmp); \ |
| 2062 | if (ret < 0) { \ |
| 2063 | pr_err("Invalid value '%s', must be '0' or '1'\n", p); \ |
| 2064 | return -EINVAL; \ |
| 2065 | } \ |
| 2066 | if (tmp > 1) { \ |
| 2067 | pr_err("Invalid value '%ld', must be '0' or '1'\n", tmp); \ |
| 2068 | return -EINVAL; \ |
| 2069 | } \ |
Sebastian Herbszt | 1f0b030 | 2014-09-01 00:17:53 +0200 | [diff] [blame] | 2070 | if (tmp) \ |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2071 | t->_var |= _bit; \ |
| 2072 | else \ |
| 2073 | t->_var &= ~_bit; \ |
| 2074 | \ |
| 2075 | return c; \ |
Hannes Reinecke | 6be526c | 2013-11-19 09:07:50 +0100 | [diff] [blame] | 2076 | } |
| 2077 | |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2078 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(transitioning, |
| 2079 | tg_pt_gp_alua_supported_states, ALUA_T_SUP); |
| 2080 | SE_DEV_ALUA_SUPPORT_STATE_STORE(transitioning, |
| 2081 | tg_pt_gp_alua_supported_states, ALUA_T_SUP); |
| 2082 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_transitioning, S_IRUGO | S_IWUSR); |
| 2083 | |
| 2084 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(offline, |
| 2085 | tg_pt_gp_alua_supported_states, ALUA_O_SUP); |
| 2086 | SE_DEV_ALUA_SUPPORT_STATE_STORE(offline, |
| 2087 | tg_pt_gp_alua_supported_states, ALUA_O_SUP); |
| 2088 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_offline, S_IRUGO | S_IWUSR); |
| 2089 | |
| 2090 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(lba_dependent, |
| 2091 | tg_pt_gp_alua_supported_states, ALUA_LBD_SUP); |
| 2092 | SE_DEV_ALUA_SUPPORT_STATE_STORE(lba_dependent, |
| 2093 | tg_pt_gp_alua_supported_states, ALUA_LBD_SUP); |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 2094 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_lba_dependent, S_IRUGO); |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2095 | |
| 2096 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(unavailable, |
| 2097 | tg_pt_gp_alua_supported_states, ALUA_U_SUP); |
| 2098 | SE_DEV_ALUA_SUPPORT_STATE_STORE(unavailable, |
| 2099 | tg_pt_gp_alua_supported_states, ALUA_U_SUP); |
| 2100 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_unavailable, S_IRUGO | S_IWUSR); |
| 2101 | |
| 2102 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(standby, |
| 2103 | tg_pt_gp_alua_supported_states, ALUA_S_SUP); |
| 2104 | SE_DEV_ALUA_SUPPORT_STATE_STORE(standby, |
| 2105 | tg_pt_gp_alua_supported_states, ALUA_S_SUP); |
| 2106 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_standby, S_IRUGO | S_IWUSR); |
| 2107 | |
| 2108 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_optimized, |
| 2109 | tg_pt_gp_alua_supported_states, ALUA_AO_SUP); |
| 2110 | SE_DEV_ALUA_SUPPORT_STATE_STORE(active_optimized, |
| 2111 | tg_pt_gp_alua_supported_states, ALUA_AO_SUP); |
| 2112 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_optimized, S_IRUGO | S_IWUSR); |
| 2113 | |
| 2114 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_nonoptimized, |
| 2115 | tg_pt_gp_alua_supported_states, ALUA_AN_SUP); |
| 2116 | SE_DEV_ALUA_SUPPORT_STATE_STORE(active_nonoptimized, |
| 2117 | tg_pt_gp_alua_supported_states, ALUA_AN_SUP); |
| 2118 | 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] | 2119 | |
| 2120 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2121 | * alua_write_metadata |
| 2122 | */ |
| 2123 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_write_metadata( |
| 2124 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2125 | char *page) |
| 2126 | { |
| 2127 | return sprintf(page, "%d\n", tg_pt_gp->tg_pt_gp_write_metadata); |
| 2128 | } |
| 2129 | |
| 2130 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_write_metadata( |
| 2131 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2132 | const char *page, |
| 2133 | size_t count) |
| 2134 | { |
| 2135 | unsigned long tmp; |
| 2136 | int ret; |
| 2137 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2138 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2139 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2140 | pr_err("Unable to extract alua_write_metadata\n"); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2141 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | if ((tmp != 0) && (tmp != 1)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2145 | pr_err("Illegal value for alua_write_metadata:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2146 | " %lu\n", tmp); |
| 2147 | return -EINVAL; |
| 2148 | } |
| 2149 | tg_pt_gp->tg_pt_gp_write_metadata = (int)tmp; |
| 2150 | |
| 2151 | return count; |
| 2152 | } |
| 2153 | |
| 2154 | SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata, S_IRUGO | S_IWUSR); |
| 2155 | |
| 2156 | |
| 2157 | |
| 2158 | /* |
| 2159 | * nonop_delay_msecs |
| 2160 | */ |
| 2161 | static ssize_t target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs( |
| 2162 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2163 | char *page) |
| 2164 | { |
| 2165 | return core_alua_show_nonop_delay_msecs(tg_pt_gp, page); |
| 2166 | |
| 2167 | } |
| 2168 | |
| 2169 | static ssize_t target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs( |
| 2170 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2171 | const char *page, |
| 2172 | size_t count) |
| 2173 | { |
| 2174 | return core_alua_store_nonop_delay_msecs(tg_pt_gp, page, count); |
| 2175 | } |
| 2176 | |
| 2177 | SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs, S_IRUGO | S_IWUSR); |
| 2178 | |
| 2179 | /* |
| 2180 | * trans_delay_msecs |
| 2181 | */ |
| 2182 | static ssize_t target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs( |
| 2183 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2184 | char *page) |
| 2185 | { |
| 2186 | return core_alua_show_trans_delay_msecs(tg_pt_gp, page); |
| 2187 | } |
| 2188 | |
| 2189 | static ssize_t target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs( |
| 2190 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2191 | const char *page, |
| 2192 | size_t count) |
| 2193 | { |
| 2194 | return core_alua_store_trans_delay_msecs(tg_pt_gp, page, count); |
| 2195 | } |
| 2196 | |
| 2197 | SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs, S_IRUGO | S_IWUSR); |
| 2198 | |
| 2199 | /* |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2200 | * implicit_trans_secs |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2201 | */ |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2202 | 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] | 2203 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2204 | char *page) |
| 2205 | { |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2206 | return core_alua_show_implicit_trans_secs(tg_pt_gp, page); |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2207 | } |
| 2208 | |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2209 | 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] | 2210 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2211 | const char *page, |
| 2212 | size_t count) |
| 2213 | { |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2214 | return core_alua_store_implicit_trans_secs(tg_pt_gp, page, count); |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2215 | } |
| 2216 | |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2217 | 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] | 2218 | |
| 2219 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2220 | * preferred |
| 2221 | */ |
| 2222 | |
| 2223 | static ssize_t target_core_alua_tg_pt_gp_show_attr_preferred( |
| 2224 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2225 | char *page) |
| 2226 | { |
| 2227 | return core_alua_show_preferred_bit(tg_pt_gp, page); |
| 2228 | } |
| 2229 | |
| 2230 | static ssize_t target_core_alua_tg_pt_gp_store_attr_preferred( |
| 2231 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2232 | const char *page, |
| 2233 | size_t count) |
| 2234 | { |
| 2235 | return core_alua_store_preferred_bit(tg_pt_gp, page, count); |
| 2236 | } |
| 2237 | |
| 2238 | SE_DEV_ALUA_TG_PT_ATTR(preferred, S_IRUGO | S_IWUSR); |
| 2239 | |
| 2240 | /* |
| 2241 | * tg_pt_gp_id |
| 2242 | */ |
| 2243 | static ssize_t target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id( |
| 2244 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2245 | char *page) |
| 2246 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2247 | if (!tg_pt_gp->tg_pt_gp_valid_id) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2248 | return 0; |
| 2249 | |
| 2250 | return sprintf(page, "%hu\n", tg_pt_gp->tg_pt_gp_id); |
| 2251 | } |
| 2252 | |
| 2253 | static ssize_t target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id( |
| 2254 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2255 | const char *page, |
| 2256 | size_t count) |
| 2257 | { |
| 2258 | struct config_group *alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group; |
| 2259 | unsigned long tg_pt_gp_id; |
| 2260 | int ret; |
| 2261 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2262 | ret = kstrtoul(page, 0, &tg_pt_gp_id); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2263 | if (ret < 0) { |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2264 | pr_err("kstrtoul() returned %d for" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2265 | " tg_pt_gp_id\n", ret); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2266 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2267 | } |
| 2268 | if (tg_pt_gp_id > 0x0000ffff) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2269 | pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2270 | " 0x0000ffff\n", tg_pt_gp_id); |
| 2271 | return -EINVAL; |
| 2272 | } |
| 2273 | |
| 2274 | ret = core_alua_set_tg_pt_gp_id(tg_pt_gp, (u16)tg_pt_gp_id); |
| 2275 | if (ret < 0) |
| 2276 | return -EINVAL; |
| 2277 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2278 | pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: " |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2279 | "core/alua/tg_pt_gps/%s to ID: %hu\n", |
| 2280 | config_item_name(&alua_tg_pt_gp_cg->cg_item), |
| 2281 | tg_pt_gp->tg_pt_gp_id); |
| 2282 | |
| 2283 | return count; |
| 2284 | } |
| 2285 | |
| 2286 | SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id, S_IRUGO | S_IWUSR); |
| 2287 | |
| 2288 | /* |
| 2289 | * members |
| 2290 | */ |
| 2291 | static ssize_t target_core_alua_tg_pt_gp_show_attr_members( |
| 2292 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2293 | char *page) |
| 2294 | { |
| 2295 | struct se_port *port; |
| 2296 | struct se_portal_group *tpg; |
| 2297 | struct se_lun *lun; |
| 2298 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; |
| 2299 | ssize_t len = 0, cur_len; |
| 2300 | unsigned char buf[TG_PT_GROUP_NAME_BUF]; |
| 2301 | |
| 2302 | memset(buf, 0, TG_PT_GROUP_NAME_BUF); |
| 2303 | |
| 2304 | spin_lock(&tg_pt_gp->tg_pt_gp_lock); |
| 2305 | list_for_each_entry(tg_pt_gp_mem, &tg_pt_gp->tg_pt_gp_mem_list, |
| 2306 | tg_pt_gp_mem_list) { |
| 2307 | port = tg_pt_gp_mem->tg_pt; |
| 2308 | tpg = port->sep_tpg; |
| 2309 | lun = port->sep_lun; |
| 2310 | |
| 2311 | 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] | 2312 | "/%s\n", tpg->se_tpg_tfo->get_fabric_name(), |
| 2313 | tpg->se_tpg_tfo->tpg_get_wwn(tpg), |
| 2314 | tpg->se_tpg_tfo->tpg_get_tag(tpg), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2315 | config_item_name(&lun->lun_group.cg_item)); |
| 2316 | cur_len++; /* Extra byte for NULL terminator */ |
| 2317 | |
| 2318 | if ((cur_len + len) > PAGE_SIZE) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2319 | pr_warn("Ran out of lu_gp_show_attr" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2320 | "_members buffer\n"); |
| 2321 | break; |
| 2322 | } |
| 2323 | memcpy(page+len, buf, cur_len); |
| 2324 | len += cur_len; |
| 2325 | } |
| 2326 | spin_unlock(&tg_pt_gp->tg_pt_gp_lock); |
| 2327 | |
| 2328 | return len; |
| 2329 | } |
| 2330 | |
| 2331 | SE_DEV_ALUA_TG_PT_ATTR_RO(members); |
| 2332 | |
| 2333 | CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp, t10_alua_tg_pt_gp, |
| 2334 | tg_pt_gp_group); |
| 2335 | |
| 2336 | static struct configfs_attribute *target_core_alua_tg_pt_gp_attrs[] = { |
| 2337 | &target_core_alua_tg_pt_gp_alua_access_state.attr, |
| 2338 | &target_core_alua_tg_pt_gp_alua_access_status.attr, |
| 2339 | &target_core_alua_tg_pt_gp_alua_access_type.attr, |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2340 | &target_core_alua_tg_pt_gp_alua_support_transitioning.attr, |
| 2341 | &target_core_alua_tg_pt_gp_alua_support_offline.attr, |
| 2342 | &target_core_alua_tg_pt_gp_alua_support_lba_dependent.attr, |
| 2343 | &target_core_alua_tg_pt_gp_alua_support_unavailable.attr, |
| 2344 | &target_core_alua_tg_pt_gp_alua_support_standby.attr, |
| 2345 | &target_core_alua_tg_pt_gp_alua_support_active_nonoptimized.attr, |
| 2346 | &target_core_alua_tg_pt_gp_alua_support_active_optimized.attr, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2347 | &target_core_alua_tg_pt_gp_alua_write_metadata.attr, |
| 2348 | &target_core_alua_tg_pt_gp_nonop_delay_msecs.attr, |
| 2349 | &target_core_alua_tg_pt_gp_trans_delay_msecs.attr, |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2350 | &target_core_alua_tg_pt_gp_implicit_trans_secs.attr, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2351 | &target_core_alua_tg_pt_gp_preferred.attr, |
| 2352 | &target_core_alua_tg_pt_gp_tg_pt_gp_id.attr, |
| 2353 | &target_core_alua_tg_pt_gp_members.attr, |
| 2354 | NULL, |
| 2355 | }; |
| 2356 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2357 | static void target_core_alua_tg_pt_gp_release(struct config_item *item) |
| 2358 | { |
| 2359 | struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item), |
| 2360 | struct t10_alua_tg_pt_gp, tg_pt_gp_group); |
| 2361 | |
| 2362 | core_alua_free_tg_pt_gp(tg_pt_gp); |
| 2363 | } |
| 2364 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2365 | static struct configfs_item_operations target_core_alua_tg_pt_gp_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2366 | .release = target_core_alua_tg_pt_gp_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2367 | .show_attribute = target_core_alua_tg_pt_gp_attr_show, |
| 2368 | .store_attribute = target_core_alua_tg_pt_gp_attr_store, |
| 2369 | }; |
| 2370 | |
| 2371 | static struct config_item_type target_core_alua_tg_pt_gp_cit = { |
| 2372 | .ct_item_ops = &target_core_alua_tg_pt_gp_ops, |
| 2373 | .ct_attrs = target_core_alua_tg_pt_gp_attrs, |
| 2374 | .ct_owner = THIS_MODULE, |
| 2375 | }; |
| 2376 | |
| 2377 | /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */ |
| 2378 | |
Nicholas Bellinger | 72aca57 | 2014-11-27 15:06:23 -0800 | [diff] [blame] | 2379 | /* 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] | 2380 | |
| 2381 | static struct config_group *target_core_alua_create_tg_pt_gp( |
| 2382 | struct config_group *group, |
| 2383 | const char *name) |
| 2384 | { |
| 2385 | struct t10_alua *alua = container_of(group, struct t10_alua, |
| 2386 | alua_tg_pt_gps_group); |
| 2387 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2388 | struct config_group *alua_tg_pt_gp_cg = NULL; |
| 2389 | struct config_item *alua_tg_pt_gp_ci = NULL; |
| 2390 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2391 | 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] | 2392 | if (!tg_pt_gp) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2393 | return NULL; |
| 2394 | |
| 2395 | alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group; |
| 2396 | alua_tg_pt_gp_ci = &alua_tg_pt_gp_cg->cg_item; |
| 2397 | |
| 2398 | config_group_init_type_name(alua_tg_pt_gp_cg, name, |
| 2399 | &target_core_alua_tg_pt_gp_cit); |
| 2400 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2401 | pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2402 | " Group: alua/tg_pt_gps/%s\n", |
| 2403 | config_item_name(alua_tg_pt_gp_ci)); |
| 2404 | |
| 2405 | return alua_tg_pt_gp_cg; |
| 2406 | } |
| 2407 | |
| 2408 | static void target_core_alua_drop_tg_pt_gp( |
| 2409 | struct config_group *group, |
| 2410 | struct config_item *item) |
| 2411 | { |
| 2412 | struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item), |
| 2413 | struct t10_alua_tg_pt_gp, tg_pt_gp_group); |
| 2414 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2415 | pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2416 | " Group: alua/tg_pt_gps/%s, ID: %hu\n", |
| 2417 | config_item_name(item), tg_pt_gp->tg_pt_gp_id); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2418 | /* |
| 2419 | * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release() |
| 2420 | * -> target_core_alua_tg_pt_gp_release(). |
| 2421 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2422 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = { |
| 2426 | .make_group = &target_core_alua_create_tg_pt_gp, |
| 2427 | .drop_item = &target_core_alua_drop_tg_pt_gp, |
| 2428 | }; |
| 2429 | |
Nicholas Bellinger | 72aca57 | 2014-11-27 15:06:23 -0800 | [diff] [blame] | 2430 | 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] | 2431 | |
Nicholas Bellinger | 72aca57 | 2014-11-27 15:06:23 -0800 | [diff] [blame] | 2432 | /* 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] | 2433 | |
| 2434 | /* Start functions for struct config_item_type target_core_alua_cit */ |
| 2435 | |
| 2436 | /* |
| 2437 | * target_core_alua_cit is a ConfigFS group that lives under |
| 2438 | * /sys/kernel/config/target/core/alua. There are default groups |
| 2439 | * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to |
| 2440 | * target_core_alua_cit in target_core_init_configfs() below. |
| 2441 | */ |
| 2442 | static struct config_item_type target_core_alua_cit = { |
| 2443 | .ct_item_ops = NULL, |
| 2444 | .ct_attrs = NULL, |
| 2445 | .ct_owner = THIS_MODULE, |
| 2446 | }; |
| 2447 | |
| 2448 | /* End functions for struct config_item_type target_core_alua_cit */ |
| 2449 | |
Nicholas Bellinger | d23ab57 | 2014-11-27 15:09:32 -0800 | [diff] [blame] | 2450 | /* Start functions for struct config_item_type tb_dev_stat_cit */ |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2451 | |
| 2452 | static struct config_group *target_core_stat_mkdir( |
| 2453 | struct config_group *group, |
| 2454 | const char *name) |
| 2455 | { |
| 2456 | return ERR_PTR(-ENOSYS); |
| 2457 | } |
| 2458 | |
| 2459 | static void target_core_stat_rmdir( |
| 2460 | struct config_group *group, |
| 2461 | struct config_item *item) |
| 2462 | { |
| 2463 | return; |
| 2464 | } |
| 2465 | |
| 2466 | static struct configfs_group_operations target_core_stat_group_ops = { |
| 2467 | .make_group = &target_core_stat_mkdir, |
| 2468 | .drop_item = &target_core_stat_rmdir, |
| 2469 | }; |
| 2470 | |
Nicholas Bellinger | d23ab57 | 2014-11-27 15:09:32 -0800 | [diff] [blame] | 2471 | TB_CIT_SETUP(dev_stat, NULL, &target_core_stat_group_ops, NULL); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2472 | |
Nicholas Bellinger | d23ab57 | 2014-11-27 15:09:32 -0800 | [diff] [blame] | 2473 | /* End functions for struct config_item_type tb_dev_stat_cit */ |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2474 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2475 | /* Start functions for struct config_item_type target_core_hba_cit */ |
| 2476 | |
| 2477 | static struct config_group *target_core_make_subdev( |
| 2478 | struct config_group *group, |
| 2479 | const char *name) |
| 2480 | { |
| 2481 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2482 | struct se_subsystem_api *t; |
| 2483 | struct config_item *hba_ci = &group->cg_item; |
| 2484 | struct se_hba *hba = item_to_hba(hba_ci); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2485 | struct se_device *dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2486 | struct config_group *dev_cg = NULL, *tg_pt_gp_cg = NULL; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2487 | struct config_group *dev_stat_grp = NULL; |
| 2488 | int errno = -ENOMEM, ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2489 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2490 | ret = mutex_lock_interruptible(&hba->hba_access_mutex); |
| 2491 | if (ret) |
| 2492 | return ERR_PTR(ret); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2493 | /* |
| 2494 | * Locate the struct se_subsystem_api from parent's struct se_hba. |
| 2495 | */ |
| 2496 | t = hba->transport; |
| 2497 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2498 | dev = target_alloc_device(hba, name); |
| 2499 | if (!dev) |
| 2500 | goto out_unlock; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2501 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2502 | dev_cg = &dev->dev_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2503 | |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 2504 | dev_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2505 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2506 | if (!dev_cg->default_groups) |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2507 | goto out_free_device; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2508 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 2509 | 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] | 2510 | config_group_init_type_name(&dev->dev_attrib.da_group, "attrib", |
Nicholas Bellinger | f79a897 | 2014-11-27 14:51:14 -0800 | [diff] [blame] | 2511 | &t->tb_cits.tb_dev_attrib_cit); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2512 | config_group_init_type_name(&dev->dev_pr_group, "pr", |
Nicholas Bellinger | 91e2e39 | 2014-11-27 14:57:01 -0800 | [diff] [blame] | 2513 | &t->tb_cits.tb_dev_pr_cit); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2514 | config_group_init_type_name(&dev->t10_wwn.t10_wwn_group, "wwn", |
Nicholas Bellinger | f8d389c | 2014-11-27 15:01:12 -0800 | [diff] [blame] | 2515 | &t->tb_cits.tb_dev_wwn_cit); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2516 | 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] | 2517 | "alua", &t->tb_cits.tb_dev_alua_tg_pt_gps_cit); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2518 | config_group_init_type_name(&dev->dev_stat_grps.stat_group, |
Nicholas Bellinger | d23ab57 | 2014-11-27 15:09:32 -0800 | [diff] [blame] | 2519 | "statistics", &t->tb_cits.tb_dev_stat_cit); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2520 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2521 | dev_cg->default_groups[0] = &dev->dev_attrib.da_group; |
| 2522 | dev_cg->default_groups[1] = &dev->dev_pr_group; |
| 2523 | dev_cg->default_groups[2] = &dev->t10_wwn.t10_wwn_group; |
| 2524 | dev_cg->default_groups[3] = &dev->t10_alua.alua_tg_pt_gps_group; |
| 2525 | dev_cg->default_groups[4] = &dev->dev_stat_grps.stat_group; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2526 | dev_cg->default_groups[5] = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2527 | /* |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2528 | * Add core/$HBA/$DEV/alua/default_tg_pt_gp |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2529 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2530 | 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] | 2531 | if (!tg_pt_gp) |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2532 | goto out_free_dev_cg_default_groups; |
| 2533 | dev->t10_alua.default_tg_pt_gp = tg_pt_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2534 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2535 | 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] | 2536 | tg_pt_gp_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2537 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2538 | if (!tg_pt_gp_cg->default_groups) { |
| 2539 | pr_err("Unable to allocate tg_pt_gp_cg->" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2540 | "default_groups\n"); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2541 | goto out_free_tg_pt_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | config_group_init_type_name(&tg_pt_gp->tg_pt_gp_group, |
| 2545 | "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit); |
| 2546 | tg_pt_gp_cg->default_groups[0] = &tg_pt_gp->tg_pt_gp_group; |
| 2547 | tg_pt_gp_cg->default_groups[1] = NULL; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2548 | /* |
| 2549 | * Add core/$HBA/$DEV/statistics/ default groups |
| 2550 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2551 | dev_stat_grp = &dev->dev_stat_grps.stat_group; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 2552 | dev_stat_grp->default_groups = kmalloc(sizeof(struct config_group *) * 4, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2553 | GFP_KERNEL); |
| 2554 | if (!dev_stat_grp->default_groups) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2555 | pr_err("Unable to allocate dev_stat_grp->default_groups\n"); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2556 | goto out_free_tg_pt_gp_cg_default_groups; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2557 | } |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2558 | target_stat_setup_dev_default_groups(dev); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2559 | |
| 2560 | mutex_unlock(&hba->hba_access_mutex); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2561 | return dev_cg; |
| 2562 | |
| 2563 | out_free_tg_pt_gp_cg_default_groups: |
| 2564 | kfree(tg_pt_gp_cg->default_groups); |
| 2565 | out_free_tg_pt_gp: |
| 2566 | core_alua_free_tg_pt_gp(tg_pt_gp); |
| 2567 | out_free_dev_cg_default_groups: |
| 2568 | kfree(dev_cg->default_groups); |
| 2569 | out_free_device: |
| 2570 | target_free_device(dev); |
| 2571 | out_unlock: |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2572 | mutex_unlock(&hba->hba_access_mutex); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2573 | return ERR_PTR(errno); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | static void target_core_drop_subdev( |
| 2577 | struct config_group *group, |
| 2578 | struct config_item *item) |
| 2579 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2580 | struct config_group *dev_cg = to_config_group(item); |
| 2581 | struct se_device *dev = |
| 2582 | container_of(dev_cg, struct se_device, dev_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2583 | struct se_hba *hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2584 | struct config_item *df_item; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2585 | struct config_group *tg_pt_gp_cg, *dev_stat_grp; |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2586 | int i; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2587 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2588 | hba = item_to_hba(&dev->se_hba->hba_group.cg_item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2589 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2590 | mutex_lock(&hba->hba_access_mutex); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2591 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2592 | dev_stat_grp = &dev->dev_stat_grps.stat_group; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2593 | for (i = 0; dev_stat_grp->default_groups[i]; i++) { |
| 2594 | df_item = &dev_stat_grp->default_groups[i]->cg_item; |
| 2595 | dev_stat_grp->default_groups[i] = NULL; |
| 2596 | config_item_put(df_item); |
| 2597 | } |
| 2598 | kfree(dev_stat_grp->default_groups); |
| 2599 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2600 | tg_pt_gp_cg = &dev->t10_alua.alua_tg_pt_gps_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2601 | for (i = 0; tg_pt_gp_cg->default_groups[i]; i++) { |
| 2602 | df_item = &tg_pt_gp_cg->default_groups[i]->cg_item; |
| 2603 | tg_pt_gp_cg->default_groups[i] = NULL; |
| 2604 | config_item_put(df_item); |
| 2605 | } |
| 2606 | kfree(tg_pt_gp_cg->default_groups); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2607 | /* |
| 2608 | * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp |
| 2609 | * directly from target_core_alua_tg_pt_gp_release(). |
| 2610 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2611 | dev->t10_alua.default_tg_pt_gp = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2612 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2613 | for (i = 0; dev_cg->default_groups[i]; i++) { |
| 2614 | df_item = &dev_cg->default_groups[i]->cg_item; |
| 2615 | dev_cg->default_groups[i] = NULL; |
| 2616 | config_item_put(df_item); |
| 2617 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2618 | /* |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2619 | * se_dev is released from target_core_dev_item_ops->release() |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2620 | */ |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2621 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2622 | mutex_unlock(&hba->hba_access_mutex); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2623 | } |
| 2624 | |
| 2625 | static struct configfs_group_operations target_core_hba_group_ops = { |
| 2626 | .make_group = target_core_make_subdev, |
| 2627 | .drop_item = target_core_drop_subdev, |
| 2628 | }; |
| 2629 | |
| 2630 | CONFIGFS_EATTR_STRUCT(target_core_hba, se_hba); |
| 2631 | #define SE_HBA_ATTR(_name, _mode) \ |
| 2632 | static struct target_core_hba_attribute \ |
| 2633 | target_core_hba_##_name = \ |
| 2634 | __CONFIGFS_EATTR(_name, _mode, \ |
| 2635 | target_core_hba_show_attr_##_name, \ |
| 2636 | target_core_hba_store_attr_##_name); |
| 2637 | |
| 2638 | #define SE_HBA_ATTR_RO(_name) \ |
| 2639 | static struct target_core_hba_attribute \ |
| 2640 | target_core_hba_##_name = \ |
| 2641 | __CONFIGFS_EATTR_RO(_name, \ |
| 2642 | target_core_hba_show_attr_##_name); |
| 2643 | |
| 2644 | static ssize_t target_core_hba_show_attr_hba_info( |
| 2645 | struct se_hba *hba, |
| 2646 | char *page) |
| 2647 | { |
| 2648 | return sprintf(page, "HBA Index: %d plugin: %s version: %s\n", |
| 2649 | hba->hba_id, hba->transport->name, |
| 2650 | TARGET_CORE_CONFIGFS_VERSION); |
| 2651 | } |
| 2652 | |
| 2653 | SE_HBA_ATTR_RO(hba_info); |
| 2654 | |
| 2655 | static ssize_t target_core_hba_show_attr_hba_mode(struct se_hba *hba, |
| 2656 | char *page) |
| 2657 | { |
| 2658 | int hba_mode = 0; |
| 2659 | |
| 2660 | if (hba->hba_flags & HBA_FLAGS_PSCSI_MODE) |
| 2661 | hba_mode = 1; |
| 2662 | |
| 2663 | return sprintf(page, "%d\n", hba_mode); |
| 2664 | } |
| 2665 | |
| 2666 | static ssize_t target_core_hba_store_attr_hba_mode(struct se_hba *hba, |
| 2667 | const char *page, size_t count) |
| 2668 | { |
| 2669 | struct se_subsystem_api *transport = hba->transport; |
| 2670 | unsigned long mode_flag; |
| 2671 | int ret; |
| 2672 | |
| 2673 | if (transport->pmode_enable_hba == NULL) |
| 2674 | return -EINVAL; |
| 2675 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2676 | ret = kstrtoul(page, 0, &mode_flag); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2677 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2678 | pr_err("Unable to extract hba mode flag: %d\n", ret); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2679 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2680 | } |
| 2681 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2682 | if (hba->dev_count) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2683 | pr_err("Unable to set hba_mode with active devices\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2684 | return -EINVAL; |
| 2685 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2686 | |
| 2687 | ret = transport->pmode_enable_hba(hba, mode_flag); |
| 2688 | if (ret < 0) |
| 2689 | return -EINVAL; |
| 2690 | if (ret > 0) |
| 2691 | hba->hba_flags |= HBA_FLAGS_PSCSI_MODE; |
| 2692 | else if (ret == 0) |
| 2693 | hba->hba_flags &= ~HBA_FLAGS_PSCSI_MODE; |
| 2694 | |
| 2695 | return count; |
| 2696 | } |
| 2697 | |
| 2698 | SE_HBA_ATTR(hba_mode, S_IRUGO | S_IWUSR); |
| 2699 | |
| 2700 | CONFIGFS_EATTR_OPS(target_core_hba, se_hba, hba_group); |
| 2701 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2702 | static void target_core_hba_release(struct config_item *item) |
| 2703 | { |
| 2704 | struct se_hba *hba = container_of(to_config_group(item), |
| 2705 | struct se_hba, hba_group); |
| 2706 | core_delete_hba(hba); |
| 2707 | } |
| 2708 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2709 | static struct configfs_attribute *target_core_hba_attrs[] = { |
| 2710 | &target_core_hba_hba_info.attr, |
| 2711 | &target_core_hba_hba_mode.attr, |
| 2712 | NULL, |
| 2713 | }; |
| 2714 | |
| 2715 | static struct configfs_item_operations target_core_hba_item_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2716 | .release = target_core_hba_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2717 | .show_attribute = target_core_hba_attr_show, |
| 2718 | .store_attribute = target_core_hba_attr_store, |
| 2719 | }; |
| 2720 | |
| 2721 | static struct config_item_type target_core_hba_cit = { |
| 2722 | .ct_item_ops = &target_core_hba_item_ops, |
| 2723 | .ct_group_ops = &target_core_hba_group_ops, |
| 2724 | .ct_attrs = target_core_hba_attrs, |
| 2725 | .ct_owner = THIS_MODULE, |
| 2726 | }; |
| 2727 | |
| 2728 | static struct config_group *target_core_call_addhbatotarget( |
| 2729 | struct config_group *group, |
| 2730 | const char *name) |
| 2731 | { |
| 2732 | char *se_plugin_str, *str, *str2; |
| 2733 | struct se_hba *hba; |
| 2734 | char buf[TARGET_CORE_NAME_MAX_LEN]; |
| 2735 | unsigned long plugin_dep_id = 0; |
| 2736 | int ret; |
| 2737 | |
| 2738 | memset(buf, 0, TARGET_CORE_NAME_MAX_LEN); |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 2739 | if (strlen(name) >= TARGET_CORE_NAME_MAX_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2740 | pr_err("Passed *name strlen(): %d exceeds" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2741 | " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name), |
| 2742 | TARGET_CORE_NAME_MAX_LEN); |
| 2743 | return ERR_PTR(-ENAMETOOLONG); |
| 2744 | } |
| 2745 | snprintf(buf, TARGET_CORE_NAME_MAX_LEN, "%s", name); |
| 2746 | |
| 2747 | str = strstr(buf, "_"); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2748 | if (!str) { |
| 2749 | pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2750 | return ERR_PTR(-EINVAL); |
| 2751 | } |
| 2752 | se_plugin_str = buf; |
| 2753 | /* |
| 2754 | * Special case for subsystem plugins that have "_" in their names. |
| 2755 | * Namely rd_direct and rd_mcp.. |
| 2756 | */ |
| 2757 | str2 = strstr(str+1, "_"); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2758 | if (str2) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2759 | *str2 = '\0'; /* Terminate for *se_plugin_str */ |
| 2760 | str2++; /* Skip to start of plugin dependent ID */ |
| 2761 | str = str2; |
| 2762 | } else { |
| 2763 | *str = '\0'; /* Terminate for *se_plugin_str */ |
| 2764 | str++; /* Skip to start of plugin dependent ID */ |
| 2765 | } |
| 2766 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2767 | ret = kstrtoul(str, 0, &plugin_dep_id); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2768 | if (ret < 0) { |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2769 | pr_err("kstrtoul() returned %d for" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2770 | " plugin_dep_id\n", ret); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2771 | return ERR_PTR(ret); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2772 | } |
| 2773 | /* |
| 2774 | * Load up TCM subsystem plugins if they have not already been loaded. |
| 2775 | */ |
Nicholas Bellinger | dbc5623 | 2011-10-22 01:03:54 -0700 | [diff] [blame] | 2776 | transport_subsystem_check_init(); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2777 | |
| 2778 | hba = core_alloc_hba(se_plugin_str, plugin_dep_id, 0); |
| 2779 | if (IS_ERR(hba)) |
| 2780 | return ERR_CAST(hba); |
| 2781 | |
| 2782 | config_group_init_type_name(&hba->hba_group, name, |
| 2783 | &target_core_hba_cit); |
| 2784 | |
| 2785 | return &hba->hba_group; |
| 2786 | } |
| 2787 | |
| 2788 | static void target_core_call_delhbafromtarget( |
| 2789 | struct config_group *group, |
| 2790 | struct config_item *item) |
| 2791 | { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2792 | /* |
| 2793 | * core_delete_hba() is called from target_core_hba_item_ops->release() |
| 2794 | * -> target_core_hba_release() |
| 2795 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2796 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2797 | } |
| 2798 | |
| 2799 | static struct configfs_group_operations target_core_group_ops = { |
| 2800 | .make_group = target_core_call_addhbatotarget, |
| 2801 | .drop_item = target_core_call_delhbafromtarget, |
| 2802 | }; |
| 2803 | |
| 2804 | static struct config_item_type target_core_cit = { |
| 2805 | .ct_item_ops = NULL, |
| 2806 | .ct_group_ops = &target_core_group_ops, |
| 2807 | .ct_attrs = NULL, |
| 2808 | .ct_owner = THIS_MODULE, |
| 2809 | }; |
| 2810 | |
| 2811 | /* Stop functions for struct config_item_type target_core_hba_cit */ |
| 2812 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 2813 | void target_core_setup_sub_cits(struct se_subsystem_api *sa) |
| 2814 | { |
| 2815 | target_core_setup_dev_cit(sa); |
Nicholas Bellinger | f79a897 | 2014-11-27 14:51:14 -0800 | [diff] [blame] | 2816 | target_core_setup_dev_attrib_cit(sa); |
Nicholas Bellinger | 91e2e39 | 2014-11-27 14:57:01 -0800 | [diff] [blame] | 2817 | target_core_setup_dev_pr_cit(sa); |
Nicholas Bellinger | f8d389c | 2014-11-27 15:01:12 -0800 | [diff] [blame] | 2818 | target_core_setup_dev_wwn_cit(sa); |
Nicholas Bellinger | 72aca57 | 2014-11-27 15:06:23 -0800 | [diff] [blame] | 2819 | target_core_setup_dev_alua_tg_pt_gps_cit(sa); |
Nicholas Bellinger | d23ab57 | 2014-11-27 15:09:32 -0800 | [diff] [blame] | 2820 | target_core_setup_dev_stat_cit(sa); |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 2821 | } |
| 2822 | EXPORT_SYMBOL(target_core_setup_sub_cits); |
| 2823 | |
Axel Lin | 54550fa | 2011-03-14 04:06:09 -0700 | [diff] [blame] | 2824 | static int __init target_core_init_configfs(void) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2825 | { |
| 2826 | struct config_group *target_cg, *hba_cg = NULL, *alua_cg = NULL; |
| 2827 | struct config_group *lu_gp_cg = NULL; |
Christoph Hellwig | d588cf8 | 2015-05-03 08:50:52 +0200 | [diff] [blame] | 2828 | struct configfs_subsystem *subsys = &target_core_fabrics; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2829 | struct t10_alua_lu_gp *lu_gp; |
| 2830 | int ret; |
| 2831 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2832 | pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2833 | " Engine: %s on %s/%s on "UTS_RELEASE"\n", |
| 2834 | TARGET_CORE_VERSION, utsname()->sysname, utsname()->machine); |
| 2835 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2836 | config_group_init(&subsys->su_group); |
| 2837 | mutex_init(&subsys->su_mutex); |
| 2838 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2839 | ret = init_se_kmem_caches(); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2840 | if (ret < 0) |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2841 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2842 | /* |
| 2843 | * Create $CONFIGFS/target/core default group for HBA <-> Storage Object |
| 2844 | * and ALUA Logical Unit Group and Target Port Group infrastructure. |
| 2845 | */ |
| 2846 | target_cg = &subsys->su_group; |
Andy Grover | ab6dae8 | 2013-12-09 14:27:36 -0800 | [diff] [blame] | 2847 | target_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2848 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2849 | if (!target_cg->default_groups) { |
| 2850 | pr_err("Unable to allocate target_cg->default_groups\n"); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 2851 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2852 | goto out_global; |
| 2853 | } |
| 2854 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2855 | config_group_init_type_name(&target_core_hbagroup, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2856 | "core", &target_core_cit); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2857 | target_cg->default_groups[0] = &target_core_hbagroup; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2858 | target_cg->default_groups[1] = NULL; |
| 2859 | /* |
| 2860 | * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/ |
| 2861 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2862 | hba_cg = &target_core_hbagroup; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 2863 | hba_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2864 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2865 | if (!hba_cg->default_groups) { |
| 2866 | pr_err("Unable to allocate hba_cg->default_groups\n"); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 2867 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2868 | goto out_global; |
| 2869 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2870 | config_group_init_type_name(&alua_group, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2871 | "alua", &target_core_alua_cit); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2872 | hba_cg->default_groups[0] = &alua_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2873 | hba_cg->default_groups[1] = NULL; |
| 2874 | /* |
| 2875 | * Add ALUA Logical Unit Group and Target Port Group ConfigFS |
| 2876 | * groups under /sys/kernel/config/target/core/alua/ |
| 2877 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2878 | alua_cg = &alua_group; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 2879 | alua_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2880 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2881 | if (!alua_cg->default_groups) { |
| 2882 | pr_err("Unable to allocate alua_cg->default_groups\n"); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 2883 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2884 | goto out_global; |
| 2885 | } |
| 2886 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2887 | config_group_init_type_name(&alua_lu_gps_group, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2888 | "lu_gps", &target_core_alua_lu_gps_cit); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2889 | alua_cg->default_groups[0] = &alua_lu_gps_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2890 | alua_cg->default_groups[1] = NULL; |
| 2891 | /* |
| 2892 | * Add core/alua/lu_gps/default_lu_gp |
| 2893 | */ |
| 2894 | lu_gp = core_alua_allocate_lu_gp("default_lu_gp", 1); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 2895 | if (IS_ERR(lu_gp)) { |
| 2896 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2897 | goto out_global; |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 2898 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2899 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2900 | lu_gp_cg = &alua_lu_gps_group; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 2901 | lu_gp_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2902 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2903 | if (!lu_gp_cg->default_groups) { |
| 2904 | pr_err("Unable to allocate lu_gp_cg->default_groups\n"); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 2905 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2906 | goto out_global; |
| 2907 | } |
| 2908 | |
| 2909 | config_group_init_type_name(&lu_gp->lu_gp_group, "default_lu_gp", |
| 2910 | &target_core_alua_lu_gp_cit); |
| 2911 | lu_gp_cg->default_groups[0] = &lu_gp->lu_gp_group; |
| 2912 | lu_gp_cg->default_groups[1] = NULL; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2913 | default_lu_gp = lu_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2914 | /* |
| 2915 | * Register the target_core_mod subsystem with configfs. |
| 2916 | */ |
| 2917 | ret = configfs_register_subsystem(subsys); |
| 2918 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2919 | pr_err("Error %d while registering subsystem %s\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2920 | ret, subsys->su_group.cg_item.ci_namebuf); |
| 2921 | goto out_global; |
| 2922 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2923 | pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2924 | " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION" on %s/%s" |
| 2925 | " on "UTS_RELEASE"\n", utsname()->sysname, utsname()->machine); |
| 2926 | /* |
| 2927 | * Register built-in RAMDISK subsystem logic for virtual LUN 0 |
| 2928 | */ |
| 2929 | ret = rd_module_init(); |
| 2930 | if (ret < 0) |
| 2931 | goto out; |
| 2932 | |
Roland Dreier | 0d0f9df | 2012-10-31 09:16:44 -0700 | [diff] [blame] | 2933 | ret = core_dev_setup_virtual_lun0(); |
| 2934 | if (ret < 0) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2935 | goto out; |
| 2936 | |
Nicholas Bellinger | f99715a | 2013-08-22 12:48:53 -0700 | [diff] [blame] | 2937 | ret = target_xcopy_setup_pt(); |
| 2938 | if (ret < 0) |
| 2939 | goto out; |
| 2940 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2941 | return 0; |
| 2942 | |
| 2943 | out: |
| 2944 | configfs_unregister_subsystem(subsys); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2945 | core_dev_release_virtual_lun0(); |
| 2946 | rd_module_exit(); |
| 2947 | out_global: |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2948 | if (default_lu_gp) { |
| 2949 | core_alua_free_lu_gp(default_lu_gp); |
| 2950 | default_lu_gp = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2951 | } |
| 2952 | if (lu_gp_cg) |
| 2953 | kfree(lu_gp_cg->default_groups); |
| 2954 | if (alua_cg) |
| 2955 | kfree(alua_cg->default_groups); |
| 2956 | if (hba_cg) |
| 2957 | kfree(hba_cg->default_groups); |
| 2958 | kfree(target_cg->default_groups); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2959 | release_se_kmem_caches(); |
| 2960 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2961 | } |
| 2962 | |
Axel Lin | 54550fa | 2011-03-14 04:06:09 -0700 | [diff] [blame] | 2963 | static void __exit target_core_exit_configfs(void) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2964 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2965 | struct config_group *hba_cg, *alua_cg, *lu_gp_cg; |
| 2966 | struct config_item *item; |
| 2967 | int i; |
| 2968 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2969 | lu_gp_cg = &alua_lu_gps_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2970 | for (i = 0; lu_gp_cg->default_groups[i]; i++) { |
| 2971 | item = &lu_gp_cg->default_groups[i]->cg_item; |
| 2972 | lu_gp_cg->default_groups[i] = NULL; |
| 2973 | config_item_put(item); |
| 2974 | } |
| 2975 | kfree(lu_gp_cg->default_groups); |
Nicholas Bellinger | 7c2bf6e9 | 2011-02-09 15:34:53 -0800 | [diff] [blame] | 2976 | lu_gp_cg->default_groups = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2977 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2978 | alua_cg = &alua_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2979 | for (i = 0; alua_cg->default_groups[i]; i++) { |
| 2980 | item = &alua_cg->default_groups[i]->cg_item; |
| 2981 | alua_cg->default_groups[i] = NULL; |
| 2982 | config_item_put(item); |
| 2983 | } |
| 2984 | kfree(alua_cg->default_groups); |
Nicholas Bellinger | 7c2bf6e9 | 2011-02-09 15:34:53 -0800 | [diff] [blame] | 2985 | alua_cg->default_groups = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2986 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2987 | hba_cg = &target_core_hbagroup; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2988 | for (i = 0; hba_cg->default_groups[i]; i++) { |
| 2989 | item = &hba_cg->default_groups[i]->cg_item; |
| 2990 | hba_cg->default_groups[i] = NULL; |
| 2991 | config_item_put(item); |
| 2992 | } |
| 2993 | kfree(hba_cg->default_groups); |
Nicholas Bellinger | 7c2bf6e9 | 2011-02-09 15:34:53 -0800 | [diff] [blame] | 2994 | hba_cg->default_groups = NULL; |
| 2995 | /* |
| 2996 | * We expect subsys->su_group.default_groups to be released |
| 2997 | * by configfs subsystem provider logic.. |
| 2998 | */ |
Christoph Hellwig | d588cf8 | 2015-05-03 08:50:52 +0200 | [diff] [blame] | 2999 | configfs_unregister_subsystem(&target_core_fabrics); |
| 3000 | kfree(target_core_fabrics.su_group.default_groups); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3001 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3002 | core_alua_free_lu_gp(default_lu_gp); |
| 3003 | default_lu_gp = NULL; |
Nicholas Bellinger | 7c2bf6e9 | 2011-02-09 15:34:53 -0800 | [diff] [blame] | 3004 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3005 | pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3006 | " Infrastructure\n"); |
| 3007 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3008 | core_dev_release_virtual_lun0(); |
| 3009 | rd_module_exit(); |
Nicholas Bellinger | f99715a | 2013-08-22 12:48:53 -0700 | [diff] [blame] | 3010 | target_xcopy_release_pt(); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3011 | release_se_kmem_caches(); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS"); |
| 3015 | MODULE_AUTHOR("nab@Linux-iSCSI.org"); |
| 3016 | MODULE_LICENSE("GPL"); |
| 3017 | |
| 3018 | module_init(target_core_init_configfs); |
| 3019 | module_exit(target_core_exit_configfs); |