Linux 3.11-rc3
[cris-mirror.git] / drivers / target / iscsi / iscsi_target_tpg.c
blob439260b7d87fa69a7e379c66e4474c416e35a21d
1 /*******************************************************************************
2 * This file contains iSCSI Target Portal Group related functions.
4 * \u00a9 Copyright 2007-2011 RisingTide Systems LLC.
6 * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
8 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 ******************************************************************************/
21 #include <target/target_core_base.h>
22 #include <target/target_core_fabric.h>
23 #include <target/target_core_configfs.h>
25 #include "iscsi_target_core.h"
26 #include "iscsi_target_erl0.h"
27 #include "iscsi_target_login.h"
28 #include "iscsi_target_nodeattrib.h"
29 #include "iscsi_target_tpg.h"
30 #include "iscsi_target_util.h"
31 #include "iscsi_target.h"
32 #include "iscsi_target_parameters.h"
34 #include <target/iscsi/iscsi_transport.h>
36 struct iscsi_portal_group *iscsit_alloc_portal_group(struct iscsi_tiqn *tiqn, u16 tpgt)
38 struct iscsi_portal_group *tpg;
40 tpg = kzalloc(sizeof(struct iscsi_portal_group), GFP_KERNEL);
41 if (!tpg) {
42 pr_err("Unable to allocate struct iscsi_portal_group\n");
43 return NULL;
46 tpg->tpgt = tpgt;
47 tpg->tpg_state = TPG_STATE_FREE;
48 tpg->tpg_tiqn = tiqn;
49 INIT_LIST_HEAD(&tpg->tpg_gnp_list);
50 INIT_LIST_HEAD(&tpg->tpg_list);
51 mutex_init(&tpg->tpg_access_lock);
52 mutex_init(&tpg->np_login_lock);
53 spin_lock_init(&tpg->tpg_state_lock);
54 spin_lock_init(&tpg->tpg_np_lock);
56 return tpg;
59 static void iscsit_set_default_tpg_attribs(struct iscsi_portal_group *);
61 int iscsit_load_discovery_tpg(void)
63 struct iscsi_param *param;
64 struct iscsi_portal_group *tpg;
65 int ret;
67 tpg = iscsit_alloc_portal_group(NULL, 1);
68 if (!tpg) {
69 pr_err("Unable to allocate struct iscsi_portal_group\n");
70 return -1;
73 ret = core_tpg_register(
74 &lio_target_fabric_configfs->tf_ops,
75 NULL, &tpg->tpg_se_tpg, tpg,
76 TRANSPORT_TPG_TYPE_DISCOVERY);
77 if (ret < 0) {
78 kfree(tpg);
79 return -1;
82 tpg->sid = 1; /* First Assigned LIO Session ID */
83 iscsit_set_default_tpg_attribs(tpg);
85 if (iscsi_create_default_params(&tpg->param_list) < 0)
86 goto out;
88 * By default we disable authentication for discovery sessions,
89 * this can be changed with:
91 * /sys/kernel/config/target/iscsi/discovery_auth/enforce_discovery_auth
93 param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list);
94 if (!param)
95 goto out;
97 if (iscsi_update_param_value(param, "CHAP,None") < 0)
98 goto out;
100 tpg->tpg_attrib.authentication = 0;
102 spin_lock(&tpg->tpg_state_lock);
103 tpg->tpg_state = TPG_STATE_ACTIVE;
104 spin_unlock(&tpg->tpg_state_lock);
106 iscsit_global->discovery_tpg = tpg;
107 pr_debug("CORE[0] - Allocated Discovery TPG\n");
109 return 0;
110 out:
111 if (tpg->sid == 1)
112 core_tpg_deregister(&tpg->tpg_se_tpg);
113 kfree(tpg);
114 return -1;
117 void iscsit_release_discovery_tpg(void)
119 struct iscsi_portal_group *tpg = iscsit_global->discovery_tpg;
121 if (!tpg)
122 return;
124 core_tpg_deregister(&tpg->tpg_se_tpg);
126 kfree(tpg);
127 iscsit_global->discovery_tpg = NULL;
130 struct iscsi_portal_group *iscsit_get_tpg_from_np(
131 struct iscsi_tiqn *tiqn,
132 struct iscsi_np *np)
134 struct iscsi_portal_group *tpg = NULL;
135 struct iscsi_tpg_np *tpg_np;
137 spin_lock(&tiqn->tiqn_tpg_lock);
138 list_for_each_entry(tpg, &tiqn->tiqn_tpg_list, tpg_list) {
140 spin_lock(&tpg->tpg_state_lock);
141 if (tpg->tpg_state == TPG_STATE_FREE) {
142 spin_unlock(&tpg->tpg_state_lock);
143 continue;
145 spin_unlock(&tpg->tpg_state_lock);
147 spin_lock(&tpg->tpg_np_lock);
148 list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, tpg_np_list) {
149 if (tpg_np->tpg_np == np) {
150 spin_unlock(&tpg->tpg_np_lock);
151 spin_unlock(&tiqn->tiqn_tpg_lock);
152 return tpg;
155 spin_unlock(&tpg->tpg_np_lock);
157 spin_unlock(&tiqn->tiqn_tpg_lock);
159 return NULL;
162 int iscsit_get_tpg(
163 struct iscsi_portal_group *tpg)
165 int ret;
167 ret = mutex_lock_interruptible(&tpg->tpg_access_lock);
168 return ((ret != 0) || signal_pending(current)) ? -1 : 0;
171 void iscsit_put_tpg(struct iscsi_portal_group *tpg)
173 mutex_unlock(&tpg->tpg_access_lock);
176 static void iscsit_clear_tpg_np_login_thread(
177 struct iscsi_tpg_np *tpg_np,
178 struct iscsi_portal_group *tpg)
180 if (!tpg_np->tpg_np) {
181 pr_err("struct iscsi_tpg_np->tpg_np is NULL!\n");
182 return;
185 iscsit_reset_np_thread(tpg_np->tpg_np, tpg_np, tpg);
188 void iscsit_clear_tpg_np_login_threads(
189 struct iscsi_portal_group *tpg)
191 struct iscsi_tpg_np *tpg_np;
193 spin_lock(&tpg->tpg_np_lock);
194 list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, tpg_np_list) {
195 if (!tpg_np->tpg_np) {
196 pr_err("struct iscsi_tpg_np->tpg_np is NULL!\n");
197 continue;
199 spin_unlock(&tpg->tpg_np_lock);
200 iscsit_clear_tpg_np_login_thread(tpg_np, tpg);
201 spin_lock(&tpg->tpg_np_lock);
203 spin_unlock(&tpg->tpg_np_lock);
206 void iscsit_tpg_dump_params(struct iscsi_portal_group *tpg)
208 iscsi_print_params(tpg->param_list);
211 static void iscsit_set_default_tpg_attribs(struct iscsi_portal_group *tpg)
213 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
215 a->authentication = TA_AUTHENTICATION;
216 a->login_timeout = TA_LOGIN_TIMEOUT;
217 a->netif_timeout = TA_NETIF_TIMEOUT;
218 a->default_cmdsn_depth = TA_DEFAULT_CMDSN_DEPTH;
219 a->generate_node_acls = TA_GENERATE_NODE_ACLS;
220 a->cache_dynamic_acls = TA_CACHE_DYNAMIC_ACLS;
221 a->demo_mode_write_protect = TA_DEMO_MODE_WRITE_PROTECT;
222 a->prod_mode_write_protect = TA_PROD_MODE_WRITE_PROTECT;
225 int iscsit_tpg_add_portal_group(struct iscsi_tiqn *tiqn, struct iscsi_portal_group *tpg)
227 if (tpg->tpg_state != TPG_STATE_FREE) {
228 pr_err("Unable to add iSCSI Target Portal Group: %d"
229 " while not in TPG_STATE_FREE state.\n", tpg->tpgt);
230 return -EEXIST;
232 iscsit_set_default_tpg_attribs(tpg);
234 if (iscsi_create_default_params(&tpg->param_list) < 0)
235 goto err_out;
237 ISCSI_TPG_ATTRIB(tpg)->tpg = tpg;
239 spin_lock(&tpg->tpg_state_lock);
240 tpg->tpg_state = TPG_STATE_INACTIVE;
241 spin_unlock(&tpg->tpg_state_lock);
243 spin_lock(&tiqn->tiqn_tpg_lock);
244 list_add_tail(&tpg->tpg_list, &tiqn->tiqn_tpg_list);
245 tiqn->tiqn_ntpgs++;
246 pr_debug("CORE[%s]_TPG[%hu] - Added iSCSI Target Portal Group\n",
247 tiqn->tiqn, tpg->tpgt);
248 spin_unlock(&tiqn->tiqn_tpg_lock);
250 return 0;
251 err_out:
252 if (tpg->param_list) {
253 iscsi_release_param_list(tpg->param_list);
254 tpg->param_list = NULL;
256 kfree(tpg);
257 return -ENOMEM;
260 int iscsit_tpg_del_portal_group(
261 struct iscsi_tiqn *tiqn,
262 struct iscsi_portal_group *tpg,
263 int force)
265 u8 old_state = tpg->tpg_state;
267 spin_lock(&tpg->tpg_state_lock);
268 tpg->tpg_state = TPG_STATE_INACTIVE;
269 spin_unlock(&tpg->tpg_state_lock);
271 if (iscsit_release_sessions_for_tpg(tpg, force) < 0) {
272 pr_err("Unable to delete iSCSI Target Portal Group:"
273 " %hu while active sessions exist, and force=0\n",
274 tpg->tpgt);
275 tpg->tpg_state = old_state;
276 return -EPERM;
279 core_tpg_clear_object_luns(&tpg->tpg_se_tpg);
281 if (tpg->param_list) {
282 iscsi_release_param_list(tpg->param_list);
283 tpg->param_list = NULL;
286 core_tpg_deregister(&tpg->tpg_se_tpg);
288 spin_lock(&tpg->tpg_state_lock);
289 tpg->tpg_state = TPG_STATE_FREE;
290 spin_unlock(&tpg->tpg_state_lock);
292 spin_lock(&tiqn->tiqn_tpg_lock);
293 tiqn->tiqn_ntpgs--;
294 list_del(&tpg->tpg_list);
295 spin_unlock(&tiqn->tiqn_tpg_lock);
297 pr_debug("CORE[%s]_TPG[%hu] - Deleted iSCSI Target Portal Group\n",
298 tiqn->tiqn, tpg->tpgt);
300 kfree(tpg);
301 return 0;
304 int iscsit_tpg_enable_portal_group(struct iscsi_portal_group *tpg)
306 struct iscsi_param *param;
307 struct iscsi_tiqn *tiqn = tpg->tpg_tiqn;
308 int ret;
310 spin_lock(&tpg->tpg_state_lock);
311 if (tpg->tpg_state == TPG_STATE_ACTIVE) {
312 pr_err("iSCSI target portal group: %hu is already"
313 " active, ignoring request.\n", tpg->tpgt);
314 spin_unlock(&tpg->tpg_state_lock);
315 return -EINVAL;
318 * Make sure that AuthMethod does not contain None as an option
319 * unless explictly disabled. Set the default to CHAP if authentication
320 * is enforced (as per default), and remove the NONE option.
322 param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list);
323 if (!param) {
324 spin_unlock(&tpg->tpg_state_lock);
325 return -EINVAL;
328 if (ISCSI_TPG_ATTRIB(tpg)->authentication) {
329 if (!strcmp(param->value, NONE)) {
330 ret = iscsi_update_param_value(param, CHAP);
331 if (ret)
332 goto err;
335 ret = iscsit_ta_authentication(tpg, 1);
336 if (ret < 0)
337 goto err;
340 tpg->tpg_state = TPG_STATE_ACTIVE;
341 spin_unlock(&tpg->tpg_state_lock);
343 spin_lock(&tiqn->tiqn_tpg_lock);
344 tiqn->tiqn_active_tpgs++;
345 pr_debug("iSCSI_TPG[%hu] - Enabled iSCSI Target Portal Group\n",
346 tpg->tpgt);
347 spin_unlock(&tiqn->tiqn_tpg_lock);
349 return 0;
351 err:
352 spin_unlock(&tpg->tpg_state_lock);
353 return ret;
356 int iscsit_tpg_disable_portal_group(struct iscsi_portal_group *tpg, int force)
358 struct iscsi_tiqn *tiqn;
359 u8 old_state = tpg->tpg_state;
361 spin_lock(&tpg->tpg_state_lock);
362 if (tpg->tpg_state == TPG_STATE_INACTIVE) {
363 pr_err("iSCSI Target Portal Group: %hu is already"
364 " inactive, ignoring request.\n", tpg->tpgt);
365 spin_unlock(&tpg->tpg_state_lock);
366 return -EINVAL;
368 tpg->tpg_state = TPG_STATE_INACTIVE;
369 spin_unlock(&tpg->tpg_state_lock);
371 iscsit_clear_tpg_np_login_threads(tpg);
373 if (iscsit_release_sessions_for_tpg(tpg, force) < 0) {
374 spin_lock(&tpg->tpg_state_lock);
375 tpg->tpg_state = old_state;
376 spin_unlock(&tpg->tpg_state_lock);
377 pr_err("Unable to disable iSCSI Target Portal Group:"
378 " %hu while active sessions exist, and force=0\n",
379 tpg->tpgt);
380 return -EPERM;
383 tiqn = tpg->tpg_tiqn;
384 if (!tiqn || (tpg == iscsit_global->discovery_tpg))
385 return 0;
387 spin_lock(&tiqn->tiqn_tpg_lock);
388 tiqn->tiqn_active_tpgs--;
389 pr_debug("iSCSI_TPG[%hu] - Disabled iSCSI Target Portal Group\n",
390 tpg->tpgt);
391 spin_unlock(&tiqn->tiqn_tpg_lock);
393 return 0;
396 struct iscsi_node_attrib *iscsit_tpg_get_node_attrib(
397 struct iscsi_session *sess)
399 struct se_session *se_sess = sess->se_sess;
400 struct se_node_acl *se_nacl = se_sess->se_node_acl;
401 struct iscsi_node_acl *acl = container_of(se_nacl, struct iscsi_node_acl,
402 se_node_acl);
404 return &acl->node_attrib;
407 struct iscsi_tpg_np *iscsit_tpg_locate_child_np(
408 struct iscsi_tpg_np *tpg_np,
409 int network_transport)
411 struct iscsi_tpg_np *tpg_np_child, *tpg_np_child_tmp;
413 spin_lock(&tpg_np->tpg_np_parent_lock);
414 list_for_each_entry_safe(tpg_np_child, tpg_np_child_tmp,
415 &tpg_np->tpg_np_parent_list, tpg_np_child_list) {
416 if (tpg_np_child->tpg_np->np_network_transport ==
417 network_transport) {
418 spin_unlock(&tpg_np->tpg_np_parent_lock);
419 return tpg_np_child;
422 spin_unlock(&tpg_np->tpg_np_parent_lock);
424 return NULL;
427 static bool iscsit_tpg_check_network_portal(
428 struct iscsi_tiqn *tiqn,
429 struct __kernel_sockaddr_storage *sockaddr,
430 int network_transport)
432 struct iscsi_portal_group *tpg;
433 struct iscsi_tpg_np *tpg_np;
434 struct iscsi_np *np;
435 bool match = false;
437 spin_lock(&tiqn->tiqn_tpg_lock);
438 list_for_each_entry(tpg, &tiqn->tiqn_tpg_list, tpg_list) {
440 spin_lock(&tpg->tpg_np_lock);
441 list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, tpg_np_list) {
442 np = tpg_np->tpg_np;
444 match = iscsit_check_np_match(sockaddr, np,
445 network_transport);
446 if (match == true)
447 break;
449 spin_unlock(&tpg->tpg_np_lock);
451 spin_unlock(&tiqn->tiqn_tpg_lock);
453 return match;
456 struct iscsi_tpg_np *iscsit_tpg_add_network_portal(
457 struct iscsi_portal_group *tpg,
458 struct __kernel_sockaddr_storage *sockaddr,
459 char *ip_str,
460 struct iscsi_tpg_np *tpg_np_parent,
461 int network_transport)
463 struct iscsi_np *np;
464 struct iscsi_tpg_np *tpg_np;
466 if (!tpg_np_parent) {
467 if (iscsit_tpg_check_network_portal(tpg->tpg_tiqn, sockaddr,
468 network_transport) == true) {
469 pr_err("Network Portal: %s already exists on a"
470 " different TPG on %s\n", ip_str,
471 tpg->tpg_tiqn->tiqn);
472 return ERR_PTR(-EEXIST);
476 tpg_np = kzalloc(sizeof(struct iscsi_tpg_np), GFP_KERNEL);
477 if (!tpg_np) {
478 pr_err("Unable to allocate memory for"
479 " struct iscsi_tpg_np.\n");
480 return ERR_PTR(-ENOMEM);
483 np = iscsit_add_np(sockaddr, ip_str, network_transport);
484 if (IS_ERR(np)) {
485 kfree(tpg_np);
486 return ERR_CAST(np);
489 INIT_LIST_HEAD(&tpg_np->tpg_np_list);
490 INIT_LIST_HEAD(&tpg_np->tpg_np_child_list);
491 INIT_LIST_HEAD(&tpg_np->tpg_np_parent_list);
492 spin_lock_init(&tpg_np->tpg_np_parent_lock);
493 tpg_np->tpg_np = np;
494 tpg_np->tpg = tpg;
496 spin_lock(&tpg->tpg_np_lock);
497 list_add_tail(&tpg_np->tpg_np_list, &tpg->tpg_gnp_list);
498 tpg->num_tpg_nps++;
499 if (tpg->tpg_tiqn)
500 tpg->tpg_tiqn->tiqn_num_tpg_nps++;
501 spin_unlock(&tpg->tpg_np_lock);
503 if (tpg_np_parent) {
504 tpg_np->tpg_np_parent = tpg_np_parent;
505 spin_lock(&tpg_np_parent->tpg_np_parent_lock);
506 list_add_tail(&tpg_np->tpg_np_child_list,
507 &tpg_np_parent->tpg_np_parent_list);
508 spin_unlock(&tpg_np_parent->tpg_np_parent_lock);
511 pr_debug("CORE[%s] - Added Network Portal: %s:%hu,%hu on %s\n",
512 tpg->tpg_tiqn->tiqn, np->np_ip, np->np_port, tpg->tpgt,
513 np->np_transport->name);
515 return tpg_np;
518 static int iscsit_tpg_release_np(
519 struct iscsi_tpg_np *tpg_np,
520 struct iscsi_portal_group *tpg,
521 struct iscsi_np *np)
523 iscsit_clear_tpg_np_login_thread(tpg_np, tpg);
525 pr_debug("CORE[%s] - Removed Network Portal: %s:%hu,%hu on %s\n",
526 tpg->tpg_tiqn->tiqn, np->np_ip, np->np_port, tpg->tpgt,
527 np->np_transport->name);
529 tpg_np->tpg_np = NULL;
530 tpg_np->tpg = NULL;
531 kfree(tpg_np);
533 * iscsit_del_np() will shutdown struct iscsi_np when last TPG reference is released.
535 return iscsit_del_np(np);
538 int iscsit_tpg_del_network_portal(
539 struct iscsi_portal_group *tpg,
540 struct iscsi_tpg_np *tpg_np)
542 struct iscsi_np *np;
543 struct iscsi_tpg_np *tpg_np_child, *tpg_np_child_tmp;
544 int ret = 0;
546 np = tpg_np->tpg_np;
547 if (!np) {
548 pr_err("Unable to locate struct iscsi_np from"
549 " struct iscsi_tpg_np\n");
550 return -EINVAL;
553 if (!tpg_np->tpg_np_parent) {
555 * We are the parent tpg network portal. Release all of the
556 * child tpg_np's (eg: the non ISCSI_TCP ones) on our parent
557 * list first.
559 list_for_each_entry_safe(tpg_np_child, tpg_np_child_tmp,
560 &tpg_np->tpg_np_parent_list,
561 tpg_np_child_list) {
562 ret = iscsit_tpg_del_network_portal(tpg, tpg_np_child);
563 if (ret < 0)
564 pr_err("iscsit_tpg_del_network_portal()"
565 " failed: %d\n", ret);
567 } else {
569 * We are not the parent ISCSI_TCP tpg network portal. Release
570 * our own network portals from the child list.
572 spin_lock(&tpg_np->tpg_np_parent->tpg_np_parent_lock);
573 list_del(&tpg_np->tpg_np_child_list);
574 spin_unlock(&tpg_np->tpg_np_parent->tpg_np_parent_lock);
577 spin_lock(&tpg->tpg_np_lock);
578 list_del(&tpg_np->tpg_np_list);
579 tpg->num_tpg_nps--;
580 if (tpg->tpg_tiqn)
581 tpg->tpg_tiqn->tiqn_num_tpg_nps--;
582 spin_unlock(&tpg->tpg_np_lock);
584 return iscsit_tpg_release_np(tpg_np, tpg, np);
587 int iscsit_tpg_set_initiator_node_queue_depth(
588 struct iscsi_portal_group *tpg,
589 unsigned char *initiatorname,
590 u32 queue_depth,
591 int force)
593 return core_tpg_set_initiator_node_queue_depth(&tpg->tpg_se_tpg,
594 initiatorname, queue_depth, force);
597 int iscsit_ta_authentication(struct iscsi_portal_group *tpg, u32 authentication)
599 unsigned char buf1[256], buf2[256], *none = NULL;
600 int len;
601 struct iscsi_param *param;
602 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
604 if ((authentication != 1) && (authentication != 0)) {
605 pr_err("Illegal value for authentication parameter:"
606 " %u, ignoring request.\n", authentication);
607 return -EINVAL;
610 memset(buf1, 0, sizeof(buf1));
611 memset(buf2, 0, sizeof(buf2));
613 param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list);
614 if (!param)
615 return -EINVAL;
617 if (authentication) {
618 snprintf(buf1, sizeof(buf1), "%s", param->value);
619 none = strstr(buf1, NONE);
620 if (!none)
621 goto out;
622 if (!strncmp(none + 4, ",", 1)) {
623 if (!strcmp(buf1, none))
624 sprintf(buf2, "%s", none+5);
625 else {
626 none--;
627 *none = '\0';
628 len = sprintf(buf2, "%s", buf1);
629 none += 5;
630 sprintf(buf2 + len, "%s", none);
632 } else {
633 none--;
634 *none = '\0';
635 sprintf(buf2, "%s", buf1);
637 if (iscsi_update_param_value(param, buf2) < 0)
638 return -EINVAL;
639 } else {
640 snprintf(buf1, sizeof(buf1), "%s", param->value);
641 none = strstr(buf1, NONE);
642 if (none)
643 goto out;
644 strncat(buf1, ",", strlen(","));
645 strncat(buf1, NONE, strlen(NONE));
646 if (iscsi_update_param_value(param, buf1) < 0)
647 return -EINVAL;
650 out:
651 a->authentication = authentication;
652 pr_debug("%s iSCSI Authentication Methods for TPG: %hu.\n",
653 a->authentication ? "Enforcing" : "Disabling", tpg->tpgt);
655 return 0;
658 int iscsit_ta_login_timeout(
659 struct iscsi_portal_group *tpg,
660 u32 login_timeout)
662 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
664 if (login_timeout > TA_LOGIN_TIMEOUT_MAX) {
665 pr_err("Requested Login Timeout %u larger than maximum"
666 " %u\n", login_timeout, TA_LOGIN_TIMEOUT_MAX);
667 return -EINVAL;
668 } else if (login_timeout < TA_LOGIN_TIMEOUT_MIN) {
669 pr_err("Requested Logout Timeout %u smaller than"
670 " minimum %u\n", login_timeout, TA_LOGIN_TIMEOUT_MIN);
671 return -EINVAL;
674 a->login_timeout = login_timeout;
675 pr_debug("Set Logout Timeout to %u for Target Portal Group"
676 " %hu\n", a->login_timeout, tpg->tpgt);
678 return 0;
681 int iscsit_ta_netif_timeout(
682 struct iscsi_portal_group *tpg,
683 u32 netif_timeout)
685 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
687 if (netif_timeout > TA_NETIF_TIMEOUT_MAX) {
688 pr_err("Requested Network Interface Timeout %u larger"
689 " than maximum %u\n", netif_timeout,
690 TA_NETIF_TIMEOUT_MAX);
691 return -EINVAL;
692 } else if (netif_timeout < TA_NETIF_TIMEOUT_MIN) {
693 pr_err("Requested Network Interface Timeout %u smaller"
694 " than minimum %u\n", netif_timeout,
695 TA_NETIF_TIMEOUT_MIN);
696 return -EINVAL;
699 a->netif_timeout = netif_timeout;
700 pr_debug("Set Network Interface Timeout to %u for"
701 " Target Portal Group %hu\n", a->netif_timeout, tpg->tpgt);
703 return 0;
706 int iscsit_ta_generate_node_acls(
707 struct iscsi_portal_group *tpg,
708 u32 flag)
710 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
712 if ((flag != 0) && (flag != 1)) {
713 pr_err("Illegal value %d\n", flag);
714 return -EINVAL;
717 a->generate_node_acls = flag;
718 pr_debug("iSCSI_TPG[%hu] - Generate Initiator Portal Group ACLs: %s\n",
719 tpg->tpgt, (a->generate_node_acls) ? "Enabled" : "Disabled");
721 if (flag == 1 && a->cache_dynamic_acls == 0) {
722 pr_debug("Explicitly setting cache_dynamic_acls=1 when "
723 "generate_node_acls=1\n");
724 a->cache_dynamic_acls = 1;
727 return 0;
730 int iscsit_ta_default_cmdsn_depth(
731 struct iscsi_portal_group *tpg,
732 u32 tcq_depth)
734 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
736 if (tcq_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
737 pr_err("Requested Default Queue Depth: %u larger"
738 " than maximum %u\n", tcq_depth,
739 TA_DEFAULT_CMDSN_DEPTH_MAX);
740 return -EINVAL;
741 } else if (tcq_depth < TA_DEFAULT_CMDSN_DEPTH_MIN) {
742 pr_err("Requested Default Queue Depth: %u smaller"
743 " than minimum %u\n", tcq_depth,
744 TA_DEFAULT_CMDSN_DEPTH_MIN);
745 return -EINVAL;
748 a->default_cmdsn_depth = tcq_depth;
749 pr_debug("iSCSI_TPG[%hu] - Set Default CmdSN TCQ Depth to %u\n",
750 tpg->tpgt, a->default_cmdsn_depth);
752 return 0;
755 int iscsit_ta_cache_dynamic_acls(
756 struct iscsi_portal_group *tpg,
757 u32 flag)
759 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
761 if ((flag != 0) && (flag != 1)) {
762 pr_err("Illegal value %d\n", flag);
763 return -EINVAL;
766 if (a->generate_node_acls == 1 && flag == 0) {
767 pr_debug("Skipping cache_dynamic_acls=0 when"
768 " generate_node_acls=1\n");
769 return 0;
772 a->cache_dynamic_acls = flag;
773 pr_debug("iSCSI_TPG[%hu] - Cache Dynamic Initiator Portal Group"
774 " ACLs %s\n", tpg->tpgt, (a->cache_dynamic_acls) ?
775 "Enabled" : "Disabled");
777 return 0;
780 int iscsit_ta_demo_mode_write_protect(
781 struct iscsi_portal_group *tpg,
782 u32 flag)
784 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
786 if ((flag != 0) && (flag != 1)) {
787 pr_err("Illegal value %d\n", flag);
788 return -EINVAL;
791 a->demo_mode_write_protect = flag;
792 pr_debug("iSCSI_TPG[%hu] - Demo Mode Write Protect bit: %s\n",
793 tpg->tpgt, (a->demo_mode_write_protect) ? "ON" : "OFF");
795 return 0;
798 int iscsit_ta_prod_mode_write_protect(
799 struct iscsi_portal_group *tpg,
800 u32 flag)
802 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
804 if ((flag != 0) && (flag != 1)) {
805 pr_err("Illegal value %d\n", flag);
806 return -EINVAL;
809 a->prod_mode_write_protect = flag;
810 pr_debug("iSCSI_TPG[%hu] - Production Mode Write Protect bit:"
811 " %s\n", tpg->tpgt, (a->prod_mode_write_protect) ?
812 "ON" : "OFF");
814 return 0;