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> 262ec5a8c1SNicholas Bellinger #include <target/iscsi/iscsi_transport.h> 27e48354ceSNicholas Bellinger 2867f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_core.h> 29e48354ceSNicholas Bellinger #include "iscsi_target_parameters.h" 30e48354ceSNicholas Bellinger #include "iscsi_target_device.h" 31e48354ceSNicholas Bellinger #include "iscsi_target_erl0.h" 32e48354ceSNicholas Bellinger #include "iscsi_target_nodeattrib.h" 33e48354ceSNicholas Bellinger #include "iscsi_target_tpg.h" 34e48354ceSNicholas Bellinger #include "iscsi_target_util.h" 35e48354ceSNicholas Bellinger #include "iscsi_target.h" 3667f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_stat.h> 37e48354ceSNicholas Bellinger 38e48354ceSNicholas Bellinger 39e48354ceSNicholas Bellinger /* Start items for lio_target_portal_cit */ 40e48354ceSNicholas Bellinger 412eafd729SChristoph Hellwig static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item) 42e48354ceSNicholas Bellinger { 432eafd729SChristoph Hellwig return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np); 442eafd729SChristoph Hellwig } 452eafd729SChristoph Hellwig 462eafd729SChristoph Hellwig static ssize_t lio_target_np_sctp_show(struct config_item *item, char *page) 472eafd729SChristoph Hellwig { 482eafd729SChristoph Hellwig struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); 49e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np_sctp; 50e48354ceSNicholas Bellinger ssize_t rb; 51e48354ceSNicholas Bellinger 52e48354ceSNicholas Bellinger tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP); 53e48354ceSNicholas Bellinger if (tpg_np_sctp) 54e48354ceSNicholas Bellinger rb = sprintf(page, "1\n"); 55e48354ceSNicholas Bellinger else 56e48354ceSNicholas Bellinger rb = sprintf(page, "0\n"); 57e48354ceSNicholas Bellinger 58e48354ceSNicholas Bellinger return rb; 59e48354ceSNicholas Bellinger } 60e48354ceSNicholas Bellinger 612eafd729SChristoph Hellwig static ssize_t lio_target_np_sctp_store(struct config_item *item, 622eafd729SChristoph Hellwig const char *page, size_t count) 63e48354ceSNicholas Bellinger { 642eafd729SChristoph Hellwig struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); 65e48354ceSNicholas Bellinger struct iscsi_np *np; 66e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 67e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np_sctp = NULL; 68e48354ceSNicholas Bellinger u32 op; 69e48354ceSNicholas Bellinger int ret; 70e48354ceSNicholas Bellinger 71ad7babd2SJörn Engel ret = kstrtou32(page, 0, &op); 72ad7babd2SJörn Engel if (ret) 73ad7babd2SJörn Engel return ret; 74e48354ceSNicholas Bellinger if ((op != 1) && (op != 0)) { 75e48354ceSNicholas Bellinger pr_err("Illegal value for tpg_enable: %u\n", op); 76e48354ceSNicholas Bellinger return -EINVAL; 77e48354ceSNicholas Bellinger } 78e48354ceSNicholas Bellinger np = tpg_np->tpg_np; 79e48354ceSNicholas Bellinger if (!np) { 80e48354ceSNicholas Bellinger pr_err("Unable to locate struct iscsi_np from" 81e48354ceSNicholas Bellinger " struct iscsi_tpg_np\n"); 82e48354ceSNicholas Bellinger return -EINVAL; 83e48354ceSNicholas Bellinger } 84e48354ceSNicholas Bellinger 85e48354ceSNicholas Bellinger tpg = tpg_np->tpg; 86e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) 87e48354ceSNicholas Bellinger return -EINVAL; 88e48354ceSNicholas Bellinger 89e48354ceSNicholas Bellinger if (op) { 90e48354ceSNicholas Bellinger /* 91e48354ceSNicholas Bellinger * Use existing np->np_sockaddr for SCTP network portal reference 92e48354ceSNicholas Bellinger */ 93e48354ceSNicholas Bellinger tpg_np_sctp = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, 9476c28f1fSAndy Grover tpg_np, ISCSI_SCTP_TCP); 95e48354ceSNicholas Bellinger if (!tpg_np_sctp || IS_ERR(tpg_np_sctp)) 96e48354ceSNicholas Bellinger goto out; 97e48354ceSNicholas Bellinger } else { 98e48354ceSNicholas Bellinger tpg_np_sctp = iscsit_tpg_locate_child_np(tpg_np, ISCSI_SCTP_TCP); 99e48354ceSNicholas Bellinger if (!tpg_np_sctp) 100e48354ceSNicholas Bellinger goto out; 101e48354ceSNicholas Bellinger 102e48354ceSNicholas Bellinger ret = iscsit_tpg_del_network_portal(tpg, tpg_np_sctp); 103e48354ceSNicholas Bellinger if (ret < 0) 104e48354ceSNicholas Bellinger goto out; 105e48354ceSNicholas Bellinger } 106e48354ceSNicholas Bellinger 107e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 108e48354ceSNicholas Bellinger return count; 109e48354ceSNicholas Bellinger out: 110e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 111e48354ceSNicholas Bellinger return -EINVAL; 112e48354ceSNicholas Bellinger } 113e48354ceSNicholas Bellinger 1142eafd729SChristoph Hellwig static ssize_t lio_target_np_iser_show(struct config_item *item, char *page) 11572438cddSNicholas Bellinger { 1162eafd729SChristoph Hellwig struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); 11772438cddSNicholas Bellinger struct iscsi_tpg_np *tpg_np_iser; 11872438cddSNicholas Bellinger ssize_t rb; 11972438cddSNicholas Bellinger 12072438cddSNicholas Bellinger tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND); 12172438cddSNicholas Bellinger if (tpg_np_iser) 12272438cddSNicholas Bellinger rb = sprintf(page, "1\n"); 12372438cddSNicholas Bellinger else 12472438cddSNicholas Bellinger rb = sprintf(page, "0\n"); 12572438cddSNicholas Bellinger 12672438cddSNicholas Bellinger return rb; 12772438cddSNicholas Bellinger } 12872438cddSNicholas Bellinger 1292eafd729SChristoph Hellwig static ssize_t lio_target_np_iser_store(struct config_item *item, 1302eafd729SChristoph Hellwig const char *page, size_t count) 13172438cddSNicholas Bellinger { 1322eafd729SChristoph Hellwig struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); 13372438cddSNicholas Bellinger struct iscsi_np *np; 13472438cddSNicholas Bellinger struct iscsi_portal_group *tpg; 13572438cddSNicholas Bellinger struct iscsi_tpg_np *tpg_np_iser = NULL; 13672438cddSNicholas Bellinger char *endptr; 13772438cddSNicholas Bellinger u32 op; 13858bd0c69SAndy Grover int rc = 0; 13972438cddSNicholas Bellinger 14072438cddSNicholas Bellinger op = simple_strtoul(page, &endptr, 0); 14172438cddSNicholas Bellinger if ((op != 1) && (op != 0)) { 14272438cddSNicholas Bellinger pr_err("Illegal value for tpg_enable: %u\n", op); 14372438cddSNicholas Bellinger return -EINVAL; 14472438cddSNicholas Bellinger } 14572438cddSNicholas Bellinger np = tpg_np->tpg_np; 14672438cddSNicholas Bellinger if (!np) { 14772438cddSNicholas Bellinger pr_err("Unable to locate struct iscsi_np from" 14872438cddSNicholas Bellinger " struct iscsi_tpg_np\n"); 14972438cddSNicholas Bellinger return -EINVAL; 15072438cddSNicholas Bellinger } 15172438cddSNicholas Bellinger 15272438cddSNicholas Bellinger tpg = tpg_np->tpg; 15372438cddSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) 15472438cddSNicholas Bellinger return -EINVAL; 15572438cddSNicholas Bellinger 15672438cddSNicholas Bellinger if (op) { 15758bd0c69SAndy Grover rc = request_module("ib_isert"); 15858bd0c69SAndy Grover if (rc != 0) { 15972438cddSNicholas Bellinger pr_warn("Unable to request_module for ib_isert\n"); 16058bd0c69SAndy Grover rc = 0; 16158bd0c69SAndy Grover } 16272438cddSNicholas Bellinger 16372438cddSNicholas Bellinger tpg_np_iser = iscsit_tpg_add_network_portal(tpg, &np->np_sockaddr, 16476c28f1fSAndy Grover tpg_np, ISCSI_INFINIBAND); 16558bd0c69SAndy Grover if (IS_ERR(tpg_np_iser)) { 16658bd0c69SAndy Grover rc = PTR_ERR(tpg_np_iser); 16772438cddSNicholas Bellinger goto out; 16858bd0c69SAndy Grover } 16972438cddSNicholas Bellinger } else { 17072438cddSNicholas Bellinger tpg_np_iser = iscsit_tpg_locate_child_np(tpg_np, ISCSI_INFINIBAND); 17158bd0c69SAndy Grover if (tpg_np_iser) { 17272438cddSNicholas Bellinger rc = iscsit_tpg_del_network_portal(tpg, tpg_np_iser); 17372438cddSNicholas Bellinger if (rc < 0) 17472438cddSNicholas Bellinger goto out; 17572438cddSNicholas Bellinger } 17658bd0c69SAndy Grover } 17772438cddSNicholas Bellinger 17872438cddSNicholas Bellinger iscsit_put_tpg(tpg); 17972438cddSNicholas Bellinger return count; 18072438cddSNicholas Bellinger out: 18172438cddSNicholas Bellinger iscsit_put_tpg(tpg); 18258bd0c69SAndy Grover return rc; 18372438cddSNicholas Bellinger } 18472438cddSNicholas Bellinger 1852eafd729SChristoph Hellwig CONFIGFS_ATTR(lio_target_np_, sctp); 1862eafd729SChristoph Hellwig CONFIGFS_ATTR(lio_target_np_, iser); 18772438cddSNicholas Bellinger 188e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_portal_attrs[] = { 1892eafd729SChristoph Hellwig &lio_target_np_attr_sctp, 1902eafd729SChristoph Hellwig &lio_target_np_attr_iser, 191e48354ceSNicholas Bellinger NULL, 192e48354ceSNicholas Bellinger }; 193e48354ceSNicholas Bellinger 194e48354ceSNicholas Bellinger /* Stop items for lio_target_portal_cit */ 195e48354ceSNicholas Bellinger 196e48354ceSNicholas Bellinger /* Start items for lio_target_np_cit */ 197e48354ceSNicholas Bellinger 198e48354ceSNicholas Bellinger #define MAX_PORTAL_LEN 256 199e48354ceSNicholas Bellinger 200fceb5bc7SChristoph Hellwig static struct se_tpg_np *lio_target_call_addnptotpg( 201e48354ceSNicholas Bellinger struct se_portal_group *se_tpg, 202e48354ceSNicholas Bellinger struct config_group *group, 203e48354ceSNicholas Bellinger const char *name) 204e48354ceSNicholas Bellinger { 205e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 206e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np; 207e48354ceSNicholas Bellinger char *str, *str2, *ip_str, *port_str; 20813a3cf08SAndy Grover struct sockaddr_storage sockaddr; 209e48354ceSNicholas Bellinger struct sockaddr_in *sock_in; 210e48354ceSNicholas Bellinger struct sockaddr_in6 *sock_in6; 211e48354ceSNicholas Bellinger unsigned long port; 212e48354ceSNicholas Bellinger int ret; 213e48354ceSNicholas Bellinger char buf[MAX_PORTAL_LEN + 1]; 214e48354ceSNicholas Bellinger 215e48354ceSNicholas Bellinger if (strlen(name) > MAX_PORTAL_LEN) { 216e48354ceSNicholas Bellinger pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n", 217e48354ceSNicholas Bellinger (int)strlen(name), MAX_PORTAL_LEN); 218e48354ceSNicholas Bellinger return ERR_PTR(-EOVERFLOW); 219e48354ceSNicholas Bellinger } 220e48354ceSNicholas Bellinger memset(buf, 0, MAX_PORTAL_LEN + 1); 2217bbb654eSNicholas Bellinger snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name); 222e48354ceSNicholas Bellinger 22313a3cf08SAndy Grover memset(&sockaddr, 0, sizeof(struct sockaddr_storage)); 224e48354ceSNicholas Bellinger 225e48354ceSNicholas Bellinger str = strstr(buf, "["); 226e48354ceSNicholas Bellinger if (str) { 227e48354ceSNicholas Bellinger const char *end; 228e48354ceSNicholas Bellinger 229e48354ceSNicholas Bellinger str2 = strstr(str, "]"); 230e48354ceSNicholas Bellinger if (!str2) { 231e48354ceSNicholas Bellinger pr_err("Unable to locate trailing \"]\"" 232e48354ceSNicholas Bellinger " in IPv6 iSCSI network portal address\n"); 233e48354ceSNicholas Bellinger return ERR_PTR(-EINVAL); 234e48354ceSNicholas Bellinger } 235e48354ceSNicholas Bellinger str++; /* Skip over leading "[" */ 23676c28f1fSAndy Grover *str2 = '\0'; /* Terminate the unbracketed IPv6 address */ 23776c28f1fSAndy Grover str2++; /* Skip over the \0 */ 238e48354ceSNicholas Bellinger port_str = strstr(str2, ":"); 239e48354ceSNicholas Bellinger if (!port_str) { 240e48354ceSNicholas Bellinger pr_err("Unable to locate \":port\"" 241e48354ceSNicholas Bellinger " in IPv6 iSCSI network portal address\n"); 242e48354ceSNicholas Bellinger return ERR_PTR(-EINVAL); 243e48354ceSNicholas Bellinger } 244e48354ceSNicholas Bellinger *port_str = '\0'; /* Terminate string for IP */ 245e48354ceSNicholas Bellinger port_str++; /* Skip over ":" */ 246e48354ceSNicholas Bellinger 24757103d7fSJingoo Han ret = kstrtoul(port_str, 0, &port); 248e48354ceSNicholas Bellinger if (ret < 0) { 24957103d7fSJingoo Han pr_err("kstrtoul() failed for port_str: %d\n", ret); 250e48354ceSNicholas Bellinger return ERR_PTR(ret); 251e48354ceSNicholas Bellinger } 252e48354ceSNicholas Bellinger sock_in6 = (struct sockaddr_in6 *)&sockaddr; 253e48354ceSNicholas Bellinger sock_in6->sin6_family = AF_INET6; 254e48354ceSNicholas Bellinger sock_in6->sin6_port = htons((unsigned short)port); 255dc58f760SAndy Grover ret = in6_pton(str, -1, 256e48354ceSNicholas Bellinger (void *)&sock_in6->sin6_addr.in6_u, -1, &end); 257e48354ceSNicholas Bellinger if (ret <= 0) { 258e48354ceSNicholas Bellinger pr_err("in6_pton returned: %d\n", ret); 259e48354ceSNicholas Bellinger return ERR_PTR(-EINVAL); 260e48354ceSNicholas Bellinger } 261e48354ceSNicholas Bellinger } else { 262e48354ceSNicholas Bellinger str = ip_str = &buf[0]; 263e48354ceSNicholas Bellinger port_str = strstr(ip_str, ":"); 264e48354ceSNicholas Bellinger if (!port_str) { 265e48354ceSNicholas Bellinger pr_err("Unable to locate \":port\"" 266e48354ceSNicholas Bellinger " in IPv4 iSCSI network portal address\n"); 267e48354ceSNicholas Bellinger return ERR_PTR(-EINVAL); 268e48354ceSNicholas Bellinger } 269e48354ceSNicholas Bellinger *port_str = '\0'; /* Terminate string for IP */ 270e48354ceSNicholas Bellinger port_str++; /* Skip over ":" */ 271e48354ceSNicholas Bellinger 27257103d7fSJingoo Han ret = kstrtoul(port_str, 0, &port); 273e48354ceSNicholas Bellinger if (ret < 0) { 27457103d7fSJingoo Han pr_err("kstrtoul() failed for port_str: %d\n", ret); 275e48354ceSNicholas Bellinger return ERR_PTR(ret); 276e48354ceSNicholas Bellinger } 277e48354ceSNicholas Bellinger sock_in = (struct sockaddr_in *)&sockaddr; 278e48354ceSNicholas Bellinger sock_in->sin_family = AF_INET; 279e48354ceSNicholas Bellinger sock_in->sin_port = htons((unsigned short)port); 280e48354ceSNicholas Bellinger sock_in->sin_addr.s_addr = in_aton(ip_str); 281e48354ceSNicholas Bellinger } 282e48354ceSNicholas Bellinger tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); 283e48354ceSNicholas Bellinger ret = iscsit_get_tpg(tpg); 284e48354ceSNicholas Bellinger if (ret < 0) 285e48354ceSNicholas Bellinger return ERR_PTR(-EINVAL); 286e48354ceSNicholas Bellinger 287e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu" 288e48354ceSNicholas Bellinger " PORTAL: %s\n", 289e48354ceSNicholas Bellinger config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), 290e48354ceSNicholas Bellinger tpg->tpgt, name); 291e48354ceSNicholas Bellinger /* 292e48354ceSNicholas Bellinger * Assume ISCSI_TCP by default. Other network portals for other 293e48354ceSNicholas Bellinger * iSCSI fabrics: 294e48354ceSNicholas Bellinger * 295e48354ceSNicholas Bellinger * Traditional iSCSI over SCTP (initial support) 296e48354ceSNicholas Bellinger * iSER/TCP (TODO, hardware available) 297e48354ceSNicholas Bellinger * iSER/SCTP (TODO, software emulation with osc-iwarp) 298e48354ceSNicholas Bellinger * iSER/IB (TODO, hardware available) 299e48354ceSNicholas Bellinger * 30020879696SMasanari Iida * can be enabled with attributes under 301e48354ceSNicholas Bellinger * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/ 302e48354ceSNicholas Bellinger * 303e48354ceSNicholas Bellinger */ 30476c28f1fSAndy Grover tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL, 305e48354ceSNicholas Bellinger ISCSI_TCP); 306e48354ceSNicholas Bellinger if (IS_ERR(tpg_np)) { 307e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 308e1750ba2SThomas Meyer return ERR_CAST(tpg_np); 309e48354ceSNicholas Bellinger } 310e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n"); 311e48354ceSNicholas Bellinger 312e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 313e48354ceSNicholas Bellinger return &tpg_np->se_tpg_np; 314e48354ceSNicholas Bellinger } 315e48354ceSNicholas Bellinger 316e48354ceSNicholas Bellinger static void lio_target_call_delnpfromtpg( 317e48354ceSNicholas Bellinger struct se_tpg_np *se_tpg_np) 318e48354ceSNicholas Bellinger { 319e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 320e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np; 321e48354ceSNicholas Bellinger struct se_portal_group *se_tpg; 322e48354ceSNicholas Bellinger int ret; 323e48354ceSNicholas Bellinger 324e48354ceSNicholas Bellinger tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np); 325e48354ceSNicholas Bellinger tpg = tpg_np->tpg; 326e48354ceSNicholas Bellinger ret = iscsit_get_tpg(tpg); 327e48354ceSNicholas Bellinger if (ret < 0) 328e48354ceSNicholas Bellinger return; 329e48354ceSNicholas Bellinger 330e48354ceSNicholas Bellinger se_tpg = &tpg->tpg_se_tpg; 331e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu" 33269d75574SAndy Grover " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), 33369d75574SAndy Grover tpg->tpgt, &tpg_np->tpg_np->np_sockaddr); 334e48354ceSNicholas Bellinger 335e48354ceSNicholas Bellinger ret = iscsit_tpg_del_network_portal(tpg, tpg_np); 336e48354ceSNicholas Bellinger if (ret < 0) 337e48354ceSNicholas Bellinger goto out; 338e48354ceSNicholas Bellinger 339e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n"); 340e48354ceSNicholas Bellinger out: 341e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 342e48354ceSNicholas Bellinger } 343e48354ceSNicholas Bellinger 344e48354ceSNicholas Bellinger /* End items for lio_target_np_cit */ 345e48354ceSNicholas Bellinger 346e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_attrib_cit */ 347e48354ceSNicholas Bellinger 3482eafd729SChristoph Hellwig #define ISCSI_NACL_ATTR(name) \ 3492eafd729SChristoph Hellwig static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\ 350e48354ceSNicholas Bellinger char *page) \ 351e48354ceSNicholas Bellinger { \ 3522eafd729SChristoph Hellwig struct se_node_acl *se_nacl = attrib_to_nacl(item); \ 353e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ 354e48354ceSNicholas Bellinger se_node_acl); \ 355e48354ceSNicholas Bellinger \ 356b7eec2cdSAndy Grover return sprintf(page, "%u\n", nacl->node_attrib.name); \ 357e48354ceSNicholas Bellinger } \ 358e48354ceSNicholas Bellinger \ 3592eafd729SChristoph Hellwig static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\ 3602eafd729SChristoph Hellwig const char *page, size_t count) \ 361e48354ceSNicholas Bellinger { \ 3622eafd729SChristoph Hellwig struct se_node_acl *se_nacl = attrib_to_nacl(item); \ 363e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ 364e48354ceSNicholas Bellinger se_node_acl); \ 365e48354ceSNicholas Bellinger u32 val; \ 366e48354ceSNicholas Bellinger int ret; \ 367e48354ceSNicholas Bellinger \ 368ad7babd2SJörn Engel ret = kstrtou32(page, 0, &val); \ 369ad7babd2SJörn Engel if (ret) \ 370ad7babd2SJörn Engel return ret; \ 371e48354ceSNicholas Bellinger ret = iscsit_na_##name(nacl, val); \ 372e48354ceSNicholas Bellinger if (ret < 0) \ 373e48354ceSNicholas Bellinger return ret; \ 374e48354ceSNicholas Bellinger \ 375e48354ceSNicholas Bellinger return count; \ 3762eafd729SChristoph Hellwig } \ 3772eafd729SChristoph Hellwig \ 3782eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_nacl_attrib_, name) 379e48354ceSNicholas Bellinger 3802eafd729SChristoph Hellwig ISCSI_NACL_ATTR(dataout_timeout); 3812eafd729SChristoph Hellwig ISCSI_NACL_ATTR(dataout_timeout_retries); 3822eafd729SChristoph Hellwig ISCSI_NACL_ATTR(default_erl); 3832eafd729SChristoph Hellwig ISCSI_NACL_ATTR(nopin_timeout); 3842eafd729SChristoph Hellwig ISCSI_NACL_ATTR(nopin_response_timeout); 3852eafd729SChristoph Hellwig ISCSI_NACL_ATTR(random_datain_pdu_offsets); 3862eafd729SChristoph Hellwig ISCSI_NACL_ATTR(random_datain_seq_offsets); 3872eafd729SChristoph Hellwig ISCSI_NACL_ATTR(random_r2t_offsets); 388e48354ceSNicholas Bellinger 389e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = { 3902eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_dataout_timeout, 3912eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_dataout_timeout_retries, 3922eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_default_erl, 3932eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_nopin_timeout, 3942eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_nopin_response_timeout, 3952eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_random_datain_pdu_offsets, 3962eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_random_datain_seq_offsets, 3972eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_random_r2t_offsets, 398e48354ceSNicholas Bellinger NULL, 399e48354ceSNicholas Bellinger }; 400e48354ceSNicholas Bellinger 401e48354ceSNicholas Bellinger /* End items for lio_target_nacl_attrib_cit */ 402e48354ceSNicholas Bellinger 403e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_auth_cit */ 404e48354ceSNicholas Bellinger 405e48354ceSNicholas Bellinger #define __DEF_NACL_AUTH_STR(prefix, name, flags) \ 4062eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show( \ 407e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl, \ 408e48354ceSNicholas Bellinger char *page) \ 409e48354ceSNicholas Bellinger { \ 410e48354ceSNicholas Bellinger struct iscsi_node_auth *auth = &nacl->node_auth; \ 411e48354ceSNicholas Bellinger \ 412e48354ceSNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 413e48354ceSNicholas Bellinger return -EPERM; \ 414e48354ceSNicholas Bellinger return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ 415e48354ceSNicholas Bellinger } \ 416e48354ceSNicholas Bellinger \ 4172eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_store( \ 418e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl, \ 419e48354ceSNicholas Bellinger const char *page, \ 420e48354ceSNicholas Bellinger size_t count) \ 421e48354ceSNicholas Bellinger { \ 422e48354ceSNicholas Bellinger struct iscsi_node_auth *auth = &nacl->node_auth; \ 423e48354ceSNicholas Bellinger \ 424e48354ceSNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 425e48354ceSNicholas Bellinger return -EPERM; \ 4262306bfb2SEric Seppanen if (count >= sizeof(auth->name)) \ 4272306bfb2SEric Seppanen return -EINVAL; \ 4280fbfc46fSJörn Engel snprintf(auth->name, sizeof(auth->name), "%s", page); \ 429e48354ceSNicholas Bellinger if (!strncmp("NULL", auth->name, 4)) \ 430e48354ceSNicholas Bellinger auth->naf_flags &= ~flags; \ 431e48354ceSNicholas Bellinger else \ 432e48354ceSNicholas Bellinger auth->naf_flags |= flags; \ 433e48354ceSNicholas Bellinger \ 434e48354ceSNicholas Bellinger if ((auth->naf_flags & NAF_USERID_IN_SET) && \ 435e48354ceSNicholas Bellinger (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ 436e48354ceSNicholas Bellinger auth->authenticate_target = 1; \ 437e48354ceSNicholas Bellinger else \ 438e48354ceSNicholas Bellinger auth->authenticate_target = 0; \ 439e48354ceSNicholas Bellinger \ 440e48354ceSNicholas Bellinger return count; \ 441e48354ceSNicholas Bellinger } 442e48354ceSNicholas Bellinger 4432eafd729SChristoph Hellwig #define DEF_NACL_AUTH_STR(name, flags) \ 4442eafd729SChristoph Hellwig __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \ 4452eafd729SChristoph Hellwig static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \ 4462eafd729SChristoph Hellwig char *page) \ 4472eafd729SChristoph Hellwig { \ 4482eafd729SChristoph Hellwig struct se_node_acl *nacl = auth_to_nacl(item); \ 4492eafd729SChristoph Hellwig return __iscsi_nacl_auth_##name##_show(container_of(nacl, \ 4502eafd729SChristoph Hellwig struct iscsi_node_acl, se_node_acl), page); \ 4512eafd729SChristoph Hellwig } \ 4522eafd729SChristoph Hellwig static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \ 4532eafd729SChristoph Hellwig const char *page, size_t count) \ 4542eafd729SChristoph Hellwig { \ 4552eafd729SChristoph Hellwig struct se_node_acl *nacl = auth_to_nacl(item); \ 4562eafd729SChristoph Hellwig return __iscsi_nacl_auth_##name##_store(container_of(nacl, \ 4572eafd729SChristoph Hellwig struct iscsi_node_acl, se_node_acl), page, count); \ 4582eafd729SChristoph Hellwig } \ 4592eafd729SChristoph Hellwig \ 4602eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_nacl_auth_, name) 4612eafd729SChristoph Hellwig 4622eafd729SChristoph Hellwig /* 4632eafd729SChristoph Hellwig * One-way authentication userid 4642eafd729SChristoph Hellwig */ 4652eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(userid, NAF_USERID_SET); 4662eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET); 4672eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); 4682eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); 4692eafd729SChristoph Hellwig 470e48354ceSNicholas Bellinger #define __DEF_NACL_AUTH_INT(prefix, name) \ 4712eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show( \ 472e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl, \ 473e48354ceSNicholas Bellinger char *page) \ 474e48354ceSNicholas Bellinger { \ 475e48354ceSNicholas Bellinger struct iscsi_node_auth *auth = &nacl->node_auth; \ 476e48354ceSNicholas Bellinger \ 477e48354ceSNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 478e48354ceSNicholas Bellinger return -EPERM; \ 479e48354ceSNicholas Bellinger \ 480e48354ceSNicholas Bellinger return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ 481e48354ceSNicholas Bellinger } 482e48354ceSNicholas Bellinger 483e48354ceSNicholas Bellinger #define DEF_NACL_AUTH_INT(name) \ 484e48354ceSNicholas Bellinger __DEF_NACL_AUTH_INT(nacl_auth, name) \ 4852eafd729SChristoph Hellwig static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \ 486e48354ceSNicholas Bellinger char *page) \ 487e48354ceSNicholas Bellinger { \ 4882eafd729SChristoph Hellwig struct se_node_acl *nacl = auth_to_nacl(item); \ 4892eafd729SChristoph Hellwig return __iscsi_nacl_auth_##name##_show(container_of(nacl, \ 490e48354ceSNicholas Bellinger struct iscsi_node_acl, se_node_acl), page); \ 4912eafd729SChristoph Hellwig } \ 4922eafd729SChristoph Hellwig \ 4932eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name) 494e48354ceSNicholas Bellinger 495e48354ceSNicholas Bellinger DEF_NACL_AUTH_INT(authenticate_target); 496e48354ceSNicholas Bellinger 497e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_auth_attrs[] = { 4982eafd729SChristoph Hellwig &iscsi_nacl_auth_attr_userid, 4992eafd729SChristoph Hellwig &iscsi_nacl_auth_attr_password, 5002eafd729SChristoph Hellwig &iscsi_nacl_auth_attr_authenticate_target, 5012eafd729SChristoph Hellwig &iscsi_nacl_auth_attr_userid_mutual, 5022eafd729SChristoph Hellwig &iscsi_nacl_auth_attr_password_mutual, 503e48354ceSNicholas Bellinger NULL, 504e48354ceSNicholas Bellinger }; 505e48354ceSNicholas Bellinger 506e48354ceSNicholas Bellinger /* End items for lio_target_nacl_auth_cit */ 507e48354ceSNicholas Bellinger 508e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_param_cit */ 509e48354ceSNicholas Bellinger 5102eafd729SChristoph Hellwig #define ISCSI_NACL_PARAM(name) \ 5112eafd729SChristoph Hellwig static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \ 512e48354ceSNicholas Bellinger char *page) \ 513e48354ceSNicholas Bellinger { \ 5142eafd729SChristoph Hellwig struct se_node_acl *se_nacl = param_to_nacl(item); \ 515e48354ceSNicholas Bellinger struct iscsi_session *sess; \ 516e48354ceSNicholas Bellinger struct se_session *se_sess; \ 517e48354ceSNicholas Bellinger ssize_t rb; \ 518e48354ceSNicholas Bellinger \ 519e48354ceSNicholas Bellinger spin_lock_bh(&se_nacl->nacl_sess_lock); \ 520e48354ceSNicholas Bellinger se_sess = se_nacl->nacl_sess; \ 521e48354ceSNicholas Bellinger if (!se_sess) { \ 522e48354ceSNicholas Bellinger rb = snprintf(page, PAGE_SIZE, \ 523e48354ceSNicholas Bellinger "No Active iSCSI Session\n"); \ 524e48354ceSNicholas Bellinger } else { \ 525e48354ceSNicholas Bellinger sess = se_sess->fabric_sess_ptr; \ 526e48354ceSNicholas Bellinger rb = snprintf(page, PAGE_SIZE, "%u\n", \ 527e48354ceSNicholas Bellinger (u32)sess->sess_ops->name); \ 528e48354ceSNicholas Bellinger } \ 529e48354ceSNicholas Bellinger spin_unlock_bh(&se_nacl->nacl_sess_lock); \ 530e48354ceSNicholas Bellinger \ 531e48354ceSNicholas Bellinger return rb; \ 5322eafd729SChristoph Hellwig } \ 5332eafd729SChristoph Hellwig \ 5342eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_nacl_param_, name) 535e48354ceSNicholas Bellinger 5362eafd729SChristoph Hellwig ISCSI_NACL_PARAM(MaxConnections); 5372eafd729SChristoph Hellwig ISCSI_NACL_PARAM(InitialR2T); 5382eafd729SChristoph Hellwig ISCSI_NACL_PARAM(ImmediateData); 5392eafd729SChristoph Hellwig ISCSI_NACL_PARAM(MaxBurstLength); 5402eafd729SChristoph Hellwig ISCSI_NACL_PARAM(FirstBurstLength); 5412eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DefaultTime2Wait); 5422eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DefaultTime2Retain); 5432eafd729SChristoph Hellwig ISCSI_NACL_PARAM(MaxOutstandingR2T); 5442eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DataPDUInOrder); 5452eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DataSequenceInOrder); 5462eafd729SChristoph Hellwig ISCSI_NACL_PARAM(ErrorRecoveryLevel); 547e48354ceSNicholas Bellinger 548e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_param_attrs[] = { 5492eafd729SChristoph Hellwig &iscsi_nacl_param_attr_MaxConnections, 5502eafd729SChristoph Hellwig &iscsi_nacl_param_attr_InitialR2T, 5512eafd729SChristoph Hellwig &iscsi_nacl_param_attr_ImmediateData, 5522eafd729SChristoph Hellwig &iscsi_nacl_param_attr_MaxBurstLength, 5532eafd729SChristoph Hellwig &iscsi_nacl_param_attr_FirstBurstLength, 5542eafd729SChristoph Hellwig &iscsi_nacl_param_attr_DefaultTime2Wait, 5552eafd729SChristoph Hellwig &iscsi_nacl_param_attr_DefaultTime2Retain, 5562eafd729SChristoph Hellwig &iscsi_nacl_param_attr_MaxOutstandingR2T, 5572eafd729SChristoph Hellwig &iscsi_nacl_param_attr_DataPDUInOrder, 5582eafd729SChristoph Hellwig &iscsi_nacl_param_attr_DataSequenceInOrder, 5592eafd729SChristoph Hellwig &iscsi_nacl_param_attr_ErrorRecoveryLevel, 560e48354ceSNicholas Bellinger NULL, 561e48354ceSNicholas Bellinger }; 562e48354ceSNicholas Bellinger 563e48354ceSNicholas Bellinger /* End items for lio_target_nacl_param_cit */ 564e48354ceSNicholas Bellinger 565e48354ceSNicholas Bellinger /* Start items for lio_target_acl_cit */ 566e48354ceSNicholas Bellinger 5672eafd729SChristoph Hellwig static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page) 568e48354ceSNicholas Bellinger { 5692eafd729SChristoph Hellwig struct se_node_acl *se_nacl = acl_to_nacl(item); 570e48354ceSNicholas Bellinger struct iscsi_session *sess; 571e48354ceSNicholas Bellinger struct iscsi_conn *conn; 572e48354ceSNicholas Bellinger struct se_session *se_sess; 573e48354ceSNicholas Bellinger ssize_t rb = 0; 574109e2381SRoland Dreier u32 max_cmd_sn; 575e48354ceSNicholas Bellinger 576e48354ceSNicholas Bellinger spin_lock_bh(&se_nacl->nacl_sess_lock); 577e48354ceSNicholas Bellinger se_sess = se_nacl->nacl_sess; 578e48354ceSNicholas Bellinger if (!se_sess) { 579e48354ceSNicholas Bellinger rb += sprintf(page+rb, "No active iSCSI Session for Initiator" 580e48354ceSNicholas Bellinger " Endpoint: %s\n", se_nacl->initiatorname); 581e48354ceSNicholas Bellinger } else { 582e48354ceSNicholas Bellinger sess = se_sess->fabric_sess_ptr; 583e48354ceSNicholas Bellinger 584e48354ceSNicholas Bellinger rb += sprintf(page+rb, "InitiatorName: %s\n", 585e48354ceSNicholas Bellinger sess->sess_ops->InitiatorName); 586e48354ceSNicholas Bellinger rb += sprintf(page+rb, "InitiatorAlias: %s\n", 587e48354ceSNicholas Bellinger sess->sess_ops->InitiatorAlias); 588e48354ceSNicholas Bellinger 5895cdf5a87SAndy Shevchenko rb += sprintf(page+rb, 5905cdf5a87SAndy Shevchenko "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ", 5915cdf5a87SAndy Shevchenko sess->sid, sess->isid, sess->tsih); 592e48354ceSNicholas Bellinger rb += sprintf(page+rb, "SessionType: %s\n", 593e48354ceSNicholas Bellinger (sess->sess_ops->SessionType) ? 594e48354ceSNicholas Bellinger "Discovery" : "Normal"); 595e48354ceSNicholas Bellinger rb += sprintf(page+rb, "Session State: "); 596e48354ceSNicholas Bellinger switch (sess->session_state) { 597e48354ceSNicholas Bellinger case TARG_SESS_STATE_FREE: 598e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_FREE\n"); 599e48354ceSNicholas Bellinger break; 600e48354ceSNicholas Bellinger case TARG_SESS_STATE_ACTIVE: 601e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n"); 602e48354ceSNicholas Bellinger break; 603e48354ceSNicholas Bellinger case TARG_SESS_STATE_LOGGED_IN: 604e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n"); 605e48354ceSNicholas Bellinger break; 606e48354ceSNicholas Bellinger case TARG_SESS_STATE_FAILED: 607e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n"); 608e48354ceSNicholas Bellinger break; 609e48354ceSNicholas Bellinger case TARG_SESS_STATE_IN_CONTINUE: 610e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n"); 611e48354ceSNicholas Bellinger break; 612e48354ceSNicholas Bellinger default: 613e48354ceSNicholas Bellinger rb += sprintf(page+rb, "ERROR: Unknown Session" 614e48354ceSNicholas Bellinger " State!\n"); 615e48354ceSNicholas Bellinger break; 616e48354ceSNicholas Bellinger } 617e48354ceSNicholas Bellinger 618e48354ceSNicholas Bellinger rb += sprintf(page+rb, "---------------------[iSCSI Session" 619e48354ceSNicholas Bellinger " Values]-----------------------\n"); 620e48354ceSNicholas Bellinger rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN" 621e48354ceSNicholas Bellinger " : MaxCmdSN : ITT : TTT\n"); 622109e2381SRoland Dreier max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn); 623e48354ceSNicholas Bellinger rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x" 624e48354ceSNicholas Bellinger " 0x%08x 0x%08x\n", 625e48354ceSNicholas Bellinger sess->cmdsn_window, 626109e2381SRoland Dreier (max_cmd_sn - sess->exp_cmd_sn) + 1, 627109e2381SRoland Dreier sess->exp_cmd_sn, max_cmd_sn, 628e48354ceSNicholas Bellinger sess->init_task_tag, sess->targ_xfer_tag); 629e48354ceSNicholas Bellinger rb += sprintf(page+rb, "----------------------[iSCSI" 630e48354ceSNicholas Bellinger " Connections]-------------------------\n"); 631e48354ceSNicholas Bellinger 632e48354ceSNicholas Bellinger spin_lock(&sess->conn_lock); 633e48354ceSNicholas Bellinger list_for_each_entry(conn, &sess->sess_conn_list, conn_list) { 634e48354ceSNicholas Bellinger rb += sprintf(page+rb, "CID: %hu Connection" 635e48354ceSNicholas Bellinger " State: ", conn->cid); 636e48354ceSNicholas Bellinger switch (conn->conn_state) { 637e48354ceSNicholas Bellinger case TARG_CONN_STATE_FREE: 638e48354ceSNicholas Bellinger rb += sprintf(page+rb, 639e48354ceSNicholas Bellinger "TARG_CONN_STATE_FREE\n"); 640e48354ceSNicholas Bellinger break; 641e48354ceSNicholas Bellinger case TARG_CONN_STATE_XPT_UP: 642e48354ceSNicholas Bellinger rb += sprintf(page+rb, 643e48354ceSNicholas Bellinger "TARG_CONN_STATE_XPT_UP\n"); 644e48354ceSNicholas Bellinger break; 645e48354ceSNicholas Bellinger case TARG_CONN_STATE_IN_LOGIN: 646e48354ceSNicholas Bellinger rb += sprintf(page+rb, 647e48354ceSNicholas Bellinger "TARG_CONN_STATE_IN_LOGIN\n"); 648e48354ceSNicholas Bellinger break; 649e48354ceSNicholas Bellinger case TARG_CONN_STATE_LOGGED_IN: 650e48354ceSNicholas Bellinger rb += sprintf(page+rb, 651e48354ceSNicholas Bellinger "TARG_CONN_STATE_LOGGED_IN\n"); 652e48354ceSNicholas Bellinger break; 653e48354ceSNicholas Bellinger case TARG_CONN_STATE_IN_LOGOUT: 654e48354ceSNicholas Bellinger rb += sprintf(page+rb, 655e48354ceSNicholas Bellinger "TARG_CONN_STATE_IN_LOGOUT\n"); 656e48354ceSNicholas Bellinger break; 657e48354ceSNicholas Bellinger case TARG_CONN_STATE_LOGOUT_REQUESTED: 658e48354ceSNicholas Bellinger rb += sprintf(page+rb, 659e48354ceSNicholas Bellinger "TARG_CONN_STATE_LOGOUT_REQUESTED\n"); 660e48354ceSNicholas Bellinger break; 661e48354ceSNicholas Bellinger case TARG_CONN_STATE_CLEANUP_WAIT: 662e48354ceSNicholas Bellinger rb += sprintf(page+rb, 663e48354ceSNicholas Bellinger "TARG_CONN_STATE_CLEANUP_WAIT\n"); 664e48354ceSNicholas Bellinger break; 665e48354ceSNicholas Bellinger default: 666e48354ceSNicholas Bellinger rb += sprintf(page+rb, 667e48354ceSNicholas Bellinger "ERROR: Unknown Connection State!\n"); 668e48354ceSNicholas Bellinger break; 669e48354ceSNicholas Bellinger } 670e48354ceSNicholas Bellinger 671dc58f760SAndy Grover rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr, 672e48354ceSNicholas Bellinger (conn->network_transport == ISCSI_TCP) ? 673e48354ceSNicholas Bellinger "TCP" : "SCTP"); 674e48354ceSNicholas Bellinger rb += sprintf(page+rb, " StatSN: 0x%08x\n", 675e48354ceSNicholas Bellinger conn->stat_sn); 676e48354ceSNicholas Bellinger } 677e48354ceSNicholas Bellinger spin_unlock(&sess->conn_lock); 678e48354ceSNicholas Bellinger } 679e48354ceSNicholas Bellinger spin_unlock_bh(&se_nacl->nacl_sess_lock); 680e48354ceSNicholas Bellinger 681e48354ceSNicholas Bellinger return rb; 682e48354ceSNicholas Bellinger } 683e48354ceSNicholas Bellinger 6842eafd729SChristoph Hellwig static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item, 685e48354ceSNicholas Bellinger char *page) 686e48354ceSNicholas Bellinger { 6872eafd729SChristoph Hellwig return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth); 688e48354ceSNicholas Bellinger } 689e48354ceSNicholas Bellinger 6902eafd729SChristoph Hellwig static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item, 6912eafd729SChristoph Hellwig const char *page, size_t count) 692e48354ceSNicholas Bellinger { 6932eafd729SChristoph Hellwig struct se_node_acl *se_nacl = acl_to_nacl(item); 694e48354ceSNicholas Bellinger struct se_portal_group *se_tpg = se_nacl->se_tpg; 695e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, 696e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); 697e48354ceSNicholas Bellinger struct config_item *acl_ci, *tpg_ci, *wwn_ci; 698e48354ceSNicholas Bellinger u32 cmdsn_depth = 0; 699e48354ceSNicholas Bellinger int ret; 700e48354ceSNicholas Bellinger 701ad7babd2SJörn Engel ret = kstrtou32(page, 0, &cmdsn_depth); 702ad7babd2SJörn Engel if (ret) 703ad7babd2SJörn Engel return ret; 704e48354ceSNicholas Bellinger if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) { 705e48354ceSNicholas Bellinger pr_err("Passed cmdsn_depth: %u exceeds" 706e48354ceSNicholas Bellinger " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth, 707e48354ceSNicholas Bellinger TA_DEFAULT_CMDSN_DEPTH_MAX); 708e48354ceSNicholas Bellinger return -EINVAL; 709e48354ceSNicholas Bellinger } 710e48354ceSNicholas Bellinger acl_ci = &se_nacl->acl_group.cg_item; 711e48354ceSNicholas Bellinger if (!acl_ci) { 712e48354ceSNicholas Bellinger pr_err("Unable to locatel acl_ci\n"); 713e48354ceSNicholas Bellinger return -EINVAL; 714e48354ceSNicholas Bellinger } 715e48354ceSNicholas Bellinger tpg_ci = &acl_ci->ci_parent->ci_group->cg_item; 716e48354ceSNicholas Bellinger if (!tpg_ci) { 717e48354ceSNicholas Bellinger pr_err("Unable to locate tpg_ci\n"); 718e48354ceSNicholas Bellinger return -EINVAL; 719e48354ceSNicholas Bellinger } 720e48354ceSNicholas Bellinger wwn_ci = &tpg_ci->ci_group->cg_item; 721e48354ceSNicholas Bellinger if (!wwn_ci) { 722e48354ceSNicholas Bellinger pr_err("Unable to locate config_item wwn_ci\n"); 723e48354ceSNicholas Bellinger return -EINVAL; 724e48354ceSNicholas Bellinger } 725e48354ceSNicholas Bellinger 726e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) 727e48354ceSNicholas Bellinger return -EINVAL; 728e48354ceSNicholas Bellinger /* 729e48354ceSNicholas Bellinger * iscsit_tpg_set_initiator_node_queue_depth() assumes force=1 730e48354ceSNicholas Bellinger */ 731e48354ceSNicholas Bellinger ret = iscsit_tpg_set_initiator_node_queue_depth(tpg, 732e48354ceSNicholas Bellinger config_item_name(acl_ci), cmdsn_depth, 1); 733e48354ceSNicholas Bellinger 734e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for" 735e48354ceSNicholas Bellinger "InitiatorName: %s\n", config_item_name(wwn_ci), 736e48354ceSNicholas Bellinger config_item_name(tpg_ci), cmdsn_depth, 737e48354ceSNicholas Bellinger config_item_name(acl_ci)); 738e48354ceSNicholas Bellinger 739e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 740e48354ceSNicholas Bellinger return (!ret) ? count : (ssize_t)ret; 741e48354ceSNicholas Bellinger } 742e48354ceSNicholas Bellinger 7432eafd729SChristoph Hellwig static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page) 74479e62fc3SAndy Grover { 7452eafd729SChristoph Hellwig return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag); 74679e62fc3SAndy Grover } 74779e62fc3SAndy Grover 7482eafd729SChristoph Hellwig static ssize_t lio_target_nacl_tag_store(struct config_item *item, 7492eafd729SChristoph Hellwig const char *page, size_t count) 75079e62fc3SAndy Grover { 7512eafd729SChristoph Hellwig struct se_node_acl *se_nacl = acl_to_nacl(item); 75279e62fc3SAndy Grover int ret; 75379e62fc3SAndy Grover 75479e62fc3SAndy Grover ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page); 75579e62fc3SAndy Grover 75679e62fc3SAndy Grover if (ret < 0) 75779e62fc3SAndy Grover return ret; 75879e62fc3SAndy Grover return count; 75979e62fc3SAndy Grover } 76079e62fc3SAndy Grover 7612eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(lio_target_nacl_, info); 7622eafd729SChristoph Hellwig CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth); 7632eafd729SChristoph Hellwig CONFIGFS_ATTR(lio_target_nacl_, tag); 76479e62fc3SAndy Grover 765e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_initiator_attrs[] = { 7662eafd729SChristoph Hellwig &lio_target_nacl_attr_info, 7672eafd729SChristoph Hellwig &lio_target_nacl_attr_cmdsn_depth, 7682eafd729SChristoph Hellwig &lio_target_nacl_attr_tag, 769e48354ceSNicholas Bellinger NULL, 770e48354ceSNicholas Bellinger }; 771e48354ceSNicholas Bellinger 772c7d6a803SChristoph Hellwig static int lio_target_init_nodeacl(struct se_node_acl *se_nacl, 773e48354ceSNicholas Bellinger const char *name) 774e48354ceSNicholas Bellinger { 775c7d6a803SChristoph Hellwig struct iscsi_node_acl *acl = 776c7d6a803SChristoph Hellwig container_of(se_nacl, struct iscsi_node_acl, se_node_acl); 777c7d6a803SChristoph Hellwig struct config_group *stats_cg = &se_nacl->acl_fabric_stat_group; 778e48354ceSNicholas Bellinger 77913f6a914SSebastian Andrzej Siewior stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, 780e48354ceSNicholas Bellinger GFP_KERNEL); 781e48354ceSNicholas Bellinger if (!stats_cg->default_groups) { 782e48354ceSNicholas Bellinger pr_err("Unable to allocate memory for" 783e48354ceSNicholas Bellinger " stats_cg->default_groups\n"); 784c7d6a803SChristoph Hellwig return -ENOMEM; 785e48354ceSNicholas Bellinger } 786e48354ceSNicholas Bellinger 787b7eec2cdSAndy Grover stats_cg->default_groups[0] = &acl->node_stat_grps.iscsi_sess_stats_group; 788e48354ceSNicholas Bellinger stats_cg->default_groups[1] = NULL; 789b7eec2cdSAndy Grover config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group, 790e48354ceSNicholas Bellinger "iscsi_sess_stats", &iscsi_stat_sess_cit); 791e48354ceSNicholas Bellinger 792c7d6a803SChristoph Hellwig return 0; 793e48354ceSNicholas Bellinger } 794e48354ceSNicholas Bellinger 795c7d6a803SChristoph Hellwig static void lio_target_cleanup_nodeacl( struct se_node_acl *se_nacl) 796e48354ceSNicholas Bellinger { 797e48354ceSNicholas Bellinger struct iscsi_node_acl *acl = container_of(se_nacl, 798e48354ceSNicholas Bellinger struct iscsi_node_acl, se_node_acl); 799e48354ceSNicholas Bellinger struct config_item *df_item; 800e48354ceSNicholas Bellinger struct config_group *stats_cg; 801e48354ceSNicholas Bellinger int i; 802e48354ceSNicholas Bellinger 803e48354ceSNicholas Bellinger stats_cg = &acl->se_node_acl.acl_fabric_stat_group; 804e48354ceSNicholas Bellinger for (i = 0; stats_cg->default_groups[i]; i++) { 805e48354ceSNicholas Bellinger df_item = &stats_cg->default_groups[i]->cg_item; 806e48354ceSNicholas Bellinger stats_cg->default_groups[i] = NULL; 807e48354ceSNicholas Bellinger config_item_put(df_item); 808e48354ceSNicholas Bellinger } 809e48354ceSNicholas Bellinger kfree(stats_cg->default_groups); 810e48354ceSNicholas Bellinger } 811e48354ceSNicholas Bellinger 812e48354ceSNicholas Bellinger /* End items for lio_target_acl_cit */ 813e48354ceSNicholas Bellinger 814e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_attrib_cit */ 815e48354ceSNicholas Bellinger 816e48354ceSNicholas Bellinger #define DEF_TPG_ATTRIB(name) \ 817e48354ceSNicholas Bellinger \ 8182eafd729SChristoph Hellwig static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \ 819e48354ceSNicholas Bellinger char *page) \ 820e48354ceSNicholas Bellinger { \ 8212eafd729SChristoph Hellwig struct se_portal_group *se_tpg = attrib_to_tpg(item); \ 822e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 823e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 824e48354ceSNicholas Bellinger ssize_t rb; \ 825e48354ceSNicholas Bellinger \ 826e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) \ 827e48354ceSNicholas Bellinger return -EINVAL; \ 828e48354ceSNicholas Bellinger \ 829b7eec2cdSAndy Grover rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \ 830e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 831e48354ceSNicholas Bellinger return rb; \ 832e48354ceSNicholas Bellinger } \ 833e48354ceSNicholas Bellinger \ 8342eafd729SChristoph Hellwig static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\ 8352eafd729SChristoph Hellwig const char *page, size_t count) \ 836e48354ceSNicholas Bellinger { \ 8372eafd729SChristoph Hellwig struct se_portal_group *se_tpg = attrib_to_tpg(item); \ 838e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 839e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 840e48354ceSNicholas Bellinger u32 val; \ 841e48354ceSNicholas Bellinger int ret; \ 842e48354ceSNicholas Bellinger \ 843e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) \ 844e48354ceSNicholas Bellinger return -EINVAL; \ 845e48354ceSNicholas Bellinger \ 846ad7babd2SJörn Engel ret = kstrtou32(page, 0, &val); \ 847ad7babd2SJörn Engel if (ret) \ 848ad7babd2SJörn Engel goto out; \ 849e48354ceSNicholas Bellinger ret = iscsit_ta_##name(tpg, val); \ 850e48354ceSNicholas Bellinger if (ret < 0) \ 851e48354ceSNicholas Bellinger goto out; \ 852e48354ceSNicholas Bellinger \ 853e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 854e48354ceSNicholas Bellinger return count; \ 855e48354ceSNicholas Bellinger out: \ 856e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 857e48354ceSNicholas Bellinger return ret; \ 8582eafd729SChristoph Hellwig } \ 8592eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_tpg_attrib_, name) 860e48354ceSNicholas Bellinger 861e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(authentication); 862e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(login_timeout); 863e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(netif_timeout); 864e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(generate_node_acls); 865e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(default_cmdsn_depth); 866e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(cache_dynamic_acls); 867e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(demo_mode_write_protect); 868e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(prod_mode_write_protect); 8694c54b6cfSThomas Glanzmann DEF_TPG_ATTRIB(demo_mode_discovery); 870d1fa7a1dSNicholas Bellinger DEF_TPG_ATTRIB(default_erl); 8718085176fSSagi Grimberg DEF_TPG_ATTRIB(t10_pi); 872901c04a3SNicholas Bellinger DEF_TPG_ATTRIB(fabric_prot_type); 873a6415cddSDavid Disseldorp DEF_TPG_ATTRIB(tpg_enabled_sendtargets); 874e48354ceSNicholas Bellinger 875e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = { 8762eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_authentication, 8772eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_login_timeout, 8782eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_netif_timeout, 8792eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_generate_node_acls, 8802eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_default_cmdsn_depth, 8812eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_cache_dynamic_acls, 8822eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_demo_mode_write_protect, 8832eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_prod_mode_write_protect, 8842eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_demo_mode_discovery, 8852eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_default_erl, 8862eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_t10_pi, 8872eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_fabric_prot_type, 8882eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets, 889e48354ceSNicholas Bellinger NULL, 890e48354ceSNicholas Bellinger }; 891e48354ceSNicholas Bellinger 892e48354ceSNicholas Bellinger /* End items for lio_target_tpg_attrib_cit */ 893e48354ceSNicholas Bellinger 894c3e51442SNicholas Bellinger /* Start items for lio_target_tpg_auth_cit */ 895c3e51442SNicholas Bellinger 896c3e51442SNicholas Bellinger #define __DEF_TPG_AUTH_STR(prefix, name, flags) \ 8972eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \ 898c3e51442SNicholas Bellinger char *page) \ 899c3e51442SNicholas Bellinger { \ 900c3e51442SNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 901c3e51442SNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 902c3e51442SNicholas Bellinger struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ 903c3e51442SNicholas Bellinger \ 904c3e51442SNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 905c3e51442SNicholas Bellinger return -EPERM; \ 906c3e51442SNicholas Bellinger \ 907c3e51442SNicholas Bellinger return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ 908c3e51442SNicholas Bellinger } \ 909c3e51442SNicholas Bellinger \ 9102eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\ 9112eafd729SChristoph Hellwig const char *page, size_t count) \ 912c3e51442SNicholas Bellinger { \ 913c3e51442SNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 914c3e51442SNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 915c3e51442SNicholas Bellinger struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ 916c3e51442SNicholas Bellinger \ 917c3e51442SNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 918c3e51442SNicholas Bellinger return -EPERM; \ 919c3e51442SNicholas Bellinger \ 92037b32c6fSNicholas Bellinger snprintf(auth->name, sizeof(auth->name), "%s", page); \ 921c3e51442SNicholas Bellinger if (!(strncmp("NULL", auth->name, 4))) \ 922c3e51442SNicholas Bellinger auth->naf_flags &= ~flags; \ 923c3e51442SNicholas Bellinger else \ 924c3e51442SNicholas Bellinger auth->naf_flags |= flags; \ 925c3e51442SNicholas Bellinger \ 926c3e51442SNicholas Bellinger if ((auth->naf_flags & NAF_USERID_IN_SET) && \ 927c3e51442SNicholas Bellinger (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ 928c3e51442SNicholas Bellinger auth->authenticate_target = 1; \ 929c3e51442SNicholas Bellinger else \ 930c3e51442SNicholas Bellinger auth->authenticate_target = 0; \ 931c3e51442SNicholas Bellinger \ 932c3e51442SNicholas Bellinger return count; \ 933c3e51442SNicholas Bellinger } 934c3e51442SNicholas Bellinger 9352eafd729SChristoph Hellwig #define DEF_TPG_AUTH_STR(name, flags) \ 9362eafd729SChristoph Hellwig __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \ 9372eafd729SChristoph Hellwig static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \ 9382eafd729SChristoph Hellwig char *page) \ 9392eafd729SChristoph Hellwig { \ 9402eafd729SChristoph Hellwig return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \ 9412eafd729SChristoph Hellwig } \ 9422eafd729SChristoph Hellwig \ 9432eafd729SChristoph Hellwig static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \ 9442eafd729SChristoph Hellwig const char *page, size_t count) \ 9452eafd729SChristoph Hellwig { \ 9462eafd729SChristoph Hellwig return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \ 9472eafd729SChristoph Hellwig } \ 9482eafd729SChristoph Hellwig \ 9492eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_tpg_auth_, name); 9502eafd729SChristoph Hellwig 9512eafd729SChristoph Hellwig 9522eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(userid, NAF_USERID_SET); 9532eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET); 9542eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); 9552eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); 9562eafd729SChristoph Hellwig 957c3e51442SNicholas Bellinger #define __DEF_TPG_AUTH_INT(prefix, name) \ 9582eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \ 959c3e51442SNicholas Bellinger char *page) \ 960c3e51442SNicholas Bellinger { \ 961c3e51442SNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 962c3e51442SNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 963c3e51442SNicholas Bellinger struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ 964c3e51442SNicholas Bellinger \ 965c3e51442SNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 966c3e51442SNicholas Bellinger return -EPERM; \ 967c3e51442SNicholas Bellinger \ 968c3e51442SNicholas Bellinger return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ 969c3e51442SNicholas Bellinger } 970c3e51442SNicholas Bellinger 971c3e51442SNicholas Bellinger #define DEF_TPG_AUTH_INT(name) \ 972c3e51442SNicholas Bellinger __DEF_TPG_AUTH_INT(tpg_auth, name) \ 9732eafd729SChristoph Hellwig static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \ 974c3e51442SNicholas Bellinger char *page) \ 975c3e51442SNicholas Bellinger { \ 9762eafd729SChristoph Hellwig return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \ 9772eafd729SChristoph Hellwig } \ 9782eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name); 979c3e51442SNicholas Bellinger 980c3e51442SNicholas Bellinger DEF_TPG_AUTH_INT(authenticate_target); 981c3e51442SNicholas Bellinger 982c3e51442SNicholas Bellinger static struct configfs_attribute *lio_target_tpg_auth_attrs[] = { 9832eafd729SChristoph Hellwig &iscsi_tpg_auth_attr_userid, 9842eafd729SChristoph Hellwig &iscsi_tpg_auth_attr_password, 9852eafd729SChristoph Hellwig &iscsi_tpg_auth_attr_authenticate_target, 9862eafd729SChristoph Hellwig &iscsi_tpg_auth_attr_userid_mutual, 9872eafd729SChristoph Hellwig &iscsi_tpg_auth_attr_password_mutual, 988c3e51442SNicholas Bellinger NULL, 989c3e51442SNicholas Bellinger }; 990c3e51442SNicholas Bellinger 991c3e51442SNicholas Bellinger /* End items for lio_target_tpg_auth_cit */ 992c3e51442SNicholas Bellinger 993e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_param_cit */ 994e48354ceSNicholas Bellinger 995e48354ceSNicholas Bellinger #define DEF_TPG_PARAM(name) \ 9962eafd729SChristoph Hellwig static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \ 997e48354ceSNicholas Bellinger char *page) \ 998e48354ceSNicholas Bellinger { \ 9992eafd729SChristoph Hellwig struct se_portal_group *se_tpg = param_to_tpg(item); \ 1000e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 1001e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 1002e48354ceSNicholas Bellinger struct iscsi_param *param; \ 1003e48354ceSNicholas Bellinger ssize_t rb; \ 1004e48354ceSNicholas Bellinger \ 1005e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) \ 1006e48354ceSNicholas Bellinger return -EINVAL; \ 1007e48354ceSNicholas Bellinger \ 1008e48354ceSNicholas Bellinger param = iscsi_find_param_from_key(__stringify(name), \ 1009e48354ceSNicholas Bellinger tpg->param_list); \ 1010e48354ceSNicholas Bellinger if (!param) { \ 1011e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 1012e48354ceSNicholas Bellinger return -EINVAL; \ 1013e48354ceSNicholas Bellinger } \ 1014e48354ceSNicholas Bellinger rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \ 1015e48354ceSNicholas Bellinger \ 1016e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 1017e48354ceSNicholas Bellinger return rb; \ 1018e48354ceSNicholas Bellinger } \ 10192eafd729SChristoph Hellwig static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \ 10202eafd729SChristoph Hellwig const char *page, size_t count) \ 1021e48354ceSNicholas Bellinger { \ 10222eafd729SChristoph Hellwig struct se_portal_group *se_tpg = param_to_tpg(item); \ 1023e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 1024e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 1025e48354ceSNicholas Bellinger char *buf; \ 1026ad7babd2SJörn Engel int ret, len; \ 1027e48354ceSNicholas Bellinger \ 1028e48354ceSNicholas Bellinger buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \ 1029e48354ceSNicholas Bellinger if (!buf) \ 1030e48354ceSNicholas Bellinger return -ENOMEM; \ 1031ad7babd2SJörn Engel len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \ 1032ad7babd2SJörn Engel if (isspace(buf[len-1])) \ 1033ad7babd2SJörn Engel buf[len-1] = '\0'; /* Kill newline */ \ 1034e48354ceSNicholas Bellinger \ 1035e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) { \ 1036e48354ceSNicholas Bellinger kfree(buf); \ 1037e48354ceSNicholas Bellinger return -EINVAL; \ 1038e48354ceSNicholas Bellinger } \ 1039e48354ceSNicholas Bellinger \ 1040e48354ceSNicholas Bellinger ret = iscsi_change_param_value(buf, tpg->param_list, 1); \ 1041e48354ceSNicholas Bellinger if (ret < 0) \ 1042e48354ceSNicholas Bellinger goto out; \ 1043e48354ceSNicholas Bellinger \ 1044e48354ceSNicholas Bellinger kfree(buf); \ 1045e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 1046e48354ceSNicholas Bellinger return count; \ 1047e48354ceSNicholas Bellinger out: \ 1048e48354ceSNicholas Bellinger kfree(buf); \ 1049e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 1050e48354ceSNicholas Bellinger return -EINVAL; \ 10512eafd729SChristoph Hellwig } \ 10522eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_tpg_param_, name) 1053e48354ceSNicholas Bellinger 1054e48354ceSNicholas Bellinger DEF_TPG_PARAM(AuthMethod); 1055e48354ceSNicholas Bellinger DEF_TPG_PARAM(HeaderDigest); 1056e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataDigest); 1057e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxConnections); 1058e48354ceSNicholas Bellinger DEF_TPG_PARAM(TargetAlias); 1059e48354ceSNicholas Bellinger DEF_TPG_PARAM(InitialR2T); 1060e48354ceSNicholas Bellinger DEF_TPG_PARAM(ImmediateData); 1061e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxRecvDataSegmentLength); 1062e004cb25SNicholas Bellinger DEF_TPG_PARAM(MaxXmitDataSegmentLength); 1063e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxBurstLength); 1064e48354ceSNicholas Bellinger DEF_TPG_PARAM(FirstBurstLength); 1065e48354ceSNicholas Bellinger DEF_TPG_PARAM(DefaultTime2Wait); 1066e48354ceSNicholas Bellinger DEF_TPG_PARAM(DefaultTime2Retain); 1067e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxOutstandingR2T); 1068e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataPDUInOrder); 1069e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataSequenceInOrder); 1070e48354ceSNicholas Bellinger DEF_TPG_PARAM(ErrorRecoveryLevel); 1071e48354ceSNicholas Bellinger DEF_TPG_PARAM(IFMarker); 1072e48354ceSNicholas Bellinger DEF_TPG_PARAM(OFMarker); 1073e48354ceSNicholas Bellinger DEF_TPG_PARAM(IFMarkInt); 1074e48354ceSNicholas Bellinger DEF_TPG_PARAM(OFMarkInt); 1075e48354ceSNicholas Bellinger 1076e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_param_attrs[] = { 10772eafd729SChristoph Hellwig &iscsi_tpg_param_attr_AuthMethod, 10782eafd729SChristoph Hellwig &iscsi_tpg_param_attr_HeaderDigest, 10792eafd729SChristoph Hellwig &iscsi_tpg_param_attr_DataDigest, 10802eafd729SChristoph Hellwig &iscsi_tpg_param_attr_MaxConnections, 10812eafd729SChristoph Hellwig &iscsi_tpg_param_attr_TargetAlias, 10822eafd729SChristoph Hellwig &iscsi_tpg_param_attr_InitialR2T, 10832eafd729SChristoph Hellwig &iscsi_tpg_param_attr_ImmediateData, 10842eafd729SChristoph Hellwig &iscsi_tpg_param_attr_MaxRecvDataSegmentLength, 10852eafd729SChristoph Hellwig &iscsi_tpg_param_attr_MaxXmitDataSegmentLength, 10862eafd729SChristoph Hellwig &iscsi_tpg_param_attr_MaxBurstLength, 10872eafd729SChristoph Hellwig &iscsi_tpg_param_attr_FirstBurstLength, 10882eafd729SChristoph Hellwig &iscsi_tpg_param_attr_DefaultTime2Wait, 10892eafd729SChristoph Hellwig &iscsi_tpg_param_attr_DefaultTime2Retain, 10902eafd729SChristoph Hellwig &iscsi_tpg_param_attr_MaxOutstandingR2T, 10912eafd729SChristoph Hellwig &iscsi_tpg_param_attr_DataPDUInOrder, 10922eafd729SChristoph Hellwig &iscsi_tpg_param_attr_DataSequenceInOrder, 10932eafd729SChristoph Hellwig &iscsi_tpg_param_attr_ErrorRecoveryLevel, 10942eafd729SChristoph Hellwig &iscsi_tpg_param_attr_IFMarker, 10952eafd729SChristoph Hellwig &iscsi_tpg_param_attr_OFMarker, 10962eafd729SChristoph Hellwig &iscsi_tpg_param_attr_IFMarkInt, 10972eafd729SChristoph Hellwig &iscsi_tpg_param_attr_OFMarkInt, 1098e48354ceSNicholas Bellinger NULL, 1099e48354ceSNicholas Bellinger }; 1100e48354ceSNicholas Bellinger 1101e48354ceSNicholas Bellinger /* End items for lio_target_tpg_param_cit */ 1102e48354ceSNicholas Bellinger 1103e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_cit */ 1104e48354ceSNicholas Bellinger 11052eafd729SChristoph Hellwig static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page) 1106e48354ceSNicholas Bellinger { 11072eafd729SChristoph Hellwig struct se_portal_group *se_tpg = to_tpg(item); 1108e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, 1109e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); 1110e48354ceSNicholas Bellinger ssize_t len; 1111e48354ceSNicholas Bellinger 1112e48354ceSNicholas Bellinger spin_lock(&tpg->tpg_state_lock); 1113e48354ceSNicholas Bellinger len = sprintf(page, "%d\n", 1114e48354ceSNicholas Bellinger (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0); 1115e48354ceSNicholas Bellinger spin_unlock(&tpg->tpg_state_lock); 1116e48354ceSNicholas Bellinger 1117e48354ceSNicholas Bellinger return len; 1118e48354ceSNicholas Bellinger } 1119e48354ceSNicholas Bellinger 11202eafd729SChristoph Hellwig static ssize_t lio_target_tpg_enable_store(struct config_item *item, 11212eafd729SChristoph Hellwig const char *page, size_t count) 1122e48354ceSNicholas Bellinger { 11232eafd729SChristoph Hellwig struct se_portal_group *se_tpg = to_tpg(item); 1124e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, 1125e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); 1126e48354ceSNicholas Bellinger u32 op; 1127ad7babd2SJörn Engel int ret; 1128e48354ceSNicholas Bellinger 1129ad7babd2SJörn Engel ret = kstrtou32(page, 0, &op); 1130ad7babd2SJörn Engel if (ret) 1131ad7babd2SJörn Engel return ret; 1132e48354ceSNicholas Bellinger if ((op != 1) && (op != 0)) { 1133e48354ceSNicholas Bellinger pr_err("Illegal value for tpg_enable: %u\n", op); 1134e48354ceSNicholas Bellinger return -EINVAL; 1135e48354ceSNicholas Bellinger } 1136e48354ceSNicholas Bellinger 1137e48354ceSNicholas Bellinger ret = iscsit_get_tpg(tpg); 1138e48354ceSNicholas Bellinger if (ret < 0) 1139e48354ceSNicholas Bellinger return -EINVAL; 1140e48354ceSNicholas Bellinger 1141e48354ceSNicholas Bellinger if (op) { 1142e48354ceSNicholas Bellinger ret = iscsit_tpg_enable_portal_group(tpg); 1143e48354ceSNicholas Bellinger if (ret < 0) 1144e48354ceSNicholas Bellinger goto out; 1145e48354ceSNicholas Bellinger } else { 1146e48354ceSNicholas Bellinger /* 1147e48354ceSNicholas Bellinger * iscsit_tpg_disable_portal_group() assumes force=1 1148e48354ceSNicholas Bellinger */ 1149e48354ceSNicholas Bellinger ret = iscsit_tpg_disable_portal_group(tpg, 1); 1150e48354ceSNicholas Bellinger if (ret < 0) 1151e48354ceSNicholas Bellinger goto out; 1152e48354ceSNicholas Bellinger } 1153e48354ceSNicholas Bellinger 1154e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 1155e48354ceSNicholas Bellinger return count; 1156e48354ceSNicholas Bellinger out: 1157e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 1158e48354ceSNicholas Bellinger return -EINVAL; 1159e48354ceSNicholas Bellinger } 1160e48354ceSNicholas Bellinger 1161e48354ceSNicholas Bellinger 11622eafd729SChristoph Hellwig static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item, 1163d4ee46ffSNicholas Bellinger char *page) 1164d4ee46ffSNicholas Bellinger { 11652eafd729SChristoph Hellwig return target_show_dynamic_sessions(to_tpg(item), page); 1166d4ee46ffSNicholas Bellinger } 1167d4ee46ffSNicholas Bellinger 11682eafd729SChristoph Hellwig CONFIGFS_ATTR(lio_target_tpg_, enable); 11692eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions); 1170d4ee46ffSNicholas Bellinger 1171e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_attrs[] = { 11722eafd729SChristoph Hellwig &lio_target_tpg_attr_enable, 11732eafd729SChristoph Hellwig &lio_target_tpg_attr_dynamic_sessions, 1174e48354ceSNicholas Bellinger NULL, 1175e48354ceSNicholas Bellinger }; 1176e48354ceSNicholas Bellinger 1177e48354ceSNicholas Bellinger /* End items for lio_target_tpg_cit */ 1178e48354ceSNicholas Bellinger 1179e48354ceSNicholas Bellinger /* Start items for lio_target_tiqn_cit */ 1180e48354ceSNicholas Bellinger 1181fceb5bc7SChristoph Hellwig static struct se_portal_group *lio_target_tiqn_addtpg( 1182e48354ceSNicholas Bellinger struct se_wwn *wwn, 1183e48354ceSNicholas Bellinger struct config_group *group, 1184e48354ceSNicholas Bellinger const char *name) 1185e48354ceSNicholas Bellinger { 1186e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 1187e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn; 1188ad7babd2SJörn Engel char *tpgt_str; 1189ad7babd2SJörn Engel int ret; 1190ad7babd2SJörn Engel u16 tpgt; 1191e48354ceSNicholas Bellinger 1192e48354ceSNicholas Bellinger tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); 1193e48354ceSNicholas Bellinger /* 1194e48354ceSNicholas Bellinger * Only tpgt_# directory groups can be created below 1195e48354ceSNicholas Bellinger * target/iscsi/iqn.superturodiskarry/ 1196e48354ceSNicholas Bellinger */ 1197e48354ceSNicholas Bellinger tpgt_str = strstr(name, "tpgt_"); 1198e48354ceSNicholas Bellinger if (!tpgt_str) { 1199e48354ceSNicholas Bellinger pr_err("Unable to locate \"tpgt_#\" directory" 1200e48354ceSNicholas Bellinger " group\n"); 1201e48354ceSNicholas Bellinger return NULL; 1202e48354ceSNicholas Bellinger } 1203e48354ceSNicholas Bellinger tpgt_str += 5; /* Skip ahead of "tpgt_" */ 1204ad7babd2SJörn Engel ret = kstrtou16(tpgt_str, 0, &tpgt); 1205ad7babd2SJörn Engel if (ret) 1206ad7babd2SJörn Engel return NULL; 1207e48354ceSNicholas Bellinger 1208e48354ceSNicholas Bellinger tpg = iscsit_alloc_portal_group(tiqn, tpgt); 1209e48354ceSNicholas Bellinger if (!tpg) 1210e48354ceSNicholas Bellinger return NULL; 1211e48354ceSNicholas Bellinger 1212bc0c94b1SNicholas Bellinger ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI); 1213e48354ceSNicholas Bellinger if (ret < 0) 1214e48354ceSNicholas Bellinger return NULL; 1215e48354ceSNicholas Bellinger 1216e48354ceSNicholas Bellinger ret = iscsit_tpg_add_portal_group(tiqn, tpg); 1217e48354ceSNicholas Bellinger if (ret != 0) 1218e48354ceSNicholas Bellinger goto out; 1219e48354ceSNicholas Bellinger 1220e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); 1221e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n", 1222e48354ceSNicholas Bellinger name); 1223e48354ceSNicholas Bellinger return &tpg->tpg_se_tpg; 1224e48354ceSNicholas Bellinger out: 1225e48354ceSNicholas Bellinger core_tpg_deregister(&tpg->tpg_se_tpg); 1226e48354ceSNicholas Bellinger kfree(tpg); 1227e48354ceSNicholas Bellinger return NULL; 1228e48354ceSNicholas Bellinger } 1229e48354ceSNicholas Bellinger 1230fceb5bc7SChristoph Hellwig static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg) 1231e48354ceSNicholas Bellinger { 1232e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 1233e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn; 1234e48354ceSNicholas Bellinger 1235e48354ceSNicholas Bellinger tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); 1236e48354ceSNicholas Bellinger tiqn = tpg->tpg_tiqn; 1237e48354ceSNicholas Bellinger /* 1238e48354ceSNicholas Bellinger * iscsit_tpg_del_portal_group() assumes force=1 1239e48354ceSNicholas Bellinger */ 1240e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n"); 1241e48354ceSNicholas Bellinger iscsit_tpg_del_portal_group(tiqn, tpg, 1); 1242e48354ceSNicholas Bellinger } 1243e48354ceSNicholas Bellinger 1244e48354ceSNicholas Bellinger /* End items for lio_target_tiqn_cit */ 1245e48354ceSNicholas Bellinger 1246e48354ceSNicholas Bellinger /* Start LIO-Target TIQN struct contig_item lio_target_cit */ 1247e48354ceSNicholas Bellinger 12482eafd729SChristoph Hellwig static ssize_t lio_target_wwn_lio_version_show(struct config_item *item, 1249e48354ceSNicholas Bellinger char *page) 1250e48354ceSNicholas Bellinger { 12514c76251eSNicholas Bellinger return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n"); 1252e48354ceSNicholas Bellinger } 1253e48354ceSNicholas Bellinger 12542eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version); 1255e48354ceSNicholas Bellinger 1256e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_wwn_attrs[] = { 12572eafd729SChristoph Hellwig &lio_target_wwn_attr_lio_version, 1258e48354ceSNicholas Bellinger NULL, 1259e48354ceSNicholas Bellinger }; 1260e48354ceSNicholas Bellinger 1261fceb5bc7SChristoph Hellwig static struct se_wwn *lio_target_call_coreaddtiqn( 1262e48354ceSNicholas Bellinger struct target_fabric_configfs *tf, 1263e48354ceSNicholas Bellinger struct config_group *group, 1264e48354ceSNicholas Bellinger const char *name) 1265e48354ceSNicholas Bellinger { 1266e48354ceSNicholas Bellinger struct config_group *stats_cg; 1267e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn; 1268e48354ceSNicholas Bellinger 1269e48354ceSNicholas Bellinger tiqn = iscsit_add_tiqn((unsigned char *)name); 1270e48354ceSNicholas Bellinger if (IS_ERR(tiqn)) 1271e1750ba2SThomas Meyer return ERR_CAST(tiqn); 1272e48354ceSNicholas Bellinger /* 1273e48354ceSNicholas Bellinger * Setup struct iscsi_wwn_stat_grps for se_wwn->fabric_stat_group. 1274e48354ceSNicholas Bellinger */ 1275e48354ceSNicholas Bellinger stats_cg = &tiqn->tiqn_wwn.fabric_stat_group; 1276e48354ceSNicholas Bellinger 127713f6a914SSebastian Andrzej Siewior stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6, 1278e48354ceSNicholas Bellinger GFP_KERNEL); 1279e48354ceSNicholas Bellinger if (!stats_cg->default_groups) { 1280e48354ceSNicholas Bellinger pr_err("Unable to allocate memory for" 1281e48354ceSNicholas Bellinger " stats_cg->default_groups\n"); 1282e48354ceSNicholas Bellinger iscsit_del_tiqn(tiqn); 1283e48354ceSNicholas Bellinger return ERR_PTR(-ENOMEM); 1284e48354ceSNicholas Bellinger } 1285e48354ceSNicholas Bellinger 1286b7eec2cdSAndy Grover stats_cg->default_groups[0] = &tiqn->tiqn_stat_grps.iscsi_instance_group; 1287b7eec2cdSAndy Grover stats_cg->default_groups[1] = &tiqn->tiqn_stat_grps.iscsi_sess_err_group; 1288b7eec2cdSAndy Grover stats_cg->default_groups[2] = &tiqn->tiqn_stat_grps.iscsi_tgt_attr_group; 1289b7eec2cdSAndy Grover stats_cg->default_groups[3] = &tiqn->tiqn_stat_grps.iscsi_login_stats_group; 1290b7eec2cdSAndy Grover stats_cg->default_groups[4] = &tiqn->tiqn_stat_grps.iscsi_logout_stats_group; 1291e48354ceSNicholas Bellinger stats_cg->default_groups[5] = NULL; 1292b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group, 1293e48354ceSNicholas Bellinger "iscsi_instance", &iscsi_stat_instance_cit); 1294b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group, 1295e48354ceSNicholas Bellinger "iscsi_sess_err", &iscsi_stat_sess_err_cit); 1296b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group, 1297e48354ceSNicholas Bellinger "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit); 1298b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group, 1299e48354ceSNicholas Bellinger "iscsi_login_stats", &iscsi_stat_login_cit); 1300b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group, 1301e48354ceSNicholas Bellinger "iscsi_logout_stats", &iscsi_stat_logout_cit); 1302e48354ceSNicholas Bellinger 1303e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); 1304e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:" 1305e48354ceSNicholas Bellinger " %s\n", name); 1306e48354ceSNicholas Bellinger return &tiqn->tiqn_wwn; 1307e48354ceSNicholas Bellinger } 1308e48354ceSNicholas Bellinger 1309fceb5bc7SChristoph Hellwig static void lio_target_call_coredeltiqn( 1310e48354ceSNicholas Bellinger struct se_wwn *wwn) 1311e48354ceSNicholas Bellinger { 1312e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); 1313e48354ceSNicholas Bellinger struct config_item *df_item; 1314e48354ceSNicholas Bellinger struct config_group *stats_cg; 1315e48354ceSNicholas Bellinger int i; 1316e48354ceSNicholas Bellinger 1317e48354ceSNicholas Bellinger stats_cg = &tiqn->tiqn_wwn.fabric_stat_group; 1318e48354ceSNicholas Bellinger for (i = 0; stats_cg->default_groups[i]; i++) { 1319e48354ceSNicholas Bellinger df_item = &stats_cg->default_groups[i]->cg_item; 1320e48354ceSNicholas Bellinger stats_cg->default_groups[i] = NULL; 1321e48354ceSNicholas Bellinger config_item_put(df_item); 1322e48354ceSNicholas Bellinger } 1323e48354ceSNicholas Bellinger kfree(stats_cg->default_groups); 1324e48354ceSNicholas Bellinger 1325e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n", 1326e48354ceSNicholas Bellinger tiqn->tiqn); 1327e48354ceSNicholas Bellinger iscsit_del_tiqn(tiqn); 1328e48354ceSNicholas Bellinger } 1329e48354ceSNicholas Bellinger 1330e48354ceSNicholas Bellinger /* End LIO-Target TIQN struct contig_lio_target_cit */ 1331e48354ceSNicholas Bellinger 1332e48354ceSNicholas Bellinger /* Start lio_target_discovery_auth_cit */ 1333e48354ceSNicholas Bellinger 1334e48354ceSNicholas Bellinger #define DEF_DISC_AUTH_STR(name, flags) \ 1335e48354ceSNicholas Bellinger __DEF_NACL_AUTH_STR(disc, name, flags) \ 13362eafd729SChristoph Hellwig static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \ 1337e48354ceSNicholas Bellinger { \ 13382eafd729SChristoph Hellwig return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\ 1339e48354ceSNicholas Bellinger page); \ 1340e48354ceSNicholas Bellinger } \ 13412eafd729SChristoph Hellwig static ssize_t iscsi_disc_##name##_store(struct config_item *item, \ 13422eafd729SChristoph Hellwig const char *page, size_t count) \ 1343e48354ceSNicholas Bellinger { \ 13442eafd729SChristoph Hellwig return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \ 1345e48354ceSNicholas Bellinger page, count); \ 13462eafd729SChristoph Hellwig \ 13472eafd729SChristoph Hellwig } \ 13482eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_disc_, name) 13492eafd729SChristoph Hellwig 13502eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(userid, NAF_USERID_SET); 13512eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET); 13522eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); 13532eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); 1354e48354ceSNicholas Bellinger 1355e48354ceSNicholas Bellinger #define DEF_DISC_AUTH_INT(name) \ 1356e48354ceSNicholas Bellinger __DEF_NACL_AUTH_INT(disc, name) \ 13572eafd729SChristoph Hellwig static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \ 1358e48354ceSNicholas Bellinger { \ 13592eafd729SChristoph Hellwig return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \ 1360e48354ceSNicholas Bellinger page); \ 13612eafd729SChristoph Hellwig } \ 13622eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_disc_, name) 1363e48354ceSNicholas Bellinger 1364e48354ceSNicholas Bellinger DEF_DISC_AUTH_INT(authenticate_target); 1365e48354ceSNicholas Bellinger 13662eafd729SChristoph Hellwig 13672eafd729SChristoph Hellwig static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item, 1368e48354ceSNicholas Bellinger char *page) 1369e48354ceSNicholas Bellinger { 1370e48354ceSNicholas Bellinger struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth; 1371e48354ceSNicholas Bellinger 1372e48354ceSNicholas Bellinger return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth); 1373e48354ceSNicholas Bellinger } 1374e48354ceSNicholas Bellinger 13752eafd729SChristoph Hellwig static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item, 13762eafd729SChristoph Hellwig const char *page, size_t count) 1377e48354ceSNicholas Bellinger { 1378e48354ceSNicholas Bellinger struct iscsi_param *param; 1379e48354ceSNicholas Bellinger struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg; 1380e48354ceSNicholas Bellinger u32 op; 1381ad7babd2SJörn Engel int err; 1382e48354ceSNicholas Bellinger 1383ad7babd2SJörn Engel err = kstrtou32(page, 0, &op); 1384ad7babd2SJörn Engel if (err) 1385ad7babd2SJörn Engel return -EINVAL; 1386e48354ceSNicholas Bellinger if ((op != 1) && (op != 0)) { 1387e48354ceSNicholas Bellinger pr_err("Illegal value for enforce_discovery_auth:" 1388e48354ceSNicholas Bellinger " %u\n", op); 1389e48354ceSNicholas Bellinger return -EINVAL; 1390e48354ceSNicholas Bellinger } 1391e48354ceSNicholas Bellinger 1392e48354ceSNicholas Bellinger if (!discovery_tpg) { 1393e48354ceSNicholas Bellinger pr_err("iscsit_global->discovery_tpg is NULL\n"); 1394e48354ceSNicholas Bellinger return -EINVAL; 1395e48354ceSNicholas Bellinger } 1396e48354ceSNicholas Bellinger 1397e48354ceSNicholas Bellinger param = iscsi_find_param_from_key(AUTHMETHOD, 1398e48354ceSNicholas Bellinger discovery_tpg->param_list); 1399e48354ceSNicholas Bellinger if (!param) 1400e48354ceSNicholas Bellinger return -EINVAL; 1401e48354ceSNicholas Bellinger 1402e48354ceSNicholas Bellinger if (op) { 1403e48354ceSNicholas Bellinger /* 1404e48354ceSNicholas Bellinger * Reset the AuthMethod key to CHAP. 1405e48354ceSNicholas Bellinger */ 1406e48354ceSNicholas Bellinger if (iscsi_update_param_value(param, CHAP) < 0) 1407e48354ceSNicholas Bellinger return -EINVAL; 1408e48354ceSNicholas Bellinger 1409e48354ceSNicholas Bellinger discovery_tpg->tpg_attrib.authentication = 1; 1410e48354ceSNicholas Bellinger iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1; 1411e48354ceSNicholas Bellinger pr_debug("LIO-CORE[0] Successfully enabled" 1412e48354ceSNicholas Bellinger " authentication enforcement for iSCSI" 1413e48354ceSNicholas Bellinger " Discovery TPG\n"); 1414e48354ceSNicholas Bellinger } else { 1415e48354ceSNicholas Bellinger /* 1416e48354ceSNicholas Bellinger * Reset the AuthMethod key to CHAP,None 1417e48354ceSNicholas Bellinger */ 1418e48354ceSNicholas Bellinger if (iscsi_update_param_value(param, "CHAP,None") < 0) 1419e48354ceSNicholas Bellinger return -EINVAL; 1420e48354ceSNicholas Bellinger 1421e48354ceSNicholas Bellinger discovery_tpg->tpg_attrib.authentication = 0; 1422e48354ceSNicholas Bellinger iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0; 1423e48354ceSNicholas Bellinger pr_debug("LIO-CORE[0] Successfully disabled" 1424e48354ceSNicholas Bellinger " authentication enforcement for iSCSI" 1425e48354ceSNicholas Bellinger " Discovery TPG\n"); 1426e48354ceSNicholas Bellinger } 1427e48354ceSNicholas Bellinger 1428e48354ceSNicholas Bellinger return count; 1429e48354ceSNicholas Bellinger } 1430e48354ceSNicholas Bellinger 14312eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth); 1432e48354ceSNicholas Bellinger 1433e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_discovery_auth_attrs[] = { 14342eafd729SChristoph Hellwig &iscsi_disc_attr_userid, 14352eafd729SChristoph Hellwig &iscsi_disc_attr_password, 14362eafd729SChristoph Hellwig &iscsi_disc_attr_authenticate_target, 14372eafd729SChristoph Hellwig &iscsi_disc_attr_userid_mutual, 14382eafd729SChristoph Hellwig &iscsi_disc_attr_password_mutual, 14392eafd729SChristoph Hellwig &iscsi_disc_attr_enforce_discovery_auth, 1440e48354ceSNicholas Bellinger NULL, 1441e48354ceSNicholas Bellinger }; 1442e48354ceSNicholas Bellinger 1443e48354ceSNicholas Bellinger /* End lio_target_discovery_auth_cit */ 1444e48354ceSNicholas Bellinger 1445e48354ceSNicholas Bellinger /* Start functions for target_core_fabric_ops */ 1446e48354ceSNicholas Bellinger 1447e48354ceSNicholas Bellinger static char *iscsi_get_fabric_name(void) 1448e48354ceSNicholas Bellinger { 1449e48354ceSNicholas Bellinger return "iSCSI"; 1450e48354ceSNicholas Bellinger } 1451e48354ceSNicholas Bellinger 1452e48354ceSNicholas Bellinger static int iscsi_get_cmd_state(struct se_cmd *se_cmd) 1453e48354ceSNicholas Bellinger { 1454e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1455e48354ceSNicholas Bellinger 1456e48354ceSNicholas Bellinger return cmd->i_state; 1457e48354ceSNicholas Bellinger } 1458e48354ceSNicholas Bellinger 1459e48354ceSNicholas Bellinger static u32 lio_sess_get_index(struct se_session *se_sess) 1460e48354ceSNicholas Bellinger { 1461e48354ceSNicholas Bellinger struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1462e48354ceSNicholas Bellinger 1463e48354ceSNicholas Bellinger return sess->session_index; 1464e48354ceSNicholas Bellinger } 1465e48354ceSNicholas Bellinger 1466e48354ceSNicholas Bellinger static u32 lio_sess_get_initiator_sid( 1467e48354ceSNicholas Bellinger struct se_session *se_sess, 1468e48354ceSNicholas Bellinger unsigned char *buf, 1469e48354ceSNicholas Bellinger u32 size) 1470e48354ceSNicholas Bellinger { 1471e48354ceSNicholas Bellinger struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1472e48354ceSNicholas Bellinger /* 1473e48354ceSNicholas Bellinger * iSCSI Initiator Session Identifier from RFC-3720. 1474e48354ceSNicholas Bellinger */ 14755cdf5a87SAndy Shevchenko return snprintf(buf, size, "%6phN", sess->isid); 1476e48354ceSNicholas Bellinger } 1477e48354ceSNicholas Bellinger 1478e48354ceSNicholas Bellinger static int lio_queue_data_in(struct se_cmd *se_cmd) 1479e48354ceSNicholas Bellinger { 1480e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1481e48354ceSNicholas Bellinger 1482e48354ceSNicholas Bellinger cmd->i_state = ISTATE_SEND_DATAIN; 14832ec5a8c1SNicholas Bellinger cmd->conn->conn_transport->iscsit_queue_data_in(cmd->conn, cmd); 14842ec5a8c1SNicholas Bellinger 1485e48354ceSNicholas Bellinger return 0; 1486e48354ceSNicholas Bellinger } 1487e48354ceSNicholas Bellinger 1488e48354ceSNicholas Bellinger static int lio_write_pending(struct se_cmd *se_cmd) 1489e48354ceSNicholas Bellinger { 1490e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 14913e1c81a9SNicholas Bellinger struct iscsi_conn *conn = cmd->conn; 1492e48354ceSNicholas Bellinger 1493e48354ceSNicholas Bellinger if (!cmd->immediate_data && !cmd->unsolicited_data) 14943e1c81a9SNicholas Bellinger return conn->conn_transport->iscsit_get_dataout(conn, cmd, false); 1495e48354ceSNicholas Bellinger 1496e48354ceSNicholas Bellinger return 0; 1497e48354ceSNicholas Bellinger } 1498e48354ceSNicholas Bellinger 1499e48354ceSNicholas Bellinger static int lio_write_pending_status(struct se_cmd *se_cmd) 1500e48354ceSNicholas Bellinger { 1501e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1502e48354ceSNicholas Bellinger int ret; 1503e48354ceSNicholas Bellinger 1504e48354ceSNicholas Bellinger spin_lock_bh(&cmd->istate_lock); 1505e48354ceSNicholas Bellinger ret = !(cmd->cmd_flags & ICF_GOT_LAST_DATAOUT); 1506e48354ceSNicholas Bellinger spin_unlock_bh(&cmd->istate_lock); 1507e48354ceSNicholas Bellinger 1508e48354ceSNicholas Bellinger return ret; 1509e48354ceSNicholas Bellinger } 1510e48354ceSNicholas Bellinger 1511e48354ceSNicholas Bellinger static int lio_queue_status(struct se_cmd *se_cmd) 1512e48354ceSNicholas Bellinger { 1513e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1514e48354ceSNicholas Bellinger 1515e48354ceSNicholas Bellinger cmd->i_state = ISTATE_SEND_STATUS; 15165e8e6b4bSNicholas Bellinger 15175e8e6b4bSNicholas Bellinger if (cmd->se_cmd.scsi_status || cmd->sense_reason) { 15185e8e6b4bSNicholas Bellinger iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state); 15195e8e6b4bSNicholas Bellinger return 0; 15205e8e6b4bSNicholas Bellinger } 15212ec5a8c1SNicholas Bellinger cmd->conn->conn_transport->iscsit_queue_status(cmd->conn, cmd); 15222ec5a8c1SNicholas Bellinger 1523e48354ceSNicholas Bellinger return 0; 1524e48354ceSNicholas Bellinger } 1525e48354ceSNicholas Bellinger 1526b79fafacSJoern Engel static void lio_queue_tm_rsp(struct se_cmd *se_cmd) 1527e48354ceSNicholas Bellinger { 1528e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1529e48354ceSNicholas Bellinger 1530e48354ceSNicholas Bellinger cmd->i_state = ISTATE_SEND_TASKMGTRSP; 1531e48354ceSNicholas Bellinger iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state); 1532e48354ceSNicholas Bellinger } 1533e48354ceSNicholas Bellinger 1534131e6abcSNicholas Bellinger static void lio_aborted_task(struct se_cmd *se_cmd) 1535131e6abcSNicholas Bellinger { 1536131e6abcSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1537131e6abcSNicholas Bellinger 1538131e6abcSNicholas Bellinger cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd); 1539131e6abcSNicholas Bellinger } 1540131e6abcSNicholas Bellinger 15412b6eb609SChristoph Hellwig static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg) 15422b6eb609SChristoph Hellwig { 15432b6eb609SChristoph Hellwig return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); 15442b6eb609SChristoph Hellwig } 15452b6eb609SChristoph Hellwig 1546e48354ceSNicholas Bellinger static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg) 1547e48354ceSNicholas Bellinger { 15482b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn; 1549e48354ceSNicholas Bellinger } 1550e48354ceSNicholas Bellinger 1551e48354ceSNicholas Bellinger static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg) 1552e48354ceSNicholas Bellinger { 15532b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpgt; 1554e48354ceSNicholas Bellinger } 1555e48354ceSNicholas Bellinger 1556e48354ceSNicholas Bellinger static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg) 1557e48354ceSNicholas Bellinger { 15582b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth; 1559e48354ceSNicholas Bellinger } 1560e48354ceSNicholas Bellinger 1561e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg) 1562e48354ceSNicholas Bellinger { 15632b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls; 1564e48354ceSNicholas Bellinger } 1565e48354ceSNicholas Bellinger 1566e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg) 1567e48354ceSNicholas Bellinger { 15682b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls; 1569e48354ceSNicholas Bellinger } 1570e48354ceSNicholas Bellinger 1571e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode_write_protect( 1572e48354ceSNicholas Bellinger struct se_portal_group *se_tpg) 1573e48354ceSNicholas Bellinger { 15742b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect; 1575e48354ceSNicholas Bellinger } 1576e48354ceSNicholas Bellinger 1577e48354ceSNicholas Bellinger static int lio_tpg_check_prod_mode_write_protect( 1578e48354ceSNicholas Bellinger struct se_portal_group *se_tpg) 1579e48354ceSNicholas Bellinger { 15802b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect; 1581e48354ceSNicholas Bellinger } 1582e48354ceSNicholas Bellinger 1583901c04a3SNicholas Bellinger static int lio_tpg_check_prot_fabric_only( 1584901c04a3SNicholas Bellinger struct se_portal_group *se_tpg) 1585901c04a3SNicholas Bellinger { 1586901c04a3SNicholas Bellinger /* 1587901c04a3SNicholas Bellinger * Only report fabric_prot_type if t10_pi has also been enabled 1588901c04a3SNicholas Bellinger * for incoming ib_isert sessions. 1589901c04a3SNicholas Bellinger */ 15902b6eb609SChristoph Hellwig if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi) 1591901c04a3SNicholas Bellinger return 0; 15922b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type; 1593901c04a3SNicholas Bellinger } 1594901c04a3SNicholas Bellinger 1595e48354ceSNicholas Bellinger /* 1596e48354ceSNicholas Bellinger * Called with spin_lock_bh(struct se_portal_group->session_lock) held.. 1597e48354ceSNicholas Bellinger * 1598e48354ceSNicholas Bellinger * Also, this function calls iscsit_inc_session_usage_count() on the 1599e48354ceSNicholas Bellinger * struct iscsi_session in question. 1600e48354ceSNicholas Bellinger */ 1601e48354ceSNicholas Bellinger static int lio_tpg_shutdown_session(struct se_session *se_sess) 1602e48354ceSNicholas Bellinger { 1603e48354ceSNicholas Bellinger struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1604e48354ceSNicholas Bellinger 1605e48354ceSNicholas Bellinger spin_lock(&sess->conn_lock); 1606e48354ceSNicholas Bellinger if (atomic_read(&sess->session_fall_back_to_erl0) || 1607e48354ceSNicholas Bellinger atomic_read(&sess->session_logout) || 1608e48354ceSNicholas Bellinger (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) { 1609e48354ceSNicholas Bellinger spin_unlock(&sess->conn_lock); 1610e48354ceSNicholas Bellinger return 0; 1611e48354ceSNicholas Bellinger } 1612e48354ceSNicholas Bellinger atomic_set(&sess->session_reinstatement, 1); 1613e48354ceSNicholas Bellinger spin_unlock(&sess->conn_lock); 1614e48354ceSNicholas Bellinger 1615e48354ceSNicholas Bellinger iscsit_stop_time2retain_timer(sess); 161699367f01SNicholas Bellinger iscsit_stop_session(sess, 1, 1); 1617e48354ceSNicholas Bellinger 1618e48354ceSNicholas Bellinger return 1; 1619e48354ceSNicholas Bellinger } 1620e48354ceSNicholas Bellinger 1621e48354ceSNicholas Bellinger /* 1622e48354ceSNicholas Bellinger * Calls iscsit_dec_session_usage_count() as inverse of 1623e48354ceSNicholas Bellinger * lio_tpg_shutdown_session() 1624e48354ceSNicholas Bellinger */ 1625e48354ceSNicholas Bellinger static void lio_tpg_close_session(struct se_session *se_sess) 1626e48354ceSNicholas Bellinger { 1627e48354ceSNicholas Bellinger struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1628e48354ceSNicholas Bellinger /* 1629e48354ceSNicholas Bellinger * If the iSCSI Session for the iSCSI Initiator Node exists, 1630e48354ceSNicholas Bellinger * forcefully shutdown the iSCSI NEXUS. 1631e48354ceSNicholas Bellinger */ 1632e48354ceSNicholas Bellinger iscsit_close_session(sess); 1633e48354ceSNicholas Bellinger } 1634e48354ceSNicholas Bellinger 1635e48354ceSNicholas Bellinger static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg) 1636e48354ceSNicholas Bellinger { 16372b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index; 1638e48354ceSNicholas Bellinger } 1639e48354ceSNicholas Bellinger 1640e48354ceSNicholas Bellinger static void lio_set_default_node_attributes(struct se_node_acl *se_acl) 1641e48354ceSNicholas Bellinger { 1642e48354ceSNicholas Bellinger struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl, 1643e48354ceSNicholas Bellinger se_node_acl); 1644d1fa7a1dSNicholas Bellinger struct se_portal_group *se_tpg = se_acl->se_tpg; 1645d1fa7a1dSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, 1646d1fa7a1dSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); 1647e48354ceSNicholas Bellinger 1648b7eec2cdSAndy Grover acl->node_attrib.nacl = acl; 1649d1fa7a1dSNicholas Bellinger iscsit_set_default_node_attribues(acl, tpg); 1650e48354ceSNicholas Bellinger } 1651e48354ceSNicholas Bellinger 16523e1c81a9SNicholas Bellinger static int lio_check_stop_free(struct se_cmd *se_cmd) 16533e1c81a9SNicholas Bellinger { 1654afc16604SBart Van Assche return target_put_sess_cmd(se_cmd); 16553e1c81a9SNicholas Bellinger } 16563e1c81a9SNicholas Bellinger 1657e48354ceSNicholas Bellinger static void lio_release_cmd(struct se_cmd *se_cmd) 1658e48354ceSNicholas Bellinger { 1659e48354ceSNicholas Bellinger struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1660e48354ceSNicholas Bellinger 1661cdb72665SNicholas Bellinger pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd); 1662d703ce2fSNicholas Bellinger iscsit_release_cmd(cmd); 1663e48354ceSNicholas Bellinger } 1664e48354ceSNicholas Bellinger 16659ac8928eSChristoph Hellwig const struct target_core_fabric_ops iscsi_ops = { 16669ac8928eSChristoph Hellwig .module = THIS_MODULE, 16679ac8928eSChristoph Hellwig .name = "iscsi", 1668144bc4c2SChristoph Hellwig .node_acl_size = sizeof(struct iscsi_node_acl), 16699ac8928eSChristoph Hellwig .get_fabric_name = iscsi_get_fabric_name, 16709ac8928eSChristoph Hellwig .tpg_get_wwn = lio_tpg_get_endpoint_wwn, 16719ac8928eSChristoph Hellwig .tpg_get_tag = lio_tpg_get_tag, 16729ac8928eSChristoph Hellwig .tpg_get_default_depth = lio_tpg_get_default_depth, 16739ac8928eSChristoph Hellwig .tpg_check_demo_mode = lio_tpg_check_demo_mode, 16749ac8928eSChristoph Hellwig .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache, 16759ac8928eSChristoph Hellwig .tpg_check_demo_mode_write_protect = 16769ac8928eSChristoph Hellwig lio_tpg_check_demo_mode_write_protect, 16779ac8928eSChristoph Hellwig .tpg_check_prod_mode_write_protect = 16789ac8928eSChristoph Hellwig lio_tpg_check_prod_mode_write_protect, 16799ac8928eSChristoph Hellwig .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only, 16809ac8928eSChristoph Hellwig .tpg_get_inst_index = lio_tpg_get_inst_index, 16819ac8928eSChristoph Hellwig .check_stop_free = lio_check_stop_free, 16829ac8928eSChristoph Hellwig .release_cmd = lio_release_cmd, 16839ac8928eSChristoph Hellwig .shutdown_session = lio_tpg_shutdown_session, 16849ac8928eSChristoph Hellwig .close_session = lio_tpg_close_session, 16859ac8928eSChristoph Hellwig .sess_get_index = lio_sess_get_index, 16869ac8928eSChristoph Hellwig .sess_get_initiator_sid = lio_sess_get_initiator_sid, 16879ac8928eSChristoph Hellwig .write_pending = lio_write_pending, 16889ac8928eSChristoph Hellwig .write_pending_status = lio_write_pending_status, 16899ac8928eSChristoph Hellwig .set_default_node_attributes = lio_set_default_node_attributes, 16909ac8928eSChristoph Hellwig .get_cmd_state = iscsi_get_cmd_state, 16919ac8928eSChristoph Hellwig .queue_data_in = lio_queue_data_in, 16929ac8928eSChristoph Hellwig .queue_status = lio_queue_status, 16939ac8928eSChristoph Hellwig .queue_tm_rsp = lio_queue_tm_rsp, 16949ac8928eSChristoph Hellwig .aborted_task = lio_aborted_task, 16959ac8928eSChristoph Hellwig .fabric_make_wwn = lio_target_call_coreaddtiqn, 16969ac8928eSChristoph Hellwig .fabric_drop_wwn = lio_target_call_coredeltiqn, 16979ac8928eSChristoph Hellwig .fabric_make_tpg = lio_target_tiqn_addtpg, 16989ac8928eSChristoph Hellwig .fabric_drop_tpg = lio_target_tiqn_deltpg, 16999ac8928eSChristoph Hellwig .fabric_make_np = lio_target_call_addnptotpg, 17009ac8928eSChristoph Hellwig .fabric_drop_np = lio_target_call_delnpfromtpg, 1701c7d6a803SChristoph Hellwig .fabric_init_nodeacl = lio_target_init_nodeacl, 1702c7d6a803SChristoph Hellwig .fabric_cleanup_nodeacl = lio_target_cleanup_nodeacl, 1703e48354ceSNicholas Bellinger 17049ac8928eSChristoph Hellwig .tfc_discovery_attrs = lio_target_discovery_auth_attrs, 17059ac8928eSChristoph Hellwig .tfc_wwn_attrs = lio_target_wwn_attrs, 17069ac8928eSChristoph Hellwig .tfc_tpg_base_attrs = lio_target_tpg_attrs, 17079ac8928eSChristoph Hellwig .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs, 17089ac8928eSChristoph Hellwig .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs, 17099ac8928eSChristoph Hellwig .tfc_tpg_param_attrs = lio_target_tpg_param_attrs, 17109ac8928eSChristoph Hellwig .tfc_tpg_np_base_attrs = lio_target_portal_attrs, 17119ac8928eSChristoph Hellwig .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs, 17129ac8928eSChristoph Hellwig .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs, 17139ac8928eSChristoph Hellwig .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs, 17149ac8928eSChristoph Hellwig .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs, 17159ac8928eSChristoph Hellwig }; 1716