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