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