mod.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * net/9p/9p.c
  3. *
  4. * 9P entry point
  5. *
  6. * Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
  7. * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
  8. * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2
  12. * as published by the Free Software Foundation.
  13. *
  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.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to:
  21. * Free Software Foundation
  22. * 51 Franklin Street, Fifth Floor
  23. * Boston, MA 02111-1301 USA
  24. *
  25. */
  26. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  27. #include <linux/module.h>
  28. #include <linux/errno.h>
  29. #include <linux/sched.h>
  30. #include <linux/moduleparam.h>
  31. #include <net/9p/9p.h>
  32. #include <linux/fs.h>
  33. #include <linux/parser.h>
  34. #include <net/9p/client.h>
  35. #include <net/9p/transport.h>
  36. #include <linux/list.h>
  37. #include <linux/spinlock.h>
  38. #ifdef CONFIG_NET_9P_DEBUG
  39. unsigned int p9_debug_level = 0; /* feature-rific global debug level */
  40. EXPORT_SYMBOL(p9_debug_level);
  41. module_param_named(debug, p9_debug_level, uint, 0);
  42. MODULE_PARM_DESC(debug, "9P debugging level");
  43. void _p9_debug(enum p9_debug_flags level, const char *func,
  44. const char *fmt, ...)
  45. {
  46. struct va_format vaf;
  47. va_list args;
  48. if ((p9_debug_level & level) != level)
  49. return;
  50. va_start(args, fmt);
  51. vaf.fmt = fmt;
  52. vaf.va = &args;
  53. if (level == P9_DEBUG_9P)
  54. pr_notice("(%8.8d) %pV", task_pid_nr(current), &vaf);
  55. else
  56. pr_notice("-- %s (%d): %pV", func, task_pid_nr(current), &vaf);
  57. va_end(args);
  58. }
  59. EXPORT_SYMBOL(_p9_debug);
  60. #endif
  61. /*
  62. * Dynamic Transport Registration Routines
  63. *
  64. */
  65. static DEFINE_SPINLOCK(v9fs_trans_lock);
  66. static LIST_HEAD(v9fs_trans_list);
  67. /**
  68. * v9fs_register_trans - register a new transport with 9p
  69. * @m: structure describing the transport module and entry points
  70. *
  71. */
  72. void v9fs_register_trans(struct p9_trans_module *m)
  73. {
  74. spin_lock(&v9fs_trans_lock);
  75. list_add_tail(&m->list, &v9fs_trans_list);
  76. spin_unlock(&v9fs_trans_lock);
  77. }
  78. EXPORT_SYMBOL(v9fs_register_trans);
  79. /**
  80. * v9fs_unregister_trans - unregister a 9p transport
  81. * @m: the transport to remove
  82. *
  83. */
  84. void v9fs_unregister_trans(struct p9_trans_module *m)
  85. {
  86. spin_lock(&v9fs_trans_lock);
  87. list_del_init(&m->list);
  88. spin_unlock(&v9fs_trans_lock);
  89. }
  90. EXPORT_SYMBOL(v9fs_unregister_trans);
  91. /**
  92. * v9fs_get_trans_by_name - get transport with the matching name
  93. * @name: string identifying transport
  94. *
  95. */
  96. struct p9_trans_module *v9fs_get_trans_by_name(char *s)
  97. {
  98. struct p9_trans_module *t, *found = NULL;
  99. spin_lock(&v9fs_trans_lock);
  100. list_for_each_entry(t, &v9fs_trans_list, list)
  101. if (strcmp(t->name, s) == 0 &&
  102. try_module_get(t->owner)) {
  103. found = t;
  104. break;
  105. }
  106. spin_unlock(&v9fs_trans_lock);
  107. return found;
  108. }
  109. EXPORT_SYMBOL(v9fs_get_trans_by_name);
  110. /**
  111. * v9fs_get_default_trans - get the default transport
  112. *
  113. */
  114. struct p9_trans_module *v9fs_get_default_trans(void)
  115. {
  116. struct p9_trans_module *t, *found = NULL;
  117. spin_lock(&v9fs_trans_lock);
  118. list_for_each_entry(t, &v9fs_trans_list, list)
  119. if (t->def && try_module_get(t->owner)) {
  120. found = t;
  121. break;
  122. }
  123. if (!found)
  124. list_for_each_entry(t, &v9fs_trans_list, list)
  125. if (try_module_get(t->owner)) {
  126. found = t;
  127. break;
  128. }
  129. spin_unlock(&v9fs_trans_lock);
  130. return found;
  131. }
  132. EXPORT_SYMBOL(v9fs_get_default_trans);
  133. /**
  134. * v9fs_put_trans - put trans
  135. * @m: transport to put
  136. *
  137. */
  138. void v9fs_put_trans(struct p9_trans_module *m)
  139. {
  140. if (m)
  141. module_put(m->owner);
  142. }
  143. /**
  144. * init_p9 - Initialize module
  145. *
  146. */
  147. static int __init init_p9(void)
  148. {
  149. int ret = 0;
  150. p9_error_init();
  151. pr_info("Installing 9P2000 support\n");
  152. p9_trans_fd_init();
  153. return ret;
  154. }
  155. /**
  156. * exit_p9 - shutdown module
  157. *
  158. */
  159. static void __exit exit_p9(void)
  160. {
  161. pr_info("Unloading 9P2000 support\n");
  162. p9_trans_fd_exit();
  163. }
  164. module_init(init_p9)
  165. module_exit(exit_p9)
  166. MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
  167. MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
  168. MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
  169. MODULE_LICENSE("GPL");