blob: a24443ba59ea04e452674403d014e507ea44b4d6 [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
46static ssize_t lio_target_np_sctp_show(struct config_item *item, char *page)
47{
48 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +000049 struct iscsi_tpg_np *tpg_np_sctp;
50 ssize_t rb;
51
52 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
53 if (tpg_np_sctp)
54 rb = sprintf(page, "1\n");
55 else
56 rb = sprintf(page, "0\n");
57
58 return rb;
59}
60
Christoph Hellwig2eafd722015-10-03 15:32:55 +020061static ssize_t lio_target_np_sctp_store(struct config_item *item,
62 const char *page, size_t count)
Nicholas Bellingere48354c2011-07-23 06:43:04 +000063{
Christoph Hellwig2eafd722015-10-03 15:32:55 +020064 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +000065 struct iscsi_np *np;
66 struct iscsi_portal_group *tpg;
Nicholas Bellingere48354c2011-07-23 06:43:04 +000067 struct iscsi_tpg_np *tpg_np_sctp = NULL;
Nicholas Bellingere48354c2011-07-23 06:43:04 +000068 u32 op;
69 int ret;
70
Jörn Engelad7babd2013-07-03 11:35:11 -040071 ret = kstrtou32(page, 0, &op);
72 if (ret)
73 return ret;
Nicholas Bellingere48354c2011-07-23 06:43:04 +000074 if ((op != 1) && (op != 0)) {
75 pr_err("Illegal value for tpg_enable: %u\n", op);
76 return -EINVAL;
77 }
78 np = tpg_np->tpg_np;
79 if (!np) {
80 pr_err("Unable to locate struct iscsi_np from"
81 " struct iscsi_tpg_np\n");
82 return -EINVAL;
83 }
84
85 tpg = tpg_np->tpg;
86 if (iscsit_get_tpg(tpg) < 0)
87 return -EINVAL;
88
89 if (op) {
90 /*
91 * Use existing np->np_sockaddr for SCTP network portal reference
92 */
93 tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
Andy Grover76c28f12015-08-24 10:26:03 -070094 tpg_np, ISCSI_SCTP_TCP);
Nicholas Bellingere48354c2011-07-23 06:43:04 +000095 if (!tpg_np_sctp || IS_ERR(tpg_np_sctp))
96 goto out;
97 } else {
98 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
99 if (!tpg_np_sctp)
100 goto out;
101
102 ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp);
103 if (ret < 0)
104 goto out;
105 }
106
107 iscsit_put_tpg(tpg);
108 return count;
109out:
110 iscsit_put_tpg(tpg);
111 return -EINVAL;
112}
113
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200114static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800115{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200116 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800117 struct iscsi_tpg_np *tpg_np_iser;
118 ssize_t rb;
119
120 tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
121 if (tpg_np_iser)
122 rb = sprintf(page, "1\n");
123 else
124 rb = sprintf(page, "0\n");
125
126 return rb;
127}
128
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200129static ssize_t lio_target_np_iser_store(struct config_item *item,
130 const char *page, size_t count)
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800131{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200132 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800133 struct iscsi_np *np;
134 struct iscsi_portal_group *tpg;
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800135 struct iscsi_tpg_np *tpg_np_iser = NULL;
136 char *endptr;
137 u32 op;
Andy Grover58bd0c62013-05-29 12:05:59 -0700138 int rc = 0;
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800139
140 op = simple_strtoul(page, &endptr, 0);
141 if ((op != 1) && (op != 0)) {
142 pr_err("Illegal value for tpg_enable: %u\n", op);
143 return -EINVAL;
144 }
145 np = tpg_np->tpg_np;
146 if (!np) {
147 pr_err("Unable to locate struct iscsi_np from"
148 " struct iscsi_tpg_np\n");
149 return -EINVAL;
150 }
151
152 tpg = tpg_np->tpg;
153 if (iscsit_get_tpg(tpg) < 0)
154 return -EINVAL;
155
156 if (op) {
Andy Grover58bd0c62013-05-29 12:05:59 -0700157 rc = request_module("ib_isert");
158 if (rc != 0) {
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800159 pr_warn("Unable to request_module for ib_isert\n");
Andy Grover58bd0c62013-05-29 12:05:59 -0700160 rc = 0;
161 }
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800162
163 tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
Andy Grover76c28f12015-08-24 10:26:03 -0700164 tpg_np, ISCSI_INFINIBAND);
Andy Grover58bd0c62013-05-29 12:05:59 -0700165 if (IS_ERR(tpg_np_iser)) {
166 rc = PTR_ERR(tpg_np_iser);
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800167 goto out;
Andy Grover58bd0c62013-05-29 12:05:59 -0700168 }
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800169 } else {
170 tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
Andy Grover58bd0c62013-05-29 12:05:59 -0700171 if (tpg_np_iser) {
172 rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser);
173 if (rc < 0)
174 goto out;
175 }
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800176 }
177
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800178 iscsit_put_tpg(tpg);
179 return count;
180out:
181 iscsit_put_tpg(tpg);
Andy Grover58bd0c62013-05-29 12:05:59 -0700182 return rc;
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800183}
184
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200185CONFIGFS_ATTR(lio_target_np_, sctp);
186CONFIGFS_ATTR(lio_target_np_, iser);
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800187
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000188static struct configfs_attribute *lio_target_portal_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200189 &lio_target_np_attr_sctp,
190 &lio_target_np_attr_iser,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000191 NULL,
192};
193
194/* Stop items for lio_target_portal_cit */
195
196/* Start items for lio_target_np_cit */
197
198#define MAX_PORTAL_LEN 256
199
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -0400200static struct se_tpg_np *lio_target_call_addnptotpg(
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000201 struct se_portal_group *se_tpg,
202 struct config_group *group,
203 const char *name)
204{
205 struct iscsi_portal_group *tpg;
206 struct iscsi_tpg_np *tpg_np;
207 char *str, *str2, *ip_str, *port_str;
Andy Grover13a3cf02015-08-24 10:26:06 -0700208 struct sockaddr_storage sockaddr;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000209 struct sockaddr_in *sock_in;
210 struct sockaddr_in6 *sock_in6;
211 unsigned long port;
212 int ret;
213 char buf[MAX_PORTAL_LEN + 1];
214
215 if (strlen(name) > MAX_PORTAL_LEN) {
216 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
217 (int)strlen(name), MAX_PORTAL_LEN);
218 return ERR_PTR(-EOVERFLOW);
219 }
220 memset(buf, 0, MAX_PORTAL_LEN + 1);
Nicholas Bellinger7bbb6542011-07-27 12:37:03 -0700221 snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000222
Andy Grover13a3cf02015-08-24 10:26:06 -0700223 memset(&sockaddr, 0, sizeof(struct sockaddr_storage));
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000224
225 str = strstr(buf, "[");
226 if (str) {
227 const char *end;
228
229 str2 = strstr(str, "]");
230 if (!str2) {
231 pr_err("Unable to locate trailing \"]\""
232 " in IPv6 iSCSI network portal address\n");
233 return ERR_PTR(-EINVAL);
234 }
235 str++; /* Skip over leading "[" */
Andy Grover76c28f12015-08-24 10:26:03 -0700236 *str2 = '\0'; /* Terminate the unbracketed IPv6 address */
237 str2++; /* Skip over the \0 */
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000238 port_str = strstr(str2, ":");
239 if (!port_str) {
240 pr_err("Unable to locate \":port\""
241 " in IPv6 iSCSI network portal address\n");
242 return ERR_PTR(-EINVAL);
243 }
244 *port_str = '\0'; /* Terminate string for IP */
245 port_str++; /* Skip over ":" */
246
Jingoo Han57103d72013-07-19 16:22:19 +0900247 ret = kstrtoul(port_str, 0, &port);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000248 if (ret < 0) {
Jingoo Han57103d72013-07-19 16:22:19 +0900249 pr_err("kstrtoul() failed for port_str: %d\n", ret);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000250 return ERR_PTR(ret);
251 }
252 sock_in6 = (struct sockaddr_in6 *)&sockaddr;
253 sock_in6->sin6_family = AF_INET6;
254 sock_in6->sin6_port = htons((unsigned short)port);
Andy Groverdc58f762015-08-24 10:26:05 -0700255 ret = in6_pton(str, -1,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000256 (void *)&sock_in6->sin6_addr.in6_u, -1, &end);
257 if (ret <= 0) {
258 pr_err("in6_pton returned: %d\n", ret);
259 return ERR_PTR(-EINVAL);
260 }
261 } else {
262 str = ip_str = &buf[0];
263 port_str = strstr(ip_str, ":");
264 if (!port_str) {
265 pr_err("Unable to locate \":port\""
266 " in IPv4 iSCSI network portal address\n");
267 return ERR_PTR(-EINVAL);
268 }
269 *port_str = '\0'; /* Terminate string for IP */
270 port_str++; /* Skip over ":" */
271
Jingoo Han57103d72013-07-19 16:22:19 +0900272 ret = kstrtoul(port_str, 0, &port);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000273 if (ret < 0) {
Jingoo Han57103d72013-07-19 16:22:19 +0900274 pr_err("kstrtoul() failed for port_str: %d\n", ret);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000275 return ERR_PTR(ret);
276 }
277 sock_in = (struct sockaddr_in *)&sockaddr;
278 sock_in->sin_family = AF_INET;
279 sock_in->sin_port = htons((unsigned short)port);
280 sock_in->sin_addr.s_addr = in_aton(ip_str);
281 }
282 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
283 ret = iscsit_get_tpg(tpg);
284 if (ret < 0)
285 return ERR_PTR(-EINVAL);
286
287 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
288 " PORTAL: %s\n",
289 config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
290 tpg->tpgt, name);
291 /*
292 * Assume ISCSI_TCP by default. Other network portals for other
293 * iSCSI fabrics:
294 *
295 * Traditional iSCSI over SCTP (initial support)
296 * iSER/TCP (TODO, hardware available)
297 * iSER/SCTP (TODO, software emulation with osc-iwarp)
298 * iSER/IB (TODO, hardware available)
299 *
Masanari Iida20879692012-08-27 22:46:00 +0900300 * can be enabled with attributes under
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000301 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
302 *
303 */
Andy Grover76c28f12015-08-24 10:26:03 -0700304 tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000305 ISCSI_TCP);
306 if (IS_ERR(tpg_np)) {
307 iscsit_put_tpg(tpg);
Thomas Meyere1750ba2011-08-01 23:58:18 +0200308 return ERR_CAST(tpg_np);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000309 }
310 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
311
312 iscsit_put_tpg(tpg);
313 return &tpg_np->se_tpg_np;
314}
315
316static void lio_target_call_delnpfromtpg(
317 struct se_tpg_np *se_tpg_np)
318{
319 struct iscsi_portal_group *tpg;
320 struct iscsi_tpg_np *tpg_np;
321 struct se_portal_group *se_tpg;
322 int ret;
323
324 tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
325 tpg = tpg_np->tpg;
326 ret = iscsit_get_tpg(tpg);
327 if (ret < 0)
328 return;
329
330 se_tpg = &tpg->tpg_se_tpg;
331 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
Andy Grover69d75572015-08-24 10:26:04 -0700332 " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
333 tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000334
335 ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
336 if (ret < 0)
337 goto out;
338
339 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
340out:
341 iscsit_put_tpg(tpg);
342}
343
344/* End items for lio_target_np_cit */
345
346/* Start items for lio_target_nacl_attrib_cit */
347
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200348#define ISCSI_NACL_ATTR(name) \
349static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
350 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000351{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200352 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000353 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
354 se_node_acl); \
355 \
Andy Groverb7eec2c2013-10-09 11:05:57 -0700356 return sprintf(page, "%u\n", nacl->node_attrib.name); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000357} \
358 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200359static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
360 const char *page, size_t count) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000361{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200362 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000363 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
364 se_node_acl); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000365 u32 val; \
366 int ret; \
367 \
Jörn Engelad7babd2013-07-03 11:35:11 -0400368 ret = kstrtou32(page, 0, &val); \
369 if (ret) \
370 return ret; \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000371 ret = iscsit_na_##name(nacl, val); \
372 if (ret < 0) \
373 return ret; \
374 \
375 return count; \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200376} \
377 \
378CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000379
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200380ISCSI_NACL_ATTR(dataout_timeout);
381ISCSI_NACL_ATTR(dataout_timeout_retries);
382ISCSI_NACL_ATTR(default_erl);
383ISCSI_NACL_ATTR(nopin_timeout);
384ISCSI_NACL_ATTR(nopin_response_timeout);
385ISCSI_NACL_ATTR(random_datain_pdu_offsets);
386ISCSI_NACL_ATTR(random_datain_seq_offsets);
387ISCSI_NACL_ATTR(random_r2t_offsets);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000388
389static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200390 &iscsi_nacl_attrib_attr_dataout_timeout,
391 &iscsi_nacl_attrib_attr_dataout_timeout_retries,
392 &iscsi_nacl_attrib_attr_default_erl,
393 &iscsi_nacl_attrib_attr_nopin_timeout,
394 &iscsi_nacl_attrib_attr_nopin_response_timeout,
395 &iscsi_nacl_attrib_attr_random_datain_pdu_offsets,
396 &iscsi_nacl_attrib_attr_random_datain_seq_offsets,
397 &iscsi_nacl_attrib_attr_random_r2t_offsets,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000398 NULL,
399};
400
401/* End items for lio_target_nacl_attrib_cit */
402
403/* Start items for lio_target_nacl_auth_cit */
404
405#define __DEF_NACL_AUTH_STR(prefix, name, flags) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200406static ssize_t __iscsi_##prefix##_##name##_show( \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000407 struct iscsi_node_acl *nacl, \
408 char *page) \
409{ \
410 struct iscsi_node_auth *auth = &nacl->node_auth; \
411 \
412 if (!capable(CAP_SYS_ADMIN)) \
413 return -EPERM; \
414 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
415} \
416 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200417static ssize_t __iscsi_##prefix##_##name##_store( \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000418 struct iscsi_node_acl *nacl, \
419 const char *page, \
420 size_t count) \
421{ \
422 struct iscsi_node_auth *auth = &nacl->node_auth; \
423 \
424 if (!capable(CAP_SYS_ADMIN)) \
425 return -EPERM; \
Eric Seppanen2306bfb2013-11-21 14:49:56 -0800426 if (count >= sizeof(auth->name)) \
427 return -EINVAL; \
Jörn Engel0fbfc462013-07-03 11:35:11 -0400428 snprintf(auth->name, sizeof(auth->name), "%s", page); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000429 if (!strncmp("NULL", auth->name, 4)) \
430 auth->naf_flags &= ~flags; \
431 else \
432 auth->naf_flags |= flags; \
433 \
434 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
435 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
436 auth->authenticate_target = 1; \
437 else \
438 auth->authenticate_target = 0; \
439 \
440 return count; \
441}
442
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200443#define DEF_NACL_AUTH_STR(name, flags) \
444 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
445static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
446 char *page) \
447{ \
448 struct se_node_acl *nacl = auth_to_nacl(item); \
449 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
450 struct iscsi_node_acl, se_node_acl), page); \
451} \
452static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \
453 const char *page, size_t count) \
454{ \
455 struct se_node_acl *nacl = auth_to_nacl(item); \
456 return __iscsi_nacl_auth_##name##_store(container_of(nacl, \
457 struct iscsi_node_acl, se_node_acl), page, count); \
458} \
459 \
460CONFIGFS_ATTR(iscsi_nacl_auth_, name)
461
462/*
463 * One-way authentication userid
464 */
465DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
466DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
467DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
468DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
469
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000470#define __DEF_NACL_AUTH_INT(prefix, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200471static ssize_t __iscsi_##prefix##_##name##_show( \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000472 struct iscsi_node_acl *nacl, \
473 char *page) \
474{ \
475 struct iscsi_node_auth *auth = &nacl->node_auth; \
476 \
477 if (!capable(CAP_SYS_ADMIN)) \
478 return -EPERM; \
479 \
480 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
481}
482
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000483#define DEF_NACL_AUTH_INT(name) \
484 __DEF_NACL_AUTH_INT(nacl_auth, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200485static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
486 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000487{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200488 struct se_node_acl *nacl = auth_to_nacl(item); \
489 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
490 struct iscsi_node_acl, se_node_acl), page); \
491} \
492 \
493CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000494
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000495DEF_NACL_AUTH_INT(authenticate_target);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000496
497static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200498 &iscsi_nacl_auth_attr_userid,
499 &iscsi_nacl_auth_attr_password,
500 &iscsi_nacl_auth_attr_authenticate_target,
501 &iscsi_nacl_auth_attr_userid_mutual,
502 &iscsi_nacl_auth_attr_password_mutual,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000503 NULL,
504};
505
506/* End items for lio_target_nacl_auth_cit */
507
508/* Start items for lio_target_nacl_param_cit */
509
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200510#define ISCSI_NACL_PARAM(name) \
511static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \
512 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000513{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200514 struct se_node_acl *se_nacl = param_to_nacl(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000515 struct iscsi_session *sess; \
516 struct se_session *se_sess; \
517 ssize_t rb; \
518 \
519 spin_lock_bh(&se_nacl->nacl_sess_lock); \
520 se_sess = se_nacl->nacl_sess; \
521 if (!se_sess) { \
522 rb = snprintf(page, PAGE_SIZE, \
523 "No Active iSCSI Session\n"); \
524 } else { \
525 sess = se_sess->fabric_sess_ptr; \
526 rb = snprintf(page, PAGE_SIZE, "%u\n", \
527 (u32)sess->sess_ops->name); \
528 } \
529 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
530 \
531 return rb; \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200532} \
533 \
534CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000535
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200536ISCSI_NACL_PARAM(MaxConnections);
537ISCSI_NACL_PARAM(InitialR2T);
538ISCSI_NACL_PARAM(ImmediateData);
539ISCSI_NACL_PARAM(MaxBurstLength);
540ISCSI_NACL_PARAM(FirstBurstLength);
541ISCSI_NACL_PARAM(DefaultTime2Wait);
542ISCSI_NACL_PARAM(DefaultTime2Retain);
543ISCSI_NACL_PARAM(MaxOutstandingR2T);
544ISCSI_NACL_PARAM(DataPDUInOrder);
545ISCSI_NACL_PARAM(DataSequenceInOrder);
546ISCSI_NACL_PARAM(ErrorRecoveryLevel);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000547
548static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200549 &iscsi_nacl_param_attr_MaxConnections,
550 &iscsi_nacl_param_attr_InitialR2T,
551 &iscsi_nacl_param_attr_ImmediateData,
552 &iscsi_nacl_param_attr_MaxBurstLength,
553 &iscsi_nacl_param_attr_FirstBurstLength,
554 &iscsi_nacl_param_attr_DefaultTime2Wait,
555 &iscsi_nacl_param_attr_DefaultTime2Retain,
556 &iscsi_nacl_param_attr_MaxOutstandingR2T,
557 &iscsi_nacl_param_attr_DataPDUInOrder,
558 &iscsi_nacl_param_attr_DataSequenceInOrder,
559 &iscsi_nacl_param_attr_ErrorRecoveryLevel,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000560 NULL,
561};
562
563/* End items for lio_target_nacl_param_cit */
564
565/* Start items for lio_target_acl_cit */
566
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200567static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000568{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200569 struct se_node_acl *se_nacl = acl_to_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000570 struct iscsi_session *sess;
571 struct iscsi_conn *conn;
572 struct se_session *se_sess;
573 ssize_t rb = 0;
Roland Dreier109e2382015-07-23 14:53:32 -0700574 u32 max_cmd_sn;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000575
576 spin_lock_bh(&se_nacl->nacl_sess_lock);
577 se_sess = se_nacl->nacl_sess;
578 if (!se_sess) {
579 rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
580 " Endpoint: %s\n", se_nacl->initiatorname);
581 } else {
582 sess = se_sess->fabric_sess_ptr;
583
Joern Engelcb354842014-09-02 17:49:50 -0400584 rb += sprintf(page+rb, "InitiatorName: %s\n",
585 sess->sess_ops->InitiatorName);
586 rb += sprintf(page+rb, "InitiatorAlias: %s\n",
587 sess->sess_ops->InitiatorAlias);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000588
Andy Shevchenko5cdf5a82015-01-15 13:40:56 +0200589 rb += sprintf(page+rb,
590 "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ",
591 sess->sid, sess->isid, sess->tsih);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000592 rb += sprintf(page+rb, "SessionType: %s\n",
593 (sess->sess_ops->SessionType) ?
594 "Discovery" : "Normal");
595 rb += sprintf(page+rb, "Session State: ");
596 switch (sess->session_state) {
597 case TARG_SESS_STATE_FREE:
598 rb += sprintf(page+rb, "TARG_SESS_FREE\n");
599 break;
600 case TARG_SESS_STATE_ACTIVE:
601 rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
602 break;
603 case TARG_SESS_STATE_LOGGED_IN:
604 rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
605 break;
606 case TARG_SESS_STATE_FAILED:
607 rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
608 break;
609 case TARG_SESS_STATE_IN_CONTINUE:
610 rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
611 break;
612 default:
613 rb += sprintf(page+rb, "ERROR: Unknown Session"
614 " State!\n");
615 break;
616 }
617
618 rb += sprintf(page+rb, "---------------------[iSCSI Session"
619 " Values]-----------------------\n");
620 rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
621 " : MaxCmdSN : ITT : TTT\n");
Roland Dreier109e2382015-07-23 14:53:32 -0700622 max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000623 rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
624 " 0x%08x 0x%08x\n",
625 sess->cmdsn_window,
Roland Dreier109e2382015-07-23 14:53:32 -0700626 (max_cmd_sn - sess->exp_cmd_sn) + 1,
627 sess->exp_cmd_sn, max_cmd_sn,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000628 sess->init_task_tag, sess->targ_xfer_tag);
629 rb += sprintf(page+rb, "----------------------[iSCSI"
630 " Connections]-------------------------\n");
631
632 spin_lock(&sess->conn_lock);
633 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
634 rb += sprintf(page+rb, "CID: %hu Connection"
635 " State: ", conn->cid);
636 switch (conn->conn_state) {
637 case TARG_CONN_STATE_FREE:
638 rb += sprintf(page+rb,
639 "TARG_CONN_STATE_FREE\n");
640 break;
641 case TARG_CONN_STATE_XPT_UP:
642 rb += sprintf(page+rb,
643 "TARG_CONN_STATE_XPT_UP\n");
644 break;
645 case TARG_CONN_STATE_IN_LOGIN:
646 rb += sprintf(page+rb,
647 "TARG_CONN_STATE_IN_LOGIN\n");
648 break;
649 case TARG_CONN_STATE_LOGGED_IN:
650 rb += sprintf(page+rb,
651 "TARG_CONN_STATE_LOGGED_IN\n");
652 break;
653 case TARG_CONN_STATE_IN_LOGOUT:
654 rb += sprintf(page+rb,
655 "TARG_CONN_STATE_IN_LOGOUT\n");
656 break;
657 case TARG_CONN_STATE_LOGOUT_REQUESTED:
658 rb += sprintf(page+rb,
659 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
660 break;
661 case TARG_CONN_STATE_CLEANUP_WAIT:
662 rb += sprintf(page+rb,
663 "TARG_CONN_STATE_CLEANUP_WAIT\n");
664 break;
665 default:
666 rb += sprintf(page+rb,
667 "ERROR: Unknown Connection State!\n");
668 break;
669 }
670
Andy Groverdc58f762015-08-24 10:26:05 -0700671 rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000672 (conn->network_transport == ISCSI_TCP) ?
673 "TCP" : "SCTP");
674 rb += sprintf(page+rb, " StatSN: 0x%08x\n",
675 conn->stat_sn);
676 }
677 spin_unlock(&sess->conn_lock);
678 }
679 spin_unlock_bh(&se_nacl->nacl_sess_lock);
680
681 return rb;
682}
683
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200684static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
685 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000686{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200687 return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000688}
689
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200690static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
691 const char *page, size_t count)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000692{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200693 struct se_node_acl *se_nacl = acl_to_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000694 struct se_portal_group *se_tpg = se_nacl->se_tpg;
695 struct iscsi_portal_group *tpg = container_of(se_tpg,
696 struct iscsi_portal_group, tpg_se_tpg);
697 struct config_item *acl_ci, *tpg_ci, *wwn_ci;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000698 u32 cmdsn_depth = 0;
699 int ret;
700
Jörn Engelad7babd2013-07-03 11:35:11 -0400701 ret = kstrtou32(page, 0, &cmdsn_depth);
702 if (ret)
703 return ret;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000704 if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
705 pr_err("Passed cmdsn_depth: %u exceeds"
706 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
707 TA_DEFAULT_CMDSN_DEPTH_MAX);
708 return -EINVAL;
709 }
710 acl_ci = &se_nacl->acl_group.cg_item;
711 if (!acl_ci) {
712 pr_err("Unable to locatel acl_ci\n");
713 return -EINVAL;
714 }
715 tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
716 if (!tpg_ci) {
717 pr_err("Unable to locate tpg_ci\n");
718 return -EINVAL;
719 }
720 wwn_ci = &tpg_ci->ci_group->cg_item;
721 if (!wwn_ci) {
722 pr_err("Unable to locate config_item wwn_ci\n");
723 return -EINVAL;
724 }
725
726 if (iscsit_get_tpg(tpg) < 0)
727 return -EINVAL;
Nicholas Bellingerd36ad772016-01-07 22:15:06 -0800728
729 ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000730
731 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
732 "InitiatorName: %s\n", config_item_name(wwn_ci),
733 config_item_name(tpg_ci), cmdsn_depth,
734 config_item_name(acl_ci));
735
736 iscsit_put_tpg(tpg);
737 return (!ret) ? count : (ssize_t)ret;
738}
739
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200740static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
Andy Grover79e62fc2012-12-11 16:30:53 -0800741{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200742 return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
Andy Grover79e62fc2012-12-11 16:30:53 -0800743}
744
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200745static ssize_t lio_target_nacl_tag_store(struct config_item *item,
746 const char *page, size_t count)
Andy Grover79e62fc2012-12-11 16:30:53 -0800747{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200748 struct se_node_acl *se_nacl = acl_to_nacl(item);
Andy Grover79e62fc2012-12-11 16:30:53 -0800749 int ret;
750
751 ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
752
753 if (ret < 0)
754 return ret;
755 return count;
756}
757
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200758CONFIGFS_ATTR_RO(lio_target_nacl_, info);
759CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
760CONFIGFS_ATTR(lio_target_nacl_, tag);
Andy Grover79e62fc2012-12-11 16:30:53 -0800761
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000762static struct configfs_attribute *lio_target_initiator_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200763 &lio_target_nacl_attr_info,
764 &lio_target_nacl_attr_cmdsn_depth,
765 &lio_target_nacl_attr_tag,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000766 NULL,
767};
768
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200769static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
770 const char *name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000771{
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200772 struct iscsi_node_acl *acl =
773 container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000774
Andy Groverb7eec2c2013-10-09 11:05:57 -0700775 config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000776 "iscsi_sess_stats", &iscsi_stat_sess_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100777 configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group,
778 &se_nacl->acl_fabric_stat_group);
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200779 return 0;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000780}
781
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200782static void lio_target_cleanup_nodeacl( struct se_node_acl *se_nacl)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000783{
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000784 struct iscsi_node_acl *acl = container_of(se_nacl,
785 struct iscsi_node_acl, se_node_acl);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000786
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100787 configfs_remove_default_groups(&acl->se_node_acl.acl_fabric_stat_group);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000788}
789
790/* End items for lio_target_acl_cit */
791
792/* Start items for lio_target_tpg_attrib_cit */
793
794#define DEF_TPG_ATTRIB(name) \
795 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200796static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \
797 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000798{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200799 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000800 struct iscsi_portal_group *tpg = container_of(se_tpg, \
801 struct iscsi_portal_group, tpg_se_tpg); \
802 ssize_t rb; \
803 \
804 if (iscsit_get_tpg(tpg) < 0) \
805 return -EINVAL; \
806 \
Andy Groverb7eec2c2013-10-09 11:05:57 -0700807 rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000808 iscsit_put_tpg(tpg); \
809 return rb; \
810} \
811 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200812static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
813 const char *page, size_t count) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000814{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200815 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000816 struct iscsi_portal_group *tpg = container_of(se_tpg, \
817 struct iscsi_portal_group, tpg_se_tpg); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000818 u32 val; \
819 int ret; \
820 \
821 if (iscsit_get_tpg(tpg) < 0) \
822 return -EINVAL; \
823 \
Jörn Engelad7babd2013-07-03 11:35:11 -0400824 ret = kstrtou32(page, 0, &val); \
825 if (ret) \
826 goto out; \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000827 ret = iscsit_ta_##name(tpg, val); \
828 if (ret < 0) \
829 goto out; \
830 \
831 iscsit_put_tpg(tpg); \
832 return count; \
833out: \
834 iscsit_put_tpg(tpg); \
835 return ret; \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200836} \
837CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000838
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000839DEF_TPG_ATTRIB(authentication);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000840DEF_TPG_ATTRIB(login_timeout);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000841DEF_TPG_ATTRIB(netif_timeout);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000842DEF_TPG_ATTRIB(generate_node_acls);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000843DEF_TPG_ATTRIB(default_cmdsn_depth);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000844DEF_TPG_ATTRIB(cache_dynamic_acls);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000845DEF_TPG_ATTRIB(demo_mode_write_protect);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000846DEF_TPG_ATTRIB(prod_mode_write_protect);
Thomas Glanzmann4c54b6c2013-10-07 23:12:11 +0200847DEF_TPG_ATTRIB(demo_mode_discovery);
Nicholas Bellingerd1fa7a12013-11-20 11:57:18 -0800848DEF_TPG_ATTRIB(default_erl);
Sagi Grimberg80851762014-02-19 17:50:20 +0200849DEF_TPG_ATTRIB(t10_pi);
Nicholas Bellinger901c04a2015-03-29 19:36:16 -0700850DEF_TPG_ATTRIB(fabric_prot_type);
David Disseldorpa6415cd2015-08-01 00:10:12 -0700851DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000852
853static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200854 &iscsi_tpg_attrib_attr_authentication,
855 &iscsi_tpg_attrib_attr_login_timeout,
856 &iscsi_tpg_attrib_attr_netif_timeout,
857 &iscsi_tpg_attrib_attr_generate_node_acls,
858 &iscsi_tpg_attrib_attr_default_cmdsn_depth,
859 &iscsi_tpg_attrib_attr_cache_dynamic_acls,
860 &iscsi_tpg_attrib_attr_demo_mode_write_protect,
861 &iscsi_tpg_attrib_attr_prod_mode_write_protect,
862 &iscsi_tpg_attrib_attr_demo_mode_discovery,
863 &iscsi_tpg_attrib_attr_default_erl,
864 &iscsi_tpg_attrib_attr_t10_pi,
865 &iscsi_tpg_attrib_attr_fabric_prot_type,
866 &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000867 NULL,
868};
869
870/* End items for lio_target_tpg_attrib_cit */
871
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700872/* Start items for lio_target_tpg_auth_cit */
873
874#define __DEF_TPG_AUTH_STR(prefix, name, flags) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200875static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
876 char *page) \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700877{ \
878 struct iscsi_portal_group *tpg = container_of(se_tpg, \
879 struct iscsi_portal_group, tpg_se_tpg); \
880 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
881 \
882 if (!capable(CAP_SYS_ADMIN)) \
883 return -EPERM; \
884 \
885 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
886} \
887 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200888static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
889 const char *page, size_t count) \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700890{ \
891 struct iscsi_portal_group *tpg = container_of(se_tpg, \
892 struct iscsi_portal_group, tpg_se_tpg); \
893 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
894 \
895 if (!capable(CAP_SYS_ADMIN)) \
896 return -EPERM; \
897 \
Nicholas Bellinger37b32c62013-07-06 16:48:55 -0700898 snprintf(auth->name, sizeof(auth->name), "%s", page); \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700899 if (!(strncmp("NULL", auth->name, 4))) \
900 auth->naf_flags &= ~flags; \
901 else \
902 auth->naf_flags |= flags; \
903 \
904 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
905 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
906 auth->authenticate_target = 1; \
907 else \
908 auth->authenticate_target = 0; \
909 \
910 return count; \
911}
912
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200913#define DEF_TPG_AUTH_STR(name, flags) \
914 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
915static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
916 char *page) \
917{ \
918 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
919} \
920 \
921static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \
922 const char *page, size_t count) \
923{ \
924 return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
925} \
926 \
927CONFIGFS_ATTR(iscsi_tpg_auth_, name);
928
929
930DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
931DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
932DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
933DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
934
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700935#define __DEF_TPG_AUTH_INT(prefix, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200936static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
937 char *page) \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700938{ \
939 struct iscsi_portal_group *tpg = container_of(se_tpg, \
940 struct iscsi_portal_group, tpg_se_tpg); \
941 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
942 \
943 if (!capable(CAP_SYS_ADMIN)) \
944 return -EPERM; \
945 \
946 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
947}
948
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700949#define DEF_TPG_AUTH_INT(name) \
950 __DEF_TPG_AUTH_INT(tpg_auth, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200951static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
952 char *page) \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700953{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200954 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
955} \
956CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700957
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700958DEF_TPG_AUTH_INT(authenticate_target);
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700959
960static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200961 &iscsi_tpg_auth_attr_userid,
962 &iscsi_tpg_auth_attr_password,
963 &iscsi_tpg_auth_attr_authenticate_target,
964 &iscsi_tpg_auth_attr_userid_mutual,
965 &iscsi_tpg_auth_attr_password_mutual,
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700966 NULL,
967};
968
969/* End items for lio_target_tpg_auth_cit */
970
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000971/* Start items for lio_target_tpg_param_cit */
972
973#define DEF_TPG_PARAM(name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200974static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \
975 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000976{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200977 struct se_portal_group *se_tpg = param_to_tpg(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000978 struct iscsi_portal_group *tpg = container_of(se_tpg, \
979 struct iscsi_portal_group, tpg_se_tpg); \
980 struct iscsi_param *param; \
981 ssize_t rb; \
982 \
983 if (iscsit_get_tpg(tpg) < 0) \
984 return -EINVAL; \
985 \
986 param = iscsi_find_param_from_key(__stringify(name), \
987 tpg->param_list); \
988 if (!param) { \
989 iscsit_put_tpg(tpg); \
990 return -EINVAL; \
991 } \
992 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
993 \
994 iscsit_put_tpg(tpg); \
995 return rb; \
996} \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200997static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
998 const char *page, size_t count) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000999{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001000 struct se_portal_group *se_tpg = param_to_tpg(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001001 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1002 struct iscsi_portal_group, tpg_se_tpg); \
1003 char *buf; \
Jörn Engelad7babd2013-07-03 11:35:11 -04001004 int ret, len; \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001005 \
1006 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
1007 if (!buf) \
1008 return -ENOMEM; \
Jörn Engelad7babd2013-07-03 11:35:11 -04001009 len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
1010 if (isspace(buf[len-1])) \
1011 buf[len-1] = '\0'; /* Kill newline */ \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001012 \
1013 if (iscsit_get_tpg(tpg) < 0) { \
1014 kfree(buf); \
1015 return -EINVAL; \
1016 } \
1017 \
1018 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
1019 if (ret < 0) \
1020 goto out; \
1021 \
1022 kfree(buf); \
1023 iscsit_put_tpg(tpg); \
1024 return count; \
1025out: \
1026 kfree(buf); \
1027 iscsit_put_tpg(tpg); \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001028 return -EINVAL; \
1029} \
1030CONFIGFS_ATTR(iscsi_tpg_param_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001031
1032DEF_TPG_PARAM(AuthMethod);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001033DEF_TPG_PARAM(HeaderDigest);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001034DEF_TPG_PARAM(DataDigest);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001035DEF_TPG_PARAM(MaxConnections);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001036DEF_TPG_PARAM(TargetAlias);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001037DEF_TPG_PARAM(InitialR2T);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001038DEF_TPG_PARAM(ImmediateData);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001039DEF_TPG_PARAM(MaxRecvDataSegmentLength);
Nicholas Bellingere004cb22012-09-29 21:47:16 -07001040DEF_TPG_PARAM(MaxXmitDataSegmentLength);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001041DEF_TPG_PARAM(MaxBurstLength);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001042DEF_TPG_PARAM(FirstBurstLength);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001043DEF_TPG_PARAM(DefaultTime2Wait);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001044DEF_TPG_PARAM(DefaultTime2Retain);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001045DEF_TPG_PARAM(MaxOutstandingR2T);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001046DEF_TPG_PARAM(DataPDUInOrder);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001047DEF_TPG_PARAM(DataSequenceInOrder);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001048DEF_TPG_PARAM(ErrorRecoveryLevel);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001049DEF_TPG_PARAM(IFMarker);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001050DEF_TPG_PARAM(OFMarker);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001051DEF_TPG_PARAM(IFMarkInt);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001052DEF_TPG_PARAM(OFMarkInt);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001053
1054static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001055 &iscsi_tpg_param_attr_AuthMethod,
1056 &iscsi_tpg_param_attr_HeaderDigest,
1057 &iscsi_tpg_param_attr_DataDigest,
1058 &iscsi_tpg_param_attr_MaxConnections,
1059 &iscsi_tpg_param_attr_TargetAlias,
1060 &iscsi_tpg_param_attr_InitialR2T,
1061 &iscsi_tpg_param_attr_ImmediateData,
1062 &iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
1063 &iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
1064 &iscsi_tpg_param_attr_MaxBurstLength,
1065 &iscsi_tpg_param_attr_FirstBurstLength,
1066 &iscsi_tpg_param_attr_DefaultTime2Wait,
1067 &iscsi_tpg_param_attr_DefaultTime2Retain,
1068 &iscsi_tpg_param_attr_MaxOutstandingR2T,
1069 &iscsi_tpg_param_attr_DataPDUInOrder,
1070 &iscsi_tpg_param_attr_DataSequenceInOrder,
1071 &iscsi_tpg_param_attr_ErrorRecoveryLevel,
1072 &iscsi_tpg_param_attr_IFMarker,
1073 &iscsi_tpg_param_attr_OFMarker,
1074 &iscsi_tpg_param_attr_IFMarkInt,
1075 &iscsi_tpg_param_attr_OFMarkInt,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001076 NULL,
1077};
1078
1079/* End items for lio_target_tpg_param_cit */
1080
1081/* Start items for lio_target_tpg_cit */
1082
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001083static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001084{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001085 struct se_portal_group *se_tpg = to_tpg(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001086 struct iscsi_portal_group *tpg = container_of(se_tpg,
1087 struct iscsi_portal_group, tpg_se_tpg);
1088 ssize_t len;
1089
1090 spin_lock(&tpg->tpg_state_lock);
1091 len = sprintf(page, "%d\n",
1092 (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1093 spin_unlock(&tpg->tpg_state_lock);
1094
1095 return len;
1096}
1097
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001098static ssize_t lio_target_tpg_enable_store(struct config_item *item,
1099 const char *page, size_t count)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001100{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001101 struct se_portal_group *se_tpg = to_tpg(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001102 struct iscsi_portal_group *tpg = container_of(se_tpg,
1103 struct iscsi_portal_group, tpg_se_tpg);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001104 u32 op;
Jörn Engelad7babd2013-07-03 11:35:11 -04001105 int ret;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001106
Jörn Engelad7babd2013-07-03 11:35:11 -04001107 ret = kstrtou32(page, 0, &op);
1108 if (ret)
1109 return ret;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001110 if ((op != 1) && (op != 0)) {
1111 pr_err("Illegal value for tpg_enable: %u\n", op);
1112 return -EINVAL;
1113 }
1114
1115 ret = iscsit_get_tpg(tpg);
1116 if (ret < 0)
1117 return -EINVAL;
1118
1119 if (op) {
1120 ret = iscsit_tpg_enable_portal_group(tpg);
1121 if (ret < 0)
1122 goto out;
1123 } else {
1124 /*
1125 * iscsit_tpg_disable_portal_group() assumes force=1
1126 */
1127 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1128 if (ret < 0)
1129 goto out;
1130 }
1131
1132 iscsit_put_tpg(tpg);
1133 return count;
1134out:
1135 iscsit_put_tpg(tpg);
1136 return -EINVAL;
1137}
1138
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001139
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001140static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
1141 char *page)
Nicholas Bellingerd4ee46f2015-03-06 20:40:57 -08001142{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001143 return target_show_dynamic_sessions(to_tpg(item), page);
Nicholas Bellingerd4ee46f2015-03-06 20:40:57 -08001144}
1145
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001146CONFIGFS_ATTR(lio_target_tpg_, enable);
1147CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
Nicholas Bellingerd4ee46f2015-03-06 20:40:57 -08001148
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001149static struct configfs_attribute *lio_target_tpg_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001150 &lio_target_tpg_attr_enable,
1151 &lio_target_tpg_attr_dynamic_sessions,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001152 NULL,
1153};
1154
1155/* End items for lio_target_tpg_cit */
1156
1157/* Start items for lio_target_tiqn_cit */
1158
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -04001159static struct se_portal_group *lio_target_tiqn_addtpg(
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001160 struct se_wwn *wwn,
1161 struct config_group *group,
1162 const char *name)
1163{
1164 struct iscsi_portal_group *tpg;
1165 struct iscsi_tiqn *tiqn;
Jörn Engelad7babd2013-07-03 11:35:11 -04001166 char *tpgt_str;
1167 int ret;
1168 u16 tpgt;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001169
1170 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1171 /*
1172 * Only tpgt_# directory groups can be created below
1173 * target/iscsi/iqn.superturodiskarry/
Jörn Engelad7babd2013-07-03 11:35:11 -04001174 */
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001175 tpgt_str = strstr(name, "tpgt_");
1176 if (!tpgt_str) {
1177 pr_err("Unable to locate \"tpgt_#\" directory"
1178 " group\n");
1179 return NULL;
1180 }
1181 tpgt_str += 5; /* Skip ahead of "tpgt_" */
Jörn Engelad7babd2013-07-03 11:35:11 -04001182 ret = kstrtou16(tpgt_str, 0, &tpgt);
1183 if (ret)
1184 return NULL;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001185
1186 tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1187 if (!tpg)
1188 return NULL;
1189
Nicholas Bellingerbc0c94b2015-05-20 21:48:03 -07001190 ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001191 if (ret < 0)
1192 return NULL;
1193
1194 ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1195 if (ret != 0)
1196 goto out;
1197
1198 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1199 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1200 name);
1201 return &tpg->tpg_se_tpg;
1202out:
1203 core_tpg_deregister(&tpg->tpg_se_tpg);
1204 kfree(tpg);
1205 return NULL;
1206}
1207
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -04001208static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001209{
1210 struct iscsi_portal_group *tpg;
1211 struct iscsi_tiqn *tiqn;
1212
1213 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1214 tiqn = tpg->tpg_tiqn;
1215 /*
1216 * iscsit_tpg_del_portal_group() assumes force=1
1217 */
1218 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1219 iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1220}
1221
1222/* End items for lio_target_tiqn_cit */
1223
1224/* Start LIO-Target TIQN struct contig_item lio_target_cit */
1225
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001226static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
1227 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001228{
Nicholas Bellinger4c762512013-09-05 15:29:12 -07001229 return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001230}
1231
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001232CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001233
1234static struct configfs_attribute *lio_target_wwn_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001235 &lio_target_wwn_attr_lio_version,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001236 NULL,
1237};
1238
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -04001239static struct se_wwn *lio_target_call_coreaddtiqn(
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001240 struct target_fabric_configfs *tf,
1241 struct config_group *group,
1242 const char *name)
1243{
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001244 struct iscsi_tiqn *tiqn;
1245
1246 tiqn = iscsit_add_tiqn((unsigned char *)name);
1247 if (IS_ERR(tiqn))
Thomas Meyere1750ba2011-08-01 23:58:18 +02001248 return ERR_CAST(tiqn);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001249
Andy Groverb7eec2c2013-10-09 11:05:57 -07001250 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001251 "iscsi_instance", &iscsi_stat_instance_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001252 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1253 &tiqn->tiqn_wwn.fabric_stat_group);
1254
Andy Groverb7eec2c2013-10-09 11:05:57 -07001255 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001256 "iscsi_sess_err", &iscsi_stat_sess_err_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001257 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1258 &tiqn->tiqn_wwn.fabric_stat_group);
1259
Andy Groverb7eec2c2013-10-09 11:05:57 -07001260 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001261 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001262 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1263 &tiqn->tiqn_wwn.fabric_stat_group);
1264
Andy Groverb7eec2c2013-10-09 11:05:57 -07001265 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001266 "iscsi_login_stats", &iscsi_stat_login_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001267 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1268 &tiqn->tiqn_wwn.fabric_stat_group);
1269
Andy Groverb7eec2c2013-10-09 11:05:57 -07001270 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001271 "iscsi_logout_stats", &iscsi_stat_logout_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001272 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1273 &tiqn->tiqn_wwn.fabric_stat_group);
1274
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001275
1276 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1277 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1278 " %s\n", name);
1279 return &tiqn->tiqn_wwn;
1280}
1281
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -04001282static void lio_target_call_coredeltiqn(
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001283 struct se_wwn *wwn)
1284{
1285 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001286
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001287 configfs_remove_default_groups(&tiqn->tiqn_wwn.fabric_stat_group);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001288
1289 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1290 tiqn->tiqn);
1291 iscsit_del_tiqn(tiqn);
1292}
1293
1294/* End LIO-Target TIQN struct contig_lio_target_cit */
1295
1296/* Start lio_target_discovery_auth_cit */
1297
1298#define DEF_DISC_AUTH_STR(name, flags) \
1299 __DEF_NACL_AUTH_STR(disc, name, flags) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001300static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001301{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001302 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001303 page); \
1304} \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001305static ssize_t iscsi_disc_##name##_store(struct config_item *item, \
1306 const char *page, size_t count) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001307{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001308 return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001309 page, count); \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001310 \
1311} \
1312CONFIGFS_ATTR(iscsi_disc_, name)
1313
1314DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1315DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1316DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1317DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001318
1319#define DEF_DISC_AUTH_INT(name) \
1320 __DEF_NACL_AUTH_INT(disc, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001321static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001322{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001323 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001324 page); \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001325} \
1326CONFIGFS_ATTR_RO(iscsi_disc_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001327
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001328DEF_DISC_AUTH_INT(authenticate_target);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001329
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001330
1331static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
1332 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001333{
1334 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1335
1336 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1337}
1338
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001339static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1340 const char *page, size_t count)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001341{
1342 struct iscsi_param *param;
1343 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001344 u32 op;
Jörn Engelad7babd2013-07-03 11:35:11 -04001345 int err;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001346
Jörn Engelad7babd2013-07-03 11:35:11 -04001347 err = kstrtou32(page, 0, &op);
1348 if (err)
1349 return -EINVAL;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001350 if ((op != 1) && (op != 0)) {
1351 pr_err("Illegal value for enforce_discovery_auth:"
1352 " %u\n", op);
1353 return -EINVAL;
1354 }
1355
1356 if (!discovery_tpg) {
1357 pr_err("iscsit_global->discovery_tpg is NULL\n");
1358 return -EINVAL;
1359 }
1360
1361 param = iscsi_find_param_from_key(AUTHMETHOD,
1362 discovery_tpg->param_list);
1363 if (!param)
1364 return -EINVAL;
1365
1366 if (op) {
1367 /*
1368 * Reset the AuthMethod key to CHAP.
1369 */
1370 if (iscsi_update_param_value(param, CHAP) < 0)
1371 return -EINVAL;
1372
1373 discovery_tpg->tpg_attrib.authentication = 1;
1374 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1375 pr_debug("LIO-CORE[0] Successfully enabled"
1376 " authentication enforcement for iSCSI"
1377 " Discovery TPG\n");
1378 } else {
1379 /*
1380 * Reset the AuthMethod key to CHAP,None
1381 */
1382 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1383 return -EINVAL;
1384
1385 discovery_tpg->tpg_attrib.authentication = 0;
1386 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1387 pr_debug("LIO-CORE[0] Successfully disabled"
1388 " authentication enforcement for iSCSI"
1389 " Discovery TPG\n");
1390 }
1391
1392 return count;
1393}
1394
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001395CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001396
1397static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001398 &iscsi_disc_attr_userid,
1399 &iscsi_disc_attr_password,
1400 &iscsi_disc_attr_authenticate_target,
1401 &iscsi_disc_attr_userid_mutual,
1402 &iscsi_disc_attr_password_mutual,
1403 &iscsi_disc_attr_enforce_discovery_auth,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001404 NULL,
1405};
1406
1407/* End lio_target_discovery_auth_cit */
1408
1409/* Start functions for target_core_fabric_ops */
1410
1411static char *iscsi_get_fabric_name(void)
1412{
1413 return "iSCSI";
1414}
1415
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001416static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1417{
1418 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1419
1420 return cmd->i_state;
1421}
1422
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001423static u32 lio_sess_get_index(struct se_session *se_sess)
1424{
1425 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1426
1427 return sess->session_index;
1428}
1429
1430static u32 lio_sess_get_initiator_sid(
1431 struct se_session *se_sess,
1432 unsigned char *buf,
1433 u32 size)
1434{
1435 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1436 /*
1437 * iSCSI Initiator Session Identifier from RFC-3720.
1438 */
Andy Shevchenko5cdf5a82015-01-15 13:40:56 +02001439 return snprintf(buf, size, "%6phN", sess->isid);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001440}
1441
1442static int lio_queue_data_in(struct se_cmd *se_cmd)
1443{
1444 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1445
1446 cmd->i_state = ISTATE_SEND_DATAIN;
Nicholas Bellinger2ec5a8c2013-03-20 15:29:15 -07001447 cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd);
1448
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001449 return 0;
1450}
1451
1452static int lio_write_pending(struct se_cmd *se_cmd)
1453{
1454 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
Nicholas Bellinger3e1c81a2013-03-06 22:18:24 -08001455 struct iscsi_conn *conn = cmd->conn;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001456
1457 if (!cmd->immediate_data && !cmd->unsolicited_data)
Nicholas Bellinger3e1c81a2013-03-06 22:18:24 -08001458 return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001459
1460 return 0;
1461}
1462
1463static int lio_write_pending_status(struct se_cmd *se_cmd)
1464{
1465 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1466 int ret;
1467
1468 spin_lock_bh(&cmd->istate_lock);
1469 ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1470 spin_unlock_bh(&cmd->istate_lock);
1471
1472 return ret;
1473}
1474
1475static int lio_queue_status(struct se_cmd *se_cmd)
1476{
1477 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1478
1479 cmd->i_state = ISTATE_SEND_STATUS;
Nicholas Bellinger5e8e6b42013-11-12 17:54:56 -08001480
1481 if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
1482 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1483 return 0;
1484 }
Nicholas Bellinger2ec5a8c2013-03-20 15:29:15 -07001485 cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd);
1486
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001487 return 0;
1488}
1489
Joern Engelb79fafa2013-07-03 11:22:17 -04001490static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001491{
1492 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1493
1494 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1495 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001496}
1497
Nicholas Bellinger131e6ab2014-03-22 14:55:56 -07001498static void lio_aborted_task(struct se_cmd *se_cmd)
1499{
1500 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1501
1502 cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1503}
1504
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001505static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg)
1506{
1507 return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1508}
1509
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001510static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1511{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001512 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001513}
1514
1515static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1516{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001517 return iscsi_tpg(se_tpg)->tpgt;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001518}
1519
1520static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1521{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001522 return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001523}
1524
1525static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1526{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001527 return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001528}
1529
1530static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1531{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001532 return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001533}
1534
1535static int lio_tpg_check_demo_mode_write_protect(
1536 struct se_portal_group *se_tpg)
1537{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001538 return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001539}
1540
1541static int lio_tpg_check_prod_mode_write_protect(
1542 struct se_portal_group *se_tpg)
1543{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001544 return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001545}
1546
Nicholas Bellinger901c04a2015-03-29 19:36:16 -07001547static int lio_tpg_check_prot_fabric_only(
1548 struct se_portal_group *se_tpg)
1549{
Nicholas Bellinger901c04a2015-03-29 19:36:16 -07001550 /*
1551 * Only report fabric_prot_type if t10_pi has also been enabled
1552 * for incoming ib_isert sessions.
1553 */
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001554 if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
Nicholas Bellinger901c04a2015-03-29 19:36:16 -07001555 return 0;
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001556 return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
Nicholas Bellinger901c04a2015-03-29 19:36:16 -07001557}
1558
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001559/*
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001560 * This function calls iscsit_inc_session_usage_count() on the
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001561 * struct iscsi_session in question.
1562 */
1563static int lio_tpg_shutdown_session(struct se_session *se_sess)
1564{
1565 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001566 struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
Nicholas Bellinger26a99c12016-01-19 16:15:27 -08001567
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001568 spin_lock_bh(&se_tpg->session_lock);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001569 spin_lock(&sess->conn_lock);
1570 if (atomic_read(&sess->session_fall_back_to_erl0) ||
1571 atomic_read(&sess->session_logout) ||
1572 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1573 spin_unlock(&sess->conn_lock);
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001574 spin_unlock_bh(&se_tpg->session_lock);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001575 return 0;
1576 }
1577 atomic_set(&sess->session_reinstatement, 1);
1578 spin_unlock(&sess->conn_lock);
1579
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001580 iscsit_stop_time2retain_timer(sess);
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001581 spin_unlock_bh(&se_tpg->session_lock);
Nicholas Bellinger26a99c12016-01-19 16:15:27 -08001582
Nicholas Bellinger99367f02012-02-27 01:43:32 -08001583 iscsit_stop_session(sess, 1, 1);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001584 return 1;
1585}
1586
1587/*
1588 * Calls iscsit_dec_session_usage_count() as inverse of
1589 * lio_tpg_shutdown_session()
1590 */
1591static void lio_tpg_close_session(struct se_session *se_sess)
1592{
1593 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1594 /*
1595 * If the iSCSI Session for the iSCSI Initiator Node exists,
1596 * forcefully shutdown the iSCSI NEXUS.
1597 */
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001598 iscsit_close_session(sess);
1599}
1600
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001601static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1602{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001603 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001604}
1605
1606static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1607{
1608 struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1609 se_node_acl);
Nicholas Bellingerd1fa7a12013-11-20 11:57:18 -08001610 struct se_portal_group *se_tpg = se_acl->se_tpg;
1611 struct iscsi_portal_group *tpg = container_of(se_tpg,
1612 struct iscsi_portal_group, tpg_se_tpg);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001613
Andy Groverb7eec2c2013-10-09 11:05:57 -07001614 acl->node_attrib.nacl = acl;
Nicholas Bellingerd1fa7a12013-11-20 11:57:18 -08001615 iscsit_set_default_node_attribues(acl, tpg);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001616}
1617
Nicholas Bellinger3e1c81a2013-03-06 22:18:24 -08001618static int lio_check_stop_free(struct se_cmd *se_cmd)
1619{
Bart Van Asscheafc16602015-04-27 13:52:36 +02001620 return target_put_sess_cmd(se_cmd);
Nicholas Bellinger3e1c81a2013-03-06 22:18:24 -08001621}
1622
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001623static void lio_release_cmd(struct se_cmd *se_cmd)
1624{
1625 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1626
Nicholas Bellingercdb72662013-03-06 22:09:17 -08001627 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001628 iscsit_release_cmd(cmd);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001629}
1630
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001631const struct target_core_fabric_ops iscsi_ops = {
1632 .module = THIS_MODULE,
1633 .name = "iscsi",
Christoph Hellwig144bc4c2015-04-13 19:51:16 +02001634 .node_acl_size = sizeof(struct iscsi_node_acl),
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001635 .get_fabric_name = iscsi_get_fabric_name,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001636 .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
1637 .tpg_get_tag = lio_tpg_get_tag,
1638 .tpg_get_default_depth = lio_tpg_get_default_depth,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001639 .tpg_check_demo_mode = lio_tpg_check_demo_mode,
1640 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
1641 .tpg_check_demo_mode_write_protect =
1642 lio_tpg_check_demo_mode_write_protect,
1643 .tpg_check_prod_mode_write_protect =
1644 lio_tpg_check_prod_mode_write_protect,
1645 .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001646 .tpg_get_inst_index = lio_tpg_get_inst_index,
1647 .check_stop_free = lio_check_stop_free,
1648 .release_cmd = lio_release_cmd,
1649 .shutdown_session = lio_tpg_shutdown_session,
1650 .close_session = lio_tpg_close_session,
1651 .sess_get_index = lio_sess_get_index,
1652 .sess_get_initiator_sid = lio_sess_get_initiator_sid,
1653 .write_pending = lio_write_pending,
1654 .write_pending_status = lio_write_pending_status,
1655 .set_default_node_attributes = lio_set_default_node_attributes,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001656 .get_cmd_state = iscsi_get_cmd_state,
1657 .queue_data_in = lio_queue_data_in,
1658 .queue_status = lio_queue_status,
1659 .queue_tm_rsp = lio_queue_tm_rsp,
1660 .aborted_task = lio_aborted_task,
1661 .fabric_make_wwn = lio_target_call_coreaddtiqn,
1662 .fabric_drop_wwn = lio_target_call_coredeltiqn,
1663 .fabric_make_tpg = lio_target_tiqn_addtpg,
1664 .fabric_drop_tpg = lio_target_tiqn_deltpg,
1665 .fabric_make_np = lio_target_call_addnptotpg,
1666 .fabric_drop_np = lio_target_call_delnpfromtpg,
Christoph Hellwigc7d6a802015-04-13 19:51:14 +02001667 .fabric_init_nodeacl = lio_target_init_nodeacl,
1668 .fabric_cleanup_nodeacl = lio_target_cleanup_nodeacl,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001669
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001670 .tfc_discovery_attrs = lio_target_discovery_auth_attrs,
1671 .tfc_wwn_attrs = lio_target_wwn_attrs,
1672 .tfc_tpg_base_attrs = lio_target_tpg_attrs,
1673 .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs,
1674 .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs,
1675 .tfc_tpg_param_attrs = lio_target_tpg_param_attrs,
1676 .tfc_tpg_np_base_attrs = lio_target_portal_attrs,
1677 .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs,
1678 .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs,
1679 .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs,
1680 .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs,
1681};