1 /* Blue Sky: File Systems in the Cloud
3 * Copyright (C) 2009 The Regents of the University of California
4 * Written by Michael Vrable <mvrable@cs.ucsd.edu>
9 /* RPC handling: registration, marshalling and unmarshalling of messages. For
10 * now this uses the standard Sun RPC mechanisms in the standard C library.
11 * Later, it might be changed to use something better. Much of this code was
12 * generated with rpcgen from the XDR specifications, but has been hand-edited
15 #include "mount_prot.h"
16 #include "nfs3_prot.h"
19 #include <rpc/pmap_clnt.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
26 mount_program_3(struct svc_req *rqstp, register SVCXPRT *transp)
29 dirpath mountproc3_mnt_3_arg;
30 dirpath mountproc3_umnt_3_arg;
33 xdrproc_t _xdr_argument, _xdr_result;
34 char *(*local)(char *, struct svc_req *);
36 switch (rqstp->rq_proc) {
38 _xdr_argument = (xdrproc_t) xdr_void;
39 _xdr_result = (xdrproc_t) xdr_void;
40 local = (char *(*)(char *, struct svc_req *)) mountproc3_null_3_svc;
44 _xdr_argument = (xdrproc_t) xdr_dirpath;
45 _xdr_result = (xdrproc_t) xdr_mountres3;
46 local = (char *(*)(char *, struct svc_req *)) mountproc3_mnt_3_svc;
50 _xdr_argument = (xdrproc_t) xdr_void;
51 _xdr_result = (xdrproc_t) xdr_mountlist;
52 local = (char *(*)(char *, struct svc_req *)) mountproc3_dump_3_svc;
56 _xdr_argument = (xdrproc_t) xdr_dirpath;
57 _xdr_result = (xdrproc_t) xdr_void;
58 local = (char *(*)(char *, struct svc_req *)) mountproc3_umnt_3_svc;
61 case MOUNTPROC3_UMNTALL:
62 _xdr_argument = (xdrproc_t) xdr_void;
63 _xdr_result = (xdrproc_t) xdr_void;
64 local = (char *(*)(char *, struct svc_req *)) mountproc3_umntall_3_svc;
67 case MOUNTPROC3_EXPORT:
68 _xdr_argument = (xdrproc_t) xdr_void;
69 _xdr_result = (xdrproc_t) xdr_exports;
70 local = (char *(*)(char *, struct svc_req *)) mountproc3_export_3_svc;
74 svcerr_noproc (transp);
77 memset ((char *)&argument, 0, sizeof (argument));
78 if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
79 svcerr_decode (transp);
82 result = (*local)((char *)&argument, rqstp);
83 if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) {
84 svcerr_systemerr (transp);
86 if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
87 fprintf (stderr, "%s", "unable to free arguments");
94 nfs_program_3(struct svc_req *rqstp, register SVCXPRT *transp)
97 nfs_fh3 nfsproc3_getattr_3_arg;
98 setattr3args nfsproc3_setattr_3_arg;
99 diropargs3 nfsproc3_lookup_3_arg;
100 access3args nfsproc3_access_3_arg;
101 nfs_fh3 nfsproc3_readlink_3_arg;
102 read3args nfsproc3_read_3_arg;
103 write3args nfsproc3_write_3_arg;
104 create3args nfsproc3_create_3_arg;
105 mkdir3args nfsproc3_mkdir_3_arg;
106 symlink3args nfsproc3_symlink_3_arg;
107 mknod3args nfsproc3_mknod_3_arg;
108 diropargs3 nfsproc3_remove_3_arg;
109 diropargs3 nfsproc3_rmdir_3_arg;
110 rename3args nfsproc3_rename_3_arg;
111 link3args nfsproc3_link_3_arg;
112 readdir3args nfsproc3_readdir_3_arg;
113 readdirplus3args nfsproc3_readdirplus_3_arg;
114 nfs_fh3 nfsproc3_fsstat_3_arg;
115 nfs_fh3 nfsproc3_fsinfo_3_arg;
116 nfs_fh3 nfsproc3_pathconf_3_arg;
117 commit3args nfsproc3_commit_3_arg;
120 xdrproc_t _xdr_argument, _xdr_result;
121 char *(*local)(char *, struct svc_req *);
123 switch (rqstp->rq_proc) {
125 _xdr_argument = (xdrproc_t) xdr_void;
126 _xdr_result = (xdrproc_t) xdr_void;
127 local = (char *(*)(char *, struct svc_req *)) nfsproc3_null_3_svc;
130 case NFSPROC3_GETATTR:
131 _xdr_argument = (xdrproc_t) xdr_nfs_fh3;
132 _xdr_result = (xdrproc_t) xdr_getattr3res;
133 local = (char *(*)(char *, struct svc_req *)) nfsproc3_getattr_3_svc;
136 case NFSPROC3_SETATTR:
137 _xdr_argument = (xdrproc_t) xdr_setattr3args;
138 _xdr_result = (xdrproc_t) xdr_wccstat3;
139 local = (char *(*)(char *, struct svc_req *)) nfsproc3_setattr_3_svc;
142 case NFSPROC3_LOOKUP:
143 _xdr_argument = (xdrproc_t) xdr_diropargs3;
144 _xdr_result = (xdrproc_t) xdr_lookup3res;
145 local = (char *(*)(char *, struct svc_req *)) nfsproc3_lookup_3_svc;
148 case NFSPROC3_ACCESS:
149 _xdr_argument = (xdrproc_t) xdr_access3args;
150 _xdr_result = (xdrproc_t) xdr_access3res;
151 local = (char *(*)(char *, struct svc_req *)) nfsproc3_access_3_svc;
154 case NFSPROC3_READLINK:
155 _xdr_argument = (xdrproc_t) xdr_nfs_fh3;
156 _xdr_result = (xdrproc_t) xdr_readlink3res;
157 local = (char *(*)(char *, struct svc_req *)) nfsproc3_readlink_3_svc;
161 _xdr_argument = (xdrproc_t) xdr_read3args;
162 _xdr_result = (xdrproc_t) xdr_read3res;
163 local = (char *(*)(char *, struct svc_req *)) nfsproc3_read_3_svc;
167 _xdr_argument = (xdrproc_t) xdr_write3args;
168 _xdr_result = (xdrproc_t) xdr_write3res;
169 local = (char *(*)(char *, struct svc_req *)) nfsproc3_write_3_svc;
172 case NFSPROC3_CREATE:
173 _xdr_argument = (xdrproc_t) xdr_create3args;
174 _xdr_result = (xdrproc_t) xdr_diropres3;
175 local = (char *(*)(char *, struct svc_req *)) nfsproc3_create_3_svc;
179 _xdr_argument = (xdrproc_t) xdr_mkdir3args;
180 _xdr_result = (xdrproc_t) xdr_diropres3;
181 local = (char *(*)(char *, struct svc_req *)) nfsproc3_mkdir_3_svc;
184 case NFSPROC3_SYMLINK:
185 _xdr_argument = (xdrproc_t) xdr_symlink3args;
186 _xdr_result = (xdrproc_t) xdr_diropres3;
187 local = (char *(*)(char *, struct svc_req *)) nfsproc3_symlink_3_svc;
191 _xdr_argument = (xdrproc_t) xdr_mknod3args;
192 _xdr_result = (xdrproc_t) xdr_diropres3;
193 local = (char *(*)(char *, struct svc_req *)) nfsproc3_mknod_3_svc;
196 case NFSPROC3_REMOVE:
197 _xdr_argument = (xdrproc_t) xdr_diropargs3;
198 _xdr_result = (xdrproc_t) xdr_wccstat3;
199 local = (char *(*)(char *, struct svc_req *)) nfsproc3_remove_3_svc;
203 _xdr_argument = (xdrproc_t) xdr_diropargs3;
204 _xdr_result = (xdrproc_t) xdr_wccstat3;
205 local = (char *(*)(char *, struct svc_req *)) nfsproc3_rmdir_3_svc;
208 case NFSPROC3_RENAME:
209 _xdr_argument = (xdrproc_t) xdr_rename3args;
210 _xdr_result = (xdrproc_t) xdr_rename3res;
211 local = (char *(*)(char *, struct svc_req *)) nfsproc3_rename_3_svc;
215 _xdr_argument = (xdrproc_t) xdr_link3args;
216 _xdr_result = (xdrproc_t) xdr_link3res;
217 local = (char *(*)(char *, struct svc_req *)) nfsproc3_link_3_svc;
220 case NFSPROC3_READDIR:
221 _xdr_argument = (xdrproc_t) xdr_readdir3args;
222 _xdr_result = (xdrproc_t) xdr_readdir3res;
223 local = (char *(*)(char *, struct svc_req *)) nfsproc3_readdir_3_svc;
226 case NFSPROC3_READDIRPLUS:
227 _xdr_argument = (xdrproc_t) xdr_readdirplus3args;
228 _xdr_result = (xdrproc_t) xdr_readdirplus3res;
229 local = (char *(*)(char *, struct svc_req *)) nfsproc3_readdirplus_3_svc;
232 case NFSPROC3_FSSTAT:
233 _xdr_argument = (xdrproc_t) xdr_nfs_fh3;
234 _xdr_result = (xdrproc_t) xdr_fsstat3res;
235 local = (char *(*)(char *, struct svc_req *)) nfsproc3_fsstat_3_svc;
238 case NFSPROC3_FSINFO:
239 _xdr_argument = (xdrproc_t) xdr_nfs_fh3;
240 _xdr_result = (xdrproc_t) xdr_fsinfo3res;
241 local = (char *(*)(char *, struct svc_req *)) nfsproc3_fsinfo_3_svc;
244 case NFSPROC3_PATHCONF:
245 _xdr_argument = (xdrproc_t) xdr_nfs_fh3;
246 _xdr_result = (xdrproc_t) xdr_pathconf3res;
247 local = (char *(*)(char *, struct svc_req *)) nfsproc3_pathconf_3_svc;
250 case NFSPROC3_COMMIT:
251 _xdr_argument = (xdrproc_t) xdr_commit3args;
252 _xdr_result = (xdrproc_t) xdr_commit3res;
253 local = (char *(*)(char *, struct svc_req *)) nfsproc3_commit_3_svc;
257 svcerr_noproc (transp);
260 memset ((char *)&argument, 0, sizeof (argument));
261 if (!svc_getargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
262 svcerr_decode (transp);
265 result = (*local)((char *)&argument, rqstp);
266 if (result != NULL && !svc_sendreply(transp, (xdrproc_t) _xdr_result, result)) {
267 svcerr_systemerr (transp);
269 if (!svc_freeargs (transp, (xdrproc_t) _xdr_argument, (caddr_t) &argument)) {
270 fprintf (stderr, "%s", "unable to free arguments");
281 pmap_unset (MOUNT_PROGRAM, MOUNT_V3);
283 transp = svcudp_create(RPC_ANYSOCK);
284 if (transp == NULL) {
285 fprintf(stderr, "%s", "cannot create udp service.");
288 if (!svc_register(transp, MOUNT_PROGRAM, MOUNT_V3, mount_program_3, IPPROTO_UDP)) {
289 fprintf(stderr, "%s", "unable to register (MOUNT_PROGRAM, MOUNT_V3, udp).");
293 transp = svctcp_create(RPC_ANYSOCK, 0, 0);
294 if (transp == NULL) {
295 fprintf(stderr, "%s", "cannot create tcp service.");
298 if (!svc_register(transp, MOUNT_PROGRAM, MOUNT_V3, mount_program_3, IPPROTO_TCP)) {
299 fprintf(stderr, "%s", "unable to register (MOUNT_PROGRAM, MOUNT_V3, tcp).");
303 /* NFS protocol (version 3) */
304 pmap_unset (NFS_PROGRAM, NFS_V3);
306 transp = svcudp_create(RPC_ANYSOCK);
307 if (transp == NULL) {
308 fprintf (stderr, "%s", "cannot create udp service.");
311 if (!svc_register(transp, NFS_PROGRAM, NFS_V3, nfs_program_3, IPPROTO_UDP)) {
312 fprintf (stderr, "%s", "unable to register (NFS_PROGRAM, NFS_V3, udp).");
316 transp = svctcp_create(RPC_ANYSOCK, 0, 0);
317 if (transp == NULL) {
318 fprintf (stderr, "%s", "cannot create tcp service.");
321 if (!svc_register(transp, NFS_PROGRAM, NFS_V3, nfs_program_3, IPPROTO_TCP)) {
322 fprintf (stderr, "%s", "unable to register (NFS_PROGRAM, NFS_V3, tcp).");