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