Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 2 | /******************************************************************************* |
| 3 | * This file contains the configfs implementation for iSCSI Target mode |
| 4 | * from the LIO-Target Project. |
| 5 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 6 | * (c) Copyright 2007-2013 Datera, Inc. |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 7 | * |
| 8 | * Author: Nicholas A. Bellinger <nab@linux-iscsi.org> |
| 9 | * |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 10 | ****************************************************************************/ |
| 11 | |
| 12 | #include <linux/configfs.h> |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 13 | #include <linux/ctype.h> |
Paul Gortmaker | c53181a | 2011-08-30 18:16:43 -0400 | [diff] [blame] | 14 | #include <linux/export.h> |
Stephen Rothwell | c3bc93d | 2012-01-23 11:39:49 +1100 | [diff] [blame] | 15 | #include <linux/inet.h> |
Bart Van Assche | 8dcf07b | 2016-11-14 15:47:14 -0800 | [diff] [blame] | 16 | #include <linux/module.h> |
| 17 | #include <net/ipv6.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 18 | #include <target/target_core_base.h> |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 19 | #include <target/target_core_fabric.h> |
Nicholas Bellinger | 2ec5a8c | 2013-03-20 15:29:15 -0700 | [diff] [blame] | 20 | #include <target/iscsi/iscsi_transport.h> |
Sagi Grimberg | 67f091f | 2015-01-07 14:57:31 +0200 | [diff] [blame] | 21 | #include <target/iscsi/iscsi_target_core.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 22 | #include "iscsi_target_parameters.h" |
| 23 | #include "iscsi_target_device.h" |
| 24 | #include "iscsi_target_erl0.h" |
| 25 | #include "iscsi_target_nodeattrib.h" |
| 26 | #include "iscsi_target_tpg.h" |
| 27 | #include "iscsi_target_util.h" |
| 28 | #include "iscsi_target.h" |
Sagi Grimberg | 67f091f | 2015-01-07 14:57:31 +0200 | [diff] [blame] | 29 | #include <target/iscsi/iscsi_target_stat.h> |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 30 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 31 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 32 | /* Start items for lio_target_portal_cit */ |
| 33 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 34 | static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 35 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 36 | return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np); |
| 37 | } |
| 38 | |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 39 | static ssize_t lio_target_np_driver_show(struct config_item *item, char *page, |
| 40 | enum iscsit_transport_type type) |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 41 | { |
| 42 | struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 43 | struct iscsi_tpg_np *tpg_np_new; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 44 | ssize_t rb; |
| 45 | |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 46 | tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type); |
| 47 | if (tpg_np_new) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 48 | rb = sprintf(page, "1\n"); |
| 49 | else |
| 50 | rb = sprintf(page, "0\n"); |
| 51 | |
| 52 | return rb; |
| 53 | } |
| 54 | |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 55 | static ssize_t lio_target_np_driver_store(struct config_item *item, |
| 56 | const char *page, size_t count, enum iscsit_transport_type type, |
| 57 | const char *mod_name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 58 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 59 | struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 60 | struct iscsi_np *np; |
| 61 | struct iscsi_portal_group *tpg; |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 62 | struct iscsi_tpg_np *tpg_np_new = NULL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 63 | u32 op; |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 64 | int rc; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 65 | |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 66 | rc = kstrtou32(page, 0, &op); |
| 67 | if (rc) |
| 68 | return rc; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 69 | if ((op != 1) && (op != 0)) { |
| 70 | pr_err("Illegal value for tpg_enable: %u\n", op); |
| 71 | return -EINVAL; |
| 72 | } |
| 73 | np = tpg_np->tpg_np; |
| 74 | if (!np) { |
| 75 | pr_err("Unable to locate struct iscsi_np from" |
| 76 | " struct iscsi_tpg_np\n"); |
| 77 | return -EINVAL; |
| 78 | } |
| 79 | |
| 80 | tpg = tpg_np->tpg; |
| 81 | if (iscsit_get_tpg(tpg) < 0) |
| 82 | return -EINVAL; |
| 83 | |
| 84 | if (op) { |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 85 | if (strlen(mod_name)) { |
| 86 | rc = request_module(mod_name); |
| 87 | if (rc != 0) { |
| 88 | pr_warn("Unable to request_module for %s\n", |
| 89 | mod_name); |
| 90 | rc = 0; |
| 91 | } |
Andy Grover | 58bd0c6 | 2013-05-29 12:05:59 -0700 | [diff] [blame] | 92 | } |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 93 | |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 94 | tpg_np_new = iscsit_tpg_add_network_portal(tpg, |
| 95 | &np->np_sockaddr, tpg_np, type); |
Varun Prakash | 83337e5 | 2016-12-11 22:05:56 +0530 | [diff] [blame] | 96 | if (IS_ERR(tpg_np_new)) { |
| 97 | rc = PTR_ERR(tpg_np_new); |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 98 | goto out; |
Varun Prakash | 83337e5 | 2016-12-11 22:05:56 +0530 | [diff] [blame] | 99 | } |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 100 | } else { |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 101 | tpg_np_new = iscsit_tpg_locate_child_np(tpg_np, type); |
| 102 | if (tpg_np_new) { |
| 103 | rc = iscsit_tpg_del_network_portal(tpg, tpg_np_new); |
Andy Grover | 58bd0c6 | 2013-05-29 12:05:59 -0700 | [diff] [blame] | 104 | if (rc < 0) |
| 105 | goto out; |
| 106 | } |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 109 | iscsit_put_tpg(tpg); |
| 110 | return count; |
| 111 | out: |
| 112 | iscsit_put_tpg(tpg); |
Andy Grover | 58bd0c6 | 2013-05-29 12:05:59 -0700 | [diff] [blame] | 113 | return rc; |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 116 | static ssize_t lio_target_np_iser_show(struct config_item *item, char *page) |
Varun Prakash | 1c46960 | 2016-04-20 00:00:16 +0530 | [diff] [blame] | 117 | { |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 118 | return lio_target_np_driver_show(item, page, ISCSI_INFINIBAND); |
| 119 | } |
Varun Prakash | 1c46960 | 2016-04-20 00:00:16 +0530 | [diff] [blame] | 120 | |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 121 | static ssize_t lio_target_np_iser_store(struct config_item *item, |
| 122 | const char *page, size_t count) |
| 123 | { |
| 124 | return lio_target_np_driver_store(item, page, count, |
| 125 | ISCSI_INFINIBAND, "ib_isert"); |
| 126 | } |
| 127 | CONFIGFS_ATTR(lio_target_np_, iser); |
Varun Prakash | 1c46960 | 2016-04-20 00:00:16 +0530 | [diff] [blame] | 128 | |
Nicholas Bellinger | ff7199b | 2016-05-14 22:28:51 -0700 | [diff] [blame] | 129 | static ssize_t lio_target_np_cxgbit_show(struct config_item *item, char *page) |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 130 | { |
Nicholas Bellinger | ff7199b | 2016-05-14 22:28:51 -0700 | [diff] [blame] | 131 | return lio_target_np_driver_show(item, page, ISCSI_CXGBIT); |
Varun Prakash | 1c46960 | 2016-04-20 00:00:16 +0530 | [diff] [blame] | 132 | } |
| 133 | |
Nicholas Bellinger | ff7199b | 2016-05-14 22:28:51 -0700 | [diff] [blame] | 134 | static ssize_t lio_target_np_cxgbit_store(struct config_item *item, |
| 135 | const char *page, size_t count) |
Varun Prakash | 1c46960 | 2016-04-20 00:00:16 +0530 | [diff] [blame] | 136 | { |
Nicholas Bellinger | d4b3fa4 | 2016-05-14 21:44:01 -0700 | [diff] [blame] | 137 | return lio_target_np_driver_store(item, page, count, |
Nicholas Bellinger | ff7199b | 2016-05-14 22:28:51 -0700 | [diff] [blame] | 138 | ISCSI_CXGBIT, "cxgbit"); |
Varun Prakash | 1c46960 | 2016-04-20 00:00:16 +0530 | [diff] [blame] | 139 | } |
Nicholas Bellinger | ff7199b | 2016-05-14 22:28:51 -0700 | [diff] [blame] | 140 | CONFIGFS_ATTR(lio_target_np_, cxgbit); |
Nicholas Bellinger | 72438cd | 2013-03-06 22:20:36 -0800 | [diff] [blame] | 141 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 142 | static struct configfs_attribute *lio_target_portal_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 143 | &lio_target_np_attr_iser, |
Nicholas Bellinger | ff7199b | 2016-05-14 22:28:51 -0700 | [diff] [blame] | 144 | &lio_target_np_attr_cxgbit, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 145 | NULL, |
| 146 | }; |
| 147 | |
| 148 | /* Stop items for lio_target_portal_cit */ |
| 149 | |
| 150 | /* Start items for lio_target_np_cit */ |
| 151 | |
| 152 | #define MAX_PORTAL_LEN 256 |
| 153 | |
Christoph Hellwig | fceb5bc | 2012-09-26 08:00:36 -0400 | [diff] [blame] | 154 | static struct se_tpg_np *lio_target_call_addnptotpg( |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 155 | struct se_portal_group *se_tpg, |
| 156 | struct config_group *group, |
| 157 | const char *name) |
| 158 | { |
| 159 | struct iscsi_portal_group *tpg; |
| 160 | struct iscsi_tpg_np *tpg_np; |
| 161 | char *str, *str2, *ip_str, *port_str; |
Sagi Grimberg | 4459e04 | 2017-02-06 12:51:03 +0200 | [diff] [blame] | 162 | struct sockaddr_storage sockaddr = { }; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 163 | int ret; |
| 164 | char buf[MAX_PORTAL_LEN + 1]; |
| 165 | |
| 166 | if (strlen(name) > MAX_PORTAL_LEN) { |
| 167 | pr_err("strlen(name): %d exceeds MAX_PORTAL_LEN: %d\n", |
| 168 | (int)strlen(name), MAX_PORTAL_LEN); |
| 169 | return ERR_PTR(-EOVERFLOW); |
| 170 | } |
| 171 | memset(buf, 0, MAX_PORTAL_LEN + 1); |
Nicholas Bellinger | 7bbb654 | 2011-07-27 12:37:03 -0700 | [diff] [blame] | 172 | snprintf(buf, MAX_PORTAL_LEN + 1, "%s", name); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 173 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 174 | str = strstr(buf, "["); |
| 175 | if (str) { |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 176 | str2 = strstr(str, "]"); |
| 177 | if (!str2) { |
| 178 | pr_err("Unable to locate trailing \"]\"" |
| 179 | " in IPv6 iSCSI network portal address\n"); |
| 180 | return ERR_PTR(-EINVAL); |
| 181 | } |
Sagi Grimberg | 4459e04 | 2017-02-06 12:51:03 +0200 | [diff] [blame] | 182 | |
| 183 | ip_str = str + 1; /* Skip over leading "[" */ |
Andy Grover | 76c28f1 | 2015-08-24 10:26:03 -0700 | [diff] [blame] | 184 | *str2 = '\0'; /* Terminate the unbracketed IPv6 address */ |
| 185 | str2++; /* Skip over the \0 */ |
Sagi Grimberg | 4459e04 | 2017-02-06 12:51:03 +0200 | [diff] [blame] | 186 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 187 | port_str = strstr(str2, ":"); |
| 188 | if (!port_str) { |
| 189 | pr_err("Unable to locate \":port\"" |
| 190 | " in IPv6 iSCSI network portal address\n"); |
| 191 | return ERR_PTR(-EINVAL); |
| 192 | } |
| 193 | *port_str = '\0'; /* Terminate string for IP */ |
| 194 | port_str++; /* Skip over ":" */ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 195 | } else { |
Sagi Grimberg | 4459e04 | 2017-02-06 12:51:03 +0200 | [diff] [blame] | 196 | ip_str = &buf[0]; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 197 | port_str = strstr(ip_str, ":"); |
| 198 | if (!port_str) { |
| 199 | pr_err("Unable to locate \":port\"" |
| 200 | " in IPv4 iSCSI network portal address\n"); |
| 201 | return ERR_PTR(-EINVAL); |
| 202 | } |
| 203 | *port_str = '\0'; /* Terminate string for IP */ |
| 204 | port_str++; /* Skip over ":" */ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 205 | } |
Sagi Grimberg | 4459e04 | 2017-02-06 12:51:03 +0200 | [diff] [blame] | 206 | |
| 207 | ret = inet_pton_with_scope(&init_net, AF_UNSPEC, ip_str, |
| 208 | port_str, &sockaddr); |
| 209 | if (ret) { |
| 210 | pr_err("malformed ip/port passed: %s\n", name); |
| 211 | return ERR_PTR(ret); |
| 212 | } |
| 213 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 214 | tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); |
| 215 | ret = iscsit_get_tpg(tpg); |
| 216 | if (ret < 0) |
| 217 | return ERR_PTR(-EINVAL); |
| 218 | |
| 219 | pr_debug("LIO_Target_ConfigFS: REGISTER -> %s TPGT: %hu" |
| 220 | " PORTAL: %s\n", |
| 221 | config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), |
| 222 | tpg->tpgt, name); |
| 223 | /* |
| 224 | * Assume ISCSI_TCP by default. Other network portals for other |
| 225 | * iSCSI fabrics: |
| 226 | * |
| 227 | * Traditional iSCSI over SCTP (initial support) |
| 228 | * iSER/TCP (TODO, hardware available) |
| 229 | * iSER/SCTP (TODO, software emulation with osc-iwarp) |
| 230 | * iSER/IB (TODO, hardware available) |
| 231 | * |
Masanari Iida | 2087969 | 2012-08-27 22:46:00 +0900 | [diff] [blame] | 232 | * can be enabled with attributes under |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 233 | * sys/kernel/config/iscsi/$IQN/$TPG/np/$IP:$PORT/ |
| 234 | * |
| 235 | */ |
Andy Grover | 76c28f1 | 2015-08-24 10:26:03 -0700 | [diff] [blame] | 236 | tpg_np = iscsit_tpg_add_network_portal(tpg, &sockaddr, NULL, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 237 | ISCSI_TCP); |
| 238 | if (IS_ERR(tpg_np)) { |
| 239 | iscsit_put_tpg(tpg); |
Thomas Meyer | e1750ba | 2011-08-01 23:58:18 +0200 | [diff] [blame] | 240 | return ERR_CAST(tpg_np); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 241 | } |
| 242 | pr_debug("LIO_Target_ConfigFS: addnptotpg done!\n"); |
| 243 | |
| 244 | iscsit_put_tpg(tpg); |
| 245 | return &tpg_np->se_tpg_np; |
| 246 | } |
| 247 | |
| 248 | static void lio_target_call_delnpfromtpg( |
| 249 | struct se_tpg_np *se_tpg_np) |
| 250 | { |
| 251 | struct iscsi_portal_group *tpg; |
| 252 | struct iscsi_tpg_np *tpg_np; |
| 253 | struct se_portal_group *se_tpg; |
| 254 | int ret; |
| 255 | |
| 256 | tpg_np = container_of(se_tpg_np, struct iscsi_tpg_np, se_tpg_np); |
| 257 | tpg = tpg_np->tpg; |
| 258 | ret = iscsit_get_tpg(tpg); |
| 259 | if (ret < 0) |
| 260 | return; |
| 261 | |
| 262 | se_tpg = &tpg->tpg_se_tpg; |
| 263 | pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s TPGT: %hu" |
Andy Grover | 69d7557 | 2015-08-24 10:26:04 -0700 | [diff] [blame] | 264 | " PORTAL: %pISpc\n", config_item_name(&se_tpg->se_tpg_wwn->wwn_group.cg_item), |
| 265 | tpg->tpgt, &tpg_np->tpg_np->np_sockaddr); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 266 | |
| 267 | ret = iscsit_tpg_del_network_portal(tpg, tpg_np); |
| 268 | if (ret < 0) |
| 269 | goto out; |
| 270 | |
| 271 | pr_debug("LIO_Target_ConfigFS: delnpfromtpg done!\n"); |
| 272 | out: |
| 273 | iscsit_put_tpg(tpg); |
| 274 | } |
| 275 | |
| 276 | /* End items for lio_target_np_cit */ |
| 277 | |
| 278 | /* Start items for lio_target_nacl_attrib_cit */ |
| 279 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 280 | #define ISCSI_NACL_ATTR(name) \ |
| 281 | static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\ |
| 282 | char *page) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 283 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 284 | struct se_node_acl *se_nacl = attrib_to_nacl(item); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 285 | struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ |
| 286 | se_node_acl); \ |
| 287 | \ |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 288 | return sprintf(page, "%u\n", nacl->node_attrib.name); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 289 | } \ |
| 290 | \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 291 | static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\ |
| 292 | const char *page, size_t count) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 293 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 294 | struct se_node_acl *se_nacl = attrib_to_nacl(item); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 295 | struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ |
| 296 | se_node_acl); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 297 | u32 val; \ |
| 298 | int ret; \ |
| 299 | \ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 300 | ret = kstrtou32(page, 0, &val); \ |
| 301 | if (ret) \ |
| 302 | return ret; \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 303 | ret = iscsit_na_##name(nacl, val); \ |
| 304 | if (ret < 0) \ |
| 305 | return ret; \ |
| 306 | \ |
| 307 | return count; \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 308 | } \ |
| 309 | \ |
| 310 | CONFIGFS_ATTR(iscsi_nacl_attrib_, name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 311 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 312 | ISCSI_NACL_ATTR(dataout_timeout); |
| 313 | ISCSI_NACL_ATTR(dataout_timeout_retries); |
| 314 | ISCSI_NACL_ATTR(default_erl); |
| 315 | ISCSI_NACL_ATTR(nopin_timeout); |
| 316 | ISCSI_NACL_ATTR(nopin_response_timeout); |
| 317 | ISCSI_NACL_ATTR(random_datain_pdu_offsets); |
| 318 | ISCSI_NACL_ATTR(random_datain_seq_offsets); |
| 319 | ISCSI_NACL_ATTR(random_r2t_offsets); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 320 | |
| 321 | static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 322 | &iscsi_nacl_attrib_attr_dataout_timeout, |
| 323 | &iscsi_nacl_attrib_attr_dataout_timeout_retries, |
| 324 | &iscsi_nacl_attrib_attr_default_erl, |
| 325 | &iscsi_nacl_attrib_attr_nopin_timeout, |
| 326 | &iscsi_nacl_attrib_attr_nopin_response_timeout, |
| 327 | &iscsi_nacl_attrib_attr_random_datain_pdu_offsets, |
| 328 | &iscsi_nacl_attrib_attr_random_datain_seq_offsets, |
| 329 | &iscsi_nacl_attrib_attr_random_r2t_offsets, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 330 | NULL, |
| 331 | }; |
| 332 | |
| 333 | /* End items for lio_target_nacl_attrib_cit */ |
| 334 | |
| 335 | /* Start items for lio_target_nacl_auth_cit */ |
| 336 | |
| 337 | #define __DEF_NACL_AUTH_STR(prefix, name, flags) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 338 | static ssize_t __iscsi_##prefix##_##name##_show( \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 339 | struct iscsi_node_acl *nacl, \ |
| 340 | char *page) \ |
| 341 | { \ |
| 342 | struct iscsi_node_auth *auth = &nacl->node_auth; \ |
| 343 | \ |
| 344 | if (!capable(CAP_SYS_ADMIN)) \ |
| 345 | return -EPERM; \ |
| 346 | return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ |
| 347 | } \ |
| 348 | \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 349 | static ssize_t __iscsi_##prefix##_##name##_store( \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 350 | struct iscsi_node_acl *nacl, \ |
| 351 | const char *page, \ |
| 352 | size_t count) \ |
| 353 | { \ |
| 354 | struct iscsi_node_auth *auth = &nacl->node_auth; \ |
| 355 | \ |
| 356 | if (!capable(CAP_SYS_ADMIN)) \ |
| 357 | return -EPERM; \ |
Eric Seppanen | 2306bfb | 2013-11-21 14:49:56 -0800 | [diff] [blame] | 358 | if (count >= sizeof(auth->name)) \ |
| 359 | return -EINVAL; \ |
Jörn Engel | 0fbfc46 | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 360 | snprintf(auth->name, sizeof(auth->name), "%s", page); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 361 | if (!strncmp("NULL", auth->name, 4)) \ |
| 362 | auth->naf_flags &= ~flags; \ |
| 363 | else \ |
| 364 | auth->naf_flags |= flags; \ |
| 365 | \ |
| 366 | if ((auth->naf_flags & NAF_USERID_IN_SET) && \ |
| 367 | (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ |
| 368 | auth->authenticate_target = 1; \ |
| 369 | else \ |
| 370 | auth->authenticate_target = 0; \ |
| 371 | \ |
| 372 | return count; \ |
| 373 | } |
| 374 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 375 | #define DEF_NACL_AUTH_STR(name, flags) \ |
| 376 | __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \ |
| 377 | static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \ |
| 378 | char *page) \ |
| 379 | { \ |
| 380 | struct se_node_acl *nacl = auth_to_nacl(item); \ |
| 381 | return __iscsi_nacl_auth_##name##_show(container_of(nacl, \ |
| 382 | struct iscsi_node_acl, se_node_acl), page); \ |
| 383 | } \ |
| 384 | static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \ |
| 385 | const char *page, size_t count) \ |
| 386 | { \ |
| 387 | struct se_node_acl *nacl = auth_to_nacl(item); \ |
| 388 | return __iscsi_nacl_auth_##name##_store(container_of(nacl, \ |
| 389 | struct iscsi_node_acl, se_node_acl), page, count); \ |
| 390 | } \ |
| 391 | \ |
| 392 | CONFIGFS_ATTR(iscsi_nacl_auth_, name) |
| 393 | |
| 394 | /* |
| 395 | * One-way authentication userid |
| 396 | */ |
| 397 | DEF_NACL_AUTH_STR(userid, NAF_USERID_SET); |
| 398 | DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET); |
| 399 | DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); |
| 400 | DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); |
| 401 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 402 | #define __DEF_NACL_AUTH_INT(prefix, name) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 403 | static ssize_t __iscsi_##prefix##_##name##_show( \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 404 | struct iscsi_node_acl *nacl, \ |
| 405 | char *page) \ |
| 406 | { \ |
| 407 | struct iscsi_node_auth *auth = &nacl->node_auth; \ |
| 408 | \ |
| 409 | if (!capable(CAP_SYS_ADMIN)) \ |
| 410 | return -EPERM; \ |
| 411 | \ |
| 412 | return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ |
| 413 | } |
| 414 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 415 | #define DEF_NACL_AUTH_INT(name) \ |
| 416 | __DEF_NACL_AUTH_INT(nacl_auth, name) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 417 | static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \ |
| 418 | char *page) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 419 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 420 | struct se_node_acl *nacl = auth_to_nacl(item); \ |
| 421 | return __iscsi_nacl_auth_##name##_show(container_of(nacl, \ |
| 422 | struct iscsi_node_acl, se_node_acl), page); \ |
| 423 | } \ |
| 424 | \ |
| 425 | CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 426 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 427 | DEF_NACL_AUTH_INT(authenticate_target); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 428 | |
| 429 | static struct configfs_attribute *lio_target_nacl_auth_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 430 | &iscsi_nacl_auth_attr_userid, |
| 431 | &iscsi_nacl_auth_attr_password, |
| 432 | &iscsi_nacl_auth_attr_authenticate_target, |
| 433 | &iscsi_nacl_auth_attr_userid_mutual, |
| 434 | &iscsi_nacl_auth_attr_password_mutual, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 435 | NULL, |
| 436 | }; |
| 437 | |
| 438 | /* End items for lio_target_nacl_auth_cit */ |
| 439 | |
| 440 | /* Start items for lio_target_nacl_param_cit */ |
| 441 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 442 | #define ISCSI_NACL_PARAM(name) \ |
| 443 | static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \ |
| 444 | char *page) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 445 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 446 | struct se_node_acl *se_nacl = param_to_nacl(item); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 447 | struct iscsi_session *sess; \ |
| 448 | struct se_session *se_sess; \ |
| 449 | ssize_t rb; \ |
| 450 | \ |
| 451 | spin_lock_bh(&se_nacl->nacl_sess_lock); \ |
| 452 | se_sess = se_nacl->nacl_sess; \ |
| 453 | if (!se_sess) { \ |
| 454 | rb = snprintf(page, PAGE_SIZE, \ |
| 455 | "No Active iSCSI Session\n"); \ |
| 456 | } else { \ |
| 457 | sess = se_sess->fabric_sess_ptr; \ |
| 458 | rb = snprintf(page, PAGE_SIZE, "%u\n", \ |
| 459 | (u32)sess->sess_ops->name); \ |
| 460 | } \ |
| 461 | spin_unlock_bh(&se_nacl->nacl_sess_lock); \ |
| 462 | \ |
| 463 | return rb; \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 464 | } \ |
| 465 | \ |
| 466 | CONFIGFS_ATTR_RO(iscsi_nacl_param_, name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 467 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 468 | ISCSI_NACL_PARAM(MaxConnections); |
| 469 | ISCSI_NACL_PARAM(InitialR2T); |
| 470 | ISCSI_NACL_PARAM(ImmediateData); |
| 471 | ISCSI_NACL_PARAM(MaxBurstLength); |
| 472 | ISCSI_NACL_PARAM(FirstBurstLength); |
| 473 | ISCSI_NACL_PARAM(DefaultTime2Wait); |
| 474 | ISCSI_NACL_PARAM(DefaultTime2Retain); |
| 475 | ISCSI_NACL_PARAM(MaxOutstandingR2T); |
| 476 | ISCSI_NACL_PARAM(DataPDUInOrder); |
| 477 | ISCSI_NACL_PARAM(DataSequenceInOrder); |
| 478 | ISCSI_NACL_PARAM(ErrorRecoveryLevel); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 479 | |
| 480 | static struct configfs_attribute *lio_target_nacl_param_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 481 | &iscsi_nacl_param_attr_MaxConnections, |
| 482 | &iscsi_nacl_param_attr_InitialR2T, |
| 483 | &iscsi_nacl_param_attr_ImmediateData, |
| 484 | &iscsi_nacl_param_attr_MaxBurstLength, |
| 485 | &iscsi_nacl_param_attr_FirstBurstLength, |
| 486 | &iscsi_nacl_param_attr_DefaultTime2Wait, |
| 487 | &iscsi_nacl_param_attr_DefaultTime2Retain, |
| 488 | &iscsi_nacl_param_attr_MaxOutstandingR2T, |
| 489 | &iscsi_nacl_param_attr_DataPDUInOrder, |
| 490 | &iscsi_nacl_param_attr_DataSequenceInOrder, |
| 491 | &iscsi_nacl_param_attr_ErrorRecoveryLevel, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 492 | NULL, |
| 493 | }; |
| 494 | |
| 495 | /* End items for lio_target_nacl_param_cit */ |
| 496 | |
| 497 | /* Start items for lio_target_acl_cit */ |
| 498 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 499 | static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 500 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 501 | struct se_node_acl *se_nacl = acl_to_nacl(item); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 502 | struct iscsi_session *sess; |
| 503 | struct iscsi_conn *conn; |
| 504 | struct se_session *se_sess; |
| 505 | ssize_t rb = 0; |
Roland Dreier | 109e238 | 2015-07-23 14:53:32 -0700 | [diff] [blame] | 506 | u32 max_cmd_sn; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 507 | |
| 508 | spin_lock_bh(&se_nacl->nacl_sess_lock); |
| 509 | se_sess = se_nacl->nacl_sess; |
| 510 | if (!se_sess) { |
| 511 | rb += sprintf(page+rb, "No active iSCSI Session for Initiator" |
| 512 | " Endpoint: %s\n", se_nacl->initiatorname); |
| 513 | } else { |
| 514 | sess = se_sess->fabric_sess_ptr; |
| 515 | |
Joern Engel | cb35484 | 2014-09-02 17:49:50 -0400 | [diff] [blame] | 516 | rb += sprintf(page+rb, "InitiatorName: %s\n", |
| 517 | sess->sess_ops->InitiatorName); |
| 518 | rb += sprintf(page+rb, "InitiatorAlias: %s\n", |
| 519 | sess->sess_ops->InitiatorAlias); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 520 | |
Andy Shevchenko | 5cdf5a8 | 2015-01-15 13:40:56 +0200 | [diff] [blame] | 521 | rb += sprintf(page+rb, |
| 522 | "LIO Session ID: %u ISID: 0x%6ph TSIH: %hu ", |
| 523 | sess->sid, sess->isid, sess->tsih); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 524 | rb += sprintf(page+rb, "SessionType: %s\n", |
| 525 | (sess->sess_ops->SessionType) ? |
| 526 | "Discovery" : "Normal"); |
| 527 | rb += sprintf(page+rb, "Session State: "); |
| 528 | switch (sess->session_state) { |
| 529 | case TARG_SESS_STATE_FREE: |
| 530 | rb += sprintf(page+rb, "TARG_SESS_FREE\n"); |
| 531 | break; |
| 532 | case TARG_SESS_STATE_ACTIVE: |
| 533 | rb += sprintf(page+rb, "TARG_SESS_STATE_ACTIVE\n"); |
| 534 | break; |
| 535 | case TARG_SESS_STATE_LOGGED_IN: |
| 536 | rb += sprintf(page+rb, "TARG_SESS_STATE_LOGGED_IN\n"); |
| 537 | break; |
| 538 | case TARG_SESS_STATE_FAILED: |
| 539 | rb += sprintf(page+rb, "TARG_SESS_STATE_FAILED\n"); |
| 540 | break; |
| 541 | case TARG_SESS_STATE_IN_CONTINUE: |
| 542 | rb += sprintf(page+rb, "TARG_SESS_STATE_IN_CONTINUE\n"); |
| 543 | break; |
| 544 | default: |
| 545 | rb += sprintf(page+rb, "ERROR: Unknown Session" |
| 546 | " State!\n"); |
| 547 | break; |
| 548 | } |
| 549 | |
| 550 | rb += sprintf(page+rb, "---------------------[iSCSI Session" |
| 551 | " Values]-----------------------\n"); |
| 552 | rb += sprintf(page+rb, " CmdSN/WR : CmdSN/WC : ExpCmdSN" |
| 553 | " : MaxCmdSN : ITT : TTT\n"); |
Roland Dreier | 109e238 | 2015-07-23 14:53:32 -0700 | [diff] [blame] | 554 | max_cmd_sn = (u32) atomic_read(&sess->max_cmd_sn); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 555 | rb += sprintf(page+rb, " 0x%08x 0x%08x 0x%08x 0x%08x" |
| 556 | " 0x%08x 0x%08x\n", |
| 557 | sess->cmdsn_window, |
Roland Dreier | 109e238 | 2015-07-23 14:53:32 -0700 | [diff] [blame] | 558 | (max_cmd_sn - sess->exp_cmd_sn) + 1, |
| 559 | sess->exp_cmd_sn, max_cmd_sn, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 560 | sess->init_task_tag, sess->targ_xfer_tag); |
| 561 | rb += sprintf(page+rb, "----------------------[iSCSI" |
| 562 | " Connections]-------------------------\n"); |
| 563 | |
| 564 | spin_lock(&sess->conn_lock); |
| 565 | list_for_each_entry(conn, &sess->sess_conn_list, conn_list) { |
| 566 | rb += sprintf(page+rb, "CID: %hu Connection" |
| 567 | " State: ", conn->cid); |
| 568 | switch (conn->conn_state) { |
| 569 | case TARG_CONN_STATE_FREE: |
| 570 | rb += sprintf(page+rb, |
| 571 | "TARG_CONN_STATE_FREE\n"); |
| 572 | break; |
| 573 | case TARG_CONN_STATE_XPT_UP: |
| 574 | rb += sprintf(page+rb, |
| 575 | "TARG_CONN_STATE_XPT_UP\n"); |
| 576 | break; |
| 577 | case TARG_CONN_STATE_IN_LOGIN: |
| 578 | rb += sprintf(page+rb, |
| 579 | "TARG_CONN_STATE_IN_LOGIN\n"); |
| 580 | break; |
| 581 | case TARG_CONN_STATE_LOGGED_IN: |
| 582 | rb += sprintf(page+rb, |
| 583 | "TARG_CONN_STATE_LOGGED_IN\n"); |
| 584 | break; |
| 585 | case TARG_CONN_STATE_IN_LOGOUT: |
| 586 | rb += sprintf(page+rb, |
| 587 | "TARG_CONN_STATE_IN_LOGOUT\n"); |
| 588 | break; |
| 589 | case TARG_CONN_STATE_LOGOUT_REQUESTED: |
| 590 | rb += sprintf(page+rb, |
| 591 | "TARG_CONN_STATE_LOGOUT_REQUESTED\n"); |
| 592 | break; |
| 593 | case TARG_CONN_STATE_CLEANUP_WAIT: |
| 594 | rb += sprintf(page+rb, |
| 595 | "TARG_CONN_STATE_CLEANUP_WAIT\n"); |
| 596 | break; |
| 597 | default: |
| 598 | rb += sprintf(page+rb, |
| 599 | "ERROR: Unknown Connection State!\n"); |
| 600 | break; |
| 601 | } |
| 602 | |
Andy Grover | dc58f76 | 2015-08-24 10:26:05 -0700 | [diff] [blame] | 603 | rb += sprintf(page+rb, " Address %pISc %s", &conn->login_sockaddr, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 604 | (conn->network_transport == ISCSI_TCP) ? |
| 605 | "TCP" : "SCTP"); |
| 606 | rb += sprintf(page+rb, " StatSN: 0x%08x\n", |
| 607 | conn->stat_sn); |
| 608 | } |
| 609 | spin_unlock(&sess->conn_lock); |
| 610 | } |
| 611 | spin_unlock_bh(&se_nacl->nacl_sess_lock); |
| 612 | |
| 613 | return rb; |
| 614 | } |
| 615 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 616 | static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item, |
| 617 | char *page) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 618 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 619 | return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 620 | } |
| 621 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 622 | static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item, |
| 623 | const char *page, size_t count) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 624 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 625 | struct se_node_acl *se_nacl = acl_to_nacl(item); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 626 | struct se_portal_group *se_tpg = se_nacl->se_tpg; |
| 627 | struct iscsi_portal_group *tpg = container_of(se_tpg, |
| 628 | struct iscsi_portal_group, tpg_se_tpg); |
| 629 | struct config_item *acl_ci, *tpg_ci, *wwn_ci; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 630 | u32 cmdsn_depth = 0; |
| 631 | int ret; |
| 632 | |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 633 | ret = kstrtou32(page, 0, &cmdsn_depth); |
| 634 | if (ret) |
| 635 | return ret; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 636 | if (cmdsn_depth > TA_DEFAULT_CMDSN_DEPTH_MAX) { |
| 637 | pr_err("Passed cmdsn_depth: %u exceeds" |
| 638 | " TA_DEFAULT_CMDSN_DEPTH_MAX: %u\n", cmdsn_depth, |
| 639 | TA_DEFAULT_CMDSN_DEPTH_MAX); |
| 640 | return -EINVAL; |
| 641 | } |
| 642 | acl_ci = &se_nacl->acl_group.cg_item; |
| 643 | if (!acl_ci) { |
| 644 | pr_err("Unable to locatel acl_ci\n"); |
| 645 | return -EINVAL; |
| 646 | } |
| 647 | tpg_ci = &acl_ci->ci_parent->ci_group->cg_item; |
| 648 | if (!tpg_ci) { |
| 649 | pr_err("Unable to locate tpg_ci\n"); |
| 650 | return -EINVAL; |
| 651 | } |
| 652 | wwn_ci = &tpg_ci->ci_group->cg_item; |
| 653 | if (!wwn_ci) { |
| 654 | pr_err("Unable to locate config_item wwn_ci\n"); |
| 655 | return -EINVAL; |
| 656 | } |
| 657 | |
| 658 | if (iscsit_get_tpg(tpg) < 0) |
| 659 | return -EINVAL; |
Nicholas Bellinger | d36ad77 | 2016-01-07 22:15:06 -0800 | [diff] [blame] | 660 | |
| 661 | ret = core_tpg_set_initiator_node_queue_depth(se_nacl, cmdsn_depth); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 662 | |
| 663 | pr_debug("LIO_Target_ConfigFS: %s/%s Set CmdSN Window: %u for" |
| 664 | "InitiatorName: %s\n", config_item_name(wwn_ci), |
| 665 | config_item_name(tpg_ci), cmdsn_depth, |
| 666 | config_item_name(acl_ci)); |
| 667 | |
| 668 | iscsit_put_tpg(tpg); |
| 669 | return (!ret) ? count : (ssize_t)ret; |
| 670 | } |
| 671 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 672 | static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page) |
Andy Grover | 79e62fc | 2012-12-11 16:30:53 -0800 | [diff] [blame] | 673 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 674 | return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag); |
Andy Grover | 79e62fc | 2012-12-11 16:30:53 -0800 | [diff] [blame] | 675 | } |
| 676 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 677 | static ssize_t lio_target_nacl_tag_store(struct config_item *item, |
| 678 | const char *page, size_t count) |
Andy Grover | 79e62fc | 2012-12-11 16:30:53 -0800 | [diff] [blame] | 679 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 680 | struct se_node_acl *se_nacl = acl_to_nacl(item); |
Andy Grover | 79e62fc | 2012-12-11 16:30:53 -0800 | [diff] [blame] | 681 | int ret; |
| 682 | |
| 683 | ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page); |
| 684 | |
| 685 | if (ret < 0) |
| 686 | return ret; |
| 687 | return count; |
| 688 | } |
| 689 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 690 | CONFIGFS_ATTR_RO(lio_target_nacl_, info); |
| 691 | CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth); |
| 692 | CONFIGFS_ATTR(lio_target_nacl_, tag); |
Andy Grover | 79e62fc | 2012-12-11 16:30:53 -0800 | [diff] [blame] | 693 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 694 | static struct configfs_attribute *lio_target_initiator_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 695 | &lio_target_nacl_attr_info, |
| 696 | &lio_target_nacl_attr_cmdsn_depth, |
| 697 | &lio_target_nacl_attr_tag, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 698 | NULL, |
| 699 | }; |
| 700 | |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 701 | static int lio_target_init_nodeacl(struct se_node_acl *se_nacl, |
| 702 | const char *name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 703 | { |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 704 | struct iscsi_node_acl *acl = |
| 705 | container_of(se_nacl, struct iscsi_node_acl, se_node_acl); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 706 | |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 707 | config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 708 | "iscsi_sess_stats", &iscsi_stat_sess_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 709 | configfs_add_default_group(&acl->node_stat_grps.iscsi_sess_stats_group, |
| 710 | &se_nacl->acl_fabric_stat_group); |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 711 | return 0; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 714 | /* End items for lio_target_acl_cit */ |
| 715 | |
| 716 | /* Start items for lio_target_tpg_attrib_cit */ |
| 717 | |
| 718 | #define DEF_TPG_ATTRIB(name) \ |
| 719 | \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 720 | static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \ |
| 721 | char *page) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 722 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 723 | struct se_portal_group *se_tpg = attrib_to_tpg(item); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 724 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 725 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 726 | ssize_t rb; \ |
| 727 | \ |
| 728 | if (iscsit_get_tpg(tpg) < 0) \ |
| 729 | return -EINVAL; \ |
| 730 | \ |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 731 | rb = sprintf(page, "%u\n", tpg->tpg_attrib.name); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 732 | iscsit_put_tpg(tpg); \ |
| 733 | return rb; \ |
| 734 | } \ |
| 735 | \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 736 | static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\ |
| 737 | const char *page, size_t count) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 738 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 739 | struct se_portal_group *se_tpg = attrib_to_tpg(item); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 740 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 741 | struct iscsi_portal_group, tpg_se_tpg); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 742 | u32 val; \ |
| 743 | int ret; \ |
| 744 | \ |
| 745 | if (iscsit_get_tpg(tpg) < 0) \ |
| 746 | return -EINVAL; \ |
| 747 | \ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 748 | ret = kstrtou32(page, 0, &val); \ |
| 749 | if (ret) \ |
| 750 | goto out; \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 751 | ret = iscsit_ta_##name(tpg, val); \ |
| 752 | if (ret < 0) \ |
| 753 | goto out; \ |
| 754 | \ |
| 755 | iscsit_put_tpg(tpg); \ |
| 756 | return count; \ |
| 757 | out: \ |
| 758 | iscsit_put_tpg(tpg); \ |
| 759 | return ret; \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 760 | } \ |
| 761 | CONFIGFS_ATTR(iscsi_tpg_attrib_, name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 762 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 763 | DEF_TPG_ATTRIB(authentication); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 764 | DEF_TPG_ATTRIB(login_timeout); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 765 | DEF_TPG_ATTRIB(netif_timeout); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 766 | DEF_TPG_ATTRIB(generate_node_acls); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 767 | DEF_TPG_ATTRIB(default_cmdsn_depth); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 768 | DEF_TPG_ATTRIB(cache_dynamic_acls); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 769 | DEF_TPG_ATTRIB(demo_mode_write_protect); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 770 | DEF_TPG_ATTRIB(prod_mode_write_protect); |
Thomas Glanzmann | 4c54b6c | 2013-10-07 23:12:11 +0200 | [diff] [blame] | 771 | DEF_TPG_ATTRIB(demo_mode_discovery); |
Nicholas Bellinger | d1fa7a1 | 2013-11-20 11:57:18 -0800 | [diff] [blame] | 772 | DEF_TPG_ATTRIB(default_erl); |
Sagi Grimberg | 8085176 | 2014-02-19 17:50:20 +0200 | [diff] [blame] | 773 | DEF_TPG_ATTRIB(t10_pi); |
Nicholas Bellinger | 901c04a | 2015-03-29 19:36:16 -0700 | [diff] [blame] | 774 | DEF_TPG_ATTRIB(fabric_prot_type); |
David Disseldorp | a6415cd | 2015-08-01 00:10:12 -0700 | [diff] [blame] | 775 | DEF_TPG_ATTRIB(tpg_enabled_sendtargets); |
Nicholas Bellinger | 138d351 | 2017-07-07 14:45:49 -0700 | [diff] [blame] | 776 | DEF_TPG_ATTRIB(login_keys_workaround); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 777 | |
| 778 | static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 779 | &iscsi_tpg_attrib_attr_authentication, |
| 780 | &iscsi_tpg_attrib_attr_login_timeout, |
| 781 | &iscsi_tpg_attrib_attr_netif_timeout, |
| 782 | &iscsi_tpg_attrib_attr_generate_node_acls, |
| 783 | &iscsi_tpg_attrib_attr_default_cmdsn_depth, |
| 784 | &iscsi_tpg_attrib_attr_cache_dynamic_acls, |
| 785 | &iscsi_tpg_attrib_attr_demo_mode_write_protect, |
| 786 | &iscsi_tpg_attrib_attr_prod_mode_write_protect, |
| 787 | &iscsi_tpg_attrib_attr_demo_mode_discovery, |
| 788 | &iscsi_tpg_attrib_attr_default_erl, |
| 789 | &iscsi_tpg_attrib_attr_t10_pi, |
| 790 | &iscsi_tpg_attrib_attr_fabric_prot_type, |
| 791 | &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets, |
Nicholas Bellinger | 138d351 | 2017-07-07 14:45:49 -0700 | [diff] [blame] | 792 | &iscsi_tpg_attrib_attr_login_keys_workaround, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 793 | NULL, |
| 794 | }; |
| 795 | |
| 796 | /* End items for lio_target_tpg_attrib_cit */ |
| 797 | |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 798 | /* Start items for lio_target_tpg_auth_cit */ |
| 799 | |
| 800 | #define __DEF_TPG_AUTH_STR(prefix, name, flags) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 801 | static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \ |
| 802 | char *page) \ |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 803 | { \ |
| 804 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 805 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 806 | struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ |
| 807 | \ |
| 808 | if (!capable(CAP_SYS_ADMIN)) \ |
| 809 | return -EPERM; \ |
| 810 | \ |
| 811 | return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ |
| 812 | } \ |
| 813 | \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 814 | static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\ |
| 815 | const char *page, size_t count) \ |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 816 | { \ |
| 817 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 818 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 819 | struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ |
| 820 | \ |
| 821 | if (!capable(CAP_SYS_ADMIN)) \ |
| 822 | return -EPERM; \ |
| 823 | \ |
Nicholas Bellinger | 37b32c6 | 2013-07-06 16:48:55 -0700 | [diff] [blame] | 824 | snprintf(auth->name, sizeof(auth->name), "%s", page); \ |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 825 | if (!(strncmp("NULL", auth->name, 4))) \ |
| 826 | auth->naf_flags &= ~flags; \ |
| 827 | else \ |
| 828 | auth->naf_flags |= flags; \ |
| 829 | \ |
| 830 | if ((auth->naf_flags & NAF_USERID_IN_SET) && \ |
| 831 | (auth->naf_flags & NAF_PASSWORD_IN_SET)) \ |
| 832 | auth->authenticate_target = 1; \ |
| 833 | else \ |
| 834 | auth->authenticate_target = 0; \ |
| 835 | \ |
| 836 | return count; \ |
| 837 | } |
| 838 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 839 | #define DEF_TPG_AUTH_STR(name, flags) \ |
| 840 | __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \ |
| 841 | static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \ |
| 842 | char *page) \ |
| 843 | { \ |
| 844 | return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \ |
| 845 | } \ |
| 846 | \ |
| 847 | static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \ |
| 848 | const char *page, size_t count) \ |
| 849 | { \ |
| 850 | return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \ |
| 851 | } \ |
| 852 | \ |
| 853 | CONFIGFS_ATTR(iscsi_tpg_auth_, name); |
| 854 | |
| 855 | |
| 856 | DEF_TPG_AUTH_STR(userid, NAF_USERID_SET); |
| 857 | DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET); |
| 858 | DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); |
| 859 | DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); |
| 860 | |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 861 | #define __DEF_TPG_AUTH_INT(prefix, name) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 862 | static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \ |
| 863 | char *page) \ |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 864 | { \ |
| 865 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 866 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 867 | struct iscsi_node_auth *auth = &tpg->tpg_demo_auth; \ |
| 868 | \ |
| 869 | if (!capable(CAP_SYS_ADMIN)) \ |
| 870 | return -EPERM; \ |
| 871 | \ |
| 872 | return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ |
| 873 | } |
| 874 | |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 875 | #define DEF_TPG_AUTH_INT(name) \ |
| 876 | __DEF_TPG_AUTH_INT(tpg_auth, name) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 877 | static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \ |
| 878 | char *page) \ |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 879 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 880 | return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \ |
| 881 | } \ |
| 882 | CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name); |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 883 | |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 884 | DEF_TPG_AUTH_INT(authenticate_target); |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 885 | |
| 886 | static struct configfs_attribute *lio_target_tpg_auth_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 887 | &iscsi_tpg_auth_attr_userid, |
| 888 | &iscsi_tpg_auth_attr_password, |
| 889 | &iscsi_tpg_auth_attr_authenticate_target, |
| 890 | &iscsi_tpg_auth_attr_userid_mutual, |
| 891 | &iscsi_tpg_auth_attr_password_mutual, |
Nicholas Bellinger | c3e5144 | 2013-06-19 18:48:51 -0700 | [diff] [blame] | 892 | NULL, |
| 893 | }; |
| 894 | |
| 895 | /* End items for lio_target_tpg_auth_cit */ |
| 896 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 897 | /* Start items for lio_target_tpg_param_cit */ |
| 898 | |
| 899 | #define DEF_TPG_PARAM(name) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 900 | static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \ |
| 901 | char *page) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 902 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 903 | struct se_portal_group *se_tpg = param_to_tpg(item); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 904 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 905 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 906 | struct iscsi_param *param; \ |
| 907 | ssize_t rb; \ |
| 908 | \ |
| 909 | if (iscsit_get_tpg(tpg) < 0) \ |
| 910 | return -EINVAL; \ |
| 911 | \ |
| 912 | param = iscsi_find_param_from_key(__stringify(name), \ |
| 913 | tpg->param_list); \ |
| 914 | if (!param) { \ |
| 915 | iscsit_put_tpg(tpg); \ |
| 916 | return -EINVAL; \ |
| 917 | } \ |
| 918 | rb = snprintf(page, PAGE_SIZE, "%s\n", param->value); \ |
| 919 | \ |
| 920 | iscsit_put_tpg(tpg); \ |
| 921 | return rb; \ |
| 922 | } \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 923 | static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \ |
| 924 | const char *page, size_t count) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 925 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 926 | struct se_portal_group *se_tpg = param_to_tpg(item); \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 927 | struct iscsi_portal_group *tpg = container_of(se_tpg, \ |
| 928 | struct iscsi_portal_group, tpg_se_tpg); \ |
| 929 | char *buf; \ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 930 | int ret, len; \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 931 | \ |
| 932 | buf = kzalloc(PAGE_SIZE, GFP_KERNEL); \ |
| 933 | if (!buf) \ |
| 934 | return -ENOMEM; \ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 935 | len = snprintf(buf, PAGE_SIZE, "%s=%s", __stringify(name), page); \ |
| 936 | if (isspace(buf[len-1])) \ |
| 937 | buf[len-1] = '\0'; /* Kill newline */ \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 938 | \ |
| 939 | if (iscsit_get_tpg(tpg) < 0) { \ |
| 940 | kfree(buf); \ |
| 941 | return -EINVAL; \ |
| 942 | } \ |
| 943 | \ |
| 944 | ret = iscsi_change_param_value(buf, tpg->param_list, 1); \ |
| 945 | if (ret < 0) \ |
| 946 | goto out; \ |
| 947 | \ |
| 948 | kfree(buf); \ |
| 949 | iscsit_put_tpg(tpg); \ |
| 950 | return count; \ |
| 951 | out: \ |
| 952 | kfree(buf); \ |
| 953 | iscsit_put_tpg(tpg); \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 954 | return -EINVAL; \ |
| 955 | } \ |
| 956 | CONFIGFS_ATTR(iscsi_tpg_param_, name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 957 | |
| 958 | DEF_TPG_PARAM(AuthMethod); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 959 | DEF_TPG_PARAM(HeaderDigest); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 960 | DEF_TPG_PARAM(DataDigest); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 961 | DEF_TPG_PARAM(MaxConnections); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 962 | DEF_TPG_PARAM(TargetAlias); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 963 | DEF_TPG_PARAM(InitialR2T); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 964 | DEF_TPG_PARAM(ImmediateData); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 965 | DEF_TPG_PARAM(MaxRecvDataSegmentLength); |
Nicholas Bellinger | e004cb2 | 2012-09-29 21:47:16 -0700 | [diff] [blame] | 966 | DEF_TPG_PARAM(MaxXmitDataSegmentLength); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 967 | DEF_TPG_PARAM(MaxBurstLength); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 968 | DEF_TPG_PARAM(FirstBurstLength); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 969 | DEF_TPG_PARAM(DefaultTime2Wait); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 970 | DEF_TPG_PARAM(DefaultTime2Retain); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 971 | DEF_TPG_PARAM(MaxOutstandingR2T); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 972 | DEF_TPG_PARAM(DataPDUInOrder); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 973 | DEF_TPG_PARAM(DataSequenceInOrder); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 974 | DEF_TPG_PARAM(ErrorRecoveryLevel); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 975 | DEF_TPG_PARAM(IFMarker); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 976 | DEF_TPG_PARAM(OFMarker); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 977 | DEF_TPG_PARAM(IFMarkInt); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 978 | DEF_TPG_PARAM(OFMarkInt); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 979 | |
| 980 | static struct configfs_attribute *lio_target_tpg_param_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 981 | &iscsi_tpg_param_attr_AuthMethod, |
| 982 | &iscsi_tpg_param_attr_HeaderDigest, |
| 983 | &iscsi_tpg_param_attr_DataDigest, |
| 984 | &iscsi_tpg_param_attr_MaxConnections, |
| 985 | &iscsi_tpg_param_attr_TargetAlias, |
| 986 | &iscsi_tpg_param_attr_InitialR2T, |
| 987 | &iscsi_tpg_param_attr_ImmediateData, |
| 988 | &iscsi_tpg_param_attr_MaxRecvDataSegmentLength, |
| 989 | &iscsi_tpg_param_attr_MaxXmitDataSegmentLength, |
| 990 | &iscsi_tpg_param_attr_MaxBurstLength, |
| 991 | &iscsi_tpg_param_attr_FirstBurstLength, |
| 992 | &iscsi_tpg_param_attr_DefaultTime2Wait, |
| 993 | &iscsi_tpg_param_attr_DefaultTime2Retain, |
| 994 | &iscsi_tpg_param_attr_MaxOutstandingR2T, |
| 995 | &iscsi_tpg_param_attr_DataPDUInOrder, |
| 996 | &iscsi_tpg_param_attr_DataSequenceInOrder, |
| 997 | &iscsi_tpg_param_attr_ErrorRecoveryLevel, |
| 998 | &iscsi_tpg_param_attr_IFMarker, |
| 999 | &iscsi_tpg_param_attr_OFMarker, |
| 1000 | &iscsi_tpg_param_attr_IFMarkInt, |
| 1001 | &iscsi_tpg_param_attr_OFMarkInt, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1002 | NULL, |
| 1003 | }; |
| 1004 | |
| 1005 | /* End items for lio_target_tpg_param_cit */ |
| 1006 | |
| 1007 | /* Start items for lio_target_tpg_cit */ |
| 1008 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1009 | static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1010 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1011 | struct se_portal_group *se_tpg = to_tpg(item); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1012 | struct iscsi_portal_group *tpg = container_of(se_tpg, |
| 1013 | struct iscsi_portal_group, tpg_se_tpg); |
| 1014 | ssize_t len; |
| 1015 | |
| 1016 | spin_lock(&tpg->tpg_state_lock); |
| 1017 | len = sprintf(page, "%d\n", |
| 1018 | (tpg->tpg_state == TPG_STATE_ACTIVE) ? 1 : 0); |
| 1019 | spin_unlock(&tpg->tpg_state_lock); |
| 1020 | |
| 1021 | return len; |
| 1022 | } |
| 1023 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1024 | static ssize_t lio_target_tpg_enable_store(struct config_item *item, |
| 1025 | const char *page, size_t count) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1026 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1027 | struct se_portal_group *se_tpg = to_tpg(item); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1028 | struct iscsi_portal_group *tpg = container_of(se_tpg, |
| 1029 | struct iscsi_portal_group, tpg_se_tpg); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1030 | u32 op; |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1031 | int ret; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1032 | |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1033 | ret = kstrtou32(page, 0, &op); |
| 1034 | if (ret) |
| 1035 | return ret; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1036 | if ((op != 1) && (op != 0)) { |
| 1037 | pr_err("Illegal value for tpg_enable: %u\n", op); |
| 1038 | return -EINVAL; |
| 1039 | } |
| 1040 | |
| 1041 | ret = iscsit_get_tpg(tpg); |
| 1042 | if (ret < 0) |
| 1043 | return -EINVAL; |
| 1044 | |
| 1045 | if (op) { |
| 1046 | ret = iscsit_tpg_enable_portal_group(tpg); |
| 1047 | if (ret < 0) |
| 1048 | goto out; |
| 1049 | } else { |
| 1050 | /* |
| 1051 | * iscsit_tpg_disable_portal_group() assumes force=1 |
| 1052 | */ |
| 1053 | ret = iscsit_tpg_disable_portal_group(tpg, 1); |
| 1054 | if (ret < 0) |
| 1055 | goto out; |
| 1056 | } |
| 1057 | |
| 1058 | iscsit_put_tpg(tpg); |
| 1059 | return count; |
| 1060 | out: |
| 1061 | iscsit_put_tpg(tpg); |
| 1062 | return -EINVAL; |
| 1063 | } |
| 1064 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1065 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1066 | static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item, |
| 1067 | char *page) |
Nicholas Bellinger | d4ee46f | 2015-03-06 20:40:57 -0800 | [diff] [blame] | 1068 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1069 | return target_show_dynamic_sessions(to_tpg(item), page); |
Nicholas Bellinger | d4ee46f | 2015-03-06 20:40:57 -0800 | [diff] [blame] | 1070 | } |
| 1071 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1072 | CONFIGFS_ATTR(lio_target_tpg_, enable); |
| 1073 | CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions); |
Nicholas Bellinger | d4ee46f | 2015-03-06 20:40:57 -0800 | [diff] [blame] | 1074 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1075 | static struct configfs_attribute *lio_target_tpg_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1076 | &lio_target_tpg_attr_enable, |
| 1077 | &lio_target_tpg_attr_dynamic_sessions, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1078 | NULL, |
| 1079 | }; |
| 1080 | |
| 1081 | /* End items for lio_target_tpg_cit */ |
| 1082 | |
| 1083 | /* Start items for lio_target_tiqn_cit */ |
| 1084 | |
Bart Van Assche | aa090ea | 2018-06-22 14:53:02 -0700 | [diff] [blame] | 1085 | static struct se_portal_group *lio_target_tiqn_addtpg(struct se_wwn *wwn, |
| 1086 | const char *name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1087 | { |
| 1088 | struct iscsi_portal_group *tpg; |
| 1089 | struct iscsi_tiqn *tiqn; |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1090 | char *tpgt_str; |
| 1091 | int ret; |
| 1092 | u16 tpgt; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1093 | |
| 1094 | tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); |
| 1095 | /* |
| 1096 | * Only tpgt_# directory groups can be created below |
| 1097 | * target/iscsi/iqn.superturodiskarry/ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1098 | */ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1099 | tpgt_str = strstr(name, "tpgt_"); |
| 1100 | if (!tpgt_str) { |
| 1101 | pr_err("Unable to locate \"tpgt_#\" directory" |
| 1102 | " group\n"); |
| 1103 | return NULL; |
| 1104 | } |
| 1105 | tpgt_str += 5; /* Skip ahead of "tpgt_" */ |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1106 | ret = kstrtou16(tpgt_str, 0, &tpgt); |
| 1107 | if (ret) |
| 1108 | return NULL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1109 | |
| 1110 | tpg = iscsit_alloc_portal_group(tiqn, tpgt); |
| 1111 | if (!tpg) |
| 1112 | return NULL; |
| 1113 | |
Nicholas Bellinger | bc0c94b | 2015-05-20 21:48:03 -0700 | [diff] [blame] | 1114 | ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1115 | if (ret < 0) |
tangwenji | 12d5a43 | 2017-09-15 16:03:13 +0800 | [diff] [blame] | 1116 | goto free_out; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1117 | |
| 1118 | ret = iscsit_tpg_add_portal_group(tiqn, tpg); |
| 1119 | if (ret != 0) |
| 1120 | goto out; |
| 1121 | |
| 1122 | pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); |
| 1123 | pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated TPG: %s\n", |
| 1124 | name); |
| 1125 | return &tpg->tpg_se_tpg; |
| 1126 | out: |
| 1127 | core_tpg_deregister(&tpg->tpg_se_tpg); |
tangwenji | 12d5a43 | 2017-09-15 16:03:13 +0800 | [diff] [blame] | 1128 | free_out: |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1129 | kfree(tpg); |
| 1130 | return NULL; |
| 1131 | } |
| 1132 | |
Christoph Hellwig | fceb5bc | 2012-09-26 08:00:36 -0400 | [diff] [blame] | 1133 | static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1134 | { |
| 1135 | struct iscsi_portal_group *tpg; |
| 1136 | struct iscsi_tiqn *tiqn; |
| 1137 | |
| 1138 | tpg = container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); |
| 1139 | tiqn = tpg->tpg_tiqn; |
| 1140 | /* |
| 1141 | * iscsit_tpg_del_portal_group() assumes force=1 |
| 1142 | */ |
| 1143 | pr_debug("LIO_Target_ConfigFS: DEREGISTER -> Releasing TPG\n"); |
| 1144 | iscsit_tpg_del_portal_group(tiqn, tpg, 1); |
| 1145 | } |
| 1146 | |
| 1147 | /* End items for lio_target_tiqn_cit */ |
| 1148 | |
| 1149 | /* Start LIO-Target TIQN struct contig_item lio_target_cit */ |
| 1150 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1151 | static ssize_t lio_target_wwn_lio_version_show(struct config_item *item, |
| 1152 | char *page) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1153 | { |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 1154 | return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n"); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1155 | } |
| 1156 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1157 | CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1158 | |
| 1159 | static struct configfs_attribute *lio_target_wwn_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1160 | &lio_target_wwn_attr_lio_version, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1161 | NULL, |
| 1162 | }; |
| 1163 | |
Christoph Hellwig | fceb5bc | 2012-09-26 08:00:36 -0400 | [diff] [blame] | 1164 | static struct se_wwn *lio_target_call_coreaddtiqn( |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1165 | struct target_fabric_configfs *tf, |
| 1166 | struct config_group *group, |
| 1167 | const char *name) |
| 1168 | { |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1169 | struct iscsi_tiqn *tiqn; |
| 1170 | |
| 1171 | tiqn = iscsit_add_tiqn((unsigned char *)name); |
| 1172 | if (IS_ERR(tiqn)) |
Thomas Meyer | e1750ba | 2011-08-01 23:58:18 +0200 | [diff] [blame] | 1173 | return ERR_CAST(tiqn); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1174 | |
Christoph Hellwig | 839559e | 2016-03-29 13:03:35 +0200 | [diff] [blame] | 1175 | pr_debug("LIO_Target_ConfigFS: REGISTER -> %s\n", tiqn->tiqn); |
| 1176 | pr_debug("LIO_Target_ConfigFS: REGISTER -> Allocated Node:" |
| 1177 | " %s\n", name); |
| 1178 | return &tiqn->tiqn_wwn; |
| 1179 | } |
| 1180 | |
| 1181 | static void lio_target_add_wwn_groups(struct se_wwn *wwn) |
| 1182 | { |
| 1183 | struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); |
| 1184 | |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 1185 | config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_instance_group, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1186 | "iscsi_instance", &iscsi_stat_instance_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 1187 | configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_instance_group, |
| 1188 | &tiqn->tiqn_wwn.fabric_stat_group); |
| 1189 | |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 1190 | config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_sess_err_group, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1191 | "iscsi_sess_err", &iscsi_stat_sess_err_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 1192 | configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_sess_err_group, |
| 1193 | &tiqn->tiqn_wwn.fabric_stat_group); |
| 1194 | |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 1195 | config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1196 | "iscsi_tgt_attr", &iscsi_stat_tgt_attr_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 1197 | configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_tgt_attr_group, |
| 1198 | &tiqn->tiqn_wwn.fabric_stat_group); |
| 1199 | |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 1200 | config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_login_stats_group, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1201 | "iscsi_login_stats", &iscsi_stat_login_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 1202 | configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_login_stats_group, |
| 1203 | &tiqn->tiqn_wwn.fabric_stat_group); |
| 1204 | |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 1205 | config_group_init_type_name(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1206 | "iscsi_logout_stats", &iscsi_stat_logout_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 1207 | configfs_add_default_group(&tiqn->tiqn_stat_grps.iscsi_logout_stats_group, |
| 1208 | &tiqn->tiqn_wwn.fabric_stat_group); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1209 | } |
| 1210 | |
Christoph Hellwig | fceb5bc | 2012-09-26 08:00:36 -0400 | [diff] [blame] | 1211 | static void lio_target_call_coredeltiqn( |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1212 | struct se_wwn *wwn) |
| 1213 | { |
| 1214 | struct iscsi_tiqn *tiqn = container_of(wwn, struct iscsi_tiqn, tiqn_wwn); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1215 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1216 | pr_debug("LIO_Target_ConfigFS: DEREGISTER -> %s\n", |
| 1217 | tiqn->tiqn); |
| 1218 | iscsit_del_tiqn(tiqn); |
| 1219 | } |
| 1220 | |
| 1221 | /* End LIO-Target TIQN struct contig_lio_target_cit */ |
| 1222 | |
| 1223 | /* Start lio_target_discovery_auth_cit */ |
| 1224 | |
| 1225 | #define DEF_DISC_AUTH_STR(name, flags) \ |
| 1226 | __DEF_NACL_AUTH_STR(disc, name, flags) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1227 | static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1228 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1229 | return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1230 | page); \ |
| 1231 | } \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1232 | static ssize_t iscsi_disc_##name##_store(struct config_item *item, \ |
| 1233 | const char *page, size_t count) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1234 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1235 | return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1236 | page, count); \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1237 | \ |
| 1238 | } \ |
| 1239 | CONFIGFS_ATTR(iscsi_disc_, name) |
| 1240 | |
| 1241 | DEF_DISC_AUTH_STR(userid, NAF_USERID_SET); |
| 1242 | DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET); |
| 1243 | DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET); |
| 1244 | DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1245 | |
| 1246 | #define DEF_DISC_AUTH_INT(name) \ |
| 1247 | __DEF_NACL_AUTH_INT(disc, name) \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1248 | static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1249 | { \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1250 | return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \ |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1251 | page); \ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1252 | } \ |
| 1253 | CONFIGFS_ATTR_RO(iscsi_disc_, name) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1254 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1255 | DEF_DISC_AUTH_INT(authenticate_target); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1256 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1257 | |
| 1258 | static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item, |
| 1259 | char *page) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1260 | { |
| 1261 | struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth; |
| 1262 | |
| 1263 | return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth); |
| 1264 | } |
| 1265 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1266 | static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item, |
| 1267 | const char *page, size_t count) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1268 | { |
| 1269 | struct iscsi_param *param; |
| 1270 | struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1271 | u32 op; |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1272 | int err; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1273 | |
Jörn Engel | ad7babd | 2013-07-03 11:35:11 -0400 | [diff] [blame] | 1274 | err = kstrtou32(page, 0, &op); |
| 1275 | if (err) |
| 1276 | return -EINVAL; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1277 | if ((op != 1) && (op != 0)) { |
| 1278 | pr_err("Illegal value for enforce_discovery_auth:" |
| 1279 | " %u\n", op); |
| 1280 | return -EINVAL; |
| 1281 | } |
| 1282 | |
| 1283 | if (!discovery_tpg) { |
| 1284 | pr_err("iscsit_global->discovery_tpg is NULL\n"); |
| 1285 | return -EINVAL; |
| 1286 | } |
| 1287 | |
| 1288 | param = iscsi_find_param_from_key(AUTHMETHOD, |
| 1289 | discovery_tpg->param_list); |
| 1290 | if (!param) |
| 1291 | return -EINVAL; |
| 1292 | |
| 1293 | if (op) { |
| 1294 | /* |
| 1295 | * Reset the AuthMethod key to CHAP. |
| 1296 | */ |
| 1297 | if (iscsi_update_param_value(param, CHAP) < 0) |
| 1298 | return -EINVAL; |
| 1299 | |
| 1300 | discovery_tpg->tpg_attrib.authentication = 1; |
| 1301 | iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 1; |
| 1302 | pr_debug("LIO-CORE[0] Successfully enabled" |
| 1303 | " authentication enforcement for iSCSI" |
| 1304 | " Discovery TPG\n"); |
| 1305 | } else { |
| 1306 | /* |
| 1307 | * Reset the AuthMethod key to CHAP,None |
| 1308 | */ |
| 1309 | if (iscsi_update_param_value(param, "CHAP,None") < 0) |
| 1310 | return -EINVAL; |
| 1311 | |
| 1312 | discovery_tpg->tpg_attrib.authentication = 0; |
| 1313 | iscsit_global->discovery_acl.node_auth.enforce_discovery_auth = 0; |
| 1314 | pr_debug("LIO-CORE[0] Successfully disabled" |
| 1315 | " authentication enforcement for iSCSI" |
| 1316 | " Discovery TPG\n"); |
| 1317 | } |
| 1318 | |
| 1319 | return count; |
| 1320 | } |
| 1321 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1322 | CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1323 | |
| 1324 | static struct configfs_attribute *lio_target_discovery_auth_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1325 | &iscsi_disc_attr_userid, |
| 1326 | &iscsi_disc_attr_password, |
| 1327 | &iscsi_disc_attr_authenticate_target, |
| 1328 | &iscsi_disc_attr_userid_mutual, |
| 1329 | &iscsi_disc_attr_password_mutual, |
| 1330 | &iscsi_disc_attr_enforce_discovery_auth, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1331 | NULL, |
| 1332 | }; |
| 1333 | |
| 1334 | /* End lio_target_discovery_auth_cit */ |
| 1335 | |
| 1336 | /* Start functions for target_core_fabric_ops */ |
| 1337 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1338 | static int iscsi_get_cmd_state(struct se_cmd *se_cmd) |
| 1339 | { |
| 1340 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1341 | |
| 1342 | return cmd->i_state; |
| 1343 | } |
| 1344 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1345 | static u32 lio_sess_get_index(struct se_session *se_sess) |
| 1346 | { |
| 1347 | struct iscsi_session *sess = se_sess->fabric_sess_ptr; |
| 1348 | |
| 1349 | return sess->session_index; |
| 1350 | } |
| 1351 | |
| 1352 | static u32 lio_sess_get_initiator_sid( |
| 1353 | struct se_session *se_sess, |
| 1354 | unsigned char *buf, |
| 1355 | u32 size) |
| 1356 | { |
| 1357 | struct iscsi_session *sess = se_sess->fabric_sess_ptr; |
| 1358 | /* |
| 1359 | * iSCSI Initiator Session Identifier from RFC-3720. |
| 1360 | */ |
Andy Shevchenko | 5cdf5a8 | 2015-01-15 13:40:56 +0200 | [diff] [blame] | 1361 | return snprintf(buf, size, "%6phN", sess->isid); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
| 1364 | static int lio_queue_data_in(struct se_cmd *se_cmd) |
| 1365 | { |
| 1366 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
Nicholas Bellinger | a446701 | 2016-10-30 17:30:08 -0700 | [diff] [blame] | 1367 | struct iscsi_conn *conn = cmd->conn; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1368 | |
| 1369 | cmd->i_state = ISTATE_SEND_DATAIN; |
Nicholas Bellinger | a446701 | 2016-10-30 17:30:08 -0700 | [diff] [blame] | 1370 | return conn->conn_transport->iscsit_queue_data_in(conn, cmd); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | static int lio_write_pending(struct se_cmd *se_cmd) |
| 1374 | { |
| 1375 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
Nicholas Bellinger | 3e1c81a | 2013-03-06 22:18:24 -0800 | [diff] [blame] | 1376 | struct iscsi_conn *conn = cmd->conn; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1377 | |
| 1378 | if (!cmd->immediate_data && !cmd->unsolicited_data) |
Nicholas Bellinger | 3e1c81a | 2013-03-06 22:18:24 -0800 | [diff] [blame] | 1379 | return conn->conn_transport->iscsit_get_dataout(conn, cmd, false); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1380 | |
| 1381 | return 0; |
| 1382 | } |
| 1383 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1384 | static int lio_queue_status(struct se_cmd *se_cmd) |
| 1385 | { |
| 1386 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
Nicholas Bellinger | a446701 | 2016-10-30 17:30:08 -0700 | [diff] [blame] | 1387 | struct iscsi_conn *conn = cmd->conn; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1388 | |
| 1389 | cmd->i_state = ISTATE_SEND_STATUS; |
Nicholas Bellinger | 5e8e6b4 | 2013-11-12 17:54:56 -0800 | [diff] [blame] | 1390 | |
| 1391 | if (cmd->se_cmd.scsi_status || cmd->sense_reason) { |
Nicholas Bellinger | a446701 | 2016-10-30 17:30:08 -0700 | [diff] [blame] | 1392 | return iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); |
Nicholas Bellinger | 5e8e6b4 | 2013-11-12 17:54:56 -0800 | [diff] [blame] | 1393 | } |
Nicholas Bellinger | a446701 | 2016-10-30 17:30:08 -0700 | [diff] [blame] | 1394 | return conn->conn_transport->iscsit_queue_status(conn, cmd); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1395 | } |
| 1396 | |
Joern Engel | b79fafa | 2013-07-03 11:22:17 -0400 | [diff] [blame] | 1397 | static void lio_queue_tm_rsp(struct se_cmd *se_cmd) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1398 | { |
| 1399 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1400 | |
| 1401 | cmd->i_state = ISTATE_SEND_TASKMGTRSP; |
| 1402 | iscsit_add_cmd_to_response_queue(cmd, cmd->conn, cmd->i_state); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1403 | } |
| 1404 | |
Nicholas Bellinger | 131e6ab | 2014-03-22 14:55:56 -0700 | [diff] [blame] | 1405 | static void lio_aborted_task(struct se_cmd *se_cmd) |
| 1406 | { |
| 1407 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1408 | |
| 1409 | cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd); |
| 1410 | } |
| 1411 | |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1412 | static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg) |
| 1413 | { |
| 1414 | return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); |
| 1415 | } |
| 1416 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1417 | static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg) |
| 1418 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1419 | return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg) |
| 1423 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1424 | return iscsi_tpg(se_tpg)->tpgt; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg) |
| 1428 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1429 | return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg) |
| 1433 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1434 | return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1435 | } |
| 1436 | |
| 1437 | static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg) |
| 1438 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1439 | return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1440 | } |
| 1441 | |
| 1442 | static int lio_tpg_check_demo_mode_write_protect( |
| 1443 | struct se_portal_group *se_tpg) |
| 1444 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1445 | return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1446 | } |
| 1447 | |
| 1448 | static int lio_tpg_check_prod_mode_write_protect( |
| 1449 | struct se_portal_group *se_tpg) |
| 1450 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1451 | return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1452 | } |
| 1453 | |
Nicholas Bellinger | 901c04a | 2015-03-29 19:36:16 -0700 | [diff] [blame] | 1454 | static int lio_tpg_check_prot_fabric_only( |
| 1455 | struct se_portal_group *se_tpg) |
| 1456 | { |
Nicholas Bellinger | 901c04a | 2015-03-29 19:36:16 -0700 | [diff] [blame] | 1457 | /* |
| 1458 | * Only report fabric_prot_type if t10_pi has also been enabled |
| 1459 | * for incoming ib_isert sessions. |
| 1460 | */ |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1461 | if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi) |
Nicholas Bellinger | 901c04a | 2015-03-29 19:36:16 -0700 | [diff] [blame] | 1462 | return 0; |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1463 | return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type; |
Nicholas Bellinger | 901c04a | 2015-03-29 19:36:16 -0700 | [diff] [blame] | 1464 | } |
| 1465 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1466 | /* |
Nicholas Bellinger | d36ad77 | 2016-01-07 22:15:06 -0800 | [diff] [blame] | 1467 | * This function calls iscsit_inc_session_usage_count() on the |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1468 | * struct iscsi_session in question. |
| 1469 | */ |
Christoph Hellwig | 44f33d0 | 2016-05-02 15:45:24 +0200 | [diff] [blame] | 1470 | static void lio_tpg_close_session(struct se_session *se_sess) |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1471 | { |
| 1472 | struct iscsi_session *sess = se_sess->fabric_sess_ptr; |
Nicholas Bellinger | d36ad77 | 2016-01-07 22:15:06 -0800 | [diff] [blame] | 1473 | struct se_portal_group *se_tpg = &sess->tpg->tpg_se_tpg; |
Nicholas Bellinger | 26a99c1 | 2016-01-19 16:15:27 -0800 | [diff] [blame] | 1474 | |
Nicholas Bellinger | d36ad77 | 2016-01-07 22:15:06 -0800 | [diff] [blame] | 1475 | spin_lock_bh(&se_tpg->session_lock); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1476 | spin_lock(&sess->conn_lock); |
| 1477 | if (atomic_read(&sess->session_fall_back_to_erl0) || |
| 1478 | atomic_read(&sess->session_logout) || |
| 1479 | (sess->time2retain_timer_flags & ISCSI_TF_EXPIRED)) { |
| 1480 | spin_unlock(&sess->conn_lock); |
Nicholas Bellinger | d36ad77 | 2016-01-07 22:15:06 -0800 | [diff] [blame] | 1481 | spin_unlock_bh(&se_tpg->session_lock); |
Christoph Hellwig | 44f33d0 | 2016-05-02 15:45:24 +0200 | [diff] [blame] | 1482 | return; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1483 | } |
| 1484 | atomic_set(&sess->session_reinstatement, 1); |
Nicholas Bellinger | 197b806 | 2017-04-25 10:55:12 -0700 | [diff] [blame] | 1485 | atomic_set(&sess->session_fall_back_to_erl0, 1); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1486 | spin_unlock(&sess->conn_lock); |
| 1487 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1488 | iscsit_stop_time2retain_timer(sess); |
Nicholas Bellinger | d36ad77 | 2016-01-07 22:15:06 -0800 | [diff] [blame] | 1489 | spin_unlock_bh(&se_tpg->session_lock); |
Nicholas Bellinger | 26a99c1 | 2016-01-19 16:15:27 -0800 | [diff] [blame] | 1490 | |
Nicholas Bellinger | 99367f0 | 2012-02-27 01:43:32 -0800 | [diff] [blame] | 1491 | iscsit_stop_session(sess, 1, 1); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1492 | iscsit_close_session(sess); |
| 1493 | } |
| 1494 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1495 | static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg) |
| 1496 | { |
Christoph Hellwig | 2b6eb60 | 2015-05-01 17:47:53 +0200 | [diff] [blame] | 1497 | return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index; |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
| 1500 | static void lio_set_default_node_attributes(struct se_node_acl *se_acl) |
| 1501 | { |
| 1502 | struct iscsi_node_acl *acl = container_of(se_acl, struct iscsi_node_acl, |
| 1503 | se_node_acl); |
Nicholas Bellinger | d1fa7a1 | 2013-11-20 11:57:18 -0800 | [diff] [blame] | 1504 | struct se_portal_group *se_tpg = se_acl->se_tpg; |
| 1505 | struct iscsi_portal_group *tpg = container_of(se_tpg, |
| 1506 | struct iscsi_portal_group, tpg_se_tpg); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1507 | |
Andy Grover | b7eec2c | 2013-10-09 11:05:57 -0700 | [diff] [blame] | 1508 | acl->node_attrib.nacl = acl; |
Nicholas Bellinger | d1fa7a1 | 2013-11-20 11:57:18 -0800 | [diff] [blame] | 1509 | iscsit_set_default_node_attribues(acl, tpg); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
Nicholas Bellinger | 3e1c81a | 2013-03-06 22:18:24 -0800 | [diff] [blame] | 1512 | static int lio_check_stop_free(struct se_cmd *se_cmd) |
| 1513 | { |
Bart Van Assche | afc1660 | 2015-04-27 13:52:36 +0200 | [diff] [blame] | 1514 | return target_put_sess_cmd(se_cmd); |
Nicholas Bellinger | 3e1c81a | 2013-03-06 22:18:24 -0800 | [diff] [blame] | 1515 | } |
| 1516 | |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1517 | static void lio_release_cmd(struct se_cmd *se_cmd) |
| 1518 | { |
| 1519 | struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); |
| 1520 | |
Nicholas Bellinger | cdb7266 | 2013-03-06 22:09:17 -0800 | [diff] [blame] | 1521 | pr_debug("Entering lio_release_cmd for se_cmd: %p\n", se_cmd); |
Nicholas Bellinger | d703ce2 | 2013-08-17 14:27:56 -0700 | [diff] [blame] | 1522 | iscsit_release_cmd(cmd); |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1525 | const struct target_core_fabric_ops iscsi_ops = { |
| 1526 | .module = THIS_MODULE, |
David Disseldorp | 59a206b | 2018-11-23 18:36:13 +0100 | [diff] [blame] | 1527 | .fabric_alias = "iscsi", |
David Disseldorp | 30c7ca9 | 2018-11-23 18:36:12 +0100 | [diff] [blame] | 1528 | .fabric_name = "iSCSI", |
Christoph Hellwig | 144bc4c | 2015-04-13 19:51:16 +0200 | [diff] [blame] | 1529 | .node_acl_size = sizeof(struct iscsi_node_acl), |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1530 | .tpg_get_wwn = lio_tpg_get_endpoint_wwn, |
| 1531 | .tpg_get_tag = lio_tpg_get_tag, |
| 1532 | .tpg_get_default_depth = lio_tpg_get_default_depth, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1533 | .tpg_check_demo_mode = lio_tpg_check_demo_mode, |
| 1534 | .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache, |
| 1535 | .tpg_check_demo_mode_write_protect = |
| 1536 | lio_tpg_check_demo_mode_write_protect, |
| 1537 | .tpg_check_prod_mode_write_protect = |
| 1538 | lio_tpg_check_prod_mode_write_protect, |
| 1539 | .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1540 | .tpg_get_inst_index = lio_tpg_get_inst_index, |
| 1541 | .check_stop_free = lio_check_stop_free, |
| 1542 | .release_cmd = lio_release_cmd, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1543 | .close_session = lio_tpg_close_session, |
| 1544 | .sess_get_index = lio_sess_get_index, |
| 1545 | .sess_get_initiator_sid = lio_sess_get_initiator_sid, |
| 1546 | .write_pending = lio_write_pending, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1547 | .set_default_node_attributes = lio_set_default_node_attributes, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1548 | .get_cmd_state = iscsi_get_cmd_state, |
| 1549 | .queue_data_in = lio_queue_data_in, |
| 1550 | .queue_status = lio_queue_status, |
| 1551 | .queue_tm_rsp = lio_queue_tm_rsp, |
| 1552 | .aborted_task = lio_aborted_task, |
| 1553 | .fabric_make_wwn = lio_target_call_coreaddtiqn, |
| 1554 | .fabric_drop_wwn = lio_target_call_coredeltiqn, |
Christoph Hellwig | 839559e | 2016-03-29 13:03:35 +0200 | [diff] [blame] | 1555 | .add_wwn_groups = lio_target_add_wwn_groups, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1556 | .fabric_make_tpg = lio_target_tiqn_addtpg, |
| 1557 | .fabric_drop_tpg = lio_target_tiqn_deltpg, |
| 1558 | .fabric_make_np = lio_target_call_addnptotpg, |
| 1559 | .fabric_drop_np = lio_target_call_delnpfromtpg, |
Christoph Hellwig | c7d6a80 | 2015-04-13 19:51:14 +0200 | [diff] [blame] | 1560 | .fabric_init_nodeacl = lio_target_init_nodeacl, |
Nicholas Bellinger | e48354c | 2011-07-23 06:43:04 +0000 | [diff] [blame] | 1561 | |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1562 | .tfc_discovery_attrs = lio_target_discovery_auth_attrs, |
| 1563 | .tfc_wwn_attrs = lio_target_wwn_attrs, |
| 1564 | .tfc_tpg_base_attrs = lio_target_tpg_attrs, |
| 1565 | .tfc_tpg_attrib_attrs = lio_target_tpg_attrib_attrs, |
| 1566 | .tfc_tpg_auth_attrs = lio_target_tpg_auth_attrs, |
| 1567 | .tfc_tpg_param_attrs = lio_target_tpg_param_attrs, |
| 1568 | .tfc_tpg_np_base_attrs = lio_target_portal_attrs, |
| 1569 | .tfc_tpg_nacl_base_attrs = lio_target_initiator_attrs, |
| 1570 | .tfc_tpg_nacl_attrib_attrs = lio_target_nacl_attrib_attrs, |
| 1571 | .tfc_tpg_nacl_auth_attrs = lio_target_nacl_auth_attrs, |
| 1572 | .tfc_tpg_nacl_param_attrs = lio_target_nacl_param_attrs, |
Bart Van Assche | fbbd492 | 2018-11-27 15:52:01 -0800 | [diff] [blame] | 1573 | |
| 1574 | .write_pending_must_be_called = true, |
Christoph Hellwig | 9ac8928 | 2015-04-08 20:01:35 +0200 | [diff] [blame] | 1575 | }; |