blob: 8a4bc15bc3f565aa94c5146668943d204389f377 [file] [log] [blame]
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001/*******************************************************************************
2 * This file contains the configfs implementation for iSCSI Target mode
3 * from the LIO-Target Project.
4 *
Nicholas Bellinger4c762512013-09-05 15:29:12 -07005 * (c) Copyright 2007-2013 Datera, Inc.
Nicholas Bellingere48354c2011-07-23 06:43:04 +00006 *
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 Engelad7babd2013-07-03 11:35:11 -040021#include <linux/ctype.h>
Paul Gortmakerc53181a2011-08-30 18:16:43 -040022#include <linux/export.h>
Stephen Rothwellc3bc93d2012-01-23 11:39:49 +110023#include <linux/inet.h>
Nicholas Bellingere48354c2011-07-23 06:43:04 +000024#include <target/target_core_base.h>
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050025#include <target/target_core_fabric.h>
Nicholas Bellinger2ec5a8c2013-03-20 15:29:15 -070026#include <target/iscsi/iscsi_transport.h>
Nicholas Bellingere48354c2011-07-23 06:43:04 +000027
Sagi Grimberg67f091f2015-01-07 14:57:31 +020028#include <target/iscsi/iscsi_target_core.h>
Nicholas Bellingere48354c2011-07-23 06:43:04 +000029#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 Grimberg67f091f2015-01-07 14:57:31 +020036#include <target/iscsi/iscsi_target_stat.h>
Nicholas Bellingere48354c2011-07-23 06:43:04 +000037
Nicholas Bellingere48354c2011-07-23 06:43:04 +000038
Nicholas Bellingere48354c2011-07-23 06:43:04 +000039/* Start items for lio_target_portal_cit */
40
Christoph Hellwig2eafd722015-10-03 15:32:55 +020041static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item)
Nicholas Bellingere48354c2011-07-23 06:43:04 +000042{
Christoph Hellwig2eafd722015-10-03 15:32:55 +020043 return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np);
44}
45
Nicholas Bellingerd4b3fa42016-05-14 21:44:01 -070046static ssize_t lio_target_np_driver_show(struct config_item *item, char *page,
47 enum iscsit_transport_type type)
Christoph Hellwig2eafd722015-10-03 15:32:55 +020048{
49 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
Nicholas Bellingerd4b3fa42016-05-14 21:44:01 -070050 struct iscsi_tpg_np *tpg_np_new;
Nicholas Bellingere48354c2011-07-23 06:43:04 +000051 ssize_t rb;
52
Nicholas Bellingerd4b3fa42016-05-14 21:44:01 -070053 tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
54 if (tpg_np_new)
Nicholas Bellingere48354c2011-07-23 06:43:04 +000055 rb = sprintf(page, "1\n");
56 else
57 rb = sprintf(page, "0\n");
58
59 return rb;
60}
61
Nicholas Bellingerd4b3fa42016-05-14 21:44:01 -070062static 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 Bellingere48354c2011-07-23 06:43:04 +000065{
Christoph Hellwig2eafd722015-10-03 15:32:55 +020066 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +000067 struct iscsi_np *np;
68 struct iscsi_portal_group *tpg;
Nicholas Bellingerd4b3fa42016-05-14 21:44:01 -070069 struct iscsi_tpg_np *tpg_np_new = NULL;
Nicholas Bellingere48354c2011-07-23 06:43:04 +000070 u32 op;
Nicholas Bellingerd4b3fa42016-05-14 21:44:01 -070071 int rc;
Nicholas Bellingere48354c2011-07-23 06:43:04 +000072
Nicholas Bellingerd4b3fa42016-05-14 21:44:01 -070073 rc = kstrtou32(page, 0, &op);
74 if (rc)
75 return rc;
Nicholas Bellingere48354c2011-07-23 06:43:04 +000076 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 Bellingerd4b3fa42016-05-14 21:44:01 -070092 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 Grover58bd0c62013-05-29 12:05:59 -070099 }
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800100
Nicholas Bellingerd4b3fa42016-05-14 21:44:01 -0700101 tpg_np_new = iscsit_tpg_add_network_portal(tpg,
102 &np->np_sockaddr, tpg_np, type);
Varun Prakash8032a302016-12-11 22:05:56 +0530103 if (IS_ERR(tpg_np_new)) {
104 rc = PTR_ERR(tpg_np_new);
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800105 goto out;
Varun Prakash8032a302016-12-11 22:05:56 +0530106 }
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800107 } else {
Nicholas Bellingerd4b3fa42016-05-14 21:44:01 -0700108 tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
109 if (tpg_np_new) {
110 rc = iscsit_tpg_del_network_portal(tpg, tpg_np_new);
Andy Grover58bd0c62013-05-29 12:05:59 -0700111 if (rc < 0)
112 goto out;
113 }
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800114 }
115
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800116 iscsit_put_tpg(tpg);
117 return count;
118out:
119 iscsit_put_tpg(tpg);
Andy Grover58bd0c62013-05-29 12:05:59 -0700120 return rc;
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800121}
122
Nicholas Bellingerd4b3fa42016-05-14 21:44:01 -0700123static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
Varun Prakash1c469602016-04-20 00:00:16 +0530124{
Nicholas Bellingerd4b3fa42016-05-14 21:44:01 -0700125 return lio_target_np_driver_show(item, page, ISCSI_INFINIBAND);
126}
Varun Prakash1c469602016-04-20 00:00:16 +0530127
Nicholas Bellingerd4b3fa42016-05-14 21:44:01 -0700128static ssize_t lio_target_np_iser_store(struct config_item *item,
129 const char *page, size_t count)
130{
131 return lio_target_np_driver_store(item, page, count,
132 ISCSI_INFINIBAND, "ib_isert");
133}
134CONFIGFS_ATTR(lio_target_np_, iser);
Varun Prakash1c469602016-04-20 00:00:16 +0530135
Nicholas Bellingerff7199b2016-05-14 22:28:51 -0700136static ssize_t lio_target_np_cxgbit_show(struct config_item *item, char *page)
Nicholas Bellingerd4b3fa42016-05-14 21:44:01 -0700137{
Nicholas Bellingerff7199b2016-05-14 22:28:51 -0700138 return lio_target_np_driver_show(item, page, ISCSI_CXGBIT);
Varun Prakash1c469602016-04-20 00:00:16 +0530139}
140
Nicholas Bellingerff7199b2016-05-14 22:28:51 -0700141static ssize_t lio_target_np_cxgbit_store(struct config_item *item,
142 const char *page, size_t count)
Varun Prakash1c469602016-04-20 00:00:16 +0530143{
Nicholas Bellingerd4b3fa42016-05-14 21:44:01 -0700144 return lio_target_np_driver_store(item, page, count,
Nicholas Bellingerff7199b2016-05-14 22:28:51 -0700145 ISCSI_CXGBIT, "cxgbit");
Varun Prakash1c469602016-04-20 00:00:16 +0530146}
Nicholas Bellingerff7199b2016-05-14 22:28:51 -0700147CONFIGFS_ATTR(lio_target_np_, cxgbit);
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800148
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000149static struct configfs_attribute *lio_target_portal_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200150 &lio_target_np_attr_iser,
Nicholas Bellingerff7199b2016-05-14 22:28:51 -0700151 &lio_target_np_attr_cxgbit,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000152 NULL,
153};
154
155/* Stop items for lio_target_portal_cit */
156
157/* Start items for lio_target_np_cit */
158
159#define MAX_PORTAL_LEN 256
160
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -0400161static struct se_tpg_np *lio_target_call_addnptotpg(
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000162 struct se_portal_group *se_tpg,
163 struct config_group *group,
164 const char *name)
165{
166 struct iscsi_portal_group *tpg;
167 struct iscsi_tpg_np *tpg_np;
168 char *str, *str2, *ip_str, *port_str;
Andy Grover13a3cf02015-08-24 10:26:06 -0700169 struct sockaddr_storage sockaddr;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000170 struct sockaddr_in *sock_in;
171 struct sockaddr_in6 *sock_in6;
172 unsigned long port;
173 int ret;
174 char buf[MAX_PORTAL_LEN + 1];
175
176 if (strlen(name) > MAX_PORTAL_LEN) {
177 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
178 (int)strlen(name), MAX_PORTAL_LEN);
179 return ERR_PTR(-EOVERFLOW);
180 }
181 memset(buf, 0, MAX_PORTAL_LEN + 1);
Nicholas Bellinger7bbb6542011-07-27 12:37:03 -0700182 snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000183
Andy Grover13a3cf02015-08-24 10:26:06 -0700184 memset(&sockaddr, 0, sizeof(struct sockaddr_storage));
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000185
186 str = strstr(buf, "[");
187 if (str) {
188 const char *end;
189
190 str2 = strstr(str, "]");
191 if (!str2) {
192 pr_err("Unable to locate trailing \"]\""
193 " in IPv6 iSCSI network portal address\n");
194 return ERR_PTR(-EINVAL);
195 }
196 str++; /* Skip over leading "[" */
Andy Grover76c28f12015-08-24 10:26:03 -0700197 *str2 = '\0'; /* Terminate the unbracketed IPv6 address */
198 str2++; /* Skip over the \0 */
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000199 port_str = strstr(str2, ":");
200 if (!port_str) {
201 pr_err("Unable to locate \":port\""
202 " in IPv6 iSCSI network portal address\n");
203 return ERR_PTR(-EINVAL);
204 }
205 *port_str = '\0'; /* Terminate string for IP */
206 port_str++; /* Skip over ":" */
207
Jingoo Han57103d72013-07-19 16:22:19 +0900208 ret = kstrtoul(port_str, 0, &port);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000209 if (ret < 0) {
Jingoo Han57103d72013-07-19 16:22:19 +0900210 pr_err("kstrtoul() failed for port_str: %d\n", ret);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000211 return ERR_PTR(ret);
212 }
213 sock_in6 = (struct sockaddr_in6 *)&sockaddr;
214 sock_in6->sin6_family = AF_INET6;
215 sock_in6->sin6_port = htons((unsigned short)port);
Andy Groverdc58f762015-08-24 10:26:05 -0700216 ret = in6_pton(str, -1,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000217 (void *)&sock_in6->sin6_addr.in6_u, -1, &end);
218 if (ret <= 0) {
219 pr_err("in6_pton returned: %d\n", ret);
220 return ERR_PTR(-EINVAL);
221 }
222 } else {
223 str = ip_str = &buf[0];
224 port_str = strstr(ip_str, ":");
225 if (!port_str) {
226 pr_err("Unable to locate \":port\""
227 " in IPv4 iSCSI network portal address\n");
228 return ERR_PTR(-EINVAL);
229 }
230 *port_str = '\0'; /* Terminate string for IP */
231 port_str++; /* Skip over ":" */
232
Jingoo Han57103d72013-07-19 16:22:19 +0900233 ret = kstrtoul(port_str, 0, &port);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000234 if (ret < 0) {
Jingoo Han57103d72013-07-19 16:22:19 +0900235 pr_err("kstrtoul() failed for port_str: %d\n", ret);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000236 return ERR_PTR(ret);
237 }
238 sock_in = (struct sockaddr_in *)&sockaddr;
239 sock_in->sin_family = AF_INET;
240 sock_in->sin_port = htons((unsigned short)port);
241 sock_in->sin_addr.s_addr = in_aton(ip_str);
242 }
243 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
244 ret = iscsit_get_tpg(tpg);
245 if (ret < 0)
246 return ERR_PTR(-EINVAL);
247
248 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
249 " PORTAL: %s\n",
250 config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
251 tpg->tpgt, name);
252 /*
253 * Assume ISCSI_TCP by default. Other network portals for other
254 * iSCSI fabrics:
255 *
256 * Traditional iSCSI over SCTP (initial support)
257 * iSER/TCP (TODO, hardware available)
258 * iSER/SCTP (TODO, software emulation with osc-iwarp)
259 * iSER/IB (TODO, hardware available)
260 *
Masanari Iida20879692012-08-27 22:46:00 +0900261 * can be enabled with attributes under
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000262 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
263 *
264 */
Andy Grover76c28f12015-08-24 10:26:03 -0700265 tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000266 ISCSI_TCP);
267 if (IS_ERR(tpg_np)) {
268 iscsit_put_tpg(tpg);
Thomas Meyere1750ba2011-08-01 23:58:18 +0200269 return ERR_CAST(tpg_np);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000270 }
271 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
272
273 iscsit_put_tpg(tpg);
274 return &tpg_np->se_tpg_np;
275}
276
277static void lio_target_call_delnpfromtpg(
278 struct se_tpg_np *se_tpg_np)
279{
280 struct iscsi_portal_group *tpg;
281 struct iscsi_tpg_np *tpg_np;
282 struct se_portal_group *se_tpg;
283 int ret;
284
285 tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
286 tpg = tpg_np->tpg;
287 ret = iscsit_get_tpg(tpg);
288 if (ret < 0)
289 return;
290
291 se_tpg = &tpg->tpg_se_tpg;
292 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
Andy Grover69d75572015-08-24 10:26:04 -0700293 " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
294 tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000295
296 ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
297 if (ret < 0)
298 goto out;
299
300 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
301out:
302 iscsit_put_tpg(tpg);
303}
304
305/* End items for lio_target_np_cit */
306
307/* Start items for lio_target_nacl_attrib_cit */
308
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200309#define ISCSI_NACL_ATTR(name) \
310static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
311 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000312{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200313 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000314 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
315 se_node_acl); \
316 \
Andy Groverb7eec2c2013-10-09 11:05:57 -0700317 return sprintf(page, "%u\n", nacl->node_attrib.name); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000318} \
319 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200320static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
321 const char *page, size_t count) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000322{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200323 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000324 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
325 se_node_acl); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000326 u32 val; \
327 int ret; \
328 \
Jörn Engelad7babd2013-07-03 11:35:11 -0400329 ret = kstrtou32(page, 0, &val); \
330 if (ret) \
331 return ret; \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000332 ret = iscsit_na_##name(nacl, val); \
333 if (ret < 0) \
334 return ret; \
335 \
336 return count; \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200337} \
338 \
339CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000340
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200341ISCSI_NACL_ATTR(dataout_timeout);
342ISCSI_NACL_ATTR(dataout_timeout_retries);
343ISCSI_NACL_ATTR(default_erl);
344ISCSI_NACL_ATTR(nopin_timeout);
345ISCSI_NACL_ATTR(nopin_response_timeout);
346ISCSI_NACL_ATTR(random_datain_pdu_offsets);
347ISCSI_NACL_ATTR(random_datain_seq_offsets);
348ISCSI_NACL_ATTR(random_r2t_offsets);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000349
350static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200351 &iscsi_nacl_attrib_attr_dataout_timeout,
352 &iscsi_nacl_attrib_attr_dataout_timeout_retries,
353 &iscsi_nacl_attrib_attr_default_erl,
354 &iscsi_nacl_attrib_attr_nopin_timeout,
355 &iscsi_nacl_attrib_attr_nopin_response_timeout,
356 &iscsi_nacl_attrib_attr_random_datain_pdu_offsets,
357 &iscsi_nacl_attrib_attr_random_datain_seq_offsets,
358 &iscsi_nacl_attrib_attr_random_r2t_offsets,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000359 NULL,
360};
361
362/* End items for lio_target_nacl_attrib_cit */
363
364/* Start items for lio_target_nacl_auth_cit */
365
366#define __DEF_NACL_AUTH_STR(prefix, name, flags) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200367static ssize_t __iscsi_##prefix##_##name##_show( \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000368 struct iscsi_node_acl *nacl, \
369 char *page) \
370{ \
371 struct iscsi_node_auth *auth = &nacl->node_auth; \
372 \
373 if (!capable(CAP_SYS_ADMIN)) \
374 return -EPERM; \
375 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
376} \
377 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200378static ssize_t __iscsi_##prefix##_##name##_store( \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000379 struct iscsi_node_acl *nacl, \
380 const char *page, \
381 size_t count) \
382{ \
383 struct iscsi_node_auth *auth = &nacl->node_auth; \
384 \
385 if (!capable(CAP_SYS_ADMIN)) \
386 return -EPERM; \
Eric Seppanen2306bfb2013-11-21 14:49:56 -0800387 if (count >= sizeof(auth->name)) \
388 return -EINVAL; \
Jörn Engel0fbfc462013-07-03 11:35:11 -0400389 snprintf(auth->name, sizeof(auth->name), "%s", page); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000390 if (!strncmp("NULL", auth->name, 4)) \
391 auth->naf_flags &= ~flags; \
392 else \
393 auth->naf_flags |= flags; \
394 \
395 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
396 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
397 auth->authenticate_target = 1; \
398 else \
399 auth->authenticate_target = 0; \
400 \
401 return count; \
402}
403
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200404#define DEF_NACL_AUTH_STR(name, flags) \
405 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
406static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
407 char *page) \
408{ \
409 struct se_node_acl *nacl = auth_to_nacl(item); \
410 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
411 struct iscsi_node_acl, se_node_acl), page); \
412} \
413static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \
414 const char *page, size_t count) \
415{ \
416 struct se_node_acl *nacl = auth_to_nacl(item); \
417 return __iscsi_nacl_auth_##name##_store(container_of(nacl, \
418 struct iscsi_node_acl, se_node_acl), page, count); \
419} \
420 \
421CONFIGFS_ATTR(iscsi_nacl_auth_, name)
422
423/*
424 * One-way authentication userid
425 */
426DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
427DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
428DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
429DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
430
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000431#define __DEF_NACL_AUTH_INT(prefix, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200432static ssize_t __iscsi_##prefix##_##name##_show( \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000433 struct iscsi_node_acl *nacl, \
434 char *page) \
435{ \
436 struct iscsi_node_auth *auth = &nacl->node_auth; \
437 \
438 if (!capable(CAP_SYS_ADMIN)) \
439 return -EPERM; \
440 \
441 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
442}
443
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000444#define DEF_NACL_AUTH_INT(name) \
445 __DEF_NACL_AUTH_INT(nacl_auth, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200446static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
447 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000448{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200449 struct se_node_acl *nacl = auth_to_nacl(item); \
450 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
451 struct iscsi_node_acl, se_node_acl), page); \
452} \
453 \
454CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000455
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000456DEF_NACL_AUTH_INT(authenticate_target);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000457
458static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200459 &iscsi_nacl_auth_attr_userid,
460 &iscsi_nacl_auth_attr_password,
461 &iscsi_nacl_auth_attr_authenticate_target,
462 &iscsi_nacl_auth_attr_userid_mutual,
463 &iscsi_nacl_auth_attr_password_mutual,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000464 NULL,
465};
466
467/* End items for lio_target_nacl_auth_cit */
468
469/* Start items for lio_target_nacl_param_cit */
470
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200471#define ISCSI_NACL_PARAM(name) \
472static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \
473 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000474{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200475 struct se_node_acl *se_nacl = param_to_nacl(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000476 struct iscsi_session *sess; \
477 struct se_session *se_sess; \
478 ssize_t rb; \
479 \
480 spin_lock_bh(&se_nacl->nacl_sess_lock); \
481 se_sess = se_nacl->nacl_sess; \
482 if (!se_sess) { \
483 rb = snprintf(page, PAGE_SIZE, \
484 "No Active iSCSI Session\n"); \
485 } else { \
486 sess = se_sess->fabric_sess_ptr; \
487 rb = snprintf(page, PAGE_SIZE, "%u\n", \
488 (u32)sess->sess_ops->name); \
489 } \
490 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
491 \
492 return rb; \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200493} \
494 \
495CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000496
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200497ISCSI_NACL_PARAM(MaxConnections);
498ISCSI_NACL_PARAM(InitialR2T);
499ISCSI_NACL_PARAM(ImmediateData);
500ISCSI_NACL_PARAM(MaxBurstLength);
501ISCSI_NACL_PARAM(FirstBurstLength);
502ISCSI_NACL_PARAM(DefaultTime2Wait);
503ISCSI_NACL_PARAM(DefaultTime2Retain);
504ISCSI_NACL_PARAM(MaxOutstandingR2T);
505ISCSI_NACL_PARAM(DataPDUInOrder);
506ISCSI_NACL_PARAM(DataSequenceInOrder);
507ISCSI_NACL_PARAM(ErrorRecoveryLevel);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000508
509static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200510 &iscsi_nacl_param_attr_MaxConnections,
511 &iscsi_nacl_param_attr_InitialR2T,
512 &iscsi_nacl_param_attr_ImmediateData,
513 &iscsi_nacl_param_attr_MaxBurstLength,
514 &iscsi_nacl_param_attr_FirstBurstLength,
515 &iscsi_nacl_param_attr_DefaultTime2Wait,
516 &iscsi_nacl_param_attr_DefaultTime2Retain,
517 &iscsi_nacl_param_attr_MaxOutstandingR2T,
518 &iscsi_nacl_param_attr_DataPDUInOrder,
519 &iscsi_nacl_param_attr_DataSequenceInOrder,
520 &iscsi_nacl_param_attr_ErrorRecoveryLevel,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000521 NULL,
522};
523
524/* End items for lio_target_nacl_param_cit */
525
526/* Start items for lio_target_acl_cit */
527
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200528static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000529{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200530 struct se_node_acl *se_nacl = acl_to_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000531 struct iscsi_session *sess;
532 struct iscsi_conn *conn;
533 struct se_session *se_sess;
534 ssize_t rb = 0;
Roland Dreier109e2382015-07-23 14:53:32 -0700535 u32 max_cmd_sn;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000536
537 spin_lock_bh(&se_nacl->nacl_sess_lock);
538 se_sess = se_nacl->nacl_sess;
539 if (!se_sess) {
540 rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
541 " Endpoint: %s\n", se_nacl->initiatorname);
542 } else {
543 sess = se_sess->fabric_sess_ptr;
544
Joern Engelcb354842014-09-02 17:49:50 -0400545 rb += sprintf(page+rb, "InitiatorName: %s\n",
546 sess->sess_ops->InitiatorName);
547 rb += sprintf(page+rb, "InitiatorAlias: %s\n",
548 sess->sess_ops->InitiatorAlias);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000549
Andy Shevchenko5cdf5a82015-01-15 13:40:56 +0200550 rb += sprintf(page+rb,
551 "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ",
552 sess->sid, sess->isid, sess->tsih);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000553 rb += sprintf(page+rb, "SessionType: %s\n",
554 (sess->sess_ops->SessionType) ?
555 "Discovery" : "Normal");
556 rb += sprintf(page+rb, "Session State: ");
557 switch (sess->session_state) {
558 case TARG_SESS_STATE_FREE:
559 rb += sprintf(page+rb, "TARG_SESS_FREE\n");
560 break;
561 case TARG_SESS_STATE_ACTIVE:
562 rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
563 break;
564 case TARG_SESS_STATE_LOGGED_IN:
565 rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
566 break;
567 case TARG_SESS_STATE_FAILED:
568 rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
569 break;
570 case TARG_SESS_STATE_IN_CONTINUE:
571 rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
572 break;
573 default:
574 rb += sprintf(page+rb, "ERROR: Unknown Session"
575 " State!\n");
576 break;
577 }
578
579 rb += sprintf(page+rb, "---------------------[iSCSI Session"
580 " Values]-----------------------\n");
581 rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
582 " : MaxCmdSN : ITT : TTT\n");
Roland Dreier109e2382015-07-23 14:53:32 -0700583 max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000584 rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
585 " 0x%08x 0x%08x\n",
586 sess->cmdsn_window,
Roland Dreier109e2382015-07-23 14:53:32 -0700587 (max_cmd_sn - sess->exp_cmd_sn) + 1,
588 sess->exp_cmd_sn, max_cmd_sn,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000589 sess->init_task_tag, sess->targ_xfer_tag);
590 rb += sprintf(page+rb, "----------------------[iSCSI"
591 " Connections]-------------------------\n");
592
593 spin_lock(&sess->conn_lock);
594 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
595 rb += sprintf(page+rb, "CID: %hu Connection"
596 " State: ", conn->cid);
597 switch (conn->conn_state) {
598 case TARG_CONN_STATE_FREE:
599 rb += sprintf(page+rb,
600 "TARG_CONN_STATE_FREE\n");
601 break;
602 case TARG_CONN_STATE_XPT_UP:
603 rb += sprintf(page+rb,
604 "TARG_CONN_STATE_XPT_UP\n");
605 break;
606 case TARG_CONN_STATE_IN_LOGIN:
607 rb += sprintf(page+rb,
608 "TARG_CONN_STATE_IN_LOGIN\n");
609 break;
610 case TARG_CONN_STATE_LOGGED_IN:
611 rb += sprintf(page+rb,
612 "TARG_CONN_STATE_LOGGED_IN\n");
613 break;
614 case TARG_CONN_STATE_IN_LOGOUT:
615 rb += sprintf(page+rb,
616 "TARG_CONN_STATE_IN_LOGOUT\n");
617 break;
618 case TARG_CONN_STATE_LOGOUT_REQUESTED:
619 rb += sprintf(page+rb,
620 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
621 break;
622 case TARG_CONN_STATE_CLEANUP_WAIT:
623 rb += sprintf(page+rb,
624 "TARG_CONN_STATE_CLEANUP_WAIT\n");
625 break;
626 default:
627 rb += sprintf(page+rb,
628 "ERROR: Unknown Connection State!\n");
629 break;
630 }
631
Andy Groverdc58f762015-08-24 10:26:05 -0700632 rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000633 (conn->network_transport == ISCSI_TCP) ?
634 "TCP" : "SCTP");
635 rb += sprintf(page+rb, " StatSN: 0x%08x\n",
636 conn->stat_sn);
637 }
638 spin_unlock(&sess->conn_lock);
639 }
640 spin_unlock_bh(&se_nacl->nacl_sess_lock);
641
642 return rb;
643}
644
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200645static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
646 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000647{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200648 return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000649}
650
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200651static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
652 const char *page, size_t count)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000653{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200654 struct se_node_acl *se_nacl = acl_to_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000655 struct se_portal_group *se_tpg = se_nacl->se_tpg;
656 struct iscsi_portal_group *tpg = container_of(se_tpg,
657 struct iscsi_portal_group, tpg_se_tpg);
658 struct config_item *acl_ci, *tpg_ci, *wwn_ci;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000659 u32 cmdsn_depth = 0;
660 int ret;
661
Jörn Engelad7babd2013-07-03 11:35:11 -0400662 ret = kstrtou32(page, 0, &cmdsn_depth);
663 if (ret)
664 return ret;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000665 if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
666 pr_err("Passed cmdsn_depth: %u exceeds"
667 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
668 TA_DEFAULT_CMDSN_DEPTH_MAX);
669 return -EINVAL;
670 }
671 acl_ci = &se_nacl->acl_group.cg_item;
672 if (!acl_ci) {
673 pr_err("Unable to locatel acl_ci\n");
674 return -EINVAL;
675 }
676 tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
677 if (!tpg_ci) {
678 pr_err("Unable to locate tpg_ci\n");
679 return -EINVAL;
680 }
681 wwn_ci = &tpg_ci->ci_group->cg_item;
682 if (!wwn_ci) {
683 pr_err("Unable to locate config_item wwn_ci\n");
684 return -EINVAL;
685 }
686
687 if (iscsit_get_tpg(tpg) < 0)
688 return -EINVAL;
Nicholas Bellingerd36ad772016-01-07 22:15:06 -0800689
690 ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000691
692 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
693 "InitiatorName: %s\n", config_item_name(wwn_ci),
694 config_item_name(tpg_ci), cmdsn_depth,
695 config_item_name(acl_ci));
696
697 iscsit_put_tpg(tpg);
698 return (!ret) ? count : (ssize_t)ret;
699}
700
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200701static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
Andy Grover79e62fc2012-12-11 16:30:53 -0800702{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200703 return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
Andy Grover79e62fc2012-12-11 16:30:53 -0800704}
705
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200706static ssize_t lio_target_nacl_tag_store(struct config_item *item,
707 const char *page, size_t count)
Andy Grover79e62fc2012-12-11 16:30:53 -0800708{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200709 struct se_node_acl *se_nacl = acl_to_nacl(item);
Andy Grover79e62fc2012-12-11 16:30:53 -0800710 int ret;
711
712 ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
713
714 if (ret < 0)
715 return ret;
716 return count;
717}
718
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200719CONFIGFS_ATTR_RO(lio_target_nacl_, info);
720CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
721CONFIGFS_ATTR(lio_target_nacl_, tag);
Andy Grover79e62fc2012-12-11 16:30:53 -0800722
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000723static struct configfs_attribute *lio_target_initiator_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200724 &lio_target_nacl_attr_info,
725 &lio_target_nacl_attr_cmdsn_depth,
726 &lio_target_nacl_attr_tag,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000727 NULL,
728};
729
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200730static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
731 const char *name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000732{
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200733 struct iscsi_node_acl *acl =
734 container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000735
Andy Groverb7eec2c2013-10-09 11:05:57 -0700736 config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000737 "iscsi_sess_stats", &iscsi_stat_sess_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100738 configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group,
739 &se_nacl->acl_fabric_stat_group);
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200740 return 0;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000741}
742
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000743/* End items for lio_target_acl_cit */
744
745/* Start items for lio_target_tpg_attrib_cit */
746
747#define DEF_TPG_ATTRIB(name) \
748 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200749static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \
750 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000751{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200752 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000753 struct iscsi_portal_group *tpg = container_of(se_tpg, \
754 struct iscsi_portal_group, tpg_se_tpg); \
755 ssize_t rb; \
756 \
757 if (iscsit_get_tpg(tpg) < 0) \
758 return -EINVAL; \
759 \
Andy Groverb7eec2c2013-10-09 11:05:57 -0700760 rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000761 iscsit_put_tpg(tpg); \
762 return rb; \
763} \
764 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200765static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
766 const char *page, size_t count) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000767{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200768 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000769 struct iscsi_portal_group *tpg = container_of(se_tpg, \
770 struct iscsi_portal_group, tpg_se_tpg); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000771 u32 val; \
772 int ret; \
773 \
774 if (iscsit_get_tpg(tpg) < 0) \
775 return -EINVAL; \
776 \
Jörn Engelad7babd2013-07-03 11:35:11 -0400777 ret = kstrtou32(page, 0, &val); \
778 if (ret) \
779 goto out; \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000780 ret = iscsit_ta_##name(tpg, val); \
781 if (ret < 0) \
782 goto out; \
783 \
784 iscsit_put_tpg(tpg); \
785 return count; \
786out: \
787 iscsit_put_tpg(tpg); \
788 return ret; \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200789} \
790CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000791
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000792DEF_TPG_ATTRIB(authentication);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000793DEF_TPG_ATTRIB(login_timeout);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000794DEF_TPG_ATTRIB(netif_timeout);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000795DEF_TPG_ATTRIB(generate_node_acls);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000796DEF_TPG_ATTRIB(default_cmdsn_depth);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000797DEF_TPG_ATTRIB(cache_dynamic_acls);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000798DEF_TPG_ATTRIB(demo_mode_write_protect);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000799DEF_TPG_ATTRIB(prod_mode_write_protect);
Thomas Glanzmann4c54b6c2013-10-07 23:12:11 +0200800DEF_TPG_ATTRIB(demo_mode_discovery);
Nicholas Bellingerd1fa7a12013-11-20 11:57:18 -0800801DEF_TPG_ATTRIB(default_erl);
Sagi Grimberg80851762014-02-19 17:50:20 +0200802DEF_TPG_ATTRIB(t10_pi);
Nicholas Bellinger901c04a2015-03-29 19:36:16 -0700803DEF_TPG_ATTRIB(fabric_prot_type);
David Disseldorpa6415cd2015-08-01 00:10:12 -0700804DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
Nicholas Bellinger732e3c72017-07-07 14:45:49 -0700805DEF_TPG_ATTRIB(login_keys_workaround);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000806
807static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200808 &iscsi_tpg_attrib_attr_authentication,
809 &iscsi_tpg_attrib_attr_login_timeout,
810 &iscsi_tpg_attrib_attr_netif_timeout,
811 &iscsi_tpg_attrib_attr_generate_node_acls,
812 &iscsi_tpg_attrib_attr_default_cmdsn_depth,
813 &iscsi_tpg_attrib_attr_cache_dynamic_acls,
814 &iscsi_tpg_attrib_attr_demo_mode_write_protect,
815 &iscsi_tpg_attrib_attr_prod_mode_write_protect,
816 &iscsi_tpg_attrib_attr_demo_mode_discovery,
817 &iscsi_tpg_attrib_attr_default_erl,
818 &iscsi_tpg_attrib_attr_t10_pi,
819 &iscsi_tpg_attrib_attr_fabric_prot_type,
820 &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
Nicholas Bellinger732e3c72017-07-07 14:45:49 -0700821 &iscsi_tpg_attrib_attr_login_keys_workaround,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000822 NULL,
823};
824
825/* End items for lio_target_tpg_attrib_cit */
826
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700827/* Start items for lio_target_tpg_auth_cit */
828
829#define __DEF_TPG_AUTH_STR(prefix, name, flags) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200830static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
831 char *page) \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700832{ \
833 struct iscsi_portal_group *tpg = container_of(se_tpg, \
834 struct iscsi_portal_group, tpg_se_tpg); \
835 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
836 \
837 if (!capable(CAP_SYS_ADMIN)) \
838 return -EPERM; \
839 \
840 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
841} \
842 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200843static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
844 const char *page, size_t count) \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700845{ \
846 struct iscsi_portal_group *tpg = container_of(se_tpg, \
847 struct iscsi_portal_group, tpg_se_tpg); \
848 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
849 \
850 if (!capable(CAP_SYS_ADMIN)) \
851 return -EPERM; \
852 \
Nicholas Bellinger37b32c62013-07-06 16:48:55 -0700853 snprintf(auth->name, sizeof(auth->name), "%s", page); \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700854 if (!(strncmp("NULL", auth->name, 4))) \
855 auth->naf_flags &= ~flags; \
856 else \
857 auth->naf_flags |= flags; \
858 \
859 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
860 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
861 auth->authenticate_target = 1; \
862 else \
863 auth->authenticate_target = 0; \
864 \
865 return count; \
866}
867
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200868#define DEF_TPG_AUTH_STR(name, flags) \
869 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
870static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
871 char *page) \
872{ \
873 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
874} \
875 \
876static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \
877 const char *page, size_t count) \
878{ \
879 return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
880} \
881 \
882CONFIGFS_ATTR(iscsi_tpg_auth_, name);
883
884
885DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
886DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
887DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
888DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
889
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700890#define __DEF_TPG_AUTH_INT(prefix, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200891static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
892 char *page) \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700893{ \
894 struct iscsi_portal_group *tpg = container_of(se_tpg, \
895 struct iscsi_portal_group, tpg_se_tpg); \
896 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
897 \
898 if (!capable(CAP_SYS_ADMIN)) \
899 return -EPERM; \
900 \
901 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
902}
903
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700904#define DEF_TPG_AUTH_INT(name) \
905 __DEF_TPG_AUTH_INT(tpg_auth, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200906static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
907 char *page) \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700908{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200909 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
910} \
911CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700912
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700913DEF_TPG_AUTH_INT(authenticate_target);
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700914
915static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200916 &iscsi_tpg_auth_attr_userid,
917 &iscsi_tpg_auth_attr_password,
918 &iscsi_tpg_auth_attr_authenticate_target,
919 &iscsi_tpg_auth_attr_userid_mutual,
920 &iscsi_tpg_auth_attr_password_mutual,
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700921 NULL,
922};
923
924/* End items for lio_target_tpg_auth_cit */
925
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000926/* Start items for lio_target_tpg_param_cit */
927
928#define DEF_TPG_PARAM(name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200929static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \
930 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000931{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200932 struct se_portal_group *se_tpg = param_to_tpg(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000933 struct iscsi_portal_group *tpg = container_of(se_tpg, \
934 struct iscsi_portal_group, tpg_se_tpg); \
935 struct iscsi_param *param; \
936 ssize_t rb; \
937 \
938 if (iscsit_get_tpg(tpg) < 0) \
939 return -EINVAL; \
940 \
941 param = iscsi_find_param_from_key(__stringify(name), \
942 tpg->param_list); \
943 if (!param) { \
944 iscsit_put_tpg(tpg); \
945 return -EINVAL; \
946 } \
947 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
948 \
949 iscsit_put_tpg(tpg); \
950 return rb; \
951} \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200952static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
953 const char *page, size_t count) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000954{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200955 struct se_portal_group *se_tpg = param_to_tpg(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000956 struct iscsi_portal_group *tpg = container_of(se_tpg, \
957 struct iscsi_portal_group, tpg_se_tpg); \
958 char *buf; \
Jörn Engelad7babd2013-07-03 11:35:11 -0400959 int ret, len; \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000960 \
961 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
962 if (!buf) \
963 return -ENOMEM; \
Jörn Engelad7babd2013-07-03 11:35:11 -0400964 len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
965 if (isspace(buf[len-1])) \
966 buf[len-1] = '\0'; /* Kill newline */ \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000967 \
968 if (iscsit_get_tpg(tpg) < 0) { \
969 kfree(buf); \
970 return -EINVAL; \
971 } \
972 \
973 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
974 if (ret < 0) \
975 goto out; \
976 \
977 kfree(buf); \
978 iscsit_put_tpg(tpg); \
979 return count; \
980out: \
981 kfree(buf); \
982 iscsit_put_tpg(tpg); \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200983 return -EINVAL; \
984} \
985CONFIGFS_ATTR(iscsi_tpg_param_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000986
987DEF_TPG_PARAM(AuthMethod);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000988DEF_TPG_PARAM(HeaderDigest);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000989DEF_TPG_PARAM(DataDigest);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000990DEF_TPG_PARAM(MaxConnections);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000991DEF_TPG_PARAM(TargetAlias);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000992DEF_TPG_PARAM(InitialR2T);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000993DEF_TPG_PARAM(ImmediateData);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000994DEF_TPG_PARAM(MaxRecvDataSegmentLength);
Nicholas Bellingere004cb22012-09-29 21:47:16 -0700995DEF_TPG_PARAM(MaxXmitDataSegmentLength);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000996DEF_TPG_PARAM(MaxBurstLength);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000997DEF_TPG_PARAM(FirstBurstLength);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000998DEF_TPG_PARAM(DefaultTime2Wait);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000999DEF_TPG_PARAM(DefaultTime2Retain);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001000DEF_TPG_PARAM(MaxOutstandingR2T);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001001DEF_TPG_PARAM(DataPDUInOrder);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001002DEF_TPG_PARAM(DataSequenceInOrder);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001003DEF_TPG_PARAM(ErrorRecoveryLevel);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001004DEF_TPG_PARAM(IFMarker);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001005DEF_TPG_PARAM(OFMarker);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001006DEF_TPG_PARAM(IFMarkInt);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001007DEF_TPG_PARAM(OFMarkInt);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001008
1009static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001010 &iscsi_tpg_param_attr_AuthMethod,
1011 &iscsi_tpg_param_attr_HeaderDigest,
1012 &iscsi_tpg_param_attr_DataDigest,
1013 &iscsi_tpg_param_attr_MaxConnections,
1014 &iscsi_tpg_param_attr_TargetAlias,
1015 &iscsi_tpg_param_attr_InitialR2T,
1016 &iscsi_tpg_param_attr_ImmediateData,
1017 &iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
1018 &iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
1019 &iscsi_tpg_param_attr_MaxBurstLength,
1020 &iscsi_tpg_param_attr_FirstBurstLength,
1021 &iscsi_tpg_param_attr_DefaultTime2Wait,
1022 &iscsi_tpg_param_attr_DefaultTime2Retain,
1023 &iscsi_tpg_param_attr_MaxOutstandingR2T,
1024 &iscsi_tpg_param_attr_DataPDUInOrder,
1025 &iscsi_tpg_param_attr_DataSequenceInOrder,
1026 &iscsi_tpg_param_attr_ErrorRecoveryLevel,
1027 &iscsi_tpg_param_attr_IFMarker,
1028 &iscsi_tpg_param_attr_OFMarker,
1029 &iscsi_tpg_param_attr_IFMarkInt,
1030 &iscsi_tpg_param_attr_OFMarkInt,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001031 NULL,
1032};
1033
1034/* End items for lio_target_tpg_param_cit */
1035
1036/* Start items for lio_target_tpg_cit */
1037
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001038static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001039{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001040 struct se_portal_group *se_tpg = to_tpg(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001041 struct iscsi_portal_group *tpg = container_of(se_tpg,
1042 struct iscsi_portal_group, tpg_se_tpg);
1043 ssize_t len;
1044
1045 spin_lock(&tpg->tpg_state_lock);
1046 len = sprintf(page, "%d\n",
1047 (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1048 spin_unlock(&tpg->tpg_state_lock);
1049
1050 return len;
1051}
1052
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001053static ssize_t lio_target_tpg_enable_store(struct config_item *item,
1054 const char *page, size_t count)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001055{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001056 struct se_portal_group *se_tpg = to_tpg(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001057 struct iscsi_portal_group *tpg = container_of(se_tpg,
1058 struct iscsi_portal_group, tpg_se_tpg);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001059 u32 op;
Jörn Engelad7babd2013-07-03 11:35:11 -04001060 int ret;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001061
Jörn Engelad7babd2013-07-03 11:35:11 -04001062 ret = kstrtou32(page, 0, &op);
1063 if (ret)
1064 return ret;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001065 if ((op != 1) && (op != 0)) {
1066 pr_err("Illegal value for tpg_enable: %u\n", op);
1067 return -EINVAL;
1068 }
1069
1070 ret = iscsit_get_tpg(tpg);
1071 if (ret < 0)
1072 return -EINVAL;
1073
1074 if (op) {
1075 ret = iscsit_tpg_enable_portal_group(tpg);
1076 if (ret < 0)
1077 goto out;
1078 } else {
1079 /*
1080 * iscsit_tpg_disable_portal_group() assumes force=1
1081 */
1082 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1083 if (ret < 0)
1084 goto out;
1085 }
1086
1087 iscsit_put_tpg(tpg);
1088 return count;
1089out:
1090 iscsit_put_tpg(tpg);
1091 return -EINVAL;
1092}
1093
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001094
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001095static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
1096 char *page)
Nicholas Bellingerd4ee46f2015-03-06 20:40:57 -08001097{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001098 return target_show_dynamic_sessions(to_tpg(item), page);
Nicholas Bellingerd4ee46f2015-03-06 20:40:57 -08001099}
1100
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001101CONFIGFS_ATTR(lio_target_tpg_, enable);
1102CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
Nicholas Bellingerd4ee46f2015-03-06 20:40:57 -08001103
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001104static struct configfs_attribute *lio_target_tpg_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001105 &lio_target_tpg_attr_enable,
1106 &lio_target_tpg_attr_dynamic_sessions,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001107 NULL,
1108};
1109
1110/* End items for lio_target_tpg_cit */
1111
1112/* Start items for lio_target_tiqn_cit */
1113
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -04001114static struct se_portal_group *lio_target_tiqn_addtpg(
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001115 struct se_wwn *wwn,
1116 struct config_group *group,
1117 const char *name)
1118{
1119 struct iscsi_portal_group *tpg;
1120 struct iscsi_tiqn *tiqn;
Jörn Engelad7babd2013-07-03 11:35:11 -04001121 char *tpgt_str;
1122 int ret;
1123 u16 tpgt;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001124
1125 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1126 /*
1127 * Only tpgt_# directory groups can be created below
1128 * target/iscsi/iqn.superturodiskarry/
Jörn Engelad7babd2013-07-03 11:35:11 -04001129 */
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001130 tpgt_str = strstr(name, "tpgt_");
1131 if (!tpgt_str) {
1132 pr_err("Unable to locate \"tpgt_#\" directory"
1133 " group\n");
1134 return NULL;
1135 }
1136 tpgt_str += 5; /* Skip ahead of "tpgt_" */
Jörn Engelad7babd2013-07-03 11:35:11 -04001137 ret = kstrtou16(tpgt_str, 0, &tpgt);
1138 if (ret)
1139 return NULL;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001140
1141 tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1142 if (!tpg)
1143 return NULL;
1144
Nicholas Bellingerbc0c94b2015-05-20 21:48:03 -07001145 ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001146 if (ret < 0)
tangwenjia4f54ec2017-09-15 16:03:13 +08001147 goto free_out;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001148
1149 ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1150 if (ret != 0)
1151 goto out;
1152
1153 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1154 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1155 name);
1156 return &tpg->tpg_se_tpg;
1157out:
1158 core_tpg_deregister(&tpg->tpg_se_tpg);
tangwenjia4f54ec2017-09-15 16:03:13 +08001159free_out:
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001160 kfree(tpg);
1161 return NULL;
1162}
1163
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -04001164static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001165{
1166 struct iscsi_portal_group *tpg;
1167 struct iscsi_tiqn *tiqn;
1168
1169 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1170 tiqn = tpg->tpg_tiqn;
1171 /*
1172 * iscsit_tpg_del_portal_group() assumes force=1
1173 */
1174 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1175 iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1176}
1177
1178/* End items for lio_target_tiqn_cit */
1179
1180/* Start LIO-Target TIQN struct contig_item lio_target_cit */
1181
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001182static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
1183 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001184{
Nicholas Bellinger4c762512013-09-05 15:29:12 -07001185 return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001186}
1187
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001188CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001189
1190static struct configfs_attribute *lio_target_wwn_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001191 &lio_target_wwn_attr_lio_version,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001192 NULL,
1193};
1194
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -04001195static struct se_wwn *lio_target_call_coreaddtiqn(
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001196 struct target_fabric_configfs *tf,
1197 struct config_group *group,
1198 const char *name)
1199{
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001200 struct iscsi_tiqn *tiqn;
1201
1202 tiqn = iscsit_add_tiqn((unsigned char *)name);
1203 if (IS_ERR(tiqn))
Thomas Meyere1750ba2011-08-01 23:58:18 +02001204 return ERR_CAST(tiqn);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001205
Christoph Hellwig839559e2016-03-29 13:03:35 +02001206 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1207 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1208 " %s\n", name);
1209 return &tiqn->tiqn_wwn;
1210}
1211
1212static void lio_target_add_wwn_groups(struct se_wwn *wwn)
1213{
1214 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1215
Andy Groverb7eec2c2013-10-09 11:05:57 -07001216 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001217 "iscsi_instance", &iscsi_stat_instance_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001218 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1219 &tiqn->tiqn_wwn.fabric_stat_group);
1220
Andy Groverb7eec2c2013-10-09 11:05:57 -07001221 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001222 "iscsi_sess_err", &iscsi_stat_sess_err_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001223 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1224 &tiqn->tiqn_wwn.fabric_stat_group);
1225
Andy Groverb7eec2c2013-10-09 11:05:57 -07001226 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001227 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001228 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1229 &tiqn->tiqn_wwn.fabric_stat_group);
1230
Andy Groverb7eec2c2013-10-09 11:05:57 -07001231 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001232 "iscsi_login_stats", &iscsi_stat_login_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001233 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1234 &tiqn->tiqn_wwn.fabric_stat_group);
1235
Andy Groverb7eec2c2013-10-09 11:05:57 -07001236 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001237 "iscsi_logout_stats", &iscsi_stat_logout_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001238 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1239 &tiqn->tiqn_wwn.fabric_stat_group);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001240}
1241
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -04001242static void lio_target_call_coredeltiqn(
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001243 struct se_wwn *wwn)
1244{
1245 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001246
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001247 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1248 tiqn->tiqn);
1249 iscsit_del_tiqn(tiqn);
1250}
1251
1252/* End LIO-Target TIQN struct contig_lio_target_cit */
1253
1254/* Start lio_target_discovery_auth_cit */
1255
1256#define DEF_DISC_AUTH_STR(name, flags) \
1257 __DEF_NACL_AUTH_STR(disc, name, flags) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001258static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001259{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001260 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001261 page); \
1262} \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001263static ssize_t iscsi_disc_##name##_store(struct config_item *item, \
1264 const char *page, size_t count) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001265{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001266 return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001267 page, count); \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001268 \
1269} \
1270CONFIGFS_ATTR(iscsi_disc_, name)
1271
1272DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1273DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1274DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1275DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001276
1277#define DEF_DISC_AUTH_INT(name) \
1278 __DEF_NACL_AUTH_INT(disc, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001279static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001280{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001281 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001282 page); \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001283} \
1284CONFIGFS_ATTR_RO(iscsi_disc_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001285
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001286DEF_DISC_AUTH_INT(authenticate_target);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001287
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001288
1289static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
1290 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001291{
1292 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1293
1294 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1295}
1296
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001297static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1298 const char *page, size_t count)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001299{
1300 struct iscsi_param *param;
1301 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001302 u32 op;
Jörn Engelad7babd2013-07-03 11:35:11 -04001303 int err;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001304
Jörn Engelad7babd2013-07-03 11:35:11 -04001305 err = kstrtou32(page, 0, &op);
1306 if (err)
1307 return -EINVAL;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001308 if ((op != 1) && (op != 0)) {
1309 pr_err("Illegal value for enforce_discovery_auth:"
1310 " %u\n", op);
1311 return -EINVAL;
1312 }
1313
1314 if (!discovery_tpg) {
1315 pr_err("iscsit_global->discovery_tpg is NULL\n");
1316 return -EINVAL;
1317 }
1318
1319 param = iscsi_find_param_from_key(AUTHMETHOD,
1320 discovery_tpg->param_list);
1321 if (!param)
1322 return -EINVAL;
1323
1324 if (op) {
1325 /*
1326 * Reset the AuthMethod key to CHAP.
1327 */
1328 if (iscsi_update_param_value(param, CHAP) < 0)
1329 return -EINVAL;
1330
1331 discovery_tpg->tpg_attrib.authentication = 1;
1332 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1333 pr_debug("LIO-CORE[0] Successfully enabled"
1334 " authentication enforcement for iSCSI"
1335 " Discovery TPG\n");
1336 } else {
1337 /*
1338 * Reset the AuthMethod key to CHAP,None
1339 */
1340 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1341 return -EINVAL;
1342
1343 discovery_tpg->tpg_attrib.authentication = 0;
1344 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1345 pr_debug("LIO-CORE[0] Successfully disabled"
1346 " authentication enforcement for iSCSI"
1347 " Discovery TPG\n");
1348 }
1349
1350 return count;
1351}
1352
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001353CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001354
1355static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001356 &iscsi_disc_attr_userid,
1357 &iscsi_disc_attr_password,
1358 &iscsi_disc_attr_authenticate_target,
1359 &iscsi_disc_attr_userid_mutual,
1360 &iscsi_disc_attr_password_mutual,
1361 &iscsi_disc_attr_enforce_discovery_auth,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001362 NULL,
1363};
1364
1365/* End lio_target_discovery_auth_cit */
1366
1367/* Start functions for target_core_fabric_ops */
1368
1369static char *iscsi_get_fabric_name(void)
1370{
1371 return "iSCSI";
1372}
1373
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001374static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1375{
1376 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1377
1378 return cmd->i_state;
1379}
1380
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001381static u32 lio_sess_get_index(struct se_session *se_sess)
1382{
1383 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1384
1385 return sess->session_index;
1386}
1387
1388static u32 lio_sess_get_initiator_sid(
1389 struct se_session *se_sess,
1390 unsigned char *buf,
1391 u32 size)
1392{
1393 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1394 /*
1395 * iSCSI Initiator Session Identifier from RFC-3720.
1396 */
Andy Shevchenko5cdf5a82015-01-15 13:40:56 +02001397 return snprintf(buf, size, "%6phN", sess->isid);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001398}
1399
1400static int lio_queue_data_in(struct se_cmd *se_cmd)
1401{
1402 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1403
1404 cmd->i_state = ISTATE_SEND_DATAIN;
Nicholas Bellinger2ec5a8c2013-03-20 15:29:15 -07001405 cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd);
1406
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001407 return 0;
1408}
1409
1410static int lio_write_pending(struct se_cmd *se_cmd)
1411{
1412 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
Nicholas Bellinger3e1c81a2013-03-06 22:18:24 -08001413 struct iscsi_conn *conn = cmd->conn;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001414
1415 if (!cmd->immediate_data && !cmd->unsolicited_data)
Nicholas Bellinger3e1c81a2013-03-06 22:18:24 -08001416 return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001417
1418 return 0;
1419}
1420
1421static int lio_write_pending_status(struct se_cmd *se_cmd)
1422{
1423 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1424 int ret;
1425
1426 spin_lock_bh(&cmd->istate_lock);
1427 ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1428 spin_unlock_bh(&cmd->istate_lock);
1429
1430 return ret;
1431}
1432
1433static int lio_queue_status(struct se_cmd *se_cmd)
1434{
1435 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1436
1437 cmd->i_state = ISTATE_SEND_STATUS;
Nicholas Bellinger5e8e6b42013-11-12 17:54:56 -08001438
1439 if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
1440 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1441 return 0;
1442 }
Nicholas Bellinger2ec5a8c2013-03-20 15:29:15 -07001443 cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd);
1444
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001445 return 0;
1446}
1447
Joern Engelb79fafa2013-07-03 11:22:17 -04001448static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001449{
1450 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1451
1452 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1453 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001454}
1455
Nicholas Bellinger131e6ab2014-03-22 14:55:56 -07001456static void lio_aborted_task(struct se_cmd *se_cmd)
1457{
1458 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1459
1460 cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1461}
1462
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001463static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg)
1464{
1465 return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1466}
1467
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001468static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1469{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001470 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001471}
1472
1473static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1474{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001475 return iscsi_tpg(se_tpg)->tpgt;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001476}
1477
1478static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1479{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001480 return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001481}
1482
1483static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1484{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001485 return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001486}
1487
1488static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1489{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001490 return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001491}
1492
1493static int lio_tpg_check_demo_mode_write_protect(
1494 struct se_portal_group *se_tpg)
1495{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001496 return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001497}
1498
1499static int lio_tpg_check_prod_mode_write_protect(
1500 struct se_portal_group *se_tpg)
1501{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001502 return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001503}
1504
Nicholas Bellinger901c04a2015-03-29 19:36:16 -07001505static int lio_tpg_check_prot_fabric_only(
1506 struct se_portal_group *se_tpg)
1507{
Nicholas Bellinger901c04a2015-03-29 19:36:16 -07001508 /*
1509 * Only report fabric_prot_type if t10_pi has also been enabled
1510 * for incoming ib_isert sessions.
1511 */
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001512 if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
Nicholas Bellinger901c04a2015-03-29 19:36:16 -07001513 return 0;
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001514 return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
Nicholas Bellinger901c04a2015-03-29 19:36:16 -07001515}
1516
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001517/*
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001518 * This function calls iscsit_inc_session_usage_count() on the
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001519 * struct iscsi_session in question.
1520 */
Christoph Hellwig44f33d02016-05-02 15:45:24 +02001521static void lio_tpg_close_session(struct se_session *se_sess)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001522{
1523 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001524 struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
Nicholas Bellinger26a99c12016-01-19 16:15:27 -08001525
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001526 spin_lock_bh(&se_tpg->session_lock);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001527 spin_lock(&sess->conn_lock);
1528 if (atomic_read(&sess->session_fall_back_to_erl0) ||
1529 atomic_read(&sess->session_logout) ||
1530 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1531 spin_unlock(&sess->conn_lock);
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001532 spin_unlock_bh(&se_tpg->session_lock);
Christoph Hellwig44f33d02016-05-02 15:45:24 +02001533 return;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001534 }
1535 atomic_set(&sess->session_reinstatement, 1);
Nicholas Bellingerbb1f06f2017-04-25 10:55:12 -07001536 atomic_set(&sess->session_fall_back_to_erl0, 1);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001537 spin_unlock(&sess->conn_lock);
1538
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001539 iscsit_stop_time2retain_timer(sess);
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001540 spin_unlock_bh(&se_tpg->session_lock);
Nicholas Bellinger26a99c12016-01-19 16:15:27 -08001541
Nicholas Bellinger99367f02012-02-27 01:43:32 -08001542 iscsit_stop_session(sess, 1, 1);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001543 iscsit_close_session(sess);
1544}
1545
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001546static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1547{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001548 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001549}
1550
1551static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1552{
1553 struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1554 se_node_acl);
Nicholas Bellingerd1fa7a12013-11-20 11:57:18 -08001555 struct se_portal_group *se_tpg = se_acl->se_tpg;
1556 struct iscsi_portal_group *tpg = container_of(se_tpg,
1557 struct iscsi_portal_group, tpg_se_tpg);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001558
Andy Groverb7eec2c2013-10-09 11:05:57 -07001559 acl->node_attrib.nacl = acl;
Nicholas Bellingerd1fa7a12013-11-20 11:57:18 -08001560 iscsit_set_default_node_attribues(acl, tpg);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001561}
1562
Nicholas Bellinger3e1c81a2013-03-06 22:18:24 -08001563static int lio_check_stop_free(struct se_cmd *se_cmd)
1564{
Bart Van Asscheafc16602015-04-27 13:52:36 +02001565 return target_put_sess_cmd(se_cmd);
Nicholas Bellinger3e1c81a2013-03-06 22:18:24 -08001566}
1567
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001568static void lio_release_cmd(struct se_cmd *se_cmd)
1569{
1570 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1571
Nicholas Bellingercdb72662013-03-06 22:09:17 -08001572 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001573 iscsit_release_cmd(cmd);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001574}
1575
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001576const struct target_core_fabric_ops iscsi_ops = {
1577 .module = THIS_MODULE,
1578 .name = "iscsi",
Christoph Hellwig144bc4c2015-04-13 19:51:16 +02001579 .node_acl_size = sizeof(struct iscsi_node_acl),
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001580 .get_fabric_name = iscsi_get_fabric_name,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001581 .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
1582 .tpg_get_tag = lio_tpg_get_tag,
1583 .tpg_get_default_depth = lio_tpg_get_default_depth,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001584 .tpg_check_demo_mode = lio_tpg_check_demo_mode,
1585 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
1586 .tpg_check_demo_mode_write_protect =
1587 lio_tpg_check_demo_mode_write_protect,
1588 .tpg_check_prod_mode_write_protect =
1589 lio_tpg_check_prod_mode_write_protect,
1590 .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001591 .tpg_get_inst_index = lio_tpg_get_inst_index,
1592 .check_stop_free = lio_check_stop_free,
1593 .release_cmd = lio_release_cmd,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001594 .close_session = lio_tpg_close_session,
1595 .sess_get_index = lio_sess_get_index,
1596 .sess_get_initiator_sid = lio_sess_get_initiator_sid,
1597 .write_pending = lio_write_pending,
1598 .write_pending_status = lio_write_pending_status,
1599 .set_default_node_attributes = lio_set_default_node_attributes,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001600 .get_cmd_state = iscsi_get_cmd_state,
1601 .queue_data_in = lio_queue_data_in,
1602 .queue_status = lio_queue_status,
1603 .queue_tm_rsp = lio_queue_tm_rsp,
1604 .aborted_task = lio_aborted_task,
1605 .fabric_make_wwn = lio_target_call_coreaddtiqn,
1606 .fabric_drop_wwn = lio_target_call_coredeltiqn,
Christoph Hellwig839559e2016-03-29 13:03:35 +02001607 .add_wwn_groups = lio_target_add_wwn_groups,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001608 .fabric_make_tpg = lio_target_tiqn_addtpg,
1609 .fabric_drop_tpg = lio_target_tiqn_deltpg,
1610 .fabric_make_np = lio_target_call_addnptotpg,
1611 .fabric_drop_np = lio_target_call_delnpfromtpg,
Christoph Hellwigc7d6a802015-04-13 19:51:14 +02001612 .fabric_init_nodeacl = lio_target_init_nodeacl,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001613
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001614 .tfc_discovery_attrs = lio_target_discovery_auth_attrs,
1615 .tfc_wwn_attrs = lio_target_wwn_attrs,
1616 .tfc_tpg_base_attrs = lio_target_tpg_attrs,
1617 .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs,
1618 .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs,
1619 .tfc_tpg_param_attrs = lio_target_tpg_param_attrs,
1620 .tfc_tpg_np_base_attrs = lio_target_portal_attrs,
1621 .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs,
1622 .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs,
1623 .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs,
1624 .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs,
1625};