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