Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * iSCSI transport class definitions |
| 3 | * |
| 4 | * Copyright (C) IBM Corporation, 2004 |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 5 | * Copyright (C) Mike Christie, 2004 - 2005 |
| 6 | * Copyright (C) Dmitry Yusupov, 2004 - 2005 |
| 7 | * Copyright (C) Alex Aizman, 2004 - 2005 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | */ |
| 23 | #include <linux/module.h> |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 24 | #include <linux/mutex.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame^] | 26 | #include <linux/bsg-lib.h> |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 27 | #include <net/tcp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <scsi/scsi.h> |
| 29 | #include <scsi/scsi_host.h> |
| 30 | #include <scsi/scsi_device.h> |
| 31 | #include <scsi/scsi_transport.h> |
| 32 | #include <scsi/scsi_transport_iscsi.h> |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 33 | #include <scsi/iscsi_if.h> |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 34 | #include <scsi/scsi_cmnd.h> |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame^] | 35 | #include <scsi/scsi_bsg_iscsi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Mike Christie | 4c2133c | 2008-06-16 10:11:34 -0500 | [diff] [blame] | 37 | #define ISCSI_TRANSPORT_VERSION "2.0-870" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 39 | static int dbg_session; |
| 40 | module_param_named(debug_session, dbg_session, int, |
| 41 | S_IRUGO | S_IWUSR); |
| 42 | MODULE_PARM_DESC(debug_session, |
| 43 | "Turn on debugging for sessions in scsi_transport_iscsi " |
| 44 | "module. Set to 1 to turn on, and zero to turn off. Default " |
| 45 | "is off."); |
| 46 | |
| 47 | static int dbg_conn; |
| 48 | module_param_named(debug_conn, dbg_conn, int, |
| 49 | S_IRUGO | S_IWUSR); |
| 50 | MODULE_PARM_DESC(debug_conn, |
| 51 | "Turn on debugging for connections in scsi_transport_iscsi " |
| 52 | "module. Set to 1 to turn on, and zero to turn off. Default " |
| 53 | "is off."); |
| 54 | |
| 55 | #define ISCSI_DBG_TRANS_SESSION(_session, dbg_fmt, arg...) \ |
| 56 | do { \ |
| 57 | if (dbg_session) \ |
| 58 | iscsi_cls_session_printk(KERN_INFO, _session, \ |
| 59 | "%s: " dbg_fmt, \ |
| 60 | __func__, ##arg); \ |
| 61 | } while (0); |
| 62 | |
| 63 | #define ISCSI_DBG_TRANS_CONN(_conn, dbg_fmt, arg...) \ |
| 64 | do { \ |
| 65 | if (dbg_conn) \ |
| 66 | iscsi_cls_conn_printk(KERN_INFO, _conn, \ |
| 67 | "%s: " dbg_fmt, \ |
| 68 | __func__, ##arg); \ |
| 69 | } while (0); |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | struct iscsi_internal { |
| 72 | struct scsi_transport_template t; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 73 | struct iscsi_transport *iscsi_transport; |
| 74 | struct list_head list; |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 75 | struct device dev; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 76 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 77 | struct transport_container conn_cont; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 78 | struct transport_container session_cont; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Mike Christie | 41be144 | 2007-02-28 17:32:18 -0600 | [diff] [blame] | 81 | static atomic_t iscsi_session_nr; /* sysfs session id for next new session */ |
Mike Christie | d8bf541 | 2007-12-13 12:43:27 -0600 | [diff] [blame] | 82 | static struct workqueue_struct *iscsi_eh_timer_workq; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 83 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 84 | /* |
| 85 | * list of registered transports and lock that must |
| 86 | * be held while accessing list. The iscsi_transport_lock must |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 87 | * be acquired after the rx_queue_mutex. |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 88 | */ |
| 89 | static LIST_HEAD(iscsi_transports); |
| 90 | static DEFINE_SPINLOCK(iscsi_transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 92 | #define to_iscsi_internal(tmpl) \ |
| 93 | container_of(tmpl, struct iscsi_internal, t) |
| 94 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 95 | #define dev_to_iscsi_internal(_dev) \ |
| 96 | container_of(_dev, struct iscsi_internal, dev) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 97 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 98 | static void iscsi_transport_release(struct device *dev) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 99 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 100 | struct iscsi_internal *priv = dev_to_iscsi_internal(dev); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 101 | kfree(priv); |
| 102 | } |
| 103 | |
| 104 | /* |
| 105 | * iscsi_transport_class represents the iscsi_transports that are |
| 106 | * registered. |
| 107 | */ |
| 108 | static struct class iscsi_transport_class = { |
| 109 | .name = "iscsi_transport", |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 110 | .dev_release = iscsi_transport_release, |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 114 | show_transport_handle(struct device *dev, struct device_attribute *attr, |
| 115 | char *buf) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 116 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 117 | struct iscsi_internal *priv = dev_to_iscsi_internal(dev); |
Mike Christie | 762e2bf | 2005-09-12 21:01:46 -0500 | [diff] [blame] | 118 | return sprintf(buf, "%llu\n", (unsigned long long)iscsi_handle(priv->iscsi_transport)); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 119 | } |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 120 | static DEVICE_ATTR(handle, S_IRUGO, show_transport_handle, NULL); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 121 | |
| 122 | #define show_transport_attr(name, format) \ |
| 123 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 124 | show_transport_##name(struct device *dev, \ |
| 125 | struct device_attribute *attr,char *buf) \ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 126 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 127 | struct iscsi_internal *priv = dev_to_iscsi_internal(dev); \ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 128 | return sprintf(buf, format"\n", priv->iscsi_transport->name); \ |
| 129 | } \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 130 | static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 131 | |
| 132 | show_transport_attr(caps, "0x%x"); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 133 | |
| 134 | static struct attribute *iscsi_transport_attrs[] = { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 135 | &dev_attr_handle.attr, |
| 136 | &dev_attr_caps.attr, |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 137 | NULL, |
| 138 | }; |
| 139 | |
| 140 | static struct attribute_group iscsi_transport_group = { |
| 141 | .attrs = iscsi_transport_attrs, |
| 142 | }; |
| 143 | |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 144 | /* |
| 145 | * iSCSI endpoint attrs |
| 146 | */ |
| 147 | #define iscsi_dev_to_endpoint(_dev) \ |
| 148 | container_of(_dev, struct iscsi_endpoint, dev) |
| 149 | |
| 150 | #define ISCSI_ATTR(_prefix,_name,_mode,_show,_store) \ |
| 151 | struct device_attribute dev_attr_##_prefix##_##_name = \ |
| 152 | __ATTR(_name,_mode,_show,_store) |
| 153 | |
| 154 | static void iscsi_endpoint_release(struct device *dev) |
| 155 | { |
| 156 | struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev); |
| 157 | kfree(ep); |
| 158 | } |
| 159 | |
| 160 | static struct class iscsi_endpoint_class = { |
| 161 | .name = "iscsi_endpoint", |
| 162 | .dev_release = iscsi_endpoint_release, |
| 163 | }; |
| 164 | |
| 165 | static ssize_t |
| 166 | show_ep_handle(struct device *dev, struct device_attribute *attr, char *buf) |
| 167 | { |
| 168 | struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev); |
Mike Christie | 2153606 | 2008-09-24 11:46:11 -0500 | [diff] [blame] | 169 | return sprintf(buf, "%llu\n", (unsigned long long) ep->id); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 170 | } |
| 171 | static ISCSI_ATTR(ep, handle, S_IRUGO, show_ep_handle, NULL); |
| 172 | |
| 173 | static struct attribute *iscsi_endpoint_attrs[] = { |
| 174 | &dev_attr_ep_handle.attr, |
| 175 | NULL, |
| 176 | }; |
| 177 | |
| 178 | static struct attribute_group iscsi_endpoint_group = { |
| 179 | .attrs = iscsi_endpoint_attrs, |
| 180 | }; |
| 181 | |
| 182 | #define ISCSI_MAX_EPID -1 |
| 183 | |
| 184 | static int iscsi_match_epid(struct device *dev, void *data) |
| 185 | { |
| 186 | struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev); |
Mike Christie | 2153606 | 2008-09-24 11:46:11 -0500 | [diff] [blame] | 187 | uint64_t *epid = (uint64_t *) data; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 188 | |
| 189 | return *epid == ep->id; |
| 190 | } |
| 191 | |
| 192 | struct iscsi_endpoint * |
| 193 | iscsi_create_endpoint(int dd_size) |
| 194 | { |
| 195 | struct device *dev; |
| 196 | struct iscsi_endpoint *ep; |
Mike Christie | 2153606 | 2008-09-24 11:46:11 -0500 | [diff] [blame] | 197 | uint64_t id; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 198 | int err; |
| 199 | |
| 200 | for (id = 1; id < ISCSI_MAX_EPID; id++) { |
Greg Kroah-Hartman | 695794a | 2008-05-22 17:21:08 -0400 | [diff] [blame] | 201 | dev = class_find_device(&iscsi_endpoint_class, NULL, &id, |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 202 | iscsi_match_epid); |
| 203 | if (!dev) |
| 204 | break; |
| 205 | } |
| 206 | if (id == ISCSI_MAX_EPID) { |
| 207 | printk(KERN_ERR "Too many connections. Max supported %u\n", |
| 208 | ISCSI_MAX_EPID - 1); |
| 209 | return NULL; |
| 210 | } |
| 211 | |
| 212 | ep = kzalloc(sizeof(*ep) + dd_size, GFP_KERNEL); |
| 213 | if (!ep) |
| 214 | return NULL; |
| 215 | |
| 216 | ep->id = id; |
| 217 | ep->dev.class = &iscsi_endpoint_class; |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 218 | dev_set_name(&ep->dev, "ep-%llu", (unsigned long long) id); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 219 | err = device_register(&ep->dev); |
| 220 | if (err) |
| 221 | goto free_ep; |
| 222 | |
| 223 | err = sysfs_create_group(&ep->dev.kobj, &iscsi_endpoint_group); |
| 224 | if (err) |
| 225 | goto unregister_dev; |
| 226 | |
| 227 | if (dd_size) |
| 228 | ep->dd_data = &ep[1]; |
| 229 | return ep; |
| 230 | |
| 231 | unregister_dev: |
| 232 | device_unregister(&ep->dev); |
| 233 | return NULL; |
| 234 | |
| 235 | free_ep: |
| 236 | kfree(ep); |
| 237 | return NULL; |
| 238 | } |
| 239 | EXPORT_SYMBOL_GPL(iscsi_create_endpoint); |
| 240 | |
| 241 | void iscsi_destroy_endpoint(struct iscsi_endpoint *ep) |
| 242 | { |
| 243 | sysfs_remove_group(&ep->dev.kobj, &iscsi_endpoint_group); |
| 244 | device_unregister(&ep->dev); |
| 245 | } |
| 246 | EXPORT_SYMBOL_GPL(iscsi_destroy_endpoint); |
| 247 | |
| 248 | struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle) |
| 249 | { |
Mike Christie | f80f868 | 2008-06-16 10:11:35 -0500 | [diff] [blame] | 250 | struct iscsi_endpoint *ep; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 251 | struct device *dev; |
| 252 | |
Greg Kroah-Hartman | 695794a | 2008-05-22 17:21:08 -0400 | [diff] [blame] | 253 | dev = class_find_device(&iscsi_endpoint_class, NULL, &handle, |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 254 | iscsi_match_epid); |
| 255 | if (!dev) |
| 256 | return NULL; |
| 257 | |
Mike Christie | f80f868 | 2008-06-16 10:11:35 -0500 | [diff] [blame] | 258 | ep = iscsi_dev_to_endpoint(dev); |
| 259 | /* |
| 260 | * we can drop this now because the interface will prevent |
| 261 | * removals and lookups from racing. |
| 262 | */ |
| 263 | put_device(dev); |
| 264 | return ep; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 265 | } |
| 266 | EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint); |
| 267 | |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 268 | /* |
| 269 | * Interface to display network param to sysfs |
| 270 | */ |
| 271 | |
| 272 | static void iscsi_iface_release(struct device *dev) |
| 273 | { |
| 274 | struct iscsi_iface *iface = iscsi_dev_to_iface(dev); |
| 275 | struct device *parent = iface->dev.parent; |
| 276 | |
| 277 | kfree(iface); |
| 278 | put_device(parent); |
| 279 | } |
| 280 | |
| 281 | |
| 282 | static struct class iscsi_iface_class = { |
| 283 | .name = "iscsi_iface", |
| 284 | .dev_release = iscsi_iface_release, |
| 285 | }; |
| 286 | |
| 287 | #define ISCSI_IFACE_ATTR(_prefix, _name, _mode, _show, _store) \ |
| 288 | struct device_attribute dev_attr_##_prefix##_##_name = \ |
| 289 | __ATTR(_name, _mode, _show, _store) |
| 290 | |
| 291 | /* iface attrs show */ |
| 292 | #define iscsi_iface_attr_show(type, name, param_type, param) \ |
| 293 | static ssize_t \ |
| 294 | show_##type##_##name(struct device *dev, struct device_attribute *attr, \ |
| 295 | char *buf) \ |
| 296 | { \ |
| 297 | struct iscsi_iface *iface = iscsi_dev_to_iface(dev); \ |
| 298 | struct iscsi_transport *t = iface->transport; \ |
| 299 | return t->get_iface_param(iface, param_type, param, buf); \ |
| 300 | } \ |
| 301 | |
| 302 | #define iscsi_iface_net_attr(type, name, param) \ |
| 303 | iscsi_iface_attr_show(type, name, ISCSI_NET_PARAM, param) \ |
| 304 | static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL); |
| 305 | |
| 306 | /* generic read only ipvi4 attribute */ |
| 307 | iscsi_iface_net_attr(ipv4_iface, ipaddress, ISCSI_NET_PARAM_IPV4_ADDR); |
| 308 | iscsi_iface_net_attr(ipv4_iface, gateway, ISCSI_NET_PARAM_IPV4_GW); |
| 309 | iscsi_iface_net_attr(ipv4_iface, subnet, ISCSI_NET_PARAM_IPV4_SUBNET); |
| 310 | iscsi_iface_net_attr(ipv4_iface, bootproto, ISCSI_NET_PARAM_IPV4_BOOTPROTO); |
| 311 | |
| 312 | /* generic read only ipv6 attribute */ |
| 313 | iscsi_iface_net_attr(ipv6_iface, ipaddress, ISCSI_NET_PARAM_IPV6_ADDR); |
| 314 | iscsi_iface_net_attr(ipv6_iface, link_local_addr, ISCSI_NET_PARAM_IPV6_LINKLOCAL); |
| 315 | iscsi_iface_net_attr(ipv6_iface, router_addr, ISCSI_NET_PARAM_IPV6_ROUTER); |
| 316 | iscsi_iface_net_attr(ipv6_iface, ipaddr_autocfg, |
| 317 | ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG); |
| 318 | iscsi_iface_net_attr(ipv6_iface, linklocal_autocfg, |
| 319 | ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG); |
| 320 | |
| 321 | /* common read only iface attribute */ |
| 322 | iscsi_iface_net_attr(iface, enabled, ISCSI_NET_PARAM_IFACE_ENABLE); |
| 323 | iscsi_iface_net_attr(iface, vlan, ISCSI_NET_PARAM_VLAN_ID); |
Mike Christie | 4223b9e | 2011-07-25 13:48:47 -0500 | [diff] [blame] | 324 | iscsi_iface_net_attr(iface, vlan_priority, ISCSI_NET_PARAM_VLAN_PRIORITY); |
| 325 | iscsi_iface_net_attr(iface, vlan_enabled, ISCSI_NET_PARAM_VLAN_ENABLED); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 326 | |
| 327 | static mode_t iscsi_iface_attr_is_visible(struct kobject *kobj, |
| 328 | struct attribute *attr, int i) |
| 329 | { |
| 330 | struct device *dev = container_of(kobj, struct device, kobj); |
| 331 | struct iscsi_iface *iface = iscsi_dev_to_iface(dev); |
| 332 | struct iscsi_transport *t = iface->transport; |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 333 | int param; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 334 | |
| 335 | if (attr == &dev_attr_iface_enabled.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 336 | param = ISCSI_NET_PARAM_IFACE_ENABLE; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 337 | else if (attr == &dev_attr_iface_vlan.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 338 | param = ISCSI_NET_PARAM_VLAN_ID; |
Mike Christie | 4223b9e | 2011-07-25 13:48:47 -0500 | [diff] [blame] | 339 | else if (attr == &dev_attr_iface_vlan_priority.attr) |
| 340 | param = ISCSI_NET_PARAM_VLAN_PRIORITY; |
| 341 | else if (attr == &dev_attr_iface_vlan_enabled.attr) |
| 342 | param = ISCSI_NET_PARAM_VLAN_ENABLED; |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 343 | else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4) { |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 344 | if (attr == &dev_attr_ipv4_iface_ipaddress.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 345 | param = ISCSI_NET_PARAM_IPV4_ADDR; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 346 | else if (attr == &dev_attr_ipv4_iface_gateway.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 347 | param = ISCSI_NET_PARAM_IPV4_GW; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 348 | else if (attr == &dev_attr_ipv4_iface_subnet.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 349 | param = ISCSI_NET_PARAM_IPV4_SUBNET; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 350 | else if (attr == &dev_attr_ipv4_iface_bootproto.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 351 | param = ISCSI_NET_PARAM_IPV4_BOOTPROTO; |
| 352 | else |
| 353 | return 0; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 354 | } else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6) { |
| 355 | if (attr == &dev_attr_ipv6_iface_ipaddress.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 356 | param = ISCSI_NET_PARAM_IPV6_ADDR; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 357 | else if (attr == &dev_attr_ipv6_iface_link_local_addr.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 358 | param = ISCSI_NET_PARAM_IPV6_LINKLOCAL; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 359 | else if (attr == &dev_attr_ipv6_iface_router_addr.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 360 | param = ISCSI_NET_PARAM_IPV6_ROUTER; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 361 | else if (attr == &dev_attr_ipv6_iface_ipaddr_autocfg.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 362 | param = ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 363 | else if (attr == &dev_attr_ipv6_iface_linklocal_autocfg.attr) |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 364 | param = ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG; |
| 365 | else |
| 366 | return 0; |
| 367 | } else { |
| 368 | WARN_ONCE(1, "Invalid iface attr"); |
| 369 | return 0; |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 370 | } |
| 371 | |
Mike Christie | b78dbba | 2011-07-25 13:48:44 -0500 | [diff] [blame] | 372 | return t->attr_is_visible(ISCSI_NET_PARAM, param); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | static struct attribute *iscsi_iface_attrs[] = { |
| 376 | &dev_attr_iface_enabled.attr, |
| 377 | &dev_attr_iface_vlan.attr, |
Mike Christie | 4223b9e | 2011-07-25 13:48:47 -0500 | [diff] [blame] | 378 | &dev_attr_iface_vlan_priority.attr, |
| 379 | &dev_attr_iface_vlan_enabled.attr, |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 380 | &dev_attr_ipv4_iface_ipaddress.attr, |
| 381 | &dev_attr_ipv4_iface_gateway.attr, |
| 382 | &dev_attr_ipv4_iface_subnet.attr, |
| 383 | &dev_attr_ipv4_iface_bootproto.attr, |
| 384 | &dev_attr_ipv6_iface_ipaddress.attr, |
| 385 | &dev_attr_ipv6_iface_link_local_addr.attr, |
| 386 | &dev_attr_ipv6_iface_router_addr.attr, |
| 387 | &dev_attr_ipv6_iface_ipaddr_autocfg.attr, |
| 388 | &dev_attr_ipv6_iface_linklocal_autocfg.attr, |
| 389 | NULL, |
| 390 | }; |
| 391 | |
| 392 | static struct attribute_group iscsi_iface_group = { |
| 393 | .attrs = iscsi_iface_attrs, |
| 394 | .is_visible = iscsi_iface_attr_is_visible, |
| 395 | }; |
| 396 | |
| 397 | struct iscsi_iface * |
| 398 | iscsi_create_iface(struct Scsi_Host *shost, struct iscsi_transport *transport, |
| 399 | uint32_t iface_type, uint32_t iface_num, int dd_size) |
| 400 | { |
| 401 | struct iscsi_iface *iface; |
| 402 | int err; |
| 403 | |
| 404 | iface = kzalloc(sizeof(*iface) + dd_size, GFP_KERNEL); |
| 405 | if (!iface) |
| 406 | return NULL; |
| 407 | |
| 408 | iface->transport = transport; |
| 409 | iface->iface_type = iface_type; |
| 410 | iface->iface_num = iface_num; |
| 411 | iface->dev.release = iscsi_iface_release; |
| 412 | iface->dev.class = &iscsi_iface_class; |
| 413 | /* parent reference released in iscsi_iface_release */ |
| 414 | iface->dev.parent = get_device(&shost->shost_gendev); |
| 415 | if (iface_type == ISCSI_IFACE_TYPE_IPV4) |
| 416 | dev_set_name(&iface->dev, "ipv4-iface-%u-%u", shost->host_no, |
| 417 | iface_num); |
| 418 | else |
| 419 | dev_set_name(&iface->dev, "ipv6-iface-%u-%u", shost->host_no, |
| 420 | iface_num); |
| 421 | |
| 422 | err = device_register(&iface->dev); |
| 423 | if (err) |
| 424 | goto free_iface; |
| 425 | |
| 426 | err = sysfs_create_group(&iface->dev.kobj, &iscsi_iface_group); |
| 427 | if (err) |
| 428 | goto unreg_iface; |
| 429 | |
| 430 | if (dd_size) |
| 431 | iface->dd_data = &iface[1]; |
| 432 | return iface; |
| 433 | |
| 434 | unreg_iface: |
| 435 | device_unregister(&iface->dev); |
| 436 | return NULL; |
| 437 | |
| 438 | free_iface: |
| 439 | put_device(iface->dev.parent); |
| 440 | kfree(iface); |
| 441 | return NULL; |
| 442 | } |
| 443 | EXPORT_SYMBOL_GPL(iscsi_create_iface); |
| 444 | |
| 445 | void iscsi_destroy_iface(struct iscsi_iface *iface) |
| 446 | { |
| 447 | sysfs_remove_group(&iface->dev.kobj, &iscsi_iface_group); |
| 448 | device_unregister(&iface->dev); |
| 449 | } |
| 450 | EXPORT_SYMBOL_GPL(iscsi_destroy_iface); |
| 451 | |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame^] | 452 | /* |
| 453 | * BSG support |
| 454 | */ |
| 455 | /** |
| 456 | * iscsi_bsg_host_dispatch - Dispatch command to LLD. |
| 457 | * @job: bsg job to be processed |
| 458 | */ |
| 459 | static int iscsi_bsg_host_dispatch(struct bsg_job *job) |
| 460 | { |
| 461 | struct Scsi_Host *shost = iscsi_job_to_shost(job); |
| 462 | struct iscsi_bsg_request *req = job->request; |
| 463 | struct iscsi_bsg_reply *reply = job->reply; |
| 464 | struct iscsi_internal *i = to_iscsi_internal(shost->transportt); |
| 465 | int cmdlen = sizeof(uint32_t); /* start with length of msgcode */ |
| 466 | int ret; |
| 467 | |
| 468 | /* check if we have the msgcode value at least */ |
| 469 | if (job->request_len < sizeof(uint32_t)) { |
| 470 | ret = -ENOMSG; |
| 471 | goto fail_host_msg; |
| 472 | } |
| 473 | |
| 474 | /* Validate the host command */ |
| 475 | switch (req->msgcode) { |
| 476 | case ISCSI_BSG_HST_VENDOR: |
| 477 | cmdlen += sizeof(struct iscsi_bsg_host_vendor); |
| 478 | if ((shost->hostt->vendor_id == 0L) || |
| 479 | (req->rqst_data.h_vendor.vendor_id != |
| 480 | shost->hostt->vendor_id)) { |
| 481 | ret = -ESRCH; |
| 482 | goto fail_host_msg; |
| 483 | } |
| 484 | break; |
| 485 | default: |
| 486 | ret = -EBADR; |
| 487 | goto fail_host_msg; |
| 488 | } |
| 489 | |
| 490 | /* check if we really have all the request data needed */ |
| 491 | if (job->request_len < cmdlen) { |
| 492 | ret = -ENOMSG; |
| 493 | goto fail_host_msg; |
| 494 | } |
| 495 | |
| 496 | ret = i->iscsi_transport->bsg_request(job); |
| 497 | if (!ret) |
| 498 | return 0; |
| 499 | |
| 500 | fail_host_msg: |
| 501 | /* return the errno failure code as the only status */ |
| 502 | BUG_ON(job->reply_len < sizeof(uint32_t)); |
| 503 | reply->reply_payload_rcv_len = 0; |
| 504 | reply->result = ret; |
| 505 | job->reply_len = sizeof(uint32_t); |
| 506 | bsg_job_done(job, ret, 0); |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | /** |
| 511 | * iscsi_bsg_host_add - Create and add the bsg hooks to receive requests |
| 512 | * @shost: shost for iscsi_host |
| 513 | * @cls_host: iscsi_cls_host adding the structures to |
| 514 | */ |
| 515 | static int |
| 516 | iscsi_bsg_host_add(struct Scsi_Host *shost, struct iscsi_cls_host *ihost) |
| 517 | { |
| 518 | struct device *dev = &shost->shost_gendev; |
| 519 | struct iscsi_internal *i = to_iscsi_internal(shost->transportt); |
| 520 | struct request_queue *q; |
| 521 | char bsg_name[20]; |
| 522 | int ret; |
| 523 | |
| 524 | if (!i->iscsi_transport->bsg_request) |
| 525 | return -ENOTSUPP; |
| 526 | |
| 527 | snprintf(bsg_name, sizeof(bsg_name), "iscsi_host%d", shost->host_no); |
| 528 | |
| 529 | q = __scsi_alloc_queue(shost, bsg_request_fn); |
| 530 | if (!q) |
| 531 | return -ENOMEM; |
| 532 | |
| 533 | ret = bsg_setup_queue(dev, q, bsg_name, iscsi_bsg_host_dispatch, 0); |
| 534 | if (ret) { |
| 535 | shost_printk(KERN_ERR, shost, "bsg interface failed to " |
| 536 | "initialize - no request queue\n"); |
| 537 | blk_cleanup_queue(q); |
| 538 | return ret; |
| 539 | } |
| 540 | |
| 541 | ihost->bsg_q = q; |
| 542 | return 0; |
| 543 | } |
| 544 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 545 | static int iscsi_setup_host(struct transport_container *tc, struct device *dev, |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 546 | struct device *cdev) |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 547 | { |
| 548 | struct Scsi_Host *shost = dev_to_shost(dev); |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 549 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 550 | |
| 551 | memset(ihost, 0, sizeof(*ihost)); |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 552 | atomic_set(&ihost->nr_scans, 0); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 553 | mutex_init(&ihost->mutex); |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame^] | 554 | |
| 555 | iscsi_bsg_host_add(shost, ihost); |
| 556 | /* ignore any bsg add error - we just can't do sgio */ |
| 557 | |
| 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | static int iscsi_remove_host(struct transport_container *tc, |
| 562 | struct device *dev, struct device *cdev) |
| 563 | { |
| 564 | struct Scsi_Host *shost = dev_to_shost(dev); |
| 565 | struct iscsi_cls_host *ihost = shost->shost_data; |
| 566 | |
| 567 | if (ihost->bsg_q) { |
| 568 | bsg_remove_queue(ihost->bsg_q); |
| 569 | blk_cleanup_queue(ihost->bsg_q); |
| 570 | } |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 571 | return 0; |
| 572 | } |
| 573 | |
| 574 | static DECLARE_TRANSPORT_CLASS(iscsi_host_class, |
| 575 | "iscsi_host", |
| 576 | iscsi_setup_host, |
Mike Christie | 90eeb01 | 2011-07-25 13:48:50 -0500 | [diff] [blame^] | 577 | iscsi_remove_host, |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 578 | NULL); |
| 579 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 580 | static DECLARE_TRANSPORT_CLASS(iscsi_session_class, |
| 581 | "iscsi_session", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | NULL, |
| 583 | NULL, |
| 584 | NULL); |
| 585 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 586 | static DECLARE_TRANSPORT_CLASS(iscsi_connection_class, |
| 587 | "iscsi_connection", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | NULL, |
| 589 | NULL, |
| 590 | NULL); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 591 | |
| 592 | static struct sock *nls; |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 593 | static DEFINE_MUTEX(rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 594 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 595 | static LIST_HEAD(sesslist); |
| 596 | static DEFINE_SPINLOCK(sesslock); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 597 | static LIST_HEAD(connlist); |
| 598 | static DEFINE_SPINLOCK(connlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 600 | static uint32_t iscsi_conn_get_sid(struct iscsi_cls_conn *conn) |
| 601 | { |
| 602 | struct iscsi_cls_session *sess = iscsi_dev_to_session(conn->dev.parent); |
| 603 | return sess->sid; |
| 604 | } |
| 605 | |
| 606 | /* |
| 607 | * Returns the matching session to a given sid |
| 608 | */ |
| 609 | static struct iscsi_cls_session *iscsi_session_lookup(uint32_t sid) |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 610 | { |
| 611 | unsigned long flags; |
| 612 | struct iscsi_cls_session *sess; |
| 613 | |
| 614 | spin_lock_irqsave(&sesslock, flags); |
| 615 | list_for_each_entry(sess, &sesslist, sess_list) { |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 616 | if (sess->sid == sid) { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 617 | spin_unlock_irqrestore(&sesslock, flags); |
| 618 | return sess; |
| 619 | } |
| 620 | } |
| 621 | spin_unlock_irqrestore(&sesslock, flags); |
| 622 | return NULL; |
| 623 | } |
| 624 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 625 | /* |
| 626 | * Returns the matching connection to a given sid / cid tuple |
| 627 | */ |
| 628 | static struct iscsi_cls_conn *iscsi_conn_lookup(uint32_t sid, uint32_t cid) |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 629 | { |
| 630 | unsigned long flags; |
| 631 | struct iscsi_cls_conn *conn; |
| 632 | |
| 633 | spin_lock_irqsave(&connlock, flags); |
| 634 | list_for_each_entry(conn, &connlist, conn_list) { |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 635 | if ((conn->cid == cid) && (iscsi_conn_get_sid(conn) == sid)) { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 636 | spin_unlock_irqrestore(&connlock, flags); |
| 637 | return conn; |
| 638 | } |
| 639 | } |
| 640 | spin_unlock_irqrestore(&connlock, flags); |
| 641 | return NULL; |
| 642 | } |
| 643 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 644 | /* |
| 645 | * The following functions can be used by LLDs that allocate |
| 646 | * their own scsi_hosts or by software iscsi LLDs |
| 647 | */ |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 648 | static struct { |
| 649 | int value; |
| 650 | char *name; |
| 651 | } iscsi_session_state_names[] = { |
| 652 | { ISCSI_SESSION_LOGGED_IN, "LOGGED_IN" }, |
| 653 | { ISCSI_SESSION_FAILED, "FAILED" }, |
| 654 | { ISCSI_SESSION_FREE, "FREE" }, |
| 655 | }; |
| 656 | |
Adrian Bunk | 3b0f208 | 2008-02-13 23:30:17 +0200 | [diff] [blame] | 657 | static const char *iscsi_session_state_name(int state) |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 658 | { |
| 659 | int i; |
| 660 | char *name = NULL; |
| 661 | |
| 662 | for (i = 0; i < ARRAY_SIZE(iscsi_session_state_names); i++) { |
| 663 | if (iscsi_session_state_names[i].value == state) { |
| 664 | name = iscsi_session_state_names[i].name; |
| 665 | break; |
| 666 | } |
| 667 | } |
| 668 | return name; |
| 669 | } |
| 670 | |
| 671 | int iscsi_session_chkready(struct iscsi_cls_session *session) |
| 672 | { |
| 673 | unsigned long flags; |
| 674 | int err; |
| 675 | |
| 676 | spin_lock_irqsave(&session->lock, flags); |
| 677 | switch (session->state) { |
| 678 | case ISCSI_SESSION_LOGGED_IN: |
| 679 | err = 0; |
| 680 | break; |
| 681 | case ISCSI_SESSION_FAILED: |
Andrew Vasquez | 9a1a69a1 | 2009-04-29 13:12:39 -0500 | [diff] [blame] | 682 | err = DID_IMM_RETRY << 16; |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 683 | break; |
| 684 | case ISCSI_SESSION_FREE: |
Mike Christie | 56d7fcf | 2008-08-19 18:45:26 -0500 | [diff] [blame] | 685 | err = DID_TRANSPORT_FAILFAST << 16; |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 686 | break; |
| 687 | default: |
| 688 | err = DID_NO_CONNECT << 16; |
| 689 | break; |
| 690 | } |
| 691 | spin_unlock_irqrestore(&session->lock, flags); |
| 692 | return err; |
| 693 | } |
| 694 | EXPORT_SYMBOL_GPL(iscsi_session_chkready); |
| 695 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 696 | static void iscsi_session_release(struct device *dev) |
| 697 | { |
| 698 | struct iscsi_cls_session *session = iscsi_dev_to_session(dev); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 699 | struct Scsi_Host *shost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 701 | shost = iscsi_session_to_shost(session); |
| 702 | scsi_host_put(shost); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 703 | ISCSI_DBG_TRANS_SESSION(session, "Completing session release\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 704 | kfree(session); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 705 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 707 | static int iscsi_is_session_dev(const struct device *dev) |
| 708 | { |
| 709 | return dev->release == iscsi_session_release; |
| 710 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | |
Mike Christie | a4804cd | 2008-05-21 15:54:00 -0500 | [diff] [blame] | 712 | static int iscsi_iter_session_fn(struct device *dev, void *data) |
| 713 | { |
| 714 | void (* fn) (struct iscsi_cls_session *) = data; |
| 715 | |
| 716 | if (!iscsi_is_session_dev(dev)) |
| 717 | return 0; |
| 718 | fn(iscsi_dev_to_session(dev)); |
| 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | void iscsi_host_for_each_session(struct Scsi_Host *shost, |
| 723 | void (*fn)(struct iscsi_cls_session *)) |
| 724 | { |
| 725 | device_for_each_child(&shost->shost_gendev, fn, |
| 726 | iscsi_iter_session_fn); |
| 727 | } |
| 728 | EXPORT_SYMBOL_GPL(iscsi_host_for_each_session); |
| 729 | |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 730 | /** |
| 731 | * iscsi_scan_finished - helper to report when running scans are done |
| 732 | * @shost: scsi host |
| 733 | * @time: scan run time |
| 734 | * |
| 735 | * This function can be used by drives like qla4xxx to report to the scsi |
| 736 | * layer when the scans it kicked off at module load time are done. |
| 737 | */ |
| 738 | int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time) |
| 739 | { |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 740 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 741 | /* |
| 742 | * qla4xxx will have kicked off some session unblocks before calling |
| 743 | * scsi_scan_host, so just wait for them to complete. |
| 744 | */ |
| 745 | return !atomic_read(&ihost->nr_scans); |
| 746 | } |
| 747 | EXPORT_SYMBOL_GPL(iscsi_scan_finished); |
| 748 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 749 | struct iscsi_scan_data { |
| 750 | unsigned int channel; |
| 751 | unsigned int id; |
| 752 | unsigned int lun; |
| 753 | }; |
| 754 | |
| 755 | static int iscsi_user_scan_session(struct device *dev, void *data) |
| 756 | { |
| 757 | struct iscsi_scan_data *scan_data = data; |
| 758 | struct iscsi_cls_session *session; |
| 759 | struct Scsi_Host *shost; |
| 760 | struct iscsi_cls_host *ihost; |
| 761 | unsigned long flags; |
| 762 | unsigned int id; |
| 763 | |
| 764 | if (!iscsi_is_session_dev(dev)) |
| 765 | return 0; |
| 766 | |
| 767 | session = iscsi_dev_to_session(dev); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 768 | |
| 769 | ISCSI_DBG_TRANS_SESSION(session, "Scanning session\n"); |
| 770 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 771 | shost = iscsi_session_to_shost(session); |
| 772 | ihost = shost->shost_data; |
| 773 | |
| 774 | mutex_lock(&ihost->mutex); |
| 775 | spin_lock_irqsave(&session->lock, flags); |
| 776 | if (session->state != ISCSI_SESSION_LOGGED_IN) { |
| 777 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 778 | goto user_scan_exit; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 779 | } |
| 780 | id = session->target_id; |
| 781 | spin_unlock_irqrestore(&session->lock, flags); |
| 782 | |
| 783 | if (id != ISCSI_MAX_TARGET) { |
| 784 | if ((scan_data->channel == SCAN_WILD_CARD || |
| 785 | scan_data->channel == 0) && |
| 786 | (scan_data->id == SCAN_WILD_CARD || |
| 787 | scan_data->id == id)) |
| 788 | scsi_scan_target(&session->dev, 0, id, |
| 789 | scan_data->lun, 1); |
| 790 | } |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 791 | |
| 792 | user_scan_exit: |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 793 | mutex_unlock(&ihost->mutex); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 794 | ISCSI_DBG_TRANS_SESSION(session, "Completed session scan\n"); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 795 | return 0; |
| 796 | } |
| 797 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 798 | static int iscsi_user_scan(struct Scsi_Host *shost, uint channel, |
| 799 | uint id, uint lun) |
| 800 | { |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 801 | struct iscsi_scan_data scan_data; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 802 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 803 | scan_data.channel = channel; |
| 804 | scan_data.id = id; |
| 805 | scan_data.lun = lun; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 806 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 807 | return device_for_each_child(&shost->shost_gendev, &scan_data, |
| 808 | iscsi_user_scan_session); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 809 | } |
| 810 | |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 811 | static void iscsi_scan_session(struct work_struct *work) |
| 812 | { |
| 813 | struct iscsi_cls_session *session = |
| 814 | container_of(work, struct iscsi_cls_session, scan_work); |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 815 | struct Scsi_Host *shost = iscsi_session_to_shost(session); |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 816 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 817 | struct iscsi_scan_data scan_data; |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 818 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 819 | scan_data.channel = 0; |
| 820 | scan_data.id = SCAN_WILD_CARD; |
| 821 | scan_data.lun = SCAN_WILD_CARD; |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 822 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 823 | iscsi_user_scan_session(&session->dev, &scan_data); |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 824 | atomic_dec(&ihost->nr_scans); |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 825 | } |
| 826 | |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 827 | /** |
| 828 | * iscsi_block_scsi_eh - block scsi eh until session state has transistioned |
Randy Dunlap | e6d4ef4 | 2010-08-14 13:05:41 -0700 | [diff] [blame] | 829 | * @cmd: scsi cmd passed to scsi eh handler |
Mike Christie | c01be6d | 2010-07-22 16:59:49 +0530 | [diff] [blame] | 830 | * |
| 831 | * If the session is down this function will wait for the recovery |
| 832 | * timer to fire or for the session to be logged back in. If the |
| 833 | * recovery timer fires then FAST_IO_FAIL is returned. The caller |
| 834 | * should pass this error value to the scsi eh. |
| 835 | */ |
| 836 | int iscsi_block_scsi_eh(struct scsi_cmnd *cmd) |
| 837 | { |
| 838 | struct iscsi_cls_session *session = |
| 839 | starget_to_session(scsi_target(cmd->device)); |
| 840 | unsigned long flags; |
| 841 | int ret = 0; |
| 842 | |
| 843 | spin_lock_irqsave(&session->lock, flags); |
| 844 | while (session->state != ISCSI_SESSION_LOGGED_IN) { |
| 845 | if (session->state == ISCSI_SESSION_FREE) { |
| 846 | ret = FAST_IO_FAIL; |
| 847 | break; |
| 848 | } |
| 849 | spin_unlock_irqrestore(&session->lock, flags); |
| 850 | msleep(1000); |
| 851 | spin_lock_irqsave(&session->lock, flags); |
| 852 | } |
| 853 | spin_unlock_irqrestore(&session->lock, flags); |
| 854 | return ret; |
| 855 | } |
| 856 | EXPORT_SYMBOL_GPL(iscsi_block_scsi_eh); |
| 857 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 858 | static void session_recovery_timedout(struct work_struct *work) |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 859 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 860 | struct iscsi_cls_session *session = |
| 861 | container_of(work, struct iscsi_cls_session, |
| 862 | recovery_work.work); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 863 | unsigned long flags; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 864 | |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 865 | iscsi_cls_session_printk(KERN_INFO, session, |
| 866 | "session recovery timed out after %d secs\n", |
| 867 | session->recovery_tmo); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 868 | |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 869 | spin_lock_irqsave(&session->lock, flags); |
| 870 | switch (session->state) { |
| 871 | case ISCSI_SESSION_FAILED: |
| 872 | session->state = ISCSI_SESSION_FREE; |
| 873 | break; |
| 874 | case ISCSI_SESSION_LOGGED_IN: |
| 875 | case ISCSI_SESSION_FREE: |
| 876 | /* we raced with the unblock's flush */ |
| 877 | spin_unlock_irqrestore(&session->lock, flags); |
| 878 | return; |
| 879 | } |
| 880 | spin_unlock_irqrestore(&session->lock, flags); |
| 881 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 882 | if (session->transport->session_recovery_timedout) |
| 883 | session->transport->session_recovery_timedout(session); |
| 884 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 885 | ISCSI_DBG_TRANS_SESSION(session, "Unblocking SCSI target\n"); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 886 | scsi_target_unblock(&session->dev); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 887 | ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking SCSI target\n"); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 888 | } |
| 889 | |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 890 | static void __iscsi_unblock_session(struct work_struct *work) |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 891 | { |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 892 | struct iscsi_cls_session *session = |
| 893 | container_of(work, struct iscsi_cls_session, |
| 894 | unblock_work); |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 895 | struct Scsi_Host *shost = iscsi_session_to_shost(session); |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 896 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 897 | unsigned long flags; |
| 898 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 899 | ISCSI_DBG_TRANS_SESSION(session, "Unblocking session\n"); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 900 | /* |
| 901 | * The recovery and unblock work get run from the same workqueue, |
| 902 | * so try to cancel it if it was going to run after this unblock. |
| 903 | */ |
| 904 | cancel_delayed_work(&session->recovery_work); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 905 | spin_lock_irqsave(&session->lock, flags); |
| 906 | session->state = ISCSI_SESSION_LOGGED_IN; |
| 907 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 908 | /* start IO */ |
| 909 | scsi_target_unblock(&session->dev); |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 910 | /* |
| 911 | * Only do kernel scanning if the driver is properly hooked into |
| 912 | * the async scanning code (drivers like iscsi_tcp do login and |
| 913 | * scanning from userspace). |
| 914 | */ |
| 915 | if (shost->hostt->scan_finished) { |
Mike Christie | 06d25af | 2009-03-05 14:46:02 -0600 | [diff] [blame] | 916 | if (scsi_queue_work(shost, &session->scan_work)) |
Mike Christie | 8aae18a | 2008-01-31 13:36:48 -0600 | [diff] [blame] | 917 | atomic_inc(&ihost->nr_scans); |
| 918 | } |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 919 | ISCSI_DBG_TRANS_SESSION(session, "Completed unblocking session\n"); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 920 | } |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 921 | |
| 922 | /** |
| 923 | * iscsi_unblock_session - set a session as logged in and start IO. |
| 924 | * @session: iscsi session |
| 925 | * |
| 926 | * Mark a session as ready to accept IO. |
| 927 | */ |
| 928 | void iscsi_unblock_session(struct iscsi_cls_session *session) |
| 929 | { |
| 930 | queue_work(iscsi_eh_timer_workq, &session->unblock_work); |
| 931 | /* |
| 932 | * make sure all the events have completed before tell the driver |
| 933 | * it is safe |
| 934 | */ |
| 935 | flush_workqueue(iscsi_eh_timer_workq); |
| 936 | } |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 937 | EXPORT_SYMBOL_GPL(iscsi_unblock_session); |
| 938 | |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 939 | static void __iscsi_block_session(struct work_struct *work) |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 940 | { |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 941 | struct iscsi_cls_session *session = |
| 942 | container_of(work, struct iscsi_cls_session, |
| 943 | block_work); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 944 | unsigned long flags; |
| 945 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 946 | ISCSI_DBG_TRANS_SESSION(session, "Blocking session\n"); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 947 | spin_lock_irqsave(&session->lock, flags); |
| 948 | session->state = ISCSI_SESSION_FAILED; |
| 949 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 950 | scsi_target_block(&session->dev); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 951 | ISCSI_DBG_TRANS_SESSION(session, "Completed SCSI target blocking\n"); |
Mike Christie | fdd46dc | 2009-11-11 16:34:34 -0600 | [diff] [blame] | 952 | if (session->recovery_tmo >= 0) |
| 953 | queue_delayed_work(iscsi_eh_timer_workq, |
| 954 | &session->recovery_work, |
| 955 | session->recovery_tmo * HZ); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 956 | } |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 957 | |
| 958 | void iscsi_block_session(struct iscsi_cls_session *session) |
| 959 | { |
| 960 | queue_work(iscsi_eh_timer_workq, &session->block_work); |
| 961 | } |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 962 | EXPORT_SYMBOL_GPL(iscsi_block_session); |
| 963 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 964 | static void __iscsi_unbind_session(struct work_struct *work) |
| 965 | { |
| 966 | struct iscsi_cls_session *session = |
| 967 | container_of(work, struct iscsi_cls_session, |
| 968 | unbind_work); |
| 969 | struct Scsi_Host *shost = iscsi_session_to_shost(session); |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 970 | struct iscsi_cls_host *ihost = shost->shost_data; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 971 | unsigned long flags; |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 972 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 973 | ISCSI_DBG_TRANS_SESSION(session, "Unbinding session\n"); |
| 974 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 975 | /* Prevent new scans and make sure scanning is not in progress */ |
| 976 | mutex_lock(&ihost->mutex); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 977 | spin_lock_irqsave(&session->lock, flags); |
| 978 | if (session->target_id == ISCSI_MAX_TARGET) { |
| 979 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 980 | mutex_unlock(&ihost->mutex); |
| 981 | return; |
| 982 | } |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 983 | session->target_id = ISCSI_MAX_TARGET; |
| 984 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 985 | mutex_unlock(&ihost->mutex); |
| 986 | |
| 987 | scsi_remove_target(&session->dev); |
| 988 | iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 989 | ISCSI_DBG_TRANS_SESSION(session, "Completed target removal\n"); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 990 | } |
| 991 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 992 | struct iscsi_cls_session * |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 993 | iscsi_alloc_session(struct Scsi_Host *shost, struct iscsi_transport *transport, |
| 994 | int dd_size) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 995 | { |
| 996 | struct iscsi_cls_session *session; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 998 | session = kzalloc(sizeof(*session) + dd_size, |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 999 | GFP_KERNEL); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1000 | if (!session) |
Mike Christie | f53a88d | 2006-06-28 12:00:27 -0500 | [diff] [blame] | 1001 | return NULL; |
| 1002 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1003 | session->transport = transport; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1004 | session->recovery_tmo = 120; |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1005 | session->state = ISCSI_SESSION_FREE; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 1006 | INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1007 | INIT_LIST_HEAD(&session->sess_list); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1008 | INIT_WORK(&session->unblock_work, __iscsi_unblock_session); |
| 1009 | INIT_WORK(&session->block_work, __iscsi_block_session); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1010 | INIT_WORK(&session->unbind_work, __iscsi_unbind_session); |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 1011 | INIT_WORK(&session->scan_work, iscsi_scan_session); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1012 | spin_lock_init(&session->lock); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1013 | |
Mike Christie | 6a8a0d3 | 2006-06-28 12:00:31 -0500 | [diff] [blame] | 1014 | /* this is released in the dev's release function */ |
| 1015 | scsi_host_get(shost); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1016 | session->dev.parent = &shost->shost_gendev; |
| 1017 | session->dev.release = iscsi_session_release; |
| 1018 | device_initialize(&session->dev); |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1019 | if (dd_size) |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1020 | session->dd_data = &session[1]; |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1021 | |
| 1022 | ISCSI_DBG_TRANS_SESSION(session, "Completed session allocation\n"); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1023 | return session; |
| 1024 | } |
| 1025 | EXPORT_SYMBOL_GPL(iscsi_alloc_session); |
| 1026 | |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1027 | static int iscsi_get_next_target_id(struct device *dev, void *data) |
| 1028 | { |
| 1029 | struct iscsi_cls_session *session; |
| 1030 | unsigned long flags; |
| 1031 | int err = 0; |
| 1032 | |
| 1033 | if (!iscsi_is_session_dev(dev)) |
| 1034 | return 0; |
| 1035 | |
| 1036 | session = iscsi_dev_to_session(dev); |
| 1037 | spin_lock_irqsave(&session->lock, flags); |
| 1038 | if (*((unsigned int *) data) == session->target_id) |
| 1039 | err = -EEXIST; |
| 1040 | spin_unlock_irqrestore(&session->lock, flags); |
| 1041 | return err; |
| 1042 | } |
| 1043 | |
Mike Christie | 6a8a0d3 | 2006-06-28 12:00:31 -0500 | [diff] [blame] | 1044 | int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id) |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1045 | { |
| 1046 | struct Scsi_Host *shost = iscsi_session_to_shost(session); |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 1047 | struct iscsi_cls_host *ihost; |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1048 | unsigned long flags; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1049 | unsigned int id = target_id; |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1050 | int err; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1051 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1052 | ihost = shost->shost_data; |
Mike Christie | 41be144 | 2007-02-28 17:32:18 -0600 | [diff] [blame] | 1053 | session->sid = atomic_add_return(1, &iscsi_session_nr); |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1054 | |
| 1055 | if (id == ISCSI_MAX_TARGET) { |
| 1056 | for (id = 0; id < ISCSI_MAX_TARGET; id++) { |
| 1057 | err = device_for_each_child(&shost->shost_gendev, &id, |
| 1058 | iscsi_get_next_target_id); |
| 1059 | if (!err) |
| 1060 | break; |
| 1061 | } |
| 1062 | |
| 1063 | if (id == ISCSI_MAX_TARGET) { |
| 1064 | iscsi_cls_session_printk(KERN_ERR, session, |
| 1065 | "Too many iscsi targets. Max " |
| 1066 | "number of targets is %d.\n", |
| 1067 | ISCSI_MAX_TARGET - 1); |
Jaswinder Singh Rajput | 24add1c | 2009-06-20 13:29:21 +0530 | [diff] [blame] | 1068 | err = -EOVERFLOW; |
Mike Christie | 7970634 | 2008-05-21 15:54:12 -0500 | [diff] [blame] | 1069 | goto release_host; |
| 1070 | } |
| 1071 | } |
| 1072 | session->target_id = id; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1073 | |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 1074 | dev_set_name(&session->dev, "session%u", session->sid); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1075 | err = device_add(&session->dev); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1076 | if (err) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1077 | iscsi_cls_session_printk(KERN_ERR, session, |
| 1078 | "could not register session's dev\n"); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1079 | goto release_host; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1080 | } |
| 1081 | transport_register_device(&session->dev); |
| 1082 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1083 | spin_lock_irqsave(&sesslock, flags); |
| 1084 | list_add(&session->sess_list, &sesslist); |
| 1085 | spin_unlock_irqrestore(&sesslock, flags); |
| 1086 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1087 | iscsi_session_event(session, ISCSI_KEVENT_CREATE_SESSION); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1088 | ISCSI_DBG_TRANS_SESSION(session, "Completed session adding\n"); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1089 | return 0; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1090 | |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1091 | release_host: |
| 1092 | scsi_host_put(shost); |
| 1093 | return err; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1094 | } |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1095 | EXPORT_SYMBOL_GPL(iscsi_add_session); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1096 | |
| 1097 | /** |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1098 | * iscsi_create_session - create iscsi class session |
| 1099 | * @shost: scsi host |
| 1100 | * @transport: iscsi transport |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1101 | * @dd_size: private driver data size |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1102 | * @target_id: which target |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1103 | * |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1104 | * This can be called from a LLD or iscsi_transport. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1105 | */ |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1106 | struct iscsi_cls_session * |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1107 | iscsi_create_session(struct Scsi_Host *shost, struct iscsi_transport *transport, |
| 1108 | int dd_size, unsigned int target_id) |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1109 | { |
| 1110 | struct iscsi_cls_session *session; |
| 1111 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1112 | session = iscsi_alloc_session(shost, transport, dd_size); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1113 | if (!session) |
| 1114 | return NULL; |
| 1115 | |
Mike Christie | 6a8a0d3 | 2006-06-28 12:00:31 -0500 | [diff] [blame] | 1116 | if (iscsi_add_session(session, target_id)) { |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1117 | iscsi_free_session(session); |
| 1118 | return NULL; |
| 1119 | } |
| 1120 | return session; |
| 1121 | } |
| 1122 | EXPORT_SYMBOL_GPL(iscsi_create_session); |
| 1123 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1124 | static void iscsi_conn_release(struct device *dev) |
| 1125 | { |
| 1126 | struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev); |
| 1127 | struct device *parent = conn->dev.parent; |
| 1128 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1129 | ISCSI_DBG_TRANS_CONN(conn, "Releasing conn\n"); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1130 | kfree(conn); |
| 1131 | put_device(parent); |
| 1132 | } |
| 1133 | |
| 1134 | static int iscsi_is_conn_dev(const struct device *dev) |
| 1135 | { |
| 1136 | return dev->release == iscsi_conn_release; |
| 1137 | } |
| 1138 | |
| 1139 | static int iscsi_iter_destroy_conn_fn(struct device *dev, void *data) |
| 1140 | { |
| 1141 | if (!iscsi_is_conn_dev(dev)) |
| 1142 | return 0; |
| 1143 | return iscsi_destroy_conn(iscsi_dev_to_conn(dev)); |
| 1144 | } |
| 1145 | |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1146 | void iscsi_remove_session(struct iscsi_cls_session *session) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1147 | { |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1148 | struct Scsi_Host *shost = iscsi_session_to_shost(session); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1149 | unsigned long flags; |
| 1150 | int err; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1151 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1152 | ISCSI_DBG_TRANS_SESSION(session, "Removing session\n"); |
| 1153 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1154 | spin_lock_irqsave(&sesslock, flags); |
| 1155 | list_del(&session->sess_list); |
| 1156 | spin_unlock_irqrestore(&sesslock, flags); |
| 1157 | |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1158 | /* make sure there are no blocks/unblocks queued */ |
| 1159 | flush_workqueue(iscsi_eh_timer_workq); |
| 1160 | /* make sure the timedout callout is not running */ |
| 1161 | if (!cancel_delayed_work(&session->recovery_work)) |
| 1162 | flush_workqueue(iscsi_eh_timer_workq); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1163 | /* |
| 1164 | * If we are blocked let commands flow again. The lld or iscsi |
| 1165 | * layer should set up the queuecommand to fail commands. |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1166 | * We assume that LLD will not be calling block/unblock while |
| 1167 | * removing the session. |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1168 | */ |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 1169 | spin_lock_irqsave(&session->lock, flags); |
| 1170 | session->state = ISCSI_SESSION_FREE; |
| 1171 | spin_unlock_irqrestore(&session->lock, flags); |
Mike Christie | bd976f6 | 2008-01-31 13:36:46 -0600 | [diff] [blame] | 1172 | |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1173 | scsi_target_unblock(&session->dev); |
| 1174 | /* flush running scans then delete devices */ |
Mike Christie | 06d25af | 2009-03-05 14:46:02 -0600 | [diff] [blame] | 1175 | scsi_flush_work(shost); |
Mike Christie | 45ab33b | 2008-03-04 13:26:55 -0600 | [diff] [blame] | 1176 | __iscsi_unbind_session(&session->unbind_work); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1177 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1178 | /* hw iscsi may not have removed all connections from session */ |
| 1179 | err = device_for_each_child(&session->dev, NULL, |
| 1180 | iscsi_iter_destroy_conn_fn); |
| 1181 | if (err) |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1182 | iscsi_cls_session_printk(KERN_ERR, session, |
| 1183 | "Could not delete all connections " |
| 1184 | "for session. Error %d.\n", err); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1185 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1186 | transport_unregister_device(&session->dev); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1187 | |
| 1188 | ISCSI_DBG_TRANS_SESSION(session, "Completing session removal\n"); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1189 | device_del(&session->dev); |
| 1190 | } |
| 1191 | EXPORT_SYMBOL_GPL(iscsi_remove_session); |
| 1192 | |
| 1193 | void iscsi_free_session(struct iscsi_cls_session *session) |
| 1194 | { |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1195 | ISCSI_DBG_TRANS_SESSION(session, "Freeing session\n"); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1196 | iscsi_session_event(session, ISCSI_KEVENT_DESTROY_SESSION); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1197 | put_device(&session->dev); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1198 | } |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1199 | EXPORT_SYMBOL_GPL(iscsi_free_session); |
| 1200 | |
| 1201 | /** |
| 1202 | * iscsi_destroy_session - destroy iscsi session |
| 1203 | * @session: iscsi_session |
| 1204 | * |
| 1205 | * Can be called by a LLD or iscsi_transport. There must not be |
| 1206 | * any running connections. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1207 | */ |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1208 | int iscsi_destroy_session(struct iscsi_cls_session *session) |
| 1209 | { |
| 1210 | iscsi_remove_session(session); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1211 | ISCSI_DBG_TRANS_SESSION(session, "Completing session destruction\n"); |
Mike Christie | 8434aa8 | 2006-06-28 12:00:30 -0500 | [diff] [blame] | 1212 | iscsi_free_session(session); |
| 1213 | return 0; |
| 1214 | } |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1215 | EXPORT_SYMBOL_GPL(iscsi_destroy_session); |
| 1216 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1217 | /** |
| 1218 | * iscsi_create_conn - create iscsi class connection |
| 1219 | * @session: iscsi cls session |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1220 | * @dd_size: private driver data size |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1221 | * @cid: connection id |
| 1222 | * |
| 1223 | * This can be called from a LLD or iscsi_transport. The connection |
| 1224 | * is child of the session so cid must be unique for all connections |
| 1225 | * on the session. |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1226 | * |
| 1227 | * Since we do not support MCS, cid will normally be zero. In some cases |
| 1228 | * for software iscsi we could be trying to preallocate a connection struct |
| 1229 | * in which case there could be two connection structs and cid would be |
| 1230 | * non-zero. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1231 | */ |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1232 | struct iscsi_cls_conn * |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1233 | iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1234 | { |
| 1235 | struct iscsi_transport *transport = session->transport; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1236 | struct iscsi_cls_conn *conn; |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1237 | unsigned long flags; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1238 | int err; |
| 1239 | |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1240 | conn = kzalloc(sizeof(*conn) + dd_size, GFP_KERNEL); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1241 | if (!conn) |
| 1242 | return NULL; |
Mike Christie | 5d91e20 | 2008-05-21 15:54:01 -0500 | [diff] [blame] | 1243 | if (dd_size) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1244 | conn->dd_data = &conn[1]; |
| 1245 | |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 1246 | mutex_init(&conn->ep_mutex); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1247 | INIT_LIST_HEAD(&conn->conn_list); |
| 1248 | conn->transport = transport; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1249 | conn->cid = cid; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1250 | |
| 1251 | /* this is released in the dev's release function */ |
| 1252 | if (!get_device(&session->dev)) |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 1253 | goto free_conn; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1254 | |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 1255 | dev_set_name(&conn->dev, "connection%d:%u", session->sid, cid); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1256 | conn->dev.parent = &session->dev; |
| 1257 | conn->dev.release = iscsi_conn_release; |
| 1258 | err = device_register(&conn->dev); |
| 1259 | if (err) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1260 | iscsi_cls_session_printk(KERN_ERR, session, "could not " |
| 1261 | "register connection's dev\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1262 | goto release_parent_ref; |
| 1263 | } |
| 1264 | transport_register_device(&conn->dev); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1265 | |
| 1266 | spin_lock_irqsave(&connlock, flags); |
| 1267 | list_add(&conn->conn_list, &connlist); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1268 | spin_unlock_irqrestore(&connlock, flags); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1269 | |
| 1270 | ISCSI_DBG_TRANS_CONN(conn, "Completed conn creation\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1271 | return conn; |
| 1272 | |
| 1273 | release_parent_ref: |
| 1274 | put_device(&session->dev); |
| 1275 | free_conn: |
| 1276 | kfree(conn); |
| 1277 | return NULL; |
| 1278 | } |
| 1279 | |
| 1280 | EXPORT_SYMBOL_GPL(iscsi_create_conn); |
| 1281 | |
| 1282 | /** |
| 1283 | * iscsi_destroy_conn - destroy iscsi class connection |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1284 | * @conn: iscsi cls session |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1285 | * |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1286 | * This can be called from a LLD or iscsi_transport. |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1287 | */ |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1288 | int iscsi_destroy_conn(struct iscsi_cls_conn *conn) |
| 1289 | { |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1290 | unsigned long flags; |
| 1291 | |
| 1292 | spin_lock_irqsave(&connlock, flags); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1293 | list_del(&conn->conn_list); |
| 1294 | spin_unlock_irqrestore(&connlock, flags); |
| 1295 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1296 | transport_unregister_device(&conn->dev); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1297 | ISCSI_DBG_TRANS_CONN(conn, "Completing conn destruction\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1298 | device_unregister(&conn->dev); |
| 1299 | return 0; |
| 1300 | } |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1301 | EXPORT_SYMBOL_GPL(iscsi_destroy_conn); |
| 1302 | |
| 1303 | /* |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1304 | * iscsi interface functions |
| 1305 | */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1306 | static struct iscsi_internal * |
| 1307 | iscsi_if_transport_lookup(struct iscsi_transport *tt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | { |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1309 | struct iscsi_internal *priv; |
| 1310 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1312 | spin_lock_irqsave(&iscsi_transport_lock, flags); |
| 1313 | list_for_each_entry(priv, &iscsi_transports, list) { |
| 1314 | if (tt == priv->iscsi_transport) { |
| 1315 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
| 1316 | return priv; |
| 1317 | } |
| 1318 | } |
| 1319 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
| 1320 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1323 | static int |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1324 | iscsi_multicast_skb(struct sk_buff *skb, uint32_t group, gfp_t gfp) |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1325 | { |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1326 | return nlmsg_multicast(nls, skb, 0, group, gfp); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1329 | int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr, |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1330 | char *data, uint32_t data_size) |
| 1331 | { |
| 1332 | struct nlmsghdr *nlh; |
| 1333 | struct sk_buff *skb; |
| 1334 | struct iscsi_uevent *ev; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1335 | char *pdu; |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 1336 | struct iscsi_internal *priv; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1337 | int len = NLMSG_SPACE(sizeof(*ev) + sizeof(struct iscsi_hdr) + |
| 1338 | data_size); |
| 1339 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 1340 | priv = iscsi_if_transport_lookup(conn->transport); |
| 1341 | if (!priv) |
| 1342 | return -EINVAL; |
| 1343 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 1344 | skb = alloc_skb(len, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1345 | if (!skb) { |
Mike Christie | e5bd7b5 | 2008-09-24 11:46:10 -0500 | [diff] [blame] | 1346 | iscsi_conn_error_event(conn, ISCSI_ERR_CONN_FAILED); |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1347 | iscsi_cls_conn_printk(KERN_ERR, conn, "can not deliver " |
| 1348 | "control PDU: OOM\n"); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1349 | return -ENOMEM; |
| 1350 | } |
| 1351 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1352 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1353 | ev = NLMSG_DATA(nlh); |
| 1354 | memset(ev, 0, sizeof(*ev)); |
| 1355 | ev->transport_handle = iscsi_handle(conn->transport); |
| 1356 | ev->type = ISCSI_KEVENT_RECV_PDU; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1357 | ev->r.recv_req.cid = conn->cid; |
| 1358 | ev->r.recv_req.sid = iscsi_conn_get_sid(conn); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1359 | pdu = (char*)ev + sizeof(*ev); |
| 1360 | memcpy(pdu, hdr, sizeof(struct iscsi_hdr)); |
| 1361 | memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size); |
| 1362 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1363 | return iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1364 | } |
| 1365 | EXPORT_SYMBOL_GPL(iscsi_recv_pdu); |
| 1366 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1367 | int iscsi_offload_mesg(struct Scsi_Host *shost, |
| 1368 | struct iscsi_transport *transport, uint32_t type, |
| 1369 | char *data, uint16_t data_size) |
| 1370 | { |
| 1371 | struct nlmsghdr *nlh; |
| 1372 | struct sk_buff *skb; |
| 1373 | struct iscsi_uevent *ev; |
| 1374 | int len = NLMSG_SPACE(sizeof(*ev) + data_size); |
| 1375 | |
Michael Chan | a541f84 | 2009-07-29 08:49:52 +0000 | [diff] [blame] | 1376 | skb = alloc_skb(len, GFP_ATOMIC); |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1377 | if (!skb) { |
| 1378 | printk(KERN_ERR "can not deliver iscsi offload message:OOM\n"); |
| 1379 | return -ENOMEM; |
| 1380 | } |
| 1381 | |
| 1382 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
| 1383 | ev = NLMSG_DATA(nlh); |
| 1384 | memset(ev, 0, sizeof(*ev)); |
| 1385 | ev->type = type; |
| 1386 | ev->transport_handle = iscsi_handle(transport); |
| 1387 | switch (type) { |
| 1388 | case ISCSI_KEVENT_PATH_REQ: |
| 1389 | ev->r.req_path.host_no = shost->host_no; |
| 1390 | break; |
| 1391 | case ISCSI_KEVENT_IF_DOWN: |
| 1392 | ev->r.notify_if_down.host_no = shost->host_no; |
| 1393 | break; |
| 1394 | } |
| 1395 | |
| 1396 | memcpy((char *)ev + sizeof(*ev), data, data_size); |
| 1397 | |
Michael Chan | a541f84 | 2009-07-29 08:49:52 +0000 | [diff] [blame] | 1398 | return iscsi_multicast_skb(skb, ISCSI_NL_GRP_UIP, GFP_ATOMIC); |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1399 | } |
| 1400 | EXPORT_SYMBOL_GPL(iscsi_offload_mesg); |
| 1401 | |
Mike Christie | e5bd7b5 | 2008-09-24 11:46:10 -0500 | [diff] [blame] | 1402 | void iscsi_conn_error_event(struct iscsi_cls_conn *conn, enum iscsi_err error) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1403 | { |
| 1404 | struct nlmsghdr *nlh; |
| 1405 | struct sk_buff *skb; |
| 1406 | struct iscsi_uevent *ev; |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 1407 | struct iscsi_internal *priv; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1408 | int len = NLMSG_SPACE(sizeof(*ev)); |
| 1409 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 1410 | priv = iscsi_if_transport_lookup(conn->transport); |
| 1411 | if (!priv) |
| 1412 | return; |
| 1413 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 1414 | skb = alloc_skb(len, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1415 | if (!skb) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1416 | iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored " |
| 1417 | "conn error (%d)\n", error); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1418 | return; |
| 1419 | } |
| 1420 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1421 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1422 | ev = NLMSG_DATA(nlh); |
| 1423 | ev->transport_handle = iscsi_handle(conn->transport); |
| 1424 | ev->type = ISCSI_KEVENT_CONN_ERROR; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1425 | ev->r.connerror.error = error; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1426 | ev->r.connerror.cid = conn->cid; |
| 1427 | ev->r.connerror.sid = iscsi_conn_get_sid(conn); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1428 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1429 | iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1430 | |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1431 | iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn error (%d)\n", |
| 1432 | error); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1433 | } |
Mike Christie | e5bd7b5 | 2008-09-24 11:46:10 -0500 | [diff] [blame] | 1434 | EXPORT_SYMBOL_GPL(iscsi_conn_error_event); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1435 | |
| 1436 | static int |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1437 | iscsi_if_send_reply(uint32_t group, int seq, int type, int done, int multi, |
| 1438 | void *payload, int size) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1439 | { |
| 1440 | struct sk_buff *skb; |
| 1441 | struct nlmsghdr *nlh; |
| 1442 | int len = NLMSG_SPACE(size); |
| 1443 | int flags = multi ? NLM_F_MULTI : 0; |
| 1444 | int t = done ? NLMSG_DONE : type; |
| 1445 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 1446 | skb = alloc_skb(len, GFP_ATOMIC); |
Mike Christie | 239a7dc | 2007-05-30 12:57:07 -0500 | [diff] [blame] | 1447 | if (!skb) { |
| 1448 | printk(KERN_ERR "Could not allocate skb to send reply.\n"); |
| 1449 | return -ENOMEM; |
| 1450 | } |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1451 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1452 | nlh = __nlmsg_put(skb, 0, 0, t, (len - sizeof(*nlh)), 0); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1453 | nlh->nlmsg_flags = flags; |
| 1454 | memcpy(NLMSG_DATA(nlh), payload, size); |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1455 | return iscsi_multicast_skb(skb, group, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1456 | } |
| 1457 | |
| 1458 | static int |
Mike Christie | 5b940ad | 2006-02-01 21:06:56 -0600 | [diff] [blame] | 1459 | iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1460 | { |
| 1461 | struct iscsi_uevent *ev = NLMSG_DATA(nlh); |
| 1462 | struct iscsi_stats *stats; |
| 1463 | struct sk_buff *skbstat; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1464 | struct iscsi_cls_conn *conn; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1465 | struct nlmsghdr *nlhstat; |
| 1466 | struct iscsi_uevent *evstat; |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 1467 | struct iscsi_internal *priv; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1468 | int len = NLMSG_SPACE(sizeof(*ev) + |
| 1469 | sizeof(struct iscsi_stats) + |
| 1470 | sizeof(struct iscsi_stats_custom) * |
| 1471 | ISCSI_STATS_CUSTOM_MAX); |
| 1472 | int err = 0; |
| 1473 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 1474 | priv = iscsi_if_transport_lookup(transport); |
| 1475 | if (!priv) |
| 1476 | return -EINVAL; |
| 1477 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1478 | conn = iscsi_conn_lookup(ev->u.get_stats.sid, ev->u.get_stats.cid); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1479 | if (!conn) |
| 1480 | return -EEXIST; |
| 1481 | |
| 1482 | do { |
| 1483 | int actual_size; |
| 1484 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 1485 | skbstat = alloc_skb(len, GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1486 | if (!skbstat) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1487 | iscsi_cls_conn_printk(KERN_ERR, conn, "can not " |
| 1488 | "deliver stats: OOM\n"); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1489 | return -ENOMEM; |
| 1490 | } |
| 1491 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1492 | nlhstat = __nlmsg_put(skbstat, 0, 0, 0, |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1493 | (len - sizeof(*nlhstat)), 0); |
| 1494 | evstat = NLMSG_DATA(nlhstat); |
| 1495 | memset(evstat, 0, sizeof(*evstat)); |
| 1496 | evstat->transport_handle = iscsi_handle(conn->transport); |
| 1497 | evstat->type = nlh->nlmsg_type; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1498 | evstat->u.get_stats.cid = |
| 1499 | ev->u.get_stats.cid; |
| 1500 | evstat->u.get_stats.sid = |
| 1501 | ev->u.get_stats.sid; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1502 | stats = (struct iscsi_stats *) |
| 1503 | ((char*)evstat + sizeof(*evstat)); |
| 1504 | memset(stats, 0, sizeof(*stats)); |
| 1505 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1506 | transport->get_stats(conn, stats); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1507 | actual_size = NLMSG_SPACE(sizeof(struct iscsi_uevent) + |
| 1508 | sizeof(struct iscsi_stats) + |
| 1509 | sizeof(struct iscsi_stats_custom) * |
| 1510 | stats->custom_length); |
| 1511 | actual_size -= sizeof(*nlhstat); |
| 1512 | actual_size = NLMSG_LENGTH(actual_size); |
Mike Christie | 5b940ad | 2006-02-01 21:06:56 -0600 | [diff] [blame] | 1513 | skb_trim(skbstat, NLMSG_ALIGN(actual_size)); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1514 | nlhstat->nlmsg_len = actual_size; |
| 1515 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1516 | err = iscsi_multicast_skb(skbstat, ISCSI_NL_GRP_ISCSID, |
| 1517 | GFP_ATOMIC); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1518 | } while (err < 0 && err != -ECONNREFUSED); |
| 1519 | |
| 1520 | return err; |
| 1521 | } |
| 1522 | |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1523 | /** |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1524 | * iscsi_session_event - send session destr. completion event |
| 1525 | * @session: iscsi class session |
| 1526 | * @event: type of event |
Rob Landley | eb44820 | 2007-11-03 13:30:39 -0500 | [diff] [blame] | 1527 | */ |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1528 | int iscsi_session_event(struct iscsi_cls_session *session, |
| 1529 | enum iscsi_uevent_e event) |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1530 | { |
| 1531 | struct iscsi_internal *priv; |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1532 | struct Scsi_Host *shost; |
| 1533 | struct iscsi_uevent *ev; |
| 1534 | struct sk_buff *skb; |
| 1535 | struct nlmsghdr *nlh; |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1536 | int rc, len = NLMSG_SPACE(sizeof(*ev)); |
| 1537 | |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1538 | priv = iscsi_if_transport_lookup(session->transport); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1539 | if (!priv) |
| 1540 | return -EINVAL; |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1541 | shost = iscsi_session_to_shost(session); |
| 1542 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 1543 | skb = alloc_skb(len, GFP_KERNEL); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1544 | if (!skb) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1545 | iscsi_cls_session_printk(KERN_ERR, session, |
| 1546 | "Cannot notify userspace of session " |
| 1547 | "event %u\n", event); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1548 | return -ENOMEM; |
| 1549 | } |
| 1550 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1551 | nlh = __nlmsg_put(skb, 0, 0, 0, (len - sizeof(*nlh)), 0); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1552 | ev = NLMSG_DATA(nlh); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1553 | ev->transport_handle = iscsi_handle(session->transport); |
| 1554 | |
| 1555 | ev->type = event; |
| 1556 | switch (event) { |
| 1557 | case ISCSI_KEVENT_DESTROY_SESSION: |
| 1558 | ev->r.d_session.host_no = shost->host_no; |
| 1559 | ev->r.d_session.sid = session->sid; |
| 1560 | break; |
| 1561 | case ISCSI_KEVENT_CREATE_SESSION: |
| 1562 | ev->r.c_session_ret.host_no = shost->host_no; |
| 1563 | ev->r.c_session_ret.sid = session->sid; |
| 1564 | break; |
| 1565 | case ISCSI_KEVENT_UNBIND_SESSION: |
| 1566 | ev->r.unbind_session.host_no = shost->host_no; |
| 1567 | ev->r.unbind_session.sid = session->sid; |
| 1568 | break; |
| 1569 | default: |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1570 | iscsi_cls_session_printk(KERN_ERR, session, "Invalid event " |
| 1571 | "%u.\n", event); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1572 | kfree_skb(skb); |
| 1573 | return -EINVAL; |
| 1574 | } |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1575 | |
| 1576 | /* |
| 1577 | * this will occur if the daemon is not up, so we just warn |
| 1578 | * the user and when the daemon is restarted it will handle it |
| 1579 | */ |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1580 | rc = iscsi_multicast_skb(skb, ISCSI_NL_GRP_ISCSID, GFP_KERNEL); |
Pablo Neira Ayuso | ff491a7 | 2009-02-05 23:56:36 -0800 | [diff] [blame] | 1581 | if (rc == -ESRCH) |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1582 | iscsi_cls_session_printk(KERN_ERR, session, |
| 1583 | "Cannot notify userspace of session " |
| 1584 | "event %u. Check iscsi daemon\n", |
| 1585 | event); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1586 | |
| 1587 | ISCSI_DBG_TRANS_SESSION(session, "Completed handling event %d rc %d\n", |
| 1588 | event, rc); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1589 | return rc; |
| 1590 | } |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1591 | EXPORT_SYMBOL_GPL(iscsi_session_event); |
Mike Christie | 53cb8a1 | 2006-06-28 12:00:32 -0500 | [diff] [blame] | 1592 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1593 | static int |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 1594 | iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_endpoint *ep, |
| 1595 | struct iscsi_uevent *ev, uint32_t initial_cmdsn, |
Mike Christie | 40753ca | 2008-05-21 15:53:56 -0500 | [diff] [blame] | 1596 | uint16_t cmds_max, uint16_t queue_depth) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1597 | { |
| 1598 | struct iscsi_transport *transport = priv->iscsi_transport; |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1599 | struct iscsi_cls_session *session; |
Mike Christie | 5e7facb | 2009-03-05 14:46:06 -0600 | [diff] [blame] | 1600 | struct Scsi_Host *shost; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1601 | |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 1602 | session = transport->create_session(ep, cmds_max, queue_depth, |
Mike Christie | 5e7facb | 2009-03-05 14:46:06 -0600 | [diff] [blame] | 1603 | initial_cmdsn); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1604 | if (!session) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1605 | return -ENOMEM; |
| 1606 | |
Mike Christie | 5e7facb | 2009-03-05 14:46:06 -0600 | [diff] [blame] | 1607 | shost = iscsi_session_to_shost(session); |
| 1608 | ev->r.c_session_ret.host_no = shost->host_no; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1609 | ev->r.c_session_ret.sid = session->sid; |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1610 | ISCSI_DBG_TRANS_SESSION(session, |
| 1611 | "Completed creating transport session\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1612 | return 0; |
| 1613 | } |
| 1614 | |
| 1615 | static int |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1616 | iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1617 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1618 | struct iscsi_cls_conn *conn; |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1619 | struct iscsi_cls_session *session; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1620 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1621 | session = iscsi_session_lookup(ev->u.c_conn.sid); |
| 1622 | if (!session) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1623 | printk(KERN_ERR "iscsi: invalid session %d.\n", |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1624 | ev->u.c_conn.sid); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1625 | return -EINVAL; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1626 | } |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1627 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1628 | conn = transport->create_conn(session, ev->u.c_conn.cid); |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1629 | if (!conn) { |
Mike Christie | 322d739 | 2008-01-31 13:36:52 -0600 | [diff] [blame] | 1630 | iscsi_cls_session_printk(KERN_ERR, session, |
| 1631 | "couldn't create a new connection."); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1632 | return -ENOMEM; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1633 | } |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1634 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1635 | ev->r.c_conn_ret.sid = session->sid; |
| 1636 | ev->r.c_conn_ret.cid = conn->cid; |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1637 | |
| 1638 | ISCSI_DBG_TRANS_CONN(conn, "Completed creating transport conn\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1639 | return 0; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | static int |
| 1643 | iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
| 1644 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1645 | struct iscsi_cls_conn *conn; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1646 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1647 | conn = iscsi_conn_lookup(ev->u.d_conn.sid, ev->u.d_conn.cid); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1648 | if (!conn) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1649 | return -EINVAL; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1650 | |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1651 | ISCSI_DBG_TRANS_CONN(conn, "Destroying transport conn\n"); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1652 | if (transport->destroy_conn) |
| 1653 | transport->destroy_conn(conn); |
Mike Christie | 632248a | 2009-08-20 15:11:01 -0500 | [diff] [blame] | 1654 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1655 | return 0; |
| 1656 | } |
| 1657 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1658 | static int |
| 1659 | iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
| 1660 | { |
| 1661 | char *data = (char*)ev + sizeof(*ev); |
| 1662 | struct iscsi_cls_conn *conn; |
| 1663 | struct iscsi_cls_session *session; |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 1664 | int err = 0, value = 0; |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1665 | |
| 1666 | session = iscsi_session_lookup(ev->u.set_param.sid); |
| 1667 | conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid); |
| 1668 | if (!conn || !session) |
| 1669 | return -EINVAL; |
| 1670 | |
| 1671 | switch (ev->u.set_param.param) { |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1672 | case ISCSI_PARAM_SESS_RECOVERY_TMO: |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 1673 | sscanf(data, "%d", &value); |
Mike Christie | fdd46dc | 2009-11-11 16:34:34 -0600 | [diff] [blame] | 1674 | session->recovery_tmo = value; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1675 | break; |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1676 | default: |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 1677 | err = transport->set_param(conn, ev->u.set_param.param, |
| 1678 | data, ev->u.set_param.len); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | return err; |
| 1682 | } |
| 1683 | |
Mike Christie | 10eb0f0 | 2009-05-13 17:57:38 -0500 | [diff] [blame] | 1684 | static int iscsi_if_ep_connect(struct iscsi_transport *transport, |
| 1685 | struct iscsi_uevent *ev, int msg_type) |
| 1686 | { |
| 1687 | struct iscsi_endpoint *ep; |
| 1688 | struct sockaddr *dst_addr; |
| 1689 | struct Scsi_Host *shost = NULL; |
| 1690 | int non_blocking, err = 0; |
| 1691 | |
| 1692 | if (!transport->ep_connect) |
| 1693 | return -EINVAL; |
| 1694 | |
| 1695 | if (msg_type == ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST) { |
| 1696 | shost = scsi_host_lookup(ev->u.ep_connect_through_host.host_no); |
| 1697 | if (!shost) { |
| 1698 | printk(KERN_ERR "ep connect failed. Could not find " |
| 1699 | "host no %u\n", |
| 1700 | ev->u.ep_connect_through_host.host_no); |
| 1701 | return -ENODEV; |
| 1702 | } |
| 1703 | non_blocking = ev->u.ep_connect_through_host.non_blocking; |
| 1704 | } else |
| 1705 | non_blocking = ev->u.ep_connect.non_blocking; |
| 1706 | |
| 1707 | dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev)); |
| 1708 | ep = transport->ep_connect(shost, dst_addr, non_blocking); |
| 1709 | if (IS_ERR(ep)) { |
| 1710 | err = PTR_ERR(ep); |
| 1711 | goto release_host; |
| 1712 | } |
| 1713 | |
| 1714 | ev->r.ep_connect_ret.handle = ep->id; |
| 1715 | release_host: |
| 1716 | if (shost) |
| 1717 | scsi_host_put(shost); |
| 1718 | return err; |
| 1719 | } |
| 1720 | |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 1721 | static int iscsi_if_ep_disconnect(struct iscsi_transport *transport, |
| 1722 | u64 ep_handle) |
| 1723 | { |
| 1724 | struct iscsi_cls_conn *conn; |
| 1725 | struct iscsi_endpoint *ep; |
| 1726 | |
| 1727 | if (!transport->ep_disconnect) |
| 1728 | return -EINVAL; |
| 1729 | |
| 1730 | ep = iscsi_lookup_endpoint(ep_handle); |
| 1731 | if (!ep) |
| 1732 | return -EINVAL; |
| 1733 | conn = ep->conn; |
| 1734 | if (conn) { |
| 1735 | mutex_lock(&conn->ep_mutex); |
| 1736 | conn->ep = NULL; |
| 1737 | mutex_unlock(&conn->ep_mutex); |
| 1738 | } |
| 1739 | |
| 1740 | transport->ep_disconnect(ep); |
| 1741 | return 0; |
| 1742 | } |
| 1743 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1744 | static int |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1745 | iscsi_if_transport_ep(struct iscsi_transport *transport, |
| 1746 | struct iscsi_uevent *ev, int msg_type) |
| 1747 | { |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 1748 | struct iscsi_endpoint *ep; |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1749 | int rc = 0; |
| 1750 | |
| 1751 | switch (msg_type) { |
Mike Christie | 10eb0f0 | 2009-05-13 17:57:38 -0500 | [diff] [blame] | 1752 | case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST: |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1753 | case ISCSI_UEVENT_TRANSPORT_EP_CONNECT: |
Mike Christie | 10eb0f0 | 2009-05-13 17:57:38 -0500 | [diff] [blame] | 1754 | rc = iscsi_if_ep_connect(transport, ev, msg_type); |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1755 | break; |
| 1756 | case ISCSI_UEVENT_TRANSPORT_EP_POLL: |
| 1757 | if (!transport->ep_poll) |
| 1758 | return -EINVAL; |
| 1759 | |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 1760 | ep = iscsi_lookup_endpoint(ev->u.ep_poll.ep_handle); |
| 1761 | if (!ep) |
| 1762 | return -EINVAL; |
| 1763 | |
| 1764 | ev->r.retcode = transport->ep_poll(ep, |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1765 | ev->u.ep_poll.timeout_ms); |
| 1766 | break; |
| 1767 | case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT: |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 1768 | rc = iscsi_if_ep_disconnect(transport, |
| 1769 | ev->u.ep_disconnect.ep_handle); |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1770 | break; |
| 1771 | } |
| 1772 | return rc; |
| 1773 | } |
| 1774 | |
| 1775 | static int |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 1776 | iscsi_tgt_dscvr(struct iscsi_transport *transport, |
| 1777 | struct iscsi_uevent *ev) |
| 1778 | { |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 1779 | struct Scsi_Host *shost; |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 1780 | struct sockaddr *dst_addr; |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 1781 | int err; |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 1782 | |
| 1783 | if (!transport->tgt_dscvr) |
| 1784 | return -EINVAL; |
| 1785 | |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 1786 | shost = scsi_host_lookup(ev->u.tgt_dscvr.host_no); |
James Smart | 315cb0a | 2008-08-07 20:49:30 -0400 | [diff] [blame] | 1787 | if (!shost) { |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 1788 | printk(KERN_ERR "target discovery could not find host no %u\n", |
| 1789 | ev->u.tgt_dscvr.host_no); |
| 1790 | return -ENODEV; |
| 1791 | } |
| 1792 | |
| 1793 | |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 1794 | dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev)); |
Mike Christie | 2174a04 | 2007-05-30 12:57:10 -0500 | [diff] [blame] | 1795 | err = transport->tgt_dscvr(shost, ev->u.tgt_dscvr.type, |
| 1796 | ev->u.tgt_dscvr.enable, dst_addr); |
| 1797 | scsi_host_put(shost); |
| 1798 | return err; |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | static int |
Mike Christie | 1d9bf13 | 2007-05-30 12:57:11 -0500 | [diff] [blame] | 1802 | iscsi_set_host_param(struct iscsi_transport *transport, |
| 1803 | struct iscsi_uevent *ev) |
| 1804 | { |
| 1805 | char *data = (char*)ev + sizeof(*ev); |
| 1806 | struct Scsi_Host *shost; |
| 1807 | int err; |
| 1808 | |
| 1809 | if (!transport->set_host_param) |
| 1810 | return -ENOSYS; |
| 1811 | |
| 1812 | shost = scsi_host_lookup(ev->u.set_host_param.host_no); |
James Smart | 315cb0a | 2008-08-07 20:49:30 -0400 | [diff] [blame] | 1813 | if (!shost) { |
Mike Christie | 1d9bf13 | 2007-05-30 12:57:11 -0500 | [diff] [blame] | 1814 | printk(KERN_ERR "set_host_param could not find host no %u\n", |
| 1815 | ev->u.set_host_param.host_no); |
| 1816 | return -ENODEV; |
| 1817 | } |
| 1818 | |
| 1819 | err = transport->set_host_param(shost, ev->u.set_host_param.param, |
| 1820 | data, ev->u.set_host_param.len); |
| 1821 | scsi_host_put(shost); |
| 1822 | return err; |
| 1823 | } |
| 1824 | |
| 1825 | static int |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1826 | iscsi_set_path(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
| 1827 | { |
| 1828 | struct Scsi_Host *shost; |
| 1829 | struct iscsi_path *params; |
| 1830 | int err; |
| 1831 | |
| 1832 | if (!transport->set_path) |
| 1833 | return -ENOSYS; |
| 1834 | |
| 1835 | shost = scsi_host_lookup(ev->u.set_path.host_no); |
| 1836 | if (!shost) { |
| 1837 | printk(KERN_ERR "set path could not find host no %u\n", |
| 1838 | ev->u.set_path.host_no); |
| 1839 | return -ENODEV; |
| 1840 | } |
| 1841 | |
| 1842 | params = (struct iscsi_path *)((char *)ev + sizeof(*ev)); |
| 1843 | err = transport->set_path(shost, params); |
| 1844 | |
| 1845 | scsi_host_put(shost); |
| 1846 | return err; |
| 1847 | } |
| 1848 | |
| 1849 | static int |
Mike Christie | 56c155b | 2011-07-25 13:48:37 -0500 | [diff] [blame] | 1850 | iscsi_set_iface_params(struct iscsi_transport *transport, |
| 1851 | struct iscsi_uevent *ev) |
| 1852 | { |
| 1853 | char *data = (char *)ev + sizeof(*ev); |
| 1854 | struct Scsi_Host *shost; |
| 1855 | int err; |
| 1856 | |
| 1857 | if (!transport->set_iface_param) |
| 1858 | return -ENOSYS; |
| 1859 | |
| 1860 | shost = scsi_host_lookup(ev->u.set_iface_params.host_no); |
| 1861 | if (!shost) { |
| 1862 | printk(KERN_ERR "set_iface_params could not find host no %u\n", |
| 1863 | ev->u.set_iface_params.host_no); |
| 1864 | return -ENODEV; |
| 1865 | } |
| 1866 | |
| 1867 | err = transport->set_iface_param(shost, data, |
| 1868 | ev->u.set_iface_params.count); |
| 1869 | scsi_host_put(shost); |
| 1870 | return err; |
| 1871 | } |
| 1872 | |
| 1873 | static int |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1874 | iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, uint32_t *group) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1875 | { |
| 1876 | int err = 0; |
| 1877 | struct iscsi_uevent *ev = NLMSG_DATA(nlh); |
| 1878 | struct iscsi_transport *transport = NULL; |
| 1879 | struct iscsi_internal *priv; |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1880 | struct iscsi_cls_session *session; |
| 1881 | struct iscsi_cls_conn *conn; |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 1882 | struct iscsi_endpoint *ep = NULL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1883 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 1884 | if (nlh->nlmsg_type == ISCSI_UEVENT_PATH_UPDATE) |
| 1885 | *group = ISCSI_NL_GRP_UIP; |
| 1886 | else |
| 1887 | *group = ISCSI_NL_GRP_ISCSID; |
| 1888 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1889 | priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle)); |
| 1890 | if (!priv) |
| 1891 | return -EINVAL; |
| 1892 | transport = priv->iscsi_transport; |
| 1893 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1894 | if (!try_module_get(transport->owner)) |
| 1895 | return -EINVAL; |
| 1896 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1897 | switch (nlh->nlmsg_type) { |
| 1898 | case ISCSI_UEVENT_CREATE_SESSION: |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 1899 | err = iscsi_if_create_session(priv, ep, ev, |
Mike Christie | 40753ca | 2008-05-21 15:53:56 -0500 | [diff] [blame] | 1900 | ev->u.c_session.initial_cmdsn, |
| 1901 | ev->u.c_session.cmds_max, |
| 1902 | ev->u.c_session.queue_depth); |
| 1903 | break; |
| 1904 | case ISCSI_UEVENT_CREATE_BOUND_SESSION: |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 1905 | ep = iscsi_lookup_endpoint(ev->u.c_bound_session.ep_handle); |
Mike Christie | c95fddc | 2008-06-16 10:11:32 -0500 | [diff] [blame] | 1906 | if (!ep) { |
| 1907 | err = -EINVAL; |
| 1908 | break; |
| 1909 | } |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 1910 | |
| 1911 | err = iscsi_if_create_session(priv, ep, ev, |
Mike Christie | 40753ca | 2008-05-21 15:53:56 -0500 | [diff] [blame] | 1912 | ev->u.c_bound_session.initial_cmdsn, |
| 1913 | ev->u.c_bound_session.cmds_max, |
| 1914 | ev->u.c_bound_session.queue_depth); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1915 | break; |
| 1916 | case ISCSI_UEVENT_DESTROY_SESSION: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1917 | session = iscsi_session_lookup(ev->u.d_session.sid); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1918 | if (session) |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1919 | transport->destroy_session(session); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1920 | else |
| 1921 | err = -EINVAL; |
| 1922 | break; |
| 1923 | case ISCSI_UEVENT_UNBIND_SESSION: |
| 1924 | session = iscsi_session_lookup(ev->u.d_session.sid); |
| 1925 | if (session) |
Mike Christie | 06d25af | 2009-03-05 14:46:02 -0600 | [diff] [blame] | 1926 | scsi_queue_work(iscsi_session_to_shost(session), |
| 1927 | &session->unbind_work); |
Mike Christie | 2697478 | 2007-12-13 12:43:29 -0600 | [diff] [blame] | 1928 | else |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1929 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1930 | break; |
| 1931 | case ISCSI_UEVENT_CREATE_CONN: |
| 1932 | err = iscsi_if_create_conn(transport, ev); |
| 1933 | break; |
| 1934 | case ISCSI_UEVENT_DESTROY_CONN: |
| 1935 | err = iscsi_if_destroy_conn(transport, ev); |
| 1936 | break; |
| 1937 | case ISCSI_UEVENT_BIND_CONN: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1938 | session = iscsi_session_lookup(ev->u.b_conn.sid); |
| 1939 | conn = iscsi_conn_lookup(ev->u.b_conn.sid, ev->u.b_conn.cid); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1940 | |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 1941 | if (conn && conn->ep) |
| 1942 | iscsi_if_ep_disconnect(transport, conn->ep->id); |
| 1943 | |
| 1944 | if (!session || !conn) { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1945 | err = -EINVAL; |
Mike Christie | 22a39fb | 2011-02-16 15:04:33 -0600 | [diff] [blame] | 1946 | break; |
| 1947 | } |
| 1948 | |
| 1949 | ev->r.retcode = transport->bind_conn(session, conn, |
| 1950 | ev->u.b_conn.transport_eph, |
| 1951 | ev->u.b_conn.is_leading); |
| 1952 | if (ev->r.retcode || !transport->ep_connect) |
| 1953 | break; |
| 1954 | |
| 1955 | ep = iscsi_lookup_endpoint(ev->u.b_conn.transport_eph); |
| 1956 | if (ep) { |
| 1957 | ep->conn = conn; |
| 1958 | |
| 1959 | mutex_lock(&conn->ep_mutex); |
| 1960 | conn->ep = ep; |
| 1961 | mutex_unlock(&conn->ep_mutex); |
| 1962 | } else |
| 1963 | iscsi_cls_conn_printk(KERN_ERR, conn, |
| 1964 | "Could not set ep conn " |
| 1965 | "binding\n"); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1966 | break; |
| 1967 | case ISCSI_UEVENT_SET_PARAM: |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1968 | err = iscsi_set_param(transport, ev); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1969 | break; |
| 1970 | case ISCSI_UEVENT_START_CONN: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1971 | conn = iscsi_conn_lookup(ev->u.start_conn.sid, ev->u.start_conn.cid); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1972 | if (conn) |
| 1973 | ev->r.retcode = transport->start_conn(conn); |
| 1974 | else |
| 1975 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1976 | break; |
| 1977 | case ISCSI_UEVENT_STOP_CONN: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1978 | conn = iscsi_conn_lookup(ev->u.stop_conn.sid, ev->u.stop_conn.cid); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1979 | if (conn) |
| 1980 | transport->stop_conn(conn, ev->u.stop_conn.flag); |
| 1981 | else |
| 1982 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1983 | break; |
| 1984 | case ISCSI_UEVENT_SEND_PDU: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1985 | conn = iscsi_conn_lookup(ev->u.send_pdu.sid, ev->u.send_pdu.cid); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1986 | if (conn) |
| 1987 | ev->r.retcode = transport->send_pdu(conn, |
| 1988 | (struct iscsi_hdr*)((char*)ev + sizeof(*ev)), |
| 1989 | (char*)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size, |
| 1990 | ev->u.send_pdu.data_size); |
| 1991 | else |
| 1992 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1993 | break; |
| 1994 | case ISCSI_UEVENT_GET_STATS: |
Mike Christie | 5b940ad | 2006-02-01 21:06:56 -0600 | [diff] [blame] | 1995 | err = iscsi_if_get_stats(transport, nlh); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1996 | break; |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1997 | case ISCSI_UEVENT_TRANSPORT_EP_CONNECT: |
| 1998 | case ISCSI_UEVENT_TRANSPORT_EP_POLL: |
| 1999 | case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT: |
Mike Christie | 10eb0f0 | 2009-05-13 17:57:38 -0500 | [diff] [blame] | 2000 | case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST: |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 2001 | err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type); |
| 2002 | break; |
Mike Christie | 01cb225 | 2006-06-28 12:00:22 -0500 | [diff] [blame] | 2003 | case ISCSI_UEVENT_TGT_DSCVR: |
| 2004 | err = iscsi_tgt_dscvr(transport, ev); |
| 2005 | break; |
Mike Christie | 1d9bf13 | 2007-05-30 12:57:11 -0500 | [diff] [blame] | 2006 | case ISCSI_UEVENT_SET_HOST_PARAM: |
| 2007 | err = iscsi_set_host_param(transport, ev); |
| 2008 | break; |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2009 | case ISCSI_UEVENT_PATH_UPDATE: |
| 2010 | err = iscsi_set_path(transport, ev); |
| 2011 | break; |
Mike Christie | 56c155b | 2011-07-25 13:48:37 -0500 | [diff] [blame] | 2012 | case ISCSI_UEVENT_SET_IFACE_PARAMS: |
| 2013 | err = iscsi_set_iface_params(transport, ev); |
| 2014 | break; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2015 | default: |
Mike Christie | 1d9bf13 | 2007-05-30 12:57:11 -0500 | [diff] [blame] | 2016 | err = -ENOSYS; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2017 | break; |
| 2018 | } |
| 2019 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 2020 | module_put(transport->owner); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2021 | return err; |
| 2022 | } |
| 2023 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2024 | /* |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2025 | * Get message from skb. Each message is processed by iscsi_if_recv_msg. |
| 2026 | * Malformed skbs with wrong lengths or invalid creds are not processed. |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 2027 | */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2028 | static void |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2029 | iscsi_if_rx(struct sk_buff *skb) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2030 | { |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 2031 | mutex_lock(&rx_queue_mutex); |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2032 | while (skb->len >= NLMSG_SPACE(0)) { |
| 2033 | int err; |
| 2034 | uint32_t rlen; |
| 2035 | struct nlmsghdr *nlh; |
| 2036 | struct iscsi_uevent *ev; |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2037 | uint32_t group; |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2038 | |
| 2039 | nlh = nlmsg_hdr(skb); |
| 2040 | if (nlh->nlmsg_len < sizeof(*nlh) || |
| 2041 | skb->len < nlh->nlmsg_len) { |
| 2042 | break; |
Mike Christie | ee7f8e4 | 2006-02-01 21:07:01 -0600 | [diff] [blame] | 2043 | } |
Mike Christie | ee7f8e4 | 2006-02-01 21:07:01 -0600 | [diff] [blame] | 2044 | |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2045 | ev = NLMSG_DATA(nlh); |
| 2046 | rlen = NLMSG_ALIGN(nlh->nlmsg_len); |
| 2047 | if (rlen > skb->len) |
| 2048 | rlen = skb->len; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2049 | |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2050 | err = iscsi_if_recv_msg(skb, nlh, &group); |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2051 | if (err) { |
| 2052 | ev->type = ISCSI_KEVENT_IF_ERROR; |
| 2053 | ev->iferror = err; |
| 2054 | } |
| 2055 | do { |
| 2056 | /* |
| 2057 | * special case for GET_STATS: |
| 2058 | * on success - sending reply and stats from |
| 2059 | * inside of if_recv_msg(), |
| 2060 | * on error - fall through. |
| 2061 | */ |
| 2062 | if (ev->type == ISCSI_UEVENT_GET_STATS && !err) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2063 | break; |
Michael Chan | 4351477 | 2009-06-08 18:14:41 -0700 | [diff] [blame] | 2064 | err = iscsi_if_send_reply(group, nlh->nlmsg_seq, |
Denis V. Lunev | cd40b7d | 2007-10-10 21:15:29 -0700 | [diff] [blame] | 2065 | nlh->nlmsg_type, 0, 0, ev, sizeof(*ev)); |
| 2066 | } while (err < 0 && err != -ECONNREFUSED); |
| 2067 | skb_pull(skb, rlen); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2068 | } |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 2069 | mutex_unlock(&rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2070 | } |
| 2071 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2072 | #define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2073 | struct device_attribute dev_attr_##_prefix##_##_name = \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2074 | __ATTR(_name,_mode,_show,_store) |
| 2075 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2076 | /* |
| 2077 | * iSCSI connection attrs |
| 2078 | */ |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2079 | #define iscsi_conn_attr_show(param) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2081 | show_conn_param_##param(struct device *dev, \ |
| 2082 | struct device_attribute *attr, char *buf) \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2083 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2084 | struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2085 | struct iscsi_transport *t = conn->transport; \ |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2086 | return t->get_conn_param(conn, param, buf); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2087 | } |
| 2088 | |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2089 | #define iscsi_conn_attr(field, param) \ |
| 2090 | iscsi_conn_attr_show(param) \ |
| 2091 | static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2092 | NULL); |
| 2093 | |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2094 | iscsi_conn_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH); |
| 2095 | iscsi_conn_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH); |
| 2096 | iscsi_conn_attr(header_digest, ISCSI_PARAM_HDRDGST_EN); |
| 2097 | iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN); |
| 2098 | iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN); |
| 2099 | iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN); |
| 2100 | iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT); |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2101 | iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN); |
| 2102 | iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS); |
Mike Christie | f6d5180 | 2007-12-13 12:43:30 -0600 | [diff] [blame] | 2103 | iscsi_conn_attr(ping_tmo, ISCSI_PARAM_PING_TMO); |
| 2104 | iscsi_conn_attr(recv_tmo, ISCSI_PARAM_RECV_TMO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2105 | |
Mike Christie | 289324b | 2011-02-16 15:04:37 -0600 | [diff] [blame] | 2106 | #define iscsi_conn_ep_attr_show(param) \ |
| 2107 | static ssize_t show_conn_ep_param_##param(struct device *dev, \ |
| 2108 | struct device_attribute *attr,\ |
| 2109 | char *buf) \ |
| 2110 | { \ |
| 2111 | struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \ |
| 2112 | struct iscsi_transport *t = conn->transport; \ |
| 2113 | struct iscsi_endpoint *ep; \ |
| 2114 | ssize_t rc; \ |
| 2115 | \ |
| 2116 | /* \ |
| 2117 | * Need to make sure ep_disconnect does not free the LLD's \ |
| 2118 | * interconnect resources while we are trying to read them. \ |
| 2119 | */ \ |
| 2120 | mutex_lock(&conn->ep_mutex); \ |
| 2121 | ep = conn->ep; \ |
| 2122 | if (!ep && t->ep_connect) { \ |
| 2123 | mutex_unlock(&conn->ep_mutex); \ |
| 2124 | return -ENOTCONN; \ |
| 2125 | } \ |
| 2126 | \ |
| 2127 | if (ep) \ |
| 2128 | rc = t->get_ep_param(ep, param, buf); \ |
| 2129 | else \ |
| 2130 | rc = t->get_conn_param(conn, param, buf); \ |
| 2131 | mutex_unlock(&conn->ep_mutex); \ |
| 2132 | return rc; \ |
| 2133 | } |
| 2134 | |
| 2135 | #define iscsi_conn_ep_attr(field, param) \ |
| 2136 | iscsi_conn_ep_attr_show(param) \ |
| 2137 | static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, \ |
| 2138 | show_conn_ep_param_##param, NULL); |
| 2139 | |
| 2140 | iscsi_conn_ep_attr(address, ISCSI_PARAM_CONN_ADDRESS); |
| 2141 | iscsi_conn_ep_attr(port, ISCSI_PARAM_CONN_PORT); |
| 2142 | |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 2143 | static struct attribute *iscsi_conn_attrs[] = { |
| 2144 | &dev_attr_conn_max_recv_dlength.attr, |
| 2145 | &dev_attr_conn_max_xmit_dlength.attr, |
| 2146 | &dev_attr_conn_header_digest.attr, |
| 2147 | &dev_attr_conn_data_digest.attr, |
| 2148 | &dev_attr_conn_ifmarker.attr, |
| 2149 | &dev_attr_conn_ofmarker.attr, |
| 2150 | &dev_attr_conn_address.attr, |
| 2151 | &dev_attr_conn_port.attr, |
| 2152 | &dev_attr_conn_exp_statsn.attr, |
| 2153 | &dev_attr_conn_persistent_address.attr, |
| 2154 | &dev_attr_conn_persistent_port.attr, |
| 2155 | &dev_attr_conn_ping_tmo.attr, |
| 2156 | &dev_attr_conn_recv_tmo.attr, |
| 2157 | NULL, |
| 2158 | }; |
| 2159 | |
| 2160 | static mode_t iscsi_conn_attr_is_visible(struct kobject *kobj, |
| 2161 | struct attribute *attr, int i) |
| 2162 | { |
| 2163 | struct device *cdev = container_of(kobj, struct device, kobj); |
| 2164 | struct iscsi_cls_conn *conn = transport_class_to_conn(cdev); |
| 2165 | struct iscsi_transport *t = conn->transport; |
| 2166 | int param; |
| 2167 | |
| 2168 | if (attr == &dev_attr_conn_max_recv_dlength.attr) |
| 2169 | param = ISCSI_PARAM_MAX_RECV_DLENGTH; |
| 2170 | else if (attr == &dev_attr_conn_max_xmit_dlength.attr) |
| 2171 | param = ISCSI_PARAM_MAX_XMIT_DLENGTH; |
| 2172 | else if (attr == &dev_attr_conn_header_digest.attr) |
| 2173 | param = ISCSI_PARAM_HDRDGST_EN; |
| 2174 | else if (attr == &dev_attr_conn_data_digest.attr) |
| 2175 | param = ISCSI_PARAM_DATADGST_EN; |
| 2176 | else if (attr == &dev_attr_conn_ifmarker.attr) |
| 2177 | param = ISCSI_PARAM_IFMARKER_EN; |
| 2178 | else if (attr == &dev_attr_conn_ofmarker.attr) |
| 2179 | param = ISCSI_PARAM_OFMARKER_EN; |
| 2180 | else if (attr == &dev_attr_conn_address.attr) |
| 2181 | param = ISCSI_PARAM_CONN_ADDRESS; |
| 2182 | else if (attr == &dev_attr_conn_port.attr) |
| 2183 | param = ISCSI_PARAM_CONN_PORT; |
| 2184 | else if (attr == &dev_attr_conn_exp_statsn.attr) |
| 2185 | param = ISCSI_PARAM_EXP_STATSN; |
| 2186 | else if (attr == &dev_attr_conn_persistent_address.attr) |
| 2187 | param = ISCSI_PARAM_PERSISTENT_ADDRESS; |
| 2188 | else if (attr == &dev_attr_conn_persistent_port.attr) |
| 2189 | param = ISCSI_PARAM_PERSISTENT_PORT; |
| 2190 | else if (attr == &dev_attr_conn_ping_tmo.attr) |
| 2191 | param = ISCSI_PARAM_PING_TMO; |
| 2192 | else if (attr == &dev_attr_conn_recv_tmo.attr) |
| 2193 | param = ISCSI_PARAM_RECV_TMO; |
| 2194 | else { |
| 2195 | WARN_ONCE(1, "Invalid conn attr"); |
| 2196 | return 0; |
| 2197 | } |
| 2198 | |
| 2199 | return t->attr_is_visible(ISCSI_PARAM, param); |
| 2200 | } |
| 2201 | |
| 2202 | static struct attribute_group iscsi_conn_group = { |
| 2203 | .attrs = iscsi_conn_attrs, |
| 2204 | .is_visible = iscsi_conn_attr_is_visible, |
| 2205 | }; |
| 2206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | /* |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2208 | * iSCSI session attrs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2209 | */ |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 2210 | #define iscsi_session_attr_show(param, perm) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2212 | show_session_param_##param(struct device *dev, \ |
| 2213 | struct device_attribute *attr, char *buf) \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2214 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2215 | struct iscsi_cls_session *session = \ |
| 2216 | iscsi_dev_to_session(dev->parent); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2217 | struct iscsi_transport *t = session->transport; \ |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 2218 | \ |
| 2219 | if (perm && !capable(CAP_SYS_ADMIN)) \ |
| 2220 | return -EACCES; \ |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2221 | return t->get_session_param(session, param, buf); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2222 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 2224 | #define iscsi_session_attr(field, param, perm) \ |
| 2225 | iscsi_session_attr_show(param, perm) \ |
Mike Christie | a54a52c | 2006-06-28 12:00:23 -0500 | [diff] [blame] | 2226 | static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2227 | NULL); |
Mike Christie | b2c6416 | 2007-05-30 12:57:16 -0500 | [diff] [blame] | 2228 | iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME, 0); |
| 2229 | iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, 0); |
| 2230 | iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, 0); |
| 2231 | iscsi_session_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, 0); |
| 2232 | iscsi_session_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, 0); |
| 2233 | iscsi_session_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, 0); |
| 2234 | iscsi_session_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, 0); |
| 2235 | iscsi_session_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, 0); |
| 2236 | iscsi_session_attr(erl, ISCSI_PARAM_ERL, 0); |
| 2237 | iscsi_session_attr(tpgt, ISCSI_PARAM_TPGT, 0); |
| 2238 | iscsi_session_attr(username, ISCSI_PARAM_USERNAME, 1); |
| 2239 | iscsi_session_attr(username_in, ISCSI_PARAM_USERNAME_IN, 1); |
| 2240 | iscsi_session_attr(password, ISCSI_PARAM_PASSWORD, 1); |
| 2241 | iscsi_session_attr(password_in, ISCSI_PARAM_PASSWORD_IN, 1); |
Mike Christie | 4cd49ea | 2007-12-13 12:43:38 -0600 | [diff] [blame] | 2242 | iscsi_session_attr(fast_abort, ISCSI_PARAM_FAST_ABORT, 0); |
| 2243 | iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0); |
| 2244 | iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0); |
Mike Christie | 3fe5ae8 | 2009-11-11 16:34:33 -0600 | [diff] [blame] | 2245 | iscsi_session_attr(tgt_reset_tmo, ISCSI_PARAM_TGT_RESET_TMO, 0); |
Mike Christie | 88dfd34 | 2008-05-21 15:54:16 -0500 | [diff] [blame] | 2246 | iscsi_session_attr(ifacename, ISCSI_PARAM_IFACE_NAME, 0); |
Vikas Chaudhary | 3b2bef1 | 2010-07-10 14:51:30 +0530 | [diff] [blame] | 2247 | iscsi_session_attr(initiatorname, ISCSI_PARAM_INITIATOR_NAME, 0); |
| 2248 | iscsi_session_attr(targetalias, ISCSI_PARAM_TARGET_ALIAS, 0); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2249 | |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 2250 | static ssize_t |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2251 | show_priv_session_state(struct device *dev, struct device_attribute *attr, |
| 2252 | char *buf) |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 2253 | { |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2254 | struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent); |
Mike Christie | 6eabafb | 2008-01-31 13:36:43 -0600 | [diff] [blame] | 2255 | return sprintf(buf, "%s\n", iscsi_session_state_name(session->state)); |
| 2256 | } |
| 2257 | static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state, |
| 2258 | NULL); |
| 2259 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2260 | #define iscsi_priv_session_attr_show(field, format) \ |
| 2261 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2262 | show_priv_session_##field(struct device *dev, \ |
| 2263 | struct device_attribute *attr, char *buf) \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2264 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2265 | struct iscsi_cls_session *session = \ |
| 2266 | iscsi_dev_to_session(dev->parent); \ |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 2267 | if (session->field == -1) \ |
| 2268 | return sprintf(buf, "off\n"); \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2269 | return sprintf(buf, format"\n", session->field); \ |
| 2270 | } |
| 2271 | |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 2272 | #define iscsi_priv_session_attr_store(field) \ |
| 2273 | static ssize_t \ |
| 2274 | store_priv_session_##field(struct device *dev, \ |
| 2275 | struct device_attribute *attr, \ |
| 2276 | const char *buf, size_t count) \ |
| 2277 | { \ |
| 2278 | int val; \ |
| 2279 | char *cp; \ |
| 2280 | struct iscsi_cls_session *session = \ |
| 2281 | iscsi_dev_to_session(dev->parent); \ |
| 2282 | if ((session->state == ISCSI_SESSION_FREE) || \ |
| 2283 | (session->state == ISCSI_SESSION_FAILED)) \ |
| 2284 | return -EBUSY; \ |
| 2285 | if (strncmp(buf, "off", 3) == 0) \ |
| 2286 | session->field = -1; \ |
| 2287 | else { \ |
| 2288 | val = simple_strtoul(buf, &cp, 0); \ |
| 2289 | if (*cp != '\0' && *cp != '\n') \ |
| 2290 | return -EINVAL; \ |
| 2291 | session->field = val; \ |
| 2292 | } \ |
| 2293 | return count; \ |
| 2294 | } |
| 2295 | |
| 2296 | #define iscsi_priv_session_rw_attr(field, format) \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2297 | iscsi_priv_session_attr_show(field, format) \ |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 2298 | iscsi_priv_session_attr_store(field) \ |
Vasiliy Kulikov | 523f3c8 | 2011-02-04 15:24:14 +0300 | [diff] [blame] | 2299 | static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO | S_IWUSR, \ |
Vikas Chaudhary | fe4f0bd | 2010-07-22 16:57:43 +0530 | [diff] [blame] | 2300 | show_priv_session_##field, \ |
| 2301 | store_priv_session_##field) |
| 2302 | iscsi_priv_session_rw_attr(recovery_tmo, "%d"); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 2303 | |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 2304 | static struct attribute *iscsi_session_attrs[] = { |
| 2305 | &dev_attr_sess_initial_r2t.attr, |
| 2306 | &dev_attr_sess_max_outstanding_r2t.attr, |
| 2307 | &dev_attr_sess_immediate_data.attr, |
| 2308 | &dev_attr_sess_first_burst_len.attr, |
| 2309 | &dev_attr_sess_max_burst_len.attr, |
| 2310 | &dev_attr_sess_data_pdu_in_order.attr, |
| 2311 | &dev_attr_sess_data_seq_in_order.attr, |
| 2312 | &dev_attr_sess_erl.attr, |
| 2313 | &dev_attr_sess_targetname.attr, |
| 2314 | &dev_attr_sess_tpgt.attr, |
| 2315 | &dev_attr_sess_password.attr, |
| 2316 | &dev_attr_sess_password_in.attr, |
| 2317 | &dev_attr_sess_username.attr, |
| 2318 | &dev_attr_sess_username_in.attr, |
| 2319 | &dev_attr_sess_fast_abort.attr, |
| 2320 | &dev_attr_sess_abort_tmo.attr, |
| 2321 | &dev_attr_sess_lu_reset_tmo.attr, |
| 2322 | &dev_attr_sess_tgt_reset_tmo.attr, |
| 2323 | &dev_attr_sess_ifacename.attr, |
| 2324 | &dev_attr_sess_initiatorname.attr, |
| 2325 | &dev_attr_sess_targetalias.attr, |
| 2326 | &dev_attr_priv_sess_recovery_tmo.attr, |
| 2327 | &dev_attr_priv_sess_state.attr, |
| 2328 | NULL, |
| 2329 | }; |
| 2330 | |
| 2331 | static mode_t iscsi_session_attr_is_visible(struct kobject *kobj, |
| 2332 | struct attribute *attr, int i) |
| 2333 | { |
| 2334 | struct device *cdev = container_of(kobj, struct device, kobj); |
| 2335 | struct iscsi_cls_session *session = transport_class_to_session(cdev); |
| 2336 | struct iscsi_transport *t = session->transport; |
| 2337 | int param; |
| 2338 | |
| 2339 | if (attr == &dev_attr_sess_initial_r2t.attr) |
| 2340 | param = ISCSI_PARAM_INITIAL_R2T_EN; |
| 2341 | else if (attr == &dev_attr_sess_max_outstanding_r2t.attr) |
| 2342 | param = ISCSI_PARAM_MAX_R2T; |
| 2343 | else if (attr == &dev_attr_sess_immediate_data.attr) |
| 2344 | param = ISCSI_PARAM_IMM_DATA_EN; |
| 2345 | else if (attr == &dev_attr_sess_first_burst_len.attr) |
| 2346 | param = ISCSI_PARAM_FIRST_BURST; |
| 2347 | else if (attr == &dev_attr_sess_max_burst_len.attr) |
| 2348 | param = ISCSI_PARAM_MAX_BURST; |
| 2349 | else if (attr == &dev_attr_sess_data_pdu_in_order.attr) |
| 2350 | param = ISCSI_PARAM_PDU_INORDER_EN; |
| 2351 | else if (attr == &dev_attr_sess_data_seq_in_order.attr) |
| 2352 | param = ISCSI_PARAM_DATASEQ_INORDER_EN; |
| 2353 | else if (attr == &dev_attr_sess_erl.attr) |
| 2354 | param = ISCSI_PARAM_ERL; |
| 2355 | else if (attr == &dev_attr_sess_targetname.attr) |
| 2356 | param = ISCSI_PARAM_TARGET_NAME; |
| 2357 | else if (attr == &dev_attr_sess_tpgt.attr) |
| 2358 | param = ISCSI_PARAM_TPGT; |
| 2359 | else if (attr == &dev_attr_sess_password.attr) |
| 2360 | param = ISCSI_PARAM_USERNAME; |
| 2361 | else if (attr == &dev_attr_sess_password_in.attr) |
| 2362 | param = ISCSI_PARAM_USERNAME_IN; |
| 2363 | else if (attr == &dev_attr_sess_username.attr) |
| 2364 | param = ISCSI_PARAM_PASSWORD; |
| 2365 | else if (attr == &dev_attr_sess_username_in.attr) |
| 2366 | param = ISCSI_PARAM_PASSWORD_IN; |
| 2367 | else if (attr == &dev_attr_sess_fast_abort.attr) |
| 2368 | param = ISCSI_PARAM_FAST_ABORT; |
| 2369 | else if (attr == &dev_attr_sess_abort_tmo.attr) |
| 2370 | param = ISCSI_PARAM_ABORT_TMO; |
| 2371 | else if (attr == &dev_attr_sess_lu_reset_tmo.attr) |
| 2372 | param = ISCSI_PARAM_LU_RESET_TMO; |
| 2373 | else if (attr == &dev_attr_sess_tgt_reset_tmo.attr) |
| 2374 | param = ISCSI_PARAM_TGT_RESET_TMO; |
| 2375 | else if (attr == &dev_attr_sess_ifacename.attr) |
| 2376 | param = ISCSI_PARAM_IFACE_NAME; |
| 2377 | else if (attr == &dev_attr_sess_initiatorname.attr) |
| 2378 | param = ISCSI_PARAM_INITIATOR_NAME; |
| 2379 | else if (attr == &dev_attr_sess_targetalias.attr) |
| 2380 | param = ISCSI_PARAM_TARGET_ALIAS; |
| 2381 | else if (attr == &dev_attr_priv_sess_recovery_tmo.attr) |
| 2382 | return S_IRUGO | S_IWUSR; |
| 2383 | else if (attr == &dev_attr_priv_sess_state.attr) |
| 2384 | return S_IRUGO; |
| 2385 | else { |
| 2386 | WARN_ONCE(1, "Invalid session attr"); |
| 2387 | return 0; |
| 2388 | } |
| 2389 | |
| 2390 | return t->attr_is_visible(ISCSI_PARAM, param); |
| 2391 | } |
| 2392 | |
| 2393 | static struct attribute_group iscsi_session_group = { |
| 2394 | .attrs = iscsi_session_attrs, |
| 2395 | .is_visible = iscsi_session_attr_is_visible, |
| 2396 | }; |
| 2397 | |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 2398 | /* |
| 2399 | * iSCSI host attrs |
| 2400 | */ |
| 2401 | #define iscsi_host_attr_show(param) \ |
| 2402 | static ssize_t \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2403 | show_host_param_##param(struct device *dev, \ |
| 2404 | struct device_attribute *attr, char *buf) \ |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 2405 | { \ |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2406 | struct Scsi_Host *shost = transport_class_to_shost(dev); \ |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 2407 | struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); \ |
| 2408 | return priv->iscsi_transport->get_host_param(shost, param, buf); \ |
| 2409 | } |
| 2410 | |
| 2411 | #define iscsi_host_attr(field, param) \ |
| 2412 | iscsi_host_attr_show(param) \ |
| 2413 | static ISCSI_CLASS_ATTR(host, field, S_IRUGO, show_host_param_##param, \ |
| 2414 | NULL); |
| 2415 | |
Mike Christie | d8196ed | 2007-05-30 12:57:25 -0500 | [diff] [blame] | 2416 | iscsi_host_attr(netdev, ISCSI_HOST_PARAM_NETDEV_NAME); |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 2417 | iscsi_host_attr(hwaddress, ISCSI_HOST_PARAM_HWADDRESS); |
Mike Christie | d8196ed | 2007-05-30 12:57:25 -0500 | [diff] [blame] | 2418 | iscsi_host_attr(ipaddress, ISCSI_HOST_PARAM_IPADDRESS); |
Mike Christie | 8ad5781 | 2007-05-30 12:57:13 -0500 | [diff] [blame] | 2419 | iscsi_host_attr(initiatorname, ISCSI_HOST_PARAM_INITIATOR_NAME); |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 2420 | |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 2421 | static struct attribute *iscsi_host_attrs[] = { |
| 2422 | &dev_attr_host_netdev.attr, |
| 2423 | &dev_attr_host_hwaddress.attr, |
| 2424 | &dev_attr_host_ipaddress.attr, |
| 2425 | &dev_attr_host_initiatorname.attr, |
| 2426 | NULL, |
| 2427 | }; |
| 2428 | |
| 2429 | static mode_t iscsi_host_attr_is_visible(struct kobject *kobj, |
| 2430 | struct attribute *attr, int i) |
| 2431 | { |
| 2432 | struct device *cdev = container_of(kobj, struct device, kobj); |
| 2433 | struct Scsi_Host *shost = transport_class_to_shost(cdev); |
| 2434 | struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); |
| 2435 | int param; |
| 2436 | |
| 2437 | if (attr == &dev_attr_host_netdev.attr) |
| 2438 | param = ISCSI_HOST_PARAM_NETDEV_NAME; |
| 2439 | else if (attr == &dev_attr_host_hwaddress.attr) |
| 2440 | param = ISCSI_HOST_PARAM_HWADDRESS; |
| 2441 | else if (attr == &dev_attr_host_ipaddress.attr) |
| 2442 | param = ISCSI_HOST_PARAM_IPADDRESS; |
| 2443 | else if (attr == &dev_attr_host_initiatorname.attr) |
| 2444 | param = ISCSI_HOST_PARAM_INITIATOR_NAME; |
| 2445 | else { |
| 2446 | WARN_ONCE(1, "Invalid host attr"); |
| 2447 | return 0; |
| 2448 | } |
| 2449 | |
| 2450 | return priv->iscsi_transport->attr_is_visible(ISCSI_HOST_PARAM, param); |
| 2451 | } |
| 2452 | |
| 2453 | static struct attribute_group iscsi_host_group = { |
| 2454 | .attrs = iscsi_host_attrs, |
| 2455 | .is_visible = iscsi_host_attr_is_visible, |
| 2456 | }; |
Mike Christie | 1819dc8 | 2007-05-30 12:57:08 -0500 | [diff] [blame] | 2457 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2458 | static int iscsi_session_match(struct attribute_container *cont, |
| 2459 | struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2461 | struct iscsi_cls_session *session; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | struct Scsi_Host *shost; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2463 | struct iscsi_internal *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2465 | if (!iscsi_is_session_dev(dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2466 | return 0; |
| 2467 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2468 | session = iscsi_dev_to_session(dev); |
| 2469 | shost = iscsi_session_to_shost(session); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2470 | if (!shost->transportt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | return 0; |
| 2472 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2473 | priv = to_iscsi_internal(shost->transportt); |
| 2474 | if (priv->session_cont.ac.class != &iscsi_session_class.class) |
| 2475 | return 0; |
| 2476 | |
| 2477 | return &priv->session_cont.ac == cont; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | } |
| 2479 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2480 | static int iscsi_conn_match(struct attribute_container *cont, |
| 2481 | struct device *dev) |
| 2482 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2483 | struct iscsi_cls_session *session; |
| 2484 | struct iscsi_cls_conn *conn; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2485 | struct Scsi_Host *shost; |
| 2486 | struct iscsi_internal *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2487 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2488 | if (!iscsi_is_conn_dev(dev)) |
| 2489 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2491 | conn = iscsi_dev_to_conn(dev); |
| 2492 | session = iscsi_dev_to_session(conn->dev.parent); |
| 2493 | shost = iscsi_session_to_shost(session); |
| 2494 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2495 | if (!shost->transportt) |
| 2496 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2498 | priv = to_iscsi_internal(shost->transportt); |
| 2499 | if (priv->conn_cont.ac.class != &iscsi_connection_class.class) |
| 2500 | return 0; |
| 2501 | |
| 2502 | return &priv->conn_cont.ac == cont; |
| 2503 | } |
| 2504 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2505 | static int iscsi_host_match(struct attribute_container *cont, |
| 2506 | struct device *dev) |
| 2507 | { |
| 2508 | struct Scsi_Host *shost; |
| 2509 | struct iscsi_internal *priv; |
| 2510 | |
| 2511 | if (!scsi_is_host_device(dev)) |
| 2512 | return 0; |
| 2513 | |
| 2514 | shost = dev_to_shost(dev); |
| 2515 | if (!shost->transportt || |
| 2516 | shost->transportt->host_attrs.ac.class != &iscsi_host_class.class) |
| 2517 | return 0; |
| 2518 | |
| 2519 | priv = to_iscsi_internal(shost->transportt); |
| 2520 | return &priv->t.host_attrs.ac == cont; |
| 2521 | } |
| 2522 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2523 | struct scsi_transport_template * |
| 2524 | iscsi_register_transport(struct iscsi_transport *tt) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2525 | { |
| 2526 | struct iscsi_internal *priv; |
| 2527 | unsigned long flags; |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 2528 | int err; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2529 | |
| 2530 | BUG_ON(!tt); |
| 2531 | |
| 2532 | priv = iscsi_if_transport_lookup(tt); |
| 2533 | if (priv) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2534 | return NULL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2535 | |
Jes Sorensen | 24669f75 | 2006-01-16 10:31:18 -0500 | [diff] [blame] | 2536 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2537 | if (!priv) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2538 | return NULL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2539 | INIT_LIST_HEAD(&priv->list); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2540 | priv->iscsi_transport = tt; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2541 | priv->t.user_scan = iscsi_user_scan; |
Mike Christie | 06d25af | 2009-03-05 14:46:02 -0600 | [diff] [blame] | 2542 | priv->t.create_work_queue = 1; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2543 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2544 | priv->dev.class = &iscsi_transport_class; |
Kay Sievers | 71610f5 | 2008-12-03 22:41:36 +0100 | [diff] [blame] | 2545 | dev_set_name(&priv->dev, "%s", tt->name); |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2546 | err = device_register(&priv->dev); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2547 | if (err) |
| 2548 | goto free_priv; |
| 2549 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2550 | err = sysfs_create_group(&priv->dev.kobj, &iscsi_transport_group); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2551 | if (err) |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2552 | goto unregister_dev; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2553 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2554 | /* host parameters */ |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2555 | priv->t.host_attrs.ac.class = &iscsi_host_class.class; |
| 2556 | priv->t.host_attrs.ac.match = iscsi_host_match; |
Mike Christie | f27fb2e | 2011-07-25 13:48:45 -0500 | [diff] [blame] | 2557 | priv->t.host_attrs.ac.grp = &iscsi_host_group; |
Mike Christie | 32c6e1b | 2008-05-21 15:53:58 -0500 | [diff] [blame] | 2558 | priv->t.host_size = sizeof(struct iscsi_cls_host); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2559 | transport_container_register(&priv->t.host_attrs); |
| 2560 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2561 | /* connection parameters */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2562 | priv->conn_cont.ac.class = &iscsi_connection_class.class; |
| 2563 | priv->conn_cont.ac.match = iscsi_conn_match; |
Mike Christie | 3128c6c | 2011-07-25 13:48:42 -0500 | [diff] [blame] | 2564 | priv->conn_cont.ac.grp = &iscsi_conn_group; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2565 | transport_container_register(&priv->conn_cont); |
| 2566 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2567 | /* session parameters */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2568 | priv->session_cont.ac.class = &iscsi_session_class.class; |
| 2569 | priv->session_cont.ac.match = iscsi_session_match; |
Mike Christie | 1d063c1 | 2011-07-25 13:48:43 -0500 | [diff] [blame] | 2570 | priv->session_cont.ac.grp = &iscsi_session_group; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2571 | transport_container_register(&priv->session_cont); |
| 2572 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2573 | spin_lock_irqsave(&iscsi_transport_lock, flags); |
| 2574 | list_add(&priv->list, &iscsi_transports); |
| 2575 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2577 | printk(KERN_NOTICE "iscsi: registered transport (%s)\n", tt->name); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2578 | return &priv->t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2580 | unregister_dev: |
| 2581 | device_unregister(&priv->dev); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2582 | return NULL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2583 | free_priv: |
| 2584 | kfree(priv); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 2585 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | } |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2587 | EXPORT_SYMBOL_GPL(iscsi_register_transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2589 | int iscsi_unregister_transport(struct iscsi_transport *tt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2590 | { |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2591 | struct iscsi_internal *priv; |
| 2592 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2594 | BUG_ON(!tt); |
| 2595 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 2596 | mutex_lock(&rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2597 | |
| 2598 | priv = iscsi_if_transport_lookup(tt); |
| 2599 | BUG_ON (!priv); |
| 2600 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2601 | spin_lock_irqsave(&iscsi_transport_lock, flags); |
| 2602 | list_del(&priv->list); |
| 2603 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
| 2604 | |
| 2605 | transport_container_unregister(&priv->conn_cont); |
| 2606 | transport_container_unregister(&priv->session_cont); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2607 | transport_container_unregister(&priv->t.host_attrs); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2608 | |
Tony Jones | ee959b0 | 2008-02-22 00:13:36 +0100 | [diff] [blame] | 2609 | sysfs_remove_group(&priv->dev.kobj, &iscsi_transport_group); |
| 2610 | device_unregister(&priv->dev); |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 2611 | mutex_unlock(&rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2612 | |
| 2613 | return 0; |
| 2614 | } |
| 2615 | EXPORT_SYMBOL_GPL(iscsi_unregister_transport); |
| 2616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | static __init int iscsi_transport_init(void) |
| 2618 | { |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2619 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2620 | |
Meelis Roos | 0949260 | 2006-12-17 12:10:26 -0600 | [diff] [blame] | 2621 | printk(KERN_INFO "Loading iSCSI transport class v%s.\n", |
Mike Christie | f4246b3 | 2006-07-24 15:47:54 -0500 | [diff] [blame] | 2622 | ISCSI_TRANSPORT_VERSION); |
| 2623 | |
Mike Christie | 41be144 | 2007-02-28 17:32:18 -0600 | [diff] [blame] | 2624 | atomic_set(&iscsi_session_nr, 0); |
| 2625 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2626 | err = class_register(&iscsi_transport_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | if (err) |
| 2628 | return err; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2629 | |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2630 | err = class_register(&iscsi_endpoint_class); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2631 | if (err) |
| 2632 | goto unregister_transport_class; |
| 2633 | |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 2634 | err = class_register(&iscsi_iface_class); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2635 | if (err) |
| 2636 | goto unregister_endpoint_class; |
| 2637 | |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 2638 | err = transport_class_register(&iscsi_host_class); |
| 2639 | if (err) |
| 2640 | goto unregister_iface_class; |
| 2641 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2642 | err = transport_class_register(&iscsi_connection_class); |
| 2643 | if (err) |
| 2644 | goto unregister_host_class; |
| 2645 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2646 | err = transport_class_register(&iscsi_session_class); |
| 2647 | if (err) |
| 2648 | goto unregister_conn_class; |
| 2649 | |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2650 | nls = netlink_kernel_create(&init_net, NETLINK_ISCSI, 1, iscsi_if_rx, |
| 2651 | NULL, THIS_MODULE); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2652 | if (!nls) { |
| 2653 | err = -ENOBUFS; |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 2654 | goto unregister_session_class; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2655 | } |
| 2656 | |
Mike Christie | d8bf541 | 2007-12-13 12:43:27 -0600 | [diff] [blame] | 2657 | iscsi_eh_timer_workq = create_singlethread_workqueue("iscsi_eh"); |
| 2658 | if (!iscsi_eh_timer_workq) |
| 2659 | goto release_nls; |
| 2660 | |
Mike Christie | 43a145a | 2006-10-16 18:09:38 -0400 | [diff] [blame] | 2661 | return 0; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2662 | |
Mike Christie | d8bf541 | 2007-12-13 12:43:27 -0600 | [diff] [blame] | 2663 | release_nls: |
Denis V. Lunev | b7c6ba6 | 2008-01-28 14:41:19 -0800 | [diff] [blame] | 2664 | netlink_kernel_release(nls); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2665 | unregister_session_class: |
| 2666 | transport_class_unregister(&iscsi_session_class); |
| 2667 | unregister_conn_class: |
| 2668 | transport_class_unregister(&iscsi_connection_class); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2669 | unregister_host_class: |
| 2670 | transport_class_unregister(&iscsi_host_class); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 2671 | unregister_iface_class: |
| 2672 | class_unregister(&iscsi_iface_class); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2673 | unregister_endpoint_class: |
| 2674 | class_unregister(&iscsi_endpoint_class); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2675 | unregister_transport_class: |
| 2676 | class_unregister(&iscsi_transport_class); |
| 2677 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2678 | } |
| 2679 | |
| 2680 | static void __exit iscsi_transport_exit(void) |
| 2681 | { |
Mike Christie | d8bf541 | 2007-12-13 12:43:27 -0600 | [diff] [blame] | 2682 | destroy_workqueue(iscsi_eh_timer_workq); |
Denis V. Lunev | b7c6ba6 | 2008-01-28 14:41:19 -0800 | [diff] [blame] | 2683 | netlink_kernel_release(nls); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2684 | transport_class_unregister(&iscsi_connection_class); |
| 2685 | transport_class_unregister(&iscsi_session_class); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 2686 | transport_class_unregister(&iscsi_host_class); |
Mike Christie | d82ff9be | 2008-05-21 15:54:13 -0500 | [diff] [blame] | 2687 | class_unregister(&iscsi_endpoint_class); |
Mike Christie | 8d07913 | 2011-07-25 13:48:40 -0500 | [diff] [blame] | 2688 | class_unregister(&iscsi_iface_class); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2689 | class_unregister(&iscsi_transport_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | module_init(iscsi_transport_init); |
| 2693 | module_exit(iscsi_transport_exit); |
| 2694 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 2695 | MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, " |
| 2696 | "Dmitry Yusupov <dmitry_yus@yahoo.com>, " |
| 2697 | "Alex Aizman <itn780@yahoo.com>"); |
| 2698 | MODULE_DESCRIPTION("iSCSI Transport Interface"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2699 | MODULE_LICENSE("GPL"); |
Mike Christie | f4246b3 | 2006-07-24 15:47:54 -0500 | [diff] [blame] | 2700 | MODULE_VERSION(ISCSI_TRANSPORT_VERSION); |
Stephen Hemminger | 058548a | 2010-12-09 09:37:56 -0800 | [diff] [blame] | 2701 | MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK, NETLINK_ISCSI); |