1 /*******************************************************************************
2 * This file contains the configfs implementation for iSCSI Target mode
3 * from the LIO-Target Project.
5 * \u00a9 Copyright 2007-2011 RisingTide Systems LLC.
7 * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
9 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 ****************************************************************************/
22 #include <linux/configfs.h>
23 #include <linux/export.h>
24 #include <linux/inet.h>
25 #include <target/target_core_base.h>
26 #include <target/target_core_fabric.h>
27 #include <target/target_core_fabric_configfs.h>
28 #include <target/target_core_configfs.h>
29 #include <target/configfs_macros.h>
30 #include <target/iscsi/iscsi_transport.h>
32 #include "iscsi_target_core.h"
33 #include "iscsi_target_parameters.h"
34 #include "iscsi_target_device.h"
35 #include "iscsi_target_erl0.h"
36 #include "iscsi_target_nodeattrib.h"
37 #include "iscsi_target_tpg.h"
38 #include "iscsi_target_util.h"
39 #include "iscsi_target.h"
40 #include "iscsi_target_stat.h"
41 #include "iscsi_target_configfs.h"
43 struct target_fabric_configfs *lio_target_fabric_configfs;
45 struct lio_target_configfs_attribute {
46 struct configfs_attribute attr;
47 ssize_t (*show)(void *, char *);
48 ssize_t (*store)(void *, const char *, size_t);
51 /* Start items for lio_target_portal_cit */
53 static ssize_t lio_target_np_show_sctp(
54 struct se_tpg_np *se_tpg_np,
57 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
58 struct iscsi_tpg_np, se_tpg_np);
59 struct iscsi_tpg_np *tpg_np_sctp;
62 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
64 rb = sprintf(page, "1\n");
66 rb = sprintf(page, "0\n");
71 static ssize_t lio_target_np_store_sctp(
72 struct se_tpg_np *se_tpg_np,
77 struct iscsi_portal_group *tpg;
78 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
79 struct iscsi_tpg_np, se_tpg_np);
80 struct iscsi_tpg_np *tpg_np_sctp = NULL;
85 op = simple_strtoul(page, &endptr, 0);
86 if ((op != 1) && (op != 0)) {
87 pr_err("Illegal value for tpg_enable: %u\n", op);
92 pr_err("Unable to locate struct iscsi_np from"
93 " struct iscsi_tpg_np\n");
98 if (iscsit_get_tpg(tpg) < 0)
103 * Use existing np->np_sockaddr for SCTP network portal reference
105 tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
106 np->np_ip, tpg_np, ISCSI_SCTP_TCP);
107 if (!tpg_np_sctp || IS_ERR(tpg_np_sctp))
110 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
114 ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp);
126 TF_NP_BASE_ATTR(lio_target, sctp, S_IRUGO | S_IWUSR);
128 static ssize_t lio_target_np_show_iser(
129 struct se_tpg_np *se_tpg_np,
132 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
133 struct iscsi_tpg_np, se_tpg_np);
134 struct iscsi_tpg_np *tpg_np_iser;
137 tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
139 rb = sprintf(page, "1\n");
141 rb = sprintf(page, "0\n");
146 static ssize_t lio_target_np_store_iser(
147 struct se_tpg_np *se_tpg_np,
152 struct iscsi_portal_group *tpg;
153 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
154 struct iscsi_tpg_np, se_tpg_np);
155 struct iscsi_tpg_np *tpg_np_iser = NULL;
160 op = simple_strtoul(page, &endptr, 0);
161 if ((op != 1) && (op != 0)) {
162 pr_err("Illegal value for tpg_enable: %u\n", op);
167 pr_err("Unable to locate struct iscsi_np from"
168 " struct iscsi_tpg_np\n");
173 if (iscsit_get_tpg(tpg) < 0)
177 int rc = request_module("ib_isert");
179 pr_warn("Unable to request_module for ib_isert\n");
181 tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
182 np->np_ip, tpg_np, ISCSI_INFINIBAND);
183 if (!tpg_np_iser || IS_ERR(tpg_np_iser))
186 tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
190 rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser);
195 printk("lio_target_np_store_iser() done, op: %d\n", op);
204 TF_NP_BASE_ATTR(lio_target, iser, S_IRUGO | S_IWUSR);
206 static struct configfs_attribute *lio_target_portal_attrs[] = {
207 &lio_target_np_sctp.attr,
208 &lio_target_np_iser.attr,
212 /* Stop items for lio_target_portal_cit */
214 /* Start items for lio_target_np_cit */
216 #define MAX_PORTAL_LEN 256
218 static struct se_tpg_np *lio_target_call_addnptotpg(
219 struct se_portal_group *se_tpg,
220 struct config_group *group,
223 struct iscsi_portal_group *tpg;
224 struct iscsi_tpg_np *tpg_np;
225 char *str, *str2, *ip_str, *port_str;
226 struct __kernel_sockaddr_storage sockaddr;
227 struct sockaddr_in *sock_in;
228 struct sockaddr_in6 *sock_in6;
231 char buf[MAX_PORTAL_LEN + 1];
233 if (strlen(name) > MAX_PORTAL_LEN) {
234 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
235 (int)strlen(name), MAX_PORTAL_LEN);
236 return ERR_PTR(-EOVERFLOW);
238 memset(buf, 0, MAX_PORTAL_LEN + 1);
239 snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
241 memset(&sockaddr, 0, sizeof(struct __kernel_sockaddr_storage));
243 str = strstr(buf, "[");
247 str2 = strstr(str, "]");
249 pr_err("Unable to locate trailing \"]\""
250 " in IPv6 iSCSI network portal address\n");
251 return ERR_PTR(-EINVAL);
253 str++; /* Skip over leading "[" */
254 *str2 = '\0'; /* Terminate the IPv6 address */
255 str2++; /* Skip over the "]" */
256 port_str = strstr(str2, ":");
258 pr_err("Unable to locate \":port\""
259 " in IPv6 iSCSI network portal address\n");
260 return ERR_PTR(-EINVAL);
262 *port_str = '\0'; /* Terminate string for IP */
263 port_str++; /* Skip over ":" */
265 ret = strict_strtoul(port_str, 0, &port);
267 pr_err("strict_strtoul() failed for port_str: %d\n", ret);
270 sock_in6 = (struct sockaddr_in6 *)&sockaddr;
271 sock_in6->sin6_family = AF_INET6;
272 sock_in6->sin6_port = htons((unsigned short)port);
273 ret = in6_pton(str, IPV6_ADDRESS_SPACE,
274 (void *)&sock_in6->sin6_addr.in6_u, -1, &end);
276 pr_err("in6_pton returned: %d\n", ret);
277 return ERR_PTR(-EINVAL);
280 str = ip_str = &buf[0];
281 port_str = strstr(ip_str, ":");
283 pr_err("Unable to locate \":port\""
284 " in IPv4 iSCSI network portal address\n");
285 return ERR_PTR(-EINVAL);
287 *port_str = '\0'; /* Terminate string for IP */
288 port_str++; /* Skip over ":" */
290 ret = strict_strtoul(port_str, 0, &port);
292 pr_err("strict_strtoul() failed for port_str: %d\n", ret);
295 sock_in = (struct sockaddr_in *)&sockaddr;
296 sock_in->sin_family = AF_INET;
297 sock_in->sin_port = htons((unsigned short)port);
298 sock_in->sin_addr.s_addr = in_aton(ip_str);
300 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
301 ret = iscsit_get_tpg(tpg);
303 return ERR_PTR(-EINVAL);
305 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
307 config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
310 * Assume ISCSI_TCP by default. Other network portals for other
313 * Traditional iSCSI over SCTP (initial support)
314 * iSER/TCP (TODO, hardware available)
315 * iSER/SCTP (TODO, software emulation with osc-iwarp)
316 * iSER/IB (TODO, hardware available)
318 * can be enabled with attributes under
319 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
322 tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, str, NULL,
324 if (IS_ERR(tpg_np)) {
326 return ERR_CAST(tpg_np);
328 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
331 return &tpg_np->se_tpg_np;
334 static void lio_target_call_delnpfromtpg(
335 struct se_tpg_np *se_tpg_np)
337 struct iscsi_portal_group *tpg;
338 struct iscsi_tpg_np *tpg_np;
339 struct se_portal_group *se_tpg;
342 tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
344 ret = iscsit_get_tpg(tpg);
348 se_tpg = &tpg->tpg_se_tpg;
349 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
350 " PORTAL: %s:%hu\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
351 tpg->tpgt, tpg_np->tpg_np->np_ip, tpg_np->tpg_np->np_port);
353 ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
357 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
362 /* End items for lio_target_np_cit */
364 /* Start items for lio_target_nacl_attrib_cit */
366 #define DEF_NACL_ATTRIB(name) \
367 static ssize_t iscsi_nacl_attrib_show_##name( \
368 struct se_node_acl *se_nacl, \
371 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
374 return sprintf(page, "%u\n", ISCSI_NODE_ATTRIB(nacl)->name); \
377 static ssize_t iscsi_nacl_attrib_store_##name( \
378 struct se_node_acl *se_nacl, \
382 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
388 val = simple_strtoul(page, &endptr, 0); \
389 ret = iscsit_na_##name(nacl, val); \
396 #define NACL_ATTR(_name, _mode) TF_NACL_ATTRIB_ATTR(iscsi, _name, _mode);
398 * Define iscsi_node_attrib_s_dataout_timeout
400 DEF_NACL_ATTRIB(dataout_timeout);
401 NACL_ATTR(dataout_timeout, S_IRUGO | S_IWUSR);
403 * Define iscsi_node_attrib_s_dataout_timeout_retries
405 DEF_NACL_ATTRIB(dataout_timeout_retries);
406 NACL_ATTR(dataout_timeout_retries, S_IRUGO | S_IWUSR);
408 * Define iscsi_node_attrib_s_default_erl
410 DEF_NACL_ATTRIB(default_erl);
411 NACL_ATTR(default_erl, S_IRUGO | S_IWUSR);
413 * Define iscsi_node_attrib_s_nopin_timeout
415 DEF_NACL_ATTRIB(nopin_timeout);
416 NACL_ATTR(nopin_timeout, S_IRUGO | S_IWUSR);
418 * Define iscsi_node_attrib_s_nopin_response_timeout
420 DEF_NACL_ATTRIB(nopin_response_timeout);
421 NACL_ATTR(nopin_response_timeout, S_IRUGO | S_IWUSR);
423 * Define iscsi_node_attrib_s_random_datain_pdu_offsets
425 DEF_NACL_ATTRIB(random_datain_pdu_offsets);
426 NACL_ATTR(random_datain_pdu_offsets, S_IRUGO | S_IWUSR);
428 * Define iscsi_node_attrib_s_random_datain_seq_offsets
430 DEF_NACL_ATTRIB(random_datain_seq_offsets);
431 NACL_ATTR(random_datain_seq_offsets, S_IRUGO | S_IWUSR);
433 * Define iscsi_node_attrib_s_random_r2t_offsets
435 DEF_NACL_ATTRIB(random_r2t_offsets);
436 NACL_ATTR(random_r2t_offsets, S_IRUGO | S_IWUSR);
438 static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
439 &iscsi_nacl_attrib_dataout_timeout.attr,
440 &iscsi_nacl_attrib_dataout_timeout_retries.attr,
441 &iscsi_nacl_attrib_default_erl.attr,
442 &iscsi_nacl_attrib_nopin_timeout.attr,
443 &iscsi_nacl_attrib_nopin_response_timeout.attr,
444 &iscsi_nacl_attrib_random_datain_pdu_offsets.attr,
445 &iscsi_nacl_attrib_random_datain_seq_offsets.attr,
446 &iscsi_nacl_attrib_random_r2t_offsets.attr,
450 /* End items for lio_target_nacl_attrib_cit */
452 /* Start items for lio_target_nacl_auth_cit */
454 #define __DEF_NACL_AUTH_STR(prefix, name, flags) \
455 static ssize_t __iscsi_##prefix##_show_##name( \
456 struct iscsi_node_acl *nacl, \
459 struct iscsi_node_auth *auth = &nacl->node_auth; \
461 if (!capable(CAP_SYS_ADMIN)) \
463 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
466 static ssize_t __iscsi_##prefix##_store_##name( \
467 struct iscsi_node_acl *nacl, \
471 struct iscsi_node_auth *auth = &nacl->node_auth; \
473 if (!capable(CAP_SYS_ADMIN)) \
476 snprintf(auth->name, PAGE_SIZE, "%s", page); \
477 if (!strncmp("NULL", auth->name, 4)) \
478 auth->naf_flags &= ~flags; \
480 auth->naf_flags |= flags; \
482 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
483 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
484 auth->authenticate_target = 1; \
486 auth->authenticate_target = 0; \
491 #define __DEF_NACL_AUTH_INT(prefix, name) \
492 static ssize_t __iscsi_##prefix##_show_##name( \
493 struct iscsi_node_acl *nacl, \
496 struct iscsi_node_auth *auth = &nacl->node_auth; \
498 if (!capable(CAP_SYS_ADMIN)) \
501 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
504 #define DEF_NACL_AUTH_STR(name, flags) \
505 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
506 static ssize_t iscsi_nacl_auth_show_##name( \
507 struct se_node_acl *nacl, \
510 return __iscsi_nacl_auth_show_##name(container_of(nacl, \
511 struct iscsi_node_acl, se_node_acl), page); \
513 static ssize_t iscsi_nacl_auth_store_##name( \
514 struct se_node_acl *nacl, \
518 return __iscsi_nacl_auth_store_##name(container_of(nacl, \
519 struct iscsi_node_acl, se_node_acl), page, count); \
522 #define DEF_NACL_AUTH_INT(name) \
523 __DEF_NACL_AUTH_INT(nacl_auth, name) \
524 static ssize_t iscsi_nacl_auth_show_##name( \
525 struct se_node_acl *nacl, \
528 return __iscsi_nacl_auth_show_##name(container_of(nacl, \
529 struct iscsi_node_acl, se_node_acl), page); \
532 #define AUTH_ATTR(_name, _mode) TF_NACL_AUTH_ATTR(iscsi, _name, _mode);
533 #define AUTH_ATTR_RO(_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name);
536 * One-way authentication userid
538 DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
539 AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
541 * One-way authentication password
543 DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
544 AUTH_ATTR(password, S_IRUGO | S_IWUSR);
546 * Enforce mutual authentication
548 DEF_NACL_AUTH_INT(authenticate_target);
549 AUTH_ATTR_RO(authenticate_target);
551 * Mutual authentication userid
553 DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
554 AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
556 * Mutual authentication password
558 DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
559 AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
561 static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
562 &iscsi_nacl_auth_userid.attr,
563 &iscsi_nacl_auth_password.attr,
564 &iscsi_nacl_auth_authenticate_target.attr,
565 &iscsi_nacl_auth_userid_mutual.attr,
566 &iscsi_nacl_auth_password_mutual.attr,
570 /* End items for lio_target_nacl_auth_cit */
572 /* Start items for lio_target_nacl_param_cit */
574 #define DEF_NACL_PARAM(name) \
575 static ssize_t iscsi_nacl_param_show_##name( \
576 struct se_node_acl *se_nacl, \
579 struct iscsi_session *sess; \
580 struct se_session *se_sess; \
583 spin_lock_bh(&se_nacl->nacl_sess_lock); \
584 se_sess = se_nacl->nacl_sess; \
586 rb = snprintf(page, PAGE_SIZE, \
587 "No Active iSCSI Session\n"); \
589 sess = se_sess->fabric_sess_ptr; \
590 rb = snprintf(page, PAGE_SIZE, "%u\n", \
591 (u32)sess->sess_ops->name); \
593 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
598 #define NACL_PARAM_ATTR(_name) TF_NACL_PARAM_ATTR_RO(iscsi, _name);
600 DEF_NACL_PARAM(MaxConnections);
601 NACL_PARAM_ATTR(MaxConnections);
603 DEF_NACL_PARAM(InitialR2T);
604 NACL_PARAM_ATTR(InitialR2T);
606 DEF_NACL_PARAM(ImmediateData);
607 NACL_PARAM_ATTR(ImmediateData);
609 DEF_NACL_PARAM(MaxBurstLength);
610 NACL_PARAM_ATTR(MaxBurstLength);
612 DEF_NACL_PARAM(FirstBurstLength);
613 NACL_PARAM_ATTR(FirstBurstLength);
615 DEF_NACL_PARAM(DefaultTime2Wait);
616 NACL_PARAM_ATTR(DefaultTime2Wait);
618 DEF_NACL_PARAM(DefaultTime2Retain);
619 NACL_PARAM_ATTR(DefaultTime2Retain);
621 DEF_NACL_PARAM(MaxOutstandingR2T);
622 NACL_PARAM_ATTR(MaxOutstandingR2T);
624 DEF_NACL_PARAM(DataPDUInOrder);
625 NACL_PARAM_ATTR(DataPDUInOrder);
627 DEF_NACL_PARAM(DataSequenceInOrder);
628 NACL_PARAM_ATTR(DataSequenceInOrder);
630 DEF_NACL_PARAM(ErrorRecoveryLevel);
631 NACL_PARAM_ATTR(ErrorRecoveryLevel);
633 static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
634 &iscsi_nacl_param_MaxConnections.attr,
635 &iscsi_nacl_param_InitialR2T.attr,
636 &iscsi_nacl_param_ImmediateData.attr,
637 &iscsi_nacl_param_MaxBurstLength.attr,
638 &iscsi_nacl_param_FirstBurstLength.attr,
639 &iscsi_nacl_param_DefaultTime2Wait.attr,
640 &iscsi_nacl_param_DefaultTime2Retain.attr,
641 &iscsi_nacl_param_MaxOutstandingR2T.attr,
642 &iscsi_nacl_param_DataPDUInOrder.attr,
643 &iscsi_nacl_param_DataSequenceInOrder.attr,
644 &iscsi_nacl_param_ErrorRecoveryLevel.attr,
648 /* End items for lio_target_nacl_param_cit */
650 /* Start items for lio_target_acl_cit */
652 static ssize_t lio_target_nacl_show_info(
653 struct se_node_acl *se_nacl,
656 struct iscsi_session *sess;
657 struct iscsi_conn *conn;
658 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 if (sess->sess_ops->InitiatorName)
670 rb += sprintf(page+rb, "InitiatorName: %s\n",
671 sess->sess_ops->InitiatorName);
672 if (sess->sess_ops->InitiatorAlias)
673 rb += sprintf(page+rb, "InitiatorAlias: %s\n",
674 sess->sess_ops->InitiatorAlias);
676 rb += sprintf(page+rb, "LIO Session ID: %u "
677 "ISID: 0x%02x %02x %02x %02x %02x %02x "
678 "TSIH: %hu ", sess->sid,
679 sess->isid[0], sess->isid[1], sess->isid[2],
680 sess->isid[3], sess->isid[4], sess->isid[5],
682 rb += sprintf(page+rb, "SessionType: %s\n",
683 (sess->sess_ops->SessionType) ?
684 "Discovery" : "Normal");
685 rb += sprintf(page+rb, "Session State: ");
686 switch (sess->session_state) {
687 case TARG_SESS_STATE_FREE:
688 rb += sprintf(page+rb, "TARG_SESS_FREE\n");
690 case TARG_SESS_STATE_ACTIVE:
691 rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
693 case TARG_SESS_STATE_LOGGED_IN:
694 rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
696 case TARG_SESS_STATE_FAILED:
697 rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
699 case TARG_SESS_STATE_IN_CONTINUE:
700 rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
703 rb += sprintf(page+rb, "ERROR: Unknown Session"
708 rb += sprintf(page+rb, "---------------------[iSCSI Session"
709 " Values]-----------------------\n");
710 rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
711 " : MaxCmdSN : ITT : TTT\n");
712 rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
715 (sess->max_cmd_sn - sess->exp_cmd_sn) + 1,
716 sess->exp_cmd_sn, sess->max_cmd_sn,
717 sess->init_task_tag, sess->targ_xfer_tag);
718 rb += sprintf(page+rb, "----------------------[iSCSI"
719 " Connections]-------------------------\n");
721 spin_lock(&sess->conn_lock);
722 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
723 rb += sprintf(page+rb, "CID: %hu Connection"
724 " State: ", conn->cid);
725 switch (conn->conn_state) {
726 case TARG_CONN_STATE_FREE:
727 rb += sprintf(page+rb,
728 "TARG_CONN_STATE_FREE\n");
730 case TARG_CONN_STATE_XPT_UP:
731 rb += sprintf(page+rb,
732 "TARG_CONN_STATE_XPT_UP\n");
734 case TARG_CONN_STATE_IN_LOGIN:
735 rb += sprintf(page+rb,
736 "TARG_CONN_STATE_IN_LOGIN\n");
738 case TARG_CONN_STATE_LOGGED_IN:
739 rb += sprintf(page+rb,
740 "TARG_CONN_STATE_LOGGED_IN\n");
742 case TARG_CONN_STATE_IN_LOGOUT:
743 rb += sprintf(page+rb,
744 "TARG_CONN_STATE_IN_LOGOUT\n");
746 case TARG_CONN_STATE_LOGOUT_REQUESTED:
747 rb += sprintf(page+rb,
748 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
750 case TARG_CONN_STATE_CLEANUP_WAIT:
751 rb += sprintf(page+rb,
752 "TARG_CONN_STATE_CLEANUP_WAIT\n");
755 rb += sprintf(page+rb,
756 "ERROR: Unknown Connection State!\n");
760 rb += sprintf(page+rb, " Address %s %s", conn->login_ip,
761 (conn->network_transport == ISCSI_TCP) ?
763 rb += sprintf(page+rb, " StatSN: 0x%08x\n",
766 spin_unlock(&sess->conn_lock);
768 spin_unlock_bh(&se_nacl->nacl_sess_lock);
773 TF_NACL_BASE_ATTR_RO(lio_target, info);
775 static ssize_t lio_target_nacl_show_cmdsn_depth(
776 struct se_node_acl *se_nacl,
779 return sprintf(page, "%u\n", se_nacl->queue_depth);
782 static ssize_t lio_target_nacl_store_cmdsn_depth(
783 struct se_node_acl *se_nacl,
787 struct se_portal_group *se_tpg = se_nacl->se_tpg;
788 struct iscsi_portal_group *tpg = container_of(se_tpg,
789 struct iscsi_portal_group, tpg_se_tpg);
790 struct config_item *acl_ci, *tpg_ci, *wwn_ci;
795 cmdsn_depth = simple_strtoul(page, &endptr, 0);
796 if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
797 pr_err("Passed cmdsn_depth: %u exceeds"
798 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
799 TA_DEFAULT_CMDSN_DEPTH_MAX);
802 acl_ci = &se_nacl->acl_group.cg_item;
804 pr_err("Unable to locatel acl_ci\n");
807 tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
809 pr_err("Unable to locate tpg_ci\n");
812 wwn_ci = &tpg_ci->ci_group->cg_item;
814 pr_err("Unable to locate config_item wwn_ci\n");
818 if (iscsit_get_tpg(tpg) < 0)
821 * iscsit_tpg_set_initiator_node_queue_depth() assumes force=1
823 ret = iscsit_tpg_set_initiator_node_queue_depth(tpg,
824 config_item_name(acl_ci), cmdsn_depth, 1);
826 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
827 "InitiatorName: %s\n", config_item_name(wwn_ci),
828 config_item_name(tpg_ci), cmdsn_depth,
829 config_item_name(acl_ci));
832 return (!ret) ? count : (ssize_t)ret;
835 TF_NACL_BASE_ATTR(lio_target, cmdsn_depth, S_IRUGO | S_IWUSR);
837 static ssize_t lio_target_nacl_show_tag(
838 struct se_node_acl *se_nacl,
841 return snprintf(page, PAGE_SIZE, "%s", se_nacl->acl_tag);
844 static ssize_t lio_target_nacl_store_tag(
845 struct se_node_acl *se_nacl,
851 ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
858 TF_NACL_BASE_ATTR(lio_target, tag, S_IRUGO | S_IWUSR);
860 static struct configfs_attribute *lio_target_initiator_attrs[] = {
861 &lio_target_nacl_info.attr,
862 &lio_target_nacl_cmdsn_depth.attr,
863 &lio_target_nacl_tag.attr,
867 static struct se_node_acl *lio_tpg_alloc_fabric_acl(
868 struct se_portal_group *se_tpg)
870 struct iscsi_node_acl *acl;
872 acl = kzalloc(sizeof(struct iscsi_node_acl), GFP_KERNEL);
874 pr_err("Unable to allocate memory for struct iscsi_node_acl\n");
878 return &acl->se_node_acl;
881 static struct se_node_acl *lio_target_make_nodeacl(
882 struct se_portal_group *se_tpg,
883 struct config_group *group,
886 struct config_group *stats_cg;
887 struct iscsi_node_acl *acl;
888 struct se_node_acl *se_nacl_new, *se_nacl;
889 struct iscsi_portal_group *tpg = container_of(se_tpg,
890 struct iscsi_portal_group, tpg_se_tpg);
893 se_nacl_new = lio_tpg_alloc_fabric_acl(se_tpg);
895 return ERR_PTR(-ENOMEM);
897 cmdsn_depth = ISCSI_TPG_ATTRIB(tpg)->default_cmdsn_depth;
899 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
900 * when converting a NdoeACL from demo mode -> explict
902 se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,
907 acl = container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
908 stats_cg = &se_nacl->acl_fabric_stat_group;
910 stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2,
912 if (!stats_cg->default_groups) {
913 pr_err("Unable to allocate memory for"
914 " stats_cg->default_groups\n");
915 core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1);
917 return ERR_PTR(-ENOMEM);
920 stats_cg->default_groups[0] = &NODE_STAT_GRPS(acl)->iscsi_sess_stats_group;
921 stats_cg->default_groups[1] = NULL;
922 config_group_init_type_name(&NODE_STAT_GRPS(acl)->iscsi_sess_stats_group,
923 "iscsi_sess_stats", &iscsi_stat_sess_cit);
928 static void lio_target_drop_nodeacl(
929 struct se_node_acl *se_nacl)
931 struct se_portal_group *se_tpg = se_nacl->se_tpg;
932 struct iscsi_node_acl *acl = container_of(se_nacl,
933 struct iscsi_node_acl, se_node_acl);
934 struct config_item *df_item;
935 struct config_group *stats_cg;
938 stats_cg = &acl->se_node_acl.acl_fabric_stat_group;
939 for (i = 0; stats_cg->default_groups[i]; i++) {
940 df_item = &stats_cg->default_groups[i]->cg_item;
941 stats_cg->default_groups[i] = NULL;
942 config_item_put(df_item);
944 kfree(stats_cg->default_groups);
946 core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1);
950 /* End items for lio_target_acl_cit */
952 /* Start items for lio_target_tpg_attrib_cit */
954 #define DEF_TPG_ATTRIB(name) \
956 static ssize_t iscsi_tpg_attrib_show_##name( \
957 struct se_portal_group *se_tpg, \
960 struct iscsi_portal_group *tpg = container_of(se_tpg, \
961 struct iscsi_portal_group, tpg_se_tpg); \
964 if (iscsit_get_tpg(tpg) < 0) \
967 rb = sprintf(page, "%u\n", ISCSI_TPG_ATTRIB(tpg)->name); \
968 iscsit_put_tpg(tpg); \
972 static ssize_t iscsi_tpg_attrib_store_##name( \
973 struct se_portal_group *se_tpg, \
977 struct iscsi_portal_group *tpg = container_of(se_tpg, \
978 struct iscsi_portal_group, tpg_se_tpg); \
983 if (iscsit_get_tpg(tpg) < 0) \
986 val = simple_strtoul(page, &endptr, 0); \
987 ret = iscsit_ta_##name(tpg, val); \
991 iscsit_put_tpg(tpg); \
994 iscsit_put_tpg(tpg); \
998 #define TPG_ATTR(_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode);
1001 * Define iscsi_tpg_attrib_s_authentication
1003 DEF_TPG_ATTRIB(authentication);
1004 TPG_ATTR(authentication, S_IRUGO | S_IWUSR);
1006 * Define iscsi_tpg_attrib_s_login_timeout
1008 DEF_TPG_ATTRIB(login_timeout);
1009 TPG_ATTR(login_timeout, S_IRUGO | S_IWUSR);
1011 * Define iscsi_tpg_attrib_s_netif_timeout
1013 DEF_TPG_ATTRIB(netif_timeout);
1014 TPG_ATTR(netif_timeout, S_IRUGO | S_IWUSR);
1016 * Define iscsi_tpg_attrib_s_generate_node_acls
1018 DEF_TPG_ATTRIB(generate_node_acls);
1019 TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR);
1021 * Define iscsi_tpg_attrib_s_default_cmdsn_depth
1023 DEF_TPG_ATTRIB(default_cmdsn_depth);
1024 TPG_ATTR(default_cmdsn_depth, S_IRUGO | S_IWUSR);
1026 Define iscsi_tpg_attrib_s_cache_dynamic_acls
1028 DEF_TPG_ATTRIB(cache_dynamic_acls);
1029 TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR);
1031 * Define iscsi_tpg_attrib_s_demo_mode_write_protect
1033 DEF_TPG_ATTRIB(demo_mode_write_protect);
1034 TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR);
1036 * Define iscsi_tpg_attrib_s_prod_mode_write_protect
1038 DEF_TPG_ATTRIB(prod_mode_write_protect);
1039 TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR);
1041 static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
1042 &iscsi_tpg_attrib_authentication.attr,
1043 &iscsi_tpg_attrib_login_timeout.attr,
1044 &iscsi_tpg_attrib_netif_timeout.attr,
1045 &iscsi_tpg_attrib_generate_node_acls.attr,
1046 &iscsi_tpg_attrib_default_cmdsn_depth.attr,
1047 &iscsi_tpg_attrib_cache_dynamic_acls.attr,
1048 &iscsi_tpg_attrib_demo_mode_write_protect.attr,
1049 &iscsi_tpg_attrib_prod_mode_write_protect.attr,
1053 /* End items for lio_target_tpg_attrib_cit */
1055 /* Start items for lio_target_tpg_param_cit */
1057 #define DEF_TPG_PARAM(name) \
1058 static ssize_t iscsi_tpg_param_show_##name( \
1059 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_param *param; \
1067 if (iscsit_get_tpg(tpg) < 0) \
1070 param = iscsi_find_param_from_key(__stringify(name), \
1073 iscsit_put_tpg(tpg); \
1076 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
1078 iscsit_put_tpg(tpg); \
1081 static ssize_t iscsi_tpg_param_store_##name( \
1082 struct se_portal_group *se_tpg, \
1086 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1087 struct iscsi_portal_group, tpg_se_tpg); \
1091 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
1094 snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
1095 buf[strlen(buf)-1] = '\0'; /* Kill newline */ \
1097 if (iscsit_get_tpg(tpg) < 0) { \
1102 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
1107 iscsit_put_tpg(tpg); \
1111 iscsit_put_tpg(tpg); \
1115 #define TPG_PARAM_ATTR(_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode);
1117 DEF_TPG_PARAM(AuthMethod);
1118 TPG_PARAM_ATTR(AuthMethod, S_IRUGO | S_IWUSR);
1120 DEF_TPG_PARAM(HeaderDigest);
1121 TPG_PARAM_ATTR(HeaderDigest, S_IRUGO | S_IWUSR);
1123 DEF_TPG_PARAM(DataDigest);
1124 TPG_PARAM_ATTR(DataDigest, S_IRUGO | S_IWUSR);
1126 DEF_TPG_PARAM(MaxConnections);
1127 TPG_PARAM_ATTR(MaxConnections, S_IRUGO | S_IWUSR);
1129 DEF_TPG_PARAM(TargetAlias);
1130 TPG_PARAM_ATTR(TargetAlias, S_IRUGO | S_IWUSR);
1132 DEF_TPG_PARAM(InitialR2T);
1133 TPG_PARAM_ATTR(InitialR2T, S_IRUGO | S_IWUSR);
1135 DEF_TPG_PARAM(ImmediateData);
1136 TPG_PARAM_ATTR(ImmediateData, S_IRUGO | S_IWUSR);
1138 DEF_TPG_PARAM(MaxRecvDataSegmentLength);
1139 TPG_PARAM_ATTR(MaxRecvDataSegmentLength, S_IRUGO | S_IWUSR);
1141 DEF_TPG_PARAM(MaxXmitDataSegmentLength);
1142 TPG_PARAM_ATTR(MaxXmitDataSegmentLength, S_IRUGO | S_IWUSR);
1144 DEF_TPG_PARAM(MaxBurstLength);
1145 TPG_PARAM_ATTR(MaxBurstLength, S_IRUGO | S_IWUSR);
1147 DEF_TPG_PARAM(FirstBurstLength);
1148 TPG_PARAM_ATTR(FirstBurstLength, S_IRUGO | S_IWUSR);
1150 DEF_TPG_PARAM(DefaultTime2Wait);
1151 TPG_PARAM_ATTR(DefaultTime2Wait, S_IRUGO | S_IWUSR);
1153 DEF_TPG_PARAM(DefaultTime2Retain);
1154 TPG_PARAM_ATTR(DefaultTime2Retain, S_IRUGO | S_IWUSR);
1156 DEF_TPG_PARAM(MaxOutstandingR2T);
1157 TPG_PARAM_ATTR(MaxOutstandingR2T, S_IRUGO | S_IWUSR);
1159 DEF_TPG_PARAM(DataPDUInOrder);
1160 TPG_PARAM_ATTR(DataPDUInOrder, S_IRUGO | S_IWUSR);
1162 DEF_TPG_PARAM(DataSequenceInOrder);
1163 TPG_PARAM_ATTR(DataSequenceInOrder, S_IRUGO | S_IWUSR);
1165 DEF_TPG_PARAM(ErrorRecoveryLevel);
1166 TPG_PARAM_ATTR(ErrorRecoveryLevel, S_IRUGO | S_IWUSR);
1168 DEF_TPG_PARAM(IFMarker);
1169 TPG_PARAM_ATTR(IFMarker, S_IRUGO | S_IWUSR);
1171 DEF_TPG_PARAM(OFMarker);
1172 TPG_PARAM_ATTR(OFMarker, S_IRUGO | S_IWUSR);
1174 DEF_TPG_PARAM(IFMarkInt);
1175 TPG_PARAM_ATTR(IFMarkInt, S_IRUGO | S_IWUSR);
1177 DEF_TPG_PARAM(OFMarkInt);
1178 TPG_PARAM_ATTR(OFMarkInt, S_IRUGO | S_IWUSR);
1180 static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
1181 &iscsi_tpg_param_AuthMethod.attr,
1182 &iscsi_tpg_param_HeaderDigest.attr,
1183 &iscsi_tpg_param_DataDigest.attr,
1184 &iscsi_tpg_param_MaxConnections.attr,
1185 &iscsi_tpg_param_TargetAlias.attr,
1186 &iscsi_tpg_param_InitialR2T.attr,
1187 &iscsi_tpg_param_ImmediateData.attr,
1188 &iscsi_tpg_param_MaxRecvDataSegmentLength.attr,
1189 &iscsi_tpg_param_MaxXmitDataSegmentLength.attr,
1190 &iscsi_tpg_param_MaxBurstLength.attr,
1191 &iscsi_tpg_param_FirstBurstLength.attr,
1192 &iscsi_tpg_param_DefaultTime2Wait.attr,
1193 &iscsi_tpg_param_DefaultTime2Retain.attr,
1194 &iscsi_tpg_param_MaxOutstandingR2T.attr,
1195 &iscsi_tpg_param_DataPDUInOrder.attr,
1196 &iscsi_tpg_param_DataSequenceInOrder.attr,
1197 &iscsi_tpg_param_ErrorRecoveryLevel.attr,
1198 &iscsi_tpg_param_IFMarker.attr,
1199 &iscsi_tpg_param_OFMarker.attr,
1200 &iscsi_tpg_param_IFMarkInt.attr,
1201 &iscsi_tpg_param_OFMarkInt.attr,
1205 /* End items for lio_target_tpg_param_cit */
1207 /* Start items for lio_target_tpg_cit */
1209 static ssize_t lio_target_tpg_show_enable(
1210 struct se_portal_group *se_tpg,
1213 struct iscsi_portal_group *tpg = container_of(se_tpg,
1214 struct iscsi_portal_group, tpg_se_tpg);
1217 spin_lock(&tpg->tpg_state_lock);
1218 len = sprintf(page, "%d\n",
1219 (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1220 spin_unlock(&tpg->tpg_state_lock);
1225 static ssize_t lio_target_tpg_store_enable(
1226 struct se_portal_group *se_tpg,
1230 struct iscsi_portal_group *tpg = container_of(se_tpg,
1231 struct iscsi_portal_group, tpg_se_tpg);
1236 op = simple_strtoul(page, &endptr, 0);
1237 if ((op != 1) && (op != 0)) {
1238 pr_err("Illegal value for tpg_enable: %u\n", op);
1242 ret = iscsit_get_tpg(tpg);
1247 ret = iscsit_tpg_enable_portal_group(tpg);
1252 * iscsit_tpg_disable_portal_group() assumes force=1
1254 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1259 iscsit_put_tpg(tpg);
1262 iscsit_put_tpg(tpg);
1266 TF_TPG_BASE_ATTR(lio_target, enable, S_IRUGO | S_IWUSR);
1268 static struct configfs_attribute *lio_target_tpg_attrs[] = {
1269 &lio_target_tpg_enable.attr,
1273 /* End items for lio_target_tpg_cit */
1275 /* Start items for lio_target_tiqn_cit */
1277 static struct se_portal_group *lio_target_tiqn_addtpg(
1279 struct config_group *group,
1282 struct iscsi_portal_group *tpg;
1283 struct iscsi_tiqn *tiqn;
1284 char *tpgt_str, *end_ptr;
1286 unsigned short int tpgt;
1288 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1290 * Only tpgt_# directory groups can be created below
1291 * target/iscsi/iqn.superturodiskarry/
1293 tpgt_str = strstr(name, "tpgt_");
1295 pr_err("Unable to locate \"tpgt_#\" directory"
1299 tpgt_str += 5; /* Skip ahead of "tpgt_" */
1300 tpgt = (unsigned short int) simple_strtoul(tpgt_str, &end_ptr, 0);
1302 tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1306 ret = core_tpg_register(
1307 &lio_target_fabric_configfs->tf_ops,
1308 wwn, &tpg->tpg_se_tpg, tpg,
1309 TRANSPORT_TPG_TYPE_NORMAL);
1313 ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1317 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1318 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1320 return &tpg->tpg_se_tpg;
1322 core_tpg_deregister(&tpg->tpg_se_tpg);
1327 static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1329 struct iscsi_portal_group *tpg;
1330 struct iscsi_tiqn *tiqn;
1332 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1333 tiqn = tpg->tpg_tiqn;
1335 * iscsit_tpg_del_portal_group() assumes force=1
1337 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1338 iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1341 /* End items for lio_target_tiqn_cit */
1343 /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1345 static ssize_t lio_target_wwn_show_attr_lio_version(
1346 struct target_fabric_configfs *tf,
1349 return sprintf(page, "RisingTide Systems Linux-iSCSI Target "ISCSIT_VERSION"\n");
1352 TF_WWN_ATTR_RO(lio_target, lio_version);
1354 static struct configfs_attribute *lio_target_wwn_attrs[] = {
1355 &lio_target_wwn_lio_version.attr,
1359 static struct se_wwn *lio_target_call_coreaddtiqn(
1360 struct target_fabric_configfs *tf,
1361 struct config_group *group,
1364 struct config_group *stats_cg;
1365 struct iscsi_tiqn *tiqn;
1367 tiqn = iscsit_add_tiqn((unsigned char *)name);
1369 return ERR_CAST(tiqn);
1371 * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group.
1373 stats_cg = &tiqn->tiqn_wwn.fabric_stat_group;
1375 stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6,
1377 if (!stats_cg->default_groups) {
1378 pr_err("Unable to allocate memory for"
1379 " stats_cg->default_groups\n");
1380 iscsit_del_tiqn(tiqn);
1381 return ERR_PTR(-ENOMEM);
1384 stats_cg->default_groups[0] = &WWN_STAT_GRPS(tiqn)->iscsi_instance_group;
1385 stats_cg->default_groups[1] = &WWN_STAT_GRPS(tiqn)->iscsi_sess_err_group;
1386 stats_cg->default_groups[2] = &WWN_STAT_GRPS(tiqn)->iscsi_tgt_attr_group;
1387 stats_cg->default_groups[3] = &WWN_STAT_GRPS(tiqn)->iscsi_login_stats_group;
1388 stats_cg->default_groups[4] = &WWN_STAT_GRPS(tiqn)->iscsi_logout_stats_group;
1389 stats_cg->default_groups[5] = NULL;
1390 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_instance_group,
1391 "iscsi_instance", &iscsi_stat_instance_cit);
1392 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_sess_err_group,
1393 "iscsi_sess_err", &iscsi_stat_sess_err_cit);
1394 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_tgt_attr_group,
1395 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1396 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_login_stats_group,
1397 "iscsi_login_stats", &iscsi_stat_login_cit);
1398 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_logout_stats_group,
1399 "iscsi_logout_stats", &iscsi_stat_logout_cit);
1401 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1402 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1404 return &tiqn->tiqn_wwn;
1407 static void lio_target_call_coredeltiqn(
1410 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1411 struct config_item *df_item;
1412 struct config_group *stats_cg;
1415 stats_cg = &tiqn->tiqn_wwn.fabric_stat_group;
1416 for (i = 0; stats_cg->default_groups[i]; i++) {
1417 df_item = &stats_cg->default_groups[i]->cg_item;
1418 stats_cg->default_groups[i] = NULL;
1419 config_item_put(df_item);
1421 kfree(stats_cg->default_groups);
1423 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1425 iscsit_del_tiqn(tiqn);
1428 /* End LIO-Target TIQN struct contig_lio_target_cit */
1430 /* Start lio_target_discovery_auth_cit */
1432 #define DEF_DISC_AUTH_STR(name, flags) \
1433 __DEF_NACL_AUTH_STR(disc, name, flags) \
1434 static ssize_t iscsi_disc_show_##name( \
1435 struct target_fabric_configfs *tf, \
1438 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \
1441 static ssize_t iscsi_disc_store_##name( \
1442 struct target_fabric_configfs *tf, \
1446 return __iscsi_disc_store_##name(&iscsit_global->discovery_acl, \
1450 #define DEF_DISC_AUTH_INT(name) \
1451 __DEF_NACL_AUTH_INT(disc, name) \
1452 static ssize_t iscsi_disc_show_##name( \
1453 struct target_fabric_configfs *tf, \
1456 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \
1460 #define DISC_AUTH_ATTR(_name, _mode) TF_DISC_ATTR(iscsi, _name, _mode)
1461 #define DISC_AUTH_ATTR_RO(_name) TF_DISC_ATTR_RO(iscsi, _name)
1464 * One-way authentication userid
1466 DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1467 DISC_AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
1469 * One-way authentication password
1471 DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1472 DISC_AUTH_ATTR(password, S_IRUGO | S_IWUSR);
1474 * Enforce mutual authentication
1476 DEF_DISC_AUTH_INT(authenticate_target);
1477 DISC_AUTH_ATTR_RO(authenticate_target);
1479 * Mutual authentication userid
1481 DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1482 DISC_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
1484 * Mutual authentication password
1486 DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1487 DISC_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
1490 * enforce_discovery_auth
1492 static ssize_t iscsi_disc_show_enforce_discovery_auth(
1493 struct target_fabric_configfs *tf,
1496 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1498 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1501 static ssize_t iscsi_disc_store_enforce_discovery_auth(
1502 struct target_fabric_configfs *tf,
1506 struct iscsi_param *param;
1507 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
1511 op = simple_strtoul(page, &endptr, 0);
1512 if ((op != 1) && (op != 0)) {
1513 pr_err("Illegal value for enforce_discovery_auth:"
1518 if (!discovery_tpg) {
1519 pr_err("iscsit_global->discovery_tpg is NULL\n");
1523 param = iscsi_find_param_from_key(AUTHMETHOD,
1524 discovery_tpg->param_list);
1530 * Reset the AuthMethod key to CHAP.
1532 if (iscsi_update_param_value(param, CHAP) < 0)
1535 discovery_tpg->tpg_attrib.authentication = 1;
1536 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1537 pr_debug("LIO-CORE[0] Successfully enabled"
1538 " authentication enforcement for iSCSI"
1539 " Discovery TPG\n");
1542 * Reset the AuthMethod key to CHAP,None
1544 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1547 discovery_tpg->tpg_attrib.authentication = 0;
1548 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1549 pr_debug("LIO-CORE[0] Successfully disabled"
1550 " authentication enforcement for iSCSI"
1551 " Discovery TPG\n");
1557 DISC_AUTH_ATTR(enforce_discovery_auth, S_IRUGO | S_IWUSR);
1559 static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1560 &iscsi_disc_userid.attr,
1561 &iscsi_disc_password.attr,
1562 &iscsi_disc_authenticate_target.attr,
1563 &iscsi_disc_userid_mutual.attr,
1564 &iscsi_disc_password_mutual.attr,
1565 &iscsi_disc_enforce_discovery_auth.attr,
1569 /* End lio_target_discovery_auth_cit */
1571 /* Start functions for target_core_fabric_ops */
1573 static char *iscsi_get_fabric_name(void)
1578 static u32 iscsi_get_task_tag(struct se_cmd *se_cmd)
1580 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1582 /* only used for printks or comparism with ->ref_task_tag */
1583 return (__force u32)cmd->init_task_tag;
1586 static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1588 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1590 return cmd->i_state;
1593 static u32 lio_sess_get_index(struct se_session *se_sess)
1595 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1597 return sess->session_index;
1600 static u32 lio_sess_get_initiator_sid(
1601 struct se_session *se_sess,
1605 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1607 * iSCSI Initiator Session Identifier from RFC-3720.
1609 return snprintf(buf, size, "%02x%02x%02x%02x%02x%02x",
1610 sess->isid[0], sess->isid[1], sess->isid[2],
1611 sess->isid[3], sess->isid[4], sess->isid[5]);
1614 static int lio_queue_data_in(struct se_cmd *se_cmd)
1616 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1618 cmd->i_state = ISTATE_SEND_DATAIN;
1619 cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd);
1624 static int lio_write_pending(struct se_cmd *se_cmd)
1626 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1627 struct iscsi_conn *conn = cmd->conn;
1629 if (!cmd->immediate_data && !cmd->unsolicited_data)
1630 return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
1635 static int lio_write_pending_status(struct se_cmd *se_cmd)
1637 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1640 spin_lock_bh(&cmd->istate_lock);
1641 ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1642 spin_unlock_bh(&cmd->istate_lock);
1647 static int lio_queue_status(struct se_cmd *se_cmd)
1649 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1651 cmd->i_state = ISTATE_SEND_STATUS;
1652 cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd);
1657 static int lio_queue_tm_rsp(struct se_cmd *se_cmd)
1659 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1661 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1662 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1666 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1668 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1670 return &tpg->tpg_tiqn->tiqn[0];
1673 static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1675 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1680 static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1682 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1684 return ISCSI_TPG_ATTRIB(tpg)->default_cmdsn_depth;
1687 static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1689 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1691 return ISCSI_TPG_ATTRIB(tpg)->generate_node_acls;
1694 static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1696 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1698 return ISCSI_TPG_ATTRIB(tpg)->cache_dynamic_acls;
1701 static int lio_tpg_check_demo_mode_write_protect(
1702 struct se_portal_group *se_tpg)
1704 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1706 return ISCSI_TPG_ATTRIB(tpg)->demo_mode_write_protect;
1709 static int lio_tpg_check_prod_mode_write_protect(
1710 struct se_portal_group *se_tpg)
1712 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1714 return ISCSI_TPG_ATTRIB(tpg)->prod_mode_write_protect;
1717 static void lio_tpg_release_fabric_acl(
1718 struct se_portal_group *se_tpg,
1719 struct se_node_acl *se_acl)
1721 struct iscsi_node_acl *acl = container_of(se_acl,
1722 struct iscsi_node_acl, se_node_acl);
1727 * Called with spin_lock_bh(struct se_portal_group->session_lock) held..
1729 * Also, this function calls iscsit_inc_session_usage_count() on the
1730 * struct iscsi_session in question.
1732 static int lio_tpg_shutdown_session(struct se_session *se_sess)
1734 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1736 spin_lock(&sess->conn_lock);
1737 if (atomic_read(&sess->session_fall_back_to_erl0) ||
1738 atomic_read(&sess->session_logout) ||
1739 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1740 spin_unlock(&sess->conn_lock);
1743 atomic_set(&sess->session_reinstatement, 1);
1744 spin_unlock(&sess->conn_lock);
1746 iscsit_stop_time2retain_timer(sess);
1747 iscsit_stop_session(sess, 1, 1);
1753 * Calls iscsit_dec_session_usage_count() as inverse of
1754 * lio_tpg_shutdown_session()
1756 static void lio_tpg_close_session(struct se_session *se_sess)
1758 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1760 * If the iSCSI Session for the iSCSI Initiator Node exists,
1761 * forcefully shutdown the iSCSI NEXUS.
1763 iscsit_close_session(sess);
1766 static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1768 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1770 return tpg->tpg_tiqn->tiqn_index;
1773 static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1775 struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1778 ISCSI_NODE_ATTRIB(acl)->nacl = acl;
1779 iscsit_set_default_node_attribues(acl);
1782 static int lio_check_stop_free(struct se_cmd *se_cmd)
1784 return target_put_sess_cmd(se_cmd->se_sess, se_cmd);
1787 static void lio_release_cmd(struct se_cmd *se_cmd)
1789 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1791 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
1792 cmd->release_cmd(cmd);
1795 /* End functions for target_core_fabric_ops */
1797 int iscsi_target_register_configfs(void)
1799 struct target_fabric_configfs *fabric;
1802 lio_target_fabric_configfs = NULL;
1803 fabric = target_fabric_configfs_init(THIS_MODULE, "iscsi");
1804 if (IS_ERR(fabric)) {
1805 pr_err("target_fabric_configfs_init() for"
1806 " LIO-Target failed!\n");
1807 return PTR_ERR(fabric);
1810 * Setup the fabric API of function pointers used by target_core_mod..
1812 fabric->tf_ops.get_fabric_name = &iscsi_get_fabric_name;
1813 fabric->tf_ops.get_fabric_proto_ident = &iscsi_get_fabric_proto_ident;
1814 fabric->tf_ops.tpg_get_wwn = &lio_tpg_get_endpoint_wwn;
1815 fabric->tf_ops.tpg_get_tag = &lio_tpg_get_tag;
1816 fabric->tf_ops.tpg_get_default_depth = &lio_tpg_get_default_depth;
1817 fabric->tf_ops.tpg_get_pr_transport_id = &iscsi_get_pr_transport_id;
1818 fabric->tf_ops.tpg_get_pr_transport_id_len =
1819 &iscsi_get_pr_transport_id_len;
1820 fabric->tf_ops.tpg_parse_pr_out_transport_id =
1821 &iscsi_parse_pr_out_transport_id;
1822 fabric->tf_ops.tpg_check_demo_mode = &lio_tpg_check_demo_mode;
1823 fabric->tf_ops.tpg_check_demo_mode_cache =
1824 &lio_tpg_check_demo_mode_cache;
1825 fabric->tf_ops.tpg_check_demo_mode_write_protect =
1826 &lio_tpg_check_demo_mode_write_protect;
1827 fabric->tf_ops.tpg_check_prod_mode_write_protect =
1828 &lio_tpg_check_prod_mode_write_protect;
1829 fabric->tf_ops.tpg_alloc_fabric_acl = &lio_tpg_alloc_fabric_acl;
1830 fabric->tf_ops.tpg_release_fabric_acl = &lio_tpg_release_fabric_acl;
1831 fabric->tf_ops.tpg_get_inst_index = &lio_tpg_get_inst_index;
1832 fabric->tf_ops.check_stop_free = &lio_check_stop_free,
1833 fabric->tf_ops.release_cmd = &lio_release_cmd;
1834 fabric->tf_ops.shutdown_session = &lio_tpg_shutdown_session;
1835 fabric->tf_ops.close_session = &lio_tpg_close_session;
1836 fabric->tf_ops.sess_get_index = &lio_sess_get_index;
1837 fabric->tf_ops.sess_get_initiator_sid = &lio_sess_get_initiator_sid;
1838 fabric->tf_ops.write_pending = &lio_write_pending;
1839 fabric->tf_ops.write_pending_status = &lio_write_pending_status;
1840 fabric->tf_ops.set_default_node_attributes =
1841 &lio_set_default_node_attributes;
1842 fabric->tf_ops.get_task_tag = &iscsi_get_task_tag;
1843 fabric->tf_ops.get_cmd_state = &iscsi_get_cmd_state;
1844 fabric->tf_ops.queue_data_in = &lio_queue_data_in;
1845 fabric->tf_ops.queue_status = &lio_queue_status;
1846 fabric->tf_ops.queue_tm_rsp = &lio_queue_tm_rsp;
1848 * Setup function pointers for generic logic in target_core_fabric_configfs.c
1850 fabric->tf_ops.fabric_make_wwn = &lio_target_call_coreaddtiqn;
1851 fabric->tf_ops.fabric_drop_wwn = &lio_target_call_coredeltiqn;
1852 fabric->tf_ops.fabric_make_tpg = &lio_target_tiqn_addtpg;
1853 fabric->tf_ops.fabric_drop_tpg = &lio_target_tiqn_deltpg;
1854 fabric->tf_ops.fabric_post_link = NULL;
1855 fabric->tf_ops.fabric_pre_unlink = NULL;
1856 fabric->tf_ops.fabric_make_np = &lio_target_call_addnptotpg;
1857 fabric->tf_ops.fabric_drop_np = &lio_target_call_delnpfromtpg;
1858 fabric->tf_ops.fabric_make_nodeacl = &lio_target_make_nodeacl;
1859 fabric->tf_ops.fabric_drop_nodeacl = &lio_target_drop_nodeacl;
1861 * Setup default attribute lists for various fabric->tf_cit_tmpl
1862 * sturct config_item_type's
1864 TF_CIT_TMPL(fabric)->tfc_discovery_cit.ct_attrs = lio_target_discovery_auth_attrs;
1865 TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = lio_target_wwn_attrs;
1866 TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = lio_target_tpg_attrs;
1867 TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = lio_target_tpg_attrib_attrs;
1868 TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = lio_target_tpg_param_attrs;
1869 TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = lio_target_portal_attrs;
1870 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs = lio_target_initiator_attrs;
1871 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = lio_target_nacl_attrib_attrs;
1872 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = lio_target_nacl_auth_attrs;
1873 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_param_cit.ct_attrs = lio_target_nacl_param_attrs;
1875 ret = target_fabric_configfs_register(fabric);
1877 pr_err("target_fabric_configfs_register() for"
1878 " LIO-Target failed!\n");
1879 target_fabric_configfs_free(fabric);
1883 lio_target_fabric_configfs = fabric;
1884 pr_debug("LIO_TARGET[0] - Set fabric ->"
1885 " lio_target_fabric_configfs\n");
1890 void iscsi_target_deregister_configfs(void)
1892 if (!lio_target_fabric_configfs)
1895 * Shutdown discovery sessions and disable discovery TPG
1897 if (iscsit_global->discovery_tpg)
1898 iscsit_tpg_disable_portal_group(iscsit_global->discovery_tpg, 1);
1900 target_fabric_configfs_deregister(lio_target_fabric_configfs);
1901 lio_target_fabric_configfs = NULL;
1902 pr_debug("LIO_TARGET[0] - Cleared"
1903 " lio_target_fabric_configfs\n");