1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 2e48354ceSNicholas Bellinger /******************************************************************************* 3e48354ceSNicholas Bellinger * This file contains the configfs implementation for iSCSI Target mode 4e48354ceSNicholas Bellinger * from the LIO-Target Project. 5e48354ceSNicholas Bellinger * 64c76251eSNicholas Bellinger * (c) Copyright 2007-2013 Datera, Inc. 7e48354ceSNicholas Bellinger * 8e48354ceSNicholas Bellinger * Author: Nicholas A. Bellinger <nab@linux-iscsi.org> 9e48354ceSNicholas Bellinger * 10e48354ceSNicholas Bellinger ****************************************************************************/ 11e48354ceSNicholas Bellinger 12e48354ceSNicholas Bellinger #include <linux/configfs.h> 13ad7babd2SJörn Engel #include <linux/ctype.h> 14c53181afSPaul Gortmaker #include <linux/export.h> 15c3bc93daSStephen Rothwell #include <linux/inet.h> 168dcf07beSBart Van Assche #include <linux/module.h> 178dcf07beSBart Van Assche #include <net/ipv6.h> 18e48354ceSNicholas Bellinger #include <target/target_core_base.h> 19c4795fb2SChristoph Hellwig #include <target/target_core_fabric.h> 202ec5a8c1SNicholas Bellinger #include <target/iscsi/iscsi_transport.h> 2167f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_core.h> 22e48354ceSNicholas Bellinger #include "iscsi_target_parameters.h" 23e48354ceSNicholas Bellinger #include "iscsi_target_device.h" 24e48354ceSNicholas Bellinger #include "iscsi_target_erl0.h" 25e48354ceSNicholas Bellinger #include "iscsi_target_nodeattrib.h" 26e48354ceSNicholas Bellinger #include "iscsi_target_tpg.h" 27e48354ceSNicholas Bellinger #include "iscsi_target_util.h" 28e48354ceSNicholas Bellinger #include "iscsi_target.h" 2967f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_stat.h> 30e48354ceSNicholas Bellinger 31e48354ceSNicholas Bellinger 32e48354ceSNicholas Bellinger /* Start items for lio_target_portal_cit */ 33e48354ceSNicholas Bellinger 342eafd729SChristoph Hellwig static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item) 35e48354ceSNicholas Bellinger { 362eafd729SChristoph Hellwig return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np); 372eafd729SChristoph Hellwig } 382eafd729SChristoph Hellwig 39d4b3fa4bSNicholas Bellinger static ssize_t lio_target_np_driver_show(struct config_item *item, char *page, 40d4b3fa4bSNicholas Bellinger enum iscsit_transport_type type) 412eafd729SChristoph Hellwig { 422eafd729SChristoph Hellwig struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); 43d4b3fa4bSNicholas Bellinger struct iscsi_tpg_np *tpg_np_new; 44e48354ceSNicholas Bellinger ssize_t rb; 45e48354ceSNicholas Bellinger 46d4b3fa4bSNicholas Bellinger tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type); 47d4b3fa4bSNicholas Bellinger if (tpg_np_new) 48e48354ceSNicholas Bellinger rb = sprintf(page, "1\n"); 49e48354ceSNicholas Bellinger else 50e48354ceSNicholas Bellinger rb = sprintf(page, "0\n"); 51e48354ceSNicholas Bellinger 52e48354ceSNicholas Bellinger return rb; 53e48354ceSNicholas Bellinger } 54e48354ceSNicholas Bellinger 55d4b3fa4bSNicholas Bellinger static ssize_t lio_target_np_driver_store(struct config_item *item, 56d4b3fa4bSNicholas Bellinger const char *page, size_t count, enum iscsit_transport_type type, 57d4b3fa4bSNicholas Bellinger const char *mod_name) 58e48354ceSNicholas Bellinger { 592eafd729SChristoph Hellwig struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); 60e48354ceSNicholas Bellinger struct iscsi_np *np; 61e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 62d4b3fa4bSNicholas Bellinger struct iscsi_tpg_np *tpg_np_new = NULL; 63e48354ceSNicholas Bellinger u32 op; 64d4b3fa4bSNicholas Bellinger int rc; 65e48354ceSNicholas Bellinger 66d4b3fa4bSNicholas Bellinger rc = kstrtou32(page, 0, &op); 67d4b3fa4bSNicholas Bellinger if (rc) 68d4b3fa4bSNicholas Bellinger return rc; 69e48354ceSNicholas Bellinger if ((op != 1) && (op != 0)) { 70e48354ceSNicholas Bellinger pr_err("Illegal value for tpg_enable: %u\n", op); 71e48354ceSNicholas Bellinger return -EINVAL; 72e48354ceSNicholas Bellinger } 73e48354ceSNicholas Bellinger np = tpg_np->tpg_np; 74e48354ceSNicholas Bellinger if (!np) { 75e48354ceSNicholas Bellinger pr_err("Unable to locate struct iscsi_np from" 76e48354ceSNicholas Bellinger " struct iscsi_tpg_np\n"); 77e48354ceSNicholas Bellinger return -EINVAL; 78e48354ceSNicholas Bellinger } 79e48354ceSNicholas Bellinger 80e48354ceSNicholas Bellinger tpg = tpg_np->tpg; 81e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) 82e48354ceSNicholas Bellinger return -EINVAL; 83e48354ceSNicholas Bellinger 84e48354ceSNicholas Bellinger if (op) { 85d4b3fa4bSNicholas Bellinger if (strlen(mod_name)) { 86d4b3fa4bSNicholas Bellinger rc = request_module(mod_name); 87d4b3fa4bSNicholas Bellinger if (rc != 0) { 88d4b3fa4bSNicholas Bellinger pr_warn("Unable to request_module for %s\n", 89d4b3fa4bSNicholas Bellinger mod_name); 90d4b3fa4bSNicholas Bellinger rc = 0; 91d4b3fa4bSNicholas Bellinger } 92d4b3fa4bSNicholas Bellinger } 93d4b3fa4bSNicholas Bellinger 94d4b3fa4bSNicholas Bellinger tpg_np_new = iscsit_tpg_add_network_portal(tpg, 95d4b3fa4bSNicholas Bellinger &np->np_sockaddr, tpg_np, type); 9683337e54SVarun Prakash if (IS_ERR(tpg_np_new)) { 9783337e54SVarun Prakash rc = PTR_ERR(tpg_np_new); 98e48354ceSNicholas Bellinger goto out; 9983337e54SVarun Prakash } 100e48354ceSNicholas Bellinger } else { 101d4b3fa4bSNicholas Bellinger tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type); 102d4b3fa4bSNicholas Bellinger if (tpg_np_new) { 103d4b3fa4bSNicholas Bellinger rc = iscsit_tpg_del_network_portal(tpg, tpg_np_new); 104d4b3fa4bSNicholas Bellinger if (rc < 0) 105e48354ceSNicholas Bellinger goto out; 106d4b3fa4bSNicholas Bellinger } 107e48354ceSNicholas Bellinger } 108e48354ceSNicholas Bellinger 109e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 110e48354ceSNicholas Bellinger return count; 111e48354ceSNicholas Bellinger out: 112e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 113d4b3fa4bSNicholas Bellinger return rc; 114e48354ceSNicholas Bellinger } 115e48354ceSNicholas Bellinger 1162eafd729SChristoph Hellwig static ssize_t lio_target_np_iser_show(struct config_item *item, char *page) 11772438cddSNicholas Bellinger { 118d4b3fa4bSNicholas Bellinger return lio_target_np_driver_show(item, page, ISCSI_INFINIBAND); 11972438cddSNicholas Bellinger } 12072438cddSNicholas Bellinger 1212eafd729SChristoph Hellwig static ssize_t lio_target_np_iser_store(struct config_item *item, 1222eafd729SChristoph Hellwig const char *page, size_t count) 12372438cddSNicholas Bellinger { 124d4b3fa4bSNicholas Bellinger return lio_target_np_driver_store(item, page, count, 125d4b3fa4bSNicholas Bellinger ISCSI_INFINIBAND, "ib_isert"); 126d4b3fa4bSNicholas Bellinger } 127d4b3fa4bSNicholas Bellinger CONFIGFS_ATTR(lio_target_np_, iser); 12872438cddSNicholas Bellinger 129ff7199b0SNicholas Bellinger static ssize_t lio_target_np_cxgbit_show(struct config_item *item, char *page) 1301c46960eSVarun Prakash { 131ff7199b0SNicholas Bellinger return lio_target_np_driver_show(item, page, ISCSI_CXGBIT); 1321c46960eSVarun Prakash } 1331c46960eSVarun Prakash 134ff7199b0SNicholas Bellinger static ssize_t lio_target_np_cxgbit_store(struct config_item *item, 1351c46960eSVarun Prakash const char *page, size_t count) 1361c46960eSVarun Prakash { 137d4b3fa4bSNicholas Bellinger return lio_target_np_driver_store(item, page, count, 138ff7199b0SNicholas Bellinger ISCSI_CXGBIT, "cxgbit"); 1391c46960eSVarun Prakash } 140ff7199b0SNicholas Bellinger CONFIGFS_ATTR(lio_target_np_, cxgbit); 14172438cddSNicholas Bellinger 142e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_portal_attrs[] = { 1432eafd729SChristoph Hellwig &lio_target_np_attr_iser, 144ff7199b0SNicholas Bellinger &lio_target_np_attr_cxgbit, 145e48354ceSNicholas Bellinger NULL, 146e48354ceSNicholas Bellinger }; 147e48354ceSNicholas Bellinger 148e48354ceSNicholas Bellinger /* Stop items for lio_target_portal_cit */ 149e48354ceSNicholas Bellinger 150e48354ceSNicholas Bellinger /* Start items for lio_target_np_cit */ 151e48354ceSNicholas Bellinger 152e48354ceSNicholas Bellinger #define MAX_PORTAL_LEN 256 153e48354ceSNicholas Bellinger 154fceb5bc7SChristoph Hellwig static struct se_tpg_np *lio_target_call_addnptotpg( 155e48354ceSNicholas Bellinger struct se_portal_group *se_tpg, 156e48354ceSNicholas Bellinger struct config_group *group, 157e48354ceSNicholas Bellinger const char *name) 158e48354ceSNicholas Bellinger { 159e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 160e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np; 161e48354ceSNicholas Bellinger char *str, *str2, *ip_str, *port_str; 1624459e042SSagi Grimberg struct sockaddr_storage sockaddr = { }; 163e48354ceSNicholas Bellinger int ret; 164c22659fbSChaitanya Kulkarni char buf[MAX_PORTAL_LEN + 1] = { }; 165e48354ceSNicholas Bellinger 166e48354ceSNicholas Bellinger if (strlen(name) > MAX_PORTAL_LEN) { 167e48354ceSNicholas Bellinger pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n", 168e48354ceSNicholas Bellinger (int)strlen(name), MAX_PORTAL_LEN); 169e48354ceSNicholas Bellinger return ERR_PTR(-EOVERFLOW); 170e48354ceSNicholas Bellinger } 1717bbb654eSNicholas Bellinger snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name); 172e48354ceSNicholas Bellinger 173e48354ceSNicholas Bellinger str = strstr(buf, "["); 174e48354ceSNicholas Bellinger if (str) { 175e48354ceSNicholas Bellinger str2 = strstr(str, "]"); 176e48354ceSNicholas Bellinger if (!str2) { 177e48354ceSNicholas Bellinger pr_err("Unable to locate trailing \"]\"" 178e48354ceSNicholas Bellinger " in IPv6 iSCSI network portal address\n"); 179e48354ceSNicholas Bellinger return ERR_PTR(-EINVAL); 180e48354ceSNicholas Bellinger } 1814459e042SSagi Grimberg 1824459e042SSagi Grimberg ip_str = str + 1; /* Skip over leading "[" */ 18376c28f1fSAndy Grover *str2 = '\0'; /* Terminate the unbracketed IPv6 address */ 18476c28f1fSAndy Grover str2++; /* Skip over the \0 */ 1854459e042SSagi Grimberg 186e48354ceSNicholas Bellinger port_str = strstr(str2, ":"); 187e48354ceSNicholas Bellinger if (!port_str) { 188e48354ceSNicholas Bellinger pr_err("Unable to locate \":port\"" 189e48354ceSNicholas Bellinger " in IPv6 iSCSI network portal address\n"); 190e48354ceSNicholas Bellinger return ERR_PTR(-EINVAL); 191e48354ceSNicholas Bellinger } 192e48354ceSNicholas Bellinger *port_str = '\0'; /* Terminate string for IP */ 193e48354ceSNicholas Bellinger port_str++; /* Skip over ":" */ 194e48354ceSNicholas Bellinger } else { 1954459e042SSagi Grimberg ip_str = &buf[0]; 196e48354ceSNicholas Bellinger port_str = strstr(ip_str, ":"); 197e48354ceSNicholas Bellinger if (!port_str) { 198e48354ceSNicholas Bellinger pr_err("Unable to locate \":port\"" 199e48354ceSNicholas Bellinger " in IPv4 iSCSI network portal address\n"); 200e48354ceSNicholas Bellinger return ERR_PTR(-EINVAL); 201e48354ceSNicholas Bellinger } 202e48354ceSNicholas Bellinger *port_str = '\0'; /* Terminate string for IP */ 203e48354ceSNicholas Bellinger port_str++; /* Skip over ":" */ 2044459e042SSagi Grimberg } 205e48354ceSNicholas Bellinger 2064459e042SSagi Grimberg ret = inet_pton_with_scope(&init_net, AF_UNSPEC, ip_str, 2074459e042SSagi Grimberg port_str, &sockaddr); 2084459e042SSagi Grimberg if (ret) { 2094459e042SSagi Grimberg pr_err("malformed ip/port passed: %s\n", name); 210e48354ceSNicholas Bellinger return ERR_PTR(ret); 211e48354ceSNicholas Bellinger } 2124459e042SSagi Grimberg 213e48354ceSNicholas Bellinger tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); 214e48354ceSNicholas Bellinger ret = iscsit_get_tpg(tpg); 215e48354ceSNicholas Bellinger if (ret < 0) 216e48354ceSNicholas Bellinger return ERR_PTR(-EINVAL); 217e48354ceSNicholas Bellinger 218e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu" 219e48354ceSNicholas Bellinger " PORTAL: %s\n", 220e48354ceSNicholas Bellinger config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), 221e48354ceSNicholas Bellinger tpg->tpgt, name); 222e48354ceSNicholas Bellinger /* 223e48354ceSNicholas Bellinger * Assume ISCSI_TCP by default. Other network portals for other 224e48354ceSNicholas Bellinger * iSCSI fabrics: 225e48354ceSNicholas Bellinger * 226e48354ceSNicholas Bellinger * Traditional iSCSI over SCTP (initial support) 227e48354ceSNicholas Bellinger * iSER/TCP (TODO, hardware available) 228e48354ceSNicholas Bellinger * iSER/SCTP (TODO, software emulation with osc-iwarp) 229e48354ceSNicholas Bellinger * iSER/IB (TODO, hardware available) 230e48354ceSNicholas Bellinger * 23120879696SMasanari Iida * can be enabled with attributes under 232e48354ceSNicholas Bellinger * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/ 233e48354ceSNicholas Bellinger * 234e48354ceSNicholas Bellinger */ 23576c28f1fSAndy Grover tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL, 236e48354ceSNicholas Bellinger ISCSI_TCP); 237e48354ceSNicholas Bellinger if (IS_ERR(tpg_np)) { 238e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 239e1750ba2SThomas Meyer return ERR_CAST(tpg_np); 240e48354ceSNicholas Bellinger } 241e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n"); 242e48354ceSNicholas Bellinger 243e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 244e48354ceSNicholas Bellinger return &tpg_np->se_tpg_np; 245e48354ceSNicholas Bellinger } 246e48354ceSNicholas Bellinger 247e48354ceSNicholas Bellinger static void lio_target_call_delnpfromtpg( 248e48354ceSNicholas Bellinger struct se_tpg_np *se_tpg_np) 249e48354ceSNicholas Bellinger { 250e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 251e48354ceSNicholas Bellinger struct iscsi_tpg_np *tpg_np; 252e48354ceSNicholas Bellinger struct se_portal_group *se_tpg; 253e48354ceSNicholas Bellinger int ret; 254e48354ceSNicholas Bellinger 255e48354ceSNicholas Bellinger tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np); 256e48354ceSNicholas Bellinger tpg = tpg_np->tpg; 257e48354ceSNicholas Bellinger ret = iscsit_get_tpg(tpg); 258e48354ceSNicholas Bellinger if (ret < 0) 259e48354ceSNicholas Bellinger return; 260e48354ceSNicholas Bellinger 261e48354ceSNicholas Bellinger se_tpg = &tpg->tpg_se_tpg; 262e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu" 26369d75574SAndy Grover " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), 26469d75574SAndy Grover tpg->tpgt, &tpg_np->tpg_np->np_sockaddr); 265e48354ceSNicholas Bellinger 266e48354ceSNicholas Bellinger ret = iscsit_tpg_del_network_portal(tpg, tpg_np); 267e48354ceSNicholas Bellinger if (ret < 0) 268e48354ceSNicholas Bellinger goto out; 269e48354ceSNicholas Bellinger 270e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n"); 271e48354ceSNicholas Bellinger out: 272e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 273e48354ceSNicholas Bellinger } 274e48354ceSNicholas Bellinger 275e48354ceSNicholas Bellinger /* End items for lio_target_np_cit */ 276e48354ceSNicholas Bellinger 277e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_attrib_cit */ 278e48354ceSNicholas Bellinger 2792eafd729SChristoph Hellwig #define ISCSI_NACL_ATTR(name) \ 2802eafd729SChristoph Hellwig static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\ 281e48354ceSNicholas Bellinger char *page) \ 282e48354ceSNicholas Bellinger { \ 2832eafd729SChristoph Hellwig struct se_node_acl *se_nacl = attrib_to_nacl(item); \ 284e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ 285e48354ceSNicholas Bellinger se_node_acl); \ 286e48354ceSNicholas Bellinger \ 287b7eec2cdSAndy Grover return sprintf(page, "%u\n", nacl->node_attrib.name); \ 288e48354ceSNicholas Bellinger } \ 289e48354ceSNicholas Bellinger \ 2902eafd729SChristoph Hellwig static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\ 2912eafd729SChristoph Hellwig const char *page, size_t count) \ 292e48354ceSNicholas Bellinger { \ 2932eafd729SChristoph Hellwig struct se_node_acl *se_nacl = attrib_to_nacl(item); \ 294e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ 295e48354ceSNicholas Bellinger se_node_acl); \ 296e48354ceSNicholas Bellinger u32 val; \ 297e48354ceSNicholas Bellinger int ret; \ 298e48354ceSNicholas Bellinger \ 299ad7babd2SJörn Engel ret = kstrtou32(page, 0, &val); \ 300ad7babd2SJörn Engel if (ret) \ 301ad7babd2SJörn Engel return ret; \ 302e48354ceSNicholas Bellinger ret = iscsit_na_##name(nacl, val); \ 303e48354ceSNicholas Bellinger if (ret < 0) \ 304e48354ceSNicholas Bellinger return ret; \ 305e48354ceSNicholas Bellinger \ 306e48354ceSNicholas Bellinger return count; \ 3072eafd729SChristoph Hellwig } \ 3082eafd729SChristoph Hellwig \ 3092eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_nacl_attrib_, name) 310e48354ceSNicholas Bellinger 3112eafd729SChristoph Hellwig ISCSI_NACL_ATTR(dataout_timeout); 3122eafd729SChristoph Hellwig ISCSI_NACL_ATTR(dataout_timeout_retries); 3132eafd729SChristoph Hellwig ISCSI_NACL_ATTR(default_erl); 3142eafd729SChristoph Hellwig ISCSI_NACL_ATTR(nopin_timeout); 3152eafd729SChristoph Hellwig ISCSI_NACL_ATTR(nopin_response_timeout); 3162eafd729SChristoph Hellwig ISCSI_NACL_ATTR(random_datain_pdu_offsets); 3172eafd729SChristoph Hellwig ISCSI_NACL_ATTR(random_datain_seq_offsets); 3182eafd729SChristoph Hellwig ISCSI_NACL_ATTR(random_r2t_offsets); 319e48354ceSNicholas Bellinger 320e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = { 3212eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_dataout_timeout, 3222eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_dataout_timeout_retries, 3232eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_default_erl, 3242eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_nopin_timeout, 3252eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_nopin_response_timeout, 3262eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_random_datain_pdu_offsets, 3272eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_random_datain_seq_offsets, 3282eafd729SChristoph Hellwig &iscsi_nacl_attrib_attr_random_r2t_offsets, 329e48354ceSNicholas Bellinger NULL, 330e48354ceSNicholas Bellinger }; 331e48354ceSNicholas Bellinger 332e48354ceSNicholas Bellinger /* End items for lio_target_nacl_attrib_cit */ 333e48354ceSNicholas Bellinger 334e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_auth_cit */ 335e48354ceSNicholas Bellinger 336e48354ceSNicholas Bellinger #define __DEF_NACL_AUTH_STR(prefix, name, flags) \ 3372eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show( \ 338e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl, \ 339e48354ceSNicholas Bellinger char *page) \ 340e48354ceSNicholas Bellinger { \ 341e48354ceSNicholas Bellinger struct iscsi_node_auth *auth = &nacl->node_auth; \ 342e48354ceSNicholas Bellinger \ 343e48354ceSNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 344e48354ceSNicholas Bellinger return -EPERM; \ 345e48354ceSNicholas Bellinger return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ 346e48354ceSNicholas Bellinger } \ 347e48354ceSNicholas Bellinger \ 3482eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_store( \ 349e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl, \ 350e48354ceSNicholas Bellinger const char *page, \ 351e48354ceSNicholas Bellinger size_t count) \ 352e48354ceSNicholas Bellinger { \ 353e48354ceSNicholas Bellinger struct iscsi_node_auth *auth = &nacl->node_auth; \ 354e48354ceSNicholas Bellinger \ 355e48354ceSNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 356e48354ceSNicholas Bellinger return -EPERM; \ 3572306bfb2SEric Seppanen if (count >= sizeof(auth->name)) \ 3582306bfb2SEric Seppanen return -EINVAL; \ 3590fbfc46fSJörn Engel snprintf(auth->name, sizeof(auth->name), "%s", page); \ 360e48354ceSNicholas Bellinger if (!strncmp("NULL", auth->name, 4)) \ 361e48354ceSNicholas Bellinger auth->naf_flags &= ~flags; \ 362e48354ceSNicholas Bellinger else \ 363e48354ceSNicholas Bellinger auth->naf_flags |= flags; \ 364e48354ceSNicholas Bellinger \ 365e48354ceSNicholas Bellinger if ((auth->naf_flags & NAF_USERID_IN_SET) && \ 366e48354ceSNicholas Bellinger (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ 367e48354ceSNicholas Bellinger auth->authenticate_target = 1; \ 368e48354ceSNicholas Bellinger else \ 369e48354ceSNicholas Bellinger auth->authenticate_target = 0; \ 370e48354ceSNicholas Bellinger \ 371e48354ceSNicholas Bellinger return count; \ 372e48354ceSNicholas Bellinger } 373e48354ceSNicholas Bellinger 3742eafd729SChristoph Hellwig #define DEF_NACL_AUTH_STR(name, flags) \ 3752eafd729SChristoph Hellwig __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \ 3762eafd729SChristoph Hellwig static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \ 3772eafd729SChristoph Hellwig char *page) \ 3782eafd729SChristoph Hellwig { \ 3792eafd729SChristoph Hellwig struct se_node_acl *nacl = auth_to_nacl(item); \ 3802eafd729SChristoph Hellwig return __iscsi_nacl_auth_##name##_show(container_of(nacl, \ 3812eafd729SChristoph Hellwig struct iscsi_node_acl, se_node_acl), page); \ 3822eafd729SChristoph Hellwig } \ 3832eafd729SChristoph Hellwig static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \ 3842eafd729SChristoph Hellwig const char *page, size_t count) \ 3852eafd729SChristoph Hellwig { \ 3862eafd729SChristoph Hellwig struct se_node_acl *nacl = auth_to_nacl(item); \ 3872eafd729SChristoph Hellwig return __iscsi_nacl_auth_##name##_store(container_of(nacl, \ 3882eafd729SChristoph Hellwig struct iscsi_node_acl, se_node_acl), page, count); \ 3892eafd729SChristoph Hellwig } \ 3902eafd729SChristoph Hellwig \ 3912eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_nacl_auth_, name) 3922eafd729SChristoph Hellwig 3932eafd729SChristoph Hellwig /* 3942eafd729SChristoph Hellwig * One-way authentication userid 3952eafd729SChristoph Hellwig */ 3962eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(userid, NAF_USERID_SET); 3972eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET); 3982eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); 3992eafd729SChristoph Hellwig DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); 4002eafd729SChristoph Hellwig 401e48354ceSNicholas Bellinger #define __DEF_NACL_AUTH_INT(prefix, name) \ 4022eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show( \ 403e48354ceSNicholas Bellinger struct iscsi_node_acl *nacl, \ 404e48354ceSNicholas Bellinger char *page) \ 405e48354ceSNicholas Bellinger { \ 406e48354ceSNicholas Bellinger struct iscsi_node_auth *auth = &nacl->node_auth; \ 407e48354ceSNicholas Bellinger \ 408e48354ceSNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 409e48354ceSNicholas Bellinger return -EPERM; \ 410e48354ceSNicholas Bellinger \ 411e48354ceSNicholas Bellinger return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ 412e48354ceSNicholas Bellinger } 413e48354ceSNicholas Bellinger 414e48354ceSNicholas Bellinger #define DEF_NACL_AUTH_INT(name) \ 415e48354ceSNicholas Bellinger __DEF_NACL_AUTH_INT(nacl_auth, name) \ 4162eafd729SChristoph Hellwig static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \ 417e48354ceSNicholas Bellinger char *page) \ 418e48354ceSNicholas Bellinger { \ 4192eafd729SChristoph Hellwig struct se_node_acl *nacl = auth_to_nacl(item); \ 4202eafd729SChristoph Hellwig return __iscsi_nacl_auth_##name##_show(container_of(nacl, \ 421e48354ceSNicholas Bellinger struct iscsi_node_acl, se_node_acl), page); \ 4222eafd729SChristoph Hellwig } \ 4232eafd729SChristoph Hellwig \ 4242eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name) 425e48354ceSNicholas Bellinger 426e48354ceSNicholas Bellinger DEF_NACL_AUTH_INT(authenticate_target); 427e48354ceSNicholas Bellinger 428e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_auth_attrs[] = { 4292eafd729SChristoph Hellwig &iscsi_nacl_auth_attr_userid, 4302eafd729SChristoph Hellwig &iscsi_nacl_auth_attr_password, 4312eafd729SChristoph Hellwig &iscsi_nacl_auth_attr_authenticate_target, 4322eafd729SChristoph Hellwig &iscsi_nacl_auth_attr_userid_mutual, 4332eafd729SChristoph Hellwig &iscsi_nacl_auth_attr_password_mutual, 434e48354ceSNicholas Bellinger NULL, 435e48354ceSNicholas Bellinger }; 436e48354ceSNicholas Bellinger 437e48354ceSNicholas Bellinger /* End items for lio_target_nacl_auth_cit */ 438e48354ceSNicholas Bellinger 439e48354ceSNicholas Bellinger /* Start items for lio_target_nacl_param_cit */ 440e48354ceSNicholas Bellinger 4412eafd729SChristoph Hellwig #define ISCSI_NACL_PARAM(name) \ 4422eafd729SChristoph Hellwig static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \ 443e48354ceSNicholas Bellinger char *page) \ 444e48354ceSNicholas Bellinger { \ 4452eafd729SChristoph Hellwig struct se_node_acl *se_nacl = param_to_nacl(item); \ 446e48354ceSNicholas Bellinger struct iscsi_session *sess; \ 447e48354ceSNicholas Bellinger struct se_session *se_sess; \ 448e48354ceSNicholas Bellinger ssize_t rb; \ 449e48354ceSNicholas Bellinger \ 450e48354ceSNicholas Bellinger spin_lock_bh(&se_nacl->nacl_sess_lock); \ 451e48354ceSNicholas Bellinger se_sess = se_nacl->nacl_sess; \ 452e48354ceSNicholas Bellinger if (!se_sess) { \ 453e48354ceSNicholas Bellinger rb = snprintf(page, PAGE_SIZE, \ 454e48354ceSNicholas Bellinger "No Active iSCSI Session\n"); \ 455e48354ceSNicholas Bellinger } else { \ 456e48354ceSNicholas Bellinger sess = se_sess->fabric_sess_ptr; \ 457e48354ceSNicholas Bellinger rb = snprintf(page, PAGE_SIZE, "%u\n", \ 458e48354ceSNicholas Bellinger (u32)sess->sess_ops->name); \ 459e48354ceSNicholas Bellinger } \ 460e48354ceSNicholas Bellinger spin_unlock_bh(&se_nacl->nacl_sess_lock); \ 461e48354ceSNicholas Bellinger \ 462e48354ceSNicholas Bellinger return rb; \ 4632eafd729SChristoph Hellwig } \ 4642eafd729SChristoph Hellwig \ 4652eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_nacl_param_, name) 466e48354ceSNicholas Bellinger 4672eafd729SChristoph Hellwig ISCSI_NACL_PARAM(MaxConnections); 4682eafd729SChristoph Hellwig ISCSI_NACL_PARAM(InitialR2T); 4692eafd729SChristoph Hellwig ISCSI_NACL_PARAM(ImmediateData); 4702eafd729SChristoph Hellwig ISCSI_NACL_PARAM(MaxBurstLength); 4712eafd729SChristoph Hellwig ISCSI_NACL_PARAM(FirstBurstLength); 4722eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DefaultTime2Wait); 4732eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DefaultTime2Retain); 4742eafd729SChristoph Hellwig ISCSI_NACL_PARAM(MaxOutstandingR2T); 4752eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DataPDUInOrder); 4762eafd729SChristoph Hellwig ISCSI_NACL_PARAM(DataSequenceInOrder); 4772eafd729SChristoph Hellwig ISCSI_NACL_PARAM(ErrorRecoveryLevel); 478e48354ceSNicholas Bellinger 479e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_nacl_param_attrs[] = { 4802eafd729SChristoph Hellwig &iscsi_nacl_param_attr_MaxConnections, 4812eafd729SChristoph Hellwig &iscsi_nacl_param_attr_InitialR2T, 4822eafd729SChristoph Hellwig &iscsi_nacl_param_attr_ImmediateData, 4832eafd729SChristoph Hellwig &iscsi_nacl_param_attr_MaxBurstLength, 4842eafd729SChristoph Hellwig &iscsi_nacl_param_attr_FirstBurstLength, 4852eafd729SChristoph Hellwig &iscsi_nacl_param_attr_DefaultTime2Wait, 4862eafd729SChristoph Hellwig &iscsi_nacl_param_attr_DefaultTime2Retain, 4872eafd729SChristoph Hellwig &iscsi_nacl_param_attr_MaxOutstandingR2T, 4882eafd729SChristoph Hellwig &iscsi_nacl_param_attr_DataPDUInOrder, 4892eafd729SChristoph Hellwig &iscsi_nacl_param_attr_DataSequenceInOrder, 4902eafd729SChristoph Hellwig &iscsi_nacl_param_attr_ErrorRecoveryLevel, 491e48354ceSNicholas Bellinger NULL, 492e48354ceSNicholas Bellinger }; 493e48354ceSNicholas Bellinger 494e48354ceSNicholas Bellinger /* End items for lio_target_nacl_param_cit */ 495e48354ceSNicholas Bellinger 496e48354ceSNicholas Bellinger /* Start items for lio_target_acl_cit */ 497e48354ceSNicholas Bellinger 4982eafd729SChristoph Hellwig static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page) 499e48354ceSNicholas Bellinger { 5002eafd729SChristoph Hellwig struct se_node_acl *se_nacl = acl_to_nacl(item); 501e48354ceSNicholas Bellinger struct iscsi_session *sess; 502*be36d683SMax Gurtovoy struct iscsit_conn *conn; 503e48354ceSNicholas Bellinger struct se_session *se_sess; 504e48354ceSNicholas Bellinger ssize_t rb = 0; 505109e2381SRoland Dreier u32 max_cmd_sn; 506e48354ceSNicholas Bellinger 507e48354ceSNicholas Bellinger spin_lock_bh(&se_nacl->nacl_sess_lock); 508e48354ceSNicholas Bellinger se_sess = se_nacl->nacl_sess; 509e48354ceSNicholas Bellinger if (!se_sess) { 510e48354ceSNicholas Bellinger rb += sprintf(page+rb, "No active iSCSI Session for Initiator" 511e48354ceSNicholas Bellinger " Endpoint: %s\n", se_nacl->initiatorname); 512e48354ceSNicholas Bellinger } else { 513e48354ceSNicholas Bellinger sess = se_sess->fabric_sess_ptr; 514e48354ceSNicholas Bellinger 515e48354ceSNicholas Bellinger rb += sprintf(page+rb, "InitiatorName: %s\n", 516e48354ceSNicholas Bellinger sess->sess_ops->InitiatorName); 517e48354ceSNicholas Bellinger rb += sprintf(page+rb, "InitiatorAlias: %s\n", 518e48354ceSNicholas Bellinger sess->sess_ops->InitiatorAlias); 519e48354ceSNicholas Bellinger 5205cdf5a87SAndy Shevchenko rb += sprintf(page+rb, 5215cdf5a87SAndy Shevchenko "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ", 5225cdf5a87SAndy Shevchenko sess->sid, sess->isid, sess->tsih); 523e48354ceSNicholas Bellinger rb += sprintf(page+rb, "SessionType: %s\n", 524e48354ceSNicholas Bellinger (sess->sess_ops->SessionType) ? 525e48354ceSNicholas Bellinger "Discovery" : "Normal"); 526e48354ceSNicholas Bellinger rb += sprintf(page+rb, "Session State: "); 527e48354ceSNicholas Bellinger switch (sess->session_state) { 528e48354ceSNicholas Bellinger case TARG_SESS_STATE_FREE: 529e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_FREE\n"); 530e48354ceSNicholas Bellinger break; 531e48354ceSNicholas Bellinger case TARG_SESS_STATE_ACTIVE: 532e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n"); 533e48354ceSNicholas Bellinger break; 534e48354ceSNicholas Bellinger case TARG_SESS_STATE_LOGGED_IN: 535e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n"); 536e48354ceSNicholas Bellinger break; 537e48354ceSNicholas Bellinger case TARG_SESS_STATE_FAILED: 538e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n"); 539e48354ceSNicholas Bellinger break; 540e48354ceSNicholas Bellinger case TARG_SESS_STATE_IN_CONTINUE: 541e48354ceSNicholas Bellinger rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n"); 542e48354ceSNicholas Bellinger break; 543e48354ceSNicholas Bellinger default: 544e48354ceSNicholas Bellinger rb += sprintf(page+rb, "ERROR: Unknown Session" 545e48354ceSNicholas Bellinger " State!\n"); 546e48354ceSNicholas Bellinger break; 547e48354ceSNicholas Bellinger } 548e48354ceSNicholas Bellinger 549e48354ceSNicholas Bellinger rb += sprintf(page+rb, "---------------------[iSCSI Session" 550e48354ceSNicholas Bellinger " Values]-----------------------\n"); 551e48354ceSNicholas Bellinger rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN" 552e48354ceSNicholas Bellinger " : MaxCmdSN : ITT : TTT\n"); 553109e2381SRoland Dreier max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn); 554e48354ceSNicholas Bellinger rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x" 555e48354ceSNicholas Bellinger " 0x%08x 0x%08x\n", 556e48354ceSNicholas Bellinger sess->cmdsn_window, 557109e2381SRoland Dreier (max_cmd_sn - sess->exp_cmd_sn) + 1, 558109e2381SRoland Dreier sess->exp_cmd_sn, max_cmd_sn, 559e48354ceSNicholas Bellinger sess->init_task_tag, sess->targ_xfer_tag); 560e48354ceSNicholas Bellinger rb += sprintf(page+rb, "----------------------[iSCSI" 561e48354ceSNicholas Bellinger " Connections]-------------------------\n"); 562e48354ceSNicholas Bellinger 563e48354ceSNicholas Bellinger spin_lock(&sess->conn_lock); 564e48354ceSNicholas Bellinger list_for_each_entry(conn, &sess->sess_conn_list, conn_list) { 565e48354ceSNicholas Bellinger rb += sprintf(page+rb, "CID: %hu Connection" 566e48354ceSNicholas Bellinger " State: ", conn->cid); 567e48354ceSNicholas Bellinger switch (conn->conn_state) { 568e48354ceSNicholas Bellinger case TARG_CONN_STATE_FREE: 569e48354ceSNicholas Bellinger rb += sprintf(page+rb, 570e48354ceSNicholas Bellinger "TARG_CONN_STATE_FREE\n"); 571e48354ceSNicholas Bellinger break; 572e48354ceSNicholas Bellinger case TARG_CONN_STATE_XPT_UP: 573e48354ceSNicholas Bellinger rb += sprintf(page+rb, 574e48354ceSNicholas Bellinger "TARG_CONN_STATE_XPT_UP\n"); 575e48354ceSNicholas Bellinger break; 576e48354ceSNicholas Bellinger case TARG_CONN_STATE_IN_LOGIN: 577e48354ceSNicholas Bellinger rb += sprintf(page+rb, 578e48354ceSNicholas Bellinger "TARG_CONN_STATE_IN_LOGIN\n"); 579e48354ceSNicholas Bellinger break; 580e48354ceSNicholas Bellinger case TARG_CONN_STATE_LOGGED_IN: 581e48354ceSNicholas Bellinger rb += sprintf(page+rb, 582e48354ceSNicholas Bellinger "TARG_CONN_STATE_LOGGED_IN\n"); 583e48354ceSNicholas Bellinger break; 584e48354ceSNicholas Bellinger case TARG_CONN_STATE_IN_LOGOUT: 585e48354ceSNicholas Bellinger rb += sprintf(page+rb, 586e48354ceSNicholas Bellinger "TARG_CONN_STATE_IN_LOGOUT\n"); 587e48354ceSNicholas Bellinger break; 588e48354ceSNicholas Bellinger case TARG_CONN_STATE_LOGOUT_REQUESTED: 589e48354ceSNicholas Bellinger rb += sprintf(page+rb, 590e48354ceSNicholas Bellinger "TARG_CONN_STATE_LOGOUT_REQUESTED\n"); 591e48354ceSNicholas Bellinger break; 592e48354ceSNicholas Bellinger case TARG_CONN_STATE_CLEANUP_WAIT: 593e48354ceSNicholas Bellinger rb += sprintf(page+rb, 594e48354ceSNicholas Bellinger "TARG_CONN_STATE_CLEANUP_WAIT\n"); 595e48354ceSNicholas Bellinger break; 596e48354ceSNicholas Bellinger default: 597e48354ceSNicholas Bellinger rb += sprintf(page+rb, 598e48354ceSNicholas Bellinger "ERROR: Unknown Connection State!\n"); 599e48354ceSNicholas Bellinger break; 600e48354ceSNicholas Bellinger } 601e48354ceSNicholas Bellinger 602dc58f760SAndy Grover rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr, 603e48354ceSNicholas Bellinger (conn->network_transport == ISCSI_TCP) ? 604e48354ceSNicholas Bellinger "TCP" : "SCTP"); 605e48354ceSNicholas Bellinger rb += sprintf(page+rb, " StatSN: 0x%08x\n", 606e48354ceSNicholas Bellinger conn->stat_sn); 607e48354ceSNicholas Bellinger } 608e48354ceSNicholas Bellinger spin_unlock(&sess->conn_lock); 609e48354ceSNicholas Bellinger } 610e48354ceSNicholas Bellinger spin_unlock_bh(&se_nacl->nacl_sess_lock); 611e48354ceSNicholas Bellinger 612e48354ceSNicholas Bellinger return rb; 613e48354ceSNicholas Bellinger } 614e48354ceSNicholas Bellinger 6152eafd729SChristoph Hellwig static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item, 616e48354ceSNicholas Bellinger char *page) 617e48354ceSNicholas Bellinger { 6182eafd729SChristoph Hellwig return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth); 619e48354ceSNicholas Bellinger } 620e48354ceSNicholas Bellinger 6212eafd729SChristoph Hellwig static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item, 6222eafd729SChristoph Hellwig const char *page, size_t count) 623e48354ceSNicholas Bellinger { 6242eafd729SChristoph Hellwig struct se_node_acl *se_nacl = acl_to_nacl(item); 625e48354ceSNicholas Bellinger struct se_portal_group *se_tpg = se_nacl->se_tpg; 626e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, 627e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); 628e48354ceSNicholas Bellinger struct config_item *acl_ci, *tpg_ci, *wwn_ci; 629e48354ceSNicholas Bellinger u32 cmdsn_depth = 0; 630e48354ceSNicholas Bellinger int ret; 631e48354ceSNicholas Bellinger 632ad7babd2SJörn Engel ret = kstrtou32(page, 0, &cmdsn_depth); 633ad7babd2SJörn Engel if (ret) 634ad7babd2SJörn Engel return ret; 635e48354ceSNicholas Bellinger if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) { 636e48354ceSNicholas Bellinger pr_err("Passed cmdsn_depth: %u exceeds" 637e48354ceSNicholas Bellinger " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth, 638e48354ceSNicholas Bellinger TA_DEFAULT_CMDSN_DEPTH_MAX); 639e48354ceSNicholas Bellinger return -EINVAL; 640e48354ceSNicholas Bellinger } 641e48354ceSNicholas Bellinger acl_ci = &se_nacl->acl_group.cg_item; 642e48354ceSNicholas Bellinger if (!acl_ci) { 643e48354ceSNicholas Bellinger pr_err("Unable to locatel acl_ci\n"); 644e48354ceSNicholas Bellinger return -EINVAL; 645e48354ceSNicholas Bellinger } 646e48354ceSNicholas Bellinger tpg_ci = &acl_ci->ci_parent->ci_group->cg_item; 647e48354ceSNicholas Bellinger if (!tpg_ci) { 648e48354ceSNicholas Bellinger pr_err("Unable to locate tpg_ci\n"); 649e48354ceSNicholas Bellinger return -EINVAL; 650e48354ceSNicholas Bellinger } 651e48354ceSNicholas Bellinger wwn_ci = &tpg_ci->ci_group->cg_item; 652e48354ceSNicholas Bellinger if (!wwn_ci) { 653e48354ceSNicholas Bellinger pr_err("Unable to locate config_item wwn_ci\n"); 654e48354ceSNicholas Bellinger return -EINVAL; 655e48354ceSNicholas Bellinger } 656e48354ceSNicholas Bellinger 657e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) 658e48354ceSNicholas Bellinger return -EINVAL; 659d36ad77fSNicholas Bellinger 660d36ad77fSNicholas Bellinger ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth); 661e48354ceSNicholas Bellinger 662e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for" 663e48354ceSNicholas Bellinger "InitiatorName: %s\n", config_item_name(wwn_ci), 664e48354ceSNicholas Bellinger config_item_name(tpg_ci), cmdsn_depth, 665e48354ceSNicholas Bellinger config_item_name(acl_ci)); 666e48354ceSNicholas Bellinger 667e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); 668e48354ceSNicholas Bellinger return (!ret) ? count : (ssize_t)ret; 669e48354ceSNicholas Bellinger } 670e48354ceSNicholas Bellinger 6712eafd729SChristoph Hellwig static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page) 67279e62fc3SAndy Grover { 6732eafd729SChristoph Hellwig return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag); 67479e62fc3SAndy Grover } 67579e62fc3SAndy Grover 6762eafd729SChristoph Hellwig static ssize_t lio_target_nacl_tag_store(struct config_item *item, 6772eafd729SChristoph Hellwig const char *page, size_t count) 67879e62fc3SAndy Grover { 6792eafd729SChristoph Hellwig struct se_node_acl *se_nacl = acl_to_nacl(item); 68079e62fc3SAndy Grover int ret; 68179e62fc3SAndy Grover 68279e62fc3SAndy Grover ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page); 68379e62fc3SAndy Grover 68479e62fc3SAndy Grover if (ret < 0) 68579e62fc3SAndy Grover return ret; 68679e62fc3SAndy Grover return count; 68779e62fc3SAndy Grover } 68879e62fc3SAndy Grover 6892eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(lio_target_nacl_, info); 6902eafd729SChristoph Hellwig CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth); 6912eafd729SChristoph Hellwig CONFIGFS_ATTR(lio_target_nacl_, tag); 69279e62fc3SAndy Grover 693e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_initiator_attrs[] = { 6942eafd729SChristoph Hellwig &lio_target_nacl_attr_info, 6952eafd729SChristoph Hellwig &lio_target_nacl_attr_cmdsn_depth, 6962eafd729SChristoph Hellwig &lio_target_nacl_attr_tag, 697e48354ceSNicholas Bellinger NULL, 698e48354ceSNicholas Bellinger }; 699e48354ceSNicholas Bellinger 700c7d6a803SChristoph Hellwig static int lio_target_init_nodeacl(struct se_node_acl *se_nacl, 701e48354ceSNicholas Bellinger const char *name) 702e48354ceSNicholas Bellinger { 703c7d6a803SChristoph Hellwig struct iscsi_node_acl *acl = 704c7d6a803SChristoph Hellwig container_of(se_nacl, struct iscsi_node_acl, se_node_acl); 705e48354ceSNicholas Bellinger 706b7eec2cdSAndy Grover config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group, 707e48354ceSNicholas Bellinger "iscsi_sess_stats", &iscsi_stat_sess_cit); 7081ae1602dSChristoph Hellwig configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group, 7091ae1602dSChristoph Hellwig &se_nacl->acl_fabric_stat_group); 710c7d6a803SChristoph Hellwig return 0; 711e48354ceSNicholas Bellinger } 712e48354ceSNicholas Bellinger 713e48354ceSNicholas Bellinger /* End items for lio_target_acl_cit */ 714e48354ceSNicholas Bellinger 715e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_attrib_cit */ 716e48354ceSNicholas Bellinger 717e48354ceSNicholas Bellinger #define DEF_TPG_ATTRIB(name) \ 718e48354ceSNicholas Bellinger \ 7192eafd729SChristoph Hellwig static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \ 720e48354ceSNicholas Bellinger char *page) \ 721e48354ceSNicholas Bellinger { \ 7222eafd729SChristoph Hellwig struct se_portal_group *se_tpg = attrib_to_tpg(item); \ 723e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 724e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 725e48354ceSNicholas Bellinger ssize_t rb; \ 726e48354ceSNicholas Bellinger \ 727e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) \ 728e48354ceSNicholas Bellinger return -EINVAL; \ 729e48354ceSNicholas Bellinger \ 730b7eec2cdSAndy Grover rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \ 731e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 732e48354ceSNicholas Bellinger return rb; \ 733e48354ceSNicholas Bellinger } \ 734e48354ceSNicholas Bellinger \ 7352eafd729SChristoph Hellwig static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\ 7362eafd729SChristoph Hellwig const char *page, size_t count) \ 737e48354ceSNicholas Bellinger { \ 7382eafd729SChristoph Hellwig struct se_portal_group *se_tpg = attrib_to_tpg(item); \ 739e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 740e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 741e48354ceSNicholas Bellinger u32 val; \ 742e48354ceSNicholas Bellinger int ret; \ 743e48354ceSNicholas Bellinger \ 744e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) \ 745e48354ceSNicholas Bellinger return -EINVAL; \ 746e48354ceSNicholas Bellinger \ 747ad7babd2SJörn Engel ret = kstrtou32(page, 0, &val); \ 748ad7babd2SJörn Engel if (ret) \ 749ad7babd2SJörn Engel goto out; \ 750e48354ceSNicholas Bellinger ret = iscsit_ta_##name(tpg, val); \ 751e48354ceSNicholas Bellinger if (ret < 0) \ 752e48354ceSNicholas Bellinger goto out; \ 753e48354ceSNicholas Bellinger \ 754e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 755e48354ceSNicholas Bellinger return count; \ 756e48354ceSNicholas Bellinger out: \ 757e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 758e48354ceSNicholas Bellinger return ret; \ 7592eafd729SChristoph Hellwig } \ 7602eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_tpg_attrib_, name) 761e48354ceSNicholas Bellinger 762e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(authentication); 763e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(login_timeout); 764e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(netif_timeout); 765e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(generate_node_acls); 766e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(default_cmdsn_depth); 767e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(cache_dynamic_acls); 768e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(demo_mode_write_protect); 769e48354ceSNicholas Bellinger DEF_TPG_ATTRIB(prod_mode_write_protect); 7704c54b6cfSThomas Glanzmann DEF_TPG_ATTRIB(demo_mode_discovery); 771d1fa7a1dSNicholas Bellinger DEF_TPG_ATTRIB(default_erl); 7728085176fSSagi Grimberg DEF_TPG_ATTRIB(t10_pi); 773901c04a3SNicholas Bellinger DEF_TPG_ATTRIB(fabric_prot_type); 774a6415cddSDavid Disseldorp DEF_TPG_ATTRIB(tpg_enabled_sendtargets); 775138d351eSNicholas Bellinger DEF_TPG_ATTRIB(login_keys_workaround); 776e48354ceSNicholas Bellinger 777e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = { 7782eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_authentication, 7792eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_login_timeout, 7802eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_netif_timeout, 7812eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_generate_node_acls, 7822eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_default_cmdsn_depth, 7832eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_cache_dynamic_acls, 7842eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_demo_mode_write_protect, 7852eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_prod_mode_write_protect, 7862eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_demo_mode_discovery, 7872eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_default_erl, 7882eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_t10_pi, 7892eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_fabric_prot_type, 7902eafd729SChristoph Hellwig &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets, 791138d351eSNicholas Bellinger &iscsi_tpg_attrib_attr_login_keys_workaround, 792e48354ceSNicholas Bellinger NULL, 793e48354ceSNicholas Bellinger }; 794e48354ceSNicholas Bellinger 795e48354ceSNicholas Bellinger /* End items for lio_target_tpg_attrib_cit */ 796e48354ceSNicholas Bellinger 797c3e51442SNicholas Bellinger /* Start items for lio_target_tpg_auth_cit */ 798c3e51442SNicholas Bellinger 799c3e51442SNicholas Bellinger #define __DEF_TPG_AUTH_STR(prefix, name, flags) \ 8002eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \ 801c3e51442SNicholas Bellinger char *page) \ 802c3e51442SNicholas Bellinger { \ 803c3e51442SNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 804c3e51442SNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 805c3e51442SNicholas Bellinger struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ 806c3e51442SNicholas Bellinger \ 807c3e51442SNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 808c3e51442SNicholas Bellinger return -EPERM; \ 809c3e51442SNicholas Bellinger \ 810c3e51442SNicholas Bellinger return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ 811c3e51442SNicholas Bellinger } \ 812c3e51442SNicholas Bellinger \ 8132eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\ 8142eafd729SChristoph Hellwig const char *page, size_t count) \ 815c3e51442SNicholas Bellinger { \ 816c3e51442SNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 817c3e51442SNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 818c3e51442SNicholas Bellinger struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ 819c3e51442SNicholas Bellinger \ 820c3e51442SNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 821c3e51442SNicholas Bellinger return -EPERM; \ 822c3e51442SNicholas Bellinger \ 82337b32c6fSNicholas Bellinger snprintf(auth->name, sizeof(auth->name), "%s", page); \ 824c3e51442SNicholas Bellinger if (!(strncmp("NULL", auth->name, 4))) \ 825c3e51442SNicholas Bellinger auth->naf_flags &= ~flags; \ 826c3e51442SNicholas Bellinger else \ 827c3e51442SNicholas Bellinger auth->naf_flags |= flags; \ 828c3e51442SNicholas Bellinger \ 829c3e51442SNicholas Bellinger if ((auth->naf_flags & NAF_USERID_IN_SET) && \ 830c3e51442SNicholas Bellinger (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ 831c3e51442SNicholas Bellinger auth->authenticate_target = 1; \ 832c3e51442SNicholas Bellinger else \ 833c3e51442SNicholas Bellinger auth->authenticate_target = 0; \ 834c3e51442SNicholas Bellinger \ 835c3e51442SNicholas Bellinger return count; \ 836c3e51442SNicholas Bellinger } 837c3e51442SNicholas Bellinger 8382eafd729SChristoph Hellwig #define DEF_TPG_AUTH_STR(name, flags) \ 8392eafd729SChristoph Hellwig __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \ 8402eafd729SChristoph Hellwig static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \ 8412eafd729SChristoph Hellwig char *page) \ 8422eafd729SChristoph Hellwig { \ 8432eafd729SChristoph Hellwig return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \ 8442eafd729SChristoph Hellwig } \ 8452eafd729SChristoph Hellwig \ 8462eafd729SChristoph Hellwig static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \ 8472eafd729SChristoph Hellwig const char *page, size_t count) \ 8482eafd729SChristoph Hellwig { \ 8492eafd729SChristoph Hellwig return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \ 8502eafd729SChristoph Hellwig } \ 8512eafd729SChristoph Hellwig \ 8522eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_tpg_auth_, name); 8532eafd729SChristoph Hellwig 8542eafd729SChristoph Hellwig 8552eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(userid, NAF_USERID_SET); 8562eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET); 8572eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); 8582eafd729SChristoph Hellwig DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); 8592eafd729SChristoph Hellwig 860c3e51442SNicholas Bellinger #define __DEF_TPG_AUTH_INT(prefix, name) \ 8612eafd729SChristoph Hellwig static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \ 862c3e51442SNicholas Bellinger char *page) \ 863c3e51442SNicholas Bellinger { \ 864c3e51442SNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 865c3e51442SNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 866c3e51442SNicholas Bellinger struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ 867c3e51442SNicholas Bellinger \ 868c3e51442SNicholas Bellinger if (!capable(CAP_SYS_ADMIN)) \ 869c3e51442SNicholas Bellinger return -EPERM; \ 870c3e51442SNicholas Bellinger \ 871c3e51442SNicholas Bellinger return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ 872c3e51442SNicholas Bellinger } 873c3e51442SNicholas Bellinger 874c3e51442SNicholas Bellinger #define DEF_TPG_AUTH_INT(name) \ 875c3e51442SNicholas Bellinger __DEF_TPG_AUTH_INT(tpg_auth, name) \ 8762eafd729SChristoph Hellwig static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \ 877c3e51442SNicholas Bellinger char *page) \ 878c3e51442SNicholas Bellinger { \ 8792eafd729SChristoph Hellwig return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \ 8802eafd729SChristoph Hellwig } \ 8812eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name); 882c3e51442SNicholas Bellinger 883c3e51442SNicholas Bellinger DEF_TPG_AUTH_INT(authenticate_target); 884c3e51442SNicholas Bellinger 885c3e51442SNicholas Bellinger static struct configfs_attribute *lio_target_tpg_auth_attrs[] = { 8862eafd729SChristoph Hellwig &iscsi_tpg_auth_attr_userid, 8872eafd729SChristoph Hellwig &iscsi_tpg_auth_attr_password, 8882eafd729SChristoph Hellwig &iscsi_tpg_auth_attr_authenticate_target, 8892eafd729SChristoph Hellwig &iscsi_tpg_auth_attr_userid_mutual, 8902eafd729SChristoph Hellwig &iscsi_tpg_auth_attr_password_mutual, 891c3e51442SNicholas Bellinger NULL, 892c3e51442SNicholas Bellinger }; 893c3e51442SNicholas Bellinger 894c3e51442SNicholas Bellinger /* End items for lio_target_tpg_auth_cit */ 895c3e51442SNicholas Bellinger 896e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_param_cit */ 897e48354ceSNicholas Bellinger 898e48354ceSNicholas Bellinger #define DEF_TPG_PARAM(name) \ 8992eafd729SChristoph Hellwig static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \ 900e48354ceSNicholas Bellinger char *page) \ 901e48354ceSNicholas Bellinger { \ 9022eafd729SChristoph Hellwig struct se_portal_group *se_tpg = param_to_tpg(item); \ 903e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 904e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 905e48354ceSNicholas Bellinger struct iscsi_param *param; \ 906e48354ceSNicholas Bellinger ssize_t rb; \ 907e48354ceSNicholas Bellinger \ 908e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) \ 909e48354ceSNicholas Bellinger return -EINVAL; \ 910e48354ceSNicholas Bellinger \ 911e48354ceSNicholas Bellinger param = iscsi_find_param_from_key(__stringify(name), \ 912e48354ceSNicholas Bellinger tpg->param_list); \ 913e48354ceSNicholas Bellinger if (!param) { \ 914e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 915e48354ceSNicholas Bellinger return -EINVAL; \ 916e48354ceSNicholas Bellinger } \ 917e48354ceSNicholas Bellinger rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \ 918e48354ceSNicholas Bellinger \ 919e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 920e48354ceSNicholas Bellinger return rb; \ 921e48354ceSNicholas Bellinger } \ 9222eafd729SChristoph Hellwig static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \ 9232eafd729SChristoph Hellwig const char *page, size_t count) \ 924e48354ceSNicholas Bellinger { \ 9252eafd729SChristoph Hellwig struct se_portal_group *se_tpg = param_to_tpg(item); \ 926e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, \ 927e48354ceSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); \ 928e48354ceSNicholas Bellinger char *buf; \ 929ad7babd2SJörn Engel int ret, len; \ 930e48354ceSNicholas Bellinger \ 931e48354ceSNicholas Bellinger buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \ 932e48354ceSNicholas Bellinger if (!buf) \ 933e48354ceSNicholas Bellinger return -ENOMEM; \ 934ad7babd2SJörn Engel len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \ 935ad7babd2SJörn Engel if (isspace(buf[len-1])) \ 936ad7babd2SJörn Engel buf[len-1] = '\0'; /* Kill newline */ \ 937e48354ceSNicholas Bellinger \ 938e48354ceSNicholas Bellinger if (iscsit_get_tpg(tpg) < 0) { \ 939e48354ceSNicholas Bellinger kfree(buf); \ 940e48354ceSNicholas Bellinger return -EINVAL; \ 941e48354ceSNicholas Bellinger } \ 942e48354ceSNicholas Bellinger \ 943e48354ceSNicholas Bellinger ret = iscsi_change_param_value(buf, tpg->param_list, 1); \ 944e48354ceSNicholas Bellinger if (ret < 0) \ 945e48354ceSNicholas Bellinger goto out; \ 946e48354ceSNicholas Bellinger \ 947e48354ceSNicholas Bellinger kfree(buf); \ 948e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 949e48354ceSNicholas Bellinger return count; \ 950e48354ceSNicholas Bellinger out: \ 951e48354ceSNicholas Bellinger kfree(buf); \ 952e48354ceSNicholas Bellinger iscsit_put_tpg(tpg); \ 953e48354ceSNicholas Bellinger return -EINVAL; \ 9542eafd729SChristoph Hellwig } \ 9552eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_tpg_param_, name) 956e48354ceSNicholas Bellinger 957e48354ceSNicholas Bellinger DEF_TPG_PARAM(AuthMethod); 958e48354ceSNicholas Bellinger DEF_TPG_PARAM(HeaderDigest); 959e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataDigest); 960e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxConnections); 961e48354ceSNicholas Bellinger DEF_TPG_PARAM(TargetAlias); 962e48354ceSNicholas Bellinger DEF_TPG_PARAM(InitialR2T); 963e48354ceSNicholas Bellinger DEF_TPG_PARAM(ImmediateData); 964e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxRecvDataSegmentLength); 965e004cb25SNicholas Bellinger DEF_TPG_PARAM(MaxXmitDataSegmentLength); 966e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxBurstLength); 967e48354ceSNicholas Bellinger DEF_TPG_PARAM(FirstBurstLength); 968e48354ceSNicholas Bellinger DEF_TPG_PARAM(DefaultTime2Wait); 969e48354ceSNicholas Bellinger DEF_TPG_PARAM(DefaultTime2Retain); 970e48354ceSNicholas Bellinger DEF_TPG_PARAM(MaxOutstandingR2T); 971e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataPDUInOrder); 972e48354ceSNicholas Bellinger DEF_TPG_PARAM(DataSequenceInOrder); 973e48354ceSNicholas Bellinger DEF_TPG_PARAM(ErrorRecoveryLevel); 974e48354ceSNicholas Bellinger DEF_TPG_PARAM(IFMarker); 975e48354ceSNicholas Bellinger DEF_TPG_PARAM(OFMarker); 976e48354ceSNicholas Bellinger DEF_TPG_PARAM(IFMarkInt); 977e48354ceSNicholas Bellinger DEF_TPG_PARAM(OFMarkInt); 978e48354ceSNicholas Bellinger 979e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_param_attrs[] = { 9802eafd729SChristoph Hellwig &iscsi_tpg_param_attr_AuthMethod, 9812eafd729SChristoph Hellwig &iscsi_tpg_param_attr_HeaderDigest, 9822eafd729SChristoph Hellwig &iscsi_tpg_param_attr_DataDigest, 9832eafd729SChristoph Hellwig &iscsi_tpg_param_attr_MaxConnections, 9842eafd729SChristoph Hellwig &iscsi_tpg_param_attr_TargetAlias, 9852eafd729SChristoph Hellwig &iscsi_tpg_param_attr_InitialR2T, 9862eafd729SChristoph Hellwig &iscsi_tpg_param_attr_ImmediateData, 9872eafd729SChristoph Hellwig &iscsi_tpg_param_attr_MaxRecvDataSegmentLength, 9882eafd729SChristoph Hellwig &iscsi_tpg_param_attr_MaxXmitDataSegmentLength, 9892eafd729SChristoph Hellwig &iscsi_tpg_param_attr_MaxBurstLength, 9902eafd729SChristoph Hellwig &iscsi_tpg_param_attr_FirstBurstLength, 9912eafd729SChristoph Hellwig &iscsi_tpg_param_attr_DefaultTime2Wait, 9922eafd729SChristoph Hellwig &iscsi_tpg_param_attr_DefaultTime2Retain, 9932eafd729SChristoph Hellwig &iscsi_tpg_param_attr_MaxOutstandingR2T, 9942eafd729SChristoph Hellwig &iscsi_tpg_param_attr_DataPDUInOrder, 9952eafd729SChristoph Hellwig &iscsi_tpg_param_attr_DataSequenceInOrder, 9962eafd729SChristoph Hellwig &iscsi_tpg_param_attr_ErrorRecoveryLevel, 9972eafd729SChristoph Hellwig &iscsi_tpg_param_attr_IFMarker, 9982eafd729SChristoph Hellwig &iscsi_tpg_param_attr_OFMarker, 9992eafd729SChristoph Hellwig &iscsi_tpg_param_attr_IFMarkInt, 10002eafd729SChristoph Hellwig &iscsi_tpg_param_attr_OFMarkInt, 1001e48354ceSNicholas Bellinger NULL, 1002e48354ceSNicholas Bellinger }; 1003e48354ceSNicholas Bellinger 1004e48354ceSNicholas Bellinger /* End items for lio_target_tpg_param_cit */ 1005e48354ceSNicholas Bellinger 1006e48354ceSNicholas Bellinger /* Start items for lio_target_tpg_cit */ 1007e48354ceSNicholas Bellinger 10082eafd729SChristoph Hellwig static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item, 1009d4ee46ffSNicholas Bellinger char *page) 1010d4ee46ffSNicholas Bellinger { 10112eafd729SChristoph Hellwig return target_show_dynamic_sessions(to_tpg(item), page); 1012d4ee46ffSNicholas Bellinger } 1013d4ee46ffSNicholas Bellinger 10142eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions); 1015d4ee46ffSNicholas Bellinger 1016e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_tpg_attrs[] = { 10172eafd729SChristoph Hellwig &lio_target_tpg_attr_dynamic_sessions, 1018e48354ceSNicholas Bellinger NULL, 1019e48354ceSNicholas Bellinger }; 1020e48354ceSNicholas Bellinger 1021e48354ceSNicholas Bellinger /* End items for lio_target_tpg_cit */ 1022e48354ceSNicholas Bellinger 1023e48354ceSNicholas Bellinger /* Start items for lio_target_tiqn_cit */ 1024e48354ceSNicholas Bellinger 1025aa090eabSBart Van Assche static struct se_portal_group *lio_target_tiqn_addtpg(struct se_wwn *wwn, 1026e48354ceSNicholas Bellinger const char *name) 1027e48354ceSNicholas Bellinger { 1028e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 1029e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn; 1030ad7babd2SJörn Engel char *tpgt_str; 1031ad7babd2SJörn Engel int ret; 1032ad7babd2SJörn Engel u16 tpgt; 1033e48354ceSNicholas Bellinger 1034e48354ceSNicholas Bellinger tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); 1035e48354ceSNicholas Bellinger /* 1036e48354ceSNicholas Bellinger * Only tpgt_# directory groups can be created below 1037e48354ceSNicholas Bellinger * target/iscsi/iqn.superturodiskarry/ 1038e48354ceSNicholas Bellinger */ 1039e48354ceSNicholas Bellinger tpgt_str = strstr(name, "tpgt_"); 1040e48354ceSNicholas Bellinger if (!tpgt_str) { 1041e48354ceSNicholas Bellinger pr_err("Unable to locate \"tpgt_#\" directory" 1042e48354ceSNicholas Bellinger " group\n"); 1043e48354ceSNicholas Bellinger return NULL; 1044e48354ceSNicholas Bellinger } 1045e48354ceSNicholas Bellinger tpgt_str += 5; /* Skip ahead of "tpgt_" */ 1046ad7babd2SJörn Engel ret = kstrtou16(tpgt_str, 0, &tpgt); 1047ad7babd2SJörn Engel if (ret) 1048ad7babd2SJörn Engel return NULL; 1049e48354ceSNicholas Bellinger 1050e48354ceSNicholas Bellinger tpg = iscsit_alloc_portal_group(tiqn, tpgt); 1051e48354ceSNicholas Bellinger if (!tpg) 1052e48354ceSNicholas Bellinger return NULL; 1053e48354ceSNicholas Bellinger 1054bc0c94b1SNicholas Bellinger ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI); 1055e48354ceSNicholas Bellinger if (ret < 0) 105612d5a43bStangwenji goto free_out; 1057e48354ceSNicholas Bellinger 1058e48354ceSNicholas Bellinger ret = iscsit_tpg_add_portal_group(tiqn, tpg); 1059e48354ceSNicholas Bellinger if (ret != 0) 1060e48354ceSNicholas Bellinger goto out; 1061e48354ceSNicholas Bellinger 1062e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); 1063e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n", 1064e48354ceSNicholas Bellinger name); 1065e48354ceSNicholas Bellinger return &tpg->tpg_se_tpg; 1066e48354ceSNicholas Bellinger out: 1067e48354ceSNicholas Bellinger core_tpg_deregister(&tpg->tpg_se_tpg); 106812d5a43bStangwenji free_out: 1069e48354ceSNicholas Bellinger kfree(tpg); 1070e48354ceSNicholas Bellinger return NULL; 1071e48354ceSNicholas Bellinger } 1072e48354ceSNicholas Bellinger 1073382731ecSDmitry Bogdanov static int lio_target_tiqn_enabletpg(struct se_portal_group *se_tpg, 1074382731ecSDmitry Bogdanov bool enable) 1075382731ecSDmitry Bogdanov { 1076382731ecSDmitry Bogdanov struct iscsi_portal_group *tpg = container_of(se_tpg, 1077382731ecSDmitry Bogdanov struct iscsi_portal_group, tpg_se_tpg); 1078382731ecSDmitry Bogdanov int ret; 1079382731ecSDmitry Bogdanov 1080382731ecSDmitry Bogdanov ret = iscsit_get_tpg(tpg); 1081382731ecSDmitry Bogdanov if (ret < 0) 1082382731ecSDmitry Bogdanov return -EINVAL; 1083382731ecSDmitry Bogdanov 1084382731ecSDmitry Bogdanov if (enable) { 1085382731ecSDmitry Bogdanov ret = iscsit_tpg_enable_portal_group(tpg); 1086382731ecSDmitry Bogdanov if (ret < 0) 1087382731ecSDmitry Bogdanov goto out; 1088382731ecSDmitry Bogdanov } else { 1089382731ecSDmitry Bogdanov /* 1090382731ecSDmitry Bogdanov * iscsit_tpg_disable_portal_group() assumes force=1 1091382731ecSDmitry Bogdanov */ 1092382731ecSDmitry Bogdanov ret = iscsit_tpg_disable_portal_group(tpg, 1); 1093382731ecSDmitry Bogdanov if (ret < 0) 1094382731ecSDmitry Bogdanov goto out; 1095382731ecSDmitry Bogdanov } 1096382731ecSDmitry Bogdanov 1097382731ecSDmitry Bogdanov iscsit_put_tpg(tpg); 1098382731ecSDmitry Bogdanov return 0; 1099382731ecSDmitry Bogdanov out: 1100382731ecSDmitry Bogdanov iscsit_put_tpg(tpg); 1101382731ecSDmitry Bogdanov return -EINVAL; 1102382731ecSDmitry Bogdanov } 1103382731ecSDmitry Bogdanov 1104fceb5bc7SChristoph Hellwig static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg) 1105e48354ceSNicholas Bellinger { 1106e48354ceSNicholas Bellinger struct iscsi_portal_group *tpg; 1107e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn; 1108e48354ceSNicholas Bellinger 1109e48354ceSNicholas Bellinger tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); 1110e48354ceSNicholas Bellinger tiqn = tpg->tpg_tiqn; 1111e48354ceSNicholas Bellinger /* 1112e48354ceSNicholas Bellinger * iscsit_tpg_del_portal_group() assumes force=1 1113e48354ceSNicholas Bellinger */ 1114e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n"); 1115e48354ceSNicholas Bellinger iscsit_tpg_del_portal_group(tiqn, tpg, 1); 1116e48354ceSNicholas Bellinger } 1117e48354ceSNicholas Bellinger 1118e48354ceSNicholas Bellinger /* End items for lio_target_tiqn_cit */ 1119e48354ceSNicholas Bellinger 1120e48354ceSNicholas Bellinger /* Start LIO-Target TIQN struct contig_item lio_target_cit */ 1121e48354ceSNicholas Bellinger 11222eafd729SChristoph Hellwig static ssize_t lio_target_wwn_lio_version_show(struct config_item *item, 1123e48354ceSNicholas Bellinger char *page) 1124e48354ceSNicholas Bellinger { 11254c76251eSNicholas Bellinger return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n"); 1126e48354ceSNicholas Bellinger } 1127e48354ceSNicholas Bellinger 11282eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version); 1129e48354ceSNicholas Bellinger 1130d72d827fSMingzhe Zou static ssize_t lio_target_wwn_cpus_allowed_list_show( 1131d72d827fSMingzhe Zou struct config_item *item, char *page) 1132d72d827fSMingzhe Zou { 1133d72d827fSMingzhe Zou return sprintf(page, "%*pbl\n", 1134d72d827fSMingzhe Zou cpumask_pr_args(iscsit_global->allowed_cpumask)); 1135d72d827fSMingzhe Zou } 1136d72d827fSMingzhe Zou 1137d72d827fSMingzhe Zou static ssize_t lio_target_wwn_cpus_allowed_list_store( 1138d72d827fSMingzhe Zou struct config_item *item, const char *page, size_t count) 1139d72d827fSMingzhe Zou { 1140d72d827fSMingzhe Zou int ret; 1141d72d827fSMingzhe Zou char *orig; 1142d72d827fSMingzhe Zou cpumask_t new_allowed_cpumask; 1143d72d827fSMingzhe Zou 1144d72d827fSMingzhe Zou orig = kstrdup(page, GFP_KERNEL); 1145d72d827fSMingzhe Zou if (!orig) 1146d72d827fSMingzhe Zou return -ENOMEM; 1147d72d827fSMingzhe Zou 1148d72d827fSMingzhe Zou cpumask_clear(&new_allowed_cpumask); 1149d72d827fSMingzhe Zou ret = cpulist_parse(orig, &new_allowed_cpumask); 1150d72d827fSMingzhe Zou 1151d72d827fSMingzhe Zou kfree(orig); 1152d72d827fSMingzhe Zou if (ret != 0) 1153d72d827fSMingzhe Zou return ret; 1154d72d827fSMingzhe Zou 1155d72d827fSMingzhe Zou cpumask_copy(iscsit_global->allowed_cpumask, &new_allowed_cpumask); 1156d72d827fSMingzhe Zou return count; 1157d72d827fSMingzhe Zou } 1158d72d827fSMingzhe Zou 1159d72d827fSMingzhe Zou CONFIGFS_ATTR(lio_target_wwn_, cpus_allowed_list); 1160d72d827fSMingzhe Zou 1161e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_wwn_attrs[] = { 11622eafd729SChristoph Hellwig &lio_target_wwn_attr_lio_version, 1163d72d827fSMingzhe Zou &lio_target_wwn_attr_cpus_allowed_list, 1164e48354ceSNicholas Bellinger NULL, 1165e48354ceSNicholas Bellinger }; 1166e48354ceSNicholas Bellinger 1167fceb5bc7SChristoph Hellwig static struct se_wwn *lio_target_call_coreaddtiqn( 1168e48354ceSNicholas Bellinger struct target_fabric_configfs *tf, 1169e48354ceSNicholas Bellinger struct config_group *group, 1170e48354ceSNicholas Bellinger const char *name) 1171e48354ceSNicholas Bellinger { 1172e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn; 1173e48354ceSNicholas Bellinger 1174e48354ceSNicholas Bellinger tiqn = iscsit_add_tiqn((unsigned char *)name); 1175e48354ceSNicholas Bellinger if (IS_ERR(tiqn)) 1176e1750ba2SThomas Meyer return ERR_CAST(tiqn); 1177e48354ceSNicholas Bellinger 1178839559e1SChristoph Hellwig pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); 1179839559e1SChristoph Hellwig pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:" 1180839559e1SChristoph Hellwig " %s\n", name); 1181839559e1SChristoph Hellwig return &tiqn->tiqn_wwn; 1182839559e1SChristoph Hellwig } 1183839559e1SChristoph Hellwig 1184839559e1SChristoph Hellwig static void lio_target_add_wwn_groups(struct se_wwn *wwn) 1185839559e1SChristoph Hellwig { 1186839559e1SChristoph Hellwig struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); 1187839559e1SChristoph Hellwig 1188b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group, 1189e48354ceSNicholas Bellinger "iscsi_instance", &iscsi_stat_instance_cit); 11901ae1602dSChristoph Hellwig configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group, 11911ae1602dSChristoph Hellwig &tiqn->tiqn_wwn.fabric_stat_group); 11921ae1602dSChristoph Hellwig 1193b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group, 1194e48354ceSNicholas Bellinger "iscsi_sess_err", &iscsi_stat_sess_err_cit); 11951ae1602dSChristoph Hellwig configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group, 11961ae1602dSChristoph Hellwig &tiqn->tiqn_wwn.fabric_stat_group); 11971ae1602dSChristoph Hellwig 1198b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group, 1199e48354ceSNicholas Bellinger "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit); 12001ae1602dSChristoph Hellwig configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group, 12011ae1602dSChristoph Hellwig &tiqn->tiqn_wwn.fabric_stat_group); 12021ae1602dSChristoph Hellwig 1203b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group, 1204e48354ceSNicholas Bellinger "iscsi_login_stats", &iscsi_stat_login_cit); 12051ae1602dSChristoph Hellwig configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group, 12061ae1602dSChristoph Hellwig &tiqn->tiqn_wwn.fabric_stat_group); 12071ae1602dSChristoph Hellwig 1208b7eec2cdSAndy Grover config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group, 1209e48354ceSNicholas Bellinger "iscsi_logout_stats", &iscsi_stat_logout_cit); 12101ae1602dSChristoph Hellwig configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group, 12111ae1602dSChristoph Hellwig &tiqn->tiqn_wwn.fabric_stat_group); 1212e48354ceSNicholas Bellinger } 1213e48354ceSNicholas Bellinger 1214fceb5bc7SChristoph Hellwig static void lio_target_call_coredeltiqn( 1215e48354ceSNicholas Bellinger struct se_wwn *wwn) 1216e48354ceSNicholas Bellinger { 1217e48354ceSNicholas Bellinger struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); 1218e48354ceSNicholas Bellinger 1219e48354ceSNicholas Bellinger pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n", 1220e48354ceSNicholas Bellinger tiqn->tiqn); 1221e48354ceSNicholas Bellinger iscsit_del_tiqn(tiqn); 1222e48354ceSNicholas Bellinger } 1223e48354ceSNicholas Bellinger 1224e48354ceSNicholas Bellinger /* End LIO-Target TIQN struct contig_lio_target_cit */ 1225e48354ceSNicholas Bellinger 1226e48354ceSNicholas Bellinger /* Start lio_target_discovery_auth_cit */ 1227e48354ceSNicholas Bellinger 1228e48354ceSNicholas Bellinger #define DEF_DISC_AUTH_STR(name, flags) \ 1229e48354ceSNicholas Bellinger __DEF_NACL_AUTH_STR(disc, name, flags) \ 12302eafd729SChristoph Hellwig static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \ 1231e48354ceSNicholas Bellinger { \ 12322eafd729SChristoph Hellwig return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\ 1233e48354ceSNicholas Bellinger page); \ 1234e48354ceSNicholas Bellinger } \ 12352eafd729SChristoph Hellwig static ssize_t iscsi_disc_##name##_store(struct config_item *item, \ 12362eafd729SChristoph Hellwig const char *page, size_t count) \ 1237e48354ceSNicholas Bellinger { \ 12382eafd729SChristoph Hellwig return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \ 1239e48354ceSNicholas Bellinger page, count); \ 12402eafd729SChristoph Hellwig \ 12412eafd729SChristoph Hellwig } \ 12422eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_disc_, name) 12432eafd729SChristoph Hellwig 12442eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(userid, NAF_USERID_SET); 12452eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET); 12462eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); 12472eafd729SChristoph Hellwig DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); 1248e48354ceSNicholas Bellinger 1249e48354ceSNicholas Bellinger #define DEF_DISC_AUTH_INT(name) \ 1250e48354ceSNicholas Bellinger __DEF_NACL_AUTH_INT(disc, name) \ 12512eafd729SChristoph Hellwig static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \ 1252e48354ceSNicholas Bellinger { \ 12532eafd729SChristoph Hellwig return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \ 1254e48354ceSNicholas Bellinger page); \ 12552eafd729SChristoph Hellwig } \ 12562eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_disc_, name) 1257e48354ceSNicholas Bellinger 1258e48354ceSNicholas Bellinger DEF_DISC_AUTH_INT(authenticate_target); 1259e48354ceSNicholas Bellinger 12602eafd729SChristoph Hellwig 12612eafd729SChristoph Hellwig static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item, 1262e48354ceSNicholas Bellinger char *page) 1263e48354ceSNicholas Bellinger { 1264e48354ceSNicholas Bellinger struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth; 1265e48354ceSNicholas Bellinger 1266e48354ceSNicholas Bellinger return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth); 1267e48354ceSNicholas Bellinger } 1268e48354ceSNicholas Bellinger 12692eafd729SChristoph Hellwig static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item, 12702eafd729SChristoph Hellwig const char *page, size_t count) 1271e48354ceSNicholas Bellinger { 1272e48354ceSNicholas Bellinger struct iscsi_param *param; 1273e48354ceSNicholas Bellinger struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg; 1274e48354ceSNicholas Bellinger u32 op; 1275ad7babd2SJörn Engel int err; 1276e48354ceSNicholas Bellinger 1277ad7babd2SJörn Engel err = kstrtou32(page, 0, &op); 1278ad7babd2SJörn Engel if (err) 1279ad7babd2SJörn Engel return -EINVAL; 1280e48354ceSNicholas Bellinger if ((op != 1) && (op != 0)) { 1281e48354ceSNicholas Bellinger pr_err("Illegal value for enforce_discovery_auth:" 1282e48354ceSNicholas Bellinger " %u\n", op); 1283e48354ceSNicholas Bellinger return -EINVAL; 1284e48354ceSNicholas Bellinger } 1285e48354ceSNicholas Bellinger 1286e48354ceSNicholas Bellinger if (!discovery_tpg) { 1287e48354ceSNicholas Bellinger pr_err("iscsit_global->discovery_tpg is NULL\n"); 1288e48354ceSNicholas Bellinger return -EINVAL; 1289e48354ceSNicholas Bellinger } 1290e48354ceSNicholas Bellinger 1291e48354ceSNicholas Bellinger param = iscsi_find_param_from_key(AUTHMETHOD, 1292e48354ceSNicholas Bellinger discovery_tpg->param_list); 1293e48354ceSNicholas Bellinger if (!param) 1294e48354ceSNicholas Bellinger return -EINVAL; 1295e48354ceSNicholas Bellinger 1296e48354ceSNicholas Bellinger if (op) { 1297e48354ceSNicholas Bellinger /* 1298e48354ceSNicholas Bellinger * Reset the AuthMethod key to CHAP. 1299e48354ceSNicholas Bellinger */ 1300e48354ceSNicholas Bellinger if (iscsi_update_param_value(param, CHAP) < 0) 1301e48354ceSNicholas Bellinger return -EINVAL; 1302e48354ceSNicholas Bellinger 1303e48354ceSNicholas Bellinger discovery_tpg->tpg_attrib.authentication = 1; 1304e48354ceSNicholas Bellinger iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1; 1305e48354ceSNicholas Bellinger pr_debug("LIO-CORE[0] Successfully enabled" 1306e48354ceSNicholas Bellinger " authentication enforcement for iSCSI" 1307e48354ceSNicholas Bellinger " Discovery TPG\n"); 1308e48354ceSNicholas Bellinger } else { 1309e48354ceSNicholas Bellinger /* 1310e48354ceSNicholas Bellinger * Reset the AuthMethod key to CHAP,None 1311e48354ceSNicholas Bellinger */ 1312e48354ceSNicholas Bellinger if (iscsi_update_param_value(param, "CHAP,None") < 0) 1313e48354ceSNicholas Bellinger return -EINVAL; 1314e48354ceSNicholas Bellinger 1315e48354ceSNicholas Bellinger discovery_tpg->tpg_attrib.authentication = 0; 1316e48354ceSNicholas Bellinger iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0; 1317e48354ceSNicholas Bellinger pr_debug("LIO-CORE[0] Successfully disabled" 1318e48354ceSNicholas Bellinger " authentication enforcement for iSCSI" 1319e48354ceSNicholas Bellinger " Discovery TPG\n"); 1320e48354ceSNicholas Bellinger } 1321e48354ceSNicholas Bellinger 1322e48354ceSNicholas Bellinger return count; 1323e48354ceSNicholas Bellinger } 1324e48354ceSNicholas Bellinger 13252eafd729SChristoph Hellwig CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth); 1326e48354ceSNicholas Bellinger 1327e48354ceSNicholas Bellinger static struct configfs_attribute *lio_target_discovery_auth_attrs[] = { 13282eafd729SChristoph Hellwig &iscsi_disc_attr_userid, 13292eafd729SChristoph Hellwig &iscsi_disc_attr_password, 13302eafd729SChristoph Hellwig &iscsi_disc_attr_authenticate_target, 13312eafd729SChristoph Hellwig &iscsi_disc_attr_userid_mutual, 13322eafd729SChristoph Hellwig &iscsi_disc_attr_password_mutual, 13332eafd729SChristoph Hellwig &iscsi_disc_attr_enforce_discovery_auth, 1334e48354ceSNicholas Bellinger NULL, 1335e48354ceSNicholas Bellinger }; 1336e48354ceSNicholas Bellinger 1337e48354ceSNicholas Bellinger /* End lio_target_discovery_auth_cit */ 1338e48354ceSNicholas Bellinger 1339e48354ceSNicholas Bellinger /* Start functions for target_core_fabric_ops */ 1340e48354ceSNicholas Bellinger 1341e48354ceSNicholas Bellinger static int iscsi_get_cmd_state(struct se_cmd *se_cmd) 1342e48354ceSNicholas Bellinger { 134366cd9d4eSMax Gurtovoy struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd); 1344e48354ceSNicholas Bellinger 1345e48354ceSNicholas Bellinger return cmd->i_state; 1346e48354ceSNicholas Bellinger } 1347e48354ceSNicholas Bellinger 1348e48354ceSNicholas Bellinger static u32 lio_sess_get_index(struct se_session *se_sess) 1349e48354ceSNicholas Bellinger { 1350e48354ceSNicholas Bellinger struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1351e48354ceSNicholas Bellinger 1352e48354ceSNicholas Bellinger return sess->session_index; 1353e48354ceSNicholas Bellinger } 1354e48354ceSNicholas Bellinger 1355e48354ceSNicholas Bellinger static u32 lio_sess_get_initiator_sid( 1356e48354ceSNicholas Bellinger struct se_session *se_sess, 1357e48354ceSNicholas Bellinger unsigned char *buf, 1358e48354ceSNicholas Bellinger u32 size) 1359e48354ceSNicholas Bellinger { 1360e48354ceSNicholas Bellinger struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1361e48354ceSNicholas Bellinger /* 1362e48354ceSNicholas Bellinger * iSCSI Initiator Session Identifier from RFC-3720. 1363e48354ceSNicholas Bellinger */ 13645cdf5a87SAndy Shevchenko return snprintf(buf, size, "%6phN", sess->isid); 1365e48354ceSNicholas Bellinger } 1366e48354ceSNicholas Bellinger 1367e48354ceSNicholas Bellinger static int lio_queue_data_in(struct se_cmd *se_cmd) 1368e48354ceSNicholas Bellinger { 136966cd9d4eSMax Gurtovoy struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd); 1370*be36d683SMax Gurtovoy struct iscsit_conn *conn = cmd->conn; 1371e48354ceSNicholas Bellinger 1372e48354ceSNicholas Bellinger cmd->i_state = ISTATE_SEND_DATAIN; 1373a4467018SNicholas Bellinger return conn->conn_transport->iscsit_queue_data_in(conn, cmd); 1374e48354ceSNicholas Bellinger } 1375e48354ceSNicholas Bellinger 1376e48354ceSNicholas Bellinger static int lio_write_pending(struct se_cmd *se_cmd) 1377e48354ceSNicholas Bellinger { 137866cd9d4eSMax Gurtovoy struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd); 1379*be36d683SMax Gurtovoy struct iscsit_conn *conn = cmd->conn; 1380e48354ceSNicholas Bellinger 1381e48354ceSNicholas Bellinger if (!cmd->immediate_data && !cmd->unsolicited_data) 13823e1c81a9SNicholas Bellinger return conn->conn_transport->iscsit_get_dataout(conn, cmd, false); 1383e48354ceSNicholas Bellinger 1384e48354ceSNicholas Bellinger return 0; 1385e48354ceSNicholas Bellinger } 1386e48354ceSNicholas Bellinger 1387e48354ceSNicholas Bellinger static int lio_queue_status(struct se_cmd *se_cmd) 1388e48354ceSNicholas Bellinger { 138966cd9d4eSMax Gurtovoy struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd); 1390*be36d683SMax Gurtovoy struct iscsit_conn *conn = cmd->conn; 1391e48354ceSNicholas Bellinger 1392e48354ceSNicholas Bellinger cmd->i_state = ISTATE_SEND_STATUS; 13935e8e6b4bSNicholas Bellinger 13945e8e6b4bSNicholas Bellinger if (cmd->se_cmd.scsi_status || cmd->sense_reason) { 1395a4467018SNicholas Bellinger return iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); 13965e8e6b4bSNicholas Bellinger } 1397a4467018SNicholas Bellinger return conn->conn_transport->iscsit_queue_status(conn, cmd); 1398e48354ceSNicholas Bellinger } 1399e48354ceSNicholas Bellinger 1400b79fafacSJoern Engel static void lio_queue_tm_rsp(struct se_cmd *se_cmd) 1401e48354ceSNicholas Bellinger { 140266cd9d4eSMax Gurtovoy struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd); 1403e48354ceSNicholas Bellinger 1404e48354ceSNicholas Bellinger cmd->i_state = ISTATE_SEND_TASKMGTRSP; 1405e48354ceSNicholas Bellinger iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state); 1406e48354ceSNicholas Bellinger } 1407e48354ceSNicholas Bellinger 1408131e6abcSNicholas Bellinger static void lio_aborted_task(struct se_cmd *se_cmd) 1409131e6abcSNicholas Bellinger { 141066cd9d4eSMax Gurtovoy struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd); 1411131e6abcSNicholas Bellinger 1412131e6abcSNicholas Bellinger cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd); 1413131e6abcSNicholas Bellinger } 1414131e6abcSNicholas Bellinger 14152b6eb609SChristoph Hellwig static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg) 14162b6eb609SChristoph Hellwig { 14172b6eb609SChristoph Hellwig return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); 14182b6eb609SChristoph Hellwig } 14192b6eb609SChristoph Hellwig 1420e48354ceSNicholas Bellinger static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg) 1421e48354ceSNicholas Bellinger { 14222b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn; 1423e48354ceSNicholas Bellinger } 1424e48354ceSNicholas Bellinger 1425e48354ceSNicholas Bellinger static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg) 1426e48354ceSNicholas Bellinger { 14272b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpgt; 1428e48354ceSNicholas Bellinger } 1429e48354ceSNicholas Bellinger 1430e48354ceSNicholas Bellinger static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg) 1431e48354ceSNicholas Bellinger { 14322b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth; 1433e48354ceSNicholas Bellinger } 1434e48354ceSNicholas Bellinger 1435e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg) 1436e48354ceSNicholas Bellinger { 14372b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls; 1438e48354ceSNicholas Bellinger } 1439e48354ceSNicholas Bellinger 1440e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg) 1441e48354ceSNicholas Bellinger { 14422b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls; 1443e48354ceSNicholas Bellinger } 1444e48354ceSNicholas Bellinger 1445e48354ceSNicholas Bellinger static int lio_tpg_check_demo_mode_write_protect( 1446e48354ceSNicholas Bellinger struct se_portal_group *se_tpg) 1447e48354ceSNicholas Bellinger { 14482b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect; 1449e48354ceSNicholas Bellinger } 1450e48354ceSNicholas Bellinger 1451e48354ceSNicholas Bellinger static int lio_tpg_check_prod_mode_write_protect( 1452e48354ceSNicholas Bellinger struct se_portal_group *se_tpg) 1453e48354ceSNicholas Bellinger { 14542b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect; 1455e48354ceSNicholas Bellinger } 1456e48354ceSNicholas Bellinger 1457901c04a3SNicholas Bellinger static int lio_tpg_check_prot_fabric_only( 1458901c04a3SNicholas Bellinger struct se_portal_group *se_tpg) 1459901c04a3SNicholas Bellinger { 1460901c04a3SNicholas Bellinger /* 1461901c04a3SNicholas Bellinger * Only report fabric_prot_type if t10_pi has also been enabled 1462901c04a3SNicholas Bellinger * for incoming ib_isert sessions. 1463901c04a3SNicholas Bellinger */ 14642b6eb609SChristoph Hellwig if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi) 1465901c04a3SNicholas Bellinger return 0; 14662b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type; 1467901c04a3SNicholas Bellinger } 1468901c04a3SNicholas Bellinger 1469e48354ceSNicholas Bellinger /* 1470d36ad77fSNicholas Bellinger * This function calls iscsit_inc_session_usage_count() on the 1471e48354ceSNicholas Bellinger * struct iscsi_session in question. 1472e48354ceSNicholas Bellinger */ 147344f33d0fSChristoph Hellwig static void lio_tpg_close_session(struct se_session *se_sess) 1474e48354ceSNicholas Bellinger { 1475e48354ceSNicholas Bellinger struct iscsi_session *sess = se_sess->fabric_sess_ptr; 1476d36ad77fSNicholas Bellinger struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg; 147726a99c19SNicholas Bellinger 1478d36ad77fSNicholas Bellinger spin_lock_bh(&se_tpg->session_lock); 1479e48354ceSNicholas Bellinger spin_lock(&sess->conn_lock); 1480e48354ceSNicholas Bellinger if (atomic_read(&sess->session_fall_back_to_erl0) || 1481e48354ceSNicholas Bellinger atomic_read(&sess->session_logout) || 148257c46e9fSMaurizio Lombardi atomic_read(&sess->session_close) || 1483e48354ceSNicholas Bellinger (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) { 1484e48354ceSNicholas Bellinger spin_unlock(&sess->conn_lock); 1485d36ad77fSNicholas Bellinger spin_unlock_bh(&se_tpg->session_lock); 148644f33d0fSChristoph Hellwig return; 1487e48354ceSNicholas Bellinger } 148857c46e9fSMaurizio Lombardi iscsit_inc_session_usage_count(sess); 1489e48354ceSNicholas Bellinger atomic_set(&sess->session_reinstatement, 1); 1490197b806aSNicholas Bellinger atomic_set(&sess->session_fall_back_to_erl0, 1); 149157c46e9fSMaurizio Lombardi atomic_set(&sess->session_close, 1); 1492e48354ceSNicholas Bellinger spin_unlock(&sess->conn_lock); 1493e48354ceSNicholas Bellinger 1494e48354ceSNicholas Bellinger iscsit_stop_time2retain_timer(sess); 1495d36ad77fSNicholas Bellinger spin_unlock_bh(&se_tpg->session_lock); 149626a99c19SNicholas Bellinger 149799367f01SNicholas Bellinger iscsit_stop_session(sess, 1, 1); 149857c46e9fSMaurizio Lombardi iscsit_dec_session_usage_count(sess); 1499e48354ceSNicholas Bellinger } 1500e48354ceSNicholas Bellinger 1501e48354ceSNicholas Bellinger static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg) 1502e48354ceSNicholas Bellinger { 15032b6eb609SChristoph Hellwig return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index; 1504e48354ceSNicholas Bellinger } 1505e48354ceSNicholas Bellinger 1506e48354ceSNicholas Bellinger static void lio_set_default_node_attributes(struct se_node_acl *se_acl) 1507e48354ceSNicholas Bellinger { 1508e48354ceSNicholas Bellinger struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl, 1509e48354ceSNicholas Bellinger se_node_acl); 1510d1fa7a1dSNicholas Bellinger struct se_portal_group *se_tpg = se_acl->se_tpg; 1511d1fa7a1dSNicholas Bellinger struct iscsi_portal_group *tpg = container_of(se_tpg, 1512d1fa7a1dSNicholas Bellinger struct iscsi_portal_group, tpg_se_tpg); 1513e48354ceSNicholas Bellinger 1514b7eec2cdSAndy Grover acl->node_attrib.nacl = acl; 1515d1fa7a1dSNicholas Bellinger iscsit_set_default_node_attribues(acl, tpg); 1516e48354ceSNicholas Bellinger } 1517e48354ceSNicholas Bellinger 15183e1c81a9SNicholas Bellinger static int lio_check_stop_free(struct se_cmd *se_cmd) 15193e1c81a9SNicholas Bellinger { 1520afc16604SBart Van Assche return target_put_sess_cmd(se_cmd); 15213e1c81a9SNicholas Bellinger } 15223e1c81a9SNicholas Bellinger 1523e48354ceSNicholas Bellinger static void lio_release_cmd(struct se_cmd *se_cmd) 1524e48354ceSNicholas Bellinger { 152566cd9d4eSMax Gurtovoy struct iscsit_cmd *cmd = container_of(se_cmd, struct iscsit_cmd, se_cmd); 1526e48354ceSNicholas Bellinger 1527cdb72665SNicholas Bellinger pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd); 1528d703ce2fSNicholas Bellinger iscsit_release_cmd(cmd); 1529e48354ceSNicholas Bellinger } 1530e48354ceSNicholas Bellinger 15319ac8928eSChristoph Hellwig const struct target_core_fabric_ops iscsi_ops = { 15329ac8928eSChristoph Hellwig .module = THIS_MODULE, 153359a206b4SDavid Disseldorp .fabric_alias = "iscsi", 153430c7ca93SDavid Disseldorp .fabric_name = "iSCSI", 1535144bc4c2SChristoph Hellwig .node_acl_size = sizeof(struct iscsi_node_acl), 15369ac8928eSChristoph Hellwig .tpg_get_wwn = lio_tpg_get_endpoint_wwn, 15379ac8928eSChristoph Hellwig .tpg_get_tag = lio_tpg_get_tag, 15389ac8928eSChristoph Hellwig .tpg_get_default_depth = lio_tpg_get_default_depth, 15399ac8928eSChristoph Hellwig .tpg_check_demo_mode = lio_tpg_check_demo_mode, 15409ac8928eSChristoph Hellwig .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache, 15419ac8928eSChristoph Hellwig .tpg_check_demo_mode_write_protect = 15429ac8928eSChristoph Hellwig lio_tpg_check_demo_mode_write_protect, 15439ac8928eSChristoph Hellwig .tpg_check_prod_mode_write_protect = 15449ac8928eSChristoph Hellwig lio_tpg_check_prod_mode_write_protect, 15459ac8928eSChristoph Hellwig .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only, 15469ac8928eSChristoph Hellwig .tpg_get_inst_index = lio_tpg_get_inst_index, 15479ac8928eSChristoph Hellwig .check_stop_free = lio_check_stop_free, 15489ac8928eSChristoph Hellwig .release_cmd = lio_release_cmd, 15499ac8928eSChristoph Hellwig .close_session = lio_tpg_close_session, 15509ac8928eSChristoph Hellwig .sess_get_index = lio_sess_get_index, 15519ac8928eSChristoph Hellwig .sess_get_initiator_sid = lio_sess_get_initiator_sid, 15529ac8928eSChristoph Hellwig .write_pending = lio_write_pending, 15539ac8928eSChristoph Hellwig .set_default_node_attributes = lio_set_default_node_attributes, 15549ac8928eSChristoph Hellwig .get_cmd_state = iscsi_get_cmd_state, 15559ac8928eSChristoph Hellwig .queue_data_in = lio_queue_data_in, 15569ac8928eSChristoph Hellwig .queue_status = lio_queue_status, 15579ac8928eSChristoph Hellwig .queue_tm_rsp = lio_queue_tm_rsp, 15589ac8928eSChristoph Hellwig .aborted_task = lio_aborted_task, 15599ac8928eSChristoph Hellwig .fabric_make_wwn = lio_target_call_coreaddtiqn, 15609ac8928eSChristoph Hellwig .fabric_drop_wwn = lio_target_call_coredeltiqn, 1561839559e1SChristoph Hellwig .add_wwn_groups = lio_target_add_wwn_groups, 15629ac8928eSChristoph Hellwig .fabric_make_tpg = lio_target_tiqn_addtpg, 1563382731ecSDmitry Bogdanov .fabric_enable_tpg = lio_target_tiqn_enabletpg, 15649ac8928eSChristoph Hellwig .fabric_drop_tpg = lio_target_tiqn_deltpg, 15659ac8928eSChristoph Hellwig .fabric_make_np = lio_target_call_addnptotpg, 15669ac8928eSChristoph Hellwig .fabric_drop_np = lio_target_call_delnpfromtpg, 1567c7d6a803SChristoph Hellwig .fabric_init_nodeacl = lio_target_init_nodeacl, 1568e48354ceSNicholas Bellinger 15699ac8928eSChristoph Hellwig .tfc_discovery_attrs = lio_target_discovery_auth_attrs, 15709ac8928eSChristoph Hellwig .tfc_wwn_attrs = lio_target_wwn_attrs, 15719ac8928eSChristoph Hellwig .tfc_tpg_base_attrs = lio_target_tpg_attrs, 15729ac8928eSChristoph Hellwig .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs, 15739ac8928eSChristoph Hellwig .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs, 15749ac8928eSChristoph Hellwig .tfc_tpg_param_attrs = lio_target_tpg_param_attrs, 15759ac8928eSChristoph Hellwig .tfc_tpg_np_base_attrs = lio_target_portal_attrs, 15769ac8928eSChristoph Hellwig .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs, 15779ac8928eSChristoph Hellwig .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs, 15789ac8928eSChristoph Hellwig .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs, 15799ac8928eSChristoph Hellwig .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs, 1580fbbd4923SBart Van Assche 1581fbbd4923SBart Van Assche .write_pending_must_be_called = true, 15829ac8928eSChristoph Hellwig }; 1583