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