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