Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * This file contains the configfs implementation for iSCSI Target mode |
| 3 | * from the LIO-Target Project. |
| 4 | * |
| 5 | * \u00a9 Copyright 2007-2011 RisingTide Systems LLC. |
| 6 | * |
| 7 | * Licensed to the Linux Foundation under the General Public License (GPL) version 2. |
| 8 | * |
| 9 | * Author: Nicholas A. Bellinger <nab@linux-iscsi.org> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | #include <linux/configfs.h> |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 23 | #include <linux/ctype.h> |
Paul Gortmaker | c53181a | 2011-08-30 18:16:43 -0400 | [diff] [blame] | 24 | #include <linux/export.h> |
Stephen Rothwell | c3bc93d | 2012-01-23 11:39:49 +1100 | [diff] [blame] | 25 | #include <linux/inet.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 26 | #include <target/target_core_base.h> |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 27 | #include <target/target_core_fabric.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 28 | #include <target/target_core_fabric_configfs.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 29 | #include <target/target_core_configfs.h> |
| 30 | #include <target/configfs_macros.h> |
Nicholas Bellinger | 2ec5a8c | 2013-03-20 15:29:15 -0700 | [diff] [blame] | 31 | #include <target/iscsi/iscsi_transport.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 32 | |
| 33 | #include "iscsi_target_core.h" |
| 34 | #include "iscsi_target_parameters.h" |
| 35 | #include "iscsi_target_device.h" |
| 36 | #include "iscsi_target_erl0.h" |
| 37 | #include "iscsi_target_nodeattrib.h" |
| 38 | #include "iscsi_target_tpg.h" |
| 39 | #include "iscsi_target_util.h" |
| 40 | #include "iscsi_target.h" |
| 41 | #include "iscsi_target_stat.h" |
| 42 | #include "iscsi_target_configfs.h" |
| 43 | |
| 44 | struct target_fabric_configfs *lio_target_fabric_configfs; |
| 45 | |
| 46 | struct lio_target_configfs_attribute { |
| 47 | struct configfs_attribute attr; |
| 48 | ssize_t (*show)(void *, char *); |
| 49 | ssize_t (*store)(void *, const char *, size_t); |
| 50 | }; |
| 51 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 52 | /* Start items for lio_target_portal_cit */ |
| 53 | |
| 54 | static ssize_t lio_target_np_show_sctp( |
| 55 | struct se_tpg_np *se_tpg_np, |
| 56 | char *page) |
| 57 | { |
| 58 | struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, |
| 59 | struct iscsi_tpg_np, se_tpg_np); |
| 60 | struct iscsi_tpg_np *tpg_np_sctp; |
| 61 | ssize_t rb; |
| 62 | |
| 63 | tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP); |
| 64 | if (tpg_np_sctp) |
| 65 | rb = sprintf(page, "1\n"); |
| 66 | else |
| 67 | rb = sprintf(page, "0\n"); |
| 68 | |
| 69 | return rb; |
| 70 | } |
| 71 | |
| 72 | static ssize_t lio_target_np_store_sctp( |
| 73 | struct se_tpg_np *se_tpg_np, |
| 74 | const char *page, |
| 75 | size_t count) |
| 76 | { |
| 77 | struct iscsi_np *np; |
| 78 | struct iscsi_portal_group *tpg; |
| 79 | struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, |
| 80 | struct iscsi_tpg_np, se_tpg_np); |
| 81 | struct iscsi_tpg_np *tpg_np_sctp = NULL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 82 | u32 op; |
| 83 | int ret; |
| 84 | |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 85 | ret = kstrtou32(page, 0, &op); |
| 86 | if (ret) |
| 87 | return ret; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 88 | if ((op != 1) && (op != 0)) { |
| 89 | pr_err("Illegal value for tpg_enable: %u\n", op); |
| 90 | return -EINVAL; |
| 91 | } |
| 92 | np = tpg_np->tpg_np; |
| 93 | if (!np) { |
| 94 | pr_err("Unable to locate struct iscsi_np from" |
| 95 | " struct iscsi_tpg_np\n"); |
| 96 | return -EINVAL; |
| 97 | } |
| 98 | |
| 99 | tpg = tpg_np->tpg; |
| 100 | if (iscsit_get_tpg(tpg) < 0) |
| 101 | return -EINVAL; |
| 102 | |
| 103 | if (op) { |
| 104 | /* |
| 105 | * Use existing np->np_sockaddr for SCTP network portal reference |
| 106 | */ |
| 107 | tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, |
| 108 | np->np_ip, tpg_np, ISCSI_SCTP_TCP); |
| 109 | if (!tpg_np_sctp || IS_ERR(tpg_np_sctp)) |
| 110 | goto out; |
| 111 | } else { |
| 112 | tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP); |
| 113 | if (!tpg_np_sctp) |
| 114 | goto out; |
| 115 | |
| 116 | ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp); |
| 117 | if (ret < 0) |
| 118 | goto out; |
| 119 | } |
| 120 | |
| 121 | iscsit_put_tpg(tpg); |
| 122 | return count; |
| 123 | out: |
| 124 | iscsit_put_tpg(tpg); |
| 125 | return -EINVAL; |
| 126 | } |
| 127 | |
| 128 | TF_NP_BASE_ATTR(lio_target, sctp, S_IRUGO | S_IWUSR); |
| 129 | |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 130 | static ssize_t lio_target_np_show_iser( |
| 131 | struct se_tpg_np *se_tpg_np, |
| 132 | char *page) |
| 133 | { |
| 134 | struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, |
| 135 | struct iscsi_tpg_np, se_tpg_np); |
| 136 | struct iscsi_tpg_np *tpg_np_iser; |
| 137 | ssize_t rb; |
| 138 | |
| 139 | tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND); |
| 140 | if (tpg_np_iser) |
| 141 | rb = sprintf(page, "1\n"); |
| 142 | else |
| 143 | rb = sprintf(page, "0\n"); |
| 144 | |
| 145 | return rb; |
| 146 | } |
| 147 | |
| 148 | static ssize_t lio_target_np_store_iser( |
| 149 | struct se_tpg_np *se_tpg_np, |
| 150 | const char *page, |
| 151 | size_t count) |
| 152 | { |
| 153 | struct iscsi_np *np; |
| 154 | struct iscsi_portal_group *tpg; |
| 155 | struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, |
| 156 | struct iscsi_tpg_np, se_tpg_np); |
| 157 | struct iscsi_tpg_np *tpg_np_iser = NULL; |
| 158 | char *endptr; |
| 159 | u32 op; |
| 160 | int rc; |
| 161 | |
| 162 | op = simple_strtoul(page, &endptr, 0); |
| 163 | if ((op != 1) && (op != 0)) { |
| 164 | pr_err("Illegal value for tpg_enable: %u\n", op); |
| 165 | return -EINVAL; |
| 166 | } |
| 167 | np = tpg_np->tpg_np; |
| 168 | if (!np) { |
| 169 | pr_err("Unable to locate struct iscsi_np from" |
| 170 | " struct iscsi_tpg_np\n"); |
| 171 | return -EINVAL; |
| 172 | } |
| 173 | |
| 174 | tpg = tpg_np->tpg; |
| 175 | if (iscsit_get_tpg(tpg) < 0) |
| 176 | return -EINVAL; |
| 177 | |
| 178 | if (op) { |
| 179 | int rc = request_module("ib_isert"); |
| 180 | if (rc != 0) |
| 181 | pr_warn("Unable to request_module for ib_isert\n"); |
| 182 | |
| 183 | tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, |
| 184 | np->np_ip, tpg_np, ISCSI_INFINIBAND); |
| 185 | if (!tpg_np_iser || IS_ERR(tpg_np_iser)) |
| 186 | goto out; |
| 187 | } else { |
| 188 | tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND); |
| 189 | if (!tpg_np_iser) |
| 190 | goto out; |
| 191 | |
| 192 | rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser); |
| 193 | if (rc < 0) |
| 194 | goto out; |
| 195 | } |
| 196 | |
| 197 | printk("lio_target_np_store_iser() done, op: %d\n", op); |
| 198 | |
| 199 | iscsit_put_tpg(tpg); |
| 200 | return count; |
| 201 | out: |
| 202 | iscsit_put_tpg(tpg); |
| 203 | return -EINVAL; |
| 204 | } |
| 205 | |
| 206 | TF_NP_BASE_ATTR(lio_target, iser, S_IRUGO | S_IWUSR); |
| 207 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 208 | static struct configfs_attribute *lio_target_portal_attrs[] = { |
| 209 | &lio_target_np_sctp.attr, |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 210 | &lio_target_np_iser.attr, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 211 | NULL, |
| 212 | }; |
| 213 | |
| 214 | /* Stop items for lio_target_portal_cit */ |
| 215 | |
| 216 | /* Start items for lio_target_np_cit */ |
| 217 | |
| 218 | #define MAX_PORTAL_LEN 256 |
| 219 | |
Christoph Hellwig | fceb5bc | 2012-09-26 08:00:36 -0400 | [diff] [blame] | 220 | static struct se_tpg_np *lio_target_call_addnptotpg( |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 221 | struct se_portal_group *se_tpg, |
| 222 | struct config_group *group, |
| 223 | const char *name) |
| 224 | { |
| 225 | struct iscsi_portal_group *tpg; |
| 226 | struct iscsi_tpg_np *tpg_np; |
| 227 | char *str, *str2, *ip_str, *port_str; |
| 228 | struct __kernel_sockaddr_storage sockaddr; |
| 229 | struct sockaddr_in *sock_in; |
| 230 | struct sockaddr_in6 *sock_in6; |
| 231 | unsigned long port; |
| 232 | int ret; |
| 233 | char buf[MAX_PORTAL_LEN + 1]; |
| 234 | |
| 235 | if (strlen(name) > MAX_PORTAL_LEN) { |
| 236 | pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n", |
| 237 | (int)strlen(name), MAX_PORTAL_LEN); |
| 238 | return ERR_PTR(-EOVERFLOW); |
| 239 | } |
| 240 | memset(buf, 0, MAX_PORTAL_LEN + 1); |
Nicholas Bellinger | 7bbb654 | 2011-07-27 12:37:03 -0700 | [diff] [blame] | 241 | snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 242 | |
| 243 | memset(&sockaddr, 0, sizeof(struct __kernel_sockaddr_storage)); |
| 244 | |
| 245 | str = strstr(buf, "["); |
| 246 | if (str) { |
| 247 | const char *end; |
| 248 | |
| 249 | str2 = strstr(str, "]"); |
| 250 | if (!str2) { |
| 251 | pr_err("Unable to locate trailing \"]\"" |
| 252 | " in IPv6 iSCSI network portal address\n"); |
| 253 | return ERR_PTR(-EINVAL); |
| 254 | } |
| 255 | str++; /* Skip over leading "[" */ |
| 256 | *str2 = '\0'; /* Terminate the IPv6 address */ |
| 257 | str2++; /* Skip over the "]" */ |
| 258 | port_str = strstr(str2, ":"); |
| 259 | if (!port_str) { |
| 260 | pr_err("Unable to locate \":port\"" |
| 261 | " in IPv6 iSCSI network portal address\n"); |
| 262 | return ERR_PTR(-EINVAL); |
| 263 | } |
| 264 | *port_str = '\0'; /* Terminate string for IP */ |
| 265 | port_str++; /* Skip over ":" */ |
| 266 | |
| 267 | ret = strict_strtoul(port_str, 0, &port); |
| 268 | if (ret < 0) { |
| 269 | pr_err("strict_strtoul() failed for port_str: %d\n", ret); |
| 270 | return ERR_PTR(ret); |
| 271 | } |
| 272 | sock_in6 = (struct sockaddr_in6 *)&sockaddr; |
| 273 | sock_in6->sin6_family = AF_INET6; |
| 274 | sock_in6->sin6_port = htons((unsigned short)port); |
| 275 | ret = in6_pton(str, IPV6_ADDRESS_SPACE, |
| 276 | (void *)&sock_in6->sin6_addr.in6_u, -1, &end); |
| 277 | if (ret <= 0) { |
| 278 | pr_err("in6_pton returned: %d\n", ret); |
| 279 | return ERR_PTR(-EINVAL); |
| 280 | } |
| 281 | } else { |
| 282 | str = ip_str = &buf[0]; |
| 283 | port_str = strstr(ip_str, ":"); |
| 284 | if (!port_str) { |
| 285 | pr_err("Unable to locate \":port\"" |
| 286 | " in IPv4 iSCSI network portal address\n"); |
| 287 | return ERR_PTR(-EINVAL); |
| 288 | } |
| 289 | *port_str = '\0'; /* Terminate string for IP */ |
| 290 | port_str++; /* Skip over ":" */ |
| 291 | |
| 292 | ret = strict_strtoul(port_str, 0, &port); |
| 293 | if (ret < 0) { |
| 294 | pr_err("strict_strtoul() failed for port_str: %d\n", ret); |
| 295 | return ERR_PTR(ret); |
| 296 | } |
| 297 | sock_in = (struct sockaddr_in *)&sockaddr; |
| 298 | sock_in->sin_family = AF_INET; |
| 299 | sock_in->sin_port = htons((unsigned short)port); |
| 300 | sock_in->sin_addr.s_addr = in_aton(ip_str); |
| 301 | } |
| 302 | tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); |
| 303 | ret = iscsit_get_tpg(tpg); |
| 304 | if (ret < 0) |
| 305 | return ERR_PTR(-EINVAL); |
| 306 | |
| 307 | pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu" |
| 308 | " PORTAL: %s\n", |
| 309 | config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), |
| 310 | tpg->tpgt, name); |
| 311 | /* |
| 312 | * Assume ISCSI_TCP by default. Other network portals for other |
| 313 | * iSCSI fabrics: |
| 314 | * |
| 315 | * Traditional iSCSI over SCTP (initial support) |
| 316 | * iSER/TCP (TODO, hardware available) |
| 317 | * iSER/SCTP (TODO, software emulation with osc-iwarp) |
| 318 | * iSER/IB (TODO, hardware available) |
| 319 | * |
Masanari Iida | 2087969 | 2012-08-27 22:46:00 +0900 | [diff] [blame] | 320 | * can be enabled with attributes under |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 321 | * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/ |
| 322 | * |
| 323 | */ |
| 324 | tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, str, NULL, |
| 325 | ISCSI_TCP); |
| 326 | if (IS_ERR(tpg_np)) { |
| 327 | iscsit_put_tpg(tpg); |
Thomas Meyer | e1750ba | 2011-08-01 23:58:18 +0200 | [diff] [blame] | 328 | return ERR_CAST(tpg_np); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 329 | } |
| 330 | pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n"); |
| 331 | |
| 332 | iscsit_put_tpg(tpg); |
| 333 | return &tpg_np->se_tpg_np; |
| 334 | } |
| 335 | |
| 336 | static void lio_target_call_delnpfromtpg( |
| 337 | struct se_tpg_np *se_tpg_np) |
| 338 | { |
| 339 | struct iscsi_portal_group *tpg; |
| 340 | struct iscsi_tpg_np *tpg_np; |
| 341 | struct se_portal_group *se_tpg; |
| 342 | int ret; |
| 343 | |
| 344 | tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np); |
| 345 | tpg = tpg_np->tpg; |
| 346 | ret = iscsit_get_tpg(tpg); |
| 347 | if (ret < 0) |
| 348 | return; |
| 349 | |
| 350 | se_tpg = &tpg->tpg_se_tpg; |
| 351 | pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu" |
| 352 | " PORTAL: %s:%hu\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), |
| 353 | tpg->tpgt, tpg_np->tpg_np->np_ip, tpg_np->tpg_np->np_port); |
| 354 | |
| 355 | ret = iscsit_tpg_del_network_portal(tpg, tpg_np); |
| 356 | if (ret < 0) |
| 357 | goto out; |
| 358 | |
| 359 | pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n"); |
| 360 | out: |
| 361 | iscsit_put_tpg(tpg); |
| 362 | } |
| 363 | |
| 364 | /* End items for lio_target_np_cit */ |
| 365 | |
| 366 | /* Start items for lio_target_nacl_attrib_cit */ |
| 367 | |
| 368 | #define DEF_NACL_ATTRIB(name) \ |
| 369 | static ssize_t iscsi_nacl_attrib_show_##name( \ |
| 370 | struct se_node_acl *se_nacl, \ |
| 371 | char *page) \ |
| 372 | { \ |
| 373 | struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ |
| 374 | se_node_acl); \ |
| 375 | \ |
| 376 | return sprintf(page, "%u\n", ISCSI_NODE_ATTRIB(nacl)->name); \ |
| 377 | } \ |
| 378 | \ |
| 379 | static ssize_t iscsi_nacl_attrib_store_##name( \ |
| 380 | struct se_node_acl *se_nacl, \ |
| 381 | const char *page, \ |
| 382 | size_t count) \ |
| 383 | { \ |
| 384 | struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ |
| 385 | se_node_acl); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 386 | u32 val; \ |
| 387 | int ret; \ |
| 388 | \ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 389 | ret = kstrtou32(page, 0, &val); \ |
| 390 | if (ret) \ |
| 391 | return ret; \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 392 | ret = iscsit_na_##name(nacl, val); \ |
| 393 | if (ret < 0) \ |
| 394 | return ret; \ |
| 395 | \ |
| 396 | return count; \ |
| 397 | } |
| 398 | |
| 399 | #define NACL_ATTR(_name, _mode) TF_NACL_ATTRIB_ATTR(iscsi, _name, _mode); |
| 400 | /* |
| 401 | * Define iscsi_node_attrib_s_dataout_timeout |
| 402 | */ |
| 403 | DEF_NACL_ATTRIB(dataout_timeout); |
| 404 | NACL_ATTR(dataout_timeout, S_IRUGO | S_IWUSR); |
| 405 | /* |
| 406 | * Define iscsi_node_attrib_s_dataout_timeout_retries |
| 407 | */ |
| 408 | DEF_NACL_ATTRIB(dataout_timeout_retries); |
| 409 | NACL_ATTR(dataout_timeout_retries, S_IRUGO | S_IWUSR); |
| 410 | /* |
| 411 | * Define iscsi_node_attrib_s_default_erl |
| 412 | */ |
| 413 | DEF_NACL_ATTRIB(default_erl); |
| 414 | NACL_ATTR(default_erl, S_IRUGO | S_IWUSR); |
| 415 | /* |
| 416 | * Define iscsi_node_attrib_s_nopin_timeout |
| 417 | */ |
| 418 | DEF_NACL_ATTRIB(nopin_timeout); |
| 419 | NACL_ATTR(nopin_timeout, S_IRUGO | S_IWUSR); |
| 420 | /* |
| 421 | * Define iscsi_node_attrib_s_nopin_response_timeout |
| 422 | */ |
| 423 | DEF_NACL_ATTRIB(nopin_response_timeout); |
| 424 | NACL_ATTR(nopin_response_timeout, S_IRUGO | S_IWUSR); |
| 425 | /* |
| 426 | * Define iscsi_node_attrib_s_random_datain_pdu_offsets |
| 427 | */ |
| 428 | DEF_NACL_ATTRIB(random_datain_pdu_offsets); |
| 429 | NACL_ATTR(random_datain_pdu_offsets, S_IRUGO | S_IWUSR); |
| 430 | /* |
| 431 | * Define iscsi_node_attrib_s_random_datain_seq_offsets |
| 432 | */ |
| 433 | DEF_NACL_ATTRIB(random_datain_seq_offsets); |
| 434 | NACL_ATTR(random_datain_seq_offsets, S_IRUGO | S_IWUSR); |
| 435 | /* |
| 436 | * Define iscsi_node_attrib_s_random_r2t_offsets |
| 437 | */ |
| 438 | DEF_NACL_ATTRIB(random_r2t_offsets); |
| 439 | NACL_ATTR(random_r2t_offsets, S_IRUGO | S_IWUSR); |
| 440 | |
| 441 | static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = { |
| 442 | &iscsi_nacl_attrib_dataout_timeout.attr, |
| 443 | &iscsi_nacl_attrib_dataout_timeout_retries.attr, |
| 444 | &iscsi_nacl_attrib_default_erl.attr, |
| 445 | &iscsi_nacl_attrib_nopin_timeout.attr, |
| 446 | &iscsi_nacl_attrib_nopin_response_timeout.attr, |
| 447 | &iscsi_nacl_attrib_random_datain_pdu_offsets.attr, |
| 448 | &iscsi_nacl_attrib_random_datain_seq_offsets.attr, |
| 449 | &iscsi_nacl_attrib_random_r2t_offsets.attr, |
| 450 | NULL, |
| 451 | }; |
| 452 | |
| 453 | /* End items for lio_target_nacl_attrib_cit */ |
| 454 | |
| 455 | /* Start items for lio_target_nacl_auth_cit */ |
| 456 | |
| 457 | #define __DEF_NACL_AUTH_STR(prefix, name, flags) \ |
| 458 | static ssize_t __iscsi_##prefix##_show_##name( \ |
| 459 | struct iscsi_node_acl *nacl, \ |
| 460 | char *page) \ |
| 461 | { \ |
| 462 | struct iscsi_node_auth *auth = &nacl->node_auth; \ |
| 463 | \ |
| 464 | if (!capable(CAP_SYS_ADMIN)) \ |
| 465 | return -EPERM; \ |
| 466 | return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ |
| 467 | } \ |
| 468 | \ |
| 469 | static ssize_t __iscsi_##prefix##_store_##name( \ |
| 470 | struct iscsi_node_acl *nacl, \ |
| 471 | const char *page, \ |
| 472 | size_t count) \ |
| 473 | { \ |
| 474 | struct iscsi_node_auth *auth = &nacl->node_auth; \ |
| 475 | \ |
| 476 | if (!capable(CAP_SYS_ADMIN)) \ |
| 477 | return -EPERM; \ |
| 478 | \ |
Jörn Engel | 0fbfc46 | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 479 | snprintf(auth->name, sizeof(auth->name), "%s", page); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 480 | if (!strncmp("NULL", auth->name, 4)) \ |
| 481 | auth->naf_flags &= ~flags; \ |
| 482 | else \ |
| 483 | auth->naf_flags |= flags; \ |
| 484 | \ |
| 485 | if ((auth->naf_flags & NAF_USERID_IN_SET) && \ |
| 486 | (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ |
| 487 | auth->authenticate_target = 1; \ |
| 488 | else \ |
| 489 | auth->authenticate_target = 0; \ |
| 490 | \ |
| 491 | return count; \ |
| 492 | } |
| 493 | |
| 494 | #define __DEF_NACL_AUTH_INT(prefix, name) \ |
| 495 | static ssize_t __iscsi_##prefix##_show_##name( \ |
| 496 | struct iscsi_node_acl *nacl, \ |
| 497 | char *page) \ |
| 498 | { \ |
| 499 | struct iscsi_node_auth *auth = &nacl->node_auth; \ |
| 500 | \ |
| 501 | if (!capable(CAP_SYS_ADMIN)) \ |
| 502 | return -EPERM; \ |
| 503 | \ |
| 504 | return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ |
| 505 | } |
| 506 | |
| 507 | #define DEF_NACL_AUTH_STR(name, flags) \ |
| 508 | __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \ |
| 509 | static ssize_t iscsi_nacl_auth_show_##name( \ |
| 510 | struct se_node_acl *nacl, \ |
| 511 | char *page) \ |
| 512 | { \ |
| 513 | return __iscsi_nacl_auth_show_##name(container_of(nacl, \ |
| 514 | struct iscsi_node_acl, se_node_acl), page); \ |
| 515 | } \ |
| 516 | static ssize_t iscsi_nacl_auth_store_##name( \ |
| 517 | struct se_node_acl *nacl, \ |
| 518 | const char *page, \ |
| 519 | size_t count) \ |
| 520 | { \ |
| 521 | return __iscsi_nacl_auth_store_##name(container_of(nacl, \ |
| 522 | struct iscsi_node_acl, se_node_acl), page, count); \ |
| 523 | } |
| 524 | |
| 525 | #define DEF_NACL_AUTH_INT(name) \ |
| 526 | __DEF_NACL_AUTH_INT(nacl_auth, name) \ |
| 527 | static ssize_t iscsi_nacl_auth_show_##name( \ |
| 528 | struct se_node_acl *nacl, \ |
| 529 | char *page) \ |
| 530 | { \ |
| 531 | return __iscsi_nacl_auth_show_##name(container_of(nacl, \ |
| 532 | struct iscsi_node_acl, se_node_acl), page); \ |
| 533 | } |
| 534 | |
| 535 | #define AUTH_ATTR(_name, _mode) TF_NACL_AUTH_ATTR(iscsi, _name, _mode); |
| 536 | #define AUTH_ATTR_RO(_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name); |
| 537 | |
| 538 | /* |
| 539 | * One-way authentication userid |
| 540 | */ |
| 541 | DEF_NACL_AUTH_STR(userid, NAF_USERID_SET); |
| 542 | AUTH_ATTR(userid, S_IRUGO | S_IWUSR); |
| 543 | /* |
| 544 | * One-way authentication password |
| 545 | */ |
| 546 | DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET); |
| 547 | AUTH_ATTR(password, S_IRUGO | S_IWUSR); |
| 548 | /* |
| 549 | * Enforce mutual authentication |
| 550 | */ |
| 551 | DEF_NACL_AUTH_INT(authenticate_target); |
| 552 | AUTH_ATTR_RO(authenticate_target); |
| 553 | /* |
| 554 | * Mutual authentication userid |
| 555 | */ |
| 556 | DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); |
| 557 | AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR); |
| 558 | /* |
| 559 | * Mutual authentication password |
| 560 | */ |
| 561 | DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); |
| 562 | AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR); |
| 563 | |
| 564 | static struct configfs_attribute *lio_target_nacl_auth_attrs[] = { |
| 565 | &iscsi_nacl_auth_userid.attr, |
| 566 | &iscsi_nacl_auth_password.attr, |
| 567 | &iscsi_nacl_auth_authenticate_target.attr, |
| 568 | &iscsi_nacl_auth_userid_mutual.attr, |
| 569 | &iscsi_nacl_auth_password_mutual.attr, |
| 570 | NULL, |
| 571 | }; |
| 572 | |
| 573 | /* End items for lio_target_nacl_auth_cit */ |
| 574 | |
| 575 | /* Start items for lio_target_nacl_param_cit */ |
| 576 | |
| 577 | #define DEF_NACL_PARAM(name) \ |
| 578 | static ssize_t iscsi_nacl_param_show_##name( \ |
| 579 | struct se_node_acl *se_nacl, \ |
| 580 | char *page) \ |
| 581 | { \ |
| 582 | struct iscsi_session *sess; \ |
| 583 | struct se_session *se_sess; \ |
| 584 | ssize_t rb; \ |
| 585 | \ |
| 586 | spin_lock_bh(&se_nacl->nacl_sess_lock); \ |
| 587 | se_sess = se_nacl->nacl_sess; \ |
| 588 | if (!se_sess) { \ |
| 589 | rb = snprintf(page, PAGE_SIZE, \ |
| 590 | "No Active iSCSI Session\n"); \ |
| 591 | } else { \ |
| 592 | sess = se_sess->fabric_sess_ptr; \ |
| 593 | rb = snprintf(page, PAGE_SIZE, "%u\n", \ |
| 594 | (u32)sess->sess_ops->name); \ |
| 595 | } \ |
| 596 | spin_unlock_bh(&se_nacl->nacl_sess_lock); \ |
| 597 | \ |
| 598 | return rb; \ |
| 599 | } |
| 600 | |
| 601 | #define NACL_PARAM_ATTR(_name) TF_NACL_PARAM_ATTR_RO(iscsi, _name); |
| 602 | |
| 603 | DEF_NACL_PARAM(MaxConnections); |
| 604 | NACL_PARAM_ATTR(MaxConnections); |
| 605 | |
| 606 | DEF_NACL_PARAM(InitialR2T); |
| 607 | NACL_PARAM_ATTR(InitialR2T); |
| 608 | |
| 609 | DEF_NACL_PARAM(ImmediateData); |
| 610 | NACL_PARAM_ATTR(ImmediateData); |
| 611 | |
| 612 | DEF_NACL_PARAM(MaxBurstLength); |
| 613 | NACL_PARAM_ATTR(MaxBurstLength); |
| 614 | |
| 615 | DEF_NACL_PARAM(FirstBurstLength); |
| 616 | NACL_PARAM_ATTR(FirstBurstLength); |
| 617 | |
| 618 | DEF_NACL_PARAM(DefaultTime2Wait); |
| 619 | NACL_PARAM_ATTR(DefaultTime2Wait); |
| 620 | |
| 621 | DEF_NACL_PARAM(DefaultTime2Retain); |
| 622 | NACL_PARAM_ATTR(DefaultTime2Retain); |
| 623 | |
| 624 | DEF_NACL_PARAM(MaxOutstandingR2T); |
| 625 | NACL_PARAM_ATTR(MaxOutstandingR2T); |
| 626 | |
| 627 | DEF_NACL_PARAM(DataPDUInOrder); |
| 628 | NACL_PARAM_ATTR(DataPDUInOrder); |
| 629 | |
| 630 | DEF_NACL_PARAM(DataSequenceInOrder); |
| 631 | NACL_PARAM_ATTR(DataSequenceInOrder); |
| 632 | |
| 633 | DEF_NACL_PARAM(ErrorRecoveryLevel); |
| 634 | NACL_PARAM_ATTR(ErrorRecoveryLevel); |
| 635 | |
| 636 | static struct configfs_attribute *lio_target_nacl_param_attrs[] = { |
| 637 | &iscsi_nacl_param_MaxConnections.attr, |
| 638 | &iscsi_nacl_param_InitialR2T.attr, |
| 639 | &iscsi_nacl_param_ImmediateData.attr, |
| 640 | &iscsi_nacl_param_MaxBurstLength.attr, |
| 641 | &iscsi_nacl_param_FirstBurstLength.attr, |
| 642 | &iscsi_nacl_param_DefaultTime2Wait.attr, |
| 643 | &iscsi_nacl_param_DefaultTime2Retain.attr, |
| 644 | &iscsi_nacl_param_MaxOutstandingR2T.attr, |
| 645 | &iscsi_nacl_param_DataPDUInOrder.attr, |
| 646 | &iscsi_nacl_param_DataSequenceInOrder.attr, |
| 647 | &iscsi_nacl_param_ErrorRecoveryLevel.attr, |
| 648 | NULL, |
| 649 | }; |
| 650 | |
| 651 | /* End items for lio_target_nacl_param_cit */ |
| 652 | |
| 653 | /* Start items for lio_target_acl_cit */ |
| 654 | |
| 655 | static ssize_t lio_target_nacl_show_info( |
| 656 | struct se_node_acl *se_nacl, |
| 657 | char *page) |
| 658 | { |
| 659 | struct iscsi_session *sess; |
| 660 | struct iscsi_conn *conn; |
| 661 | struct se_session *se_sess; |
| 662 | ssize_t rb = 0; |
| 663 | |
| 664 | spin_lock_bh(&se_nacl->nacl_sess_lock); |
| 665 | se_sess = se_nacl->nacl_sess; |
| 666 | if (!se_sess) { |
| 667 | rb += sprintf(page+rb, "No active iSCSI Session for Initiator" |
| 668 | " Endpoint: %s\n", se_nacl->initiatorname); |
| 669 | } else { |
| 670 | sess = se_sess->fabric_sess_ptr; |
| 671 | |
| 672 | if (sess->sess_ops->InitiatorName) |
| 673 | rb += sprintf(page+rb, "InitiatorName: %s\n", |
| 674 | sess->sess_ops->InitiatorName); |
| 675 | if (sess->sess_ops->InitiatorAlias) |
| 676 | rb += sprintf(page+rb, "InitiatorAlias: %s\n", |
| 677 | sess->sess_ops->InitiatorAlias); |
| 678 | |
| 679 | rb += sprintf(page+rb, "LIO Session ID: %u " |
| 680 | "ISID: 0x%02x %02x %02x %02x %02x %02x " |
| 681 | "TSIH: %hu ", sess->sid, |
| 682 | sess->isid[0], sess->isid[1], sess->isid[2], |
| 683 | sess->isid[3], sess->isid[4], sess->isid[5], |
| 684 | sess->tsih); |
| 685 | rb += sprintf(page+rb, "SessionType: %s\n", |
| 686 | (sess->sess_ops->SessionType) ? |
| 687 | "Discovery" : "Normal"); |
| 688 | rb += sprintf(page+rb, "Session State: "); |
| 689 | switch (sess->session_state) { |
| 690 | case TARG_SESS_STATE_FREE: |
| 691 | rb += sprintf(page+rb, "TARG_SESS_FREE\n"); |
| 692 | break; |
| 693 | case TARG_SESS_STATE_ACTIVE: |
| 694 | rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n"); |
| 695 | break; |
| 696 | case TARG_SESS_STATE_LOGGED_IN: |
| 697 | rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n"); |
| 698 | break; |
| 699 | case TARG_SESS_STATE_FAILED: |
| 700 | rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n"); |
| 701 | break; |
| 702 | case TARG_SESS_STATE_IN_CONTINUE: |
| 703 | rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n"); |
| 704 | break; |
| 705 | default: |
| 706 | rb += sprintf(page+rb, "ERROR: Unknown Session" |
| 707 | " State!\n"); |
| 708 | break; |
| 709 | } |
| 710 | |
| 711 | rb += sprintf(page+rb, "---------------------[iSCSI Session" |
| 712 | " Values]-----------------------\n"); |
| 713 | rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN" |
| 714 | " : MaxCmdSN : ITT : TTT\n"); |
| 715 | rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x" |
| 716 | " 0x%08x 0x%08x\n", |
| 717 | sess->cmdsn_window, |
| 718 | (sess->max_cmd_sn - sess->exp_cmd_sn) + 1, |
| 719 | sess->exp_cmd_sn, sess->max_cmd_sn, |
| 720 | sess->init_task_tag, sess->targ_xfer_tag); |
| 721 | rb += sprintf(page+rb, "----------------------[iSCSI" |
| 722 | " Connections]-------------------------\n"); |
| 723 | |
| 724 | spin_lock(&sess->conn_lock); |
| 725 | list_for_each_entry(conn, &sess->sess_conn_list, conn_list) { |
| 726 | rb += sprintf(page+rb, "CID: %hu Connection" |
| 727 | " State: ", conn->cid); |
| 728 | switch (conn->conn_state) { |
| 729 | case TARG_CONN_STATE_FREE: |
| 730 | rb += sprintf(page+rb, |
| 731 | "TARG_CONN_STATE_FREE\n"); |
| 732 | break; |
| 733 | case TARG_CONN_STATE_XPT_UP: |
| 734 | rb += sprintf(page+rb, |
| 735 | "TARG_CONN_STATE_XPT_UP\n"); |
| 736 | break; |
| 737 | case TARG_CONN_STATE_IN_LOGIN: |
| 738 | rb += sprintf(page+rb, |
| 739 | "TARG_CONN_STATE_IN_LOGIN\n"); |
| 740 | break; |
| 741 | case TARG_CONN_STATE_LOGGED_IN: |
| 742 | rb += sprintf(page+rb, |
| 743 | "TARG_CONN_STATE_LOGGED_IN\n"); |
| 744 | break; |
| 745 | case TARG_CONN_STATE_IN_LOGOUT: |
| 746 | rb += sprintf(page+rb, |
| 747 | "TARG_CONN_STATE_IN_LOGOUT\n"); |
| 748 | break; |
| 749 | case TARG_CONN_STATE_LOGOUT_REQUESTED: |
| 750 | rb += sprintf(page+rb, |
| 751 | "TARG_CONN_STATE_LOGOUT_REQUESTED\n"); |
| 752 | break; |
| 753 | case TARG_CONN_STATE_CLEANUP_WAIT: |
| 754 | rb += sprintf(page+rb, |
| 755 | "TARG_CONN_STATE_CLEANUP_WAIT\n"); |
| 756 | break; |
| 757 | default: |
| 758 | rb += sprintf(page+rb, |
| 759 | "ERROR: Unknown Connection State!\n"); |
| 760 | break; |
| 761 | } |
| 762 | |
| 763 | rb += sprintf(page+rb, " Address %s %s", conn->login_ip, |
| 764 | (conn->network_transport == ISCSI_TCP) ? |
| 765 | "TCP" : "SCTP"); |
| 766 | rb += sprintf(page+rb, " StatSN: 0x%08x\n", |
| 767 | conn->stat_sn); |
| 768 | } |
| 769 | spin_unlock(&sess->conn_lock); |
| 770 | } |
| 771 | spin_unlock_bh(&se_nacl->nacl_sess_lock); |
| 772 | |
| 773 | return rb; |
| 774 | } |
| 775 | |
| 776 | TF_NACL_BASE_ATTR_RO(lio_target, info); |
| 777 | |
| 778 | static ssize_t lio_target_nacl_show_cmdsn_depth( |
| 779 | struct se_node_acl *se_nacl, |
| 780 | char *page) |
| 781 | { |
| 782 | return sprintf(page, "%u\n", se_nacl->queue_depth); |
| 783 | } |
| 784 | |
| 785 | static ssize_t lio_target_nacl_store_cmdsn_depth( |
| 786 | struct se_node_acl *se_nacl, |
| 787 | const char *page, |
| 788 | size_t count) |
| 789 | { |
| 790 | struct se_portal_group *se_tpg = se_nacl->se_tpg; |
| 791 | struct iscsi_portal_group *tpg = container_of(se_tpg, |
| 792 | struct iscsi_portal_group, tpg_se_tpg); |
| 793 | struct config_item *acl_ci, *tpg_ci, *wwn_ci; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 794 | u32 cmdsn_depth = 0; |
| 795 | int ret; |
| 796 | |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 797 | ret = kstrtou32(page, 0, &cmdsn_depth); |
| 798 | if (ret) |
| 799 | return ret; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 800 | if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) { |
| 801 | pr_err("Passed cmdsn_depth: %u exceeds" |
| 802 | " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth, |
| 803 | TA_DEFAULT_CMDSN_DEPTH_MAX); |
| 804 | return -EINVAL; |
| 805 | } |
| 806 | acl_ci = &se_nacl->acl_group.cg_item; |
| 807 | if (!acl_ci) { |
| 808 | pr_err("Unable to locatel acl_ci\n"); |
| 809 | return -EINVAL; |
| 810 | } |
| 811 | tpg_ci = &acl_ci->ci_parent->ci_group->cg_item; |
| 812 | if (!tpg_ci) { |
| 813 | pr_err("Unable to locate tpg_ci\n"); |
| 814 | return -EINVAL; |
| 815 | } |
| 816 | wwn_ci = &tpg_ci->ci_group->cg_item; |
| 817 | if (!wwn_ci) { |
| 818 | pr_err("Unable to locate config_item wwn_ci\n"); |
| 819 | return -EINVAL; |
| 820 | } |
| 821 | |
| 822 | if (iscsit_get_tpg(tpg) < 0) |
| 823 | return -EINVAL; |
| 824 | /* |
| 825 | * iscsit_tpg_set_initiator_node_queue_depth() assumes force=1 |
| 826 | */ |
| 827 | ret = iscsit_tpg_set_initiator_node_queue_depth(tpg, |
| 828 | config_item_name(acl_ci), cmdsn_depth, 1); |
| 829 | |
| 830 | pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for" |
| 831 | "InitiatorName: %s\n", config_item_name(wwn_ci), |
| 832 | config_item_name(tpg_ci), cmdsn_depth, |
| 833 | config_item_name(acl_ci)); |
| 834 | |
| 835 | iscsit_put_tpg(tpg); |
| 836 | return (!ret) ? count : (ssize_t)ret; |
| 837 | } |
| 838 | |
| 839 | TF_NACL_BASE_ATTR(lio_target, cmdsn_depth, S_IRUGO | S_IWUSR); |
| 840 | |
Andy Grover | 79e62fc | 2012-12-11 16:30:53 -0800 | [diff] [blame] | 841 | static ssize_t lio_target_nacl_show_tag( |
| 842 | struct se_node_acl *se_nacl, |
| 843 | char *page) |
| 844 | { |
| 845 | return snprintf(page, PAGE_SIZE, "%s", se_nacl->acl_tag); |
| 846 | } |
| 847 | |
| 848 | static ssize_t lio_target_nacl_store_tag( |
| 849 | struct se_node_acl *se_nacl, |
| 850 | const char *page, |
| 851 | size_t count) |
| 852 | { |
| 853 | int ret; |
| 854 | |
| 855 | ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page); |
| 856 | |
| 857 | if (ret < 0) |
| 858 | return ret; |
| 859 | return count; |
| 860 | } |
| 861 | |
| 862 | TF_NACL_BASE_ATTR(lio_target, tag, S_IRUGO | S_IWUSR); |
| 863 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 864 | static struct configfs_attribute *lio_target_initiator_attrs[] = { |
| 865 | &lio_target_nacl_info.attr, |
| 866 | &lio_target_nacl_cmdsn_depth.attr, |
Andy Grover | 79e62fc | 2012-12-11 16:30:53 -0800 | [diff] [blame] | 867 | &lio_target_nacl_tag.attr, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 868 | NULL, |
| 869 | }; |
| 870 | |
| 871 | static struct se_node_acl *lio_tpg_alloc_fabric_acl( |
| 872 | struct se_portal_group *se_tpg) |
| 873 | { |
| 874 | struct iscsi_node_acl *acl; |
| 875 | |
| 876 | acl = kzalloc(sizeof(struct iscsi_node_acl), GFP_KERNEL); |
| 877 | if (!acl) { |
| 878 | pr_err("Unable to allocate memory for struct iscsi_node_acl\n"); |
| 879 | return NULL; |
| 880 | } |
| 881 | |
| 882 | return &acl->se_node_acl; |
| 883 | } |
| 884 | |
| 885 | static struct se_node_acl *lio_target_make_nodeacl( |
| 886 | struct se_portal_group *se_tpg, |
| 887 | struct config_group *group, |
| 888 | const char *name) |
| 889 | { |
| 890 | struct config_group *stats_cg; |
| 891 | struct iscsi_node_acl *acl; |
| 892 | struct se_node_acl *se_nacl_new, *se_nacl; |
| 893 | struct iscsi_portal_group *tpg = container_of(se_tpg, |
| 894 | struct iscsi_portal_group, tpg_se_tpg); |
| 895 | u32 cmdsn_depth; |
| 896 | |
| 897 | se_nacl_new = lio_tpg_alloc_fabric_acl(se_tpg); |
| 898 | if (!se_nacl_new) |
| 899 | return ERR_PTR(-ENOMEM); |
| 900 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 901 | cmdsn_depth = ISCSI_TPG_ATTRIB(tpg)->default_cmdsn_depth; |
| 902 | /* |
| 903 | * se_nacl_new may be released by core_tpg_add_initiator_node_acl() |
| 904 | * when converting a NdoeACL from demo mode -> explict |
| 905 | */ |
| 906 | se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new, |
| 907 | name, cmdsn_depth); |
| 908 | if (IS_ERR(se_nacl)) |
| 909 | return se_nacl; |
| 910 | |
Nicholas Bellinger | d062833 | 2012-02-26 22:16:07 -0800 | [diff] [blame] | 911 | acl = container_of(se_nacl, struct iscsi_node_acl, se_node_acl); |
| 912 | stats_cg = &se_nacl->acl_fabric_stat_group; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 913 | |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 914 | stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 915 | GFP_KERNEL); |
| 916 | if (!stats_cg->default_groups) { |
| 917 | pr_err("Unable to allocate memory for" |
| 918 | " stats_cg->default_groups\n"); |
| 919 | core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1); |
| 920 | kfree(acl); |
| 921 | return ERR_PTR(-ENOMEM); |
| 922 | } |
| 923 | |
| 924 | stats_cg->default_groups[0] = &NODE_STAT_GRPS(acl)->iscsi_sess_stats_group; |
| 925 | stats_cg->default_groups[1] = NULL; |
| 926 | config_group_init_type_name(&NODE_STAT_GRPS(acl)->iscsi_sess_stats_group, |
| 927 | "iscsi_sess_stats", &iscsi_stat_sess_cit); |
| 928 | |
| 929 | return se_nacl; |
| 930 | } |
| 931 | |
| 932 | static void lio_target_drop_nodeacl( |
| 933 | struct se_node_acl *se_nacl) |
| 934 | { |
| 935 | struct se_portal_group *se_tpg = se_nacl->se_tpg; |
| 936 | struct iscsi_node_acl *acl = container_of(se_nacl, |
| 937 | struct iscsi_node_acl, se_node_acl); |
| 938 | struct config_item *df_item; |
| 939 | struct config_group *stats_cg; |
| 940 | int i; |
| 941 | |
| 942 | stats_cg = &acl->se_node_acl.acl_fabric_stat_group; |
| 943 | for (i = 0; stats_cg->default_groups[i]; i++) { |
| 944 | df_item = &stats_cg->default_groups[i]->cg_item; |
| 945 | stats_cg->default_groups[i] = NULL; |
| 946 | config_item_put(df_item); |
| 947 | } |
| 948 | kfree(stats_cg->default_groups); |
| 949 | |
| 950 | core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1); |
| 951 | kfree(acl); |
| 952 | } |
| 953 | |
| 954 | /* End items for lio_target_acl_cit */ |
| 955 | |
| 956 | /* Start items for lio_target_tpg_attrib_cit */ |
| 957 | |
| 958 | #define DEF_TPG_ATTRIB(name) \ |
| 959 | \ |
| 960 | static ssize_t iscsi_tpg_attrib_show_##name( \ |
| 961 | struct se_portal_group *se_tpg, \ |
| 962 | char *page) \ |
| 963 | { \ |
| 964 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 965 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 966 | ssize_t rb; \ |
| 967 | \ |
| 968 | if (iscsit_get_tpg(tpg) < 0) \ |
| 969 | return -EINVAL; \ |
| 970 | \ |
| 971 | rb = sprintf(page, "%u\n", ISCSI_TPG_ATTRIB(tpg)->name); \ |
| 972 | iscsit_put_tpg(tpg); \ |
| 973 | return rb; \ |
| 974 | } \ |
| 975 | \ |
| 976 | static ssize_t iscsi_tpg_attrib_store_##name( \ |
| 977 | struct se_portal_group *se_tpg, \ |
| 978 | const char *page, \ |
| 979 | size_t count) \ |
| 980 | { \ |
| 981 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 982 | struct iscsi_portal_group, tpg_se_tpg); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 983 | u32 val; \ |
| 984 | int ret; \ |
| 985 | \ |
| 986 | if (iscsit_get_tpg(tpg) < 0) \ |
| 987 | return -EINVAL; \ |
| 988 | \ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 989 | ret = kstrtou32(page, 0, &val); \ |
| 990 | if (ret) \ |
| 991 | goto out; \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 992 | ret = iscsit_ta_##name(tpg, val); \ |
| 993 | if (ret < 0) \ |
| 994 | goto out; \ |
| 995 | \ |
| 996 | iscsit_put_tpg(tpg); \ |
| 997 | return count; \ |
| 998 | out: \ |
| 999 | iscsit_put_tpg(tpg); \ |
| 1000 | return ret; \ |
| 1001 | } |
| 1002 | |
| 1003 | #define TPG_ATTR(_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode); |
| 1004 | |
| 1005 | /* |
| 1006 | * Define iscsi_tpg_attrib_s_authentication |
| 1007 | */ |
| 1008 | DEF_TPG_ATTRIB(authentication); |
| 1009 | TPG_ATTR(authentication, S_IRUGO | S_IWUSR); |
| 1010 | /* |
| 1011 | * Define iscsi_tpg_attrib_s_login_timeout |
| 1012 | */ |
| 1013 | DEF_TPG_ATTRIB(login_timeout); |
| 1014 | TPG_ATTR(login_timeout, S_IRUGO | S_IWUSR); |
| 1015 | /* |
| 1016 | * Define iscsi_tpg_attrib_s_netif_timeout |
| 1017 | */ |
| 1018 | DEF_TPG_ATTRIB(netif_timeout); |
| 1019 | TPG_ATTR(netif_timeout, S_IRUGO | S_IWUSR); |
| 1020 | /* |
| 1021 | * Define iscsi_tpg_attrib_s_generate_node_acls |
| 1022 | */ |
| 1023 | DEF_TPG_ATTRIB(generate_node_acls); |
| 1024 | TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR); |
| 1025 | /* |
| 1026 | * Define iscsi_tpg_attrib_s_default_cmdsn_depth |
| 1027 | */ |
| 1028 | DEF_TPG_ATTRIB(default_cmdsn_depth); |
| 1029 | TPG_ATTR(default_cmdsn_depth, S_IRUGO | S_IWUSR); |
| 1030 | /* |
| 1031 | Define iscsi_tpg_attrib_s_cache_dynamic_acls |
| 1032 | */ |
| 1033 | DEF_TPG_ATTRIB(cache_dynamic_acls); |
| 1034 | TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR); |
| 1035 | /* |
| 1036 | * Define iscsi_tpg_attrib_s_demo_mode_write_protect |
| 1037 | */ |
| 1038 | DEF_TPG_ATTRIB(demo_mode_write_protect); |
| 1039 | TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR); |
| 1040 | /* |
| 1041 | * Define iscsi_tpg_attrib_s_prod_mode_write_protect |
| 1042 | */ |
| 1043 | DEF_TPG_ATTRIB(prod_mode_write_protect); |
| 1044 | TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR); |
| 1045 | |
| 1046 | static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = { |
| 1047 | &iscsi_tpg_attrib_authentication.attr, |
| 1048 | &iscsi_tpg_attrib_login_timeout.attr, |
| 1049 | &iscsi_tpg_attrib_netif_timeout.attr, |
| 1050 | &iscsi_tpg_attrib_generate_node_acls.attr, |
| 1051 | &iscsi_tpg_attrib_default_cmdsn_depth.attr, |
| 1052 | &iscsi_tpg_attrib_cache_dynamic_acls.attr, |
| 1053 | &iscsi_tpg_attrib_demo_mode_write_protect.attr, |
| 1054 | &iscsi_tpg_attrib_prod_mode_write_protect.attr, |
| 1055 | NULL, |
| 1056 | }; |
| 1057 | |
| 1058 | /* End items for lio_target_tpg_attrib_cit */ |
| 1059 | |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 1060 | /* Start items for lio_target_tpg_auth_cit */ |
| 1061 | |
| 1062 | #define __DEF_TPG_AUTH_STR(prefix, name, flags) \ |
| 1063 | static ssize_t __iscsi_##prefix##_show_##name( \ |
| 1064 | struct se_portal_group *se_tpg, \ |
| 1065 | char *page) \ |
| 1066 | { \ |
| 1067 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 1068 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 1069 | struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ |
| 1070 | \ |
| 1071 | if (!capable(CAP_SYS_ADMIN)) \ |
| 1072 | return -EPERM; \ |
| 1073 | \ |
| 1074 | return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ |
| 1075 | } \ |
| 1076 | \ |
| 1077 | static ssize_t __iscsi_##prefix##_store_##name( \ |
| 1078 | struct se_portal_group *se_tpg, \ |
| 1079 | const char *page, \ |
| 1080 | size_t count) \ |
| 1081 | { \ |
| 1082 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 1083 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 1084 | struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ |
| 1085 | \ |
| 1086 | if (!capable(CAP_SYS_ADMIN)) \ |
| 1087 | return -EPERM; \ |
| 1088 | \ |
Nicholas Bellinger | 37b32c6 | 2013-07-06 16:48:55 -0700 | [diff] [blame] | 1089 | snprintf(auth->name, sizeof(auth->name), "%s", page); \ |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 1090 | if (!(strncmp("NULL", auth->name, 4))) \ |
| 1091 | auth->naf_flags &= ~flags; \ |
| 1092 | else \ |
| 1093 | auth->naf_flags |= flags; \ |
| 1094 | \ |
| 1095 | if ((auth->naf_flags & NAF_USERID_IN_SET) && \ |
| 1096 | (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ |
| 1097 | auth->authenticate_target = 1; \ |
| 1098 | else \ |
| 1099 | auth->authenticate_target = 0; \ |
| 1100 | \ |
| 1101 | return count; \ |
| 1102 | } |
| 1103 | |
| 1104 | #define __DEF_TPG_AUTH_INT(prefix, name) \ |
| 1105 | static ssize_t __iscsi_##prefix##_show_##name( \ |
| 1106 | struct se_portal_group *se_tpg, \ |
| 1107 | char *page) \ |
| 1108 | { \ |
| 1109 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 1110 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 1111 | struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ |
| 1112 | \ |
| 1113 | if (!capable(CAP_SYS_ADMIN)) \ |
| 1114 | return -EPERM; \ |
| 1115 | \ |
| 1116 | return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ |
| 1117 | } |
| 1118 | |
| 1119 | #define DEF_TPG_AUTH_STR(name, flags) \ |
| 1120 | __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \ |
| 1121 | static ssize_t iscsi_tpg_auth_show_##name( \ |
| 1122 | struct se_portal_group *se_tpg, \ |
| 1123 | char *page) \ |
| 1124 | { \ |
| 1125 | return __iscsi_tpg_auth_show_##name(se_tpg, page); \ |
| 1126 | } \ |
| 1127 | \ |
| 1128 | static ssize_t iscsi_tpg_auth_store_##name( \ |
| 1129 | struct se_portal_group *se_tpg, \ |
| 1130 | const char *page, \ |
| 1131 | size_t count) \ |
| 1132 | { \ |
| 1133 | return __iscsi_tpg_auth_store_##name(se_tpg, page, count); \ |
| 1134 | } |
| 1135 | |
| 1136 | #define DEF_TPG_AUTH_INT(name) \ |
| 1137 | __DEF_TPG_AUTH_INT(tpg_auth, name) \ |
| 1138 | static ssize_t iscsi_tpg_auth_show_##name( \ |
| 1139 | struct se_portal_group *se_tpg, \ |
| 1140 | char *page) \ |
| 1141 | { \ |
| 1142 | return __iscsi_tpg_auth_show_##name(se_tpg, page); \ |
| 1143 | } |
| 1144 | |
| 1145 | #define TPG_AUTH_ATTR(_name, _mode) TF_TPG_AUTH_ATTR(iscsi, _name, _mode); |
| 1146 | #define TPG_AUTH_ATTR_RO(_name) TF_TPG_AUTH_ATTR_RO(iscsi, _name); |
| 1147 | |
| 1148 | /* |
| 1149 | * * One-way authentication userid |
| 1150 | * */ |
| 1151 | DEF_TPG_AUTH_STR(userid, NAF_USERID_SET); |
| 1152 | TPG_AUTH_ATTR(userid, S_IRUGO | S_IWUSR); |
| 1153 | /* |
| 1154 | * * One-way authentication password |
| 1155 | * */ |
| 1156 | DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET); |
| 1157 | TPG_AUTH_ATTR(password, S_IRUGO | S_IWUSR); |
| 1158 | /* |
| 1159 | * * Enforce mutual authentication |
| 1160 | * */ |
| 1161 | DEF_TPG_AUTH_INT(authenticate_target); |
| 1162 | TPG_AUTH_ATTR_RO(authenticate_target); |
| 1163 | /* |
| 1164 | * * Mutual authentication userid |
| 1165 | * */ |
| 1166 | DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); |
| 1167 | TPG_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR); |
| 1168 | /* |
| 1169 | * * Mutual authentication password |
| 1170 | * */ |
| 1171 | DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); |
| 1172 | TPG_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR); |
| 1173 | |
| 1174 | static struct configfs_attribute *lio_target_tpg_auth_attrs[] = { |
| 1175 | &iscsi_tpg_auth_userid.attr, |
| 1176 | &iscsi_tpg_auth_password.attr, |
| 1177 | &iscsi_tpg_auth_authenticate_target.attr, |
| 1178 | &iscsi_tpg_auth_userid_mutual.attr, |
| 1179 | &iscsi_tpg_auth_password_mutual.attr, |
| 1180 | NULL, |
| 1181 | }; |
| 1182 | |
| 1183 | /* End items for lio_target_tpg_auth_cit */ |
| 1184 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1185 | /* Start items for lio_target_tpg_param_cit */ |
| 1186 | |
| 1187 | #define DEF_TPG_PARAM(name) \ |
| 1188 | static ssize_t iscsi_tpg_param_show_##name( \ |
| 1189 | struct se_portal_group *se_tpg, \ |
| 1190 | char *page) \ |
| 1191 | { \ |
| 1192 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 1193 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 1194 | struct iscsi_param *param; \ |
| 1195 | ssize_t rb; \ |
| 1196 | \ |
| 1197 | if (iscsit_get_tpg(tpg) < 0) \ |
| 1198 | return -EINVAL; \ |
| 1199 | \ |
| 1200 | param = iscsi_find_param_from_key(__stringify(name), \ |
| 1201 | tpg->param_list); \ |
| 1202 | if (!param) { \ |
| 1203 | iscsit_put_tpg(tpg); \ |
| 1204 | return -EINVAL; \ |
| 1205 | } \ |
| 1206 | rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \ |
| 1207 | \ |
| 1208 | iscsit_put_tpg(tpg); \ |
| 1209 | return rb; \ |
| 1210 | } \ |
| 1211 | static ssize_t iscsi_tpg_param_store_##name( \ |
| 1212 | struct se_portal_group *se_tpg, \ |
| 1213 | const char *page, \ |
| 1214 | size_t count) \ |
| 1215 | { \ |
| 1216 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 1217 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 1218 | char *buf; \ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1219 | int ret, len; \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1220 | \ |
| 1221 | buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \ |
| 1222 | if (!buf) \ |
| 1223 | return -ENOMEM; \ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1224 | len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \ |
| 1225 | if (isspace(buf[len-1])) \ |
| 1226 | buf[len-1] = '\0'; /* Kill newline */ \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1227 | \ |
| 1228 | if (iscsit_get_tpg(tpg) < 0) { \ |
| 1229 | kfree(buf); \ |
| 1230 | return -EINVAL; \ |
| 1231 | } \ |
| 1232 | \ |
| 1233 | ret = iscsi_change_param_value(buf, tpg->param_list, 1); \ |
| 1234 | if (ret < 0) \ |
| 1235 | goto out; \ |
| 1236 | \ |
| 1237 | kfree(buf); \ |
| 1238 | iscsit_put_tpg(tpg); \ |
| 1239 | return count; \ |
| 1240 | out: \ |
| 1241 | kfree(buf); \ |
| 1242 | iscsit_put_tpg(tpg); \ |
| 1243 | return -EINVAL; \ |
| 1244 | } |
| 1245 | |
| 1246 | #define TPG_PARAM_ATTR(_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode); |
| 1247 | |
| 1248 | DEF_TPG_PARAM(AuthMethod); |
| 1249 | TPG_PARAM_ATTR(AuthMethod, S_IRUGO | S_IWUSR); |
| 1250 | |
| 1251 | DEF_TPG_PARAM(HeaderDigest); |
| 1252 | TPG_PARAM_ATTR(HeaderDigest, S_IRUGO | S_IWUSR); |
| 1253 | |
| 1254 | DEF_TPG_PARAM(DataDigest); |
| 1255 | TPG_PARAM_ATTR(DataDigest, S_IRUGO | S_IWUSR); |
| 1256 | |
| 1257 | DEF_TPG_PARAM(MaxConnections); |
| 1258 | TPG_PARAM_ATTR(MaxConnections, S_IRUGO | S_IWUSR); |
| 1259 | |
| 1260 | DEF_TPG_PARAM(TargetAlias); |
| 1261 | TPG_PARAM_ATTR(TargetAlias, S_IRUGO | S_IWUSR); |
| 1262 | |
| 1263 | DEF_TPG_PARAM(InitialR2T); |
| 1264 | TPG_PARAM_ATTR(InitialR2T, S_IRUGO | S_IWUSR); |
| 1265 | |
| 1266 | DEF_TPG_PARAM(ImmediateData); |
| 1267 | TPG_PARAM_ATTR(ImmediateData, S_IRUGO | S_IWUSR); |
| 1268 | |
| 1269 | DEF_TPG_PARAM(MaxRecvDataSegmentLength); |
| 1270 | TPG_PARAM_ATTR(MaxRecvDataSegmentLength, S_IRUGO | S_IWUSR); |
| 1271 | |
Nicholas Bellinger | e004cb2 | 2012-09-29 21:47:16 -0700 | [diff] [blame] | 1272 | DEF_TPG_PARAM(MaxXmitDataSegmentLength); |
| 1273 | TPG_PARAM_ATTR(MaxXmitDataSegmentLength, S_IRUGO | S_IWUSR); |
| 1274 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1275 | DEF_TPG_PARAM(MaxBurstLength); |
| 1276 | TPG_PARAM_ATTR(MaxBurstLength, S_IRUGO | S_IWUSR); |
| 1277 | |
| 1278 | DEF_TPG_PARAM(FirstBurstLength); |
| 1279 | TPG_PARAM_ATTR(FirstBurstLength, S_IRUGO | S_IWUSR); |
| 1280 | |
| 1281 | DEF_TPG_PARAM(DefaultTime2Wait); |
| 1282 | TPG_PARAM_ATTR(DefaultTime2Wait, S_IRUGO | S_IWUSR); |
| 1283 | |
| 1284 | DEF_TPG_PARAM(DefaultTime2Retain); |
| 1285 | TPG_PARAM_ATTR(DefaultTime2Retain, S_IRUGO | S_IWUSR); |
| 1286 | |
| 1287 | DEF_TPG_PARAM(MaxOutstandingR2T); |
| 1288 | TPG_PARAM_ATTR(MaxOutstandingR2T, S_IRUGO | S_IWUSR); |
| 1289 | |
| 1290 | DEF_TPG_PARAM(DataPDUInOrder); |
| 1291 | TPG_PARAM_ATTR(DataPDUInOrder, S_IRUGO | S_IWUSR); |
| 1292 | |
| 1293 | DEF_TPG_PARAM(DataSequenceInOrder); |
| 1294 | TPG_PARAM_ATTR(DataSequenceInOrder, S_IRUGO | S_IWUSR); |
| 1295 | |
| 1296 | DEF_TPG_PARAM(ErrorRecoveryLevel); |
| 1297 | TPG_PARAM_ATTR(ErrorRecoveryLevel, S_IRUGO | S_IWUSR); |
| 1298 | |
| 1299 | DEF_TPG_PARAM(IFMarker); |
| 1300 | TPG_PARAM_ATTR(IFMarker, S_IRUGO | S_IWUSR); |
| 1301 | |
| 1302 | DEF_TPG_PARAM(OFMarker); |
| 1303 | TPG_PARAM_ATTR(OFMarker, S_IRUGO | S_IWUSR); |
| 1304 | |
| 1305 | DEF_TPG_PARAM(IFMarkInt); |
| 1306 | TPG_PARAM_ATTR(IFMarkInt, S_IRUGO | S_IWUSR); |
| 1307 | |
| 1308 | DEF_TPG_PARAM(OFMarkInt); |
| 1309 | TPG_PARAM_ATTR(OFMarkInt, S_IRUGO | S_IWUSR); |
| 1310 | |
| 1311 | static struct configfs_attribute *lio_target_tpg_param_attrs[] = { |
| 1312 | &iscsi_tpg_param_AuthMethod.attr, |
| 1313 | &iscsi_tpg_param_HeaderDigest.attr, |
| 1314 | &iscsi_tpg_param_DataDigest.attr, |
| 1315 | &iscsi_tpg_param_MaxConnections.attr, |
| 1316 | &iscsi_tpg_param_TargetAlias.attr, |
| 1317 | &iscsi_tpg_param_InitialR2T.attr, |
| 1318 | &iscsi_tpg_param_ImmediateData.attr, |
| 1319 | &iscsi_tpg_param_MaxRecvDataSegmentLength.attr, |
Nicholas Bellinger | e004cb2 | 2012-09-29 21:47:16 -0700 | [diff] [blame] | 1320 | &iscsi_tpg_param_MaxXmitDataSegmentLength.attr, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1321 | &iscsi_tpg_param_MaxBurstLength.attr, |
| 1322 | &iscsi_tpg_param_FirstBurstLength.attr, |
| 1323 | &iscsi_tpg_param_DefaultTime2Wait.attr, |
| 1324 | &iscsi_tpg_param_DefaultTime2Retain.attr, |
| 1325 | &iscsi_tpg_param_MaxOutstandingR2T.attr, |
| 1326 | &iscsi_tpg_param_DataPDUInOrder.attr, |
| 1327 | &iscsi_tpg_param_DataSequenceInOrder.attr, |
| 1328 | &iscsi_tpg_param_ErrorRecoveryLevel.attr, |
| 1329 | &iscsi_tpg_param_IFMarker.attr, |
| 1330 | &iscsi_tpg_param_OFMarker.attr, |
| 1331 | &iscsi_tpg_param_IFMarkInt.attr, |
| 1332 | &iscsi_tpg_param_OFMarkInt.attr, |
| 1333 | NULL, |
| 1334 | }; |
| 1335 | |
| 1336 | /* End items for lio_target_tpg_param_cit */ |
| 1337 | |
| 1338 | /* Start items for lio_target_tpg_cit */ |
| 1339 | |
| 1340 | static ssize_t lio_target_tpg_show_enable( |
| 1341 | struct se_portal_group *se_tpg, |
| 1342 | char *page) |
| 1343 | { |
| 1344 | struct iscsi_portal_group *tpg = container_of(se_tpg, |
| 1345 | struct iscsi_portal_group, tpg_se_tpg); |
| 1346 | ssize_t len; |
| 1347 | |
| 1348 | spin_lock(&tpg->tpg_state_lock); |
| 1349 | len = sprintf(page, "%d\n", |
| 1350 | (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0); |
| 1351 | spin_unlock(&tpg->tpg_state_lock); |
| 1352 | |
| 1353 | return len; |
| 1354 | } |
| 1355 | |
| 1356 | static ssize_t lio_target_tpg_store_enable( |
| 1357 | struct se_portal_group *se_tpg, |
| 1358 | const char *page, |
| 1359 | size_t count) |
| 1360 | { |
| 1361 | struct iscsi_portal_group *tpg = container_of(se_tpg, |
| 1362 | struct iscsi_portal_group, tpg_se_tpg); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1363 | u32 op; |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1364 | int ret; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1365 | |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1366 | ret = kstrtou32(page, 0, &op); |
| 1367 | if (ret) |
| 1368 | return ret; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1369 | if ((op != 1) && (op != 0)) { |
| 1370 | pr_err("Illegal value for tpg_enable: %u\n", op); |
| 1371 | return -EINVAL; |
| 1372 | } |
| 1373 | |
| 1374 | ret = iscsit_get_tpg(tpg); |
| 1375 | if (ret < 0) |
| 1376 | return -EINVAL; |
| 1377 | |
| 1378 | if (op) { |
| 1379 | ret = iscsit_tpg_enable_portal_group(tpg); |
| 1380 | if (ret < 0) |
| 1381 | goto out; |
| 1382 | } else { |
| 1383 | /* |
| 1384 | * iscsit_tpg_disable_portal_group() assumes force=1 |
| 1385 | */ |
| 1386 | ret = iscsit_tpg_disable_portal_group(tpg, 1); |
| 1387 | if (ret < 0) |
| 1388 | goto out; |
| 1389 | } |
| 1390 | |
| 1391 | iscsit_put_tpg(tpg); |
| 1392 | return count; |
| 1393 | out: |
| 1394 | iscsit_put_tpg(tpg); |
| 1395 | return -EINVAL; |
| 1396 | } |
| 1397 | |
| 1398 | TF_TPG_BASE_ATTR(lio_target, enable, S_IRUGO | S_IWUSR); |
| 1399 | |
| 1400 | static struct configfs_attribute *lio_target_tpg_attrs[] = { |
| 1401 | &lio_target_tpg_enable.attr, |
| 1402 | NULL, |
| 1403 | }; |
| 1404 | |
| 1405 | /* End items for lio_target_tpg_cit */ |
| 1406 | |
| 1407 | /* Start items for lio_target_tiqn_cit */ |
| 1408 | |
Christoph Hellwig | fceb5bc | 2012-09-26 08:00:36 -0400 | [diff] [blame] | 1409 | static struct se_portal_group *lio_target_tiqn_addtpg( |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1410 | struct se_wwn *wwn, |
| 1411 | struct config_group *group, |
| 1412 | const char *name) |
| 1413 | { |
| 1414 | struct iscsi_portal_group *tpg; |
| 1415 | struct iscsi_tiqn *tiqn; |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1416 | char *tpgt_str; |
| 1417 | int ret; |
| 1418 | u16 tpgt; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1419 | |
| 1420 | tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); |
| 1421 | /* |
| 1422 | * Only tpgt_# directory groups can be created below |
| 1423 | * target/iscsi/iqn.superturodiskarry/ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1424 | */ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1425 | tpgt_str = strstr(name, "tpgt_"); |
| 1426 | if (!tpgt_str) { |
| 1427 | pr_err("Unable to locate \"tpgt_#\" directory" |
| 1428 | " group\n"); |
| 1429 | return NULL; |
| 1430 | } |
| 1431 | tpgt_str += 5; /* Skip ahead of "tpgt_" */ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1432 | ret = kstrtou16(tpgt_str, 0, &tpgt); |
| 1433 | if (ret) |
| 1434 | return NULL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1435 | |
| 1436 | tpg = iscsit_alloc_portal_group(tiqn, tpgt); |
| 1437 | if (!tpg) |
| 1438 | return NULL; |
| 1439 | |
| 1440 | ret = core_tpg_register( |
| 1441 | &lio_target_fabric_configfs->tf_ops, |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 1442 | wwn, &tpg->tpg_se_tpg, tpg, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1443 | TRANSPORT_TPG_TYPE_NORMAL); |
| 1444 | if (ret < 0) |
| 1445 | return NULL; |
| 1446 | |
| 1447 | ret = iscsit_tpg_add_portal_group(tiqn, tpg); |
| 1448 | if (ret != 0) |
| 1449 | goto out; |
| 1450 | |
| 1451 | pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); |
| 1452 | pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n", |
| 1453 | name); |
| 1454 | return &tpg->tpg_se_tpg; |
| 1455 | out: |
| 1456 | core_tpg_deregister(&tpg->tpg_se_tpg); |
| 1457 | kfree(tpg); |
| 1458 | return NULL; |
| 1459 | } |
| 1460 | |
Christoph Hellwig | fceb5bc | 2012-09-26 08:00:36 -0400 | [diff] [blame] | 1461 | static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1462 | { |
| 1463 | struct iscsi_portal_group *tpg; |
| 1464 | struct iscsi_tiqn *tiqn; |
| 1465 | |
| 1466 | tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); |
| 1467 | tiqn = tpg->tpg_tiqn; |
| 1468 | /* |
| 1469 | * iscsit_tpg_del_portal_group() assumes force=1 |
| 1470 | */ |
| 1471 | pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n"); |
| 1472 | iscsit_tpg_del_portal_group(tiqn, tpg, 1); |
| 1473 | } |
| 1474 | |
| 1475 | /* End items for lio_target_tiqn_cit */ |
| 1476 | |
| 1477 | /* Start LIO-Target TIQN struct contig_item lio_target_cit */ |
| 1478 | |
| 1479 | static ssize_t lio_target_wwn_show_attr_lio_version( |
| 1480 | struct target_fabric_configfs *tf, |
| 1481 | char *page) |
| 1482 | { |
| 1483 | return sprintf(page, "RisingTide Systems Linux-iSCSI Target "ISCSIT_VERSION"\n"); |
| 1484 | } |
| 1485 | |
| 1486 | TF_WWN_ATTR_RO(lio_target, lio_version); |
| 1487 | |
| 1488 | static struct configfs_attribute *lio_target_wwn_attrs[] = { |
| 1489 | &lio_target_wwn_lio_version.attr, |
| 1490 | NULL, |
| 1491 | }; |
| 1492 | |
Christoph Hellwig | fceb5bc | 2012-09-26 08:00:36 -0400 | [diff] [blame] | 1493 | static struct se_wwn *lio_target_call_coreaddtiqn( |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1494 | struct target_fabric_configfs *tf, |
| 1495 | struct config_group *group, |
| 1496 | const char *name) |
| 1497 | { |
| 1498 | struct config_group *stats_cg; |
| 1499 | struct iscsi_tiqn *tiqn; |
| 1500 | |
| 1501 | tiqn = iscsit_add_tiqn((unsigned char *)name); |
| 1502 | if (IS_ERR(tiqn)) |
Thomas Meyer | e1750ba | 2011-08-01 23:58:18 +0200 | [diff] [blame] | 1503 | return ERR_CAST(tiqn); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1504 | /* |
| 1505 | * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group. |
| 1506 | */ |
| 1507 | stats_cg = &tiqn->tiqn_wwn.fabric_stat_group; |
| 1508 | |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 1509 | stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1510 | GFP_KERNEL); |
| 1511 | if (!stats_cg->default_groups) { |
| 1512 | pr_err("Unable to allocate memory for" |
| 1513 | " stats_cg->default_groups\n"); |
| 1514 | iscsit_del_tiqn(tiqn); |
| 1515 | return ERR_PTR(-ENOMEM); |
| 1516 | } |
| 1517 | |
| 1518 | stats_cg->default_groups[0] = &WWN_STAT_GRPS(tiqn)->iscsi_instance_group; |
| 1519 | stats_cg->default_groups[1] = &WWN_STAT_GRPS(tiqn)->iscsi_sess_err_group; |
| 1520 | stats_cg->default_groups[2] = &WWN_STAT_GRPS(tiqn)->iscsi_tgt_attr_group; |
| 1521 | stats_cg->default_groups[3] = &WWN_STAT_GRPS(tiqn)->iscsi_login_stats_group; |
| 1522 | stats_cg->default_groups[4] = &WWN_STAT_GRPS(tiqn)->iscsi_logout_stats_group; |
| 1523 | stats_cg->default_groups[5] = NULL; |
| 1524 | config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_instance_group, |
| 1525 | "iscsi_instance", &iscsi_stat_instance_cit); |
| 1526 | config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_sess_err_group, |
| 1527 | "iscsi_sess_err", &iscsi_stat_sess_err_cit); |
| 1528 | config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_tgt_attr_group, |
| 1529 | "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit); |
| 1530 | config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_login_stats_group, |
| 1531 | "iscsi_login_stats", &iscsi_stat_login_cit); |
| 1532 | config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_logout_stats_group, |
| 1533 | "iscsi_logout_stats", &iscsi_stat_logout_cit); |
| 1534 | |
| 1535 | pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); |
| 1536 | pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:" |
| 1537 | " %s\n", name); |
| 1538 | return &tiqn->tiqn_wwn; |
| 1539 | } |
| 1540 | |
Christoph Hellwig | fceb5bc | 2012-09-26 08:00:36 -0400 | [diff] [blame] | 1541 | static void lio_target_call_coredeltiqn( |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1542 | struct se_wwn *wwn) |
| 1543 | { |
| 1544 | struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); |
| 1545 | struct config_item *df_item; |
| 1546 | struct config_group *stats_cg; |
| 1547 | int i; |
| 1548 | |
| 1549 | stats_cg = &tiqn->tiqn_wwn.fabric_stat_group; |
| 1550 | for (i = 0; stats_cg->default_groups[i]; i++) { |
| 1551 | df_item = &stats_cg->default_groups[i]->cg_item; |
| 1552 | stats_cg->default_groups[i] = NULL; |
| 1553 | config_item_put(df_item); |
| 1554 | } |
| 1555 | kfree(stats_cg->default_groups); |
| 1556 | |
| 1557 | pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n", |
| 1558 | tiqn->tiqn); |
| 1559 | iscsit_del_tiqn(tiqn); |
| 1560 | } |
| 1561 | |
| 1562 | /* End LIO-Target TIQN struct contig_lio_target_cit */ |
| 1563 | |
| 1564 | /* Start lio_target_discovery_auth_cit */ |
| 1565 | |
| 1566 | #define DEF_DISC_AUTH_STR(name, flags) \ |
| 1567 | __DEF_NACL_AUTH_STR(disc, name, flags) \ |
| 1568 | static ssize_t iscsi_disc_show_##name( \ |
| 1569 | struct target_fabric_configfs *tf, \ |
| 1570 | char *page) \ |
| 1571 | { \ |
| 1572 | return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \ |
| 1573 | page); \ |
| 1574 | } \ |
| 1575 | static ssize_t iscsi_disc_store_##name( \ |
| 1576 | struct target_fabric_configfs *tf, \ |
| 1577 | const char *page, \ |
| 1578 | size_t count) \ |
| 1579 | { \ |
| 1580 | return __iscsi_disc_store_##name(&iscsit_global->discovery_acl, \ |
| 1581 | page, count); \ |
| 1582 | } |
| 1583 | |
| 1584 | #define DEF_DISC_AUTH_INT(name) \ |
| 1585 | __DEF_NACL_AUTH_INT(disc, name) \ |
| 1586 | static ssize_t iscsi_disc_show_##name( \ |
| 1587 | struct target_fabric_configfs *tf, \ |
| 1588 | char *page) \ |
| 1589 | { \ |
| 1590 | return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \ |
| 1591 | page); \ |
| 1592 | } |
| 1593 | |
| 1594 | #define DISC_AUTH_ATTR(_name, _mode) TF_DISC_ATTR(iscsi, _name, _mode) |
| 1595 | #define DISC_AUTH_ATTR_RO(_name) TF_DISC_ATTR_RO(iscsi, _name) |
| 1596 | |
| 1597 | /* |
| 1598 | * One-way authentication userid |
| 1599 | */ |
| 1600 | DEF_DISC_AUTH_STR(userid, NAF_USERID_SET); |
| 1601 | DISC_AUTH_ATTR(userid, S_IRUGO | S_IWUSR); |
| 1602 | /* |
| 1603 | * One-way authentication password |
| 1604 | */ |
| 1605 | DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET); |
| 1606 | DISC_AUTH_ATTR(password, S_IRUGO | S_IWUSR); |
| 1607 | /* |
| 1608 | * Enforce mutual authentication |
| 1609 | */ |
| 1610 | DEF_DISC_AUTH_INT(authenticate_target); |
| 1611 | DISC_AUTH_ATTR_RO(authenticate_target); |
| 1612 | /* |
| 1613 | * Mutual authentication userid |
| 1614 | */ |
| 1615 | DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); |
| 1616 | DISC_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR); |
| 1617 | /* |
| 1618 | * Mutual authentication password |
| 1619 | */ |
| 1620 | DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); |
| 1621 | DISC_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR); |
| 1622 | |
| 1623 | /* |
| 1624 | * enforce_discovery_auth |
| 1625 | */ |
| 1626 | static ssize_t iscsi_disc_show_enforce_discovery_auth( |
| 1627 | struct target_fabric_configfs *tf, |
| 1628 | char *page) |
| 1629 | { |
| 1630 | struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth; |
| 1631 | |
| 1632 | return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth); |
| 1633 | } |
| 1634 | |
| 1635 | static ssize_t iscsi_disc_store_enforce_discovery_auth( |
| 1636 | struct target_fabric_configfs *tf, |
| 1637 | const char *page, |
| 1638 | size_t count) |
| 1639 | { |
| 1640 | struct iscsi_param *param; |
| 1641 | struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1642 | u32 op; |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1643 | int err; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1644 | |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1645 | err = kstrtou32(page, 0, &op); |
| 1646 | if (err) |
| 1647 | return -EINVAL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1648 | if ((op != 1) && (op != 0)) { |
| 1649 | pr_err("Illegal value for enforce_discovery_auth:" |
| 1650 | " %u\n", op); |
| 1651 | return -EINVAL; |
| 1652 | } |
| 1653 | |
| 1654 | if (!discovery_tpg) { |
| 1655 | pr_err("iscsit_global->discovery_tpg is NULL\n"); |
| 1656 | return -EINVAL; |
| 1657 | } |
| 1658 | |
| 1659 | param = iscsi_find_param_from_key(AUTHMETHOD, |
| 1660 | discovery_tpg->param_list); |
| 1661 | if (!param) |
| 1662 | return -EINVAL; |
| 1663 | |
| 1664 | if (op) { |
| 1665 | /* |
| 1666 | * Reset the AuthMethod key to CHAP. |
| 1667 | */ |
| 1668 | if (iscsi_update_param_value(param, CHAP) < 0) |
| 1669 | return -EINVAL; |
| 1670 | |
| 1671 | discovery_tpg->tpg_attrib.authentication = 1; |
| 1672 | iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1; |
| 1673 | pr_debug("LIO-CORE[0] Successfully enabled" |
| 1674 | " authentication enforcement for iSCSI" |
| 1675 | " Discovery TPG\n"); |
| 1676 | } else { |
| 1677 | /* |
| 1678 | * Reset the AuthMethod key to CHAP,None |
| 1679 | */ |
| 1680 | if (iscsi_update_param_value(param, "CHAP,None") < 0) |
| 1681 | return -EINVAL; |
| 1682 | |
| 1683 | discovery_tpg->tpg_attrib.authentication = 0; |
| 1684 | iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0; |
| 1685 | pr_debug("LIO-CORE[0] Successfully disabled" |
| 1686 | " authentication enforcement for iSCSI" |
| 1687 | " Discovery TPG\n"); |
| 1688 | } |
| 1689 | |
| 1690 | return count; |
| 1691 | } |
| 1692 | |
| 1693 | DISC_AUTH_ATTR(enforce_discovery_auth, S_IRUGO | S_IWUSR); |
| 1694 | |
| 1695 | static struct configfs_attribute *lio_target_discovery_auth_attrs[] = { |
| 1696 | &iscsi_disc_userid.attr, |
| 1697 | &iscsi_disc_password.attr, |
| 1698 | &iscsi_disc_authenticate_target.attr, |
| 1699 | &iscsi_disc_userid_mutual.attr, |
| 1700 | &iscsi_disc_password_mutual.attr, |
| 1701 | &iscsi_disc_enforce_discovery_auth.attr, |
| 1702 | NULL, |
| 1703 | }; |
| 1704 | |
| 1705 | /* End lio_target_discovery_auth_cit */ |
| 1706 | |
| 1707 | /* Start functions for target_core_fabric_ops */ |
| 1708 | |
| 1709 | static char *iscsi_get_fabric_name(void) |
| 1710 | { |
| 1711 | return "iSCSI"; |
| 1712 | } |
| 1713 | |
| 1714 | static u32 iscsi_get_task_tag(struct se_cmd *se_cmd) |
| 1715 | { |
| 1716 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1717 | |
Christoph Hellwig | 66c7db6 | 2012-09-26 08:00:39 -0400 | [diff] [blame] | 1718 | /* only used for printks or comparism with ->ref_task_tag */ |
| 1719 | return (__force u32)cmd->init_task_tag; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | static int iscsi_get_cmd_state(struct se_cmd *se_cmd) |
| 1723 | { |
| 1724 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1725 | |
| 1726 | return cmd->i_state; |
| 1727 | } |
| 1728 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1729 | static u32 lio_sess_get_index(struct se_session *se_sess) |
| 1730 | { |
| 1731 | struct iscsi_session *sess = se_sess->fabric_sess_ptr; |
| 1732 | |
| 1733 | return sess->session_index; |
| 1734 | } |
| 1735 | |
| 1736 | static u32 lio_sess_get_initiator_sid( |
| 1737 | struct se_session *se_sess, |
| 1738 | unsigned char *buf, |
| 1739 | u32 size) |
| 1740 | { |
| 1741 | struct iscsi_session *sess = se_sess->fabric_sess_ptr; |
| 1742 | /* |
| 1743 | * iSCSI Initiator Session Identifier from RFC-3720. |
| 1744 | */ |
| 1745 | return snprintf(buf, size, "%02x%02x%02x%02x%02x%02x", |
| 1746 | sess->isid[0], sess->isid[1], sess->isid[2], |
| 1747 | sess->isid[3], sess->isid[4], sess->isid[5]); |
| 1748 | } |
| 1749 | |
| 1750 | static int lio_queue_data_in(struct se_cmd *se_cmd) |
| 1751 | { |
| 1752 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1753 | |
| 1754 | cmd->i_state = ISTATE_SEND_DATAIN; |
Nicholas Bellinger | 2ec5a8c | 2013-03-20 15:29:15 -0700 | [diff] [blame] | 1755 | cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd); |
| 1756 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1757 | return 0; |
| 1758 | } |
| 1759 | |
| 1760 | static int lio_write_pending(struct se_cmd *se_cmd) |
| 1761 | { |
| 1762 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
Nicholas Bellinger | 3e1c81a | 2013-03-06 22:18:24 -0800 | [diff] [blame] | 1763 | struct iscsi_conn *conn = cmd->conn; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1764 | |
| 1765 | if (!cmd->immediate_data && !cmd->unsolicited_data) |
Nicholas Bellinger | 3e1c81a | 2013-03-06 22:18:24 -0800 | [diff] [blame] | 1766 | return conn->conn_transport->iscsit_get_dataout(conn, cmd, false); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1767 | |
| 1768 | return 0; |
| 1769 | } |
| 1770 | |
| 1771 | static int lio_write_pending_status(struct se_cmd *se_cmd) |
| 1772 | { |
| 1773 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1774 | int ret; |
| 1775 | |
| 1776 | spin_lock_bh(&cmd->istate_lock); |
| 1777 | ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT); |
| 1778 | spin_unlock_bh(&cmd->istate_lock); |
| 1779 | |
| 1780 | return ret; |
| 1781 | } |
| 1782 | |
| 1783 | static int lio_queue_status(struct se_cmd *se_cmd) |
| 1784 | { |
| 1785 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1786 | |
| 1787 | cmd->i_state = ISTATE_SEND_STATUS; |
Nicholas Bellinger | 2ec5a8c | 2013-03-20 15:29:15 -0700 | [diff] [blame] | 1788 | cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd); |
| 1789 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1790 | return 0; |
| 1791 | } |
| 1792 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1793 | static int lio_queue_tm_rsp(struct se_cmd *se_cmd) |
| 1794 | { |
| 1795 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1796 | |
| 1797 | cmd->i_state = ISTATE_SEND_TASKMGTRSP; |
| 1798 | iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state); |
| 1799 | return 0; |
| 1800 | } |
| 1801 | |
| 1802 | static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg) |
| 1803 | { |
| 1804 | struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; |
| 1805 | |
| 1806 | return &tpg->tpg_tiqn->tiqn[0]; |
| 1807 | } |
| 1808 | |
| 1809 | static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg) |
| 1810 | { |
| 1811 | struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; |
| 1812 | |
| 1813 | return tpg->tpgt; |
| 1814 | } |
| 1815 | |
| 1816 | static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg) |
| 1817 | { |
| 1818 | struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; |
| 1819 | |
| 1820 | return ISCSI_TPG_ATTRIB(tpg)->default_cmdsn_depth; |
| 1821 | } |
| 1822 | |
| 1823 | static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg) |
| 1824 | { |
| 1825 | struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; |
| 1826 | |
| 1827 | return ISCSI_TPG_ATTRIB(tpg)->generate_node_acls; |
| 1828 | } |
| 1829 | |
| 1830 | static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg) |
| 1831 | { |
| 1832 | struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; |
| 1833 | |
| 1834 | return ISCSI_TPG_ATTRIB(tpg)->cache_dynamic_acls; |
| 1835 | } |
| 1836 | |
| 1837 | static int lio_tpg_check_demo_mode_write_protect( |
| 1838 | struct se_portal_group *se_tpg) |
| 1839 | { |
| 1840 | struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; |
| 1841 | |
| 1842 | return ISCSI_TPG_ATTRIB(tpg)->demo_mode_write_protect; |
| 1843 | } |
| 1844 | |
| 1845 | static int lio_tpg_check_prod_mode_write_protect( |
| 1846 | struct se_portal_group *se_tpg) |
| 1847 | { |
| 1848 | struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; |
| 1849 | |
| 1850 | return ISCSI_TPG_ATTRIB(tpg)->prod_mode_write_protect; |
| 1851 | } |
| 1852 | |
| 1853 | static void lio_tpg_release_fabric_acl( |
| 1854 | struct se_portal_group *se_tpg, |
| 1855 | struct se_node_acl *se_acl) |
| 1856 | { |
| 1857 | struct iscsi_node_acl *acl = container_of(se_acl, |
| 1858 | struct iscsi_node_acl, se_node_acl); |
| 1859 | kfree(acl); |
| 1860 | } |
| 1861 | |
| 1862 | /* |
| 1863 | * Called with spin_lock_bh(struct se_portal_group->session_lock) held.. |
| 1864 | * |
| 1865 | * Also, this function calls iscsit_inc_session_usage_count() on the |
| 1866 | * struct iscsi_session in question. |
| 1867 | */ |
| 1868 | static int lio_tpg_shutdown_session(struct se_session *se_sess) |
| 1869 | { |
| 1870 | struct iscsi_session *sess = se_sess->fabric_sess_ptr; |
| 1871 | |
| 1872 | spin_lock(&sess->conn_lock); |
| 1873 | if (atomic_read(&sess->session_fall_back_to_erl0) || |
| 1874 | atomic_read(&sess->session_logout) || |
| 1875 | (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) { |
| 1876 | spin_unlock(&sess->conn_lock); |
| 1877 | return 0; |
| 1878 | } |
| 1879 | atomic_set(&sess->session_reinstatement, 1); |
| 1880 | spin_unlock(&sess->conn_lock); |
| 1881 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1882 | iscsit_stop_time2retain_timer(sess); |
Nicholas Bellinger | 99367f0 | 2012-02-27 01:43:32 -0800 | [diff] [blame] | 1883 | iscsit_stop_session(sess, 1, 1); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1884 | |
| 1885 | return 1; |
| 1886 | } |
| 1887 | |
| 1888 | /* |
| 1889 | * Calls iscsit_dec_session_usage_count() as inverse of |
| 1890 | * lio_tpg_shutdown_session() |
| 1891 | */ |
| 1892 | static void lio_tpg_close_session(struct se_session *se_sess) |
| 1893 | { |
| 1894 | struct iscsi_session *sess = se_sess->fabric_sess_ptr; |
| 1895 | /* |
| 1896 | * If the iSCSI Session for the iSCSI Initiator Node exists, |
| 1897 | * forcefully shutdown the iSCSI NEXUS. |
| 1898 | */ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1899 | iscsit_close_session(sess); |
| 1900 | } |
| 1901 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1902 | static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg) |
| 1903 | { |
| 1904 | struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; |
| 1905 | |
| 1906 | return tpg->tpg_tiqn->tiqn_index; |
| 1907 | } |
| 1908 | |
| 1909 | static void lio_set_default_node_attributes(struct se_node_acl *se_acl) |
| 1910 | { |
| 1911 | struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl, |
| 1912 | se_node_acl); |
| 1913 | |
| 1914 | ISCSI_NODE_ATTRIB(acl)->nacl = acl; |
| 1915 | iscsit_set_default_node_attribues(acl); |
| 1916 | } |
| 1917 | |
Nicholas Bellinger | 3e1c81a | 2013-03-06 22:18:24 -0800 | [diff] [blame] | 1918 | static int lio_check_stop_free(struct se_cmd *se_cmd) |
| 1919 | { |
| 1920 | return target_put_sess_cmd(se_cmd->se_sess, se_cmd); |
| 1921 | } |
| 1922 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1923 | static void lio_release_cmd(struct se_cmd *se_cmd) |
| 1924 | { |
| 1925 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1926 | |
Nicholas Bellinger | cdb7266 | 2013-03-06 22:09:17 -0800 | [diff] [blame] | 1927 | pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd); |
| 1928 | cmd->release_cmd(cmd); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1929 | } |
| 1930 | |
| 1931 | /* End functions for target_core_fabric_ops */ |
| 1932 | |
| 1933 | int iscsi_target_register_configfs(void) |
| 1934 | { |
| 1935 | struct target_fabric_configfs *fabric; |
| 1936 | int ret; |
| 1937 | |
| 1938 | lio_target_fabric_configfs = NULL; |
| 1939 | fabric = target_fabric_configfs_init(THIS_MODULE, "iscsi"); |
| 1940 | if (IS_ERR(fabric)) { |
| 1941 | pr_err("target_fabric_configfs_init() for" |
| 1942 | " LIO-Target failed!\n"); |
| 1943 | return PTR_ERR(fabric); |
| 1944 | } |
| 1945 | /* |
| 1946 | * Setup the fabric API of function pointers used by target_core_mod.. |
| 1947 | */ |
| 1948 | fabric->tf_ops.get_fabric_name = &iscsi_get_fabric_name; |
| 1949 | fabric->tf_ops.get_fabric_proto_ident = &iscsi_get_fabric_proto_ident; |
| 1950 | fabric->tf_ops.tpg_get_wwn = &lio_tpg_get_endpoint_wwn; |
| 1951 | fabric->tf_ops.tpg_get_tag = &lio_tpg_get_tag; |
| 1952 | fabric->tf_ops.tpg_get_default_depth = &lio_tpg_get_default_depth; |
| 1953 | fabric->tf_ops.tpg_get_pr_transport_id = &iscsi_get_pr_transport_id; |
| 1954 | fabric->tf_ops.tpg_get_pr_transport_id_len = |
| 1955 | &iscsi_get_pr_transport_id_len; |
| 1956 | fabric->tf_ops.tpg_parse_pr_out_transport_id = |
| 1957 | &iscsi_parse_pr_out_transport_id; |
| 1958 | fabric->tf_ops.tpg_check_demo_mode = &lio_tpg_check_demo_mode; |
| 1959 | fabric->tf_ops.tpg_check_demo_mode_cache = |
| 1960 | &lio_tpg_check_demo_mode_cache; |
| 1961 | fabric->tf_ops.tpg_check_demo_mode_write_protect = |
| 1962 | &lio_tpg_check_demo_mode_write_protect; |
| 1963 | fabric->tf_ops.tpg_check_prod_mode_write_protect = |
| 1964 | &lio_tpg_check_prod_mode_write_protect; |
| 1965 | fabric->tf_ops.tpg_alloc_fabric_acl = &lio_tpg_alloc_fabric_acl; |
| 1966 | fabric->tf_ops.tpg_release_fabric_acl = &lio_tpg_release_fabric_acl; |
| 1967 | fabric->tf_ops.tpg_get_inst_index = &lio_tpg_get_inst_index; |
Nicholas Bellinger | 3e1c81a | 2013-03-06 22:18:24 -0800 | [diff] [blame] | 1968 | fabric->tf_ops.check_stop_free = &lio_check_stop_free, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1969 | fabric->tf_ops.release_cmd = &lio_release_cmd; |
| 1970 | fabric->tf_ops.shutdown_session = &lio_tpg_shutdown_session; |
| 1971 | fabric->tf_ops.close_session = &lio_tpg_close_session; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1972 | fabric->tf_ops.sess_get_index = &lio_sess_get_index; |
| 1973 | fabric->tf_ops.sess_get_initiator_sid = &lio_sess_get_initiator_sid; |
| 1974 | fabric->tf_ops.write_pending = &lio_write_pending; |
| 1975 | fabric->tf_ops.write_pending_status = &lio_write_pending_status; |
| 1976 | fabric->tf_ops.set_default_node_attributes = |
| 1977 | &lio_set_default_node_attributes; |
| 1978 | fabric->tf_ops.get_task_tag = &iscsi_get_task_tag; |
| 1979 | fabric->tf_ops.get_cmd_state = &iscsi_get_cmd_state; |
| 1980 | fabric->tf_ops.queue_data_in = &lio_queue_data_in; |
| 1981 | fabric->tf_ops.queue_status = &lio_queue_status; |
| 1982 | fabric->tf_ops.queue_tm_rsp = &lio_queue_tm_rsp; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1983 | /* |
| 1984 | * Setup function pointers for generic logic in target_core_fabric_configfs.c |
| 1985 | */ |
| 1986 | fabric->tf_ops.fabric_make_wwn = &lio_target_call_coreaddtiqn; |
| 1987 | fabric->tf_ops.fabric_drop_wwn = &lio_target_call_coredeltiqn; |
| 1988 | fabric->tf_ops.fabric_make_tpg = &lio_target_tiqn_addtpg; |
| 1989 | fabric->tf_ops.fabric_drop_tpg = &lio_target_tiqn_deltpg; |
| 1990 | fabric->tf_ops.fabric_post_link = NULL; |
| 1991 | fabric->tf_ops.fabric_pre_unlink = NULL; |
| 1992 | fabric->tf_ops.fabric_make_np = &lio_target_call_addnptotpg; |
| 1993 | fabric->tf_ops.fabric_drop_np = &lio_target_call_delnpfromtpg; |
| 1994 | fabric->tf_ops.fabric_make_nodeacl = &lio_target_make_nodeacl; |
| 1995 | fabric->tf_ops.fabric_drop_nodeacl = &lio_target_drop_nodeacl; |
| 1996 | /* |
| 1997 | * Setup default attribute lists for various fabric->tf_cit_tmpl |
| 1998 | * sturct config_item_type's |
| 1999 | */ |
| 2000 | TF_CIT_TMPL(fabric)->tfc_discovery_cit.ct_attrs = lio_target_discovery_auth_attrs; |
| 2001 | TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = lio_target_wwn_attrs; |
| 2002 | TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = lio_target_tpg_attrs; |
| 2003 | TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = lio_target_tpg_attrib_attrs; |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 2004 | TF_CIT_TMPL(fabric)->tfc_tpg_auth_cit.ct_attrs = lio_target_tpg_auth_attrs; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 2005 | TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = lio_target_tpg_param_attrs; |
| 2006 | TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = lio_target_portal_attrs; |
| 2007 | TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs = lio_target_initiator_attrs; |
| 2008 | TF_CIT_TMPL(fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = lio_target_nacl_attrib_attrs; |
| 2009 | TF_CIT_TMPL(fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = lio_target_nacl_auth_attrs; |
| 2010 | TF_CIT_TMPL(fabric)->tfc_tpg_nacl_param_cit.ct_attrs = lio_target_nacl_param_attrs; |
| 2011 | |
| 2012 | ret = target_fabric_configfs_register(fabric); |
| 2013 | if (ret < 0) { |
| 2014 | pr_err("target_fabric_configfs_register() for" |
| 2015 | " LIO-Target failed!\n"); |
| 2016 | target_fabric_configfs_free(fabric); |
| 2017 | return ret; |
| 2018 | } |
| 2019 | |
| 2020 | lio_target_fabric_configfs = fabric; |
| 2021 | pr_debug("LIO_TARGET[0] - Set fabric ->" |
| 2022 | " lio_target_fabric_configfs\n"); |
| 2023 | return 0; |
| 2024 | } |
| 2025 | |
| 2026 | |
| 2027 | void iscsi_target_deregister_configfs(void) |
| 2028 | { |
| 2029 | if (!lio_target_fabric_configfs) |
| 2030 | return; |
| 2031 | /* |
| 2032 | * Shutdown discovery sessions and disable discovery TPG |
| 2033 | */ |
| 2034 | if (iscsit_global->discovery_tpg) |
| 2035 | iscsit_tpg_disable_portal_group(iscsit_global->discovery_tpg, 1); |
| 2036 | |
| 2037 | target_fabric_configfs_deregister(lio_target_fabric_configfs); |
| 2038 | lio_target_fabric_configfs = NULL; |
| 2039 | pr_debug("LIO_TARGET[0] - Cleared" |
| 2040 | " lio_target_fabric_configfs\n"); |
| 2041 | } |