1 /*******************************************************************************
2 * This file contains the configfs implementation for iSCSI Target mode
3 * from the LIO-Target Project.
5 * (c) Copyright 2007-2013 Datera, Inc.
7 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 ****************************************************************************/
20 #include <linux/configfs.h>
21 #include <linux/ctype.h>
22 #include <linux/export.h>
23 #include <linux/inet.h>
24 #include <target/target_core_base.h>
25 #include <target/target_core_fabric.h>
26 #include <target/iscsi/iscsi_transport.h>
28 #include <target/iscsi/iscsi_target_core.h>
29 #include "iscsi_target_parameters.h"
30 #include "iscsi_target_device.h"
31 #include "iscsi_target_erl0.h"
32 #include "iscsi_target_nodeattrib.h"
33 #include "iscsi_target_tpg.h"
34 #include "iscsi_target_util.h"
35 #include "iscsi_target.h"
36 #include <target/iscsi/iscsi_target_stat.h>
39 /* Start items for lio_target_portal_cit */
41 static inline struct iscsi_tpg_np
*to_iscsi_tpg_np(struct config_item
*item
)
43 return container_of(to_tpg_np(item
), struct iscsi_tpg_np
, se_tpg_np
);
46 static ssize_t
lio_target_np_driver_show(struct config_item
*item
, char *page
,
47 enum iscsit_transport_type type
)
49 struct iscsi_tpg_np
*tpg_np
= to_iscsi_tpg_np(item
);
50 struct iscsi_tpg_np
*tpg_np_new
;
53 tpg_np_new
= iscsit_tpg_locate_child_np(tpg_np
, type
);
55 rb
= sprintf(page
, "1\n");
57 rb
= sprintf(page
, "0\n");
62 static ssize_t
lio_target_np_driver_store(struct config_item
*item
,
63 const char *page
, size_t count
, enum iscsit_transport_type type
,
66 struct iscsi_tpg_np
*tpg_np
= to_iscsi_tpg_np(item
);
68 struct iscsi_portal_group
*tpg
;
69 struct iscsi_tpg_np
*tpg_np_new
= NULL
;
73 rc
= kstrtou32(page
, 0, &op
);
76 if ((op
!= 1) && (op
!= 0)) {
77 pr_err("Illegal value for tpg_enable: %u\n", op
);
82 pr_err("Unable to locate struct iscsi_np from"
83 " struct iscsi_tpg_np\n");
88 if (iscsit_get_tpg(tpg
) < 0)
92 if (strlen(mod_name
)) {
93 rc
= request_module(mod_name
);
95 pr_warn("Unable to request_module for %s\n",
101 tpg_np_new
= iscsit_tpg_add_network_portal(tpg
,
102 &np
->np_sockaddr
, tpg_np
, type
);
103 if (IS_ERR(tpg_np_new
))
106 tpg_np_new
= iscsit_tpg_locate_child_np(tpg_np
, type
);
108 rc
= iscsit_tpg_del_network_portal(tpg
, tpg_np_new
);
121 static ssize_t
lio_target_np_iser_show(struct config_item
*item
, char *page
)
123 return lio_target_np_driver_show(item
, page
, ISCSI_INFINIBAND
);
126 static ssize_t
lio_target_np_iser_store(struct config_item
*item
,
127 const char *page
, size_t count
)
129 return lio_target_np_driver_store(item
, page
, count
,
130 ISCSI_INFINIBAND
, "ib_isert");
132 CONFIGFS_ATTR(lio_target_np_
, iser
);
134 static ssize_t
lio_target_np_cxgbit_show(struct config_item
*item
, char *page
)
136 return lio_target_np_driver_show(item
, page
, ISCSI_CXGBIT
);
139 static ssize_t
lio_target_np_cxgbit_store(struct config_item
*item
,
140 const char *page
, size_t count
)
142 return lio_target_np_driver_store(item
, page
, count
,
143 ISCSI_CXGBIT
, "cxgbit");
145 CONFIGFS_ATTR(lio_target_np_
, cxgbit
);
147 static struct configfs_attribute
*lio_target_portal_attrs
[] = {
148 &lio_target_np_attr_iser
,
149 &lio_target_np_attr_cxgbit
,
153 /* Stop items for lio_target_portal_cit */
155 /* Start items for lio_target_np_cit */
157 #define MAX_PORTAL_LEN 256
159 static struct se_tpg_np
*lio_target_call_addnptotpg(
160 struct se_portal_group
*se_tpg
,
161 struct config_group
*group
,
164 struct iscsi_portal_group
*tpg
;
165 struct iscsi_tpg_np
*tpg_np
;
166 char *str
, *str2
, *ip_str
, *port_str
;
167 struct sockaddr_storage sockaddr
;
168 struct sockaddr_in
*sock_in
;
169 struct sockaddr_in6
*sock_in6
;
172 char buf
[MAX_PORTAL_LEN
+ 1];
174 if (strlen(name
) > MAX_PORTAL_LEN
) {
175 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
176 (int)strlen(name
), MAX_PORTAL_LEN
);
177 return ERR_PTR(-EOVERFLOW
);
179 memset(buf
, 0, MAX_PORTAL_LEN
+ 1);
180 snprintf(buf
, MAX_PORTAL_LEN
+ 1, "%s", name
);
182 memset(&sockaddr
, 0, sizeof(struct sockaddr_storage
));
184 str
= strstr(buf
, "[");
188 str2
= strstr(str
, "]");
190 pr_err("Unable to locate trailing \"]\""
191 " in IPv6 iSCSI network portal address\n");
192 return ERR_PTR(-EINVAL
);
194 str
++; /* Skip over leading "[" */
195 *str2
= '\0'; /* Terminate the unbracketed IPv6 address */
196 str2
++; /* Skip over the \0 */
197 port_str
= strstr(str2
, ":");
199 pr_err("Unable to locate \":port\""
200 " in IPv6 iSCSI network portal address\n");
201 return ERR_PTR(-EINVAL
);
203 *port_str
= '\0'; /* Terminate string for IP */
204 port_str
++; /* Skip over ":" */
206 ret
= kstrtoul(port_str
, 0, &port
);
208 pr_err("kstrtoul() failed for port_str: %d\n", ret
);
211 sock_in6
= (struct sockaddr_in6
*)&sockaddr
;
212 sock_in6
->sin6_family
= AF_INET6
;
213 sock_in6
->sin6_port
= htons((unsigned short)port
);
214 ret
= in6_pton(str
, -1,
215 (void *)&sock_in6
->sin6_addr
.in6_u
, -1, &end
);
217 pr_err("in6_pton returned: %d\n", ret
);
218 return ERR_PTR(-EINVAL
);
221 str
= ip_str
= &buf
[0];
222 port_str
= strstr(ip_str
, ":");
224 pr_err("Unable to locate \":port\""
225 " in IPv4 iSCSI network portal address\n");
226 return ERR_PTR(-EINVAL
);
228 *port_str
= '\0'; /* Terminate string for IP */
229 port_str
++; /* Skip over ":" */
231 ret
= kstrtoul(port_str
, 0, &port
);
233 pr_err("kstrtoul() failed for port_str: %d\n", ret
);
236 sock_in
= (struct sockaddr_in
*)&sockaddr
;
237 sock_in
->sin_family
= AF_INET
;
238 sock_in
->sin_port
= htons((unsigned short)port
);
239 sock_in
->sin_addr
.s_addr
= in_aton(ip_str
);
241 tpg
= container_of(se_tpg
, struct iscsi_portal_group
, tpg_se_tpg
);
242 ret
= iscsit_get_tpg(tpg
);
244 return ERR_PTR(-EINVAL
);
246 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
248 config_item_name(&se_tpg
->se_tpg_wwn
->wwn_group
.cg_item
),
251 * Assume ISCSI_TCP by default. Other network portals for other
254 * Traditional iSCSI over SCTP (initial support)
255 * iSER/TCP (TODO, hardware available)
256 * iSER/SCTP (TODO, software emulation with osc-iwarp)
257 * iSER/IB (TODO, hardware available)
259 * can be enabled with attributes under
260 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
263 tpg_np
= iscsit_tpg_add_network_portal(tpg
, &sockaddr
, NULL
,
265 if (IS_ERR(tpg_np
)) {
267 return ERR_CAST(tpg_np
);
269 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
272 return &tpg_np
->se_tpg_np
;
275 static void lio_target_call_delnpfromtpg(
276 struct se_tpg_np
*se_tpg_np
)
278 struct iscsi_portal_group
*tpg
;
279 struct iscsi_tpg_np
*tpg_np
;
280 struct se_portal_group
*se_tpg
;
283 tpg_np
= container_of(se_tpg_np
, struct iscsi_tpg_np
, se_tpg_np
);
285 ret
= iscsit_get_tpg(tpg
);
289 se_tpg
= &tpg
->tpg_se_tpg
;
290 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
291 " PORTAL: %pISpc\n", config_item_name(&se_tpg
->se_tpg_wwn
->wwn_group
.cg_item
),
292 tpg
->tpgt
, &tpg_np
->tpg_np
->np_sockaddr
);
294 ret
= iscsit_tpg_del_network_portal(tpg
, tpg_np
);
298 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
303 /* End items for lio_target_np_cit */
305 /* Start items for lio_target_nacl_attrib_cit */
307 #define ISCSI_NACL_ATTR(name) \
308 static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
311 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
312 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
315 return sprintf(page, "%u\n", nacl->node_attrib.name); \
318 static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
319 const char *page, size_t count) \
321 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
322 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
327 ret = kstrtou32(page, 0, &val); \
330 ret = iscsit_na_##name(nacl, val); \
337 CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
339 ISCSI_NACL_ATTR(dataout_timeout
);
340 ISCSI_NACL_ATTR(dataout_timeout_retries
);
341 ISCSI_NACL_ATTR(default_erl
);
342 ISCSI_NACL_ATTR(nopin_timeout
);
343 ISCSI_NACL_ATTR(nopin_response_timeout
);
344 ISCSI_NACL_ATTR(random_datain_pdu_offsets
);
345 ISCSI_NACL_ATTR(random_datain_seq_offsets
);
346 ISCSI_NACL_ATTR(random_r2t_offsets
);
348 static struct configfs_attribute
*lio_target_nacl_attrib_attrs
[] = {
349 &iscsi_nacl_attrib_attr_dataout_timeout
,
350 &iscsi_nacl_attrib_attr_dataout_timeout_retries
,
351 &iscsi_nacl_attrib_attr_default_erl
,
352 &iscsi_nacl_attrib_attr_nopin_timeout
,
353 &iscsi_nacl_attrib_attr_nopin_response_timeout
,
354 &iscsi_nacl_attrib_attr_random_datain_pdu_offsets
,
355 &iscsi_nacl_attrib_attr_random_datain_seq_offsets
,
356 &iscsi_nacl_attrib_attr_random_r2t_offsets
,
360 /* End items for lio_target_nacl_attrib_cit */
362 /* Start items for lio_target_nacl_auth_cit */
364 #define __DEF_NACL_AUTH_STR(prefix, name, flags) \
365 static ssize_t __iscsi_##prefix##_##name##_show( \
366 struct iscsi_node_acl *nacl, \
369 struct iscsi_node_auth *auth = &nacl->node_auth; \
371 if (!capable(CAP_SYS_ADMIN)) \
373 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
376 static ssize_t __iscsi_##prefix##_##name##_store( \
377 struct iscsi_node_acl *nacl, \
381 struct iscsi_node_auth *auth = &nacl->node_auth; \
383 if (!capable(CAP_SYS_ADMIN)) \
385 if (count >= sizeof(auth->name)) \
387 snprintf(auth->name, sizeof(auth->name), "%s", page); \
388 if (!strncmp("NULL", auth->name, 4)) \
389 auth->naf_flags &= ~flags; \
391 auth->naf_flags |= flags; \
393 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
394 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
395 auth->authenticate_target = 1; \
397 auth->authenticate_target = 0; \
402 #define DEF_NACL_AUTH_STR(name, flags) \
403 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
404 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
407 struct se_node_acl *nacl = auth_to_nacl(item); \
408 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
409 struct iscsi_node_acl, se_node_acl), page); \
411 static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \
412 const char *page, size_t count) \
414 struct se_node_acl *nacl = auth_to_nacl(item); \
415 return __iscsi_nacl_auth_##name##_store(container_of(nacl, \
416 struct iscsi_node_acl, se_node_acl), page, count); \
419 CONFIGFS_ATTR(iscsi_nacl_auth_, name)
422 * One-way authentication userid
424 DEF_NACL_AUTH_STR(userid
, NAF_USERID_SET
);
425 DEF_NACL_AUTH_STR(password
, NAF_PASSWORD_SET
);
426 DEF_NACL_AUTH_STR(userid_mutual
, NAF_USERID_IN_SET
);
427 DEF_NACL_AUTH_STR(password_mutual
, NAF_PASSWORD_IN_SET
);
429 #define __DEF_NACL_AUTH_INT(prefix, name) \
430 static ssize_t __iscsi_##prefix##_##name##_show( \
431 struct iscsi_node_acl *nacl, \
434 struct iscsi_node_auth *auth = &nacl->node_auth; \
436 if (!capable(CAP_SYS_ADMIN)) \
439 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
442 #define DEF_NACL_AUTH_INT(name) \
443 __DEF_NACL_AUTH_INT(nacl_auth, name) \
444 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
447 struct se_node_acl *nacl = auth_to_nacl(item); \
448 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
449 struct iscsi_node_acl, se_node_acl), page); \
452 CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
454 DEF_NACL_AUTH_INT(authenticate_target
);
456 static struct configfs_attribute
*lio_target_nacl_auth_attrs
[] = {
457 &iscsi_nacl_auth_attr_userid
,
458 &iscsi_nacl_auth_attr_password
,
459 &iscsi_nacl_auth_attr_authenticate_target
,
460 &iscsi_nacl_auth_attr_userid_mutual
,
461 &iscsi_nacl_auth_attr_password_mutual
,
465 /* End items for lio_target_nacl_auth_cit */
467 /* Start items for lio_target_nacl_param_cit */
469 #define ISCSI_NACL_PARAM(name) \
470 static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \
473 struct se_node_acl *se_nacl = param_to_nacl(item); \
474 struct iscsi_session *sess; \
475 struct se_session *se_sess; \
478 spin_lock_bh(&se_nacl->nacl_sess_lock); \
479 se_sess = se_nacl->nacl_sess; \
481 rb = snprintf(page, PAGE_SIZE, \
482 "No Active iSCSI Session\n"); \
484 sess = se_sess->fabric_sess_ptr; \
485 rb = snprintf(page, PAGE_SIZE, "%u\n", \
486 (u32)sess->sess_ops->name); \
488 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
493 CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
495 ISCSI_NACL_PARAM(MaxConnections
);
496 ISCSI_NACL_PARAM(InitialR2T
);
497 ISCSI_NACL_PARAM(ImmediateData
);
498 ISCSI_NACL_PARAM(MaxBurstLength
);
499 ISCSI_NACL_PARAM(FirstBurstLength
);
500 ISCSI_NACL_PARAM(DefaultTime2Wait
);
501 ISCSI_NACL_PARAM(DefaultTime2Retain
);
502 ISCSI_NACL_PARAM(MaxOutstandingR2T
);
503 ISCSI_NACL_PARAM(DataPDUInOrder
);
504 ISCSI_NACL_PARAM(DataSequenceInOrder
);
505 ISCSI_NACL_PARAM(ErrorRecoveryLevel
);
507 static struct configfs_attribute
*lio_target_nacl_param_attrs
[] = {
508 &iscsi_nacl_param_attr_MaxConnections
,
509 &iscsi_nacl_param_attr_InitialR2T
,
510 &iscsi_nacl_param_attr_ImmediateData
,
511 &iscsi_nacl_param_attr_MaxBurstLength
,
512 &iscsi_nacl_param_attr_FirstBurstLength
,
513 &iscsi_nacl_param_attr_DefaultTime2Wait
,
514 &iscsi_nacl_param_attr_DefaultTime2Retain
,
515 &iscsi_nacl_param_attr_MaxOutstandingR2T
,
516 &iscsi_nacl_param_attr_DataPDUInOrder
,
517 &iscsi_nacl_param_attr_DataSequenceInOrder
,
518 &iscsi_nacl_param_attr_ErrorRecoveryLevel
,
522 /* End items for lio_target_nacl_param_cit */
524 /* Start items for lio_target_acl_cit */
526 static ssize_t
lio_target_nacl_info_show(struct config_item
*item
, char *page
)
528 struct se_node_acl
*se_nacl
= acl_to_nacl(item
);
529 struct iscsi_session
*sess
;
530 struct iscsi_conn
*conn
;
531 struct se_session
*se_sess
;
535 spin_lock_bh(&se_nacl
->nacl_sess_lock
);
536 se_sess
= se_nacl
->nacl_sess
;
538 rb
+= sprintf(page
+rb
, "No active iSCSI Session for Initiator"
539 " Endpoint: %s\n", se_nacl
->initiatorname
);
541 sess
= se_sess
->fabric_sess_ptr
;
543 rb
+= sprintf(page
+rb
, "InitiatorName: %s\n",
544 sess
->sess_ops
->InitiatorName
);
545 rb
+= sprintf(page
+rb
, "InitiatorAlias: %s\n",
546 sess
->sess_ops
->InitiatorAlias
);
548 rb
+= sprintf(page
+rb
,
549 "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ",
550 sess
->sid
, sess
->isid
, sess
->tsih
);
551 rb
+= sprintf(page
+rb
, "SessionType: %s\n",
552 (sess
->sess_ops
->SessionType
) ?
553 "Discovery" : "Normal");
554 rb
+= sprintf(page
+rb
, "Session State: ");
555 switch (sess
->session_state
) {
556 case TARG_SESS_STATE_FREE
:
557 rb
+= sprintf(page
+rb
, "TARG_SESS_FREE\n");
559 case TARG_SESS_STATE_ACTIVE
:
560 rb
+= sprintf(page
+rb
, "TARG_SESS_STATE_ACTIVE\n");
562 case TARG_SESS_STATE_LOGGED_IN
:
563 rb
+= sprintf(page
+rb
, "TARG_SESS_STATE_LOGGED_IN\n");
565 case TARG_SESS_STATE_FAILED
:
566 rb
+= sprintf(page
+rb
, "TARG_SESS_STATE_FAILED\n");
568 case TARG_SESS_STATE_IN_CONTINUE
:
569 rb
+= sprintf(page
+rb
, "TARG_SESS_STATE_IN_CONTINUE\n");
572 rb
+= sprintf(page
+rb
, "ERROR: Unknown Session"
577 rb
+= sprintf(page
+rb
, "---------------------[iSCSI Session"
578 " Values]-----------------------\n");
579 rb
+= sprintf(page
+rb
, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
580 " : MaxCmdSN : ITT : TTT\n");
581 max_cmd_sn
= (u32
) atomic_read(&sess
->max_cmd_sn
);
582 rb
+= sprintf(page
+rb
, " 0x%08x 0x%08x 0x%08x 0x%08x"
585 (max_cmd_sn
- sess
->exp_cmd_sn
) + 1,
586 sess
->exp_cmd_sn
, max_cmd_sn
,
587 sess
->init_task_tag
, sess
->targ_xfer_tag
);
588 rb
+= sprintf(page
+rb
, "----------------------[iSCSI"
589 " Connections]-------------------------\n");
591 spin_lock(&sess
->conn_lock
);
592 list_for_each_entry(conn
, &sess
->sess_conn_list
, conn_list
) {
593 rb
+= sprintf(page
+rb
, "CID: %hu Connection"
594 " State: ", conn
->cid
);
595 switch (conn
->conn_state
) {
596 case TARG_CONN_STATE_FREE
:
597 rb
+= sprintf(page
+rb
,
598 "TARG_CONN_STATE_FREE\n");
600 case TARG_CONN_STATE_XPT_UP
:
601 rb
+= sprintf(page
+rb
,
602 "TARG_CONN_STATE_XPT_UP\n");
604 case TARG_CONN_STATE_IN_LOGIN
:
605 rb
+= sprintf(page
+rb
,
606 "TARG_CONN_STATE_IN_LOGIN\n");
608 case TARG_CONN_STATE_LOGGED_IN
:
609 rb
+= sprintf(page
+rb
,
610 "TARG_CONN_STATE_LOGGED_IN\n");
612 case TARG_CONN_STATE_IN_LOGOUT
:
613 rb
+= sprintf(page
+rb
,
614 "TARG_CONN_STATE_IN_LOGOUT\n");
616 case TARG_CONN_STATE_LOGOUT_REQUESTED
:
617 rb
+= sprintf(page
+rb
,
618 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
620 case TARG_CONN_STATE_CLEANUP_WAIT
:
621 rb
+= sprintf(page
+rb
,
622 "TARG_CONN_STATE_CLEANUP_WAIT\n");
625 rb
+= sprintf(page
+rb
,
626 "ERROR: Unknown Connection State!\n");
630 rb
+= sprintf(page
+rb
, " Address %pISc %s", &conn
->login_sockaddr
,
631 (conn
->network_transport
== ISCSI_TCP
) ?
633 rb
+= sprintf(page
+rb
, " StatSN: 0x%08x\n",
636 spin_unlock(&sess
->conn_lock
);
638 spin_unlock_bh(&se_nacl
->nacl_sess_lock
);
643 static ssize_t
lio_target_nacl_cmdsn_depth_show(struct config_item
*item
,
646 return sprintf(page
, "%u\n", acl_to_nacl(item
)->queue_depth
);
649 static ssize_t
lio_target_nacl_cmdsn_depth_store(struct config_item
*item
,
650 const char *page
, size_t count
)
652 struct se_node_acl
*se_nacl
= acl_to_nacl(item
);
653 struct se_portal_group
*se_tpg
= se_nacl
->se_tpg
;
654 struct iscsi_portal_group
*tpg
= container_of(se_tpg
,
655 struct iscsi_portal_group
, tpg_se_tpg
);
656 struct config_item
*acl_ci
, *tpg_ci
, *wwn_ci
;
660 ret
= kstrtou32(page
, 0, &cmdsn_depth
);
663 if (cmdsn_depth
> TA_DEFAULT_CMDSN_DEPTH_MAX
) {
664 pr_err("Passed cmdsn_depth: %u exceeds"
665 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth
,
666 TA_DEFAULT_CMDSN_DEPTH_MAX
);
669 acl_ci
= &se_nacl
->acl_group
.cg_item
;
671 pr_err("Unable to locatel acl_ci\n");
674 tpg_ci
= &acl_ci
->ci_parent
->ci_group
->cg_item
;
676 pr_err("Unable to locate tpg_ci\n");
679 wwn_ci
= &tpg_ci
->ci_group
->cg_item
;
681 pr_err("Unable to locate config_item wwn_ci\n");
685 if (iscsit_get_tpg(tpg
) < 0)
688 ret
= core_tpg_set_initiator_node_queue_depth(se_nacl
, cmdsn_depth
);
690 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
691 "InitiatorName: %s\n", config_item_name(wwn_ci
),
692 config_item_name(tpg_ci
), cmdsn_depth
,
693 config_item_name(acl_ci
));
696 return (!ret
) ? count
: (ssize_t
)ret
;
699 static ssize_t
lio_target_nacl_tag_show(struct config_item
*item
, char *page
)
701 return snprintf(page
, PAGE_SIZE
, "%s", acl_to_nacl(item
)->acl_tag
);
704 static ssize_t
lio_target_nacl_tag_store(struct config_item
*item
,
705 const char *page
, size_t count
)
707 struct se_node_acl
*se_nacl
= acl_to_nacl(item
);
710 ret
= core_tpg_set_initiator_node_tag(se_nacl
->se_tpg
, se_nacl
, page
);
717 CONFIGFS_ATTR_RO(lio_target_nacl_
, info
);
718 CONFIGFS_ATTR(lio_target_nacl_
, cmdsn_depth
);
719 CONFIGFS_ATTR(lio_target_nacl_
, tag
);
721 static struct configfs_attribute
*lio_target_initiator_attrs
[] = {
722 &lio_target_nacl_attr_info
,
723 &lio_target_nacl_attr_cmdsn_depth
,
724 &lio_target_nacl_attr_tag
,
728 static int lio_target_init_nodeacl(struct se_node_acl
*se_nacl
,
731 struct iscsi_node_acl
*acl
=
732 container_of(se_nacl
, struct iscsi_node_acl
, se_node_acl
);
734 config_group_init_type_name(&acl
->node_stat_grps
.iscsi_sess_stats_group
,
735 "iscsi_sess_stats", &iscsi_stat_sess_cit
);
736 configfs_add_default_group(&acl
->node_stat_grps
.iscsi_sess_stats_group
,
737 &se_nacl
->acl_fabric_stat_group
);
741 /* End items for lio_target_acl_cit */
743 /* Start items for lio_target_tpg_attrib_cit */
745 #define DEF_TPG_ATTRIB(name) \
747 static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \
750 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
751 struct iscsi_portal_group *tpg = container_of(se_tpg, \
752 struct iscsi_portal_group, tpg_se_tpg); \
755 if (iscsit_get_tpg(tpg) < 0) \
758 rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \
759 iscsit_put_tpg(tpg); \
763 static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
764 const char *page, size_t count) \
766 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
767 struct iscsi_portal_group *tpg = container_of(se_tpg, \
768 struct iscsi_portal_group, tpg_se_tpg); \
772 if (iscsit_get_tpg(tpg) < 0) \
775 ret = kstrtou32(page, 0, &val); \
778 ret = iscsit_ta_##name(tpg, val); \
782 iscsit_put_tpg(tpg); \
785 iscsit_put_tpg(tpg); \
788 CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
790 DEF_TPG_ATTRIB(authentication
);
791 DEF_TPG_ATTRIB(login_timeout
);
792 DEF_TPG_ATTRIB(netif_timeout
);
793 DEF_TPG_ATTRIB(generate_node_acls
);
794 DEF_TPG_ATTRIB(default_cmdsn_depth
);
795 DEF_TPG_ATTRIB(cache_dynamic_acls
);
796 DEF_TPG_ATTRIB(demo_mode_write_protect
);
797 DEF_TPG_ATTRIB(prod_mode_write_protect
);
798 DEF_TPG_ATTRIB(demo_mode_discovery
);
799 DEF_TPG_ATTRIB(default_erl
);
800 DEF_TPG_ATTRIB(t10_pi
);
801 DEF_TPG_ATTRIB(fabric_prot_type
);
802 DEF_TPG_ATTRIB(tpg_enabled_sendtargets
);
804 static struct configfs_attribute
*lio_target_tpg_attrib_attrs
[] = {
805 &iscsi_tpg_attrib_attr_authentication
,
806 &iscsi_tpg_attrib_attr_login_timeout
,
807 &iscsi_tpg_attrib_attr_netif_timeout
,
808 &iscsi_tpg_attrib_attr_generate_node_acls
,
809 &iscsi_tpg_attrib_attr_default_cmdsn_depth
,
810 &iscsi_tpg_attrib_attr_cache_dynamic_acls
,
811 &iscsi_tpg_attrib_attr_demo_mode_write_protect
,
812 &iscsi_tpg_attrib_attr_prod_mode_write_protect
,
813 &iscsi_tpg_attrib_attr_demo_mode_discovery
,
814 &iscsi_tpg_attrib_attr_default_erl
,
815 &iscsi_tpg_attrib_attr_t10_pi
,
816 &iscsi_tpg_attrib_attr_fabric_prot_type
,
817 &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets
,
821 /* End items for lio_target_tpg_attrib_cit */
823 /* Start items for lio_target_tpg_auth_cit */
825 #define __DEF_TPG_AUTH_STR(prefix, name, flags) \
826 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
829 struct iscsi_portal_group *tpg = container_of(se_tpg, \
830 struct iscsi_portal_group, tpg_se_tpg); \
831 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
833 if (!capable(CAP_SYS_ADMIN)) \
836 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
839 static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
840 const char *page, size_t count) \
842 struct iscsi_portal_group *tpg = container_of(se_tpg, \
843 struct iscsi_portal_group, tpg_se_tpg); \
844 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
846 if (!capable(CAP_SYS_ADMIN)) \
849 snprintf(auth->name, sizeof(auth->name), "%s", page); \
850 if (!(strncmp("NULL", auth->name, 4))) \
851 auth->naf_flags &= ~flags; \
853 auth->naf_flags |= flags; \
855 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
856 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
857 auth->authenticate_target = 1; \
859 auth->authenticate_target = 0; \
864 #define DEF_TPG_AUTH_STR(name, flags) \
865 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
866 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
869 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
872 static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \
873 const char *page, size_t count) \
875 return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
878 CONFIGFS_ATTR(iscsi_tpg_auth_, name);
881 DEF_TPG_AUTH_STR(userid
, NAF_USERID_SET
);
882 DEF_TPG_AUTH_STR(password
, NAF_PASSWORD_SET
);
883 DEF_TPG_AUTH_STR(userid_mutual
, NAF_USERID_IN_SET
);
884 DEF_TPG_AUTH_STR(password_mutual
, NAF_PASSWORD_IN_SET
);
886 #define __DEF_TPG_AUTH_INT(prefix, name) \
887 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
890 struct iscsi_portal_group *tpg = container_of(se_tpg, \
891 struct iscsi_portal_group, tpg_se_tpg); \
892 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
894 if (!capable(CAP_SYS_ADMIN)) \
897 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
900 #define DEF_TPG_AUTH_INT(name) \
901 __DEF_TPG_AUTH_INT(tpg_auth, name) \
902 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
905 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
907 CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
909 DEF_TPG_AUTH_INT(authenticate_target
);
911 static struct configfs_attribute
*lio_target_tpg_auth_attrs
[] = {
912 &iscsi_tpg_auth_attr_userid
,
913 &iscsi_tpg_auth_attr_password
,
914 &iscsi_tpg_auth_attr_authenticate_target
,
915 &iscsi_tpg_auth_attr_userid_mutual
,
916 &iscsi_tpg_auth_attr_password_mutual
,
920 /* End items for lio_target_tpg_auth_cit */
922 /* Start items for lio_target_tpg_param_cit */
924 #define DEF_TPG_PARAM(name) \
925 static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \
928 struct se_portal_group *se_tpg = param_to_tpg(item); \
929 struct iscsi_portal_group *tpg = container_of(se_tpg, \
930 struct iscsi_portal_group, tpg_se_tpg); \
931 struct iscsi_param *param; \
934 if (iscsit_get_tpg(tpg) < 0) \
937 param = iscsi_find_param_from_key(__stringify(name), \
940 iscsit_put_tpg(tpg); \
943 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
945 iscsit_put_tpg(tpg); \
948 static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
949 const char *page, size_t count) \
951 struct se_portal_group *se_tpg = param_to_tpg(item); \
952 struct iscsi_portal_group *tpg = container_of(se_tpg, \
953 struct iscsi_portal_group, tpg_se_tpg); \
957 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
960 len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
961 if (isspace(buf[len-1])) \
962 buf[len-1] = '\0'; /* Kill newline */ \
964 if (iscsit_get_tpg(tpg) < 0) { \
969 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
974 iscsit_put_tpg(tpg); \
978 iscsit_put_tpg(tpg); \
981 CONFIGFS_ATTR(iscsi_tpg_param_, name)
983 DEF_TPG_PARAM(AuthMethod
);
984 DEF_TPG_PARAM(HeaderDigest
);
985 DEF_TPG_PARAM(DataDigest
);
986 DEF_TPG_PARAM(MaxConnections
);
987 DEF_TPG_PARAM(TargetAlias
);
988 DEF_TPG_PARAM(InitialR2T
);
989 DEF_TPG_PARAM(ImmediateData
);
990 DEF_TPG_PARAM(MaxRecvDataSegmentLength
);
991 DEF_TPG_PARAM(MaxXmitDataSegmentLength
);
992 DEF_TPG_PARAM(MaxBurstLength
);
993 DEF_TPG_PARAM(FirstBurstLength
);
994 DEF_TPG_PARAM(DefaultTime2Wait
);
995 DEF_TPG_PARAM(DefaultTime2Retain
);
996 DEF_TPG_PARAM(MaxOutstandingR2T
);
997 DEF_TPG_PARAM(DataPDUInOrder
);
998 DEF_TPG_PARAM(DataSequenceInOrder
);
999 DEF_TPG_PARAM(ErrorRecoveryLevel
);
1000 DEF_TPG_PARAM(IFMarker
);
1001 DEF_TPG_PARAM(OFMarker
);
1002 DEF_TPG_PARAM(IFMarkInt
);
1003 DEF_TPG_PARAM(OFMarkInt
);
1005 static struct configfs_attribute
*lio_target_tpg_param_attrs
[] = {
1006 &iscsi_tpg_param_attr_AuthMethod
,
1007 &iscsi_tpg_param_attr_HeaderDigest
,
1008 &iscsi_tpg_param_attr_DataDigest
,
1009 &iscsi_tpg_param_attr_MaxConnections
,
1010 &iscsi_tpg_param_attr_TargetAlias
,
1011 &iscsi_tpg_param_attr_InitialR2T
,
1012 &iscsi_tpg_param_attr_ImmediateData
,
1013 &iscsi_tpg_param_attr_MaxRecvDataSegmentLength
,
1014 &iscsi_tpg_param_attr_MaxXmitDataSegmentLength
,
1015 &iscsi_tpg_param_attr_MaxBurstLength
,
1016 &iscsi_tpg_param_attr_FirstBurstLength
,
1017 &iscsi_tpg_param_attr_DefaultTime2Wait
,
1018 &iscsi_tpg_param_attr_DefaultTime2Retain
,
1019 &iscsi_tpg_param_attr_MaxOutstandingR2T
,
1020 &iscsi_tpg_param_attr_DataPDUInOrder
,
1021 &iscsi_tpg_param_attr_DataSequenceInOrder
,
1022 &iscsi_tpg_param_attr_ErrorRecoveryLevel
,
1023 &iscsi_tpg_param_attr_IFMarker
,
1024 &iscsi_tpg_param_attr_OFMarker
,
1025 &iscsi_tpg_param_attr_IFMarkInt
,
1026 &iscsi_tpg_param_attr_OFMarkInt
,
1030 /* End items for lio_target_tpg_param_cit */
1032 /* Start items for lio_target_tpg_cit */
1034 static ssize_t
lio_target_tpg_enable_show(struct config_item
*item
, char *page
)
1036 struct se_portal_group
*se_tpg
= to_tpg(item
);
1037 struct iscsi_portal_group
*tpg
= container_of(se_tpg
,
1038 struct iscsi_portal_group
, tpg_se_tpg
);
1041 spin_lock(&tpg
->tpg_state_lock
);
1042 len
= sprintf(page
, "%d\n",
1043 (tpg
->tpg_state
== TPG_STATE_ACTIVE
) ? 1 : 0);
1044 spin_unlock(&tpg
->tpg_state_lock
);
1049 static ssize_t
lio_target_tpg_enable_store(struct config_item
*item
,
1050 const char *page
, size_t count
)
1052 struct se_portal_group
*se_tpg
= to_tpg(item
);
1053 struct iscsi_portal_group
*tpg
= container_of(se_tpg
,
1054 struct iscsi_portal_group
, tpg_se_tpg
);
1058 ret
= kstrtou32(page
, 0, &op
);
1061 if ((op
!= 1) && (op
!= 0)) {
1062 pr_err("Illegal value for tpg_enable: %u\n", op
);
1066 ret
= iscsit_get_tpg(tpg
);
1071 ret
= iscsit_tpg_enable_portal_group(tpg
);
1076 * iscsit_tpg_disable_portal_group() assumes force=1
1078 ret
= iscsit_tpg_disable_portal_group(tpg
, 1);
1083 iscsit_put_tpg(tpg
);
1086 iscsit_put_tpg(tpg
);
1091 static ssize_t
lio_target_tpg_dynamic_sessions_show(struct config_item
*item
,
1094 return target_show_dynamic_sessions(to_tpg(item
), page
);
1097 CONFIGFS_ATTR(lio_target_tpg_
, enable
);
1098 CONFIGFS_ATTR_RO(lio_target_tpg_
, dynamic_sessions
);
1100 static struct configfs_attribute
*lio_target_tpg_attrs
[] = {
1101 &lio_target_tpg_attr_enable
,
1102 &lio_target_tpg_attr_dynamic_sessions
,
1106 /* End items for lio_target_tpg_cit */
1108 /* Start items for lio_target_tiqn_cit */
1110 static struct se_portal_group
*lio_target_tiqn_addtpg(
1112 struct config_group
*group
,
1115 struct iscsi_portal_group
*tpg
;
1116 struct iscsi_tiqn
*tiqn
;
1121 tiqn
= container_of(wwn
, struct iscsi_tiqn
, tiqn_wwn
);
1123 * Only tpgt_# directory groups can be created below
1124 * target/iscsi/iqn.superturodiskarry/
1126 tpgt_str
= strstr(name
, "tpgt_");
1128 pr_err("Unable to locate \"tpgt_#\" directory"
1132 tpgt_str
+= 5; /* Skip ahead of "tpgt_" */
1133 ret
= kstrtou16(tpgt_str
, 0, &tpgt
);
1137 tpg
= iscsit_alloc_portal_group(tiqn
, tpgt
);
1141 ret
= core_tpg_register(wwn
, &tpg
->tpg_se_tpg
, SCSI_PROTOCOL_ISCSI
);
1145 ret
= iscsit_tpg_add_portal_group(tiqn
, tpg
);
1149 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn
->tiqn
);
1150 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1152 return &tpg
->tpg_se_tpg
;
1154 core_tpg_deregister(&tpg
->tpg_se_tpg
);
1159 static void lio_target_tiqn_deltpg(struct se_portal_group
*se_tpg
)
1161 struct iscsi_portal_group
*tpg
;
1162 struct iscsi_tiqn
*tiqn
;
1164 tpg
= container_of(se_tpg
, struct iscsi_portal_group
, tpg_se_tpg
);
1165 tiqn
= tpg
->tpg_tiqn
;
1167 * iscsit_tpg_del_portal_group() assumes force=1
1169 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1170 iscsit_tpg_del_portal_group(tiqn
, tpg
, 1);
1173 /* End items for lio_target_tiqn_cit */
1175 /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1177 static ssize_t
lio_target_wwn_lio_version_show(struct config_item
*item
,
1180 return sprintf(page
, "Datera Inc. iSCSI Target "ISCSIT_VERSION
"\n");
1183 CONFIGFS_ATTR_RO(lio_target_wwn_
, lio_version
);
1185 static struct configfs_attribute
*lio_target_wwn_attrs
[] = {
1186 &lio_target_wwn_attr_lio_version
,
1190 static struct se_wwn
*lio_target_call_coreaddtiqn(
1191 struct target_fabric_configfs
*tf
,
1192 struct config_group
*group
,
1195 struct iscsi_tiqn
*tiqn
;
1197 tiqn
= iscsit_add_tiqn((unsigned char *)name
);
1199 return ERR_CAST(tiqn
);
1201 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn
->tiqn
);
1202 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1204 return &tiqn
->tiqn_wwn
;
1207 static void lio_target_add_wwn_groups(struct se_wwn
*wwn
)
1209 struct iscsi_tiqn
*tiqn
= container_of(wwn
, struct iscsi_tiqn
, tiqn_wwn
);
1211 config_group_init_type_name(&tiqn
->tiqn_stat_grps
.iscsi_instance_group
,
1212 "iscsi_instance", &iscsi_stat_instance_cit
);
1213 configfs_add_default_group(&tiqn
->tiqn_stat_grps
.iscsi_instance_group
,
1214 &tiqn
->tiqn_wwn
.fabric_stat_group
);
1216 config_group_init_type_name(&tiqn
->tiqn_stat_grps
.iscsi_sess_err_group
,
1217 "iscsi_sess_err", &iscsi_stat_sess_err_cit
);
1218 configfs_add_default_group(&tiqn
->tiqn_stat_grps
.iscsi_sess_err_group
,
1219 &tiqn
->tiqn_wwn
.fabric_stat_group
);
1221 config_group_init_type_name(&tiqn
->tiqn_stat_grps
.iscsi_tgt_attr_group
,
1222 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit
);
1223 configfs_add_default_group(&tiqn
->tiqn_stat_grps
.iscsi_tgt_attr_group
,
1224 &tiqn
->tiqn_wwn
.fabric_stat_group
);
1226 config_group_init_type_name(&tiqn
->tiqn_stat_grps
.iscsi_login_stats_group
,
1227 "iscsi_login_stats", &iscsi_stat_login_cit
);
1228 configfs_add_default_group(&tiqn
->tiqn_stat_grps
.iscsi_login_stats_group
,
1229 &tiqn
->tiqn_wwn
.fabric_stat_group
);
1231 config_group_init_type_name(&tiqn
->tiqn_stat_grps
.iscsi_logout_stats_group
,
1232 "iscsi_logout_stats", &iscsi_stat_logout_cit
);
1233 configfs_add_default_group(&tiqn
->tiqn_stat_grps
.iscsi_logout_stats_group
,
1234 &tiqn
->tiqn_wwn
.fabric_stat_group
);
1237 static void lio_target_call_coredeltiqn(
1240 struct iscsi_tiqn
*tiqn
= container_of(wwn
, struct iscsi_tiqn
, tiqn_wwn
);
1242 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1244 iscsit_del_tiqn(tiqn
);
1247 /* End LIO-Target TIQN struct contig_lio_target_cit */
1249 /* Start lio_target_discovery_auth_cit */
1251 #define DEF_DISC_AUTH_STR(name, flags) \
1252 __DEF_NACL_AUTH_STR(disc, name, flags) \
1253 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1255 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
1258 static ssize_t iscsi_disc_##name##_store(struct config_item *item, \
1259 const char *page, size_t count) \
1261 return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \
1265 CONFIGFS_ATTR(iscsi_disc_, name)
1267 DEF_DISC_AUTH_STR(userid
, NAF_USERID_SET
);
1268 DEF_DISC_AUTH_STR(password
, NAF_PASSWORD_SET
);
1269 DEF_DISC_AUTH_STR(userid_mutual
, NAF_USERID_IN_SET
);
1270 DEF_DISC_AUTH_STR(password_mutual
, NAF_PASSWORD_IN_SET
);
1272 #define DEF_DISC_AUTH_INT(name) \
1273 __DEF_NACL_AUTH_INT(disc, name) \
1274 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1276 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
1279 CONFIGFS_ATTR_RO(iscsi_disc_, name)
1281 DEF_DISC_AUTH_INT(authenticate_target
);
1284 static ssize_t
iscsi_disc_enforce_discovery_auth_show(struct config_item
*item
,
1287 struct iscsi_node_auth
*discovery_auth
= &iscsit_global
->discovery_acl
.node_auth
;
1289 return sprintf(page
, "%d\n", discovery_auth
->enforce_discovery_auth
);
1292 static ssize_t
iscsi_disc_enforce_discovery_auth_store(struct config_item
*item
,
1293 const char *page
, size_t count
)
1295 struct iscsi_param
*param
;
1296 struct iscsi_portal_group
*discovery_tpg
= iscsit_global
->discovery_tpg
;
1300 err
= kstrtou32(page
, 0, &op
);
1303 if ((op
!= 1) && (op
!= 0)) {
1304 pr_err("Illegal value for enforce_discovery_auth:"
1309 if (!discovery_tpg
) {
1310 pr_err("iscsit_global->discovery_tpg is NULL\n");
1314 param
= iscsi_find_param_from_key(AUTHMETHOD
,
1315 discovery_tpg
->param_list
);
1321 * Reset the AuthMethod key to CHAP.
1323 if (iscsi_update_param_value(param
, CHAP
) < 0)
1326 discovery_tpg
->tpg_attrib
.authentication
= 1;
1327 iscsit_global
->discovery_acl
.node_auth
.enforce_discovery_auth
= 1;
1328 pr_debug("LIO-CORE[0] Successfully enabled"
1329 " authentication enforcement for iSCSI"
1330 " Discovery TPG\n");
1333 * Reset the AuthMethod key to CHAP,None
1335 if (iscsi_update_param_value(param
, "CHAP,None") < 0)
1338 discovery_tpg
->tpg_attrib
.authentication
= 0;
1339 iscsit_global
->discovery_acl
.node_auth
.enforce_discovery_auth
= 0;
1340 pr_debug("LIO-CORE[0] Successfully disabled"
1341 " authentication enforcement for iSCSI"
1342 " Discovery TPG\n");
1348 CONFIGFS_ATTR(iscsi_disc_
, enforce_discovery_auth
);
1350 static struct configfs_attribute
*lio_target_discovery_auth_attrs
[] = {
1351 &iscsi_disc_attr_userid
,
1352 &iscsi_disc_attr_password
,
1353 &iscsi_disc_attr_authenticate_target
,
1354 &iscsi_disc_attr_userid_mutual
,
1355 &iscsi_disc_attr_password_mutual
,
1356 &iscsi_disc_attr_enforce_discovery_auth
,
1360 /* End lio_target_discovery_auth_cit */
1362 /* Start functions for target_core_fabric_ops */
1364 static char *iscsi_get_fabric_name(void)
1369 static int iscsi_get_cmd_state(struct se_cmd
*se_cmd
)
1371 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1373 return cmd
->i_state
;
1376 static u32
lio_sess_get_index(struct se_session
*se_sess
)
1378 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1380 return sess
->session_index
;
1383 static u32
lio_sess_get_initiator_sid(
1384 struct se_session
*se_sess
,
1388 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1390 * iSCSI Initiator Session Identifier from RFC-3720.
1392 return snprintf(buf
, size
, "%6phN", sess
->isid
);
1395 static int lio_queue_data_in(struct se_cmd
*se_cmd
)
1397 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1399 cmd
->i_state
= ISTATE_SEND_DATAIN
;
1400 cmd
->conn
->conn_transport
->iscsit_queue_data_in(cmd
->conn
, cmd
);
1405 static int lio_write_pending(struct se_cmd
*se_cmd
)
1407 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1408 struct iscsi_conn
*conn
= cmd
->conn
;
1410 if (!cmd
->immediate_data
&& !cmd
->unsolicited_data
)
1411 return conn
->conn_transport
->iscsit_get_dataout(conn
, cmd
, false);
1416 static int lio_write_pending_status(struct se_cmd
*se_cmd
)
1418 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1421 spin_lock_bh(&cmd
->istate_lock
);
1422 ret
= !(cmd
->cmd_flags
& ICF_GOT_LAST_DATAOUT
);
1423 spin_unlock_bh(&cmd
->istate_lock
);
1428 static int lio_queue_status(struct se_cmd
*se_cmd
)
1430 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1432 cmd
->i_state
= ISTATE_SEND_STATUS
;
1434 if (cmd
->se_cmd
.scsi_status
|| cmd
->sense_reason
) {
1435 iscsit_add_cmd_to_response_queue(cmd
, cmd
->conn
, cmd
->i_state
);
1438 cmd
->conn
->conn_transport
->iscsit_queue_status(cmd
->conn
, cmd
);
1443 static void lio_queue_tm_rsp(struct se_cmd
*se_cmd
)
1445 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1447 cmd
->i_state
= ISTATE_SEND_TASKMGTRSP
;
1448 iscsit_add_cmd_to_response_queue(cmd
, cmd
->conn
, cmd
->i_state
);
1451 static void lio_aborted_task(struct se_cmd
*se_cmd
)
1453 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1455 cmd
->conn
->conn_transport
->iscsit_aborted_task(cmd
->conn
, cmd
);
1458 static inline struct iscsi_portal_group
*iscsi_tpg(struct se_portal_group
*se_tpg
)
1460 return container_of(se_tpg
, struct iscsi_portal_group
, tpg_se_tpg
);
1463 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group
*se_tpg
)
1465 return iscsi_tpg(se_tpg
)->tpg_tiqn
->tiqn
;
1468 static u16
lio_tpg_get_tag(struct se_portal_group
*se_tpg
)
1470 return iscsi_tpg(se_tpg
)->tpgt
;
1473 static u32
lio_tpg_get_default_depth(struct se_portal_group
*se_tpg
)
1475 return iscsi_tpg(se_tpg
)->tpg_attrib
.default_cmdsn_depth
;
1478 static int lio_tpg_check_demo_mode(struct se_portal_group
*se_tpg
)
1480 return iscsi_tpg(se_tpg
)->tpg_attrib
.generate_node_acls
;
1483 static int lio_tpg_check_demo_mode_cache(struct se_portal_group
*se_tpg
)
1485 return iscsi_tpg(se_tpg
)->tpg_attrib
.cache_dynamic_acls
;
1488 static int lio_tpg_check_demo_mode_write_protect(
1489 struct se_portal_group
*se_tpg
)
1491 return iscsi_tpg(se_tpg
)->tpg_attrib
.demo_mode_write_protect
;
1494 static int lio_tpg_check_prod_mode_write_protect(
1495 struct se_portal_group
*se_tpg
)
1497 return iscsi_tpg(se_tpg
)->tpg_attrib
.prod_mode_write_protect
;
1500 static int lio_tpg_check_prot_fabric_only(
1501 struct se_portal_group
*se_tpg
)
1504 * Only report fabric_prot_type if t10_pi has also been enabled
1505 * for incoming ib_isert sessions.
1507 if (!iscsi_tpg(se_tpg
)->tpg_attrib
.t10_pi
)
1509 return iscsi_tpg(se_tpg
)->tpg_attrib
.fabric_prot_type
;
1513 * This function calls iscsit_inc_session_usage_count() on the
1514 * struct iscsi_session in question.
1516 static void lio_tpg_close_session(struct se_session
*se_sess
)
1518 struct iscsi_session
*sess
= se_sess
->fabric_sess_ptr
;
1519 struct se_portal_group
*se_tpg
= &sess
->tpg
->tpg_se_tpg
;
1521 spin_lock_bh(&se_tpg
->session_lock
);
1522 spin_lock(&sess
->conn_lock
);
1523 if (atomic_read(&sess
->session_fall_back_to_erl0
) ||
1524 atomic_read(&sess
->session_logout
) ||
1525 (sess
->time2retain_timer_flags
& ISCSI_TF_EXPIRED
)) {
1526 spin_unlock(&sess
->conn_lock
);
1527 spin_unlock_bh(&se_tpg
->session_lock
);
1530 atomic_set(&sess
->session_reinstatement
, 1);
1531 spin_unlock(&sess
->conn_lock
);
1533 iscsit_stop_time2retain_timer(sess
);
1534 spin_unlock_bh(&se_tpg
->session_lock
);
1536 iscsit_stop_session(sess
, 1, 1);
1537 iscsit_close_session(sess
);
1540 static u32
lio_tpg_get_inst_index(struct se_portal_group
*se_tpg
)
1542 return iscsi_tpg(se_tpg
)->tpg_tiqn
->tiqn_index
;
1545 static void lio_set_default_node_attributes(struct se_node_acl
*se_acl
)
1547 struct iscsi_node_acl
*acl
= container_of(se_acl
, struct iscsi_node_acl
,
1549 struct se_portal_group
*se_tpg
= se_acl
->se_tpg
;
1550 struct iscsi_portal_group
*tpg
= container_of(se_tpg
,
1551 struct iscsi_portal_group
, tpg_se_tpg
);
1553 acl
->node_attrib
.nacl
= acl
;
1554 iscsit_set_default_node_attribues(acl
, tpg
);
1557 static int lio_check_stop_free(struct se_cmd
*se_cmd
)
1559 return target_put_sess_cmd(se_cmd
);
1562 static void lio_release_cmd(struct se_cmd
*se_cmd
)
1564 struct iscsi_cmd
*cmd
= container_of(se_cmd
, struct iscsi_cmd
, se_cmd
);
1566 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd
);
1567 iscsit_release_cmd(cmd
);
1570 const struct target_core_fabric_ops iscsi_ops
= {
1571 .module
= THIS_MODULE
,
1573 .node_acl_size
= sizeof(struct iscsi_node_acl
),
1574 .get_fabric_name
= iscsi_get_fabric_name
,
1575 .tpg_get_wwn
= lio_tpg_get_endpoint_wwn
,
1576 .tpg_get_tag
= lio_tpg_get_tag
,
1577 .tpg_get_default_depth
= lio_tpg_get_default_depth
,
1578 .tpg_check_demo_mode
= lio_tpg_check_demo_mode
,
1579 .tpg_check_demo_mode_cache
= lio_tpg_check_demo_mode_cache
,
1580 .tpg_check_demo_mode_write_protect
=
1581 lio_tpg_check_demo_mode_write_protect
,
1582 .tpg_check_prod_mode_write_protect
=
1583 lio_tpg_check_prod_mode_write_protect
,
1584 .tpg_check_prot_fabric_only
= &lio_tpg_check_prot_fabric_only
,
1585 .tpg_get_inst_index
= lio_tpg_get_inst_index
,
1586 .check_stop_free
= lio_check_stop_free
,
1587 .release_cmd
= lio_release_cmd
,
1588 .close_session
= lio_tpg_close_session
,
1589 .sess_get_index
= lio_sess_get_index
,
1590 .sess_get_initiator_sid
= lio_sess_get_initiator_sid
,
1591 .write_pending
= lio_write_pending
,
1592 .write_pending_status
= lio_write_pending_status
,
1593 .set_default_node_attributes
= lio_set_default_node_attributes
,
1594 .get_cmd_state
= iscsi_get_cmd_state
,
1595 .queue_data_in
= lio_queue_data_in
,
1596 .queue_status
= lio_queue_status
,
1597 .queue_tm_rsp
= lio_queue_tm_rsp
,
1598 .aborted_task
= lio_aborted_task
,
1599 .fabric_make_wwn
= lio_target_call_coreaddtiqn
,
1600 .fabric_drop_wwn
= lio_target_call_coredeltiqn
,
1601 .add_wwn_groups
= lio_target_add_wwn_groups
,
1602 .fabric_make_tpg
= lio_target_tiqn_addtpg
,
1603 .fabric_drop_tpg
= lio_target_tiqn_deltpg
,
1604 .fabric_make_np
= lio_target_call_addnptotpg
,
1605 .fabric_drop_np
= lio_target_call_delnpfromtpg
,
1606 .fabric_init_nodeacl
= lio_target_init_nodeacl
,
1608 .tfc_discovery_attrs
= lio_target_discovery_auth_attrs
,
1609 .tfc_wwn_attrs
= lio_target_wwn_attrs
,
1610 .tfc_tpg_base_attrs
= lio_target_tpg_attrs
,
1611 .tfc_tpg_attrib_attrs
= lio_target_tpg_attrib_attrs
,
1612 .tfc_tpg_auth_attrs
= lio_target_tpg_auth_attrs
,
1613 .tfc_tpg_param_attrs
= lio_target_tpg_param_attrs
,
1614 .tfc_tpg_np_base_attrs
= lio_target_portal_attrs
,
1615 .tfc_tpg_nacl_base_attrs
= lio_target_initiator_attrs
,
1616 .tfc_tpg_nacl_attrib_attrs
= lio_target_nacl_attrib_attrs
,
1617 .tfc_tpg_nacl_auth_attrs
= lio_target_nacl_auth_attrs
,
1618 .tfc_tpg_nacl_param_attrs
= lio_target_nacl_param_attrs
,