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_sctp_show(struct config_item *item, char *page)
48 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
49 struct iscsi_tpg_np *tpg_np_sctp;
52 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
54 rb = sprintf(page, "1\n");
56 rb = sprintf(page, "0\n");
61 static ssize_t lio_target_np_sctp_store(struct config_item *item,
62 const char *page, size_t count)
64 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
66 struct iscsi_portal_group *tpg;
67 struct iscsi_tpg_np *tpg_np_sctp = NULL;
71 ret = kstrtou32(page, 0, &op);
74 if ((op != 1) && (op != 0)) {
75 pr_err("Illegal value for tpg_enable: %u\n", op);
80 pr_err("Unable to locate struct iscsi_np from"
81 " struct iscsi_tpg_np\n");
86 if (iscsit_get_tpg(tpg) < 0)
91 * Use existing np->np_sockaddr for SCTP network portal reference
93 tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
94 tpg_np, ISCSI_SCTP_TCP);
95 if (!tpg_np_sctp || IS_ERR(tpg_np_sctp))
98 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
102 ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp);
114 static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
116 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
117 struct iscsi_tpg_np *tpg_np_iser;
120 tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
122 rb = sprintf(page, "1\n");
124 rb = sprintf(page, "0\n");
129 static ssize_t lio_target_np_iser_store(struct config_item *item,
130 const char *page, size_t count)
132 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
134 struct iscsi_portal_group *tpg;
135 struct iscsi_tpg_np *tpg_np_iser = NULL;
140 op = simple_strtoul(page, &endptr, 0);
141 if ((op != 1) && (op != 0)) {
142 pr_err("Illegal value for tpg_enable: %u\n", op);
147 pr_err("Unable to locate struct iscsi_np from"
148 " struct iscsi_tpg_np\n");
153 if (iscsit_get_tpg(tpg) < 0)
157 rc = request_module("ib_isert");
159 pr_warn("Unable to request_module for ib_isert\n");
163 tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
164 tpg_np, ISCSI_INFINIBAND);
165 if (IS_ERR(tpg_np_iser)) {
166 rc = PTR_ERR(tpg_np_iser);
170 tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
172 rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser);
185 CONFIGFS_ATTR(lio_target_np_, sctp);
186 CONFIGFS_ATTR(lio_target_np_, iser);
188 static struct configfs_attribute *lio_target_portal_attrs[] = {
189 &lio_target_np_attr_sctp,
190 &lio_target_np_attr_iser,
194 /* Stop items for lio_target_portal_cit */
196 /* Start items for lio_target_np_cit */
198 #define MAX_PORTAL_LEN 256
200 static struct se_tpg_np *lio_target_call_addnptotpg(
201 struct se_portal_group *se_tpg,
202 struct config_group *group,
205 struct iscsi_portal_group *tpg;
206 struct iscsi_tpg_np *tpg_np;
207 char *str, *str2, *ip_str, *port_str;
208 struct sockaddr_storage sockaddr;
209 struct sockaddr_in *sock_in;
210 struct sockaddr_in6 *sock_in6;
213 char buf[MAX_PORTAL_LEN + 1];
215 if (strlen(name) > MAX_PORTAL_LEN) {
216 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
217 (int)strlen(name), MAX_PORTAL_LEN);
218 return ERR_PTR(-EOVERFLOW);
220 memset(buf, 0, MAX_PORTAL_LEN + 1);
221 snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
223 memset(&sockaddr, 0, sizeof(struct sockaddr_storage));
225 str = strstr(buf, "[");
229 str2 = strstr(str, "]");
231 pr_err("Unable to locate trailing \"]\""
232 " in IPv6 iSCSI network portal address\n");
233 return ERR_PTR(-EINVAL);
235 str++; /* Skip over leading "[" */
236 *str2 = '\0'; /* Terminate the unbracketed IPv6 address */
237 str2++; /* Skip over the \0 */
238 port_str = strstr(str2, ":");
240 pr_err("Unable to locate \":port\""
241 " in IPv6 iSCSI network portal address\n");
242 return ERR_PTR(-EINVAL);
244 *port_str = '\0'; /* Terminate string for IP */
245 port_str++; /* Skip over ":" */
247 ret = kstrtoul(port_str, 0, &port);
249 pr_err("kstrtoul() failed for port_str: %d\n", ret);
252 sock_in6 = (struct sockaddr_in6 *)&sockaddr;
253 sock_in6->sin6_family = AF_INET6;
254 sock_in6->sin6_port = htons((unsigned short)port);
255 ret = in6_pton(str, -1,
256 (void *)&sock_in6->sin6_addr.in6_u, -1, &end);
258 pr_err("in6_pton returned: %d\n", ret);
259 return ERR_PTR(-EINVAL);
262 str = ip_str = &buf[0];
263 port_str = strstr(ip_str, ":");
265 pr_err("Unable to locate \":port\""
266 " in IPv4 iSCSI network portal address\n");
267 return ERR_PTR(-EINVAL);
269 *port_str = '\0'; /* Terminate string for IP */
270 port_str++; /* Skip over ":" */
272 ret = kstrtoul(port_str, 0, &port);
274 pr_err("kstrtoul() failed for port_str: %d\n", ret);
277 sock_in = (struct sockaddr_in *)&sockaddr;
278 sock_in->sin_family = AF_INET;
279 sock_in->sin_port = htons((unsigned short)port);
280 sock_in->sin_addr.s_addr = in_aton(ip_str);
282 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
283 ret = iscsit_get_tpg(tpg);
285 return ERR_PTR(-EINVAL);
287 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
289 config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
292 * Assume ISCSI_TCP by default. Other network portals for other
295 * Traditional iSCSI over SCTP (initial support)
296 * iSER/TCP (TODO, hardware available)
297 * iSER/SCTP (TODO, software emulation with osc-iwarp)
298 * iSER/IB (TODO, hardware available)
300 * can be enabled with attributes under
301 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
304 tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
306 if (IS_ERR(tpg_np)) {
308 return ERR_CAST(tpg_np);
310 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
313 return &tpg_np->se_tpg_np;
316 static void lio_target_call_delnpfromtpg(
317 struct se_tpg_np *se_tpg_np)
319 struct iscsi_portal_group *tpg;
320 struct iscsi_tpg_np *tpg_np;
321 struct se_portal_group *se_tpg;
324 tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
326 ret = iscsit_get_tpg(tpg);
330 se_tpg = &tpg->tpg_se_tpg;
331 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
332 " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
333 tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
335 ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
339 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
344 /* End items for lio_target_np_cit */
346 /* Start items for lio_target_nacl_attrib_cit */
348 #define ISCSI_NACL_ATTR(name) \
349 static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
352 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
353 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
356 return sprintf(page, "%u\n", nacl->node_attrib.name); \
359 static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
360 const char *page, size_t count) \
362 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
363 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
368 ret = kstrtou32(page, 0, &val); \
371 ret = iscsit_na_##name(nacl, val); \
378 CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
380 ISCSI_NACL_ATTR(dataout_timeout);
381 ISCSI_NACL_ATTR(dataout_timeout_retries);
382 ISCSI_NACL_ATTR(default_erl);
383 ISCSI_NACL_ATTR(nopin_timeout);
384 ISCSI_NACL_ATTR(nopin_response_timeout);
385 ISCSI_NACL_ATTR(random_datain_pdu_offsets);
386 ISCSI_NACL_ATTR(random_datain_seq_offsets);
387 ISCSI_NACL_ATTR(random_r2t_offsets);
389 static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
390 &iscsi_nacl_attrib_attr_dataout_timeout,
391 &iscsi_nacl_attrib_attr_dataout_timeout_retries,
392 &iscsi_nacl_attrib_attr_default_erl,
393 &iscsi_nacl_attrib_attr_nopin_timeout,
394 &iscsi_nacl_attrib_attr_nopin_response_timeout,
395 &iscsi_nacl_attrib_attr_random_datain_pdu_offsets,
396 &iscsi_nacl_attrib_attr_random_datain_seq_offsets,
397 &iscsi_nacl_attrib_attr_random_r2t_offsets,
401 /* End items for lio_target_nacl_attrib_cit */
403 /* Start items for lio_target_nacl_auth_cit */
405 #define __DEF_NACL_AUTH_STR(prefix, name, flags) \
406 static ssize_t __iscsi_##prefix##_##name##_show( \
407 struct iscsi_node_acl *nacl, \
410 struct iscsi_node_auth *auth = &nacl->node_auth; \
412 if (!capable(CAP_SYS_ADMIN)) \
414 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
417 static ssize_t __iscsi_##prefix##_##name##_store( \
418 struct iscsi_node_acl *nacl, \
422 struct iscsi_node_auth *auth = &nacl->node_auth; \
424 if (!capable(CAP_SYS_ADMIN)) \
426 if (count >= sizeof(auth->name)) \
428 snprintf(auth->name, sizeof(auth->name), "%s", page); \
429 if (!strncmp("NULL", auth->name, 4)) \
430 auth->naf_flags &= ~flags; \
432 auth->naf_flags |= flags; \
434 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
435 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
436 auth->authenticate_target = 1; \
438 auth->authenticate_target = 0; \
443 #define DEF_NACL_AUTH_STR(name, flags) \
444 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
445 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
448 struct se_node_acl *nacl = auth_to_nacl(item); \
449 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
450 struct iscsi_node_acl, se_node_acl), page); \
452 static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \
453 const char *page, size_t count) \
455 struct se_node_acl *nacl = auth_to_nacl(item); \
456 return __iscsi_nacl_auth_##name##_store(container_of(nacl, \
457 struct iscsi_node_acl, se_node_acl), page, count); \
460 CONFIGFS_ATTR(iscsi_nacl_auth_, name)
463 * One-way authentication userid
465 DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
466 DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
467 DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
468 DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
470 #define __DEF_NACL_AUTH_INT(prefix, name) \
471 static ssize_t __iscsi_##prefix##_##name##_show( \
472 struct iscsi_node_acl *nacl, \
475 struct iscsi_node_auth *auth = &nacl->node_auth; \
477 if (!capable(CAP_SYS_ADMIN)) \
480 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
483 #define DEF_NACL_AUTH_INT(name) \
484 __DEF_NACL_AUTH_INT(nacl_auth, name) \
485 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
488 struct se_node_acl *nacl = auth_to_nacl(item); \
489 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
490 struct iscsi_node_acl, se_node_acl), page); \
493 CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
495 DEF_NACL_AUTH_INT(authenticate_target);
497 static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
498 &iscsi_nacl_auth_attr_userid,
499 &iscsi_nacl_auth_attr_password,
500 &iscsi_nacl_auth_attr_authenticate_target,
501 &iscsi_nacl_auth_attr_userid_mutual,
502 &iscsi_nacl_auth_attr_password_mutual,
506 /* End items for lio_target_nacl_auth_cit */
508 /* Start items for lio_target_nacl_param_cit */
510 #define ISCSI_NACL_PARAM(name) \
511 static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \
514 struct se_node_acl *se_nacl = param_to_nacl(item); \
515 struct iscsi_session *sess; \
516 struct se_session *se_sess; \
519 spin_lock_bh(&se_nacl->nacl_sess_lock); \
520 se_sess = se_nacl->nacl_sess; \
522 rb = snprintf(page, PAGE_SIZE, \
523 "No Active iSCSI Session\n"); \
525 sess = se_sess->fabric_sess_ptr; \
526 rb = snprintf(page, PAGE_SIZE, "%u\n", \
527 (u32)sess->sess_ops->name); \
529 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
534 CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
536 ISCSI_NACL_PARAM(MaxConnections);
537 ISCSI_NACL_PARAM(InitialR2T);
538 ISCSI_NACL_PARAM(ImmediateData);
539 ISCSI_NACL_PARAM(MaxBurstLength);
540 ISCSI_NACL_PARAM(FirstBurstLength);
541 ISCSI_NACL_PARAM(DefaultTime2Wait);
542 ISCSI_NACL_PARAM(DefaultTime2Retain);
543 ISCSI_NACL_PARAM(MaxOutstandingR2T);
544 ISCSI_NACL_PARAM(DataPDUInOrder);
545 ISCSI_NACL_PARAM(DataSequenceInOrder);
546 ISCSI_NACL_PARAM(ErrorRecoveryLevel);
548 static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
549 &iscsi_nacl_param_attr_MaxConnections,
550 &iscsi_nacl_param_attr_InitialR2T,
551 &iscsi_nacl_param_attr_ImmediateData,
552 &iscsi_nacl_param_attr_MaxBurstLength,
553 &iscsi_nacl_param_attr_FirstBurstLength,
554 &iscsi_nacl_param_attr_DefaultTime2Wait,
555 &iscsi_nacl_param_attr_DefaultTime2Retain,
556 &iscsi_nacl_param_attr_MaxOutstandingR2T,
557 &iscsi_nacl_param_attr_DataPDUInOrder,
558 &iscsi_nacl_param_attr_DataSequenceInOrder,
559 &iscsi_nacl_param_attr_ErrorRecoveryLevel,
563 /* End items for lio_target_nacl_param_cit */
565 /* Start items for lio_target_acl_cit */
567 static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
569 struct se_node_acl *se_nacl = acl_to_nacl(item);
570 struct iscsi_session *sess;
571 struct iscsi_conn *conn;
572 struct se_session *se_sess;
576 spin_lock_bh(&se_nacl->nacl_sess_lock);
577 se_sess = se_nacl->nacl_sess;
579 rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
580 " Endpoint: %s\n", se_nacl->initiatorname);
582 sess = se_sess->fabric_sess_ptr;
584 rb += sprintf(page+rb, "InitiatorName: %s\n",
585 sess->sess_ops->InitiatorName);
586 rb += sprintf(page+rb, "InitiatorAlias: %s\n",
587 sess->sess_ops->InitiatorAlias);
589 rb += sprintf(page+rb,
590 "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ",
591 sess->sid, sess->isid, sess->tsih);
592 rb += sprintf(page+rb, "SessionType: %s\n",
593 (sess->sess_ops->SessionType) ?
594 "Discovery" : "Normal");
595 rb += sprintf(page+rb, "Session State: ");
596 switch (sess->session_state) {
597 case TARG_SESS_STATE_FREE:
598 rb += sprintf(page+rb, "TARG_SESS_FREE\n");
600 case TARG_SESS_STATE_ACTIVE:
601 rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
603 case TARG_SESS_STATE_LOGGED_IN:
604 rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
606 case TARG_SESS_STATE_FAILED:
607 rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
609 case TARG_SESS_STATE_IN_CONTINUE:
610 rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
613 rb += sprintf(page+rb, "ERROR: Unknown Session"
618 rb += sprintf(page+rb, "---------------------[iSCSI Session"
619 " Values]-----------------------\n");
620 rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
621 " : MaxCmdSN : ITT : TTT\n");
622 max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
623 rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
626 (max_cmd_sn - sess->exp_cmd_sn) + 1,
627 sess->exp_cmd_sn, max_cmd_sn,
628 sess->init_task_tag, sess->targ_xfer_tag);
629 rb += sprintf(page+rb, "----------------------[iSCSI"
630 " Connections]-------------------------\n");
632 spin_lock(&sess->conn_lock);
633 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
634 rb += sprintf(page+rb, "CID: %hu Connection"
635 " State: ", conn->cid);
636 switch (conn->conn_state) {
637 case TARG_CONN_STATE_FREE:
638 rb += sprintf(page+rb,
639 "TARG_CONN_STATE_FREE\n");
641 case TARG_CONN_STATE_XPT_UP:
642 rb += sprintf(page+rb,
643 "TARG_CONN_STATE_XPT_UP\n");
645 case TARG_CONN_STATE_IN_LOGIN:
646 rb += sprintf(page+rb,
647 "TARG_CONN_STATE_IN_LOGIN\n");
649 case TARG_CONN_STATE_LOGGED_IN:
650 rb += sprintf(page+rb,
651 "TARG_CONN_STATE_LOGGED_IN\n");
653 case TARG_CONN_STATE_IN_LOGOUT:
654 rb += sprintf(page+rb,
655 "TARG_CONN_STATE_IN_LOGOUT\n");
657 case TARG_CONN_STATE_LOGOUT_REQUESTED:
658 rb += sprintf(page+rb,
659 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
661 case TARG_CONN_STATE_CLEANUP_WAIT:
662 rb += sprintf(page+rb,
663 "TARG_CONN_STATE_CLEANUP_WAIT\n");
666 rb += sprintf(page+rb,
667 "ERROR: Unknown Connection State!\n");
671 rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr,
672 (conn->network_transport == ISCSI_TCP) ?
674 rb += sprintf(page+rb, " StatSN: 0x%08x\n",
677 spin_unlock(&sess->conn_lock);
679 spin_unlock_bh(&se_nacl->nacl_sess_lock);
684 static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
687 return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth);
690 static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
691 const char *page, size_t count)
693 struct se_node_acl *se_nacl = acl_to_nacl(item);
694 struct se_portal_group *se_tpg = se_nacl->se_tpg;
695 struct iscsi_portal_group *tpg = container_of(se_tpg,
696 struct iscsi_portal_group, tpg_se_tpg);
697 struct config_item *acl_ci, *tpg_ci, *wwn_ci;
701 ret = kstrtou32(page, 0, &cmdsn_depth);
704 if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
705 pr_err("Passed cmdsn_depth: %u exceeds"
706 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
707 TA_DEFAULT_CMDSN_DEPTH_MAX);
710 acl_ci = &se_nacl->acl_group.cg_item;
712 pr_err("Unable to locatel acl_ci\n");
715 tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
717 pr_err("Unable to locate tpg_ci\n");
720 wwn_ci = &tpg_ci->ci_group->cg_item;
722 pr_err("Unable to locate config_item wwn_ci\n");
726 if (iscsit_get_tpg(tpg) < 0)
729 ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth);
731 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
732 "InitiatorName: %s\n", config_item_name(wwn_ci),
733 config_item_name(tpg_ci), cmdsn_depth,
734 config_item_name(acl_ci));
737 return (!ret) ? count : (ssize_t)ret;
740 static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
742 return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
745 static ssize_t lio_target_nacl_tag_store(struct config_item *item,
746 const char *page, size_t count)
748 struct se_node_acl *se_nacl = acl_to_nacl(item);
751 ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
758 CONFIGFS_ATTR_RO(lio_target_nacl_, info);
759 CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
760 CONFIGFS_ATTR(lio_target_nacl_, tag);
762 static struct configfs_attribute *lio_target_initiator_attrs[] = {
763 &lio_target_nacl_attr_info,
764 &lio_target_nacl_attr_cmdsn_depth,
765 &lio_target_nacl_attr_tag,
769 static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
772 struct iscsi_node_acl *acl =
773 container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
775 config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
776 "iscsi_sess_stats", &iscsi_stat_sess_cit);
777 configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group,
778 &se_nacl->acl_fabric_stat_group);
782 static void lio_target_cleanup_nodeacl( struct se_node_acl *se_nacl)
784 struct iscsi_node_acl *acl = container_of(se_nacl,
785 struct iscsi_node_acl, se_node_acl);
787 configfs_remove_default_groups(&acl->se_node_acl.acl_fabric_stat_group);
790 /* End items for lio_target_acl_cit */
792 /* Start items for lio_target_tpg_attrib_cit */
794 #define DEF_TPG_ATTRIB(name) \
796 static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \
799 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
800 struct iscsi_portal_group *tpg = container_of(se_tpg, \
801 struct iscsi_portal_group, tpg_se_tpg); \
804 if (iscsit_get_tpg(tpg) < 0) \
807 rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \
808 iscsit_put_tpg(tpg); \
812 static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
813 const char *page, size_t count) \
815 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
816 struct iscsi_portal_group *tpg = container_of(se_tpg, \
817 struct iscsi_portal_group, tpg_se_tpg); \
821 if (iscsit_get_tpg(tpg) < 0) \
824 ret = kstrtou32(page, 0, &val); \
827 ret = iscsit_ta_##name(tpg, val); \
831 iscsit_put_tpg(tpg); \
834 iscsit_put_tpg(tpg); \
837 CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
839 DEF_TPG_ATTRIB(authentication);
840 DEF_TPG_ATTRIB(login_timeout);
841 DEF_TPG_ATTRIB(netif_timeout);
842 DEF_TPG_ATTRIB(generate_node_acls);
843 DEF_TPG_ATTRIB(default_cmdsn_depth);
844 DEF_TPG_ATTRIB(cache_dynamic_acls);
845 DEF_TPG_ATTRIB(demo_mode_write_protect);
846 DEF_TPG_ATTRIB(prod_mode_write_protect);
847 DEF_TPG_ATTRIB(demo_mode_discovery);
848 DEF_TPG_ATTRIB(default_erl);
849 DEF_TPG_ATTRIB(t10_pi);
850 DEF_TPG_ATTRIB(fabric_prot_type);
851 DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
853 static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
854 &iscsi_tpg_attrib_attr_authentication,
855 &iscsi_tpg_attrib_attr_login_timeout,
856 &iscsi_tpg_attrib_attr_netif_timeout,
857 &iscsi_tpg_attrib_attr_generate_node_acls,
858 &iscsi_tpg_attrib_attr_default_cmdsn_depth,
859 &iscsi_tpg_attrib_attr_cache_dynamic_acls,
860 &iscsi_tpg_attrib_attr_demo_mode_write_protect,
861 &iscsi_tpg_attrib_attr_prod_mode_write_protect,
862 &iscsi_tpg_attrib_attr_demo_mode_discovery,
863 &iscsi_tpg_attrib_attr_default_erl,
864 &iscsi_tpg_attrib_attr_t10_pi,
865 &iscsi_tpg_attrib_attr_fabric_prot_type,
866 &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
870 /* End items for lio_target_tpg_attrib_cit */
872 /* Start items for lio_target_tpg_auth_cit */
874 #define __DEF_TPG_AUTH_STR(prefix, name, flags) \
875 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
878 struct iscsi_portal_group *tpg = container_of(se_tpg, \
879 struct iscsi_portal_group, tpg_se_tpg); \
880 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
882 if (!capable(CAP_SYS_ADMIN)) \
885 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
888 static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
889 const char *page, size_t count) \
891 struct iscsi_portal_group *tpg = container_of(se_tpg, \
892 struct iscsi_portal_group, tpg_se_tpg); \
893 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
895 if (!capable(CAP_SYS_ADMIN)) \
898 snprintf(auth->name, sizeof(auth->name), "%s", page); \
899 if (!(strncmp("NULL", auth->name, 4))) \
900 auth->naf_flags &= ~flags; \
902 auth->naf_flags |= flags; \
904 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
905 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
906 auth->authenticate_target = 1; \
908 auth->authenticate_target = 0; \
913 #define DEF_TPG_AUTH_STR(name, flags) \
914 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
915 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
918 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
921 static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \
922 const char *page, size_t count) \
924 return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
927 CONFIGFS_ATTR(iscsi_tpg_auth_, name);
930 DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
931 DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
932 DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
933 DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
935 #define __DEF_TPG_AUTH_INT(prefix, name) \
936 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
939 struct iscsi_portal_group *tpg = container_of(se_tpg, \
940 struct iscsi_portal_group, tpg_se_tpg); \
941 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
943 if (!capable(CAP_SYS_ADMIN)) \
946 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
949 #define DEF_TPG_AUTH_INT(name) \
950 __DEF_TPG_AUTH_INT(tpg_auth, name) \
951 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
954 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
956 CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
958 DEF_TPG_AUTH_INT(authenticate_target);
960 static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
961 &iscsi_tpg_auth_attr_userid,
962 &iscsi_tpg_auth_attr_password,
963 &iscsi_tpg_auth_attr_authenticate_target,
964 &iscsi_tpg_auth_attr_userid_mutual,
965 &iscsi_tpg_auth_attr_password_mutual,
969 /* End items for lio_target_tpg_auth_cit */
971 /* Start items for lio_target_tpg_param_cit */
973 #define DEF_TPG_PARAM(name) \
974 static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \
977 struct se_portal_group *se_tpg = param_to_tpg(item); \
978 struct iscsi_portal_group *tpg = container_of(se_tpg, \
979 struct iscsi_portal_group, tpg_se_tpg); \
980 struct iscsi_param *param; \
983 if (iscsit_get_tpg(tpg) < 0) \
986 param = iscsi_find_param_from_key(__stringify(name), \
989 iscsit_put_tpg(tpg); \
992 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
994 iscsit_put_tpg(tpg); \
997 static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
998 const char *page, size_t count) \
1000 struct se_portal_group *se_tpg = param_to_tpg(item); \
1001 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1002 struct iscsi_portal_group, tpg_se_tpg); \
1006 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
1009 len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
1010 if (isspace(buf[len-1])) \
1011 buf[len-1] = '\0'; /* Kill newline */ \
1013 if (iscsit_get_tpg(tpg) < 0) { \
1018 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
1023 iscsit_put_tpg(tpg); \
1027 iscsit_put_tpg(tpg); \
1030 CONFIGFS_ATTR(iscsi_tpg_param_, name)
1032 DEF_TPG_PARAM(AuthMethod);
1033 DEF_TPG_PARAM(HeaderDigest);
1034 DEF_TPG_PARAM(DataDigest);
1035 DEF_TPG_PARAM(MaxConnections);
1036 DEF_TPG_PARAM(TargetAlias);
1037 DEF_TPG_PARAM(InitialR2T);
1038 DEF_TPG_PARAM(ImmediateData);
1039 DEF_TPG_PARAM(MaxRecvDataSegmentLength);
1040 DEF_TPG_PARAM(MaxXmitDataSegmentLength);
1041 DEF_TPG_PARAM(MaxBurstLength);
1042 DEF_TPG_PARAM(FirstBurstLength);
1043 DEF_TPG_PARAM(DefaultTime2Wait);
1044 DEF_TPG_PARAM(DefaultTime2Retain);
1045 DEF_TPG_PARAM(MaxOutstandingR2T);
1046 DEF_TPG_PARAM(DataPDUInOrder);
1047 DEF_TPG_PARAM(DataSequenceInOrder);
1048 DEF_TPG_PARAM(ErrorRecoveryLevel);
1049 DEF_TPG_PARAM(IFMarker);
1050 DEF_TPG_PARAM(OFMarker);
1051 DEF_TPG_PARAM(IFMarkInt);
1052 DEF_TPG_PARAM(OFMarkInt);
1054 static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
1055 &iscsi_tpg_param_attr_AuthMethod,
1056 &iscsi_tpg_param_attr_HeaderDigest,
1057 &iscsi_tpg_param_attr_DataDigest,
1058 &iscsi_tpg_param_attr_MaxConnections,
1059 &iscsi_tpg_param_attr_TargetAlias,
1060 &iscsi_tpg_param_attr_InitialR2T,
1061 &iscsi_tpg_param_attr_ImmediateData,
1062 &iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
1063 &iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
1064 &iscsi_tpg_param_attr_MaxBurstLength,
1065 &iscsi_tpg_param_attr_FirstBurstLength,
1066 &iscsi_tpg_param_attr_DefaultTime2Wait,
1067 &iscsi_tpg_param_attr_DefaultTime2Retain,
1068 &iscsi_tpg_param_attr_MaxOutstandingR2T,
1069 &iscsi_tpg_param_attr_DataPDUInOrder,
1070 &iscsi_tpg_param_attr_DataSequenceInOrder,
1071 &iscsi_tpg_param_attr_ErrorRecoveryLevel,
1072 &iscsi_tpg_param_attr_IFMarker,
1073 &iscsi_tpg_param_attr_OFMarker,
1074 &iscsi_tpg_param_attr_IFMarkInt,
1075 &iscsi_tpg_param_attr_OFMarkInt,
1079 /* End items for lio_target_tpg_param_cit */
1081 /* Start items for lio_target_tpg_cit */
1083 static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page)
1085 struct se_portal_group *se_tpg = to_tpg(item);
1086 struct iscsi_portal_group *tpg = container_of(se_tpg,
1087 struct iscsi_portal_group, tpg_se_tpg);
1090 spin_lock(&tpg->tpg_state_lock);
1091 len = sprintf(page, "%d\n",
1092 (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1093 spin_unlock(&tpg->tpg_state_lock);
1098 static ssize_t lio_target_tpg_enable_store(struct config_item *item,
1099 const char *page, size_t count)
1101 struct se_portal_group *se_tpg = to_tpg(item);
1102 struct iscsi_portal_group *tpg = container_of(se_tpg,
1103 struct iscsi_portal_group, tpg_se_tpg);
1107 ret = kstrtou32(page, 0, &op);
1110 if ((op != 1) && (op != 0)) {
1111 pr_err("Illegal value for tpg_enable: %u\n", op);
1115 ret = iscsit_get_tpg(tpg);
1120 ret = iscsit_tpg_enable_portal_group(tpg);
1125 * iscsit_tpg_disable_portal_group() assumes force=1
1127 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1132 iscsit_put_tpg(tpg);
1135 iscsit_put_tpg(tpg);
1140 static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
1143 return target_show_dynamic_sessions(to_tpg(item), page);
1146 CONFIGFS_ATTR(lio_target_tpg_, enable);
1147 CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
1149 static struct configfs_attribute *lio_target_tpg_attrs[] = {
1150 &lio_target_tpg_attr_enable,
1151 &lio_target_tpg_attr_dynamic_sessions,
1155 /* End items for lio_target_tpg_cit */
1157 /* Start items for lio_target_tiqn_cit */
1159 static struct se_portal_group *lio_target_tiqn_addtpg(
1161 struct config_group *group,
1164 struct iscsi_portal_group *tpg;
1165 struct iscsi_tiqn *tiqn;
1170 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1172 * Only tpgt_# directory groups can be created below
1173 * target/iscsi/iqn.superturodiskarry/
1175 tpgt_str = strstr(name, "tpgt_");
1177 pr_err("Unable to locate \"tpgt_#\" directory"
1181 tpgt_str += 5; /* Skip ahead of "tpgt_" */
1182 ret = kstrtou16(tpgt_str, 0, &tpgt);
1186 tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1190 ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
1194 ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1198 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1199 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1201 return &tpg->tpg_se_tpg;
1203 core_tpg_deregister(&tpg->tpg_se_tpg);
1208 static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1210 struct iscsi_portal_group *tpg;
1211 struct iscsi_tiqn *tiqn;
1213 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1214 tiqn = tpg->tpg_tiqn;
1216 * iscsit_tpg_del_portal_group() assumes force=1
1218 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1219 iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1222 /* End items for lio_target_tiqn_cit */
1224 /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1226 static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
1229 return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
1232 CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
1234 static struct configfs_attribute *lio_target_wwn_attrs[] = {
1235 &lio_target_wwn_attr_lio_version,
1239 static struct se_wwn *lio_target_call_coreaddtiqn(
1240 struct target_fabric_configfs *tf,
1241 struct config_group *group,
1244 struct iscsi_tiqn *tiqn;
1246 tiqn = iscsit_add_tiqn((unsigned char *)name);
1248 return ERR_CAST(tiqn);
1250 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1251 "iscsi_instance", &iscsi_stat_instance_cit);
1252 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1253 &tiqn->tiqn_wwn.fabric_stat_group);
1255 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1256 "iscsi_sess_err", &iscsi_stat_sess_err_cit);
1257 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1258 &tiqn->tiqn_wwn.fabric_stat_group);
1260 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1261 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1262 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1263 &tiqn->tiqn_wwn.fabric_stat_group);
1265 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1266 "iscsi_login_stats", &iscsi_stat_login_cit);
1267 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1268 &tiqn->tiqn_wwn.fabric_stat_group);
1270 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1271 "iscsi_logout_stats", &iscsi_stat_logout_cit);
1272 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1273 &tiqn->tiqn_wwn.fabric_stat_group);
1276 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1277 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1279 return &tiqn->tiqn_wwn;
1282 static void lio_target_call_coredeltiqn(
1285 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1287 configfs_remove_default_groups(&tiqn->tiqn_wwn.fabric_stat_group);
1289 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1291 iscsit_del_tiqn(tiqn);
1294 /* End LIO-Target TIQN struct contig_lio_target_cit */
1296 /* Start lio_target_discovery_auth_cit */
1298 #define DEF_DISC_AUTH_STR(name, flags) \
1299 __DEF_NACL_AUTH_STR(disc, name, flags) \
1300 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1302 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
1305 static ssize_t iscsi_disc_##name##_store(struct config_item *item, \
1306 const char *page, size_t count) \
1308 return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \
1312 CONFIGFS_ATTR(iscsi_disc_, name)
1314 DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1315 DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1316 DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1317 DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1319 #define DEF_DISC_AUTH_INT(name) \
1320 __DEF_NACL_AUTH_INT(disc, name) \
1321 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1323 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
1326 CONFIGFS_ATTR_RO(iscsi_disc_, name)
1328 DEF_DISC_AUTH_INT(authenticate_target);
1331 static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
1334 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1336 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1339 static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1340 const char *page, size_t count)
1342 struct iscsi_param *param;
1343 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
1347 err = kstrtou32(page, 0, &op);
1350 if ((op != 1) && (op != 0)) {
1351 pr_err("Illegal value for enforce_discovery_auth:"
1356 if (!discovery_tpg) {
1357 pr_err("iscsit_global->discovery_tpg is NULL\n");
1361 param = iscsi_find_param_from_key(AUTHMETHOD,
1362 discovery_tpg->param_list);
1368 * Reset the AuthMethod key to CHAP.
1370 if (iscsi_update_param_value(param, CHAP) < 0)
1373 discovery_tpg->tpg_attrib.authentication = 1;
1374 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1375 pr_debug("LIO-CORE[0] Successfully enabled"
1376 " authentication enforcement for iSCSI"
1377 " Discovery TPG\n");
1380 * Reset the AuthMethod key to CHAP,None
1382 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1385 discovery_tpg->tpg_attrib.authentication = 0;
1386 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1387 pr_debug("LIO-CORE[0] Successfully disabled"
1388 " authentication enforcement for iSCSI"
1389 " Discovery TPG\n");
1395 CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
1397 static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1398 &iscsi_disc_attr_userid,
1399 &iscsi_disc_attr_password,
1400 &iscsi_disc_attr_authenticate_target,
1401 &iscsi_disc_attr_userid_mutual,
1402 &iscsi_disc_attr_password_mutual,
1403 &iscsi_disc_attr_enforce_discovery_auth,
1407 /* End lio_target_discovery_auth_cit */
1409 /* Start functions for target_core_fabric_ops */
1411 static char *iscsi_get_fabric_name(void)
1416 static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1418 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1420 return cmd->i_state;
1423 static u32 lio_sess_get_index(struct se_session *se_sess)
1425 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1427 return sess->session_index;
1430 static u32 lio_sess_get_initiator_sid(
1431 struct se_session *se_sess,
1435 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1437 * iSCSI Initiator Session Identifier from RFC-3720.
1439 return snprintf(buf, size, "%6phN", sess->isid);
1442 static int lio_queue_data_in(struct se_cmd *se_cmd)
1444 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1446 cmd->i_state = ISTATE_SEND_DATAIN;
1447 cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd);
1452 static int lio_write_pending(struct se_cmd *se_cmd)
1454 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1455 struct iscsi_conn *conn = cmd->conn;
1457 if (!cmd->immediate_data && !cmd->unsolicited_data)
1458 return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
1463 static int lio_write_pending_status(struct se_cmd *se_cmd)
1465 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1468 spin_lock_bh(&cmd->istate_lock);
1469 ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1470 spin_unlock_bh(&cmd->istate_lock);
1475 static int lio_queue_status(struct se_cmd *se_cmd)
1477 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1479 cmd->i_state = ISTATE_SEND_STATUS;
1481 if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
1482 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1485 cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd);
1490 static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
1492 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1494 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1495 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1498 static void lio_aborted_task(struct se_cmd *se_cmd)
1500 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1502 cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1505 static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg)
1507 return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1510 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1512 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
1515 static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1517 return iscsi_tpg(se_tpg)->tpgt;
1520 static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1522 return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
1525 static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1527 return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
1530 static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1532 return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
1535 static int lio_tpg_check_demo_mode_write_protect(
1536 struct se_portal_group *se_tpg)
1538 return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
1541 static int lio_tpg_check_prod_mode_write_protect(
1542 struct se_portal_group *se_tpg)
1544 return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
1547 static int lio_tpg_check_prot_fabric_only(
1548 struct se_portal_group *se_tpg)
1551 * Only report fabric_prot_type if t10_pi has also been enabled
1552 * for incoming ib_isert sessions.
1554 if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
1556 return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
1560 * This function calls iscsit_inc_session_usage_count() on the
1561 * struct iscsi_session in question.
1563 static int lio_tpg_shutdown_session(struct se_session *se_sess)
1565 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1566 struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
1568 spin_lock_bh(&se_tpg->session_lock);
1569 spin_lock(&sess->conn_lock);
1570 if (atomic_read(&sess->session_fall_back_to_erl0) ||
1571 atomic_read(&sess->session_logout) ||
1572 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1573 spin_unlock(&sess->conn_lock);
1574 spin_unlock_bh(&se_tpg->session_lock);
1577 atomic_set(&sess->session_reinstatement, 1);
1578 spin_unlock(&sess->conn_lock);
1580 iscsit_stop_time2retain_timer(sess);
1581 spin_unlock_bh(&se_tpg->session_lock);
1583 iscsit_stop_session(sess, 1, 1);
1588 * Calls iscsit_dec_session_usage_count() as inverse of
1589 * lio_tpg_shutdown_session()
1591 static void lio_tpg_close_session(struct se_session *se_sess)
1593 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1595 * If the iSCSI Session for the iSCSI Initiator Node exists,
1596 * forcefully shutdown the iSCSI NEXUS.
1598 iscsit_close_session(sess);
1601 static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1603 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
1606 static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1608 struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1610 struct se_portal_group *se_tpg = se_acl->se_tpg;
1611 struct iscsi_portal_group *tpg = container_of(se_tpg,
1612 struct iscsi_portal_group, tpg_se_tpg);
1614 acl->node_attrib.nacl = acl;
1615 iscsit_set_default_node_attribues(acl, tpg);
1618 static int lio_check_stop_free(struct se_cmd *se_cmd)
1620 return target_put_sess_cmd(se_cmd);
1623 static void lio_release_cmd(struct se_cmd *se_cmd)
1625 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1627 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
1628 iscsit_release_cmd(cmd);
1631 const struct target_core_fabric_ops iscsi_ops = {
1632 .module = THIS_MODULE,
1634 .node_acl_size = sizeof(struct iscsi_node_acl),
1635 .get_fabric_name = iscsi_get_fabric_name,
1636 .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
1637 .tpg_get_tag = lio_tpg_get_tag,
1638 .tpg_get_default_depth = lio_tpg_get_default_depth,
1639 .tpg_check_demo_mode = lio_tpg_check_demo_mode,
1640 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
1641 .tpg_check_demo_mode_write_protect =
1642 lio_tpg_check_demo_mode_write_protect,
1643 .tpg_check_prod_mode_write_protect =
1644 lio_tpg_check_prod_mode_write_protect,
1645 .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only,
1646 .tpg_get_inst_index = lio_tpg_get_inst_index,
1647 .check_stop_free = lio_check_stop_free,
1648 .release_cmd = lio_release_cmd,
1649 .shutdown_session = lio_tpg_shutdown_session,
1650 .close_session = lio_tpg_close_session,
1651 .sess_get_index = lio_sess_get_index,
1652 .sess_get_initiator_sid = lio_sess_get_initiator_sid,
1653 .write_pending = lio_write_pending,
1654 .write_pending_status = lio_write_pending_status,
1655 .set_default_node_attributes = lio_set_default_node_attributes,
1656 .get_cmd_state = iscsi_get_cmd_state,
1657 .queue_data_in = lio_queue_data_in,
1658 .queue_status = lio_queue_status,
1659 .queue_tm_rsp = lio_queue_tm_rsp,
1660 .aborted_task = lio_aborted_task,
1661 .fabric_make_wwn = lio_target_call_coreaddtiqn,
1662 .fabric_drop_wwn = lio_target_call_coredeltiqn,
1663 .fabric_make_tpg = lio_target_tiqn_addtpg,
1664 .fabric_drop_tpg = lio_target_tiqn_deltpg,
1665 .fabric_make_np = lio_target_call_addnptotpg,
1666 .fabric_drop_np = lio_target_call_delnpfromtpg,
1667 .fabric_init_nodeacl = lio_target_init_nodeacl,
1668 .fabric_cleanup_nodeacl = lio_target_cleanup_nodeacl,
1670 .tfc_discovery_attrs = lio_target_discovery_auth_attrs,
1671 .tfc_wwn_attrs = lio_target_wwn_attrs,
1672 .tfc_tpg_base_attrs = lio_target_tpg_attrs,
1673 .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs,
1674 .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs,
1675 .tfc_tpg_param_attrs = lio_target_tpg_param_attrs,
1676 .tfc_tpg_np_base_attrs = lio_target_portal_attrs,
1677 .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs,
1678 .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs,
1679 .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs,
1680 .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs,