nfs: Add RPC and NFS XDR translation routines
Signed-off-by: Shehjar Tikoo <shehjart@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 399 (NFS translator with Mount v3 and NFS v3 support) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=399
This commit is contained in:
parent
fce2ae459b
commit
eff83c8dae
@ -107,6 +107,9 @@ AC_CONFIG_FILES([Makefile
|
||||
contrib/fuse-util/Makefile
|
||||
xlators/features/access-control/Makefile
|
||||
xlators/features/access-control/src/Makefile
|
||||
xlators/nfs/Makefile
|
||||
xlators/nfs/lib/Makefile
|
||||
xlators/nfs/lib/src/Makefile
|
||||
glusterfs.spec])
|
||||
|
||||
AC_CANONICAL_HOST
|
||||
|
@ -1,3 +1,3 @@
|
||||
SUBDIRS = cluster storage protocol performance debug features encryption mount
|
||||
SUBDIRS = cluster storage protocol performance debug features encryption mount nfs
|
||||
|
||||
CLEANFILES =
|
||||
|
3
xlators/nfs/Makefile.am
Normal file
3
xlators/nfs/Makefile.am
Normal file
@ -0,0 +1,3 @@
|
||||
SUBDIRS = lib
|
||||
|
||||
CLEANFILES =
|
3
xlators/nfs/lib/Makefile.am
Normal file
3
xlators/nfs/lib/Makefile.am
Normal file
@ -0,0 +1,3 @@
|
||||
SUBDIRS = src
|
||||
|
||||
CLEANFILES =
|
11
xlators/nfs/lib/src/Makefile.am
Normal file
11
xlators/nfs/lib/src/Makefile.am
Normal file
@ -0,0 +1,11 @@
|
||||
lib_LTLIBRARIES = librpcsvc.la
|
||||
librpcsvc_la_LDFLAGS = -module -avoidversion
|
||||
|
||||
librpcsvc_la_SOURCES = msg-nfs3.c xdr-nfs3.c xdr-rpc.c
|
||||
librpcsvc_la_LIBADD = $(top_builddir)/libglusterfs/src/libglusterfs.la
|
||||
|
||||
noinst_HEADERS = xdr-rpc.h msg-nfs3.h xdr-common.h xdr-nfs3.h
|
||||
AM_CFLAGS = -fPIC -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -Wall -D$(GF_HOST_OS)\
|
||||
-I$(top_srcdir)/libglusterfs/src -shared -nostartfiles $(GF_CFLAGS)
|
||||
|
||||
CLEANFILES =
|
558
xlators/nfs/lib/src/msg-nfs3.c
Normal file
558
xlators/nfs/lib/src/msg-nfs3.c
Normal file
@ -0,0 +1,558 @@
|
||||
/*
|
||||
Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
|
||||
This file is part of GlusterFS.
|
||||
|
||||
GlusterFS is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
GlusterFS is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/uio.h>
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "xdr-nfs3.h"
|
||||
#include "msg-nfs3.h"
|
||||
#include "xdr-common.h"
|
||||
|
||||
|
||||
/* Decode the mount path from the network message in inmsg
|
||||
* into the memory referenced by outpath.iov_base.
|
||||
* The size allocated for outpath.iov_base is outpath.iov_len.
|
||||
* The size of the path extracted from the message is returned.
|
||||
*/
|
||||
ssize_t
|
||||
xdr_to_mountpath (struct iovec outpath, struct iovec inmsg)
|
||||
{
|
||||
XDR xdr;
|
||||
ssize_t ret = -1;
|
||||
char *mntpath = NULL;
|
||||
|
||||
if ((!outpath.iov_base) || (!inmsg.iov_base))
|
||||
return -1;
|
||||
|
||||
xdrmem_create (&xdr, inmsg.iov_base, (unsigned int)inmsg.iov_len,
|
||||
XDR_DECODE);
|
||||
|
||||
mntpath = outpath.iov_base;
|
||||
if (!xdr_dirpath (&xdr, (dirpath *)&mntpath)) {
|
||||
ret = -1;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
ret = xdr_decoded_length (xdr);
|
||||
|
||||
ret:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_generic (struct iovec outmsg, void *res, xdrproc_t proc)
|
||||
{
|
||||
ssize_t ret = -1;
|
||||
XDR xdr;
|
||||
|
||||
if ((!outmsg.iov_base) || (!res) || (!proc))
|
||||
return -1;
|
||||
|
||||
xdrmem_create (&xdr, outmsg.iov_base, (unsigned int)outmsg.iov_len,
|
||||
XDR_ENCODE);
|
||||
|
||||
if (!proc (&xdr, res)) {
|
||||
ret = -1;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
ret = xdr_encoded_length (xdr);
|
||||
|
||||
ret:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_generic (struct iovec inmsg, void *args, xdrproc_t proc)
|
||||
{
|
||||
XDR xdr;
|
||||
ssize_t ret = -1;
|
||||
|
||||
if ((!inmsg.iov_base) || (!args) || (!proc))
|
||||
return -1;
|
||||
|
||||
xdrmem_create (&xdr, inmsg.iov_base, (unsigned int)inmsg.iov_len,
|
||||
XDR_DECODE);
|
||||
|
||||
if (!proc (&xdr, args)) {
|
||||
ret = -1;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
ret = xdr_decoded_length (xdr);
|
||||
ret:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_generic_payload (struct iovec inmsg, void *args, xdrproc_t proc,
|
||||
struct iovec *pendingpayload)
|
||||
{
|
||||
XDR xdr;
|
||||
ssize_t ret = -1;
|
||||
|
||||
if ((!inmsg.iov_base) || (!args) || (!proc))
|
||||
return -1;
|
||||
|
||||
xdrmem_create (&xdr, inmsg.iov_base, (unsigned int)inmsg.iov_len,
|
||||
XDR_DECODE);
|
||||
|
||||
if (!proc (&xdr, args)) {
|
||||
ret = -1;
|
||||
goto ret;
|
||||
}
|
||||
|
||||
ret = xdr_decoded_length (xdr);
|
||||
|
||||
if (pendingpayload) {
|
||||
pendingpayload->iov_base = xdr_decoded_remaining_addr (xdr);
|
||||
pendingpayload->iov_len = xdr_decoded_remaining_len (xdr);
|
||||
}
|
||||
|
||||
ret:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Translate the mountres3 structure in res into XDR format into memory
|
||||
* referenced by outmsg.iov_base.
|
||||
* Returns the number of bytes used in encoding into XDR format.
|
||||
*/
|
||||
ssize_t
|
||||
xdr_serialize_mountres3 (struct iovec outmsg, mountres3 *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_mountres3);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_mountbody (struct iovec outmsg, mountbody *mb)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)mb,
|
||||
(xdrproc_t)xdr_mountbody);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_mountlist (struct iovec outmsg, mountlist *ml)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)ml,
|
||||
(xdrproc_t)xdr_mountlist);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_mountstat3 (struct iovec outmsg, mountstat3 *m)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)m,
|
||||
(xdrproc_t)xdr_mountstat3);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_getattr3args (struct iovec inmsg, getattr3args *ga)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)ga,(xdrproc_t)xdr_getattr3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_getattr3res (struct iovec outmsg, getattr3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_getattr3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_setattr3res (struct iovec outmsg, setattr3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_setattr3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_setattr3args (struct iovec inmsg, setattr3args *sa)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)sa, (xdrproc_t)xdr_setattr3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_lookup3res (struct iovec outmsg, lookup3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_lookup3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_lookup3args (struct iovec inmsg, lookup3args *la)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)la, (xdrproc_t)xdr_lookup3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_access3args (struct iovec inmsg, access3args *ac)
|
||||
{
|
||||
return xdr_to_generic (inmsg,(void *)ac, (xdrproc_t)xdr_access3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_access3res (struct iovec outmsg, access3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_access3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_readlink3args (struct iovec inmsg, readlink3args *ra)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)ra, (xdrproc_t)xdr_readlink3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_readlink3res (struct iovec outmsg, readlink3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_readlink3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_read3args (struct iovec inmsg, read3args *ra)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)ra, (xdrproc_t)xdr_read3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_read3res (struct iovec outmsg, read3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_read3res);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_read3res_nocopy (struct iovec outmsg, read3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_read3res_nocopy);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_write3args (struct iovec inmsg, write3args *wa)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)wa,(xdrproc_t)xdr_write3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_write3args_nocopy (struct iovec inmsg, write3args *wa,
|
||||
struct iovec *payload)
|
||||
{
|
||||
return xdr_to_generic_payload (inmsg, (void *)wa,
|
||||
(xdrproc_t)xdr_write3args, payload);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_write3res (struct iovec outmsg, write3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_write3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_create3args (struct iovec inmsg, create3args *ca)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)ca, (xdrproc_t)xdr_create3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_create3res (struct iovec outmsg, create3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_create3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_mkdir3res (struct iovec outmsg, mkdir3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_mkdir3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_mkdir3args (struct iovec inmsg, mkdir3args *ma)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)ma, (xdrproc_t)xdr_mkdir3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_symlink3args (struct iovec inmsg, symlink3args *sa)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)sa, (xdrproc_t)xdr_symlink3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_symlink3res (struct iovec outmsg, symlink3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_symlink3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_mknod3args (struct iovec inmsg, mknod3args *ma)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)ma, (xdrproc_t)xdr_mknod3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_mknod3res (struct iovec outmsg, mknod3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_mknod3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_remove3args (struct iovec inmsg, remove3args *ra)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)ra, (xdrproc_t)xdr_remove3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_remove3res (struct iovec outmsg, remove3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_remove3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_rmdir3args (struct iovec inmsg, rmdir3args *ra)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)ra, (xdrproc_t)xdr_rmdir3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_rmdir3res (struct iovec outmsg, rmdir3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_rmdir3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_rename3res (struct iovec outmsg, rename3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_rename3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_rename3args (struct iovec inmsg, rename3args *ra)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)ra, (xdrproc_t)xdr_rename3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_link3res (struct iovec outmsg, link3res *li)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)li,
|
||||
(xdrproc_t)xdr_link3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_link3args (struct iovec inmsg, link3args *la)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)la, (xdrproc_t)xdr_link3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_readdir3args (struct iovec inmsg, readdir3args *rd)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)rd, (xdrproc_t)xdr_readdir3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_readdir3res (struct iovec outmsg, readdir3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_readdir3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_readdirp3args (struct iovec inmsg, readdirp3args *rp)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)rp, (xdrproc_t)xdr_readdirp3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_readdirp3res (struct iovec outmsg, readdirp3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_readdirp3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_fsstat3args (struct iovec inmsg, fsstat3args *fa)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)fa, (xdrproc_t)xdr_fsstat3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_fsstat3res (struct iovec outmsg, fsstat3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_fsstat3res);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
xdr_to_fsinfo3args (struct iovec inmsg, fsinfo3args *fi)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)fi, (xdrproc_t)xdr_fsinfo3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_fsinfo3res (struct iovec outmsg, fsinfo3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_fsinfo3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_pathconf3args (struct iovec inmsg, pathconf3args *pc)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)pc, (xdrproc_t)xdr_pathconf3args);}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_pathconf3res (struct iovec outmsg, pathconf3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_pathconf3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_to_commit3args (struct iovec inmsg, commit3args *ca)
|
||||
{
|
||||
return xdr_to_generic (inmsg, (void *)ca, (xdrproc_t)xdr_commit3args);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_commit3res (struct iovec outmsg, commit3res *res)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)res,
|
||||
(xdrproc_t)xdr_commit3res);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_exports (struct iovec outmsg, exports *elist)
|
||||
{
|
||||
XDR xdr;
|
||||
ssize_t ret = -1;
|
||||
|
||||
if ((!outmsg.iov_base) || (!elist))
|
||||
return -1;
|
||||
|
||||
xdrmem_create (&xdr, outmsg.iov_base, (unsigned int)outmsg.iov_len,
|
||||
XDR_ENCODE);
|
||||
|
||||
if (!xdr_exports (&xdr, elist))
|
||||
goto ret;
|
||||
|
||||
ret = xdr_decoded_length (xdr);
|
||||
|
||||
ret:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_serialize_nfsstat3 (struct iovec outmsg, nfsstat3 *s)
|
||||
{
|
||||
return xdr_serialize_generic (outmsg, (void *)s,
|
||||
(xdrproc_t)xdr_nfsstat3);
|
||||
}
|
||||
|
||||
|
||||
ssize_t
|
||||
xdr_length_round_up (size_t len, size_t bufsize)
|
||||
{
|
||||
int roundup = 0;
|
||||
|
||||
roundup = len % XDR_BYTES_PER_UNIT;
|
||||
if (roundup > 0)
|
||||
roundup = XDR_BYTES_PER_UNIT - roundup;
|
||||
|
||||
if ((roundup > 0) && ((roundup + len) <= bufsize))
|
||||
len += roundup;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
int
|
||||
xdr_bytes_round_up (struct iovec *vec, size_t bufsize)
|
||||
{
|
||||
vec->iov_len = xdr_length_round_up (vec->iov_len, bufsize);
|
||||
return 0;
|
||||
}
|
||||
|
192
xlators/nfs/lib/src/msg-nfs3.h
Normal file
192
xlators/nfs/lib/src/msg-nfs3.h
Normal file
@ -0,0 +1,192 @@
|
||||
/*
|
||||
Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
|
||||
This file is part of GlusterFS.
|
||||
|
||||
GlusterFS is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
GlusterFS is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _MSG_NFS3_H_
|
||||
#define _MSG_NFS3_H_
|
||||
|
||||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "xdr-nfs3.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_mountpath (struct iovec outpath, struct iovec inmsg);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_mountres3 (struct iovec outmsg, mountres3 *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_mountbody (struct iovec outmsg, mountbody *mb);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_getattr3args (struct iovec inmsg, getattr3args *ga);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_getattr3res (struct iovec outmsg, getattr3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_setattr3res (struct iovec outmsg, setattr3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_setattr3args (struct iovec inmsg, setattr3args *sa);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_lookup3res (struct iovec outmsg, lookup3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_lookup3args (struct iovec inmsg, lookup3args *la);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_access3args (struct iovec inmsg, access3args *ac);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_access3res (struct iovec outmsg, access3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_readlink3args (struct iovec inmsg, readlink3args *ra);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_readlink3res (struct iovec outmsg, readlink3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_read3args (struct iovec inmsg, read3args *ra);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_read3res (struct iovec outmsg, read3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_read3res_nocopy (struct iovec outmsg, read3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_write3args (struct iovec inmsg, write3args *wa);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_write3args_nocopy (struct iovec inmsg, write3args *wa,
|
||||
struct iovec *payload);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_write3res (struct iovec outmsg, write3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_create3args (struct iovec inmsg, create3args *ca);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_create3res (struct iovec outmsg, create3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_mkdir3res (struct iovec outmsg, mkdir3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_mkdir3args (struct iovec inmsg, mkdir3args *ma);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_symlink3args (struct iovec inmsg, symlink3args *sa);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_symlink3res (struct iovec outmsg, symlink3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_mknod3args (struct iovec inmsg, mknod3args *ma);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_mknod3res (struct iovec outmsg, mknod3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_remove3args (struct iovec inmsg, remove3args *ra);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_remove3res (struct iovec outmsg, remove3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_rmdir3args (struct iovec inmsg, rmdir3args *ra);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_rmdir3res (struct iovec outmsg, rmdir3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_rename3res (struct iovec outmsg, rename3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_rename3args (struct iovec inmsg, rename3args *ra);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_link3res (struct iovec outmsg, link3res *li);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_link3args (struct iovec inmsg, link3args *la);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_readdir3args (struct iovec inmsg, readdir3args *rd);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_readdir3res (struct iovec outmsg, readdir3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_readdirp3args (struct iovec inmsg, readdirp3args *rp);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_readdirp3res (struct iovec outmsg, readdirp3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_fsstat3args (struct iovec inmsg, fsstat3args *fa);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_fsstat3res (struct iovec outmsg, fsstat3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_fsinfo3args (struct iovec inmsg, fsinfo3args *fi);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_fsinfo3res (struct iovec outmsg, fsinfo3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_pathconf3args (struct iovec inmsg, pathconf3args *pc);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_pathconf3res (struct iovec outmsg, pathconf3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_to_commit3args (struct iovec inmsg, commit3args *ca);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_commit3res (struct iovec outmsg, commit3res *res);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_exports (struct iovec outmsg, exports *elist);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_mountlist (struct iovec outmsg, mountlist *ml);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_mountstat3 (struct iovec outmsg, mountstat3 *m);
|
||||
|
||||
extern ssize_t
|
||||
xdr_serialize_nfsstat3 (struct iovec outmsg, nfsstat3 *s);
|
||||
|
||||
extern int
|
||||
xdr_bytes_round_up (struct iovec *vec, size_t bufsize);
|
||||
|
||||
extern ssize_t
|
||||
xdr_length_round_up (size_t len, size_t bufsize);
|
||||
#endif
|
48
xlators/nfs/lib/src/xdr-common.h
Normal file
48
xlators/nfs/lib/src/xdr-common.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
|
||||
This file is part of GlusterFS.
|
||||
|
||||
GlusterFS is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
GlusterFS is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _XDR_COMMON_H_
|
||||
#define _XDR_COMMON_H_
|
||||
|
||||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#define XDR_BYTES_PER_UNIT 4
|
||||
|
||||
/* Returns the address of the byte that follows the
|
||||
* last byte used for decoding the previous xdr component.
|
||||
* For eg, once the RPC call for NFS has been decoded, thie macro will return
|
||||
* the address from which the NFS header starts.
|
||||
*/
|
||||
#define xdr_decoded_remaining_addr(xdr) ((&xdr)->x_private)
|
||||
|
||||
/* Returns the length of the remaining record after the previous decode
|
||||
* operation completed.
|
||||
*/
|
||||
#define xdr_decoded_remaining_len(xdr) ((&xdr)->x_handy)
|
||||
|
||||
/* Returns the number of bytes used by the last encode operation. */
|
||||
#define xdr_encoded_length(xdr) (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base))
|
||||
|
||||
#define xdr_decoded_length(xdr) (((size_t)(&xdr)->x_private) - ((size_t)(&xdr)->x_base))
|
||||
|
||||
#endif
|
1892
xlators/nfs/lib/src/xdr-nfs3.c
Normal file
1892
xlators/nfs/lib/src/xdr-nfs3.c
Normal file
File diff suppressed because it is too large
Load Diff
1205
xlators/nfs/lib/src/xdr-nfs3.h
Normal file
1205
xlators/nfs/lib/src/xdr-nfs3.h
Normal file
File diff suppressed because it is too large
Load Diff
190
xlators/nfs/lib/src/xdr-rpc.c
Normal file
190
xlators/nfs/lib/src/xdr-rpc.c
Normal file
@ -0,0 +1,190 @@
|
||||
/*
|
||||
Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
|
||||
This file is part of GlusterFS.
|
||||
|
||||
GlusterFS is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
GlusterFS is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/pmap_clnt.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <sys/uio.h>
|
||||
#include <rpc/auth_unix.h>
|
||||
|
||||
#include "mem-pool.h"
|
||||
#include "xdr-rpc.h"
|
||||
#include "xdr-common.h"
|
||||
#include "logging.h"
|
||||
|
||||
/* Decodes the XDR format in msgbuf into rpc_msg.
|
||||
* The remaining payload is returned into payload.
|
||||
*/
|
||||
int
|
||||
xdr_to_rpc_call (char *msgbuf, size_t len, struct rpc_msg *call,
|
||||
struct iovec *payload, char *credbytes, char *verfbytes)
|
||||
{
|
||||
XDR xdr;
|
||||
char opaquebytes[MAX_AUTH_BYTES];
|
||||
struct opaque_auth *oa = NULL;
|
||||
|
||||
if ((!msgbuf) || (!call))
|
||||
return -1;
|
||||
|
||||
memset (call, 0, sizeof (*call));
|
||||
|
||||
oa = &call->rm_call.cb_cred;
|
||||
if (!credbytes)
|
||||
oa->oa_base = opaquebytes;
|
||||
else
|
||||
oa->oa_base = credbytes;
|
||||
|
||||
oa = &call->rm_call.cb_verf;
|
||||
if (!verfbytes)
|
||||
oa->oa_base = opaquebytes;
|
||||
else
|
||||
oa->oa_base = verfbytes;
|
||||
|
||||
xdrmem_create (&xdr, msgbuf, len, XDR_DECODE);
|
||||
if (!xdr_callmsg (&xdr, call))
|
||||
return -1;
|
||||
|
||||
if (payload) {
|
||||
payload->iov_base = xdr_decoded_remaining_addr (xdr);
|
||||
payload->iov_len = xdr_decoded_remaining_len (xdr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool_t
|
||||
true_func (XDR *s, caddr_t *a)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
rpc_fill_empty_reply (struct rpc_msg *reply, uint32_t xid)
|
||||
{
|
||||
if (!reply)
|
||||
return -1;
|
||||
|
||||
/* Setting to 0 also results in reply verifier flavor to be
|
||||
* set to AUTH_NULL which is what we want right now.
|
||||
*/
|
||||
memset (reply, 0, sizeof (*reply));
|
||||
reply->rm_xid = xid;
|
||||
reply->rm_direction = REPLY;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
rpc_fill_denied_reply (struct rpc_msg *reply, int rjstat, int auth_err)
|
||||
{
|
||||
if (!reply)
|
||||
return -1;
|
||||
|
||||
reply->rm_reply.rp_stat = MSG_DENIED;
|
||||
reply->rjcted_rply.rj_stat = rjstat;
|
||||
if (rjstat == RPC_MISMATCH) {
|
||||
/* No problem with hardocoding
|
||||
* RPC version numbers. We only support
|
||||
* v2 anyway.
|
||||
*/
|
||||
reply->rjcted_rply.rj_vers.low = 2;
|
||||
reply->rjcted_rply.rj_vers.high = 2;
|
||||
} else if (rjstat == AUTH_ERROR)
|
||||
reply->rjcted_rply.rj_why = auth_err;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
rpc_fill_accepted_reply (struct rpc_msg *reply, int arstat, int proglow,
|
||||
int proghigh, int verf, int len, char *vdata)
|
||||
{
|
||||
if (!reply)
|
||||
return -1;
|
||||
|
||||
reply->rm_reply.rp_stat = MSG_ACCEPTED;
|
||||
reply->acpted_rply.ar_stat = arstat;
|
||||
|
||||
reply->acpted_rply.ar_verf.oa_flavor = verf;
|
||||
reply->acpted_rply.ar_verf.oa_length = len;
|
||||
reply->acpted_rply.ar_verf.oa_base = vdata;
|
||||
if (arstat == PROG_MISMATCH) {
|
||||
reply->acpted_rply.ar_vers.low = proglow;
|
||||
reply->acpted_rply.ar_vers.high = proghigh;
|
||||
} else if (arstat == SUCCESS) {
|
||||
|
||||
/* This is a hack. I'd really like to build a custom
|
||||
* XDR library because Sun RPC interface is not very flexible.
|
||||
*/
|
||||
reply->acpted_rply.ar_results.proc = (xdrproc_t)true_func;
|
||||
reply->acpted_rply.ar_results.where = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
rpc_reply_to_xdr (struct rpc_msg *reply, char *dest, size_t len,
|
||||
struct iovec *dst)
|
||||
{
|
||||
XDR xdr;
|
||||
|
||||
if ((!dest) || (!reply) || (!dst))
|
||||
return -1;
|
||||
|
||||
xdrmem_create (&xdr, dest, len, XDR_ENCODE);
|
||||
if (!xdr_replymsg(&xdr, reply))
|
||||
return -1;
|
||||
|
||||
dst->iov_base = dest;
|
||||
dst->iov_len = xdr_encoded_length (xdr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
xdr_to_auth_unix_cred (char *msgbuf, int msglen, struct authunix_parms *au,
|
||||
char *machname, gid_t *gids)
|
||||
{
|
||||
XDR xdr;
|
||||
|
||||
if ((!msgbuf) || (!machname) || (!gids) || (!au))
|
||||
return -1;
|
||||
|
||||
au->aup_machname = machname;
|
||||
au->aup_gids = gids;
|
||||
|
||||
xdrmem_create (&xdr, msgbuf, msglen, XDR_DECODE);
|
||||
|
||||
if (!xdr_authunix_parms (&xdr, au))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
74
xlators/nfs/lib/src/xdr-rpc.h
Normal file
74
xlators/nfs/lib/src/xdr-rpc.h
Normal file
@ -0,0 +1,74 @@
|
||||
/*
|
||||
Copyright (c) 2010 Gluster, Inc. <http://www.gluster.com>
|
||||
This file is part of GlusterFS.
|
||||
|
||||
GlusterFS is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
GlusterFS is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _XDR_RPC_H
|
||||
#define _XDR_RPC_H_
|
||||
|
||||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/pmap_clnt.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <rpc/xdr.h>
|
||||
#include <sys/uio.h>
|
||||
|
||||
/* Converts a given network buffer from its XDR format to a structure
|
||||
* that contains everything an RPC call needs to work.
|
||||
*/
|
||||
extern int
|
||||
xdr_to_rpc_call (char *msgbuf, size_t len, struct rpc_msg *call,
|
||||
struct iovec *payload, char *credbytes, char *verfbytes);
|
||||
|
||||
extern int
|
||||
rpc_fill_empty_reply (struct rpc_msg *reply, uint32_t xid);
|
||||
|
||||
extern int
|
||||
rpc_fill_denied_reply (struct rpc_msg *reply, int rjstat, int auth_err);
|
||||
|
||||
extern int
|
||||
rpc_fill_accepted_reply (struct rpc_msg *reply, int arstat, int proglow,
|
||||
int proghigh, int verf, int len, char *vdata);
|
||||
extern int
|
||||
rpc_reply_to_xdr (struct rpc_msg *reply, char *dest, size_t len,
|
||||
struct iovec *dst);
|
||||
|
||||
extern int
|
||||
xdr_to_auth_unix_cred (char *msgbuf, int msglen, struct authunix_parms *au,
|
||||
char *machname, gid_t *gids);
|
||||
/* Macros that simplify accesing the members of an RPC call structure. */
|
||||
#define rpc_call_xid(call) ((call)->rm_xid)
|
||||
#define rpc_call_direction(call) ((call)->rm_direction)
|
||||
#define rpc_call_rpcvers(call) ((call)->ru.RM_cmb.cb_rpcvers)
|
||||
#define rpc_call_program(call) ((call)->ru.RM_cmb.cb_prog)
|
||||
#define rpc_call_progver(call) ((call)->ru.RM_cmb.cb_vers)
|
||||
#define rpc_call_progproc(call) ((call)->ru.RM_cmb.cb_proc)
|
||||
#define rpc_opaque_auth_flavour(oa) ((oa)->oa_flavor)
|
||||
#define rpc_opaque_auth_len(oa) ((oa)->oa_length)
|
||||
|
||||
#define rpc_call_cred_flavour(call) (rpc_opaque_auth_flavour ((&(call)->ru.RM_cmb.cb_cred)))
|
||||
#define rpc_call_cred_len(call) (rpc_opaque_auth_len ((&(call)->ru.RM_cmb.cb_cred)))
|
||||
|
||||
|
||||
#define rpc_call_verf_flavour(call) (rpc_opaque_auth_flavour ((&(call)->ru.RM_cmb.cb_verf)))
|
||||
#define rpc_call_verf_len(call) (rpc_opaque_auth_len ((&(call)->ru.RM_cmb.cb_verf)))
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user