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> |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 24 | #include <linux/mempool.h> |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 25 | #include <linux/mutex.h> |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 26 | #include <net/tcp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <scsi/scsi.h> |
| 28 | #include <scsi/scsi_host.h> |
| 29 | #include <scsi/scsi_device.h> |
| 30 | #include <scsi/scsi_transport.h> |
| 31 | #include <scsi/scsi_transport_iscsi.h> |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 32 | #include <scsi/iscsi_if.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 34 | #define ISCSI_SESSION_ATTRS 11 |
Mike Christie | 8d2860b | 2006-05-02 19:46:47 -0500 | [diff] [blame] | 35 | #define ISCSI_CONN_ATTRS 11 |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 36 | #define ISCSI_HOST_ATTRS 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | struct iscsi_internal { |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 39 | int daemon_pid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | struct scsi_transport_template t; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 41 | struct iscsi_transport *iscsi_transport; |
| 42 | struct list_head list; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 43 | struct class_device cdev; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 44 | |
| 45 | struct class_device_attribute *host_attrs[ISCSI_HOST_ATTRS + 1]; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 46 | struct transport_container conn_cont; |
| 47 | struct class_device_attribute *conn_attrs[ISCSI_CONN_ATTRS + 1]; |
| 48 | struct transport_container session_cont; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | struct class_device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | }; |
| 51 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 52 | static int iscsi_session_nr; /* sysfs session id for next new session */ |
| 53 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 54 | /* |
| 55 | * list of registered transports and lock that must |
| 56 | * be held while accessing list. The iscsi_transport_lock must |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 57 | * be acquired after the rx_queue_mutex. |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 58 | */ |
| 59 | static LIST_HEAD(iscsi_transports); |
| 60 | static DEFINE_SPINLOCK(iscsi_transport_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 62 | #define to_iscsi_internal(tmpl) \ |
| 63 | container_of(tmpl, struct iscsi_internal, t) |
| 64 | |
| 65 | #define cdev_to_iscsi_internal(_cdev) \ |
| 66 | container_of(_cdev, struct iscsi_internal, cdev) |
| 67 | |
| 68 | static void iscsi_transport_release(struct class_device *cdev) |
| 69 | { |
| 70 | struct iscsi_internal *priv = cdev_to_iscsi_internal(cdev); |
| 71 | kfree(priv); |
| 72 | } |
| 73 | |
| 74 | /* |
| 75 | * iscsi_transport_class represents the iscsi_transports that are |
| 76 | * registered. |
| 77 | */ |
| 78 | static struct class iscsi_transport_class = { |
| 79 | .name = "iscsi_transport", |
| 80 | .release = iscsi_transport_release, |
| 81 | }; |
| 82 | |
| 83 | static ssize_t |
| 84 | show_transport_handle(struct class_device *cdev, char *buf) |
| 85 | { |
| 86 | struct iscsi_internal *priv = cdev_to_iscsi_internal(cdev); |
Mike Christie | 762e2bf | 2005-09-12 21:01:46 -0500 | [diff] [blame] | 87 | 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] | 88 | } |
| 89 | static CLASS_DEVICE_ATTR(handle, S_IRUGO, show_transport_handle, NULL); |
| 90 | |
| 91 | #define show_transport_attr(name, format) \ |
| 92 | static ssize_t \ |
| 93 | show_transport_##name(struct class_device *cdev, char *buf) \ |
| 94 | { \ |
| 95 | struct iscsi_internal *priv = cdev_to_iscsi_internal(cdev); \ |
| 96 | return sprintf(buf, format"\n", priv->iscsi_transport->name); \ |
| 97 | } \ |
| 98 | static CLASS_DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL); |
| 99 | |
| 100 | show_transport_attr(caps, "0x%x"); |
| 101 | show_transport_attr(max_lun, "%d"); |
| 102 | show_transport_attr(max_conn, "%d"); |
| 103 | show_transport_attr(max_cmd_len, "%d"); |
| 104 | |
| 105 | static struct attribute *iscsi_transport_attrs[] = { |
| 106 | &class_device_attr_handle.attr, |
| 107 | &class_device_attr_caps.attr, |
| 108 | &class_device_attr_max_lun.attr, |
| 109 | &class_device_attr_max_conn.attr, |
| 110 | &class_device_attr_max_cmd_len.attr, |
| 111 | NULL, |
| 112 | }; |
| 113 | |
| 114 | static struct attribute_group iscsi_transport_group = { |
| 115 | .attrs = iscsi_transport_attrs, |
| 116 | }; |
| 117 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 118 | static int iscsi_setup_host(struct transport_container *tc, struct device *dev, |
| 119 | struct class_device *cdev) |
| 120 | { |
| 121 | struct Scsi_Host *shost = dev_to_shost(dev); |
| 122 | struct iscsi_host *ihost = shost->shost_data; |
| 123 | |
| 124 | memset(ihost, 0, sizeof(*ihost)); |
| 125 | INIT_LIST_HEAD(&ihost->sessions); |
| 126 | mutex_init(&ihost->mutex); |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | static DECLARE_TRANSPORT_CLASS(iscsi_host_class, |
| 131 | "iscsi_host", |
| 132 | iscsi_setup_host, |
| 133 | NULL, |
| 134 | NULL); |
| 135 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 136 | static DECLARE_TRANSPORT_CLASS(iscsi_session_class, |
| 137 | "iscsi_session", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | NULL, |
| 139 | NULL, |
| 140 | NULL); |
| 141 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 142 | static DECLARE_TRANSPORT_CLASS(iscsi_connection_class, |
| 143 | "iscsi_connection", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | NULL, |
| 145 | NULL, |
| 146 | NULL); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 147 | |
| 148 | static struct sock *nls; |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 149 | static DEFINE_MUTEX(rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 150 | |
| 151 | struct mempool_zone { |
| 152 | mempool_t *pool; |
| 153 | atomic_t allocated; |
| 154 | int size; |
| 155 | int hiwat; |
| 156 | struct list_head freequeue; |
| 157 | spinlock_t freelock; |
| 158 | }; |
| 159 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 160 | static struct mempool_zone *z_reply; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | /* |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 163 | * Z_MAX_* - actual mempool size allocated at the mempool_zone_init() time |
| 164 | * Z_HIWAT_* - zone's high watermark when if_error bit will be set to -ENOMEM |
| 165 | * so daemon will notice OOM on NETLINK tranposrt level and will |
| 166 | * be able to predict or change operational behavior |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 168 | #define Z_MAX_REPLY 8 |
| 169 | #define Z_HIWAT_REPLY 6 |
| 170 | #define Z_MAX_PDU 8 |
| 171 | #define Z_HIWAT_PDU 6 |
| 172 | #define Z_MAX_ERROR 16 |
| 173 | #define Z_HIWAT_ERROR 12 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 175 | static LIST_HEAD(sesslist); |
| 176 | static DEFINE_SPINLOCK(sesslock); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 177 | static LIST_HEAD(connlist); |
| 178 | static DEFINE_SPINLOCK(connlock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 180 | static uint32_t iscsi_conn_get_sid(struct iscsi_cls_conn *conn) |
| 181 | { |
| 182 | struct iscsi_cls_session *sess = iscsi_dev_to_session(conn->dev.parent); |
| 183 | return sess->sid; |
| 184 | } |
| 185 | |
| 186 | /* |
| 187 | * Returns the matching session to a given sid |
| 188 | */ |
| 189 | static struct iscsi_cls_session *iscsi_session_lookup(uint32_t sid) |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 190 | { |
| 191 | unsigned long flags; |
| 192 | struct iscsi_cls_session *sess; |
| 193 | |
| 194 | spin_lock_irqsave(&sesslock, flags); |
| 195 | list_for_each_entry(sess, &sesslist, sess_list) { |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 196 | if (sess->sid == sid) { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 197 | spin_unlock_irqrestore(&sesslock, flags); |
| 198 | return sess; |
| 199 | } |
| 200 | } |
| 201 | spin_unlock_irqrestore(&sesslock, flags); |
| 202 | return NULL; |
| 203 | } |
| 204 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 205 | /* |
| 206 | * Returns the matching connection to a given sid / cid tuple |
| 207 | */ |
| 208 | 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] | 209 | { |
| 210 | unsigned long flags; |
| 211 | struct iscsi_cls_conn *conn; |
| 212 | |
| 213 | spin_lock_irqsave(&connlock, flags); |
| 214 | list_for_each_entry(conn, &connlist, conn_list) { |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 215 | if ((conn->cid == cid) && (iscsi_conn_get_sid(conn) == sid)) { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 216 | spin_unlock_irqrestore(&connlock, flags); |
| 217 | return conn; |
| 218 | } |
| 219 | } |
| 220 | spin_unlock_irqrestore(&connlock, flags); |
| 221 | return NULL; |
| 222 | } |
| 223 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 224 | /* |
| 225 | * The following functions can be used by LLDs that allocate |
| 226 | * their own scsi_hosts or by software iscsi LLDs |
| 227 | */ |
| 228 | static void iscsi_session_release(struct device *dev) |
| 229 | { |
| 230 | struct iscsi_cls_session *session = iscsi_dev_to_session(dev); |
| 231 | struct iscsi_transport *transport = session->transport; |
| 232 | struct Scsi_Host *shost; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 234 | shost = iscsi_session_to_shost(session); |
| 235 | scsi_host_put(shost); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 236 | kfree(session->targetname); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 237 | kfree(session); |
| 238 | module_put(transport->owner); |
| 239 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 241 | static int iscsi_is_session_dev(const struct device *dev) |
| 242 | { |
| 243 | return dev->release == iscsi_session_release; |
| 244 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 246 | static int iscsi_user_scan(struct Scsi_Host *shost, uint channel, |
| 247 | uint id, uint lun) |
| 248 | { |
| 249 | struct iscsi_host *ihost = shost->shost_data; |
| 250 | struct iscsi_cls_session *session; |
| 251 | |
| 252 | mutex_lock(&ihost->mutex); |
| 253 | list_for_each_entry(session, &ihost->sessions, host_list) { |
| 254 | if ((channel == SCAN_WILD_CARD || |
| 255 | channel == session->channel) && |
| 256 | (id == SCAN_WILD_CARD || id == session->target_id)) |
| 257 | scsi_scan_target(&session->dev, session->channel, |
| 258 | session->target_id, lun, 1); |
| 259 | } |
| 260 | mutex_unlock(&ihost->mutex); |
| 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | static void session_recovery_timedout(void *data) |
| 266 | { |
| 267 | struct iscsi_cls_session *session = data; |
| 268 | |
Or Gerlitz | be2df72 | 2006-05-02 19:46:43 -0500 | [diff] [blame] | 269 | dev_printk(KERN_INFO, &session->dev, "iscsi: session recovery timed " |
| 270 | "out after %d secs\n", session->recovery_tmo); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 271 | |
| 272 | if (session->transport->session_recovery_timedout) |
| 273 | session->transport->session_recovery_timedout(session); |
| 274 | |
| 275 | scsi_target_unblock(&session->dev); |
| 276 | } |
| 277 | |
| 278 | void iscsi_unblock_session(struct iscsi_cls_session *session) |
| 279 | { |
| 280 | if (!cancel_delayed_work(&session->recovery_work)) |
| 281 | flush_scheduled_work(); |
| 282 | scsi_target_unblock(&session->dev); |
| 283 | } |
| 284 | EXPORT_SYMBOL_GPL(iscsi_unblock_session); |
| 285 | |
| 286 | void iscsi_block_session(struct iscsi_cls_session *session) |
| 287 | { |
| 288 | scsi_target_block(&session->dev); |
| 289 | schedule_delayed_work(&session->recovery_work, |
| 290 | session->recovery_tmo * HZ); |
| 291 | } |
| 292 | EXPORT_SYMBOL_GPL(iscsi_block_session); |
| 293 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 294 | /** |
| 295 | * iscsi_create_session - create iscsi class session |
| 296 | * @shost: scsi host |
| 297 | * @transport: iscsi transport |
| 298 | * |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 299 | * This can be called from a LLD or iscsi_transport. |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 300 | **/ |
| 301 | struct iscsi_cls_session * |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 302 | iscsi_create_session(struct Scsi_Host *shost, |
| 303 | struct iscsi_transport *transport, int channel) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 304 | { |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 305 | struct iscsi_host *ihost; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 306 | struct iscsi_cls_session *session; |
| 307 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 309 | if (!try_module_get(transport->owner)) |
| 310 | return NULL; |
| 311 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 312 | session = kzalloc(sizeof(*session) + transport->sessiondata_size, |
| 313 | GFP_KERNEL); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 314 | if (!session) |
| 315 | goto module_put; |
| 316 | session->transport = transport; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 317 | session->recovery_tmo = 120; |
| 318 | INIT_WORK(&session->recovery_work, session_recovery_timedout, session); |
| 319 | INIT_LIST_HEAD(&session->host_list); |
| 320 | INIT_LIST_HEAD(&session->sess_list); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 321 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 322 | if (transport->sessiondata_size) |
| 323 | session->dd_data = &session[1]; |
| 324 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 325 | /* this is released in the dev's release function */ |
| 326 | scsi_host_get(shost); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 327 | ihost = shost->shost_data; |
| 328 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 329 | session->sid = iscsi_session_nr++; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 330 | session->channel = channel; |
| 331 | session->target_id = ihost->next_target_id++; |
| 332 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 333 | snprintf(session->dev.bus_id, BUS_ID_SIZE, "session%u", |
| 334 | session->sid); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 335 | session->dev.parent = &shost->shost_gendev; |
| 336 | session->dev.release = iscsi_session_release; |
| 337 | err = device_register(&session->dev); |
| 338 | if (err) { |
| 339 | dev_printk(KERN_ERR, &session->dev, "iscsi: could not " |
| 340 | "register session's dev\n"); |
| 341 | goto free_session; |
| 342 | } |
| 343 | transport_register_device(&session->dev); |
| 344 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 345 | mutex_lock(&ihost->mutex); |
| 346 | list_add(&session->host_list, &ihost->sessions); |
| 347 | mutex_unlock(&ihost->mutex); |
| 348 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 349 | return session; |
| 350 | |
| 351 | free_session: |
| 352 | kfree(session); |
| 353 | module_put: |
| 354 | module_put(transport->owner); |
| 355 | return NULL; |
| 356 | } |
| 357 | |
| 358 | EXPORT_SYMBOL_GPL(iscsi_create_session); |
| 359 | |
| 360 | /** |
| 361 | * iscsi_destroy_session - destroy iscsi session |
| 362 | * @session: iscsi_session |
| 363 | * |
| 364 | * Can be called by a LLD or iscsi_transport. There must not be |
| 365 | * any running connections. |
| 366 | **/ |
| 367 | int iscsi_destroy_session(struct iscsi_cls_session *session) |
| 368 | { |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 369 | struct Scsi_Host *shost = iscsi_session_to_shost(session); |
| 370 | struct iscsi_host *ihost = shost->shost_data; |
| 371 | |
| 372 | if (!cancel_delayed_work(&session->recovery_work)) |
| 373 | flush_scheduled_work(); |
| 374 | |
| 375 | mutex_lock(&ihost->mutex); |
| 376 | list_del(&session->host_list); |
| 377 | mutex_unlock(&ihost->mutex); |
| 378 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 379 | transport_unregister_device(&session->dev); |
| 380 | device_unregister(&session->dev); |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | EXPORT_SYMBOL_GPL(iscsi_destroy_session); |
| 385 | |
| 386 | static void iscsi_conn_release(struct device *dev) |
| 387 | { |
| 388 | struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev); |
| 389 | struct device *parent = conn->dev.parent; |
| 390 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 391 | kfree(conn->persistent_address); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 392 | kfree(conn); |
| 393 | put_device(parent); |
| 394 | } |
| 395 | |
| 396 | static int iscsi_is_conn_dev(const struct device *dev) |
| 397 | { |
| 398 | return dev->release == iscsi_conn_release; |
| 399 | } |
| 400 | |
| 401 | /** |
| 402 | * iscsi_create_conn - create iscsi class connection |
| 403 | * @session: iscsi cls session |
| 404 | * @cid: connection id |
| 405 | * |
| 406 | * This can be called from a LLD or iscsi_transport. The connection |
| 407 | * is child of the session so cid must be unique for all connections |
| 408 | * on the session. |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 409 | * |
| 410 | * Since we do not support MCS, cid will normally be zero. In some cases |
| 411 | * for software iscsi we could be trying to preallocate a connection struct |
| 412 | * in which case there could be two connection structs and cid would be |
| 413 | * non-zero. |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 414 | **/ |
| 415 | struct iscsi_cls_conn * |
| 416 | iscsi_create_conn(struct iscsi_cls_session *session, uint32_t cid) |
| 417 | { |
| 418 | struct iscsi_transport *transport = session->transport; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 419 | struct iscsi_cls_conn *conn; |
| 420 | int err; |
| 421 | |
| 422 | conn = kzalloc(sizeof(*conn) + transport->conndata_size, GFP_KERNEL); |
| 423 | if (!conn) |
| 424 | return NULL; |
| 425 | |
| 426 | if (transport->conndata_size) |
| 427 | conn->dd_data = &conn[1]; |
| 428 | |
| 429 | INIT_LIST_HEAD(&conn->conn_list); |
| 430 | conn->transport = transport; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 431 | conn->cid = cid; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 432 | |
| 433 | /* this is released in the dev's release function */ |
| 434 | if (!get_device(&session->dev)) |
| 435 | goto free_conn; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 436 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 437 | snprintf(conn->dev.bus_id, BUS_ID_SIZE, "connection%d:%u", |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 438 | session->sid, cid); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 439 | conn->dev.parent = &session->dev; |
| 440 | conn->dev.release = iscsi_conn_release; |
| 441 | err = device_register(&conn->dev); |
| 442 | if (err) { |
| 443 | dev_printk(KERN_ERR, &conn->dev, "iscsi: could not register " |
| 444 | "connection's dev\n"); |
| 445 | goto release_parent_ref; |
| 446 | } |
| 447 | transport_register_device(&conn->dev); |
| 448 | return conn; |
| 449 | |
| 450 | release_parent_ref: |
| 451 | put_device(&session->dev); |
| 452 | free_conn: |
| 453 | kfree(conn); |
| 454 | return NULL; |
| 455 | } |
| 456 | |
| 457 | EXPORT_SYMBOL_GPL(iscsi_create_conn); |
| 458 | |
| 459 | /** |
| 460 | * iscsi_destroy_conn - destroy iscsi class connection |
| 461 | * @session: iscsi cls session |
| 462 | * |
| 463 | * This can be called from a LLD or iscsi_transport. |
| 464 | **/ |
| 465 | int iscsi_destroy_conn(struct iscsi_cls_conn *conn) |
| 466 | { |
| 467 | transport_unregister_device(&conn->dev); |
| 468 | device_unregister(&conn->dev); |
| 469 | return 0; |
| 470 | } |
| 471 | |
| 472 | EXPORT_SYMBOL_GPL(iscsi_destroy_conn); |
| 473 | |
| 474 | /* |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 475 | * iscsi interface functions |
| 476 | */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 477 | static struct iscsi_internal * |
| 478 | iscsi_if_transport_lookup(struct iscsi_transport *tt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 480 | struct iscsi_internal *priv; |
| 481 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 483 | spin_lock_irqsave(&iscsi_transport_lock, flags); |
| 484 | list_for_each_entry(priv, &iscsi_transports, list) { |
| 485 | if (tt == priv->iscsi_transport) { |
| 486 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
| 487 | return priv; |
| 488 | } |
| 489 | } |
| 490 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
| 491 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 494 | static inline struct list_head *skb_to_lh(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | { |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 496 | return (struct list_head *)&skb->cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | } |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 498 | |
| 499 | static void* |
Mike Christie | 28e5554 | 2006-02-01 21:07:11 -0600 | [diff] [blame] | 500 | mempool_zone_alloc_skb(gfp_t gfp_mask, void *pool_data) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 501 | { |
| 502 | struct mempool_zone *zone = pool_data; |
| 503 | |
| 504 | return alloc_skb(zone->size, gfp_mask); |
| 505 | } |
| 506 | |
| 507 | static void |
| 508 | mempool_zone_free_skb(void *element, void *pool_data) |
| 509 | { |
| 510 | kfree_skb(element); |
| 511 | } |
| 512 | |
| 513 | static void |
| 514 | mempool_zone_complete(struct mempool_zone *zone) |
| 515 | { |
| 516 | unsigned long flags; |
| 517 | struct list_head *lh, *n; |
| 518 | |
| 519 | spin_lock_irqsave(&zone->freelock, flags); |
| 520 | list_for_each_safe(lh, n, &zone->freequeue) { |
| 521 | struct sk_buff *skb = (struct sk_buff *)((char *)lh - |
| 522 | offsetof(struct sk_buff, cb)); |
| 523 | if (!skb_shared(skb)) { |
| 524 | list_del(skb_to_lh(skb)); |
| 525 | mempool_free(skb, zone->pool); |
| 526 | atomic_dec(&zone->allocated); |
| 527 | } |
| 528 | } |
| 529 | spin_unlock_irqrestore(&zone->freelock, flags); |
| 530 | } |
| 531 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 532 | static struct mempool_zone * |
| 533 | mempool_zone_init(unsigned max, unsigned size, unsigned hiwat) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 534 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 535 | struct mempool_zone *zp; |
| 536 | |
| 537 | zp = kzalloc(sizeof(*zp), GFP_KERNEL); |
| 538 | if (!zp) |
| 539 | return NULL; |
| 540 | |
Mike Christie | 142e301 | 2006-02-01 21:06:58 -0600 | [diff] [blame] | 541 | zp->size = size; |
| 542 | zp->hiwat = hiwat; |
| 543 | INIT_LIST_HEAD(&zp->freequeue); |
| 544 | spin_lock_init(&zp->freelock); |
| 545 | atomic_set(&zp->allocated, 0); |
| 546 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 547 | zp->pool = mempool_create(max, mempool_zone_alloc_skb, |
| 548 | mempool_zone_free_skb, zp); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 549 | if (!zp->pool) { |
| 550 | kfree(zp); |
| 551 | return NULL; |
| 552 | } |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 553 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 554 | return zp; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 557 | static void mempool_zone_destroy(struct mempool_zone *zp) |
| 558 | { |
| 559 | mempool_destroy(zp->pool); |
| 560 | kfree(zp); |
| 561 | } |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 562 | |
| 563 | static struct sk_buff* |
| 564 | mempool_zone_get_skb(struct mempool_zone *zone) |
| 565 | { |
| 566 | struct sk_buff *skb; |
| 567 | |
| 568 | skb = mempool_alloc(zone->pool, GFP_ATOMIC); |
| 569 | if (skb) |
| 570 | atomic_inc(&zone->allocated); |
| 571 | return skb; |
| 572 | } |
| 573 | |
| 574 | static int |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 575 | iscsi_unicast_skb(struct mempool_zone *zone, struct sk_buff *skb, int pid) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 576 | { |
| 577 | unsigned long flags; |
| 578 | int rc; |
| 579 | |
| 580 | skb_get(skb); |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 581 | rc = netlink_unicast(nls, skb, pid, MSG_DONTWAIT); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 582 | if (rc < 0) { |
| 583 | mempool_free(skb, zone->pool); |
| 584 | printk(KERN_ERR "iscsi: can not unicast skb (%d)\n", rc); |
| 585 | return rc; |
| 586 | } |
| 587 | |
| 588 | spin_lock_irqsave(&zone->freelock, flags); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 589 | INIT_LIST_HEAD(skb_to_lh(skb)); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 590 | list_add(skb_to_lh(skb), &zone->freequeue); |
| 591 | spin_unlock_irqrestore(&zone->freelock, flags); |
| 592 | |
| 593 | return 0; |
| 594 | } |
| 595 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 596 | 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] | 597 | char *data, uint32_t data_size) |
| 598 | { |
| 599 | struct nlmsghdr *nlh; |
| 600 | struct sk_buff *skb; |
| 601 | struct iscsi_uevent *ev; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 602 | char *pdu; |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 603 | struct iscsi_internal *priv; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 604 | int len = NLMSG_SPACE(sizeof(*ev) + sizeof(struct iscsi_hdr) + |
| 605 | data_size); |
| 606 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 607 | priv = iscsi_if_transport_lookup(conn->transport); |
| 608 | if (!priv) |
| 609 | return -EINVAL; |
| 610 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 611 | mempool_zone_complete(conn->z_pdu); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 612 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 613 | skb = mempool_zone_get_skb(conn->z_pdu); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 614 | if (!skb) { |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 615 | iscsi_conn_error(conn, ISCSI_ERR_CONN_FAILED); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 616 | dev_printk(KERN_ERR, &conn->dev, "iscsi: can not deliver " |
| 617 | "control PDU: OOM\n"); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 618 | return -ENOMEM; |
| 619 | } |
| 620 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 621 | 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] | 622 | ev = NLMSG_DATA(nlh); |
| 623 | memset(ev, 0, sizeof(*ev)); |
| 624 | ev->transport_handle = iscsi_handle(conn->transport); |
| 625 | ev->type = ISCSI_KEVENT_RECV_PDU; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 626 | if (atomic_read(&conn->z_pdu->allocated) >= conn->z_pdu->hiwat) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 627 | ev->iferror = -ENOMEM; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 628 | ev->r.recv_req.cid = conn->cid; |
| 629 | ev->r.recv_req.sid = iscsi_conn_get_sid(conn); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 630 | pdu = (char*)ev + sizeof(*ev); |
| 631 | memcpy(pdu, hdr, sizeof(struct iscsi_hdr)); |
| 632 | memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size); |
| 633 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 634 | return iscsi_unicast_skb(conn->z_pdu, skb, priv->daemon_pid); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 635 | } |
| 636 | EXPORT_SYMBOL_GPL(iscsi_recv_pdu); |
| 637 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 638 | void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 639 | { |
| 640 | struct nlmsghdr *nlh; |
| 641 | struct sk_buff *skb; |
| 642 | struct iscsi_uevent *ev; |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 643 | struct iscsi_internal *priv; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 644 | int len = NLMSG_SPACE(sizeof(*ev)); |
| 645 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 646 | priv = iscsi_if_transport_lookup(conn->transport); |
| 647 | if (!priv) |
| 648 | return; |
| 649 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 650 | mempool_zone_complete(conn->z_error); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 651 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 652 | skb = mempool_zone_get_skb(conn->z_error); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 653 | if (!skb) { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 654 | dev_printk(KERN_ERR, &conn->dev, "iscsi: gracefully ignored " |
| 655 | "conn error (%d)\n", error); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 656 | return; |
| 657 | } |
| 658 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 659 | 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] | 660 | ev = NLMSG_DATA(nlh); |
| 661 | ev->transport_handle = iscsi_handle(conn->transport); |
| 662 | ev->type = ISCSI_KEVENT_CONN_ERROR; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 663 | if (atomic_read(&conn->z_error->allocated) >= conn->z_error->hiwat) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 664 | ev->iferror = -ENOMEM; |
| 665 | ev->r.connerror.error = error; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 666 | ev->r.connerror.cid = conn->cid; |
| 667 | ev->r.connerror.sid = iscsi_conn_get_sid(conn); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 668 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 669 | iscsi_unicast_skb(conn->z_error, skb, priv->daemon_pid); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 670 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 671 | dev_printk(KERN_INFO, &conn->dev, "iscsi: detected conn error (%d)\n", |
| 672 | error); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 673 | } |
| 674 | EXPORT_SYMBOL_GPL(iscsi_conn_error); |
| 675 | |
| 676 | static int |
| 677 | iscsi_if_send_reply(int pid, int seq, int type, int done, int multi, |
| 678 | void *payload, int size) |
| 679 | { |
| 680 | struct sk_buff *skb; |
| 681 | struct nlmsghdr *nlh; |
| 682 | int len = NLMSG_SPACE(size); |
| 683 | int flags = multi ? NLM_F_MULTI : 0; |
| 684 | int t = done ? NLMSG_DONE : type; |
| 685 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 686 | mempool_zone_complete(z_reply); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 687 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 688 | skb = mempool_zone_get_skb(z_reply); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 689 | /* |
| 690 | * FIXME: |
| 691 | * user is supposed to react on iferror == -ENOMEM; |
| 692 | * see iscsi_if_rx(). |
| 693 | */ |
| 694 | BUG_ON(!skb); |
| 695 | |
| 696 | nlh = __nlmsg_put(skb, pid, seq, t, (len - sizeof(*nlh)), 0); |
| 697 | nlh->nlmsg_flags = flags; |
| 698 | memcpy(NLMSG_DATA(nlh), payload, size); |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 699 | return iscsi_unicast_skb(z_reply, skb, pid); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | static int |
Mike Christie | 5b940ad | 2006-02-01 21:06:56 -0600 | [diff] [blame] | 703 | iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 704 | { |
| 705 | struct iscsi_uevent *ev = NLMSG_DATA(nlh); |
| 706 | struct iscsi_stats *stats; |
| 707 | struct sk_buff *skbstat; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 708 | struct iscsi_cls_conn *conn; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 709 | struct nlmsghdr *nlhstat; |
| 710 | struct iscsi_uevent *evstat; |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 711 | struct iscsi_internal *priv; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 712 | int len = NLMSG_SPACE(sizeof(*ev) + |
| 713 | sizeof(struct iscsi_stats) + |
| 714 | sizeof(struct iscsi_stats_custom) * |
| 715 | ISCSI_STATS_CUSTOM_MAX); |
| 716 | int err = 0; |
| 717 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 718 | priv = iscsi_if_transport_lookup(transport); |
| 719 | if (!priv) |
| 720 | return -EINVAL; |
| 721 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 722 | 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] | 723 | if (!conn) |
| 724 | return -EEXIST; |
| 725 | |
| 726 | do { |
| 727 | int actual_size; |
| 728 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 729 | mempool_zone_complete(conn->z_pdu); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 730 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 731 | skbstat = mempool_zone_get_skb(conn->z_pdu); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 732 | if (!skbstat) { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 733 | dev_printk(KERN_ERR, &conn->dev, "iscsi: can not " |
| 734 | "deliver stats: OOM\n"); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 735 | return -ENOMEM; |
| 736 | } |
| 737 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 738 | nlhstat = __nlmsg_put(skbstat, priv->daemon_pid, 0, 0, |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 739 | (len - sizeof(*nlhstat)), 0); |
| 740 | evstat = NLMSG_DATA(nlhstat); |
| 741 | memset(evstat, 0, sizeof(*evstat)); |
| 742 | evstat->transport_handle = iscsi_handle(conn->transport); |
| 743 | evstat->type = nlh->nlmsg_type; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 744 | if (atomic_read(&conn->z_pdu->allocated) >= conn->z_pdu->hiwat) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 745 | evstat->iferror = -ENOMEM; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 746 | evstat->u.get_stats.cid = |
| 747 | ev->u.get_stats.cid; |
| 748 | evstat->u.get_stats.sid = |
| 749 | ev->u.get_stats.sid; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 750 | stats = (struct iscsi_stats *) |
| 751 | ((char*)evstat + sizeof(*evstat)); |
| 752 | memset(stats, 0, sizeof(*stats)); |
| 753 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 754 | transport->get_stats(conn, stats); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 755 | actual_size = NLMSG_SPACE(sizeof(struct iscsi_uevent) + |
| 756 | sizeof(struct iscsi_stats) + |
| 757 | sizeof(struct iscsi_stats_custom) * |
| 758 | stats->custom_length); |
| 759 | actual_size -= sizeof(*nlhstat); |
| 760 | actual_size = NLMSG_LENGTH(actual_size); |
Mike Christie | 5b940ad | 2006-02-01 21:06:56 -0600 | [diff] [blame] | 761 | skb_trim(skbstat, NLMSG_ALIGN(actual_size)); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 762 | nlhstat->nlmsg_len = actual_size; |
| 763 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 764 | err = iscsi_unicast_skb(conn->z_pdu, skbstat, priv->daemon_pid); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 765 | } while (err < 0 && err != -ECONNREFUSED); |
| 766 | |
| 767 | return err; |
| 768 | } |
| 769 | |
| 770 | static int |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 771 | iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_uevent *ev) |
| 772 | { |
| 773 | struct iscsi_transport *transport = priv->iscsi_transport; |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 774 | struct iscsi_cls_session *session; |
Mike Christie | 7996a77 | 2006-04-06 21:13:41 -0500 | [diff] [blame] | 775 | unsigned long flags; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 776 | uint32_t hostno; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 777 | |
Mike Christie | 7996a77 | 2006-04-06 21:13:41 -0500 | [diff] [blame] | 778 | session = transport->create_session(transport, &priv->t, |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 779 | ev->u.c_session.initial_cmdsn, |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 780 | &hostno); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 781 | if (!session) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 782 | return -ENOMEM; |
| 783 | |
Mike Christie | 7996a77 | 2006-04-06 21:13:41 -0500 | [diff] [blame] | 784 | spin_lock_irqsave(&sesslock, flags); |
| 785 | list_add(&session->sess_list, &sesslist); |
| 786 | spin_unlock_irqrestore(&sesslock, flags); |
| 787 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 788 | ev->r.c_session_ret.host_no = hostno; |
| 789 | ev->r.c_session_ret.sid = session->sid; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 790 | return 0; |
| 791 | } |
| 792 | |
| 793 | static int |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 794 | iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 795 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 796 | struct iscsi_cls_conn *conn; |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 797 | struct iscsi_cls_session *session; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 798 | unsigned long flags; |
| 799 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 800 | session = iscsi_session_lookup(ev->u.c_conn.sid); |
| 801 | if (!session) { |
| 802 | printk(KERN_ERR "iscsi: invalid session %d\n", |
| 803 | ev->u.c_conn.sid); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 804 | return -EINVAL; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 805 | } |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 806 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 807 | conn = transport->create_conn(session, ev->u.c_conn.cid); |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 808 | if (!conn) { |
| 809 | printk(KERN_ERR "iscsi: couldn't create a new " |
| 810 | "connection for session %d\n", |
| 811 | session->sid); |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 812 | return -ENOMEM; |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 813 | } |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 814 | |
| 815 | conn->z_pdu = mempool_zone_init(Z_MAX_PDU, |
| 816 | NLMSG_SPACE(sizeof(struct iscsi_uevent) + |
| 817 | sizeof(struct iscsi_hdr) + |
| 818 | DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH), |
| 819 | Z_HIWAT_PDU); |
| 820 | if (!conn->z_pdu) { |
| 821 | dev_printk(KERN_ERR, &conn->dev, "iscsi: can not allocate " |
| 822 | "pdu zone for new conn\n"); |
| 823 | goto destroy_conn; |
| 824 | } |
| 825 | |
| 826 | conn->z_error = mempool_zone_init(Z_MAX_ERROR, |
| 827 | NLMSG_SPACE(sizeof(struct iscsi_uevent)), |
| 828 | Z_HIWAT_ERROR); |
| 829 | if (!conn->z_error) { |
| 830 | dev_printk(KERN_ERR, &conn->dev, "iscsi: can not allocate " |
| 831 | "error zone for new conn\n"); |
| 832 | goto free_pdu_pool; |
| 833 | } |
| 834 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 835 | ev->r.c_conn_ret.sid = session->sid; |
| 836 | ev->r.c_conn_ret.cid = conn->cid; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 837 | |
| 838 | spin_lock_irqsave(&connlock, flags); |
| 839 | list_add(&conn->conn_list, &connlist); |
| 840 | conn->active = 1; |
| 841 | spin_unlock_irqrestore(&connlock, flags); |
| 842 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 843 | return 0; |
| 844 | |
| 845 | free_pdu_pool: |
| 846 | mempool_zone_destroy(conn->z_pdu); |
| 847 | destroy_conn: |
| 848 | if (transport->destroy_conn) |
| 849 | transport->destroy_conn(conn->dd_data); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 850 | return -ENOMEM; |
| 851 | } |
| 852 | |
| 853 | static int |
| 854 | iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
| 855 | { |
| 856 | unsigned long flags; |
| 857 | struct iscsi_cls_conn *conn; |
| 858 | struct mempool_zone *z_error, *z_pdu; |
| 859 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 860 | 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] | 861 | if (!conn) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 862 | return -EINVAL; |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 863 | spin_lock_irqsave(&connlock, flags); |
| 864 | conn->active = 0; |
| 865 | list_del(&conn->conn_list); |
| 866 | spin_unlock_irqrestore(&connlock, flags); |
| 867 | |
| 868 | z_pdu = conn->z_pdu; |
| 869 | z_error = conn->z_error; |
| 870 | |
| 871 | if (transport->destroy_conn) |
| 872 | transport->destroy_conn(conn); |
| 873 | |
| 874 | mempool_zone_destroy(z_pdu); |
| 875 | mempool_zone_destroy(z_error); |
| 876 | |
| 877 | return 0; |
| 878 | } |
| 879 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 880 | static void |
| 881 | iscsi_copy_param(struct iscsi_uevent *ev, uint32_t *value, char *data) |
| 882 | { |
| 883 | if (ev->u.set_param.len != sizeof(uint32_t)) |
| 884 | BUG(); |
| 885 | memcpy(value, data, min_t(uint32_t, sizeof(uint32_t), |
| 886 | ev->u.set_param.len)); |
| 887 | } |
| 888 | |
| 889 | static int |
| 890 | iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev) |
| 891 | { |
| 892 | char *data = (char*)ev + sizeof(*ev); |
| 893 | struct iscsi_cls_conn *conn; |
| 894 | struct iscsi_cls_session *session; |
| 895 | int err = 0; |
| 896 | uint32_t value = 0; |
| 897 | |
| 898 | session = iscsi_session_lookup(ev->u.set_param.sid); |
| 899 | conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid); |
| 900 | if (!conn || !session) |
| 901 | return -EINVAL; |
| 902 | |
| 903 | switch (ev->u.set_param.param) { |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 904 | case ISCSI_PARAM_SESS_RECOVERY_TMO: |
| 905 | iscsi_copy_param(ev, &value, data); |
| 906 | if (value != 0) |
| 907 | session->recovery_tmo = value; |
| 908 | break; |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 909 | case ISCSI_PARAM_TARGET_NAME: |
| 910 | /* this should not change between logins */ |
| 911 | if (session->targetname) |
| 912 | return 0; |
| 913 | |
| 914 | session->targetname = kstrdup(data, GFP_KERNEL); |
| 915 | if (!session->targetname) |
| 916 | return -ENOMEM; |
| 917 | break; |
| 918 | case ISCSI_PARAM_TPGT: |
| 919 | iscsi_copy_param(ev, &value, data); |
| 920 | session->tpgt = value; |
| 921 | break; |
| 922 | case ISCSI_PARAM_PERSISTENT_PORT: |
| 923 | iscsi_copy_param(ev, &value, data); |
| 924 | conn->persistent_port = value; |
| 925 | break; |
| 926 | case ISCSI_PARAM_PERSISTENT_ADDRESS: |
| 927 | /* |
| 928 | * this is the address returned in discovery so it should |
| 929 | * not change between logins. |
| 930 | */ |
| 931 | if (conn->persistent_address) |
| 932 | return 0; |
| 933 | |
| 934 | conn->persistent_address = kstrdup(data, GFP_KERNEL); |
| 935 | if (!conn->persistent_address) |
| 936 | return -ENOMEM; |
| 937 | break; |
| 938 | default: |
| 939 | iscsi_copy_param(ev, &value, data); |
| 940 | err = transport->set_param(conn, ev->u.set_param.param, value); |
| 941 | } |
| 942 | |
| 943 | return err; |
| 944 | } |
| 945 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 946 | static int |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 947 | iscsi_if_transport_ep(struct iscsi_transport *transport, |
| 948 | struct iscsi_uevent *ev, int msg_type) |
| 949 | { |
| 950 | struct sockaddr *dst_addr; |
| 951 | int rc = 0; |
| 952 | |
| 953 | switch (msg_type) { |
| 954 | case ISCSI_UEVENT_TRANSPORT_EP_CONNECT: |
| 955 | if (!transport->ep_connect) |
| 956 | return -EINVAL; |
| 957 | |
| 958 | dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev)); |
| 959 | rc = transport->ep_connect(dst_addr, |
| 960 | ev->u.ep_connect.non_blocking, |
| 961 | &ev->r.ep_connect_ret.handle); |
| 962 | break; |
| 963 | case ISCSI_UEVENT_TRANSPORT_EP_POLL: |
| 964 | if (!transport->ep_poll) |
| 965 | return -EINVAL; |
| 966 | |
| 967 | ev->r.retcode = transport->ep_poll(ev->u.ep_poll.ep_handle, |
| 968 | ev->u.ep_poll.timeout_ms); |
| 969 | break; |
| 970 | case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT: |
| 971 | if (!transport->ep_disconnect) |
| 972 | return -EINVAL; |
| 973 | |
| 974 | transport->ep_disconnect(ev->u.ep_disconnect.ep_handle); |
| 975 | break; |
| 976 | } |
| 977 | return rc; |
| 978 | } |
| 979 | |
| 980 | static int |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 981 | iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh) |
| 982 | { |
| 983 | int err = 0; |
| 984 | struct iscsi_uevent *ev = NLMSG_DATA(nlh); |
| 985 | struct iscsi_transport *transport = NULL; |
| 986 | struct iscsi_internal *priv; |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 987 | struct iscsi_cls_session *session; |
| 988 | struct iscsi_cls_conn *conn; |
Mike Christie | 7996a77 | 2006-04-06 21:13:41 -0500 | [diff] [blame] | 989 | unsigned long flags; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 990 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 991 | priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle)); |
| 992 | if (!priv) |
| 993 | return -EINVAL; |
| 994 | transport = priv->iscsi_transport; |
| 995 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 996 | if (!try_module_get(transport->owner)) |
| 997 | return -EINVAL; |
| 998 | |
Mike Christie | 790f39a | 2006-05-18 20:31:39 -0500 | [diff] [blame] | 999 | priv->daemon_pid = NETLINK_CREDS(skb)->pid; |
| 1000 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1001 | switch (nlh->nlmsg_type) { |
| 1002 | case ISCSI_UEVENT_CREATE_SESSION: |
| 1003 | err = iscsi_if_create_session(priv, ev); |
| 1004 | break; |
| 1005 | case ISCSI_UEVENT_DESTROY_SESSION: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1006 | session = iscsi_session_lookup(ev->u.d_session.sid); |
Mike Christie | 7996a77 | 2006-04-06 21:13:41 -0500 | [diff] [blame] | 1007 | if (session) { |
| 1008 | spin_lock_irqsave(&sesslock, flags); |
| 1009 | list_del(&session->sess_list); |
| 1010 | spin_unlock_irqrestore(&sesslock, flags); |
| 1011 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1012 | transport->destroy_session(session); |
Mike Christie | 7996a77 | 2006-04-06 21:13:41 -0500 | [diff] [blame] | 1013 | } else |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1014 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1015 | break; |
| 1016 | case ISCSI_UEVENT_CREATE_CONN: |
| 1017 | err = iscsi_if_create_conn(transport, ev); |
| 1018 | break; |
| 1019 | case ISCSI_UEVENT_DESTROY_CONN: |
| 1020 | err = iscsi_if_destroy_conn(transport, ev); |
| 1021 | break; |
| 1022 | case ISCSI_UEVENT_BIND_CONN: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1023 | session = iscsi_session_lookup(ev->u.b_conn.sid); |
| 1024 | 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] | 1025 | |
| 1026 | if (session && conn) |
| 1027 | ev->r.retcode = transport->bind_conn(session, conn, |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1028 | ev->u.b_conn.transport_eph, |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1029 | ev->u.b_conn.is_leading); |
| 1030 | else |
| 1031 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1032 | break; |
| 1033 | case ISCSI_UEVENT_SET_PARAM: |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1034 | err = iscsi_set_param(transport, ev); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1035 | break; |
| 1036 | case ISCSI_UEVENT_START_CONN: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1037 | 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] | 1038 | if (conn) |
| 1039 | ev->r.retcode = transport->start_conn(conn); |
| 1040 | else |
| 1041 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1042 | break; |
| 1043 | case ISCSI_UEVENT_STOP_CONN: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1044 | 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] | 1045 | if (conn) |
| 1046 | transport->stop_conn(conn, ev->u.stop_conn.flag); |
| 1047 | else |
| 1048 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1049 | break; |
| 1050 | case ISCSI_UEVENT_SEND_PDU: |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1051 | 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] | 1052 | if (conn) |
| 1053 | ev->r.retcode = transport->send_pdu(conn, |
| 1054 | (struct iscsi_hdr*)((char*)ev + sizeof(*ev)), |
| 1055 | (char*)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size, |
| 1056 | ev->u.send_pdu.data_size); |
| 1057 | else |
| 1058 | err = -EINVAL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1059 | break; |
| 1060 | case ISCSI_UEVENT_GET_STATS: |
Mike Christie | 5b940ad | 2006-02-01 21:06:56 -0600 | [diff] [blame] | 1061 | err = iscsi_if_get_stats(transport, nlh); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1062 | break; |
Or Gerlitz | 264faaa | 2006-05-02 19:46:36 -0500 | [diff] [blame] | 1063 | case ISCSI_UEVENT_TRANSPORT_EP_CONNECT: |
| 1064 | case ISCSI_UEVENT_TRANSPORT_EP_POLL: |
| 1065 | case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT: |
| 1066 | err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type); |
| 1067 | break; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1068 | default: |
| 1069 | err = -EINVAL; |
| 1070 | break; |
| 1071 | } |
| 1072 | |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1073 | module_put(transport->owner); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1074 | return err; |
| 1075 | } |
| 1076 | |
Mike Christie | b5c7a12 | 2006-04-06 21:13:33 -0500 | [diff] [blame] | 1077 | /* |
| 1078 | * Get message from skb (based on rtnetlink_rcv_skb). Each message is |
| 1079 | * processed by iscsi_if_recv_msg. Malformed skbs with wrong lengths or |
| 1080 | * invalid creds are discarded silently. |
| 1081 | */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1082 | static void |
| 1083 | iscsi_if_rx(struct sock *sk, int len) |
| 1084 | { |
| 1085 | struct sk_buff *skb; |
| 1086 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 1087 | mutex_lock(&rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1088 | while ((skb = skb_dequeue(&sk->sk_receive_queue)) != NULL) { |
Mike Christie | ee7f8e4 | 2006-02-01 21:07:01 -0600 | [diff] [blame] | 1089 | if (NETLINK_CREDS(skb)->uid) { |
| 1090 | skb_pull(skb, skb->len); |
| 1091 | goto free_skb; |
| 1092 | } |
Mike Christie | ee7f8e4 | 2006-02-01 21:07:01 -0600 | [diff] [blame] | 1093 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1094 | while (skb->len >= NLMSG_SPACE(0)) { |
| 1095 | int err; |
| 1096 | uint32_t rlen; |
| 1097 | struct nlmsghdr *nlh; |
| 1098 | struct iscsi_uevent *ev; |
| 1099 | |
| 1100 | nlh = (struct nlmsghdr *)skb->data; |
| 1101 | if (nlh->nlmsg_len < sizeof(*nlh) || |
| 1102 | skb->len < nlh->nlmsg_len) { |
| 1103 | break; |
| 1104 | } |
Mike Christie | ee7f8e4 | 2006-02-01 21:07:01 -0600 | [diff] [blame] | 1105 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1106 | ev = NLMSG_DATA(nlh); |
| 1107 | rlen = NLMSG_ALIGN(nlh->nlmsg_len); |
| 1108 | if (rlen > skb->len) |
| 1109 | rlen = skb->len; |
Mike Christie | ee7f8e4 | 2006-02-01 21:07:01 -0600 | [diff] [blame] | 1110 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1111 | err = iscsi_if_recv_msg(skb, nlh); |
| 1112 | if (err) { |
| 1113 | ev->type = ISCSI_KEVENT_IF_ERROR; |
| 1114 | ev->iferror = err; |
| 1115 | } |
| 1116 | do { |
| 1117 | /* |
| 1118 | * special case for GET_STATS: |
| 1119 | * on success - sending reply and stats from |
| 1120 | * inside of if_recv_msg(), |
| 1121 | * on error - fall through. |
| 1122 | */ |
| 1123 | if (ev->type == ISCSI_UEVENT_GET_STATS && !err) |
| 1124 | break; |
| 1125 | err = iscsi_if_send_reply( |
| 1126 | NETLINK_CREDS(skb)->pid, nlh->nlmsg_seq, |
| 1127 | nlh->nlmsg_type, 0, 0, ev, sizeof(*ev)); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1128 | if (atomic_read(&z_reply->allocated) >= |
| 1129 | z_reply->hiwat) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1130 | ev->iferror = -ENOMEM; |
| 1131 | } while (err < 0 && err != -ECONNREFUSED); |
| 1132 | skb_pull(skb, rlen); |
| 1133 | } |
Mike Christie | ee7f8e4 | 2006-02-01 21:07:01 -0600 | [diff] [blame] | 1134 | free_skb: |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1135 | kfree_skb(skb); |
| 1136 | } |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 1137 | mutex_unlock(&rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1140 | #define iscsi_cdev_to_conn(_cdev) \ |
| 1141 | iscsi_dev_to_conn(_cdev->dev) |
| 1142 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1143 | #define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \ |
| 1144 | struct class_device_attribute class_device_attr_##_prefix##_##_name = \ |
| 1145 | __ATTR(_name,_mode,_show,_store) |
| 1146 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1147 | /* |
| 1148 | * iSCSI connection attrs |
| 1149 | */ |
| 1150 | #define iscsi_conn_int_attr_show(param, format) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | static ssize_t \ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1152 | show_conn_int_param_##param(struct class_device *cdev, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | { \ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1154 | uint32_t value = 0; \ |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1155 | struct iscsi_cls_conn *conn = iscsi_cdev_to_conn(cdev); \ |
| 1156 | struct iscsi_transport *t = conn->transport; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1157 | \ |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1158 | t->get_conn_param(conn, param, &value); \ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1159 | return snprintf(buf, 20, format"\n", value); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | } |
| 1161 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1162 | #define iscsi_conn_int_attr(field, param, format) \ |
| 1163 | iscsi_conn_int_attr_show(param, format) \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1164 | static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_int_param_##param, \ |
| 1165 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1167 | iscsi_conn_int_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH, "%u"); |
| 1168 | iscsi_conn_int_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH, "%u"); |
| 1169 | iscsi_conn_int_attr(header_digest, ISCSI_PARAM_HDRDGST_EN, "%d"); |
| 1170 | iscsi_conn_int_attr(data_digest, ISCSI_PARAM_DATADGST_EN, "%d"); |
| 1171 | iscsi_conn_int_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN, "%d"); |
| 1172 | iscsi_conn_int_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN, "%d"); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1173 | iscsi_conn_int_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT, "%d"); |
| 1174 | iscsi_conn_int_attr(port, ISCSI_PARAM_CONN_PORT, "%d"); |
Mike Christie | 8d2860b | 2006-05-02 19:46:47 -0500 | [diff] [blame] | 1175 | iscsi_conn_int_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN, "%u"); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1176 | |
| 1177 | #define iscsi_conn_str_attr_show(param) \ |
| 1178 | static ssize_t \ |
| 1179 | show_conn_str_param_##param(struct class_device *cdev, char *buf) \ |
| 1180 | { \ |
| 1181 | struct iscsi_cls_conn *conn = iscsi_cdev_to_conn(cdev); \ |
| 1182 | struct iscsi_transport *t = conn->transport; \ |
| 1183 | return t->get_conn_str_param(conn, param, buf); \ |
| 1184 | } |
| 1185 | |
| 1186 | #define iscsi_conn_str_attr(field, param) \ |
| 1187 | iscsi_conn_str_attr_show(param) \ |
| 1188 | static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_str_param_##param, \ |
| 1189 | NULL); |
| 1190 | |
| 1191 | iscsi_conn_str_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS); |
| 1192 | iscsi_conn_str_attr(address, ISCSI_PARAM_CONN_ADDRESS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1194 | #define iscsi_cdev_to_session(_cdev) \ |
| 1195 | iscsi_dev_to_session(_cdev->dev) |
| 1196 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | /* |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1198 | * iSCSI session attrs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | */ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1200 | #define iscsi_session_int_attr_show(param, format) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | static ssize_t \ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1202 | show_session_int_param_##param(struct class_device *cdev, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | { \ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1204 | uint32_t value = 0; \ |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1205 | struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev); \ |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1206 | struct iscsi_transport *t = session->transport; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | \ |
Mike Christie | 7b7232f | 2006-02-01 21:06:49 -0600 | [diff] [blame] | 1208 | t->get_session_param(session, param, &value); \ |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1209 | return snprintf(buf, 20, format"\n", value); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1212 | #define iscsi_session_int_attr(field, param, format) \ |
| 1213 | iscsi_session_int_attr_show(param, format) \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1214 | static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_int_param_##param, \ |
| 1215 | NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1217 | iscsi_session_int_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, "%d"); |
| 1218 | iscsi_session_int_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, "%hu"); |
| 1219 | iscsi_session_int_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, "%d"); |
| 1220 | iscsi_session_int_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, "%u"); |
| 1221 | iscsi_session_int_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, "%u"); |
| 1222 | iscsi_session_int_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, "%d"); |
| 1223 | iscsi_session_int_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, "%d"); |
| 1224 | iscsi_session_int_attr(erl, ISCSI_PARAM_ERL, "%d"); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1225 | iscsi_session_int_attr(tpgt, ISCSI_PARAM_TPGT, "%d"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1227 | #define iscsi_session_str_attr_show(param) \ |
| 1228 | static ssize_t \ |
| 1229 | show_session_str_param_##param(struct class_device *cdev, char *buf) \ |
| 1230 | { \ |
| 1231 | struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev); \ |
| 1232 | struct iscsi_transport *t = session->transport; \ |
| 1233 | return t->get_session_str_param(session, param, buf); \ |
| 1234 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1236 | #define iscsi_session_str_attr(field, param) \ |
| 1237 | iscsi_session_str_attr_show(param) \ |
| 1238 | static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_str_param_##param, \ |
| 1239 | NULL); |
| 1240 | |
| 1241 | iscsi_session_str_attr(targetname, ISCSI_PARAM_TARGET_NAME); |
| 1242 | |
| 1243 | /* |
| 1244 | * Private session and conn attrs. userspace uses several iscsi values |
| 1245 | * to identify each session between reboots. Some of these values may not |
| 1246 | * be present in the iscsi_transport/LLD driver becuase userspace handles |
| 1247 | * login (and failback for login redirect) so for these type of drivers |
| 1248 | * the class manages the attrs and values for the iscsi_transport/LLD |
| 1249 | */ |
| 1250 | #define iscsi_priv_session_attr_show(field, format) \ |
| 1251 | static ssize_t \ |
| 1252 | show_priv_session_##field(struct class_device *cdev, char *buf) \ |
| 1253 | { \ |
| 1254 | struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev); \ |
| 1255 | return sprintf(buf, format"\n", session->field); \ |
| 1256 | } |
| 1257 | |
| 1258 | #define iscsi_priv_session_attr(field, format) \ |
| 1259 | iscsi_priv_session_attr_show(field, format) \ |
| 1260 | static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO, show_priv_session_##field, \ |
| 1261 | NULL) |
| 1262 | iscsi_priv_session_attr(targetname, "%s"); |
| 1263 | iscsi_priv_session_attr(tpgt, "%d"); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1264 | iscsi_priv_session_attr(recovery_tmo, "%d"); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1265 | |
| 1266 | #define iscsi_priv_conn_attr_show(field, format) \ |
| 1267 | static ssize_t \ |
| 1268 | show_priv_conn_##field(struct class_device *cdev, char *buf) \ |
| 1269 | { \ |
| 1270 | struct iscsi_cls_conn *conn = iscsi_cdev_to_conn(cdev); \ |
| 1271 | return sprintf(buf, format"\n", conn->field); \ |
| 1272 | } |
| 1273 | |
| 1274 | #define iscsi_priv_conn_attr(field, format) \ |
| 1275 | iscsi_priv_conn_attr_show(field, format) \ |
| 1276 | static ISCSI_CLASS_ATTR(priv_conn, field, S_IRUGO, show_priv_conn_##field, \ |
| 1277 | NULL) |
| 1278 | iscsi_priv_conn_attr(persistent_address, "%s"); |
| 1279 | iscsi_priv_conn_attr(persistent_port, "%d"); |
| 1280 | |
| 1281 | #define SETUP_PRIV_SESSION_RD_ATTR(field) \ |
| 1282 | do { \ |
| 1283 | priv->session_attrs[count] = &class_device_attr_priv_sess_##field; \ |
| 1284 | count++; \ |
| 1285 | } while (0) |
| 1286 | |
| 1287 | #define SETUP_SESSION_RD_ATTR(field, param_flag) \ |
| 1288 | do { \ |
| 1289 | if (tt->param_mask & param_flag) { \ |
| 1290 | priv->session_attrs[count] = &class_device_attr_sess_##field; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | count++; \ |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1292 | } \ |
| 1293 | } while (0) |
| 1294 | |
| 1295 | #define SETUP_PRIV_CONN_RD_ATTR(field) \ |
| 1296 | do { \ |
| 1297 | priv->conn_attrs[count] = &class_device_attr_priv_conn_##field; \ |
| 1298 | count++; \ |
| 1299 | } while (0) |
| 1300 | |
| 1301 | #define SETUP_CONN_RD_ATTR(field, param_flag) \ |
| 1302 | do { \ |
| 1303 | if (tt->param_mask & param_flag) { \ |
| 1304 | priv->conn_attrs[count] = &class_device_attr_conn_##field; \ |
| 1305 | count++; \ |
| 1306 | } \ |
| 1307 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1309 | static int iscsi_session_match(struct attribute_container *cont, |
| 1310 | struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1312 | struct iscsi_cls_session *session; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | struct Scsi_Host *shost; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1314 | struct iscsi_internal *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1316 | if (!iscsi_is_session_dev(dev)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | return 0; |
| 1318 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1319 | session = iscsi_dev_to_session(dev); |
| 1320 | shost = iscsi_session_to_shost(session); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1321 | if (!shost->transportt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1322 | return 0; |
| 1323 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1324 | priv = to_iscsi_internal(shost->transportt); |
| 1325 | if (priv->session_cont.ac.class != &iscsi_session_class.class) |
| 1326 | return 0; |
| 1327 | |
| 1328 | return &priv->session_cont.ac == cont; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1331 | static int iscsi_conn_match(struct attribute_container *cont, |
| 1332 | struct device *dev) |
| 1333 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1334 | struct iscsi_cls_session *session; |
| 1335 | struct iscsi_cls_conn *conn; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1336 | struct Scsi_Host *shost; |
| 1337 | struct iscsi_internal *priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1339 | if (!iscsi_is_conn_dev(dev)) |
| 1340 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1342 | conn = iscsi_dev_to_conn(dev); |
| 1343 | session = iscsi_dev_to_session(conn->dev.parent); |
| 1344 | shost = iscsi_session_to_shost(session); |
| 1345 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1346 | if (!shost->transportt) |
| 1347 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1349 | priv = to_iscsi_internal(shost->transportt); |
| 1350 | if (priv->conn_cont.ac.class != &iscsi_connection_class.class) |
| 1351 | return 0; |
| 1352 | |
| 1353 | return &priv->conn_cont.ac == cont; |
| 1354 | } |
| 1355 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1356 | static int iscsi_host_match(struct attribute_container *cont, |
| 1357 | struct device *dev) |
| 1358 | { |
| 1359 | struct Scsi_Host *shost; |
| 1360 | struct iscsi_internal *priv; |
| 1361 | |
| 1362 | if (!scsi_is_host_device(dev)) |
| 1363 | return 0; |
| 1364 | |
| 1365 | shost = dev_to_shost(dev); |
| 1366 | if (!shost->transportt || |
| 1367 | shost->transportt->host_attrs.ac.class != &iscsi_host_class.class) |
| 1368 | return 0; |
| 1369 | |
| 1370 | priv = to_iscsi_internal(shost->transportt); |
| 1371 | return &priv->t.host_attrs.ac == cont; |
| 1372 | } |
| 1373 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1374 | struct scsi_transport_template * |
| 1375 | iscsi_register_transport(struct iscsi_transport *tt) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1376 | { |
| 1377 | struct iscsi_internal *priv; |
| 1378 | unsigned long flags; |
| 1379 | int count = 0, err; |
| 1380 | |
| 1381 | BUG_ON(!tt); |
| 1382 | |
| 1383 | priv = iscsi_if_transport_lookup(tt); |
| 1384 | if (priv) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1385 | return NULL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1386 | |
Jes Sorensen | 24669f75 | 2006-01-16 10:31:18 -0500 | [diff] [blame] | 1387 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1388 | if (!priv) |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1389 | return NULL; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1390 | INIT_LIST_HEAD(&priv->list); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1391 | priv->iscsi_transport = tt; |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1392 | priv->t.user_scan = iscsi_user_scan; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1393 | |
| 1394 | priv->cdev.class = &iscsi_transport_class; |
| 1395 | snprintf(priv->cdev.class_id, BUS_ID_SIZE, "%s", tt->name); |
| 1396 | err = class_device_register(&priv->cdev); |
| 1397 | if (err) |
| 1398 | goto free_priv; |
| 1399 | |
| 1400 | err = sysfs_create_group(&priv->cdev.kobj, &iscsi_transport_group); |
| 1401 | if (err) |
| 1402 | goto unregister_cdev; |
| 1403 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1404 | /* host parameters */ |
| 1405 | priv->t.host_attrs.ac.attrs = &priv->host_attrs[0]; |
| 1406 | priv->t.host_attrs.ac.class = &iscsi_host_class.class; |
| 1407 | priv->t.host_attrs.ac.match = iscsi_host_match; |
| 1408 | priv->t.host_size = sizeof(struct iscsi_host); |
| 1409 | priv->host_attrs[0] = NULL; |
| 1410 | transport_container_register(&priv->t.host_attrs); |
| 1411 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1412 | /* connection parameters */ |
| 1413 | priv->conn_cont.ac.attrs = &priv->conn_attrs[0]; |
| 1414 | priv->conn_cont.ac.class = &iscsi_connection_class.class; |
| 1415 | priv->conn_cont.ac.match = iscsi_conn_match; |
| 1416 | transport_container_register(&priv->conn_cont); |
| 1417 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1418 | SETUP_CONN_RD_ATTR(max_recv_dlength, ISCSI_MAX_RECV_DLENGTH); |
| 1419 | SETUP_CONN_RD_ATTR(max_xmit_dlength, ISCSI_MAX_XMIT_DLENGTH); |
| 1420 | SETUP_CONN_RD_ATTR(header_digest, ISCSI_HDRDGST_EN); |
| 1421 | SETUP_CONN_RD_ATTR(data_digest, ISCSI_DATADGST_EN); |
| 1422 | SETUP_CONN_RD_ATTR(ifmarker, ISCSI_IFMARKER_EN); |
| 1423 | SETUP_CONN_RD_ATTR(ofmarker, ISCSI_OFMARKER_EN); |
| 1424 | SETUP_CONN_RD_ATTR(address, ISCSI_CONN_ADDRESS); |
| 1425 | SETUP_CONN_RD_ATTR(port, ISCSI_CONN_PORT); |
Mike Christie | 8d2860b | 2006-05-02 19:46:47 -0500 | [diff] [blame] | 1426 | SETUP_CONN_RD_ATTR(exp_statsn, ISCSI_EXP_STATSN); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1427 | |
| 1428 | if (tt->param_mask & ISCSI_PERSISTENT_ADDRESS) |
| 1429 | SETUP_CONN_RD_ATTR(persistent_address, ISCSI_PERSISTENT_ADDRESS); |
| 1430 | else |
| 1431 | SETUP_PRIV_CONN_RD_ATTR(persistent_address); |
| 1432 | |
| 1433 | if (tt->param_mask & ISCSI_PERSISTENT_PORT) |
| 1434 | SETUP_CONN_RD_ATTR(persistent_port, ISCSI_PERSISTENT_PORT); |
| 1435 | else |
| 1436 | SETUP_PRIV_CONN_RD_ATTR(persistent_port); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1437 | |
| 1438 | BUG_ON(count > ISCSI_CONN_ATTRS); |
| 1439 | priv->conn_attrs[count] = NULL; |
| 1440 | count = 0; |
| 1441 | |
| 1442 | /* session parameters */ |
| 1443 | priv->session_cont.ac.attrs = &priv->session_attrs[0]; |
| 1444 | priv->session_cont.ac.class = &iscsi_session_class.class; |
| 1445 | priv->session_cont.ac.match = iscsi_session_match; |
| 1446 | transport_container_register(&priv->session_cont); |
| 1447 | |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1448 | SETUP_SESSION_RD_ATTR(initial_r2t, ISCSI_INITIAL_R2T_EN); |
| 1449 | SETUP_SESSION_RD_ATTR(max_outstanding_r2t, ISCSI_MAX_R2T); |
| 1450 | SETUP_SESSION_RD_ATTR(immediate_data, ISCSI_IMM_DATA_EN); |
| 1451 | SETUP_SESSION_RD_ATTR(first_burst_len, ISCSI_FIRST_BURST); |
| 1452 | SETUP_SESSION_RD_ATTR(max_burst_len, ISCSI_MAX_BURST); |
| 1453 | SETUP_SESSION_RD_ATTR(data_pdu_in_order, ISCSI_PDU_INORDER_EN); |
| 1454 | SETUP_SESSION_RD_ATTR(data_seq_in_order, ISCSI_DATASEQ_INORDER_EN); |
| 1455 | SETUP_SESSION_RD_ATTR(erl, ISCSI_ERL); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1456 | SETUP_PRIV_SESSION_RD_ATTR(recovery_tmo); |
Mike Christie | fd7255f | 2006-04-06 21:13:36 -0500 | [diff] [blame] | 1457 | |
| 1458 | if (tt->param_mask & ISCSI_TARGET_NAME) |
| 1459 | SETUP_SESSION_RD_ATTR(targetname, ISCSI_TARGET_NAME); |
| 1460 | else |
| 1461 | SETUP_PRIV_SESSION_RD_ATTR(targetname); |
| 1462 | |
| 1463 | if (tt->param_mask & ISCSI_TPGT) |
| 1464 | SETUP_SESSION_RD_ATTR(tpgt, ISCSI_TPGT); |
| 1465 | else |
| 1466 | SETUP_PRIV_SESSION_RD_ATTR(tpgt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | |
| 1468 | BUG_ON(count > ISCSI_SESSION_ATTRS); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1469 | priv->session_attrs[count] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1471 | spin_lock_irqsave(&iscsi_transport_lock, flags); |
| 1472 | list_add(&priv->list, &iscsi_transports); |
| 1473 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1475 | printk(KERN_NOTICE "iscsi: registered transport (%s)\n", tt->name); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1476 | return &priv->t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1478 | unregister_cdev: |
| 1479 | class_device_unregister(&priv->cdev); |
| 1480 | free_priv: |
| 1481 | kfree(priv); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1482 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | } |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1484 | EXPORT_SYMBOL_GPL(iscsi_register_transport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1486 | int iscsi_unregister_transport(struct iscsi_transport *tt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | { |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1488 | struct iscsi_internal *priv; |
| 1489 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1491 | BUG_ON(!tt); |
| 1492 | |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 1493 | mutex_lock(&rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1494 | |
| 1495 | priv = iscsi_if_transport_lookup(tt); |
| 1496 | BUG_ON (!priv); |
| 1497 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1498 | spin_lock_irqsave(&iscsi_transport_lock, flags); |
| 1499 | list_del(&priv->list); |
| 1500 | spin_unlock_irqrestore(&iscsi_transport_lock, flags); |
| 1501 | |
| 1502 | transport_container_unregister(&priv->conn_cont); |
| 1503 | transport_container_unregister(&priv->session_cont); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1504 | transport_container_unregister(&priv->t.host_attrs); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1505 | |
| 1506 | sysfs_remove_group(&priv->cdev.kobj, &iscsi_transport_group); |
| 1507 | class_device_unregister(&priv->cdev); |
Arjan van de Ven | 0b95067 | 2006-01-11 13:16:10 +0100 | [diff] [blame] | 1508 | mutex_unlock(&rx_queue_mutex); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1509 | |
| 1510 | return 0; |
| 1511 | } |
| 1512 | EXPORT_SYMBOL_GPL(iscsi_unregister_transport); |
| 1513 | |
| 1514 | static int |
| 1515 | iscsi_rcv_nl_event(struct notifier_block *this, unsigned long event, void *ptr) |
| 1516 | { |
| 1517 | struct netlink_notify *n = ptr; |
| 1518 | |
| 1519 | if (event == NETLINK_URELEASE && |
| 1520 | n->protocol == NETLINK_ISCSI && n->pid) { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1521 | struct iscsi_cls_conn *conn; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1522 | unsigned long flags; |
| 1523 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1524 | mempool_zone_complete(z_reply); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1525 | spin_lock_irqsave(&connlock, flags); |
| 1526 | list_for_each_entry(conn, &connlist, conn_list) { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1527 | mempool_zone_complete(conn->z_error); |
| 1528 | mempool_zone_complete(conn->z_pdu); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1529 | } |
| 1530 | spin_unlock_irqrestore(&connlock, flags); |
| 1531 | } |
| 1532 | |
| 1533 | return NOTIFY_DONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | } |
| 1535 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1536 | static struct notifier_block iscsi_nl_notifier = { |
| 1537 | .notifier_call = iscsi_rcv_nl_event, |
| 1538 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1539 | |
| 1540 | static __init int iscsi_transport_init(void) |
| 1541 | { |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1542 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1544 | err = class_register(&iscsi_transport_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | if (err) |
| 1546 | return err; |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1547 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1548 | err = transport_class_register(&iscsi_host_class); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1549 | if (err) |
| 1550 | goto unregister_transport_class; |
| 1551 | |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1552 | err = transport_class_register(&iscsi_connection_class); |
| 1553 | if (err) |
| 1554 | goto unregister_host_class; |
| 1555 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1556 | err = transport_class_register(&iscsi_session_class); |
| 1557 | if (err) |
| 1558 | goto unregister_conn_class; |
| 1559 | |
| 1560 | err = netlink_register_notifier(&iscsi_nl_notifier); |
| 1561 | if (err) |
| 1562 | goto unregister_session_class; |
| 1563 | |
James Bottomley | 2290d2b | 2005-09-08 10:14:11 -0500 | [diff] [blame] | 1564 | nls = netlink_kernel_create(NETLINK_ISCSI, 1, iscsi_if_rx, |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1565 | THIS_MODULE); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1566 | if (!nls) { |
| 1567 | err = -ENOBUFS; |
| 1568 | goto unregister_notifier; |
| 1569 | } |
| 1570 | |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1571 | z_reply = mempool_zone_init(Z_MAX_REPLY, |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1572 | NLMSG_SPACE(sizeof(struct iscsi_uevent)), Z_HIWAT_REPLY); |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1573 | if (z_reply) |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1574 | return 0; |
| 1575 | |
| 1576 | sock_release(nls->sk_socket); |
| 1577 | unregister_notifier: |
| 1578 | netlink_unregister_notifier(&iscsi_nl_notifier); |
| 1579 | unregister_session_class: |
| 1580 | transport_class_unregister(&iscsi_session_class); |
| 1581 | unregister_conn_class: |
| 1582 | transport_class_unregister(&iscsi_connection_class); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1583 | unregister_host_class: |
| 1584 | transport_class_unregister(&iscsi_host_class); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1585 | unregister_transport_class: |
| 1586 | class_unregister(&iscsi_transport_class); |
| 1587 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | static void __exit iscsi_transport_exit(void) |
| 1591 | { |
Mike Christie | 7b8631b | 2006-01-13 18:05:50 -0600 | [diff] [blame] | 1592 | mempool_zone_destroy(z_reply); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1593 | sock_release(nls->sk_socket); |
| 1594 | netlink_unregister_notifier(&iscsi_nl_notifier); |
| 1595 | transport_class_unregister(&iscsi_connection_class); |
| 1596 | transport_class_unregister(&iscsi_session_class); |
Mike Christie | 30a6c65 | 2006-04-06 21:13:39 -0500 | [diff] [blame] | 1597 | transport_class_unregister(&iscsi_host_class); |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1598 | class_unregister(&iscsi_transport_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | module_init(iscsi_transport_init); |
| 1602 | module_exit(iscsi_transport_exit); |
| 1603 | |
Alex Aizman | 0896b75 | 2005-08-04 19:33:07 -0700 | [diff] [blame] | 1604 | MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, " |
| 1605 | "Dmitry Yusupov <dmitry_yus@yahoo.com>, " |
| 1606 | "Alex Aizman <itn780@yahoo.com>"); |
| 1607 | MODULE_DESCRIPTION("iSCSI Transport Interface"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | MODULE_LICENSE("GPL"); |