1139823Simp/*-
222521Sdyson * Copyright (c) 1989, 1993, 1995
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * This code is derived from software contributed to Berkeley by
61541Srgrimes * Rick Macklem at The University of Guelph.
71541Srgrimes *
81541Srgrimes * Redistribution and use in source and binary forms, with or without
91541Srgrimes * modification, are permitted provided that the following conditions
101541Srgrimes * are met:
111541Srgrimes * 1. Redistributions of source code must retain the above copyright
121541Srgrimes *    notice, this list of conditions and the following disclaimer.
131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141541Srgrimes *    notice, this list of conditions and the following disclaimer in the
151541Srgrimes *    documentation and/or other materials provided with the distribution.
161541Srgrimes * 4. Neither the name of the University nor the names of its contributors
171541Srgrimes *    may be used to endorse or promote products derived from this software
181541Srgrimes *    without specific prior written permission.
191541Srgrimes *
201541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301541Srgrimes * SUCH DAMAGE.
311541Srgrimes *
3222521Sdyson *	@(#)nfs.h	8.4 (Berkeley) 5/1/95
3350477Speter * $FreeBSD$
341541Srgrimes */
351541Srgrimes
3683651Speter#ifndef _NFSCLIENT_NFS_H_
3783651Speter#define _NFSCLIENT_NFS_H_
382175Spaul
3955206Speter#ifdef _KERNEL
4037272Sjmg#include "opt_nfs.h"
4137291Sjmg#endif
4237272Sjmg
4383651Speter#include <nfsclient/nfsargs.h>
4483651Speter
451541Srgrimes/*
461541Srgrimes * Tunable constants for nfs
471541Srgrimes */
481541Srgrimes
49126962Speter#define NFS_TICKINTVL	10		/* Desired time for a tick (msec) */
509336Sdfr#define NFS_HZ		(hz / nfs_ticks) /* Ticks/sec */
519336Sdfr#define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
529336Sdfr#define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
539336Sdfr#define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
549336Sdfr#define	NFS_MINIDEMTIMEO (5 * NFS_HZ)	/* Min timeout for non-idempotent ops*/
551541Srgrimes#define	NFS_MAXREXMIT	100		/* Stop counting after this many */
56158860Scel#define	NFS_RETRANS	10		/* Num of retrans for UDP soft mounts */
57158860Scel#define	NFS_RETRANS_TCP	2		/* Num of retrans for TCP soft mounts */
581541Srgrimes#define	NFS_MAXGRPS	16		/* Max. size of groups list */
591828Sdg#ifndef NFS_MINATTRTIMO
6036176Speter#define	NFS_MINATTRTIMO 3		/* VREG attrib cache timeout in sec */
611828Sdg#endif
621828Sdg#ifndef NFS_MAXATTRTIMO
631541Srgrimes#define	NFS_MAXATTRTIMO 60
641828Sdg#endif
6536176Speter#ifndef NFS_MINDIRATTRTIMO
66190783Sjhb#define	NFS_MINDIRATTRTIMO 3		/* VDIR attrib cache timeout in sec */
6736176Speter#endif
6836176Speter#ifndef NFS_MAXDIRATTRTIMO
6936176Speter#define	NFS_MAXDIRATTRTIMO 60
7036176Speter#endif
71190176Sjhb#ifndef	NFS_ACCESSCACHESIZE
72190176Sjhb#define	NFS_ACCESSCACHESIZE 8		/* Per-node access cache entries */
73190176Sjhb#endif
741541Srgrimes#define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
751541Srgrimes#define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
769336Sdfr#define NFS_READDIRSIZE	8192		/* Def. readdir size */
771541Srgrimes#define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
781541Srgrimes#define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
7989407Speter#define	NFS_MAXASYNCDAEMON 	64	/* Max. number async_daemons runnable */
809336Sdfr#define	NFS_DIRBLKSIZ	4096		/* Must be a multiple of DIRBLKSIZ */
8155206Speter#ifdef _KERNEL
8224378Sbde#define	DIRBLKSIZ	512		/* XXX we used to use ufs's DIRBLKSIZ */
8324378Sbde#endif
8483651Speter#define NFS_MAXDEADTHRESH	9	/* How long till we say 'server not responding' */
859336Sdfr
869336Sdfr/*
879336Sdfr * Oddballs
889336Sdfr */
899336Sdfr#define NFS_CMPFH(n, f, s) \
909336Sdfr	((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
919336Sdfr#define NFS_ISV3(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
92158905Smohans#define NFS_ISV4(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV4)
931541Srgrimes
9436176Speter#define NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier for V3 */
9536176Speter#define NFSSTA_GOTFSINFO	0x00100000  /* Got the V3 fsinfo */
9636176Speter#define	NFSSTA_SNDLOCK		0x01000000  /* Send socket lock */
9736176Speter#define	NFSSTA_WANTSND		0x02000000  /* Want above */
98131691Salfred#define	NFSSTA_TIMEO		0x10000000  /* Experiencing a timeout */
99180025Sdfr#define	NFSSTA_LOCKTIMEO	0x20000000  /* Experiencing a lockd timeout */
10036176Speter
101131691Salfred
10222521Sdyson/*
10322521Sdyson * XXX to allow amd to include nfs.h without nfsproto.h
10422521Sdyson */
10522521Sdyson#ifdef NFS_NPROCS
10683651Speter#include <nfsclient/nfsstats.h>
10722521Sdyson#endif
1081541Srgrimes
1091541Srgrimes/*
110221986Srmacklem * vfs.oldnfs sysctl(3) identifiers
1113820Swollman */
1123820Swollman#define NFS_NFSSTATS	1		/* struct: struct nfsstats */
1133820Swollman
11455206Speter#ifdef _KERNEL
1154067Swollman
11630354Sphk#ifdef MALLOC_DECLARE
11730354SphkMALLOC_DECLARE(M_NFSREQ);
11830354SphkMALLOC_DECLARE(M_NFSDIROFF);
11930354SphkMALLOC_DECLARE(M_NFSBIGFH);
12036329SpeterMALLOC_DECLARE(M_NFSHASH);
121138899SpsMALLOC_DECLARE(M_NFSDIRECTIO);
12230354Sphk#endif
12330354Sphk
124102966Sbdeextern struct uma_zone *nfsmount_zone;
12536329Speter
12683651Speterextern struct nfsstats nfsstats;
127158739Smohansextern struct mtx nfs_iod_mtx;
128212506Skibextern struct task nfs_nfsiodnew_task;
12938894Sbde
13083651Speterextern int nfs_numasync;
131128111Speadarextern unsigned int nfs_iodmax;
13283651Speterextern int nfs_pbuf_freecnt;
13383651Speterextern int nfs_ticks;
1344067Swollman
13583651Speter/* Data constants in XDR form */
13683651Speterextern u_int32_t nfs_true, nfs_false, nfs_xdrneg1;
13783651Speterextern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers;
13883651Speterextern u_int32_t rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr;
13983651Speter
14083651Speterextern int nfsv3_procid[NFS_NPROCS];
14183651Speter
14232998Sbde/*
1431541Srgrimes * Socket errors ignored for connectionless sockets??
1441541Srgrimes * For now, ignore them all
1451541Srgrimes */
1461541Srgrimes#define	NFSIGNORE_SOERROR(s, e) \
147131691Salfred		((e) != EINTR && (e) != EIO && \
148163471Sbde		(e) != ERESTART && (e) != EWOULDBLOCK && \
1491541Srgrimes		((s) & PR_CONNREQUIRED) == 0)
1501541Srgrimes
151184588Sdfrstruct nfsmount;
152184588Sdfr
153163471Sbdestruct buf;
154163471Sbdestruct socket;
155163471Sbdestruct uio;
156163471Sbdestruct vattr;
157163471Sbde
15836503Speter/*
159122953Salfred * Pointers to ops that differ from v3 to v4
160122953Salfred */
161122953Salfredstruct nfs_rpcops {
162163471Sbde	int	(*nr_readrpc)(struct vnode *vp, struct uio *uiop,
163163471Sbde		    struct ucred *cred);
164163471Sbde	int	(*nr_writerpc)(struct vnode *vp, struct uio *uiop,
165163471Sbde		    struct ucred *cred, int *iomode, int *must_commit);
166122953Salfred	int	(*nr_writebp)(struct buf *bp, int force, struct thread *td);
167163471Sbde	int	(*nr_readlinkrpc)(struct vnode *vp, struct uio *uiop,
168163471Sbde		    struct ucred *cred);
169122953Salfred	void	(*nr_invaldir)(struct vnode *vp);
170122953Salfred	int	(*nr_commit)(struct vnode *vp, u_quad_t offset, int cnt,
171163471Sbde		    struct ucred *cred, struct thread *td);
172122953Salfred};
173122953Salfred
174122953Salfred/*
17527446Sdfr * Defines for WebNFS
17627446Sdfr */
17727446Sdfr
17827446Sdfr#define WEBNFS_ESC_CHAR		'%'
17927446Sdfr#define WEBNFS_SPECCHAR_START	0x80
18027446Sdfr
18127446Sdfr#define WEBNFS_NATIVE_CHAR	0x80
18227446Sdfr/*
18327446Sdfr * ..
18427446Sdfr * Possibly more here in the future.
18527446Sdfr */
18627446Sdfr
18727446Sdfr/*
18827446Sdfr * Macro for converting escape characters in WebNFS pathnames.
18927446Sdfr * Should really be in libkern.
19027446Sdfr */
19127446Sdfr
19227446Sdfr#define HEXTOC(c) \
19327446Sdfr	((c) >= 'a' ? ((c) - ('a' - 10)) : \
19427446Sdfr	    ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
19527446Sdfr#define HEXSTRTOI(p) \
19627446Sdfr	((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
19727446Sdfr
198131691Salfred/* nfs_sigintr() helper, when 'rep' has all we need */
199131691Salfred#define NFS_SIGREP(rep)		nfs_sigintr((rep)->r_nmp, (rep), (rep)->r_td)
200131691Salfred
20125663Sdfr#ifdef NFS_DEBUG
20222521Sdyson
20325663Sdfrextern int nfs_debug;
20425663Sdfr#define NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
20525663Sdfr#define NFS_DEBUG_WG		2 /* server write gathering */
20625663Sdfr#define NFS_DEBUG_RC		4 /* server request caching */
20725663Sdfr
20825663Sdfr#define NFS_DPF(cat, args)					\
20925663Sdfr	do {							\
21025663Sdfr		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
21125663Sdfr	} while (0)
21225663Sdfr
21325663Sdfr#else
21425663Sdfr
21525663Sdfr#define NFS_DPF(cat, args)
21625663Sdfr
21725663Sdfr#endif
21825663Sdfr
219158859Scel/*
220158859Scel * On fast networks, the estimator will try to reduce the
221158859Scel * timeout lower than the latency of the server's disks,
222158859Scel * which results in too many timeouts, so cap the lower
223158859Scel * bound.
224158859Scel */
225158859Scel#define NFS_MINRTO	(NFS_HZ >> 2)
226158859Scel
227158859Scel/*
228158859Scel * Keep the RTO from increasing to unreasonably large values
229158859Scel * when a server is not responding.
230158859Scel */
231158859Scel#define NFS_MAXRTO	(20 * NFS_HZ)
232158859Scel
233158859Scelenum nfs_rto_timer_t {
234158859Scel	NFS_DEFAULT_TIMER,
235158859Scel	NFS_GETATTR_TIMER,
236158859Scel	NFS_LOOKUP_TIMER,
237158859Scel	NFS_READ_TIMER,
238158859Scel	NFS_WRITE_TIMER,
239158859Scel};
240158859Scel#define NFS_MAX_TIMER	(NFS_WRITE_TIMER)
241158859Scel
242158859Scel#define NFS_INITRTT	(NFS_HZ << 3)
243158859Scel
244101777Sphkvfs_init_t nfs_init;
245101777Sphkvfs_uninit_t nfs_uninit;
246191990Sattilioint	nfs_mountroot(struct mount *mp);
247122698Salfred
248190785Sjhbvoid	nfs_purgecache(struct vnode *);
249140731Sphkint	nfs_vinvalbuf(struct vnode *, int, struct thread *, int);
25083651Speterint	nfs_readrpc(struct vnode *, struct uio *, struct ucred *);
25183651Speterint	nfs_writerpc(struct vnode *, struct uio *, struct ucred *, int *,
25283651Speter	    int *);
25383651Speterint	nfs_commit(struct vnode *vp, u_quad_t offset, int cnt,
25483651Speter	    struct ucred *cred, struct thread *td);
25583651Speterint	nfs_readdirrpc(struct vnode *, struct uio *, struct ucred *);
256214026Skibvoid	nfs_nfsiodnew(void);
257212506Skibvoid	nfs_nfsiodnew_tq(__unused void *, int);
258134898Sphkint	nfs_asyncio(struct nfsmount *, struct buf *, struct ucred *, struct thread *);
259135860Sphkint	nfs_doio(struct vnode *, struct buf *, struct ucred *, struct thread *);
260163471Sbdevoid	nfs_doio_directwrite (struct buf *);
26183651Speterint	nfs_readlinkrpc(struct vnode *, struct uio *, struct ucred *);
262195203Sdfrint	nfs_sigintr(struct nfsmount *, struct thread *);
26383651Speterint	nfs_readdirplusrpc(struct vnode *, struct uio *, struct ucred *);
26483651Speterint	nfs_request(struct vnode *, struct mbuf *, int, struct thread *,
26583651Speter	    struct ucred *, struct mbuf **, struct mbuf **, caddr_t *);
26683651Speterint	nfs_loadattrcache(struct vnode **, struct mbuf **, caddr_t *,
26783651Speter	    struct vattr *, int);
26883651Speterint	nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *);
26983651Spetervoid	nfs_nhinit(void);
270128111Speadarvoid	nfs_nhuninit(void);
27188796Siedowseint	nfs_nmcancelreqs(struct nfsmount *);
27283651Spetervoid	nfs_timer(void*);
273122698Salfred
274195203Sdfrint	nfs_connect(struct nfsmount *);
27583651Spetervoid	nfs_disconnect(struct nfsmount *);
27683651Spetervoid	nfs_safedisconnect(struct nfsmount *);
27783651Speterint	nfs_getattrcache(struct vnode *, struct vattr *);
278166218Sbdeint	nfs_iosize(struct nfsmount *nmp);
27983651Speterint	nfsm_strtmbuf(struct mbuf **, char **, const char *, long);
28083651Speterint	nfs_bioread(struct vnode *, struct uio *, int, struct ucred *);
28183651Speterint	nfsm_uiotombuf(struct uio *, struct mbuf **, int, caddr_t *);
28283651Spetervoid	nfs_clearcommit(struct mount *);
28383651Speterint	nfs_writebp(struct buf *, int, struct thread *);
28483651Speterint	nfs_fsinfo(struct nfsmount *, struct vnode *, struct ucred *,
28583651Speter	    struct thread *);
28687834Sdillonint	nfs_meta_setsize (struct vnode *, struct ucred *,
28787834Sdillon	    struct thread *, u_quad_t);
2886361Sphk
289163471Sbdevoid	nfs_set_sigmask(struct thread *td, sigset_t *oldset);
290163471Sbdevoid	nfs_restore_sigmask(struct thread *td, sigset_t *set);
291163471Sbdeint	nfs_msleep(struct thread *td, void *ident, struct mtx *mtx,
292163471Sbde	    int priority, char *wmesg, int timo);
293138496Sps
29455206Speter#endif	/* _KERNEL */
2952175Spaul
2962175Spaul#endif
297