2 * iSCSI transport class definitions
4 * Copyright (C) IBM Corporation, 2004
5 * Copyright (C) Mike Christie, 2004 - 2005
6 * Copyright (C) Dmitry Yusupov, 2004 - 2005
7 * Copyright (C) Alex Aizman, 2004 - 2005
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.
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.
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.
23 #include <linux/module.h>
24 #include <linux/mutex.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_host.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_transport.h>
30 #include <scsi/scsi_transport_iscsi.h>
31 #include <scsi/iscsi_if.h>
33 #define ISCSI_SESSION_ATTRS 18
34 #define ISCSI_CONN_ATTRS 11
35 #define ISCSI_HOST_ATTRS 4
36 #define ISCSI_TRANSPORT_VERSION "2.0-867"
38 struct iscsi_internal {
40 struct scsi_transport_template t;
41 struct iscsi_transport *iscsi_transport;
42 struct list_head list;
43 struct class_device cdev;
45 struct class_device_attribute *host_attrs[ISCSI_HOST_ATTRS + 1];
46 struct transport_container conn_cont;
47 struct class_device_attribute *conn_attrs[ISCSI_CONN_ATTRS + 1];
48 struct transport_container session_cont;
49 struct class_device_attribute *session_attrs[ISCSI_SESSION_ATTRS + 1];
52 static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
53 static struct workqueue_struct *iscsi_eh_timer_workq;
56 * list of registered transports and lock that must
57 * be held while accessing list. The iscsi_transport_lock must
58 * be acquired after the rx_queue_mutex.
60 static LIST_HEAD(iscsi_transports);
61 static DEFINE_SPINLOCK(iscsi_transport_lock);
63 #define to_iscsi_internal(tmpl) \
64 container_of(tmpl, struct iscsi_internal, t)
66 #define cdev_to_iscsi_internal(_cdev) \
67 container_of(_cdev, struct iscsi_internal, cdev)
69 static void iscsi_transport_release(struct class_device *cdev)
71 struct iscsi_internal *priv = cdev_to_iscsi_internal(cdev);
76 * iscsi_transport_class represents the iscsi_transports that are
79 static struct class iscsi_transport_class = {
80 .name = "iscsi_transport",
81 .release = iscsi_transport_release,
85 show_transport_handle(struct class_device *cdev, char *buf)
87 struct iscsi_internal *priv = cdev_to_iscsi_internal(cdev);
88 return sprintf(buf, "%llu\n", (unsigned long long)iscsi_handle(priv->iscsi_transport));
90 static CLASS_DEVICE_ATTR(handle, S_IRUGO, show_transport_handle, NULL);
92 #define show_transport_attr(name, format) \
94 show_transport_##name(struct class_device *cdev, char *buf) \
96 struct iscsi_internal *priv = cdev_to_iscsi_internal(cdev); \
97 return sprintf(buf, format"\n", priv->iscsi_transport->name); \
99 static CLASS_DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL);
101 show_transport_attr(caps, "0x%x");
102 show_transport_attr(max_lun, "%d");
103 show_transport_attr(max_conn, "%d");
104 show_transport_attr(max_cmd_len, "%d");
106 static struct attribute *iscsi_transport_attrs[] = {
107 &class_device_attr_handle.attr,
108 &class_device_attr_caps.attr,
109 &class_device_attr_max_lun.attr,
110 &class_device_attr_max_conn.attr,
111 &class_device_attr_max_cmd_len.attr,
115 static struct attribute_group iscsi_transport_group = {
116 .attrs = iscsi_transport_attrs,
121 static int iscsi_setup_host(struct transport_container *tc, struct device *dev,
122 struct class_device *cdev)
124 struct Scsi_Host *shost = dev_to_shost(dev);
125 struct iscsi_host *ihost = shost->shost_data;
127 memset(ihost, 0, sizeof(*ihost));
128 INIT_LIST_HEAD(&ihost->sessions);
129 mutex_init(&ihost->mutex);
131 snprintf(ihost->unbind_workq_name, KOBJ_NAME_LEN, "iscsi_unbind_%d",
133 ihost->unbind_workq = create_singlethread_workqueue(
134 ihost->unbind_workq_name);
135 if (!ihost->unbind_workq)
140 static int iscsi_remove_host(struct transport_container *tc, struct device *dev,
141 struct class_device *cdev)
143 struct Scsi_Host *shost = dev_to_shost(dev);
144 struct iscsi_host *ihost = shost->shost_data;
146 destroy_workqueue(ihost->unbind_workq);
150 static DECLARE_TRANSPORT_CLASS(iscsi_host_class,
156 static DECLARE_TRANSPORT_CLASS(iscsi_session_class,
162 static DECLARE_TRANSPORT_CLASS(iscsi_connection_class,
168 static struct sock *nls;
169 static DEFINE_MUTEX(rx_queue_mutex);
171 static LIST_HEAD(sesslist);
172 static DEFINE_SPINLOCK(sesslock);
173 static LIST_HEAD(connlist);
174 static DEFINE_SPINLOCK(connlock);
176 static uint32_t iscsi_conn_get_sid(struct iscsi_cls_conn *conn)
178 struct iscsi_cls_session *sess = iscsi_dev_to_session(conn->dev.parent);
183 * Returns the matching session to a given sid
185 static struct iscsi_cls_session *iscsi_session_lookup(uint32_t sid)
188 struct iscsi_cls_session *sess;
190 spin_lock_irqsave(&sesslock, flags);
191 list_for_each_entry(sess, &sesslist, sess_list) {
192 if (sess->sid == sid) {
193 spin_unlock_irqrestore(&sesslock, flags);
197 spin_unlock_irqrestore(&sesslock, flags);
202 * Returns the matching connection to a given sid / cid tuple
204 static struct iscsi_cls_conn *iscsi_conn_lookup(uint32_t sid, uint32_t cid)
207 struct iscsi_cls_conn *conn;
209 spin_lock_irqsave(&connlock, flags);
210 list_for_each_entry(conn, &connlist, conn_list) {
211 if ((conn->cid == cid) && (iscsi_conn_get_sid(conn) == sid)) {
212 spin_unlock_irqrestore(&connlock, flags);
216 spin_unlock_irqrestore(&connlock, flags);
221 * The following functions can be used by LLDs that allocate
222 * their own scsi_hosts or by software iscsi LLDs
224 static void iscsi_session_release(struct device *dev)
226 struct iscsi_cls_session *session = iscsi_dev_to_session(dev);
227 struct Scsi_Host *shost;
229 shost = iscsi_session_to_shost(session);
230 scsi_host_put(shost);
234 static int iscsi_is_session_dev(const struct device *dev)
236 return dev->release == iscsi_session_release;
239 static int iscsi_user_scan(struct Scsi_Host *shost, uint channel,
242 struct iscsi_host *ihost = shost->shost_data;
243 struct iscsi_cls_session *session;
245 mutex_lock(&ihost->mutex);
246 list_for_each_entry(session, &ihost->sessions, host_list) {
247 if ((channel == SCAN_WILD_CARD || channel == 0) &&
248 (id == SCAN_WILD_CARD || id == session->target_id))
249 scsi_scan_target(&session->dev, 0,
250 session->target_id, lun, 1);
252 mutex_unlock(&ihost->mutex);
257 static void session_recovery_timedout(struct work_struct *work)
259 struct iscsi_cls_session *session =
260 container_of(work, struct iscsi_cls_session,
263 dev_printk(KERN_INFO, &session->dev, "iscsi: session recovery timed "
264 "out after %d secs\n", session->recovery_tmo);
266 if (session->transport->session_recovery_timedout)
267 session->transport->session_recovery_timedout(session);
269 scsi_target_unblock(&session->dev);
272 void iscsi_unblock_session(struct iscsi_cls_session *session)
274 if (!cancel_delayed_work(&session->recovery_work))
275 flush_workqueue(iscsi_eh_timer_workq);
276 scsi_target_unblock(&session->dev);
278 EXPORT_SYMBOL_GPL(iscsi_unblock_session);
280 void iscsi_block_session(struct iscsi_cls_session *session)
282 scsi_target_block(&session->dev);
283 queue_delayed_work(iscsi_eh_timer_workq, &session->recovery_work,
284 session->recovery_tmo * HZ);
286 EXPORT_SYMBOL_GPL(iscsi_block_session);
288 static void __iscsi_unbind_session(struct work_struct *work)
290 struct iscsi_cls_session *session =
291 container_of(work, struct iscsi_cls_session,
293 struct Scsi_Host *shost = iscsi_session_to_shost(session);
294 struct iscsi_host *ihost = shost->shost_data;
296 /* Prevent new scans and make sure scanning is not in progress */
297 mutex_lock(&ihost->mutex);
298 if (list_empty(&session->host_list)) {
299 mutex_unlock(&ihost->mutex);
302 list_del_init(&session->host_list);
303 mutex_unlock(&ihost->mutex);
305 scsi_remove_target(&session->dev);
306 iscsi_session_event(session, ISCSI_KEVENT_UNBIND_SESSION);
309 static int iscsi_unbind_session(struct iscsi_cls_session *session)
311 struct Scsi_Host *shost = iscsi_session_to_shost(session);
312 struct iscsi_host *ihost = shost->shost_data;
314 return queue_work(ihost->unbind_workq, &session->unbind_work);
317 struct iscsi_cls_session *
318 iscsi_alloc_session(struct Scsi_Host *shost,
319 struct iscsi_transport *transport)
321 struct iscsi_cls_session *session;
323 session = kzalloc(sizeof(*session) + transport->sessiondata_size,
328 session->transport = transport;
329 session->recovery_tmo = 120;
330 INIT_DELAYED_WORK(&session->recovery_work, session_recovery_timedout);
331 INIT_LIST_HEAD(&session->host_list);
332 INIT_LIST_HEAD(&session->sess_list);
333 INIT_WORK(&session->unbind_work, __iscsi_unbind_session);
335 /* this is released in the dev's release function */
336 scsi_host_get(shost);
337 session->dev.parent = &shost->shost_gendev;
338 session->dev.release = iscsi_session_release;
339 device_initialize(&session->dev);
340 if (transport->sessiondata_size)
341 session->dd_data = &session[1];
344 EXPORT_SYMBOL_GPL(iscsi_alloc_session);
346 int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
348 struct Scsi_Host *shost = iscsi_session_to_shost(session);
349 struct iscsi_host *ihost;
353 ihost = shost->shost_data;
354 session->sid = atomic_add_return(1, &iscsi_session_nr);
355 session->target_id = target_id;
357 snprintf(session->dev.bus_id, BUS_ID_SIZE, "session%u",
359 err = device_add(&session->dev);
361 dev_printk(KERN_ERR, &session->dev, "iscsi: could not "
362 "register session's dev\n");
365 transport_register_device(&session->dev);
367 spin_lock_irqsave(&sesslock, flags);
368 list_add(&session->sess_list, &sesslist);
369 spin_unlock_irqrestore(&sesslock, flags);
371 mutex_lock(&ihost->mutex);
372 list_add(&session->host_list, &ihost->sessions);
373 mutex_unlock(&ihost->mutex);
375 iscsi_session_event(session, ISCSI_KEVENT_CREATE_SESSION);
379 scsi_host_put(shost);
382 EXPORT_SYMBOL_GPL(iscsi_add_session);
385 * iscsi_create_session - create iscsi class session
387 * @transport: iscsi transport
388 * @target_id: which target
390 * This can be called from a LLD or iscsi_transport.
392 struct iscsi_cls_session *
393 iscsi_create_session(struct Scsi_Host *shost,
394 struct iscsi_transport *transport,
395 unsigned int target_id)
397 struct iscsi_cls_session *session;
399 session = iscsi_alloc_session(shost, transport);
403 if (iscsi_add_session(session, target_id)) {
404 iscsi_free_session(session);
409 EXPORT_SYMBOL_GPL(iscsi_create_session);
411 static void iscsi_conn_release(struct device *dev)
413 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev);
414 struct device *parent = conn->dev.parent;
420 static int iscsi_is_conn_dev(const struct device *dev)
422 return dev->release == iscsi_conn_release;
425 static int iscsi_iter_destroy_conn_fn(struct device *dev, void *data)
427 if (!iscsi_is_conn_dev(dev))
429 return iscsi_destroy_conn(iscsi_dev_to_conn(dev));
432 void iscsi_remove_session(struct iscsi_cls_session *session)
434 struct Scsi_Host *shost = iscsi_session_to_shost(session);
435 struct iscsi_host *ihost = shost->shost_data;
439 spin_lock_irqsave(&sesslock, flags);
440 list_del(&session->sess_list);
441 spin_unlock_irqrestore(&sesslock, flags);
444 * If we are blocked let commands flow again. The lld or iscsi
445 * layer should set up the queuecommand to fail commands.
447 iscsi_unblock_session(session);
448 iscsi_unbind_session(session);
450 * If the session dropped while removing devices then we need to make
451 * sure it is not blocked
453 if (!cancel_delayed_work(&session->recovery_work))
454 flush_workqueue(iscsi_eh_timer_workq);
455 flush_workqueue(ihost->unbind_workq);
457 /* hw iscsi may not have removed all connections from session */
458 err = device_for_each_child(&session->dev, NULL,
459 iscsi_iter_destroy_conn_fn);
461 dev_printk(KERN_ERR, &session->dev, "iscsi: Could not delete "
462 "all connections for session. Error %d.\n", err);
464 transport_unregister_device(&session->dev);
465 device_del(&session->dev);
467 EXPORT_SYMBOL_GPL(iscsi_remove_session);
469 void iscsi_free_session(struct iscsi_cls_session *session)
471 iscsi_session_event(session, ISCSI_KEVENT_DESTROY_SESSION);
472 put_device(&session->dev);
474 EXPORT_SYMBOL_GPL(iscsi_free_session);
477 * iscsi_destroy_session - destroy iscsi session
478 * @session: iscsi_session
480 * Can be called by a LLD or iscsi_transport. There must not be
481 * any running connections.
483 int iscsi_destroy_session(struct iscsi_cls_session *session)
485 iscsi_remove_session(session);
486 iscsi_free_session(session);
489 EXPORT_SYMBOL_GPL(iscsi_destroy_session);
492 * iscsi_create_conn - create iscsi class connection
493 * @session: iscsi cls session
494 * @cid: connection id
496 * This can be called from a LLD or iscsi_transport. The connection
497 * is child of the session so cid must be unique for all connections
500 * Since we do not support MCS, cid will normally be zero. In some cases
501 * for software iscsi we could be trying to preallocate a connection struct
502 * in which case there could be two connection structs and cid would be
505 struct iscsi_cls_conn *
506 iscsi_create_conn(struct iscsi_cls_session *session, uint32_t cid)
508 struct iscsi_transport *transport = session->transport;
509 struct iscsi_cls_conn *conn;
513 conn = kzalloc(sizeof(*conn) + transport->conndata_size, GFP_KERNEL);
517 if (transport->conndata_size)
518 conn->dd_data = &conn[1];
520 INIT_LIST_HEAD(&conn->conn_list);
521 conn->transport = transport;
524 /* this is released in the dev's release function */
525 if (!get_device(&session->dev))
528 snprintf(conn->dev.bus_id, BUS_ID_SIZE, "connection%d:%u",
530 conn->dev.parent = &session->dev;
531 conn->dev.release = iscsi_conn_release;
532 err = device_register(&conn->dev);
534 dev_printk(KERN_ERR, &conn->dev, "iscsi: could not register "
535 "connection's dev\n");
536 goto release_parent_ref;
538 transport_register_device(&conn->dev);
540 spin_lock_irqsave(&connlock, flags);
541 list_add(&conn->conn_list, &connlist);
543 spin_unlock_irqrestore(&connlock, flags);
547 put_device(&session->dev);
553 EXPORT_SYMBOL_GPL(iscsi_create_conn);
556 * iscsi_destroy_conn - destroy iscsi class connection
557 * @conn: iscsi cls session
559 * This can be called from a LLD or iscsi_transport.
561 int iscsi_destroy_conn(struct iscsi_cls_conn *conn)
565 spin_lock_irqsave(&connlock, flags);
567 list_del(&conn->conn_list);
568 spin_unlock_irqrestore(&connlock, flags);
570 transport_unregister_device(&conn->dev);
571 device_unregister(&conn->dev);
574 EXPORT_SYMBOL_GPL(iscsi_destroy_conn);
577 * iscsi interface functions
579 static struct iscsi_internal *
580 iscsi_if_transport_lookup(struct iscsi_transport *tt)
582 struct iscsi_internal *priv;
585 spin_lock_irqsave(&iscsi_transport_lock, flags);
586 list_for_each_entry(priv, &iscsi_transports, list) {
587 if (tt == priv->iscsi_transport) {
588 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
592 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
597 iscsi_broadcast_skb(struct sk_buff *skb, gfp_t gfp)
601 rc = netlink_broadcast(nls, skb, 0, 1, gfp);
603 printk(KERN_ERR "iscsi: can not broadcast skb (%d)\n", rc);
611 iscsi_unicast_skb(struct sk_buff *skb, int pid)
615 rc = netlink_unicast(nls, skb, pid, MSG_DONTWAIT);
617 printk(KERN_ERR "iscsi: can not unicast skb (%d)\n", rc);
624 int iscsi_recv_pdu(struct iscsi_cls_conn *conn, struct iscsi_hdr *hdr,
625 char *data, uint32_t data_size)
627 struct nlmsghdr *nlh;
629 struct iscsi_uevent *ev;
631 struct iscsi_internal *priv;
632 int len = NLMSG_SPACE(sizeof(*ev) + sizeof(struct iscsi_hdr) +
635 priv = iscsi_if_transport_lookup(conn->transport);
639 skb = alloc_skb(len, GFP_ATOMIC);
641 iscsi_conn_error(conn, ISCSI_ERR_CONN_FAILED);
642 dev_printk(KERN_ERR, &conn->dev, "iscsi: can not deliver "
643 "control PDU: OOM\n");
647 nlh = __nlmsg_put(skb, priv->daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
648 ev = NLMSG_DATA(nlh);
649 memset(ev, 0, sizeof(*ev));
650 ev->transport_handle = iscsi_handle(conn->transport);
651 ev->type = ISCSI_KEVENT_RECV_PDU;
652 ev->r.recv_req.cid = conn->cid;
653 ev->r.recv_req.sid = iscsi_conn_get_sid(conn);
654 pdu = (char*)ev + sizeof(*ev);
655 memcpy(pdu, hdr, sizeof(struct iscsi_hdr));
656 memcpy(pdu + sizeof(struct iscsi_hdr), data, data_size);
658 return iscsi_unicast_skb(skb, priv->daemon_pid);
660 EXPORT_SYMBOL_GPL(iscsi_recv_pdu);
662 void iscsi_conn_error(struct iscsi_cls_conn *conn, enum iscsi_err error)
664 struct nlmsghdr *nlh;
666 struct iscsi_uevent *ev;
667 struct iscsi_internal *priv;
668 int len = NLMSG_SPACE(sizeof(*ev));
670 priv = iscsi_if_transport_lookup(conn->transport);
674 skb = alloc_skb(len, GFP_ATOMIC);
676 dev_printk(KERN_ERR, &conn->dev, "iscsi: gracefully ignored "
677 "conn error (%d)\n", error);
681 nlh = __nlmsg_put(skb, priv->daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
682 ev = NLMSG_DATA(nlh);
683 ev->transport_handle = iscsi_handle(conn->transport);
684 ev->type = ISCSI_KEVENT_CONN_ERROR;
685 ev->r.connerror.error = error;
686 ev->r.connerror.cid = conn->cid;
687 ev->r.connerror.sid = iscsi_conn_get_sid(conn);
689 iscsi_broadcast_skb(skb, GFP_ATOMIC);
691 dev_printk(KERN_INFO, &conn->dev, "iscsi: detected conn error (%d)\n",
694 EXPORT_SYMBOL_GPL(iscsi_conn_error);
697 iscsi_if_send_reply(int pid, int seq, int type, int done, int multi,
698 void *payload, int size)
701 struct nlmsghdr *nlh;
702 int len = NLMSG_SPACE(size);
703 int flags = multi ? NLM_F_MULTI : 0;
704 int t = done ? NLMSG_DONE : type;
706 skb = alloc_skb(len, GFP_ATOMIC);
708 printk(KERN_ERR "Could not allocate skb to send reply.\n");
712 nlh = __nlmsg_put(skb, pid, seq, t, (len - sizeof(*nlh)), 0);
713 nlh->nlmsg_flags = flags;
714 memcpy(NLMSG_DATA(nlh), payload, size);
715 return iscsi_unicast_skb(skb, pid);
719 iscsi_if_get_stats(struct iscsi_transport *transport, struct nlmsghdr *nlh)
721 struct iscsi_uevent *ev = NLMSG_DATA(nlh);
722 struct iscsi_stats *stats;
723 struct sk_buff *skbstat;
724 struct iscsi_cls_conn *conn;
725 struct nlmsghdr *nlhstat;
726 struct iscsi_uevent *evstat;
727 struct iscsi_internal *priv;
728 int len = NLMSG_SPACE(sizeof(*ev) +
729 sizeof(struct iscsi_stats) +
730 sizeof(struct iscsi_stats_custom) *
731 ISCSI_STATS_CUSTOM_MAX);
734 priv = iscsi_if_transport_lookup(transport);
738 conn = iscsi_conn_lookup(ev->u.get_stats.sid, ev->u.get_stats.cid);
745 skbstat = alloc_skb(len, GFP_ATOMIC);
747 dev_printk(KERN_ERR, &conn->dev, "iscsi: can not "
748 "deliver stats: OOM\n");
752 nlhstat = __nlmsg_put(skbstat, priv->daemon_pid, 0, 0,
753 (len - sizeof(*nlhstat)), 0);
754 evstat = NLMSG_DATA(nlhstat);
755 memset(evstat, 0, sizeof(*evstat));
756 evstat->transport_handle = iscsi_handle(conn->transport);
757 evstat->type = nlh->nlmsg_type;
758 evstat->u.get_stats.cid =
760 evstat->u.get_stats.sid =
762 stats = (struct iscsi_stats *)
763 ((char*)evstat + sizeof(*evstat));
764 memset(stats, 0, sizeof(*stats));
766 transport->get_stats(conn, stats);
767 actual_size = NLMSG_SPACE(sizeof(struct iscsi_uevent) +
768 sizeof(struct iscsi_stats) +
769 sizeof(struct iscsi_stats_custom) *
770 stats->custom_length);
771 actual_size -= sizeof(*nlhstat);
772 actual_size = NLMSG_LENGTH(actual_size);
773 skb_trim(skbstat, NLMSG_ALIGN(actual_size));
774 nlhstat->nlmsg_len = actual_size;
776 err = iscsi_unicast_skb(skbstat, priv->daemon_pid);
777 } while (err < 0 && err != -ECONNREFUSED);
783 * iscsi_session_event - send session destr. completion event
784 * @session: iscsi class session
785 * @event: type of event
787 int iscsi_session_event(struct iscsi_cls_session *session,
788 enum iscsi_uevent_e event)
790 struct iscsi_internal *priv;
791 struct Scsi_Host *shost;
792 struct iscsi_uevent *ev;
794 struct nlmsghdr *nlh;
795 int rc, len = NLMSG_SPACE(sizeof(*ev));
797 priv = iscsi_if_transport_lookup(session->transport);
800 shost = iscsi_session_to_shost(session);
802 skb = alloc_skb(len, GFP_KERNEL);
804 dev_printk(KERN_ERR, &session->dev, "Cannot notify userspace "
805 "of session event %u\n", event);
809 nlh = __nlmsg_put(skb, priv->daemon_pid, 0, 0, (len - sizeof(*nlh)), 0);
810 ev = NLMSG_DATA(nlh);
811 ev->transport_handle = iscsi_handle(session->transport);
815 case ISCSI_KEVENT_DESTROY_SESSION:
816 ev->r.d_session.host_no = shost->host_no;
817 ev->r.d_session.sid = session->sid;
819 case ISCSI_KEVENT_CREATE_SESSION:
820 ev->r.c_session_ret.host_no = shost->host_no;
821 ev->r.c_session_ret.sid = session->sid;
823 case ISCSI_KEVENT_UNBIND_SESSION:
824 ev->r.unbind_session.host_no = shost->host_no;
825 ev->r.unbind_session.sid = session->sid;
828 dev_printk(KERN_ERR, &session->dev, "Invalid event %u.\n",
835 * this will occur if the daemon is not up, so we just warn
836 * the user and when the daemon is restarted it will handle it
838 rc = iscsi_broadcast_skb(skb, GFP_KERNEL);
840 dev_printk(KERN_ERR, &session->dev, "Cannot notify userspace "
841 "of session event %u. Check iscsi daemon\n", event);
844 EXPORT_SYMBOL_GPL(iscsi_session_event);
847 iscsi_if_create_session(struct iscsi_internal *priv, struct iscsi_uevent *ev)
849 struct iscsi_transport *transport = priv->iscsi_transport;
850 struct iscsi_cls_session *session;
853 session = transport->create_session(transport, &priv->t,
854 ev->u.c_session.cmds_max,
855 ev->u.c_session.queue_depth,
856 ev->u.c_session.initial_cmdsn,
861 ev->r.c_session_ret.host_no = hostno;
862 ev->r.c_session_ret.sid = session->sid;
867 iscsi_if_create_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
869 struct iscsi_cls_conn *conn;
870 struct iscsi_cls_session *session;
872 session = iscsi_session_lookup(ev->u.c_conn.sid);
874 printk(KERN_ERR "iscsi: invalid session %d\n",
879 conn = transport->create_conn(session, ev->u.c_conn.cid);
881 printk(KERN_ERR "iscsi: couldn't create a new "
882 "connection for session %d\n",
887 ev->r.c_conn_ret.sid = session->sid;
888 ev->r.c_conn_ret.cid = conn->cid;
893 iscsi_if_destroy_conn(struct iscsi_transport *transport, struct iscsi_uevent *ev)
895 struct iscsi_cls_conn *conn;
897 conn = iscsi_conn_lookup(ev->u.d_conn.sid, ev->u.d_conn.cid);
901 if (transport->destroy_conn)
902 transport->destroy_conn(conn);
907 iscsi_set_param(struct iscsi_transport *transport, struct iscsi_uevent *ev)
909 char *data = (char*)ev + sizeof(*ev);
910 struct iscsi_cls_conn *conn;
911 struct iscsi_cls_session *session;
912 int err = 0, value = 0;
914 session = iscsi_session_lookup(ev->u.set_param.sid);
915 conn = iscsi_conn_lookup(ev->u.set_param.sid, ev->u.set_param.cid);
916 if (!conn || !session)
919 switch (ev->u.set_param.param) {
920 case ISCSI_PARAM_SESS_RECOVERY_TMO:
921 sscanf(data, "%d", &value);
923 session->recovery_tmo = value;
926 err = transport->set_param(conn, ev->u.set_param.param,
927 data, ev->u.set_param.len);
934 iscsi_if_transport_ep(struct iscsi_transport *transport,
935 struct iscsi_uevent *ev, int msg_type)
937 struct sockaddr *dst_addr;
941 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
942 if (!transport->ep_connect)
945 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
946 rc = transport->ep_connect(dst_addr,
947 ev->u.ep_connect.non_blocking,
948 &ev->r.ep_connect_ret.handle);
950 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
951 if (!transport->ep_poll)
954 ev->r.retcode = transport->ep_poll(ev->u.ep_poll.ep_handle,
955 ev->u.ep_poll.timeout_ms);
957 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
958 if (!transport->ep_disconnect)
961 transport->ep_disconnect(ev->u.ep_disconnect.ep_handle);
968 iscsi_tgt_dscvr(struct iscsi_transport *transport,
969 struct iscsi_uevent *ev)
971 struct Scsi_Host *shost;
972 struct sockaddr *dst_addr;
975 if (!transport->tgt_dscvr)
978 shost = scsi_host_lookup(ev->u.tgt_dscvr.host_no);
980 printk(KERN_ERR "target discovery could not find host no %u\n",
981 ev->u.tgt_dscvr.host_no);
986 dst_addr = (struct sockaddr *)((char*)ev + sizeof(*ev));
987 err = transport->tgt_dscvr(shost, ev->u.tgt_dscvr.type,
988 ev->u.tgt_dscvr.enable, dst_addr);
989 scsi_host_put(shost);
994 iscsi_set_host_param(struct iscsi_transport *transport,
995 struct iscsi_uevent *ev)
997 char *data = (char*)ev + sizeof(*ev);
998 struct Scsi_Host *shost;
1001 if (!transport->set_host_param)
1004 shost = scsi_host_lookup(ev->u.set_host_param.host_no);
1005 if (IS_ERR(shost)) {
1006 printk(KERN_ERR "set_host_param could not find host no %u\n",
1007 ev->u.set_host_param.host_no);
1011 err = transport->set_host_param(shost, ev->u.set_host_param.param,
1012 data, ev->u.set_host_param.len);
1013 scsi_host_put(shost);
1018 iscsi_if_recv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
1021 struct iscsi_uevent *ev = NLMSG_DATA(nlh);
1022 struct iscsi_transport *transport = NULL;
1023 struct iscsi_internal *priv;
1024 struct iscsi_cls_session *session;
1025 struct iscsi_cls_conn *conn;
1027 priv = iscsi_if_transport_lookup(iscsi_ptr(ev->transport_handle));
1030 transport = priv->iscsi_transport;
1032 if (!try_module_get(transport->owner))
1035 priv->daemon_pid = NETLINK_CREDS(skb)->pid;
1037 switch (nlh->nlmsg_type) {
1038 case ISCSI_UEVENT_CREATE_SESSION:
1039 err = iscsi_if_create_session(priv, ev);
1041 case ISCSI_UEVENT_DESTROY_SESSION:
1042 session = iscsi_session_lookup(ev->u.d_session.sid);
1044 transport->destroy_session(session);
1048 case ISCSI_UEVENT_UNBIND_SESSION:
1049 session = iscsi_session_lookup(ev->u.d_session.sid);
1051 iscsi_unbind_session(session);
1055 case ISCSI_UEVENT_CREATE_CONN:
1056 err = iscsi_if_create_conn(transport, ev);
1058 case ISCSI_UEVENT_DESTROY_CONN:
1059 err = iscsi_if_destroy_conn(transport, ev);
1061 case ISCSI_UEVENT_BIND_CONN:
1062 session = iscsi_session_lookup(ev->u.b_conn.sid);
1063 conn = iscsi_conn_lookup(ev->u.b_conn.sid, ev->u.b_conn.cid);
1065 if (session && conn)
1066 ev->r.retcode = transport->bind_conn(session, conn,
1067 ev->u.b_conn.transport_eph,
1068 ev->u.b_conn.is_leading);
1072 case ISCSI_UEVENT_SET_PARAM:
1073 err = iscsi_set_param(transport, ev);
1075 case ISCSI_UEVENT_START_CONN:
1076 conn = iscsi_conn_lookup(ev->u.start_conn.sid, ev->u.start_conn.cid);
1078 ev->r.retcode = transport->start_conn(conn);
1082 case ISCSI_UEVENT_STOP_CONN:
1083 conn = iscsi_conn_lookup(ev->u.stop_conn.sid, ev->u.stop_conn.cid);
1085 transport->stop_conn(conn, ev->u.stop_conn.flag);
1089 case ISCSI_UEVENT_SEND_PDU:
1090 conn = iscsi_conn_lookup(ev->u.send_pdu.sid, ev->u.send_pdu.cid);
1092 ev->r.retcode = transport->send_pdu(conn,
1093 (struct iscsi_hdr*)((char*)ev + sizeof(*ev)),
1094 (char*)ev + sizeof(*ev) + ev->u.send_pdu.hdr_size,
1095 ev->u.send_pdu.data_size);
1099 case ISCSI_UEVENT_GET_STATS:
1100 err = iscsi_if_get_stats(transport, nlh);
1102 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT:
1103 case ISCSI_UEVENT_TRANSPORT_EP_POLL:
1104 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT:
1105 err = iscsi_if_transport_ep(transport, ev, nlh->nlmsg_type);
1107 case ISCSI_UEVENT_TGT_DSCVR:
1108 err = iscsi_tgt_dscvr(transport, ev);
1110 case ISCSI_UEVENT_SET_HOST_PARAM:
1111 err = iscsi_set_host_param(transport, ev);
1118 module_put(transport->owner);
1123 * Get message from skb. Each message is processed by iscsi_if_recv_msg.
1124 * Malformed skbs with wrong lengths or invalid creds are not processed.
1127 iscsi_if_rx(struct sk_buff *skb)
1129 mutex_lock(&rx_queue_mutex);
1130 while (skb->len >= NLMSG_SPACE(0)) {
1133 struct nlmsghdr *nlh;
1134 struct iscsi_uevent *ev;
1136 nlh = nlmsg_hdr(skb);
1137 if (nlh->nlmsg_len < sizeof(*nlh) ||
1138 skb->len < nlh->nlmsg_len) {
1142 ev = NLMSG_DATA(nlh);
1143 rlen = NLMSG_ALIGN(nlh->nlmsg_len);
1144 if (rlen > skb->len)
1147 err = iscsi_if_recv_msg(skb, nlh);
1149 ev->type = ISCSI_KEVENT_IF_ERROR;
1154 * special case for GET_STATS:
1155 * on success - sending reply and stats from
1156 * inside of if_recv_msg(),
1157 * on error - fall through.
1159 if (ev->type == ISCSI_UEVENT_GET_STATS && !err)
1161 err = iscsi_if_send_reply(
1162 NETLINK_CREDS(skb)->pid, nlh->nlmsg_seq,
1163 nlh->nlmsg_type, 0, 0, ev, sizeof(*ev));
1164 } while (err < 0 && err != -ECONNREFUSED);
1165 skb_pull(skb, rlen);
1167 mutex_unlock(&rx_queue_mutex);
1170 #define iscsi_cdev_to_conn(_cdev) \
1171 iscsi_dev_to_conn(_cdev->dev)
1173 #define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \
1174 struct class_device_attribute class_device_attr_##_prefix##_##_name = \
1175 __ATTR(_name,_mode,_show,_store)
1178 * iSCSI connection attrs
1180 #define iscsi_conn_attr_show(param) \
1182 show_conn_param_##param(struct class_device *cdev, char *buf) \
1184 struct iscsi_cls_conn *conn = iscsi_cdev_to_conn(cdev); \
1185 struct iscsi_transport *t = conn->transport; \
1186 return t->get_conn_param(conn, param, buf); \
1189 #define iscsi_conn_attr(field, param) \
1190 iscsi_conn_attr_show(param) \
1191 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \
1194 iscsi_conn_attr(max_recv_dlength, ISCSI_PARAM_MAX_RECV_DLENGTH);
1195 iscsi_conn_attr(max_xmit_dlength, ISCSI_PARAM_MAX_XMIT_DLENGTH);
1196 iscsi_conn_attr(header_digest, ISCSI_PARAM_HDRDGST_EN);
1197 iscsi_conn_attr(data_digest, ISCSI_PARAM_DATADGST_EN);
1198 iscsi_conn_attr(ifmarker, ISCSI_PARAM_IFMARKER_EN);
1199 iscsi_conn_attr(ofmarker, ISCSI_PARAM_OFMARKER_EN);
1200 iscsi_conn_attr(persistent_port, ISCSI_PARAM_PERSISTENT_PORT);
1201 iscsi_conn_attr(port, ISCSI_PARAM_CONN_PORT);
1202 iscsi_conn_attr(exp_statsn, ISCSI_PARAM_EXP_STATSN);
1203 iscsi_conn_attr(persistent_address, ISCSI_PARAM_PERSISTENT_ADDRESS);
1204 iscsi_conn_attr(address, ISCSI_PARAM_CONN_ADDRESS);
1205 iscsi_conn_attr(ping_tmo, ISCSI_PARAM_PING_TMO);
1206 iscsi_conn_attr(recv_tmo, ISCSI_PARAM_RECV_TMO);
1208 #define iscsi_cdev_to_session(_cdev) \
1209 iscsi_dev_to_session(_cdev->dev)
1212 * iSCSI session attrs
1214 #define iscsi_session_attr_show(param, perm) \
1216 show_session_param_##param(struct class_device *cdev, char *buf) \
1218 struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev); \
1219 struct iscsi_transport *t = session->transport; \
1221 if (perm && !capable(CAP_SYS_ADMIN)) \
1223 return t->get_session_param(session, param, buf); \
1226 #define iscsi_session_attr(field, param, perm) \
1227 iscsi_session_attr_show(param, perm) \
1228 static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \
1231 iscsi_session_attr(targetname, ISCSI_PARAM_TARGET_NAME, 0);
1232 iscsi_session_attr(initial_r2t, ISCSI_PARAM_INITIAL_R2T_EN, 0);
1233 iscsi_session_attr(max_outstanding_r2t, ISCSI_PARAM_MAX_R2T, 0);
1234 iscsi_session_attr(immediate_data, ISCSI_PARAM_IMM_DATA_EN, 0);
1235 iscsi_session_attr(first_burst_len, ISCSI_PARAM_FIRST_BURST, 0);
1236 iscsi_session_attr(max_burst_len, ISCSI_PARAM_MAX_BURST, 0);
1237 iscsi_session_attr(data_pdu_in_order, ISCSI_PARAM_PDU_INORDER_EN, 0);
1238 iscsi_session_attr(data_seq_in_order, ISCSI_PARAM_DATASEQ_INORDER_EN, 0);
1239 iscsi_session_attr(erl, ISCSI_PARAM_ERL, 0);
1240 iscsi_session_attr(tpgt, ISCSI_PARAM_TPGT, 0);
1241 iscsi_session_attr(username, ISCSI_PARAM_USERNAME, 1);
1242 iscsi_session_attr(username_in, ISCSI_PARAM_USERNAME_IN, 1);
1243 iscsi_session_attr(password, ISCSI_PARAM_PASSWORD, 1);
1244 iscsi_session_attr(password_in, ISCSI_PARAM_PASSWORD_IN, 1);
1245 iscsi_session_attr(fast_abort, ISCSI_PARAM_FAST_ABORT, 0);
1246 iscsi_session_attr(abort_tmo, ISCSI_PARAM_ABORT_TMO, 0);
1247 iscsi_session_attr(lu_reset_tmo, ISCSI_PARAM_LU_RESET_TMO, 0);
1249 #define iscsi_priv_session_attr_show(field, format) \
1251 show_priv_session_##field(struct class_device *cdev, char *buf) \
1253 struct iscsi_cls_session *session = iscsi_cdev_to_session(cdev);\
1254 return sprintf(buf, format"\n", session->field); \
1257 #define iscsi_priv_session_attr(field, format) \
1258 iscsi_priv_session_attr_show(field, format) \
1259 static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO, show_priv_session_##field, \
1261 iscsi_priv_session_attr(recovery_tmo, "%d");
1266 #define iscsi_host_attr_show(param) \
1268 show_host_param_##param(struct class_device *cdev, char *buf) \
1270 struct Scsi_Host *shost = transport_class_to_shost(cdev); \
1271 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); \
1272 return priv->iscsi_transport->get_host_param(shost, param, buf); \
1275 #define iscsi_host_attr(field, param) \
1276 iscsi_host_attr_show(param) \
1277 static ISCSI_CLASS_ATTR(host, field, S_IRUGO, show_host_param_##param, \
1280 iscsi_host_attr(netdev, ISCSI_HOST_PARAM_NETDEV_NAME);
1281 iscsi_host_attr(hwaddress, ISCSI_HOST_PARAM_HWADDRESS);
1282 iscsi_host_attr(ipaddress, ISCSI_HOST_PARAM_IPADDRESS);
1283 iscsi_host_attr(initiatorname, ISCSI_HOST_PARAM_INITIATOR_NAME);
1285 #define SETUP_PRIV_SESSION_RD_ATTR(field) \
1287 priv->session_attrs[count] = &class_device_attr_priv_sess_##field; \
1292 #define SETUP_SESSION_RD_ATTR(field, param_flag) \
1294 if (tt->param_mask & param_flag) { \
1295 priv->session_attrs[count] = &class_device_attr_sess_##field; \
1300 #define SETUP_CONN_RD_ATTR(field, param_flag) \
1302 if (tt->param_mask & param_flag) { \
1303 priv->conn_attrs[count] = &class_device_attr_conn_##field; \
1308 #define SETUP_HOST_RD_ATTR(field, param_flag) \
1310 if (tt->host_param_mask & param_flag) { \
1311 priv->host_attrs[count] = &class_device_attr_host_##field; \
1316 static int iscsi_session_match(struct attribute_container *cont,
1319 struct iscsi_cls_session *session;
1320 struct Scsi_Host *shost;
1321 struct iscsi_internal *priv;
1323 if (!iscsi_is_session_dev(dev))
1326 session = iscsi_dev_to_session(dev);
1327 shost = iscsi_session_to_shost(session);
1328 if (!shost->transportt)
1331 priv = to_iscsi_internal(shost->transportt);
1332 if (priv->session_cont.ac.class != &iscsi_session_class.class)
1335 return &priv->session_cont.ac == cont;
1338 static int iscsi_conn_match(struct attribute_container *cont,
1341 struct iscsi_cls_session *session;
1342 struct iscsi_cls_conn *conn;
1343 struct Scsi_Host *shost;
1344 struct iscsi_internal *priv;
1346 if (!iscsi_is_conn_dev(dev))
1349 conn = iscsi_dev_to_conn(dev);
1350 session = iscsi_dev_to_session(conn->dev.parent);
1351 shost = iscsi_session_to_shost(session);
1353 if (!shost->transportt)
1356 priv = to_iscsi_internal(shost->transportt);
1357 if (priv->conn_cont.ac.class != &iscsi_connection_class.class)
1360 return &priv->conn_cont.ac == cont;
1363 static int iscsi_host_match(struct attribute_container *cont,
1366 struct Scsi_Host *shost;
1367 struct iscsi_internal *priv;
1369 if (!scsi_is_host_device(dev))
1372 shost = dev_to_shost(dev);
1373 if (!shost->transportt ||
1374 shost->transportt->host_attrs.ac.class != &iscsi_host_class.class)
1377 priv = to_iscsi_internal(shost->transportt);
1378 return &priv->t.host_attrs.ac == cont;
1381 struct scsi_transport_template *
1382 iscsi_register_transport(struct iscsi_transport *tt)
1384 struct iscsi_internal *priv;
1385 unsigned long flags;
1390 priv = iscsi_if_transport_lookup(tt);
1394 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1397 INIT_LIST_HEAD(&priv->list);
1398 priv->daemon_pid = -1;
1399 priv->iscsi_transport = tt;
1400 priv->t.user_scan = iscsi_user_scan;
1402 priv->cdev.class = &iscsi_transport_class;
1403 snprintf(priv->cdev.class_id, BUS_ID_SIZE, "%s", tt->name);
1404 err = class_device_register(&priv->cdev);
1408 err = sysfs_create_group(&priv->cdev.kobj, &iscsi_transport_group);
1410 goto unregister_cdev;
1412 /* host parameters */
1413 priv->t.host_attrs.ac.attrs = &priv->host_attrs[0];
1414 priv->t.host_attrs.ac.class = &iscsi_host_class.class;
1415 priv->t.host_attrs.ac.match = iscsi_host_match;
1416 priv->t.host_size = sizeof(struct iscsi_host);
1417 transport_container_register(&priv->t.host_attrs);
1419 SETUP_HOST_RD_ATTR(netdev, ISCSI_HOST_NETDEV_NAME);
1420 SETUP_HOST_RD_ATTR(ipaddress, ISCSI_HOST_IPADDRESS);
1421 SETUP_HOST_RD_ATTR(hwaddress, ISCSI_HOST_HWADDRESS);
1422 SETUP_HOST_RD_ATTR(initiatorname, ISCSI_HOST_INITIATOR_NAME);
1423 BUG_ON(count > ISCSI_HOST_ATTRS);
1424 priv->host_attrs[count] = NULL;
1427 /* connection parameters */
1428 priv->conn_cont.ac.attrs = &priv->conn_attrs[0];
1429 priv->conn_cont.ac.class = &iscsi_connection_class.class;
1430 priv->conn_cont.ac.match = iscsi_conn_match;
1431 transport_container_register(&priv->conn_cont);
1433 SETUP_CONN_RD_ATTR(max_recv_dlength, ISCSI_MAX_RECV_DLENGTH);
1434 SETUP_CONN_RD_ATTR(max_xmit_dlength, ISCSI_MAX_XMIT_DLENGTH);
1435 SETUP_CONN_RD_ATTR(header_digest, ISCSI_HDRDGST_EN);
1436 SETUP_CONN_RD_ATTR(data_digest, ISCSI_DATADGST_EN);
1437 SETUP_CONN_RD_ATTR(ifmarker, ISCSI_IFMARKER_EN);
1438 SETUP_CONN_RD_ATTR(ofmarker, ISCSI_OFMARKER_EN);
1439 SETUP_CONN_RD_ATTR(address, ISCSI_CONN_ADDRESS);
1440 SETUP_CONN_RD_ATTR(port, ISCSI_CONN_PORT);
1441 SETUP_CONN_RD_ATTR(exp_statsn, ISCSI_EXP_STATSN);
1442 SETUP_CONN_RD_ATTR(persistent_address, ISCSI_PERSISTENT_ADDRESS);
1443 SETUP_CONN_RD_ATTR(persistent_port, ISCSI_PERSISTENT_PORT);
1444 SETUP_CONN_RD_ATTR(ping_tmo, ISCSI_PING_TMO);
1445 SETUP_CONN_RD_ATTR(recv_tmo, ISCSI_RECV_TMO);
1447 BUG_ON(count > ISCSI_CONN_ATTRS);
1448 priv->conn_attrs[count] = NULL;
1451 /* session parameters */
1452 priv->session_cont.ac.attrs = &priv->session_attrs[0];
1453 priv->session_cont.ac.class = &iscsi_session_class.class;
1454 priv->session_cont.ac.match = iscsi_session_match;
1455 transport_container_register(&priv->session_cont);
1457 SETUP_SESSION_RD_ATTR(initial_r2t, ISCSI_INITIAL_R2T_EN);
1458 SETUP_SESSION_RD_ATTR(max_outstanding_r2t, ISCSI_MAX_R2T);
1459 SETUP_SESSION_RD_ATTR(immediate_data, ISCSI_IMM_DATA_EN);
1460 SETUP_SESSION_RD_ATTR(first_burst_len, ISCSI_FIRST_BURST);
1461 SETUP_SESSION_RD_ATTR(max_burst_len, ISCSI_MAX_BURST);
1462 SETUP_SESSION_RD_ATTR(data_pdu_in_order, ISCSI_PDU_INORDER_EN);
1463 SETUP_SESSION_RD_ATTR(data_seq_in_order, ISCSI_DATASEQ_INORDER_EN);
1464 SETUP_SESSION_RD_ATTR(erl, ISCSI_ERL);
1465 SETUP_SESSION_RD_ATTR(targetname, ISCSI_TARGET_NAME);
1466 SETUP_SESSION_RD_ATTR(tpgt, ISCSI_TPGT);
1467 SETUP_SESSION_RD_ATTR(password, ISCSI_USERNAME);
1468 SETUP_SESSION_RD_ATTR(password_in, ISCSI_USERNAME_IN);
1469 SETUP_SESSION_RD_ATTR(username, ISCSI_PASSWORD);
1470 SETUP_SESSION_RD_ATTR(username_in, ISCSI_PASSWORD_IN);
1471 SETUP_SESSION_RD_ATTR(fast_abort, ISCSI_FAST_ABORT);
1472 SETUP_SESSION_RD_ATTR(abort_tmo, ISCSI_ABORT_TMO);
1473 SETUP_SESSION_RD_ATTR(lu_reset_tmo,ISCSI_LU_RESET_TMO);
1474 SETUP_PRIV_SESSION_RD_ATTR(recovery_tmo);
1476 BUG_ON(count > ISCSI_SESSION_ATTRS);
1477 priv->session_attrs[count] = NULL;
1479 spin_lock_irqsave(&iscsi_transport_lock, flags);
1480 list_add(&priv->list, &iscsi_transports);
1481 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
1483 printk(KERN_NOTICE "iscsi: registered transport (%s)\n", tt->name);
1487 class_device_unregister(&priv->cdev);
1492 EXPORT_SYMBOL_GPL(iscsi_register_transport);
1494 int iscsi_unregister_transport(struct iscsi_transport *tt)
1496 struct iscsi_internal *priv;
1497 unsigned long flags;
1501 mutex_lock(&rx_queue_mutex);
1503 priv = iscsi_if_transport_lookup(tt);
1506 spin_lock_irqsave(&iscsi_transport_lock, flags);
1507 list_del(&priv->list);
1508 spin_unlock_irqrestore(&iscsi_transport_lock, flags);
1510 transport_container_unregister(&priv->conn_cont);
1511 transport_container_unregister(&priv->session_cont);
1512 transport_container_unregister(&priv->t.host_attrs);
1514 sysfs_remove_group(&priv->cdev.kobj, &iscsi_transport_group);
1515 class_device_unregister(&priv->cdev);
1516 mutex_unlock(&rx_queue_mutex);
1520 EXPORT_SYMBOL_GPL(iscsi_unregister_transport);
1522 static __init int iscsi_transport_init(void)
1526 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
1527 ISCSI_TRANSPORT_VERSION);
1529 atomic_set(&iscsi_session_nr, 0);
1531 err = class_register(&iscsi_transport_class);
1535 err = transport_class_register(&iscsi_host_class);
1537 goto unregister_transport_class;
1539 err = transport_class_register(&iscsi_connection_class);
1541 goto unregister_host_class;
1543 err = transport_class_register(&iscsi_session_class);
1545 goto unregister_conn_class;
1547 nls = netlink_kernel_create(&init_net, NETLINK_ISCSI, 1, iscsi_if_rx, NULL,
1551 goto unregister_session_class;
1554 iscsi_eh_timer_workq = create_singlethread_workqueue("iscsi_eh");
1555 if (!iscsi_eh_timer_workq)
1561 sock_release(nls->sk_socket);
1562 unregister_session_class:
1563 transport_class_unregister(&iscsi_session_class);
1564 unregister_conn_class:
1565 transport_class_unregister(&iscsi_connection_class);
1566 unregister_host_class:
1567 transport_class_unregister(&iscsi_host_class);
1568 unregister_transport_class:
1569 class_unregister(&iscsi_transport_class);
1573 static void __exit iscsi_transport_exit(void)
1575 destroy_workqueue(iscsi_eh_timer_workq);
1576 sock_release(nls->sk_socket);
1577 transport_class_unregister(&iscsi_connection_class);
1578 transport_class_unregister(&iscsi_session_class);
1579 transport_class_unregister(&iscsi_host_class);
1580 class_unregister(&iscsi_transport_class);
1583 module_init(iscsi_transport_init);
1584 module_exit(iscsi_transport_exit);
1586 MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
1587 "Dmitry Yusupov <dmitry_yus@yahoo.com>, "
1588 "Alex Aizman <itn780@yahoo.com>");
1589 MODULE_DESCRIPTION("iSCSI Transport Interface");
1590 MODULE_LICENSE("GPL");
1591 MODULE_VERSION(ISCSI_TRANSPORT_VERSION);