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