nfs: Add NFSv3 protocol support

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:
Shehjar Tikoo 2010-03-31 07:27:05 +00:00 committed by Anand V. Avati
parent e63053803d
commit f66f04e3af
6 changed files with 8215 additions and 2 deletions

View File

@ -2,10 +2,10 @@ xlator_LTLIBRARIES = server.la
xlatordir = $(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator/nfs
rpclibdir = $(top_srcdir)/xlators/nfs/lib/src/
server_la_LDFLAGS = -module -avoidversion
server_la_SOURCES = nfs.c nfs-common.c nfs-fops.c nfs-inodes.c nfs-generics.c mount3.c nfs3-fh.c
server_la_SOURCES = nfs.c nfs-common.c nfs-fops.c nfs-inodes.c nfs-generics.c mount3.c nfs3-fh.c nfs3.c nfs3-helpers.c
server_la_LIBADD = $(top_builddir)/xlators/nfs/lib/src/librpcsvc.la $(top_builddir)/libglusterfs/src/libglusterfs.la
noinst_HEADERS = nfs.h nfs-common.h nfs-fops.h nfs-inodes.h nfs-generics.h mount3.h nfs3-fh.h
noinst_HEADERS = nfs.h nfs-common.h nfs-fops.h nfs-inodes.h nfs-generics.h mount3.h nfs3-fh.h nfs3.h nfs3-helpers.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)\

View File

