]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/target/iscsi/iscsi_target_configfs.c
1b8f885dbfebec033f9b04755041787bd73fa552
[karo-tx-linux.git] / drivers / target / iscsi / iscsi_target_configfs.c
1 /*******************************************************************************
2  * This file contains the configfs implementation for iSCSI Target mode
3  * from the LIO-Target Project.
4  *
5  * (c) Copyright 2007-2013 Datera, Inc.
6  *
7  * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
8  *
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.
13  *
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  ****************************************************************************/
19
20 #include <linux/configfs.h>
21 #include <linux/ctype.h>
22 #include <linux/export.h>
23 #include <linux/inet.h>
24 #include <target/target_core_base.h>
25 #include <target/target_core_fabric.h>
26 #include <target/iscsi/iscsi_transport.h>
27
28 #include <target/iscsi/iscsi_target_core.h>
29 #include "iscsi_target_parameters.h"
30 #include "iscsi_target_device.h"
31 #include "iscsi_target_erl0.h"
32 #include "iscsi_target_nodeattrib.h"
33 #include "iscsi_target_tpg.h"
34 #include "iscsi_target_util.h"
35 #include "iscsi_target.h"
36 #include <target/iscsi/iscsi_target_stat.h>
37
38
39 /* Start items for lio_target_portal_cit */
40
41 static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item)
42 {
43         return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np);
44 }
45
46 static ssize_t lio_target_np_sctp_show(struct config_item *item, char *page)
47 {
48         struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
49         struct iscsi_tpg_np *tpg_np_sctp;
50         ssize_t rb;
51
52         tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
53         if (tpg_np_sctp)
54                 rb = sprintf(page, "1\n");
55         else
56                 rb = sprintf(page, "0\n");
57
58         return rb;
59 }
60
61 static ssize_t lio_target_np_sctp_store(struct config_item *item,
62                 const char *page, size_t count)
63 {
64         struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
65         struct iscsi_np *np;
66         struct iscsi_portal_group *tpg;
67         struct iscsi_tpg_np *tpg_np_sctp = NULL;
68         u32 op;
69         int ret;
70
71         ret = kstrtou32(page, 0, &op);
72         if (ret)
73                 return ret;
74         if ((op != 1) && (op != 0)) {
75                 pr_err("Illegal value for tpg_enable: %u\n", op);
76                 return -EINVAL;
77         }
78         np = tpg_np->tpg_np;
79         if (!np) {
80                 pr_err("Unable to locate struct iscsi_np from"
81                                 " struct iscsi_tpg_np\n");
82                 return -EINVAL;
83         }
84
85         tpg = tpg_np->tpg;
86         if (iscsit_get_tpg(tpg) < 0)
87                 return -EINVAL;
88
89         if (op) {
90                 /*
91                  * Use existing np->np_sockaddr for SCTP network portal reference
92                  */
93                 tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
94                                         tpg_np, ISCSI_SCTP_TCP);
95                 if (!tpg_np_sctp || IS_ERR(tpg_np_sctp))
96                         goto out;
97         } else {
98                 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP);
99                 if (!tpg_np_sctp)
100                         goto out;
101
102                 ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp);
103                 if (ret < 0)
104                         goto out;
105         }
106
107         iscsit_put_tpg(tpg);
108         return count;
109 out:
110         iscsit_put_tpg(tpg);
111         return -EINVAL;
112 }
113
114 static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
115 {
116         struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
117         struct iscsi_tpg_np *tpg_np_iser;
118         ssize_t rb;
119
120         tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
121         if (tpg_np_iser)
122                 rb = sprintf(page, "1\n");
123         else
124                 rb = sprintf(page, "0\n");
125
126         return rb;
127 }
128
129 static ssize_t lio_target_np_iser_store(struct config_item *item,
130                 const char *page, size_t count)
131 {
132         struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
133         struct iscsi_np *np;
134         struct iscsi_portal_group *tpg;
135         struct iscsi_tpg_np *tpg_np_iser = NULL;
136         char *endptr;
137         u32 op;
138         int rc = 0;
139
140         op = simple_strtoul(page, &endptr, 0);
141         if ((op != 1) && (op != 0)) {
142                 pr_err("Illegal value for tpg_enable: %u\n", op);
143                 return -EINVAL;
144         }
145         np = tpg_np->tpg_np;
146         if (!np) {
147                 pr_err("Unable to locate struct iscsi_np from"
148                                 " struct iscsi_tpg_np\n");
149                 return -EINVAL;
150         }
151
152         tpg = tpg_np->tpg;
153         if (iscsit_get_tpg(tpg) < 0)
154                 return -EINVAL;
155
156         if (op) {
157                 rc = request_module("ib_isert");
158                 if (rc != 0) {
159                         pr_warn("Unable to request_module for ib_isert\n");
160                         rc = 0;
161                 }
162
163                 tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr,
164                                 tpg_np, ISCSI_INFINIBAND);
165                 if (IS_ERR(tpg_np_iser)) {
166                         rc = PTR_ERR(tpg_np_iser);
167                         goto out;
168                 }
169         } else {
170                 tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND);
171                 if (tpg_np_iser) {
172                         rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser);
173                         if (rc < 0)
174                                 goto out;
175                 }
176         }
177
178         iscsit_put_tpg(tpg);
179         return count;
180 out:
181         iscsit_put_tpg(tpg);
182         return rc;
183 }
184
185 static ssize_t lio_target_np_hw_offload_show(struct config_item *item,
186                                              char *page)
187 {
188         struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
189         struct iscsi_tpg_np *tpg_np_hw_offload;
190         ssize_t rb;
191
192         tpg_np_hw_offload = iscsit_tpg_locate_child_np(tpg_np,
193                                                        ISCSI_HW_OFFLOAD);
194         if (tpg_np_hw_offload)
195                 rb = sprintf(page, "1\n");
196         else
197                 rb = sprintf(page, "0\n");
198
199         return rb;
200 }
201
202 static ssize_t lio_target_np_hw_offload_store(struct config_item *item,
203                                               const char *page, size_t count)
204 {
205         struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
206         struct iscsi_np *np;
207         struct iscsi_portal_group *tpg;
208         struct iscsi_tpg_np *tpg_np_hw_offload = NULL;
209         u32 op;
210         int rc = 0;
211
212         rc = kstrtou32(page, 0, &op);
213         if (rc)
214                 return rc;
215
216         if ((op != 1) && (op != 0)) {
217                 pr_err("Illegal value for tpg_enable: %u\n", op);
218                 return -EINVAL;
219         }
220
221         np = tpg_np->tpg_np;
222         if (!np) {
223                 pr_err("Unable to locate struct iscsi_np from"
224                        " struct iscsi_tpg_np\n");
225                 return -EINVAL;
226         }
227
228         tpg = tpg_np->tpg;
229         if (iscsit_get_tpg(tpg) < 0)
230                 return -EINVAL;
231
232         if (op) {
233                 tpg_np_hw_offload = iscsit_tpg_add_network_portal(tpg,
234                                 &np->np_sockaddr, tpg_np, ISCSI_HW_OFFLOAD);
235
236                 if (IS_ERR(tpg_np_hw_offload)) {
237                         rc = PTR_ERR(tpg_np_hw_offload);
238                         goto out;
239                 }
240         } else {
241                 tpg_np_hw_offload = iscsit_tpg_locate_child_np(tpg_np,
242                                 ISCSI_HW_OFFLOAD);
243
244                 if (tpg_np_hw_offload) {
245                         rc = iscsit_tpg_del_network_portal(tpg,
246                                                            tpg_np_hw_offload);
247                         if (rc < 0)
248                                 goto out;
249                 }
250         }
251
252         iscsit_put_tpg(tpg);
253         return count;
254 out:
255         iscsit_put_tpg(tpg);
256         return rc;
257 }
258
259 CONFIGFS_ATTR(lio_target_np_, sctp);
260 CONFIGFS_ATTR(lio_target_np_, iser);
261 CONFIGFS_ATTR(lio_target_np_, hw_offload);
262
263 static struct configfs_attribute *lio_target_portal_attrs[] = {
264         &lio_target_np_attr_sctp,
265         &lio_target_np_attr_iser,
266         &lio_target_np_attr_hw_offload,
267         NULL,
268 };
269
270 /* Stop items for lio_target_portal_cit */
271
272 /* Start items for lio_target_np_cit */
273
274 #define MAX_PORTAL_LEN          256
275
276 static struct se_tpg_np *lio_target_call_addnptotpg(
277         struct se_portal_group *se_tpg,
278         struct config_group *group,
279         const char *name)
280 {
281         struct iscsi_portal_group *tpg;
282         struct iscsi_tpg_np *tpg_np;
283         char *str, *str2, *ip_str, *port_str;
284         struct sockaddr_storage sockaddr;
285         struct sockaddr_in *sock_in;
286         struct sockaddr_in6 *sock_in6;
287         unsigned long port;
288         int ret;
289         char buf[MAX_PORTAL_LEN + 1];
290
291         if (strlen(name) > MAX_PORTAL_LEN) {
292                 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n",
293                         (int)strlen(name), MAX_PORTAL_LEN);
294                 return ERR_PTR(-EOVERFLOW);
295         }
296         memset(buf, 0, MAX_PORTAL_LEN + 1);
297         snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name);
298
299         memset(&sockaddr, 0, sizeof(struct sockaddr_storage));
300
301         str = strstr(buf, "[");
302         if (str) {
303                 const char *end;
304
305                 str2 = strstr(str, "]");
306                 if (!str2) {
307                         pr_err("Unable to locate trailing \"]\""
308                                 " in IPv6 iSCSI network portal address\n");
309                         return ERR_PTR(-EINVAL);
310                 }
311                 str++; /* Skip over leading "[" */
312                 *str2 = '\0'; /* Terminate the unbracketed IPv6 address */
313                 str2++; /* Skip over the \0 */
314                 port_str = strstr(str2, ":");
315                 if (!port_str) {
316                         pr_err("Unable to locate \":port\""
317                                 " in IPv6 iSCSI network portal address\n");
318                         return ERR_PTR(-EINVAL);
319                 }
320                 *port_str = '\0'; /* Terminate string for IP */
321                 port_str++; /* Skip over ":" */
322
323                 ret = kstrtoul(port_str, 0, &port);
324                 if (ret < 0) {
325                         pr_err("kstrtoul() failed for port_str: %d\n", ret);
326                         return ERR_PTR(ret);
327                 }
328                 sock_in6 = (struct sockaddr_in6 *)&sockaddr;
329                 sock_in6->sin6_family = AF_INET6;
330                 sock_in6->sin6_port = htons((unsigned short)port);
331                 ret = in6_pton(str, -1,
332                                 (void *)&sock_in6->sin6_addr.in6_u, -1, &end);
333                 if (ret <= 0) {
334                         pr_err("in6_pton returned: %d\n", ret);
335                         return ERR_PTR(-EINVAL);
336                 }
337         } else {
338                 str = ip_str = &buf[0];
339                 port_str = strstr(ip_str, ":");
340                 if (!port_str) {
341                         pr_err("Unable to locate \":port\""
342                                 " in IPv4 iSCSI network portal address\n");
343                         return ERR_PTR(-EINVAL);
344                 }
345                 *port_str = '\0'; /* Terminate string for IP */
346                 port_str++; /* Skip over ":" */
347
348                 ret = kstrtoul(port_str, 0, &port);
349                 if (ret < 0) {
350                         pr_err("kstrtoul() failed for port_str: %d\n", ret);
351                         return ERR_PTR(ret);
352                 }
353                 sock_in = (struct sockaddr_in *)&sockaddr;
354                 sock_in->sin_family = AF_INET;
355                 sock_in->sin_port = htons((unsigned short)port);
356                 sock_in->sin_addr.s_addr = in_aton(ip_str);
357         }
358         tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
359         ret = iscsit_get_tpg(tpg);
360         if (ret < 0)
361                 return ERR_PTR(-EINVAL);
362
363         pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu"
364                 " PORTAL: %s\n",
365                 config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
366                 tpg->tpgt, name);
367         /*
368          * Assume ISCSI_TCP by default.  Other network portals for other
369          * iSCSI fabrics:
370          *
371          * Traditional iSCSI over SCTP (initial support)
372          * iSER/TCP (TODO, hardware available)
373          * iSER/SCTP (TODO, software emulation with osc-iwarp)
374          * iSER/IB (TODO, hardware available)
375          *
376          * can be enabled with attributes under
377          * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/
378          *
379          */
380         tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL,
381                                 ISCSI_TCP);
382         if (IS_ERR(tpg_np)) {
383                 iscsit_put_tpg(tpg);
384                 return ERR_CAST(tpg_np);
385         }
386         pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n");
387
388         iscsit_put_tpg(tpg);
389         return &tpg_np->se_tpg_np;
390 }
391
392 static void lio_target_call_delnpfromtpg(
393         struct se_tpg_np *se_tpg_np)
394 {
395         struct iscsi_portal_group *tpg;
396         struct iscsi_tpg_np *tpg_np;
397         struct se_portal_group *se_tpg;
398         int ret;
399
400         tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np);
401         tpg = tpg_np->tpg;
402         ret = iscsit_get_tpg(tpg);
403         if (ret < 0)
404                 return;
405
406         se_tpg = &tpg->tpg_se_tpg;
407         pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu"
408                 " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item),
409                 tpg->tpgt, &tpg_np->tpg_np->np_sockaddr);
410
411         ret = iscsit_tpg_del_network_portal(tpg, tpg_np);
412         if (ret < 0)
413                 goto out;
414
415         pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n");
416 out:
417         iscsit_put_tpg(tpg);
418 }
419
420 /* End items for lio_target_np_cit */
421
422 /* Start items for lio_target_nacl_attrib_cit */
423
424 #define ISCSI_NACL_ATTR(name)                                           \
425 static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
426                 char *page)                                             \
427 {                                                                       \
428         struct se_node_acl *se_nacl = attrib_to_nacl(item);             \
429         struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
430                                         se_node_acl);                   \
431                                                                         \
432         return sprintf(page, "%u\n", nacl->node_attrib.name);           \
433 }                                                                       \
434                                                                         \
435 static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
436                 const char *page, size_t count)                         \
437 {                                                                       \
438         struct se_node_acl *se_nacl = attrib_to_nacl(item);             \
439         struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
440                                         se_node_acl);                   \
441         u32 val;                                                        \
442         int ret;                                                        \
443                                                                         \
444         ret = kstrtou32(page, 0, &val);                                 \
445         if (ret)                                                        \
446                 return ret;                                             \
447         ret = iscsit_na_##name(nacl, val);                              \
448         if (ret < 0)                                                    \
449                 return ret;                                             \
450                                                                         \
451         return count;                                                   \
452 }                                                                       \
453                                                                         \
454 CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
455
456 ISCSI_NACL_ATTR(dataout_timeout);
457 ISCSI_NACL_ATTR(dataout_timeout_retries);
458 ISCSI_NACL_ATTR(default_erl);
459 ISCSI_NACL_ATTR(nopin_timeout);
460 ISCSI_NACL_ATTR(nopin_response_timeout);
461 ISCSI_NACL_ATTR(random_datain_pdu_offsets);
462 ISCSI_NACL_ATTR(random_datain_seq_offsets);
463 ISCSI_NACL_ATTR(random_r2t_offsets);
464
465 static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
466         &iscsi_nacl_attrib_attr_dataout_timeout,
467         &iscsi_nacl_attrib_attr_dataout_timeout_retries,
468         &iscsi_nacl_attrib_attr_default_erl,
469         &iscsi_nacl_attrib_attr_nopin_timeout,
470         &iscsi_nacl_attrib_attr_nopin_response_timeout,
471         &iscsi_nacl_attrib_attr_random_datain_pdu_offsets,
472         &iscsi_nacl_attrib_attr_random_datain_seq_offsets,
473         &iscsi_nacl_attrib_attr_random_r2t_offsets,
474         NULL,
475 };
476
477 /* End items for lio_target_nacl_attrib_cit */
478
479 /* Start items for lio_target_nacl_auth_cit */
480
481 #define __DEF_NACL_AUTH_STR(prefix, name, flags)                        \
482 static ssize_t __iscsi_##prefix##_##name##_show(                        \
483         struct iscsi_node_acl *nacl,                                    \
484         char *page)                                                     \
485 {                                                                       \
486         struct iscsi_node_auth *auth = &nacl->node_auth;                \
487                                                                         \
488         if (!capable(CAP_SYS_ADMIN))                                    \
489                 return -EPERM;                                          \
490         return snprintf(page, PAGE_SIZE, "%s\n", auth->name);           \
491 }                                                                       \
492                                                                         \
493 static ssize_t __iscsi_##prefix##_##name##_store(                       \
494         struct iscsi_node_acl *nacl,                                    \
495         const char *page,                                               \
496         size_t count)                                                   \
497 {                                                                       \
498         struct iscsi_node_auth *auth = &nacl->node_auth;                \
499                                                                         \
500         if (!capable(CAP_SYS_ADMIN))                                    \
501                 return -EPERM;                                          \
502         if (count >= sizeof(auth->name))                                \
503                 return -EINVAL;                                         \
504         snprintf(auth->name, sizeof(auth->name), "%s", page);           \
505         if (!strncmp("NULL", auth->name, 4))                            \
506                 auth->naf_flags &= ~flags;                              \
507         else                                                            \
508                 auth->naf_flags |= flags;                               \
509                                                                         \
510         if ((auth->naf_flags & NAF_USERID_IN_SET) &&                    \
511             (auth->naf_flags & NAF_PASSWORD_IN_SET))                    \
512                 auth->authenticate_target = 1;                          \
513         else                                                            \
514                 auth->authenticate_target = 0;                          \
515                                                                         \
516         return count;                                                   \
517 }
518
519 #define DEF_NACL_AUTH_STR(name, flags)                                  \
520         __DEF_NACL_AUTH_STR(nacl_auth, name, flags)                     \
521 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item,  \
522                 char *page)                                             \
523 {                                                                       \
524         struct se_node_acl *nacl = auth_to_nacl(item);                  \
525         return __iscsi_nacl_auth_##name##_show(container_of(nacl,       \
526                         struct iscsi_node_acl, se_node_acl), page);     \
527 }                                                                       \
528 static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \
529                 const char *page, size_t count)                         \
530 {                                                                       \
531         struct se_node_acl *nacl = auth_to_nacl(item);                  \
532         return __iscsi_nacl_auth_##name##_store(container_of(nacl,      \
533                         struct iscsi_node_acl, se_node_acl), page, count); \
534 }                                                                       \
535                                                                         \
536 CONFIGFS_ATTR(iscsi_nacl_auth_, name)
537
538 /*
539  * One-way authentication userid
540  */
541 DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
542 DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
543 DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
544 DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
545
546 #define __DEF_NACL_AUTH_INT(prefix, name)                               \
547 static ssize_t __iscsi_##prefix##_##name##_show(                                \
548         struct iscsi_node_acl *nacl,                                    \
549         char *page)                                                     \
550 {                                                                       \
551         struct iscsi_node_auth *auth = &nacl->node_auth;                \
552                                                                         \
553         if (!capable(CAP_SYS_ADMIN))                                    \
554                 return -EPERM;                                          \
555                                                                         \
556         return snprintf(page, PAGE_SIZE, "%d\n", auth->name);           \
557 }
558
559 #define DEF_NACL_AUTH_INT(name)                                         \
560         __DEF_NACL_AUTH_INT(nacl_auth, name)                            \
561 static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item,  \
562                 char *page)                                             \
563 {                                                                       \
564         struct se_node_acl *nacl = auth_to_nacl(item);                  \
565         return __iscsi_nacl_auth_##name##_show(container_of(nacl,       \
566                         struct iscsi_node_acl, se_node_acl), page);     \
567 }                                                                       \
568                                                                         \
569 CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
570
571 DEF_NACL_AUTH_INT(authenticate_target);
572
573 static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
574         &iscsi_nacl_auth_attr_userid,
575         &iscsi_nacl_auth_attr_password,
576         &iscsi_nacl_auth_attr_authenticate_target,
577         &iscsi_nacl_auth_attr_userid_mutual,
578         &iscsi_nacl_auth_attr_password_mutual,
579         NULL,
580 };
581
582 /* End items for lio_target_nacl_auth_cit */
583
584 /* Start items for lio_target_nacl_param_cit */
585
586 #define ISCSI_NACL_PARAM(name)                                          \
587 static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \
588                 char *page)                                             \
589 {                                                                       \
590         struct se_node_acl *se_nacl = param_to_nacl(item);              \
591         struct iscsi_session *sess;                                     \
592         struct se_session *se_sess;                                     \
593         ssize_t rb;                                                     \
594                                                                         \
595         spin_lock_bh(&se_nacl->nacl_sess_lock);                         \
596         se_sess = se_nacl->nacl_sess;                                   \
597         if (!se_sess) {                                                 \
598                 rb = snprintf(page, PAGE_SIZE,                          \
599                         "No Active iSCSI Session\n");                   \
600         } else {                                                        \
601                 sess = se_sess->fabric_sess_ptr;                        \
602                 rb = snprintf(page, PAGE_SIZE, "%u\n",                  \
603                         (u32)sess->sess_ops->name);                     \
604         }                                                               \
605         spin_unlock_bh(&se_nacl->nacl_sess_lock);                       \
606                                                                         \
607         return rb;                                                      \
608 }                                                                       \
609                                                                         \
610 CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
611
612 ISCSI_NACL_PARAM(MaxConnections);
613 ISCSI_NACL_PARAM(InitialR2T);
614 ISCSI_NACL_PARAM(ImmediateData);
615 ISCSI_NACL_PARAM(MaxBurstLength);
616 ISCSI_NACL_PARAM(FirstBurstLength);
617 ISCSI_NACL_PARAM(DefaultTime2Wait);
618 ISCSI_NACL_PARAM(DefaultTime2Retain);
619 ISCSI_NACL_PARAM(MaxOutstandingR2T);
620 ISCSI_NACL_PARAM(DataPDUInOrder);
621 ISCSI_NACL_PARAM(DataSequenceInOrder);
622 ISCSI_NACL_PARAM(ErrorRecoveryLevel);
623
624 static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
625         &iscsi_nacl_param_attr_MaxConnections,
626         &iscsi_nacl_param_attr_InitialR2T,
627         &iscsi_nacl_param_attr_ImmediateData,
628         &iscsi_nacl_param_attr_MaxBurstLength,
629         &iscsi_nacl_param_attr_FirstBurstLength,
630         &iscsi_nacl_param_attr_DefaultTime2Wait,
631         &iscsi_nacl_param_attr_DefaultTime2Retain,
632         &iscsi_nacl_param_attr_MaxOutstandingR2T,
633         &iscsi_nacl_param_attr_DataPDUInOrder,
634         &iscsi_nacl_param_attr_DataSequenceInOrder,
635         &iscsi_nacl_param_attr_ErrorRecoveryLevel,
636         NULL,
637 };
638
639 /* End items for lio_target_nacl_param_cit */
640
641 /* Start items for lio_target_acl_cit */
642
643 static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
644 {
645         struct se_node_acl *se_nacl = acl_to_nacl(item);
646         struct iscsi_session *sess;
647         struct iscsi_conn *conn;
648         struct se_session *se_sess;
649         ssize_t rb = 0;
650         u32 max_cmd_sn;
651
652         spin_lock_bh(&se_nacl->nacl_sess_lock);
653         se_sess = se_nacl->nacl_sess;
654         if (!se_sess) {
655                 rb += sprintf(page+rb, "No active iSCSI Session for Initiator"
656                         " Endpoint: %s\n", se_nacl->initiatorname);
657         } else {
658                 sess = se_sess->fabric_sess_ptr;
659
660                 rb += sprintf(page+rb, "InitiatorName: %s\n",
661                         sess->sess_ops->InitiatorName);
662                 rb += sprintf(page+rb, "InitiatorAlias: %s\n",
663                         sess->sess_ops->InitiatorAlias);
664
665                 rb += sprintf(page+rb,
666                               "LIO Session ID: %u   ISID: 0x%6ph  TSIH: %hu  ",
667                               sess->sid, sess->isid, sess->tsih);
668                 rb += sprintf(page+rb, "SessionType: %s\n",
669                                 (sess->sess_ops->SessionType) ?
670                                 "Discovery" : "Normal");
671                 rb += sprintf(page+rb, "Session State: ");
672                 switch (sess->session_state) {
673                 case TARG_SESS_STATE_FREE:
674                         rb += sprintf(page+rb, "TARG_SESS_FREE\n");
675                         break;
676                 case TARG_SESS_STATE_ACTIVE:
677                         rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n");
678                         break;
679                 case TARG_SESS_STATE_LOGGED_IN:
680                         rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n");
681                         break;
682                 case TARG_SESS_STATE_FAILED:
683                         rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n");
684                         break;
685                 case TARG_SESS_STATE_IN_CONTINUE:
686                         rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n");
687                         break;
688                 default:
689                         rb += sprintf(page+rb, "ERROR: Unknown Session"
690                                         " State!\n");
691                         break;
692                 }
693
694                 rb += sprintf(page+rb, "---------------------[iSCSI Session"
695                                 " Values]-----------------------\n");
696                 rb += sprintf(page+rb, "  CmdSN/WR  :  CmdSN/WC  :  ExpCmdSN"
697                                 "  :  MaxCmdSN  :     ITT    :     TTT\n");
698                 max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn);
699                 rb += sprintf(page+rb, " 0x%08x   0x%08x   0x%08x   0x%08x"
700                                 "   0x%08x   0x%08x\n",
701                         sess->cmdsn_window,
702                         (max_cmd_sn - sess->exp_cmd_sn) + 1,
703                         sess->exp_cmd_sn, max_cmd_sn,
704                         sess->init_task_tag, sess->targ_xfer_tag);
705                 rb += sprintf(page+rb, "----------------------[iSCSI"
706                                 " Connections]-------------------------\n");
707
708                 spin_lock(&sess->conn_lock);
709                 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) {
710                         rb += sprintf(page+rb, "CID: %hu  Connection"
711                                         " State: ", conn->cid);
712                         switch (conn->conn_state) {
713                         case TARG_CONN_STATE_FREE:
714                                 rb += sprintf(page+rb,
715                                         "TARG_CONN_STATE_FREE\n");
716                                 break;
717                         case TARG_CONN_STATE_XPT_UP:
718                                 rb += sprintf(page+rb,
719                                         "TARG_CONN_STATE_XPT_UP\n");
720                                 break;
721                         case TARG_CONN_STATE_IN_LOGIN:
722                                 rb += sprintf(page+rb,
723                                         "TARG_CONN_STATE_IN_LOGIN\n");
724                                 break;
725                         case TARG_CONN_STATE_LOGGED_IN:
726                                 rb += sprintf(page+rb,
727                                         "TARG_CONN_STATE_LOGGED_IN\n");
728                                 break;
729                         case TARG_CONN_STATE_IN_LOGOUT:
730                                 rb += sprintf(page+rb,
731                                         "TARG_CONN_STATE_IN_LOGOUT\n");
732                                 break;
733                         case TARG_CONN_STATE_LOGOUT_REQUESTED:
734                                 rb += sprintf(page+rb,
735                                         "TARG_CONN_STATE_LOGOUT_REQUESTED\n");
736                                 break;
737                         case TARG_CONN_STATE_CLEANUP_WAIT:
738                                 rb += sprintf(page+rb,
739                                         "TARG_CONN_STATE_CLEANUP_WAIT\n");
740                                 break;
741                         default:
742                                 rb += sprintf(page+rb,
743                                         "ERROR: Unknown Connection State!\n");
744                                 break;
745                         }
746
747                         rb += sprintf(page+rb, "   Address %pISc %s", &conn->login_sockaddr,
748                                 (conn->network_transport == ISCSI_TCP) ?
749                                 "TCP" : "SCTP");
750                         rb += sprintf(page+rb, "  StatSN: 0x%08x\n",
751                                 conn->stat_sn);
752                 }
753                 spin_unlock(&sess->conn_lock);
754         }
755         spin_unlock_bh(&se_nacl->nacl_sess_lock);
756
757         return rb;
758 }
759
760 static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
761                 char *page)
762 {
763         return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth);
764 }
765
766 static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
767                 const char *page, size_t count)
768 {
769         struct se_node_acl *se_nacl = acl_to_nacl(item);
770         struct se_portal_group *se_tpg = se_nacl->se_tpg;
771         struct iscsi_portal_group *tpg = container_of(se_tpg,
772                         struct iscsi_portal_group, tpg_se_tpg);
773         struct config_item *acl_ci, *tpg_ci, *wwn_ci;
774         u32 cmdsn_depth = 0;
775         int ret;
776
777         ret = kstrtou32(page, 0, &cmdsn_depth);
778         if (ret)
779                 return ret;
780         if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
781                 pr_err("Passed cmdsn_depth: %u exceeds"
782                         " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth,
783                         TA_DEFAULT_CMDSN_DEPTH_MAX);
784                 return -EINVAL;
785         }
786         acl_ci = &se_nacl->acl_group.cg_item;
787         if (!acl_ci) {
788                 pr_err("Unable to locatel acl_ci\n");
789                 return -EINVAL;
790         }
791         tpg_ci = &acl_ci->ci_parent->ci_group->cg_item;
792         if (!tpg_ci) {
793                 pr_err("Unable to locate tpg_ci\n");
794                 return -EINVAL;
795         }
796         wwn_ci = &tpg_ci->ci_group->cg_item;
797         if (!wwn_ci) {
798                 pr_err("Unable to locate config_item wwn_ci\n");
799                 return -EINVAL;
800         }
801
802         if (iscsit_get_tpg(tpg) < 0)
803                 return -EINVAL;
804
805         ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth);
806
807         pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for"
808                 "InitiatorName: %s\n", config_item_name(wwn_ci),
809                 config_item_name(tpg_ci), cmdsn_depth,
810                 config_item_name(acl_ci));
811
812         iscsit_put_tpg(tpg);
813         return (!ret) ? count : (ssize_t)ret;
814 }
815
816 static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
817 {
818         return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
819 }
820
821 static ssize_t lio_target_nacl_tag_store(struct config_item *item,
822                 const char *page, size_t count)
823 {
824         struct se_node_acl *se_nacl = acl_to_nacl(item);
825         int ret;
826
827         ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
828
829         if (ret < 0)
830                 return ret;
831         return count;
832 }
833
834 CONFIGFS_ATTR_RO(lio_target_nacl_, info);
835 CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
836 CONFIGFS_ATTR(lio_target_nacl_, tag);
837
838 static struct configfs_attribute *lio_target_initiator_attrs[] = {
839         &lio_target_nacl_attr_info,
840         &lio_target_nacl_attr_cmdsn_depth,
841         &lio_target_nacl_attr_tag,
842         NULL,
843 };
844
845 static int lio_target_init_nodeacl(struct se_node_acl *se_nacl,
846                 const char *name)
847 {
848         struct iscsi_node_acl *acl =
849                 container_of(se_nacl, struct iscsi_node_acl, se_node_acl);
850
851         config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group,
852                         "iscsi_sess_stats", &iscsi_stat_sess_cit);
853         configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group,
854                         &se_nacl->acl_fabric_stat_group);
855         return 0;
856 }
857
858 /* End items for lio_target_acl_cit */
859
860 /* Start items for lio_target_tpg_attrib_cit */
861
862 #define DEF_TPG_ATTRIB(name)                                            \
863                                                                         \
864 static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \
865                 char *page)                                             \
866 {                                                                       \
867         struct se_portal_group *se_tpg = attrib_to_tpg(item);           \
868         struct iscsi_portal_group *tpg = container_of(se_tpg,           \
869                         struct iscsi_portal_group, tpg_se_tpg); \
870         ssize_t rb;                                                     \
871                                                                         \
872         if (iscsit_get_tpg(tpg) < 0)                                    \
873                 return -EINVAL;                                         \
874                                                                         \
875         rb = sprintf(page, "%u\n", tpg->tpg_attrib.name);               \
876         iscsit_put_tpg(tpg);                                            \
877         return rb;                                                      \
878 }                                                                       \
879                                                                         \
880 static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
881                 const char *page, size_t count)                         \
882 {                                                                       \
883         struct se_portal_group *se_tpg = attrib_to_tpg(item);           \
884         struct iscsi_portal_group *tpg = container_of(se_tpg,           \
885                         struct iscsi_portal_group, tpg_se_tpg); \
886         u32 val;                                                        \
887         int ret;                                                        \
888                                                                         \
889         if (iscsit_get_tpg(tpg) < 0)                                    \
890                 return -EINVAL;                                         \
891                                                                         \
892         ret = kstrtou32(page, 0, &val);                                 \
893         if (ret)                                                        \
894                 goto out;                                               \
895         ret = iscsit_ta_##name(tpg, val);                               \
896         if (ret < 0)                                                    \
897                 goto out;                                               \
898                                                                         \
899         iscsit_put_tpg(tpg);                                            \
900         return count;                                                   \
901 out:                                                                    \
902         iscsit_put_tpg(tpg);                                            \
903         return ret;                                                     \
904 }                                                                       \
905 CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
906
907 DEF_TPG_ATTRIB(authentication);
908 DEF_TPG_ATTRIB(login_timeout);
909 DEF_TPG_ATTRIB(netif_timeout);
910 DEF_TPG_ATTRIB(generate_node_acls);
911 DEF_TPG_ATTRIB(default_cmdsn_depth);
912 DEF_TPG_ATTRIB(cache_dynamic_acls);
913 DEF_TPG_ATTRIB(demo_mode_write_protect);
914 DEF_TPG_ATTRIB(prod_mode_write_protect);
915 DEF_TPG_ATTRIB(demo_mode_discovery);
916 DEF_TPG_ATTRIB(default_erl);
917 DEF_TPG_ATTRIB(t10_pi);
918 DEF_TPG_ATTRIB(fabric_prot_type);
919 DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
920
921 static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
922         &iscsi_tpg_attrib_attr_authentication,
923         &iscsi_tpg_attrib_attr_login_timeout,
924         &iscsi_tpg_attrib_attr_netif_timeout,
925         &iscsi_tpg_attrib_attr_generate_node_acls,
926         &iscsi_tpg_attrib_attr_default_cmdsn_depth,
927         &iscsi_tpg_attrib_attr_cache_dynamic_acls,
928         &iscsi_tpg_attrib_attr_demo_mode_write_protect,
929         &iscsi_tpg_attrib_attr_prod_mode_write_protect,
930         &iscsi_tpg_attrib_attr_demo_mode_discovery,
931         &iscsi_tpg_attrib_attr_default_erl,
932         &iscsi_tpg_attrib_attr_t10_pi,
933         &iscsi_tpg_attrib_attr_fabric_prot_type,
934         &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
935         NULL,
936 };
937
938 /* End items for lio_target_tpg_attrib_cit */
939
940 /* Start items for lio_target_tpg_auth_cit */
941
942 #define __DEF_TPG_AUTH_STR(prefix, name, flags)                                 \
943 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
944                 char *page)                                                     \
945 {                                                                               \
946         struct iscsi_portal_group *tpg = container_of(se_tpg,                   \
947                                 struct iscsi_portal_group, tpg_se_tpg);         \
948         struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;                     \
949                                                                                 \
950         if (!capable(CAP_SYS_ADMIN))                                            \
951                 return -EPERM;                                                  \
952                                                                                 \
953         return snprintf(page, PAGE_SIZE, "%s\n", auth->name);                   \
954 }                                                                               \
955                                                                                 \
956 static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
957                 const char *page, size_t count)                                 \
958 {                                                                               \
959         struct iscsi_portal_group *tpg = container_of(se_tpg,                   \
960                                 struct iscsi_portal_group, tpg_se_tpg);         \
961         struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;                     \
962                                                                                 \
963         if (!capable(CAP_SYS_ADMIN))                                            \
964                 return -EPERM;                                                  \
965                                                                                 \
966         snprintf(auth->name, sizeof(auth->name), "%s", page);                   \
967         if (!(strncmp("NULL", auth->name, 4)))                                  \
968                 auth->naf_flags &= ~flags;                                      \
969         else                                                                    \
970                 auth->naf_flags |= flags;                                       \
971                                                                                 \
972         if ((auth->naf_flags & NAF_USERID_IN_SET) &&                            \
973             (auth->naf_flags & NAF_PASSWORD_IN_SET))                            \
974                 auth->authenticate_target = 1;                                  \
975         else                                                                    \
976                 auth->authenticate_target = 0;                                  \
977                                                                                 \
978         return count;                                                           \
979 }
980
981 #define DEF_TPG_AUTH_STR(name, flags)                                           \
982         __DEF_TPG_AUTH_STR(tpg_auth, name, flags)                               \
983 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item,           \
984                 char *page)                                                     \
985 {                                                                               \
986         return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page);         \
987 }                                                                               \
988                                                                                 \
989 static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item,          \
990                 const char *page, size_t count)                                 \
991 {                                                                               \
992         return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
993 }                                                                               \
994                                                                                 \
995 CONFIGFS_ATTR(iscsi_tpg_auth_, name);
996
997
998 DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
999 DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
1000 DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1001 DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1002
1003 #define __DEF_TPG_AUTH_INT(prefix, name)                                        \
1004 static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
1005                 char *page)                                                             \
1006 {                                                                               \
1007         struct iscsi_portal_group *tpg = container_of(se_tpg,                   \
1008                                 struct iscsi_portal_group, tpg_se_tpg);         \
1009         struct iscsi_node_auth *auth = &tpg->tpg_demo_auth;                     \
1010                                                                                 \
1011         if (!capable(CAP_SYS_ADMIN))                                            \
1012                 return -EPERM;                                                  \
1013                                                                                 \
1014         return snprintf(page, PAGE_SIZE, "%d\n", auth->name);                   \
1015 }
1016
1017 #define DEF_TPG_AUTH_INT(name)                                                  \
1018         __DEF_TPG_AUTH_INT(tpg_auth, name)                                      \
1019 static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item,           \
1020                 char *page) \
1021 {                                                                               \
1022         return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page);         \
1023 }                                                                               \
1024 CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
1025
1026 DEF_TPG_AUTH_INT(authenticate_target);
1027
1028 static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
1029         &iscsi_tpg_auth_attr_userid,
1030         &iscsi_tpg_auth_attr_password,
1031         &iscsi_tpg_auth_attr_authenticate_target,
1032         &iscsi_tpg_auth_attr_userid_mutual,
1033         &iscsi_tpg_auth_attr_password_mutual,
1034         NULL,
1035 };
1036
1037 /* End items for lio_target_tpg_auth_cit */
1038
1039 /* Start items for lio_target_tpg_param_cit */
1040
1041 #define DEF_TPG_PARAM(name)                                             \
1042 static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item,  \
1043                 char *page)                                             \
1044 {                                                                       \
1045         struct se_portal_group *se_tpg = param_to_tpg(item);            \
1046         struct iscsi_portal_group *tpg = container_of(se_tpg,           \
1047                         struct iscsi_portal_group, tpg_se_tpg);         \
1048         struct iscsi_param *param;                                      \
1049         ssize_t rb;                                                     \
1050                                                                         \
1051         if (iscsit_get_tpg(tpg) < 0)                                    \
1052                 return -EINVAL;                                         \
1053                                                                         \
1054         param = iscsi_find_param_from_key(__stringify(name),            \
1055                                 tpg->param_list);                       \
1056         if (!param) {                                                   \
1057                 iscsit_put_tpg(tpg);                                    \
1058                 return -EINVAL;                                         \
1059         }                                                               \
1060         rb = snprintf(page, PAGE_SIZE, "%s\n", param->value);           \
1061                                                                         \
1062         iscsit_put_tpg(tpg);                                            \
1063         return rb;                                                      \
1064 }                                                                       \
1065 static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
1066                 const char *page, size_t count)                         \
1067 {                                                                       \
1068         struct se_portal_group *se_tpg = param_to_tpg(item);            \
1069         struct iscsi_portal_group *tpg = container_of(se_tpg,           \
1070                         struct iscsi_portal_group, tpg_se_tpg);         \
1071         char *buf;                                                      \
1072         int ret, len;                                                   \
1073                                                                         \
1074         buf = kzalloc(PAGE_SIZE, GFP_KERNEL);                           \
1075         if (!buf)                                                       \
1076                 return -ENOMEM;                                         \
1077         len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page);       \
1078         if (isspace(buf[len-1]))                                        \
1079                 buf[len-1] = '\0'; /* Kill newline */                   \
1080                                                                         \
1081         if (iscsit_get_tpg(tpg) < 0) {                                  \
1082                 kfree(buf);                                             \
1083                 return -EINVAL;                                         \
1084         }                                                               \
1085                                                                         \
1086         ret = iscsi_change_param_value(buf, tpg->param_list, 1);        \
1087         if (ret < 0)                                                    \
1088                 goto out;                                               \
1089                                                                         \
1090         kfree(buf);                                                     \
1091         iscsit_put_tpg(tpg);                                            \
1092         return count;                                                   \
1093 out:                                                                    \
1094         kfree(buf);                                                     \
1095         iscsit_put_tpg(tpg);                                            \
1096         return -EINVAL;                                                 \
1097 }                                                                       \
1098 CONFIGFS_ATTR(iscsi_tpg_param_, name)
1099
1100 DEF_TPG_PARAM(AuthMethod);
1101 DEF_TPG_PARAM(HeaderDigest);
1102 DEF_TPG_PARAM(DataDigest);
1103 DEF_TPG_PARAM(MaxConnections);
1104 DEF_TPG_PARAM(TargetAlias);
1105 DEF_TPG_PARAM(InitialR2T);
1106 DEF_TPG_PARAM(ImmediateData);
1107 DEF_TPG_PARAM(MaxRecvDataSegmentLength);
1108 DEF_TPG_PARAM(MaxXmitDataSegmentLength);
1109 DEF_TPG_PARAM(MaxBurstLength);
1110 DEF_TPG_PARAM(FirstBurstLength);
1111 DEF_TPG_PARAM(DefaultTime2Wait);
1112 DEF_TPG_PARAM(DefaultTime2Retain);
1113 DEF_TPG_PARAM(MaxOutstandingR2T);
1114 DEF_TPG_PARAM(DataPDUInOrder);
1115 DEF_TPG_PARAM(DataSequenceInOrder);
1116 DEF_TPG_PARAM(ErrorRecoveryLevel);
1117 DEF_TPG_PARAM(IFMarker);
1118 DEF_TPG_PARAM(OFMarker);
1119 DEF_TPG_PARAM(IFMarkInt);
1120 DEF_TPG_PARAM(OFMarkInt);
1121
1122 static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
1123         &iscsi_tpg_param_attr_AuthMethod,
1124         &iscsi_tpg_param_attr_HeaderDigest,
1125         &iscsi_tpg_param_attr_DataDigest,
1126         &iscsi_tpg_param_attr_MaxConnections,
1127         &iscsi_tpg_param_attr_TargetAlias,
1128         &iscsi_tpg_param_attr_InitialR2T,
1129         &iscsi_tpg_param_attr_ImmediateData,
1130         &iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
1131         &iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
1132         &iscsi_tpg_param_attr_MaxBurstLength,
1133         &iscsi_tpg_param_attr_FirstBurstLength,
1134         &iscsi_tpg_param_attr_DefaultTime2Wait,
1135         &iscsi_tpg_param_attr_DefaultTime2Retain,
1136         &iscsi_tpg_param_attr_MaxOutstandingR2T,
1137         &iscsi_tpg_param_attr_DataPDUInOrder,
1138         &iscsi_tpg_param_attr_DataSequenceInOrder,
1139         &iscsi_tpg_param_attr_ErrorRecoveryLevel,
1140         &iscsi_tpg_param_attr_IFMarker,
1141         &iscsi_tpg_param_attr_OFMarker,
1142         &iscsi_tpg_param_attr_IFMarkInt,
1143         &iscsi_tpg_param_attr_OFMarkInt,
1144         NULL,
1145 };
1146
1147 /* End items for lio_target_tpg_param_cit */
1148
1149 /* Start items for lio_target_tpg_cit */
1150
1151 static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page)
1152 {
1153         struct se_portal_group *se_tpg = to_tpg(item);
1154         struct iscsi_portal_group *tpg = container_of(se_tpg,
1155                         struct iscsi_portal_group, tpg_se_tpg);
1156         ssize_t len;
1157
1158         spin_lock(&tpg->tpg_state_lock);
1159         len = sprintf(page, "%d\n",
1160                         (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0);
1161         spin_unlock(&tpg->tpg_state_lock);
1162
1163         return len;
1164 }
1165
1166 static ssize_t lio_target_tpg_enable_store(struct config_item *item,
1167                 const char *page, size_t count)
1168 {
1169         struct se_portal_group *se_tpg = to_tpg(item);
1170         struct iscsi_portal_group *tpg = container_of(se_tpg,
1171                         struct iscsi_portal_group, tpg_se_tpg);
1172         u32 op;
1173         int ret;
1174
1175         ret = kstrtou32(page, 0, &op);
1176         if (ret)
1177                 return ret;
1178         if ((op != 1) && (op != 0)) {
1179                 pr_err("Illegal value for tpg_enable: %u\n", op);
1180                 return -EINVAL;
1181         }
1182
1183         ret = iscsit_get_tpg(tpg);
1184         if (ret < 0)
1185                 return -EINVAL;
1186
1187         if (op) {
1188                 ret = iscsit_tpg_enable_portal_group(tpg);
1189                 if (ret < 0)
1190                         goto out;
1191         } else {
1192                 /*
1193                  * iscsit_tpg_disable_portal_group() assumes force=1
1194                  */
1195                 ret = iscsit_tpg_disable_portal_group(tpg, 1);
1196                 if (ret < 0)
1197                         goto out;
1198         }
1199
1200         iscsit_put_tpg(tpg);
1201         return count;
1202 out:
1203         iscsit_put_tpg(tpg);
1204         return -EINVAL;
1205 }
1206
1207
1208 static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
1209                 char *page)
1210 {
1211         return target_show_dynamic_sessions(to_tpg(item), page);
1212 }
1213
1214 CONFIGFS_ATTR(lio_target_tpg_, enable);
1215 CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
1216
1217 static struct configfs_attribute *lio_target_tpg_attrs[] = {
1218         &lio_target_tpg_attr_enable,
1219         &lio_target_tpg_attr_dynamic_sessions,
1220         NULL,
1221 };
1222
1223 /* End items for lio_target_tpg_cit */
1224
1225 /* Start items for lio_target_tiqn_cit */
1226
1227 static struct se_portal_group *lio_target_tiqn_addtpg(
1228         struct se_wwn *wwn,
1229         struct config_group *group,
1230         const char *name)
1231 {
1232         struct iscsi_portal_group *tpg;
1233         struct iscsi_tiqn *tiqn;
1234         char *tpgt_str;
1235         int ret;
1236         u16 tpgt;
1237
1238         tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1239         /*
1240          * Only tpgt_# directory groups can be created below
1241          * target/iscsi/iqn.superturodiskarry/
1242          */
1243         tpgt_str = strstr(name, "tpgt_");
1244         if (!tpgt_str) {
1245                 pr_err("Unable to locate \"tpgt_#\" directory"
1246                                 " group\n");
1247                 return NULL;
1248         }
1249         tpgt_str += 5; /* Skip ahead of "tpgt_" */
1250         ret = kstrtou16(tpgt_str, 0, &tpgt);
1251         if (ret)
1252                 return NULL;
1253
1254         tpg = iscsit_alloc_portal_group(tiqn, tpgt);
1255         if (!tpg)
1256                 return NULL;
1257
1258         ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI);
1259         if (ret < 0)
1260                 return NULL;
1261
1262         ret = iscsit_tpg_add_portal_group(tiqn, tpg);
1263         if (ret != 0)
1264                 goto out;
1265
1266         pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1267         pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n",
1268                         name);
1269         return &tpg->tpg_se_tpg;
1270 out:
1271         core_tpg_deregister(&tpg->tpg_se_tpg);
1272         kfree(tpg);
1273         return NULL;
1274 }
1275
1276 static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1277 {
1278         struct iscsi_portal_group *tpg;
1279         struct iscsi_tiqn *tiqn;
1280
1281         tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1282         tiqn = tpg->tpg_tiqn;
1283         /*
1284          * iscsit_tpg_del_portal_group() assumes force=1
1285          */
1286         pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n");
1287         iscsit_tpg_del_portal_group(tiqn, tpg, 1);
1288 }
1289
1290 /* End items for lio_target_tiqn_cit */
1291
1292 /* Start LIO-Target TIQN struct contig_item lio_target_cit */
1293
1294 static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
1295                 char *page)
1296 {
1297         return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
1298 }
1299
1300 CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
1301
1302 static struct configfs_attribute *lio_target_wwn_attrs[] = {
1303         &lio_target_wwn_attr_lio_version,
1304         NULL,
1305 };
1306
1307 static struct se_wwn *lio_target_call_coreaddtiqn(
1308         struct target_fabric_configfs *tf,
1309         struct config_group *group,
1310         const char *name)
1311 {
1312         struct iscsi_tiqn *tiqn;
1313
1314         tiqn = iscsit_add_tiqn((unsigned char *)name);
1315         if (IS_ERR(tiqn))
1316                 return ERR_CAST(tiqn);
1317
1318         pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn);
1319         pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:"
1320                         " %s\n", name);
1321         return &tiqn->tiqn_wwn;
1322 }
1323
1324 static void lio_target_add_wwn_groups(struct se_wwn *wwn)
1325 {
1326         struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1327
1328         config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1329                         "iscsi_instance", &iscsi_stat_instance_cit);
1330         configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group,
1331                         &tiqn->tiqn_wwn.fabric_stat_group);
1332
1333         config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1334                         "iscsi_sess_err", &iscsi_stat_sess_err_cit);
1335         configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group,
1336                         &tiqn->tiqn_wwn.fabric_stat_group);
1337
1338         config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1339                         "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit);
1340         configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group,
1341                         &tiqn->tiqn_wwn.fabric_stat_group);
1342
1343         config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1344                         "iscsi_login_stats", &iscsi_stat_login_cit);
1345         configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group,
1346                         &tiqn->tiqn_wwn.fabric_stat_group);
1347
1348         config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1349                         "iscsi_logout_stats", &iscsi_stat_logout_cit);
1350         configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group,
1351                         &tiqn->tiqn_wwn.fabric_stat_group);
1352 }
1353
1354 static void lio_target_call_coredeltiqn(
1355         struct se_wwn *wwn)
1356 {
1357         struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn);
1358
1359         pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n",
1360                         tiqn->tiqn);
1361         iscsit_del_tiqn(tiqn);
1362 }
1363
1364 /* End LIO-Target TIQN struct contig_lio_target_cit */
1365
1366 /* Start lio_target_discovery_auth_cit */
1367
1368 #define DEF_DISC_AUTH_STR(name, flags)                                  \
1369         __DEF_NACL_AUTH_STR(disc, name, flags)                          \
1370 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1371 {                                                                       \
1372         return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
1373                 page);                                                  \
1374 }                                                                       \
1375 static ssize_t iscsi_disc_##name##_store(struct config_item *item,      \
1376                 const char *page, size_t count)                         \
1377 {                                                                       \
1378         return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl,       \
1379                 page, count);                                           \
1380                                                                         \
1381 }                                                                       \
1382 CONFIGFS_ATTR(iscsi_disc_, name)
1383
1384 DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1385 DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1386 DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1387 DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1388
1389 #define DEF_DISC_AUTH_INT(name)                                         \
1390         __DEF_NACL_AUTH_INT(disc, name)                                 \
1391 static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1392 {                                                                       \
1393         return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
1394                         page);                                          \
1395 }                                                                       \
1396 CONFIGFS_ATTR_RO(iscsi_disc_, name)
1397
1398 DEF_DISC_AUTH_INT(authenticate_target);
1399
1400
1401 static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
1402                 char *page)
1403 {
1404         struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1405
1406         return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1407 }
1408
1409 static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1410                 const char *page, size_t count)
1411 {
1412         struct iscsi_param *param;
1413         struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
1414         u32 op;
1415         int err;
1416
1417         err = kstrtou32(page, 0, &op);
1418         if (err)
1419                 return -EINVAL;
1420         if ((op != 1) && (op != 0)) {
1421                 pr_err("Illegal value for enforce_discovery_auth:"
1422                                 " %u\n", op);
1423                 return -EINVAL;
1424         }
1425
1426         if (!discovery_tpg) {
1427                 pr_err("iscsit_global->discovery_tpg is NULL\n");
1428                 return -EINVAL;
1429         }
1430
1431         param = iscsi_find_param_from_key(AUTHMETHOD,
1432                                 discovery_tpg->param_list);
1433         if (!param)
1434                 return -EINVAL;
1435
1436         if (op) {
1437                 /*
1438                  * Reset the AuthMethod key to CHAP.
1439                  */
1440                 if (iscsi_update_param_value(param, CHAP) < 0)
1441                         return -EINVAL;
1442
1443                 discovery_tpg->tpg_attrib.authentication = 1;
1444                 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1;
1445                 pr_debug("LIO-CORE[0] Successfully enabled"
1446                         " authentication enforcement for iSCSI"
1447                         " Discovery TPG\n");
1448         } else {
1449                 /*
1450                  * Reset the AuthMethod key to CHAP,None
1451                  */
1452                 if (iscsi_update_param_value(param, "CHAP,None") < 0)
1453                         return -EINVAL;
1454
1455                 discovery_tpg->tpg_attrib.authentication = 0;
1456                 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0;
1457                 pr_debug("LIO-CORE[0] Successfully disabled"
1458                         " authentication enforcement for iSCSI"
1459                         " Discovery TPG\n");
1460         }
1461
1462         return count;
1463 }
1464
1465 CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
1466
1467 static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1468         &iscsi_disc_attr_userid,
1469         &iscsi_disc_attr_password,
1470         &iscsi_disc_attr_authenticate_target,
1471         &iscsi_disc_attr_userid_mutual,
1472         &iscsi_disc_attr_password_mutual,
1473         &iscsi_disc_attr_enforce_discovery_auth,
1474         NULL,
1475 };
1476
1477 /* End lio_target_discovery_auth_cit */
1478
1479 /* Start functions for target_core_fabric_ops */
1480
1481 static char *iscsi_get_fabric_name(void)
1482 {
1483         return "iSCSI";
1484 }
1485
1486 static int iscsi_get_cmd_state(struct se_cmd *se_cmd)
1487 {
1488         struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1489
1490         return cmd->i_state;
1491 }
1492
1493 static u32 lio_sess_get_index(struct se_session *se_sess)
1494 {
1495         struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1496
1497         return sess->session_index;
1498 }
1499
1500 static u32 lio_sess_get_initiator_sid(
1501         struct se_session *se_sess,
1502         unsigned char *buf,
1503         u32 size)
1504 {
1505         struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1506         /*
1507          * iSCSI Initiator Session Identifier from RFC-3720.
1508          */
1509         return snprintf(buf, size, "%6phN", sess->isid);
1510 }
1511
1512 static int lio_queue_data_in(struct se_cmd *se_cmd)
1513 {
1514         struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1515
1516         cmd->i_state = ISTATE_SEND_DATAIN;
1517         cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd);
1518
1519         return 0;
1520 }
1521
1522 static int lio_write_pending(struct se_cmd *se_cmd)
1523 {
1524         struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1525         struct iscsi_conn *conn = cmd->conn;
1526
1527         if (!cmd->immediate_data && !cmd->unsolicited_data)
1528                 return conn->conn_transport->iscsit_get_dataout(conn, cmd, false);
1529
1530         return 0;
1531 }
1532
1533 static int lio_write_pending_status(struct se_cmd *se_cmd)
1534 {
1535         struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1536         int ret;
1537
1538         spin_lock_bh(&cmd->istate_lock);
1539         ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT);
1540         spin_unlock_bh(&cmd->istate_lock);
1541
1542         return ret;
1543 }
1544
1545 static int lio_queue_status(struct se_cmd *se_cmd)
1546 {
1547         struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1548
1549         cmd->i_state = ISTATE_SEND_STATUS;
1550
1551         if (cmd->se_cmd.scsi_status || cmd->sense_reason) {
1552                 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1553                 return 0;
1554         }
1555         cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd);
1556
1557         return 0;
1558 }
1559
1560 static void lio_queue_tm_rsp(struct se_cmd *se_cmd)
1561 {
1562         struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1563
1564         cmd->i_state = ISTATE_SEND_TASKMGTRSP;
1565         iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state);
1566 }
1567
1568 static void lio_aborted_task(struct se_cmd *se_cmd)
1569 {
1570         struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1571
1572         cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd);
1573 }
1574
1575 static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg)
1576 {
1577         return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg);
1578 }
1579
1580 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg)
1581 {
1582         return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn;
1583 }
1584
1585 static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg)
1586 {
1587         return iscsi_tpg(se_tpg)->tpgt;
1588 }
1589
1590 static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg)
1591 {
1592         return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth;
1593 }
1594
1595 static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg)
1596 {
1597         return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls;
1598 }
1599
1600 static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg)
1601 {
1602         return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls;
1603 }
1604
1605 static int lio_tpg_check_demo_mode_write_protect(
1606         struct se_portal_group *se_tpg)
1607 {
1608         return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect;
1609 }
1610
1611 static int lio_tpg_check_prod_mode_write_protect(
1612         struct se_portal_group *se_tpg)
1613 {
1614         return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect;
1615 }
1616
1617 static int lio_tpg_check_prot_fabric_only(
1618         struct se_portal_group *se_tpg)
1619 {
1620         /*
1621          * Only report fabric_prot_type if t10_pi has also been enabled
1622          * for incoming ib_isert sessions.
1623          */
1624         if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi)
1625                 return 0;
1626         return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type;
1627 }
1628
1629 /*
1630  * This function calls iscsit_inc_session_usage_count() on the
1631  * struct iscsi_session in question.
1632  */
1633 static void lio_tpg_close_session(struct se_session *se_sess)
1634 {
1635         struct iscsi_session *sess = se_sess->fabric_sess_ptr;
1636         struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg;
1637
1638         spin_lock_bh(&se_tpg->session_lock);
1639         spin_lock(&sess->conn_lock);
1640         if (atomic_read(&sess->session_fall_back_to_erl0) ||
1641             atomic_read(&sess->session_logout) ||
1642             (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) {
1643                 spin_unlock(&sess->conn_lock);
1644                 spin_unlock_bh(&se_tpg->session_lock);
1645                 return;
1646         }
1647         atomic_set(&sess->session_reinstatement, 1);
1648         spin_unlock(&sess->conn_lock);
1649
1650         iscsit_stop_time2retain_timer(sess);
1651         spin_unlock_bh(&se_tpg->session_lock);
1652
1653         iscsit_stop_session(sess, 1, 1);
1654         iscsit_close_session(sess);
1655 }
1656
1657 static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg)
1658 {
1659         return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index;
1660 }
1661
1662 static void lio_set_default_node_attributes(struct se_node_acl *se_acl)
1663 {
1664         struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl,
1665                                 se_node_acl);
1666         struct se_portal_group *se_tpg = se_acl->se_tpg;
1667         struct iscsi_portal_group *tpg = container_of(se_tpg,
1668                                 struct iscsi_portal_group, tpg_se_tpg);
1669
1670         acl->node_attrib.nacl = acl;
1671         iscsit_set_default_node_attribues(acl, tpg);
1672 }
1673
1674 static int lio_check_stop_free(struct se_cmd *se_cmd)
1675 {
1676         return target_put_sess_cmd(se_cmd);
1677 }
1678
1679 static void lio_release_cmd(struct se_cmd *se_cmd)
1680 {
1681         struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd);
1682
1683         pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd);
1684         iscsit_release_cmd(cmd);
1685 }
1686
1687 const struct target_core_fabric_ops iscsi_ops = {
1688         .module                         = THIS_MODULE,
1689         .name                           = "iscsi",
1690         .node_acl_size                  = sizeof(struct iscsi_node_acl),
1691         .get_fabric_name                = iscsi_get_fabric_name,
1692         .tpg_get_wwn                    = lio_tpg_get_endpoint_wwn,
1693         .tpg_get_tag                    = lio_tpg_get_tag,
1694         .tpg_get_default_depth          = lio_tpg_get_default_depth,
1695         .tpg_check_demo_mode            = lio_tpg_check_demo_mode,
1696         .tpg_check_demo_mode_cache      = lio_tpg_check_demo_mode_cache,
1697         .tpg_check_demo_mode_write_protect =
1698                         lio_tpg_check_demo_mode_write_protect,
1699         .tpg_check_prod_mode_write_protect =
1700                         lio_tpg_check_prod_mode_write_protect,
1701         .tpg_check_prot_fabric_only     = &lio_tpg_check_prot_fabric_only,
1702         .tpg_get_inst_index             = lio_tpg_get_inst_index,
1703         .check_stop_free                = lio_check_stop_free,
1704         .release_cmd                    = lio_release_cmd,
1705         .close_session                  = lio_tpg_close_session,
1706         .sess_get_index                 = lio_sess_get_index,
1707         .sess_get_initiator_sid         = lio_sess_get_initiator_sid,
1708         .write_pending                  = lio_write_pending,
1709         .write_pending_status           = lio_write_pending_status,
1710         .set_default_node_attributes    = lio_set_default_node_attributes,
1711         .get_cmd_state                  = iscsi_get_cmd_state,
1712         .queue_data_in                  = lio_queue_data_in,
1713         .queue_status                   = lio_queue_status,
1714         .queue_tm_rsp                   = lio_queue_tm_rsp,
1715         .aborted_task                   = lio_aborted_task,
1716         .fabric_make_wwn                = lio_target_call_coreaddtiqn,
1717         .fabric_drop_wwn                = lio_target_call_coredeltiqn,
1718         .add_wwn_groups                 = lio_target_add_wwn_groups,
1719         .fabric_make_tpg                = lio_target_tiqn_addtpg,
1720         .fabric_drop_tpg                = lio_target_tiqn_deltpg,
1721         .fabric_make_np                 = lio_target_call_addnptotpg,
1722         .fabric_drop_np                 = lio_target_call_delnpfromtpg,
1723         .fabric_init_nodeacl            = lio_target_init_nodeacl,
1724
1725         .tfc_discovery_attrs            = lio_target_discovery_auth_attrs,
1726         .tfc_wwn_attrs                  = lio_target_wwn_attrs,
1727         .tfc_tpg_base_attrs             = lio_target_tpg_attrs,
1728         .tfc_tpg_attrib_attrs           = lio_target_tpg_attrib_attrs,
1729         .tfc_tpg_auth_attrs             = lio_target_tpg_auth_attrs,
1730         .tfc_tpg_param_attrs            = lio_target_tpg_param_attrs,
1731         .tfc_tpg_np_base_attrs          = lio_target_portal_attrs,
1732         .tfc_tpg_nacl_base_attrs        = lio_target_initiator_attrs,
1733         .tfc_tpg_nacl_attrib_attrs      = lio_target_nacl_attrib_attrs,
1734         .tfc_tpg_nacl_auth_attrs        = lio_target_nacl_auth_attrs,
1735         .tfc_tpg_nacl_param_attrs       = lio_target_nacl_param_attrs,
1736 };