1 /*******************************************************************************
2 * This file contains iSCSI Target Portal Group related functions.
4 * (c) Copyright 2007-2013 Datera, Inc.
6 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 ******************************************************************************/
19 #include <linux/slab.h>
20 #include <target/target_core_base.h>
21 #include <target/target_core_fabric.h>
22 #include <target/iscsi/iscsi_target_core.h>
23 #include "iscsi_target_erl0.h"
24 #include "iscsi_target_login.h"
25 #include "iscsi_target_nodeattrib.h"
26 #include "iscsi_target_tpg.h"
27 #include "iscsi_target_util.h"
28 #include "iscsi_target.h"
29 #include "iscsi_target_parameters.h"
31 #include <target/iscsi/iscsi_transport.h>
33 struct iscsi_portal_group
*iscsit_alloc_portal_group(struct iscsi_tiqn
*tiqn
, u16 tpgt
)
35 struct iscsi_portal_group
*tpg
;
37 tpg
= kzalloc(sizeof(struct iscsi_portal_group
), GFP_KERNEL
);
39 pr_err("Unable to allocate struct iscsi_portal_group\n");
44 tpg
->tpg_state
= TPG_STATE_FREE
;
46 INIT_LIST_HEAD(&tpg
->tpg_gnp_list
);
47 INIT_LIST_HEAD(&tpg
->tpg_list
);
48 mutex_init(&tpg
->tpg_access_lock
);
49 sema_init(&tpg
->np_login_sem
, 1);
50 spin_lock_init(&tpg
->tpg_state_lock
);
51 spin_lock_init(&tpg
->tpg_np_lock
);
56 static void iscsit_set_default_tpg_attribs(struct iscsi_portal_group
*);
58 int iscsit_load_discovery_tpg(void)
60 struct iscsi_param
*param
;
61 struct iscsi_portal_group
*tpg
;
64 tpg
= iscsit_alloc_portal_group(NULL
, 1);
66 pr_err("Unable to allocate struct iscsi_portal_group\n");
70 * Save iscsi_ops pointer for special case discovery TPG that
71 * doesn't exist as se_wwn->wwn_group within configfs.
73 tpg
->tpg_se_tpg
.se_tpg_tfo
= &iscsi_ops
;
74 ret
= core_tpg_register(NULL
, &tpg
->tpg_se_tpg
, -1);
80 tpg
->sid
= 1; /* First Assigned LIO Session ID */
81 iscsit_set_default_tpg_attribs(tpg
);
83 if (iscsi_create_default_params(&tpg
->param_list
) < 0)
86 * By default we disable authentication for discovery sessions,
87 * this can be changed with:
89 * /sys/kernel/config/target/iscsi/discovery_auth/enforce_discovery_auth
91 param
= iscsi_find_param_from_key(AUTHMETHOD
, tpg
->param_list
);
95 if (iscsi_update_param_value(param
, "CHAP,None") < 0)
98 tpg
->tpg_attrib
.authentication
= 0;
100 spin_lock(&tpg
->tpg_state_lock
);
101 tpg
->tpg_state
= TPG_STATE_ACTIVE
;
102 spin_unlock(&tpg
->tpg_state_lock
);
104 iscsit_global
->discovery_tpg
= tpg
;
105 pr_debug("CORE[0] - Allocated Discovery TPG\n");
109 iscsi_release_param_list(tpg
->param_list
);
112 core_tpg_deregister(&tpg
->tpg_se_tpg
);
117 void iscsit_release_discovery_tpg(void)
119 struct iscsi_portal_group
*tpg
= iscsit_global
->discovery_tpg
;
124 iscsi_release_param_list(tpg
->param_list
);
125 core_tpg_deregister(&tpg
->tpg_se_tpg
);
128 iscsit_global
->discovery_tpg
= NULL
;
131 struct iscsi_portal_group
*iscsit_get_tpg_from_np(
132 struct iscsi_tiqn
*tiqn
,
134 struct iscsi_tpg_np
**tpg_np_out
)
136 struct iscsi_portal_group
*tpg
= NULL
;
137 struct iscsi_tpg_np
*tpg_np
;
139 spin_lock(&tiqn
->tiqn_tpg_lock
);
140 list_for_each_entry(tpg
, &tiqn
->tiqn_tpg_list
, tpg_list
) {
142 spin_lock(&tpg
->tpg_state_lock
);
143 if (tpg
->tpg_state
!= TPG_STATE_ACTIVE
) {
144 spin_unlock(&tpg
->tpg_state_lock
);
147 spin_unlock(&tpg
->tpg_state_lock
);
149 spin_lock(&tpg
->tpg_np_lock
);
150 list_for_each_entry(tpg_np
, &tpg
->tpg_gnp_list
, tpg_np_list
) {
151 if (tpg_np
->tpg_np
== np
) {
152 *tpg_np_out
= tpg_np
;
153 kref_get(&tpg_np
->tpg_np_kref
);
154 spin_unlock(&tpg
->tpg_np_lock
);
155 spin_unlock(&tiqn
->tiqn_tpg_lock
);
159 spin_unlock(&tpg
->tpg_np_lock
);
161 spin_unlock(&tiqn
->tiqn_tpg_lock
);
167 struct iscsi_portal_group
*tpg
)
169 return mutex_lock_interruptible(&tpg
->tpg_access_lock
);
172 void iscsit_put_tpg(struct iscsi_portal_group
*tpg
)
174 mutex_unlock(&tpg
->tpg_access_lock
);
177 static void iscsit_clear_tpg_np_login_thread(
178 struct iscsi_tpg_np
*tpg_np
,
179 struct iscsi_portal_group
*tpg
,
182 if (!tpg_np
->tpg_np
) {
183 pr_err("struct iscsi_tpg_np->tpg_np is NULL!\n");
188 tpg_np
->tpg_np
->enabled
= false;
189 iscsit_reset_np_thread(tpg_np
->tpg_np
, tpg_np
, tpg
, shutdown
);
192 static void iscsit_clear_tpg_np_login_threads(
193 struct iscsi_portal_group
*tpg
,
196 struct iscsi_tpg_np
*tpg_np
;
198 spin_lock(&tpg
->tpg_np_lock
);
199 list_for_each_entry(tpg_np
, &tpg
->tpg_gnp_list
, tpg_np_list
) {
200 if (!tpg_np
->tpg_np
) {
201 pr_err("struct iscsi_tpg_np->tpg_np is NULL!\n");
204 spin_unlock(&tpg
->tpg_np_lock
);
205 iscsit_clear_tpg_np_login_thread(tpg_np
, tpg
, shutdown
);
206 spin_lock(&tpg
->tpg_np_lock
);
208 spin_unlock(&tpg
->tpg_np_lock
);
211 void iscsit_tpg_dump_params(struct iscsi_portal_group
*tpg
)
213 iscsi_print_params(tpg
->param_list
);
216 static void iscsit_set_default_tpg_attribs(struct iscsi_portal_group
*tpg
)
218 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
220 a
->authentication
= TA_AUTHENTICATION
;
221 a
->login_timeout
= TA_LOGIN_TIMEOUT
;
222 a
->netif_timeout
= TA_NETIF_TIMEOUT
;
223 a
->default_cmdsn_depth
= TA_DEFAULT_CMDSN_DEPTH
;
224 a
->generate_node_acls
= TA_GENERATE_NODE_ACLS
;
225 a
->cache_dynamic_acls
= TA_CACHE_DYNAMIC_ACLS
;
226 a
->demo_mode_write_protect
= TA_DEMO_MODE_WRITE_PROTECT
;
227 a
->prod_mode_write_protect
= TA_PROD_MODE_WRITE_PROTECT
;
228 a
->demo_mode_discovery
= TA_DEMO_MODE_DISCOVERY
;
229 a
->default_erl
= TA_DEFAULT_ERL
;
230 a
->t10_pi
= TA_DEFAULT_T10_PI
;
231 a
->fabric_prot_type
= TA_DEFAULT_FABRIC_PROT_TYPE
;
232 a
->tpg_enabled_sendtargets
= TA_DEFAULT_TPG_ENABLED_SENDTARGETS
;
233 a
->login_keys_workaround
= TA_DEFAULT_LOGIN_KEYS_WORKAROUND
;
236 int iscsit_tpg_add_portal_group(struct iscsi_tiqn
*tiqn
, struct iscsi_portal_group
*tpg
)
238 if (tpg
->tpg_state
!= TPG_STATE_FREE
) {
239 pr_err("Unable to add iSCSI Target Portal Group: %d"
240 " while not in TPG_STATE_FREE state.\n", tpg
->tpgt
);
243 iscsit_set_default_tpg_attribs(tpg
);
245 if (iscsi_create_default_params(&tpg
->param_list
) < 0)
248 tpg
->tpg_attrib
.tpg
= tpg
;
250 spin_lock(&tpg
->tpg_state_lock
);
251 tpg
->tpg_state
= TPG_STATE_INACTIVE
;
252 spin_unlock(&tpg
->tpg_state_lock
);
254 spin_lock(&tiqn
->tiqn_tpg_lock
);
255 list_add_tail(&tpg
->tpg_list
, &tiqn
->tiqn_tpg_list
);
257 pr_debug("CORE[%s]_TPG[%hu] - Added iSCSI Target Portal Group\n",
258 tiqn
->tiqn
, tpg
->tpgt
);
259 spin_unlock(&tiqn
->tiqn_tpg_lock
);
263 if (tpg
->param_list
) {
264 iscsi_release_param_list(tpg
->param_list
);
265 tpg
->param_list
= NULL
;
270 int iscsit_tpg_del_portal_group(
271 struct iscsi_tiqn
*tiqn
,
272 struct iscsi_portal_group
*tpg
,
275 u8 old_state
= tpg
->tpg_state
;
277 spin_lock(&tpg
->tpg_state_lock
);
278 tpg
->tpg_state
= TPG_STATE_INACTIVE
;
279 spin_unlock(&tpg
->tpg_state_lock
);
281 if (iscsit_release_sessions_for_tpg(tpg
, force
) < 0) {
282 pr_err("Unable to delete iSCSI Target Portal Group:"
283 " %hu while active sessions exist, and force=0\n",
285 tpg
->tpg_state
= old_state
;
289 if (tpg
->param_list
) {
290 iscsi_release_param_list(tpg
->param_list
);
291 tpg
->param_list
= NULL
;
294 core_tpg_deregister(&tpg
->tpg_se_tpg
);
296 spin_lock(&tpg
->tpg_state_lock
);
297 tpg
->tpg_state
= TPG_STATE_FREE
;
298 spin_unlock(&tpg
->tpg_state_lock
);
300 spin_lock(&tiqn
->tiqn_tpg_lock
);
302 list_del(&tpg
->tpg_list
);
303 spin_unlock(&tiqn
->tiqn_tpg_lock
);
305 pr_debug("CORE[%s]_TPG[%hu] - Deleted iSCSI Target Portal Group\n",
306 tiqn
->tiqn
, tpg
->tpgt
);
312 int iscsit_tpg_enable_portal_group(struct iscsi_portal_group
*tpg
)
314 struct iscsi_param
*param
;
315 struct iscsi_tiqn
*tiqn
= tpg
->tpg_tiqn
;
318 if (tpg
->tpg_state
== TPG_STATE_ACTIVE
) {
319 pr_err("iSCSI target portal group: %hu is already"
320 " active, ignoring request.\n", tpg
->tpgt
);
324 * Make sure that AuthMethod does not contain None as an option
325 * unless explictly disabled. Set the default to CHAP if authentication
326 * is enforced (as per default), and remove the NONE option.
328 param
= iscsi_find_param_from_key(AUTHMETHOD
, tpg
->param_list
);
332 if (tpg
->tpg_attrib
.authentication
) {
333 if (!strcmp(param
->value
, NONE
)) {
334 ret
= iscsi_update_param_value(param
, CHAP
);
339 ret
= iscsit_ta_authentication(tpg
, 1);
344 spin_lock(&tpg
->tpg_state_lock
);
345 tpg
->tpg_state
= TPG_STATE_ACTIVE
;
346 spin_unlock(&tpg
->tpg_state_lock
);
348 spin_lock(&tiqn
->tiqn_tpg_lock
);
349 tiqn
->tiqn_active_tpgs
++;
350 pr_debug("iSCSI_TPG[%hu] - Enabled iSCSI Target Portal Group\n",
352 spin_unlock(&tiqn
->tiqn_tpg_lock
);
360 int iscsit_tpg_disable_portal_group(struct iscsi_portal_group
*tpg
, int force
)
362 struct iscsi_tiqn
*tiqn
;
363 u8 old_state
= tpg
->tpg_state
;
365 spin_lock(&tpg
->tpg_state_lock
);
366 if (tpg
->tpg_state
== TPG_STATE_INACTIVE
) {
367 pr_err("iSCSI Target Portal Group: %hu is already"
368 " inactive, ignoring request.\n", tpg
->tpgt
);
369 spin_unlock(&tpg
->tpg_state_lock
);
372 tpg
->tpg_state
= TPG_STATE_INACTIVE
;
373 spin_unlock(&tpg
->tpg_state_lock
);
375 iscsit_clear_tpg_np_login_threads(tpg
, false);
377 if (iscsit_release_sessions_for_tpg(tpg
, force
) < 0) {
378 spin_lock(&tpg
->tpg_state_lock
);
379 tpg
->tpg_state
= old_state
;
380 spin_unlock(&tpg
->tpg_state_lock
);
381 pr_err("Unable to disable iSCSI Target Portal Group:"
382 " %hu while active sessions exist, and force=0\n",
387 tiqn
= tpg
->tpg_tiqn
;
388 if (!tiqn
|| (tpg
== iscsit_global
->discovery_tpg
))
391 spin_lock(&tiqn
->tiqn_tpg_lock
);
392 tiqn
->tiqn_active_tpgs
--;
393 pr_debug("iSCSI_TPG[%hu] - Disabled iSCSI Target Portal Group\n",
395 spin_unlock(&tiqn
->tiqn_tpg_lock
);
400 struct iscsi_node_attrib
*iscsit_tpg_get_node_attrib(
401 struct iscsi_session
*sess
)
403 struct se_session
*se_sess
= sess
->se_sess
;
404 struct se_node_acl
*se_nacl
= se_sess
->se_node_acl
;
405 struct iscsi_node_acl
*acl
= container_of(se_nacl
, struct iscsi_node_acl
,
408 return &acl
->node_attrib
;
411 struct iscsi_tpg_np
*iscsit_tpg_locate_child_np(
412 struct iscsi_tpg_np
*tpg_np
,
413 int network_transport
)
415 struct iscsi_tpg_np
*tpg_np_child
, *tpg_np_child_tmp
;
417 spin_lock(&tpg_np
->tpg_np_parent_lock
);
418 list_for_each_entry_safe(tpg_np_child
, tpg_np_child_tmp
,
419 &tpg_np
->tpg_np_parent_list
, tpg_np_child_list
) {
420 if (tpg_np_child
->tpg_np
->np_network_transport
==
422 spin_unlock(&tpg_np
->tpg_np_parent_lock
);
426 spin_unlock(&tpg_np
->tpg_np_parent_lock
);
431 static bool iscsit_tpg_check_network_portal(
432 struct iscsi_tiqn
*tiqn
,
433 struct sockaddr_storage
*sockaddr
,
434 int network_transport
)
436 struct iscsi_portal_group
*tpg
;
437 struct iscsi_tpg_np
*tpg_np
;
441 spin_lock(&tiqn
->tiqn_tpg_lock
);
442 list_for_each_entry(tpg
, &tiqn
->tiqn_tpg_list
, tpg_list
) {
444 spin_lock(&tpg
->tpg_np_lock
);
445 list_for_each_entry(tpg_np
, &tpg
->tpg_gnp_list
, tpg_np_list
) {
448 match
= iscsit_check_np_match(sockaddr
, np
,
453 spin_unlock(&tpg
->tpg_np_lock
);
455 spin_unlock(&tiqn
->tiqn_tpg_lock
);
460 struct iscsi_tpg_np
*iscsit_tpg_add_network_portal(
461 struct iscsi_portal_group
*tpg
,
462 struct sockaddr_storage
*sockaddr
,
463 struct iscsi_tpg_np
*tpg_np_parent
,
464 int network_transport
)
467 struct iscsi_tpg_np
*tpg_np
;
469 if (!tpg_np_parent
) {
470 if (iscsit_tpg_check_network_portal(tpg
->tpg_tiqn
, sockaddr
,
471 network_transport
)) {
472 pr_err("Network Portal: %pISc already exists on a"
473 " different TPG on %s\n", sockaddr
,
474 tpg
->tpg_tiqn
->tiqn
);
475 return ERR_PTR(-EEXIST
);
479 tpg_np
= kzalloc(sizeof(struct iscsi_tpg_np
), GFP_KERNEL
);
481 pr_err("Unable to allocate memory for"
482 " struct iscsi_tpg_np.\n");
483 return ERR_PTR(-ENOMEM
);
486 np
= iscsit_add_np(sockaddr
, network_transport
);
492 INIT_LIST_HEAD(&tpg_np
->tpg_np_list
);
493 INIT_LIST_HEAD(&tpg_np
->tpg_np_child_list
);
494 INIT_LIST_HEAD(&tpg_np
->tpg_np_parent_list
);
495 spin_lock_init(&tpg_np
->tpg_np_parent_lock
);
496 init_completion(&tpg_np
->tpg_np_comp
);
497 kref_init(&tpg_np
->tpg_np_kref
);
501 spin_lock(&tpg
->tpg_np_lock
);
502 list_add_tail(&tpg_np
->tpg_np_list
, &tpg
->tpg_gnp_list
);
505 tpg
->tpg_tiqn
->tiqn_num_tpg_nps
++;
506 spin_unlock(&tpg
->tpg_np_lock
);
509 tpg_np
->tpg_np_parent
= tpg_np_parent
;
510 spin_lock(&tpg_np_parent
->tpg_np_parent_lock
);
511 list_add_tail(&tpg_np
->tpg_np_child_list
,
512 &tpg_np_parent
->tpg_np_parent_list
);
513 spin_unlock(&tpg_np_parent
->tpg_np_parent_lock
);
516 pr_debug("CORE[%s] - Added Network Portal: %pISpc,%hu on %s\n",
517 tpg
->tpg_tiqn
->tiqn
, &np
->np_sockaddr
, tpg
->tpgt
,
518 np
->np_transport
->name
);
523 static int iscsit_tpg_release_np(
524 struct iscsi_tpg_np
*tpg_np
,
525 struct iscsi_portal_group
*tpg
,
528 iscsit_clear_tpg_np_login_thread(tpg_np
, tpg
, true);
530 pr_debug("CORE[%s] - Removed Network Portal: %pISpc,%hu on %s\n",
531 tpg
->tpg_tiqn
->tiqn
, &np
->np_sockaddr
, tpg
->tpgt
,
532 np
->np_transport
->name
);
534 tpg_np
->tpg_np
= NULL
;
538 * iscsit_del_np() will shutdown struct iscsi_np when last TPG reference is released.
540 return iscsit_del_np(np
);
543 int iscsit_tpg_del_network_portal(
544 struct iscsi_portal_group
*tpg
,
545 struct iscsi_tpg_np
*tpg_np
)
548 struct iscsi_tpg_np
*tpg_np_child
, *tpg_np_child_tmp
;
553 pr_err("Unable to locate struct iscsi_np from"
554 " struct iscsi_tpg_np\n");
558 if (!tpg_np
->tpg_np_parent
) {
560 * We are the parent tpg network portal. Release all of the
561 * child tpg_np's (eg: the non ISCSI_TCP ones) on our parent
564 list_for_each_entry_safe(tpg_np_child
, tpg_np_child_tmp
,
565 &tpg_np
->tpg_np_parent_list
,
567 ret
= iscsit_tpg_del_network_portal(tpg
, tpg_np_child
);
569 pr_err("iscsit_tpg_del_network_portal()"
570 " failed: %d\n", ret
);
574 * We are not the parent ISCSI_TCP tpg network portal. Release
575 * our own network portals from the child list.
577 spin_lock(&tpg_np
->tpg_np_parent
->tpg_np_parent_lock
);
578 list_del(&tpg_np
->tpg_np_child_list
);
579 spin_unlock(&tpg_np
->tpg_np_parent
->tpg_np_parent_lock
);
582 spin_lock(&tpg
->tpg_np_lock
);
583 list_del(&tpg_np
->tpg_np_list
);
586 tpg
->tpg_tiqn
->tiqn_num_tpg_nps
--;
587 spin_unlock(&tpg
->tpg_np_lock
);
589 return iscsit_tpg_release_np(tpg_np
, tpg
, np
);
592 int iscsit_ta_authentication(struct iscsi_portal_group
*tpg
, u32 authentication
)
594 unsigned char buf1
[256], buf2
[256], *none
= NULL
;
596 struct iscsi_param
*param
;
597 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
599 if ((authentication
!= 1) && (authentication
!= 0)) {
600 pr_err("Illegal value for authentication parameter:"
601 " %u, ignoring request.\n", authentication
);
605 memset(buf1
, 0, sizeof(buf1
));
606 memset(buf2
, 0, sizeof(buf2
));
608 param
= iscsi_find_param_from_key(AUTHMETHOD
, tpg
->param_list
);
612 if (authentication
) {
613 snprintf(buf1
, sizeof(buf1
), "%s", param
->value
);
614 none
= strstr(buf1
, NONE
);
617 if (!strncmp(none
+ 4, ",", 1)) {
618 if (!strcmp(buf1
, none
))
619 sprintf(buf2
, "%s", none
+5);
623 len
= sprintf(buf2
, "%s", buf1
);
625 sprintf(buf2
+ len
, "%s", none
);
630 sprintf(buf2
, "%s", buf1
);
632 if (iscsi_update_param_value(param
, buf2
) < 0)
635 snprintf(buf1
, sizeof(buf1
), "%s", param
->value
);
636 none
= strstr(buf1
, NONE
);
639 strlcat(buf1
, "," NONE
, sizeof(buf1
));
640 if (iscsi_update_param_value(param
, buf1
) < 0)
645 a
->authentication
= authentication
;
646 pr_debug("%s iSCSI Authentication Methods for TPG: %hu.\n",
647 a
->authentication
? "Enforcing" : "Disabling", tpg
->tpgt
);
652 int iscsit_ta_login_timeout(
653 struct iscsi_portal_group
*tpg
,
656 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
658 if (login_timeout
> TA_LOGIN_TIMEOUT_MAX
) {
659 pr_err("Requested Login Timeout %u larger than maximum"
660 " %u\n", login_timeout
, TA_LOGIN_TIMEOUT_MAX
);
662 } else if (login_timeout
< TA_LOGIN_TIMEOUT_MIN
) {
663 pr_err("Requested Logout Timeout %u smaller than"
664 " minimum %u\n", login_timeout
, TA_LOGIN_TIMEOUT_MIN
);
668 a
->login_timeout
= login_timeout
;
669 pr_debug("Set Logout Timeout to %u for Target Portal Group"
670 " %hu\n", a
->login_timeout
, tpg
->tpgt
);
675 int iscsit_ta_netif_timeout(
676 struct iscsi_portal_group
*tpg
,
679 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
681 if (netif_timeout
> TA_NETIF_TIMEOUT_MAX
) {
682 pr_err("Requested Network Interface Timeout %u larger"
683 " than maximum %u\n", netif_timeout
,
684 TA_NETIF_TIMEOUT_MAX
);
686 } else if (netif_timeout
< TA_NETIF_TIMEOUT_MIN
) {
687 pr_err("Requested Network Interface Timeout %u smaller"
688 " than minimum %u\n", netif_timeout
,
689 TA_NETIF_TIMEOUT_MIN
);
693 a
->netif_timeout
= netif_timeout
;
694 pr_debug("Set Network Interface Timeout to %u for"
695 " Target Portal Group %hu\n", a
->netif_timeout
, tpg
->tpgt
);
700 int iscsit_ta_generate_node_acls(
701 struct iscsi_portal_group
*tpg
,
704 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
706 if ((flag
!= 0) && (flag
!= 1)) {
707 pr_err("Illegal value %d\n", flag
);
711 a
->generate_node_acls
= flag
;
712 pr_debug("iSCSI_TPG[%hu] - Generate Initiator Portal Group ACLs: %s\n",
713 tpg
->tpgt
, (a
->generate_node_acls
) ? "Enabled" : "Disabled");
715 if (flag
== 1 && a
->cache_dynamic_acls
== 0) {
716 pr_debug("Explicitly setting cache_dynamic_acls=1 when "
717 "generate_node_acls=1\n");
718 a
->cache_dynamic_acls
= 1;
724 int iscsit_ta_default_cmdsn_depth(
725 struct iscsi_portal_group
*tpg
,
728 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
730 if (tcq_depth
> TA_DEFAULT_CMDSN_DEPTH_MAX
) {
731 pr_err("Requested Default Queue Depth: %u larger"
732 " than maximum %u\n", tcq_depth
,
733 TA_DEFAULT_CMDSN_DEPTH_MAX
);
735 } else if (tcq_depth
< TA_DEFAULT_CMDSN_DEPTH_MIN
) {
736 pr_err("Requested Default Queue Depth: %u smaller"
737 " than minimum %u\n", tcq_depth
,
738 TA_DEFAULT_CMDSN_DEPTH_MIN
);
742 a
->default_cmdsn_depth
= tcq_depth
;
743 pr_debug("iSCSI_TPG[%hu] - Set Default CmdSN TCQ Depth to %u\n",
744 tpg
->tpgt
, a
->default_cmdsn_depth
);
749 int iscsit_ta_cache_dynamic_acls(
750 struct iscsi_portal_group
*tpg
,
753 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
755 if ((flag
!= 0) && (flag
!= 1)) {
756 pr_err("Illegal value %d\n", flag
);
760 if (a
->generate_node_acls
== 1 && flag
== 0) {
761 pr_debug("Skipping cache_dynamic_acls=0 when"
762 " generate_node_acls=1\n");
766 a
->cache_dynamic_acls
= flag
;
767 pr_debug("iSCSI_TPG[%hu] - Cache Dynamic Initiator Portal Group"
768 " ACLs %s\n", tpg
->tpgt
, (a
->cache_dynamic_acls
) ?
769 "Enabled" : "Disabled");
774 int iscsit_ta_demo_mode_write_protect(
775 struct iscsi_portal_group
*tpg
,
778 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
780 if ((flag
!= 0) && (flag
!= 1)) {
781 pr_err("Illegal value %d\n", flag
);
785 a
->demo_mode_write_protect
= flag
;
786 pr_debug("iSCSI_TPG[%hu] - Demo Mode Write Protect bit: %s\n",
787 tpg
->tpgt
, (a
->demo_mode_write_protect
) ? "ON" : "OFF");
792 int iscsit_ta_prod_mode_write_protect(
793 struct iscsi_portal_group
*tpg
,
796 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
798 if ((flag
!= 0) && (flag
!= 1)) {
799 pr_err("Illegal value %d\n", flag
);
803 a
->prod_mode_write_protect
= flag
;
804 pr_debug("iSCSI_TPG[%hu] - Production Mode Write Protect bit:"
805 " %s\n", tpg
->tpgt
, (a
->prod_mode_write_protect
) ?
811 int iscsit_ta_demo_mode_discovery(
812 struct iscsi_portal_group
*tpg
,
815 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
817 if ((flag
!= 0) && (flag
!= 1)) {
818 pr_err("Illegal value %d\n", flag
);
822 a
->demo_mode_discovery
= flag
;
823 pr_debug("iSCSI_TPG[%hu] - Demo Mode Discovery bit:"
824 " %s\n", tpg
->tpgt
, (a
->demo_mode_discovery
) ?
830 int iscsit_ta_default_erl(
831 struct iscsi_portal_group
*tpg
,
834 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
836 if ((default_erl
!= 0) && (default_erl
!= 1) && (default_erl
!= 2)) {
837 pr_err("Illegal value for default_erl: %u\n", default_erl
);
841 a
->default_erl
= default_erl
;
842 pr_debug("iSCSI_TPG[%hu] - DefaultERL: %u\n", tpg
->tpgt
, a
->default_erl
);
847 int iscsit_ta_t10_pi(
848 struct iscsi_portal_group
*tpg
,
851 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
853 if ((flag
!= 0) && (flag
!= 1)) {
854 pr_err("Illegal value %d\n", flag
);
859 pr_debug("iSCSI_TPG[%hu] - T10 Protection information bit:"
860 " %s\n", tpg
->tpgt
, (a
->t10_pi
) ?
866 int iscsit_ta_fabric_prot_type(
867 struct iscsi_portal_group
*tpg
,
870 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
872 if ((prot_type
!= 0) && (prot_type
!= 1) && (prot_type
!= 3)) {
873 pr_err("Illegal value for fabric_prot_type: %u\n", prot_type
);
877 a
->fabric_prot_type
= prot_type
;
878 pr_debug("iSCSI_TPG[%hu] - T10 Fabric Protection Type: %u\n",
879 tpg
->tpgt
, prot_type
);
884 int iscsit_ta_tpg_enabled_sendtargets(
885 struct iscsi_portal_group
*tpg
,
888 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
890 if ((flag
!= 0) && (flag
!= 1)) {
891 pr_err("Illegal value %d\n", flag
);
895 a
->tpg_enabled_sendtargets
= flag
;
896 pr_debug("iSCSI_TPG[%hu] - TPG enabled bit required for SendTargets:"
897 " %s\n", tpg
->tpgt
, (a
->tpg_enabled_sendtargets
) ? "ON" : "OFF");
902 int iscsit_ta_login_keys_workaround(
903 struct iscsi_portal_group
*tpg
,
906 struct iscsi_tpg_attrib
*a
= &tpg
->tpg_attrib
;
908 if ((flag
!= 0) && (flag
!= 1)) {
909 pr_err("Illegal value %d\n", flag
);
913 a
->login_keys_workaround
= flag
;
914 pr_debug("iSCSI_TPG[%hu] - TPG enabled bit for login keys workaround: %s ",
915 tpg
->tpgt
, (a
->login_keys_workaround
) ? "ON" : "OFF");