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