blob: 1b8f885dbfebec033f9b04755041787bd73fa552 [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
Varun Prakash1c469602016-04-20 00:00:16 +0530185static ssize_t lio_target_np_hw_offload_show(struct config_item *item,
186 char *page)
187{
188 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
189 struct iscsi_tpg_np *tpg_np_hw_offload;
190 ssize_t rb;
191
192 tpg_np_hw_offload = iscsit_tpg_locate_child_np(tpg_np,
193 ISCSI_HW_OFFLOAD);
194 if (tpg_np_hw_offload)
195 rb = sprintf(page, "1\n");
196 else
197 rb = sprintf(page, "0\n");
198
199 return rb;
200}
201
202static ssize_t lio_target_np_hw_offload_store(struct config_item *item,
203 const char *page, size_t count)
204{
205 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
206 struct iscsi_np *np;
207 struct iscsi_portal_group *tpg;
208 struct iscsi_tpg_np *tpg_np_hw_offload = NULL;
209 u32 op;
210 int rc = 0;
211
212 rc = kstrtou32(page, 0, &op);
213 if (rc)
214 return rc;
215
216 if ((op != 1) && (op != 0)) {
217 pr_err("Illegal value for tpg_enable: %u\n", op);
218 return -EINVAL;
219 }
220
221 np = tpg_np->tpg_np;
222 if (!np) {
223 pr_err("Unable to locate struct iscsi_np from"
224 " struct iscsi_tpg_np\n");
225 return -EINVAL;
226 }
227
228 tpg = tpg_np->tpg;
229 if (iscsit_get_tpg(tpg) < 0)
230 return -EINVAL;
231
232 if (op) {
233 tpg_np_hw_offload = iscsit_tpg_add_network_portal(tpg,
234 &np->np_sockaddr, tpg_np, ISCSI_HW_OFFLOAD);
235
236 if (IS_ERR(tpg_np_hw_offload)) {
237 rc = PTR_ERR(tpg_np_hw_offload);
238 goto out;
239 }
240 } else {
241 tpg_np_hw_offload = iscsit_tpg_locate_child_np(tpg_np,
242 ISCSI_HW_OFFLOAD);
243
244 if (tpg_np_hw_offload) {
245 rc = iscsit_tpg_del_network_portal(tpg,
246 tpg_np_hw_offload);
247 if (rc < 0)
248 goto out;
249 }
250 }
251
252 iscsit_put_tpg(tpg);
253 return count;
254out:
255 iscsit_put_tpg(tpg);
256 return rc;
257}
258
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200259CONFIGFS_ATTR(lio_target_np_, sctp);
260CONFIGFS_ATTR(lio_target_np_, iser);
Varun Prakash1c469602016-04-20 00:00:16 +0530261CONFIGFS_ATTR(lio_target_np_, hw_offload);
Nicholas Bellinger72438cd2013-03-06 22:20:36 -0800262
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000263static struct configfs_attribute *lio_target_portal_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200264 &lio_target_np_attr_sctp,
265 &lio_target_np_attr_iser,
Varun Prakash1c469602016-04-20 00:00:16 +0530266 &lio_target_np_attr_hw_offload,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000267 NULL,
268};
269
270/* Stop items for lio_target_portal_cit */
271
272/* Start items for lio_target_np_cit */
273
274#define MAX_PORTAL_LEN 256
275
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -0400276static struct se_tpg_np *lio_target_call_addnptotpg(
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000277 struct se_portal_group *se_tpg,
278 struct config_group *group,
279 const char *name)
280{
281 struct iscsi_portal_group *tpg;
282 struct iscsi_tpg_np *tpg_np;
283 char *str, *str2, *ip_str, *port_str;
Andy Grover13a3cf02015-08-24 10:26:06 -0700284 struct sockaddr_storage sockaddr;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000285 struct sockaddr_in *sock_in;
286 struct sockaddr_in6 *sock_in6;
287 unsigned long port;
288 int ret;
289 char buf[MAX_PORTAL_LEN + 1];
290
291 if (strlen(name) > MAX_PORTAL_LEN) {
292 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
293 (int)strlen(name), MAX_PORTAL_LEN);
294 return ERR_PTR(-EOVERFLOW);
295 }
296 memset(buf, 0, MAX_PORTAL_LEN + 1);
Nicholas Bellinger7bbb6542011-07-27 12:37:03 -0700297 snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000298
Andy Grover13a3cf02015-08-24 10:26:06 -0700299 memset(&sockaddr, 0, sizeof(struct sockaddr_storage));
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000300
301 str = strstr(buf, "[");
302 if (str) {
303 const char *end;
304
305 str2 = strstr(str, "]");
306 if (!str2) {
307 pr_err("Unable to locate trailing \"]\""
308 " in IPv6 iSCSI network portal address\n");
309 return ERR_PTR(-EINVAL);
310 }
311 str++; /* Skip over leading "[" */
Andy Grover76c28f12015-08-24 10:26:03 -0700312 *str2 = '\0'; /* Terminate the unbracketed IPv6 address */
313 str2++; /* Skip over the \0 */
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000314 port_str = strstr(str2, ":");
315 if (!port_str) {
316 pr_err("Unable to locate \":port\""
317 " in IPv6 iSCSI network portal address\n");
318 return ERR_PTR(-EINVAL);
319 }
320 *port_str = '\0'; /* Terminate string for IP */
321 port_str++; /* Skip over ":" */
322
Jingoo Han57103d72013-07-19 16:22:19 +0900323 ret = kstrtoul(port_str, 0, &port);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000324 if (ret < 0) {
Jingoo Han57103d72013-07-19 16:22:19 +0900325 pr_err("kstrtoul() failed for port_str: %d\n", ret);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000326 return ERR_PTR(ret);
327 }
328 sock_in6 = (struct sockaddr_in6 *)&sockaddr;
329 sock_in6->sin6_family = AF_INET6;
330 sock_in6->sin6_port = htons((unsigned short)port);
Andy Groverdc58f762015-08-24 10:26:05 -0700331 ret = in6_pton(str, -1,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000332 (void *)&sock_in6->sin6_addr.in6_u, -1, &end);
333 if (ret <= 0) {
334 pr_err("in6_pton returned: %d\n", ret);
335 return ERR_PTR(-EINVAL);
336 }
337 } else {
338 str = ip_str = &buf[0];
339 port_str = strstr(ip_str, ":");
340 if (!port_str) {
341 pr_err("Unable to locate \":port\""
342 " in IPv4 iSCSI network portal address\n");
343 return ERR_PTR(-EINVAL);
344 }
345 *port_str = '\0'; /* Terminate string for IP */
346 port_str++; /* Skip over ":" */
347
Jingoo Han57103d72013-07-19 16:22:19 +0900348 ret = kstrtoul(port_str, 0, &port);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000349 if (ret < 0) {
Jingoo Han57103d72013-07-19 16:22:19 +0900350 pr_err("kstrtoul() failed for port_str: %d\n", ret);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000351 return ERR_PTR(ret);
352 }
353 sock_in = (struct sockaddr_in *)&sockaddr;
354 sock_in->sin_family = AF_INET;
355 sock_in->sin_port = htons((unsigned short)port);
356 sock_in->sin_addr.s_addr = in_aton(ip_str);
357 }
358 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
359 ret = iscsit_get_tpg(tpg);
360 if (ret < 0)
361 return ERR_PTR(-EINVAL);
362
363 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
364 " PORTAL: %s\n",
365 config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
366 tpg->tpgt, name);
367 /*
368 * Assume ISCSI_TCP by default. Other network portals for other
369 * iSCSI fabrics:
370 *
371 * Traditional iSCSI over SCTP (initial support)
372 * iSER/TCP (TODO, hardware available)
373 * iSER/SCTP (TODO, software emulation with osc-iwarp)
374 * iSER/IB (TODO, hardware available)
375 *
Masanari Iida20879692012-08-27 22:46:00 +0900376 * can be enabled with attributes under
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000377 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
378 *
379 */
Andy Grover76c28f12015-08-24 10:26:03 -0700380 tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000381 ISCSI_TCP);
382 if (IS_ERR(tpg_np)) {
383 iscsit_put_tpg(tpg);
Thomas Meyere1750ba2011-08-01 23:58:18 +0200384 return ERR_CAST(tpg_np);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000385 }
386 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
387
388 iscsit_put_tpg(tpg);
389 return &tpg_np->se_tpg_np;
390}
391
392static void lio_target_call_delnpfromtpg(
393 struct se_tpg_np *se_tpg_np)
394{
395 struct iscsi_portal_group *tpg;
396 struct iscsi_tpg_np *tpg_np;
397 struct se_portal_group *se_tpg;
398 int ret;
399
400 tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
401 tpg = tpg_np->tpg;
402 ret = iscsit_get_tpg(tpg);
403 if (ret < 0)
404 return;
405
406 se_tpg = &tpg->tpg_se_tpg;
407 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
Andy Grover69d75572015-08-24 10:26:04 -0700408 " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
409 tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000410
411 ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
412 if (ret < 0)
413 goto out;
414
415 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
416out:
417 iscsit_put_tpg(tpg);
418}
419
420/* End items for lio_target_np_cit */
421
422/* Start items for lio_target_nacl_attrib_cit */
423
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200424#define ISCSI_NACL_ATTR(name) \
425static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
426 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000427{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200428 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000429 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
430 se_node_acl); \
431 \
Andy Groverb7eec2c2013-10-09 11:05:57 -0700432 return sprintf(page, "%u\n", nacl->node_attrib.name); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000433} \
434 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200435static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
436 const char *page, size_t count) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000437{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200438 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000439 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
440 se_node_acl); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000441 u32 val; \
442 int ret; \
443 \
Jörn Engelad7babd2013-07-03 11:35:11 -0400444 ret = kstrtou32(page, 0, &val); \
445 if (ret) \
446 return ret; \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000447 ret = iscsit_na_##name(nacl, val); \
448 if (ret < 0) \
449 return ret; \
450 \
451 return count; \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200452} \
453 \
454CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000455
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200456ISCSI_NACL_ATTR(dataout_timeout);
457ISCSI_NACL_ATTR(dataout_timeout_retries);
458ISCSI_NACL_ATTR(default_erl);
459ISCSI_NACL_ATTR(nopin_timeout);
460ISCSI_NACL_ATTR(nopin_response_timeout);
461ISCSI_NACL_ATTR(random_datain_pdu_offsets);
462ISCSI_NACL_ATTR(random_datain_seq_offsets);
463ISCSI_NACL_ATTR(random_r2t_offsets);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000464
465static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200466 &iscsi_nacl_attrib_attr_dataout_timeout,
467 &iscsi_nacl_attrib_attr_dataout_timeout_retries,
468 &iscsi_nacl_attrib_attr_default_erl,
469 &iscsi_nacl_attrib_attr_nopin_timeout,
470 &iscsi_nacl_attrib_attr_nopin_response_timeout,
471 &iscsi_nacl_attrib_attr_random_datain_pdu_offsets,
472 &iscsi_nacl_attrib_attr_random_datain_seq_offsets,
473 &iscsi_nacl_attrib_attr_random_r2t_offsets,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000474 NULL,
475};
476
477/* End items for lio_target_nacl_attrib_cit */
478
479/* Start items for lio_target_nacl_auth_cit */
480
481#define __DEF_NACL_AUTH_STR(prefix, name, flags) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200482static ssize_t __iscsi_##prefix##_##name##_show( \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000483 struct iscsi_node_acl *nacl, \
484 char *page) \
485{ \
486 struct iscsi_node_auth *auth = &nacl->node_auth; \
487 \
488 if (!capable(CAP_SYS_ADMIN)) \
489 return -EPERM; \
490 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
491} \
492 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200493static ssize_t __iscsi_##prefix##_##name##_store( \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000494 struct iscsi_node_acl *nacl, \
495 const char *page, \
496 size_t count) \
497{ \
498 struct iscsi_node_auth *auth = &nacl->node_auth; \
499 \
500 if (!capable(CAP_SYS_ADMIN)) \
501 return -EPERM; \
Eric Seppanen2306bfb2013-11-21 14:49:56 -0800502 if (count >= sizeof(auth->name)) \
503 return -EINVAL; \
Jörn Engel0fbfc462013-07-03 11:35:11 -0400504 snprintf(auth->name, sizeof(auth->name), "%s", page); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000505 if (!strncmp("NULL", auth->name, 4)) \
506 auth->naf_flags &= ~flags; \
507 else \
508 auth->naf_flags |= flags; \
509 \
510 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
511 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
512 auth->authenticate_target = 1; \
513 else \
514 auth->authenticate_target = 0; \
515 \
516 return count; \
517}
518
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200519#define DEF_NACL_AUTH_STR(name, flags) \
520 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
521static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
522 char *page) \
523{ \
524 struct se_node_acl *nacl = auth_to_nacl(item); \
525 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
526 struct iscsi_node_acl, se_node_acl), page); \
527} \
528static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \
529 const char *page, size_t count) \
530{ \
531 struct se_node_acl *nacl = auth_to_nacl(item); \
532 return __iscsi_nacl_auth_##name##_store(container_of(nacl, \
533 struct iscsi_node_acl, se_node_acl), page, count); \
534} \
535 \
536CONFIGFS_ATTR(iscsi_nacl_auth_, name)
537
538/*
539 * One-way authentication userid
540 */
541DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
542DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
543DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
544DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
545
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000546#define __DEF_NACL_AUTH_INT(prefix, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200547static ssize_t __iscsi_##prefix##_##name##_show( \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000548 struct iscsi_node_acl *nacl, \
549 char *page) \
550{ \
551 struct iscsi_node_auth *auth = &nacl->node_auth; \
552 \
553 if (!capable(CAP_SYS_ADMIN)) \
554 return -EPERM; \
555 \
556 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
557}
558
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000559#define DEF_NACL_AUTH_INT(name) \
560 __DEF_NACL_AUTH_INT(nacl_auth, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200561static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
562 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000563{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200564 struct se_node_acl *nacl = auth_to_nacl(item); \
565 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
566 struct iscsi_node_acl, se_node_acl), page); \
567} \
568 \
569CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000570
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000571DEF_NACL_AUTH_INT(authenticate_target);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000572
573static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200574 &iscsi_nacl_auth_attr_userid,
575 &iscsi_nacl_auth_attr_password,
576 &iscsi_nacl_auth_attr_authenticate_target,
577 &iscsi_nacl_auth_attr_userid_mutual,
578 &iscsi_nacl_auth_attr_password_mutual,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000579 NULL,
580};
581
582/* End items for lio_target_nacl_auth_cit */
583
584/* Start items for lio_target_nacl_param_cit */
585
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200586#define ISCSI_NACL_PARAM(name) \
587static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \
588 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000589{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200590 struct se_node_acl *se_nacl = param_to_nacl(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000591 struct iscsi_session *sess; \
592 struct se_session *se_sess; \
593 ssize_t rb; \
594 \
595 spin_lock_bh(&se_nacl->nacl_sess_lock); \
596 se_sess = se_nacl->nacl_sess; \
597 if (!se_sess) { \
598 rb = snprintf(page, PAGE_SIZE, \
599 "No Active iSCSI Session\n"); \
600 } else { \
601 sess = se_sess->fabric_sess_ptr; \
602 rb = snprintf(page, PAGE_SIZE, "%u\n", \
603 (u32)sess->sess_ops->name); \
604 } \
605 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
606 \
607 return rb; \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200608} \
609 \
610CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000611
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200612ISCSI_NACL_PARAM(MaxConnections);
613ISCSI_NACL_PARAM(InitialR2T);
614ISCSI_NACL_PARAM(ImmediateData);
615ISCSI_NACL_PARAM(MaxBurstLength);
616ISCSI_NACL_PARAM(FirstBurstLength);
617ISCSI_NACL_PARAM(DefaultTime2Wait);
618ISCSI_NACL_PARAM(DefaultTime2Retain);
619ISCSI_NACL_PARAM(MaxOutstandingR2T);
620ISCSI_NACL_PARAM(DataPDUInOrder);
621ISCSI_NACL_PARAM(DataSequenceInOrder);
622ISCSI_NACL_PARAM(ErrorRecoveryLevel);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000623
624static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200625 &iscsi_nacl_param_attr_MaxConnections,
626 &iscsi_nacl_param_attr_InitialR2T,
627 &iscsi_nacl_param_attr_ImmediateData,
628 &iscsi_nacl_param_attr_MaxBurstLength,
629 &iscsi_nacl_param_attr_FirstBurstLength,
630 &iscsi_nacl_param_attr_DefaultTime2Wait,
631 &iscsi_nacl_param_attr_DefaultTime2Retain,
632 &iscsi_nacl_param_attr_MaxOutstandingR2T,
633 &iscsi_nacl_param_attr_DataPDUInOrder,
634 &iscsi_nacl_param_attr_DataSequenceInOrder,
635 &iscsi_nacl_param_attr_ErrorRecoveryLevel,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000636 NULL,
637};
638
639/* End items for lio_target_nacl_param_cit */
640
641/* Start items for lio_target_acl_cit */
642
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200643static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000644{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200645 struct se_node_acl *se_nacl = acl_to_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000646 struct iscsi_session *sess;
647 struct iscsi_conn *conn;
648 struct se_session *se_sess;
649 ssize_t rb = 0;
Roland Dreier109e2382015-07-23 14:53:32 -0700650 u32 max_cmd_sn;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000651
652 spin_lock_bh(&se_nacl->nacl_sess_lock);
653 se_sess = se_nacl->nacl_sess;
654 if (!se_sess) {
655 rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
656 " Endpoint: %s\n", se_nacl->initiatorname);
657 } else {
658 sess = se_sess->fabric_sess_ptr;
659
Joern Engelcb354842014-09-02 17:49:50 -0400660 rb += sprintf(page+rb, "InitiatorName: %s\n",
661 sess->sess_ops->InitiatorName);
662 rb += sprintf(page+rb, "InitiatorAlias: %s\n",
663 sess->sess_ops->InitiatorAlias);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000664
Andy Shevchenko5cdf5a82015-01-15 13:40:56 +0200665 rb += sprintf(page+rb,
666 "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ",
667 sess->sid, sess->isid, sess->tsih);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000668 rb += sprintf(page+rb, "SessionType: %s\n",
669 (sess->sess_ops->SessionType) ?
670 "Discovery" : "Normal");
671 rb += sprintf(page+rb, "Session State: ");
672 switch (sess->session_state) {
673 case TARG_SESS_STATE_FREE:
674 rb += sprintf(page+rb, "TARG_SESS_FREE\n");
675 break;
676 case TARG_SESS_STATE_ACTIVE:
677 rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
678 break;
679 case TARG_SESS_STATE_LOGGED_IN:
680 rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
681 break;
682 case TARG_SESS_STATE_FAILED:
683 rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
684 break;
685 case TARG_SESS_STATE_IN_CONTINUE:
686 rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
687 break;
688 default:
689 rb += sprintf(page+rb, "ERROR: Unknown Session"
690 " State!\n");
691 break;
692 }
693
694 rb += sprintf(page+rb, "---------------------[iSCSI Session"
695 " Values]-----------------------\n");
696 rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
697 " : MaxCmdSN : ITT : TTT\n");
Roland Dreier109e2382015-07-23 14:53:32 -0700698 max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000699 rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
700 " 0x%08x 0x%08x\n",
701 sess->cmdsn_window,
Roland Dreier109e2382015-07-23 14:53:32 -0700702 (max_cmd_sn - sess->exp_cmd_sn) + 1,
703 sess->exp_cmd_sn, max_cmd_sn,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000704 sess->init_task_tag, sess->targ_xfer_tag);
705 rb += sprintf(page+rb, "----------------------[iSCSI"
706 " Connections]-------------------------\n");
707
708 spin_lock(&sess->conn_lock);
709 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
710 rb += sprintf(page+rb, "CID: %hu Connection"
711 " State: ", conn->cid);
712 switch (conn->conn_state) {
713 case TARG_CONN_STATE_FREE:
714 rb += sprintf(page+rb,
715 "TARG_CONN_STATE_FREE\n");
716 break;
717 case TARG_CONN_STATE_XPT_UP:
718 rb += sprintf(page+rb,
719 "TARG_CONN_STATE_XPT_UP\n");
720 break;
721 case TARG_CONN_STATE_IN_LOGIN:
722 rb += sprintf(page+rb,
723 "TARG_CONN_STATE_IN_LOGIN\n");
724 break;
725 case TARG_CONN_STATE_LOGGED_IN:
726 rb += sprintf(page+rb,
727 "TARG_CONN_STATE_LOGGED_IN\n");
728 break;
729 case TARG_CONN_STATE_IN_LOGOUT:
730 rb += sprintf(page+rb,
731 "TARG_CONN_STATE_IN_LOGOUT\n");
732 break;
733 case TARG_CONN_STATE_LOGOUT_REQUESTED:
734 rb += sprintf(page+rb,
735 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
736 break;
737 case TARG_CONN_STATE_CLEANUP_WAIT:
738 rb += sprintf(page+rb,
739 "TARG_CONN_STATE_CLEANUP_WAIT\n");
740 break;
741 default:
742 rb += sprintf(page+rb,
743 "ERROR: Unknown Connection State!\n");
744 break;
745 }
746
Andy Groverdc58f762015-08-24 10:26:05 -0700747 rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000748 (conn->network_transport == ISCSI_TCP) ?
749 "TCP" : "SCTP");
750 rb += sprintf(page+rb, " StatSN: 0x%08x\n",
751 conn->stat_sn);
752 }
753 spin_unlock(&sess->conn_lock);
754 }
755 spin_unlock_bh(&se_nacl->nacl_sess_lock);
756
757 return rb;
758}
759
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200760static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
761 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000762{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200763 return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000764}
765
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200766static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
767 const char *page, size_t count)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000768{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200769 struct se_node_acl *se_nacl = acl_to_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000770 struct se_portal_group *se_tpg = se_nacl->se_tpg;
771 struct iscsi_portal_group *tpg = container_of(se_tpg,
772 struct iscsi_portal_group, tpg_se_tpg);
773 struct config_item *acl_ci, *tpg_ci, *wwn_ci;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000774 u32 cmdsn_depth = 0;
775 int ret;
776
Jörn Engelad7babd2013-07-03 11:35:11 -0400777 ret = kstrtou32(page, 0, &cmdsn_depth);
778 if (ret)
779 return ret;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000780 if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
781 pr_err("Passed cmdsn_depth: %u exceeds"
782 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
783 TA_DEFAULT_CMDSN_DEPTH_MAX);
784 return -EINVAL;
785 }
786 acl_ci = &se_nacl->acl_group.cg_item;
787 if (!acl_ci) {
788 pr_err("Unable to locatel acl_ci\n");
789 return -EINVAL;
790 }
791 tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
792 if (!tpg_ci) {
793 pr_err("Unable to locate tpg_ci\n");
794 return -EINVAL;
795 }
796 wwn_ci = &tpg_ci->ci_group->cg_item;
797 if (!wwn_ci) {
798 pr_err("Unable to locate config_item wwn_ci\n");
799 return -EINVAL;
800 }
801
802 if (iscsit_get_tpg(tpg) < 0)
803 return -EINVAL;
Nicholas Bellingerd36ad772016-01-07 22:15:06 -0800804
805 ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000806
807 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
808 "InitiatorName: %s\n", config_item_name(wwn_ci),
809 config_item_name(tpg_ci), cmdsn_depth,
810 config_item_name(acl_ci));
811
812 iscsit_put_tpg(tpg);
813 return (!ret) ? count : (ssize_t)ret;
814}
815
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200816static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
Andy Grover79e62fc2012-12-11 16:30:53 -0800817{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200818 return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
Andy Grover79e62fc2012-12-11 16:30:53 -0800819}
820
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200821static ssize_t lio_target_nacl_tag_store(struct config_item *item,
822 const char *page, size_t count)
Andy Grover79e62fc2012-12-11 16:30:53 -0800823{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200824 struct se_node_acl *se_nacl = acl_to_nacl(item);
Andy Grover79e62fc2012-12-11 16:30:53 -0800825 int ret;
826
827 ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
828
829 if (ret < 0)
830 return ret;
831 return count;
832}
833
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200834CONFIGFS_ATTR_RO(lio_target_nacl_, info);
835CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
836CONFIGFS_ATTR(lio_target_nacl_, tag);
Andy Grover79e62fc2012-12-11 16:30:53 -0800837
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000838static struct configfs_attribute *lio_target_initiator_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200839 &lio_target_nacl_attr_info,
840 &lio_target_nacl_attr_cmdsn_depth,
841 &lio_target_nacl_attr_tag,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000842 NULL,
843};
844
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200845static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
846 const char *name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000847{
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200848 struct iscsi_node_acl *acl =
849 container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000850
Andy Groverb7eec2c2013-10-09 11:05:57 -0700851 config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000852 "iscsi_sess_stats", &iscsi_stat_sess_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100853 configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group,
854 &se_nacl->acl_fabric_stat_group);
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200855 return 0;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000856}
857
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000858/* End items for lio_target_acl_cit */
859
860/* Start items for lio_target_tpg_attrib_cit */
861
862#define DEF_TPG_ATTRIB(name) \
863 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200864static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \
865 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000866{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200867 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000868 struct iscsi_portal_group *tpg = container_of(se_tpg, \
869 struct iscsi_portal_group, tpg_se_tpg); \
870 ssize_t rb; \
871 \
872 if (iscsit_get_tpg(tpg) < 0) \
873 return -EINVAL; \
874 \
Andy Groverb7eec2c2013-10-09 11:05:57 -0700875 rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000876 iscsit_put_tpg(tpg); \
877 return rb; \
878} \
879 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200880static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
881 const char *page, size_t count) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000882{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200883 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000884 struct iscsi_portal_group *tpg = container_of(se_tpg, \
885 struct iscsi_portal_group, tpg_se_tpg); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000886 u32 val; \
887 int ret; \
888 \
889 if (iscsit_get_tpg(tpg) < 0) \
890 return -EINVAL; \
891 \
Jörn Engelad7babd2013-07-03 11:35:11 -0400892 ret = kstrtou32(page, 0, &val); \
893 if (ret) \
894 goto out; \
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000895 ret = iscsit_ta_##name(tpg, val); \
896 if (ret < 0) \
897 goto out; \
898 \
899 iscsit_put_tpg(tpg); \
900 return count; \
901out: \
902 iscsit_put_tpg(tpg); \
903 return ret; \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200904} \
905CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000906
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000907DEF_TPG_ATTRIB(authentication);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000908DEF_TPG_ATTRIB(login_timeout);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000909DEF_TPG_ATTRIB(netif_timeout);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000910DEF_TPG_ATTRIB(generate_node_acls);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000911DEF_TPG_ATTRIB(default_cmdsn_depth);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000912DEF_TPG_ATTRIB(cache_dynamic_acls);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000913DEF_TPG_ATTRIB(demo_mode_write_protect);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000914DEF_TPG_ATTRIB(prod_mode_write_protect);
Thomas Glanzmann4c54b6c2013-10-07 23:12:11 +0200915DEF_TPG_ATTRIB(demo_mode_discovery);
Nicholas Bellingerd1fa7a12013-11-20 11:57:18 -0800916DEF_TPG_ATTRIB(default_erl);
Sagi Grimberg80851762014-02-19 17:50:20 +0200917DEF_TPG_ATTRIB(t10_pi);
Nicholas Bellinger901c04a2015-03-29 19:36:16 -0700918DEF_TPG_ATTRIB(fabric_prot_type);
David Disseldorpa6415cd2015-08-01 00:10:12 -0700919DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000920
921static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200922 &iscsi_tpg_attrib_attr_authentication,
923 &iscsi_tpg_attrib_attr_login_timeout,
924 &iscsi_tpg_attrib_attr_netif_timeout,
925 &iscsi_tpg_attrib_attr_generate_node_acls,
926 &iscsi_tpg_attrib_attr_default_cmdsn_depth,
927 &iscsi_tpg_attrib_attr_cache_dynamic_acls,
928 &iscsi_tpg_attrib_attr_demo_mode_write_protect,
929 &iscsi_tpg_attrib_attr_prod_mode_write_protect,
930 &iscsi_tpg_attrib_attr_demo_mode_discovery,
931 &iscsi_tpg_attrib_attr_default_erl,
932 &iscsi_tpg_attrib_attr_t10_pi,
933 &iscsi_tpg_attrib_attr_fabric_prot_type,
934 &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000935 NULL,
936};
937
938/* End items for lio_target_tpg_attrib_cit */
939
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700940/* Start items for lio_target_tpg_auth_cit */
941
942#define __DEF_TPG_AUTH_STR(prefix, name, flags) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200943static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
944 char *page) \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700945{ \
946 struct iscsi_portal_group *tpg = container_of(se_tpg, \
947 struct iscsi_portal_group, tpg_se_tpg); \
948 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
949 \
950 if (!capable(CAP_SYS_ADMIN)) \
951 return -EPERM; \
952 \
953 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
954} \
955 \
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200956static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
957 const char *page, size_t count) \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700958{ \
959 struct iscsi_portal_group *tpg = container_of(se_tpg, \
960 struct iscsi_portal_group, tpg_se_tpg); \
961 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
962 \
963 if (!capable(CAP_SYS_ADMIN)) \
964 return -EPERM; \
965 \
Nicholas Bellinger37b32c62013-07-06 16:48:55 -0700966 snprintf(auth->name, sizeof(auth->name), "%s", page); \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -0700967 if (!(strncmp("NULL", auth->name, 4))) \
968 auth->naf_flags &= ~flags; \
969 else \
970 auth->naf_flags |= flags; \
971 \
972 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
973 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
974 auth->authenticate_target = 1; \
975 else \
976 auth->authenticate_target = 0; \
977 \
978 return count; \
979}
980
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200981#define DEF_TPG_AUTH_STR(name, flags) \
982 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
983static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
984 char *page) \
985{ \
986 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
987} \
988 \
989static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \
990 const char *page, size_t count) \
991{ \
992 return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
993} \
994 \
995CONFIGFS_ATTR(iscsi_tpg_auth_, name);
996
997
998DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
999DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
1000DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1001DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1002
Nicholas Bellingerc3e51442013-06-19 18:48:51 -07001003#define __DEF_TPG_AUTH_INT(prefix, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001004static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
1005 char *page) \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -07001006{ \
1007 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1008 struct iscsi_portal_group, tpg_se_tpg); \
1009 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
1010 \
1011 if (!capable(CAP_SYS_ADMIN)) \
1012 return -EPERM; \
1013 \
1014 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
1015}
1016
Nicholas Bellingerc3e51442013-06-19 18:48:51 -07001017#define DEF_TPG_AUTH_INT(name) \
1018 __DEF_TPG_AUTH_INT(tpg_auth, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001019static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
1020 char *page) \
Nicholas Bellingerc3e51442013-06-19 18:48:51 -07001021{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001022 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
1023} \
1024CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
Nicholas Bellingerc3e51442013-06-19 18:48:51 -07001025
Nicholas Bellingerc3e51442013-06-19 18:48:51 -07001026DEF_TPG_AUTH_INT(authenticate_target);
Nicholas Bellingerc3e51442013-06-19 18:48:51 -07001027
1028static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001029 &iscsi_tpg_auth_attr_userid,
1030 &iscsi_tpg_auth_attr_password,
1031 &iscsi_tpg_auth_attr_authenticate_target,
1032 &iscsi_tpg_auth_attr_userid_mutual,
1033 &iscsi_tpg_auth_attr_password_mutual,
Nicholas Bellingerc3e51442013-06-19 18:48:51 -07001034 NULL,
1035};
1036
1037/* End items for lio_target_tpg_auth_cit */
1038
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001039/* Start items for lio_target_tpg_param_cit */
1040
1041#define DEF_TPG_PARAM(name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001042static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \
1043 char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001044{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001045 struct se_portal_group *se_tpg = param_to_tpg(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001046 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1047 struct iscsi_portal_group, tpg_se_tpg); \
1048 struct iscsi_param *param; \
1049 ssize_t rb; \
1050 \
1051 if (iscsit_get_tpg(tpg) < 0) \
1052 return -EINVAL; \
1053 \
1054 param = iscsi_find_param_from_key(__stringify(name), \
1055 tpg->param_list); \
1056 if (!param) { \
1057 iscsit_put_tpg(tpg); \
1058 return -EINVAL; \
1059 } \
1060 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
1061 \
1062 iscsit_put_tpg(tpg); \
1063 return rb; \
1064} \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001065static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
1066 const char *page, size_t count) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001067{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001068 struct se_portal_group *se_tpg = param_to_tpg(item); \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001069 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1070 struct iscsi_portal_group, tpg_se_tpg); \
1071 char *buf; \
Jörn Engelad7babd2013-07-03 11:35:11 -04001072 int ret, len; \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001073 \
1074 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
1075 if (!buf) \
1076 return -ENOMEM; \
Jörn Engelad7babd2013-07-03 11:35:11 -04001077 len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
1078 if (isspace(buf[len-1])) \
1079 buf[len-1] = '\0'; /* Kill newline */ \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001080 \
1081 if (iscsit_get_tpg(tpg) < 0) { \
1082 kfree(buf); \
1083 return -EINVAL; \
1084 } \
1085 \
1086 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
1087 if (ret < 0) \
1088 goto out; \
1089 \
1090 kfree(buf); \
1091 iscsit_put_tpg(tpg); \
1092 return count; \
1093out: \
1094 kfree(buf); \
1095 iscsit_put_tpg(tpg); \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001096 return -EINVAL; \
1097} \
1098CONFIGFS_ATTR(iscsi_tpg_param_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001099
1100DEF_TPG_PARAM(AuthMethod);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001101DEF_TPG_PARAM(HeaderDigest);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001102DEF_TPG_PARAM(DataDigest);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001103DEF_TPG_PARAM(MaxConnections);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001104DEF_TPG_PARAM(TargetAlias);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001105DEF_TPG_PARAM(InitialR2T);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001106DEF_TPG_PARAM(ImmediateData);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001107DEF_TPG_PARAM(MaxRecvDataSegmentLength);
Nicholas Bellingere004cb22012-09-29 21:47:16 -07001108DEF_TPG_PARAM(MaxXmitDataSegmentLength);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001109DEF_TPG_PARAM(MaxBurstLength);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001110DEF_TPG_PARAM(FirstBurstLength);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001111DEF_TPG_PARAM(DefaultTime2Wait);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001112DEF_TPG_PARAM(DefaultTime2Retain);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001113DEF_TPG_PARAM(MaxOutstandingR2T);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001114DEF_TPG_PARAM(DataPDUInOrder);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001115DEF_TPG_PARAM(DataSequenceInOrder);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001116DEF_TPG_PARAM(ErrorRecoveryLevel);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001117DEF_TPG_PARAM(IFMarker);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001118DEF_TPG_PARAM(OFMarker);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001119DEF_TPG_PARAM(IFMarkInt);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001120DEF_TPG_PARAM(OFMarkInt);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001121
1122static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001123 &iscsi_tpg_param_attr_AuthMethod,
1124 &iscsi_tpg_param_attr_HeaderDigest,
1125 &iscsi_tpg_param_attr_DataDigest,
1126 &iscsi_tpg_param_attr_MaxConnections,
1127 &iscsi_tpg_param_attr_TargetAlias,
1128 &iscsi_tpg_param_attr_InitialR2T,
1129 &iscsi_tpg_param_attr_ImmediateData,
1130 &iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
1131 &iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
1132 &iscsi_tpg_param_attr_MaxBurstLength,
1133 &iscsi_tpg_param_attr_FirstBurstLength,
1134 &iscsi_tpg_param_attr_DefaultTime2Wait,
1135 &iscsi_tpg_param_attr_DefaultTime2Retain,
1136 &iscsi_tpg_param_attr_MaxOutstandingR2T,
1137 &iscsi_tpg_param_attr_DataPDUInOrder,
1138 &iscsi_tpg_param_attr_DataSequenceInOrder,
1139 &iscsi_tpg_param_attr_ErrorRecoveryLevel,
1140 &iscsi_tpg_param_attr_IFMarker,
1141 &iscsi_tpg_param_attr_OFMarker,
1142 &iscsi_tpg_param_attr_IFMarkInt,
1143 &iscsi_tpg_param_attr_OFMarkInt,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001144 NULL,
1145};
1146
1147/* End items for lio_target_tpg_param_cit */
1148
1149/* Start items for lio_target_tpg_cit */
1150
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001151static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001152{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001153 struct se_portal_group *se_tpg = to_tpg(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001154 struct iscsi_portal_group *tpg = container_of(se_tpg,
1155 struct iscsi_portal_group, tpg_se_tpg);
1156 ssize_t len;
1157
1158 spin_lock(&tpg->tpg_state_lock);
1159 len = sprintf(page, "%d\n",
1160 (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1161 spin_unlock(&tpg->tpg_state_lock);
1162
1163 return len;
1164}
1165
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001166static ssize_t lio_target_tpg_enable_store(struct config_item *item,
1167 const char *page, size_t count)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001168{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001169 struct se_portal_group *se_tpg = to_tpg(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001170 struct iscsi_portal_group *tpg = container_of(se_tpg,
1171 struct iscsi_portal_group, tpg_se_tpg);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001172 u32 op;
Jörn Engelad7babd2013-07-03 11:35:11 -04001173 int ret;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001174
Jörn Engelad7babd2013-07-03 11:35:11 -04001175 ret = kstrtou32(page, 0, &op);
1176 if (ret)
1177 return ret;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001178 if ((op != 1) && (op != 0)) {
1179 pr_err("Illegal value for tpg_enable: %u\n", op);
1180 return -EINVAL;
1181 }
1182
1183 ret = iscsit_get_tpg(tpg);
1184 if (ret < 0)
1185 return -EINVAL;
1186
1187 if (op) {
1188 ret = iscsit_tpg_enable_portal_group(tpg);
1189 if (ret < 0)
1190 goto out;
1191 } else {
1192 /*
1193 * iscsit_tpg_disable_portal_group() assumes force=1
1194 */
1195 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1196 if (ret < 0)
1197 goto out;
1198 }
1199
1200 iscsit_put_tpg(tpg);
1201 return count;
1202out:
1203 iscsit_put_tpg(tpg);
1204 return -EINVAL;
1205}
1206
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001207
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001208static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
1209 char *page)
Nicholas Bellingerd4ee46f2015-03-06 20:40:57 -08001210{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001211 return target_show_dynamic_sessions(to_tpg(item), page);
Nicholas Bellingerd4ee46f2015-03-06 20:40:57 -08001212}
1213
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001214CONFIGFS_ATTR(lio_target_tpg_, enable);
1215CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
Nicholas Bellingerd4ee46f2015-03-06 20:40:57 -08001216
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001217static struct configfs_attribute *lio_target_tpg_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001218 &lio_target_tpg_attr_enable,
1219 &lio_target_tpg_attr_dynamic_sessions,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001220 NULL,
1221};
1222
1223/* End items for lio_target_tpg_cit */
1224
1225/* Start items for lio_target_tiqn_cit */
1226
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -04001227static struct se_portal_group *lio_target_tiqn_addtpg(
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001228 struct se_wwn *wwn,
1229 struct config_group *group,
1230 const char *name)
1231{
1232 struct iscsi_portal_group *tpg;
1233 struct iscsi_tiqn *tiqn;
Jörn Engelad7babd2013-07-03 11:35:11 -04001234 char *tpgt_str;
1235 int ret;
1236 u16 tpgt;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001237
1238 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1239 /*
1240 * Only tpgt_# directory groups can be created below
1241 * target/iscsi/iqn.superturodiskarry/
Jörn Engelad7babd2013-07-03 11:35:11 -04001242 */
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001243 tpgt_str = strstr(name, "tpgt_");
1244 if (!tpgt_str) {
1245 pr_err("Unable to locate \"tpgt_#\" directory"
1246 " group\n");
1247 return NULL;
1248 }
1249 tpgt_str += 5; /* Skip ahead of "tpgt_" */
Jörn Engelad7babd2013-07-03 11:35:11 -04001250 ret = kstrtou16(tpgt_str, 0, &tpgt);
1251 if (ret)
1252 return NULL;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001253
1254 tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1255 if (!tpg)
1256 return NULL;
1257
Nicholas Bellingerbc0c94b2015-05-20 21:48:03 -07001258 ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001259 if (ret < 0)
1260 return NULL;
1261
1262 ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1263 if (ret != 0)
1264 goto out;
1265
1266 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1267 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1268 name);
1269 return &tpg->tpg_se_tpg;
1270out:
1271 core_tpg_deregister(&tpg->tpg_se_tpg);
1272 kfree(tpg);
1273 return NULL;
1274}
1275
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -04001276static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001277{
1278 struct iscsi_portal_group *tpg;
1279 struct iscsi_tiqn *tiqn;
1280
1281 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1282 tiqn = tpg->tpg_tiqn;
1283 /*
1284 * iscsit_tpg_del_portal_group() assumes force=1
1285 */
1286 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1287 iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1288}
1289
1290/* End items for lio_target_tiqn_cit */
1291
1292/* Start LIO-Target TIQN struct contig_item lio_target_cit */
1293
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001294static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
1295 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001296{
Nicholas Bellinger4c762512013-09-05 15:29:12 -07001297 return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001298}
1299
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001300CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001301
1302static struct configfs_attribute *lio_target_wwn_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001303 &lio_target_wwn_attr_lio_version,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001304 NULL,
1305};
1306
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -04001307static struct se_wwn *lio_target_call_coreaddtiqn(
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001308 struct target_fabric_configfs *tf,
1309 struct config_group *group,
1310 const char *name)
1311{
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001312 struct iscsi_tiqn *tiqn;
1313
1314 tiqn = iscsit_add_tiqn((unsigned char *)name);
1315 if (IS_ERR(tiqn))
Thomas Meyere1750ba2011-08-01 23:58:18 +02001316 return ERR_CAST(tiqn);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001317
Christoph Hellwig839559e2016-03-29 13:03:35 +02001318 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1319 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1320 " %s\n", name);
1321 return &tiqn->tiqn_wwn;
1322}
1323
1324static void lio_target_add_wwn_groups(struct se_wwn *wwn)
1325{
1326 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1327
Andy Groverb7eec2c2013-10-09 11:05:57 -07001328 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001329 "iscsi_instance", &iscsi_stat_instance_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001330 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1331 &tiqn->tiqn_wwn.fabric_stat_group);
1332
Andy Groverb7eec2c2013-10-09 11:05:57 -07001333 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001334 "iscsi_sess_err", &iscsi_stat_sess_err_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001335 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1336 &tiqn->tiqn_wwn.fabric_stat_group);
1337
Andy Groverb7eec2c2013-10-09 11:05:57 -07001338 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001339 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001340 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1341 &tiqn->tiqn_wwn.fabric_stat_group);
1342
Andy Groverb7eec2c2013-10-09 11:05:57 -07001343 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001344 "iscsi_login_stats", &iscsi_stat_login_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001345 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1346 &tiqn->tiqn_wwn.fabric_stat_group);
1347
Andy Groverb7eec2c2013-10-09 11:05:57 -07001348 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001349 "iscsi_logout_stats", &iscsi_stat_logout_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001350 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1351 &tiqn->tiqn_wwn.fabric_stat_group);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001352}
1353
Christoph Hellwigfceb5bc2012-09-26 08:00:36 -04001354static void lio_target_call_coredeltiqn(
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001355 struct se_wwn *wwn)
1356{
1357 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001358
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001359 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1360 tiqn->tiqn);
1361 iscsit_del_tiqn(tiqn);
1362}
1363
1364/* End LIO-Target TIQN struct contig_lio_target_cit */
1365
1366/* Start lio_target_discovery_auth_cit */
1367
1368#define DEF_DISC_AUTH_STR(name, flags) \
1369 __DEF_NACL_AUTH_STR(disc, name, flags) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001370static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001371{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001372 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001373 page); \
1374} \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001375static ssize_t iscsi_disc_##name##_store(struct config_item *item, \
1376 const char *page, size_t count) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001377{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001378 return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001379 page, count); \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001380 \
1381} \
1382CONFIGFS_ATTR(iscsi_disc_, name)
1383
1384DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1385DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1386DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1387DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001388
1389#define DEF_DISC_AUTH_INT(name) \
1390 __DEF_NACL_AUTH_INT(disc, name) \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001391static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001392{ \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001393 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001394 page); \
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001395} \
1396CONFIGFS_ATTR_RO(iscsi_disc_, name)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001397
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001398DEF_DISC_AUTH_INT(authenticate_target);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001399
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001400
1401static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
1402 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001403{
1404 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1405
1406 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1407}
1408
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001409static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1410 const char *page, size_t count)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001411{
1412 struct iscsi_param *param;
1413 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001414 u32 op;
Jörn Engelad7babd2013-07-03 11:35:11 -04001415 int err;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001416
Jörn Engelad7babd2013-07-03 11:35:11 -04001417 err = kstrtou32(page, 0, &op);
1418 if (err)
1419 return -EINVAL;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001420 if ((op != 1) && (op != 0)) {
1421 pr_err("Illegal value for enforce_discovery_auth:"
1422 " %u\n", op);
1423 return -EINVAL;
1424 }
1425
1426 if (!discovery_tpg) {
1427 pr_err("iscsit_global->discovery_tpg is NULL\n");
1428 return -EINVAL;
1429 }
1430
1431 param = iscsi_find_param_from_key(AUTHMETHOD,
1432 discovery_tpg->param_list);
1433 if (!param)
1434 return -EINVAL;
1435
1436 if (op) {
1437 /*
1438 * Reset the AuthMethod key to CHAP.
1439 */
1440 if (iscsi_update_param_value(param, CHAP) < 0)
1441 return -EINVAL;
1442
1443 discovery_tpg->tpg_attrib.authentication = 1;
1444 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1445 pr_debug("LIO-CORE[0] Successfully enabled"
1446 " authentication enforcement for iSCSI"
1447 " Discovery TPG\n");
1448 } else {
1449 /*
1450 * Reset the AuthMethod key to CHAP,None
1451 */
1452 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1453 return -EINVAL;
1454
1455 discovery_tpg->tpg_attrib.authentication = 0;
1456 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1457 pr_debug("LIO-CORE[0] Successfully disabled"
1458 " authentication enforcement for iSCSI"
1459 " Discovery TPG\n");
1460 }
1461
1462 return count;
1463}
1464
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001465CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001466
1467static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001468 &iscsi_disc_attr_userid,
1469 &iscsi_disc_attr_password,
1470 &iscsi_disc_attr_authenticate_target,
1471 &iscsi_disc_attr_userid_mutual,
1472 &iscsi_disc_attr_password_mutual,
1473 &iscsi_disc_attr_enforce_discovery_auth,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001474 NULL,
1475};
1476
1477/* End lio_target_discovery_auth_cit */
1478
1479/* Start functions for target_core_fabric_ops */
1480
1481static char *iscsi_get_fabric_name(void)
1482{
1483 return "iSCSI";
1484}
1485
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001486static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1487{
1488 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1489
1490 return cmd->i_state;
1491}
1492
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001493static u32 lio_sess_get_index(struct se_session *se_sess)
1494{
1495 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1496
1497 return sess->session_index;
1498}
1499
1500static u32 lio_sess_get_initiator_sid(
1501 struct se_session *se_sess,
1502 unsigned char *buf,
1503 u32 size)
1504{
1505 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1506 /*
1507 * iSCSI Initiator Session Identifier from RFC-3720.
1508 */
Andy Shevchenko5cdf5a82015-01-15 13:40:56 +02001509 return snprintf(buf, size, "%6phN", sess->isid);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001510}
1511
1512static int lio_queue_data_in(struct se_cmd *se_cmd)
1513{
1514 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1515
1516 cmd->i_state = ISTATE_SEND_DATAIN;
Nicholas Bellinger2ec5a8c2013-03-20 15:29:15 -07001517 cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd);
1518
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001519 return 0;
1520}
1521
1522static int lio_write_pending(struct se_cmd *se_cmd)
1523{
1524 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
Nicholas Bellinger3e1c81a2013-03-06 22:18:24 -08001525 struct iscsi_conn *conn = cmd->conn;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001526
1527 if (!cmd->immediate_data && !cmd->unsolicited_data)
Nicholas Bellinger3e1c81a2013-03-06 22:18:24 -08001528 return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001529
1530 return 0;
1531}
1532
1533static int lio_write_pending_status(struct se_cmd *se_cmd)
1534{
1535 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1536 int ret;
1537
1538 spin_lock_bh(&cmd->istate_lock);
1539 ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1540 spin_unlock_bh(&cmd->istate_lock);
1541
1542 return ret;
1543}
1544
1545static int lio_queue_status(struct se_cmd *se_cmd)
1546{
1547 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1548
1549 cmd->i_state = ISTATE_SEND_STATUS;
Nicholas Bellinger5e8e6b42013-11-12 17:54:56 -08001550
1551 if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
1552 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1553 return 0;
1554 }
Nicholas Bellinger2ec5a8c2013-03-20 15:29:15 -07001555 cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd);
1556
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001557 return 0;
1558}
1559
Joern Engelb79fafa2013-07-03 11:22:17 -04001560static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001561{
1562 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1563
1564 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1565 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001566}
1567
Nicholas Bellinger131e6ab2014-03-22 14:55:56 -07001568static void lio_aborted_task(struct se_cmd *se_cmd)
1569{
1570 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1571
1572 cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1573}
1574
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001575static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg)
1576{
1577 return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1578}
1579
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001580static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1581{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001582 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001583}
1584
1585static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1586{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001587 return iscsi_tpg(se_tpg)->tpgt;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001588}
1589
1590static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1591{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001592 return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001593}
1594
1595static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1596{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001597 return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001598}
1599
1600static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1601{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001602 return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001603}
1604
1605static int lio_tpg_check_demo_mode_write_protect(
1606 struct se_portal_group *se_tpg)
1607{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001608 return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001609}
1610
1611static int lio_tpg_check_prod_mode_write_protect(
1612 struct se_portal_group *se_tpg)
1613{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001614 return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001615}
1616
Nicholas Bellinger901c04a2015-03-29 19:36:16 -07001617static int lio_tpg_check_prot_fabric_only(
1618 struct se_portal_group *se_tpg)
1619{
Nicholas Bellinger901c04a2015-03-29 19:36:16 -07001620 /*
1621 * Only report fabric_prot_type if t10_pi has also been enabled
1622 * for incoming ib_isert sessions.
1623 */
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001624 if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
Nicholas Bellinger901c04a2015-03-29 19:36:16 -07001625 return 0;
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001626 return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
Nicholas Bellinger901c04a2015-03-29 19:36:16 -07001627}
1628
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001629/*
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001630 * This function calls iscsit_inc_session_usage_count() on the
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001631 * struct iscsi_session in question.
1632 */
Christoph Hellwig44f33d02016-05-02 15:45:24 +02001633static void lio_tpg_close_session(struct se_session *se_sess)
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001634{
1635 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001636 struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
Nicholas Bellinger26a99c12016-01-19 16:15:27 -08001637
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001638 spin_lock_bh(&se_tpg->session_lock);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001639 spin_lock(&sess->conn_lock);
1640 if (atomic_read(&sess->session_fall_back_to_erl0) ||
1641 atomic_read(&sess->session_logout) ||
1642 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1643 spin_unlock(&sess->conn_lock);
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001644 spin_unlock_bh(&se_tpg->session_lock);
Christoph Hellwig44f33d02016-05-02 15:45:24 +02001645 return;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001646 }
1647 atomic_set(&sess->session_reinstatement, 1);
1648 spin_unlock(&sess->conn_lock);
1649
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001650 iscsit_stop_time2retain_timer(sess);
Nicholas Bellingerd36ad772016-01-07 22:15:06 -08001651 spin_unlock_bh(&se_tpg->session_lock);
Nicholas Bellinger26a99c12016-01-19 16:15:27 -08001652
Nicholas Bellinger99367f02012-02-27 01:43:32 -08001653 iscsit_stop_session(sess, 1, 1);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001654 iscsit_close_session(sess);
1655}
1656
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001657static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1658{
Christoph Hellwig2b6eb602015-05-01 17:47:53 +02001659 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001660}
1661
1662static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1663{
1664 struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1665 se_node_acl);
Nicholas Bellingerd1fa7a12013-11-20 11:57:18 -08001666 struct se_portal_group *se_tpg = se_acl->se_tpg;
1667 struct iscsi_portal_group *tpg = container_of(se_tpg,
1668 struct iscsi_portal_group, tpg_se_tpg);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001669
Andy Groverb7eec2c2013-10-09 11:05:57 -07001670 acl->node_attrib.nacl = acl;
Nicholas Bellingerd1fa7a12013-11-20 11:57:18 -08001671 iscsit_set_default_node_attribues(acl, tpg);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001672}
1673
Nicholas Bellinger3e1c81a2013-03-06 22:18:24 -08001674static int lio_check_stop_free(struct se_cmd *se_cmd)
1675{
Bart Van Asscheafc16602015-04-27 13:52:36 +02001676 return target_put_sess_cmd(se_cmd);
Nicholas Bellinger3e1c81a2013-03-06 22:18:24 -08001677}
1678
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001679static void lio_release_cmd(struct se_cmd *se_cmd)
1680{
1681 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1682
Nicholas Bellingercdb72662013-03-06 22:09:17 -08001683 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
Nicholas Bellingerd703ce22013-08-17 14:27:56 -07001684 iscsit_release_cmd(cmd);
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001685}
1686
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001687const struct target_core_fabric_ops iscsi_ops = {
1688 .module = THIS_MODULE,
1689 .name = "iscsi",
Christoph Hellwig144bc4c2015-04-13 19:51:16 +02001690 .node_acl_size = sizeof(struct iscsi_node_acl),
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001691 .get_fabric_name = iscsi_get_fabric_name,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001692 .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
1693 .tpg_get_tag = lio_tpg_get_tag,
1694 .tpg_get_default_depth = lio_tpg_get_default_depth,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001695 .tpg_check_demo_mode = lio_tpg_check_demo_mode,
1696 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
1697 .tpg_check_demo_mode_write_protect =
1698 lio_tpg_check_demo_mode_write_protect,
1699 .tpg_check_prod_mode_write_protect =
1700 lio_tpg_check_prod_mode_write_protect,
1701 .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001702 .tpg_get_inst_index = lio_tpg_get_inst_index,
1703 .check_stop_free = lio_check_stop_free,
1704 .release_cmd = lio_release_cmd,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001705 .close_session = lio_tpg_close_session,
1706 .sess_get_index = lio_sess_get_index,
1707 .sess_get_initiator_sid = lio_sess_get_initiator_sid,
1708 .write_pending = lio_write_pending,
1709 .write_pending_status = lio_write_pending_status,
1710 .set_default_node_attributes = lio_set_default_node_attributes,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001711 .get_cmd_state = iscsi_get_cmd_state,
1712 .queue_data_in = lio_queue_data_in,
1713 .queue_status = lio_queue_status,
1714 .queue_tm_rsp = lio_queue_tm_rsp,
1715 .aborted_task = lio_aborted_task,
1716 .fabric_make_wwn = lio_target_call_coreaddtiqn,
1717 .fabric_drop_wwn = lio_target_call_coredeltiqn,
Christoph Hellwig839559e2016-03-29 13:03:35 +02001718 .add_wwn_groups = lio_target_add_wwn_groups,
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001719 .fabric_make_tpg = lio_target_tiqn_addtpg,
1720 .fabric_drop_tpg = lio_target_tiqn_deltpg,
1721 .fabric_make_np = lio_target_call_addnptotpg,
1722 .fabric_drop_np = lio_target_call_delnpfromtpg,
Christoph Hellwigc7d6a802015-04-13 19:51:14 +02001723 .fabric_init_nodeacl = lio_target_init_nodeacl,
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001724
Christoph Hellwig9ac89282015-04-08 20:01:35 +02001725 .tfc_discovery_attrs = lio_target_discovery_auth_attrs,
1726 .tfc_wwn_attrs = lio_target_wwn_attrs,
1727 .tfc_tpg_base_attrs = lio_target_tpg_attrs,
1728 .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs,
1729 .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs,
1730 .tfc_tpg_param_attrs = lio_target_tpg_param_attrs,
1731 .tfc_tpg_np_base_attrs = lio_target_portal_attrs,
1732 .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs,
1733 .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs,
1734 .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs,
1735 .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs,
1736};