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