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