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 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 5 | * (c) Copyright 2007-2013 Datera, Inc. |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 6 | * |
| 7 | * Author: Nicholas A. Bellinger <nab@linux-iscsi.org> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | ****************************************************************************/ |
| 19 | |
| 20 | #include <linux/configfs.h> |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 21 | #include <linux/ctype.h> |
Paul Gortmaker | c53181a | 2011-08-30 18:16:43 -0400 | [diff] [blame] | 22 | #include <linux/export.h> |
Stephen Rothwell | c3bc93d | 2012-01-23 11:39:49 +1100 | [diff] [blame] | 23 | #include <linux/inet.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 24 | #include <target/target_core_base.h> |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 25 | #include <target/target_core_fabric.h> |
Nicholas Bellinger | 2ec5a8c | 2013-03-20 15:29:15 -0700 | [diff] [blame] | 26 | #include <target/iscsi/iscsi_transport.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 27 | |
Sagi Grimberg | 67f091f | 2015-01-07 14:57:31 +0200 | [diff] [blame] | 28 | #include <target/iscsi/iscsi_target_core.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 29 | #include "iscsi_target_parameters.h" |
| 30 | #include "iscsi_target_device.h" |
| 31 | #include "iscsi_target_erl0.h" |
| 32 | #include "iscsi_target_nodeattrib.h" |
| 33 | #include "iscsi_target_tpg.h" |
| 34 | #include "iscsi_target_util.h" |
| 35 | #include "iscsi_target.h" |
Sagi Grimberg | 67f091f | 2015-01-07 14:57:31 +0200 | [diff] [blame] | 36 | #include <target/iscsi/iscsi_target_stat.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 37 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 38 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 39 | /* Start items for lio_target_portal_cit */ |
| 40 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 41 | static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 42 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 43 | return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np); |
| 44 | } |
| 45 | |
| 46 | static ssize_t lio_target_np_sctp_show(struct config_item *item, char *page) |
| 47 | { |
| 48 | struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 49 | struct iscsi_tpg_np *tpg_np_sctp; |
| 50 | ssize_t rb; |
| 51 | |
| 52 | tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP); |
| 53 | if (tpg_np_sctp) |
| 54 | rb = sprintf(page, "1\n"); |
| 55 | else |
| 56 | rb = sprintf(page, "0\n"); |
| 57 | |
| 58 | return rb; |
| 59 | } |
| 60 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 61 | static ssize_t lio_target_np_sctp_store(struct config_item *item, |
| 62 | const char *page, size_t count) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 63 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 64 | struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 65 | struct iscsi_np *np; |
| 66 | struct iscsi_portal_group *tpg; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 67 | struct iscsi_tpg_np *tpg_np_sctp = NULL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 68 | u32 op; |
| 69 | int ret; |
| 70 | |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 71 | ret = kstrtou32(page, 0, &op); |
| 72 | if (ret) |
| 73 | return ret; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 74 | if ((op != 1) && (op != 0)) { |
| 75 | pr_err("Illegal value for tpg_enable: %u\n", op); |
| 76 | return -EINVAL; |
| 77 | } |
| 78 | np = tpg_np->tpg_np; |
| 79 | if (!np) { |
| 80 | pr_err("Unable to locate struct iscsi_np from" |
| 81 | " struct iscsi_tpg_np\n"); |
| 82 | return -EINVAL; |
| 83 | } |
| 84 | |
| 85 | tpg = tpg_np->tpg; |
| 86 | if (iscsit_get_tpg(tpg) < 0) |
| 87 | return -EINVAL; |
| 88 | |
| 89 | if (op) { |
| 90 | /* |
| 91 | * Use existing np->np_sockaddr for SCTP network portal reference |
| 92 | */ |
| 93 | tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, |
Andy Grover | 76c28f1 | 2015-08-24 10:26:03 -0700 | [diff] [blame] | 94 | tpg_np, ISCSI_SCTP_TCP); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 95 | if (!tpg_np_sctp || IS_ERR(tpg_np_sctp)) |
| 96 | goto out; |
| 97 | } else { |
| 98 | tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP); |
| 99 | if (!tpg_np_sctp) |
| 100 | goto out; |
| 101 | |
| 102 | ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp); |
| 103 | if (ret < 0) |
| 104 | goto out; |
| 105 | } |
| 106 | |
| 107 | iscsit_put_tpg(tpg); |
| 108 | return count; |
| 109 | out: |
| 110 | iscsit_put_tpg(tpg); |
| 111 | return -EINVAL; |
| 112 | } |
| 113 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 114 | static ssize_t lio_target_np_iser_show(struct config_item *item, char *page) |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 115 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 116 | struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 117 | struct iscsi_tpg_np *tpg_np_iser; |
| 118 | ssize_t rb; |
| 119 | |
| 120 | tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND); |
| 121 | if (tpg_np_iser) |
| 122 | rb = sprintf(page, "1\n"); |
| 123 | else |
| 124 | rb = sprintf(page, "0\n"); |
| 125 | |
| 126 | return rb; |
| 127 | } |
| 128 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 129 | static ssize_t lio_target_np_iser_store(struct config_item *item, |
| 130 | const char *page, size_t count) |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 131 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 132 | struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 133 | struct iscsi_np *np; |
| 134 | struct iscsi_portal_group *tpg; |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 135 | struct iscsi_tpg_np *tpg_np_iser = NULL; |
| 136 | char *endptr; |
| 137 | u32 op; |
Andy Grover | 58bd0c6 | 2013-05-29 12:05:59 -0700 | [diff] [blame] | 138 | int rc = 0; |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 139 | |
| 140 | op = simple_strtoul(page, &endptr, 0); |
| 141 | if ((op != 1) && (op != 0)) { |
| 142 | pr_err("Illegal value for tpg_enable: %u\n", op); |
| 143 | return -EINVAL; |
| 144 | } |
| 145 | np = tpg_np->tpg_np; |
| 146 | if (!np) { |
| 147 | pr_err("Unable to locate struct iscsi_np from" |
| 148 | " struct iscsi_tpg_np\n"); |
| 149 | return -EINVAL; |
| 150 | } |
| 151 | |
| 152 | tpg = tpg_np->tpg; |
| 153 | if (iscsit_get_tpg(tpg) < 0) |
| 154 | return -EINVAL; |
| 155 | |
| 156 | if (op) { |
Andy Grover | 58bd0c6 | 2013-05-29 12:05:59 -0700 | [diff] [blame] | 157 | rc = request_module("ib_isert"); |
| 158 | if (rc != 0) { |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 159 | pr_warn("Unable to request_module for ib_isert\n"); |
Andy Grover | 58bd0c6 | 2013-05-29 12:05:59 -0700 | [diff] [blame] | 160 | rc = 0; |
| 161 | } |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 162 | |
| 163 | tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, |
Andy Grover | 76c28f1 | 2015-08-24 10:26:03 -0700 | [diff] [blame] | 164 | tpg_np, ISCSI_INFINIBAND); |
Andy Grover | 58bd0c6 | 2013-05-29 12:05:59 -0700 | [diff] [blame] | 165 | if (IS_ERR(tpg_np_iser)) { |
| 166 | rc = PTR_ERR(tpg_np_iser); |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 167 | goto out; |
Andy Grover | 58bd0c6 | 2013-05-29 12:05:59 -0700 | [diff] [blame] | 168 | } |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 169 | } else { |
| 170 | tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND); |
Andy Grover | 58bd0c6 | 2013-05-29 12:05:59 -0700 | [diff] [blame] | 171 | if (tpg_np_iser) { |
| 172 | rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser); |
| 173 | if (rc < 0) |
| 174 | goto out; |
| 175 | } |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 178 | iscsit_put_tpg(tpg); |
| 179 | return count; |
| 180 | out: |
| 181 | iscsit_put_tpg(tpg); |
Andy Grover | 58bd0c6 | 2013-05-29 12:05:59 -0700 | [diff] [blame] | 182 | return rc; |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 183 | } |
| 184 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 185 | CONFIGFS_ATTR(lio_target_np_, sctp); |
| 186 | CONFIGFS_ATTR(lio_target_np_, iser); |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 187 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 188 | static struct configfs_attribute *lio_target_portal_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 189 | &lio_target_np_attr_sctp, |
| 190 | &lio_target_np_attr_iser, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 191 | NULL, |
| 192 | }; |
| 193 | |
| 194 | /* Stop items for lio_target_portal_cit */ |
| 195 | |
| 196 | /* Start items for lio_target_np_cit */ |
| 197 | |
| 198 | #define MAX_PORTAL_LEN 256 |
| 199 | |
Christoph Hellwig | fceb5bc | 2012-09-26 08:00:36 -0400 | [diff] [blame] | 200 | static struct se_tpg_np *lio_target_call_addnptotpg( |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 201 | struct se_portal_group *se_tpg, |
| 202 | struct config_group *group, |
| 203 | const char *name) |
| 204 | { |
| 205 | struct iscsi_portal_group *tpg; |
| 206 | struct iscsi_tpg_np *tpg_np; |
| 207 | char *str, *str2, *ip_str, *port_str; |
Andy Grover | 13a3cf0 | 2015-08-24 10:26:06 -0700 | [diff] [blame] | 208 | struct sockaddr_storage sockaddr; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 209 | struct sockaddr_in *sock_in; |
| 210 | struct sockaddr_in6 *sock_in6; |
| 211 | unsigned long port; |
| 212 | int ret; |
| 213 | char buf[MAX_PORTAL_LEN + 1]; |
| 214 | |
| 215 | if (strlen(name) > MAX_PORTAL_LEN) { |
| 216 | pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n", |
| 217 | (int)strlen(name), MAX_PORTAL_LEN); |
| 218 | return ERR_PTR(-EOVERFLOW); |
| 219 | } |
| 220 | memset(buf, 0, MAX_PORTAL_LEN + 1); |
Nicholas Bellinger | 7bbb654 | 2011-07-27 12:37:03 -0700 | [diff] [blame] | 221 | snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 222 | |
Andy Grover | 13a3cf0 | 2015-08-24 10:26:06 -0700 | [diff] [blame] | 223 | memset(&sockaddr, 0, sizeof(struct sockaddr_storage)); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 224 | |
| 225 | str = strstr(buf, "["); |
| 226 | if (str) { |
| 227 | const char *end; |
| 228 | |
| 229 | str2 = strstr(str, "]"); |
| 230 | if (!str2) { |
| 231 | pr_err("Unable to locate trailing \"]\"" |
| 232 | " in IPv6 iSCSI network portal address\n"); |
| 233 | return ERR_PTR(-EINVAL); |
| 234 | } |
| 235 | str++; /* Skip over leading "[" */ |
Andy Grover | 76c28f1 | 2015-08-24 10:26:03 -0700 | [diff] [blame] | 236 | *str2 = '\0'; /* Terminate the unbracketed IPv6 address */ |
| 237 | str2++; /* Skip over the \0 */ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 238 | port_str = strstr(str2, ":"); |
| 239 | if (!port_str) { |
| 240 | pr_err("Unable to locate \":port\"" |
| 241 | " in IPv6 iSCSI network portal address\n"); |
| 242 | return ERR_PTR(-EINVAL); |
| 243 | } |
| 244 | *port_str = '\0'; /* Terminate string for IP */ |
| 245 | port_str++; /* Skip over ":" */ |
| 246 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 247 | ret = kstrtoul(port_str, 0, &port); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 248 | if (ret < 0) { |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 249 | pr_err("kstrtoul() failed for port_str: %d\n", ret); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 250 | return ERR_PTR(ret); |
| 251 | } |
| 252 | sock_in6 = (struct sockaddr_in6 *)&sockaddr; |
| 253 | sock_in6->sin6_family = AF_INET6; |
| 254 | sock_in6->sin6_port = htons((unsigned short)port); |
Andy Grover | dc58f76 | 2015-08-24 10:26:05 -0700 | [diff] [blame] | 255 | ret = in6_pton(str, -1, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 256 | (void *)&sock_in6->sin6_addr.in6_u, -1, &end); |
| 257 | if (ret <= 0) { |
| 258 | pr_err("in6_pton returned: %d\n", ret); |
| 259 | return ERR_PTR(-EINVAL); |
| 260 | } |
| 261 | } else { |
| 262 | str = ip_str = &buf[0]; |
| 263 | port_str = strstr(ip_str, ":"); |
| 264 | if (!port_str) { |
| 265 | pr_err("Unable to locate \":port\"" |
| 266 | " in IPv4 iSCSI network portal address\n"); |
| 267 | return ERR_PTR(-EINVAL); |
| 268 | } |
| 269 | *port_str = '\0'; /* Terminate string for IP */ |
| 270 | port_str++; /* Skip over ":" */ |
| 271 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 272 | ret = kstrtoul(port_str, 0, &port); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 273 | if (ret < 0) { |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 274 | pr_err("kstrtoul() failed for port_str: %d\n", ret); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 275 | return ERR_PTR(ret); |
| 276 | } |
| 277 | sock_in = (struct sockaddr_in *)&sockaddr; |
| 278 | sock_in->sin_family = AF_INET; |
| 279 | sock_in->sin_port = htons((unsigned short)port); |
| 280 | sock_in->sin_addr.s_addr = in_aton(ip_str); |
| 281 | } |
| 282 | tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); |
| 283 | ret = iscsit_get_tpg(tpg); |
| 284 | if (ret < 0) |
| 285 | return ERR_PTR(-EINVAL); |
| 286 | |
| 287 | pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu" |
| 288 | " PORTAL: %s\n", |
| 289 | config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), |
| 290 | tpg->tpgt, name); |
| 291 | /* |
| 292 | * Assume ISCSI_TCP by default. Other network portals for other |
| 293 | * iSCSI fabrics: |
| 294 | * |
| 295 | * Traditional iSCSI over SCTP (initial support) |
| 296 | * iSER/TCP (TODO, hardware available) |
| 297 | * iSER/SCTP (TODO, software emulation with osc-iwarp) |
| 298 | * iSER/IB (TODO, hardware available) |
| 299 | * |
Masanari Iida | 2087969 | 2012-08-27 22:46:00 +0900 | [diff] [blame] | 300 | * can be enabled with attributes under |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 301 | * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/ |
| 302 | * |
| 303 | */ |
Andy Grover | 76c28f1 | 2015-08-24 10:26:03 -0700 | [diff] [blame] | 304 | tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 305 | ISCSI_TCP); |
| 306 | if (IS_ERR(tpg_np)) { |
| 307 | iscsit_put_tpg(tpg); |
Thomas Meyer | e1750ba | 2011-08-01 23:58:18 +0200 | [diff] [blame] | 308 | return ERR_CAST(tpg_np); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 309 | } |
| 310 | pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n"); |
| 311 | |
| 312 | iscsit_put_tpg(tpg); |
| 313 | return &tpg_np->se_tpg_np; |
| 314 | } |
| 315 | |
| 316 | static void lio_target_call_delnpfromtpg( |
| 317 | struct se_tpg_np *se_tpg_np) |
| 318 | { |
| 319 | struct iscsi_portal_group *tpg; |
| 320 | struct iscsi_tpg_np *tpg_np; |
| 321 | struct se_portal_group *se_tpg; |
| 322 | int ret; |
| 323 | |
| 324 | tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np); |
| 325 | tpg = tpg_np->tpg; |
| 326 | ret = iscsit_get_tpg(tpg); |
| 327 | if (ret < 0) |
| 328 | return; |
| 329 | |
| 330 | se_tpg = &tpg->tpg_se_tpg; |
| 331 | pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu" |
Andy Grover | 69d7557 | 2015-08-24 10:26:04 -0700 | [diff] [blame] | 332 | " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), |
| 333 | tpg->tpgt, &tpg_np->tpg_np->np_sockaddr); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 334 | |
| 335 | ret = iscsit_tpg_del_network_portal(tpg, tpg_np); |
| 336 | if (ret < 0) |
| 337 | goto out; |
| 338 | |
| 339 | pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n"); |
| 340 | out: |
| 341 | iscsit_put_tpg(tpg); |
| 342 | } |
| 343 | |
| 344 | /* End items for lio_target_np_cit */ |
| 345 | |
| 346 | /* Start items for lio_target_nacl_attrib_cit */ |
| 347 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 348 | #define ISCSI_NACL_ATTR(name) \ |
| 349 | static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\ |
| 350 | char *page) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 351 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 352 | struct se_node_acl *se_nacl = attrib_to_nacl(item); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 353 | struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ |
| 354 | se_node_acl); \ |
| 355 | \ |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 356 | return sprintf(page, "%u\n", nacl->node_attrib.name); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 357 | } \ |
| 358 | \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 359 | static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\ |
| 360 | const char *page, size_t count) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 361 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 362 | struct se_node_acl *se_nacl = attrib_to_nacl(item); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 363 | struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ |
| 364 | se_node_acl); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 365 | u32 val; \ |
| 366 | int ret; \ |
| 367 | \ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 368 | ret = kstrtou32(page, 0, &val); \ |
| 369 | if (ret) \ |
| 370 | return ret; \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 371 | ret = iscsit_na_##name(nacl, val); \ |
| 372 | if (ret < 0) \ |
| 373 | return ret; \ |
| 374 | \ |
| 375 | return count; \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 376 | } \ |
| 377 | \ |
| 378 | CONFIGFS_ATTR(iscsi_nacl_attrib_, name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 379 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 380 | ISCSI_NACL_ATTR(dataout_timeout); |
| 381 | ISCSI_NACL_ATTR(dataout_timeout_retries); |
| 382 | ISCSI_NACL_ATTR(default_erl); |
| 383 | ISCSI_NACL_ATTR(nopin_timeout); |
| 384 | ISCSI_NACL_ATTR(nopin_response_timeout); |
| 385 | ISCSI_NACL_ATTR(random_datain_pdu_offsets); |
| 386 | ISCSI_NACL_ATTR(random_datain_seq_offsets); |
| 387 | ISCSI_NACL_ATTR(random_r2t_offsets); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 388 | |
| 389 | static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 390 | &iscsi_nacl_attrib_attr_dataout_timeout, |
| 391 | &iscsi_nacl_attrib_attr_dataout_timeout_retries, |
| 392 | &iscsi_nacl_attrib_attr_default_erl, |
| 393 | &iscsi_nacl_attrib_attr_nopin_timeout, |
| 394 | &iscsi_nacl_attrib_attr_nopin_response_timeout, |
| 395 | &iscsi_nacl_attrib_attr_random_datain_pdu_offsets, |
| 396 | &iscsi_nacl_attrib_attr_random_datain_seq_offsets, |
| 397 | &iscsi_nacl_attrib_attr_random_r2t_offsets, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 398 | NULL, |
| 399 | }; |
| 400 | |
| 401 | /* End items for lio_target_nacl_attrib_cit */ |
| 402 | |
| 403 | /* Start items for lio_target_nacl_auth_cit */ |
| 404 | |
| 405 | #define __DEF_NACL_AUTH_STR(prefix, name, flags) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 406 | static ssize_t __iscsi_##prefix##_##name##_show( \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 407 | struct iscsi_node_acl *nacl, \ |
| 408 | char *page) \ |
| 409 | { \ |
| 410 | struct iscsi_node_auth *auth = &nacl->node_auth; \ |
| 411 | \ |
| 412 | if (!capable(CAP_SYS_ADMIN)) \ |
| 413 | return -EPERM; \ |
| 414 | return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ |
| 415 | } \ |
| 416 | \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 417 | static ssize_t __iscsi_##prefix##_##name##_store( \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 418 | struct iscsi_node_acl *nacl, \ |
| 419 | const char *page, \ |
| 420 | size_t count) \ |
| 421 | { \ |
| 422 | struct iscsi_node_auth *auth = &nacl->node_auth; \ |
| 423 | \ |
| 424 | if (!capable(CAP_SYS_ADMIN)) \ |
| 425 | return -EPERM; \ |
Eric Seppanen | 2306bfb | 2013-11-21 14:49:56 -0800 | [diff] [blame] | 426 | if (count >= sizeof(auth->name)) \ |
| 427 | return -EINVAL; \ |
Jörn Engel | 0fbfc46 | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 428 | snprintf(auth->name, sizeof(auth->name), "%s", page); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 429 | if (!strncmp("NULL", auth->name, 4)) \ |
| 430 | auth->naf_flags &= ~flags; \ |
| 431 | else \ |
| 432 | auth->naf_flags |= flags; \ |
| 433 | \ |
| 434 | if ((auth->naf_flags & NAF_USERID_IN_SET) && \ |
| 435 | (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ |
| 436 | auth->authenticate_target = 1; \ |
| 437 | else \ |
| 438 | auth->authenticate_target = 0; \ |
| 439 | \ |
| 440 | return count; \ |
| 441 | } |
| 442 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 443 | #define DEF_NACL_AUTH_STR(name, flags) \ |
| 444 | __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \ |
| 445 | static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \ |
| 446 | char *page) \ |
| 447 | { \ |
| 448 | struct se_node_acl *nacl = auth_to_nacl(item); \ |
| 449 | return __iscsi_nacl_auth_##name##_show(container_of(nacl, \ |
| 450 | struct iscsi_node_acl, se_node_acl), page); \ |
| 451 | } \ |
| 452 | static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \ |
| 453 | const char *page, size_t count) \ |
| 454 | { \ |
| 455 | struct se_node_acl *nacl = auth_to_nacl(item); \ |
| 456 | return __iscsi_nacl_auth_##name##_store(container_of(nacl, \ |
| 457 | struct iscsi_node_acl, se_node_acl), page, count); \ |
| 458 | } \ |
| 459 | \ |
| 460 | CONFIGFS_ATTR(iscsi_nacl_auth_, name) |
| 461 | |
| 462 | /* |
| 463 | * One-way authentication userid |
| 464 | */ |
| 465 | DEF_NACL_AUTH_STR(userid, NAF_USERID_SET); |
| 466 | DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET); |
| 467 | DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); |
| 468 | DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); |
| 469 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 470 | #define __DEF_NACL_AUTH_INT(prefix, name) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 471 | static ssize_t __iscsi_##prefix##_##name##_show( \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 472 | struct iscsi_node_acl *nacl, \ |
| 473 | char *page) \ |
| 474 | { \ |
| 475 | struct iscsi_node_auth *auth = &nacl->node_auth; \ |
| 476 | \ |
| 477 | if (!capable(CAP_SYS_ADMIN)) \ |
| 478 | return -EPERM; \ |
| 479 | \ |
| 480 | return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ |
| 481 | } |
| 482 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 483 | #define DEF_NACL_AUTH_INT(name) \ |
| 484 | __DEF_NACL_AUTH_INT(nacl_auth, name) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 485 | static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \ |
| 486 | char *page) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 487 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 488 | struct se_node_acl *nacl = auth_to_nacl(item); \ |
| 489 | return __iscsi_nacl_auth_##name##_show(container_of(nacl, \ |
| 490 | struct iscsi_node_acl, se_node_acl), page); \ |
| 491 | } \ |
| 492 | \ |
| 493 | CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 494 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 495 | DEF_NACL_AUTH_INT(authenticate_target); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 496 | |
| 497 | static struct configfs_attribute *lio_target_nacl_auth_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 498 | &iscsi_nacl_auth_attr_userid, |
| 499 | &iscsi_nacl_auth_attr_password, |
| 500 | &iscsi_nacl_auth_attr_authenticate_target, |
| 501 | &iscsi_nacl_auth_attr_userid_mutual, |
| 502 | &iscsi_nacl_auth_attr_password_mutual, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 503 | NULL, |
| 504 | }; |
| 505 | |
| 506 | /* End items for lio_target_nacl_auth_cit */ |
| 507 | |
| 508 | /* Start items for lio_target_nacl_param_cit */ |
| 509 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 510 | #define ISCSI_NACL_PARAM(name) \ |
| 511 | static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \ |
| 512 | char *page) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 513 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 514 | struct se_node_acl *se_nacl = param_to_nacl(item); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 515 | struct iscsi_session *sess; \ |
| 516 | struct se_session *se_sess; \ |
| 517 | ssize_t rb; \ |
| 518 | \ |
| 519 | spin_lock_bh(&se_nacl->nacl_sess_lock); \ |
| 520 | se_sess = se_nacl->nacl_sess; \ |
| 521 | if (!se_sess) { \ |
| 522 | rb = snprintf(page, PAGE_SIZE, \ |
| 523 | "No Active iSCSI Session\n"); \ |
| 524 | } else { \ |
| 525 | sess = se_sess->fabric_sess_ptr; \ |
| 526 | rb = snprintf(page, PAGE_SIZE, "%u\n", \ |
| 527 | (u32)sess->sess_ops->name); \ |
| 528 | } \ |
| 529 | spin_unlock_bh(&se_nacl->nacl_sess_lock); \ |
| 530 | \ |
| 531 | return rb; \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 532 | } \ |
| 533 | \ |
| 534 | CONFIGFS_ATTR_RO(iscsi_nacl_param_, name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 535 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 536 | ISCSI_NACL_PARAM(MaxConnections); |
| 537 | ISCSI_NACL_PARAM(InitialR2T); |
| 538 | ISCSI_NACL_PARAM(ImmediateData); |
| 539 | ISCSI_NACL_PARAM(MaxBurstLength); |
| 540 | ISCSI_NACL_PARAM(FirstBurstLength); |
| 541 | ISCSI_NACL_PARAM(DefaultTime2Wait); |
| 542 | ISCSI_NACL_PARAM(DefaultTime2Retain); |
| 543 | ISCSI_NACL_PARAM(MaxOutstandingR2T); |
| 544 | ISCSI_NACL_PARAM(DataPDUInOrder); |
| 545 | ISCSI_NACL_PARAM(DataSequenceInOrder); |
| 546 | ISCSI_NACL_PARAM(ErrorRecoveryLevel); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 547 | |
| 548 | static struct configfs_attribute *lio_target_nacl_param_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 549 | &iscsi_nacl_param_attr_MaxConnections, |
| 550 | &iscsi_nacl_param_attr_InitialR2T, |
| 551 | &iscsi_nacl_param_attr_ImmediateData, |
| 552 | &iscsi_nacl_param_attr_MaxBurstLength, |
| 553 | &iscsi_nacl_param_attr_FirstBurstLength, |
| 554 | &iscsi_nacl_param_attr_DefaultTime2Wait, |
| 555 | &iscsi_nacl_param_attr_DefaultTime2Retain, |
| 556 | &iscsi_nacl_param_attr_MaxOutstandingR2T, |
| 557 | &iscsi_nacl_param_attr_DataPDUInOrder, |
| 558 | &iscsi_nacl_param_attr_DataSequenceInOrder, |
| 559 | &iscsi_nacl_param_attr_ErrorRecoveryLevel, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 560 | NULL, |
| 561 | }; |
| 562 | |
| 563 | /* End items for lio_target_nacl_param_cit */ |
| 564 | |
| 565 | /* Start items for lio_target_acl_cit */ |
| 566 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 567 | static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 568 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 569 | struct se_node_acl *se_nacl = acl_to_nacl(item); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 570 | struct iscsi_session *sess; |
| 571 | struct iscsi_conn *conn; |
| 572 | struct se_session *se_sess; |
| 573 | ssize_t rb = 0; |
Roland Dreier | 109e238 | 2015-07-23 14:53:32 -0700 | [diff] [blame] | 574 | u32 max_cmd_sn; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 575 | |
| 576 | spin_lock_bh(&se_nacl->nacl_sess_lock); |
| 577 | se_sess = se_nacl->nacl_sess; |
| 578 | if (!se_sess) { |
| 579 | rb += sprintf(page+rb, "No active iSCSI Session for Initiator" |
| 580 | " Endpoint: %s\n", se_nacl->initiatorname); |
| 581 | } else { |
| 582 | sess = se_sess->fabric_sess_ptr; |
| 583 | |
Joern Engel | cb35484 | 2014-09-02 17:49:50 -0400 | [diff] [blame] | 584 | rb += sprintf(page+rb, "InitiatorName: %s\n", |
| 585 | sess->sess_ops->InitiatorName); |
| 586 | rb += sprintf(page+rb, "InitiatorAlias: %s\n", |
| 587 | sess->sess_ops->InitiatorAlias); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 588 | |
Andy Shevchenko | 5cdf5a8 | 2015-01-15 13:40:56 +0200 | [diff] [blame] | 589 | rb += sprintf(page+rb, |
| 590 | "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ", |
| 591 | sess->sid, sess->isid, sess->tsih); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 592 | rb += sprintf(page+rb, "SessionType: %s\n", |
| 593 | (sess->sess_ops->SessionType) ? |
| 594 | "Discovery" : "Normal"); |
| 595 | rb += sprintf(page+rb, "Session State: "); |
| 596 | switch (sess->session_state) { |
| 597 | case TARG_SESS_STATE_FREE: |
| 598 | rb += sprintf(page+rb, "TARG_SESS_FREE\n"); |
| 599 | break; |
| 600 | case TARG_SESS_STATE_ACTIVE: |
| 601 | rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n"); |
| 602 | break; |
| 603 | case TARG_SESS_STATE_LOGGED_IN: |
| 604 | rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n"); |
| 605 | break; |
| 606 | case TARG_SESS_STATE_FAILED: |
| 607 | rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n"); |
| 608 | break; |
| 609 | case TARG_SESS_STATE_IN_CONTINUE: |
| 610 | rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n"); |
| 611 | break; |
| 612 | default: |
| 613 | rb += sprintf(page+rb, "ERROR: Unknown Session" |
| 614 | " State!\n"); |
| 615 | break; |
| 616 | } |
| 617 | |
| 618 | rb += sprintf(page+rb, "---------------------[iSCSI Session" |
| 619 | " Values]-----------------------\n"); |
| 620 | rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN" |
| 621 | " : MaxCmdSN : ITT : TTT\n"); |
Roland Dreier | 109e238 | 2015-07-23 14:53:32 -0700 | [diff] [blame] | 622 | max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 623 | rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x" |
| 624 | " 0x%08x 0x%08x\n", |
| 625 | sess->cmdsn_window, |
Roland Dreier | 109e238 | 2015-07-23 14:53:32 -0700 | [diff] [blame] | 626 | (max_cmd_sn - sess->exp_cmd_sn) + 1, |
| 627 | sess->exp_cmd_sn, max_cmd_sn, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 628 | sess->init_task_tag, sess->targ_xfer_tag); |
| 629 | rb += sprintf(page+rb, "----------------------[iSCSI" |
| 630 | " Connections]-------------------------\n"); |
| 631 | |
| 632 | spin_lock(&sess->conn_lock); |
| 633 | list_for_each_entry(conn, &sess->sess_conn_list, conn_list) { |
| 634 | rb += sprintf(page+rb, "CID: %hu Connection" |
| 635 | " State: ", conn->cid); |
| 636 | switch (conn->conn_state) { |
| 637 | case TARG_CONN_STATE_FREE: |
| 638 | rb += sprintf(page+rb, |
| 639 | "TARG_CONN_STATE_FREE\n"); |
| 640 | break; |
| 641 | case TARG_CONN_STATE_XPT_UP: |
| 642 | rb += sprintf(page+rb, |
| 643 | "TARG_CONN_STATE_XPT_UP\n"); |
| 644 | break; |
| 645 | case TARG_CONN_STATE_IN_LOGIN: |
| 646 | rb += sprintf(page+rb, |
| 647 | "TARG_CONN_STATE_IN_LOGIN\n"); |
| 648 | break; |
| 649 | case TARG_CONN_STATE_LOGGED_IN: |
| 650 | rb += sprintf(page+rb, |
| 651 | "TARG_CONN_STATE_LOGGED_IN\n"); |
| 652 | break; |
| 653 | case TARG_CONN_STATE_IN_LOGOUT: |
| 654 | rb += sprintf(page+rb, |
| 655 | "TARG_CONN_STATE_IN_LOGOUT\n"); |
| 656 | break; |
| 657 | case TARG_CONN_STATE_LOGOUT_REQUESTED: |
| 658 | rb += sprintf(page+rb, |
| 659 | "TARG_CONN_STATE_LOGOUT_REQUESTED\n"); |
| 660 | break; |
| 661 | case TARG_CONN_STATE_CLEANUP_WAIT: |
| 662 | rb += sprintf(page+rb, |
| 663 | "TARG_CONN_STATE_CLEANUP_WAIT\n"); |
| 664 | break; |
| 665 | default: |
| 666 | rb += sprintf(page+rb, |
| 667 | "ERROR: Unknown Connection State!\n"); |
| 668 | break; |
| 669 | } |
| 670 | |
Andy Grover | dc58f76 | 2015-08-24 10:26:05 -0700 | [diff] [blame] | 671 | rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 672 | (conn->network_transport == ISCSI_TCP) ? |
| 673 | "TCP" : "SCTP"); |
| 674 | rb += sprintf(page+rb, " StatSN: 0x%08x\n", |
| 675 | conn->stat_sn); |
| 676 | } |
| 677 | spin_unlock(&sess->conn_lock); |
| 678 | } |
| 679 | spin_unlock_bh(&se_nacl->nacl_sess_lock); |
| 680 | |
| 681 | return rb; |
| 682 | } |
| 683 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 684 | static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item, |
| 685 | char *page) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 686 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 687 | return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 688 | } |
| 689 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 690 | static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item, |
| 691 | const char *page, size_t count) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 692 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 693 | struct se_node_acl *se_nacl = acl_to_nacl(item); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 694 | struct se_portal_group *se_tpg = se_nacl->se_tpg; |
| 695 | struct iscsi_portal_group *tpg = container_of(se_tpg, |
| 696 | struct iscsi_portal_group, tpg_se_tpg); |
| 697 | struct config_item *acl_ci, *tpg_ci, *wwn_ci; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 698 | u32 cmdsn_depth = 0; |
| 699 | int ret; |
| 700 | |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 701 | ret = kstrtou32(page, 0, &cmdsn_depth); |
| 702 | if (ret) |
| 703 | return ret; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 704 | if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) { |
| 705 | pr_err("Passed cmdsn_depth: %u exceeds" |
| 706 | " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth, |
| 707 | TA_DEFAULT_CMDSN_DEPTH_MAX); |
| 708 | return -EINVAL; |
| 709 | } |
| 710 | acl_ci = &se_nacl->acl_group.cg_item; |
| 711 | if (!acl_ci) { |
| 712 | pr_err("Unable to locatel acl_ci\n"); |
| 713 | return -EINVAL; |
| 714 | } |
| 715 | tpg_ci = &acl_ci->ci_parent->ci_group->cg_item; |
| 716 | if (!tpg_ci) { |
| 717 | pr_err("Unable to locate tpg_ci\n"); |
| 718 | return -EINVAL; |
| 719 | } |
| 720 | wwn_ci = &tpg_ci->ci_group->cg_item; |
| 721 | if (!wwn_ci) { |
| 722 | pr_err("Unable to locate config_item wwn_ci\n"); |
| 723 | return -EINVAL; |
| 724 | } |
| 725 | |
| 726 | if (iscsit_get_tpg(tpg) < 0) |
| 727 | return -EINVAL; |
| 728 | /* |
| 729 | * iscsit_tpg_set_initiator_node_queue_depth() assumes force=1 |
| 730 | */ |
| 731 | ret = iscsit_tpg_set_initiator_node_queue_depth(tpg, |
| 732 | config_item_name(acl_ci), cmdsn_depth, 1); |
| 733 | |
| 734 | pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for" |
| 735 | "InitiatorName: %s\n", config_item_name(wwn_ci), |
| 736 | config_item_name(tpg_ci), cmdsn_depth, |
| 737 | config_item_name(acl_ci)); |
| 738 | |
| 739 | iscsit_put_tpg(tpg); |
| 740 | return (!ret) ? count : (ssize_t)ret; |
| 741 | } |
| 742 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 743 | static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page) |
Andy Grover | 79e62fc | 2012-12-11 16:30:53 -0800 | [diff] [blame] | 744 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 745 | return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag); |
Andy Grover | 79e62fc | 2012-12-11 16:30:53 -0800 | [diff] [blame] | 746 | } |
| 747 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 748 | static ssize_t lio_target_nacl_tag_store(struct config_item *item, |
| 749 | const char *page, size_t count) |
Andy Grover | 79e62fc | 2012-12-11 16:30:53 -0800 | [diff] [blame] | 750 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 751 | struct se_node_acl *se_nacl = acl_to_nacl(item); |
Andy Grover | 79e62fc | 2012-12-11 16:30:53 -0800 | [diff] [blame] | 752 | int ret; |
| 753 | |
| 754 | ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page); |
| 755 | |
| 756 | if (ret < 0) |
| 757 | return ret; |
| 758 | return count; |
| 759 | } |
| 760 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 761 | CONFIGFS_ATTR_RO(lio_target_nacl_, info); |
| 762 | CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth); |
| 763 | CONFIGFS_ATTR(lio_target_nacl_, tag); |
Andy Grover | 79e62fc | 2012-12-11 16:30:53 -0800 | [diff] [blame] | 764 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 765 | static struct configfs_attribute *lio_target_initiator_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 766 | &lio_target_nacl_attr_info, |
| 767 | &lio_target_nacl_attr_cmdsn_depth, |
| 768 | &lio_target_nacl_attr_tag, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 769 | NULL, |
| 770 | }; |
| 771 | |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 772 | static int lio_target_init_nodeacl(struct se_node_acl *se_nacl, |
| 773 | const char *name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 774 | { |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 775 | struct iscsi_node_acl *acl = |
| 776 | container_of(se_nacl, struct iscsi_node_acl, se_node_acl); |
| 777 | struct config_group *stats_cg = &se_nacl->acl_fabric_stat_group; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 778 | |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 779 | stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 780 | GFP_KERNEL); |
| 781 | if (!stats_cg->default_groups) { |
| 782 | pr_err("Unable to allocate memory for" |
| 783 | " stats_cg->default_groups\n"); |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 784 | return -ENOMEM; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 785 | } |
| 786 | |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 787 | stats_cg->default_groups[0] = &acl->node_stat_grps.iscsi_sess_stats_group; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 788 | stats_cg->default_groups[1] = NULL; |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 789 | config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 790 | "iscsi_sess_stats", &iscsi_stat_sess_cit); |
| 791 | |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 792 | return 0; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 795 | static void lio_target_cleanup_nodeacl( struct se_node_acl *se_nacl) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 796 | { |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 797 | struct iscsi_node_acl *acl = container_of(se_nacl, |
| 798 | struct iscsi_node_acl, se_node_acl); |
| 799 | struct config_item *df_item; |
| 800 | struct config_group *stats_cg; |
| 801 | int i; |
| 802 | |
| 803 | stats_cg = &acl->se_node_acl.acl_fabric_stat_group; |
| 804 | for (i = 0; stats_cg->default_groups[i]; i++) { |
| 805 | df_item = &stats_cg->default_groups[i]->cg_item; |
| 806 | stats_cg->default_groups[i] = NULL; |
| 807 | config_item_put(df_item); |
| 808 | } |
| 809 | kfree(stats_cg->default_groups); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 810 | } |
| 811 | |
| 812 | /* End items for lio_target_acl_cit */ |
| 813 | |
| 814 | /* Start items for lio_target_tpg_attrib_cit */ |
| 815 | |
| 816 | #define DEF_TPG_ATTRIB(name) \ |
| 817 | \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 818 | static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \ |
| 819 | char *page) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 820 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 821 | struct se_portal_group *se_tpg = attrib_to_tpg(item); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 822 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 823 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 824 | ssize_t rb; \ |
| 825 | \ |
| 826 | if (iscsit_get_tpg(tpg) < 0) \ |
| 827 | return -EINVAL; \ |
| 828 | \ |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 829 | rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 830 | iscsit_put_tpg(tpg); \ |
| 831 | return rb; \ |
| 832 | } \ |
| 833 | \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 834 | static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\ |
| 835 | const char *page, size_t count) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 836 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 837 | struct se_portal_group *se_tpg = attrib_to_tpg(item); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 838 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 839 | struct iscsi_portal_group, tpg_se_tpg); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 840 | u32 val; \ |
| 841 | int ret; \ |
| 842 | \ |
| 843 | if (iscsit_get_tpg(tpg) < 0) \ |
| 844 | return -EINVAL; \ |
| 845 | \ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 846 | ret = kstrtou32(page, 0, &val); \ |
| 847 | if (ret) \ |
| 848 | goto out; \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 849 | ret = iscsit_ta_##name(tpg, val); \ |
| 850 | if (ret < 0) \ |
| 851 | goto out; \ |
| 852 | \ |
| 853 | iscsit_put_tpg(tpg); \ |
| 854 | return count; \ |
| 855 | out: \ |
| 856 | iscsit_put_tpg(tpg); \ |
| 857 | return ret; \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 858 | } \ |
| 859 | CONFIGFS_ATTR(iscsi_tpg_attrib_, name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 860 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 861 | DEF_TPG_ATTRIB(authentication); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 862 | DEF_TPG_ATTRIB(login_timeout); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 863 | DEF_TPG_ATTRIB(netif_timeout); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 864 | DEF_TPG_ATTRIB(generate_node_acls); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 865 | DEF_TPG_ATTRIB(default_cmdsn_depth); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 866 | DEF_TPG_ATTRIB(cache_dynamic_acls); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 867 | DEF_TPG_ATTRIB(demo_mode_write_protect); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 868 | DEF_TPG_ATTRIB(prod_mode_write_protect); |
Thomas Glanzmann | 4c54b6c | 2013-10-07 23:12:11 +0200 | [diff] [blame] | 869 | DEF_TPG_ATTRIB(demo_mode_discovery); |
Nicholas Bellinger | d1fa7a1 | 2013-11-20 11:57:18 -0800 | [diff] [blame] | 870 | DEF_TPG_ATTRIB(default_erl); |
Sagi Grimberg | 8085176 | 2014-02-19 17:50:20 +0200 | [diff] [blame] | 871 | DEF_TPG_ATTRIB(t10_pi); |
Nicholas Bellinger | 901c04a | 2015-03-29 19:36:16 -0700 | [diff] [blame] | 872 | DEF_TPG_ATTRIB(fabric_prot_type); |
David Disseldorp | a6415cd | 2015-08-01 00:10:12 -0700 | [diff] [blame] | 873 | DEF_TPG_ATTRIB(tpg_enabled_sendtargets); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 874 | |
| 875 | static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 876 | &iscsi_tpg_attrib_attr_authentication, |
| 877 | &iscsi_tpg_attrib_attr_login_timeout, |
| 878 | &iscsi_tpg_attrib_attr_netif_timeout, |
| 879 | &iscsi_tpg_attrib_attr_generate_node_acls, |
| 880 | &iscsi_tpg_attrib_attr_default_cmdsn_depth, |
| 881 | &iscsi_tpg_attrib_attr_cache_dynamic_acls, |
| 882 | &iscsi_tpg_attrib_attr_demo_mode_write_protect, |
| 883 | &iscsi_tpg_attrib_attr_prod_mode_write_protect, |
| 884 | &iscsi_tpg_attrib_attr_demo_mode_discovery, |
| 885 | &iscsi_tpg_attrib_attr_default_erl, |
| 886 | &iscsi_tpg_attrib_attr_t10_pi, |
| 887 | &iscsi_tpg_attrib_attr_fabric_prot_type, |
| 888 | &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 889 | NULL, |
| 890 | }; |
| 891 | |
| 892 | /* End items for lio_target_tpg_attrib_cit */ |
| 893 | |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 894 | /* Start items for lio_target_tpg_auth_cit */ |
| 895 | |
| 896 | #define __DEF_TPG_AUTH_STR(prefix, name, flags) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 897 | static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \ |
| 898 | char *page) \ |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 899 | { \ |
| 900 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 901 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 902 | struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ |
| 903 | \ |
| 904 | if (!capable(CAP_SYS_ADMIN)) \ |
| 905 | return -EPERM; \ |
| 906 | \ |
| 907 | return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ |
| 908 | } \ |
| 909 | \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 910 | static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\ |
| 911 | const char *page, size_t count) \ |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 912 | { \ |
| 913 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 914 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 915 | struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ |
| 916 | \ |
| 917 | if (!capable(CAP_SYS_ADMIN)) \ |
| 918 | return -EPERM; \ |
| 919 | \ |
Nicholas Bellinger | 37b32c6 | 2013-07-06 16:48:55 -0700 | [diff] [blame] | 920 | snprintf(auth->name, sizeof(auth->name), "%s", page); \ |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 921 | if (!(strncmp("NULL", auth->name, 4))) \ |
| 922 | auth->naf_flags &= ~flags; \ |
| 923 | else \ |
| 924 | auth->naf_flags |= flags; \ |
| 925 | \ |
| 926 | if ((auth->naf_flags & NAF_USERID_IN_SET) && \ |
| 927 | (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ |
| 928 | auth->authenticate_target = 1; \ |
| 929 | else \ |
| 930 | auth->authenticate_target = 0; \ |
| 931 | \ |
| 932 | return count; \ |
| 933 | } |
| 934 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 935 | #define DEF_TPG_AUTH_STR(name, flags) \ |
| 936 | __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \ |
| 937 | static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \ |
| 938 | char *page) \ |
| 939 | { \ |
| 940 | return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \ |
| 941 | } \ |
| 942 | \ |
| 943 | static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \ |
| 944 | const char *page, size_t count) \ |
| 945 | { \ |
| 946 | return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \ |
| 947 | } \ |
| 948 | \ |
| 949 | CONFIGFS_ATTR(iscsi_tpg_auth_, name); |
| 950 | |
| 951 | |
| 952 | DEF_TPG_AUTH_STR(userid, NAF_USERID_SET); |
| 953 | DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET); |
| 954 | DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); |
| 955 | DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); |
| 956 | |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 957 | #define __DEF_TPG_AUTH_INT(prefix, name) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 958 | static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \ |
| 959 | char *page) \ |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 960 | { \ |
| 961 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 962 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 963 | struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ |
| 964 | \ |
| 965 | if (!capable(CAP_SYS_ADMIN)) \ |
| 966 | return -EPERM; \ |
| 967 | \ |
| 968 | return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ |
| 969 | } |
| 970 | |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 971 | #define DEF_TPG_AUTH_INT(name) \ |
| 972 | __DEF_TPG_AUTH_INT(tpg_auth, name) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 973 | static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \ |
| 974 | char *page) \ |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 975 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 976 | return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \ |
| 977 | } \ |
| 978 | CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name); |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 979 | |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 980 | DEF_TPG_AUTH_INT(authenticate_target); |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 981 | |
| 982 | static struct configfs_attribute *lio_target_tpg_auth_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 983 | &iscsi_tpg_auth_attr_userid, |
| 984 | &iscsi_tpg_auth_attr_password, |
| 985 | &iscsi_tpg_auth_attr_authenticate_target, |
| 986 | &iscsi_tpg_auth_attr_userid_mutual, |
| 987 | &iscsi_tpg_auth_attr_password_mutual, |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 988 | NULL, |
| 989 | }; |
| 990 | |
| 991 | /* End items for lio_target_tpg_auth_cit */ |
| 992 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 993 | /* Start items for lio_target_tpg_param_cit */ |
| 994 | |
| 995 | #define DEF_TPG_PARAM(name) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 996 | static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \ |
| 997 | char *page) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 998 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 999 | struct se_portal_group *se_tpg = param_to_tpg(item); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1000 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 1001 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 1002 | struct iscsi_param *param; \ |
| 1003 | ssize_t rb; \ |
| 1004 | \ |
| 1005 | if (iscsit_get_tpg(tpg) < 0) \ |
| 1006 | return -EINVAL; \ |
| 1007 | \ |
| 1008 | param = iscsi_find_param_from_key(__stringify(name), \ |
| 1009 | tpg->param_list); \ |
| 1010 | if (!param) { \ |
| 1011 | iscsit_put_tpg(tpg); \ |
| 1012 | return -EINVAL; \ |
| 1013 | } \ |
| 1014 | rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \ |
| 1015 | \ |
| 1016 | iscsit_put_tpg(tpg); \ |
| 1017 | return rb; \ |
| 1018 | } \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1019 | static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \ |
| 1020 | const char *page, size_t count) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1021 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1022 | struct se_portal_group *se_tpg = param_to_tpg(item); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1023 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 1024 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 1025 | char *buf; \ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1026 | int ret, len; \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1027 | \ |
| 1028 | buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \ |
| 1029 | if (!buf) \ |
| 1030 | return -ENOMEM; \ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1031 | len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \ |
| 1032 | if (isspace(buf[len-1])) \ |
| 1033 | buf[len-1] = '\0'; /* Kill newline */ \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1034 | \ |
| 1035 | if (iscsit_get_tpg(tpg) < 0) { \ |
| 1036 | kfree(buf); \ |
| 1037 | return -EINVAL; \ |
| 1038 | } \ |
| 1039 | \ |
| 1040 | ret = iscsi_change_param_value(buf, tpg->param_list, 1); \ |
| 1041 | if (ret < 0) \ |
| 1042 | goto out; \ |
| 1043 | \ |
| 1044 | kfree(buf); \ |
| 1045 | iscsit_put_tpg(tpg); \ |
| 1046 | return count; \ |
| 1047 | out: \ |
| 1048 | kfree(buf); \ |
| 1049 | iscsit_put_tpg(tpg); \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1050 | return -EINVAL; \ |
| 1051 | } \ |
| 1052 | CONFIGFS_ATTR(iscsi_tpg_param_, name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1053 | |
| 1054 | DEF_TPG_PARAM(AuthMethod); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1055 | DEF_TPG_PARAM(HeaderDigest); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1056 | DEF_TPG_PARAM(DataDigest); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1057 | DEF_TPG_PARAM(MaxConnections); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1058 | DEF_TPG_PARAM(TargetAlias); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1059 | DEF_TPG_PARAM(InitialR2T); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1060 | DEF_TPG_PARAM(ImmediateData); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1061 | DEF_TPG_PARAM(MaxRecvDataSegmentLength); |
Nicholas Bellinger | e004cb2 | 2012-09-29 21:47:16 -0700 | [diff] [blame] | 1062 | DEF_TPG_PARAM(MaxXmitDataSegmentLength); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1063 | DEF_TPG_PARAM(MaxBurstLength); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1064 | DEF_TPG_PARAM(FirstBurstLength); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1065 | DEF_TPG_PARAM(DefaultTime2Wait); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1066 | DEF_TPG_PARAM(DefaultTime2Retain); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1067 | DEF_TPG_PARAM(MaxOutstandingR2T); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1068 | DEF_TPG_PARAM(DataPDUInOrder); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1069 | DEF_TPG_PARAM(DataSequenceInOrder); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1070 | DEF_TPG_PARAM(ErrorRecoveryLevel); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1071 | DEF_TPG_PARAM(IFMarker); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1072 | DEF_TPG_PARAM(OFMarker); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1073 | DEF_TPG_PARAM(IFMarkInt); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1074 | DEF_TPG_PARAM(OFMarkInt); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1075 | |
| 1076 | static struct configfs_attribute *lio_target_tpg_param_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1077 | &iscsi_tpg_param_attr_AuthMethod, |
| 1078 | &iscsi_tpg_param_attr_HeaderDigest, |
| 1079 | &iscsi_tpg_param_attr_DataDigest, |
| 1080 | &iscsi_tpg_param_attr_MaxConnections, |
| 1081 | &iscsi_tpg_param_attr_TargetAlias, |
| 1082 | &iscsi_tpg_param_attr_InitialR2T, |
| 1083 | &iscsi_tpg_param_attr_ImmediateData, |
| 1084 | &iscsi_tpg_param_attr_MaxRecvDataSegmentLength, |
| 1085 | &iscsi_tpg_param_attr_MaxXmitDataSegmentLength, |
| 1086 | &iscsi_tpg_param_attr_MaxBurstLength, |
| 1087 | &iscsi_tpg_param_attr_FirstBurstLength, |
| 1088 | &iscsi_tpg_param_attr_DefaultTime2Wait, |
| 1089 | &iscsi_tpg_param_attr_DefaultTime2Retain, |
| 1090 | &iscsi_tpg_param_attr_MaxOutstandingR2T, |
| 1091 | &iscsi_tpg_param_attr_DataPDUInOrder, |
| 1092 | &iscsi_tpg_param_attr_DataSequenceInOrder, |
| 1093 | &iscsi_tpg_param_attr_ErrorRecoveryLevel, |
| 1094 | &iscsi_tpg_param_attr_IFMarker, |
| 1095 | &iscsi_tpg_param_attr_OFMarker, |
| 1096 | &iscsi_tpg_param_attr_IFMarkInt, |
| 1097 | &iscsi_tpg_param_attr_OFMarkInt, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1098 | NULL, |
| 1099 | }; |
| 1100 | |
| 1101 | /* End items for lio_target_tpg_param_cit */ |
| 1102 | |
| 1103 | /* Start items for lio_target_tpg_cit */ |
| 1104 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1105 | static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1106 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1107 | struct se_portal_group *se_tpg = to_tpg(item); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1108 | struct iscsi_portal_group *tpg = container_of(se_tpg, |
| 1109 | struct iscsi_portal_group, tpg_se_tpg); |
| 1110 | ssize_t len; |
| 1111 | |
| 1112 | spin_lock(&tpg->tpg_state_lock); |
| 1113 | len = sprintf(page, "%d\n", |
| 1114 | (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0); |
| 1115 | spin_unlock(&tpg->tpg_state_lock); |
| 1116 | |
| 1117 | return len; |
| 1118 | } |
| 1119 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1120 | static ssize_t lio_target_tpg_enable_store(struct config_item *item, |
| 1121 | const char *page, size_t count) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1122 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1123 | struct se_portal_group *se_tpg = to_tpg(item); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1124 | struct iscsi_portal_group *tpg = container_of(se_tpg, |
| 1125 | struct iscsi_portal_group, tpg_se_tpg); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1126 | u32 op; |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1127 | int ret; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1128 | |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1129 | ret = kstrtou32(page, 0, &op); |
| 1130 | if (ret) |
| 1131 | return ret; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1132 | if ((op != 1) && (op != 0)) { |
| 1133 | pr_err("Illegal value for tpg_enable: %u\n", op); |
| 1134 | return -EINVAL; |
| 1135 | } |
| 1136 | |
| 1137 | ret = iscsit_get_tpg(tpg); |
| 1138 | if (ret < 0) |
| 1139 | return -EINVAL; |
| 1140 | |
| 1141 | if (op) { |
| 1142 | ret = iscsit_tpg_enable_portal_group(tpg); |
| 1143 | if (ret < 0) |
| 1144 | goto out; |
| 1145 | } else { |
| 1146 | /* |
| 1147 | * iscsit_tpg_disable_portal_group() assumes force=1 |
| 1148 | */ |
| 1149 | ret = iscsit_tpg_disable_portal_group(tpg, 1); |
| 1150 | if (ret < 0) |
| 1151 | goto out; |
| 1152 | } |
| 1153 | |
| 1154 | iscsit_put_tpg(tpg); |
| 1155 | return count; |
| 1156 | out: |
| 1157 | iscsit_put_tpg(tpg); |
| 1158 | return -EINVAL; |
| 1159 | } |
| 1160 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1161 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1162 | static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item, |
| 1163 | char *page) |
Nicholas Bellinger | d4ee46f | 2015-03-06 20:40:57 -0800 | [diff] [blame] | 1164 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1165 | return target_show_dynamic_sessions(to_tpg(item), page); |
Nicholas Bellinger | d4ee46f | 2015-03-06 20:40:57 -0800 | [diff] [blame] | 1166 | } |
| 1167 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1168 | CONFIGFS_ATTR(lio_target_tpg_, enable); |
| 1169 | CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions); |
Nicholas Bellinger | d4ee46f | 2015-03-06 20:40:57 -0800 | [diff] [blame] | 1170 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1171 | static struct configfs_attribute *lio_target_tpg_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1172 | &lio_target_tpg_attr_enable, |
| 1173 | &lio_target_tpg_attr_dynamic_sessions, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1174 | NULL, |
| 1175 | }; |
| 1176 | |
| 1177 | /* End items for lio_target_tpg_cit */ |
| 1178 | |
| 1179 | /* Start items for lio_target_tiqn_cit */ |
| 1180 | |
Christoph Hellwig | fceb5bc | 2012-09-26 08:00:36 -0400 | [diff] [blame] | 1181 | static struct se_portal_group *lio_target_tiqn_addtpg( |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1182 | struct se_wwn *wwn, |
| 1183 | struct config_group *group, |
| 1184 | const char *name) |
| 1185 | { |
| 1186 | struct iscsi_portal_group *tpg; |
| 1187 | struct iscsi_tiqn *tiqn; |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1188 | char *tpgt_str; |
| 1189 | int ret; |
| 1190 | u16 tpgt; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1191 | |
| 1192 | tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); |
| 1193 | /* |
| 1194 | * Only tpgt_# directory groups can be created below |
| 1195 | * target/iscsi/iqn.superturodiskarry/ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1196 | */ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1197 | tpgt_str = strstr(name, "tpgt_"); |
| 1198 | if (!tpgt_str) { |
| 1199 | pr_err("Unable to locate \"tpgt_#\" directory" |
| 1200 | " group\n"); |
| 1201 | return NULL; |
| 1202 | } |
| 1203 | tpgt_str += 5; /* Skip ahead of "tpgt_" */ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1204 | ret = kstrtou16(tpgt_str, 0, &tpgt); |
| 1205 | if (ret) |
| 1206 | return NULL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1207 | |
| 1208 | tpg = iscsit_alloc_portal_group(tiqn, tpgt); |
| 1209 | if (!tpg) |
| 1210 | return NULL; |
| 1211 | |
Nicholas Bellinger | bc0c94b | 2015-05-20 21:48:03 -0700 | [diff] [blame] | 1212 | ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1213 | if (ret < 0) |
| 1214 | return NULL; |
| 1215 | |
| 1216 | ret = iscsit_tpg_add_portal_group(tiqn, tpg); |
| 1217 | if (ret != 0) |
| 1218 | goto out; |
| 1219 | |
| 1220 | pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); |
| 1221 | pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n", |
| 1222 | name); |
| 1223 | return &tpg->tpg_se_tpg; |
| 1224 | out: |
| 1225 | core_tpg_deregister(&tpg->tpg_se_tpg); |
| 1226 | kfree(tpg); |
| 1227 | return NULL; |
| 1228 | } |
| 1229 | |
Christoph Hellwig | fceb5bc | 2012-09-26 08:00:36 -0400 | [diff] [blame] | 1230 | static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1231 | { |
| 1232 | struct iscsi_portal_group *tpg; |
| 1233 | struct iscsi_tiqn *tiqn; |
| 1234 | |
| 1235 | tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); |
| 1236 | tiqn = tpg->tpg_tiqn; |
| 1237 | /* |
| 1238 | * iscsit_tpg_del_portal_group() assumes force=1 |
| 1239 | */ |
| 1240 | pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n"); |
| 1241 | iscsit_tpg_del_portal_group(tiqn, tpg, 1); |
| 1242 | } |
| 1243 | |
| 1244 | /* End items for lio_target_tiqn_cit */ |
| 1245 | |
| 1246 | /* Start LIO-Target TIQN struct contig_item lio_target_cit */ |
| 1247 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1248 | static ssize_t lio_target_wwn_lio_version_show(struct config_item *item, |
| 1249 | char *page) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1250 | { |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 1251 | return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n"); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1252 | } |
| 1253 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1254 | CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1255 | |
| 1256 | static struct configfs_attribute *lio_target_wwn_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1257 | &lio_target_wwn_attr_lio_version, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1258 | NULL, |
| 1259 | }; |
| 1260 | |
Christoph Hellwig | fceb5bc | 2012-09-26 08:00:36 -0400 | [diff] [blame] | 1261 | static struct se_wwn *lio_target_call_coreaddtiqn( |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1262 | struct target_fabric_configfs *tf, |
| 1263 | struct config_group *group, |
| 1264 | const char *name) |
| 1265 | { |
| 1266 | struct config_group *stats_cg; |
| 1267 | struct iscsi_tiqn *tiqn; |
| 1268 | |
| 1269 | tiqn = iscsit_add_tiqn((unsigned char *)name); |
| 1270 | if (IS_ERR(tiqn)) |
Thomas Meyer | e1750ba | 2011-08-01 23:58:18 +0200 | [diff] [blame] | 1271 | return ERR_CAST(tiqn); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1272 | /* |
| 1273 | * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group. |
| 1274 | */ |
| 1275 | stats_cg = &tiqn->tiqn_wwn.fabric_stat_group; |
| 1276 | |
Sebastian Andrzej Siewior | 13f6a91 | 2012-11-27 18:54:21 +0100 | [diff] [blame] | 1277 | stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1278 | GFP_KERNEL); |
| 1279 | if (!stats_cg->default_groups) { |
| 1280 | pr_err("Unable to allocate memory for" |
| 1281 | " stats_cg->default_groups\n"); |
| 1282 | iscsit_del_tiqn(tiqn); |
| 1283 | return ERR_PTR(-ENOMEM); |
| 1284 | } |
| 1285 | |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 1286 | stats_cg->default_groups[0] = &tiqn->tiqn_stat_grps.iscsi_instance_group; |
| 1287 | stats_cg->default_groups[1] = &tiqn->tiqn_stat_grps.iscsi_sess_err_group; |
| 1288 | stats_cg->default_groups[2] = &tiqn->tiqn_stat_grps.iscsi_tgt_attr_group; |
| 1289 | stats_cg->default_groups[3] = &tiqn->tiqn_stat_grps.iscsi_login_stats_group; |
| 1290 | stats_cg->default_groups[4] = &tiqn->tiqn_stat_grps.iscsi_logout_stats_group; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1291 | stats_cg->default_groups[5] = NULL; |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 1292 | config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1293 | "iscsi_instance", &iscsi_stat_instance_cit); |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 1294 | config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1295 | "iscsi_sess_err", &iscsi_stat_sess_err_cit); |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 1296 | config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1297 | "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit); |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 1298 | config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1299 | "iscsi_login_stats", &iscsi_stat_login_cit); |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 1300 | config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1301 | "iscsi_logout_stats", &iscsi_stat_logout_cit); |
| 1302 | |
| 1303 | pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); |
| 1304 | pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:" |
| 1305 | " %s\n", name); |
| 1306 | return &tiqn->tiqn_wwn; |
| 1307 | } |
| 1308 | |
Christoph Hellwig | fceb5bc | 2012-09-26 08:00:36 -0400 | [diff] [blame] | 1309 | static void lio_target_call_coredeltiqn( |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1310 | struct se_wwn *wwn) |
| 1311 | { |
| 1312 | struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); |
| 1313 | struct config_item *df_item; |
| 1314 | struct config_group *stats_cg; |
| 1315 | int i; |
| 1316 | |
| 1317 | stats_cg = &tiqn->tiqn_wwn.fabric_stat_group; |
| 1318 | for (i = 0; stats_cg->default_groups[i]; i++) { |
| 1319 | df_item = &stats_cg->default_groups[i]->cg_item; |
| 1320 | stats_cg->default_groups[i] = NULL; |
| 1321 | config_item_put(df_item); |
| 1322 | } |
| 1323 | kfree(stats_cg->default_groups); |
| 1324 | |
| 1325 | pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n", |
| 1326 | tiqn->tiqn); |
| 1327 | iscsit_del_tiqn(tiqn); |
| 1328 | } |
| 1329 | |
| 1330 | /* End LIO-Target TIQN struct contig_lio_target_cit */ |
| 1331 | |
| 1332 | /* Start lio_target_discovery_auth_cit */ |
| 1333 | |
| 1334 | #define DEF_DISC_AUTH_STR(name, flags) \ |
| 1335 | __DEF_NACL_AUTH_STR(disc, name, flags) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1336 | static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1337 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1338 | return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1339 | page); \ |
| 1340 | } \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1341 | static ssize_t iscsi_disc_##name##_store(struct config_item *item, \ |
| 1342 | const char *page, size_t count) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1343 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1344 | return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1345 | page, count); \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1346 | \ |
| 1347 | } \ |
| 1348 | CONFIGFS_ATTR(iscsi_disc_, name) |
| 1349 | |
| 1350 | DEF_DISC_AUTH_STR(userid, NAF_USERID_SET); |
| 1351 | DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET); |
| 1352 | DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); |
| 1353 | DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1354 | |
| 1355 | #define DEF_DISC_AUTH_INT(name) \ |
| 1356 | __DEF_NACL_AUTH_INT(disc, name) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1357 | static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1358 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1359 | return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1360 | page); \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1361 | } \ |
| 1362 | CONFIGFS_ATTR_RO(iscsi_disc_, name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1363 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1364 | DEF_DISC_AUTH_INT(authenticate_target); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1365 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1366 | |
| 1367 | static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item, |
| 1368 | char *page) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1369 | { |
| 1370 | struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth; |
| 1371 | |
| 1372 | return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth); |
| 1373 | } |
| 1374 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1375 | static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item, |
| 1376 | const char *page, size_t count) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1377 | { |
| 1378 | struct iscsi_param *param; |
| 1379 | struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1380 | u32 op; |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1381 | int err; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1382 | |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1383 | err = kstrtou32(page, 0, &op); |
| 1384 | if (err) |
| 1385 | return -EINVAL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1386 | if ((op != 1) && (op != 0)) { |
| 1387 | pr_err("Illegal value for enforce_discovery_auth:" |
| 1388 | " %u\n", op); |
| 1389 | return -EINVAL; |
| 1390 | } |
| 1391 | |
| 1392 | if (!discovery_tpg) { |
| 1393 | pr_err("iscsit_global->discovery_tpg is NULL\n"); |
| 1394 | return -EINVAL; |
| 1395 | } |
| 1396 | |
| 1397 | param = iscsi_find_param_from_key(AUTHMETHOD, |
| 1398 | discovery_tpg->param_list); |
| 1399 | if (!param) |
| 1400 | return -EINVAL; |
| 1401 | |
| 1402 | if (op) { |
| 1403 | /* |
| 1404 | * Reset the AuthMethod key to CHAP. |
| 1405 | */ |
| 1406 | if (iscsi_update_param_value(param, CHAP) < 0) |
| 1407 | return -EINVAL; |
| 1408 | |
| 1409 | discovery_tpg->tpg_attrib.authentication = 1; |
| 1410 | iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1; |
| 1411 | pr_debug("LIO-CORE[0] Successfully enabled" |
| 1412 | " authentication enforcement for iSCSI" |
| 1413 | " Discovery TPG\n"); |
| 1414 | } else { |
| 1415 | /* |
| 1416 | * Reset the AuthMethod key to CHAP,None |
| 1417 | */ |
| 1418 | if (iscsi_update_param_value(param, "CHAP,None") < 0) |
| 1419 | return -EINVAL; |
| 1420 | |
| 1421 | discovery_tpg->tpg_attrib.authentication = 0; |
| 1422 | iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0; |
| 1423 | pr_debug("LIO-CORE[0] Successfully disabled" |
| 1424 | " authentication enforcement for iSCSI" |
| 1425 | " Discovery TPG\n"); |
| 1426 | } |
| 1427 | |
| 1428 | return count; |
| 1429 | } |
| 1430 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1431 | CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1432 | |
| 1433 | static struct configfs_attribute *lio_target_discovery_auth_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1434 | &iscsi_disc_attr_userid, |
| 1435 | &iscsi_disc_attr_password, |
| 1436 | &iscsi_disc_attr_authenticate_target, |
| 1437 | &iscsi_disc_attr_userid_mutual, |
| 1438 | &iscsi_disc_attr_password_mutual, |
| 1439 | &iscsi_disc_attr_enforce_discovery_auth, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1440 | NULL, |
| 1441 | }; |
| 1442 | |
| 1443 | /* End lio_target_discovery_auth_cit */ |
| 1444 | |
| 1445 | /* Start functions for target_core_fabric_ops */ |
| 1446 | |
| 1447 | static char *iscsi_get_fabric_name(void) |
| 1448 | { |
| 1449 | return "iSCSI"; |
| 1450 | } |
| 1451 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1452 | static int iscsi_get_cmd_state(struct se_cmd *se_cmd) |
| 1453 | { |
| 1454 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1455 | |
| 1456 | return cmd->i_state; |
| 1457 | } |
| 1458 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1459 | static u32 lio_sess_get_index(struct se_session *se_sess) |
| 1460 | { |
| 1461 | struct iscsi_session *sess = se_sess->fabric_sess_ptr; |
| 1462 | |
| 1463 | return sess->session_index; |
| 1464 | } |
| 1465 | |
| 1466 | static u32 lio_sess_get_initiator_sid( |
| 1467 | struct se_session *se_sess, |
| 1468 | unsigned char *buf, |
| 1469 | u32 size) |
| 1470 | { |
| 1471 | struct iscsi_session *sess = se_sess->fabric_sess_ptr; |
| 1472 | /* |
| 1473 | * iSCSI Initiator Session Identifier from RFC-3720. |
| 1474 | */ |
Andy Shevchenko | 5cdf5a8 | 2015-01-15 13:40:56 +0200 | [diff] [blame] | 1475 | return snprintf(buf, size, "%6phN", sess->isid); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | static int lio_queue_data_in(struct se_cmd *se_cmd) |
| 1479 | { |
| 1480 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1481 | |
| 1482 | cmd->i_state = ISTATE_SEND_DATAIN; |
Nicholas Bellinger | 2ec5a8c | 2013-03-20 15:29:15 -0700 | [diff] [blame] | 1483 | cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd); |
| 1484 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1485 | return 0; |
| 1486 | } |
| 1487 | |
| 1488 | static int lio_write_pending(struct se_cmd *se_cmd) |
| 1489 | { |
| 1490 | 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] | 1491 | struct iscsi_conn *conn = cmd->conn; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1492 | |
| 1493 | if (!cmd->immediate_data && !cmd->unsolicited_data) |
Nicholas Bellinger | 3e1c81a | 2013-03-06 22:18:24 -0800 | [diff] [blame] | 1494 | return conn->conn_transport->iscsit_get_dataout(conn, cmd, false); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1495 | |
| 1496 | return 0; |
| 1497 | } |
| 1498 | |
| 1499 | static int lio_write_pending_status(struct se_cmd *se_cmd) |
| 1500 | { |
| 1501 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1502 | int ret; |
| 1503 | |
| 1504 | spin_lock_bh(&cmd->istate_lock); |
| 1505 | ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT); |
| 1506 | spin_unlock_bh(&cmd->istate_lock); |
| 1507 | |
| 1508 | return ret; |
| 1509 | } |
| 1510 | |
| 1511 | static int lio_queue_status(struct se_cmd *se_cmd) |
| 1512 | { |
| 1513 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1514 | |
| 1515 | cmd->i_state = ISTATE_SEND_STATUS; |
Nicholas Bellinger | 5e8e6b4 | 2013-11-12 17:54:56 -0800 | [diff] [blame] | 1516 | |
| 1517 | if (cmd->se_cmd.scsi_status || cmd->sense_reason) { |
| 1518 | iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state); |
| 1519 | return 0; |
| 1520 | } |
Nicholas Bellinger | 2ec5a8c | 2013-03-20 15:29:15 -0700 | [diff] [blame] | 1521 | cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd); |
| 1522 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1523 | return 0; |
| 1524 | } |
| 1525 | |
Joern Engel | b79fafa | 2013-07-03 11:22:17 -0400 | [diff] [blame] | 1526 | static void lio_queue_tm_rsp(struct se_cmd *se_cmd) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1527 | { |
| 1528 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1529 | |
| 1530 | cmd->i_state = ISTATE_SEND_TASKMGTRSP; |
| 1531 | iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
Nicholas Bellinger | 131e6ab | 2014-03-22 14:55:56 -0700 | [diff] [blame] | 1534 | static void lio_aborted_task(struct se_cmd *se_cmd) |
| 1535 | { |
| 1536 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1537 | |
| 1538 | cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd); |
| 1539 | } |
| 1540 | |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1541 | static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg) |
| 1542 | { |
| 1543 | return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); |
| 1544 | } |
| 1545 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1546 | static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg) |
| 1547 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1548 | return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1549 | } |
| 1550 | |
| 1551 | static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg) |
| 1552 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1553 | return iscsi_tpg(se_tpg)->tpgt; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg) |
| 1557 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1558 | return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg) |
| 1562 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1563 | return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg) |
| 1567 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1568 | return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | static int lio_tpg_check_demo_mode_write_protect( |
| 1572 | struct se_portal_group *se_tpg) |
| 1573 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1574 | return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | static int lio_tpg_check_prod_mode_write_protect( |
| 1578 | struct se_portal_group *se_tpg) |
| 1579 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1580 | return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1581 | } |
| 1582 | |
Nicholas Bellinger | 901c04a | 2015-03-29 19:36:16 -0700 | [diff] [blame] | 1583 | static int lio_tpg_check_prot_fabric_only( |
| 1584 | struct se_portal_group *se_tpg) |
| 1585 | { |
Nicholas Bellinger | 901c04a | 2015-03-29 19:36:16 -0700 | [diff] [blame] | 1586 | /* |
| 1587 | * Only report fabric_prot_type if t10_pi has also been enabled |
| 1588 | * for incoming ib_isert sessions. |
| 1589 | */ |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1590 | if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi) |
Nicholas Bellinger | 901c04a | 2015-03-29 19:36:16 -0700 | [diff] [blame] | 1591 | return 0; |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1592 | return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type; |
Nicholas Bellinger | 901c04a | 2015-03-29 19:36:16 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1595 | /* |
| 1596 | * Called with spin_lock_bh(struct se_portal_group->session_lock) held.. |
| 1597 | * |
| 1598 | * Also, this function calls iscsit_inc_session_usage_count() on the |
| 1599 | * struct iscsi_session in question. |
| 1600 | */ |
| 1601 | static int lio_tpg_shutdown_session(struct se_session *se_sess) |
| 1602 | { |
| 1603 | struct iscsi_session *sess = se_sess->fabric_sess_ptr; |
| 1604 | |
| 1605 | spin_lock(&sess->conn_lock); |
| 1606 | if (atomic_read(&sess->session_fall_back_to_erl0) || |
| 1607 | atomic_read(&sess->session_logout) || |
| 1608 | (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) { |
| 1609 | spin_unlock(&sess->conn_lock); |
| 1610 | return 0; |
| 1611 | } |
| 1612 | atomic_set(&sess->session_reinstatement, 1); |
| 1613 | spin_unlock(&sess->conn_lock); |
| 1614 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1615 | iscsit_stop_time2retain_timer(sess); |
Nicholas Bellinger | 99367f0 | 2012-02-27 01:43:32 -0800 | [diff] [blame] | 1616 | iscsit_stop_session(sess, 1, 1); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1617 | |
| 1618 | return 1; |
| 1619 | } |
| 1620 | |
| 1621 | /* |
| 1622 | * Calls iscsit_dec_session_usage_count() as inverse of |
| 1623 | * lio_tpg_shutdown_session() |
| 1624 | */ |
| 1625 | static void lio_tpg_close_session(struct se_session *se_sess) |
| 1626 | { |
| 1627 | struct iscsi_session *sess = se_sess->fabric_sess_ptr; |
| 1628 | /* |
| 1629 | * If the iSCSI Session for the iSCSI Initiator Node exists, |
| 1630 | * forcefully shutdown the iSCSI NEXUS. |
| 1631 | */ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1632 | iscsit_close_session(sess); |
| 1633 | } |
| 1634 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1635 | static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg) |
| 1636 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1637 | return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | static void lio_set_default_node_attributes(struct se_node_acl *se_acl) |
| 1641 | { |
| 1642 | struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl, |
| 1643 | se_node_acl); |
Nicholas Bellinger | d1fa7a1 | 2013-11-20 11:57:18 -0800 | [diff] [blame] | 1644 | struct se_portal_group *se_tpg = se_acl->se_tpg; |
| 1645 | struct iscsi_portal_group *tpg = container_of(se_tpg, |
| 1646 | struct iscsi_portal_group, tpg_se_tpg); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1647 | |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 1648 | acl->node_attrib.nacl = acl; |
Nicholas Bellinger | d1fa7a1 | 2013-11-20 11:57:18 -0800 | [diff] [blame] | 1649 | iscsit_set_default_node_attribues(acl, tpg); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1650 | } |
| 1651 | |
Nicholas Bellinger | 3e1c81a | 2013-03-06 22:18:24 -0800 | [diff] [blame] | 1652 | static int lio_check_stop_free(struct se_cmd *se_cmd) |
| 1653 | { |
Bart Van Assche | afc1660 | 2015-04-27 13:52:36 +0200 | [diff] [blame] | 1654 | return target_put_sess_cmd(se_cmd); |
Nicholas Bellinger | 3e1c81a | 2013-03-06 22:18:24 -0800 | [diff] [blame] | 1655 | } |
| 1656 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1657 | static void lio_release_cmd(struct se_cmd *se_cmd) |
| 1658 | { |
| 1659 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1660 | |
Nicholas Bellinger | cdb7266 | 2013-03-06 22:09:17 -0800 | [diff] [blame] | 1661 | pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd); |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1662 | iscsit_release_cmd(cmd); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1665 | const struct target_core_fabric_ops iscsi_ops = { |
| 1666 | .module = THIS_MODULE, |
| 1667 | .name = "iscsi", |
Christoph Hellwig | 144bc4c | 2015-04-13 19:51:16 +0200 | [diff] [blame] | 1668 | .node_acl_size = sizeof(struct iscsi_node_acl), |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1669 | .get_fabric_name = iscsi_get_fabric_name, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1670 | .tpg_get_wwn = lio_tpg_get_endpoint_wwn, |
| 1671 | .tpg_get_tag = lio_tpg_get_tag, |
| 1672 | .tpg_get_default_depth = lio_tpg_get_default_depth, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1673 | .tpg_check_demo_mode = lio_tpg_check_demo_mode, |
| 1674 | .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache, |
| 1675 | .tpg_check_demo_mode_write_protect = |
| 1676 | lio_tpg_check_demo_mode_write_protect, |
| 1677 | .tpg_check_prod_mode_write_protect = |
| 1678 | lio_tpg_check_prod_mode_write_protect, |
| 1679 | .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1680 | .tpg_get_inst_index = lio_tpg_get_inst_index, |
| 1681 | .check_stop_free = lio_check_stop_free, |
| 1682 | .release_cmd = lio_release_cmd, |
| 1683 | .shutdown_session = lio_tpg_shutdown_session, |
| 1684 | .close_session = lio_tpg_close_session, |
| 1685 | .sess_get_index = lio_sess_get_index, |
| 1686 | .sess_get_initiator_sid = lio_sess_get_initiator_sid, |
| 1687 | .write_pending = lio_write_pending, |
| 1688 | .write_pending_status = lio_write_pending_status, |
| 1689 | .set_default_node_attributes = lio_set_default_node_attributes, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1690 | .get_cmd_state = iscsi_get_cmd_state, |
| 1691 | .queue_data_in = lio_queue_data_in, |
| 1692 | .queue_status = lio_queue_status, |
| 1693 | .queue_tm_rsp = lio_queue_tm_rsp, |
| 1694 | .aborted_task = lio_aborted_task, |
| 1695 | .fabric_make_wwn = lio_target_call_coreaddtiqn, |
| 1696 | .fabric_drop_wwn = lio_target_call_coredeltiqn, |
| 1697 | .fabric_make_tpg = lio_target_tiqn_addtpg, |
| 1698 | .fabric_drop_tpg = lio_target_tiqn_deltpg, |
| 1699 | .fabric_make_np = lio_target_call_addnptotpg, |
| 1700 | .fabric_drop_np = lio_target_call_delnpfromtpg, |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 1701 | .fabric_init_nodeacl = lio_target_init_nodeacl, |
| 1702 | .fabric_cleanup_nodeacl = lio_target_cleanup_nodeacl, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1703 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1704 | .tfc_discovery_attrs = lio_target_discovery_auth_attrs, |
| 1705 | .tfc_wwn_attrs = lio_target_wwn_attrs, |
| 1706 | .tfc_tpg_base_attrs = lio_target_tpg_attrs, |
| 1707 | .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs, |
| 1708 | .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs, |
| 1709 | .tfc_tpg_param_attrs = lio_target_tpg_param_attrs, |
| 1710 | .tfc_tpg_np_base_attrs = lio_target_portal_attrs, |
| 1711 | .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs, |
| 1712 | .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs, |
| 1713 | .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs, |
| 1714 | .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs, |
| 1715 | }; |