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