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