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