diff options
Diffstat (limited to 'net/9p/mod.c')
-rw-r--r-- | net/9p/mod.c | 92 |
1 files changed, 67 insertions, 25 deletions
diff --git a/net/9p/mod.c b/net/9p/mod.c index bdee1fb7cc62..1084feb24cb0 100644 --- a/net/9p/mod.c +++ b/net/9p/mod.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/parser.h> | 31 | #include <linux/parser.h> |
32 | #include <net/9p/transport.h> | 32 | #include <net/9p/transport.h> |
33 | #include <linux/list.h> | 33 | #include <linux/list.h> |
34 | #include <linux/spinlock.h> | ||
34 | 35 | ||
35 | #ifdef CONFIG_NET_9P_DEBUG | 36 | #ifdef CONFIG_NET_9P_DEBUG |
36 | unsigned int p9_debug_level = 0; /* feature-rific global debug level */ | 37 | unsigned int p9_debug_level = 0; /* feature-rific global debug level */ |
@@ -44,8 +45,8 @@ MODULE_PARM_DESC(debug, "9P debugging level"); | |||
44 | * | 45 | * |
45 | */ | 46 | */ |
46 | 47 | ||
48 | static DEFINE_SPINLOCK(v9fs_trans_lock); | ||
47 | static LIST_HEAD(v9fs_trans_list); | 49 | static LIST_HEAD(v9fs_trans_list); |
48 | static struct p9_trans_module *v9fs_default_transport; | ||
49 | 50 | ||
50 | /** | 51 | /** |
51 | * v9fs_register_trans - register a new transport with 9p | 52 | * v9fs_register_trans - register a new transport with 9p |
@@ -54,48 +55,87 @@ static struct p9_trans_module *v9fs_default_transport; | |||
54 | */ | 55 | */ |
55 | void v9fs_register_trans(struct p9_trans_module *m) | 56 | void v9fs_register_trans(struct p9_trans_module *m) |
56 | { | 57 | { |
58 | spin_lock(&v9fs_trans_lock); | ||
57 | list_add_tail(&m->list, &v9fs_trans_list); | 59 | list_add_tail(&m->list, &v9fs_trans_list); |
58 | if (m->def) | 60 | spin_unlock(&v9fs_trans_lock); |
59 | v9fs_default_transport = m; | ||
60 | } | 61 | } |
61 | EXPORT_SYMBOL(v9fs_register_trans); | 62 | EXPORT_SYMBOL(v9fs_register_trans); |
62 | 63 | ||
63 | /** | 64 | /** |
64 | * v9fs_match_trans - match transport versus registered transports | 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 | /** | ||
78 | * v9fs_get_trans_by_name - get transport with the matching name | ||
65 | * @name: string identifying transport | 79 | * @name: string identifying transport |
66 | * | 80 | * |
67 | */ | 81 | */ |
68 | struct p9_trans_module *v9fs_match_trans(const substring_t *name) | 82 | struct p9_trans_module *v9fs_get_trans_by_name(const substring_t *name) |
69 | { | 83 | { |
70 | struct list_head *p; | 84 | struct p9_trans_module *t, *found = NULL; |
71 | struct p9_trans_module *t = NULL; | 85 | |
72 | 86 | spin_lock(&v9fs_trans_lock); | |
73 | list_for_each(p, &v9fs_trans_list) { | 87 | |
74 | t = list_entry(p, struct p9_trans_module, list); | 88 | list_for_each_entry(t, &v9fs_trans_list, list) |
75 | if (strncmp(t->name, name->from, name->to-name->from) == 0) | 89 | if (strncmp(t->name, name->from, name->to-name->from) == 0 && |
76 | return t; | 90 | try_module_get(t->owner)) { |
77 | } | 91 | found = t; |
78 | return NULL; | 92 | break; |
93 | } | ||
94 | |||
95 | spin_unlock(&v9fs_trans_lock); | ||
96 | return found; | ||
79 | } | 97 | } |
80 | EXPORT_SYMBOL(v9fs_match_trans); | 98 | EXPORT_SYMBOL(v9fs_get_trans_by_name); |
81 | 99 | ||
82 | /** | 100 | /** |
83 | * v9fs_default_trans - returns pointer to default transport | 101 | * v9fs_get_default_trans - get the default transport |
84 | * | 102 | * |
85 | */ | 103 | */ |
86 | 104 | ||
87 | struct p9_trans_module *v9fs_default_trans(void) | 105 | struct p9_trans_module *v9fs_get_default_trans(void) |
88 | { | 106 | { |
89 | if (v9fs_default_transport) | 107 | struct p9_trans_module *t, *found = NULL; |
90 | return v9fs_default_transport; | 108 | |
91 | else if (!list_empty(&v9fs_trans_list)) | 109 | spin_lock(&v9fs_trans_lock); |
92 | return list_first_entry(&v9fs_trans_list, | 110 | |
93 | struct p9_trans_module, list); | 111 | list_for_each_entry(t, &v9fs_trans_list, list) |
94 | else | 112 | if (t->def && try_module_get(t->owner)) { |
95 | return NULL; | 113 | found = t; |
114 | break; | ||
115 | } | ||
116 | |||
117 | if (!found) | ||
118 | list_for_each_entry(t, &v9fs_trans_list, list) | ||
119 | if (try_module_get(t->owner)) { | ||
120 | found = t; | ||
121 | break; | ||
122 | } | ||
123 | |||
124 | spin_unlock(&v9fs_trans_lock); | ||
125 | return found; | ||
96 | } | 126 | } |
97 | EXPORT_SYMBOL(v9fs_default_trans); | 127 | EXPORT_SYMBOL(v9fs_get_default_trans); |
98 | 128 | ||
129 | /** | ||
130 | * v9fs_put_trans - put trans | ||
131 | * @m: transport to put | ||
132 | * | ||
133 | */ | ||
134 | void v9fs_put_trans(struct p9_trans_module *m) | ||
135 | { | ||
136 | if (m) | ||
137 | module_put(m->owner); | ||
138 | } | ||
99 | 139 | ||
100 | /** | 140 | /** |
101 | * v9fs_init - Initialize module | 141 | * v9fs_init - Initialize module |
@@ -120,6 +160,8 @@ static int __init init_p9(void) | |||
120 | static void __exit exit_p9(void) | 160 | static void __exit exit_p9(void) |
121 | { | 161 | { |
122 | printk(KERN_INFO "Unloading 9P2000 support\n"); | 162 | printk(KERN_INFO "Unloading 9P2000 support\n"); |
163 | |||
164 | p9_trans_fd_exit(); | ||
123 | } | 165 | } |
124 | 166 | ||
125 | module_init(init_p9) | 167 | module_init(init_p9) |