blob: 0a2ce7b6325cdbf13d5aceda17add03898567f24 [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 Christie4c2133c2008-06-16 10:11:34 -050037#define ISCSI_TRANSPORT_VERSION "2.0-870"
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);
Mike Christie21536062008-09-24 11:46:11 -0500141 return sprintf(buf, "%llu\n", (unsigned long long) ep->id);
Mike Christied82ff9be2008-05-21 15:54:13 -0500142}
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);
Mike Christie21536062008-09-24 11:46:11 -0500159 uint64_t *epid = (uint64_t *) data;
Mike Christied82ff9be2008-05-21 15:54:13 -0500160
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;
Mike Christie21536062008-09-24 11:46:11 -0500169 uint64_t id;
Mike Christied82ff9be2008-05-21 15:54:13 -0500170 int err;
171
172 for (id = 1; id < ISCSI_MAX_EPID; id++) {
Greg Kroah-Hartman695794a2008-05-22 17:21:08 -0400173 dev = class_find_device(&iscsi_endpoint_class, NULL, &id,
Mike Christied82ff9be2008-05-21 15:54:13 -0500174 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;
Kay Sievers71610f52008-12-03 22:41:36 +0100190 dev_set_name(&ep->dev, "ep-%llu", (unsigned long long) id);
Mike Christied82ff9be2008-05-21 15:54:13 -0500191 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{
Mike Christief80f8682008-06-16 10:11:35 -0500222 struct iscsi_endpoint *ep;
Mike Christied82ff9be2008-05-21 15:54:13 -0500223 struct device *dev;
224
Greg Kroah-Hartman695794a2008-05-22 17:21:08 -0400225 dev = class_find_device(&iscsi_endpoint_class, NULL, &handle,
Mike Christied82ff9be2008-05-21 15:54:13 -0500226 iscsi_match_epid);
227 if (!dev)
228 return NULL;
229
Mike Christief80f8682008-06-16 10:11:35 -0500230 ep = iscsi_dev_to_endpoint(dev);
231 /*
232 * we can drop this now because the interface will prevent
233 * removals and lookups from racing.
234 */
235 put_device(dev);
236 return ep;
Mike Christied82ff9be2008-05-21 15:54:13 -0500237}
238EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint);
239
Mike Christie30a6c652006-04-06 21:13:39 -0500240static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
Tony Jonesee959b02008-02-22 00:13:36 +0100241 struct device *cdev)
Mike Christie30a6c652006-04-06 21:13:39 -0500242{
243 struct Scsi_Host *shost = dev_to_shost(dev);
Mike Christie32c6e1b2008-05-21 15:53:58 -0500244 struct iscsi_cls_host *ihost = shost->shost_data;
Mike Christie30a6c652006-04-06 21:13:39 -0500245
246 memset(ihost, 0, sizeof(*ihost));
Mike Christie8aae18a2008-01-31 13:36:48 -0600247 atomic_set(&ihost->nr_scans, 0);
Mike Christie79706342008-05-21 15:54:12 -0500248 mutex_init(&ihost->mutex);
Mike Christie30a6c652006-04-06 21:13:39 -0500249 return 0;
250}
251
252static DECLARE_TRANSPORT_CLASS(iscsi_host_class,
253 "iscsi_host",
254 iscsi_setup_host,
Mike Christie06d25af2009-03-05 14:46:02 -0600255 NULL,
Mike Christie30a6c652006-04-06 21:13:39 -0500256 NULL);
257
Alex Aizman0896b752005-08-04 19:33:07 -0700258static DECLARE_TRANSPORT_CLASS(iscsi_session_class,
259 "iscsi_session",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 NULL,
261 NULL,
262 NULL);
263
Alex Aizman0896b752005-08-04 19:33:07 -0700264static DECLARE_TRANSPORT_CLASS(iscsi_connection_class,
265 "iscsi_connection",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 NULL,
267 NULL,
268 NULL);
Alex Aizman0896b752005-08-04 19:33:07 -0700269
270static struct sock *nls;
Arjan van de Ven0b950672006-01-11 13:16:10 +0100271static DEFINE_MUTEX(rx_queue_mutex);
Alex Aizman0896b752005-08-04 19:33:07 -0700272
Mike Christie7b7232f2006-02-01 21:06:49 -0600273static LIST_HEAD(sesslist);
274static DEFINE_SPINLOCK(sesslock);
Alex Aizman0896b752005-08-04 19:33:07 -0700275static LIST_HEAD(connlist);
276static DEFINE_SPINLOCK(connlock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Mike Christieb5c7a122006-04-06 21:13:33 -0500278static uint32_t iscsi_conn_get_sid(struct iscsi_cls_conn *conn)
279{
280 struct iscsi_cls_session *sess = iscsi_dev_to_session(conn->dev.parent);
281 return sess->sid;
282}
283
284/*
285 * Returns the matching session to a given sid
286 */
287static struct iscsi_cls_session *iscsi_session_lookup(uint32_t sid)
Mike Christie7b7232f2006-02-01 21:06:49 -0600288{
289 unsigned long flags;
290 struct iscsi_cls_session *sess;
291
292 spin_lock_irqsave(&sesslock, flags);
293 list_for_each_entry(sess, &sesslist, sess_list) {
Mike Christieb5c7a122006-04-06 21:13:33 -0500294 if (sess->sid == sid) {
Mike Christie7b7232f2006-02-01 21:06:49 -0600295 spin_unlock_irqrestore(&sesslock, flags);
296 return sess;
297 }
298 }
299 spin_unlock_irqrestore(&sesslock, flags);
300 return NULL;
301}
302
Mike Christieb5c7a122006-04-06 21:13:33 -0500303/*
304 * Returns the matching connection to a given sid / cid tuple
305 */
306static struct iscsi_cls_conn *iscsi_conn_lookup(uint32_t sid, uint32_t cid)
Mike Christie7b7232f2006-02-01 21:06:49 -0600307{
308 unsigned long flags;
309 struct iscsi_cls_conn *conn;
310
311 spin_lock_irqsave(&connlock, flags);
312 list_for_each_entry(conn, &connlist, conn_list) {
Mike Christieb5c7a122006-04-06 21:13:33 -0500313 if ((conn->cid == cid) && (iscsi_conn_get_sid(conn) == sid)) {
Mike Christie7b7232f2006-02-01 21:06:49 -0600314 spin_unlock_irqrestore(&connlock, flags);
315 return conn;
316 }
317 }
318 spin_unlock_irqrestore(&connlock, flags);
319 return NULL;
320}
321
Mike Christie7b8631b2006-01-13 18:05:50 -0600322/*
323 * The following functions can be used by LLDs that allocate
324 * their own scsi_hosts or by software iscsi LLDs
325 */
Mike Christie6eabafb2008-01-31 13:36:43 -0600326static struct {
327 int value;
328 char *name;
329} iscsi_session_state_names[] = {
330 { ISCSI_SESSION_LOGGED_IN, "LOGGED_IN" },
331 { ISCSI_SESSION_FAILED, "FAILED" },
332 { ISCSI_SESSION_FREE, "FREE" },
333};
334
Adrian Bunk3b0f2082008-02-13 23:30:17 +0200335static const char *iscsi_session_state_name(int state)
Mike Christie6eabafb2008-01-31 13:36:43 -0600336{
337 int i;
338 char *name = NULL;
339
340 for (i = 0; i < ARRAY_SIZE(iscsi_session_state_names); i++) {
341 if (iscsi_session_state_names[i].value == state) {
342 name = iscsi_session_state_names[i].name;
343 break;
344 }
345 }
346 return name;
347}
348
349int iscsi_session_chkready(struct iscsi_cls_session *session)
350{
351 unsigned long flags;
352 int err;
353
354 spin_lock_irqsave(&session->lock, flags);
355 switch (session->state) {
356 case ISCSI_SESSION_LOGGED_IN:
357 err = 0;
358 break;
359 case ISCSI_SESSION_FAILED:
Andrew Vasquez9a1a69a12009-04-29 13:12:39 -0500360 err = DID_IMM_RETRY << 16;
Mike Christie6eabafb2008-01-31 13:36:43 -0600361 break;
362 case ISCSI_SESSION_FREE:
Mike Christie56d7fcf2008-08-19 18:45:26 -0500363 err = DID_TRANSPORT_FAILFAST << 16;
Mike Christie6eabafb2008-01-31 13:36:43 -0600364 break;
365 default:
366 err = DID_NO_CONNECT << 16;
367 break;
368 }
369 spin_unlock_irqrestore(&session->lock, flags);
370 return err;
371}
372EXPORT_SYMBOL_GPL(iscsi_session_chkready);
373
Mike Christie7b8631b2006-01-13 18:05:50 -0600374static void iscsi_session_release(struct device *dev)
375{
376 struct iscsi_cls_session *session = iscsi_dev_to_session(dev);
Mike Christie7b8631b2006-01-13 18:05:50 -0600377 struct Scsi_Host *shost;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Mike Christie7b8631b2006-01-13 18:05:50 -0600379 shost = iscsi_session_to_shost(session);
380 scsi_host_put(shost);
381 kfree(session);
Mike Christie7b8631b2006-01-13 18:05:50 -0600382}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
Mike Christie7b8631b2006-01-13 18:05:50 -0600384static int iscsi_is_session_dev(const struct device *dev)
385{
386 return dev->release == iscsi_session_release;
387}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Mike Christiea4804cd2008-05-21 15:54:00 -0500389static int iscsi_iter_session_fn(struct device *dev, void *data)
390{
391 void (* fn) (struct iscsi_cls_session *) = data;
392
393 if (!iscsi_is_session_dev(dev))
394 return 0;
395 fn(iscsi_dev_to_session(dev));
396 return 0;
397}
398
399void iscsi_host_for_each_session(struct Scsi_Host *shost,
400 void (*fn)(struct iscsi_cls_session *))
401{
402 device_for_each_child(&shost->shost_gendev, fn,
403 iscsi_iter_session_fn);
404}
405EXPORT_SYMBOL_GPL(iscsi_host_for_each_session);
406
Mike Christie8aae18a2008-01-31 13:36:48 -0600407/**
408 * iscsi_scan_finished - helper to report when running scans are done
409 * @shost: scsi host
410 * @time: scan run time
411 *
412 * This function can be used by drives like qla4xxx to report to the scsi
413 * layer when the scans it kicked off at module load time are done.
414 */
415int iscsi_scan_finished(struct Scsi_Host *shost, unsigned long time)
416{
Mike Christie32c6e1b2008-05-21 15:53:58 -0500417 struct iscsi_cls_host *ihost = shost->shost_data;
Mike Christie8aae18a2008-01-31 13:36:48 -0600418 /*
419 * qla4xxx will have kicked off some session unblocks before calling
420 * scsi_scan_host, so just wait for them to complete.
421 */
422 return !atomic_read(&ihost->nr_scans);
423}
424EXPORT_SYMBOL_GPL(iscsi_scan_finished);
425
Mike Christie79706342008-05-21 15:54:12 -0500426struct iscsi_scan_data {
427 unsigned int channel;
428 unsigned int id;
429 unsigned int lun;
430};
431
432static int iscsi_user_scan_session(struct device *dev, void *data)
433{
434 struct iscsi_scan_data *scan_data = data;
435 struct iscsi_cls_session *session;
436 struct Scsi_Host *shost;
437 struct iscsi_cls_host *ihost;
438 unsigned long flags;
439 unsigned int id;
440
441 if (!iscsi_is_session_dev(dev))
442 return 0;
443
444 session = iscsi_dev_to_session(dev);
445 shost = iscsi_session_to_shost(session);
446 ihost = shost->shost_data;
447
448 mutex_lock(&ihost->mutex);
449 spin_lock_irqsave(&session->lock, flags);
450 if (session->state != ISCSI_SESSION_LOGGED_IN) {
451 spin_unlock_irqrestore(&session->lock, flags);
452 mutex_unlock(&ihost->mutex);
453 return 0;
454 }
455 id = session->target_id;
456 spin_unlock_irqrestore(&session->lock, flags);
457
458 if (id != ISCSI_MAX_TARGET) {
459 if ((scan_data->channel == SCAN_WILD_CARD ||
460 scan_data->channel == 0) &&
461 (scan_data->id == SCAN_WILD_CARD ||
462 scan_data->id == id))
463 scsi_scan_target(&session->dev, 0, id,
464 scan_data->lun, 1);
465 }
466 mutex_unlock(&ihost->mutex);
467 return 0;
468}
469
Mike Christie30a6c652006-04-06 21:13:39 -0500470static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
471 uint id, uint lun)
472{
Mike Christie79706342008-05-21 15:54:12 -0500473 struct iscsi_scan_data scan_data;
Mike Christie30a6c652006-04-06 21:13:39 -0500474
Mike Christie79706342008-05-21 15:54:12 -0500475 scan_data.channel = channel;
476 scan_data.id = id;
477 scan_data.lun = lun;
Mike Christie30a6c652006-04-06 21:13:39 -0500478
Mike Christie79706342008-05-21 15:54:12 -0500479 return device_for_each_child(&shost->shost_gendev, &scan_data,
480 iscsi_user_scan_session);
Mike Christie30a6c652006-04-06 21:13:39 -0500481}
482
Mike Christiebd976f62008-01-31 13:36:46 -0600483static void iscsi_scan_session(struct work_struct *work)
484{
485 struct iscsi_cls_session *session =
486 container_of(work, struct iscsi_cls_session, scan_work);
Mike Christie8aae18a2008-01-31 13:36:48 -0600487 struct Scsi_Host *shost = iscsi_session_to_shost(session);
Mike Christie32c6e1b2008-05-21 15:53:58 -0500488 struct iscsi_cls_host *ihost = shost->shost_data;
Mike Christie79706342008-05-21 15:54:12 -0500489 struct iscsi_scan_data scan_data;
Mike Christiebd976f62008-01-31 13:36:46 -0600490
Mike Christie79706342008-05-21 15:54:12 -0500491 scan_data.channel = 0;
492 scan_data.id = SCAN_WILD_CARD;
493 scan_data.lun = SCAN_WILD_CARD;
Mike Christiebd976f62008-01-31 13:36:46 -0600494
Mike Christie79706342008-05-21 15:54:12 -0500495 iscsi_user_scan_session(&session->dev, &scan_data);
Mike Christie8aae18a2008-01-31 13:36:48 -0600496 atomic_dec(&ihost->nr_scans);
Mike Christiebd976f62008-01-31 13:36:46 -0600497}
498
David Howellsc4028952006-11-22 14:57:56 +0000499static void session_recovery_timedout(struct work_struct *work)
Mike Christie30a6c652006-04-06 21:13:39 -0500500{
David Howellsc4028952006-11-22 14:57:56 +0000501 struct iscsi_cls_session *session =
502 container_of(work, struct iscsi_cls_session,
503 recovery_work.work);
Mike Christie6eabafb2008-01-31 13:36:43 -0600504 unsigned long flags;
Mike Christie30a6c652006-04-06 21:13:39 -0500505
Mike Christie322d7392008-01-31 13:36:52 -0600506 iscsi_cls_session_printk(KERN_INFO, session,
507 "session recovery timed out after %d secs\n",
508 session->recovery_tmo);
Mike Christie30a6c652006-04-06 21:13:39 -0500509
Mike Christie6eabafb2008-01-31 13:36:43 -0600510 spin_lock_irqsave(&session->lock, flags);
511 switch (session->state) {
512 case ISCSI_SESSION_FAILED:
513 session->state = ISCSI_SESSION_FREE;
514 break;
515 case ISCSI_SESSION_LOGGED_IN:
516 case ISCSI_SESSION_FREE:
517 /* we raced with the unblock's flush */
518 spin_unlock_irqrestore(&session->lock, flags);
519 return;
520 }
521 spin_unlock_irqrestore(&session->lock, flags);
522
Mike Christie30a6c652006-04-06 21:13:39 -0500523 if (session->transport->session_recovery_timedout)
524 session->transport->session_recovery_timedout(session);
525
526 scsi_target_unblock(&session->dev);
527}
528
Mike Christie45ab33b2008-03-04 13:26:55 -0600529static void __iscsi_unblock_session(struct work_struct *work)
Mike Christie30a6c652006-04-06 21:13:39 -0500530{
Mike Christie45ab33b2008-03-04 13:26:55 -0600531 struct iscsi_cls_session *session =
532 container_of(work, struct iscsi_cls_session,
533 unblock_work);
Mike Christiebd976f62008-01-31 13:36:46 -0600534 struct Scsi_Host *shost = iscsi_session_to_shost(session);
Mike Christie32c6e1b2008-05-21 15:53:58 -0500535 struct iscsi_cls_host *ihost = shost->shost_data;
Mike Christie6eabafb2008-01-31 13:36:43 -0600536 unsigned long flags;
537
Mike Christie45ab33b2008-03-04 13:26:55 -0600538 /*
539 * The recovery and unblock work get run from the same workqueue,
540 * so try to cancel it if it was going to run after this unblock.
541 */
542 cancel_delayed_work(&session->recovery_work);
Mike Christie6eabafb2008-01-31 13:36:43 -0600543 spin_lock_irqsave(&session->lock, flags);
544 session->state = ISCSI_SESSION_LOGGED_IN;
545 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie45ab33b2008-03-04 13:26:55 -0600546 /* start IO */
547 scsi_target_unblock(&session->dev);
Mike Christie8aae18a2008-01-31 13:36:48 -0600548 /*
549 * Only do kernel scanning if the driver is properly hooked into
550 * the async scanning code (drivers like iscsi_tcp do login and
551 * scanning from userspace).
552 */
553 if (shost->hostt->scan_finished) {
Mike Christie06d25af2009-03-05 14:46:02 -0600554 if (scsi_queue_work(shost, &session->scan_work))
Mike Christie8aae18a2008-01-31 13:36:48 -0600555 atomic_inc(&ihost->nr_scans);
556 }
Mike Christie6eabafb2008-01-31 13:36:43 -0600557}
Mike Christie45ab33b2008-03-04 13:26:55 -0600558
559/**
560 * iscsi_unblock_session - set a session as logged in and start IO.
561 * @session: iscsi session
562 *
563 * Mark a session as ready to accept IO.
564 */
565void iscsi_unblock_session(struct iscsi_cls_session *session)
566{
567 queue_work(iscsi_eh_timer_workq, &session->unblock_work);
568 /*
569 * make sure all the events have completed before tell the driver
570 * it is safe
571 */
572 flush_workqueue(iscsi_eh_timer_workq);
573}
Mike Christie30a6c652006-04-06 21:13:39 -0500574EXPORT_SYMBOL_GPL(iscsi_unblock_session);
575
Mike Christie45ab33b2008-03-04 13:26:55 -0600576static void __iscsi_block_session(struct work_struct *work)
Mike Christie30a6c652006-04-06 21:13:39 -0500577{
Mike Christie45ab33b2008-03-04 13:26:55 -0600578 struct iscsi_cls_session *session =
579 container_of(work, struct iscsi_cls_session,
580 block_work);
Mike Christie6eabafb2008-01-31 13:36:43 -0600581 unsigned long flags;
582
583 spin_lock_irqsave(&session->lock, flags);
584 session->state = ISCSI_SESSION_FAILED;
585 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie30a6c652006-04-06 21:13:39 -0500586 scsi_target_block(&session->dev);
Mike Christied8bf5412007-12-13 12:43:27 -0600587 queue_delayed_work(iscsi_eh_timer_workq, &session->recovery_work,
588 session->recovery_tmo * HZ);
Mike Christie30a6c652006-04-06 21:13:39 -0500589}
Mike Christie45ab33b2008-03-04 13:26:55 -0600590
591void iscsi_block_session(struct iscsi_cls_session *session)
592{
593 queue_work(iscsi_eh_timer_workq, &session->block_work);
594}
Mike Christie30a6c652006-04-06 21:13:39 -0500595EXPORT_SYMBOL_GPL(iscsi_block_session);
596
Mike Christie26974782007-12-13 12:43:29 -0600597static void __iscsi_unbind_session(struct work_struct *work)
598{
599 struct iscsi_cls_session *session =
600 container_of(work, struct iscsi_cls_session,
601 unbind_work);
602 struct Scsi_Host *shost = iscsi_session_to_shost(session);
Mike Christie32c6e1b2008-05-21 15:53:58 -0500603 struct iscsi_cls_host *ihost = shost->shost_data;
Mike Christie79706342008-05-21 15:54:12 -0500604 unsigned long flags;
Mike Christie26974782007-12-13 12:43:29 -0600605
606 /* Prevent new scans and make sure scanning is not in progress */
607 mutex_lock(&ihost->mutex);
Mike Christie79706342008-05-21 15:54:12 -0500608 spin_lock_irqsave(&session->lock, flags);
609 if (session->target_id == ISCSI_MAX_TARGET) {
610 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie26974782007-12-13 12:43:29 -0600611 mutex_unlock(&ihost->mutex);
612 return;
613 }
Mike Christie79706342008-05-21 15:54:12 -0500614 session->target_id = ISCSI_MAX_TARGET;
615 spin_unlock_irqrestore(&session->lock, flags);
Mike Christie26974782007-12-13 12:43:29 -0600616 mutex_unlock(&ihost->mutex);
617
618 scsi_remove_target(&session->dev);
619 iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION);
620}
621
Mike Christie7b8631b2006-01-13 18:05:50 -0600622struct iscsi_cls_session *
Mike Christie5d91e202008-05-21 15:54:01 -0500623iscsi_alloc_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
624 int dd_size)
Mike Christie7b8631b2006-01-13 18:05:50 -0600625{
626 struct iscsi_cls_session *session;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627
Mike Christie5d91e202008-05-21 15:54:01 -0500628 session = kzalloc(sizeof(*session) + dd_size,
Mike Christieb5c7a122006-04-06 21:13:33 -0500629 GFP_KERNEL);
Mike Christie7b8631b2006-01-13 18:05:50 -0600630 if (!session)
Mike Christief53a88d2006-06-28 12:00:27 -0500631 return NULL;
632
Mike Christie7b8631b2006-01-13 18:05:50 -0600633 session->transport = transport;
Mike Christie30a6c652006-04-06 21:13:39 -0500634 session->recovery_tmo = 120;
Mike Christie6eabafb2008-01-31 13:36:43 -0600635 session->state = ISCSI_SESSION_FREE;
David Howellsc4028952006-11-22 14:57:56 +0000636 INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout);
Mike Christie30a6c652006-04-06 21:13:39 -0500637 INIT_LIST_HEAD(&session->sess_list);
Mike Christie45ab33b2008-03-04 13:26:55 -0600638 INIT_WORK(&session->unblock_work, __iscsi_unblock_session);
639 INIT_WORK(&session->block_work, __iscsi_block_session);
Mike Christie26974782007-12-13 12:43:29 -0600640 INIT_WORK(&session->unbind_work, __iscsi_unbind_session);
Mike Christiebd976f62008-01-31 13:36:46 -0600641 INIT_WORK(&session->scan_work, iscsi_scan_session);
Mike Christie6eabafb2008-01-31 13:36:43 -0600642 spin_lock_init(&session->lock);
Mike Christie7b8631b2006-01-13 18:05:50 -0600643
Mike Christie6a8a0d32006-06-28 12:00:31 -0500644 /* this is released in the dev's release function */
645 scsi_host_get(shost);
Mike Christie8434aa82006-06-28 12:00:30 -0500646 session->dev.parent = &shost->shost_gendev;
647 session->dev.release = iscsi_session_release;
648 device_initialize(&session->dev);
Mike Christie5d91e202008-05-21 15:54:01 -0500649 if (dd_size)
Mike Christieb5c7a122006-04-06 21:13:33 -0500650 session->dd_data = &session[1];
Mike Christie8434aa82006-06-28 12:00:30 -0500651 return session;
652}
653EXPORT_SYMBOL_GPL(iscsi_alloc_session);
654
Mike Christie79706342008-05-21 15:54:12 -0500655static int iscsi_get_next_target_id(struct device *dev, void *data)
656{
657 struct iscsi_cls_session *session;
658 unsigned long flags;
659 int err = 0;
660
661 if (!iscsi_is_session_dev(dev))
662 return 0;
663
664 session = iscsi_dev_to_session(dev);
665 spin_lock_irqsave(&session->lock, flags);
666 if (*((unsigned int *) data) == session->target_id)
667 err = -EEXIST;
668 spin_unlock_irqrestore(&session->lock, flags);
669 return err;
670}
671
Mike Christie6a8a0d32006-06-28 12:00:31 -0500672int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
Mike Christie8434aa82006-06-28 12:00:30 -0500673{
674 struct Scsi_Host *shost = iscsi_session_to_shost(session);
Mike Christie32c6e1b2008-05-21 15:53:58 -0500675 struct iscsi_cls_host *ihost;
Mike Christie26974782007-12-13 12:43:29 -0600676 unsigned long flags;
Mike Christie79706342008-05-21 15:54:12 -0500677 unsigned int id = target_id;
Mike Christie8434aa82006-06-28 12:00:30 -0500678 int err;
Mike Christieb5c7a122006-04-06 21:13:33 -0500679
Mike Christie30a6c652006-04-06 21:13:39 -0500680 ihost = shost->shost_data;
Mike Christie41be1442007-02-28 17:32:18 -0600681 session->sid = atomic_add_return(1, &iscsi_session_nr);
Mike Christie79706342008-05-21 15:54:12 -0500682
683 if (id == ISCSI_MAX_TARGET) {
684 for (id = 0; id < ISCSI_MAX_TARGET; id++) {
685 err = device_for_each_child(&shost->shost_gendev, &id,
686 iscsi_get_next_target_id);
687 if (!err)
688 break;
689 }
690
691 if (id == ISCSI_MAX_TARGET) {
692 iscsi_cls_session_printk(KERN_ERR, session,
693 "Too many iscsi targets. Max "
694 "number of targets is %d.\n",
695 ISCSI_MAX_TARGET - 1);
696 goto release_host;
697 }
698 }
699 session->target_id = id;
Mike Christie30a6c652006-04-06 21:13:39 -0500700
Kay Sievers71610f52008-12-03 22:41:36 +0100701 dev_set_name(&session->dev, "session%u", session->sid);
Mike Christie8434aa82006-06-28 12:00:30 -0500702 err = device_add(&session->dev);
Mike Christie7b8631b2006-01-13 18:05:50 -0600703 if (err) {
Mike Christie322d7392008-01-31 13:36:52 -0600704 iscsi_cls_session_printk(KERN_ERR, session,
705 "could not register session's dev\n");
Mike Christie8434aa82006-06-28 12:00:30 -0500706 goto release_host;
Mike Christie7b8631b2006-01-13 18:05:50 -0600707 }
708 transport_register_device(&session->dev);
709
Mike Christie26974782007-12-13 12:43:29 -0600710 spin_lock_irqsave(&sesslock, flags);
711 list_add(&session->sess_list, &sesslist);
712 spin_unlock_irqrestore(&sesslock, flags);
713
Mike Christie26974782007-12-13 12:43:29 -0600714 iscsi_session_event(session, ISCSI_KEVENT_CREATE_SESSION);
Mike Christie8434aa82006-06-28 12:00:30 -0500715 return 0;
Mike Christie30a6c652006-04-06 21:13:39 -0500716
Mike Christie8434aa82006-06-28 12:00:30 -0500717release_host:
718 scsi_host_put(shost);
719 return err;
Mike Christie7b8631b2006-01-13 18:05:50 -0600720}
Mike Christie8434aa82006-06-28 12:00:30 -0500721EXPORT_SYMBOL_GPL(iscsi_add_session);
Mike Christie7b8631b2006-01-13 18:05:50 -0600722
723/**
Mike Christie8434aa82006-06-28 12:00:30 -0500724 * iscsi_create_session - create iscsi class session
725 * @shost: scsi host
726 * @transport: iscsi transport
Mike Christie5d91e202008-05-21 15:54:01 -0500727 * @dd_size: private driver data size
Rob Landleyeb448202007-11-03 13:30:39 -0500728 * @target_id: which target
Mike Christie7b8631b2006-01-13 18:05:50 -0600729 *
Mike Christie8434aa82006-06-28 12:00:30 -0500730 * This can be called from a LLD or iscsi_transport.
Rob Landleyeb448202007-11-03 13:30:39 -0500731 */
Mike Christie8434aa82006-06-28 12:00:30 -0500732struct iscsi_cls_session *
Mike Christie5d91e202008-05-21 15:54:01 -0500733iscsi_create_session(struct Scsi_Host *shost, struct iscsi_transport *transport,
734 int dd_size, unsigned int target_id)
Mike Christie8434aa82006-06-28 12:00:30 -0500735{
736 struct iscsi_cls_session *session;
737
Mike Christie5d91e202008-05-21 15:54:01 -0500738 session = iscsi_alloc_session(shost, transport, dd_size);
Mike Christie8434aa82006-06-28 12:00:30 -0500739 if (!session)
740 return NULL;
741
Mike Christie6a8a0d32006-06-28 12:00:31 -0500742 if (iscsi_add_session(session, target_id)) {
Mike Christie8434aa82006-06-28 12:00:30 -0500743 iscsi_free_session(session);
744 return NULL;
745 }
746 return session;
747}
748EXPORT_SYMBOL_GPL(iscsi_create_session);
749
Mike Christie26974782007-12-13 12:43:29 -0600750static void iscsi_conn_release(struct device *dev)
751{
752 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev);
753 struct device *parent = conn->dev.parent;
754
755 kfree(conn);
756 put_device(parent);
757}
758
759static int iscsi_is_conn_dev(const struct device *dev)
760{
761 return dev->release == iscsi_conn_release;
762}
763
764static int iscsi_iter_destroy_conn_fn(struct device *dev, void *data)
765{
766 if (!iscsi_is_conn_dev(dev))
767 return 0;
768 return iscsi_destroy_conn(iscsi_dev_to_conn(dev));
769}
770
Mike Christie8434aa82006-06-28 12:00:30 -0500771void iscsi_remove_session(struct iscsi_cls_session *session)
Mike Christie7b8631b2006-01-13 18:05:50 -0600772{
Mike Christie30a6c652006-04-06 21:13:39 -0500773 struct Scsi_Host *shost = iscsi_session_to_shost(session);
Mike Christie26974782007-12-13 12:43:29 -0600774 unsigned long flags;
775 int err;
Mike Christie30a6c652006-04-06 21:13:39 -0500776
Mike Christie26974782007-12-13 12:43:29 -0600777 spin_lock_irqsave(&sesslock, flags);
778 list_del(&session->sess_list);
779 spin_unlock_irqrestore(&sesslock, flags);
780
Mike Christie45ab33b2008-03-04 13:26:55 -0600781 /* make sure there are no blocks/unblocks queued */
782 flush_workqueue(iscsi_eh_timer_workq);
783 /* make sure the timedout callout is not running */
784 if (!cancel_delayed_work(&session->recovery_work))
785 flush_workqueue(iscsi_eh_timer_workq);
Mike Christie26974782007-12-13 12:43:29 -0600786 /*
787 * If we are blocked let commands flow again. The lld or iscsi
788 * layer should set up the queuecommand to fail commands.
Mike Christie45ab33b2008-03-04 13:26:55 -0600789 * We assume that LLD will not be calling block/unblock while
790 * removing the session.
Mike Christie26974782007-12-13 12:43:29 -0600791 */
Mike Christie6eabafb2008-01-31 13:36:43 -0600792 spin_lock_irqsave(&session->lock, flags);
793 session->state = ISCSI_SESSION_FREE;
794 spin_unlock_irqrestore(&session->lock, flags);
Mike Christiebd976f62008-01-31 13:36:46 -0600795
Mike Christie45ab33b2008-03-04 13:26:55 -0600796 scsi_target_unblock(&session->dev);
797 /* flush running scans then delete devices */
Mike Christie06d25af2009-03-05 14:46:02 -0600798 scsi_flush_work(shost);
Mike Christie45ab33b2008-03-04 13:26:55 -0600799 __iscsi_unbind_session(&session->unbind_work);
Mike Christie30a6c652006-04-06 21:13:39 -0500800
Mike Christie26974782007-12-13 12:43:29 -0600801 /* hw iscsi may not have removed all connections from session */
802 err = device_for_each_child(&session->dev, NULL,
803 iscsi_iter_destroy_conn_fn);
804 if (err)
Mike Christie322d7392008-01-31 13:36:52 -0600805 iscsi_cls_session_printk(KERN_ERR, session,
806 "Could not delete all connections "
807 "for session. Error %d.\n", err);
Mike Christie8434aa82006-06-28 12:00:30 -0500808
Mike Christie7b8631b2006-01-13 18:05:50 -0600809 transport_unregister_device(&session->dev);
Mike Christie8434aa82006-06-28 12:00:30 -0500810 device_del(&session->dev);
811}
812EXPORT_SYMBOL_GPL(iscsi_remove_session);
813
814void iscsi_free_session(struct iscsi_cls_session *session)
815{
Mike Christie26974782007-12-13 12:43:29 -0600816 iscsi_session_event(session, ISCSI_KEVENT_DESTROY_SESSION);
Mike Christie8434aa82006-06-28 12:00:30 -0500817 put_device(&session->dev);
Mike Christie7b8631b2006-01-13 18:05:50 -0600818}
Mike Christie8434aa82006-06-28 12:00:30 -0500819EXPORT_SYMBOL_GPL(iscsi_free_session);
820
821/**
822 * iscsi_destroy_session - destroy iscsi session
823 * @session: iscsi_session
824 *
825 * Can be called by a LLD or iscsi_transport. There must not be
826 * any running connections.
Rob Landleyeb448202007-11-03 13:30:39 -0500827 */
Mike Christie8434aa82006-06-28 12:00:30 -0500828int iscsi_destroy_session(struct iscsi_cls_session *session)
829{
830 iscsi_remove_session(session);
831 iscsi_free_session(session);
832 return 0;
833}
Mike Christie7b8631b2006-01-13 18:05:50 -0600834EXPORT_SYMBOL_GPL(iscsi_destroy_session);
835
Mike Christie7b8631b2006-01-13 18:05:50 -0600836/**
837 * iscsi_create_conn - create iscsi class connection
838 * @session: iscsi cls session
Mike Christie5d91e202008-05-21 15:54:01 -0500839 * @dd_size: private driver data size
Mike Christie7b8631b2006-01-13 18:05:50 -0600840 * @cid: connection id
841 *
842 * This can be called from a LLD or iscsi_transport. The connection
843 * is child of the session so cid must be unique for all connections
844 * on the session.
Mike Christieb5c7a122006-04-06 21:13:33 -0500845 *
846 * Since we do not support MCS, cid will normally be zero. In some cases
847 * for software iscsi we could be trying to preallocate a connection struct
848 * in which case there could be two connection structs and cid would be
849 * non-zero.
Rob Landleyeb448202007-11-03 13:30:39 -0500850 */
Mike Christie7b8631b2006-01-13 18:05:50 -0600851struct iscsi_cls_conn *
Mike Christie5d91e202008-05-21 15:54:01 -0500852iscsi_create_conn(struct iscsi_cls_session *session, int dd_size, uint32_t cid)
Mike Christie7b8631b2006-01-13 18:05:50 -0600853{
854 struct iscsi_transport *transport = session->transport;
Mike Christie7b8631b2006-01-13 18:05:50 -0600855 struct iscsi_cls_conn *conn;
Mike Christie26974782007-12-13 12:43:29 -0600856 unsigned long flags;
Mike Christie7b8631b2006-01-13 18:05:50 -0600857 int err;
858
Mike Christie5d91e202008-05-21 15:54:01 -0500859 conn = kzalloc(sizeof(*conn) + dd_size, GFP_KERNEL);
Mike Christie7b8631b2006-01-13 18:05:50 -0600860 if (!conn)
861 return NULL;
Mike Christie5d91e202008-05-21 15:54:01 -0500862 if (dd_size)
Mike Christie7b8631b2006-01-13 18:05:50 -0600863 conn->dd_data = &conn[1];
864
865 INIT_LIST_HEAD(&conn->conn_list);
866 conn->transport = transport;
Mike Christieb5c7a122006-04-06 21:13:33 -0500867 conn->cid = cid;
Mike Christie7b8631b2006-01-13 18:05:50 -0600868
869 /* this is released in the dev's release function */
870 if (!get_device(&session->dev))
Mike Christie43a145a2006-10-16 18:09:38 -0400871 goto free_conn;
Mike Christieb5c7a122006-04-06 21:13:33 -0500872
Kay Sievers71610f52008-12-03 22:41:36 +0100873 dev_set_name(&conn->dev, "connection%d:%u", session->sid, cid);
Mike Christie7b8631b2006-01-13 18:05:50 -0600874 conn->dev.parent = &session->dev;
875 conn->dev.release = iscsi_conn_release;
876 err = device_register(&conn->dev);
877 if (err) {
Mike Christie322d7392008-01-31 13:36:52 -0600878 iscsi_cls_session_printk(KERN_ERR, session, "could not "
879 "register connection's dev\n");
Mike Christie7b8631b2006-01-13 18:05:50 -0600880 goto release_parent_ref;
881 }
882 transport_register_device(&conn->dev);
Mike Christie26974782007-12-13 12:43:29 -0600883
884 spin_lock_irqsave(&connlock, flags);
885 list_add(&conn->conn_list, &connlist);
886 conn->active = 1;
887 spin_unlock_irqrestore(&connlock, flags);
Mike Christie7b8631b2006-01-13 18:05:50 -0600888 return conn;
889
890release_parent_ref:
891 put_device(&session->dev);
892free_conn:
893 kfree(conn);
894 return NULL;
895}
896
897EXPORT_SYMBOL_GPL(iscsi_create_conn);
898
899/**
900 * iscsi_destroy_conn - destroy iscsi class connection
Rob Landleyeb448202007-11-03 13:30:39 -0500901 * @conn: iscsi cls session
Mike Christie7b8631b2006-01-13 18:05:50 -0600902 *
Mike Christie26974782007-12-13 12:43:29 -0600903 * This can be called from a LLD or iscsi_transport.
Rob Landleyeb448202007-11-03 13:30:39 -0500904 */
Mike Christie7b8631b2006-01-13 18:05:50 -0600905int iscsi_destroy_conn(struct iscsi_cls_conn *conn)
906{
Mike Christie26974782007-12-13 12:43:29 -0600907 unsigned long flags;
908
909 spin_lock_irqsave(&connlock, flags);
910 conn->active = 0;
911 list_del(&conn->conn_list);
912 spin_unlock_irqrestore(&connlock, flags);
913
Mike Christie7b8631b2006-01-13 18:05:50 -0600914 transport_unregister_device(&conn->dev);
915 device_unregister(&conn->dev);
916 return 0;
917}
Mike Christie7b8631b2006-01-13 18:05:50 -0600918EXPORT_SYMBOL_GPL(iscsi_destroy_conn);
919
920/*
Mike Christie7b8631b2006-01-13 18:05:50 -0600921 * iscsi interface functions
922 */
Alex Aizman0896b752005-08-04 19:33:07 -0700923static struct iscsi_internal *
924iscsi_if_transport_lookup(struct iscsi_transport *tt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925{
Alex Aizman0896b752005-08-04 19:33:07 -0700926 struct iscsi_internal *priv;
927 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Alex Aizman0896b752005-08-04 19:33:07 -0700929 spin_lock_irqsave(&iscsi_transport_lock, flags);
930 list_for_each_entry(priv, &iscsi_transports, list) {
931 if (tt == priv->iscsi_transport) {
932 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
933 return priv;
934 }
935 }
936 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
937 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
Alex Aizman0896b752005-08-04 19:33:07 -0700940static int
Mike Christie43a145a2006-10-16 18:09:38 -0400941iscsi_broadcast_skb(struct sk_buff *skb, gfp_t gfp)
Mike Christie53cb8a12006-06-28 12:00:32 -0500942{
Pablo Neira Ayusoff491a72009-02-05 23:56:36 -0800943 return netlink_broadcast(nls, skb, 0, 1, gfp);
Mike Christie53cb8a12006-06-28 12:00:32 -0500944}
945
946static int
Mike Christie43a145a2006-10-16 18:09:38 -0400947iscsi_unicast_skb(struct sk_buff *skb, int pid)
Alex Aizman0896b752005-08-04 19:33:07 -0700948{
Alex Aizman0896b752005-08-04 19:33:07 -0700949 int rc;
950
Mike Christie790f39a2006-05-18 20:31:39 -0500951 rc = netlink_unicast(nls, skb, pid, MSG_DONTWAIT);
Alex Aizman0896b752005-08-04 19:33:07 -0700952 if (rc < 0) {
Alex Aizman0896b752005-08-04 19:33:07 -0700953 printk(KERN_ERR "iscsi: can not unicast skb (%d)\n", rc);
954 return rc;
955 }
956
Alex Aizman0896b752005-08-04 19:33:07 -0700957 return 0;
958}
959
Mike Christie7b7232f2006-02-01 21:06:49 -0600960int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
Alex Aizman0896b752005-08-04 19:33:07 -0700961 char *data, uint32_t data_size)
962{
963 struct nlmsghdr *nlh;
964 struct sk_buff *skb;
965 struct iscsi_uevent *ev;
Alex Aizman0896b752005-08-04 19:33:07 -0700966 char *pdu;
Mike Christie790f39a2006-05-18 20:31:39 -0500967 struct iscsi_internal *priv;
Alex Aizman0896b752005-08-04 19:33:07 -0700968 int len = NLMSG_SPACE(sizeof(*ev) + sizeof(struct iscsi_hdr) +
969 data_size);
970
Mike Christie790f39a2006-05-18 20:31:39 -0500971 priv = iscsi_if_transport_lookup(conn->transport);
972 if (!priv)
973 return -EINVAL;
974
Mike Christie43a145a2006-10-16 18:09:38 -0400975 skb = alloc_skb(len, GFP_ATOMIC);
Alex Aizman0896b752005-08-04 19:33:07 -0700976 if (!skb) {
Mike Christiee5bd7b52008-09-24 11:46:10 -0500977 iscsi_conn_error_event(conn, ISCSI_ERR_CONN_FAILED);
Mike Christie322d7392008-01-31 13:36:52 -0600978 iscsi_cls_conn_printk(KERN_ERR, conn, "can not deliver "
979 "control PDU: OOM\n");
Alex Aizman0896b752005-08-04 19:33:07 -0700980 return -ENOMEM;
981 }
982
Mike Christie790f39a2006-05-18 20:31:39 -0500983 nlh = __nlmsg_put(skb, priv->daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
Alex Aizman0896b752005-08-04 19:33:07 -0700984 ev = NLMSG_DATA(nlh);
985 memset(ev, 0, sizeof(*ev));
986 ev->transport_handle = iscsi_handle(conn->transport);
987 ev->type = ISCSI_KEVENT_RECV_PDU;
Mike Christieb5c7a122006-04-06 21:13:33 -0500988 ev->r.recv_req.cid = conn->cid;
989 ev->r.recv_req.sid = iscsi_conn_get_sid(conn);
Alex Aizman0896b752005-08-04 19:33:07 -0700990 pdu = (char*)ev + sizeof(*ev);
991 memcpy(pdu, hdr, sizeof(struct iscsi_hdr));
992 memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size);
993
Mike Christie43a145a2006-10-16 18:09:38 -0400994 return iscsi_unicast_skb(skb, priv->daemon_pid);
Alex Aizman0896b752005-08-04 19:33:07 -0700995}
996EXPORT_SYMBOL_GPL(iscsi_recv_pdu);
997
Mike Christiee5bd7b52008-09-24 11:46:10 -0500998void iscsi_conn_error_event(struct iscsi_cls_conn *conn, enum iscsi_err error)
Alex Aizman0896b752005-08-04 19:33:07 -0700999{
1000 struct nlmsghdr *nlh;
1001 struct sk_buff *skb;
1002 struct iscsi_uevent *ev;
Mike Christie790f39a2006-05-18 20:31:39 -05001003 struct iscsi_internal *priv;
Alex Aizman0896b752005-08-04 19:33:07 -07001004 int len = NLMSG_SPACE(sizeof(*ev));
1005
Mike Christie790f39a2006-05-18 20:31:39 -05001006 priv = iscsi_if_transport_lookup(conn->transport);
1007 if (!priv)
1008 return;
1009
Mike Christie43a145a2006-10-16 18:09:38 -04001010 skb = alloc_skb(len, GFP_ATOMIC);
Alex Aizman0896b752005-08-04 19:33:07 -07001011 if (!skb) {
Mike Christie322d7392008-01-31 13:36:52 -06001012 iscsi_cls_conn_printk(KERN_ERR, conn, "gracefully ignored "
1013 "conn error (%d)\n", error);
Alex Aizman0896b752005-08-04 19:33:07 -07001014 return;
1015 }
1016
Mike Christie790f39a2006-05-18 20:31:39 -05001017 nlh = __nlmsg_put(skb, priv->daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
Alex Aizman0896b752005-08-04 19:33:07 -07001018 ev = NLMSG_DATA(nlh);
1019 ev->transport_handle = iscsi_handle(conn->transport);
1020 ev->type = ISCSI_KEVENT_CONN_ERROR;
Alex Aizman0896b752005-08-04 19:33:07 -07001021 ev->r.connerror.error = error;
Mike Christieb5c7a122006-04-06 21:13:33 -05001022 ev->r.connerror.cid = conn->cid;
1023 ev->r.connerror.sid = iscsi_conn_get_sid(conn);
Alex Aizman0896b752005-08-04 19:33:07 -07001024
Mike Christie43a145a2006-10-16 18:09:38 -04001025 iscsi_broadcast_skb(skb, GFP_ATOMIC);
Alex Aizman0896b752005-08-04 19:33:07 -07001026
Mike Christie322d7392008-01-31 13:36:52 -06001027 iscsi_cls_conn_printk(KERN_INFO, conn, "detected conn error (%d)\n",
1028 error);
Alex Aizman0896b752005-08-04 19:33:07 -07001029}
Mike Christiee5bd7b52008-09-24 11:46:10 -05001030EXPORT_SYMBOL_GPL(iscsi_conn_error_event);
Alex Aizman0896b752005-08-04 19:33:07 -07001031
1032static int
1033iscsi_if_send_reply(int pid, int seq, int type, int done, int multi,
1034 void *payload, int size)
1035{
1036 struct sk_buff *skb;
1037 struct nlmsghdr *nlh;
1038 int len = NLMSG_SPACE(size);
1039 int flags = multi ? NLM_F_MULTI : 0;
1040 int t = done ? NLMSG_DONE : type;
1041
Mike Christie43a145a2006-10-16 18:09:38 -04001042 skb = alloc_skb(len, GFP_ATOMIC);
Mike Christie239a7dc2007-05-30 12:57:07 -05001043 if (!skb) {
1044 printk(KERN_ERR "Could not allocate skb to send reply.\n");
1045 return -ENOMEM;
1046 }
Alex Aizman0896b752005-08-04 19:33:07 -07001047
1048 nlh = __nlmsg_put(skb, pid, seq, t, (len - sizeof(*nlh)), 0);
1049 nlh->nlmsg_flags = flags;
1050 memcpy(NLMSG_DATA(nlh), payload, size);
Mike Christie43a145a2006-10-16 18:09:38 -04001051 return iscsi_unicast_skb(skb, pid);
Alex Aizman0896b752005-08-04 19:33:07 -07001052}
1053
1054static int
Mike Christie5b940ad2006-02-01 21:06:56 -06001055iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
Alex Aizman0896b752005-08-04 19:33:07 -07001056{
1057 struct iscsi_uevent *ev = NLMSG_DATA(nlh);
1058 struct iscsi_stats *stats;
1059 struct sk_buff *skbstat;
Mike Christie7b8631b2006-01-13 18:05:50 -06001060 struct iscsi_cls_conn *conn;
Alex Aizman0896b752005-08-04 19:33:07 -07001061 struct nlmsghdr *nlhstat;
1062 struct iscsi_uevent *evstat;
Mike Christie790f39a2006-05-18 20:31:39 -05001063 struct iscsi_internal *priv;
Alex Aizman0896b752005-08-04 19:33:07 -07001064 int len = NLMSG_SPACE(sizeof(*ev) +
1065 sizeof(struct iscsi_stats) +
1066 sizeof(struct iscsi_stats_custom) *
1067 ISCSI_STATS_CUSTOM_MAX);
1068 int err = 0;
1069
Mike Christie790f39a2006-05-18 20:31:39 -05001070 priv = iscsi_if_transport_lookup(transport);
1071 if (!priv)
1072 return -EINVAL;
1073
Mike Christieb5c7a122006-04-06 21:13:33 -05001074 conn = iscsi_conn_lookup(ev->u.get_stats.sid, ev->u.get_stats.cid);
Alex Aizman0896b752005-08-04 19:33:07 -07001075 if (!conn)
1076 return -EEXIST;
1077
1078 do {
1079 int actual_size;
1080
Mike Christie43a145a2006-10-16 18:09:38 -04001081 skbstat = alloc_skb(len, GFP_ATOMIC);
Alex Aizman0896b752005-08-04 19:33:07 -07001082 if (!skbstat) {
Mike Christie322d7392008-01-31 13:36:52 -06001083 iscsi_cls_conn_printk(KERN_ERR, conn, "can not "
1084 "deliver stats: OOM\n");
Alex Aizman0896b752005-08-04 19:33:07 -07001085 return -ENOMEM;
1086 }
1087
Mike Christie790f39a2006-05-18 20:31:39 -05001088 nlhstat = __nlmsg_put(skbstat, priv->daemon_pid, 0, 0,
Alex Aizman0896b752005-08-04 19:33:07 -07001089 (len - sizeof(*nlhstat)), 0);
1090 evstat = NLMSG_DATA(nlhstat);
1091 memset(evstat, 0, sizeof(*evstat));
1092 evstat->transport_handle = iscsi_handle(conn->transport);
1093 evstat->type = nlh->nlmsg_type;
Mike Christieb5c7a122006-04-06 21:13:33 -05001094 evstat->u.get_stats.cid =
1095 ev->u.get_stats.cid;
1096 evstat->u.get_stats.sid =
1097 ev->u.get_stats.sid;
Alex Aizman0896b752005-08-04 19:33:07 -07001098 stats = (struct iscsi_stats *)
1099 ((char*)evstat + sizeof(*evstat));
1100 memset(stats, 0, sizeof(*stats));
1101
Mike Christie7b7232f2006-02-01 21:06:49 -06001102 transport->get_stats(conn, stats);
Alex Aizman0896b752005-08-04 19:33:07 -07001103 actual_size = NLMSG_SPACE(sizeof(struct iscsi_uevent) +
1104 sizeof(struct iscsi_stats) +
1105 sizeof(struct iscsi_stats_custom) *
1106 stats->custom_length);
1107 actual_size -= sizeof(*nlhstat);
1108 actual_size = NLMSG_LENGTH(actual_size);
Mike Christie5b940ad2006-02-01 21:06:56 -06001109 skb_trim(skbstat, NLMSG_ALIGN(actual_size));
Alex Aizman0896b752005-08-04 19:33:07 -07001110 nlhstat->nlmsg_len = actual_size;
1111
Mike Christie43a145a2006-10-16 18:09:38 -04001112 err = iscsi_unicast_skb(skbstat, priv->daemon_pid);
Alex Aizman0896b752005-08-04 19:33:07 -07001113 } while (err < 0 && err != -ECONNREFUSED);
1114
1115 return err;
1116}
1117
Mike Christie53cb8a12006-06-28 12:00:32 -05001118/**
Mike Christie26974782007-12-13 12:43:29 -06001119 * iscsi_session_event - send session destr. completion event
1120 * @session: iscsi class session
1121 * @event: type of event
Rob Landleyeb448202007-11-03 13:30:39 -05001122 */
Mike Christie26974782007-12-13 12:43:29 -06001123int iscsi_session_event(struct iscsi_cls_session *session,
1124 enum iscsi_uevent_e event)
Mike Christie53cb8a12006-06-28 12:00:32 -05001125{
1126 struct iscsi_internal *priv;
Mike Christie53cb8a12006-06-28 12:00:32 -05001127 struct Scsi_Host *shost;
1128 struct iscsi_uevent *ev;
1129 struct sk_buff *skb;
1130 struct nlmsghdr *nlh;
Mike Christie53cb8a12006-06-28 12:00:32 -05001131 int rc, len = NLMSG_SPACE(sizeof(*ev));
1132
Mike Christie26974782007-12-13 12:43:29 -06001133 priv = iscsi_if_transport_lookup(session->transport);
Mike Christie53cb8a12006-06-28 12:00:32 -05001134 if (!priv)
1135 return -EINVAL;
Mike Christie53cb8a12006-06-28 12:00:32 -05001136 shost = iscsi_session_to_shost(session);
1137
Mike Christie43a145a2006-10-16 18:09:38 -04001138 skb = alloc_skb(len, GFP_KERNEL);
Mike Christie53cb8a12006-06-28 12:00:32 -05001139 if (!skb) {
Mike Christie322d7392008-01-31 13:36:52 -06001140 iscsi_cls_session_printk(KERN_ERR, session,
1141 "Cannot notify userspace of session "
1142 "event %u\n", event);
Mike Christie53cb8a12006-06-28 12:00:32 -05001143 return -ENOMEM;
1144 }
1145
1146 nlh = __nlmsg_put(skb, priv->daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
1147 ev = NLMSG_DATA(nlh);
Mike Christie26974782007-12-13 12:43:29 -06001148 ev->transport_handle = iscsi_handle(session->transport);
1149
1150 ev->type = event;
1151 switch (event) {
1152 case ISCSI_KEVENT_DESTROY_SESSION:
1153 ev->r.d_session.host_no = shost->host_no;
1154 ev->r.d_session.sid = session->sid;
1155 break;
1156 case ISCSI_KEVENT_CREATE_SESSION:
1157 ev->r.c_session_ret.host_no = shost->host_no;
1158 ev->r.c_session_ret.sid = session->sid;
1159 break;
1160 case ISCSI_KEVENT_UNBIND_SESSION:
1161 ev->r.unbind_session.host_no = shost->host_no;
1162 ev->r.unbind_session.sid = session->sid;
1163 break;
1164 default:
Mike Christie322d7392008-01-31 13:36:52 -06001165 iscsi_cls_session_printk(KERN_ERR, session, "Invalid event "
1166 "%u.\n", event);
Mike Christie26974782007-12-13 12:43:29 -06001167 kfree_skb(skb);
1168 return -EINVAL;
1169 }
Mike Christie53cb8a12006-06-28 12:00:32 -05001170
1171 /*
1172 * this will occur if the daemon is not up, so we just warn
1173 * the user and when the daemon is restarted it will handle it
1174 */
Mike Christie43a145a2006-10-16 18:09:38 -04001175 rc = iscsi_broadcast_skb(skb, GFP_KERNEL);
Pablo Neira Ayusoff491a72009-02-05 23:56:36 -08001176 if (rc == -ESRCH)
Mike Christie322d7392008-01-31 13:36:52 -06001177 iscsi_cls_session_printk(KERN_ERR, session,
1178 "Cannot notify userspace of session "
1179 "event %u. Check iscsi daemon\n",
1180 event);
Mike Christie53cb8a12006-06-28 12:00:32 -05001181 return rc;
1182}
Mike Christie26974782007-12-13 12:43:29 -06001183EXPORT_SYMBOL_GPL(iscsi_session_event);
Mike Christie53cb8a12006-06-28 12:00:32 -05001184
Alex Aizman0896b752005-08-04 19:33:07 -07001185static int
Mike Christied82ff9be2008-05-21 15:54:13 -05001186iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_endpoint *ep,
1187 struct iscsi_uevent *ev, uint32_t initial_cmdsn,
Mike Christie40753ca2008-05-21 15:53:56 -05001188 uint16_t cmds_max, uint16_t queue_depth)
Mike Christie7b8631b2006-01-13 18:05:50 -06001189{
1190 struct iscsi_transport *transport = priv->iscsi_transport;
Mike Christie7b7232f2006-02-01 21:06:49 -06001191 struct iscsi_cls_session *session;
Mike Christie5e7facb2009-03-05 14:46:06 -06001192 struct Scsi_Host *shost;
Mike Christie7b8631b2006-01-13 18:05:50 -06001193
Mike Christied82ff9be2008-05-21 15:54:13 -05001194 session = transport->create_session(ep, cmds_max, queue_depth,
Mike Christie5e7facb2009-03-05 14:46:06 -06001195 initial_cmdsn);
Mike Christie7b7232f2006-02-01 21:06:49 -06001196 if (!session)
Mike Christie7b8631b2006-01-13 18:05:50 -06001197 return -ENOMEM;
1198
Mike Christie5e7facb2009-03-05 14:46:06 -06001199 shost = iscsi_session_to_shost(session);
1200 ev->r.c_session_ret.host_no = shost->host_no;
Mike Christieb5c7a122006-04-06 21:13:33 -05001201 ev->r.c_session_ret.sid = session->sid;
Mike Christie7b8631b2006-01-13 18:05:50 -06001202 return 0;
1203}
1204
1205static int
Mike Christie7b7232f2006-02-01 21:06:49 -06001206iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
Mike Christie7b8631b2006-01-13 18:05:50 -06001207{
Mike Christie7b8631b2006-01-13 18:05:50 -06001208 struct iscsi_cls_conn *conn;
Mike Christie7b7232f2006-02-01 21:06:49 -06001209 struct iscsi_cls_session *session;
Mike Christie7b8631b2006-01-13 18:05:50 -06001210
Mike Christieb5c7a122006-04-06 21:13:33 -05001211 session = iscsi_session_lookup(ev->u.c_conn.sid);
1212 if (!session) {
Mike Christie322d7392008-01-31 13:36:52 -06001213 printk(KERN_ERR "iscsi: invalid session %d.\n",
Mike Christieb5c7a122006-04-06 21:13:33 -05001214 ev->u.c_conn.sid);
Mike Christie7b8631b2006-01-13 18:05:50 -06001215 return -EINVAL;
Mike Christieb5c7a122006-04-06 21:13:33 -05001216 }
Mike Christie7b8631b2006-01-13 18:05:50 -06001217
Mike Christie7b7232f2006-02-01 21:06:49 -06001218 conn = transport->create_conn(session, ev->u.c_conn.cid);
Mike Christieb5c7a122006-04-06 21:13:33 -05001219 if (!conn) {
Mike Christie322d7392008-01-31 13:36:52 -06001220 iscsi_cls_session_printk(KERN_ERR, session,
1221 "couldn't create a new connection.");
Mike Christie7b7232f2006-02-01 21:06:49 -06001222 return -ENOMEM;
Mike Christieb5c7a122006-04-06 21:13:33 -05001223 }
Mike Christie7b8631b2006-01-13 18:05:50 -06001224
Mike Christieb5c7a122006-04-06 21:13:33 -05001225 ev->r.c_conn_ret.sid = session->sid;
1226 ev->r.c_conn_ret.cid = conn->cid;
Mike Christie7b8631b2006-01-13 18:05:50 -06001227 return 0;
Mike Christie7b8631b2006-01-13 18:05:50 -06001228}
1229
1230static int
1231iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
1232{
Mike Christie7b8631b2006-01-13 18:05:50 -06001233 struct iscsi_cls_conn *conn;
Mike Christie7b8631b2006-01-13 18:05:50 -06001234
Mike Christieb5c7a122006-04-06 21:13:33 -05001235 conn = iscsi_conn_lookup(ev->u.d_conn.sid, ev->u.d_conn.cid);
Mike Christie7b8631b2006-01-13 18:05:50 -06001236 if (!conn)
Mike Christie7b8631b2006-01-13 18:05:50 -06001237 return -EINVAL;
Mike Christie7b8631b2006-01-13 18:05:50 -06001238
Mike Christie7b8631b2006-01-13 18:05:50 -06001239 if (transport->destroy_conn)
1240 transport->destroy_conn(conn);
Mike Christie7b8631b2006-01-13 18:05:50 -06001241 return 0;
1242}
1243
Mike Christiefd7255f2006-04-06 21:13:36 -05001244static int
1245iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
1246{
1247 char *data = (char*)ev + sizeof(*ev);
1248 struct iscsi_cls_conn *conn;
1249 struct iscsi_cls_session *session;
Mike Christiea54a52c2006-06-28 12:00:23 -05001250 int err = 0, value = 0;
Mike Christiefd7255f2006-04-06 21:13:36 -05001251
1252 session = iscsi_session_lookup(ev->u.set_param.sid);
1253 conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid);
1254 if (!conn || !session)
1255 return -EINVAL;
1256
1257 switch (ev->u.set_param.param) {
Mike Christie30a6c652006-04-06 21:13:39 -05001258 case ISCSI_PARAM_SESS_RECOVERY_TMO:
Mike Christiea54a52c2006-06-28 12:00:23 -05001259 sscanf(data, "%d", &value);
Mike Christie30a6c652006-04-06 21:13:39 -05001260 if (value != 0)
1261 session->recovery_tmo = value;
1262 break;
Mike Christiefd7255f2006-04-06 21:13:36 -05001263 default:
Mike Christiea54a52c2006-06-28 12:00:23 -05001264 err = transport->set_param(conn, ev->u.set_param.param,
1265 data, ev->u.set_param.len);
Mike Christiefd7255f2006-04-06 21:13:36 -05001266 }
1267
1268 return err;
1269}
1270
Mike Christie7b8631b2006-01-13 18:05:50 -06001271static int
Or Gerlitz264faaa2006-05-02 19:46:36 -05001272iscsi_if_transport_ep(struct iscsi_transport *transport,
1273 struct iscsi_uevent *ev, int msg_type)
1274{
Mike Christied82ff9be2008-05-21 15:54:13 -05001275 struct iscsi_endpoint *ep;
Or Gerlitz264faaa2006-05-02 19:46:36 -05001276 struct sockaddr *dst_addr;
1277 int rc = 0;
1278
1279 switch (msg_type) {
1280 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
1281 if (!transport->ep_connect)
1282 return -EINVAL;
1283
1284 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
Mike Christied82ff9be2008-05-21 15:54:13 -05001285 ep = transport->ep_connect(dst_addr,
1286 ev->u.ep_connect.non_blocking);
1287 if (IS_ERR(ep))
1288 return PTR_ERR(ep);
1289
1290 ev->r.ep_connect_ret.handle = ep->id;
Or Gerlitz264faaa2006-05-02 19:46:36 -05001291 break;
1292 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
1293 if (!transport->ep_poll)
1294 return -EINVAL;
1295
Mike Christied82ff9be2008-05-21 15:54:13 -05001296 ep = iscsi_lookup_endpoint(ev->u.ep_poll.ep_handle);
1297 if (!ep)
1298 return -EINVAL;
1299
1300 ev->r.retcode = transport->ep_poll(ep,
Or Gerlitz264faaa2006-05-02 19:46:36 -05001301 ev->u.ep_poll.timeout_ms);
1302 break;
1303 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
1304 if (!transport->ep_disconnect)
1305 return -EINVAL;
1306
Mike Christied82ff9be2008-05-21 15:54:13 -05001307 ep = iscsi_lookup_endpoint(ev->u.ep_disconnect.ep_handle);
1308 if (!ep)
1309 return -EINVAL;
1310
1311 transport->ep_disconnect(ep);
Or Gerlitz264faaa2006-05-02 19:46:36 -05001312 break;
1313 }
1314 return rc;
1315}
1316
1317static int
Mike Christie01cb2252006-06-28 12:00:22 -05001318iscsi_tgt_dscvr(struct iscsi_transport *transport,
1319 struct iscsi_uevent *ev)
1320{
Mike Christie2174a042007-05-30 12:57:10 -05001321 struct Scsi_Host *shost;
Mike Christie01cb2252006-06-28 12:00:22 -05001322 struct sockaddr *dst_addr;
Mike Christie2174a042007-05-30 12:57:10 -05001323 int err;
Mike Christie01cb2252006-06-28 12:00:22 -05001324
1325 if (!transport->tgt_dscvr)
1326 return -EINVAL;
1327
Mike Christie2174a042007-05-30 12:57:10 -05001328 shost = scsi_host_lookup(ev->u.tgt_dscvr.host_no);
James Smart315cb0a2008-08-07 20:49:30 -04001329 if (!shost) {
Mike Christie2174a042007-05-30 12:57:10 -05001330 printk(KERN_ERR "target discovery could not find host no %u\n",
1331 ev->u.tgt_dscvr.host_no);
1332 return -ENODEV;
1333 }
1334
1335
Mike Christie01cb2252006-06-28 12:00:22 -05001336 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
Mike Christie2174a042007-05-30 12:57:10 -05001337 err = transport->tgt_dscvr(shost, ev->u.tgt_dscvr.type,
1338 ev->u.tgt_dscvr.enable, dst_addr);
1339 scsi_host_put(shost);
1340 return err;
Mike Christie01cb2252006-06-28 12:00:22 -05001341}
1342
1343static int
Mike Christie1d9bf132007-05-30 12:57:11 -05001344iscsi_set_host_param(struct iscsi_transport *transport,
1345 struct iscsi_uevent *ev)
1346{
1347 char *data = (char*)ev + sizeof(*ev);
1348 struct Scsi_Host *shost;
1349 int err;
1350
1351 if (!transport->set_host_param)
1352 return -ENOSYS;
1353
1354 shost = scsi_host_lookup(ev->u.set_host_param.host_no);
James Smart315cb0a2008-08-07 20:49:30 -04001355 if (!shost) {
Mike Christie1d9bf132007-05-30 12:57:11 -05001356 printk(KERN_ERR "set_host_param could not find host no %u\n",
1357 ev->u.set_host_param.host_no);
1358 return -ENODEV;
1359 }
1360
1361 err = transport->set_host_param(shost, ev->u.set_host_param.param,
1362 data, ev->u.set_host_param.len);
1363 scsi_host_put(shost);
1364 return err;
1365}
1366
1367static int
Alex Aizman0896b752005-08-04 19:33:07 -07001368iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1369{
1370 int err = 0;
1371 struct iscsi_uevent *ev = NLMSG_DATA(nlh);
1372 struct iscsi_transport *transport = NULL;
1373 struct iscsi_internal *priv;
Mike Christie7b7232f2006-02-01 21:06:49 -06001374 struct iscsi_cls_session *session;
1375 struct iscsi_cls_conn *conn;
Mike Christied82ff9be2008-05-21 15:54:13 -05001376 struct iscsi_endpoint *ep = NULL;
Alex Aizman0896b752005-08-04 19:33:07 -07001377
Alex Aizman0896b752005-08-04 19:33:07 -07001378 priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle));
1379 if (!priv)
1380 return -EINVAL;
1381 transport = priv->iscsi_transport;
1382
Mike Christie7b7232f2006-02-01 21:06:49 -06001383 if (!try_module_get(transport->owner))
1384 return -EINVAL;
1385
Mike Christie790f39a2006-05-18 20:31:39 -05001386 priv->daemon_pid = NETLINK_CREDS(skb)->pid;
1387
Alex Aizman0896b752005-08-04 19:33:07 -07001388 switch (nlh->nlmsg_type) {
1389 case ISCSI_UEVENT_CREATE_SESSION:
Mike Christied82ff9be2008-05-21 15:54:13 -05001390 err = iscsi_if_create_session(priv, ep, ev,
Mike Christie40753ca2008-05-21 15:53:56 -05001391 ev->u.c_session.initial_cmdsn,
1392 ev->u.c_session.cmds_max,
1393 ev->u.c_session.queue_depth);
1394 break;
1395 case ISCSI_UEVENT_CREATE_BOUND_SESSION:
Mike Christied82ff9be2008-05-21 15:54:13 -05001396 ep = iscsi_lookup_endpoint(ev->u.c_bound_session.ep_handle);
Mike Christiec95fddc2008-06-16 10:11:32 -05001397 if (!ep) {
1398 err = -EINVAL;
1399 break;
1400 }
Mike Christied82ff9be2008-05-21 15:54:13 -05001401
1402 err = iscsi_if_create_session(priv, ep, ev,
Mike Christie40753ca2008-05-21 15:53:56 -05001403 ev->u.c_bound_session.initial_cmdsn,
1404 ev->u.c_bound_session.cmds_max,
1405 ev->u.c_bound_session.queue_depth);
Alex Aizman0896b752005-08-04 19:33:07 -07001406 break;
1407 case ISCSI_UEVENT_DESTROY_SESSION:
Mike Christieb5c7a122006-04-06 21:13:33 -05001408 session = iscsi_session_lookup(ev->u.d_session.sid);
Mike Christie26974782007-12-13 12:43:29 -06001409 if (session)
Mike Christie7b7232f2006-02-01 21:06:49 -06001410 transport->destroy_session(session);
Mike Christie26974782007-12-13 12:43:29 -06001411 else
1412 err = -EINVAL;
1413 break;
1414 case ISCSI_UEVENT_UNBIND_SESSION:
1415 session = iscsi_session_lookup(ev->u.d_session.sid);
1416 if (session)
Mike Christie06d25af2009-03-05 14:46:02 -06001417 scsi_queue_work(iscsi_session_to_shost(session),
1418 &session->unbind_work);
Mike Christie26974782007-12-13 12:43:29 -06001419 else
Mike Christie7b7232f2006-02-01 21:06:49 -06001420 err = -EINVAL;
Alex Aizman0896b752005-08-04 19:33:07 -07001421 break;
1422 case ISCSI_UEVENT_CREATE_CONN:
1423 err = iscsi_if_create_conn(transport, ev);
1424 break;
1425 case ISCSI_UEVENT_DESTROY_CONN:
1426 err = iscsi_if_destroy_conn(transport, ev);
1427 break;
1428 case ISCSI_UEVENT_BIND_CONN:
Mike Christieb5c7a122006-04-06 21:13:33 -05001429 session = iscsi_session_lookup(ev->u.b_conn.sid);
1430 conn = iscsi_conn_lookup(ev->u.b_conn.sid, ev->u.b_conn.cid);
Mike Christie7b7232f2006-02-01 21:06:49 -06001431
1432 if (session && conn)
1433 ev->r.retcode = transport->bind_conn(session, conn,
Or Gerlitz264faaa2006-05-02 19:46:36 -05001434 ev->u.b_conn.transport_eph,
Mike Christie7b7232f2006-02-01 21:06:49 -06001435 ev->u.b_conn.is_leading);
1436 else
1437 err = -EINVAL;
Alex Aizman0896b752005-08-04 19:33:07 -07001438 break;
1439 case ISCSI_UEVENT_SET_PARAM:
Mike Christiefd7255f2006-04-06 21:13:36 -05001440 err = iscsi_set_param(transport, ev);
Alex Aizman0896b752005-08-04 19:33:07 -07001441 break;
1442 case ISCSI_UEVENT_START_CONN:
Mike Christieb5c7a122006-04-06 21:13:33 -05001443 conn = iscsi_conn_lookup(ev->u.start_conn.sid, ev->u.start_conn.cid);
Mike Christie7b7232f2006-02-01 21:06:49 -06001444 if (conn)
1445 ev->r.retcode = transport->start_conn(conn);
1446 else
1447 err = -EINVAL;
Alex Aizman0896b752005-08-04 19:33:07 -07001448 break;
1449 case ISCSI_UEVENT_STOP_CONN:
Mike Christieb5c7a122006-04-06 21:13:33 -05001450 conn = iscsi_conn_lookup(ev->u.stop_conn.sid, ev->u.stop_conn.cid);
Mike Christie7b7232f2006-02-01 21:06:49 -06001451 if (conn)
1452 transport->stop_conn(conn, ev->u.stop_conn.flag);
1453 else
1454 err = -EINVAL;
Alex Aizman0896b752005-08-04 19:33:07 -07001455 break;
1456 case ISCSI_UEVENT_SEND_PDU:
Mike Christieb5c7a122006-04-06 21:13:33 -05001457 conn = iscsi_conn_lookup(ev->u.send_pdu.sid, ev->u.send_pdu.cid);
Mike Christie7b7232f2006-02-01 21:06:49 -06001458 if (conn)
1459 ev->r.retcode = transport->send_pdu(conn,
1460 (struct iscsi_hdr*)((char*)ev + sizeof(*ev)),
1461 (char*)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size,
1462 ev->u.send_pdu.data_size);
1463 else
1464 err = -EINVAL;
Alex Aizman0896b752005-08-04 19:33:07 -07001465 break;
1466 case ISCSI_UEVENT_GET_STATS:
Mike Christie5b940ad2006-02-01 21:06:56 -06001467 err = iscsi_if_get_stats(transport, nlh);
Alex Aizman0896b752005-08-04 19:33:07 -07001468 break;
Or Gerlitz264faaa2006-05-02 19:46:36 -05001469 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
1470 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
1471 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
1472 err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type);
1473 break;
Mike Christie01cb2252006-06-28 12:00:22 -05001474 case ISCSI_UEVENT_TGT_DSCVR:
1475 err = iscsi_tgt_dscvr(transport, ev);
1476 break;
Mike Christie1d9bf132007-05-30 12:57:11 -05001477 case ISCSI_UEVENT_SET_HOST_PARAM:
1478 err = iscsi_set_host_param(transport, ev);
1479 break;
Alex Aizman0896b752005-08-04 19:33:07 -07001480 default:
Mike Christie1d9bf132007-05-30 12:57:11 -05001481 err = -ENOSYS;
Alex Aizman0896b752005-08-04 19:33:07 -07001482 break;
1483 }
1484
Mike Christie7b7232f2006-02-01 21:06:49 -06001485 module_put(transport->owner);
Alex Aizman0896b752005-08-04 19:33:07 -07001486 return err;
1487}
1488
Mike Christieb5c7a122006-04-06 21:13:33 -05001489/*
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07001490 * Get message from skb. Each message is processed by iscsi_if_recv_msg.
1491 * Malformed skbs with wrong lengths or invalid creds are not processed.
Mike Christieb5c7a122006-04-06 21:13:33 -05001492 */
Alex Aizman0896b752005-08-04 19:33:07 -07001493static void
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07001494iscsi_if_rx(struct sk_buff *skb)
Alex Aizman0896b752005-08-04 19:33:07 -07001495{
Arjan van de Ven0b950672006-01-11 13:16:10 +01001496 mutex_lock(&rx_queue_mutex);
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07001497 while (skb->len >= NLMSG_SPACE(0)) {
1498 int err;
1499 uint32_t rlen;
1500 struct nlmsghdr *nlh;
1501 struct iscsi_uevent *ev;
1502
1503 nlh = nlmsg_hdr(skb);
1504 if (nlh->nlmsg_len < sizeof(*nlh) ||
1505 skb->len < nlh->nlmsg_len) {
1506 break;
Mike Christieee7f8e42006-02-01 21:07:01 -06001507 }
Mike Christieee7f8e42006-02-01 21:07:01 -06001508
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07001509 ev = NLMSG_DATA(nlh);
1510 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
1511 if (rlen > skb->len)
1512 rlen = skb->len;
Alex Aizman0896b752005-08-04 19:33:07 -07001513
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07001514 err = iscsi_if_recv_msg(skb, nlh);
1515 if (err) {
1516 ev->type = ISCSI_KEVENT_IF_ERROR;
1517 ev->iferror = err;
1518 }
1519 do {
1520 /*
1521 * special case for GET_STATS:
1522 * on success - sending reply and stats from
1523 * inside of if_recv_msg(),
1524 * on error - fall through.
1525 */
1526 if (ev->type == ISCSI_UEVENT_GET_STATS && !err)
Alex Aizman0896b752005-08-04 19:33:07 -07001527 break;
Denis V. Lunevcd40b7d2007-10-10 21:15:29 -07001528 err = iscsi_if_send_reply(
1529 NETLINK_CREDS(skb)->pid, nlh->nlmsg_seq,
1530 nlh->nlmsg_type, 0, 0, ev, sizeof(*ev));
1531 } while (err < 0 && err != -ECONNREFUSED);
1532 skb_pull(skb, rlen);
Alex Aizman0896b752005-08-04 19:33:07 -07001533 }
Arjan van de Ven0b950672006-01-11 13:16:10 +01001534 mutex_unlock(&rx_queue_mutex);
Alex Aizman0896b752005-08-04 19:33:07 -07001535}
1536
Mike Christiefd7255f2006-04-06 21:13:36 -05001537#define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \
Tony Jonesee959b02008-02-22 00:13:36 +01001538struct device_attribute dev_attr_##_prefix##_##_name = \
Mike Christiefd7255f2006-04-06 21:13:36 -05001539 __ATTR(_name,_mode,_show,_store)
1540
Alex Aizman0896b752005-08-04 19:33:07 -07001541/*
1542 * iSCSI connection attrs
1543 */
Mike Christiea54a52c2006-06-28 12:00:23 -05001544#define iscsi_conn_attr_show(param) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001546show_conn_param_##param(struct device *dev, \
1547 struct device_attribute *attr, char *buf) \
Mike Christiefd7255f2006-04-06 21:13:36 -05001548{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001549 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
Mike Christiefd7255f2006-04-06 21:13:36 -05001550 struct iscsi_transport *t = conn->transport; \
Mike Christiea54a52c2006-06-28 12:00:23 -05001551 return t->get_conn_param(conn, param, buf); \
Mike Christiefd7255f2006-04-06 21:13:36 -05001552}
1553
Mike Christiea54a52c2006-06-28 12:00:23 -05001554#define iscsi_conn_attr(field, param) \
1555 iscsi_conn_attr_show(param) \
1556static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \
Mike Christiefd7255f2006-04-06 21:13:36 -05001557 NULL);
1558
Mike Christiea54a52c2006-06-28 12:00:23 -05001559iscsi_conn_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH);
1560iscsi_conn_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH);
1561iscsi_conn_attr(header_digest, ISCSI_PARAM_HDRDGST_EN);
1562iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN);
1563iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN);
1564iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN);
1565iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT);
1566iscsi_conn_attr(port, ISCSI_PARAM_CONN_PORT);
1567iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN);
1568iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS);
1569iscsi_conn_attr(address, ISCSI_PARAM_CONN_ADDRESS);
Mike Christief6d51802007-12-13 12:43:30 -06001570iscsi_conn_attr(ping_tmo, ISCSI_PARAM_PING_TMO);
1571iscsi_conn_attr(recv_tmo, ISCSI_PARAM_RECV_TMO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
1573/*
Alex Aizman0896b752005-08-04 19:33:07 -07001574 * iSCSI session attrs
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 */
Mike Christieb2c64162007-05-30 12:57:16 -05001576#define iscsi_session_attr_show(param, perm) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001578show_session_param_##param(struct device *dev, \
1579 struct device_attribute *attr, char *buf) \
Mike Christiefd7255f2006-04-06 21:13:36 -05001580{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001581 struct iscsi_cls_session *session = \
1582 iscsi_dev_to_session(dev->parent); \
Mike Christiefd7255f2006-04-06 21:13:36 -05001583 struct iscsi_transport *t = session->transport; \
Mike Christieb2c64162007-05-30 12:57:16 -05001584 \
1585 if (perm && !capable(CAP_SYS_ADMIN)) \
1586 return -EACCES; \
Mike Christiea54a52c2006-06-28 12:00:23 -05001587 return t->get_session_param(session, param, buf); \
Mike Christiefd7255f2006-04-06 21:13:36 -05001588}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589
Mike Christieb2c64162007-05-30 12:57:16 -05001590#define iscsi_session_attr(field, param, perm) \
1591 iscsi_session_attr_show(param, perm) \
Mike Christiea54a52c2006-06-28 12:00:23 -05001592static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \
Mike Christiefd7255f2006-04-06 21:13:36 -05001593 NULL);
1594
Mike Christieb2c64162007-05-30 12:57:16 -05001595iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME, 0);
1596iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, 0);
1597iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, 0);
1598iscsi_session_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, 0);
1599iscsi_session_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, 0);
1600iscsi_session_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, 0);
1601iscsi_session_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, 0);
1602iscsi_session_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, 0);
1603iscsi_session_attr(erl, ISCSI_PARAM_ERL, 0);
1604iscsi_session_attr(tpgt, ISCSI_PARAM_TPGT, 0);
1605iscsi_session_attr(username, ISCSI_PARAM_USERNAME, 1);
1606iscsi_session_attr(username_in, ISCSI_PARAM_USERNAME_IN, 1);
1607iscsi_session_attr(password, ISCSI_PARAM_PASSWORD, 1);
1608iscsi_session_attr(password_in, ISCSI_PARAM_PASSWORD_IN, 1);
Mike Christie4cd49ea2007-12-13 12:43:38 -06001609iscsi_session_attr(fast_abort, ISCSI_PARAM_FAST_ABORT, 0);
1610iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0);
1611iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0);
Mike Christie88dfd342008-05-21 15:54:16 -05001612iscsi_session_attr(ifacename, ISCSI_PARAM_IFACE_NAME, 0);
1613iscsi_session_attr(initiatorname, ISCSI_PARAM_INITIATOR_NAME, 0)
Mike Christiefd7255f2006-04-06 21:13:36 -05001614
Mike Christie6eabafb2008-01-31 13:36:43 -06001615static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +01001616show_priv_session_state(struct device *dev, struct device_attribute *attr,
1617 char *buf)
Mike Christie6eabafb2008-01-31 13:36:43 -06001618{
Tony Jonesee959b02008-02-22 00:13:36 +01001619 struct iscsi_cls_session *session = iscsi_dev_to_session(dev->parent);
Mike Christie6eabafb2008-01-31 13:36:43 -06001620 return sprintf(buf, "%s\n", iscsi_session_state_name(session->state));
1621}
1622static ISCSI_CLASS_ATTR(priv_sess, state, S_IRUGO, show_priv_session_state,
1623 NULL);
1624
Mike Christiefd7255f2006-04-06 21:13:36 -05001625#define iscsi_priv_session_attr_show(field, format) \
1626static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001627show_priv_session_##field(struct device *dev, \
1628 struct device_attribute *attr, char *buf) \
Mike Christiefd7255f2006-04-06 21:13:36 -05001629{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001630 struct iscsi_cls_session *session = \
1631 iscsi_dev_to_session(dev->parent); \
Mike Christiefd7255f2006-04-06 21:13:36 -05001632 return sprintf(buf, format"\n", session->field); \
1633}
1634
1635#define iscsi_priv_session_attr(field, format) \
1636 iscsi_priv_session_attr_show(field, format) \
1637static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO, show_priv_session_##field, \
1638 NULL)
Mike Christie30a6c652006-04-06 21:13:39 -05001639iscsi_priv_session_attr(recovery_tmo, "%d");
Mike Christiefd7255f2006-04-06 21:13:36 -05001640
Mike Christie1819dc82007-05-30 12:57:08 -05001641/*
1642 * iSCSI host attrs
1643 */
1644#define iscsi_host_attr_show(param) \
1645static ssize_t \
Tony Jonesee959b02008-02-22 00:13:36 +01001646show_host_param_##param(struct device *dev, \
1647 struct device_attribute *attr, char *buf) \
Mike Christie1819dc82007-05-30 12:57:08 -05001648{ \
Tony Jonesee959b02008-02-22 00:13:36 +01001649 struct Scsi_Host *shost = transport_class_to_shost(dev); \
Mike Christie1819dc82007-05-30 12:57:08 -05001650 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); \
1651 return priv->iscsi_transport->get_host_param(shost, param, buf); \
1652}
1653
1654#define iscsi_host_attr(field, param) \
1655 iscsi_host_attr_show(param) \
1656static ISCSI_CLASS_ATTR(host, field, S_IRUGO, show_host_param_##param, \
1657 NULL);
1658
Mike Christied8196ed2007-05-30 12:57:25 -05001659iscsi_host_attr(netdev, ISCSI_HOST_PARAM_NETDEV_NAME);
Mike Christie1819dc82007-05-30 12:57:08 -05001660iscsi_host_attr(hwaddress, ISCSI_HOST_PARAM_HWADDRESS);
Mike Christied8196ed2007-05-30 12:57:25 -05001661iscsi_host_attr(ipaddress, ISCSI_HOST_PARAM_IPADDRESS);
Mike Christie8ad57812007-05-30 12:57:13 -05001662iscsi_host_attr(initiatorname, ISCSI_HOST_PARAM_INITIATOR_NAME);
Mike Christie1819dc82007-05-30 12:57:08 -05001663
Mike Christiefd7255f2006-04-06 21:13:36 -05001664#define SETUP_PRIV_SESSION_RD_ATTR(field) \
1665do { \
Tony Jonesee959b02008-02-22 00:13:36 +01001666 priv->session_attrs[count] = &dev_attr_priv_sess_##field; \
Mike Christiefd7255f2006-04-06 21:13:36 -05001667 count++; \
1668} while (0)
1669
Mike Christiea54a52c2006-06-28 12:00:23 -05001670
Mike Christiefd7255f2006-04-06 21:13:36 -05001671#define SETUP_SESSION_RD_ATTR(field, param_flag) \
1672do { \
1673 if (tt->param_mask & param_flag) { \
Tony Jonesee959b02008-02-22 00:13:36 +01001674 priv->session_attrs[count] = &dev_attr_sess_##field; \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 count++; \
Mike Christiefd7255f2006-04-06 21:13:36 -05001676 } \
1677} while (0)
1678
Mike Christiefd7255f2006-04-06 21:13:36 -05001679#define SETUP_CONN_RD_ATTR(field, param_flag) \
1680do { \
1681 if (tt->param_mask & param_flag) { \
Tony Jonesee959b02008-02-22 00:13:36 +01001682 priv->conn_attrs[count] = &dev_attr_conn_##field; \
Mike Christiefd7255f2006-04-06 21:13:36 -05001683 count++; \
1684 } \
1685} while (0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686
Mike Christie1819dc82007-05-30 12:57:08 -05001687#define SETUP_HOST_RD_ATTR(field, param_flag) \
1688do { \
1689 if (tt->host_param_mask & param_flag) { \
Tony Jonesee959b02008-02-22 00:13:36 +01001690 priv->host_attrs[count] = &dev_attr_host_##field; \
Mike Christie1819dc82007-05-30 12:57:08 -05001691 count++; \
1692 } \
1693} while (0)
1694
Alex Aizman0896b752005-08-04 19:33:07 -07001695static int iscsi_session_match(struct attribute_container *cont,
1696 struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697{
Mike Christie7b8631b2006-01-13 18:05:50 -06001698 struct iscsi_cls_session *session;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 struct Scsi_Host *shost;
Alex Aizman0896b752005-08-04 19:33:07 -07001700 struct iscsi_internal *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701
Alex Aizman0896b752005-08-04 19:33:07 -07001702 if (!iscsi_is_session_dev(dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 return 0;
1704
Mike Christie7b8631b2006-01-13 18:05:50 -06001705 session = iscsi_dev_to_session(dev);
1706 shost = iscsi_session_to_shost(session);
Alex Aizman0896b752005-08-04 19:33:07 -07001707 if (!shost->transportt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 return 0;
1709
Alex Aizman0896b752005-08-04 19:33:07 -07001710 priv = to_iscsi_internal(shost->transportt);
1711 if (priv->session_cont.ac.class != &iscsi_session_class.class)
1712 return 0;
1713
1714 return &priv->session_cont.ac == cont;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715}
1716
Alex Aizman0896b752005-08-04 19:33:07 -07001717static int iscsi_conn_match(struct attribute_container *cont,
1718 struct device *dev)
1719{
Mike Christie7b8631b2006-01-13 18:05:50 -06001720 struct iscsi_cls_session *session;
1721 struct iscsi_cls_conn *conn;
Alex Aizman0896b752005-08-04 19:33:07 -07001722 struct Scsi_Host *shost;
1723 struct iscsi_internal *priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
Alex Aizman0896b752005-08-04 19:33:07 -07001725 if (!iscsi_is_conn_dev(dev))
1726 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Mike Christie7b8631b2006-01-13 18:05:50 -06001728 conn = iscsi_dev_to_conn(dev);
1729 session = iscsi_dev_to_session(conn->dev.parent);
1730 shost = iscsi_session_to_shost(session);
1731
Alex Aizman0896b752005-08-04 19:33:07 -07001732 if (!shost->transportt)
1733 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
Alex Aizman0896b752005-08-04 19:33:07 -07001735 priv = to_iscsi_internal(shost->transportt);
1736 if (priv->conn_cont.ac.class != &iscsi_connection_class.class)
1737 return 0;
1738
1739 return &priv->conn_cont.ac == cont;
1740}
1741
Mike Christie30a6c652006-04-06 21:13:39 -05001742static int iscsi_host_match(struct attribute_container *cont,
1743 struct device *dev)
1744{
1745 struct Scsi_Host *shost;
1746 struct iscsi_internal *priv;
1747
1748 if (!scsi_is_host_device(dev))
1749 return 0;
1750
1751 shost = dev_to_shost(dev);
1752 if (!shost->transportt ||
1753 shost->transportt->host_attrs.ac.class != &iscsi_host_class.class)
1754 return 0;
1755
1756 priv = to_iscsi_internal(shost->transportt);
1757 return &priv->t.host_attrs.ac == cont;
1758}
1759
Mike Christie7b8631b2006-01-13 18:05:50 -06001760struct scsi_transport_template *
1761iscsi_register_transport(struct iscsi_transport *tt)
Alex Aizman0896b752005-08-04 19:33:07 -07001762{
1763 struct iscsi_internal *priv;
1764 unsigned long flags;
1765 int count = 0, err;
1766
1767 BUG_ON(!tt);
1768
1769 priv = iscsi_if_transport_lookup(tt);
1770 if (priv)
Mike Christie7b8631b2006-01-13 18:05:50 -06001771 return NULL;
Alex Aizman0896b752005-08-04 19:33:07 -07001772
Jes Sorensen24669f752006-01-16 10:31:18 -05001773 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
Alex Aizman0896b752005-08-04 19:33:07 -07001774 if (!priv)
Mike Christie7b8631b2006-01-13 18:05:50 -06001775 return NULL;
Alex Aizman0896b752005-08-04 19:33:07 -07001776 INIT_LIST_HEAD(&priv->list);
Mike Christie53cb8a12006-06-28 12:00:32 -05001777 priv->daemon_pid = -1;
Alex Aizman0896b752005-08-04 19:33:07 -07001778 priv->iscsi_transport = tt;
Mike Christie30a6c652006-04-06 21:13:39 -05001779 priv->t.user_scan = iscsi_user_scan;
Mike Christie06d25af2009-03-05 14:46:02 -06001780 priv->t.create_work_queue = 1;
Alex Aizman0896b752005-08-04 19:33:07 -07001781
Tony Jonesee959b02008-02-22 00:13:36 +01001782 priv->dev.class = &iscsi_transport_class;
Kay Sievers71610f52008-12-03 22:41:36 +01001783 dev_set_name(&priv->dev, "%s", tt->name);
Tony Jonesee959b02008-02-22 00:13:36 +01001784 err = device_register(&priv->dev);
Alex Aizman0896b752005-08-04 19:33:07 -07001785 if (err)
1786 goto free_priv;
1787
Tony Jonesee959b02008-02-22 00:13:36 +01001788 err = sysfs_create_group(&priv->dev.kobj, &iscsi_transport_group);
Alex Aizman0896b752005-08-04 19:33:07 -07001789 if (err)
Tony Jonesee959b02008-02-22 00:13:36 +01001790 goto unregister_dev;
Alex Aizman0896b752005-08-04 19:33:07 -07001791
Mike Christie30a6c652006-04-06 21:13:39 -05001792 /* host parameters */
1793 priv->t.host_attrs.ac.attrs = &priv->host_attrs[0];
1794 priv->t.host_attrs.ac.class = &iscsi_host_class.class;
1795 priv->t.host_attrs.ac.match = iscsi_host_match;
Mike Christie32c6e1b2008-05-21 15:53:58 -05001796 priv->t.host_size = sizeof(struct iscsi_cls_host);
Mike Christie30a6c652006-04-06 21:13:39 -05001797 transport_container_register(&priv->t.host_attrs);
1798
Mike Christied8196ed2007-05-30 12:57:25 -05001799 SETUP_HOST_RD_ATTR(netdev, ISCSI_HOST_NETDEV_NAME);
Mike Christie22236962007-05-30 12:57:24 -05001800 SETUP_HOST_RD_ATTR(ipaddress, ISCSI_HOST_IPADDRESS);
Mike Christie1819dc82007-05-30 12:57:08 -05001801 SETUP_HOST_RD_ATTR(hwaddress, ISCSI_HOST_HWADDRESS);
Mike Christie8ad57812007-05-30 12:57:13 -05001802 SETUP_HOST_RD_ATTR(initiatorname, ISCSI_HOST_INITIATOR_NAME);
Mike Christie1819dc82007-05-30 12:57:08 -05001803 BUG_ON(count > ISCSI_HOST_ATTRS);
1804 priv->host_attrs[count] = NULL;
1805 count = 0;
1806
Alex Aizman0896b752005-08-04 19:33:07 -07001807 /* connection parameters */
1808 priv->conn_cont.ac.attrs = &priv->conn_attrs[0];
1809 priv->conn_cont.ac.class = &iscsi_connection_class.class;
1810 priv->conn_cont.ac.match = iscsi_conn_match;
1811 transport_container_register(&priv->conn_cont);
1812
Mike Christiefd7255f2006-04-06 21:13:36 -05001813 SETUP_CONN_RD_ATTR(max_recv_dlength, ISCSI_MAX_RECV_DLENGTH);
1814 SETUP_CONN_RD_ATTR(max_xmit_dlength, ISCSI_MAX_XMIT_DLENGTH);
1815 SETUP_CONN_RD_ATTR(header_digest, ISCSI_HDRDGST_EN);
1816 SETUP_CONN_RD_ATTR(data_digest, ISCSI_DATADGST_EN);
1817 SETUP_CONN_RD_ATTR(ifmarker, ISCSI_IFMARKER_EN);
1818 SETUP_CONN_RD_ATTR(ofmarker, ISCSI_OFMARKER_EN);
1819 SETUP_CONN_RD_ATTR(address, ISCSI_CONN_ADDRESS);
1820 SETUP_CONN_RD_ATTR(port, ISCSI_CONN_PORT);
Mike Christie8d2860b2006-05-02 19:46:47 -05001821 SETUP_CONN_RD_ATTR(exp_statsn, ISCSI_EXP_STATSN);
Mike Christiea54a52c2006-06-28 12:00:23 -05001822 SETUP_CONN_RD_ATTR(persistent_address, ISCSI_PERSISTENT_ADDRESS);
1823 SETUP_CONN_RD_ATTR(persistent_port, ISCSI_PERSISTENT_PORT);
Mike Christief6d51802007-12-13 12:43:30 -06001824 SETUP_CONN_RD_ATTR(ping_tmo, ISCSI_PING_TMO);
1825 SETUP_CONN_RD_ATTR(recv_tmo, ISCSI_RECV_TMO);
Alex Aizman0896b752005-08-04 19:33:07 -07001826
1827 BUG_ON(count > ISCSI_CONN_ATTRS);
1828 priv->conn_attrs[count] = NULL;
1829 count = 0;
1830
1831 /* session parameters */
1832 priv->session_cont.ac.attrs = &priv->session_attrs[0];
1833 priv->session_cont.ac.class = &iscsi_session_class.class;
1834 priv->session_cont.ac.match = iscsi_session_match;
1835 transport_container_register(&priv->session_cont);
1836
Mike Christiefd7255f2006-04-06 21:13:36 -05001837 SETUP_SESSION_RD_ATTR(initial_r2t, ISCSI_INITIAL_R2T_EN);
1838 SETUP_SESSION_RD_ATTR(max_outstanding_r2t, ISCSI_MAX_R2T);
1839 SETUP_SESSION_RD_ATTR(immediate_data, ISCSI_IMM_DATA_EN);
1840 SETUP_SESSION_RD_ATTR(first_burst_len, ISCSI_FIRST_BURST);
1841 SETUP_SESSION_RD_ATTR(max_burst_len, ISCSI_MAX_BURST);
1842 SETUP_SESSION_RD_ATTR(data_pdu_in_order, ISCSI_PDU_INORDER_EN);
1843 SETUP_SESSION_RD_ATTR(data_seq_in_order, ISCSI_DATASEQ_INORDER_EN);
1844 SETUP_SESSION_RD_ATTR(erl, ISCSI_ERL);
Mike Christiea54a52c2006-06-28 12:00:23 -05001845 SETUP_SESSION_RD_ATTR(targetname, ISCSI_TARGET_NAME);
1846 SETUP_SESSION_RD_ATTR(tpgt, ISCSI_TPGT);
Mike Christieb2c64162007-05-30 12:57:16 -05001847 SETUP_SESSION_RD_ATTR(password, ISCSI_USERNAME);
1848 SETUP_SESSION_RD_ATTR(password_in, ISCSI_USERNAME_IN);
1849 SETUP_SESSION_RD_ATTR(username, ISCSI_PASSWORD);
1850 SETUP_SESSION_RD_ATTR(username_in, ISCSI_PASSWORD_IN);
Mike Christie843c0a82007-12-13 12:43:20 -06001851 SETUP_SESSION_RD_ATTR(fast_abort, ISCSI_FAST_ABORT);
Mike Christie4cd49ea2007-12-13 12:43:38 -06001852 SETUP_SESSION_RD_ATTR(abort_tmo, ISCSI_ABORT_TMO);
1853 SETUP_SESSION_RD_ATTR(lu_reset_tmo,ISCSI_LU_RESET_TMO);
Mike Christie88dfd342008-05-21 15:54:16 -05001854 SETUP_SESSION_RD_ATTR(ifacename, ISCSI_IFACE_NAME);
1855 SETUP_SESSION_RD_ATTR(initiatorname, ISCSI_INITIATOR_NAME);
Mike Christie30a6c652006-04-06 21:13:39 -05001856 SETUP_PRIV_SESSION_RD_ATTR(recovery_tmo);
Mike Christie6eabafb2008-01-31 13:36:43 -06001857 SETUP_PRIV_SESSION_RD_ATTR(state);
Mike Christiefd7255f2006-04-06 21:13:36 -05001858
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 BUG_ON(count > ISCSI_SESSION_ATTRS);
Alex Aizman0896b752005-08-04 19:33:07 -07001860 priv->session_attrs[count] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
Alex Aizman0896b752005-08-04 19:33:07 -07001862 spin_lock_irqsave(&iscsi_transport_lock, flags);
1863 list_add(&priv->list, &iscsi_transports);
1864 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
Alex Aizman0896b752005-08-04 19:33:07 -07001866 printk(KERN_NOTICE "iscsi: registered transport (%s)\n", tt->name);
Mike Christie7b8631b2006-01-13 18:05:50 -06001867 return &priv->t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868
Tony Jonesee959b02008-02-22 00:13:36 +01001869unregister_dev:
1870 device_unregister(&priv->dev);
Mike Christied82ff9be2008-05-21 15:54:13 -05001871 return NULL;
Alex Aizman0896b752005-08-04 19:33:07 -07001872free_priv:
1873 kfree(priv);
Mike Christie7b8631b2006-01-13 18:05:50 -06001874 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875}
Alex Aizman0896b752005-08-04 19:33:07 -07001876EXPORT_SYMBOL_GPL(iscsi_register_transport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
Alex Aizman0896b752005-08-04 19:33:07 -07001878int iscsi_unregister_transport(struct iscsi_transport *tt)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879{
Alex Aizman0896b752005-08-04 19:33:07 -07001880 struct iscsi_internal *priv;
1881 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
Alex Aizman0896b752005-08-04 19:33:07 -07001883 BUG_ON(!tt);
1884
Arjan van de Ven0b950672006-01-11 13:16:10 +01001885 mutex_lock(&rx_queue_mutex);
Alex Aizman0896b752005-08-04 19:33:07 -07001886
1887 priv = iscsi_if_transport_lookup(tt);
1888 BUG_ON (!priv);
1889
Alex Aizman0896b752005-08-04 19:33:07 -07001890 spin_lock_irqsave(&iscsi_transport_lock, flags);
1891 list_del(&priv->list);
1892 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
1893
1894 transport_container_unregister(&priv->conn_cont);
1895 transport_container_unregister(&priv->session_cont);
Mike Christie30a6c652006-04-06 21:13:39 -05001896 transport_container_unregister(&priv->t.host_attrs);
Alex Aizman0896b752005-08-04 19:33:07 -07001897
Tony Jonesee959b02008-02-22 00:13:36 +01001898 sysfs_remove_group(&priv->dev.kobj, &iscsi_transport_group);
1899 device_unregister(&priv->dev);
Arjan van de Ven0b950672006-01-11 13:16:10 +01001900 mutex_unlock(&rx_queue_mutex);
Alex Aizman0896b752005-08-04 19:33:07 -07001901
1902 return 0;
1903}
1904EXPORT_SYMBOL_GPL(iscsi_unregister_transport);
1905
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906static __init int iscsi_transport_init(void)
1907{
Alex Aizman0896b752005-08-04 19:33:07 -07001908 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
Meelis Roos09492602006-12-17 12:10:26 -06001910 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
Mike Christief4246b32006-07-24 15:47:54 -05001911 ISCSI_TRANSPORT_VERSION);
1912
Mike Christie41be1442007-02-28 17:32:18 -06001913 atomic_set(&iscsi_session_nr, 0);
1914
Alex Aizman0896b752005-08-04 19:33:07 -07001915 err = class_register(&iscsi_transport_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 if (err)
1917 return err;
Alex Aizman0896b752005-08-04 19:33:07 -07001918
Mike Christied82ff9be2008-05-21 15:54:13 -05001919 err = class_register(&iscsi_endpoint_class);
Alex Aizman0896b752005-08-04 19:33:07 -07001920 if (err)
1921 goto unregister_transport_class;
1922
Mike Christied82ff9be2008-05-21 15:54:13 -05001923 err = transport_class_register(&iscsi_host_class);
1924 if (err)
1925 goto unregister_endpoint_class;
1926
Mike Christie30a6c652006-04-06 21:13:39 -05001927 err = transport_class_register(&iscsi_connection_class);
1928 if (err)
1929 goto unregister_host_class;
1930
Alex Aizman0896b752005-08-04 19:33:07 -07001931 err = transport_class_register(&iscsi_session_class);
1932 if (err)
1933 goto unregister_conn_class;
1934
Mike Christied82ff9be2008-05-21 15:54:13 -05001935 nls = netlink_kernel_create(&init_net, NETLINK_ISCSI, 1, iscsi_if_rx,
1936 NULL, THIS_MODULE);
Alex Aizman0896b752005-08-04 19:33:07 -07001937 if (!nls) {
1938 err = -ENOBUFS;
Mike Christie43a145a2006-10-16 18:09:38 -04001939 goto unregister_session_class;
Alex Aizman0896b752005-08-04 19:33:07 -07001940 }
1941
Mike Christied8bf5412007-12-13 12:43:27 -06001942 iscsi_eh_timer_workq = create_singlethread_workqueue("iscsi_eh");
1943 if (!iscsi_eh_timer_workq)
1944 goto release_nls;
1945
Mike Christie43a145a2006-10-16 18:09:38 -04001946 return 0;
Alex Aizman0896b752005-08-04 19:33:07 -07001947
Mike Christied8bf5412007-12-13 12:43:27 -06001948release_nls:
Denis V. Lunevb7c6ba62008-01-28 14:41:19 -08001949 netlink_kernel_release(nls);
Alex Aizman0896b752005-08-04 19:33:07 -07001950unregister_session_class:
1951 transport_class_unregister(&iscsi_session_class);
1952unregister_conn_class:
1953 transport_class_unregister(&iscsi_connection_class);
Mike Christie30a6c652006-04-06 21:13:39 -05001954unregister_host_class:
1955 transport_class_unregister(&iscsi_host_class);
Mike Christied82ff9be2008-05-21 15:54:13 -05001956unregister_endpoint_class:
1957 class_unregister(&iscsi_endpoint_class);
Alex Aizman0896b752005-08-04 19:33:07 -07001958unregister_transport_class:
1959 class_unregister(&iscsi_transport_class);
1960 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961}
1962
1963static void __exit iscsi_transport_exit(void)
1964{
Mike Christied8bf5412007-12-13 12:43:27 -06001965 destroy_workqueue(iscsi_eh_timer_workq);
Denis V. Lunevb7c6ba62008-01-28 14:41:19 -08001966 netlink_kernel_release(nls);
Alex Aizman0896b752005-08-04 19:33:07 -07001967 transport_class_unregister(&iscsi_connection_class);
1968 transport_class_unregister(&iscsi_session_class);
Mike Christie30a6c652006-04-06 21:13:39 -05001969 transport_class_unregister(&iscsi_host_class);
Mike Christied82ff9be2008-05-21 15:54:13 -05001970 class_unregister(&iscsi_endpoint_class);
Alex Aizman0896b752005-08-04 19:33:07 -07001971 class_unregister(&iscsi_transport_class);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972}
1973
1974module_init(iscsi_transport_init);
1975module_exit(iscsi_transport_exit);
1976
Alex Aizman0896b752005-08-04 19:33:07 -07001977MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
1978 "Dmitry Yusupov <dmitry_yus@yahoo.com>, "
1979 "Alex Aizman <itn780@yahoo.com>");
1980MODULE_DESCRIPTION("iSCSI Transport Interface");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981MODULE_LICENSE("GPL");
Mike Christief4246b32006-07-24 15:47:54 -05001982MODULE_VERSION(ISCSI_TRANSPORT_VERSION);