@ -37,6 +37,7 @@
#include "nfs-fops.h"
#include "inode.h"
#include "mount3.h"
#include "nfs3.h"
/* Every NFS version must call this function with the init function
* for its particular version.
@ -152,6 +153,13 @@ nfs_add_all_initiators (struct nfs_state *nfs)
goto ret;
}
ret = nfs_add_initer (&nfs->versions, nfs3svc_init);
if (ret == -1) {
gf_log (GF_NFS, GF_LOG_ERROR, "Failed to add protocol"
" initializer");
goto ret;
}
ret = 0;
ret:
return ret;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,342 @@
/*
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 _NFS3_HELPER_H_
#define _NFS3_HELPER_H_
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif
#include "xlator.h"
#include "nfs3.h"
#include "nfs3-fh.h"
#include "msg-nfs3.h"
#include "xdr-nfs3.h"
#include <sys/statvfs.h>
#define GF_NFS3_FD_CACHED 0xcaced
extern struct nfs3_fh
nfs3_extract_lookup_fh (lookup3args *args);
extern char *
nfs3_extract_lookup_name (lookup3args *args);
extern nfsstat3
nfs3_errno_to_nfsstat3 (int errnum);
extern void
nfs3_fill_lookup3res (lookup3res *res, nfsstat3 stat, struct nfs3_fh *newfh,
struct iatt *stbuf, struct iatt *postparent);
extern post_op_attr
nfs3_stat_to_post_op_attr (struct iatt *buf);
extern struct nfs3_fh
nfs3_extract_getattr_fh (getattr3args *args);
extern void
nfs3_fill_getattr3res (getattr3res *res, nfsstat3 stat, struct iatt *buf,
uint16_t xlid);
extern struct nfs3_fh
nfs3_extract_fsinfo_fh (fsinfo3args *args);
extern void
nfs3_fill_fsinfo3res (struct nfs3_state *nfs3, fsinfo3res *res,
nfsstat3 status, struct iatt *fsroot, uint16_t xlid);
/* Functions containing _prep_ are used specifically to work around
* the memory allocations that happen inside Sun RPC library.
* In that library, there are numerous places where every NFS request
* can result in really tiny malloc calls. I fear the memory fragmentation
* that will follow. After studying the points at and the way in which malloc
* is called in Sun RPC, I've come up with this work-around. It is based on
* the idea that if the user/caller of the xdr_to_XXXXargs functions can provide
* already allocated memory or provide references to memory areas on its stack
* just for the short-term purpose of decoding the message from XDR format, we
* can avoid the memory allocations in Sun RPC. This is based on the fact
* that Sun RPC first checks whether structure members which require memory
* are NULL or not and only then calls malloc. In this case, if the caller
* provided references are non-NULL, then the if-branches containing malloc
* in Sun RPC will be avoided.
* PS: You're not expected to understand this unless you've spent some time
* looking through the glibc/sunrpc sources.
*/
extern void
nfs3_prep_lookup3args (lookup3args *args, struct nfs3_fh *fh, char *name);
extern void
nfs3_prep_getattr3args (getattr3args *args, struct nfs3_fh *fh);
extern void
nfs3_prep_fsinfo3args (fsinfo3args *args, struct nfs3_fh *root);
extern char *
nfsstat3_strerror(int stat);
extern void
nfs3_prep_access3args (access3args *args, struct nfs3_fh *fh);
extern void
nfs3_fill_access3res (access3res *res, nfsstat3 status, struct iatt *buf,
uint32_t accbits, uid_t uid, gid_t gid, uint16_t xlid);
extern char *
nfs3_fhcache_getpath (struct nfs3_state *nfs3, struct nfs3_fh *fh);
extern int
nfs3_fhcache_putpath (struct nfs3_state *nfs3, struct nfs3_fh *fh, char *path);
extern void
nfs3_prep_readdir3args (readdir3args *ra, struct nfs3_fh *fh);
extern void
nfs3_fill_readdir3res (readdir3res *res, nfsstat3 stat, uint64_t cverf,
struct iatt *dirstat, gf_dirent_t *entries,count3 count,
int is_eof, uint16_t xlid);
extern void
nfs3_prep_readdirp3args (readdirp3args *ra, struct nfs3_fh *fh);
extern void
nfs3_fill_readdirp3res (readdirp3res *res, nfsstat3 stat, struct nfs3_fh *dirfh,
uint64_t cverf, struct iatt *dirstat,
gf_dirent_t *entries, count3 dircount, count3 maxcount,
int is_eof);
extern void
nfs3_free_readdirp3res (readdirp3res *res);
extern void
nfs3_free_readdir3res (readdir3res *res);
extern void
nfs3_prep_fsstat3args (fsstat3args *args, struct nfs3_fh *fh);
extern void
nfs3_fill_fsstat3res (fsstat3res *res, nfsstat3 stat, struct statvfs *fsbuf,
struct iatt *postbuf, uint16_t xlid);
extern int32_t
nfs3_sattr3_to_setattr_valid (sattr3 *sattr, struct iatt *buf, mode_t *omode);
extern void
nfs3_fill_create3res (create3res *res, nfsstat3 stat, struct nfs3_fh *newfh,
struct iatt *newbuf, struct iatt *preparent,
struct iatt *postparent);
extern void
nfs3_prep_create3args (create3args *args, struct nfs3_fh *fh, char *name);
extern void
nfs3_prep_setattr3args (setattr3args *args, struct nfs3_fh *fh);
extern void
nfs3_fill_setattr3res (setattr3res *res, nfsstat3 stat, struct iatt *preop,
struct iatt *postop, uint16_t xlid);
extern void
nfs3_prep_mkdir3args (mkdir3args *args, struct nfs3_fh *dirfh, char *name);
extern void
nfs3_fill_mkdir3res (mkdir3res *res, nfsstat3 stat, struct nfs3_fh *fh,
struct iatt *buf, struct iatt *preparent,
struct iatt *postparent);
extern void
nfs3_prep_symlink3args (symlink3args *args, struct nfs3_fh *dirfh, char *name,
char *target);
extern void
nfs3_fill_symlink3res (symlink3res *res, nfsstat3 stat, struct nfs3_fh *fh,
struct iatt *buf, struct iatt *preparent,
struct iatt *postparent);
extern void
nfs3_prep_readlink3args (readlink3args *args, struct nfs3_fh *fh);
extern void
nfs3_fill_readlink3res (readlink3res *res, nfsstat3 stat, char *path,
struct iatt *buf, uint16_t xlid);
extern void
nfs3_prep_mknod3args (mknod3args *args, struct nfs3_fh *fh, char *name);
extern void
nfs3_fill_mknod3res (mknod3res *res, nfsstat3 stat, struct nfs3_fh *fh,
struct iatt *buf, struct iatt *preparent,
struct iatt *postparent);
extern void
nfs3_fill_remove3res (remove3res *res, nfsstat3 stat, struct iatt *preparent,
struct iatt *postparent, uint16_t xlid);
extern void
nfs3_prep_remove3args (remove3args *args, struct nfs3_fh *fh, char *name);
extern void
nfs3_fill_rmdir3res (rmdir3res *res, nfsstat3 stat, struct iatt *preparent,
struct iatt *postparent, uint16_t xlid);
extern void
nfs3_prep_rmdir3args (rmdir3args *args, struct nfs3_fh *fh, char *name);
extern void
nfs3_fill_link3res (link3res *res, nfsstat3 stat, struct iatt *buf,
struct iatt *preparent, struct iatt *postparent,
uint16_t xlid);
extern void
nfs3_prep_link3args (link3args *args, struct nfs3_fh *target,
struct nfs3_fh * dirfh, char *name);
extern void
nfs3_prep_rename3args (rename3args *args, struct nfs3_fh *olddirfh,
char *oldname, struct nfs3_fh *newdirfh,
char *newname);
extern void
nfs3_fill_rename3res (rename3res *res, nfsstat3 stat, struct iatt *buf,
struct iatt *preoldparent, struct iatt *postoldparent,
struct iatt *prenewparent, struct iatt *postnewparent,
uint16_t xlid);
extern void
nfs3_prep_write3args (write3args *args, struct nfs3_fh *fh);
extern void
nfs3_fill_write3res (write3res *res, nfsstat3 stat, count3 count,
stable_how stable, uint64_t wverf, struct iatt *prestat,
struct iatt *poststat, uint16_t xlid);
extern void
nfs3_prep_commit3args (commit3args *args, struct nfs3_fh *fh);
extern void
nfs3_fill_commit3res (commit3res *res, nfsstat3 stat, uint64_t wverf,
struct iatt *prestat, struct iatt *poststat,
uint16_t xlid);
extern void
nfs3_fill_read3res (read3res *res, nfsstat3 stat, count3 count,
struct iatt *poststat, int is_eof, uint16_t xlid);
extern void
nfs3_prep_read3args (read3args *args, struct nfs3_fh *fh);
extern void
nfs3_prep_pathconf3args (pathconf3args *args, struct nfs3_fh *fh);
extern void
nfs3_fill_pathconf3res (pathconf3res *res, nfsstat3 stat, struct iatt *buf,
uint16_t xlid);
extern int
nfs3_cached_inode_opened (xlator_t *nfsxl, inode_t *inode);
extern void
nfs3_log_common_res (uint32_t xid, char *op, nfsstat3 stat, int pstat);
extern void
nfs3_log_readlink_res (uint32_t xid, nfsstat3 stat, int pstat, char *linkpath);
extern void
nfs3_log_read_res (uint32_t xid, nfsstat3 stat, int pstat, count3 count,
int is_eof);
extern void
nfs3_log_write_res (uint32_t xid, nfsstat3 stat, int pstat, count3 count,
int stable, uint64_t wverf);
extern void
nfs3_log_newfh_res (uint32_t xid, char *op, nfsstat3 stat, int pstat,
struct nfs3_fh *newfh);
extern void
nfs3_log_readdir_res (uint32_t xid, nfsstat3 stat, int pstat, uint64_t cverf,
count3 count, int is_eof);
extern void
nfs3_log_readdirp_res (uint32_t xid, nfsstat3 stat, int pstat, uint64_t cverf,
count3 dircount, count3 maxcount, int is_eof);
extern void
nfs3_log_commit_res (uint32_t xid, nfsstat3 stat, int pstat, uint64_t wverf);
extern void
nfs3_log_common_call (uint32_t xid, char *op, struct nfs3_fh *fh);
extern void
nfs3_log_fh_entry_call (uint32_t xid, char *op, struct nfs3_fh *fh,
char *name);
extern void
nfs3_log_rw_call (uint32_t xid, char *op, struct nfs3_fh *fh, offset3 offt,
count3 count, int stablewrite);
extern void
nfs3_log_create_call (uint32_t xid, struct nfs3_fh *fh, char *name,
createmode3 mode);
extern void
nfs3_log_symlink_call (uint32_t xid, struct nfs3_fh *fh, char *name, char *tgt);
extern void
nfs3_log_mknod_call (uint32_t xid, struct nfs3_fh *fh, char *name, int type);
extern void
nfs3_log_rename_call (uint32_t xid, struct nfs3_fh *src, char *sname,
struct nfs3_fh *dst, char *dname);
extern void
nfs3_log_link_call (uint32_t xid, struct nfs3_fh *fh, char *name,
struct nfs3_fh *tgt);
extern void
nfs3_log_readdir_call (uint32_t xid, struct nfs3_fh *fh, count3 dircount,
count3 maxcount);
extern int
nfs3_fh_resolve_entry_hard (nfs3_call_state_t *cs);
extern int
nfs3_fh_resolve_inode (nfs3_call_state_t *cs);
extern int
nfs3_fh_resolve_entry (nfs3_call_state_t *cs);
extern int
nfs3_fh_resolve_and_resume (nfs3_call_state_t *cs, struct nfs3_fh *fh,
char *entry, nfs3_resume_fn_t resum_fn);
extern int
nfs3_file_open_and_resume (nfs3_call_state_t *cs, nfs3_resume_fn_t resume);
extern int
nfs3_dir_open_and_resume (nfs3_call_state_t *cs, nfs3_resume_fn_t resume);
extern int
nfs3_verify_dircookie (struct nfs3_state *nfs3, fd_t *dirfd, cookie3 cookie,
uint64_t cverf, nfsstat3 *stat);
extern int
nfs3_fdcache_remove (struct nfs3_state *nfs3, fd_t *fd);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,202 @@
/*
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 _NFS3_H_
#define _NFS3_H_
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif
#include "rpcsvc.h"
#include "dict.h"
#include "xlator.h"
#include "iobuf.h"
#include "nfs.h"
#include "nfs3-fh.h"
#include "nfs-common.h"
#include "xdr-nfs3.h"
#include "mem-pool.h"
#include <sys/statvfs.h>
#define GF_NFS3 GF_NFS"-nfsv3"
#define GF_NFS3_PORT 38467
#define GF_NFS3_DEFAULT_MEMFACTOR 15
#define GF_NFS3_IOBPOOL_MULT GF_NFS_CONCURRENT_OPS_MULT
#define GF_NFS3_CLTABLE_BUCKETS_MULT 2
#define GF_NFS3_FDTABLE_BUCKETS_MULT 2
/* Static values used for FSINFO
FIXME: This should be configurable */
#define GF_NFS3_RTMAX (64 * GF_UNIT_KB)
#define GF_NFS3_RTPREF (64 * GF_UNIT_KB)
#define GF_NFS3_RTMULT (4 * GF_UNIT_KB)
#define GF_NFS3_WTMAX (64 * GF_UNIT_KB)
#define GF_NFS3_WTPREF (64 * GF_UNIT_KB)
#define GF_NFS3_WTMULT (4 * GF_UNIT_KB)
#define GF_NFS3_DTMIN (4 * GF_UNIT_KB)
#define GF_NFS3_DTPREF (64 * GF_UNIT_KB)
#define GF_NFS3_MAXFILE (1 * GF_UNIT_PB)
/* FIXME: Handle time resolutions */
#define GF_NFS3_TIMEDELTA_SECS {1,0}
#define GF_NFS3_TIMEDELTA_NSECS {0,1}
#define GF_NFS3_TIMEDELTA_MSECS {0,1000000}
#define GF_NFS3_FS_PROP (FSF3_LINK | FSF3_SYMLINK | FSF3_HOMOGENEOUS | FSF3_CANSETTIME)
#define GF_NFS3_DIRFD_VALID 1
#define GF_NFS3_DIRFD_INVALID 0
#define GF_NFS3_VOLACCESS_RW 1
#define GF_NFS3_VOLACCESS_RO 2
#define GF_NFS3_FDCACHE_SIZE 512
/* This should probably be moved to a more generic layer so that if needed
* different versions of NFS protocol can use the same thing.
*/
struct nfs3_fd_entry {
fd_t *cachedfd;
struct list_head list;
};
/* Per subvolume nfs3 specific state */
struct nfs3_export {
xlator_t *subvol;
int access;
};
#define GF_NFS3_DEFAULT_VOLACCESS (GF_NFS3_VOLACCESS_RW)
/* The NFSv3 protocol state */
struct nfs3_state {
/* The NFS xlator pointer. The NFS xlator can be running
* multiple versions of the NFS protocol.
*/
xlator_t *nfsx;
/* The iob pool from which memory allocations are made for receiving
* and sending network messages.
*/
struct iobuf_pool *iobpool;
/* List of child subvolumes for the NFSv3 protocol.
* Right now, is simply referring to the list of children in nfsx above.
*/
xlator_list_t *exportslist;
struct nfs3_export *exports;
/* Mempool for allocations of struct nfs3_local */
struct mem_pool *localpool;
/* Server start-up timestamp, currently used for write verifier. */
uint64_t serverstart;
/* NFSv3 Protocol configurables */
size_t readsize;
size_t writesize;
size_t readdirsize;
/* Size of the iobufs used, depends on the sizes of the three params
* above.
*/
size_t iobsize;
unsigned int memfactor;
struct list_head fdlru;
gf_lock_t fdlrulock;
int fdcount;
};
typedef int (*nfs3_resume_fn_t) (void *cs);
/* Structure used to communicate state between a fop and its callback.
* Not all members are used at all times. Usage is fop and NFS request
* dependent.
*
* I wish we could have a smaller structure for communicating state
* between callers and callbacks. It could be broken into smaller parts
* but I feel that will lead to a proliferation of types/structures and then
* we'll just be tracking down which structure is used by which fop, not
* to mention that having one type allows me to used a single mem-pool.
* Imagine the chaos if we need a mem-pool for each one of those sub-structures.
*/
struct nfs3_local {
rpcsvc_request_t *req;
xlator_t *vol;
nfs3_resume_fn_t resume_fn;
xlator_t *nfsx;
/* The list hook to attach this call state to the inode's queue till
* the opening of the fd on the inode completes.
*/
struct list_head openwait_q;
/* Per-NFSv3 Op state */
struct nfs3_fh parent;
struct nfs3_fh fh;
fd_t *fd;
uint32_t accessbits;
int operrno;
count3 dircount;
count3 maxcount;
struct statvfs fsstat;
gf_dirent_t entries;
struct iatt stbuf;
struct iatt preparent;
struct iatt postparent;
int32_t setattr_valid;
nfstime3 timestamp;
loc_t oploc;
int writetype;
count3 datacount;
offset3 dataoffset;
struct iobuf *iob;
createmode3 createmode;
uint64_t cookieverf;
int sattrguardcheck;
char *pathname;
ftype3 mknodtype;
specdata3 devnums;
cookie3 cookie;
struct iovec datavec;
mode_t mode;
/* NFSv3 FH resolver state */
struct nfs3_fh resolvefh;
loc_t resolvedloc;
int resolve_ret;
int resolve_errno;
int hashidx;
fd_t *resolve_dir_fd;
char *resolventry;
};
typedef struct nfs3_local nfs3_call_state_t;
extern rpcsvc_program_t *
nfs3svc_init (xlator_t *nfsx);
#endif