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