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 <target/target_core_base.h>
25 #include <target/target_core_transport.h>
26 #include <target/target_core_fabric_ops.h>
27 #include <target/target_core_fabric_configfs.h>
28 #include <target/target_core_fabric_lib.h>
29 #include <target/target_core_device.h>
30 #include <target/target_core_tpg.h>
31 #include <target/target_core_configfs.h>
32 #include <target/configfs_macros.h>
34 #include "iscsi_target_core.h"
35 #include "iscsi_target_parameters.h"
36 #include "iscsi_target_device.h"
37 #include "iscsi_target_erl0.h"
38 #include "iscsi_target_nodeattrib.h"
39 #include "iscsi_target_tpg.h"
40 #include "iscsi_target_util.h"
41 #include "iscsi_target.h"
42 #include "iscsi_target_stat.h"
43 #include "iscsi_target_configfs.h"
45 struct target_fabric_configfs
*lio_target_fabric_configfs
;
47 struct lio_target_configfs_attribute
{
48 struct configfs_attribute attr
;
49 ssize_t (*show
)(void *, char *);
50 ssize_t (*store
)(void *, const char *, size_t);
53 struct iscsi_portal_group
*lio_get_tpg_from_tpg_item(
54 struct config_item
*item
,
55 struct iscsi_tiqn
**tiqn_out
)
57 struct se_portal_group
*se_tpg
= container_of(to_config_group(item
),
58 struct se_portal_group
, tpg_group
);
59 struct iscsi_portal_group
*tpg
=
60 (struct iscsi_portal_group
*)se_tpg
->se_tpg_fabric_ptr
;
64 pr_err("Unable to locate struct iscsi_portal_group "
68 ret
= iscsit_get_tpg(tpg
);
72 *tiqn_out
= tpg
->tpg_tiqn
;
76 /* Start items for lio_target_portal_cit */
78 static ssize_t
lio_target_np_show_sctp(
79 struct se_tpg_np
*se_tpg_np
,
82 struct iscsi_tpg_np
*tpg_np
= container_of(se_tpg_np
,
83 struct iscsi_tpg_np
, se_tpg_np
);
84 struct iscsi_tpg_np
*tpg_np_sctp
;
87 tpg_np_sctp
= iscsit_tpg_locate_child_np(tpg_np
, ISCSI_SCTP_TCP
);
89 rb
= sprintf(page
, "1\n");
91 rb
= sprintf(page
, "0\n");
96 static ssize_t
lio_target_np_store_sctp(
97 struct se_tpg_np
*se_tpg_np
,
102 struct iscsi_portal_group
*tpg
;
103 struct iscsi_tpg_np
*tpg_np
= container_of(se_tpg_np
,
104 struct iscsi_tpg_np
, se_tpg_np
);
105 struct iscsi_tpg_np
*tpg_np_sctp
= NULL
;
110 op
= simple_strtoul(page
, &endptr
, 0);
111 if ((op
!= 1) && (op
!= 0)) {
112 pr_err("Illegal value for tpg_enable: %u\n", op
);
117 pr_err("Unable to locate struct iscsi_np from"
118 " struct iscsi_tpg_np\n");
123 if (iscsit_get_tpg(tpg
) < 0)
128 * Use existing np->np_sockaddr for SCTP network portal reference
130 tpg_np_sctp
= iscsit_tpg_add_network_portal(tpg
, &np
->np_sockaddr
,
131 np
->np_ip
, tpg_np
, ISCSI_SCTP_TCP
);
132 if (!tpg_np_sctp
|| IS_ERR(tpg_np_sctp
))
135 tpg_np_sctp
= iscsit_tpg_locate_child_np(tpg_np
, ISCSI_SCTP_TCP
);
139 ret
= iscsit_tpg_del_network_portal(tpg
, tpg_np_sctp
);
151 TF_NP_BASE_ATTR(lio_target
, sctp
, S_IRUGO
| S_IWUSR
);
153 static struct configfs_attribute
*lio_target_portal_attrs
[] = {
154 &lio_target_np_sctp
.attr
,
158 /* Stop items for lio_target_portal_cit */
160 /* Start items for lio_target_np_cit */
162 #define MAX_PORTAL_LEN 256
164 struct se_tpg_np
*lio_target_call_addnptotpg(
165 struct se_portal_group
*se_tpg
,
166 struct config_group
*group
,
169 struct iscsi_portal_group
*tpg
;
170 struct iscsi_tpg_np
*tpg_np
;
171 char *str
, *str2
, *ip_str
, *port_str
;
172 struct __kernel_sockaddr_storage sockaddr
;
173 struct sockaddr_in
*sock_in
;
174 struct sockaddr_in6
*sock_in6
;
177 char buf
[MAX_PORTAL_LEN
+ 1];
179 if (strlen(name
) > MAX_PORTAL_LEN
) {
180 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
181 (int)strlen(name
), MAX_PORTAL_LEN
);
182 return ERR_PTR(-EOVERFLOW
);
184 memset(buf
, 0, MAX_PORTAL_LEN
+ 1);
185 snprintf(buf
, MAX_PORTAL_LEN
+ 1, "%s", name
);
187 memset(&sockaddr
, 0, sizeof(struct __kernel_sockaddr_storage
));
189 str
= strstr(buf
, "[");
193 str2
= strstr(str
, "]");
195 pr_err("Unable to locate trailing \"]\""
196 " in IPv6 iSCSI network portal address\n");
197 return ERR_PTR(-EINVAL
);
199 str
++; /* Skip over leading "[" */
200 *str2
= '\0'; /* Terminate the IPv6 address */
201 str2
++; /* Skip over the "]" */
202 port_str
= strstr(str2
, ":");
204 pr_err("Unable to locate \":port\""
205 " in IPv6 iSCSI network portal address\n");
206 return ERR_PTR(-EINVAL
);
208 *port_str
= '\0'; /* Terminate string for IP */
209 port_str
++; /* Skip over ":" */
211 ret
= strict_strtoul(port_str
, 0, &port
);
213 pr_err("strict_strtoul() failed for port_str: %d\n", ret
);
216 sock_in6
= (struct sockaddr_in6
*)&sockaddr
;
217 sock_in6
->sin6_family
= AF_INET6
;
218 sock_in6
->sin6_port
= htons((unsigned short)port
);
219 ret
= in6_pton(str
, IPV6_ADDRESS_SPACE
,
220 (void *)&sock_in6
->sin6_addr
.in6_u
, -1, &end
);
222 pr_err("in6_pton returned: %d\n", ret
);
223 return ERR_PTR(-EINVAL
);
226 str
= ip_str
= &buf
[0];
227 port_str
= strstr(ip_str
, ":");
229 pr_err("Unable to locate \":port\""
230 " in IPv4 iSCSI network portal address\n");
231 return ERR_PTR(-EINVAL
);
233 *port_str
= '\0'; /* Terminate string for IP */
234 port_str
++; /* Skip over ":" */
236 ret
= strict_strtoul(port_str
, 0, &port
);
238 pr_err("strict_strtoul() failed for port_str: %d\n", ret
);
241 sock_in
= (struct sockaddr_in
*)&sockaddr
;
242 sock_in
->sin_family
= AF_INET
;
243 sock_in
->sin_port
= htons((unsigned short)port
);
244 sock_in
->sin_addr
.s_addr
= in_aton(ip_str
);
246 tpg
= container_of(se_tpg
, struct iscsi_portal_group
, tpg_se_tpg
);
247 ret
= iscsit_get_tpg(tpg
);
249 return ERR_PTR(-EINVAL
);
251 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
253 config_item_name(&se_tpg
->se_tpg_wwn
->wwn_group
.cg_item
),
256 * Assume ISCSI_TCP by default. Other network portals for other
259 * Traditional iSCSI over SCTP (initial support)
260 * iSER/TCP (TODO, hardware available)
261 * iSER/SCTP (TODO, software emulation with osc-iwarp)
262 * iSER/IB (TODO, hardware available)
264 * can be enabled with atributes under
265 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
268 tpg_np
= iscsit_tpg_add_network_portal(tpg
, &sockaddr
, str
, NULL
,
270 if (IS_ERR(tpg_np
)) {
272 return ERR_CAST(tpg_np
);
274 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
277 return &tpg_np
->se_tpg_np
;
280 static void lio_target_call_delnpfromtpg(
281 struct se_tpg_np
*se_tpg_np
)
283 struct iscsi_portal_group
*tpg
;
284 struct iscsi_tpg_np
*tpg_np
;
285 struct se_portal_group
*se_tpg
;
288 tpg_np
= container_of(se_tpg_np
, struct iscsi_tpg_np
, se_tpg_np
);
290 ret
= iscsit_get_tpg(tpg
);
294 se_tpg
= &tpg
->tpg_se_tpg
;
295 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
296 " PORTAL: %s:%hu\n", config_item_name(&se_tpg
->se_tpg_wwn
->wwn_group
.cg_item
),
297 tpg
->tpgt
, tpg_np
->tpg_np
->np_ip
, tpg_np
->tpg_np
->np_port
);
299 ret
= iscsit_tpg_del_network_portal(tpg
, tpg_np
);
303 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
308 /* End items for lio_target_np_cit */
310 /* Start items for lio_target_nacl_attrib_cit */
312 #define DEF_NACL_ATTRIB(name) \
313 static ssize_t iscsi_nacl_attrib_show_##name( \
314 struct se_node_acl *se_nacl, \
317 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
320 return sprintf(page, "%u\n", ISCSI_NODE_ATTRIB(nacl)->name); \
323 static ssize_t iscsi_nacl_attrib_store_##name( \
324 struct se_node_acl *se_nacl, \
328 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
334 val = simple_strtoul(page, &endptr, 0); \
335 ret = iscsit_na_##name(nacl, val); \
342 #define NACL_ATTR(_name, _mode) TF_NACL_ATTRIB_ATTR(iscsi, _name, _mode);
344 * Define iscsi_node_attrib_s_dataout_timeout
346 DEF_NACL_ATTRIB(dataout_timeout
);
347 NACL_ATTR(dataout_timeout
, S_IRUGO
| S_IWUSR
);
349 * Define iscsi_node_attrib_s_dataout_timeout_retries
351 DEF_NACL_ATTRIB(dataout_timeout_retries
);
352 NACL_ATTR(dataout_timeout_retries
, S_IRUGO
| S_IWUSR
);
354 * Define iscsi_node_attrib_s_default_erl
356 DEF_NACL_ATTRIB(default_erl
);
357 NACL_ATTR(default_erl
, S_IRUGO
| S_IWUSR
);
359 * Define iscsi_node_attrib_s_nopin_timeout
361 DEF_NACL_ATTRIB(nopin_timeout
);
362 NACL_ATTR(nopin_timeout
, S_IRUGO
| S_IWUSR
);
364 * Define iscsi_node_attrib_s_nopin_response_timeout
366 DEF_NACL_ATTRIB(nopin_response_timeout
);
367 NACL_ATTR(nopin_response_timeout
, S_IRUGO
| S_IWUSR
);
369 * Define iscsi_node_attrib_s_random_datain_pdu_offsets
371 DEF_NACL_ATTRIB(random_datain_pdu_offsets
);
372 NACL_ATTR(random_datain_pdu_offsets
, S_IRUGO
| S_IWUSR
);
374 * Define iscsi_node_attrib_s_random_datain_seq_offsets
376 DEF_NACL_ATTRIB(random_datain_seq_offsets
);
377 NACL_ATTR(random_datain_seq_offsets
, S_IRUGO
| S_IWUSR
);
379 * Define iscsi_node_attrib_s_random_r2t_offsets
381 DEF_NACL_ATTRIB(random_r2t_offsets
);
382 NACL_ATTR(random_r2t_offsets
, S_IRUGO
| S_IWUSR
);
384 static struct configfs_attribute
*lio_target_nacl_attrib_attrs
[] = {
385 &iscsi_nacl_attrib_dataout_timeout
.attr
,
386 &iscsi_nacl_attrib_dataout_timeout_retries
.attr
,
387 &iscsi_nacl_attrib_default_erl
.attr
,
388 &iscsi_nacl_attrib_nopin_timeout
.attr
,
389 &iscsi_nacl_attrib_nopin_response_timeout
.attr
,
390 &iscsi_nacl_attrib_random_datain_pdu_offsets
.attr
,
391 &iscsi_nacl_attrib_random_datain_seq_offsets
.attr
,
392 &iscsi_nacl_attrib_random_r2t_offsets
.attr
,
396 /* End items for lio_target_nacl_attrib_cit */
398 /* Start items for lio_target_nacl_auth_cit */
400 #define __DEF_NACL_AUTH_STR(prefix, name, flags) \
401 static ssize_t __iscsi_##prefix##_show_##name( \
402 struct iscsi_node_acl *nacl, \
405 struct iscsi_node_auth *auth = &nacl->node_auth; \
407 if (!capable(CAP_SYS_ADMIN)) \
409 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
412 static ssize_t __iscsi_##prefix##_store_##name( \
413 struct iscsi_node_acl *nacl, \
417 struct iscsi_node_auth *auth = &nacl->node_auth; \
419 if (!capable(CAP_SYS_ADMIN)) \
422 snprintf(auth->name, PAGE_SIZE, "%s", page); \
423 if (!strncmp("NULL", auth->name, 4)) \
424 auth->naf_flags &= ~flags; \
426 auth->naf_flags |= flags; \
428 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
429 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
430 auth->authenticate_target = 1; \
432 auth->authenticate_target = 0; \
437 #define __DEF_NACL_AUTH_INT(prefix, name) \
438 static ssize_t __iscsi_##prefix##_show_##name( \
439 struct iscsi_node_acl *nacl, \
442 struct iscsi_node_auth *auth = &nacl->node_auth; \
444 if (!capable(CAP_SYS_ADMIN)) \
447 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
450 #define DEF_NACL_AUTH_STR(name, flags) \
451 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
452 static ssize_t iscsi_nacl_auth_show_##name( \
453 struct se_node_acl *nacl, \
456 return __iscsi_nacl_auth_show_##name(container_of(nacl, \
457 struct iscsi_node_acl, se_node_acl), page); \
459 static ssize_t iscsi_nacl_auth_store_##name( \
460 struct se_node_acl *nacl, \
464 return __iscsi_nacl_auth_store_##name(container_of(nacl, \
465 struct iscsi_node_acl, se_node_acl), page, count); \
468 #define DEF_NACL_AUTH_INT(name) \
469 __DEF_NACL_AUTH_INT(nacl_auth, name) \
470 static ssize_t iscsi_nacl_auth_show_##name( \
471 struct se_node_acl *nacl, \
474 return __iscsi_nacl_auth_show_##name(container_of(nacl, \
475 struct iscsi_node_acl, se_node_acl), page); \
478 #define AUTH_ATTR(_name, _mode) TF_NACL_AUTH_ATTR(iscsi, _name, _mode);
479 #define AUTH_ATTR_RO(_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name);
482 * One-way authentication userid
484 DEF_NACL_AUTH_STR(userid
, NAF_USERID_SET
);
485 AUTH_ATTR(userid
, S_IRUGO
| S_IWUSR
);
487 * One-way authentication password
489 DEF_NACL_AUTH_STR(password
, NAF_PASSWORD_SET
);
490 AUTH_ATTR(password
, S_IRUGO
| S_IWUSR
);
492 * Enforce mutual authentication
494 DEF_NACL_AUTH_INT(authenticate_target
);
495 AUTH_ATTR_RO(authenticate_target
);
497 * Mutual authentication userid
499 DEF_NACL_AUTH_STR(userid_mutual
, NAF_USERID_IN_SET
);
500 AUTH_ATTR(userid_mutual
, S_IRUGO
| S_IWUSR
);
502 * Mutual authentication password
504 DEF_NACL_AUTH_STR(password_mutual
, NAF_PASSWORD_IN_SET
);
505 AUTH_ATTR(password_mutual
, S_IRUGO
| S_IWUSR
);
507 static struct configfs_attribute
*lio_target_nacl_auth_attrs
[] = {
508 &iscsi_nacl_auth_userid
.attr
,
509 &iscsi_nacl_auth_password
.attr
,
510 &iscsi_nacl_auth_authenticate_target
.attr
,
511 &iscsi_nacl_auth_userid_mutual
.attr
,
512 &iscsi_nacl_auth_password_mutual
.attr
,
516 /* End items for lio_target_nacl_auth_cit */
518 /* Start items for lio_target_nacl_param_cit */
520 #define DEF_NACL_PARAM(name) \
521 static ssize_t iscsi_nacl_param_show_##name( \
522 struct se_node_acl *se_nacl, \
525 struct iscsi_session *sess; \
526 struct se_session *se_sess; \
529 spin_lock_bh(&se_nacl->nacl_sess_lock); \
530 se_sess = se_nacl->nacl_sess; \
532 rb = snprintf(page, PAGE_SIZE, \
533 "No Active iSCSI Session\n"); \
535 sess = se_sess->fabric_sess_ptr; \
536 rb = snprintf(page, PAGE_SIZE, "%u\n", \
537 (u32)sess->sess_ops->name); \
539 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
544 #define NACL_PARAM_ATTR(_name) TF_NACL_PARAM_ATTR_RO(iscsi, _name);
546 DEF_NACL_PARAM(MaxConnections
);
547 NACL_PARAM_ATTR(MaxConnections
);
549 DEF_NACL_PARAM(InitialR2T
);
550 NACL_PARAM_ATTR(InitialR2T
);
552 DEF_NACL_PARAM(ImmediateData
);
553 NACL_PARAM_ATTR(ImmediateData
);
555 DEF_NACL_PARAM(MaxBurstLength
);
556 NACL_PARAM_ATTR(MaxBurstLength
);
558 DEF_NACL_PARAM(FirstBurstLength
);
559 NACL_PARAM_ATTR(FirstBurstLength
);
561 DEF_NACL_PARAM(DefaultTime2Wait
);
562 NACL_PARAM_ATTR(DefaultTime2Wait
);
564 DEF_NACL_PARAM(DefaultTime2Retain
);
565 NACL_PARAM_ATTR(DefaultTime2Retain
);
567 DEF_NACL_PARAM(MaxOutstandingR2T
);
568 NACL_PARAM_ATTR(MaxOutstandingR2T
);
570 DEF_NACL_PARAM(DataPDUInOrder
);
571 NACL_PARAM_ATTR(DataPDUInOrder
);
573 DEF_NACL_PARAM(DataSequenceInOrder
);
574 NACL_PARAM_ATTR(DataSequenceInOrder
);
576 DEF_NACL_PARAM(ErrorRecoveryLevel
);
577 NACL_PARAM_ATTR(ErrorRecoveryLevel
);
579 static struct configfs_attribute
*lio_target_nacl_param_attrs
[] = {
580 &iscsi_nacl_param_MaxConnections
.attr
,
581 &iscsi_nacl_param_InitialR2T
.attr
,
582 &iscsi_nacl_param_ImmediateData
.attr
,
583 &iscsi_nacl_param_MaxBurstLength
.attr
,
584 &iscsi_nacl_param_FirstBurstLength
.attr
,
585 &iscsi_nacl_param_DefaultTime2Wait
.attr
,
586 &iscsi_nacl_param_DefaultTime2Retain
.attr
,
587 &iscsi_nacl_param_MaxOutstandingR2T
.attr
,
588 &iscsi_nacl_param_DataPDUInOrder
.attr
,
589 &iscsi_nacl_param_DataSequenceInOrder
.attr
,
590 &iscsi_nacl_param_ErrorRecoveryLevel
.attr
,
594 /* End items for lio_target_nacl_param_cit */
596 /* Start items for lio_target_acl_cit */
598 static ssize_t
lio_target_nacl_show_info(
599 struct se_node_acl
*se_nacl
,
602 struct iscsi_session
*sess
;
603 struct iscsi_conn
*conn
;
604 struct se_session
*se_sess
;
607 spin_lock_bh(&se_nacl
->nacl_sess_lock
);
608 se_sess
= se_nacl
->nacl_sess
;
610 rb
+= sprintf(page
+rb
, "No active iSCSI Session for Initiator"
611 " Endpoint: %s\n", se_nacl
->initiatorname
);
613 sess
= se_sess
->fabric_sess_ptr
;
615 if (sess
->sess_ops
->InitiatorName
)
616 rb
+= sprintf(page
+rb
, "InitiatorName: %s\n",
617 sess
->sess_ops
->InitiatorName
);
618 if (sess
->sess_ops
->InitiatorAlias
)
619 rb
+= sprintf(page
+rb
, "InitiatorAlias: %s\n",
620 sess
->sess_ops
->InitiatorAlias
);
622 rb
+= sprintf(page
+rb
, "LIO Session ID: %u "
623 "ISID: 0x%02x %02x %02x %02x %02x %02x "
624 "TSIH: %hu ", sess
->sid
,
625 sess
->isid
[0], sess
->isid
[1], sess
->isid
[2],
626 sess
->isid
[3], sess
->isid
[4], sess
->isid
[5],
628 rb
+= sprintf(page
+rb
, "SessionType: %s\n",
629 (sess
->sess_ops
->SessionType
) ?
630 "Discovery" : "Normal");
631 rb
+= sprintf(page
+rb
, "Session State: ");
632 switch (sess
->session_state
) {
633 case TARG_SESS_STATE_FREE
:
634 rb
+= sprintf(page
+rb
, "TARG_SESS_FREE\n");
636 case TARG_SESS_STATE_ACTIVE
:
637 rb
+= sprintf(page
+rb
, "TARG_SESS_STATE_ACTIVE\n");
639 case TARG_SESS_STATE_LOGGED_IN
:
640 rb
+= sprintf(page
+rb
, "TARG_SESS_STATE_LOGGED_IN\n");
642 case TARG_SESS_STATE_FAILED
:
643 rb
+= sprintf(page
+rb
, "TARG_SESS_STATE_FAILED\n");
645 case TARG_SESS_STATE_IN_CONTINUE
:
646 rb
+= sprintf(page
+rb
, "TARG_SESS_STATE_IN_CONTINUE\n");
649 rb
+= sprintf(page
+rb
, "ERROR: Unknown Session"
654 rb
+= sprintf(page
+rb
, "---------------------[iSCSI Session"
655 " Values]-----------------------\n");
656 rb
+= sprintf(page
+rb
, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
657 " : MaxCmdSN : ITT : TTT\n");
658 rb
+= sprintf(page
+rb
, " 0x%08x 0x%08x 0x%08x 0x%08x"
661 (sess
->max_cmd_sn
- sess
->exp_cmd_sn
) + 1,
662 sess
->exp_cmd_sn
, sess
->max_cmd_sn
,
663 sess
->init_task_tag
, sess
->targ_xfer_tag
);
664 rb
+= sprintf(page
+rb
, "----------------------[iSCSI"
665 " Connections]-------------------------\n");
667 spin_lock(&sess
->conn_lock
);
668 list_for_each_entry(conn
, &sess
->sess_conn_list
, conn_list
) {
669 rb
+= sprintf(page
+rb
, "CID: %hu Connection"
670 " State: ", conn
->cid
);
671 switch (conn
->conn_state
) {
672 case TARG_CONN_STATE_FREE
:
673 rb
+= sprintf(page
+rb
,
674 "TARG_CONN_STATE_FREE\n");
676 case TARG_CONN_STATE_XPT_UP
:
677 rb
+= sprintf(page
+rb
,
678 "TARG_CONN_STATE_XPT_UP\n");
680 case TARG_CONN_STATE_IN_LOGIN
:
681 rb
+= sprintf(page
+rb
,
682 "TARG_CONN_STATE_IN_LOGIN\n");
684 case TARG_CONN_STATE_LOGGED_IN
:
685 rb
+= sprintf(page
+rb
,
686 "TARG_CONN_STATE_LOGGED_IN\n");
688 case TARG_CONN_STATE_IN_LOGOUT
:
689 rb
+= sprintf(page
+rb
,
690 "TARG_CONN_STATE_IN_LOGOUT\n");
692 case TARG_CONN_STATE_LOGOUT_REQUESTED
:
693 rb
+= sprintf(page
+rb
,
694 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
696 case TARG_CONN_STATE_CLEANUP_WAIT
:
697 rb
+= sprintf(page
+rb
,
698 "TARG_CONN_STATE_CLEANUP_WAIT\n");
701 rb
+= sprintf(page
+rb
,
702 "ERROR: Unknown Connection State!\n");
706 rb
+= sprintf(page
+rb
, " Address %s %s", conn
->login_ip
,
707 (conn
->network_transport
== ISCSI_TCP
) ?
709 rb
+= sprintf(page
+rb
, " StatSN: 0x%08x\n",
712 spin_unlock(&sess
->conn_lock
);
714 spin_unlock_bh(&se_nacl
->nacl_sess_lock
);
719 TF_NACL_BASE_ATTR_RO(lio_target
, info
);
721 static ssize_t
lio_target_nacl_show_cmdsn_depth(
722 struct se_node_acl
*se_nacl
,
725 return sprintf(page
, "%u\n", se_nacl
->queue_depth
);
728 static ssize_t
lio_target_nacl_store_cmdsn_depth(
729 struct se_node_acl
*se_nacl
,
733 struct se_portal_group
*se_tpg
= se_nacl
->se_tpg
;
734 struct iscsi_portal_group
*tpg
= container_of(se_tpg
,
735 struct iscsi_portal_group
, tpg_se_tpg
);
736 struct config_item
*acl_ci
, *tpg_ci
, *wwn_ci
;
741 cmdsn_depth
= simple_strtoul(page
, &endptr
, 0);
742 if (cmdsn_depth
> TA_DEFAULT_CMDSN_DEPTH_MAX
) {
743 pr_err("Passed cmdsn_depth: %u exceeds"
744 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth
,
745 TA_DEFAULT_CMDSN_DEPTH_MAX
);
748 acl_ci
= &se_nacl
->acl_group
.cg_item
;
750 pr_err("Unable to locatel acl_ci\n");
753 tpg_ci
= &acl_ci
->ci_parent
->ci_group
->cg_item
;
755 pr_err("Unable to locate tpg_ci\n");
758 wwn_ci
= &tpg_ci
->ci_group
->cg_item
;
760 pr_err("Unable to locate config_item wwn_ci\n");
764 if (iscsit_get_tpg(tpg
) < 0)
767 * iscsit_tpg_set_initiator_node_queue_depth() assumes force=1
769 ret
= iscsit_tpg_set_initiator_node_queue_depth(tpg
,
770 config_item_name(acl_ci
), cmdsn_depth
, 1);
772 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
773 "InitiatorName: %s\n", config_item_name(wwn_ci
),
774 config_item_name(tpg_ci
), cmdsn_depth
,
775 config_item_name(acl_ci
));
778 return (!ret
) ? count
: (ssize_t
)ret
;
781 TF_NACL_BASE_ATTR(lio_target
, cmdsn_depth
, S_IRUGO
| S_IWUSR
);
783 static struct configfs_attribute
*lio_target_initiator_attrs
[] = {
784 &lio_target_nacl_info
.attr
,
785 &lio_target_nacl_cmdsn_depth
.attr
,
789 static struct se_node_acl
*lio_tpg_alloc_fabric_acl(
790 struct se_portal_group
*se_tpg
)
792 struct iscsi_node_acl
*acl
;
794 acl
= kzalloc(sizeof(struct iscsi_node_acl
), GFP_KERNEL
);
796 pr_err("Unable to allocate memory for struct iscsi_node_acl\n");
800 return &acl
->se_node_acl
;
803 static struct se_node_acl
*lio_target_make_nodeacl(
804 struct se_portal_group
*se_tpg
,
805 struct config_group
*group
,
808 struct config_group
*stats_cg
;
809 struct iscsi_node_acl
*acl
;
810 struct se_node_acl
*se_nacl_new
, *se_nacl
;
811 struct iscsi_portal_group
*tpg
= container_of(se_tpg
,
812 struct iscsi_portal_group
, tpg_se_tpg
);
815 se_nacl_new
= lio_tpg_alloc_fabric_acl(se_tpg
);
817 return ERR_PTR(-ENOMEM
);
819 acl
= container_of(se_nacl_new
, struct iscsi_node_acl
,
822 cmdsn_depth
= ISCSI_TPG_ATTRIB(tpg
)->default_cmdsn_depth
;
824 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
825 * when converting a NdoeACL from demo mode -> explict
827 se_nacl
= core_tpg_add_initiator_node_acl(se_tpg
, se_nacl_new
,
832 stats_cg
= &acl
->se_node_acl
.acl_fabric_stat_group
;
834 stats_cg
->default_groups
= kzalloc(sizeof(struct config_group
) * 2,
836 if (!stats_cg
->default_groups
) {
837 pr_err("Unable to allocate memory for"
838 " stats_cg->default_groups\n");
839 core_tpg_del_initiator_node_acl(se_tpg
, se_nacl
, 1);
841 return ERR_PTR(-ENOMEM
);
844 stats_cg
->default_groups
[0] = &NODE_STAT_GRPS(acl
)->iscsi_sess_stats_group
;
845 stats_cg
->default_groups
[1] = NULL
;
846 config_group_init_type_name(&NODE_STAT_GRPS(acl
)->iscsi_sess_stats_group
,
847 "iscsi_sess_stats", &iscsi_stat_sess_cit
);
852 static void lio_target_drop_nodeacl(
853 struct se_node_acl
*se_nacl
)
855 struct se_portal_group
*se_tpg
= se_nacl
->se_tpg
;
856 struct iscsi_node_acl
*acl
= container_of(se_nacl
,
857 struct iscsi_node_acl
, se_node_acl
);
858 struct config_item
*df_item
;
859 struct config_group
*stats_cg
;
862 stats_cg
= &acl
->se_node_acl
.acl_fabric_stat_group
;
863 for (i
= 0; stats_cg
->default_groups
[i
]; i
++) {
864 df_item
= &stats_cg
->default_groups
[i
]->cg_item
;
865 stats_cg
->default_groups
[i
] = NULL
;
866 config_item_put(df_item
);
868 kfree(stats_cg
->default_groups
);
870 core_tpg_del_initiator_node_acl(se_tpg
, se_nacl
, 1);
874 /* End items for lio_target_acl_cit */
876 /* Start items for lio_target_tpg_attrib_cit */
878 #define DEF_TPG_ATTRIB(name) \
880 static ssize_t iscsi_tpg_attrib_show_##name( \
881 struct se_portal_group *se_tpg, \
884 struct iscsi_portal_group *tpg = container_of(se_tpg, \
885 struct iscsi_portal_group, tpg_se_tpg); \
888 if (iscsit_get_tpg(tpg) < 0) \
891 rb = sprintf(page, "%u\n", ISCSI_TPG_ATTRIB(tpg)->name); \
892 iscsit_put_tpg(tpg); \
896 static ssize_t iscsi_tpg_attrib_store_##name( \
897 struct se_portal_group *se_tpg, \
901 struct iscsi_portal_group *tpg = container_of(se_tpg, \
902 struct iscsi_portal_group, tpg_se_tpg); \
907 if (iscsit_get_tpg(tpg) < 0) \
910 val = simple_strtoul(page, &endptr, 0); \
911 ret = iscsit_ta_##name(tpg, val); \
915 iscsit_put_tpg(tpg); \
918 iscsit_put_tpg(tpg); \
922 #define TPG_ATTR(_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode);
925 * Define iscsi_tpg_attrib_s_authentication
927 DEF_TPG_ATTRIB(authentication
);
928 TPG_ATTR(authentication
, S_IRUGO
| S_IWUSR
);
930 * Define iscsi_tpg_attrib_s_login_timeout
932 DEF_TPG_ATTRIB(login_timeout
);
933 TPG_ATTR(login_timeout
, S_IRUGO
| S_IWUSR
);
935 * Define iscsi_tpg_attrib_s_netif_timeout
937 DEF_TPG_ATTRIB(netif_timeout
);
938 TPG_ATTR(netif_timeout
, S_IRUGO
| S_IWUSR
);
940 * Define iscsi_tpg_attrib_s_generate_node_acls
942 DEF_TPG_ATTRIB(generate_node_acls
);
943 TPG_ATTR(generate_node_acls
, S_IRUGO
| S_IWUSR
);
945 * Define iscsi_tpg_attrib_s_default_cmdsn_depth
947 DEF_TPG_ATTRIB(default_cmdsn_depth
);
948 TPG_ATTR(default_cmdsn_depth
, S_IRUGO
| S_IWUSR
);
950 Define iscsi_tpg_attrib_s_cache_dynamic_acls
952 DEF_TPG_ATTRIB(cache_dynamic_acls
);
953 TPG_ATTR(cache_dynamic_acls
, S_IRUGO
| S_IWUSR
);
955 * Define iscsi_tpg_attrib_s_demo_mode_write_protect
957 DEF_TPG_ATTRIB(demo_mode_write_protect
);
958 TPG_ATTR(demo_mode_write_protect
, S_IRUGO
| S_IWUSR
);
960 * Define iscsi_tpg_attrib_s_prod_mode_write_protect
962 DEF_TPG_ATTRIB(prod_mode_write_protect
);
963 TPG_ATTR(prod_mode_write_protect
, S_IRUGO
| S_IWUSR
);
965 static struct configfs_attribute
*lio_target_tpg_attrib_attrs
[] = {
966 &iscsi_tpg_attrib_authentication
.attr
,
967 &iscsi_tpg_attrib_login_timeout
.attr
,
968 &iscsi_tpg_attrib_netif_timeout
.attr
,
969 &iscsi_tpg_attrib_generate_node_acls
.attr
,
970 &iscsi_tpg_attrib_default_cmdsn_depth
.attr
,
971 &iscsi_tpg_attrib_cache_dynamic_acls
.attr
,
972 &iscsi_tpg_attrib_demo_mode_write_protect
.attr
,
973 &iscsi_tpg_attrib_prod_mode_write_protect
.attr
,
977 /* End items for lio_target_tpg_attrib_cit */
979 /* Start items for lio_target_tpg_param_cit */
981 #define DEF_TPG_PARAM(name) \
982 static ssize_t iscsi_tpg_param_show_##name( \
983 struct se_portal_group *se_tpg, \
986 struct iscsi_portal_group *tpg = container_of(se_tpg, \
987 struct iscsi_portal_group, tpg_se_tpg); \
988 struct iscsi_param *param; \
991 if (iscsit_get_tpg(tpg) < 0) \
994 param = iscsi_find_param_from_key(__stringify(name), \
997 iscsit_put_tpg(tpg); \
1000 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
1002 iscsit_put_tpg(tpg); \
1005 static ssize_t iscsi_tpg_param_store_##name( \
1006 struct se_portal_group *se_tpg, \
1010 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1011 struct iscsi_portal_group, tpg_se_tpg); \
1015 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
1018 snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
1019 buf[strlen(buf)-1] = '\0'; /* Kill newline */ \
1021 if (iscsit_get_tpg(tpg) < 0) { \
1026 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
1031 iscsit_put_tpg(tpg); \
1035 iscsit_put_tpg(tpg); \
1039 #define TPG_PARAM_ATTR(_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode);
1041 DEF_TPG_PARAM(AuthMethod
);
1042 TPG_PARAM_ATTR(AuthMethod
, S_IRUGO
| S_IWUSR
);
1044 DEF_TPG_PARAM(HeaderDigest
);
1045 TPG_PARAM_ATTR(HeaderDigest
, S_IRUGO
| S_IWUSR
);
1047 DEF_TPG_PARAM(DataDigest
);
1048 TPG_PARAM_ATTR(DataDigest
, S_IRUGO
| S_IWUSR
);
1050 DEF_TPG_PARAM(MaxConnections
);
1051 TPG_PARAM_ATTR(MaxConnections
, S_IRUGO
| S_IWUSR
);
1053 DEF_TPG_PARAM(TargetAlias
);
1054 TPG_PARAM_ATTR(TargetAlias
, S_IRUGO
| S_IWUSR
);
1056 DEF_TPG_PARAM(InitialR2T
);
1057 TPG_PARAM_ATTR(InitialR2T
, S_IRUGO
| S_IWUSR
);
1059 DEF_TPG_PARAM(ImmediateData
);
1060 TPG_PARAM_ATTR(ImmediateData
, S_IRUGO
| S_IWUSR
);
1062 DEF_TPG_PARAM(MaxRecvDataSegmentLength
);
1063 TPG_PARAM_ATTR(MaxRecvDataSegmentLength
, S_IRUGO
| S_IWUSR
);
1065 DEF_TPG_PARAM(MaxBurstLength
);
1066 TPG_PARAM_ATTR(MaxBurstLength
, S_IRUGO
| S_IWUSR
);
1068 DEF_TPG_PARAM(FirstBurstLength
);
1069 TPG_PARAM_ATTR(FirstBurstLength
, S_IRUGO
| S_IWUSR
);
1071 DEF_TPG_PARAM(DefaultTime2Wait
);
1072 TPG_PARAM_ATTR(DefaultTime2Wait
, S_IRUGO
| S_IWUSR
);
1074 DEF_TPG_PARAM(DefaultTime2Retain
);
1075 TPG_PARAM_ATTR(DefaultTime2Retain
, S_IRUGO
| S_IWUSR
);
1077 DEF_TPG_PARAM(MaxOutstandingR2T
);
1078 TPG_PARAM_ATTR(MaxOutstandingR2T
, S_IRUGO
| S_IWUSR
);
1080 DEF_TPG_PARAM(DataPDUInOrder
);
1081 TPG_PARAM_ATTR(DataPDUInOrder
, S_IRUGO
| S_IWUSR
);
1083 DEF_TPG_PARAM(DataSequenceInOrder
);
1084 TPG_PARAM_ATTR(DataSequenceInOrder
, S_IRUGO
| S_IWUSR
);
1086 DEF_TPG_PARAM(ErrorRecoveryLevel
);
1087 TPG_PARAM_ATTR(ErrorRecoveryLevel
, S_IRUGO
| S_IWUSR
);
1089 DEF_TPG_PARAM(IFMarker
);
1090 TPG_PARAM_ATTR(IFMarker
, S_IRUGO
| S_IWUSR
);
1092 DEF_TPG_PARAM(OFMarker
);
1093 TPG_PARAM_ATTR(OFMarker
, S_IRUGO
| S_IWUSR
);
1095 DEF_TPG_PARAM(IFMarkInt
);
1096 TPG_PARAM_ATTR(IFMarkInt
, S_IRUGO
| S_IWUSR
);
1098 DEF_TPG_PARAM(OFMarkInt
);
1099 TPG_PARAM_ATTR(OFMarkInt
, S_IRUGO
| S_IWUSR
);
1101 static struct configfs_attribute
*lio_target_tpg_param_attrs
[] = {
1102 &iscsi_tpg_param_AuthMethod
.attr
,
1103 &iscsi_tpg_param_HeaderDigest
.attr
,
1104 &iscsi_tpg_param_DataDigest
.attr
,
1105 &iscsi_tpg_param_MaxConnections
.attr
,
1106 &iscsi_tpg_param_TargetAlias
.attr
,
1107 &iscsi_tpg_param_InitialR2T
.attr
,
1108 &iscsi_tpg_param_ImmediateData
.attr
,
1109 &iscsi_tpg_param_MaxRecvDataSegmentLength
.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 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
, (void *)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 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 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
= kzalloc(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 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 return cmd
->init_task_tag
;
1505 static int iscsi_get_cmd_state(struct se_cmd
*se_cmd
)
1507 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1509 return cmd
->i_state
;
1512 static int iscsi_is_state_remove(struct se_cmd
*se_cmd
)
1514 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1516 return (cmd
->i_state
== ISTATE_REMOVE
);
1519 static int lio_sess_logged_in(struct se_session
*se_sess
)
1521 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1524 * Called with spin_lock_bh(&tpg_lock); and
1525 * spin_lock(&se_tpg->session_lock); held.
1527 spin_lock(&sess
->conn_lock
);
1528 ret
= (sess
->session_state
!= TARG_SESS_STATE_LOGGED_IN
);
1529 spin_unlock(&sess
->conn_lock
);
1534 static u32
lio_sess_get_index(struct se_session
*se_sess
)
1536 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1538 return sess
->session_index
;
1541 static u32
lio_sess_get_initiator_sid(
1542 struct se_session
*se_sess
,
1546 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1548 * iSCSI Initiator Session Identifier from RFC-3720.
1550 return snprintf(buf
, size
, "%02x%02x%02x%02x%02x%02x",
1551 sess
->isid
[0], sess
->isid
[1], sess
->isid
[2],
1552 sess
->isid
[3], sess
->isid
[4], sess
->isid
[5]);
1555 static int lio_queue_data_in(struct se_cmd
*se_cmd
)
1557 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1559 cmd
->i_state
= ISTATE_SEND_DATAIN
;
1560 iscsit_add_cmd_to_response_queue(cmd
, cmd
->conn
, cmd
->i_state
);
1564 static int lio_write_pending(struct se_cmd
*se_cmd
)
1566 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1568 if (!cmd
->immediate_data
&& !cmd
->unsolicited_data
)
1569 return iscsit_build_r2ts_for_cmd(cmd
, cmd
->conn
, 1);
1574 static int lio_write_pending_status(struct se_cmd
*se_cmd
)
1576 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1579 spin_lock_bh(&cmd
->istate_lock
);
1580 ret
= !(cmd
->cmd_flags
& ICF_GOT_LAST_DATAOUT
);
1581 spin_unlock_bh(&cmd
->istate_lock
);
1586 static int lio_queue_status(struct se_cmd
*se_cmd
)
1588 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1590 cmd
->i_state
= ISTATE_SEND_STATUS
;
1591 iscsit_add_cmd_to_response_queue(cmd
, cmd
->conn
, cmd
->i_state
);
1595 static u16
lio_set_fabric_sense_len(struct se_cmd
*se_cmd
, u32 sense_length
)
1597 unsigned char *buffer
= se_cmd
->sense_buffer
;
1599 * From RFC-3720 10.4.7. Data Segment - Sense and Response Data Segment
1600 * 16-bit SenseLength.
1602 buffer
[0] = ((sense_length
>> 8) & 0xff);
1603 buffer
[1] = (sense_length
& 0xff);
1605 * Return two byte offset into allocated sense_buffer.
1610 static u16
lio_get_fabric_sense_len(void)
1613 * Return two byte offset into allocated sense_buffer.
1618 static int lio_queue_tm_rsp(struct se_cmd
*se_cmd
)
1620 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1622 cmd
->i_state
= ISTATE_SEND_TASKMGTRSP
;
1623 iscsit_add_cmd_to_response_queue(cmd
, cmd
->conn
, cmd
->i_state
);
1627 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group
*se_tpg
)
1629 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1631 return &tpg
->tpg_tiqn
->tiqn
[0];
1634 static u16
lio_tpg_get_tag(struct se_portal_group
*se_tpg
)
1636 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1641 static u32
lio_tpg_get_default_depth(struct se_portal_group
*se_tpg
)
1643 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1645 return ISCSI_TPG_ATTRIB(tpg
)->default_cmdsn_depth
;
1648 static int lio_tpg_check_demo_mode(struct se_portal_group
*se_tpg
)
1650 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1652 return ISCSI_TPG_ATTRIB(tpg
)->generate_node_acls
;
1655 static int lio_tpg_check_demo_mode_cache(struct se_portal_group
*se_tpg
)
1657 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1659 return ISCSI_TPG_ATTRIB(tpg
)->cache_dynamic_acls
;
1662 static int lio_tpg_check_demo_mode_write_protect(
1663 struct se_portal_group
*se_tpg
)
1665 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1667 return ISCSI_TPG_ATTRIB(tpg
)->demo_mode_write_protect
;
1670 static int lio_tpg_check_prod_mode_write_protect(
1671 struct se_portal_group
*se_tpg
)
1673 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1675 return ISCSI_TPG_ATTRIB(tpg
)->prod_mode_write_protect
;
1678 static void lio_tpg_release_fabric_acl(
1679 struct se_portal_group
*se_tpg
,
1680 struct se_node_acl
*se_acl
)
1682 struct iscsi_node_acl
*acl
= container_of(se_acl
,
1683 struct iscsi_node_acl
, se_node_acl
);
1688 * Called with spin_lock_bh(struct se_portal_group->session_lock) held..
1690 * Also, this function calls iscsit_inc_session_usage_count() on the
1691 * struct iscsi_session in question.
1693 static int lio_tpg_shutdown_session(struct se_session
*se_sess
)
1695 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1697 spin_lock(&sess
->conn_lock
);
1698 if (atomic_read(&sess
->session_fall_back_to_erl0
) ||
1699 atomic_read(&sess
->session_logout
) ||
1700 (sess
->time2retain_timer_flags
& ISCSI_TF_EXPIRED
)) {
1701 spin_unlock(&sess
->conn_lock
);
1704 atomic_set(&sess
->session_reinstatement
, 1);
1705 spin_unlock(&sess
->conn_lock
);
1707 iscsit_inc_session_usage_count(sess
);
1708 iscsit_stop_time2retain_timer(sess
);
1714 * Calls iscsit_dec_session_usage_count() as inverse of
1715 * lio_tpg_shutdown_session()
1717 static void lio_tpg_close_session(struct se_session
*se_sess
)
1719 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1721 * If the iSCSI Session for the iSCSI Initiator Node exists,
1722 * forcefully shutdown the iSCSI NEXUS.
1724 iscsit_stop_session(sess
, 1, 1);
1725 iscsit_dec_session_usage_count(sess
);
1726 iscsit_close_session(sess
);
1729 static void lio_tpg_stop_session(
1730 struct se_session
*se_sess
,
1734 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1736 iscsit_stop_session(sess
, sess_sleep
, conn_sleep
);
1739 static void lio_tpg_fall_back_to_erl0(struct se_session
*se_sess
)
1741 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1743 iscsit_fall_back_to_erl0(sess
);
1746 static u32
lio_tpg_get_inst_index(struct se_portal_group
*se_tpg
)
1748 struct iscsi_portal_group
*tpg
= se_tpg
->se_tpg_fabric_ptr
;
1750 return tpg
->tpg_tiqn
->tiqn_index
;
1753 static void lio_set_default_node_attributes(struct se_node_acl
*se_acl
)
1755 struct iscsi_node_acl
*acl
= container_of(se_acl
, struct iscsi_node_acl
,
1758 ISCSI_NODE_ATTRIB(acl
)->nacl
= acl
;
1759 iscsit_set_default_node_attribues(acl
);
1762 static void lio_release_cmd(struct se_cmd
*se_cmd
)
1764 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1766 iscsit_release_cmd(cmd
);
1769 /* End functions for target_core_fabric_ops */
1771 int iscsi_target_register_configfs(void)
1773 struct target_fabric_configfs
*fabric
;
1776 lio_target_fabric_configfs
= NULL
;
1777 fabric
= target_fabric_configfs_init(THIS_MODULE
, "iscsi");
1778 if (IS_ERR(fabric
)) {
1779 pr_err("target_fabric_configfs_init() for"
1780 " LIO-Target failed!\n");
1781 return PTR_ERR(fabric
);
1784 * Setup the fabric API of function pointers used by target_core_mod..
1786 fabric
->tf_ops
.get_fabric_name
= &iscsi_get_fabric_name
;
1787 fabric
->tf_ops
.get_fabric_proto_ident
= &iscsi_get_fabric_proto_ident
;
1788 fabric
->tf_ops
.tpg_get_wwn
= &lio_tpg_get_endpoint_wwn
;
1789 fabric
->tf_ops
.tpg_get_tag
= &lio_tpg_get_tag
;
1790 fabric
->tf_ops
.tpg_get_default_depth
= &lio_tpg_get_default_depth
;
1791 fabric
->tf_ops
.tpg_get_pr_transport_id
= &iscsi_get_pr_transport_id
;
1792 fabric
->tf_ops
.tpg_get_pr_transport_id_len
=
1793 &iscsi_get_pr_transport_id_len
;
1794 fabric
->tf_ops
.tpg_parse_pr_out_transport_id
=
1795 &iscsi_parse_pr_out_transport_id
;
1796 fabric
->tf_ops
.tpg_check_demo_mode
= &lio_tpg_check_demo_mode
;
1797 fabric
->tf_ops
.tpg_check_demo_mode_cache
=
1798 &lio_tpg_check_demo_mode_cache
;
1799 fabric
->tf_ops
.tpg_check_demo_mode_write_protect
=
1800 &lio_tpg_check_demo_mode_write_protect
;
1801 fabric
->tf_ops
.tpg_check_prod_mode_write_protect
=
1802 &lio_tpg_check_prod_mode_write_protect
;
1803 fabric
->tf_ops
.tpg_alloc_fabric_acl
= &lio_tpg_alloc_fabric_acl
;
1804 fabric
->tf_ops
.tpg_release_fabric_acl
= &lio_tpg_release_fabric_acl
;
1805 fabric
->tf_ops
.tpg_get_inst_index
= &lio_tpg_get_inst_index
;
1806 fabric
->tf_ops
.release_cmd
= &lio_release_cmd
;
1807 fabric
->tf_ops
.shutdown_session
= &lio_tpg_shutdown_session
;
1808 fabric
->tf_ops
.close_session
= &lio_tpg_close_session
;
1809 fabric
->tf_ops
.stop_session
= &lio_tpg_stop_session
;
1810 fabric
->tf_ops
.fall_back_to_erl0
= &lio_tpg_fall_back_to_erl0
;
1811 fabric
->tf_ops
.sess_logged_in
= &lio_sess_logged_in
;
1812 fabric
->tf_ops
.sess_get_index
= &lio_sess_get_index
;
1813 fabric
->tf_ops
.sess_get_initiator_sid
= &lio_sess_get_initiator_sid
;
1814 fabric
->tf_ops
.write_pending
= &lio_write_pending
;
1815 fabric
->tf_ops
.write_pending_status
= &lio_write_pending_status
;
1816 fabric
->tf_ops
.set_default_node_attributes
=
1817 &lio_set_default_node_attributes
;
1818 fabric
->tf_ops
.get_task_tag
= &iscsi_get_task_tag
;
1819 fabric
->tf_ops
.get_cmd_state
= &iscsi_get_cmd_state
;
1820 fabric
->tf_ops
.queue_data_in
= &lio_queue_data_in
;
1821 fabric
->tf_ops
.queue_status
= &lio_queue_status
;
1822 fabric
->tf_ops
.queue_tm_rsp
= &lio_queue_tm_rsp
;
1823 fabric
->tf_ops
.set_fabric_sense_len
= &lio_set_fabric_sense_len
;
1824 fabric
->tf_ops
.get_fabric_sense_len
= &lio_get_fabric_sense_len
;
1825 fabric
->tf_ops
.is_state_remove
= &iscsi_is_state_remove
;
1827 * Setup function pointers for generic logic in target_core_fabric_configfs.c
1829 fabric
->tf_ops
.fabric_make_wwn
= &lio_target_call_coreaddtiqn
;
1830 fabric
->tf_ops
.fabric_drop_wwn
= &lio_target_call_coredeltiqn
;
1831 fabric
->tf_ops
.fabric_make_tpg
= &lio_target_tiqn_addtpg
;
1832 fabric
->tf_ops
.fabric_drop_tpg
= &lio_target_tiqn_deltpg
;
1833 fabric
->tf_ops
.fabric_post_link
= NULL
;
1834 fabric
->tf_ops
.fabric_pre_unlink
= NULL
;
1835 fabric
->tf_ops
.fabric_make_np
= &lio_target_call_addnptotpg
;
1836 fabric
->tf_ops
.fabric_drop_np
= &lio_target_call_delnpfromtpg
;
1837 fabric
->tf_ops
.fabric_make_nodeacl
= &lio_target_make_nodeacl
;
1838 fabric
->tf_ops
.fabric_drop_nodeacl
= &lio_target_drop_nodeacl
;
1840 * Setup default attribute lists for various fabric->tf_cit_tmpl
1841 * sturct config_item_type's
1843 TF_CIT_TMPL(fabric
)->tfc_discovery_cit
.ct_attrs
= lio_target_discovery_auth_attrs
;
1844 TF_CIT_TMPL(fabric
)->tfc_wwn_cit
.ct_attrs
= lio_target_wwn_attrs
;
1845 TF_CIT_TMPL(fabric
)->tfc_tpg_base_cit
.ct_attrs
= lio_target_tpg_attrs
;
1846 TF_CIT_TMPL(fabric
)->tfc_tpg_attrib_cit
.ct_attrs
= lio_target_tpg_attrib_attrs
;
1847 TF_CIT_TMPL(fabric
)->tfc_tpg_param_cit
.ct_attrs
= lio_target_tpg_param_attrs
;
1848 TF_CIT_TMPL(fabric
)->tfc_tpg_np_base_cit
.ct_attrs
= lio_target_portal_attrs
;
1849 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_base_cit
.ct_attrs
= lio_target_initiator_attrs
;
1850 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_attrib_cit
.ct_attrs
= lio_target_nacl_attrib_attrs
;
1851 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_auth_cit
.ct_attrs
= lio_target_nacl_auth_attrs
;
1852 TF_CIT_TMPL(fabric
)->tfc_tpg_nacl_param_cit
.ct_attrs
= lio_target_nacl_param_attrs
;
1854 ret
= target_fabric_configfs_register(fabric
);
1856 pr_err("target_fabric_configfs_register() for"
1857 " LIO-Target failed!\n");
1858 target_fabric_configfs_free(fabric
);
1862 lio_target_fabric_configfs
= fabric
;
1863 pr_debug("LIO_TARGET[0] - Set fabric ->"
1864 " lio_target_fabric_configfs\n");
1869 void iscsi_target_deregister_configfs(void)
1871 if (!lio_target_fabric_configfs
)
1874 * Shutdown discovery sessions and disable discovery TPG
1876 if (iscsit_global
->discovery_tpg
)
1877 iscsit_tpg_disable_portal_group(iscsit_global
->discovery_tpg
, 1);
1879 target_fabric_configfs_deregister(lio_target_fabric_configfs
);
1880 lio_target_fabric_configfs
= NULL
;
1881 pr_debug("LIO_TARGET[0] - Cleared"
1882 " lio_target_fabric_configfs\n");