cgroup: fix and restructure error handling in copy_cgroup_ns()
[linux/fpc-iii.git] / drivers / target / iscsi / iscsi_target_tpg.c
blob0814e5894a9616ffcc79fb0d0f086f718a971fd7
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 <target/target_core_base.h>
20 #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);
38 if (!tpg) {
39 pr_err("Unable to allocate struct iscsi_portal_group\n");
40 return NULL;
43 tpg->tpgt = tpgt;
44 tpg->tpg_state = TPG_STATE_FREE;
45 tpg->tpg_tiqn = tiqn;
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);
53 return tpg;
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;
62 int ret;
64 tpg = iscsit_alloc_portal_group(NULL, 1);
65 if (!tpg) {
66 pr_err("Unable to allocate struct iscsi_portal_group\n");
67 return -1;
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);
75 if (ret < 0) {
76 kfree(tpg);
77 return -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)
84 goto out;
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);
92 if (!param)
93 goto out;
95 if (iscsi_update_param_value(param, "CHAP,None") < 0)
96 goto out;
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");
107 return 0;
108 out:
109 if (tpg->sid == 1)
110 core_tpg_deregister(&tpg->tpg_se_tpg);
111 kfree(tpg);
112 return -1;
115 void iscsit_release_discovery_tpg(void)
117 struct iscsi_portal_group *tpg = iscsit_global->discovery_tpg;
119 if (!tpg)
120 return;
122 core_tpg_deregister(&tpg->tpg_se_tpg);
124 kfree(tpg);
125 iscsit_global->discovery_tpg = NULL;
128 struct iscsi_portal_group *iscsit_get_tpg_from_np(
129 struct iscsi_tiqn *tiqn,
130 struct iscsi_np *np,
131 struct iscsi_tpg_np **tpg_np_out)
133 struct iscsi_portal_group *tpg = NULL;
134 struct iscsi_tpg_np *tpg_np;
136 spin_lock(&tiqn->tiqn_tpg_lock);
137 list_for_each_entry(tpg, &tiqn->tiqn_tpg_list, tpg_list) {
139 spin_lock(&tpg->tpg_state_lock);
140 if (tpg->tpg_state != TPG_STATE_ACTIVE) {
141 spin_unlock(&tpg->tpg_state_lock);
142 continue;
144 spin_unlock(&tpg->tpg_state_lock);
146 spin_lock(&tpg->tpg_np_lock);
147 list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, tpg_np_list) {
148 if (tpg_np->tpg_np == np) {
149 *tpg_np_out = tpg_np;
150 kref_get(&tpg_np->tpg_np_kref);
151 spin_unlock(&tpg->tpg_np_lock);
152 spin_unlock(&tiqn->tiqn_tpg_lock);
153 return tpg;
156 spin_unlock(&tpg->tpg_np_lock);
158 spin_unlock(&tiqn->tiqn_tpg_lock);
160 return NULL;
163 int iscsit_get_tpg(
164 struct iscsi_portal_group *tpg)
166 return mutex_lock_interruptible(&tpg->tpg_access_lock);
169 void iscsit_put_tpg(struct iscsi_portal_group *tpg)
171 mutex_unlock(&tpg->tpg_access_lock);
174 static void iscsit_clear_tpg_np_login_thread(
175 struct iscsi_tpg_np *tpg_np,
176 struct iscsi_portal_group *tpg,
177 bool shutdown)
179 if (!tpg_np->tpg_np) {
180 pr_err("struct iscsi_tpg_np->tpg_np is NULL!\n");
181 return;
184 if (shutdown)
185 tpg_np->tpg_np->enabled = false;
186 iscsit_reset_np_thread(tpg_np->tpg_np, tpg_np, tpg, shutdown);
189 static void iscsit_clear_tpg_np_login_threads(
190 struct iscsi_portal_group *tpg,
191 bool shutdown)
193 struct iscsi_tpg_np *tpg_np;
195 spin_lock(&tpg->tpg_np_lock);
196 list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, tpg_np_list) {
197 if (!tpg_np->tpg_np) {
198 pr_err("struct iscsi_tpg_np->tpg_np is NULL!\n");
199 continue;
201 spin_unlock(&tpg->tpg_np_lock);
202 iscsit_clear_tpg_np_login_thread(tpg_np, tpg, shutdown);
203 spin_lock(&tpg->tpg_np_lock);
205 spin_unlock(&tpg->tpg_np_lock);
208 void iscsit_tpg_dump_params(struct iscsi_portal_group *tpg)
210 iscsi_print_params(tpg->param_list);
213 static void iscsit_set_default_tpg_attribs(struct iscsi_portal_group *tpg)
215 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
217 a->authentication = TA_AUTHENTICATION;
218 a->login_timeout = TA_LOGIN_TIMEOUT;
219 a->netif_timeout = TA_NETIF_TIMEOUT;
220 a->default_cmdsn_depth = TA_DEFAULT_CMDSN_DEPTH;
221 a->generate_node_acls = TA_GENERATE_NODE_ACLS;
222 a->cache_dynamic_acls = TA_CACHE_DYNAMIC_ACLS;
223 a->demo_mode_write_protect = TA_DEMO_MODE_WRITE_PROTECT;
224 a->prod_mode_write_protect = TA_PROD_MODE_WRITE_PROTECT;
225 a->demo_mode_discovery = TA_DEMO_MODE_DISCOVERY;
226 a->default_erl = TA_DEFAULT_ERL;
227 a->t10_pi = TA_DEFAULT_T10_PI;
228 a->fabric_prot_type = TA_DEFAULT_FABRIC_PROT_TYPE;
229 a->tpg_enabled_sendtargets = TA_DEFAULT_TPG_ENABLED_SENDTARGETS;
232 int iscsit_tpg_add_portal_group(struct iscsi_tiqn *tiqn, struct iscsi_portal_group *tpg)
234 if (tpg->tpg_state != TPG_STATE_FREE) {
235 pr_err("Unable to add iSCSI Target Portal Group: %d"
236 " while not in TPG_STATE_FREE state.\n", tpg->tpgt);
237 return -EEXIST;
239 iscsit_set_default_tpg_attribs(tpg);
241 if (iscsi_create_default_params(&tpg->param_list) < 0)
242 goto err_out;
244 tpg->tpg_attrib.tpg = tpg;
246 spin_lock(&tpg->tpg_state_lock);
247 tpg->tpg_state = TPG_STATE_INACTIVE;
248 spin_unlock(&tpg->tpg_state_lock);
250 spin_lock(&tiqn->tiqn_tpg_lock);
251 list_add_tail(&tpg->tpg_list, &tiqn->tiqn_tpg_list);
252 tiqn->tiqn_ntpgs++;
253 pr_debug("CORE[%s]_TPG[%hu] - Added iSCSI Target Portal Group\n",
254 tiqn->tiqn, tpg->tpgt);
255 spin_unlock(&tiqn->tiqn_tpg_lock);
257 return 0;
258 err_out:
259 if (tpg->param_list) {
260 iscsi_release_param_list(tpg->param_list);
261 tpg->param_list = NULL;
263 kfree(tpg);
264 return -ENOMEM;
267 int iscsit_tpg_del_portal_group(
268 struct iscsi_tiqn *tiqn,
269 struct iscsi_portal_group *tpg,
270 int force)
272 u8 old_state = tpg->tpg_state;
274 spin_lock(&tpg->tpg_state_lock);
275 tpg->tpg_state = TPG_STATE_INACTIVE;
276 spin_unlock(&tpg->tpg_state_lock);
278 if (iscsit_release_sessions_for_tpg(tpg, force) < 0) {
279 pr_err("Unable to delete iSCSI Target Portal Group:"
280 " %hu while active sessions exist, and force=0\n",
281 tpg->tpgt);
282 tpg->tpg_state = old_state;
283 return -EPERM;
286 if (tpg->param_list) {
287 iscsi_release_param_list(tpg->param_list);
288 tpg->param_list = NULL;
291 core_tpg_deregister(&tpg->tpg_se_tpg);
293 spin_lock(&tpg->tpg_state_lock);
294 tpg->tpg_state = TPG_STATE_FREE;
295 spin_unlock(&tpg->tpg_state_lock);
297 spin_lock(&tiqn->tiqn_tpg_lock);
298 tiqn->tiqn_ntpgs--;
299 list_del(&tpg->tpg_list);
300 spin_unlock(&tiqn->tiqn_tpg_lock);
302 pr_debug("CORE[%s]_TPG[%hu] - Deleted iSCSI Target Portal Group\n",
303 tiqn->tiqn, tpg->tpgt);
305 kfree(tpg);
306 return 0;
309 int iscsit_tpg_enable_portal_group(struct iscsi_portal_group *tpg)
311 struct iscsi_param *param;
312 struct iscsi_tiqn *tiqn = tpg->tpg_tiqn;
313 int ret;
315 spin_lock(&tpg->tpg_state_lock);
316 if (tpg->tpg_state == TPG_STATE_ACTIVE) {
317 pr_err("iSCSI target portal group: %hu is already"
318 " active, ignoring request.\n", tpg->tpgt);
319 spin_unlock(&tpg->tpg_state_lock);
320 return -EINVAL;
323 * Make sure that AuthMethod does not contain None as an option
324 * unless explictly disabled. Set the default to CHAP if authentication
325 * is enforced (as per default), and remove the NONE option.
327 param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list);
328 if (!param) {
329 spin_unlock(&tpg->tpg_state_lock);
330 return -EINVAL;
333 if (tpg->tpg_attrib.authentication) {
334 if (!strcmp(param->value, NONE)) {
335 ret = iscsi_update_param_value(param, CHAP);
336 if (ret)
337 goto err;
340 ret = iscsit_ta_authentication(tpg, 1);
341 if (ret < 0)
342 goto err;
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",
351 tpg->tpgt);
352 spin_unlock(&tiqn->tiqn_tpg_lock);
354 return 0;
356 err:
357 spin_unlock(&tpg->tpg_state_lock);
358 return ret;
361 int iscsit_tpg_disable_portal_group(struct iscsi_portal_group *tpg, int force)
363 struct iscsi_tiqn *tiqn;
364 u8 old_state = tpg->tpg_state;
366 spin_lock(&tpg->tpg_state_lock);
367 if (tpg->tpg_state == TPG_STATE_INACTIVE) {
368 pr_err("iSCSI Target Portal Group: %hu is already"
369 " inactive, ignoring request.\n", tpg->tpgt);
370 spin_unlock(&tpg->tpg_state_lock);
371 return -EINVAL;
373 tpg->tpg_state = TPG_STATE_INACTIVE;
374 spin_unlock(&tpg->tpg_state_lock);
376 iscsit_clear_tpg_np_login_threads(tpg, false);
378 if (iscsit_release_sessions_for_tpg(tpg, force) < 0) {
379 spin_lock(&tpg->tpg_state_lock);
380 tpg->tpg_state = old_state;
381 spin_unlock(&tpg->tpg_state_lock);
382 pr_err("Unable to disable iSCSI Target Portal Group:"
383 " %hu while active sessions exist, and force=0\n",
384 tpg->tpgt);
385 return -EPERM;
388 tiqn = tpg->tpg_tiqn;
389 if (!tiqn || (tpg == iscsit_global->discovery_tpg))
390 return 0;
392 spin_lock(&tiqn->tiqn_tpg_lock);
393 tiqn->tiqn_active_tpgs--;
394 pr_debug("iSCSI_TPG[%hu] - Disabled iSCSI Target Portal Group\n",
395 tpg->tpgt);
396 spin_unlock(&tiqn->tiqn_tpg_lock);
398 return 0;
401 struct iscsi_node_attrib *iscsit_tpg_get_node_attrib(
402 struct iscsi_session *sess)
404 struct se_session *se_sess = sess->se_sess;
405 struct se_node_acl *se_nacl = se_sess->se_node_acl;
406 struct iscsi_node_acl *acl = container_of(se_nacl, struct iscsi_node_acl,
407 se_node_acl);
409 return &acl->node_attrib;
412 struct iscsi_tpg_np *iscsit_tpg_locate_child_np(
413 struct iscsi_tpg_np *tpg_np,
414 int network_transport)
416 struct iscsi_tpg_np *tpg_np_child, *tpg_np_child_tmp;
418 spin_lock(&tpg_np->tpg_np_parent_lock);
419 list_for_each_entry_safe(tpg_np_child, tpg_np_child_tmp,
420 &tpg_np->tpg_np_parent_list, tpg_np_child_list) {
421 if (tpg_np_child->tpg_np->np_network_transport ==
422 network_transport) {
423 spin_unlock(&tpg_np->tpg_np_parent_lock);
424 return tpg_np_child;
427 spin_unlock(&tpg_np->tpg_np_parent_lock);
429 return NULL;
432 static bool iscsit_tpg_check_network_portal(
433 struct iscsi_tiqn *tiqn,
434 struct sockaddr_storage *sockaddr,
435 int network_transport)
437 struct iscsi_portal_group *tpg;
438 struct iscsi_tpg_np *tpg_np;
439 struct iscsi_np *np;
440 bool match = false;
442 spin_lock(&tiqn->tiqn_tpg_lock);
443 list_for_each_entry(tpg, &tiqn->tiqn_tpg_list, tpg_list) {
445 spin_lock(&tpg->tpg_np_lock);
446 list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, tpg_np_list) {
447 np = tpg_np->tpg_np;
449 match = iscsit_check_np_match(sockaddr, np,
450 network_transport);
451 if (match)
452 break;
454 spin_unlock(&tpg->tpg_np_lock);
456 spin_unlock(&tiqn->tiqn_tpg_lock);
458 return match;
461 struct iscsi_tpg_np *iscsit_tpg_add_network_portal(
462 struct iscsi_portal_group *tpg,
463 struct sockaddr_storage *sockaddr,
464 struct iscsi_tpg_np *tpg_np_parent,
465 int network_transport)
467 struct iscsi_np *np;
468 struct iscsi_tpg_np *tpg_np;
470 if (!tpg_np_parent) {
471 if (iscsit_tpg_check_network_portal(tpg->tpg_tiqn, sockaddr,
472 network_transport)) {
473 pr_err("Network Portal: %pISc already exists on a"
474 " different TPG on %s\n", sockaddr,
475 tpg->tpg_tiqn->tiqn);
476 return ERR_PTR(-EEXIST);
480 tpg_np = kzalloc(sizeof(struct iscsi_tpg_np), GFP_KERNEL);
481 if (!tpg_np) {
482 pr_err("Unable to allocate memory for"
483 " struct iscsi_tpg_np.\n");
484 return ERR_PTR(-ENOMEM);
487 np = iscsit_add_np(sockaddr, network_transport);
488 if (IS_ERR(np)) {
489 kfree(tpg_np);
490 return ERR_CAST(np);
493 INIT_LIST_HEAD(&tpg_np->tpg_np_list);
494 INIT_LIST_HEAD(&tpg_np->tpg_np_child_list);
495 INIT_LIST_HEAD(&tpg_np->tpg_np_parent_list);
496 spin_lock_init(&tpg_np->tpg_np_parent_lock);
497 init_completion(&tpg_np->tpg_np_comp);
498 kref_init(&tpg_np->tpg_np_kref);
499 tpg_np->tpg_np = np;
500 tpg_np->tpg = tpg;
502 spin_lock(&tpg->tpg_np_lock);
503 list_add_tail(&tpg_np->tpg_np_list, &tpg->tpg_gnp_list);
504 tpg->num_tpg_nps++;
505 if (tpg->tpg_tiqn)
506 tpg->tpg_tiqn->tiqn_num_tpg_nps++;
507 spin_unlock(&tpg->tpg_np_lock);
509 if (tpg_np_parent) {
510 tpg_np->tpg_np_parent = tpg_np_parent;
511 spin_lock(&tpg_np_parent->tpg_np_parent_lock);
512 list_add_tail(&tpg_np->tpg_np_child_list,
513 &tpg_np_parent->tpg_np_parent_list);
514 spin_unlock(&tpg_np_parent->tpg_np_parent_lock);
517 pr_debug("CORE[%s] - Added Network Portal: %pISpc,%hu on %s\n",
518 tpg->tpg_tiqn->tiqn, &np->np_sockaddr, tpg->tpgt,
519 np->np_transport->name);
521 return tpg_np;
524 static int iscsit_tpg_release_np(
525 struct iscsi_tpg_np *tpg_np,
526 struct iscsi_portal_group *tpg,
527 struct iscsi_np *np)
529 iscsit_clear_tpg_np_login_thread(tpg_np, tpg, true);
531 pr_debug("CORE[%s] - Removed Network Portal: %pISpc,%hu on %s\n",
532 tpg->tpg_tiqn->tiqn, &np->np_sockaddr, tpg->tpgt,
533 np->np_transport->name);
535 tpg_np->tpg_np = NULL;
536 tpg_np->tpg = NULL;
537 kfree(tpg_np);
539 * iscsit_del_np() will shutdown struct iscsi_np when last TPG reference is released.
541 return iscsit_del_np(np);
544 int iscsit_tpg_del_network_portal(
545 struct iscsi_portal_group *tpg,
546 struct iscsi_tpg_np *tpg_np)
548 struct iscsi_np *np;
549 struct iscsi_tpg_np *tpg_np_child, *tpg_np_child_tmp;
550 int ret = 0;
552 np = tpg_np->tpg_np;
553 if (!np) {
554 pr_err("Unable to locate struct iscsi_np from"
555 " struct iscsi_tpg_np\n");
556 return -EINVAL;
559 if (!tpg_np->tpg_np_parent) {
561 * We are the parent tpg network portal. Release all of the
562 * child tpg_np's (eg: the non ISCSI_TCP ones) on our parent
563 * list first.
565 list_for_each_entry_safe(tpg_np_child, tpg_np_child_tmp,
566 &tpg_np->tpg_np_parent_list,
567 tpg_np_child_list) {
568 ret = iscsit_tpg_del_network_portal(tpg, tpg_np_child);
569 if (ret < 0)
570 pr_err("iscsit_tpg_del_network_portal()"
571 " failed: %d\n", ret);
573 } else {
575 * We are not the parent ISCSI_TCP tpg network portal. Release
576 * our own network portals from the child list.
578 spin_lock(&tpg_np->tpg_np_parent->tpg_np_parent_lock);
579 list_del(&tpg_np->tpg_np_child_list);
580 spin_unlock(&tpg_np->tpg_np_parent->tpg_np_parent_lock);
583 spin_lock(&tpg->tpg_np_lock);
584 list_del(&tpg_np->tpg_np_list);
585 tpg->num_tpg_nps--;
586 if (tpg->tpg_tiqn)
587 tpg->tpg_tiqn->tiqn_num_tpg_nps--;
588 spin_unlock(&tpg->tpg_np_lock);
590 return iscsit_tpg_release_np(tpg_np, tpg, np);
593 int iscsit_ta_authentication(struct iscsi_portal_group *tpg, u32 authentication)
595 unsigned char buf1[256], buf2[256], *none = NULL;
596 int len;
597 struct iscsi_param *param;
598 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
600 if ((authentication != 1) && (authentication != 0)) {
601 pr_err("Illegal value for authentication parameter:"
602 " %u, ignoring request.\n", authentication);
603 return -EINVAL;
606 memset(buf1, 0, sizeof(buf1));
607 memset(buf2, 0, sizeof(buf2));
609 param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list);
610 if (!param)
611 return -EINVAL;
613 if (authentication) {
614 snprintf(buf1, sizeof(buf1), "%s", param->value);
615 none = strstr(buf1, NONE);
616 if (!none)
617 goto out;
618 if (!strncmp(none + 4, ",", 1)) {
619 if (!strcmp(buf1, none))
620 sprintf(buf2, "%s", none+5);
621 else {
622 none--;
623 *none = '\0';
624 len = sprintf(buf2, "%s", buf1);
625 none += 5;
626 sprintf(buf2 + len, "%s", none);
628 } else {
629 none--;
630 *none = '\0';
631 sprintf(buf2, "%s", buf1);
633 if (iscsi_update_param_value(param, buf2) < 0)
634 return -EINVAL;
635 } else {
636 snprintf(buf1, sizeof(buf1), "%s", param->value);
637 none = strstr(buf1, NONE);
638 if (none)
639 goto out;
640 strncat(buf1, ",", strlen(","));
641 strncat(buf1, NONE, strlen(NONE));
642 if (iscsi_update_param_value(param, buf1) < 0)
643 return -EINVAL;
646 out:
647 a->authentication = authentication;
648 pr_debug("%s iSCSI Authentication Methods for TPG: %hu.\n",
649 a->authentication ? "Enforcing" : "Disabling", tpg->tpgt);
651 return 0;
654 int iscsit_ta_login_timeout(
655 struct iscsi_portal_group *tpg,
656 u32 login_timeout)
658 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
660 if (login_timeout > TA_LOGIN_TIMEOUT_MAX) {
661 pr_err("Requested Login Timeout %u larger than maximum"
662 " %u\n", login_timeout, TA_LOGIN_TIMEOUT_MAX);
663 return -EINVAL;
664 } else if (login_timeout < TA_LOGIN_TIMEOUT_MIN) {
665 pr_err("Requested Logout Timeout %u smaller than"
666 " minimum %u\n", login_timeout, TA_LOGIN_TIMEOUT_MIN);
667 return -EINVAL;
670 a->login_timeout = login_timeout;
671 pr_debug("Set Logout Timeout to %u for Target Portal Group"
672 " %hu\n", a->login_timeout, tpg->tpgt);
674 return 0;
677 int iscsit_ta_netif_timeout(
678 struct iscsi_portal_group *tpg,
679 u32 netif_timeout)
681 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
683 if (netif_timeout > TA_NETIF_TIMEOUT_MAX) {
684 pr_err("Requested Network Interface Timeout %u larger"
685 " than maximum %u\n", netif_timeout,
686 TA_NETIF_TIMEOUT_MAX);
687 return -EINVAL;
688 } else if (netif_timeout < TA_NETIF_TIMEOUT_MIN) {
689 pr_err("Requested Network Interface Timeout %u smaller"
690 " than minimum %u\n", netif_timeout,
691 TA_NETIF_TIMEOUT_MIN);
692 return -EINVAL;
695 a->netif_timeout = netif_timeout;
696 pr_debug("Set Network Interface Timeout to %u for"
697 " Target Portal Group %hu\n", a->netif_timeout, tpg->tpgt);
699 return 0;
702 int iscsit_ta_generate_node_acls(
703 struct iscsi_portal_group *tpg,
704 u32 flag)
706 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
708 if ((flag != 0) && (flag != 1)) {
709 pr_err("Illegal value %d\n", flag);
710 return -EINVAL;
713 a->generate_node_acls = flag;
714 pr_debug("iSCSI_TPG[%hu] - Generate Initiator Portal Group ACLs: %s\n",
715 tpg->tpgt, (a->generate_node_acls) ? "Enabled" : "Disabled");
717 if (flag == 1 && a->cache_dynamic_acls == 0) {
718 pr_debug("Explicitly setting cache_dynamic_acls=1 when "
719 "generate_node_acls=1\n");
720 a->cache_dynamic_acls = 1;
723 return 0;
726 int iscsit_ta_default_cmdsn_depth(
727 struct iscsi_portal_group *tpg,
728 u32 tcq_depth)
730 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
732 if (tcq_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) {
733 pr_err("Requested Default Queue Depth: %u larger"
734 " than maximum %u\n", tcq_depth,
735 TA_DEFAULT_CMDSN_DEPTH_MAX);
736 return -EINVAL;
737 } else if (tcq_depth < TA_DEFAULT_CMDSN_DEPTH_MIN) {
738 pr_err("Requested Default Queue Depth: %u smaller"
739 " than minimum %u\n", tcq_depth,
740 TA_DEFAULT_CMDSN_DEPTH_MIN);
741 return -EINVAL;
744 a->default_cmdsn_depth = tcq_depth;
745 pr_debug("iSCSI_TPG[%hu] - Set Default CmdSN TCQ Depth to %u\n",
746 tpg->tpgt, a->default_cmdsn_depth);
748 return 0;
751 int iscsit_ta_cache_dynamic_acls(
752 struct iscsi_portal_group *tpg,
753 u32 flag)
755 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
757 if ((flag != 0) && (flag != 1)) {
758 pr_err("Illegal value %d\n", flag);
759 return -EINVAL;
762 if (a->generate_node_acls == 1 && flag == 0) {
763 pr_debug("Skipping cache_dynamic_acls=0 when"
764 " generate_node_acls=1\n");
765 return 0;
768 a->cache_dynamic_acls = flag;
769 pr_debug("iSCSI_TPG[%hu] - Cache Dynamic Initiator Portal Group"
770 " ACLs %s\n", tpg->tpgt, (a->cache_dynamic_acls) ?
771 "Enabled" : "Disabled");
773 return 0;
776 int iscsit_ta_demo_mode_write_protect(
777 struct iscsi_portal_group *tpg,
778 u32 flag)
780 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
782 if ((flag != 0) && (flag != 1)) {
783 pr_err("Illegal value %d\n", flag);
784 return -EINVAL;
787 a->demo_mode_write_protect = flag;
788 pr_debug("iSCSI_TPG[%hu] - Demo Mode Write Protect bit: %s\n",
789 tpg->tpgt, (a->demo_mode_write_protect) ? "ON" : "OFF");
791 return 0;
794 int iscsit_ta_prod_mode_write_protect(
795 struct iscsi_portal_group *tpg,
796 u32 flag)
798 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
800 if ((flag != 0) && (flag != 1)) {
801 pr_err("Illegal value %d\n", flag);
802 return -EINVAL;
805 a->prod_mode_write_protect = flag;
806 pr_debug("iSCSI_TPG[%hu] - Production Mode Write Protect bit:"
807 " %s\n", tpg->tpgt, (a->prod_mode_write_protect) ?
808 "ON" : "OFF");
810 return 0;
813 int iscsit_ta_demo_mode_discovery(
814 struct iscsi_portal_group *tpg,
815 u32 flag)
817 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
819 if ((flag != 0) && (flag != 1)) {
820 pr_err("Illegal value %d\n", flag);
821 return -EINVAL;
824 a->demo_mode_discovery = flag;
825 pr_debug("iSCSI_TPG[%hu] - Demo Mode Discovery bit:"
826 " %s\n", tpg->tpgt, (a->demo_mode_discovery) ?
827 "ON" : "OFF");
829 return 0;
832 int iscsit_ta_default_erl(
833 struct iscsi_portal_group *tpg,
834 u32 default_erl)
836 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
838 if ((default_erl != 0) && (default_erl != 1) && (default_erl != 2)) {
839 pr_err("Illegal value for default_erl: %u\n", default_erl);
840 return -EINVAL;
843 a->default_erl = default_erl;
844 pr_debug("iSCSI_TPG[%hu] - DefaultERL: %u\n", tpg->tpgt, a->default_erl);
846 return 0;
849 int iscsit_ta_t10_pi(
850 struct iscsi_portal_group *tpg,
851 u32 flag)
853 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
855 if ((flag != 0) && (flag != 1)) {
856 pr_err("Illegal value %d\n", flag);
857 return -EINVAL;
860 a->t10_pi = flag;
861 pr_debug("iSCSI_TPG[%hu] - T10 Protection information bit:"
862 " %s\n", tpg->tpgt, (a->t10_pi) ?
863 "ON" : "OFF");
865 return 0;
868 int iscsit_ta_fabric_prot_type(
869 struct iscsi_portal_group *tpg,
870 u32 prot_type)
872 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
874 if ((prot_type != 0) && (prot_type != 1) && (prot_type != 3)) {
875 pr_err("Illegal value for fabric_prot_type: %u\n", prot_type);
876 return -EINVAL;
879 a->fabric_prot_type = prot_type;
880 pr_debug("iSCSI_TPG[%hu] - T10 Fabric Protection Type: %u\n",
881 tpg->tpgt, prot_type);
883 return 0;
886 int iscsit_ta_tpg_enabled_sendtargets(
887 struct iscsi_portal_group *tpg,
888 u32 flag)
890 struct iscsi_tpg_attrib *a = &tpg->tpg_attrib;
892 if ((flag != 0) && (flag != 1)) {
893 pr_err("Illegal value %d\n", flag);
894 return -EINVAL;
897 a->tpg_enabled_sendtargets = flag;
898 pr_debug("iSCSI_TPG[%hu] - TPG enabled bit required for SendTargets:"
899 " %s\n", tpg->tpgt, (a->tpg_enabled_sendtargets) ? "ON" : "OFF");
901 return 0;