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>
25 #include <linux/slab.h>
26 #include <linux/bsg-lib.h>
28 #include <scsi/scsi.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_transport.h>
32 #include <scsi/scsi_transport_iscsi.h>
33 #include <scsi/iscsi_if.h>
34 #include <scsi/scsi_cmnd.h>
35 #include <scsi/scsi_bsg_iscsi.h>
37 #define ISCSI_TRANSPORT_VERSION "2.0-870"
39 static int dbg_session
;
40 module_param_named(debug_session
, dbg_session
, int,
42 MODULE_PARM_DESC(debug_session
,
43 "Turn on debugging for sessions in scsi_transport_iscsi "
44 "module. Set to 1 to turn on, and zero to turn off. Default "
48 module_param_named(debug_conn
, dbg_conn
, int,
50 MODULE_PARM_DESC(debug_conn
,
51 "Turn on debugging for connections in scsi_transport_iscsi "
52 "module. Set to 1 to turn on, and zero to turn off. Default "
55 #define ISCSI_DBG_TRANS_SESSION(_session, dbg_fmt, arg...) \
58 iscsi_cls_session_printk(KERN_INFO, _session, \
63 #define ISCSI_DBG_TRANS_CONN(_conn, dbg_fmt, arg...) \
66 iscsi_cls_conn_printk(KERN_INFO, _conn, \
71 struct iscsi_internal
{
72 struct scsi_transport_template t
;
73 struct iscsi_transport
*iscsi_transport
;
74 struct list_head list
;
77 struct transport_container conn_cont
;
78 struct transport_container session_cont
;
81 static atomic_t iscsi_session_nr
; /* sysfs session id for next new session */
82 static struct workqueue_struct
*iscsi_eh_timer_workq
;
85 * list of registered transports and lock that must
86 * be held while accessing list. The iscsi_transport_lock must
87 * be acquired after the rx_queue_mutex.
89 static LIST_HEAD(iscsi_transports
);
90 static DEFINE_SPINLOCK(iscsi_transport_lock
);
92 #define to_iscsi_internal(tmpl) \
93 container_of(tmpl, struct iscsi_internal, t)
95 #define dev_to_iscsi_internal(_dev) \
96 container_of(_dev, struct iscsi_internal, dev)
98 static void iscsi_transport_release(struct device
*dev
)
100 struct iscsi_internal
*priv
= dev_to_iscsi_internal(dev
);
105 * iscsi_transport_class represents the iscsi_transports that are
108 static struct class iscsi_transport_class
= {
109 .name
= "iscsi_transport",
110 .dev_release
= iscsi_transport_release
,
114 show_transport_handle(struct device
*dev
, struct device_attribute
*attr
,
117 struct iscsi_internal
*priv
= dev_to_iscsi_internal(dev
);
118 return sprintf(buf
, "%llu\n", (unsigned long long)iscsi_handle(priv
->iscsi_transport
));
120 static DEVICE_ATTR(handle
, S_IRUGO
, show_transport_handle
, NULL
);
122 #define show_transport_attr(name, format) \
124 show_transport_##name(struct device *dev, \
125 struct device_attribute *attr,char *buf) \
127 struct iscsi_internal *priv = dev_to_iscsi_internal(dev); \
128 return sprintf(buf, format"\n", priv->iscsi_transport->name); \
130 static DEVICE_ATTR(name, S_IRUGO, show_transport_##name, NULL);
132 show_transport_attr(caps
, "0x%x");
134 static struct attribute
*iscsi_transport_attrs
[] = {
135 &dev_attr_handle
.attr
,
140 static struct attribute_group iscsi_transport_group
= {
141 .attrs
= iscsi_transport_attrs
,
145 * iSCSI endpoint attrs
147 #define iscsi_dev_to_endpoint(_dev) \
148 container_of(_dev, struct iscsi_endpoint, dev)
150 #define ISCSI_ATTR(_prefix,_name,_mode,_show,_store) \
151 struct device_attribute dev_attr_##_prefix##_##_name = \
152 __ATTR(_name,_mode,_show,_store)
154 static void iscsi_endpoint_release(struct device
*dev
)
156 struct iscsi_endpoint
*ep
= iscsi_dev_to_endpoint(dev
);
160 static struct class iscsi_endpoint_class
= {
161 .name
= "iscsi_endpoint",
162 .dev_release
= iscsi_endpoint_release
,
166 show_ep_handle(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
168 struct iscsi_endpoint
*ep
= iscsi_dev_to_endpoint(dev
);
169 return sprintf(buf
, "%llu\n", (unsigned long long) ep
->id
);
171 static ISCSI_ATTR(ep
, handle
, S_IRUGO
, show_ep_handle
, NULL
);
173 static struct attribute
*iscsi_endpoint_attrs
[] = {
174 &dev_attr_ep_handle
.attr
,
178 static struct attribute_group iscsi_endpoint_group
= {
179 .attrs
= iscsi_endpoint_attrs
,
182 #define ISCSI_MAX_EPID -1
184 static int iscsi_match_epid(struct device
*dev
, void *data
)
186 struct iscsi_endpoint
*ep
= iscsi_dev_to_endpoint(dev
);
187 uint64_t *epid
= (uint64_t *) data
;
189 return *epid
== ep
->id
;
192 struct iscsi_endpoint
*
193 iscsi_create_endpoint(int dd_size
)
196 struct iscsi_endpoint
*ep
;
200 for (id
= 1; id
< ISCSI_MAX_EPID
; id
++) {
201 dev
= class_find_device(&iscsi_endpoint_class
, NULL
, &id
,
206 if (id
== ISCSI_MAX_EPID
) {
207 printk(KERN_ERR
"Too many connections. Max supported %u\n",
212 ep
= kzalloc(sizeof(*ep
) + dd_size
, GFP_KERNEL
);
217 ep
->dev
.class = &iscsi_endpoint_class
;
218 dev_set_name(&ep
->dev
, "ep-%llu", (unsigned long long) id
);
219 err
= device_register(&ep
->dev
);
223 err
= sysfs_create_group(&ep
->dev
.kobj
, &iscsi_endpoint_group
);
228 ep
->dd_data
= &ep
[1];
232 device_unregister(&ep
->dev
);
239 EXPORT_SYMBOL_GPL(iscsi_create_endpoint
);
241 void iscsi_destroy_endpoint(struct iscsi_endpoint
*ep
)
243 sysfs_remove_group(&ep
->dev
.kobj
, &iscsi_endpoint_group
);
244 device_unregister(&ep
->dev
);
246 EXPORT_SYMBOL_GPL(iscsi_destroy_endpoint
);
248 struct iscsi_endpoint
*iscsi_lookup_endpoint(u64 handle
)
250 struct iscsi_endpoint
*ep
;
253 dev
= class_find_device(&iscsi_endpoint_class
, NULL
, &handle
,
258 ep
= iscsi_dev_to_endpoint(dev
);
260 * we can drop this now because the interface will prevent
261 * removals and lookups from racing.
266 EXPORT_SYMBOL_GPL(iscsi_lookup_endpoint
);
269 * Interface to display network param to sysfs
272 static void iscsi_iface_release(struct device
*dev
)
274 struct iscsi_iface
*iface
= iscsi_dev_to_iface(dev
);
275 struct device
*parent
= iface
->dev
.parent
;
282 static struct class iscsi_iface_class
= {
283 .name
= "iscsi_iface",
284 .dev_release
= iscsi_iface_release
,
287 #define ISCSI_IFACE_ATTR(_prefix, _name, _mode, _show, _store) \
288 struct device_attribute dev_attr_##_prefix##_##_name = \
289 __ATTR(_name, _mode, _show, _store)
291 /* iface attrs show */
292 #define iscsi_iface_attr_show(type, name, param_type, param) \
294 show_##type##_##name(struct device *dev, struct device_attribute *attr, \
297 struct iscsi_iface *iface = iscsi_dev_to_iface(dev); \
298 struct iscsi_transport *t = iface->transport; \
299 return t->get_iface_param(iface, param_type, param, buf); \
302 #define iscsi_iface_net_attr(type, name, param) \
303 iscsi_iface_attr_show(type, name, ISCSI_NET_PARAM, param) \
304 static ISCSI_IFACE_ATTR(type, name, S_IRUGO, show_##type##_##name, NULL);
306 /* generic read only ipvi4 attribute */
307 iscsi_iface_net_attr(ipv4_iface
, ipaddress
, ISCSI_NET_PARAM_IPV4_ADDR
);
308 iscsi_iface_net_attr(ipv4_iface
, gateway
, ISCSI_NET_PARAM_IPV4_GW
);
309 iscsi_iface_net_attr(ipv4_iface
, subnet
, ISCSI_NET_PARAM_IPV4_SUBNET
);
310 iscsi_iface_net_attr(ipv4_iface
, bootproto
, ISCSI_NET_PARAM_IPV4_BOOTPROTO
);
312 /* generic read only ipv6 attribute */
313 iscsi_iface_net_attr(ipv6_iface
, ipaddress
, ISCSI_NET_PARAM_IPV6_ADDR
);
314 iscsi_iface_net_attr(ipv6_iface
, link_local_addr
, ISCSI_NET_PARAM_IPV6_LINKLOCAL
);
315 iscsi_iface_net_attr(ipv6_iface
, router_addr
, ISCSI_NET_PARAM_IPV6_ROUTER
);
316 iscsi_iface_net_attr(ipv6_iface
, ipaddr_autocfg
,
317 ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG
);
318 iscsi_iface_net_attr(ipv6_iface
, linklocal_autocfg
,
319 ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG
);
321 /* common read only iface attribute */
322 iscsi_iface_net_attr(iface
, enabled
, ISCSI_NET_PARAM_IFACE_ENABLE
);
323 iscsi_iface_net_attr(iface
, vlan
, ISCSI_NET_PARAM_VLAN_ID
);
324 iscsi_iface_net_attr(iface
, vlan_priority
, ISCSI_NET_PARAM_VLAN_PRIORITY
);
325 iscsi_iface_net_attr(iface
, vlan_enabled
, ISCSI_NET_PARAM_VLAN_ENABLED
);
326 iscsi_iface_net_attr(iface
, mtu
, ISCSI_NET_PARAM_MTU
);
327 iscsi_iface_net_attr(iface
, port
, ISCSI_NET_PARAM_PORT
);
329 static mode_t
iscsi_iface_attr_is_visible(struct kobject
*kobj
,
330 struct attribute
*attr
, int i
)
332 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
333 struct iscsi_iface
*iface
= iscsi_dev_to_iface(dev
);
334 struct iscsi_transport
*t
= iface
->transport
;
337 if (attr
== &dev_attr_iface_enabled
.attr
)
338 param
= ISCSI_NET_PARAM_IFACE_ENABLE
;
339 else if (attr
== &dev_attr_iface_vlan
.attr
)
340 param
= ISCSI_NET_PARAM_VLAN_ID
;
341 else if (attr
== &dev_attr_iface_vlan_priority
.attr
)
342 param
= ISCSI_NET_PARAM_VLAN_PRIORITY
;
343 else if (attr
== &dev_attr_iface_vlan_enabled
.attr
)
344 param
= ISCSI_NET_PARAM_VLAN_ENABLED
;
345 else if (attr
== &dev_attr_iface_mtu
.attr
)
346 param
= ISCSI_NET_PARAM_MTU
;
347 else if (attr
== &dev_attr_iface_port
.attr
)
348 param
= ISCSI_NET_PARAM_PORT
;
349 else if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV4
) {
350 if (attr
== &dev_attr_ipv4_iface_ipaddress
.attr
)
351 param
= ISCSI_NET_PARAM_IPV4_ADDR
;
352 else if (attr
== &dev_attr_ipv4_iface_gateway
.attr
)
353 param
= ISCSI_NET_PARAM_IPV4_GW
;
354 else if (attr
== &dev_attr_ipv4_iface_subnet
.attr
)
355 param
= ISCSI_NET_PARAM_IPV4_SUBNET
;
356 else if (attr
== &dev_attr_ipv4_iface_bootproto
.attr
)
357 param
= ISCSI_NET_PARAM_IPV4_BOOTPROTO
;
360 } else if (iface
->iface_type
== ISCSI_IFACE_TYPE_IPV6
) {
361 if (attr
== &dev_attr_ipv6_iface_ipaddress
.attr
)
362 param
= ISCSI_NET_PARAM_IPV6_ADDR
;
363 else if (attr
== &dev_attr_ipv6_iface_link_local_addr
.attr
)
364 param
= ISCSI_NET_PARAM_IPV6_LINKLOCAL
;
365 else if (attr
== &dev_attr_ipv6_iface_router_addr
.attr
)
366 param
= ISCSI_NET_PARAM_IPV6_ROUTER
;
367 else if (attr
== &dev_attr_ipv6_iface_ipaddr_autocfg
.attr
)
368 param
= ISCSI_NET_PARAM_IPV6_ADDR_AUTOCFG
;
369 else if (attr
== &dev_attr_ipv6_iface_linklocal_autocfg
.attr
)
370 param
= ISCSI_NET_PARAM_IPV6_LINKLOCAL_AUTOCFG
;
374 WARN_ONCE(1, "Invalid iface attr");
378 return t
->attr_is_visible(ISCSI_NET_PARAM
, param
);
381 static struct attribute
*iscsi_iface_attrs
[] = {
382 &dev_attr_iface_enabled
.attr
,
383 &dev_attr_iface_vlan
.attr
,
384 &dev_attr_iface_vlan_priority
.attr
,
385 &dev_attr_iface_vlan_enabled
.attr
,
386 &dev_attr_ipv4_iface_ipaddress
.attr
,
387 &dev_attr_ipv4_iface_gateway
.attr
,
388 &dev_attr_ipv4_iface_subnet
.attr
,
389 &dev_attr_ipv4_iface_bootproto
.attr
,
390 &dev_attr_ipv6_iface_ipaddress
.attr
,
391 &dev_attr_ipv6_iface_link_local_addr
.attr
,
392 &dev_attr_ipv6_iface_router_addr
.attr
,
393 &dev_attr_ipv6_iface_ipaddr_autocfg
.attr
,
394 &dev_attr_ipv6_iface_linklocal_autocfg
.attr
,
395 &dev_attr_iface_mtu
.attr
,
396 &dev_attr_iface_port
.attr
,
400 static struct attribute_group iscsi_iface_group
= {
401 .attrs
= iscsi_iface_attrs
,
402 .is_visible
= iscsi_iface_attr_is_visible
,
406 iscsi_create_iface(struct Scsi_Host
*shost
, struct iscsi_transport
*transport
,
407 uint32_t iface_type
, uint32_t iface_num
, int dd_size
)
409 struct iscsi_iface
*iface
;
412 iface
= kzalloc(sizeof(*iface
) + dd_size
, GFP_KERNEL
);
416 iface
->transport
= transport
;
417 iface
->iface_type
= iface_type
;
418 iface
->iface_num
= iface_num
;
419 iface
->dev
.release
= iscsi_iface_release
;
420 iface
->dev
.class = &iscsi_iface_class
;
421 /* parent reference released in iscsi_iface_release */
422 iface
->dev
.parent
= get_device(&shost
->shost_gendev
);
423 if (iface_type
== ISCSI_IFACE_TYPE_IPV4
)
424 dev_set_name(&iface
->dev
, "ipv4-iface-%u-%u", shost
->host_no
,
427 dev_set_name(&iface
->dev
, "ipv6-iface-%u-%u", shost
->host_no
,
430 err
= device_register(&iface
->dev
);
434 err
= sysfs_create_group(&iface
->dev
.kobj
, &iscsi_iface_group
);
439 iface
->dd_data
= &iface
[1];
443 device_unregister(&iface
->dev
);
447 put_device(iface
->dev
.parent
);
451 EXPORT_SYMBOL_GPL(iscsi_create_iface
);
453 void iscsi_destroy_iface(struct iscsi_iface
*iface
)
455 sysfs_remove_group(&iface
->dev
.kobj
, &iscsi_iface_group
);
456 device_unregister(&iface
->dev
);
458 EXPORT_SYMBOL_GPL(iscsi_destroy_iface
);
464 * iscsi_bsg_host_dispatch - Dispatch command to LLD.
465 * @job: bsg job to be processed
467 static int iscsi_bsg_host_dispatch(struct bsg_job
*job
)
469 struct Scsi_Host
*shost
= iscsi_job_to_shost(job
);
470 struct iscsi_bsg_request
*req
= job
->request
;
471 struct iscsi_bsg_reply
*reply
= job
->reply
;
472 struct iscsi_internal
*i
= to_iscsi_internal(shost
->transportt
);
473 int cmdlen
= sizeof(uint32_t); /* start with length of msgcode */
476 /* check if we have the msgcode value at least */
477 if (job
->request_len
< sizeof(uint32_t)) {
482 /* Validate the host command */
483 switch (req
->msgcode
) {
484 case ISCSI_BSG_HST_VENDOR
:
485 cmdlen
+= sizeof(struct iscsi_bsg_host_vendor
);
486 if ((shost
->hostt
->vendor_id
== 0L) ||
487 (req
->rqst_data
.h_vendor
.vendor_id
!=
488 shost
->hostt
->vendor_id
)) {
498 /* check if we really have all the request data needed */
499 if (job
->request_len
< cmdlen
) {
504 ret
= i
->iscsi_transport
->bsg_request(job
);
509 /* return the errno failure code as the only status */
510 BUG_ON(job
->reply_len
< sizeof(uint32_t));
511 reply
->reply_payload_rcv_len
= 0;
513 job
->reply_len
= sizeof(uint32_t);
514 bsg_job_done(job
, ret
, 0);
519 * iscsi_bsg_host_add - Create and add the bsg hooks to receive requests
520 * @shost: shost for iscsi_host
521 * @cls_host: iscsi_cls_host adding the structures to
524 iscsi_bsg_host_add(struct Scsi_Host
*shost
, struct iscsi_cls_host
*ihost
)
526 struct device
*dev
= &shost
->shost_gendev
;
527 struct iscsi_internal
*i
= to_iscsi_internal(shost
->transportt
);
528 struct request_queue
*q
;
532 if (!i
->iscsi_transport
->bsg_request
)
535 snprintf(bsg_name
, sizeof(bsg_name
), "iscsi_host%d", shost
->host_no
);
537 q
= __scsi_alloc_queue(shost
, bsg_request_fn
);
541 ret
= bsg_setup_queue(dev
, q
, bsg_name
, iscsi_bsg_host_dispatch
, 0);
543 shost_printk(KERN_ERR
, shost
, "bsg interface failed to "
544 "initialize - no request queue\n");
545 blk_cleanup_queue(q
);
553 static int iscsi_setup_host(struct transport_container
*tc
, struct device
*dev
,
556 struct Scsi_Host
*shost
= dev_to_shost(dev
);
557 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
559 memset(ihost
, 0, sizeof(*ihost
));
560 atomic_set(&ihost
->nr_scans
, 0);
561 mutex_init(&ihost
->mutex
);
563 iscsi_bsg_host_add(shost
, ihost
);
564 /* ignore any bsg add error - we just can't do sgio */
569 static int iscsi_remove_host(struct transport_container
*tc
,
570 struct device
*dev
, struct device
*cdev
)
572 struct Scsi_Host
*shost
= dev_to_shost(dev
);
573 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
576 bsg_remove_queue(ihost
->bsg_q
);
577 blk_cleanup_queue(ihost
->bsg_q
);
582 static DECLARE_TRANSPORT_CLASS(iscsi_host_class
,
588 static DECLARE_TRANSPORT_CLASS(iscsi_session_class
,
594 static DECLARE_TRANSPORT_CLASS(iscsi_connection_class
,
600 static struct sock
*nls
;
601 static DEFINE_MUTEX(rx_queue_mutex
);
603 static LIST_HEAD(sesslist
);
604 static DEFINE_SPINLOCK(sesslock
);
605 static LIST_HEAD(connlist
);
606 static DEFINE_SPINLOCK(connlock
);
608 static uint32_t iscsi_conn_get_sid(struct iscsi_cls_conn
*conn
)
610 struct iscsi_cls_session
*sess
= iscsi_dev_to_session(conn
->dev
.parent
);
615 * Returns the matching session to a given sid
617 static struct iscsi_cls_session
*iscsi_session_lookup(uint32_t sid
)
620 struct iscsi_cls_session
*sess
;
622 spin_lock_irqsave(&sesslock
, flags
);
623 list_for_each_entry(sess
, &sesslist
, sess_list
) {
624 if (sess
->sid
== sid
) {
625 spin_unlock_irqrestore(&sesslock
, flags
);
629 spin_unlock_irqrestore(&sesslock
, flags
);
634 * Returns the matching connection to a given sid / cid tuple
636 static struct iscsi_cls_conn
*iscsi_conn_lookup(uint32_t sid
, uint32_t cid
)
639 struct iscsi_cls_conn
*conn
;
641 spin_lock_irqsave(&connlock
, flags
);
642 list_for_each_entry(conn
, &connlist
, conn_list
) {
643 if ((conn
->cid
== cid
) && (iscsi_conn_get_sid(conn
) == sid
)) {
644 spin_unlock_irqrestore(&connlock
, flags
);
648 spin_unlock_irqrestore(&connlock
, flags
);
653 * The following functions can be used by LLDs that allocate
654 * their own scsi_hosts or by software iscsi LLDs
659 } iscsi_session_state_names
[] = {
660 { ISCSI_SESSION_LOGGED_IN
, "LOGGED_IN" },
661 { ISCSI_SESSION_FAILED
, "FAILED" },
662 { ISCSI_SESSION_FREE
, "FREE" },
665 static const char *iscsi_session_state_name(int state
)
670 for (i
= 0; i
< ARRAY_SIZE(iscsi_session_state_names
); i
++) {
671 if (iscsi_session_state_names
[i
].value
== state
) {
672 name
= iscsi_session_state_names
[i
].name
;
679 int iscsi_session_chkready(struct iscsi_cls_session
*session
)
684 spin_lock_irqsave(&session
->lock
, flags
);
685 switch (session
->state
) {
686 case ISCSI_SESSION_LOGGED_IN
:
689 case ISCSI_SESSION_FAILED
:
690 err
= DID_IMM_RETRY
<< 16;
692 case ISCSI_SESSION_FREE
:
693 err
= DID_TRANSPORT_FAILFAST
<< 16;
696 err
= DID_NO_CONNECT
<< 16;
699 spin_unlock_irqrestore(&session
->lock
, flags
);
702 EXPORT_SYMBOL_GPL(iscsi_session_chkready
);
704 int iscsi_is_session_online(struct iscsi_cls_session
*session
)
709 spin_lock_irqsave(&session
->lock
, flags
);
710 if (session
->state
== ISCSI_SESSION_LOGGED_IN
)
712 spin_unlock_irqrestore(&session
->lock
, flags
);
715 EXPORT_SYMBOL_GPL(iscsi_is_session_online
);
717 static void iscsi_session_release(struct device
*dev
)
719 struct iscsi_cls_session
*session
= iscsi_dev_to_session(dev
);
720 struct Scsi_Host
*shost
;
722 shost
= iscsi_session_to_shost(session
);
723 scsi_host_put(shost
);
724 ISCSI_DBG_TRANS_SESSION(session
, "Completing session release\n");
728 static int iscsi_is_session_dev(const struct device
*dev
)
730 return dev
->release
== iscsi_session_release
;
733 static int iscsi_iter_session_fn(struct device
*dev
, void *data
)
735 void (* fn
) (struct iscsi_cls_session
*) = data
;
737 if (!iscsi_is_session_dev(dev
))
739 fn(iscsi_dev_to_session(dev
));
743 void iscsi_host_for_each_session(struct Scsi_Host
*shost
,
744 void (*fn
)(struct iscsi_cls_session
*))
746 device_for_each_child(&shost
->shost_gendev
, fn
,
747 iscsi_iter_session_fn
);
749 EXPORT_SYMBOL_GPL(iscsi_host_for_each_session
);
752 * iscsi_scan_finished - helper to report when running scans are done
754 * @time: scan run time
756 * This function can be used by drives like qla4xxx to report to the scsi
757 * layer when the scans it kicked off at module load time are done.
759 int iscsi_scan_finished(struct Scsi_Host
*shost
, unsigned long time
)
761 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
763 * qla4xxx will have kicked off some session unblocks before calling
764 * scsi_scan_host, so just wait for them to complete.
766 return !atomic_read(&ihost
->nr_scans
);
768 EXPORT_SYMBOL_GPL(iscsi_scan_finished
);
770 struct iscsi_scan_data
{
771 unsigned int channel
;
776 static int iscsi_user_scan_session(struct device
*dev
, void *data
)
778 struct iscsi_scan_data
*scan_data
= data
;
779 struct iscsi_cls_session
*session
;
780 struct Scsi_Host
*shost
;
781 struct iscsi_cls_host
*ihost
;
785 if (!iscsi_is_session_dev(dev
))
788 session
= iscsi_dev_to_session(dev
);
790 ISCSI_DBG_TRANS_SESSION(session
, "Scanning session\n");
792 shost
= iscsi_session_to_shost(session
);
793 ihost
= shost
->shost_data
;
795 mutex_lock(&ihost
->mutex
);
796 spin_lock_irqsave(&session
->lock
, flags
);
797 if (session
->state
!= ISCSI_SESSION_LOGGED_IN
) {
798 spin_unlock_irqrestore(&session
->lock
, flags
);
801 id
= session
->target_id
;
802 spin_unlock_irqrestore(&session
->lock
, flags
);
804 if (id
!= ISCSI_MAX_TARGET
) {
805 if ((scan_data
->channel
== SCAN_WILD_CARD
||
806 scan_data
->channel
== 0) &&
807 (scan_data
->id
== SCAN_WILD_CARD
||
808 scan_data
->id
== id
))
809 scsi_scan_target(&session
->dev
, 0, id
,
814 mutex_unlock(&ihost
->mutex
);
815 ISCSI_DBG_TRANS_SESSION(session
, "Completed session scan\n");
819 static int iscsi_user_scan(struct Scsi_Host
*shost
, uint channel
,
822 struct iscsi_scan_data scan_data
;
824 scan_data
.channel
= channel
;
828 return device_for_each_child(&shost
->shost_gendev
, &scan_data
,
829 iscsi_user_scan_session
);
832 static void iscsi_scan_session(struct work_struct
*work
)
834 struct iscsi_cls_session
*session
=
835 container_of(work
, struct iscsi_cls_session
, scan_work
);
836 struct Scsi_Host
*shost
= iscsi_session_to_shost(session
);
837 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
838 struct iscsi_scan_data scan_data
;
840 scan_data
.channel
= 0;
841 scan_data
.id
= SCAN_WILD_CARD
;
842 scan_data
.lun
= SCAN_WILD_CARD
;
844 iscsi_user_scan_session(&session
->dev
, &scan_data
);
845 atomic_dec(&ihost
->nr_scans
);
849 * iscsi_block_scsi_eh - block scsi eh until session state has transistioned
850 * @cmd: scsi cmd passed to scsi eh handler
852 * If the session is down this function will wait for the recovery
853 * timer to fire or for the session to be logged back in. If the
854 * recovery timer fires then FAST_IO_FAIL is returned. The caller
855 * should pass this error value to the scsi eh.
857 int iscsi_block_scsi_eh(struct scsi_cmnd
*cmd
)
859 struct iscsi_cls_session
*session
=
860 starget_to_session(scsi_target(cmd
->device
));
864 spin_lock_irqsave(&session
->lock
, flags
);
865 while (session
->state
!= ISCSI_SESSION_LOGGED_IN
) {
866 if (session
->state
== ISCSI_SESSION_FREE
) {
870 spin_unlock_irqrestore(&session
->lock
, flags
);
872 spin_lock_irqsave(&session
->lock
, flags
);
874 spin_unlock_irqrestore(&session
->lock
, flags
);
877 EXPORT_SYMBOL_GPL(iscsi_block_scsi_eh
);
879 static void session_recovery_timedout(struct work_struct
*work
)
881 struct iscsi_cls_session
*session
=
882 container_of(work
, struct iscsi_cls_session
,
886 iscsi_cls_session_printk(KERN_INFO
, session
,
887 "session recovery timed out after %d secs\n",
888 session
->recovery_tmo
);
890 spin_lock_irqsave(&session
->lock
, flags
);
891 switch (session
->state
) {
892 case ISCSI_SESSION_FAILED
:
893 session
->state
= ISCSI_SESSION_FREE
;
895 case ISCSI_SESSION_LOGGED_IN
:
896 case ISCSI_SESSION_FREE
:
897 /* we raced with the unblock's flush */
898 spin_unlock_irqrestore(&session
->lock
, flags
);
901 spin_unlock_irqrestore(&session
->lock
, flags
);
903 if (session
->transport
->session_recovery_timedout
)
904 session
->transport
->session_recovery_timedout(session
);
906 ISCSI_DBG_TRANS_SESSION(session
, "Unblocking SCSI target\n");
907 scsi_target_unblock(&session
->dev
);
908 ISCSI_DBG_TRANS_SESSION(session
, "Completed unblocking SCSI target\n");
911 static void __iscsi_unblock_session(struct work_struct
*work
)
913 struct iscsi_cls_session
*session
=
914 container_of(work
, struct iscsi_cls_session
,
916 struct Scsi_Host
*shost
= iscsi_session_to_shost(session
);
917 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
920 ISCSI_DBG_TRANS_SESSION(session
, "Unblocking session\n");
922 * The recovery and unblock work get run from the same workqueue,
923 * so try to cancel it if it was going to run after this unblock.
925 cancel_delayed_work(&session
->recovery_work
);
926 spin_lock_irqsave(&session
->lock
, flags
);
927 session
->state
= ISCSI_SESSION_LOGGED_IN
;
928 spin_unlock_irqrestore(&session
->lock
, flags
);
930 scsi_target_unblock(&session
->dev
);
932 * Only do kernel scanning if the driver is properly hooked into
933 * the async scanning code (drivers like iscsi_tcp do login and
934 * scanning from userspace).
936 if (shost
->hostt
->scan_finished
) {
937 if (scsi_queue_work(shost
, &session
->scan_work
))
938 atomic_inc(&ihost
->nr_scans
);
940 ISCSI_DBG_TRANS_SESSION(session
, "Completed unblocking session\n");
944 * iscsi_unblock_session - set a session as logged in and start IO.
945 * @session: iscsi session
947 * Mark a session as ready to accept IO.
949 void iscsi_unblock_session(struct iscsi_cls_session
*session
)
951 queue_work(iscsi_eh_timer_workq
, &session
->unblock_work
);
953 * make sure all the events have completed before tell the driver
956 flush_workqueue(iscsi_eh_timer_workq
);
958 EXPORT_SYMBOL_GPL(iscsi_unblock_session
);
960 static void __iscsi_block_session(struct work_struct
*work
)
962 struct iscsi_cls_session
*session
=
963 container_of(work
, struct iscsi_cls_session
,
967 ISCSI_DBG_TRANS_SESSION(session
, "Blocking session\n");
968 spin_lock_irqsave(&session
->lock
, flags
);
969 session
->state
= ISCSI_SESSION_FAILED
;
970 spin_unlock_irqrestore(&session
->lock
, flags
);
971 scsi_target_block(&session
->dev
);
972 ISCSI_DBG_TRANS_SESSION(session
, "Completed SCSI target blocking\n");
973 if (session
->recovery_tmo
>= 0)
974 queue_delayed_work(iscsi_eh_timer_workq
,
975 &session
->recovery_work
,
976 session
->recovery_tmo
* HZ
);
979 void iscsi_block_session(struct iscsi_cls_session
*session
)
981 queue_work(iscsi_eh_timer_workq
, &session
->block_work
);
983 EXPORT_SYMBOL_GPL(iscsi_block_session
);
985 static void __iscsi_unbind_session(struct work_struct
*work
)
987 struct iscsi_cls_session
*session
=
988 container_of(work
, struct iscsi_cls_session
,
990 struct Scsi_Host
*shost
= iscsi_session_to_shost(session
);
991 struct iscsi_cls_host
*ihost
= shost
->shost_data
;
994 ISCSI_DBG_TRANS_SESSION(session
, "Unbinding session\n");
996 /* Prevent new scans and make sure scanning is not in progress */
997 mutex_lock(&ihost
->mutex
);
998 spin_lock_irqsave(&session
->lock
, flags
);
999 if (session
->target_id
== ISCSI_MAX_TARGET
) {
1000 spin_unlock_irqrestore(&session
->lock
, flags
);
1001 mutex_unlock(&ihost
->mutex
);
1004 session
->target_id
= ISCSI_MAX_TARGET
;
1005 spin_unlock_irqrestore(&session
->lock
, flags
);
1006 mutex_unlock(&ihost
->mutex
);
1008 scsi_remove_target(&session
->dev
);
1009 iscsi_session_event(session
, ISCSI_KEVENT_UNBIND_SESSION
);
1010 ISCSI_DBG_TRANS_SESSION(session
, "Completed target removal\n");
1013 struct iscsi_cls_session
*
1014 iscsi_alloc_session(struct Scsi_Host
*shost
, struct iscsi_transport
*transport
,
1017 struct iscsi_cls_session
*session
;
1019 session
= kzalloc(sizeof(*session
) + dd_size
,
1024 session
->transport
= transport
;
1025 session
->recovery_tmo
= 120;
1026 session
->state
= ISCSI_SESSION_FREE
;
1027 INIT_DELAYED_WORK(&session
->recovery_work
, session_recovery_timedout
);
1028 INIT_LIST_HEAD(&session
->sess_list
);
1029 INIT_WORK(&session
->unblock_work
, __iscsi_unblock_session
);
1030 INIT_WORK(&session
->block_work
, __iscsi_block_session
);
1031 INIT_WORK(&session
->unbind_work
, __iscsi_unbind_session
);
1032 INIT_WORK(&session
->scan_work
, iscsi_scan_session
);
1033 spin_lock_init(&session
->lock
);
1035 /* this is released in the dev's release function */
1036 scsi_host_get(shost
);
1037 session
->dev
.parent
= &shost
->shost_gendev
;
1038 session
->dev
.release
= iscsi_session_release
;
1039 device_initialize(&session
->dev
);
1041 session
->dd_data
= &session
[1];
1043 ISCSI_DBG_TRANS_SESSION(session
, "Completed session allocation\n");
1046 EXPORT_SYMBOL_GPL(iscsi_alloc_session
);
1048 static int iscsi_get_next_target_id(struct device
*dev
, void *data
)
1050 struct iscsi_cls_session
*session
;
1051 unsigned long flags
;
1054 if (!iscsi_is_session_dev(dev
))
1057 session
= iscsi_dev_to_session(dev
);
1058 spin_lock_irqsave(&session
->lock
, flags
);
1059 if (*((unsigned int *) data
) == session
->target_id
)
1061 spin_unlock_irqrestore(&session
->lock
, flags
);
1065 int iscsi_add_session(struct iscsi_cls_session
*session
, unsigned int target_id
)
1067 struct Scsi_Host
*shost
= iscsi_session_to_shost(session
);
1068 struct iscsi_cls_host
*ihost
;
1069 unsigned long flags
;
1070 unsigned int id
= target_id
;
1073 ihost
= shost
->shost_data
;
1074 session
->sid
= atomic_add_return(1, &iscsi_session_nr
);
1076 if (id
== ISCSI_MAX_TARGET
) {
1077 for (id
= 0; id
< ISCSI_MAX_TARGET
; id
++) {
1078 err
= device_for_each_child(&shost
->shost_gendev
, &id
,
1079 iscsi_get_next_target_id
);
1084 if (id
== ISCSI_MAX_TARGET
) {
1085 iscsi_cls_session_printk(KERN_ERR
, session
,
1086 "Too many iscsi targets. Max "
1087 "number of targets is %d.\n",
1088 ISCSI_MAX_TARGET
- 1);
1093 session
->target_id
= id
;
1095 dev_set_name(&session
->dev
, "session%u", session
->sid
);
1096 err
= device_add(&session
->dev
);
1098 iscsi_cls_session_printk(KERN_ERR
, session
,
1099 "could not register session's dev\n");
1102 transport_register_device(&session
->dev
);
1104 spin_lock_irqsave(&sesslock
, flags
);
1105 list_add(&session
->sess_list
, &sesslist
);
1106 spin_unlock_irqrestore(&sesslock
, flags
);
1108 iscsi_session_event(session
, ISCSI_KEVENT_CREATE_SESSION
);
1109 ISCSI_DBG_TRANS_SESSION(session
, "Completed session adding\n");
1113 scsi_host_put(shost
);
1116 EXPORT_SYMBOL_GPL(iscsi_add_session
);
1119 * iscsi_create_session - create iscsi class session
1121 * @transport: iscsi transport
1122 * @dd_size: private driver data size
1123 * @target_id: which target
1125 * This can be called from a LLD or iscsi_transport.
1127 struct iscsi_cls_session
*
1128 iscsi_create_session(struct Scsi_Host
*shost
, struct iscsi_transport
*transport
,
1129 int dd_size
, unsigned int target_id
)
1131 struct iscsi_cls_session
*session
;
1133 session
= iscsi_alloc_session(shost
, transport
, dd_size
);
1137 if (iscsi_add_session(session
, target_id
)) {
1138 iscsi_free_session(session
);
1143 EXPORT_SYMBOL_GPL(iscsi_create_session
);
1145 static void iscsi_conn_release(struct device
*dev
)
1147 struct iscsi_cls_conn
*conn
= iscsi_dev_to_conn(dev
);
1148 struct device
*parent
= conn
->dev
.parent
;
1150 ISCSI_DBG_TRANS_CONN(conn
, "Releasing conn\n");
1155 static int iscsi_is_conn_dev(const struct device
*dev
)
1157 return dev
->release
== iscsi_conn_release
;
1160 static int iscsi_iter_destroy_conn_fn(struct device
*dev
, void *data
)
1162 if (!iscsi_is_conn_dev(dev
))
1164 return iscsi_destroy_conn(iscsi_dev_to_conn(dev
));
1167 void iscsi_remove_session(struct iscsi_cls_session
*session
)
1169 struct Scsi_Host
*shost
= iscsi_session_to_shost(session
);
1170 unsigned long flags
;
1173 ISCSI_DBG_TRANS_SESSION(session
, "Removing session\n");
1175 spin_lock_irqsave(&sesslock
, flags
);
1176 list_del(&session
->sess_list
);
1177 spin_unlock_irqrestore(&sesslock
, flags
);
1179 /* make sure there are no blocks/unblocks queued */
1180 flush_workqueue(iscsi_eh_timer_workq
);
1181 /* make sure the timedout callout is not running */
1182 if (!cancel_delayed_work(&session
->recovery_work
))
1183 flush_workqueue(iscsi_eh_timer_workq
);
1185 * If we are blocked let commands flow again. The lld or iscsi
1186 * layer should set up the queuecommand to fail commands.
1187 * We assume that LLD will not be calling block/unblock while
1188 * removing the session.
1190 spin_lock_irqsave(&session
->lock
, flags
);
1191 session
->state
= ISCSI_SESSION_FREE
;
1192 spin_unlock_irqrestore(&session
->lock
, flags
);
1194 scsi_target_unblock(&session
->dev
);
1195 /* flush running scans then delete devices */
1196 scsi_flush_work(shost
);
1197 __iscsi_unbind_session(&session
->unbind_work
);
1199 /* hw iscsi may not have removed all connections from session */
1200 err
= device_for_each_child(&session
->dev
, NULL
,
1201 iscsi_iter_destroy_conn_fn
);
1203 iscsi_cls_session_printk(KERN_ERR
, session
,
1204 "Could not delete all connections "
1205 "for session. Error %d.\n", err
);
1207 transport_unregister_device(&session
->dev
);
1209 ISCSI_DBG_TRANS_SESSION(session
, "Completing session removal\n");
1210 device_del(&session
->dev
);
1212 EXPORT_SYMBOL_GPL(iscsi_remove_session
);
1214 void iscsi_free_session(struct iscsi_cls_session
*session
)
1216 ISCSI_DBG_TRANS_SESSION(session
, "Freeing session\n");
1217 iscsi_session_event(session
, ISCSI_KEVENT_DESTROY_SESSION
);
1218 put_device(&session
->dev
);
1220 EXPORT_SYMBOL_GPL(iscsi_free_session
);
1223 * iscsi_destroy_session - destroy iscsi session
1224 * @session: iscsi_session
1226 * Can be called by a LLD or iscsi_transport. There must not be
1227 * any running connections.
1229 int iscsi_destroy_session(struct iscsi_cls_session
*session
)
1231 iscsi_remove_session(session
);
1232 ISCSI_DBG_TRANS_SESSION(session
, "Completing session destruction\n");
1233 iscsi_free_session(session
);
1236 EXPORT_SYMBOL_GPL(iscsi_destroy_session
);
1239 * iscsi_create_conn - create iscsi class connection
1240 * @session: iscsi cls session
1241 * @dd_size: private driver data size
1242 * @cid: connection id
1244 * This can be called from a LLD or iscsi_transport. The connection
1245 * is child of the session so cid must be unique for all connections
1248 * Since we do not support MCS, cid will normally be zero. In some cases
1249 * for software iscsi we could be trying to preallocate a connection struct
1250 * in which case there could be two connection structs and cid would be
1253 struct iscsi_cls_conn
*
1254 iscsi_create_conn(struct iscsi_cls_session
*session
, int dd_size
, uint32_t cid
)
1256 struct iscsi_transport
*transport
= session
->transport
;
1257 struct iscsi_cls_conn
*conn
;
1258 unsigned long flags
;
1261 conn
= kzalloc(sizeof(*conn
) + dd_size
, GFP_KERNEL
);
1265 conn
->dd_data
= &conn
[1];
1267 mutex_init(&conn
->ep_mutex
);
1268 INIT_LIST_HEAD(&conn
->conn_list
);
1269 conn
->transport
= transport
;
1272 /* this is released in the dev's release function */
1273 if (!get_device(&session
->dev
))
1276 dev_set_name(&conn
->dev
, "connection%d:%u", session
->sid
, cid
);
1277 conn
->dev
.parent
= &session
->dev
;
1278 conn
->dev
.release
= iscsi_conn_release
;
1279 err
= device_register(&conn
->dev
);
1281 iscsi_cls_session_printk(KERN_ERR
, session
, "could not "
1282 "register connection's dev\n");
1283 goto release_parent_ref
;
1285 transport_register_device(&conn
->dev
);
1287 spin_lock_irqsave(&connlock
, flags
);
1288 list_add(&conn
->conn_list
, &connlist
);
1289 spin_unlock_irqrestore(&connlock
, flags
);
1291 ISCSI_DBG_TRANS_CONN(conn
, "Completed conn creation\n");
1295 put_device(&session
->dev
);
1301 EXPORT_SYMBOL_GPL(iscsi_create_conn
);
1304 * iscsi_destroy_conn - destroy iscsi class connection
1305 * @conn: iscsi cls session
1307 * This can be called from a LLD or iscsi_transport.
1309 int iscsi_destroy_conn(struct iscsi_cls_conn
*conn
)
1311 unsigned long flags
;
1313 spin_lock_irqsave(&connlock
, flags
);
1314 list_del(&conn
->conn_list
);
1315 spin_unlock_irqrestore(&connlock
, flags
);
1317 transport_unregister_device(&conn
->dev
);
1318 ISCSI_DBG_TRANS_CONN(conn
, "Completing conn destruction\n");
1319 device_unregister(&conn
->dev
);
1322 EXPORT_SYMBOL_GPL(iscsi_destroy_conn
);
1325 * iscsi interface functions
1327 static struct iscsi_internal
*
1328 iscsi_if_transport_lookup(struct iscsi_transport
*tt
)
1330 struct iscsi_internal
*priv
;
1331 unsigned long flags
;
1333 spin_lock_irqsave(&iscsi_transport_lock
, flags
);
1334 list_for_each_entry(priv
, &iscsi_transports
, list
) {
1335 if (tt
== priv
->iscsi_transport
) {
1336 spin_unlock_irqrestore(&iscsi_transport_lock
, flags
);
1340 spin_unlock_irqrestore(&iscsi_transport_lock
, flags
);
1345 iscsi_multicast_skb(struct sk_buff
*skb
, uint32_t group
, gfp_t gfp
)
1347 return nlmsg_multicast(nls
, skb
, 0, group
, gfp
);
1350 int iscsi_recv_pdu(struct iscsi_cls_conn
*conn
, struct iscsi_hdr
*hdr
,
1351 char *data
, uint32_t data_size
)
1353 struct nlmsghdr
*nlh
;
1354 struct sk_buff
*skb
;
1355 struct iscsi_uevent
*ev
;
1357 struct iscsi_internal
*priv
;
1358 int len
= NLMSG_SPACE(sizeof(*ev
) + sizeof(struct iscsi_hdr
) +
1361 priv
= iscsi_if_transport_lookup(conn
->transport
);
1365 skb
= alloc_skb(len
, GFP_ATOMIC
);
1367 iscsi_conn_error_event(conn
, ISCSI_ERR_CONN_FAILED
);
1368 iscsi_cls_conn_printk(KERN_ERR
, conn
, "can not deliver "
1369 "control PDU: OOM\n");
1373 nlh
= __nlmsg_put(skb
, 0, 0, 0, (len
- sizeof(*nlh
)), 0);
1374 ev
= NLMSG_DATA(nlh
);
1375 memset(ev
, 0, sizeof(*ev
));
1376 ev
->transport_handle
= iscsi_handle(conn
->transport
);
1377 ev
->type
= ISCSI_KEVENT_RECV_PDU
;
1378 ev
->r
.recv_req
.cid
= conn
->cid
;
1379 ev
->r
.recv_req
.sid
= iscsi_conn_get_sid(conn
);
1380 pdu
= (char*)ev
+ sizeof(*ev
);
1381 memcpy(pdu
, hdr
, sizeof(struct iscsi_hdr
));
1382 memcpy(pdu
+ sizeof(struct iscsi_hdr
), data
, data_size
);
1384 return iscsi_multicast_skb(skb
, ISCSI_NL_GRP_ISCSID
, GFP_ATOMIC
);
1386 EXPORT_SYMBOL_GPL(iscsi_recv_pdu
);
1388 int iscsi_offload_mesg(struct Scsi_Host
*shost
,
1389 struct iscsi_transport
*transport
, uint32_t type
,
1390 char *data
, uint16_t data_size
)
1392 struct nlmsghdr
*nlh
;
1393 struct sk_buff
*skb
;
1394 struct iscsi_uevent
*ev
;
1395 int len
= NLMSG_SPACE(sizeof(*ev
) + data_size
);
1397 skb
= alloc_skb(len
, GFP_ATOMIC
);
1399 printk(KERN_ERR
"can not deliver iscsi offload message:OOM\n");
1403 nlh
= __nlmsg_put(skb
, 0, 0, 0, (len
- sizeof(*nlh
)), 0);
1404 ev
= NLMSG_DATA(nlh
);
1405 memset(ev
, 0, sizeof(*ev
));
1407 ev
->transport_handle
= iscsi_handle(transport
);
1409 case ISCSI_KEVENT_PATH_REQ
:
1410 ev
->r
.req_path
.host_no
= shost
->host_no
;
1412 case ISCSI_KEVENT_IF_DOWN
:
1413 ev
->r
.notify_if_down
.host_no
= shost
->host_no
;
1417 memcpy((char *)ev
+ sizeof(*ev
), data
, data_size
);
1419 return iscsi_multicast_skb(skb
, ISCSI_NL_GRP_UIP
, GFP_ATOMIC
);
1421 EXPORT_SYMBOL_GPL(iscsi_offload_mesg
);
1423 void iscsi_conn_error_event(struct iscsi_cls_conn
*conn
, enum iscsi_err error
)
1425 struct nlmsghdr
*nlh
;
1426 struct sk_buff
*skb
;
1427 struct iscsi_uevent
*ev
;
1428 struct iscsi_internal
*priv
;
1429 int len
= NLMSG_SPACE(sizeof(*ev
));
1431 priv
= iscsi_if_transport_lookup(conn
->transport
);
1435 skb
= alloc_skb(len
, GFP_ATOMIC
);
1437 iscsi_cls_conn_printk(KERN_ERR
, conn
, "gracefully ignored "
1438 "conn error (%d)\n", error
);
1442 nlh
= __nlmsg_put(skb
, 0, 0, 0, (len
- sizeof(*nlh
)), 0);
1443 ev
= NLMSG_DATA(nlh
);
1444 ev
->transport_handle
= iscsi_handle(conn
->transport
);
1445 ev
->type
= ISCSI_KEVENT_CONN_ERROR
;
1446 ev
->r
.connerror
.error
= error
;
1447 ev
->r
.connerror
.cid
= conn
->cid
;
1448 ev
->r
.connerror
.sid
= iscsi_conn_get_sid(conn
);
1450 iscsi_multicast_skb(skb
, ISCSI_NL_GRP_ISCSID
, GFP_ATOMIC
);
1452 iscsi_cls_conn_printk(KERN_INFO
, conn
, "detected conn error (%d)\n",
1455 EXPORT_SYMBOL_GPL(iscsi_conn_error_event
);
1457 void iscsi_conn_login_event(struct iscsi_cls_conn
*conn
,
1458 enum iscsi_conn_state state
)
1460 struct nlmsghdr
*nlh
;
1461 struct sk_buff
*skb
;
1462 struct iscsi_uevent
*ev
;
1463 struct iscsi_internal
*priv
;
1464 int len
= NLMSG_SPACE(sizeof(*ev
));
1466 priv
= iscsi_if_transport_lookup(conn
->transport
);
1470 skb
= alloc_skb(len
, GFP_ATOMIC
);
1472 iscsi_cls_conn_printk(KERN_ERR
, conn
, "gracefully ignored "
1473 "conn login (%d)\n", state
);
1477 nlh
= __nlmsg_put(skb
, 0, 0, 0, (len
- sizeof(*nlh
)), 0);
1478 ev
= NLMSG_DATA(nlh
);
1479 ev
->transport_handle
= iscsi_handle(conn
->transport
);
1480 ev
->type
= ISCSI_KEVENT_CONN_LOGIN_STATE
;
1481 ev
->r
.conn_login
.state
= state
;
1482 ev
->r
.conn_login
.cid
= conn
->cid
;
1483 ev
->r
.conn_login
.sid
= iscsi_conn_get_sid(conn
);
1484 iscsi_multicast_skb(skb
, ISCSI_NL_GRP_ISCSID
, GFP_ATOMIC
);
1486 iscsi_cls_conn_printk(KERN_INFO
, conn
, "detected conn login (%d)\n",
1489 EXPORT_SYMBOL_GPL(iscsi_conn_login_event
);
1492 iscsi_if_send_reply(uint32_t group
, int seq
, int type
, int done
, int multi
,
1493 void *payload
, int size
)
1495 struct sk_buff
*skb
;
1496 struct nlmsghdr
*nlh
;
1497 int len
= NLMSG_SPACE(size
);
1498 int flags
= multi
? NLM_F_MULTI
: 0;
1499 int t
= done
? NLMSG_DONE
: type
;
1501 skb
= alloc_skb(len
, GFP_ATOMIC
);
1503 printk(KERN_ERR
"Could not allocate skb to send reply.\n");
1507 nlh
= __nlmsg_put(skb
, 0, 0, t
, (len
- sizeof(*nlh
)), 0);
1508 nlh
->nlmsg_flags
= flags
;
1509 memcpy(NLMSG_DATA(nlh
), payload
, size
);
1510 return iscsi_multicast_skb(skb
, group
, GFP_ATOMIC
);
1514 iscsi_if_get_stats(struct iscsi_transport
*transport
, struct nlmsghdr
*nlh
)
1516 struct iscsi_uevent
*ev
= NLMSG_DATA(nlh
);
1517 struct iscsi_stats
*stats
;
1518 struct sk_buff
*skbstat
;
1519 struct iscsi_cls_conn
*conn
;
1520 struct nlmsghdr
*nlhstat
;
1521 struct iscsi_uevent
*evstat
;
1522 struct iscsi_internal
*priv
;
1523 int len
= NLMSG_SPACE(sizeof(*ev
) +
1524 sizeof(struct iscsi_stats
) +
1525 sizeof(struct iscsi_stats_custom
) *
1526 ISCSI_STATS_CUSTOM_MAX
);
1529 priv
= iscsi_if_transport_lookup(transport
);
1533 conn
= iscsi_conn_lookup(ev
->u
.get_stats
.sid
, ev
->u
.get_stats
.cid
);
1540 skbstat
= alloc_skb(len
, GFP_ATOMIC
);
1542 iscsi_cls_conn_printk(KERN_ERR
, conn
, "can not "
1543 "deliver stats: OOM\n");
1547 nlhstat
= __nlmsg_put(skbstat
, 0, 0, 0,
1548 (len
- sizeof(*nlhstat
)), 0);
1549 evstat
= NLMSG_DATA(nlhstat
);
1550 memset(evstat
, 0, sizeof(*evstat
));
1551 evstat
->transport_handle
= iscsi_handle(conn
->transport
);
1552 evstat
->type
= nlh
->nlmsg_type
;
1553 evstat
->u
.get_stats
.cid
=
1554 ev
->u
.get_stats
.cid
;
1555 evstat
->u
.get_stats
.sid
=
1556 ev
->u
.get_stats
.sid
;
1557 stats
= (struct iscsi_stats
*)
1558 ((char*)evstat
+ sizeof(*evstat
));
1559 memset(stats
, 0, sizeof(*stats
));
1561 transport
->get_stats(conn
, stats
);
1562 actual_size
= NLMSG_SPACE(sizeof(struct iscsi_uevent
) +
1563 sizeof(struct iscsi_stats
) +
1564 sizeof(struct iscsi_stats_custom
) *
1565 stats
->custom_length
);
1566 actual_size
-= sizeof(*nlhstat
);
1567 actual_size
= NLMSG_LENGTH(actual_size
);
1568 skb_trim(skbstat
, NLMSG_ALIGN(actual_size
));
1569 nlhstat
->nlmsg_len
= actual_size
;
1571 err
= iscsi_multicast_skb(skbstat
, ISCSI_NL_GRP_ISCSID
,
1573 } while (err
< 0 && err
!= -ECONNREFUSED
);
1579 * iscsi_session_event - send session destr. completion event
1580 * @session: iscsi class session
1581 * @event: type of event
1583 int iscsi_session_event(struct iscsi_cls_session
*session
,
1584 enum iscsi_uevent_e event
)
1586 struct iscsi_internal
*priv
;
1587 struct Scsi_Host
*shost
;
1588 struct iscsi_uevent
*ev
;
1589 struct sk_buff
*skb
;
1590 struct nlmsghdr
*nlh
;
1591 int rc
, len
= NLMSG_SPACE(sizeof(*ev
));
1593 priv
= iscsi_if_transport_lookup(session
->transport
);
1596 shost
= iscsi_session_to_shost(session
);
1598 skb
= alloc_skb(len
, GFP_KERNEL
);
1600 iscsi_cls_session_printk(KERN_ERR
, session
,
1601 "Cannot notify userspace of session "
1602 "event %u\n", event
);
1606 nlh
= __nlmsg_put(skb
, 0, 0, 0, (len
- sizeof(*nlh
)), 0);
1607 ev
= NLMSG_DATA(nlh
);
1608 ev
->transport_handle
= iscsi_handle(session
->transport
);
1612 case ISCSI_KEVENT_DESTROY_SESSION
:
1613 ev
->r
.d_session
.host_no
= shost
->host_no
;
1614 ev
->r
.d_session
.sid
= session
->sid
;
1616 case ISCSI_KEVENT_CREATE_SESSION
:
1617 ev
->r
.c_session_ret
.host_no
= shost
->host_no
;
1618 ev
->r
.c_session_ret
.sid
= session
->sid
;
1620 case ISCSI_KEVENT_UNBIND_SESSION
:
1621 ev
->r
.unbind_session
.host_no
= shost
->host_no
;
1622 ev
->r
.unbind_session
.sid
= session
->sid
;
1625 iscsi_cls_session_printk(KERN_ERR
, session
, "Invalid event "
1632 * this will occur if the daemon is not up, so we just warn
1633 * the user and when the daemon is restarted it will handle it
1635 rc
= iscsi_multicast_skb(skb
, ISCSI_NL_GRP_ISCSID
, GFP_KERNEL
);
1637 iscsi_cls_session_printk(KERN_ERR
, session
,
1638 "Cannot notify userspace of session "
1639 "event %u. Check iscsi daemon\n",
1642 ISCSI_DBG_TRANS_SESSION(session
, "Completed handling event %d rc %d\n",
1646 EXPORT_SYMBOL_GPL(iscsi_session_event
);
1649 iscsi_if_create_session(struct iscsi_internal
*priv
, struct iscsi_endpoint
*ep
,
1650 struct iscsi_uevent
*ev
, uint32_t initial_cmdsn
,
1651 uint16_t cmds_max
, uint16_t queue_depth
)
1653 struct iscsi_transport
*transport
= priv
->iscsi_transport
;
1654 struct iscsi_cls_session
*session
;
1655 struct Scsi_Host
*shost
;
1657 session
= transport
->create_session(ep
, cmds_max
, queue_depth
,
1662 shost
= iscsi_session_to_shost(session
);
1663 ev
->r
.c_session_ret
.host_no
= shost
->host_no
;
1664 ev
->r
.c_session_ret
.sid
= session
->sid
;
1665 ISCSI_DBG_TRANS_SESSION(session
,
1666 "Completed creating transport session\n");
1671 iscsi_if_create_conn(struct iscsi_transport
*transport
, struct iscsi_uevent
*ev
)
1673 struct iscsi_cls_conn
*conn
;
1674 struct iscsi_cls_session
*session
;
1676 session
= iscsi_session_lookup(ev
->u
.c_conn
.sid
);
1678 printk(KERN_ERR
"iscsi: invalid session %d.\n",
1683 conn
= transport
->create_conn(session
, ev
->u
.c_conn
.cid
);
1685 iscsi_cls_session_printk(KERN_ERR
, session
,
1686 "couldn't create a new connection.");
1690 ev
->r
.c_conn_ret
.sid
= session
->sid
;
1691 ev
->r
.c_conn_ret
.cid
= conn
->cid
;
1693 ISCSI_DBG_TRANS_CONN(conn
, "Completed creating transport conn\n");
1698 iscsi_if_destroy_conn(struct iscsi_transport
*transport
, struct iscsi_uevent
*ev
)
1700 struct iscsi_cls_conn
*conn
;
1702 conn
= iscsi_conn_lookup(ev
->u
.d_conn
.sid
, ev
->u
.d_conn
.cid
);
1706 ISCSI_DBG_TRANS_CONN(conn
, "Destroying transport conn\n");
1707 if (transport
->destroy_conn
)
1708 transport
->destroy_conn(conn
);
1714 iscsi_set_param(struct iscsi_transport
*transport
, struct iscsi_uevent
*ev
)
1716 char *data
= (char*)ev
+ sizeof(*ev
);
1717 struct iscsi_cls_conn
*conn
;
1718 struct iscsi_cls_session
*session
;
1719 int err
= 0, value
= 0;
1721 session
= iscsi_session_lookup(ev
->u
.set_param
.sid
);
1722 conn
= iscsi_conn_lookup(ev
->u
.set_param
.sid
, ev
->u
.set_param
.cid
);
1723 if (!conn
|| !session
)
1726 switch (ev
->u
.set_param
.param
) {
1727 case ISCSI_PARAM_SESS_RECOVERY_TMO
:
1728 sscanf(data
, "%d", &value
);
1729 session
->recovery_tmo
= value
;
1732 err
= transport
->set_param(conn
, ev
->u
.set_param
.param
,
1733 data
, ev
->u
.set_param
.len
);
1739 static int iscsi_if_ep_connect(struct iscsi_transport
*transport
,
1740 struct iscsi_uevent
*ev
, int msg_type
)
1742 struct iscsi_endpoint
*ep
;
1743 struct sockaddr
*dst_addr
;
1744 struct Scsi_Host
*shost
= NULL
;
1745 int non_blocking
, err
= 0;
1747 if (!transport
->ep_connect
)
1750 if (msg_type
== ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST
) {
1751 shost
= scsi_host_lookup(ev
->u
.ep_connect_through_host
.host_no
);
1753 printk(KERN_ERR
"ep connect failed. Could not find "
1755 ev
->u
.ep_connect_through_host
.host_no
);
1758 non_blocking
= ev
->u
.ep_connect_through_host
.non_blocking
;
1760 non_blocking
= ev
->u
.ep_connect
.non_blocking
;
1762 dst_addr
= (struct sockaddr
*)((char*)ev
+ sizeof(*ev
));
1763 ep
= transport
->ep_connect(shost
, dst_addr
, non_blocking
);
1769 ev
->r
.ep_connect_ret
.handle
= ep
->id
;
1772 scsi_host_put(shost
);
1776 static int iscsi_if_ep_disconnect(struct iscsi_transport
*transport
,
1779 struct iscsi_cls_conn
*conn
;
1780 struct iscsi_endpoint
*ep
;
1782 if (!transport
->ep_disconnect
)
1785 ep
= iscsi_lookup_endpoint(ep_handle
);
1790 mutex_lock(&conn
->ep_mutex
);
1792 mutex_unlock(&conn
->ep_mutex
);
1795 transport
->ep_disconnect(ep
);
1800 iscsi_if_transport_ep(struct iscsi_transport
*transport
,
1801 struct iscsi_uevent
*ev
, int msg_type
)
1803 struct iscsi_endpoint
*ep
;
1807 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST
:
1808 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT
:
1809 rc
= iscsi_if_ep_connect(transport
, ev
, msg_type
);
1811 case ISCSI_UEVENT_TRANSPORT_EP_POLL
:
1812 if (!transport
->ep_poll
)
1815 ep
= iscsi_lookup_endpoint(ev
->u
.ep_poll
.ep_handle
);
1819 ev
->r
.retcode
= transport
->ep_poll(ep
,
1820 ev
->u
.ep_poll
.timeout_ms
);
1822 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT
:
1823 rc
= iscsi_if_ep_disconnect(transport
,
1824 ev
->u
.ep_disconnect
.ep_handle
);
1831 iscsi_tgt_dscvr(struct iscsi_transport
*transport
,
1832 struct iscsi_uevent
*ev
)
1834 struct Scsi_Host
*shost
;
1835 struct sockaddr
*dst_addr
;
1838 if (!transport
->tgt_dscvr
)
1841 shost
= scsi_host_lookup(ev
->u
.tgt_dscvr
.host_no
);
1843 printk(KERN_ERR
"target discovery could not find host no %u\n",
1844 ev
->u
.tgt_dscvr
.host_no
);
1849 dst_addr
= (struct sockaddr
*)((char*)ev
+ sizeof(*ev
));
1850 err
= transport
->tgt_dscvr(shost
, ev
->u
.tgt_dscvr
.type
,
1851 ev
->u
.tgt_dscvr
.enable
, dst_addr
);
1852 scsi_host_put(shost
);
1857 iscsi_set_host_param(struct iscsi_transport
*transport
,
1858 struct iscsi_uevent
*ev
)
1860 char *data
= (char*)ev
+ sizeof(*ev
);
1861 struct Scsi_Host
*shost
;
1864 if (!transport
->set_host_param
)
1867 shost
= scsi_host_lookup(ev
->u
.set_host_param
.host_no
);
1869 printk(KERN_ERR
"set_host_param could not find host no %u\n",
1870 ev
->u
.set_host_param
.host_no
);
1874 err
= transport
->set_host_param(shost
, ev
->u
.set_host_param
.param
,
1875 data
, ev
->u
.set_host_param
.len
);
1876 scsi_host_put(shost
);
1881 iscsi_set_path(struct iscsi_transport
*transport
, struct iscsi_uevent
*ev
)
1883 struct Scsi_Host
*shost
;
1884 struct iscsi_path
*params
;
1887 if (!transport
->set_path
)
1890 shost
= scsi_host_lookup(ev
->u
.set_path
.host_no
);
1892 printk(KERN_ERR
"set path could not find host no %u\n",
1893 ev
->u
.set_path
.host_no
);
1897 params
= (struct iscsi_path
*)((char *)ev
+ sizeof(*ev
));
1898 err
= transport
->set_path(shost
, params
);
1900 scsi_host_put(shost
);
1905 iscsi_set_iface_params(struct iscsi_transport
*transport
,
1906 struct iscsi_uevent
*ev
)
1908 char *data
= (char *)ev
+ sizeof(*ev
);
1909 struct Scsi_Host
*shost
;
1912 if (!transport
->set_iface_param
)
1915 shost
= scsi_host_lookup(ev
->u
.set_iface_params
.host_no
);
1917 printk(KERN_ERR
"set_iface_params could not find host no %u\n",
1918 ev
->u
.set_iface_params
.host_no
);
1922 err
= transport
->set_iface_param(shost
, data
,
1923 ev
->u
.set_iface_params
.count
);
1924 scsi_host_put(shost
);
1929 iscsi_if_recv_msg(struct sk_buff
*skb
, struct nlmsghdr
*nlh
, uint32_t *group
)
1932 struct iscsi_uevent
*ev
= NLMSG_DATA(nlh
);
1933 struct iscsi_transport
*transport
= NULL
;
1934 struct iscsi_internal
*priv
;
1935 struct iscsi_cls_session
*session
;
1936 struct iscsi_cls_conn
*conn
;
1937 struct iscsi_endpoint
*ep
= NULL
;
1939 if (nlh
->nlmsg_type
== ISCSI_UEVENT_PATH_UPDATE
)
1940 *group
= ISCSI_NL_GRP_UIP
;
1942 *group
= ISCSI_NL_GRP_ISCSID
;
1944 priv
= iscsi_if_transport_lookup(iscsi_ptr(ev
->transport_handle
));
1947 transport
= priv
->iscsi_transport
;
1949 if (!try_module_get(transport
->owner
))
1952 switch (nlh
->nlmsg_type
) {
1953 case ISCSI_UEVENT_CREATE_SESSION
:
1954 err
= iscsi_if_create_session(priv
, ep
, ev
,
1955 ev
->u
.c_session
.initial_cmdsn
,
1956 ev
->u
.c_session
.cmds_max
,
1957 ev
->u
.c_session
.queue_depth
);
1959 case ISCSI_UEVENT_CREATE_BOUND_SESSION
:
1960 ep
= iscsi_lookup_endpoint(ev
->u
.c_bound_session
.ep_handle
);
1966 err
= iscsi_if_create_session(priv
, ep
, ev
,
1967 ev
->u
.c_bound_session
.initial_cmdsn
,
1968 ev
->u
.c_bound_session
.cmds_max
,
1969 ev
->u
.c_bound_session
.queue_depth
);
1971 case ISCSI_UEVENT_DESTROY_SESSION
:
1972 session
= iscsi_session_lookup(ev
->u
.d_session
.sid
);
1974 transport
->destroy_session(session
);
1978 case ISCSI_UEVENT_UNBIND_SESSION
:
1979 session
= iscsi_session_lookup(ev
->u
.d_session
.sid
);
1981 scsi_queue_work(iscsi_session_to_shost(session
),
1982 &session
->unbind_work
);
1986 case ISCSI_UEVENT_CREATE_CONN
:
1987 err
= iscsi_if_create_conn(transport
, ev
);
1989 case ISCSI_UEVENT_DESTROY_CONN
:
1990 err
= iscsi_if_destroy_conn(transport
, ev
);
1992 case ISCSI_UEVENT_BIND_CONN
:
1993 session
= iscsi_session_lookup(ev
->u
.b_conn
.sid
);
1994 conn
= iscsi_conn_lookup(ev
->u
.b_conn
.sid
, ev
->u
.b_conn
.cid
);
1996 if (conn
&& conn
->ep
)
1997 iscsi_if_ep_disconnect(transport
, conn
->ep
->id
);
1999 if (!session
|| !conn
) {
2004 ev
->r
.retcode
= transport
->bind_conn(session
, conn
,
2005 ev
->u
.b_conn
.transport_eph
,
2006 ev
->u
.b_conn
.is_leading
);
2007 if (ev
->r
.retcode
|| !transport
->ep_connect
)
2010 ep
= iscsi_lookup_endpoint(ev
->u
.b_conn
.transport_eph
);
2014 mutex_lock(&conn
->ep_mutex
);
2016 mutex_unlock(&conn
->ep_mutex
);
2018 iscsi_cls_conn_printk(KERN_ERR
, conn
,
2019 "Could not set ep conn "
2022 case ISCSI_UEVENT_SET_PARAM
:
2023 err
= iscsi_set_param(transport
, ev
);
2025 case ISCSI_UEVENT_START_CONN
:
2026 conn
= iscsi_conn_lookup(ev
->u
.start_conn
.sid
, ev
->u
.start_conn
.cid
);
2028 ev
->r
.retcode
= transport
->start_conn(conn
);
2032 case ISCSI_UEVENT_STOP_CONN
:
2033 conn
= iscsi_conn_lookup(ev
->u
.stop_conn
.sid
, ev
->u
.stop_conn
.cid
);
2035 transport
->stop_conn(conn
, ev
->u
.stop_conn
.flag
);
2039 case ISCSI_UEVENT_SEND_PDU
:
2040 conn
= iscsi_conn_lookup(ev
->u
.send_pdu
.sid
, ev
->u
.send_pdu
.cid
);
2042 ev
->r
.retcode
= transport
->send_pdu(conn
,
2043 (struct iscsi_hdr
*)((char*)ev
+ sizeof(*ev
)),
2044 (char*)ev
+ sizeof(*ev
) + ev
->u
.send_pdu
.hdr_size
,
2045 ev
->u
.send_pdu
.data_size
);
2049 case ISCSI_UEVENT_GET_STATS
:
2050 err
= iscsi_if_get_stats(transport
, nlh
);
2052 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT
:
2053 case ISCSI_UEVENT_TRANSPORT_EP_POLL
:
2054 case ISCSI_UEVENT_TRANSPORT_EP_DISCONNECT
:
2055 case ISCSI_UEVENT_TRANSPORT_EP_CONNECT_THROUGH_HOST
:
2056 err
= iscsi_if_transport_ep(transport
, ev
, nlh
->nlmsg_type
);
2058 case ISCSI_UEVENT_TGT_DSCVR
:
2059 err
= iscsi_tgt_dscvr(transport
, ev
);
2061 case ISCSI_UEVENT_SET_HOST_PARAM
:
2062 err
= iscsi_set_host_param(transport
, ev
);
2064 case ISCSI_UEVENT_PATH_UPDATE
:
2065 err
= iscsi_set_path(transport
, ev
);
2067 case ISCSI_UEVENT_SET_IFACE_PARAMS
:
2068 err
= iscsi_set_iface_params(transport
, ev
);
2075 module_put(transport
->owner
);
2080 * Get message from skb. Each message is processed by iscsi_if_recv_msg.
2081 * Malformed skbs with wrong lengths or invalid creds are not processed.
2084 iscsi_if_rx(struct sk_buff
*skb
)
2086 mutex_lock(&rx_queue_mutex
);
2087 while (skb
->len
>= NLMSG_SPACE(0)) {
2090 struct nlmsghdr
*nlh
;
2091 struct iscsi_uevent
*ev
;
2094 nlh
= nlmsg_hdr(skb
);
2095 if (nlh
->nlmsg_len
< sizeof(*nlh
) ||
2096 skb
->len
< nlh
->nlmsg_len
) {
2100 ev
= NLMSG_DATA(nlh
);
2101 rlen
= NLMSG_ALIGN(nlh
->nlmsg_len
);
2102 if (rlen
> skb
->len
)
2105 err
= iscsi_if_recv_msg(skb
, nlh
, &group
);
2107 ev
->type
= ISCSI_KEVENT_IF_ERROR
;
2112 * special case for GET_STATS:
2113 * on success - sending reply and stats from
2114 * inside of if_recv_msg(),
2115 * on error - fall through.
2117 if (ev
->type
== ISCSI_UEVENT_GET_STATS
&& !err
)
2119 err
= iscsi_if_send_reply(group
, nlh
->nlmsg_seq
,
2120 nlh
->nlmsg_type
, 0, 0, ev
, sizeof(*ev
));
2121 } while (err
< 0 && err
!= -ECONNREFUSED
);
2122 skb_pull(skb
, rlen
);
2124 mutex_unlock(&rx_queue_mutex
);
2127 #define ISCSI_CLASS_ATTR(_prefix,_name,_mode,_show,_store) \
2128 struct device_attribute dev_attr_##_prefix##_##_name = \
2129 __ATTR(_name,_mode,_show,_store)
2132 * iSCSI connection attrs
2134 #define iscsi_conn_attr_show(param) \
2136 show_conn_param_##param(struct device *dev, \
2137 struct device_attribute *attr, char *buf) \
2139 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
2140 struct iscsi_transport *t = conn->transport; \
2141 return t->get_conn_param(conn, param, buf); \
2144 #define iscsi_conn_attr(field, param) \
2145 iscsi_conn_attr_show(param) \
2146 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, show_conn_param_##param, \
2149 iscsi_conn_attr(max_recv_dlength
, ISCSI_PARAM_MAX_RECV_DLENGTH
);
2150 iscsi_conn_attr(max_xmit_dlength
, ISCSI_PARAM_MAX_XMIT_DLENGTH
);
2151 iscsi_conn_attr(header_digest
, ISCSI_PARAM_HDRDGST_EN
);
2152 iscsi_conn_attr(data_digest
, ISCSI_PARAM_DATADGST_EN
);
2153 iscsi_conn_attr(ifmarker
, ISCSI_PARAM_IFMARKER_EN
);
2154 iscsi_conn_attr(ofmarker
, ISCSI_PARAM_OFMARKER_EN
);
2155 iscsi_conn_attr(persistent_port
, ISCSI_PARAM_PERSISTENT_PORT
);
2156 iscsi_conn_attr(exp_statsn
, ISCSI_PARAM_EXP_STATSN
);
2157 iscsi_conn_attr(persistent_address
, ISCSI_PARAM_PERSISTENT_ADDRESS
);
2158 iscsi_conn_attr(ping_tmo
, ISCSI_PARAM_PING_TMO
);
2159 iscsi_conn_attr(recv_tmo
, ISCSI_PARAM_RECV_TMO
);
2161 #define iscsi_conn_ep_attr_show(param) \
2162 static ssize_t show_conn_ep_param_##param(struct device *dev, \
2163 struct device_attribute *attr,\
2166 struct iscsi_cls_conn *conn = iscsi_dev_to_conn(dev->parent); \
2167 struct iscsi_transport *t = conn->transport; \
2168 struct iscsi_endpoint *ep; \
2172 * Need to make sure ep_disconnect does not free the LLD's \
2173 * interconnect resources while we are trying to read them. \
2175 mutex_lock(&conn->ep_mutex); \
2177 if (!ep && t->ep_connect) { \
2178 mutex_unlock(&conn->ep_mutex); \
2183 rc = t->get_ep_param(ep, param, buf); \
2185 rc = t->get_conn_param(conn, param, buf); \
2186 mutex_unlock(&conn->ep_mutex); \
2190 #define iscsi_conn_ep_attr(field, param) \
2191 iscsi_conn_ep_attr_show(param) \
2192 static ISCSI_CLASS_ATTR(conn, field, S_IRUGO, \
2193 show_conn_ep_param_##param, NULL);
2195 iscsi_conn_ep_attr(address
, ISCSI_PARAM_CONN_ADDRESS
);
2196 iscsi_conn_ep_attr(port
, ISCSI_PARAM_CONN_PORT
);
2198 static struct attribute
*iscsi_conn_attrs
[] = {
2199 &dev_attr_conn_max_recv_dlength
.attr
,
2200 &dev_attr_conn_max_xmit_dlength
.attr
,
2201 &dev_attr_conn_header_digest
.attr
,
2202 &dev_attr_conn_data_digest
.attr
,
2203 &dev_attr_conn_ifmarker
.attr
,
2204 &dev_attr_conn_ofmarker
.attr
,
2205 &dev_attr_conn_address
.attr
,
2206 &dev_attr_conn_port
.attr
,
2207 &dev_attr_conn_exp_statsn
.attr
,
2208 &dev_attr_conn_persistent_address
.attr
,
2209 &dev_attr_conn_persistent_port
.attr
,
2210 &dev_attr_conn_ping_tmo
.attr
,
2211 &dev_attr_conn_recv_tmo
.attr
,
2215 static mode_t
iscsi_conn_attr_is_visible(struct kobject
*kobj
,
2216 struct attribute
*attr
, int i
)
2218 struct device
*cdev
= container_of(kobj
, struct device
, kobj
);
2219 struct iscsi_cls_conn
*conn
= transport_class_to_conn(cdev
);
2220 struct iscsi_transport
*t
= conn
->transport
;
2223 if (attr
== &dev_attr_conn_max_recv_dlength
.attr
)
2224 param
= ISCSI_PARAM_MAX_RECV_DLENGTH
;
2225 else if (attr
== &dev_attr_conn_max_xmit_dlength
.attr
)
2226 param
= ISCSI_PARAM_MAX_XMIT_DLENGTH
;
2227 else if (attr
== &dev_attr_conn_header_digest
.attr
)
2228 param
= ISCSI_PARAM_HDRDGST_EN
;
2229 else if (attr
== &dev_attr_conn_data_digest
.attr
)
2230 param
= ISCSI_PARAM_DATADGST_EN
;
2231 else if (attr
== &dev_attr_conn_ifmarker
.attr
)
2232 param
= ISCSI_PARAM_IFMARKER_EN
;
2233 else if (attr
== &dev_attr_conn_ofmarker
.attr
)
2234 param
= ISCSI_PARAM_OFMARKER_EN
;
2235 else if (attr
== &dev_attr_conn_address
.attr
)
2236 param
= ISCSI_PARAM_CONN_ADDRESS
;
2237 else if (attr
== &dev_attr_conn_port
.attr
)
2238 param
= ISCSI_PARAM_CONN_PORT
;
2239 else if (attr
== &dev_attr_conn_exp_statsn
.attr
)
2240 param
= ISCSI_PARAM_EXP_STATSN
;
2241 else if (attr
== &dev_attr_conn_persistent_address
.attr
)
2242 param
= ISCSI_PARAM_PERSISTENT_ADDRESS
;
2243 else if (attr
== &dev_attr_conn_persistent_port
.attr
)
2244 param
= ISCSI_PARAM_PERSISTENT_PORT
;
2245 else if (attr
== &dev_attr_conn_ping_tmo
.attr
)
2246 param
= ISCSI_PARAM_PING_TMO
;
2247 else if (attr
== &dev_attr_conn_recv_tmo
.attr
)
2248 param
= ISCSI_PARAM_RECV_TMO
;
2250 WARN_ONCE(1, "Invalid conn attr");
2254 return t
->attr_is_visible(ISCSI_PARAM
, param
);
2257 static struct attribute_group iscsi_conn_group
= {
2258 .attrs
= iscsi_conn_attrs
,
2259 .is_visible
= iscsi_conn_attr_is_visible
,
2263 * iSCSI session attrs
2265 #define iscsi_session_attr_show(param, perm) \
2267 show_session_param_##param(struct device *dev, \
2268 struct device_attribute *attr, char *buf) \
2270 struct iscsi_cls_session *session = \
2271 iscsi_dev_to_session(dev->parent); \
2272 struct iscsi_transport *t = session->transport; \
2274 if (perm && !capable(CAP_SYS_ADMIN)) \
2276 return t->get_session_param(session, param, buf); \
2279 #define iscsi_session_attr(field, param, perm) \
2280 iscsi_session_attr_show(param, perm) \
2281 static ISCSI_CLASS_ATTR(sess, field, S_IRUGO, show_session_param_##param, \
2283 iscsi_session_attr(targetname
, ISCSI_PARAM_TARGET_NAME
, 0);
2284 iscsi_session_attr(initial_r2t
, ISCSI_PARAM_INITIAL_R2T_EN
, 0);
2285 iscsi_session_attr(max_outstanding_r2t
, ISCSI_PARAM_MAX_R2T
, 0);
2286 iscsi_session_attr(immediate_data
, ISCSI_PARAM_IMM_DATA_EN
, 0);
2287 iscsi_session_attr(first_burst_len
, ISCSI_PARAM_FIRST_BURST
, 0);
2288 iscsi_session_attr(max_burst_len
, ISCSI_PARAM_MAX_BURST
, 0);
2289 iscsi_session_attr(data_pdu_in_order
, ISCSI_PARAM_PDU_INORDER_EN
, 0);
2290 iscsi_session_attr(data_seq_in_order
, ISCSI_PARAM_DATASEQ_INORDER_EN
, 0);
2291 iscsi_session_attr(erl
, ISCSI_PARAM_ERL
, 0);
2292 iscsi_session_attr(tpgt
, ISCSI_PARAM_TPGT
, 0);
2293 iscsi_session_attr(username
, ISCSI_PARAM_USERNAME
, 1);
2294 iscsi_session_attr(username_in
, ISCSI_PARAM_USERNAME_IN
, 1);
2295 iscsi_session_attr(password
, ISCSI_PARAM_PASSWORD
, 1);
2296 iscsi_session_attr(password_in
, ISCSI_PARAM_PASSWORD_IN
, 1);
2297 iscsi_session_attr(fast_abort
, ISCSI_PARAM_FAST_ABORT
, 0);
2298 iscsi_session_attr(abort_tmo
, ISCSI_PARAM_ABORT_TMO
, 0);
2299 iscsi_session_attr(lu_reset_tmo
, ISCSI_PARAM_LU_RESET_TMO
, 0);
2300 iscsi_session_attr(tgt_reset_tmo
, ISCSI_PARAM_TGT_RESET_TMO
, 0);
2301 iscsi_session_attr(ifacename
, ISCSI_PARAM_IFACE_NAME
, 0);
2302 iscsi_session_attr(initiatorname
, ISCSI_PARAM_INITIATOR_NAME
, 0);
2303 iscsi_session_attr(targetalias
, ISCSI_PARAM_TARGET_ALIAS
, 0);
2306 show_priv_session_state(struct device
*dev
, struct device_attribute
*attr
,
2309 struct iscsi_cls_session
*session
= iscsi_dev_to_session(dev
->parent
);
2310 return sprintf(buf
, "%s\n", iscsi_session_state_name(session
->state
));
2312 static ISCSI_CLASS_ATTR(priv_sess
, state
, S_IRUGO
, show_priv_session_state
,
2315 #define iscsi_priv_session_attr_show(field, format) \
2317 show_priv_session_##field(struct device *dev, \
2318 struct device_attribute *attr, char *buf) \
2320 struct iscsi_cls_session *session = \
2321 iscsi_dev_to_session(dev->parent); \
2322 if (session->field == -1) \
2323 return sprintf(buf, "off\n"); \
2324 return sprintf(buf, format"\n", session->field); \
2327 #define iscsi_priv_session_attr_store(field) \
2329 store_priv_session_##field(struct device *dev, \
2330 struct device_attribute *attr, \
2331 const char *buf, size_t count) \
2335 struct iscsi_cls_session *session = \
2336 iscsi_dev_to_session(dev->parent); \
2337 if ((session->state == ISCSI_SESSION_FREE) || \
2338 (session->state == ISCSI_SESSION_FAILED)) \
2340 if (strncmp(buf, "off", 3) == 0) \
2341 session->field = -1; \
2343 val = simple_strtoul(buf, &cp, 0); \
2344 if (*cp != '\0' && *cp != '\n') \
2346 session->field = val; \
2351 #define iscsi_priv_session_rw_attr(field, format) \
2352 iscsi_priv_session_attr_show(field, format) \
2353 iscsi_priv_session_attr_store(field) \
2354 static ISCSI_CLASS_ATTR(priv_sess, field, S_IRUGO | S_IWUSR, \
2355 show_priv_session_##field, \
2356 store_priv_session_##field)
2357 iscsi_priv_session_rw_attr(recovery_tmo
, "%d");
2359 static struct attribute
*iscsi_session_attrs
[] = {
2360 &dev_attr_sess_initial_r2t
.attr
,
2361 &dev_attr_sess_max_outstanding_r2t
.attr
,
2362 &dev_attr_sess_immediate_data
.attr
,
2363 &dev_attr_sess_first_burst_len
.attr
,
2364 &dev_attr_sess_max_burst_len
.attr
,
2365 &dev_attr_sess_data_pdu_in_order
.attr
,
2366 &dev_attr_sess_data_seq_in_order
.attr
,
2367 &dev_attr_sess_erl
.attr
,
2368 &dev_attr_sess_targetname
.attr
,
2369 &dev_attr_sess_tpgt
.attr
,
2370 &dev_attr_sess_password
.attr
,
2371 &dev_attr_sess_password_in
.attr
,
2372 &dev_attr_sess_username
.attr
,
2373 &dev_attr_sess_username_in
.attr
,
2374 &dev_attr_sess_fast_abort
.attr
,
2375 &dev_attr_sess_abort_tmo
.attr
,
2376 &dev_attr_sess_lu_reset_tmo
.attr
,
2377 &dev_attr_sess_tgt_reset_tmo
.attr
,
2378 &dev_attr_sess_ifacename
.attr
,
2379 &dev_attr_sess_initiatorname
.attr
,
2380 &dev_attr_sess_targetalias
.attr
,
2381 &dev_attr_priv_sess_recovery_tmo
.attr
,
2382 &dev_attr_priv_sess_state
.attr
,
2386 static mode_t
iscsi_session_attr_is_visible(struct kobject
*kobj
,
2387 struct attribute
*attr
, int i
)
2389 struct device
*cdev
= container_of(kobj
, struct device
, kobj
);
2390 struct iscsi_cls_session
*session
= transport_class_to_session(cdev
);
2391 struct iscsi_transport
*t
= session
->transport
;
2394 if (attr
== &dev_attr_sess_initial_r2t
.attr
)
2395 param
= ISCSI_PARAM_INITIAL_R2T_EN
;
2396 else if (attr
== &dev_attr_sess_max_outstanding_r2t
.attr
)
2397 param
= ISCSI_PARAM_MAX_R2T
;
2398 else if (attr
== &dev_attr_sess_immediate_data
.attr
)
2399 param
= ISCSI_PARAM_IMM_DATA_EN
;
2400 else if (attr
== &dev_attr_sess_first_burst_len
.attr
)
2401 param
= ISCSI_PARAM_FIRST_BURST
;
2402 else if (attr
== &dev_attr_sess_max_burst_len
.attr
)
2403 param
= ISCSI_PARAM_MAX_BURST
;
2404 else if (attr
== &dev_attr_sess_data_pdu_in_order
.attr
)
2405 param
= ISCSI_PARAM_PDU_INORDER_EN
;
2406 else if (attr
== &dev_attr_sess_data_seq_in_order
.attr
)
2407 param
= ISCSI_PARAM_DATASEQ_INORDER_EN
;
2408 else if (attr
== &dev_attr_sess_erl
.attr
)
2409 param
= ISCSI_PARAM_ERL
;
2410 else if (attr
== &dev_attr_sess_targetname
.attr
)
2411 param
= ISCSI_PARAM_TARGET_NAME
;
2412 else if (attr
== &dev_attr_sess_tpgt
.attr
)
2413 param
= ISCSI_PARAM_TPGT
;
2414 else if (attr
== &dev_attr_sess_password
.attr
)
2415 param
= ISCSI_PARAM_USERNAME
;
2416 else if (attr
== &dev_attr_sess_password_in
.attr
)
2417 param
= ISCSI_PARAM_USERNAME_IN
;
2418 else if (attr
== &dev_attr_sess_username
.attr
)
2419 param
= ISCSI_PARAM_PASSWORD
;
2420 else if (attr
== &dev_attr_sess_username_in
.attr
)
2421 param
= ISCSI_PARAM_PASSWORD_IN
;
2422 else if (attr
== &dev_attr_sess_fast_abort
.attr
)
2423 param
= ISCSI_PARAM_FAST_ABORT
;
2424 else if (attr
== &dev_attr_sess_abort_tmo
.attr
)
2425 param
= ISCSI_PARAM_ABORT_TMO
;
2426 else if (attr
== &dev_attr_sess_lu_reset_tmo
.attr
)
2427 param
= ISCSI_PARAM_LU_RESET_TMO
;
2428 else if (attr
== &dev_attr_sess_tgt_reset_tmo
.attr
)
2429 param
= ISCSI_PARAM_TGT_RESET_TMO
;
2430 else if (attr
== &dev_attr_sess_ifacename
.attr
)
2431 param
= ISCSI_PARAM_IFACE_NAME
;
2432 else if (attr
== &dev_attr_sess_initiatorname
.attr
)
2433 param
= ISCSI_PARAM_INITIATOR_NAME
;
2434 else if (attr
== &dev_attr_sess_targetalias
.attr
)
2435 param
= ISCSI_PARAM_TARGET_ALIAS
;
2436 else if (attr
== &dev_attr_priv_sess_recovery_tmo
.attr
)
2437 return S_IRUGO
| S_IWUSR
;
2438 else if (attr
== &dev_attr_priv_sess_state
.attr
)
2441 WARN_ONCE(1, "Invalid session attr");
2445 return t
->attr_is_visible(ISCSI_PARAM
, param
);
2448 static struct attribute_group iscsi_session_group
= {
2449 .attrs
= iscsi_session_attrs
,
2450 .is_visible
= iscsi_session_attr_is_visible
,
2456 #define iscsi_host_attr_show(param) \
2458 show_host_param_##param(struct device *dev, \
2459 struct device_attribute *attr, char *buf) \
2461 struct Scsi_Host *shost = transport_class_to_shost(dev); \
2462 struct iscsi_internal *priv = to_iscsi_internal(shost->transportt); \
2463 return priv->iscsi_transport->get_host_param(shost, param, buf); \
2466 #define iscsi_host_attr(field, param) \
2467 iscsi_host_attr_show(param) \
2468 static ISCSI_CLASS_ATTR(host, field, S_IRUGO, show_host_param_##param, \
2471 iscsi_host_attr(netdev
, ISCSI_HOST_PARAM_NETDEV_NAME
);
2472 iscsi_host_attr(hwaddress
, ISCSI_HOST_PARAM_HWADDRESS
);
2473 iscsi_host_attr(ipaddress
, ISCSI_HOST_PARAM_IPADDRESS
);
2474 iscsi_host_attr(initiatorname
, ISCSI_HOST_PARAM_INITIATOR_NAME
);
2476 static struct attribute
*iscsi_host_attrs
[] = {
2477 &dev_attr_host_netdev
.attr
,
2478 &dev_attr_host_hwaddress
.attr
,
2479 &dev_attr_host_ipaddress
.attr
,
2480 &dev_attr_host_initiatorname
.attr
,
2484 static mode_t
iscsi_host_attr_is_visible(struct kobject
*kobj
,
2485 struct attribute
*attr
, int i
)
2487 struct device
*cdev
= container_of(kobj
, struct device
, kobj
);
2488 struct Scsi_Host
*shost
= transport_class_to_shost(cdev
);
2489 struct iscsi_internal
*priv
= to_iscsi_internal(shost
->transportt
);
2492 if (attr
== &dev_attr_host_netdev
.attr
)
2493 param
= ISCSI_HOST_PARAM_NETDEV_NAME
;
2494 else if (attr
== &dev_attr_host_hwaddress
.attr
)
2495 param
= ISCSI_HOST_PARAM_HWADDRESS
;
2496 else if (attr
== &dev_attr_host_ipaddress
.attr
)
2497 param
= ISCSI_HOST_PARAM_IPADDRESS
;
2498 else if (attr
== &dev_attr_host_initiatorname
.attr
)
2499 param
= ISCSI_HOST_PARAM_INITIATOR_NAME
;
2501 WARN_ONCE(1, "Invalid host attr");
2505 return priv
->iscsi_transport
->attr_is_visible(ISCSI_HOST_PARAM
, param
);
2508 static struct attribute_group iscsi_host_group
= {
2509 .attrs
= iscsi_host_attrs
,
2510 .is_visible
= iscsi_host_attr_is_visible
,
2513 static int iscsi_session_match(struct attribute_container
*cont
,
2516 struct iscsi_cls_session
*session
;
2517 struct Scsi_Host
*shost
;
2518 struct iscsi_internal
*priv
;
2520 if (!iscsi_is_session_dev(dev
))
2523 session
= iscsi_dev_to_session(dev
);
2524 shost
= iscsi_session_to_shost(session
);
2525 if (!shost
->transportt
)
2528 priv
= to_iscsi_internal(shost
->transportt
);
2529 if (priv
->session_cont
.ac
.class != &iscsi_session_class
.class)
2532 return &priv
->session_cont
.ac
== cont
;
2535 static int iscsi_conn_match(struct attribute_container
*cont
,
2538 struct iscsi_cls_session
*session
;
2539 struct iscsi_cls_conn
*conn
;
2540 struct Scsi_Host
*shost
;
2541 struct iscsi_internal
*priv
;
2543 if (!iscsi_is_conn_dev(dev
))
2546 conn
= iscsi_dev_to_conn(dev
);
2547 session
= iscsi_dev_to_session(conn
->dev
.parent
);
2548 shost
= iscsi_session_to_shost(session
);
2550 if (!shost
->transportt
)
2553 priv
= to_iscsi_internal(shost
->transportt
);
2554 if (priv
->conn_cont
.ac
.class != &iscsi_connection_class
.class)
2557 return &priv
->conn_cont
.ac
== cont
;
2560 static int iscsi_host_match(struct attribute_container
*cont
,
2563 struct Scsi_Host
*shost
;
2564 struct iscsi_internal
*priv
;
2566 if (!scsi_is_host_device(dev
))
2569 shost
= dev_to_shost(dev
);
2570 if (!shost
->transportt
||
2571 shost
->transportt
->host_attrs
.ac
.class != &iscsi_host_class
.class)
2574 priv
= to_iscsi_internal(shost
->transportt
);
2575 return &priv
->t
.host_attrs
.ac
== cont
;
2578 struct scsi_transport_template
*
2579 iscsi_register_transport(struct iscsi_transport
*tt
)
2581 struct iscsi_internal
*priv
;
2582 unsigned long flags
;
2587 priv
= iscsi_if_transport_lookup(tt
);
2591 priv
= kzalloc(sizeof(*priv
), GFP_KERNEL
);
2594 INIT_LIST_HEAD(&priv
->list
);
2595 priv
->iscsi_transport
= tt
;
2596 priv
->t
.user_scan
= iscsi_user_scan
;
2597 priv
->t
.create_work_queue
= 1;
2599 priv
->dev
.class = &iscsi_transport_class
;
2600 dev_set_name(&priv
->dev
, "%s", tt
->name
);
2601 err
= device_register(&priv
->dev
);
2605 err
= sysfs_create_group(&priv
->dev
.kobj
, &iscsi_transport_group
);
2607 goto unregister_dev
;
2609 /* host parameters */
2610 priv
->t
.host_attrs
.ac
.class = &iscsi_host_class
.class;
2611 priv
->t
.host_attrs
.ac
.match
= iscsi_host_match
;
2612 priv
->t
.host_attrs
.ac
.grp
= &iscsi_host_group
;
2613 priv
->t
.host_size
= sizeof(struct iscsi_cls_host
);
2614 transport_container_register(&priv
->t
.host_attrs
);
2616 /* connection parameters */
2617 priv
->conn_cont
.ac
.class = &iscsi_connection_class
.class;
2618 priv
->conn_cont
.ac
.match
= iscsi_conn_match
;
2619 priv
->conn_cont
.ac
.grp
= &iscsi_conn_group
;
2620 transport_container_register(&priv
->conn_cont
);
2622 /* session parameters */
2623 priv
->session_cont
.ac
.class = &iscsi_session_class
.class;
2624 priv
->session_cont
.ac
.match
= iscsi_session_match
;
2625 priv
->session_cont
.ac
.grp
= &iscsi_session_group
;
2626 transport_container_register(&priv
->session_cont
);
2628 spin_lock_irqsave(&iscsi_transport_lock
, flags
);
2629 list_add(&priv
->list
, &iscsi_transports
);
2630 spin_unlock_irqrestore(&iscsi_transport_lock
, flags
);
2632 printk(KERN_NOTICE
"iscsi: registered transport (%s)\n", tt
->name
);
2636 device_unregister(&priv
->dev
);
2642 EXPORT_SYMBOL_GPL(iscsi_register_transport
);
2644 int iscsi_unregister_transport(struct iscsi_transport
*tt
)
2646 struct iscsi_internal
*priv
;
2647 unsigned long flags
;
2651 mutex_lock(&rx_queue_mutex
);
2653 priv
= iscsi_if_transport_lookup(tt
);
2656 spin_lock_irqsave(&iscsi_transport_lock
, flags
);
2657 list_del(&priv
->list
);
2658 spin_unlock_irqrestore(&iscsi_transport_lock
, flags
);
2660 transport_container_unregister(&priv
->conn_cont
);
2661 transport_container_unregister(&priv
->session_cont
);
2662 transport_container_unregister(&priv
->t
.host_attrs
);
2664 sysfs_remove_group(&priv
->dev
.kobj
, &iscsi_transport_group
);
2665 device_unregister(&priv
->dev
);
2666 mutex_unlock(&rx_queue_mutex
);
2670 EXPORT_SYMBOL_GPL(iscsi_unregister_transport
);
2672 static __init
int iscsi_transport_init(void)
2676 printk(KERN_INFO
"Loading iSCSI transport class v%s.\n",
2677 ISCSI_TRANSPORT_VERSION
);
2679 atomic_set(&iscsi_session_nr
, 0);
2681 err
= class_register(&iscsi_transport_class
);
2685 err
= class_register(&iscsi_endpoint_class
);
2687 goto unregister_transport_class
;
2689 err
= class_register(&iscsi_iface_class
);
2691 goto unregister_endpoint_class
;
2693 err
= transport_class_register(&iscsi_host_class
);
2695 goto unregister_iface_class
;
2697 err
= transport_class_register(&iscsi_connection_class
);
2699 goto unregister_host_class
;
2701 err
= transport_class_register(&iscsi_session_class
);
2703 goto unregister_conn_class
;
2705 nls
= netlink_kernel_create(&init_net
, NETLINK_ISCSI
, 1, iscsi_if_rx
,
2709 goto unregister_session_class
;
2712 iscsi_eh_timer_workq
= create_singlethread_workqueue("iscsi_eh");
2713 if (!iscsi_eh_timer_workq
)
2719 netlink_kernel_release(nls
);
2720 unregister_session_class
:
2721 transport_class_unregister(&iscsi_session_class
);
2722 unregister_conn_class
:
2723 transport_class_unregister(&iscsi_connection_class
);
2724 unregister_host_class
:
2725 transport_class_unregister(&iscsi_host_class
);
2726 unregister_iface_class
:
2727 class_unregister(&iscsi_iface_class
);
2728 unregister_endpoint_class
:
2729 class_unregister(&iscsi_endpoint_class
);
2730 unregister_transport_class
:
2731 class_unregister(&iscsi_transport_class
);
2735 static void __exit
iscsi_transport_exit(void)
2737 destroy_workqueue(iscsi_eh_timer_workq
);
2738 netlink_kernel_release(nls
);
2739 transport_class_unregister(&iscsi_connection_class
);
2740 transport_class_unregister(&iscsi_session_class
);
2741 transport_class_unregister(&iscsi_host_class
);
2742 class_unregister(&iscsi_endpoint_class
);
2743 class_unregister(&iscsi_iface_class
);
2744 class_unregister(&iscsi_transport_class
);
2747 module_init(iscsi_transport_init
);
2748 module_exit(iscsi_transport_exit
);
2750 MODULE_AUTHOR("Mike Christie <michaelc@cs.wisc.edu>, "
2751 "Dmitry Yusupov <dmitry_yus@yahoo.com>, "
2752 "Alex Aizman <itn780@yahoo.com>");
2753 MODULE_DESCRIPTION("iSCSI Transport Interface");
2754 MODULE_LICENSE("GPL");
2755 MODULE_VERSION(ISCSI_TRANSPORT_VERSION
);
2756 MODULE_ALIAS_NET_PF_PROTO(PF_NETLINK
, NETLINK_ISCSI
);