1 /*******************************************************************************
2 * This file contains the configfs implementation for iSCSI Target mode
3 * from the LIO-Target Project.
5 * \u00a9 Copyright 2007-2011 RisingTide Systems LLC.
7 * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
9 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 ****************************************************************************/
22 #include <linux/configfs.h>
23 #include <linux/export.h>
24 #include <linux/inet.h>
25 #include <target/target_core_base.h>
26 #include <target/target_core_fabric.h>
27 #include <target/target_core_fabric_configfs.h>
28 #include <target/target_core_configfs.h>
29 #include <target/configfs_macros.h>
31 #include "iscsi_target_core.h"
32 #include "iscsi_target_parameters.h"
33 #include "iscsi_target_device.h"
34 #include "iscsi_target_erl0.h"
35 #include "iscsi_target_nodeattrib.h"
36 #include "iscsi_target_tpg.h"
37 #include "iscsi_target_util.h"
38 #include "iscsi_target.h"
39 #include "iscsi_target_stat.h"
40 #include "iscsi_target_configfs.h"
42 struct target_fabric_configfs
*lio_target_fabric_configfs
;
44 struct lio_target_configfs_attribute
{
45 struct configfs_attribute attr
;
46 ssize_t (*show
)(void *, char *);
47 ssize_t (*store
)(void *, const char *, size_t);
50 /* Start items for lio_target_portal_cit */
52 static ssize_t
lio_target_np_show_sctp(
53 struct se_tpg_np
*se_tpg_np
,
56 struct iscsi_tpg_np
*tpg_np
= container_of(se_tpg_np
,
57 struct iscsi_tpg_np
, se_tpg_np
);
58 struct iscsi_tpg_np
*tpg_np_sctp
;
61 tpg_np_sctp
= iscsit_tpg_locate_child_np(tpg_np
, ISCSI_SCTP_TCP
);
63 rb
= sprintf(page
, "1\n");
65 rb
= sprintf(page
, "0\n");
70 static ssize_t
lio_target_np_store_sctp(
71 struct se_tpg_np
*se_tpg_np
,
76 struct iscsi_portal_group
*tpg
;
77 struct iscsi_tpg_np
*tpg_np
= container_of(se_tpg_np
,
78 struct iscsi_tpg_np
, se_tpg_np
);
79 struct iscsi_tpg_np
*tpg_np_sctp
= NULL
;
84 op
= simple_strtoul(page
, &endptr
, 0);
85 if ((op
!= 1) && (op
!= 0)) {
86 pr_err("Illegal value for tpg_enable: %u\n", op
);
91 pr_err("Unable to locate struct iscsi_np from"
92 " struct iscsi_tpg_np\n");
97 if (iscsit_get_tpg(tpg
) < 0)
102 * Use existing np->np_sockaddr for SCTP network portal reference
104 tpg_np_sctp
= iscsit_tpg_add_network_portal(tpg
, &np
->np_sockaddr
,
105 np
->np_ip
, tpg_np
, ISCSI_SCTP_TCP
);
106 if (!tpg_np_sctp
|| IS_ERR(tpg_np_sctp
))
109 tpg_np_sctp
= iscsit_tpg_locate_child_np(tpg_np
, ISCSI_SCTP_TCP
);
113 ret
= iscsit_tpg_del_network_portal(tpg
, tpg_np_sctp
);
125 TF_NP_BASE_ATTR(lio_target
, sctp
, S_IRUGO
| S_IWUSR
);
127 static struct configfs_attribute
*lio_target_portal_attrs
[] = {
128 &lio_target_np_sctp
.attr
,
132 /* Stop items for lio_target_portal_cit */
134 /* Start items for lio_target_np_cit */
136 #define MAX_PORTAL_LEN 256
138 static struct se_tpg_np
*lio_target_call_addnptotpg(
139 struct se_portal_group
*se_tpg
,
140 struct config_group
*group
,
143 struct iscsi_portal_group
*tpg
;
144 struct iscsi_tpg_np
*tpg_np
;
145 char *str
, *str2
, *ip_str
, *port_str
;
146 struct __kernel_sockaddr_storage sockaddr
;
147 struct sockaddr_in
*sock_in
;
148 struct sockaddr_in6
*sock_in6
;
151 char buf
[MAX_PORTAL_LEN
+ 1];
153 if (strlen(name
) > MAX_PORTAL_LEN
) {
154 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
155 (int)strlen(name
), MAX_PORTAL_LEN
);
156 return ERR_PTR(-EOVERFLOW
);
158 memset(buf
, 0, MAX_PORTAL_LEN
+ 1);
159 snprintf(buf
, MAX_PORTAL_LEN
+ 1, "%s", name
);
161 memset(&sockaddr
, 0, sizeof(struct __kernel_sockaddr_storage
));
163 str
= strstr(buf
, "[");
167 str2
= strstr(str
, "]");
169 pr_err("Unable to locate trailing \"]\""
170 " in IPv6 iSCSI network portal address\n");
171 return ERR_PTR(-EINVAL
);
173 str
++; /* Skip over leading "[" */
174 *str2
= '\0'; /* Terminate the IPv6 address */
175 str2
++; /* Skip over the "]" */
176 port_str
= strstr(str2
, ":");
178 pr_err("Unable to locate \":port\""
179 " in IPv6 iSCSI network portal address\n");
180 return ERR_PTR(-EINVAL
);
182 *port_str
= '\0'; /* Terminate string for IP */
183 port_str
++; /* Skip over ":" */
185 ret
= strict_strtoul(port_str
, 0, &port
);
187 pr_err("strict_strtoul() failed for port_str: %d\n", ret
);
190 sock_in6
= (struct sockaddr_in6
*)&sockaddr
;
191 sock_in6
->sin6_family
= AF_INET6
;
192 sock_in6
->sin6_port
= htons((unsigned short)port
);
193 ret
= in6_pton(str
, IPV6_ADDRESS_SPACE
,
194 (void *)&sock_in6
->sin6_addr
.in6_u
, -1, &end
);
196 pr_err("in6_pton returned: %d\n", ret
);
197 return ERR_PTR(-EINVAL
);
200 str
= ip_str
= &buf
[0];
201 port_str
= strstr(ip_str
, ":");
203 pr_err("Unable to locate \":port\""
204 " in IPv4 iSCSI network portal address\n");
205 return ERR_PTR(-EINVAL
);
207 *port_str
= '\0'; /* Terminate string for IP */
208 port_str
++; /* Skip over ":" */
210 ret
= strict_strtoul(port_str
, 0, &port
);
212 pr_err("strict_strtoul() failed for port_str: %d\n", ret
);
215 sock_in
= (struct sockaddr_in
*)&sockaddr
;
216 sock_in
->sin_family
= AF_INET
;
217 sock_in
->sin_port
= htons((unsigned short)port
);
218 sock_in
->sin_addr
.s_addr
= in_aton(ip_str
);
220 tpg
= container_of(se_tpg
, struct iscsi_portal_group
, tpg_se_tpg
);
221 ret
= iscsit_get_tpg(tpg
);
223 return ERR_PTR(-EINVAL
);
225 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
227 config_item_name(&se_tpg
->se_tpg_wwn
->wwn_group
.cg_item
),
230 * Assume ISCSI_TCP by default. Other network portals for other
233 * Traditional iSCSI over SCTP (initial support)
234 * iSER/TCP (TODO, hardware available)
235 * iSER/SCTP (TODO, software emulation with osc-iwarp)
236 * iSER/IB (TODO, hardware available)
238 * can be enabled with attributes under
239 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
242 tpg_np
= iscsit_tpg_add_network_portal(tpg
, &sockaddr
, str
, NULL
,
244 if (IS_ERR(tpg_np
)) {
246 return ERR_CAST(tpg_np
);
248 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
251 return &tpg_np
->se_tpg_np
;
254 static void lio_target_call_delnpfromtpg(
255 struct se_tpg_np
*se_tpg_np
)
257 struct iscsi_portal_group
*tpg
;
258 struct iscsi_tpg_np
*tpg_np
;
259 struct se_portal_group
*se_tpg
;
262 tpg_np
= container_of(se_tpg_np
, struct iscsi_tpg_np
, se_tpg_np
);
264 ret
= iscsit_get_tpg(tpg
);
268 se_tpg
= &tpg
->tpg_se_tpg
;
269 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
270 " PORTAL: %s:%hu\n", config_item_name(&se_tpg
->se_tpg_wwn
->wwn_group
.cg_item
),
271 tpg
->tpgt
, tpg_np
->tpg_np
->np_ip
, tpg_np
->tpg_np
->np_port
);
273 ret
= iscsit_tpg_del_network_portal(tpg
, tpg_np
);
277 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
282 /* End items for lio_target_np_cit */
284 /* Start items for lio_target_nacl_attrib_cit */
286 #define DEF_NACL_ATTRIB(name) \
287 static ssize_t iscsi_nacl_attrib_show_##name( \
288 struct se_node_acl *se_nacl, \
291 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
294 return sprintf(page, "%u\n", ISCSI_NODE_ATTRIB(nacl)->name); \
297 static ssize_t iscsi_nacl_attrib_store_##name( \
298 struct se_node_acl *se_nacl, \
302 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
308 val = simple_strtoul(page, &endptr, 0); \
309 ret = iscsit_na_##name(nacl, val); \
316 #define NACL_ATTR(_name, _mode) TF_NACL_ATTRIB_ATTR(iscsi, _name, _mode);
318 * Define iscsi_node_attrib_s_dataout_timeout
320 DEF_NACL_ATTRIB(dataout_timeout
);
321 NACL_ATTR(dataout_timeout
, S_IRUGO
| S_IWUSR
);
323 * Define iscsi_node_attrib_s_dataout_timeout_retries
325 DEF_NACL_ATTRIB(dataout_timeout_retries
);
326 NACL_ATTR(dataout_timeout_retries
, S_IRUGO
| S_IWUSR
);
328 * Define iscsi_node_attrib_s_default_erl
330 DEF_NACL_ATTRIB(default_erl
);
331 NACL_ATTR(default_erl
, S_IRUGO
| S_IWUSR
);
333 * Define iscsi_node_attrib_s_nopin_timeout
335 DEF_NACL_ATTRIB(nopin_timeout
);
336 NACL_ATTR(nopin_timeout
, S_IRUGO
| S_IWUSR
);
338 * Define iscsi_node_attrib_s_nopin_response_timeout
340 DEF_NACL_ATTRIB(nopin_response_timeout
);
341 NACL_ATTR(nopin_response_timeout
, S_IRUGO
| S_IWUSR
);
343 * Define iscsi_node_attrib_s_random_datain_pdu_offsets
345 DEF_NACL_ATTRIB(random_datain_pdu_offsets
);
346 NACL_ATTR(random_datain_pdu_offsets
, S_IRUGO
| S_IWUSR
);
348 * Define iscsi_node_attrib_s_random_datain_seq_offsets
350 DEF_NACL_ATTRIB(random_datain_seq_offsets
);
351 NACL_ATTR(random_datain_seq_offsets
, S_IRUGO
| S_IWUSR
);
353 * Define iscsi_node_attrib_s_random_r2t_offsets
355 DEF_NACL_ATTRIB(random_r2t_offsets
);
356 NACL_ATTR(random_r2t_offsets
, S_IRUGO
| S_IWUSR
);
358 static struct configfs_attribute
*lio_target_nacl_attrib_attrs
[] = {
359 &iscsi_nacl_attrib_dataout_timeout
.attr
,
360 &iscsi_nacl_attrib_dataout_timeout_retries
.attr
,
361 &iscsi_nacl_attrib_default_erl
.attr
,
362 &iscsi_nacl_attrib_nopin_timeout
.attr
,
363 &iscsi_nacl_attrib_nopin_response_timeout
.attr
,
364 &iscsi_nacl_attrib_random_datain_pdu_offsets
.attr
,
365 &iscsi_nacl_attrib_random_datain_seq_offsets
.attr
,
366 &iscsi_nacl_attrib_random_r2t_offsets
.attr
,
370 /* End items for lio_target_nacl_attrib_cit */
372 /* Start items for lio_target_nacl_auth_cit */
374 #define __DEF_NACL_AUTH_STR(prefix, name, flags) \
375 static ssize_t __iscsi_##prefix##_show_##name( \
376 struct iscsi_node_acl *nacl, \
379 struct iscsi_node_auth *auth = &nacl->node_auth; \
381 if (!capable(CAP_SYS_ADMIN)) \
383 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
386 static ssize_t __iscsi_##prefix##_store_##name( \
387 struct iscsi_node_acl *nacl, \
391 struct iscsi_node_auth *auth = &nacl->node_auth; \
393 if (!capable(CAP_SYS_ADMIN)) \
396 snprintf(auth->name, PAGE_SIZE, "%s", page); \
397 if (!strncmp("NULL", auth->name, 4)) \
398 auth->naf_flags &= ~flags; \
400 auth->naf_flags |= flags; \
402 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
403 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
404 auth->authenticate_target = 1; \
406 auth->authenticate_target = 0; \
411 #define __DEF_NACL_AUTH_INT(prefix, name) \
412 static ssize_t __iscsi_##prefix##_show_##name( \
413 struct iscsi_node_acl *nacl, \
416 struct iscsi_node_auth *auth = &nacl->node_auth; \
418 if (!capable(CAP_SYS_ADMIN)) \
421 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
424 #define DEF_NACL_AUTH_STR(name, flags) \
425 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
426 static ssize_t iscsi_nacl_auth_show_##name( \
427 struct se_node_acl *nacl, \
430 return __iscsi_nacl_auth_show_##name(container_of(nacl, \
431 struct iscsi_node_acl, se_node_acl), page); \
433 static ssize_t iscsi_nacl_auth_store_##name( \
434 struct se_node_acl *nacl, \
438 return __iscsi_nacl_auth_store_##name(container_of(nacl, \
439 struct iscsi_node_acl, se_node_acl), page, count); \
442 #define DEF_NACL_AUTH_INT(name) \
443 __DEF_NACL_AUTH_INT(nacl_auth, name) \
444 static ssize_t iscsi_nacl_auth_show_##name( \
445 struct se_node_acl *nacl, \
448 return __iscsi_nacl_auth_show_##name(container_of(nacl, \
449 struct iscsi_node_acl, se_node_acl), page); \
452 #define AUTH_ATTR(_name, _mode) TF_NACL_AUTH_ATTR(iscsi, _name, _mode);
453 #define AUTH_ATTR_RO(_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name);
456 * One-way authentication userid
458 DEF_NACL_AUTH_STR(userid
, NAF_USERID_SET
);
459 AUTH_ATTR(userid
, S_IRUGO
| S_IWUSR
);
461 * One-way authentication password
463 DEF_NACL_AUTH_STR(password
, NAF_PASSWORD_SET
);
464 AUTH_ATTR(password
, S_IRUGO
| S_IWUSR
);
466 * Enforce mutual authentication
468 DEF_NACL_AUTH_INT(authenticate_target
);
469 AUTH_ATTR_RO(authenticate_target
);
471 * Mutual authentication userid
473 DEF_NACL_AUTH_STR(userid_mutual
, NAF_USERID_IN_SET
);
474 AUTH_ATTR(userid_mutual
, S_IRUGO
| S_IWUSR
);
476 * Mutual authentication password
478 DEF_NACL_AUTH_STR(password_mutual
, NAF_PASSWORD_IN_SET
);
479 AUTH_ATTR(password_mutual
, S_IRUGO
| S_IWUSR
);
481 static struct configfs_attribute
*lio_target_nacl_auth_attrs
[] = {
482 &iscsi_nacl_auth_userid
.attr
,
483 &iscsi_nacl_auth_password
.attr
,
484 &iscsi_nacl_auth_authenticate_target
.attr
,
485 &iscsi_nacl_auth_userid_mutual
.attr
,
486 &iscsi_nacl_auth_password_mutual
.attr
,
490 /* End items for lio_target_nacl_auth_cit */
492 /* Start items for lio_target_nacl_param_cit */
494 #define DEF_NACL_PARAM(name) \
495 static ssize_t iscsi_nacl_param_show_##name( \
496 struct se_node_acl *se_nacl, \
499 struct iscsi_session *sess; \
500 struct se_session *se_sess; \
503 spin_lock_bh(&se_nacl->nacl_sess_lock); \
504 se_sess = se_nacl->nacl_sess; \
506 rb = snprintf(page, PAGE_SIZE, \
507 "No Active iSCSI Session\n"); \
509 sess = se_sess->fabric_sess_ptr; \
510 rb = snprintf(page, PAGE_SIZE, "%u\n", \
511 (u32)sess->sess_ops->name); \
513 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
518 #define NACL_PARAM_ATTR(_name) TF_NACL_PARAM_ATTR_RO(iscsi, _name);
520 DEF_NACL_PARAM(MaxConnections
);
521 NACL_PARAM_ATTR(MaxConnections
);
523 DEF_NACL_PARAM(InitialR2T
);
524 NACL_PARAM_ATTR(InitialR2T
);
526 DEF_NACL_PARAM(ImmediateData
);
527 NACL_PARAM_ATTR(ImmediateData
);
529 DEF_NACL_PARAM(MaxBurstLength
);
530 NACL_PARAM_ATTR(MaxBurstLength
);
532 DEF_NACL_PARAM(FirstBurstLength
);
533 NACL_PARAM_ATTR(FirstBurstLength
);
535 DEF_NACL_PARAM(DefaultTime2Wait
);
536 NACL_PARAM_ATTR(DefaultTime2Wait
);
538 DEF_NACL_PARAM(DefaultTime2Retain
);
539 NACL_PARAM_ATTR(DefaultTime2Retain
);
541 DEF_NACL_PARAM(MaxOutstandingR2T
);
542 NACL_PARAM_ATTR(MaxOutstandingR2T
);
544 DEF_NACL_PARAM(DataPDUInOrder
);
545 NACL_PARAM_ATTR(DataPDUInOrder
);
547 DEF_NACL_PARAM(DataSequenceInOrder
);
548 NACL_PARAM_ATTR(DataSequenceInOrder
);
550 DEF_NACL_PARAM(ErrorRecoveryLevel
);
551 NACL_PARAM_ATTR(ErrorRecoveryLevel
);
553 static struct configfs_attribute
*lio_target_nacl_param_attrs
[] = {
554 &iscsi_nacl_param_MaxConnections
.attr
,
555 &iscsi_nacl_param_InitialR2T
.attr
,
556 &iscsi_nacl_param_ImmediateData
.attr
,
557 &iscsi_nacl_param_MaxBurstLength
.attr
,
558 &iscsi_nacl_param_FirstBurstLength
.attr
,
559 &iscsi_nacl_param_DefaultTime2Wait
.attr
,
560 &iscsi_nacl_param_DefaultTime2Retain
.attr
,
561 &iscsi_nacl_param_MaxOutstandingR2T
.attr
,
562 &iscsi_nacl_param_DataPDUInOrder
.attr
,
563 &iscsi_nacl_param_DataSequenceInOrder
.attr
,
564 &iscsi_nacl_param_ErrorRecoveryLevel
.attr
,
568 /* End items for lio_target_nacl_param_cit */
570 /* Start items for lio_target_acl_cit */
572 static ssize_t
lio_target_nacl_show_info(
573 struct se_node_acl
*se_nacl
,
576 struct iscsi_session
*sess
;
577 struct iscsi_conn
*conn
;
578 struct se_session
*se_sess
;
581 spin_lock_bh(&se_nacl
->nacl_sess_lock
);
582 se_sess
= se_nacl
->nacl_sess
;
584 rb
+= sprintf(page
+rb
, "No active iSCSI Session for Initiator"
585 " Endpoint: %s\n", se_nacl
->initiatorname
);
587 sess
= se_sess
->fabric_sess_ptr
;
589 if (sess
->sess_ops
->InitiatorName
)
590 rb
+= sprintf(page
+rb
, "InitiatorName: %s\n",
591 sess
->sess_ops
->InitiatorName
);
592 if (sess
->sess_ops
->InitiatorAlias
)
593 rb
+= sprintf(page
+rb
, "InitiatorAlias: %s\n",
594 sess
->sess_ops
->InitiatorAlias
);
596 rb
+= sprintf(page
+rb
, "LIO Session ID: %u "
597 "ISID: 0x%02x %02x %02x %02x %02x %02x "
598 "TSIH: %hu ", sess
->sid
,
599 sess
->isid
[0], sess
->isid
[1], sess
->isid
[2],
600 sess
->isid
[3], sess
->isid
[4], sess
->isid
[5],
602 rb
+= sprintf(page
+rb
, "SessionType: %s\n",
603 (sess
->sess_ops
->SessionType
) ?
604 "Discovery" : "Normal");
605 rb
+= sprintf(page
+rb
, "Session State: ");
606 switch (sess
->session_state
) {
607 case TARG_SESS_STATE_FREE
:
608 rb
+= sprintf(page
+rb
, "TARG_SESS_FREE\n");
610 case TARG_SESS_STATE_ACTIVE
:
611 rb
+= sprintf(page
+rb
, "TARG_SESS_STATE_ACTIVE\n");
613 case TARG_SESS_STATE_LOGGED_IN
:
614 rb
+= sprintf(page
+rb
, "TARG_SESS_STATE_LOGGED_IN\n");
616 case TARG_SESS_STATE_FAILED
:
617 rb
+= sprintf(page
+rb
, "TARG_SESS_STATE_FAILED\n");
619 case TARG_SESS_STATE_IN_CONTINUE
:
620 rb
+= sprintf(page
+rb
, "TARG_SESS_STATE_IN_CONTINUE\n");
623 rb
+= sprintf(page
+rb
, "ERROR: Unknown Session"
628 rb
+= sprintf(page
+rb
, "---------------------[iSCSI Session"
629 " Values]-----------------------\n");
630 rb
+= sprintf(page
+rb
, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
631 " : MaxCmdSN : ITT : TTT\n");
632 rb
+= sprintf(page
+rb
, " 0x%08x 0x%08x 0x%08x 0x%08x"
635 (sess
->max_cmd_sn
- sess
->exp_cmd_sn
) + 1,
636 sess
->exp_cmd_sn
, sess
->max_cmd_sn
,
637 sess
->init_task_tag
, sess
->targ_xfer_tag
);
638 rb
+= sprintf(page
+rb
, "----------------------[iSCSI"
639 " Connections]-------------------------\n");
641 spin_lock(&sess
->conn_lock
);
642 list_for_each_entry(conn
, &sess
->sess_conn_list
, conn_list
) {
643 rb
+= sprintf(page
+rb
, "CID: %hu Connection"
644 " State: ", conn
->cid
);
645 switch (conn
->conn_state
) {
646 case TARG_CONN_STATE_FREE
:
647 rb
+= sprintf(page
+rb
,
648 "TARG_CONN_STATE_FREE\n");
650 case TARG_CONN_STATE_XPT_UP
:
651 rb
+= sprintf(page
+rb
,
652 "TARG_CONN_STATE_XPT_UP\n");
654 case TARG_CONN_STATE_IN_LOGIN
:
655 rb
+= sprintf(page
+rb
,
656 "TARG_CONN_STATE_IN_LOGIN\n");
658 case TARG_CONN_STATE_LOGGED_IN
:
659 rb
+= sprintf(page
+rb
,
660 "TARG_CONN_STATE_LOGGED_IN\n");
662 case TARG_CONN_STATE_IN_LOGOUT
:
663 rb
+= sprintf(page
+rb
,
664 "TARG_CONN_STATE_IN_LOGOUT\n");
666 case TARG_CONN_STATE_LOGOUT_REQUESTED
:
667 rb
+= sprintf(page
+rb
,
668 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
670 case TARG_CONN_STATE_CLEANUP_WAIT
:
671 rb
+= sprintf(page
+rb
,
672 "TARG_CONN_STATE_CLEANUP_WAIT\n");
675 rb
+= sprintf(page
+rb
,
676 "ERROR: Unknown Connection State!\n");
680 rb
+= sprintf(page
+rb
, " Address %s %s", conn
->login_ip
,
681 (conn
->network_transport
== ISCSI_TCP
) ?
683 rb
+= sprintf(page
+rb
, " StatSN: 0x%08x\n",
686 spin_unlock(&sess
->conn_lock
);
688 spin_unlock_bh(&se_nacl
->nacl_sess_lock
);
693 TF_NACL_BASE_ATTR_RO(lio_target
, info
);
695 static ssize_t
lio_target_nacl_show_cmdsn_depth(
696 struct se_node_acl
*se_nacl
,
699 return sprintf(page
, "%u\n", se_nacl
->queue_depth
);
702 static ssize_t
lio_target_nacl_store_cmdsn_depth(
703 struct se_node_acl
*se_nacl
,
707 struct se_portal_group
*se_tpg
= se_nacl
->se_tpg
;
708 struct iscsi_portal_group
*tpg
= container_of(se_tpg
,
709 struct iscsi_portal_group
, tpg_se_tpg
);
710 struct config_item
*acl_ci
, *tpg_ci
, *wwn_ci
;
715 cmdsn_depth
= simple_strtoul(page
, &endptr
, 0);
716 if (cmdsn_depth
> TA_DEFAULT_CMDSN_DEPTH_MAX
) {
717 pr_err("Passed cmdsn_depth: %u exceeds"
718 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth
,
719 TA_DEFAULT_CMDSN_DEPTH_MAX
);
722 acl_ci
= &se_nacl
->acl_group
.cg_item
;
724 pr_err("Unable to locatel acl_ci\n");
727 tpg_ci
= &acl_ci
->ci_parent
->ci_group
->cg_item
;
729 pr_err("Unable to locate tpg_ci\n");
732 wwn_ci
= &tpg_ci
->ci_group
->cg_item
;
734 pr_err("Unable to locate config_item wwn_ci\n");
738 if (iscsit_get_tpg(tpg
) < 0)
741 * iscsit_tpg_set_initiator_node_queue_depth() assumes force=1
743 ret
= iscsit_tpg_set_initiator_node_queue_depth(tpg
,
744 config_item_name(acl_ci
), cmdsn_depth
, 1);
746 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
747 "InitiatorName: %s\n", config_item_name(wwn_ci
),
748 config_item_name(tpg_ci
), cmdsn_depth
,
749 config_item_name(acl_ci
));
752 return (!ret
) ? count
: (ssize_t
)ret
;
755 TF_NACL_BASE_ATTR(lio_target
, cmdsn_depth
, S_IRUGO
| S_IWUSR
);
757 static ssize_t
lio_target_nacl_show_tag(
758 struct se_node_acl
*se_nacl
,
761 return snprintf(page
, PAGE_SIZE
, "%s", se_nacl
->acl_tag
);
764 static ssize_t
lio_target_nacl_store_tag(
765 struct se_node_acl
*se_nacl
,
771 ret
= core_tpg_set_initiator_node_tag(se_nacl
->se_tpg
, se_nacl
, page
);
778 TF_NACL_BASE_ATTR(lio_target
, tag
, S_IRUGO
| S_IWUSR
);
780 static struct configfs_attribute
*lio_target_initiator_attrs
[] = {
781 &lio_target_nacl_info
.attr
,
782 &lio_target_nacl_cmdsn_depth
.attr
,
783 &lio_target_nacl_tag
.attr
,
787 static struct se_node_acl
*lio_tpg_alloc_fabric_acl(
788 struct se_portal_group
*se_tpg
)
790 struct iscsi_node_acl
*acl
;
792 acl
= kzalloc(sizeof(struct iscsi_node_acl
), GFP_KERNEL
);
794 pr_err("Unable to allocate memory for struct iscsi_node_acl\n");
798 return &acl
->se_node_acl
;
801 static struct se_node_acl
*lio_target_make_nodeacl(
802 struct se_portal_group
*se_tpg
,
803 struct config_group
*group
,
806 struct config_group
*stats_cg
;
807 struct iscsi_node_acl
*acl
;
808 struct se_node_acl
*se_nacl_new
, *se_nacl
;
809 struct iscsi_portal_group
*tpg
= container_of(se_tpg
,
810 struct iscsi_portal_group
, tpg_se_tpg
);
813 se_nacl_new
= lio_tpg_alloc_fabric_acl(se_tpg
);
815 return ERR_PTR(-ENOMEM
);
817 cmdsn_depth
= ISCSI_TPG_ATTRIB(tpg
)->default_cmdsn_depth
;
819 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
820 * when converting a NdoeACL from demo mode -> explict
822 se_nacl
= core_tpg_add_initiator_node_acl(se_tpg
, se_nacl_new
,
827 acl
= container_of(se_nacl
, struct iscsi_node_acl
, se_node_acl
);
828 stats_cg
= &se_nacl
->acl_fabric_stat_group
;
830 stats_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 2,
832 if (!stats_cg
->default_groups
) {
833 pr_err("Unable to allocate memory for"
834 " stats_cg->default_groups\n");
835 core_tpg_del_initiator_node_acl(se_tpg
, se_nacl
, 1);
837 return ERR_PTR(-ENOMEM
);
840 stats_cg
->default_groups
[0] = &NODE_STAT_GRPS(acl
)->iscsi_sess_stats_group
;
841 stats_cg
->default_groups
[1] = NULL
;
842 config_group_init_type_name(&NODE_STAT_GRPS(acl
)->iscsi_sess_stats_group
,
843 "iscsi_sess_stats", &iscsi_stat_sess_cit
);
848 static void lio_target_drop_nodeacl(
849 struct se_node_acl
*se_nacl
)
851 struct se_portal_group
*se_tpg
= se_nacl
->se_tpg
;
852 struct iscsi_node_acl
*acl
= container_of(se_nacl
,
853 struct iscsi_node_acl
, se_node_acl
);
854 struct config_item
*df_item
;
855 struct config_group
*stats_cg
;
858 stats_cg
= &acl
->se_node_acl
.acl_fabric_stat_group
;
859 for (i
= 0; stats_cg
->default_groups
[i
]; i
++) {
860 df_item
= &stats_cg
->default_groups
[i
]->cg_item
;
861 stats_cg
->default_groups
[i
] = NULL
;
862 config_item_put(df_item
);
864 kfree(stats_cg
->default_groups
);
866 core_tpg_del_initiator_node_acl(se_tpg
, se_nacl
, 1);
870 /* End items for lio_target_acl_cit */
872 /* Start items for lio_target_tpg_attrib_cit */
874 #define DEF_TPG_ATTRIB(name) \
876 static ssize_t iscsi_tpg_attrib_show_##name( \
877 struct se_portal_group *se_tpg, \
880 struct iscsi_portal_group *tpg = container_of(se_tpg, \
881 struct iscsi_portal_group, tpg_se_tpg); \
884 if (iscsit_get_tpg(tpg) < 0) \
887 rb = sprintf(page, "%u\n", ISCSI_TPG_ATTRIB(tpg)->name); \
888 iscsit_put_tpg(tpg); \
892 static ssize_t iscsi_tpg_attrib_store_##name( \
893 struct se_portal_group *se_tpg, \
897 struct iscsi_portal_group *tpg = container_of(se_tpg, \
898 struct iscsi_portal_group, tpg_se_tpg); \
903 if (iscsit_get_tpg(tpg) < 0) \
906 val = simple_strtoul(page, &endptr, 0); \
907 ret = iscsit_ta_##name(tpg, val); \
911 iscsit_put_tpg(tpg); \
914 iscsit_put_tpg(tpg); \
918 #define TPG_ATTR(_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode);
921 * Define iscsi_tpg_attrib_s_authentication
923 DEF_TPG_ATTRIB(authentication
);
924 TPG_ATTR(authentication
, S_IRUGO
| S_IWUSR
);
926 * Define iscsi_tpg_attrib_s_login_timeout
928 DEF_TPG_ATTRIB(login_timeout
);
929 TPG_ATTR(login_timeout
, S_IRUGO
| S_IWUSR
);
931 * Define iscsi_tpg_attrib_s_netif_timeout
933 DEF_TPG_ATTRIB(netif_timeout
);
934 TPG_ATTR(netif_timeout
, S_IRUGO
| S_IWUSR
);
936 * Define iscsi_tpg_attrib_s_generate_node_acls
938 DEF_TPG_ATTRIB(generate_node_acls
);
939 TPG_ATTR(generate_node_acls
, S_IRUGO
| S_IWUSR
);
941 * Define iscsi_tpg_attrib_s_default_cmdsn_depth
943 DEF_TPG_ATTRIB(default_cmdsn_depth
);
944 TPG_ATTR(default_cmdsn_depth
, S_IRUGO
| S_IWUSR
);
946 Define iscsi_tpg_attrib_s_cache_dynamic_acls
948 DEF_TPG_ATTRIB(cache_dynamic_acls
);
949 TPG_ATTR(cache_dynamic_acls
, S_IRUGO
| S_IWUSR
);
951 * Define iscsi_tpg_attrib_s_demo_mode_write_protect
953 DEF_TPG_ATTRIB(demo_mode_write_protect
);
954 TPG_ATTR(demo_mode_write_protect
, S_IRUGO
| S_IWUSR
);
956 * Define iscsi_tpg_attrib_s_prod_mode_write_protect
958 DEF_TPG_ATTRIB(prod_mode_write_protect
);
959 TPG_ATTR(prod_mode_write_protect
, S_IRUGO
| S_IWUSR
);
961 static struct configfs_attribute
*lio_target_tpg_attrib_attrs
[] = {
962 &iscsi_tpg_attrib_authentication
.attr
,
963 &iscsi_tpg_attrib_login_timeout
.attr
,
964 &iscsi_tpg_attrib_netif_timeout
.attr
,
965 &iscsi_tpg_attrib_generate_node_acls
.attr
,
966 &iscsi_tpg_attrib_default_cmdsn_depth
.attr
,
967 &iscsi_tpg_attrib_cache_dynamic_acls
.attr
,
968 &iscsi_tpg_attrib_demo_mode_write_protect
.attr
,
969 &iscsi_tpg_attrib_prod_mode_write_protect
.attr
,
973 /* End items for lio_target_tpg_attrib_cit */
975 /* Start items for lio_target_tpg_param_cit */
977 #define DEF_TPG_PARAM(name) \
978 static ssize_t iscsi_tpg_param_show_##name( \
979 struct se_portal_group *se_tpg, \
982 struct iscsi_portal_group *tpg = container_of(se_tpg, \
983 struct iscsi_portal_group, tpg_se_tpg); \
984 struct iscsi_param *param; \
987 if (iscsit_get_tpg(tpg) < 0) \
990 param = iscsi_find_param_from_key(__stringify(name), \
993 iscsit_put_tpg(tpg); \
996 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
998 iscsit_put_tpg(tpg); \
1001 static ssize_t iscsi_tpg_param_store_##name( \
1002 struct se_portal_group *se_tpg, \
1006 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1007 struct iscsi_portal_group, tpg_se_tpg); \
1011 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
1014 snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
1015 buf[strlen(buf)-1] = '\0'; /* Kill newline */ \
1017 if (iscsit_get_tpg(tpg) < 0) { \
1022 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
1027 iscsit_put_tpg(tpg); \
1031 iscsit_put_tpg(tpg); \
1035 #define TPG_PARAM_ATTR(_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode);
1037 DEF_TPG_PARAM(AuthMethod
);
1038 TPG_PARAM_ATTR(AuthMethod
, S_IRUGO
| S_IWUSR
);
1040 DEF_TPG_PARAM(HeaderDigest
);
1041 TPG_PARAM_ATTR(HeaderDigest
, S_IRUGO
| S_IWUSR
);
1043 DEF_TPG_PARAM(DataDigest
);
1044 TPG_PARAM_ATTR(DataDigest
, S_IRUGO
| S_IWUSR
);
1046 DEF_TPG_PARAM(MaxConnections
);
1047 TPG_PARAM_ATTR(MaxConnections
, S_IRUGO
| S_IWUSR
);
1049 DEF_TPG_PARAM(TargetAlias
);
1050 TPG_PARAM_ATTR(TargetAlias
, S_IRUGO
| S_IWUSR
);
1052 DEF_TPG_PARAM(InitialR2T
);
1053 TPG_PARAM_ATTR(InitialR2T
, S_IRUGO
| S_IWUSR
);
1055 DEF_TPG_PARAM(ImmediateData
);
1056 TPG_PARAM_ATTR(ImmediateData
, S_IRUGO
| S_IWUSR
);
1058 DEF_TPG_PARAM(MaxRecvDataSegmentLength
);
1059 TPG_PARAM_ATTR(MaxRecvDataSegmentLength
, S_IRUGO
| S_IWUSR
);
1061 DEF_TPG_PARAM(MaxXmitDataSegmentLength
);
1062 TPG_PARAM_ATTR(MaxXmitDataSegmentLength
, S_IRUGO
| S_IWUSR
);
1064 DEF_TPG_PARAM(MaxBurstLength
);
1065 TPG_PARAM_ATTR(MaxBurstLength
, S_IRUGO
| S_IWUSR
);
1067 DEF_TPG_PARAM(FirstBurstLength
);
1068 TPG_PARAM_ATTR(FirstBurstLength
, S_IRUGO
| S_IWUSR
);
1070 DEF_TPG_PARAM(DefaultTime2Wait
);
1071 TPG_PARAM_ATTR(DefaultTime2Wait
, S_IRUGO
| S_IWUSR
);
1073 DEF_TPG_PARAM(DefaultTime2Retain
);
1074 TPG_PARAM_ATTR(DefaultTime2Retain
, S_IRUGO
| S_IWUSR
);
1076 DEF_TPG_PARAM(MaxOutstandingR2T
);
1077 TPG_PARAM_ATTR(MaxOutstandingR2T
, S_IRUGO
| S_IWUSR
);
1079 DEF_TPG_PARAM(DataPDUInOrder
);
1080 TPG_PARAM_ATTR(DataPDUInOrder
, S_IRUGO
| S_IWUSR
);
1082 DEF_TPG_PARAM(DataSequenceInOrder
);
1083 TPG_PARAM_ATTR(DataSequenceInOrder
, S_IRUGO
| S_IWUSR
);
1085 DEF_TPG_PARAM(ErrorRecoveryLevel
);
1086 TPG_PARAM_ATTR(ErrorRecoveryLevel
, S_IRUGO
| S_IWUSR
);
1088 DEF_TPG_PARAM(IFMarker
);
1089 TPG_PARAM_ATTR(IFMarker
, S_IRUGO
| S_IWUSR
);
1091 DEF_TPG_PARAM(OFMarker
);
1092 TPG_PARAM_ATTR(OFMarker
, S_IRUGO
| S_IWUSR
);
1094 DEF_TPG_PARAM(IFMarkInt
);
1095 TPG_PARAM_ATTR(IFMarkInt
, S_IRUGO
| S_IWUSR
);
1097 DEF_TPG_PARAM(OFMarkInt
);
1098 TPG_PARAM_ATTR(OFMarkInt
, S_IRUGO
| S_IWUSR
);
1100 static struct configfs_attribute
*lio_target_tpg_param_attrs
[] = {
1101 &iscsi_tpg_param_AuthMethod
.attr
,
1102 &iscsi_tpg_param_HeaderDigest
.attr
,
1103 &iscsi_tpg_param_DataDigest
.attr
,
1104 &iscsi_tpg_param_MaxConnections
.attr
,
1105 &iscsi_tpg_param_TargetAlias
.attr
,
1106 &iscsi_tpg_param_InitialR2T
.attr
,
1107 &iscsi_tpg_param_ImmediateData
.attr
,
1108 &iscsi_tpg_param_MaxRecvDataSegmentLength
.attr
,
1109 &iscsi_tpg_param_MaxXmitDataSegmentLength
.attr
,
1110 &iscsi_tpg_param_MaxBurstLength
.attr
,
1111 &iscsi_tpg_param_FirstBurstLength
.attr
,
1112 &iscsi_tpg_param_DefaultTime2Wait
.attr
,
1113 &iscsi_tpg_param_DefaultTime2Retain
.attr
,
1114 &iscsi_tpg_param_MaxOutstandingR2T
.attr
,
1115 &iscsi_tpg_param_DataPDUInOrder
.attr
,
1116 &iscsi_tpg_param_DataSequenceInOrder
.attr
,
1117 &iscsi_tpg_param_ErrorRecoveryLevel
.attr
,
1118 &iscsi_tpg_param_IFMarker
.attr
,
1119 &iscsi_tpg_param_OFMarker
.attr
,
1120 &iscsi_tpg_param_IFMarkInt
.attr
,
1121 &iscsi_tpg_param_OFMarkInt
.attr
,
1125 /* End items for lio_target_tpg_param_cit */
1127 /* Start items for lio_target_tpg_cit */
1129 static ssize_t
lio_target_tpg_show_enable(
1130 struct se_portal_group
*se_tpg
,
1133 struct iscsi_portal_group
*tpg
= container_of(se_tpg
,
1134 struct iscsi_portal_group
, tpg_se_tpg
);
1137 spin_lock(&tpg
->tpg_state_lock
);
1138 len
= sprintf(page
, "%d\n",
1139 (tpg
->tpg_state
== TPG_STATE_ACTIVE
) ? 1 : 0);
1140 spin_unlock(&tpg
->tpg_state_lock
);
1145 static ssize_t
lio_target_tpg_store_enable(
1146 struct se_portal_group
*se_tpg
,
1150 struct iscsi_portal_group
*tpg
= container_of(se_tpg
,
1151 struct iscsi_portal_group
, tpg_se_tpg
);
1156 op
= simple_strtoul(page
, &endptr
, 0);
1157 if ((op
!= 1) && (op
!= 0)) {
1158 pr_err("Illegal value for tpg_enable: %u\n", op
);
1162 ret
= iscsit_get_tpg(tpg
);
1167 ret
= iscsit_tpg_enable_portal_group(tpg
);
1172 * iscsit_tpg_disable_portal_group() assumes force=1
1174 ret
= iscsit_tpg_disable_portal_group(tpg
, 1);
1179 iscsit_put_tpg(tpg
);
1182 iscsit_put_tpg(tpg
);
1186 TF_TPG_BASE_ATTR(lio_target
, enable
, S_IRUGO
| S_IWUSR
);
1188 static struct configfs_attribute
*lio_target_tpg_attrs
[] = {
1189 &lio_target_tpg_enable
.attr
,
1193 /* End items for lio_target_tpg_cit */
1195 /* Start items for lio_target_tiqn_cit */
1197 static struct se_portal_group
*lio_target_tiqn_addtpg(
1199 struct config_group
*group
,
1202 struct iscsi_portal_group
*tpg
;
1203 struct iscsi_tiqn
*tiqn
;
1204 char *tpgt_str
, *end_ptr
;
1206 unsigned short int tpgt
;
1208 tiqn
= container_of(wwn
, struct iscsi_tiqn
, tiqn_wwn
);
1210 * Only tpgt_# directory groups can be created below
1211 * target/iscsi/iqn.superturodiskarry/
1213 tpgt_str
= strstr(name
, "tpgt_");
1215 pr_err("Unable to locate \"tpgt_#\" directory"
1219 tpgt_str
+= 5; /* Skip ahead of "tpgt_" */
1220 tpgt
= (unsigned short int) simple_strtoul(tpgt_str
, &end_ptr
, 0);
1222 tpg
= iscsit_alloc_portal_group(tiqn
, tpgt
);
1226 ret
= core_tpg_register(
1227 &lio_target_fabric_configfs
->tf_ops
,
1228 wwn
, &tpg
->tpg_se_tpg
, tpg
,
1229 TRANSPORT_TPG_TYPE_NORMAL
);
1233 ret
= iscsit_tpg_add_portal_group(tiqn
, tpg
);
1237 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn
->tiqn
);
1238 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1240 return &tpg
->tpg_se_tpg
;
1242 core_tpg_deregister(&tpg
->tpg_se_tpg
);
1247 static void lio_target_tiqn_deltpg(struct se_portal_group
*se_tpg
)
1249 struct iscsi_portal_group
*tpg
;
1250 struct iscsi_tiqn
*tiqn
;
1252 tpg
= container_of(se_tpg
, struct iscsi_portal_group
, tpg_se_tpg
);
1253 tiqn
= tpg
->tpg_tiqn
;
1255 * iscsit_tpg_del_portal_group() assumes force=1
1257 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1258 iscsit_tpg_del_portal_group(tiqn
, tpg
, 1);
1261 /* End items for lio_target_tiqn_cit */
1263 /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1265 static ssize_t
lio_target_wwn_show_attr_lio_version(
1266 struct target_fabric_configfs
*tf
,
1269 return sprintf(page
, "RisingTide Systems Linux-iSCSI Target "ISCSIT_VERSION
"\n");
1272 TF_WWN_ATTR_RO(lio_target
, lio_version
);
1274 static struct configfs_attribute
*lio_target_wwn_attrs
[] = {
1275 &lio_target_wwn_lio_version
.attr
,
1279 static struct se_wwn
*lio_target_call_coreaddtiqn(
1280 struct target_fabric_configfs
*tf
,
1281 struct config_group
*group
,
1284 struct config_group
*stats_cg
;
1285 struct iscsi_tiqn
*tiqn
;
1287 tiqn
= iscsit_add_tiqn((unsigned char *)name
);
1289 return ERR_CAST(tiqn
);
1291 * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group.
1293 stats_cg
= &tiqn
->tiqn_wwn
.fabric_stat_group
;
1295 stats_cg
->default_groups
= kmalloc(sizeof(struct config_group
*) * 6,
1297 if (!stats_cg
->default_groups
) {
1298 pr_err("Unable to allocate memory for"
1299 " stats_cg->default_groups\n");
1300 iscsit_del_tiqn(tiqn
);
1301 return ERR_PTR(-ENOMEM
);
1304 stats_cg
->default_groups
[0] = &WWN_STAT_GRPS(tiqn
)->iscsi_instance_group
;
1305 stats_cg
->default_groups
[1] = &WWN_STAT_GRPS(tiqn
)->iscsi_sess_err_group
;
1306 stats_cg
->default_groups
[2] = &WWN_STAT_GRPS(tiqn
)->iscsi_tgt_attr_group
;
1307 stats_cg
->default_groups
[3] = &WWN_STAT_GRPS(tiqn
)->iscsi_login_stats_group
;
1308 stats_cg
->default_groups
[4] = &WWN_STAT_GRPS(tiqn
)->iscsi_logout_stats_group
;
1309 stats_cg
->default_groups
[5] = NULL
;
1310 config_group_init_type_name(&WWN_STAT_GRPS(tiqn
)->iscsi_instance_group
,
1311 "iscsi_instance", &iscsi_stat_instance_cit
);
1312 config_group_init_type_name(&WWN_STAT_GRPS(tiqn
)->iscsi_sess_err_group
,
1313 "iscsi_sess_err", &iscsi_stat_sess_err_cit
);
1314 config_group_init_type_name(&WWN_STAT_GRPS(tiqn
)->iscsi_tgt_attr_group
,
1315 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit
);
1316 config_group_init_type_name(&WWN_STAT_GRPS(tiqn
)->iscsi_login_stats_group
,
1317 "iscsi_login_stats", &iscsi_stat_login_cit
);
1318 config_group_init_type_name(&WWN_STAT_GRPS(tiqn
)->iscsi_logout_stats_group
,
1319 "iscsi_logout_stats", &iscsi_stat_logout_cit
);
1321 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn
->tiqn
);
1322 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1324 return &tiqn
->tiqn_wwn
;
1327 static void lio_target_call_coredeltiqn(
1330 struct iscsi_tiqn
*tiqn
= container_of(wwn
, struct iscsi_tiqn
, tiqn_wwn
);
1331 struct config_item
*df_item
;
1332 struct config_group
*stats_cg
;
1335 stats_cg
= &tiqn
->tiqn_wwn
.fabric_stat_group
;
1336 for (i
= 0; stats_cg
->default_groups
[i
]; i
++) {
1337 df_item
= &stats_cg
->default_groups
[i
]->cg_item
;
1338 stats_cg
->default_groups
[i
] = NULL
;
1339 config_item_put(df_item
);
1341 kfree(stats_cg
->default_groups
);
1343 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1345 iscsit_del_tiqn(tiqn
);
1348 /* End LIO-Target TIQN struct contig_lio_target_cit */
1350 /* Start lio_target_discovery_auth_cit */
1352 #define DEF_DISC_AUTH_STR(name, flags) \
1353 __DEF_NACL_AUTH_STR(disc, name, flags) \
1354 static ssize_t iscsi_disc_show_##name( \
1355 struct target_fabric_configfs *tf, \
1358 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \
1361 static ssize_t iscsi_disc_store_##name( \
1362 struct target_fabric_configfs *tf, \
1366 return __iscsi_disc_store_##name(&iscsit_global->discovery_acl, \
1370 #define DEF_DISC_AUTH_INT(name) \
1371 __DEF_NACL_AUTH_INT(disc, name) \
1372 static ssize_t iscsi_disc_show_##name( \
1373 struct target_fabric_configfs *tf, \
1376 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \
1380 #define DISC_AUTH_ATTR(_name, _mode) TF_DISC_ATTR(iscsi, _name, _mode)
1381 #define DISC_AUTH_ATTR_RO(_name) TF_DISC_ATTR_RO(iscsi, _name)
1384 * One-way authentication userid
1386 DEF_DISC_AUTH_STR(userid
, NAF_USERID_SET
);
1387 DISC_AUTH_ATTR(userid
, S_IRUGO
| S_IWUSR
);
1389 * One-way authentication password
1391 DEF_DISC_AUTH_STR(password
, NAF_PASSWORD_SET
);
1392 DISC_AUTH_ATTR(password
, S_IRUGO
| S_IWUSR
);
1394 * Enforce mutual authentication
1396 DEF_DISC_AUTH_INT(authenticate_target
);
1397 DISC_AUTH_ATTR_RO(authenticate_target
);
1399 * Mutual authentication userid
1401 DEF_DISC_AUTH_STR(userid_mutual
, NAF_USERID_IN_SET
);
1402 DISC_AUTH_ATTR(userid_mutual
, S_IRUGO
| S_IWUSR
);
1404 * Mutual authentication password
1406 DEF_DISC_AUTH_STR(password_mutual
, NAF_PASSWORD_IN_SET
);
1407 DISC_AUTH_ATTR(password_mutual
, S_IRUGO
| S_IWUSR
);
1410 * enforce_discovery_auth
1412 static ssize_t
iscsi_disc_show_enforce_discovery_auth(
1413 struct target_fabric_configfs
*tf
,
1416 struct iscsi_node_auth
*discovery_auth
= &iscsit_global
->discovery_acl
.node_auth
;
1418 return sprintf(page
, "%d\n", discovery_auth
->enforce_discovery_auth
);
1421 static ssize_t
iscsi_disc_store_enforce_discovery_auth(
1422 struct target_fabric_configfs
*tf
,
1426 struct iscsi_param
*param
;
1427 struct iscsi_portal_group
*discovery_tpg
= iscsit_global
->discovery_tpg
;
1431 op
= simple_strtoul(page
, &endptr
, 0);
1432 if ((op
!= 1) && (op
!= 0)) {
1433 pr_err("Illegal value for enforce_discovery_auth:"
1438 if (!discovery_tpg
) {
1439 pr_err("iscsit_global->discovery_tpg is NULL\n");
1443 param
= iscsi_find_param_from_key(AUTHMETHOD
,
1444 discovery_tpg
->param_list
);
1450 * Reset the AuthMethod key to CHAP.
1452 if (iscsi_update_param_value(param
, CHAP
) < 0)
1455 discovery_tpg
->tpg_attrib
.authentication
= 1;
1456 iscsit_global
->discovery_acl
.node_auth
.enforce_discovery_auth
= 1;
1457 pr_debug("LIO-CORE[0] Successfully enabled"
1458 " authentication enforcement for iSCSI"
1459 " Discovery TPG\n");
1462 * Reset the AuthMethod key to CHAP,None
1464 if (iscsi_update_param_value(param
, "CHAP,None") < 0)
1467 discovery_tpg
->tpg_attrib
.authentication
= 0;
1468 iscsit_global
->discovery_acl
.node_auth
.enforce_discovery_auth
= 0;
1469 pr_debug("LIO-CORE[0] Successfully disabled"
1470 " authentication enforcement for iSCSI"
1471 " Discovery TPG\n");
1477 DISC_AUTH_ATTR(enforce_discovery_auth
, S_IRUGO
| S_IWUSR
);
1479 static struct configfs_attribute
*lio_target_discovery_auth_attrs
[] = {
1480 &iscsi_disc_userid
.attr
,
1481 &iscsi_disc_password
.attr
,
1482 &iscsi_disc_authenticate_target
.attr
,
1483 &iscsi_disc_userid_mutual
.attr
,
1484 &iscsi_disc_password_mutual
.attr
,
1485 &iscsi_disc_enforce_discovery_auth
.attr
,
1489 /* End lio_target_discovery_auth_cit */
1491 /* Start functions for target_core_fabric_ops */
1493 static char *iscsi_get_fabric_name(void)
1498 static u32
iscsi_get_task_tag(struct se_cmd
*se_cmd
)
1500 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1502 /* only used for printks or comparism with ->ref_task_tag */
1503 return (__force u32
)cmd
->init_task_tag
;
1506 static int iscsi_get_cmd_state(struct se_cmd
*se_cmd
)
1508 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1510 return cmd
->i_state
;
1513 static u32
lio_sess_get_index(struct se_session
*se_sess
)
1515 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1517 return sess
->session_index
;
1520 static u32
lio_sess_get_initiator_sid(
1521 struct se_session
*se_sess
,
1525 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1527 * iSCSI Initiator Session Identifier from RFC-3720.
1529 return snprintf(buf
, size
, "%02x%02x%02x%02x%02x%02x",
1530 sess
->isid
[0], sess
->isid
[1], sess
->isid
[2],
1531 sess
->isid
[3], sess
->isid
[4], sess
->isid
[5]);
1534 static int lio_queue_data_in(struct se_cmd
*se_cmd
)
1536 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1538 cmd
->i_state
= ISTATE_SEND_DATAIN
;
1539 iscsit_add_cmd_to_response_queue(cmd
, cmd
->conn
, cmd
->i_state
);
1543 static int lio_write_pending(struct se_cmd
*se_cmd
)
1545 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1547 if (!cmd
->immediate_data
&& !cmd
->unsolicited_data
)
1548 return iscsit_build_r2ts_for_cmd(cmd
, cmd
->conn
, false);
1553 static int lio_write_pending_status(struct se_cmd
*se_cmd
)
1555 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1558 spin_lock_bh(&cmd
->istate_lock
);
1559 ret
= !(cmd
->cmd_flags
& ICF_GOT_LAST_DATAOUT
);
1560 spin_unlock_bh(&cmd
->istate_lock
);
1565 static int lio_queue_status(struct se_cmd
*se_cmd
)
1567 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1569 cmd
->i_state
= ISTATE_SEND_STATUS
;
1570 iscsit_add_cmd_to_response_queue(cmd
, cmd
->conn
, cmd
->i_state
);
1574 static int lio_queue_tm_rsp(struct se_cmd
*se_cmd
)
1576 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1578 cmd
->i_state
= ISTATE_SEND_TASKMGTRSP
;
1579 iscsit_add_cmd_to_response_queue(cmd
, cmd
->conn
, cmd
->i_state
);
1583 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group
*se_tpg
)
1585 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1587 return &tpg
->tpg_tiqn
->tiqn
[0];
1590 static u16
lio_tpg_get_tag(struct se_portal_group
*se_tpg
)
1592 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1597 static u32
lio_tpg_get_default_depth(struct se_portal_group
*se_tpg
)
1599 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1601 return ISCSI_TPG_ATTRIB(tpg
)->default_cmdsn_depth
;
1604 static int lio_tpg_check_demo_mode(struct se_portal_group
*se_tpg
)
1606 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1608 return ISCSI_TPG_ATTRIB(tpg
)->generate_node_acls
;
1611 static int lio_tpg_check_demo_mode_cache(struct se_portal_group
*se_tpg
)
1613 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1615 return ISCSI_TPG_ATTRIB(tpg
)->cache_dynamic_acls
;
1618 static int lio_tpg_check_demo_mode_write_protect(
1619 struct se_portal_group
*se_tpg
)
1621 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1623 return ISCSI_TPG_ATTRIB(tpg
)->demo_mode_write_protect
;
1626 static int lio_tpg_check_prod_mode_write_protect(
1627 struct se_portal_group
*se_tpg
)
1629 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1631 return ISCSI_TPG_ATTRIB(tpg
)->prod_mode_write_protect
;
1634 static void lio_tpg_release_fabric_acl(
1635 struct se_portal_group
*se_tpg
,
1636 struct se_node_acl
*se_acl
)
1638 struct iscsi_node_acl
*acl
= container_of(se_acl
,
1639 struct iscsi_node_acl
, se_node_acl
);
1644 * Called with spin_lock_bh(struct se_portal_group->session_lock) held..
1646 * Also, this function calls iscsit_inc_session_usage_count() on the
1647 * struct iscsi_session in question.
1649 static int lio_tpg_shutdown_session(struct se_session
*se_sess
)
1651 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1653 spin_lock(&sess
->conn_lock
);
1654 if (atomic_read(&sess
->session_fall_back_to_erl0
) ||
1655 atomic_read(&sess
->session_logout
) ||
1656 (sess
->time2retain_timer_flags
& ISCSI_TF_EXPIRED
)) {
1657 spin_unlock(&sess
->conn_lock
);
1660 atomic_set(&sess
->session_reinstatement
, 1);
1661 spin_unlock(&sess
->conn_lock
);
1663 iscsit_stop_time2retain_timer(sess
);
1664 iscsit_stop_session(sess
, 1, 1);
1670 * Calls iscsit_dec_session_usage_count() as inverse of
1671 * lio_tpg_shutdown_session()
1673 static void lio_tpg_close_session(struct se_session
*se_sess
)
1675 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1677 * If the iSCSI Session for the iSCSI Initiator Node exists,
1678 * forcefully shutdown the iSCSI NEXUS.
1680 iscsit_close_session(sess
);
1683 static u32
lio_tpg_get_inst_index(struct se_portal_group
*se_tpg
)
1685 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1687 return tpg
->tpg_tiqn
->tiqn_index
;
1690 static void lio_set_default_node_attributes(struct se_node_acl
*se_acl
)
1692 struct iscsi_node_acl
*acl
= container_of(se_acl
, struct iscsi_node_acl
,
1695 ISCSI_NODE_ATTRIB(acl
)->nacl
= acl
;
1696 iscsit_set_default_node_attribues(acl
);
1699 static void lio_release_cmd(struct se_cmd
*se_cmd
)
1701 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1703 iscsit_release_cmd(cmd
);
1706 /* End functions for target_core_fabric_ops */
1708 int iscsi_target_register_configfs(void)
1710 struct target_fabric_configfs
*fabric
;
1713 lio_target_fabric_configfs
= NULL
;
1714 fabric
= target_fabric_configfs_init(THIS_MODULE
, "iscsi");
1715 if (IS_ERR(fabric
)) {
1716 pr_err("target_fabric_configfs_init() for"
1717 " LIO-Target failed!\n");
1718 return PTR_ERR(fabric
);
1721 * Setup the fabric API of function pointers used by target_core_mod..
1723 fabric
->tf_ops
.get_fabric_name
= &iscsi_get_fabric_name
;
1724 fabric
->tf_ops
.get_fabric_proto_ident
= &iscsi_get_fabric_proto_ident
;
1725 fabric
->tf_ops
.tpg_get_wwn
= &lio_tpg_get_endpoint_wwn
;
1726 fabric
->tf_ops
.tpg_get_tag
= &lio_tpg_get_tag
;
1727 fabric
->tf_ops
.tpg_get_default_depth
= &lio_tpg_get_default_depth
;
1728 fabric
->tf_ops
.tpg_get_pr_transport_id
= &iscsi_get_pr_transport_id
;
1729 fabric
->tf_ops
.tpg_get_pr_transport_id_len
=
1730 &iscsi_get_pr_transport_id_len
;
1731 fabric
->tf_ops
.tpg_parse_pr_out_transport_id
=
1732 &iscsi_parse_pr_out_transport_id
;
1733 fabric
->tf_ops
.tpg_check_demo_mode
= &lio_tpg_check_demo_mode
;
1734 fabric
->tf_ops
.tpg_check_demo_mode_cache
=
1735 &lio_tpg_check_demo_mode_cache
;
1736 fabric
->tf_ops
.tpg_check_demo_mode_write_protect
=
1737 &lio_tpg_check_demo_mode_write_protect
;
1738 fabric
->tf_ops
.tpg_check_prod_mode_write_protect
=
1739 &lio_tpg_check_prod_mode_write_protect
;
1740 fabric
->tf_ops
.tpg_alloc_fabric_acl
= &lio_tpg_alloc_fabric_acl
;
1741 fabric
->tf_ops
.tpg_release_fabric_acl
= &lio_tpg_release_fabric_acl
;
1742 fabric
->tf_ops
.tpg_get_inst_index
= &lio_tpg_get_inst_index
;
1743 fabric
->tf_ops
.release_cmd
= &lio_release_cmd
;
1744 fabric
->tf_ops
.shutdown_session
= &lio_tpg_shutdown_session
;
1745 fabric
->tf_ops
.close_session
= &lio_tpg_close_session
;
1746 fabric
->tf_ops
.sess_get_index
= &lio_sess_get_index
;
1747 fabric
->tf_ops
.sess_get_initiator_sid
= &lio_sess_get_initiator_sid
;
1748 fabric
->tf_ops
.write_pending
= &lio_write_pending
;
1749 fabric
->tf_ops
.write_pending_status
= &lio_write_pending_status
;
1750 fabric
->tf_ops
.set_default_node_attributes
=
1751 &lio_set_default_node_attributes
;
1752 fabric
->tf_ops
.get_task_tag
= &iscsi_get_task_tag
;
1753 fabric
->tf_ops
.get_cmd_state
= &iscsi_get_cmd_state
;
1754 fabric
->tf_ops
.queue_data_in
= &lio_queue_data_in
;
1755 fabric
->tf_ops
.queue_status
= &lio_queue_status
;
1756 fabric
->tf_ops
.queue_tm_rsp
= &lio_queue_tm_rsp
;
1758 * Setup function pointers for generic logic in target_core_fabric_configfs.c
1760 fabric
->tf_ops
.fabric_make_wwn
= &lio_target_call_coreaddtiqn
;
1761 fabric
->tf_ops
.fabric_drop_wwn
= &lio_target_call_coredeltiqn
;
1762 fabric
->tf_ops
.fabric_make_tpg
= &lio_target_tiqn_addtpg
;
1763 fabric
->tf_ops
.fabric_drop_tpg
= &lio_target_tiqn_deltpg
;
1764 fabric
->tf_ops
.fabric_post_link
= NULL
;
1765 fabric
->tf_ops
.fabric_pre_unlink
= NULL
;
1766 fabric
->tf_ops
.fabric_make_np
= &lio_target_call_addnptotpg
;
1767 fabric
->tf_ops
.fabric_drop_np
= &lio_target_call_delnpfromtpg
;
1768 fabric
->tf_ops
.fabric_make_nodeacl
= &lio_target_make_nodeacl
;
1769 fabric
->tf_ops
.fabric_drop_nodeacl
= &lio_target_drop_nodeacl
;
1771 * Setup default attribute lists for various fabric->tf_cit_tmpl
1772 * sturct config_item_type's
1774 TF_CIT_TMPL(fabric
)->tfc_discovery_cit
.ct_attrs
= lio_target_discovery_auth_attrs
;
1775 TF_CIT_TMPL(fabric
)->tfc_wwn_cit
.ct_attrs
= lio_target_wwn_attrs
;
1776 TF_CIT_TMPL(fabric
)->tfc_tpg_base_cit
.ct_attrs
= lio_target_tpg_attrs
;
1777 TF_CIT_TMPL(fabric
)->tfc_tpg_attrib_cit
.ct_attrs
= lio_target_tpg_attrib_attrs
;
1778 TF_CIT_TMPL(fabric
)->tfc_tpg_param_cit
.ct_attrs
= lio_target_tpg_param_attrs
;
1779 TF_CIT_TMPL(fabric
)->tfc_tpg_np_base_cit
.ct_attrs
= lio_target_portal_attrs
;
1780 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_base_cit
.ct_attrs
= lio_target_initiator_attrs
;
1781 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_attrib_cit
.ct_attrs
= lio_target_nacl_attrib_attrs
;
1782 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_auth_cit
.ct_attrs
= lio_target_nacl_auth_attrs
;
1783 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_param_cit
.ct_attrs
= lio_target_nacl_param_attrs
;
1785 ret
= target_fabric_configfs_register(fabric
);
1787 pr_err("target_fabric_configfs_register() for"
1788 " LIO-Target failed!\n");
1789 target_fabric_configfs_free(fabric
);
1793 lio_target_fabric_configfs
= fabric
;
1794 pr_debug("LIO_TARGET[0] - Set fabric ->"
1795 " lio_target_fabric_configfs\n");
1800 void iscsi_target_deregister_configfs(void)
1802 if (!lio_target_fabric_configfs
)
1805 * Shutdown discovery sessions and disable discovery TPG
1807 if (iscsit_global
->discovery_tpg
)
1808 iscsit_tpg_disable_portal_group(iscsit_global
->discovery_tpg
, 1);
1810 target_fabric_configfs_deregister(lio_target_fabric_configfs
);
1811 lio_target_fabric_configfs
= NULL
;
1812 pr_debug("LIO_TARGET[0] - Cleared"
1813 " lio_target_fabric_configfs\n");