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 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 atributes 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 struct configfs_attribute
*lio_target_initiator_attrs
[] = {
758 &lio_target_nacl_info
.attr
,
759 &lio_target_nacl_cmdsn_depth
.attr
,
763 static struct se_node_acl
*lio_tpg_alloc_fabric_acl(
764 struct se_portal_group
*se_tpg
)
766 struct iscsi_node_acl
*acl
;
768 acl
= kzalloc(sizeof(struct iscsi_node_acl
), GFP_KERNEL
);
770 pr_err("Unable to allocate memory for struct iscsi_node_acl\n");
774 return &acl
->se_node_acl
;
777 static struct se_node_acl
*lio_target_make_nodeacl(
778 struct se_portal_group
*se_tpg
,
779 struct config_group
*group
,
782 struct config_group
*stats_cg
;
783 struct iscsi_node_acl
*acl
;
784 struct se_node_acl
*se_nacl_new
, *se_nacl
;
785 struct iscsi_portal_group
*tpg
= container_of(se_tpg
,
786 struct iscsi_portal_group
, tpg_se_tpg
);
789 se_nacl_new
= lio_tpg_alloc_fabric_acl(se_tpg
);
791 return ERR_PTR(-ENOMEM
);
793 cmdsn_depth
= ISCSI_TPG_ATTRIB(tpg
)->default_cmdsn_depth
;
795 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
796 * when converting a NdoeACL from demo mode -> explict
798 se_nacl
= core_tpg_add_initiator_node_acl(se_tpg
, se_nacl_new
,
803 acl
= container_of(se_nacl
, struct iscsi_node_acl
, se_node_acl
);
804 stats_cg
= &se_nacl
->acl_fabric_stat_group
;
806 stats_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
808 if (!stats_cg
->default_groups
) {
809 pr_err("Unable to allocate memory for"
810 " stats_cg->default_groups\n");
811 core_tpg_del_initiator_node_acl(se_tpg
, se_nacl
, 1);
813 return ERR_PTR(-ENOMEM
);
816 stats_cg
->default_groups
[0] = &NODE_STAT_GRPS(acl
)->iscsi_sess_stats_group
;
817 stats_cg
->default_groups
[1] = NULL
;
818 config_group_init_type_name(&NODE_STAT_GRPS(acl
)->iscsi_sess_stats_group
,
819 "iscsi_sess_stats", &iscsi_stat_sess_cit
);
824 static void lio_target_drop_nodeacl(
825 struct se_node_acl
*se_nacl
)
827 struct se_portal_group
*se_tpg
= se_nacl
->se_tpg
;
828 struct iscsi_node_acl
*acl
= container_of(se_nacl
,
829 struct iscsi_node_acl
, se_node_acl
);
830 struct config_item
*df_item
;
831 struct config_group
*stats_cg
;
834 stats_cg
= &acl
->se_node_acl
.acl_fabric_stat_group
;
835 for (i
= 0; stats_cg
->default_groups
[i
]; i
++) {
836 df_item
= &stats_cg
->default_groups
[i
]->cg_item
;
837 stats_cg
->default_groups
[i
] = NULL
;
838 config_item_put(df_item
);
840 kfree(stats_cg
->default_groups
);
842 core_tpg_del_initiator_node_acl(se_tpg
, se_nacl
, 1);
846 /* End items for lio_target_acl_cit */
848 /* Start items for lio_target_tpg_attrib_cit */
850 #define DEF_TPG_ATTRIB(name) \
852 static ssize_t iscsi_tpg_attrib_show_##name( \
853 struct se_portal_group *se_tpg, \
856 struct iscsi_portal_group *tpg = container_of(se_tpg, \
857 struct iscsi_portal_group, tpg_se_tpg); \
860 if (iscsit_get_tpg(tpg) < 0) \
863 rb = sprintf(page, "%u\n", ISCSI_TPG_ATTRIB(tpg)->name); \
864 iscsit_put_tpg(tpg); \
868 static ssize_t iscsi_tpg_attrib_store_##name( \
869 struct se_portal_group *se_tpg, \
873 struct iscsi_portal_group *tpg = container_of(se_tpg, \
874 struct iscsi_portal_group, tpg_se_tpg); \
879 if (iscsit_get_tpg(tpg) < 0) \
882 val = simple_strtoul(page, &endptr, 0); \
883 ret = iscsit_ta_##name(tpg, val); \
887 iscsit_put_tpg(tpg); \
890 iscsit_put_tpg(tpg); \
894 #define TPG_ATTR(_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode);
897 * Define iscsi_tpg_attrib_s_authentication
899 DEF_TPG_ATTRIB(authentication
);
900 TPG_ATTR(authentication
, S_IRUGO
| S_IWUSR
);
902 * Define iscsi_tpg_attrib_s_login_timeout
904 DEF_TPG_ATTRIB(login_timeout
);
905 TPG_ATTR(login_timeout
, S_IRUGO
| S_IWUSR
);
907 * Define iscsi_tpg_attrib_s_netif_timeout
909 DEF_TPG_ATTRIB(netif_timeout
);
910 TPG_ATTR(netif_timeout
, S_IRUGO
| S_IWUSR
);
912 * Define iscsi_tpg_attrib_s_generate_node_acls
914 DEF_TPG_ATTRIB(generate_node_acls
);
915 TPG_ATTR(generate_node_acls
, S_IRUGO
| S_IWUSR
);
917 * Define iscsi_tpg_attrib_s_default_cmdsn_depth
919 DEF_TPG_ATTRIB(default_cmdsn_depth
);
920 TPG_ATTR(default_cmdsn_depth
, S_IRUGO
| S_IWUSR
);
922 Define iscsi_tpg_attrib_s_cache_dynamic_acls
924 DEF_TPG_ATTRIB(cache_dynamic_acls
);
925 TPG_ATTR(cache_dynamic_acls
, S_IRUGO
| S_IWUSR
);
927 * Define iscsi_tpg_attrib_s_demo_mode_write_protect
929 DEF_TPG_ATTRIB(demo_mode_write_protect
);
930 TPG_ATTR(demo_mode_write_protect
, S_IRUGO
| S_IWUSR
);
932 * Define iscsi_tpg_attrib_s_prod_mode_write_protect
934 DEF_TPG_ATTRIB(prod_mode_write_protect
);
935 TPG_ATTR(prod_mode_write_protect
, S_IRUGO
| S_IWUSR
);
937 static struct configfs_attribute
*lio_target_tpg_attrib_attrs
[] = {
938 &iscsi_tpg_attrib_authentication
.attr
,
939 &iscsi_tpg_attrib_login_timeout
.attr
,
940 &iscsi_tpg_attrib_netif_timeout
.attr
,
941 &iscsi_tpg_attrib_generate_node_acls
.attr
,
942 &iscsi_tpg_attrib_default_cmdsn_depth
.attr
,
943 &iscsi_tpg_attrib_cache_dynamic_acls
.attr
,
944 &iscsi_tpg_attrib_demo_mode_write_protect
.attr
,
945 &iscsi_tpg_attrib_prod_mode_write_protect
.attr
,
949 /* End items for lio_target_tpg_attrib_cit */
951 /* Start items for lio_target_tpg_param_cit */
953 #define DEF_TPG_PARAM(name) \
954 static ssize_t iscsi_tpg_param_show_##name( \
955 struct se_portal_group *se_tpg, \
958 struct iscsi_portal_group *tpg = container_of(se_tpg, \
959 struct iscsi_portal_group, tpg_se_tpg); \
960 struct iscsi_param *param; \
963 if (iscsit_get_tpg(tpg) < 0) \
966 param = iscsi_find_param_from_key(__stringify(name), \
969 iscsit_put_tpg(tpg); \
972 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
974 iscsit_put_tpg(tpg); \
977 static ssize_t iscsi_tpg_param_store_##name( \
978 struct se_portal_group *se_tpg, \
982 struct iscsi_portal_group *tpg = container_of(se_tpg, \
983 struct iscsi_portal_group, tpg_se_tpg); \
987 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
990 snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
991 buf[strlen(buf)-1] = '\0'; /* Kill newline */ \
993 if (iscsit_get_tpg(tpg) < 0) { \
998 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
1003 iscsit_put_tpg(tpg); \
1007 iscsit_put_tpg(tpg); \
1011 #define TPG_PARAM_ATTR(_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode);
1013 DEF_TPG_PARAM(AuthMethod
);
1014 TPG_PARAM_ATTR(AuthMethod
, S_IRUGO
| S_IWUSR
);
1016 DEF_TPG_PARAM(HeaderDigest
);
1017 TPG_PARAM_ATTR(HeaderDigest
, S_IRUGO
| S_IWUSR
);
1019 DEF_TPG_PARAM(DataDigest
);
1020 TPG_PARAM_ATTR(DataDigest
, S_IRUGO
| S_IWUSR
);
1022 DEF_TPG_PARAM(MaxConnections
);
1023 TPG_PARAM_ATTR(MaxConnections
, S_IRUGO
| S_IWUSR
);
1025 DEF_TPG_PARAM(TargetAlias
);
1026 TPG_PARAM_ATTR(TargetAlias
, S_IRUGO
| S_IWUSR
);
1028 DEF_TPG_PARAM(InitialR2T
);
1029 TPG_PARAM_ATTR(InitialR2T
, S_IRUGO
| S_IWUSR
);
1031 DEF_TPG_PARAM(ImmediateData
);
1032 TPG_PARAM_ATTR(ImmediateData
, S_IRUGO
| S_IWUSR
);
1034 DEF_TPG_PARAM(MaxRecvDataSegmentLength
);
1035 TPG_PARAM_ATTR(MaxRecvDataSegmentLength
, S_IRUGO
| S_IWUSR
);
1037 DEF_TPG_PARAM(MaxBurstLength
);
1038 TPG_PARAM_ATTR(MaxBurstLength
, S_IRUGO
| S_IWUSR
);
1040 DEF_TPG_PARAM(FirstBurstLength
);
1041 TPG_PARAM_ATTR(FirstBurstLength
, S_IRUGO
| S_IWUSR
);
1043 DEF_TPG_PARAM(DefaultTime2Wait
);
1044 TPG_PARAM_ATTR(DefaultTime2Wait
, S_IRUGO
| S_IWUSR
);
1046 DEF_TPG_PARAM(DefaultTime2Retain
);
1047 TPG_PARAM_ATTR(DefaultTime2Retain
, S_IRUGO
| S_IWUSR
);
1049 DEF_TPG_PARAM(MaxOutstandingR2T
);
1050 TPG_PARAM_ATTR(MaxOutstandingR2T
, S_IRUGO
| S_IWUSR
);
1052 DEF_TPG_PARAM(DataPDUInOrder
);
1053 TPG_PARAM_ATTR(DataPDUInOrder
, S_IRUGO
| S_IWUSR
);
1055 DEF_TPG_PARAM(DataSequenceInOrder
);
1056 TPG_PARAM_ATTR(DataSequenceInOrder
, S_IRUGO
| S_IWUSR
);
1058 DEF_TPG_PARAM(ErrorRecoveryLevel
);
1059 TPG_PARAM_ATTR(ErrorRecoveryLevel
, S_IRUGO
| S_IWUSR
);
1061 DEF_TPG_PARAM(IFMarker
);
1062 TPG_PARAM_ATTR(IFMarker
, S_IRUGO
| S_IWUSR
);
1064 DEF_TPG_PARAM(OFMarker
);
1065 TPG_PARAM_ATTR(OFMarker
, S_IRUGO
| S_IWUSR
);
1067 DEF_TPG_PARAM(IFMarkInt
);
1068 TPG_PARAM_ATTR(IFMarkInt
, S_IRUGO
| S_IWUSR
);
1070 DEF_TPG_PARAM(OFMarkInt
);
1071 TPG_PARAM_ATTR(OFMarkInt
, S_IRUGO
| S_IWUSR
);
1073 static struct configfs_attribute
*lio_target_tpg_param_attrs
[] = {
1074 &iscsi_tpg_param_AuthMethod
.attr
,
1075 &iscsi_tpg_param_HeaderDigest
.attr
,
1076 &iscsi_tpg_param_DataDigest
.attr
,
1077 &iscsi_tpg_param_MaxConnections
.attr
,
1078 &iscsi_tpg_param_TargetAlias
.attr
,
1079 &iscsi_tpg_param_InitialR2T
.attr
,
1080 &iscsi_tpg_param_ImmediateData
.attr
,
1081 &iscsi_tpg_param_MaxRecvDataSegmentLength
.attr
,
1082 &iscsi_tpg_param_MaxBurstLength
.attr
,
1083 &iscsi_tpg_param_FirstBurstLength
.attr
,
1084 &iscsi_tpg_param_DefaultTime2Wait
.attr
,
1085 &iscsi_tpg_param_DefaultTime2Retain
.attr
,
1086 &iscsi_tpg_param_MaxOutstandingR2T
.attr
,
1087 &iscsi_tpg_param_DataPDUInOrder
.attr
,
1088 &iscsi_tpg_param_DataSequenceInOrder
.attr
,
1089 &iscsi_tpg_param_ErrorRecoveryLevel
.attr
,
1090 &iscsi_tpg_param_IFMarker
.attr
,
1091 &iscsi_tpg_param_OFMarker
.attr
,
1092 &iscsi_tpg_param_IFMarkInt
.attr
,
1093 &iscsi_tpg_param_OFMarkInt
.attr
,
1097 /* End items for lio_target_tpg_param_cit */
1099 /* Start items for lio_target_tpg_cit */
1101 static ssize_t
lio_target_tpg_show_enable(
1102 struct se_portal_group
*se_tpg
,
1105 struct iscsi_portal_group
*tpg
= container_of(se_tpg
,
1106 struct iscsi_portal_group
, tpg_se_tpg
);
1109 spin_lock(&tpg
->tpg_state_lock
);
1110 len
= sprintf(page
, "%d\n",
1111 (tpg
->tpg_state
== TPG_STATE_ACTIVE
) ? 1 : 0);
1112 spin_unlock(&tpg
->tpg_state_lock
);
1117 static ssize_t
lio_target_tpg_store_enable(
1118 struct se_portal_group
*se_tpg
,
1122 struct iscsi_portal_group
*tpg
= container_of(se_tpg
,
1123 struct iscsi_portal_group
, tpg_se_tpg
);
1128 op
= simple_strtoul(page
, &endptr
, 0);
1129 if ((op
!= 1) && (op
!= 0)) {
1130 pr_err("Illegal value for tpg_enable: %u\n", op
);
1134 ret
= iscsit_get_tpg(tpg
);
1139 ret
= iscsit_tpg_enable_portal_group(tpg
);
1144 * iscsit_tpg_disable_portal_group() assumes force=1
1146 ret
= iscsit_tpg_disable_portal_group(tpg
, 1);
1151 iscsit_put_tpg(tpg
);
1154 iscsit_put_tpg(tpg
);
1158 TF_TPG_BASE_ATTR(lio_target
, enable
, S_IRUGO
| S_IWUSR
);
1160 static struct configfs_attribute
*lio_target_tpg_attrs
[] = {
1161 &lio_target_tpg_enable
.attr
,
1165 /* End items for lio_target_tpg_cit */
1167 /* Start items for lio_target_tiqn_cit */
1169 struct se_portal_group
*lio_target_tiqn_addtpg(
1171 struct config_group
*group
,
1174 struct iscsi_portal_group
*tpg
;
1175 struct iscsi_tiqn
*tiqn
;
1176 char *tpgt_str
, *end_ptr
;
1178 unsigned short int tpgt
;
1180 tiqn
= container_of(wwn
, struct iscsi_tiqn
, tiqn_wwn
);
1182 * Only tpgt_# directory groups can be created below
1183 * target/iscsi/iqn.superturodiskarry/
1185 tpgt_str
= strstr(name
, "tpgt_");
1187 pr_err("Unable to locate \"tpgt_#\" directory"
1191 tpgt_str
+= 5; /* Skip ahead of "tpgt_" */
1192 tpgt
= (unsigned short int) simple_strtoul(tpgt_str
, &end_ptr
, 0);
1194 tpg
= iscsit_alloc_portal_group(tiqn
, tpgt
);
1198 ret
= core_tpg_register(
1199 &lio_target_fabric_configfs
->tf_ops
,
1200 wwn
, &tpg
->tpg_se_tpg
, tpg
,
1201 TRANSPORT_TPG_TYPE_NORMAL
);
1205 ret
= iscsit_tpg_add_portal_group(tiqn
, tpg
);
1209 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn
->tiqn
);
1210 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1212 return &tpg
->tpg_se_tpg
;
1214 core_tpg_deregister(&tpg
->tpg_se_tpg
);
1219 void lio_target_tiqn_deltpg(struct se_portal_group
*se_tpg
)
1221 struct iscsi_portal_group
*tpg
;
1222 struct iscsi_tiqn
*tiqn
;
1224 tpg
= container_of(se_tpg
, struct iscsi_portal_group
, tpg_se_tpg
);
1225 tiqn
= tpg
->tpg_tiqn
;
1227 * iscsit_tpg_del_portal_group() assumes force=1
1229 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1230 iscsit_tpg_del_portal_group(tiqn
, tpg
, 1);
1233 /* End items for lio_target_tiqn_cit */
1235 /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1237 static ssize_t
lio_target_wwn_show_attr_lio_version(
1238 struct target_fabric_configfs
*tf
,
1241 return sprintf(page
, "RisingTide Systems Linux-iSCSI Target "ISCSIT_VERSION
"\n");
1244 TF_WWN_ATTR_RO(lio_target
, lio_version
);
1246 static struct configfs_attribute
*lio_target_wwn_attrs
[] = {
1247 &lio_target_wwn_lio_version
.attr
,
1251 struct se_wwn
*lio_target_call_coreaddtiqn(
1252 struct target_fabric_configfs
*tf
,
1253 struct config_group
*group
,
1256 struct config_group
*stats_cg
;
1257 struct iscsi_tiqn
*tiqn
;
1259 tiqn
= iscsit_add_tiqn((unsigned char *)name
);
1261 return ERR_CAST(tiqn
);
1263 * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group.
1265 stats_cg
= &tiqn
->tiqn_wwn
.fabric_stat_group
;
1267 stats_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 6,
1269 if (!stats_cg
->default_groups
) {
1270 pr_err("Unable to allocate memory for"
1271 " stats_cg->default_groups\n");
1272 iscsit_del_tiqn(tiqn
);
1273 return ERR_PTR(-ENOMEM
);
1276 stats_cg
->default_groups
[0] = &WWN_STAT_GRPS(tiqn
)->iscsi_instance_group
;
1277 stats_cg
->default_groups
[1] = &WWN_STAT_GRPS(tiqn
)->iscsi_sess_err_group
;
1278 stats_cg
->default_groups
[2] = &WWN_STAT_GRPS(tiqn
)->iscsi_tgt_attr_group
;
1279 stats_cg
->default_groups
[3] = &WWN_STAT_GRPS(tiqn
)->iscsi_login_stats_group
;
1280 stats_cg
->default_groups
[4] = &WWN_STAT_GRPS(tiqn
)->iscsi_logout_stats_group
;
1281 stats_cg
->default_groups
[5] = NULL
;
1282 config_group_init_type_name(&WWN_STAT_GRPS(tiqn
)->iscsi_instance_group
,
1283 "iscsi_instance", &iscsi_stat_instance_cit
);
1284 config_group_init_type_name(&WWN_STAT_GRPS(tiqn
)->iscsi_sess_err_group
,
1285 "iscsi_sess_err", &iscsi_stat_sess_err_cit
);
1286 config_group_init_type_name(&WWN_STAT_GRPS(tiqn
)->iscsi_tgt_attr_group
,
1287 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit
);
1288 config_group_init_type_name(&WWN_STAT_GRPS(tiqn
)->iscsi_login_stats_group
,
1289 "iscsi_login_stats", &iscsi_stat_login_cit
);
1290 config_group_init_type_name(&WWN_STAT_GRPS(tiqn
)->iscsi_logout_stats_group
,
1291 "iscsi_logout_stats", &iscsi_stat_logout_cit
);
1293 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn
->tiqn
);
1294 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1296 return &tiqn
->tiqn_wwn
;
1299 void lio_target_call_coredeltiqn(
1302 struct iscsi_tiqn
*tiqn
= container_of(wwn
, struct iscsi_tiqn
, tiqn_wwn
);
1303 struct config_item
*df_item
;
1304 struct config_group
*stats_cg
;
1307 stats_cg
= &tiqn
->tiqn_wwn
.fabric_stat_group
;
1308 for (i
= 0; stats_cg
->default_groups
[i
]; i
++) {
1309 df_item
= &stats_cg
->default_groups
[i
]->cg_item
;
1310 stats_cg
->default_groups
[i
] = NULL
;
1311 config_item_put(df_item
);
1313 kfree(stats_cg
->default_groups
);
1315 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1317 iscsit_del_tiqn(tiqn
);
1320 /* End LIO-Target TIQN struct contig_lio_target_cit */
1322 /* Start lio_target_discovery_auth_cit */
1324 #define DEF_DISC_AUTH_STR(name, flags) \
1325 __DEF_NACL_AUTH_STR(disc, name, flags) \
1326 static ssize_t iscsi_disc_show_##name( \
1327 struct target_fabric_configfs *tf, \
1330 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \
1333 static ssize_t iscsi_disc_store_##name( \
1334 struct target_fabric_configfs *tf, \
1338 return __iscsi_disc_store_##name(&iscsit_global->discovery_acl, \
1342 #define DEF_DISC_AUTH_INT(name) \
1343 __DEF_NACL_AUTH_INT(disc, name) \
1344 static ssize_t iscsi_disc_show_##name( \
1345 struct target_fabric_configfs *tf, \
1348 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \
1352 #define DISC_AUTH_ATTR(_name, _mode) TF_DISC_ATTR(iscsi, _name, _mode)
1353 #define DISC_AUTH_ATTR_RO(_name) TF_DISC_ATTR_RO(iscsi, _name)
1356 * One-way authentication userid
1358 DEF_DISC_AUTH_STR(userid
, NAF_USERID_SET
);
1359 DISC_AUTH_ATTR(userid
, S_IRUGO
| S_IWUSR
);
1361 * One-way authentication password
1363 DEF_DISC_AUTH_STR(password
, NAF_PASSWORD_SET
);
1364 DISC_AUTH_ATTR(password
, S_IRUGO
| S_IWUSR
);
1366 * Enforce mutual authentication
1368 DEF_DISC_AUTH_INT(authenticate_target
);
1369 DISC_AUTH_ATTR_RO(authenticate_target
);
1371 * Mutual authentication userid
1373 DEF_DISC_AUTH_STR(userid_mutual
, NAF_USERID_IN_SET
);
1374 DISC_AUTH_ATTR(userid_mutual
, S_IRUGO
| S_IWUSR
);
1376 * Mutual authentication password
1378 DEF_DISC_AUTH_STR(password_mutual
, NAF_PASSWORD_IN_SET
);
1379 DISC_AUTH_ATTR(password_mutual
, S_IRUGO
| S_IWUSR
);
1382 * enforce_discovery_auth
1384 static ssize_t
iscsi_disc_show_enforce_discovery_auth(
1385 struct target_fabric_configfs
*tf
,
1388 struct iscsi_node_auth
*discovery_auth
= &iscsit_global
->discovery_acl
.node_auth
;
1390 return sprintf(page
, "%d\n", discovery_auth
->enforce_discovery_auth
);
1393 static ssize_t
iscsi_disc_store_enforce_discovery_auth(
1394 struct target_fabric_configfs
*tf
,
1398 struct iscsi_param
*param
;
1399 struct iscsi_portal_group
*discovery_tpg
= iscsit_global
->discovery_tpg
;
1403 op
= simple_strtoul(page
, &endptr
, 0);
1404 if ((op
!= 1) && (op
!= 0)) {
1405 pr_err("Illegal value for enforce_discovery_auth:"
1410 if (!discovery_tpg
) {
1411 pr_err("iscsit_global->discovery_tpg is NULL\n");
1415 param
= iscsi_find_param_from_key(AUTHMETHOD
,
1416 discovery_tpg
->param_list
);
1422 * Reset the AuthMethod key to CHAP.
1424 if (iscsi_update_param_value(param
, CHAP
) < 0)
1427 discovery_tpg
->tpg_attrib
.authentication
= 1;
1428 iscsit_global
->discovery_acl
.node_auth
.enforce_discovery_auth
= 1;
1429 pr_debug("LIO-CORE[0] Successfully enabled"
1430 " authentication enforcement for iSCSI"
1431 " Discovery TPG\n");
1434 * Reset the AuthMethod key to CHAP,None
1436 if (iscsi_update_param_value(param
, "CHAP,None") < 0)
1439 discovery_tpg
->tpg_attrib
.authentication
= 0;
1440 iscsit_global
->discovery_acl
.node_auth
.enforce_discovery_auth
= 0;
1441 pr_debug("LIO-CORE[0] Successfully disabled"
1442 " authentication enforcement for iSCSI"
1443 " Discovery TPG\n");
1449 DISC_AUTH_ATTR(enforce_discovery_auth
, S_IRUGO
| S_IWUSR
);
1451 static struct configfs_attribute
*lio_target_discovery_auth_attrs
[] = {
1452 &iscsi_disc_userid
.attr
,
1453 &iscsi_disc_password
.attr
,
1454 &iscsi_disc_authenticate_target
.attr
,
1455 &iscsi_disc_userid_mutual
.attr
,
1456 &iscsi_disc_password_mutual
.attr
,
1457 &iscsi_disc_enforce_discovery_auth
.attr
,
1461 /* End lio_target_discovery_auth_cit */
1463 /* Start functions for target_core_fabric_ops */
1465 static char *iscsi_get_fabric_name(void)
1470 static u32
iscsi_get_task_tag(struct se_cmd
*se_cmd
)
1472 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1474 return cmd
->init_task_tag
;
1477 static int iscsi_get_cmd_state(struct se_cmd
*se_cmd
)
1479 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1481 return cmd
->i_state
;
1484 static u32
lio_sess_get_index(struct se_session
*se_sess
)
1486 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1488 return sess
->session_index
;
1491 static u32
lio_sess_get_initiator_sid(
1492 struct se_session
*se_sess
,
1496 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1498 * iSCSI Initiator Session Identifier from RFC-3720.
1500 return snprintf(buf
, size
, "%02x%02x%02x%02x%02x%02x",
1501 sess
->isid
[0], sess
->isid
[1], sess
->isid
[2],
1502 sess
->isid
[3], sess
->isid
[4], sess
->isid
[5]);
1505 static int lio_queue_data_in(struct se_cmd
*se_cmd
)
1507 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1509 cmd
->i_state
= ISTATE_SEND_DATAIN
;
1510 iscsit_add_cmd_to_response_queue(cmd
, cmd
->conn
, cmd
->i_state
);
1514 static int lio_write_pending(struct se_cmd
*se_cmd
)
1516 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1518 if (!cmd
->immediate_data
&& !cmd
->unsolicited_data
)
1519 return iscsit_build_r2ts_for_cmd(cmd
, cmd
->conn
, false);
1524 static int lio_write_pending_status(struct se_cmd
*se_cmd
)
1526 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1529 spin_lock_bh(&cmd
->istate_lock
);
1530 ret
= !(cmd
->cmd_flags
& ICF_GOT_LAST_DATAOUT
);
1531 spin_unlock_bh(&cmd
->istate_lock
);
1536 static int lio_queue_status(struct se_cmd
*se_cmd
)
1538 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1540 cmd
->i_state
= ISTATE_SEND_STATUS
;
1541 iscsit_add_cmd_to_response_queue(cmd
, cmd
->conn
, cmd
->i_state
);
1545 static u16
lio_set_fabric_sense_len(struct se_cmd
*se_cmd
, u32 sense_length
)
1547 unsigned char *buffer
= se_cmd
->sense_buffer
;
1549 * From RFC-3720 10.4.7. Data Segment - Sense and Response Data Segment
1550 * 16-bit SenseLength.
1552 buffer
[0] = ((sense_length
>> 8) & 0xff);
1553 buffer
[1] = (sense_length
& 0xff);
1555 * Return two byte offset into allocated sense_buffer.
1560 static u16
lio_get_fabric_sense_len(void)
1563 * Return two byte offset into allocated sense_buffer.
1568 static int lio_queue_tm_rsp(struct se_cmd
*se_cmd
)
1570 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1572 cmd
->i_state
= ISTATE_SEND_TASKMGTRSP
;
1573 iscsit_add_cmd_to_response_queue(cmd
, cmd
->conn
, cmd
->i_state
);
1577 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group
*se_tpg
)
1579 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1581 return &tpg
->tpg_tiqn
->tiqn
[0];
1584 static u16
lio_tpg_get_tag(struct se_portal_group
*se_tpg
)
1586 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1591 static u32
lio_tpg_get_default_depth(struct se_portal_group
*se_tpg
)
1593 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1595 return ISCSI_TPG_ATTRIB(tpg
)->default_cmdsn_depth
;
1598 static int lio_tpg_check_demo_mode(struct se_portal_group
*se_tpg
)
1600 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1602 return ISCSI_TPG_ATTRIB(tpg
)->generate_node_acls
;
1605 static int lio_tpg_check_demo_mode_cache(struct se_portal_group
*se_tpg
)
1607 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1609 return ISCSI_TPG_ATTRIB(tpg
)->cache_dynamic_acls
;
1612 static int lio_tpg_check_demo_mode_write_protect(
1613 struct se_portal_group
*se_tpg
)
1615 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1617 return ISCSI_TPG_ATTRIB(tpg
)->demo_mode_write_protect
;
1620 static int lio_tpg_check_prod_mode_write_protect(
1621 struct se_portal_group
*se_tpg
)
1623 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1625 return ISCSI_TPG_ATTRIB(tpg
)->prod_mode_write_protect
;
1628 static void lio_tpg_release_fabric_acl(
1629 struct se_portal_group
*se_tpg
,
1630 struct se_node_acl
*se_acl
)
1632 struct iscsi_node_acl
*acl
= container_of(se_acl
,
1633 struct iscsi_node_acl
, se_node_acl
);
1638 * Called with spin_lock_bh(struct se_portal_group->session_lock) held..
1640 * Also, this function calls iscsit_inc_session_usage_count() on the
1641 * struct iscsi_session in question.
1643 static int lio_tpg_shutdown_session(struct se_session
*se_sess
)
1645 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1647 spin_lock(&sess
->conn_lock
);
1648 if (atomic_read(&sess
->session_fall_back_to_erl0
) ||
1649 atomic_read(&sess
->session_logout
) ||
1650 (sess
->time2retain_timer_flags
& ISCSI_TF_EXPIRED
)) {
1651 spin_unlock(&sess
->conn_lock
);
1654 atomic_set(&sess
->session_reinstatement
, 1);
1655 spin_unlock(&sess
->conn_lock
);
1657 iscsit_stop_time2retain_timer(sess
);
1658 iscsit_stop_session(sess
, 1, 1);
1664 * Calls iscsit_dec_session_usage_count() as inverse of
1665 * lio_tpg_shutdown_session()
1667 static void lio_tpg_close_session(struct se_session
*se_sess
)
1669 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1671 * If the iSCSI Session for the iSCSI Initiator Node exists,
1672 * forcefully shutdown the iSCSI NEXUS.
1674 iscsit_close_session(sess
);
1677 static u32
lio_tpg_get_inst_index(struct se_portal_group
*se_tpg
)
1679 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1681 return tpg
->tpg_tiqn
->tiqn_index
;
1684 static void lio_set_default_node_attributes(struct se_node_acl
*se_acl
)
1686 struct iscsi_node_acl
*acl
= container_of(se_acl
, struct iscsi_node_acl
,
1689 ISCSI_NODE_ATTRIB(acl
)->nacl
= acl
;
1690 iscsit_set_default_node_attribues(acl
);
1693 static void lio_release_cmd(struct se_cmd
*se_cmd
)
1695 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1697 iscsit_release_cmd(cmd
);
1700 /* End functions for target_core_fabric_ops */
1702 int iscsi_target_register_configfs(void)
1704 struct target_fabric_configfs
*fabric
;
1707 lio_target_fabric_configfs
= NULL
;
1708 fabric
= target_fabric_configfs_init(THIS_MODULE
, "iscsi");
1709 if (IS_ERR(fabric
)) {
1710 pr_err("target_fabric_configfs_init() for"
1711 " LIO-Target failed!\n");
1712 return PTR_ERR(fabric
);
1715 * Setup the fabric API of function pointers used by target_core_mod..
1717 fabric
->tf_ops
.get_fabric_name
= &iscsi_get_fabric_name
;
1718 fabric
->tf_ops
.get_fabric_proto_ident
= &iscsi_get_fabric_proto_ident
;
1719 fabric
->tf_ops
.tpg_get_wwn
= &lio_tpg_get_endpoint_wwn
;
1720 fabric
->tf_ops
.tpg_get_tag
= &lio_tpg_get_tag
;
1721 fabric
->tf_ops
.tpg_get_default_depth
= &lio_tpg_get_default_depth
;
1722 fabric
->tf_ops
.tpg_get_pr_transport_id
= &iscsi_get_pr_transport_id
;
1723 fabric
->tf_ops
.tpg_get_pr_transport_id_len
=
1724 &iscsi_get_pr_transport_id_len
;
1725 fabric
->tf_ops
.tpg_parse_pr_out_transport_id
=
1726 &iscsi_parse_pr_out_transport_id
;
1727 fabric
->tf_ops
.tpg_check_demo_mode
= &lio_tpg_check_demo_mode
;
1728 fabric
->tf_ops
.tpg_check_demo_mode_cache
=
1729 &lio_tpg_check_demo_mode_cache
;
1730 fabric
->tf_ops
.tpg_check_demo_mode_write_protect
=
1731 &lio_tpg_check_demo_mode_write_protect
;
1732 fabric
->tf_ops
.tpg_check_prod_mode_write_protect
=
1733 &lio_tpg_check_prod_mode_write_protect
;
1734 fabric
->tf_ops
.tpg_alloc_fabric_acl
= &lio_tpg_alloc_fabric_acl
;
1735 fabric
->tf_ops
.tpg_release_fabric_acl
= &lio_tpg_release_fabric_acl
;
1736 fabric
->tf_ops
.tpg_get_inst_index
= &lio_tpg_get_inst_index
;
1737 fabric
->tf_ops
.release_cmd
= &lio_release_cmd
;
1738 fabric
->tf_ops
.shutdown_session
= &lio_tpg_shutdown_session
;
1739 fabric
->tf_ops
.close_session
= &lio_tpg_close_session
;
1740 fabric
->tf_ops
.sess_get_index
= &lio_sess_get_index
;
1741 fabric
->tf_ops
.sess_get_initiator_sid
= &lio_sess_get_initiator_sid
;
1742 fabric
->tf_ops
.write_pending
= &lio_write_pending
;
1743 fabric
->tf_ops
.write_pending_status
= &lio_write_pending_status
;
1744 fabric
->tf_ops
.set_default_node_attributes
=
1745 &lio_set_default_node_attributes
;
1746 fabric
->tf_ops
.get_task_tag
= &iscsi_get_task_tag
;
1747 fabric
->tf_ops
.get_cmd_state
= &iscsi_get_cmd_state
;
1748 fabric
->tf_ops
.queue_data_in
= &lio_queue_data_in
;
1749 fabric
->tf_ops
.queue_status
= &lio_queue_status
;
1750 fabric
->tf_ops
.queue_tm_rsp
= &lio_queue_tm_rsp
;
1751 fabric
->tf_ops
.set_fabric_sense_len
= &lio_set_fabric_sense_len
;
1752 fabric
->tf_ops
.get_fabric_sense_len
= &lio_get_fabric_sense_len
;
1754 * Setup function pointers for generic logic in target_core_fabric_configfs.c
1756 fabric
->tf_ops
.fabric_make_wwn
= &lio_target_call_coreaddtiqn
;
1757 fabric
->tf_ops
.fabric_drop_wwn
= &lio_target_call_coredeltiqn
;
1758 fabric
->tf_ops
.fabric_make_tpg
= &lio_target_tiqn_addtpg
;
1759 fabric
->tf_ops
.fabric_drop_tpg
= &lio_target_tiqn_deltpg
;
1760 fabric
->tf_ops
.fabric_post_link
= NULL
;
1761 fabric
->tf_ops
.fabric_pre_unlink
= NULL
;
1762 fabric
->tf_ops
.fabric_make_np
= &lio_target_call_addnptotpg
;
1763 fabric
->tf_ops
.fabric_drop_np
= &lio_target_call_delnpfromtpg
;
1764 fabric
->tf_ops
.fabric_make_nodeacl
= &lio_target_make_nodeacl
;
1765 fabric
->tf_ops
.fabric_drop_nodeacl
= &lio_target_drop_nodeacl
;
1767 * Setup default attribute lists for various fabric->tf_cit_tmpl
1768 * sturct config_item_type's
1770 TF_CIT_TMPL(fabric
)->tfc_discovery_cit
.ct_attrs
= lio_target_discovery_auth_attrs
;
1771 TF_CIT_TMPL(fabric
)->tfc_wwn_cit
.ct_attrs
= lio_target_wwn_attrs
;
1772 TF_CIT_TMPL(fabric
)->tfc_tpg_base_cit
.ct_attrs
= lio_target_tpg_attrs
;
1773 TF_CIT_TMPL(fabric
)->tfc_tpg_attrib_cit
.ct_attrs
= lio_target_tpg_attrib_attrs
;
1774 TF_CIT_TMPL(fabric
)->tfc_tpg_param_cit
.ct_attrs
= lio_target_tpg_param_attrs
;
1775 TF_CIT_TMPL(fabric
)->tfc_tpg_np_base_cit
.ct_attrs
= lio_target_portal_attrs
;
1776 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_base_cit
.ct_attrs
= lio_target_initiator_attrs
;
1777 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_attrib_cit
.ct_attrs
= lio_target_nacl_attrib_attrs
;
1778 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_auth_cit
.ct_attrs
= lio_target_nacl_auth_attrs
;
1779 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_param_cit
.ct_attrs
= lio_target_nacl_param_attrs
;
1781 ret
= target_fabric_configfs_register(fabric
);
1783 pr_err("target_fabric_configfs_register() for"
1784 " LIO-Target failed!\n");
1785 target_fabric_configfs_free(fabric
);
1789 lio_target_fabric_configfs
= fabric
;
1790 pr_debug("LIO_TARGET[0] - Set fabric ->"
1791 " lio_target_fabric_configfs\n");
1796 void iscsi_target_deregister_configfs(void)
1798 if (!lio_target_fabric_configfs
)
1801 * Shutdown discovery sessions and disable discovery TPG
1803 if (iscsit_global
->discovery_tpg
)
1804 iscsit_tpg_disable_portal_group(iscsit_global
->discovery_tpg
, 1);
1806 target_fabric_configfs_deregister(lio_target_fabric_configfs
);
1807 lio_target_fabric_configfs
= NULL
;
1808 pr_debug("LIO_TARGET[0] - Cleared"
1809 " lio_target_fabric_configfs\n");