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