aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorLatchesar Ionkov <lucho@ionkov.net>2007-07-10 18:57:28 -0400
committerEric Van Hensbergen <ericvh@ericvh-desktop.austin.ibm.com>2007-07-14 16:13:40 -0400
commitbd238fb431f31989898423c8b6496bc8c4204a86 (patch)
treef85a536383cbf360125ecb0592f6c515e0ecf0ff /include
parent8d9107e8c50e1c4ff43c91c8841805833f3ecfb9 (diff)
9p: Reorganization of 9p file system code
This patchset moves non-filesystem interfaces of v9fs from fs/9p to net/9p. It moves the transport, packet marshalling and connection layers to net/9p leaving only the VFS related files in fs/9p. This work is being done in preparation for in-kernel 9p servers as well as alternate 9p clients (other than VFS). Signed-off-by: Latchesar Ionkov <lucho@ionkov.net> Signed-off-by: Eric Van Hensbergen <ericvh@gmail.com>
Diffstat (limited to 'include')
-rw-r--r--include/net/9p/9p.h417
-rw-r--r--include/net/9p/client.h80
-rw-r--r--include/net/9p/conn.h57
-rw-r--r--include/net/9p/transport.h49
4 files changed, 603 insertions, 0 deletions
diff --git a/include/net/9p/9p.h b/include/net/9p/9p.h
new file mode 100644
index 000000000000..88884d39f28f
--- /dev/null
+++ b/include/net/9p/9p.h
@@ -0,0 +1,417 @@
1/*
2 * include/net/9p/9p.h
3 *
4 * 9P protocol definitions.
5 *
6 * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
7 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
8 * Copyright (C) 2002 by Ron Minnich <rminnich@lanl.gov>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to:
21 * Free Software Foundation
22 * 51 Franklin Street, Fifth Floor
23 * Boston, MA 02111-1301 USA
24 *
25 */
26
27#ifndef NET_9P_H
28#define NET_9P_H
29
30#ifdef CONFIG_NET_9P_DEBUG
31
32#define P9_DEBUG_ERROR (1<<0)
33#define P9_DEBUG_9P (1<<2)
34#define P9_DEBUG_VFS (1<<3)
35#define P9_DEBUG_CONV (1<<4)
36#define P9_DEBUG_MUX (1<<5)
37#define P9_DEBUG_TRANS (1<<6)
38#define P9_DEBUG_SLABS (1<<7)
39#define P9_DEBUG_FCALL (1<<8)
40
41extern unsigned int p9_debug_level;
42
43#define P9_DPRINTK(level, format, arg...) \
44do { \
45 if ((p9_debug_level & level) == level) \
46 printk(KERN_NOTICE "-- %s (%d): " \
47 format , __FUNCTION__, current->pid , ## arg); \
48} while (0)
49
50#define PRINT_FCALL_ERROR(s, fcall) P9_DPRINTK(P9_DEBUG_ERROR, \
51 "%s: %.*s\n", s, fcall?fcall->params.rerror.error.len:0, \
52 fcall?fcall->params.rerror.error.str:"");
53
54#else
55#define P9_DPRINTK(level, format, arg...) do { } while (0)
56#define PRINT_FCALL_ERROR(s, fcall) do { } while (0)
57#endif
58
59#define P9_EPRINTK(level, format, arg...) \
60do { \
61 printk(level "9p: %s (%d): " \
62 format , __FUNCTION__, current->pid , ## arg); \
63} while (0)
64
65
66/* Message Types */
67enum {
68 P9_TVERSION = 100,
69 P9_RVERSION,
70 P9_TAUTH = 102,
71 P9_RAUTH,
72 P9_TATTACH = 104,
73 P9_RATTACH,
74 P9_TERROR = 106,
75 P9_RERROR,
76 P9_TFLUSH = 108,
77 P9_RFLUSH,
78 P9_TWALK = 110,
79 P9_RWALK,
80 P9_TOPEN = 112,
81 P9_ROPEN,
82 P9_TCREATE = 114,
83 P9_RCREATE,
84 P9_TREAD = 116,
85 P9_RREAD,
86 P9_TWRITE = 118,
87 P9_RWRITE,
88 P9_TCLUNK = 120,
89 P9_RCLUNK,
90 P9_TREMOVE = 122,
91 P9_RREMOVE,
92 P9_TSTAT = 124,
93 P9_RSTAT,
94 P9_TWSTAT = 126,
95 P9_RWSTAT,
96};
97
98/* open modes */
99enum {
100 P9_OREAD = 0x00,
101 P9_OWRITE = 0x01,
102 P9_ORDWR = 0x02,
103 P9_OEXEC = 0x03,
104 P9_OEXCL = 0x04,
105 P9_OTRUNC = 0x10,
106 P9_OREXEC = 0x20,
107 P9_ORCLOSE = 0x40,
108 P9_OAPPEND = 0x80,
109};
110
111/* permissions */
112enum {
113 P9_DMDIR = 0x80000000,
114 P9_DMAPPEND = 0x40000000,
115 P9_DMEXCL = 0x20000000,
116 P9_DMMOUNT = 0x10000000,
117 P9_DMAUTH = 0x08000000,
118 P9_DMTMP = 0x04000000,
119 P9_DMSYMLINK = 0x02000000,
120 P9_DMLINK = 0x01000000,
121 /* 9P2000.u extensions */
122 P9_DMDEVICE = 0x00800000,
123 P9_DMNAMEDPIPE = 0x00200000,
124 P9_DMSOCKET = 0x00100000,
125 P9_DMSETUID = 0x00080000,
126 P9_DMSETGID = 0x00040000,
127};
128
129/* qid.types */
130enum {
131 P9_QTDIR = 0x80,
132 P9_QTAPPEND = 0x40,
133 P9_QTEXCL = 0x20,
134 P9_QTMOUNT = 0x10,
135 P9_QTAUTH = 0x08,
136 P9_QTTMP = 0x04,
137 P9_QTSYMLINK = 0x02,
138 P9_QTLINK = 0x01,
139 P9_QTFILE = 0x00,
140};
141
142#define P9_NOTAG (u16)(~0)
143#define P9_NOFID (u32)(~0)
144#define P9_MAXWELEM 16
145
146/* ample room for Twrite/Rread header */
147#define P9_IOHDRSZ 24
148
149struct p9_str {
150 u16 len;
151 char *str;
152};
153
154/* qids are the unique ID for a file (like an inode */
155struct p9_qid {
156 u8 type;
157 u32 version;
158 u64 path;
159};
160
161/* Plan 9 file metadata (stat) structure */
162struct p9_stat {
163 u16 size;
164 u16 type;
165 u32 dev;
166 struct p9_qid qid;
167 u32 mode;
168 u32 atime;
169 u32 mtime;
170 u64 length;
171 struct p9_str name;
172 struct p9_str uid;
173 struct p9_str gid;
174 struct p9_str muid;
175 struct p9_str extension; /* 9p2000.u extensions */
176 u32 n_uid; /* 9p2000.u extensions */
177 u32 n_gid; /* 9p2000.u extensions */
178 u32 n_muid; /* 9p2000.u extensions */
179};
180
181/* file metadata (stat) structure used to create Twstat message
182 The is similar to p9_stat, but the strings don't point to
183 the same memory block and should be freed separately
184*/
185struct p9_wstat {
186 u16 size;
187 u16 type;
188 u32 dev;
189 struct p9_qid qid;
190 u32 mode;
191 u32 atime;
192 u32 mtime;
193 u64 length;
194 char *name;
195 char *uid;
196 char *gid;
197 char *muid;
198 char *extension; /* 9p2000.u extensions */
199 u32 n_uid; /* 9p2000.u extensions */
200 u32 n_gid; /* 9p2000.u extensions */
201 u32 n_muid; /* 9p2000.u extensions */
202};
203
204/* Structures for Protocol Operations */
205struct p9_tversion {
206 u32 msize;
207 struct p9_str version;
208};
209
210struct p9_rversion {
211 u32 msize;
212 struct p9_str version;
213};
214
215struct p9_tauth {
216 u32 afid;
217 struct p9_str uname;
218 struct p9_str aname;
219};
220
221struct p9_rauth {
222 struct p9_qid qid;
223};
224
225struct p9_rerror {
226 struct p9_str error;
227 u32 errno; /* 9p2000.u extension */
228};
229
230struct p9_tflush {
231 u16 oldtag;
232};
233
234struct p9_rflush {
235};
236
237struct p9_tattach {
238 u32 fid;
239 u32 afid;
240 struct p9_str uname;
241 struct p9_str aname;
242};
243
244struct p9_rattach {
245 struct p9_qid qid;
246};
247
248struct p9_twalk {
249 u32 fid;
250 u32 newfid;
251 u16 nwname;
252 struct p9_str wnames[16];
253};
254
255struct p9_rwalk {
256 u16 nwqid;
257 struct p9_qid wqids[16];
258};
259
260struct p9_topen {
261 u32 fid;
262 u8 mode;
263};
264
265struct p9_ropen {
266 struct p9_qid qid;
267 u32 iounit;
268};
269
270struct p9_tcreate {
271 u32 fid;
272 struct p9_str name;
273 u32 perm;
274 u8 mode;
275 struct p9_str extension;
276};
277
278struct p9_rcreate {
279 struct p9_qid qid;
280 u32 iounit;
281};
282
283struct p9_tread {
284 u32 fid;
285 u64 offset;
286 u32 count;
287};
288
289struct p9_rread {
290 u32 count;
291 u8 *data;
292};
293
294struct p9_twrite {
295 u32 fid;
296 u64 offset;
297 u32 count;
298 u8 *data;
299};
300
301struct p9_rwrite {
302 u32 count;
303};
304
305struct p9_tclunk {
306 u32 fid;
307};
308
309struct p9_rclunk {
310};
311
312struct p9_tremove {
313 u32 fid;
314};
315
316struct p9_rremove {
317};
318
319struct p9_tstat {
320 u32 fid;
321};
322
323struct p9_rstat {
324 struct p9_stat stat;
325};
326
327struct p9_twstat {
328 u32 fid;
329 struct p9_stat stat;
330};
331
332struct p9_rwstat {
333};
334
335/*
336 * fcall is the primary packet structure
337 *
338 */
339
340struct p9_fcall {
341 u32 size;
342 u8 id;
343 u16 tag;
344 void *sdata;
345
346 union {
347 struct p9_tversion tversion;
348 struct p9_rversion rversion;
349 struct p9_tauth tauth;
350 struct p9_rauth rauth;
351 struct p9_rerror rerror;
352 struct p9_tflush tflush;
353 struct p9_rflush rflush;
354 struct p9_tattach tattach;
355 struct p9_rattach rattach;
356 struct p9_twalk twalk;
357 struct p9_rwalk rwalk;
358 struct p9_topen topen;
359 struct p9_ropen ropen;
360 struct p9_tcreate tcreate;
361 struct p9_rcreate rcreate;
362 struct p9_tread tread;
363 struct p9_rread rread;
364 struct p9_twrite twrite;
365 struct p9_rwrite rwrite;
366 struct p9_tclunk tclunk;
367 struct p9_rclunk rclunk;
368 struct p9_tremove tremove;
369 struct p9_rremove rremove;
370 struct p9_tstat tstat;
371 struct p9_rstat rstat;
372 struct p9_twstat twstat;
373 struct p9_rwstat rwstat;
374 } params;
375};
376
377struct p9_idpool;
378
379int p9_deserialize_stat(void *buf, u32 buflen, struct p9_stat *stat,
380 int dotu);
381int p9_deserialize_fcall(void *buf, u32 buflen, struct p9_fcall *fc, int dotu);
382void p9_set_tag(struct p9_fcall *fc, u16 tag);
383struct p9_fcall *p9_create_tversion(u32 msize, char *version);
384struct p9_fcall *p9_create_tattach(u32 fid, u32 afid, char *uname,
385 char *aname);
386struct p9_fcall *p9_create_tauth(u32 afid, char *uname, char *aname);
387struct p9_fcall *p9_create_tflush(u16 oldtag);
388struct p9_fcall *p9_create_twalk(u32 fid, u32 newfid, u16 nwname,
389 char **wnames);
390struct p9_fcall *p9_create_topen(u32 fid, u8 mode);
391struct p9_fcall *p9_create_tcreate(u32 fid, char *name, u32 perm, u8 mode,
392 char *extension, int dotu);
393struct p9_fcall *p9_create_tread(u32 fid, u64 offset, u32 count);
394struct p9_fcall *p9_create_twrite(u32 fid, u64 offset, u32 count,
395 const char *data);
396struct p9_fcall *p9_create_twrite_u(u32 fid, u64 offset, u32 count,
397 const char __user *data);
398struct p9_fcall *p9_create_tclunk(u32 fid);
399struct p9_fcall *p9_create_tremove(u32 fid);
400struct p9_fcall *p9_create_tstat(u32 fid);
401struct p9_fcall *p9_create_twstat(u32 fid, struct p9_wstat *wstat,
402 int dotu);
403
404int p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int dotu);
405int p9_errstr2errno(char *errstr, int len);
406
407struct p9_idpool *p9_idpool_create(void);
408void p9_idpool_destroy(struct p9_idpool *);
409int p9_idpool_get(struct p9_idpool *p);
410void p9_idpool_put(int id, struct p9_idpool *p);
411int p9_idpool_check(int id, struct p9_idpool *p);
412
413int p9_error_init(void);
414int p9_errstr2errno(char *, int);
415int __init p9_sysctl_register(void);
416void __exit p9_sysctl_unregister(void);
417#endif /* NET_9P_H */
diff --git a/include/net/9p/client.h b/include/net/9p/client.h
new file mode 100644
index 000000000000..d65ed7c69063
--- /dev/null
+++ b/include/net/9p/client.h
@@ -0,0 +1,80 @@
1/*
2 * include/net/9p/client.h
3 *
4 * 9P Client Definitions
5 *
6 * Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to:
19 * Free Software Foundation
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02111-1301 USA
22 *
23 */
24
25#ifndef NET_9P_CLIENT_H
26#define NET_9P_CLIENT_H
27
28struct p9_client {
29 spinlock_t lock; /* protect client structure */
30 int msize;
31 unsigned char dotu;
32 struct p9_transport *trans;
33 struct p9_conn *conn;
34
35 struct p9_idpool *fidpool;
36 struct list_head fidlist;
37};
38
39struct p9_fid {
40 struct p9_client *clnt;
41 u32 fid;
42 int mode;
43 struct p9_qid qid;
44 u32 iounit;
45 uid_t uid;
46 void *aux;
47
48 int rdir_fpos;
49 int rdir_pos;
50 struct p9_fcall *rdir_fcall;
51 struct list_head flist;
52 struct list_head dlist; /* list of all fids attached to a dentry */
53};
54
55struct p9_client *p9_client_create(struct p9_transport *trans, int msize,
56 int dotu);
57void p9_client_destroy(struct p9_client *clnt);
58void p9_client_disconnect(struct p9_client *clnt);
59struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid,
60 char *uname, char *aname);
61struct p9_fid *p9_client_auth(struct p9_client *clnt, char *uname, char *aname);
62struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames,
63 int clone);
64int p9_client_open(struct p9_fid *fid, int mode);
65int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode,
66 char *extension);
67int p9_client_clunk(struct p9_fid *fid);
68int p9_client_remove(struct p9_fid *fid);
69int p9_client_read(struct p9_fid *fid, char *data, u64 offset, u32 count);
70int p9_client_readn(struct p9_fid *fid, char *data, u64 offset, u32 count);
71int p9_client_write(struct p9_fid *fid, char *data, u64 offset, u32 count);
72int p9_client_uread(struct p9_fid *fid, char __user *data, u64 offset,
73 u32 count);
74int p9_client_uwrite(struct p9_fid *fid, const char __user *data, u64 offset,
75 u32 count);
76struct p9_stat *p9_client_stat(struct p9_fid *fid);
77int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst);
78struct p9_stat *p9_client_dirread(struct p9_fid *fid, u64 offset);
79
80#endif /* NET_9P_CLIENT_H */
diff --git a/include/net/9p/conn.h b/include/net/9p/conn.h
new file mode 100644
index 000000000000..583b6a2cb3df
--- /dev/null
+++ b/include/net/9p/conn.h
@@ -0,0 +1,57 @@
1/*
2 * include/net/9p/conn.h
3 *
4 * Connection Definitions
5 *
6 * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
7 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
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
26#ifndef NET_9P_CONN_H
27#define NET_9P_CONN_H
28
29#undef P9_NONBLOCK
30
31struct p9_conn;
32struct p9_req;
33
34/**
35 * p9_mux_req_callback - callback function that is called when the
36 * response of a request is received. The callback is called from
37 * a workqueue and shouldn't block.
38 *
39 * @req - request
40 * @a - the pointer that was specified when the request was send to be
41 * passed to the callback
42 */
43typedef void (*p9_conn_req_callback)(struct p9_req *req, void *a);
44
45struct p9_conn *p9_conn_create(struct p9_transport *trans, int msize,
46 unsigned char *dotu);
47void p9_conn_destroy(struct p9_conn *);
48int p9_conn_rpc(struct p9_conn *m, struct p9_fcall *tc, struct p9_fcall **rc);
49
50#ifdef P9_NONBLOCK
51int p9_conn_rpcnb(struct p9_conn *m, struct p9_fcall *tc,
52 p9_conn_req_callback cb, void *a);
53#endif /* P9_NONBLOCK */
54
55void p9_conn_cancel(struct p9_conn *m, int err);
56
57#endif /* NET_9P_CONN_H */
diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
new file mode 100644
index 000000000000..462d42279fb0
--- /dev/null
+++ b/include/net/9p/transport.h
@@ -0,0 +1,49 @@
1/*
2 * include/net/9p/transport.h
3 *
4 * Transport Definition
5 *
6 * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
7 * Copyright (C) 2004 by Eric Van Hensbergen <ericvh@gmail.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2
11 * as published by the Free Software Foundation.
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
26#ifndef NET_9P_TRANSPORT_H
27#define NET_9P_TRANSPORT_H
28
29enum p9_transport_status {
30 Connected,
31 Disconnected,
32 Hung,
33};
34
35struct p9_transport {
36 enum p9_transport_status status;
37 void *priv;
38
39 int (*write) (struct p9_transport *, void *, int);
40 int (*read) (struct p9_transport *, void *, int);
41 void (*close) (struct p9_transport *);
42 unsigned int (*poll)(struct p9_transport *, struct poll_table_struct *);
43};
44
45struct p9_transport *p9_trans_create_tcp(const char *addr, int port);
46struct p9_transport *p9_trans_create_unix(const char *addr);
47struct p9_transport *p9_trans_create_fd(int rfd, int wfd);
48
49#endif /* NET_9P_TRANSPORT_H */