blob: 94cd2d132fd7fa9796b20e4407ec69c6e0348daf [file] [log] [blame]
Thomas Gleixner1f327612019-05-28 09:57:16 -07001// SPDX-License-Identifier: GPL-2.0-only
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05002/*
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>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050010 */
11
Joe Perches5d385152011-11-28 10:40:46 -080012#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050014#include <linux/module.h>
Joe Perches5d385152011-11-28 10:40:46 -080015#include <linux/errno.h>
16#include <linux/sched.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050017#include <linux/moduleparam.h>
18#include <net/9p/9p.h>
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -050019#include <linux/fs.h>
20#include <linux/parser.h>
Eric Van Hensbergen8b81ef52008-10-13 18:45:25 -050021#include <net/9p/client.h>
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -050022#include <net/9p/transport.h>
23#include <linux/list.h>
Tejun Heo72029fe2008-09-24 16:22:23 -050024#include <linux/spinlock.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050025
26#ifdef CONFIG_NET_9P_DEBUG
27unsigned int p9_debug_level = 0; /* feature-rific global debug level */
28EXPORT_SYMBOL(p9_debug_level);
29module_param_named(debug, p9_debug_level, uint, 0);
30MODULE_PARM_DESC(debug, "9P debugging level");
Joe Perches5d385152011-11-28 10:40:46 -080031
32void _p9_debug(enum p9_debug_flags level, const char *func,
33 const char *fmt, ...)
34{
35 struct va_format vaf;
36 va_list args;
37
38 if ((p9_debug_level & level) != level)
39 return;
40
41 va_start(args, fmt);
42
43 vaf.fmt = fmt;
44 vaf.va = &args;
45
46 if (level == P9_DEBUG_9P)
47 pr_notice("(%8.8d) %pV", task_pid_nr(current), &vaf);
48 else
49 pr_notice("-- %s (%d): %pV", func, task_pid_nr(current), &vaf);
50
51 va_end(args);
52}
53EXPORT_SYMBOL(_p9_debug);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050054#endif
55
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -050056/*
57 * Dynamic Transport Registration Routines
58 *
59 */
60
Tejun Heo72029fe2008-09-24 16:22:23 -050061static DEFINE_SPINLOCK(v9fs_trans_lock);
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -050062static LIST_HEAD(v9fs_trans_list);
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -050063
64/**
65 * v9fs_register_trans - register a new transport with 9p
Eric Van Hensbergenee443992008-03-05 07:08:09 -060066 * @m: structure describing the transport module and entry points
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -050067 *
68 */
69void v9fs_register_trans(struct p9_trans_module *m)
70{
Tejun Heo72029fe2008-09-24 16:22:23 -050071 spin_lock(&v9fs_trans_lock);
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -050072 list_add_tail(&m->list, &v9fs_trans_list);
Tejun Heo72029fe2008-09-24 16:22:23 -050073 spin_unlock(&v9fs_trans_lock);
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -050074}
75EXPORT_SYMBOL(v9fs_register_trans);
76
77/**
Tejun Heo72029fe2008-09-24 16:22:23 -050078 * v9fs_unregister_trans - unregister a 9p transport
79 * @m: the transport to remove
80 *
81 */
82void v9fs_unregister_trans(struct p9_trans_module *m)
83{
84 spin_lock(&v9fs_trans_lock);
85 list_del_init(&m->list);
86 spin_unlock(&v9fs_trans_lock);
87}
88EXPORT_SYMBOL(v9fs_unregister_trans);
89
90/**
91 * v9fs_get_trans_by_name - get transport with the matching name
Sun Lianwen3a443bd62018-05-05 11:29:16 +080092 * @s: string identifying transport
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -050093 *
94 */
Prem Karat4d630552011-05-06 18:35:32 +053095struct p9_trans_module *v9fs_get_trans_by_name(char *s)
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -050096{
Tejun Heo72029fe2008-09-24 16:22:23 -050097 struct p9_trans_module *t, *found = NULL;
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -050098
Tejun Heo72029fe2008-09-24 16:22:23 -050099 spin_lock(&v9fs_trans_lock);
100
101 list_for_each_entry(t, &v9fs_trans_list, list)
Prem Karat4d630552011-05-06 18:35:32 +0530102 if (strcmp(t->name, s) == 0 &&
Tejun Heo72029fe2008-09-24 16:22:23 -0500103 try_module_get(t->owner)) {
104 found = t;
105 break;
106 }
107
108 spin_unlock(&v9fs_trans_lock);
109 return found;
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -0500110}
Tejun Heo72029fe2008-09-24 16:22:23 -0500111EXPORT_SYMBOL(v9fs_get_trans_by_name);
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -0500112
113/**
Tejun Heo72029fe2008-09-24 16:22:23 -0500114 * v9fs_get_default_trans - get the default transport
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -0500115 *
116 */
117
Tejun Heo72029fe2008-09-24 16:22:23 -0500118struct p9_trans_module *v9fs_get_default_trans(void)
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -0500119{
Tejun Heo72029fe2008-09-24 16:22:23 -0500120 struct p9_trans_module *t, *found = NULL;
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -0500121
Tejun Heo72029fe2008-09-24 16:22:23 -0500122 spin_lock(&v9fs_trans_lock);
123
124 list_for_each_entry(t, &v9fs_trans_list, list)
125 if (t->def && try_module_get(t->owner)) {
126 found = t;
127 break;
128 }
129
130 if (!found)
131 list_for_each_entry(t, &v9fs_trans_list, list)
132 if (try_module_get(t->owner)) {
133 found = t;
134 break;
135 }
136
137 spin_unlock(&v9fs_trans_lock);
138 return found;
139}
140EXPORT_SYMBOL(v9fs_get_default_trans);
141
142/**
143 * v9fs_put_trans - put trans
144 * @m: transport to put
145 *
146 */
147void v9fs_put_trans(struct p9_trans_module *m)
148{
149 if (m)
150 module_put(m->owner);
151}
Eric Van Hensbergenfb0466c2007-10-17 14:31:07 -0500152
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500153/**
Rob Landley961a5a52011-04-30 12:56:24 -0500154 * init_p9 - Initialize module
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500155 *
156 */
157static int __init init_p9(void)
158{
Matthew Wilcox996d5b42018-07-11 14:02:24 -0700159 int ret;
160
161 ret = p9_client_init();
162 if (ret)
163 return ret;
164
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500165 p9_error_init();
Joe Perches5d385152011-11-28 10:40:46 -0800166 pr_info("Installing 9P2000 support\n");
Eric Van Hensbergen887b3ec2008-05-08 20:26:37 -0500167 p9_trans_fd_init();
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500168
Matthew Wilcox996d5b42018-07-11 14:02:24 -0700169 return ret;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500170}
171
172/**
Rob Landley961a5a52011-04-30 12:56:24 -0500173 * exit_p9 - shutdown module
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500174 *
175 */
176
177static void __exit exit_p9(void)
178{
Joe Perches5d385152011-11-28 10:40:46 -0800179 pr_info("Unloading 9P2000 support\n");
Tejun Heo72029fe2008-09-24 16:22:23 -0500180
181 p9_trans_fd_exit();
Matthew Wilcox996d5b42018-07-11 14:02:24 -0700182 p9_client_exit();
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500183}
184
185module_init(init_p9)
186module_exit(exit_p9)
187
188MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
189MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
190MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
191MODULE_LICENSE("GPL");
Greg Kroah-Hartmand483eed2020-07-02 12:51:03 +0200192MODULE_IMPORT_NS(VFS_internal_I_am_really_a_filesystem_and_am_NOT_a_driver);
Rob Gill67c20de2020-06-20 02:08:25 +0000193MODULE_DESCRIPTION("Plan 9 Resource Sharing Support (9P2000)");