Thomas Gleixner | 1f32761 | 2019-05-28 09:57:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 2 | /* |
| 3 | * net/9p/9p.c |
| 4 | * |
| 5 | * 9P entry point |
| 6 | * |
| 7 | * Copyright (C) 2007 by Latchesar Ionkov <[email protected]> |
| 8 | * Copyright (C) 2004 by Eric Van Hensbergen <[email protected]> |
| 9 | * Copyright (C) 2002 by Ron Minnich <[email protected]> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 10 | */ |
| 11 | |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 13 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 14 | #include <linux/module.h> |
Thomas Weißschuh | 4cd82a5 | 2021-10-17 15:46:11 +0200 | [diff] [blame^] | 15 | #include <linux/kmod.h> |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 16 | #include <linux/errno.h> |
| 17 | #include <linux/sched.h> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 18 | #include <linux/moduleparam.h> |
| 19 | #include <net/9p/9p.h> |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 20 | #include <linux/fs.h> |
| 21 | #include <linux/parser.h> |
Eric Van Hensbergen | 8b81ef5 | 2008-10-13 18:45:25 -0500 | [diff] [blame] | 22 | #include <net/9p/client.h> |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 23 | #include <net/9p/transport.h> |
| 24 | #include <linux/list.h> |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 25 | #include <linux/spinlock.h> |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 26 | |
| 27 | #ifdef CONFIG_NET_9P_DEBUG |
| 28 | unsigned int p9_debug_level = 0; /* feature-rific global debug level */ |
| 29 | EXPORT_SYMBOL(p9_debug_level); |
| 30 | module_param_named(debug, p9_debug_level, uint, 0); |
| 31 | MODULE_PARM_DESC(debug, "9P debugging level"); |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 32 | |
| 33 | void _p9_debug(enum p9_debug_flags level, const char *func, |
| 34 | const char *fmt, ...) |
| 35 | { |
| 36 | struct va_format vaf; |
| 37 | va_list args; |
| 38 | |
| 39 | if ((p9_debug_level & level) != level) |
| 40 | return; |
| 41 | |
| 42 | va_start(args, fmt); |
| 43 | |
| 44 | vaf.fmt = fmt; |
| 45 | vaf.va = &args; |
| 46 | |
| 47 | if (level == P9_DEBUG_9P) |
| 48 | pr_notice("(%8.8d) %pV", task_pid_nr(current), &vaf); |
| 49 | else |
| 50 | pr_notice("-- %s (%d): %pV", func, task_pid_nr(current), &vaf); |
| 51 | |
| 52 | va_end(args); |
| 53 | } |
| 54 | EXPORT_SYMBOL(_p9_debug); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 55 | #endif |
| 56 | |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 57 | /* |
| 58 | * Dynamic Transport Registration Routines |
| 59 | * |
| 60 | */ |
| 61 | |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 62 | static DEFINE_SPINLOCK(v9fs_trans_lock); |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 63 | static LIST_HEAD(v9fs_trans_list); |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * v9fs_register_trans - register a new transport with 9p |
Eric Van Hensbergen | ee44399 | 2008-03-05 07:08:09 -0600 | [diff] [blame] | 67 | * @m: structure describing the transport module and entry points |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 68 | * |
| 69 | */ |
| 70 | void v9fs_register_trans(struct p9_trans_module *m) |
| 71 | { |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 72 | spin_lock(&v9fs_trans_lock); |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 73 | list_add_tail(&m->list, &v9fs_trans_list); |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 74 | spin_unlock(&v9fs_trans_lock); |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 75 | } |
| 76 | EXPORT_SYMBOL(v9fs_register_trans); |
| 77 | |
| 78 | /** |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 79 | * v9fs_unregister_trans - unregister a 9p transport |
| 80 | * @m: the transport to remove |
| 81 | * |
| 82 | */ |
| 83 | void v9fs_unregister_trans(struct p9_trans_module *m) |
| 84 | { |
| 85 | spin_lock(&v9fs_trans_lock); |
| 86 | list_del_init(&m->list); |
| 87 | spin_unlock(&v9fs_trans_lock); |
| 88 | } |
| 89 | EXPORT_SYMBOL(v9fs_unregister_trans); |
| 90 | |
Thomas Weißschuh | 4cd82a5 | 2021-10-17 15:46:11 +0200 | [diff] [blame^] | 91 | static struct p9_trans_module *_p9_get_trans_by_name(char *s) |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 92 | { |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 93 | struct p9_trans_module *t, *found = NULL; |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 94 | |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 95 | spin_lock(&v9fs_trans_lock); |
| 96 | |
| 97 | list_for_each_entry(t, &v9fs_trans_list, list) |
Prem Karat | 4d63055 | 2011-05-06 18:35:32 +0530 | [diff] [blame] | 98 | if (strcmp(t->name, s) == 0 && |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 99 | try_module_get(t->owner)) { |
| 100 | found = t; |
| 101 | break; |
| 102 | } |
| 103 | |
| 104 | spin_unlock(&v9fs_trans_lock); |
Thomas Weißschuh | 4cd82a5 | 2021-10-17 15:46:11 +0200 | [diff] [blame^] | 105 | |
| 106 | return found; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * v9fs_get_trans_by_name - get transport with the matching name |
| 111 | * @s: string identifying transport |
| 112 | * |
| 113 | */ |
| 114 | struct p9_trans_module *v9fs_get_trans_by_name(char *s) |
| 115 | { |
| 116 | struct p9_trans_module *found = NULL; |
| 117 | |
| 118 | found = _p9_get_trans_by_name(s); |
| 119 | |
| 120 | #ifdef CONFIG_MODULES |
| 121 | if (!found) { |
| 122 | request_module("9p-%s", s); |
| 123 | found = _p9_get_trans_by_name(s); |
| 124 | } |
| 125 | #endif |
| 126 | |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 127 | return found; |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 128 | } |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 129 | EXPORT_SYMBOL(v9fs_get_trans_by_name); |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 130 | |
| 131 | /** |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 132 | * v9fs_get_default_trans - get the default transport |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 133 | * |
| 134 | */ |
| 135 | |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 136 | struct p9_trans_module *v9fs_get_default_trans(void) |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 137 | { |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 138 | struct p9_trans_module *t, *found = NULL; |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 139 | |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 140 | spin_lock(&v9fs_trans_lock); |
| 141 | |
| 142 | list_for_each_entry(t, &v9fs_trans_list, list) |
| 143 | if (t->def && try_module_get(t->owner)) { |
| 144 | found = t; |
| 145 | break; |
| 146 | } |
| 147 | |
| 148 | if (!found) |
| 149 | list_for_each_entry(t, &v9fs_trans_list, list) |
| 150 | if (try_module_get(t->owner)) { |
| 151 | found = t; |
| 152 | break; |
| 153 | } |
| 154 | |
| 155 | spin_unlock(&v9fs_trans_lock); |
| 156 | return found; |
| 157 | } |
| 158 | EXPORT_SYMBOL(v9fs_get_default_trans); |
| 159 | |
| 160 | /** |
| 161 | * v9fs_put_trans - put trans |
| 162 | * @m: transport to put |
| 163 | * |
| 164 | */ |
| 165 | void v9fs_put_trans(struct p9_trans_module *m) |
| 166 | { |
| 167 | if (m) |
| 168 | module_put(m->owner); |
| 169 | } |
Eric Van Hensbergen | fb0466c3 | 2007-10-17 14:31:07 -0500 | [diff] [blame] | 170 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 171 | /** |
Rob Landley | 961a5a5 | 2011-04-30 12:56:24 -0500 | [diff] [blame] | 172 | * init_p9 - Initialize module |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 173 | * |
| 174 | */ |
| 175 | static int __init init_p9(void) |
| 176 | { |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 177 | int ret; |
| 178 | |
| 179 | ret = p9_client_init(); |
| 180 | if (ret) |
| 181 | return ret; |
| 182 | |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 183 | p9_error_init(); |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 184 | pr_info("Installing 9P2000 support\n"); |
Eric Van Hensbergen | 887b3ec | 2008-05-08 20:26:37 -0500 | [diff] [blame] | 185 | p9_trans_fd_init(); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 186 | |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 187 | return ret; |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | /** |
Rob Landley | 961a5a5 | 2011-04-30 12:56:24 -0500 | [diff] [blame] | 191 | * exit_p9 - shutdown module |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 192 | * |
| 193 | */ |
| 194 | |
| 195 | static void __exit exit_p9(void) |
| 196 | { |
Joe Perches | 5d38515 | 2011-11-28 10:40:46 -0800 | [diff] [blame] | 197 | pr_info("Unloading 9P2000 support\n"); |
Tejun Heo | 72029fe | 2008-09-24 16:22:23 -0500 | [diff] [blame] | 198 | |
| 199 | p9_trans_fd_exit(); |
Matthew Wilcox | 996d5b4 | 2018-07-11 14:02:24 -0700 | [diff] [blame] | 200 | p9_client_exit(); |
Latchesar Ionkov | bd238fb | 2007-07-10 17:57:28 -0500 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | module_init(init_p9) |
| 204 | module_exit(exit_p9) |
| 205 | |
| 206 | MODULE_AUTHOR("Latchesar Ionkov <[email protected]>"); |
| 207 | MODULE_AUTHOR("Eric Van Hensbergen <[email protected]>"); |
| 208 | MODULE_AUTHOR("Ron Minnich <[email protected]>"); |
| 209 | MODULE_LICENSE("GPL"); |
Rob Gill | 67c20de | 2020-06-20 02:08:25 +0000 | [diff] [blame] | 210 | MODULE_DESCRIPTION("Plan 9 Resource Sharing Support (9P2000)"); |