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