target: add a new add_wwn_groups fabrics method
[linux-2.6-block.git] / drivers / target / iscsi / iscsi_target_configfs.c
CommitLineData
e48354ce
NB
1/*******************************************************************************
2 * This file contains the configfs implementation for iSCSI Target mode
3 * from the LIO-Target Project.
4 *
4c76251e 5 * (c) Copyright 2007-2013 Datera, Inc.
e48354ce
NB
6 *
7 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 ****************************************************************************/
19
20#include <linux/configfs.h>
ad7babd2 21#include <linux/ctype.h>
c53181af 22#include <linux/export.h>
c3bc93da 23#include <linux/inet.h>
e48354ce 24#include <target/target_core_base.h>
c4795fb2 25#include <target/target_core_fabric.h>
2ec5a8c1 26#include <target/iscsi/iscsi_transport.h>
e48354ce 27
67f091f2 28#include <target/iscsi/iscsi_target_core.h>
e48354ce
NB
29#include "iscsi_target_parameters.h"
30#include "iscsi_target_device.h"
31#include "iscsi_target_erl0.h"
32#include "iscsi_target_nodeattrib.h"
33#include "iscsi_target_tpg.h"
34#include "iscsi_target_util.h"
35#include "iscsi_target.h"
67f091f2 36#include <target/iscsi/iscsi_target_stat.h>
e48354ce 37
e48354ce 38
e48354ce
NB
39/* Start items for lio_target_portal_cit */
40
2eafd729
CH
41static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item)
42{
43 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)
e48354ce 47{
2eafd729 48 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
e48354ce
NB
49 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
2eafd729
CH
61static ssize_t lio_target_np_sctp_store(struct config_item *item,
62 const char *page, size_t count)
e48354ce 63{
2eafd729 64 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
e48354ce
NB
65 struct iscsi_np *np;
66 struct iscsi_portal_group *tpg;
e48354ce 67 struct iscsi_tpg_np *tpg_np_sctp = NULL;
e48354ce
NB
68 u32 op;
69 int ret;
70
ad7babd2
JE
71 ret = kstrtou32(page, 0, &op);
72 if (ret)
73 return ret;
e48354ce
NB
74 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,
76c28f1f 94 tpg_np, ISCSI_SCTP_TCP);
e48354ce
NB
95 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
2eafd729 114static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
72438cdd 115{
2eafd729 116 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
72438cdd
NB
117 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
2eafd729
CH
129static ssize_t lio_target_np_iser_store(struct config_item *item,
130 const char *page, size_t count)
72438cdd 131{
2eafd729 132 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
72438cdd
NB
133 struct iscsi_np *np;
134 struct iscsi_portal_group *tpg;
72438cdd
NB
135 struct iscsi_tpg_np *tpg_np_iser = NULL;
136 char *endptr;
137 u32 op;
58bd0c69 138 int rc = 0;
72438cdd
NB
139
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) {
58bd0c69
AG
157 rc = request_module("ib_isert");
158 if (rc != 0) {
72438cdd 159 pr_warn("Unable to request_module for ib_isert\n");
58bd0c69
AG
160 rc = 0;
161 }
72438cdd
NB
162
163 tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
76c28f1f 164 tpg_np, ISCSI_INFINIBAND);
58bd0c69
AG
165 if (IS_ERR(tpg_np_iser)) {
166 rc = PTR_ERR(tpg_np_iser);
72438cdd 167 goto out;
58bd0c69 168 }
72438cdd
NB
169 } else {
170 tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
58bd0c69
AG
171 if (tpg_np_iser) {
172 rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser);
173 if (rc < 0)
174 goto out;
175 }
72438cdd
NB
176 }
177
72438cdd
NB
178 iscsit_put_tpg(tpg);
179 return count;
180out:
181 iscsit_put_tpg(tpg);
58bd0c69 182 return rc;
72438cdd
NB
183}
184
2eafd729
CH
185CONFIGFS_ATTR(lio_target_np_, sctp);
186CONFIGFS_ATTR(lio_target_np_, iser);
72438cdd 187
e48354ce 188static struct configfs_attribute *lio_target_portal_attrs[] = {
2eafd729
CH
189 &lio_target_np_attr_sctp,
190 &lio_target_np_attr_iser,
e48354ce
NB
191 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
fceb5bc7 200static struct se_tpg_np *lio_target_call_addnptotpg(
e48354ce
NB
201 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;
13a3cf08 208 struct sockaddr_storage sockaddr;
e48354ce
NB
209 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);
7bbb654e 221 snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
e48354ce 222
13a3cf08 223 memset(&sockaddr, 0, sizeof(struct sockaddr_storage));
e48354ce
NB
224
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 "[" */
76c28f1f
AG
236 *str2 = '\0'; /* Terminate the unbracketed IPv6 address */
237 str2++; /* Skip over the \0 */
e48354ce
NB
238 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
57103d7f 247 ret = kstrtoul(port_str, 0, &port);
e48354ce 248 if (ret < 0) {
57103d7f 249 pr_err("kstrtoul() failed for port_str: %d\n", ret);
e48354ce
NB
250 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);
dc58f760 255 ret = in6_pton(str, -1,
e48354ce
NB
256 (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
57103d7f 272 ret = kstrtoul(port_str, 0, &port);
e48354ce 273 if (ret < 0) {
57103d7f 274 pr_err("kstrtoul() failed for port_str: %d\n", ret);
e48354ce
NB
275 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 *
20879696 300 * can be enabled with attributes under
e48354ce
NB
301 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
302 *
303 */
76c28f1f 304 tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
e48354ce
NB
305 ISCSI_TCP);
306 if (IS_ERR(tpg_np)) {
307 iscsit_put_tpg(tpg);
e1750ba2 308 return ERR_CAST(tpg_np);
e48354ce
NB
309 }
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"
69d75574
AG
332 " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
333 tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
e48354ce
NB
334
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
2eafd729
CH
348#define ISCSI_NACL_ATTR(name) \
349static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
350 char *page) \
e48354ce 351{ \
2eafd729 352 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
e48354ce
NB
353 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
354 se_node_acl); \
355 \
b7eec2cd 356 return sprintf(page, "%u\n", nacl->node_attrib.name); \
e48354ce
NB
357} \
358 \
2eafd729
CH
359static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
360 const char *page, size_t count) \
e48354ce 361{ \
2eafd729 362 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
e48354ce
NB
363 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
364 se_node_acl); \
e48354ce
NB
365 u32 val; \
366 int ret; \
367 \
ad7babd2
JE
368 ret = kstrtou32(page, 0, &val); \
369 if (ret) \
370 return ret; \
e48354ce
NB
371 ret = iscsit_na_##name(nacl, val); \
372 if (ret < 0) \
373 return ret; \
374 \
375 return count; \
2eafd729
CH
376} \
377 \
378CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
e48354ce 379
2eafd729
CH
380ISCSI_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);
e48354ce
NB
388
389static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
2eafd729
CH
390 &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,
e48354ce
NB
398 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) \
2eafd729 406static ssize_t __iscsi_##prefix##_##name##_show( \
e48354ce
NB
407 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 \
2eafd729 417static ssize_t __iscsi_##prefix##_##name##_store( \
e48354ce
NB
418 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; \
2306bfb2
ES
426 if (count >= sizeof(auth->name)) \
427 return -EINVAL; \
0fbfc46f 428 snprintf(auth->name, sizeof(auth->name), "%s", page); \
e48354ce
NB
429 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
2eafd729
CH
443#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
e48354ce 470#define __DEF_NACL_AUTH_INT(prefix, name) \
2eafd729 471static ssize_t __iscsi_##prefix##_##name##_show( \
e48354ce
NB
472 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
e48354ce
NB
483#define DEF_NACL_AUTH_INT(name) \
484 __DEF_NACL_AUTH_INT(nacl_auth, name) \
2eafd729
CH
485static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
486 char *page) \
e48354ce 487{ \
2eafd729
CH
488 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)
e48354ce 494
e48354ce 495DEF_NACL_AUTH_INT(authenticate_target);
e48354ce
NB
496
497static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
2eafd729
CH
498 &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,
e48354ce
NB
503 NULL,
504};
505
506/* End items for lio_target_nacl_auth_cit */
507
508/* Start items for lio_target_nacl_param_cit */
509
2eafd729
CH
510#define ISCSI_NACL_PARAM(name) \
511static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \
512 char *page) \
e48354ce 513{ \
2eafd729 514 struct se_node_acl *se_nacl = param_to_nacl(item); \
e48354ce
NB
515 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; \
2eafd729
CH
532} \
533 \
534CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
535
536ISCSI_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);
e48354ce
NB
547
548static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
2eafd729
CH
549 &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,
e48354ce
NB
560 NULL,
561};
562
563/* End items for lio_target_nacl_param_cit */
564
565/* Start items for lio_target_acl_cit */
566
2eafd729 567static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
e48354ce 568{
2eafd729 569 struct se_node_acl *se_nacl = acl_to_nacl(item);
e48354ce
NB
570 struct iscsi_session *sess;
571 struct iscsi_conn *conn;
572 struct se_session *se_sess;
573 ssize_t rb = 0;
109e2381 574 u32 max_cmd_sn;
e48354ce
NB
575
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
cb354842
JE
584 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);
e48354ce 588
5cdf5a87
AS
589 rb += sprintf(page+rb,
590 "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ",
591 sess->sid, sess->isid, sess->tsih);
e48354ce
NB
592 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");
109e2381 622 max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
e48354ce
NB
623 rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
624 " 0x%08x 0x%08x\n",
625 sess->cmdsn_window,
109e2381
RD
626 (max_cmd_sn - sess->exp_cmd_sn) + 1,
627 sess->exp_cmd_sn, max_cmd_sn,
e48354ce
NB
628 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
dc58f760 671 rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr,
e48354ce
NB
672 (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
2eafd729
CH
684static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
685 char *page)
e48354ce 686{
2eafd729 687 return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth);
e48354ce
NB
688}
689
2eafd729
CH
690static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
691 const char *page, size_t count)
e48354ce 692{
2eafd729 693 struct se_node_acl *se_nacl = acl_to_nacl(item);
e48354ce
NB
694 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;
e48354ce
NB
698 u32 cmdsn_depth = 0;
699 int ret;
700
ad7babd2
JE
701 ret = kstrtou32(page, 0, &cmdsn_depth);
702 if (ret)
703 return ret;
e48354ce
NB
704 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;
d36ad77f
NB
728
729 ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth);
e48354ce
NB
730
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
2eafd729 740static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
79e62fc3 741{
2eafd729 742 return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
79e62fc3
AG
743}
744
2eafd729
CH
745static ssize_t lio_target_nacl_tag_store(struct config_item *item,
746 const char *page, size_t count)
79e62fc3 747{
2eafd729 748 struct se_node_acl *se_nacl = acl_to_nacl(item);
79e62fc3
AG
749 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
2eafd729
CH
758CONFIGFS_ATTR_RO(lio_target_nacl_, info);
759CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
760CONFIGFS_ATTR(lio_target_nacl_, tag);
79e62fc3 761
e48354ce 762static struct configfs_attribute *lio_target_initiator_attrs[] = {
2eafd729
CH
763 &lio_target_nacl_attr_info,
764 &lio_target_nacl_attr_cmdsn_depth,
765 &lio_target_nacl_attr_tag,
e48354ce
NB
766 NULL,
767};
768
c7d6a803
CH
769static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
770 const char *name)
e48354ce 771{
c7d6a803
CH
772 struct iscsi_node_acl *acl =
773 container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
e48354ce 774
b7eec2cd 775 config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
e48354ce 776 "iscsi_sess_stats", &iscsi_stat_sess_cit);
1ae1602d
CH
777 configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group,
778 &se_nacl->acl_fabric_stat_group);
c7d6a803 779 return 0;
e48354ce
NB
780}
781
e48354ce
NB
782/* End items for lio_target_acl_cit */
783
784/* Start items for lio_target_tpg_attrib_cit */
785
786#define DEF_TPG_ATTRIB(name) \
787 \
2eafd729
CH
788static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \
789 char *page) \
e48354ce 790{ \
2eafd729 791 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
e48354ce
NB
792 struct iscsi_portal_group *tpg = container_of(se_tpg, \
793 struct iscsi_portal_group, tpg_se_tpg); \
794 ssize_t rb; \
795 \
796 if (iscsit_get_tpg(tpg) < 0) \
797 return -EINVAL; \
798 \
b7eec2cd 799 rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \
e48354ce
NB
800 iscsit_put_tpg(tpg); \
801 return rb; \
802} \
803 \
2eafd729
CH
804static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
805 const char *page, size_t count) \
e48354ce 806{ \
2eafd729 807 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
e48354ce
NB
808 struct iscsi_portal_group *tpg = container_of(se_tpg, \
809 struct iscsi_portal_group, tpg_se_tpg); \
e48354ce
NB
810 u32 val; \
811 int ret; \
812 \
813 if (iscsit_get_tpg(tpg) < 0) \
814 return -EINVAL; \
815 \
ad7babd2
JE
816 ret = kstrtou32(page, 0, &val); \
817 if (ret) \
818 goto out; \
e48354ce
NB
819 ret = iscsit_ta_##name(tpg, val); \
820 if (ret < 0) \
821 goto out; \
822 \
823 iscsit_put_tpg(tpg); \
824 return count; \
825out: \
826 iscsit_put_tpg(tpg); \
827 return ret; \
2eafd729
CH
828} \
829CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
e48354ce 830
e48354ce 831DEF_TPG_ATTRIB(authentication);
e48354ce 832DEF_TPG_ATTRIB(login_timeout);
e48354ce 833DEF_TPG_ATTRIB(netif_timeout);
e48354ce 834DEF_TPG_ATTRIB(generate_node_acls);
e48354ce 835DEF_TPG_ATTRIB(default_cmdsn_depth);
e48354ce 836DEF_TPG_ATTRIB(cache_dynamic_acls);
e48354ce 837DEF_TPG_ATTRIB(demo_mode_write_protect);
e48354ce 838DEF_TPG_ATTRIB(prod_mode_write_protect);
4c54b6cf 839DEF_TPG_ATTRIB(demo_mode_discovery);
d1fa7a1d 840DEF_TPG_ATTRIB(default_erl);
8085176f 841DEF_TPG_ATTRIB(t10_pi);
901c04a3 842DEF_TPG_ATTRIB(fabric_prot_type);
a6415cdd 843DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
e48354ce
NB
844
845static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
2eafd729
CH
846 &iscsi_tpg_attrib_attr_authentication,
847 &iscsi_tpg_attrib_attr_login_timeout,
848 &iscsi_tpg_attrib_attr_netif_timeout,
849 &iscsi_tpg_attrib_attr_generate_node_acls,
850 &iscsi_tpg_attrib_attr_default_cmdsn_depth,
851 &iscsi_tpg_attrib_attr_cache_dynamic_acls,
852 &iscsi_tpg_attrib_attr_demo_mode_write_protect,
853 &iscsi_tpg_attrib_attr_prod_mode_write_protect,
854 &iscsi_tpg_attrib_attr_demo_mode_discovery,
855 &iscsi_tpg_attrib_attr_default_erl,
856 &iscsi_tpg_attrib_attr_t10_pi,
857 &iscsi_tpg_attrib_attr_fabric_prot_type,
858 &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
e48354ce
NB
859 NULL,
860};
861
862/* End items for lio_target_tpg_attrib_cit */
863
c3e51442
NB
864/* Start items for lio_target_tpg_auth_cit */
865
866#define __DEF_TPG_AUTH_STR(prefix, name, flags) \
2eafd729
CH
867static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
868 char *page) \
c3e51442
NB
869{ \
870 struct iscsi_portal_group *tpg = container_of(se_tpg, \
871 struct iscsi_portal_group, tpg_se_tpg); \
872 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
873 \
874 if (!capable(CAP_SYS_ADMIN)) \
875 return -EPERM; \
876 \
877 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
878} \
879 \
2eafd729
CH
880static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
881 const char *page, size_t count) \
c3e51442
NB
882{ \
883 struct iscsi_portal_group *tpg = container_of(se_tpg, \
884 struct iscsi_portal_group, tpg_se_tpg); \
885 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
886 \
887 if (!capable(CAP_SYS_ADMIN)) \
888 return -EPERM; \
889 \
37b32c6f 890 snprintf(auth->name, sizeof(auth->name), "%s", page); \
c3e51442
NB
891 if (!(strncmp("NULL", auth->name, 4))) \
892 auth->naf_flags &= ~flags; \
893 else \
894 auth->naf_flags |= flags; \
895 \
896 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
897 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
898 auth->authenticate_target = 1; \
899 else \
900 auth->authenticate_target = 0; \
901 \
902 return count; \
903}
904
2eafd729
CH
905#define DEF_TPG_AUTH_STR(name, flags) \
906 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
907static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
908 char *page) \
909{ \
910 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
911} \
912 \
913static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \
914 const char *page, size_t count) \
915{ \
916 return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
917} \
918 \
919CONFIGFS_ATTR(iscsi_tpg_auth_, name);
920
921
922DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
923DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
924DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
925DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
926
c3e51442 927#define __DEF_TPG_AUTH_INT(prefix, name) \
2eafd729
CH
928static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
929 char *page) \
c3e51442
NB
930{ \
931 struct iscsi_portal_group *tpg = container_of(se_tpg, \
932 struct iscsi_portal_group, tpg_se_tpg); \
933 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
934 \
935 if (!capable(CAP_SYS_ADMIN)) \
936 return -EPERM; \
937 \
938 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
939}
940
c3e51442
NB
941#define DEF_TPG_AUTH_INT(name) \
942 __DEF_TPG_AUTH_INT(tpg_auth, name) \
2eafd729
CH
943static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
944 char *page) \
c3e51442 945{ \
2eafd729
CH
946 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
947} \
948CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
c3e51442 949
c3e51442 950DEF_TPG_AUTH_INT(authenticate_target);
c3e51442
NB
951
952static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
2eafd729
CH
953 &iscsi_tpg_auth_attr_userid,
954 &iscsi_tpg_auth_attr_password,
955 &iscsi_tpg_auth_attr_authenticate_target,
956 &iscsi_tpg_auth_attr_userid_mutual,
957 &iscsi_tpg_auth_attr_password_mutual,
c3e51442
NB
958 NULL,
959};
960
961/* End items for lio_target_tpg_auth_cit */
962
e48354ce
NB
963/* Start items for lio_target_tpg_param_cit */
964
965#define DEF_TPG_PARAM(name) \
2eafd729
CH
966static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \
967 char *page) \
e48354ce 968{ \
2eafd729 969 struct se_portal_group *se_tpg = param_to_tpg(item); \
e48354ce
NB
970 struct iscsi_portal_group *tpg = container_of(se_tpg, \
971 struct iscsi_portal_group, tpg_se_tpg); \
972 struct iscsi_param *param; \
973 ssize_t rb; \
974 \
975 if (iscsit_get_tpg(tpg) < 0) \
976 return -EINVAL; \
977 \
978 param = iscsi_find_param_from_key(__stringify(name), \
979 tpg->param_list); \
980 if (!param) { \
981 iscsit_put_tpg(tpg); \
982 return -EINVAL; \
983 } \
984 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
985 \
986 iscsit_put_tpg(tpg); \
987 return rb; \
988} \
2eafd729
CH
989static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
990 const char *page, size_t count) \
e48354ce 991{ \
2eafd729 992 struct se_portal_group *se_tpg = param_to_tpg(item); \
e48354ce
NB
993 struct iscsi_portal_group *tpg = container_of(se_tpg, \
994 struct iscsi_portal_group, tpg_se_tpg); \
995 char *buf; \
ad7babd2 996 int ret, len; \
e48354ce
NB
997 \
998 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
999 if (!buf) \
1000 return -ENOMEM; \
ad7babd2
JE
1001 len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
1002 if (isspace(buf[len-1])) \
1003 buf[len-1] = '\0'; /* Kill newline */ \
e48354ce
NB
1004 \
1005 if (iscsit_get_tpg(tpg) < 0) { \
1006 kfree(buf); \
1007 return -EINVAL; \
1008 } \
1009 \
1010 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
1011 if (ret < 0) \
1012 goto out; \
1013 \
1014 kfree(buf); \
1015 iscsit_put_tpg(tpg); \
1016 return count; \
1017out: \
1018 kfree(buf); \
1019 iscsit_put_tpg(tpg); \
2eafd729
CH
1020 return -EINVAL; \
1021} \
1022CONFIGFS_ATTR(iscsi_tpg_param_, name)
e48354ce
NB
1023
1024DEF_TPG_PARAM(AuthMethod);
e48354ce 1025DEF_TPG_PARAM(HeaderDigest);
e48354ce 1026DEF_TPG_PARAM(DataDigest);
e48354ce 1027DEF_TPG_PARAM(MaxConnections);
e48354ce 1028DEF_TPG_PARAM(TargetAlias);
e48354ce 1029DEF_TPG_PARAM(InitialR2T);
e48354ce 1030DEF_TPG_PARAM(ImmediateData);
e48354ce 1031DEF_TPG_PARAM(MaxRecvDataSegmentLength);
e004cb25 1032DEF_TPG_PARAM(MaxXmitDataSegmentLength);
e48354ce 1033DEF_TPG_PARAM(MaxBurstLength);
e48354ce 1034DEF_TPG_PARAM(FirstBurstLength);
e48354ce 1035DEF_TPG_PARAM(DefaultTime2Wait);
e48354ce 1036DEF_TPG_PARAM(DefaultTime2Retain);
e48354ce 1037DEF_TPG_PARAM(MaxOutstandingR2T);
e48354ce 1038DEF_TPG_PARAM(DataPDUInOrder);
e48354ce 1039DEF_TPG_PARAM(DataSequenceInOrder);
e48354ce 1040DEF_TPG_PARAM(ErrorRecoveryLevel);
e48354ce 1041DEF_TPG_PARAM(IFMarker);
e48354ce 1042DEF_TPG_PARAM(OFMarker);
e48354ce 1043DEF_TPG_PARAM(IFMarkInt);
e48354ce 1044DEF_TPG_PARAM(OFMarkInt);
e48354ce
NB
1045
1046static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
2eafd729
CH
1047 &iscsi_tpg_param_attr_AuthMethod,
1048 &iscsi_tpg_param_attr_HeaderDigest,
1049 &iscsi_tpg_param_attr_DataDigest,
1050 &iscsi_tpg_param_attr_MaxConnections,
1051 &iscsi_tpg_param_attr_TargetAlias,
1052 &iscsi_tpg_param_attr_InitialR2T,
1053 &iscsi_tpg_param_attr_ImmediateData,
1054 &iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
1055 &iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
1056 &iscsi_tpg_param_attr_MaxBurstLength,
1057 &iscsi_tpg_param_attr_FirstBurstLength,
1058 &iscsi_tpg_param_attr_DefaultTime2Wait,
1059 &iscsi_tpg_param_attr_DefaultTime2Retain,
1060 &iscsi_tpg_param_attr_MaxOutstandingR2T,
1061 &iscsi_tpg_param_attr_DataPDUInOrder,
1062 &iscsi_tpg_param_attr_DataSequenceInOrder,
1063 &iscsi_tpg_param_attr_ErrorRecoveryLevel,
1064 &iscsi_tpg_param_attr_IFMarker,
1065 &iscsi_tpg_param_attr_OFMarker,
1066 &iscsi_tpg_param_attr_IFMarkInt,
1067 &iscsi_tpg_param_attr_OFMarkInt,
e48354ce
NB
1068 NULL,
1069};
1070
1071/* End items for lio_target_tpg_param_cit */
1072
1073/* Start items for lio_target_tpg_cit */
1074
2eafd729 1075static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page)
e48354ce 1076{
2eafd729 1077 struct se_portal_group *se_tpg = to_tpg(item);
e48354ce
NB
1078 struct iscsi_portal_group *tpg = container_of(se_tpg,
1079 struct iscsi_portal_group, tpg_se_tpg);
1080 ssize_t len;
1081
1082 spin_lock(&tpg->tpg_state_lock);
1083 len = sprintf(page, "%d\n",
1084 (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1085 spin_unlock(&tpg->tpg_state_lock);
1086
1087 return len;
1088}
1089
2eafd729
CH
1090static ssize_t lio_target_tpg_enable_store(struct config_item *item,
1091 const char *page, size_t count)
e48354ce 1092{
2eafd729 1093 struct se_portal_group *se_tpg = to_tpg(item);
e48354ce
NB
1094 struct iscsi_portal_group *tpg = container_of(se_tpg,
1095 struct iscsi_portal_group, tpg_se_tpg);
e48354ce 1096 u32 op;
ad7babd2 1097 int ret;
e48354ce 1098
ad7babd2
JE
1099 ret = kstrtou32(page, 0, &op);
1100 if (ret)
1101 return ret;
e48354ce
NB
1102 if ((op != 1) && (op != 0)) {
1103 pr_err("Illegal value for tpg_enable: %u\n", op);
1104 return -EINVAL;
1105 }
1106
1107 ret = iscsit_get_tpg(tpg);
1108 if (ret < 0)
1109 return -EINVAL;
1110
1111 if (op) {
1112 ret = iscsit_tpg_enable_portal_group(tpg);
1113 if (ret < 0)
1114 goto out;
1115 } else {
1116 /*
1117 * iscsit_tpg_disable_portal_group() assumes force=1
1118 */
1119 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1120 if (ret < 0)
1121 goto out;
1122 }
1123
1124 iscsit_put_tpg(tpg);
1125 return count;
1126out:
1127 iscsit_put_tpg(tpg);
1128 return -EINVAL;
1129}
1130
e48354ce 1131
2eafd729
CH
1132static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
1133 char *page)
d4ee46ff 1134{
2eafd729 1135 return target_show_dynamic_sessions(to_tpg(item), page);
d4ee46ff
NB
1136}
1137
2eafd729
CH
1138CONFIGFS_ATTR(lio_target_tpg_, enable);
1139CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
d4ee46ff 1140
e48354ce 1141static struct configfs_attribute *lio_target_tpg_attrs[] = {
2eafd729
CH
1142 &lio_target_tpg_attr_enable,
1143 &lio_target_tpg_attr_dynamic_sessions,
e48354ce
NB
1144 NULL,
1145};
1146
1147/* End items for lio_target_tpg_cit */
1148
1149/* Start items for lio_target_tiqn_cit */
1150
fceb5bc7 1151static struct se_portal_group *lio_target_tiqn_addtpg(
e48354ce
NB
1152 struct se_wwn *wwn,
1153 struct config_group *group,
1154 const char *name)
1155{
1156 struct iscsi_portal_group *tpg;
1157 struct iscsi_tiqn *tiqn;
ad7babd2
JE
1158 char *tpgt_str;
1159 int ret;
1160 u16 tpgt;
e48354ce
NB
1161
1162 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1163 /*
1164 * Only tpgt_# directory groups can be created below
1165 * target/iscsi/iqn.superturodiskarry/
ad7babd2 1166 */
e48354ce
NB
1167 tpgt_str = strstr(name, "tpgt_");
1168 if (!tpgt_str) {
1169 pr_err("Unable to locate \"tpgt_#\" directory"
1170 " group\n");
1171 return NULL;
1172 }
1173 tpgt_str += 5; /* Skip ahead of "tpgt_" */
ad7babd2
JE
1174 ret = kstrtou16(tpgt_str, 0, &tpgt);
1175 if (ret)
1176 return NULL;
e48354ce
NB
1177
1178 tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1179 if (!tpg)
1180 return NULL;
1181
bc0c94b1 1182 ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
e48354ce
NB
1183 if (ret < 0)
1184 return NULL;
1185
1186 ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1187 if (ret != 0)
1188 goto out;
1189
1190 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1191 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1192 name);
1193 return &tpg->tpg_se_tpg;
1194out:
1195 core_tpg_deregister(&tpg->tpg_se_tpg);
1196 kfree(tpg);
1197 return NULL;
1198}
1199
fceb5bc7 1200static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
e48354ce
NB
1201{
1202 struct iscsi_portal_group *tpg;
1203 struct iscsi_tiqn *tiqn;
1204
1205 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1206 tiqn = tpg->tpg_tiqn;
1207 /*
1208 * iscsit_tpg_del_portal_group() assumes force=1
1209 */
1210 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1211 iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1212}
1213
1214/* End items for lio_target_tiqn_cit */
1215
1216/* Start LIO-Target TIQN struct contig_item lio_target_cit */
1217
2eafd729
CH
1218static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
1219 char *page)
e48354ce 1220{
4c76251e 1221 return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
e48354ce
NB
1222}
1223
2eafd729 1224CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
e48354ce
NB
1225
1226static struct configfs_attribute *lio_target_wwn_attrs[] = {
2eafd729 1227 &lio_target_wwn_attr_lio_version,
e48354ce
NB
1228 NULL,
1229};
1230
fceb5bc7 1231static struct se_wwn *lio_target_call_coreaddtiqn(
e48354ce
NB
1232 struct target_fabric_configfs *tf,
1233 struct config_group *group,
1234 const char *name)
1235{
e48354ce
NB
1236 struct iscsi_tiqn *tiqn;
1237
1238 tiqn = iscsit_add_tiqn((unsigned char *)name);
1239 if (IS_ERR(tiqn))
e1750ba2 1240 return ERR_CAST(tiqn);
e48354ce 1241
839559e1
CH
1242 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1243 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1244 " %s\n", name);
1245 return &tiqn->tiqn_wwn;
1246}
1247
1248static void lio_target_add_wwn_groups(struct se_wwn *wwn)
1249{
1250 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1251
b7eec2cd 1252 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
e48354ce 1253 "iscsi_instance", &iscsi_stat_instance_cit);
1ae1602d
CH
1254 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1255 &tiqn->tiqn_wwn.fabric_stat_group);
1256
b7eec2cd 1257 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
e48354ce 1258 "iscsi_sess_err", &iscsi_stat_sess_err_cit);
1ae1602d
CH
1259 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1260 &tiqn->tiqn_wwn.fabric_stat_group);
1261
b7eec2cd 1262 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
e48354ce 1263 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1ae1602d
CH
1264 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1265 &tiqn->tiqn_wwn.fabric_stat_group);
1266
b7eec2cd 1267 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
e48354ce 1268 "iscsi_login_stats", &iscsi_stat_login_cit);
1ae1602d
CH
1269 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1270 &tiqn->tiqn_wwn.fabric_stat_group);
1271
b7eec2cd 1272 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
e48354ce 1273 "iscsi_logout_stats", &iscsi_stat_logout_cit);
1ae1602d
CH
1274 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1275 &tiqn->tiqn_wwn.fabric_stat_group);
e48354ce
NB
1276}
1277
fceb5bc7 1278static void lio_target_call_coredeltiqn(
e48354ce
NB
1279 struct se_wwn *wwn)
1280{
1281 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1ae1602d 1282
e48354ce
NB
1283 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1284 tiqn->tiqn);
1285 iscsit_del_tiqn(tiqn);
1286}
1287
1288/* End LIO-Target TIQN struct contig_lio_target_cit */
1289
1290/* Start lio_target_discovery_auth_cit */
1291
1292#define DEF_DISC_AUTH_STR(name, flags) \
1293 __DEF_NACL_AUTH_STR(disc, name, flags) \
2eafd729 1294static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
e48354ce 1295{ \
2eafd729 1296 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
e48354ce
NB
1297 page); \
1298} \
2eafd729
CH
1299static ssize_t iscsi_disc_##name##_store(struct config_item *item, \
1300 const char *page, size_t count) \
e48354ce 1301{ \
2eafd729 1302 return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \
e48354ce 1303 page, count); \
2eafd729
CH
1304 \
1305} \
1306CONFIGFS_ATTR(iscsi_disc_, name)
1307
1308DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1309DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1310DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1311DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
e48354ce
NB
1312
1313#define DEF_DISC_AUTH_INT(name) \
1314 __DEF_NACL_AUTH_INT(disc, name) \
2eafd729 1315static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
e48354ce 1316{ \
2eafd729 1317 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
e48354ce 1318 page); \
2eafd729
CH
1319} \
1320CONFIGFS_ATTR_RO(iscsi_disc_, name)
e48354ce 1321
e48354ce 1322DEF_DISC_AUTH_INT(authenticate_target);
e48354ce 1323
2eafd729
CH
1324
1325static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
1326 char *page)
e48354ce
NB
1327{
1328 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1329
1330 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1331}
1332
2eafd729
CH
1333static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1334 const char *page, size_t count)
e48354ce
NB
1335{
1336 struct iscsi_param *param;
1337 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
e48354ce 1338 u32 op;
ad7babd2 1339 int err;
e48354ce 1340
ad7babd2
JE
1341 err = kstrtou32(page, 0, &op);
1342 if (err)
1343 return -EINVAL;
e48354ce
NB
1344 if ((op != 1) && (op != 0)) {
1345 pr_err("Illegal value for enforce_discovery_auth:"
1346 " %u\n", op);
1347 return -EINVAL;
1348 }
1349
1350 if (!discovery_tpg) {
1351 pr_err("iscsit_global->discovery_tpg is NULL\n");
1352 return -EINVAL;
1353 }
1354
1355 param = iscsi_find_param_from_key(AUTHMETHOD,
1356 discovery_tpg->param_list);
1357 if (!param)
1358 return -EINVAL;
1359
1360 if (op) {
1361 /*
1362 * Reset the AuthMethod key to CHAP.
1363 */
1364 if (iscsi_update_param_value(param, CHAP) < 0)
1365 return -EINVAL;
1366
1367 discovery_tpg->tpg_attrib.authentication = 1;
1368 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1369 pr_debug("LIO-CORE[0] Successfully enabled"
1370 " authentication enforcement for iSCSI"
1371 " Discovery TPG\n");
1372 } else {
1373 /*
1374 * Reset the AuthMethod key to CHAP,None
1375 */
1376 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1377 return -EINVAL;
1378
1379 discovery_tpg->tpg_attrib.authentication = 0;
1380 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1381 pr_debug("LIO-CORE[0] Successfully disabled"
1382 " authentication enforcement for iSCSI"
1383 " Discovery TPG\n");
1384 }
1385
1386 return count;
1387}
1388
2eafd729 1389CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
e48354ce
NB
1390
1391static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
2eafd729
CH
1392 &iscsi_disc_attr_userid,
1393 &iscsi_disc_attr_password,
1394 &iscsi_disc_attr_authenticate_target,
1395 &iscsi_disc_attr_userid_mutual,
1396 &iscsi_disc_attr_password_mutual,
1397 &iscsi_disc_attr_enforce_discovery_auth,
e48354ce
NB
1398 NULL,
1399};
1400
1401/* End lio_target_discovery_auth_cit */
1402
1403/* Start functions for target_core_fabric_ops */
1404
1405static char *iscsi_get_fabric_name(void)
1406{
1407 return "iSCSI";
1408}
1409
e48354ce
NB
1410static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1411{
1412 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1413
1414 return cmd->i_state;
1415}
1416
e48354ce
NB
1417static u32 lio_sess_get_index(struct se_session *se_sess)
1418{
1419 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1420
1421 return sess->session_index;
1422}
1423
1424static u32 lio_sess_get_initiator_sid(
1425 struct se_session *se_sess,
1426 unsigned char *buf,
1427 u32 size)
1428{
1429 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1430 /*
1431 * iSCSI Initiator Session Identifier from RFC-3720.
1432 */
5cdf5a87 1433 return snprintf(buf, size, "%6phN", sess->isid);
e48354ce
NB
1434}
1435
1436static int lio_queue_data_in(struct se_cmd *se_cmd)
1437{
1438 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1439
1440 cmd->i_state = ISTATE_SEND_DATAIN;
2ec5a8c1
NB
1441 cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd);
1442
e48354ce
NB
1443 return 0;
1444}
1445
1446static int lio_write_pending(struct se_cmd *se_cmd)
1447{
1448 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
3e1c81a9 1449 struct iscsi_conn *conn = cmd->conn;
e48354ce
NB
1450
1451 if (!cmd->immediate_data && !cmd->unsolicited_data)
3e1c81a9 1452 return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
e48354ce
NB
1453
1454 return 0;
1455}
1456
1457static int lio_write_pending_status(struct se_cmd *se_cmd)
1458{
1459 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1460 int ret;
1461
1462 spin_lock_bh(&cmd->istate_lock);
1463 ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1464 spin_unlock_bh(&cmd->istate_lock);
1465
1466 return ret;
1467}
1468
1469static int lio_queue_status(struct se_cmd *se_cmd)
1470{
1471 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1472
1473 cmd->i_state = ISTATE_SEND_STATUS;
5e8e6b4b
NB
1474
1475 if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
1476 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1477 return 0;
1478 }
2ec5a8c1
NB
1479 cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd);
1480
e48354ce
NB
1481 return 0;
1482}
1483
b79fafac 1484static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
e48354ce
NB
1485{
1486 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1487
1488 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1489 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
e48354ce
NB
1490}
1491
131e6abc
NB
1492static void lio_aborted_task(struct se_cmd *se_cmd)
1493{
1494 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1495
1496 cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1497}
1498
2b6eb609 1499static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg)
e48354ce 1500{
2b6eb609
CH
1501 return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1502}
e48354ce 1503
2b6eb609
CH
1504static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1505{
1506 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
e48354ce
NB
1507}
1508
1509static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1510{
2b6eb609 1511 return iscsi_tpg(se_tpg)->tpgt;
e48354ce
NB
1512}
1513
1514static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1515{
2b6eb609 1516 return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
e48354ce
NB
1517}
1518
1519static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1520{
2b6eb609 1521 return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
e48354ce
NB
1522}
1523
1524static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1525{
2b6eb609 1526 return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
e48354ce
NB
1527}
1528
1529static int lio_tpg_check_demo_mode_write_protect(
1530 struct se_portal_group *se_tpg)
1531{
2b6eb609 1532 return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
e48354ce
NB
1533}
1534
1535static int lio_tpg_check_prod_mode_write_protect(
1536 struct se_portal_group *se_tpg)
1537{
2b6eb609 1538 return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
e48354ce
NB
1539}
1540
901c04a3
NB
1541static int lio_tpg_check_prot_fabric_only(
1542 struct se_portal_group *se_tpg)
1543{
901c04a3
NB
1544 /*
1545 * Only report fabric_prot_type if t10_pi has also been enabled
1546 * for incoming ib_isert sessions.
1547 */
2b6eb609 1548 if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
901c04a3 1549 return 0;
2b6eb609 1550 return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
901c04a3
NB
1551}
1552
e48354ce 1553/*
d36ad77f 1554 * This function calls iscsit_inc_session_usage_count() on the
e48354ce
NB
1555 * struct iscsi_session in question.
1556 */
1557static int lio_tpg_shutdown_session(struct se_session *se_sess)
1558{
1559 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
d36ad77f 1560 struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
e48354ce 1561
d36ad77f 1562 spin_lock_bh(&se_tpg->session_lock);
e48354ce
NB
1563 spin_lock(&sess->conn_lock);
1564 if (atomic_read(&sess->session_fall_back_to_erl0) ||
1565 atomic_read(&sess->session_logout) ||
1566 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1567 spin_unlock(&sess->conn_lock);
d36ad77f 1568 spin_unlock_bh(&se_tpg->session_lock);
e48354ce
NB
1569 return 0;
1570 }
1571 atomic_set(&sess->session_reinstatement, 1);
1572 spin_unlock(&sess->conn_lock);
1573
e48354ce 1574 iscsit_stop_time2retain_timer(sess);
d36ad77f 1575 spin_unlock_bh(&se_tpg->session_lock);
26a99c19 1576
99367f01 1577 iscsit_stop_session(sess, 1, 1);
e48354ce
NB
1578 return 1;
1579}
1580
1581/*
1582 * Calls iscsit_dec_session_usage_count() as inverse of
1583 * lio_tpg_shutdown_session()
1584 */
1585static void lio_tpg_close_session(struct se_session *se_sess)
1586{
1587 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1588 /*
1589 * If the iSCSI Session for the iSCSI Initiator Node exists,
1590 * forcefully shutdown the iSCSI NEXUS.
1591 */
e48354ce
NB
1592 iscsit_close_session(sess);
1593}
1594
e48354ce
NB
1595static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1596{
2b6eb609 1597 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
e48354ce
NB
1598}
1599
1600static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1601{
1602 struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1603 se_node_acl);
d1fa7a1d
NB
1604 struct se_portal_group *se_tpg = se_acl->se_tpg;
1605 struct iscsi_portal_group *tpg = container_of(se_tpg,
1606 struct iscsi_portal_group, tpg_se_tpg);
e48354ce 1607
b7eec2cd 1608 acl->node_attrib.nacl = acl;
d1fa7a1d 1609 iscsit_set_default_node_attribues(acl, tpg);
e48354ce
NB
1610}
1611
3e1c81a9
NB
1612static int lio_check_stop_free(struct se_cmd *se_cmd)
1613{
afc16604 1614 return target_put_sess_cmd(se_cmd);
3e1c81a9
NB
1615}
1616
e48354ce
NB
1617static void lio_release_cmd(struct se_cmd *se_cmd)
1618{
1619 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1620
cdb72665 1621 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
d703ce2f 1622 iscsit_release_cmd(cmd);
e48354ce
NB
1623}
1624
9ac8928e
CH
1625const struct target_core_fabric_ops iscsi_ops = {
1626 .module = THIS_MODULE,
1627 .name = "iscsi",
144bc4c2 1628 .node_acl_size = sizeof(struct iscsi_node_acl),
9ac8928e 1629 .get_fabric_name = iscsi_get_fabric_name,
9ac8928e
CH
1630 .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
1631 .tpg_get_tag = lio_tpg_get_tag,
1632 .tpg_get_default_depth = lio_tpg_get_default_depth,
9ac8928e
CH
1633 .tpg_check_demo_mode = lio_tpg_check_demo_mode,
1634 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
1635 .tpg_check_demo_mode_write_protect =
1636 lio_tpg_check_demo_mode_write_protect,
1637 .tpg_check_prod_mode_write_protect =
1638 lio_tpg_check_prod_mode_write_protect,
1639 .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only,
9ac8928e
CH
1640 .tpg_get_inst_index = lio_tpg_get_inst_index,
1641 .check_stop_free = lio_check_stop_free,
1642 .release_cmd = lio_release_cmd,
1643 .shutdown_session = lio_tpg_shutdown_session,
1644 .close_session = lio_tpg_close_session,
1645 .sess_get_index = lio_sess_get_index,
1646 .sess_get_initiator_sid = lio_sess_get_initiator_sid,
1647 .write_pending = lio_write_pending,
1648 .write_pending_status = lio_write_pending_status,
1649 .set_default_node_attributes = lio_set_default_node_attributes,
9ac8928e
CH
1650 .get_cmd_state = iscsi_get_cmd_state,
1651 .queue_data_in = lio_queue_data_in,
1652 .queue_status = lio_queue_status,
1653 .queue_tm_rsp = lio_queue_tm_rsp,
1654 .aborted_task = lio_aborted_task,
1655 .fabric_make_wwn = lio_target_call_coreaddtiqn,
1656 .fabric_drop_wwn = lio_target_call_coredeltiqn,
839559e1 1657 .add_wwn_groups = lio_target_add_wwn_groups,
9ac8928e
CH
1658 .fabric_make_tpg = lio_target_tiqn_addtpg,
1659 .fabric_drop_tpg = lio_target_tiqn_deltpg,
1660 .fabric_make_np = lio_target_call_addnptotpg,
1661 .fabric_drop_np = lio_target_call_delnpfromtpg,
c7d6a803 1662 .fabric_init_nodeacl = lio_target_init_nodeacl,
9ac8928e
CH
1663
1664 .tfc_discovery_attrs = lio_target_discovery_auth_attrs,
1665 .tfc_wwn_attrs = lio_target_wwn_attrs,
1666 .tfc_tpg_base_attrs = lio_target_tpg_attrs,
1667 .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs,
1668 .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs,
1669 .tfc_tpg_param_attrs = lio_target_tpg_param_attrs,
1670 .tfc_tpg_np_base_attrs = lio_target_portal_attrs,
1671 .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs,
1672 .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs,
1673 .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs,
1674 .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs,
1675};