gro: Allow tunnel stacking in the case of FOU/GUE
[linux/fpc-iii.git] / drivers / target / iscsi / iscsi_target_configfs.c
blob83bb55b944348a4991c5ef27b01175bb66b92d64
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/target_core_fabric_configfs.h>
27 #include <target/target_core_configfs.h>
28 #include <target/configfs_macros.h>
29 #include <target/iscsi/iscsi_transport.h>
31 #include <target/iscsi/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 <target/iscsi/iscsi_target_stat.h>
41 struct lio_target_configfs_attribute {
42 struct configfs_attribute attr;
43 ssize_t (*show)(void *, char *);
44 ssize_t (*store)(void *, const char *, size_t);
47 /* Start items for lio_target_portal_cit */
49 static ssize_t lio_target_np_show_sctp(
50 struct se_tpg_np *se_tpg_np,
51 char *page)
53 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
54 struct iscsi_tpg_np, se_tpg_np);
55 struct iscsi_tpg_np *tpg_np_sctp;
56 ssize_t rb;
58 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
59 if (tpg_np_sctp)
60 rb = sprintf(page, "1\n");
61 else
62 rb = sprintf(page, "0\n");
64 return rb;
67 static ssize_t lio_target_np_store_sctp(
68 struct se_tpg_np *se_tpg_np,
69 const char *page,
70 size_t count)
72 struct iscsi_np *np;
73 struct iscsi_portal_group *tpg;
74 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
75 struct iscsi_tpg_np, se_tpg_np);
76 struct iscsi_tpg_np *tpg_np_sctp = NULL;
77 u32 op;
78 int ret;
80 ret = kstrtou32(page, 0, &op);
81 if (ret)
82 return ret;
83 if ((op != 1) && (op != 0)) {
84 pr_err("Illegal value for tpg_enable: %u\n", op);
85 return -EINVAL;
87 np = tpg_np->tpg_np;
88 if (!np) {
89 pr_err("Unable to locate struct iscsi_np from"
90 " struct iscsi_tpg_np\n");
91 return -EINVAL;
94 tpg = tpg_np->tpg;
95 if (iscsit_get_tpg(tpg) < 0)
96 return -EINVAL;
98 if (op) {
100 * Use existing np->np_sockaddr for SCTP network portal reference
102 tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
103 tpg_np, ISCSI_SCTP_TCP);
104 if (!tpg_np_sctp || IS_ERR(tpg_np_sctp))
105 goto out;
106 } else {
107 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
108 if (!tpg_np_sctp)
109 goto out;
111 ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp);
112 if (ret < 0)
113 goto out;
116 iscsit_put_tpg(tpg);
117 return count;
118 out:
119 iscsit_put_tpg(tpg);
120 return -EINVAL;
123 TF_NP_BASE_ATTR(lio_target, sctp, S_IRUGO | S_IWUSR);
125 static ssize_t lio_target_np_show_iser(
126 struct se_tpg_np *se_tpg_np,
127 char *page)
129 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
130 struct iscsi_tpg_np, se_tpg_np);
131 struct iscsi_tpg_np *tpg_np_iser;
132 ssize_t rb;
134 tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
135 if (tpg_np_iser)
136 rb = sprintf(page, "1\n");
137 else
138 rb = sprintf(page, "0\n");
140 return rb;
143 static ssize_t lio_target_np_store_iser(
144 struct se_tpg_np *se_tpg_np,
145 const char *page,
146 size_t count)
148 struct iscsi_np *np;
149 struct iscsi_portal_group *tpg;
150 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
151 struct iscsi_tpg_np, se_tpg_np);
152 struct iscsi_tpg_np *tpg_np_iser = NULL;
153 char *endptr;
154 u32 op;
155 int rc = 0;
157 op = simple_strtoul(page, &endptr, 0);
158 if ((op != 1) && (op != 0)) {
159 pr_err("Illegal value for tpg_enable: %u\n", op);
160 return -EINVAL;
162 np = tpg_np->tpg_np;
163 if (!np) {
164 pr_err("Unable to locate struct iscsi_np from"
165 " struct iscsi_tpg_np\n");
166 return -EINVAL;
169 tpg = tpg_np->tpg;
170 if (iscsit_get_tpg(tpg) < 0)
171 return -EINVAL;
173 if (op) {
174 rc = request_module("ib_isert");
175 if (rc != 0) {
176 pr_warn("Unable to request_module for ib_isert\n");
177 rc = 0;
180 tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
181 tpg_np, ISCSI_INFINIBAND);
182 if (IS_ERR(tpg_np_iser)) {
183 rc = PTR_ERR(tpg_np_iser);
184 goto out;
186 } else {
187 tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
188 if (tpg_np_iser) {
189 rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser);
190 if (rc < 0)
191 goto out;
195 iscsit_put_tpg(tpg);
196 return count;
197 out:
198 iscsit_put_tpg(tpg);
199 return rc;
202 TF_NP_BASE_ATTR(lio_target, iser, S_IRUGO | S_IWUSR);
204 static struct configfs_attribute *lio_target_portal_attrs[] = {
205 &lio_target_np_sctp.attr,
206 &lio_target_np_iser.attr,
207 NULL,
210 /* Stop items for lio_target_portal_cit */
212 /* Start items for lio_target_np_cit */
214 #define MAX_PORTAL_LEN 256
216 static struct se_tpg_np *lio_target_call_addnptotpg(
217 struct se_portal_group *se_tpg,
218 struct config_group *group,
219 const char *name)
221 struct iscsi_portal_group *tpg;
222 struct iscsi_tpg_np *tpg_np;
223 char *str, *str2, *ip_str, *port_str;
224 struct __kernel_sockaddr_storage sockaddr;
225 struct sockaddr_in *sock_in;
226 struct sockaddr_in6 *sock_in6;
227 unsigned long port;
228 int ret;
229 char buf[MAX_PORTAL_LEN + 1];
231 if (strlen(name) > MAX_PORTAL_LEN) {
232 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
233 (int)strlen(name), MAX_PORTAL_LEN);
234 return ERR_PTR(-EOVERFLOW);
236 memset(buf, 0, MAX_PORTAL_LEN + 1);
237 snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
239 memset(&sockaddr, 0, sizeof(struct __kernel_sockaddr_storage));
241 str = strstr(buf, "[");
242 if (str) {
243 const char *end;
245 str2 = strstr(str, "]");
246 if (!str2) {
247 pr_err("Unable to locate trailing \"]\""
248 " in IPv6 iSCSI network portal address\n");
249 return ERR_PTR(-EINVAL);
251 str++; /* Skip over leading "[" */
252 *str2 = '\0'; /* Terminate the unbracketed IPv6 address */
253 str2++; /* Skip over the \0 */
254 port_str = strstr(str2, ":");
255 if (!port_str) {
256 pr_err("Unable to locate \":port\""
257 " in IPv6 iSCSI network portal address\n");
258 return ERR_PTR(-EINVAL);
260 *port_str = '\0'; /* Terminate string for IP */
261 port_str++; /* Skip over ":" */
263 ret = kstrtoul(port_str, 0, &port);
264 if (ret < 0) {
265 pr_err("kstrtoul() failed for port_str: %d\n", ret);
266 return ERR_PTR(ret);
268 sock_in6 = (struct sockaddr_in6 *)&sockaddr;
269 sock_in6->sin6_family = AF_INET6;
270 sock_in6->sin6_port = htons((unsigned short)port);
271 ret = in6_pton(str, IPV6_ADDRESS_SPACE,
272 (void *)&sock_in6->sin6_addr.in6_u, -1, &end);
273 if (ret <= 0) {
274 pr_err("in6_pton returned: %d\n", ret);
275 return ERR_PTR(-EINVAL);
277 } else {
278 str = ip_str = &buf[0];
279 port_str = strstr(ip_str, ":");
280 if (!port_str) {
281 pr_err("Unable to locate \":port\""
282 " in IPv4 iSCSI network portal address\n");
283 return ERR_PTR(-EINVAL);
285 *port_str = '\0'; /* Terminate string for IP */
286 port_str++; /* Skip over ":" */
288 ret = kstrtoul(port_str, 0, &port);
289 if (ret < 0) {
290 pr_err("kstrtoul() failed for port_str: %d\n", ret);
291 return ERR_PTR(ret);
293 sock_in = (struct sockaddr_in *)&sockaddr;
294 sock_in->sin_family = AF_INET;
295 sock_in->sin_port = htons((unsigned short)port);
296 sock_in->sin_addr.s_addr = in_aton(ip_str);
298 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
299 ret = iscsit_get_tpg(tpg);
300 if (ret < 0)
301 return ERR_PTR(-EINVAL);
303 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
304 " PORTAL: %s\n",
305 config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
306 tpg->tpgt, name);
308 * Assume ISCSI_TCP by default. Other network portals for other
309 * iSCSI fabrics:
311 * Traditional iSCSI over SCTP (initial support)
312 * iSER/TCP (TODO, hardware available)
313 * iSER/SCTP (TODO, software emulation with osc-iwarp)
314 * iSER/IB (TODO, hardware available)
316 * can be enabled with attributes under
317 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
320 tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
321 ISCSI_TCP);
322 if (IS_ERR(tpg_np)) {
323 iscsit_put_tpg(tpg);
324 return ERR_CAST(tpg_np);
326 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
328 iscsit_put_tpg(tpg);
329 return &tpg_np->se_tpg_np;
332 static void lio_target_call_delnpfromtpg(
333 struct se_tpg_np *se_tpg_np)
335 struct iscsi_portal_group *tpg;
336 struct iscsi_tpg_np *tpg_np;
337 struct se_portal_group *se_tpg;
338 int ret;
340 tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
341 tpg = tpg_np->tpg;
342 ret = iscsit_get_tpg(tpg);
343 if (ret < 0)
344 return;
346 se_tpg = &tpg->tpg_se_tpg;
347 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
348 " PORTAL: %pISc:%hu\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
349 tpg->tpgt, &tpg_np->tpg_np->np_sockaddr, tpg_np->tpg_np->np_port);
351 ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
352 if (ret < 0)
353 goto out;
355 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
356 out:
357 iscsit_put_tpg(tpg);
360 /* End items for lio_target_np_cit */
362 /* Start items for lio_target_nacl_attrib_cit */
364 #define DEF_NACL_ATTRIB(name) \
365 static ssize_t iscsi_nacl_attrib_show_##name( \
366 struct se_node_acl *se_nacl, \
367 char *page) \
369 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
370 se_node_acl); \
372 return sprintf(page, "%u\n", nacl->node_attrib.name); \
375 static ssize_t iscsi_nacl_attrib_store_##name( \
376 struct se_node_acl *se_nacl, \
377 const char *page, \
378 size_t count) \
380 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
381 se_node_acl); \
382 u32 val; \
383 int ret; \
385 ret = kstrtou32(page, 0, &val); \
386 if (ret) \
387 return ret; \
388 ret = iscsit_na_##name(nacl, val); \
389 if (ret < 0) \
390 return ret; \
392 return count; \
395 #define NACL_ATTR(_name, _mode) TF_NACL_ATTRIB_ATTR(iscsi, _name, _mode);
397 * Define iscsi_node_attrib_s_dataout_timeout
399 DEF_NACL_ATTRIB(dataout_timeout);
400 NACL_ATTR(dataout_timeout, S_IRUGO | S_IWUSR);
402 * Define iscsi_node_attrib_s_dataout_timeout_retries
404 DEF_NACL_ATTRIB(dataout_timeout_retries);
405 NACL_ATTR(dataout_timeout_retries, S_IRUGO | S_IWUSR);
407 * Define iscsi_node_attrib_s_default_erl
409 DEF_NACL_ATTRIB(default_erl);
410 NACL_ATTR(default_erl, S_IRUGO | S_IWUSR);
412 * Define iscsi_node_attrib_s_nopin_timeout
414 DEF_NACL_ATTRIB(nopin_timeout);
415 NACL_ATTR(nopin_timeout, S_IRUGO | S_IWUSR);
417 * Define iscsi_node_attrib_s_nopin_response_timeout
419 DEF_NACL_ATTRIB(nopin_response_timeout);
420 NACL_ATTR(nopin_response_timeout, S_IRUGO | S_IWUSR);
422 * Define iscsi_node_attrib_s_random_datain_pdu_offsets
424 DEF_NACL_ATTRIB(random_datain_pdu_offsets);
425 NACL_ATTR(random_datain_pdu_offsets, S_IRUGO | S_IWUSR);
427 * Define iscsi_node_attrib_s_random_datain_seq_offsets
429 DEF_NACL_ATTRIB(random_datain_seq_offsets);
430 NACL_ATTR(random_datain_seq_offsets, S_IRUGO | S_IWUSR);
432 * Define iscsi_node_attrib_s_random_r2t_offsets
434 DEF_NACL_ATTRIB(random_r2t_offsets);
435 NACL_ATTR(random_r2t_offsets, S_IRUGO | S_IWUSR);
437 static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
438 &iscsi_nacl_attrib_dataout_timeout.attr,
439 &iscsi_nacl_attrib_dataout_timeout_retries.attr,
440 &iscsi_nacl_attrib_default_erl.attr,
441 &iscsi_nacl_attrib_nopin_timeout.attr,
442 &iscsi_nacl_attrib_nopin_response_timeout.attr,
443 &iscsi_nacl_attrib_random_datain_pdu_offsets.attr,
444 &iscsi_nacl_attrib_random_datain_seq_offsets.attr,
445 &iscsi_nacl_attrib_random_r2t_offsets.attr,
446 NULL,
449 /* End items for lio_target_nacl_attrib_cit */
451 /* Start items for lio_target_nacl_auth_cit */
453 #define __DEF_NACL_AUTH_STR(prefix, name, flags) \
454 static ssize_t __iscsi_##prefix##_show_##name( \
455 struct iscsi_node_acl *nacl, \
456 char *page) \
458 struct iscsi_node_auth *auth = &nacl->node_auth; \
460 if (!capable(CAP_SYS_ADMIN)) \
461 return -EPERM; \
462 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
465 static ssize_t __iscsi_##prefix##_store_##name( \
466 struct iscsi_node_acl *nacl, \
467 const char *page, \
468 size_t count) \
470 struct iscsi_node_auth *auth = &nacl->node_auth; \
472 if (!capable(CAP_SYS_ADMIN)) \
473 return -EPERM; \
474 if (count >= sizeof(auth->name)) \
475 return -EINVAL; \
476 snprintf(auth->name, sizeof(auth->name), "%s", page); \
477 if (!strncmp("NULL", auth->name, 4)) \
478 auth->naf_flags &= ~flags; \
479 else \
480 auth->naf_flags |= flags; \
482 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
483 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
484 auth->authenticate_target = 1; \
485 else \
486 auth->authenticate_target = 0; \
488 return count; \
491 #define __DEF_NACL_AUTH_INT(prefix, name) \
492 static ssize_t __iscsi_##prefix##_show_##name( \
493 struct iscsi_node_acl *nacl, \
494 char *page) \
496 struct iscsi_node_auth *auth = &nacl->node_auth; \
498 if (!capable(CAP_SYS_ADMIN)) \
499 return -EPERM; \
501 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
504 #define DEF_NACL_AUTH_STR(name, flags) \
505 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
506 static ssize_t iscsi_nacl_auth_show_##name( \
507 struct se_node_acl *nacl, \
508 char *page) \
510 return __iscsi_nacl_auth_show_##name(container_of(nacl, \
511 struct iscsi_node_acl, se_node_acl), page); \
513 static ssize_t iscsi_nacl_auth_store_##name( \
514 struct se_node_acl *nacl, \
515 const char *page, \
516 size_t count) \
518 return __iscsi_nacl_auth_store_##name(container_of(nacl, \
519 struct iscsi_node_acl, se_node_acl), page, count); \
522 #define DEF_NACL_AUTH_INT(name) \
523 __DEF_NACL_AUTH_INT(nacl_auth, name) \
524 static ssize_t iscsi_nacl_auth_show_##name( \
525 struct se_node_acl *nacl, \
526 char *page) \
528 return __iscsi_nacl_auth_show_##name(container_of(nacl, \
529 struct iscsi_node_acl, se_node_acl), page); \
532 #define AUTH_ATTR(_name, _mode) TF_NACL_AUTH_ATTR(iscsi, _name, _mode);
533 #define AUTH_ATTR_RO(_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name);
536 * One-way authentication userid
538 DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
539 AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
541 * One-way authentication password
543 DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
544 AUTH_ATTR(password, S_IRUGO | S_IWUSR);
546 * Enforce mutual authentication
548 DEF_NACL_AUTH_INT(authenticate_target);
549 AUTH_ATTR_RO(authenticate_target);
551 * Mutual authentication userid
553 DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
554 AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
556 * Mutual authentication password
558 DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
559 AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
561 static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
562 &iscsi_nacl_auth_userid.attr,
563 &iscsi_nacl_auth_password.attr,
564 &iscsi_nacl_auth_authenticate_target.attr,
565 &iscsi_nacl_auth_userid_mutual.attr,
566 &iscsi_nacl_auth_password_mutual.attr,
567 NULL,
570 /* End items for lio_target_nacl_auth_cit */
572 /* Start items for lio_target_nacl_param_cit */
574 #define DEF_NACL_PARAM(name) \
575 static ssize_t iscsi_nacl_param_show_##name( \
576 struct se_node_acl *se_nacl, \
577 char *page) \
579 struct iscsi_session *sess; \
580 struct se_session *se_sess; \
581 ssize_t rb; \
583 spin_lock_bh(&se_nacl->nacl_sess_lock); \
584 se_sess = se_nacl->nacl_sess; \
585 if (!se_sess) { \
586 rb = snprintf(page, PAGE_SIZE, \
587 "No Active iSCSI Session\n"); \
588 } else { \
589 sess = se_sess->fabric_sess_ptr; \
590 rb = snprintf(page, PAGE_SIZE, "%u\n", \
591 (u32)sess->sess_ops->name); \
593 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
595 return rb; \
598 #define NACL_PARAM_ATTR(_name) TF_NACL_PARAM_ATTR_RO(iscsi, _name);
600 DEF_NACL_PARAM(MaxConnections);
601 NACL_PARAM_ATTR(MaxConnections);
603 DEF_NACL_PARAM(InitialR2T);
604 NACL_PARAM_ATTR(InitialR2T);
606 DEF_NACL_PARAM(ImmediateData);
607 NACL_PARAM_ATTR(ImmediateData);
609 DEF_NACL_PARAM(MaxBurstLength);
610 NACL_PARAM_ATTR(MaxBurstLength);
612 DEF_NACL_PARAM(FirstBurstLength);
613 NACL_PARAM_ATTR(FirstBurstLength);
615 DEF_NACL_PARAM(DefaultTime2Wait);
616 NACL_PARAM_ATTR(DefaultTime2Wait);
618 DEF_NACL_PARAM(DefaultTime2Retain);
619 NACL_PARAM_ATTR(DefaultTime2Retain);
621 DEF_NACL_PARAM(MaxOutstandingR2T);
622 NACL_PARAM_ATTR(MaxOutstandingR2T);
624 DEF_NACL_PARAM(DataPDUInOrder);
625 NACL_PARAM_ATTR(DataPDUInOrder);
627 DEF_NACL_PARAM(DataSequenceInOrder);
628 NACL_PARAM_ATTR(DataSequenceInOrder);
630 DEF_NACL_PARAM(ErrorRecoveryLevel);
631 NACL_PARAM_ATTR(ErrorRecoveryLevel);
633 static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
634 &iscsi_nacl_param_MaxConnections.attr,
635 &iscsi_nacl_param_InitialR2T.attr,
636 &iscsi_nacl_param_ImmediateData.attr,
637 &iscsi_nacl_param_MaxBurstLength.attr,
638 &iscsi_nacl_param_FirstBurstLength.attr,
639 &iscsi_nacl_param_DefaultTime2Wait.attr,
640 &iscsi_nacl_param_DefaultTime2Retain.attr,
641 &iscsi_nacl_param_MaxOutstandingR2T.attr,
642 &iscsi_nacl_param_DataPDUInOrder.attr,
643 &iscsi_nacl_param_DataSequenceInOrder.attr,
644 &iscsi_nacl_param_ErrorRecoveryLevel.attr,
645 NULL,
648 /* End items for lio_target_nacl_param_cit */
650 /* Start items for lio_target_acl_cit */
652 static ssize_t lio_target_nacl_show_info(
653 struct se_node_acl *se_nacl,
654 char *page)
656 struct iscsi_session *sess;
657 struct iscsi_conn *conn;
658 struct se_session *se_sess;
659 ssize_t rb = 0;
661 spin_lock_bh(&se_nacl->nacl_sess_lock);
662 se_sess = se_nacl->nacl_sess;
663 if (!se_sess) {
664 rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
665 " Endpoint: %s\n", se_nacl->initiatorname);
666 } else {
667 sess = se_sess->fabric_sess_ptr;
669 rb += sprintf(page+rb, "InitiatorName: %s\n",
670 sess->sess_ops->InitiatorName);
671 rb += sprintf(page+rb, "InitiatorAlias: %s\n",
672 sess->sess_ops->InitiatorAlias);
674 rb += sprintf(page+rb,
675 "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ",
676 sess->sid, sess->isid, sess->tsih);
677 rb += sprintf(page+rb, "SessionType: %s\n",
678 (sess->sess_ops->SessionType) ?
679 "Discovery" : "Normal");
680 rb += sprintf(page+rb, "Session State: ");
681 switch (sess->session_state) {
682 case TARG_SESS_STATE_FREE:
683 rb += sprintf(page+rb, "TARG_SESS_FREE\n");
684 break;
685 case TARG_SESS_STATE_ACTIVE:
686 rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
687 break;
688 case TARG_SESS_STATE_LOGGED_IN:
689 rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
690 break;
691 case TARG_SESS_STATE_FAILED:
692 rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
693 break;
694 case TARG_SESS_STATE_IN_CONTINUE:
695 rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
696 break;
697 default:
698 rb += sprintf(page+rb, "ERROR: Unknown Session"
699 " State!\n");
700 break;
703 rb += sprintf(page+rb, "---------------------[iSCSI Session"
704 " Values]-----------------------\n");
705 rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN"
706 " : MaxCmdSN : ITT : TTT\n");
707 rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x"
708 " 0x%08x 0x%08x\n",
709 sess->cmdsn_window,
710 (sess->max_cmd_sn - sess->exp_cmd_sn) + 1,
711 sess->exp_cmd_sn, sess->max_cmd_sn,
712 sess->init_task_tag, sess->targ_xfer_tag);
713 rb += sprintf(page+rb, "----------------------[iSCSI"
714 " Connections]-------------------------\n");
716 spin_lock(&sess->conn_lock);
717 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
718 rb += sprintf(page+rb, "CID: %hu Connection"
719 " State: ", conn->cid);
720 switch (conn->conn_state) {
721 case TARG_CONN_STATE_FREE:
722 rb += sprintf(page+rb,
723 "TARG_CONN_STATE_FREE\n");
724 break;
725 case TARG_CONN_STATE_XPT_UP:
726 rb += sprintf(page+rb,
727 "TARG_CONN_STATE_XPT_UP\n");
728 break;
729 case TARG_CONN_STATE_IN_LOGIN:
730 rb += sprintf(page+rb,
731 "TARG_CONN_STATE_IN_LOGIN\n");
732 break;
733 case TARG_CONN_STATE_LOGGED_IN:
734 rb += sprintf(page+rb,
735 "TARG_CONN_STATE_LOGGED_IN\n");
736 break;
737 case TARG_CONN_STATE_IN_LOGOUT:
738 rb += sprintf(page+rb,
739 "TARG_CONN_STATE_IN_LOGOUT\n");
740 break;
741 case TARG_CONN_STATE_LOGOUT_REQUESTED:
742 rb += sprintf(page+rb,
743 "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
744 break;
745 case TARG_CONN_STATE_CLEANUP_WAIT:
746 rb += sprintf(page+rb,
747 "TARG_CONN_STATE_CLEANUP_WAIT\n");
748 break;
749 default:
750 rb += sprintf(page+rb,
751 "ERROR: Unknown Connection State!\n");
752 break;
755 rb += sprintf(page+rb, " Address %s %s", conn->login_ip,
756 (conn->network_transport == ISCSI_TCP) ?
757 "TCP" : "SCTP");
758 rb += sprintf(page+rb, " StatSN: 0x%08x\n",
759 conn->stat_sn);
761 spin_unlock(&sess->conn_lock);
763 spin_unlock_bh(&se_nacl->nacl_sess_lock);
765 return rb;
768 TF_NACL_BASE_ATTR_RO(lio_target, info);
770 static ssize_t lio_target_nacl_show_cmdsn_depth(
771 struct se_node_acl *se_nacl,
772 char *page)
774 return sprintf(page, "%u\n", se_nacl->queue_depth);
777 static ssize_t lio_target_nacl_store_cmdsn_depth(
778 struct se_node_acl *se_nacl,
779 const char *page,
780 size_t count)
782 struct se_portal_group *se_tpg = se_nacl->se_tpg;
783 struct iscsi_portal_group *tpg = container_of(se_tpg,
784 struct iscsi_portal_group, tpg_se_tpg);
785 struct config_item *acl_ci, *tpg_ci, *wwn_ci;
786 u32 cmdsn_depth = 0;
787 int ret;
789 ret = kstrtou32(page, 0, &cmdsn_depth);
790 if (ret)
791 return ret;
792 if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
793 pr_err("Passed cmdsn_depth: %u exceeds"
794 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
795 TA_DEFAULT_CMDSN_DEPTH_MAX);
796 return -EINVAL;
798 acl_ci = &se_nacl->acl_group.cg_item;
799 if (!acl_ci) {
800 pr_err("Unable to locatel acl_ci\n");
801 return -EINVAL;
803 tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
804 if (!tpg_ci) {
805 pr_err("Unable to locate tpg_ci\n");
806 return -EINVAL;
808 wwn_ci = &tpg_ci->ci_group->cg_item;
809 if (!wwn_ci) {
810 pr_err("Unable to locate config_item wwn_ci\n");
811 return -EINVAL;
814 if (iscsit_get_tpg(tpg) < 0)
815 return -EINVAL;
817 * iscsit_tpg_set_initiator_node_queue_depth() assumes force=1
819 ret = iscsit_tpg_set_initiator_node_queue_depth(tpg,
820 config_item_name(acl_ci), cmdsn_depth, 1);
822 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
823 "InitiatorName: %s\n", config_item_name(wwn_ci),
824 config_item_name(tpg_ci), cmdsn_depth,
825 config_item_name(acl_ci));
827 iscsit_put_tpg(tpg);
828 return (!ret) ? count : (ssize_t)ret;
831 TF_NACL_BASE_ATTR(lio_target, cmdsn_depth, S_IRUGO | S_IWUSR);
833 static ssize_t lio_target_nacl_show_tag(
834 struct se_node_acl *se_nacl,
835 char *page)
837 return snprintf(page, PAGE_SIZE, "%s", se_nacl->acl_tag);
840 static ssize_t lio_target_nacl_store_tag(
841 struct se_node_acl *se_nacl,
842 const char *page,
843 size_t count)
845 int ret;
847 ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
849 if (ret < 0)
850 return ret;
851 return count;
854 TF_NACL_BASE_ATTR(lio_target, tag, S_IRUGO | S_IWUSR);
856 static struct configfs_attribute *lio_target_initiator_attrs[] = {
857 &lio_target_nacl_info.attr,
858 &lio_target_nacl_cmdsn_depth.attr,
859 &lio_target_nacl_tag.attr,
860 NULL,
863 static struct se_node_acl *lio_tpg_alloc_fabric_acl(
864 struct se_portal_group *se_tpg)
866 struct iscsi_node_acl *acl;
868 acl = kzalloc(sizeof(struct iscsi_node_acl), GFP_KERNEL);
869 if (!acl) {
870 pr_err("Unable to allocate memory for struct iscsi_node_acl\n");
871 return NULL;
874 return &acl->se_node_acl;
877 static struct se_node_acl *lio_target_make_nodeacl(
878 struct se_portal_group *se_tpg,
879 struct config_group *group,
880 const char *name)
882 struct config_group *stats_cg;
883 struct iscsi_node_acl *acl;
884 struct se_node_acl *se_nacl_new, *se_nacl;
885 struct iscsi_portal_group *tpg = container_of(se_tpg,
886 struct iscsi_portal_group, tpg_se_tpg);
887 u32 cmdsn_depth;
889 se_nacl_new = lio_tpg_alloc_fabric_acl(se_tpg);
890 if (!se_nacl_new)
891 return ERR_PTR(-ENOMEM);
893 cmdsn_depth = tpg->tpg_attrib.default_cmdsn_depth;
895 * se_nacl_new may be released by core_tpg_add_initiator_node_acl()
896 * when converting a NdoeACL from demo mode -> explict
898 se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,
899 name, cmdsn_depth);
900 if (IS_ERR(se_nacl))
901 return se_nacl;
903 acl = container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
904 stats_cg = &se_nacl->acl_fabric_stat_group;
906 stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2,
907 GFP_KERNEL);
908 if (!stats_cg->default_groups) {
909 pr_err("Unable to allocate memory for"
910 " stats_cg->default_groups\n");
911 core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1);
912 kfree(acl);
913 return ERR_PTR(-ENOMEM);
916 stats_cg->default_groups[0] = &acl->node_stat_grps.iscsi_sess_stats_group;
917 stats_cg->default_groups[1] = NULL;
918 config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
919 "iscsi_sess_stats", &iscsi_stat_sess_cit);
921 return se_nacl;
924 static void lio_target_drop_nodeacl(
925 struct se_node_acl *se_nacl)
927 struct se_portal_group *se_tpg = se_nacl->se_tpg;
928 struct iscsi_node_acl *acl = container_of(se_nacl,
929 struct iscsi_node_acl, se_node_acl);
930 struct config_item *df_item;
931 struct config_group *stats_cg;
932 int i;
934 stats_cg = &acl->se_node_acl.acl_fabric_stat_group;
935 for (i = 0; stats_cg->default_groups[i]; i++) {
936 df_item = &stats_cg->default_groups[i]->cg_item;
937 stats_cg->default_groups[i] = NULL;
938 config_item_put(df_item);
940 kfree(stats_cg->default_groups);
942 core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1);
943 kfree(acl);
946 /* End items for lio_target_acl_cit */
948 /* Start items for lio_target_tpg_attrib_cit */
950 #define DEF_TPG_ATTRIB(name) \
952 static ssize_t iscsi_tpg_attrib_show_##name( \
953 struct se_portal_group *se_tpg, \
954 char *page) \
956 struct iscsi_portal_group *tpg = container_of(se_tpg, \
957 struct iscsi_portal_group, tpg_se_tpg); \
958 ssize_t rb; \
960 if (iscsit_get_tpg(tpg) < 0) \
961 return -EINVAL; \
963 rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \
964 iscsit_put_tpg(tpg); \
965 return rb; \
968 static ssize_t iscsi_tpg_attrib_store_##name( \
969 struct se_portal_group *se_tpg, \
970 const char *page, \
971 size_t count) \
973 struct iscsi_portal_group *tpg = container_of(se_tpg, \
974 struct iscsi_portal_group, tpg_se_tpg); \
975 u32 val; \
976 int ret; \
978 if (iscsit_get_tpg(tpg) < 0) \
979 return -EINVAL; \
981 ret = kstrtou32(page, 0, &val); \
982 if (ret) \
983 goto out; \
984 ret = iscsit_ta_##name(tpg, val); \
985 if (ret < 0) \
986 goto out; \
988 iscsit_put_tpg(tpg); \
989 return count; \
990 out: \
991 iscsit_put_tpg(tpg); \
992 return ret; \
995 #define TPG_ATTR(_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode);
998 * Define iscsi_tpg_attrib_s_authentication
1000 DEF_TPG_ATTRIB(authentication);
1001 TPG_ATTR(authentication, S_IRUGO | S_IWUSR);
1003 * Define iscsi_tpg_attrib_s_login_timeout
1005 DEF_TPG_ATTRIB(login_timeout);
1006 TPG_ATTR(login_timeout, S_IRUGO | S_IWUSR);
1008 * Define iscsi_tpg_attrib_s_netif_timeout
1010 DEF_TPG_ATTRIB(netif_timeout);
1011 TPG_ATTR(netif_timeout, S_IRUGO | S_IWUSR);
1013 * Define iscsi_tpg_attrib_s_generate_node_acls
1015 DEF_TPG_ATTRIB(generate_node_acls);
1016 TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR);
1018 * Define iscsi_tpg_attrib_s_default_cmdsn_depth
1020 DEF_TPG_ATTRIB(default_cmdsn_depth);
1021 TPG_ATTR(default_cmdsn_depth, S_IRUGO | S_IWUSR);
1023 Define iscsi_tpg_attrib_s_cache_dynamic_acls
1025 DEF_TPG_ATTRIB(cache_dynamic_acls);
1026 TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR);
1028 * Define iscsi_tpg_attrib_s_demo_mode_write_protect
1030 DEF_TPG_ATTRIB(demo_mode_write_protect);
1031 TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR);
1033 * Define iscsi_tpg_attrib_s_prod_mode_write_protect
1035 DEF_TPG_ATTRIB(prod_mode_write_protect);
1036 TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR);
1038 * Define iscsi_tpg_attrib_s_demo_mode_discovery,
1040 DEF_TPG_ATTRIB(demo_mode_discovery);
1041 TPG_ATTR(demo_mode_discovery, S_IRUGO | S_IWUSR);
1043 * Define iscsi_tpg_attrib_s_default_erl
1045 DEF_TPG_ATTRIB(default_erl);
1046 TPG_ATTR(default_erl, S_IRUGO | S_IWUSR);
1048 * Define iscsi_tpg_attrib_s_t10_pi
1050 DEF_TPG_ATTRIB(t10_pi);
1051 TPG_ATTR(t10_pi, S_IRUGO | S_IWUSR);
1053 * Define iscsi_tpg_attrib_s_fabric_prot_type
1055 DEF_TPG_ATTRIB(fabric_prot_type);
1056 TPG_ATTR(fabric_prot_type, S_IRUGO | S_IWUSR);
1058 static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
1059 &iscsi_tpg_attrib_authentication.attr,
1060 &iscsi_tpg_attrib_login_timeout.attr,
1061 &iscsi_tpg_attrib_netif_timeout.attr,
1062 &iscsi_tpg_attrib_generate_node_acls.attr,
1063 &iscsi_tpg_attrib_default_cmdsn_depth.attr,
1064 &iscsi_tpg_attrib_cache_dynamic_acls.attr,
1065 &iscsi_tpg_attrib_demo_mode_write_protect.attr,
1066 &iscsi_tpg_attrib_prod_mode_write_protect.attr,
1067 &iscsi_tpg_attrib_demo_mode_discovery.attr,
1068 &iscsi_tpg_attrib_default_erl.attr,
1069 &iscsi_tpg_attrib_t10_pi.attr,
1070 &iscsi_tpg_attrib_fabric_prot_type.attr,
1071 NULL,
1074 /* End items for lio_target_tpg_attrib_cit */
1076 /* Start items for lio_target_tpg_auth_cit */
1078 #define __DEF_TPG_AUTH_STR(prefix, name, flags) \
1079 static ssize_t __iscsi_##prefix##_show_##name( \
1080 struct se_portal_group *se_tpg, \
1081 char *page) \
1083 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1084 struct iscsi_portal_group, tpg_se_tpg); \
1085 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
1087 if (!capable(CAP_SYS_ADMIN)) \
1088 return -EPERM; \
1090 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
1093 static ssize_t __iscsi_##prefix##_store_##name( \
1094 struct se_portal_group *se_tpg, \
1095 const char *page, \
1096 size_t count) \
1098 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1099 struct iscsi_portal_group, tpg_se_tpg); \
1100 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
1102 if (!capable(CAP_SYS_ADMIN)) \
1103 return -EPERM; \
1105 snprintf(auth->name, sizeof(auth->name), "%s", page); \
1106 if (!(strncmp("NULL", auth->name, 4))) \
1107 auth->naf_flags &= ~flags; \
1108 else \
1109 auth->naf_flags |= flags; \
1111 if ((auth->naf_flags & NAF_USERID_IN_SET) && \
1112 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \
1113 auth->authenticate_target = 1; \
1114 else \
1115 auth->authenticate_target = 0; \
1117 return count; \
1120 #define __DEF_TPG_AUTH_INT(prefix, name) \
1121 static ssize_t __iscsi_##prefix##_show_##name( \
1122 struct se_portal_group *se_tpg, \
1123 char *page) \
1125 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1126 struct iscsi_portal_group, tpg_se_tpg); \
1127 struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \
1129 if (!capable(CAP_SYS_ADMIN)) \
1130 return -EPERM; \
1132 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
1135 #define DEF_TPG_AUTH_STR(name, flags) \
1136 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
1137 static ssize_t iscsi_tpg_auth_show_##name( \
1138 struct se_portal_group *se_tpg, \
1139 char *page) \
1141 return __iscsi_tpg_auth_show_##name(se_tpg, page); \
1144 static ssize_t iscsi_tpg_auth_store_##name( \
1145 struct se_portal_group *se_tpg, \
1146 const char *page, \
1147 size_t count) \
1149 return __iscsi_tpg_auth_store_##name(se_tpg, page, count); \
1152 #define DEF_TPG_AUTH_INT(name) \
1153 __DEF_TPG_AUTH_INT(tpg_auth, name) \
1154 static ssize_t iscsi_tpg_auth_show_##name( \
1155 struct se_portal_group *se_tpg, \
1156 char *page) \
1158 return __iscsi_tpg_auth_show_##name(se_tpg, page); \
1161 #define TPG_AUTH_ATTR(_name, _mode) TF_TPG_AUTH_ATTR(iscsi, _name, _mode);
1162 #define TPG_AUTH_ATTR_RO(_name) TF_TPG_AUTH_ATTR_RO(iscsi, _name);
1165 * * One-way authentication userid
1166 * */
1167 DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
1168 TPG_AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
1170 * * One-way authentication password
1171 * */
1172 DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
1173 TPG_AUTH_ATTR(password, S_IRUGO | S_IWUSR);
1175 * * Enforce mutual authentication
1176 * */
1177 DEF_TPG_AUTH_INT(authenticate_target);
1178 TPG_AUTH_ATTR_RO(authenticate_target);
1180 * * Mutual authentication userid
1181 * */
1182 DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1183 TPG_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
1185 * * Mutual authentication password
1186 * */
1187 DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1188 TPG_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
1190 static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
1191 &iscsi_tpg_auth_userid.attr,
1192 &iscsi_tpg_auth_password.attr,
1193 &iscsi_tpg_auth_authenticate_target.attr,
1194 &iscsi_tpg_auth_userid_mutual.attr,
1195 &iscsi_tpg_auth_password_mutual.attr,
1196 NULL,
1199 /* End items for lio_target_tpg_auth_cit */
1201 /* Start items for lio_target_tpg_param_cit */
1203 #define DEF_TPG_PARAM(name) \
1204 static ssize_t iscsi_tpg_param_show_##name( \
1205 struct se_portal_group *se_tpg, \
1206 char *page) \
1208 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1209 struct iscsi_portal_group, tpg_se_tpg); \
1210 struct iscsi_param *param; \
1211 ssize_t rb; \
1213 if (iscsit_get_tpg(tpg) < 0) \
1214 return -EINVAL; \
1216 param = iscsi_find_param_from_key(__stringify(name), \
1217 tpg->param_list); \
1218 if (!param) { \
1219 iscsit_put_tpg(tpg); \
1220 return -EINVAL; \
1222 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \
1224 iscsit_put_tpg(tpg); \
1225 return rb; \
1227 static ssize_t iscsi_tpg_param_store_##name( \
1228 struct se_portal_group *se_tpg, \
1229 const char *page, \
1230 size_t count) \
1232 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1233 struct iscsi_portal_group, tpg_se_tpg); \
1234 char *buf; \
1235 int ret, len; \
1237 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \
1238 if (!buf) \
1239 return -ENOMEM; \
1240 len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \
1241 if (isspace(buf[len-1])) \
1242 buf[len-1] = '\0'; /* Kill newline */ \
1244 if (iscsit_get_tpg(tpg) < 0) { \
1245 kfree(buf); \
1246 return -EINVAL; \
1249 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \
1250 if (ret < 0) \
1251 goto out; \
1253 kfree(buf); \
1254 iscsit_put_tpg(tpg); \
1255 return count; \
1256 out: \
1257 kfree(buf); \
1258 iscsit_put_tpg(tpg); \
1259 return -EINVAL; \
1262 #define TPG_PARAM_ATTR(_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode);
1264 DEF_TPG_PARAM(AuthMethod);
1265 TPG_PARAM_ATTR(AuthMethod, S_IRUGO | S_IWUSR);
1267 DEF_TPG_PARAM(HeaderDigest);
1268 TPG_PARAM_ATTR(HeaderDigest, S_IRUGO | S_IWUSR);
1270 DEF_TPG_PARAM(DataDigest);
1271 TPG_PARAM_ATTR(DataDigest, S_IRUGO | S_IWUSR);
1273 DEF_TPG_PARAM(MaxConnections);
1274 TPG_PARAM_ATTR(MaxConnections, S_IRUGO | S_IWUSR);
1276 DEF_TPG_PARAM(TargetAlias);
1277 TPG_PARAM_ATTR(TargetAlias, S_IRUGO | S_IWUSR);
1279 DEF_TPG_PARAM(InitialR2T);
1280 TPG_PARAM_ATTR(InitialR2T, S_IRUGO | S_IWUSR);
1282 DEF_TPG_PARAM(ImmediateData);
1283 TPG_PARAM_ATTR(ImmediateData, S_IRUGO | S_IWUSR);
1285 DEF_TPG_PARAM(MaxRecvDataSegmentLength);
1286 TPG_PARAM_ATTR(MaxRecvDataSegmentLength, S_IRUGO | S_IWUSR);
1288 DEF_TPG_PARAM(MaxXmitDataSegmentLength);
1289 TPG_PARAM_ATTR(MaxXmitDataSegmentLength, S_IRUGO | S_IWUSR);
1291 DEF_TPG_PARAM(MaxBurstLength);
1292 TPG_PARAM_ATTR(MaxBurstLength, S_IRUGO | S_IWUSR);
1294 DEF_TPG_PARAM(FirstBurstLength);
1295 TPG_PARAM_ATTR(FirstBurstLength, S_IRUGO | S_IWUSR);
1297 DEF_TPG_PARAM(DefaultTime2Wait);
1298 TPG_PARAM_ATTR(DefaultTime2Wait, S_IRUGO | S_IWUSR);
1300 DEF_TPG_PARAM(DefaultTime2Retain);
1301 TPG_PARAM_ATTR(DefaultTime2Retain, S_IRUGO | S_IWUSR);
1303 DEF_TPG_PARAM(MaxOutstandingR2T);
1304 TPG_PARAM_ATTR(MaxOutstandingR2T, S_IRUGO | S_IWUSR);
1306 DEF_TPG_PARAM(DataPDUInOrder);
1307 TPG_PARAM_ATTR(DataPDUInOrder, S_IRUGO | S_IWUSR);
1309 DEF_TPG_PARAM(DataSequenceInOrder);
1310 TPG_PARAM_ATTR(DataSequenceInOrder, S_IRUGO | S_IWUSR);
1312 DEF_TPG_PARAM(ErrorRecoveryLevel);
1313 TPG_PARAM_ATTR(ErrorRecoveryLevel, S_IRUGO | S_IWUSR);
1315 DEF_TPG_PARAM(IFMarker);
1316 TPG_PARAM_ATTR(IFMarker, S_IRUGO | S_IWUSR);
1318 DEF_TPG_PARAM(OFMarker);
1319 TPG_PARAM_ATTR(OFMarker, S_IRUGO | S_IWUSR);
1321 DEF_TPG_PARAM(IFMarkInt);
1322 TPG_PARAM_ATTR(IFMarkInt, S_IRUGO | S_IWUSR);
1324 DEF_TPG_PARAM(OFMarkInt);
1325 TPG_PARAM_ATTR(OFMarkInt, S_IRUGO | S_IWUSR);
1327 static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
1328 &iscsi_tpg_param_AuthMethod.attr,
1329 &iscsi_tpg_param_HeaderDigest.attr,
1330 &iscsi_tpg_param_DataDigest.attr,
1331 &iscsi_tpg_param_MaxConnections.attr,
1332 &iscsi_tpg_param_TargetAlias.attr,
1333 &iscsi_tpg_param_InitialR2T.attr,
1334 &iscsi_tpg_param_ImmediateData.attr,
1335 &iscsi_tpg_param_MaxRecvDataSegmentLength.attr,
1336 &iscsi_tpg_param_MaxXmitDataSegmentLength.attr,
1337 &iscsi_tpg_param_MaxBurstLength.attr,
1338 &iscsi_tpg_param_FirstBurstLength.attr,
1339 &iscsi_tpg_param_DefaultTime2Wait.attr,
1340 &iscsi_tpg_param_DefaultTime2Retain.attr,
1341 &iscsi_tpg_param_MaxOutstandingR2T.attr,
1342 &iscsi_tpg_param_DataPDUInOrder.attr,
1343 &iscsi_tpg_param_DataSequenceInOrder.attr,
1344 &iscsi_tpg_param_ErrorRecoveryLevel.attr,
1345 &iscsi_tpg_param_IFMarker.attr,
1346 &iscsi_tpg_param_OFMarker.attr,
1347 &iscsi_tpg_param_IFMarkInt.attr,
1348 &iscsi_tpg_param_OFMarkInt.attr,
1349 NULL,
1352 /* End items for lio_target_tpg_param_cit */
1354 /* Start items for lio_target_tpg_cit */
1356 static ssize_t lio_target_tpg_show_enable(
1357 struct se_portal_group *se_tpg,
1358 char *page)
1360 struct iscsi_portal_group *tpg = container_of(se_tpg,
1361 struct iscsi_portal_group, tpg_se_tpg);
1362 ssize_t len;
1364 spin_lock(&tpg->tpg_state_lock);
1365 len = sprintf(page, "%d\n",
1366 (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1367 spin_unlock(&tpg->tpg_state_lock);
1369 return len;
1372 static ssize_t lio_target_tpg_store_enable(
1373 struct se_portal_group *se_tpg,
1374 const char *page,
1375 size_t count)
1377 struct iscsi_portal_group *tpg = container_of(se_tpg,
1378 struct iscsi_portal_group, tpg_se_tpg);
1379 u32 op;
1380 int ret;
1382 ret = kstrtou32(page, 0, &op);
1383 if (ret)
1384 return ret;
1385 if ((op != 1) && (op != 0)) {
1386 pr_err("Illegal value for tpg_enable: %u\n", op);
1387 return -EINVAL;
1390 ret = iscsit_get_tpg(tpg);
1391 if (ret < 0)
1392 return -EINVAL;
1394 if (op) {
1395 ret = iscsit_tpg_enable_portal_group(tpg);
1396 if (ret < 0)
1397 goto out;
1398 } else {
1400 * iscsit_tpg_disable_portal_group() assumes force=1
1402 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1403 if (ret < 0)
1404 goto out;
1407 iscsit_put_tpg(tpg);
1408 return count;
1409 out:
1410 iscsit_put_tpg(tpg);
1411 return -EINVAL;
1414 TF_TPG_BASE_ATTR(lio_target, enable, S_IRUGO | S_IWUSR);
1416 static ssize_t lio_target_tpg_show_dynamic_sessions(
1417 struct se_portal_group *se_tpg,
1418 char *page)
1420 return target_show_dynamic_sessions(se_tpg, page);
1423 TF_TPG_BASE_ATTR_RO(lio_target, dynamic_sessions);
1425 static struct configfs_attribute *lio_target_tpg_attrs[] = {
1426 &lio_target_tpg_enable.attr,
1427 &lio_target_tpg_dynamic_sessions.attr,
1428 NULL,
1431 /* End items for lio_target_tpg_cit */
1433 /* Start items for lio_target_tiqn_cit */
1435 static struct se_portal_group *lio_target_tiqn_addtpg(
1436 struct se_wwn *wwn,
1437 struct config_group *group,
1438 const char *name)
1440 struct iscsi_portal_group *tpg;
1441 struct iscsi_tiqn *tiqn;
1442 char *tpgt_str;
1443 int ret;
1444 u16 tpgt;
1446 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1448 * Only tpgt_# directory groups can be created below
1449 * target/iscsi/iqn.superturodiskarry/
1451 tpgt_str = strstr(name, "tpgt_");
1452 if (!tpgt_str) {
1453 pr_err("Unable to locate \"tpgt_#\" directory"
1454 " group\n");
1455 return NULL;
1457 tpgt_str += 5; /* Skip ahead of "tpgt_" */
1458 ret = kstrtou16(tpgt_str, 0, &tpgt);
1459 if (ret)
1460 return NULL;
1462 tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1463 if (!tpg)
1464 return NULL;
1466 ret = core_tpg_register(&iscsi_ops, wwn, &tpg->tpg_se_tpg,
1467 tpg, TRANSPORT_TPG_TYPE_NORMAL);
1468 if (ret < 0)
1469 return NULL;
1471 ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1472 if (ret != 0)
1473 goto out;
1475 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1476 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1477 name);
1478 return &tpg->tpg_se_tpg;
1479 out:
1480 core_tpg_deregister(&tpg->tpg_se_tpg);
1481 kfree(tpg);
1482 return NULL;
1485 static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1487 struct iscsi_portal_group *tpg;
1488 struct iscsi_tiqn *tiqn;
1490 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1491 tiqn = tpg->tpg_tiqn;
1493 * iscsit_tpg_del_portal_group() assumes force=1
1495 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1496 iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1499 /* End items for lio_target_tiqn_cit */
1501 /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1503 static ssize_t lio_target_wwn_show_attr_lio_version(
1504 struct target_fabric_configfs *tf,
1505 char *page)
1507 return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
1510 TF_WWN_ATTR_RO(lio_target, lio_version);
1512 static struct configfs_attribute *lio_target_wwn_attrs[] = {
1513 &lio_target_wwn_lio_version.attr,
1514 NULL,
1517 static struct se_wwn *lio_target_call_coreaddtiqn(
1518 struct target_fabric_configfs *tf,
1519 struct config_group *group,
1520 const char *name)
1522 struct config_group *stats_cg;
1523 struct iscsi_tiqn *tiqn;
1525 tiqn = iscsit_add_tiqn((unsigned char *)name);
1526 if (IS_ERR(tiqn))
1527 return ERR_CAST(tiqn);
1529 * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group.
1531 stats_cg = &tiqn->tiqn_wwn.fabric_stat_group;
1533 stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6,
1534 GFP_KERNEL);
1535 if (!stats_cg->default_groups) {
1536 pr_err("Unable to allocate memory for"
1537 " stats_cg->default_groups\n");
1538 iscsit_del_tiqn(tiqn);
1539 return ERR_PTR(-ENOMEM);
1542 stats_cg->default_groups[0] = &tiqn->tiqn_stat_grps.iscsi_instance_group;
1543 stats_cg->default_groups[1] = &tiqn->tiqn_stat_grps.iscsi_sess_err_group;
1544 stats_cg->default_groups[2] = &tiqn->tiqn_stat_grps.iscsi_tgt_attr_group;
1545 stats_cg->default_groups[3] = &tiqn->tiqn_stat_grps.iscsi_login_stats_group;
1546 stats_cg->default_groups[4] = &tiqn->tiqn_stat_grps.iscsi_logout_stats_group;
1547 stats_cg->default_groups[5] = NULL;
1548 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1549 "iscsi_instance", &iscsi_stat_instance_cit);
1550 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1551 "iscsi_sess_err", &iscsi_stat_sess_err_cit);
1552 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1553 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1554 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1555 "iscsi_login_stats", &iscsi_stat_login_cit);
1556 config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1557 "iscsi_logout_stats", &iscsi_stat_logout_cit);
1559 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1560 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1561 " %s\n", name);
1562 return &tiqn->tiqn_wwn;
1565 static void lio_target_call_coredeltiqn(
1566 struct se_wwn *wwn)
1568 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1569 struct config_item *df_item;
1570 struct config_group *stats_cg;
1571 int i;
1573 stats_cg = &tiqn->tiqn_wwn.fabric_stat_group;
1574 for (i = 0; stats_cg->default_groups[i]; i++) {
1575 df_item = &stats_cg->default_groups[i]->cg_item;
1576 stats_cg->default_groups[i] = NULL;
1577 config_item_put(df_item);
1579 kfree(stats_cg->default_groups);
1581 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1582 tiqn->tiqn);
1583 iscsit_del_tiqn(tiqn);
1586 /* End LIO-Target TIQN struct contig_lio_target_cit */
1588 /* Start lio_target_discovery_auth_cit */
1590 #define DEF_DISC_AUTH_STR(name, flags) \
1591 __DEF_NACL_AUTH_STR(disc, name, flags) \
1592 static ssize_t iscsi_disc_show_##name( \
1593 struct target_fabric_configfs *tf, \
1594 char *page) \
1596 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \
1597 page); \
1599 static ssize_t iscsi_disc_store_##name( \
1600 struct target_fabric_configfs *tf, \
1601 const char *page, \
1602 size_t count) \
1604 return __iscsi_disc_store_##name(&iscsit_global->discovery_acl, \
1605 page, count); \
1608 #define DEF_DISC_AUTH_INT(name) \
1609 __DEF_NACL_AUTH_INT(disc, name) \
1610 static ssize_t iscsi_disc_show_##name( \
1611 struct target_fabric_configfs *tf, \
1612 char *page) \
1614 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \
1615 page); \
1618 #define DISC_AUTH_ATTR(_name, _mode) TF_DISC_ATTR(iscsi, _name, _mode)
1619 #define DISC_AUTH_ATTR_RO(_name) TF_DISC_ATTR_RO(iscsi, _name)
1622 * One-way authentication userid
1624 DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1625 DISC_AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
1627 * One-way authentication password
1629 DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1630 DISC_AUTH_ATTR(password, S_IRUGO | S_IWUSR);
1632 * Enforce mutual authentication
1634 DEF_DISC_AUTH_INT(authenticate_target);
1635 DISC_AUTH_ATTR_RO(authenticate_target);
1637 * Mutual authentication userid
1639 DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1640 DISC_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
1642 * Mutual authentication password
1644 DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1645 DISC_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
1648 * enforce_discovery_auth
1650 static ssize_t iscsi_disc_show_enforce_discovery_auth(
1651 struct target_fabric_configfs *tf,
1652 char *page)
1654 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1656 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1659 static ssize_t iscsi_disc_store_enforce_discovery_auth(
1660 struct target_fabric_configfs *tf,
1661 const char *page,
1662 size_t count)
1664 struct iscsi_param *param;
1665 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
1666 u32 op;
1667 int err;
1669 err = kstrtou32(page, 0, &op);
1670 if (err)
1671 return -EINVAL;
1672 if ((op != 1) && (op != 0)) {
1673 pr_err("Illegal value for enforce_discovery_auth:"
1674 " %u\n", op);
1675 return -EINVAL;
1678 if (!discovery_tpg) {
1679 pr_err("iscsit_global->discovery_tpg is NULL\n");
1680 return -EINVAL;
1683 param = iscsi_find_param_from_key(AUTHMETHOD,
1684 discovery_tpg->param_list);
1685 if (!param)
1686 return -EINVAL;
1688 if (op) {
1690 * Reset the AuthMethod key to CHAP.
1692 if (iscsi_update_param_value(param, CHAP) < 0)
1693 return -EINVAL;
1695 discovery_tpg->tpg_attrib.authentication = 1;
1696 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1697 pr_debug("LIO-CORE[0] Successfully enabled"
1698 " authentication enforcement for iSCSI"
1699 " Discovery TPG\n");
1700 } else {
1702 * Reset the AuthMethod key to CHAP,None
1704 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1705 return -EINVAL;
1707 discovery_tpg->tpg_attrib.authentication = 0;
1708 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1709 pr_debug("LIO-CORE[0] Successfully disabled"
1710 " authentication enforcement for iSCSI"
1711 " Discovery TPG\n");
1714 return count;
1717 DISC_AUTH_ATTR(enforce_discovery_auth, S_IRUGO | S_IWUSR);
1719 static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1720 &iscsi_disc_userid.attr,
1721 &iscsi_disc_password.attr,
1722 &iscsi_disc_authenticate_target.attr,
1723 &iscsi_disc_userid_mutual.attr,
1724 &iscsi_disc_password_mutual.attr,
1725 &iscsi_disc_enforce_discovery_auth.attr,
1726 NULL,
1729 /* End lio_target_discovery_auth_cit */
1731 /* Start functions for target_core_fabric_ops */
1733 static char *iscsi_get_fabric_name(void)
1735 return "iSCSI";
1738 static u32 iscsi_get_task_tag(struct se_cmd *se_cmd)
1740 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1742 /* only used for printks or comparism with ->ref_task_tag */
1743 return (__force u32)cmd->init_task_tag;
1746 static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1748 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1750 return cmd->i_state;
1753 static u32 lio_sess_get_index(struct se_session *se_sess)
1755 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1757 return sess->session_index;
1760 static u32 lio_sess_get_initiator_sid(
1761 struct se_session *se_sess,
1762 unsigned char *buf,
1763 u32 size)
1765 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1767 * iSCSI Initiator Session Identifier from RFC-3720.
1769 return snprintf(buf, size, "%6phN", sess->isid);
1772 static int lio_queue_data_in(struct se_cmd *se_cmd)
1774 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1776 cmd->i_state = ISTATE_SEND_DATAIN;
1777 cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd);
1779 return 0;
1782 static int lio_write_pending(struct se_cmd *se_cmd)
1784 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1785 struct iscsi_conn *conn = cmd->conn;
1787 if (!cmd->immediate_data && !cmd->unsolicited_data)
1788 return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
1790 return 0;
1793 static int lio_write_pending_status(struct se_cmd *se_cmd)
1795 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1796 int ret;
1798 spin_lock_bh(&cmd->istate_lock);
1799 ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1800 spin_unlock_bh(&cmd->istate_lock);
1802 return ret;
1805 static int lio_queue_status(struct se_cmd *se_cmd)
1807 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1809 cmd->i_state = ISTATE_SEND_STATUS;
1811 if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
1812 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1813 return 0;
1815 cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd);
1817 return 0;
1820 static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
1822 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1824 cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1825 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1828 static void lio_aborted_task(struct se_cmd *se_cmd)
1830 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1832 cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1835 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1837 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1839 return &tpg->tpg_tiqn->tiqn[0];
1842 static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1844 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1846 return tpg->tpgt;
1849 static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1851 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1853 return tpg->tpg_attrib.default_cmdsn_depth;
1856 static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1858 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1860 return tpg->tpg_attrib.generate_node_acls;
1863 static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1865 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1867 return tpg->tpg_attrib.cache_dynamic_acls;
1870 static int lio_tpg_check_demo_mode_write_protect(
1871 struct se_portal_group *se_tpg)
1873 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1875 return tpg->tpg_attrib.demo_mode_write_protect;
1878 static int lio_tpg_check_prod_mode_write_protect(
1879 struct se_portal_group *se_tpg)
1881 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1883 return tpg->tpg_attrib.prod_mode_write_protect;
1886 static int lio_tpg_check_prot_fabric_only(
1887 struct se_portal_group *se_tpg)
1889 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1891 * Only report fabric_prot_type if t10_pi has also been enabled
1892 * for incoming ib_isert sessions.
1894 if (!tpg->tpg_attrib.t10_pi)
1895 return 0;
1897 return tpg->tpg_attrib.fabric_prot_type;
1900 static void lio_tpg_release_fabric_acl(
1901 struct se_portal_group *se_tpg,
1902 struct se_node_acl *se_acl)
1904 struct iscsi_node_acl *acl = container_of(se_acl,
1905 struct iscsi_node_acl, se_node_acl);
1906 kfree(acl);
1910 * Called with spin_lock_irq(struct se_portal_group->session_lock) held
1911 * or not held.
1913 * Also, this function calls iscsit_inc_session_usage_count() on the
1914 * struct iscsi_session in question.
1916 static int lio_tpg_shutdown_session(struct se_session *se_sess)
1918 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1919 struct se_portal_group *se_tpg = se_sess->se_tpg;
1920 bool local_lock = false;
1922 if (!spin_is_locked(&se_tpg->session_lock)) {
1923 spin_lock_irq(&se_tpg->session_lock);
1924 local_lock = true;
1927 spin_lock(&sess->conn_lock);
1928 if (atomic_read(&sess->session_fall_back_to_erl0) ||
1929 atomic_read(&sess->session_logout) ||
1930 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1931 spin_unlock(&sess->conn_lock);
1932 if (local_lock)
1933 spin_unlock_irq(&sess->conn_lock);
1934 return 0;
1936 atomic_set(&sess->session_reinstatement, 1);
1937 spin_unlock(&sess->conn_lock);
1939 iscsit_stop_time2retain_timer(sess);
1940 spin_unlock_irq(&se_tpg->session_lock);
1942 iscsit_stop_session(sess, 1, 1);
1943 if (!local_lock)
1944 spin_lock_irq(&se_tpg->session_lock);
1946 return 1;
1950 * Calls iscsit_dec_session_usage_count() as inverse of
1951 * lio_tpg_shutdown_session()
1953 static void lio_tpg_close_session(struct se_session *se_sess)
1955 struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1957 * If the iSCSI Session for the iSCSI Initiator Node exists,
1958 * forcefully shutdown the iSCSI NEXUS.
1960 iscsit_close_session(sess);
1963 static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1965 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr;
1967 return tpg->tpg_tiqn->tiqn_index;
1970 static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1972 struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1973 se_node_acl);
1974 struct se_portal_group *se_tpg = se_acl->se_tpg;
1975 struct iscsi_portal_group *tpg = container_of(se_tpg,
1976 struct iscsi_portal_group, tpg_se_tpg);
1978 acl->node_attrib.nacl = acl;
1979 iscsit_set_default_node_attribues(acl, tpg);
1982 static int lio_check_stop_free(struct se_cmd *se_cmd)
1984 return target_put_sess_cmd(se_cmd);
1987 static void lio_release_cmd(struct se_cmd *se_cmd)
1989 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1991 pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
1992 iscsit_release_cmd(cmd);
1995 const struct target_core_fabric_ops iscsi_ops = {
1996 .module = THIS_MODULE,
1997 .name = "iscsi",
1998 .get_fabric_name = iscsi_get_fabric_name,
1999 .get_fabric_proto_ident = iscsi_get_fabric_proto_ident,
2000 .tpg_get_wwn = lio_tpg_get_endpoint_wwn,
2001 .tpg_get_tag = lio_tpg_get_tag,
2002 .tpg_get_default_depth = lio_tpg_get_default_depth,
2003 .tpg_get_pr_transport_id = iscsi_get_pr_transport_id,
2004 .tpg_get_pr_transport_id_len = iscsi_get_pr_transport_id_len,
2005 .tpg_parse_pr_out_transport_id = iscsi_parse_pr_out_transport_id,
2006 .tpg_check_demo_mode = lio_tpg_check_demo_mode,
2007 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache,
2008 .tpg_check_demo_mode_write_protect =
2009 lio_tpg_check_demo_mode_write_protect,
2010 .tpg_check_prod_mode_write_protect =
2011 lio_tpg_check_prod_mode_write_protect,
2012 .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only,
2013 .tpg_alloc_fabric_acl = lio_tpg_alloc_fabric_acl,
2014 .tpg_release_fabric_acl = lio_tpg_release_fabric_acl,
2015 .tpg_get_inst_index = lio_tpg_get_inst_index,
2016 .check_stop_free = lio_check_stop_free,
2017 .release_cmd = lio_release_cmd,
2018 .shutdown_session = lio_tpg_shutdown_session,
2019 .close_session = lio_tpg_close_session,
2020 .sess_get_index = lio_sess_get_index,
2021 .sess_get_initiator_sid = lio_sess_get_initiator_sid,
2022 .write_pending = lio_write_pending,
2023 .write_pending_status = lio_write_pending_status,
2024 .set_default_node_attributes = lio_set_default_node_attributes,
2025 .get_task_tag = iscsi_get_task_tag,
2026 .get_cmd_state = iscsi_get_cmd_state,
2027 .queue_data_in = lio_queue_data_in,
2028 .queue_status = lio_queue_status,
2029 .queue_tm_rsp = lio_queue_tm_rsp,
2030 .aborted_task = lio_aborted_task,
2031 .fabric_make_wwn = lio_target_call_coreaddtiqn,
2032 .fabric_drop_wwn = lio_target_call_coredeltiqn,
2033 .fabric_make_tpg = lio_target_tiqn_addtpg,
2034 .fabric_drop_tpg = lio_target_tiqn_deltpg,
2035 .fabric_make_np = lio_target_call_addnptotpg,
2036 .fabric_drop_np = lio_target_call_delnpfromtpg,
2037 .fabric_make_nodeacl = lio_target_make_nodeacl,
2038 .fabric_drop_nodeacl = lio_target_drop_nodeacl,
2040 .tfc_discovery_attrs = lio_target_discovery_auth_attrs,
2041 .tfc_wwn_attrs = lio_target_wwn_attrs,
2042 .tfc_tpg_base_attrs = lio_target_tpg_attrs,
2043 .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs,
2044 .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs,
2045 .tfc_tpg_param_attrs = lio_target_tpg_param_attrs,
2046 .tfc_tpg_np_base_attrs = lio_target_portal_attrs,
2047 .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs,
2048 .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs,
2049 .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs,
2050 .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs,