1139823Simp/*-
21541Srgrimes * Copyright (c) 1989, 1993
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 *	@(#)nfsnode.h	8.9 (Berkeley) 5/14/95
3350477Speter * $FreeBSD$
341541Srgrimes */
351541Srgrimes
3683651Speter#ifndef _NFSCLIENT_NFSNODE_H_
3783651Speter#define _NFSCLIENT_NFSNODE_H_
3822521Sdyson
39224604Srmacklem#include <sys/_task.h>
4083651Speter#if !defined(_NFSCLIENT_NFS_H_) && !defined(_KERNEL)
419336Sdfr#include <nfs/nfs.h>
429336Sdfr#endif
439336Sdfr
441541Srgrimes/*
451541Srgrimes * Silly rename structure that hangs off the nfsnode until the name
461541Srgrimes * can be removed by nfs_inactive()
471541Srgrimes */
481541Srgrimesstruct sillyrename {
49224604Srmacklem	struct	task s_task;
501541Srgrimes	struct	ucred *s_cred;
511541Srgrimes	struct	vnode *s_dvp;
52122698Salfred	int	(*s_removeit)(struct sillyrename *sp);
531541Srgrimes	long	s_namlen;
54138919Sps	char	s_name[32];
551541Srgrimes};
561541Srgrimes
571541Srgrimes/*
589336Sdfr * This structure is used to save the logical directory offset to
599336Sdfr * NFS cookie mappings.
609336Sdfr * The mappings are stored in a list headed
619336Sdfr * by n_cookies, as required.
629336Sdfr * There is one mapping for each NFS_DIRBLKSIZ bytes of directory information
639336Sdfr * stored in increasing logical offset byte order.
649336Sdfr */
659336Sdfr#define NFSNUMCOOKIES		31
669336Sdfr
679336Sdfrstruct nfsdmap {
6860938Sjake	LIST_ENTRY(nfsdmap)	ndm_list;
699336Sdfr	int			ndm_eocookie;
70122698Salfred	union {
71122698Salfred		nfsuint64	ndmu3_cookies[NFSNUMCOOKIES];
72122698Salfred		uint64_t	ndmu4_cookies[NFSNUMCOOKIES];
73122698Salfred	} ndm_un1;
749336Sdfr};
759336Sdfr
76122698Salfred#define ndm_cookies	ndm_un1.ndmu3_cookies
77122698Salfred#define ndm4_cookies	ndm_un1.ndmu4_cookies
78122698Salfred
79190176Sjhbstruct nfs_accesscache {
80190176Sjhb	u_int32_t		mode;		/* ACCESS mode cache */
81190176Sjhb	uid_t			uid;		/* credentials having mode */
82190176Sjhb	time_t			stamp;		/* mode cache timestamp */
83190176Sjhb};
84190176Sjhb
859336Sdfr/*
861541Srgrimes * The nfsnode is the nfs equivalent to ufs's inode. Any similarity
871541Srgrimes * is purely coincidental.
881541Srgrimes * There is a unique nfsnode allocated for each active file,
891541Srgrimes * each current directory, each mounted-on file, text file, and the root.
901541Srgrimes * An nfsnode is 'named' by its file handle. (nget/nfs_node.c)
919336Sdfr * If this structure exceeds 256 bytes (it is currently 256 using 4.4BSD-Lite
929336Sdfr * type definitions), file handles of > 32 bytes should probably be split out
939336Sdfr * into a separate MALLOC()'d data structure. (Reduce the size of nfsfh_t by
9436526Speter * changing the definition in nfsproto.h of NFS_SMALLFH.)
959336Sdfr * NB: Hopefully the current order of the fields is such that everything will
969336Sdfr *     be well aligned and, therefore, tightly packed.
971541Srgrimes */
981541Srgrimesstruct nfsnode {
99158739Smohans	struct mtx 		n_mtx;		/* Protects all of these members */
1009336Sdfr	u_quad_t		n_size;		/* Current size of file */
1019336Sdfr	u_quad_t		n_brev;		/* Modify rev when cached */
1029336Sdfr	u_quad_t		n_lrev;		/* Modify rev for lease */
1039336Sdfr	struct vattr		n_vattr;	/* Vnode attribute cache */
1049336Sdfr	time_t			n_attrstamp;	/* Attr. cache timestamp */
105190176Sjhb	struct nfs_accesscache	n_accesscache[NFS_ACCESSCACHESIZE];
106138473Sps	struct timespec		n_mtime;	/* Prev modify time. */
107233285Sjhb	struct timespec		n_unused0;
108233285Sjhb	struct timespec		n_unused1;
109233285Sjhb	int			n_unused2;
1109336Sdfr	nfsfh_t			*n_fhp;		/* NFS File Handle */
1119336Sdfr	struct vnode		*n_vnode;	/* associated vnode */
112122698Salfred	struct vnode		*n_dvp;		/* parent vnode */
1139336Sdfr	int			n_error;	/* Save write error value */
1149336Sdfr	union {
1159336Sdfr		struct timespec	nf_atim;	/* Special file times */
1169336Sdfr		nfsuint64	nd_cookieverf;	/* Cookie verifier (dir only) */
117122698Salfred		u_char		nd4_cookieverf[NFSX_V4VERF];
1189336Sdfr	} n_un1;
1199336Sdfr	union {
1209336Sdfr		struct timespec	nf_mtim;
1219336Sdfr		off_t		nd_direof;	/* Dir. EOF offset cache */
1229336Sdfr	} n_un2;
1239336Sdfr	union {
1249336Sdfr		struct sillyrename *nf_silly;	/* Ptr to silly rename struct */
12560938Sjake		LIST_HEAD(, nfsdmap) nd_cook;	/* cookies */
1269336Sdfr	} n_un3;
1279336Sdfr	short			n_fhsize;	/* size in bytes, of fh */
1289336Sdfr	short			n_flag;		/* Flag for locking.. */
1299336Sdfr	nfsfh_t			n_fh;		/* Small File Handle */
130122953Salfred	u_char			*n_name;	/* leaf name, for v4 OPEN op */
131122698Salfred	uint32_t		n_namelen;
132138899Sps	int			n_directio_opens;
133158739Smohans	int                     n_directio_asyncwr;
134236096Srmacklem	struct ucred		*n_writecred;	/* Cred. for putpages */
1351541Srgrimes};
1361541Srgrimes
1379336Sdfr#define n_atim		n_un1.nf_atim
1389336Sdfr#define n_mtim		n_un2.nf_mtim
1399336Sdfr#define n_sillyrename	n_un3.nf_silly
1409336Sdfr#define n_cookieverf	n_un1.nd_cookieverf
141122698Salfred#define n4_cookieverf	n_un1.nd4_cookieverf
1429336Sdfr#define n_direofoffset	n_un2.nd_direof
1439336Sdfr#define n_cookies	n_un3.nd_cook
1449336Sdfr
1451541Srgrimes/*
1461541Srgrimes * Flags for n_flag
1471541Srgrimes */
148158739Smohans#define NFSYNCWAIT      0x0002  /* fsync waiting for all directio async writes
149158739Smohans				  to drain */
1501541Srgrimes#define	NMODIFIED	0x0004	/* Might have a modified buffer in bio */
1511541Srgrimes#define	NWRITEERR	0x0008	/* Flag write errors so close will know */
15283651Speter/* 0x20, 0x40, 0x80 free */
1531541Srgrimes#define	NACC		0x0100	/* Special file accessed */
1541541Srgrimes#define	NUPD		0x0200	/* Special file updated */
1551541Srgrimes#define	NCHG		0x0400	/* Special file times changed */
156122698Salfred#define	NCREATED	0x0800	/* Opened by nfs_create() */
157122698Salfred#define	NTRUNCATE	0x1000	/* Opened by nfs_setattr() */
158128263Speadar#define	NSIZECHANGED	0x2000  /* File size has changed: need cache inval */
159138899Sps#define NNONCACHE	0x4000  /* Node marked as noncacheable */
160158739Smohans#define NDIRCOOKIELK	0x8000	/* Lock to serialize access to directory cookies */
1611541Srgrimes
1621541Srgrimes/*
1631541Srgrimes * Convert between nfsnode pointers and vnode pointers
1641541Srgrimes */
1651541Srgrimes#define VTONFS(vp)	((struct nfsnode *)(vp)->v_data)
1661541Srgrimes#define NFSTOV(np)	((struct vnode *)(np)->n_vnode)
1671541Srgrimes
168138473Sps#define NFS_TIMESPEC_COMPARE(T1, T2)	(((T1)->tv_sec != (T2)->tv_sec) || ((T1)->tv_nsec != (T2)->tv_nsec))
169138473Sps
1701541Srgrimes/*
171214026Skib * NFS iod threads can be in one of these two states once spawned.
172203072Srmacklem * NFSIOD_NOT_AVAILABLE - Cannot be assigned an I/O operation at this time.
173203072Srmacklem * NFSIOD_AVAILABLE - Available to be assigned an I/O operation.
174203072Srmacklem */
175203072Srmacklemenum nfsiod_state {
176203072Srmacklem	NFSIOD_NOT_AVAILABLE = 0,
177203072Srmacklem	NFSIOD_AVAILABLE = 1,
178203072Srmacklem};
179203072Srmacklem
180203072Srmacklem/*
1811541Srgrimes * Queue head for nfsiod's
1821541Srgrimes */
18360938Sjakeextern TAILQ_HEAD(nfs_bufq, buf) nfs_bufq;
184203072Srmacklemextern enum nfsiod_state nfs_iodwant[NFS_MAXASYNCDAEMON];
18519449Sdfrextern struct nfsmount *nfs_iodmount[NFS_MAXASYNCDAEMON];
1861541Srgrimes
18755206Speter#if defined(_KERNEL)
18854605Sdillon
189138290Sphkextern	struct vop_vector	nfs_fifoops;
190138290Sphkextern	struct vop_vector	nfs_vnodeops;
191136927Sphkextern struct buf_ops buf_ops_nfs;
192122698Salfred
1931541Srgrimes/*
1941541Srgrimes * Prototypes for NFS vnode operations
1951541Srgrimes */
19683651Speterint	nfs_getpages(struct vop_getpages_args *);
19783651Speterint	nfs_putpages(struct vop_putpages_args *);
19883651Speterint	nfs_write(struct vop_write_args *);
19983651Speterint	nfs_inactive(struct vop_inactive_args *);
20083651Speterint	nfs_reclaim(struct vop_reclaim_args *);
2013305Sphk
2023305Sphk/* other stuff */
20383651Speterint	nfs_removeit(struct sillyrename *);
204162288Smohansint	nfs_nget(struct mount *, nfsfh_t *, int, struct nfsnode **, int flags);
20583651Speternfsuint64 *nfs_getcookie(struct nfsnode *, off_t, int);
20683651Spetervoid	nfs_invaldir(struct vnode *);
207176134Sattilioint	nfs_upgrade_vnlock(struct vnode *vp);
208176134Sattiliovoid	nfs_downgrade_vnlock(struct vnode *vp, int old_lock);
209158739Smohansvoid	nfs_printf(const char *fmt, ...);
2103305Sphk
211158739Smohansvoid nfs_dircookie_lock(struct nfsnode *np);
212158739Smohansvoid nfs_dircookie_unlock(struct nfsnode *np);
213158739Smohans
21455206Speter#endif /* _KERNEL */
2152175Spaul
2162175Spaul#endif
217