diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/9p/Kconfig | 10 | ||||
-rw-r--r-- | net/9p/Makefile | 5 | ||||
-rw-r--r-- | net/9p/client.c | 13 | ||||
-rw-r--r-- | net/9p/conv.c | 32 | ||||
-rw-r--r-- | net/9p/mod.c | 71 | ||||
-rw-r--r-- | net/9p/mux.c | 5 | ||||
-rw-r--r-- | net/9p/sysctl.c | 81 | ||||
-rw-r--r-- | net/9p/trans_fd.c | 419 |
8 files changed, 378 insertions, 258 deletions
diff --git a/net/9p/Kconfig b/net/9p/Kconfig index 66821cd64a76..eecbf12f6393 100644 --- a/net/9p/Kconfig +++ b/net/9p/Kconfig | |||
@@ -13,6 +13,16 @@ menuconfig NET_9P | |||
13 | 13 | ||
14 | If unsure, say N. | 14 | If unsure, say N. |
15 | 15 | ||
16 | config NET_9P_FD | ||
17 | depends on NET_9P | ||
18 | default y if NET_9P | ||
19 | tristate "9P File Descriptor Transports (Experimental)" | ||
20 | help | ||
21 | This builds support for file descriptor transports for 9p | ||
22 | which includes support for TCP/IP, named pipes, or passed | ||
23 | file descriptors. TCP/IP is the default transport for 9p, | ||
24 | so if you are going to use 9p, you'll likely want this. | ||
25 | |||
16 | config NET_9P_DEBUG | 26 | config NET_9P_DEBUG |
17 | bool "Debug information" | 27 | bool "Debug information" |
18 | depends on NET_9P | 28 | depends on NET_9P |
diff --git a/net/9p/Makefile b/net/9p/Makefile index 85b3a7838acf..5059bc06f8f3 100644 --- a/net/9p/Makefile +++ b/net/9p/Makefile | |||
@@ -1,8 +1,8 @@ | |||
1 | obj-$(CONFIG_NET_9P) := 9pnet.o | 1 | obj-$(CONFIG_NET_9P) := 9pnet.o |
2 | obj-$(CONFIG_NET_9P_FD) += 9pnet_fd.o | ||
2 | 3 | ||
3 | 9pnet-objs := \ | 4 | 9pnet-objs := \ |
4 | mod.o \ | 5 | mod.o \ |
5 | trans_fd.o \ | ||
6 | mux.o \ | 6 | mux.o \ |
7 | client.o \ | 7 | client.o \ |
8 | conv.o \ | 8 | conv.o \ |
@@ -10,4 +10,5 @@ obj-$(CONFIG_NET_9P) := 9pnet.o | |||
10 | fcprint.o \ | 10 | fcprint.o \ |
11 | util.o \ | 11 | util.o \ |
12 | 12 | ||
13 | 9pnet-$(CONFIG_SYSCTL) += sysctl.o | 13 | 9pnet_fd-objs := \ |
14 | trans_fd.o \ | ||
diff --git a/net/9p/client.c b/net/9p/client.c index cb170750337c..af9199364049 100644 --- a/net/9p/client.c +++ b/net/9p/client.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/sched.h> | 30 | #include <linux/sched.h> |
31 | #include <linux/uaccess.h> | 31 | #include <linux/uaccess.h> |
32 | #include <net/9p/9p.h> | 32 | #include <net/9p/9p.h> |
33 | #include <linux/parser.h> | ||
33 | #include <net/9p/transport.h> | 34 | #include <net/9p/transport.h> |
34 | #include <net/9p/conn.h> | 35 | #include <net/9p/conn.h> |
35 | #include <net/9p/client.h> | 36 | #include <net/9p/client.h> |
@@ -38,7 +39,7 @@ static struct p9_fid *p9_fid_create(struct p9_client *clnt); | |||
38 | static void p9_fid_destroy(struct p9_fid *fid); | 39 | static void p9_fid_destroy(struct p9_fid *fid); |
39 | static struct p9_stat *p9_clone_stat(struct p9_stat *st, int dotu); | 40 | static struct p9_stat *p9_clone_stat(struct p9_stat *st, int dotu); |
40 | 41 | ||
41 | struct p9_client *p9_client_create(struct p9_transport *trans, int msize, | 42 | struct p9_client *p9_client_create(struct p9_trans *trans, int msize, |
42 | int dotu) | 43 | int dotu) |
43 | { | 44 | { |
44 | int err, n; | 45 | int err, n; |
@@ -146,7 +147,7 @@ void p9_client_disconnect(struct p9_client *clnt) | |||
146 | EXPORT_SYMBOL(p9_client_disconnect); | 147 | EXPORT_SYMBOL(p9_client_disconnect); |
147 | 148 | ||
148 | struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, | 149 | struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, |
149 | char *uname, char *aname) | 150 | char *uname, u32 n_uname, char *aname) |
150 | { | 151 | { |
151 | int err; | 152 | int err; |
152 | struct p9_fcall *tc, *rc; | 153 | struct p9_fcall *tc, *rc; |
@@ -165,7 +166,8 @@ struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, | |||
165 | goto error; | 166 | goto error; |
166 | } | 167 | } |
167 | 168 | ||
168 | tc = p9_create_tattach(fid->fid, afid?afid->fid:P9_NOFID, uname, aname); | 169 | tc = p9_create_tattach(fid->fid, afid?afid->fid:P9_NOFID, uname, aname, |
170 | n_uname, clnt->dotu); | ||
169 | if (IS_ERR(tc)) { | 171 | if (IS_ERR(tc)) { |
170 | err = PTR_ERR(tc); | 172 | err = PTR_ERR(tc); |
171 | tc = NULL; | 173 | tc = NULL; |
@@ -190,7 +192,8 @@ error: | |||
190 | } | 192 | } |
191 | EXPORT_SYMBOL(p9_client_attach); | 193 | EXPORT_SYMBOL(p9_client_attach); |
192 | 194 | ||
193 | struct p9_fid *p9_client_auth(struct p9_client *clnt, char *uname, char *aname) | 195 | struct p9_fid *p9_client_auth(struct p9_client *clnt, char *uname, |
196 | u32 n_uname, char *aname) | ||
194 | { | 197 | { |
195 | int err; | 198 | int err; |
196 | struct p9_fcall *tc, *rc; | 199 | struct p9_fcall *tc, *rc; |
@@ -209,7 +212,7 @@ struct p9_fid *p9_client_auth(struct p9_client *clnt, char *uname, char *aname) | |||
209 | goto error; | 212 | goto error; |
210 | } | 213 | } |
211 | 214 | ||
212 | tc = p9_create_tauth(fid->fid, uname, aname); | 215 | tc = p9_create_tauth(fid->fid, uname, aname, n_uname, clnt->dotu); |
213 | if (IS_ERR(tc)) { | 216 | if (IS_ERR(tc)) { |
214 | err = PTR_ERR(tc); | 217 | err = PTR_ERR(tc); |
215 | tc = NULL; | 218 | tc = NULL; |
diff --git a/net/9p/conv.c b/net/9p/conv.c index d979d958ea19..aa2aa9884f95 100644 --- a/net/9p/conv.c +++ b/net/9p/conv.c | |||
@@ -547,7 +547,8 @@ error: | |||
547 | } | 547 | } |
548 | EXPORT_SYMBOL(p9_create_tversion); | 548 | EXPORT_SYMBOL(p9_create_tversion); |
549 | 549 | ||
550 | struct p9_fcall *p9_create_tauth(u32 afid, char *uname, char *aname) | 550 | struct p9_fcall *p9_create_tauth(u32 afid, char *uname, char *aname, |
551 | u32 n_uname, int dotu) | ||
551 | { | 552 | { |
552 | int size; | 553 | int size; |
553 | struct p9_fcall *fc; | 554 | struct p9_fcall *fc; |
@@ -555,7 +556,16 @@ struct p9_fcall *p9_create_tauth(u32 afid, char *uname, char *aname) | |||
555 | struct cbuf *bufp = &buffer; | 556 | struct cbuf *bufp = &buffer; |
556 | 557 | ||
557 | /* afid[4] uname[s] aname[s] */ | 558 | /* afid[4] uname[s] aname[s] */ |
558 | size = 4 + 2 + strlen(uname) + 2 + strlen(aname); | 559 | size = 4 + 2 + 2; |
560 | if (uname) | ||
561 | size += strlen(uname); | ||
562 | |||
563 | if (aname) | ||
564 | size += strlen(aname); | ||
565 | |||
566 | if (dotu) | ||
567 | size += 4; /* n_uname */ | ||
568 | |||
559 | fc = p9_create_common(bufp, size, P9_TAUTH); | 569 | fc = p9_create_common(bufp, size, P9_TAUTH); |
560 | if (IS_ERR(fc)) | 570 | if (IS_ERR(fc)) |
561 | goto error; | 571 | goto error; |
@@ -563,6 +573,8 @@ struct p9_fcall *p9_create_tauth(u32 afid, char *uname, char *aname) | |||
563 | p9_put_int32(bufp, afid, &fc->params.tauth.afid); | 573 | p9_put_int32(bufp, afid, &fc->params.tauth.afid); |
564 | p9_put_str(bufp, uname, &fc->params.tauth.uname); | 574 | p9_put_str(bufp, uname, &fc->params.tauth.uname); |
565 | p9_put_str(bufp, aname, &fc->params.tauth.aname); | 575 | p9_put_str(bufp, aname, &fc->params.tauth.aname); |
576 | if (dotu) | ||
577 | p9_put_int32(bufp, n_uname, &fc->params.tauth.n_uname); | ||
566 | 578 | ||
567 | if (buf_check_overflow(bufp)) { | 579 | if (buf_check_overflow(bufp)) { |
568 | kfree(fc); | 580 | kfree(fc); |
@@ -574,7 +586,8 @@ error: | |||
574 | EXPORT_SYMBOL(p9_create_tauth); | 586 | EXPORT_SYMBOL(p9_create_tauth); |
575 | 587 | ||
576 | struct p9_fcall * | 588 | struct p9_fcall * |
577 | p9_create_tattach(u32 fid, u32 afid, char *uname, char *aname) | 589 | p9_create_tattach(u32 fid, u32 afid, char *uname, char *aname, |
590 | u32 n_uname, int dotu) | ||
578 | { | 591 | { |
579 | int size; | 592 | int size; |
580 | struct p9_fcall *fc; | 593 | struct p9_fcall *fc; |
@@ -582,7 +595,16 @@ p9_create_tattach(u32 fid, u32 afid, char *uname, char *aname) | |||
582 | struct cbuf *bufp = &buffer; | 595 | struct cbuf *bufp = &buffer; |
583 | 596 | ||
584 | /* fid[4] afid[4] uname[s] aname[s] */ | 597 | /* fid[4] afid[4] uname[s] aname[s] */ |
585 | size = 4 + 4 + 2 + strlen(uname) + 2 + strlen(aname); | 598 | size = 4 + 4 + 2 + 2; |
599 | if (uname) | ||
600 | size += strlen(uname); | ||
601 | |||
602 | if (aname) | ||
603 | size += strlen(aname); | ||
604 | |||
605 | if (dotu) | ||
606 | size += 4; /* n_uname */ | ||
607 | |||
586 | fc = p9_create_common(bufp, size, P9_TATTACH); | 608 | fc = p9_create_common(bufp, size, P9_TATTACH); |
587 | if (IS_ERR(fc)) | 609 | if (IS_ERR(fc)) |
588 | goto error; | 610 | goto error; |
@@ -591,6 +613,8 @@ p9_create_tattach(u32 fid, u32 afid, char *uname, char *aname) | |||
591 | p9_put_int32(bufp, afid, &fc->params.tattach.afid); | 613 | p9_put_int32(bufp, afid, &fc->params.tattach.afid); |
592 | p9_put_str(bufp, uname, &fc->params.tattach.uname); | 614 | p9_put_str(bufp, uname, &fc->params.tattach.uname); |
593 | p9_put_str(bufp, aname, &fc->params.tattach.aname); | 615 | p9_put_str(bufp, aname, &fc->params.tattach.aname); |
616 | if (dotu) | ||
617 | p9_put_int32(bufp, n_uname, &fc->params.tattach.n_uname); | ||
594 | 618 | ||
595 | error: | 619 | error: |
596 | return fc; | 620 | return fc; |
diff --git a/net/9p/mod.c b/net/9p/mod.c index 4f9e1d2ac257..41d70f47375d 100644 --- a/net/9p/mod.c +++ b/net/9p/mod.c | |||
@@ -27,6 +27,10 @@ | |||
27 | #include <linux/module.h> | 27 | #include <linux/module.h> |
28 | #include <linux/moduleparam.h> | 28 | #include <linux/moduleparam.h> |
29 | #include <net/9p/9p.h> | 29 | #include <net/9p/9p.h> |
30 | #include <linux/fs.h> | ||
31 | #include <linux/parser.h> | ||
32 | #include <net/9p/transport.h> | ||
33 | #include <linux/list.h> | ||
30 | 34 | ||
31 | #ifdef CONFIG_NET_9P_DEBUG | 35 | #ifdef CONFIG_NET_9P_DEBUG |
32 | unsigned int p9_debug_level = 0; /* feature-rific global debug level */ | 36 | unsigned int p9_debug_level = 0; /* feature-rific global debug level */ |
@@ -37,8 +41,64 @@ MODULE_PARM_DESC(debug, "9P debugging level"); | |||
37 | 41 | ||
38 | extern int p9_mux_global_init(void); | 42 | extern int p9_mux_global_init(void); |
39 | extern void p9_mux_global_exit(void); | 43 | extern void p9_mux_global_exit(void); |
40 | extern int p9_sysctl_register(void); | 44 | |
41 | extern void p9_sysctl_unregister(void); | 45 | /* |
46 | * Dynamic Transport Registration Routines | ||
47 | * | ||
48 | */ | ||
49 | |||
50 | static LIST_HEAD(v9fs_trans_list); | ||
51 | static struct p9_trans_module *v9fs_default_transport; | ||
52 | |||
53 | /** | ||
54 | * v9fs_register_trans - register a new transport with 9p | ||
55 | * @m - structure describing the transport module and entry points | ||
56 | * | ||
57 | */ | ||
58 | void v9fs_register_trans(struct p9_trans_module *m) | ||
59 | { | ||
60 | list_add_tail(&m->list, &v9fs_trans_list); | ||
61 | if (m->def) | ||
62 | v9fs_default_transport = m; | ||
63 | } | ||
64 | EXPORT_SYMBOL(v9fs_register_trans); | ||
65 | |||
66 | /** | ||
67 | * v9fs_match_trans - match transport versus registered transports | ||
68 | * @arg: string identifying transport | ||
69 | * | ||
70 | */ | ||
71 | struct p9_trans_module *v9fs_match_trans(const substring_t *name) | ||
72 | { | ||
73 | struct list_head *p; | ||
74 | struct p9_trans_module *t = NULL; | ||
75 | |||
76 | list_for_each(p, &v9fs_trans_list) { | ||
77 | t = list_entry(p, struct p9_trans_module, list); | ||
78 | if (strncmp(t->name, name->from, name->to-name->from) == 0) | ||
79 | break; | ||
80 | } | ||
81 | return t; | ||
82 | } | ||
83 | EXPORT_SYMBOL(v9fs_match_trans); | ||
84 | |||
85 | /** | ||
86 | * v9fs_default_trans - returns pointer to default transport | ||
87 | * | ||
88 | */ | ||
89 | |||
90 | struct p9_trans_module *v9fs_default_trans(void) | ||
91 | { | ||
92 | if (v9fs_default_transport) | ||
93 | return v9fs_default_transport; | ||
94 | else if (!list_empty(&v9fs_trans_list)) | ||
95 | return list_first_entry(&v9fs_trans_list, | ||
96 | struct p9_trans_module, list); | ||
97 | else | ||
98 | return NULL; | ||
99 | } | ||
100 | EXPORT_SYMBOL(v9fs_default_trans); | ||
101 | |||
42 | 102 | ||
43 | /** | 103 | /** |
44 | * v9fs_init - Initialize module | 104 | * v9fs_init - Initialize module |
@@ -56,12 +116,6 @@ static int __init init_p9(void) | |||
56 | return ret; | 116 | return ret; |
57 | } | 117 | } |
58 | 118 | ||
59 | ret = p9_sysctl_register(); | ||
60 | if (ret) { | ||
61 | printk(KERN_WARNING "9p: registering sysctl failed\n"); | ||
62 | return ret; | ||
63 | } | ||
64 | |||
65 | return ret; | 119 | return ret; |
66 | } | 120 | } |
67 | 121 | ||
@@ -72,7 +126,6 @@ static int __init init_p9(void) | |||
72 | 126 | ||
73 | static void __exit exit_p9(void) | 127 | static void __exit exit_p9(void) |
74 | { | 128 | { |
75 | p9_sysctl_unregister(); | ||
76 | p9_mux_global_exit(); | 129 | p9_mux_global_exit(); |
77 | } | 130 | } |
78 | 131 | ||
diff --git a/net/9p/mux.c b/net/9p/mux.c index 5d70558c4c61..f14014793bed 100644 --- a/net/9p/mux.c +++ b/net/9p/mux.c | |||
@@ -31,6 +31,7 @@ | |||
31 | #include <linux/idr.h> | 31 | #include <linux/idr.h> |
32 | #include <linux/mutex.h> | 32 | #include <linux/mutex.h> |
33 | #include <net/9p/9p.h> | 33 | #include <net/9p/9p.h> |
34 | #include <linux/parser.h> | ||
34 | #include <net/9p/transport.h> | 35 | #include <net/9p/transport.h> |
35 | #include <net/9p/conn.h> | 36 | #include <net/9p/conn.h> |
36 | 37 | ||
@@ -71,7 +72,7 @@ struct p9_conn { | |||
71 | struct p9_mux_poll_task *poll_task; | 72 | struct p9_mux_poll_task *poll_task; |
72 | int msize; | 73 | int msize; |
73 | unsigned char *extended; | 74 | unsigned char *extended; |
74 | struct p9_transport *trans; | 75 | struct p9_trans *trans; |
75 | struct p9_idpool *tagpool; | 76 | struct p9_idpool *tagpool; |
76 | int err; | 77 | int err; |
77 | wait_queue_head_t equeue; | 78 | wait_queue_head_t equeue; |
@@ -271,7 +272,7 @@ static void p9_mux_poll_stop(struct p9_conn *m) | |||
271 | * @msize - maximum message size | 272 | * @msize - maximum message size |
272 | * @extended - pointer to the extended flag | 273 | * @extended - pointer to the extended flag |
273 | */ | 274 | */ |
274 | struct p9_conn *p9_conn_create(struct p9_transport *trans, int msize, | 275 | struct p9_conn *p9_conn_create(struct p9_trans *trans, int msize, |
275 | unsigned char *extended) | 276 | unsigned char *extended) |
276 | { | 277 | { |
277 | int i, n; | 278 | int i, n; |
diff --git a/net/9p/sysctl.c b/net/9p/sysctl.c deleted file mode 100644 index 8b61027a24ea..000000000000 --- a/net/9p/sysctl.c +++ /dev/null | |||
@@ -1,81 +0,0 @@ | |||
1 | /* | ||
2 | * net/9p/sysctl.c | ||
3 | * | ||
4 | * 9P sysctl interface | ||
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 | #include <linux/kernel.h> | ||
26 | #include <linux/mm.h> | ||
27 | #include <linux/sysctl.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <net/9p/9p.h> | ||
30 | |||
31 | static struct ctl_table p9_table[] = { | ||
32 | #ifdef CONFIG_NET_9P_DEBUG | ||
33 | { | ||
34 | .ctl_name = CTL_UNNUMBERED, | ||
35 | .procname = "debug", | ||
36 | .data = &p9_debug_level, | ||
37 | .maxlen = sizeof(int), | ||
38 | .mode = 0644, | ||
39 | .proc_handler = &proc_dointvec | ||
40 | }, | ||
41 | #endif | ||
42 | {}, | ||
43 | }; | ||
44 | |||
45 | static struct ctl_table p9_net_table[] = { | ||
46 | { | ||
47 | .ctl_name = CTL_UNNUMBERED, | ||
48 | .procname = "9p", | ||
49 | .maxlen = 0, | ||
50 | .mode = 0555, | ||
51 | .child = p9_table, | ||
52 | }, | ||
53 | {}, | ||
54 | }; | ||
55 | |||
56 | static struct ctl_table p9_ctl_table[] = { | ||
57 | { | ||
58 | .ctl_name = CTL_NET, | ||
59 | .procname = "net", | ||
60 | .maxlen = 0, | ||
61 | .mode = 0555, | ||
62 | .child = p9_net_table, | ||
63 | }, | ||
64 | {}, | ||
65 | }; | ||
66 | |||
67 | static struct ctl_table_header *p9_table_header; | ||
68 | |||
69 | int __init p9_sysctl_register(void) | ||
70 | { | ||
71 | p9_table_header = register_sysctl_table(p9_ctl_table); | ||
72 | if (!p9_table_header) | ||
73 | return -ENOMEM; | ||
74 | |||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | void __exit p9_sysctl_unregister(void) | ||
79 | { | ||
80 | unregister_sysctl_table(p9_table_header); | ||
81 | } | ||
diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c index fd636e94358f..30269a4ff22a 100644 --- a/net/9p/trans_fd.c +++ b/net/9p/trans_fd.c | |||
@@ -5,7 +5,7 @@ | |||
5 | * | 5 | * |
6 | * Copyright (C) 2006 by Russ Cox <rsc@swtch.com> | 6 | * Copyright (C) 2006 by Russ Cox <rsc@swtch.com> |
7 | * Copyright (C) 2004-2005 by Latchesar Ionkov <lucho@ionkov.net> | 7 | * Copyright (C) 2004-2005 by Latchesar Ionkov <lucho@ionkov.net> |
8 | * Copyright (C) 2004-2005 by Eric Van Hensbergen <ericvh@gmail.com> | 8 | * Copyright (C) 2004-2007 by Eric Van Hensbergen <ericvh@gmail.com> |
9 | * Copyright (C) 1997-2002 by Ron Minnich <rminnich@sarnoff.com> | 9 | * Copyright (C) 1997-2002 by Ron Minnich <rminnich@sarnoff.com> |
10 | * | 10 | * |
11 | * This program is free software; you can redistribute it and/or modify | 11 | * This program is free software; you can redistribute it and/or modify |
@@ -36,160 +36,114 @@ | |||
36 | #include <linux/inet.h> | 36 | #include <linux/inet.h> |
37 | #include <linux/idr.h> | 37 | #include <linux/idr.h> |
38 | #include <linux/file.h> | 38 | #include <linux/file.h> |
39 | #include <linux/parser.h> | ||
39 | #include <net/9p/9p.h> | 40 | #include <net/9p/9p.h> |
40 | #include <net/9p/transport.h> | 41 | #include <net/9p/transport.h> |
41 | 42 | ||
42 | #define P9_PORT 564 | 43 | #define P9_PORT 564 |
44 | #define MAX_SOCK_BUF (64*1024) | ||
45 | |||
46 | |||
47 | struct p9_fd_opts { | ||
48 | int rfd; | ||
49 | int wfd; | ||
50 | u16 port; | ||
51 | }; | ||
43 | 52 | ||
44 | struct p9_trans_fd { | 53 | struct p9_trans_fd { |
45 | struct file *rd; | 54 | struct file *rd; |
46 | struct file *wr; | 55 | struct file *wr; |
47 | }; | 56 | }; |
48 | 57 | ||
49 | static int p9_socket_open(struct p9_transport *trans, struct socket *csocket); | 58 | /* |
50 | static int p9_fd_open(struct p9_transport *trans, int rfd, int wfd); | 59 | * Option Parsing (code inspired by NFS code) |
51 | static int p9_fd_read(struct p9_transport *trans, void *v, int len); | 60 | * - a little lazy - parse all fd-transport options |
52 | static int p9_fd_write(struct p9_transport *trans, void *v, int len); | 61 | */ |
53 | static unsigned int p9_fd_poll(struct p9_transport *trans, | ||
54 | struct poll_table_struct *pt); | ||
55 | static void p9_fd_close(struct p9_transport *trans); | ||
56 | |||
57 | struct p9_transport *p9_trans_create_tcp(const char *addr, int port) | ||
58 | { | ||
59 | int err; | ||
60 | struct p9_transport *trans; | ||
61 | struct socket *csocket; | ||
62 | struct sockaddr_in sin_server; | ||
63 | |||
64 | csocket = NULL; | ||
65 | trans = kmalloc(sizeof(struct p9_transport), GFP_KERNEL); | ||
66 | if (!trans) | ||
67 | return ERR_PTR(-ENOMEM); | ||
68 | |||
69 | trans->write = p9_fd_write; | ||
70 | trans->read = p9_fd_read; | ||
71 | trans->close = p9_fd_close; | ||
72 | trans->poll = p9_fd_poll; | ||
73 | |||
74 | sin_server.sin_family = AF_INET; | ||
75 | sin_server.sin_addr.s_addr = in_aton(addr); | ||
76 | sin_server.sin_port = htons(port); | ||
77 | sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &csocket); | ||
78 | |||
79 | if (!csocket) { | ||
80 | P9_EPRINTK(KERN_ERR, "p9_trans_tcp: problem creating socket\n"); | ||
81 | err = -EIO; | ||
82 | goto error; | ||
83 | } | ||
84 | |||
85 | err = csocket->ops->connect(csocket, | ||
86 | (struct sockaddr *)&sin_server, | ||
87 | sizeof(struct sockaddr_in), 0); | ||
88 | if (err < 0) { | ||
89 | P9_EPRINTK(KERN_ERR, | ||
90 | "p9_trans_tcp: problem connecting socket to %s\n", | ||
91 | addr); | ||
92 | goto error; | ||
93 | } | ||
94 | |||
95 | err = p9_socket_open(trans, csocket); | ||
96 | if (err < 0) | ||
97 | goto error; | ||
98 | 62 | ||
99 | return trans; | 63 | enum { |
64 | /* Options that take integer arguments */ | ||
65 | Opt_port, Opt_rfdno, Opt_wfdno, | ||
66 | }; | ||
100 | 67 | ||
101 | error: | 68 | static match_table_t tokens = { |
102 | if (csocket) | 69 | {Opt_port, "port=%u"}, |
103 | sock_release(csocket); | 70 | {Opt_rfdno, "rfdno=%u"}, |
71 | {Opt_wfdno, "wfdno=%u"}, | ||
72 | }; | ||
104 | 73 | ||
105 | kfree(trans); | 74 | /** |
106 | return ERR_PTR(err); | 75 | * v9fs_parse_options - parse mount options into session structure |
107 | } | 76 | * @options: options string passed from mount |
108 | EXPORT_SYMBOL(p9_trans_create_tcp); | 77 | * @v9ses: existing v9fs session information |
78 | * | ||
79 | */ | ||
109 | 80 | ||
110 | struct p9_transport *p9_trans_create_unix(const char *addr) | 81 | static void parse_opts(char *options, struct p9_fd_opts *opts) |
111 | { | 82 | { |
112 | int err; | 83 | char *p; |
113 | struct socket *csocket; | 84 | substring_t args[MAX_OPT_ARGS]; |
114 | struct sockaddr_un sun_server; | 85 | int option; |
115 | struct p9_transport *trans; | 86 | int ret; |
116 | |||
117 | csocket = NULL; | ||
118 | trans = kmalloc(sizeof(struct p9_transport), GFP_KERNEL); | ||
119 | if (!trans) | ||
120 | return ERR_PTR(-ENOMEM); | ||
121 | 87 | ||
122 | trans->write = p9_fd_write; | 88 | opts->port = P9_PORT; |
123 | trans->read = p9_fd_read; | 89 | opts->rfd = ~0; |
124 | trans->close = p9_fd_close; | 90 | opts->wfd = ~0; |
125 | trans->poll = p9_fd_poll; | ||
126 | 91 | ||
127 | if (strlen(addr) > UNIX_PATH_MAX) { | 92 | if (!options) |
128 | P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n", | 93 | return; |
129 | addr); | ||
130 | err = -ENAMETOOLONG; | ||
131 | goto error; | ||
132 | } | ||
133 | 94 | ||
134 | sun_server.sun_family = PF_UNIX; | 95 | while ((p = strsep(&options, ",")) != NULL) { |
135 | strcpy(sun_server.sun_path, addr); | 96 | int token; |
136 | sock_create_kern(PF_UNIX, SOCK_STREAM, 0, &csocket); | 97 | if (!*p) |
137 | err = csocket->ops->connect(csocket, (struct sockaddr *)&sun_server, | 98 | continue; |
138 | sizeof(struct sockaddr_un) - 1, 0); | 99 | token = match_token(p, tokens, args); |
139 | if (err < 0) { | 100 | ret = match_int(&args[0], &option); |
140 | P9_EPRINTK(KERN_ERR, | 101 | if (ret < 0) { |
141 | "p9_trans_unix: problem connecting socket: %s: %d\n", | 102 | P9_DPRINTK(P9_DEBUG_ERROR, |
142 | addr, err); | 103 | "integer field, but no integer?\n"); |
143 | goto error; | 104 | continue; |
105 | } | ||
106 | switch (token) { | ||
107 | case Opt_port: | ||
108 | opts->port = option; | ||
109 | break; | ||
110 | case Opt_rfdno: | ||
111 | opts->rfd = option; | ||
112 | break; | ||
113 | case Opt_wfdno: | ||
114 | opts->wfd = option; | ||
115 | break; | ||
116 | default: | ||
117 | continue; | ||
118 | } | ||
144 | } | 119 | } |
145 | |||
146 | err = p9_socket_open(trans, csocket); | ||
147 | if (err < 0) | ||
148 | goto error; | ||
149 | |||
150 | return trans; | ||
151 | |||
152 | error: | ||
153 | if (csocket) | ||
154 | sock_release(csocket); | ||
155 | |||
156 | kfree(trans); | ||
157 | return ERR_PTR(err); | ||
158 | } | 120 | } |
159 | EXPORT_SYMBOL(p9_trans_create_unix); | ||
160 | 121 | ||
161 | struct p9_transport *p9_trans_create_fd(int rfd, int wfd) | 122 | static int p9_fd_open(struct p9_trans *trans, int rfd, int wfd) |
162 | { | 123 | { |
163 | int err; | 124 | struct p9_trans_fd *ts = kmalloc(sizeof(struct p9_trans_fd), |
164 | struct p9_transport *trans; | 125 | GFP_KERNEL); |
126 | if (!ts) | ||
127 | return -ENOMEM; | ||
165 | 128 | ||
166 | if (rfd == ~0 || wfd == ~0) { | 129 | ts->rd = fget(rfd); |
167 | printk(KERN_ERR "v9fs: Insufficient options for proto=fd\n"); | 130 | ts->wr = fget(wfd); |
168 | return ERR_PTR(-ENOPROTOOPT); | 131 | if (!ts->rd || !ts->wr) { |
132 | if (ts->rd) | ||
133 | fput(ts->rd); | ||
134 | if (ts->wr) | ||
135 | fput(ts->wr); | ||
136 | kfree(ts); | ||
137 | return -EIO; | ||
169 | } | 138 | } |
170 | 139 | ||
171 | trans = kmalloc(sizeof(struct p9_transport), GFP_KERNEL); | 140 | trans->priv = ts; |
172 | if (!trans) | 141 | trans->status = Connected; |
173 | return ERR_PTR(-ENOMEM); | ||
174 | |||
175 | trans->write = p9_fd_write; | ||
176 | trans->read = p9_fd_read; | ||
177 | trans->close = p9_fd_close; | ||
178 | trans->poll = p9_fd_poll; | ||
179 | |||
180 | err = p9_fd_open(trans, rfd, wfd); | ||
181 | if (err < 0) | ||
182 | goto error; | ||
183 | |||
184 | return trans; | ||
185 | 142 | ||
186 | error: | 143 | return 0; |
187 | kfree(trans); | ||
188 | return ERR_PTR(err); | ||
189 | } | 144 | } |
190 | EXPORT_SYMBOL(p9_trans_create_fd); | ||
191 | 145 | ||
192 | static int p9_socket_open(struct p9_transport *trans, struct socket *csocket) | 146 | static int p9_socket_open(struct p9_trans *trans, struct socket *csocket) |
193 | { | 147 | { |
194 | int fd, ret; | 148 | int fd, ret; |
195 | 149 | ||
@@ -212,30 +166,6 @@ static int p9_socket_open(struct p9_transport *trans, struct socket *csocket) | |||
212 | return 0; | 166 | return 0; |
213 | } | 167 | } |
214 | 168 | ||
215 | static int p9_fd_open(struct p9_transport *trans, int rfd, int wfd) | ||
216 | { | ||
217 | struct p9_trans_fd *ts = kmalloc(sizeof(struct p9_trans_fd), | ||
218 | GFP_KERNEL); | ||
219 | if (!ts) | ||
220 | return -ENOMEM; | ||
221 | |||
222 | ts->rd = fget(rfd); | ||
223 | ts->wr = fget(wfd); | ||
224 | if (!ts->rd || !ts->wr) { | ||
225 | if (ts->rd) | ||
226 | fput(ts->rd); | ||
227 | if (ts->wr) | ||
228 | fput(ts->wr); | ||
229 | kfree(ts); | ||
230 | return -EIO; | ||
231 | } | ||
232 | |||
233 | trans->priv = ts; | ||
234 | trans->status = Connected; | ||
235 | |||
236 | return 0; | ||
237 | } | ||
238 | |||
239 | /** | 169 | /** |
240 | * p9_fd_read- read from a fd | 170 | * p9_fd_read- read from a fd |
241 | * @v9ses: session information | 171 | * @v9ses: session information |
@@ -243,7 +173,7 @@ static int p9_fd_open(struct p9_transport *trans, int rfd, int wfd) | |||
243 | * @len: size of receive buffer | 173 | * @len: size of receive buffer |
244 | * | 174 | * |
245 | */ | 175 | */ |
246 | static int p9_fd_read(struct p9_transport *trans, void *v, int len) | 176 | static int p9_fd_read(struct p9_trans *trans, void *v, int len) |
247 | { | 177 | { |
248 | int ret; | 178 | int ret; |
249 | struct p9_trans_fd *ts = NULL; | 179 | struct p9_trans_fd *ts = NULL; |
@@ -270,7 +200,7 @@ static int p9_fd_read(struct p9_transport *trans, void *v, int len) | |||
270 | * @len: size of send buffer | 200 | * @len: size of send buffer |
271 | * | 201 | * |
272 | */ | 202 | */ |
273 | static int p9_fd_write(struct p9_transport *trans, void *v, int len) | 203 | static int p9_fd_write(struct p9_trans *trans, void *v, int len) |
274 | { | 204 | { |
275 | int ret; | 205 | int ret; |
276 | mm_segment_t oldfs; | 206 | mm_segment_t oldfs; |
@@ -297,7 +227,7 @@ static int p9_fd_write(struct p9_transport *trans, void *v, int len) | |||
297 | } | 227 | } |
298 | 228 | ||
299 | static unsigned int | 229 | static unsigned int |
300 | p9_fd_poll(struct p9_transport *trans, struct poll_table_struct *pt) | 230 | p9_fd_poll(struct p9_trans *trans, struct poll_table_struct *pt) |
301 | { | 231 | { |
302 | int ret, n; | 232 | int ret, n; |
303 | struct p9_trans_fd *ts = NULL; | 233 | struct p9_trans_fd *ts = NULL; |
@@ -341,7 +271,7 @@ end: | |||
341 | * @trans: private socket structure | 271 | * @trans: private socket structure |
342 | * | 272 | * |
343 | */ | 273 | */ |
344 | static void p9_fd_close(struct p9_transport *trans) | 274 | static void p9_fd_close(struct p9_trans *trans) |
345 | { | 275 | { |
346 | struct p9_trans_fd *ts; | 276 | struct p9_trans_fd *ts; |
347 | 277 | ||
@@ -361,3 +291,182 @@ static void p9_fd_close(struct p9_transport *trans) | |||
361 | kfree(ts); | 291 | kfree(ts); |
362 | } | 292 | } |
363 | 293 | ||
294 | static struct p9_trans *p9_trans_create_tcp(const char *addr, char *args) | ||
295 | { | ||
296 | int err; | ||
297 | struct p9_trans *trans; | ||
298 | struct socket *csocket; | ||
299 | struct sockaddr_in sin_server; | ||
300 | struct p9_fd_opts opts; | ||
301 | |||
302 | parse_opts(args, &opts); | ||
303 | |||
304 | csocket = NULL; | ||
305 | trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL); | ||
306 | if (!trans) | ||
307 | return ERR_PTR(-ENOMEM); | ||
308 | |||
309 | trans->write = p9_fd_write; | ||
310 | trans->read = p9_fd_read; | ||
311 | trans->close = p9_fd_close; | ||
312 | trans->poll = p9_fd_poll; | ||
313 | |||
314 | sin_server.sin_family = AF_INET; | ||
315 | sin_server.sin_addr.s_addr = in_aton(addr); | ||
316 | sin_server.sin_port = htons(opts.port); | ||
317 | sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &csocket); | ||
318 | |||
319 | if (!csocket) { | ||
320 | P9_EPRINTK(KERN_ERR, "p9_trans_tcp: problem creating socket\n"); | ||
321 | err = -EIO; | ||
322 | goto error; | ||
323 | } | ||
324 | |||
325 | err = csocket->ops->connect(csocket, | ||
326 | (struct sockaddr *)&sin_server, | ||
327 | sizeof(struct sockaddr_in), 0); | ||
328 | if (err < 0) { | ||
329 | P9_EPRINTK(KERN_ERR, | ||
330 | "p9_trans_tcp: problem connecting socket to %s\n", | ||
331 | addr); | ||
332 | goto error; | ||
333 | } | ||
334 | |||
335 | err = p9_socket_open(trans, csocket); | ||
336 | if (err < 0) | ||
337 | goto error; | ||
338 | |||
339 | return trans; | ||
340 | |||
341 | error: | ||
342 | if (csocket) | ||
343 | sock_release(csocket); | ||
344 | |||
345 | kfree(trans); | ||
346 | return ERR_PTR(err); | ||
347 | } | ||
348 | |||
349 | static struct p9_trans *p9_trans_create_unix(const char *addr, char *args) | ||
350 | { | ||
351 | int err; | ||
352 | struct socket *csocket; | ||
353 | struct sockaddr_un sun_server; | ||
354 | struct p9_trans *trans; | ||
355 | |||
356 | csocket = NULL; | ||
357 | trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL); | ||
358 | if (!trans) | ||
359 | return ERR_PTR(-ENOMEM); | ||
360 | |||
361 | trans->write = p9_fd_write; | ||
362 | trans->read = p9_fd_read; | ||
363 | trans->close = p9_fd_close; | ||
364 | trans->poll = p9_fd_poll; | ||
365 | |||
366 | if (strlen(addr) > UNIX_PATH_MAX) { | ||
367 | P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n", | ||
368 | addr); | ||
369 | err = -ENAMETOOLONG; | ||
370 | goto error; | ||
371 | } | ||
372 | |||
373 | sun_server.sun_family = PF_UNIX; | ||
374 | strcpy(sun_server.sun_path, addr); | ||
375 | sock_create_kern(PF_UNIX, SOCK_STREAM, 0, &csocket); | ||
376 | err = csocket->ops->connect(csocket, (struct sockaddr *)&sun_server, | ||
377 | sizeof(struct sockaddr_un) - 1, 0); | ||
378 | if (err < 0) { | ||
379 | P9_EPRINTK(KERN_ERR, | ||
380 | "p9_trans_unix: problem connecting socket: %s: %d\n", | ||
381 | addr, err); | ||
382 | goto error; | ||
383 | } | ||
384 | |||
385 | err = p9_socket_open(trans, csocket); | ||
386 | if (err < 0) | ||
387 | goto error; | ||
388 | |||
389 | return trans; | ||
390 | |||
391 | error: | ||
392 | if (csocket) | ||
393 | sock_release(csocket); | ||
394 | |||
395 | kfree(trans); | ||
396 | return ERR_PTR(err); | ||
397 | } | ||
398 | |||
399 | static struct p9_trans *p9_trans_create_fd(const char *name, char *args) | ||
400 | { | ||
401 | int err; | ||
402 | struct p9_trans *trans; | ||
403 | struct p9_fd_opts opts; | ||
404 | |||
405 | parse_opts(args, &opts); | ||
406 | |||
407 | if (opts.rfd == ~0 || opts.wfd == ~0) { | ||
408 | printk(KERN_ERR "v9fs: Insufficient options for proto=fd\n"); | ||
409 | return ERR_PTR(-ENOPROTOOPT); | ||
410 | } | ||
411 | |||
412 | trans = kmalloc(sizeof(struct p9_trans), GFP_KERNEL); | ||
413 | if (!trans) | ||
414 | return ERR_PTR(-ENOMEM); | ||
415 | |||
416 | trans->write = p9_fd_write; | ||
417 | trans->read = p9_fd_read; | ||
418 | trans->close = p9_fd_close; | ||
419 | trans->poll = p9_fd_poll; | ||
420 | |||
421 | err = p9_fd_open(trans, opts.rfd, opts.wfd); | ||
422 | if (err < 0) | ||
423 | goto error; | ||
424 | |||
425 | return trans; | ||
426 | |||
427 | error: | ||
428 | kfree(trans); | ||
429 | return ERR_PTR(err); | ||
430 | } | ||
431 | |||
432 | static struct p9_trans_module p9_tcp_trans = { | ||
433 | .name = "tcp", | ||
434 | .maxsize = MAX_SOCK_BUF, | ||
435 | .def = 1, | ||
436 | .create = p9_trans_create_tcp, | ||
437 | }; | ||
438 | |||
439 | static struct p9_trans_module p9_unix_trans = { | ||
440 | .name = "unix", | ||
441 | .maxsize = MAX_SOCK_BUF, | ||
442 | .def = 0, | ||
443 | .create = p9_trans_create_unix, | ||
444 | }; | ||
445 | |||
446 | static struct p9_trans_module p9_fd_trans = { | ||
447 | .name = "fd", | ||
448 | .maxsize = MAX_SOCK_BUF, | ||
449 | .def = 0, | ||
450 | .create = p9_trans_create_fd, | ||
451 | }; | ||
452 | |||
453 | static int __init p9_trans_fd_init(void) | ||
454 | { | ||
455 | v9fs_register_trans(&p9_tcp_trans); | ||
456 | v9fs_register_trans(&p9_unix_trans); | ||
457 | v9fs_register_trans(&p9_fd_trans); | ||
458 | |||
459 | return 1; | ||
460 | } | ||
461 | |||
462 | static void __exit p9_trans_fd_exit(void) { | ||
463 | printk(KERN_ERR "Removal of 9p transports not implemented\n"); | ||
464 | BUG(); | ||
465 | } | ||
466 | |||
467 | module_init(p9_trans_fd_init); | ||
468 | module_exit(p9_trans_fd_exit); | ||
469 | |||
470 | MODULE_AUTHOR("Latchesar Ionkov <lucho@ionkov.net>"); | ||
471 | MODULE_AUTHOR("Eric Van Hensbergen <ericvh@gmail.com>"); | ||
472 | MODULE_LICENSE("GPL"); | ||