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 | 3effdb9 | 2015-05-10 18:14:58 +0200 | [diff] [blame] | 474 | #define DEF_TB_DEV_ATTRIB_SHOW(_name) \ |
| 475 | static ssize_t show_##_name(struct se_dev_attrib *da, char *page) \ |
Christoph Hellwig | 5873c4d | 2015-05-10 18:14:57 +0200 | [diff] [blame] | 476 | { \ |
Christoph Hellwig | 3effdb9 | 2015-05-10 18:14:58 +0200 | [diff] [blame] | 477 | return snprintf(page, PAGE_SIZE, "%u\n", da->_name); \ |
Christoph Hellwig | 5873c4d | 2015-05-10 18:14:57 +0200 | [diff] [blame] | 478 | } |
| 479 | |
Christoph Hellwig | 3effdb9 | 2015-05-10 18:14:58 +0200 | [diff] [blame] | 480 | DEF_TB_DEV_ATTRIB_SHOW(emulate_model_alias); |
| 481 | DEF_TB_DEV_ATTRIB_SHOW(emulate_dpo); |
| 482 | DEF_TB_DEV_ATTRIB_SHOW(emulate_fua_write); |
| 483 | DEF_TB_DEV_ATTRIB_SHOW(emulate_fua_read); |
| 484 | DEF_TB_DEV_ATTRIB_SHOW(emulate_write_cache); |
| 485 | DEF_TB_DEV_ATTRIB_SHOW(emulate_ua_intlck_ctrl); |
| 486 | DEF_TB_DEV_ATTRIB_SHOW(emulate_tas); |
| 487 | DEF_TB_DEV_ATTRIB_SHOW(emulate_tpu); |
| 488 | DEF_TB_DEV_ATTRIB_SHOW(emulate_tpws); |
| 489 | DEF_TB_DEV_ATTRIB_SHOW(emulate_caw); |
| 490 | DEF_TB_DEV_ATTRIB_SHOW(emulate_3pc); |
| 491 | DEF_TB_DEV_ATTRIB_SHOW(pi_prot_type); |
| 492 | DEF_TB_DEV_ATTRIB_SHOW(hw_pi_prot_type); |
| 493 | DEF_TB_DEV_ATTRIB_SHOW(pi_prot_format); |
| 494 | DEF_TB_DEV_ATTRIB_SHOW(enforce_pr_isids); |
| 495 | DEF_TB_DEV_ATTRIB_SHOW(is_nonrot); |
| 496 | DEF_TB_DEV_ATTRIB_SHOW(emulate_rest_reord); |
| 497 | DEF_TB_DEV_ATTRIB_SHOW(force_pr_aptpl); |
| 498 | DEF_TB_DEV_ATTRIB_SHOW(hw_block_size); |
| 499 | DEF_TB_DEV_ATTRIB_SHOW(block_size); |
| 500 | DEF_TB_DEV_ATTRIB_SHOW(hw_max_sectors); |
| 501 | DEF_TB_DEV_ATTRIB_SHOW(optimal_sectors); |
| 502 | DEF_TB_DEV_ATTRIB_SHOW(hw_queue_depth); |
| 503 | DEF_TB_DEV_ATTRIB_SHOW(queue_depth); |
| 504 | DEF_TB_DEV_ATTRIB_SHOW(max_unmap_lba_count); |
| 505 | DEF_TB_DEV_ATTRIB_SHOW(max_unmap_block_desc_count); |
| 506 | DEF_TB_DEV_ATTRIB_SHOW(unmap_granularity); |
| 507 | DEF_TB_DEV_ATTRIB_SHOW(unmap_granularity_alignment); |
| 508 | DEF_TB_DEV_ATTRIB_SHOW(max_write_same_len); |
| 509 | |
| 510 | #define DEF_TB_DEV_ATTRIB_STORE_U32(_name) \ |
| 511 | static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\ |
| 512 | size_t count) \ |
Christoph Hellwig | 5873c4d | 2015-05-10 18:14:57 +0200 | [diff] [blame] | 513 | { \ |
Christoph Hellwig | 3effdb9 | 2015-05-10 18:14:58 +0200 | [diff] [blame] | 514 | u32 val; \ |
Christoph Hellwig | 5873c4d | 2015-05-10 18:14:57 +0200 | [diff] [blame] | 515 | int ret; \ |
| 516 | \ |
Christoph Hellwig | 3effdb9 | 2015-05-10 18:14:58 +0200 | [diff] [blame] | 517 | ret = kstrtou32(page, 0, &val); \ |
| 518 | if (ret < 0) \ |
| 519 | return ret; \ |
| 520 | da->_name = val; \ |
| 521 | return count; \ |
Christoph Hellwig | 5873c4d | 2015-05-10 18:14:57 +0200 | [diff] [blame] | 522 | } |
| 523 | |
Christoph Hellwig | 3effdb9 | 2015-05-10 18:14:58 +0200 | [diff] [blame] | 524 | DEF_TB_DEV_ATTRIB_STORE_U32(max_unmap_lba_count); |
| 525 | DEF_TB_DEV_ATTRIB_STORE_U32(max_unmap_block_desc_count); |
| 526 | DEF_TB_DEV_ATTRIB_STORE_U32(unmap_granularity); |
| 527 | DEF_TB_DEV_ATTRIB_STORE_U32(unmap_granularity_alignment); |
| 528 | DEF_TB_DEV_ATTRIB_STORE_U32(max_write_same_len); |
Christoph Hellwig | 5873c4d | 2015-05-10 18:14:57 +0200 | [diff] [blame] | 529 | |
Christoph Hellwig | 3effdb9 | 2015-05-10 18:14:58 +0200 | [diff] [blame] | 530 | #define DEF_TB_DEV_ATTRIB_STORE_BOOL(_name) \ |
| 531 | static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\ |
| 532 | size_t count) \ |
| 533 | { \ |
| 534 | bool flag; \ |
| 535 | int ret; \ |
| 536 | \ |
| 537 | ret = strtobool(page, &flag); \ |
| 538 | if (ret < 0) \ |
| 539 | return ret; \ |
| 540 | da->_name = flag; \ |
| 541 | return count; \ |
| 542 | } |
| 543 | |
| 544 | DEF_TB_DEV_ATTRIB_STORE_BOOL(emulate_fua_write); |
| 545 | DEF_TB_DEV_ATTRIB_STORE_BOOL(emulate_caw); |
| 546 | DEF_TB_DEV_ATTRIB_STORE_BOOL(emulate_3pc); |
| 547 | DEF_TB_DEV_ATTRIB_STORE_BOOL(enforce_pr_isids); |
| 548 | DEF_TB_DEV_ATTRIB_STORE_BOOL(is_nonrot); |
| 549 | |
| 550 | #define DEF_TB_DEV_ATTRIB_STORE_STUB(_name) \ |
| 551 | static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\ |
| 552 | size_t count) \ |
| 553 | { \ |
| 554 | printk_once(KERN_WARNING \ |
| 555 | "ignoring deprecated ##_name## attribute\n"); \ |
| 556 | return count; \ |
| 557 | } |
| 558 | |
| 559 | DEF_TB_DEV_ATTRIB_STORE_STUB(emulate_dpo); |
| 560 | DEF_TB_DEV_ATTRIB_STORE_STUB(emulate_fua_read); |
| 561 | |
| 562 | static void dev_set_t10_wwn_model_alias(struct se_device *dev) |
| 563 | { |
| 564 | const char *configname; |
| 565 | |
| 566 | configname = config_item_name(&dev->dev_group.cg_item); |
| 567 | if (strlen(configname) >= 16) { |
| 568 | pr_warn("dev[%p]: Backstore name '%s' is too long for " |
| 569 | "INQUIRY_MODEL, truncating to 16 bytes\n", dev, |
| 570 | configname); |
| 571 | } |
| 572 | snprintf(&dev->t10_wwn.model[0], 16, "%s", configname); |
| 573 | } |
| 574 | |
| 575 | static ssize_t store_emulate_model_alias(struct se_dev_attrib *da, |
| 576 | const char *page, size_t count) |
| 577 | { |
| 578 | struct se_device *dev = da->da_dev; |
| 579 | bool flag; |
| 580 | int ret; |
| 581 | |
| 582 | if (dev->export_count) { |
| 583 | pr_err("dev[%p]: Unable to change model alias" |
| 584 | " while export_count is %d\n", |
| 585 | dev, dev->export_count); |
| 586 | return -EINVAL; |
| 587 | } |
| 588 | |
| 589 | ret = strtobool(page, &flag); |
| 590 | if (ret < 0) |
| 591 | return ret; |
| 592 | |
| 593 | if (flag) { |
| 594 | dev_set_t10_wwn_model_alias(dev); |
| 595 | } else { |
| 596 | strncpy(&dev->t10_wwn.model[0], |
| 597 | dev->transport->inquiry_prod, 16); |
| 598 | } |
| 599 | da->emulate_model_alias = flag; |
| 600 | return count; |
| 601 | } |
| 602 | |
| 603 | static ssize_t store_emulate_write_cache(struct se_dev_attrib *da, |
| 604 | const char *page, size_t count) |
| 605 | { |
| 606 | bool flag; |
| 607 | int ret; |
| 608 | |
| 609 | ret = strtobool(page, &flag); |
| 610 | if (ret < 0) |
| 611 | return ret; |
| 612 | |
| 613 | if (flag && da->da_dev->transport->get_write_cache) { |
| 614 | pr_err("emulate_write_cache not supported for this device\n"); |
| 615 | return -EINVAL; |
| 616 | } |
| 617 | |
| 618 | da->emulate_write_cache = flag; |
| 619 | pr_debug("dev[%p]: SE Device WRITE_CACHE_EMULATION flag: %d\n", |
| 620 | da->da_dev, flag); |
| 621 | return count; |
| 622 | } |
| 623 | |
| 624 | static ssize_t store_emulate_ua_intlck_ctrl(struct se_dev_attrib *da, |
| 625 | const char *page, size_t count) |
| 626 | { |
| 627 | u32 val; |
| 628 | int ret; |
| 629 | |
| 630 | ret = kstrtou32(page, 0, &val); |
| 631 | if (ret < 0) |
| 632 | return ret; |
| 633 | |
| 634 | if (val != 0 && val != 1 && val != 2) { |
| 635 | pr_err("Illegal value %d\n", val); |
| 636 | return -EINVAL; |
| 637 | } |
| 638 | |
| 639 | if (da->da_dev->export_count) { |
| 640 | pr_err("dev[%p]: Unable to change SE Device" |
| 641 | " UA_INTRLCK_CTRL while export_count is %d\n", |
| 642 | da->da_dev, da->da_dev->export_count); |
| 643 | return -EINVAL; |
| 644 | } |
| 645 | da->emulate_ua_intlck_ctrl = val; |
| 646 | pr_debug("dev[%p]: SE Device UA_INTRLCK_CTRL flag: %d\n", |
| 647 | da->da_dev, val); |
| 648 | return count; |
| 649 | } |
| 650 | |
| 651 | static ssize_t store_emulate_tas(struct se_dev_attrib *da, |
| 652 | const char *page, size_t count) |
| 653 | { |
| 654 | bool flag; |
| 655 | int ret; |
| 656 | |
| 657 | ret = strtobool(page, &flag); |
| 658 | if (ret < 0) |
| 659 | return ret; |
| 660 | |
| 661 | if (da->da_dev->export_count) { |
| 662 | pr_err("dev[%p]: Unable to change SE Device TAS while" |
| 663 | " export_count is %d\n", |
| 664 | da->da_dev, da->da_dev->export_count); |
| 665 | return -EINVAL; |
| 666 | } |
| 667 | da->emulate_tas = flag; |
| 668 | pr_debug("dev[%p]: SE Device TASK_ABORTED status bit: %s\n", |
| 669 | da->da_dev, flag ? "Enabled" : "Disabled"); |
| 670 | |
| 671 | return count; |
| 672 | } |
| 673 | |
| 674 | static ssize_t store_emulate_tpu(struct se_dev_attrib *da, |
| 675 | const char *page, size_t count) |
| 676 | { |
| 677 | bool flag; |
| 678 | int ret; |
| 679 | |
| 680 | ret = strtobool(page, &flag); |
| 681 | if (ret < 0) |
| 682 | return ret; |
| 683 | |
| 684 | /* |
| 685 | * We expect this value to be non-zero when generic Block Layer |
| 686 | * Discard supported is detected iblock_create_virtdevice(). |
| 687 | */ |
| 688 | if (flag && !da->max_unmap_block_desc_count) { |
| 689 | pr_err("Generic Block Discard not supported\n"); |
| 690 | return -ENOSYS; |
| 691 | } |
| 692 | |
| 693 | da->emulate_tpu = flag; |
| 694 | pr_debug("dev[%p]: SE Device Thin Provisioning UNMAP bit: %d\n", |
| 695 | da->da_dev, flag); |
| 696 | return count; |
| 697 | } |
| 698 | |
| 699 | static ssize_t store_emulate_tpws(struct se_dev_attrib *da, |
| 700 | const char *page, size_t count) |
| 701 | { |
| 702 | bool flag; |
| 703 | int ret; |
| 704 | |
| 705 | ret = strtobool(page, &flag); |
| 706 | if (ret < 0) |
| 707 | return ret; |
| 708 | |
| 709 | /* |
| 710 | * We expect this value to be non-zero when generic Block Layer |
| 711 | * Discard supported is detected iblock_create_virtdevice(). |
| 712 | */ |
| 713 | if (flag && !da->max_unmap_block_desc_count) { |
| 714 | pr_err("Generic Block Discard not supported\n"); |
| 715 | return -ENOSYS; |
| 716 | } |
| 717 | |
| 718 | da->emulate_tpws = flag; |
| 719 | pr_debug("dev[%p]: SE Device Thin Provisioning WRITE_SAME: %d\n", |
| 720 | da->da_dev, flag); |
| 721 | return count; |
| 722 | } |
| 723 | |
| 724 | static ssize_t store_pi_prot_type(struct se_dev_attrib *da, |
| 725 | const char *page, size_t count) |
| 726 | { |
| 727 | int old_prot = da->pi_prot_type, ret; |
| 728 | struct se_device *dev = da->da_dev; |
| 729 | u32 flag; |
| 730 | |
| 731 | ret = kstrtou32(page, 0, &flag); |
| 732 | if (ret < 0) |
| 733 | return ret; |
| 734 | |
| 735 | if (flag != 0 && flag != 1 && flag != 2 && flag != 3) { |
| 736 | pr_err("Illegal value %d for pi_prot_type\n", flag); |
| 737 | return -EINVAL; |
| 738 | } |
| 739 | if (flag == 2) { |
| 740 | pr_err("DIF TYPE2 protection currently not supported\n"); |
| 741 | return -ENOSYS; |
| 742 | } |
| 743 | if (da->hw_pi_prot_type) { |
| 744 | pr_warn("DIF protection enabled on underlying hardware," |
| 745 | " ignoring\n"); |
| 746 | return count; |
| 747 | } |
| 748 | if (!dev->transport->init_prot || !dev->transport->free_prot) { |
| 749 | /* 0 is only allowed value for non-supporting backends */ |
| 750 | if (flag == 0) |
| 751 | return 0; |
| 752 | |
| 753 | pr_err("DIF protection not supported by backend: %s\n", |
| 754 | dev->transport->name); |
| 755 | return -ENOSYS; |
| 756 | } |
| 757 | if (!(dev->dev_flags & DF_CONFIGURED)) { |
| 758 | pr_err("DIF protection requires device to be configured\n"); |
| 759 | return -ENODEV; |
| 760 | } |
| 761 | if (dev->export_count) { |
| 762 | pr_err("dev[%p]: Unable to change SE Device PROT type while" |
| 763 | " export_count is %d\n", dev, dev->export_count); |
| 764 | return -EINVAL; |
| 765 | } |
| 766 | |
| 767 | da->pi_prot_type = flag; |
| 768 | |
| 769 | if (flag && !old_prot) { |
| 770 | ret = dev->transport->init_prot(dev); |
| 771 | if (ret) { |
| 772 | da->pi_prot_type = old_prot; |
| 773 | return ret; |
| 774 | } |
| 775 | |
| 776 | } else if (!flag && old_prot) { |
| 777 | dev->transport->free_prot(dev); |
| 778 | } |
| 779 | |
| 780 | pr_debug("dev[%p]: SE Device Protection Type: %d\n", dev, flag); |
| 781 | return count; |
| 782 | } |
| 783 | |
| 784 | static ssize_t store_pi_prot_format(struct se_dev_attrib *da, |
| 785 | const char *page, size_t count) |
| 786 | { |
| 787 | struct se_device *dev = da->da_dev; |
| 788 | bool flag; |
| 789 | int ret; |
| 790 | |
| 791 | ret = strtobool(page, &flag); |
| 792 | if (ret < 0) |
| 793 | return ret; |
| 794 | |
| 795 | if (!flag) |
| 796 | return count; |
| 797 | |
| 798 | if (!dev->transport->format_prot) { |
| 799 | pr_err("DIF protection format not supported by backend %s\n", |
| 800 | dev->transport->name); |
| 801 | return -ENOSYS; |
| 802 | } |
| 803 | if (!(dev->dev_flags & DF_CONFIGURED)) { |
| 804 | pr_err("DIF protection format requires device to be configured\n"); |
| 805 | return -ENODEV; |
| 806 | } |
| 807 | if (dev->export_count) { |
| 808 | pr_err("dev[%p]: Unable to format SE Device PROT type while" |
| 809 | " export_count is %d\n", dev, dev->export_count); |
| 810 | return -EINVAL; |
| 811 | } |
| 812 | |
| 813 | ret = dev->transport->format_prot(dev); |
| 814 | if (ret) |
| 815 | return ret; |
| 816 | |
| 817 | pr_debug("dev[%p]: SE Device Protection Format complete\n", dev); |
| 818 | return count; |
| 819 | } |
| 820 | |
| 821 | static ssize_t store_force_pr_aptpl(struct se_dev_attrib *da, |
| 822 | const char *page, size_t count) |
| 823 | { |
| 824 | bool flag; |
| 825 | int ret; |
| 826 | |
| 827 | ret = strtobool(page, &flag); |
| 828 | if (ret < 0) |
| 829 | return ret; |
| 830 | if (da->da_dev->export_count) { |
| 831 | pr_err("dev[%p]: Unable to set force_pr_aptpl while" |
| 832 | " export_count is %d\n", |
| 833 | da->da_dev, da->da_dev->export_count); |
| 834 | return -EINVAL; |
| 835 | } |
| 836 | |
| 837 | da->force_pr_aptpl = flag; |
| 838 | pr_debug("dev[%p]: SE Device force_pr_aptpl: %d\n", da->da_dev, flag); |
| 839 | return count; |
| 840 | } |
| 841 | |
| 842 | static ssize_t store_emulate_rest_reord(struct se_dev_attrib *da, |
| 843 | const char *page, size_t count) |
| 844 | { |
| 845 | bool flag; |
| 846 | int ret; |
| 847 | |
| 848 | ret = strtobool(page, &flag); |
| 849 | if (ret < 0) |
| 850 | return ret; |
| 851 | |
| 852 | if (flag != 0) { |
| 853 | printk(KERN_ERR "dev[%p]: SE Device emulation of restricted" |
| 854 | " reordering not implemented\n", da->da_dev); |
| 855 | return -ENOSYS; |
| 856 | } |
| 857 | da->emulate_rest_reord = flag; |
| 858 | pr_debug("dev[%p]: SE Device emulate_rest_reord: %d\n", |
| 859 | da->da_dev, flag); |
| 860 | return count; |
| 861 | } |
| 862 | |
| 863 | /* |
| 864 | * Note, this can only be called on unexported SE Device Object. |
| 865 | */ |
| 866 | static ssize_t store_queue_depth(struct se_dev_attrib *da, |
| 867 | const char *page, size_t count) |
| 868 | { |
| 869 | struct se_device *dev = da->da_dev; |
| 870 | u32 val; |
| 871 | int ret; |
| 872 | |
| 873 | ret = kstrtou32(page, 0, &val); |
| 874 | if (ret < 0) |
| 875 | return ret; |
| 876 | |
| 877 | if (dev->export_count) { |
| 878 | pr_err("dev[%p]: Unable to change SE Device TCQ while" |
| 879 | " export_count is %d\n", |
| 880 | dev, dev->export_count); |
| 881 | return -EINVAL; |
| 882 | } |
| 883 | if (!val) { |
| 884 | pr_err("dev[%p]: Illegal ZERO value for queue_depth\n", dev); |
| 885 | return -EINVAL; |
| 886 | } |
| 887 | |
| 888 | if (val > dev->dev_attrib.queue_depth) { |
| 889 | if (val > dev->dev_attrib.hw_queue_depth) { |
| 890 | pr_err("dev[%p]: Passed queue_depth:" |
| 891 | " %u exceeds TCM/SE_Device MAX" |
| 892 | " TCQ: %u\n", dev, val, |
| 893 | dev->dev_attrib.hw_queue_depth); |
| 894 | return -EINVAL; |
| 895 | } |
| 896 | } |
| 897 | da->queue_depth = dev->queue_depth = val; |
| 898 | pr_debug("dev[%p]: SE Device TCQ Depth changed to: %u\n", dev, val); |
| 899 | return count; |
| 900 | } |
| 901 | |
| 902 | static ssize_t store_optimal_sectors(struct se_dev_attrib *da, |
| 903 | const char *page, size_t count) |
| 904 | { |
| 905 | u32 val; |
| 906 | int ret; |
| 907 | |
| 908 | ret = kstrtou32(page, 0, &val); |
| 909 | if (ret < 0) |
| 910 | return ret; |
| 911 | |
| 912 | if (da->da_dev->export_count) { |
| 913 | pr_err("dev[%p]: Unable to change SE Device" |
| 914 | " optimal_sectors while export_count is %d\n", |
| 915 | da->da_dev, da->da_dev->export_count); |
| 916 | return -EINVAL; |
| 917 | } |
| 918 | if (val > da->hw_max_sectors) { |
| 919 | pr_err("dev[%p]: Passed optimal_sectors %u cannot be" |
| 920 | " greater than hw_max_sectors: %u\n", |
| 921 | da->da_dev, val, da->hw_max_sectors); |
| 922 | return -EINVAL; |
| 923 | } |
| 924 | |
| 925 | da->optimal_sectors = val; |
| 926 | pr_debug("dev[%p]: SE Device optimal_sectors changed to %u\n", |
| 927 | da->da_dev, val); |
| 928 | return count; |
| 929 | } |
| 930 | |
| 931 | static ssize_t store_block_size(struct se_dev_attrib *da, |
| 932 | const char *page, size_t count) |
| 933 | { |
| 934 | u32 val; |
| 935 | int ret; |
| 936 | |
| 937 | ret = kstrtou32(page, 0, &val); |
| 938 | if (ret < 0) |
| 939 | return ret; |
| 940 | |
| 941 | if (da->da_dev->export_count) { |
| 942 | pr_err("dev[%p]: Unable to change SE Device block_size" |
| 943 | " while export_count is %d\n", |
| 944 | da->da_dev, da->da_dev->export_count); |
| 945 | return -EINVAL; |
| 946 | } |
| 947 | |
| 948 | if (val != 512 && val != 1024 && val != 2048 && val != 4096) { |
| 949 | pr_err("dev[%p]: Illegal value for block_device: %u" |
| 950 | " for SE device, must be 512, 1024, 2048 or 4096\n", |
| 951 | da->da_dev, val); |
| 952 | return -EINVAL; |
| 953 | } |
| 954 | |
| 955 | da->block_size = val; |
| 956 | if (da->max_bytes_per_io) |
| 957 | da->hw_max_sectors = da->max_bytes_per_io / val; |
| 958 | |
| 959 | pr_debug("dev[%p]: SE Device block_size changed to %u\n", |
| 960 | da->da_dev, val); |
| 961 | return count; |
| 962 | } |
Christoph Hellwig | 5873c4d | 2015-05-10 18:14:57 +0200 | [diff] [blame] | 963 | |
| 964 | CONFIGFS_EATTR_STRUCT(target_backend_dev_attrib, se_dev_attrib); |
| 965 | #define TB_DEV_ATTR(_backend, _name, _mode) \ |
| 966 | static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name = \ |
Christoph Hellwig | 3effdb9 | 2015-05-10 18:14:58 +0200 | [diff] [blame] | 967 | __CONFIGFS_EATTR(_name, _mode, \ |
| 968 | show_##_name, \ |
| 969 | store_##_name); |
Christoph Hellwig | 5873c4d | 2015-05-10 18:14:57 +0200 | [diff] [blame] | 970 | |
Christoph Hellwig | 3effdb9 | 2015-05-10 18:14:58 +0200 | [diff] [blame] | 971 | #define TB_DEV_ATTR_RO(_backend, _name) \ |
Christoph Hellwig | 5873c4d | 2015-05-10 18:14:57 +0200 | [diff] [blame] | 972 | static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name = \ |
| 973 | __CONFIGFS_EATTR_RO(_name, \ |
Christoph Hellwig | 3effdb9 | 2015-05-10 18:14:58 +0200 | [diff] [blame] | 974 | show_##_name); |
Christoph Hellwig | 5873c4d | 2015-05-10 18:14:57 +0200 | [diff] [blame] | 975 | |
| 976 | TB_DEV_ATTR(target_core, emulate_model_alias, S_IRUGO | S_IWUSR); |
| 977 | TB_DEV_ATTR(target_core, emulate_dpo, S_IRUGO | S_IWUSR); |
| 978 | TB_DEV_ATTR(target_core, emulate_fua_write, S_IRUGO | S_IWUSR); |
| 979 | TB_DEV_ATTR(target_core, emulate_fua_read, S_IRUGO | S_IWUSR); |
| 980 | TB_DEV_ATTR(target_core, emulate_write_cache, S_IRUGO | S_IWUSR); |
| 981 | TB_DEV_ATTR(target_core, emulate_ua_intlck_ctrl, S_IRUGO | S_IWUSR); |
| 982 | TB_DEV_ATTR(target_core, emulate_tas, S_IRUGO | S_IWUSR); |
| 983 | TB_DEV_ATTR(target_core, emulate_tpu, S_IRUGO | S_IWUSR); |
| 984 | TB_DEV_ATTR(target_core, emulate_tpws, S_IRUGO | S_IWUSR); |
| 985 | TB_DEV_ATTR(target_core, emulate_caw, S_IRUGO | S_IWUSR); |
| 986 | TB_DEV_ATTR(target_core, emulate_3pc, S_IRUGO | S_IWUSR); |
| 987 | TB_DEV_ATTR(target_core, pi_prot_type, S_IRUGO | S_IWUSR); |
| 988 | TB_DEV_ATTR_RO(target_core, hw_pi_prot_type); |
| 989 | TB_DEV_ATTR(target_core, pi_prot_format, S_IRUGO | S_IWUSR); |
| 990 | TB_DEV_ATTR(target_core, enforce_pr_isids, S_IRUGO | S_IWUSR); |
| 991 | TB_DEV_ATTR(target_core, is_nonrot, S_IRUGO | S_IWUSR); |
| 992 | TB_DEV_ATTR(target_core, emulate_rest_reord, S_IRUGO | S_IWUSR); |
| 993 | TB_DEV_ATTR(target_core, force_pr_aptpl, S_IRUGO | S_IWUSR) |
| 994 | TB_DEV_ATTR_RO(target_core, hw_block_size); |
| 995 | TB_DEV_ATTR(target_core, block_size, S_IRUGO | S_IWUSR) |
| 996 | TB_DEV_ATTR_RO(target_core, hw_max_sectors); |
| 997 | TB_DEV_ATTR(target_core, optimal_sectors, S_IRUGO | S_IWUSR); |
| 998 | TB_DEV_ATTR_RO(target_core, hw_queue_depth); |
| 999 | TB_DEV_ATTR(target_core, queue_depth, S_IRUGO | S_IWUSR); |
| 1000 | TB_DEV_ATTR(target_core, max_unmap_lba_count, S_IRUGO | S_IWUSR); |
| 1001 | TB_DEV_ATTR(target_core, max_unmap_block_desc_count, S_IRUGO | S_IWUSR); |
| 1002 | TB_DEV_ATTR(target_core, unmap_granularity, S_IRUGO | S_IWUSR); |
| 1003 | TB_DEV_ATTR(target_core, unmap_granularity_alignment, S_IRUGO | S_IWUSR); |
| 1004 | 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] | 1005 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1006 | CONFIGFS_EATTR_STRUCT(target_core_dev_attrib, se_dev_attrib); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1007 | CONFIGFS_EATTR_OPS(target_core_dev_attrib, se_dev_attrib, da_group); |
| 1008 | |
Christoph Hellwig | 5873c4d | 2015-05-10 18:14:57 +0200 | [diff] [blame] | 1009 | /* |
| 1010 | * dev_attrib attributes for devices using the target core SBC/SPC |
| 1011 | * interpreter. Any backend using spc_parse_cdb should be using |
| 1012 | * these. |
| 1013 | */ |
| 1014 | struct configfs_attribute *sbc_attrib_attrs[] = { |
| 1015 | &target_core_dev_attrib_emulate_model_alias.attr, |
| 1016 | &target_core_dev_attrib_emulate_dpo.attr, |
| 1017 | &target_core_dev_attrib_emulate_fua_write.attr, |
| 1018 | &target_core_dev_attrib_emulate_fua_read.attr, |
| 1019 | &target_core_dev_attrib_emulate_write_cache.attr, |
| 1020 | &target_core_dev_attrib_emulate_ua_intlck_ctrl.attr, |
| 1021 | &target_core_dev_attrib_emulate_tas.attr, |
| 1022 | &target_core_dev_attrib_emulate_tpu.attr, |
| 1023 | &target_core_dev_attrib_emulate_tpws.attr, |
| 1024 | &target_core_dev_attrib_emulate_caw.attr, |
| 1025 | &target_core_dev_attrib_emulate_3pc.attr, |
| 1026 | &target_core_dev_attrib_pi_prot_type.attr, |
| 1027 | &target_core_dev_attrib_hw_pi_prot_type.attr, |
| 1028 | &target_core_dev_attrib_pi_prot_format.attr, |
| 1029 | &target_core_dev_attrib_enforce_pr_isids.attr, |
| 1030 | &target_core_dev_attrib_is_nonrot.attr, |
| 1031 | &target_core_dev_attrib_emulate_rest_reord.attr, |
| 1032 | &target_core_dev_attrib_force_pr_aptpl.attr, |
| 1033 | &target_core_dev_attrib_hw_block_size.attr, |
| 1034 | &target_core_dev_attrib_block_size.attr, |
| 1035 | &target_core_dev_attrib_hw_max_sectors.attr, |
| 1036 | &target_core_dev_attrib_optimal_sectors.attr, |
| 1037 | &target_core_dev_attrib_hw_queue_depth.attr, |
| 1038 | &target_core_dev_attrib_queue_depth.attr, |
| 1039 | &target_core_dev_attrib_max_unmap_lba_count.attr, |
| 1040 | &target_core_dev_attrib_max_unmap_block_desc_count.attr, |
| 1041 | &target_core_dev_attrib_unmap_granularity.attr, |
| 1042 | &target_core_dev_attrib_unmap_granularity_alignment.attr, |
| 1043 | &target_core_dev_attrib_max_write_same_len.attr, |
| 1044 | NULL, |
| 1045 | }; |
| 1046 | EXPORT_SYMBOL(sbc_attrib_attrs); |
| 1047 | |
Christoph Hellwig | 5873c4d | 2015-05-10 18:14:57 +0200 | [diff] [blame] | 1048 | TB_DEV_ATTR_RO(target_pt, hw_pi_prot_type); |
| 1049 | TB_DEV_ATTR_RO(target_pt, hw_block_size); |
| 1050 | TB_DEV_ATTR_RO(target_pt, hw_max_sectors); |
| 1051 | TB_DEV_ATTR_RO(target_pt, hw_queue_depth); |
| 1052 | |
| 1053 | /* |
| 1054 | * Minimal dev_attrib attributes for devices passing through CDBs. |
| 1055 | * In this case we only provide a few read-only attributes for |
| 1056 | * backwards compatibility. |
| 1057 | */ |
| 1058 | struct configfs_attribute *passthrough_attrib_attrs[] = { |
| 1059 | &target_pt_dev_attrib_hw_pi_prot_type.attr, |
| 1060 | &target_pt_dev_attrib_hw_block_size.attr, |
| 1061 | &target_pt_dev_attrib_hw_max_sectors.attr, |
| 1062 | &target_pt_dev_attrib_hw_queue_depth.attr, |
| 1063 | NULL, |
| 1064 | }; |
| 1065 | EXPORT_SYMBOL(passthrough_attrib_attrs); |
| 1066 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1067 | static struct configfs_item_operations target_core_dev_attrib_ops = { |
| 1068 | .show_attribute = target_core_dev_attrib_attr_show, |
| 1069 | .store_attribute = target_core_dev_attrib_attr_store, |
| 1070 | }; |
| 1071 | |
Christoph Hellwig | 0a06d43 | 2015-05-10 18:14:56 +0200 | [diff] [blame] | 1072 | TB_CIT_SETUP_DRV(dev_attrib, &target_core_dev_attrib_ops, NULL); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1073 | |
Nicholas Bellinger | f79a897 | 2014-11-27 14:51:14 -0800 | [diff] [blame] | 1074 | /* End functions for struct config_item_type tb_dev_attrib_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1075 | |
Nicholas Bellinger | f8d389c | 2014-11-27 15:01:12 -0800 | [diff] [blame] | 1076 | /* Start functions for struct config_item_type tb_dev_wwn_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1077 | |
| 1078 | CONFIGFS_EATTR_STRUCT(target_core_dev_wwn, t10_wwn); |
| 1079 | #define SE_DEV_WWN_ATTR(_name, _mode) \ |
| 1080 | static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \ |
| 1081 | __CONFIGFS_EATTR(_name, _mode, \ |
| 1082 | target_core_dev_wwn_show_attr_##_name, \ |
| 1083 | target_core_dev_wwn_store_attr_##_name); |
| 1084 | |
| 1085 | #define SE_DEV_WWN_ATTR_RO(_name); \ |
| 1086 | do { \ |
| 1087 | static struct target_core_dev_wwn_attribute \ |
| 1088 | target_core_dev_wwn_##_name = \ |
| 1089 | __CONFIGFS_EATTR_RO(_name, \ |
| 1090 | target_core_dev_wwn_show_attr_##_name); \ |
| 1091 | } while (0); |
| 1092 | |
| 1093 | /* |
| 1094 | * VPD page 0x80 Unit serial |
| 1095 | */ |
| 1096 | static ssize_t target_core_dev_wwn_show_attr_vpd_unit_serial( |
| 1097 | struct t10_wwn *t10_wwn, |
| 1098 | char *page) |
| 1099 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1100 | return sprintf(page, "T10 VPD Unit Serial Number: %s\n", |
| 1101 | &t10_wwn->unit_serial[0]); |
| 1102 | } |
| 1103 | |
| 1104 | static ssize_t target_core_dev_wwn_store_attr_vpd_unit_serial( |
| 1105 | struct t10_wwn *t10_wwn, |
| 1106 | const char *page, |
| 1107 | size_t count) |
| 1108 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1109 | struct se_device *dev = t10_wwn->t10_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1110 | unsigned char buf[INQUIRY_VPD_SERIAL_LEN]; |
| 1111 | |
| 1112 | /* |
| 1113 | * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial |
| 1114 | * from the struct scsi_device level firmware, do not allow |
| 1115 | * VPD Unit Serial to be emulated. |
| 1116 | * |
| 1117 | * Note this struct scsi_device could also be emulating VPD |
| 1118 | * information from its drivers/scsi LLD. But for now we assume |
| 1119 | * it is doing 'the right thing' wrt a world wide unique |
| 1120 | * VPD Unit Serial Number that OS dependent multipath can depend on. |
| 1121 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1122 | if (dev->dev_flags & DF_FIRMWARE_VPD_UNIT_SERIAL) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1123 | pr_err("Underlying SCSI device firmware provided VPD" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1124 | " Unit Serial, ignoring request\n"); |
| 1125 | return -EOPNOTSUPP; |
| 1126 | } |
| 1127 | |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 1128 | if (strlen(page) >= INQUIRY_VPD_SERIAL_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1129 | pr_err("Emulated VPD Unit Serial exceeds" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1130 | " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN); |
| 1131 | return -EOVERFLOW; |
| 1132 | } |
| 1133 | /* |
| 1134 | * Check to see if any active $FABRIC_MOD exports exist. If they |
| 1135 | * do exist, fail here as changing this information on the fly |
| 1136 | * (underneath the initiator side OS dependent multipath code) |
| 1137 | * could cause negative effects. |
| 1138 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1139 | if (dev->export_count) { |
| 1140 | pr_err("Unable to set VPD Unit Serial while" |
| 1141 | " active %d $FABRIC_MOD exports exist\n", |
| 1142 | dev->export_count); |
| 1143 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1144 | } |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1145 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1146 | /* |
| 1147 | * This currently assumes ASCII encoding for emulated VPD Unit Serial. |
| 1148 | * |
| 1149 | * Also, strip any newline added from the userspace |
| 1150 | * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial |
| 1151 | */ |
| 1152 | memset(buf, 0, INQUIRY_VPD_SERIAL_LEN); |
| 1153 | snprintf(buf, INQUIRY_VPD_SERIAL_LEN, "%s", page); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1154 | snprintf(dev->t10_wwn.unit_serial, INQUIRY_VPD_SERIAL_LEN, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1155 | "%s", strstrip(buf)); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1156 | dev->dev_flags |= DF_EMULATED_VPD_UNIT_SERIAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1157 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1158 | pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:" |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1159 | " %s\n", dev->t10_wwn.unit_serial); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1160 | |
| 1161 | return count; |
| 1162 | } |
| 1163 | |
| 1164 | SE_DEV_WWN_ATTR(vpd_unit_serial, S_IRUGO | S_IWUSR); |
| 1165 | |
| 1166 | /* |
| 1167 | * VPD page 0x83 Protocol Identifier |
| 1168 | */ |
| 1169 | static ssize_t target_core_dev_wwn_show_attr_vpd_protocol_identifier( |
| 1170 | struct t10_wwn *t10_wwn, |
| 1171 | char *page) |
| 1172 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1173 | struct t10_vpd *vpd; |
| 1174 | unsigned char buf[VPD_TMP_BUF_SIZE]; |
| 1175 | ssize_t len = 0; |
| 1176 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1177 | memset(buf, 0, VPD_TMP_BUF_SIZE); |
| 1178 | |
| 1179 | spin_lock(&t10_wwn->t10_vpd_lock); |
| 1180 | list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1181 | if (!vpd->protocol_identifier_set) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1182 | continue; |
| 1183 | |
| 1184 | transport_dump_vpd_proto_id(vpd, buf, VPD_TMP_BUF_SIZE); |
| 1185 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1186 | if (len + strlen(buf) >= PAGE_SIZE) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1187 | break; |
| 1188 | |
| 1189 | len += sprintf(page+len, "%s", buf); |
| 1190 | } |
| 1191 | spin_unlock(&t10_wwn->t10_vpd_lock); |
| 1192 | |
| 1193 | return len; |
| 1194 | } |
| 1195 | |
| 1196 | static ssize_t target_core_dev_wwn_store_attr_vpd_protocol_identifier( |
| 1197 | struct t10_wwn *t10_wwn, |
| 1198 | const char *page, |
| 1199 | size_t count) |
| 1200 | { |
| 1201 | return -ENOSYS; |
| 1202 | } |
| 1203 | |
| 1204 | SE_DEV_WWN_ATTR(vpd_protocol_identifier, S_IRUGO | S_IWUSR); |
| 1205 | |
| 1206 | /* |
| 1207 | * Generic wrapper for dumping VPD identifiers by association. |
| 1208 | */ |
| 1209 | #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \ |
| 1210 | static ssize_t target_core_dev_wwn_show_attr_##_name( \ |
| 1211 | struct t10_wwn *t10_wwn, \ |
| 1212 | char *page) \ |
| 1213 | { \ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1214 | struct t10_vpd *vpd; \ |
| 1215 | unsigned char buf[VPD_TMP_BUF_SIZE]; \ |
| 1216 | ssize_t len = 0; \ |
| 1217 | \ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1218 | spin_lock(&t10_wwn->t10_vpd_lock); \ |
| 1219 | list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \ |
| 1220 | if (vpd->association != _assoc) \ |
| 1221 | continue; \ |
| 1222 | \ |
| 1223 | memset(buf, 0, VPD_TMP_BUF_SIZE); \ |
| 1224 | transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1225 | if (len + strlen(buf) >= PAGE_SIZE) \ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1226 | break; \ |
| 1227 | len += sprintf(page+len, "%s", buf); \ |
| 1228 | \ |
| 1229 | memset(buf, 0, VPD_TMP_BUF_SIZE); \ |
| 1230 | transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1231 | if (len + strlen(buf) >= PAGE_SIZE) \ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1232 | break; \ |
| 1233 | len += sprintf(page+len, "%s", buf); \ |
| 1234 | \ |
| 1235 | memset(buf, 0, VPD_TMP_BUF_SIZE); \ |
| 1236 | transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1237 | if (len + strlen(buf) >= PAGE_SIZE) \ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1238 | break; \ |
| 1239 | len += sprintf(page+len, "%s", buf); \ |
| 1240 | } \ |
| 1241 | spin_unlock(&t10_wwn->t10_vpd_lock); \ |
| 1242 | \ |
| 1243 | return len; \ |
| 1244 | } |
| 1245 | |
| 1246 | /* |
Andy Shevchenko | 163cd5f | 2011-07-18 22:17:43 -0700 | [diff] [blame] | 1247 | * VPD page 0x83 Association: Logical Unit |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1248 | */ |
| 1249 | DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit, 0x00); |
| 1250 | |
| 1251 | static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_logical_unit( |
| 1252 | struct t10_wwn *t10_wwn, |
| 1253 | const char *page, |
| 1254 | size_t count) |
| 1255 | { |
| 1256 | return -ENOSYS; |
| 1257 | } |
| 1258 | |
| 1259 | SE_DEV_WWN_ATTR(vpd_assoc_logical_unit, S_IRUGO | S_IWUSR); |
| 1260 | |
| 1261 | /* |
| 1262 | * VPD page 0x83 Association: Target Port |
| 1263 | */ |
| 1264 | DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port, 0x10); |
| 1265 | |
| 1266 | static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_target_port( |
| 1267 | struct t10_wwn *t10_wwn, |
| 1268 | const char *page, |
| 1269 | size_t count) |
| 1270 | { |
| 1271 | return -ENOSYS; |
| 1272 | } |
| 1273 | |
| 1274 | SE_DEV_WWN_ATTR(vpd_assoc_target_port, S_IRUGO | S_IWUSR); |
| 1275 | |
| 1276 | /* |
| 1277 | * VPD page 0x83 Association: SCSI Target Device |
| 1278 | */ |
| 1279 | DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device, 0x20); |
| 1280 | |
| 1281 | static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device( |
| 1282 | struct t10_wwn *t10_wwn, |
| 1283 | const char *page, |
| 1284 | size_t count) |
| 1285 | { |
| 1286 | return -ENOSYS; |
| 1287 | } |
| 1288 | |
| 1289 | SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device, S_IRUGO | S_IWUSR); |
| 1290 | |
| 1291 | CONFIGFS_EATTR_OPS(target_core_dev_wwn, t10_wwn, t10_wwn_group); |
| 1292 | |
| 1293 | static struct configfs_attribute *target_core_dev_wwn_attrs[] = { |
| 1294 | &target_core_dev_wwn_vpd_unit_serial.attr, |
| 1295 | &target_core_dev_wwn_vpd_protocol_identifier.attr, |
| 1296 | &target_core_dev_wwn_vpd_assoc_logical_unit.attr, |
| 1297 | &target_core_dev_wwn_vpd_assoc_target_port.attr, |
| 1298 | &target_core_dev_wwn_vpd_assoc_scsi_target_device.attr, |
| 1299 | NULL, |
| 1300 | }; |
| 1301 | |
| 1302 | static struct configfs_item_operations target_core_dev_wwn_ops = { |
| 1303 | .show_attribute = target_core_dev_wwn_attr_show, |
| 1304 | .store_attribute = target_core_dev_wwn_attr_store, |
| 1305 | }; |
| 1306 | |
Nicholas Bellinger | f8d389c | 2014-11-27 15:01:12 -0800 | [diff] [blame] | 1307 | 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] | 1308 | |
Nicholas Bellinger | f8d389c | 2014-11-27 15:01:12 -0800 | [diff] [blame] | 1309 | /* End functions for struct config_item_type tb_dev_wwn_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1310 | |
Nicholas Bellinger | 91e2e39 | 2014-11-27 14:57:01 -0800 | [diff] [blame] | 1311 | /* Start functions for struct config_item_type tb_dev_pr_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1312 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1313 | CONFIGFS_EATTR_STRUCT(target_core_dev_pr, se_device); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1314 | #define SE_DEV_PR_ATTR(_name, _mode) \ |
| 1315 | static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \ |
| 1316 | __CONFIGFS_EATTR(_name, _mode, \ |
| 1317 | target_core_dev_pr_show_attr_##_name, \ |
| 1318 | target_core_dev_pr_store_attr_##_name); |
| 1319 | |
| 1320 | #define SE_DEV_PR_ATTR_RO(_name); \ |
| 1321 | static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \ |
| 1322 | __CONFIGFS_EATTR_RO(_name, \ |
| 1323 | target_core_dev_pr_show_attr_##_name); |
| 1324 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1325 | static ssize_t target_core_dev_pr_show_spc3_res(struct se_device *dev, |
| 1326 | char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1327 | { |
| 1328 | struct se_node_acl *se_nacl; |
| 1329 | struct t10_pr_registration *pr_reg; |
| 1330 | char i_buf[PR_REG_ISID_ID_LEN]; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1331 | |
| 1332 | memset(i_buf, 0, PR_REG_ISID_ID_LEN); |
| 1333 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1334 | pr_reg = dev->dev_pr_res_holder; |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1335 | if (!pr_reg) |
| 1336 | return sprintf(page, "No SPC-3 Reservation holder\n"); |
| 1337 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1338 | se_nacl = pr_reg->pr_reg_nacl; |
Andy Grover | d2843c1 | 2013-05-16 10:40:55 -0700 | [diff] [blame] | 1339 | 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] | 1340 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1341 | return sprintf(page, "SPC-3 Reservation: %s Initiator: %s%s\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1342 | se_nacl->se_tpg->se_tpg_tfo->get_fabric_name(), |
Andy Grover | d2843c1 | 2013-05-16 10:40:55 -0700 | [diff] [blame] | 1343 | se_nacl->initiatorname, i_buf); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1344 | } |
| 1345 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1346 | static ssize_t target_core_dev_pr_show_spc2_res(struct se_device *dev, |
| 1347 | char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1348 | { |
| 1349 | struct se_node_acl *se_nacl; |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1350 | ssize_t len; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1351 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1352 | se_nacl = dev->dev_reserved_node_acl; |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1353 | if (se_nacl) { |
| 1354 | len = sprintf(page, |
| 1355 | "SPC-2 Reservation: %s Initiator: %s\n", |
| 1356 | se_nacl->se_tpg->se_tpg_tfo->get_fabric_name(), |
| 1357 | se_nacl->initiatorname); |
| 1358 | } else { |
| 1359 | len = sprintf(page, "No SPC-2 Reservation holder\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1360 | } |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1361 | return len; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1362 | } |
| 1363 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1364 | static ssize_t target_core_dev_pr_show_attr_res_holder(struct se_device *dev, |
| 1365 | char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1366 | { |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1367 | int ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1368 | |
Andy Grover | a354170 | 2015-05-19 14:44:41 -0700 | [diff] [blame] | 1369 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1370 | return sprintf(page, "Passthrough\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1371 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1372 | spin_lock(&dev->dev_reservation_lock); |
| 1373 | if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) |
| 1374 | ret = target_core_dev_pr_show_spc2_res(dev, page); |
| 1375 | else |
| 1376 | ret = target_core_dev_pr_show_spc3_res(dev, page); |
| 1377 | spin_unlock(&dev->dev_reservation_lock); |
| 1378 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | SE_DEV_PR_ATTR_RO(res_holder); |
| 1382 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1383 | 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] | 1384 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1385 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1386 | ssize_t len = 0; |
| 1387 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1388 | spin_lock(&dev->dev_reservation_lock); |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1389 | if (!dev->dev_pr_res_holder) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1390 | len = sprintf(page, "No SPC-3 Reservation holder\n"); |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1391 | } else if (dev->dev_pr_res_holder->pr_reg_all_tg_pt) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1392 | len = sprintf(page, "SPC-3 Reservation: All Target" |
| 1393 | " Ports registration\n"); |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1394 | } else { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1395 | len = sprintf(page, "SPC-3 Reservation: Single" |
| 1396 | " Target Port registration\n"); |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1397 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1398 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1399 | spin_unlock(&dev->dev_reservation_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1400 | return len; |
| 1401 | } |
| 1402 | |
| 1403 | SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts); |
| 1404 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1405 | static ssize_t target_core_dev_pr_show_attr_res_pr_generation( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1406 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1407 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1408 | return sprintf(page, "0x%08x\n", dev->t10_pr.pr_generation); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1409 | } |
| 1410 | |
| 1411 | SE_DEV_PR_ATTR_RO(res_pr_generation); |
| 1412 | |
| 1413 | /* |
| 1414 | * res_pr_holder_tg_port |
| 1415 | */ |
| 1416 | 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] | 1417 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1418 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1419 | struct se_node_acl *se_nacl; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1420 | struct se_portal_group *se_tpg; |
| 1421 | struct t10_pr_registration *pr_reg; |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1422 | const struct target_core_fabric_ops *tfo; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1423 | ssize_t len = 0; |
| 1424 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1425 | spin_lock(&dev->dev_reservation_lock); |
| 1426 | pr_reg = dev->dev_pr_res_holder; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1427 | if (!pr_reg) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1428 | len = sprintf(page, "No SPC-3 Reservation holder\n"); |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1429 | goto out_unlock; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1430 | } |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1431 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1432 | se_nacl = pr_reg->pr_reg_nacl; |
| 1433 | se_tpg = se_nacl->se_tpg; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1434 | tfo = se_tpg->se_tpg_tfo; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1435 | |
| 1436 | len += sprintf(page+len, "SPC-3 Reservation: %s" |
| 1437 | " Target Node Endpoint: %s\n", tfo->get_fabric_name(), |
| 1438 | tfo->tpg_get_wwn(se_tpg)); |
| 1439 | len += sprintf(page+len, "SPC-3 Reservation: Relative Port" |
Masanari Iida | 35d1efe | 2012-08-16 22:43:13 +0900 | [diff] [blame] | 1440 | " Identifier Tag: %hu %s Portal Group Tag: %hu" |
Nicholas Bellinger | 79dc9c9 | 2015-03-27 04:51:03 +0000 | [diff] [blame] | 1441 | " %s Logical Unit: %u\n", pr_reg->tg_pt_sep_rtpi, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1442 | tfo->get_fabric_name(), tfo->tpg_get_tag(se_tpg), |
Nicholas Bellinger | 79dc9c9 | 2015-03-27 04:51:03 +0000 | [diff] [blame] | 1443 | tfo->get_fabric_name(), pr_reg->pr_aptpl_target_lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1444 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1445 | out_unlock: |
| 1446 | spin_unlock(&dev->dev_reservation_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1447 | return len; |
| 1448 | } |
| 1449 | |
| 1450 | SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port); |
| 1451 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1452 | 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] | 1453 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1454 | { |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1455 | const struct target_core_fabric_ops *tfo; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1456 | struct t10_pr_registration *pr_reg; |
| 1457 | unsigned char buf[384]; |
| 1458 | char i_buf[PR_REG_ISID_ID_LEN]; |
| 1459 | ssize_t len = 0; |
Andy Grover | d2843c1 | 2013-05-16 10:40:55 -0700 | [diff] [blame] | 1460 | int reg_count = 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1461 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1462 | len += sprintf(page+len, "SPC-3 PR Registrations:\n"); |
| 1463 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1464 | spin_lock(&dev->t10_pr.registration_lock); |
| 1465 | list_for_each_entry(pr_reg, &dev->t10_pr.registration_list, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1466 | pr_reg_list) { |
| 1467 | |
| 1468 | memset(buf, 0, 384); |
| 1469 | memset(i_buf, 0, PR_REG_ISID_ID_LEN); |
| 1470 | tfo = pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo; |
Andy Grover | d2843c1 | 2013-05-16 10:40:55 -0700 | [diff] [blame] | 1471 | core_pr_dump_initiator_port(pr_reg, i_buf, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1472 | PR_REG_ISID_ID_LEN); |
| 1473 | sprintf(buf, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n", |
| 1474 | tfo->get_fabric_name(), |
Andy Grover | d2843c1 | 2013-05-16 10:40:55 -0700 | [diff] [blame] | 1475 | 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] | 1476 | pr_reg->pr_res_generation); |
| 1477 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1478 | if (len + strlen(buf) >= PAGE_SIZE) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1479 | break; |
| 1480 | |
| 1481 | len += sprintf(page+len, "%s", buf); |
| 1482 | reg_count++; |
| 1483 | } |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1484 | spin_unlock(&dev->t10_pr.registration_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1485 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1486 | if (!reg_count) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1487 | len += sprintf(page+len, "None\n"); |
| 1488 | |
| 1489 | return len; |
| 1490 | } |
| 1491 | |
| 1492 | SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts); |
| 1493 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1494 | static ssize_t target_core_dev_pr_show_attr_res_pr_type( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1495 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1496 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1497 | struct t10_pr_registration *pr_reg; |
| 1498 | ssize_t len = 0; |
| 1499 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1500 | spin_lock(&dev->dev_reservation_lock); |
| 1501 | pr_reg = dev->dev_pr_res_holder; |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1502 | if (pr_reg) { |
| 1503 | len = sprintf(page, "SPC-3 Reservation Type: %s\n", |
| 1504 | core_scsi3_pr_dump_type(pr_reg->pr_res_type)); |
| 1505 | } else { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1506 | len = sprintf(page, "No SPC-3 Reservation holder\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1507 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1508 | |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1509 | spin_unlock(&dev->dev_reservation_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1510 | return len; |
| 1511 | } |
| 1512 | |
| 1513 | SE_DEV_PR_ATTR_RO(res_pr_type); |
| 1514 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1515 | static ssize_t target_core_dev_pr_show_attr_res_type( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1516 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1517 | { |
Andy Grover | a354170 | 2015-05-19 14:44:41 -0700 | [diff] [blame] | 1518 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1519 | return sprintf(page, "SPC_PASSTHROUGH\n"); |
| 1520 | else if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) |
| 1521 | return sprintf(page, "SPC2_RESERVATIONS\n"); |
| 1522 | else |
| 1523 | return sprintf(page, "SPC3_PERSISTENT_RESERVATIONS\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | SE_DEV_PR_ATTR_RO(res_type); |
| 1527 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1528 | static ssize_t target_core_dev_pr_show_attr_res_aptpl_active( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1529 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1530 | { |
Andy Grover | a354170 | 2015-05-19 14:44:41 -0700 | [diff] [blame] | 1531 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1532 | return 0; |
| 1533 | |
| 1534 | return sprintf(page, "APTPL Bit Status: %s\n", |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1535 | (dev->t10_pr.pr_aptpl_active) ? "Activated" : "Disabled"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | SE_DEV_PR_ATTR_RO(res_aptpl_active); |
| 1539 | |
| 1540 | /* |
| 1541 | * res_aptpl_metadata |
| 1542 | */ |
| 1543 | static ssize_t target_core_dev_pr_show_attr_res_aptpl_metadata( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1544 | struct se_device *dev, char *page) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1545 | { |
Andy Grover | a354170 | 2015-05-19 14:44:41 -0700 | [diff] [blame] | 1546 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1547 | return 0; |
| 1548 | |
| 1549 | return sprintf(page, "Ready to process PR APTPL metadata..\n"); |
| 1550 | } |
| 1551 | |
| 1552 | enum { |
| 1553 | Opt_initiator_fabric, Opt_initiator_node, Opt_initiator_sid, |
| 1554 | Opt_sa_res_key, Opt_res_holder, Opt_res_type, Opt_res_scope, |
| 1555 | Opt_res_all_tg_pt, Opt_mapped_lun, Opt_target_fabric, |
| 1556 | Opt_target_node, Opt_tpgt, Opt_port_rtpi, Opt_target_lun, Opt_err |
| 1557 | }; |
| 1558 | |
| 1559 | static match_table_t tokens = { |
| 1560 | {Opt_initiator_fabric, "initiator_fabric=%s"}, |
| 1561 | {Opt_initiator_node, "initiator_node=%s"}, |
| 1562 | {Opt_initiator_sid, "initiator_sid=%s"}, |
| 1563 | {Opt_sa_res_key, "sa_res_key=%s"}, |
| 1564 | {Opt_res_holder, "res_holder=%d"}, |
| 1565 | {Opt_res_type, "res_type=%d"}, |
| 1566 | {Opt_res_scope, "res_scope=%d"}, |
| 1567 | {Opt_res_all_tg_pt, "res_all_tg_pt=%d"}, |
| 1568 | {Opt_mapped_lun, "mapped_lun=%d"}, |
| 1569 | {Opt_target_fabric, "target_fabric=%s"}, |
| 1570 | {Opt_target_node, "target_node=%s"}, |
| 1571 | {Opt_tpgt, "tpgt=%d"}, |
| 1572 | {Opt_port_rtpi, "port_rtpi=%d"}, |
| 1573 | {Opt_target_lun, "target_lun=%d"}, |
| 1574 | {Opt_err, NULL} |
| 1575 | }; |
| 1576 | |
| 1577 | static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1578 | struct se_device *dev, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1579 | const char *page, |
| 1580 | size_t count) |
| 1581 | { |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1582 | unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL; |
| 1583 | unsigned char *t_fabric = NULL, *t_port = NULL; |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1584 | char *orig, *ptr, *opts; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1585 | substring_t args[MAX_OPT_ARGS]; |
| 1586 | unsigned long long tmp_ll; |
| 1587 | u64 sa_res_key = 0; |
| 1588 | u32 mapped_lun = 0, target_lun = 0; |
| 1589 | 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] | 1590 | u16 tpgt = 0; |
| 1591 | u8 type = 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1592 | |
Andy Grover | a354170 | 2015-05-19 14:44:41 -0700 | [diff] [blame] | 1593 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
Christoph Hellwig | d977f43 | 2012-10-10 17:37:15 -0400 | [diff] [blame] | 1594 | return 0; |
| 1595 | if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1596 | return 0; |
| 1597 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1598 | if (dev->export_count) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1599 | pr_debug("Unable to process APTPL metadata while" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1600 | " active fabric exports exist\n"); |
| 1601 | return -EINVAL; |
| 1602 | } |
| 1603 | |
| 1604 | opts = kstrdup(page, GFP_KERNEL); |
| 1605 | if (!opts) |
| 1606 | return -ENOMEM; |
| 1607 | |
| 1608 | orig = opts; |
Sebastian Andrzej Siewior | 90c161b | 2011-11-23 20:53:17 +0100 | [diff] [blame] | 1609 | while ((ptr = strsep(&opts, ",\n")) != NULL) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1610 | if (!*ptr) |
| 1611 | continue; |
| 1612 | |
| 1613 | token = match_token(ptr, tokens, args); |
| 1614 | switch (token) { |
| 1615 | case Opt_initiator_fabric: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1616 | i_fabric = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1617 | if (!i_fabric) { |
| 1618 | ret = -ENOMEM; |
| 1619 | goto out; |
| 1620 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1621 | break; |
| 1622 | case Opt_initiator_node: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1623 | i_port = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1624 | if (!i_port) { |
| 1625 | ret = -ENOMEM; |
| 1626 | goto out; |
| 1627 | } |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 1628 | if (strlen(i_port) >= PR_APTPL_MAX_IPORT_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1629 | pr_err("APTPL metadata initiator_node=" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1630 | " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n", |
| 1631 | PR_APTPL_MAX_IPORT_LEN); |
| 1632 | ret = -EINVAL; |
| 1633 | break; |
| 1634 | } |
| 1635 | break; |
| 1636 | case Opt_initiator_sid: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1637 | isid = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1638 | if (!isid) { |
| 1639 | ret = -ENOMEM; |
| 1640 | goto out; |
| 1641 | } |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 1642 | if (strlen(isid) >= PR_REG_ISID_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1643 | pr_err("APTPL metadata initiator_isid" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1644 | "= exceeds PR_REG_ISID_LEN: %d\n", |
| 1645 | PR_REG_ISID_LEN); |
| 1646 | ret = -EINVAL; |
| 1647 | break; |
| 1648 | } |
| 1649 | break; |
| 1650 | case Opt_sa_res_key: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1651 | ret = kstrtoull(args->from, 0, &tmp_ll); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1652 | if (ret < 0) { |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1653 | pr_err("kstrtoull() failed for sa_res_key=\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1654 | goto out; |
| 1655 | } |
| 1656 | sa_res_key = (u64)tmp_ll; |
| 1657 | break; |
| 1658 | /* |
| 1659 | * PR APTPL Metadata for Reservation |
| 1660 | */ |
| 1661 | case Opt_res_holder: |
| 1662 | match_int(args, &arg); |
| 1663 | res_holder = arg; |
| 1664 | break; |
| 1665 | case Opt_res_type: |
| 1666 | match_int(args, &arg); |
| 1667 | type = (u8)arg; |
| 1668 | break; |
| 1669 | case Opt_res_scope: |
| 1670 | match_int(args, &arg); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1671 | break; |
| 1672 | case Opt_res_all_tg_pt: |
| 1673 | match_int(args, &arg); |
| 1674 | all_tg_pt = (int)arg; |
| 1675 | break; |
| 1676 | case Opt_mapped_lun: |
| 1677 | match_int(args, &arg); |
| 1678 | mapped_lun = (u32)arg; |
| 1679 | break; |
| 1680 | /* |
| 1681 | * PR APTPL Metadata for Target Port |
| 1682 | */ |
| 1683 | case Opt_target_fabric: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1684 | t_fabric = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1685 | if (!t_fabric) { |
| 1686 | ret = -ENOMEM; |
| 1687 | goto out; |
| 1688 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1689 | break; |
| 1690 | case Opt_target_node: |
Joern Engel | 8d21355 | 2014-09-02 17:49:56 -0400 | [diff] [blame] | 1691 | t_port = match_strdup(args); |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1692 | if (!t_port) { |
| 1693 | ret = -ENOMEM; |
| 1694 | goto out; |
| 1695 | } |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 1696 | if (strlen(t_port) >= PR_APTPL_MAX_TPORT_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1697 | pr_err("APTPL metadata target_node=" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1698 | " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n", |
| 1699 | PR_APTPL_MAX_TPORT_LEN); |
| 1700 | ret = -EINVAL; |
| 1701 | break; |
| 1702 | } |
| 1703 | break; |
| 1704 | case Opt_tpgt: |
| 1705 | match_int(args, &arg); |
| 1706 | tpgt = (u16)arg; |
| 1707 | break; |
| 1708 | case Opt_port_rtpi: |
| 1709 | match_int(args, &arg); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1710 | break; |
| 1711 | case Opt_target_lun: |
| 1712 | match_int(args, &arg); |
| 1713 | target_lun = (u32)arg; |
| 1714 | break; |
| 1715 | default: |
| 1716 | break; |
| 1717 | } |
| 1718 | } |
| 1719 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1720 | if (!i_port || !t_port || !sa_res_key) { |
| 1721 | pr_err("Illegal parameters for APTPL registration\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1722 | ret = -EINVAL; |
| 1723 | goto out; |
| 1724 | } |
| 1725 | |
| 1726 | if (res_holder && !(type)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1727 | pr_err("Illegal PR type: 0x%02x for reservation" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1728 | " holder\n", type); |
| 1729 | ret = -EINVAL; |
| 1730 | goto out; |
| 1731 | } |
| 1732 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1733 | ret = core_scsi3_alloc_aptpl_registration(&dev->t10_pr, sa_res_key, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1734 | i_port, isid, mapped_lun, t_port, tpgt, target_lun, |
| 1735 | res_holder, all_tg_pt, type); |
| 1736 | out: |
Jesper Juhl | 6d18025 | 2011-03-14 04:05:56 -0700 | [diff] [blame] | 1737 | kfree(i_fabric); |
| 1738 | kfree(i_port); |
| 1739 | kfree(isid); |
| 1740 | kfree(t_fabric); |
| 1741 | kfree(t_port); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1742 | kfree(orig); |
| 1743 | return (ret == 0) ? count : ret; |
| 1744 | } |
| 1745 | |
| 1746 | SE_DEV_PR_ATTR(res_aptpl_metadata, S_IRUGO | S_IWUSR); |
| 1747 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1748 | CONFIGFS_EATTR_OPS(target_core_dev_pr, se_device, dev_pr_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1749 | |
| 1750 | static struct configfs_attribute *target_core_dev_pr_attrs[] = { |
| 1751 | &target_core_dev_pr_res_holder.attr, |
| 1752 | &target_core_dev_pr_res_pr_all_tgt_pts.attr, |
| 1753 | &target_core_dev_pr_res_pr_generation.attr, |
| 1754 | &target_core_dev_pr_res_pr_holder_tg_port.attr, |
| 1755 | &target_core_dev_pr_res_pr_registered_i_pts.attr, |
| 1756 | &target_core_dev_pr_res_pr_type.attr, |
| 1757 | &target_core_dev_pr_res_type.attr, |
| 1758 | &target_core_dev_pr_res_aptpl_active.attr, |
| 1759 | &target_core_dev_pr_res_aptpl_metadata.attr, |
| 1760 | NULL, |
| 1761 | }; |
| 1762 | |
| 1763 | static struct configfs_item_operations target_core_dev_pr_ops = { |
| 1764 | .show_attribute = target_core_dev_pr_attr_show, |
| 1765 | .store_attribute = target_core_dev_pr_attr_store, |
| 1766 | }; |
| 1767 | |
Nicholas Bellinger | 91e2e39 | 2014-11-27 14:57:01 -0800 | [diff] [blame] | 1768 | 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] | 1769 | |
Nicholas Bellinger | 91e2e39 | 2014-11-27 14:57:01 -0800 | [diff] [blame] | 1770 | /* End functions for struct config_item_type tb_dev_pr_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1771 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 1772 | /* Start functions for struct config_item_type tb_dev_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1773 | |
| 1774 | static ssize_t target_core_show_dev_info(void *p, char *page) |
| 1775 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1776 | struct se_device *dev = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1777 | int bl = 0; |
| 1778 | ssize_t read_bytes = 0; |
| 1779 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1780 | transport_dump_dev_state(dev, page, &bl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1781 | read_bytes += bl; |
Christoph Hellwig | 0a06d43 | 2015-05-10 18:14:56 +0200 | [diff] [blame] | 1782 | read_bytes += dev->transport->show_configfs_dev_params(dev, |
| 1783 | page+read_bytes); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1784 | return read_bytes; |
| 1785 | } |
| 1786 | |
| 1787 | static struct target_core_configfs_attribute target_core_attr_dev_info = { |
| 1788 | .attr = { .ca_owner = THIS_MODULE, |
| 1789 | .ca_name = "info", |
| 1790 | .ca_mode = S_IRUGO }, |
| 1791 | .show = target_core_show_dev_info, |
| 1792 | .store = NULL, |
| 1793 | }; |
| 1794 | |
| 1795 | static ssize_t target_core_store_dev_control( |
| 1796 | void *p, |
| 1797 | const char *page, |
| 1798 | size_t count) |
| 1799 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1800 | struct se_device *dev = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1801 | |
Christoph Hellwig | 0a06d43 | 2015-05-10 18:14:56 +0200 | [diff] [blame] | 1802 | return dev->transport->set_configfs_dev_params(dev, page, count); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1803 | } |
| 1804 | |
| 1805 | static struct target_core_configfs_attribute target_core_attr_dev_control = { |
| 1806 | .attr = { .ca_owner = THIS_MODULE, |
| 1807 | .ca_name = "control", |
| 1808 | .ca_mode = S_IWUSR }, |
| 1809 | .show = NULL, |
| 1810 | .store = target_core_store_dev_control, |
| 1811 | }; |
| 1812 | |
| 1813 | static ssize_t target_core_show_dev_alias(void *p, char *page) |
| 1814 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1815 | struct se_device *dev = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1816 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1817 | if (!(dev->dev_flags & DF_USING_ALIAS)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1818 | return 0; |
| 1819 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1820 | return snprintf(page, PAGE_SIZE, "%s\n", dev->dev_alias); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | static ssize_t target_core_store_dev_alias( |
| 1824 | void *p, |
| 1825 | const char *page, |
| 1826 | size_t count) |
| 1827 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1828 | struct se_device *dev = p; |
| 1829 | struct se_hba *hba = dev->se_hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1830 | ssize_t read_bytes; |
| 1831 | |
| 1832 | if (count > (SE_DEV_ALIAS_LEN-1)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1833 | pr_err("alias count: %d exceeds" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1834 | " SE_DEV_ALIAS_LEN-1: %u\n", (int)count, |
| 1835 | SE_DEV_ALIAS_LEN-1); |
| 1836 | return -EINVAL; |
| 1837 | } |
| 1838 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1839 | 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] | 1840 | if (!read_bytes) |
| 1841 | return -EINVAL; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1842 | if (dev->dev_alias[read_bytes - 1] == '\n') |
| 1843 | dev->dev_alias[read_bytes - 1] = '\0'; |
Sebastian Andrzej Siewior | 0877eafd | 2011-11-28 13:57:25 +0100 | [diff] [blame] | 1844 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1845 | dev->dev_flags |= DF_USING_ALIAS; |
Dan Carpenter | 3011684 | 2012-01-27 15:50:55 +0300 | [diff] [blame] | 1846 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1847 | pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1848 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1849 | config_item_name(&dev->dev_group.cg_item), |
| 1850 | dev->dev_alias); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1851 | |
| 1852 | return read_bytes; |
| 1853 | } |
| 1854 | |
| 1855 | static struct target_core_configfs_attribute target_core_attr_dev_alias = { |
| 1856 | .attr = { .ca_owner = THIS_MODULE, |
| 1857 | .ca_name = "alias", |
| 1858 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 1859 | .show = target_core_show_dev_alias, |
| 1860 | .store = target_core_store_dev_alias, |
| 1861 | }; |
| 1862 | |
| 1863 | static ssize_t target_core_show_dev_udev_path(void *p, char *page) |
| 1864 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1865 | struct se_device *dev = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1866 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1867 | if (!(dev->dev_flags & DF_USING_UDEV_PATH)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1868 | return 0; |
| 1869 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1870 | return snprintf(page, PAGE_SIZE, "%s\n", dev->udev_path); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | static ssize_t target_core_store_dev_udev_path( |
| 1874 | void *p, |
| 1875 | const char *page, |
| 1876 | size_t count) |
| 1877 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1878 | struct se_device *dev = p; |
| 1879 | struct se_hba *hba = dev->se_hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1880 | ssize_t read_bytes; |
| 1881 | |
| 1882 | if (count > (SE_UDEV_PATH_LEN-1)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1883 | pr_err("udev_path count: %d exceeds" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1884 | " SE_UDEV_PATH_LEN-1: %u\n", (int)count, |
| 1885 | SE_UDEV_PATH_LEN-1); |
| 1886 | return -EINVAL; |
| 1887 | } |
| 1888 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1889 | read_bytes = snprintf(&dev->udev_path[0], SE_UDEV_PATH_LEN, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1890 | "%s", page); |
Dan Carpenter | 3011684 | 2012-01-27 15:50:55 +0300 | [diff] [blame] | 1891 | if (!read_bytes) |
| 1892 | return -EINVAL; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1893 | if (dev->udev_path[read_bytes - 1] == '\n') |
| 1894 | dev->udev_path[read_bytes - 1] = '\0'; |
Sebastian Andrzej Siewior | 0877eafd | 2011-11-28 13:57:25 +0100 | [diff] [blame] | 1895 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1896 | dev->dev_flags |= DF_USING_UDEV_PATH; |
Dan Carpenter | 3011684 | 2012-01-27 15:50:55 +0300 | [diff] [blame] | 1897 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1898 | pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1899 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1900 | config_item_name(&dev->dev_group.cg_item), |
| 1901 | dev->udev_path); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1902 | |
| 1903 | return read_bytes; |
| 1904 | } |
| 1905 | |
| 1906 | static struct target_core_configfs_attribute target_core_attr_dev_udev_path = { |
| 1907 | .attr = { .ca_owner = THIS_MODULE, |
| 1908 | .ca_name = "udev_path", |
| 1909 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 1910 | .show = target_core_show_dev_udev_path, |
| 1911 | .store = target_core_store_dev_udev_path, |
| 1912 | }; |
| 1913 | |
Andy Grover | 64146db | 2013-04-30 11:59:15 -0700 | [diff] [blame] | 1914 | static ssize_t target_core_show_dev_enable(void *p, char *page) |
| 1915 | { |
| 1916 | struct se_device *dev = p; |
| 1917 | |
| 1918 | return snprintf(page, PAGE_SIZE, "%d\n", !!(dev->dev_flags & DF_CONFIGURED)); |
| 1919 | } |
| 1920 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1921 | static ssize_t target_core_store_dev_enable( |
| 1922 | void *p, |
| 1923 | const char *page, |
| 1924 | size_t count) |
| 1925 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1926 | struct se_device *dev = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1927 | char *ptr; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1928 | int ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1929 | |
| 1930 | ptr = strstr(page, "1"); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1931 | if (!ptr) { |
| 1932 | pr_err("For dev_enable ops, only valid value" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1933 | " is \"1\"\n"); |
| 1934 | return -EINVAL; |
| 1935 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1936 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1937 | ret = target_configure_device(dev); |
| 1938 | if (ret) |
| 1939 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1940 | return count; |
| 1941 | } |
| 1942 | |
| 1943 | static struct target_core_configfs_attribute target_core_attr_dev_enable = { |
| 1944 | .attr = { .ca_owner = THIS_MODULE, |
| 1945 | .ca_name = "enable", |
Andy Grover | 64146db | 2013-04-30 11:59:15 -0700 | [diff] [blame] | 1946 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 1947 | .show = target_core_show_dev_enable, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1948 | .store = target_core_store_dev_enable, |
| 1949 | }; |
| 1950 | |
| 1951 | static ssize_t target_core_show_alua_lu_gp(void *p, char *page) |
| 1952 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1953 | struct se_device *dev = p; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1954 | struct config_item *lu_ci; |
| 1955 | struct t10_alua_lu_gp *lu_gp; |
| 1956 | struct t10_alua_lu_gp_member *lu_gp_mem; |
| 1957 | ssize_t len = 0; |
| 1958 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1959 | lu_gp_mem = dev->dev_alua_lu_gp_mem; |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 1960 | if (!lu_gp_mem) |
| 1961 | return 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1962 | |
| 1963 | spin_lock(&lu_gp_mem->lu_gp_mem_lock); |
| 1964 | lu_gp = lu_gp_mem->lu_gp; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1965 | if (lu_gp) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1966 | lu_ci = &lu_gp->lu_gp_group.cg_item; |
| 1967 | len += sprintf(page, "LU Group Alias: %s\nLU Group ID: %hu\n", |
| 1968 | config_item_name(lu_ci), lu_gp->lu_gp_id); |
| 1969 | } |
| 1970 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); |
| 1971 | |
| 1972 | return len; |
| 1973 | } |
| 1974 | |
| 1975 | static ssize_t target_core_store_alua_lu_gp( |
| 1976 | void *p, |
| 1977 | const char *page, |
| 1978 | size_t count) |
| 1979 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1980 | struct se_device *dev = p; |
| 1981 | struct se_hba *hba = dev->se_hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1982 | struct t10_alua_lu_gp *lu_gp = NULL, *lu_gp_new = NULL; |
| 1983 | struct t10_alua_lu_gp_member *lu_gp_mem; |
| 1984 | unsigned char buf[LU_GROUP_NAME_BUF]; |
| 1985 | int move = 0; |
| 1986 | |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 1987 | lu_gp_mem = dev->dev_alua_lu_gp_mem; |
| 1988 | if (!lu_gp_mem) |
| 1989 | return 0; |
| 1990 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1991 | if (count > LU_GROUP_NAME_BUF) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1992 | pr_err("ALUA LU Group Alias too large!\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1993 | return -EINVAL; |
| 1994 | } |
| 1995 | memset(buf, 0, LU_GROUP_NAME_BUF); |
| 1996 | memcpy(buf, page, count); |
| 1997 | /* |
| 1998 | * Any ALUA logical unit alias besides "NULL" means we will be |
| 1999 | * making a new group association. |
| 2000 | */ |
| 2001 | if (strcmp(strstrip(buf), "NULL")) { |
| 2002 | /* |
| 2003 | * core_alua_get_lu_gp_by_name() will increment reference to |
| 2004 | * struct t10_alua_lu_gp. This reference is released with |
| 2005 | * core_alua_get_lu_gp_by_name below(). |
| 2006 | */ |
| 2007 | lu_gp_new = core_alua_get_lu_gp_by_name(strstrip(buf)); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2008 | if (!lu_gp_new) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2009 | return -ENODEV; |
| 2010 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2011 | |
| 2012 | spin_lock(&lu_gp_mem->lu_gp_mem_lock); |
| 2013 | lu_gp = lu_gp_mem->lu_gp; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2014 | if (lu_gp) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2015 | /* |
| 2016 | * Clearing an existing lu_gp association, and replacing |
| 2017 | * with NULL |
| 2018 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2019 | if (!lu_gp_new) { |
| 2020 | pr_debug("Target_Core_ConfigFS: Releasing %s/%s" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2021 | " from ALUA LU Group: core/alua/lu_gps/%s, ID:" |
| 2022 | " %hu\n", |
| 2023 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2024 | config_item_name(&dev->dev_group.cg_item), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2025 | config_item_name(&lu_gp->lu_gp_group.cg_item), |
| 2026 | lu_gp->lu_gp_id); |
| 2027 | |
| 2028 | __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp); |
| 2029 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); |
| 2030 | |
| 2031 | return count; |
| 2032 | } |
| 2033 | /* |
| 2034 | * Removing existing association of lu_gp_mem with lu_gp |
| 2035 | */ |
| 2036 | __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp); |
| 2037 | move = 1; |
| 2038 | } |
| 2039 | /* |
| 2040 | * Associate lu_gp_mem with lu_gp_new. |
| 2041 | */ |
| 2042 | __core_alua_attach_lu_gp_mem(lu_gp_mem, lu_gp_new); |
| 2043 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); |
| 2044 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2045 | pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2046 | " core/alua/lu_gps/%s, ID: %hu\n", |
| 2047 | (move) ? "Moving" : "Adding", |
| 2048 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2049 | config_item_name(&dev->dev_group.cg_item), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2050 | config_item_name(&lu_gp_new->lu_gp_group.cg_item), |
| 2051 | lu_gp_new->lu_gp_id); |
| 2052 | |
| 2053 | core_alua_put_lu_gp_from_name(lu_gp_new); |
| 2054 | return count; |
| 2055 | } |
| 2056 | |
| 2057 | static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp = { |
| 2058 | .attr = { .ca_owner = THIS_MODULE, |
| 2059 | .ca_name = "alua_lu_gp", |
| 2060 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 2061 | .show = target_core_show_alua_lu_gp, |
| 2062 | .store = target_core_store_alua_lu_gp, |
| 2063 | }; |
| 2064 | |
Hannes Reinecke | 229d4f1 | 2013-12-17 09:18:50 +0100 | [diff] [blame] | 2065 | static ssize_t target_core_show_dev_lba_map(void *p, char *page) |
| 2066 | { |
| 2067 | struct se_device *dev = p; |
| 2068 | struct t10_alua_lba_map *map; |
| 2069 | struct t10_alua_lba_map_member *mem; |
| 2070 | char *b = page; |
| 2071 | int bl = 0; |
| 2072 | char state; |
| 2073 | |
| 2074 | spin_lock(&dev->t10_alua.lba_map_lock); |
| 2075 | if (!list_empty(&dev->t10_alua.lba_map_list)) |
| 2076 | bl += sprintf(b + bl, "%u %u\n", |
| 2077 | dev->t10_alua.lba_map_segment_size, |
| 2078 | dev->t10_alua.lba_map_segment_multiplier); |
| 2079 | list_for_each_entry(map, &dev->t10_alua.lba_map_list, lba_map_list) { |
| 2080 | bl += sprintf(b + bl, "%llu %llu", |
| 2081 | map->lba_map_first_lba, map->lba_map_last_lba); |
| 2082 | list_for_each_entry(mem, &map->lba_map_mem_list, |
| 2083 | lba_map_mem_list) { |
| 2084 | switch (mem->lba_map_mem_alua_state) { |
| 2085 | case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED: |
| 2086 | state = 'O'; |
| 2087 | break; |
| 2088 | case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED: |
| 2089 | state = 'A'; |
| 2090 | break; |
| 2091 | case ALUA_ACCESS_STATE_STANDBY: |
| 2092 | state = 'S'; |
| 2093 | break; |
| 2094 | case ALUA_ACCESS_STATE_UNAVAILABLE: |
| 2095 | state = 'U'; |
| 2096 | break; |
| 2097 | default: |
| 2098 | state = '.'; |
| 2099 | break; |
| 2100 | } |
| 2101 | bl += sprintf(b + bl, " %d:%c", |
| 2102 | mem->lba_map_mem_alua_pg_id, state); |
| 2103 | } |
| 2104 | bl += sprintf(b + bl, "\n"); |
| 2105 | } |
| 2106 | spin_unlock(&dev->t10_alua.lba_map_lock); |
| 2107 | return bl; |
| 2108 | } |
| 2109 | |
| 2110 | static ssize_t target_core_store_dev_lba_map( |
| 2111 | void *p, |
| 2112 | const char *page, |
| 2113 | size_t count) |
| 2114 | { |
| 2115 | struct se_device *dev = p; |
| 2116 | struct t10_alua_lba_map *lba_map = NULL; |
| 2117 | struct list_head lba_list; |
| 2118 | char *map_entries, *ptr; |
| 2119 | char state; |
| 2120 | int pg_num = -1, pg; |
| 2121 | int ret = 0, num = 0, pg_id, alua_state; |
| 2122 | unsigned long start_lba = -1, end_lba = -1; |
| 2123 | unsigned long segment_size = -1, segment_mult = -1; |
| 2124 | |
| 2125 | map_entries = kstrdup(page, GFP_KERNEL); |
| 2126 | if (!map_entries) |
| 2127 | return -ENOMEM; |
| 2128 | |
| 2129 | INIT_LIST_HEAD(&lba_list); |
| 2130 | while ((ptr = strsep(&map_entries, "\n")) != NULL) { |
| 2131 | if (!*ptr) |
| 2132 | continue; |
| 2133 | |
| 2134 | if (num == 0) { |
| 2135 | if (sscanf(ptr, "%lu %lu\n", |
| 2136 | &segment_size, &segment_mult) != 2) { |
| 2137 | pr_err("Invalid line %d\n", num); |
| 2138 | ret = -EINVAL; |
| 2139 | break; |
| 2140 | } |
| 2141 | num++; |
| 2142 | continue; |
| 2143 | } |
| 2144 | if (sscanf(ptr, "%lu %lu", &start_lba, &end_lba) != 2) { |
| 2145 | pr_err("Invalid line %d\n", num); |
| 2146 | ret = -EINVAL; |
| 2147 | break; |
| 2148 | } |
| 2149 | ptr = strchr(ptr, ' '); |
| 2150 | if (!ptr) { |
| 2151 | pr_err("Invalid line %d, missing end lba\n", num); |
| 2152 | ret = -EINVAL; |
| 2153 | break; |
| 2154 | } |
| 2155 | ptr++; |
| 2156 | ptr = strchr(ptr, ' '); |
| 2157 | if (!ptr) { |
| 2158 | pr_err("Invalid line %d, missing state definitions\n", |
| 2159 | num); |
| 2160 | ret = -EINVAL; |
| 2161 | break; |
| 2162 | } |
| 2163 | ptr++; |
| 2164 | lba_map = core_alua_allocate_lba_map(&lba_list, |
| 2165 | start_lba, end_lba); |
| 2166 | if (IS_ERR(lba_map)) { |
| 2167 | ret = PTR_ERR(lba_map); |
| 2168 | break; |
| 2169 | } |
| 2170 | pg = 0; |
| 2171 | while (sscanf(ptr, "%d:%c", &pg_id, &state) == 2) { |
| 2172 | switch (state) { |
| 2173 | case 'O': |
| 2174 | alua_state = ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED; |
| 2175 | break; |
| 2176 | case 'A': |
| 2177 | alua_state = ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED; |
| 2178 | break; |
| 2179 | case 'S': |
| 2180 | alua_state = ALUA_ACCESS_STATE_STANDBY; |
| 2181 | break; |
| 2182 | case 'U': |
| 2183 | alua_state = ALUA_ACCESS_STATE_UNAVAILABLE; |
| 2184 | break; |
| 2185 | default: |
| 2186 | pr_err("Invalid ALUA state '%c'\n", state); |
| 2187 | ret = -EINVAL; |
| 2188 | goto out; |
| 2189 | } |
| 2190 | |
| 2191 | ret = core_alua_allocate_lba_map_mem(lba_map, |
| 2192 | pg_id, alua_state); |
| 2193 | if (ret) { |
| 2194 | pr_err("Invalid target descriptor %d:%c " |
| 2195 | "at line %d\n", |
| 2196 | pg_id, state, num); |
| 2197 | break; |
| 2198 | } |
| 2199 | pg++; |
| 2200 | ptr = strchr(ptr, ' '); |
| 2201 | if (ptr) |
| 2202 | ptr++; |
| 2203 | else |
| 2204 | break; |
| 2205 | } |
| 2206 | if (pg_num == -1) |
| 2207 | pg_num = pg; |
| 2208 | else if (pg != pg_num) { |
| 2209 | pr_err("Only %d from %d port groups definitions " |
| 2210 | "at line %d\n", pg, pg_num, num); |
| 2211 | ret = -EINVAL; |
| 2212 | break; |
| 2213 | } |
| 2214 | num++; |
| 2215 | } |
| 2216 | out: |
| 2217 | if (ret) { |
| 2218 | core_alua_free_lba_map(&lba_list); |
| 2219 | count = ret; |
| 2220 | } else |
| 2221 | core_alua_set_lba_map(dev, &lba_list, |
| 2222 | segment_size, segment_mult); |
| 2223 | kfree(map_entries); |
| 2224 | return count; |
| 2225 | } |
| 2226 | |
| 2227 | static struct target_core_configfs_attribute target_core_attr_dev_lba_map = { |
| 2228 | .attr = { .ca_owner = THIS_MODULE, |
| 2229 | .ca_name = "lba_map", |
| 2230 | .ca_mode = S_IRUGO | S_IWUSR }, |
| 2231 | .show = target_core_show_dev_lba_map, |
| 2232 | .store = target_core_store_dev_lba_map, |
| 2233 | }; |
| 2234 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 2235 | static struct configfs_attribute *target_core_dev_attrs[] = { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2236 | &target_core_attr_dev_info.attr, |
| 2237 | &target_core_attr_dev_control.attr, |
| 2238 | &target_core_attr_dev_alias.attr, |
| 2239 | &target_core_attr_dev_udev_path.attr, |
| 2240 | &target_core_attr_dev_enable.attr, |
| 2241 | &target_core_attr_dev_alua_lu_gp.attr, |
Hannes Reinecke | 229d4f1 | 2013-12-17 09:18:50 +0100 | [diff] [blame] | 2242 | &target_core_attr_dev_lba_map.attr, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2243 | NULL, |
| 2244 | }; |
| 2245 | |
| 2246 | static void target_core_dev_release(struct config_item *item) |
| 2247 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2248 | struct config_group *dev_cg = to_config_group(item); |
| 2249 | struct se_device *dev = |
| 2250 | container_of(dev_cg, struct se_device, dev_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2251 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2252 | kfree(dev_cg->default_groups); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2253 | target_free_device(dev); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | static ssize_t target_core_dev_show(struct config_item *item, |
| 2257 | struct configfs_attribute *attr, |
| 2258 | char *page) |
| 2259 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2260 | struct config_group *dev_cg = to_config_group(item); |
| 2261 | struct se_device *dev = |
| 2262 | container_of(dev_cg, struct se_device, dev_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2263 | struct target_core_configfs_attribute *tc_attr = container_of( |
| 2264 | attr, struct target_core_configfs_attribute, attr); |
| 2265 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2266 | if (!tc_attr->show) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2267 | return -EINVAL; |
| 2268 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2269 | return tc_attr->show(dev, page); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | static ssize_t target_core_dev_store(struct config_item *item, |
| 2273 | struct configfs_attribute *attr, |
| 2274 | const char *page, size_t count) |
| 2275 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2276 | struct config_group *dev_cg = to_config_group(item); |
| 2277 | struct se_device *dev = |
| 2278 | container_of(dev_cg, struct se_device, dev_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2279 | struct target_core_configfs_attribute *tc_attr = container_of( |
| 2280 | attr, struct target_core_configfs_attribute, attr); |
| 2281 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2282 | if (!tc_attr->store) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2283 | return -EINVAL; |
| 2284 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2285 | return tc_attr->store(dev, page, count); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | static struct configfs_item_operations target_core_dev_item_ops = { |
| 2289 | .release = target_core_dev_release, |
| 2290 | .show_attribute = target_core_dev_show, |
| 2291 | .store_attribute = target_core_dev_store, |
| 2292 | }; |
| 2293 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 2294 | 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] | 2295 | |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 2296 | /* End functions for struct config_item_type tb_dev_cit */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2297 | |
| 2298 | /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */ |
| 2299 | |
| 2300 | CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp, t10_alua_lu_gp); |
| 2301 | #define SE_DEV_ALUA_LU_ATTR(_name, _mode) \ |
| 2302 | static struct target_core_alua_lu_gp_attribute \ |
| 2303 | target_core_alua_lu_gp_##_name = \ |
| 2304 | __CONFIGFS_EATTR(_name, _mode, \ |
| 2305 | target_core_alua_lu_gp_show_attr_##_name, \ |
| 2306 | target_core_alua_lu_gp_store_attr_##_name); |
| 2307 | |
| 2308 | #define SE_DEV_ALUA_LU_ATTR_RO(_name) \ |
| 2309 | static struct target_core_alua_lu_gp_attribute \ |
| 2310 | target_core_alua_lu_gp_##_name = \ |
| 2311 | __CONFIGFS_EATTR_RO(_name, \ |
| 2312 | target_core_alua_lu_gp_show_attr_##_name); |
| 2313 | |
| 2314 | /* |
| 2315 | * lu_gp_id |
| 2316 | */ |
| 2317 | static ssize_t target_core_alua_lu_gp_show_attr_lu_gp_id( |
| 2318 | struct t10_alua_lu_gp *lu_gp, |
| 2319 | char *page) |
| 2320 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2321 | if (!lu_gp->lu_gp_valid_id) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2322 | return 0; |
| 2323 | |
| 2324 | return sprintf(page, "%hu\n", lu_gp->lu_gp_id); |
| 2325 | } |
| 2326 | |
| 2327 | static ssize_t target_core_alua_lu_gp_store_attr_lu_gp_id( |
| 2328 | struct t10_alua_lu_gp *lu_gp, |
| 2329 | const char *page, |
| 2330 | size_t count) |
| 2331 | { |
| 2332 | struct config_group *alua_lu_gp_cg = &lu_gp->lu_gp_group; |
| 2333 | unsigned long lu_gp_id; |
| 2334 | int ret; |
| 2335 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2336 | ret = kstrtoul(page, 0, &lu_gp_id); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2337 | if (ret < 0) { |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2338 | pr_err("kstrtoul() returned %d for" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2339 | " lu_gp_id\n", ret); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2340 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2341 | } |
| 2342 | if (lu_gp_id > 0x0000ffff) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2343 | pr_err("ALUA lu_gp_id: %lu exceeds maximum:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2344 | " 0x0000ffff\n", lu_gp_id); |
| 2345 | return -EINVAL; |
| 2346 | } |
| 2347 | |
| 2348 | ret = core_alua_set_lu_gp_id(lu_gp, (u16)lu_gp_id); |
| 2349 | if (ret < 0) |
| 2350 | return -EINVAL; |
| 2351 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2352 | pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2353 | " Group: core/alua/lu_gps/%s to ID: %hu\n", |
| 2354 | config_item_name(&alua_lu_gp_cg->cg_item), |
| 2355 | lu_gp->lu_gp_id); |
| 2356 | |
| 2357 | return count; |
| 2358 | } |
| 2359 | |
| 2360 | SE_DEV_ALUA_LU_ATTR(lu_gp_id, S_IRUGO | S_IWUSR); |
| 2361 | |
| 2362 | /* |
| 2363 | * members |
| 2364 | */ |
| 2365 | static ssize_t target_core_alua_lu_gp_show_attr_members( |
| 2366 | struct t10_alua_lu_gp *lu_gp, |
| 2367 | char *page) |
| 2368 | { |
| 2369 | struct se_device *dev; |
| 2370 | struct se_hba *hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2371 | struct t10_alua_lu_gp_member *lu_gp_mem; |
| 2372 | ssize_t len = 0, cur_len; |
| 2373 | unsigned char buf[LU_GROUP_NAME_BUF]; |
| 2374 | |
| 2375 | memset(buf, 0, LU_GROUP_NAME_BUF); |
| 2376 | |
| 2377 | spin_lock(&lu_gp->lu_gp_lock); |
| 2378 | list_for_each_entry(lu_gp_mem, &lu_gp->lu_gp_mem_list, lu_gp_mem_list) { |
| 2379 | dev = lu_gp_mem->lu_gp_mem_dev; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2380 | hba = dev->se_hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2381 | |
| 2382 | cur_len = snprintf(buf, LU_GROUP_NAME_BUF, "%s/%s\n", |
| 2383 | config_item_name(&hba->hba_group.cg_item), |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2384 | config_item_name(&dev->dev_group.cg_item)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2385 | cur_len++; /* Extra byte for NULL terminator */ |
| 2386 | |
| 2387 | if ((cur_len + len) > PAGE_SIZE) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2388 | pr_warn("Ran out of lu_gp_show_attr" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2389 | "_members buffer\n"); |
| 2390 | break; |
| 2391 | } |
| 2392 | memcpy(page+len, buf, cur_len); |
| 2393 | len += cur_len; |
| 2394 | } |
| 2395 | spin_unlock(&lu_gp->lu_gp_lock); |
| 2396 | |
| 2397 | return len; |
| 2398 | } |
| 2399 | |
| 2400 | SE_DEV_ALUA_LU_ATTR_RO(members); |
| 2401 | |
| 2402 | CONFIGFS_EATTR_OPS(target_core_alua_lu_gp, t10_alua_lu_gp, lu_gp_group); |
| 2403 | |
| 2404 | static struct configfs_attribute *target_core_alua_lu_gp_attrs[] = { |
| 2405 | &target_core_alua_lu_gp_lu_gp_id.attr, |
| 2406 | &target_core_alua_lu_gp_members.attr, |
| 2407 | NULL, |
| 2408 | }; |
| 2409 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2410 | static void target_core_alua_lu_gp_release(struct config_item *item) |
| 2411 | { |
| 2412 | struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item), |
| 2413 | struct t10_alua_lu_gp, lu_gp_group); |
| 2414 | |
| 2415 | core_alua_free_lu_gp(lu_gp); |
| 2416 | } |
| 2417 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2418 | static struct configfs_item_operations target_core_alua_lu_gp_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2419 | .release = target_core_alua_lu_gp_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2420 | .show_attribute = target_core_alua_lu_gp_attr_show, |
| 2421 | .store_attribute = target_core_alua_lu_gp_attr_store, |
| 2422 | }; |
| 2423 | |
| 2424 | static struct config_item_type target_core_alua_lu_gp_cit = { |
| 2425 | .ct_item_ops = &target_core_alua_lu_gp_ops, |
| 2426 | .ct_attrs = target_core_alua_lu_gp_attrs, |
| 2427 | .ct_owner = THIS_MODULE, |
| 2428 | }; |
| 2429 | |
| 2430 | /* End functions for struct config_item_type target_core_alua_lu_gp_cit */ |
| 2431 | |
| 2432 | /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */ |
| 2433 | |
| 2434 | static struct config_group *target_core_alua_create_lu_gp( |
| 2435 | struct config_group *group, |
| 2436 | const char *name) |
| 2437 | { |
| 2438 | struct t10_alua_lu_gp *lu_gp; |
| 2439 | struct config_group *alua_lu_gp_cg = NULL; |
| 2440 | struct config_item *alua_lu_gp_ci = NULL; |
| 2441 | |
| 2442 | lu_gp = core_alua_allocate_lu_gp(name, 0); |
| 2443 | if (IS_ERR(lu_gp)) |
| 2444 | return NULL; |
| 2445 | |
| 2446 | alua_lu_gp_cg = &lu_gp->lu_gp_group; |
| 2447 | alua_lu_gp_ci = &alua_lu_gp_cg->cg_item; |
| 2448 | |
| 2449 | config_group_init_type_name(alua_lu_gp_cg, name, |
| 2450 | &target_core_alua_lu_gp_cit); |
| 2451 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2452 | pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2453 | " Group: core/alua/lu_gps/%s\n", |
| 2454 | config_item_name(alua_lu_gp_ci)); |
| 2455 | |
| 2456 | return alua_lu_gp_cg; |
| 2457 | |
| 2458 | } |
| 2459 | |
| 2460 | static void target_core_alua_drop_lu_gp( |
| 2461 | struct config_group *group, |
| 2462 | struct config_item *item) |
| 2463 | { |
| 2464 | struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item), |
| 2465 | struct t10_alua_lu_gp, lu_gp_group); |
| 2466 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2467 | pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2468 | " Group: core/alua/lu_gps/%s, ID: %hu\n", |
| 2469 | config_item_name(item), lu_gp->lu_gp_id); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2470 | /* |
| 2471 | * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release() |
| 2472 | * -> target_core_alua_lu_gp_release() |
| 2473 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2474 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2475 | } |
| 2476 | |
| 2477 | static struct configfs_group_operations target_core_alua_lu_gps_group_ops = { |
| 2478 | .make_group = &target_core_alua_create_lu_gp, |
| 2479 | .drop_item = &target_core_alua_drop_lu_gp, |
| 2480 | }; |
| 2481 | |
| 2482 | static struct config_item_type target_core_alua_lu_gps_cit = { |
| 2483 | .ct_item_ops = NULL, |
| 2484 | .ct_group_ops = &target_core_alua_lu_gps_group_ops, |
| 2485 | .ct_owner = THIS_MODULE, |
| 2486 | }; |
| 2487 | |
| 2488 | /* End functions for struct config_item_type target_core_alua_lu_gps_cit */ |
| 2489 | |
| 2490 | /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */ |
| 2491 | |
| 2492 | CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp, t10_alua_tg_pt_gp); |
| 2493 | #define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \ |
| 2494 | static struct target_core_alua_tg_pt_gp_attribute \ |
| 2495 | target_core_alua_tg_pt_gp_##_name = \ |
| 2496 | __CONFIGFS_EATTR(_name, _mode, \ |
| 2497 | target_core_alua_tg_pt_gp_show_attr_##_name, \ |
| 2498 | target_core_alua_tg_pt_gp_store_attr_##_name); |
| 2499 | |
| 2500 | #define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \ |
| 2501 | static struct target_core_alua_tg_pt_gp_attribute \ |
| 2502 | target_core_alua_tg_pt_gp_##_name = \ |
| 2503 | __CONFIGFS_EATTR_RO(_name, \ |
| 2504 | target_core_alua_tg_pt_gp_show_attr_##_name); |
| 2505 | |
| 2506 | /* |
| 2507 | * alua_access_state |
| 2508 | */ |
| 2509 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_state( |
| 2510 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2511 | char *page) |
| 2512 | { |
| 2513 | return sprintf(page, "%d\n", |
| 2514 | atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state)); |
| 2515 | } |
| 2516 | |
| 2517 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_state( |
| 2518 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2519 | const char *page, |
| 2520 | size_t count) |
| 2521 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2522 | struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2523 | unsigned long tmp; |
| 2524 | int new_state, ret; |
| 2525 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2526 | if (!tg_pt_gp->tg_pt_gp_valid_id) { |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2527 | pr_err("Unable to do implicit ALUA on non valid" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2528 | " tg_pt_gp ID: %hu\n", tg_pt_gp->tg_pt_gp_valid_id); |
| 2529 | return -EINVAL; |
| 2530 | } |
Nicholas Bellinger | f145377 | 2014-06-06 00:52:57 -0700 | [diff] [blame] | 2531 | if (!(dev->dev_flags & DF_CONFIGURED)) { |
| 2532 | pr_err("Unable to set alua_access_state while device is" |
| 2533 | " not configured\n"); |
| 2534 | return -ENODEV; |
| 2535 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2536 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2537 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2538 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2539 | pr_err("Unable to extract new ALUA access state from" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2540 | " %s\n", page); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2541 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2542 | } |
| 2543 | new_state = (int)tmp; |
| 2544 | |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2545 | if (!(tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_IMPLICIT_ALUA)) { |
| 2546 | pr_err("Unable to process implicit configfs ALUA" |
| 2547 | " transition while TPGS_IMPLICIT_ALUA is disabled\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2548 | return -EINVAL; |
| 2549 | } |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 2550 | if (tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_EXPLICIT_ALUA && |
| 2551 | new_state == ALUA_ACCESS_STATE_LBA_DEPENDENT) { |
| 2552 | /* LBA DEPENDENT is only allowed with implicit ALUA */ |
| 2553 | pr_err("Unable to process implicit configfs ALUA transition" |
| 2554 | " while explicit ALUA management is enabled\n"); |
| 2555 | return -EINVAL; |
| 2556 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2557 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2558 | ret = core_alua_do_port_transition(tg_pt_gp, dev, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2559 | NULL, NULL, new_state, 0); |
| 2560 | return (!ret) ? count : -EINVAL; |
| 2561 | } |
| 2562 | |
| 2563 | SE_DEV_ALUA_TG_PT_ATTR(alua_access_state, S_IRUGO | S_IWUSR); |
| 2564 | |
| 2565 | /* |
| 2566 | * alua_access_status |
| 2567 | */ |
| 2568 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_status( |
| 2569 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2570 | char *page) |
| 2571 | { |
| 2572 | return sprintf(page, "%s\n", |
| 2573 | core_alua_dump_status(tg_pt_gp->tg_pt_gp_alua_access_status)); |
| 2574 | } |
| 2575 | |
| 2576 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_status( |
| 2577 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2578 | const char *page, |
| 2579 | size_t count) |
| 2580 | { |
| 2581 | unsigned long tmp; |
| 2582 | int new_status, ret; |
| 2583 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2584 | if (!tg_pt_gp->tg_pt_gp_valid_id) { |
| 2585 | pr_err("Unable to do set ALUA access status on non" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2586 | " valid tg_pt_gp ID: %hu\n", |
| 2587 | tg_pt_gp->tg_pt_gp_valid_id); |
| 2588 | return -EINVAL; |
| 2589 | } |
| 2590 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2591 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2592 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2593 | pr_err("Unable to extract new ALUA access status" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2594 | " from %s\n", page); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2595 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2596 | } |
| 2597 | new_status = (int)tmp; |
| 2598 | |
| 2599 | if ((new_status != ALUA_STATUS_NONE) && |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2600 | (new_status != ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG) && |
| 2601 | (new_status != ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2602 | pr_err("Illegal ALUA access status: 0x%02x\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2603 | new_status); |
| 2604 | return -EINVAL; |
| 2605 | } |
| 2606 | |
| 2607 | tg_pt_gp->tg_pt_gp_alua_access_status = new_status; |
| 2608 | return count; |
| 2609 | } |
| 2610 | |
| 2611 | SE_DEV_ALUA_TG_PT_ATTR(alua_access_status, S_IRUGO | S_IWUSR); |
| 2612 | |
| 2613 | /* |
| 2614 | * alua_access_type |
| 2615 | */ |
| 2616 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_type( |
| 2617 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2618 | char *page) |
| 2619 | { |
| 2620 | return core_alua_show_access_type(tg_pt_gp, page); |
| 2621 | } |
| 2622 | |
| 2623 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_type( |
| 2624 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2625 | const char *page, |
| 2626 | size_t count) |
| 2627 | { |
| 2628 | return core_alua_store_access_type(tg_pt_gp, page, count); |
| 2629 | } |
| 2630 | |
| 2631 | SE_DEV_ALUA_TG_PT_ATTR(alua_access_type, S_IRUGO | S_IWUSR); |
| 2632 | |
| 2633 | /* |
Hannes Reinecke | 6be526c | 2013-11-19 09:07:50 +0100 | [diff] [blame] | 2634 | * alua_supported_states |
| 2635 | */ |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2636 | |
| 2637 | #define SE_DEV_ALUA_SUPPORT_STATE_SHOW(_name, _var, _bit) \ |
| 2638 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_support_##_name( \ |
| 2639 | struct t10_alua_tg_pt_gp *t, char *p) \ |
| 2640 | { \ |
| 2641 | return sprintf(p, "%d\n", !!(t->_var & _bit)); \ |
Hannes Reinecke | 6be526c | 2013-11-19 09:07:50 +0100 | [diff] [blame] | 2642 | } |
| 2643 | |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2644 | #define SE_DEV_ALUA_SUPPORT_STATE_STORE(_name, _var, _bit) \ |
| 2645 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_support_##_name(\ |
| 2646 | struct t10_alua_tg_pt_gp *t, const char *p, size_t c) \ |
| 2647 | { \ |
| 2648 | unsigned long tmp; \ |
| 2649 | int ret; \ |
| 2650 | \ |
| 2651 | if (!t->tg_pt_gp_valid_id) { \ |
| 2652 | pr_err("Unable to do set ##_name ALUA state on non" \ |
| 2653 | " valid tg_pt_gp ID: %hu\n", \ |
| 2654 | t->tg_pt_gp_valid_id); \ |
| 2655 | return -EINVAL; \ |
| 2656 | } \ |
| 2657 | \ |
| 2658 | ret = kstrtoul(p, 0, &tmp); \ |
| 2659 | if (ret < 0) { \ |
| 2660 | pr_err("Invalid value '%s', must be '0' or '1'\n", p); \ |
| 2661 | return -EINVAL; \ |
| 2662 | } \ |
| 2663 | if (tmp > 1) { \ |
| 2664 | pr_err("Invalid value '%ld', must be '0' or '1'\n", tmp); \ |
| 2665 | return -EINVAL; \ |
| 2666 | } \ |
Sebastian Herbszt | 1f0b030 | 2014-09-01 00:17:53 +0200 | [diff] [blame] | 2667 | if (tmp) \ |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2668 | t->_var |= _bit; \ |
| 2669 | else \ |
| 2670 | t->_var &= ~_bit; \ |
| 2671 | \ |
| 2672 | return c; \ |
Hannes Reinecke | 6be526c | 2013-11-19 09:07:50 +0100 | [diff] [blame] | 2673 | } |
| 2674 | |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2675 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(transitioning, |
| 2676 | tg_pt_gp_alua_supported_states, ALUA_T_SUP); |
| 2677 | SE_DEV_ALUA_SUPPORT_STATE_STORE(transitioning, |
| 2678 | tg_pt_gp_alua_supported_states, ALUA_T_SUP); |
| 2679 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_transitioning, S_IRUGO | S_IWUSR); |
| 2680 | |
| 2681 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(offline, |
| 2682 | tg_pt_gp_alua_supported_states, ALUA_O_SUP); |
| 2683 | SE_DEV_ALUA_SUPPORT_STATE_STORE(offline, |
| 2684 | tg_pt_gp_alua_supported_states, ALUA_O_SUP); |
| 2685 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_offline, S_IRUGO | S_IWUSR); |
| 2686 | |
| 2687 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(lba_dependent, |
| 2688 | tg_pt_gp_alua_supported_states, ALUA_LBD_SUP); |
| 2689 | SE_DEV_ALUA_SUPPORT_STATE_STORE(lba_dependent, |
| 2690 | tg_pt_gp_alua_supported_states, ALUA_LBD_SUP); |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 2691 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_lba_dependent, S_IRUGO); |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2692 | |
| 2693 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(unavailable, |
| 2694 | tg_pt_gp_alua_supported_states, ALUA_U_SUP); |
| 2695 | SE_DEV_ALUA_SUPPORT_STATE_STORE(unavailable, |
| 2696 | tg_pt_gp_alua_supported_states, ALUA_U_SUP); |
| 2697 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_unavailable, S_IRUGO | S_IWUSR); |
| 2698 | |
| 2699 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(standby, |
| 2700 | tg_pt_gp_alua_supported_states, ALUA_S_SUP); |
| 2701 | SE_DEV_ALUA_SUPPORT_STATE_STORE(standby, |
| 2702 | tg_pt_gp_alua_supported_states, ALUA_S_SUP); |
| 2703 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_standby, S_IRUGO | S_IWUSR); |
| 2704 | |
| 2705 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_optimized, |
| 2706 | tg_pt_gp_alua_supported_states, ALUA_AO_SUP); |
| 2707 | SE_DEV_ALUA_SUPPORT_STATE_STORE(active_optimized, |
| 2708 | tg_pt_gp_alua_supported_states, ALUA_AO_SUP); |
| 2709 | SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_optimized, S_IRUGO | S_IWUSR); |
| 2710 | |
| 2711 | SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_nonoptimized, |
| 2712 | tg_pt_gp_alua_supported_states, ALUA_AN_SUP); |
| 2713 | SE_DEV_ALUA_SUPPORT_STATE_STORE(active_nonoptimized, |
| 2714 | tg_pt_gp_alua_supported_states, ALUA_AN_SUP); |
| 2715 | 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] | 2716 | |
| 2717 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2718 | * alua_write_metadata |
| 2719 | */ |
| 2720 | static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_write_metadata( |
| 2721 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2722 | char *page) |
| 2723 | { |
| 2724 | return sprintf(page, "%d\n", tg_pt_gp->tg_pt_gp_write_metadata); |
| 2725 | } |
| 2726 | |
| 2727 | static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_write_metadata( |
| 2728 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2729 | const char *page, |
| 2730 | size_t count) |
| 2731 | { |
| 2732 | unsigned long tmp; |
| 2733 | int ret; |
| 2734 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2735 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2736 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2737 | pr_err("Unable to extract alua_write_metadata\n"); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2738 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | if ((tmp != 0) && (tmp != 1)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2742 | pr_err("Illegal value for alua_write_metadata:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2743 | " %lu\n", tmp); |
| 2744 | return -EINVAL; |
| 2745 | } |
| 2746 | tg_pt_gp->tg_pt_gp_write_metadata = (int)tmp; |
| 2747 | |
| 2748 | return count; |
| 2749 | } |
| 2750 | |
| 2751 | SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata, S_IRUGO | S_IWUSR); |
| 2752 | |
| 2753 | |
| 2754 | |
| 2755 | /* |
| 2756 | * nonop_delay_msecs |
| 2757 | */ |
| 2758 | static ssize_t target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs( |
| 2759 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2760 | char *page) |
| 2761 | { |
| 2762 | return core_alua_show_nonop_delay_msecs(tg_pt_gp, page); |
| 2763 | |
| 2764 | } |
| 2765 | |
| 2766 | static ssize_t target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs( |
| 2767 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2768 | const char *page, |
| 2769 | size_t count) |
| 2770 | { |
| 2771 | return core_alua_store_nonop_delay_msecs(tg_pt_gp, page, count); |
| 2772 | } |
| 2773 | |
| 2774 | SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs, S_IRUGO | S_IWUSR); |
| 2775 | |
| 2776 | /* |
| 2777 | * trans_delay_msecs |
| 2778 | */ |
| 2779 | static ssize_t target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs( |
| 2780 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2781 | char *page) |
| 2782 | { |
| 2783 | return core_alua_show_trans_delay_msecs(tg_pt_gp, page); |
| 2784 | } |
| 2785 | |
| 2786 | static ssize_t target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs( |
| 2787 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2788 | const char *page, |
| 2789 | size_t count) |
| 2790 | { |
| 2791 | return core_alua_store_trans_delay_msecs(tg_pt_gp, page, count); |
| 2792 | } |
| 2793 | |
| 2794 | SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs, S_IRUGO | S_IWUSR); |
| 2795 | |
| 2796 | /* |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2797 | * implicit_trans_secs |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2798 | */ |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2799 | 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] | 2800 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2801 | char *page) |
| 2802 | { |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2803 | return core_alua_show_implicit_trans_secs(tg_pt_gp, page); |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2804 | } |
| 2805 | |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2806 | 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] | 2807 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2808 | const char *page, |
| 2809 | size_t count) |
| 2810 | { |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2811 | return core_alua_store_implicit_trans_secs(tg_pt_gp, page, count); |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2812 | } |
| 2813 | |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2814 | 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] | 2815 | |
| 2816 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2817 | * preferred |
| 2818 | */ |
| 2819 | |
| 2820 | static ssize_t target_core_alua_tg_pt_gp_show_attr_preferred( |
| 2821 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2822 | char *page) |
| 2823 | { |
| 2824 | return core_alua_show_preferred_bit(tg_pt_gp, page); |
| 2825 | } |
| 2826 | |
| 2827 | static ssize_t target_core_alua_tg_pt_gp_store_attr_preferred( |
| 2828 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2829 | const char *page, |
| 2830 | size_t count) |
| 2831 | { |
| 2832 | return core_alua_store_preferred_bit(tg_pt_gp, page, count); |
| 2833 | } |
| 2834 | |
| 2835 | SE_DEV_ALUA_TG_PT_ATTR(preferred, S_IRUGO | S_IWUSR); |
| 2836 | |
| 2837 | /* |
| 2838 | * tg_pt_gp_id |
| 2839 | */ |
| 2840 | static ssize_t target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id( |
| 2841 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2842 | char *page) |
| 2843 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2844 | if (!tg_pt_gp->tg_pt_gp_valid_id) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2845 | return 0; |
| 2846 | |
| 2847 | return sprintf(page, "%hu\n", tg_pt_gp->tg_pt_gp_id); |
| 2848 | } |
| 2849 | |
| 2850 | static ssize_t target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id( |
| 2851 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2852 | const char *page, |
| 2853 | size_t count) |
| 2854 | { |
| 2855 | struct config_group *alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group; |
| 2856 | unsigned long tg_pt_gp_id; |
| 2857 | int ret; |
| 2858 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2859 | ret = kstrtoul(page, 0, &tg_pt_gp_id); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2860 | if (ret < 0) { |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2861 | pr_err("kstrtoul() returned %d for" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2862 | " tg_pt_gp_id\n", ret); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2863 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2864 | } |
| 2865 | if (tg_pt_gp_id > 0x0000ffff) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2866 | pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2867 | " 0x0000ffff\n", tg_pt_gp_id); |
| 2868 | return -EINVAL; |
| 2869 | } |
| 2870 | |
| 2871 | ret = core_alua_set_tg_pt_gp_id(tg_pt_gp, (u16)tg_pt_gp_id); |
| 2872 | if (ret < 0) |
| 2873 | return -EINVAL; |
| 2874 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2875 | pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: " |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2876 | "core/alua/tg_pt_gps/%s to ID: %hu\n", |
| 2877 | config_item_name(&alua_tg_pt_gp_cg->cg_item), |
| 2878 | tg_pt_gp->tg_pt_gp_id); |
| 2879 | |
| 2880 | return count; |
| 2881 | } |
| 2882 | |
| 2883 | SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id, S_IRUGO | S_IWUSR); |
| 2884 | |
| 2885 | /* |
| 2886 | * members |
| 2887 | */ |
| 2888 | static ssize_t target_core_alua_tg_pt_gp_show_attr_members( |
| 2889 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2890 | char *page) |
| 2891 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2892 | struct se_lun *lun; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2893 | ssize_t len = 0, cur_len; |
| 2894 | unsigned char buf[TG_PT_GROUP_NAME_BUF]; |
| 2895 | |
| 2896 | memset(buf, 0, TG_PT_GROUP_NAME_BUF); |
| 2897 | |
| 2898 | spin_lock(&tg_pt_gp->tg_pt_gp_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 2899 | list_for_each_entry(lun, &tg_pt_gp->tg_pt_gp_lun_list, |
| 2900 | lun_tg_pt_gp_link) { |
| 2901 | struct se_portal_group *tpg = lun->lun_tpg; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2902 | |
| 2903 | 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] | 2904 | "/%s\n", tpg->se_tpg_tfo->get_fabric_name(), |
| 2905 | tpg->se_tpg_tfo->tpg_get_wwn(tpg), |
| 2906 | tpg->se_tpg_tfo->tpg_get_tag(tpg), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2907 | config_item_name(&lun->lun_group.cg_item)); |
| 2908 | cur_len++; /* Extra byte for NULL terminator */ |
| 2909 | |
| 2910 | if ((cur_len + len) > PAGE_SIZE) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2911 | pr_warn("Ran out of lu_gp_show_attr" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2912 | "_members buffer\n"); |
| 2913 | break; |
| 2914 | } |
| 2915 | memcpy(page+len, buf, cur_len); |
| 2916 | len += cur_len; |
| 2917 | } |
| 2918 | spin_unlock(&tg_pt_gp->tg_pt_gp_lock); |
| 2919 | |
| 2920 | return len; |
| 2921 | } |
| 2922 | |
| 2923 | SE_DEV_ALUA_TG_PT_ATTR_RO(members); |
| 2924 | |
| 2925 | CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp, t10_alua_tg_pt_gp, |
| 2926 | tg_pt_gp_group); |
| 2927 | |
| 2928 | static struct configfs_attribute *target_core_alua_tg_pt_gp_attrs[] = { |
| 2929 | &target_core_alua_tg_pt_gp_alua_access_state.attr, |
| 2930 | &target_core_alua_tg_pt_gp_alua_access_status.attr, |
| 2931 | &target_core_alua_tg_pt_gp_alua_access_type.attr, |
Hannes Reinecke | b0a382c | 2013-11-19 09:07:51 +0100 | [diff] [blame] | 2932 | &target_core_alua_tg_pt_gp_alua_support_transitioning.attr, |
| 2933 | &target_core_alua_tg_pt_gp_alua_support_offline.attr, |
| 2934 | &target_core_alua_tg_pt_gp_alua_support_lba_dependent.attr, |
| 2935 | &target_core_alua_tg_pt_gp_alua_support_unavailable.attr, |
| 2936 | &target_core_alua_tg_pt_gp_alua_support_standby.attr, |
| 2937 | &target_core_alua_tg_pt_gp_alua_support_active_nonoptimized.attr, |
| 2938 | &target_core_alua_tg_pt_gp_alua_support_active_optimized.attr, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2939 | &target_core_alua_tg_pt_gp_alua_write_metadata.attr, |
| 2940 | &target_core_alua_tg_pt_gp_nonop_delay_msecs.attr, |
| 2941 | &target_core_alua_tg_pt_gp_trans_delay_msecs.attr, |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2942 | &target_core_alua_tg_pt_gp_implicit_trans_secs.attr, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2943 | &target_core_alua_tg_pt_gp_preferred.attr, |
| 2944 | &target_core_alua_tg_pt_gp_tg_pt_gp_id.attr, |
| 2945 | &target_core_alua_tg_pt_gp_members.attr, |
| 2946 | NULL, |
| 2947 | }; |
| 2948 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2949 | static void target_core_alua_tg_pt_gp_release(struct config_item *item) |
| 2950 | { |
| 2951 | struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item), |
| 2952 | struct t10_alua_tg_pt_gp, tg_pt_gp_group); |
| 2953 | |
| 2954 | core_alua_free_tg_pt_gp(tg_pt_gp); |
| 2955 | } |
| 2956 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2957 | static struct configfs_item_operations target_core_alua_tg_pt_gp_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 2958 | .release = target_core_alua_tg_pt_gp_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2959 | .show_attribute = target_core_alua_tg_pt_gp_attr_show, |
| 2960 | .store_attribute = target_core_alua_tg_pt_gp_attr_store, |
| 2961 | }; |
| 2962 | |
| 2963 | static struct config_item_type target_core_alua_tg_pt_gp_cit = { |
| 2964 | .ct_item_ops = &target_core_alua_tg_pt_gp_ops, |
| 2965 | .ct_attrs = target_core_alua_tg_pt_gp_attrs, |
| 2966 | .ct_owner = THIS_MODULE, |
| 2967 | }; |
| 2968 | |
| 2969 | /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */ |
| 2970 | |
Nicholas Bellinger | 72aca57 | 2014-11-27 15:06:23 -0800 | [diff] [blame] | 2971 | /* 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] | 2972 | |
| 2973 | static struct config_group *target_core_alua_create_tg_pt_gp( |
| 2974 | struct config_group *group, |
| 2975 | const char *name) |
| 2976 | { |
| 2977 | struct t10_alua *alua = container_of(group, struct t10_alua, |
| 2978 | alua_tg_pt_gps_group); |
| 2979 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2980 | struct config_group *alua_tg_pt_gp_cg = NULL; |
| 2981 | struct config_item *alua_tg_pt_gp_ci = NULL; |
| 2982 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2983 | 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] | 2984 | if (!tg_pt_gp) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2985 | return NULL; |
| 2986 | |
| 2987 | alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group; |
| 2988 | alua_tg_pt_gp_ci = &alua_tg_pt_gp_cg->cg_item; |
| 2989 | |
| 2990 | config_group_init_type_name(alua_tg_pt_gp_cg, name, |
| 2991 | &target_core_alua_tg_pt_gp_cit); |
| 2992 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2993 | pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2994 | " Group: alua/tg_pt_gps/%s\n", |
| 2995 | config_item_name(alua_tg_pt_gp_ci)); |
| 2996 | |
| 2997 | return alua_tg_pt_gp_cg; |
| 2998 | } |
| 2999 | |
| 3000 | static void target_core_alua_drop_tg_pt_gp( |
| 3001 | struct config_group *group, |
| 3002 | struct config_item *item) |
| 3003 | { |
| 3004 | struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item), |
| 3005 | struct t10_alua_tg_pt_gp, tg_pt_gp_group); |
| 3006 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3007 | pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3008 | " Group: alua/tg_pt_gps/%s, ID: %hu\n", |
| 3009 | config_item_name(item), tg_pt_gp->tg_pt_gp_id); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 3010 | /* |
| 3011 | * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release() |
| 3012 | * -> target_core_alua_tg_pt_gp_release(). |
| 3013 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3014 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3015 | } |
| 3016 | |
| 3017 | static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = { |
| 3018 | .make_group = &target_core_alua_create_tg_pt_gp, |
| 3019 | .drop_item = &target_core_alua_drop_tg_pt_gp, |
| 3020 | }; |
| 3021 | |
Nicholas Bellinger | 72aca57 | 2014-11-27 15:06:23 -0800 | [diff] [blame] | 3022 | 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] | 3023 | |
Nicholas Bellinger | 72aca57 | 2014-11-27 15:06:23 -0800 | [diff] [blame] | 3024 | /* 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] | 3025 | |
| 3026 | /* Start functions for struct config_item_type target_core_alua_cit */ |
| 3027 | |
| 3028 | /* |
| 3029 | * target_core_alua_cit is a ConfigFS group that lives under |
| 3030 | * /sys/kernel/config/target/core/alua. There are default groups |
| 3031 | * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to |
| 3032 | * target_core_alua_cit in target_core_init_configfs() below. |
| 3033 | */ |
| 3034 | static struct config_item_type target_core_alua_cit = { |
| 3035 | .ct_item_ops = NULL, |
| 3036 | .ct_attrs = NULL, |
| 3037 | .ct_owner = THIS_MODULE, |
| 3038 | }; |
| 3039 | |
| 3040 | /* End functions for struct config_item_type target_core_alua_cit */ |
| 3041 | |
Nicholas Bellinger | d23ab57 | 2014-11-27 15:09:32 -0800 | [diff] [blame] | 3042 | /* Start functions for struct config_item_type tb_dev_stat_cit */ |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 3043 | |
| 3044 | static struct config_group *target_core_stat_mkdir( |
| 3045 | struct config_group *group, |
| 3046 | const char *name) |
| 3047 | { |
| 3048 | return ERR_PTR(-ENOSYS); |
| 3049 | } |
| 3050 | |
| 3051 | static void target_core_stat_rmdir( |
| 3052 | struct config_group *group, |
| 3053 | struct config_item *item) |
| 3054 | { |
| 3055 | return; |
| 3056 | } |
| 3057 | |
| 3058 | static struct configfs_group_operations target_core_stat_group_ops = { |
| 3059 | .make_group = &target_core_stat_mkdir, |
| 3060 | .drop_item = &target_core_stat_rmdir, |
| 3061 | }; |
| 3062 | |
Nicholas Bellinger | d23ab57 | 2014-11-27 15:09:32 -0800 | [diff] [blame] | 3063 | TB_CIT_SETUP(dev_stat, NULL, &target_core_stat_group_ops, NULL); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 3064 | |
Nicholas Bellinger | d23ab57 | 2014-11-27 15:09:32 -0800 | [diff] [blame] | 3065 | /* End functions for struct config_item_type tb_dev_stat_cit */ |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 3066 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3067 | /* Start functions for struct config_item_type target_core_hba_cit */ |
| 3068 | |
| 3069 | static struct config_group *target_core_make_subdev( |
| 3070 | struct config_group *group, |
| 3071 | const char *name) |
| 3072 | { |
| 3073 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3074 | struct config_item *hba_ci = &group->cg_item; |
| 3075 | struct se_hba *hba = item_to_hba(hba_ci); |
Christoph Hellwig | 0a06d43 | 2015-05-10 18:14:56 +0200 | [diff] [blame] | 3076 | struct target_backend *tb = hba->backend; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3077 | struct se_device *dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3078 | struct config_group *dev_cg = NULL, *tg_pt_gp_cg = NULL; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 3079 | struct config_group *dev_stat_grp = NULL; |
| 3080 | int errno = -ENOMEM, ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3081 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 3082 | ret = mutex_lock_interruptible(&hba->hba_access_mutex); |
| 3083 | if (ret) |
| 3084 | return ERR_PTR(ret); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3085 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3086 | dev = target_alloc_device(hba, name); |
| 3087 | if (!dev) |
| 3088 | goto out_unlock; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3089 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3090 | dev_cg = &dev->dev_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3091 | |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 3092 | dev_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3093 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3094 | if (!dev_cg->default_groups) |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3095 | goto out_free_device; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3096 | |
Christoph Hellwig | 0a06d43 | 2015-05-10 18:14:56 +0200 | [diff] [blame] | 3097 | config_group_init_type_name(dev_cg, name, &tb->tb_dev_cit); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3098 | config_group_init_type_name(&dev->dev_attrib.da_group, "attrib", |
Christoph Hellwig | 0a06d43 | 2015-05-10 18:14:56 +0200 | [diff] [blame] | 3099 | &tb->tb_dev_attrib_cit); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3100 | config_group_init_type_name(&dev->dev_pr_group, "pr", |
Christoph Hellwig | 0a06d43 | 2015-05-10 18:14:56 +0200 | [diff] [blame] | 3101 | &tb->tb_dev_pr_cit); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3102 | config_group_init_type_name(&dev->t10_wwn.t10_wwn_group, "wwn", |
Christoph Hellwig | 0a06d43 | 2015-05-10 18:14:56 +0200 | [diff] [blame] | 3103 | &tb->tb_dev_wwn_cit); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3104 | 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] | 3105 | "alua", &tb->tb_dev_alua_tg_pt_gps_cit); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3106 | config_group_init_type_name(&dev->dev_stat_grps.stat_group, |
Christoph Hellwig | 0a06d43 | 2015-05-10 18:14:56 +0200 | [diff] [blame] | 3107 | "statistics", &tb->tb_dev_stat_cit); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 3108 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3109 | dev_cg->default_groups[0] = &dev->dev_attrib.da_group; |
| 3110 | dev_cg->default_groups[1] = &dev->dev_pr_group; |
| 3111 | dev_cg->default_groups[2] = &dev->t10_wwn.t10_wwn_group; |
| 3112 | dev_cg->default_groups[3] = &dev->t10_alua.alua_tg_pt_gps_group; |
| 3113 | dev_cg->default_groups[4] = &dev->dev_stat_grps.stat_group; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 3114 | dev_cg->default_groups[5] = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3115 | /* |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 3116 | * Add core/$HBA/$DEV/alua/default_tg_pt_gp |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3117 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3118 | 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] | 3119 | if (!tg_pt_gp) |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3120 | goto out_free_dev_cg_default_groups; |
| 3121 | dev->t10_alua.default_tg_pt_gp = tg_pt_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3122 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3123 | 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] | 3124 | tg_pt_gp_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3125 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3126 | if (!tg_pt_gp_cg->default_groups) { |
| 3127 | pr_err("Unable to allocate tg_pt_gp_cg->" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3128 | "default_groups\n"); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3129 | goto out_free_tg_pt_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | config_group_init_type_name(&tg_pt_gp->tg_pt_gp_group, |
| 3133 | "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit); |
| 3134 | tg_pt_gp_cg->default_groups[0] = &tg_pt_gp->tg_pt_gp_group; |
| 3135 | tg_pt_gp_cg->default_groups[1] = NULL; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 3136 | /* |
| 3137 | * Add core/$HBA/$DEV/statistics/ default groups |
| 3138 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3139 | dev_stat_grp = &dev->dev_stat_grps.stat_group; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 3140 | dev_stat_grp->default_groups = kmalloc(sizeof(struct config_group *) * 4, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 3141 | GFP_KERNEL); |
| 3142 | if (!dev_stat_grp->default_groups) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3143 | pr_err("Unable to allocate dev_stat_grp->default_groups\n"); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3144 | goto out_free_tg_pt_gp_cg_default_groups; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 3145 | } |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3146 | target_stat_setup_dev_default_groups(dev); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3147 | |
| 3148 | mutex_unlock(&hba->hba_access_mutex); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3149 | return dev_cg; |
| 3150 | |
| 3151 | out_free_tg_pt_gp_cg_default_groups: |
| 3152 | kfree(tg_pt_gp_cg->default_groups); |
| 3153 | out_free_tg_pt_gp: |
| 3154 | core_alua_free_tg_pt_gp(tg_pt_gp); |
| 3155 | out_free_dev_cg_default_groups: |
| 3156 | kfree(dev_cg->default_groups); |
| 3157 | out_free_device: |
| 3158 | target_free_device(dev); |
| 3159 | out_unlock: |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3160 | mutex_unlock(&hba->hba_access_mutex); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 3161 | return ERR_PTR(errno); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3162 | } |
| 3163 | |
| 3164 | static void target_core_drop_subdev( |
| 3165 | struct config_group *group, |
| 3166 | struct config_item *item) |
| 3167 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3168 | struct config_group *dev_cg = to_config_group(item); |
| 3169 | struct se_device *dev = |
| 3170 | container_of(dev_cg, struct se_device, dev_group); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3171 | struct se_hba *hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3172 | struct config_item *df_item; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3173 | struct config_group *tg_pt_gp_cg, *dev_stat_grp; |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 3174 | int i; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3175 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3176 | hba = item_to_hba(&dev->se_hba->hba_group.cg_item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3177 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 3178 | mutex_lock(&hba->hba_access_mutex); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3179 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3180 | dev_stat_grp = &dev->dev_stat_grps.stat_group; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 3181 | for (i = 0; dev_stat_grp->default_groups[i]; i++) { |
| 3182 | df_item = &dev_stat_grp->default_groups[i]->cg_item; |
| 3183 | dev_stat_grp->default_groups[i] = NULL; |
| 3184 | config_item_put(df_item); |
| 3185 | } |
| 3186 | kfree(dev_stat_grp->default_groups); |
| 3187 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3188 | tg_pt_gp_cg = &dev->t10_alua.alua_tg_pt_gps_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3189 | for (i = 0; tg_pt_gp_cg->default_groups[i]; i++) { |
| 3190 | df_item = &tg_pt_gp_cg->default_groups[i]->cg_item; |
| 3191 | tg_pt_gp_cg->default_groups[i] = NULL; |
| 3192 | config_item_put(df_item); |
| 3193 | } |
| 3194 | kfree(tg_pt_gp_cg->default_groups); |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 3195 | /* |
| 3196 | * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp |
| 3197 | * directly from target_core_alua_tg_pt_gp_release(). |
| 3198 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3199 | dev->t10_alua.default_tg_pt_gp = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3200 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3201 | for (i = 0; dev_cg->default_groups[i]; i++) { |
| 3202 | df_item = &dev_cg->default_groups[i]->cg_item; |
| 3203 | dev_cg->default_groups[i] = NULL; |
| 3204 | config_item_put(df_item); |
| 3205 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3206 | /* |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3207 | * se_dev is released from target_core_dev_item_ops->release() |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3208 | */ |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 3209 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3210 | mutex_unlock(&hba->hba_access_mutex); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3211 | } |
| 3212 | |
| 3213 | static struct configfs_group_operations target_core_hba_group_ops = { |
| 3214 | .make_group = target_core_make_subdev, |
| 3215 | .drop_item = target_core_drop_subdev, |
| 3216 | }; |
| 3217 | |
| 3218 | CONFIGFS_EATTR_STRUCT(target_core_hba, se_hba); |
| 3219 | #define SE_HBA_ATTR(_name, _mode) \ |
| 3220 | static struct target_core_hba_attribute \ |
| 3221 | target_core_hba_##_name = \ |
| 3222 | __CONFIGFS_EATTR(_name, _mode, \ |
| 3223 | target_core_hba_show_attr_##_name, \ |
| 3224 | target_core_hba_store_attr_##_name); |
| 3225 | |
| 3226 | #define SE_HBA_ATTR_RO(_name) \ |
| 3227 | static struct target_core_hba_attribute \ |
| 3228 | target_core_hba_##_name = \ |
| 3229 | __CONFIGFS_EATTR_RO(_name, \ |
| 3230 | target_core_hba_show_attr_##_name); |
| 3231 | |
| 3232 | static ssize_t target_core_hba_show_attr_hba_info( |
| 3233 | struct se_hba *hba, |
| 3234 | char *page) |
| 3235 | { |
| 3236 | return sprintf(page, "HBA Index: %d plugin: %s version: %s\n", |
Christoph Hellwig | 0a06d43 | 2015-05-10 18:14:56 +0200 | [diff] [blame] | 3237 | hba->hba_id, hba->backend->ops->name, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3238 | TARGET_CORE_CONFIGFS_VERSION); |
| 3239 | } |
| 3240 | |
| 3241 | SE_HBA_ATTR_RO(hba_info); |
| 3242 | |
| 3243 | static ssize_t target_core_hba_show_attr_hba_mode(struct se_hba *hba, |
| 3244 | char *page) |
| 3245 | { |
| 3246 | int hba_mode = 0; |
| 3247 | |
| 3248 | if (hba->hba_flags & HBA_FLAGS_PSCSI_MODE) |
| 3249 | hba_mode = 1; |
| 3250 | |
| 3251 | return sprintf(page, "%d\n", hba_mode); |
| 3252 | } |
| 3253 | |
| 3254 | static ssize_t target_core_hba_store_attr_hba_mode(struct se_hba *hba, |
| 3255 | const char *page, size_t count) |
| 3256 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3257 | unsigned long mode_flag; |
| 3258 | int ret; |
| 3259 | |
Christoph Hellwig | 0a06d43 | 2015-05-10 18:14:56 +0200 | [diff] [blame] | 3260 | if (hba->backend->ops->pmode_enable_hba == NULL) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3261 | return -EINVAL; |
| 3262 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 3263 | ret = kstrtoul(page, 0, &mode_flag); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3264 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3265 | pr_err("Unable to extract hba mode flag: %d\n", ret); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 3266 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3267 | } |
| 3268 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 3269 | if (hba->dev_count) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3270 | pr_err("Unable to set hba_mode with active devices\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3271 | return -EINVAL; |
| 3272 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3273 | |
Christoph Hellwig | 0a06d43 | 2015-05-10 18:14:56 +0200 | [diff] [blame] | 3274 | ret = hba->backend->ops->pmode_enable_hba(hba, mode_flag); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3275 | if (ret < 0) |
| 3276 | return -EINVAL; |
| 3277 | if (ret > 0) |
| 3278 | hba->hba_flags |= HBA_FLAGS_PSCSI_MODE; |
| 3279 | else if (ret == 0) |
| 3280 | hba->hba_flags &= ~HBA_FLAGS_PSCSI_MODE; |
| 3281 | |
| 3282 | return count; |
| 3283 | } |
| 3284 | |
| 3285 | SE_HBA_ATTR(hba_mode, S_IRUGO | S_IWUSR); |
| 3286 | |
| 3287 | CONFIGFS_EATTR_OPS(target_core_hba, se_hba, hba_group); |
| 3288 | |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 3289 | static void target_core_hba_release(struct config_item *item) |
| 3290 | { |
| 3291 | struct se_hba *hba = container_of(to_config_group(item), |
| 3292 | struct se_hba, hba_group); |
| 3293 | core_delete_hba(hba); |
| 3294 | } |
| 3295 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3296 | static struct configfs_attribute *target_core_hba_attrs[] = { |
| 3297 | &target_core_hba_hba_info.attr, |
| 3298 | &target_core_hba_hba_mode.attr, |
| 3299 | NULL, |
| 3300 | }; |
| 3301 | |
| 3302 | static struct configfs_item_operations target_core_hba_item_ops = { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 3303 | .release = target_core_hba_release, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3304 | .show_attribute = target_core_hba_attr_show, |
| 3305 | .store_attribute = target_core_hba_attr_store, |
| 3306 | }; |
| 3307 | |
| 3308 | static struct config_item_type target_core_hba_cit = { |
| 3309 | .ct_item_ops = &target_core_hba_item_ops, |
| 3310 | .ct_group_ops = &target_core_hba_group_ops, |
| 3311 | .ct_attrs = target_core_hba_attrs, |
| 3312 | .ct_owner = THIS_MODULE, |
| 3313 | }; |
| 3314 | |
| 3315 | static struct config_group *target_core_call_addhbatotarget( |
| 3316 | struct config_group *group, |
| 3317 | const char *name) |
| 3318 | { |
| 3319 | char *se_plugin_str, *str, *str2; |
| 3320 | struct se_hba *hba; |
| 3321 | char buf[TARGET_CORE_NAME_MAX_LEN]; |
| 3322 | unsigned long plugin_dep_id = 0; |
| 3323 | int ret; |
| 3324 | |
| 3325 | memset(buf, 0, TARGET_CORE_NAME_MAX_LEN); |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 3326 | if (strlen(name) >= TARGET_CORE_NAME_MAX_LEN) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3327 | pr_err("Passed *name strlen(): %d exceeds" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3328 | " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name), |
| 3329 | TARGET_CORE_NAME_MAX_LEN); |
| 3330 | return ERR_PTR(-ENAMETOOLONG); |
| 3331 | } |
| 3332 | snprintf(buf, TARGET_CORE_NAME_MAX_LEN, "%s", name); |
| 3333 | |
| 3334 | str = strstr(buf, "_"); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3335 | if (!str) { |
| 3336 | pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3337 | return ERR_PTR(-EINVAL); |
| 3338 | } |
| 3339 | se_plugin_str = buf; |
| 3340 | /* |
| 3341 | * Special case for subsystem plugins that have "_" in their names. |
| 3342 | * Namely rd_direct and rd_mcp.. |
| 3343 | */ |
| 3344 | str2 = strstr(str+1, "_"); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3345 | if (str2) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3346 | *str2 = '\0'; /* Terminate for *se_plugin_str */ |
| 3347 | str2++; /* Skip to start of plugin dependent ID */ |
| 3348 | str = str2; |
| 3349 | } else { |
| 3350 | *str = '\0'; /* Terminate for *se_plugin_str */ |
| 3351 | str++; /* Skip to start of plugin dependent ID */ |
| 3352 | } |
| 3353 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 3354 | ret = kstrtoul(str, 0, &plugin_dep_id); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3355 | if (ret < 0) { |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 3356 | pr_err("kstrtoul() returned %d for" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3357 | " plugin_dep_id\n", ret); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 3358 | return ERR_PTR(ret); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3359 | } |
| 3360 | /* |
| 3361 | * Load up TCM subsystem plugins if they have not already been loaded. |
| 3362 | */ |
Nicholas Bellinger | dbc5623 | 2011-10-22 01:03:54 -0700 | [diff] [blame] | 3363 | transport_subsystem_check_init(); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3364 | |
| 3365 | hba = core_alloc_hba(se_plugin_str, plugin_dep_id, 0); |
| 3366 | if (IS_ERR(hba)) |
| 3367 | return ERR_CAST(hba); |
| 3368 | |
| 3369 | config_group_init_type_name(&hba->hba_group, name, |
| 3370 | &target_core_hba_cit); |
| 3371 | |
| 3372 | return &hba->hba_group; |
| 3373 | } |
| 3374 | |
| 3375 | static void target_core_call_delhbafromtarget( |
| 3376 | struct config_group *group, |
| 3377 | struct config_item *item) |
| 3378 | { |
Nicholas Bellinger | 1f6fe7c | 2011-02-09 15:34:54 -0800 | [diff] [blame] | 3379 | /* |
| 3380 | * core_delete_hba() is called from target_core_hba_item_ops->release() |
| 3381 | * -> target_core_hba_release() |
| 3382 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3383 | config_item_put(item); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | static struct configfs_group_operations target_core_group_ops = { |
| 3387 | .make_group = target_core_call_addhbatotarget, |
| 3388 | .drop_item = target_core_call_delhbafromtarget, |
| 3389 | }; |
| 3390 | |
| 3391 | static struct config_item_type target_core_cit = { |
| 3392 | .ct_item_ops = NULL, |
| 3393 | .ct_group_ops = &target_core_group_ops, |
| 3394 | .ct_attrs = NULL, |
| 3395 | .ct_owner = THIS_MODULE, |
| 3396 | }; |
| 3397 | |
| 3398 | /* Stop functions for struct config_item_type target_core_hba_cit */ |
| 3399 | |
Christoph Hellwig | 0a06d43 | 2015-05-10 18:14:56 +0200 | [diff] [blame] | 3400 | void target_setup_backend_cits(struct target_backend *tb) |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 3401 | { |
Christoph Hellwig | 0a06d43 | 2015-05-10 18:14:56 +0200 | [diff] [blame] | 3402 | target_core_setup_dev_cit(tb); |
| 3403 | target_core_setup_dev_attrib_cit(tb); |
| 3404 | target_core_setup_dev_pr_cit(tb); |
| 3405 | target_core_setup_dev_wwn_cit(tb); |
| 3406 | target_core_setup_dev_alua_tg_pt_gps_cit(tb); |
| 3407 | target_core_setup_dev_stat_cit(tb); |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 3408 | } |
Nicholas Bellinger | 73112ed | 2014-11-27 13:59:20 -0800 | [diff] [blame] | 3409 | |
Axel Lin | 54550fa | 2011-03-14 04:06:09 -0700 | [diff] [blame] | 3410 | static int __init target_core_init_configfs(void) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3411 | { |
| 3412 | struct config_group *target_cg, *hba_cg = NULL, *alua_cg = NULL; |
| 3413 | struct config_group *lu_gp_cg = NULL; |
Christoph Hellwig | d588cf8 | 2015-05-03 08:50:52 +0200 | [diff] [blame] | 3414 | struct configfs_subsystem *subsys = &target_core_fabrics; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3415 | struct t10_alua_lu_gp *lu_gp; |
| 3416 | int ret; |
| 3417 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3418 | pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3419 | " Engine: %s on %s/%s on "UTS_RELEASE"\n", |
| 3420 | TARGET_CORE_VERSION, utsname()->sysname, utsname()->machine); |
| 3421 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3422 | config_group_init(&subsys->su_group); |
| 3423 | mutex_init(&subsys->su_mutex); |
| 3424 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3425 | ret = init_se_kmem_caches(); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3426 | if (ret < 0) |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3427 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3428 | /* |
| 3429 | * Create $CONFIGFS/target/core default group for HBA <-> Storage Object |
| 3430 | * and ALUA Logical Unit Group and Target Port Group infrastructure. |
| 3431 | */ |
| 3432 | target_cg = &subsys->su_group; |
Andy Grover | ab6dae8 | 2013-12-09 14:27:36 -0800 | [diff] [blame] | 3433 | target_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3434 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3435 | if (!target_cg->default_groups) { |
| 3436 | pr_err("Unable to allocate target_cg->default_groups\n"); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 3437 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3438 | goto out_global; |
| 3439 | } |
| 3440 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3441 | config_group_init_type_name(&target_core_hbagroup, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3442 | "core", &target_core_cit); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3443 | target_cg->default_groups[0] = &target_core_hbagroup; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3444 | target_cg->default_groups[1] = NULL; |
| 3445 | /* |
| 3446 | * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/ |
| 3447 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3448 | hba_cg = &target_core_hbagroup; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 3449 | hba_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3450 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3451 | if (!hba_cg->default_groups) { |
| 3452 | pr_err("Unable to allocate hba_cg->default_groups\n"); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 3453 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3454 | goto out_global; |
| 3455 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3456 | config_group_init_type_name(&alua_group, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3457 | "alua", &target_core_alua_cit); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3458 | hba_cg->default_groups[0] = &alua_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3459 | hba_cg->default_groups[1] = NULL; |
| 3460 | /* |
| 3461 | * Add ALUA Logical Unit Group and Target Port Group ConfigFS |
| 3462 | * groups under /sys/kernel/config/target/core/alua/ |
| 3463 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3464 | alua_cg = &alua_group; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 3465 | alua_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3466 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3467 | if (!alua_cg->default_groups) { |
| 3468 | pr_err("Unable to allocate alua_cg->default_groups\n"); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 3469 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3470 | goto out_global; |
| 3471 | } |
| 3472 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3473 | config_group_init_type_name(&alua_lu_gps_group, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3474 | "lu_gps", &target_core_alua_lu_gps_cit); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3475 | alua_cg->default_groups[0] = &alua_lu_gps_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3476 | alua_cg->default_groups[1] = NULL; |
| 3477 | /* |
| 3478 | * Add core/alua/lu_gps/default_lu_gp |
| 3479 | */ |
| 3480 | lu_gp = core_alua_allocate_lu_gp("default_lu_gp", 1); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 3481 | if (IS_ERR(lu_gp)) { |
| 3482 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3483 | goto out_global; |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 3484 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3485 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3486 | lu_gp_cg = &alua_lu_gps_group; |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 3487 | lu_gp_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3488 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3489 | if (!lu_gp_cg->default_groups) { |
| 3490 | pr_err("Unable to allocate lu_gp_cg->default_groups\n"); |
Peter Senna Tschudin | 37bb789 | 2012-09-17 20:05:33 +0200 | [diff] [blame] | 3491 | ret = -ENOMEM; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3492 | goto out_global; |
| 3493 | } |
| 3494 | |
| 3495 | config_group_init_type_name(&lu_gp->lu_gp_group, "default_lu_gp", |
| 3496 | &target_core_alua_lu_gp_cit); |
| 3497 | lu_gp_cg->default_groups[0] = &lu_gp->lu_gp_group; |
| 3498 | lu_gp_cg->default_groups[1] = NULL; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3499 | default_lu_gp = lu_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3500 | /* |
| 3501 | * Register the target_core_mod subsystem with configfs. |
| 3502 | */ |
| 3503 | ret = configfs_register_subsystem(subsys); |
| 3504 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3505 | pr_err("Error %d while registering subsystem %s\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3506 | ret, subsys->su_group.cg_item.ci_namebuf); |
| 3507 | goto out_global; |
| 3508 | } |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3509 | pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3510 | " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION" on %s/%s" |
| 3511 | " on "UTS_RELEASE"\n", utsname()->sysname, utsname()->machine); |
| 3512 | /* |
| 3513 | * Register built-in RAMDISK subsystem logic for virtual LUN 0 |
| 3514 | */ |
| 3515 | ret = rd_module_init(); |
| 3516 | if (ret < 0) |
| 3517 | goto out; |
| 3518 | |
Roland Dreier | 0d0f9df | 2012-10-31 09:16:44 -0700 | [diff] [blame] | 3519 | ret = core_dev_setup_virtual_lun0(); |
| 3520 | if (ret < 0) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3521 | goto out; |
| 3522 | |
Nicholas Bellinger | f99715a | 2013-08-22 12:48:53 -0700 | [diff] [blame] | 3523 | ret = target_xcopy_setup_pt(); |
| 3524 | if (ret < 0) |
| 3525 | goto out; |
| 3526 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3527 | return 0; |
| 3528 | |
| 3529 | out: |
| 3530 | configfs_unregister_subsystem(subsys); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3531 | core_dev_release_virtual_lun0(); |
| 3532 | rd_module_exit(); |
| 3533 | out_global: |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3534 | if (default_lu_gp) { |
| 3535 | core_alua_free_lu_gp(default_lu_gp); |
| 3536 | default_lu_gp = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3537 | } |
| 3538 | if (lu_gp_cg) |
| 3539 | kfree(lu_gp_cg->default_groups); |
| 3540 | if (alua_cg) |
| 3541 | kfree(alua_cg->default_groups); |
| 3542 | if (hba_cg) |
| 3543 | kfree(hba_cg->default_groups); |
| 3544 | kfree(target_cg->default_groups); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3545 | release_se_kmem_caches(); |
| 3546 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3547 | } |
| 3548 | |
Axel Lin | 54550fa | 2011-03-14 04:06:09 -0700 | [diff] [blame] | 3549 | static void __exit target_core_exit_configfs(void) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3550 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3551 | struct config_group *hba_cg, *alua_cg, *lu_gp_cg; |
| 3552 | struct config_item *item; |
| 3553 | int i; |
| 3554 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3555 | lu_gp_cg = &alua_lu_gps_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3556 | for (i = 0; lu_gp_cg->default_groups[i]; i++) { |
| 3557 | item = &lu_gp_cg->default_groups[i]->cg_item; |
| 3558 | lu_gp_cg->default_groups[i] = NULL; |
| 3559 | config_item_put(item); |
| 3560 | } |
| 3561 | kfree(lu_gp_cg->default_groups); |
Nicholas Bellinger | 7c2bf6e | 2011-02-09 15:34:53 -0800 | [diff] [blame] | 3562 | lu_gp_cg->default_groups = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3563 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3564 | alua_cg = &alua_group; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3565 | for (i = 0; alua_cg->default_groups[i]; i++) { |
| 3566 | item = &alua_cg->default_groups[i]->cg_item; |
| 3567 | alua_cg->default_groups[i] = NULL; |
| 3568 | config_item_put(item); |
| 3569 | } |
| 3570 | kfree(alua_cg->default_groups); |
Nicholas Bellinger | 7c2bf6e | 2011-02-09 15:34:53 -0800 | [diff] [blame] | 3571 | alua_cg->default_groups = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3572 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3573 | hba_cg = &target_core_hbagroup; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3574 | for (i = 0; hba_cg->default_groups[i]; i++) { |
| 3575 | item = &hba_cg->default_groups[i]->cg_item; |
| 3576 | hba_cg->default_groups[i] = NULL; |
| 3577 | config_item_put(item); |
| 3578 | } |
| 3579 | kfree(hba_cg->default_groups); |
Nicholas Bellinger | 7c2bf6e | 2011-02-09 15:34:53 -0800 | [diff] [blame] | 3580 | hba_cg->default_groups = NULL; |
| 3581 | /* |
| 3582 | * We expect subsys->su_group.default_groups to be released |
| 3583 | * by configfs subsystem provider logic.. |
| 3584 | */ |
Christoph Hellwig | d588cf8 | 2015-05-03 08:50:52 +0200 | [diff] [blame] | 3585 | configfs_unregister_subsystem(&target_core_fabrics); |
| 3586 | kfree(target_core_fabrics.su_group.default_groups); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3587 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3588 | core_alua_free_lu_gp(default_lu_gp); |
| 3589 | default_lu_gp = NULL; |
Nicholas Bellinger | 7c2bf6e | 2011-02-09 15:34:53 -0800 | [diff] [blame] | 3590 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 3591 | pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3592 | " Infrastructure\n"); |
| 3593 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3594 | core_dev_release_virtual_lun0(); |
| 3595 | rd_module_exit(); |
Nicholas Bellinger | f99715a | 2013-08-22 12:48:53 -0700 | [diff] [blame] | 3596 | target_xcopy_release_pt(); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 3597 | release_se_kmem_caches(); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 3598 | } |
| 3599 | |
| 3600 | MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS"); |
| 3601 | MODULE_AUTHOR("nab@Linux-iSCSI.org"); |
| 3602 | MODULE_LICENSE("GPL"); |
| 3603 | |
| 3604 | module_init(target_core_init_configfs); |
| 3605 | module_exit(target_core_exit_configfs); |