iscsi_target_transport.c 1.2 KB

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