blob: bc0f74d4ea09f547ebbac93cac6aa7123cef85a3 [file] [log] [blame]
Alex Aizman0896b752005-08-04 19:33:07 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * iSCSI transport class definitions
3 *
4 * Copyright (C) IBM Corporation, 2004
Alex Aizman0896b752005-08-04 19:33:07 -07005 * Copyright (C) Mike Christie, 2004 - 2005
6 * Copyright (C) Dmitry Yusupov, 2004 - 2005
7 * Copyright (C) Alex Aizman, 2004 - 2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
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 Ven0b950672006-01-11 13:16:10 +010024#include <linux/mutex.h>
Alex Aizman0896b752005-08-04 19:33:07 -070025#include <net/tcp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#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 Aizman0896b752005-08-04 19:33:07 -070031#include <scsi/iscsi_if.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Mike Christie88dfd342008-05-21 15:54:16 -050033#define ISCSI_SESSION_ATTRS 21
Mike Christiec238c3b2008-01-31 13:36:51 -060034#define ISCSI_CONN_ATTRS 13
Mike Christied8196ed2007-05-30 12:57:25 -050035#define ISCSI_HOST_ATTRS 4
Mike Christied82ff9be2008-05-21 15:54:13 -050036
Mike Christie31ed0bf2008-02-26 12:35:23 -060037#define ISCSI_TRANSPORT_VERSION "2.0-869"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
39struct iscsi_internal {
Mike Christie790f39a2006-05-18 20:31:39 -050040 int daemon_pid;
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 struct scsi_transport_template t;
Alex Aizman0896b752005-08-04 19:33:07 -070042 struct iscsi_transport *iscsi_transport;
43 struct list_head list;
Tony Jonesee959b02008-02-22 00:13:36 +010044 struct device dev;
Mike Christie30a6c652006-04-06 21:13:39 -050045
Tony Jonesee959b02008-02-22 00:13:36 +010046 struct device_attribute *host_attrs[ISCSI_HOST_ATTRS + 1];
Alex Aizman0896b752005-08-04 19:33:07 -070047 struct transport_container conn_cont;
Tony Jonesee959b02008-02-22 00:13:36 +010048 struct device_attribute *conn_attrs[ISCSI_CONN_ATTRS + 1];
Alex Aizman0896b752005-08-04 19:33:07 -070049 struct transport_container session_cont;
Tony Jonesee959b02008-02-22 00:13:36 +010050 struct device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
Linus Torvalds1da177e2005-04-16 15:20:36 -070051};
52
Mike Christie41be1442007-02-28 17:32:18 -060053static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
Mike Christied8bf5412007-12-13 12:43:27 -060054static struct workqueue_struct *iscsi_eh_timer_workq;
Mike Christieb5c7a122006-04-06 21:13:33 -050055
Alex Aizman0896b752005-08-04 19:33:07 -070056/*
57 * list of registered transports and lock that must
58 * be held while accessing list. The iscsi_transport_lock must
Arjan van de Ven0b950672006-01-11 13:16:10 +010059 * be acquired after the rx_queue_mutex.
Alex Aizman0896b752005-08-04 19:33:07 -070060 */
61static LIST_HEAD(iscsi_transports);
62static DEFINE_SPINLOCK(iscsi_transport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Alex Aizman0896b752005-08-04 19:33:07 -070064#define to_iscsi_internal(tmpl) \
65 container_of(tmpl, struct iscsi_internal, t)
66
Tony Jonesee959b02008-02-22 00:13:36 +010067#define dev_to_iscsi_internal(_dev) \
68 container_of(_dev, struct iscsi_internal, dev)
Alex Aizman0896b752005-08-04 19:33:07 -070069
Tony Jonesee959b02008-02-22 00:13:36 +010070static void iscsi_transport_release(struct device *dev)
Alex Aizman0896b752005-08-04 19:33:07 -070071{
Tony Jonesee959b02008-02-22 00:13:36 +010072 struct iscsi_internal *priv = dev_to_iscsi_internal(dev);
Alex Aizman0896b752005-08-04 19:33:07 -070073 kfree(priv);
74}
75
76/*
77 * iscsi_transport_class represents the iscsi_transports that are
78 * registered.
79 */
80static struct class iscsi_transport_class = {
81 .name = "iscsi_transport",
Tony Jonesee959b02008-02-22 00:13:36 +010082 .dev_release = iscsi_transport_release,
Alex Aizman0896b752005-08-04 19:33:07 -070083};
84
85static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +010086show_transport_handle(struct device *dev, struct device_attribute *attr,
87 char *buf)
Alex Aizman0896b752005-08-04 19:33:07 -070088{
Tony Jonesee959b02008-02-22 00:13:36 +010089 struct iscsi_internal *priv = dev_to_iscsi_internal(dev);
Mike Christie762e2bf2005-09-12 21:01:46 -050090 return sprintf(buf, "%llu\n", (unsigned long long)iscsi_handle(priv->iscsi_transport));
Alex Aizman0896b752005-08-04 19:33:07 -070091}
Tony Jonesee959b02008-02-22 00:13:36 +010092static DEVICE_ATTR(handle, S_IRUGO, show_transport_handle, NULL);
Alex Aizman0896b752005-08-04 19:33:07 -070093
94#define show_transport_attr(name, format) \
95static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +010096show_transport_##name(struct device *dev, \
97 struct device_attribute *attr,char *buf) \
Alex Aizman0896b752005-08-04 19:33:07 -070098{ \
Tony Jonesee959b02008-02-22 00:13:36 +010099 struct iscsi_internal *priv = dev_to_iscsi_internal(dev); \
Alex Aizman0896b752005-08-04 19:33:07 -0700100 return sprintf(buf, format"\n", priv->iscsi_transport->name); \
101} \
Tony Jonesee959b02008-02-22 00:13:36 +0100102static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL);
Alex Aizman0896b752005-08-04 19:33:07 -0700103
104show_transport_attr(caps, "0x%x");
Alex Aizman0896b752005-08-04 19:33:07 -0700105
106static struct attribute *iscsi_transport_attrs[] = {
Tony Jonesee959b02008-02-22 00:13:36 +0100107 &dev_attr_handle.attr,
108 &dev_attr_caps.attr,
Alex Aizman0896b752005-08-04 19:33:07 -0700109 NULL,
110};
111
112static struct attribute_group iscsi_transport_group = {
113 .attrs = iscsi_transport_attrs,
114};
115
Mike Christied82ff9be2008-05-21 15:54:13 -0500116/*
117 * iSCSI endpoint attrs
118 */
119#define iscsi_dev_to_endpoint(_dev) \
120 container_of(_dev, struct iscsi_endpoint, dev)
121
122#define ISCSI_ATTR(_prefix,_name,_mode,_show,_store) \
123struct device_attribute dev_attr_##_prefix##_##_name = \
124 __ATTR(_name,_mode,_show,_store)
125
126static void iscsi_endpoint_release(struct device *dev)
127{
128 struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
129 kfree(ep);
130}
131
132static struct class iscsi_endpoint_class = {
133 .name = "iscsi_endpoint",
134 .dev_release = iscsi_endpoint_release,
135};
136
137static ssize_t
138show_ep_handle(struct device *dev, struct device_attribute *attr, char *buf)
139{
140 struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
141 return sprintf(buf, "%u\n", ep->id);
142}
143static ISCSI_ATTR(ep, handle, S_IRUGO, show_ep_handle, NULL);
144
145static struct attribute *iscsi_endpoint_attrs[] = {
146 &dev_attr_ep_handle.attr,
147 NULL,
148};
149
150static struct attribute_group iscsi_endpoint_group = {
151 .attrs = iscsi_endpoint_attrs,
152};
153
154#define ISCSI_MAX_EPID -1
155
156static int iscsi_match_epid(struct device *dev, void *data)
157{
158 struct iscsi_endpoint *ep = iscsi_dev_to_endpoint(dev);
159 unsigned int *epid = (unsigned int *) data;
160
161 return *epid == ep->id;
162}
163
164struct iscsi_endpoint *
165iscsi_create_endpoint(int dd_size)
166{
167 struct device *dev;
168 struct iscsi_endpoint *ep;
169 unsigned int id;
170 int err;
171
172 for (id = 1; id < ISCSI_MAX_EPID; id++) {
173 dev = class_find_device(&iscsi_endpoint_class, &id,
174 iscsi_match_epid);
175 if (!dev)
176 break;
177 }
178 if (id == ISCSI_MAX_EPID) {
179 printk(KERN_ERR "Too many connections. Max supported %u\n",
180 ISCSI_MAX_EPID - 1);
181 return NULL;
182 }
183
184 ep = kzalloc(sizeof(*ep) + dd_size, GFP_KERNEL);
185 if (!ep)
186 return NULL;
187
188 ep->id = id;
189 ep->dev.class = &iscsi_endpoint_class;
190 snprintf(ep->dev.bus_id, BUS_ID_SIZE, "ep-%u", id);
191 err = device_register(&ep->dev);
192 if (err)
193 goto free_ep;
194
195 err = sysfs_create_group(&ep->dev.kobj, &iscsi_endpoint_group);
196 if (err)
197 goto unregister_dev;
198
199 if (dd_size)
200 ep->dd_data = &ep[1];
201 return ep;
202
203unregister_dev:
204 device_unregister(&ep->dev);
205 return NULL;
206
207free_ep:
208 kfree(ep);
209 return NULL;
210}
211EXPORT_SYMBOL_GPL(iscsi_create_endpoint);
212
213void iscsi_destroy_endpoint(struct iscsi_endpoint *ep)
214{
215 sysfs_remove_group(&ep->dev.kobj, &iscsi_endpoint_group);
216 device_unregister(&ep->dev);
217}
218EXPORT_SYMBOL_GPL(iscsi_destroy_endpoint);
219
220struct iscsi_endpoint *iscsi_lookup_endpoint(u64 handle)
221{
222 struct device *dev;
223
224 dev = class_find_device(&iscsi_endpoint_class, &handle,
225 iscsi_match_epid);
226 if (!dev)
227 return NULL;
228
229 return iscsi_dev_to_endpoint(dev);
230}
231EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint);
232
Mike Christie30a6c652006-04-06 21:13:39 -0500233static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
Tony Jonesee959b02008-02-22 00:13:36 +0100234 struct device *cdev)
Mike Christie30a6c652006-04-06 21:13:39 -0500235{
236 struct Scsi_Host *shost = dev_to_shost(dev);
Mike Christie32c6e1b2008-05-21 15:53:58 -0500237 struct iscsi_cls_host *ihost = shost->shost_data;
Mike Christie30a6c652006-04-06 21:13:39 -0500238
239 memset(ihost, 0, sizeof(*ihost));
Mike Christie8aae18a2008-01-31 13:36:48 -0600240 atomic_set(&ihost->nr_scans, 0);
Mike Christie79706342008-05-21 15:54:12 -0500241 mutex_init(&ihost->mutex);
Mike Christie26974782007-12-13 12:43:29 -0600242
Mike Christiebd976f62008-01-31 13:36:46 -0600243 snprintf(ihost->scan_workq_name, KOBJ_NAME_LEN, "iscsi_scan_%d",
Mike Christie26974782007-12-13 12:43:29 -0600244 shost->host_no);
Mike Christiebd976f62008-01-31 13:36:46 -0600245 ihost->scan_workq = create_singlethread_workqueue(
246 ihost->scan_workq_name);
247 if (!ihost->scan_workq)
Mike Christie26974782007-12-13 12:43:29 -0600248 return -ENOMEM;
249 return 0;
250}
251
252static int iscsi_remove_host(struct transport_container *tc, struct device *dev,
Tony Jonesee959b02008-02-22 00:13:36 +0100253 struct device *cdev)
Mike Christie26974782007-12-13 12:43:29 -0600254{
255 struct Scsi_Host *shost = dev_to_shost(dev);
Mike Christie32c6e1b2008-05-21 15:53:58 -0500256 struct iscsi_cls_host *ihost = shost->shost_data;
Mike Christie26974782007-12-13 12:43:29 -0600257
Mike Christiebd976f62008-01-31 13:36:46 -0600258 destroy_workqueue(ihost->scan_workq);
Mike Christie30a6c652006-04-06 21:13:39 -0500259 return 0;
260}
261
262static DECLARE_TRANSPORT_CLASS(iscsi_host_class,
263 "iscsi_host",
264 iscsi_setup_host,
Mike Christie26974782007-12-13 12:43:29 -0600265 iscsi_remove_host,
Mike Christie30a6c652006-04-06 21:13:39 -0500266 NULL);
267
Alex Aizman0896b752005-08-04 19:33:07 -0700268static DECLARE_TRANSPORT_CLASS(iscsi_session_class,
269 "iscsi_session",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 NULL,
271 NULL,
272 NULL);
273
Alex Aizman0896b752005-08-04 19:33:07 -0700274static DECLARE_TRANSPORT_CLASS(iscsi_connection_class,
275 "iscsi_connection",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 NULL,
277 NULL,
278 NULL);
Alex Aizman0896b752005-08-04 19:33:07 -0700279
280static struct sock *nls;
Arjan van de Ven0b950672006-01-11 13:16:10 +0100281static DEFINE_MUTEX(rx_queue_mutex);
Alex Aizman0896b752005-08-04 19:33:07 -0700282
Mike Christie7b7232f2006-02-01 21:06:49 -0600283static LIST_HEAD(sesslist);
284static DEFINE_SPINLOCK(sesslock);
Alex Aizman0896b752005-08-04 19:33:07 -0700285static LIST_HEAD(connlist);
286static DEFINE_SPINLOCK(connlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Mike Christieb5c7a122006-04-06 21:13:33 -0500288static uint32_t iscsi_conn_get_sid(struct iscsi_cls_conn *conn)
289{
290 struct iscsi_cls_session *sess = iscsi_dev_to_session(conn->dev.parent);
291 return sess->sid;
292}
293
294/*
295 * Returns the matching session to a given sid
296 */
297static struct iscsi_cls_session *iscsi_session_lookup(uint32_t sid)
Mike Christie7b7232f2006-02-01 21:06:49 -0600298{
299 unsigned long flags;
300 struct iscsi_cls_session *sess;
301
302 spin_lock_irqsave(&sesslock, flags);
303 list_for_each_entry(sess, &sesslist, sess_list) {
Mike Christieb5c7a122006-04-06 21:13:33 -0500304 if (sess->sid == sid) {
Mike Christie7b7232f2006-02-01 21:06:49 -0600305 spin_unlock_irqrestore(&sesslock, flags);
306 return sess;
307 }
308 }
309 spin_unlock_irqrestore(&sesslock, flags);
310 return NULL;
311}
312
Mike Christieb5c7a122006-04-06 21:13:33 -0500313/*
314 * Returns the matching connection to a given sid / cid tuple
315 */
316static struct iscsi_cls_conn *iscsi_conn_lookup(uint32_t sid, uint32_t cid)
Mike Christie7b7232f2006-02-01 21:06:49 -0600317{
318 unsigned long flags;
319 struct iscsi_cls_conn *conn;
320
321 spin_lock_irqsave(&connlock, flags);
322 list_for_each_entry(conn, &connlist, conn_list) {
Mike Christieb5c7a122006-04-06 21:13:33 -0500323 if ((conn->cid == cid) && (iscsi_conn_get_sid(conn) == sid)) {
Mike Christie7b7232f2006-02-01 21:06:49 -0600324 spin_unlock_irqrestore(&connlock, flags);
325 return conn;
326 }
327 }
328 spin_unlock_irqrestore(&connlock, flags);
329 return NULL;
330}
331
Mike Christie7b8631b2006-01-13 18:05:50 -0600332/*
333 * The following functions can be used by LLDs that allocate
334 * their own scsi_hosts or by software iscsi LLDs
335 */
Mike Christie6eabafb2008-01-31 13:36:43 -0600336static struct {
337 int value;
338 char *name;
339} iscsi_session_state_names[] = {
340 { ISCSI_SESSION_LOGGED_IN, "LOGGED_IN" },
341 { ISCSI_SESSION_FAILED, "FAILED" },
342 { ISCSI_SESSION_FREE, "FREE" },
343};
344
Adrian Bunk3b0f2082008-02-13 23:30:17 +0200345static const char *iscsi_session_state_name(int state)
Mike Christie6eabafb2008-01-31 13:36:43 -0600346{
347 int i;
348 char *name = NULL;
349
350 for (i = 0; i < ARRAY_SIZE(iscsi_session_state_names); i++) {
351 if (iscsi_session_state_names[i].value == state) {
352 name = iscsi_session_state_names[i].name;
353 break;
354 }
355 }
356 return name;
357}
358
359int iscsi_session_chkready(struct iscsi_cls_session *session)
360{
361 unsigned long flags;
362 int err;
363
364 spin_lock_irqsave(&session->lock, flags);
365 switch (session->state) {
366 case ISCSI_SESSION_LOGGED_IN:
367 err = 0;
368 break;
369 case ISCSI_SESSION_FAILED:
370 err = DID_IMM_RETRY << 16;
371 break;
372 case ISCSI_SESSION_FREE:
373 err = DID_NO_CONNECT << 16;
374 break;
375 default:
376 err = DID_NO_CONNECT << 16;
377 break;
378 }
379 spin_unlock_irqrestore(&session->lock, flags);
380 return err;
381}
382EXPORT_SYMBOL_GPL(iscsi_session_chkready);
383
Mike Christie7b8631b2006-01-13 18:05:50 -0600384static void iscsi_session_release(struct device *dev)
385{
386 struct iscsi_cls_session *session = iscsi_dev_to_session(dev);
Mike Christie7b8631b2006-01-13 18:05:50 -0600387 struct Scsi_Host *shost;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Mike Christie7b8631b2006-01-13 18:05:50 -0600389 shost = iscsi_session_to_shost(session);
390 scsi_host_put(shost);
391 kfree(session);
Mike Christie7b8631b2006-01-13 18:05:50 -0600392}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Mike Christie7b8631b2006-01-13 18:05:50 -0600394static int iscsi_is_session_dev(const struct device *dev)
395{
396 return dev->release == iscsi_session_release;
397}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Mike Christiea4804cd2008-05-21 15:54:00 -0500399static int iscsi_iter_session_fn(struct device *dev, void *data)
400{
401 void (* fn) (struct iscsi_cls_session *) = data;
402
403 if (!iscsi_is_session_dev(dev))
404 return 0;
405 fn(iscsi_dev_to_session(dev));
406 return 0;
407}
408
409void iscsi_host_for_each_session(struct Scsi_Host *shost,
410 void (*fn)(struct iscsi_cls_session *))
411{
412 device_for_each_child(&shost->shost_gendev, fn,
413 iscsi_iter_session_fn);
414}
415EXPORT_SYMBOL_GPL(iscsi_host_for_each_session);
416
Mike Christie8aae18a2008-01-31 13:36:48 -0600417/**
418 * iscsi_scan_finished - helper to report when running scans are done
419 * @shost: scsi host
420 * @time: scan run time
421 *
422 * This function can be used by drives like qla4xxx to report to the scsi
423 * layer when the scans it kicked off at module load time are done.
424 */
425int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time)
426{
Mike Christie32c6e1b2008-05-21 15:53:58 -0500427 struct iscsi_cls_host *ihost = shost->shost_data;
Mike Christie8aae18a2008-01-31 13:36:48 -0600428 /*
429 * qla4xxx will have kicked off some session unblocks before calling
430 * scsi_scan_host, so just wait for them to complete.
431 */
432 return !atomic_read(&ihost->nr_scans);
433}
434EXPORT_SYMBOL_GPL(iscsi_scan_finished);
435
Mike Christie79706342008-05-21 15:54:12 -0500436struct iscsi_scan_data {
437 unsigned int channel;
438 unsigned int id;
439 unsigned int lun;
440};
441
442static int iscsi_user_scan_session(struct device *dev, void *data)
443{
444 struct iscsi_scan_data *scan_data = data;
445 struct iscsi_cls_session *session;
446 struct Scsi_Host *shost;
447 struct iscsi_cls_host *ihost;
448 unsigned long flags;
449 unsigned int id;
450
451 if (!iscsi_is_session_dev(dev))
452 return 0;
453
454 session = iscsi_dev_to_session(dev);
455 shost = iscsi_session_to_shost(session);
456 ihost = shost->shost_data;
457
458 mutex_lock(&ihost->mutex);
459 spin_lock_irqsave(&session->lock, flags);
460 if (session->state != ISCSI_SESSION_LOGGED_IN) {
461 spin_unlock_irqrestore(&session->lock, flags);
462 mutex_unlock(&ihost->mutex);
463 return 0;
464 }
465 id = session->target_id;
466 spin_unlock_irqrestore(&session->lock, flags);
467
468 if (id != ISCSI_MAX_TARGET) {
469 if ((scan_data->channel == SCAN_WILD_CARD ||
470 scan_data->channel == 0) &&
471 (scan_data->id == SCAN_WILD_CARD ||
472 scan_data->id == id))
473 scsi_scan_target(&session->dev, 0, id,
474 scan_data->lun, 1);
475 }
476 mutex_unlock(&ihost->mutex);
477 return 0;
478}
479
Mike Christie30a6c652006-04-06 21:13:39 -0500480static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
481 uint id, uint lun)
482{
Mike Christie79706342008-05-21 15:54:12 -0500483 struct iscsi_scan_data scan_data;
Mike Christie30a6c652006-04-06 21:13:39 -0500484
Mike Christie79706342008-05-21 15:54:12 -0500485 scan_data.channel = channel;
486 scan_data.id = id;
487 scan_data.lun = lun;
Mike Christie30a6c652006-04-06 21:13:39 -0500488
Mike Christie79706342008-05-21 15:54:12 -0500489 return device_for_each_child(&shost->shost_gendev, &scan_data,
490 iscsi_user_scan_session);
Mike Christie30a6c652006-04-06 21:13:39 -0500491}
492
Mike Christiebd976f62008-01-31 13:36:46 -0600493static void iscsi_scan_session(struct work_struct *work)
494{
495 struct iscsi_cls_session *session =
496 container_of(work, struct iscsi_cls_session, scan_work);
Mike Christie8aae18a2008-01-31 13:36:48 -0600497 struct Scsi_Host *shost = iscsi_session_to_shost(session);
Mike Christie32c6e1b2008-05-21 15:53:58 -0500498 struct iscsi_cls_host *ihost = shost->shost_data;
Mike Christie79706342008-05-21 15:54:12 -0500499 struct iscsi_scan_data scan_data;
Mike Christiebd976f62008-01-31 13:36:46 -0600500
Mike Christie79706342008-05-21 15:54:12 -0500501 scan_data.channel = 0;
502 scan_data.id = SCAN_WILD_CARD;
503 scan_data.lun = SCAN_WILD_CARD;
Mike Christiebd976f62008-01-31 13:36:46 -0600504
Mike Christie79706342008-05-21 15:54:12 -0500505 iscsi_user_scan_session(&session->dev, &scan_data);
Mike Christie8aae18a2008-01-31 13:36:48 -0600506 atomic_dec(&ihost->nr_scans);
Mike Christiebd976f62008-01-31 13:36:46 -0600507}
508
David Howellsc4028952006-11-22 14:57:56 +0000509static void session_recovery_timedout(struct work_struct *work)
Mike Christie30a6c652006-04-06 21:13:39 -0500510{
David Howellsc4028952006-11-22 14:57:56 +0000511 struct iscsi_cls_session *session =
512 container_of(work, struct iscsi_cls_session,
513 recovery_work.work);
Mike Christie6eabafb2008-01-31 13:36:43 -0600514 unsigned long flags;
Mike Christie30a6c652006-04-06 21:13:39 -0500515
Mike Christie322d7392008-01-31 13:36:52 -0600516 iscsi_cls_session_printk(KERN_INFO, session,
517 "session recovery timed out after %d secs\n",
518 session->recovery_tmo);
Mike Christie30a6c652006-04-06 21:13:39 -0500519
Mike Christie6eabafb2008-01-31 13:36:43 -0600520 spin_lock_irqsave(&session->lock, flags);
521 switch (session->state) {
522 case ISCSI_SESSION_FAILED:
523 session->state = ISCSI_SESSION_FREE;
524 break;
525 case ISCSI_SESSION_LOGGED_IN:
526 case ISCSI_SESSION_FREE:
527 /* we raced with the unblock's flush */
528 spin_unlock_irqrestore(&session->lock, flags);
529 return;
530 }
531 spin_unlock_irqrestore(&session->lock, flags);
532
Mike Christie30a6c652006-04-06 21:13:39 -0500533 if (session->transport->session_recovery_timedout)
534 session->transport->session_recovery_timedout(session);
535
536 scsi_target_unblock(&session->dev);
537}
538
Mike Christie45ab33b2008-03-04 13:26:55 -0600539static void __iscsi_unblock_session(struct work_struct *work)
Mike Christie30a6c652006-04-06 21:13:39 -0500540{
Mike Christie45ab33b2008-03-04 13:26:55 -0600541 struct iscsi_cls_session *session =
542 container_of(work, struct iscsi_cls_session,
543 unblock_work);
Mike Christiebd976f62008-01-31 13:36:46 -0600544 struct Scsi_Host *shost = iscsi_session_to_shost(session);
Mike Christie32c6e1b2008-05-21 15:53:58 -0500545 struct iscsi_cls_host *ihost = shost->shost_data;
Mike Christie6eabafb2008-01-31 13:36:43 -0600546 unsigned long flags;
547
Mike Christie45ab33b2008-03-04 13:26:55 -0600548 /*
549 * The recovery and unblock work get run from the same workqueue,
550 * so try to cancel it if it was going to run after this unblock.
551 */
552 cancel_delayed_work(&session->recovery_work);
Mike Christie6eabafb2008-01-31 13:36:43 -0600553 spin_lock_irqsave(&session->lock, flags);
554 session->state = ISCSI_SESSION_LOGGED_IN;
555 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie45ab33b2008-03-04 13:26:55 -0600556 /* start IO */
557 scsi_target_unblock(&session->dev);
Mike Christie8aae18a2008-01-31 13:36:48 -0600558 /*
559 * Only do kernel scanning if the driver is properly hooked into
560 * the async scanning code (drivers like iscsi_tcp do login and
561 * scanning from userspace).
562 */
563 if (shost->hostt->scan_finished) {
564 if (queue_work(ihost->scan_workq, &session->scan_work))
565 atomic_inc(&ihost->nr_scans);
566 }
Mike Christie6eabafb2008-01-31 13:36:43 -0600567}
Mike Christie45ab33b2008-03-04 13:26:55 -0600568
569/**
570 * iscsi_unblock_session - set a session as logged in and start IO.
571 * @session: iscsi session
572 *
573 * Mark a session as ready to accept IO.
574 */
575void iscsi_unblock_session(struct iscsi_cls_session *session)
576{
577 queue_work(iscsi_eh_timer_workq, &session->unblock_work);
578 /*
579 * make sure all the events have completed before tell the driver
580 * it is safe
581 */
582 flush_workqueue(iscsi_eh_timer_workq);
583}
Mike Christie30a6c652006-04-06 21:13:39 -0500584EXPORT_SYMBOL_GPL(iscsi_unblock_session);
585
Mike Christie45ab33b2008-03-04 13:26:55 -0600586static void __iscsi_block_session(struct work_struct *work)
Mike Christie30a6c652006-04-06 21:13:39 -0500587{
Mike Christie45ab33b2008-03-04 13:26:55 -0600588 struct iscsi_cls_session *session =
589 container_of(work, struct iscsi_cls_session,
590 block_work);
Mike Christie6eabafb2008-01-31 13:36:43 -0600591 unsigned long flags;
592
593 spin_lock_irqsave(&session->lock, flags);
594 session->state = ISCSI_SESSION_FAILED;
595 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie30a6c652006-04-06 21:13:39 -0500596 scsi_target_block(&session->dev);
Mike Christied8bf5412007-12-13 12:43:27 -0600597 queue_delayed_work(iscsi_eh_timer_workq, &session->recovery_work,
598 session->recovery_tmo * HZ);
Mike Christie30a6c652006-04-06 21:13:39 -0500599}
Mike Christie45ab33b2008-03-04 13:26:55 -0600600
601void iscsi_block_session(struct iscsi_cls_session *session)
602{
603 queue_work(iscsi_eh_timer_workq, &session->block_work);
604}
Mike Christie30a6c652006-04-06 21:13:39 -0500605EXPORT_SYMBOL_GPL(iscsi_block_session);
606
Mike Christie26974782007-12-13 12:43:29 -0600607static void __iscsi_unbind_session(struct work_struct *work)
608{
609 struct iscsi_cls_session *session =
610 container_of(work, struct iscsi_cls_session,
611 unbind_work);
612 struct Scsi_Host *shost = iscsi_session_to_shost(session);
Mike Christie32c6e1b2008-05-21 15:53:58 -0500613 struct iscsi_cls_host *ihost = shost->shost_data;
Mike Christie79706342008-05-21 15:54:12 -0500614 unsigned long flags;
Mike Christie26974782007-12-13 12:43:29 -0600615
616 /* Prevent new scans and make sure scanning is not in progress */
617 mutex_lock(&ihost->mutex);
Mike Christie79706342008-05-21 15:54:12 -0500618 spin_lock_irqsave(&session->lock, flags);
619 if (session->target_id == ISCSI_MAX_TARGET) {
620 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie26974782007-12-13 12:43:29 -0600621 mutex_unlock(&ihost->mutex);
622 return;
623 }
Mike Christie79706342008-05-21 15:54:12 -0500624 session->target_id = ISCSI_MAX_TARGET;
625 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie26974782007-12-13 12:43:29 -0600626 mutex_unlock(&ihost->mutex);
627
628 scsi_remove_target(&session->dev);
629 iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION);
630}
631
632static int iscsi_unbind_session(struct iscsi_cls_session *session)
633{
634 struct Scsi_Host *shost = iscsi_session_to_shost(session);
Mike Christie32c6e1b2008-05-21 15:53:58 -0500635 struct iscsi_cls_host *ihost = shost->shost_data;
Mike Christie26974782007-12-13 12:43:29 -0600636
Mike Christiebd976f62008-01-31 13:36:46 -0600637 return queue_work(ihost->scan_workq, &session->unbind_work);
Mike Christie26974782007-12-13 12:43:29 -0600638}
639
Mike Christie7b8631b2006-01-13 18:05:50 -0600640struct iscsi_cls_session *
Mike Christie5d91e202008-05-21 15:54:01 -0500641iscsi_alloc_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
642 int dd_size)
Mike Christie7b8631b2006-01-13 18:05:50 -0600643{
644 struct iscsi_cls_session *session;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645
Mike Christie5d91e202008-05-21 15:54:01 -0500646 session = kzalloc(sizeof(*session) + dd_size,
Mike Christieb5c7a122006-04-06 21:13:33 -0500647 GFP_KERNEL);
Mike Christie7b8631b2006-01-13 18:05:50 -0600648 if (!session)
Mike Christief53a88d2006-06-28 12:00:27 -0500649 return NULL;
650
Mike Christie7b8631b2006-01-13 18:05:50 -0600651 session->transport = transport;
Mike Christie30a6c652006-04-06 21:13:39 -0500652 session->recovery_tmo = 120;
Mike Christie6eabafb2008-01-31 13:36:43 -0600653 session->state = ISCSI_SESSION_FREE;
David Howellsc4028952006-11-22 14:57:56 +0000654 INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout);
Mike Christie30a6c652006-04-06 21:13:39 -0500655 INIT_LIST_HEAD(&session->sess_list);
Mike Christie45ab33b2008-03-04 13:26:55 -0600656 INIT_WORK(&session->unblock_work, __iscsi_unblock_session);
657 INIT_WORK(&session->block_work, __iscsi_block_session);
Mike Christie26974782007-12-13 12:43:29 -0600658 INIT_WORK(&session->unbind_work, __iscsi_unbind_session);
Mike Christiebd976f62008-01-31 13:36:46 -0600659 INIT_WORK(&session->scan_work, iscsi_scan_session);
Mike Christie6eabafb2008-01-31 13:36:43 -0600660 spin_lock_init(&session->lock);
Mike Christie7b8631b2006-01-13 18:05:50 -0600661
Mike Christie6a8a0d32006-06-28 12:00:31 -0500662 /* this is released in the dev's release function */
663 scsi_host_get(shost);
Mike Christie8434aa82006-06-28 12:00:30 -0500664 session->dev.parent = &shost->shost_gendev;
665 session->dev.release = iscsi_session_release;
666 device_initialize(&session->dev);
Mike Christie5d91e202008-05-21 15:54:01 -0500667 if (dd_size)
Mike Christieb5c7a122006-04-06 21:13:33 -0500668 session->dd_data = &session[1];
Mike Christie8434aa82006-06-28 12:00:30 -0500669 return session;
670}
671EXPORT_SYMBOL_GPL(iscsi_alloc_session);
672
Mike Christie79706342008-05-21 15:54:12 -0500673static int iscsi_get_next_target_id(struct device *dev, void *data)
674{
675 struct iscsi_cls_session *session;
676 unsigned long flags;
677 int err = 0;
678
679 if (!iscsi_is_session_dev(dev))
680 return 0;
681
682 session = iscsi_dev_to_session(dev);
683 spin_lock_irqsave(&session->lock, flags);
684 if (*((unsigned int *) data) == session->target_id)
685 err = -EEXIST;
686 spin_unlock_irqrestore(&session->lock, flags);
687 return err;
688}
689
Mike Christie6a8a0d32006-06-28 12:00:31 -0500690int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
Mike Christie8434aa82006-06-28 12:00:30 -0500691{
692 struct Scsi_Host *shost = iscsi_session_to_shost(session);
Mike Christie32c6e1b2008-05-21 15:53:58 -0500693 struct iscsi_cls_host *ihost;
Mike Christie26974782007-12-13 12:43:29 -0600694 unsigned long flags;
Mike Christie79706342008-05-21 15:54:12 -0500695 unsigned int id = target_id;
Mike Christie8434aa82006-06-28 12:00:30 -0500696 int err;
Mike Christieb5c7a122006-04-06 21:13:33 -0500697
Mike Christie30a6c652006-04-06 21:13:39 -0500698 ihost = shost->shost_data;
Mike Christie41be1442007-02-28 17:32:18 -0600699 session->sid = atomic_add_return(1, &iscsi_session_nr);
Mike Christie79706342008-05-21 15:54:12 -0500700
701 if (id == ISCSI_MAX_TARGET) {
702 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
703 err = device_for_each_child(&shost->shost_gendev, &id,
704 iscsi_get_next_target_id);
705 if (!err)
706 break;
707 }
708
709 if (id == ISCSI_MAX_TARGET) {
710 iscsi_cls_session_printk(KERN_ERR, session,
711 "Too many iscsi targets. Max "
712 "number of targets is %d.\n",
713 ISCSI_MAX_TARGET - 1);
714 goto release_host;
715 }
716 }
717 session->target_id = id;
Mike Christie30a6c652006-04-06 21:13:39 -0500718
Mike Christieb5c7a122006-04-06 21:13:33 -0500719 snprintf(session->dev.bus_id, BUS_ID_SIZE, "session%u",
720 session->sid);
Mike Christie8434aa82006-06-28 12:00:30 -0500721 err = device_add(&session->dev);
Mike Christie7b8631b2006-01-13 18:05:50 -0600722 if (err) {
Mike Christie322d7392008-01-31 13:36:52 -0600723 iscsi_cls_session_printk(KERN_ERR, session,
724 "could not register session's dev\n");
Mike Christie8434aa82006-06-28 12:00:30 -0500725 goto release_host;
Mike Christie7b8631b2006-01-13 18:05:50 -0600726 }
727 transport_register_device(&session->dev);
728
Mike Christie26974782007-12-13 12:43:29 -0600729 spin_lock_irqsave(&sesslock, flags);
730 list_add(&session->sess_list, &sesslist);
731 spin_unlock_irqrestore(&sesslock, flags);
732
Mike Christie26974782007-12-13 12:43:29 -0600733 iscsi_session_event(session, ISCSI_KEVENT_CREATE_SESSION);
Mike Christie8434aa82006-06-28 12:00:30 -0500734 return 0;
Mike Christie30a6c652006-04-06 21:13:39 -0500735
Mike Christie8434aa82006-06-28 12:00:30 -0500736release_host:
737 scsi_host_put(shost);
738 return err;
Mike Christie7b8631b2006-01-13 18:05:50 -0600739}
Mike Christie8434aa82006-06-28 12:00:30 -0500740EXPORT_SYMBOL_GPL(iscsi_add_session);
Mike Christie7b8631b2006-01-13 18:05:50 -0600741
742/**
Mike Christie8434aa82006-06-28 12:00:30 -0500743 * iscsi_create_session - create iscsi class session
744 * @shost: scsi host
745 * @transport: iscsi transport
Mike Christie5d91e202008-05-21 15:54:01 -0500746 * @dd_size: private driver data size
Rob Landleyeb448202007-11-03 13:30:39 -0500747 * @target_id: which target
Mike Christie7b8631b2006-01-13 18:05:50 -0600748 *
Mike Christie8434aa82006-06-28 12:00:30 -0500749 * This can be called from a LLD or iscsi_transport.
Rob Landleyeb448202007-11-03 13:30:39 -0500750 */
Mike Christie8434aa82006-06-28 12:00:30 -0500751struct iscsi_cls_session *
Mike Christie5d91e202008-05-21 15:54:01 -0500752iscsi_create_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
753 int dd_size, unsigned int target_id)
Mike Christie8434aa82006-06-28 12:00:30 -0500754{
755 struct iscsi_cls_session *session;
756
Mike Christie5d91e202008-05-21 15:54:01 -0500757 session = iscsi_alloc_session(shost, transport, dd_size);
Mike Christie8434aa82006-06-28 12:00:30 -0500758 if (!session)
759 return NULL;
760
Mike Christie6a8a0d32006-06-28 12:00:31 -0500761 if (iscsi_add_session(session, target_id)) {
Mike Christie8434aa82006-06-28 12:00:30 -0500762 iscsi_free_session(session);
763 return NULL;
764 }
765 return session;
766}
767EXPORT_SYMBOL_GPL(iscsi_create_session);
768
Mike Christie26974782007-12-13 12:43:29 -0600769static void iscsi_conn_release(struct device *dev)
770{
771 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev);
772 struct device *parent = conn->dev.parent;
773
774 kfree(conn);
775 put_device(parent);
776}
777
778static int iscsi_is_conn_dev(const struct device *dev)
779{
780 return dev->release == iscsi_conn_release;
781}
782
783static int iscsi_iter_destroy_conn_fn(struct device *dev, void *data)
784{
785 if (!iscsi_is_conn_dev(dev))
786 return 0;
787 return iscsi_destroy_conn(iscsi_dev_to_conn(dev));
788}
789
Mike Christie8434aa82006-06-28 12:00:30 -0500790void iscsi_remove_session(struct iscsi_cls_session *session)
Mike Christie7b8631b2006-01-13 18:05:50 -0600791{
Mike Christie30a6c652006-04-06 21:13:39 -0500792 struct Scsi_Host *shost = iscsi_session_to_shost(session);
Mike Christie32c6e1b2008-05-21 15:53:58 -0500793 struct iscsi_cls_host *ihost = shost->shost_data;
Mike Christie26974782007-12-13 12:43:29 -0600794 unsigned long flags;
795 int err;
Mike Christie30a6c652006-04-06 21:13:39 -0500796
Mike Christie26974782007-12-13 12:43:29 -0600797 spin_lock_irqsave(&sesslock, flags);
798 list_del(&session->sess_list);
799 spin_unlock_irqrestore(&sesslock, flags);
800
Mike Christie45ab33b2008-03-04 13:26:55 -0600801 /* make sure there are no blocks/unblocks queued */
802 flush_workqueue(iscsi_eh_timer_workq);
803 /* make sure the timedout callout is not running */
804 if (!cancel_delayed_work(&session->recovery_work))
805 flush_workqueue(iscsi_eh_timer_workq);
Mike Christie26974782007-12-13 12:43:29 -0600806 /*
807 * If we are blocked let commands flow again. The lld or iscsi
808 * layer should set up the queuecommand to fail commands.
Mike Christie45ab33b2008-03-04 13:26:55 -0600809 * We assume that LLD will not be calling block/unblock while
810 * removing the session.
Mike Christie26974782007-12-13 12:43:29 -0600811 */
Mike Christie6eabafb2008-01-31 13:36:43 -0600812 spin_lock_irqsave(&session->lock, flags);
813 session->state = ISCSI_SESSION_FREE;
814 spin_unlock_irqrestore(&session->lock, flags);
Mike Christiebd976f62008-01-31 13:36:46 -0600815
Mike Christie45ab33b2008-03-04 13:26:55 -0600816 scsi_target_unblock(&session->dev);
817 /* flush running scans then delete devices */
Mike Christiebd976f62008-01-31 13:36:46 -0600818 flush_workqueue(ihost->scan_workq);
Mike Christie45ab33b2008-03-04 13:26:55 -0600819 __iscsi_unbind_session(&session->unbind_work);
Mike Christie30a6c652006-04-06 21:13:39 -0500820
Mike Christie26974782007-12-13 12:43:29 -0600821 /* hw iscsi may not have removed all connections from session */
822 err = device_for_each_child(&session->dev, NULL,
823 iscsi_iter_destroy_conn_fn);
824 if (err)
Mike Christie322d7392008-01-31 13:36:52 -0600825 iscsi_cls_session_printk(KERN_ERR, session,
826 "Could not delete all connections "
827 "for session. Error %d.\n", err);
Mike Christie8434aa82006-06-28 12:00:30 -0500828
Mike Christie7b8631b2006-01-13 18:05:50 -0600829 transport_unregister_device(&session->dev);
Mike Christie8434aa82006-06-28 12:00:30 -0500830 device_del(&session->dev);
831}
832EXPORT_SYMBOL_GPL(iscsi_remove_session);
833
834void iscsi_free_session(struct iscsi_cls_session *session)
835{
Mike Christie26974782007-12-13 12:43:29 -0600836 iscsi_session_event(session, ISCSI_KEVENT_DESTROY_SESSION);
Mike Christie8434aa82006-06-28 12:00:30 -0500837 put_device(&session->dev);
Mike Christie7b8631b2006-01-13 18:05:50 -0600838}
Mike Christie8434aa82006-06-28 12:00:30 -0500839EXPORT_SYMBOL_GPL(iscsi_free_session);
840
841/**
842 * iscsi_destroy_session - destroy iscsi session
843 * @session: iscsi_session
844 *
845 * Can be called by a LLD or iscsi_transport. There must not be
846 * any running connections.
Rob Landleyeb448202007-11-03 13:30:39 -0500847 */
Mike Christie8434aa82006-06-28 12:00:30 -0500848int iscsi_destroy_session(struct iscsi_cls_session *session)
849{
850 iscsi_remove_session(session);
851 iscsi_free_session(session);
852 return 0;
853}
Mike Christie7b8631b2006-01-13 18:05:50 -0600854EXPORT_SYMBOL_GPL(iscsi_destroy_session);
855
Mike Christie7b8631b2006-01-13 18:05:50 -0600856/**
857 * iscsi_create_conn - create iscsi class connection
858 * @session: iscsi cls session
Mike Christie5d91e202008-05-21 15:54:01 -0500859 * @dd_size: private driver data size
Mike Christie7b8631b2006-01-13 18:05:50 -0600860 * @cid: connection id
861 *
862 * This can be called from a LLD or iscsi_transport. The connection
863 * is child of the session so cid must be unique for all connections
864 * on the session.
Mike Christieb5c7a122006-04-06 21:13:33 -0500865 *
866 * Since we do not support MCS, cid will normally be zero. In some cases
867 * for software iscsi we could be trying to preallocate a connection struct
868 * in which case there could be two connection structs and cid would be
869 * non-zero.
Rob Landleyeb448202007-11-03 13:30:39 -0500870 */
Mike Christie7b8631b2006-01-13 18:05:50 -0600871struct iscsi_cls_conn *
Mike Christie5d91e202008-05-21 15:54:01 -0500872iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid)
Mike Christie7b8631b2006-01-13 18:05:50 -0600873{
874 struct iscsi_transport *transport = session->transport;
Mike Christie7b8631b2006-01-13 18:05:50 -0600875 struct iscsi_cls_conn *conn;
Mike Christie26974782007-12-13 12:43:29 -0600876 unsigned long flags;
Mike Christie7b8631b2006-01-13 18:05:50 -0600877 int err;
878
Mike Christie5d91e202008-05-21 15:54:01 -0500879 conn = kzalloc(sizeof(*conn) + dd_size, GFP_KERNEL);
Mike Christie7b8631b2006-01-13 18:05:50 -0600880 if (!conn)
881 return NULL;
Mike Christie5d91e202008-05-21 15:54:01 -0500882 if (dd_size)
Mike Christie7b8631b2006-01-13 18:05:50 -0600883 conn->dd_data = &conn[1];
884
885 INIT_LIST_HEAD(&conn->conn_list);
886 conn->transport = transport;
Mike Christieb5c7a122006-04-06 21:13:33 -0500887 conn->cid = cid;
Mike Christie7b8631b2006-01-13 18:05:50 -0600888
889 /* this is released in the dev's release function */
890 if (!get_device(&session->dev))
Mike Christie43a145a2006-10-16 18:09:38 -0400891 goto free_conn;
Mike Christieb5c7a122006-04-06 21:13:33 -0500892
Mike Christie7b8631b2006-01-13 18:05:50 -0600893 snprintf(conn->dev.bus_id, BUS_ID_SIZE, "connection%d:%u",
Mike Christieb5c7a122006-04-06 21:13:33 -0500894 session->sid, cid);
Mike Christie7b8631b2006-01-13 18:05:50 -0600895 conn->dev.parent = &session->dev;
896 conn->dev.release = iscsi_conn_release;
897 err = device_register(&conn->dev);
898 if (err) {
Mike Christie322d7392008-01-31 13:36:52 -0600899 iscsi_cls_session_printk(KERN_ERR, session, "could not "
900 "register connection's dev\n");
Mike Christie7b8631b2006-01-13 18:05:50 -0600901 goto release_parent_ref;
902 }
903 transport_register_device(&conn->dev);
Mike Christie26974782007-12-13 12:43:29 -0600904
905 spin_lock_irqsave(&connlock, flags);
906 list_add(&conn->conn_list, &connlist);
907 conn->active = 1;
908 spin_unlock_irqrestore(&connlock, flags);
Mike Christie7b8631b2006-01-13 18:05:50 -0600909 return conn;
910
911release_parent_ref:
912 put_device(&session->dev);
913free_conn:
914 kfree(conn);
915 return NULL;
916}
917
918EXPORT_SYMBOL_GPL(iscsi_create_conn);
919
920/**
921 * iscsi_destroy_conn - destroy iscsi class connection
Rob Landleyeb448202007-11-03 13:30:39 -0500922 * @conn: iscsi cls session
Mike Christie7b8631b2006-01-13 18:05:50 -0600923 *
Mike Christie26974782007-12-13 12:43:29 -0600924 * This can be called from a LLD or iscsi_transport.
Rob Landleyeb448202007-11-03 13:30:39 -0500925 */
Mike Christie7b8631b2006-01-13 18:05:50 -0600926int iscsi_destroy_conn(struct iscsi_cls_conn *conn)
927{
Mike Christie26974782007-12-13 12:43:29 -0600928 unsigned long flags;
929
930 spin_lock_irqsave(&connlock, flags);
931 conn->active = 0;
932 list_del(&conn->conn_list);
933 spin_unlock_irqrestore(&connlock, flags);
934
Mike Christie7b8631b2006-01-13 18:05:50 -0600935 transport_unregister_device(&conn->dev);
936 device_unregister(&conn->dev);
937 return 0;
938}
Mike Christie7b8631b2006-01-13 18:05:50 -0600939EXPORT_SYMBOL_GPL(iscsi_destroy_conn);
940
941/*
Mike Christie7b8631b2006-01-13 18:05:50 -0600942 * iscsi interface functions
943 */
Alex Aizman0896b752005-08-04 19:33:07 -0700944static struct iscsi_internal *
945iscsi_if_transport_lookup(struct iscsi_transport *tt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946{
Alex Aizman0896b752005-08-04 19:33:07 -0700947 struct iscsi_internal *priv;
948 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Alex Aizman0896b752005-08-04 19:33:07 -0700950 spin_lock_irqsave(&iscsi_transport_lock, flags);
951 list_for_each_entry(priv, &iscsi_transports, list) {
952 if (tt == priv->iscsi_transport) {
953 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
954 return priv;
955 }
956 }
957 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
958 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
Alex Aizman0896b752005-08-04 19:33:07 -0700961static int
Mike Christie43a145a2006-10-16 18:09:38 -0400962iscsi_broadcast_skb(struct sk_buff *skb, gfp_t gfp)
Mike Christie53cb8a12006-06-28 12:00:32 -0500963{
Mike Christie53cb8a12006-06-28 12:00:32 -0500964 int rc;
965
Mike Christie9aaa2b42006-07-24 15:47:34 -0500966 rc = netlink_broadcast(nls, skb, 0, 1, gfp);
Mike Christie53cb8a12006-06-28 12:00:32 -0500967 if (rc < 0) {
Mike Christie53cb8a12006-06-28 12:00:32 -0500968 printk(KERN_ERR "iscsi: can not broadcast skb (%d)\n", rc);
969 return rc;
970 }
971
Mike Christie53cb8a12006-06-28 12:00:32 -0500972 return 0;
973}
974
975static int
Mike Christie43a145a2006-10-16 18:09:38 -0400976iscsi_unicast_skb(struct sk_buff *skb, int pid)
Alex Aizman0896b752005-08-04 19:33:07 -0700977{
Alex Aizman0896b752005-08-04 19:33:07 -0700978 int rc;
979
Mike Christie790f39a2006-05-18 20:31:39 -0500980 rc = netlink_unicast(nls, skb, pid, MSG_DONTWAIT);
Alex Aizman0896b752005-08-04 19:33:07 -0700981 if (rc < 0) {
Alex Aizman0896b752005-08-04 19:33:07 -0700982 printk(KERN_ERR "iscsi: can not unicast skb (%d)\n", rc);
983 return rc;
984 }
985
Alex Aizman0896b752005-08-04 19:33:07 -0700986 return 0;
987}
988
Mike Christie7b7232f2006-02-01 21:06:49 -0600989int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
Alex Aizman0896b752005-08-04 19:33:07 -0700990 char *data, uint32_t data_size)
991{
992 struct nlmsghdr *nlh;
993 struct sk_buff *skb;
994 struct iscsi_uevent *ev;
Alex Aizman0896b752005-08-04 19:33:07 -0700995 char *pdu;
Mike Christie790f39a2006-05-18 20:31:39 -0500996 struct iscsi_internal *priv;
Alex Aizman0896b752005-08-04 19:33:07 -0700997 int len = NLMSG_SPACE(sizeof(*ev) + sizeof(struct iscsi_hdr) +
998 data_size);
999
Mike Christie790f39a2006-05-18 20:31:39 -05001000 priv = iscsi_if_transport_lookup(conn->transport);
1001 if (!priv)
1002 return -EINVAL;
1003
Mike Christie43a145a2006-10-16 18:09:38 -04001004 skb = alloc_skb(len, GFP_ATOMIC);
Alex Aizman0896b752005-08-04 19:33:07 -07001005 if (!skb) {
Mike Christie7b7232f2006-02-01 21:06:49 -06001006 iscsi_conn_error(conn, ISCSI_ERR_CONN_FAILED);
Mike Christie322d7392008-01-31 13:36:52 -06001007 iscsi_cls_conn_printk(KERN_ERR, conn, "can not deliver "
1008 "control PDU: OOM\n");
Alex Aizman0896b752005-08-04 19:33:07 -07001009 return -ENOMEM;
1010 }
1011
Mike Christie790f39a2006-05-18 20:31:39 -05001012 nlh = __nlmsg_put(skb, priv->daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
Alex Aizman0896b752005-08-04 19:33:07 -07001013 ev = NLMSG_DATA(nlh);
1014 memset(ev, 0, sizeof(*ev));
1015 ev->transport_handle = iscsi_handle(conn->transport);
1016 ev->type = ISCSI_KEVENT_RECV_PDU;
Mike Christieb5c7a122006-04-06 21:13:33 -05001017 ev->r.recv_req.cid = conn->cid;
1018 ev->r.recv_req.sid = iscsi_conn_get_sid(conn);
Alex Aizman0896b752005-08-04 19:33:07 -07001019 pdu = (char*)ev + sizeof(*ev);
1020 memcpy(pdu, hdr, sizeof(struct iscsi_hdr));
1021 memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size);
1022
Mike Christie43a145a2006-10-16 18:09:38 -04001023 return iscsi_unicast_skb(skb, priv->daemon_pid);
Alex Aizman0896b752005-08-04 19:33:07 -07001024}
1025EXPORT_SYMBOL_GPL(iscsi_recv_pdu);
1026
Mike Christie7b7232f2006-02-01 21:06:49 -06001027void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error)
Alex Aizman0896b752005-08-04 19:33:07 -07001028{
1029 struct nlmsghdr *nlh;
1030 struct sk_buff *skb;
1031 struct iscsi_uevent *ev;
Mike Christie790f39a2006-05-18 20:31:39 -05001032 struct iscsi_internal *priv;
Alex Aizman0896b752005-08-04 19:33:07 -07001033 int len = NLMSG_SPACE(sizeof(*ev));
1034
Mike Christie790f39a2006-05-18 20:31:39 -05001035 priv = iscsi_if_transport_lookup(conn->transport);
1036 if (!priv)
1037 return;
1038
Mike Christie43a145a2006-10-16 18:09:38 -04001039 skb = alloc_skb(len, GFP_ATOMIC);
Alex Aizman0896b752005-08-04 19:33:07 -07001040 if (!skb) {
Mike Christie322d7392008-01-31 13:36:52 -06001041 iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
1042 "conn error (%d)\n", error);
Alex Aizman0896b752005-08-04 19:33:07 -07001043 return;
1044 }
1045
Mike Christie790f39a2006-05-18 20:31:39 -05001046 nlh = __nlmsg_put(skb, priv->daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
Alex Aizman0896b752005-08-04 19:33:07 -07001047 ev = NLMSG_DATA(nlh);
1048 ev->transport_handle = iscsi_handle(conn->transport);
1049 ev->type = ISCSI_KEVENT_CONN_ERROR;
Alex Aizman0896b752005-08-04 19:33:07 -07001050 ev->r.connerror.error = error;
Mike Christieb5c7a122006-04-06 21:13:33 -05001051 ev->r.connerror.cid = conn->cid;
1052 ev->r.connerror.sid = iscsi_conn_get_sid(conn);
Alex Aizman0896b752005-08-04 19:33:07 -07001053
Mike Christie43a145a2006-10-16 18:09:38 -04001054 iscsi_broadcast_skb(skb, GFP_ATOMIC);
Alex Aizman0896b752005-08-04 19:33:07 -07001055
Mike Christie322d7392008-01-31 13:36:52 -06001056 iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn error (%d)\n",
1057 error);
Alex Aizman0896b752005-08-04 19:33:07 -07001058}
1059EXPORT_SYMBOL_GPL(iscsi_conn_error);
1060
1061static int
1062iscsi_if_send_reply(int pid, int seq, int type, int done, int multi,
1063 void *payload, int size)
1064{
1065 struct sk_buff *skb;
1066 struct nlmsghdr *nlh;
1067 int len = NLMSG_SPACE(size);
1068 int flags = multi ? NLM_F_MULTI : 0;
1069 int t = done ? NLMSG_DONE : type;
1070
Mike Christie43a145a2006-10-16 18:09:38 -04001071 skb = alloc_skb(len, GFP_ATOMIC);
Mike Christie239a7dc2007-05-30 12:57:07 -05001072 if (!skb) {
1073 printk(KERN_ERR "Could not allocate skb to send reply.\n");
1074 return -ENOMEM;
1075 }
Alex Aizman0896b752005-08-04 19:33:07 -07001076
1077 nlh = __nlmsg_put(skb, pid, seq, t, (len - sizeof(*nlh)), 0);
1078 nlh->nlmsg_flags = flags;
1079 memcpy(NLMSG_DATA(nlh), payload, size);
Mike Christie43a145a2006-10-16 18:09:38 -04001080 return iscsi_unicast_skb(skb, pid);
Alex Aizman0896b752005-08-04 19:33:07 -07001081}
1082
1083static int
Mike Christie5b940ad2006-02-01 21:06:56 -06001084iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
Alex Aizman0896b752005-08-04 19:33:07 -07001085{
1086 struct iscsi_uevent *ev = NLMSG_DATA(nlh);
1087 struct iscsi_stats *stats;
1088 struct sk_buff *skbstat;
Mike Christie7b8631b2006-01-13 18:05:50 -06001089 struct iscsi_cls_conn *conn;
Alex Aizman0896b752005-08-04 19:33:07 -07001090 struct nlmsghdr *nlhstat;
1091 struct iscsi_uevent *evstat;
Mike Christie790f39a2006-05-18 20:31:39 -05001092 struct iscsi_internal *priv;
Alex Aizman0896b752005-08-04 19:33:07 -07001093 int len = NLMSG_SPACE(sizeof(*ev) +
1094 sizeof(struct iscsi_stats) +
1095 sizeof(struct iscsi_stats_custom) *
1096 ISCSI_STATS_CUSTOM_MAX);
1097 int err = 0;
1098
Mike Christie790f39a2006-05-18 20:31:39 -05001099 priv = iscsi_if_transport_lookup(transport);
1100 if (!priv)
1101 return -EINVAL;
1102
Mike Christieb5c7a122006-04-06 21:13:33 -05001103 conn = iscsi_conn_lookup(ev->u.get_stats.sid, ev->u.get_stats.cid);
Alex Aizman0896b752005-08-04 19:33:07 -07001104 if (!conn)
1105 return -EEXIST;
1106
1107 do {
1108 int actual_size;
1109
Mike Christie43a145a2006-10-16 18:09:38 -04001110 skbstat = alloc_skb(len, GFP_ATOMIC);
Alex Aizman0896b752005-08-04 19:33:07 -07001111 if (!skbstat) {
Mike Christie322d7392008-01-31 13:36:52 -06001112 iscsi_cls_conn_printk(KERN_ERR, conn, "can not "
1113 "deliver stats: OOM\n");
Alex Aizman0896b752005-08-04 19:33:07 -07001114 return -ENOMEM;
1115 }
1116
Mike Christie790f39a2006-05-18 20:31:39 -05001117 nlhstat = __nlmsg_put(skbstat, priv->daemon_pid, 0, 0,
Alex Aizman0896b752005-08-04 19:33:07 -07001118 (len - sizeof(*nlhstat)), 0);
1119 evstat = NLMSG_DATA(nlhstat);
1120 memset(evstat, 0, sizeof(*evstat));
1121 evstat->transport_handle = iscsi_handle(conn->transport);
1122 evstat->type = nlh->nlmsg_type;
Mike Christieb5c7a122006-04-06 21:13:33 -05001123 evstat->u.get_stats.cid =
1124 ev->u.get_stats.cid;
1125 evstat->u.get_stats.sid =
1126 ev->u.get_stats.sid;
Alex Aizman0896b752005-08-04 19:33:07 -07001127 stats = (struct iscsi_stats *)
1128 ((char*)evstat + sizeof(*evstat));
1129 memset(stats, 0, sizeof(*stats));
1130
Mike Christie7b7232f2006-02-01 21:06:49 -06001131 transport->get_stats(conn, stats);
Alex Aizman0896b752005-08-04 19:33:07 -07001132 actual_size = NLMSG_SPACE(sizeof(struct iscsi_uevent) +
1133 sizeof(struct iscsi_stats) +
1134 sizeof(struct iscsi_stats_custom) *
1135 stats->custom_length);
1136 actual_size -= sizeof(*nlhstat);
1137 actual_size = NLMSG_LENGTH(actual_size);
Mike Christie5b940ad2006-02-01 21:06:56 -06001138 skb_trim(skbstat, NLMSG_ALIGN(actual_size));
Alex Aizman0896b752005-08-04 19:33:07 -07001139 nlhstat->nlmsg_len = actual_size;
1140
Mike Christie43a145a2006-10-16 18:09:38 -04001141 err = iscsi_unicast_skb(skbstat, priv->daemon_pid);
Alex Aizman0896b752005-08-04 19:33:07 -07001142 } while (err < 0 && err != -ECONNREFUSED);
1143
1144 return err;
1145}
1146
Mike Christie53cb8a12006-06-28 12:00:32 -05001147/**
Mike Christie26974782007-12-13 12:43:29 -06001148 * iscsi_session_event - send session destr. completion event
1149 * @session: iscsi class session
1150 * @event: type of event
Rob Landleyeb448202007-11-03 13:30:39 -05001151 */
Mike Christie26974782007-12-13 12:43:29 -06001152int iscsi_session_event(struct iscsi_cls_session *session,
1153 enum iscsi_uevent_e event)
Mike Christie53cb8a12006-06-28 12:00:32 -05001154{
1155 struct iscsi_internal *priv;
Mike Christie53cb8a12006-06-28 12:00:32 -05001156 struct Scsi_Host *shost;
1157 struct iscsi_uevent *ev;
1158 struct sk_buff *skb;
1159 struct nlmsghdr *nlh;
Mike Christie53cb8a12006-06-28 12:00:32 -05001160 int rc, len = NLMSG_SPACE(sizeof(*ev));
1161
Mike Christie26974782007-12-13 12:43:29 -06001162 priv = iscsi_if_transport_lookup(session->transport);
Mike Christie53cb8a12006-06-28 12:00:32 -05001163 if (!priv)
1164 return -EINVAL;
Mike Christie53cb8a12006-06-28 12:00:32 -05001165 shost = iscsi_session_to_shost(session);
1166
Mike Christie43a145a2006-10-16 18:09:38 -04001167 skb = alloc_skb(len, GFP_KERNEL);
Mike Christie53cb8a12006-06-28 12:00:32 -05001168 if (!skb) {
Mike Christie322d7392008-01-31 13:36:52 -06001169 iscsi_cls_session_printk(KERN_ERR, session,
1170 "Cannot notify userspace of session "
1171 "event %u\n", event);
Mike Christie53cb8a12006-06-28 12:00:32 -05001172 return -ENOMEM;
1173 }
1174
1175 nlh = __nlmsg_put(skb, priv->daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
1176 ev = NLMSG_DATA(nlh);
Mike Christie26974782007-12-13 12:43:29 -06001177 ev->transport_handle = iscsi_handle(session->transport);
1178
1179 ev->type = event;
1180 switch (event) {
1181 case ISCSI_KEVENT_DESTROY_SESSION:
1182 ev->r.d_session.host_no = shost->host_no;
1183 ev->r.d_session.sid = session->sid;
1184 break;
1185 case ISCSI_KEVENT_CREATE_SESSION:
1186 ev->r.c_session_ret.host_no = shost->host_no;
1187 ev->r.c_session_ret.sid = session->sid;
1188 break;
1189 case ISCSI_KEVENT_UNBIND_SESSION:
1190 ev->r.unbind_session.host_no = shost->host_no;
1191 ev->r.unbind_session.sid = session->sid;
1192 break;
1193 default:
Mike Christie322d7392008-01-31 13:36:52 -06001194 iscsi_cls_session_printk(KERN_ERR, session, "Invalid event "
1195 "%u.\n", event);
Mike Christie26974782007-12-13 12:43:29 -06001196 kfree_skb(skb);
1197 return -EINVAL;
1198 }
Mike Christie53cb8a12006-06-28 12:00:32 -05001199
1200 /*
1201 * this will occur if the daemon is not up, so we just warn
1202 * the user and when the daemon is restarted it will handle it
1203 */
Mike Christie43a145a2006-10-16 18:09:38 -04001204 rc = iscsi_broadcast_skb(skb, GFP_KERNEL);
Mike Christie53cb8a12006-06-28 12:00:32 -05001205 if (rc < 0)
Mike Christie322d7392008-01-31 13:36:52 -06001206 iscsi_cls_session_printk(KERN_ERR, session,
1207 "Cannot notify userspace of session "
1208 "event %u. Check iscsi daemon\n",
1209 event);
Mike Christie53cb8a12006-06-28 12:00:32 -05001210 return rc;
1211}
Mike Christie26974782007-12-13 12:43:29 -06001212EXPORT_SYMBOL_GPL(iscsi_session_event);
Mike Christie53cb8a12006-06-28 12:00:32 -05001213
Alex Aizman0896b752005-08-04 19:33:07 -07001214static int
Mike Christied82ff9be2008-05-21 15:54:13 -05001215iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_endpoint *ep,
1216 struct iscsi_uevent *ev, uint32_t initial_cmdsn,
Mike Christie40753ca2008-05-21 15:53:56 -05001217 uint16_t cmds_max, uint16_t queue_depth)
Mike Christie7b8631b2006-01-13 18:05:50 -06001218{
1219 struct iscsi_transport *transport = priv->iscsi_transport;
Mike Christie7b7232f2006-02-01 21:06:49 -06001220 struct iscsi_cls_session *session;
Mike Christied82ff9be2008-05-21 15:54:13 -05001221 uint32_t host_no;
Mike Christie7b8631b2006-01-13 18:05:50 -06001222
Mike Christied82ff9be2008-05-21 15:54:13 -05001223 session = transport->create_session(ep, cmds_max, queue_depth,
Mike Christie40753ca2008-05-21 15:53:56 -05001224 initial_cmdsn, &host_no);
Mike Christie7b7232f2006-02-01 21:06:49 -06001225 if (!session)
Mike Christie7b8631b2006-01-13 18:05:50 -06001226 return -ENOMEM;
1227
Mike Christie40753ca2008-05-21 15:53:56 -05001228 ev->r.c_session_ret.host_no = host_no;
Mike Christieb5c7a122006-04-06 21:13:33 -05001229 ev->r.c_session_ret.sid = session->sid;
Mike Christie7b8631b2006-01-13 18:05:50 -06001230 return 0;
1231}
1232
1233static int
Mike Christie7b7232f2006-02-01 21:06:49 -06001234iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
Mike Christie7b8631b2006-01-13 18:05:50 -06001235{
Mike Christie7b8631b2006-01-13 18:05:50 -06001236 struct iscsi_cls_conn *conn;
Mike Christie7b7232f2006-02-01 21:06:49 -06001237 struct iscsi_cls_session *session;
Mike Christie7b8631b2006-01-13 18:05:50 -06001238
Mike Christieb5c7a122006-04-06 21:13:33 -05001239 session = iscsi_session_lookup(ev->u.c_conn.sid);
1240 if (!session) {
Mike Christie322d7392008-01-31 13:36:52 -06001241 printk(KERN_ERR "iscsi: invalid session %d.\n",
Mike Christieb5c7a122006-04-06 21:13:33 -05001242 ev->u.c_conn.sid);
Mike Christie7b8631b2006-01-13 18:05:50 -06001243 return -EINVAL;
Mike Christieb5c7a122006-04-06 21:13:33 -05001244 }
Mike Christie7b8631b2006-01-13 18:05:50 -06001245
Mike Christie7b7232f2006-02-01 21:06:49 -06001246 conn = transport->create_conn(session, ev->u.c_conn.cid);
Mike Christieb5c7a122006-04-06 21:13:33 -05001247 if (!conn) {
Mike Christie322d7392008-01-31 13:36:52 -06001248 iscsi_cls_session_printk(KERN_ERR, session,
1249 "couldn't create a new connection.");
Mike Christie7b7232f2006-02-01 21:06:49 -06001250 return -ENOMEM;
Mike Christieb5c7a122006-04-06 21:13:33 -05001251 }
Mike Christie7b8631b2006-01-13 18:05:50 -06001252
Mike Christieb5c7a122006-04-06 21:13:33 -05001253 ev->r.c_conn_ret.sid = session->sid;
1254 ev->r.c_conn_ret.cid = conn->cid;
Mike Christie7b8631b2006-01-13 18:05:50 -06001255 return 0;
Mike Christie7b8631b2006-01-13 18:05:50 -06001256}
1257
1258static int
1259iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
1260{
Mike Christie7b8631b2006-01-13 18:05:50 -06001261 struct iscsi_cls_conn *conn;
Mike Christie7b8631b2006-01-13 18:05:50 -06001262
Mike Christieb5c7a122006-04-06 21:13:33 -05001263 conn = iscsi_conn_lookup(ev->u.d_conn.sid, ev->u.d_conn.cid);
Mike Christie7b8631b2006-01-13 18:05:50 -06001264 if (!conn)
Mike Christie7b8631b2006-01-13 18:05:50 -06001265 return -EINVAL;
Mike Christie7b8631b2006-01-13 18:05:50 -06001266
Mike Christie7b8631b2006-01-13 18:05:50 -06001267 if (transport->destroy_conn)
1268 transport->destroy_conn(conn);
Mike Christie7b8631b2006-01-13 18:05:50 -06001269 return 0;
1270}
1271
Mike Christiefd7255f2006-04-06 21:13:36 -05001272static int
1273iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
1274{
1275 char *data = (char*)ev + sizeof(*ev);
1276 struct iscsi_cls_conn *conn;
1277 struct iscsi_cls_session *session;
Mike Christiea54a52c2006-06-28 12:00:23 -05001278 int err = 0, value = 0;
Mike Christiefd7255f2006-04-06 21:13:36 -05001279
1280 session = iscsi_session_lookup(ev->u.set_param.sid);
1281 conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid);
1282 if (!conn || !session)
1283 return -EINVAL;
1284
1285 switch (ev->u.set_param.param) {
Mike Christie30a6c652006-04-06 21:13:39 -05001286 case ISCSI_PARAM_SESS_RECOVERY_TMO:
Mike Christiea54a52c2006-06-28 12:00:23 -05001287 sscanf(data, "%d", &value);
Mike Christie30a6c652006-04-06 21:13:39 -05001288 if (value != 0)
1289 session->recovery_tmo = value;
1290 break;
Mike Christiefd7255f2006-04-06 21:13:36 -05001291 default:
Mike Christiea54a52c2006-06-28 12:00:23 -05001292 err = transport->set_param(conn, ev->u.set_param.param,
1293 data, ev->u.set_param.len);
Mike Christiefd7255f2006-04-06 21:13:36 -05001294 }
1295
1296 return err;
1297}
1298
Mike Christie7b8631b2006-01-13 18:05:50 -06001299static int
Or Gerlitz264faaa2006-05-02 19:46:36 -05001300iscsi_if_transport_ep(struct iscsi_transport *transport,
1301 struct iscsi_uevent *ev, int msg_type)
1302{
Mike Christied82ff9be2008-05-21 15:54:13 -05001303 struct iscsi_endpoint *ep;
Or Gerlitz264faaa2006-05-02 19:46:36 -05001304 struct sockaddr *dst_addr;
1305 int rc = 0;
1306
1307 switch (msg_type) {
1308 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
1309 if (!transport->ep_connect)
1310 return -EINVAL;
1311
1312 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
Mike Christied82ff9be2008-05-21 15:54:13 -05001313 ep = transport->ep_connect(dst_addr,
1314 ev->u.ep_connect.non_blocking);
1315 if (IS_ERR(ep))
1316 return PTR_ERR(ep);
1317
1318 ev->r.ep_connect_ret.handle = ep->id;
Or Gerlitz264faaa2006-05-02 19:46:36 -05001319 break;
1320 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
1321 if (!transport->ep_poll)
1322 return -EINVAL;
1323
Mike Christied82ff9be2008-05-21 15:54:13 -05001324 ep = iscsi_lookup_endpoint(ev->u.ep_poll.ep_handle);
1325 if (!ep)
1326 return -EINVAL;
1327
1328 ev->r.retcode = transport->ep_poll(ep,
Or Gerlitz264faaa2006-05-02 19:46:36 -05001329 ev->u.ep_poll.timeout_ms);
1330 break;
1331 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
1332 if (!transport->ep_disconnect)
1333 return -EINVAL;
1334
Mike Christied82ff9be2008-05-21 15:54:13 -05001335 ep = iscsi_lookup_endpoint(ev->u.ep_disconnect.ep_handle);
1336 if (!ep)
1337 return -EINVAL;
1338
1339 transport->ep_disconnect(ep);
Or Gerlitz264faaa2006-05-02 19:46:36 -05001340 break;
1341 }
1342 return rc;
1343}
1344
1345static int
Mike Christie01cb2252006-06-28 12:00:22 -05001346iscsi_tgt_dscvr(struct iscsi_transport *transport,
1347 struct iscsi_uevent *ev)
1348{
Mike Christie2174a042007-05-30 12:57:10 -05001349 struct Scsi_Host *shost;
Mike Christie01cb2252006-06-28 12:00:22 -05001350 struct sockaddr *dst_addr;
Mike Christie2174a042007-05-30 12:57:10 -05001351 int err;
Mike Christie01cb2252006-06-28 12:00:22 -05001352
1353 if (!transport->tgt_dscvr)
1354 return -EINVAL;
1355
Mike Christie2174a042007-05-30 12:57:10 -05001356 shost = scsi_host_lookup(ev->u.tgt_dscvr.host_no);
1357 if (IS_ERR(shost)) {
1358 printk(KERN_ERR "target discovery could not find host no %u\n",
1359 ev->u.tgt_dscvr.host_no);
1360 return -ENODEV;
1361 }
1362
1363
Mike Christie01cb2252006-06-28 12:00:22 -05001364 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
Mike Christie2174a042007-05-30 12:57:10 -05001365 err = transport->tgt_dscvr(shost, ev->u.tgt_dscvr.type,
1366 ev->u.tgt_dscvr.enable, dst_addr);
1367 scsi_host_put(shost);
1368 return err;
Mike Christie01cb2252006-06-28 12:00:22 -05001369}
1370
1371static int
Mike Christie1d9bf132007-05-30 12:57:11 -05001372iscsi_set_host_param(struct iscsi_transport *transport,
1373 struct iscsi_uevent *ev)
1374{
1375 char *data = (char*)ev + sizeof(*ev);
1376 struct Scsi_Host *shost;
1377 int err;
1378
1379 if (!transport->set_host_param)
1380 return -ENOSYS;
1381
1382 shost = scsi_host_lookup(ev->u.set_host_param.host_no);
1383 if (IS_ERR(shost)) {
1384 printk(KERN_ERR "set_host_param could not find host no %u\n",
1385 ev->u.set_host_param.host_no);
1386 return -ENODEV;
1387 }
1388
1389 err = transport->set_host_param(shost, ev->u.set_host_param.param,
1390 data, ev->u.set_host_param.len);
1391 scsi_host_put(shost);
1392 return err;
1393}
1394
1395static int
Alex Aizman0896b752005-08-04 19:33:07 -07001396iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1397{
1398 int err = 0;
1399 struct iscsi_uevent *ev = NLMSG_DATA(nlh);
1400 struct iscsi_transport *transport = NULL;
1401 struct iscsi_internal *priv;
Mike Christie7b7232f2006-02-01 21:06:49 -06001402 struct iscsi_cls_session *session;
1403 struct iscsi_cls_conn *conn;
Mike Christied82ff9be2008-05-21 15:54:13 -05001404 struct iscsi_endpoint *ep = NULL;
Alex Aizman0896b752005-08-04 19:33:07 -07001405
Alex Aizman0896b752005-08-04 19:33:07 -07001406 priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle));
1407 if (!priv)
1408 return -EINVAL;
1409 transport = priv->iscsi_transport;
1410
Mike Christie7b7232f2006-02-01 21:06:49 -06001411 if (!try_module_get(transport->owner))
1412 return -EINVAL;
1413
Mike Christie790f39a2006-05-18 20:31:39 -05001414 priv->daemon_pid = NETLINK_CREDS(skb)->pid;
1415
Alex Aizman0896b752005-08-04 19:33:07 -07001416 switch (nlh->nlmsg_type) {
1417 case ISCSI_UEVENT_CREATE_SESSION:
Mike Christied82ff9be2008-05-21 15:54:13 -05001418 err = iscsi_if_create_session(priv, ep, ev,
Mike Christie40753ca2008-05-21 15:53:56 -05001419 ev->u.c_session.initial_cmdsn,
1420 ev->u.c_session.cmds_max,
1421 ev->u.c_session.queue_depth);
1422 break;
1423 case ISCSI_UEVENT_CREATE_BOUND_SESSION:
Mike Christied82ff9be2008-05-21 15:54:13 -05001424 ep = iscsi_lookup_endpoint(ev->u.c_bound_session.ep_handle);
Mike Christiec95fddc2008-06-16 10:11:32 -05001425 if (!ep) {
1426 err = -EINVAL;
1427 break;
1428 }
Mike Christied82ff9be2008-05-21 15:54:13 -05001429
1430 err = iscsi_if_create_session(priv, ep, ev,
Mike Christie40753ca2008-05-21 15:53:56 -05001431 ev->u.c_bound_session.initial_cmdsn,
1432 ev->u.c_bound_session.cmds_max,
1433 ev->u.c_bound_session.queue_depth);
Alex Aizman0896b752005-08-04 19:33:07 -07001434 break;
1435 case ISCSI_UEVENT_DESTROY_SESSION:
Mike Christieb5c7a122006-04-06 21:13:33 -05001436 session = iscsi_session_lookup(ev->u.d_session.sid);
Mike Christie26974782007-12-13 12:43:29 -06001437 if (session)
Mike Christie7b7232f2006-02-01 21:06:49 -06001438 transport->destroy_session(session);
Mike Christie26974782007-12-13 12:43:29 -06001439 else
1440 err = -EINVAL;
1441 break;
1442 case ISCSI_UEVENT_UNBIND_SESSION:
1443 session = iscsi_session_lookup(ev->u.d_session.sid);
1444 if (session)
1445 iscsi_unbind_session(session);
1446 else
Mike Christie7b7232f2006-02-01 21:06:49 -06001447 err = -EINVAL;
Alex Aizman0896b752005-08-04 19:33:07 -07001448 break;
1449 case ISCSI_UEVENT_CREATE_CONN:
1450 err = iscsi_if_create_conn(transport, ev);
1451 break;
1452 case ISCSI_UEVENT_DESTROY_CONN:
1453 err = iscsi_if_destroy_conn(transport, ev);
1454 break;
1455 case ISCSI_UEVENT_BIND_CONN:
Mike Christieb5c7a122006-04-06 21:13:33 -05001456 session = iscsi_session_lookup(ev->u.b_conn.sid);
1457 conn = iscsi_conn_lookup(ev->u.b_conn.sid, ev->u.b_conn.cid);
Mike Christie7b7232f2006-02-01 21:06:49 -06001458
1459 if (session && conn)
1460 ev->r.retcode = transport->bind_conn(session, conn,
Or Gerlitz264faaa2006-05-02 19:46:36 -05001461 ev->u.b_conn.transport_eph,
Mike Christie7b7232f2006-02-01 21:06:49 -06001462 ev->u.b_conn.is_leading);
1463 else
1464 err = -EINVAL;
Alex Aizman0896b752005-08-04 19:33:07 -07001465 break;
1466 case ISCSI_UEVENT_SET_PARAM:
Mike Christiefd7255f2006-04-06 21:13:36 -05001467 err = iscsi_set_param(transport, ev);
Alex Aizman0896b752005-08-04 19:33:07 -07001468 break;
1469 case ISCSI_UEVENT_START_CONN:
Mike Christieb5c7a122006-04-06 21:13:33 -05001470 conn = iscsi_conn_lookup(ev->u.start_conn.sid, ev->u.start_conn.cid);
Mike Christie7b7232f2006-02-01 21:06:49 -06001471 if (conn)
1472 ev->r.retcode = transport->start_conn(conn);
1473 else
1474 err = -EINVAL;
Alex Aizman0896b752005-08-04 19:33:07 -07001475 break;
1476 case ISCSI_UEVENT_STOP_CONN:
Mike Christieb5c7a122006-04-06 21:13:33 -05001477 conn = iscsi_conn_lookup(ev->u.stop_conn.sid, ev->u.stop_conn.cid);
Mike Christie7b7232f2006-02-01 21:06:49 -06001478 if (conn)
1479 transport->stop_conn(conn, ev->u.stop_conn.flag);
1480 else
1481 err = -EINVAL;
Alex Aizman0896b752005-08-04 19:33:07 -07001482 break;
1483 case ISCSI_UEVENT_SEND_PDU:
Mike Christieb5c7a122006-04-06 21:13:33 -05001484 conn = iscsi_conn_lookup(ev->u.send_pdu.sid, ev->u.send_pdu.cid);
Mike Christie7b7232f2006-02-01 21:06:49 -06001485 if (conn)
1486 ev->r.retcode = transport->send_pdu(conn,
1487 (struct iscsi_hdr*)((char*)ev + sizeof(*ev)),
1488 (char*)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size,
1489 ev->u.send_pdu.data_size);
1490 else
1491 err = -EINVAL;
Alex Aizman0896b752005-08-04 19:33:07 -07001492 break;
1493 case ISCSI_UEVENT_GET_STATS:
Mike Christie5b940ad2006-02-01 21:06:56 -06001494 err = iscsi_if_get_stats(transport, nlh);
Alex Aizman0896b752005-08-04 19:33:07 -07001495 break;
Or Gerlitz264faaa2006-05-02 19:46:36 -05001496 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
1497 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
1498 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
1499 err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type);
1500 break;
Mike Christie01cb2252006-06-28 12:00:22 -05001501 case ISCSI_UEVENT_TGT_DSCVR:
1502 err = iscsi_tgt_dscvr(transport, ev);
1503 break;
Mike Christie1d9bf132007-05-30 12:57:11 -05001504 case ISCSI_UEVENT_SET_HOST_PARAM:
1505 err = iscsi_set_host_param(transport, ev);
1506 break;
Alex Aizman0896b752005-08-04 19:33:07 -07001507 default:
Mike Christie1d9bf132007-05-30 12:57:11 -05001508 err = -ENOSYS;
Alex Aizman0896b752005-08-04 19:33:07 -07001509 break;
1510 }
1511
Mike Christie7b7232f2006-02-01 21:06:49 -06001512 module_put(transport->owner);
Alex Aizman0896b752005-08-04 19:33:07 -07001513 return err;
1514}
1515
Mike Christieb5c7a122006-04-06 21:13:33 -05001516/*
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07001517 * Get message from skb. Each message is processed by iscsi_if_recv_msg.
1518 * Malformed skbs with wrong lengths or invalid creds are not processed.
Mike Christieb5c7a122006-04-06 21:13:33 -05001519 */
Alex Aizman0896b752005-08-04 19:33:07 -07001520static void
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07001521iscsi_if_rx(struct sk_buff *skb)
Alex Aizman0896b752005-08-04 19:33:07 -07001522{
Arjan van de Ven0b950672006-01-11 13:16:10 +01001523 mutex_lock(&rx_queue_mutex);
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07001524 while (skb->len >= NLMSG_SPACE(0)) {
1525 int err;
1526 uint32_t rlen;
1527 struct nlmsghdr *nlh;
1528 struct iscsi_uevent *ev;
1529
1530 nlh = nlmsg_hdr(skb);
1531 if (nlh->nlmsg_len < sizeof(*nlh) ||
1532 skb->len < nlh->nlmsg_len) {
1533 break;
Mike Christieee7f8e42006-02-01 21:07:01 -06001534 }
Mike Christieee7f8e42006-02-01 21:07:01 -06001535
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07001536 ev = NLMSG_DATA(nlh);
1537 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
1538 if (rlen > skb->len)
1539 rlen = skb->len;
Alex Aizman0896b752005-08-04 19:33:07 -07001540
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07001541 err = iscsi_if_recv_msg(skb, nlh);
1542 if (err) {
1543 ev->type = ISCSI_KEVENT_IF_ERROR;
1544 ev->iferror = err;
1545 }
1546 do {
1547 /*
1548 * special case for GET_STATS:
1549 * on success - sending reply and stats from
1550 * inside of if_recv_msg(),
1551 * on error - fall through.
1552 */
1553 if (ev->type == ISCSI_UEVENT_GET_STATS && !err)
Alex Aizman0896b752005-08-04 19:33:07 -07001554 break;
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07001555 err = iscsi_if_send_reply(
1556 NETLINK_CREDS(skb)->pid, nlh->nlmsg_seq,
1557 nlh->nlmsg_type, 0, 0, ev, sizeof(*ev));
1558 } while (err < 0 && err != -ECONNREFUSED);
1559 skb_pull(skb, rlen);
Alex Aizman0896b752005-08-04 19:33:07 -07001560 }
Arjan van de Ven0b950672006-01-11 13:16:10 +01001561 mutex_unlock(&rx_queue_mutex);
Alex Aizman0896b752005-08-04 19:33:07 -07001562}
1563
Mike Christiefd7255f2006-04-06 21:13:36 -05001564#define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \
Tony Jonesee959b02008-02-22 00:13:36 +01001565struct device_attribute dev_attr_##_prefix##_##_name = \
Mike Christiefd7255f2006-04-06 21:13:36 -05001566 __ATTR(_name,_mode,_show,_store)
1567
Alex Aizman0896b752005-08-04 19:33:07 -07001568/*
1569 * iSCSI connection attrs
1570 */
Mike Christiea54a52c2006-06-28 12:00:23 -05001571#define iscsi_conn_attr_show(param) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001573show_conn_param_##param(struct device *dev, \
1574 struct device_attribute *attr, char *buf) \
Mike Christiefd7255f2006-04-06 21:13:36 -05001575{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001576 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
Mike Christiefd7255f2006-04-06 21:13:36 -05001577 struct iscsi_transport *t = conn->transport; \
Mike Christiea54a52c2006-06-28 12:00:23 -05001578 return t->get_conn_param(conn, param, buf); \
Mike Christiefd7255f2006-04-06 21:13:36 -05001579}
1580
Mike Christiea54a52c2006-06-28 12:00:23 -05001581#define iscsi_conn_attr(field, param) \
1582 iscsi_conn_attr_show(param) \
1583static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \
Mike Christiefd7255f2006-04-06 21:13:36 -05001584 NULL);
1585
Mike Christiea54a52c2006-06-28 12:00:23 -05001586iscsi_conn_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH);
1587iscsi_conn_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH);
1588iscsi_conn_attr(header_digest, ISCSI_PARAM_HDRDGST_EN);
1589iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN);
1590iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN);
1591iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN);
1592iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT);
1593iscsi_conn_attr(port, ISCSI_PARAM_CONN_PORT);
1594iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN);
1595iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS);
1596iscsi_conn_attr(address, ISCSI_PARAM_CONN_ADDRESS);
Mike Christief6d51802007-12-13 12:43:30 -06001597iscsi_conn_attr(ping_tmo, ISCSI_PARAM_PING_TMO);
1598iscsi_conn_attr(recv_tmo, ISCSI_PARAM_RECV_TMO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
1600/*
Alex Aizman0896b752005-08-04 19:33:07 -07001601 * iSCSI session attrs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 */
Mike Christieb2c64162007-05-30 12:57:16 -05001603#define iscsi_session_attr_show(param, perm) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001605show_session_param_##param(struct device *dev, \
1606 struct device_attribute *attr, char *buf) \
Mike Christiefd7255f2006-04-06 21:13:36 -05001607{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001608 struct iscsi_cls_session *session = \
1609 iscsi_dev_to_session(dev->parent); \
Mike Christiefd7255f2006-04-06 21:13:36 -05001610 struct iscsi_transport *t = session->transport; \
Mike Christieb2c64162007-05-30 12:57:16 -05001611 \
1612 if (perm && !capable(CAP_SYS_ADMIN)) \
1613 return -EACCES; \
Mike Christiea54a52c2006-06-28 12:00:23 -05001614 return t->get_session_param(session, param, buf); \
Mike Christiefd7255f2006-04-06 21:13:36 -05001615}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
Mike Christieb2c64162007-05-30 12:57:16 -05001617#define iscsi_session_attr(field, param, perm) \
1618 iscsi_session_attr_show(param, perm) \
Mike Christiea54a52c2006-06-28 12:00:23 -05001619static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \
Mike Christiefd7255f2006-04-06 21:13:36 -05001620 NULL);
1621
Mike Christieb2c64162007-05-30 12:57:16 -05001622iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME, 0);
1623iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, 0);
1624iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, 0);
1625iscsi_session_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, 0);
1626iscsi_session_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, 0);
1627iscsi_session_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, 0);
1628iscsi_session_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, 0);
1629iscsi_session_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, 0);
1630iscsi_session_attr(erl, ISCSI_PARAM_ERL, 0);
1631iscsi_session_attr(tpgt, ISCSI_PARAM_TPGT, 0);
1632iscsi_session_attr(username, ISCSI_PARAM_USERNAME, 1);
1633iscsi_session_attr(username_in, ISCSI_PARAM_USERNAME_IN, 1);
1634iscsi_session_attr(password, ISCSI_PARAM_PASSWORD, 1);
1635iscsi_session_attr(password_in, ISCSI_PARAM_PASSWORD_IN, 1);
Mike Christie4cd49ea2007-12-13 12:43:38 -06001636iscsi_session_attr(fast_abort, ISCSI_PARAM_FAST_ABORT, 0);
1637iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0);
1638iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0);
Mike Christie88dfd342008-05-21 15:54:16 -05001639iscsi_session_attr(ifacename, ISCSI_PARAM_IFACE_NAME, 0);
1640iscsi_session_attr(initiatorname, ISCSI_PARAM_INITIATOR_NAME, 0)
Mike Christiefd7255f2006-04-06 21:13:36 -05001641
Mike Christie6eabafb2008-01-31 13:36:43 -06001642static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001643show_priv_session_state(struct device *dev, struct device_attribute *attr,
1644 char *buf)
Mike Christie6eabafb2008-01-31 13:36:43 -06001645{
Tony Jonesee959b02008-02-22 00:13:36 +01001646 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
Mike Christie6eabafb2008-01-31 13:36:43 -06001647 return sprintf(buf, "%s\n", iscsi_session_state_name(session->state));
1648}
1649static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state,
1650 NULL);
1651
Mike Christiefd7255f2006-04-06 21:13:36 -05001652#define iscsi_priv_session_attr_show(field, format) \
1653static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001654show_priv_session_##field(struct device *dev, \
1655 struct device_attribute *attr, char *buf) \
Mike Christiefd7255f2006-04-06 21:13:36 -05001656{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001657 struct iscsi_cls_session *session = \
1658 iscsi_dev_to_session(dev->parent); \
Mike Christiefd7255f2006-04-06 21:13:36 -05001659 return sprintf(buf, format"\n", session->field); \
1660}
1661
1662#define iscsi_priv_session_attr(field, format) \
1663 iscsi_priv_session_attr_show(field, format) \
1664static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO, show_priv_session_##field, \
1665 NULL)
Mike Christie30a6c652006-04-06 21:13:39 -05001666iscsi_priv_session_attr(recovery_tmo, "%d");
Mike Christiefd7255f2006-04-06 21:13:36 -05001667
Mike Christie1819dc82007-05-30 12:57:08 -05001668/*
1669 * iSCSI host attrs
1670 */
1671#define iscsi_host_attr_show(param) \
1672static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001673show_host_param_##param(struct device *dev, \
1674 struct device_attribute *attr, char *buf) \
Mike Christie1819dc82007-05-30 12:57:08 -05001675{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001676 struct Scsi_Host *shost = transport_class_to_shost(dev); \
Mike Christie1819dc82007-05-30 12:57:08 -05001677 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); \
1678 return priv->iscsi_transport->get_host_param(shost, param, buf); \
1679}
1680
1681#define iscsi_host_attr(field, param) \
1682 iscsi_host_attr_show(param) \
1683static ISCSI_CLASS_ATTR(host, field, S_IRUGO, show_host_param_##param, \
1684 NULL);
1685
Mike Christied8196ed2007-05-30 12:57:25 -05001686iscsi_host_attr(netdev, ISCSI_HOST_PARAM_NETDEV_NAME);
Mike Christie1819dc82007-05-30 12:57:08 -05001687iscsi_host_attr(hwaddress, ISCSI_HOST_PARAM_HWADDRESS);
Mike Christied8196ed2007-05-30 12:57:25 -05001688iscsi_host_attr(ipaddress, ISCSI_HOST_PARAM_IPADDRESS);
Mike Christie8ad57812007-05-30 12:57:13 -05001689iscsi_host_attr(initiatorname, ISCSI_HOST_PARAM_INITIATOR_NAME);
Mike Christie1819dc82007-05-30 12:57:08 -05001690
Mike Christiefd7255f2006-04-06 21:13:36 -05001691#define SETUP_PRIV_SESSION_RD_ATTR(field) \
1692do { \
Tony Jonesee959b02008-02-22 00:13:36 +01001693 priv->session_attrs[count] = &dev_attr_priv_sess_##field; \
Mike Christiefd7255f2006-04-06 21:13:36 -05001694 count++; \
1695} while (0)
1696
Mike Christiea54a52c2006-06-28 12:00:23 -05001697
Mike Christiefd7255f2006-04-06 21:13:36 -05001698#define SETUP_SESSION_RD_ATTR(field, param_flag) \
1699do { \
1700 if (tt->param_mask & param_flag) { \
Tony Jonesee959b02008-02-22 00:13:36 +01001701 priv->session_attrs[count] = &dev_attr_sess_##field; \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 count++; \
Mike Christiefd7255f2006-04-06 21:13:36 -05001703 } \
1704} while (0)
1705
Mike Christiefd7255f2006-04-06 21:13:36 -05001706#define SETUP_CONN_RD_ATTR(field, param_flag) \
1707do { \
1708 if (tt->param_mask & param_flag) { \
Tony Jonesee959b02008-02-22 00:13:36 +01001709 priv->conn_attrs[count] = &dev_attr_conn_##field; \
Mike Christiefd7255f2006-04-06 21:13:36 -05001710 count++; \
1711 } \
1712} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713
Mike Christie1819dc82007-05-30 12:57:08 -05001714#define SETUP_HOST_RD_ATTR(field, param_flag) \
1715do { \
1716 if (tt->host_param_mask & param_flag) { \
Tony Jonesee959b02008-02-22 00:13:36 +01001717 priv->host_attrs[count] = &dev_attr_host_##field; \
Mike Christie1819dc82007-05-30 12:57:08 -05001718 count++; \
1719 } \
1720} while (0)
1721
Alex Aizman0896b752005-08-04 19:33:07 -07001722static int iscsi_session_match(struct attribute_container *cont,
1723 struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724{
Mike Christie7b8631b2006-01-13 18:05:50 -06001725 struct iscsi_cls_session *session;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 struct Scsi_Host *shost;
Alex Aizman0896b752005-08-04 19:33:07 -07001727 struct iscsi_internal *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
Alex Aizman0896b752005-08-04 19:33:07 -07001729 if (!iscsi_is_session_dev(dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 return 0;
1731
Mike Christie7b8631b2006-01-13 18:05:50 -06001732 session = iscsi_dev_to_session(dev);
1733 shost = iscsi_session_to_shost(session);
Alex Aizman0896b752005-08-04 19:33:07 -07001734 if (!shost->transportt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 return 0;
1736
Alex Aizman0896b752005-08-04 19:33:07 -07001737 priv = to_iscsi_internal(shost->transportt);
1738 if (priv->session_cont.ac.class != &iscsi_session_class.class)
1739 return 0;
1740
1741 return &priv->session_cont.ac == cont;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742}
1743
Alex Aizman0896b752005-08-04 19:33:07 -07001744static int iscsi_conn_match(struct attribute_container *cont,
1745 struct device *dev)
1746{
Mike Christie7b8631b2006-01-13 18:05:50 -06001747 struct iscsi_cls_session *session;
1748 struct iscsi_cls_conn *conn;
Alex Aizman0896b752005-08-04 19:33:07 -07001749 struct Scsi_Host *shost;
1750 struct iscsi_internal *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
Alex Aizman0896b752005-08-04 19:33:07 -07001752 if (!iscsi_is_conn_dev(dev))
1753 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
Mike Christie7b8631b2006-01-13 18:05:50 -06001755 conn = iscsi_dev_to_conn(dev);
1756 session = iscsi_dev_to_session(conn->dev.parent);
1757 shost = iscsi_session_to_shost(session);
1758
Alex Aizman0896b752005-08-04 19:33:07 -07001759 if (!shost->transportt)
1760 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761
Alex Aizman0896b752005-08-04 19:33:07 -07001762 priv = to_iscsi_internal(shost->transportt);
1763 if (priv->conn_cont.ac.class != &iscsi_connection_class.class)
1764 return 0;
1765
1766 return &priv->conn_cont.ac == cont;
1767}
1768
Mike Christie30a6c652006-04-06 21:13:39 -05001769static int iscsi_host_match(struct attribute_container *cont,
1770 struct device *dev)
1771{
1772 struct Scsi_Host *shost;
1773 struct iscsi_internal *priv;
1774
1775 if (!scsi_is_host_device(dev))
1776 return 0;
1777
1778 shost = dev_to_shost(dev);
1779 if (!shost->transportt ||
1780 shost->transportt->host_attrs.ac.class != &iscsi_host_class.class)
1781 return 0;
1782
1783 priv = to_iscsi_internal(shost->transportt);
1784 return &priv->t.host_attrs.ac == cont;
1785}
1786
Mike Christie7b8631b2006-01-13 18:05:50 -06001787struct scsi_transport_template *
1788iscsi_register_transport(struct iscsi_transport *tt)
Alex Aizman0896b752005-08-04 19:33:07 -07001789{
1790 struct iscsi_internal *priv;
1791 unsigned long flags;
1792 int count = 0, err;
1793
1794 BUG_ON(!tt);
1795
1796 priv = iscsi_if_transport_lookup(tt);
1797 if (priv)
Mike Christie7b8631b2006-01-13 18:05:50 -06001798 return NULL;
Alex Aizman0896b752005-08-04 19:33:07 -07001799
Jes Sorensen24669f752006-01-16 10:31:18 -05001800 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
Alex Aizman0896b752005-08-04 19:33:07 -07001801 if (!priv)
Mike Christie7b8631b2006-01-13 18:05:50 -06001802 return NULL;
Alex Aizman0896b752005-08-04 19:33:07 -07001803 INIT_LIST_HEAD(&priv->list);
Mike Christie53cb8a12006-06-28 12:00:32 -05001804 priv->daemon_pid = -1;
Alex Aizman0896b752005-08-04 19:33:07 -07001805 priv->iscsi_transport = tt;
Mike Christie30a6c652006-04-06 21:13:39 -05001806 priv->t.user_scan = iscsi_user_scan;
Mike Christiea4804cd2008-05-21 15:54:00 -05001807 if (!(tt->caps & CAP_DATA_PATH_OFFLOAD))
1808 priv->t.create_work_queue = 1;
Alex Aizman0896b752005-08-04 19:33:07 -07001809
Tony Jonesee959b02008-02-22 00:13:36 +01001810 priv->dev.class = &iscsi_transport_class;
1811 snprintf(priv->dev.bus_id, BUS_ID_SIZE, "%s", tt->name);
1812 err = device_register(&priv->dev);
Alex Aizman0896b752005-08-04 19:33:07 -07001813 if (err)
1814 goto free_priv;
1815
Tony Jonesee959b02008-02-22 00:13:36 +01001816 err = sysfs_create_group(&priv->dev.kobj, &iscsi_transport_group);
Alex Aizman0896b752005-08-04 19:33:07 -07001817 if (err)
Tony Jonesee959b02008-02-22 00:13:36 +01001818 goto unregister_dev;
Alex Aizman0896b752005-08-04 19:33:07 -07001819
Mike Christie30a6c652006-04-06 21:13:39 -05001820 /* host parameters */
1821 priv->t.host_attrs.ac.attrs = &priv->host_attrs[0];
1822 priv->t.host_attrs.ac.class = &iscsi_host_class.class;
1823 priv->t.host_attrs.ac.match = iscsi_host_match;
Mike Christie32c6e1b2008-05-21 15:53:58 -05001824 priv->t.host_size = sizeof(struct iscsi_cls_host);
Mike Christie30a6c652006-04-06 21:13:39 -05001825 transport_container_register(&priv->t.host_attrs);
1826
Mike Christied8196ed2007-05-30 12:57:25 -05001827 SETUP_HOST_RD_ATTR(netdev, ISCSI_HOST_NETDEV_NAME);
Mike Christie22236962007-05-30 12:57:24 -05001828 SETUP_HOST_RD_ATTR(ipaddress, ISCSI_HOST_IPADDRESS);
Mike Christie1819dc82007-05-30 12:57:08 -05001829 SETUP_HOST_RD_ATTR(hwaddress, ISCSI_HOST_HWADDRESS);
Mike Christie8ad57812007-05-30 12:57:13 -05001830 SETUP_HOST_RD_ATTR(initiatorname, ISCSI_HOST_INITIATOR_NAME);
Mike Christie1819dc82007-05-30 12:57:08 -05001831 BUG_ON(count > ISCSI_HOST_ATTRS);
1832 priv->host_attrs[count] = NULL;
1833 count = 0;
1834
Alex Aizman0896b752005-08-04 19:33:07 -07001835 /* connection parameters */
1836 priv->conn_cont.ac.attrs = &priv->conn_attrs[0];
1837 priv->conn_cont.ac.class = &iscsi_connection_class.class;
1838 priv->conn_cont.ac.match = iscsi_conn_match;
1839 transport_container_register(&priv->conn_cont);
1840
Mike Christiefd7255f2006-04-06 21:13:36 -05001841 SETUP_CONN_RD_ATTR(max_recv_dlength, ISCSI_MAX_RECV_DLENGTH);
1842 SETUP_CONN_RD_ATTR(max_xmit_dlength, ISCSI_MAX_XMIT_DLENGTH);
1843 SETUP_CONN_RD_ATTR(header_digest, ISCSI_HDRDGST_EN);
1844 SETUP_CONN_RD_ATTR(data_digest, ISCSI_DATADGST_EN);
1845 SETUP_CONN_RD_ATTR(ifmarker, ISCSI_IFMARKER_EN);
1846 SETUP_CONN_RD_ATTR(ofmarker, ISCSI_OFMARKER_EN);
1847 SETUP_CONN_RD_ATTR(address, ISCSI_CONN_ADDRESS);
1848 SETUP_CONN_RD_ATTR(port, ISCSI_CONN_PORT);
Mike Christie8d2860b2006-05-02 19:46:47 -05001849 SETUP_CONN_RD_ATTR(exp_statsn, ISCSI_EXP_STATSN);
Mike Christiea54a52c2006-06-28 12:00:23 -05001850 SETUP_CONN_RD_ATTR(persistent_address, ISCSI_PERSISTENT_ADDRESS);
1851 SETUP_CONN_RD_ATTR(persistent_port, ISCSI_PERSISTENT_PORT);
Mike Christief6d51802007-12-13 12:43:30 -06001852 SETUP_CONN_RD_ATTR(ping_tmo, ISCSI_PING_TMO);
1853 SETUP_CONN_RD_ATTR(recv_tmo, ISCSI_RECV_TMO);
Alex Aizman0896b752005-08-04 19:33:07 -07001854
1855 BUG_ON(count > ISCSI_CONN_ATTRS);
1856 priv->conn_attrs[count] = NULL;
1857 count = 0;
1858
1859 /* session parameters */
1860 priv->session_cont.ac.attrs = &priv->session_attrs[0];
1861 priv->session_cont.ac.class = &iscsi_session_class.class;
1862 priv->session_cont.ac.match = iscsi_session_match;
1863 transport_container_register(&priv->session_cont);
1864
Mike Christiefd7255f2006-04-06 21:13:36 -05001865 SETUP_SESSION_RD_ATTR(initial_r2t, ISCSI_INITIAL_R2T_EN);
1866 SETUP_SESSION_RD_ATTR(max_outstanding_r2t, ISCSI_MAX_R2T);
1867 SETUP_SESSION_RD_ATTR(immediate_data, ISCSI_IMM_DATA_EN);
1868 SETUP_SESSION_RD_ATTR(first_burst_len, ISCSI_FIRST_BURST);
1869 SETUP_SESSION_RD_ATTR(max_burst_len, ISCSI_MAX_BURST);
1870 SETUP_SESSION_RD_ATTR(data_pdu_in_order, ISCSI_PDU_INORDER_EN);
1871 SETUP_SESSION_RD_ATTR(data_seq_in_order, ISCSI_DATASEQ_INORDER_EN);
1872 SETUP_SESSION_RD_ATTR(erl, ISCSI_ERL);
Mike Christiea54a52c2006-06-28 12:00:23 -05001873 SETUP_SESSION_RD_ATTR(targetname, ISCSI_TARGET_NAME);
1874 SETUP_SESSION_RD_ATTR(tpgt, ISCSI_TPGT);
Mike Christieb2c64162007-05-30 12:57:16 -05001875 SETUP_SESSION_RD_ATTR(password, ISCSI_USERNAME);
1876 SETUP_SESSION_RD_ATTR(password_in, ISCSI_USERNAME_IN);
1877 SETUP_SESSION_RD_ATTR(username, ISCSI_PASSWORD);
1878 SETUP_SESSION_RD_ATTR(username_in, ISCSI_PASSWORD_IN);
Mike Christie843c0a82007-12-13 12:43:20 -06001879 SETUP_SESSION_RD_ATTR(fast_abort, ISCSI_FAST_ABORT);
Mike Christie4cd49ea2007-12-13 12:43:38 -06001880 SETUP_SESSION_RD_ATTR(abort_tmo, ISCSI_ABORT_TMO);
1881 SETUP_SESSION_RD_ATTR(lu_reset_tmo,ISCSI_LU_RESET_TMO);
Mike Christie88dfd342008-05-21 15:54:16 -05001882 SETUP_SESSION_RD_ATTR(ifacename, ISCSI_IFACE_NAME);
1883 SETUP_SESSION_RD_ATTR(initiatorname, ISCSI_INITIATOR_NAME);
Mike Christie30a6c652006-04-06 21:13:39 -05001884 SETUP_PRIV_SESSION_RD_ATTR(recovery_tmo);
Mike Christie6eabafb2008-01-31 13:36:43 -06001885 SETUP_PRIV_SESSION_RD_ATTR(state);
Mike Christiefd7255f2006-04-06 21:13:36 -05001886
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 BUG_ON(count > ISCSI_SESSION_ATTRS);
Alex Aizman0896b752005-08-04 19:33:07 -07001888 priv->session_attrs[count] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889
Alex Aizman0896b752005-08-04 19:33:07 -07001890 spin_lock_irqsave(&iscsi_transport_lock, flags);
1891 list_add(&priv->list, &iscsi_transports);
1892 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Alex Aizman0896b752005-08-04 19:33:07 -07001894 printk(KERN_NOTICE "iscsi: registered transport (%s)\n", tt->name);
Mike Christie7b8631b2006-01-13 18:05:50 -06001895 return &priv->t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
Tony Jonesee959b02008-02-22 00:13:36 +01001897unregister_dev:
1898 device_unregister(&priv->dev);
Mike Christied82ff9be2008-05-21 15:54:13 -05001899 return NULL;
Alex Aizman0896b752005-08-04 19:33:07 -07001900free_priv:
1901 kfree(priv);
Mike Christie7b8631b2006-01-13 18:05:50 -06001902 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903}
Alex Aizman0896b752005-08-04 19:33:07 -07001904EXPORT_SYMBOL_GPL(iscsi_register_transport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905
Alex Aizman0896b752005-08-04 19:33:07 -07001906int iscsi_unregister_transport(struct iscsi_transport *tt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907{
Alex Aizman0896b752005-08-04 19:33:07 -07001908 struct iscsi_internal *priv;
1909 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910
Alex Aizman0896b752005-08-04 19:33:07 -07001911 BUG_ON(!tt);
1912
Arjan van de Ven0b950672006-01-11 13:16:10 +01001913 mutex_lock(&rx_queue_mutex);
Alex Aizman0896b752005-08-04 19:33:07 -07001914
1915 priv = iscsi_if_transport_lookup(tt);
1916 BUG_ON (!priv);
1917
Alex Aizman0896b752005-08-04 19:33:07 -07001918 spin_lock_irqsave(&iscsi_transport_lock, flags);
1919 list_del(&priv->list);
1920 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
1921
1922 transport_container_unregister(&priv->conn_cont);
1923 transport_container_unregister(&priv->session_cont);
Mike Christie30a6c652006-04-06 21:13:39 -05001924 transport_container_unregister(&priv->t.host_attrs);
Alex Aizman0896b752005-08-04 19:33:07 -07001925
Tony Jonesee959b02008-02-22 00:13:36 +01001926 sysfs_remove_group(&priv->dev.kobj, &iscsi_transport_group);
1927 device_unregister(&priv->dev);
Arjan van de Ven0b950672006-01-11 13:16:10 +01001928 mutex_unlock(&rx_queue_mutex);
Alex Aizman0896b752005-08-04 19:33:07 -07001929
1930 return 0;
1931}
1932EXPORT_SYMBOL_GPL(iscsi_unregister_transport);
1933
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934static __init int iscsi_transport_init(void)
1935{
Alex Aizman0896b752005-08-04 19:33:07 -07001936 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937
Meelis Roos09492602006-12-17 12:10:26 -06001938 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
Mike Christief4246b32006-07-24 15:47:54 -05001939 ISCSI_TRANSPORT_VERSION);
1940
Mike Christie41be1442007-02-28 17:32:18 -06001941 atomic_set(&iscsi_session_nr, 0);
1942
Alex Aizman0896b752005-08-04 19:33:07 -07001943 err = class_register(&iscsi_transport_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944 if (err)
1945 return err;
Alex Aizman0896b752005-08-04 19:33:07 -07001946
Mike Christied82ff9be2008-05-21 15:54:13 -05001947 err = class_register(&iscsi_endpoint_class);
Alex Aizman0896b752005-08-04 19:33:07 -07001948 if (err)
1949 goto unregister_transport_class;
1950
Mike Christied82ff9be2008-05-21 15:54:13 -05001951 err = transport_class_register(&iscsi_host_class);
1952 if (err)
1953 goto unregister_endpoint_class;
1954
Mike Christie30a6c652006-04-06 21:13:39 -05001955 err = transport_class_register(&iscsi_connection_class);
1956 if (err)
1957 goto unregister_host_class;
1958
Alex Aizman0896b752005-08-04 19:33:07 -07001959 err = transport_class_register(&iscsi_session_class);
1960 if (err)
1961 goto unregister_conn_class;
1962
Mike Christied82ff9be2008-05-21 15:54:13 -05001963 nls = netlink_kernel_create(&init_net, NETLINK_ISCSI, 1, iscsi_if_rx,
1964 NULL, THIS_MODULE);
Alex Aizman0896b752005-08-04 19:33:07 -07001965 if (!nls) {
1966 err = -ENOBUFS;
Mike Christie43a145a2006-10-16 18:09:38 -04001967 goto unregister_session_class;
Alex Aizman0896b752005-08-04 19:33:07 -07001968 }
1969
Mike Christied8bf5412007-12-13 12:43:27 -06001970 iscsi_eh_timer_workq = create_singlethread_workqueue("iscsi_eh");
1971 if (!iscsi_eh_timer_workq)
1972 goto release_nls;
1973
Mike Christie43a145a2006-10-16 18:09:38 -04001974 return 0;
Alex Aizman0896b752005-08-04 19:33:07 -07001975
Mike Christied8bf5412007-12-13 12:43:27 -06001976release_nls:
Denis V. Lunevb7c6ba62008-01-28 14:41:19 -08001977 netlink_kernel_release(nls);
Alex Aizman0896b752005-08-04 19:33:07 -07001978unregister_session_class:
1979 transport_class_unregister(&iscsi_session_class);
1980unregister_conn_class:
1981 transport_class_unregister(&iscsi_connection_class);
Mike Christie30a6c652006-04-06 21:13:39 -05001982unregister_host_class:
1983 transport_class_unregister(&iscsi_host_class);
Mike Christied82ff9be2008-05-21 15:54:13 -05001984unregister_endpoint_class:
1985 class_unregister(&iscsi_endpoint_class);
Alex Aizman0896b752005-08-04 19:33:07 -07001986unregister_transport_class:
1987 class_unregister(&iscsi_transport_class);
1988 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989}
1990
1991static void __exit iscsi_transport_exit(void)
1992{
Mike Christied8bf5412007-12-13 12:43:27 -06001993 destroy_workqueue(iscsi_eh_timer_workq);
Denis V. Lunevb7c6ba62008-01-28 14:41:19 -08001994 netlink_kernel_release(nls);
Alex Aizman0896b752005-08-04 19:33:07 -07001995 transport_class_unregister(&iscsi_connection_class);
1996 transport_class_unregister(&iscsi_session_class);
Mike Christie30a6c652006-04-06 21:13:39 -05001997 transport_class_unregister(&iscsi_host_class);
Mike Christied82ff9be2008-05-21 15:54:13 -05001998 class_unregister(&iscsi_endpoint_class);
Alex Aizman0896b752005-08-04 19:33:07 -07001999 class_unregister(&iscsi_transport_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000}
2001
2002module_init(iscsi_transport_init);
2003module_exit(iscsi_transport_exit);
2004
Alex Aizman0896b752005-08-04 19:33:07 -07002005MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
2006 "Dmitry Yusupov <dmitry_yus@yahoo.com>, "
2007 "Alex Aizman <itn780@yahoo.com>");
2008MODULE_DESCRIPTION("iSCSI Transport Interface");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009MODULE_LICENSE("GPL");
Mike Christief4246b32006-07-24 15:47:54 -05002010MODULE_VERSION(ISCSI_TRANSPORT_VERSION);