1e48354ceSNicholas Bellinger /******************************************************************************* 2e48354ceSNicholas Bellinger * This file contains the configfs implementation for iSCSI Target mode 3e48354ceSNicholas Bellinger * from the LIO-Target Project. 4e48354ceSNicholas Bellinger * 54c76251eSNicholas Bellinger * (c) Copyright 2007-2013 Datera, Inc. 6e48354ceSNicholas Bellinger * 7e48354ceSNicholas Bellinger * Author: Nicholas A. Bellinger <nab@linux-iscsi.org> 8e48354ceSNicholas Bellinger * 9e48354ceSNicholas Bellinger * This program is free software; you can redistribute it and/or modify 10e48354ceSNicholas Bellinger * it under the terms of the GNU General Public License as published by 11e48354ceSNicholas Bellinger * the Free Software Foundation; either version 2 of the License, or 12e48354ceSNicholas Bellinger * (at your option) any later version. 13e48354ceSNicholas Bellinger * 14e48354ceSNicholas Bellinger * This program is distributed in the hope that it will be useful, 15e48354ceSNicholas Bellinger * but WITHOUT ANY WARRANTY; without even the implied warranty of 16e48354ceSNicholas Bellinger * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17e48354ceSNicholas Bellinger * GNU General Public License for more details. 18e48354ceSNicholas Bellinger ****************************************************************************/ 19e48354ceSNicholas Bellinger 20e48354ceSNicholas Bellinger #include <linux/configfs.h> 21ad7babd2SJörn Engel #include <linux/ctype.h> 22c53181afSPaul Gortmaker #include <linux/export.h> 23c3bc93daSStephen Rothwell #include <linux/inet.h> 24e48354ceSNicholas Bellinger #include <target/target_core_base.h> 25c4795fb2SChristoph Hellwig #include <target/target_core_fabric.h> 26e48354ceSNicholas Bellinger #include <target/target_core_fabric_configfs.h> 27e48354ceSNicholas Bellinger #include <target/target_core_configfs.h> 28e48354ceSNicholas Bellinger #include <target/configfs_macros.h> 292ec5a8c1SNicholas Bellinger #include <target/iscsi/iscsi_transport.h> 30e48354ceSNicholas Bellinger 3167f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_core.h> 32e48354ceSNicholas Bellinger #include "iscsi_target_parameters.h" 33e48354ceSNicholas Bellinger #include "iscsi_target_device.h" 34e48354ceSNicholas Bellinger #include "iscsi_target_erl0.h" 35e48354ceSNicholas Bellinger #include "iscsi_target_nodeattrib.h" 36e48354ceSNicholas Bellinger #include "iscsi_target_tpg.h" 37e48354ceSNicholas Bellinger #include "iscsi_target_util.h" 38e48354ceSNicholas Bellinger #include "iscsi_target.h" 3967f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_stat.h> 40e48354ceSNicholas Bellinger #include "iscsi_target_configfs.h" 41e48354ceSNicholas Bellinger 42e48354ceSNicholas Bellinger struct target_fabric_configfs *lio_target_fabric_configfs; 43e48354ceSNicholas Bellinger 44e48354ceSNicholas Bellinger struct lio_target_configfs_attribute { 45e48354ceSNicholas Bellinger struct configfs_attribute attr; 46e48354ceSNicholas Bellinger ssize_t (*show)(void *, char *); 47e48354ceSNicholas Bellinger ssize_t (*store)(void *, const char *, size_t); 48e48354ceSNicholas Bellinger }; 49e48354ceSNicholas Bellinger 50e48354ceSNicholas Bellinger /* Start items for lio_target_portal_cit */ 51e48354ceSNicholas Bellinger 52e48354ceSNicholas Bellinger static ssize_t lio_target_np_show_sctp( 53e48354ceSNicholas Bellinger struct se_tpg_np *se_tpg_np, 54e48354ceSNicholas Bellinger char *page) 55e48354ceSNicholas Bellinger { 56e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, 57e48354ceSNicholas Bellinger struct iscsi_tpg_np, se_tpg_np); 58e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np_sctp; 59e48354ceSNicholas Bellinger ssize_t rb; 60e48354ceSNicholas Bellinger 61e48354ceSNicholas Bellinger tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP); 62e48354ceSNicholas Bellinger if (tpg_np_sctp) 63e48354ceSNicholas Bellinger rb = sprintf(page, "1\n"); 64e48354ceSNicholas Bellinger else 65e48354ceSNicholas Bellinger rb = sprintf(page, "0\n"); 66e48354ceSNicholas Bellinger 67e48354ceSNicholas Bellinger return rb; 68e48354ceSNicholas Bellinger } 69e48354ceSNicholas Bellinger 70e48354ceSNicholas Bellinger static ssize_t lio_target_np_store_sctp( 71e48354ceSNicholas Bellinger struct se_tpg_np *se_tpg_np, 72e48354ceSNicholas Bellinger const char *page, 73e48354ceSNicholas Bellinger size_t count) 74e48354ceSNicholas Bellinger { 75e48354ceSNicholas Bellinger struct iscsi_np *np; 76e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 77e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, 78e48354ceSNicholas Bellinger struct iscsi_tpg_np, se_tpg_np); 79e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np_sctp = NULL; 80e48354ceSNicholas Bellinger u32 op; 81e48354ceSNicholas Bellinger int ret; 82e48354ceSNicholas Bellinger 83ad7babd2SJörn Engel ret = kstrtou32(page, 0, &op); 84ad7babd2SJörn Engel if (ret) 85ad7babd2SJörn Engel return ret; 86e48354ceSNicholas Bellinger if ((op != 1) && (op != 0)) { 87e48354ceSNicholas Bellinger pr_err("Illegal value for tpg_enable: %u\n", op); 88e48354ceSNicholas Bellinger return -EINVAL; 89e48354ceSNicholas Bellinger } 90e48354ceSNicholas Bellinger np = tpg_np->tpg_np; 91e48354ceSNicholas Bellinger if (!np) { 92e48354ceSNicholas Bellinger pr_err("Unable to locate struct iscsi_np from" 93e48354ceSNicholas Bellinger " struct iscsi_tpg_np\n"); 94e48354ceSNicholas Bellinger return -EINVAL; 95e48354ceSNicholas Bellinger } 96e48354ceSNicholas Bellinger 97e48354ceSNicholas Bellinger tpg = tpg_np->tpg; 98e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) 99e48354ceSNicholas Bellinger return -EINVAL; 100e48354ceSNicholas Bellinger 101e48354ceSNicholas Bellinger if (op) { 102e48354ceSNicholas Bellinger /* 103e48354ceSNicholas Bellinger * Use existing np->np_sockaddr for SCTP network portal reference 104e48354ceSNicholas Bellinger */ 105e48354ceSNicholas Bellinger tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, 106e48354ceSNicholas Bellinger np->np_ip, tpg_np, ISCSI_SCTP_TCP); 107e48354ceSNicholas Bellinger if (!tpg_np_sctp || IS_ERR(tpg_np_sctp)) 108e48354ceSNicholas Bellinger goto out; 109e48354ceSNicholas Bellinger } else { 110e48354ceSNicholas Bellinger tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP); 111e48354ceSNicholas Bellinger if (!tpg_np_sctp) 112e48354ceSNicholas Bellinger goto out; 113e48354ceSNicholas Bellinger 114e48354ceSNicholas Bellinger ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp); 115e48354ceSNicholas Bellinger if (ret < 0) 116e48354ceSNicholas Bellinger goto out; 117e48354ceSNicholas Bellinger } 118e48354ceSNicholas Bellinger 119e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 120e48354ceSNicholas Bellinger return count; 121e48354ceSNicholas Bellinger out: 122e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 123e48354ceSNicholas Bellinger return -EINVAL; 124e48354ceSNicholas Bellinger } 125e48354ceSNicholas Bellinger 126e48354ceSNicholas Bellinger TF_NP_BASE_ATTR(lio_target, sctp, S_IRUGO | S_IWUSR); 127e48354ceSNicholas Bellinger 12872438cddSNicholas Bellinger static ssize_t lio_target_np_show_iser( 12972438cddSNicholas Bellinger struct se_tpg_np *se_tpg_np, 13072438cddSNicholas Bellinger char *page) 13172438cddSNicholas Bellinger { 13272438cddSNicholas Bellinger struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, 13372438cddSNicholas Bellinger struct iscsi_tpg_np, se_tpg_np); 13472438cddSNicholas Bellinger struct iscsi_tpg_np *tpg_np_iser; 13572438cddSNicholas Bellinger ssize_t rb; 13672438cddSNicholas Bellinger 13772438cddSNicholas Bellinger tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND); 13872438cddSNicholas Bellinger if (tpg_np_iser) 13972438cddSNicholas Bellinger rb = sprintf(page, "1\n"); 14072438cddSNicholas Bellinger else 14172438cddSNicholas Bellinger rb = sprintf(page, "0\n"); 14272438cddSNicholas Bellinger 14372438cddSNicholas Bellinger return rb; 14472438cddSNicholas Bellinger } 14572438cddSNicholas Bellinger 14672438cddSNicholas Bellinger static ssize_t lio_target_np_store_iser( 14772438cddSNicholas Bellinger struct se_tpg_np *se_tpg_np, 14872438cddSNicholas Bellinger const char *page, 14972438cddSNicholas Bellinger size_t count) 15072438cddSNicholas Bellinger { 15172438cddSNicholas Bellinger struct iscsi_np *np; 15272438cddSNicholas Bellinger struct iscsi_portal_group *tpg; 15372438cddSNicholas Bellinger struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, 15472438cddSNicholas Bellinger struct iscsi_tpg_np, se_tpg_np); 15572438cddSNicholas Bellinger struct iscsi_tpg_np *tpg_np_iser = NULL; 15672438cddSNicholas Bellinger char *endptr; 15772438cddSNicholas Bellinger u32 op; 15858bd0c69SAndy Grover int rc = 0; 15972438cddSNicholas Bellinger 16072438cddSNicholas Bellinger op = simple_strtoul(page, &endptr, 0); 16172438cddSNicholas Bellinger if ((op != 1) && (op != 0)) { 16272438cddSNicholas Bellinger pr_err("Illegal value for tpg_enable: %u\n", op); 16372438cddSNicholas Bellinger return -EINVAL; 16472438cddSNicholas Bellinger } 16572438cddSNicholas Bellinger np = tpg_np->tpg_np; 16672438cddSNicholas Bellinger if (!np) { 16772438cddSNicholas Bellinger pr_err("Unable to locate struct iscsi_np from" 16872438cddSNicholas Bellinger " struct iscsi_tpg_np\n"); 16972438cddSNicholas Bellinger return -EINVAL; 17072438cddSNicholas Bellinger } 17172438cddSNicholas Bellinger 17272438cddSNicholas Bellinger tpg = tpg_np->tpg; 17372438cddSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) 17472438cddSNicholas Bellinger return -EINVAL; 17572438cddSNicholas Bellinger 17672438cddSNicholas Bellinger if (op) { 17758bd0c69SAndy Grover rc = request_module("ib_isert"); 17858bd0c69SAndy Grover if (rc != 0) { 17972438cddSNicholas Bellinger pr_warn("Unable to request_module for ib_isert\n"); 18058bd0c69SAndy Grover rc = 0; 18158bd0c69SAndy Grover } 18272438cddSNicholas Bellinger 18372438cddSNicholas Bellinger tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, 18472438cddSNicholas Bellinger np->np_ip, tpg_np, ISCSI_INFINIBAND); 18558bd0c69SAndy Grover if (IS_ERR(tpg_np_iser)) { 18658bd0c69SAndy Grover rc = PTR_ERR(tpg_np_iser); 18772438cddSNicholas Bellinger goto out; 18858bd0c69SAndy Grover } 18972438cddSNicholas Bellinger } else { 19072438cddSNicholas Bellinger tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND); 19158bd0c69SAndy Grover if (tpg_np_iser) { 19272438cddSNicholas Bellinger rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser); 19372438cddSNicholas Bellinger if (rc < 0) 19472438cddSNicholas Bellinger goto out; 19572438cddSNicholas Bellinger } 19658bd0c69SAndy Grover } 19772438cddSNicholas Bellinger 19872438cddSNicholas Bellinger iscsit_put_tpg(tpg); 19972438cddSNicholas Bellinger return count; 20072438cddSNicholas Bellinger out: 20172438cddSNicholas Bellinger iscsit_put_tpg(tpg); 20258bd0c69SAndy Grover return rc; 20372438cddSNicholas Bellinger } 20472438cddSNicholas Bellinger 20572438cddSNicholas Bellinger TF_NP_BASE_ATTR(lio_target, iser, S_IRUGO | S_IWUSR); 20672438cddSNicholas Bellinger 207e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_portal_attrs[] = { 208e48354ceSNicholas Bellinger &lio_target_np_sctp.attr, 20972438cddSNicholas Bellinger &lio_target_np_iser.attr, 210e48354ceSNicholas Bellinger NULL, 211e48354ceSNicholas Bellinger }; 212e48354ceSNicholas Bellinger 213e48354ceSNicholas Bellinger /* Stop items for lio_target_portal_cit */ 214e48354ceSNicholas Bellinger 215e48354ceSNicholas Bellinger /* Start items for lio_target_np_cit */ 216e48354ceSNicholas Bellinger 217e48354ceSNicholas Bellinger #define MAX_PORTAL_LEN 256 218e48354ceSNicholas Bellinger 219fceb5bc7SChristoph Hellwig static struct se_tpg_np *lio_target_call_addnptotpg( 220e48354ceSNicholas Bellinger struct se_portal_group *se_tpg, 221e48354ceSNicholas Bellinger struct config_group *group, 222e48354ceSNicholas Bellinger const char *name) 223e48354ceSNicholas Bellinger { 224e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 225e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np; 226e48354ceSNicholas Bellinger char *str, *str2, *ip_str, *port_str; 227e48354ceSNicholas Bellinger struct __kernel_sockaddr_storage sockaddr; 228e48354ceSNicholas Bellinger struct sockaddr_in *sock_in; 229e48354ceSNicholas Bellinger struct sockaddr_in6 *sock_in6; 230e48354ceSNicholas Bellinger unsigned long port; 231e48354ceSNicholas Bellinger int ret; 232e48354ceSNicholas Bellinger char buf[MAX_PORTAL_LEN + 1]; 233e48354ceSNicholas Bellinger 234e48354ceSNicholas Bellinger if (strlen(name) > MAX_PORTAL_LEN) { 235e48354ceSNicholas Bellinger pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n", 236e48354ceSNicholas Bellinger (int)strlen(name), MAX_PORTAL_LEN); 237e48354ceSNicholas Bellinger return ERR_PTR(-EOVERFLOW); 238e48354ceSNicholas Bellinger } 239e48354ceSNicholas Bellinger memset(buf, 0, MAX_PORTAL_LEN + 1); 2407bbb654eSNicholas Bellinger snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name); 241e48354ceSNicholas Bellinger 242e48354ceSNicholas Bellinger memset(&sockaddr, 0, sizeof(struct __kernel_sockaddr_storage)); 243e48354ceSNicholas Bellinger 244e48354ceSNicholas Bellinger str = strstr(buf, "["); 245e48354ceSNicholas Bellinger if (str) { 246e48354ceSNicholas Bellinger const char *end; 247e48354ceSNicholas Bellinger 248e48354ceSNicholas Bellinger str2 = strstr(str, "]"); 249e48354ceSNicholas Bellinger if (!str2) { 250e48354ceSNicholas Bellinger pr_err("Unable to locate trailing \"]\"" 251e48354ceSNicholas Bellinger " in IPv6 iSCSI network portal address\n"); 252e48354ceSNicholas Bellinger return ERR_PTR(-EINVAL); 253e48354ceSNicholas Bellinger } 254e48354ceSNicholas Bellinger str++; /* Skip over leading "[" */ 255e48354ceSNicholas Bellinger *str2 = '\0'; /* Terminate the IPv6 address */ 256e48354ceSNicholas Bellinger str2++; /* Skip over the "]" */ 257e48354ceSNicholas Bellinger port_str = strstr(str2, ":"); 258e48354ceSNicholas Bellinger if (!port_str) { 259e48354ceSNicholas Bellinger pr_err("Unable to locate \":port\"" 260e48354ceSNicholas Bellinger " in IPv6 iSCSI network portal address\n"); 261e48354ceSNicholas Bellinger return ERR_PTR(-EINVAL); 262e48354ceSNicholas Bellinger } 263e48354ceSNicholas Bellinger *port_str = '\0'; /* Terminate string for IP */ 264e48354ceSNicholas Bellinger port_str++; /* Skip over ":" */ 265e48354ceSNicholas Bellinger 26657103d7fSJingoo Han ret = kstrtoul(port_str, 0, &port); 267e48354ceSNicholas Bellinger if (ret < 0) { 26857103d7fSJingoo Han pr_err("kstrtoul() failed for port_str: %d\n", ret); 269e48354ceSNicholas Bellinger return ERR_PTR(ret); 270e48354ceSNicholas Bellinger } 271e48354ceSNicholas Bellinger sock_in6 = (struct sockaddr_in6 *)&sockaddr; 272e48354ceSNicholas Bellinger sock_in6->sin6_family = AF_INET6; 273e48354ceSNicholas Bellinger sock_in6->sin6_port = htons((unsigned short)port); 274e48354ceSNicholas Bellinger ret = in6_pton(str, IPV6_ADDRESS_SPACE, 275e48354ceSNicholas Bellinger (void *)&sock_in6->sin6_addr.in6_u, -1, &end); 276e48354ceSNicholas Bellinger if (ret <= 0) { 277e48354ceSNicholas Bellinger pr_err("in6_pton returned: %d\n", ret); 278e48354ceSNicholas Bellinger return ERR_PTR(-EINVAL); 279e48354ceSNicholas Bellinger } 280e48354ceSNicholas Bellinger } else { 281e48354ceSNicholas Bellinger str = ip_str = &buf[0]; 282e48354ceSNicholas Bellinger port_str = strstr(ip_str, ":"); 283e48354ceSNicholas Bellinger if (!port_str) { 284e48354ceSNicholas Bellinger pr_err("Unable to locate \":port\"" 285e48354ceSNicholas Bellinger " in IPv4 iSCSI network portal address\n"); 286e48354ceSNicholas Bellinger return ERR_PTR(-EINVAL); 287e48354ceSNicholas Bellinger } 288e48354ceSNicholas Bellinger *port_str = '\0'; /* Terminate string for IP */ 289e48354ceSNicholas Bellinger port_str++; /* Skip over ":" */ 290e48354ceSNicholas Bellinger 29157103d7fSJingoo Han ret = kstrtoul(port_str, 0, &port); 292e48354ceSNicholas Bellinger if (ret < 0) { 29357103d7fSJingoo Han pr_err("kstrtoul() failed for port_str: %d\n", ret); 294e48354ceSNicholas Bellinger return ERR_PTR(ret); 295e48354ceSNicholas Bellinger } 296e48354ceSNicholas Bellinger sock_in = (struct sockaddr_in *)&sockaddr; 297e48354ceSNicholas Bellinger sock_in->sin_family = AF_INET; 298e48354ceSNicholas Bellinger sock_in->sin_port = htons((unsigned short)port); 299e48354ceSNicholas Bellinger sock_in->sin_addr.s_addr = in_aton(ip_str); 300e48354ceSNicholas Bellinger } 301e48354ceSNicholas Bellinger tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); 302e48354ceSNicholas Bellinger ret = iscsit_get_tpg(tpg); 303e48354ceSNicholas Bellinger if (ret < 0) 304e48354ceSNicholas Bellinger return ERR_PTR(-EINVAL); 305e48354ceSNicholas Bellinger 306e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu" 307e48354ceSNicholas Bellinger " PORTAL: %s\n", 308e48354ceSNicholas Bellinger config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), 309e48354ceSNicholas Bellinger tpg->tpgt, name); 310e48354ceSNicholas Bellinger /* 311e48354ceSNicholas Bellinger * Assume ISCSI_TCP by default. Other network portals for other 312e48354ceSNicholas Bellinger * iSCSI fabrics: 313e48354ceSNicholas Bellinger * 314e48354ceSNicholas Bellinger * Traditional iSCSI over SCTP (initial support) 315e48354ceSNicholas Bellinger * iSER/TCP (TODO, hardware available) 316e48354ceSNicholas Bellinger * iSER/SCTP (TODO, software emulation with osc-iwarp) 317e48354ceSNicholas Bellinger * iSER/IB (TODO, hardware available) 318e48354ceSNicholas Bellinger * 31920879696SMasanari Iida * can be enabled with attributes under 320e48354ceSNicholas Bellinger * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/ 321e48354ceSNicholas Bellinger * 322e48354ceSNicholas Bellinger */ 323e48354ceSNicholas Bellinger tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, str, NULL, 324e48354ceSNicholas Bellinger ISCSI_TCP); 325e48354ceSNicholas Bellinger if (IS_ERR(tpg_np)) { 326e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 327e1750ba2SThomas Meyer return ERR_CAST(tpg_np); 328e48354ceSNicholas Bellinger } 329e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n"); 330e48354ceSNicholas Bellinger 331e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 332e48354ceSNicholas Bellinger return &tpg_np->se_tpg_np; 333e48354ceSNicholas Bellinger } 334e48354ceSNicholas Bellinger 335e48354ceSNicholas Bellinger static void lio_target_call_delnpfromtpg( 336e48354ceSNicholas Bellinger struct se_tpg_np *se_tpg_np) 337e48354ceSNicholas Bellinger { 338e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 339e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np; 340e48354ceSNicholas Bellinger struct se_portal_group *se_tpg; 341e48354ceSNicholas Bellinger int ret; 342e48354ceSNicholas Bellinger 343e48354ceSNicholas Bellinger tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np); 344e48354ceSNicholas Bellinger tpg = tpg_np->tpg; 345e48354ceSNicholas Bellinger ret = iscsit_get_tpg(tpg); 346e48354ceSNicholas Bellinger if (ret < 0) 347e48354ceSNicholas Bellinger return; 348e48354ceSNicholas Bellinger 349e48354ceSNicholas Bellinger se_tpg = &tpg->tpg_se_tpg; 350e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu" 351e48354ceSNicholas Bellinger " PORTAL: %s:%hu\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), 352e48354ceSNicholas Bellinger tpg->tpgt, tpg_np->tpg_np->np_ip, tpg_np->tpg_np->np_port); 353e48354ceSNicholas Bellinger 354e48354ceSNicholas Bellinger ret = iscsit_tpg_del_network_portal(tpg, tpg_np); 355e48354ceSNicholas Bellinger if (ret < 0) 356e48354ceSNicholas Bellinger goto out; 357e48354ceSNicholas Bellinger 358e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n"); 359e48354ceSNicholas Bellinger out: 360e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 361e48354ceSNicholas Bellinger } 362e48354ceSNicholas Bellinger 363e48354ceSNicholas Bellinger /* End items for lio_target_np_cit */ 364e48354ceSNicholas Bellinger 365e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_attrib_cit */ 366e48354ceSNicholas Bellinger 367e48354ceSNicholas Bellinger #define DEF_NACL_ATTRIB(name) \ 368e48354ceSNicholas Bellinger static ssize_t iscsi_nacl_attrib_show_##name( \ 369e48354ceSNicholas Bellinger struct se_node_acl *se_nacl, \ 370e48354ceSNicholas Bellinger char *page) \ 371e48354ceSNicholas Bellinger { \ 372e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ 373e48354ceSNicholas Bellinger se_node_acl); \ 374e48354ceSNicholas Bellinger \ 375b7eec2cdSAndy Grover return sprintf(page, "%u\n", nacl->node_attrib.name); \ 376e48354ceSNicholas Bellinger } \ 377e48354ceSNicholas Bellinger \ 378e48354ceSNicholas Bellinger static ssize_t iscsi_nacl_attrib_store_##name( \ 379e48354ceSNicholas Bellinger struct se_node_acl *se_nacl, \ 380e48354ceSNicholas Bellinger const char *page, \ 381e48354ceSNicholas Bellinger size_t count) \ 382e48354ceSNicholas Bellinger { \ 383e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ 384e48354ceSNicholas Bellinger se_node_acl); \ 385e48354ceSNicholas Bellinger u32 val; \ 386e48354ceSNicholas Bellinger int ret; \ 387e48354ceSNicholas Bellinger \ 388ad7babd2SJörn Engel ret = kstrtou32(page, 0, &val); \ 389ad7babd2SJörn Engel if (ret) \ 390ad7babd2SJörn Engel return ret; \ 391e48354ceSNicholas Bellinger ret = iscsit_na_##name(nacl, val); \ 392e48354ceSNicholas Bellinger if (ret < 0) \ 393e48354ceSNicholas Bellinger return ret; \ 394e48354ceSNicholas Bellinger \ 395e48354ceSNicholas Bellinger return count; \ 396e48354ceSNicholas Bellinger } 397e48354ceSNicholas Bellinger 398e48354ceSNicholas Bellinger #define NACL_ATTR(_name, _mode) TF_NACL_ATTRIB_ATTR(iscsi, _name, _mode); 399e48354ceSNicholas Bellinger /* 400e48354ceSNicholas Bellinger * Define iscsi_node_attrib_s_dataout_timeout 401e48354ceSNicholas Bellinger */ 402e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(dataout_timeout); 403e48354ceSNicholas Bellinger NACL_ATTR(dataout_timeout, S_IRUGO | S_IWUSR); 404e48354ceSNicholas Bellinger /* 405e48354ceSNicholas Bellinger * Define iscsi_node_attrib_s_dataout_timeout_retries 406e48354ceSNicholas Bellinger */ 407e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(dataout_timeout_retries); 408e48354ceSNicholas Bellinger NACL_ATTR(dataout_timeout_retries, S_IRUGO | S_IWUSR); 409e48354ceSNicholas Bellinger /* 410e48354ceSNicholas Bellinger * Define iscsi_node_attrib_s_default_erl 411e48354ceSNicholas Bellinger */ 412e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(default_erl); 413e48354ceSNicholas Bellinger NACL_ATTR(default_erl, S_IRUGO | S_IWUSR); 414e48354ceSNicholas Bellinger /* 415e48354ceSNicholas Bellinger * Define iscsi_node_attrib_s_nopin_timeout 416e48354ceSNicholas Bellinger */ 417e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(nopin_timeout); 418e48354ceSNicholas Bellinger NACL_ATTR(nopin_timeout, S_IRUGO | S_IWUSR); 419e48354ceSNicholas Bellinger /* 420e48354ceSNicholas Bellinger * Define iscsi_node_attrib_s_nopin_response_timeout 421e48354ceSNicholas Bellinger */ 422e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(nopin_response_timeout); 423e48354ceSNicholas Bellinger NACL_ATTR(nopin_response_timeout, S_IRUGO | S_IWUSR); 424e48354ceSNicholas Bellinger /* 425e48354ceSNicholas Bellinger * Define iscsi_node_attrib_s_random_datain_pdu_offsets 426e48354ceSNicholas Bellinger */ 427e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(random_datain_pdu_offsets); 428e48354ceSNicholas Bellinger NACL_ATTR(random_datain_pdu_offsets, S_IRUGO | S_IWUSR); 429e48354ceSNicholas Bellinger /* 430e48354ceSNicholas Bellinger * Define iscsi_node_attrib_s_random_datain_seq_offsets 431e48354ceSNicholas Bellinger */ 432e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(random_datain_seq_offsets); 433e48354ceSNicholas Bellinger NACL_ATTR(random_datain_seq_offsets, S_IRUGO | S_IWUSR); 434e48354ceSNicholas Bellinger /* 435e48354ceSNicholas Bellinger * Define iscsi_node_attrib_s_random_r2t_offsets 436e48354ceSNicholas Bellinger */ 437e48354ceSNicholas Bellinger DEF_NACL_ATTRIB(random_r2t_offsets); 438e48354ceSNicholas Bellinger NACL_ATTR(random_r2t_offsets, S_IRUGO | S_IWUSR); 439e48354ceSNicholas Bellinger 440e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = { 441e48354ceSNicholas Bellinger &iscsi_nacl_attrib_dataout_timeout.attr, 442e48354ceSNicholas Bellinger &iscsi_nacl_attrib_dataout_timeout_retries.attr, 443e48354ceSNicholas Bellinger &iscsi_nacl_attrib_default_erl.attr, 444e48354ceSNicholas Bellinger &iscsi_nacl_attrib_nopin_timeout.attr, 445e48354ceSNicholas Bellinger &iscsi_nacl_attrib_nopin_response_timeout.attr, 446e48354ceSNicholas Bellinger &iscsi_nacl_attrib_random_datain_pdu_offsets.attr, 447e48354ceSNicholas Bellinger &iscsi_nacl_attrib_random_datain_seq_offsets.attr, 448e48354ceSNicholas Bellinger &iscsi_nacl_attrib_random_r2t_offsets.attr, 449e48354ceSNicholas Bellinger NULL, 450e48354ceSNicholas Bellinger }; 451e48354ceSNicholas Bellinger 452e48354ceSNicholas Bellinger /* End items for lio_target_nacl_attrib_cit */ 453e48354ceSNicholas Bellinger 454e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_auth_cit */ 455e48354ceSNicholas Bellinger 456e48354ceSNicholas Bellinger #define __DEF_NACL_AUTH_STR(prefix, name, flags) \ 457e48354ceSNicholas Bellinger static ssize_t __iscsi_##prefix##_show_##name( \ 458e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl, \ 459e48354ceSNicholas Bellinger char *page) \ 460e48354ceSNicholas Bellinger { \ 461e48354ceSNicholas Bellinger struct iscsi_node_auth *auth = &nacl->node_auth; \ 462e48354ceSNicholas Bellinger \ 463e48354ceSNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 464e48354ceSNicholas Bellinger return -EPERM; \ 465e48354ceSNicholas Bellinger return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ 466e48354ceSNicholas Bellinger } \ 467e48354ceSNicholas Bellinger \ 468e48354ceSNicholas Bellinger static ssize_t __iscsi_##prefix##_store_##name( \ 469e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl, \ 470e48354ceSNicholas Bellinger const char *page, \ 471e48354ceSNicholas Bellinger size_t count) \ 472e48354ceSNicholas Bellinger { \ 473e48354ceSNicholas Bellinger struct iscsi_node_auth *auth = &nacl->node_auth; \ 474e48354ceSNicholas Bellinger \ 475e48354ceSNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 476e48354ceSNicholas Bellinger return -EPERM; \ 4772306bfb2SEric Seppanen if (count >= sizeof(auth->name)) \ 4782306bfb2SEric Seppanen return -EINVAL; \ 4790fbfc46fSJörn Engel snprintf(auth->name, sizeof(auth->name), "%s", page); \ 480e48354ceSNicholas Bellinger if (!strncmp("NULL", auth->name, 4)) \ 481e48354ceSNicholas Bellinger auth->naf_flags &= ~flags; \ 482e48354ceSNicholas Bellinger else \ 483e48354ceSNicholas Bellinger auth->naf_flags |= flags; \ 484e48354ceSNicholas Bellinger \ 485e48354ceSNicholas Bellinger if ((auth->naf_flags & NAF_USERID_IN_SET) && \ 486e48354ceSNicholas Bellinger (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ 487e48354ceSNicholas Bellinger auth->authenticate_target = 1; \ 488e48354ceSNicholas Bellinger else \ 489e48354ceSNicholas Bellinger auth->authenticate_target = 0; \ 490e48354ceSNicholas Bellinger \ 491e48354ceSNicholas Bellinger return count; \ 492e48354ceSNicholas Bellinger } 493e48354ceSNicholas Bellinger 494e48354ceSNicholas Bellinger #define __DEF_NACL_AUTH_INT(prefix, name) \ 495e48354ceSNicholas Bellinger static ssize_t __iscsi_##prefix##_show_##name( \ 496e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl, \ 497e48354ceSNicholas Bellinger char *page) \ 498e48354ceSNicholas Bellinger { \ 499e48354ceSNicholas Bellinger struct iscsi_node_auth *auth = &nacl->node_auth; \ 500e48354ceSNicholas Bellinger \ 501e48354ceSNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 502e48354ceSNicholas Bellinger return -EPERM; \ 503e48354ceSNicholas Bellinger \ 504e48354ceSNicholas Bellinger return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ 505e48354ceSNicholas Bellinger } 506e48354ceSNicholas Bellinger 507e48354ceSNicholas Bellinger #define DEF_NACL_AUTH_STR(name, flags) \ 508e48354ceSNicholas Bellinger __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \ 509e48354ceSNicholas Bellinger static ssize_t iscsi_nacl_auth_show_##name( \ 510e48354ceSNicholas Bellinger struct se_node_acl *nacl, \ 511e48354ceSNicholas Bellinger char *page) \ 512e48354ceSNicholas Bellinger { \ 513e48354ceSNicholas Bellinger return __iscsi_nacl_auth_show_##name(container_of(nacl, \ 514e48354ceSNicholas Bellinger struct iscsi_node_acl, se_node_acl), page); \ 515e48354ceSNicholas Bellinger } \ 516e48354ceSNicholas Bellinger static ssize_t iscsi_nacl_auth_store_##name( \ 517e48354ceSNicholas Bellinger struct se_node_acl *nacl, \ 518e48354ceSNicholas Bellinger const char *page, \ 519e48354ceSNicholas Bellinger size_t count) \ 520e48354ceSNicholas Bellinger { \ 521e48354ceSNicholas Bellinger return __iscsi_nacl_auth_store_##name(container_of(nacl, \ 522e48354ceSNicholas Bellinger struct iscsi_node_acl, se_node_acl), page, count); \ 523e48354ceSNicholas Bellinger } 524e48354ceSNicholas Bellinger 525e48354ceSNicholas Bellinger #define DEF_NACL_AUTH_INT(name) \ 526e48354ceSNicholas Bellinger __DEF_NACL_AUTH_INT(nacl_auth, name) \ 527e48354ceSNicholas Bellinger static ssize_t iscsi_nacl_auth_show_##name( \ 528e48354ceSNicholas Bellinger struct se_node_acl *nacl, \ 529e48354ceSNicholas Bellinger char *page) \ 530e48354ceSNicholas Bellinger { \ 531e48354ceSNicholas Bellinger return __iscsi_nacl_auth_show_##name(container_of(nacl, \ 532e48354ceSNicholas Bellinger struct iscsi_node_acl, se_node_acl), page); \ 533e48354ceSNicholas Bellinger } 534e48354ceSNicholas Bellinger 535e48354ceSNicholas Bellinger #define AUTH_ATTR(_name, _mode) TF_NACL_AUTH_ATTR(iscsi, _name, _mode); 536e48354ceSNicholas Bellinger #define AUTH_ATTR_RO(_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name); 537e48354ceSNicholas Bellinger 538e48354ceSNicholas Bellinger /* 539e48354ceSNicholas Bellinger * One-way authentication userid 540e48354ceSNicholas Bellinger */ 541e48354ceSNicholas Bellinger DEF_NACL_AUTH_STR(userid, NAF_USERID_SET); 542e48354ceSNicholas Bellinger AUTH_ATTR(userid, S_IRUGO | S_IWUSR); 543e48354ceSNicholas Bellinger /* 544e48354ceSNicholas Bellinger * One-way authentication password 545e48354ceSNicholas Bellinger */ 546e48354ceSNicholas Bellinger DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET); 547e48354ceSNicholas Bellinger AUTH_ATTR(password, S_IRUGO | S_IWUSR); 548e48354ceSNicholas Bellinger /* 549e48354ceSNicholas Bellinger * Enforce mutual authentication 550e48354ceSNicholas Bellinger */ 551e48354ceSNicholas Bellinger DEF_NACL_AUTH_INT(authenticate_target); 552e48354ceSNicholas Bellinger AUTH_ATTR_RO(authenticate_target); 553e48354ceSNicholas Bellinger /* 554e48354ceSNicholas Bellinger * Mutual authentication userid 555e48354ceSNicholas Bellinger */ 556e48354ceSNicholas Bellinger DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); 557e48354ceSNicholas Bellinger AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR); 558e48354ceSNicholas Bellinger /* 559e48354ceSNicholas Bellinger * Mutual authentication password 560e48354ceSNicholas Bellinger */ 561e48354ceSNicholas Bellinger DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); 562e48354ceSNicholas Bellinger AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR); 563e48354ceSNicholas Bellinger 564e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_auth_attrs[] = { 565e48354ceSNicholas Bellinger &iscsi_nacl_auth_userid.attr, 566e48354ceSNicholas Bellinger &iscsi_nacl_auth_password.attr, 567e48354ceSNicholas Bellinger &iscsi_nacl_auth_authenticate_target.attr, 568e48354ceSNicholas Bellinger &iscsi_nacl_auth_userid_mutual.attr, 569e48354ceSNicholas Bellinger &iscsi_nacl_auth_password_mutual.attr, 570e48354ceSNicholas Bellinger NULL, 571e48354ceSNicholas Bellinger }; 572e48354ceSNicholas Bellinger 573e48354ceSNicholas Bellinger /* End items for lio_target_nacl_auth_cit */ 574e48354ceSNicholas Bellinger 575e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_param_cit */ 576e48354ceSNicholas Bellinger 577e48354ceSNicholas Bellinger #define DEF_NACL_PARAM(name) \ 578e48354ceSNicholas Bellinger static ssize_t iscsi_nacl_param_show_##name( \ 579e48354ceSNicholas Bellinger struct se_node_acl *se_nacl, \ 580e48354ceSNicholas Bellinger char *page) \ 581e48354ceSNicholas Bellinger { \ 582e48354ceSNicholas Bellinger struct iscsi_session *sess; \ 583e48354ceSNicholas Bellinger struct se_session *se_sess; \ 584e48354ceSNicholas Bellinger ssize_t rb; \ 585e48354ceSNicholas Bellinger \ 586e48354ceSNicholas Bellinger spin_lock_bh(&se_nacl->nacl_sess_lock); \ 587e48354ceSNicholas Bellinger se_sess = se_nacl->nacl_sess; \ 588e48354ceSNicholas Bellinger if (!se_sess) { \ 589e48354ceSNicholas Bellinger rb = snprintf(page, PAGE_SIZE, \ 590e48354ceSNicholas Bellinger "No Active iSCSI Session\n"); \ 591e48354ceSNicholas Bellinger } else { \ 592e48354ceSNicholas Bellinger sess = se_sess->fabric_sess_ptr; \ 593e48354ceSNicholas Bellinger rb = snprintf(page, PAGE_SIZE, "%u\n", \ 594e48354ceSNicholas Bellinger (u32)sess->sess_ops->name); \ 595e48354ceSNicholas Bellinger } \ 596e48354ceSNicholas Bellinger spin_unlock_bh(&se_nacl->nacl_sess_lock); \ 597e48354ceSNicholas Bellinger \ 598e48354ceSNicholas Bellinger return rb; \ 599e48354ceSNicholas Bellinger } 600e48354ceSNicholas Bellinger 601e48354ceSNicholas Bellinger #define NACL_PARAM_ATTR(_name) TF_NACL_PARAM_ATTR_RO(iscsi, _name); 602e48354ceSNicholas Bellinger 603e48354ceSNicholas Bellinger DEF_NACL_PARAM(MaxConnections); 604e48354ceSNicholas Bellinger NACL_PARAM_ATTR(MaxConnections); 605e48354ceSNicholas Bellinger 606e48354ceSNicholas Bellinger DEF_NACL_PARAM(InitialR2T); 607e48354ceSNicholas Bellinger NACL_PARAM_ATTR(InitialR2T); 608e48354ceSNicholas Bellinger 609e48354ceSNicholas Bellinger DEF_NACL_PARAM(ImmediateData); 610e48354ceSNicholas Bellinger NACL_PARAM_ATTR(ImmediateData); 611e48354ceSNicholas Bellinger 612e48354ceSNicholas Bellinger DEF_NACL_PARAM(MaxBurstLength); 613e48354ceSNicholas Bellinger NACL_PARAM_ATTR(MaxBurstLength); 614e48354ceSNicholas Bellinger 615e48354ceSNicholas Bellinger DEF_NACL_PARAM(FirstBurstLength); 616e48354ceSNicholas Bellinger NACL_PARAM_ATTR(FirstBurstLength); 617e48354ceSNicholas Bellinger 618e48354ceSNicholas Bellinger DEF_NACL_PARAM(DefaultTime2Wait); 619e48354ceSNicholas Bellinger NACL_PARAM_ATTR(DefaultTime2Wait); 620e48354ceSNicholas Bellinger 621e48354ceSNicholas Bellinger DEF_NACL_PARAM(DefaultTime2Retain); 622e48354ceSNicholas Bellinger NACL_PARAM_ATTR(DefaultTime2Retain); 623e48354ceSNicholas Bellinger 624e48354ceSNicholas Bellinger DEF_NACL_PARAM(MaxOutstandingR2T); 625e48354ceSNicholas Bellinger NACL_PARAM_ATTR(MaxOutstandingR2T); 626e48354ceSNicholas Bellinger 627e48354ceSNicholas Bellinger DEF_NACL_PARAM(DataPDUInOrder); 628e48354ceSNicholas Bellinger NACL_PARAM_ATTR(DataPDUInOrder); 629e48354ceSNicholas Bellinger 630e48354ceSNicholas Bellinger DEF_NACL_PARAM(DataSequenceInOrder); 631e48354ceSNicholas Bellinger NACL_PARAM_ATTR(DataSequenceInOrder); 632e48354ceSNicholas Bellinger 633e48354ceSNicholas Bellinger DEF_NACL_PARAM(ErrorRecoveryLevel); 634e48354ceSNicholas Bellinger NACL_PARAM_ATTR(ErrorRecoveryLevel); 635e48354ceSNicholas Bellinger 636e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_param_attrs[] = { 637e48354ceSNicholas Bellinger &iscsi_nacl_param_MaxConnections.attr, 638e48354ceSNicholas Bellinger &iscsi_nacl_param_InitialR2T.attr, 639e48354ceSNicholas Bellinger &iscsi_nacl_param_ImmediateData.attr, 640e48354ceSNicholas Bellinger &iscsi_nacl_param_MaxBurstLength.attr, 641e48354ceSNicholas Bellinger &iscsi_nacl_param_FirstBurstLength.attr, 642e48354ceSNicholas Bellinger &iscsi_nacl_param_DefaultTime2Wait.attr, 643e48354ceSNicholas Bellinger &iscsi_nacl_param_DefaultTime2Retain.attr, 644e48354ceSNicholas Bellinger &iscsi_nacl_param_MaxOutstandingR2T.attr, 645e48354ceSNicholas Bellinger &iscsi_nacl_param_DataPDUInOrder.attr, 646e48354ceSNicholas Bellinger &iscsi_nacl_param_DataSequenceInOrder.attr, 647e48354ceSNicholas Bellinger &iscsi_nacl_param_ErrorRecoveryLevel.attr, 648e48354ceSNicholas Bellinger NULL, 649e48354ceSNicholas Bellinger }; 650e48354ceSNicholas Bellinger 651e48354ceSNicholas Bellinger /* End items for lio_target_nacl_param_cit */ 652e48354ceSNicholas Bellinger 653e48354ceSNicholas Bellinger /* Start items for lio_target_acl_cit */ 654e48354ceSNicholas Bellinger 655e48354ceSNicholas Bellinger static ssize_t lio_target_nacl_show_info( 656e48354ceSNicholas Bellinger struct se_node_acl *se_nacl, 657e48354ceSNicholas Bellinger char *page) 658e48354ceSNicholas Bellinger { 659e48354ceSNicholas Bellinger struct iscsi_session *sess; 660e48354ceSNicholas Bellinger struct iscsi_conn *conn; 661e48354ceSNicholas Bellinger struct se_session *se_sess; 662e48354ceSNicholas Bellinger ssize_t rb = 0; 663e48354ceSNicholas Bellinger 664e48354ceSNicholas Bellinger spin_lock_bh(&se_nacl->nacl_sess_lock); 665e48354ceSNicholas Bellinger se_sess = se_nacl->nacl_sess; 666e48354ceSNicholas Bellinger if (!se_sess) { 667e48354ceSNicholas Bellinger rb += sprintf(page+rb, "No active iSCSI Session for Initiator" 668e48354ceSNicholas Bellinger " Endpoint: %s\n", se_nacl->initiatorname); 669e48354ceSNicholas Bellinger } else { 670e48354ceSNicholas Bellinger sess = se_sess->fabric_sess_ptr; 671e48354ceSNicholas Bellinger 672e48354ceSNicholas Bellinger rb += sprintf(page+rb, "InitiatorName: %s\n", 673e48354ceSNicholas Bellinger sess->sess_ops->InitiatorName); 674e48354ceSNicholas Bellinger rb += sprintf(page+rb, "InitiatorAlias: %s\n", 675e48354ceSNicholas Bellinger sess->sess_ops->InitiatorAlias); 676e48354ceSNicholas Bellinger 6775cdf5a87SAndy Shevchenko rb += sprintf(page+rb, 6785cdf5a87SAndy Shevchenko "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ", 6795cdf5a87SAndy Shevchenko sess->sid, sess->isid, sess->tsih); 680e48354ceSNicholas Bellinger rb += sprintf(page+rb, "SessionType: %s\n", 681e48354ceSNicholas Bellinger (sess->sess_ops->SessionType) ? 682e48354ceSNicholas Bellinger "Discovery" : "Normal"); 683e48354ceSNicholas Bellinger rb += sprintf(page+rb, "Session State: "); 684e48354ceSNicholas Bellinger switch (sess->session_state) { 685e48354ceSNicholas Bellinger case TARG_SESS_STATE_FREE: 686e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_FREE\n"); 687e48354ceSNicholas Bellinger break; 688e48354ceSNicholas Bellinger case TARG_SESS_STATE_ACTIVE: 689e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n"); 690e48354ceSNicholas Bellinger break; 691e48354ceSNicholas Bellinger case TARG_SESS_STATE_LOGGED_IN: 692e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n"); 693e48354ceSNicholas Bellinger break; 694e48354ceSNicholas Bellinger case TARG_SESS_STATE_FAILED: 695e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n"); 696e48354ceSNicholas Bellinger break; 697e48354ceSNicholas Bellinger case TARG_SESS_STATE_IN_CONTINUE: 698e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n"); 699e48354ceSNicholas Bellinger break; 700e48354ceSNicholas Bellinger default: 701e48354ceSNicholas Bellinger rb += sprintf(page+rb, "ERROR: Unknown Session" 702e48354ceSNicholas Bellinger " State!\n"); 703e48354ceSNicholas Bellinger break; 704e48354ceSNicholas Bellinger } 705e48354ceSNicholas Bellinger 706e48354ceSNicholas Bellinger rb += sprintf(page+rb, "---------------------[iSCSI Session" 707e48354ceSNicholas Bellinger " Values]-----------------------\n"); 708e48354ceSNicholas Bellinger rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN" 709e48354ceSNicholas Bellinger " : MaxCmdSN : ITT : TTT\n"); 710e48354ceSNicholas Bellinger rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x" 711e48354ceSNicholas Bellinger " 0x%08x 0x%08x\n", 712e48354ceSNicholas Bellinger sess->cmdsn_window, 713e48354ceSNicholas Bellinger (sess->max_cmd_sn - sess->exp_cmd_sn) + 1, 714e48354ceSNicholas Bellinger sess->exp_cmd_sn, sess->max_cmd_sn, 715e48354ceSNicholas Bellinger sess->init_task_tag, sess->targ_xfer_tag); 716e48354ceSNicholas Bellinger rb += sprintf(page+rb, "----------------------[iSCSI" 717e48354ceSNicholas Bellinger " Connections]-------------------------\n"); 718e48354ceSNicholas Bellinger 719e48354ceSNicholas Bellinger spin_lock(&sess->conn_lock); 720e48354ceSNicholas Bellinger list_for_each_entry(conn, &sess->sess_conn_list, conn_list) { 721e48354ceSNicholas Bellinger rb += sprintf(page+rb, "CID: %hu Connection" 722e48354ceSNicholas Bellinger " State: ", conn->cid); 723e48354ceSNicholas Bellinger switch (conn->conn_state) { 724e48354ceSNicholas Bellinger case TARG_CONN_STATE_FREE: 725e48354ceSNicholas Bellinger rb += sprintf(page+rb, 726e48354ceSNicholas Bellinger "TARG_CONN_STATE_FREE\n"); 727e48354ceSNicholas Bellinger break; 728e48354ceSNicholas Bellinger case TARG_CONN_STATE_XPT_UP: 729e48354ceSNicholas Bellinger rb += sprintf(page+rb, 730e48354ceSNicholas Bellinger "TARG_CONN_STATE_XPT_UP\n"); 731e48354ceSNicholas Bellinger break; 732e48354ceSNicholas Bellinger case TARG_CONN_STATE_IN_LOGIN: 733e48354ceSNicholas Bellinger rb += sprintf(page+rb, 734e48354ceSNicholas Bellinger "TARG_CONN_STATE_IN_LOGIN\n"); 735e48354ceSNicholas Bellinger break; 736e48354ceSNicholas Bellinger case TARG_CONN_STATE_LOGGED_IN: 737e48354ceSNicholas Bellinger rb += sprintf(page+rb, 738e48354ceSNicholas Bellinger "TARG_CONN_STATE_LOGGED_IN\n"); 739e48354ceSNicholas Bellinger break; 740e48354ceSNicholas Bellinger case TARG_CONN_STATE_IN_LOGOUT: 741e48354ceSNicholas Bellinger rb += sprintf(page+rb, 742e48354ceSNicholas Bellinger "TARG_CONN_STATE_IN_LOGOUT\n"); 743e48354ceSNicholas Bellinger break; 744e48354ceSNicholas Bellinger case TARG_CONN_STATE_LOGOUT_REQUESTED: 745e48354ceSNicholas Bellinger rb += sprintf(page+rb, 746e48354ceSNicholas Bellinger "TARG_CONN_STATE_LOGOUT_REQUESTED\n"); 747e48354ceSNicholas Bellinger break; 748e48354ceSNicholas Bellinger case TARG_CONN_STATE_CLEANUP_WAIT: 749e48354ceSNicholas Bellinger rb += sprintf(page+rb, 750e48354ceSNicholas Bellinger "TARG_CONN_STATE_CLEANUP_WAIT\n"); 751e48354ceSNicholas Bellinger break; 752e48354ceSNicholas Bellinger default: 753e48354ceSNicholas Bellinger rb += sprintf(page+rb, 754e48354ceSNicholas Bellinger "ERROR: Unknown Connection State!\n"); 755e48354ceSNicholas Bellinger break; 756e48354ceSNicholas Bellinger } 757e48354ceSNicholas Bellinger 758e48354ceSNicholas Bellinger rb += sprintf(page+rb, " Address %s %s", conn->login_ip, 759e48354ceSNicholas Bellinger (conn->network_transport == ISCSI_TCP) ? 760e48354ceSNicholas Bellinger "TCP" : "SCTP"); 761e48354ceSNicholas Bellinger rb += sprintf(page+rb, " StatSN: 0x%08x\n", 762e48354ceSNicholas Bellinger conn->stat_sn); 763e48354ceSNicholas Bellinger } 764e48354ceSNicholas Bellinger spin_unlock(&sess->conn_lock); 765e48354ceSNicholas Bellinger } 766e48354ceSNicholas Bellinger spin_unlock_bh(&se_nacl->nacl_sess_lock); 767e48354ceSNicholas Bellinger 768e48354ceSNicholas Bellinger return rb; 769e48354ceSNicholas Bellinger } 770e48354ceSNicholas Bellinger 771e48354ceSNicholas Bellinger TF_NACL_BASE_ATTR_RO(lio_target, info); 772e48354ceSNicholas Bellinger 773e48354ceSNicholas Bellinger static ssize_t lio_target_nacl_show_cmdsn_depth( 774e48354ceSNicholas Bellinger struct se_node_acl *se_nacl, 775e48354ceSNicholas Bellinger char *page) 776e48354ceSNicholas Bellinger { 777e48354ceSNicholas Bellinger return sprintf(page, "%u\n", se_nacl->queue_depth); 778e48354ceSNicholas Bellinger } 779e48354ceSNicholas Bellinger 780e48354ceSNicholas Bellinger static ssize_t lio_target_nacl_store_cmdsn_depth( 781e48354ceSNicholas Bellinger struct se_node_acl *se_nacl, 782e48354ceSNicholas Bellinger const char *page, 783e48354ceSNicholas Bellinger size_t count) 784e48354ceSNicholas Bellinger { 785e48354ceSNicholas Bellinger struct se_portal_group *se_tpg = se_nacl->se_tpg; 786e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, 787e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); 788e48354ceSNicholas Bellinger struct config_item *acl_ci, *tpg_ci, *wwn_ci; 789e48354ceSNicholas Bellinger u32 cmdsn_depth = 0; 790e48354ceSNicholas Bellinger int ret; 791e48354ceSNicholas Bellinger 792ad7babd2SJörn Engel ret = kstrtou32(page, 0, &cmdsn_depth); 793ad7babd2SJörn Engel if (ret) 794ad7babd2SJörn Engel return ret; 795e48354ceSNicholas Bellinger if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) { 796e48354ceSNicholas Bellinger pr_err("Passed cmdsn_depth: %u exceeds" 797e48354ceSNicholas Bellinger " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth, 798e48354ceSNicholas Bellinger TA_DEFAULT_CMDSN_DEPTH_MAX); 799e48354ceSNicholas Bellinger return -EINVAL; 800e48354ceSNicholas Bellinger } 801e48354ceSNicholas Bellinger acl_ci = &se_nacl->acl_group.cg_item; 802e48354ceSNicholas Bellinger if (!acl_ci) { 803e48354ceSNicholas Bellinger pr_err("Unable to locatel acl_ci\n"); 804e48354ceSNicholas Bellinger return -EINVAL; 805e48354ceSNicholas Bellinger } 806e48354ceSNicholas Bellinger tpg_ci = &acl_ci->ci_parent->ci_group->cg_item; 807e48354ceSNicholas Bellinger if (!tpg_ci) { 808e48354ceSNicholas Bellinger pr_err("Unable to locate tpg_ci\n"); 809e48354ceSNicholas Bellinger return -EINVAL; 810e48354ceSNicholas Bellinger } 811e48354ceSNicholas Bellinger wwn_ci = &tpg_ci->ci_group->cg_item; 812e48354ceSNicholas Bellinger if (!wwn_ci) { 813e48354ceSNicholas Bellinger pr_err("Unable to locate config_item wwn_ci\n"); 814e48354ceSNicholas Bellinger return -EINVAL; 815e48354ceSNicholas Bellinger } 816e48354ceSNicholas Bellinger 817e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) 818e48354ceSNicholas Bellinger return -EINVAL; 819e48354ceSNicholas Bellinger /* 820e48354ceSNicholas Bellinger * iscsit_tpg_set_initiator_node_queue_depth() assumes force=1 821e48354ceSNicholas Bellinger */ 822e48354ceSNicholas Bellinger ret = iscsit_tpg_set_initiator_node_queue_depth(tpg, 823e48354ceSNicholas Bellinger config_item_name(acl_ci), cmdsn_depth, 1); 824e48354ceSNicholas Bellinger 825e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for" 826e48354ceSNicholas Bellinger "InitiatorName: %s\n", config_item_name(wwn_ci), 827e48354ceSNicholas Bellinger config_item_name(tpg_ci), cmdsn_depth, 828e48354ceSNicholas Bellinger config_item_name(acl_ci)); 829e48354ceSNicholas Bellinger 830e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 831e48354ceSNicholas Bellinger return (!ret) ? count : (ssize_t)ret; 832e48354ceSNicholas Bellinger } 833e48354ceSNicholas Bellinger 834e48354ceSNicholas Bellinger TF_NACL_BASE_ATTR(lio_target, cmdsn_depth, S_IRUGO | S_IWUSR); 835e48354ceSNicholas Bellinger 83679e62fc3SAndy Grover static ssize_t lio_target_nacl_show_tag( 83779e62fc3SAndy Grover struct se_node_acl *se_nacl, 83879e62fc3SAndy Grover char *page) 83979e62fc3SAndy Grover { 84079e62fc3SAndy Grover return snprintf(page, PAGE_SIZE, "%s", se_nacl->acl_tag); 84179e62fc3SAndy Grover } 84279e62fc3SAndy Grover 84379e62fc3SAndy Grover static ssize_t lio_target_nacl_store_tag( 84479e62fc3SAndy Grover struct se_node_acl *se_nacl, 84579e62fc3SAndy Grover const char *page, 84679e62fc3SAndy Grover size_t count) 84779e62fc3SAndy Grover { 84879e62fc3SAndy Grover int ret; 84979e62fc3SAndy Grover 85079e62fc3SAndy Grover ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page); 85179e62fc3SAndy Grover 85279e62fc3SAndy Grover if (ret < 0) 85379e62fc3SAndy Grover return ret; 85479e62fc3SAndy Grover return count; 85579e62fc3SAndy Grover } 85679e62fc3SAndy Grover 85779e62fc3SAndy Grover TF_NACL_BASE_ATTR(lio_target, tag, S_IRUGO | S_IWUSR); 85879e62fc3SAndy Grover 859e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_initiator_attrs[] = { 860e48354ceSNicholas Bellinger &lio_target_nacl_info.attr, 861e48354ceSNicholas Bellinger &lio_target_nacl_cmdsn_depth.attr, 86279e62fc3SAndy Grover &lio_target_nacl_tag.attr, 863e48354ceSNicholas Bellinger NULL, 864e48354ceSNicholas Bellinger }; 865e48354ceSNicholas Bellinger 866e48354ceSNicholas Bellinger static struct se_node_acl *lio_tpg_alloc_fabric_acl( 867e48354ceSNicholas Bellinger struct se_portal_group *se_tpg) 868e48354ceSNicholas Bellinger { 869e48354ceSNicholas Bellinger struct iscsi_node_acl *acl; 870e48354ceSNicholas Bellinger 871e48354ceSNicholas Bellinger acl = kzalloc(sizeof(struct iscsi_node_acl), GFP_KERNEL); 872e48354ceSNicholas Bellinger if (!acl) { 873e48354ceSNicholas Bellinger pr_err("Unable to allocate memory for struct iscsi_node_acl\n"); 874e48354ceSNicholas Bellinger return NULL; 875e48354ceSNicholas Bellinger } 876e48354ceSNicholas Bellinger 877e48354ceSNicholas Bellinger return &acl->se_node_acl; 878e48354ceSNicholas Bellinger } 879e48354ceSNicholas Bellinger 880e48354ceSNicholas Bellinger static struct se_node_acl *lio_target_make_nodeacl( 881e48354ceSNicholas Bellinger struct se_portal_group *se_tpg, 882e48354ceSNicholas Bellinger struct config_group *group, 883e48354ceSNicholas Bellinger const char *name) 884e48354ceSNicholas Bellinger { 885e48354ceSNicholas Bellinger struct config_group *stats_cg; 886e48354ceSNicholas Bellinger struct iscsi_node_acl *acl; 887e48354ceSNicholas Bellinger struct se_node_acl *se_nacl_new, *se_nacl; 888e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, 889e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); 890e48354ceSNicholas Bellinger u32 cmdsn_depth; 891e48354ceSNicholas Bellinger 892e48354ceSNicholas Bellinger se_nacl_new = lio_tpg_alloc_fabric_acl(se_tpg); 893e48354ceSNicholas Bellinger if (!se_nacl_new) 894e48354ceSNicholas Bellinger return ERR_PTR(-ENOMEM); 895e48354ceSNicholas Bellinger 896b7eec2cdSAndy Grover cmdsn_depth = tpg->tpg_attrib.default_cmdsn_depth; 897e48354ceSNicholas Bellinger /* 898e48354ceSNicholas Bellinger * se_nacl_new may be released by core_tpg_add_initiator_node_acl() 899e48354ceSNicholas Bellinger * when converting a NdoeACL from demo mode -> explict 900e48354ceSNicholas Bellinger */ 901e48354ceSNicholas Bellinger se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new, 902e48354ceSNicholas Bellinger name, cmdsn_depth); 903e48354ceSNicholas Bellinger if (IS_ERR(se_nacl)) 904e48354ceSNicholas Bellinger return se_nacl; 905e48354ceSNicholas Bellinger 906d0628334SNicholas Bellinger acl = container_of(se_nacl, struct iscsi_node_acl, se_node_acl); 907d0628334SNicholas Bellinger stats_cg = &se_nacl->acl_fabric_stat_group; 908e48354ceSNicholas Bellinger 90913f6a914SSebastian Andrzej Siewior stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, 910e48354ceSNicholas Bellinger GFP_KERNEL); 911e48354ceSNicholas Bellinger if (!stats_cg->default_groups) { 912e48354ceSNicholas Bellinger pr_err("Unable to allocate memory for" 913e48354ceSNicholas Bellinger " stats_cg->default_groups\n"); 914e48354ceSNicholas Bellinger core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1); 915e48354ceSNicholas Bellinger kfree(acl); 916e48354ceSNicholas Bellinger return ERR_PTR(-ENOMEM); 917e48354ceSNicholas Bellinger } 918e48354ceSNicholas Bellinger 919b7eec2cdSAndy Grover stats_cg->default_groups[0] = &acl->node_stat_grps.iscsi_sess_stats_group; 920e48354ceSNicholas Bellinger stats_cg->default_groups[1] = NULL; 921b7eec2cdSAndy Grover config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group, 922e48354ceSNicholas Bellinger "iscsi_sess_stats", &iscsi_stat_sess_cit); 923e48354ceSNicholas Bellinger 924e48354ceSNicholas Bellinger return se_nacl; 925e48354ceSNicholas Bellinger } 926e48354ceSNicholas Bellinger 927e48354ceSNicholas Bellinger static void lio_target_drop_nodeacl( 928e48354ceSNicholas Bellinger struct se_node_acl *se_nacl) 929e48354ceSNicholas Bellinger { 930e48354ceSNicholas Bellinger struct se_portal_group *se_tpg = se_nacl->se_tpg; 931e48354ceSNicholas Bellinger struct iscsi_node_acl *acl = container_of(se_nacl, 932e48354ceSNicholas Bellinger struct iscsi_node_acl, se_node_acl); 933e48354ceSNicholas Bellinger struct config_item *df_item; 934e48354ceSNicholas Bellinger struct config_group *stats_cg; 935e48354ceSNicholas Bellinger int i; 936e48354ceSNicholas Bellinger 937e48354ceSNicholas Bellinger stats_cg = &acl->se_node_acl.acl_fabric_stat_group; 938e48354ceSNicholas Bellinger for (i = 0; stats_cg->default_groups[i]; i++) { 939e48354ceSNicholas Bellinger df_item = &stats_cg->default_groups[i]->cg_item; 940e48354ceSNicholas Bellinger stats_cg->default_groups[i] = NULL; 941e48354ceSNicholas Bellinger config_item_put(df_item); 942e48354ceSNicholas Bellinger } 943e48354ceSNicholas Bellinger kfree(stats_cg->default_groups); 944e48354ceSNicholas Bellinger 945e48354ceSNicholas Bellinger core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1); 946e48354ceSNicholas Bellinger kfree(acl); 947e48354ceSNicholas Bellinger } 948e48354ceSNicholas Bellinger 949e48354ceSNicholas Bellinger /* End items for lio_target_acl_cit */ 950e48354ceSNicholas Bellinger 951e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_attrib_cit */ 952e48354ceSNicholas Bellinger 953e48354ceSNicholas Bellinger #define DEF_TPG_ATTRIB(name) \ 954e48354ceSNicholas Bellinger \ 955e48354ceSNicholas Bellinger static ssize_t iscsi_tpg_attrib_show_##name( \ 956e48354ceSNicholas Bellinger struct se_portal_group *se_tpg, \ 957e48354ceSNicholas Bellinger char *page) \ 958e48354ceSNicholas Bellinger { \ 959e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 960e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 961e48354ceSNicholas Bellinger ssize_t rb; \ 962e48354ceSNicholas Bellinger \ 963e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) \ 964e48354ceSNicholas Bellinger return -EINVAL; \ 965e48354ceSNicholas Bellinger \ 966b7eec2cdSAndy Grover rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \ 967e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 968e48354ceSNicholas Bellinger return rb; \ 969e48354ceSNicholas Bellinger } \ 970e48354ceSNicholas Bellinger \ 971e48354ceSNicholas Bellinger static ssize_t iscsi_tpg_attrib_store_##name( \ 972e48354ceSNicholas Bellinger struct se_portal_group *se_tpg, \ 973e48354ceSNicholas Bellinger const char *page, \ 974e48354ceSNicholas Bellinger size_t count) \ 975e48354ceSNicholas Bellinger { \ 976e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 977e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 978e48354ceSNicholas Bellinger u32 val; \ 979e48354ceSNicholas Bellinger int ret; \ 980e48354ceSNicholas Bellinger \ 981e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) \ 982e48354ceSNicholas Bellinger return -EINVAL; \ 983e48354ceSNicholas Bellinger \ 984ad7babd2SJörn Engel ret = kstrtou32(page, 0, &val); \ 985ad7babd2SJörn Engel if (ret) \ 986ad7babd2SJörn Engel goto out; \ 987e48354ceSNicholas Bellinger ret = iscsit_ta_##name(tpg, val); \ 988e48354ceSNicholas Bellinger if (ret < 0) \ 989e48354ceSNicholas Bellinger goto out; \ 990e48354ceSNicholas Bellinger \ 991e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 992e48354ceSNicholas Bellinger return count; \ 993e48354ceSNicholas Bellinger out: \ 994e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 995e48354ceSNicholas Bellinger return ret; \ 996e48354ceSNicholas Bellinger } 997e48354ceSNicholas Bellinger 998e48354ceSNicholas Bellinger #define TPG_ATTR(_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode); 999e48354ceSNicholas Bellinger 1000e48354ceSNicholas Bellinger /* 1001e48354ceSNicholas Bellinger * Define iscsi_tpg_attrib_s_authentication 1002e48354ceSNicholas Bellinger */ 1003e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(authentication); 1004e48354ceSNicholas Bellinger TPG_ATTR(authentication, S_IRUGO | S_IWUSR); 1005e48354ceSNicholas Bellinger /* 1006e48354ceSNicholas Bellinger * Define iscsi_tpg_attrib_s_login_timeout 1007e48354ceSNicholas Bellinger */ 1008e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(login_timeout); 1009e48354ceSNicholas Bellinger TPG_ATTR(login_timeout, S_IRUGO | S_IWUSR); 1010e48354ceSNicholas Bellinger /* 1011e48354ceSNicholas Bellinger * Define iscsi_tpg_attrib_s_netif_timeout 1012e48354ceSNicholas Bellinger */ 1013e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(netif_timeout); 1014e48354ceSNicholas Bellinger TPG_ATTR(netif_timeout, S_IRUGO | S_IWUSR); 1015e48354ceSNicholas Bellinger /* 1016e48354ceSNicholas Bellinger * Define iscsi_tpg_attrib_s_generate_node_acls 1017e48354ceSNicholas Bellinger */ 1018e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(generate_node_acls); 1019e48354ceSNicholas Bellinger TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR); 1020e48354ceSNicholas Bellinger /* 1021e48354ceSNicholas Bellinger * Define iscsi_tpg_attrib_s_default_cmdsn_depth 1022e48354ceSNicholas Bellinger */ 1023e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(default_cmdsn_depth); 1024e48354ceSNicholas Bellinger TPG_ATTR(default_cmdsn_depth, S_IRUGO | S_IWUSR); 1025e48354ceSNicholas Bellinger /* 1026e48354ceSNicholas Bellinger Define iscsi_tpg_attrib_s_cache_dynamic_acls 1027e48354ceSNicholas Bellinger */ 1028e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(cache_dynamic_acls); 1029e48354ceSNicholas Bellinger TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR); 1030e48354ceSNicholas Bellinger /* 1031e48354ceSNicholas Bellinger * Define iscsi_tpg_attrib_s_demo_mode_write_protect 1032e48354ceSNicholas Bellinger */ 1033e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(demo_mode_write_protect); 1034e48354ceSNicholas Bellinger TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR); 1035e48354ceSNicholas Bellinger /* 1036e48354ceSNicholas Bellinger * Define iscsi_tpg_attrib_s_prod_mode_write_protect 1037e48354ceSNicholas Bellinger */ 1038e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(prod_mode_write_protect); 1039e48354ceSNicholas Bellinger TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR); 10404c54b6cfSThomas Glanzmann /* 10414c54b6cfSThomas Glanzmann * Define iscsi_tpg_attrib_s_demo_mode_discovery, 10424c54b6cfSThomas Glanzmann */ 10434c54b6cfSThomas Glanzmann DEF_TPG_ATTRIB(demo_mode_discovery); 10444c54b6cfSThomas Glanzmann TPG_ATTR(demo_mode_discovery, S_IRUGO | S_IWUSR); 1045d1fa7a1dSNicholas Bellinger /* 1046d1fa7a1dSNicholas Bellinger * Define iscsi_tpg_attrib_s_default_erl 1047d1fa7a1dSNicholas Bellinger */ 1048d1fa7a1dSNicholas Bellinger DEF_TPG_ATTRIB(default_erl); 1049d1fa7a1dSNicholas Bellinger TPG_ATTR(default_erl, S_IRUGO | S_IWUSR); 10508085176fSSagi Grimberg /* 10518085176fSSagi Grimberg * Define iscsi_tpg_attrib_s_t10_pi 10528085176fSSagi Grimberg */ 10538085176fSSagi Grimberg DEF_TPG_ATTRIB(t10_pi); 10548085176fSSagi Grimberg TPG_ATTR(t10_pi, S_IRUGO | S_IWUSR); 1055901c04a3SNicholas Bellinger /* 1056901c04a3SNicholas Bellinger * Define iscsi_tpg_attrib_s_fabric_prot_type 1057901c04a3SNicholas Bellinger */ 1058901c04a3SNicholas Bellinger DEF_TPG_ATTRIB(fabric_prot_type); 1059901c04a3SNicholas Bellinger TPG_ATTR(fabric_prot_type, S_IRUGO | S_IWUSR); 1060e48354ceSNicholas Bellinger 1061e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = { 1062e48354ceSNicholas Bellinger &iscsi_tpg_attrib_authentication.attr, 1063e48354ceSNicholas Bellinger &iscsi_tpg_attrib_login_timeout.attr, 1064e48354ceSNicholas Bellinger &iscsi_tpg_attrib_netif_timeout.attr, 1065e48354ceSNicholas Bellinger &iscsi_tpg_attrib_generate_node_acls.attr, 1066e48354ceSNicholas Bellinger &iscsi_tpg_attrib_default_cmdsn_depth.attr, 1067e48354ceSNicholas Bellinger &iscsi_tpg_attrib_cache_dynamic_acls.attr, 1068e48354ceSNicholas Bellinger &iscsi_tpg_attrib_demo_mode_write_protect.attr, 1069e48354ceSNicholas Bellinger &iscsi_tpg_attrib_prod_mode_write_protect.attr, 10704c54b6cfSThomas Glanzmann &iscsi_tpg_attrib_demo_mode_discovery.attr, 1071d1fa7a1dSNicholas Bellinger &iscsi_tpg_attrib_default_erl.attr, 10728085176fSSagi Grimberg &iscsi_tpg_attrib_t10_pi.attr, 1073901c04a3SNicholas Bellinger &iscsi_tpg_attrib_fabric_prot_type.attr, 1074e48354ceSNicholas Bellinger NULL, 1075e48354ceSNicholas Bellinger }; 1076e48354ceSNicholas Bellinger 1077e48354ceSNicholas Bellinger /* End items for lio_target_tpg_attrib_cit */ 1078e48354ceSNicholas Bellinger 1079c3e51442SNicholas Bellinger /* Start items for lio_target_tpg_auth_cit */ 1080c3e51442SNicholas Bellinger 1081c3e51442SNicholas Bellinger #define __DEF_TPG_AUTH_STR(prefix, name, flags) \ 1082c3e51442SNicholas Bellinger static ssize_t __iscsi_##prefix##_show_##name( \ 1083c3e51442SNicholas Bellinger struct se_portal_group *se_tpg, \ 1084c3e51442SNicholas Bellinger char *page) \ 1085c3e51442SNicholas Bellinger { \ 1086c3e51442SNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 1087c3e51442SNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 1088c3e51442SNicholas Bellinger struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ 1089c3e51442SNicholas Bellinger \ 1090c3e51442SNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 1091c3e51442SNicholas Bellinger return -EPERM; \ 1092c3e51442SNicholas Bellinger \ 1093c3e51442SNicholas Bellinger return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ 1094c3e51442SNicholas Bellinger } \ 1095c3e51442SNicholas Bellinger \ 1096c3e51442SNicholas Bellinger static ssize_t __iscsi_##prefix##_store_##name( \ 1097c3e51442SNicholas Bellinger struct se_portal_group *se_tpg, \ 1098c3e51442SNicholas Bellinger const char *page, \ 1099c3e51442SNicholas Bellinger size_t count) \ 1100c3e51442SNicholas Bellinger { \ 1101c3e51442SNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 1102c3e51442SNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 1103c3e51442SNicholas Bellinger struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ 1104c3e51442SNicholas Bellinger \ 1105c3e51442SNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 1106c3e51442SNicholas Bellinger return -EPERM; \ 1107c3e51442SNicholas Bellinger \ 110837b32c6fSNicholas Bellinger snprintf(auth->name, sizeof(auth->name), "%s", page); \ 1109c3e51442SNicholas Bellinger if (!(strncmp("NULL", auth->name, 4))) \ 1110c3e51442SNicholas Bellinger auth->naf_flags &= ~flags; \ 1111c3e51442SNicholas Bellinger else \ 1112c3e51442SNicholas Bellinger auth->naf_flags |= flags; \ 1113c3e51442SNicholas Bellinger \ 1114c3e51442SNicholas Bellinger if ((auth->naf_flags & NAF_USERID_IN_SET) && \ 1115c3e51442SNicholas Bellinger (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ 1116c3e51442SNicholas Bellinger auth->authenticate_target = 1; \ 1117c3e51442SNicholas Bellinger else \ 1118c3e51442SNicholas Bellinger auth->authenticate_target = 0; \ 1119c3e51442SNicholas Bellinger \ 1120c3e51442SNicholas Bellinger return count; \ 1121c3e51442SNicholas Bellinger } 1122c3e51442SNicholas Bellinger 1123c3e51442SNicholas Bellinger #define __DEF_TPG_AUTH_INT(prefix, name) \ 1124c3e51442SNicholas Bellinger static ssize_t __iscsi_##prefix##_show_##name( \ 1125c3e51442SNicholas Bellinger struct se_portal_group *se_tpg, \ 1126c3e51442SNicholas Bellinger char *page) \ 1127c3e51442SNicholas Bellinger { \ 1128c3e51442SNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 1129c3e51442SNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 1130c3e51442SNicholas Bellinger struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ 1131c3e51442SNicholas Bellinger \ 1132c3e51442SNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 1133c3e51442SNicholas Bellinger return -EPERM; \ 1134c3e51442SNicholas Bellinger \ 1135c3e51442SNicholas Bellinger return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ 1136c3e51442SNicholas Bellinger } 1137c3e51442SNicholas Bellinger 1138c3e51442SNicholas Bellinger #define DEF_TPG_AUTH_STR(name, flags) \ 1139c3e51442SNicholas Bellinger __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \ 1140c3e51442SNicholas Bellinger static ssize_t iscsi_tpg_auth_show_##name( \ 1141c3e51442SNicholas Bellinger struct se_portal_group *se_tpg, \ 1142c3e51442SNicholas Bellinger char *page) \ 1143c3e51442SNicholas Bellinger { \ 1144c3e51442SNicholas Bellinger return __iscsi_tpg_auth_show_##name(se_tpg, page); \ 1145c3e51442SNicholas Bellinger } \ 1146c3e51442SNicholas Bellinger \ 1147c3e51442SNicholas Bellinger static ssize_t iscsi_tpg_auth_store_##name( \ 1148c3e51442SNicholas Bellinger struct se_portal_group *se_tpg, \ 1149c3e51442SNicholas Bellinger const char *page, \ 1150c3e51442SNicholas Bellinger size_t count) \ 1151c3e51442SNicholas Bellinger { \ 1152c3e51442SNicholas Bellinger return __iscsi_tpg_auth_store_##name(se_tpg, page, count); \ 1153c3e51442SNicholas Bellinger } 1154c3e51442SNicholas Bellinger 1155c3e51442SNicholas Bellinger #define DEF_TPG_AUTH_INT(name) \ 1156c3e51442SNicholas Bellinger __DEF_TPG_AUTH_INT(tpg_auth, name) \ 1157c3e51442SNicholas Bellinger static ssize_t iscsi_tpg_auth_show_##name( \ 1158c3e51442SNicholas Bellinger struct se_portal_group *se_tpg, \ 1159c3e51442SNicholas Bellinger char *page) \ 1160c3e51442SNicholas Bellinger { \ 1161c3e51442SNicholas Bellinger return __iscsi_tpg_auth_show_##name(se_tpg, page); \ 1162c3e51442SNicholas Bellinger } 1163c3e51442SNicholas Bellinger 1164c3e51442SNicholas Bellinger #define TPG_AUTH_ATTR(_name, _mode) TF_TPG_AUTH_ATTR(iscsi, _name, _mode); 1165c3e51442SNicholas Bellinger #define TPG_AUTH_ATTR_RO(_name) TF_TPG_AUTH_ATTR_RO(iscsi, _name); 1166c3e51442SNicholas Bellinger 1167c3e51442SNicholas Bellinger /* 1168c3e51442SNicholas Bellinger * * One-way authentication userid 1169c3e51442SNicholas Bellinger * */ 1170c3e51442SNicholas Bellinger DEF_TPG_AUTH_STR(userid, NAF_USERID_SET); 1171c3e51442SNicholas Bellinger TPG_AUTH_ATTR(userid, S_IRUGO | S_IWUSR); 1172c3e51442SNicholas Bellinger /* 1173c3e51442SNicholas Bellinger * * One-way authentication password 1174c3e51442SNicholas Bellinger * */ 1175c3e51442SNicholas Bellinger DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET); 1176c3e51442SNicholas Bellinger TPG_AUTH_ATTR(password, S_IRUGO | S_IWUSR); 1177c3e51442SNicholas Bellinger /* 1178c3e51442SNicholas Bellinger * * Enforce mutual authentication 1179c3e51442SNicholas Bellinger * */ 1180c3e51442SNicholas Bellinger DEF_TPG_AUTH_INT(authenticate_target); 1181c3e51442SNicholas Bellinger TPG_AUTH_ATTR_RO(authenticate_target); 1182c3e51442SNicholas Bellinger /* 1183c3e51442SNicholas Bellinger * * Mutual authentication userid 1184c3e51442SNicholas Bellinger * */ 1185c3e51442SNicholas Bellinger DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); 1186c3e51442SNicholas Bellinger TPG_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR); 1187c3e51442SNicholas Bellinger /* 1188c3e51442SNicholas Bellinger * * Mutual authentication password 1189c3e51442SNicholas Bellinger * */ 1190c3e51442SNicholas Bellinger DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); 1191c3e51442SNicholas Bellinger TPG_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR); 1192c3e51442SNicholas Bellinger 1193c3e51442SNicholas Bellinger static struct configfs_attribute *lio_target_tpg_auth_attrs[] = { 1194c3e51442SNicholas Bellinger &iscsi_tpg_auth_userid.attr, 1195c3e51442SNicholas Bellinger &iscsi_tpg_auth_password.attr, 1196c3e51442SNicholas Bellinger &iscsi_tpg_auth_authenticate_target.attr, 1197c3e51442SNicholas Bellinger &iscsi_tpg_auth_userid_mutual.attr, 1198c3e51442SNicholas Bellinger &iscsi_tpg_auth_password_mutual.attr, 1199c3e51442SNicholas Bellinger NULL, 1200c3e51442SNicholas Bellinger }; 1201c3e51442SNicholas Bellinger 1202c3e51442SNicholas Bellinger /* End items for lio_target_tpg_auth_cit */ 1203c3e51442SNicholas Bellinger 1204e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_param_cit */ 1205e48354ceSNicholas Bellinger 1206e48354ceSNicholas Bellinger #define DEF_TPG_PARAM(name) \ 1207e48354ceSNicholas Bellinger static ssize_t iscsi_tpg_param_show_##name( \ 1208e48354ceSNicholas Bellinger struct se_portal_group *se_tpg, \ 1209e48354ceSNicholas Bellinger char *page) \ 1210e48354ceSNicholas Bellinger { \ 1211e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 1212e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 1213e48354ceSNicholas Bellinger struct iscsi_param *param; \ 1214e48354ceSNicholas Bellinger ssize_t rb; \ 1215e48354ceSNicholas Bellinger \ 1216e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) \ 1217e48354ceSNicholas Bellinger return -EINVAL; \ 1218e48354ceSNicholas Bellinger \ 1219e48354ceSNicholas Bellinger param = iscsi_find_param_from_key(__stringify(name), \ 1220e48354ceSNicholas Bellinger tpg->param_list); \ 1221e48354ceSNicholas Bellinger if (!param) { \ 1222e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 1223e48354ceSNicholas Bellinger return -EINVAL; \ 1224e48354ceSNicholas Bellinger } \ 1225e48354ceSNicholas Bellinger rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \ 1226e48354ceSNicholas Bellinger \ 1227e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 1228e48354ceSNicholas Bellinger return rb; \ 1229e48354ceSNicholas Bellinger } \ 1230e48354ceSNicholas Bellinger static ssize_t iscsi_tpg_param_store_##name( \ 1231e48354ceSNicholas Bellinger struct se_portal_group *se_tpg, \ 1232e48354ceSNicholas Bellinger const char *page, \ 1233e48354ceSNicholas Bellinger size_t count) \ 1234e48354ceSNicholas Bellinger { \ 1235e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 1236e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 1237e48354ceSNicholas Bellinger char *buf; \ 1238ad7babd2SJörn Engel int ret, len; \ 1239e48354ceSNicholas Bellinger \ 1240e48354ceSNicholas Bellinger buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \ 1241e48354ceSNicholas Bellinger if (!buf) \ 1242e48354ceSNicholas Bellinger return -ENOMEM; \ 1243ad7babd2SJörn Engel len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \ 1244ad7babd2SJörn Engel if (isspace(buf[len-1])) \ 1245ad7babd2SJörn Engel buf[len-1] = '\0'; /* Kill newline */ \ 1246e48354ceSNicholas Bellinger \ 1247e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) { \ 1248e48354ceSNicholas Bellinger kfree(buf); \ 1249e48354ceSNicholas Bellinger return -EINVAL; \ 1250e48354ceSNicholas Bellinger } \ 1251e48354ceSNicholas Bellinger \ 1252e48354ceSNicholas Bellinger ret = iscsi_change_param_value(buf, tpg->param_list, 1); \ 1253e48354ceSNicholas Bellinger if (ret < 0) \ 1254e48354ceSNicholas Bellinger goto out; \ 1255e48354ceSNicholas Bellinger \ 1256e48354ceSNicholas Bellinger kfree(buf); \ 1257e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 1258e48354ceSNicholas Bellinger return count; \ 1259e48354ceSNicholas Bellinger out: \ 1260e48354ceSNicholas Bellinger kfree(buf); \ 1261e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 1262e48354ceSNicholas Bellinger return -EINVAL; \ 1263e48354ceSNicholas Bellinger } 1264e48354ceSNicholas Bellinger 1265e48354ceSNicholas Bellinger #define TPG_PARAM_ATTR(_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode); 1266e48354ceSNicholas Bellinger 1267e48354ceSNicholas Bellinger DEF_TPG_PARAM(AuthMethod); 1268e48354ceSNicholas Bellinger TPG_PARAM_ATTR(AuthMethod, S_IRUGO | S_IWUSR); 1269e48354ceSNicholas Bellinger 1270e48354ceSNicholas Bellinger DEF_TPG_PARAM(HeaderDigest); 1271e48354ceSNicholas Bellinger TPG_PARAM_ATTR(HeaderDigest, S_IRUGO | S_IWUSR); 1272e48354ceSNicholas Bellinger 1273e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataDigest); 1274e48354ceSNicholas Bellinger TPG_PARAM_ATTR(DataDigest, S_IRUGO | S_IWUSR); 1275e48354ceSNicholas Bellinger 1276e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxConnections); 1277e48354ceSNicholas Bellinger TPG_PARAM_ATTR(MaxConnections, S_IRUGO | S_IWUSR); 1278e48354ceSNicholas Bellinger 1279e48354ceSNicholas Bellinger DEF_TPG_PARAM(TargetAlias); 1280e48354ceSNicholas Bellinger TPG_PARAM_ATTR(TargetAlias, S_IRUGO | S_IWUSR); 1281e48354ceSNicholas Bellinger 1282e48354ceSNicholas Bellinger DEF_TPG_PARAM(InitialR2T); 1283e48354ceSNicholas Bellinger TPG_PARAM_ATTR(InitialR2T, S_IRUGO | S_IWUSR); 1284e48354ceSNicholas Bellinger 1285e48354ceSNicholas Bellinger DEF_TPG_PARAM(ImmediateData); 1286e48354ceSNicholas Bellinger TPG_PARAM_ATTR(ImmediateData, S_IRUGO | S_IWUSR); 1287e48354ceSNicholas Bellinger 1288e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxRecvDataSegmentLength); 1289e48354ceSNicholas Bellinger TPG_PARAM_ATTR(MaxRecvDataSegmentLength, S_IRUGO | S_IWUSR); 1290e48354ceSNicholas Bellinger 1291e004cb25SNicholas Bellinger DEF_TPG_PARAM(MaxXmitDataSegmentLength); 1292e004cb25SNicholas Bellinger TPG_PARAM_ATTR(MaxXmitDataSegmentLength, S_IRUGO | S_IWUSR); 1293e004cb25SNicholas Bellinger 1294e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxBurstLength); 1295e48354ceSNicholas Bellinger TPG_PARAM_ATTR(MaxBurstLength, S_IRUGO | S_IWUSR); 1296e48354ceSNicholas Bellinger 1297e48354ceSNicholas Bellinger DEF_TPG_PARAM(FirstBurstLength); 1298e48354ceSNicholas Bellinger TPG_PARAM_ATTR(FirstBurstLength, S_IRUGO | S_IWUSR); 1299e48354ceSNicholas Bellinger 1300e48354ceSNicholas Bellinger DEF_TPG_PARAM(DefaultTime2Wait); 1301e48354ceSNicholas Bellinger TPG_PARAM_ATTR(DefaultTime2Wait, S_IRUGO | S_IWUSR); 1302e48354ceSNicholas Bellinger 1303e48354ceSNicholas Bellinger DEF_TPG_PARAM(DefaultTime2Retain); 1304e48354ceSNicholas Bellinger TPG_PARAM_ATTR(DefaultTime2Retain, S_IRUGO | S_IWUSR); 1305e48354ceSNicholas Bellinger 1306e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxOutstandingR2T); 1307e48354ceSNicholas Bellinger TPG_PARAM_ATTR(MaxOutstandingR2T, S_IRUGO | S_IWUSR); 1308e48354ceSNicholas Bellinger 1309e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataPDUInOrder); 1310e48354ceSNicholas Bellinger TPG_PARAM_ATTR(DataPDUInOrder, S_IRUGO | S_IWUSR); 1311e48354ceSNicholas Bellinger 1312e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataSequenceInOrder); 1313e48354ceSNicholas Bellinger TPG_PARAM_ATTR(DataSequenceInOrder, S_IRUGO | S_IWUSR); 1314e48354ceSNicholas Bellinger 1315e48354ceSNicholas Bellinger DEF_TPG_PARAM(ErrorRecoveryLevel); 1316e48354ceSNicholas Bellinger TPG_PARAM_ATTR(ErrorRecoveryLevel, S_IRUGO | S_IWUSR); 1317e48354ceSNicholas Bellinger 1318e48354ceSNicholas Bellinger DEF_TPG_PARAM(IFMarker); 1319e48354ceSNicholas Bellinger TPG_PARAM_ATTR(IFMarker, S_IRUGO | S_IWUSR); 1320e48354ceSNicholas Bellinger 1321e48354ceSNicholas Bellinger DEF_TPG_PARAM(OFMarker); 1322e48354ceSNicholas Bellinger TPG_PARAM_ATTR(OFMarker, S_IRUGO | S_IWUSR); 1323e48354ceSNicholas Bellinger 1324e48354ceSNicholas Bellinger DEF_TPG_PARAM(IFMarkInt); 1325e48354ceSNicholas Bellinger TPG_PARAM_ATTR(IFMarkInt, S_IRUGO | S_IWUSR); 1326e48354ceSNicholas Bellinger 1327e48354ceSNicholas Bellinger DEF_TPG_PARAM(OFMarkInt); 1328e48354ceSNicholas Bellinger TPG_PARAM_ATTR(OFMarkInt, S_IRUGO | S_IWUSR); 1329e48354ceSNicholas Bellinger 1330e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_param_attrs[] = { 1331e48354ceSNicholas Bellinger &iscsi_tpg_param_AuthMethod.attr, 1332e48354ceSNicholas Bellinger &iscsi_tpg_param_HeaderDigest.attr, 1333e48354ceSNicholas Bellinger &iscsi_tpg_param_DataDigest.attr, 1334e48354ceSNicholas Bellinger &iscsi_tpg_param_MaxConnections.attr, 1335e48354ceSNicholas Bellinger &iscsi_tpg_param_TargetAlias.attr, 1336e48354ceSNicholas Bellinger &iscsi_tpg_param_InitialR2T.attr, 1337e48354ceSNicholas Bellinger &iscsi_tpg_param_ImmediateData.attr, 1338e48354ceSNicholas Bellinger &iscsi_tpg_param_MaxRecvDataSegmentLength.attr, 1339e004cb25SNicholas Bellinger &iscsi_tpg_param_MaxXmitDataSegmentLength.attr, 1340e48354ceSNicholas Bellinger &iscsi_tpg_param_MaxBurstLength.attr, 1341e48354ceSNicholas Bellinger &iscsi_tpg_param_FirstBurstLength.attr, 1342e48354ceSNicholas Bellinger &iscsi_tpg_param_DefaultTime2Wait.attr, 1343e48354ceSNicholas Bellinger &iscsi_tpg_param_DefaultTime2Retain.attr, 1344e48354ceSNicholas Bellinger &iscsi_tpg_param_MaxOutstandingR2T.attr, 1345e48354ceSNicholas Bellinger &iscsi_tpg_param_DataPDUInOrder.attr, 1346e48354ceSNicholas Bellinger &iscsi_tpg_param_DataSequenceInOrder.attr, 1347e48354ceSNicholas Bellinger &iscsi_tpg_param_ErrorRecoveryLevel.attr, 1348e48354ceSNicholas Bellinger &iscsi_tpg_param_IFMarker.attr, 1349e48354ceSNicholas Bellinger &iscsi_tpg_param_OFMarker.attr, 1350e48354ceSNicholas Bellinger &iscsi_tpg_param_IFMarkInt.attr, 1351e48354ceSNicholas Bellinger &iscsi_tpg_param_OFMarkInt.attr, 1352e48354ceSNicholas Bellinger NULL, 1353e48354ceSNicholas Bellinger }; 1354e48354ceSNicholas Bellinger 1355e48354ceSNicholas Bellinger /* End items for lio_target_tpg_param_cit */ 1356e48354ceSNicholas Bellinger 1357e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_cit */ 1358e48354ceSNicholas Bellinger 1359e48354ceSNicholas Bellinger static ssize_t lio_target_tpg_show_enable( 1360e48354ceSNicholas Bellinger struct se_portal_group *se_tpg, 1361e48354ceSNicholas Bellinger char *page) 1362e48354ceSNicholas Bellinger { 1363e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, 1364e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); 1365e48354ceSNicholas Bellinger ssize_t len; 1366e48354ceSNicholas Bellinger 1367e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_state_lock); 1368e48354ceSNicholas Bellinger len = sprintf(page, "%d\n", 1369e48354ceSNicholas Bellinger (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0); 1370e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_state_lock); 1371e48354ceSNicholas Bellinger 1372e48354ceSNicholas Bellinger return len; 1373e48354ceSNicholas Bellinger } 1374e48354ceSNicholas Bellinger 1375e48354ceSNicholas Bellinger static ssize_t lio_target_tpg_store_enable( 1376e48354ceSNicholas Bellinger struct se_portal_group *se_tpg, 1377e48354ceSNicholas Bellinger const char *page, 1378e48354ceSNicholas Bellinger size_t count) 1379e48354ceSNicholas Bellinger { 1380e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, 1381e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); 1382e48354ceSNicholas Bellinger u32 op; 1383ad7babd2SJörn Engel int ret; 1384e48354ceSNicholas Bellinger 1385ad7babd2SJörn Engel ret = kstrtou32(page, 0, &op); 1386ad7babd2SJörn Engel if (ret) 1387ad7babd2SJörn Engel return ret; 1388e48354ceSNicholas Bellinger if ((op != 1) && (op != 0)) { 1389e48354ceSNicholas Bellinger pr_err("Illegal value for tpg_enable: %u\n", op); 1390e48354ceSNicholas Bellinger return -EINVAL; 1391e48354ceSNicholas Bellinger } 1392e48354ceSNicholas Bellinger 1393e48354ceSNicholas Bellinger ret = iscsit_get_tpg(tpg); 1394e48354ceSNicholas Bellinger if (ret < 0) 1395e48354ceSNicholas Bellinger return -EINVAL; 1396e48354ceSNicholas Bellinger 1397e48354ceSNicholas Bellinger if (op) { 1398e48354ceSNicholas Bellinger ret = iscsit_tpg_enable_portal_group(tpg); 1399e48354ceSNicholas Bellinger if (ret < 0) 1400e48354ceSNicholas Bellinger goto out; 1401e48354ceSNicholas Bellinger } else { 1402e48354ceSNicholas Bellinger /* 1403e48354ceSNicholas Bellinger * iscsit_tpg_disable_portal_group() assumes force=1 1404e48354ceSNicholas Bellinger */ 1405e48354ceSNicholas Bellinger ret = iscsit_tpg_disable_portal_group(tpg, 1); 1406e48354ceSNicholas Bellinger if (ret < 0) 1407e48354ceSNicholas Bellinger goto out; 1408e48354ceSNicholas Bellinger } 1409e48354ceSNicholas Bellinger 1410e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 1411e48354ceSNicholas Bellinger return count; 1412e48354ceSNicholas Bellinger out: 1413e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 1414e48354ceSNicholas Bellinger return -EINVAL; 1415e48354ceSNicholas Bellinger } 1416e48354ceSNicholas Bellinger 1417e48354ceSNicholas Bellinger TF_TPG_BASE_ATTR(lio_target, enable, S_IRUGO | S_IWUSR); 1418e48354ceSNicholas Bellinger 1419d4ee46ffSNicholas Bellinger static ssize_t lio_target_tpg_show_dynamic_sessions( 1420d4ee46ffSNicholas Bellinger struct se_portal_group *se_tpg, 1421d4ee46ffSNicholas Bellinger char *page) 1422d4ee46ffSNicholas Bellinger { 1423d4ee46ffSNicholas Bellinger return target_show_dynamic_sessions(se_tpg, page); 1424d4ee46ffSNicholas Bellinger } 1425d4ee46ffSNicholas Bellinger 1426d4ee46ffSNicholas Bellinger TF_TPG_BASE_ATTR_RO(lio_target, dynamic_sessions); 1427d4ee46ffSNicholas Bellinger 1428e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_attrs[] = { 1429e48354ceSNicholas Bellinger &lio_target_tpg_enable.attr, 1430d4ee46ffSNicholas Bellinger &lio_target_tpg_dynamic_sessions.attr, 1431e48354ceSNicholas Bellinger NULL, 1432e48354ceSNicholas Bellinger }; 1433e48354ceSNicholas Bellinger 1434e48354ceSNicholas Bellinger /* End items for lio_target_tpg_cit */ 1435e48354ceSNicholas Bellinger 1436e48354ceSNicholas Bellinger /* Start items for lio_target_tiqn_cit */ 1437e48354ceSNicholas Bellinger 1438fceb5bc7SChristoph Hellwig static struct se_portal_group *lio_target_tiqn_addtpg( 1439e48354ceSNicholas Bellinger struct se_wwn *wwn, 1440e48354ceSNicholas Bellinger struct config_group *group, 1441e48354ceSNicholas Bellinger const char *name) 1442e48354ceSNicholas Bellinger { 1443e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 1444e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn; 1445ad7babd2SJörn Engel char *tpgt_str; 1446ad7babd2SJörn Engel int ret; 1447ad7babd2SJörn Engel u16 tpgt; 1448e48354ceSNicholas Bellinger 1449e48354ceSNicholas Bellinger tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); 1450e48354ceSNicholas Bellinger /* 1451e48354ceSNicholas Bellinger * Only tpgt_# directory groups can be created below 1452e48354ceSNicholas Bellinger * target/iscsi/iqn.superturodiskarry/ 1453e48354ceSNicholas Bellinger */ 1454e48354ceSNicholas Bellinger tpgt_str = strstr(name, "tpgt_"); 1455e48354ceSNicholas Bellinger if (!tpgt_str) { 1456e48354ceSNicholas Bellinger pr_err("Unable to locate \"tpgt_#\" directory" 1457e48354ceSNicholas Bellinger " group\n"); 1458e48354ceSNicholas Bellinger return NULL; 1459e48354ceSNicholas Bellinger } 1460e48354ceSNicholas Bellinger tpgt_str += 5; /* Skip ahead of "tpgt_" */ 1461ad7babd2SJörn Engel ret = kstrtou16(tpgt_str, 0, &tpgt); 1462ad7babd2SJörn Engel if (ret) 1463ad7babd2SJörn Engel return NULL; 1464e48354ceSNicholas Bellinger 1465e48354ceSNicholas Bellinger tpg = iscsit_alloc_portal_group(tiqn, tpgt); 1466e48354ceSNicholas Bellinger if (!tpg) 1467e48354ceSNicholas Bellinger return NULL; 1468e48354ceSNicholas Bellinger 1469e48354ceSNicholas Bellinger ret = core_tpg_register( 1470e48354ceSNicholas Bellinger &lio_target_fabric_configfs->tf_ops, 14718359cf43SJörn Engel wwn, &tpg->tpg_se_tpg, tpg, 1472e48354ceSNicholas Bellinger TRANSPORT_TPG_TYPE_NORMAL); 1473e48354ceSNicholas Bellinger if (ret < 0) 1474e48354ceSNicholas Bellinger return NULL; 1475e48354ceSNicholas Bellinger 1476e48354ceSNicholas Bellinger ret = iscsit_tpg_add_portal_group(tiqn, tpg); 1477e48354ceSNicholas Bellinger if (ret != 0) 1478e48354ceSNicholas Bellinger goto out; 1479e48354ceSNicholas Bellinger 1480e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); 1481e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n", 1482e48354ceSNicholas Bellinger name); 1483e48354ceSNicholas Bellinger return &tpg->tpg_se_tpg; 1484e48354ceSNicholas Bellinger out: 1485e48354ceSNicholas Bellinger core_tpg_deregister(&tpg->tpg_se_tpg); 1486e48354ceSNicholas Bellinger kfree(tpg); 1487e48354ceSNicholas Bellinger return NULL; 1488e48354ceSNicholas Bellinger } 1489e48354ceSNicholas Bellinger 1490fceb5bc7SChristoph Hellwig static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg) 1491e48354ceSNicholas Bellinger { 1492e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 1493e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn; 1494e48354ceSNicholas Bellinger 1495e48354ceSNicholas Bellinger tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); 1496e48354ceSNicholas Bellinger tiqn = tpg->tpg_tiqn; 1497e48354ceSNicholas Bellinger /* 1498e48354ceSNicholas Bellinger * iscsit_tpg_del_portal_group() assumes force=1 1499e48354ceSNicholas Bellinger */ 1500e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n"); 1501e48354ceSNicholas Bellinger iscsit_tpg_del_portal_group(tiqn, tpg, 1); 1502e48354ceSNicholas Bellinger } 1503e48354ceSNicholas Bellinger 1504e48354ceSNicholas Bellinger /* End items for lio_target_tiqn_cit */ 1505e48354ceSNicholas Bellinger 1506e48354ceSNicholas Bellinger /* Start LIO-Target TIQN struct contig_item lio_target_cit */ 1507e48354ceSNicholas Bellinger 1508e48354ceSNicholas Bellinger static ssize_t lio_target_wwn_show_attr_lio_version( 1509e48354ceSNicholas Bellinger struct target_fabric_configfs *tf, 1510e48354ceSNicholas Bellinger char *page) 1511e48354ceSNicholas Bellinger { 15124c76251eSNicholas Bellinger return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n"); 1513e48354ceSNicholas Bellinger } 1514e48354ceSNicholas Bellinger 1515e48354ceSNicholas Bellinger TF_WWN_ATTR_RO(lio_target, lio_version); 1516e48354ceSNicholas Bellinger 1517e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_wwn_attrs[] = { 1518e48354ceSNicholas Bellinger &lio_target_wwn_lio_version.attr, 1519e48354ceSNicholas Bellinger NULL, 1520e48354ceSNicholas Bellinger }; 1521e48354ceSNicholas Bellinger 1522fceb5bc7SChristoph Hellwig static struct se_wwn *lio_target_call_coreaddtiqn( 1523e48354ceSNicholas Bellinger struct target_fabric_configfs *tf, 1524e48354ceSNicholas Bellinger struct config_group *group, 1525e48354ceSNicholas Bellinger const char *name) 1526e48354ceSNicholas Bellinger { 1527e48354ceSNicholas Bellinger struct config_group *stats_cg; 1528e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn; 1529e48354ceSNicholas Bellinger 1530e48354ceSNicholas Bellinger tiqn = iscsit_add_tiqn((unsigned char *)name); 1531e48354ceSNicholas Bellinger if (IS_ERR(tiqn)) 1532e1750ba2SThomas Meyer return ERR_CAST(tiqn); 1533e48354ceSNicholas Bellinger /* 1534e48354ceSNicholas Bellinger * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group. 1535e48354ceSNicholas Bellinger */ 1536e48354ceSNicholas Bellinger stats_cg = &tiqn->tiqn_wwn.fabric_stat_group; 1537e48354ceSNicholas Bellinger 153813f6a914SSebastian Andrzej Siewior stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6, 1539e48354ceSNicholas Bellinger GFP_KERNEL); 1540e48354ceSNicholas Bellinger if (!stats_cg->default_groups) { 1541e48354ceSNicholas Bellinger pr_err("Unable to allocate memory for" 1542e48354ceSNicholas Bellinger " stats_cg->default_groups\n"); 1543e48354ceSNicholas Bellinger iscsit_del_tiqn(tiqn); 1544e48354ceSNicholas Bellinger return ERR_PTR(-ENOMEM); 1545e48354ceSNicholas Bellinger } 1546e48354ceSNicholas Bellinger 1547b7eec2cdSAndy Grover stats_cg->default_groups[0] = &tiqn->tiqn_stat_grps.iscsi_instance_group; 1548b7eec2cdSAndy Grover stats_cg->default_groups[1] = &tiqn->tiqn_stat_grps.iscsi_sess_err_group; 1549b7eec2cdSAndy Grover stats_cg->default_groups[2] = &tiqn->tiqn_stat_grps.iscsi_tgt_attr_group; 1550b7eec2cdSAndy Grover stats_cg->default_groups[3] = &tiqn->tiqn_stat_grps.iscsi_login_stats_group; 1551b7eec2cdSAndy Grover stats_cg->default_groups[4] = &tiqn->tiqn_stat_grps.iscsi_logout_stats_group; 1552e48354ceSNicholas Bellinger stats_cg->default_groups[5] = NULL; 1553b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group, 1554e48354ceSNicholas Bellinger "iscsi_instance", &iscsi_stat_instance_cit); 1555b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group, 1556e48354ceSNicholas Bellinger "iscsi_sess_err", &iscsi_stat_sess_err_cit); 1557b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group, 1558e48354ceSNicholas Bellinger "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit); 1559b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group, 1560e48354ceSNicholas Bellinger "iscsi_login_stats", &iscsi_stat_login_cit); 1561b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group, 1562e48354ceSNicholas Bellinger "iscsi_logout_stats", &iscsi_stat_logout_cit); 1563e48354ceSNicholas Bellinger 1564e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); 1565e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:" 1566e48354ceSNicholas Bellinger " %s\n", name); 1567e48354ceSNicholas Bellinger return &tiqn->tiqn_wwn; 1568e48354ceSNicholas Bellinger } 1569e48354ceSNicholas Bellinger 1570fceb5bc7SChristoph Hellwig static void lio_target_call_coredeltiqn( 1571e48354ceSNicholas Bellinger struct se_wwn *wwn) 1572e48354ceSNicholas Bellinger { 1573e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); 1574e48354ceSNicholas Bellinger struct config_item *df_item; 1575e48354ceSNicholas Bellinger struct config_group *stats_cg; 1576e48354ceSNicholas Bellinger int i; 1577e48354ceSNicholas Bellinger 1578e48354ceSNicholas Bellinger stats_cg = &tiqn->tiqn_wwn.fabric_stat_group; 1579e48354ceSNicholas Bellinger for (i = 0; stats_cg->default_groups[i]; i++) { 1580e48354ceSNicholas Bellinger df_item = &stats_cg->default_groups[i]->cg_item; 1581e48354ceSNicholas Bellinger stats_cg->default_groups[i] = NULL; 1582e48354ceSNicholas Bellinger config_item_put(df_item); 1583e48354ceSNicholas Bellinger } 1584e48354ceSNicholas Bellinger kfree(stats_cg->default_groups); 1585e48354ceSNicholas Bellinger 1586e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n", 1587e48354ceSNicholas Bellinger tiqn->tiqn); 1588e48354ceSNicholas Bellinger iscsit_del_tiqn(tiqn); 1589e48354ceSNicholas Bellinger } 1590e48354ceSNicholas Bellinger 1591e48354ceSNicholas Bellinger /* End LIO-Target TIQN struct contig_lio_target_cit */ 1592e48354ceSNicholas Bellinger 1593e48354ceSNicholas Bellinger /* Start lio_target_discovery_auth_cit */ 1594e48354ceSNicholas Bellinger 1595e48354ceSNicholas Bellinger #define DEF_DISC_AUTH_STR(name, flags) \ 1596e48354ceSNicholas Bellinger __DEF_NACL_AUTH_STR(disc, name, flags) \ 1597e48354ceSNicholas Bellinger static ssize_t iscsi_disc_show_##name( \ 1598e48354ceSNicholas Bellinger struct target_fabric_configfs *tf, \ 1599e48354ceSNicholas Bellinger char *page) \ 1600e48354ceSNicholas Bellinger { \ 1601e48354ceSNicholas Bellinger return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \ 1602e48354ceSNicholas Bellinger page); \ 1603e48354ceSNicholas Bellinger } \ 1604e48354ceSNicholas Bellinger static ssize_t iscsi_disc_store_##name( \ 1605e48354ceSNicholas Bellinger struct target_fabric_configfs *tf, \ 1606e48354ceSNicholas Bellinger const char *page, \ 1607e48354ceSNicholas Bellinger size_t count) \ 1608e48354ceSNicholas Bellinger { \ 1609e48354ceSNicholas Bellinger return __iscsi_disc_store_##name(&iscsit_global->discovery_acl, \ 1610e48354ceSNicholas Bellinger page, count); \ 1611e48354ceSNicholas Bellinger } 1612e48354ceSNicholas Bellinger 1613e48354ceSNicholas Bellinger #define DEF_DISC_AUTH_INT(name) \ 1614e48354ceSNicholas Bellinger __DEF_NACL_AUTH_INT(disc, name) \ 1615e48354ceSNicholas Bellinger static ssize_t iscsi_disc_show_##name( \ 1616e48354ceSNicholas Bellinger struct target_fabric_configfs *tf, \ 1617e48354ceSNicholas Bellinger char *page) \ 1618e48354ceSNicholas Bellinger { \ 1619e48354ceSNicholas Bellinger return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \ 1620e48354ceSNicholas Bellinger page); \ 1621e48354ceSNicholas Bellinger } 1622e48354ceSNicholas Bellinger 1623e48354ceSNicholas Bellinger #define DISC_AUTH_ATTR(_name, _mode) TF_DISC_ATTR(iscsi, _name, _mode) 1624e48354ceSNicholas Bellinger #define DISC_AUTH_ATTR_RO(_name) TF_DISC_ATTR_RO(iscsi, _name) 1625e48354ceSNicholas Bellinger 1626e48354ceSNicholas Bellinger /* 1627e48354ceSNicholas Bellinger * One-way authentication userid 1628e48354ceSNicholas Bellinger */ 1629e48354ceSNicholas Bellinger DEF_DISC_AUTH_STR(userid, NAF_USERID_SET); 1630e48354ceSNicholas Bellinger DISC_AUTH_ATTR(userid, S_IRUGO | S_IWUSR); 1631e48354ceSNicholas Bellinger /* 1632e48354ceSNicholas Bellinger * One-way authentication password 1633e48354ceSNicholas Bellinger */ 1634e48354ceSNicholas Bellinger DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET); 1635e48354ceSNicholas Bellinger DISC_AUTH_ATTR(password, S_IRUGO | S_IWUSR); 1636e48354ceSNicholas Bellinger /* 1637e48354ceSNicholas Bellinger * Enforce mutual authentication 1638e48354ceSNicholas Bellinger */ 1639e48354ceSNicholas Bellinger DEF_DISC_AUTH_INT(authenticate_target); 1640e48354ceSNicholas Bellinger DISC_AUTH_ATTR_RO(authenticate_target); 1641e48354ceSNicholas Bellinger /* 1642e48354ceSNicholas Bellinger * Mutual authentication userid 1643e48354ceSNicholas Bellinger */ 1644e48354ceSNicholas Bellinger DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); 1645e48354ceSNicholas Bellinger DISC_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR); 1646e48354ceSNicholas Bellinger /* 1647e48354ceSNicholas Bellinger * Mutual authentication password 1648e48354ceSNicholas Bellinger */ 1649e48354ceSNicholas Bellinger DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); 1650e48354ceSNicholas Bellinger DISC_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR); 1651e48354ceSNicholas Bellinger 1652e48354ceSNicholas Bellinger /* 1653e48354ceSNicholas Bellinger * enforce_discovery_auth 1654e48354ceSNicholas Bellinger */ 1655e48354ceSNicholas Bellinger static ssize_t iscsi_disc_show_enforce_discovery_auth( 1656e48354ceSNicholas Bellinger struct target_fabric_configfs *tf, 1657e48354ceSNicholas Bellinger char *page) 1658e48354ceSNicholas Bellinger { 1659e48354ceSNicholas Bellinger struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth; 1660e48354ceSNicholas Bellinger 1661e48354ceSNicholas Bellinger return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth); 1662e48354ceSNicholas Bellinger } 1663e48354ceSNicholas Bellinger 1664e48354ceSNicholas Bellinger static ssize_t iscsi_disc_store_enforce_discovery_auth( 1665e48354ceSNicholas Bellinger struct target_fabric_configfs *tf, 1666e48354ceSNicholas Bellinger const char *page, 1667e48354ceSNicholas Bellinger size_t count) 1668e48354ceSNicholas Bellinger { 1669e48354ceSNicholas Bellinger struct iscsi_param *param; 1670e48354ceSNicholas Bellinger struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg; 1671e48354ceSNicholas Bellinger u32 op; 1672ad7babd2SJörn Engel int err; 1673e48354ceSNicholas Bellinger 1674ad7babd2SJörn Engel err = kstrtou32(page, 0, &op); 1675ad7babd2SJörn Engel if (err) 1676ad7babd2SJörn Engel return -EINVAL; 1677e48354ceSNicholas Bellinger if ((op != 1) && (op != 0)) { 1678e48354ceSNicholas Bellinger pr_err("Illegal value for enforce_discovery_auth:" 1679e48354ceSNicholas Bellinger " %u\n", op); 1680e48354ceSNicholas Bellinger return -EINVAL; 1681e48354ceSNicholas Bellinger } 1682e48354ceSNicholas Bellinger 1683e48354ceSNicholas Bellinger if (!discovery_tpg) { 1684e48354ceSNicholas Bellinger pr_err("iscsit_global->discovery_tpg is NULL\n"); 1685e48354ceSNicholas Bellinger return -EINVAL; 1686e48354ceSNicholas Bellinger } 1687e48354ceSNicholas Bellinger 1688e48354ceSNicholas Bellinger param = iscsi_find_param_from_key(AUTHMETHOD, 1689e48354ceSNicholas Bellinger discovery_tpg->param_list); 1690e48354ceSNicholas Bellinger if (!param) 1691e48354ceSNicholas Bellinger return -EINVAL; 1692e48354ceSNicholas Bellinger 1693e48354ceSNicholas Bellinger if (op) { 1694e48354ceSNicholas Bellinger /* 1695e48354ceSNicholas Bellinger * Reset the AuthMethod key to CHAP. 1696e48354ceSNicholas Bellinger */ 1697e48354ceSNicholas Bellinger if (iscsi_update_param_value(param, CHAP) < 0) 1698e48354ceSNicholas Bellinger return -EINVAL; 1699e48354ceSNicholas Bellinger 1700e48354ceSNicholas Bellinger discovery_tpg->tpg_attrib.authentication = 1; 1701e48354ceSNicholas Bellinger iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1; 1702e48354ceSNicholas Bellinger pr_debug("LIO-CORE[0] Successfully enabled" 1703e48354ceSNicholas Bellinger " authentication enforcement for iSCSI" 1704e48354ceSNicholas Bellinger " Discovery TPG\n"); 1705e48354ceSNicholas Bellinger } else { 1706e48354ceSNicholas Bellinger /* 1707e48354ceSNicholas Bellinger * Reset the AuthMethod key to CHAP,None 1708e48354ceSNicholas Bellinger */ 1709e48354ceSNicholas Bellinger if (iscsi_update_param_value(param, "CHAP,None") < 0) 1710e48354ceSNicholas Bellinger return -EINVAL; 1711e48354ceSNicholas Bellinger 1712e48354ceSNicholas Bellinger discovery_tpg->tpg_attrib.authentication = 0; 1713e48354ceSNicholas Bellinger iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0; 1714e48354ceSNicholas Bellinger pr_debug("LIO-CORE[0] Successfully disabled" 1715e48354ceSNicholas Bellinger " authentication enforcement for iSCSI" 1716e48354ceSNicholas Bellinger " Discovery TPG\n"); 1717e48354ceSNicholas Bellinger } 1718e48354ceSNicholas Bellinger 1719e48354ceSNicholas Bellinger return count; 1720e48354ceSNicholas Bellinger } 1721e48354ceSNicholas Bellinger 1722e48354ceSNicholas Bellinger DISC_AUTH_ATTR(enforce_discovery_auth, S_IRUGO | S_IWUSR); 1723e48354ceSNicholas Bellinger 1724e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_discovery_auth_attrs[] = { 1725e48354ceSNicholas Bellinger &iscsi_disc_userid.attr, 1726e48354ceSNicholas Bellinger &iscsi_disc_password.attr, 1727e48354ceSNicholas Bellinger &iscsi_disc_authenticate_target.attr, 1728e48354ceSNicholas Bellinger &iscsi_disc_userid_mutual.attr, 1729e48354ceSNicholas Bellinger &iscsi_disc_password_mutual.attr, 1730e48354ceSNicholas Bellinger &iscsi_disc_enforce_discovery_auth.attr, 1731e48354ceSNicholas Bellinger NULL, 1732e48354ceSNicholas Bellinger }; 1733e48354ceSNicholas Bellinger 1734e48354ceSNicholas Bellinger /* End lio_target_discovery_auth_cit */ 1735e48354ceSNicholas Bellinger 1736e48354ceSNicholas Bellinger /* Start functions for target_core_fabric_ops */ 1737e48354ceSNicholas Bellinger 1738e48354ceSNicholas Bellinger static char *iscsi_get_fabric_name(void) 1739e48354ceSNicholas Bellinger { 1740e48354ceSNicholas Bellinger return "iSCSI"; 1741e48354ceSNicholas Bellinger } 1742e48354ceSNicholas Bellinger 1743e48354ceSNicholas Bellinger static u32 iscsi_get_task_tag(struct se_cmd *se_cmd) 1744e48354ceSNicholas Bellinger { 1745e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1746e48354ceSNicholas Bellinger 174766c7db68SChristoph Hellwig /* only used for printks or comparism with ->ref_task_tag */ 174866c7db68SChristoph Hellwig return (__force u32)cmd->init_task_tag; 1749e48354ceSNicholas Bellinger } 1750e48354ceSNicholas Bellinger 1751e48354ceSNicholas Bellinger static int iscsi_get_cmd_state(struct se_cmd *se_cmd) 1752e48354ceSNicholas Bellinger { 1753e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1754e48354ceSNicholas Bellinger 1755e48354ceSNicholas Bellinger return cmd->i_state; 1756e48354ceSNicholas Bellinger } 1757e48354ceSNicholas Bellinger 1758e48354ceSNicholas Bellinger static u32 lio_sess_get_index(struct se_session *se_sess) 1759e48354ceSNicholas Bellinger { 1760e48354ceSNicholas Bellinger struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1761e48354ceSNicholas Bellinger 1762e48354ceSNicholas Bellinger return sess->session_index; 1763e48354ceSNicholas Bellinger } 1764e48354ceSNicholas Bellinger 1765e48354ceSNicholas Bellinger static u32 lio_sess_get_initiator_sid( 1766e48354ceSNicholas Bellinger struct se_session *se_sess, 1767e48354ceSNicholas Bellinger unsigned char *buf, 1768e48354ceSNicholas Bellinger u32 size) 1769e48354ceSNicholas Bellinger { 1770e48354ceSNicholas Bellinger struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1771e48354ceSNicholas Bellinger /* 1772e48354ceSNicholas Bellinger * iSCSI Initiator Session Identifier from RFC-3720. 1773e48354ceSNicholas Bellinger */ 17745cdf5a87SAndy Shevchenko return snprintf(buf, size, "%6phN", sess->isid); 1775e48354ceSNicholas Bellinger } 1776e48354ceSNicholas Bellinger 1777e48354ceSNicholas Bellinger static int lio_queue_data_in(struct se_cmd *se_cmd) 1778e48354ceSNicholas Bellinger { 1779e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1780e48354ceSNicholas Bellinger 1781e48354ceSNicholas Bellinger cmd->i_state = ISTATE_SEND_DATAIN; 17822ec5a8c1SNicholas Bellinger cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd); 17832ec5a8c1SNicholas Bellinger 1784e48354ceSNicholas Bellinger return 0; 1785e48354ceSNicholas Bellinger } 1786e48354ceSNicholas Bellinger 1787e48354ceSNicholas Bellinger static int lio_write_pending(struct se_cmd *se_cmd) 1788e48354ceSNicholas Bellinger { 1789e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 17903e1c81a9SNicholas Bellinger struct iscsi_conn *conn = cmd->conn; 1791e48354ceSNicholas Bellinger 1792e48354ceSNicholas Bellinger if (!cmd->immediate_data && !cmd->unsolicited_data) 17933e1c81a9SNicholas Bellinger return conn->conn_transport->iscsit_get_dataout(conn, cmd, false); 1794e48354ceSNicholas Bellinger 1795e48354ceSNicholas Bellinger return 0; 1796e48354ceSNicholas Bellinger } 1797e48354ceSNicholas Bellinger 1798e48354ceSNicholas Bellinger static int lio_write_pending_status(struct se_cmd *se_cmd) 1799e48354ceSNicholas Bellinger { 1800e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1801e48354ceSNicholas Bellinger int ret; 1802e48354ceSNicholas Bellinger 1803e48354ceSNicholas Bellinger spin_lock_bh(&cmd->istate_lock); 1804e48354ceSNicholas Bellinger ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT); 1805e48354ceSNicholas Bellinger spin_unlock_bh(&cmd->istate_lock); 1806e48354ceSNicholas Bellinger 1807e48354ceSNicholas Bellinger return ret; 1808e48354ceSNicholas Bellinger } 1809e48354ceSNicholas Bellinger 1810e48354ceSNicholas Bellinger static int lio_queue_status(struct se_cmd *se_cmd) 1811e48354ceSNicholas Bellinger { 1812e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1813e48354ceSNicholas Bellinger 1814e48354ceSNicholas Bellinger cmd->i_state = ISTATE_SEND_STATUS; 18155e8e6b4bSNicholas Bellinger 18165e8e6b4bSNicholas Bellinger if (cmd->se_cmd.scsi_status || cmd->sense_reason) { 18175e8e6b4bSNicholas Bellinger iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state); 18185e8e6b4bSNicholas Bellinger return 0; 18195e8e6b4bSNicholas Bellinger } 18202ec5a8c1SNicholas Bellinger cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd); 18212ec5a8c1SNicholas Bellinger 1822e48354ceSNicholas Bellinger return 0; 1823e48354ceSNicholas Bellinger } 1824e48354ceSNicholas Bellinger 1825b79fafacSJoern Engel static void lio_queue_tm_rsp(struct se_cmd *se_cmd) 1826e48354ceSNicholas Bellinger { 1827e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1828e48354ceSNicholas Bellinger 1829e48354ceSNicholas Bellinger cmd->i_state = ISTATE_SEND_TASKMGTRSP; 1830e48354ceSNicholas Bellinger iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state); 1831e48354ceSNicholas Bellinger } 1832e48354ceSNicholas Bellinger 1833131e6abcSNicholas Bellinger static void lio_aborted_task(struct se_cmd *se_cmd) 1834131e6abcSNicholas Bellinger { 1835131e6abcSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1836131e6abcSNicholas Bellinger 1837131e6abcSNicholas Bellinger cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd); 1838131e6abcSNicholas Bellinger } 1839131e6abcSNicholas Bellinger 1840e48354ceSNicholas Bellinger static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg) 1841e48354ceSNicholas Bellinger { 1842e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1843e48354ceSNicholas Bellinger 1844e48354ceSNicholas Bellinger return &tpg->tpg_tiqn->tiqn[0]; 1845e48354ceSNicholas Bellinger } 1846e48354ceSNicholas Bellinger 1847e48354ceSNicholas Bellinger static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg) 1848e48354ceSNicholas Bellinger { 1849e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1850e48354ceSNicholas Bellinger 1851e48354ceSNicholas Bellinger return tpg->tpgt; 1852e48354ceSNicholas Bellinger } 1853e48354ceSNicholas Bellinger 1854e48354ceSNicholas Bellinger static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg) 1855e48354ceSNicholas Bellinger { 1856e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1857e48354ceSNicholas Bellinger 1858b7eec2cdSAndy Grover return tpg->tpg_attrib.default_cmdsn_depth; 1859e48354ceSNicholas Bellinger } 1860e48354ceSNicholas Bellinger 1861e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg) 1862e48354ceSNicholas Bellinger { 1863e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1864e48354ceSNicholas Bellinger 1865b7eec2cdSAndy Grover return tpg->tpg_attrib.generate_node_acls; 1866e48354ceSNicholas Bellinger } 1867e48354ceSNicholas Bellinger 1868e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg) 1869e48354ceSNicholas Bellinger { 1870e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1871e48354ceSNicholas Bellinger 1872b7eec2cdSAndy Grover return tpg->tpg_attrib.cache_dynamic_acls; 1873e48354ceSNicholas Bellinger } 1874e48354ceSNicholas Bellinger 1875e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode_write_protect( 1876e48354ceSNicholas Bellinger struct se_portal_group *se_tpg) 1877e48354ceSNicholas Bellinger { 1878e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1879e48354ceSNicholas Bellinger 1880b7eec2cdSAndy Grover return tpg->tpg_attrib.demo_mode_write_protect; 1881e48354ceSNicholas Bellinger } 1882e48354ceSNicholas Bellinger 1883e48354ceSNicholas Bellinger static int lio_tpg_check_prod_mode_write_protect( 1884e48354ceSNicholas Bellinger struct se_portal_group *se_tpg) 1885e48354ceSNicholas Bellinger { 1886e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1887e48354ceSNicholas Bellinger 1888b7eec2cdSAndy Grover return tpg->tpg_attrib.prod_mode_write_protect; 1889e48354ceSNicholas Bellinger } 1890e48354ceSNicholas Bellinger 1891901c04a3SNicholas Bellinger static int lio_tpg_check_prot_fabric_only( 1892901c04a3SNicholas Bellinger struct se_portal_group *se_tpg) 1893901c04a3SNicholas Bellinger { 1894901c04a3SNicholas Bellinger struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1895901c04a3SNicholas Bellinger /* 1896901c04a3SNicholas Bellinger * Only report fabric_prot_type if t10_pi has also been enabled 1897901c04a3SNicholas Bellinger * for incoming ib_isert sessions. 1898901c04a3SNicholas Bellinger */ 1899901c04a3SNicholas Bellinger if (!tpg->tpg_attrib.t10_pi) 1900901c04a3SNicholas Bellinger return 0; 1901901c04a3SNicholas Bellinger 1902901c04a3SNicholas Bellinger return tpg->tpg_attrib.fabric_prot_type; 1903901c04a3SNicholas Bellinger } 1904901c04a3SNicholas Bellinger 1905e48354ceSNicholas Bellinger static void lio_tpg_release_fabric_acl( 1906e48354ceSNicholas Bellinger struct se_portal_group *se_tpg, 1907e48354ceSNicholas Bellinger struct se_node_acl *se_acl) 1908e48354ceSNicholas Bellinger { 1909e48354ceSNicholas Bellinger struct iscsi_node_acl *acl = container_of(se_acl, 1910e48354ceSNicholas Bellinger struct iscsi_node_acl, se_node_acl); 1911e48354ceSNicholas Bellinger kfree(acl); 1912e48354ceSNicholas Bellinger } 1913e48354ceSNicholas Bellinger 1914e48354ceSNicholas Bellinger /* 1915e48354ceSNicholas Bellinger * Called with spin_lock_bh(struct se_portal_group->session_lock) held.. 1916e48354ceSNicholas Bellinger * 1917e48354ceSNicholas Bellinger * Also, this function calls iscsit_inc_session_usage_count() on the 1918e48354ceSNicholas Bellinger * struct iscsi_session in question. 1919e48354ceSNicholas Bellinger */ 1920e48354ceSNicholas Bellinger static int lio_tpg_shutdown_session(struct se_session *se_sess) 1921e48354ceSNicholas Bellinger { 1922e48354ceSNicholas Bellinger struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1923e48354ceSNicholas Bellinger 1924e48354ceSNicholas Bellinger spin_lock(&sess->conn_lock); 1925e48354ceSNicholas Bellinger if (atomic_read(&sess->session_fall_back_to_erl0) || 1926e48354ceSNicholas Bellinger atomic_read(&sess->session_logout) || 1927e48354ceSNicholas Bellinger (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) { 1928e48354ceSNicholas Bellinger spin_unlock(&sess->conn_lock); 1929e48354ceSNicholas Bellinger return 0; 1930e48354ceSNicholas Bellinger } 1931e48354ceSNicholas Bellinger atomic_set(&sess->session_reinstatement, 1); 1932e48354ceSNicholas Bellinger spin_unlock(&sess->conn_lock); 1933e48354ceSNicholas Bellinger 1934e48354ceSNicholas Bellinger iscsit_stop_time2retain_timer(sess); 193599367f01SNicholas Bellinger iscsit_stop_session(sess, 1, 1); 1936e48354ceSNicholas Bellinger 1937e48354ceSNicholas Bellinger return 1; 1938e48354ceSNicholas Bellinger } 1939e48354ceSNicholas Bellinger 1940e48354ceSNicholas Bellinger /* 1941e48354ceSNicholas Bellinger * Calls iscsit_dec_session_usage_count() as inverse of 1942e48354ceSNicholas Bellinger * lio_tpg_shutdown_session() 1943e48354ceSNicholas Bellinger */ 1944e48354ceSNicholas Bellinger static void lio_tpg_close_session(struct se_session *se_sess) 1945e48354ceSNicholas Bellinger { 1946e48354ceSNicholas Bellinger struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1947e48354ceSNicholas Bellinger /* 1948e48354ceSNicholas Bellinger * If the iSCSI Session for the iSCSI Initiator Node exists, 1949e48354ceSNicholas Bellinger * forcefully shutdown the iSCSI NEXUS. 1950e48354ceSNicholas Bellinger */ 1951e48354ceSNicholas Bellinger iscsit_close_session(sess); 1952e48354ceSNicholas Bellinger } 1953e48354ceSNicholas Bellinger 1954e48354ceSNicholas Bellinger static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg) 1955e48354ceSNicholas Bellinger { 1956e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1957e48354ceSNicholas Bellinger 1958e48354ceSNicholas Bellinger return tpg->tpg_tiqn->tiqn_index; 1959e48354ceSNicholas Bellinger } 1960e48354ceSNicholas Bellinger 1961e48354ceSNicholas Bellinger static void lio_set_default_node_attributes(struct se_node_acl *se_acl) 1962e48354ceSNicholas Bellinger { 1963e48354ceSNicholas Bellinger struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl, 1964e48354ceSNicholas Bellinger se_node_acl); 1965d1fa7a1dSNicholas Bellinger struct se_portal_group *se_tpg = se_acl->se_tpg; 1966d1fa7a1dSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, 1967d1fa7a1dSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); 1968e48354ceSNicholas Bellinger 1969b7eec2cdSAndy Grover acl->node_attrib.nacl = acl; 1970d1fa7a1dSNicholas Bellinger iscsit_set_default_node_attribues(acl, tpg); 1971e48354ceSNicholas Bellinger } 1972e48354ceSNicholas Bellinger 19733e1c81a9SNicholas Bellinger static int lio_check_stop_free(struct se_cmd *se_cmd) 19743e1c81a9SNicholas Bellinger { 19753e1c81a9SNicholas Bellinger return target_put_sess_cmd(se_cmd->se_sess, se_cmd); 19763e1c81a9SNicholas Bellinger } 19773e1c81a9SNicholas Bellinger 1978e48354ceSNicholas Bellinger static void lio_release_cmd(struct se_cmd *se_cmd) 1979e48354ceSNicholas Bellinger { 1980e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1981e48354ceSNicholas Bellinger 1982cdb72665SNicholas Bellinger pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd); 1983d703ce2fSNicholas Bellinger iscsit_release_cmd(cmd); 1984e48354ceSNicholas Bellinger } 1985e48354ceSNicholas Bellinger 1986e48354ceSNicholas Bellinger /* End functions for target_core_fabric_ops */ 1987e48354ceSNicholas Bellinger 1988e48354ceSNicholas Bellinger int iscsi_target_register_configfs(void) 1989e48354ceSNicholas Bellinger { 1990e48354ceSNicholas Bellinger struct target_fabric_configfs *fabric; 1991e48354ceSNicholas Bellinger int ret; 1992e48354ceSNicholas Bellinger 1993e48354ceSNicholas Bellinger lio_target_fabric_configfs = NULL; 1994e48354ceSNicholas Bellinger fabric = target_fabric_configfs_init(THIS_MODULE, "iscsi"); 1995e48354ceSNicholas Bellinger if (IS_ERR(fabric)) { 1996e48354ceSNicholas Bellinger pr_err("target_fabric_configfs_init() for" 1997e48354ceSNicholas Bellinger " LIO-Target failed!\n"); 1998e48354ceSNicholas Bellinger return PTR_ERR(fabric); 1999e48354ceSNicholas Bellinger } 2000e48354ceSNicholas Bellinger /* 2001e48354ceSNicholas Bellinger * Setup the fabric API of function pointers used by target_core_mod.. 2002e48354ceSNicholas Bellinger */ 2003e48354ceSNicholas Bellinger fabric->tf_ops.get_fabric_name = &iscsi_get_fabric_name; 2004e48354ceSNicholas Bellinger fabric->tf_ops.get_fabric_proto_ident = &iscsi_get_fabric_proto_ident; 2005e48354ceSNicholas Bellinger fabric->tf_ops.tpg_get_wwn = &lio_tpg_get_endpoint_wwn; 2006e48354ceSNicholas Bellinger fabric->tf_ops.tpg_get_tag = &lio_tpg_get_tag; 2007e48354ceSNicholas Bellinger fabric->tf_ops.tpg_get_default_depth = &lio_tpg_get_default_depth; 2008e48354ceSNicholas Bellinger fabric->tf_ops.tpg_get_pr_transport_id = &iscsi_get_pr_transport_id; 2009e48354ceSNicholas Bellinger fabric->tf_ops.tpg_get_pr_transport_id_len = 2010e48354ceSNicholas Bellinger &iscsi_get_pr_transport_id_len; 2011e48354ceSNicholas Bellinger fabric->tf_ops.tpg_parse_pr_out_transport_id = 2012e48354ceSNicholas Bellinger &iscsi_parse_pr_out_transport_id; 2013e48354ceSNicholas Bellinger fabric->tf_ops.tpg_check_demo_mode = &lio_tpg_check_demo_mode; 2014e48354ceSNicholas Bellinger fabric->tf_ops.tpg_check_demo_mode_cache = 2015e48354ceSNicholas Bellinger &lio_tpg_check_demo_mode_cache; 2016e48354ceSNicholas Bellinger fabric->tf_ops.tpg_check_demo_mode_write_protect = 2017e48354ceSNicholas Bellinger &lio_tpg_check_demo_mode_write_protect; 2018e48354ceSNicholas Bellinger fabric->tf_ops.tpg_check_prod_mode_write_protect = 2019e48354ceSNicholas Bellinger &lio_tpg_check_prod_mode_write_protect; 2020901c04a3SNicholas Bellinger fabric->tf_ops.tpg_check_prot_fabric_only = 2021901c04a3SNicholas Bellinger &lio_tpg_check_prot_fabric_only; 2022e48354ceSNicholas Bellinger fabric->tf_ops.tpg_alloc_fabric_acl = &lio_tpg_alloc_fabric_acl; 2023e48354ceSNicholas Bellinger fabric->tf_ops.tpg_release_fabric_acl = &lio_tpg_release_fabric_acl; 2024e48354ceSNicholas Bellinger fabric->tf_ops.tpg_get_inst_index = &lio_tpg_get_inst_index; 20253e1c81a9SNicholas Bellinger fabric->tf_ops.check_stop_free = &lio_check_stop_free, 2026e48354ceSNicholas Bellinger fabric->tf_ops.release_cmd = &lio_release_cmd; 2027e48354ceSNicholas Bellinger fabric->tf_ops.shutdown_session = &lio_tpg_shutdown_session; 2028e48354ceSNicholas Bellinger fabric->tf_ops.close_session = &lio_tpg_close_session; 2029e48354ceSNicholas Bellinger fabric->tf_ops.sess_get_index = &lio_sess_get_index; 2030e48354ceSNicholas Bellinger fabric->tf_ops.sess_get_initiator_sid = &lio_sess_get_initiator_sid; 2031e48354ceSNicholas Bellinger fabric->tf_ops.write_pending = &lio_write_pending; 2032e48354ceSNicholas Bellinger fabric->tf_ops.write_pending_status = &lio_write_pending_status; 2033e48354ceSNicholas Bellinger fabric->tf_ops.set_default_node_attributes = 2034e48354ceSNicholas Bellinger &lio_set_default_node_attributes; 2035e48354ceSNicholas Bellinger fabric->tf_ops.get_task_tag = &iscsi_get_task_tag; 2036e48354ceSNicholas Bellinger fabric->tf_ops.get_cmd_state = &iscsi_get_cmd_state; 2037e48354ceSNicholas Bellinger fabric->tf_ops.queue_data_in = &lio_queue_data_in; 2038e48354ceSNicholas Bellinger fabric->tf_ops.queue_status = &lio_queue_status; 2039e48354ceSNicholas Bellinger fabric->tf_ops.queue_tm_rsp = &lio_queue_tm_rsp; 2040131e6abcSNicholas Bellinger fabric->tf_ops.aborted_task = &lio_aborted_task; 2041e48354ceSNicholas Bellinger /* 2042e48354ceSNicholas Bellinger * Setup function pointers for generic logic in target_core_fabric_configfs.c 2043e48354ceSNicholas Bellinger */ 2044e48354ceSNicholas Bellinger fabric->tf_ops.fabric_make_wwn = &lio_target_call_coreaddtiqn; 2045e48354ceSNicholas Bellinger fabric->tf_ops.fabric_drop_wwn = &lio_target_call_coredeltiqn; 2046e48354ceSNicholas Bellinger fabric->tf_ops.fabric_make_tpg = &lio_target_tiqn_addtpg; 2047e48354ceSNicholas Bellinger fabric->tf_ops.fabric_drop_tpg = &lio_target_tiqn_deltpg; 2048e48354ceSNicholas Bellinger fabric->tf_ops.fabric_post_link = NULL; 2049e48354ceSNicholas Bellinger fabric->tf_ops.fabric_pre_unlink = NULL; 2050e48354ceSNicholas Bellinger fabric->tf_ops.fabric_make_np = &lio_target_call_addnptotpg; 2051e48354ceSNicholas Bellinger fabric->tf_ops.fabric_drop_np = &lio_target_call_delnpfromtpg; 2052e48354ceSNicholas Bellinger fabric->tf_ops.fabric_make_nodeacl = &lio_target_make_nodeacl; 2053e48354ceSNicholas Bellinger fabric->tf_ops.fabric_drop_nodeacl = &lio_target_drop_nodeacl; 2054e48354ceSNicholas Bellinger /* 2055e48354ceSNicholas Bellinger * Setup default attribute lists for various fabric->tf_cit_tmpl 2056e48354ceSNicholas Bellinger * sturct config_item_type's 2057e48354ceSNicholas Bellinger */ 2058d80e224dSAndy Grover fabric->tf_cit_tmpl.tfc_discovery_cit.ct_attrs = lio_target_discovery_auth_attrs; 2059d80e224dSAndy Grover fabric->tf_cit_tmpl.tfc_wwn_cit.ct_attrs = lio_target_wwn_attrs; 2060d80e224dSAndy Grover fabric->tf_cit_tmpl.tfc_tpg_base_cit.ct_attrs = lio_target_tpg_attrs; 2061d80e224dSAndy Grover fabric->tf_cit_tmpl.tfc_tpg_attrib_cit.ct_attrs = lio_target_tpg_attrib_attrs; 2062d80e224dSAndy Grover fabric->tf_cit_tmpl.tfc_tpg_auth_cit.ct_attrs = lio_target_tpg_auth_attrs; 2063d80e224dSAndy Grover fabric->tf_cit_tmpl.tfc_tpg_param_cit.ct_attrs = lio_target_tpg_param_attrs; 2064d80e224dSAndy Grover fabric->tf_cit_tmpl.tfc_tpg_np_base_cit.ct_attrs = lio_target_portal_attrs; 2065d80e224dSAndy Grover fabric->tf_cit_tmpl.tfc_tpg_nacl_base_cit.ct_attrs = lio_target_initiator_attrs; 2066d80e224dSAndy Grover fabric->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit.ct_attrs = lio_target_nacl_attrib_attrs; 2067d80e224dSAndy Grover fabric->tf_cit_tmpl.tfc_tpg_nacl_auth_cit.ct_attrs = lio_target_nacl_auth_attrs; 2068d80e224dSAndy Grover fabric->tf_cit_tmpl.tfc_tpg_nacl_param_cit.ct_attrs = lio_target_nacl_param_attrs; 2069e48354ceSNicholas Bellinger 2070e48354ceSNicholas Bellinger ret = target_fabric_configfs_register(fabric); 2071e48354ceSNicholas Bellinger if (ret < 0) { 2072e48354ceSNicholas Bellinger pr_err("target_fabric_configfs_register() for" 2073e48354ceSNicholas Bellinger " LIO-Target failed!\n"); 2074e48354ceSNicholas Bellinger target_fabric_configfs_free(fabric); 2075e48354ceSNicholas Bellinger return ret; 2076e48354ceSNicholas Bellinger } 2077e48354ceSNicholas Bellinger 2078e48354ceSNicholas Bellinger lio_target_fabric_configfs = fabric; 2079e48354ceSNicholas Bellinger pr_debug("LIO_TARGET[0] - Set fabric ->" 2080e48354ceSNicholas Bellinger " lio_target_fabric_configfs\n"); 2081e48354ceSNicholas Bellinger return 0; 2082e48354ceSNicholas Bellinger } 2083e48354ceSNicholas Bellinger 2084e48354ceSNicholas Bellinger 2085e48354ceSNicholas Bellinger void iscsi_target_deregister_configfs(void) 2086e48354ceSNicholas Bellinger { 2087e48354ceSNicholas Bellinger if (!lio_target_fabric_configfs) 2088e48354ceSNicholas Bellinger return; 2089e48354ceSNicholas Bellinger /* 2090e48354ceSNicholas Bellinger * Shutdown discovery sessions and disable discovery TPG 2091e48354ceSNicholas Bellinger */ 2092e48354ceSNicholas Bellinger if (iscsit_global->discovery_tpg) 2093e48354ceSNicholas Bellinger iscsit_tpg_disable_portal_group(iscsit_global->discovery_tpg, 1); 2094e48354ceSNicholas Bellinger 2095e48354ceSNicholas Bellinger target_fabric_configfs_deregister(lio_target_fabric_configfs); 2096e48354ceSNicholas Bellinger lio_target_fabric_configfs = NULL; 2097e48354ceSNicholas Bellinger pr_debug("LIO_TARGET[0] - Cleared" 2098e48354ceSNicholas Bellinger " lio_target_fabric_configfs\n"); 2099e48354ceSNicholas Bellinger } 2100