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