blob: c4eb141c6435983ea3493159f48cf6c3919a9f7c [file] [log] [blame]
Nicholas Bellinger3f993062013-03-06 21:53:26 -08001#include <linux/spinlock.h>
2#include <linux/list.h>
Bart Van Assche8dcf07b2016-11-14 15:47:14 -08003#include <linux/module.h>
Nicholas Bellinger3f993062013-03-06 21:53:26 -08004#include <target/iscsi/iscsi_transport.h>
5
6static LIST_HEAD(g_transport_list);
7static DEFINE_MUTEX(transport_mutex);
8
9struct iscsit_transport *iscsit_get_transport(int type)
10{
11 struct iscsit_transport *t;
12
13 mutex_lock(&transport_mutex);
14 list_for_each_entry(t, &g_transport_list, t_node) {
15 if (t->transport_type == type) {
16 if (t->owner && !try_module_get(t->owner)) {
17 t = NULL;
18 }
19 mutex_unlock(&transport_mutex);
20 return t;
21 }
22 }
23 mutex_unlock(&transport_mutex);
24
25 return NULL;
26}
27
28void iscsit_put_transport(struct iscsit_transport *t)
29{
Markus Elfring2ed37f62014-11-21 10:25:45 +010030 module_put(t->owner);
Nicholas Bellinger3f993062013-03-06 21:53:26 -080031}
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);