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 <linux/module.h>
26 #include <target/target_core_base.h>
27 #include <target/target_core_fabric.h>
28 #include <target/iscsi/iscsi_transport.h>
29 #include <target/iscsi/iscsi_target_core.h>
30 #include "iscsi_target_parameters.h"
31 #include "iscsi_target_device.h"
32 #include "iscsi_target_erl0.h"
33 #include "iscsi_target_nodeattrib.h"
34 #include "iscsi_target_tpg.h"
35 #include "iscsi_target_util.h"
36 #include "iscsi_target.h"
37 #include <target/iscsi/iscsi_target_stat.h>
40 /* Start items for lio_target_portal_cit */
42 static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item)
44 return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np);
47 static ssize_t lio_target_np_driver_show(struct config_item *item, char *page,
48 enum iscsit_transport_type type)
50 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
51 struct iscsi_tpg_np *tpg_np_new;
54 tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
56 rb = sprintf(page, "1\n");
58 rb = sprintf(page, "0\n");
63 static ssize_t lio_target_np_driver_store(struct config_item *item,
64 const char *page, size_t count, enum iscsit_transport_type type,
67 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
69 struct iscsi_portal_group *tpg;
70 struct iscsi_tpg_np *tpg_np_new = NULL;
74 rc = kstrtou32(page, 0, &op);
77 if ((op != 1) && (op != 0)) {
78 pr_err("Illegal value for tpg_enable: %u\n", op);
83 pr_err("Unable to locate struct iscsi_np from"
84 " struct iscsi_tpg_np\n");
89 if (iscsit_get_tpg(tpg) < 0)
93 if (strlen(mod_name)) {
94 rc = request_module(mod_name);
96 pr_warn("Unable to request_module for %s\n",
102 tpg_np_new = iscsit_tpg_add_network_portal(tpg,
103 &np->np_sockaddr, tpg_np, type);
104 if (IS_ERR(tpg_np_new)) {
105 rc = PTR_ERR(tpg_np_new);
109 tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
111 rc = iscsit_tpg_del_network_portal(tpg, tpg_np_new);
124 static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
126 return lio_target_np_driver_show(item, page, ISCSI_INFINIBAND);
129 static ssize_t lio_target_np_iser_store(struct config_item *item,
130 const char *page, size_t count)
132 return lio_target_np_driver_store(item, page, count,
133 ISCSI_INFINIBAND, "ib_isert");
135 CONFIGFS_ATTR(lio_target_np_, iser);
137 static ssize_t lio_target_np_cxgbit_show(struct config_item *item, char *page)
139 return lio_target_np_driver_show(item, page, ISCSI_CXGBIT);
142 static ssize_t lio_target_np_cxgbit_store(struct config_item *item,
143 const char *page, size_t count)
145 return lio_target_np_driver_store(item, page, count,
146 ISCSI_CXGBIT, "cxgbit");
148 CONFIGFS_ATTR(lio_target_np_, cxgbit);
150 static struct configfs_attribute *lio_target_portal_attrs[] = {
151 &lio_target_np_attr_iser,
152 &lio_target_np_attr_cxgbit,
156 /* Stop items for lio_target_portal_cit */
158 /* Start items for lio_target_np_cit */
160 #define MAX_PORTAL_LEN 256
162 static struct se_tpg_np *lio_target_call_addnptotpg(
163 struct se_portal_group *se_tpg,
164 struct config_group *group,
167 struct iscsi_portal_group *tpg;
168 struct iscsi_tpg_np *tpg_np;
169 char *str, *str2, *ip_str, *port_str;
170 struct sockaddr_storage sockaddr = { };
172 char buf[MAX_PORTAL_LEN + 1];
174 if (strlen(name) > MAX_PORTAL_LEN) {
175 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
176 (int)strlen(name), MAX_PORTAL_LEN);
177 return ERR_PTR(-EOVERFLOW);
179 memset(buf, 0, MAX_PORTAL_LEN + 1);
180 snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
182 str = strstr(buf, "[");
184 str2 = strstr(str, "]");
186 pr_err("Unable to locate trailing \"]\""
187 " in IPv6 iSCSI network portal address\n");
188 return ERR_PTR(-EINVAL);
191 ip_str = str + 1; /* Skip over leading "[" */
192 *str2 = '\0'; /* Terminate the unbracketed IPv6 address */
193 str2++; /* Skip over the \0 */
195 port_str = strstr(str2, ":");
197 pr_err("Unable to locate \":port\""
198 " in IPv6 iSCSI network portal address\n");
199 return ERR_PTR(-EINVAL);
201 *port_str = '\0'; /* Terminate string for IP */
202 port_str++; /* Skip over ":" */
205 port_str = strstr(ip_str, ":");
207 pr_err("Unable to locate \":port\""
208 " in IPv4 iSCSI network portal address\n");
209 return ERR_PTR(-EINVAL);
211 *port_str = '\0'; /* Terminate string for IP */
212 port_str++; /* Skip over ":" */
215 ret = inet_pton_with_scope(&init_net, AF_UNSPEC, ip_str,
216 port_str, &sockaddr);
218 pr_err("malformed ip/port passed: %s\n", name);
222 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
223 ret = iscsit_get_tpg(tpg);
225 return ERR_PTR(-EINVAL);
227 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
229 config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
232 * Assume ISCSI_TCP by default. Other network portals for other
235 * Traditional iSCSI over SCTP (initial support)
236 * iSER/TCP (TODO, hardware available)
237 * iSER/SCTP (TODO, software emulation with osc-iwarp)
238 * iSER/IB (TODO, hardware available)
240 * can be enabled with attributes under
241 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
244 tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
246 if (IS_ERR(tpg_np)) {
248 return ERR_CAST(tpg_np);
250 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
253 return &tpg_np->se_tpg_np;
256 static void lio_target_call_delnpfromtpg(
257 struct se_tpg_np *se_tpg_np)
259 struct iscsi_portal_group *tpg;
260 struct iscsi_tpg_np *tpg_np;
261 struct se_portal_group *se_tpg;
264 tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
266 ret = iscsit_get_tpg(tpg);
270 se_tpg = &tpg->tpg_se_tpg;
271 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
272 " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
273 tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
275 ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
279 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
284 /* End items for lio_target_np_cit */
286 /* Start items for lio_target_nacl_attrib_cit */
288 #define ISCSI_NACL_ATTR(name) \
289 static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
292 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
293 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
296 return sprintf(page, "%u\n", nacl->node_attrib.name); \
299 static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
300 const char *page, size_t count) \
302 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
303 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
308 ret = kstrtou32(page, 0, &val); \
311 ret = iscsit_na_##name(nacl, val); \
318 CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
320 ISCSI_NACL_ATTR(dataout_timeout);
321 ISCSI_NACL_ATTR(dataout_timeout_retries);
322 ISCSI_NACL_ATTR(default_erl);
323 ISCSI_NACL_ATTR(nopin_timeout);
324 ISCSI_NACL_ATTR(nopin_response_timeout);
325 ISCSI_NACL_ATTR(random_datain_pdu_offsets);
326 ISCSI_NACL_ATTR(random_datain_seq_offsets);
327 ISCSI_NACL_ATTR(random_r2t_offsets);
329 static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
330 &iscsi_nacl_attrib_attr_dataout_timeout,
331 &iscsi_nacl_attrib_attr_dataout_timeout_retries,
332 &iscsi_nacl_attrib_attr_default_erl,
333 &iscsi_nacl_attrib_attr_nopin_timeout,
334 &iscsi_nacl_attrib_attr_nopin_response_timeout,
335 &iscsi_nacl_attrib_attr_random_datain_pdu_offsets,
336 &iscsi_nacl_attrib_attr_random_datain_seq_offsets,
337 &iscsi_nacl_attrib_attr_random_r2t_offsets,
341 /* End items for lio_target_nacl_attrib_cit */
343 /* Start items for lio_target_nacl_auth_cit */
345 #define __DEF_NACL_AUTH_STR(prefix, name, flags) \
346 static ssize_t __iscsi_##prefix##_##name##_show( \
347 struct iscsi_node_acl *nacl, \
350 struct iscsi_node_auth *auth = &nacl->node_auth; \
352 if (!capable(CAP_SYS_ADMIN)) \
354 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
357 static ssize_t __iscsi_##prefix##_##name##_store( \
358 struct iscsi_node_acl *nacl, \
362 struct iscsi_node_auth *auth = &nacl->node_auth; \
364 if (!capable(CAP_SYS_ADMIN)) \
366 if (count >= sizeof(auth->name)) \
368 snprintf(auth->name, sizeof(auth->name), "%s", page); \
369 if (!strncmp("NULL", auth->name, 4)) \
370 auth->naf_flags &= ~flags; \
372 auth->naf_flags |= flags; \
374 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
375 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
376 auth->authenticate_target = 1; \
378 auth->authenticate_target = 0; \
383 #define DEF_NACL_AUTH_STR(name, flags) \
384 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
385 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
388 struct se_node_acl *nacl = auth_to_nacl(item); \
389 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
390 struct iscsi_node_acl, se_node_acl), page); \
392 static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \
393 const char *page, size_t count) \
395 struct se_node_acl *nacl = auth_to_nacl(item); \
396 return __iscsi_nacl_auth_##name##_store(container_of(nacl, \
397 struct iscsi_node_acl, se_node_acl), page, count); \
400 CONFIGFS_ATTR(iscsi_nacl_auth_, name)
403 * One-way authentication userid
405 DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
406 DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
407 DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
408 DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
410 #define __DEF_NACL_AUTH_INT(prefix, name) \
411 static ssize_t __iscsi_##prefix##_##name##_show( \
412 struct iscsi_node_acl *nacl, \
415 struct iscsi_node_auth *auth = &nacl->node_auth; \
417 if (!capable(CAP_SYS_ADMIN)) \
420 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
423 #define DEF_NACL_AUTH_INT(name) \
424 __DEF_NACL_AUTH_INT(nacl_auth, name) \
425 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
428 struct se_node_acl *nacl = auth_to_nacl(item); \
429 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
430 struct iscsi_node_acl, se_node_acl), page); \
433 CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
435 DEF_NACL_AUTH_INT(authenticate_target);
437 static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
438 &iscsi_nacl_auth_attr_userid,
439 &iscsi_nacl_auth_attr_password,
440 &iscsi_nacl_auth_attr_authenticate_target,
441 &iscsi_nacl_auth_attr_userid_mutual,
442 &iscsi_nacl_auth_attr_password_mutual,
446 /* End items for lio_target_nacl_auth_cit */
448 /* Start items for lio_target_nacl_param_cit */
450 #define ISCSI_NACL_PARAM(name) \
451 static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \
454 struct se_node_acl *se_nacl = param_to_nacl(item); \
455 struct iscsi_session *sess; \
456 struct se_session *se_sess; \
459 spin_lock_bh(&se_nacl->nacl_sess_lock); \
460 se_sess = se_nacl->nacl_sess; \
462 rb = snprintf(page, PAGE_SIZE, \
463 "No Active iSCSI Session\n"); \
465 sess = se_sess->fabric_sess_ptr; \
466 rb = snprintf(page, PAGE_SIZE, "%u\n", \
467 (u32)sess->sess_ops->name); \
469 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
474 CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
476 ISCSI_NACL_PARAM(MaxConnections);
477 ISCSI_NACL_PARAM(InitialR2T);
478 ISCSI_NACL_PARAM(ImmediateData);
479 ISCSI_NACL_PARAM(MaxBurstLength);
480 ISCSI_NACL_PARAM(FirstBurstLength);
481 ISCSI_NACL_PARAM(DefaultTime2Wait);
482 ISCSI_NACL_PARAM(DefaultTime2Retain);
483 ISCSI_NACL_PARAM(MaxOutstandingR2T);
484 ISCSI_NACL_PARAM(DataPDUInOrder);
485 ISCSI_NACL_PARAM(DataSequenceInOrder);
486 ISCSI_NACL_PARAM(ErrorRecoveryLevel);
488 static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
489 &iscsi_nacl_param_attr_MaxConnections,
490 &iscsi_nacl_param_attr_InitialR2T,
491 &iscsi_nacl_param_attr_ImmediateData,
492 &iscsi_nacl_param_attr_MaxBurstLength,
493 &iscsi_nacl_param_attr_FirstBurstLength,
494 &iscsi_nacl_param_attr_DefaultTime2Wait,
495 &iscsi_nacl_param_attr_DefaultTime2Retain,
496 &iscsi_nacl_param_attr_MaxOutstandingR2T,
497 &iscsi_nacl_param_attr_DataPDUInOrder,
498 &iscsi_nacl_param_attr_DataSequenceInOrder,
499 &iscsi_nacl_param_attr_ErrorRecoveryLevel,
503 /* End items for lio_target_nacl_param_cit */
505 /* Start items for lio_target_acl_cit */
507 static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
509 struct se_node_acl *se_nacl = acl_to_nacl(item);
510 struct iscsi_session *sess;
511 struct iscsi_conn *conn;
512 struct se_session *se_sess;
516 spin_lock_bh(&se_nacl->nacl_sess_lock);
517 se_sess = se_nacl->nacl_sess;
519 rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
520 " Endpoint: %s\n", se_nacl->initiatorname);
522 sess = se_sess->fabric_sess_ptr;
524 rb += sprintf(page+rb, "InitiatorName: %s\n",
525 sess->sess_ops->InitiatorName);
526 rb += sprintf(page+rb, "InitiatorAlias: %s\n",
527 sess->sess_ops->InitiatorAlias);
529 rb += sprintf(page+rb,
530 "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ",
531 sess->sid, sess->isid, sess->tsih);
532 rb += sprintf(page+rb, "SessionType: %s\n",
533 (sess->sess_ops->SessionType) ?
534 "Discovery" : "Normal");
535 rb += sprintf(page+rb, "Session State: ");
536 switch (sess->session_state) {
537 case TARG_SESS_STATE_FREE:
538 rb += sprintf(page+rb, "TARG_SESS_FREE\n");
540 case TARG_SESS_STATE_ACTIVE:
541 rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
543 case TARG_SESS_STATE_LOGGED_IN:
544 rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
546 case TARG_SESS_STATE_FAILED:
547 rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
549 case TARG_SESS_STATE_IN_CONTINUE:
550 rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
553 rb += sprintf(page+rb, "ERROR: Unknown Session"
558 rb += sprintf(page+rb, "---------------------[iSCSI Session"
559 " Values]-----------------------\n");
560 rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
561 " : MaxCmdSN : ITT : TTT\n");
562 max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
563 rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
566 (max_cmd_sn - sess->exp_cmd_sn) + 1,
567 sess->exp_cmd_sn, max_cmd_sn,
568 sess->init_task_tag, sess->targ_xfer_tag);
569 rb += sprintf(page+rb, "----------------------[iSCSI"
570 " Connections]-------------------------\n");
572 spin_lock(&sess->conn_lock);
573 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
574 rb += sprintf(page+rb, "CID: %hu Connection"
575 " State: ", conn->cid);
576 switch (conn->conn_state) {
577 case TARG_CONN_STATE_FREE:
578 rb += sprintf(page+rb,
579 "TARG_CONN_STATE_FREE\n");
581 case TARG_CONN_STATE_XPT_UP:
582 rb += sprintf(page+rb,
583 "TARG_CONN_STATE_XPT_UP\n");
585 case TARG_CONN_STATE_IN_LOGIN:
586 rb += sprintf(page+rb,
587 "TARG_CONN_STATE_IN_LOGIN\n");
589 case TARG_CONN_STATE_LOGGED_IN:
590 rb += sprintf(page+rb,
591 "TARG_CONN_STATE_LOGGED_IN\n");
593 case TARG_CONN_STATE_IN_LOGOUT:
594 rb += sprintf(page+rb,
595 "TARG_CONN_STATE_IN_LOGOUT\n");
597 case TARG_CONN_STATE_LOGOUT_REQUESTED:
598 rb += sprintf(page+rb,
599 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
601 case TARG_CONN_STATE_CLEANUP_WAIT:
602 rb += sprintf(page+rb,
603 "TARG_CONN_STATE_CLEANUP_WAIT\n");
606 rb += sprintf(page+rb,
607 "ERROR: Unknown Connection State!\n");
611 rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr,
612 (conn->network_transport == ISCSI_TCP) ?
614 rb += sprintf(page+rb, " StatSN: 0x%08x\n",
617 spin_unlock(&sess->conn_lock);
619 spin_unlock_bh(&se_nacl->nacl_sess_lock);
624 static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
627 return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth);
630 static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
631 const char *page, size_t count)
633 struct se_node_acl *se_nacl = acl_to_nacl(item);
634 struct se_portal_group *se_tpg = se_nacl->se_tpg;
635 struct iscsi_portal_group *tpg = container_of(se_tpg,
636 struct iscsi_portal_group, tpg_se_tpg);
637 struct config_item *acl_ci, *tpg_ci, *wwn_ci;
641 ret = kstrtou32(page, 0, &cmdsn_depth);
644 if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
645 pr_err("Passed cmdsn_depth: %u exceeds"
646 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
647 TA_DEFAULT_CMDSN_DEPTH_MAX);
650 acl_ci = &se_nacl->acl_group.cg_item;
652 pr_err("Unable to locatel acl_ci\n");
655 tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
657 pr_err("Unable to locate tpg_ci\n");
660 wwn_ci = &tpg_ci->ci_group->cg_item;
662 pr_err("Unable to locate config_item wwn_ci\n");
666 if (iscsit_get_tpg(tpg) < 0)
669 ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth);
671 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
672 "InitiatorName: %s\n", config_item_name(wwn_ci),
673 config_item_name(tpg_ci), cmdsn_depth,
674 config_item_name(acl_ci));
677 return (!ret) ? count : (ssize_t)ret;
680 static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
682 return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
685 static ssize_t lio_target_nacl_tag_store(struct config_item *item,
686 const char *page, size_t count)
688 struct se_node_acl *se_nacl = acl_to_nacl(item);
691 ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
698 CONFIGFS_ATTR_RO(lio_target_nacl_, info);
699 CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
700 CONFIGFS_ATTR(lio_target_nacl_, tag);
702 static struct configfs_attribute *lio_target_initiator_attrs[] = {
703 &lio_target_nacl_attr_info,
704 &lio_target_nacl_attr_cmdsn_depth,
705 &lio_target_nacl_attr_tag,
709 static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
712 struct iscsi_node_acl *acl =
713 container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
715 config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
716 "iscsi_sess_stats", &iscsi_stat_sess_cit);
717 configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group,
718 &se_nacl->acl_fabric_stat_group);
722 /* End items for lio_target_acl_cit */
724 /* Start items for lio_target_tpg_attrib_cit */
726 #define DEF_TPG_ATTRIB(name) \
728 static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \
731 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
732 struct iscsi_portal_group *tpg = container_of(se_tpg, \
733 struct iscsi_portal_group, tpg_se_tpg); \
736 if (iscsit_get_tpg(tpg) < 0) \
739 rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \
740 iscsit_put_tpg(tpg); \
744 static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
745 const char *page, size_t count) \
747 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
748 struct iscsi_portal_group *tpg = container_of(se_tpg, \
749 struct iscsi_portal_group, tpg_se_tpg); \
753 if (iscsit_get_tpg(tpg) < 0) \
756 ret = kstrtou32(page, 0, &val); \
759 ret = iscsit_ta_##name(tpg, val); \
763 iscsit_put_tpg(tpg); \
766 iscsit_put_tpg(tpg); \
769 CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
771 DEF_TPG_ATTRIB(authentication);
772 DEF_TPG_ATTRIB(login_timeout);
773 DEF_TPG_ATTRIB(netif_timeout);
774 DEF_TPG_ATTRIB(generate_node_acls);
775 DEF_TPG_ATTRIB(default_cmdsn_depth);
776 DEF_TPG_ATTRIB(cache_dynamic_acls);
777 DEF_TPG_ATTRIB(demo_mode_write_protect);
778 DEF_TPG_ATTRIB(prod_mode_write_protect);
779 DEF_TPG_ATTRIB(demo_mode_discovery);
780 DEF_TPG_ATTRIB(default_erl);
781 DEF_TPG_ATTRIB(t10_pi);
782 DEF_TPG_ATTRIB(fabric_prot_type);
783 DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
784 DEF_TPG_ATTRIB(login_keys_workaround);
786 static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
787 &iscsi_tpg_attrib_attr_authentication,
788 &iscsi_tpg_attrib_attr_login_timeout,
789 &iscsi_tpg_attrib_attr_netif_timeout,
790 &iscsi_tpg_attrib_attr_generate_node_acls,
791 &iscsi_tpg_attrib_attr_default_cmdsn_depth,
792 &iscsi_tpg_attrib_attr_cache_dynamic_acls,
793 &iscsi_tpg_attrib_attr_demo_mode_write_protect,
794 &iscsi_tpg_attrib_attr_prod_mode_write_protect,
795 &iscsi_tpg_attrib_attr_demo_mode_discovery,
796 &iscsi_tpg_attrib_attr_default_erl,
797 &iscsi_tpg_attrib_attr_t10_pi,
798 &iscsi_tpg_attrib_attr_fabric_prot_type,
799 &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
800 &iscsi_tpg_attrib_attr_login_keys_workaround,
804 /* End items for lio_target_tpg_attrib_cit */
806 /* Start items for lio_target_tpg_auth_cit */
808 #define __DEF_TPG_AUTH_STR(prefix, name, flags) \
809 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
812 struct iscsi_portal_group *tpg = container_of(se_tpg, \
813 struct iscsi_portal_group, tpg_se_tpg); \
814 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
816 if (!capable(CAP_SYS_ADMIN)) \
819 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
822 static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
823 const char *page, size_t count) \
825 struct iscsi_portal_group *tpg = container_of(se_tpg, \
826 struct iscsi_portal_group, tpg_se_tpg); \
827 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
829 if (!capable(CAP_SYS_ADMIN)) \
832 snprintf(auth->name, sizeof(auth->name), "%s", page); \
833 if (!(strncmp("NULL", auth->name, 4))) \
834 auth->naf_flags &= ~flags; \
836 auth->naf_flags |= flags; \
838 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
839 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
840 auth->authenticate_target = 1; \
842 auth->authenticate_target = 0; \
847 #define DEF_TPG_AUTH_STR(name, flags) \
848 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
849 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
852 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
855 static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \
856 const char *page, size_t count) \
858 return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
861 CONFIGFS_ATTR(iscsi_tpg_auth_, name);
864 DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
865 DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
866 DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
867 DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
869 #define __DEF_TPG_AUTH_INT(prefix, name) \
870 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
873 struct iscsi_portal_group *tpg = container_of(se_tpg, \
874 struct iscsi_portal_group, tpg_se_tpg); \
875 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
877 if (!capable(CAP_SYS_ADMIN)) \
880 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
883 #define DEF_TPG_AUTH_INT(name) \
884 __DEF_TPG_AUTH_INT(tpg_auth, name) \
885 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
888 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
890 CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
892 DEF_TPG_AUTH_INT(authenticate_target);
894 static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
895 &iscsi_tpg_auth_attr_userid,
896 &iscsi_tpg_auth_attr_password,
897 &iscsi_tpg_auth_attr_authenticate_target,
898 &iscsi_tpg_auth_attr_userid_mutual,
899 &iscsi_tpg_auth_attr_password_mutual,
903 /* End items for lio_target_tpg_auth_cit */
905 /* Start items for lio_target_tpg_param_cit */
907 #define DEF_TPG_PARAM(name) \
908 static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \
911 struct se_portal_group *se_tpg = param_to_tpg(item); \
912 struct iscsi_portal_group *tpg = container_of(se_tpg, \
913 struct iscsi_portal_group, tpg_se_tpg); \
914 struct iscsi_param *param; \
917 if (iscsit_get_tpg(tpg) < 0) \
920 param = iscsi_find_param_from_key(__stringify(name), \
923 iscsit_put_tpg(tpg); \
926 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
928 iscsit_put_tpg(tpg); \
931 static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
932 const char *page, size_t count) \
934 struct se_portal_group *se_tpg = param_to_tpg(item); \
935 struct iscsi_portal_group *tpg = container_of(se_tpg, \
936 struct iscsi_portal_group, tpg_se_tpg); \
940 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
943 len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
944 if (isspace(buf[len-1])) \
945 buf[len-1] = '\0'; /* Kill newline */ \
947 if (iscsit_get_tpg(tpg) < 0) { \
952 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
957 iscsit_put_tpg(tpg); \
961 iscsit_put_tpg(tpg); \
964 CONFIGFS_ATTR(iscsi_tpg_param_, name)
966 DEF_TPG_PARAM(AuthMethod);
967 DEF_TPG_PARAM(HeaderDigest);
968 DEF_TPG_PARAM(DataDigest);
969 DEF_TPG_PARAM(MaxConnections);
970 DEF_TPG_PARAM(TargetAlias);
971 DEF_TPG_PARAM(InitialR2T);
972 DEF_TPG_PARAM(ImmediateData);
973 DEF_TPG_PARAM(MaxRecvDataSegmentLength);
974 DEF_TPG_PARAM(MaxXmitDataSegmentLength);
975 DEF_TPG_PARAM(MaxBurstLength);
976 DEF_TPG_PARAM(FirstBurstLength);
977 DEF_TPG_PARAM(DefaultTime2Wait);
978 DEF_TPG_PARAM(DefaultTime2Retain);
979 DEF_TPG_PARAM(MaxOutstandingR2T);
980 DEF_TPG_PARAM(DataPDUInOrder);
981 DEF_TPG_PARAM(DataSequenceInOrder);
982 DEF_TPG_PARAM(ErrorRecoveryLevel);
983 DEF_TPG_PARAM(IFMarker);
984 DEF_TPG_PARAM(OFMarker);
985 DEF_TPG_PARAM(IFMarkInt);
986 DEF_TPG_PARAM(OFMarkInt);
988 static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
989 &iscsi_tpg_param_attr_AuthMethod,
990 &iscsi_tpg_param_attr_HeaderDigest,
991 &iscsi_tpg_param_attr_DataDigest,
992 &iscsi_tpg_param_attr_MaxConnections,
993 &iscsi_tpg_param_attr_TargetAlias,
994 &iscsi_tpg_param_attr_InitialR2T,
995 &iscsi_tpg_param_attr_ImmediateData,
996 &iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
997 &iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
998 &iscsi_tpg_param_attr_MaxBurstLength,
999 &iscsi_tpg_param_attr_FirstBurstLength,
1000 &iscsi_tpg_param_attr_DefaultTime2Wait,
1001 &iscsi_tpg_param_attr_DefaultTime2Retain,
1002 &iscsi_tpg_param_attr_MaxOutstandingR2T,
1003 &iscsi_tpg_param_attr_DataPDUInOrder,
1004 &iscsi_tpg_param_attr_DataSequenceInOrder,
1005 &iscsi_tpg_param_attr_ErrorRecoveryLevel,
1006 &iscsi_tpg_param_attr_IFMarker,
1007 &iscsi_tpg_param_attr_OFMarker,
1008 &iscsi_tpg_param_attr_IFMarkInt,
1009 &iscsi_tpg_param_attr_OFMarkInt,
1013 /* End items for lio_target_tpg_param_cit */
1015 /* Start items for lio_target_tpg_cit */
1017 static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page)
1019 struct se_portal_group *se_tpg = to_tpg(item);
1020 struct iscsi_portal_group *tpg = container_of(se_tpg,
1021 struct iscsi_portal_group, tpg_se_tpg);
1024 spin_lock(&tpg->tpg_state_lock);
1025 len = sprintf(page, "%d\n",
1026 (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1027 spin_unlock(&tpg->tpg_state_lock);
1032 static ssize_t lio_target_tpg_enable_store(struct config_item *item,
1033 const char *page, size_t count)
1035 struct se_portal_group *se_tpg = to_tpg(item);
1036 struct iscsi_portal_group *tpg = container_of(se_tpg,
1037 struct iscsi_portal_group, tpg_se_tpg);
1041 ret = kstrtou32(page, 0, &op);
1044 if ((op != 1) && (op != 0)) {
1045 pr_err("Illegal value for tpg_enable: %u\n", op);
1049 ret = iscsit_get_tpg(tpg);
1054 ret = iscsit_tpg_enable_portal_group(tpg);
1059 * iscsit_tpg_disable_portal_group() assumes force=1
1061 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1066 iscsit_put_tpg(tpg);
1069 iscsit_put_tpg(tpg);
1074 static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
1077 return target_show_dynamic_sessions(to_tpg(item), page);
1080 CONFIGFS_ATTR(lio_target_tpg_, enable);
1081 CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
1083 static struct configfs_attribute *lio_target_tpg_attrs[] = {
1084 &lio_target_tpg_attr_enable,
1085 &lio_target_tpg_attr_dynamic_sessions,
1089 /* End items for lio_target_tpg_cit */
1091 /* Start items for lio_target_tiqn_cit */
1093 static struct se_portal_group *lio_target_tiqn_addtpg(struct se_wwn *wwn,
1096 struct iscsi_portal_group *tpg;
1097 struct iscsi_tiqn *tiqn;
1102 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1104 * Only tpgt_# directory groups can be created below
1105 * target/iscsi/iqn.superturodiskarry/
1107 tpgt_str = strstr(name, "tpgt_");
1109 pr_err("Unable to locate \"tpgt_#\" directory"
1113 tpgt_str += 5; /* Skip ahead of "tpgt_" */
1114 ret = kstrtou16(tpgt_str, 0, &tpgt);
1118 tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1122 ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
1126 ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1130 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1131 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1133 return &tpg->tpg_se_tpg;
1135 core_tpg_deregister(&tpg->tpg_se_tpg);
1141 static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1143 struct iscsi_portal_group *tpg;
1144 struct iscsi_tiqn *tiqn;
1146 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1147 tiqn = tpg->tpg_tiqn;
1149 * iscsit_tpg_del_portal_group() assumes force=1
1151 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1152 iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1155 /* End items for lio_target_tiqn_cit */
1157 /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1159 static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
1162 return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
1165 CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
1167 static struct configfs_attribute *lio_target_wwn_attrs[] = {
1168 &lio_target_wwn_attr_lio_version,
1172 static struct se_wwn *lio_target_call_coreaddtiqn(
1173 struct target_fabric_configfs *tf,
1174 struct config_group *group,
1177 struct iscsi_tiqn *tiqn;
1179 tiqn = iscsit_add_tiqn((unsigned char *)name);
1181 return ERR_CAST(tiqn);
1183 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1184 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1186 return &tiqn->tiqn_wwn;
1189 static void lio_target_add_wwn_groups(struct se_wwn *wwn)
1191 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1193 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1194 "iscsi_instance", &iscsi_stat_instance_cit);
1195 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1196 &tiqn->tiqn_wwn.fabric_stat_group);
1198 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1199 "iscsi_sess_err", &iscsi_stat_sess_err_cit);
1200 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1201 &tiqn->tiqn_wwn.fabric_stat_group);
1203 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1204 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1205 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1206 &tiqn->tiqn_wwn.fabric_stat_group);
1208 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1209 "iscsi_login_stats", &iscsi_stat_login_cit);
1210 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1211 &tiqn->tiqn_wwn.fabric_stat_group);
1213 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1214 "iscsi_logout_stats", &iscsi_stat_logout_cit);
1215 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1216 &tiqn->tiqn_wwn.fabric_stat_group);
1219 static void lio_target_call_coredeltiqn(
1222 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1224 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1226 iscsit_del_tiqn(tiqn);
1229 /* End LIO-Target TIQN struct contig_lio_target_cit */
1231 /* Start lio_target_discovery_auth_cit */
1233 #define DEF_DISC_AUTH_STR(name, flags) \
1234 __DEF_NACL_AUTH_STR(disc, name, flags) \
1235 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1237 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
1240 static ssize_t iscsi_disc_##name##_store(struct config_item *item, \
1241 const char *page, size_t count) \
1243 return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \
1247 CONFIGFS_ATTR(iscsi_disc_, name)
1249 DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1250 DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1251 DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1252 DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1254 #define DEF_DISC_AUTH_INT(name) \
1255 __DEF_NACL_AUTH_INT(disc, name) \
1256 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1258 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
1261 CONFIGFS_ATTR_RO(iscsi_disc_, name)
1263 DEF_DISC_AUTH_INT(authenticate_target);
1266 static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
1269 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1271 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1274 static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1275 const char *page, size_t count)
1277 struct iscsi_param *param;
1278 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
1282 err = kstrtou32(page, 0, &op);
1285 if ((op != 1) && (op != 0)) {
1286 pr_err("Illegal value for enforce_discovery_auth:"
1291 if (!discovery_tpg) {
1292 pr_err("iscsit_global->discovery_tpg is NULL\n");
1296 param = iscsi_find_param_from_key(AUTHMETHOD,
1297 discovery_tpg->param_list);
1303 * Reset the AuthMethod key to CHAP.
1305 if (iscsi_update_param_value(param, CHAP) < 0)
1308 discovery_tpg->tpg_attrib.authentication = 1;
1309 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1310 pr_debug("LIO-CORE[0] Successfully enabled"
1311 " authentication enforcement for iSCSI"
1312 " Discovery TPG\n");
1315 * Reset the AuthMethod key to CHAP,None
1317 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1320 discovery_tpg->tpg_attrib.authentication = 0;
1321 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1322 pr_debug("LIO-CORE[0] Successfully disabled"
1323 " authentication enforcement for iSCSI"
1324 " Discovery TPG\n");
1330 CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
1332 static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1333 &iscsi_disc_attr_userid,
1334 &iscsi_disc_attr_password,
1335 &iscsi_disc_attr_authenticate_target,
1336 &iscsi_disc_attr_userid_mutual,
1337 &iscsi_disc_attr_password_mutual,
1338 &iscsi_disc_attr_enforce_discovery_auth,
1342 /* End lio_target_discovery_auth_cit */
1344 /* Start functions for target_core_fabric_ops */
1346 static char *iscsi_get_fabric_name(void)
1351 static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1353 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1355 return cmd->i_state;
1358 static u32 lio_sess_get_index(struct se_session *se_sess)
1360 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1362 return sess->session_index;
1365 static u32 lio_sess_get_initiator_sid(
1366 struct se_session *se_sess,
1370 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1372 * iSCSI Initiator Session Identifier from RFC-3720.
1374 return snprintf(buf, size, "%6phN", sess->isid);
1377 static int lio_queue_data_in(struct se_cmd *se_cmd)
1379 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1380 struct iscsi_conn *conn = cmd->conn;
1382 cmd->i_state = ISTATE_SEND_DATAIN;
1383 return conn->conn_transport->iscsit_queue_data_in(conn, cmd);
1386 static int lio_write_pending(struct se_cmd *se_cmd)
1388 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1389 struct iscsi_conn *conn = cmd->conn;
1391 if (!cmd->immediate_data && !cmd->unsolicited_data)
1392 return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
1397 static int lio_write_pending_status(struct se_cmd *se_cmd)
1399 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1402 spin_lock_bh(&cmd->istate_lock);
1403 ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1404 spin_unlock_bh(&cmd->istate_lock);
1409 static int lio_queue_status(struct se_cmd *se_cmd)
1411 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1412 struct iscsi_conn *conn = cmd->conn;
1414 cmd->i_state = ISTATE_SEND_STATUS;
1416 if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
1417 return iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);
1419 return conn->conn_transport->iscsit_queue_status(conn, cmd);
1422 static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
1424 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1426 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1427 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1430 static void lio_aborted_task(struct se_cmd *se_cmd)
1432 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1434 cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1437 static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg)
1439 return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1442 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1444 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
1447 static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1449 return iscsi_tpg(se_tpg)->tpgt;
1452 static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1454 return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
1457 static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1459 return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
1462 static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1464 return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
1467 static int lio_tpg_check_demo_mode_write_protect(
1468 struct se_portal_group *se_tpg)
1470 return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
1473 static int lio_tpg_check_prod_mode_write_protect(
1474 struct se_portal_group *se_tpg)
1476 return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
1479 static int lio_tpg_check_prot_fabric_only(
1480 struct se_portal_group *se_tpg)
1483 * Only report fabric_prot_type if t10_pi has also been enabled
1484 * for incoming ib_isert sessions.
1486 if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
1488 return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
1492 * This function calls iscsit_inc_session_usage_count() on the
1493 * struct iscsi_session in question.
1495 static void lio_tpg_close_session(struct se_session *se_sess)
1497 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1498 struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
1500 spin_lock_bh(&se_tpg->session_lock);
1501 spin_lock(&sess->conn_lock);
1502 if (atomic_read(&sess->session_fall_back_to_erl0) ||
1503 atomic_read(&sess->session_logout) ||
1504 atomic_read(&sess->session_close) ||
1505 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1506 spin_unlock(&sess->conn_lock);
1507 spin_unlock_bh(&se_tpg->session_lock);
1510 iscsit_inc_session_usage_count(sess);
1511 atomic_set(&sess->session_reinstatement, 1);
1512 atomic_set(&sess->session_fall_back_to_erl0, 1);
1513 atomic_set(&sess->session_close, 1);
1514 spin_unlock(&sess->conn_lock);
1516 iscsit_stop_time2retain_timer(sess);
1517 spin_unlock_bh(&se_tpg->session_lock);
1519 iscsit_stop_session(sess, 1, 1);
1520 iscsit_dec_session_usage_count(sess);
1523 static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1525 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
1528 static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1530 struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1532 struct se_portal_group *se_tpg = se_acl->se_tpg;
1533 struct iscsi_portal_group *tpg = container_of(se_tpg,
1534 struct iscsi_portal_group, tpg_se_tpg);
1536 acl->node_attrib.nacl = acl;
1537 iscsit_set_default_node_attribues(acl, tpg);
1540 static int lio_check_stop_free(struct se_cmd *se_cmd)
1542 return target_put_sess_cmd(se_cmd);
1545 static void lio_release_cmd(struct se_cmd *se_cmd)
1547 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1549 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
1550 iscsit_release_cmd(cmd);
1553 const struct target_core_fabric_ops iscsi_ops = {
1554 .module = THIS_MODULE,
1556 .node_acl_size = sizeof(struct iscsi_node_acl),
1557 .get_fabric_name = iscsi_get_fabric_name,
1558 .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
1559 .tpg_get_tag = lio_tpg_get_tag,
1560 .tpg_get_default_depth = lio_tpg_get_default_depth,
1561 .tpg_check_demo_mode = lio_tpg_check_demo_mode,
1562 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
1563 .tpg_check_demo_mode_write_protect =
1564 lio_tpg_check_demo_mode_write_protect,
1565 .tpg_check_prod_mode_write_protect =
1566 lio_tpg_check_prod_mode_write_protect,
1567 .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only,
1568 .tpg_get_inst_index = lio_tpg_get_inst_index,
1569 .check_stop_free = lio_check_stop_free,
1570 .release_cmd = lio_release_cmd,
1571 .close_session = lio_tpg_close_session,
1572 .sess_get_index = lio_sess_get_index,
1573 .sess_get_initiator_sid = lio_sess_get_initiator_sid,
1574 .write_pending = lio_write_pending,
1575 .write_pending_status = lio_write_pending_status,
1576 .set_default_node_attributes = lio_set_default_node_attributes,
1577 .get_cmd_state = iscsi_get_cmd_state,
1578 .queue_data_in = lio_queue_data_in,
1579 .queue_status = lio_queue_status,
1580 .queue_tm_rsp = lio_queue_tm_rsp,
1581 .aborted_task = lio_aborted_task,
1582 .fabric_make_wwn = lio_target_call_coreaddtiqn,
1583 .fabric_drop_wwn = lio_target_call_coredeltiqn,
1584 .add_wwn_groups = lio_target_add_wwn_groups,
1585 .fabric_make_tpg = lio_target_tiqn_addtpg,
1586 .fabric_drop_tpg = lio_target_tiqn_deltpg,
1587 .fabric_make_np = lio_target_call_addnptotpg,
1588 .fabric_drop_np = lio_target_call_delnpfromtpg,
1589 .fabric_init_nodeacl = lio_target_init_nodeacl,
1591 .tfc_discovery_attrs = lio_target_discovery_auth_attrs,
1592 .tfc_wwn_attrs = lio_target_wwn_attrs,
1593 .tfc_tpg_base_attrs = lio_target_tpg_attrs,
1594 .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs,
1595 .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs,
1596 .tfc_tpg_param_attrs = lio_target_tpg_param_attrs,
1597 .tfc_tpg_np_base_attrs = lio_target_portal_attrs,
1598 .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs,
1599 .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs,
1600 .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs,
1601 .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs,