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