blob: 882728fac30c4e8a8fcf9db5e26f826ec86d2f0d [file] [log] [blame]
Nicholas Bellinger3f993062013-03-06 21:53:26 -08001#include <linux/spinlock.h>
2#include <linux/list.h>
3#include <target/iscsi/iscsi_transport.h>
4
5static LIST_HEAD(g_transport_list);
6static DEFINE_MUTEX(transport_mutex);
7
8struct iscsit_transport *iscsit_get_transport(int type)
9{
10 struct iscsit_transport *t;
11
12 mutex_lock(&transport_mutex);
13 list_for_each_entry(t, &g_transport_list, t_node) {
14 if (t->transport_type == type) {
15 if (t->owner && !try_module_get(t->owner)) {
16 t = NULL;
17 }
18 mutex_unlock(&transport_mutex);
19 return t;
20 }
21 }
22 mutex_unlock(&transport_mutex);
23
24 return NULL;
25}
26
27void iscsit_put_transport(struct iscsit_transport *t)
28{
29 if (t->owner)
30 module_put(t->owner);
31}
32
33int iscsit_register_transport(struct iscsit_transport *t)
34{
35 INIT_LIST_HEAD(&t->t_node);
36
37 mutex_lock(&transport_mutex);
38 list_add_tail(&t->t_node, &g_transport_list);
39 mutex_unlock(&transport_mutex);
40
41 pr_debug("Registered iSCSI transport: %s\n", t->name);
42
43 return 0;
44}
45EXPORT_SYMBOL(iscsit_register_transport);
46
47void iscsit_unregister_transport(struct iscsit_transport *t)
48{
49 mutex_lock(&transport_mutex);
50 list_del(&t->t_node);
51 mutex_unlock(&transport_mutex);
52
53 pr_debug("Unregistered iSCSI transport: %s\n", t->name);
54}
55EXPORT_SYMBOL(iscsit_unregister_transport);