/net/9p/mod.c

http://github.com/mirrors/linux · C · 191 lines · 112 code · 33 blank · 46 comment · 12 complexity · e710ba56b785438cf91e825a747e2297 MD5 · raw file

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