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