Merge branch 'drm-patches' of ssh://master.kernel.org/pub/scm/linux/kernel/git/airlie...
[deliverable/linux.git] / fs / 9p / v9fs.c
CommitLineData
9e82cf6a
EVH
1/*
2 * linux/fs/9p/v9fs.c
3 *
4 * This file contains functions assisting in mapping VFS to 9P2000
5 *
6 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
7 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
8 *
9 * This program is free software; you can redistribute it and/or modify
42e8c509
EVH
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
9e82cf6a
EVH
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to:
20 * Free Software Foundation
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02111-1301 USA
23 *
24 */
25
9e82cf6a
EVH
26#include <linux/module.h>
27#include <linux/errno.h>
28#include <linux/fs.h>
914e2637 29#include <linux/sched.h>
9e82cf6a
EVH
30#include <linux/parser.h>
31#include <linux/idr.h>
bd238fb4
LI
32#include <net/9p/9p.h>
33#include <net/9p/transport.h>
34#include <net/9p/conn.h>
35#include <net/9p/client.h>
9e82cf6a 36#include "v9fs.h"
9e82cf6a 37#include "v9fs_vfs.h"
9e82cf6a
EVH
38
39/*
40 * Option Parsing (code inspired by NFS code)
41 *
42 */
43
44enum {
45 /* Options that take integer arguments */
9e2f6688 46 Opt_debug, Opt_port, Opt_msize, Opt_uid, Opt_gid, Opt_afid,
9e82cf6a
EVH
47 Opt_rfdno, Opt_wfdno,
48 /* String options */
67543e50 49 Opt_uname, Opt_remotename,
9e82cf6a 50 /* Options that take no arguments */
bd238fb4 51 Opt_legacy, Opt_nodevmap, Opt_unix, Opt_tcp, Opt_fd, Opt_pci,
e03abc0c
EVH
52 /* Cache options */
53 Opt_cache_loose,
9e82cf6a
EVH
54 /* Error token */
55 Opt_err
56};
57
58static match_table_t tokens = {
9e2f6688 59 {Opt_debug, "debug=%x"},
9e82cf6a
EVH
60 {Opt_port, "port=%u"},
61 {Opt_msize, "msize=%u"},
62 {Opt_uid, "uid=%u"},
63 {Opt_gid, "gid=%u"},
64 {Opt_afid, "afid=%u"},
65 {Opt_rfdno, "rfdno=%u"},
66 {Opt_wfdno, "wfdno=%u"},
67543e50 67 {Opt_uname, "uname=%s"},
9e82cf6a
EVH
68 {Opt_remotename, "aname=%s"},
69 {Opt_unix, "proto=unix"},
70 {Opt_tcp, "proto=tcp"},
71 {Opt_fd, "proto=fd"},
bd238fb4
LI
72#ifdef CONFIG_PCI_9P
73 {Opt_pci, "proto=pci"},
74#endif
9e82cf6a
EVH
75 {Opt_tcp, "tcp"},
76 {Opt_unix, "unix"},
77 {Opt_fd, "fd"},
78 {Opt_legacy, "noextend"},
79 {Opt_nodevmap, "nodevmap"},
e03abc0c
EVH
80 {Opt_cache_loose, "cache=loose"},
81 {Opt_cache_loose, "loose"},
9e82cf6a
EVH
82 {Opt_err, NULL}
83};
84
bd238fb4
LI
85extern struct p9_transport *p9pci_trans_create(void);
86
9e82cf6a
EVH
87/*
88 * Parse option string.
89 */
90
91/**
92 * v9fs_parse_options - parse mount options into session structure
93 * @options: options string passed from mount
94 * @v9ses: existing v9fs session information
95 *
96 */
97
98static void v9fs_parse_options(char *options, struct v9fs_session_info *v9ses)
99{
100 char *p;
101 substring_t args[MAX_OPT_ARGS];
102 int option;
103 int ret;
104
105 /* setup defaults */
106 v9ses->port = V9FS_PORT;
107 v9ses->maxdata = 9000;
108 v9ses->proto = PROTO_TCP;
109 v9ses->extended = 1;
110 v9ses->afid = ~0;
111 v9ses->debug = 0;
112 v9ses->rfdno = ~0;
113 v9ses->wfdno = ~0;
e03abc0c 114 v9ses->cache = 0;
9e82cf6a
EVH
115
116 if (!options)
117 return;
118
119 while ((p = strsep(&options, ",")) != NULL) {
120 int token;
121 if (!*p)
122 continue;
123 token = match_token(p, tokens, args);
67543e50 124 if (token < Opt_uname) {
9e82cf6a 125 if ((ret = match_int(&args[0], &option)) < 0) {
bd238fb4 126 P9_DPRINTK(P9_DEBUG_ERROR,
9e82cf6a
EVH
127 "integer field, but no integer?\n");
128 continue;
129 }
9e82cf6a
EVH
130 }
131 switch (token) {
9e2f6688
EVH
132 case Opt_debug:
133 v9ses->debug = option;
134 p9_debug_level = option;
135 break;
9e82cf6a
EVH
136 case Opt_port:
137 v9ses->port = option;
138 break;
139 case Opt_msize:
140 v9ses->maxdata = option;
141 break;
142 case Opt_uid:
143 v9ses->uid = option;
144 break;
145 case Opt_gid:
146 v9ses->gid = option;
147 break;
148 case Opt_afid:
149 v9ses->afid = option;
150 break;
151 case Opt_rfdno:
152 v9ses->rfdno = option;
153 break;
154 case Opt_wfdno:
155 v9ses->wfdno = option;
156 break;
9e82cf6a
EVH
157 case Opt_tcp:
158 v9ses->proto = PROTO_TCP;
159 break;
160 case Opt_unix:
161 v9ses->proto = PROTO_UNIX;
162 break;
bd238fb4
LI
163 case Opt_pci:
164 v9ses->proto = PROTO_PCI;
165 break;
9e82cf6a
EVH
166 case Opt_fd:
167 v9ses->proto = PROTO_FD;
168 break;
67543e50 169 case Opt_uname:
9e82cf6a
EVH
170 match_strcpy(v9ses->name, &args[0]);
171 break;
172 case Opt_remotename:
173 match_strcpy(v9ses->remotename, &args[0]);
174 break;
175 case Opt_legacy:
176 v9ses->extended = 0;
177 break;
178 case Opt_nodevmap:
179 v9ses->nodev = 1;
180 break;
e03abc0c
EVH
181 case Opt_cache_loose:
182 v9ses->cache = CACHE_LOOSE;
183 break;
9e82cf6a
EVH
184 default:
185 continue;
186 }
187 }
188}
189
9e82cf6a
EVH
190/**
191 * v9fs_session_init - initialize session
192 * @v9ses: session information structure
193 * @dev_name: device being mounted
194 * @data: options
195 *
196 */
197
bd238fb4 198struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
9e82cf6a
EVH
199 const char *dev_name, char *data)
200{
9e82cf6a 201 int retval = -EINVAL;
bd238fb4
LI
202 struct p9_transport *trans;
203 struct p9_fid *fid;
9e82cf6a
EVH
204
205 v9ses->name = __getname();
206 if (!v9ses->name)
bd238fb4 207 return ERR_PTR(-ENOMEM);
9e82cf6a
EVH
208
209 v9ses->remotename = __getname();
210 if (!v9ses->remotename) {
ce44eeb6 211 __putname(v9ses->name);
bd238fb4 212 return ERR_PTR(-ENOMEM);
9e82cf6a
EVH
213 }
214
215 strcpy(v9ses->name, V9FS_DEFUSER);
216 strcpy(v9ses->remotename, V9FS_DEFANAME);
217
218 v9fs_parse_options(data, v9ses);
219
9e82cf6a
EVH
220 switch (v9ses->proto) {
221 case PROTO_TCP:
bd238fb4 222 trans = p9_trans_create_tcp(dev_name, v9ses->port);
9e82cf6a
EVH
223 break;
224 case PROTO_UNIX:
bd238fb4 225 trans = p9_trans_create_unix(dev_name);
9e82cf6a
EVH
226 *v9ses->remotename = 0;
227 break;
228 case PROTO_FD:
bd238fb4
LI
229 trans = p9_trans_create_fd(v9ses->rfdno, v9ses->wfdno);
230 *v9ses->remotename = 0;
231 break;
232#ifdef CONFIG_PCI_9P
233 case PROTO_PCI:
234 trans = p9pci_trans_create();
9e82cf6a 235 *v9ses->remotename = 0;
9e82cf6a 236 break;
bd238fb4 237#endif
9e82cf6a
EVH
238 default:
239 printk(KERN_ERR "v9fs: Bad mount protocol %d\n", v9ses->proto);
240 retval = -ENOPROTOOPT;
bd238fb4 241 goto error;
9e82cf6a
EVH
242 };
243
bd238fb4
LI
244 if (IS_ERR(trans)) {
245 retval = PTR_ERR(trans);
246 trans = NULL;
247 goto error;
a8e63bff
LI
248 }
249
bd238fb4
LI
250 v9ses->clnt = p9_client_create(trans, v9ses->maxdata + P9_IOHDRSZ,
251 v9ses->extended);
9e82cf6a 252
bd238fb4
LI
253 if (IS_ERR(v9ses->clnt)) {
254 retval = PTR_ERR(v9ses->clnt);
255 v9ses->clnt = NULL;
256 P9_DPRINTK(P9_DEBUG_ERROR, "problem initializing 9p client\n");
257 goto error;
9e82cf6a
EVH
258 }
259
bd238fb4
LI
260 fid = p9_client_attach(v9ses->clnt, NULL, v9ses->name,
261 v9ses->remotename);
262 if (IS_ERR(fid)) {
263 retval = PTR_ERR(fid);
264 fid = NULL;
265 P9_DPRINTK(P9_DEBUG_ERROR, "cannot attach\n");
266 goto error;
9e82cf6a
EVH
267 }
268
bd238fb4 269 return fid;
9e82cf6a 270
bd238fb4 271error:
9e82cf6a 272 v9fs_session_close(v9ses);
bd238fb4 273 return ERR_PTR(retval);
9e82cf6a
EVH
274}
275
276/**
277 * v9fs_session_close - shutdown a session
278 * @v9ses: session information structure
279 *
280 */
281
282void v9fs_session_close(struct v9fs_session_info *v9ses)
283{
bd238fb4
LI
284 if (v9ses->clnt) {
285 p9_client_destroy(v9ses->clnt);
286 v9ses->clnt = NULL;
3cf6429a 287 }
9e82cf6a 288
ce44eeb6
DA
289 __putname(v9ses->name);
290 __putname(v9ses->remotename);
9e82cf6a
EVH
291}
292
322b329a
EVH
293/**
294 * v9fs_session_cancel - mark transport as disconnected
295 * and cancel all pending requests.
296 */
297void v9fs_session_cancel(struct v9fs_session_info *v9ses) {
bd238fb4
LI
298 P9_DPRINTK(P9_DEBUG_ERROR, "cancel session %p\n", v9ses);
299 p9_client_disconnect(v9ses->clnt);
322b329a
EVH
300}
301
9e82cf6a
EVH
302extern int v9fs_error_init(void);
303
304/**
305 * v9fs_init - Initialize module
306 *
307 */
308
309static int __init init_v9fs(void)
310{
f94b3470 311 printk(KERN_INFO "Installing v9fs 9p2000 file system support\n");
9e82cf6a 312
bd238fb4 313 return register_filesystem(&v9fs_fs_type);
9e82cf6a
EVH
314}
315
316/**
317 * v9fs_init - shutdown module
318 *
319 */
320
321static void __exit exit_v9fs(void)
322{
323 unregister_filesystem(&v9fs_fs_type);
324}
325
326module_init(init_v9fs)
327module_exit(exit_v9fs)
328
bd238fb4 329MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>");
9e82cf6a
EVH
330MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>");
331MODULE_AUTHOR("Ron Minnich <rminnich@lanl.gov>");
332MODULE_LICENSE("GPL");
This page took 0.203435 seconds and 5 git commands to generate.