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/target_core_fabric_configfs.h>
27 #include <target/configfs_macros.h>
28 #include <target/iscsi/iscsi_transport.h>
30 #include <target/iscsi/iscsi_target_core.h>
31 #include "iscsi_target_parameters.h"
32 #include "iscsi_target_device.h"
33 #include "iscsi_target_erl0.h"
34 #include "iscsi_target_nodeattrib.h"
35 #include "iscsi_target_tpg.h"
36 #include "iscsi_target_util.h"
37 #include "iscsi_target.h"
38 #include <target/iscsi/iscsi_target_stat.h>
40 struct lio_target_configfs_attribute {
41 struct configfs_attribute attr;
42 ssize_t (*show)(void *, char *);
43 ssize_t (*store)(void *, const char *, size_t);
46 /* Start items for lio_target_portal_cit */
48 static ssize_t lio_target_np_show_sctp(
49 struct se_tpg_np *se_tpg_np,
52 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
53 struct iscsi_tpg_np, se_tpg_np);
54 struct iscsi_tpg_np *tpg_np_sctp;
57 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
59 rb = sprintf(page, "1\n");
61 rb = sprintf(page, "0\n");
66 static ssize_t lio_target_np_store_sctp(
67 struct se_tpg_np *se_tpg_np,
72 struct iscsi_portal_group *tpg;
73 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
74 struct iscsi_tpg_np, se_tpg_np);
75 struct iscsi_tpg_np *tpg_np_sctp = NULL;
79 ret = kstrtou32(page, 0, &op);
82 if ((op != 1) && (op != 0)) {
83 pr_err("Illegal value for tpg_enable: %u\n", op);
88 pr_err("Unable to locate struct iscsi_np from"
89 " struct iscsi_tpg_np\n");
94 if (iscsit_get_tpg(tpg) < 0)
99 * Use existing np->np_sockaddr for SCTP network portal reference
101 tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
102 tpg_np, ISCSI_SCTP_TCP);
103 if (!tpg_np_sctp || IS_ERR(tpg_np_sctp))
106 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
110 ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp);
122 TF_NP_BASE_ATTR(lio_target, sctp, S_IRUGO | S_IWUSR);
124 static ssize_t lio_target_np_show_iser(
125 struct se_tpg_np *se_tpg_np,
128 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
129 struct iscsi_tpg_np, se_tpg_np);
130 struct iscsi_tpg_np *tpg_np_iser;
133 tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
135 rb = sprintf(page, "1\n");
137 rb = sprintf(page, "0\n");
142 static ssize_t lio_target_np_store_iser(
143 struct se_tpg_np *se_tpg_np,
148 struct iscsi_portal_group *tpg;
149 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
150 struct iscsi_tpg_np, se_tpg_np);
151 struct iscsi_tpg_np *tpg_np_iser = NULL;
156 op = simple_strtoul(page, &endptr, 0);
157 if ((op != 1) && (op != 0)) {
158 pr_err("Illegal value for tpg_enable: %u\n", op);
163 pr_err("Unable to locate struct iscsi_np from"
164 " struct iscsi_tpg_np\n");
169 if (iscsit_get_tpg(tpg) < 0)
173 rc = request_module("ib_isert");
175 pr_warn("Unable to request_module for ib_isert\n");
179 tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
180 tpg_np, ISCSI_INFINIBAND);
181 if (IS_ERR(tpg_np_iser)) {
182 rc = PTR_ERR(tpg_np_iser);
186 tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
188 rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser);
201 TF_NP_BASE_ATTR(lio_target, iser, S_IRUGO | S_IWUSR);
203 static struct configfs_attribute *lio_target_portal_attrs[] = {
204 &lio_target_np_sctp.attr,
205 &lio_target_np_iser.attr,
209 /* Stop items for lio_target_portal_cit */
211 /* Start items for lio_target_np_cit */
213 #define MAX_PORTAL_LEN 256
215 static struct se_tpg_np *lio_target_call_addnptotpg(
216 struct se_portal_group *se_tpg,
217 struct config_group *group,
220 struct iscsi_portal_group *tpg;
221 struct iscsi_tpg_np *tpg_np;
222 char *str, *str2, *ip_str, *port_str;
223 struct sockaddr_storage sockaddr;
224 struct sockaddr_in *sock_in;
225 struct sockaddr_in6 *sock_in6;
228 char buf[MAX_PORTAL_LEN + 1];
230 if (strlen(name) > MAX_PORTAL_LEN) {
231 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
232 (int)strlen(name), MAX_PORTAL_LEN);
233 return ERR_PTR(-EOVERFLOW);
235 memset(buf, 0, MAX_PORTAL_LEN + 1);
236 snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
238 memset(&sockaddr, 0, sizeof(struct sockaddr_storage));
240 str = strstr(buf, "[");
244 str2 = strstr(str, "]");
246 pr_err("Unable to locate trailing \"]\""
247 " in IPv6 iSCSI network portal address\n");
248 return ERR_PTR(-EINVAL);
250 str++; /* Skip over leading "[" */
251 *str2 = '\0'; /* Terminate the unbracketed IPv6 address */
252 str2++; /* Skip over the \0 */
253 port_str = strstr(str2, ":");
255 pr_err("Unable to locate \":port\""
256 " in IPv6 iSCSI network portal address\n");
257 return ERR_PTR(-EINVAL);
259 *port_str = '\0'; /* Terminate string for IP */
260 port_str++; /* Skip over ":" */
262 ret = kstrtoul(port_str, 0, &port);
264 pr_err("kstrtoul() failed for port_str: %d\n", ret);
267 sock_in6 = (struct sockaddr_in6 *)&sockaddr;
268 sock_in6->sin6_family = AF_INET6;
269 sock_in6->sin6_port = htons((unsigned short)port);
270 ret = in6_pton(str, -1,
271 (void *)&sock_in6->sin6_addr.in6_u, -1, &end);
273 pr_err("in6_pton returned: %d\n", ret);
274 return ERR_PTR(-EINVAL);
277 str = ip_str = &buf[0];
278 port_str = strstr(ip_str, ":");
280 pr_err("Unable to locate \":port\""
281 " in IPv4 iSCSI network portal address\n");
282 return ERR_PTR(-EINVAL);
284 *port_str = '\0'; /* Terminate string for IP */
285 port_str++; /* Skip over ":" */
287 ret = kstrtoul(port_str, 0, &port);
289 pr_err("kstrtoul() failed for port_str: %d\n", ret);
292 sock_in = (struct sockaddr_in *)&sockaddr;
293 sock_in->sin_family = AF_INET;
294 sock_in->sin_port = htons((unsigned short)port);
295 sock_in->sin_addr.s_addr = in_aton(ip_str);
297 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
298 ret = iscsit_get_tpg(tpg);
300 return ERR_PTR(-EINVAL);
302 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
304 config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
307 * Assume ISCSI_TCP by default. Other network portals for other
310 * Traditional iSCSI over SCTP (initial support)
311 * iSER/TCP (TODO, hardware available)
312 * iSER/SCTP (TODO, software emulation with osc-iwarp)
313 * iSER/IB (TODO, hardware available)
315 * can be enabled with attributes under
316 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
319 tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
321 if (IS_ERR(tpg_np)) {
323 return ERR_CAST(tpg_np);
325 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
328 return &tpg_np->se_tpg_np;
331 static void lio_target_call_delnpfromtpg(
332 struct se_tpg_np *se_tpg_np)
334 struct iscsi_portal_group *tpg;
335 struct iscsi_tpg_np *tpg_np;
336 struct se_portal_group *se_tpg;
339 tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
341 ret = iscsit_get_tpg(tpg);
345 se_tpg = &tpg->tpg_se_tpg;
346 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
347 " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
348 tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
350 ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
354 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
359 /* End items for lio_target_np_cit */
361 /* Start items for lio_target_nacl_attrib_cit */
363 #define DEF_NACL_ATTRIB(name) \
364 static ssize_t iscsi_nacl_attrib_show_##name( \
365 struct se_node_acl *se_nacl, \
368 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
371 return sprintf(page, "%u\n", nacl->node_attrib.name); \
374 static ssize_t iscsi_nacl_attrib_store_##name( \
375 struct se_node_acl *se_nacl, \
379 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
384 ret = kstrtou32(page, 0, &val); \
387 ret = iscsit_na_##name(nacl, val); \
394 #define NACL_ATTR(_name, _mode) TF_NACL_ATTRIB_ATTR(iscsi, _name, _mode);
396 * Define iscsi_node_attrib_s_dataout_timeout
398 DEF_NACL_ATTRIB(dataout_timeout);
399 NACL_ATTR(dataout_timeout, S_IRUGO | S_IWUSR);
401 * Define iscsi_node_attrib_s_dataout_timeout_retries
403 DEF_NACL_ATTRIB(dataout_timeout_retries);
404 NACL_ATTR(dataout_timeout_retries, S_IRUGO | S_IWUSR);
406 * Define iscsi_node_attrib_s_default_erl
408 DEF_NACL_ATTRIB(default_erl);
409 NACL_ATTR(default_erl, S_IRUGO | S_IWUSR);
411 * Define iscsi_node_attrib_s_nopin_timeout
413 DEF_NACL_ATTRIB(nopin_timeout);
414 NACL_ATTR(nopin_timeout, S_IRUGO | S_IWUSR);
416 * Define iscsi_node_attrib_s_nopin_response_timeout
418 DEF_NACL_ATTRIB(nopin_response_timeout);
419 NACL_ATTR(nopin_response_timeout, S_IRUGO | S_IWUSR);
421 * Define iscsi_node_attrib_s_random_datain_pdu_offsets
423 DEF_NACL_ATTRIB(random_datain_pdu_offsets);
424 NACL_ATTR(random_datain_pdu_offsets, S_IRUGO | S_IWUSR);
426 * Define iscsi_node_attrib_s_random_datain_seq_offsets
428 DEF_NACL_ATTRIB(random_datain_seq_offsets);
429 NACL_ATTR(random_datain_seq_offsets, S_IRUGO | S_IWUSR);
431 * Define iscsi_node_attrib_s_random_r2t_offsets
433 DEF_NACL_ATTRIB(random_r2t_offsets);
434 NACL_ATTR(random_r2t_offsets, S_IRUGO | S_IWUSR);
436 static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
437 &iscsi_nacl_attrib_dataout_timeout.attr,
438 &iscsi_nacl_attrib_dataout_timeout_retries.attr,
439 &iscsi_nacl_attrib_default_erl.attr,
440 &iscsi_nacl_attrib_nopin_timeout.attr,
441 &iscsi_nacl_attrib_nopin_response_timeout.attr,
442 &iscsi_nacl_attrib_random_datain_pdu_offsets.attr,
443 &iscsi_nacl_attrib_random_datain_seq_offsets.attr,
444 &iscsi_nacl_attrib_random_r2t_offsets.attr,
448 /* End items for lio_target_nacl_attrib_cit */
450 /* Start items for lio_target_nacl_auth_cit */
452 #define __DEF_NACL_AUTH_STR(prefix, name, flags) \
453 static ssize_t __iscsi_##prefix##_show_##name( \
454 struct iscsi_node_acl *nacl, \
457 struct iscsi_node_auth *auth = &nacl->node_auth; \
459 if (!capable(CAP_SYS_ADMIN)) \
461 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
464 static ssize_t __iscsi_##prefix##_store_##name( \
465 struct iscsi_node_acl *nacl, \
469 struct iscsi_node_auth *auth = &nacl->node_auth; \
471 if (!capable(CAP_SYS_ADMIN)) \
473 if (count >= sizeof(auth->name)) \
475 snprintf(auth->name, sizeof(auth->name), "%s", page); \
476 if (!strncmp("NULL", auth->name, 4)) \
477 auth->naf_flags &= ~flags; \
479 auth->naf_flags |= flags; \
481 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
482 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
483 auth->authenticate_target = 1; \
485 auth->authenticate_target = 0; \
490 #define __DEF_NACL_AUTH_INT(prefix, name) \
491 static ssize_t __iscsi_##prefix##_show_##name( \
492 struct iscsi_node_acl *nacl, \
495 struct iscsi_node_auth *auth = &nacl->node_auth; \
497 if (!capable(CAP_SYS_ADMIN)) \
500 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
503 #define DEF_NACL_AUTH_STR(name, flags) \
504 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
505 static ssize_t iscsi_nacl_auth_show_##name( \
506 struct se_node_acl *nacl, \
509 return __iscsi_nacl_auth_show_##name(container_of(nacl, \
510 struct iscsi_node_acl, se_node_acl), page); \
512 static ssize_t iscsi_nacl_auth_store_##name( \
513 struct se_node_acl *nacl, \
517 return __iscsi_nacl_auth_store_##name(container_of(nacl, \
518 struct iscsi_node_acl, se_node_acl), page, count); \
521 #define DEF_NACL_AUTH_INT(name) \
522 __DEF_NACL_AUTH_INT(nacl_auth, name) \
523 static ssize_t iscsi_nacl_auth_show_##name( \
524 struct se_node_acl *nacl, \
527 return __iscsi_nacl_auth_show_##name(container_of(nacl, \
528 struct iscsi_node_acl, se_node_acl), page); \
531 #define AUTH_ATTR(_name, _mode) TF_NACL_AUTH_ATTR(iscsi, _name, _mode);
532 #define AUTH_ATTR_RO(_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name);
535 * One-way authentication userid
537 DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
538 AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
540 * One-way authentication password
542 DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
543 AUTH_ATTR(password, S_IRUGO | S_IWUSR);
545 * Enforce mutual authentication
547 DEF_NACL_AUTH_INT(authenticate_target);
548 AUTH_ATTR_RO(authenticate_target);
550 * Mutual authentication userid
552 DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
553 AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
555 * Mutual authentication password
557 DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
558 AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
560 static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
561 &iscsi_nacl_auth_userid.attr,
562 &iscsi_nacl_auth_password.attr,
563 &iscsi_nacl_auth_authenticate_target.attr,
564 &iscsi_nacl_auth_userid_mutual.attr,
565 &iscsi_nacl_auth_password_mutual.attr,
569 /* End items for lio_target_nacl_auth_cit */
571 /* Start items for lio_target_nacl_param_cit */
573 #define DEF_NACL_PARAM(name) \
574 static ssize_t iscsi_nacl_param_show_##name( \
575 struct se_node_acl *se_nacl, \
578 struct iscsi_session *sess; \
579 struct se_session *se_sess; \
582 spin_lock_bh(&se_nacl->nacl_sess_lock); \
583 se_sess = se_nacl->nacl_sess; \
585 rb = snprintf(page, PAGE_SIZE, \
586 "No Active iSCSI Session\n"); \
588 sess = se_sess->fabric_sess_ptr; \
589 rb = snprintf(page, PAGE_SIZE, "%u\n", \
590 (u32)sess->sess_ops->name); \
592 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
597 #define NACL_PARAM_ATTR(_name) TF_NACL_PARAM_ATTR_RO(iscsi, _name);
599 DEF_NACL_PARAM(MaxConnections);
600 NACL_PARAM_ATTR(MaxConnections);
602 DEF_NACL_PARAM(InitialR2T);
603 NACL_PARAM_ATTR(InitialR2T);
605 DEF_NACL_PARAM(ImmediateData);
606 NACL_PARAM_ATTR(ImmediateData);
608 DEF_NACL_PARAM(MaxBurstLength);
609 NACL_PARAM_ATTR(MaxBurstLength);
611 DEF_NACL_PARAM(FirstBurstLength);
612 NACL_PARAM_ATTR(FirstBurstLength);
614 DEF_NACL_PARAM(DefaultTime2Wait);
615 NACL_PARAM_ATTR(DefaultTime2Wait);
617 DEF_NACL_PARAM(DefaultTime2Retain);
618 NACL_PARAM_ATTR(DefaultTime2Retain);
620 DEF_NACL_PARAM(MaxOutstandingR2T);
621 NACL_PARAM_ATTR(MaxOutstandingR2T);
623 DEF_NACL_PARAM(DataPDUInOrder);
624 NACL_PARAM_ATTR(DataPDUInOrder);
626 DEF_NACL_PARAM(DataSequenceInOrder);
627 NACL_PARAM_ATTR(DataSequenceInOrder);
629 DEF_NACL_PARAM(ErrorRecoveryLevel);
630 NACL_PARAM_ATTR(ErrorRecoveryLevel);
632 static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
633 &iscsi_nacl_param_MaxConnections.attr,
634 &iscsi_nacl_param_InitialR2T.attr,
635 &iscsi_nacl_param_ImmediateData.attr,
636 &iscsi_nacl_param_MaxBurstLength.attr,
637 &iscsi_nacl_param_FirstBurstLength.attr,
638 &iscsi_nacl_param_DefaultTime2Wait.attr,
639 &iscsi_nacl_param_DefaultTime2Retain.attr,
640 &iscsi_nacl_param_MaxOutstandingR2T.attr,
641 &iscsi_nacl_param_DataPDUInOrder.attr,
642 &iscsi_nacl_param_DataSequenceInOrder.attr,
643 &iscsi_nacl_param_ErrorRecoveryLevel.attr,
647 /* End items for lio_target_nacl_param_cit */
649 /* Start items for lio_target_acl_cit */
651 static ssize_t lio_target_nacl_show_info(
652 struct se_node_acl *se_nacl,
655 struct iscsi_session *sess;
656 struct iscsi_conn *conn;
657 struct se_session *se_sess;
661 spin_lock_bh(&se_nacl->nacl_sess_lock);
662 se_sess = se_nacl->nacl_sess;
664 rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
665 " Endpoint: %s\n", se_nacl->initiatorname);
667 sess = se_sess->fabric_sess_ptr;
669 rb += sprintf(page+rb, "InitiatorName: %s\n",
670 sess->sess_ops->InitiatorName);
671 rb += sprintf(page+rb, "InitiatorAlias: %s\n",
672 sess->sess_ops->InitiatorAlias);
674 rb += sprintf(page+rb,
675 "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ",
676 sess->sid, sess->isid, sess->tsih);
677 rb += sprintf(page+rb, "SessionType: %s\n",
678 (sess->sess_ops->SessionType) ?
679 "Discovery" : "Normal");
680 rb += sprintf(page+rb, "Session State: ");
681 switch (sess->session_state) {
682 case TARG_SESS_STATE_FREE:
683 rb += sprintf(page+rb, "TARG_SESS_FREE\n");
685 case TARG_SESS_STATE_ACTIVE:
686 rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
688 case TARG_SESS_STATE_LOGGED_IN:
689 rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
691 case TARG_SESS_STATE_FAILED:
692 rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
694 case TARG_SESS_STATE_IN_CONTINUE:
695 rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
698 rb += sprintf(page+rb, "ERROR: Unknown Session"
703 rb += sprintf(page+rb, "---------------------[iSCSI Session"
704 " Values]-----------------------\n");
705 rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
706 " : MaxCmdSN : ITT : TTT\n");
707 max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
708 rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
711 (max_cmd_sn - sess->exp_cmd_sn) + 1,
712 sess->exp_cmd_sn, max_cmd_sn,
713 sess->init_task_tag, sess->targ_xfer_tag);
714 rb += sprintf(page+rb, "----------------------[iSCSI"
715 " Connections]-------------------------\n");
717 spin_lock(&sess->conn_lock);
718 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
719 rb += sprintf(page+rb, "CID: %hu Connection"
720 " State: ", conn->cid);
721 switch (conn->conn_state) {
722 case TARG_CONN_STATE_FREE:
723 rb += sprintf(page+rb,
724 "TARG_CONN_STATE_FREE\n");
726 case TARG_CONN_STATE_XPT_UP:
727 rb += sprintf(page+rb,
728 "TARG_CONN_STATE_XPT_UP\n");
730 case TARG_CONN_STATE_IN_LOGIN:
731 rb += sprintf(page+rb,
732 "TARG_CONN_STATE_IN_LOGIN\n");
734 case TARG_CONN_STATE_LOGGED_IN:
735 rb += sprintf(page+rb,
736 "TARG_CONN_STATE_LOGGED_IN\n");
738 case TARG_CONN_STATE_IN_LOGOUT:
739 rb += sprintf(page+rb,
740 "TARG_CONN_STATE_IN_LOGOUT\n");
742 case TARG_CONN_STATE_LOGOUT_REQUESTED:
743 rb += sprintf(page+rb,
744 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
746 case TARG_CONN_STATE_CLEANUP_WAIT:
747 rb += sprintf(page+rb,
748 "TARG_CONN_STATE_CLEANUP_WAIT\n");
751 rb += sprintf(page+rb,
752 "ERROR: Unknown Connection State!\n");
756 rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr,
757 (conn->network_transport == ISCSI_TCP) ?
759 rb += sprintf(page+rb, " StatSN: 0x%08x\n",
762 spin_unlock(&sess->conn_lock);
764 spin_unlock_bh(&se_nacl->nacl_sess_lock);
769 TF_NACL_BASE_ATTR_RO(lio_target, info);
771 static ssize_t lio_target_nacl_show_cmdsn_depth(
772 struct se_node_acl *se_nacl,
775 return sprintf(page, "%u\n", se_nacl->queue_depth);
778 static ssize_t lio_target_nacl_store_cmdsn_depth(
779 struct se_node_acl *se_nacl,
783 struct se_portal_group *se_tpg = se_nacl->se_tpg;
784 struct iscsi_portal_group *tpg = container_of(se_tpg,
785 struct iscsi_portal_group, tpg_se_tpg);
786 struct config_item *acl_ci, *tpg_ci, *wwn_ci;
790 ret = kstrtou32(page, 0, &cmdsn_depth);
793 if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
794 pr_err("Passed cmdsn_depth: %u exceeds"
795 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
796 TA_DEFAULT_CMDSN_DEPTH_MAX);
799 acl_ci = &se_nacl->acl_group.cg_item;
801 pr_err("Unable to locatel acl_ci\n");
804 tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
806 pr_err("Unable to locate tpg_ci\n");
809 wwn_ci = &tpg_ci->ci_group->cg_item;
811 pr_err("Unable to locate config_item wwn_ci\n");
815 if (iscsit_get_tpg(tpg) < 0)
818 * iscsit_tpg_set_initiator_node_queue_depth() assumes force=1
820 ret = iscsit_tpg_set_initiator_node_queue_depth(tpg,
821 config_item_name(acl_ci), cmdsn_depth, 1);
823 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
824 "InitiatorName: %s\n", config_item_name(wwn_ci),
825 config_item_name(tpg_ci), cmdsn_depth,
826 config_item_name(acl_ci));
829 return (!ret) ? count : (ssize_t)ret;
832 TF_NACL_BASE_ATTR(lio_target, cmdsn_depth, S_IRUGO | S_IWUSR);
834 static ssize_t lio_target_nacl_show_tag(
835 struct se_node_acl *se_nacl,
838 return snprintf(page, PAGE_SIZE, "%s", se_nacl->acl_tag);
841 static ssize_t lio_target_nacl_store_tag(
842 struct se_node_acl *se_nacl,
848 ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
855 TF_NACL_BASE_ATTR(lio_target, tag, S_IRUGO | S_IWUSR);
857 static struct configfs_attribute *lio_target_initiator_attrs[] = {
858 &lio_target_nacl_info.attr,
859 &lio_target_nacl_cmdsn_depth.attr,
860 &lio_target_nacl_tag.attr,
864 static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
867 struct iscsi_node_acl *acl =
868 container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
869 struct config_group *stats_cg = &se_nacl->acl_fabric_stat_group;
871 stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2,
873 if (!stats_cg->default_groups) {
874 pr_err("Unable to allocate memory for"
875 " stats_cg->default_groups\n");
879 stats_cg->default_groups[0] = &acl->node_stat_grps.iscsi_sess_stats_group;
880 stats_cg->default_groups[1] = NULL;
881 config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
882 "iscsi_sess_stats", &iscsi_stat_sess_cit);
887 static void lio_target_cleanup_nodeacl( struct se_node_acl *se_nacl)
889 struct iscsi_node_acl *acl = container_of(se_nacl,
890 struct iscsi_node_acl, se_node_acl);
891 struct config_item *df_item;
892 struct config_group *stats_cg;
895 stats_cg = &acl->se_node_acl.acl_fabric_stat_group;
896 for (i = 0; stats_cg->default_groups[i]; i++) {
897 df_item = &stats_cg->default_groups[i]->cg_item;
898 stats_cg->default_groups[i] = NULL;
899 config_item_put(df_item);
901 kfree(stats_cg->default_groups);
904 /* End items for lio_target_acl_cit */
906 /* Start items for lio_target_tpg_attrib_cit */
908 #define DEF_TPG_ATTRIB(name) \
910 static ssize_t iscsi_tpg_attrib_show_##name( \
911 struct se_portal_group *se_tpg, \
914 struct iscsi_portal_group *tpg = container_of(se_tpg, \
915 struct iscsi_portal_group, tpg_se_tpg); \
918 if (iscsit_get_tpg(tpg) < 0) \
921 rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \
922 iscsit_put_tpg(tpg); \
926 static ssize_t iscsi_tpg_attrib_store_##name( \
927 struct se_portal_group *se_tpg, \
931 struct iscsi_portal_group *tpg = container_of(se_tpg, \
932 struct iscsi_portal_group, tpg_se_tpg); \
936 if (iscsit_get_tpg(tpg) < 0) \
939 ret = kstrtou32(page, 0, &val); \
942 ret = iscsit_ta_##name(tpg, val); \
946 iscsit_put_tpg(tpg); \
949 iscsit_put_tpg(tpg); \
953 #define TPG_ATTR(_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode);
956 * Define iscsi_tpg_attrib_s_authentication
958 DEF_TPG_ATTRIB(authentication);
959 TPG_ATTR(authentication, S_IRUGO | S_IWUSR);
961 * Define iscsi_tpg_attrib_s_login_timeout
963 DEF_TPG_ATTRIB(login_timeout);
964 TPG_ATTR(login_timeout, S_IRUGO | S_IWUSR);
966 * Define iscsi_tpg_attrib_s_netif_timeout
968 DEF_TPG_ATTRIB(netif_timeout);
969 TPG_ATTR(netif_timeout, S_IRUGO | S_IWUSR);
971 * Define iscsi_tpg_attrib_s_generate_node_acls
973 DEF_TPG_ATTRIB(generate_node_acls);
974 TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR);
976 * Define iscsi_tpg_attrib_s_default_cmdsn_depth
978 DEF_TPG_ATTRIB(default_cmdsn_depth);
979 TPG_ATTR(default_cmdsn_depth, S_IRUGO | S_IWUSR);
981 Define iscsi_tpg_attrib_s_cache_dynamic_acls
983 DEF_TPG_ATTRIB(cache_dynamic_acls);
984 TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR);
986 * Define iscsi_tpg_attrib_s_demo_mode_write_protect
988 DEF_TPG_ATTRIB(demo_mode_write_protect);
989 TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR);
991 * Define iscsi_tpg_attrib_s_prod_mode_write_protect
993 DEF_TPG_ATTRIB(prod_mode_write_protect);
994 TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR);
996 * Define iscsi_tpg_attrib_s_demo_mode_discovery,
998 DEF_TPG_ATTRIB(demo_mode_discovery);
999 TPG_ATTR(demo_mode_discovery, S_IRUGO | S_IWUSR);
1001 * Define iscsi_tpg_attrib_s_default_erl
1003 DEF_TPG_ATTRIB(default_erl);
1004 TPG_ATTR(default_erl, S_IRUGO | S_IWUSR);
1006 * Define iscsi_tpg_attrib_s_t10_pi
1008 DEF_TPG_ATTRIB(t10_pi);
1009 TPG_ATTR(t10_pi, S_IRUGO | S_IWUSR);
1011 * Define iscsi_tpg_attrib_s_fabric_prot_type
1013 DEF_TPG_ATTRIB(fabric_prot_type);
1014 TPG_ATTR(fabric_prot_type, S_IRUGO | S_IWUSR);
1016 * Define iscsi_tpg_attrib_s_tpg_enabled_sendtargets
1018 DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
1019 TPG_ATTR(tpg_enabled_sendtargets, S_IRUGO | S_IWUSR);
1021 static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
1022 &iscsi_tpg_attrib_authentication.attr,
1023 &iscsi_tpg_attrib_login_timeout.attr,
1024 &iscsi_tpg_attrib_netif_timeout.attr,
1025 &iscsi_tpg_attrib_generate_node_acls.attr,
1026 &iscsi_tpg_attrib_default_cmdsn_depth.attr,
1027 &iscsi_tpg_attrib_cache_dynamic_acls.attr,
1028 &iscsi_tpg_attrib_demo_mode_write_protect.attr,
1029 &iscsi_tpg_attrib_prod_mode_write_protect.attr,
1030 &iscsi_tpg_attrib_demo_mode_discovery.attr,
1031 &iscsi_tpg_attrib_default_erl.attr,
1032 &iscsi_tpg_attrib_t10_pi.attr,
1033 &iscsi_tpg_attrib_fabric_prot_type.attr,
1034 &iscsi_tpg_attrib_tpg_enabled_sendtargets.attr,
1038 /* End items for lio_target_tpg_attrib_cit */
1040 /* Start items for lio_target_tpg_auth_cit */
1042 #define __DEF_TPG_AUTH_STR(prefix, name, flags) \
1043 static ssize_t __iscsi_##prefix##_show_##name( \
1044 struct se_portal_group *se_tpg, \
1047 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1048 struct iscsi_portal_group, tpg_se_tpg); \
1049 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
1051 if (!capable(CAP_SYS_ADMIN)) \
1054 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
1057 static ssize_t __iscsi_##prefix##_store_##name( \
1058 struct se_portal_group *se_tpg, \
1062 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1063 struct iscsi_portal_group, tpg_se_tpg); \
1064 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
1066 if (!capable(CAP_SYS_ADMIN)) \
1069 snprintf(auth->name, sizeof(auth->name), "%s", page); \
1070 if (!(strncmp("NULL", auth->name, 4))) \
1071 auth->naf_flags &= ~flags; \
1073 auth->naf_flags |= flags; \
1075 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
1076 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
1077 auth->authenticate_target = 1; \
1079 auth->authenticate_target = 0; \
1084 #define __DEF_TPG_AUTH_INT(prefix, name) \
1085 static ssize_t __iscsi_##prefix##_show_##name( \
1086 struct se_portal_group *se_tpg, \
1089 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1090 struct iscsi_portal_group, tpg_se_tpg); \
1091 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
1093 if (!capable(CAP_SYS_ADMIN)) \
1096 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
1099 #define DEF_TPG_AUTH_STR(name, flags) \
1100 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
1101 static ssize_t iscsi_tpg_auth_show_##name( \
1102 struct se_portal_group *se_tpg, \
1105 return __iscsi_tpg_auth_show_##name(se_tpg, page); \
1108 static ssize_t iscsi_tpg_auth_store_##name( \
1109 struct se_portal_group *se_tpg, \
1113 return __iscsi_tpg_auth_store_##name(se_tpg, page, count); \
1116 #define DEF_TPG_AUTH_INT(name) \
1117 __DEF_TPG_AUTH_INT(tpg_auth, name) \
1118 static ssize_t iscsi_tpg_auth_show_##name( \
1119 struct se_portal_group *se_tpg, \
1122 return __iscsi_tpg_auth_show_##name(se_tpg, page); \
1125 #define TPG_AUTH_ATTR(_name, _mode) TF_TPG_AUTH_ATTR(iscsi, _name, _mode);
1126 #define TPG_AUTH_ATTR_RO(_name) TF_TPG_AUTH_ATTR_RO(iscsi, _name);
1129 * * One-way authentication userid
1131 DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
1132 TPG_AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
1134 * * One-way authentication password
1136 DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
1137 TPG_AUTH_ATTR(password, S_IRUGO | S_IWUSR);
1139 * * Enforce mutual authentication
1141 DEF_TPG_AUTH_INT(authenticate_target);
1142 TPG_AUTH_ATTR_RO(authenticate_target);
1144 * * Mutual authentication userid
1146 DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1147 TPG_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
1149 * * Mutual authentication password
1151 DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1152 TPG_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
1154 static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
1155 &iscsi_tpg_auth_userid.attr,
1156 &iscsi_tpg_auth_password.attr,
1157 &iscsi_tpg_auth_authenticate_target.attr,
1158 &iscsi_tpg_auth_userid_mutual.attr,
1159 &iscsi_tpg_auth_password_mutual.attr,
1163 /* End items for lio_target_tpg_auth_cit */
1165 /* Start items for lio_target_tpg_param_cit */
1167 #define DEF_TPG_PARAM(name) \
1168 static ssize_t iscsi_tpg_param_show_##name( \
1169 struct se_portal_group *se_tpg, \
1172 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1173 struct iscsi_portal_group, tpg_se_tpg); \
1174 struct iscsi_param *param; \
1177 if (iscsit_get_tpg(tpg) < 0) \
1180 param = iscsi_find_param_from_key(__stringify(name), \
1183 iscsit_put_tpg(tpg); \
1186 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
1188 iscsit_put_tpg(tpg); \
1191 static ssize_t iscsi_tpg_param_store_##name( \
1192 struct se_portal_group *se_tpg, \
1196 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1197 struct iscsi_portal_group, tpg_se_tpg); \
1201 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
1204 len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
1205 if (isspace(buf[len-1])) \
1206 buf[len-1] = '\0'; /* Kill newline */ \
1208 if (iscsit_get_tpg(tpg) < 0) { \
1213 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
1218 iscsit_put_tpg(tpg); \
1222 iscsit_put_tpg(tpg); \
1226 #define TPG_PARAM_ATTR(_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode);
1228 DEF_TPG_PARAM(AuthMethod);
1229 TPG_PARAM_ATTR(AuthMethod, S_IRUGO | S_IWUSR);
1231 DEF_TPG_PARAM(HeaderDigest);
1232 TPG_PARAM_ATTR(HeaderDigest, S_IRUGO | S_IWUSR);
1234 DEF_TPG_PARAM(DataDigest);
1235 TPG_PARAM_ATTR(DataDigest, S_IRUGO | S_IWUSR);
1237 DEF_TPG_PARAM(MaxConnections);
1238 TPG_PARAM_ATTR(MaxConnections, S_IRUGO | S_IWUSR);
1240 DEF_TPG_PARAM(TargetAlias);
1241 TPG_PARAM_ATTR(TargetAlias, S_IRUGO | S_IWUSR);
1243 DEF_TPG_PARAM(InitialR2T);
1244 TPG_PARAM_ATTR(InitialR2T, S_IRUGO | S_IWUSR);
1246 DEF_TPG_PARAM(ImmediateData);
1247 TPG_PARAM_ATTR(ImmediateData, S_IRUGO | S_IWUSR);
1249 DEF_TPG_PARAM(MaxRecvDataSegmentLength);
1250 TPG_PARAM_ATTR(MaxRecvDataSegmentLength, S_IRUGO | S_IWUSR);
1252 DEF_TPG_PARAM(MaxXmitDataSegmentLength);
1253 TPG_PARAM_ATTR(MaxXmitDataSegmentLength, S_IRUGO | S_IWUSR);
1255 DEF_TPG_PARAM(MaxBurstLength);
1256 TPG_PARAM_ATTR(MaxBurstLength, S_IRUGO | S_IWUSR);
1258 DEF_TPG_PARAM(FirstBurstLength);
1259 TPG_PARAM_ATTR(FirstBurstLength, S_IRUGO | S_IWUSR);
1261 DEF_TPG_PARAM(DefaultTime2Wait);
1262 TPG_PARAM_ATTR(DefaultTime2Wait, S_IRUGO | S_IWUSR);
1264 DEF_TPG_PARAM(DefaultTime2Retain);
1265 TPG_PARAM_ATTR(DefaultTime2Retain, S_IRUGO | S_IWUSR);
1267 DEF_TPG_PARAM(MaxOutstandingR2T);
1268 TPG_PARAM_ATTR(MaxOutstandingR2T, S_IRUGO | S_IWUSR);
1270 DEF_TPG_PARAM(DataPDUInOrder);
1271 TPG_PARAM_ATTR(DataPDUInOrder, S_IRUGO | S_IWUSR);
1273 DEF_TPG_PARAM(DataSequenceInOrder);
1274 TPG_PARAM_ATTR(DataSequenceInOrder, S_IRUGO | S_IWUSR);
1276 DEF_TPG_PARAM(ErrorRecoveryLevel);
1277 TPG_PARAM_ATTR(ErrorRecoveryLevel, S_IRUGO | S_IWUSR);
1279 DEF_TPG_PARAM(IFMarker);
1280 TPG_PARAM_ATTR(IFMarker, S_IRUGO | S_IWUSR);
1282 DEF_TPG_PARAM(OFMarker);
1283 TPG_PARAM_ATTR(OFMarker, S_IRUGO | S_IWUSR);
1285 DEF_TPG_PARAM(IFMarkInt);
1286 TPG_PARAM_ATTR(IFMarkInt, S_IRUGO | S_IWUSR);
1288 DEF_TPG_PARAM(OFMarkInt);
1289 TPG_PARAM_ATTR(OFMarkInt, S_IRUGO | S_IWUSR);
1291 static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
1292 &iscsi_tpg_param_AuthMethod.attr,
1293 &iscsi_tpg_param_HeaderDigest.attr,
1294 &iscsi_tpg_param_DataDigest.attr,
1295 &iscsi_tpg_param_MaxConnections.attr,
1296 &iscsi_tpg_param_TargetAlias.attr,
1297 &iscsi_tpg_param_InitialR2T.attr,
1298 &iscsi_tpg_param_ImmediateData.attr,
1299 &iscsi_tpg_param_MaxRecvDataSegmentLength.attr,
1300 &iscsi_tpg_param_MaxXmitDataSegmentLength.attr,
1301 &iscsi_tpg_param_MaxBurstLength.attr,
1302 &iscsi_tpg_param_FirstBurstLength.attr,
1303 &iscsi_tpg_param_DefaultTime2Wait.attr,
1304 &iscsi_tpg_param_DefaultTime2Retain.attr,
1305 &iscsi_tpg_param_MaxOutstandingR2T.attr,
1306 &iscsi_tpg_param_DataPDUInOrder.attr,
1307 &iscsi_tpg_param_DataSequenceInOrder.attr,
1308 &iscsi_tpg_param_ErrorRecoveryLevel.attr,
1309 &iscsi_tpg_param_IFMarker.attr,
1310 &iscsi_tpg_param_OFMarker.attr,
1311 &iscsi_tpg_param_IFMarkInt.attr,
1312 &iscsi_tpg_param_OFMarkInt.attr,
1316 /* End items for lio_target_tpg_param_cit */
1318 /* Start items for lio_target_tpg_cit */
1320 static ssize_t lio_target_tpg_show_enable(
1321 struct se_portal_group *se_tpg,
1324 struct iscsi_portal_group *tpg = container_of(se_tpg,
1325 struct iscsi_portal_group, tpg_se_tpg);
1328 spin_lock(&tpg->tpg_state_lock);
1329 len = sprintf(page, "%d\n",
1330 (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1331 spin_unlock(&tpg->tpg_state_lock);
1336 static ssize_t lio_target_tpg_store_enable(
1337 struct se_portal_group *se_tpg,
1341 struct iscsi_portal_group *tpg = container_of(se_tpg,
1342 struct iscsi_portal_group, tpg_se_tpg);
1346 ret = kstrtou32(page, 0, &op);
1349 if ((op != 1) && (op != 0)) {
1350 pr_err("Illegal value for tpg_enable: %u\n", op);
1354 ret = iscsit_get_tpg(tpg);
1359 ret = iscsit_tpg_enable_portal_group(tpg);
1364 * iscsit_tpg_disable_portal_group() assumes force=1
1366 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1371 iscsit_put_tpg(tpg);
1374 iscsit_put_tpg(tpg);
1378 TF_TPG_BASE_ATTR(lio_target, enable, S_IRUGO | S_IWUSR);
1380 static ssize_t lio_target_tpg_show_dynamic_sessions(
1381 struct se_portal_group *se_tpg,
1384 return target_show_dynamic_sessions(se_tpg, page);
1387 TF_TPG_BASE_ATTR_RO(lio_target, dynamic_sessions);
1389 static struct configfs_attribute *lio_target_tpg_attrs[] = {
1390 &lio_target_tpg_enable.attr,
1391 &lio_target_tpg_dynamic_sessions.attr,
1395 /* End items for lio_target_tpg_cit */
1397 /* Start items for lio_target_tiqn_cit */
1399 static struct se_portal_group *lio_target_tiqn_addtpg(
1401 struct config_group *group,
1404 struct iscsi_portal_group *tpg;
1405 struct iscsi_tiqn *tiqn;
1410 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1412 * Only tpgt_# directory groups can be created below
1413 * target/iscsi/iqn.superturodiskarry/
1415 tpgt_str = strstr(name, "tpgt_");
1417 pr_err("Unable to locate \"tpgt_#\" directory"
1421 tpgt_str += 5; /* Skip ahead of "tpgt_" */
1422 ret = kstrtou16(tpgt_str, 0, &tpgt);
1426 tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1430 ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
1434 ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1438 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1439 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1441 return &tpg->tpg_se_tpg;
1443 core_tpg_deregister(&tpg->tpg_se_tpg);
1448 static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1450 struct iscsi_portal_group *tpg;
1451 struct iscsi_tiqn *tiqn;
1453 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1454 tiqn = tpg->tpg_tiqn;
1456 * iscsit_tpg_del_portal_group() assumes force=1
1458 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1459 iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1462 /* End items for lio_target_tiqn_cit */
1464 /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1466 static ssize_t lio_target_wwn_show_attr_lio_version(
1467 struct target_fabric_configfs *tf,
1470 return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
1473 TF_WWN_ATTR_RO(lio_target, lio_version);
1475 static struct configfs_attribute *lio_target_wwn_attrs[] = {
1476 &lio_target_wwn_lio_version.attr,
1480 static struct se_wwn *lio_target_call_coreaddtiqn(
1481 struct target_fabric_configfs *tf,
1482 struct config_group *group,
1485 struct config_group *stats_cg;
1486 struct iscsi_tiqn *tiqn;
1488 tiqn = iscsit_add_tiqn((unsigned char *)name);
1490 return ERR_CAST(tiqn);
1492 * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group.
1494 stats_cg = &tiqn->tiqn_wwn.fabric_stat_group;
1496 stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6,
1498 if (!stats_cg->default_groups) {
1499 pr_err("Unable to allocate memory for"
1500 " stats_cg->default_groups\n");
1501 iscsit_del_tiqn(tiqn);
1502 return ERR_PTR(-ENOMEM);
1505 stats_cg->default_groups[0] = &tiqn->tiqn_stat_grps.iscsi_instance_group;
1506 stats_cg->default_groups[1] = &tiqn->tiqn_stat_grps.iscsi_sess_err_group;
1507 stats_cg->default_groups[2] = &tiqn->tiqn_stat_grps.iscsi_tgt_attr_group;
1508 stats_cg->default_groups[3] = &tiqn->tiqn_stat_grps.iscsi_login_stats_group;
1509 stats_cg->default_groups[4] = &tiqn->tiqn_stat_grps.iscsi_logout_stats_group;
1510 stats_cg->default_groups[5] = NULL;
1511 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1512 "iscsi_instance", &iscsi_stat_instance_cit);
1513 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1514 "iscsi_sess_err", &iscsi_stat_sess_err_cit);
1515 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1516 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1517 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1518 "iscsi_login_stats", &iscsi_stat_login_cit);
1519 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1520 "iscsi_logout_stats", &iscsi_stat_logout_cit);
1522 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1523 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1525 return &tiqn->tiqn_wwn;
1528 static void lio_target_call_coredeltiqn(
1531 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1532 struct config_item *df_item;
1533 struct config_group *stats_cg;
1536 stats_cg = &tiqn->tiqn_wwn.fabric_stat_group;
1537 for (i = 0; stats_cg->default_groups[i]; i++) {
1538 df_item = &stats_cg->default_groups[i]->cg_item;
1539 stats_cg->default_groups[i] = NULL;
1540 config_item_put(df_item);
1542 kfree(stats_cg->default_groups);
1544 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1546 iscsit_del_tiqn(tiqn);
1549 /* End LIO-Target TIQN struct contig_lio_target_cit */
1551 /* Start lio_target_discovery_auth_cit */
1553 #define DEF_DISC_AUTH_STR(name, flags) \
1554 __DEF_NACL_AUTH_STR(disc, name, flags) \
1555 static ssize_t iscsi_disc_show_##name( \
1556 struct target_fabric_configfs *tf, \
1559 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \
1562 static ssize_t iscsi_disc_store_##name( \
1563 struct target_fabric_configfs *tf, \
1567 return __iscsi_disc_store_##name(&iscsit_global->discovery_acl, \
1571 #define DEF_DISC_AUTH_INT(name) \
1572 __DEF_NACL_AUTH_INT(disc, name) \
1573 static ssize_t iscsi_disc_show_##name( \
1574 struct target_fabric_configfs *tf, \
1577 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \
1581 #define DISC_AUTH_ATTR(_name, _mode) TF_DISC_ATTR(iscsi, _name, _mode)
1582 #define DISC_AUTH_ATTR_RO(_name) TF_DISC_ATTR_RO(iscsi, _name)
1585 * One-way authentication userid
1587 DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1588 DISC_AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
1590 * One-way authentication password
1592 DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1593 DISC_AUTH_ATTR(password, S_IRUGO | S_IWUSR);
1595 * Enforce mutual authentication
1597 DEF_DISC_AUTH_INT(authenticate_target);
1598 DISC_AUTH_ATTR_RO(authenticate_target);
1600 * Mutual authentication userid
1602 DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1603 DISC_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
1605 * Mutual authentication password
1607 DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1608 DISC_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
1611 * enforce_discovery_auth
1613 static ssize_t iscsi_disc_show_enforce_discovery_auth(
1614 struct target_fabric_configfs *tf,
1617 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1619 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1622 static ssize_t iscsi_disc_store_enforce_discovery_auth(
1623 struct target_fabric_configfs *tf,
1627 struct iscsi_param *param;
1628 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
1632 err = kstrtou32(page, 0, &op);
1635 if ((op != 1) && (op != 0)) {
1636 pr_err("Illegal value for enforce_discovery_auth:"
1641 if (!discovery_tpg) {
1642 pr_err("iscsit_global->discovery_tpg is NULL\n");
1646 param = iscsi_find_param_from_key(AUTHMETHOD,
1647 discovery_tpg->param_list);
1653 * Reset the AuthMethod key to CHAP.
1655 if (iscsi_update_param_value(param, CHAP) < 0)
1658 discovery_tpg->tpg_attrib.authentication = 1;
1659 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1660 pr_debug("LIO-CORE[0] Successfully enabled"
1661 " authentication enforcement for iSCSI"
1662 " Discovery TPG\n");
1665 * Reset the AuthMethod key to CHAP,None
1667 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1670 discovery_tpg->tpg_attrib.authentication = 0;
1671 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1672 pr_debug("LIO-CORE[0] Successfully disabled"
1673 " authentication enforcement for iSCSI"
1674 " Discovery TPG\n");
1680 DISC_AUTH_ATTR(enforce_discovery_auth, S_IRUGO | S_IWUSR);
1682 static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1683 &iscsi_disc_userid.attr,
1684 &iscsi_disc_password.attr,
1685 &iscsi_disc_authenticate_target.attr,
1686 &iscsi_disc_userid_mutual.attr,
1687 &iscsi_disc_password_mutual.attr,
1688 &iscsi_disc_enforce_discovery_auth.attr,
1692 /* End lio_target_discovery_auth_cit */
1694 /* Start functions for target_core_fabric_ops */
1696 static char *iscsi_get_fabric_name(void)
1701 static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1703 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1705 return cmd->i_state;
1708 static u32 lio_sess_get_index(struct se_session *se_sess)
1710 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1712 return sess->session_index;
1715 static u32 lio_sess_get_initiator_sid(
1716 struct se_session *se_sess,
1720 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1722 * iSCSI Initiator Session Identifier from RFC-3720.
1724 return snprintf(buf, size, "%6phN", sess->isid);
1727 static int lio_queue_data_in(struct se_cmd *se_cmd)
1729 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1731 cmd->i_state = ISTATE_SEND_DATAIN;
1732 cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd);
1737 static int lio_write_pending(struct se_cmd *se_cmd)
1739 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1740 struct iscsi_conn *conn = cmd->conn;
1742 if (!cmd->immediate_data && !cmd->unsolicited_data)
1743 return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
1748 static int lio_write_pending_status(struct se_cmd *se_cmd)
1750 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1753 spin_lock_bh(&cmd->istate_lock);
1754 ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1755 spin_unlock_bh(&cmd->istate_lock);
1760 static int lio_queue_status(struct se_cmd *se_cmd)
1762 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1764 cmd->i_state = ISTATE_SEND_STATUS;
1766 if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
1767 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1770 cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd);
1775 static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
1777 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1779 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1780 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1783 static void lio_aborted_task(struct se_cmd *se_cmd)
1785 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1787 cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1790 static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg)
1792 return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1795 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1797 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
1800 static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1802 return iscsi_tpg(se_tpg)->tpgt;
1805 static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1807 return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
1810 static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1812 return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
1815 static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1817 return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
1820 static int lio_tpg_check_demo_mode_write_protect(
1821 struct se_portal_group *se_tpg)
1823 return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
1826 static int lio_tpg_check_prod_mode_write_protect(
1827 struct se_portal_group *se_tpg)
1829 return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
1832 static int lio_tpg_check_prot_fabric_only(
1833 struct se_portal_group *se_tpg)
1836 * Only report fabric_prot_type if t10_pi has also been enabled
1837 * for incoming ib_isert sessions.
1839 if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
1841 return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
1845 * Called with spin_lock_bh(struct se_portal_group->session_lock) held..
1847 * Also, this function calls iscsit_inc_session_usage_count() on the
1848 * struct iscsi_session in question.
1850 static int lio_tpg_shutdown_session(struct se_session *se_sess)
1852 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1854 spin_lock(&sess->conn_lock);
1855 if (atomic_read(&sess->session_fall_back_to_erl0) ||
1856 atomic_read(&sess->session_logout) ||
1857 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1858 spin_unlock(&sess->conn_lock);
1861 atomic_set(&sess->session_reinstatement, 1);
1862 spin_unlock(&sess->conn_lock);
1864 iscsit_stop_time2retain_timer(sess);
1865 iscsit_stop_session(sess, 1, 1);
1871 * Calls iscsit_dec_session_usage_count() as inverse of
1872 * lio_tpg_shutdown_session()
1874 static void lio_tpg_close_session(struct se_session *se_sess)
1876 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1878 * If the iSCSI Session for the iSCSI Initiator Node exists,
1879 * forcefully shutdown the iSCSI NEXUS.
1881 iscsit_close_session(sess);
1884 static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1886 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
1889 static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1891 struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1893 struct se_portal_group *se_tpg = se_acl->se_tpg;
1894 struct iscsi_portal_group *tpg = container_of(se_tpg,
1895 struct iscsi_portal_group, tpg_se_tpg);
1897 acl->node_attrib.nacl = acl;
1898 iscsit_set_default_node_attribues(acl, tpg);
1901 static int lio_check_stop_free(struct se_cmd *se_cmd)
1903 return target_put_sess_cmd(se_cmd);
1906 static void lio_release_cmd(struct se_cmd *se_cmd)
1908 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1910 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
1911 iscsit_release_cmd(cmd);
1914 const struct target_core_fabric_ops iscsi_ops = {
1915 .module = THIS_MODULE,
1917 .node_acl_size = sizeof(struct iscsi_node_acl),
1918 .get_fabric_name = iscsi_get_fabric_name,
1919 .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
1920 .tpg_get_tag = lio_tpg_get_tag,
1921 .tpg_get_default_depth = lio_tpg_get_default_depth,
1922 .tpg_check_demo_mode = lio_tpg_check_demo_mode,
1923 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
1924 .tpg_check_demo_mode_write_protect =
1925 lio_tpg_check_demo_mode_write_protect,
1926 .tpg_check_prod_mode_write_protect =
1927 lio_tpg_check_prod_mode_write_protect,
1928 .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only,
1929 .tpg_get_inst_index = lio_tpg_get_inst_index,
1930 .check_stop_free = lio_check_stop_free,
1931 .release_cmd = lio_release_cmd,
1932 .shutdown_session = lio_tpg_shutdown_session,
1933 .close_session = lio_tpg_close_session,
1934 .sess_get_index = lio_sess_get_index,
1935 .sess_get_initiator_sid = lio_sess_get_initiator_sid,
1936 .write_pending = lio_write_pending,
1937 .write_pending_status = lio_write_pending_status,
1938 .set_default_node_attributes = lio_set_default_node_attributes,
1939 .get_cmd_state = iscsi_get_cmd_state,
1940 .queue_data_in = lio_queue_data_in,
1941 .queue_status = lio_queue_status,
1942 .queue_tm_rsp = lio_queue_tm_rsp,
1943 .aborted_task = lio_aborted_task,
1944 .fabric_make_wwn = lio_target_call_coreaddtiqn,
1945 .fabric_drop_wwn = lio_target_call_coredeltiqn,
1946 .fabric_make_tpg = lio_target_tiqn_addtpg,
1947 .fabric_drop_tpg = lio_target_tiqn_deltpg,
1948 .fabric_make_np = lio_target_call_addnptotpg,
1949 .fabric_drop_np = lio_target_call_delnpfromtpg,
1950 .fabric_init_nodeacl = lio_target_init_nodeacl,
1951 .fabric_cleanup_nodeacl = lio_target_cleanup_nodeacl,
1953 .tfc_discovery_attrs = lio_target_discovery_auth_attrs,
1954 .tfc_wwn_attrs = lio_target_wwn_attrs,
1955 .tfc_tpg_base_attrs = lio_target_tpg_attrs,
1956 .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs,
1957 .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs,
1958 .tfc_tpg_param_attrs = lio_target_tpg_param_attrs,
1959 .tfc_tpg_np_base_attrs = lio_target_portal_attrs,
1960 .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs,
1961 .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs,
1962 .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs,
1963 .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs,