summaryrefslogtreecommitdiffstats
path: root/sys/nfsserver
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2001-09-18 23:32:09 +0000
committerpeter <peter@FreeBSD.org>2001-09-18 23:32:09 +0000
commit85182a8d785d189f1e845c7d66810e3977ac161b (patch)
tree626c88f61c1e52e9cd18eaec61b54aaaee5d3bfc /sys/nfsserver
parentabe9cf18de01077e00cd2ee3d47363af647e65e4 (diff)
downloadFreeBSD-src-85182a8d785d189f1e845c7d66810e3977ac161b.zip
FreeBSD-src-85182a8d785d189f1e845c7d66810e3977ac161b.tar.gz
Cleanup and split of nfs client and server code.
This builds on the top of several repo-copies.
Diffstat (limited to 'sys/nfsserver')
-rw-r--r--sys/nfsserver/nfs.h530
-rw-r--r--sys/nfsserver/nfs_serv.c853
-rw-r--r--sys/nfsserver/nfs_srvcache.c72
-rw-r--r--sys/nfsserver/nfs_srvsock.c1807
-rw-r--r--sys/nfsserver/nfs_srvsubs.c1399
-rw-r--r--sys/nfsserver/nfs_syscalls.c694
-rw-r--r--sys/nfsserver/nfsm_subs.h561
-rw-r--r--sys/nfsserver/nfsrvcache.h8
-rw-r--r--sys/nfsserver/nfsrvstats.h680
9 files changed, 1076 insertions, 5528 deletions
diff --git a/sys/nfsserver/nfs.h b/sys/nfsserver/nfs.h
index da808f4..93e56eb 100644
--- a/sys/nfsserver/nfs.h
+++ b/sys/nfsserver/nfs.h
@@ -37,8 +37,8 @@
* $FreeBSD$
*/
-#ifndef _NFS_NFS_H_
-#define _NFS_NFS_H_
+#ifndef _NFSSERVER_NFS_H_
+#define _NFSSERVER_NFS_H_
#ifdef _KERNEL
#include "opt_nfs.h"
@@ -48,41 +48,16 @@
* Tunable constants for nfs
*/
-#define NFS_MAXIOVEC 34
#define NFS_TICKINTVL 5 /* Desired time for a tick (msec) */
#define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */
#define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */
#define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */
#define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */
#define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/
-#define NFS_MAXREXMIT 100 /* Stop counting after this many */
-#define NFS_MAXWINDOW 1024 /* Max number of outstanding requests */
-#define NFS_RETRANS 10 /* Num of retrans for soft mounts */
-#define NFS_MAXGRPS 16 /* Max. size of groups list */
-#ifndef NFS_MINATTRTIMO
-#define NFS_MINATTRTIMO 3 /* VREG attrib cache timeout in sec */
-#endif
-#ifndef NFS_MAXATTRTIMO
-#define NFS_MAXATTRTIMO 60
-#endif
-#ifndef NFS_MINDIRATTRTIMO
-#define NFS_MINDIRATTRTIMO 30 /* VDIR attrib cache timeout in sec */
-#endif
-#ifndef NFS_MAXDIRATTRTIMO
-#define NFS_MAXDIRATTRTIMO 60
-#endif
-#define NFS_WSIZE 8192 /* Def. write data size <= 8192 */
-#define NFS_RSIZE 8192 /* Def. read data size <= 8192 */
-#define NFS_READDIRSIZE 8192 /* Def. readdir size */
-#define NFS_DEFRAHEAD 1 /* Def. read ahead # blocks */
-#define NFS_MAXRAHEAD 4 /* Max. read ahead # blocks */
#define NFS_MAXUIDHASH 64 /* Max. # of hashed uid entries/mp */
-#define NFS_MAXASYNCDAEMON 20 /* Max. number async_daemons runnable */
-#define NFS_MAXGATHERDELAY 100 /* Max. write gather delay (msec) */
#ifndef NFS_GATHERDELAY
#define NFS_GATHERDELAY 10 /* Default write gather delay (msec) */
#endif
-#define NFS_DIRBLKSIZ 4096 /* Must be a multiple of DIRBLKSIZ */
#ifdef _KERNEL
#define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
#endif
@@ -90,10 +65,6 @@
/*
* Oddballs
*/
-#define NMOD(a) ((a) % nfs_asyncdaemons)
-#define NFS_CMPFH(n, f, s) \
- ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
-#define NFS_ISV3(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
#define NFS_SRVMAXDATA(n) \
(((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
@@ -113,75 +84,10 @@
#define IO_METASYNC 0
#endif
-/*
- * Arguments to mount NFS
- */
-#define NFS_ARGSVERSION 3 /* change when nfs_args changes */
-struct nfs_args {
- int version; /* args structure version number */
- struct sockaddr *addr; /* file server address */
- int addrlen; /* length of address */
- int sotype; /* Socket type */
- int proto; /* and Protocol */
- u_char *fh; /* File handle to be mounted */
- int fhsize; /* Size, in bytes, of fh */
- int flags; /* flags */
- int wsize; /* write size in bytes */
- int rsize; /* read size in bytes */
- int readdirsize; /* readdir size in bytes */
- int timeo; /* initial timeout in .1 secs */
- int retrans; /* times to retry send */
- int maxgrouplist; /* Max. size of group list */
- int readahead; /* # of blocks to readahead */
- int leaseterm; /* Term (sec) of lease */
- int deadthresh; /* Retrans threshold */
- char *hostname; /* server's name */
- int acregmin; /* cache attrs for reg files min time */
- int acregmax; /* cache attrs for reg files max time */
- int acdirmin; /* cache attrs for dirs min time */
- int acdirmax; /* cache attrs for dirs max time */
-};
-/*
- * NFS mount option flags
- */
-#define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */
-#define NFSMNT_WSIZE 0x00000002 /* set write size */
-#define NFSMNT_RSIZE 0x00000004 /* set read size */
-#define NFSMNT_TIMEO 0x00000008 /* set initial timeout */
-#define NFSMNT_RETRANS 0x00000010 /* set number of request retries */
-#define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */
-#define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */
-#define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */
-#define NFSMNT_NQNFS 0x00000100 /* Use Nqnfs protocol */
-#define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */
-#define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */
-#define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */
-#define NFSMNT_LEASETERM 0x00001000 /* set lease term (nqnfs) */
-#define NFSMNT_READAHEAD 0x00002000 /* set read ahead */
-#define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */
-#define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */
-#define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */
-#define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */
-#define NFSMNT_ACREGMIN 0x00040000
-#define NFSMNT_ACREGMAX 0x00080000
-#define NFSMNT_ACDIRMIN 0x00100000
-#define NFSMNT_ACDIRMAX 0x00200000
-
-#define NFSSTA_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */
-#define NFSSTA_GOTPATHCONF 0x00080000 /* Got the V3 pathconf info */
-#define NFSSTA_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */
-#define NFSSTA_MNTD 0x00200000 /* Mnt server for mnt point */
-#define NFSSTA_DISMINPROG 0x00400000 /* Dismount in progress */
-#define NFSSTA_DISMNT 0x00800000 /* Dismounted */
-#define NFSSTA_SNDLOCK 0x01000000 /* Send socket lock */
-#define NFSSTA_WANTSND 0x02000000 /* Want above */
-#define NFSSTA_RCVLOCK 0x04000000 /* Rcv socket lock */
-#define NFSSTA_WANTRCV 0x08000000 /* Want above */
-#define NFSSTA_WAITAUTH 0x10000000 /* Wait for authentication */
-#define NFSSTA_HASAUTH 0x20000000 /* Has authenticator */
-#define NFSSTA_WANTAUTH 0x40000000 /* Wants an authenticator */
-#define NFSSTA_AUTHERR 0x80000000 /* Authentication error */
+/* NFS state flags XXX -Wunused */
+#define NFSRV_SNDLOCK 0x01000000 /* Send socket lock */
+#define NFSRV_WANTSND 0x02000000 /* Want above */
/*
* Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
@@ -204,7 +110,6 @@ struct nfsd_srvargs {
u_char *nsd_verfstr;
struct timeval nsd_timestamp; /* timestamp from verifier */
u_int32_t nsd_ttl; /* credential ttl (sec) */
- NFSKERBKEY_T nsd_key; /* Session key */
};
struct nfsd_cargs {
@@ -215,180 +120,69 @@ struct nfsd_cargs {
u_char *ncd_authstr; /* Authenticator string */
u_int ncd_verflen; /* and the verifier */
u_char *ncd_verfstr;
- NFSKERBKEY_T ncd_key; /* Session key */
};
/*
* XXX to allow amd to include nfs.h without nfsproto.h
*/
#ifdef NFS_NPROCS
-/*
- * Stats structure
- */
-struct nfsstats {
- int attrcache_hits;
- int attrcache_misses;
- int lookupcache_hits;
- int lookupcache_misses;
- int direofcache_hits;
- int direofcache_misses;
- int biocache_reads;
- int read_bios;
- int read_physios;
- int biocache_writes;
- int write_bios;
- int write_physios;
- int biocache_readlinks;
- int readlink_bios;
- int biocache_readdirs;
- int readdir_bios;
- int rpccnt[NFS_NPROCS];
- int rpcretries;
- int srvrpccnt[NFS_NPROCS];
- int srvrpc_errs;
- int srv_errs;
- int rpcrequests;
- int rpctimeouts;
- int rpcunexpected;
- int rpcinvalid;
- int srvcache_inproghits;
- int srvcache_idemdonehits;
- int srvcache_nonidemdonehits;
- int srvcache_misses;
- int srvnqnfs_leases;
- int srvnqnfs_maxleases;
- int srvnqnfs_getleases;
- int srvvop_writes;
- int accesscache_hits;
- int accesscache_misses;
-};
+#include <nfsserver/nfsrvstats.h>
#endif
/*
* Flags for nfssvc() system call.
*/
-#define NFSSVC_BIOD 0x002
#define NFSSVC_NFSD 0x004
#define NFSSVC_ADDSOCK 0x008
-#define NFSSVC_AUTHIN 0x010
-#define NFSSVC_GOTAUTH 0x040
-#define NFSSVC_AUTHINFAIL 0x080
-#define NFSSVC_MNTD 0x100
-#define NFSSVC_LOCKDANS 0x200
/*
- * fs.nfs sysctl(3) identifiers
+ * vfs.nfsrv sysctl(3) identifiers
*/
-#define NFS_NFSSTATS 1 /* struct: struct nfsstats */
+#define NFS_NFSRVSTATS 1 /* struct: struct nfsrvstats */
#define NFS_NFSPRIVPORT 2 /* int: prohibit nfs to resvports */
-#define FS_NFS_NAMES { \
- { 0, 0 }, \
- { "nfsstats", CTLTYPE_STRUCT }, \
- { "nfsprivport", CTLTYPE_INT }, \
-}
-
#ifdef _KERNEL
#ifdef MALLOC_DECLARE
-MALLOC_DECLARE(M_NFSREQ);
-MALLOC_DECLARE(M_NFSDIROFF);
MALLOC_DECLARE(M_NFSRVDESC);
-MALLOC_DECLARE(M_NFSUID);
-MALLOC_DECLARE(M_NQLEASE);
MALLOC_DECLARE(M_NFSD);
-MALLOC_DECLARE(M_NFSBIGFH);
-MALLOC_DECLARE(M_NFSHASH);
#endif
-#ifdef ZONE_INTERRUPT
-extern vm_zone_t nfsmount_zone;
-#endif
+/* Forward declarations */
+struct nfssvc_sock;
+struct nfsrv_descript;
+struct uio;
+struct vattr;
+struct nameidata;
-extern struct callout_handle nfs_timer_handle;
+extern struct callout_handle nfsrv_timer_handle;
+extern struct nfsrvstats nfsrvstats;
-struct uio; struct buf; struct vattr; struct nameidata; /* XXX */
+extern int nfs_ticks;
+extern int nfsrvw_procrastinate;
+extern int nfsrvw_procrastinate_v3;
-/*
- * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
- * What should be in this set is open to debate, but I believe that since
- * I/O system calls on ufs are never interrupted by signals the set should
- * be minimal. My reasoning is that many current programs that use signals
- * such as SIGALRM will not expect file I/O system calls to be interrupted
- * by them and break.
- */
-#define NFSINT_SIGMASK(set) \
- (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \
- SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \
- SIGISMEMBER(set, SIGQUIT))
-
-/*
- * Socket errors ignored for connectionless sockets??
- * For now, ignore them all
- */
-#define NFSIGNORE_SOERROR(s, e) \
- ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
- ((s) & PR_CONNREQUIRED) == 0)
-
-/*
- * Nfs outstanding request list element
- */
-struct nfsreq {
- TAILQ_ENTRY(nfsreq) r_chain;
- struct mbuf *r_mreq;
- struct mbuf *r_mrep;
- struct mbuf *r_md;
- caddr_t r_dpos;
- struct nfsmount *r_nmp;
- struct vnode *r_vp;
- u_int32_t r_xid;
- int r_flags; /* flags on request, see below */
- int r_retry; /* max retransmission count */
- int r_rexmit; /* current retrans count */
- int r_timer; /* tick counter on reply */
- u_int32_t r_procnum; /* NFS procedure number */
- int r_rtt; /* RTT for rpc */
- struct thread *r_td; /* Proc that did I/O system call */
-};
+/* Various values converted to XDR form. */
+extern u_int32_t nfs_false, nfs_true, nfs_xdrneg1, nfs_prog;
+extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers;
+extern u_int32_t rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr;
-/*
- * Queue head for nfsreq's
- */
-extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
-
-/* Flag values for r_flags */
-#define R_TIMING 0x01 /* timing request (in mntp) */
-#define R_SENT 0x02 /* request has been sent */
-#define R_SOFTTERM 0x04 /* soft mnt, too many retries */
-#define R_INTR 0x08 /* intr mnt, signal pending */
-#define R_SOCKERR 0x10 /* Fatal error on socket */
-#define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */
-#define R_MUSTRESEND 0x40 /* Must resend request */
-#define R_GETONEREP 0x80 /* Probe for one reply only */
+/* Procedure table data */
+extern int nfsrvv2_procid[NFS_NPROCS];
+extern int nfsv3_procid[NFS_NPROCS];
+extern int32_t (*nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *nd,
+ struct nfssvc_sock *slp, struct thread *td,
+ struct mbuf **mreqp);
/*
* A list of nfssvc_sock structures is maintained with all the sockets
* that require service by the nfsd.
- * The nfsuid structs hang off of the nfssvc_sock structs in both lru
- * and uid hash lists.
*/
-#ifndef NFS_UIDHASHSIZ
-#define NFS_UIDHASHSIZ 29 /* Tune the size of nfssvc_sock with this */
-#endif
-#define NUIDHASH(sock, uid) \
- (&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
#ifndef NFS_WDELAYHASHSIZ
#define NFS_WDELAYHASHSIZ 16 /* and with this */
#endif
#define NWDELAYHASH(sock, f) \
(&(sock)->ns_wdelayhashtbl[(*((u_int32_t *)(f))) % NFS_WDELAYHASHSIZ])
-#ifndef NFS_MUIDHASHSIZ
-#define NFS_MUIDHASHSIZ 63 /* Tune the size of nfsmount with this */
-#endif
-#define NMUIDHASH(nmp, uid) \
- (&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
-#define NFSNOHASH(fhsum) \
- (&nfsnodehashtbl[(fhsum) & nfsnodehash])
/*
* Network address hash list element
@@ -398,18 +192,6 @@ union nethostaddr {
struct sockaddr *had_nam;
};
-struct nfsuid {
- TAILQ_ENTRY(nfsuid) nu_lru; /* LRU chain */
- LIST_ENTRY(nfsuid) nu_hash; /* Hash list */
- int nu_flag; /* Flags */
- union nethostaddr nu_haddr; /* Host addr. for dgram sockets */
- struct ucred nu_cr; /* Cred uid mapped to */
- int nu_expire; /* Expiry time (sec) */
- struct timeval nu_timestamp; /* Kerb. timestamp */
- u_int32_t nu_nickname; /* Nickname on server */
- NFSKERBKEY_T nu_key; /* and session key */
-};
-
#define nu_inetaddr nu_haddr.had_inetaddr
#define nu_nam nu_haddr.had_nam
/* Bits for nu_flag */
@@ -425,7 +207,6 @@ struct nfsrv_rec {
struct nfssvc_sock {
TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */
- TAILQ_HEAD(, nfsuid) ns_uidlruhead;
struct file *ns_fp;
struct socket *ns_so;
struct sockaddr *ns_nam;
@@ -437,10 +218,8 @@ struct nfssvc_sock {
int ns_solock;
int ns_cc;
int ns_reclen;
- int ns_numuids;
u_int32_t ns_sref;
LIST_HEAD(, nfsrv_descript) ns_tq; /* Write gather lists */
- LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
};
@@ -476,8 +255,6 @@ struct nfsd {
/* Bits for "nfsd_flag" */
#define NFSD_WAITING 0x01
#define NFSD_REQINPROG 0x02
-#define NFSD_NEEDAUTH 0x04
-#define NFSD_AUTHFAIL 0x08
/*
* This structure is used by the server for describing each request.
@@ -488,8 +265,8 @@ struct nfsrv_descript {
off_t nd_off; /* Start byte offset */
off_t nd_eoff; /* and end byte offset */
LIST_ENTRY(nfsrv_descript) nd_hash; /* Hash list */
- LIST_ENTRY(nfsrv_descript) nd_tq; /* and timer list */
- LIST_HEAD(,nfsrv_descript) nd_coalesce; /* coalesced writes */
+ LIST_ENTRY(nfsrv_descript) nd_tq; /* and timer list */
+ LIST_HEAD(, nfsrv_descript) nd_coalesce;/* coalesced writes */
struct mbuf *nd_mrep; /* Request mbuf list */
struct mbuf *nd_md; /* Current dissect mbuf */
struct mbuf *nd_mreq; /* Reply mbuf list */
@@ -502,22 +279,13 @@ struct nfsrv_descript {
int nd_len; /* Length of this write */
int nd_repstat; /* Reply status */
u_int32_t nd_retxid; /* Reply xid */
- u_int32_t nd_duration; /* Lease duration */
struct timeval nd_starttime; /* Time RPC initiated */
fhandle_t nd_fh; /* File handle */
struct ucred nd_cr; /* Credentials */
};
/* Bits for "nd_flag" */
-#define ND_READ LEASE_READ
-#define ND_WRITE LEASE_WRITE
-#define ND_CHECK 0x04
-#define ND_LEASE (ND_READ | ND_WRITE | ND_CHECK)
#define ND_NFSV3 0x08
-#define ND_NQNFS 0x10
-#define ND_KERBNICK 0x20
-#define ND_KERBFULL 0x40
-#define ND_KERBAUTH (ND_KERBNICK | ND_KERBFULL)
extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
extern int nfsd_head_flag;
@@ -531,8 +299,7 @@ extern int nfsd_head_flag;
!bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
#define NFSW_SAMECRED(o, n) \
- (((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
- !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
+ (!bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
sizeof (struct ucred)))
/*
@@ -577,151 +344,94 @@ extern int nfs_debug;
#endif
-u_quad_t nfs_curusec __P((void));
-int nfs_init __P((struct vfsconf *vfsp));
-int nfs_uninit __P((struct vfsconf *vfsp));
-int nfs_reply __P((struct nfsreq *));
-int nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int));
-int nfs_send __P((struct socket *, struct sockaddr *, struct mbuf *,
- struct nfsreq *));
-int nfs_rephead __P((int, struct nfsrv_descript *, struct nfssvc_sock *,
- int, int, u_quad_t *, struct mbuf **, struct mbuf **,
- caddr_t *));
-int nfs_sndlock __P((struct nfsreq *));
-void nfs_sndunlock __P((struct nfsreq *));
-int nfs_slplock __P((struct nfssvc_sock *, int));
-void nfs_slpunlock __P((struct nfssvc_sock *));
-int nfs_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *));
-int nfs_vinvalbuf __P((struct vnode *, int, struct ucred *, struct thread *,
- int));
-int nfs_readrpc __P((struct vnode *, struct uio *, struct ucred *));
-int nfs_writerpc __P((struct vnode *, struct uio *, struct ucred *, int *,
- int *));
-int nfs_commit __P((struct vnode *vp, u_quad_t offset, int cnt,
- struct ucred *cred, struct thread *td));
-int nfs_readdirrpc __P((struct vnode *, struct uio *, struct ucred *));
-int nfs_asyncio __P((struct buf *, struct ucred *, struct thread *));
-int nfs_doio __P((struct buf *, struct ucred *, struct thread *));
-int nfs_readlinkrpc __P((struct vnode *, struct uio *, struct ucred *));
-int nfs_sigintr __P((struct nfsmount *, struct nfsreq *, struct proc *));
-int nfs_readdirplusrpc __P((struct vnode *, struct uio *, struct ucred *));
-int nfsm_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *));
-void nfsm_srvfattr __P((struct nfsrv_descript *, struct vattr *,
- struct nfs_fattr *));
-void nfsm_srvwcc __P((struct nfsrv_descript *, int, struct vattr *, int,
- struct vattr *, struct mbuf **, char **));
-void nfsm_srvpostopattr __P((struct nfsrv_descript *, int, struct vattr *,
- struct mbuf **, char **));
-int netaddr_match __P((int, union nethostaddr *, struct sockaddr *));
-int nfs_request __P((struct vnode *, struct mbuf *, int, struct thread *,
- struct ucred *, struct mbuf **, struct mbuf **,
- caddr_t *));
-int nfs_loadattrcache __P((struct vnode **, struct mbuf **, caddr_t *,
- struct vattr *, int));
-int nfs_namei __P((struct nameidata *, fhandle_t *, int,
- struct nfssvc_sock *, struct sockaddr *, struct mbuf **,
- caddr_t *, struct vnode **, struct thread *, int, int));
-void nfsm_adj __P((struct mbuf *, int, int));
-int nfsm_mbuftouio __P((struct mbuf **, struct uio *, int, caddr_t *));
-void nfsrv_initcache __P((void));
-int nfs_getauth __P((struct nfsmount *, struct nfsreq *, struct ucred *,
- char **, int *, char *, int *, NFSKERBKEY_T));
-int nfs_getnickauth __P((struct nfsmount *, struct ucred *, char **,
- int *, char *, int));
-int nfs_savenickauth __P((struct nfsmount *, struct ucred *, int,
- NFSKERBKEY_T, struct mbuf **, char **,
- struct mbuf *));
-int nfs_adv __P((struct mbuf **, caddr_t *, int, int));
-void nfs_nhinit __P((void));
-void nfs_timer __P((void*));
-int nfsrv_dorec __P((struct nfssvc_sock *, struct nfsd *,
- struct nfsrv_descript **));
-int nfsrv_getcache __P((struct nfsrv_descript *, struct nfssvc_sock *,
- struct mbuf **));
-void nfsrv_updatecache __P((struct nfsrv_descript *, int, struct mbuf *));
-void nfsrv_cleancache __P((void));
-int nfs_connect __P((struct nfsmount *, struct nfsreq *));
-void nfs_disconnect __P((struct nfsmount *));
-void nfs_safedisconnect __P((struct nfsmount *));
-int nfs_getattrcache __P((struct vnode *, struct vattr *));
-int nfsm_strtmbuf __P((struct mbuf **, char **, const char *, long));
-int nfs_bioread __P((struct vnode *, struct uio *, int, struct ucred *));
-int nfsm_uiotombuf __P((struct uio *, struct mbuf **, int, caddr_t *));
-void nfsrv_init __P((int));
-void nfs_clearcommit __P((struct mount *));
-int nfsrv_errmap __P((struct nfsrv_descript *, int));
-void nfsrvw_sort __P((gid_t *, int));
-void nfsrv_setcred __P((struct ucred *, struct ucred *));
-int nfs_writebp __P((struct buf *, int, struct thread *));
-int nfsrv_object_create __P((struct vnode *));
-void nfsrv_wakenfsd __P((struct nfssvc_sock *slp));
-int nfsrv_writegather __P((struct nfsrv_descript **, struct nfssvc_sock *,
- struct thread *, struct mbuf **));
-int nfs_fsinfo __P((struct nfsmount *, struct vnode *, struct ucred *,
- struct thread *td));
-
-int nfsrv3_access __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_commit __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_create __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_fhtovp __P((fhandle_t *, int, struct vnode **, struct ucred *,
- struct nfssvc_sock *, struct sockaddr *, int *,
- int, int));
-int nfsrv_setpublicfs __P((struct mount *, struct netexport *,
- struct export_args *));
-int nfs_ispublicfh __P((fhandle_t *));
-int nfsrv_fsinfo __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_getattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_link __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_lookup __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_mkdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_mknod __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_noop __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_null __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_pathconf __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp, struct thread *td,
- struct mbuf **mrq));
-int nfsrv_read __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_readdir __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_readdirplus __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp, struct thread *td,
- struct mbuf **mrq));
-int nfsrv_readlink __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp, struct thread *td,
- struct mbuf **mrq));
-int nfsrv_remove __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_rename __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_rmdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_setattr __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_statfs __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_symlink __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_write __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-void nfsrv_rcv __P((struct socket *so, void *arg, int waitflag));
-void nfsrv_slpderef __P((struct nfssvc_sock *slp));
+int nfs_getreq(struct nfsrv_descript *, struct nfsd *, int);
+int nfsrv_send(struct socket *, struct sockaddr *, struct mbuf *);
+void nfs_rephead(int, struct nfsrv_descript *, struct nfssvc_sock *,
+ int, struct mbuf **, struct mbuf **, caddr_t *);
+int nfs_slplock(struct nfssvc_sock *, int);
+void nfs_slpunlock(struct nfssvc_sock *);
+void nfsm_srvfattr(struct nfsrv_descript *, struct vattr *,
+ struct nfs_fattr *);
+void nfsm_srvwcc(struct nfsrv_descript *, int, struct vattr *, int,
+ struct vattr *, struct mbuf **, char **);
+void nfsm_srvpostopattr(struct nfsrv_descript *, int, struct vattr *,
+ struct mbuf **, char **);
+int netaddr_match(int, union nethostaddr *, struct sockaddr *);
+int nfs_namei(struct nameidata *, fhandle_t *, int,
+ struct nfssvc_sock *, struct sockaddr *, struct mbuf **,
+ caddr_t *, struct vnode **, struct thread *, int);
+void nfsm_adj(struct mbuf *, int, int);
+int nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *);
+void nfsrv_initcache(void);
+void nfsrv_timer(void*);
+int nfsrv_dorec(struct nfssvc_sock *, struct nfsd *,
+ struct nfsrv_descript **);
+int nfsrv_getcache(struct nfsrv_descript *, struct nfssvc_sock *,
+ struct mbuf **);
+void nfsrv_updatecache(struct nfsrv_descript *, int, struct mbuf *);
+void nfsrv_cleancache(void);
+void nfsrv_init(int);
+int nfsrv_errmap(struct nfsrv_descript *, int);
+void nfsrvw_sort(gid_t *, int);
+void nfsrv_setcred(struct ucred *, struct ucred *);
+int nfsrv_object_create(struct vnode *);
+void nfsrv_wakenfsd(struct nfssvc_sock *slp);
+int nfsrv_writegather(struct nfsrv_descript **, struct nfssvc_sock *,
+ struct thread *, struct mbuf **);
+
+int nfsrv3_access(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_commit(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_fhtovp(fhandle_t *, int, struct vnode **, struct ucred *,
+ struct nfssvc_sock *, struct sockaddr *, int *, int);
+int nfsrv_setpublicfs(struct mount *, struct netexport *,
+ struct export_args *);
+int nfs_ispublicfh(fhandle_t *);
+int nfsrv_fsinfo(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_getattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_link(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_lookup(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_mkdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_mknod(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_noop(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_null(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_pathconf(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_read(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_readdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_readdirplus(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_readlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_remove(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_rename(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_rmdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_setattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_statfs(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_symlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+int nfsrv_write(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq);
+void nfsrv_rcv(struct socket *so, void *arg, int waitflag);
+void nfsrv_slpderef(struct nfssvc_sock *slp);
#endif /* _KERNEL */
#endif
diff --git a/sys/nfsserver/nfs_serv.c b/sys/nfsserver/nfs_serv.c
index 0469388..901250f 100644
--- a/sys/nfsserver/nfs_serv.c
+++ b/sys/nfsserver/nfs_serv.c
@@ -34,9 +34,11 @@
* SUCH DAMAGE.
*
* @(#)nfs_serv.c 8.8 (Berkeley) 7/31/95
- * $FreeBSD$
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
/*
* nfs version 2 and 3 server calls to vnode ops
* - these routines generally have 3 phases
@@ -94,10 +96,9 @@
#include <nfs/nfsproto.h>
#include <nfs/rpcv2.h>
-#include <nfs/nfs.h>
+#include <nfsserver/nfs.h>
#include <nfs/xdr_subs.h>
-#include <nfs/nfsm_subs.h>
-#include <nfs/nqnfs.h>
+#include <nfsserver/nfsm_subs.h>
#ifdef NFSRV_DEBUG
#define nfsdbprintf(info) printf info
@@ -113,51 +114,46 @@
#define NHUSE_MAX 2048
static struct nfsheur {
- struct vnode *nh_vp; /* vp to match (unreferenced pointer) */
- off_t nh_nextr; /* next offset for sequential detection */
- int nh_use; /* use count for selection */
- int nh_seqcount; /* heuristic */
+ struct vnode *nh_vp; /* vp to match (unreferenced pointer) */
+ off_t nh_nextr; /* next offset for sequential detection */
+ int nh_use; /* use count for selection */
+ int nh_seqcount; /* heuristic */
} nfsheur[NUM_HEURISTIC];
-nfstype nfsv3_type[9] = { NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK, NFSOCK,
- NFFIFO, NFNON };
-#ifndef NFS_NOSERVER
-nfstype nfsv2_type[9] = { NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK, NFNON,
- NFCHR, NFNON };
/* Global vars */
-extern u_int32_t nfs_xdrneg1;
-extern u_int32_t nfs_false, nfs_true;
-extern enum vtype nv3tov_type[8];
-extern struct nfsstats nfsstats;
int nfsrvw_procrastinate = NFS_GATHERDELAY * 1000;
int nfsrvw_procrastinate_v3 = 0;
static struct timeval nfsver = { 0 };
-SYSCTL_DECL(_vfs_nfs);
+SYSCTL_NODE(_vfs, OID_AUTO, nfsrv, CTLFLAG_RW, 0, "NFS server");
static int nfs_async;
-SYSCTL_INT(_vfs_nfs, OID_AUTO, async, CTLFLAG_RW, &nfs_async, 0, "");
static int nfs_commit_blks;
static int nfs_commit_miss;
-SYSCTL_INT(_vfs_nfs, OID_AUTO, commit_blks, CTLFLAG_RW, &nfs_commit_blks, 0, "");
-SYSCTL_INT(_vfs_nfs, OID_AUTO, commit_miss, CTLFLAG_RW, &nfs_commit_miss, 0, "");
+SYSCTL_INT(_vfs_nfsrv, OID_AUTO, async, CTLFLAG_RW, &nfs_async, 0, "");
+SYSCTL_INT(_vfs_nfsrv, OID_AUTO, commit_blks, CTLFLAG_RW, &nfs_commit_blks, 0, "");
+SYSCTL_INT(_vfs_nfsrv, OID_AUTO, commit_miss, CTLFLAG_RW, &nfs_commit_miss, 0, "");
+
+struct nfsrvstats nfsrvstats;
+SYSCTL_STRUCT(_vfs_nfsrv, NFS_NFSRVSTATS, nfsrvstats, CTLFLAG_RD,
+ &nfsrvstats, nfsrvstats, "S,nfsrvstats");
-static int nfsrv_access __P((struct vnode *,int,struct ucred *,int,
- struct thread *, int));
-static void nfsrvw_coalesce __P((struct nfsrv_descript *,
- struct nfsrv_descript *));
+static int nfsrv_access(struct vnode *, int, struct ucred *, int,
+ struct thread *, int);
+static void nfsrvw_coalesce(struct nfsrv_descript *,
+ struct nfsrv_descript *);
/*
* Clear nameidata fields that are tested in nsfmout cleanup code prior
* to using first nfsm macro (that might jump to the cleanup code).
*/
-static __inline
-void
+static __inline void
ndclear(struct nameidata *nd)
{
+
nd->ni_cnd.cn_flags = 0;
nd->ni_vp = NULL;
nd->ni_dvp = NULL;
@@ -168,11 +164,8 @@ ndclear(struct nameidata *nd)
* nfs v3 access service
*/
int
-nfsrv3_access(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv3_access(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
@@ -181,25 +174,21 @@ nfsrv3_access(nfsd, slp, td, mrq)
struct vnode *vp = NULL;
nfsfh_t nfh;
fhandle_t *fhp;
- register u_int32_t *tl;
- register int32_t t1;
+ u_int32_t *tl;
caddr_t bpos;
- int error = 0, rdonly, cache, getret;
- char *cp2;
- struct mbuf *mb, *mreq, *mb2;
+ int error = 0, rdonly, getret;
+ struct mbuf *mb, *mreq;
struct vattr vattr, *vap = &vattr;
u_long testmode, nfsmode;
- u_quad_t frev;
+ int v3 = (nfsd->nd_flag & ND_NFSV3);
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
-#ifndef nolint
- cache = 0;
-#endif
+ if (!v3)
+ panic("nfsrv3_access: v3 proc called on a v2 connection");
fhp = &nfh.fh_generic;
nfsm_srvmtofh(fhp);
nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
- error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly,
- (nfsd->nd_flag & ND_KERBAUTH), TRUE);
+ error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
if (error) {
nfsm_reply(NFSX_UNSIGNED);
nfsm_srvpostop_attr(1, (struct vattr *)0);
@@ -242,41 +231,33 @@ nfsmout:
* nfs getattr service
*/
int
-nfsrv_getattr(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_getattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
- register struct nfs_fattr *fp;
+ struct nfs_fattr *fp;
struct vattr va;
- register struct vattr *vap = &va;
+ struct vattr *vap = &va;
struct vnode *vp = NULL;
nfsfh_t nfh;
fhandle_t *fhp;
- register u_int32_t *tl;
- register int32_t t1;
+ u_int32_t *tl;
caddr_t bpos;
- int error = 0, rdonly, cache;
- char *cp2;
- struct mbuf *mb, *mb2, *mreq;
- u_quad_t frev;
+ int error = 0, rdonly;
+ struct mbuf *mb, *mreq;
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
fhp = &nfh.fh_generic;
nfsm_srvmtofh(fhp);
- error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam,
- &rdonly, (nfsd->nd_flag & ND_KERBAUTH), TRUE);
+ error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
if (error) {
nfsm_reply(0);
error = 0;
goto nfsmout;
}
- nqsrv_getl(vp, ND_READ);
error = VOP_GETATTR(vp, vap, cred, td);
vput(vp);
vp = NULL;
@@ -299,31 +280,25 @@ nfsmout:
* nfs setattr service
*/
int
-nfsrv_setattr(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_setattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
struct vattr va, preat;
- register struct vattr *vap = &va;
- register struct nfsv2_sattr *sp;
- register struct nfs_fattr *fp;
+ struct vattr *vap = &va;
+ struct nfsv2_sattr *sp;
+ struct nfs_fattr *fp;
struct vnode *vp = NULL;
nfsfh_t nfh;
fhandle_t *fhp;
- register u_int32_t *tl;
- register int32_t t1;
+ u_int32_t *tl;
caddr_t bpos;
- int error = 0, rdonly, cache, preat_ret = 1, postat_ret = 1;
+ int error = 0, rdonly, preat_ret = 1, postat_ret = 1;
int v3 = (nfsd->nd_flag & ND_NFSV3), gcheck = 0;
- char *cp2;
- struct mbuf *mb, *mb2, *mreq;
- u_quad_t frev;
+ struct mbuf *mb, *mreq;
struct timespec guard;
struct mount *mp = NULL;
@@ -384,11 +359,11 @@ nfsrv_setattr(nfsd, slp, td, mrq)
/*
* Now that we have all the fields, lets do it.
*/
- error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly,
- (nfsd->nd_flag & ND_KERBAUTH), TRUE);
+ error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
if (error) {
nfsm_reply(2 * NFSX_UNSIGNED);
- nfsm_srvwcc_data(preat_ret, &preat, postat_ret, vap);
+ if (v3)
+ nfsm_srvwcc_data(preat_ret, &preat, postat_ret, vap);
error = 0;
goto nfsmout;
}
@@ -396,8 +371,6 @@ nfsrv_setattr(nfsd, slp, td, mrq)
/*
* vp now an active resource, pay careful attention to cleanup
*/
-
- nqsrv_getl(vp, ND_WRITE);
if (v3) {
error = preat_ret = VOP_GETATTR(vp, &preat, cred, td);
if (!error && gcheck &&
@@ -408,7 +381,8 @@ nfsrv_setattr(nfsd, slp, td, mrq)
vput(vp);
vp = NULL;
nfsm_reply(NFSX_WCCDATA(v3));
- nfsm_srvwcc_data(preat_ret, &preat, postat_ret, vap);
+ if (v3)
+ nfsm_srvwcc_data(preat_ret, &preat, postat_ret, vap);
error = 0;
goto nfsmout;
}
@@ -462,31 +436,24 @@ nfsmout:
* nfs lookup rpc
*/
int
-nfsrv_lookup(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_lookup(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
- register struct nfs_fattr *fp;
+ struct nfs_fattr *fp;
struct nameidata nd, ind, *ndp = &nd;
struct vnode *vp, *dirp = NULL;
nfsfh_t nfh;
fhandle_t *fhp;
- register caddr_t cp;
- register u_int32_t *tl;
- register int32_t t1;
+ u_int32_t *tl;
caddr_t bpos;
- int error = 0, cache, len, dirattr_ret = 1;
+ int error = 0, len, dirattr_ret = 1;
int v3 = (nfsd->nd_flag & ND_NFSV3), pubflag;
- char *cp2;
- struct mbuf *mb, *mb2, *mreq;
+ struct mbuf *mb, *mreq;
struct vattr va, dirattr, *vap = &va;
- u_quad_t frev;
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
ndclear(&nd);
@@ -501,7 +468,7 @@ nfsrv_lookup(nfsd, slp, td, mrq)
nd.ni_cnd.cn_nameiop = LOOKUP;
nd.ni_cnd.cn_flags = LOCKLEAF | SAVESTART;
error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
- &dirp, td, (nfsd->nd_flag & ND_KERBAUTH), pubflag);
+ &dirp, td, pubflag);
/*
* namei failure, only dirp to cleanup. Clear out garbarge from
@@ -517,7 +484,8 @@ nfsrv_lookup(nfsd, slp, td, mrq)
dirp = NULL;
}
nfsm_reply(NFSX_POSTOPATTR(v3));
- nfsm_srvpostop_attr(dirattr_ret, &dirattr);
+ if (v3)
+ nfsm_srvpostop_attr(dirattr_ret, &dirattr);
error = 0;
goto nfsmout;
}
@@ -559,7 +527,7 @@ nfsrv_lookup(nfsd, slp, td, mrq)
* Found an index file. Get rid of
* the old references. transfer nd.ni_vp'
*/
- if (dirp)
+ if (dirp)
vrele(dirp);
dirp = nd.ni_vp;
nd.ni_vp = NULL;
@@ -599,13 +567,12 @@ nfsrv_lookup(nfsd, slp, td, mrq)
if (error) {
nfsm_reply(NFSX_POSTOPATTR(v3));
- nfsm_srvpostop_attr(dirattr_ret, &dirattr);
+ if (v3)
+ nfsm_srvpostop_attr(dirattr_ret, &dirattr);
error = 0;
goto nfsmout;
}
- nqsrv_getl(ndp->ni_startdir, ND_READ);
-
/*
* Clear out some resources prior to potentially blocking. This
* is not as critical as ni_dvp resources in other routines, but
@@ -630,7 +597,8 @@ nfsrv_lookup(nfsd, slp, td, mrq)
ndp->ni_vp = NULL;
nfsm_reply(NFSX_SRVFH(v3) + NFSX_POSTOPORFATTR(v3) + NFSX_POSTOPATTR(v3));
if (error) {
- nfsm_srvpostop_attr(dirattr_ret, &dirattr);
+ if (v3)
+ nfsm_srvpostop_attr(dirattr_ret, &dirattr);
error = 0;
goto nfsmout;
}
@@ -658,36 +626,30 @@ nfsmout:
* nfs readlink service
*/
int
-nfsrv_readlink(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_readlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
struct iovec iv[(NFS_MAXPATHLEN+MLEN-1)/MLEN];
- register struct iovec *ivp = iv;
- register struct mbuf *mp;
- register u_int32_t *tl;
- register int32_t t1;
+ struct iovec *ivp = iv;
+ struct mbuf *mp;
+ u_int32_t *tl;
caddr_t bpos;
- int error = 0, rdonly, cache, i, tlen, len, getret;
+ int error = 0, rdonly, i, tlen, len, getret;
int v3 = (nfsd->nd_flag & ND_NFSV3);
- char *cp2;
- struct mbuf *mb, *mb2, *mp2, *mp3, *mreq;
+ struct mbuf *mb, *mp3, *nmp, *mreq;
struct vnode *vp = NULL;
struct vattr attr;
nfsfh_t nfh;
fhandle_t *fhp;
struct uio io, *uiop = &io;
- u_quad_t frev;
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
#ifndef nolint
- mp2 = (struct mbuf *)0;
+ mp = (struct mbuf *)0;
#endif
mp3 = NULL;
fhp = &nfh.fh_generic;
@@ -695,17 +657,17 @@ nfsrv_readlink(nfsd, slp, td, mrq)
len = 0;
i = 0;
while (len < NFS_MAXPATHLEN) {
- MGET(mp, M_TRYWAIT, MT_DATA);
- MCLGET(mp, M_TRYWAIT);
- mp->m_len = NFSMSIZ(mp);
+ MGET(nmp, M_TRYWAIT, MT_DATA);
+ MCLGET(nmp, M_TRYWAIT);
+ nmp->m_len = NFSMSIZ(nmp);
if (len == 0)
- mp3 = mp2 = mp;
+ mp3 = mp = nmp;
else {
- mp2->m_next = mp;
- mp2 = mp;
+ mp->m_next = nmp;
+ mp = nmp;
}
- if ((len+mp->m_len) > NFS_MAXPATHLEN) {
- mp->m_len = NFS_MAXPATHLEN-len;
+ if ((len + mp->m_len) > NFS_MAXPATHLEN) {
+ mp->m_len = NFS_MAXPATHLEN - len;
len = NFS_MAXPATHLEN;
} else
len += mp->m_len;
@@ -721,11 +683,11 @@ nfsrv_readlink(nfsd, slp, td, mrq)
uiop->uio_rw = UIO_READ;
uiop->uio_segflg = UIO_SYSSPACE;
uiop->uio_td = (struct thread *)0;
- error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam,
- &rdonly, (nfsd->nd_flag & ND_KERBAUTH), TRUE);
+ error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
if (error) {
nfsm_reply(2 * NFSX_UNSIGNED);
- nfsm_srvpostop_attr(1, (struct vattr *)0);
+ if (v3)
+ nfsm_srvpostop_attr(1, (struct vattr *)0);
error = 0;
goto nfsmout;
}
@@ -736,7 +698,6 @@ nfsrv_readlink(nfsd, slp, td, mrq)
error = ENXIO;
goto out;
}
- nqsrv_getl(vp, ND_READ);
error = VOP_READLINK(vp, uiop, cred);
out:
getret = VOP_GETATTR(vp, &attr, cred, td);
@@ -771,28 +732,23 @@ nfsmout:
* nfs read service
*/
int
-nfsrv_read(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_read(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
- register struct iovec *iv;
+ struct iovec *iv;
struct iovec *iv2;
- register struct mbuf *m;
- register struct nfs_fattr *fp;
- register u_int32_t *tl;
- register int32_t t1;
- register int i;
+ struct mbuf *m;
+ struct nfs_fattr *fp;
+ u_int32_t *tl;
+ int i;
caddr_t bpos;
- int error = 0, rdonly, cache, cnt, len, left, siz, tlen, getret;
+ int error = 0, rdonly, cnt, len, left, siz, tlen, getret;
int v3 = (nfsd->nd_flag & ND_NFSV3), reqlen;
- char *cp2;
- struct mbuf *mb, *mb2, *mreq;
+ struct mbuf *mb, *mreq;
struct mbuf *m2;
struct vnode *vp = NULL;
nfsfh_t nfh;
@@ -802,7 +758,6 @@ nfsrv_read(nfsd, slp, td, mrq)
struct nfsheur *nh;
off_t off;
int ioflag = 0;
- u_quad_t frev;
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
fhp = &nfh.fh_generic;
@@ -822,12 +777,12 @@ nfsrv_read(nfsd, slp, td, mrq)
* as well.
*/
- error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam,
- &rdonly, (nfsd->nd_flag & ND_KERBAUTH), TRUE);
+ error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
if (error) {
vp = NULL;
nfsm_reply(2 * NFSX_UNSIGNED);
- nfsm_srvpostop_attr(1, (struct vattr *)0);
+ if (v3)
+ nfsm_srvpostop_attr(1, (struct vattr *)0);
error = 0;
goto nfsmout;
}
@@ -839,9 +794,8 @@ nfsrv_read(nfsd, slp, td, mrq)
error = (vp->v_type == VDIR) ? EISDIR : EACCES;
}
if (!error) {
- nqsrv_getl(vp, ND_READ);
- if ((error = nfsrv_access(vp, VREAD, cred, rdonly, td, 1)) != 0)
- error = nfsrv_access(vp, VEXEC, cred, rdonly, td, 1);
+ if ((error = nfsrv_access(vp, VREAD, cred, rdonly, td, 1)) != 0)
+ error = nfsrv_access(vp, VEXEC, cred, rdonly, td, 1);
}
getret = VOP_GETATTR(vp, vap, cred, td);
if (!error)
@@ -850,7 +804,8 @@ nfsrv_read(nfsd, slp, td, mrq)
vput(vp);
vp = NULL;
nfsm_reply(NFSX_POSTOPATTR(v3));
- nfsm_srvpostop_attr(getret, vap);
+ if (v3)
+ nfsm_srvpostop_attr(getret, vap);
error = 0;
goto nfsmout;
}
@@ -989,7 +944,8 @@ nfsrv_read(nfsd, slp, td, mrq)
vput(vp);
vp = NULL;
nfsm_reply(NFSX_POSTOPATTR(v3));
- nfsm_srvpostop_attr(getret, vap);
+ if (v3)
+ nfsm_srvpostop_attr(getret, vap);
error = 0;
goto nfsmout;
}
@@ -1022,38 +978,32 @@ nfsmout:
* nfs write service
*/
int
-nfsrv_write(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_write(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
- register struct iovec *ivp;
- register int i, cnt;
- register struct mbuf *mp;
- register struct nfs_fattr *fp;
+ struct iovec *ivp;
+ int i, cnt;
+ struct mbuf *mp;
+ struct nfs_fattr *fp;
struct iovec *iv;
struct vattr va, forat;
- register struct vattr *vap = &va;
- register u_int32_t *tl;
- register int32_t t1;
+ struct vattr *vap = &va;
+ u_int32_t *tl;
caddr_t bpos;
- int error = 0, rdonly, cache, len, forat_ret = 1;
+ int error = 0, rdonly, len, forat_ret = 1;
int ioflags, aftat_ret = 1, retlen = 0, zeroing, adjust;
int stable = NFSV3WRITE_FILESYNC;
int v3 = (nfsd->nd_flag & ND_NFSV3);
- char *cp2;
- struct mbuf *mb, *mb2, *mreq;
+ struct mbuf *mb, *mreq;
struct vnode *vp = NULL;
nfsfh_t nfh;
fhandle_t *fhp;
struct uio io, *uiop = &io;
off_t off;
- u_quad_t frev;
struct mount *mntp = NULL;
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
@@ -1123,16 +1073,17 @@ nfsrv_write(nfsd, slp, td, mrq)
if (len > NFS_MAXDATA || len < 0 || i < len) {
error = EIO;
nfsm_reply(2 * NFSX_UNSIGNED);
- nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, vap);
+ if (v3)
+ nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, vap);
error = 0;
goto nfsmout;
}
- error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam,
- &rdonly, (nfsd->nd_flag & ND_KERBAUTH), TRUE);
+ error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
if (error) {
vp = NULL;
nfsm_reply(2 * NFSX_UNSIGNED);
- nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, vap);
+ if (v3)
+ nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, vap);
error = 0;
goto nfsmout;
}
@@ -1144,15 +1095,14 @@ nfsrv_write(nfsd, slp, td, mrq)
else
error = (vp->v_type == VDIR) ? EISDIR : EACCES;
}
- if (!error) {
- nqsrv_getl(vp, ND_WRITE);
+ if (!error)
error = nfsrv_access(vp, VWRITE, cred, rdonly, td, 1);
- }
if (error) {
vput(vp);
vp = NULL;
nfsm_reply(NFSX_WCCDATA(v3));
- nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, vap);
+ if (v3)
+ nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, vap);
error = 0;
goto nfsmout;
}
@@ -1191,7 +1141,7 @@ nfsrv_write(nfsd, slp, td, mrq)
uiop->uio_td = (struct thread *)0;
uiop->uio_offset = off;
error = VOP_WRITE(vp, uiop, ioflags, cred);
- nfsstats.srvvop_writes++;
+ nfsrvstats.srvvop_writes++;
FREE((caddr_t)iv, M_TEMP);
}
aftat_ret = VOP_GETATTR(vp, vap, cred, td);
@@ -1246,31 +1196,26 @@ nfsmout:
* Jan. 1994.
*/
int
-nfsrv_writegather(ndp, slp, td, mrq)
- struct nfsrv_descript **ndp;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_writegather(struct nfsrv_descript **ndp, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
- register struct iovec *ivp;
- register struct mbuf *mp;
- register struct nfsrv_descript *wp, *nfsd, *owp, *swp;
- register struct nfs_fattr *fp;
- register int i;
+ struct iovec *ivp;
+ struct mbuf *mp;
+ struct nfsrv_descript *wp, *nfsd, *owp, *swp;
+ struct nfs_fattr *fp;
+ int i;
struct iovec *iov;
struct nfsrvw_delayhash *wpp;
struct ucred *cred;
struct vattr va, forat;
- register u_int32_t *tl;
- register int32_t t1;
+ u_int32_t *tl;
caddr_t bpos, dpos;
- int error = 0, rdonly, cache, len, forat_ret = 1;
+ int error = 0, rdonly, len, forat_ret = 1;
int ioflags, aftat_ret = 1, s, adjust, v3, zeroing;
- char *cp2;
- struct mbuf *mb, *mb2, *mreq, *mrep, *md;
+ struct mbuf *mb, *mreq, *mrep, *md;
struct vnode *vp = NULL;
struct uio io, *uiop = &io;
- u_quad_t frev, cur_usec;
+ u_quad_t cur_usec;
struct mount *mntp = NULL;
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
@@ -1293,7 +1238,7 @@ nfsrv_writegather(ndp, slp, td, mrq)
cur_usec = nfs_curusec();
nfsd->nd_time = cur_usec +
(v3 ? nfsrvw_procrastinate_v3 : nfsrvw_procrastinate);
-
+
/*
* Now, get the write header..
*/
@@ -1313,7 +1258,7 @@ nfsrv_writegather(ndp, slp, td, mrq)
len = fxdr_unsigned(int32_t, *tl);
nfsd->nd_len = len;
nfsd->nd_eoff = nfsd->nd_off + len;
-
+
/*
* Trim the header out of the mbuf list and trim off any trailing
* junk so that the mbuf list has only the write data.
@@ -1344,23 +1289,23 @@ nfsrv_writegather(ndp, slp, td, mrq)
nfsmout:
m_freem(mrep);
error = EIO;
- nfsm_writereply(2 * NFSX_UNSIGNED, v3);
+ nfsm_writereply(2 * NFSX_UNSIGNED);
if (v3)
nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, &va);
nfsd->nd_mreq = mreq;
nfsd->nd_mrep = NULL;
nfsd->nd_time = 0;
}
-
+
/*
* Add this entry to the hash and time queues.
*/
s = splsoftclock();
owp = NULL;
- wp = slp->ns_tq.lh_first;
+ wp = LIST_FIRST(&slp->ns_tq);
while (wp && wp->nd_time < nfsd->nd_time) {
owp = wp;
- wp = wp->nd_tq.le_next;
+ wp = LIST_NEXT(wp, nd_tq);
}
NFS_DPF(WG, ("Q%03x", nfsd->nd_retxid & 0xfff));
if (owp) {
@@ -1371,16 +1316,16 @@ nfsmout:
if (nfsd->nd_mrep) {
wpp = NWDELAYHASH(slp, nfsd->nd_fh.fh_fid.fid_data);
owp = NULL;
- wp = wpp->lh_first;
+ wp = LIST_FIRST(wpp);
while (wp &&
- bcmp((caddr_t)&nfsd->nd_fh,(caddr_t)&wp->nd_fh,NFSX_V3FH)) {
+ bcmp((caddr_t)&nfsd->nd_fh,(caddr_t)&wp->nd_fh, NFSX_V3FH)){
owp = wp;
- wp = wp->nd_hash.le_next;
+ wp = LIST_NEXT(wp, nd_hash);
}
while (wp && wp->nd_off < nfsd->nd_off &&
- !bcmp((caddr_t)&nfsd->nd_fh,(caddr_t)&wp->nd_fh,NFSX_V3FH)) {
+ !bcmp((caddr_t)&nfsd->nd_fh,(caddr_t)&wp->nd_fh, NFSX_V3FH)) {
owp = wp;
- wp = wp->nd_hash.le_next;
+ wp = LIST_NEXT(wp, nd_hash);
}
if (owp) {
LIST_INSERT_AFTER(owp, nfsd, nd_hash);
@@ -1390,7 +1335,7 @@ nfsmout:
* coalesce.
*/
for(; nfsd && NFSW_CONTIG(owp, nfsd); nfsd = wp) {
- wp = nfsd->nd_hash.le_next;
+ wp = LIST_NEXT(nfsd, nd_hash);
if (NFSW_SAMECRED(owp, nfsd))
nfsrvw_coalesce(owp, nfsd);
}
@@ -1400,7 +1345,7 @@ nfsmout:
}
splx(s);
}
-
+
/*
* Now, do VOP_WRITE()s for any one(s) that need to be done now
* and generate the associated reply mbuf list(s).
@@ -1408,8 +1353,8 @@ nfsmout:
loop1:
cur_usec = nfs_curusec();
s = splsoftclock();
- for (nfsd = slp->ns_tq.lh_first; nfsd; nfsd = owp) {
- owp = nfsd->nd_tq.le_next;
+ for (nfsd = LIST_FIRST(&slp->ns_tq); nfsd; nfsd = owp) {
+ owp = LIST_NEXT(nfsd, nd_tq);
if (nfsd->nd_time > cur_usec)
break;
if (nfsd->nd_mreq)
@@ -1423,8 +1368,8 @@ loop1:
cred = &nfsd->nd_cr;
v3 = (nfsd->nd_flag & ND_NFSV3);
forat_ret = aftat_ret = 1;
- error = nfsrv_fhtovp(&nfsd->nd_fh, 1, &vp, cred, slp,
- nfsd->nd_nam, &rdonly, (nfsd->nd_flag & ND_KERBAUTH), TRUE);
+ error = nfsrv_fhtovp(&nfsd->nd_fh, 1, &vp, cred, slp,
+ nfsd->nd_nam, &rdonly, TRUE);
if (!error) {
if (v3)
forat_ret = VOP_GETATTR(vp, &forat, cred, td);
@@ -1437,11 +1382,8 @@ loop1:
} else {
vp = NULL;
}
- if (!error) {
- nqsrv_getl(vp, ND_WRITE);
+ if (!error)
error = nfsrv_access(vp, VWRITE, cred, rdonly, td, 1);
- }
-
if (nfsd->nd_stable == NFSV3WRITE_UNSTABLE)
ioflags = IO_NODELOCKED;
else if (nfsd->nd_stable == NFSV3WRITE_DATASYNC)
@@ -1462,7 +1404,7 @@ loop1:
mp = mp->m_next;
}
uiop->uio_iovcnt = i;
- MALLOC(iov, struct iovec *, i * sizeof (struct iovec),
+ MALLOC(iov, struct iovec *, i * sizeof (struct iovec),
M_TEMP, M_WAITOK);
uiop->uio_iov = ivp = iov;
mp = mrep;
@@ -1483,7 +1425,7 @@ loop1:
}
if (!error) {
error = VOP_WRITE(vp, uiop, ioflags, cred);
- nfsstats.srvvop_writes++;
+ nfsrvstats.srvvop_writes++;
vn_finished_write(mntp);
}
FREE((caddr_t)iov, M_TEMP);
@@ -1503,14 +1445,14 @@ loop1:
do {
NFS_DPF(WG, ("R%03x", nfsd->nd_retxid & 0xfff));
if (error) {
- nfsm_writereply(NFSX_WCCDATA(v3), v3);
+ nfsm_writereply(NFSX_WCCDATA(v3));
if (v3) {
nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, &va);
}
} else {
nfsm_writereply(NFSX_PREOPATTR(v3) +
NFSX_POSTOPORFATTR(v3) + 2 * NFSX_UNSIGNED +
- NFSX_WRITEVERF(v3), v3);
+ NFSX_WRITEVERF(v3));
if (v3) {
nfsm_srvwcc_data(forat_ret, &forat, aftat_ret, &va);
nfsm_build(tl, u_int32_t *, 4 * NFSX_UNSIGNED);
@@ -1543,7 +1485,7 @@ loop1:
nfsd->nd_time = 0;
LIST_INSERT_HEAD(&slp->ns_tq, nfsd, nd_tq);
}
- nfsd = swp->nd_coalesce.lh_first;
+ nfsd = LIST_FIRST(&swp->nd_coalesce);
if (nfsd) {
LIST_REMOVE(nfsd, nd_tq);
}
@@ -1561,7 +1503,7 @@ loop1:
* Search for a reply to return.
*/
s = splsoftclock();
- for (nfsd = slp->ns_tq.lh_first; nfsd; nfsd = nfsd->nd_tq.le_next)
+ LIST_FOREACH(nfsd, &slp->ns_tq, nd_tq)
if (nfsd->nd_mreq) {
NFS_DPF(WG, ("X%03x", nfsd->nd_retxid & 0xfff));
LIST_REMOVE(nfsd, nd_tq);
@@ -1582,12 +1524,10 @@ loop1:
* NB: Must be called at splsoftclock().
*/
static void
-nfsrvw_coalesce(owp, nfsd)
- register struct nfsrv_descript *owp;
- register struct nfsrv_descript *nfsd;
+nfsrvw_coalesce(struct nfsrv_descript *owp, struct nfsrv_descript *nfsd)
{
- register int overlap;
- register struct mbuf *mp;
+ int overlap;
+ struct mbuf *mp;
struct nfsrv_descript *p;
NFS_DPF(WG, ("C%03x-%03x",
@@ -1619,8 +1559,8 @@ nfsrvw_coalesce(owp, nfsd)
* If nfsd had anything else coalesced into it, transfer them
* to owp, otherwise their replies will never get sent.
*/
- for (p = nfsd->nd_coalesce.lh_first; p;
- p = nfsd->nd_coalesce.lh_first) {
+ for (p = LIST_FIRST(&nfsd->nd_coalesce); p;
+ p = LIST_FIRST(&nfsd->nd_coalesce)) {
LIST_REMOVE(p, nd_tq);
LIST_INSERT_HEAD(&owp->nd_coalesce, p, nd_tq);
}
@@ -1631,33 +1571,28 @@ nfsrvw_coalesce(owp, nfsd)
* now does a truncate to 0 length via. setattr if it already exists
*/
int
-nfsrv_create(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
- register struct nfs_fattr *fp;
+ struct nfs_fattr *fp;
struct vattr va, dirfor, diraft;
- register struct vattr *vap = &va;
- register struct nfsv2_sattr *sp;
- register u_int32_t *tl;
+ struct vattr *vap = &va;
+ struct nfsv2_sattr *sp;
+ u_int32_t *tl;
struct nameidata nd;
- register int32_t t1;
caddr_t bpos;
- int error = 0, rdev, cache, len, tsize, dirfor_ret = 1, diraft_ret = 1;
+ int error = 0, rdev, len, tsize, dirfor_ret = 1, diraft_ret = 1;
int v3 = (nfsd->nd_flag & ND_NFSV3), how, exclusive_flag = 0;
caddr_t cp;
- char *cp2;
- struct mbuf *mb, *mb2, *mreq;
+ struct mbuf *mb, *mreq;
struct vnode *dirp = (struct vnode *)0;
nfsfh_t nfh;
fhandle_t *fhp;
- u_quad_t frev, tempsize;
+ u_quad_t tempsize;
u_char cverf[NFSX_V3CREATEVERF];
struct mount *mp = NULL;
struct vnode *vp;
@@ -1696,7 +1631,7 @@ nfsrv_create(nfsd, slp, td, mrq)
* prior to calling nfsm_reply ( which might goto nfsmout ).
*/
error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
- &dirp, td, (nfsd->nd_flag & ND_KERBAUTH), FALSE);
+ &dirp, td, FALSE);
if (dirp) {
if (v3) {
dirfor_ret = VOP_GETATTR(dirp, &dirfor, cred,
@@ -1708,7 +1643,8 @@ nfsrv_create(nfsd, slp, td, mrq)
}
if (error) {
nfsm_reply(NFSX_WCCDATA(v3));
- nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
+ if (v3)
+ nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
error = 0;
goto nfsmout;
}
@@ -1776,12 +1712,11 @@ nfsrv_create(nfsd, slp, td, mrq)
* otherwise just truncate to 0 length
* should I set the mode too ?
*
- * The only possible error we can have at this point is EEXIST.
+ * The only possible error we can have at this point is EEXIST.
* nd.ni_vp will also be non-NULL in that case.
*/
if (nd.ni_vp == NULL) {
if (vap->va_type == VREG || vap->va_type == VSOCK) {
- nqsrv_getl(nd.ni_dvp, ND_WRITE);
error = VOP_CREATE(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, vap);
if (error)
NDFREE(&nd, NDF_ONLY_PNBUF);
@@ -1797,7 +1732,7 @@ nfsrv_create(nfsd, slp, td, mrq)
}
}
} else if (
- vap->va_type == VCHR ||
+ vap->va_type == VCHR ||
vap->va_type == VBLK ||
vap->va_type == VFIFO
) {
@@ -1812,8 +1747,6 @@ nfsrv_create(nfsd, slp, td, mrq)
goto nfsmreply0;
}
vap->va_rdev = rdev;
- nqsrv_getl(nd.ni_dvp, ND_WRITE);
-
error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, vap);
if (error) {
NDFREE(&nd, NDF_ONLY_PNBUF);
@@ -1829,10 +1762,10 @@ nfsrv_create(nfsd, slp, td, mrq)
nd.ni_dvp = NULL;
/*
- * Setup for lookup.
+ * Setup for lookup.
*
* Even though LOCKPARENT was cleared, ni_dvp may
- * be garbage.
+ * be garbage.
*/
nd.ni_cnd.cn_nameiop = LOOKUP;
nd.ni_cnd.cn_flags &= ~(LOCKPARENT);
@@ -1859,7 +1792,6 @@ nfsrv_create(nfsd, slp, td, mrq)
error = nfsrv_access(nd.ni_vp, VWRITE, cred,
(nd.ni_cnd.cn_flags & RDONLY), td, 0);
if (!error) {
- nqsrv_getl(nd.ni_vp, ND_WRITE);
tempsize = vap->va_size;
VATTR_NULL(vap);
vap->va_size = tempsize;
@@ -1903,9 +1835,6 @@ ereply:
nfsmreply0:
nfsm_reply(0);
- error = 0;
- /* fall through */
-
nfsmout:
if (nd.ni_startdir) {
vrele(nd.ni_startdir);
@@ -1930,34 +1859,31 @@ nfsmout:
* nfs v3 mknod service
*/
int
-nfsrv_mknod(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_mknod(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
struct vattr va, dirfor, diraft;
- register struct vattr *vap = &va;
- register u_int32_t *tl;
+ struct vattr *vap = &va;
+ u_int32_t *tl;
struct nameidata nd;
- register int32_t t1;
caddr_t bpos;
- int error = 0, cache, len, dirfor_ret = 1, diraft_ret = 1;
+ int error = 0, len, dirfor_ret = 1, diraft_ret = 1;
u_int32_t major, minor;
enum vtype vtyp;
- char *cp2;
- struct mbuf *mb, *mb2, *mreq;
+ struct mbuf *mb, *mreq;
struct vnode *vp, *dirp = (struct vnode *)0;
nfsfh_t nfh;
fhandle_t *fhp;
- u_quad_t frev;
struct mount *mp = NULL;
+ int v3 = (nfsd->nd_flag & ND_NFSV3);
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
+ if (!v3)
+ panic("nfsrv_mknod: v3 proc called on a v2 connection");
ndclear(&nd);
fhp = &nfh.fh_generic;
@@ -1986,7 +1912,7 @@ nfsrv_mknod(nfsd, slp, td, mrq)
*/
error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
- &dirp, td, (nfsd->nd_flag & ND_KERBAUTH), FALSE);
+ &dirp, td, FALSE);
if (dirp)
dirfor_ret = VOP_GETATTR(dirp, &dirfor, cred, td);
if (error) {
@@ -2021,15 +1947,12 @@ nfsrv_mknod(nfsd, slp, td, mrq)
if (vtyp == VSOCK) {
vrele(nd.ni_startdir);
nd.ni_startdir = NULL;
- nqsrv_getl(nd.ni_dvp, ND_WRITE);
error = VOP_CREATE(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, vap);
if (error)
NDFREE(&nd, NDF_ONLY_PNBUF);
} else {
if (vtyp != VFIFO && (error = suser_xxx(cred, 0, 0)))
goto out;
- nqsrv_getl(nd.ni_dvp, ND_WRITE);
-
error = VOP_MKNOD(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, vap);
if (error) {
NDFREE(&nd, NDF_ONLY_PNBUF);
@@ -2092,11 +2015,13 @@ out:
}
ereply:
nfsm_reply(NFSX_SRVFH(1) + NFSX_POSTOPATTR(1) + NFSX_WCCDATA(1));
- if (!error) {
- nfsm_srvpostop_fh(fhp);
- nfsm_srvpostop_attr(0, vap);
+ if (v3) {
+ if (!error) {
+ nfsm_srvpostop_fh(fhp);
+ nfsm_srvpostop_attr(0, vap);
+ }
+ nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
}
- nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
vn_finished_write(mp);
return (0);
nfsmout:
@@ -2121,29 +2046,23 @@ nfsmout:
* nfs remove service
*/
int
-nfsrv_remove(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_remove(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
struct nameidata nd;
- register u_int32_t *tl;
- register int32_t t1;
+ u_int32_t *tl;
caddr_t bpos;
- int error = 0, cache, len, dirfor_ret = 1, diraft_ret = 1;
+ int error = 0, len, dirfor_ret = 1, diraft_ret = 1;
int v3 = (nfsd->nd_flag & ND_NFSV3);
- char *cp2;
struct mbuf *mb, *mreq;
struct vnode *dirp;
struct vattr dirfor, diraft;
nfsfh_t nfh;
fhandle_t *fhp;
- u_quad_t frev;
struct mount *mp = NULL;
struct vnode *vp;
@@ -2169,7 +2088,7 @@ nfsrv_remove(nfsd, slp, td, mrq)
nd.ni_cnd.cn_nameiop = DELETE;
nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF;
error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
- &dirp, td, (nfsd->nd_flag & ND_KERBAUTH), FALSE);
+ &dirp, td, FALSE);
if (dirp) {
if (v3) {
dirfor_ret = VOP_GETATTR(dirp, &dirfor, cred,
@@ -2193,8 +2112,6 @@ nfsrv_remove(nfsd, slp, td, mrq)
}
out:
if (!error) {
- nqsrv_getl(nd.ni_dvp, ND_WRITE);
- nqsrv_getl(nd.ni_vp, ND_WRITE);
error = VOP_REMOVE(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd);
NDFREE(&nd, NDF_ONLY_PNBUF);
}
@@ -2228,23 +2145,18 @@ nfsmout:
* nfs rename service
*/
int
-nfsrv_rename(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_rename(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
- register u_int32_t *tl;
- register int32_t t1;
+ u_int32_t *tl;
caddr_t bpos;
- int error = 0, cache, len, len2, fdirfor_ret = 1, fdiraft_ret = 1;
+ int error = 0, len, len2, fdirfor_ret = 1, fdiraft_ret = 1;
int tdirfor_ret = 1, tdiraft_ret = 1;
int v3 = (nfsd->nd_flag & ND_NFSV3);
- char *cp2;
struct mbuf *mb, *mreq;
struct nameidata fromnd, tond;
struct vnode *fvp, *tvp, *tdvp, *fdirp = (struct vnode *)0;
@@ -2252,7 +2164,6 @@ nfsrv_rename(nfsd, slp, td, mrq)
struct vattr fdirfor, fdiraft, tdirfor, tdiraft;
nfsfh_t fnfh, tnfh;
fhandle_t *ffhp, *tfhp;
- u_quad_t frev;
uid_t saved_uid;
struct mount *mp = NULL;
struct vnode *vp;
@@ -2293,7 +2204,7 @@ nfsrv_rename(nfsd, slp, td, mrq)
fromnd.ni_cnd.cn_nameiop = DELETE;
fromnd.ni_cnd.cn_flags = WANTPARENT | SAVESTART;
error = nfs_namei(&fromnd, ffhp, len, slp, nam, &md,
- &dpos, &fdirp, td, (nfsd->nd_flag & ND_KERBAUTH), FALSE);
+ &dpos, &fdirp, td, FALSE);
if (fdirp) {
if (v3) {
fdirfor_ret = VOP_GETATTR(fdirp, &fdirfor, cred,
@@ -2305,8 +2216,10 @@ nfsrv_rename(nfsd, slp, td, mrq)
}
if (error) {
nfsm_reply(2 * NFSX_WCCDATA(v3));
- nfsm_srvwcc_data(fdirfor_ret, &fdirfor, fdiraft_ret, &fdiraft);
- nfsm_srvwcc_data(tdirfor_ret, &tdirfor, tdiraft_ret, &tdiraft);
+ if (v3) {
+ nfsm_srvwcc_data(fdirfor_ret, &fdirfor, fdiraft_ret, &fdiraft);
+ nfsm_srvwcc_data(tdirfor_ret, &tdirfor, tdiraft_ret, &tdiraft);
+ }
error = 0;
goto nfsmout;
}
@@ -2318,7 +2231,7 @@ nfsrv_rename(nfsd, slp, td, mrq)
tond.ni_cnd.cn_nameiop = RENAME;
tond.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART;
error = nfs_namei(&tond, tfhp, len2, slp, nam, &md,
- &dpos, &tdirp, td, (nfsd->nd_flag & ND_KERBAUTH), FALSE);
+ &dpos, &tdirp, td, FALSE);
if (tdirp) {
if (v3) {
tdirfor_ret = VOP_GETATTR(tdirp, &tdirfor, cred,
@@ -2392,11 +2305,6 @@ out:
* locks prior to returning so we need to clear the pointers
* to bypass cleanup code later on.
*/
- nqsrv_getl(fromnd.ni_dvp, ND_WRITE);
- nqsrv_getl(tdvp, ND_WRITE);
- if (tvp) {
- nqsrv_getl(tvp, ND_WRITE);
- }
error = VOP_RENAME(fromnd.ni_dvp, fromnd.ni_vp, &fromnd.ni_cnd,
tond.ni_dvp, tond.ni_vp, &tond.ni_cnd);
fromnd.ni_dvp = NULL;
@@ -2465,29 +2373,23 @@ nfsmout:
* nfs link service
*/
int
-nfsrv_link(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_link(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
struct nameidata nd;
- register u_int32_t *tl;
- register int32_t t1;
+ u_int32_t *tl;
caddr_t bpos;
- int error = 0, rdonly, cache, len, dirfor_ret = 1, diraft_ret = 1;
+ int error = 0, rdonly, len, dirfor_ret = 1, diraft_ret = 1;
int getret = 1, v3 = (nfsd->nd_flag & ND_NFSV3);
- char *cp2;
struct mbuf *mb, *mreq;
struct vnode *vp = NULL, *xp, *dirp = (struct vnode *)0;
struct vattr dirfor, diraft, at;
nfsfh_t nfh, dnfh;
fhandle_t *fhp, *dfhp;
- u_quad_t frev;
struct mount *mp = NULL;
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
@@ -2510,12 +2412,13 @@ nfsrv_link(nfsd, slp, td, mrq)
nfsm_srvmtofh(dfhp);
nfsm_srvnamesiz(len);
- error = nfsrv_fhtovp(fhp, FALSE, &vp, cred, slp, nam,
- &rdonly, (nfsd->nd_flag & ND_KERBAUTH), TRUE);
+ error = nfsrv_fhtovp(fhp, FALSE, &vp, cred, slp, nam, &rdonly, TRUE);
if (error) {
nfsm_reply(NFSX_POSTOPATTR(v3) + NFSX_WCCDATA(v3));
- nfsm_srvpostop_attr(getret, &at);
- nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
+ if (v3) {
+ nfsm_srvpostop_attr(getret, &at);
+ nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
+ }
vp = NULL;
error = 0;
goto nfsmout;
@@ -2528,7 +2431,7 @@ nfsrv_link(nfsd, slp, td, mrq)
nd.ni_cnd.cn_nameiop = CREATE;
nd.ni_cnd.cn_flags = LOCKPARENT;
error = nfs_namei(&nd, dfhp, len, slp, nam, &md, &dpos,
- &dirp, td, (nfsd->nd_flag & ND_KERBAUTH), FALSE);
+ &dirp, td, FALSE);
if (dirp) {
if (v3) {
dirfor_ret = VOP_GETATTR(dirp, &dirfor, cred,
@@ -2551,8 +2454,6 @@ nfsrv_link(nfsd, slp, td, mrq)
error = EXDEV;
out:
if (!error) {
- nqsrv_getl(vp, ND_WRITE);
- nqsrv_getl(xp, ND_WRITE);
error = VOP_LINK(nd.ni_dvp, vp, &nd.ni_cnd);
NDFREE(&nd, NDF_ONLY_PNBUF);
}
@@ -2594,11 +2495,8 @@ nfsmout:
* nfs symbolic link service
*/
int
-nfsrv_symlink(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_symlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
@@ -2606,20 +2504,18 @@ nfsrv_symlink(nfsd, slp, td, mrq)
struct ucred *cred = &nfsd->nd_cr;
struct vattr va, dirfor, diraft;
struct nameidata nd;
- register struct vattr *vap = &va;
- register u_int32_t *tl;
- register int32_t t1;
+ struct vattr *vap = &va;
+ u_int32_t *tl;
struct nfsv2_sattr *sp;
- char *bpos, *pathcp = (char *)0, *cp2;
+ char *bpos, *pathcp = (char *)0;
struct uio io;
struct iovec iv;
- int error = 0, cache, len, len2, dirfor_ret = 1, diraft_ret = 1;
+ int error = 0, len, len2, dirfor_ret = 1, diraft_ret = 1;
int v3 = (nfsd->nd_flag & ND_NFSV3);
- struct mbuf *mb, *mreq, *mb2;
+ struct mbuf *mb, *mreq;
struct vnode *dirp = (struct vnode *)0;
nfsfh_t nfh;
fhandle_t *fhp;
- u_quad_t frev;
struct mount *mp = NULL;
struct vnode *vp;
@@ -2644,7 +2540,7 @@ nfsrv_symlink(nfsd, slp, td, mrq)
nd.ni_cnd.cn_nameiop = CREATE;
nd.ni_cnd.cn_flags = LOCKPARENT | SAVESTART;
error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
- &dirp, td, (nfsd->nd_flag & ND_KERBAUTH), FALSE);
+ &dirp, td, FALSE);
if (dirp) {
if (v3) {
dirfor_ret = VOP_GETATTR(dirp, &dirfor, cred,
@@ -2686,7 +2582,6 @@ nfsrv_symlink(nfsd, slp, td, mrq)
* issue symlink op. SAVESTART is set so the underlying path component
* is only freed by the VOP if an error occurs.
*/
- nqsrv_getl(nd.ni_dvp, ND_WRITE);
error = VOP_SYMLINK(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, vap, pathcp);
if (error)
NDFREE(&nd, NDF_ONLY_PNBUF);
@@ -2784,33 +2679,26 @@ nfsmout:
* nfs mkdir service
*/
int
-nfsrv_mkdir(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_mkdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
struct vattr va, dirfor, diraft;
- register struct vattr *vap = &va;
- register struct nfs_fattr *fp;
+ struct vattr *vap = &va;
+ struct nfs_fattr *fp;
struct nameidata nd;
- register caddr_t cp;
- register u_int32_t *tl;
- register int32_t t1;
+ u_int32_t *tl;
caddr_t bpos;
- int error = 0, cache, len, dirfor_ret = 1, diraft_ret = 1;
+ int error = 0, len, dirfor_ret = 1, diraft_ret = 1;
int v3 = (nfsd->nd_flag & ND_NFSV3);
- char *cp2;
- struct mbuf *mb, *mb2, *mreq;
+ struct mbuf *mb, *mreq;
struct vnode *dirp = NULL;
int vpexcl = 0;
nfsfh_t nfh;
fhandle_t *fhp;
- u_quad_t frev;
struct mount *mp = NULL;
struct vnode *vp;
@@ -2836,7 +2724,7 @@ nfsrv_mkdir(nfsd, slp, td, mrq)
nd.ni_cnd.cn_flags = LOCKPARENT;
error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
- &dirp, td, (nfsd->nd_flag & ND_KERBAUTH), FALSE);
+ &dirp, td, FALSE);
if (dirp) {
if (v3) {
dirfor_ret = VOP_GETATTR(dirp, &dirfor, cred,
@@ -2848,7 +2736,8 @@ nfsrv_mkdir(nfsd, slp, td, mrq)
}
if (error) {
nfsm_reply(NFSX_WCCDATA(v3));
- nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
+ if (v3)
+ nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
error = 0;
goto nfsmout;
}
@@ -2873,11 +2762,10 @@ nfsrv_mkdir(nfsd, slp, td, mrq)
}
/*
- * Issue mkdir op. Since SAVESTART is not set, the pathname
+ * Issue mkdir op. Since SAVESTART is not set, the pathname
* component is freed by the VOP call. This will fill-in
* nd.ni_vp, reference, and exclusively lock it.
*/
- nqsrv_getl(nd.ni_dvp, ND_WRITE);
error = VOP_MKDIR(nd.ni_dvp, &nd.ni_vp, &nd.ni_cnd, vap);
NDFREE(&nd, NDF_ONLY_PNBUF);
vpexcl = 1;
@@ -2935,29 +2823,23 @@ nfsmout:
* nfs rmdir service
*/
int
-nfsrv_rmdir(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_rmdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
- register u_int32_t *tl;
- register int32_t t1;
+ u_int32_t *tl;
caddr_t bpos;
- int error = 0, cache, len, dirfor_ret = 1, diraft_ret = 1;
+ int error = 0, len, dirfor_ret = 1, diraft_ret = 1;
int v3 = (nfsd->nd_flag & ND_NFSV3);
- char *cp2;
struct mbuf *mb, *mreq;
struct vnode *vp, *dirp = (struct vnode *)0;
struct vattr dirfor, diraft;
nfsfh_t nfh;
fhandle_t *fhp;
struct nameidata nd;
- u_quad_t frev;
struct mount *mp = NULL;
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
@@ -2981,7 +2863,7 @@ nfsrv_rmdir(nfsd, slp, td, mrq)
nd.ni_cnd.cn_nameiop = DELETE;
nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF;
error = nfs_namei(&nd, fhp, len, slp, nam, &md, &dpos,
- &dirp, td, (nfsd->nd_flag & ND_KERBAUTH), FALSE);
+ &dirp, td, FALSE);
if (dirp) {
if (v3) {
dirfor_ret = VOP_GETATTR(dirp, &dirfor, cred,
@@ -2993,7 +2875,8 @@ nfsrv_rmdir(nfsd, slp, td, mrq)
}
if (error) {
nfsm_reply(NFSX_WCCDATA(v3));
- nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
+ if (v3)
+ nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
error = 0;
goto nfsmout;
}
@@ -3019,11 +2902,8 @@ out:
* Issue or abort op. Since SAVESTART is not set, path name
* component is freed by the VOP after either.
*/
- if (!error) {
- nqsrv_getl(nd.ni_dvp, ND_WRITE);
- nqsrv_getl(vp, ND_WRITE);
+ if (!error)
error = VOP_RMDIR(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd);
- }
NDFREE(&nd, NDF_ONLY_PNBUF);
if (dirp)
@@ -3091,25 +2971,21 @@ struct flrep {
};
int
-nfsrv_readdir(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_readdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
- register char *bp, *be;
- register struct mbuf *mp;
- register struct dirent *dp;
- register caddr_t cp;
- register u_int32_t *tl;
- register int32_t t1;
+ char *bp, *be;
+ struct mbuf *mp;
+ struct dirent *dp;
+ caddr_t cp;
+ u_int32_t *tl;
caddr_t bpos;
- struct mbuf *mb, *mb2, *mreq, *mp2;
- char *cpos, *cend, *cp2, *rbuf;
+ struct mbuf *mb, *mreq;
+ char *cpos, *cend, *rbuf;
struct vnode *vp = NULL;
struct vattr at;
nfsfh_t nfh;
@@ -3117,9 +2993,9 @@ nfsrv_readdir(nfsd, slp, td, mrq)
struct uio io;
struct iovec iv;
int len, nlen, rem, xfer, tsiz, i, error = 0, getret = 1;
- int siz, cnt, fullsiz, eofflag, rdonly, cache, ncookies;
+ int siz, cnt, fullsiz, eofflag, rdonly, ncookies;
int v3 = (nfsd->nd_flag & ND_NFSV3);
- u_quad_t frev, off, toff, verf;
+ u_quad_t off, toff, verf;
u_long *cookies = NULL, *cookiep; /* needs to be int64_t or off_t */
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
@@ -3143,8 +3019,7 @@ nfsrv_readdir(nfsd, slp, td, mrq)
if (siz > xfer)
siz = xfer;
fullsiz = siz;
- error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam,
- &rdonly, (nfsd->nd_flag & ND_KERBAUTH), TRUE);
+ error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
if (!error && vp->v_type != VDIR) {
error = ENOTDIR;
vput(vp);
@@ -3152,7 +3027,8 @@ nfsrv_readdir(nfsd, slp, td, mrq)
}
if (error) {
nfsm_reply(NFSX_UNSIGNED);
- nfsm_srvpostop_attr(getret, &at);
+ if (v3)
+ nfsm_srvpostop_attr(getret, &at);
error = 0;
goto nfsmout;
}
@@ -3160,8 +3036,6 @@ nfsrv_readdir(nfsd, slp, td, mrq)
/*
* Obtain lock on vnode for this section of the code
*/
-
- nqsrv_getl(vp, ND_READ);
if (v3) {
error = getret = VOP_GETATTR(vp, &at, cred, td);
#if 0
@@ -3178,7 +3052,8 @@ nfsrv_readdir(nfsd, slp, td, mrq)
vput(vp);
vp = NULL;
nfsm_reply(NFSX_POSTOPATTR(v3));
- nfsm_srvpostop_attr(getret, &at);
+ if (v3)
+ nfsm_srvpostop_attr(getret, &at);
error = 0;
goto nfsmout;
}
@@ -3221,7 +3096,8 @@ again:
if (cookies)
free((caddr_t)cookies, M_TEMP);
nfsm_reply(NFSX_POSTOPATTR(v3));
- nfsm_srvpostop_attr(getret, &at);
+ if (v3)
+ nfsm_srvpostop_attr(getret, &at);
error = 0;
goto nfsmout;
}
@@ -3289,7 +3165,7 @@ again:
nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
txdr_hyper(at.va_filerev, tl);
}
- mp = mp2 = mb;
+ mp = mb;
bp = bpos;
be = bp + M_TRAILINGSPACE(mp);
@@ -3384,25 +3260,21 @@ nfsmout:
}
int
-nfsrv_readdirplus(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_readdirplus(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
- register char *bp, *be;
- register struct mbuf *mp;
- register struct dirent *dp;
- register caddr_t cp;
- register u_int32_t *tl;
- register int32_t t1;
+ char *bp, *be;
+ struct mbuf *mp;
+ struct dirent *dp;
+ caddr_t cp;
+ u_int32_t *tl;
caddr_t bpos;
- struct mbuf *mb, *mb2, *mreq, *mp2;
- char *cpos, *cend, *cp2, *rbuf;
+ struct mbuf *mb, *mreq;
+ char *cpos, *cend, *rbuf;
struct vnode *vp = NULL, *nvp;
struct flrep fl;
nfsfh_t nfh;
@@ -3412,11 +3284,14 @@ nfsrv_readdirplus(nfsd, slp, td, mrq)
struct vattr va, at, *vap = &va;
struct nfs_fattr *fp;
int len, nlen, rem, xfer, tsiz, i, error = 0, getret = 1;
- int siz, cnt, fullsiz, eofflag, rdonly, cache, dirlen, ncookies;
- u_quad_t frev, off, toff, verf;
+ int siz, cnt, fullsiz, eofflag, rdonly, dirlen, ncookies;
+ u_quad_t off, toff, verf;
u_long *cookies = NULL, *cookiep; /* needs to be int64_t or off_t */
+ int v3 = (nfsd->nd_flag & ND_NFSV3);
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
+ if (!v3)
+ panic("nfsrv_readdirplus: v3 proc called on a v2 connection");
fhp = &nfh.fh_generic;
nfsm_srvmtofh(fhp);
nfsm_dissect(tl, u_int32_t *, 6 * NFSX_UNSIGNED);
@@ -3432,8 +3307,7 @@ nfsrv_readdirplus(nfsd, slp, td, mrq)
if (siz > xfer)
siz = xfer;
fullsiz = siz;
- error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam,
- &rdonly, (nfsd->nd_flag & ND_KERBAUTH), TRUE);
+ error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
if (!error && vp->v_type != VDIR) {
error = ENOTDIR;
vput(vp);
@@ -3453,10 +3327,8 @@ nfsrv_readdirplus(nfsd, slp, td, mrq)
if (!error && toff && verf && verf != at.va_filerev)
error = NFSERR_BAD_COOKIE;
#endif
- if (!error) {
- nqsrv_getl(vp, ND_READ);
+ if (!error)
error = nfsrv_access(vp, VEXEC, cred, rdonly, td, 0);
- }
if (error) {
vput(vp);
vp = NULL;
@@ -3573,13 +3445,13 @@ again:
}
vput(nvp);
nvp = NULL;
-
+
dirlen = len = NFSX_V3POSTOPATTR + NFSX_V3COOKIEVERF + 2 * NFSX_UNSIGNED;
nfsm_reply(cnt);
nfsm_srvpostop_attr(getret, &at);
nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
txdr_hyper(at.va_filerev, tl);
- mp = mp2 = mb;
+ mp = mb;
bp = bpos;
be = bp + M_TRAILINGSPACE(mp);
@@ -3668,7 +3540,7 @@ again:
/* And null pad to a int32_t boundary */
for (i = 0; i < rem; i++)
*bp++ = '\0';
-
+
/*
* Now copy the flrep structure out.
*/
@@ -3721,11 +3593,8 @@ nfsmout:
* nfs commit service
*/
int
-nfsrv_commit(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_commit(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
@@ -3735,19 +3604,17 @@ nfsrv_commit(nfsd, slp, td, mrq)
struct vnode *vp = NULL;
nfsfh_t nfh;
fhandle_t *fhp;
- register u_int32_t *tl;
- register int32_t t1;
+ u_int32_t *tl;
caddr_t bpos;
- int error = 0, rdonly, for_ret = 1, aft_ret = 1, cnt, cache;
- char *cp2;
- struct mbuf *mb, *mb2, *mreq;
- u_quad_t frev, off;
+ int error = 0, rdonly, for_ret = 1, aft_ret = 1, cnt;
+ struct mbuf *mb, *mreq;
+ u_quad_t off;
struct mount *mp = NULL;
+ int v3 = (nfsd->nd_flag & ND_NFSV3);
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
-#ifndef nolint
- cache = 0;
-#endif
+ if (!v3)
+ panic("nfsrv_commit: v3 proc called on a v2 connection");
fhp = &nfh.fh_generic;
nfsm_srvmtofh(fhp);
if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) {
@@ -3770,8 +3637,7 @@ nfsrv_commit(nfsd, slp, td, mrq)
off = fxdr_hyper(tl);
tl += 2;
cnt = fxdr_unsigned(int, *tl);
- error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam,
- &rdonly, (nfsd->nd_flag & ND_KERBAUTH), TRUE);
+ error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
if (error) {
nfsm_reply(2 * NFSX_UNSIGNED);
nfsm_srvwcc_data(for_ret, &bfor, aft_ret, &aft);
@@ -3872,43 +3738,35 @@ nfsmout:
* nfs statfs service
*/
int
-nfsrv_statfs(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_statfs(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
- register struct statfs *sf;
- register struct nfs_statfs *sfp;
- register u_int32_t *tl;
- register int32_t t1;
+ struct statfs *sf;
+ struct nfs_statfs *sfp;
+ u_int32_t *tl;
caddr_t bpos;
- int error = 0, rdonly, cache, getret = 1;
+ int error = 0, rdonly, getret = 1;
int v3 = (nfsd->nd_flag & ND_NFSV3);
- char *cp2;
- struct mbuf *mb, *mb2, *mreq;
+ struct mbuf *mb, *mreq;
struct vnode *vp = NULL;
struct vattr at;
nfsfh_t nfh;
fhandle_t *fhp;
struct statfs statfs;
- u_quad_t frev, tval;
+ u_quad_t tval;
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
-#ifndef nolint
- cache = 0;
-#endif
fhp = &nfh.fh_generic;
nfsm_srvmtofh(fhp);
- error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam,
- &rdonly, (nfsd->nd_flag & ND_KERBAUTH), TRUE);
+ error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
if (error) {
nfsm_reply(NFSX_UNSIGNED);
- nfsm_srvpostop_attr(getret, &at);
+ if (v3)
+ nfsm_srvpostop_attr(getret, &at);
error = 0;
goto nfsmout;
}
@@ -3959,38 +3817,32 @@ nfsmout:
* nfs fsinfo service
*/
int
-nfsrv_fsinfo(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_fsinfo(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
- register u_int32_t *tl;
- register struct nfsv3_fsinfo *sip;
- register int32_t t1;
+ u_int32_t *tl;
+ struct nfsv3_fsinfo *sip;
caddr_t bpos;
- int error = 0, rdonly, cache, getret = 1, pref;
- char *cp2;
- struct mbuf *mb, *mb2, *mreq;
+ int error = 0, rdonly, getret = 1, pref;
+ struct mbuf *mb, *mreq;
struct vnode *vp = NULL;
struct vattr at;
nfsfh_t nfh;
fhandle_t *fhp;
- u_quad_t frev, maxfsize;
+ u_quad_t maxfsize;
struct statfs sb;
+ int v3 = (nfsd->nd_flag & ND_NFSV3);
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
-#ifndef nolint
- cache = 0;
-#endif
+ if (!v3)
+ panic("nfsrv_fsinfo: v3 proc called on a v2 connection");
fhp = &nfh.fh_generic;
nfsm_srvmtofh(fhp);
- error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam,
- &rdonly, (nfsd->nd_flag & ND_KERBAUTH), TRUE);
+ error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
if (error) {
nfsm_reply(NFSX_UNSIGNED);
nfsm_srvpostop_attr(getret, &at);
@@ -4041,38 +3893,31 @@ nfsmout:
* nfs pathconf service
*/
int
-nfsrv_pathconf(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_pathconf(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep, *md = nfsd->nd_md;
struct sockaddr *nam = nfsd->nd_nam;
caddr_t dpos = nfsd->nd_dpos;
struct ucred *cred = &nfsd->nd_cr;
- register u_int32_t *tl;
- register struct nfsv3_pathconf *pc;
- register int32_t t1;
+ u_int32_t *tl;
+ struct nfsv3_pathconf *pc;
caddr_t bpos;
- int error = 0, rdonly, cache, getret = 1;
+ int error = 0, rdonly, getret = 1;
register_t linkmax, namemax, chownres, notrunc;
- char *cp2;
- struct mbuf *mb, *mb2, *mreq;
+ struct mbuf *mb, *mreq;
struct vnode *vp = NULL;
struct vattr at;
nfsfh_t nfh;
fhandle_t *fhp;
- u_quad_t frev;
+ int v3 = (nfsd->nd_flag & ND_NFSV3);
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
-#ifndef nolint
- cache = 0;
-#endif
+ if (!v3)
+ panic("nfsrv_pathconf: v3 proc called on a v2 connection");
fhp = &nfh.fh_generic;
nfsm_srvmtofh(fhp);
- error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam,
- &rdonly, (nfsd->nd_flag & ND_KERBAUTH), TRUE);
+ error = nfsrv_fhtovp(fhp, 1, &vp, cred, slp, nam, &rdonly, TRUE);
if (error) {
nfsm_reply(NFSX_UNSIGNED);
nfsm_srvpostop_attr(getret, &at);
@@ -4110,7 +3955,7 @@ nfsrv_pathconf(nfsd, slp, td, mrq)
pc->pc_caseinsensitive = nfs_false;
pc->pc_casepreserving = nfs_true;
nfsmout:
- if (vp)
+ if (vp)
vput(vp);
return(error);
}
@@ -4120,24 +3965,18 @@ nfsmout:
*/
/* ARGSUSED */
int
-nfsrv_null(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_null(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep;
caddr_t bpos;
- int error = NFSERR_RETVOID, cache;
+ int error = NFSERR_RETVOID;
struct mbuf *mb, *mreq;
- u_quad_t frev;
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
-#ifndef nolint
- cache = 0;
-#endif
nfsm_reply(0);
- nfsm_srvdone;
+nfsmout:
+ return (error);
}
/*
@@ -4145,28 +3984,22 @@ nfsrv_null(nfsd, slp, td, mrq)
*/
/* ARGSUSED */
int
-nfsrv_noop(nfsd, slp, td, mrq)
- struct nfsrv_descript *nfsd;
- struct nfssvc_sock *slp;
- struct thread *td;
- struct mbuf **mrq;
+nfsrv_noop(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ struct thread *td, struct mbuf **mrq)
{
struct mbuf *mrep = nfsd->nd_mrep;
caddr_t bpos;
- int error, cache;
+ int error;
struct mbuf *mb, *mreq;
- u_quad_t frev;
nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
-#ifndef nolint
- cache = 0;
-#endif
if (nfsd->nd_repstat)
error = nfsd->nd_repstat;
else
error = EPROCUNAVAIL;
nfsm_reply(0);
- nfsm_srvdone;
+nfsmout:
+ return (error);
}
/*
@@ -4184,13 +4017,8 @@ nfsrv_noop(nfsd, slp, td, mrq)
* will return EPERM instead of EACCESS. EPERM is always an error.
*/
static int
-nfsrv_access(vp, flags, cred, rdonly, td, override)
- register struct vnode *vp;
- int flags;
- register struct ucred *cred;
- int rdonly;
- struct thread *td;
- int override;
+nfsrv_access(struct vnode *vp, int flags, struct ucred *cred, int rdonly,
+ struct thread *td, int override)
{
struct vattr vattr;
int error;
@@ -4232,4 +4060,3 @@ nfsrv_access(vp, flags, cred, rdonly, td, override)
error = 0;
return error;
}
-#endif /* NFS_NOSERVER */
diff --git a/sys/nfsserver/nfs_srvcache.c b/sys/nfsserver/nfs_srvcache.c
index e7b10dd..4bab5d0 100644
--- a/sys/nfsserver/nfs_srvcache.c
+++ b/sys/nfsserver/nfs_srvcache.c
@@ -34,9 +34,11 @@
* SUCH DAMAGE.
*
* @(#)nfs_srvcache.c 8.3 (Berkeley) 3/30/95
- * $FreeBSD$
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
/*
* Reference: Chet Juszczak, "Improving the Performance and Correctness
* of an NFS Server", in Proc. Winter 1989 USENIX Conference,
@@ -53,12 +55,9 @@
#include <netinet/in.h>
#include <nfs/rpcv2.h>
#include <nfs/nfsproto.h>
-#include <nfs/nfs.h>
-#include <nfs/nfsrvcache.h>
+#include <nfsserver/nfs.h>
+#include <nfsserver/nfsrvcache.h>
-#ifndef NFS_NOSERVER
-extern struct nfsstats nfsstats;
-extern int nfsv2_procid[NFS_NPROCS];
static long numnfsrvcache;
static long desirednfsrvcache = NFSRVCACHESIZ;
@@ -101,9 +100,6 @@ static int nonidempotent[NFS_NPROCS] = {
FALSE,
FALSE,
FALSE,
- FALSE,
- FALSE,
- FALSE,
};
/* True iff the rpc reply is an nfs status ONLY! */
@@ -132,7 +128,7 @@ static int nfsv2_repstat[NFS_NPROCS] = {
* Initialize the server request cache list
*/
void
-nfsrv_initcache()
+nfsrv_initcache(void)
{
nfsrvhashtbl = hashinit(desirednfsrvcache, M_NFSD, &nfsrvhash);
@@ -154,12 +150,10 @@ nfsrv_initcache()
* Update/add new request at end of lru list
*/
int
-nfsrv_getcache(nd, slp, repp)
- register struct nfsrv_descript *nd;
- struct nfssvc_sock *slp;
- struct mbuf **repp;
+nfsrv_getcache(struct nfsrv_descript *nd, struct nfssvc_sock *slp,
+ struct mbuf **repp)
{
- register struct nfsrvcache *rp;
+ struct nfsrvcache *rp;
struct mbuf *mb;
struct sockaddr_in *saddr;
caddr_t bpos;
@@ -172,8 +166,7 @@ nfsrv_getcache(nd, slp, repp)
if (!nd->nd_nam2)
return (RC_DOIT);
loop:
- for (rp = NFSRCHASH(nd->nd_retxid)->lh_first; rp != 0;
- rp = rp->rc_hash.le_next) {
+ LIST_FOREACH(rp, NFSRCHASH(nd->nd_retxid), rc_hash) {
if (nd->nd_retxid == rp->rc_xid && nd->nd_procnum == rp->rc_proc &&
netaddr_match(NETFAMILY(rp), &rp->rc_haddr, nd->nd_nam)) {
NFS_DPF(RC, ("H%03x", rp->rc_xid & 0xfff));
@@ -184,27 +177,27 @@ loop:
}
rp->rc_flag |= RC_LOCKED;
/* If not at end of LRU chain, move it there */
- if (rp->rc_lru.tqe_next) {
+ if (TAILQ_NEXT(rp, rc_lru)) {
TAILQ_REMOVE(&nfsrvlruhead, rp, rc_lru);
TAILQ_INSERT_TAIL(&nfsrvlruhead, rp, rc_lru);
}
if (rp->rc_state == RC_UNUSED)
panic("nfsrv cache");
if (rp->rc_state == RC_INPROG) {
- nfsstats.srvcache_inproghits++;
+ nfsrvstats.srvcache_inproghits++;
ret = RC_DROPIT;
} else if (rp->rc_flag & RC_REPSTATUS) {
- nfsstats.srvcache_nonidemdonehits++;
+ nfsrvstats.srvcache_nonidemdonehits++;
nfs_rephead(0, nd, slp, rp->rc_status,
- 0, (u_quad_t *)0, repp, &mb, &bpos);
+ repp, &mb, &bpos);
ret = RC_REPLY;
} else if (rp->rc_flag & RC_REPMBUF) {
- nfsstats.srvcache_nonidemdonehits++;
+ nfsrvstats.srvcache_nonidemdonehits++;
*repp = m_copym(rp->rc_reply, 0, M_COPYALL,
M_TRYWAIT);
ret = RC_REPLY;
} else {
- nfsstats.srvcache_idemdonehits++;
+ nfsrvstats.srvcache_idemdonehits++;
rp->rc_state = RC_INPROG;
ret = RC_DOIT;
}
@@ -216,7 +209,7 @@ loop:
return (ret);
}
}
- nfsstats.srvcache_misses++;
+ nfsrvstats.srvcache_misses++;
NFS_DPF(RC, ("M%03x", nd->nd_retxid & 0xfff));
if (numnfsrvcache < desirednfsrvcache) {
rp = (struct nfsrvcache *)malloc((u_long)sizeof *rp,
@@ -224,11 +217,11 @@ loop:
numnfsrvcache++;
rp->rc_flag = RC_LOCKED;
} else {
- rp = nfsrvlruhead.tqh_first;
+ rp = TAILQ_FIRST(&nfsrvlruhead);
while ((rp->rc_flag & RC_LOCKED) != 0) {
rp->rc_flag |= RC_WANTED;
(void) tsleep((caddr_t)rp, PZERO-1, "nfsrc", 0);
- rp = nfsrvlruhead.tqh_first;
+ rp = TAILQ_FIRST(&nfsrvlruhead);
}
rp->rc_flag |= RC_LOCKED;
LIST_REMOVE(rp, rc_hash);
@@ -268,18 +261,14 @@ loop:
* Update a request cache entry after the rpc has been done
*/
void
-nfsrv_updatecache(nd, repvalid, repmbuf)
- register struct nfsrv_descript *nd;
- int repvalid;
- struct mbuf *repmbuf;
+nfsrv_updatecache(struct nfsrv_descript *nd, int repvalid, struct mbuf *repmbuf)
{
- register struct nfsrvcache *rp;
+ struct nfsrvcache *rp;
if (!nd->nd_nam2)
return;
loop:
- for (rp = NFSRCHASH(nd->nd_retxid)->lh_first; rp != 0;
- rp = rp->rc_hash.le_next) {
+ LIST_FOREACH(rp, NFSRCHASH(nd->nd_retxid), rc_hash) {
if (nd->nd_retxid == rp->rc_xid && nd->nd_procnum == rp->rc_proc &&
netaddr_match(NETFAMILY(rp), &rp->rc_haddr, nd->nd_nam)) {
NFS_DPF(RC, ("U%03x", rp->rc_xid & 0xfff));
@@ -292,8 +281,8 @@ loop:
if (rp->rc_state == RC_DONE) {
/*
* This can occur if the cache is too small.
- * Retransmits of the same request aren't
- * dropped so we may see the operation
+ * Retransmits of the same request aren't
+ * dropped so we may see the operation
* complete more then once.
*/
if (rp->rc_flag & RC_REPMBUF) {
@@ -308,7 +297,8 @@ loop:
*/
if (repvalid && nonidempotent[nd->nd_procnum]) {
if ((nd->nd_flag & ND_NFSV3) == 0 &&
- nfsv2_repstat[nfsv2_procid[nd->nd_procnum]]) {
+ nfsv2_repstat[
+ nfsrvv2_procid[nd->nd_procnum]]) {
rp->rc_status = nd->nd_repstat;
rp->rc_flag |= RC_REPSTATUS;
} else {
@@ -332,12 +322,12 @@ loop:
* Clean out the cache. Called when the last nfsd terminates.
*/
void
-nfsrv_cleancache()
+nfsrv_cleancache(void)
{
- register struct nfsrvcache *rp, *nextrp;
+ struct nfsrvcache *rp, *nextrp;
- for (rp = nfsrvlruhead.tqh_first; rp != 0; rp = nextrp) {
- nextrp = rp->rc_lru.tqe_next;
+ for (rp = TAILQ_FIRST(&nfsrvlruhead); rp != 0; rp = nextrp) {
+ nextrp = TAILQ_NEXT(rp, rc_lru);
LIST_REMOVE(rp, rc_hash);
TAILQ_REMOVE(&nfsrvlruhead, rp, rc_lru);
if (rp->rc_flag & RC_REPMBUF)
@@ -348,5 +338,3 @@ nfsrv_cleancache()
}
numnfsrvcache = 0;
}
-
-#endif /* NFS_NOSERVER */
diff --git a/sys/nfsserver/nfs_srvsock.c b/sys/nfsserver/nfs_srvsock.c
index 8991672..0c36faa 100644
--- a/sys/nfsserver/nfs_srvsock.c
+++ b/sys/nfsserver/nfs_srvsock.c
@@ -37,6 +37,9 @@
* $FreeBSD$
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
/*
* Socket operations for use by nfs
*/
@@ -63,70 +66,20 @@
#include <nfs/rpcv2.h>
#include <nfs/nfsproto.h>
-#include <nfs/nfs.h>
+#include <nfsserver/nfs.h>
#include <nfs/xdr_subs.h>
-#include <nfs/nfsm_subs.h>
-#include <nfs/nfsmount.h>
-#include <nfs/nfsnode.h>
-#include <nfs/nfsrtt.h>
-#include <nfs/nqnfs.h>
+#include <nfsserver/nfsm_subs.h>
#define TRUE 1
#define FALSE 0
-/*
- * Estimate rto for an nfs rpc sent via. an unreliable datagram.
- * Use the mean and mean deviation of rtt for the appropriate type of rpc
- * for the frequent rpcs and a default for the others.
- * The justification for doing "other" this way is that these rpcs
- * happen so infrequently that timer est. would probably be stale.
- * Also, since many of these rpcs are
- * non-idempotent, a conservative timeout is desired.
- * getattr, lookup - A+2D
- * read, write - A+4D
- * other - nm_timeo
- */
-#define NFS_RTO(n, t) \
- ((t) == 0 ? (n)->nm_timeo : \
- ((t) < 3 ? \
- (((((n)->nm_srtt[t-1] + 3) >> 2) + (n)->nm_sdrtt[t-1] + 1) >> 1) : \
- ((((n)->nm_srtt[t-1] + 7) >> 3) + (n)->nm_sdrtt[t-1] + 1)))
-#define NFS_SRTT(r) (r)->r_nmp->nm_srtt[proct[(r)->r_procnum] - 1]
-#define NFS_SDRTT(r) (r)->r_nmp->nm_sdrtt[proct[(r)->r_procnum] - 1]
-/*
- * External data, mostly RPC constants in XDR form
- */
-extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers,
- rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr,
- rpc_auth_kerb;
-extern u_int32_t nfs_prog, nqnfs_prog;
-extern time_t nqnfsstarttime;
-extern struct nfsstats nfsstats;
-extern int nfsv3_procid[NFS_NPROCS];
-extern int nfs_ticks;
-
-/*
- * Defines which timer to use for the procnum.
- * 0 - default
- * 1 - getattr
- * 2 - lookup
- * 3 - read
- * 4 - write
- */
-static int proct[NFS_NPROCS] = {
- 0, 1, 0, 2, 1, 3, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 0, 0, 0, 0,
- 0, 0, 0,
-};
-
static int nfs_realign_test;
static int nfs_realign_count;
-static int nfs_bufpackets = 4;
-SYSCTL_DECL(_vfs_nfs);
+SYSCTL_DECL(_vfs_nfsrv);
-SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_test, CTLFLAG_RW, &nfs_realign_test, 0, "");
-SYSCTL_INT(_vfs_nfs, OID_AUTO, realign_count, CTLFLAG_RW, &nfs_realign_count, 0, "");
-SYSCTL_INT(_vfs_nfs, OID_AUTO, bufpackets, CTLFLAG_RW, &nfs_bufpackets, 0, "");
+SYSCTL_INT(_vfs_nfsrv, OID_AUTO, realign_test, CTLFLAG_RW, &nfs_realign_test, 0, "");
+SYSCTL_INT(_vfs_nfsrv, OID_AUTO, realign_count, CTLFLAG_RW, &nfs_realign_count, 0, "");
/*
@@ -144,26 +97,15 @@ SYSCTL_INT(_vfs_nfs, OID_AUTO, bufpackets, CTLFLAG_RW, &nfs_bufpackets, 0, "");
*/
#define NFS_CWNDSCALE 256
#define NFS_MAXCWND (NFS_CWNDSCALE * 32)
-static int nfs_backoff[8] = { 2, 4, 8, 16, 32, 64, 128, 256, };
-int nfsrtton = 0;
-struct nfsrtt nfsrtt;
-struct callout_handle nfs_timer_handle;
+struct callout_handle nfsrv_timer_handle;
-static int nfs_msg __P((struct thread *,char *,char *));
-static int nfs_rcvlock __P((struct nfsreq *));
-static void nfs_rcvunlock __P((struct nfsreq *));
-static void nfs_realign __P((struct mbuf **pm, int hsiz));
-static int nfs_receive __P((struct nfsreq *rep, struct sockaddr **aname,
- struct mbuf **mp));
-static void nfs_softterm __P((struct nfsreq *rep));
-static int nfs_reconnect __P((struct nfsreq *rep));
-#ifndef NFS_NOSERVER
-static int nfsrv_getstream __P((struct nfssvc_sock *,int));
+static void nfs_realign(struct mbuf **pm, int hsiz); /* XXX SHARED */
+static int nfsrv_getstream(struct nfssvc_sock *, int);
-int (*nfsrv3_procs[NFS_NPROCS]) __P((struct nfsrv_descript *nd,
- struct nfssvc_sock *slp,
- struct thread *td,
- struct mbuf **mreqp)) = {
+int (*nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *nd,
+ struct nfssvc_sock *slp,
+ struct thread *td,
+ struct mbuf **mreqp) = {
nfsrv_null,
nfsrv_getattr,
nfsrv_setattr,
@@ -186,1059 +128,26 @@ int (*nfsrv3_procs[NFS_NPROCS]) __P((struct nfsrv_descript *nd,
nfsrv_fsinfo,
nfsrv_pathconf,
nfsrv_commit,
- nqnfsrv_getlease,
- nqnfsrv_vacated,
- nfsrv_noop,
nfsrv_noop
};
-#endif /* NFS_NOSERVER */
-
-/*
- * Initialize sockets and congestion for a new NFS connection.
- * We do not free the sockaddr if error.
- */
-int
-nfs_connect(nmp, rep)
- register struct nfsmount *nmp;
- struct nfsreq *rep;
-{
- register struct socket *so;
- int s, error, rcvreserve, sndreserve;
- int pktscale;
- struct sockaddr *saddr;
- struct sockaddr_in *sin;
- struct thread *td = thread0; /* only used for socreate and sobind */
-
- nmp->nm_so = (struct socket *)0;
- saddr = nmp->nm_nam;
- error = socreate(saddr->sa_family, &nmp->nm_so, nmp->nm_sotype,
- nmp->nm_soproto, td);
- if (error)
- goto bad;
- so = nmp->nm_so;
- nmp->nm_soflags = so->so_proto->pr_flags;
-
- /*
- * Some servers require that the client port be a reserved port number.
- */
- if (saddr->sa_family == AF_INET && (nmp->nm_flag & NFSMNT_RESVPORT)) {
- struct sockopt sopt;
- int ip;
- struct sockaddr_in ssin;
-
- bzero(&sopt, sizeof sopt);
- ip = IP_PORTRANGE_LOW;
- sopt.sopt_dir = SOPT_SET;
- sopt.sopt_level = IPPROTO_IP;
- sopt.sopt_name = IP_PORTRANGE;
- sopt.sopt_val = (void *)&ip;
- sopt.sopt_valsize = sizeof(ip);
- sopt.sopt_td = NULL;
- error = sosetopt(so, &sopt);
- if (error)
- goto bad;
- bzero(&ssin, sizeof ssin);
- sin = &ssin;
- sin->sin_len = sizeof (struct sockaddr_in);
- sin->sin_family = AF_INET;
- sin->sin_addr.s_addr = INADDR_ANY;
- sin->sin_port = htons(0);
- error = sobind(so, (struct sockaddr *)sin, td);
- if (error)
- goto bad;
- bzero(&sopt, sizeof sopt);
- ip = IP_PORTRANGE_DEFAULT;
- sopt.sopt_dir = SOPT_SET;
- sopt.sopt_level = IPPROTO_IP;
- sopt.sopt_name = IP_PORTRANGE;
- sopt.sopt_val = (void *)&ip;
- sopt.sopt_valsize = sizeof(ip);
- sopt.sopt_td = NULL;
- error = sosetopt(so, &sopt);
- if (error)
- goto bad;
- }
-
- /*
- * Protocols that do not require connections may be optionally left
- * unconnected for servers that reply from a port other than NFS_PORT.
- */
- if (nmp->nm_flag & NFSMNT_NOCONN) {
- if (nmp->nm_soflags & PR_CONNREQUIRED) {
- error = ENOTCONN;
- goto bad;
- }
- } else {
- error = soconnect(so, nmp->nm_nam, td);
- if (error)
- goto bad;
-
- /*
- * Wait for the connection to complete. Cribbed from the
- * connect system call but with the wait timing out so
- * that interruptible mounts don't hang here for a long time.
- */
- s = splnet();
- while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
- (void) tsleep((caddr_t)&so->so_timeo, PSOCK,
- "nfscon", 2 * hz);
- if ((so->so_state & SS_ISCONNECTING) &&
- so->so_error == 0 && rep &&
- (error = nfs_sigintr(nmp, rep,
- (rep->r_td ? rep->r_td->td_proc : NULL))) != 0){
- so->so_state &= ~SS_ISCONNECTING;
- splx(s);
- goto bad;
- }
- }
- if (so->so_error) {
- error = so->so_error;
- so->so_error = 0;
- splx(s);
- goto bad;
- }
- splx(s);
- }
- if (nmp->nm_flag & (NFSMNT_SOFT | NFSMNT_INT)) {
- so->so_rcv.sb_timeo = (5 * hz);
- so->so_snd.sb_timeo = (5 * hz);
- } else {
- so->so_rcv.sb_timeo = 0;
- so->so_snd.sb_timeo = 0;
- }
-
- /*
- * Get buffer reservation size from sysctl, but impose reasonable
- * limits.
- */
- pktscale = nfs_bufpackets;
- if (pktscale < 2)
- pktscale = 2;
- if (pktscale > 64)
- pktscale = 64;
-
- if (nmp->nm_sotype == SOCK_DGRAM) {
- sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR) * pktscale;
- rcvreserve = (max(nmp->nm_rsize, nmp->nm_readdirsize) +
- NFS_MAXPKTHDR) * pktscale;
- } else if (nmp->nm_sotype == SOCK_SEQPACKET) {
- sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR) * pktscale;
- rcvreserve = (max(nmp->nm_rsize, nmp->nm_readdirsize) +
- NFS_MAXPKTHDR) * pktscale;
- } else {
- if (nmp->nm_sotype != SOCK_STREAM)
- panic("nfscon sotype");
- if (so->so_proto->pr_flags & PR_CONNREQUIRED) {
- struct sockopt sopt;
- int val;
-
- bzero(&sopt, sizeof sopt);
- sopt.sopt_level = SOL_SOCKET;
- sopt.sopt_name = SO_KEEPALIVE;
- sopt.sopt_val = &val;
- sopt.sopt_valsize = sizeof val;
- val = 1;
- sosetopt(so, &sopt);
- }
- if (so->so_proto->pr_protocol == IPPROTO_TCP) {
- struct sockopt sopt;
- int val;
-
- bzero(&sopt, sizeof sopt);
- sopt.sopt_level = IPPROTO_TCP;
- sopt.sopt_name = TCP_NODELAY;
- sopt.sopt_val = &val;
- sopt.sopt_valsize = sizeof val;
- val = 1;
- sosetopt(so, &sopt);
- }
- sndreserve = (nmp->nm_wsize + NFS_MAXPKTHDR +
- sizeof (u_int32_t)) * pktscale;
- rcvreserve = (nmp->nm_rsize + NFS_MAXPKTHDR +
- sizeof (u_int32_t)) * pktscale;
- }
- error = soreserve(so, sndreserve, rcvreserve);
- if (error)
- goto bad;
- so->so_rcv.sb_flags |= SB_NOINTR;
- so->so_snd.sb_flags |= SB_NOINTR;
-
- /* Initialize other non-zero congestion variables */
- nmp->nm_srtt[0] = nmp->nm_srtt[1] = nmp->nm_srtt[2] =
- nmp->nm_srtt[3] = (NFS_TIMEO << 3);
- nmp->nm_sdrtt[0] = nmp->nm_sdrtt[1] = nmp->nm_sdrtt[2] =
- nmp->nm_sdrtt[3] = 0;
- nmp->nm_cwnd = NFS_MAXCWND / 2; /* Initial send window */
- nmp->nm_sent = 0;
- nmp->nm_timeouts = 0;
- return (0);
-
-bad:
- nfs_disconnect(nmp);
- return (error);
-}
-
-/*
- * Reconnect routine:
- * Called when a connection is broken on a reliable protocol.
- * - clean up the old socket
- * - nfs_connect() again
- * - set R_MUSTRESEND for all outstanding requests on mount point
- * If this fails the mount point is DEAD!
- * nb: Must be called with the nfs_sndlock() set on the mount point.
- */
-static int
-nfs_reconnect(rep)
- register struct nfsreq *rep;
-{
- register struct nfsreq *rp;
- register struct nfsmount *nmp = rep->r_nmp;
- int error;
-
- nfs_disconnect(nmp);
- while ((error = nfs_connect(nmp, rep)) != 0) {
- if (error == EINTR || error == ERESTART)
- return (EINTR);
- (void) tsleep((caddr_t)&lbolt, PSOCK, "nfscon", 0);
- }
-
- /*
- * Loop through outstanding request list and fix up all requests
- * on old socket.
- */
- for (rp = nfs_reqq.tqh_first; rp != 0; rp = rp->r_chain.tqe_next) {
- if (rp->r_nmp == nmp)
- rp->r_flags |= R_MUSTRESEND;
- }
- return (0);
-}
-
-/*
- * NFS disconnect. Clean up and unlink.
- */
-void
-nfs_disconnect(nmp)
- register struct nfsmount *nmp;
-{
- register struct socket *so;
-
- if (nmp->nm_so) {
- so = nmp->nm_so;
- nmp->nm_so = (struct socket *)0;
- soshutdown(so, 2);
- soclose(so);
- }
-}
-
-void
-nfs_safedisconnect(nmp)
- struct nfsmount *nmp;
-{
- struct nfsreq dummyreq;
-
- bzero(&dummyreq, sizeof(dummyreq));
- dummyreq.r_nmp = nmp;
- nfs_rcvlock(&dummyreq);
- nfs_disconnect(nmp);
- nfs_rcvunlock(&dummyreq);
-}
-
-/*
- * This is the nfs send routine. For connection based socket types, it
- * must be called with an nfs_sndlock() on the socket.
- * "rep == NULL" indicates that it has been called from a server.
- * For the client side:
- * - return EINTR if the RPC is terminated, 0 otherwise
- * - set R_MUSTRESEND if the send fails for any reason
- * - do any cleanup required by recoverable socket errors (?)
- * For the server side:
- * - return EINTR or ERESTART if interrupted by a signal
- * - return EPIPE if a connection is lost for connection based sockets (TCP...)
- * - do any cleanup required by recoverable socket errors (?)
- */
-int
-nfs_send(so, nam, top, rep)
- register struct socket *so;
- struct sockaddr *nam;
- register struct mbuf *top;
- struct nfsreq *rep;
-{
- struct sockaddr *sendnam;
- int error, soflags, flags;
-
- if (rep) {
- if (rep->r_flags & R_SOFTTERM) {
- m_freem(top);
- return (EINTR);
- }
- if ((so = rep->r_nmp->nm_so) == NULL) {
- rep->r_flags |= R_MUSTRESEND;
- m_freem(top);
- return (0);
- }
- rep->r_flags &= ~R_MUSTRESEND;
- soflags = rep->r_nmp->nm_soflags;
- } else
- soflags = so->so_proto->pr_flags;
- if ((soflags & PR_CONNREQUIRED) || (so->so_state & SS_ISCONNECTED))
- sendnam = (struct sockaddr *)0;
- else
- sendnam = nam;
- if (so->so_type == SOCK_SEQPACKET)
- flags = MSG_EOR;
- else
- flags = 0;
-
- error = so->so_proto->pr_usrreqs->pru_sosend(so, sendnam, 0, top, 0,
- flags, curthread /*XXX*/);
- /*
- * ENOBUFS for dgram sockets is transient and non fatal.
- * No need to log, and no need to break a soft mount.
- */
- if (error == ENOBUFS && so->so_type == SOCK_DGRAM) {
- error = 0;
- if (rep) /* do backoff retransmit on client */
- rep->r_flags |= R_MUSTRESEND;
- }
-
- if (error) {
- if (rep) {
- log(LOG_INFO, "nfs send error %d for server %s\n",error,
- rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname);
- /*
- * Deal with errors for the client side.
- */
- if (rep->r_flags & R_SOFTTERM)
- error = EINTR;
- else
- rep->r_flags |= R_MUSTRESEND;
- } else
- log(LOG_INFO, "nfsd send error %d\n", error);
-
- /*
- * Handle any recoverable (soft) socket errors here. (?)
- */
- if (error != EINTR && error != ERESTART &&
- error != EWOULDBLOCK && error != EPIPE)
- error = 0;
- }
- return (error);
-}
-
-/*
- * Receive a Sun RPC Request/Reply. For SOCK_DGRAM, the work is all
- * done by soreceive(), but for SOCK_STREAM we must deal with the Record
- * Mark and consolidate the data into a new mbuf list.
- * nb: Sometimes TCP passes the data up to soreceive() in long lists of
- * small mbufs.
- * For SOCK_STREAM we must be very careful to read an entire record once
- * we have read any of it, even if the system call has been interrupted.
- */
-static int
-nfs_receive(rep, aname, mp)
- register struct nfsreq *rep;
- struct sockaddr **aname;
- struct mbuf **mp;
-{
- register struct socket *so;
- struct uio auio;
- struct iovec aio;
- register struct mbuf *m;
- struct mbuf *control;
- u_int32_t len;
- struct sockaddr **getnam;
- int error, sotype, rcvflg;
- struct thread *td = curthread; /* XXX */
-
- /*
- * Set up arguments for soreceive()
- */
- *mp = (struct mbuf *)0;
- *aname = (struct sockaddr *)0;
- sotype = rep->r_nmp->nm_sotype;
-
- /*
- * For reliable protocols, lock against other senders/receivers
- * in case a reconnect is necessary.
- * For SOCK_STREAM, first get the Record Mark to find out how much
- * more there is to get.
- * We must lock the socket against other receivers
- * until we have an entire rpc request/reply.
- */
- if (sotype != SOCK_DGRAM) {
- error = nfs_sndlock(rep);
- if (error)
- return (error);
-tryagain:
- /*
- * Check for fatal errors and resending request.
- */
- /*
- * Ugh: If a reconnect attempt just happened, nm_so
- * would have changed. NULL indicates a failed
- * attempt that has essentially shut down this
- * mount point.
- */
- if (rep->r_mrep || (rep->r_flags & R_SOFTTERM)) {
- nfs_sndunlock(rep);
- return (EINTR);
- }
- so = rep->r_nmp->nm_so;
- if (!so) {
- error = nfs_reconnect(rep);
- if (error) {
- nfs_sndunlock(rep);
- return (error);
- }
- goto tryagain;
- }
- while (rep->r_flags & R_MUSTRESEND) {
- m = m_copym(rep->r_mreq, 0, M_COPYALL, M_TRYWAIT);
- nfsstats.rpcretries++;
- error = nfs_send(so, rep->r_nmp->nm_nam, m, rep);
- if (error) {
- if (error == EINTR || error == ERESTART ||
- (error = nfs_reconnect(rep)) != 0) {
- nfs_sndunlock(rep);
- return (error);
- }
- goto tryagain;
- }
- }
- nfs_sndunlock(rep);
- if (sotype == SOCK_STREAM) {
- aio.iov_base = (caddr_t) &len;
- aio.iov_len = sizeof(u_int32_t);
- auio.uio_iov = &aio;
- auio.uio_iovcnt = 1;
- auio.uio_segflg = UIO_SYSSPACE;
- auio.uio_rw = UIO_READ;
- auio.uio_offset = 0;
- auio.uio_resid = sizeof(u_int32_t);
- auio.uio_td = td;
- do {
- rcvflg = MSG_WAITALL;
- error = so->so_proto->pr_usrreqs->pru_soreceive
- (so, (struct sockaddr **)0, &auio,
- (struct mbuf **)0, (struct mbuf **)0,
- &rcvflg);
- if (error == EWOULDBLOCK && rep) {
- if (rep->r_flags & R_SOFTTERM)
- return (EINTR);
- }
- } while (error == EWOULDBLOCK);
- if (!error && auio.uio_resid > 0) {
- /*
- * Don't log a 0 byte receive; it means
- * that the socket has been closed, and
- * can happen during normal operation
- * (forcible unmount or Solaris server).
- */
- if (auio.uio_resid != sizeof (u_int32_t))
- log(LOG_INFO,
- "short receive (%d/%d) from nfs server %s\n",
- (int)(sizeof(u_int32_t) - auio.uio_resid),
- (int)sizeof(u_int32_t),
- rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname);
- error = EPIPE;
- }
- if (error)
- goto errout;
- len = ntohl(len) & ~0x80000000;
- /*
- * This is SERIOUS! We are out of sync with the sender
- * and forcing a disconnect/reconnect is all I can do.
- */
- if (len > NFS_MAXPACKET) {
- log(LOG_ERR, "%s (%d) from nfs server %s\n",
- "impossible packet length",
- len,
- rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname);
- error = EFBIG;
- goto errout;
- }
- auio.uio_resid = len;
- do {
- rcvflg = MSG_WAITALL;
- error = so->so_proto->pr_usrreqs->pru_soreceive
- (so, (struct sockaddr **)0,
- &auio, mp, (struct mbuf **)0, &rcvflg);
- } while (error == EWOULDBLOCK || error == EINTR ||
- error == ERESTART);
- if (!error && auio.uio_resid > 0) {
- if (len != auio.uio_resid)
- log(LOG_INFO,
- "short receive (%d/%d) from nfs server %s\n",
- len - auio.uio_resid, len,
- rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname);
- error = EPIPE;
- }
- } else {
- /*
- * NB: Since uio_resid is big, MSG_WAITALL is ignored
- * and soreceive() will return when it has either a
- * control msg or a data msg.
- * We have no use for control msg., but must grab them
- * and then throw them away so we know what is going
- * on.
- */
- auio.uio_resid = len = 100000000; /* Anything Big */
- auio.uio_td = td;
- do {
- rcvflg = 0;
- error = so->so_proto->pr_usrreqs->pru_soreceive
- (so, (struct sockaddr **)0,
- &auio, mp, &control, &rcvflg);
- if (control)
- m_freem(control);
- if (error == EWOULDBLOCK && rep) {
- if (rep->r_flags & R_SOFTTERM)
- return (EINTR);
- }
- } while (error == EWOULDBLOCK ||
- (!error && *mp == NULL && control));
- if ((rcvflg & MSG_EOR) == 0)
- printf("Egad!!\n");
- if (!error && *mp == NULL)
- error = EPIPE;
- len -= auio.uio_resid;
- }
-errout:
- if (error && error != EINTR && error != ERESTART) {
- m_freem(*mp);
- *mp = (struct mbuf *)0;
- if (error != EPIPE)
- log(LOG_INFO,
- "receive error %d from nfs server %s\n",
- error,
- rep->r_nmp->nm_mountp->mnt_stat.f_mntfromname);
- error = nfs_sndlock(rep);
- if (!error)
- error = nfs_reconnect(rep);
- if (!error)
- goto tryagain;
- else
- nfs_sndunlock(rep);
- }
- } else {
- if ((so = rep->r_nmp->nm_so) == NULL)
- return (EACCES);
- if (so->so_state & SS_ISCONNECTED)
- getnam = (struct sockaddr **)0;
- else
- getnam = aname;
- auio.uio_resid = len = 1000000;
- auio.uio_td = td;
- do {
- rcvflg = 0;
- error = so->so_proto->pr_usrreqs->pru_soreceive
- (so, getnam, &auio, mp,
- (struct mbuf **)0, &rcvflg);
- if (error == EWOULDBLOCK &&
- (rep->r_flags & R_SOFTTERM))
- return (EINTR);
- } while (error == EWOULDBLOCK);
- len -= auio.uio_resid;
- }
- if (error) {
- m_freem(*mp);
- *mp = (struct mbuf *)0;
- }
- /*
- * Search for any mbufs that are not a multiple of 4 bytes long
- * or with m_data not longword aligned.
- * These could cause pointer alignment problems, so copy them to
- * well aligned mbufs.
- */
- nfs_realign(mp, 5 * NFSX_UNSIGNED);
- return (error);
-}
-
-/*
- * Implement receipt of reply on a socket.
- * We must search through the list of received datagrams matching them
- * with outstanding requests using the xid, until ours is found.
- */
-/* ARGSUSED */
-int
-nfs_reply(myrep)
- struct nfsreq *myrep;
-{
- register struct nfsreq *rep;
- register struct nfsmount *nmp = myrep->r_nmp;
- register int32_t t1;
- struct mbuf *mrep, *md;
- struct sockaddr *nam;
- u_int32_t rxid, *tl;
- caddr_t dpos, cp2;
- int error;
-
- /*
- * Loop around until we get our own reply
- */
- for (;;) {
- /*
- * Lock against other receivers so that I don't get stuck in
- * sbwait() after someone else has received my reply for me.
- * Also necessary for connection based protocols to avoid
- * race conditions during a reconnect.
- * If nfs_rcvlock() returns EALREADY, that means that
- * the reply has already been recieved by another
- * process and we can return immediately. In this
- * case, the lock is not taken to avoid races with
- * other processes.
- */
- error = nfs_rcvlock(myrep);
- if (error == EALREADY)
- return (0);
- if (error)
- return (error);
- /*
- * Get the next Rpc reply off the socket
- */
- error = nfs_receive(myrep, &nam, &mrep);
- nfs_rcvunlock(myrep);
- if (error) {
-
- /*
- * Ignore routing errors on connectionless protocols??
- */
- if (NFSIGNORE_SOERROR(nmp->nm_soflags, error)) {
- nmp->nm_so->so_error = 0;
- if (myrep->r_flags & R_GETONEREP)
- return (0);
- continue;
- }
- return (error);
- }
- if (nam)
- FREE(nam, M_SONAME);
-
- /*
- * Get the xid and check that it is an rpc reply
- */
- md = mrep;
- dpos = mtod(md, caddr_t);
- nfsm_dissect(tl, u_int32_t *, 2*NFSX_UNSIGNED);
- rxid = *tl++;
- if (*tl != rpc_reply) {
-#ifndef NFS_NOSERVER
- if (nmp->nm_flag & NFSMNT_NQNFS) {
- if (nqnfs_callback(nmp, mrep, md, dpos))
- nfsstats.rpcinvalid++;
- } else {
- nfsstats.rpcinvalid++;
- m_freem(mrep);
- }
-#else
- nfsstats.rpcinvalid++;
- m_freem(mrep);
-#endif
-nfsmout:
- if (myrep->r_flags & R_GETONEREP)
- return (0);
- continue;
- }
-
- /*
- * Loop through the request list to match up the reply
- * Iff no match, just drop the datagram
- */
- for (rep = nfs_reqq.tqh_first; rep != 0;
- rep = rep->r_chain.tqe_next) {
- if (rep->r_mrep == NULL && rxid == rep->r_xid) {
- /* Found it.. */
- rep->r_mrep = mrep;
- rep->r_md = md;
- rep->r_dpos = dpos;
- if (nfsrtton) {
- struct rttl *rt;
-
- rt = &nfsrtt.rttl[nfsrtt.pos];
- rt->proc = rep->r_procnum;
- rt->rto = NFS_RTO(nmp, proct[rep->r_procnum]);
- rt->sent = nmp->nm_sent;
- rt->cwnd = nmp->nm_cwnd;
- rt->srtt = nmp->nm_srtt[proct[rep->r_procnum] - 1];
- rt->sdrtt = nmp->nm_sdrtt[proct[rep->r_procnum] - 1];
- rt->fsid = nmp->nm_mountp->mnt_stat.f_fsid;
- getmicrotime(&rt->tstamp);
- if (rep->r_flags & R_TIMING)
- rt->rtt = rep->r_rtt;
- else
- rt->rtt = 1000000;
- nfsrtt.pos = (nfsrtt.pos + 1) % NFSRTTLOGSIZ;
- }
- /*
- * Update congestion window.
- * Do the additive increase of
- * one rpc/rtt.
- */
- if (nmp->nm_cwnd <= nmp->nm_sent) {
- nmp->nm_cwnd +=
- (NFS_CWNDSCALE * NFS_CWNDSCALE +
- (nmp->nm_cwnd >> 1)) / nmp->nm_cwnd;
- if (nmp->nm_cwnd > NFS_MAXCWND)
- nmp->nm_cwnd = NFS_MAXCWND;
- }
- if (rep->r_flags & R_SENT) {
- rep->r_flags &= ~R_SENT;
- nmp->nm_sent -= NFS_CWNDSCALE;
- }
- /*
- * Update rtt using a gain of 0.125 on the mean
- * and a gain of 0.25 on the deviation.
- */
- if (rep->r_flags & R_TIMING) {
- /*
- * Since the timer resolution of
- * NFS_HZ is so course, it can often
- * result in r_rtt == 0. Since
- * r_rtt == N means that the actual
- * rtt is between N+dt and N+2-dt ticks,
- * add 1.
- */
- t1 = rep->r_rtt + 1;
- t1 -= (NFS_SRTT(rep) >> 3);
- NFS_SRTT(rep) += t1;
- if (t1 < 0)
- t1 = -t1;
- t1 -= (NFS_SDRTT(rep) >> 2);
- NFS_SDRTT(rep) += t1;
- }
- nmp->nm_timeouts = 0;
- break;
- }
- }
- /*
- * If not matched to a request, drop it.
- * If it's mine, get out.
- */
- if (rep == 0) {
- nfsstats.rpcunexpected++;
- m_freem(mrep);
- } else if (rep == myrep) {
- if (rep->r_mrep == NULL)
- panic("nfsreply nil");
- return (0);
- }
- if (myrep->r_flags & R_GETONEREP)
- return (0);
- }
-}
-
-/*
- * nfs_request - goes something like this
- * - fill in request struct
- * - links it into list
- * - calls nfs_send() for first transmit
- * - calls nfs_receive() to get reply
- * - break down rpc header and return with nfs reply pointed to
- * by mrep or error
- * nb: always frees up mreq mbuf list
- */
-int
-nfs_request(vp, mrest, procnum, td, cred, mrp, mdp, dposp)
- struct vnode *vp;
- struct mbuf *mrest;
- int procnum;
- struct thread *td;
- struct ucred *cred;
- struct mbuf **mrp;
- struct mbuf **mdp;
- caddr_t *dposp;
-{
- register struct mbuf *mrep, *m2;
- register struct nfsreq *rep;
- register u_int32_t *tl;
- register int i;
- struct nfsmount *nmp;
- struct mbuf *m, *md, *mheadend;
- struct nfsnode *np;
- char nickv[RPCX_NICKVERF];
- time_t reqtime, waituntil;
- caddr_t dpos, cp2;
- int t1, nqlflag, cachable, s, error = 0, mrest_len, auth_len, auth_type;
- int trylater_delay = NQ_TRYLATERDEL, trylater_cnt = 0, failed_auth = 0;
- int verf_len, verf_type;
- u_int32_t xid;
- u_quad_t frev;
- char *auth_str, *verf_str;
- NFSKERBKEY_T key; /* save session key */
-
- nmp = VFSTONFS(vp->v_mount);
- MALLOC(rep, struct nfsreq *, sizeof(struct nfsreq), M_NFSREQ, M_WAITOK);
- rep->r_nmp = nmp;
- rep->r_vp = vp;
- rep->r_td = td;
- rep->r_procnum = procnum;
- i = 0;
- m = mrest;
- while (m) {
- i += m->m_len;
- m = m->m_next;
- }
- mrest_len = i;
-
- /*
- * Get the RPC header with authorization.
- */
-kerbauth:
- verf_str = auth_str = (char *)0;
- if (nmp->nm_flag & NFSMNT_KERB) {
- verf_str = nickv;
- verf_len = sizeof (nickv);
- auth_type = RPCAUTH_KERB4;
- bzero((caddr_t)key, sizeof (key));
- if (failed_auth || nfs_getnickauth(nmp, cred, &auth_str,
- &auth_len, verf_str, verf_len)) {
- error = nfs_getauth(nmp, rep, cred, &auth_str,
- &auth_len, verf_str, &verf_len, key);
- if (error) {
- free((caddr_t)rep, M_NFSREQ);
- m_freem(mrest);
- return (error);
- }
- }
- } else {
- auth_type = RPCAUTH_UNIX;
- if (cred->cr_ngroups < 1)
- panic("nfsreq nogrps");
- auth_len = ((((cred->cr_ngroups - 1) > nmp->nm_numgrps) ?
- nmp->nm_numgrps : (cred->cr_ngroups - 1)) << 2) +
- 5 * NFSX_UNSIGNED;
- }
- m = nfsm_rpchead(cred, nmp->nm_flag, procnum, auth_type, auth_len,
- auth_str, verf_len, verf_str, mrest, mrest_len, &mheadend, &xid);
- if (auth_str)
- free(auth_str, M_TEMP);
-
- /*
- * For stream protocols, insert a Sun RPC Record Mark.
- */
- if (nmp->nm_sotype == SOCK_STREAM) {
- M_PREPEND(m, NFSX_UNSIGNED, M_TRYWAIT);
- *mtod(m, u_int32_t *) = htonl(0x80000000 |
- (m->m_pkthdr.len - NFSX_UNSIGNED));
- }
- rep->r_mreq = m;
- rep->r_xid = xid;
-tryagain:
- if (nmp->nm_flag & NFSMNT_SOFT)
- rep->r_retry = nmp->nm_retry;
- else
- rep->r_retry = NFS_MAXREXMIT + 1; /* past clip limit */
- rep->r_rtt = rep->r_rexmit = 0;
- if (proct[procnum] > 0)
- rep->r_flags = R_TIMING;
- else
- rep->r_flags = 0;
- rep->r_mrep = NULL;
-
- /*
- * Do the client side RPC.
- */
- nfsstats.rpcrequests++;
- /*
- * Chain request into list of outstanding requests. Be sure
- * to put it LAST so timer finds oldest requests first.
- */
- s = splsoftclock();
- TAILQ_INSERT_TAIL(&nfs_reqq, rep, r_chain);
-
- /* Get send time for nqnfs */
- reqtime = time_second;
-
- /*
- * If backing off another request or avoiding congestion, don't
- * send this one now but let timer do it. If not timing a request,
- * do it now.
- */
- if (nmp->nm_so && (nmp->nm_sotype != SOCK_DGRAM ||
- (nmp->nm_flag & NFSMNT_DUMBTIMR) ||
- nmp->nm_sent < nmp->nm_cwnd)) {
- splx(s);
- if (nmp->nm_soflags & PR_CONNREQUIRED)
- error = nfs_sndlock(rep);
- if (!error) {
- m2 = m_copym(m, 0, M_COPYALL, M_TRYWAIT);
- error = nfs_send(nmp->nm_so, nmp->nm_nam, m2, rep);
- if (nmp->nm_soflags & PR_CONNREQUIRED)
- nfs_sndunlock(rep);
- }
- if (!error && (rep->r_flags & R_MUSTRESEND) == 0) {
- nmp->nm_sent += NFS_CWNDSCALE;
- rep->r_flags |= R_SENT;
- }
- } else {
- splx(s);
- rep->r_rtt = -1;
- }
-
- /*
- * Wait for the reply from our send or the timer's.
- */
- if (!error || error == EPIPE)
- error = nfs_reply(rep);
-
- /*
- * RPC done, unlink the request.
- */
- s = splsoftclock();
- TAILQ_REMOVE(&nfs_reqq, rep, r_chain);
- splx(s);
-
- /*
- * Decrement the outstanding request count.
- */
- if (rep->r_flags & R_SENT) {
- rep->r_flags &= ~R_SENT; /* paranoia */
- nmp->nm_sent -= NFS_CWNDSCALE;
- }
- /*
- * If there was a successful reply and a tprintf msg.
- * tprintf a response.
- */
- if (!error && (rep->r_flags & R_TPRINTFMSG))
- nfs_msg(rep->r_td, nmp->nm_mountp->mnt_stat.f_mntfromname,
- "is alive again");
- mrep = rep->r_mrep;
- md = rep->r_md;
- dpos = rep->r_dpos;
- if (error) {
- m_freem(rep->r_mreq);
- free((caddr_t)rep, M_NFSREQ);
- return (error);
- }
-
- /*
- * break down the rpc header and check if ok
- */
- nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
- if (*tl++ == rpc_msgdenied) {
- if (*tl == rpc_mismatch)
- error = EOPNOTSUPP;
- else if ((nmp->nm_flag & NFSMNT_KERB) && *tl++ == rpc_autherr) {
- if (!failed_auth) {
- failed_auth++;
- mheadend->m_next = (struct mbuf *)0;
- m_freem(mrep);
- m_freem(rep->r_mreq);
- goto kerbauth;
- } else
- error = EAUTH;
- } else
- error = EACCES;
- m_freem(mrep);
- m_freem(rep->r_mreq);
- free((caddr_t)rep, M_NFSREQ);
- return (error);
- }
-
- /*
- * Grab any Kerberos verifier, otherwise just throw it away.
- */
- verf_type = fxdr_unsigned(int, *tl++);
- i = fxdr_unsigned(int32_t, *tl);
- if ((nmp->nm_flag & NFSMNT_KERB) && verf_type == RPCAUTH_KERB4) {
- error = nfs_savenickauth(nmp, cred, i, key, &md, &dpos, mrep);
- if (error)
- goto nfsmout;
- } else if (i > 0)
- nfsm_adv(nfsm_rndup(i));
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
- /* 0 == ok */
- if (*tl == 0) {
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
- if (*tl != 0) {
- error = fxdr_unsigned(int, *tl);
- if ((nmp->nm_flag & NFSMNT_NFSV3) &&
- error == NFSERR_TRYLATER) {
- m_freem(mrep);
- error = 0;
- waituntil = time_second + trylater_delay;
- while (time_second < waituntil)
- (void) tsleep((caddr_t)&lbolt,
- PSOCK, "nqnfstry", 0);
- trylater_delay *= nfs_backoff[trylater_cnt];
- if (trylater_cnt < 7)
- trylater_cnt++;
- goto tryagain;
- }
-
- /*
- * If the File Handle was stale, invalidate the
- * lookup cache, just in case.
- */
- if (error == ESTALE)
- cache_purge(vp);
- if (nmp->nm_flag & NFSMNT_NFSV3) {
- *mrp = mrep;
- *mdp = md;
- *dposp = dpos;
- error |= NFSERR_RETERR;
- } else
- m_freem(mrep);
- m_freem(rep->r_mreq);
- free((caddr_t)rep, M_NFSREQ);
- return (error);
- }
-
- /*
- * For nqnfs, get any lease in reply
- */
- if (nmp->nm_flag & NFSMNT_NQNFS) {
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
- if (*tl) {
- np = VTONFS(vp);
- nqlflag = fxdr_unsigned(int, *tl);
- nfsm_dissect(tl, u_int32_t *, 4*NFSX_UNSIGNED);
- cachable = fxdr_unsigned(int, *tl++);
- reqtime += fxdr_unsigned(int, *tl++);
- if (reqtime > time_second) {
- frev = fxdr_hyper(tl);
- nqnfs_clientlease(nmp, np, nqlflag,
- cachable, reqtime, frev);
- }
- }
- }
- *mrp = mrep;
- *mdp = md;
- *dposp = dpos;
- m_freem(rep->r_mreq);
- FREE((caddr_t)rep, M_NFSREQ);
- return (0);
- }
- m_freem(mrep);
- error = EPROTONOSUPPORT;
-nfsmout:
- m_freem(rep->r_mreq);
- free((caddr_t)rep, M_NFSREQ);
- return (error);
-}
-#ifndef NFS_NOSERVER
/*
* Generate the rpc reply header
* siz arg. is used to decide if adding a cluster is worthwhile
*/
-int
-nfs_rephead(siz, nd, slp, err, cache, frev, mrq, mbp, bposp)
- int siz;
- struct nfsrv_descript *nd;
- struct nfssvc_sock *slp;
- int err;
- int cache;
- u_quad_t *frev;
- struct mbuf **mrq;
- struct mbuf **mbp;
- caddr_t *bposp;
+void
+nfs_rephead(int siz, struct nfsrv_descript *nd, struct nfssvc_sock *slp,
+ int err, struct mbuf **mrq, struct mbuf **mbp, caddr_t *bposp)
{
- register u_int32_t *tl;
- register struct mbuf *mreq;
+ u_int32_t *tl;
+ struct mbuf *mreq;
caddr_t bpos;
- struct mbuf *mb, *mb2;
+ struct mbuf *mb;
+
+ nd->nd_repstat = err;
+ if (err && (nd->nd_flag & ND_NFSV3) == 0) /* XXX recheck */
+ siz = 0;
MGETHDR(mreq, M_TRYWAIT, MT_DATA);
mb = mreq;
@@ -1272,48 +181,10 @@ nfs_rephead(siz, nd, slp, err, cache, frev, mrq, mbp, bposp)
*tl++ = rpc_msgaccepted;
/*
- * For Kerberos authentication, we must send the nickname
- * verifier back, otherwise just RPCAUTH_NULL.
+ * Send a RPCAUTH_NULL verifier - no Kerberos.
*/
- if (nd->nd_flag & ND_KERBFULL) {
- register struct nfsuid *nuidp;
- struct timeval ktvin, ktvout;
-
- for (nuidp = NUIDHASH(slp, nd->nd_cr.cr_uid)->lh_first;
- nuidp != 0; nuidp = nuidp->nu_hash.le_next) {
- if (nuidp->nu_cr.cr_uid == nd->nd_cr.cr_uid &&
- (!nd->nd_nam2 || netaddr_match(NU_NETFAM(nuidp),
- &nuidp->nu_haddr, nd->nd_nam2)))
- break;
- }
- if (nuidp) {
- ktvin.tv_sec =
- txdr_unsigned(nuidp->nu_timestamp.tv_sec - 1);
- ktvin.tv_usec =
- txdr_unsigned(nuidp->nu_timestamp.tv_usec);
-
- /*
- * Encrypt the timestamp in ecb mode using the
- * session key.
- */
-#ifdef NFSKERB
- XXX
-#endif
-
- *tl++ = rpc_auth_kerb;
- *tl++ = txdr_unsigned(3 * NFSX_UNSIGNED);
- *tl = ktvout.tv_sec;
- nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
- *tl++ = ktvout.tv_usec;
- *tl++ = txdr_unsigned(nuidp->nu_cr.cr_uid);
- } else {
- *tl++ = 0;
- *tl++ = 0;
- }
- } else {
- *tl++ = 0;
- *tl++ = 0;
- }
+ *tl++ = 0;
+ *tl++ = 0;
switch (err) {
case EPROGUNAVAIL:
*tl = txdr_unsigned(RPC_PROGUNAVAIL);
@@ -1321,13 +192,8 @@ nfs_rephead(siz, nd, slp, err, cache, frev, mrq, mbp, bposp)
case EPROGMISMATCH:
*tl = txdr_unsigned(RPC_PROGMISMATCH);
nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
- if (nd->nd_flag & ND_NQNFS) {
- *tl++ = txdr_unsigned(3);
- *tl = txdr_unsigned(3);
- } else {
- *tl++ = txdr_unsigned(2);
- *tl = txdr_unsigned(3);
- }
+ *tl++ = txdr_unsigned(2);
+ *tl = txdr_unsigned(3);
break;
case EPROCUNAVAIL:
*tl = txdr_unsigned(RPC_PROCUNAVAIL);
@@ -1348,320 +214,14 @@ nfs_rephead(siz, nd, slp, err, cache, frev, mrq, mbp, bposp)
};
}
- /*
- * For nqnfs, piggyback lease as requested.
- */
- if ((nd->nd_flag & ND_NQNFS) && err == 0) {
- if (nd->nd_flag & ND_LEASE) {
- nfsm_build(tl, u_int32_t *, 5 * NFSX_UNSIGNED);
- *tl++ = txdr_unsigned(nd->nd_flag & ND_LEASE);
- *tl++ = txdr_unsigned(cache);
- *tl++ = txdr_unsigned(nd->nd_duration);
- txdr_hyper(*frev, tl);
- } else {
- nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
- *tl = 0;
- }
- }
if (mrq != NULL)
- *mrq = mreq;
+ *mrq = mreq;
*mbp = mb;
*bposp = bpos;
if (err != 0 && err != NFSERR_RETVOID)
- nfsstats.srvrpc_errs++;
- return (0);
-}
-
-
-#endif /* NFS_NOSERVER */
-/*
- * Nfs timer routine
- * Scan the nfsreq list and retranmit any requests that have timed out
- * To avoid retransmission attempts on STREAM sockets (in the future) make
- * sure to set the r_retry field to 0 (implies nm_retry == 0).
- */
-void
-nfs_timer(arg)
- void *arg; /* never used */
-{
- register struct nfsreq *rep;
- register struct mbuf *m;
- register struct socket *so;
- register struct nfsmount *nmp;
- register int timeo;
- int s, error;
-#ifndef NFS_NOSERVER
- static long lasttime = 0;
- register struct nfssvc_sock *slp;
- u_quad_t cur_usec;
-#endif /* NFS_NOSERVER */
- struct thread *td = thread0; /* XXX for credentials, will break if sleep */
-
- s = splnet();
- for (rep = nfs_reqq.tqh_first; rep != 0; rep = rep->r_chain.tqe_next) {
- nmp = rep->r_nmp;
- if (rep->r_mrep || (rep->r_flags & R_SOFTTERM))
- continue;
- if (nfs_sigintr(nmp, rep,
- (rep->r_td ? rep->r_td->td_proc : NULL))) {
- nfs_softterm(rep);
- continue;
- }
- if (rep->r_rtt >= 0) {
- rep->r_rtt++;
- if (nmp->nm_flag & NFSMNT_DUMBTIMR)
- timeo = nmp->nm_timeo;
- else
- timeo = NFS_RTO(nmp, proct[rep->r_procnum]);
- if (nmp->nm_timeouts > 0)
- timeo *= nfs_backoff[nmp->nm_timeouts - 1];
- if (rep->r_rtt <= timeo)
- continue;
- if (nmp->nm_timeouts < 8)
- nmp->nm_timeouts++;
- }
- /*
- * Check for server not responding
- */
- if ((rep->r_flags & R_TPRINTFMSG) == 0 &&
- rep->r_rexmit > nmp->nm_deadthresh) {
- nfs_msg(rep->r_td,
- nmp->nm_mountp->mnt_stat.f_mntfromname,
- "not responding");
- rep->r_flags |= R_TPRINTFMSG;
- }
- if (rep->r_rexmit >= rep->r_retry) { /* too many */
- nfsstats.rpctimeouts++;
- nfs_softterm(rep);
- continue;
- }
- if (nmp->nm_sotype != SOCK_DGRAM) {
- if (++rep->r_rexmit > NFS_MAXREXMIT)
- rep->r_rexmit = NFS_MAXREXMIT;
- continue;
- }
- if ((so = nmp->nm_so) == NULL)
- continue;
-
- /*
- * If there is enough space and the window allows..
- * Resend it
- * Set r_rtt to -1 in case we fail to send it now.
- */
- rep->r_rtt = -1;
- if (sbspace(&so->so_snd) >= rep->r_mreq->m_pkthdr.len &&
- ((nmp->nm_flag & NFSMNT_DUMBTIMR) ||
- (rep->r_flags & R_SENT) ||
- nmp->nm_sent < nmp->nm_cwnd) &&
- (m = m_copym(rep->r_mreq, 0, M_COPYALL, M_DONTWAIT))){
- if ((nmp->nm_flag & NFSMNT_NOCONN) == 0)
- error = (*so->so_proto->pr_usrreqs->pru_send)
- (so, 0, m, (struct sockaddr *)0,
- (struct mbuf *)0, td);
- else
- error = (*so->so_proto->pr_usrreqs->pru_send)
- (so, 0, m, nmp->nm_nam, (struct mbuf *)0,
- td);
- if (error) {
- if (NFSIGNORE_SOERROR(nmp->nm_soflags, error))
- so->so_error = 0;
- } else {
- /*
- * Iff first send, start timing
- * else turn timing off, backoff timer
- * and divide congestion window by 2.
- */
- if (rep->r_flags & R_SENT) {
- rep->r_flags &= ~R_TIMING;
- if (++rep->r_rexmit > NFS_MAXREXMIT)
- rep->r_rexmit = NFS_MAXREXMIT;
- nmp->nm_cwnd >>= 1;
- if (nmp->nm_cwnd < NFS_CWNDSCALE)
- nmp->nm_cwnd = NFS_CWNDSCALE;
- nfsstats.rpcretries++;
- } else {
- rep->r_flags |= R_SENT;
- nmp->nm_sent += NFS_CWNDSCALE;
- }
- rep->r_rtt = 0;
- }
- }
- }
-#ifndef NFS_NOSERVER
- /*
- * Call the nqnfs server timer once a second to handle leases.
- */
- if (lasttime != time_second) {
- lasttime = time_second;
- nqnfs_serverd();
- }
-
- /*
- * Scan the write gathering queues for writes that need to be
- * completed now.
- */
- cur_usec = nfs_curusec();
- for (slp = nfssvc_sockhead.tqh_first; slp != 0;
- slp = slp->ns_chain.tqe_next) {
- if (slp->ns_tq.lh_first && slp->ns_tq.lh_first->nd_time<=cur_usec)
- nfsrv_wakenfsd(slp);
- }
-#endif /* NFS_NOSERVER */
- splx(s);
- nfs_timer_handle = timeout(nfs_timer, (void *)0, nfs_ticks);
-}
-
-/*
- * Flag a request as being about to terminate (due to NFSMNT_INT/NFSMNT_SOFT).
- * The nm_send count is decremented now to avoid deadlocks when the process in
- * soreceive() hasn't yet managed to send its own request.
- */
-
-static void
-nfs_softterm(rep)
- struct nfsreq *rep;
-{
- rep->r_flags |= R_SOFTTERM;
-
- if (rep->r_flags & R_SENT) {
- rep->r_nmp->nm_sent -= NFS_CWNDSCALE;
- rep->r_flags &= ~R_SENT;
- }
-}
-
-/*
- * Test for a termination condition pending on the process.
- * This is used for NFSMNT_INT mounts.
- */
-int
-nfs_sigintr(nmp, rep, p)
- struct nfsmount *nmp;
- struct nfsreq *rep;
- register struct proc *p;
-{
- sigset_t tmpset;
-
- if (rep && (rep->r_flags & R_SOFTTERM))
- return (EINTR);
- if (!(nmp->nm_flag & NFSMNT_INT))
- return (0);
- if (p == NULL)
- return (0);
-
- tmpset = p->p_siglist;
- SIGSETNAND(tmpset, p->p_sigmask);
- SIGSETNAND(tmpset, p->p_sigignore);
- if (SIGNOTEMPTY(p->p_siglist) && NFSINT_SIGMASK(tmpset))
- return (EINTR);
-
- return (0);
-}
-
-/*
- * Lock a socket against others.
- * Necessary for STREAM sockets to ensure you get an entire rpc request/reply
- * and also to avoid race conditions between the processes with nfs requests
- * in progress when a reconnect is necessary.
- */
-int
-nfs_sndlock(rep)
- struct nfsreq *rep;
-{
- register int *statep = &rep->r_nmp->nm_state;
- struct thread *td;
- int slpflag = 0, slptimeo = 0;
-
- if (rep) {
- td = rep->r_td;
- if (rep->r_nmp->nm_flag & NFSMNT_INT)
- slpflag = PCATCH;
- } else
- td = (struct thread *)0;
- while (*statep & NFSSTA_SNDLOCK) {
- if (nfs_sigintr(rep->r_nmp, rep, td ? td->td_proc : NULL))
- return (EINTR);
- *statep |= NFSSTA_WANTSND;
- (void) tsleep((caddr_t)statep, slpflag | (PZERO - 1),
- "nfsndlck", slptimeo);
- if (slpflag == PCATCH) {
- slpflag = 0;
- slptimeo = 2 * hz;
- }
- }
- *statep |= NFSSTA_SNDLOCK;
- return (0);
-}
-
-/*
- * Unlock the stream socket for others.
- */
-void
-nfs_sndunlock(rep)
- struct nfsreq *rep;
-{
- register int *statep = &rep->r_nmp->nm_state;
-
- if ((*statep & NFSSTA_SNDLOCK) == 0)
- panic("nfs sndunlock");
- *statep &= ~NFSSTA_SNDLOCK;
- if (*statep & NFSSTA_WANTSND) {
- *statep &= ~NFSSTA_WANTSND;
- wakeup((caddr_t)statep);
- }
-}
-
-static int
-nfs_rcvlock(rep)
- register struct nfsreq *rep;
-{
- register int *statep = &rep->r_nmp->nm_state;
- int slpflag, slptimeo = 0;
-
- if (rep->r_nmp->nm_flag & NFSMNT_INT)
- slpflag = PCATCH;
- else
- slpflag = 0;
- while (*statep & NFSSTA_RCVLOCK) {
- if (nfs_sigintr(rep->r_nmp, rep,
- (rep->r_td ? rep->r_td->td_proc : NULL)))
- return (EINTR);
- *statep |= NFSSTA_WANTRCV;
- (void) tsleep((caddr_t)statep, slpflag | (PZERO - 1), "nfsrcvlk",
- slptimeo);
- /*
- * If our reply was recieved while we were sleeping,
- * then just return without taking the lock to avoid a
- * situation where a single iod could 'capture' the
- * recieve lock.
- */
- if (rep->r_mrep != NULL)
- return (EALREADY);
- if (slpflag == PCATCH) {
- slpflag = 0;
- slptimeo = 2 * hz;
- }
- }
- *statep |= NFSSTA_RCVLOCK;
- return (0);
+ nfsrvstats.srvrpc_errs++;
}
-/*
- * Unlock the stream socket for others.
- */
-static void
-nfs_rcvunlock(rep)
- register struct nfsreq *rep;
-{
- register int *statep = &rep->r_nmp->nm_state;
-
- if ((*statep & NFSSTA_RCVLOCK) == 0)
- panic("nfs rcvunlock");
- *statep &= ~NFSSTA_RCVLOCK;
- if (*statep & NFSSTA_WANTRCV) {
- *statep &= ~NFSSTA_WANTRCV;
- wakeup((caddr_t)statep);
- }
-}
/*
* nfs_realign:
@@ -1679,16 +239,13 @@ nfs_rcvunlock(rep)
* with TCP. Use vfs.nfs.realign_count and realign_test to check this.
*/
static void
-nfs_realign(pm, hsiz)
- register struct mbuf **pm;
- int hsiz;
+nfs_realign(struct mbuf **pm, int hsiz) /* XXX COMMON */
{
struct mbuf *m;
struct mbuf *n = NULL;
int off = 0;
++nfs_realign_test;
-
while ((m = *pm) != NULL) {
if ((m->m_len & 0x3) || (mtod(m, intptr_t) & 0x3)) {
MGET(n, M_TRYWAIT, MT_DATA);
@@ -1717,7 +274,6 @@ nfs_realign(pm, hsiz)
}
}
-#ifndef NFS_NOSERVER
/*
* Parse an RPC request
@@ -1725,26 +281,14 @@ nfs_realign(pm, hsiz)
* - fill in the cred struct.
*/
int
-nfs_getreq(nd, nfsd, has_header)
- register struct nfsrv_descript *nd;
- struct nfsd *nfsd;
- int has_header;
+nfs_getreq(struct nfsrv_descript *nd, struct nfsd *nfsd, int has_header)
{
- register int len, i;
- register u_int32_t *tl;
- register int32_t t1;
- struct uio uio;
- struct iovec iov;
- caddr_t dpos, cp2, cp;
+ int len, i;
+ u_int32_t *tl;
+ caddr_t dpos;
u_int32_t nfsvers, auth_type;
- uid_t nickuid;
- int error = 0, nqnfs = 0, ticklen;
+ int error = 0;
struct mbuf *mrep, *md;
- register struct nfsuid *nuidp;
- struct timeval tvin, tvout;
-#if 0 /* until encrypted keys are implemented */
- NFSKERBKEYSCHED_T keys; /* stores key schedule */
-#endif
mrep = nd->nd_mrep;
md = nd->nd_md;
@@ -1766,38 +310,36 @@ nfs_getreq(nd, nfsd, has_header)
return (0);
}
if (*tl != nfs_prog) {
- if (*tl == nqnfs_prog)
- nqnfs++;
- else {
- nd->nd_repstat = EPROGUNAVAIL;
- nd->nd_procnum = NFSPROC_NOOP;
- return (0);
- }
+ nd->nd_repstat = EPROGUNAVAIL;
+ nd->nd_procnum = NFSPROC_NOOP;
+ return (0);
}
tl++;
nfsvers = fxdr_unsigned(u_int32_t, *tl++);
- if (((nfsvers < NFS_VER2 || nfsvers > NFS_VER3) && !nqnfs) ||
- (nfsvers != NQNFS_VER3 && nqnfs)) {
+ if (nfsvers < NFS_VER2 || nfsvers > NFS_VER3) {
nd->nd_repstat = EPROGMISMATCH;
nd->nd_procnum = NFSPROC_NOOP;
return (0);
}
- if (nqnfs)
- nd->nd_flag = (ND_NFSV3 | ND_NQNFS);
- else if (nfsvers == NFS_VER3)
- nd->nd_flag = ND_NFSV3;
nd->nd_procnum = fxdr_unsigned(u_int32_t, *tl++);
if (nd->nd_procnum == NFSPROC_NULL)
return (0);
- if (nd->nd_procnum >= NFS_NPROCS ||
- (!nqnfs && nd->nd_procnum >= NQNFSPROC_GETLEASE) ||
- (!nd->nd_flag && nd->nd_procnum > NFSV2PROC_STATFS)) {
- nd->nd_repstat = EPROCUNAVAIL;
- nd->nd_procnum = NFSPROC_NOOP;
- return (0);
- }
- if ((nd->nd_flag & ND_NFSV3) == 0)
+ if (nfsvers == NFS_VER3) {
+ nd->nd_flag = ND_NFSV3;
+ if (nd->nd_procnum >= NFS_NPROCS) {
+ nd->nd_repstat = EPROCUNAVAIL;
+ nd->nd_procnum = NFSPROC_NOOP;
+ return (0);
+ }
+ } else {
+ if (nd->nd_procnum > NFSV2PROC_STATFS) {
+ nd->nd_repstat = EPROCUNAVAIL;
+ nd->nd_procnum = NFSPROC_NOOP;
+ return (0);
+ }
+ /* Map the v2 procedure numbers into v3 ones */
nd->nd_procnum = nfsv3_procid[nd->nd_procnum];
+ }
auth_type = *tl++;
len = fxdr_unsigned(int, *tl++);
if (len < 0 || len > RPCAUTH_MAXSIZ) {
@@ -1805,9 +347,8 @@ nfs_getreq(nd, nfsd, has_header)
return (EBADRPC);
}
- nd->nd_flag &= ~ND_KERBAUTH;
/*
- * Handle auth_unix or auth_kerb.
+ * Handle auth_unix;
*/
if (auth_type == rpc_auth_unix) {
len = fxdr_unsigned(int, *++tl);
@@ -1842,123 +383,12 @@ nfs_getreq(nd, nfsd, has_header)
}
if (len > 0)
nfsm_adv(nfsm_rndup(len));
- } else if (auth_type == rpc_auth_kerb) {
- switch (fxdr_unsigned(int, *tl++)) {
- case RPCAKN_FULLNAME:
- ticklen = fxdr_unsigned(int, *tl);
- *((u_int32_t *)nfsd->nfsd_authstr) = *tl;
- uio.uio_resid = nfsm_rndup(ticklen) + NFSX_UNSIGNED;
- nfsd->nfsd_authlen = uio.uio_resid + NFSX_UNSIGNED;
- if (uio.uio_resid > (len - 2 * NFSX_UNSIGNED)) {
- m_freem(mrep);
- return (EBADRPC);
- }
- uio.uio_offset = 0;
- uio.uio_iov = &iov;
- uio.uio_iovcnt = 1;
- uio.uio_segflg = UIO_SYSSPACE;
- iov.iov_base = (caddr_t)&nfsd->nfsd_authstr[4];
- iov.iov_len = RPCAUTH_MAXSIZ - 4;
- nfsm_mtouio(&uio, uio.uio_resid);
- nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
- if (*tl++ != rpc_auth_kerb ||
- fxdr_unsigned(int, *tl) != 4 * NFSX_UNSIGNED) {
- printf("Bad kerb verifier\n");
- nd->nd_repstat = (NFSERR_AUTHERR|AUTH_BADVERF);
- nd->nd_procnum = NFSPROC_NOOP;
- return (0);
- }
- nfsm_dissect(cp, caddr_t, 4 * NFSX_UNSIGNED);
- tl = (u_int32_t *)cp;
- if (fxdr_unsigned(int, *tl) != RPCAKN_FULLNAME) {
- printf("Not fullname kerb verifier\n");
- nd->nd_repstat = (NFSERR_AUTHERR|AUTH_BADVERF);
- nd->nd_procnum = NFSPROC_NOOP;
- return (0);
- }
- cp += NFSX_UNSIGNED;
- bcopy(cp, nfsd->nfsd_verfstr, 3 * NFSX_UNSIGNED);
- nfsd->nfsd_verflen = 3 * NFSX_UNSIGNED;
- nd->nd_flag |= ND_KERBFULL;
- nfsd->nfsd_flag |= NFSD_NEEDAUTH;
- break;
- case RPCAKN_NICKNAME:
- if (len != 2 * NFSX_UNSIGNED) {
- printf("Kerb nickname short\n");
- nd->nd_repstat = (NFSERR_AUTHERR|AUTH_BADCRED);
- nd->nd_procnum = NFSPROC_NOOP;
- return (0);
- }
- nickuid = fxdr_unsigned(uid_t, *tl);
- nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
- if (*tl++ != rpc_auth_kerb ||
- fxdr_unsigned(int, *tl) != 3 * NFSX_UNSIGNED) {
- printf("Kerb nick verifier bad\n");
- nd->nd_repstat = (NFSERR_AUTHERR|AUTH_BADVERF);
- nd->nd_procnum = NFSPROC_NOOP;
- return (0);
- }
- nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
- tvin.tv_sec = *tl++;
- tvin.tv_usec = *tl;
-
- for (nuidp = NUIDHASH(nfsd->nfsd_slp,nickuid)->lh_first;
- nuidp != 0; nuidp = nuidp->nu_hash.le_next) {
- if (nuidp->nu_cr.cr_uid == nickuid &&
- (!nd->nd_nam2 ||
- netaddr_match(NU_NETFAM(nuidp),
- &nuidp->nu_haddr, nd->nd_nam2)))
- break;
- }
- if (!nuidp) {
- nd->nd_repstat =
- (NFSERR_AUTHERR|AUTH_REJECTCRED);
- nd->nd_procnum = NFSPROC_NOOP;
- return (0);
- }
-
- /*
- * Now, decrypt the timestamp using the session key
- * and validate it.
- */
-#ifdef NFSKERB
- XXX
-#endif
-
- tvout.tv_sec = fxdr_unsigned(long, tvout.tv_sec);
- tvout.tv_usec = fxdr_unsigned(long, tvout.tv_usec);
- if (nuidp->nu_expire < time_second ||
- nuidp->nu_timestamp.tv_sec > tvout.tv_sec ||
- (nuidp->nu_timestamp.tv_sec == tvout.tv_sec &&
- nuidp->nu_timestamp.tv_usec > tvout.tv_usec)) {
- nuidp->nu_expire = 0;
- nd->nd_repstat =
- (NFSERR_AUTHERR|AUTH_REJECTVERF);
- nd->nd_procnum = NFSPROC_NOOP;
- return (0);
- }
- nfsrv_setcred(&nuidp->nu_cr, &nd->nd_cr);
- nd->nd_flag |= ND_KERBNICK;
- };
} else {
nd->nd_repstat = (NFSERR_AUTHERR | AUTH_REJECTCRED);
nd->nd_procnum = NFSPROC_NOOP;
return (0);
}
- /*
- * For nqnfs, get piggybacked lease request.
- */
- if (nqnfs && nd->nd_procnum != NQNFSPROC_EVICTED) {
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
- nd->nd_flag |= fxdr_unsigned(int, *tl);
- if (nd->nd_flag & ND_LEASE) {
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED);
- nd->nd_duration = fxdr_unsigned(int32_t, *tl);
- } else
- nd->nd_duration = NQ_MINLEASE;
- } else
- nd->nd_duration = NQ_MINLEASE;
nd->nd_md = md;
nd->nd_dpos = dpos;
return (0);
@@ -1966,19 +396,6 @@ nfsmout:
return (error);
}
-#endif
-
-static int
-nfs_msg(td, server, msg)
- struct thread *td;
- char *server, *msg;
-{
-
- tprintf(td->td_proc, LOG_INFO, "nfs server %s: %s\n", server, msg);
- return (0);
-}
-
-#ifndef NFS_NOSERVER
/*
* Socket upcall routine for the nfsd sockets.
* The caddr_t arg is a pointer to the "struct nfssvc_sock".
@@ -1986,13 +403,10 @@ nfs_msg(td, server, msg)
* be called with M_TRYWAIT from an nfsd.
*/
void
-nfsrv_rcv(so, arg, waitflag)
- struct socket *so;
- void *arg;
- int waitflag;
+nfsrv_rcv(struct socket *so, void *arg, int waitflag)
{
- register struct nfssvc_sock *slp = (struct nfssvc_sock *)arg;
- register struct mbuf *m;
+ struct nfssvc_sock *slp = (struct nfssvc_sock *)arg;
+ struct mbuf *m;
struct mbuf *mp;
struct sockaddr *nam;
struct uio auio;
@@ -2005,7 +419,8 @@ nfsrv_rcv(so, arg, waitflag)
* Define this to test for nfsds handling this under heavy load.
*/
if (waitflag == M_DONTWAIT) {
- slp->ns_flag |= SLP_NEEDQ; goto dorecs;
+ slp->ns_flag |= SLP_NEEDQ;
+ goto dorecs;
}
#endif
auio.uio_td = NULL;
@@ -2104,13 +519,11 @@ dorecs:
* can sleep.
*/
static int
-nfsrv_getstream(slp, waitflag)
- register struct nfssvc_sock *slp;
- int waitflag;
+nfsrv_getstream(struct nfssvc_sock *slp, int waitflag)
{
- register struct mbuf *m, **mpp;
- register char *cp1, *cp2;
- register int len;
+ struct mbuf *m, **mpp;
+ char *cp1, *cp2;
+ int len;
struct mbuf *om, *m2, *recm = NULL;
u_int32_t recmark;
@@ -2229,15 +642,13 @@ nfsrv_getstream(slp, waitflag)
* Parse an RPC header.
*/
int
-nfsrv_dorec(slp, nfsd, ndp)
- register struct nfssvc_sock *slp;
- struct nfsd *nfsd;
- struct nfsrv_descript **ndp;
+nfsrv_dorec(struct nfssvc_sock *slp, struct nfsd *nfsd,
+ struct nfsrv_descript **ndp)
{
struct nfsrv_rec *rec;
- register struct mbuf *m;
+ struct mbuf *m;
struct sockaddr *nam;
- register struct nfsrv_descript *nd;
+ struct nfsrv_descript *nd;
int error;
*ndp = NULL;
@@ -2272,14 +683,13 @@ nfsrv_dorec(slp, nfsd, ndp)
* running nfsds will go look for the work in the nfssvc_sock list.
*/
void
-nfsrv_wakenfsd(slp)
- struct nfssvc_sock *slp;
+nfsrv_wakenfsd(struct nfssvc_sock *slp)
{
- register struct nfsd *nd;
+ struct nfsd *nd;
if ((slp->ns_flag & SLP_VALID) == 0)
return;
- for (nd = nfsd_head.tqh_first; nd != 0; nd = nd->nfsd_chain.tqe_next) {
+ TAILQ_FOREACH(nd, &nfsd_head, nfsd_chain) {
if (nd->nfsd_flag & NFSD_WAITING) {
nd->nfsd_flag &= ~NFSD_WAITING;
if (nd->nfsd_slp)
@@ -2293,4 +703,71 @@ nfsrv_wakenfsd(slp)
slp->ns_flag |= SLP_DOREC;
nfsd_head_flag |= NFSD_CHECKSLP;
}
-#endif /* NFS_NOSERVER */
+
+/*
+ * This is the nfs send routine.
+ * For the server side:
+ * - return EINTR or ERESTART if interrupted by a signal
+ * - return EPIPE if a connection is lost for connection based sockets (TCP...)
+ * - do any cleanup required by recoverable socket errors (?)
+ */
+int
+nfsrv_send(struct socket *so, struct sockaddr *nam, struct mbuf *top)
+{
+ struct sockaddr *sendnam;
+ int error, soflags, flags;
+
+ soflags = so->so_proto->pr_flags;
+ if ((soflags & PR_CONNREQUIRED) || (so->so_state & SS_ISCONNECTED))
+ sendnam = (struct sockaddr *)0;
+ else
+ sendnam = nam;
+ if (so->so_type == SOCK_SEQPACKET)
+ flags = MSG_EOR;
+ else
+ flags = 0;
+
+ error = so->so_proto->pr_usrreqs->pru_sosend(so, sendnam, 0, top, 0,
+ flags, curthread/*XXX*/);
+ if (error == ENOBUFS && so->so_type == SOCK_DGRAM)
+ error = 0;
+
+ if (error) {
+ log(LOG_INFO, "nfsd send error %d\n", error);
+
+ /*
+ * Handle any recoverable (soft) socket errors here. (?)
+ */
+ if (error != EINTR && error != ERESTART &&
+ error != EWOULDBLOCK && error != EPIPE)
+ error = 0;
+ }
+ return (error);
+}
+
+/*
+ * Nfs timer routine
+ * Scan the nfsreq list and retranmit any requests that have timed out
+ * To avoid retransmission attempts on STREAM sockets (in the future) make
+ * sure to set the r_retry field to 0 (implies nm_retry == 0).
+ */
+void
+nfsrv_timer(void *arg)
+{
+ int s;
+ struct nfssvc_sock *slp;
+ u_quad_t cur_usec;
+
+ s = splnet();
+ /*
+ * Scan the write gathering queues for writes that need to be
+ * completed now.
+ */
+ cur_usec = nfs_curusec();
+ TAILQ_FOREACH(slp, &nfssvc_sockhead, ns_chain) {
+ if (LIST_FIRST(&slp->ns_tq) && LIST_FIRST(&slp->ns_tq)->nd_time<=cur_usec)
+ nfsrv_wakenfsd(slp);
+ }
+ splx(s);
+ nfsrv_timer_handle = timeout(nfsrv_timer, (void *)0, nfs_ticks);
+}
diff --git a/sys/nfsserver/nfs_srvsubs.c b/sys/nfsserver/nfs_srvsubs.c
index 4425129..31a095f 100644
--- a/sys/nfsserver/nfs_srvsubs.c
+++ b/sys/nfsserver/nfs_srvsubs.c
@@ -37,11 +37,15 @@
* $FreeBSD$
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
/*
* These functions support the macros and help fiddle mbuf chains for
* the nfs op functions. They do things like create the rpc header and
* copy data between mbuf chains and uio lists.
*/
+
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
@@ -57,6 +61,7 @@
#include <sys/malloc.h>
#include <sys/sysent.h>
#include <sys/syscall.h>
+#include <sys/sysproto.h>
#include <vm/vm.h>
#include <vm/vm_object.h>
@@ -65,13 +70,9 @@
#include <nfs/rpcv2.h>
#include <nfs/nfsproto.h>
-#include <nfs/nfs.h>
-#include <nfs/nfsnode.h>
+#include <nfsserver/nfs.h>
#include <nfs/xdr_subs.h>
-#include <nfs/nfsm_subs.h>
-#include <nfs/nfsmount.h>
-#include <nfs/nqnfs.h>
-#include <nfs/nfsrtt.h>
+#include <nfsserver/nfsm_subs.h>
#include <netinet/in.h>
@@ -81,40 +82,25 @@
*/
u_int32_t nfs_xdrneg1;
u_int32_t rpc_call, rpc_vers, rpc_reply, rpc_msgdenied, rpc_autherr,
- rpc_mismatch, rpc_auth_unix, rpc_msgaccepted,
- rpc_auth_kerb;
-u_int32_t nfs_prog, nqnfs_prog, nfs_true, nfs_false;
+ rpc_mismatch, rpc_auth_unix, rpc_msgaccepted;
+u_int32_t nfs_prog, nfs_true, nfs_false;
/* And other global data */
-static u_int32_t nfs_xid = 0;
-static enum vtype nv2tov_type[8]= {
- VNON, VREG, VDIR, VBLK, VCHR, VLNK, VNON, VNON
-};
-enum vtype nv3tov_type[8]= {
- VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO
-};
+static nfstype nfsv2_type[9] = { NFNON, NFREG, NFDIR, NFBLK, NFCHR, NFLNK,
+ NFNON, NFCHR, NFNON };
+#define vtonfsv2_type(a) txdr_unsigned(nfsv2_type[((int32_t)(a))])
+#define vtonfsv3_mode(m) txdr_unsigned((m) & ALLPERMS)
int nfs_ticks;
-int nfs_pbuf_freecnt = -1; /* start out unlimited */
-struct nfs_reqq nfs_reqq;
struct nfssvc_sockhead nfssvc_sockhead;
int nfssvc_sockhead_flag;
struct nfsd_head nfsd_head;
int nfsd_head_flag;
-struct nfs_bufq nfs_bufq;
-struct nqtimerhead nqtimerhead;
-struct nqfhhashhead *nqfhhashtbl;
-u_long nqfhhash;
-static void (*nfs_prev_lease_updatetime) __P((int));
static int nfs_prev_nfssvc_sy_narg;
static sy_call_t *nfs_prev_nfssvc_sy_call;
-#ifndef NFS_NOSERVER
-
-static vop_t *nfs_prev_vop_lease_check;
-
/*
* Mapping of old NFS Version 2 RPC numbers to generic numbers.
*/
@@ -142,16 +128,12 @@ int nfsv3_procid[NFS_NPROCS] = {
NFSPROC_NOOP,
NFSPROC_NOOP,
NFSPROC_NOOP,
- NFSPROC_NOOP,
- NFSPROC_NOOP,
- NFSPROC_NOOP
};
-#endif /* NFS_NOSERVER */
/*
* and the reverse mapping from generic to Version 2 procedure numbers
*/
-int nfsv2_procid[NFS_NPROCS] = {
+int nfsrvv2_procid[NFS_NPROCS] = {
NFSV2PROC_NULL,
NFSV2PROC_GETATTR,
NFSV2PROC_SETATTR,
@@ -175,12 +157,8 @@ int nfsv2_procid[NFS_NPROCS] = {
NFSV2PROC_NOOP,
NFSV2PROC_NOOP,
NFSV2PROC_NOOP,
- NFSV2PROC_NOOP,
- NFSV2PROC_NOOP,
- NFSV2PROC_NOOP,
};
-#ifndef NFS_NOSERVER
/*
* Maps errno values to nfs error numbers.
* Use NFSERR_IO as the catch all for ones not specifically defined in
@@ -539,573 +517,13 @@ static short *nfsrv_v3errmap[] = {
nfsv3err_commit,
};
-#endif /* NFS_NOSERVER */
-
-extern struct nfsrtt nfsrtt;
-extern time_t nqnfsstarttime;
-extern int nqsrv_clockskew;
-extern int nqsrv_writeslack;
-extern int nqsrv_maxlease;
-extern struct nfsstats nfsstats;
-extern int nqnfs_piggy[NFS_NPROCS];
-extern nfstype nfsv2_type[9];
-extern nfstype nfsv3_type[9];
-extern struct nfsnodehashhead *nfsnodehashtbl;
-extern u_long nfsnodehash;
-
-struct nfssvc_args;
-extern int nfssvc(struct thread *, struct nfssvc_args *, int *);
-
-LIST_HEAD(nfsnodehashhead, nfsnode);
-
-int nfs_webnamei __P((struct nameidata *, struct vnode *, struct thread *));
-
-u_quad_t
-nfs_curusec()
-{
- struct timeval tv;
-
- getmicrotime(&tv);
- return ((u_quad_t)tv.tv_sec * 1000000 + (u_quad_t)tv.tv_usec);
-}
-
-/*
- * Create the header for an rpc request packet
- * The hsiz is the size of the rest of the nfs request header.
- * (just used to decide if a cluster is a good idea)
- */
-struct mbuf *
-nfsm_reqh(vp, procid, hsiz, bposp)
- struct vnode *vp;
- u_long procid;
- int hsiz;
- caddr_t *bposp;
-{
- register struct mbuf *mb;
- register u_int32_t *tl;
- register caddr_t bpos;
- struct mbuf *mb2;
- struct nfsmount *nmp;
- int nqflag;
-
- MGET(mb, M_TRYWAIT, MT_DATA);
- if (hsiz >= MINCLSIZE)
- MCLGET(mb, M_TRYWAIT);
- mb->m_len = 0;
- bpos = mtod(mb, caddr_t);
-
- /*
- * For NQNFS, add lease request.
- */
- if (vp) {
- nmp = VFSTONFS(vp->v_mount);
- if (nmp->nm_flag & NFSMNT_NQNFS) {
- nqflag = NQNFS_NEEDLEASE(vp, procid);
- if (nqflag) {
- nfsm_build(tl, u_int32_t *, 2*NFSX_UNSIGNED);
- *tl++ = txdr_unsigned(nqflag);
- *tl = txdr_unsigned(nmp->nm_leaseterm);
- } else {
- nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
- *tl = 0;
- }
- }
- }
- /* Finally, return values */
- *bposp = bpos;
- return (mb);
-}
-
-/*
- * Build the RPC header and fill in the authorization info.
- * The authorization string argument is only used when the credentials
- * come from outside of the kernel.
- * Returns the head of the mbuf list.
- */
-struct mbuf *
-nfsm_rpchead(cr, nmflag, procid, auth_type, auth_len, auth_str, verf_len,
- verf_str, mrest, mrest_len, mbp, xidp)
- register struct ucred *cr;
- int nmflag;
- int procid;
- int auth_type;
- int auth_len;
- char *auth_str;
- int verf_len;
- char *verf_str;
- struct mbuf *mrest;
- int mrest_len;
- struct mbuf **mbp;
- u_int32_t *xidp;
-{
- register struct mbuf *mb;
- register u_int32_t *tl;
- register caddr_t bpos;
- register int i;
- struct mbuf *mreq, *mb2;
- int siz, grpsiz, authsiz;
-
- authsiz = nfsm_rndup(auth_len);
- MGETHDR(mb, M_TRYWAIT, MT_DATA);
- if ((authsiz + 10 * NFSX_UNSIGNED) >= MINCLSIZE) {
- MCLGET(mb, M_TRYWAIT);
- } else if ((authsiz + 10 * NFSX_UNSIGNED) < MHLEN) {
- MH_ALIGN(mb, authsiz + 10 * NFSX_UNSIGNED);
- } else {
- MH_ALIGN(mb, 8 * NFSX_UNSIGNED);
- }
- mb->m_len = 0;
- mreq = mb;
- bpos = mtod(mb, caddr_t);
-
- /*
- * First the RPC header.
- */
- nfsm_build(tl, u_int32_t *, 8 * NFSX_UNSIGNED);
-
- /* Get a pretty random xid to start with */
- if (!nfs_xid)
- nfs_xid = random();
- /*
- * Skip zero xid if it should ever happen.
- */
- if (++nfs_xid == 0)
- nfs_xid++;
-
- *tl++ = *xidp = txdr_unsigned(nfs_xid);
- *tl++ = rpc_call;
- *tl++ = rpc_vers;
- if (nmflag & NFSMNT_NQNFS) {
- *tl++ = txdr_unsigned(NQNFS_PROG);
- *tl++ = txdr_unsigned(NQNFS_VER3);
- } else {
- *tl++ = txdr_unsigned(NFS_PROG);
- if (nmflag & NFSMNT_NFSV3)
- *tl++ = txdr_unsigned(NFS_VER3);
- else
- *tl++ = txdr_unsigned(NFS_VER2);
- }
- if (nmflag & NFSMNT_NFSV3)
- *tl++ = txdr_unsigned(procid);
- else
- *tl++ = txdr_unsigned(nfsv2_procid[procid]);
-
- /*
- * And then the authorization cred.
- */
- *tl++ = txdr_unsigned(auth_type);
- *tl = txdr_unsigned(authsiz);
- switch (auth_type) {
- case RPCAUTH_UNIX:
- nfsm_build(tl, u_int32_t *, auth_len);
- *tl++ = 0; /* stamp ?? */
- *tl++ = 0; /* NULL hostname */
- *tl++ = txdr_unsigned(cr->cr_uid);
- *tl++ = txdr_unsigned(cr->cr_groups[0]);
- grpsiz = (auth_len >> 2) - 5;
- *tl++ = txdr_unsigned(grpsiz);
- for (i = 1; i <= grpsiz; i++)
- *tl++ = txdr_unsigned(cr->cr_groups[i]);
- break;
- case RPCAUTH_KERB4:
- siz = auth_len;
- while (siz > 0) {
- if (M_TRAILINGSPACE(mb) == 0) {
- MGET(mb2, M_TRYWAIT, MT_DATA);
- if (siz >= MINCLSIZE)
- MCLGET(mb2, M_TRYWAIT);
- mb->m_next = mb2;
- mb = mb2;
- mb->m_len = 0;
- bpos = mtod(mb, caddr_t);
- }
- i = min(siz, M_TRAILINGSPACE(mb));
- bcopy(auth_str, bpos, i);
- mb->m_len += i;
- auth_str += i;
- bpos += i;
- siz -= i;
- }
- if ((siz = (nfsm_rndup(auth_len) - auth_len)) > 0) {
- for (i = 0; i < siz; i++)
- *bpos++ = '\0';
- mb->m_len += siz;
- }
- break;
- };
-
- /*
- * And the verifier...
- */
- nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
- if (verf_str) {
- *tl++ = txdr_unsigned(RPCAUTH_KERB4);
- *tl = txdr_unsigned(verf_len);
- siz = verf_len;
- while (siz > 0) {
- if (M_TRAILINGSPACE(mb) == 0) {
- MGET(mb2, M_TRYWAIT, MT_DATA);
- if (siz >= MINCLSIZE)
- MCLGET(mb2, M_TRYWAIT);
- mb->m_next = mb2;
- mb = mb2;
- mb->m_len = 0;
- bpos = mtod(mb, caddr_t);
- }
- i = min(siz, M_TRAILINGSPACE(mb));
- bcopy(verf_str, bpos, i);
- mb->m_len += i;
- verf_str += i;
- bpos += i;
- siz -= i;
- }
- if ((siz = (nfsm_rndup(verf_len) - verf_len)) > 0) {
- for (i = 0; i < siz; i++)
- *bpos++ = '\0';
- mb->m_len += siz;
- }
- } else {
- *tl++ = txdr_unsigned(RPCAUTH_NULL);
- *tl = 0;
- }
- mb->m_next = mrest;
- mreq->m_pkthdr.len = authsiz + 10 * NFSX_UNSIGNED + mrest_len;
- mreq->m_pkthdr.rcvif = (struct ifnet *)0;
- *mbp = mb;
- return (mreq);
-}
-
-/*
- * copies mbuf chain to the uio scatter/gather list
- */
-int
-nfsm_mbuftouio(mrep, uiop, siz, dpos)
- struct mbuf **mrep;
- register struct uio *uiop;
- int siz;
- caddr_t *dpos;
-{
- register char *mbufcp, *uiocp;
- register int xfer, left, len;
- register struct mbuf *mp;
- long uiosiz, rem;
- int error = 0;
-
- mp = *mrep;
- mbufcp = *dpos;
- len = mtod(mp, caddr_t)+mp->m_len-mbufcp;
- rem = nfsm_rndup(siz)-siz;
- while (siz > 0) {
- if (uiop->uio_iovcnt <= 0 || uiop->uio_iov == NULL)
- return (EFBIG);
- left = uiop->uio_iov->iov_len;
- uiocp = uiop->uio_iov->iov_base;
- if (left > siz)
- left = siz;
- uiosiz = left;
- while (left > 0) {
- while (len == 0) {
- mp = mp->m_next;
- if (mp == NULL)
- return (EBADRPC);
- mbufcp = mtod(mp, caddr_t);
- len = mp->m_len;
- }
- xfer = (left > len) ? len : left;
-#ifdef notdef
- /* Not Yet.. */
- if (uiop->uio_iov->iov_op != NULL)
- (*(uiop->uio_iov->iov_op))
- (mbufcp, uiocp, xfer);
- else
-#endif
- if (uiop->uio_segflg == UIO_SYSSPACE)
- bcopy(mbufcp, uiocp, xfer);
- else
- copyout(mbufcp, uiocp, xfer);
- left -= xfer;
- len -= xfer;
- mbufcp += xfer;
- uiocp += xfer;
- uiop->uio_offset += xfer;
- uiop->uio_resid -= xfer;
- }
- if (uiop->uio_iov->iov_len <= siz) {
- uiop->uio_iovcnt--;
- uiop->uio_iov++;
- } else {
- uiop->uio_iov->iov_base += uiosiz;
- uiop->uio_iov->iov_len -= uiosiz;
- }
- siz -= uiosiz;
- }
- *dpos = mbufcp;
- *mrep = mp;
- if (rem > 0) {
- if (len < rem)
- error = nfs_adv(mrep, dpos, rem, len);
- else
- *dpos += rem;
- }
- return (error);
-}
-
-/*
- * copies a uio scatter/gather list to an mbuf chain.
- * NOTE: can ony handle iovcnt == 1
- */
-int
-nfsm_uiotombuf(uiop, mq, siz, bpos)
- register struct uio *uiop;
- struct mbuf **mq;
- int siz;
- caddr_t *bpos;
-{
- register char *uiocp;
- register struct mbuf *mp, *mp2;
- register int xfer, left, mlen;
- int uiosiz, clflg, rem;
- char *cp;
-
-#ifdef DIAGNOSTIC
- if (uiop->uio_iovcnt != 1)
- panic("nfsm_uiotombuf: iovcnt != 1");
-#endif
-
- if (siz > MLEN) /* or should it >= MCLBYTES ?? */
- clflg = 1;
- else
- clflg = 0;
- rem = nfsm_rndup(siz)-siz;
- mp = mp2 = *mq;
- while (siz > 0) {
- left = uiop->uio_iov->iov_len;
- uiocp = uiop->uio_iov->iov_base;
- if (left > siz)
- left = siz;
- uiosiz = left;
- while (left > 0) {
- mlen = M_TRAILINGSPACE(mp);
- if (mlen == 0) {
- MGET(mp, M_TRYWAIT, MT_DATA);
- if (clflg)
- MCLGET(mp, M_TRYWAIT);
- mp->m_len = 0;
- mp2->m_next = mp;
- mp2 = mp;
- mlen = M_TRAILINGSPACE(mp);
- }
- xfer = (left > mlen) ? mlen : left;
-#ifdef notdef
- /* Not Yet.. */
- if (uiop->uio_iov->iov_op != NULL)
- (*(uiop->uio_iov->iov_op))
- (uiocp, mtod(mp, caddr_t)+mp->m_len, xfer);
- else
-#endif
- if (uiop->uio_segflg == UIO_SYSSPACE)
- bcopy(uiocp, mtod(mp, caddr_t)+mp->m_len, xfer);
- else
- copyin(uiocp, mtod(mp, caddr_t)+mp->m_len, xfer);
- mp->m_len += xfer;
- left -= xfer;
- uiocp += xfer;
- uiop->uio_offset += xfer;
- uiop->uio_resid -= xfer;
- }
- uiop->uio_iov->iov_base += uiosiz;
- uiop->uio_iov->iov_len -= uiosiz;
- siz -= uiosiz;
- }
- if (rem > 0) {
- if (rem > M_TRAILINGSPACE(mp)) {
- MGET(mp, M_TRYWAIT, MT_DATA);
- mp->m_len = 0;
- mp2->m_next = mp;
- }
- cp = mtod(mp, caddr_t)+mp->m_len;
- for (left = 0; left < rem; left++)
- *cp++ = '\0';
- mp->m_len += rem;
- *bpos = cp;
- } else
- *bpos = mtod(mp, caddr_t)+mp->m_len;
- *mq = mp;
- return (0);
-}
-
-/*
- * Help break down an mbuf chain by setting the first siz bytes contiguous
- * pointed to by returned val.
- * This is used by the macros nfsm_dissect and nfsm_dissecton for tough
- * cases. (The macros use the vars. dpos and dpos2)
- */
-int
-nfsm_disct(mdp, dposp, siz, left, cp2)
- struct mbuf **mdp;
- caddr_t *dposp;
- int siz;
- int left;
- caddr_t *cp2;
-{
- register struct mbuf *mp, *mp2;
- register int siz2, xfer;
- register caddr_t ptr;
-
- mp = *mdp;
- while (left == 0) {
- *mdp = mp = mp->m_next;
- if (mp == NULL)
- return (EBADRPC);
- left = mp->m_len;
- *dposp = mtod(mp, caddr_t);
- }
- if (left >= siz) {
- *cp2 = *dposp;
- *dposp += siz;
- } else if (mp->m_next == NULL) {
- return (EBADRPC);
- } else if (siz > MHLEN) {
- panic("nfs S too big");
- } else {
- MGET(mp2, M_TRYWAIT, MT_DATA);
- mp2->m_next = mp->m_next;
- mp->m_next = mp2;
- mp->m_len -= left;
- mp = mp2;
- *cp2 = ptr = mtod(mp, caddr_t);
- bcopy(*dposp, ptr, left); /* Copy what was left */
- siz2 = siz-left;
- ptr += left;
- mp2 = mp->m_next;
- /* Loop around copying up the siz2 bytes */
- while (siz2 > 0) {
- if (mp2 == NULL)
- return (EBADRPC);
- xfer = (siz2 > mp2->m_len) ? mp2->m_len : siz2;
- if (xfer > 0) {
- bcopy(mtod(mp2, caddr_t), ptr, xfer);
- NFSMADV(mp2, xfer);
- mp2->m_len -= xfer;
- ptr += xfer;
- siz2 -= xfer;
- }
- if (siz2 > 0)
- mp2 = mp2->m_next;
- }
- mp->m_len = siz;
- *mdp = mp2;
- *dposp = mtod(mp2, caddr_t);
- }
- return (0);
-}
-
-/*
- * Advance the position in the mbuf chain.
- */
-int
-nfs_adv(mdp, dposp, offs, left)
- struct mbuf **mdp;
- caddr_t *dposp;
- int offs;
- int left;
-{
- register struct mbuf *m;
- register int s;
-
- m = *mdp;
- s = left;
- while (s < offs) {
- offs -= s;
- m = m->m_next;
- if (m == NULL)
- return (EBADRPC);
- s = m->m_len;
- }
- *mdp = m;
- *dposp = mtod(m, caddr_t)+offs;
- return (0);
-}
-
-/*
- * Copy a string into mbufs for the hard cases...
- */
-int
-nfsm_strtmbuf(mb, bpos, cp, siz)
- struct mbuf **mb;
- char **bpos;
- const char *cp;
- long siz;
-{
- register struct mbuf *m1 = NULL, *m2;
- long left, xfer, len, tlen;
- u_int32_t *tl;
- int putsize;
-
- putsize = 1;
- m2 = *mb;
- left = M_TRAILINGSPACE(m2);
- if (left > 0) {
- tl = ((u_int32_t *)(*bpos));
- *tl++ = txdr_unsigned(siz);
- putsize = 0;
- left -= NFSX_UNSIGNED;
- m2->m_len += NFSX_UNSIGNED;
- if (left > 0) {
- bcopy(cp, (caddr_t) tl, left);
- siz -= left;
- cp += left;
- m2->m_len += left;
- left = 0;
- }
- }
- /* Loop around adding mbufs */
- while (siz > 0) {
- MGET(m1, M_TRYWAIT, MT_DATA);
- if (siz > MLEN)
- MCLGET(m1, M_TRYWAIT);
- m1->m_len = NFSMSIZ(m1);
- m2->m_next = m1;
- m2 = m1;
- tl = mtod(m1, u_int32_t *);
- tlen = 0;
- if (putsize) {
- *tl++ = txdr_unsigned(siz);
- m1->m_len -= NFSX_UNSIGNED;
- tlen = NFSX_UNSIGNED;
- putsize = 0;
- }
- if (siz < m1->m_len) {
- len = nfsm_rndup(siz);
- xfer = siz;
- if (xfer < len)
- *(tl+(xfer>>2)) = 0;
- } else {
- xfer = len = m1->m_len;
- }
- bcopy(cp, (caddr_t) tl, xfer);
- m1->m_len = len+tlen;
- siz -= xfer;
- cp += xfer;
- }
- *mb = m1;
- *bpos = mtod(m1, caddr_t)+m1->m_len;
- return (0);
-}
-
/*
* Called once to initialize data structures...
*/
-int
-nfs_init(vfsp)
- struct vfsconf *vfsp;
+static int
+nfs_init(void *dummy __unused)
{
- register int i;
-
- nfsmount_zone = zinit("NFSMOUNT", sizeof(struct nfsmount), 0, 0, 1);
- nfs_mount_type = vfsp->vfc_typenum;
- nfsrtt.pos = 0;
rpc_vers = txdr_unsigned(RPC_VER2);
rpc_call = txdr_unsigned(RPC_CALL);
rpc_reply = txdr_unsigned(RPC_REPLY);
@@ -1114,340 +532,40 @@ nfs_init(vfsp)
rpc_mismatch = txdr_unsigned(RPC_MISMATCH);
rpc_autherr = txdr_unsigned(RPC_AUTHERR);
rpc_auth_unix = txdr_unsigned(RPCAUTH_UNIX);
- rpc_auth_kerb = txdr_unsigned(RPCAUTH_KERB4);
nfs_prog = txdr_unsigned(NFS_PROG);
- nqnfs_prog = txdr_unsigned(NQNFS_PROG);
nfs_true = txdr_unsigned(TRUE);
nfs_false = txdr_unsigned(FALSE);
nfs_xdrneg1 = txdr_unsigned(-1);
nfs_ticks = (hz * NFS_TICKINTVL + 500) / 1000;
if (nfs_ticks < 1)
nfs_ticks = 1;
- /* Ensure async daemons disabled */
- for (i = 0; i < NFS_MAXASYNCDAEMON; i++) {
- nfs_iodwant[i] = (struct proc *)0;
- nfs_iodmount[i] = (struct nfsmount *)0;
- }
- nfs_nhinit(); /* Init the nfsnode table */
-#ifndef NFS_NOSERVER
+
nfsrv_init(0); /* Init server data structures */
nfsrv_initcache(); /* Init the server request cache */
-#endif
-
- /*
- * Initialize the nqnfs server stuff.
- */
- if (nqnfsstarttime == 0) {
- nqnfsstarttime = boottime.tv_sec + nqsrv_maxlease
- + nqsrv_clockskew + nqsrv_writeslack;
- NQLOADNOVRAM(nqnfsstarttime);
- TAILQ_INIT(&nqtimerhead);
- nqfhhashtbl = hashinit(NQLCHSZ, M_NQLEASE, &nqfhhash);
- }
- /*
- * Initialize reply list and start timer
- */
- TAILQ_INIT(&nfs_reqq);
-
- nfs_timer(0);
+ nfsrv_timer(0);
- /*
- * Set up lease_check and lease_updatetime so that other parts
- * of the system can call us, if we are loadable.
- */
-#ifndef NFS_NOSERVER
- nfs_prev_vop_lease_check = default_vnodeop_p[VOFFSET(vop_lease)];
- default_vnodeop_p[VOFFSET(vop_lease)] = (vop_t *)nqnfs_vop_lease_check;
-#endif
- nfs_prev_lease_updatetime = lease_updatetime;
- lease_updatetime = nfs_lease_updatetime;
nfs_prev_nfssvc_sy_narg = sysent[SYS_nfssvc].sy_narg;
sysent[SYS_nfssvc].sy_narg = 2;
nfs_prev_nfssvc_sy_call = sysent[SYS_nfssvc].sy_call;
sysent[SYS_nfssvc].sy_call = (sy_call_t *)nfssvc;
- nfs_pbuf_freecnt = nswbuf / 2 + 1;
-
return (0);
}
+SYSINIT(nfs, SI_SUB_VFS, SI_ORDER_ANY, nfs_init, NULL);
-int
-nfs_uninit(vfsp)
- struct vfsconf *vfsp;
+static int
+nfs_uninit(void *dummy __unused)
{
- untimeout(nfs_timer, (void *)NULL, nfs_timer_handle);
- nfs_mount_type = -1;
-#ifndef NFS_NOSERVER
- default_vnodeop_p[VOFFSET(vop_lease)] = nfs_prev_vop_lease_check;
-#endif
- lease_updatetime = nfs_prev_lease_updatetime;
+ untimeout(nfsrv_timer, (void *)NULL, nfsrv_timer_handle);
sysent[SYS_nfssvc].sy_narg = nfs_prev_nfssvc_sy_narg;
sysent[SYS_nfssvc].sy_call = nfs_prev_nfssvc_sy_call;
return (0);
}
+SYSUNINIT(nfs, SI_SUB_VFS, SI_ORDER_ANY, nfs_uninit, NULL);
/*
- * Attribute cache routines.
- * nfs_loadattrcache() - loads or updates the cache contents from attributes
- * that are on the mbuf list
- * nfs_getattrcache() - returns valid attributes if found in cache, returns
- * error otherwise
- */
-
-/*
- * Load the attribute cache (that lives in the nfsnode entry) with
- * the values on the mbuf list and
- * Iff vap not NULL
- * copy the attributes to *vaper
- */
-int
-nfs_loadattrcache(vpp, mdp, dposp, vaper, dontshrink)
- struct vnode **vpp;
- struct mbuf **mdp;
- caddr_t *dposp;
- struct vattr *vaper;
- int dontshrink;
-{
- register struct vnode *vp = *vpp;
- register struct vattr *vap;
- register struct nfs_fattr *fp;
- register struct nfsnode *np;
- register int32_t t1;
- caddr_t cp2;
- int error = 0, rdev;
- struct mbuf *md;
- enum vtype vtyp;
- u_short vmode;
- struct timespec mtime;
- int v3 = NFS_ISV3(vp);
-
- md = *mdp;
- t1 = (mtod(md, caddr_t) + md->m_len) - *dposp;
- if ((error = nfsm_disct(mdp, dposp, NFSX_FATTR(v3), t1, &cp2)) != 0)
- return (error);
- fp = (struct nfs_fattr *)cp2;
- if (v3) {
- vtyp = nfsv3tov_type(fp->fa_type);
- vmode = fxdr_unsigned(u_short, fp->fa_mode);
- rdev = makeudev(fxdr_unsigned(int, fp->fa3_rdev.specdata1),
- fxdr_unsigned(int, fp->fa3_rdev.specdata2));
- fxdr_nfsv3time(&fp->fa3_mtime, &mtime);
- } else {
- vtyp = nfsv2tov_type(fp->fa_type);
- vmode = fxdr_unsigned(u_short, fp->fa_mode);
- /*
- * XXX
- *
- * The duplicate information returned in fa_type and fa_mode
- * is an ambiguity in the NFS version 2 protocol.
- *
- * VREG should be taken literally as a regular file. If a
- * server intents to return some type information differently
- * in the upper bits of the mode field (e.g. for sockets, or
- * FIFOs), NFSv2 mandates fa_type to be VNON. Anyway, we
- * leave the examination of the mode bits even in the VREG
- * case to avoid breakage for bogus servers, but we make sure
- * that there are actually type bits set in the upper part of
- * fa_mode (and failing that, trust the va_type field).
- *
- * NFSv3 cleared the issue, and requires fa_mode to not
- * contain any type information (while also introduing sockets
- * and FIFOs for fa_type).
- */
- if (vtyp == VNON || (vtyp == VREG && (vmode & S_IFMT) != 0))
- vtyp = IFTOVT(vmode);
- rdev = fxdr_unsigned(int32_t, fp->fa2_rdev);
- fxdr_nfsv2time(&fp->fa2_mtime, &mtime);
-
- /*
- * Really ugly NFSv2 kludge.
- */
- if (vtyp == VCHR && rdev == 0xffffffff)
- vtyp = VFIFO;
- }
-
- /*
- * If v_type == VNON it is a new node, so fill in the v_type,
- * n_mtime fields. Check to see if it represents a special
- * device, and if so, check for a possible alias. Once the
- * correct vnode has been obtained, fill in the rest of the
- * information.
- */
- np = VTONFS(vp);
- if (vp->v_type != vtyp) {
- vp->v_type = vtyp;
- if (vp->v_type == VFIFO) {
- vp->v_op = fifo_nfsv2nodeop_p;
- }
- if (vp->v_type == VCHR || vp->v_type == VBLK) {
- vp->v_op = spec_nfsv2nodeop_p;
- vp = addaliasu(vp, rdev);
- np->n_vnode = vp;
- }
- np->n_mtime = mtime.tv_sec;
- }
- vap = &np->n_vattr;
- vap->va_type = vtyp;
- vap->va_mode = (vmode & 07777);
- vap->va_rdev = rdev;
- vap->va_mtime = mtime;
- vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
- if (v3) {
- vap->va_nlink = fxdr_unsigned(u_short, fp->fa_nlink);
- vap->va_uid = fxdr_unsigned(uid_t, fp->fa_uid);
- vap->va_gid = fxdr_unsigned(gid_t, fp->fa_gid);
- vap->va_size = fxdr_hyper(&fp->fa3_size);
- vap->va_blocksize = NFS_FABLKSIZE;
- vap->va_bytes = fxdr_hyper(&fp->fa3_used);
- vap->va_fileid = fxdr_unsigned(int32_t,
- fp->fa3_fileid.nfsuquad[1]);
- fxdr_nfsv3time(&fp->fa3_atime, &vap->va_atime);
- fxdr_nfsv3time(&fp->fa3_ctime, &vap->va_ctime);
- vap->va_flags = 0;
- vap->va_filerev = 0;
- } else {
- vap->va_nlink = fxdr_unsigned(u_short, fp->fa_nlink);
- vap->va_uid = fxdr_unsigned(uid_t, fp->fa_uid);
- vap->va_gid = fxdr_unsigned(gid_t, fp->fa_gid);
- vap->va_size = fxdr_unsigned(u_int32_t, fp->fa2_size);
- vap->va_blocksize = fxdr_unsigned(int32_t, fp->fa2_blocksize);
- vap->va_bytes = (u_quad_t)fxdr_unsigned(int32_t, fp->fa2_blocks)
- * NFS_FABLKSIZE;
- vap->va_fileid = fxdr_unsigned(int32_t, fp->fa2_fileid);
- fxdr_nfsv2time(&fp->fa2_atime, &vap->va_atime);
- vap->va_flags = 0;
- vap->va_ctime.tv_sec = fxdr_unsigned(u_int32_t,
- fp->fa2_ctime.nfsv2_sec);
- vap->va_ctime.tv_nsec = 0;
- vap->va_gen = fxdr_unsigned(u_int32_t,fp->fa2_ctime.nfsv2_usec);
- vap->va_filerev = 0;
- }
- np->n_attrstamp = time_second;
- if (vap->va_size != np->n_size) {
- if (vap->va_type == VREG) {
- if (dontshrink && vap->va_size < np->n_size) {
- /*
- * We've been told not to shrink the file;
- * zero np->n_attrstamp to indicate that
- * the attributes are stale.
- */
- vap->va_size = np->n_size;
- np->n_attrstamp = 0;
- } else if (np->n_flag & NMODIFIED) {
- if (vap->va_size < np->n_size)
- vap->va_size = np->n_size;
- else
- np->n_size = vap->va_size;
- } else {
- np->n_size = vap->va_size;
- }
- vnode_pager_setsize(vp, np->n_size);
- } else {
- np->n_size = vap->va_size;
- }
- }
- if (vaper != NULL) {
- bcopy((caddr_t)vap, (caddr_t)vaper, sizeof(*vap));
- if (np->n_flag & NCHG) {
- if (np->n_flag & NACC)
- vaper->va_atime = np->n_atim;
- if (np->n_flag & NUPD)
- vaper->va_mtime = np->n_mtim;
- }
- }
- return (0);
-}
-
-#ifdef NFS_ACDEBUG
-#include <sys/sysctl.h>
-SYSCTL_DECL(_vfs_nfs);
-static int nfs_acdebug;
-SYSCTL_INT(_vfs_nfs, OID_AUTO, acdebug, CTLFLAG_RW, &nfs_acdebug, 0, "");
-#endif
-
-/*
- * Check the time stamp
- * If the cache is valid, copy contents to *vap and return 0
- * otherwise return an error
- */
-int
-nfs_getattrcache(vp, vaper)
- register struct vnode *vp;
- struct vattr *vaper;
-{
- register struct nfsnode *np;
- register struct vattr *vap;
- struct nfsmount *nmp;
- int timeo;
-
- np = VTONFS(vp);
- vap = &np->n_vattr;
- nmp = VFSTONFS(vp->v_mount);
- /* XXX n_mtime doesn't seem to be updated on a miss-and-reload */
- timeo = (time_second - np->n_mtime) / 10;
-
-#ifdef NFS_ACDEBUG
- if (nfs_acdebug>1)
- printf("nfs_getattrcache: initial timeo = %d\n", timeo);
-#endif
-
- if (vap->va_type == VDIR) {
- if ((np->n_flag & NMODIFIED) || timeo < nmp->nm_acdirmin)
- timeo = nmp->nm_acdirmin;
- else if (timeo > nmp->nm_acdirmax)
- timeo = nmp->nm_acdirmax;
- } else {
- if ((np->n_flag & NMODIFIED) || timeo < nmp->nm_acregmin)
- timeo = nmp->nm_acregmin;
- else if (timeo > nmp->nm_acregmax)
- timeo = nmp->nm_acregmax;
- }
-
-#ifdef NFS_ACDEBUG
- if (nfs_acdebug > 2)
- printf("acregmin %d; acregmax %d; acdirmin %d; acdirmax %d\n",
- nmp->nm_acregmin, nmp->nm_acregmax,
- nmp->nm_acdirmin, nmp->nm_acdirmax);
-
- if (nfs_acdebug)
- printf("nfs_getattrcache: age = %d; final timeo = %d\n",
- (time_second - np->n_attrstamp), timeo);
-#endif
-
- if ((time_second - np->n_attrstamp) >= timeo) {
- nfsstats.attrcache_misses++;
- return (ENOENT);
- }
- nfsstats.attrcache_hits++;
- if (vap->va_size != np->n_size) {
- if (vap->va_type == VREG) {
- if (np->n_flag & NMODIFIED) {
- if (vap->va_size < np->n_size)
- vap->va_size = np->n_size;
- else
- np->n_size = vap->va_size;
- } else {
- np->n_size = vap->va_size;
- }
- vnode_pager_setsize(vp, np->n_size);
- } else {
- np->n_size = vap->va_size;
- }
- }
- bcopy((caddr_t)vap, (caddr_t)vaper, sizeof(struct vattr));
- if (np->n_flag & NCHG) {
- if (np->n_flag & NACC)
- vaper->va_atime = np->n_atim;
- if (np->n_flag & NUPD)
- vaper->va_mtime = np->n_mtim;
- }
- return (0);
-}
-
-#ifndef NFS_NOSERVER
-/*
* Set up nameidata for a lookup() call and do it.
*
* If pubflag is set, this call is done for a lookup operation on the
@@ -1460,25 +578,17 @@ nfs_getattrcache(vp, vaper)
* This is mainly ni_vp and ni_dvp when an error occurs, and ni_dvp when no
* error occurs but the parent was not requested.
*
- * dirp may be set whether an error is returned or not, and must be
+ * dirp may be set whether an error is returned or not, and must be
* released by the caller.
*/
int
-nfs_namei(ndp, fhp, len, slp, nam, mdp, dposp, retdirp, td, kerbflag, pubflag)
- register struct nameidata *ndp;
- fhandle_t *fhp;
- int len;
- struct nfssvc_sock *slp;
- struct sockaddr *nam;
- struct mbuf **mdp;
- caddr_t *dposp;
- struct vnode **retdirp;
- struct thread *td;
- int kerbflag, pubflag;
+nfs_namei(struct nameidata *ndp, fhandle_t *fhp, int len,
+ struct nfssvc_sock *slp, struct sockaddr *nam, struct mbuf **mdp,
+ caddr_t *dposp, struct vnode **retdirp, struct thread *td, int pubflag)
{
- register int i, rem;
- register struct mbuf *md;
- register char *fromcp, *tocp, *cp;
+ int i, rem;
+ struct mbuf *md;
+ char *fromcp, *tocp, *cp;
struct iovec aiov;
struct uio auio;
struct vnode *dp;
@@ -1528,7 +638,7 @@ nfs_namei(ndp, fhp, len, slp, nam, mdp, dposp, retdirp, td, kerbflag, pubflag)
* Extract and set starting directory.
*/
error = nfsrv_fhtovp(fhp, FALSE, &dp, ndp->ni_cnd.cn_cred, slp,
- nam, &rdonly, kerbflag, pubflag);
+ nam, &rdonly, pubflag);
if (error)
goto out;
if (dp->v_type != VDIR) {
@@ -1541,7 +651,7 @@ nfs_namei(ndp, fhp, len, slp, nam, mdp, dposp, retdirp, td, kerbflag, pubflag)
cnp->cn_flags |= RDONLY;
/*
- * Set return directory. Reference to dp is implicitly transfered
+ * Set return directory. Reference to dp is implicitly transfered
* to the returned pointer
*/
*retdirp = dp;
@@ -1631,7 +741,7 @@ nfs_namei(ndp, fhp, len, slp, nam, mdp, dposp, retdirp, td, kerbflag, pubflag)
break;
/*
- * Check for encountering a symbolic link. Trivial
+ * Check for encountering a symbolic link. Trivial
* termination occurs if no symlink encountered.
* Note: zfree is safe because error is 0, so we will
* not zfree it again when we break.
@@ -1704,8 +814,8 @@ nfs_namei(ndp, fhp, len, slp, nam, mdp, dposp, retdirp, td, kerbflag, pubflag)
ndp->ni_pathlen += linklen;
/*
- * Cleanup refs for next loop and check if root directory
- * should replace current directory. Normally ni_dvp
+ * Cleanup refs for next loop and check if root directory
+ * should replace current directory. Normally ni_dvp
* becomes the new base directory and is cleaned up when
* we loop. Explicitly null pointers after invalidation
* to clarify operation.
@@ -1745,14 +855,11 @@ out:
* boundary and only trims off the back end
*/
void
-nfsm_adj(mp, len, nul)
- struct mbuf *mp;
- register int len;
- int nul;
+nfsm_adj(struct mbuf *mp, int len, int nul)
{
- register struct mbuf *m;
- register int count, i;
- register char *cp;
+ struct mbuf *m;
+ int count, i;
+ char *cp;
/*
* Trim from tail. Scan the mbuf chain,
@@ -1807,18 +914,13 @@ nfsm_adj(mp, len, nul)
* doesn't get too big...
*/
void
-nfsm_srvwcc(nfsd, before_ret, before_vap, after_ret, after_vap, mbp, bposp)
- struct nfsrv_descript *nfsd;
- int before_ret;
- register struct vattr *before_vap;
- int after_ret;
- struct vattr *after_vap;
- struct mbuf **mbp;
- char **bposp;
+nfsm_srvwcc(struct nfsrv_descript *nfsd, int before_ret,
+ struct vattr *before_vap, int after_ret, struct vattr *after_vap,
+ struct mbuf **mbp, char **bposp)
{
- register struct mbuf *mb = *mbp, *mb2;
- register char *bpos = *bposp;
- register u_int32_t *tl;
+ struct mbuf *mb = *mbp;
+ char *bpos = *bposp;
+ u_int32_t *tl;
if (before_ret) {
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
@@ -1838,17 +940,13 @@ nfsm_srvwcc(nfsd, before_ret, before_vap, after_ret, after_vap, mbp, bposp)
}
void
-nfsm_srvpostopattr(nfsd, after_ret, after_vap, mbp, bposp)
- struct nfsrv_descript *nfsd;
- int after_ret;
- struct vattr *after_vap;
- struct mbuf **mbp;
- char **bposp;
+nfsm_srvpostopattr(struct nfsrv_descript *nfsd, int after_ret,
+ struct vattr *after_vap, struct mbuf **mbp, char **bposp)
{
- register struct mbuf *mb = *mbp, *mb2;
- register char *bpos = *bposp;
- register u_int32_t *tl;
- register struct nfs_fattr *fp;
+ struct mbuf *mb = *mbp;
+ char *bpos = *bposp;
+ u_int32_t *tl;
+ struct nfs_fattr *fp;
if (after_ret) {
nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED);
@@ -1864,10 +962,8 @@ nfsm_srvpostopattr(nfsd, after_ret, after_vap, mbp, bposp)
}
void
-nfsm_srvfattr(nfsd, vap, fp)
- register struct nfsrv_descript *nfsd;
- register struct vattr *vap;
- register struct nfs_fattr *fp;
+nfsm_srvfattr(struct nfsrv_descript *nfsd, struct vattr *vap,
+ struct nfs_fattr *fp)
{
fp->fa_nlink = txdr_unsigned(vap->va_nlink);
@@ -1913,20 +1009,13 @@ nfsm_srvfattr(nfsd, vap, fp)
* - if not lockflag unlock it with VOP_UNLOCK()
*/
int
-nfsrv_fhtovp(fhp, lockflag, vpp, cred, slp, nam, rdonlyp, kerbflag, pubflag)
- fhandle_t *fhp;
- int lockflag;
- struct vnode **vpp;
- struct ucred *cred;
- struct nfssvc_sock *slp;
- struct sockaddr *nam;
- int *rdonlyp;
- int kerbflag;
- int pubflag;
+nfsrv_fhtovp(fhandle_t *fhp, int lockflag, struct vnode **vpp,
+ struct ucred *cred, struct nfssvc_sock *slp, struct sockaddr *nam,
+ int *rdonlyp, int pubflag)
{
struct thread *td = curthread; /* XXX */
- register struct mount *mp;
- register int i;
+ struct mount *mp;
+ int i;
struct ucred *credanon;
int error, exflags;
#ifdef MNT_EXNORESPORT /* XXX needs mountd and /etc/exports help yet */
@@ -1946,7 +1035,7 @@ nfsrv_fhtovp(fhp, lockflag, vpp, cred, slp, nam, rdonlyp, kerbflag, pubflag)
return (ESTALE);
error = VFS_CHECKEXP(mp, nam, &exflags, &credanon);
if (error)
- return (error);
+ return (error);
error = VFS_FHTOVP(mp, &fhp->fh_fid, vpp);
if (error)
return (error);
@@ -1964,17 +1053,7 @@ nfsrv_fhtovp(fhp, lockflag, vpp, cred, slp, nam, rdonlyp, kerbflag, pubflag)
/*
* Check/setup credentials.
*/
- if (exflags & MNT_EXKERB) {
- if (!kerbflag) {
- vput(*vpp);
- *vpp = NULL;
- return (NFSERR_AUTHERR | AUTH_TOOWEAK);
- }
- } else if (kerbflag) {
- vput(*vpp);
- *vpp = NULL;
- return (NFSERR_AUTHERR | AUTH_TOOWEAK);
- } else if (cred->cr_uid == 0 || (exflags & MNT_EXPORTANON)) {
+ if (cred->cr_uid == 0 || (exflags & MNT_EXPORTANON)) {
cred->cr_uid = credanon->cr_uid;
for (i = 0; i < credanon->cr_ngroups && i < NGROUPS; i++)
cred->cr_groups[i] = credanon->cr_groups[i];
@@ -1999,8 +1078,7 @@ nfsrv_fhtovp(fhp, lockflag, vpp, cred, slp, nam, rdonlyp, kerbflag, pubflag)
* transformed this to all zeroes in both cases, so check for it.
*/
int
-nfs_ispublicfh(fhp)
- fhandle_t *fhp;
+nfs_ispublicfh(fhandle_t *fhp)
{
char *cp = (char *)fhp;
int i;
@@ -2010,8 +1088,7 @@ nfs_ispublicfh(fhp)
return (FALSE);
return (TRUE);
}
-
-#endif /* NFS_NOSERVER */
+
/*
* This function compares two net addresses by family and returns TRUE
* if they are the same host.
@@ -2020,12 +1097,9 @@ nfs_ispublicfh(fhp)
* don't need to be saved to store "struct in_addr", which is only 4 bytes.
*/
int
-netaddr_match(family, haddr, nam)
- int family;
- union nethostaddr *haddr;
- struct sockaddr *nam;
+netaddr_match(int family, union nethostaddr *haddr, struct sockaddr *nam)
{
- register struct sockaddr_in *inetaddr;
+ struct sockaddr_in *inetaddr;
switch (family) {
case AF_INET:
@@ -2040,136 +1114,14 @@ netaddr_match(family, haddr, nam)
return (0);
}
-static nfsuint64 nfs_nullcookie = { { 0, 0 } };
-/*
- * This function finds the directory cookie that corresponds to the
- * logical byte offset given.
- */
-nfsuint64 *
-nfs_getcookie(np, off, add)
- register struct nfsnode *np;
- off_t off;
- int add;
-{
- register struct nfsdmap *dp, *dp2;
- register int pos;
-
- pos = (uoff_t)off / NFS_DIRBLKSIZ;
- if (pos == 0 || off < 0) {
-#ifdef DIAGNOSTIC
- if (add)
- panic("nfs getcookie add at <= 0");
-#endif
- return (&nfs_nullcookie);
- }
- pos--;
- dp = np->n_cookies.lh_first;
- if (!dp) {
- if (add) {
- MALLOC(dp, struct nfsdmap *, sizeof (struct nfsdmap),
- M_NFSDIROFF, M_WAITOK);
- dp->ndm_eocookie = 0;
- LIST_INSERT_HEAD(&np->n_cookies, dp, ndm_list);
- } else
- return ((nfsuint64 *)0);
- }
- while (pos >= NFSNUMCOOKIES) {
- pos -= NFSNUMCOOKIES;
- if (dp->ndm_list.le_next) {
- if (!add && dp->ndm_eocookie < NFSNUMCOOKIES &&
- pos >= dp->ndm_eocookie)
- return ((nfsuint64 *)0);
- dp = dp->ndm_list.le_next;
- } else if (add) {
- MALLOC(dp2, struct nfsdmap *, sizeof (struct nfsdmap),
- M_NFSDIROFF, M_WAITOK);
- dp2->ndm_eocookie = 0;
- LIST_INSERT_AFTER(dp, dp2, ndm_list);
- dp = dp2;
- } else
- return ((nfsuint64 *)0);
- }
- if (pos >= dp->ndm_eocookie) {
- if (add)
- dp->ndm_eocookie = pos + 1;
- else
- return ((nfsuint64 *)0);
- }
- return (&dp->ndm_cookies[pos]);
-}
-
-/*
- * Invalidate cached directory information, except for the actual directory
- * blocks (which are invalidated separately).
- * Done mainly to avoid the use of stale offset cookies.
- */
-void
-nfs_invaldir(vp)
- register struct vnode *vp;
-{
- register struct nfsnode *np = VTONFS(vp);
-
-#ifdef DIAGNOSTIC
- if (vp->v_type != VDIR)
- panic("nfs: invaldir not dir");
-#endif
- np->n_direofoffset = 0;
- np->n_cookieverf.nfsuquad[0] = 0;
- np->n_cookieverf.nfsuquad[1] = 0;
- if (np->n_cookies.lh_first)
- np->n_cookies.lh_first->ndm_eocookie = 0;
-}
-
-/*
- * The write verifier has changed (probably due to a server reboot), so all
- * B_NEEDCOMMIT blocks will have to be written again. Since they are on the
- * dirty block list as B_DELWRI, all this takes is clearing the B_NEEDCOMMIT
- * and B_CLUSTEROK flags. Once done the new write verifier can be set for the
- * mount point.
- *
- * B_CLUSTEROK must be cleared along with B_NEEDCOMMIT because stage 1 data
- * writes are not clusterable.
- */
-void
-nfs_clearcommit(mp)
- struct mount *mp;
-{
- register struct vnode *vp, *nvp;
- register struct buf *bp, *nbp;
- int s;
-
- GIANT_REQUIRED;
-
- s = splbio();
- mtx_lock(&mntvnode_mtx);
-loop:
- for (vp = LIST_FIRST(&mp->mnt_vnodelist); vp; vp = nvp) {
- if (vp->v_mount != mp) /* Paranoia */
- goto loop;
- nvp = LIST_NEXT(vp, v_mntvnodes);
- for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
- nbp = TAILQ_NEXT(bp, b_vnbufs);
- if (BUF_REFCNT(bp) == 0 &&
- (bp->b_flags & (B_DELWRI | B_NEEDCOMMIT))
- == (B_DELWRI | B_NEEDCOMMIT))
- bp->b_flags &= ~(B_NEEDCOMMIT | B_CLUSTEROK);
- }
- }
- mtx_unlock(&mntvnode_mtx);
- splx(s);
-}
-
-#ifndef NFS_NOSERVER
/*
* Map errnos to NFS error numbers. For Version 3 also filter out error
* numbers not specified for the associated procedure.
*/
int
-nfsrv_errmap(nd, err)
- struct nfsrv_descript *nd;
- register int err;
+nfsrv_errmap(struct nfsrv_descript *nd, int err)
{
- register short *defaulterrp, *errp;
+ short *defaulterrp, *errp;
if (nd->nd_flag & ND_NFSV3) {
if (nd->nd_procnum <= NFSPROC_COMMIT) {
@@ -2190,8 +1142,7 @@ nfsrv_errmap(nd, err)
}
int
-nfsrv_object_create(vp)
- struct vnode *vp;
+nfsrv_object_create(struct vnode *vp)
{
if (vp == NULL || vp->v_type != VREG)
@@ -2206,11 +1157,9 @@ nfsrv_object_create(vp)
* that used to be here.)
*/
void
-nfsrvw_sort(list, num)
- register gid_t *list;
- register int num;
+nfsrvw_sort(gid_t *list, int num)
{
- register int i, j;
+ int i, j;
gid_t v;
/* Insertion sort. */
@@ -2227,10 +1176,9 @@ nfsrvw_sort(list, num)
* copy credentials making sure that the result can be compared with bcmp().
*/
void
-nfsrv_setcred(incred, outcred)
- register struct ucred *incred, *outcred;
+nfsrv_setcred(struct ucred *incred, struct ucred *outcred)
{
- register int i;
+ int i;
bzero((caddr_t)outcred, sizeof (struct ucred));
outcred->cr_ref = 1;
@@ -2240,4 +1188,207 @@ nfsrv_setcred(incred, outcred)
outcred->cr_groups[i] = incred->cr_groups[i];
nfsrvw_sort(outcred->cr_groups, outcred->cr_ngroups);
}
-#endif /* NFS_NOSERVER */
+
+/*
+ * Helper functions for macros.
+ */
+
+void
+nfsm_srvfhtom_xx(fhandle_t *f, int v3,
+ u_int32_t **tl, struct mbuf **mb, caddr_t *bpos)
+{
+ u_int32_t *cp;
+
+ if (v3) {
+ nfsm_build_xx((void **)tl, NFSX_UNSIGNED + NFSX_V3FH, mb,
+ bpos);
+ *(*tl)++ = txdr_unsigned(NFSX_V3FH);
+ bcopy(f, (*tl), NFSX_V3FH);
+ } else {
+ nfsm_build_xx((void **)&cp, NFSX_V2FH, mb, bpos);
+ bcopy(f, cp, NFSX_V2FH);
+ }
+}
+
+void
+nfsm_srvpostop_fh_xx(fhandle_t *f,
+ u_int32_t **tl, struct mbuf **mb, caddr_t *bpos)
+{
+ nfsm_build_xx((void **)tl, 2 * NFSX_UNSIGNED + NFSX_V3FH, mb, bpos);
+ *(*tl)++ = nfs_true;
+ *(*tl)++ = txdr_unsigned(NFSX_V3FH);
+ bcopy(f, (*tl), NFSX_V3FH);
+}
+
+int
+nfsm_srvstrsiz_xx(int *s, int m,
+ u_int32_t **tl, struct mbuf **md, caddr_t *dpos)
+{
+ int ret;
+
+ ret = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
+ if (ret)
+ return ret;
+ *s = fxdr_unsigned(int32_t, **tl);
+ if (*s > m || *s <= 0)
+ return EBADRPC;
+ return 0;
+}
+
+int
+nfsm_srvnamesiz_xx(int *s,
+ u_int32_t **tl, struct mbuf **md, caddr_t *dpos)
+{
+ int ret;
+
+ ret = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
+ if (ret)
+ return ret;
+ *s = fxdr_unsigned(int32_t, **tl);
+ if (*s > NFS_MAXNAMLEN)
+ return NFSERR_NAMETOL;
+ if (*s <= 0)
+ return EBADRPC;
+ return 0;
+}
+
+void
+nfsm_clget_xx(u_int32_t **tl, struct mbuf *mb, struct mbuf **mp,
+ char **bp, char **be, caddr_t bpos)
+{
+ struct mbuf *nmp;
+
+ if (*bp >= *be) {
+ if (*mp == mb)
+ (*mp)->m_len += *bp - bpos;
+ MGET(nmp, M_TRYWAIT, MT_DATA);
+ MCLGET(nmp, M_TRYWAIT);
+ nmp->m_len = NFSMSIZ(nmp);
+ (*mp)->m_next = nmp;
+ *mp = nmp;
+ *bp = mtod(*mp, caddr_t);
+ *be = *bp + (*mp)->m_len;
+ }
+ *tl = (u_int32_t *)*bp;
+}
+
+int
+nfsm_srvmtofh_xx(fhandle_t *f, struct nfsrv_descript *nfsd,
+ u_int32_t **tl, struct mbuf **md, caddr_t *dpos)
+{
+ int error;
+ int fhlen;
+
+ if (nfsd->nd_flag & ND_NFSV3) {
+ error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
+ if (error)
+ return error;
+ fhlen = fxdr_unsigned(int, **tl);
+ if (fhlen != 0 && fhlen != NFSX_V3FH)
+ return EBADRPC;
+ } else {
+ fhlen = NFSX_V2FH;
+ }
+ if (fhlen != 0) {
+ error = nfsm_dissect_xx((void **)tl, fhlen, md, dpos);
+ if (error)
+ return error;
+ bcopy((caddr_t)*tl, (caddr_t)(f), fhlen);
+ } else {
+ bzero((caddr_t)(f), NFSX_V3FH);
+ }
+ return 0;
+}
+
+int
+nfsm_srvsattr_xx(struct vattr *a,
+ u_int32_t **tl, struct mbuf **md, caddr_t *dpos)
+{
+ int error = 0;
+
+ error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
+ if (error)
+ goto bugout;
+ if (**tl == nfs_true) {
+ error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
+ if (error)
+ goto bugout;
+ (a)->va_mode = nfstov_mode(**tl);
+ }
+ error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
+ if (error)
+ goto bugout;
+ if (**tl == nfs_true) {
+ error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
+ if (error)
+ goto bugout;
+ (a)->va_uid = fxdr_unsigned(uid_t, **tl);
+ }
+ error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
+ if (error)
+ goto bugout;
+ if (**tl == nfs_true) {
+ error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
+ if (error)
+ goto bugout;
+ (a)->va_gid = fxdr_unsigned(gid_t, **tl);
+ }
+ error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
+ if (error)
+ goto bugout;
+ if (**tl == nfs_true) {
+ error = nfsm_dissect_xx((void **)tl, 2 * NFSX_UNSIGNED,
+ md, dpos);
+ if (error)
+ goto bugout;
+ (a)->va_size = fxdr_hyper(*tl);
+ }
+ error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
+ if (error)
+ goto bugout;
+ switch (fxdr_unsigned(int, **tl)) {
+ case NFSV3SATTRTIME_TOCLIENT:
+ error = nfsm_dissect_xx((void **)tl, 2 * NFSX_UNSIGNED,
+ md, dpos);
+ if (error)
+ goto bugout;
+ fxdr_nfsv3time(*tl, &(a)->va_atime);
+ break;
+ case NFSV3SATTRTIME_TOSERVER:
+ getnanotime(&(a)->va_atime);
+ break;
+ }
+ error = nfsm_dissect_xx((void **)tl, NFSX_UNSIGNED, md, dpos);
+ if (error)
+ goto bugout;
+ switch (fxdr_unsigned(int, **tl)) {
+ case NFSV3SATTRTIME_TOCLIENT:
+ error = nfsm_dissect_xx((void **)tl, 2 * NFSX_UNSIGNED,
+ md, dpos);
+ if (error)
+ goto bugout;
+ fxdr_nfsv3time(*tl, &(a)->va_mtime);
+ break;
+ case NFSV3SATTRTIME_TOSERVER:
+ getnanotime(&(a)->va_mtime);
+ break;
+ }
+ return 0;
+
+bugout:
+ return error;
+}
+
+void
+nfs_rephead_xx(int s, struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
+ int error, struct mbuf **mrq, struct mbuf **mb,
+ struct mbuf **mreq, struct mbuf **mrep, caddr_t *bpos)
+{
+
+ nfs_rephead(s, nfsd, slp, error, mrq, mb, bpos);
+ if (*mrep != NULL) {
+ m_freem(*mrep);
+ *mrep = NULL;
+ }
+ *mreq = *mrq;
+}
diff --git a/sys/nfsserver/nfs_syscalls.c b/sys/nfsserver/nfs_syscalls.c
index 657f299..be8fc69 100644
--- a/sys/nfsserver/nfs_syscalls.c
+++ b/sys/nfsserver/nfs_syscalls.c
@@ -37,6 +37,9 @@
* $FreeBSD$
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/sysproto.h>
@@ -64,66 +67,45 @@
#include <nfs/xdr_subs.h>
#include <nfs/rpcv2.h>
#include <nfs/nfsproto.h>
-#include <nfs/nfs.h>
-#include <nfs/nfsm_subs.h>
-#include <nfs/nfsrvcache.h>
-#include <nfs/nfsmount.h>
-#include <nfs/nfsnode.h>
-#include <nfs/nqnfs.h>
-#include <nfs/nfsrtt.h>
-#include <nfs/nfs_lock.h>
+#include <nfsserver/nfs.h>
+#include <nfsserver/nfsm_subs.h>
+#include <nfsserver/nfsrvcache.h>
static MALLOC_DEFINE(M_NFSSVC, "NFS srvsock", "Nfs server structure");
-/* Global defs. */
-extern int32_t (*nfsrv3_procs[NFS_NPROCS]) __P((struct nfsrv_descript *nd,
- struct nfssvc_sock *slp,
- struct thread *td,
- struct mbuf **mreqp));
-extern int nfs_numasync;
-extern time_t nqnfsstarttime;
-extern int nqsrv_writeslack;
-extern int nfsrtton;
-extern struct nfsstats nfsstats;
-extern int nfsrvw_procrastinate;
-extern int nfsrvw_procrastinate_v3;
-static int nuidhash_max = NFS_MAXUIDHASH;
+MALLOC_DEFINE(M_NFSRVDESC, "NFSV3 srvdesc", "NFS server socket descriptor");
+MALLOC_DEFINE(M_NFSD, "NFS daemon", "Nfs server daemon structure");
-#ifndef NFS_NOSERVER
-static void nfsrv_zapsock __P((struct nfssvc_sock *slp));
-#endif
-static int nfssvc_iod __P((struct thread *));
+
+/* Global defs. */
+struct nfsrvstats nfsrvstats;
#define TRUE 1
#define FALSE 0
-static int nfs_asyncdaemon[NFS_MAXASYNCDAEMON];
+SYSCTL_DECL(_vfs_nfsrv);
-SYSCTL_DECL(_vfs_nfs);
+int nfsd_waiting = 0;
+static int nfs_numnfsd = 0;
+static int notstarted = 1;
-#ifndef NFS_NOSERVER
-int nfsd_waiting = 0;
-static struct nfsdrt nfsdrt;
-static int nfs_numnfsd = 0;
-static int notstarted = 1;
-static int modify_flag = 0;
-static void nfsd_rt __P((int sotype, struct nfsrv_descript *nd,
- int cacherep));
-static int nfssvc_addsock __P((struct file *, struct sockaddr *,
- struct thread *));
-static int nfssvc_nfsd __P((struct nfsd_srvargs *,caddr_t,
- struct thread *));
+static int nfs_privport = 0;
+SYSCTL_INT(_vfs_nfsrv, NFS_NFSPRIVPORT, nfs_privport, CTLFLAG_RW,
+ &nfs_privport, 0, "");
+SYSCTL_INT(_vfs_nfsrv, OID_AUTO, gatherdelay, CTLFLAG_RW,
+ &nfsrvw_procrastinate, 0, "");
+SYSCTL_INT(_vfs_nfsrv, OID_AUTO, gatherdelay_v3, CTLFLAG_RW,
+ &nfsrvw_procrastinate_v3, 0, "");
-static int nfs_privport = 0;
-SYSCTL_INT(_vfs_nfs, NFS_NFSPRIVPORT, nfs_privport, CTLFLAG_RW, &nfs_privport, 0, "");
-SYSCTL_INT(_vfs_nfs, OID_AUTO, gatherdelay, CTLFLAG_RW, &nfsrvw_procrastinate, 0, "");
-SYSCTL_INT(_vfs_nfs, OID_AUTO, gatherdelay_v3, CTLFLAG_RW, &nfsrvw_procrastinate_v3, 0, "");
+static int nfssvc_addsock(struct file *, struct sockaddr *,
+ struct thread *);
+static void nfsrv_zapsock(struct nfssvc_sock *slp);
+static int nfssvc_nfsd(struct nfsd_srvargs *, caddr_t, struct thread *);
/*
* NFS server system calls
*/
-#endif /* NFS_NOSERVER */
/*
* Nfs server psuedo system call for the nfsd's
* Based on the flag value it either:
@@ -141,37 +123,15 @@ struct nfssvc_args {
* MPSAFE
*/
int
-nfssvc(td, uap)
- struct thread *td;
- register struct nfssvc_args *uap;
+nfssvc(struct thread *td, struct nfssvc_args *uap)
{
-#ifndef NFS_NOSERVER
- struct nameidata nd;
struct file *fp;
struct sockaddr *nam;
struct nfsd_args nfsdarg;
struct nfsd_srvargs nfsd_srvargs, *nsd = &nfsd_srvargs;
- struct nfsd_cargs ncd;
- struct nfsd *nfsd;
- struct nfssvc_sock *slp;
- struct nfsuid *nuidp;
- struct nfsmount *nmp;
-#endif /* NFS_NOSERVER */
int error;
mtx_lock(&Giant);
-
- if ((uap->flag & NFSSVC_LOCKDANS) != 0) {
- struct lockd_ans la;
-
- error = copyin(uap->argp, &la, sizeof(la));
- if (error == 0)
- error = nfslockdans(td->td_proc, &la);
- goto done2;
- }
- /*
- * Must be super user
- */
error = suser_td(td);
if (error)
goto done2;
@@ -179,37 +139,7 @@ nfssvc(td, uap)
nfssvc_sockhead_flag |= SLP_WANTINIT;
(void) tsleep((caddr_t)&nfssvc_sockhead, PSOCK, "nfsd init", 0);
}
- if (uap->flag & NFSSVC_BIOD)
- error = nfssvc_iod(td);
-#ifdef NFS_NOSERVER
- else
- error = ENXIO;
-#else /* !NFS_NOSERVER */
- else if (uap->flag & NFSSVC_MNTD) {
- error = copyin(uap->argp, (caddr_t)&ncd, sizeof (ncd));
- if (error)
- goto done2;
- NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE,
- ncd.ncd_dirp, td);
- error = namei(&nd);
- if (error)
- goto done2;
- NDFREE(&nd, NDF_ONLY_PNBUF);
- if ((nd.ni_vp->v_flag & VROOT) == 0)
- error = EINVAL;
- nmp = VFSTONFS(nd.ni_vp->v_mount);
- vput(nd.ni_vp);
- if (error)
- goto done2;
- if ((nmp->nm_state & NFSSTA_MNTD) &&
- (uap->flag & NFSSVC_GOTAUTH) == 0) {
- error = 0;
- goto done2;
- }
- nmp->nm_state |= NFSSTA_MNTD;
- error = nqnfs_clientd(nmp, td->td_proc->p_ucred, &ncd, uap->flag,
- uap->argp, td);
- } else if (uap->flag & NFSSVC_ADDSOCK) {
+ if (uap->flag & NFSSVC_ADDSOCK) {
error = copyin(uap->argp, (caddr_t)&nfsdarg, sizeof(nfsdarg));
if (error)
goto done2;
@@ -231,106 +161,14 @@ nfssvc(td, uap)
}
error = nfssvc_addsock(fp, nam, td);
fdrop(fp, td);
- } else {
+ } else if (uap->flag & NFSSVC_NFSD) {
error = copyin(uap->argp, (caddr_t)nsd, sizeof (*nsd));
if (error)
- goto done2;
- if ((uap->flag & NFSSVC_AUTHIN) &&
- ((nfsd = nsd->nsd_nfsd)) != NULL &&
- (nfsd->nfsd_slp->ns_flag & SLP_VALID)) {
- slp = nfsd->nfsd_slp;
-
- /*
- * First check to see if another nfsd has already
- * added this credential.
- */
- for (nuidp = NUIDHASH(slp,nsd->nsd_cr.cr_uid)->lh_first;
- nuidp != 0; nuidp = nuidp->nu_hash.le_next) {
- if (nuidp->nu_cr.cr_uid == nsd->nsd_cr.cr_uid &&
- (!nfsd->nfsd_nd->nd_nam2 ||
- netaddr_match(NU_NETFAM(nuidp),
- &nuidp->nu_haddr, nfsd->nfsd_nd->nd_nam2)))
- break;
- }
- if (nuidp) {
- nfsrv_setcred(&nuidp->nu_cr,&nfsd->nfsd_nd->nd_cr);
- nfsd->nfsd_nd->nd_flag |= ND_KERBFULL;
- } else {
- /*
- * Nope, so we will.
- */
- if (slp->ns_numuids < nuidhash_max) {
- slp->ns_numuids++;
- nuidp = (struct nfsuid *)
- malloc(sizeof (struct nfsuid), M_NFSUID,
- M_WAITOK);
- } else
- nuidp = (struct nfsuid *)0;
- if ((slp->ns_flag & SLP_VALID) == 0) {
- if (nuidp)
- free((caddr_t)nuidp, M_NFSUID);
- } else {
- if (nuidp == (struct nfsuid *)0) {
- nuidp = slp->ns_uidlruhead.tqh_first;
- LIST_REMOVE(nuidp, nu_hash);
- TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp,
- nu_lru);
- if (nuidp->nu_flag & NU_NAM)
- FREE(nuidp->nu_nam, M_SONAME);
- }
- nuidp->nu_flag = 0;
- bzero(&nuidp->nu_cr, sizeof(nuidp->nu_cr));
- nuidp->nu_cr.cr_uid = nsd->nsd_cr.cr_uid;
- nuidp->nu_cr.cr_ngroups =
- nsd->nsd_cr.cr_ngroups;
- bcopy(nsd->nsd_cr.cr_groups,
- nuidp->nu_cr.cr_groups,
- sizeof(nuidp->nu_cr.cr_groups));
- if (nuidp->nu_cr.cr_ngroups > NGROUPS)
- nuidp->nu_cr.cr_ngroups = NGROUPS;
- nuidp->nu_cr.cr_ref = 1;
- nuidp->nu_timestamp = nsd->nsd_timestamp;
- nuidp->nu_expire = time_second + nsd->nsd_ttl;
- /*
- * and save the session key in nu_key.
- */
- bcopy(nsd->nsd_key, nuidp->nu_key,
- sizeof (nsd->nsd_key));
- if (nfsd->nfsd_nd->nd_nam2) {
- struct sockaddr_in *saddr;
-
- saddr = (struct sockaddr_in *)
- nfsd->nfsd_nd->nd_nam2;
- switch (saddr->sin_family) {
- case AF_INET:
- nuidp->nu_flag |= NU_INETADDR;
- nuidp->nu_inetaddr =
- saddr->sin_addr.s_addr;
- break;
- case AF_ISO:
- default:
- nuidp->nu_flag |= NU_NAM;
- nuidp->nu_nam =
- dup_sockaddr(nfsd->nfsd_nd->
- nd_nam2, 1);
- break;
- };
- }
- TAILQ_INSERT_TAIL(&slp->ns_uidlruhead, nuidp,
- nu_lru);
- LIST_INSERT_HEAD(NUIDHASH(slp, nsd->nsd_uid),
- nuidp, nu_hash);
- nfsrv_setcred(&nuidp->nu_cr,
- &nfsd->nfsd_nd->nd_cr);
- nfsd->nfsd_nd->nd_flag |= ND_KERBFULL;
- }
- }
- }
- if ((uap->flag & NFSSVC_AUTHINFAIL) && (nfsd = nsd->nsd_nfsd))
- nfsd->nfsd_flag |= NFSD_AUTHFAIL;
+ return (error);
error = nfssvc_nfsd(nsd, uap->argp, td);
+ } else {
+ error = ENXIO;
}
-#endif /* NFS_NOSERVER */
if (error == EINTR || error == ERESTART)
error = 0;
done2:
@@ -338,19 +176,15 @@ done2:
return (error);
}
-#ifndef NFS_NOSERVER
/*
* Adds a socket to the list for servicing by nfsds.
*/
static int
-nfssvc_addsock(fp, mynam, td)
- struct file *fp;
- struct sockaddr *mynam;
- struct thread *td;
+nfssvc_addsock(struct file *fp, struct sockaddr *mynam, struct thread *td)
{
- register int siz;
- register struct nfssvc_sock *slp;
- register struct socket *so;
+ int siz;
+ struct nfssvc_sock *slp;
+ struct socket *so;
int error, s;
so = (struct socket *)fp->f_data;
@@ -418,7 +252,6 @@ nfssvc_addsock(fp, mynam, td)
malloc(sizeof (struct nfssvc_sock), M_NFSSVC,
M_WAITOK | M_ZERO);
STAILQ_INIT(&slp->ns_rec);
- TAILQ_INIT(&slp->ns_uidlruhead);
TAILQ_INSERT_TAIL(&nfssvc_sockhead, slp, ns_chain);
slp->ns_so = so;
@@ -440,13 +273,10 @@ nfssvc_addsock(fp, mynam, td)
* until it is killed by a signal.
*/
static int
-nfssvc_nfsd(nsd, argp, td)
- struct nfsd_srvargs *nsd;
- caddr_t argp;
- struct thread *td;
+nfssvc_nfsd(struct nfsd_srvargs *nsd, caddr_t argp, struct thread *td)
{
- register int siz;
- register struct nfssvc_sock *slp;
+ int siz;
+ struct nfssvc_sock *slp;
struct nfsd *nfsd = nsd->nsd_nfsd;
struct nfsrv_descript *nd = NULL;
struct mbuf *m, *mreq;
@@ -485,8 +315,7 @@ nfssvc_nfsd(nsd, argp, td)
}
if (nfsd->nfsd_slp == (struct nfssvc_sock *)0 &&
(nfsd_head_flag & NFSD_CHECKSLP) != 0) {
- for (slp = nfssvc_sockhead.tqh_first; slp != 0;
- slp = slp->ns_chain.tqe_next) {
+ TAILQ_FOREACH(slp, &nfssvc_sockhead, ns_chain) {
if ((slp->ns_flag & (SLP_VALID | SLP_DOREC))
== (SLP_VALID | SLP_DOREC)) {
slp->ns_flag &= ~SLP_DOREC;
@@ -512,8 +341,8 @@ nfssvc_nfsd(nsd, argp, td)
}
error = nfsrv_dorec(slp, nfsd, &nd);
cur_usec = nfs_curusec();
- if (error && slp->ns_tq.lh_first &&
- slp->ns_tq.lh_first->nd_time <= cur_usec) {
+ if (error && LIST_FIRST(&slp->ns_tq) &&
+ LIST_FIRST(&slp->ns_tq)->nd_time <= cur_usec) {
error = 0;
cacherep = RC_DOIT;
writes_todo = 1;
@@ -547,49 +376,9 @@ nfssvc_nfsd(nsd, argp, td)
/*
* Check to see if authorization is needed.
*/
- if (nfsd->nfsd_flag & NFSD_NEEDAUTH) {
- nfsd->nfsd_flag &= ~NFSD_NEEDAUTH;
- nsd->nsd_haddr =
- ((struct sockaddr_in *)
- nd->nd_nam)->sin_addr.s_addr;
- nsd->nsd_authlen = nfsd->nfsd_authlen;
- nsd->nsd_verflen = nfsd->nfsd_verflen;
- if (!copyout(nfsd->nfsd_authstr,nsd->nsd_authstr,
- nfsd->nfsd_authlen) &&
- !copyout(nfsd->nfsd_verfstr, nsd->nsd_verfstr,
- nfsd->nfsd_verflen) &&
- !copyout((caddr_t)nsd, argp, sizeof (*nsd)))
- return (ENEEDAUTH);
- cacherep = RC_DROPIT;
- } else
- cacherep = nfsrv_getcache(nd, slp, &mreq);
+ cacherep = nfsrv_getcache(nd, slp, &mreq);
- /*
- * Check for just starting up for NQNFS and send
- * fake "try again later" replies to the NQNFS clients.
- */
- if (notstarted && nqnfsstarttime <= time_second) {
- if (modify_flag) {
- nqnfsstarttime = time_second + nqsrv_writeslack;
- modify_flag = 0;
- } else
- notstarted = 0;
- }
- if (notstarted) {
- if ((nd->nd_flag & ND_NQNFS) == 0)
- cacherep = RC_DROPIT;
- else if (nd->nd_procnum != NFSPROC_WRITE) {
- nd->nd_procnum = NFSPROC_NOOP;
- nd->nd_repstat = NQNFS_TRYLATER;
- cacherep = RC_DOIT;
- } else
- modify_flag = 1;
- } else if (nfsd->nfsd_flag & NFSD_AUTHFAIL) {
- nfsd->nfsd_flag &= ~NFSD_AUTHFAIL;
- nd->nd_procnum = NFSPROC_NOOP;
- nd->nd_repstat = (NFSERR_AUTHERR | AUTH_TOOWEAK);
- cacherep = RC_DOIT;
- } else if (nfs_privport) {
+ if (nfs_privport) {
/* Check if source port is privileged */
u_short port;
struct sockaddr *nam = nd->nd_nam;
@@ -597,7 +386,7 @@ nfssvc_nfsd(nsd, argp, td)
sin = (struct sockaddr_in *)nam;
port = ntohs(sin->sin_port);
- if (port >= IPPORT_RESERVED &&
+ if (port >= IPPORT_RESERVED &&
nd->nd_procnum != NFSPROC_NULL) {
nd->nd_procnum = NFSPROC_NOOP;
nd->nd_repstat = (NFSERR_AUTHERR | AUTH_TOOWEAK);
@@ -630,14 +419,13 @@ nfssvc_nfsd(nsd, argp, td)
if (mreq == NULL)
break;
if (error != 0 && error != NFSERR_RETVOID) {
- if (nd->nd_procnum != NQNFSPROC_VACATED)
- nfsstats.srv_errs++;
+ nfsrvstats.srv_errs++;
nfsrv_updatecache(nd, FALSE, mreq);
if (nd->nd_nam2)
FREE(nd->nd_nam2, M_SONAME);
break;
}
- nfsstats.srvrpccnt[nd->nd_procnum]++;
+ nfsrvstats.srvrpccnt[nd->nd_procnum]++;
nfsrv_updatecache(nd, TRUE, mreq);
nd->nd_mrep = (struct mbuf *)0;
case RC_REPLY:
@@ -665,13 +453,11 @@ nfssvc_nfsd(nsd, argp, td)
if (slp->ns_so->so_proto->pr_flags & PR_CONNREQUIRED)
(void) nfs_slplock(slp, 1);
if (slp->ns_flag & SLP_VALID)
- error = nfs_send(slp->ns_so, nd->nd_nam2, m, NULL);
+ error = nfsrv_send(slp->ns_so, nd->nd_nam2, m);
else {
error = EPIPE;
m_freem(m);
}
- if (nfsrtton)
- nfsd_rt(sotype, nd, cacherep);
if (nd->nd_nam2)
FREE(nd->nd_nam2, M_SONAME);
if (nd->nd_mrep)
@@ -688,8 +474,6 @@ nfssvc_nfsd(nsd, argp, td)
}
break;
case RC_DROPIT:
- if (nfsrtton)
- nfsd_rt(sotype, nd, cacherep);
m_freem(nd->nd_mrep);
if (nd->nd_nam2)
FREE(nd->nd_nam2, M_SONAME);
@@ -706,8 +490,8 @@ nfssvc_nfsd(nsd, argp, td)
*/
cur_usec = nfs_curusec();
s = splsoftclock();
- if (slp->ns_tq.lh_first &&
- slp->ns_tq.lh_first->nd_time <= cur_usec) {
+ if (LIST_FIRST(&slp->ns_tq) &&
+ LIST_FIRST(&slp->ns_tq)->nd_time <= cur_usec) {
cacherep = RC_DOIT;
writes_todo = 1;
} else
@@ -739,11 +523,9 @@ done:
* reassigned during cleanup.
*/
static void
-nfsrv_zapsock(slp)
- register struct nfssvc_sock *slp;
+nfsrv_zapsock(struct nfssvc_sock *slp)
{
- register struct nfsuid *nuidp, *nnuidp;
- register struct nfsrv_descript *nwp, *nnwp;
+ struct nfsrv_descript *nwp, *nnwp;
struct socket *so;
struct file *fp;
struct nfsrv_rec *rec;
@@ -769,18 +551,9 @@ nfsrv_zapsock(slp)
m_freem(rec->nr_packet);
free(rec, M_NFSRVDESC);
}
- for (nuidp = slp->ns_uidlruhead.tqh_first; nuidp != 0;
- nuidp = nnuidp) {
- nnuidp = nuidp->nu_lru.tqe_next;
- LIST_REMOVE(nuidp, nu_hash);
- TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp, nu_lru);
- if (nuidp->nu_flag & NU_NAM)
- FREE(nuidp->nu_nam, M_SONAME);
- free((caddr_t)nuidp, M_NFSUID);
- }
s = splsoftclock();
- for (nwp = slp->ns_tq.lh_first; nwp; nwp = nnwp) {
- nnwp = nwp->nd_tq.le_next;
+ for (nwp = LIST_FIRST(&slp->ns_tq); nwp; nwp = nnwp) {
+ nnwp = LIST_NEXT(nwp, nd_tq);
LIST_REMOVE(nwp, nd_tq);
free((caddr_t)nwp, M_NFSRVDESC);
}
@@ -794,9 +567,9 @@ nfsrv_zapsock(slp)
* is no longer valid, you can throw it away.
*/
void
-nfsrv_slpderef(slp)
- register struct nfssvc_sock *slp;
+nfsrv_slpderef(struct nfssvc_sock *slp)
{
+
if (--(slp->ns_sref) == 0 && (slp->ns_flag & SLP_VALID) == 0) {
TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain);
free((caddr_t)slp, M_NFSSVC);
@@ -807,19 +580,17 @@ nfsrv_slpderef(slp)
* Lock a socket against others.
*/
int
-nfs_slplock(slp, wait)
- register struct nfssvc_sock *slp;
- int wait;
+nfs_slplock(struct nfssvc_sock *slp, int wait)
{
int *statep = &slp->ns_solock;
- if (!wait && (*statep & NFSSTA_SNDLOCK))
+ if (!wait && (*statep & NFSRV_SNDLOCK))
return(0); /* already locked, fail */
- while (*statep & NFSSTA_SNDLOCK) {
- *statep |= NFSSTA_WANTSND;
+ while (*statep & NFSRV_SNDLOCK) {
+ *statep |= NFSRV_WANTSND;
(void) tsleep((caddr_t)statep, PZERO - 1, "nfsslplck", 0);
}
- *statep |= NFSSTA_SNDLOCK;
+ *statep |= NFSRV_SNDLOCK;
return (1);
}
@@ -827,16 +598,15 @@ nfs_slplock(slp, wait)
* Unlock the stream socket for others.
*/
void
-nfs_slpunlock(slp)
- register struct nfssvc_sock *slp;
+nfs_slpunlock(struct nfssvc_sock *slp)
{
int *statep = &slp->ns_solock;
- if ((*statep & NFSSTA_SNDLOCK) == 0)
+ if ((*statep & NFSRV_SNDLOCK) == 0)
panic("nfs slpunlock");
- *statep &= ~NFSSTA_SNDLOCK;
- if (*statep & NFSSTA_WANTSND) {
- *statep &= ~NFSSTA_WANTSND;
+ *statep &= ~NFSRV_SNDLOCK;
+ if (*statep & NFSRV_WANTSND) {
+ *statep &= ~NFSRV_WANTSND;
wakeup((caddr_t)statep);
}
}
@@ -847,17 +617,16 @@ nfs_slpunlock(slp)
* corruption.
*/
void
-nfsrv_init(terminating)
- int terminating;
+nfsrv_init(int terminating)
{
- register struct nfssvc_sock *slp, *nslp;
+ struct nfssvc_sock *slp, *nslp;
if (nfssvc_sockhead_flag & SLP_INIT)
panic("nfsd init");
nfssvc_sockhead_flag |= SLP_INIT;
if (terminating) {
- for (slp = nfssvc_sockhead.tqh_first; slp != 0; slp = nslp) {
- nslp = slp->ns_chain.tqe_next;
+ for (slp = TAILQ_FIRST(&nfssvc_sockhead); slp != 0; slp = nslp){
+ nslp = TAILQ_NEXT(slp, ns_chain);
if (slp->ns_flag & SLP_VALID)
nfsrv_zapsock(slp);
TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain);
@@ -881,334 +650,11 @@ nfsrv_init(terminating)
nfs_udpsock = (struct nfssvc_sock *)
malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK | M_ZERO);
STAILQ_INIT(&nfs_udpsock->ns_rec);
- TAILQ_INIT(&nfs_udpsock->ns_uidlruhead);
TAILQ_INSERT_HEAD(&nfssvc_sockhead, nfs_udpsock, ns_chain);
nfs_cltpsock = (struct nfssvc_sock *)
malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK | M_ZERO);
STAILQ_INIT(&nfs_cltpsock->ns_rec);
- TAILQ_INIT(&nfs_cltpsock->ns_uidlruhead);
TAILQ_INSERT_TAIL(&nfssvc_sockhead, nfs_cltpsock, ns_chain);
#endif
}
-
-/*
- * Add entries to the server monitor log.
- */
-static void
-nfsd_rt(sotype, nd, cacherep)
- int sotype;
- register struct nfsrv_descript *nd;
- int cacherep;
-{
- register struct drt *rt;
-
- rt = &nfsdrt.drt[nfsdrt.pos];
- if (cacherep == RC_DOIT)
- rt->flag = 0;
- else if (cacherep == RC_REPLY)
- rt->flag = DRT_CACHEREPLY;
- else
- rt->flag = DRT_CACHEDROP;
- if (sotype == SOCK_STREAM)
- rt->flag |= DRT_TCP;
- if (nd->nd_flag & ND_NQNFS)
- rt->flag |= DRT_NQNFS;
- else if (nd->nd_flag & ND_NFSV3)
- rt->flag |= DRT_NFSV3;
- rt->proc = nd->nd_procnum;
- if (nd->nd_nam->sa_family == AF_INET)
- rt->ipadr = ((struct sockaddr_in *)nd->nd_nam)->sin_addr.s_addr;
- else
- rt->ipadr = INADDR_ANY;
- rt->resptime = nfs_curusec() - (nd->nd_starttime.tv_sec * 1000000 + nd->nd_starttime.tv_usec);
- getmicrotime(&rt->tstamp);
- nfsdrt.pos = (nfsdrt.pos + 1) % NFSRTTLOGSIZ;
-}
-#endif /* NFS_NOSERVER */
-
-static int nfs_defect = 0;
-SYSCTL_INT(_vfs_nfs, OID_AUTO, defect, CTLFLAG_RW, &nfs_defect, 0, "");
-
-/*
- * Asynchronous I/O daemons for client nfs.
- * They do read-ahead and write-behind operations on the block I/O cache.
- * Never returns unless it fails or gets killed.
- */
-static int
-nfssvc_iod(td)
- struct thread *td;
-{
- register struct buf *bp;
- register int i, myiod;
- struct nfsmount *nmp;
- int error = 0;
-
- /*
- * Assign my position or return error if too many already running
- */
- myiod = -1;
- for (i = 0; i < NFS_MAXASYNCDAEMON; i++)
- if (nfs_asyncdaemon[i] == 0) {
- nfs_asyncdaemon[i]++;
- myiod = i;
- break;
- }
- if (myiod == -1)
- return (EBUSY);
- nfs_numasync++;
- /*
- * Just loop around doin our stuff until SIGKILL
- */
- for (;;) {
- while (((nmp = nfs_iodmount[myiod]) == NULL
- || nmp->nm_bufq.tqh_first == NULL)
- && error == 0) {
- if (nmp)
- nmp->nm_bufqiods--;
- nfs_iodwant[myiod] = td->td_proc;
- nfs_iodmount[myiod] = NULL;
- error = tsleep((caddr_t)&nfs_iodwant[myiod],
- PWAIT | PCATCH, "nfsidl", 0);
- }
- if (error) {
- nfs_asyncdaemon[myiod] = 0;
- if (nmp)
- nmp->nm_bufqiods--;
- nfs_iodwant[myiod] = NULL;
- nfs_iodmount[myiod] = NULL;
- nfs_numasync--;
- return (error);
- }
- while ((bp = nmp->nm_bufq.tqh_first) != NULL) {
- /* Take one off the front of the list */
- TAILQ_REMOVE(&nmp->nm_bufq, bp, b_freelist);
- nmp->nm_bufqlen--;
- if (nmp->nm_bufqwant && nmp->nm_bufqlen <= nfs_numasync) {
- nmp->nm_bufqwant = FALSE;
- wakeup(&nmp->nm_bufq);
- }
- if (bp->b_iocmd == BIO_READ)
- (void) nfs_doio(bp, bp->b_rcred, (struct thread *)0);
- else
- (void) nfs_doio(bp, bp->b_wcred, (struct thread *)0);
- /*
- * If there are more than one iod on this mount, then defect
- * so that the iods can be shared out fairly between the mounts
- */
- if (nfs_defect && nmp->nm_bufqiods > 1) {
- NFS_DPF(ASYNCIO,
- ("nfssvc_iod: iod %d defecting from mount %p\n",
- myiod, nmp));
- nfs_iodmount[myiod] = NULL;
- nmp->nm_bufqiods--;
- break;
- }
- }
- }
-}
-
-
-/*
- * Get an authorization string for the uid by having the mount_nfs sitting
- * on this mount point porpous out of the kernel and do it.
- */
-int
-nfs_getauth(nmp, rep, cred, auth_str, auth_len, verf_str, verf_len, key)
- register struct nfsmount *nmp;
- struct nfsreq *rep;
- struct ucred *cred;
- char **auth_str;
- int *auth_len;
- char *verf_str;
- int *verf_len;
- NFSKERBKEY_T key; /* return session key */
-{
- int error = 0;
-
- while ((nmp->nm_state & NFSSTA_WAITAUTH) == 0) {
- nmp->nm_state |= NFSSTA_WANTAUTH;
- (void) tsleep((caddr_t)&nmp->nm_authtype, PSOCK,
- "nfsauth1", 2 * hz);
- error = nfs_sigintr(nmp, rep, rep->r_td->td_proc);
- if (error) {
- nmp->nm_state &= ~NFSSTA_WANTAUTH;
- return (error);
- }
- }
- nmp->nm_state &= ~(NFSSTA_WAITAUTH | NFSSTA_WANTAUTH);
- nmp->nm_authstr = *auth_str = (char *)malloc(RPCAUTH_MAXSIZ, M_TEMP, M_WAITOK);
- nmp->nm_authlen = RPCAUTH_MAXSIZ;
- nmp->nm_verfstr = verf_str;
- nmp->nm_verflen = *verf_len;
- nmp->nm_authuid = cred->cr_uid;
- wakeup((caddr_t)&nmp->nm_authstr);
-
- /*
- * And wait for mount_nfs to do its stuff.
- */
- while ((nmp->nm_state & NFSSTA_HASAUTH) == 0 && error == 0) {
- (void) tsleep((caddr_t)&nmp->nm_authlen, PSOCK,
- "nfsauth2", 2 * hz);
- error = nfs_sigintr(nmp, rep, rep->r_td->td_proc);
- }
- if (nmp->nm_state & NFSSTA_AUTHERR) {
- nmp->nm_state &= ~NFSSTA_AUTHERR;
- error = EAUTH;
- }
- if (error)
- free((caddr_t)*auth_str, M_TEMP);
- else {
- *auth_len = nmp->nm_authlen;
- *verf_len = nmp->nm_verflen;
- bcopy((caddr_t)nmp->nm_key, (caddr_t)key, sizeof (key));
- }
- nmp->nm_state &= ~NFSSTA_HASAUTH;
- nmp->nm_state |= NFSSTA_WAITAUTH;
- if (nmp->nm_state & NFSSTA_WANTAUTH) {
- nmp->nm_state &= ~NFSSTA_WANTAUTH;
- wakeup((caddr_t)&nmp->nm_authtype);
- }
- return (error);
-}
-
-/*
- * Get a nickname authenticator and verifier.
- */
-int
-nfs_getnickauth(nmp, cred, auth_str, auth_len, verf_str, verf_len)
- struct nfsmount *nmp;
- struct ucred *cred;
- char **auth_str;
- int *auth_len;
- char *verf_str;
- int verf_len;
-{
- register struct nfsuid *nuidp;
- register u_int32_t *nickp, *verfp;
- struct timeval ktvin, ktvout;
-
-#ifdef DIAGNOSTIC
- if (verf_len < (4 * NFSX_UNSIGNED))
- panic("nfs_getnickauth verf too small");
-#endif
- for (nuidp = NMUIDHASH(nmp, cred->cr_uid)->lh_first;
- nuidp != 0; nuidp = nuidp->nu_hash.le_next) {
- if (nuidp->nu_cr.cr_uid == cred->cr_uid)
- break;
- }
- if (!nuidp || nuidp->nu_expire < time_second)
- return (EACCES);
-
- /*
- * Move to the end of the lru list (end of lru == most recently used).
- */
- TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp, nu_lru);
- TAILQ_INSERT_TAIL(&nmp->nm_uidlruhead, nuidp, nu_lru);
-
- nickp = (u_int32_t *)malloc(2 * NFSX_UNSIGNED, M_TEMP, M_WAITOK);
- *nickp++ = txdr_unsigned(RPCAKN_NICKNAME);
- *nickp = txdr_unsigned(nuidp->nu_nickname);
- *auth_str = (char *)nickp;
- *auth_len = 2 * NFSX_UNSIGNED;
-
- /*
- * Now we must encrypt the verifier and package it up.
- */
- verfp = (u_int32_t *)verf_str;
- *verfp++ = txdr_unsigned(RPCAKN_NICKNAME);
- if (time_second > nuidp->nu_timestamp.tv_sec ||
- (time_second == nuidp->nu_timestamp.tv_sec &&
- time_second > nuidp->nu_timestamp.tv_usec))
- getmicrotime(&nuidp->nu_timestamp);
- else
- nuidp->nu_timestamp.tv_usec++;
- ktvin.tv_sec = txdr_unsigned(nuidp->nu_timestamp.tv_sec);
- ktvin.tv_usec = txdr_unsigned(nuidp->nu_timestamp.tv_usec);
-
- /*
- * Now encrypt the timestamp verifier in ecb mode using the session
- * key.
- */
-#ifdef NFSKERB
- XXX
-#endif
-
- *verfp++ = ktvout.tv_sec;
- *verfp++ = ktvout.tv_usec;
- *verfp = 0;
- return (0);
-}
-
-/*
- * Save the current nickname in a hash list entry on the mount point.
- */
-int
-nfs_savenickauth(nmp, cred, len, key, mdp, dposp, mrep)
- register struct nfsmount *nmp;
- struct ucred *cred;
- int len;
- NFSKERBKEY_T key;
- struct mbuf **mdp;
- char **dposp;
- struct mbuf *mrep;
-{
- register struct nfsuid *nuidp;
- register u_int32_t *tl;
- register int32_t t1;
- struct mbuf *md = *mdp;
- struct timeval ktvin, ktvout;
- u_int32_t nick;
- char *dpos = *dposp, *cp2;
- int deltasec, error = 0;
-
- if (len == (3 * NFSX_UNSIGNED)) {
- nfsm_dissect(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
- ktvin.tv_sec = *tl++;
- ktvin.tv_usec = *tl++;
- nick = fxdr_unsigned(u_int32_t, *tl);
-
- /*
- * Decrypt the timestamp in ecb mode.
- */
-#ifdef NFSKERB
- XXX
-#endif
- ktvout.tv_sec = fxdr_unsigned(long, ktvout.tv_sec);
- ktvout.tv_usec = fxdr_unsigned(long, ktvout.tv_usec);
- deltasec = time_second - ktvout.tv_sec;
- if (deltasec < 0)
- deltasec = -deltasec;
- /*
- * If ok, add it to the hash list for the mount point.
- */
- if (deltasec <= NFS_KERBCLOCKSKEW) {
- if (nmp->nm_numuids < nuidhash_max) {
- nmp->nm_numuids++;
- nuidp = (struct nfsuid *)
- malloc(sizeof (struct nfsuid), M_NFSUID,
- M_WAITOK);
- } else {
- nuidp = nmp->nm_uidlruhead.tqh_first;
- LIST_REMOVE(nuidp, nu_hash);
- TAILQ_REMOVE(&nmp->nm_uidlruhead, nuidp,
- nu_lru);
- }
- nuidp->nu_flag = 0;
- nuidp->nu_cr.cr_uid = cred->cr_uid;
- nuidp->nu_expire = time_second + NFS_KERBTTL;
- nuidp->nu_timestamp = ktvout;
- nuidp->nu_nickname = nick;
- bcopy(key, nuidp->nu_key, sizeof (key));
- TAILQ_INSERT_TAIL(&nmp->nm_uidlruhead, nuidp,
- nu_lru);
- LIST_INSERT_HEAD(NMUIDHASH(nmp, cred->cr_uid),
- nuidp, nu_hash);
- }
- } else
- nfsm_adv(nfsm_rndup(len));
-nfsmout:
- *mdp = md;
- *dposp = dpos;
- return (error);
-}
diff --git a/sys/nfsserver/nfsm_subs.h b/sys/nfsserver/nfsm_subs.h
index d58ef15..2f60521 100644
--- a/sys/nfsserver/nfsm_subs.h
+++ b/sys/nfsserver/nfsm_subs.h
@@ -37,12 +37,12 @@
* $FreeBSD$
*/
+#ifndef _NFSSERVER_NFSM_SUBS_H_
+#define _NFSSERVER_NFSM_SUBS_H_
-#ifndef _NFS_NFSM_SUBS_H_
-#define _NFS_NFSM_SUBS_H_
+#include <nfs/nfs_common.h>
-struct ucred;
-struct vnode;
+#define nfstov_mode(a) (fxdr_unsigned(u_int32_t, (a)) & ALLPERMS)
/*
* These macros do strange and peculiar things to mbuf chains for
@@ -53,24 +53,8 @@ struct vnode;
/*
* First define what the actual subs. return
*/
-struct mbuf *nfsm_reqh __P((struct vnode *vp, u_long procid, int hsiz,
- caddr_t *bposp));
-struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid,
- int auth_type, int auth_len, char *auth_str,
- int verf_len, char *verf_str,
- struct mbuf *mrest, int mrest_len,
- struct mbuf **mbp, u_int32_t *xidp));
#define M_HASCL(m) ((m)->m_flags & M_EXT)
-#define NFSMINOFF(m) \
- do { \
- if (M_HASCL(m)) \
- (m)->m_data = (m)->m_ext.ext_buf; \
- else if ((m)->m_flags & M_PKTHDR) \
- (m)->m_data = (m)->m_pktdat; \
- else \
- (m)->m_data = (m)->m_dat; \
- } while (0)
#define NFSMADV(m, s) \
do { \
(m)->m_data += (s); \
@@ -91,474 +75,111 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid,
* unions.
*/
-#define nfsm_build(a,c,s) \
- do { \
- if ((s) > M_TRAILINGSPACE(mb)) { \
- MGET(mb2, M_TRYWAIT, MT_DATA); \
- if ((s) > MLEN) \
- panic("build > MLEN"); \
- mb->m_next = mb2; \
- mb = mb2; \
- mb->m_len = 0; \
- bpos = mtod(mb, caddr_t); \
- } \
- (a) = (c)(bpos); \
- mb->m_len += (s); \
- bpos += (s); \
- } while (0)
-#define nfsm_dissect(a, c, s) \
- do { \
- t1 = mtod(md, caddr_t)+md->m_len-dpos; \
- if (t1 >= (s)) { \
- (a) = (c)(dpos); \
- dpos += (s); \
- } else if ((t1 = nfsm_disct(&md, &dpos, (s), t1, &cp2)) != 0){ \
- error = t1; \
- m_freem(mrep); \
- goto nfsmout; \
- } else { \
- (a) = (c)cp2; \
- } \
- } while (0)
-
-#define nfsm_fhtom(v, v3) \
- do { \
- if (v3) { \
- t2 = nfsm_rndup(VTONFS(v)->n_fhsize) + NFSX_UNSIGNED; \
- if (t2 <= M_TRAILINGSPACE(mb)) { \
- nfsm_build(tl, u_int32_t *, t2); \
- *tl++ = txdr_unsigned(VTONFS(v)->n_fhsize); \
- *(tl + ((t2>>2) - 2)) = 0; \
- bcopy((caddr_t)VTONFS(v)->n_fhp,(caddr_t)tl, \
- VTONFS(v)->n_fhsize); \
- } else if ((t2 = nfsm_strtmbuf(&mb, &bpos, \
- (caddr_t)VTONFS(v)->n_fhp, \
- VTONFS(v)->n_fhsize)) != 0) { \
- error = t2; \
- m_freem(mreq); \
- goto nfsmout; \
- } \
- } else { \
- nfsm_build(cp, caddr_t, NFSX_V2FH); \
- bcopy((caddr_t)VTONFS(v)->n_fhp, cp, NFSX_V2FH); \
- } \
- } while (0)
+/* Helpers for macros */
+void nfsm_srvfhtom_xx(fhandle_t *f, int v3, u_int32_t **tl, struct mbuf **mb,
+ caddr_t *bpos);
+void nfsm_srvpostop_fh_xx(fhandle_t *f, u_int32_t **tl, struct mbuf **mb,
+ caddr_t *bpos);
+int nfsm_srvstrsiz_xx(int *s, int m, u_int32_t **tl, struct mbuf **md,
+ caddr_t *dpos);
+int nfsm_srvnamesiz_xx(int *s, u_int32_t **tl, struct mbuf **md,
+ caddr_t *dpos);
+void nfs_rephead_xx(int s, struct nfsrv_descript *nfsd,
+ struct nfssvc_sock *slp, int error, struct mbuf **mrq,
+ struct mbuf **mb, struct mbuf **mreq, struct mbuf **mrep,
+ caddr_t *bpos);
+int nfsm_srvmtofh_xx(fhandle_t *f, struct nfsrv_descript *nfsd,
+ u_int32_t **tl, struct mbuf **md, caddr_t *dpos);
+void nfsm_clget_xx(u_int32_t **tl, struct mbuf *mb, struct mbuf **mp,
+ char **bp, char **be, caddr_t bpos);
+int nfsm_srvsattr_xx(struct vattr *a, u_int32_t **tl, struct mbuf **md,
+ caddr_t *dpos);
#define nfsm_srvfhtom(f, v3) \
- do { \
- if (v3) { \
- nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED + NFSX_V3FH);\
- *tl++ = txdr_unsigned(NFSX_V3FH); \
- bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \
- } else { \
- nfsm_build(cp, caddr_t, NFSX_V2FH); \
- bcopy((caddr_t)(f), cp, NFSX_V2FH); \
- } \
- } while (0)
+do { \
+ nfsm_srvfhtom_xx((f), (v3), &tl, &mb, &bpos); \
+} while (0)
#define nfsm_srvpostop_fh(f) \
- do { \
- nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED + NFSX_V3FH); \
- *tl++ = nfs_true; \
- *tl++ = txdr_unsigned(NFSX_V3FH); \
- bcopy((caddr_t)(f), (caddr_t)tl, NFSX_V3FH); \
- } while (0)
-
-#define nfsm_mtofh(d, v, v3, f) \
- do { \
- struct nfsnode *ttnp; nfsfh_t *ttfhp; int ttfhsize; \
- if (v3) { \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- (f) = fxdr_unsigned(int, *tl); \
- } else \
- (f) = 1; \
- if (f) { \
- nfsm_getfh(ttfhp, ttfhsize, (v3)); \
- if ((t1 = nfs_nget((d)->v_mount, ttfhp, ttfhsize, \
- &ttnp)) != 0) { \
- error = t1; \
- m_freem(mrep); \
- goto nfsmout; \
- } \
- (v) = NFSTOV(ttnp); \
- } \
- if (v3) { \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- if (f) \
- (f) = fxdr_unsigned(int, *tl); \
- else if (fxdr_unsigned(int, *tl)) \
- nfsm_adv(NFSX_V3FATTR); \
- } \
- if (f) \
- nfsm_loadattr((v), (struct vattr *)0); \
- } while (0)
-
-#define nfsm_getfh(f, s, v3) \
- do { \
- if (v3) { \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- if (((s) = fxdr_unsigned(int, *tl)) <= 0 || \
- (s) > NFSX_V3FHMAX) { \
- m_freem(mrep); \
- error = EBADRPC; \
- goto nfsmout; \
- } \
- } else \
- (s) = NFSX_V2FH; \
- nfsm_dissect((f), nfsfh_t *, nfsm_rndup(s)); \
- } while (0)
-
-#define nfsm_loadattr(v, a) \
- do { \
- struct vnode *ttvp = (v); \
- if ((t1 = nfs_loadattrcache(&ttvp, &md, &dpos, (a), 0)) != 0) { \
- error = t1; \
- m_freem(mrep); \
- goto nfsmout; \
- } \
- (v) = ttvp; \
- } while (0)
-
-#define nfsm_postop_attr(v, f) \
- do { \
- struct vnode *ttvp = (v); \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- if (((f) = fxdr_unsigned(int, *tl)) != 0) { \
- if ((t1 = nfs_loadattrcache(&ttvp, &md, &dpos, \
- (struct vattr *)0, 1)) != 0) { \
- error = t1; \
- (f) = 0; \
- m_freem(mrep); \
- goto nfsmout; \
- } \
- (v) = ttvp; \
- } \
- } while (0)
-
-/* Used as (f) for nfsm_wcc_data() */
-#define NFSV3_WCCRATTR 0
-#define NFSV3_WCCCHK 1
-
-#define nfsm_wcc_data(v, f) \
- do { \
- int ttattrf, ttretf = 0; \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- if (*tl == nfs_true) { \
- nfsm_dissect(tl, u_int32_t *, 6 * NFSX_UNSIGNED); \
- if (f) \
- ttretf = (VTONFS(v)->n_mtime == \
- fxdr_unsigned(u_int32_t, *(tl + 2))); \
- } \
- nfsm_postop_attr((v), ttattrf); \
- if (f) { \
- (f) = ttretf; \
- } else { \
- (f) = ttattrf; \
- } \
- } while (0)
-
-/* If full is true, set all fields, otherwise just set mode and time fields */
-#define nfsm_v3attrbuild(a, full) \
- do { \
- if ((a)->va_mode != (mode_t)VNOVAL) { \
- nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
- *tl++ = nfs_true; \
- *tl = txdr_unsigned((a)->va_mode); \
- } else { \
- nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
- *tl = nfs_false; \
- } \
- if ((full) && (a)->va_uid != (uid_t)VNOVAL) { \
- nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
- *tl++ = nfs_true; \
- *tl = txdr_unsigned((a)->va_uid); \
- } else { \
- nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
- *tl = nfs_false; \
- } \
- if ((full) && (a)->va_gid != (gid_t)VNOVAL) { \
- nfsm_build(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
- *tl++ = nfs_true; \
- *tl = txdr_unsigned((a)->va_gid); \
- } else { \
- nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
- *tl = nfs_false; \
- } \
- if ((full) && (a)->va_size != VNOVAL) { \
- nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED); \
- *tl++ = nfs_true; \
- txdr_hyper((a)->va_size, tl); \
- } else { \
- nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
- *tl = nfs_false; \
- } \
- if ((a)->va_atime.tv_sec != VNOVAL) { \
- if ((a)->va_atime.tv_sec != time_second) { \
- nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);\
- *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);\
- txdr_nfsv3time(&(a)->va_atime, tl); \
- } else { \
- nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
- *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \
- } \
- } else { \
- nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
- *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \
- } \
- if ((a)->va_mtime.tv_sec != VNOVAL) { \
- if ((a)->va_mtime.tv_sec != time_second) { \
- nfsm_build(tl, u_int32_t *, 3 * NFSX_UNSIGNED);\
- *tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);\
- txdr_nfsv3time(&(a)->va_mtime, tl); \
- } else { \
- nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
- *tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER); \
- } \
- } else { \
- nfsm_build(tl, u_int32_t *, NFSX_UNSIGNED); \
- *tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE); \
- } \
- } while (0)
-
-
-#define nfsm_strsiz(s,m) \
- do { \
- nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \
- if (((s) = fxdr_unsigned(int32_t,*tl)) > (m)) { \
- m_freem(mrep); \
- error = EBADRPC; \
- goto nfsmout; \
- } \
- } while (0)
-
-#define nfsm_srvstrsiz(s,m) \
- do { \
- nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \
- if (((s) = fxdr_unsigned(int32_t,*tl)) > (m) || (s) <= 0) { \
- error = EBADRPC; \
- nfsm_reply(0); \
- } \
- } while (0)
+do { \
+ nfsm_srvpostop_fh_xx((f), &tl, &mb, &bpos); \
+} while (0)
+
+#define nfsm_srvstrsiz(s, m) \
+do { \
+ int t1; \
+ t1 = nfsm_srvstrsiz_xx(&(s), (m), &tl, &md, &dpos); \
+ if (t1) { \
+ error = t1; \
+ nfsm_reply(0); \
+ } \
+} while (0)
#define nfsm_srvnamesiz(s) \
- do { \
- nfsm_dissect(tl,u_int32_t *,NFSX_UNSIGNED); \
- if (((s) = fxdr_unsigned(int32_t,*tl)) > NFS_MAXNAMLEN) \
- error = NFSERR_NAMETOL; \
- if ((s) <= 0) \
- error = EBADRPC; \
- if (error) \
- nfsm_reply(0); \
- } while (0)
-
-#define nfsm_mtouio(p,s) \
- do {\
- if ((s) > 0 && \
- (t1 = nfsm_mbuftouio(&md,(p),(s),&dpos)) != 0) { \
- error = t1; \
- m_freem(mrep); \
- goto nfsmout; \
- } \
- } while (0)
-
-#define nfsm_uiotom(p,s) \
- do { \
- if ((t1 = nfsm_uiotombuf((p),&mb,(s),&bpos)) != 0) { \
- error = t1; \
- m_freem(mreq); \
- goto nfsmout; \
- } \
- } while (0)
-
-#define nfsm_reqhead(v,a,s) \
- do { \
- mb = mreq = nfsm_reqh((v),(a),(s),&bpos); \
- } while (0)
-
-#define nfsm_reqdone \
- do { \
- m_freem(mrep); \
- nfsmout: \
- } while (0)
-
-#define nfsm_rndup(a) (((a)+3)&(~0x3))
-
-#define nfsm_request(v, t, p, c) \
- do { \
- if ((error = nfs_request((v), mreq, (t), (p), \
- (c), &mrep, &md, &dpos)) != 0) { \
- if (error & NFSERR_RETERR) \
- error &= ~NFSERR_RETERR; \
- else \
- goto nfsmout; \
- } \
- } while (0)
-
-#define nfsm_strtom(a,s,m) \
- do {\
- if ((s) > (m)) { \
- m_freem(mreq); \
- error = ENAMETOOLONG; \
- goto nfsmout; \
- } \
- t2 = nfsm_rndup(s)+NFSX_UNSIGNED; \
- if (t2 <= M_TRAILINGSPACE(mb)) { \
- nfsm_build(tl,u_int32_t *,t2); \
- *tl++ = txdr_unsigned(s); \
- *(tl+((t2>>2)-2)) = 0; \
- bcopy((const char *)(a), (caddr_t)tl, (s)); \
- } else if ((t2 = nfsm_strtmbuf(&mb, &bpos, (a), (s))) != 0) { \
- error = t2; \
- m_freem(mreq); \
- goto nfsmout; \
- } \
- } while (0)
-
-#define nfsm_srvdone \
- do { \
- nfsmout: \
- return (error); \
- } while (0)
+do { \
+ int t1; \
+ t1 = nfsm_srvnamesiz_xx(&(s), &tl, &md, &dpos); \
+ if (t1) { \
+ error = t1; \
+ nfsm_reply(0); \
+ } \
+} while (0)
#define nfsm_reply(s) \
- do { \
- nfsd->nd_repstat = error; \
- if (error && !(nfsd->nd_flag & ND_NFSV3)) \
- (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \
- mrq, &mb, &bpos); \
- else \
- (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \
- mrq, &mb, &bpos); \
- if (mrep != NULL) { \
- m_freem(mrep); \
- mrep = NULL; \
- } \
- mreq = *mrq; \
- if (error && (!(nfsd->nd_flag & ND_NFSV3) || \
- error == EBADRPC)) { \
- error = 0; \
- goto nfsmout; \
- } \
- } while (0)
-
-#define nfsm_writereply(s, v3) \
- do { \
- nfsd->nd_repstat = error; \
- if (error && !(v3)) \
- (void) nfs_rephead(0, nfsd, slp, error, cache, &frev, \
- &mreq, &mb, &bpos); \
- else \
- (void) nfs_rephead((s), nfsd, slp, error, cache, &frev, \
- &mreq, &mb, &bpos); \
- } while (0)
-
-#define nfsm_adv(s) \
- do { \
- t1 = mtod(md, caddr_t)+md->m_len-dpos; \
- if (t1 >= (s)) { \
- dpos += (s); \
- } else if ((t1 = nfs_adv(&md, &dpos, (s), t1)) != 0) { \
- error = t1; \
- m_freem(mrep); \
- goto nfsmout; \
- } \
- } while (0)
+do { \
+ nfs_rephead_xx((s), nfsd, slp, error, mrq, &mb, &mreq, &mrep, &bpos); \
+ if (error && error == EBADRPC) { \
+ error = 0; \
+ goto nfsmout; \
+ } \
+} while (0)
+
+#define nfsm_writereply(s) \
+do { \
+ nfs_rephead((s), nfsd, slp, error, &mreq, &mb, &bpos); \
+} while (0)
#define nfsm_srvmtofh(f) \
- do { \
- int fhlen; \
- if (nfsd->nd_flag & ND_NFSV3) { \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- fhlen = fxdr_unsigned(int, *tl); \
- if (fhlen != 0 && fhlen != NFSX_V3FH) { \
- error = EBADRPC; \
- nfsm_reply(0); \
- } \
- } else { \
- fhlen = NFSX_V2FH; \
- } \
- if (fhlen != 0) { \
- nfsm_dissect(tl, u_int32_t *, fhlen); \
- bcopy((caddr_t)tl, (caddr_t)(f), fhlen); \
- } else {\
- bzero((caddr_t)(f), NFSX_V3FH); \
- } \
- } while (0)
-
-#define nfsm_clget \
- do { \
- if (bp >= be) { \
- if (mp == mb) \
- mp->m_len += bp-bpos; \
- MGET(mp, M_TRYWAIT, MT_DATA); \
- MCLGET(mp, M_TRYWAIT); \
- mp->m_len = NFSMSIZ(mp); \
- mp2->m_next = mp; \
- mp2 = mp; \
- bp = mtod(mp, caddr_t); \
- be = bp+mp->m_len; \
- } \
- tl = (u_int32_t *)bp; \
- } while (0)
+do { \
+ int t1; \
+ t1 = nfsm_srvmtofh_xx((f), nfsd, &tl, &md, &dpos); \
+ if (t1) { \
+ error = t1; \
+ nfsm_reply(0); \
+ } \
+} while (0)
+
+#define nfsm_clget \
+do { \
+ nfsm_clget_xx(&tl, mb, &mp, &bp, &be, bpos); \
+} while (0)
#define nfsm_srvfillattr(a, f) \
- do { \
- nfsm_srvfattr(nfsd, (a), (f)); \
- } while (0)
+do { \
+ nfsm_srvfattr(nfsd, (a), (f)); \
+} while (0)
#define nfsm_srvwcc_data(br, b, ar, a) \
- do { \
- nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos); \
- } while (0)
+do { \
+ nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos); \
+} while (0)
#define nfsm_srvpostop_attr(r, a) \
- do { \
- nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos); \
- } while (0)
+do { \
+ nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos); \
+} while (0)
#define nfsm_srvsattr(a) \
- do { \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- if (*tl == nfs_true) { \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- (a)->va_mode = nfstov_mode(*tl); \
- } \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- if (*tl == nfs_true) { \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- (a)->va_uid = fxdr_unsigned(uid_t, *tl); \
- } \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- if (*tl == nfs_true) { \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- (a)->va_gid = fxdr_unsigned(gid_t, *tl); \
- } \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- if (*tl == nfs_true) { \
- nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
- (a)->va_size = fxdr_hyper(tl); \
- } \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- switch (fxdr_unsigned(int, *tl)) { \
- case NFSV3SATTRTIME_TOCLIENT: \
- nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
- fxdr_nfsv3time(tl, &(a)->va_atime); \
- break; \
- case NFSV3SATTRTIME_TOSERVER: \
- getnanotime(&(a)->va_atime); \
- break; \
- }; \
- nfsm_dissect(tl, u_int32_t *, NFSX_UNSIGNED); \
- switch (fxdr_unsigned(int, *tl)) { \
- case NFSV3SATTRTIME_TOCLIENT: \
- nfsm_dissect(tl, u_int32_t *, 2 * NFSX_UNSIGNED); \
- fxdr_nfsv3time(tl, &(a)->va_mtime); \
- break; \
- case NFSV3SATTRTIME_TOSERVER: \
- getnanotime(&(a)->va_mtime); \
- break; \
- } \
- } while (0)
+do { \
+ int t1; \
+ t1 = nfsm_srvsattr_xx((a), &tl, &md, &dpos); \
+ if (t1) { \
+ error = t1; \
+ m_freem(mrep); \
+ mrep = NULL; \
+ goto nfsmout; \
+ } \
+} while (0)
#endif
diff --git a/sys/nfsserver/nfsrvcache.h b/sys/nfsserver/nfsrvcache.h
index eec5850..96b76d5 100644
--- a/sys/nfsserver/nfsrvcache.h
+++ b/sys/nfsserver/nfsrvcache.h
@@ -37,9 +37,8 @@
* $FreeBSD$
*/
-
-#ifndef _NFS_NFSRVCACHE_H_
-#define _NFS_NFSRVCACHE_H_
+#ifndef _NFSSERVER_NFSRVCACHE_H_
+#define _NFSSERVER_NFSRVCACHE_H_
#include <sys/queue.h>
@@ -77,14 +76,13 @@ struct nfsrvcache {
#define RC_DROPIT 0
#define RC_REPLY 1
#define RC_DOIT 2
-#define RC_CHECKIT 3
/* Flag bits */
#define RC_LOCKED 0x01
#define RC_WANTED 0x02
#define RC_REPSTATUS 0x04
#define RC_REPMBUF 0x08
-#define RC_NQNFS 0x10
+/* free 0x10 */
#define RC_INETADDR 0x20
#define RC_NAM 0x40
diff --git a/sys/nfsserver/nfsrvstats.h b/sys/nfsserver/nfsrvstats.h
index da808f4..d744f95 100644
--- a/sys/nfsserver/nfsrvstats.h
+++ b/sys/nfsserver/nfsrvstats.h
@@ -37,691 +37,21 @@
* $FreeBSD$
*/
-#ifndef _NFS_NFS_H_
-#define _NFS_NFS_H_
-
-#ifdef _KERNEL
-#include "opt_nfs.h"
-#endif
-
-/*
- * Tunable constants for nfs
- */
-
-#define NFS_MAXIOVEC 34
-#define NFS_TICKINTVL 5 /* Desired time for a tick (msec) */
-#define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */
-#define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */
-#define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */
-#define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */
-#define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/
-#define NFS_MAXREXMIT 100 /* Stop counting after this many */
-#define NFS_MAXWINDOW 1024 /* Max number of outstanding requests */
-#define NFS_RETRANS 10 /* Num of retrans for soft mounts */
-#define NFS_MAXGRPS 16 /* Max. size of groups list */
-#ifndef NFS_MINATTRTIMO
-#define NFS_MINATTRTIMO 3 /* VREG attrib cache timeout in sec */
-#endif
-#ifndef NFS_MAXATTRTIMO
-#define NFS_MAXATTRTIMO 60
-#endif
-#ifndef NFS_MINDIRATTRTIMO
-#define NFS_MINDIRATTRTIMO 30 /* VDIR attrib cache timeout in sec */
-#endif
-#ifndef NFS_MAXDIRATTRTIMO
-#define NFS_MAXDIRATTRTIMO 60
-#endif
-#define NFS_WSIZE 8192 /* Def. write data size <= 8192 */
-#define NFS_RSIZE 8192 /* Def. read data size <= 8192 */
-#define NFS_READDIRSIZE 8192 /* Def. readdir size */
-#define NFS_DEFRAHEAD 1 /* Def. read ahead # blocks */
-#define NFS_MAXRAHEAD 4 /* Max. read ahead # blocks */
-#define NFS_MAXUIDHASH 64 /* Max. # of hashed uid entries/mp */
-#define NFS_MAXASYNCDAEMON 20 /* Max. number async_daemons runnable */
-#define NFS_MAXGATHERDELAY 100 /* Max. write gather delay (msec) */
-#ifndef NFS_GATHERDELAY
-#define NFS_GATHERDELAY 10 /* Default write gather delay (msec) */
-#endif
-#define NFS_DIRBLKSIZ 4096 /* Must be a multiple of DIRBLKSIZ */
-#ifdef _KERNEL
-#define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
-#endif
-
-/*
- * Oddballs
- */
-#define NMOD(a) ((a) % nfs_asyncdaemons)
-#define NFS_CMPFH(n, f, s) \
- ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
-#define NFS_ISV3(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
-#define NFS_SRVMAXDATA(n) \
- (((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
- NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
-
-/*
- * XXX
- * The B_INVAFTERWRITE flag should be set to whatever is required by the
- * buffer cache code to say "Invalidate the block after it is written back".
- */
-#define B_INVAFTERWRITE B_NOCACHE
-
-/*
- * The IO_METASYNC flag should be implemented for local file systems.
- * (Until then, it is nothin at all.)
- */
-#ifndef IO_METASYNC
-#define IO_METASYNC 0
-#endif
-
-/*
- * Arguments to mount NFS
- */
-#define NFS_ARGSVERSION 3 /* change when nfs_args changes */
-struct nfs_args {
- int version; /* args structure version number */
- struct sockaddr *addr; /* file server address */
- int addrlen; /* length of address */
- int sotype; /* Socket type */
- int proto; /* and Protocol */
- u_char *fh; /* File handle to be mounted */
- int fhsize; /* Size, in bytes, of fh */
- int flags; /* flags */
- int wsize; /* write size in bytes */
- int rsize; /* read size in bytes */
- int readdirsize; /* readdir size in bytes */
- int timeo; /* initial timeout in .1 secs */
- int retrans; /* times to retry send */
- int maxgrouplist; /* Max. size of group list */
- int readahead; /* # of blocks to readahead */
- int leaseterm; /* Term (sec) of lease */
- int deadthresh; /* Retrans threshold */
- char *hostname; /* server's name */
- int acregmin; /* cache attrs for reg files min time */
- int acregmax; /* cache attrs for reg files max time */
- int acdirmin; /* cache attrs for dirs min time */
- int acdirmax; /* cache attrs for dirs max time */
-};
-
-/*
- * NFS mount option flags
- */
-#define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */
-#define NFSMNT_WSIZE 0x00000002 /* set write size */
-#define NFSMNT_RSIZE 0x00000004 /* set read size */
-#define NFSMNT_TIMEO 0x00000008 /* set initial timeout */
-#define NFSMNT_RETRANS 0x00000010 /* set number of request retries */
-#define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */
-#define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */
-#define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */
-#define NFSMNT_NQNFS 0x00000100 /* Use Nqnfs protocol */
-#define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */
-#define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */
-#define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */
-#define NFSMNT_LEASETERM 0x00001000 /* set lease term (nqnfs) */
-#define NFSMNT_READAHEAD 0x00002000 /* set read ahead */
-#define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */
-#define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */
-#define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */
-#define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */
-#define NFSMNT_ACREGMIN 0x00040000
-#define NFSMNT_ACREGMAX 0x00080000
-#define NFSMNT_ACDIRMIN 0x00100000
-#define NFSMNT_ACDIRMAX 0x00200000
-
-#define NFSSTA_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */
-#define NFSSTA_GOTPATHCONF 0x00080000 /* Got the V3 pathconf info */
-#define NFSSTA_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */
-#define NFSSTA_MNTD 0x00200000 /* Mnt server for mnt point */
-#define NFSSTA_DISMINPROG 0x00400000 /* Dismount in progress */
-#define NFSSTA_DISMNT 0x00800000 /* Dismounted */
-#define NFSSTA_SNDLOCK 0x01000000 /* Send socket lock */
-#define NFSSTA_WANTSND 0x02000000 /* Want above */
-#define NFSSTA_RCVLOCK 0x04000000 /* Rcv socket lock */
-#define NFSSTA_WANTRCV 0x08000000 /* Want above */
-#define NFSSTA_WAITAUTH 0x10000000 /* Wait for authentication */
-#define NFSSTA_HASAUTH 0x20000000 /* Has authenticator */
-#define NFSSTA_WANTAUTH 0x40000000 /* Wants an authenticator */
-#define NFSSTA_AUTHERR 0x80000000 /* Authentication error */
+#ifndef _NFSSERVER_NFSRVSTATS_H_
+#define _NFSSERVER_NFSRVSTATS_H_
/*
- * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
- * should ever try and use it.
+ * Server stats structure
*/
-struct nfsd_args {
- int sock; /* Socket to serve */
- caddr_t name; /* Client addr for connection based sockets */
- int namelen; /* Length of name */
-};
-
-struct nfsd_srvargs {
- struct nfsd *nsd_nfsd; /* Pointer to in kernel nfsd struct */
- uid_t nsd_uid; /* Effective uid mapped to cred */
- u_int32_t nsd_haddr; /* Ip address of client */
- struct xucred nsd_cr; /* Cred. uid maps to */
- u_int nsd_authlen; /* Length of auth string (ret) */
- u_char *nsd_authstr; /* Auth string (ret) */
- u_int nsd_verflen; /* and the verfier */
- u_char *nsd_verfstr;
- struct timeval nsd_timestamp; /* timestamp from verifier */
- u_int32_t nsd_ttl; /* credential ttl (sec) */
- NFSKERBKEY_T nsd_key; /* Session key */
-};
-
-struct nfsd_cargs {
- char *ncd_dirp; /* Mount dir path */
- uid_t ncd_authuid; /* Effective uid */
- int ncd_authtype; /* Type of authenticator */
- u_int ncd_authlen; /* Length of authenticator string */
- u_char *ncd_authstr; /* Authenticator string */
- u_int ncd_verflen; /* and the verifier */
- u_char *ncd_verfstr;
- NFSKERBKEY_T ncd_key; /* Session key */
-};
-
-/*
- * XXX to allow amd to include nfs.h without nfsproto.h
- */
-#ifdef NFS_NPROCS
-/*
- * Stats structure
- */
-struct nfsstats {
- int attrcache_hits;
- int attrcache_misses;
- int lookupcache_hits;
- int lookupcache_misses;
- int direofcache_hits;
- int direofcache_misses;
- int biocache_reads;
- int read_bios;
- int read_physios;
- int biocache_writes;
- int write_bios;
- int write_physios;
- int biocache_readlinks;
- int readlink_bios;
- int biocache_readdirs;
- int readdir_bios;
- int rpccnt[NFS_NPROCS];
- int rpcretries;
- int srvrpccnt[NFS_NPROCS];
+struct nfsrvstats {
int srvrpc_errs;
int srv_errs;
- int rpcrequests;
- int rpctimeouts;
- int rpcunexpected;
- int rpcinvalid;
int srvcache_inproghits;
int srvcache_idemdonehits;
int srvcache_nonidemdonehits;
int srvcache_misses;
- int srvnqnfs_leases;
- int srvnqnfs_maxleases;
- int srvnqnfs_getleases;
int srvvop_writes;
- int accesscache_hits;
- int accesscache_misses;
-};
-#endif
-
-/*
- * Flags for nfssvc() system call.
- */
-#define NFSSVC_BIOD 0x002
-#define NFSSVC_NFSD 0x004
-#define NFSSVC_ADDSOCK 0x008
-#define NFSSVC_AUTHIN 0x010
-#define NFSSVC_GOTAUTH 0x040
-#define NFSSVC_AUTHINFAIL 0x080
-#define NFSSVC_MNTD 0x100
-#define NFSSVC_LOCKDANS 0x200
-
-/*
- * fs.nfs sysctl(3) identifiers
- */
-#define NFS_NFSSTATS 1 /* struct: struct nfsstats */
-#define NFS_NFSPRIVPORT 2 /* int: prohibit nfs to resvports */
-
-#define FS_NFS_NAMES { \
- { 0, 0 }, \
- { "nfsstats", CTLTYPE_STRUCT }, \
- { "nfsprivport", CTLTYPE_INT }, \
-}
-
-#ifdef _KERNEL
-
-#ifdef MALLOC_DECLARE
-MALLOC_DECLARE(M_NFSREQ);
-MALLOC_DECLARE(M_NFSDIROFF);
-MALLOC_DECLARE(M_NFSRVDESC);
-MALLOC_DECLARE(M_NFSUID);
-MALLOC_DECLARE(M_NQLEASE);
-MALLOC_DECLARE(M_NFSD);
-MALLOC_DECLARE(M_NFSBIGFH);
-MALLOC_DECLARE(M_NFSHASH);
-#endif
-
-#ifdef ZONE_INTERRUPT
-extern vm_zone_t nfsmount_zone;
-#endif
-
-extern struct callout_handle nfs_timer_handle;
-
-struct uio; struct buf; struct vattr; struct nameidata; /* XXX */
-
-/*
- * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
- * What should be in this set is open to debate, but I believe that since
- * I/O system calls on ufs are never interrupted by signals the set should
- * be minimal. My reasoning is that many current programs that use signals
- * such as SIGALRM will not expect file I/O system calls to be interrupted
- * by them and break.
- */
-#define NFSINT_SIGMASK(set) \
- (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \
- SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \
- SIGISMEMBER(set, SIGQUIT))
-
-/*
- * Socket errors ignored for connectionless sockets??
- * For now, ignore them all
- */
-#define NFSIGNORE_SOERROR(s, e) \
- ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
- ((s) & PR_CONNREQUIRED) == 0)
-
-/*
- * Nfs outstanding request list element
- */
-struct nfsreq {
- TAILQ_ENTRY(nfsreq) r_chain;
- struct mbuf *r_mreq;
- struct mbuf *r_mrep;
- struct mbuf *r_md;
- caddr_t r_dpos;
- struct nfsmount *r_nmp;
- struct vnode *r_vp;
- u_int32_t r_xid;
- int r_flags; /* flags on request, see below */
- int r_retry; /* max retransmission count */
- int r_rexmit; /* current retrans count */
- int r_timer; /* tick counter on reply */
- u_int32_t r_procnum; /* NFS procedure number */
- int r_rtt; /* RTT for rpc */
- struct thread *r_td; /* Proc that did I/O system call */
-};
-
-/*
- * Queue head for nfsreq's
- */
-extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
-
-/* Flag values for r_flags */
-#define R_TIMING 0x01 /* timing request (in mntp) */
-#define R_SENT 0x02 /* request has been sent */
-#define R_SOFTTERM 0x04 /* soft mnt, too many retries */
-#define R_INTR 0x08 /* intr mnt, signal pending */
-#define R_SOCKERR 0x10 /* Fatal error on socket */
-#define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */
-#define R_MUSTRESEND 0x40 /* Must resend request */
-#define R_GETONEREP 0x80 /* Probe for one reply only */
-
-/*
- * A list of nfssvc_sock structures is maintained with all the sockets
- * that require service by the nfsd.
- * The nfsuid structs hang off of the nfssvc_sock structs in both lru
- * and uid hash lists.
- */
-#ifndef NFS_UIDHASHSIZ
-#define NFS_UIDHASHSIZ 29 /* Tune the size of nfssvc_sock with this */
-#endif
-#define NUIDHASH(sock, uid) \
- (&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
-#ifndef NFS_WDELAYHASHSIZ
-#define NFS_WDELAYHASHSIZ 16 /* and with this */
-#endif
-#define NWDELAYHASH(sock, f) \
- (&(sock)->ns_wdelayhashtbl[(*((u_int32_t *)(f))) % NFS_WDELAYHASHSIZ])
-#ifndef NFS_MUIDHASHSIZ
-#define NFS_MUIDHASHSIZ 63 /* Tune the size of nfsmount with this */
-#endif
-#define NMUIDHASH(nmp, uid) \
- (&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
-#define NFSNOHASH(fhsum) \
- (&nfsnodehashtbl[(fhsum) & nfsnodehash])
-
-/*
- * Network address hash list element
- */
-union nethostaddr {
- u_int32_t had_inetaddr;
- struct sockaddr *had_nam;
-};
-
-struct nfsuid {
- TAILQ_ENTRY(nfsuid) nu_lru; /* LRU chain */
- LIST_ENTRY(nfsuid) nu_hash; /* Hash list */
- int nu_flag; /* Flags */
- union nethostaddr nu_haddr; /* Host addr. for dgram sockets */
- struct ucred nu_cr; /* Cred uid mapped to */
- int nu_expire; /* Expiry time (sec) */
- struct timeval nu_timestamp; /* Kerb. timestamp */
- u_int32_t nu_nickname; /* Nickname on server */
- NFSKERBKEY_T nu_key; /* and session key */
-};
-
-#define nu_inetaddr nu_haddr.had_inetaddr
-#define nu_nam nu_haddr.had_nam
-/* Bits for nu_flag */
-#define NU_INETADDR 0x1
-#define NU_NAM 0x2
-#define NU_NETFAM(u) (((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
-
-struct nfsrv_rec {
- STAILQ_ENTRY(nfsrv_rec) nr_link;
- struct sockaddr *nr_address;
- struct mbuf *nr_packet;
-};
-
-struct nfssvc_sock {
- TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */
- TAILQ_HEAD(, nfsuid) ns_uidlruhead;
- struct file *ns_fp;
- struct socket *ns_so;
- struct sockaddr *ns_nam;
- struct mbuf *ns_raw;
- struct mbuf *ns_rawend;
- STAILQ_HEAD(, nfsrv_rec) ns_rec;
- struct mbuf *ns_frag;
- int ns_flag;
- int ns_solock;
- int ns_cc;
- int ns_reclen;
- int ns_numuids;
- u_int32_t ns_sref;
- LIST_HEAD(, nfsrv_descript) ns_tq; /* Write gather lists */
- LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ];
- LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
-};
-
-/* Bits for "ns_flag" */
-#define SLP_VALID 0x01
-#define SLP_DOREC 0x02
-#define SLP_NEEDQ 0x04
-#define SLP_DISCONN 0x08
-#define SLP_GETSTREAM 0x10
-#define SLP_LASTFRAG 0x20
-#define SLP_ALLFLAGS 0xff
-
-extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
-extern int nfssvc_sockhead_flag;
-#define SLP_INIT 0x01
-#define SLP_WANTINIT 0x02
-
-/*
- * One of these structures is allocated for each nfsd.
- */
-struct nfsd {
- TAILQ_ENTRY(nfsd) nfsd_chain; /* List of all nfsd's */
- int nfsd_flag; /* NFSD_ flags */
- struct nfssvc_sock *nfsd_slp; /* Current socket */
- int nfsd_authlen; /* Authenticator len */
- u_char nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
- int nfsd_verflen; /* and the Verifier */
- u_char nfsd_verfstr[RPCVERF_MAXSIZ];
- struct thread *nfsd_td; /* daemon thread ptr */
- struct nfsrv_descript *nfsd_nd; /* Associated nfsrv_descript */
-};
-
-/* Bits for "nfsd_flag" */
-#define NFSD_WAITING 0x01
-#define NFSD_REQINPROG 0x02
-#define NFSD_NEEDAUTH 0x04
-#define NFSD_AUTHFAIL 0x08
-
-/*
- * This structure is used by the server for describing each request.
- * Some fields are used only when write request gathering is performed.
- */
-struct nfsrv_descript {
- u_quad_t nd_time; /* Write deadline (usec) */
- off_t nd_off; /* Start byte offset */
- off_t nd_eoff; /* and end byte offset */
- LIST_ENTRY(nfsrv_descript) nd_hash; /* Hash list */
- LIST_ENTRY(nfsrv_descript) nd_tq; /* and timer list */
- LIST_HEAD(,nfsrv_descript) nd_coalesce; /* coalesced writes */
- struct mbuf *nd_mrep; /* Request mbuf list */
- struct mbuf *nd_md; /* Current dissect mbuf */
- struct mbuf *nd_mreq; /* Reply mbuf list */
- struct sockaddr *nd_nam; /* and socket addr */
- struct sockaddr *nd_nam2; /* return socket addr */
- caddr_t nd_dpos; /* Current dissect pos */
- u_int32_t nd_procnum; /* RPC # */
- int nd_stable; /* storage type */
- int nd_flag; /* nd_flag */
- int nd_len; /* Length of this write */
- int nd_repstat; /* Reply status */
- u_int32_t nd_retxid; /* Reply xid */
- u_int32_t nd_duration; /* Lease duration */
- struct timeval nd_starttime; /* Time RPC initiated */
- fhandle_t nd_fh; /* File handle */
- struct ucred nd_cr; /* Credentials */
+ int srvrpccnt[NFS_NPROCS];
};
-/* Bits for "nd_flag" */
-#define ND_READ LEASE_READ
-#define ND_WRITE LEASE_WRITE
-#define ND_CHECK 0x04
-#define ND_LEASE (ND_READ | ND_WRITE | ND_CHECK)
-#define ND_NFSV3 0x08
-#define ND_NQNFS 0x10
-#define ND_KERBNICK 0x20
-#define ND_KERBFULL 0x40
-#define ND_KERBAUTH (ND_KERBNICK | ND_KERBFULL)
-
-extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
-extern int nfsd_head_flag;
-#define NFSD_CHECKSLP 0x01
-
-/*
- * These macros compare nfsrv_descript structures.
- */
-#define NFSW_CONTIG(o, n) \
- ((o)->nd_eoff >= (n)->nd_off && \
- !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
-
-#define NFSW_SAMECRED(o, n) \
- (((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
- !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
- sizeof (struct ucred)))
-
-/*
- * Defines for WebNFS
- */
-
-#define WEBNFS_ESC_CHAR '%'
-#define WEBNFS_SPECCHAR_START 0x80
-
-#define WEBNFS_NATIVE_CHAR 0x80
-/*
- * ..
- * Possibly more here in the future.
- */
-
-/*
- * Macro for converting escape characters in WebNFS pathnames.
- * Should really be in libkern.
- */
-
-#define HEXTOC(c) \
- ((c) >= 'a' ? ((c) - ('a' - 10)) : \
- ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
-#define HEXSTRTOI(p) \
- ((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
-
-#ifdef NFS_DEBUG
-
-extern int nfs_debug;
-#define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */
-#define NFS_DEBUG_WG 2 /* server write gathering */
-#define NFS_DEBUG_RC 4 /* server request caching */
-
-#define NFS_DPF(cat, args) \
- do { \
- if (nfs_debug & NFS_DEBUG_##cat) printf args; \
- } while (0)
-
-#else
-
-#define NFS_DPF(cat, args)
-
-#endif
-
-u_quad_t nfs_curusec __P((void));
-int nfs_init __P((struct vfsconf *vfsp));
-int nfs_uninit __P((struct vfsconf *vfsp));
-int nfs_reply __P((struct nfsreq *));
-int nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int));
-int nfs_send __P((struct socket *, struct sockaddr *, struct mbuf *,
- struct nfsreq *));
-int nfs_rephead __P((int, struct nfsrv_descript *, struct nfssvc_sock *,
- int, int, u_quad_t *, struct mbuf **, struct mbuf **,
- caddr_t *));
-int nfs_sndlock __P((struct nfsreq *));
-void nfs_sndunlock __P((struct nfsreq *));
-int nfs_slplock __P((struct nfssvc_sock *, int));
-void nfs_slpunlock __P((struct nfssvc_sock *));
-int nfs_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *));
-int nfs_vinvalbuf __P((struct vnode *, int, struct ucred *, struct thread *,
- int));
-int nfs_readrpc __P((struct vnode *, struct uio *, struct ucred *));
-int nfs_writerpc __P((struct vnode *, struct uio *, struct ucred *, int *,
- int *));
-int nfs_commit __P((struct vnode *vp, u_quad_t offset, int cnt,
- struct ucred *cred, struct thread *td));
-int nfs_readdirrpc __P((struct vnode *, struct uio *, struct ucred *));
-int nfs_asyncio __P((struct buf *, struct ucred *, struct thread *));
-int nfs_doio __P((struct buf *, struct ucred *, struct thread *));
-int nfs_readlinkrpc __P((struct vnode *, struct uio *, struct ucred *));
-int nfs_sigintr __P((struct nfsmount *, struct nfsreq *, struct proc *));
-int nfs_readdirplusrpc __P((struct vnode *, struct uio *, struct ucred *));
-int nfsm_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *));
-void nfsm_srvfattr __P((struct nfsrv_descript *, struct vattr *,
- struct nfs_fattr *));
-void nfsm_srvwcc __P((struct nfsrv_descript *, int, struct vattr *, int,
- struct vattr *, struct mbuf **, char **));
-void nfsm_srvpostopattr __P((struct nfsrv_descript *, int, struct vattr *,
- struct mbuf **, char **));
-int netaddr_match __P((int, union nethostaddr *, struct sockaddr *));
-int nfs_request __P((struct vnode *, struct mbuf *, int, struct thread *,
- struct ucred *, struct mbuf **, struct mbuf **,
- caddr_t *));
-int nfs_loadattrcache __P((struct vnode **, struct mbuf **, caddr_t *,
- struct vattr *, int));
-int nfs_namei __P((struct nameidata *, fhandle_t *, int,
- struct nfssvc_sock *, struct sockaddr *, struct mbuf **,
- caddr_t *, struct vnode **, struct thread *, int, int));
-void nfsm_adj __P((struct mbuf *, int, int));
-int nfsm_mbuftouio __P((struct mbuf **, struct uio *, int, caddr_t *));
-void nfsrv_initcache __P((void));
-int nfs_getauth __P((struct nfsmount *, struct nfsreq *, struct ucred *,
- char **, int *, char *, int *, NFSKERBKEY_T));
-int nfs_getnickauth __P((struct nfsmount *, struct ucred *, char **,
- int *, char *, int));
-int nfs_savenickauth __P((struct nfsmount *, struct ucred *, int,
- NFSKERBKEY_T, struct mbuf **, char **,
- struct mbuf *));
-int nfs_adv __P((struct mbuf **, caddr_t *, int, int));
-void nfs_nhinit __P((void));
-void nfs_timer __P((void*));
-int nfsrv_dorec __P((struct nfssvc_sock *, struct nfsd *,
- struct nfsrv_descript **));
-int nfsrv_getcache __P((struct nfsrv_descript *, struct nfssvc_sock *,
- struct mbuf **));
-void nfsrv_updatecache __P((struct nfsrv_descript *, int, struct mbuf *));
-void nfsrv_cleancache __P((void));
-int nfs_connect __P((struct nfsmount *, struct nfsreq *));
-void nfs_disconnect __P((struct nfsmount *));
-void nfs_safedisconnect __P((struct nfsmount *));
-int nfs_getattrcache __P((struct vnode *, struct vattr *));
-int nfsm_strtmbuf __P((struct mbuf **, char **, const char *, long));
-int nfs_bioread __P((struct vnode *, struct uio *, int, struct ucred *));
-int nfsm_uiotombuf __P((struct uio *, struct mbuf **, int, caddr_t *));
-void nfsrv_init __P((int));
-void nfs_clearcommit __P((struct mount *));
-int nfsrv_errmap __P((struct nfsrv_descript *, int));
-void nfsrvw_sort __P((gid_t *, int));
-void nfsrv_setcred __P((struct ucred *, struct ucred *));
-int nfs_writebp __P((struct buf *, int, struct thread *));
-int nfsrv_object_create __P((struct vnode *));
-void nfsrv_wakenfsd __P((struct nfssvc_sock *slp));
-int nfsrv_writegather __P((struct nfsrv_descript **, struct nfssvc_sock *,
- struct thread *, struct mbuf **));
-int nfs_fsinfo __P((struct nfsmount *, struct vnode *, struct ucred *,
- struct thread *td));
-
-int nfsrv3_access __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_commit __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_create __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_fhtovp __P((fhandle_t *, int, struct vnode **, struct ucred *,
- struct nfssvc_sock *, struct sockaddr *, int *,
- int, int));
-int nfsrv_setpublicfs __P((struct mount *, struct netexport *,
- struct export_args *));
-int nfs_ispublicfh __P((fhandle_t *));
-int nfsrv_fsinfo __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_getattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_link __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_lookup __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_mkdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_mknod __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_noop __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_null __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_pathconf __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp, struct thread *td,
- struct mbuf **mrq));
-int nfsrv_read __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_readdir __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_readdirplus __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp, struct thread *td,
- struct mbuf **mrq));
-int nfsrv_readlink __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp, struct thread *td,
- struct mbuf **mrq));
-int nfsrv_remove __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_rename __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_rmdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_setattr __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_statfs __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_symlink __P((struct nfsrv_descript *nfsd,
- struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-int nfsrv_write __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
- struct thread *td, struct mbuf **mrq));
-void nfsrv_rcv __P((struct socket *so, void *arg, int waitflag));
-void nfsrv_slpderef __P((struct nfssvc_sock *slp));
-#endif /* _KERNEL */
-
#endif
OpenPOWER on IntegriCloud