| @@ -1,155 +1,154 @@ | | | @@ -1,155 +1,154 @@ |
1 | /* $NetBSD: rumpnfsd.c,v 1.3 2010/07/30 21:10:44 pooka Exp $ */ | | 1 | /* $NetBSD: rumpnfsd.c,v 1.4 2010/08/05 16:47:59 pooka Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2010 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2010 The NetBSD Foundation, Inc. |
5 | * | | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | | 7 | * modification, are permitted provided that the following conditions |
8 | * are met: | | 8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright | | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright | | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the | | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. | | 13 | * documentation and/or other materials provided with the distribution. |
14 | * | | 14 | * |
15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS | | 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | 16 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | 17 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | | 18 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | | 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 21 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 | * SUCH DAMAGE. | | 25 | * SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | #include <sys/types.h> | | 28 | #include <sys/types.h> |
29 | | | 29 | |
30 | #include <dlfcn.h> | | 30 | #include <dlfcn.h> |
31 | #include <err.h> | | 31 | #include <err.h> |
32 | #include <errno.h> | | 32 | #include <errno.h> |
33 | #include <pthread.h> | | 33 | #include <pthread.h> |
34 | #include <semaphore.h> | | 34 | #include <semaphore.h> |
35 | #include <stdio.h> | | 35 | #include <stdio.h> |
36 | #include <stdlib.h> | | 36 | #include <stdlib.h> |
37 | #include <string.h> | | 37 | #include <string.h> |
38 | #include <syslog.h> | | 38 | #include <syslog.h> |
39 | #include <unistd.h> | | 39 | #include <unistd.h> |
40 | | | 40 | |
41 | void *mountd_main(void *); | | 41 | void *mountd_main(void *); |
42 | void *rpcbind_main(void *); | | 42 | void *rpcbind_main(void *); |
43 | int nfsd_main(int, char **); | | 43 | int nfsd_main(int, char **); |
44 | | | 44 | |
45 | sem_t gensem; | | 45 | sem_t gensem; |
46 | | | 46 | |
47 | #include "../../../net/config/netconfig.c" | | 47 | #include "../../../net/config/netconfig.c" |
48 | #include "../../common/h_fsmacros.h" | | 48 | #include "../../common/h_fsmacros.h" |
49 | #include "svc_fdset.h" | | 49 | #include "svc_fdset.h" |
50 | | | 50 | |
51 | #include <rump/rump.h> | | 51 | #include <rump/rump.h> |
52 | #include <rump/rump_syscalls.h> | | 52 | #include <rump/rump_syscalls.h> |
53 | | | 53 | |
54 | int | | 54 | int |
55 | main(int argc, char *argv[]) | | 55 | main(int argc, char *argv[]) |
56 | { | | 56 | { |
57 | const char *ethername; | | 57 | const char *ethername; |
58 | const char *serveraddr; | | 58 | const char *serveraddr; |
59 | const char *netmask; | | 59 | const char *netmask; |
60 | const char *exportpath; | | 60 | const char *exportpath; |
61 | const char *imagename; | | 61 | const char *imagename; |
62 | char ifname[IFNAMSIZ]; | | 62 | char ifname[IFNAMSIZ]; |
63 | void *fsarg; | | 63 | void *fsarg; |
64 | pthread_t t; | | 64 | pthread_t t; |
65 | int rv; | | 65 | int rv; |
66 | | | 66 | |
67 | /* use defaults? */ | | 67 | /* use defaults? */ |
68 | if (argc == 1) { | | 68 | if (argc == 1) { |
69 | ethername = "etherbus"; | | 69 | ethername = "etherbus"; |
70 | serveraddr = "10.3.2.1"; | | 70 | serveraddr = "10.3.2.1"; |
71 | netmask = "255.255.255.0"; | | 71 | netmask = "255.255.255.0"; |
72 | exportpath = "/myexport"; | | 72 | exportpath = "/myexport"; |
73 | imagename = "ffs.img"; | | 73 | imagename = "ffs.img"; |
74 | } else { | | 74 | } else { |
75 | ethername = argv[1]; | | 75 | ethername = argv[1]; |
76 | serveraddr = argv[2]; | | 76 | serveraddr = argv[2]; |
77 | netmask = argv[3]; | | 77 | netmask = argv[3]; |
78 | exportpath = argv[4]; | | 78 | exportpath = argv[4]; |
79 | imagename = argv[5]; | | 79 | imagename = argv[5]; |
80 | } | | 80 | } |
81 | | | 81 | |
82 | rump_init(); | | 82 | rump_init(); |
83 | init_fdsets(); | | 83 | init_fdsets(); |
84 | | | 84 | |
85 | rv = rump_pub_etfs_register("/etc/exports", "./exports", RUMP_ETFS_REG); | | 85 | rv = rump_pub_etfs_register("/etc/exports", "./exports", RUMP_ETFS_REG); |
86 | if (rv) { | | 86 | if (rv) { |
87 | errx(1, "register /etc/exports: %s", strerror(rv)); | | 87 | errx(1, "register /etc/exports: %s", strerror(rv)); |
88 | } | | 88 | } |
89 | | | 89 | |
90 | /* mini-mtree for mountd */ | | 90 | /* mini-mtree for mountd */ |
91 | rump_sys_mkdir("/var", 0777); | | 91 | rump_sys_mkdir("/var", 0777); |
92 | rump_sys_mkdir("/var/run", 0777); | | 92 | rump_sys_mkdir("/var/run", 0777); |
93 | rump_sys_mkdir("/var/db", 0777); | | 93 | rump_sys_mkdir("/var/db", 0777); |
94 | | | 94 | |
95 | fprintf(stderr, "imagename %s\n", imagename); | | | |
96 | if (ffs_fstest_newfs(NULL, &fsarg, | | 95 | if (ffs_fstest_newfs(NULL, &fsarg, |
97 | FSTEST_IMGNAME, FSTEST_IMGSIZE, NULL) != 0) | | 96 | FSTEST_IMGNAME, FSTEST_IMGSIZE, NULL) != 0) |
98 | atf_tc_fail("newfs failed"); | | 97 | atf_tc_fail("newfs failed"); |
99 | if (ffs_fstest_mount(NULL, fsarg, exportpath, 0) != 0) | | 98 | if (ffs_fstest_mount(NULL, fsarg, exportpath, 0) != 0) |
100 | atf_tc_fail("mount failed"); | | 99 | atf_tc_fail("mount failed"); |
101 | | | 100 | |
102 | #if 0 | | 101 | #if 0 |
103 | /* | | 102 | /* |
104 | * Serve from host instead of dedicated mount? | | 103 | * Serve from host instead of dedicated mount? |
105 | * THIS IS MORE EVIL THAN MURRAY THE DEMONIC TALKING SKULL! | | 104 | * THIS IS MORE EVIL THAN MURRAY THE DEMONIC TALKING SKULL! |
106 | */ | | 105 | */ |
107 | | | 106 | |
108 | if (ukfs_modload("/usr/lib/librumpfs_syspuffs.so") < 1) | | 107 | if (ukfs_modload("/usr/lib/librumpfs_syspuffs.so") < 1) |
109 | errx(1, "modload"); | | 108 | errx(1, "modload"); |
110 | | | 109 | |
111 | mount_syspuffs_parseargs(__arraycount(pnullarg), pnullarg, | | 110 | mount_syspuffs_parseargs(__arraycount(pnullarg), pnullarg, |
112 | &args, &mntflags, canon_dev, canon_dir); | | 111 | &args, &mntflags, canon_dev, canon_dir); |
113 | if ((ukfs = ukfs_mount(MOUNT_PUFFS, "/", UKFS_DEFAULTMP, MNT_RDONLY, | | 112 | if ((ukfs = ukfs_mount(MOUNT_PUFFS, "/", UKFS_DEFAULTMP, MNT_RDONLY, |
114 | &args, sizeof(args))) == NULL) | | 113 | &args, sizeof(args))) == NULL) |
115 | err(1, "mount"); | | 114 | err(1, "mount"); |
116 | | | 115 | |
117 | if (ukfs_modload("/usr/lib/librumpfs_nfsserver.so") < 1) | | 116 | if (ukfs_modload("/usr/lib/librumpfs_nfsserver.so") < 1) |
118 | errx(1, "modload"); | | 117 | errx(1, "modload"); |
119 | #endif | | 118 | #endif |
120 | | | 119 | |
121 | if (sem_init(&gensem, 1, 0) == -1) | | 120 | if (sem_init(&gensem, 1, 0) == -1) |
122 | err(1, "gensem init"); | | 121 | err(1, "gensem init"); |
123 | | | 122 | |
124 | /* create interface */ | | 123 | /* create interface */ |
125 | netcfg_rump_makeshmif(ethername, ifname); | | 124 | netcfg_rump_makeshmif(ethername, ifname); |
126 | netcfg_rump_if(ifname, serveraddr, netmask); | | 125 | netcfg_rump_if(ifname, serveraddr, netmask); |
127 | | | 126 | |
128 | /* | | 127 | /* |
129 | * No syslogging, thanks. | | 128 | * No syslogging, thanks. |
130 | * XXX: "0" does not modify the mask, so pick something | | 129 | * XXX: "0" does not modify the mask, so pick something |
131 | * which is unlikely to cause any logging | | 130 | * which is unlikely to cause any logging |
132 | */ | | 131 | */ |
133 | setlogmask(0x10000000); | | 132 | setlogmask(0x10000000); |
134 | | | 133 | |
135 | if (pthread_create(&t, NULL, rpcbind_main, NULL) == -1) | | 134 | if (pthread_create(&t, NULL, rpcbind_main, NULL) == -1) |
136 | err(1, "rpcbind"); | | 135 | err(1, "rpcbind"); |
137 | sem_wait(&gensem); | | 136 | sem_wait(&gensem); |
138 | | | 137 | |
139 | if (pthread_create(&t, NULL, mountd_main, NULL) == -1) | | 138 | if (pthread_create(&t, NULL, mountd_main, NULL) == -1) |
140 | err(1, "mountd"); | | 139 | err(1, "mountd"); |
141 | sem_wait(&gensem); | | 140 | sem_wait(&gensem); |
142 | | | 141 | |
143 | rv = 0; | | 142 | rv = 0; |
144 | /* signal the other process we're almost done */ | | 143 | /* signal the other process we're almost done */ |
145 | if (write(3, &rv, 4) != 4) | | 144 | if (write(3, &rv, 4) != 4) |
146 | errx(1, "magic write failed"); | | 145 | errx(1, "magic write failed"); |
147 | | | 146 | |
148 | { | | 147 | { |
149 | char *nfsargv[] = { __UNCONST("nfsd"), NULL }; | | 148 | char *nfsargv[] = { __UNCONST("nfsd"), NULL }; |
150 | nfsd_main(1, nfsargv); | | 149 | nfsd_main(1, nfsargv); |
151 | } | | 150 | } |
152 | /*NOTREACHED*/ | | 151 | /*NOTREACHED*/ |
153 | | | 152 | |
154 | return 0; | | 153 | return 0; |
155 | } | | 154 | } |