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