1 /*******************************************************************************
2 * This file contains the configfs implementation for iSCSI Target mode
3 * from the LIO-Target Project.
5 * (c) Copyright 2007-2013 Datera, Inc.
7 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 ****************************************************************************/
20 #include <linux/configfs.h>
21 #include <linux/ctype.h>
22 #include <linux/export.h>
23 #include <linux/inet.h>
24 #include <target/target_core_base.h>
25 #include <target/target_core_fabric.h>
26 #include <target/iscsi/iscsi_transport.h>
28 #include <target/iscsi/iscsi_target_core.h>
29 #include "iscsi_target_parameters.h"
30 #include "iscsi_target_device.h"
31 #include "iscsi_target_erl0.h"
32 #include "iscsi_target_nodeattrib.h"
33 #include "iscsi_target_tpg.h"
34 #include "iscsi_target_util.h"
35 #include "iscsi_target.h"
36 #include <target/iscsi/iscsi_target_stat.h>
39 /* Start items for lio_target_portal_cit */
41 static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item)
43 return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np);
46 static ssize_t lio_target_np_driver_show(struct config_item *item, char *page,
47 enum iscsit_transport_type type)
49 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
50 struct iscsi_tpg_np *tpg_np_new;
53 tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
55 rb = sprintf(page, "1\n");
57 rb = sprintf(page, "0\n");
62 static ssize_t lio_target_np_driver_store(struct config_item *item,
63 const char *page, size_t count, enum iscsit_transport_type type,
66 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
68 struct iscsi_portal_group *tpg;
69 struct iscsi_tpg_np *tpg_np_new = NULL;
73 rc = kstrtou32(page, 0, &op);
76 if ((op != 1) && (op != 0)) {
77 pr_err("Illegal value for tpg_enable: %u\n", op);
82 pr_err("Unable to locate struct iscsi_np from"
83 " struct iscsi_tpg_np\n");
88 if (iscsit_get_tpg(tpg) < 0)
92 if (strlen(mod_name)) {
93 rc = request_module(mod_name);
95 pr_warn("Unable to request_module for %s\n",
101 tpg_np_new = iscsit_tpg_add_network_portal(tpg,
102 &np->np_sockaddr, tpg_np, type);
103 if (IS_ERR(tpg_np_new)) {
104 rc = PTR_ERR(tpg_np_new);
108 tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type);
110 rc = iscsit_tpg_del_network_portal(tpg, tpg_np_new);
123 static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
125 return lio_target_np_driver_show(item, page, ISCSI_INFINIBAND);
128 static ssize_t lio_target_np_iser_store(struct config_item *item,
129 const char *page, size_t count)
131 return lio_target_np_driver_store(item, page, count,
132 ISCSI_INFINIBAND, "ib_isert");
134 CONFIGFS_ATTR(lio_target_np_, iser);
136 static ssize_t lio_target_np_cxgbit_show(struct config_item *item, char *page)
138 return lio_target_np_driver_show(item, page, ISCSI_CXGBIT);
141 static ssize_t lio_target_np_cxgbit_store(struct config_item *item,
142 const char *page, size_t count)
144 return lio_target_np_driver_store(item, page, count,
145 ISCSI_CXGBIT, "cxgbit");
147 CONFIGFS_ATTR(lio_target_np_, cxgbit);
149 static struct configfs_attribute *lio_target_portal_attrs[] = {
150 &lio_target_np_attr_iser,
151 &lio_target_np_attr_cxgbit,
155 /* Stop items for lio_target_portal_cit */
157 /* Start items for lio_target_np_cit */
159 #define MAX_PORTAL_LEN 256
161 static struct se_tpg_np *lio_target_call_addnptotpg(
162 struct se_portal_group *se_tpg,
163 struct config_group *group,
166 struct iscsi_portal_group *tpg;
167 struct iscsi_tpg_np *tpg_np;
168 char *str, *str2, *ip_str, *port_str;
169 struct sockaddr_storage sockaddr;
170 struct sockaddr_in *sock_in;
171 struct sockaddr_in6 *sock_in6;
174 char buf[MAX_PORTAL_LEN + 1];
176 if (strlen(name) > MAX_PORTAL_LEN) {
177 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
178 (int)strlen(name), MAX_PORTAL_LEN);
179 return ERR_PTR(-EOVERFLOW);
181 memset(buf, 0, MAX_PORTAL_LEN + 1);
182 snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
184 memset(&sockaddr, 0, sizeof(struct sockaddr_storage));
186 str = strstr(buf, "[");
190 str2 = strstr(str, "]");
192 pr_err("Unable to locate trailing \"]\""
193 " in IPv6 iSCSI network portal address\n");
194 return ERR_PTR(-EINVAL);
196 str++; /* Skip over leading "[" */
197 *str2 = '\0'; /* Terminate the unbracketed IPv6 address */
198 str2++; /* Skip over the \0 */
199 port_str = strstr(str2, ":");
201 pr_err("Unable to locate \":port\""
202 " in IPv6 iSCSI network portal address\n");
203 return ERR_PTR(-EINVAL);
205 *port_str = '\0'; /* Terminate string for IP */
206 port_str++; /* Skip over ":" */
208 ret = kstrtoul(port_str, 0, &port);
210 pr_err("kstrtoul() failed for port_str: %d\n", ret);
213 sock_in6 = (struct sockaddr_in6 *)&sockaddr;
214 sock_in6->sin6_family = AF_INET6;
215 sock_in6->sin6_port = htons((unsigned short)port);
216 ret = in6_pton(str, -1,
217 (void *)&sock_in6->sin6_addr.in6_u, -1, &end);
219 pr_err("in6_pton returned: %d\n", ret);
220 return ERR_PTR(-EINVAL);
223 str = ip_str = &buf[0];
224 port_str = strstr(ip_str, ":");
226 pr_err("Unable to locate \":port\""
227 " in IPv4 iSCSI network portal address\n");
228 return ERR_PTR(-EINVAL);
230 *port_str = '\0'; /* Terminate string for IP */
231 port_str++; /* Skip over ":" */
233 ret = kstrtoul(port_str, 0, &port);
235 pr_err("kstrtoul() failed for port_str: %d\n", ret);
238 sock_in = (struct sockaddr_in *)&sockaddr;
239 sock_in->sin_family = AF_INET;
240 sock_in->sin_port = htons((unsigned short)port);
241 sock_in->sin_addr.s_addr = in_aton(ip_str);
243 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
244 ret = iscsit_get_tpg(tpg);
246 return ERR_PTR(-EINVAL);
248 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
250 config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
253 * Assume ISCSI_TCP by default. Other network portals for other
256 * Traditional iSCSI over SCTP (initial support)
257 * iSER/TCP (TODO, hardware available)
258 * iSER/SCTP (TODO, software emulation with osc-iwarp)
259 * iSER/IB (TODO, hardware available)
261 * can be enabled with attributes under
262 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
265 tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
267 if (IS_ERR(tpg_np)) {
269 return ERR_CAST(tpg_np);
271 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
274 return &tpg_np->se_tpg_np;
277 static void lio_target_call_delnpfromtpg(
278 struct se_tpg_np *se_tpg_np)
280 struct iscsi_portal_group *tpg;
281 struct iscsi_tpg_np *tpg_np;
282 struct se_portal_group *se_tpg;
285 tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
287 ret = iscsit_get_tpg(tpg);
291 se_tpg = &tpg->tpg_se_tpg;
292 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
293 " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
294 tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
296 ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
300 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
305 /* End items for lio_target_np_cit */
307 /* Start items for lio_target_nacl_attrib_cit */
309 #define ISCSI_NACL_ATTR(name) \
310 static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
313 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
314 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
317 return sprintf(page, "%u\n", nacl->node_attrib.name); \
320 static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
321 const char *page, size_t count) \
323 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
324 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
329 ret = kstrtou32(page, 0, &val); \
332 ret = iscsit_na_##name(nacl, val); \
339 CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
341 ISCSI_NACL_ATTR(dataout_timeout);
342 ISCSI_NACL_ATTR(dataout_timeout_retries);
343 ISCSI_NACL_ATTR(default_erl);
344 ISCSI_NACL_ATTR(nopin_timeout);
345 ISCSI_NACL_ATTR(nopin_response_timeout);
346 ISCSI_NACL_ATTR(random_datain_pdu_offsets);
347 ISCSI_NACL_ATTR(random_datain_seq_offsets);
348 ISCSI_NACL_ATTR(random_r2t_offsets);
350 static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
351 &iscsi_nacl_attrib_attr_dataout_timeout,
352 &iscsi_nacl_attrib_attr_dataout_timeout_retries,
353 &iscsi_nacl_attrib_attr_default_erl,
354 &iscsi_nacl_attrib_attr_nopin_timeout,
355 &iscsi_nacl_attrib_attr_nopin_response_timeout,
356 &iscsi_nacl_attrib_attr_random_datain_pdu_offsets,
357 &iscsi_nacl_attrib_attr_random_datain_seq_offsets,
358 &iscsi_nacl_attrib_attr_random_r2t_offsets,
362 /* End items for lio_target_nacl_attrib_cit */
364 /* Start items for lio_target_nacl_auth_cit */
366 #define __DEF_NACL_AUTH_STR(prefix, name, flags) \
367 static ssize_t __iscsi_##prefix##_##name##_show( \
368 struct iscsi_node_acl *nacl, \
371 struct iscsi_node_auth *auth = &nacl->node_auth; \
373 if (!capable(CAP_SYS_ADMIN)) \
375 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
378 static ssize_t __iscsi_##prefix##_##name##_store( \
379 struct iscsi_node_acl *nacl, \
383 struct iscsi_node_auth *auth = &nacl->node_auth; \
385 if (!capable(CAP_SYS_ADMIN)) \
387 if (count >= sizeof(auth->name)) \
389 snprintf(auth->name, sizeof(auth->name), "%s", page); \
390 if (!strncmp("NULL", auth->name, 4)) \
391 auth->naf_flags &= ~flags; \
393 auth->naf_flags |= flags; \
395 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
396 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
397 auth->authenticate_target = 1; \
399 auth->authenticate_target = 0; \
404 #define DEF_NACL_AUTH_STR(name, flags) \
405 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
406 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
409 struct se_node_acl *nacl = auth_to_nacl(item); \
410 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
411 struct iscsi_node_acl, se_node_acl), page); \
413 static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \
414 const char *page, size_t count) \
416 struct se_node_acl *nacl = auth_to_nacl(item); \
417 return __iscsi_nacl_auth_##name##_store(container_of(nacl, \
418 struct iscsi_node_acl, se_node_acl), page, count); \
421 CONFIGFS_ATTR(iscsi_nacl_auth_, name)
424 * One-way authentication userid
426 DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
427 DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
428 DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
429 DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
431 #define __DEF_NACL_AUTH_INT(prefix, name) \
432 static ssize_t __iscsi_##prefix##_##name##_show( \
433 struct iscsi_node_acl *nacl, \
436 struct iscsi_node_auth *auth = &nacl->node_auth; \
438 if (!capable(CAP_SYS_ADMIN)) \
441 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
444 #define DEF_NACL_AUTH_INT(name) \
445 __DEF_NACL_AUTH_INT(nacl_auth, name) \
446 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
449 struct se_node_acl *nacl = auth_to_nacl(item); \
450 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
451 struct iscsi_node_acl, se_node_acl), page); \
454 CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
456 DEF_NACL_AUTH_INT(authenticate_target);
458 static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
459 &iscsi_nacl_auth_attr_userid,
460 &iscsi_nacl_auth_attr_password,
461 &iscsi_nacl_auth_attr_authenticate_target,
462 &iscsi_nacl_auth_attr_userid_mutual,
463 &iscsi_nacl_auth_attr_password_mutual,
467 /* End items for lio_target_nacl_auth_cit */
469 /* Start items for lio_target_nacl_param_cit */
471 #define ISCSI_NACL_PARAM(name) \
472 static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \
475 struct se_node_acl *se_nacl = param_to_nacl(item); \
476 struct iscsi_session *sess; \
477 struct se_session *se_sess; \
480 spin_lock_bh(&se_nacl->nacl_sess_lock); \
481 se_sess = se_nacl->nacl_sess; \
483 rb = snprintf(page, PAGE_SIZE, \
484 "No Active iSCSI Session\n"); \
486 sess = se_sess->fabric_sess_ptr; \
487 rb = snprintf(page, PAGE_SIZE, "%u\n", \
488 (u32)sess->sess_ops->name); \
490 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
495 CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
497 ISCSI_NACL_PARAM(MaxConnections);
498 ISCSI_NACL_PARAM(InitialR2T);
499 ISCSI_NACL_PARAM(ImmediateData);
500 ISCSI_NACL_PARAM(MaxBurstLength);
501 ISCSI_NACL_PARAM(FirstBurstLength);
502 ISCSI_NACL_PARAM(DefaultTime2Wait);
503 ISCSI_NACL_PARAM(DefaultTime2Retain);
504 ISCSI_NACL_PARAM(MaxOutstandingR2T);
505 ISCSI_NACL_PARAM(DataPDUInOrder);
506 ISCSI_NACL_PARAM(DataSequenceInOrder);
507 ISCSI_NACL_PARAM(ErrorRecoveryLevel);
509 static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
510 &iscsi_nacl_param_attr_MaxConnections,
511 &iscsi_nacl_param_attr_InitialR2T,
512 &iscsi_nacl_param_attr_ImmediateData,
513 &iscsi_nacl_param_attr_MaxBurstLength,
514 &iscsi_nacl_param_attr_FirstBurstLength,
515 &iscsi_nacl_param_attr_DefaultTime2Wait,
516 &iscsi_nacl_param_attr_DefaultTime2Retain,
517 &iscsi_nacl_param_attr_MaxOutstandingR2T,
518 &iscsi_nacl_param_attr_DataPDUInOrder,
519 &iscsi_nacl_param_attr_DataSequenceInOrder,
520 &iscsi_nacl_param_attr_ErrorRecoveryLevel,
524 /* End items for lio_target_nacl_param_cit */
526 /* Start items for lio_target_acl_cit */
528 static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
530 struct se_node_acl *se_nacl = acl_to_nacl(item);
531 struct iscsi_session *sess;
532 struct iscsi_conn *conn;
533 struct se_session *se_sess;
537 spin_lock_bh(&se_nacl->nacl_sess_lock);
538 se_sess = se_nacl->nacl_sess;
540 rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
541 " Endpoint: %s\n", se_nacl->initiatorname);
543 sess = se_sess->fabric_sess_ptr;
545 rb += sprintf(page+rb, "InitiatorName: %s\n",
546 sess->sess_ops->InitiatorName);
547 rb += sprintf(page+rb, "InitiatorAlias: %s\n",
548 sess->sess_ops->InitiatorAlias);
550 rb += sprintf(page+rb,
551 "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ",
552 sess->sid, sess->isid, sess->tsih);
553 rb += sprintf(page+rb, "SessionType: %s\n",
554 (sess->sess_ops->SessionType) ?
555 "Discovery" : "Normal");
556 rb += sprintf(page+rb, "Session State: ");
557 switch (sess->session_state) {
558 case TARG_SESS_STATE_FREE:
559 rb += sprintf(page+rb, "TARG_SESS_FREE\n");
561 case TARG_SESS_STATE_ACTIVE:
562 rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
564 case TARG_SESS_STATE_LOGGED_IN:
565 rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
567 case TARG_SESS_STATE_FAILED:
568 rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
570 case TARG_SESS_STATE_IN_CONTINUE:
571 rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
574 rb += sprintf(page+rb, "ERROR: Unknown Session"
579 rb += sprintf(page+rb, "---------------------[iSCSI Session"
580 " Values]-----------------------\n");
581 rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
582 " : MaxCmdSN : ITT : TTT\n");
583 max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
584 rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
587 (max_cmd_sn - sess->exp_cmd_sn) + 1,
588 sess->exp_cmd_sn, max_cmd_sn,
589 sess->init_task_tag, sess->targ_xfer_tag);
590 rb += sprintf(page+rb, "----------------------[iSCSI"
591 " Connections]-------------------------\n");
593 spin_lock(&sess->conn_lock);
594 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
595 rb += sprintf(page+rb, "CID: %hu Connection"
596 " State: ", conn->cid);
597 switch (conn->conn_state) {
598 case TARG_CONN_STATE_FREE:
599 rb += sprintf(page+rb,
600 "TARG_CONN_STATE_FREE\n");
602 case TARG_CONN_STATE_XPT_UP:
603 rb += sprintf(page+rb,
604 "TARG_CONN_STATE_XPT_UP\n");
606 case TARG_CONN_STATE_IN_LOGIN:
607 rb += sprintf(page+rb,
608 "TARG_CONN_STATE_IN_LOGIN\n");
610 case TARG_CONN_STATE_LOGGED_IN:
611 rb += sprintf(page+rb,
612 "TARG_CONN_STATE_LOGGED_IN\n");
614 case TARG_CONN_STATE_IN_LOGOUT:
615 rb += sprintf(page+rb,
616 "TARG_CONN_STATE_IN_LOGOUT\n");
618 case TARG_CONN_STATE_LOGOUT_REQUESTED:
619 rb += sprintf(page+rb,
620 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
622 case TARG_CONN_STATE_CLEANUP_WAIT:
623 rb += sprintf(page+rb,
624 "TARG_CONN_STATE_CLEANUP_WAIT\n");
627 rb += sprintf(page+rb,
628 "ERROR: Unknown Connection State!\n");
632 rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr,
633 (conn->network_transport == ISCSI_TCP) ?
635 rb += sprintf(page+rb, " StatSN: 0x%08x\n",
638 spin_unlock(&sess->conn_lock);
640 spin_unlock_bh(&se_nacl->nacl_sess_lock);
645 static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
648 return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth);
651 static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
652 const char *page, size_t count)
654 struct se_node_acl *se_nacl = acl_to_nacl(item);
655 struct se_portal_group *se_tpg = se_nacl->se_tpg;
656 struct iscsi_portal_group *tpg = container_of(se_tpg,
657 struct iscsi_portal_group, tpg_se_tpg);
658 struct config_item *acl_ci, *tpg_ci, *wwn_ci;
662 ret = kstrtou32(page, 0, &cmdsn_depth);
665 if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
666 pr_err("Passed cmdsn_depth: %u exceeds"
667 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
668 TA_DEFAULT_CMDSN_DEPTH_MAX);
671 acl_ci = &se_nacl->acl_group.cg_item;
673 pr_err("Unable to locatel acl_ci\n");
676 tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
678 pr_err("Unable to locate tpg_ci\n");
681 wwn_ci = &tpg_ci->ci_group->cg_item;
683 pr_err("Unable to locate config_item wwn_ci\n");
687 if (iscsit_get_tpg(tpg) < 0)
690 ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth);
692 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
693 "InitiatorName: %s\n", config_item_name(wwn_ci),
694 config_item_name(tpg_ci), cmdsn_depth,
695 config_item_name(acl_ci));
698 return (!ret) ? count : (ssize_t)ret;
701 static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
703 return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
706 static ssize_t lio_target_nacl_tag_store(struct config_item *item,
707 const char *page, size_t count)
709 struct se_node_acl *se_nacl = acl_to_nacl(item);
712 ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
719 CONFIGFS_ATTR_RO(lio_target_nacl_, info);
720 CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
721 CONFIGFS_ATTR(lio_target_nacl_, tag);
723 static struct configfs_attribute *lio_target_initiator_attrs[] = {
724 &lio_target_nacl_attr_info,
725 &lio_target_nacl_attr_cmdsn_depth,
726 &lio_target_nacl_attr_tag,
730 static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
733 struct iscsi_node_acl *acl =
734 container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
736 config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
737 "iscsi_sess_stats", &iscsi_stat_sess_cit);
738 configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group,
739 &se_nacl->acl_fabric_stat_group);
743 /* End items for lio_target_acl_cit */
745 /* Start items for lio_target_tpg_attrib_cit */
747 #define DEF_TPG_ATTRIB(name) \
749 static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \
752 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
753 struct iscsi_portal_group *tpg = container_of(se_tpg, \
754 struct iscsi_portal_group, tpg_se_tpg); \
757 if (iscsit_get_tpg(tpg) < 0) \
760 rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \
761 iscsit_put_tpg(tpg); \
765 static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
766 const char *page, size_t count) \
768 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
769 struct iscsi_portal_group *tpg = container_of(se_tpg, \
770 struct iscsi_portal_group, tpg_se_tpg); \
774 if (iscsit_get_tpg(tpg) < 0) \
777 ret = kstrtou32(page, 0, &val); \
780 ret = iscsit_ta_##name(tpg, val); \
784 iscsit_put_tpg(tpg); \
787 iscsit_put_tpg(tpg); \
790 CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
792 DEF_TPG_ATTRIB(authentication);
793 DEF_TPG_ATTRIB(login_timeout);
794 DEF_TPG_ATTRIB(netif_timeout);
795 DEF_TPG_ATTRIB(generate_node_acls);
796 DEF_TPG_ATTRIB(default_cmdsn_depth);
797 DEF_TPG_ATTRIB(cache_dynamic_acls);
798 DEF_TPG_ATTRIB(demo_mode_write_protect);
799 DEF_TPG_ATTRIB(prod_mode_write_protect);
800 DEF_TPG_ATTRIB(demo_mode_discovery);
801 DEF_TPG_ATTRIB(default_erl);
802 DEF_TPG_ATTRIB(t10_pi);
803 DEF_TPG_ATTRIB(fabric_prot_type);
804 DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
805 DEF_TPG_ATTRIB(login_keys_workaround);
807 static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
808 &iscsi_tpg_attrib_attr_authentication,
809 &iscsi_tpg_attrib_attr_login_timeout,
810 &iscsi_tpg_attrib_attr_netif_timeout,
811 &iscsi_tpg_attrib_attr_generate_node_acls,
812 &iscsi_tpg_attrib_attr_default_cmdsn_depth,
813 &iscsi_tpg_attrib_attr_cache_dynamic_acls,
814 &iscsi_tpg_attrib_attr_demo_mode_write_protect,
815 &iscsi_tpg_attrib_attr_prod_mode_write_protect,
816 &iscsi_tpg_attrib_attr_demo_mode_discovery,
817 &iscsi_tpg_attrib_attr_default_erl,
818 &iscsi_tpg_attrib_attr_t10_pi,
819 &iscsi_tpg_attrib_attr_fabric_prot_type,
820 &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
821 &iscsi_tpg_attrib_attr_login_keys_workaround,
825 /* End items for lio_target_tpg_attrib_cit */
827 /* Start items for lio_target_tpg_auth_cit */
829 #define __DEF_TPG_AUTH_STR(prefix, name, flags) \
830 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
833 struct iscsi_portal_group *tpg = container_of(se_tpg, \
834 struct iscsi_portal_group, tpg_se_tpg); \
835 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
837 if (!capable(CAP_SYS_ADMIN)) \
840 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
843 static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
844 const char *page, size_t count) \
846 struct iscsi_portal_group *tpg = container_of(se_tpg, \
847 struct iscsi_portal_group, tpg_se_tpg); \
848 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
850 if (!capable(CAP_SYS_ADMIN)) \
853 snprintf(auth->name, sizeof(auth->name), "%s", page); \
854 if (!(strncmp("NULL", auth->name, 4))) \
855 auth->naf_flags &= ~flags; \
857 auth->naf_flags |= flags; \
859 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
860 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
861 auth->authenticate_target = 1; \
863 auth->authenticate_target = 0; \
868 #define DEF_TPG_AUTH_STR(name, flags) \
869 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
870 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
873 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
876 static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \
877 const char *page, size_t count) \
879 return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
882 CONFIGFS_ATTR(iscsi_tpg_auth_, name);
885 DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
886 DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
887 DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
888 DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
890 #define __DEF_TPG_AUTH_INT(prefix, name) \
891 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
894 struct iscsi_portal_group *tpg = container_of(se_tpg, \
895 struct iscsi_portal_group, tpg_se_tpg); \
896 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
898 if (!capable(CAP_SYS_ADMIN)) \
901 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
904 #define DEF_TPG_AUTH_INT(name) \
905 __DEF_TPG_AUTH_INT(tpg_auth, name) \
906 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
909 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
911 CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
913 DEF_TPG_AUTH_INT(authenticate_target);
915 static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
916 &iscsi_tpg_auth_attr_userid,
917 &iscsi_tpg_auth_attr_password,
918 &iscsi_tpg_auth_attr_authenticate_target,
919 &iscsi_tpg_auth_attr_userid_mutual,
920 &iscsi_tpg_auth_attr_password_mutual,
924 /* End items for lio_target_tpg_auth_cit */
926 /* Start items for lio_target_tpg_param_cit */
928 #define DEF_TPG_PARAM(name) \
929 static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \
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); \
935 struct iscsi_param *param; \
938 if (iscsit_get_tpg(tpg) < 0) \
941 param = iscsi_find_param_from_key(__stringify(name), \
944 iscsit_put_tpg(tpg); \
947 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
949 iscsit_put_tpg(tpg); \
952 static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
953 const char *page, size_t count) \
955 struct se_portal_group *se_tpg = param_to_tpg(item); \
956 struct iscsi_portal_group *tpg = container_of(se_tpg, \
957 struct iscsi_portal_group, tpg_se_tpg); \
961 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
964 len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
965 if (isspace(buf[len-1])) \
966 buf[len-1] = '\0'; /* Kill newline */ \
968 if (iscsit_get_tpg(tpg) < 0) { \
973 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
978 iscsit_put_tpg(tpg); \
982 iscsit_put_tpg(tpg); \
985 CONFIGFS_ATTR(iscsi_tpg_param_, name)
987 DEF_TPG_PARAM(AuthMethod);
988 DEF_TPG_PARAM(HeaderDigest);
989 DEF_TPG_PARAM(DataDigest);
990 DEF_TPG_PARAM(MaxConnections);
991 DEF_TPG_PARAM(TargetAlias);
992 DEF_TPG_PARAM(InitialR2T);
993 DEF_TPG_PARAM(ImmediateData);
994 DEF_TPG_PARAM(MaxRecvDataSegmentLength);
995 DEF_TPG_PARAM(MaxXmitDataSegmentLength);
996 DEF_TPG_PARAM(MaxBurstLength);
997 DEF_TPG_PARAM(FirstBurstLength);
998 DEF_TPG_PARAM(DefaultTime2Wait);
999 DEF_TPG_PARAM(DefaultTime2Retain);
1000 DEF_TPG_PARAM(MaxOutstandingR2T);
1001 DEF_TPG_PARAM(DataPDUInOrder);
1002 DEF_TPG_PARAM(DataSequenceInOrder);
1003 DEF_TPG_PARAM(ErrorRecoveryLevel);
1004 DEF_TPG_PARAM(IFMarker);
1005 DEF_TPG_PARAM(OFMarker);
1006 DEF_TPG_PARAM(IFMarkInt);
1007 DEF_TPG_PARAM(OFMarkInt);
1009 static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
1010 &iscsi_tpg_param_attr_AuthMethod,
1011 &iscsi_tpg_param_attr_HeaderDigest,
1012 &iscsi_tpg_param_attr_DataDigest,
1013 &iscsi_tpg_param_attr_MaxConnections,
1014 &iscsi_tpg_param_attr_TargetAlias,
1015 &iscsi_tpg_param_attr_InitialR2T,
1016 &iscsi_tpg_param_attr_ImmediateData,
1017 &iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
1018 &iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
1019 &iscsi_tpg_param_attr_MaxBurstLength,
1020 &iscsi_tpg_param_attr_FirstBurstLength,
1021 &iscsi_tpg_param_attr_DefaultTime2Wait,
1022 &iscsi_tpg_param_attr_DefaultTime2Retain,
1023 &iscsi_tpg_param_attr_MaxOutstandingR2T,
1024 &iscsi_tpg_param_attr_DataPDUInOrder,
1025 &iscsi_tpg_param_attr_DataSequenceInOrder,
1026 &iscsi_tpg_param_attr_ErrorRecoveryLevel,
1027 &iscsi_tpg_param_attr_IFMarker,
1028 &iscsi_tpg_param_attr_OFMarker,
1029 &iscsi_tpg_param_attr_IFMarkInt,
1030 &iscsi_tpg_param_attr_OFMarkInt,
1034 /* End items for lio_target_tpg_param_cit */
1036 /* Start items for lio_target_tpg_cit */
1038 static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page)
1040 struct se_portal_group *se_tpg = to_tpg(item);
1041 struct iscsi_portal_group *tpg = container_of(se_tpg,
1042 struct iscsi_portal_group, tpg_se_tpg);
1045 spin_lock(&tpg->tpg_state_lock);
1046 len = sprintf(page, "%d\n",
1047 (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1048 spin_unlock(&tpg->tpg_state_lock);
1053 static ssize_t lio_target_tpg_enable_store(struct config_item *item,
1054 const char *page, size_t count)
1056 struct se_portal_group *se_tpg = to_tpg(item);
1057 struct iscsi_portal_group *tpg = container_of(se_tpg,
1058 struct iscsi_portal_group, tpg_se_tpg);
1062 ret = kstrtou32(page, 0, &op);
1065 if ((op != 1) && (op != 0)) {
1066 pr_err("Illegal value for tpg_enable: %u\n", op);
1070 ret = iscsit_get_tpg(tpg);
1075 ret = iscsit_tpg_enable_portal_group(tpg);
1080 * iscsit_tpg_disable_portal_group() assumes force=1
1082 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1087 iscsit_put_tpg(tpg);
1090 iscsit_put_tpg(tpg);
1095 static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
1098 return target_show_dynamic_sessions(to_tpg(item), page);
1101 CONFIGFS_ATTR(lio_target_tpg_, enable);
1102 CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
1104 static struct configfs_attribute *lio_target_tpg_attrs[] = {
1105 &lio_target_tpg_attr_enable,
1106 &lio_target_tpg_attr_dynamic_sessions,
1110 /* End items for lio_target_tpg_cit */
1112 /* Start items for lio_target_tiqn_cit */
1114 static struct se_portal_group *lio_target_tiqn_addtpg(
1116 struct config_group *group,
1119 struct iscsi_portal_group *tpg;
1120 struct iscsi_tiqn *tiqn;
1125 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1127 * Only tpgt_# directory groups can be created below
1128 * target/iscsi/iqn.superturodiskarry/
1130 tpgt_str = strstr(name, "tpgt_");
1132 pr_err("Unable to locate \"tpgt_#\" directory"
1136 tpgt_str += 5; /* Skip ahead of "tpgt_" */
1137 ret = kstrtou16(tpgt_str, 0, &tpgt);
1141 tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1145 ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
1149 ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1153 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1154 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1156 return &tpg->tpg_se_tpg;
1158 core_tpg_deregister(&tpg->tpg_se_tpg);
1164 static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1166 struct iscsi_portal_group *tpg;
1167 struct iscsi_tiqn *tiqn;
1169 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1170 tiqn = tpg->tpg_tiqn;
1172 * iscsit_tpg_del_portal_group() assumes force=1
1174 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1175 iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1178 /* End items for lio_target_tiqn_cit */
1180 /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1182 static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
1185 return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
1188 CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
1190 static struct configfs_attribute *lio_target_wwn_attrs[] = {
1191 &lio_target_wwn_attr_lio_version,
1195 static struct se_wwn *lio_target_call_coreaddtiqn(
1196 struct target_fabric_configfs *tf,
1197 struct config_group *group,
1200 struct iscsi_tiqn *tiqn;
1202 tiqn = iscsit_add_tiqn((unsigned char *)name);
1204 return ERR_CAST(tiqn);
1206 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1207 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1209 return &tiqn->tiqn_wwn;
1212 static void lio_target_add_wwn_groups(struct se_wwn *wwn)
1214 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1216 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1217 "iscsi_instance", &iscsi_stat_instance_cit);
1218 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1219 &tiqn->tiqn_wwn.fabric_stat_group);
1221 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1222 "iscsi_sess_err", &iscsi_stat_sess_err_cit);
1223 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1224 &tiqn->tiqn_wwn.fabric_stat_group);
1226 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1227 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1228 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1229 &tiqn->tiqn_wwn.fabric_stat_group);
1231 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1232 "iscsi_login_stats", &iscsi_stat_login_cit);
1233 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1234 &tiqn->tiqn_wwn.fabric_stat_group);
1236 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1237 "iscsi_logout_stats", &iscsi_stat_logout_cit);
1238 configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1239 &tiqn->tiqn_wwn.fabric_stat_group);
1242 static void lio_target_call_coredeltiqn(
1245 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1247 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1249 iscsit_del_tiqn(tiqn);
1252 /* End LIO-Target TIQN struct contig_lio_target_cit */
1254 /* Start lio_target_discovery_auth_cit */
1256 #define DEF_DISC_AUTH_STR(name, flags) \
1257 __DEF_NACL_AUTH_STR(disc, name, flags) \
1258 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1260 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
1263 static ssize_t iscsi_disc_##name##_store(struct config_item *item, \
1264 const char *page, size_t count) \
1266 return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \
1270 CONFIGFS_ATTR(iscsi_disc_, name)
1272 DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1273 DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1274 DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1275 DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1277 #define DEF_DISC_AUTH_INT(name) \
1278 __DEF_NACL_AUTH_INT(disc, name) \
1279 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1281 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
1284 CONFIGFS_ATTR_RO(iscsi_disc_, name)
1286 DEF_DISC_AUTH_INT(authenticate_target);
1289 static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
1292 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1294 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1297 static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1298 const char *page, size_t count)
1300 struct iscsi_param *param;
1301 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
1305 err = kstrtou32(page, 0, &op);
1308 if ((op != 1) && (op != 0)) {
1309 pr_err("Illegal value for enforce_discovery_auth:"
1314 if (!discovery_tpg) {
1315 pr_err("iscsit_global->discovery_tpg is NULL\n");
1319 param = iscsi_find_param_from_key(AUTHMETHOD,
1320 discovery_tpg->param_list);
1326 * Reset the AuthMethod key to CHAP.
1328 if (iscsi_update_param_value(param, CHAP) < 0)
1331 discovery_tpg->tpg_attrib.authentication = 1;
1332 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1333 pr_debug("LIO-CORE[0] Successfully enabled"
1334 " authentication enforcement for iSCSI"
1335 " Discovery TPG\n");
1338 * Reset the AuthMethod key to CHAP,None
1340 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1343 discovery_tpg->tpg_attrib.authentication = 0;
1344 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1345 pr_debug("LIO-CORE[0] Successfully disabled"
1346 " authentication enforcement for iSCSI"
1347 " Discovery TPG\n");
1353 CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
1355 static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1356 &iscsi_disc_attr_userid,
1357 &iscsi_disc_attr_password,
1358 &iscsi_disc_attr_authenticate_target,
1359 &iscsi_disc_attr_userid_mutual,
1360 &iscsi_disc_attr_password_mutual,
1361 &iscsi_disc_attr_enforce_discovery_auth,
1365 /* End lio_target_discovery_auth_cit */
1367 /* Start functions for target_core_fabric_ops */
1369 static char *iscsi_get_fabric_name(void)
1374 static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1376 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1378 return cmd->i_state;
1381 static u32 lio_sess_get_index(struct se_session *se_sess)
1383 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1385 return sess->session_index;
1388 static u32 lio_sess_get_initiator_sid(
1389 struct se_session *se_sess,
1393 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1395 * iSCSI Initiator Session Identifier from RFC-3720.
1397 return snprintf(buf, size, "%6phN", sess->isid);
1400 static int lio_queue_data_in(struct se_cmd *se_cmd)
1402 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1404 cmd->i_state = ISTATE_SEND_DATAIN;
1405 cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd);
1410 static int lio_write_pending(struct se_cmd *se_cmd)
1412 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1413 struct iscsi_conn *conn = cmd->conn;
1415 if (!cmd->immediate_data && !cmd->unsolicited_data)
1416 return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
1421 static int lio_write_pending_status(struct se_cmd *se_cmd)
1423 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1426 spin_lock_bh(&cmd->istate_lock);
1427 ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1428 spin_unlock_bh(&cmd->istate_lock);
1433 static int lio_queue_status(struct se_cmd *se_cmd)
1435 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1437 cmd->i_state = ISTATE_SEND_STATUS;
1439 if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
1440 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1443 cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd);
1448 static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
1450 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1452 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1453 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1456 static void lio_aborted_task(struct se_cmd *se_cmd)
1458 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1460 cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1463 static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg)
1465 return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1468 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1470 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
1473 static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1475 return iscsi_tpg(se_tpg)->tpgt;
1478 static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1480 return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
1483 static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1485 return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
1488 static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1490 return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
1493 static int lio_tpg_check_demo_mode_write_protect(
1494 struct se_portal_group *se_tpg)
1496 return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
1499 static int lio_tpg_check_prod_mode_write_protect(
1500 struct se_portal_group *se_tpg)
1502 return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
1505 static int lio_tpg_check_prot_fabric_only(
1506 struct se_portal_group *se_tpg)
1509 * Only report fabric_prot_type if t10_pi has also been enabled
1510 * for incoming ib_isert sessions.
1512 if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
1514 return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
1518 * This function calls iscsit_inc_session_usage_count() on the
1519 * struct iscsi_session in question.
1521 static void lio_tpg_close_session(struct se_session *se_sess)
1523 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1524 struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
1526 spin_lock_bh(&se_tpg->session_lock);
1527 spin_lock(&sess->conn_lock);
1528 if (atomic_read(&sess->session_fall_back_to_erl0) ||
1529 atomic_read(&sess->session_logout) ||
1530 atomic_read(&sess->session_close) ||
1531 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1532 spin_unlock(&sess->conn_lock);
1533 spin_unlock_bh(&se_tpg->session_lock);
1536 iscsit_inc_session_usage_count(sess);
1537 atomic_set(&sess->session_reinstatement, 1);
1538 atomic_set(&sess->session_fall_back_to_erl0, 1);
1539 atomic_set(&sess->session_close, 1);
1540 spin_unlock(&sess->conn_lock);
1542 iscsit_stop_time2retain_timer(sess);
1543 spin_unlock_bh(&se_tpg->session_lock);
1545 iscsit_stop_session(sess, 1, 1);
1546 iscsit_dec_session_usage_count(sess);
1549 static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1551 return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
1554 static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1556 struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1558 struct se_portal_group *se_tpg = se_acl->se_tpg;
1559 struct iscsi_portal_group *tpg = container_of(se_tpg,
1560 struct iscsi_portal_group, tpg_se_tpg);
1562 acl->node_attrib.nacl = acl;
1563 iscsit_set_default_node_attribues(acl, tpg);
1566 static int lio_check_stop_free(struct se_cmd *se_cmd)
1568 return target_put_sess_cmd(se_cmd);
1571 static void lio_release_cmd(struct se_cmd *se_cmd)
1573 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1575 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
1576 iscsit_release_cmd(cmd);
1579 const struct target_core_fabric_ops iscsi_ops = {
1580 .module = THIS_MODULE,
1582 .node_acl_size = sizeof(struct iscsi_node_acl),
1583 .get_fabric_name = iscsi_get_fabric_name,
1584 .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
1585 .tpg_get_tag = lio_tpg_get_tag,
1586 .tpg_get_default_depth = lio_tpg_get_default_depth,
1587 .tpg_check_demo_mode = lio_tpg_check_demo_mode,
1588 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
1589 .tpg_check_demo_mode_write_protect =
1590 lio_tpg_check_demo_mode_write_protect,
1591 .tpg_check_prod_mode_write_protect =
1592 lio_tpg_check_prod_mode_write_protect,
1593 .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only,
1594 .tpg_get_inst_index = lio_tpg_get_inst_index,
1595 .check_stop_free = lio_check_stop_free,
1596 .release_cmd = lio_release_cmd,
1597 .close_session = lio_tpg_close_session,
1598 .sess_get_index = lio_sess_get_index,
1599 .sess_get_initiator_sid = lio_sess_get_initiator_sid,
1600 .write_pending = lio_write_pending,
1601 .write_pending_status = lio_write_pending_status,
1602 .set_default_node_attributes = lio_set_default_node_attributes,
1603 .get_cmd_state = iscsi_get_cmd_state,
1604 .queue_data_in = lio_queue_data_in,
1605 .queue_status = lio_queue_status,
1606 .queue_tm_rsp = lio_queue_tm_rsp,
1607 .aborted_task = lio_aborted_task,
1608 .fabric_make_wwn = lio_target_call_coreaddtiqn,
1609 .fabric_drop_wwn = lio_target_call_coredeltiqn,
1610 .add_wwn_groups = lio_target_add_wwn_groups,
1611 .fabric_make_tpg = lio_target_tiqn_addtpg,
1612 .fabric_drop_tpg = lio_target_tiqn_deltpg,
1613 .fabric_make_np = lio_target_call_addnptotpg,
1614 .fabric_drop_np = lio_target_call_delnpfromtpg,
1615 .fabric_init_nodeacl = lio_target_init_nodeacl,
1617 .tfc_discovery_attrs = lio_target_discovery_auth_attrs,
1618 .tfc_wwn_attrs = lio_target_wwn_attrs,
1619 .tfc_tpg_base_attrs = lio_target_tpg_attrs,
1620 .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs,
1621 .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs,
1622 .tfc_tpg_param_attrs = lio_target_tpg_param_attrs,
1623 .tfc_tpg_np_base_attrs = lio_target_portal_attrs,
1624 .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs,
1625 .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs,
1626 .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs,
1627 .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs,