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