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