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