1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*******************************************************************************
3 * This file contains the configfs implementation for iSCSI Target mode
4 * from the LIO-Target Project.
6 * (c) Copyright 2007-2013 Datera, Inc.
8 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
10 ****************************************************************************/
12 #include <linux/configfs.h>
13 #include <linux/ctype.h>
14 #include <linux/export.h>
15 #include <linux/inet.h>
16 #include <linux/module.h>
18 #include <target/target_core_base.h>
19 #include <target/target_core_fabric.h>
20 #include <target/iscsi/iscsi_transport.h>
21 #include <target/iscsi/iscsi_target_core.h>
22 #include "iscsi_target_parameters.h"
23 #include "iscsi_target_device.h"
24 #include "iscsi_target_erl0.h"
25 #include "iscsi_target_nodeattrib.h"
26 #include "iscsi_target_tpg.h"
27 #include "iscsi_target_util.h"
28 #include "iscsi_target.h"
29 #include <target/iscsi/iscsi_target_stat.h>
32 /* Start items for lio_target_portal_cit */
34 static inline struct iscsi_tpg_np
*to_iscsi_tpg_np(struct config_item
*item
)
36 return container_of(to_tpg_np(item
), struct iscsi_tpg_np
, se_tpg_np
);
39 static ssize_t
lio_target_np_driver_show(struct config_item
*item
, char *page
,
40 enum iscsit_transport_type type
)
42 struct iscsi_tpg_np
*tpg_np
= to_iscsi_tpg_np(item
);
43 struct iscsi_tpg_np
*tpg_np_new
;
46 tpg_np_new
= iscsit_tpg_locate_child_np(tpg_np
, type
);
48 rb
= sysfs_emit(page
, "1\n");
50 rb
= sysfs_emit(page
, "0\n");
55 static ssize_t
lio_target_np_driver_store(struct config_item
*item
,
56 const char *page
, size_t count
, enum iscsit_transport_type type
,
59 struct iscsi_tpg_np
*tpg_np
= to_iscsi_tpg_np(item
);
61 struct iscsi_portal_group
*tpg
;
62 struct iscsi_tpg_np
*tpg_np_new
= NULL
;
66 rc
= kstrtou32(page
, 0, &op
);
69 if ((op
!= 1) && (op
!= 0)) {
70 pr_err("Illegal value for tpg_enable: %u\n", op
);
75 pr_err("Unable to locate struct iscsi_np from"
76 " struct iscsi_tpg_np\n");
81 if (iscsit_get_tpg(tpg
) < 0)
85 if (strlen(mod_name
)) {
86 rc
= request_module(mod_name
);
88 pr_warn("Unable to request_module for %s\n",
94 tpg_np_new
= iscsit_tpg_add_network_portal(tpg
,
95 &np
->np_sockaddr
, tpg_np
, type
);
96 if (IS_ERR(tpg_np_new
)) {
97 rc
= PTR_ERR(tpg_np_new
);
101 tpg_np_new
= iscsit_tpg_locate_child_np(tpg_np
, type
);
103 rc
= iscsit_tpg_del_network_portal(tpg
, tpg_np_new
);
116 static ssize_t
lio_target_np_iser_show(struct config_item
*item
, char *page
)
118 return lio_target_np_driver_show(item
, page
, ISCSI_INFINIBAND
);
121 static ssize_t
lio_target_np_iser_store(struct config_item
*item
,
122 const char *page
, size_t count
)
124 return lio_target_np_driver_store(item
, page
, count
,
125 ISCSI_INFINIBAND
, "ib_isert");
127 CONFIGFS_ATTR(lio_target_np_
, iser
);
129 static ssize_t
lio_target_np_cxgbit_show(struct config_item
*item
, char *page
)
131 return lio_target_np_driver_show(item
, page
, ISCSI_CXGBIT
);
134 static ssize_t
lio_target_np_cxgbit_store(struct config_item
*item
,
135 const char *page
, size_t count
)
137 return lio_target_np_driver_store(item
, page
, count
,
138 ISCSI_CXGBIT
, "cxgbit");
140 CONFIGFS_ATTR(lio_target_np_
, cxgbit
);
142 static struct configfs_attribute
*lio_target_portal_attrs
[] = {
143 &lio_target_np_attr_iser
,
144 &lio_target_np_attr_cxgbit
,
148 /* Stop items for lio_target_portal_cit */
150 /* Start items for lio_target_np_cit */
152 #define MAX_PORTAL_LEN 256
154 static struct se_tpg_np
*lio_target_call_addnptotpg(
155 struct se_portal_group
*se_tpg
,
156 struct config_group
*group
,
159 struct iscsi_portal_group
*tpg
;
160 struct iscsi_tpg_np
*tpg_np
;
161 char *str
, *str2
, *ip_str
, *port_str
;
162 struct sockaddr_storage sockaddr
= { };
164 char buf
[MAX_PORTAL_LEN
+ 1] = { };
166 if (strlen(name
) > MAX_PORTAL_LEN
) {
167 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
168 (int)strlen(name
), MAX_PORTAL_LEN
);
169 return ERR_PTR(-EOVERFLOW
);
171 snprintf(buf
, MAX_PORTAL_LEN
+ 1, "%s", name
);
173 str
= strstr(buf
, "[");
175 str2
= strstr(str
, "]");
177 pr_err("Unable to locate trailing \"]\""
178 " in IPv6 iSCSI network portal address\n");
179 return ERR_PTR(-EINVAL
);
182 ip_str
= str
+ 1; /* Skip over leading "[" */
183 *str2
= '\0'; /* Terminate the unbracketed IPv6 address */
184 str2
++; /* Skip over the \0 */
186 port_str
= strstr(str2
, ":");
188 pr_err("Unable to locate \":port\""
189 " in IPv6 iSCSI network portal address\n");
190 return ERR_PTR(-EINVAL
);
192 *port_str
= '\0'; /* Terminate string for IP */
193 port_str
++; /* Skip over ":" */
196 port_str
= strstr(ip_str
, ":");
198 pr_err("Unable to locate \":port\""
199 " in IPv4 iSCSI network portal address\n");
200 return ERR_PTR(-EINVAL
);
202 *port_str
= '\0'; /* Terminate string for IP */
203 port_str
++; /* Skip over ":" */
206 ret
= inet_pton_with_scope(&init_net
, AF_UNSPEC
, ip_str
,
207 port_str
, &sockaddr
);
209 pr_err("malformed ip/port passed: %s\n", name
);
213 tpg
= to_iscsi_tpg(se_tpg
);
214 ret
= iscsit_get_tpg(tpg
);
216 return ERR_PTR(-EINVAL
);
218 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
220 config_item_name(&se_tpg
->se_tpg_wwn
->wwn_group
.cg_item
),
223 * Assume ISCSI_TCP by default. Other network portals for other
226 * Traditional iSCSI over SCTP (initial support)
227 * iSER/TCP (TODO, hardware available)
228 * iSER/SCTP (TODO, software emulation with osc-iwarp)
229 * iSER/IB (TODO, hardware available)
231 * can be enabled with attributes under
232 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
235 tpg_np
= iscsit_tpg_add_network_portal(tpg
, &sockaddr
, NULL
,
237 if (IS_ERR(tpg_np
)) {
239 return ERR_CAST(tpg_np
);
241 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
244 return &tpg_np
->se_tpg_np
;
247 static void lio_target_call_delnpfromtpg(
248 struct se_tpg_np
*se_tpg_np
)
250 struct iscsi_portal_group
*tpg
;
251 struct iscsi_tpg_np
*tpg_np
;
252 struct se_portal_group
*se_tpg
;
255 tpg_np
= container_of(se_tpg_np
, struct iscsi_tpg_np
, se_tpg_np
);
257 ret
= iscsit_get_tpg(tpg
);
261 se_tpg
= &tpg
->tpg_se_tpg
;
262 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
263 " PORTAL: %pISpc\n", config_item_name(&se_tpg
->se_tpg_wwn
->wwn_group
.cg_item
),
264 tpg
->tpgt
, &tpg_np
->tpg_np
->np_sockaddr
);
266 ret
= iscsit_tpg_del_network_portal(tpg
, tpg_np
);
270 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
275 /* End items for lio_target_np_cit */
277 /* Start items for lio_target_nacl_attrib_cit */
279 #define ISCSI_NACL_ATTR(name) \
280 static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
283 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
284 struct iscsi_node_acl *nacl = to_iscsi_nacl(se_nacl); \
285 return sysfs_emit(page, "%u\n", nacl->node_attrib.name); \
288 static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
289 const char *page, size_t count) \
291 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
292 struct iscsi_node_acl *nacl = to_iscsi_nacl(se_nacl); \
296 ret = kstrtou32(page, 0, &val); \
299 ret = iscsit_na_##name(nacl, val); \
306 CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
308 ISCSI_NACL_ATTR(dataout_timeout
);
309 ISCSI_NACL_ATTR(dataout_timeout_retries
);
310 ISCSI_NACL_ATTR(default_erl
);
311 ISCSI_NACL_ATTR(nopin_timeout
);
312 ISCSI_NACL_ATTR(nopin_response_timeout
);
313 ISCSI_NACL_ATTR(random_datain_pdu_offsets
);
314 ISCSI_NACL_ATTR(random_datain_seq_offsets
);
315 ISCSI_NACL_ATTR(random_r2t_offsets
);
317 static ssize_t
iscsi_nacl_attrib_authentication_show(struct config_item
*item
,
320 struct se_node_acl
*se_nacl
= attrib_to_nacl(item
);
321 struct iscsi_node_acl
*nacl
= to_iscsi_nacl(se_nacl
);
323 return sysfs_emit(page
, "%d\n", nacl
->node_attrib
.authentication
);
326 static ssize_t
iscsi_nacl_attrib_authentication_store(struct config_item
*item
,
327 const char *page
, size_t count
)
329 struct se_node_acl
*se_nacl
= attrib_to_nacl(item
);
330 struct iscsi_node_acl
*nacl
= to_iscsi_nacl(se_nacl
);
334 ret
= kstrtos32(page
, 0, &val
);
337 if (val
!= 0 && val
!= 1 && val
!= NA_AUTHENTICATION_INHERITED
)
340 nacl
->node_attrib
.authentication
= val
;
345 CONFIGFS_ATTR(iscsi_nacl_attrib_
, authentication
);
347 static struct configfs_attribute
*lio_target_nacl_attrib_attrs
[] = {
348 &iscsi_nacl_attrib_attr_dataout_timeout
,
349 &iscsi_nacl_attrib_attr_dataout_timeout_retries
,
350 &iscsi_nacl_attrib_attr_default_erl
,
351 &iscsi_nacl_attrib_attr_nopin_timeout
,
352 &iscsi_nacl_attrib_attr_nopin_response_timeout
,
353 &iscsi_nacl_attrib_attr_random_datain_pdu_offsets
,
354 &iscsi_nacl_attrib_attr_random_datain_seq_offsets
,
355 &iscsi_nacl_attrib_attr_random_r2t_offsets
,
356 &iscsi_nacl_attrib_attr_authentication
,
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(to_iscsi_nacl(nacl), page); \
410 static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \
411 const char *page, size_t count) \
413 struct se_node_acl *nacl = auth_to_nacl(item); \
414 return __iscsi_nacl_auth_##name##_store(to_iscsi_nacl(nacl), \
418 CONFIGFS_ATTR(iscsi_nacl_auth_, name)
421 * One-way authentication userid
423 DEF_NACL_AUTH_STR(userid
, NAF_USERID_SET
);
424 DEF_NACL_AUTH_STR(password
, NAF_PASSWORD_SET
);
425 DEF_NACL_AUTH_STR(userid_mutual
, NAF_USERID_IN_SET
);
426 DEF_NACL_AUTH_STR(password_mutual
, NAF_PASSWORD_IN_SET
);
428 #define __DEF_NACL_AUTH_INT(prefix, name) \
429 static ssize_t __iscsi_##prefix##_##name##_show( \
430 struct iscsi_node_acl *nacl, \
433 struct iscsi_node_auth *auth = &nacl->node_auth; \
435 if (!capable(CAP_SYS_ADMIN)) \
438 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
441 #define DEF_NACL_AUTH_INT(name) \
442 __DEF_NACL_AUTH_INT(nacl_auth, name) \
443 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
446 struct se_node_acl *nacl = auth_to_nacl(item); \
447 return __iscsi_nacl_auth_##name##_show(to_iscsi_nacl(nacl), page); \
450 CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
452 DEF_NACL_AUTH_INT(authenticate_target
);
454 static struct configfs_attribute
*lio_target_nacl_auth_attrs
[] = {
455 &iscsi_nacl_auth_attr_userid
,
456 &iscsi_nacl_auth_attr_password
,
457 &iscsi_nacl_auth_attr_authenticate_target
,
458 &iscsi_nacl_auth_attr_userid_mutual
,
459 &iscsi_nacl_auth_attr_password_mutual
,
463 /* End items for lio_target_nacl_auth_cit */
465 /* Start items for lio_target_nacl_param_cit */
467 #define ISCSI_NACL_PARAM(name) \
468 static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \
471 struct se_node_acl *se_nacl = param_to_nacl(item); \
472 struct iscsit_session *sess; \
473 struct se_session *se_sess; \
476 spin_lock_bh(&se_nacl->nacl_sess_lock); \
477 se_sess = se_nacl->nacl_sess; \
479 rb = snprintf(page, PAGE_SIZE, \
480 "No Active iSCSI Session\n"); \
482 sess = se_sess->fabric_sess_ptr; \
483 rb = snprintf(page, PAGE_SIZE, "%u\n", \
484 (u32)sess->sess_ops->name); \
486 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
491 CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
493 ISCSI_NACL_PARAM(MaxConnections
);
494 ISCSI_NACL_PARAM(InitialR2T
);
495 ISCSI_NACL_PARAM(ImmediateData
);
496 ISCSI_NACL_PARAM(MaxBurstLength
);
497 ISCSI_NACL_PARAM(FirstBurstLength
);
498 ISCSI_NACL_PARAM(DefaultTime2Wait
);
499 ISCSI_NACL_PARAM(DefaultTime2Retain
);
500 ISCSI_NACL_PARAM(MaxOutstandingR2T
);
501 ISCSI_NACL_PARAM(DataPDUInOrder
);
502 ISCSI_NACL_PARAM(DataSequenceInOrder
);
503 ISCSI_NACL_PARAM(ErrorRecoveryLevel
);
505 static struct configfs_attribute
*lio_target_nacl_param_attrs
[] = {
506 &iscsi_nacl_param_attr_MaxConnections
,
507 &iscsi_nacl_param_attr_InitialR2T
,
508 &iscsi_nacl_param_attr_ImmediateData
,
509 &iscsi_nacl_param_attr_MaxBurstLength
,
510 &iscsi_nacl_param_attr_FirstBurstLength
,
511 &iscsi_nacl_param_attr_DefaultTime2Wait
,
512 &iscsi_nacl_param_attr_DefaultTime2Retain
,
513 &iscsi_nacl_param_attr_MaxOutstandingR2T
,
514 &iscsi_nacl_param_attr_DataPDUInOrder
,
515 &iscsi_nacl_param_attr_DataSequenceInOrder
,
516 &iscsi_nacl_param_attr_ErrorRecoveryLevel
,
520 /* End items for lio_target_nacl_param_cit */
522 /* Start items for lio_target_acl_cit */
524 static ssize_t
lio_target_nacl_info_show(struct config_item
*item
, char *page
)
526 struct se_node_acl
*se_nacl
= acl_to_nacl(item
);
527 struct iscsit_session
*sess
;
528 struct iscsit_conn
*conn
;
529 struct se_session
*se_sess
;
533 spin_lock_bh(&se_nacl
->nacl_sess_lock
);
534 se_sess
= se_nacl
->nacl_sess
;
536 rb
+= sysfs_emit_at(page
, rb
, "No active iSCSI Session for Initiator"
537 " Endpoint: %s\n", se_nacl
->initiatorname
);
539 sess
= se_sess
->fabric_sess_ptr
;
541 rb
+= sysfs_emit_at(page
, rb
, "InitiatorName: %s\n",
542 sess
->sess_ops
->InitiatorName
);
543 rb
+= sysfs_emit_at(page
, rb
, "InitiatorAlias: %s\n",
544 sess
->sess_ops
->InitiatorAlias
);
546 rb
+= sysfs_emit_at(page
, rb
,
547 "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ",
548 sess
->sid
, sess
->isid
, sess
->tsih
);
549 rb
+= sysfs_emit_at(page
, rb
, "SessionType: %s\n",
550 (sess
->sess_ops
->SessionType
) ?
551 "Discovery" : "Normal");
552 rb
+= sysfs_emit_at(page
, rb
, "Session State: ");
553 switch (sess
->session_state
) {
554 case TARG_SESS_STATE_FREE
:
555 rb
+= sysfs_emit_at(page
, rb
, "TARG_SESS_FREE\n");
557 case TARG_SESS_STATE_ACTIVE
:
558 rb
+= sysfs_emit_at(page
, rb
, "TARG_SESS_STATE_ACTIVE\n");
560 case TARG_SESS_STATE_LOGGED_IN
:
561 rb
+= sysfs_emit_at(page
, rb
, "TARG_SESS_STATE_LOGGED_IN\n");
563 case TARG_SESS_STATE_FAILED
:
564 rb
+= sysfs_emit_at(page
, rb
, "TARG_SESS_STATE_FAILED\n");
566 case TARG_SESS_STATE_IN_CONTINUE
:
567 rb
+= sysfs_emit_at(page
, rb
, "TARG_SESS_STATE_IN_CONTINUE\n");
570 rb
+= sysfs_emit_at(page
, rb
, "ERROR: Unknown Session"
575 rb
+= sysfs_emit_at(page
, rb
, "---------------------[iSCSI Session"
576 " Values]-----------------------\n");
577 rb
+= sysfs_emit_at(page
, rb
, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
578 " : MaxCmdSN : ITT : TTT\n");
579 max_cmd_sn
= (u32
) atomic_read(&sess
->max_cmd_sn
);
580 rb
+= sysfs_emit_at(page
, rb
, " 0x%08x 0x%08x 0x%08x 0x%08x"
583 (max_cmd_sn
- sess
->exp_cmd_sn
) + 1,
584 sess
->exp_cmd_sn
, max_cmd_sn
,
585 sess
->init_task_tag
, sess
->targ_xfer_tag
);
586 rb
+= sysfs_emit_at(page
, rb
, "----------------------[iSCSI"
587 " Connections]-------------------------\n");
589 spin_lock(&sess
->conn_lock
);
590 list_for_each_entry(conn
, &sess
->sess_conn_list
, conn_list
) {
591 rb
+= sysfs_emit_at(page
, rb
, "CID: %hu Connection"
592 " State: ", conn
->cid
);
593 switch (conn
->conn_state
) {
594 case TARG_CONN_STATE_FREE
:
595 rb
+= sysfs_emit_at(page
, rb
,
596 "TARG_CONN_STATE_FREE\n");
598 case TARG_CONN_STATE_XPT_UP
:
599 rb
+= sysfs_emit_at(page
, rb
,
600 "TARG_CONN_STATE_XPT_UP\n");
602 case TARG_CONN_STATE_IN_LOGIN
:
603 rb
+= sysfs_emit_at(page
, rb
,
604 "TARG_CONN_STATE_IN_LOGIN\n");
606 case TARG_CONN_STATE_LOGGED_IN
:
607 rb
+= sysfs_emit_at(page
, rb
,
608 "TARG_CONN_STATE_LOGGED_IN\n");
610 case TARG_CONN_STATE_IN_LOGOUT
:
611 rb
+= sysfs_emit_at(page
, rb
,
612 "TARG_CONN_STATE_IN_LOGOUT\n");
614 case TARG_CONN_STATE_LOGOUT_REQUESTED
:
615 rb
+= sysfs_emit_at(page
, rb
,
616 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
618 case TARG_CONN_STATE_CLEANUP_WAIT
:
619 rb
+= sysfs_emit_at(page
, rb
,
620 "TARG_CONN_STATE_CLEANUP_WAIT\n");
623 rb
+= sysfs_emit_at(page
, rb
,
624 "ERROR: Unknown Connection State!\n");
628 rb
+= sysfs_emit_at(page
, rb
, " Address %pISc %s", &conn
->login_sockaddr
,
629 (conn
->network_transport
== ISCSI_TCP
) ?
631 rb
+= sysfs_emit_at(page
, rb
, " StatSN: 0x%08x\n",
634 spin_unlock(&sess
->conn_lock
);
636 spin_unlock_bh(&se_nacl
->nacl_sess_lock
);
641 static ssize_t
lio_target_nacl_cmdsn_depth_show(struct config_item
*item
,
644 return sysfs_emit(page
, "%u\n", acl_to_nacl(item
)->queue_depth
);
647 static ssize_t
lio_target_nacl_cmdsn_depth_store(struct config_item
*item
,
648 const char *page
, size_t count
)
650 struct se_node_acl
*se_nacl
= acl_to_nacl(item
);
651 struct se_portal_group
*se_tpg
= se_nacl
->se_tpg
;
652 struct iscsi_portal_group
*tpg
= to_iscsi_tpg(se_tpg
);
653 struct config_item
*acl_ci
, *tpg_ci
, *wwn_ci
;
657 ret
= kstrtou32(page
, 0, &cmdsn_depth
);
660 if (cmdsn_depth
> TA_DEFAULT_CMDSN_DEPTH_MAX
) {
661 pr_err("Passed cmdsn_depth: %u exceeds"
662 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth
,
663 TA_DEFAULT_CMDSN_DEPTH_MAX
);
666 acl_ci
= &se_nacl
->acl_group
.cg_item
;
668 pr_err("Unable to locatel acl_ci\n");
671 tpg_ci
= &acl_ci
->ci_parent
->ci_group
->cg_item
;
673 pr_err("Unable to locate tpg_ci\n");
676 wwn_ci
= &tpg_ci
->ci_group
->cg_item
;
678 pr_err("Unable to locate config_item wwn_ci\n");
682 if (iscsit_get_tpg(tpg
) < 0)
685 ret
= core_tpg_set_initiator_node_queue_depth(se_nacl
, cmdsn_depth
);
687 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
688 "InitiatorName: %s\n", config_item_name(wwn_ci
),
689 config_item_name(tpg_ci
), cmdsn_depth
,
690 config_item_name(acl_ci
));
693 return (!ret
) ? count
: (ssize_t
)ret
;
696 static ssize_t
lio_target_nacl_tag_show(struct config_item
*item
, char *page
)
698 return snprintf(page
, PAGE_SIZE
, "%s", acl_to_nacl(item
)->acl_tag
);
701 static ssize_t
lio_target_nacl_tag_store(struct config_item
*item
,
702 const char *page
, size_t count
)
704 struct se_node_acl
*se_nacl
= acl_to_nacl(item
);
707 ret
= core_tpg_set_initiator_node_tag(se_nacl
->se_tpg
, se_nacl
, page
);
714 CONFIGFS_ATTR_RO(lio_target_nacl_
, info
);
715 CONFIGFS_ATTR(lio_target_nacl_
, cmdsn_depth
);
716 CONFIGFS_ATTR(lio_target_nacl_
, tag
);
718 static struct configfs_attribute
*lio_target_initiator_attrs
[] = {
719 &lio_target_nacl_attr_info
,
720 &lio_target_nacl_attr_cmdsn_depth
,
721 &lio_target_nacl_attr_tag
,
725 static int lio_target_init_nodeacl(struct se_node_acl
*se_nacl
,
728 struct iscsi_node_acl
*acl
= to_iscsi_nacl(se_nacl
);
730 config_group_init_type_name(&acl
->node_stat_grps
.iscsi_sess_stats_group
,
731 "iscsi_sess_stats", &iscsi_stat_sess_cit
);
732 configfs_add_default_group(&acl
->node_stat_grps
.iscsi_sess_stats_group
,
733 &se_nacl
->acl_fabric_stat_group
);
737 /* End items for lio_target_acl_cit */
739 /* Start items for lio_target_tpg_attrib_cit */
741 #define DEF_TPG_ATTRIB(name) \
743 static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \
746 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
747 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg); \
750 if (iscsit_get_tpg(tpg) < 0) \
753 rb = sysfs_emit(page, "%u\n", tpg->tpg_attrib.name); \
754 iscsit_put_tpg(tpg); \
758 static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
759 const char *page, size_t count) \
761 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
762 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg); \
766 if (iscsit_get_tpg(tpg) < 0) \
769 ret = kstrtou32(page, 0, &val); \
772 ret = iscsit_ta_##name(tpg, val); \
776 iscsit_put_tpg(tpg); \
779 iscsit_put_tpg(tpg); \
782 CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
784 DEF_TPG_ATTRIB(authentication
);
785 DEF_TPG_ATTRIB(login_timeout
);
786 DEF_TPG_ATTRIB(generate_node_acls
);
787 DEF_TPG_ATTRIB(default_cmdsn_depth
);
788 DEF_TPG_ATTRIB(cache_dynamic_acls
);
789 DEF_TPG_ATTRIB(demo_mode_write_protect
);
790 DEF_TPG_ATTRIB(prod_mode_write_protect
);
791 DEF_TPG_ATTRIB(demo_mode_discovery
);
792 DEF_TPG_ATTRIB(default_erl
);
793 DEF_TPG_ATTRIB(t10_pi
);
794 DEF_TPG_ATTRIB(fabric_prot_type
);
795 DEF_TPG_ATTRIB(tpg_enabled_sendtargets
);
796 DEF_TPG_ATTRIB(login_keys_workaround
);
798 static struct configfs_attribute
*lio_target_tpg_attrib_attrs
[] = {
799 &iscsi_tpg_attrib_attr_authentication
,
800 &iscsi_tpg_attrib_attr_login_timeout
,
801 &iscsi_tpg_attrib_attr_generate_node_acls
,
802 &iscsi_tpg_attrib_attr_default_cmdsn_depth
,
803 &iscsi_tpg_attrib_attr_cache_dynamic_acls
,
804 &iscsi_tpg_attrib_attr_demo_mode_write_protect
,
805 &iscsi_tpg_attrib_attr_prod_mode_write_protect
,
806 &iscsi_tpg_attrib_attr_demo_mode_discovery
,
807 &iscsi_tpg_attrib_attr_default_erl
,
808 &iscsi_tpg_attrib_attr_t10_pi
,
809 &iscsi_tpg_attrib_attr_fabric_prot_type
,
810 &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets
,
811 &iscsi_tpg_attrib_attr_login_keys_workaround
,
815 /* End items for lio_target_tpg_attrib_cit */
817 /* Start items for lio_target_tpg_auth_cit */
819 #define __DEF_TPG_AUTH_STR(prefix, name, flags) \
820 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
823 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg); \
824 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
826 if (!capable(CAP_SYS_ADMIN)) \
829 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
832 static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
833 const char *page, size_t count) \
835 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg); \
836 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
838 if (!capable(CAP_SYS_ADMIN)) \
841 snprintf(auth->name, sizeof(auth->name), "%s", page); \
842 if (!(strncmp("NULL", auth->name, 4))) \
843 auth->naf_flags &= ~flags; \
845 auth->naf_flags |= flags; \
847 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
848 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
849 auth->authenticate_target = 1; \
851 auth->authenticate_target = 0; \
856 #define DEF_TPG_AUTH_STR(name, flags) \
857 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
858 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
861 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
864 static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \
865 const char *page, size_t count) \
867 return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
870 CONFIGFS_ATTR(iscsi_tpg_auth_, name);
873 DEF_TPG_AUTH_STR(userid
, NAF_USERID_SET
);
874 DEF_TPG_AUTH_STR(password
, NAF_PASSWORD_SET
);
875 DEF_TPG_AUTH_STR(userid_mutual
, NAF_USERID_IN_SET
);
876 DEF_TPG_AUTH_STR(password_mutual
, NAF_PASSWORD_IN_SET
);
878 #define __DEF_TPG_AUTH_INT(prefix, name) \
879 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
882 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg); \
883 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
885 if (!capable(CAP_SYS_ADMIN)) \
888 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
891 #define DEF_TPG_AUTH_INT(name) \
892 __DEF_TPG_AUTH_INT(tpg_auth, name) \
893 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
896 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
898 CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
900 DEF_TPG_AUTH_INT(authenticate_target
);
902 static struct configfs_attribute
*lio_target_tpg_auth_attrs
[] = {
903 &iscsi_tpg_auth_attr_userid
,
904 &iscsi_tpg_auth_attr_password
,
905 &iscsi_tpg_auth_attr_authenticate_target
,
906 &iscsi_tpg_auth_attr_userid_mutual
,
907 &iscsi_tpg_auth_attr_password_mutual
,
911 /* End items for lio_target_tpg_auth_cit */
913 /* Start items for lio_target_tpg_param_cit */
915 #define DEF_TPG_PARAM(name) \
916 static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \
919 struct se_portal_group *se_tpg = param_to_tpg(item); \
920 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg); \
921 struct iscsi_param *param; \
924 if (iscsit_get_tpg(tpg) < 0) \
927 param = iscsi_find_param_from_key(__stringify(name), \
930 iscsit_put_tpg(tpg); \
933 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
935 iscsit_put_tpg(tpg); \
938 static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
939 const char *page, size_t count) \
941 struct se_portal_group *se_tpg = param_to_tpg(item); \
942 struct iscsi_portal_group *tpg = to_iscsi_tpg(se_tpg); \
946 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
949 len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
950 if (isspace(buf[len-1])) \
951 buf[len-1] = '\0'; /* Kill newline */ \
953 if (iscsit_get_tpg(tpg) < 0) { \
958 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
963 iscsit_put_tpg(tpg); \
967 iscsit_put_tpg(tpg); \
970 CONFIGFS_ATTR(iscsi_tpg_param_, name)
972 DEF_TPG_PARAM(AuthMethod
);
973 DEF_TPG_PARAM(HeaderDigest
);
974 DEF_TPG_PARAM(DataDigest
);
975 DEF_TPG_PARAM(MaxConnections
);
976 DEF_TPG_PARAM(TargetAlias
);
977 DEF_TPG_PARAM(InitialR2T
);
978 DEF_TPG_PARAM(ImmediateData
);
979 DEF_TPG_PARAM(MaxRecvDataSegmentLength
);
980 DEF_TPG_PARAM(MaxXmitDataSegmentLength
);
981 DEF_TPG_PARAM(MaxBurstLength
);
982 DEF_TPG_PARAM(FirstBurstLength
);
983 DEF_TPG_PARAM(DefaultTime2Wait
);
984 DEF_TPG_PARAM(DefaultTime2Retain
);
985 DEF_TPG_PARAM(MaxOutstandingR2T
);
986 DEF_TPG_PARAM(DataPDUInOrder
);
987 DEF_TPG_PARAM(DataSequenceInOrder
);
988 DEF_TPG_PARAM(ErrorRecoveryLevel
);
989 DEF_TPG_PARAM(IFMarker
);
990 DEF_TPG_PARAM(OFMarker
);
991 DEF_TPG_PARAM(IFMarkInt
);
992 DEF_TPG_PARAM(OFMarkInt
);
994 static struct configfs_attribute
*lio_target_tpg_param_attrs
[] = {
995 &iscsi_tpg_param_attr_AuthMethod
,
996 &iscsi_tpg_param_attr_HeaderDigest
,
997 &iscsi_tpg_param_attr_DataDigest
,
998 &iscsi_tpg_param_attr_MaxConnections
,
999 &iscsi_tpg_param_attr_TargetAlias
,
1000 &iscsi_tpg_param_attr_InitialR2T
,
1001 &iscsi_tpg_param_attr_ImmediateData
,
1002 &iscsi_tpg_param_attr_MaxRecvDataSegmentLength
,
1003 &iscsi_tpg_param_attr_MaxXmitDataSegmentLength
,
1004 &iscsi_tpg_param_attr_MaxBurstLength
,
1005 &iscsi_tpg_param_attr_FirstBurstLength
,
1006 &iscsi_tpg_param_attr_DefaultTime2Wait
,
1007 &iscsi_tpg_param_attr_DefaultTime2Retain
,
1008 &iscsi_tpg_param_attr_MaxOutstandingR2T
,
1009 &iscsi_tpg_param_attr_DataPDUInOrder
,
1010 &iscsi_tpg_param_attr_DataSequenceInOrder
,
1011 &iscsi_tpg_param_attr_ErrorRecoveryLevel
,
1012 &iscsi_tpg_param_attr_IFMarker
,
1013 &iscsi_tpg_param_attr_OFMarker
,
1014 &iscsi_tpg_param_attr_IFMarkInt
,
1015 &iscsi_tpg_param_attr_OFMarkInt
,
1019 /* End items for lio_target_tpg_param_cit */
1021 /* Start items for lio_target_tpg_cit */
1023 static ssize_t
lio_target_tpg_dynamic_sessions_show(struct config_item
*item
,
1026 return target_show_dynamic_sessions(to_tpg(item
), page
);
1029 CONFIGFS_ATTR_RO(lio_target_tpg_
, dynamic_sessions
);
1031 static struct configfs_attribute
*lio_target_tpg_attrs
[] = {
1032 &lio_target_tpg_attr_dynamic_sessions
,
1036 /* End items for lio_target_tpg_cit */
1038 /* Start items for lio_target_tiqn_cit */
1040 static struct se_portal_group
*lio_target_tiqn_addtpg(struct se_wwn
*wwn
,
1043 struct iscsi_portal_group
*tpg
;
1044 struct iscsi_tiqn
*tiqn
;
1049 tiqn
= container_of(wwn
, struct iscsi_tiqn
, tiqn_wwn
);
1051 * Only tpgt_# directory groups can be created below
1052 * target/iscsi/iqn.superturodiskarry/
1054 tpgt_str
= strstr(name
, "tpgt_");
1056 pr_err("Unable to locate \"tpgt_#\" directory"
1060 tpgt_str
+= 5; /* Skip ahead of "tpgt_" */
1061 ret
= kstrtou16(tpgt_str
, 0, &tpgt
);
1065 tpg
= iscsit_alloc_portal_group(tiqn
, tpgt
);
1069 ret
= core_tpg_register(wwn
, &tpg
->tpg_se_tpg
, SCSI_PROTOCOL_ISCSI
);
1073 ret
= iscsit_tpg_add_portal_group(tiqn
, tpg
);
1077 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn
->tiqn
);
1078 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1080 return &tpg
->tpg_se_tpg
;
1082 core_tpg_deregister(&tpg
->tpg_se_tpg
);
1088 static int lio_target_tiqn_enabletpg(struct se_portal_group
*se_tpg
,
1091 struct iscsi_portal_group
*tpg
= to_iscsi_tpg(se_tpg
);
1094 ret
= iscsit_get_tpg(tpg
);
1099 ret
= iscsit_tpg_enable_portal_group(tpg
);
1104 * iscsit_tpg_disable_portal_group() assumes force=1
1106 ret
= iscsit_tpg_disable_portal_group(tpg
, 1);
1111 iscsit_put_tpg(tpg
);
1114 iscsit_put_tpg(tpg
);
1118 static void lio_target_tiqn_deltpg(struct se_portal_group
*se_tpg
)
1120 struct iscsi_portal_group
*tpg
;
1121 struct iscsi_tiqn
*tiqn
;
1123 tpg
= to_iscsi_tpg(se_tpg
);
1124 tiqn
= tpg
->tpg_tiqn
;
1126 * iscsit_tpg_del_portal_group() assumes force=1
1128 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1129 iscsit_tpg_del_portal_group(tiqn
, tpg
, 1);
1132 /* End items for lio_target_tiqn_cit */
1134 /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1136 static ssize_t
lio_target_wwn_lio_version_show(struct config_item
*item
,
1139 return sysfs_emit(page
, "Datera Inc. iSCSI Target %s\n", ISCSIT_VERSION
);
1142 CONFIGFS_ATTR_RO(lio_target_wwn_
, lio_version
);
1144 static ssize_t
lio_target_wwn_cpus_allowed_list_show(
1145 struct config_item
*item
, char *page
)
1147 return sysfs_emit(page
, "%*pbl\n",
1148 cpumask_pr_args(iscsit_global
->allowed_cpumask
));
1151 static ssize_t
lio_target_wwn_cpus_allowed_list_store(
1152 struct config_item
*item
, const char *page
, size_t count
)
1156 cpumask_var_t new_allowed_cpumask
;
1158 if (!zalloc_cpumask_var(&new_allowed_cpumask
, GFP_KERNEL
))
1161 orig
= kstrdup(page
, GFP_KERNEL
);
1163 goto out_free_cpumask
;
1165 ret
= cpulist_parse(orig
, new_allowed_cpumask
);
1167 cpumask_copy(iscsit_global
->allowed_cpumask
,
1168 new_allowed_cpumask
);
1172 free_cpumask_var(new_allowed_cpumask
);
1174 return ret
? ret
: count
;
1177 CONFIGFS_ATTR(lio_target_wwn_
, cpus_allowed_list
);
1179 static struct configfs_attribute
*lio_target_wwn_attrs
[] = {
1180 &lio_target_wwn_attr_lio_version
,
1181 &lio_target_wwn_attr_cpus_allowed_list
,
1185 static struct se_wwn
*lio_target_call_coreaddtiqn(
1186 struct target_fabric_configfs
*tf
,
1187 struct config_group
*group
,
1190 struct iscsi_tiqn
*tiqn
;
1192 tiqn
= iscsit_add_tiqn((unsigned char *)name
);
1194 return ERR_CAST(tiqn
);
1196 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn
->tiqn
);
1197 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1199 return &tiqn
->tiqn_wwn
;
1202 static void lio_target_add_wwn_groups(struct se_wwn
*wwn
)
1204 struct iscsi_tiqn
*tiqn
= container_of(wwn
, struct iscsi_tiqn
, tiqn_wwn
);
1206 config_group_init_type_name(&tiqn
->tiqn_stat_grps
.iscsi_instance_group
,
1207 "iscsi_instance", &iscsi_stat_instance_cit
);
1208 configfs_add_default_group(&tiqn
->tiqn_stat_grps
.iscsi_instance_group
,
1209 &tiqn
->tiqn_wwn
.fabric_stat_group
);
1211 config_group_init_type_name(&tiqn
->tiqn_stat_grps
.iscsi_sess_err_group
,
1212 "iscsi_sess_err", &iscsi_stat_sess_err_cit
);
1213 configfs_add_default_group(&tiqn
->tiqn_stat_grps
.iscsi_sess_err_group
,
1214 &tiqn
->tiqn_wwn
.fabric_stat_group
);
1216 config_group_init_type_name(&tiqn
->tiqn_stat_grps
.iscsi_tgt_attr_group
,
1217 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit
);
1218 configfs_add_default_group(&tiqn
->tiqn_stat_grps
.iscsi_tgt_attr_group
,
1219 &tiqn
->tiqn_wwn
.fabric_stat_group
);
1221 config_group_init_type_name(&tiqn
->tiqn_stat_grps
.iscsi_login_stats_group
,
1222 "iscsi_login_stats", &iscsi_stat_login_cit
);
1223 configfs_add_default_group(&tiqn
->tiqn_stat_grps
.iscsi_login_stats_group
,
1224 &tiqn
->tiqn_wwn
.fabric_stat_group
);
1226 config_group_init_type_name(&tiqn
->tiqn_stat_grps
.iscsi_logout_stats_group
,
1227 "iscsi_logout_stats", &iscsi_stat_logout_cit
);
1228 configfs_add_default_group(&tiqn
->tiqn_stat_grps
.iscsi_logout_stats_group
,
1229 &tiqn
->tiqn_wwn
.fabric_stat_group
);
1232 static void lio_target_call_coredeltiqn(
1235 struct iscsi_tiqn
*tiqn
= container_of(wwn
, struct iscsi_tiqn
, tiqn_wwn
);
1237 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1239 iscsit_del_tiqn(tiqn
);
1242 /* End LIO-Target TIQN struct contig_lio_target_cit */
1244 /* Start lio_target_discovery_auth_cit */
1246 #define DEF_DISC_AUTH_STR(name, flags) \
1247 __DEF_NACL_AUTH_STR(disc, name, flags) \
1248 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1250 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
1253 static ssize_t iscsi_disc_##name##_store(struct config_item *item, \
1254 const char *page, size_t count) \
1256 return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \
1260 CONFIGFS_ATTR(iscsi_disc_, name)
1262 DEF_DISC_AUTH_STR(userid
, NAF_USERID_SET
);
1263 DEF_DISC_AUTH_STR(password
, NAF_PASSWORD_SET
);
1264 DEF_DISC_AUTH_STR(userid_mutual
, NAF_USERID_IN_SET
);
1265 DEF_DISC_AUTH_STR(password_mutual
, NAF_PASSWORD_IN_SET
);
1267 #define DEF_DISC_AUTH_INT(name) \
1268 __DEF_NACL_AUTH_INT(disc, name) \
1269 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1271 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
1274 CONFIGFS_ATTR_RO(iscsi_disc_, name)
1276 DEF_DISC_AUTH_INT(authenticate_target
);
1279 static ssize_t
iscsi_disc_enforce_discovery_auth_show(struct config_item
*item
,
1282 struct iscsi_node_auth
*discovery_auth
= &iscsit_global
->discovery_acl
.node_auth
;
1284 return sysfs_emit(page
, "%d\n", discovery_auth
->enforce_discovery_auth
);
1287 static ssize_t
iscsi_disc_enforce_discovery_auth_store(struct config_item
*item
,
1288 const char *page
, size_t count
)
1290 struct iscsi_param
*param
;
1291 struct iscsi_portal_group
*discovery_tpg
= iscsit_global
->discovery_tpg
;
1295 err
= kstrtou32(page
, 0, &op
);
1298 if ((op
!= 1) && (op
!= 0)) {
1299 pr_err("Illegal value for enforce_discovery_auth:"
1304 if (!discovery_tpg
) {
1305 pr_err("iscsit_global->discovery_tpg is NULL\n");
1309 param
= iscsi_find_param_from_key(AUTHMETHOD
,
1310 discovery_tpg
->param_list
);
1316 * Reset the AuthMethod key to CHAP.
1318 if (iscsi_update_param_value(param
, CHAP
) < 0)
1321 discovery_tpg
->tpg_attrib
.authentication
= 1;
1322 iscsit_global
->discovery_acl
.node_auth
.enforce_discovery_auth
= 1;
1323 pr_debug("LIO-CORE[0] Successfully enabled"
1324 " authentication enforcement for iSCSI"
1325 " Discovery TPG\n");
1328 * Reset the AuthMethod key to CHAP,None
1330 if (iscsi_update_param_value(param
, "CHAP,None") < 0)
1333 discovery_tpg
->tpg_attrib
.authentication
= 0;
1334 iscsit_global
->discovery_acl
.node_auth
.enforce_discovery_auth
= 0;
1335 pr_debug("LIO-CORE[0] Successfully disabled"
1336 " authentication enforcement for iSCSI"
1337 " Discovery TPG\n");
1343 CONFIGFS_ATTR(iscsi_disc_
, enforce_discovery_auth
);
1345 static struct configfs_attribute
*lio_target_discovery_auth_attrs
[] = {
1346 &iscsi_disc_attr_userid
,
1347 &iscsi_disc_attr_password
,
1348 &iscsi_disc_attr_authenticate_target
,
1349 &iscsi_disc_attr_userid_mutual
,
1350 &iscsi_disc_attr_password_mutual
,
1351 &iscsi_disc_attr_enforce_discovery_auth
,
1355 /* End lio_target_discovery_auth_cit */
1357 /* Start functions for target_core_fabric_ops */
1359 static int iscsi_get_cmd_state(struct se_cmd
*se_cmd
)
1361 struct iscsit_cmd
*cmd
= container_of(se_cmd
, struct iscsit_cmd
, se_cmd
);
1363 return cmd
->i_state
;
1366 static u32
lio_sess_get_index(struct se_session
*se_sess
)
1368 struct iscsit_session
*sess
= se_sess
->fabric_sess_ptr
;
1370 return sess
->session_index
;
1373 static u32
lio_sess_get_initiator_sid(
1374 struct se_session
*se_sess
,
1378 struct iscsit_session
*sess
= se_sess
->fabric_sess_ptr
;
1380 * iSCSI Initiator Session Identifier from RFC-3720.
1382 return snprintf(buf
, size
, "%6phN", sess
->isid
);
1385 static int lio_queue_data_in(struct se_cmd
*se_cmd
)
1387 struct iscsit_cmd
*cmd
= container_of(se_cmd
, struct iscsit_cmd
, se_cmd
);
1388 struct iscsit_conn
*conn
= cmd
->conn
;
1390 cmd
->i_state
= ISTATE_SEND_DATAIN
;
1391 return conn
->conn_transport
->iscsit_queue_data_in(conn
, cmd
);
1394 static int lio_write_pending(struct se_cmd
*se_cmd
)
1396 struct iscsit_cmd
*cmd
= container_of(se_cmd
, struct iscsit_cmd
, se_cmd
);
1397 struct iscsit_conn
*conn
= cmd
->conn
;
1399 if (!cmd
->immediate_data
&& !cmd
->unsolicited_data
)
1400 return conn
->conn_transport
->iscsit_get_dataout(conn
, cmd
, false);
1405 static int lio_queue_status(struct se_cmd
*se_cmd
)
1407 struct iscsit_cmd
*cmd
= container_of(se_cmd
, struct iscsit_cmd
, se_cmd
);
1408 struct iscsit_conn
*conn
= cmd
->conn
;
1410 cmd
->i_state
= ISTATE_SEND_STATUS
;
1412 if (cmd
->se_cmd
.scsi_status
|| cmd
->sense_reason
) {
1413 return iscsit_add_cmd_to_response_queue(cmd
, conn
, cmd
->i_state
);
1415 return conn
->conn_transport
->iscsit_queue_status(conn
, cmd
);
1418 static void lio_queue_tm_rsp(struct se_cmd
*se_cmd
)
1420 struct iscsit_cmd
*cmd
= container_of(se_cmd
, struct iscsit_cmd
, se_cmd
);
1422 cmd
->i_state
= ISTATE_SEND_TASKMGTRSP
;
1423 iscsit_add_cmd_to_response_queue(cmd
, cmd
->conn
, cmd
->i_state
);
1426 static void lio_aborted_task(struct se_cmd
*se_cmd
)
1428 struct iscsit_cmd
*cmd
= container_of(se_cmd
, struct iscsit_cmd
, se_cmd
);
1430 cmd
->conn
->conn_transport
->iscsit_aborted_task(cmd
->conn
, cmd
);
1433 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group
*se_tpg
)
1435 return to_iscsi_tpg(se_tpg
)->tpg_tiqn
->tiqn
;
1438 static u16
lio_tpg_get_tag(struct se_portal_group
*se_tpg
)
1440 return to_iscsi_tpg(se_tpg
)->tpgt
;
1443 static u32
lio_tpg_get_default_depth(struct se_portal_group
*se_tpg
)
1445 return to_iscsi_tpg(se_tpg
)->tpg_attrib
.default_cmdsn_depth
;
1448 static int lio_tpg_check_demo_mode(struct se_portal_group
*se_tpg
)
1450 return to_iscsi_tpg(se_tpg
)->tpg_attrib
.generate_node_acls
;
1453 static int lio_tpg_check_demo_mode_cache(struct se_portal_group
*se_tpg
)
1455 return to_iscsi_tpg(se_tpg
)->tpg_attrib
.cache_dynamic_acls
;
1458 static int lio_tpg_check_demo_mode_write_protect(
1459 struct se_portal_group
*se_tpg
)
1461 return to_iscsi_tpg(se_tpg
)->tpg_attrib
.demo_mode_write_protect
;
1464 static int lio_tpg_check_prod_mode_write_protect(
1465 struct se_portal_group
*se_tpg
)
1467 return to_iscsi_tpg(se_tpg
)->tpg_attrib
.prod_mode_write_protect
;
1470 static int lio_tpg_check_prot_fabric_only(
1471 struct se_portal_group
*se_tpg
)
1474 * Only report fabric_prot_type if t10_pi has also been enabled
1475 * for incoming ib_isert sessions.
1477 if (!to_iscsi_tpg(se_tpg
)->tpg_attrib
.t10_pi
)
1479 return to_iscsi_tpg(se_tpg
)->tpg_attrib
.fabric_prot_type
;
1483 * This function calls iscsit_inc_session_usage_count() on the
1484 * struct iscsit_session in question.
1486 static void lio_tpg_close_session(struct se_session
*se_sess
)
1488 struct iscsit_session
*sess
= se_sess
->fabric_sess_ptr
;
1489 struct se_portal_group
*se_tpg
= &sess
->tpg
->tpg_se_tpg
;
1491 spin_lock_bh(&se_tpg
->session_lock
);
1492 spin_lock(&sess
->conn_lock
);
1493 if (atomic_read(&sess
->session_fall_back_to_erl0
) ||
1494 atomic_read(&sess
->session_logout
) ||
1495 atomic_read(&sess
->session_close
) ||
1496 (sess
->time2retain_timer_flags
& ISCSI_TF_EXPIRED
)) {
1497 spin_unlock(&sess
->conn_lock
);
1498 spin_unlock_bh(&se_tpg
->session_lock
);
1501 iscsit_inc_session_usage_count(sess
);
1502 atomic_set(&sess
->session_reinstatement
, 1);
1503 atomic_set(&sess
->session_fall_back_to_erl0
, 1);
1504 atomic_set(&sess
->session_close
, 1);
1505 spin_unlock(&sess
->conn_lock
);
1507 iscsit_stop_time2retain_timer(sess
);
1508 spin_unlock_bh(&se_tpg
->session_lock
);
1510 iscsit_stop_session(sess
, 1, 1);
1511 iscsit_dec_session_usage_count(sess
);
1514 static u32
lio_tpg_get_inst_index(struct se_portal_group
*se_tpg
)
1516 return to_iscsi_tpg(se_tpg
)->tpg_tiqn
->tiqn_index
;
1519 static void lio_set_default_node_attributes(struct se_node_acl
*se_acl
)
1521 struct iscsi_node_acl
*acl
= to_iscsi_nacl(se_acl
);
1522 struct se_portal_group
*se_tpg
= se_acl
->se_tpg
;
1523 struct iscsi_portal_group
*tpg
= to_iscsi_tpg(se_tpg
);
1525 acl
->node_attrib
.nacl
= acl
;
1526 iscsit_set_default_node_attribues(acl
, tpg
);
1529 static int lio_check_stop_free(struct se_cmd
*se_cmd
)
1531 return target_put_sess_cmd(se_cmd
);
1534 static void lio_release_cmd(struct se_cmd
*se_cmd
)
1536 struct iscsit_cmd
*cmd
= container_of(se_cmd
, struct iscsit_cmd
, se_cmd
);
1538 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd
);
1539 iscsit_release_cmd(cmd
);
1542 const struct target_core_fabric_ops iscsi_ops
= {
1543 .module
= THIS_MODULE
,
1544 .fabric_alias
= "iscsi",
1545 .fabric_name
= "iSCSI",
1546 .node_acl_size
= sizeof(struct iscsi_node_acl
),
1547 .tpg_get_wwn
= lio_tpg_get_endpoint_wwn
,
1548 .tpg_get_tag
= lio_tpg_get_tag
,
1549 .tpg_get_default_depth
= lio_tpg_get_default_depth
,
1550 .tpg_check_demo_mode
= lio_tpg_check_demo_mode
,
1551 .tpg_check_demo_mode_cache
= lio_tpg_check_demo_mode_cache
,
1552 .tpg_check_demo_mode_write_protect
=
1553 lio_tpg_check_demo_mode_write_protect
,
1554 .tpg_check_prod_mode_write_protect
=
1555 lio_tpg_check_prod_mode_write_protect
,
1556 .tpg_check_prot_fabric_only
= &lio_tpg_check_prot_fabric_only
,
1557 .tpg_get_inst_index
= lio_tpg_get_inst_index
,
1558 .check_stop_free
= lio_check_stop_free
,
1559 .release_cmd
= lio_release_cmd
,
1560 .close_session
= lio_tpg_close_session
,
1561 .sess_get_index
= lio_sess_get_index
,
1562 .sess_get_initiator_sid
= lio_sess_get_initiator_sid
,
1563 .write_pending
= lio_write_pending
,
1564 .set_default_node_attributes
= lio_set_default_node_attributes
,
1565 .get_cmd_state
= iscsi_get_cmd_state
,
1566 .queue_data_in
= lio_queue_data_in
,
1567 .queue_status
= lio_queue_status
,
1568 .queue_tm_rsp
= lio_queue_tm_rsp
,
1569 .aborted_task
= lio_aborted_task
,
1570 .fabric_make_wwn
= lio_target_call_coreaddtiqn
,
1571 .fabric_drop_wwn
= lio_target_call_coredeltiqn
,
1572 .add_wwn_groups
= lio_target_add_wwn_groups
,
1573 .fabric_make_tpg
= lio_target_tiqn_addtpg
,
1574 .fabric_enable_tpg
= lio_target_tiqn_enabletpg
,
1575 .fabric_drop_tpg
= lio_target_tiqn_deltpg
,
1576 .fabric_make_np
= lio_target_call_addnptotpg
,
1577 .fabric_drop_np
= lio_target_call_delnpfromtpg
,
1578 .fabric_init_nodeacl
= lio_target_init_nodeacl
,
1580 .tfc_discovery_attrs
= lio_target_discovery_auth_attrs
,
1581 .tfc_wwn_attrs
= lio_target_wwn_attrs
,
1582 .tfc_tpg_base_attrs
= lio_target_tpg_attrs
,
1583 .tfc_tpg_attrib_attrs
= lio_target_tpg_attrib_attrs
,
1584 .tfc_tpg_auth_attrs
= lio_target_tpg_auth_attrs
,
1585 .tfc_tpg_param_attrs
= lio_target_tpg_param_attrs
,
1586 .tfc_tpg_np_base_attrs
= lio_target_portal_attrs
,
1587 .tfc_tpg_nacl_base_attrs
= lio_target_initiator_attrs
,
1588 .tfc_tpg_nacl_attrib_attrs
= lio_target_nacl_attrib_attrs
,
1589 .tfc_tpg_nacl_auth_attrs
= lio_target_nacl_auth_attrs
,
1590 .tfc_tpg_nacl_param_attrs
= lio_target_nacl_param_attrs
,
1592 .write_pending_must_be_called
= 1,
1594 .default_submit_type
= TARGET_DIRECT_SUBMIT
,
1595 .direct_submit_supp
= 1,