spi-topcliff-pch: supports a spi mode setup and bit order setup by IO control
[zen-stable.git] / drivers / target / iscsi / iscsi_target_configfs.c
blobdcef63bf5f9da13eef0d82891c69d86b76a5ecde
1 /*******************************************************************************
2 * This file contains the configfs implementation for iSCSI Target mode
3 * from the LIO-Target Project.
5 * \u00a9 Copyright 2007-2011 RisingTide Systems LLC.
7 * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
9 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 ****************************************************************************/
22 #include <linux/configfs.h>
23 #include <linux/export.h>
24 #include <linux/inet.h>
25 #include <target/target_core_base.h>
26 #include <target/target_core_fabric.h>
27 #include <target/target_core_fabric_configfs.h>
28 #include <target/target_core_configfs.h>
29 #include <target/configfs_macros.h>
31 #include "iscsi_target_core.h"
32 #include "iscsi_target_parameters.h"
33 #include "iscsi_target_device.h"
34 #include "iscsi_target_erl0.h"
35 #include "iscsi_target_nodeattrib.h"
36 #include "iscsi_target_tpg.h"
37 #include "iscsi_target_util.h"
38 #include "iscsi_target.h"
39 #include "iscsi_target_stat.h"
40 #include "iscsi_target_configfs.h"
42 struct target_fabric_configfs *lio_target_fabric_configfs;
44 struct lio_target_configfs_attribute {
45 struct configfs_attribute attr;
46 ssize_t (*show)(void *, char *);
47 ssize_t (*store)(void *, const char *, size_t);
50 struct iscsi_portal_group *lio_get_tpg_from_tpg_item(
51 struct config_item *item,
52 struct iscsi_tiqn **tiqn_out)
54 struct se_portal_group *se_tpg = container_of(to_config_group(item),
55 struct se_portal_group, tpg_group);
56 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
57 int ret;
59 if (!tpg) {
60 pr_err("Unable to locate struct iscsi_portal_group "
61 "pointer\n");
62 return NULL;
64 ret = iscsit_get_tpg(tpg);
65 if (ret < 0)
66 return NULL;
68 *tiqn_out = tpg->tpg_tiqn;
69 return tpg;
72 /* Start items for lio_target_portal_cit */
74 static ssize_t lio_target_np_show_sctp(
75 struct se_tpg_np *se_tpg_np,
76 char *page)
78 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
79 struct iscsi_tpg_np, se_tpg_np);
80 struct iscsi_tpg_np *tpg_np_sctp;
81 ssize_t rb;
83 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
84 if (tpg_np_sctp)
85 rb = sprintf(page, "1\n");
86 else
87 rb = sprintf(page, "0\n");
89 return rb;
92 static ssize_t lio_target_np_store_sctp(
93 struct se_tpg_np *se_tpg_np,
94 const char *page,
95 size_t count)
97 struct iscsi_np *np;
98 struct iscsi_portal_group *tpg;
99 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
100 struct iscsi_tpg_np, se_tpg_np);
101 struct iscsi_tpg_np *tpg_np_sctp = NULL;
102 char *endptr;
103 u32 op;
104 int ret;
106 op = simple_strtoul(page, &endptr, 0);
107 if ((op != 1) && (op != 0)) {
108 pr_err("Illegal value for tpg_enable: %u\n", op);
109 return -EINVAL;
111 np = tpg_np->tpg_np;
112 if (!np) {
113 pr_err("Unable to locate struct iscsi_np from"
114 " struct iscsi_tpg_np\n");
115 return -EINVAL;
118 tpg = tpg_np->tpg;
119 if (iscsit_get_tpg(tpg) < 0)
120 return -EINVAL;
122 if (op) {
124 * Use existing np->np_sockaddr for SCTP network portal reference
126 tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
127 np->np_ip, tpg_np, ISCSI_SCTP_TCP);
128 if (!tpg_np_sctp || IS_ERR(tpg_np_sctp))
129 goto out;
130 } else {
131 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
132 if (!tpg_np_sctp)
133 goto out;
135 ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp);
136 if (ret < 0)
137 goto out;
140 iscsit_put_tpg(tpg);
141 return count;
142 out:
143 iscsit_put_tpg(tpg);
144 return -EINVAL;
147 TF_NP_BASE_ATTR(lio_target, sctp, S_IRUGO | S_IWUSR);
149 static struct configfs_attribute *lio_target_portal_attrs[] = {
150 &lio_target_np_sctp.attr,
151 NULL,
154 /* Stop items for lio_target_portal_cit */
156 /* Start items for lio_target_np_cit */
158 #define MAX_PORTAL_LEN 256
160 struct se_tpg_np *lio_target_call_addnptotpg(
161 struct se_portal_group *se_tpg,
162 struct config_group *group,
163 const char *name)
165 struct iscsi_portal_group *tpg;
166 struct iscsi_tpg_np *tpg_np;
167 char *str, *str2, *ip_str, *port_str;
168 struct __kernel_sockaddr_storage sockaddr;
169 struct sockaddr_in *sock_in;
170 struct sockaddr_in6 *sock_in6;
171 unsigned long port;
172 int ret;
173 char buf[MAX_PORTAL_LEN + 1];
175 if (strlen(name) > MAX_PORTAL_LEN) {
176 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
177 (int)strlen(name), MAX_PORTAL_LEN);
178 return ERR_PTR(-EOVERFLOW);
180 memset(buf, 0, MAX_PORTAL_LEN + 1);
181 snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
183 memset(&sockaddr, 0, sizeof(struct __kernel_sockaddr_storage));
185 str = strstr(buf, "[");
186 if (str) {
187 const char *end;
189 str2 = strstr(str, "]");
190 if (!str2) {
191 pr_err("Unable to locate trailing \"]\""
192 " in IPv6 iSCSI network portal address\n");
193 return ERR_PTR(-EINVAL);
195 str++; /* Skip over leading "[" */
196 *str2 = '\0'; /* Terminate the IPv6 address */
197 str2++; /* Skip over the "]" */
198 port_str = strstr(str2, ":");
199 if (!port_str) {
200 pr_err("Unable to locate \":port\""
201 " in IPv6 iSCSI network portal address\n");
202 return ERR_PTR(-EINVAL);
204 *port_str = '\0'; /* Terminate string for IP */
205 port_str++; /* Skip over ":" */
207 ret = strict_strtoul(port_str, 0, &port);
208 if (ret < 0) {
209 pr_err("strict_strtoul() failed for port_str: %d\n", ret);
210 return ERR_PTR(ret);
212 sock_in6 = (struct sockaddr_in6 *)&sockaddr;
213 sock_in6->sin6_family = AF_INET6;
214 sock_in6->sin6_port = htons((unsigned short)port);
215 ret = in6_pton(str, IPV6_ADDRESS_SPACE,
216 (void *)&sock_in6->sin6_addr.in6_u, -1, &end);
217 if (ret <= 0) {
218 pr_err("in6_pton returned: %d\n", ret);
219 return ERR_PTR(-EINVAL);
221 } else {
222 str = ip_str = &buf[0];
223 port_str = strstr(ip_str, ":");
224 if (!port_str) {
225 pr_err("Unable to locate \":port\""
226 " in IPv4 iSCSI network portal address\n");
227 return ERR_PTR(-EINVAL);
229 *port_str = '\0'; /* Terminate string for IP */
230 port_str++; /* Skip over ":" */
232 ret = strict_strtoul(port_str, 0, &port);
233 if (ret < 0) {
234 pr_err("strict_strtoul() failed for port_str: %d\n", ret);
235 return ERR_PTR(ret);
237 sock_in = (struct sockaddr_in *)&sockaddr;
238 sock_in->sin_family = AF_INET;
239 sock_in->sin_port = htons((unsigned short)port);
240 sock_in->sin_addr.s_addr = in_aton(ip_str);
242 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
243 ret = iscsit_get_tpg(tpg);
244 if (ret < 0)
245 return ERR_PTR(-EINVAL);
247 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
248 " PORTAL: %s\n",
249 config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
250 tpg->tpgt, name);
252 * Assume ISCSI_TCP by default. Other network portals for other
253 * iSCSI fabrics:
255 * Traditional iSCSI over SCTP (initial support)
256 * iSER/TCP (TODO, hardware available)
257 * iSER/SCTP (TODO, software emulation with osc-iwarp)
258 * iSER/IB (TODO, hardware available)
260 * can be enabled with atributes under
261 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
264 tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, str, NULL,
265 ISCSI_TCP);
266 if (IS_ERR(tpg_np)) {
267 iscsit_put_tpg(tpg);
268 return ERR_CAST(tpg_np);
270 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
272 iscsit_put_tpg(tpg);
273 return &tpg_np->se_tpg_np;
276 static void lio_target_call_delnpfromtpg(
277 struct se_tpg_np *se_tpg_np)
279 struct iscsi_portal_group *tpg;
280 struct iscsi_tpg_np *tpg_np;
281 struct se_portal_group *se_tpg;
282 int ret;
284 tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
285 tpg = tpg_np->tpg;
286 ret = iscsit_get_tpg(tpg);
287 if (ret < 0)
288 return;
290 se_tpg = &tpg->tpg_se_tpg;
291 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
292 " PORTAL: %s:%hu\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
293 tpg->tpgt, tpg_np->tpg_np->np_ip, tpg_np->tpg_np->np_port);
295 ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
296 if (ret < 0)
297 goto out;
299 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
300 out:
301 iscsit_put_tpg(tpg);
304 /* End items for lio_target_np_cit */
306 /* Start items for lio_target_nacl_attrib_cit */
308 #define DEF_NACL_ATTRIB(name) \
309 static ssize_t iscsi_nacl_attrib_show_##name( \
310 struct se_node_acl *se_nacl, \
311 char *page) \
313 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
314 se_node_acl); \
316 return sprintf(page, "%u\n", ISCSI_NODE_ATTRIB(nacl)->name); \
319 static ssize_t iscsi_nacl_attrib_store_##name( \
320 struct se_node_acl *se_nacl, \
321 const char *page, \
322 size_t count) \
324 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
325 se_node_acl); \
326 char *endptr; \
327 u32 val; \
328 int ret; \
330 val = simple_strtoul(page, &endptr, 0); \
331 ret = iscsit_na_##name(nacl, val); \
332 if (ret < 0) \
333 return ret; \
335 return count; \
338 #define NACL_ATTR(_name, _mode) TF_NACL_ATTRIB_ATTR(iscsi, _name, _mode);
340 * Define iscsi_node_attrib_s_dataout_timeout
342 DEF_NACL_ATTRIB(dataout_timeout);
343 NACL_ATTR(dataout_timeout, S_IRUGO | S_IWUSR);
345 * Define iscsi_node_attrib_s_dataout_timeout_retries
347 DEF_NACL_ATTRIB(dataout_timeout_retries);
348 NACL_ATTR(dataout_timeout_retries, S_IRUGO | S_IWUSR);
350 * Define iscsi_node_attrib_s_default_erl
352 DEF_NACL_ATTRIB(default_erl);
353 NACL_ATTR(default_erl, S_IRUGO | S_IWUSR);
355 * Define iscsi_node_attrib_s_nopin_timeout
357 DEF_NACL_ATTRIB(nopin_timeout);
358 NACL_ATTR(nopin_timeout, S_IRUGO | S_IWUSR);
360 * Define iscsi_node_attrib_s_nopin_response_timeout
362 DEF_NACL_ATTRIB(nopin_response_timeout);
363 NACL_ATTR(nopin_response_timeout, S_IRUGO | S_IWUSR);
365 * Define iscsi_node_attrib_s_random_datain_pdu_offsets
367 DEF_NACL_ATTRIB(random_datain_pdu_offsets);
368 NACL_ATTR(random_datain_pdu_offsets, S_IRUGO | S_IWUSR);
370 * Define iscsi_node_attrib_s_random_datain_seq_offsets
372 DEF_NACL_ATTRIB(random_datain_seq_offsets);
373 NACL_ATTR(random_datain_seq_offsets, S_IRUGO | S_IWUSR);
375 * Define iscsi_node_attrib_s_random_r2t_offsets
377 DEF_NACL_ATTRIB(random_r2t_offsets);
378 NACL_ATTR(random_r2t_offsets, S_IRUGO | S_IWUSR);
380 static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
381 &iscsi_nacl_attrib_dataout_timeout.attr,
382 &iscsi_nacl_attrib_dataout_timeout_retries.attr,
383 &iscsi_nacl_attrib_default_erl.attr,
384 &iscsi_nacl_attrib_nopin_timeout.attr,
385 &iscsi_nacl_attrib_nopin_response_timeout.attr,
386 &iscsi_nacl_attrib_random_datain_pdu_offsets.attr,
387 &iscsi_nacl_attrib_random_datain_seq_offsets.attr,
388 &iscsi_nacl_attrib_random_r2t_offsets.attr,
389 NULL,
392 /* End items for lio_target_nacl_attrib_cit */
394 /* Start items for lio_target_nacl_auth_cit */
396 #define __DEF_NACL_AUTH_STR(prefix, name, flags) \
397 static ssize_t __iscsi_##prefix##_show_##name( \
398 struct iscsi_node_acl *nacl, \
399 char *page) \
401 struct iscsi_node_auth *auth = &nacl->node_auth; \
403 if (!capable(CAP_SYS_ADMIN)) \
404 return -EPERM; \
405 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
408 static ssize_t __iscsi_##prefix##_store_##name( \
409 struct iscsi_node_acl *nacl, \
410 const char *page, \
411 size_t count) \
413 struct iscsi_node_auth *auth = &nacl->node_auth; \
415 if (!capable(CAP_SYS_ADMIN)) \
416 return -EPERM; \
418 snprintf(auth->name, PAGE_SIZE, "%s", page); \
419 if (!strncmp("NULL", auth->name, 4)) \
420 auth->naf_flags &= ~flags; \
421 else \
422 auth->naf_flags |= flags; \
424 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
425 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
426 auth->authenticate_target = 1; \
427 else \
428 auth->authenticate_target = 0; \
430 return count; \
433 #define __DEF_NACL_AUTH_INT(prefix, name) \
434 static ssize_t __iscsi_##prefix##_show_##name( \
435 struct iscsi_node_acl *nacl, \
436 char *page) \
438 struct iscsi_node_auth *auth = &nacl->node_auth; \
440 if (!capable(CAP_SYS_ADMIN)) \
441 return -EPERM; \
443 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
446 #define DEF_NACL_AUTH_STR(name, flags) \
447 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
448 static ssize_t iscsi_nacl_auth_show_##name( \
449 struct se_node_acl *nacl, \
450 char *page) \
452 return __iscsi_nacl_auth_show_##name(container_of(nacl, \
453 struct iscsi_node_acl, se_node_acl), page); \
455 static ssize_t iscsi_nacl_auth_store_##name( \
456 struct se_node_acl *nacl, \
457 const char *page, \
458 size_t count) \
460 return __iscsi_nacl_auth_store_##name(container_of(nacl, \
461 struct iscsi_node_acl, se_node_acl), page, count); \
464 #define DEF_NACL_AUTH_INT(name) \
465 __DEF_NACL_AUTH_INT(nacl_auth, name) \
466 static ssize_t iscsi_nacl_auth_show_##name( \
467 struct se_node_acl *nacl, \
468 char *page) \
470 return __iscsi_nacl_auth_show_##name(container_of(nacl, \
471 struct iscsi_node_acl, se_node_acl), page); \
474 #define AUTH_ATTR(_name, _mode) TF_NACL_AUTH_ATTR(iscsi, _name, _mode);
475 #define AUTH_ATTR_RO(_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name);
478 * One-way authentication userid
480 DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
481 AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
483 * One-way authentication password
485 DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
486 AUTH_ATTR(password, S_IRUGO | S_IWUSR);
488 * Enforce mutual authentication
490 DEF_NACL_AUTH_INT(authenticate_target);
491 AUTH_ATTR_RO(authenticate_target);
493 * Mutual authentication userid
495 DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
496 AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
498 * Mutual authentication password
500 DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
501 AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
503 static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
504 &iscsi_nacl_auth_userid.attr,
505 &iscsi_nacl_auth_password.attr,
506 &iscsi_nacl_auth_authenticate_target.attr,
507 &iscsi_nacl_auth_userid_mutual.attr,
508 &iscsi_nacl_auth_password_mutual.attr,
509 NULL,
512 /* End items for lio_target_nacl_auth_cit */
514 /* Start items for lio_target_nacl_param_cit */
516 #define DEF_NACL_PARAM(name) \
517 static ssize_t iscsi_nacl_param_show_##name( \
518 struct se_node_acl *se_nacl, \
519 char *page) \
521 struct iscsi_session *sess; \
522 struct se_session *se_sess; \
523 ssize_t rb; \
525 spin_lock_bh(&se_nacl->nacl_sess_lock); \
526 se_sess = se_nacl->nacl_sess; \
527 if (!se_sess) { \
528 rb = snprintf(page, PAGE_SIZE, \
529 "No Active iSCSI Session\n"); \
530 } else { \
531 sess = se_sess->fabric_sess_ptr; \
532 rb = snprintf(page, PAGE_SIZE, "%u\n", \
533 (u32)sess->sess_ops->name); \
535 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
537 return rb; \
540 #define NACL_PARAM_ATTR(_name) TF_NACL_PARAM_ATTR_RO(iscsi, _name);
542 DEF_NACL_PARAM(MaxConnections);
543 NACL_PARAM_ATTR(MaxConnections);
545 DEF_NACL_PARAM(InitialR2T);
546 NACL_PARAM_ATTR(InitialR2T);
548 DEF_NACL_PARAM(ImmediateData);
549 NACL_PARAM_ATTR(ImmediateData);
551 DEF_NACL_PARAM(MaxBurstLength);
552 NACL_PARAM_ATTR(MaxBurstLength);
554 DEF_NACL_PARAM(FirstBurstLength);
555 NACL_PARAM_ATTR(FirstBurstLength);
557 DEF_NACL_PARAM(DefaultTime2Wait);
558 NACL_PARAM_ATTR(DefaultTime2Wait);
560 DEF_NACL_PARAM(DefaultTime2Retain);
561 NACL_PARAM_ATTR(DefaultTime2Retain);
563 DEF_NACL_PARAM(MaxOutstandingR2T);
564 NACL_PARAM_ATTR(MaxOutstandingR2T);
566 DEF_NACL_PARAM(DataPDUInOrder);
567 NACL_PARAM_ATTR(DataPDUInOrder);
569 DEF_NACL_PARAM(DataSequenceInOrder);
570 NACL_PARAM_ATTR(DataSequenceInOrder);
572 DEF_NACL_PARAM(ErrorRecoveryLevel);
573 NACL_PARAM_ATTR(ErrorRecoveryLevel);
575 static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
576 &iscsi_nacl_param_MaxConnections.attr,
577 &iscsi_nacl_param_InitialR2T.attr,
578 &iscsi_nacl_param_ImmediateData.attr,
579 &iscsi_nacl_param_MaxBurstLength.attr,
580 &iscsi_nacl_param_FirstBurstLength.attr,
581 &iscsi_nacl_param_DefaultTime2Wait.attr,
582 &iscsi_nacl_param_DefaultTime2Retain.attr,
583 &iscsi_nacl_param_MaxOutstandingR2T.attr,
584 &iscsi_nacl_param_DataPDUInOrder.attr,
585 &iscsi_nacl_param_DataSequenceInOrder.attr,
586 &iscsi_nacl_param_ErrorRecoveryLevel.attr,
587 NULL,
590 /* End items for lio_target_nacl_param_cit */
592 /* Start items for lio_target_acl_cit */
594 static ssize_t lio_target_nacl_show_info(
595 struct se_node_acl *se_nacl,
596 char *page)
598 struct iscsi_session *sess;
599 struct iscsi_conn *conn;
600 struct se_session *se_sess;
601 ssize_t rb = 0;
603 spin_lock_bh(&se_nacl->nacl_sess_lock);
604 se_sess = se_nacl->nacl_sess;
605 if (!se_sess) {
606 rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
607 " Endpoint: %s\n", se_nacl->initiatorname);
608 } else {
609 sess = se_sess->fabric_sess_ptr;
611 if (sess->sess_ops->InitiatorName)
612 rb += sprintf(page+rb, "InitiatorName: %s\n",
613 sess->sess_ops->InitiatorName);
614 if (sess->sess_ops->InitiatorAlias)
615 rb += sprintf(page+rb, "InitiatorAlias: %s\n",
616 sess->sess_ops->InitiatorAlias);
618 rb += sprintf(page+rb, "LIO Session ID: %u "
619 "ISID: 0x%02x %02x %02x %02x %02x %02x "
620 "TSIH: %hu ", sess->sid,
621 sess->isid[0], sess->isid[1], sess->isid[2],
622 sess->isid[3], sess->isid[4], sess->isid[5],
623 sess->tsih);
624 rb += sprintf(page+rb, "SessionType: %s\n",
625 (sess->sess_ops->SessionType) ?
626 "Discovery" : "Normal");
627 rb += sprintf(page+rb, "Session State: ");
628 switch (sess->session_state) {
629 case TARG_SESS_STATE_FREE:
630 rb += sprintf(page+rb, "TARG_SESS_FREE\n");
631 break;
632 case TARG_SESS_STATE_ACTIVE:
633 rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
634 break;
635 case TARG_SESS_STATE_LOGGED_IN:
636 rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
637 break;
638 case TARG_SESS_STATE_FAILED:
639 rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
640 break;
641 case TARG_SESS_STATE_IN_CONTINUE:
642 rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
643 break;
644 default:
645 rb += sprintf(page+rb, "ERROR: Unknown Session"
646 " State!\n");
647 break;
650 rb += sprintf(page+rb, "---------------------[iSCSI Session"
651 " Values]-----------------------\n");
652 rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
653 " : MaxCmdSN : ITT : TTT\n");
654 rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
655 " 0x%08x 0x%08x\n",
656 sess->cmdsn_window,
657 (sess->max_cmd_sn - sess->exp_cmd_sn) + 1,
658 sess->exp_cmd_sn, sess->max_cmd_sn,
659 sess->init_task_tag, sess->targ_xfer_tag);
660 rb += sprintf(page+rb, "----------------------[iSCSI"
661 " Connections]-------------------------\n");
663 spin_lock(&sess->conn_lock);
664 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
665 rb += sprintf(page+rb, "CID: %hu Connection"
666 " State: ", conn->cid);
667 switch (conn->conn_state) {
668 case TARG_CONN_STATE_FREE:
669 rb += sprintf(page+rb,
670 "TARG_CONN_STATE_FREE\n");
671 break;
672 case TARG_CONN_STATE_XPT_UP:
673 rb += sprintf(page+rb,
674 "TARG_CONN_STATE_XPT_UP\n");
675 break;
676 case TARG_CONN_STATE_IN_LOGIN:
677 rb += sprintf(page+rb,
678 "TARG_CONN_STATE_IN_LOGIN\n");
679 break;
680 case TARG_CONN_STATE_LOGGED_IN:
681 rb += sprintf(page+rb,
682 "TARG_CONN_STATE_LOGGED_IN\n");
683 break;
684 case TARG_CONN_STATE_IN_LOGOUT:
685 rb += sprintf(page+rb,
686 "TARG_CONN_STATE_IN_LOGOUT\n");
687 break;
688 case TARG_CONN_STATE_LOGOUT_REQUESTED:
689 rb += sprintf(page+rb,
690 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
691 break;
692 case TARG_CONN_STATE_CLEANUP_WAIT:
693 rb += sprintf(page+rb,
694 "TARG_CONN_STATE_CLEANUP_WAIT\n");
695 break;
696 default:
697 rb += sprintf(page+rb,
698 "ERROR: Unknown Connection State!\n");
699 break;
702 rb += sprintf(page+rb, " Address %s %s", conn->login_ip,
703 (conn->network_transport == ISCSI_TCP) ?
704 "TCP" : "SCTP");
705 rb += sprintf(page+rb, " StatSN: 0x%08x\n",
706 conn->stat_sn);
708 spin_unlock(&sess->conn_lock);
710 spin_unlock_bh(&se_nacl->nacl_sess_lock);
712 return rb;
715 TF_NACL_BASE_ATTR_RO(lio_target, info);
717 static ssize_t lio_target_nacl_show_cmdsn_depth(
718 struct se_node_acl *se_nacl,
719 char *page)
721 return sprintf(page, "%u\n", se_nacl->queue_depth);
724 static ssize_t lio_target_nacl_store_cmdsn_depth(
725 struct se_node_acl *se_nacl,
726 const char *page,
727 size_t count)
729 struct se_portal_group *se_tpg = se_nacl->se_tpg;
730 struct iscsi_portal_group *tpg = container_of(se_tpg,
731 struct iscsi_portal_group, tpg_se_tpg);
732 struct config_item *acl_ci, *tpg_ci, *wwn_ci;
733 char *endptr;
734 u32 cmdsn_depth = 0;
735 int ret;
737 cmdsn_depth = simple_strtoul(page, &endptr, 0);
738 if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
739 pr_err("Passed cmdsn_depth: %u exceeds"
740 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
741 TA_DEFAULT_CMDSN_DEPTH_MAX);
742 return -EINVAL;
744 acl_ci = &se_nacl->acl_group.cg_item;
745 if (!acl_ci) {
746 pr_err("Unable to locatel acl_ci\n");
747 return -EINVAL;
749 tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
750 if (!tpg_ci) {
751 pr_err("Unable to locate tpg_ci\n");
752 return -EINVAL;
754 wwn_ci = &tpg_ci->ci_group->cg_item;
755 if (!wwn_ci) {
756 pr_err("Unable to locate config_item wwn_ci\n");
757 return -EINVAL;
760 if (iscsit_get_tpg(tpg) < 0)
761 return -EINVAL;
763 * iscsit_tpg_set_initiator_node_queue_depth() assumes force=1
765 ret = iscsit_tpg_set_initiator_node_queue_depth(tpg,
766 config_item_name(acl_ci), cmdsn_depth, 1);
768 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
769 "InitiatorName: %s\n", config_item_name(wwn_ci),
770 config_item_name(tpg_ci), cmdsn_depth,
771 config_item_name(acl_ci));
773 iscsit_put_tpg(tpg);
774 return (!ret) ? count : (ssize_t)ret;
777 TF_NACL_BASE_ATTR(lio_target, cmdsn_depth, S_IRUGO | S_IWUSR);
779 static struct configfs_attribute *lio_target_initiator_attrs[] = {
780 &lio_target_nacl_info.attr,
781 &lio_target_nacl_cmdsn_depth.attr,
782 NULL,
785 static struct se_node_acl *lio_tpg_alloc_fabric_acl(
786 struct se_portal_group *se_tpg)
788 struct iscsi_node_acl *acl;
790 acl = kzalloc(sizeof(struct iscsi_node_acl), GFP_KERNEL);
791 if (!acl) {
792 pr_err("Unable to allocate memory for struct iscsi_node_acl\n");
793 return NULL;
796 return &acl->se_node_acl;
799 static struct se_node_acl *lio_target_make_nodeacl(
800 struct se_portal_group *se_tpg,
801 struct config_group *group,
802 const char *name)
804 struct config_group *stats_cg;
805 struct iscsi_node_acl *acl;
806 struct se_node_acl *se_nacl_new, *se_nacl;
807 struct iscsi_portal_group *tpg = container_of(se_tpg,
808 struct iscsi_portal_group, tpg_se_tpg);
809 u32 cmdsn_depth;
811 se_nacl_new = lio_tpg_alloc_fabric_acl(se_tpg);
812 if (!se_nacl_new)
813 return ERR_PTR(-ENOMEM);
815 cmdsn_depth = ISCSI_TPG_ATTRIB(tpg)->default_cmdsn_depth;
817 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
818 * when converting a NdoeACL from demo mode -> explict
820 se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,
821 name, cmdsn_depth);
822 if (IS_ERR(se_nacl))
823 return se_nacl;
825 acl = container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
826 stats_cg = &se_nacl->acl_fabric_stat_group;
828 stats_cg->default_groups = kzalloc(sizeof(struct config_group) * 2,
829 GFP_KERNEL);
830 if (!stats_cg->default_groups) {
831 pr_err("Unable to allocate memory for"
832 " stats_cg->default_groups\n");
833 core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1);
834 kfree(acl);
835 return ERR_PTR(-ENOMEM);
838 stats_cg->default_groups[0] = &NODE_STAT_GRPS(acl)->iscsi_sess_stats_group;
839 stats_cg->default_groups[1] = NULL;
840 config_group_init_type_name(&NODE_STAT_GRPS(acl)->iscsi_sess_stats_group,
841 "iscsi_sess_stats", &iscsi_stat_sess_cit);
843 return se_nacl;
846 static void lio_target_drop_nodeacl(
847 struct se_node_acl *se_nacl)
849 struct se_portal_group *se_tpg = se_nacl->se_tpg;
850 struct iscsi_node_acl *acl = container_of(se_nacl,
851 struct iscsi_node_acl, se_node_acl);
852 struct config_item *df_item;
853 struct config_group *stats_cg;
854 int i;
856 stats_cg = &acl->se_node_acl.acl_fabric_stat_group;
857 for (i = 0; stats_cg->default_groups[i]; i++) {
858 df_item = &stats_cg->default_groups[i]->cg_item;
859 stats_cg->default_groups[i] = NULL;
860 config_item_put(df_item);
862 kfree(stats_cg->default_groups);
864 core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1);
865 kfree(acl);
868 /* End items for lio_target_acl_cit */
870 /* Start items for lio_target_tpg_attrib_cit */
872 #define DEF_TPG_ATTRIB(name) \
874 static ssize_t iscsi_tpg_attrib_show_##name( \
875 struct se_portal_group *se_tpg, \
876 char *page) \
878 struct iscsi_portal_group *tpg = container_of(se_tpg, \
879 struct iscsi_portal_group, tpg_se_tpg); \
880 ssize_t rb; \
882 if (iscsit_get_tpg(tpg) < 0) \
883 return -EINVAL; \
885 rb = sprintf(page, "%u\n", ISCSI_TPG_ATTRIB(tpg)->name); \
886 iscsit_put_tpg(tpg); \
887 return rb; \
890 static ssize_t iscsi_tpg_attrib_store_##name( \
891 struct se_portal_group *se_tpg, \
892 const char *page, \
893 size_t count) \
895 struct iscsi_portal_group *tpg = container_of(se_tpg, \
896 struct iscsi_portal_group, tpg_se_tpg); \
897 char *endptr; \
898 u32 val; \
899 int ret; \
901 if (iscsit_get_tpg(tpg) < 0) \
902 return -EINVAL; \
904 val = simple_strtoul(page, &endptr, 0); \
905 ret = iscsit_ta_##name(tpg, val); \
906 if (ret < 0) \
907 goto out; \
909 iscsit_put_tpg(tpg); \
910 return count; \
911 out: \
912 iscsit_put_tpg(tpg); \
913 return ret; \
916 #define TPG_ATTR(_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode);
919 * Define iscsi_tpg_attrib_s_authentication
921 DEF_TPG_ATTRIB(authentication);
922 TPG_ATTR(authentication, S_IRUGO | S_IWUSR);
924 * Define iscsi_tpg_attrib_s_login_timeout
926 DEF_TPG_ATTRIB(login_timeout);
927 TPG_ATTR(login_timeout, S_IRUGO | S_IWUSR);
929 * Define iscsi_tpg_attrib_s_netif_timeout
931 DEF_TPG_ATTRIB(netif_timeout);
932 TPG_ATTR(netif_timeout, S_IRUGO | S_IWUSR);
934 * Define iscsi_tpg_attrib_s_generate_node_acls
936 DEF_TPG_ATTRIB(generate_node_acls);
937 TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR);
939 * Define iscsi_tpg_attrib_s_default_cmdsn_depth
941 DEF_TPG_ATTRIB(default_cmdsn_depth);
942 TPG_ATTR(default_cmdsn_depth, S_IRUGO | S_IWUSR);
944 Define iscsi_tpg_attrib_s_cache_dynamic_acls
946 DEF_TPG_ATTRIB(cache_dynamic_acls);
947 TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR);
949 * Define iscsi_tpg_attrib_s_demo_mode_write_protect
951 DEF_TPG_ATTRIB(demo_mode_write_protect);
952 TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR);
954 * Define iscsi_tpg_attrib_s_prod_mode_write_protect
956 DEF_TPG_ATTRIB(prod_mode_write_protect);
957 TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR);
959 static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
960 &iscsi_tpg_attrib_authentication.attr,
961 &iscsi_tpg_attrib_login_timeout.attr,
962 &iscsi_tpg_attrib_netif_timeout.attr,
963 &iscsi_tpg_attrib_generate_node_acls.attr,
964 &iscsi_tpg_attrib_default_cmdsn_depth.attr,
965 &iscsi_tpg_attrib_cache_dynamic_acls.attr,
966 &iscsi_tpg_attrib_demo_mode_write_protect.attr,
967 &iscsi_tpg_attrib_prod_mode_write_protect.attr,
968 NULL,
971 /* End items for lio_target_tpg_attrib_cit */
973 /* Start items for lio_target_tpg_param_cit */
975 #define DEF_TPG_PARAM(name) \
976 static ssize_t iscsi_tpg_param_show_##name( \
977 struct se_portal_group *se_tpg, \
978 char *page) \
980 struct iscsi_portal_group *tpg = container_of(se_tpg, \
981 struct iscsi_portal_group, tpg_se_tpg); \
982 struct iscsi_param *param; \
983 ssize_t rb; \
985 if (iscsit_get_tpg(tpg) < 0) \
986 return -EINVAL; \
988 param = iscsi_find_param_from_key(__stringify(name), \
989 tpg->param_list); \
990 if (!param) { \
991 iscsit_put_tpg(tpg); \
992 return -EINVAL; \
994 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
996 iscsit_put_tpg(tpg); \
997 return rb; \
999 static ssize_t iscsi_tpg_param_store_##name( \
1000 struct se_portal_group *se_tpg, \
1001 const char *page, \
1002 size_t count) \
1004 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1005 struct iscsi_portal_group, tpg_se_tpg); \
1006 char *buf; \
1007 int ret; \
1009 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
1010 if (!buf) \
1011 return -ENOMEM; \
1012 snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
1013 buf[strlen(buf)-1] = '\0'; /* Kill newline */ \
1015 if (iscsit_get_tpg(tpg) < 0) { \
1016 kfree(buf); \
1017 return -EINVAL; \
1020 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
1021 if (ret < 0) \
1022 goto out; \
1024 kfree(buf); \
1025 iscsit_put_tpg(tpg); \
1026 return count; \
1027 out: \
1028 kfree(buf); \
1029 iscsit_put_tpg(tpg); \
1030 return -EINVAL; \
1033 #define TPG_PARAM_ATTR(_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode);
1035 DEF_TPG_PARAM(AuthMethod);
1036 TPG_PARAM_ATTR(AuthMethod, S_IRUGO | S_IWUSR);
1038 DEF_TPG_PARAM(HeaderDigest);
1039 TPG_PARAM_ATTR(HeaderDigest, S_IRUGO | S_IWUSR);
1041 DEF_TPG_PARAM(DataDigest);
1042 TPG_PARAM_ATTR(DataDigest, S_IRUGO | S_IWUSR);
1044 DEF_TPG_PARAM(MaxConnections);
1045 TPG_PARAM_ATTR(MaxConnections, S_IRUGO | S_IWUSR);
1047 DEF_TPG_PARAM(TargetAlias);
1048 TPG_PARAM_ATTR(TargetAlias, S_IRUGO | S_IWUSR);
1050 DEF_TPG_PARAM(InitialR2T);
1051 TPG_PARAM_ATTR(InitialR2T, S_IRUGO | S_IWUSR);
1053 DEF_TPG_PARAM(ImmediateData);
1054 TPG_PARAM_ATTR(ImmediateData, S_IRUGO | S_IWUSR);
1056 DEF_TPG_PARAM(MaxRecvDataSegmentLength);
1057 TPG_PARAM_ATTR(MaxRecvDataSegmentLength, S_IRUGO | S_IWUSR);
1059 DEF_TPG_PARAM(MaxBurstLength);
1060 TPG_PARAM_ATTR(MaxBurstLength, S_IRUGO | S_IWUSR);
1062 DEF_TPG_PARAM(FirstBurstLength);
1063 TPG_PARAM_ATTR(FirstBurstLength, S_IRUGO | S_IWUSR);
1065 DEF_TPG_PARAM(DefaultTime2Wait);
1066 TPG_PARAM_ATTR(DefaultTime2Wait, S_IRUGO | S_IWUSR);
1068 DEF_TPG_PARAM(DefaultTime2Retain);
1069 TPG_PARAM_ATTR(DefaultTime2Retain, S_IRUGO | S_IWUSR);
1071 DEF_TPG_PARAM(MaxOutstandingR2T);
1072 TPG_PARAM_ATTR(MaxOutstandingR2T, S_IRUGO | S_IWUSR);
1074 DEF_TPG_PARAM(DataPDUInOrder);
1075 TPG_PARAM_ATTR(DataPDUInOrder, S_IRUGO | S_IWUSR);
1077 DEF_TPG_PARAM(DataSequenceInOrder);
1078 TPG_PARAM_ATTR(DataSequenceInOrder, S_IRUGO | S_IWUSR);
1080 DEF_TPG_PARAM(ErrorRecoveryLevel);
1081 TPG_PARAM_ATTR(ErrorRecoveryLevel, S_IRUGO | S_IWUSR);
1083 DEF_TPG_PARAM(IFMarker);
1084 TPG_PARAM_ATTR(IFMarker, S_IRUGO | S_IWUSR);
1086 DEF_TPG_PARAM(OFMarker);
1087 TPG_PARAM_ATTR(OFMarker, S_IRUGO | S_IWUSR);
1089 DEF_TPG_PARAM(IFMarkInt);
1090 TPG_PARAM_ATTR(IFMarkInt, S_IRUGO | S_IWUSR);
1092 DEF_TPG_PARAM(OFMarkInt);
1093 TPG_PARAM_ATTR(OFMarkInt, S_IRUGO | S_IWUSR);
1095 static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
1096 &iscsi_tpg_param_AuthMethod.attr,
1097 &iscsi_tpg_param_HeaderDigest.attr,
1098 &iscsi_tpg_param_DataDigest.attr,
1099 &iscsi_tpg_param_MaxConnections.attr,
1100 &iscsi_tpg_param_TargetAlias.attr,
1101 &iscsi_tpg_param_InitialR2T.attr,
1102 &iscsi_tpg_param_ImmediateData.attr,
1103 &iscsi_tpg_param_MaxRecvDataSegmentLength.attr,
1104 &iscsi_tpg_param_MaxBurstLength.attr,
1105 &iscsi_tpg_param_FirstBurstLength.attr,
1106 &iscsi_tpg_param_DefaultTime2Wait.attr,
1107 &iscsi_tpg_param_DefaultTime2Retain.attr,
1108 &iscsi_tpg_param_MaxOutstandingR2T.attr,
1109 &iscsi_tpg_param_DataPDUInOrder.attr,
1110 &iscsi_tpg_param_DataSequenceInOrder.attr,
1111 &iscsi_tpg_param_ErrorRecoveryLevel.attr,
1112 &iscsi_tpg_param_IFMarker.attr,
1113 &iscsi_tpg_param_OFMarker.attr,
1114 &iscsi_tpg_param_IFMarkInt.attr,
1115 &iscsi_tpg_param_OFMarkInt.attr,
1116 NULL,
1119 /* End items for lio_target_tpg_param_cit */
1121 /* Start items for lio_target_tpg_cit */
1123 static ssize_t lio_target_tpg_show_enable(
1124 struct se_portal_group *se_tpg,
1125 char *page)
1127 struct iscsi_portal_group *tpg = container_of(se_tpg,
1128 struct iscsi_portal_group, tpg_se_tpg);
1129 ssize_t len;
1131 spin_lock(&tpg->tpg_state_lock);
1132 len = sprintf(page, "%d\n",
1133 (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1134 spin_unlock(&tpg->tpg_state_lock);
1136 return len;
1139 static ssize_t lio_target_tpg_store_enable(
1140 struct se_portal_group *se_tpg,
1141 const char *page,
1142 size_t count)
1144 struct iscsi_portal_group *tpg = container_of(se_tpg,
1145 struct iscsi_portal_group, tpg_se_tpg);
1146 char *endptr;
1147 u32 op;
1148 int ret = 0;
1150 op = simple_strtoul(page, &endptr, 0);
1151 if ((op != 1) && (op != 0)) {
1152 pr_err("Illegal value for tpg_enable: %u\n", op);
1153 return -EINVAL;
1156 ret = iscsit_get_tpg(tpg);
1157 if (ret < 0)
1158 return -EINVAL;
1160 if (op) {
1161 ret = iscsit_tpg_enable_portal_group(tpg);
1162 if (ret < 0)
1163 goto out;
1164 } else {
1166 * iscsit_tpg_disable_portal_group() assumes force=1
1168 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1169 if (ret < 0)
1170 goto out;
1173 iscsit_put_tpg(tpg);
1174 return count;
1175 out:
1176 iscsit_put_tpg(tpg);
1177 return -EINVAL;
1180 TF_TPG_BASE_ATTR(lio_target, enable, S_IRUGO | S_IWUSR);
1182 static struct configfs_attribute *lio_target_tpg_attrs[] = {
1183 &lio_target_tpg_enable.attr,
1184 NULL,
1187 /* End items for lio_target_tpg_cit */
1189 /* Start items for lio_target_tiqn_cit */
1191 struct se_portal_group *lio_target_tiqn_addtpg(
1192 struct se_wwn *wwn,
1193 struct config_group *group,
1194 const char *name)
1196 struct iscsi_portal_group *tpg;
1197 struct iscsi_tiqn *tiqn;
1198 char *tpgt_str, *end_ptr;
1199 int ret = 0;
1200 unsigned short int tpgt;
1202 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1204 * Only tpgt_# directory groups can be created below
1205 * target/iscsi/iqn.superturodiskarry/
1207 tpgt_str = strstr(name, "tpgt_");
1208 if (!tpgt_str) {
1209 pr_err("Unable to locate \"tpgt_#\" directory"
1210 " group\n");
1211 return NULL;
1213 tpgt_str += 5; /* Skip ahead of "tpgt_" */
1214 tpgt = (unsigned short int) simple_strtoul(tpgt_str, &end_ptr, 0);
1216 tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1217 if (!tpg)
1218 return NULL;
1220 ret = core_tpg_register(
1221 &lio_target_fabric_configfs->tf_ops,
1222 wwn, &tpg->tpg_se_tpg, tpg,
1223 TRANSPORT_TPG_TYPE_NORMAL);
1224 if (ret < 0)
1225 return NULL;
1227 ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1228 if (ret != 0)
1229 goto out;
1231 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1232 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1233 name);
1234 return &tpg->tpg_se_tpg;
1235 out:
1236 core_tpg_deregister(&tpg->tpg_se_tpg);
1237 kfree(tpg);
1238 return NULL;
1241 void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1243 struct iscsi_portal_group *tpg;
1244 struct iscsi_tiqn *tiqn;
1246 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1247 tiqn = tpg->tpg_tiqn;
1249 * iscsit_tpg_del_portal_group() assumes force=1
1251 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1252 iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1255 /* End items for lio_target_tiqn_cit */
1257 /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1259 static ssize_t lio_target_wwn_show_attr_lio_version(
1260 struct target_fabric_configfs *tf,
1261 char *page)
1263 return sprintf(page, "RisingTide Systems Linux-iSCSI Target "ISCSIT_VERSION"\n");
1266 TF_WWN_ATTR_RO(lio_target, lio_version);
1268 static struct configfs_attribute *lio_target_wwn_attrs[] = {
1269 &lio_target_wwn_lio_version.attr,
1270 NULL,
1273 struct se_wwn *lio_target_call_coreaddtiqn(
1274 struct target_fabric_configfs *tf,
1275 struct config_group *group,
1276 const char *name)
1278 struct config_group *stats_cg;
1279 struct iscsi_tiqn *tiqn;
1281 tiqn = iscsit_add_tiqn((unsigned char *)name);
1282 if (IS_ERR(tiqn))
1283 return ERR_CAST(tiqn);
1285 * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group.
1287 stats_cg = &tiqn->tiqn_wwn.fabric_stat_group;
1289 stats_cg->default_groups = kzalloc(sizeof(struct config_group) * 6,
1290 GFP_KERNEL);
1291 if (!stats_cg->default_groups) {
1292 pr_err("Unable to allocate memory for"
1293 " stats_cg->default_groups\n");
1294 iscsit_del_tiqn(tiqn);
1295 return ERR_PTR(-ENOMEM);
1298 stats_cg->default_groups[0] = &WWN_STAT_GRPS(tiqn)->iscsi_instance_group;
1299 stats_cg->default_groups[1] = &WWN_STAT_GRPS(tiqn)->iscsi_sess_err_group;
1300 stats_cg->default_groups[2] = &WWN_STAT_GRPS(tiqn)->iscsi_tgt_attr_group;
1301 stats_cg->default_groups[3] = &WWN_STAT_GRPS(tiqn)->iscsi_login_stats_group;
1302 stats_cg->default_groups[4] = &WWN_STAT_GRPS(tiqn)->iscsi_logout_stats_group;
1303 stats_cg->default_groups[5] = NULL;
1304 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_instance_group,
1305 "iscsi_instance", &iscsi_stat_instance_cit);
1306 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_sess_err_group,
1307 "iscsi_sess_err", &iscsi_stat_sess_err_cit);
1308 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_tgt_attr_group,
1309 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1310 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_login_stats_group,
1311 "iscsi_login_stats", &iscsi_stat_login_cit);
1312 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_logout_stats_group,
1313 "iscsi_logout_stats", &iscsi_stat_logout_cit);
1315 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1316 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1317 " %s\n", name);
1318 return &tiqn->tiqn_wwn;
1321 void lio_target_call_coredeltiqn(
1322 struct se_wwn *wwn)
1324 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1325 struct config_item *df_item;
1326 struct config_group *stats_cg;
1327 int i;
1329 stats_cg = &tiqn->tiqn_wwn.fabric_stat_group;
1330 for (i = 0; stats_cg->default_groups[i]; i++) {
1331 df_item = &stats_cg->default_groups[i]->cg_item;
1332 stats_cg->default_groups[i] = NULL;
1333 config_item_put(df_item);
1335 kfree(stats_cg->default_groups);
1337 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1338 tiqn->tiqn);
1339 iscsit_del_tiqn(tiqn);
1342 /* End LIO-Target TIQN struct contig_lio_target_cit */
1344 /* Start lio_target_discovery_auth_cit */
1346 #define DEF_DISC_AUTH_STR(name, flags) \
1347 __DEF_NACL_AUTH_STR(disc, name, flags) \
1348 static ssize_t iscsi_disc_show_##name( \
1349 struct target_fabric_configfs *tf, \
1350 char *page) \
1352 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \
1353 page); \
1355 static ssize_t iscsi_disc_store_##name( \
1356 struct target_fabric_configfs *tf, \
1357 const char *page, \
1358 size_t count) \
1360 return __iscsi_disc_store_##name(&iscsit_global->discovery_acl, \
1361 page, count); \
1364 #define DEF_DISC_AUTH_INT(name) \
1365 __DEF_NACL_AUTH_INT(disc, name) \
1366 static ssize_t iscsi_disc_show_##name( \
1367 struct target_fabric_configfs *tf, \
1368 char *page) \
1370 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \
1371 page); \
1374 #define DISC_AUTH_ATTR(_name, _mode) TF_DISC_ATTR(iscsi, _name, _mode)
1375 #define DISC_AUTH_ATTR_RO(_name) TF_DISC_ATTR_RO(iscsi, _name)
1378 * One-way authentication userid
1380 DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1381 DISC_AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
1383 * One-way authentication password
1385 DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1386 DISC_AUTH_ATTR(password, S_IRUGO | S_IWUSR);
1388 * Enforce mutual authentication
1390 DEF_DISC_AUTH_INT(authenticate_target);
1391 DISC_AUTH_ATTR_RO(authenticate_target);
1393 * Mutual authentication userid
1395 DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1396 DISC_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
1398 * Mutual authentication password
1400 DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1401 DISC_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
1404 * enforce_discovery_auth
1406 static ssize_t iscsi_disc_show_enforce_discovery_auth(
1407 struct target_fabric_configfs *tf,
1408 char *page)
1410 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1412 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1415 static ssize_t iscsi_disc_store_enforce_discovery_auth(
1416 struct target_fabric_configfs *tf,
1417 const char *page,
1418 size_t count)
1420 struct iscsi_param *param;
1421 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
1422 char *endptr;
1423 u32 op;
1425 op = simple_strtoul(page, &endptr, 0);
1426 if ((op != 1) && (op != 0)) {
1427 pr_err("Illegal value for enforce_discovery_auth:"
1428 " %u\n", op);
1429 return -EINVAL;
1432 if (!discovery_tpg) {
1433 pr_err("iscsit_global->discovery_tpg is NULL\n");
1434 return -EINVAL;
1437 param = iscsi_find_param_from_key(AUTHMETHOD,
1438 discovery_tpg->param_list);
1439 if (!param)
1440 return -EINVAL;
1442 if (op) {
1444 * Reset the AuthMethod key to CHAP.
1446 if (iscsi_update_param_value(param, CHAP) < 0)
1447 return -EINVAL;
1449 discovery_tpg->tpg_attrib.authentication = 1;
1450 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1451 pr_debug("LIO-CORE[0] Successfully enabled"
1452 " authentication enforcement for iSCSI"
1453 " Discovery TPG\n");
1454 } else {
1456 * Reset the AuthMethod key to CHAP,None
1458 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1459 return -EINVAL;
1461 discovery_tpg->tpg_attrib.authentication = 0;
1462 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1463 pr_debug("LIO-CORE[0] Successfully disabled"
1464 " authentication enforcement for iSCSI"
1465 " Discovery TPG\n");
1468 return count;
1471 DISC_AUTH_ATTR(enforce_discovery_auth, S_IRUGO | S_IWUSR);
1473 static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1474 &iscsi_disc_userid.attr,
1475 &iscsi_disc_password.attr,
1476 &iscsi_disc_authenticate_target.attr,
1477 &iscsi_disc_userid_mutual.attr,
1478 &iscsi_disc_password_mutual.attr,
1479 &iscsi_disc_enforce_discovery_auth.attr,
1480 NULL,
1483 /* End lio_target_discovery_auth_cit */
1485 /* Start functions for target_core_fabric_ops */
1487 static char *iscsi_get_fabric_name(void)
1489 return "iSCSI";
1492 static u32 iscsi_get_task_tag(struct se_cmd *se_cmd)
1494 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1496 return cmd->init_task_tag;
1499 static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1501 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1503 return cmd->i_state;
1506 static int iscsi_is_state_remove(struct se_cmd *se_cmd)
1508 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1510 return (cmd->i_state == ISTATE_REMOVE);
1513 static int lio_sess_logged_in(struct se_session *se_sess)
1515 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1516 int ret;
1518 * Called with spin_lock_bh(&tpg_lock); and
1519 * spin_lock(&se_tpg->session_lock); held.
1521 spin_lock(&sess->conn_lock);
1522 ret = (sess->session_state != TARG_SESS_STATE_LOGGED_IN);
1523 spin_unlock(&sess->conn_lock);
1525 return ret;
1528 static u32 lio_sess_get_index(struct se_session *se_sess)
1530 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1532 return sess->session_index;
1535 static u32 lio_sess_get_initiator_sid(
1536 struct se_session *se_sess,
1537 unsigned char *buf,
1538 u32 size)
1540 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1542 * iSCSI Initiator Session Identifier from RFC-3720.
1544 return snprintf(buf, size, "%02x%02x%02x%02x%02x%02x",
1545 sess->isid[0], sess->isid[1], sess->isid[2],
1546 sess->isid[3], sess->isid[4], sess->isid[5]);
1549 static int lio_queue_data_in(struct se_cmd *se_cmd)
1551 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1553 cmd->i_state = ISTATE_SEND_DATAIN;
1554 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1555 return 0;
1558 static int lio_write_pending(struct se_cmd *se_cmd)
1560 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1562 if (!cmd->immediate_data && !cmd->unsolicited_data)
1563 return iscsit_build_r2ts_for_cmd(cmd, cmd->conn, 1);
1565 return 0;
1568 static int lio_write_pending_status(struct se_cmd *se_cmd)
1570 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1571 int ret;
1573 spin_lock_bh(&cmd->istate_lock);
1574 ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1575 spin_unlock_bh(&cmd->istate_lock);
1577 return ret;
1580 static int lio_queue_status(struct se_cmd *se_cmd)
1582 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1584 cmd->i_state = ISTATE_SEND_STATUS;
1585 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1586 return 0;
1589 static u16 lio_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_length)
1591 unsigned char *buffer = se_cmd->sense_buffer;
1593 * From RFC-3720 10.4.7. Data Segment - Sense and Response Data Segment
1594 * 16-bit SenseLength.
1596 buffer[0] = ((sense_length >> 8) & 0xff);
1597 buffer[1] = (sense_length & 0xff);
1599 * Return two byte offset into allocated sense_buffer.
1601 return 2;
1604 static u16 lio_get_fabric_sense_len(void)
1607 * Return two byte offset into allocated sense_buffer.
1609 return 2;
1612 static int lio_queue_tm_rsp(struct se_cmd *se_cmd)
1614 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1616 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1617 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1618 return 0;
1621 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1623 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1625 return &tpg->tpg_tiqn->tiqn[0];
1628 static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1630 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1632 return tpg->tpgt;
1635 static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1637 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1639 return ISCSI_TPG_ATTRIB(tpg)->default_cmdsn_depth;
1642 static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1644 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1646 return ISCSI_TPG_ATTRIB(tpg)->generate_node_acls;
1649 static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1651 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1653 return ISCSI_TPG_ATTRIB(tpg)->cache_dynamic_acls;
1656 static int lio_tpg_check_demo_mode_write_protect(
1657 struct se_portal_group *se_tpg)
1659 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1661 return ISCSI_TPG_ATTRIB(tpg)->demo_mode_write_protect;
1664 static int lio_tpg_check_prod_mode_write_protect(
1665 struct se_portal_group *se_tpg)
1667 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1669 return ISCSI_TPG_ATTRIB(tpg)->prod_mode_write_protect;
1672 static void lio_tpg_release_fabric_acl(
1673 struct se_portal_group *se_tpg,
1674 struct se_node_acl *se_acl)
1676 struct iscsi_node_acl *acl = container_of(se_acl,
1677 struct iscsi_node_acl, se_node_acl);
1678 kfree(acl);
1682 * Called with spin_lock_bh(struct se_portal_group->session_lock) held..
1684 * Also, this function calls iscsit_inc_session_usage_count() on the
1685 * struct iscsi_session in question.
1687 static int lio_tpg_shutdown_session(struct se_session *se_sess)
1689 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1691 spin_lock(&sess->conn_lock);
1692 if (atomic_read(&sess->session_fall_back_to_erl0) ||
1693 atomic_read(&sess->session_logout) ||
1694 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1695 spin_unlock(&sess->conn_lock);
1696 return 0;
1698 atomic_set(&sess->session_reinstatement, 1);
1699 spin_unlock(&sess->conn_lock);
1701 iscsit_inc_session_usage_count(sess);
1702 iscsit_stop_time2retain_timer(sess);
1704 return 1;
1708 * Calls iscsit_dec_session_usage_count() as inverse of
1709 * lio_tpg_shutdown_session()
1711 static void lio_tpg_close_session(struct se_session *se_sess)
1713 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1715 * If the iSCSI Session for the iSCSI Initiator Node exists,
1716 * forcefully shutdown the iSCSI NEXUS.
1718 iscsit_stop_session(sess, 1, 1);
1719 iscsit_dec_session_usage_count(sess);
1720 iscsit_close_session(sess);
1723 static void lio_tpg_stop_session(
1724 struct se_session *se_sess,
1725 int sess_sleep,
1726 int conn_sleep)
1728 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1730 iscsit_stop_session(sess, sess_sleep, conn_sleep);
1733 static void lio_tpg_fall_back_to_erl0(struct se_session *se_sess)
1735 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1737 iscsit_fall_back_to_erl0(sess);
1740 static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1742 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1744 return tpg->tpg_tiqn->tiqn_index;
1747 static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1749 struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1750 se_node_acl);
1752 ISCSI_NODE_ATTRIB(acl)->nacl = acl;
1753 iscsit_set_default_node_attribues(acl);
1756 static void lio_release_cmd(struct se_cmd *se_cmd)
1758 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1760 iscsit_release_cmd(cmd);
1763 /* End functions for target_core_fabric_ops */
1765 int iscsi_target_register_configfs(void)
1767 struct target_fabric_configfs *fabric;
1768 int ret;
1770 lio_target_fabric_configfs = NULL;
1771 fabric = target_fabric_configfs_init(THIS_MODULE, "iscsi");
1772 if (IS_ERR(fabric)) {
1773 pr_err("target_fabric_configfs_init() for"
1774 " LIO-Target failed!\n");
1775 return PTR_ERR(fabric);
1778 * Setup the fabric API of function pointers used by target_core_mod..
1780 fabric->tf_ops.get_fabric_name = &iscsi_get_fabric_name;
1781 fabric->tf_ops.get_fabric_proto_ident = &iscsi_get_fabric_proto_ident;
1782 fabric->tf_ops.tpg_get_wwn = &lio_tpg_get_endpoint_wwn;
1783 fabric->tf_ops.tpg_get_tag = &lio_tpg_get_tag;
1784 fabric->tf_ops.tpg_get_default_depth = &lio_tpg_get_default_depth;
1785 fabric->tf_ops.tpg_get_pr_transport_id = &iscsi_get_pr_transport_id;
1786 fabric->tf_ops.tpg_get_pr_transport_id_len =
1787 &iscsi_get_pr_transport_id_len;
1788 fabric->tf_ops.tpg_parse_pr_out_transport_id =
1789 &iscsi_parse_pr_out_transport_id;
1790 fabric->tf_ops.tpg_check_demo_mode = &lio_tpg_check_demo_mode;
1791 fabric->tf_ops.tpg_check_demo_mode_cache =
1792 &lio_tpg_check_demo_mode_cache;
1793 fabric->tf_ops.tpg_check_demo_mode_write_protect =
1794 &lio_tpg_check_demo_mode_write_protect;
1795 fabric->tf_ops.tpg_check_prod_mode_write_protect =
1796 &lio_tpg_check_prod_mode_write_protect;
1797 fabric->tf_ops.tpg_alloc_fabric_acl = &lio_tpg_alloc_fabric_acl;
1798 fabric->tf_ops.tpg_release_fabric_acl = &lio_tpg_release_fabric_acl;
1799 fabric->tf_ops.tpg_get_inst_index = &lio_tpg_get_inst_index;
1800 fabric->tf_ops.release_cmd = &lio_release_cmd;
1801 fabric->tf_ops.shutdown_session = &lio_tpg_shutdown_session;
1802 fabric->tf_ops.close_session = &lio_tpg_close_session;
1803 fabric->tf_ops.stop_session = &lio_tpg_stop_session;
1804 fabric->tf_ops.fall_back_to_erl0 = &lio_tpg_fall_back_to_erl0;
1805 fabric->tf_ops.sess_logged_in = &lio_sess_logged_in;
1806 fabric->tf_ops.sess_get_index = &lio_sess_get_index;
1807 fabric->tf_ops.sess_get_initiator_sid = &lio_sess_get_initiator_sid;
1808 fabric->tf_ops.write_pending = &lio_write_pending;
1809 fabric->tf_ops.write_pending_status = &lio_write_pending_status;
1810 fabric->tf_ops.set_default_node_attributes =
1811 &lio_set_default_node_attributes;
1812 fabric->tf_ops.get_task_tag = &iscsi_get_task_tag;
1813 fabric->tf_ops.get_cmd_state = &iscsi_get_cmd_state;
1814 fabric->tf_ops.queue_data_in = &lio_queue_data_in;
1815 fabric->tf_ops.queue_status = &lio_queue_status;
1816 fabric->tf_ops.queue_tm_rsp = &lio_queue_tm_rsp;
1817 fabric->tf_ops.set_fabric_sense_len = &lio_set_fabric_sense_len;
1818 fabric->tf_ops.get_fabric_sense_len = &lio_get_fabric_sense_len;
1819 fabric->tf_ops.is_state_remove = &iscsi_is_state_remove;
1821 * Setup function pointers for generic logic in target_core_fabric_configfs.c
1823 fabric->tf_ops.fabric_make_wwn = &lio_target_call_coreaddtiqn;
1824 fabric->tf_ops.fabric_drop_wwn = &lio_target_call_coredeltiqn;
1825 fabric->tf_ops.fabric_make_tpg = &lio_target_tiqn_addtpg;
1826 fabric->tf_ops.fabric_drop_tpg = &lio_target_tiqn_deltpg;
1827 fabric->tf_ops.fabric_post_link = NULL;
1828 fabric->tf_ops.fabric_pre_unlink = NULL;
1829 fabric->tf_ops.fabric_make_np = &lio_target_call_addnptotpg;
1830 fabric->tf_ops.fabric_drop_np = &lio_target_call_delnpfromtpg;
1831 fabric->tf_ops.fabric_make_nodeacl = &lio_target_make_nodeacl;
1832 fabric->tf_ops.fabric_drop_nodeacl = &lio_target_drop_nodeacl;
1834 * Setup default attribute lists for various fabric->tf_cit_tmpl
1835 * sturct config_item_type's
1837 TF_CIT_TMPL(fabric)->tfc_discovery_cit.ct_attrs = lio_target_discovery_auth_attrs;
1838 TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = lio_target_wwn_attrs;
1839 TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = lio_target_tpg_attrs;
1840 TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = lio_target_tpg_attrib_attrs;
1841 TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = lio_target_tpg_param_attrs;
1842 TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = lio_target_portal_attrs;
1843 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs = lio_target_initiator_attrs;
1844 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = lio_target_nacl_attrib_attrs;
1845 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = lio_target_nacl_auth_attrs;
1846 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_param_cit.ct_attrs = lio_target_nacl_param_attrs;
1848 ret = target_fabric_configfs_register(fabric);
1849 if (ret < 0) {
1850 pr_err("target_fabric_configfs_register() for"
1851 " LIO-Target failed!\n");
1852 target_fabric_configfs_free(fabric);
1853 return ret;
1856 lio_target_fabric_configfs = fabric;
1857 pr_debug("LIO_TARGET[0] - Set fabric ->"
1858 " lio_target_fabric_configfs\n");
1859 return 0;
1863 void iscsi_target_deregister_configfs(void)
1865 if (!lio_target_fabric_configfs)
1866 return;
1868 * Shutdown discovery sessions and disable discovery TPG
1870 if (iscsit_global->discovery_tpg)
1871 iscsit_tpg_disable_portal_group(iscsit_global->discovery_tpg, 1);
1873 target_fabric_configfs_deregister(lio_target_fabric_configfs);
1874 lio_target_fabric_configfs = NULL;
1875 pr_debug("LIO_TARGET[0] - Cleared"
1876 " lio_target_fabric_configfs\n");