1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*******************************************************************************
3 * This file contains the configfs implementation for iSCSI Target mode
4 * from the LIO-Target Project.
6 * (c) Copyright 2007-2013 Datera, Inc.
8 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
10 ****************************************************************************/
12 #include <linux/configfs.h>
13 #include <linux/ctype.h>
14 #include <linux/export.h>
15 #include <linux/inet.h>
16 #include <linux/module.h>
18 #include <target/target_core_base.h>
19 #include <target/target_core_fabric.h>
20 #include <target/iscsi/iscsi_transport.h>
21 #include <target/iscsi/iscsi_target_core.h>
22 #include "iscsi_target_parameters.h"
23 #include "iscsi_target_device.h"
24 #include "iscsi_target_erl0.h"
25 #include "iscsi_target_nodeattrib.h"
26 #include "iscsi_target_tpg.h"
27 #include "iscsi_target_util.h"
28 #include "iscsi_target.h"
29 #include <target/iscsi/iscsi_target_stat.h>
32 /* Start items for lio_target_portal_cit */
34 static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item)
36 return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np);
39 static ssize_t lio_target_np_driver_show(struct config_item *item, char *page,
40 enum iscsit_transport_type type)
42 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
43 struct iscsi_tpg_np *tpg_np_new;
46 tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
48 rb = sprintf(page, "1\n");
50 rb = sprintf(page, "0\n");
55 static ssize_t lio_target_np_driver_store(struct config_item *item,
56 const char *page, size_t count, enum iscsit_transport_type type,
59 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
61 struct iscsi_portal_group *tpg;
62 struct iscsi_tpg_np *tpg_np_new = NULL;
66 rc = kstrtou32(page, 0, &op);
69 if ((op != 1) && (op != 0)) {
70 pr_err("Illegal value for tpg_enable: %u\n", op);
75 pr_err("Unable to locate struct iscsi_np from"
76 " struct iscsi_tpg_np\n");
81 if (iscsit_get_tpg(tpg) < 0)
85 if (strlen(mod_name)) {
86 rc = request_module(mod_name);
88 pr_warn("Unable to request_module for %s\n",
94 tpg_np_new = iscsit_tpg_add_network_portal(tpg,
95 &np->np_sockaddr, tpg_np, type);
96 if (IS_ERR(tpg_np_new)) {
97 rc = PTR_ERR(tpg_np_new);
101 tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
103 rc = iscsit_tpg_del_network_portal(tpg, tpg_np_new);
116 static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
118 return lio_target_np_driver_show(item, page, ISCSI_INFINIBAND);
121 static ssize_t lio_target_np_iser_store(struct config_item *item,
122 const char *page, size_t count)
124 return lio_target_np_driver_store(item, page, count,
125 ISCSI_INFINIBAND, "ib_isert");
127 CONFIGFS_ATTR(lio_target_np_, iser);
129 static ssize_t lio_target_np_cxgbit_show(struct config_item *item, char *page)
131 return lio_target_np_driver_show(item, page, ISCSI_CXGBIT);
134 static ssize_t lio_target_np_cxgbit_store(struct config_item *item,
135 const char *page, size_t count)
137 return lio_target_np_driver_store(item, page, count,
138 ISCSI_CXGBIT, "cxgbit");
140 CONFIGFS_ATTR(lio_target_np_, cxgbit);
142 static struct configfs_attribute *lio_target_portal_attrs[] = {
143 &lio_target_np_attr_iser,
144 &lio_target_np_attr_cxgbit,
148 /* Stop items for lio_target_portal_cit */
150 /* Start items for lio_target_np_cit */
152 #define MAX_PORTAL_LEN 256
154 static struct se_tpg_np *lio_target_call_addnptotpg(
155 struct se_portal_group *se_tpg,
156 struct config_group *group,
159 struct iscsi_portal_group *tpg;
160 struct iscsi_tpg_np *tpg_np;
161 char *str, *str2, *ip_str, *port_str;
162 struct sockaddr_storage sockaddr = { };
164 char buf[MAX_PORTAL_LEN + 1];
166 if (strlen(name) > MAX_PORTAL_LEN) {
167 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
168 (int)strlen(name), MAX_PORTAL_LEN);
169 return ERR_PTR(-EOVERFLOW);
171 memset(buf, 0, MAX_PORTAL_LEN + 1);
172 snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
174 str = strstr(buf, "[");
176 str2 = strstr(str, "]");
178 pr_err("Unable to locate trailing \"]\""
179 " in IPv6 iSCSI network portal address\n");
180 return ERR_PTR(-EINVAL);
183 ip_str = str + 1; /* Skip over leading "[" */
184 *str2 = '\0'; /* Terminate the unbracketed IPv6 address */
185 str2++; /* Skip over the \0 */
187 port_str = strstr(str2, ":");
189 pr_err("Unable to locate \":port\""
190 " in IPv6 iSCSI network portal address\n");
191 return ERR_PTR(-EINVAL);
193 *port_str = '\0'; /* Terminate string for IP */
194 port_str++; /* Skip over ":" */
197 port_str = strstr(ip_str, ":");
199 pr_err("Unable to locate \":port\""
200 " in IPv4 iSCSI network portal address\n");
201 return ERR_PTR(-EINVAL);
203 *port_str = '\0'; /* Terminate string for IP */
204 port_str++; /* Skip over ":" */
207 ret = inet_pton_with_scope(&init_net, AF_UNSPEC, ip_str,
208 port_str, &sockaddr);
210 pr_err("malformed ip/port passed: %s\n", name);
214 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
215 ret = iscsit_get_tpg(tpg);
217 return ERR_PTR(-EINVAL);
219 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
221 config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
224 * Assume ISCSI_TCP by default. Other network portals for other
227 * Traditional iSCSI over SCTP (initial support)
228 * iSER/TCP (TODO, hardware available)
229 * iSER/SCTP (TODO, software emulation with osc-iwarp)
230 * iSER/IB (TODO, hardware available)
232 * can be enabled with attributes under
233 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
236 tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
238 if (IS_ERR(tpg_np)) {
240 return ERR_CAST(tpg_np);
242 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
245 return &tpg_np->se_tpg_np;
248 static void lio_target_call_delnpfromtpg(
249 struct se_tpg_np *se_tpg_np)
251 struct iscsi_portal_group *tpg;
252 struct iscsi_tpg_np *tpg_np;
253 struct se_portal_group *se_tpg;
256 tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
258 ret = iscsit_get_tpg(tpg);
262 se_tpg = &tpg->tpg_se_tpg;
263 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
264 " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
265 tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
267 ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
271 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
276 /* End items for lio_target_np_cit */
278 /* Start items for lio_target_nacl_attrib_cit */
280 #define ISCSI_NACL_ATTR(name) \
281 static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
284 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
285 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
288 return sprintf(page, "%u\n", nacl->node_attrib.name); \
291 static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
292 const char *page, size_t count) \
294 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
295 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
300 ret = kstrtou32(page, 0, &val); \
303 ret = iscsit_na_##name(nacl, val); \
310 CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
312 ISCSI_NACL_ATTR(dataout_timeout);
313 ISCSI_NACL_ATTR(dataout_timeout_retries);
314 ISCSI_NACL_ATTR(default_erl);
315 ISCSI_NACL_ATTR(nopin_timeout);
316 ISCSI_NACL_ATTR(nopin_response_timeout);
317 ISCSI_NACL_ATTR(random_datain_pdu_offsets);
318 ISCSI_NACL_ATTR(random_datain_seq_offsets);
319 ISCSI_NACL_ATTR(random_r2t_offsets);
321 static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
322 &iscsi_nacl_attrib_attr_dataout_timeout,
323 &iscsi_nacl_attrib_attr_dataout_timeout_retries,
324 &iscsi_nacl_attrib_attr_default_erl,
325 &iscsi_nacl_attrib_attr_nopin_timeout,
326 &iscsi_nacl_attrib_attr_nopin_response_timeout,
327 &iscsi_nacl_attrib_attr_random_datain_pdu_offsets,
328 &iscsi_nacl_attrib_attr_random_datain_seq_offsets,
329 &iscsi_nacl_attrib_attr_random_r2t_offsets,
333 /* End items for lio_target_nacl_attrib_cit */
335 /* Start items for lio_target_nacl_auth_cit */
337 #define __DEF_NACL_AUTH_STR(prefix, name, flags) \
338 static ssize_t __iscsi_##prefix##_##name##_show( \
339 struct iscsi_node_acl *nacl, \
342 struct iscsi_node_auth *auth = &nacl->node_auth; \
344 if (!capable(CAP_SYS_ADMIN)) \
346 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
349 static ssize_t __iscsi_##prefix##_##name##_store( \
350 struct iscsi_node_acl *nacl, \
354 struct iscsi_node_auth *auth = &nacl->node_auth; \
356 if (!capable(CAP_SYS_ADMIN)) \
358 if (count >= sizeof(auth->name)) \
360 snprintf(auth->name, sizeof(auth->name), "%s", page); \
361 if (!strncmp("NULL", auth->name, 4)) \
362 auth->naf_flags &= ~flags; \
364 auth->naf_flags |= flags; \
366 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
367 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
368 auth->authenticate_target = 1; \
370 auth->authenticate_target = 0; \
375 #define DEF_NACL_AUTH_STR(name, flags) \
376 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
377 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
380 struct se_node_acl *nacl = auth_to_nacl(item); \
381 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
382 struct iscsi_node_acl, se_node_acl), page); \
384 static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \
385 const char *page, size_t count) \
387 struct se_node_acl *nacl = auth_to_nacl(item); \
388 return __iscsi_nacl_auth_##name##_store(container_of(nacl, \
389 struct iscsi_node_acl, se_node_acl), page, count); \
392 CONFIGFS_ATTR(iscsi_nacl_auth_, name)
395 * One-way authentication userid
397 DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
398 DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
399 DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
400 DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
402 #define __DEF_NACL_AUTH_INT(prefix, name) \
403 static ssize_t __iscsi_##prefix##_##name##_show( \
404 struct iscsi_node_acl *nacl, \
407 struct iscsi_node_auth *auth = &nacl->node_auth; \
409 if (!capable(CAP_SYS_ADMIN)) \
412 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
415 #define DEF_NACL_AUTH_INT(name) \
416 __DEF_NACL_AUTH_INT(nacl_auth, name) \
417 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
420 struct se_node_acl *nacl = auth_to_nacl(item); \
421 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
422 struct iscsi_node_acl, se_node_acl), page); \
425 CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
427 DEF_NACL_AUTH_INT(authenticate_target);
429 static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
430 &iscsi_nacl_auth_attr_userid,
431 &iscsi_nacl_auth_attr_password,
432 &iscsi_nacl_auth_attr_authenticate_target,
433 &iscsi_nacl_auth_attr_userid_mutual,
434 &iscsi_nacl_auth_attr_password_mutual,
438 /* End items for lio_target_nacl_auth_cit */
440 /* Start items for lio_target_nacl_param_cit */
442 #define ISCSI_NACL_PARAM(name) \
443 static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \
446 struct se_node_acl *se_nacl = param_to_nacl(item); \
447 struct iscsi_session *sess; \
448 struct se_session *se_sess; \
451 spin_lock_bh(&se_nacl->nacl_sess_lock); \
452 se_sess = se_nacl->nacl_sess; \
454 rb = snprintf(page, PAGE_SIZE, \
455 "No Active iSCSI Session\n"); \
457 sess = se_sess->fabric_sess_ptr; \
458 rb = snprintf(page, PAGE_SIZE, "%u\n", \
459 (u32)sess->sess_ops->name); \
461 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
466 CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
468 ISCSI_NACL_PARAM(MaxConnections);
469 ISCSI_NACL_PARAM(InitialR2T);
470 ISCSI_NACL_PARAM(ImmediateData);
471 ISCSI_NACL_PARAM(MaxBurstLength);
472 ISCSI_NACL_PARAM(FirstBurstLength);
473 ISCSI_NACL_PARAM(DefaultTime2Wait);
474 ISCSI_NACL_PARAM(DefaultTime2Retain);
475 ISCSI_NACL_PARAM(MaxOutstandingR2T);
476 ISCSI_NACL_PARAM(DataPDUInOrder);
477 ISCSI_NACL_PARAM(DataSequenceInOrder);
478 ISCSI_NACL_PARAM(ErrorRecoveryLevel);
480 static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
481 &iscsi_nacl_param_attr_MaxConnections,
482 &iscsi_nacl_param_attr_InitialR2T,
483 &iscsi_nacl_param_attr_ImmediateData,
484 &iscsi_nacl_param_attr_MaxBurstLength,
485 &iscsi_nacl_param_attr_FirstBurstLength,
486 &iscsi_nacl_param_attr_DefaultTime2Wait,
487 &iscsi_nacl_param_attr_DefaultTime2Retain,
488 &iscsi_nacl_param_attr_MaxOutstandingR2T,
489 &iscsi_nacl_param_attr_DataPDUInOrder,
490 &iscsi_nacl_param_attr_DataSequenceInOrder,
491 &iscsi_nacl_param_attr_ErrorRecoveryLevel,
495 /* End items for lio_target_nacl_param_cit */
497 /* Start items for lio_target_acl_cit */
499 static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
501 struct se_node_acl *se_nacl = acl_to_nacl(item);
502 struct iscsi_session *sess;
503 struct iscsi_conn *conn;
504 struct se_session *se_sess;
508 spin_lock_bh(&se_nacl->nacl_sess_lock);
509 se_sess = se_nacl->nacl_sess;
511 rb += sysfs_emit_at(page, rb, "No active iSCSI Session for Initiator"
512 " Endpoint: %s\n", se_nacl->initiatorname);
514 sess = se_sess->fabric_sess_ptr;
516 rb += sysfs_emit_at(page, rb, "InitiatorName: %s\n",
517 sess->sess_ops->InitiatorName);
518 rb += sysfs_emit_at(page, rb, "InitiatorAlias: %s\n",
519 sess->sess_ops->InitiatorAlias);
521 rb += sysfs_emit_at(page, rb,
522 "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ",
523 sess->sid, sess->isid, sess->tsih);
524 rb += sysfs_emit_at(page, rb, "SessionType: %s\n",
525 (sess->sess_ops->SessionType) ?
526 "Discovery" : "Normal");
527 rb += sysfs_emit_at(page, rb, "Session State: ");
528 switch (sess->session_state) {
529 case TARG_SESS_STATE_FREE:
530 rb += sysfs_emit_at(page, rb, "TARG_SESS_FREE\n");
532 case TARG_SESS_STATE_ACTIVE:
533 rb += sysfs_emit_at(page, rb, "TARG_SESS_STATE_ACTIVE\n");
535 case TARG_SESS_STATE_LOGGED_IN:
536 rb += sysfs_emit_at(page, rb, "TARG_SESS_STATE_LOGGED_IN\n");
538 case TARG_SESS_STATE_FAILED:
539 rb += sysfs_emit_at(page, rb, "TARG_SESS_STATE_FAILED\n");
541 case TARG_SESS_STATE_IN_CONTINUE:
542 rb += sysfs_emit_at(page, rb, "TARG_SESS_STATE_IN_CONTINUE\n");
545 rb += sysfs_emit_at(page, rb, "ERROR: Unknown Session"
550 rb += sysfs_emit_at(page, rb, "---------------------[iSCSI Session"
551 " Values]-----------------------\n");
552 rb += sysfs_emit_at(page, rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
553 " : MaxCmdSN : ITT : TTT\n");
554 max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
555 rb += sysfs_emit_at(page, rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
558 (max_cmd_sn - sess->exp_cmd_sn) + 1,
559 sess->exp_cmd_sn, max_cmd_sn,
560 sess->init_task_tag, sess->targ_xfer_tag);
561 rb += sysfs_emit_at(page, rb, "----------------------[iSCSI"
562 " Connections]-------------------------\n");
564 spin_lock(&sess->conn_lock);
565 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
566 rb += sysfs_emit_at(page, rb, "CID: %hu Connection"
567 " State: ", conn->cid);
568 switch (conn->conn_state) {
569 case TARG_CONN_STATE_FREE:
570 rb += sysfs_emit_at(page, rb,
571 "TARG_CONN_STATE_FREE\n");
573 case TARG_CONN_STATE_XPT_UP:
574 rb += sysfs_emit_at(page, rb,
575 "TARG_CONN_STATE_XPT_UP\n");
577 case TARG_CONN_STATE_IN_LOGIN:
578 rb += sysfs_emit_at(page, rb,
579 "TARG_CONN_STATE_IN_LOGIN\n");
581 case TARG_CONN_STATE_LOGGED_IN:
582 rb += sysfs_emit_at(page, rb,
583 "TARG_CONN_STATE_LOGGED_IN\n");
585 case TARG_CONN_STATE_IN_LOGOUT:
586 rb += sysfs_emit_at(page, rb,
587 "TARG_CONN_STATE_IN_LOGOUT\n");
589 case TARG_CONN_STATE_LOGOUT_REQUESTED:
590 rb += sysfs_emit_at(page, rb,
591 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
593 case TARG_CONN_STATE_CLEANUP_WAIT:
594 rb += sysfs_emit_at(page, rb,
595 "TARG_CONN_STATE_CLEANUP_WAIT\n");
598 rb += sysfs_emit_at(page, rb,
599 "ERROR: Unknown Connection State!\n");
603 rb += sysfs_emit_at(page, rb, " Address %pISc %s", &conn->login_sockaddr,
604 (conn->network_transport == ISCSI_TCP) ?
606 rb += sysfs_emit_at(page, rb, " StatSN: 0x%08x\n",
609 spin_unlock(&sess->conn_lock);
611 spin_unlock_bh(&se_nacl->nacl_sess_lock);
616 static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
619 return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth);
622 static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
623 const char *page, size_t count)
625 struct se_node_acl *se_nacl = acl_to_nacl(item);
626 struct se_portal_group *se_tpg = se_nacl->se_tpg;
627 struct iscsi_portal_group *tpg = container_of(se_tpg,
628 struct iscsi_portal_group, tpg_se_tpg);
629 struct config_item *acl_ci, *tpg_ci, *wwn_ci;
633 ret = kstrtou32(page, 0, &cmdsn_depth);
636 if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
637 pr_err("Passed cmdsn_depth: %u exceeds"
638 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
639 TA_DEFAULT_CMDSN_DEPTH_MAX);
642 acl_ci = &se_nacl->acl_group.cg_item;
644 pr_err("Unable to locatel acl_ci\n");
647 tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
649 pr_err("Unable to locate tpg_ci\n");
652 wwn_ci = &tpg_ci->ci_group->cg_item;
654 pr_err("Unable to locate config_item wwn_ci\n");
658 if (iscsit_get_tpg(tpg) < 0)
661 ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth);
663 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
664 "InitiatorName: %s\n", config_item_name(wwn_ci),
665 config_item_name(tpg_ci), cmdsn_depth,
666 config_item_name(acl_ci));
669 return (!ret) ? count : (ssize_t)ret;
672 static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
674 return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
677 static ssize_t lio_target_nacl_tag_store(struct config_item *item,
678 const char *page, size_t count)
680 struct se_node_acl *se_nacl = acl_to_nacl(item);
683 ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
690 CONFIGFS_ATTR_RO(lio_target_nacl_, info);
691 CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
692 CONFIGFS_ATTR(lio_target_nacl_, tag);
694 static struct configfs_attribute *lio_target_initiator_attrs[] = {
695 &lio_target_nacl_attr_info,
696 &lio_target_nacl_attr_cmdsn_depth,
697 &lio_target_nacl_attr_tag,
701 static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
704 struct iscsi_node_acl *acl =
705 container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
707 config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
708 "iscsi_sess_stats", &iscsi_stat_sess_cit);
709 configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group,
710 &se_nacl->acl_fabric_stat_group);
714 /* End items for lio_target_acl_cit */
716 /* Start items for lio_target_tpg_attrib_cit */
718 #define DEF_TPG_ATTRIB(name) \
720 static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \
723 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
724 struct iscsi_portal_group *tpg = container_of(se_tpg, \
725 struct iscsi_portal_group, tpg_se_tpg); \
728 if (iscsit_get_tpg(tpg) < 0) \
731 rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \
732 iscsit_put_tpg(tpg); \
736 static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
737 const char *page, size_t count) \
739 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
740 struct iscsi_portal_group *tpg = container_of(se_tpg, \
741 struct iscsi_portal_group, tpg_se_tpg); \
745 if (iscsit_get_tpg(tpg) < 0) \
748 ret = kstrtou32(page, 0, &val); \
751 ret = iscsit_ta_##name(tpg, val); \
755 iscsit_put_tpg(tpg); \
758 iscsit_put_tpg(tpg); \
761 CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
763 DEF_TPG_ATTRIB(authentication);
764 DEF_TPG_ATTRIB(login_timeout);
765 DEF_TPG_ATTRIB(netif_timeout);
766 DEF_TPG_ATTRIB(generate_node_acls);
767 DEF_TPG_ATTRIB(default_cmdsn_depth);
768 DEF_TPG_ATTRIB(cache_dynamic_acls);
769 DEF_TPG_ATTRIB(demo_mode_write_protect);
770 DEF_TPG_ATTRIB(prod_mode_write_protect);
771 DEF_TPG_ATTRIB(demo_mode_discovery);
772 DEF_TPG_ATTRIB(default_erl);
773 DEF_TPG_ATTRIB(t10_pi);
774 DEF_TPG_ATTRIB(fabric_prot_type);
775 DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
776 DEF_TPG_ATTRIB(login_keys_workaround);
778 static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
779 &iscsi_tpg_attrib_attr_authentication,
780 &iscsi_tpg_attrib_attr_login_timeout,
781 &iscsi_tpg_attrib_attr_netif_timeout,
782 &iscsi_tpg_attrib_attr_generate_node_acls,
783 &iscsi_tpg_attrib_attr_default_cmdsn_depth,
784 &iscsi_tpg_attrib_attr_cache_dynamic_acls,
785 &iscsi_tpg_attrib_attr_demo_mode_write_protect,
786 &iscsi_tpg_attrib_attr_prod_mode_write_protect,
787 &iscsi_tpg_attrib_attr_demo_mode_discovery,
788 &iscsi_tpg_attrib_attr_default_erl,
789 &iscsi_tpg_attrib_attr_t10_pi,
790 &iscsi_tpg_attrib_attr_fabric_prot_type,
791 &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
792 &iscsi_tpg_attrib_attr_login_keys_workaround,
796 /* End items for lio_target_tpg_attrib_cit */
798 /* Start items for lio_target_tpg_auth_cit */
800 #define __DEF_TPG_AUTH_STR(prefix, name, flags) \
801 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
804 struct iscsi_portal_group *tpg = container_of(se_tpg, \
805 struct iscsi_portal_group, tpg_se_tpg); \
806 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
808 if (!capable(CAP_SYS_ADMIN)) \
811 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
814 static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
815 const char *page, size_t count) \
817 struct iscsi_portal_group *tpg = container_of(se_tpg, \
818 struct iscsi_portal_group, tpg_se_tpg); \
819 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
821 if (!capable(CAP_SYS_ADMIN)) \
824 snprintf(auth->name, sizeof(auth->name), "%s", page); \
825 if (!(strncmp("NULL", auth->name, 4))) \
826 auth->naf_flags &= ~flags; \
828 auth->naf_flags |= flags; \
830 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
831 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
832 auth->authenticate_target = 1; \
834 auth->authenticate_target = 0; \
839 #define DEF_TPG_AUTH_STR(name, flags) \
840 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
841 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
844 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
847 static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \
848 const char *page, size_t count) \
850 return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
853 CONFIGFS_ATTR(iscsi_tpg_auth_, name);
856 DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
857 DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
858 DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
859 DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
861 #define __DEF_TPG_AUTH_INT(prefix, name) \
862 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
865 struct iscsi_portal_group *tpg = container_of(se_tpg, \
866 struct iscsi_portal_group, tpg_se_tpg); \
867 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
869 if (!capable(CAP_SYS_ADMIN)) \
872 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
875 #define DEF_TPG_AUTH_INT(name) \
876 __DEF_TPG_AUTH_INT(tpg_auth, name) \
877 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
880 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
882 CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
884 DEF_TPG_AUTH_INT(authenticate_target);
886 static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
887 &iscsi_tpg_auth_attr_userid,
888 &iscsi_tpg_auth_attr_password,
889 &iscsi_tpg_auth_attr_authenticate_target,
890 &iscsi_tpg_auth_attr_userid_mutual,
891 &iscsi_tpg_auth_attr_password_mutual,
895 /* End items for lio_target_tpg_auth_cit */
897 /* Start items for lio_target_tpg_param_cit */
899 #define DEF_TPG_PARAM(name) \
900 static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \
903 struct se_portal_group *se_tpg = param_to_tpg(item); \
904 struct iscsi_portal_group *tpg = container_of(se_tpg, \
905 struct iscsi_portal_group, tpg_se_tpg); \
906 struct iscsi_param *param; \
909 if (iscsit_get_tpg(tpg) < 0) \
912 param = iscsi_find_param_from_key(__stringify(name), \
915 iscsit_put_tpg(tpg); \
918 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
920 iscsit_put_tpg(tpg); \
923 static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
924 const char *page, size_t count) \
926 struct se_portal_group *se_tpg = param_to_tpg(item); \
927 struct iscsi_portal_group *tpg = container_of(se_tpg, \
928 struct iscsi_portal_group, tpg_se_tpg); \
932 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
935 len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
936 if (isspace(buf[len-1])) \
937 buf[len-1] = '\0'; /* Kill newline */ \
939 if (iscsit_get_tpg(tpg) < 0) { \
944 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
949 iscsit_put_tpg(tpg); \
953 iscsit_put_tpg(tpg); \
956 CONFIGFS_ATTR(iscsi_tpg_param_, name)
958 DEF_TPG_PARAM(AuthMethod);
959 DEF_TPG_PARAM(HeaderDigest);
960 DEF_TPG_PARAM(DataDigest);
961 DEF_TPG_PARAM(MaxConnections);
962 DEF_TPG_PARAM(TargetAlias);
963 DEF_TPG_PARAM(InitialR2T);
964 DEF_TPG_PARAM(ImmediateData);
965 DEF_TPG_PARAM(MaxRecvDataSegmentLength);
966 DEF_TPG_PARAM(MaxXmitDataSegmentLength);
967 DEF_TPG_PARAM(MaxBurstLength);
968 DEF_TPG_PARAM(FirstBurstLength);
969 DEF_TPG_PARAM(DefaultTime2Wait);
970 DEF_TPG_PARAM(DefaultTime2Retain);
971 DEF_TPG_PARAM(MaxOutstandingR2T);
972 DEF_TPG_PARAM(DataPDUInOrder);
973 DEF_TPG_PARAM(DataSequenceInOrder);
974 DEF_TPG_PARAM(ErrorRecoveryLevel);
975 DEF_TPG_PARAM(IFMarker);
976 DEF_TPG_PARAM(OFMarker);
977 DEF_TPG_PARAM(IFMarkInt);
978 DEF_TPG_PARAM(OFMarkInt);
980 static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
981 &iscsi_tpg_param_attr_AuthMethod,
982 &iscsi_tpg_param_attr_HeaderDigest,
983 &iscsi_tpg_param_attr_DataDigest,
984 &iscsi_tpg_param_attr_MaxConnections,
985 &iscsi_tpg_param_attr_TargetAlias,
986 &iscsi_tpg_param_attr_InitialR2T,
987 &iscsi_tpg_param_attr_ImmediateData,
988 &iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
989 &iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
990 &iscsi_tpg_param_attr_MaxBurstLength,
991 &iscsi_tpg_param_attr_FirstBurstLength,
992 &iscsi_tpg_param_attr_DefaultTime2Wait,
993 &iscsi_tpg_param_attr_DefaultTime2Retain,
994 &iscsi_tpg_param_attr_MaxOutstandingR2T,
995 &iscsi_tpg_param_attr_DataPDUInOrder,
996 &iscsi_tpg_param_attr_DataSequenceInOrder,
997 &iscsi_tpg_param_attr_ErrorRecoveryLevel,
998 &iscsi_tpg_param_attr_IFMarker,
999 &iscsi_tpg_param_attr_OFMarker,
1000 &iscsi_tpg_param_attr_IFMarkInt,
1001 &iscsi_tpg_param_attr_OFMarkInt,
1005 /* End items for lio_target_tpg_param_cit */
1007 /* Start items for lio_target_tpg_cit */
1009 static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page)
1011 struct se_portal_group *se_tpg = to_tpg(item);
1012 struct iscsi_portal_group *tpg = container_of(se_tpg,
1013 struct iscsi_portal_group, tpg_se_tpg);
1016 spin_lock(&tpg->tpg_state_lock);
1017 len = sprintf(page, "%d\n",
1018 (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1019 spin_unlock(&tpg->tpg_state_lock);
1024 static ssize_t lio_target_tpg_enable_store(struct config_item *item,
1025 const char *page, size_t count)
1027 struct se_portal_group *se_tpg = to_tpg(item);
1028 struct iscsi_portal_group *tpg = container_of(se_tpg,
1029 struct iscsi_portal_group, tpg_se_tpg);
1033 ret = kstrtou32(page, 0, &op);
1036 if ((op != 1) && (op != 0)) {
1037 pr_err("Illegal value for tpg_enable: %u\n", op);
1041 ret = iscsit_get_tpg(tpg);
1046 ret = iscsit_tpg_enable_portal_group(tpg);
1051 * iscsit_tpg_disable_portal_group() assumes force=1
1053 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1058 iscsit_put_tpg(tpg);
1061 iscsit_put_tpg(tpg);
1066 static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
1069 return target_show_dynamic_sessions(to_tpg(item), page);
1072 CONFIGFS_ATTR(lio_target_tpg_, enable);
1073 CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
1075 static struct configfs_attribute *lio_target_tpg_attrs[] = {
1076 &lio_target_tpg_attr_enable,
1077 &lio_target_tpg_attr_dynamic_sessions,
1081 /* End items for lio_target_tpg_cit */
1083 /* Start items for lio_target_tiqn_cit */
1085 static struct se_portal_group *lio_target_tiqn_addtpg(struct se_wwn *wwn,
1088 struct iscsi_portal_group *tpg;
1089 struct iscsi_tiqn *tiqn;
1094 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1096 * Only tpgt_# directory groups can be created below
1097 * target/iscsi/iqn.superturodiskarry/
1099 tpgt_str = strstr(name, "tpgt_");
1101 pr_err("Unable to locate \"tpgt_#\" directory"
1105 tpgt_str += 5; /* Skip ahead of "tpgt_" */
1106 ret = kstrtou16(tpgt_str, 0, &tpgt);
1110 tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1114 ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
1118 ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1122 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1123 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1125 return &tpg->tpg_se_tpg;
1127 core_tpg_deregister(&tpg->tpg_se_tpg);
1133 static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1135 struct iscsi_portal_group *tpg;
1136 struct iscsi_tiqn *tiqn;
1138 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1139 tiqn = tpg->tpg_tiqn;
1141 * iscsit_tpg_del_portal_group() assumes force=1
1143 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1144 iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1147 /* End items for lio_target_tiqn_cit */
1149 /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1151 static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
1154 return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
1157 CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
1159 static struct configfs_attribute *lio_target_wwn_attrs[] = {
1160 &lio_target_wwn_attr_lio_version,
1164 static struct se_wwn *lio_target_call_coreaddtiqn(
1165 struct target_fabric_configfs *tf,
1166 struct config_group *group,
1169 struct iscsi_tiqn *tiqn;
1171 tiqn = iscsit_add_tiqn((unsigned char *)name);
1173 return ERR_CAST(tiqn);
1175 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1176 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1178 return &tiqn->tiqn_wwn;
1181 static void lio_target_add_wwn_groups(struct se_wwn *wwn)
1183 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1185 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1186 "iscsi_instance", &iscsi_stat_instance_cit);
1187 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1188 &tiqn->tiqn_wwn.fabric_stat_group);
1190 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1191 "iscsi_sess_err", &iscsi_stat_sess_err_cit);
1192 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1193 &tiqn->tiqn_wwn.fabric_stat_group);
1195 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1196 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1197 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1198 &tiqn->tiqn_wwn.fabric_stat_group);
1200 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1201 "iscsi_login_stats", &iscsi_stat_login_cit);
1202 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1203 &tiqn->tiqn_wwn.fabric_stat_group);
1205 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1206 "iscsi_logout_stats", &iscsi_stat_logout_cit);
1207 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1208 &tiqn->tiqn_wwn.fabric_stat_group);
1211 static void lio_target_call_coredeltiqn(
1214 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1216 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1218 iscsit_del_tiqn(tiqn);
1221 /* End LIO-Target TIQN struct contig_lio_target_cit */
1223 /* Start lio_target_discovery_auth_cit */
1225 #define DEF_DISC_AUTH_STR(name, flags) \
1226 __DEF_NACL_AUTH_STR(disc, name, flags) \
1227 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1229 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
1232 static ssize_t iscsi_disc_##name##_store(struct config_item *item, \
1233 const char *page, size_t count) \
1235 return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \
1239 CONFIGFS_ATTR(iscsi_disc_, name)
1241 DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1242 DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1243 DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1244 DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1246 #define DEF_DISC_AUTH_INT(name) \
1247 __DEF_NACL_AUTH_INT(disc, name) \
1248 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1250 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
1253 CONFIGFS_ATTR_RO(iscsi_disc_, name)
1255 DEF_DISC_AUTH_INT(authenticate_target);
1258 static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
1261 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1263 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1266 static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1267 const char *page, size_t count)
1269 struct iscsi_param *param;
1270 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
1274 err = kstrtou32(page, 0, &op);
1277 if ((op != 1) && (op != 0)) {
1278 pr_err("Illegal value for enforce_discovery_auth:"
1283 if (!discovery_tpg) {
1284 pr_err("iscsit_global->discovery_tpg is NULL\n");
1288 param = iscsi_find_param_from_key(AUTHMETHOD,
1289 discovery_tpg->param_list);
1295 * Reset the AuthMethod key to CHAP.
1297 if (iscsi_update_param_value(param, CHAP) < 0)
1300 discovery_tpg->tpg_attrib.authentication = 1;
1301 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1302 pr_debug("LIO-CORE[0] Successfully enabled"
1303 " authentication enforcement for iSCSI"
1304 " Discovery TPG\n");
1307 * Reset the AuthMethod key to CHAP,None
1309 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1312 discovery_tpg->tpg_attrib.authentication = 0;
1313 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1314 pr_debug("LIO-CORE[0] Successfully disabled"
1315 " authentication enforcement for iSCSI"
1316 " Discovery TPG\n");
1322 CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
1324 static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1325 &iscsi_disc_attr_userid,
1326 &iscsi_disc_attr_password,
1327 &iscsi_disc_attr_authenticate_target,
1328 &iscsi_disc_attr_userid_mutual,
1329 &iscsi_disc_attr_password_mutual,
1330 &iscsi_disc_attr_enforce_discovery_auth,
1334 /* End lio_target_discovery_auth_cit */
1336 /* Start functions for target_core_fabric_ops */
1338 static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1340 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1342 return cmd->i_state;
1345 static u32 lio_sess_get_index(struct se_session *se_sess)
1347 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1349 return sess->session_index;
1352 static u32 lio_sess_get_initiator_sid(
1353 struct se_session *se_sess,
1357 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1359 * iSCSI Initiator Session Identifier from RFC-3720.
1361 return snprintf(buf, size, "%6phN", sess->isid);
1364 static int lio_queue_data_in(struct se_cmd *se_cmd)
1366 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1367 struct iscsi_conn *conn = cmd->conn;
1369 cmd->i_state = ISTATE_SEND_DATAIN;
1370 return conn->conn_transport->iscsit_queue_data_in(conn, cmd);
1373 static int lio_write_pending(struct se_cmd *se_cmd)
1375 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1376 struct iscsi_conn *conn = cmd->conn;
1378 if (!cmd->immediate_data && !cmd->unsolicited_data)
1379 return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
1384 static int lio_queue_status(struct se_cmd *se_cmd)
1386 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1387 struct iscsi_conn *conn = cmd->conn;
1389 cmd->i_state = ISTATE_SEND_STATUS;
1391 if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
1392 return iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state);
1394 return conn->conn_transport->iscsit_queue_status(conn, cmd);
1397 static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
1399 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1401 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1402 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1405 static void lio_aborted_task(struct se_cmd *se_cmd)
1407 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1409 cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1412 static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg)
1414 return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1417 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1419 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
1422 static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1424 return iscsi_tpg(se_tpg)->tpgt;
1427 static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1429 return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
1432 static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1434 return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
1437 static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1439 return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
1442 static int lio_tpg_check_demo_mode_write_protect(
1443 struct se_portal_group *se_tpg)
1445 return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
1448 static int lio_tpg_check_prod_mode_write_protect(
1449 struct se_portal_group *se_tpg)
1451 return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
1454 static int lio_tpg_check_prot_fabric_only(
1455 struct se_portal_group *se_tpg)
1458 * Only report fabric_prot_type if t10_pi has also been enabled
1459 * for incoming ib_isert sessions.
1461 if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
1463 return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
1467 * This function calls iscsit_inc_session_usage_count() on the
1468 * struct iscsi_session in question.
1470 static void lio_tpg_close_session(struct se_session *se_sess)
1472 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1473 struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
1475 spin_lock_bh(&se_tpg->session_lock);
1476 spin_lock(&sess->conn_lock);
1477 if (atomic_read(&sess->session_fall_back_to_erl0) ||
1478 atomic_read(&sess->session_logout) ||
1479 atomic_read(&sess->session_close) ||
1480 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1481 spin_unlock(&sess->conn_lock);
1482 spin_unlock_bh(&se_tpg->session_lock);
1485 iscsit_inc_session_usage_count(sess);
1486 atomic_set(&sess->session_reinstatement, 1);
1487 atomic_set(&sess->session_fall_back_to_erl0, 1);
1488 atomic_set(&sess->session_close, 1);
1489 spin_unlock(&sess->conn_lock);
1491 iscsit_stop_time2retain_timer(sess);
1492 spin_unlock_bh(&se_tpg->session_lock);
1494 iscsit_stop_session(sess, 1, 1);
1495 iscsit_dec_session_usage_count(sess);
1498 static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1500 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
1503 static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1505 struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1507 struct se_portal_group *se_tpg = se_acl->se_tpg;
1508 struct iscsi_portal_group *tpg = container_of(se_tpg,
1509 struct iscsi_portal_group, tpg_se_tpg);
1511 acl->node_attrib.nacl = acl;
1512 iscsit_set_default_node_attribues(acl, tpg);
1515 static int lio_check_stop_free(struct se_cmd *se_cmd)
1517 return target_put_sess_cmd(se_cmd);
1520 static void lio_release_cmd(struct se_cmd *se_cmd)
1522 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1524 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
1525 iscsit_release_cmd(cmd);
1528 const struct target_core_fabric_ops iscsi_ops = {
1529 .module = THIS_MODULE,
1530 .fabric_alias = "iscsi",
1531 .fabric_name = "iSCSI",
1532 .node_acl_size = sizeof(struct iscsi_node_acl),
1533 .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
1534 .tpg_get_tag = lio_tpg_get_tag,
1535 .tpg_get_default_depth = lio_tpg_get_default_depth,
1536 .tpg_check_demo_mode = lio_tpg_check_demo_mode,
1537 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
1538 .tpg_check_demo_mode_write_protect =
1539 lio_tpg_check_demo_mode_write_protect,
1540 .tpg_check_prod_mode_write_protect =
1541 lio_tpg_check_prod_mode_write_protect,
1542 .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only,
1543 .tpg_get_inst_index = lio_tpg_get_inst_index,
1544 .check_stop_free = lio_check_stop_free,
1545 .release_cmd = lio_release_cmd,
1546 .close_session = lio_tpg_close_session,
1547 .sess_get_index = lio_sess_get_index,
1548 .sess_get_initiator_sid = lio_sess_get_initiator_sid,
1549 .write_pending = lio_write_pending,
1550 .set_default_node_attributes = lio_set_default_node_attributes,
1551 .get_cmd_state = iscsi_get_cmd_state,
1552 .queue_data_in = lio_queue_data_in,
1553 .queue_status = lio_queue_status,
1554 .queue_tm_rsp = lio_queue_tm_rsp,
1555 .aborted_task = lio_aborted_task,
1556 .fabric_make_wwn = lio_target_call_coreaddtiqn,
1557 .fabric_drop_wwn = lio_target_call_coredeltiqn,
1558 .add_wwn_groups = lio_target_add_wwn_groups,
1559 .fabric_make_tpg = lio_target_tiqn_addtpg,
1560 .fabric_drop_tpg = lio_target_tiqn_deltpg,
1561 .fabric_make_np = lio_target_call_addnptotpg,
1562 .fabric_drop_np = lio_target_call_delnpfromtpg,
1563 .fabric_init_nodeacl = lio_target_init_nodeacl,
1565 .tfc_discovery_attrs = lio_target_discovery_auth_attrs,
1566 .tfc_wwn_attrs = lio_target_wwn_attrs,
1567 .tfc_tpg_base_attrs = lio_target_tpg_attrs,
1568 .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs,
1569 .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs,
1570 .tfc_tpg_param_attrs = lio_target_tpg_param_attrs,
1571 .tfc_tpg_np_base_attrs = lio_target_portal_attrs,
1572 .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs,
1573 .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs,
1574 .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs,
1575 .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs,
1577 .write_pending_must_be_called = true,