1 /******************************************************************************* 2 * This file contains the configfs implementation for iSCSI Target mode 3 * from the LIO-Target Project. 4 * 5 * \u00a9 Copyright 2007-2011 RisingTide Systems LLC. 6 * 7 * Licensed to the Linux Foundation under the General Public License (GPL) version 2. 8 * 9 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org> 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 ****************************************************************************/ 21 22 #include <linux/configfs.h> 23 #include <linux/export.h> 24 #include <linux/inet.h> 25 #include <target/target_core_base.h> 26 #include <target/target_core_fabric.h> 27 #include <target/target_core_fabric_configfs.h> 28 #include <target/target_core_configfs.h> 29 #include <target/configfs_macros.h> 30 31 #include "iscsi_target_core.h" 32 #include "iscsi_target_parameters.h" 33 #include "iscsi_target_device.h" 34 #include "iscsi_target_erl0.h" 35 #include "iscsi_target_nodeattrib.h" 36 #include "iscsi_target_tpg.h" 37 #include "iscsi_target_util.h" 38 #include "iscsi_target.h" 39 #include "iscsi_target_stat.h" 40 #include "iscsi_target_configfs.h" 41 42 struct target_fabric_configfs *lio_target_fabric_configfs; 43 44 struct lio_target_configfs_attribute { 45 struct configfs_attribute attr; 46 ssize_t (*show)(void *, char *); 47 ssize_t (*store)(void *, const char *, size_t); 48 }; 49 50 /* Start items for lio_target_portal_cit */ 51 52 static ssize_t lio_target_np_show_sctp( 53 struct se_tpg_np *se_tpg_np, 54 char *page) 55 { 56 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, 57 struct iscsi_tpg_np, se_tpg_np); 58 struct iscsi_tpg_np *tpg_np_sctp; 59 ssize_t rb; 60 61 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP); 62 if (tpg_np_sctp) 63 rb = sprintf(page, "1\n"); 64 else 65 rb = sprintf(page, "0\n"); 66 67 return rb; 68 } 69 70 static ssize_t lio_target_np_store_sctp( 71 struct se_tpg_np *se_tpg_np, 72 const char *page, 73 size_t count) 74 { 75 struct iscsi_np *np; 76 struct iscsi_portal_group *tpg; 77 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, 78 struct iscsi_tpg_np, se_tpg_np); 79 struct iscsi_tpg_np *tpg_np_sctp = NULL; 80 char *endptr; 81 u32 op; 82 int ret; 83 84 op = simple_strtoul(page, &endptr, 0); 85 if ((op != 1) && (op != 0)) { 86 pr_err("Illegal value for tpg_enable: %u\n", op); 87 return -EINVAL; 88 } 89 np = tpg_np->tpg_np; 90 if (!np) { 91 pr_err("Unable to locate struct iscsi_np from" 92 " struct iscsi_tpg_np\n"); 93 return -EINVAL; 94 } 95 96 tpg = tpg_np->tpg; 97 if (iscsit_get_tpg(tpg) < 0) 98 return -EINVAL; 99 100 if (op) { 101 /* 102 * Use existing np->np_sockaddr for SCTP network portal reference 103 */ 104 tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, 105 np->np_ip, tpg_np, ISCSI_SCTP_TCP); 106 if (!tpg_np_sctp || IS_ERR(tpg_np_sctp)) 107 goto out; 108 } else { 109 tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP); 110 if (!tpg_np_sctp) 111 goto out; 112 113 ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp); 114 if (ret < 0) 115 goto out; 116 } 117 118 iscsit_put_tpg(tpg); 119 return count; 120 out: 121 iscsit_put_tpg(tpg); 122 return -EINVAL; 123 } 124 125 TF_NP_BASE_ATTR(lio_target, sctp, S_IRUGO | S_IWUSR); 126 127 static struct configfs_attribute *lio_target_portal_attrs[] = { 128 &lio_target_np_sctp.attr, 129 NULL, 130 }; 131 132 /* Stop items for lio_target_portal_cit */ 133 134 /* Start items for lio_target_np_cit */ 135 136 #define MAX_PORTAL_LEN 256 137 138 struct se_tpg_np *lio_target_call_addnptotpg( 139 struct se_portal_group *se_tpg, 140 struct config_group *group, 141 const char *name) 142 { 143 struct iscsi_portal_group *tpg; 144 struct iscsi_tpg_np *tpg_np; 145 char *str, *str2, *ip_str, *port_str; 146 struct __kernel_sockaddr_storage sockaddr; 147 struct sockaddr_in *sock_in; 148 struct sockaddr_in6 *sock_in6; 149 unsigned long port; 150 int ret; 151 char buf[MAX_PORTAL_LEN + 1]; 152 153 if (strlen(name) > MAX_PORTAL_LEN) { 154 pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n", 155 (int)strlen(name), MAX_PORTAL_LEN); 156 return ERR_PTR(-EOVERFLOW); 157 } 158 memset(buf, 0, MAX_PORTAL_LEN + 1); 159 snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name); 160 161 memset(&sockaddr, 0, sizeof(struct __kernel_sockaddr_storage)); 162 163 str = strstr(buf, "["); 164 if (str) { 165 const char *end; 166 167 str2 = strstr(str, "]"); 168 if (!str2) { 169 pr_err("Unable to locate trailing \"]\"" 170 " in IPv6 iSCSI network portal address\n"); 171 return ERR_PTR(-EINVAL); 172 } 173 str++; /* Skip over leading "[" */ 174 *str2 = '\0'; /* Terminate the IPv6 address */ 175 str2++; /* Skip over the "]" */ 176 port_str = strstr(str2, ":"); 177 if (!port_str) { 178 pr_err("Unable to locate \":port\"" 179 " in IPv6 iSCSI network portal address\n"); 180 return ERR_PTR(-EINVAL); 181 } 182 *port_str = '\0'; /* Terminate string for IP */ 183 port_str++; /* Skip over ":" */ 184 185 ret = strict_strtoul(port_str, 0, &port); 186 if (ret < 0) { 187 pr_err("strict_strtoul() failed for port_str: %d\n", ret); 188 return ERR_PTR(ret); 189 } 190 sock_in6 = (struct sockaddr_in6 *)&sockaddr; 191 sock_in6->sin6_family = AF_INET6; 192 sock_in6->sin6_port = htons((unsigned short)port); 193 ret = in6_pton(str, IPV6_ADDRESS_SPACE, 194 (void *)&sock_in6->sin6_addr.in6_u, -1, &end); 195 if (ret <= 0) { 196 pr_err("in6_pton returned: %d\n", ret); 197 return ERR_PTR(-EINVAL); 198 } 199 } else { 200 str = ip_str = &buf[0]; 201 port_str = strstr(ip_str, ":"); 202 if (!port_str) { 203 pr_err("Unable to locate \":port\"" 204 " in IPv4 iSCSI network portal address\n"); 205 return ERR_PTR(-EINVAL); 206 } 207 *port_str = '\0'; /* Terminate string for IP */ 208 port_str++; /* Skip over ":" */ 209 210 ret = strict_strtoul(port_str, 0, &port); 211 if (ret < 0) { 212 pr_err("strict_strtoul() failed for port_str: %d\n", ret); 213 return ERR_PTR(ret); 214 } 215 sock_in = (struct sockaddr_in *)&sockaddr; 216 sock_in->sin_family = AF_INET; 217 sock_in->sin_port = htons((unsigned short)port); 218 sock_in->sin_addr.s_addr = in_aton(ip_str); 219 } 220 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); 221 ret = iscsit_get_tpg(tpg); 222 if (ret < 0) 223 return ERR_PTR(-EINVAL); 224 225 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu" 226 " PORTAL: %s\n", 227 config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), 228 tpg->tpgt, name); 229 /* 230 * Assume ISCSI_TCP by default. Other network portals for other 231 * iSCSI fabrics: 232 * 233 * Traditional iSCSI over SCTP (initial support) 234 * iSER/TCP (TODO, hardware available) 235 * iSER/SCTP (TODO, software emulation with osc-iwarp) 236 * iSER/IB (TODO, hardware available) 237 * 238 * can be enabled with atributes under 239 * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/ 240 * 241 */ 242 tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, str, NULL, 243 ISCSI_TCP); 244 if (IS_ERR(tpg_np)) { 245 iscsit_put_tpg(tpg); 246 return ERR_CAST(tpg_np); 247 } 248 pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n"); 249 250 iscsit_put_tpg(tpg); 251 return &tpg_np->se_tpg_np; 252 } 253 254 static void lio_target_call_delnpfromtpg( 255 struct se_tpg_np *se_tpg_np) 256 { 257 struct iscsi_portal_group *tpg; 258 struct iscsi_tpg_np *tpg_np; 259 struct se_portal_group *se_tpg; 260 int ret; 261 262 tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np); 263 tpg = tpg_np->tpg; 264 ret = iscsit_get_tpg(tpg); 265 if (ret < 0) 266 return; 267 268 se_tpg = &tpg->tpg_se_tpg; 269 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu" 270 " PORTAL: %s:%hu\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), 271 tpg->tpgt, tpg_np->tpg_np->np_ip, tpg_np->tpg_np->np_port); 272 273 ret = iscsit_tpg_del_network_portal(tpg, tpg_np); 274 if (ret < 0) 275 goto out; 276 277 pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n"); 278 out: 279 iscsit_put_tpg(tpg); 280 } 281 282 /* End items for lio_target_np_cit */ 283 284 /* Start items for lio_target_nacl_attrib_cit */ 285 286 #define DEF_NACL_ATTRIB(name) \ 287 static ssize_t iscsi_nacl_attrib_show_##name( \ 288 struct se_node_acl *se_nacl, \ 289 char *page) \ 290 { \ 291 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ 292 se_node_acl); \ 293 \ 294 return sprintf(page, "%u\n", ISCSI_NODE_ATTRIB(nacl)->name); \ 295 } \ 296 \ 297 static ssize_t iscsi_nacl_attrib_store_##name( \ 298 struct se_node_acl *se_nacl, \ 299 const char *page, \ 300 size_t count) \ 301 { \ 302 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ 303 se_node_acl); \ 304 char *endptr; \ 305 u32 val; \ 306 int ret; \ 307 \ 308 val = simple_strtoul(page, &endptr, 0); \ 309 ret = iscsit_na_##name(nacl, val); \ 310 if (ret < 0) \ 311 return ret; \ 312 \ 313 return count; \ 314 } 315 316 #define NACL_ATTR(_name, _mode) TF_NACL_ATTRIB_ATTR(iscsi, _name, _mode); 317 /* 318 * Define iscsi_node_attrib_s_dataout_timeout 319 */ 320 DEF_NACL_ATTRIB(dataout_timeout); 321 NACL_ATTR(dataout_timeout, S_IRUGO | S_IWUSR); 322 /* 323 * Define iscsi_node_attrib_s_dataout_timeout_retries 324 */ 325 DEF_NACL_ATTRIB(dataout_timeout_retries); 326 NACL_ATTR(dataout_timeout_retries, S_IRUGO | S_IWUSR); 327 /* 328 * Define iscsi_node_attrib_s_default_erl 329 */ 330 DEF_NACL_ATTRIB(default_erl); 331 NACL_ATTR(default_erl, S_IRUGO | S_IWUSR); 332 /* 333 * Define iscsi_node_attrib_s_nopin_timeout 334 */ 335 DEF_NACL_ATTRIB(nopin_timeout); 336 NACL_ATTR(nopin_timeout, S_IRUGO | S_IWUSR); 337 /* 338 * Define iscsi_node_attrib_s_nopin_response_timeout 339 */ 340 DEF_NACL_ATTRIB(nopin_response_timeout); 341 NACL_ATTR(nopin_response_timeout, S_IRUGO | S_IWUSR); 342 /* 343 * Define iscsi_node_attrib_s_random_datain_pdu_offsets 344 */ 345 DEF_NACL_ATTRIB(random_datain_pdu_offsets); 346 NACL_ATTR(random_datain_pdu_offsets, S_IRUGO | S_IWUSR); 347 /* 348 * Define iscsi_node_attrib_s_random_datain_seq_offsets 349 */ 350 DEF_NACL_ATTRIB(random_datain_seq_offsets); 351 NACL_ATTR(random_datain_seq_offsets, S_IRUGO | S_IWUSR); 352 /* 353 * Define iscsi_node_attrib_s_random_r2t_offsets 354 */ 355 DEF_NACL_ATTRIB(random_r2t_offsets); 356 NACL_ATTR(random_r2t_offsets, S_IRUGO | S_IWUSR); 357 358 static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = { 359 &iscsi_nacl_attrib_dataout_timeout.attr, 360 &iscsi_nacl_attrib_dataout_timeout_retries.attr, 361 &iscsi_nacl_attrib_default_erl.attr, 362 &iscsi_nacl_attrib_nopin_timeout.attr, 363 &iscsi_nacl_attrib_nopin_response_timeout.attr, 364 &iscsi_nacl_attrib_random_datain_pdu_offsets.attr, 365 &iscsi_nacl_attrib_random_datain_seq_offsets.attr, 366 &iscsi_nacl_attrib_random_r2t_offsets.attr, 367 NULL, 368 }; 369 370 /* End items for lio_target_nacl_attrib_cit */ 371 372 /* Start items for lio_target_nacl_auth_cit */ 373 374 #define __DEF_NACL_AUTH_STR(prefix, name, flags) \ 375 static ssize_t __iscsi_##prefix##_show_##name( \ 376 struct iscsi_node_acl *nacl, \ 377 char *page) \ 378 { \ 379 struct iscsi_node_auth *auth = &nacl->node_auth; \ 380 \ 381 if (!capable(CAP_SYS_ADMIN)) \ 382 return -EPERM; \ 383 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ 384 } \ 385 \ 386 static ssize_t __iscsi_##prefix##_store_##name( \ 387 struct iscsi_node_acl *nacl, \ 388 const char *page, \ 389 size_t count) \ 390 { \ 391 struct iscsi_node_auth *auth = &nacl->node_auth; \ 392 \ 393 if (!capable(CAP_SYS_ADMIN)) \ 394 return -EPERM; \ 395 \ 396 snprintf(auth->name, PAGE_SIZE, "%s", page); \ 397 if (!strncmp("NULL", auth->name, 4)) \ 398 auth->naf_flags &= ~flags; \ 399 else \ 400 auth->naf_flags |= flags; \ 401 \ 402 if ((auth->naf_flags & NAF_USERID_IN_SET) && \ 403 (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ 404 auth->authenticate_target = 1; \ 405 else \ 406 auth->authenticate_target = 0; \ 407 \ 408 return count; \ 409 } 410 411 #define __DEF_NACL_AUTH_INT(prefix, name) \ 412 static ssize_t __iscsi_##prefix##_show_##name( \ 413 struct iscsi_node_acl *nacl, \ 414 char *page) \ 415 { \ 416 struct iscsi_node_auth *auth = &nacl->node_auth; \ 417 \ 418 if (!capable(CAP_SYS_ADMIN)) \ 419 return -EPERM; \ 420 \ 421 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ 422 } 423 424 #define DEF_NACL_AUTH_STR(name, flags) \ 425 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \ 426 static ssize_t iscsi_nacl_auth_show_##name( \ 427 struct se_node_acl *nacl, \ 428 char *page) \ 429 { \ 430 return __iscsi_nacl_auth_show_##name(container_of(nacl, \ 431 struct iscsi_node_acl, se_node_acl), page); \ 432 } \ 433 static ssize_t iscsi_nacl_auth_store_##name( \ 434 struct se_node_acl *nacl, \ 435 const char *page, \ 436 size_t count) \ 437 { \ 438 return __iscsi_nacl_auth_store_##name(container_of(nacl, \ 439 struct iscsi_node_acl, se_node_acl), page, count); \ 440 } 441 442 #define DEF_NACL_AUTH_INT(name) \ 443 __DEF_NACL_AUTH_INT(nacl_auth, name) \ 444 static ssize_t iscsi_nacl_auth_show_##name( \ 445 struct se_node_acl *nacl, \ 446 char *page) \ 447 { \ 448 return __iscsi_nacl_auth_show_##name(container_of(nacl, \ 449 struct iscsi_node_acl, se_node_acl), page); \ 450 } 451 452 #define AUTH_ATTR(_name, _mode) TF_NACL_AUTH_ATTR(iscsi, _name, _mode); 453 #define AUTH_ATTR_RO(_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name); 454 455 /* 456 * One-way authentication userid 457 */ 458 DEF_NACL_AUTH_STR(userid, NAF_USERID_SET); 459 AUTH_ATTR(userid, S_IRUGO | S_IWUSR); 460 /* 461 * One-way authentication password 462 */ 463 DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET); 464 AUTH_ATTR(password, S_IRUGO | S_IWUSR); 465 /* 466 * Enforce mutual authentication 467 */ 468 DEF_NACL_AUTH_INT(authenticate_target); 469 AUTH_ATTR_RO(authenticate_target); 470 /* 471 * Mutual authentication userid 472 */ 473 DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); 474 AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR); 475 /* 476 * Mutual authentication password 477 */ 478 DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); 479 AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR); 480 481 static struct configfs_attribute *lio_target_nacl_auth_attrs[] = { 482 &iscsi_nacl_auth_userid.attr, 483 &iscsi_nacl_auth_password.attr, 484 &iscsi_nacl_auth_authenticate_target.attr, 485 &iscsi_nacl_auth_userid_mutual.attr, 486 &iscsi_nacl_auth_password_mutual.attr, 487 NULL, 488 }; 489 490 /* End items for lio_target_nacl_auth_cit */ 491 492 /* Start items for lio_target_nacl_param_cit */ 493 494 #define DEF_NACL_PARAM(name) \ 495 static ssize_t iscsi_nacl_param_show_##name( \ 496 struct se_node_acl *se_nacl, \ 497 char *page) \ 498 { \ 499 struct iscsi_session *sess; \ 500 struct se_session *se_sess; \ 501 ssize_t rb; \ 502 \ 503 spin_lock_bh(&se_nacl->nacl_sess_lock); \ 504 se_sess = se_nacl->nacl_sess; \ 505 if (!se_sess) { \ 506 rb = snprintf(page, PAGE_SIZE, \ 507 "No Active iSCSI Session\n"); \ 508 } else { \ 509 sess = se_sess->fabric_sess_ptr; \ 510 rb = snprintf(page, PAGE_SIZE, "%u\n", \ 511 (u32)sess->sess_ops->name); \ 512 } \ 513 spin_unlock_bh(&se_nacl->nacl_sess_lock); \ 514 \ 515 return rb; \ 516 } 517 518 #define NACL_PARAM_ATTR(_name) TF_NACL_PARAM_ATTR_RO(iscsi, _name); 519 520 DEF_NACL_PARAM(MaxConnections); 521 NACL_PARAM_ATTR(MaxConnections); 522 523 DEF_NACL_PARAM(InitialR2T); 524 NACL_PARAM_ATTR(InitialR2T); 525 526 DEF_NACL_PARAM(ImmediateData); 527 NACL_PARAM_ATTR(ImmediateData); 528 529 DEF_NACL_PARAM(MaxBurstLength); 530 NACL_PARAM_ATTR(MaxBurstLength); 531 532 DEF_NACL_PARAM(FirstBurstLength); 533 NACL_PARAM_ATTR(FirstBurstLength); 534 535 DEF_NACL_PARAM(DefaultTime2Wait); 536 NACL_PARAM_ATTR(DefaultTime2Wait); 537 538 DEF_NACL_PARAM(DefaultTime2Retain); 539 NACL_PARAM_ATTR(DefaultTime2Retain); 540 541 DEF_NACL_PARAM(MaxOutstandingR2T); 542 NACL_PARAM_ATTR(MaxOutstandingR2T); 543 544 DEF_NACL_PARAM(DataPDUInOrder); 545 NACL_PARAM_ATTR(DataPDUInOrder); 546 547 DEF_NACL_PARAM(DataSequenceInOrder); 548 NACL_PARAM_ATTR(DataSequenceInOrder); 549 550 DEF_NACL_PARAM(ErrorRecoveryLevel); 551 NACL_PARAM_ATTR(ErrorRecoveryLevel); 552 553 static struct configfs_attribute *lio_target_nacl_param_attrs[] = { 554 &iscsi_nacl_param_MaxConnections.attr, 555 &iscsi_nacl_param_InitialR2T.attr, 556 &iscsi_nacl_param_ImmediateData.attr, 557 &iscsi_nacl_param_MaxBurstLength.attr, 558 &iscsi_nacl_param_FirstBurstLength.attr, 559 &iscsi_nacl_param_DefaultTime2Wait.attr, 560 &iscsi_nacl_param_DefaultTime2Retain.attr, 561 &iscsi_nacl_param_MaxOutstandingR2T.attr, 562 &iscsi_nacl_param_DataPDUInOrder.attr, 563 &iscsi_nacl_param_DataSequenceInOrder.attr, 564 &iscsi_nacl_param_ErrorRecoveryLevel.attr, 565 NULL, 566 }; 567 568 /* End items for lio_target_nacl_param_cit */ 569 570 /* Start items for lio_target_acl_cit */ 571 572 static ssize_t lio_target_nacl_show_info( 573 struct se_node_acl *se_nacl, 574 char *page) 575 { 576 struct iscsi_session *sess; 577 struct iscsi_conn *conn; 578 struct se_session *se_sess; 579 ssize_t rb = 0; 580 581 spin_lock_bh(&se_nacl->nacl_sess_lock); 582 se_sess = se_nacl->nacl_sess; 583 if (!se_sess) { 584 rb += sprintf(page+rb, "No active iSCSI Session for Initiator" 585 " Endpoint: %s\n", se_nacl->initiatorname); 586 } else { 587 sess = se_sess->fabric_sess_ptr; 588 589 if (sess->sess_ops->InitiatorName) 590 rb += sprintf(page+rb, "InitiatorName: %s\n", 591 sess->sess_ops->InitiatorName); 592 if (sess->sess_ops->InitiatorAlias) 593 rb += sprintf(page+rb, "InitiatorAlias: %s\n", 594 sess->sess_ops->InitiatorAlias); 595 596 rb += sprintf(page+rb, "LIO Session ID: %u " 597 "ISID: 0x%02x %02x %02x %02x %02x %02x " 598 "TSIH: %hu ", sess->sid, 599 sess->isid[0], sess->isid[1], sess->isid[2], 600 sess->isid[3], sess->isid[4], sess->isid[5], 601 sess->tsih); 602 rb += sprintf(page+rb, "SessionType: %s\n", 603 (sess->sess_ops->SessionType) ? 604 "Discovery" : "Normal"); 605 rb += sprintf(page+rb, "Session State: "); 606 switch (sess->session_state) { 607 case TARG_SESS_STATE_FREE: 608 rb += sprintf(page+rb, "TARG_SESS_FREE\n"); 609 break; 610 case TARG_SESS_STATE_ACTIVE: 611 rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n"); 612 break; 613 case TARG_SESS_STATE_LOGGED_IN: 614 rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n"); 615 break; 616 case TARG_SESS_STATE_FAILED: 617 rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n"); 618 break; 619 case TARG_SESS_STATE_IN_CONTINUE: 620 rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n"); 621 break; 622 default: 623 rb += sprintf(page+rb, "ERROR: Unknown Session" 624 " State!\n"); 625 break; 626 } 627 628 rb += sprintf(page+rb, "---------------------[iSCSI Session" 629 " Values]-----------------------\n"); 630 rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN" 631 " : MaxCmdSN : ITT : TTT\n"); 632 rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x" 633 " 0x%08x 0x%08x\n", 634 sess->cmdsn_window, 635 (sess->max_cmd_sn - sess->exp_cmd_sn) + 1, 636 sess->exp_cmd_sn, sess->max_cmd_sn, 637 sess->init_task_tag, sess->targ_xfer_tag); 638 rb += sprintf(page+rb, "----------------------[iSCSI" 639 " Connections]-------------------------\n"); 640 641 spin_lock(&sess->conn_lock); 642 list_for_each_entry(conn, &sess->sess_conn_list, conn_list) { 643 rb += sprintf(page+rb, "CID: %hu Connection" 644 " State: ", conn->cid); 645 switch (conn->conn_state) { 646 case TARG_CONN_STATE_FREE: 647 rb += sprintf(page+rb, 648 "TARG_CONN_STATE_FREE\n"); 649 break; 650 case TARG_CONN_STATE_XPT_UP: 651 rb += sprintf(page+rb, 652 "TARG_CONN_STATE_XPT_UP\n"); 653 break; 654 case TARG_CONN_STATE_IN_LOGIN: 655 rb += sprintf(page+rb, 656 "TARG_CONN_STATE_IN_LOGIN\n"); 657 break; 658 case TARG_CONN_STATE_LOGGED_IN: 659 rb += sprintf(page+rb, 660 "TARG_CONN_STATE_LOGGED_IN\n"); 661 break; 662 case TARG_CONN_STATE_IN_LOGOUT: 663 rb += sprintf(page+rb, 664 "TARG_CONN_STATE_IN_LOGOUT\n"); 665 break; 666 case TARG_CONN_STATE_LOGOUT_REQUESTED: 667 rb += sprintf(page+rb, 668 "TARG_CONN_STATE_LOGOUT_REQUESTED\n"); 669 break; 670 case TARG_CONN_STATE_CLEANUP_WAIT: 671 rb += sprintf(page+rb, 672 "TARG_CONN_STATE_CLEANUP_WAIT\n"); 673 break; 674 default: 675 rb += sprintf(page+rb, 676 "ERROR: Unknown Connection State!\n"); 677 break; 678 } 679 680 rb += sprintf(page+rb, " Address %s %s", conn->login_ip, 681 (conn->network_transport == ISCSI_TCP) ? 682 "TCP" : "SCTP"); 683 rb += sprintf(page+rb, " StatSN: 0x%08x\n", 684 conn->stat_sn); 685 } 686 spin_unlock(&sess->conn_lock); 687 } 688 spin_unlock_bh(&se_nacl->nacl_sess_lock); 689 690 return rb; 691 } 692 693 TF_NACL_BASE_ATTR_RO(lio_target, info); 694 695 static ssize_t lio_target_nacl_show_cmdsn_depth( 696 struct se_node_acl *se_nacl, 697 char *page) 698 { 699 return sprintf(page, "%u\n", se_nacl->queue_depth); 700 } 701 702 static ssize_t lio_target_nacl_store_cmdsn_depth( 703 struct se_node_acl *se_nacl, 704 const char *page, 705 size_t count) 706 { 707 struct se_portal_group *se_tpg = se_nacl->se_tpg; 708 struct iscsi_portal_group *tpg = container_of(se_tpg, 709 struct iscsi_portal_group, tpg_se_tpg); 710 struct config_item *acl_ci, *tpg_ci, *wwn_ci; 711 char *endptr; 712 u32 cmdsn_depth = 0; 713 int ret; 714 715 cmdsn_depth = simple_strtoul(page, &endptr, 0); 716 if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) { 717 pr_err("Passed cmdsn_depth: %u exceeds" 718 " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth, 719 TA_DEFAULT_CMDSN_DEPTH_MAX); 720 return -EINVAL; 721 } 722 acl_ci = &se_nacl->acl_group.cg_item; 723 if (!acl_ci) { 724 pr_err("Unable to locatel acl_ci\n"); 725 return -EINVAL; 726 } 727 tpg_ci = &acl_ci->ci_parent->ci_group->cg_item; 728 if (!tpg_ci) { 729 pr_err("Unable to locate tpg_ci\n"); 730 return -EINVAL; 731 } 732 wwn_ci = &tpg_ci->ci_group->cg_item; 733 if (!wwn_ci) { 734 pr_err("Unable to locate config_item wwn_ci\n"); 735 return -EINVAL; 736 } 737 738 if (iscsit_get_tpg(tpg) < 0) 739 return -EINVAL; 740 /* 741 * iscsit_tpg_set_initiator_node_queue_depth() assumes force=1 742 */ 743 ret = iscsit_tpg_set_initiator_node_queue_depth(tpg, 744 config_item_name(acl_ci), cmdsn_depth, 1); 745 746 pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for" 747 "InitiatorName: %s\n", config_item_name(wwn_ci), 748 config_item_name(tpg_ci), cmdsn_depth, 749 config_item_name(acl_ci)); 750 751 iscsit_put_tpg(tpg); 752 return (!ret) ? count : (ssize_t)ret; 753 } 754 755 TF_NACL_BASE_ATTR(lio_target, cmdsn_depth, S_IRUGO | S_IWUSR); 756 757 static struct configfs_attribute *lio_target_initiator_attrs[] = { 758 &lio_target_nacl_info.attr, 759 &lio_target_nacl_cmdsn_depth.attr, 760 NULL, 761 }; 762 763 static struct se_node_acl *lio_tpg_alloc_fabric_acl( 764 struct se_portal_group *se_tpg) 765 { 766 struct iscsi_node_acl *acl; 767 768 acl = kzalloc(sizeof(struct iscsi_node_acl), GFP_KERNEL); 769 if (!acl) { 770 pr_err("Unable to allocate memory for struct iscsi_node_acl\n"); 771 return NULL; 772 } 773 774 return &acl->se_node_acl; 775 } 776 777 static struct se_node_acl *lio_target_make_nodeacl( 778 struct se_portal_group *se_tpg, 779 struct config_group *group, 780 const char *name) 781 { 782 struct config_group *stats_cg; 783 struct iscsi_node_acl *acl; 784 struct se_node_acl *se_nacl_new, *se_nacl; 785 struct iscsi_portal_group *tpg = container_of(se_tpg, 786 struct iscsi_portal_group, tpg_se_tpg); 787 u32 cmdsn_depth; 788 789 se_nacl_new = lio_tpg_alloc_fabric_acl(se_tpg); 790 if (!se_nacl_new) 791 return ERR_PTR(-ENOMEM); 792 793 cmdsn_depth = ISCSI_TPG_ATTRIB(tpg)->default_cmdsn_depth; 794 /* 795 * se_nacl_new may be released by core_tpg_add_initiator_node_acl() 796 * when converting a NdoeACL from demo mode -> explict 797 */ 798 se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new, 799 name, cmdsn_depth); 800 if (IS_ERR(se_nacl)) 801 return se_nacl; 802 803 acl = container_of(se_nacl, struct iscsi_node_acl, se_node_acl); 804 stats_cg = &se_nacl->acl_fabric_stat_group; 805 806 stats_cg->default_groups = kzalloc(sizeof(struct config_group) * 2, 807 GFP_KERNEL); 808 if (!stats_cg->default_groups) { 809 pr_err("Unable to allocate memory for" 810 " stats_cg->default_groups\n"); 811 core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1); 812 kfree(acl); 813 return ERR_PTR(-ENOMEM); 814 } 815 816 stats_cg->default_groups[0] = &NODE_STAT_GRPS(acl)->iscsi_sess_stats_group; 817 stats_cg->default_groups[1] = NULL; 818 config_group_init_type_name(&NODE_STAT_GRPS(acl)->iscsi_sess_stats_group, 819 "iscsi_sess_stats", &iscsi_stat_sess_cit); 820 821 return se_nacl; 822 } 823 824 static void lio_target_drop_nodeacl( 825 struct se_node_acl *se_nacl) 826 { 827 struct se_portal_group *se_tpg = se_nacl->se_tpg; 828 struct iscsi_node_acl *acl = container_of(se_nacl, 829 struct iscsi_node_acl, se_node_acl); 830 struct config_item *df_item; 831 struct config_group *stats_cg; 832 int i; 833 834 stats_cg = &acl->se_node_acl.acl_fabric_stat_group; 835 for (i = 0; stats_cg->default_groups[i]; i++) { 836 df_item = &stats_cg->default_groups[i]->cg_item; 837 stats_cg->default_groups[i] = NULL; 838 config_item_put(df_item); 839 } 840 kfree(stats_cg->default_groups); 841 842 core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1); 843 kfree(acl); 844 } 845 846 /* End items for lio_target_acl_cit */ 847 848 /* Start items for lio_target_tpg_attrib_cit */ 849 850 #define DEF_TPG_ATTRIB(name) \ 851 \ 852 static ssize_t iscsi_tpg_attrib_show_##name( \ 853 struct se_portal_group *se_tpg, \ 854 char *page) \ 855 { \ 856 struct iscsi_portal_group *tpg = container_of(se_tpg, \ 857 struct iscsi_portal_group, tpg_se_tpg); \ 858 ssize_t rb; \ 859 \ 860 if (iscsit_get_tpg(tpg) < 0) \ 861 return -EINVAL; \ 862 \ 863 rb = sprintf(page, "%u\n", ISCSI_TPG_ATTRIB(tpg)->name); \ 864 iscsit_put_tpg(tpg); \ 865 return rb; \ 866 } \ 867 \ 868 static ssize_t iscsi_tpg_attrib_store_##name( \ 869 struct se_portal_group *se_tpg, \ 870 const char *page, \ 871 size_t count) \ 872 { \ 873 struct iscsi_portal_group *tpg = container_of(se_tpg, \ 874 struct iscsi_portal_group, tpg_se_tpg); \ 875 char *endptr; \ 876 u32 val; \ 877 int ret; \ 878 \ 879 if (iscsit_get_tpg(tpg) < 0) \ 880 return -EINVAL; \ 881 \ 882 val = simple_strtoul(page, &endptr, 0); \ 883 ret = iscsit_ta_##name(tpg, val); \ 884 if (ret < 0) \ 885 goto out; \ 886 \ 887 iscsit_put_tpg(tpg); \ 888 return count; \ 889 out: \ 890 iscsit_put_tpg(tpg); \ 891 return ret; \ 892 } 893 894 #define TPG_ATTR(_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode); 895 896 /* 897 * Define iscsi_tpg_attrib_s_authentication 898 */ 899 DEF_TPG_ATTRIB(authentication); 900 TPG_ATTR(authentication, S_IRUGO | S_IWUSR); 901 /* 902 * Define iscsi_tpg_attrib_s_login_timeout 903 */ 904 DEF_TPG_ATTRIB(login_timeout); 905 TPG_ATTR(login_timeout, S_IRUGO | S_IWUSR); 906 /* 907 * Define iscsi_tpg_attrib_s_netif_timeout 908 */ 909 DEF_TPG_ATTRIB(netif_timeout); 910 TPG_ATTR(netif_timeout, S_IRUGO | S_IWUSR); 911 /* 912 * Define iscsi_tpg_attrib_s_generate_node_acls 913 */ 914 DEF_TPG_ATTRIB(generate_node_acls); 915 TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR); 916 /* 917 * Define iscsi_tpg_attrib_s_default_cmdsn_depth 918 */ 919 DEF_TPG_ATTRIB(default_cmdsn_depth); 920 TPG_ATTR(default_cmdsn_depth, S_IRUGO | S_IWUSR); 921 /* 922 Define iscsi_tpg_attrib_s_cache_dynamic_acls 923 */ 924 DEF_TPG_ATTRIB(cache_dynamic_acls); 925 TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR); 926 /* 927 * Define iscsi_tpg_attrib_s_demo_mode_write_protect 928 */ 929 DEF_TPG_ATTRIB(demo_mode_write_protect); 930 TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR); 931 /* 932 * Define iscsi_tpg_attrib_s_prod_mode_write_protect 933 */ 934 DEF_TPG_ATTRIB(prod_mode_write_protect); 935 TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR); 936 937 static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = { 938 &iscsi_tpg_attrib_authentication.attr, 939 &iscsi_tpg_attrib_login_timeout.attr, 940 &iscsi_tpg_attrib_netif_timeout.attr, 941 &iscsi_tpg_attrib_generate_node_acls.attr, 942 &iscsi_tpg_attrib_default_cmdsn_depth.attr, 943 &iscsi_tpg_attrib_cache_dynamic_acls.attr, 944 &iscsi_tpg_attrib_demo_mode_write_protect.attr, 945 &iscsi_tpg_attrib_prod_mode_write_protect.attr, 946 NULL, 947 }; 948 949 /* End items for lio_target_tpg_attrib_cit */ 950 951 /* Start items for lio_target_tpg_param_cit */ 952 953 #define DEF_TPG_PARAM(name) \ 954 static ssize_t iscsi_tpg_param_show_##name( \ 955 struct se_portal_group *se_tpg, \ 956 char *page) \ 957 { \ 958 struct iscsi_portal_group *tpg = container_of(se_tpg, \ 959 struct iscsi_portal_group, tpg_se_tpg); \ 960 struct iscsi_param *param; \ 961 ssize_t rb; \ 962 \ 963 if (iscsit_get_tpg(tpg) < 0) \ 964 return -EINVAL; \ 965 \ 966 param = iscsi_find_param_from_key(__stringify(name), \ 967 tpg->param_list); \ 968 if (!param) { \ 969 iscsit_put_tpg(tpg); \ 970 return -EINVAL; \ 971 } \ 972 rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \ 973 \ 974 iscsit_put_tpg(tpg); \ 975 return rb; \ 976 } \ 977 static ssize_t iscsi_tpg_param_store_##name( \ 978 struct se_portal_group *se_tpg, \ 979 const char *page, \ 980 size_t count) \ 981 { \ 982 struct iscsi_portal_group *tpg = container_of(se_tpg, \ 983 struct iscsi_portal_group, tpg_se_tpg); \ 984 char *buf; \ 985 int ret; \ 986 \ 987 buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \ 988 if (!buf) \ 989 return -ENOMEM; \ 990 snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \ 991 buf[strlen(buf)-1] = '\0'; /* Kill newline */ \ 992 \ 993 if (iscsit_get_tpg(tpg) < 0) { \ 994 kfree(buf); \ 995 return -EINVAL; \ 996 } \ 997 \ 998 ret = iscsi_change_param_value(buf, tpg->param_list, 1); \ 999 if (ret < 0) \ 1000 goto out; \ 1001 \ 1002 kfree(buf); \ 1003 iscsit_put_tpg(tpg); \ 1004 return count; \ 1005 out: \ 1006 kfree(buf); \ 1007 iscsit_put_tpg(tpg); \ 1008 return -EINVAL; \ 1009 } 1010 1011 #define TPG_PARAM_ATTR(_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode); 1012 1013 DEF_TPG_PARAM(AuthMethod); 1014 TPG_PARAM_ATTR(AuthMethod, S_IRUGO | S_IWUSR); 1015 1016 DEF_TPG_PARAM(HeaderDigest); 1017 TPG_PARAM_ATTR(HeaderDigest, S_IRUGO | S_IWUSR); 1018 1019 DEF_TPG_PARAM(DataDigest); 1020 TPG_PARAM_ATTR(DataDigest, S_IRUGO | S_IWUSR); 1021 1022 DEF_TPG_PARAM(MaxConnections); 1023 TPG_PARAM_ATTR(MaxConnections, S_IRUGO | S_IWUSR); 1024 1025 DEF_TPG_PARAM(TargetAlias); 1026 TPG_PARAM_ATTR(TargetAlias, S_IRUGO | S_IWUSR); 1027 1028 DEF_TPG_PARAM(InitialR2T); 1029 TPG_PARAM_ATTR(InitialR2T, S_IRUGO | S_IWUSR); 1030 1031 DEF_TPG_PARAM(ImmediateData); 1032 TPG_PARAM_ATTR(ImmediateData, S_IRUGO | S_IWUSR); 1033 1034 DEF_TPG_PARAM(MaxRecvDataSegmentLength); 1035 TPG_PARAM_ATTR(MaxRecvDataSegmentLength, S_IRUGO | S_IWUSR); 1036 1037 DEF_TPG_PARAM(MaxBurstLength); 1038 TPG_PARAM_ATTR(MaxBurstLength, S_IRUGO | S_IWUSR); 1039 1040 DEF_TPG_PARAM(FirstBurstLength); 1041 TPG_PARAM_ATTR(FirstBurstLength, S_IRUGO | S_IWUSR); 1042 1043 DEF_TPG_PARAM(DefaultTime2Wait); 1044 TPG_PARAM_ATTR(DefaultTime2Wait, S_IRUGO | S_IWUSR); 1045 1046 DEF_TPG_PARAM(DefaultTime2Retain); 1047 TPG_PARAM_ATTR(DefaultTime2Retain, S_IRUGO | S_IWUSR); 1048 1049 DEF_TPG_PARAM(MaxOutstandingR2T); 1050 TPG_PARAM_ATTR(MaxOutstandingR2T, S_IRUGO | S_IWUSR); 1051 1052 DEF_TPG_PARAM(DataPDUInOrder); 1053 TPG_PARAM_ATTR(DataPDUInOrder, S_IRUGO | S_IWUSR); 1054 1055 DEF_TPG_PARAM(DataSequenceInOrder); 1056 TPG_PARAM_ATTR(DataSequenceInOrder, S_IRUGO | S_IWUSR); 1057 1058 DEF_TPG_PARAM(ErrorRecoveryLevel); 1059 TPG_PARAM_ATTR(ErrorRecoveryLevel, S_IRUGO | S_IWUSR); 1060 1061 DEF_TPG_PARAM(IFMarker); 1062 TPG_PARAM_ATTR(IFMarker, S_IRUGO | S_IWUSR); 1063 1064 DEF_TPG_PARAM(OFMarker); 1065 TPG_PARAM_ATTR(OFMarker, S_IRUGO | S_IWUSR); 1066 1067 DEF_TPG_PARAM(IFMarkInt); 1068 TPG_PARAM_ATTR(IFMarkInt, S_IRUGO | S_IWUSR); 1069 1070 DEF_TPG_PARAM(OFMarkInt); 1071 TPG_PARAM_ATTR(OFMarkInt, S_IRUGO | S_IWUSR); 1072 1073 static struct configfs_attribute *lio_target_tpg_param_attrs[] = { 1074 &iscsi_tpg_param_AuthMethod.attr, 1075 &iscsi_tpg_param_HeaderDigest.attr, 1076 &iscsi_tpg_param_DataDigest.attr, 1077 &iscsi_tpg_param_MaxConnections.attr, 1078 &iscsi_tpg_param_TargetAlias.attr, 1079 &iscsi_tpg_param_InitialR2T.attr, 1080 &iscsi_tpg_param_ImmediateData.attr, 1081 &iscsi_tpg_param_MaxRecvDataSegmentLength.attr, 1082 &iscsi_tpg_param_MaxBurstLength.attr, 1083 &iscsi_tpg_param_FirstBurstLength.attr, 1084 &iscsi_tpg_param_DefaultTime2Wait.attr, 1085 &iscsi_tpg_param_DefaultTime2Retain.attr, 1086 &iscsi_tpg_param_MaxOutstandingR2T.attr, 1087 &iscsi_tpg_param_DataPDUInOrder.attr, 1088 &iscsi_tpg_param_DataSequenceInOrder.attr, 1089 &iscsi_tpg_param_ErrorRecoveryLevel.attr, 1090 &iscsi_tpg_param_IFMarker.attr, 1091 &iscsi_tpg_param_OFMarker.attr, 1092 &iscsi_tpg_param_IFMarkInt.attr, 1093 &iscsi_tpg_param_OFMarkInt.attr, 1094 NULL, 1095 }; 1096 1097 /* End items for lio_target_tpg_param_cit */ 1098 1099 /* Start items for lio_target_tpg_cit */ 1100 1101 static ssize_t lio_target_tpg_show_enable( 1102 struct se_portal_group *se_tpg, 1103 char *page) 1104 { 1105 struct iscsi_portal_group *tpg = container_of(se_tpg, 1106 struct iscsi_portal_group, tpg_se_tpg); 1107 ssize_t len; 1108 1109 spin_lock(&tpg->tpg_state_lock); 1110 len = sprintf(page, "%d\n", 1111 (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0); 1112 spin_unlock(&tpg->tpg_state_lock); 1113 1114 return len; 1115 } 1116 1117 static ssize_t lio_target_tpg_store_enable( 1118 struct se_portal_group *se_tpg, 1119 const char *page, 1120 size_t count) 1121 { 1122 struct iscsi_portal_group *tpg = container_of(se_tpg, 1123 struct iscsi_portal_group, tpg_se_tpg); 1124 char *endptr; 1125 u32 op; 1126 int ret = 0; 1127 1128 op = simple_strtoul(page, &endptr, 0); 1129 if ((op != 1) && (op != 0)) { 1130 pr_err("Illegal value for tpg_enable: %u\n", op); 1131 return -EINVAL; 1132 } 1133 1134 ret = iscsit_get_tpg(tpg); 1135 if (ret < 0) 1136 return -EINVAL; 1137 1138 if (op) { 1139 ret = iscsit_tpg_enable_portal_group(tpg); 1140 if (ret < 0) 1141 goto out; 1142 } else { 1143 /* 1144 * iscsit_tpg_disable_portal_group() assumes force=1 1145 */ 1146 ret = iscsit_tpg_disable_portal_group(tpg, 1); 1147 if (ret < 0) 1148 goto out; 1149 } 1150 1151 iscsit_put_tpg(tpg); 1152 return count; 1153 out: 1154 iscsit_put_tpg(tpg); 1155 return -EINVAL; 1156 } 1157 1158 TF_TPG_BASE_ATTR(lio_target, enable, S_IRUGO | S_IWUSR); 1159 1160 static struct configfs_attribute *lio_target_tpg_attrs[] = { 1161 &lio_target_tpg_enable.attr, 1162 NULL, 1163 }; 1164 1165 /* End items for lio_target_tpg_cit */ 1166 1167 /* Start items for lio_target_tiqn_cit */ 1168 1169 struct se_portal_group *lio_target_tiqn_addtpg( 1170 struct se_wwn *wwn, 1171 struct config_group *group, 1172 const char *name) 1173 { 1174 struct iscsi_portal_group *tpg; 1175 struct iscsi_tiqn *tiqn; 1176 char *tpgt_str, *end_ptr; 1177 int ret = 0; 1178 unsigned short int tpgt; 1179 1180 tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); 1181 /* 1182 * Only tpgt_# directory groups can be created below 1183 * target/iscsi/iqn.superturodiskarry/ 1184 */ 1185 tpgt_str = strstr(name, "tpgt_"); 1186 if (!tpgt_str) { 1187 pr_err("Unable to locate \"tpgt_#\" directory" 1188 " group\n"); 1189 return NULL; 1190 } 1191 tpgt_str += 5; /* Skip ahead of "tpgt_" */ 1192 tpgt = (unsigned short int) simple_strtoul(tpgt_str, &end_ptr, 0); 1193 1194 tpg = iscsit_alloc_portal_group(tiqn, tpgt); 1195 if (!tpg) 1196 return NULL; 1197 1198 ret = core_tpg_register( 1199 &lio_target_fabric_configfs->tf_ops, 1200 wwn, &tpg->tpg_se_tpg, tpg, 1201 TRANSPORT_TPG_TYPE_NORMAL); 1202 if (ret < 0) 1203 return NULL; 1204 1205 ret = iscsit_tpg_add_portal_group(tiqn, tpg); 1206 if (ret != 0) 1207 goto out; 1208 1209 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); 1210 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n", 1211 name); 1212 return &tpg->tpg_se_tpg; 1213 out: 1214 core_tpg_deregister(&tpg->tpg_se_tpg); 1215 kfree(tpg); 1216 return NULL; 1217 } 1218 1219 void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg) 1220 { 1221 struct iscsi_portal_group *tpg; 1222 struct iscsi_tiqn *tiqn; 1223 1224 tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); 1225 tiqn = tpg->tpg_tiqn; 1226 /* 1227 * iscsit_tpg_del_portal_group() assumes force=1 1228 */ 1229 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n"); 1230 iscsit_tpg_del_portal_group(tiqn, tpg, 1); 1231 } 1232 1233 /* End items for lio_target_tiqn_cit */ 1234 1235 /* Start LIO-Target TIQN struct contig_item lio_target_cit */ 1236 1237 static ssize_t lio_target_wwn_show_attr_lio_version( 1238 struct target_fabric_configfs *tf, 1239 char *page) 1240 { 1241 return sprintf(page, "RisingTide Systems Linux-iSCSI Target "ISCSIT_VERSION"\n"); 1242 } 1243 1244 TF_WWN_ATTR_RO(lio_target, lio_version); 1245 1246 static struct configfs_attribute *lio_target_wwn_attrs[] = { 1247 &lio_target_wwn_lio_version.attr, 1248 NULL, 1249 }; 1250 1251 struct se_wwn *lio_target_call_coreaddtiqn( 1252 struct target_fabric_configfs *tf, 1253 struct config_group *group, 1254 const char *name) 1255 { 1256 struct config_group *stats_cg; 1257 struct iscsi_tiqn *tiqn; 1258 1259 tiqn = iscsit_add_tiqn((unsigned char *)name); 1260 if (IS_ERR(tiqn)) 1261 return ERR_CAST(tiqn); 1262 /* 1263 * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group. 1264 */ 1265 stats_cg = &tiqn->tiqn_wwn.fabric_stat_group; 1266 1267 stats_cg->default_groups = kzalloc(sizeof(struct config_group) * 6, 1268 GFP_KERNEL); 1269 if (!stats_cg->default_groups) { 1270 pr_err("Unable to allocate memory for" 1271 " stats_cg->default_groups\n"); 1272 iscsit_del_tiqn(tiqn); 1273 return ERR_PTR(-ENOMEM); 1274 } 1275 1276 stats_cg->default_groups[0] = &WWN_STAT_GRPS(tiqn)->iscsi_instance_group; 1277 stats_cg->default_groups[1] = &WWN_STAT_GRPS(tiqn)->iscsi_sess_err_group; 1278 stats_cg->default_groups[2] = &WWN_STAT_GRPS(tiqn)->iscsi_tgt_attr_group; 1279 stats_cg->default_groups[3] = &WWN_STAT_GRPS(tiqn)->iscsi_login_stats_group; 1280 stats_cg->default_groups[4] = &WWN_STAT_GRPS(tiqn)->iscsi_logout_stats_group; 1281 stats_cg->default_groups[5] = NULL; 1282 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_instance_group, 1283 "iscsi_instance", &iscsi_stat_instance_cit); 1284 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_sess_err_group, 1285 "iscsi_sess_err", &iscsi_stat_sess_err_cit); 1286 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_tgt_attr_group, 1287 "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit); 1288 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_login_stats_group, 1289 "iscsi_login_stats", &iscsi_stat_login_cit); 1290 config_group_init_type_name(&WWN_STAT_GRPS(tiqn)->iscsi_logout_stats_group, 1291 "iscsi_logout_stats", &iscsi_stat_logout_cit); 1292 1293 pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); 1294 pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:" 1295 " %s\n", name); 1296 return &tiqn->tiqn_wwn; 1297 } 1298 1299 void lio_target_call_coredeltiqn( 1300 struct se_wwn *wwn) 1301 { 1302 struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); 1303 struct config_item *df_item; 1304 struct config_group *stats_cg; 1305 int i; 1306 1307 stats_cg = &tiqn->tiqn_wwn.fabric_stat_group; 1308 for (i = 0; stats_cg->default_groups[i]; i++) { 1309 df_item = &stats_cg->default_groups[i]->cg_item; 1310 stats_cg->default_groups[i] = NULL; 1311 config_item_put(df_item); 1312 } 1313 kfree(stats_cg->default_groups); 1314 1315 pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n", 1316 tiqn->tiqn); 1317 iscsit_del_tiqn(tiqn); 1318 } 1319 1320 /* End LIO-Target TIQN struct contig_lio_target_cit */ 1321 1322 /* Start lio_target_discovery_auth_cit */ 1323 1324 #define DEF_DISC_AUTH_STR(name, flags) \ 1325 __DEF_NACL_AUTH_STR(disc, name, flags) \ 1326 static ssize_t iscsi_disc_show_##name( \ 1327 struct target_fabric_configfs *tf, \ 1328 char *page) \ 1329 { \ 1330 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \ 1331 page); \ 1332 } \ 1333 static ssize_t iscsi_disc_store_##name( \ 1334 struct target_fabric_configfs *tf, \ 1335 const char *page, \ 1336 size_t count) \ 1337 { \ 1338 return __iscsi_disc_store_##name(&iscsit_global->discovery_acl, \ 1339 page, count); \ 1340 } 1341 1342 #define DEF_DISC_AUTH_INT(name) \ 1343 __DEF_NACL_AUTH_INT(disc, name) \ 1344 static ssize_t iscsi_disc_show_##name( \ 1345 struct target_fabric_configfs *tf, \ 1346 char *page) \ 1347 { \ 1348 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \ 1349 page); \ 1350 } 1351 1352 #define DISC_AUTH_ATTR(_name, _mode) TF_DISC_ATTR(iscsi, _name, _mode) 1353 #define DISC_AUTH_ATTR_RO(_name) TF_DISC_ATTR_RO(iscsi, _name) 1354 1355 /* 1356 * One-way authentication userid 1357 */ 1358 DEF_DISC_AUTH_STR(userid, NAF_USERID_SET); 1359 DISC_AUTH_ATTR(userid, S_IRUGO | S_IWUSR); 1360 /* 1361 * One-way authentication password 1362 */ 1363 DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET); 1364 DISC_AUTH_ATTR(password, S_IRUGO | S_IWUSR); 1365 /* 1366 * Enforce mutual authentication 1367 */ 1368 DEF_DISC_AUTH_INT(authenticate_target); 1369 DISC_AUTH_ATTR_RO(authenticate_target); 1370 /* 1371 * Mutual authentication userid 1372 */ 1373 DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); 1374 DISC_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR); 1375 /* 1376 * Mutual authentication password 1377 */ 1378 DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); 1379 DISC_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR); 1380 1381 /* 1382 * enforce_discovery_auth 1383 */ 1384 static ssize_t iscsi_disc_show_enforce_discovery_auth( 1385 struct target_fabric_configfs *tf, 1386 char *page) 1387 { 1388 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth; 1389 1390 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth); 1391 } 1392 1393 static ssize_t iscsi_disc_store_enforce_discovery_auth( 1394 struct target_fabric_configfs *tf, 1395 const char *page, 1396 size_t count) 1397 { 1398 struct iscsi_param *param; 1399 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg; 1400 char *endptr; 1401 u32 op; 1402 1403 op = simple_strtoul(page, &endptr, 0); 1404 if ((op != 1) && (op != 0)) { 1405 pr_err("Illegal value for enforce_discovery_auth:" 1406 " %u\n", op); 1407 return -EINVAL; 1408 } 1409 1410 if (!discovery_tpg) { 1411 pr_err("iscsit_global->discovery_tpg is NULL\n"); 1412 return -EINVAL; 1413 } 1414 1415 param = iscsi_find_param_from_key(AUTHMETHOD, 1416 discovery_tpg->param_list); 1417 if (!param) 1418 return -EINVAL; 1419 1420 if (op) { 1421 /* 1422 * Reset the AuthMethod key to CHAP. 1423 */ 1424 if (iscsi_update_param_value(param, CHAP) < 0) 1425 return -EINVAL; 1426 1427 discovery_tpg->tpg_attrib.authentication = 1; 1428 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1; 1429 pr_debug("LIO-CORE[0] Successfully enabled" 1430 " authentication enforcement for iSCSI" 1431 " Discovery TPG\n"); 1432 } else { 1433 /* 1434 * Reset the AuthMethod key to CHAP,None 1435 */ 1436 if (iscsi_update_param_value(param, "CHAP,None") < 0) 1437 return -EINVAL; 1438 1439 discovery_tpg->tpg_attrib.authentication = 0; 1440 iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0; 1441 pr_debug("LIO-CORE[0] Successfully disabled" 1442 " authentication enforcement for iSCSI" 1443 " Discovery TPG\n"); 1444 } 1445 1446 return count; 1447 } 1448 1449 DISC_AUTH_ATTR(enforce_discovery_auth, S_IRUGO | S_IWUSR); 1450 1451 static struct configfs_attribute *lio_target_discovery_auth_attrs[] = { 1452 &iscsi_disc_userid.attr, 1453 &iscsi_disc_password.attr, 1454 &iscsi_disc_authenticate_target.attr, 1455 &iscsi_disc_userid_mutual.attr, 1456 &iscsi_disc_password_mutual.attr, 1457 &iscsi_disc_enforce_discovery_auth.attr, 1458 NULL, 1459 }; 1460 1461 /* End lio_target_discovery_auth_cit */ 1462 1463 /* Start functions for target_core_fabric_ops */ 1464 1465 static char *iscsi_get_fabric_name(void) 1466 { 1467 return "iSCSI"; 1468 } 1469 1470 static u32 iscsi_get_task_tag(struct se_cmd *se_cmd) 1471 { 1472 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1473 1474 return cmd->init_task_tag; 1475 } 1476 1477 static int iscsi_get_cmd_state(struct se_cmd *se_cmd) 1478 { 1479 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1480 1481 return cmd->i_state; 1482 } 1483 1484 static u32 lio_sess_get_index(struct se_session *se_sess) 1485 { 1486 struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1487 1488 return sess->session_index; 1489 } 1490 1491 static u32 lio_sess_get_initiator_sid( 1492 struct se_session *se_sess, 1493 unsigned char *buf, 1494 u32 size) 1495 { 1496 struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1497 /* 1498 * iSCSI Initiator Session Identifier from RFC-3720. 1499 */ 1500 return snprintf(buf, size, "%02x%02x%02x%02x%02x%02x", 1501 sess->isid[0], sess->isid[1], sess->isid[2], 1502 sess->isid[3], sess->isid[4], sess->isid[5]); 1503 } 1504 1505 static int lio_queue_data_in(struct se_cmd *se_cmd) 1506 { 1507 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1508 1509 cmd->i_state = ISTATE_SEND_DATAIN; 1510 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state); 1511 return 0; 1512 } 1513 1514 static int lio_write_pending(struct se_cmd *se_cmd) 1515 { 1516 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1517 1518 if (!cmd->immediate_data && !cmd->unsolicited_data) 1519 return iscsit_build_r2ts_for_cmd(cmd, cmd->conn, false); 1520 1521 return 0; 1522 } 1523 1524 static int lio_write_pending_status(struct se_cmd *se_cmd) 1525 { 1526 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1527 int ret; 1528 1529 spin_lock_bh(&cmd->istate_lock); 1530 ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT); 1531 spin_unlock_bh(&cmd->istate_lock); 1532 1533 return ret; 1534 } 1535 1536 static int lio_queue_status(struct se_cmd *se_cmd) 1537 { 1538 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1539 1540 cmd->i_state = ISTATE_SEND_STATUS; 1541 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state); 1542 return 0; 1543 } 1544 1545 static u16 lio_set_fabric_sense_len(struct se_cmd *se_cmd, u32 sense_length) 1546 { 1547 unsigned char *buffer = se_cmd->sense_buffer; 1548 /* 1549 * From RFC-3720 10.4.7. Data Segment - Sense and Response Data Segment 1550 * 16-bit SenseLength. 1551 */ 1552 buffer[0] = ((sense_length >> 8) & 0xff); 1553 buffer[1] = (sense_length & 0xff); 1554 /* 1555 * Return two byte offset into allocated sense_buffer. 1556 */ 1557 return 2; 1558 } 1559 1560 static u16 lio_get_fabric_sense_len(void) 1561 { 1562 /* 1563 * Return two byte offset into allocated sense_buffer. 1564 */ 1565 return 2; 1566 } 1567 1568 static int lio_queue_tm_rsp(struct se_cmd *se_cmd) 1569 { 1570 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1571 1572 cmd->i_state = ISTATE_SEND_TASKMGTRSP; 1573 iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state); 1574 return 0; 1575 } 1576 1577 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg) 1578 { 1579 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1580 1581 return &tpg->tpg_tiqn->tiqn[0]; 1582 } 1583 1584 static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg) 1585 { 1586 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1587 1588 return tpg->tpgt; 1589 } 1590 1591 static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg) 1592 { 1593 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1594 1595 return ISCSI_TPG_ATTRIB(tpg)->default_cmdsn_depth; 1596 } 1597 1598 static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg) 1599 { 1600 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1601 1602 return ISCSI_TPG_ATTRIB(tpg)->generate_node_acls; 1603 } 1604 1605 static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg) 1606 { 1607 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1608 1609 return ISCSI_TPG_ATTRIB(tpg)->cache_dynamic_acls; 1610 } 1611 1612 static int lio_tpg_check_demo_mode_write_protect( 1613 struct se_portal_group *se_tpg) 1614 { 1615 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1616 1617 return ISCSI_TPG_ATTRIB(tpg)->demo_mode_write_protect; 1618 } 1619 1620 static int lio_tpg_check_prod_mode_write_protect( 1621 struct se_portal_group *se_tpg) 1622 { 1623 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1624 1625 return ISCSI_TPG_ATTRIB(tpg)->prod_mode_write_protect; 1626 } 1627 1628 static void lio_tpg_release_fabric_acl( 1629 struct se_portal_group *se_tpg, 1630 struct se_node_acl *se_acl) 1631 { 1632 struct iscsi_node_acl *acl = container_of(se_acl, 1633 struct iscsi_node_acl, se_node_acl); 1634 kfree(acl); 1635 } 1636 1637 /* 1638 * Called with spin_lock_bh(struct se_portal_group->session_lock) held.. 1639 * 1640 * Also, this function calls iscsit_inc_session_usage_count() on the 1641 * struct iscsi_session in question. 1642 */ 1643 static int lio_tpg_shutdown_session(struct se_session *se_sess) 1644 { 1645 struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1646 1647 spin_lock(&sess->conn_lock); 1648 if (atomic_read(&sess->session_fall_back_to_erl0) || 1649 atomic_read(&sess->session_logout) || 1650 (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) { 1651 spin_unlock(&sess->conn_lock); 1652 return 0; 1653 } 1654 atomic_set(&sess->session_reinstatement, 1); 1655 spin_unlock(&sess->conn_lock); 1656 1657 iscsit_stop_time2retain_timer(sess); 1658 iscsit_stop_session(sess, 1, 1); 1659 1660 return 1; 1661 } 1662 1663 /* 1664 * Calls iscsit_dec_session_usage_count() as inverse of 1665 * lio_tpg_shutdown_session() 1666 */ 1667 static void lio_tpg_close_session(struct se_session *se_sess) 1668 { 1669 struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1670 /* 1671 * If the iSCSI Session for the iSCSI Initiator Node exists, 1672 * forcefully shutdown the iSCSI NEXUS. 1673 */ 1674 iscsit_close_session(sess); 1675 } 1676 1677 static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg) 1678 { 1679 struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1680 1681 return tpg->tpg_tiqn->tiqn_index; 1682 } 1683 1684 static void lio_set_default_node_attributes(struct se_node_acl *se_acl) 1685 { 1686 struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl, 1687 se_node_acl); 1688 1689 ISCSI_NODE_ATTRIB(acl)->nacl = acl; 1690 iscsit_set_default_node_attribues(acl); 1691 } 1692 1693 static void lio_release_cmd(struct se_cmd *se_cmd) 1694 { 1695 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1696 1697 iscsit_release_cmd(cmd); 1698 } 1699 1700 /* End functions for target_core_fabric_ops */ 1701 1702 int iscsi_target_register_configfs(void) 1703 { 1704 struct target_fabric_configfs *fabric; 1705 int ret; 1706 1707 lio_target_fabric_configfs = NULL; 1708 fabric = target_fabric_configfs_init(THIS_MODULE, "iscsi"); 1709 if (IS_ERR(fabric)) { 1710 pr_err("target_fabric_configfs_init() for" 1711 " LIO-Target failed!\n"); 1712 return PTR_ERR(fabric); 1713 } 1714 /* 1715 * Setup the fabric API of function pointers used by target_core_mod.. 1716 */ 1717 fabric->tf_ops.get_fabric_name = &iscsi_get_fabric_name; 1718 fabric->tf_ops.get_fabric_proto_ident = &iscsi_get_fabric_proto_ident; 1719 fabric->tf_ops.tpg_get_wwn = &lio_tpg_get_endpoint_wwn; 1720 fabric->tf_ops.tpg_get_tag = &lio_tpg_get_tag; 1721 fabric->tf_ops.tpg_get_default_depth = &lio_tpg_get_default_depth; 1722 fabric->tf_ops.tpg_get_pr_transport_id = &iscsi_get_pr_transport_id; 1723 fabric->tf_ops.tpg_get_pr_transport_id_len = 1724 &iscsi_get_pr_transport_id_len; 1725 fabric->tf_ops.tpg_parse_pr_out_transport_id = 1726 &iscsi_parse_pr_out_transport_id; 1727 fabric->tf_ops.tpg_check_demo_mode = &lio_tpg_check_demo_mode; 1728 fabric->tf_ops.tpg_check_demo_mode_cache = 1729 &lio_tpg_check_demo_mode_cache; 1730 fabric->tf_ops.tpg_check_demo_mode_write_protect = 1731 &lio_tpg_check_demo_mode_write_protect; 1732 fabric->tf_ops.tpg_check_prod_mode_write_protect = 1733 &lio_tpg_check_prod_mode_write_protect; 1734 fabric->tf_ops.tpg_alloc_fabric_acl = &lio_tpg_alloc_fabric_acl; 1735 fabric->tf_ops.tpg_release_fabric_acl = &lio_tpg_release_fabric_acl; 1736 fabric->tf_ops.tpg_get_inst_index = &lio_tpg_get_inst_index; 1737 fabric->tf_ops.release_cmd = &lio_release_cmd; 1738 fabric->tf_ops.shutdown_session = &lio_tpg_shutdown_session; 1739 fabric->tf_ops.close_session = &lio_tpg_close_session; 1740 fabric->tf_ops.sess_get_index = &lio_sess_get_index; 1741 fabric->tf_ops.sess_get_initiator_sid = &lio_sess_get_initiator_sid; 1742 fabric->tf_ops.write_pending = &lio_write_pending; 1743 fabric->tf_ops.write_pending_status = &lio_write_pending_status; 1744 fabric->tf_ops.set_default_node_attributes = 1745 &lio_set_default_node_attributes; 1746 fabric->tf_ops.get_task_tag = &iscsi_get_task_tag; 1747 fabric->tf_ops.get_cmd_state = &iscsi_get_cmd_state; 1748 fabric->tf_ops.queue_data_in = &lio_queue_data_in; 1749 fabric->tf_ops.queue_status = &lio_queue_status; 1750 fabric->tf_ops.queue_tm_rsp = &lio_queue_tm_rsp; 1751 fabric->tf_ops.set_fabric_sense_len = &lio_set_fabric_sense_len; 1752 fabric->tf_ops.get_fabric_sense_len = &lio_get_fabric_sense_len; 1753 /* 1754 * Setup function pointers for generic logic in target_core_fabric_configfs.c 1755 */ 1756 fabric->tf_ops.fabric_make_wwn = &lio_target_call_coreaddtiqn; 1757 fabric->tf_ops.fabric_drop_wwn = &lio_target_call_coredeltiqn; 1758 fabric->tf_ops.fabric_make_tpg = &lio_target_tiqn_addtpg; 1759 fabric->tf_ops.fabric_drop_tpg = &lio_target_tiqn_deltpg; 1760 fabric->tf_ops.fabric_post_link = NULL; 1761 fabric->tf_ops.fabric_pre_unlink = NULL; 1762 fabric->tf_ops.fabric_make_np = &lio_target_call_addnptotpg; 1763 fabric->tf_ops.fabric_drop_np = &lio_target_call_delnpfromtpg; 1764 fabric->tf_ops.fabric_make_nodeacl = &lio_target_make_nodeacl; 1765 fabric->tf_ops.fabric_drop_nodeacl = &lio_target_drop_nodeacl; 1766 /* 1767 * Setup default attribute lists for various fabric->tf_cit_tmpl 1768 * sturct config_item_type's 1769 */ 1770 TF_CIT_TMPL(fabric)->tfc_discovery_cit.ct_attrs = lio_target_discovery_auth_attrs; 1771 TF_CIT_TMPL(fabric)->tfc_wwn_cit.ct_attrs = lio_target_wwn_attrs; 1772 TF_CIT_TMPL(fabric)->tfc_tpg_base_cit.ct_attrs = lio_target_tpg_attrs; 1773 TF_CIT_TMPL(fabric)->tfc_tpg_attrib_cit.ct_attrs = lio_target_tpg_attrib_attrs; 1774 TF_CIT_TMPL(fabric)->tfc_tpg_param_cit.ct_attrs = lio_target_tpg_param_attrs; 1775 TF_CIT_TMPL(fabric)->tfc_tpg_np_base_cit.ct_attrs = lio_target_portal_attrs; 1776 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_base_cit.ct_attrs = lio_target_initiator_attrs; 1777 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_attrib_cit.ct_attrs = lio_target_nacl_attrib_attrs; 1778 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_auth_cit.ct_attrs = lio_target_nacl_auth_attrs; 1779 TF_CIT_TMPL(fabric)->tfc_tpg_nacl_param_cit.ct_attrs = lio_target_nacl_param_attrs; 1780 1781 ret = target_fabric_configfs_register(fabric); 1782 if (ret < 0) { 1783 pr_err("target_fabric_configfs_register() for" 1784 " LIO-Target failed!\n"); 1785 target_fabric_configfs_free(fabric); 1786 return ret; 1787 } 1788 1789 lio_target_fabric_configfs = fabric; 1790 pr_debug("LIO_TARGET[0] - Set fabric ->" 1791 " lio_target_fabric_configfs\n"); 1792 return 0; 1793 } 1794 1795 1796 void iscsi_target_deregister_configfs(void) 1797 { 1798 if (!lio_target_fabric_configfs) 1799 return; 1800 /* 1801 * Shutdown discovery sessions and disable discovery TPG 1802 */ 1803 if (iscsit_global->discovery_tpg) 1804 iscsit_tpg_disable_portal_group(iscsit_global->discovery_tpg, 1); 1805 1806 target_fabric_configfs_deregister(lio_target_fabric_configfs); 1807 lio_target_fabric_configfs = NULL; 1808 pr_debug("LIO_TARGET[0] - Cleared" 1809 " lio_target_fabric_configfs\n"); 1810 } 1811