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