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