Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * This file contains iSCSI Target Portal Group related functions. |
| 3 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 4 | * (c) Copyright 2007-2013 Datera, Inc. |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 5 | * |
| 6 | * Author: Nicholas A. Bellinger <nab@linux-iscsi.org> |
| 7 | * |
| 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. |
| 12 | * |
| 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 | ******************************************************************************/ |
| 18 | |
| 19 | #include <target/target_core_base.h> |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 20 | #include <target/target_core_fabric.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 21 | |
Sagi Grimberg | 67f091f | 2015-01-07 14:57:31 +0200 | [diff] [blame] | 22 | #include <target/iscsi/iscsi_target_core.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 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" |
| 30 | |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 31 | #include <target/iscsi/iscsi_transport.h> |
| 32 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 33 | struct iscsi_portal_group *iscsit_alloc_portal_group(struct iscsi_tiqn *tiqn, u16 tpgt) |
| 34 | { |
| 35 | struct iscsi_portal_group *tpg; |
| 36 | |
| 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; |
| 41 | } |
| 42 | |
| 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); |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 49 | sema_init(&tpg->np_login_sem, 1); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 50 | spin_lock_init(&tpg->tpg_state_lock); |
| 51 | spin_lock_init(&tpg->tpg_np_lock); |
| 52 | |
| 53 | return tpg; |
| 54 | } |
| 55 | |
| 56 | static void iscsit_set_default_tpg_attribs(struct iscsi_portal_group *); |
| 57 | |
| 58 | int iscsit_load_discovery_tpg(void) |
| 59 | { |
| 60 | struct iscsi_param *param; |
| 61 | struct iscsi_portal_group *tpg; |
| 62 | int ret; |
| 63 | |
| 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; |
| 68 | } |
| 69 | |
Christoph Hellwig | e4aae5a | 2015-05-01 17:47:56 +0200 | [diff] [blame] | 70 | ret = core_tpg_register(&iscsi_ops, NULL, &tpg->tpg_se_tpg, -1); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 71 | if (ret < 0) { |
| 72 | kfree(tpg); |
| 73 | return -1; |
| 74 | } |
| 75 | |
| 76 | tpg->sid = 1; /* First Assigned LIO Session ID */ |
| 77 | iscsit_set_default_tpg_attribs(tpg); |
| 78 | |
| 79 | if (iscsi_create_default_params(&tpg->param_list) < 0) |
| 80 | goto out; |
| 81 | /* |
| 82 | * By default we disable authentication for discovery sessions, |
| 83 | * this can be changed with: |
| 84 | * |
| 85 | * /sys/kernel/config/target/iscsi/discovery_auth/enforce_discovery_auth |
| 86 | */ |
| 87 | param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list); |
| 88 | if (!param) |
| 89 | goto out; |
| 90 | |
| 91 | if (iscsi_update_param_value(param, "CHAP,None") < 0) |
| 92 | goto out; |
| 93 | |
| 94 | tpg->tpg_attrib.authentication = 0; |
| 95 | |
| 96 | spin_lock(&tpg->tpg_state_lock); |
| 97 | tpg->tpg_state = TPG_STATE_ACTIVE; |
| 98 | spin_unlock(&tpg->tpg_state_lock); |
| 99 | |
| 100 | iscsit_global->discovery_tpg = tpg; |
| 101 | pr_debug("CORE[0] - Allocated Discovery TPG\n"); |
| 102 | |
| 103 | return 0; |
| 104 | out: |
| 105 | if (tpg->sid == 1) |
| 106 | core_tpg_deregister(&tpg->tpg_se_tpg); |
| 107 | kfree(tpg); |
| 108 | return -1; |
| 109 | } |
| 110 | |
| 111 | void iscsit_release_discovery_tpg(void) |
| 112 | { |
| 113 | struct iscsi_portal_group *tpg = iscsit_global->discovery_tpg; |
| 114 | |
| 115 | if (!tpg) |
| 116 | return; |
| 117 | |
| 118 | core_tpg_deregister(&tpg->tpg_se_tpg); |
| 119 | |
| 120 | kfree(tpg); |
| 121 | iscsit_global->discovery_tpg = NULL; |
| 122 | } |
| 123 | |
| 124 | struct iscsi_portal_group *iscsit_get_tpg_from_np( |
| 125 | struct iscsi_tiqn *tiqn, |
Nicholas Bellinger | d381a80 | 2013-08-15 13:40:17 -0700 | [diff] [blame] | 126 | struct iscsi_np *np, |
| 127 | struct iscsi_tpg_np **tpg_np_out) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 128 | { |
| 129 | struct iscsi_portal_group *tpg = NULL; |
| 130 | struct iscsi_tpg_np *tpg_np; |
| 131 | |
| 132 | spin_lock(&tiqn->tiqn_tpg_lock); |
| 133 | list_for_each_entry(tpg, &tiqn->tiqn_tpg_list, tpg_list) { |
| 134 | |
| 135 | spin_lock(&tpg->tpg_state_lock); |
Nicholas Bellinger | a2a99ce | 2014-02-26 03:09:41 -0800 | [diff] [blame] | 136 | if (tpg->tpg_state != TPG_STATE_ACTIVE) { |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 137 | spin_unlock(&tpg->tpg_state_lock); |
| 138 | continue; |
| 139 | } |
| 140 | spin_unlock(&tpg->tpg_state_lock); |
| 141 | |
| 142 | spin_lock(&tpg->tpg_np_lock); |
| 143 | list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, tpg_np_list) { |
| 144 | if (tpg_np->tpg_np == np) { |
Nicholas Bellinger | d381a80 | 2013-08-15 13:40:17 -0700 | [diff] [blame] | 145 | *tpg_np_out = tpg_np; |
| 146 | kref_get(&tpg_np->tpg_np_kref); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 147 | spin_unlock(&tpg->tpg_np_lock); |
| 148 | spin_unlock(&tiqn->tiqn_tpg_lock); |
| 149 | return tpg; |
| 150 | } |
| 151 | } |
| 152 | spin_unlock(&tpg->tpg_np_lock); |
| 153 | } |
| 154 | spin_unlock(&tiqn->tiqn_tpg_lock); |
| 155 | |
| 156 | return NULL; |
| 157 | } |
| 158 | |
| 159 | int iscsit_get_tpg( |
| 160 | struct iscsi_portal_group *tpg) |
| 161 | { |
Nicholas Bellinger | ee7619f | 2015-05-19 15:10:44 -0700 | [diff] [blame] | 162 | return mutex_lock_interruptible(&tpg->tpg_access_lock); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | void iscsit_put_tpg(struct iscsi_portal_group *tpg) |
| 166 | { |
| 167 | mutex_unlock(&tpg->tpg_access_lock); |
| 168 | } |
| 169 | |
| 170 | static void iscsit_clear_tpg_np_login_thread( |
| 171 | struct iscsi_tpg_np *tpg_np, |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 172 | struct iscsi_portal_group *tpg, |
| 173 | bool shutdown) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 174 | { |
| 175 | if (!tpg_np->tpg_np) { |
| 176 | pr_err("struct iscsi_tpg_np->tpg_np is NULL!\n"); |
| 177 | return; |
| 178 | } |
| 179 | |
Nicholas Bellinger | 2363d19 | 2014-06-03 18:27:52 -0700 | [diff] [blame] | 180 | if (shutdown) |
| 181 | tpg_np->tpg_np->enabled = false; |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 182 | iscsit_reset_np_thread(tpg_np->tpg_np, tpg_np, tpg, shutdown); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Nicholas Bellinger | 5256ffd | 2014-06-03 18:28:25 -0700 | [diff] [blame] | 185 | static void iscsit_clear_tpg_np_login_threads( |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 186 | struct iscsi_portal_group *tpg, |
| 187 | bool shutdown) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 188 | { |
| 189 | struct iscsi_tpg_np *tpg_np; |
| 190 | |
| 191 | spin_lock(&tpg->tpg_np_lock); |
| 192 | list_for_each_entry(tpg_np, &tpg->tpg_gnp_list, tpg_np_list) { |
| 193 | if (!tpg_np->tpg_np) { |
| 194 | pr_err("struct iscsi_tpg_np->tpg_np is NULL!\n"); |
| 195 | continue; |
| 196 | } |
| 197 | spin_unlock(&tpg->tpg_np_lock); |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 198 | iscsit_clear_tpg_np_login_thread(tpg_np, tpg, shutdown); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 199 | spin_lock(&tpg->tpg_np_lock); |
| 200 | } |
| 201 | spin_unlock(&tpg->tpg_np_lock); |
| 202 | } |
| 203 | |
| 204 | void iscsit_tpg_dump_params(struct iscsi_portal_group *tpg) |
| 205 | { |
| 206 | iscsi_print_params(tpg->param_list); |
| 207 | } |
| 208 | |
| 209 | static void iscsit_set_default_tpg_attribs(struct iscsi_portal_group *tpg) |
| 210 | { |
| 211 | struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; |
| 212 | |
| 213 | a->authentication = TA_AUTHENTICATION; |
| 214 | a->login_timeout = TA_LOGIN_TIMEOUT; |
| 215 | a->netif_timeout = TA_NETIF_TIMEOUT; |
| 216 | a->default_cmdsn_depth = TA_DEFAULT_CMDSN_DEPTH; |
| 217 | a->generate_node_acls = TA_GENERATE_NODE_ACLS; |
| 218 | a->cache_dynamic_acls = TA_CACHE_DYNAMIC_ACLS; |
| 219 | a->demo_mode_write_protect = TA_DEMO_MODE_WRITE_PROTECT; |
| 220 | a->prod_mode_write_protect = TA_PROD_MODE_WRITE_PROTECT; |
Thomas Glanzmann | 4c54b6c | 2013-10-07 23:12:11 +0200 | [diff] [blame] | 221 | a->demo_mode_discovery = TA_DEMO_MODE_DISCOVERY; |
Nicholas Bellinger | d1fa7a1 | 2013-11-20 11:57:18 -0800 | [diff] [blame] | 222 | a->default_erl = TA_DEFAULT_ERL; |
Sagi Grimberg | 5b168dc | 2014-02-19 17:50:19 +0200 | [diff] [blame] | 223 | a->t10_pi = TA_DEFAULT_T10_PI; |
Nicholas Bellinger | 901c04a | 2015-03-29 19:36:16 -0700 | [diff] [blame] | 224 | a->fabric_prot_type = TA_DEFAULT_FABRIC_PROT_TYPE; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | int iscsit_tpg_add_portal_group(struct iscsi_tiqn *tiqn, struct iscsi_portal_group *tpg) |
| 228 | { |
| 229 | if (tpg->tpg_state != TPG_STATE_FREE) { |
| 230 | pr_err("Unable to add iSCSI Target Portal Group: %d" |
| 231 | " while not in TPG_STATE_FREE state.\n", tpg->tpgt); |
| 232 | return -EEXIST; |
| 233 | } |
| 234 | iscsit_set_default_tpg_attribs(tpg); |
| 235 | |
| 236 | if (iscsi_create_default_params(&tpg->param_list) < 0) |
| 237 | goto err_out; |
| 238 | |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 239 | tpg->tpg_attrib.tpg = tpg; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 240 | |
| 241 | spin_lock(&tpg->tpg_state_lock); |
| 242 | tpg->tpg_state = TPG_STATE_INACTIVE; |
| 243 | spin_unlock(&tpg->tpg_state_lock); |
| 244 | |
| 245 | spin_lock(&tiqn->tiqn_tpg_lock); |
| 246 | list_add_tail(&tpg->tpg_list, &tiqn->tiqn_tpg_list); |
| 247 | tiqn->tiqn_ntpgs++; |
| 248 | pr_debug("CORE[%s]_TPG[%hu] - Added iSCSI Target Portal Group\n", |
| 249 | tiqn->tiqn, tpg->tpgt); |
| 250 | spin_unlock(&tiqn->tiqn_tpg_lock); |
| 251 | |
| 252 | return 0; |
| 253 | err_out: |
| 254 | if (tpg->param_list) { |
| 255 | iscsi_release_param_list(tpg->param_list); |
| 256 | tpg->param_list = NULL; |
| 257 | } |
| 258 | kfree(tpg); |
| 259 | return -ENOMEM; |
| 260 | } |
| 261 | |
| 262 | int iscsit_tpg_del_portal_group( |
| 263 | struct iscsi_tiqn *tiqn, |
| 264 | struct iscsi_portal_group *tpg, |
| 265 | int force) |
| 266 | { |
| 267 | u8 old_state = tpg->tpg_state; |
| 268 | |
| 269 | spin_lock(&tpg->tpg_state_lock); |
| 270 | tpg->tpg_state = TPG_STATE_INACTIVE; |
| 271 | spin_unlock(&tpg->tpg_state_lock); |
| 272 | |
| 273 | if (iscsit_release_sessions_for_tpg(tpg, force) < 0) { |
| 274 | pr_err("Unable to delete iSCSI Target Portal Group:" |
| 275 | " %hu while active sessions exist, and force=0\n", |
| 276 | tpg->tpgt); |
| 277 | tpg->tpg_state = old_state; |
| 278 | return -EPERM; |
| 279 | } |
| 280 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 281 | if (tpg->param_list) { |
| 282 | iscsi_release_param_list(tpg->param_list); |
| 283 | tpg->param_list = NULL; |
| 284 | } |
| 285 | |
| 286 | core_tpg_deregister(&tpg->tpg_se_tpg); |
| 287 | |
| 288 | spin_lock(&tpg->tpg_state_lock); |
| 289 | tpg->tpg_state = TPG_STATE_FREE; |
| 290 | spin_unlock(&tpg->tpg_state_lock); |
| 291 | |
| 292 | spin_lock(&tiqn->tiqn_tpg_lock); |
| 293 | tiqn->tiqn_ntpgs--; |
| 294 | list_del(&tpg->tpg_list); |
| 295 | spin_unlock(&tiqn->tiqn_tpg_lock); |
| 296 | |
| 297 | pr_debug("CORE[%s]_TPG[%hu] - Deleted iSCSI Target Portal Group\n", |
| 298 | tiqn->tiqn, tpg->tpgt); |
| 299 | |
| 300 | kfree(tpg); |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | int iscsit_tpg_enable_portal_group(struct iscsi_portal_group *tpg) |
| 305 | { |
| 306 | struct iscsi_param *param; |
| 307 | struct iscsi_tiqn *tiqn = tpg->tpg_tiqn; |
Andy Grover | 617a0c2 | 2012-07-12 17:34:56 -0700 | [diff] [blame] | 308 | int ret; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 309 | |
| 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; |
| 316 | } |
| 317 | /* |
| 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. |
| 321 | */ |
| 322 | param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list); |
| 323 | if (!param) { |
| 324 | spin_unlock(&tpg->tpg_state_lock); |
Andy Grover | 617a0c2 | 2012-07-12 17:34:56 -0700 | [diff] [blame] | 325 | return -EINVAL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 326 | } |
| 327 | |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 328 | if (tpg->tpg_attrib.authentication) { |
Andy Grover | 617a0c2 | 2012-07-12 17:34:56 -0700 | [diff] [blame] | 329 | if (!strcmp(param->value, NONE)) { |
| 330 | ret = iscsi_update_param_value(param, CHAP); |
| 331 | if (ret) |
| 332 | goto err; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 333 | } |
Andy Grover | 617a0c2 | 2012-07-12 17:34:56 -0700 | [diff] [blame] | 334 | |
| 335 | ret = iscsit_ta_authentication(tpg, 1); |
| 336 | if (ret < 0) |
| 337 | goto err; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | tpg->tpg_state = TPG_STATE_ACTIVE; |
| 341 | spin_unlock(&tpg->tpg_state_lock); |
| 342 | |
| 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); |
| 348 | |
| 349 | return 0; |
Andy Grover | 617a0c2 | 2012-07-12 17:34:56 -0700 | [diff] [blame] | 350 | |
| 351 | err: |
| 352 | spin_unlock(&tpg->tpg_state_lock); |
| 353 | return ret; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | int iscsit_tpg_disable_portal_group(struct iscsi_portal_group *tpg, int force) |
| 357 | { |
| 358 | struct iscsi_tiqn *tiqn; |
| 359 | u8 old_state = tpg->tpg_state; |
| 360 | |
| 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; |
| 367 | } |
| 368 | tpg->tpg_state = TPG_STATE_INACTIVE; |
| 369 | spin_unlock(&tpg->tpg_state_lock); |
| 370 | |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 371 | iscsit_clear_tpg_np_login_threads(tpg, false); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 372 | |
| 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; |
| 381 | } |
| 382 | |
| 383 | tiqn = tpg->tpg_tiqn; |
| 384 | if (!tiqn || (tpg == iscsit_global->discovery_tpg)) |
| 385 | return 0; |
| 386 | |
| 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); |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | struct iscsi_node_attrib *iscsit_tpg_get_node_attrib( |
| 397 | struct iscsi_session *sess) |
| 398 | { |
| 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); |
| 403 | |
| 404 | return &acl->node_attrib; |
| 405 | } |
| 406 | |
| 407 | struct iscsi_tpg_np *iscsit_tpg_locate_child_np( |
| 408 | struct iscsi_tpg_np *tpg_np, |
| 409 | int network_transport) |
| 410 | { |
| 411 | struct iscsi_tpg_np *tpg_np_child, *tpg_np_child_tmp; |
| 412 | |
| 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; |
| 420 | } |
| 421 | } |
| 422 | spin_unlock(&tpg_np->tpg_np_parent_lock); |
| 423 | |
| 424 | return NULL; |
| 425 | } |
| 426 | |
Nicholas Bellinger | 6e54593 | 2013-02-18 21:01:02 -0800 | [diff] [blame] | 427 | static bool iscsit_tpg_check_network_portal( |
| 428 | struct iscsi_tiqn *tiqn, |
| 429 | struct __kernel_sockaddr_storage *sockaddr, |
| 430 | int network_transport) |
| 431 | { |
| 432 | struct iscsi_portal_group *tpg; |
| 433 | struct iscsi_tpg_np *tpg_np; |
| 434 | struct iscsi_np *np; |
| 435 | bool match = false; |
| 436 | |
| 437 | spin_lock(&tiqn->tiqn_tpg_lock); |
| 438 | list_for_each_entry(tpg, &tiqn->tiqn_tpg_list, tpg_list) { |
| 439 | |
| 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; |
| 443 | |
| 444 | match = iscsit_check_np_match(sockaddr, np, |
| 445 | network_transport); |
Christophe Vu-Brugier | 0bcc297 | 2014-06-06 17:15:16 +0200 | [diff] [blame] | 446 | if (match) |
Nicholas Bellinger | 6e54593 | 2013-02-18 21:01:02 -0800 | [diff] [blame] | 447 | break; |
| 448 | } |
| 449 | spin_unlock(&tpg->tpg_np_lock); |
| 450 | } |
| 451 | spin_unlock(&tiqn->tiqn_tpg_lock); |
| 452 | |
| 453 | return match; |
| 454 | } |
| 455 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 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) |
| 462 | { |
| 463 | struct iscsi_np *np; |
| 464 | struct iscsi_tpg_np *tpg_np; |
| 465 | |
Nicholas Bellinger | 6e54593 | 2013-02-18 21:01:02 -0800 | [diff] [blame] | 466 | if (!tpg_np_parent) { |
| 467 | if (iscsit_tpg_check_network_portal(tpg->tpg_tiqn, sockaddr, |
Christophe Vu-Brugier | 0bcc297 | 2014-06-06 17:15:16 +0200 | [diff] [blame] | 468 | network_transport)) { |
Nicholas Bellinger | 6e54593 | 2013-02-18 21:01:02 -0800 | [diff] [blame] | 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); |
| 473 | } |
| 474 | } |
| 475 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 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); |
| 481 | } |
| 482 | |
| 483 | np = iscsit_add_np(sockaddr, ip_str, network_transport); |
| 484 | if (IS_ERR(np)) { |
| 485 | kfree(tpg_np); |
| 486 | return ERR_CAST(np); |
| 487 | } |
| 488 | |
| 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); |
Nicholas Bellinger | d381a80 | 2013-08-15 13:40:17 -0700 | [diff] [blame] | 493 | init_completion(&tpg_np->tpg_np_comp); |
| 494 | kref_init(&tpg_np->tpg_np_kref); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 495 | tpg_np->tpg_np = np; |
| 496 | tpg_np->tpg = tpg; |
| 497 | |
| 498 | spin_lock(&tpg->tpg_np_lock); |
| 499 | list_add_tail(&tpg_np->tpg_np_list, &tpg->tpg_gnp_list); |
| 500 | tpg->num_tpg_nps++; |
| 501 | if (tpg->tpg_tiqn) |
| 502 | tpg->tpg_tiqn->tiqn_num_tpg_nps++; |
| 503 | spin_unlock(&tpg->tpg_np_lock); |
| 504 | |
| 505 | if (tpg_np_parent) { |
| 506 | tpg_np->tpg_np_parent = tpg_np_parent; |
| 507 | spin_lock(&tpg_np_parent->tpg_np_parent_lock); |
| 508 | list_add_tail(&tpg_np->tpg_np_child_list, |
| 509 | &tpg_np_parent->tpg_np_parent_list); |
| 510 | spin_unlock(&tpg_np_parent->tpg_np_parent_lock); |
| 511 | } |
| 512 | |
| 513 | pr_debug("CORE[%s] - Added Network Portal: %s:%hu,%hu on %s\n", |
| 514 | tpg->tpg_tiqn->tiqn, np->np_ip, np->np_port, tpg->tpgt, |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 515 | np->np_transport->name); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 516 | |
| 517 | return tpg_np; |
| 518 | } |
| 519 | |
| 520 | static int iscsit_tpg_release_np( |
| 521 | struct iscsi_tpg_np *tpg_np, |
| 522 | struct iscsi_portal_group *tpg, |
| 523 | struct iscsi_np *np) |
| 524 | { |
Nicholas Bellinger | a91eb7d | 2013-08-15 12:49:02 -0700 | [diff] [blame] | 525 | iscsit_clear_tpg_np_login_thread(tpg_np, tpg, true); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 526 | |
| 527 | pr_debug("CORE[%s] - Removed Network Portal: %s:%hu,%hu on %s\n", |
| 528 | tpg->tpg_tiqn->tiqn, np->np_ip, np->np_port, tpg->tpgt, |
Nicholas Bellinger | baa4d64 | 2013-03-06 21:54:13 -0800 | [diff] [blame] | 529 | np->np_transport->name); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 530 | |
| 531 | tpg_np->tpg_np = NULL; |
| 532 | tpg_np->tpg = NULL; |
| 533 | kfree(tpg_np); |
| 534 | /* |
| 535 | * iscsit_del_np() will shutdown struct iscsi_np when last TPG reference is released. |
| 536 | */ |
| 537 | return iscsit_del_np(np); |
| 538 | } |
| 539 | |
| 540 | int iscsit_tpg_del_network_portal( |
| 541 | struct iscsi_portal_group *tpg, |
| 542 | struct iscsi_tpg_np *tpg_np) |
| 543 | { |
| 544 | struct iscsi_np *np; |
| 545 | struct iscsi_tpg_np *tpg_np_child, *tpg_np_child_tmp; |
| 546 | int ret = 0; |
| 547 | |
| 548 | np = tpg_np->tpg_np; |
| 549 | if (!np) { |
| 550 | pr_err("Unable to locate struct iscsi_np from" |
| 551 | " struct iscsi_tpg_np\n"); |
| 552 | return -EINVAL; |
| 553 | } |
| 554 | |
| 555 | if (!tpg_np->tpg_np_parent) { |
| 556 | /* |
| 557 | * We are the parent tpg network portal. Release all of the |
| 558 | * child tpg_np's (eg: the non ISCSI_TCP ones) on our parent |
| 559 | * list first. |
| 560 | */ |
| 561 | list_for_each_entry_safe(tpg_np_child, tpg_np_child_tmp, |
| 562 | &tpg_np->tpg_np_parent_list, |
| 563 | tpg_np_child_list) { |
| 564 | ret = iscsit_tpg_del_network_portal(tpg, tpg_np_child); |
| 565 | if (ret < 0) |
| 566 | pr_err("iscsit_tpg_del_network_portal()" |
| 567 | " failed: %d\n", ret); |
| 568 | } |
| 569 | } else { |
| 570 | /* |
| 571 | * We are not the parent ISCSI_TCP tpg network portal. Release |
| 572 | * our own network portals from the child list. |
| 573 | */ |
| 574 | spin_lock(&tpg_np->tpg_np_parent->tpg_np_parent_lock); |
| 575 | list_del(&tpg_np->tpg_np_child_list); |
| 576 | spin_unlock(&tpg_np->tpg_np_parent->tpg_np_parent_lock); |
| 577 | } |
| 578 | |
| 579 | spin_lock(&tpg->tpg_np_lock); |
| 580 | list_del(&tpg_np->tpg_np_list); |
| 581 | tpg->num_tpg_nps--; |
| 582 | if (tpg->tpg_tiqn) |
| 583 | tpg->tpg_tiqn->tiqn_num_tpg_nps--; |
| 584 | spin_unlock(&tpg->tpg_np_lock); |
| 585 | |
| 586 | return iscsit_tpg_release_np(tpg_np, tpg, np); |
| 587 | } |
| 588 | |
| 589 | int iscsit_tpg_set_initiator_node_queue_depth( |
| 590 | struct iscsi_portal_group *tpg, |
| 591 | unsigned char *initiatorname, |
| 592 | u32 queue_depth, |
| 593 | int force) |
| 594 | { |
| 595 | return core_tpg_set_initiator_node_queue_depth(&tpg->tpg_se_tpg, |
| 596 | initiatorname, queue_depth, force); |
| 597 | } |
| 598 | |
| 599 | int iscsit_ta_authentication(struct iscsi_portal_group *tpg, u32 authentication) |
| 600 | { |
| 601 | unsigned char buf1[256], buf2[256], *none = NULL; |
| 602 | int len; |
| 603 | struct iscsi_param *param; |
| 604 | struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; |
| 605 | |
| 606 | if ((authentication != 1) && (authentication != 0)) { |
| 607 | pr_err("Illegal value for authentication parameter:" |
| 608 | " %u, ignoring request.\n", authentication); |
Andy Grover | 617a0c2 | 2012-07-12 17:34:56 -0700 | [diff] [blame] | 609 | return -EINVAL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | memset(buf1, 0, sizeof(buf1)); |
| 613 | memset(buf2, 0, sizeof(buf2)); |
| 614 | |
| 615 | param = iscsi_find_param_from_key(AUTHMETHOD, tpg->param_list); |
| 616 | if (!param) |
| 617 | return -EINVAL; |
| 618 | |
| 619 | if (authentication) { |
| 620 | snprintf(buf1, sizeof(buf1), "%s", param->value); |
| 621 | none = strstr(buf1, NONE); |
| 622 | if (!none) |
| 623 | goto out; |
| 624 | if (!strncmp(none + 4, ",", 1)) { |
| 625 | if (!strcmp(buf1, none)) |
| 626 | sprintf(buf2, "%s", none+5); |
| 627 | else { |
| 628 | none--; |
| 629 | *none = '\0'; |
| 630 | len = sprintf(buf2, "%s", buf1); |
| 631 | none += 5; |
| 632 | sprintf(buf2 + len, "%s", none); |
| 633 | } |
| 634 | } else { |
| 635 | none--; |
| 636 | *none = '\0'; |
| 637 | sprintf(buf2, "%s", buf1); |
| 638 | } |
| 639 | if (iscsi_update_param_value(param, buf2) < 0) |
| 640 | return -EINVAL; |
| 641 | } else { |
| 642 | snprintf(buf1, sizeof(buf1), "%s", param->value); |
| 643 | none = strstr(buf1, NONE); |
Andy Grover | ee1b1b9 | 2012-07-12 17:34:54 -0700 | [diff] [blame] | 644 | if (none) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 645 | goto out; |
| 646 | strncat(buf1, ",", strlen(",")); |
| 647 | strncat(buf1, NONE, strlen(NONE)); |
| 648 | if (iscsi_update_param_value(param, buf1) < 0) |
| 649 | return -EINVAL; |
| 650 | } |
| 651 | |
| 652 | out: |
| 653 | a->authentication = authentication; |
| 654 | pr_debug("%s iSCSI Authentication Methods for TPG: %hu.\n", |
| 655 | a->authentication ? "Enforcing" : "Disabling", tpg->tpgt); |
| 656 | |
| 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | int iscsit_ta_login_timeout( |
| 661 | struct iscsi_portal_group *tpg, |
| 662 | u32 login_timeout) |
| 663 | { |
| 664 | struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; |
| 665 | |
| 666 | if (login_timeout > TA_LOGIN_TIMEOUT_MAX) { |
| 667 | pr_err("Requested Login Timeout %u larger than maximum" |
| 668 | " %u\n", login_timeout, TA_LOGIN_TIMEOUT_MAX); |
| 669 | return -EINVAL; |
| 670 | } else if (login_timeout < TA_LOGIN_TIMEOUT_MIN) { |
| 671 | pr_err("Requested Logout Timeout %u smaller than" |
| 672 | " minimum %u\n", login_timeout, TA_LOGIN_TIMEOUT_MIN); |
| 673 | return -EINVAL; |
| 674 | } |
| 675 | |
| 676 | a->login_timeout = login_timeout; |
| 677 | pr_debug("Set Logout Timeout to %u for Target Portal Group" |
| 678 | " %hu\n", a->login_timeout, tpg->tpgt); |
| 679 | |
| 680 | return 0; |
| 681 | } |
| 682 | |
| 683 | int iscsit_ta_netif_timeout( |
| 684 | struct iscsi_portal_group *tpg, |
| 685 | u32 netif_timeout) |
| 686 | { |
| 687 | struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; |
| 688 | |
| 689 | if (netif_timeout > TA_NETIF_TIMEOUT_MAX) { |
| 690 | pr_err("Requested Network Interface Timeout %u larger" |
| 691 | " than maximum %u\n", netif_timeout, |
| 692 | TA_NETIF_TIMEOUT_MAX); |
| 693 | return -EINVAL; |
| 694 | } else if (netif_timeout < TA_NETIF_TIMEOUT_MIN) { |
| 695 | pr_err("Requested Network Interface Timeout %u smaller" |
| 696 | " than minimum %u\n", netif_timeout, |
| 697 | TA_NETIF_TIMEOUT_MIN); |
| 698 | return -EINVAL; |
| 699 | } |
| 700 | |
| 701 | a->netif_timeout = netif_timeout; |
| 702 | pr_debug("Set Network Interface Timeout to %u for" |
| 703 | " Target Portal Group %hu\n", a->netif_timeout, tpg->tpgt); |
| 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
| 708 | int iscsit_ta_generate_node_acls( |
| 709 | struct iscsi_portal_group *tpg, |
| 710 | u32 flag) |
| 711 | { |
| 712 | struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; |
| 713 | |
| 714 | if ((flag != 0) && (flag != 1)) { |
| 715 | pr_err("Illegal value %d\n", flag); |
| 716 | return -EINVAL; |
| 717 | } |
| 718 | |
| 719 | a->generate_node_acls = flag; |
| 720 | pr_debug("iSCSI_TPG[%hu] - Generate Initiator Portal Group ACLs: %s\n", |
| 721 | tpg->tpgt, (a->generate_node_acls) ? "Enabled" : "Disabled"); |
| 722 | |
Nicholas Bellinger | 38b11ba | 2012-09-30 12:20:02 -0700 | [diff] [blame] | 723 | if (flag == 1 && a->cache_dynamic_acls == 0) { |
| 724 | pr_debug("Explicitly setting cache_dynamic_acls=1 when " |
| 725 | "generate_node_acls=1\n"); |
| 726 | a->cache_dynamic_acls = 1; |
| 727 | } |
| 728 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | int iscsit_ta_default_cmdsn_depth( |
| 733 | struct iscsi_portal_group *tpg, |
| 734 | u32 tcq_depth) |
| 735 | { |
| 736 | struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; |
| 737 | |
| 738 | if (tcq_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) { |
| 739 | pr_err("Requested Default Queue Depth: %u larger" |
| 740 | " than maximum %u\n", tcq_depth, |
| 741 | TA_DEFAULT_CMDSN_DEPTH_MAX); |
| 742 | return -EINVAL; |
| 743 | } else if (tcq_depth < TA_DEFAULT_CMDSN_DEPTH_MIN) { |
| 744 | pr_err("Requested Default Queue Depth: %u smaller" |
| 745 | " than minimum %u\n", tcq_depth, |
| 746 | TA_DEFAULT_CMDSN_DEPTH_MIN); |
| 747 | return -EINVAL; |
| 748 | } |
| 749 | |
| 750 | a->default_cmdsn_depth = tcq_depth; |
| 751 | pr_debug("iSCSI_TPG[%hu] - Set Default CmdSN TCQ Depth to %u\n", |
| 752 | tpg->tpgt, a->default_cmdsn_depth); |
| 753 | |
| 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | int iscsit_ta_cache_dynamic_acls( |
| 758 | struct iscsi_portal_group *tpg, |
| 759 | u32 flag) |
| 760 | { |
| 761 | struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; |
| 762 | |
| 763 | if ((flag != 0) && (flag != 1)) { |
| 764 | pr_err("Illegal value %d\n", flag); |
| 765 | return -EINVAL; |
| 766 | } |
| 767 | |
Nicholas Bellinger | 38b11ba | 2012-09-30 12:20:02 -0700 | [diff] [blame] | 768 | if (a->generate_node_acls == 1 && flag == 0) { |
| 769 | pr_debug("Skipping cache_dynamic_acls=0 when" |
| 770 | " generate_node_acls=1\n"); |
| 771 | return 0; |
| 772 | } |
| 773 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 774 | a->cache_dynamic_acls = flag; |
| 775 | pr_debug("iSCSI_TPG[%hu] - Cache Dynamic Initiator Portal Group" |
| 776 | " ACLs %s\n", tpg->tpgt, (a->cache_dynamic_acls) ? |
| 777 | "Enabled" : "Disabled"); |
| 778 | |
| 779 | return 0; |
| 780 | } |
| 781 | |
| 782 | int iscsit_ta_demo_mode_write_protect( |
| 783 | struct iscsi_portal_group *tpg, |
| 784 | u32 flag) |
| 785 | { |
| 786 | struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; |
| 787 | |
| 788 | if ((flag != 0) && (flag != 1)) { |
| 789 | pr_err("Illegal value %d\n", flag); |
| 790 | return -EINVAL; |
| 791 | } |
| 792 | |
| 793 | a->demo_mode_write_protect = flag; |
| 794 | pr_debug("iSCSI_TPG[%hu] - Demo Mode Write Protect bit: %s\n", |
| 795 | tpg->tpgt, (a->demo_mode_write_protect) ? "ON" : "OFF"); |
| 796 | |
| 797 | return 0; |
| 798 | } |
| 799 | |
| 800 | int iscsit_ta_prod_mode_write_protect( |
| 801 | struct iscsi_portal_group *tpg, |
| 802 | u32 flag) |
| 803 | { |
| 804 | struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; |
| 805 | |
| 806 | if ((flag != 0) && (flag != 1)) { |
| 807 | pr_err("Illegal value %d\n", flag); |
| 808 | return -EINVAL; |
| 809 | } |
| 810 | |
| 811 | a->prod_mode_write_protect = flag; |
| 812 | pr_debug("iSCSI_TPG[%hu] - Production Mode Write Protect bit:" |
| 813 | " %s\n", tpg->tpgt, (a->prod_mode_write_protect) ? |
| 814 | "ON" : "OFF"); |
| 815 | |
| 816 | return 0; |
| 817 | } |
Thomas Glanzmann | 4c54b6c | 2013-10-07 23:12:11 +0200 | [diff] [blame] | 818 | |
| 819 | int iscsit_ta_demo_mode_discovery( |
| 820 | struct iscsi_portal_group *tpg, |
| 821 | u32 flag) |
| 822 | { |
| 823 | struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; |
| 824 | |
| 825 | if ((flag != 0) && (flag != 1)) { |
| 826 | pr_err("Illegal value %d\n", flag); |
| 827 | return -EINVAL; |
| 828 | } |
| 829 | |
| 830 | a->demo_mode_discovery = flag; |
| 831 | pr_debug("iSCSI_TPG[%hu] - Demo Mode Discovery bit:" |
| 832 | " %s\n", tpg->tpgt, (a->demo_mode_discovery) ? |
| 833 | "ON" : "OFF"); |
| 834 | |
| 835 | return 0; |
| 836 | } |
Nicholas Bellinger | d1fa7a1 | 2013-11-20 11:57:18 -0800 | [diff] [blame] | 837 | |
| 838 | int iscsit_ta_default_erl( |
| 839 | struct iscsi_portal_group *tpg, |
| 840 | u32 default_erl) |
| 841 | { |
| 842 | struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; |
| 843 | |
| 844 | if ((default_erl != 0) && (default_erl != 1) && (default_erl != 2)) { |
| 845 | pr_err("Illegal value for default_erl: %u\n", default_erl); |
| 846 | return -EINVAL; |
| 847 | } |
| 848 | |
| 849 | a->default_erl = default_erl; |
| 850 | pr_debug("iSCSI_TPG[%hu] - DefaultERL: %u\n", tpg->tpgt, a->default_erl); |
| 851 | |
| 852 | return 0; |
| 853 | } |
Sagi Grimberg | 8085176 | 2014-02-19 17:50:20 +0200 | [diff] [blame] | 854 | |
| 855 | int iscsit_ta_t10_pi( |
| 856 | struct iscsi_portal_group *tpg, |
| 857 | u32 flag) |
| 858 | { |
| 859 | struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; |
| 860 | |
| 861 | if ((flag != 0) && (flag != 1)) { |
| 862 | pr_err("Illegal value %d\n", flag); |
| 863 | return -EINVAL; |
| 864 | } |
| 865 | |
| 866 | a->t10_pi = flag; |
| 867 | pr_debug("iSCSI_TPG[%hu] - T10 Protection information bit:" |
| 868 | " %s\n", tpg->tpgt, (a->t10_pi) ? |
| 869 | "ON" : "OFF"); |
| 870 | |
| 871 | return 0; |
| 872 | } |
Nicholas Bellinger | 901c04a | 2015-03-29 19:36:16 -0700 | [diff] [blame] | 873 | |
| 874 | int iscsit_ta_fabric_prot_type( |
| 875 | struct iscsi_portal_group *tpg, |
| 876 | u32 prot_type) |
| 877 | { |
| 878 | struct iscsi_tpg_attrib *a = &tpg->tpg_attrib; |
| 879 | |
| 880 | if ((prot_type != 0) && (prot_type != 1) && (prot_type != 3)) { |
| 881 | pr_err("Illegal value for fabric_prot_type: %u\n", prot_type); |
| 882 | return -EINVAL; |
| 883 | } |
| 884 | |
| 885 | a->fabric_prot_type = prot_type; |
| 886 | pr_debug("iSCSI_TPG[%hu] - T10 Fabric Protection Type: %u\n", |
| 887 | tpg->tpgt, prot_type); |
| 888 | |
| 889 | return 0; |
| 890 | } |