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);
785 static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
786 &iscsi_tpg_attrib_attr_authentication,
787 &iscsi_tpg_attrib_attr_login_timeout,
788 &iscsi_tpg_attrib_attr_netif_timeout,
789 &iscsi_tpg_attrib_attr_generate_node_acls,
790 &iscsi_tpg_attrib_attr_default_cmdsn_depth,
791 &iscsi_tpg_attrib_attr_cache_dynamic_acls,
792 &iscsi_tpg_attrib_attr_demo_mode_write_protect,
793 &iscsi_tpg_attrib_attr_prod_mode_write_protect,
794 &iscsi_tpg_attrib_attr_demo_mode_discovery,
795 &iscsi_tpg_attrib_attr_default_erl,
796 &iscsi_tpg_attrib_attr_t10_pi,
797 &iscsi_tpg_attrib_attr_fabric_prot_type,
798 &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
802 /* End items for lio_target_tpg_attrib_cit */
804 /* Start items for lio_target_tpg_auth_cit */
806 #define __DEF_TPG_AUTH_STR(prefix, name, flags) \
807 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
810 struct iscsi_portal_group *tpg = container_of(se_tpg, \
811 struct iscsi_portal_group, tpg_se_tpg); \
812 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
814 if (!capable(CAP_SYS_ADMIN)) \
817 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
820 static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
821 const char *page, size_t count) \
823 struct iscsi_portal_group *tpg = container_of(se_tpg, \
824 struct iscsi_portal_group, tpg_se_tpg); \
825 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
827 if (!capable(CAP_SYS_ADMIN)) \
830 snprintf(auth->name, sizeof(auth->name), "%s", page); \
831 if (!(strncmp("NULL", auth->name, 4))) \
832 auth->naf_flags &= ~flags; \
834 auth->naf_flags |= flags; \
836 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
837 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
838 auth->authenticate_target = 1; \
840 auth->authenticate_target = 0; \
845 #define DEF_TPG_AUTH_STR(name, flags) \
846 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
847 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
850 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
853 static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \
854 const char *page, size_t count) \
856 return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
859 CONFIGFS_ATTR(iscsi_tpg_auth_, name);
862 DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
863 DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
864 DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
865 DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
867 #define __DEF_TPG_AUTH_INT(prefix, name) \
868 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
871 struct iscsi_portal_group *tpg = container_of(se_tpg, \
872 struct iscsi_portal_group, tpg_se_tpg); \
873 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
875 if (!capable(CAP_SYS_ADMIN)) \
878 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
881 #define DEF_TPG_AUTH_INT(name) \
882 __DEF_TPG_AUTH_INT(tpg_auth, name) \
883 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
886 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
888 CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
890 DEF_TPG_AUTH_INT(authenticate_target);
892 static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
893 &iscsi_tpg_auth_attr_userid,
894 &iscsi_tpg_auth_attr_password,
895 &iscsi_tpg_auth_attr_authenticate_target,
896 &iscsi_tpg_auth_attr_userid_mutual,
897 &iscsi_tpg_auth_attr_password_mutual,
901 /* End items for lio_target_tpg_auth_cit */
903 /* Start items for lio_target_tpg_param_cit */
905 #define DEF_TPG_PARAM(name) \
906 static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \
909 struct se_portal_group *se_tpg = param_to_tpg(item); \
910 struct iscsi_portal_group *tpg = container_of(se_tpg, \
911 struct iscsi_portal_group, tpg_se_tpg); \
912 struct iscsi_param *param; \
915 if (iscsit_get_tpg(tpg) < 0) \
918 param = iscsi_find_param_from_key(__stringify(name), \
921 iscsit_put_tpg(tpg); \
924 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
926 iscsit_put_tpg(tpg); \
929 static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
930 const char *page, size_t count) \
932 struct se_portal_group *se_tpg = param_to_tpg(item); \
933 struct iscsi_portal_group *tpg = container_of(se_tpg, \
934 struct iscsi_portal_group, tpg_se_tpg); \
938 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
941 len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
942 if (isspace(buf[len-1])) \
943 buf[len-1] = '\0'; /* Kill newline */ \
945 if (iscsit_get_tpg(tpg) < 0) { \
950 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
955 iscsit_put_tpg(tpg); \
959 iscsit_put_tpg(tpg); \
962 CONFIGFS_ATTR(iscsi_tpg_param_, name)
964 DEF_TPG_PARAM(AuthMethod);
965 DEF_TPG_PARAM(HeaderDigest);
966 DEF_TPG_PARAM(DataDigest);
967 DEF_TPG_PARAM(MaxConnections);
968 DEF_TPG_PARAM(TargetAlias);
969 DEF_TPG_PARAM(InitialR2T);
970 DEF_TPG_PARAM(ImmediateData);
971 DEF_TPG_PARAM(MaxRecvDataSegmentLength);
972 DEF_TPG_PARAM(MaxXmitDataSegmentLength);
973 DEF_TPG_PARAM(MaxBurstLength);
974 DEF_TPG_PARAM(FirstBurstLength);
975 DEF_TPG_PARAM(DefaultTime2Wait);
976 DEF_TPG_PARAM(DefaultTime2Retain);
977 DEF_TPG_PARAM(MaxOutstandingR2T);
978 DEF_TPG_PARAM(DataPDUInOrder);
979 DEF_TPG_PARAM(DataSequenceInOrder);
980 DEF_TPG_PARAM(ErrorRecoveryLevel);
981 DEF_TPG_PARAM(IFMarker);
982 DEF_TPG_PARAM(OFMarker);
983 DEF_TPG_PARAM(IFMarkInt);
984 DEF_TPG_PARAM(OFMarkInt);
986 static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
987 &iscsi_tpg_param_attr_AuthMethod,
988 &iscsi_tpg_param_attr_HeaderDigest,
989 &iscsi_tpg_param_attr_DataDigest,
990 &iscsi_tpg_param_attr_MaxConnections,
991 &iscsi_tpg_param_attr_TargetAlias,
992 &iscsi_tpg_param_attr_InitialR2T,
993 &iscsi_tpg_param_attr_ImmediateData,
994 &iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
995 &iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
996 &iscsi_tpg_param_attr_MaxBurstLength,
997 &iscsi_tpg_param_attr_FirstBurstLength,
998 &iscsi_tpg_param_attr_DefaultTime2Wait,
999 &iscsi_tpg_param_attr_DefaultTime2Retain,
1000 &iscsi_tpg_param_attr_MaxOutstandingR2T,
1001 &iscsi_tpg_param_attr_DataPDUInOrder,
1002 &iscsi_tpg_param_attr_DataSequenceInOrder,
1003 &iscsi_tpg_param_attr_ErrorRecoveryLevel,
1004 &iscsi_tpg_param_attr_IFMarker,
1005 &iscsi_tpg_param_attr_OFMarker,
1006 &iscsi_tpg_param_attr_IFMarkInt,
1007 &iscsi_tpg_param_attr_OFMarkInt,
1011 /* End items for lio_target_tpg_param_cit */
1013 /* Start items for lio_target_tpg_cit */
1015 static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page)
1017 struct se_portal_group *se_tpg = to_tpg(item);
1018 struct iscsi_portal_group *tpg = container_of(se_tpg,
1019 struct iscsi_portal_group, tpg_se_tpg);
1022 spin_lock(&tpg->tpg_state_lock);
1023 len = sprintf(page, "%d\n",
1024 (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1025 spin_unlock(&tpg->tpg_state_lock);
1030 static ssize_t lio_target_tpg_enable_store(struct config_item *item,
1031 const char *page, size_t count)
1033 struct se_portal_group *se_tpg = to_tpg(item);
1034 struct iscsi_portal_group *tpg = container_of(se_tpg,
1035 struct iscsi_portal_group, tpg_se_tpg);
1039 ret = kstrtou32(page, 0, &op);
1042 if ((op != 1) && (op != 0)) {
1043 pr_err("Illegal value for tpg_enable: %u\n", op);
1047 ret = iscsit_get_tpg(tpg);
1052 ret = iscsit_tpg_enable_portal_group(tpg);
1057 * iscsit_tpg_disable_portal_group() assumes force=1
1059 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1064 iscsit_put_tpg(tpg);
1067 iscsit_put_tpg(tpg);
1072 static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
1075 return target_show_dynamic_sessions(to_tpg(item), page);
1078 CONFIGFS_ATTR(lio_target_tpg_, enable);
1079 CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
1081 static struct configfs_attribute *lio_target_tpg_attrs[] = {
1082 &lio_target_tpg_attr_enable,
1083 &lio_target_tpg_attr_dynamic_sessions,
1087 /* End items for lio_target_tpg_cit */
1089 /* Start items for lio_target_tiqn_cit */
1091 static struct se_portal_group *lio_target_tiqn_addtpg(
1093 struct config_group *group,
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);
1140 static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1142 struct iscsi_portal_group *tpg;
1143 struct iscsi_tiqn *tiqn;
1145 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1146 tiqn = tpg->tpg_tiqn;
1148 * iscsit_tpg_del_portal_group() assumes force=1
1150 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1151 iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1154 /* End items for lio_target_tiqn_cit */
1156 /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1158 static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
1161 return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
1164 CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
1166 static struct configfs_attribute *lio_target_wwn_attrs[] = {
1167 &lio_target_wwn_attr_lio_version,
1171 static struct se_wwn *lio_target_call_coreaddtiqn(
1172 struct target_fabric_configfs *tf,
1173 struct config_group *group,
1176 struct iscsi_tiqn *tiqn;
1178 tiqn = iscsit_add_tiqn((unsigned char *)name);
1180 return ERR_CAST(tiqn);
1182 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1183 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1185 return &tiqn->tiqn_wwn;
1188 static void lio_target_add_wwn_groups(struct se_wwn *wwn)
1190 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1192 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1193 "iscsi_instance", &iscsi_stat_instance_cit);
1194 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1195 &tiqn->tiqn_wwn.fabric_stat_group);
1197 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1198 "iscsi_sess_err", &iscsi_stat_sess_err_cit);
1199 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1200 &tiqn->tiqn_wwn.fabric_stat_group);
1202 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1203 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1204 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1205 &tiqn->tiqn_wwn.fabric_stat_group);
1207 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1208 "iscsi_login_stats", &iscsi_stat_login_cit);
1209 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1210 &tiqn->tiqn_wwn.fabric_stat_group);
1212 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1213 "iscsi_logout_stats", &iscsi_stat_logout_cit);
1214 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1215 &tiqn->tiqn_wwn.fabric_stat_group);
1218 static void lio_target_call_coredeltiqn(
1221 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1223 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1225 iscsit_del_tiqn(tiqn);
1228 /* End LIO-Target TIQN struct contig_lio_target_cit */
1230 /* Start lio_target_discovery_auth_cit */
1232 #define DEF_DISC_AUTH_STR(name, flags) \
1233 __DEF_NACL_AUTH_STR(disc, name, flags) \
1234 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1236 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
1239 static ssize_t iscsi_disc_##name##_store(struct config_item *item, \
1240 const char *page, size_t count) \
1242 return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \
1246 CONFIGFS_ATTR(iscsi_disc_, name)
1248 DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1249 DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1250 DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1251 DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1253 #define DEF_DISC_AUTH_INT(name) \
1254 __DEF_NACL_AUTH_INT(disc, name) \
1255 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1257 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
1260 CONFIGFS_ATTR_RO(iscsi_disc_, name)
1262 DEF_DISC_AUTH_INT(authenticate_target);
1265 static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
1268 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1270 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1273 static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1274 const char *page, size_t count)
1276 struct iscsi_param *param;
1277 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
1281 err = kstrtou32(page, 0, &op);
1284 if ((op != 1) && (op != 0)) {
1285 pr_err("Illegal value for enforce_discovery_auth:"
1290 if (!discovery_tpg) {
1291 pr_err("iscsit_global->discovery_tpg is NULL\n");
1295 param = iscsi_find_param_from_key(AUTHMETHOD,
1296 discovery_tpg->param_list);
1302 * Reset the AuthMethod key to CHAP.
1304 if (iscsi_update_param_value(param, CHAP) < 0)
1307 discovery_tpg->tpg_attrib.authentication = 1;
1308 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1309 pr_debug("LIO-CORE[0] Successfully enabled"
1310 " authentication enforcement for iSCSI"
1311 " Discovery TPG\n");
1314 * Reset the AuthMethod key to CHAP,None
1316 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1319 discovery_tpg->tpg_attrib.authentication = 0;
1320 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1321 pr_debug("LIO-CORE[0] Successfully disabled"
1322 " authentication enforcement for iSCSI"
1323 " Discovery TPG\n");
1329 CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
1331 static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1332 &iscsi_disc_attr_userid,
1333 &iscsi_disc_attr_password,
1334 &iscsi_disc_attr_authenticate_target,
1335 &iscsi_disc_attr_userid_mutual,
1336 &iscsi_disc_attr_password_mutual,
1337 &iscsi_disc_attr_enforce_discovery_auth,
1341 /* End lio_target_discovery_auth_cit */
1343 /* Start functions for target_core_fabric_ops */
1345 static char *iscsi_get_fabric_name(void)
1350 static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1352 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1354 return cmd->i_state;
1357 static u32 lio_sess_get_index(struct se_session *se_sess)
1359 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1361 return sess->session_index;
1364 static u32 lio_sess_get_initiator_sid(
1365 struct se_session *se_sess,
1369 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1371 * iSCSI Initiator Session Identifier from RFC-3720.
1373 return snprintf(buf, size, "%6phN", sess->isid);
1376 static int lio_queue_data_in(struct se_cmd *se_cmd)
1378 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1379 struct iscsi_conn *conn = cmd->conn;
1381 cmd->i_state = ISTATE_SEND_DATAIN;
1382 return conn->conn_transport->iscsit_queue_data_in(conn, cmd);
1385 static int lio_write_pending(struct se_cmd *se_cmd)
1387 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1388 struct iscsi_conn *conn = cmd->conn;
1390 if (!cmd->immediate_data && !cmd->unsolicited_data)
1391 return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
1396 static int lio_write_pending_status(struct se_cmd *se_cmd)
1398 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1401 spin_lock_bh(&cmd->istate_lock);
1402 ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1403 spin_unlock_bh(&cmd->istate_lock);
1408 static int lio_queue_status(struct se_cmd *se_cmd)
1410 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1411 struct iscsi_conn *conn = cmd->conn;
1413 cmd->i_state = ISTATE_SEND_STATUS;
1415 if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
1416 return iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);
1418 return conn->conn_transport->iscsit_queue_status(conn, cmd);
1421 static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
1423 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1425 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1426 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1429 static void lio_aborted_task(struct se_cmd *se_cmd)
1431 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1433 cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1436 static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg)
1438 return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1441 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1443 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
1446 static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1448 return iscsi_tpg(se_tpg)->tpgt;
1451 static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1453 return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
1456 static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1458 return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
1461 static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1463 return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
1466 static int lio_tpg_check_demo_mode_write_protect(
1467 struct se_portal_group *se_tpg)
1469 return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
1472 static int lio_tpg_check_prod_mode_write_protect(
1473 struct se_portal_group *se_tpg)
1475 return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
1478 static int lio_tpg_check_prot_fabric_only(
1479 struct se_portal_group *se_tpg)
1482 * Only report fabric_prot_type if t10_pi has also been enabled
1483 * for incoming ib_isert sessions.
1485 if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
1487 return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
1491 * This function calls iscsit_inc_session_usage_count() on the
1492 * struct iscsi_session in question.
1494 static void lio_tpg_close_session(struct se_session *se_sess)
1496 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1497 struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
1499 spin_lock_bh(&se_tpg->session_lock);
1500 spin_lock(&sess->conn_lock);
1501 if (atomic_read(&sess->session_fall_back_to_erl0) ||
1502 atomic_read(&sess->session_logout) ||
1503 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1504 spin_unlock(&sess->conn_lock);
1505 spin_unlock_bh(&se_tpg->session_lock);
1508 atomic_set(&sess->session_reinstatement, 1);
1509 spin_unlock(&sess->conn_lock);
1511 iscsit_stop_time2retain_timer(sess);
1512 spin_unlock_bh(&se_tpg->session_lock);
1514 iscsit_stop_session(sess, 1, 1);
1515 iscsit_close_session(sess);
1518 static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1520 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
1523 static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1525 struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1527 struct se_portal_group *se_tpg = se_acl->se_tpg;
1528 struct iscsi_portal_group *tpg = container_of(se_tpg,
1529 struct iscsi_portal_group, tpg_se_tpg);
1531 acl->node_attrib.nacl = acl;
1532 iscsit_set_default_node_attribues(acl, tpg);
1535 static int lio_check_stop_free(struct se_cmd *se_cmd)
1537 return target_put_sess_cmd(se_cmd);
1540 static void lio_release_cmd(struct se_cmd *se_cmd)
1542 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1544 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
1545 iscsit_release_cmd(cmd);
1548 const struct target_core_fabric_ops iscsi_ops = {
1549 .module = THIS_MODULE,
1551 .node_acl_size = sizeof(struct iscsi_node_acl),
1552 .get_fabric_name = iscsi_get_fabric_name,
1553 .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
1554 .tpg_get_tag = lio_tpg_get_tag,
1555 .tpg_get_default_depth = lio_tpg_get_default_depth,
1556 .tpg_check_demo_mode = lio_tpg_check_demo_mode,
1557 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
1558 .tpg_check_demo_mode_write_protect =
1559 lio_tpg_check_demo_mode_write_protect,
1560 .tpg_check_prod_mode_write_protect =
1561 lio_tpg_check_prod_mode_write_protect,
1562 .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only,
1563 .tpg_get_inst_index = lio_tpg_get_inst_index,
1564 .check_stop_free = lio_check_stop_free,
1565 .release_cmd = lio_release_cmd,
1566 .close_session = lio_tpg_close_session,
1567 .sess_get_index = lio_sess_get_index,
1568 .sess_get_initiator_sid = lio_sess_get_initiator_sid,
1569 .write_pending = lio_write_pending,
1570 .write_pending_status = lio_write_pending_status,
1571 .set_default_node_attributes = lio_set_default_node_attributes,
1572 .get_cmd_state = iscsi_get_cmd_state,
1573 .queue_data_in = lio_queue_data_in,
1574 .queue_status = lio_queue_status,
1575 .queue_tm_rsp = lio_queue_tm_rsp,
1576 .aborted_task = lio_aborted_task,
1577 .fabric_make_wwn = lio_target_call_coreaddtiqn,
1578 .fabric_drop_wwn = lio_target_call_coredeltiqn,
1579 .add_wwn_groups = lio_target_add_wwn_groups,
1580 .fabric_make_tpg = lio_target_tiqn_addtpg,
1581 .fabric_drop_tpg = lio_target_tiqn_deltpg,
1582 .fabric_make_np = lio_target_call_addnptotpg,
1583 .fabric_drop_np = lio_target_call_delnpfromtpg,
1584 .fabric_init_nodeacl = lio_target_init_nodeacl,
1586 .tfc_discovery_attrs = lio_target_discovery_auth_attrs,
1587 .tfc_wwn_attrs = lio_target_wwn_attrs,
1588 .tfc_tpg_base_attrs = lio_target_tpg_attrs,
1589 .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs,
1590 .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs,
1591 .tfc_tpg_param_attrs = lio_target_tpg_param_attrs,
1592 .tfc_tpg_np_base_attrs = lio_target_portal_attrs,
1593 .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs,
1594 .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs,
1595 .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs,
1596 .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs,