xref: /netbsd-src/sys/fs/nfs/client/nfsnode.h (revision 3be2222bbe56192eb75b39905cef98ac451a3d70)
1*3be2222bSpgoyette /*	$NetBSD: nfsnode.h,v 1.3 2016/12/13 22:17:33 pgoyette Exp $	*/
26ca35587Sdholland /*-
36ca35587Sdholland  * Copyright (c) 1989, 1993
46ca35587Sdholland  *	The Regents of the University of California.  All rights reserved.
56ca35587Sdholland  *
66ca35587Sdholland  * This code is derived from software contributed to Berkeley by
76ca35587Sdholland  * Rick Macklem at The University of Guelph.
86ca35587Sdholland  *
96ca35587Sdholland  * Redistribution and use in source and binary forms, with or without
106ca35587Sdholland  * modification, are permitted provided that the following conditions
116ca35587Sdholland  * are met:
126ca35587Sdholland  * 1. Redistributions of source code must retain the above copyright
136ca35587Sdholland  *    notice, this list of conditions and the following disclaimer.
146ca35587Sdholland  * 2. Redistributions in binary form must reproduce the above copyright
156ca35587Sdholland  *    notice, this list of conditions and the following disclaimer in the
166ca35587Sdholland  *    documentation and/or other materials provided with the distribution.
176ca35587Sdholland  * 4. Neither the name of the University nor the names of its contributors
186ca35587Sdholland  *    may be used to endorse or promote products derived from this software
196ca35587Sdholland  *    without specific prior written permission.
206ca35587Sdholland  *
216ca35587Sdholland  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
226ca35587Sdholland  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
236ca35587Sdholland  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
246ca35587Sdholland  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
256ca35587Sdholland  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
266ca35587Sdholland  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
276ca35587Sdholland  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
286ca35587Sdholland  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
296ca35587Sdholland  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
306ca35587Sdholland  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
316ca35587Sdholland  * SUCH DAMAGE.
326ca35587Sdholland  *
33e81f0ea2Spgoyette  * FreeBSD: head/sys/fs/nfsclient/nfsnode.h 303715 2016-08-03 15:58:20Z kib
34*3be2222bSpgoyette  * $NetBSD: nfsnode.h,v 1.3 2016/12/13 22:17:33 pgoyette Exp $
356ca35587Sdholland  */
366ca35587Sdholland 
376ca35587Sdholland #ifndef _NFSCLIENT_NFSNODE_H_
386ca35587Sdholland #define	_NFSCLIENT_NFSNODE_H_
396ca35587Sdholland 
406ca35587Sdholland /*
416ca35587Sdholland  * Silly rename structure that hangs off the nfsnode until the name
426ca35587Sdholland  * can be removed by nfs_inactive()
436ca35587Sdholland  */
446ca35587Sdholland struct sillyrename {
456ca35587Sdholland 	struct	ucred *s_cred;
466ca35587Sdholland 	struct	vnode *s_dvp;
476ca35587Sdholland 	long	s_namlen;
486ca35587Sdholland 	char	s_name[32];
496ca35587Sdholland };
506ca35587Sdholland 
516ca35587Sdholland /*
526ca35587Sdholland  * This structure is used to save the logical directory offset to
536ca35587Sdholland  * NFS cookie mappings.
546ca35587Sdholland  * The mappings are stored in a list headed
556ca35587Sdholland  * by n_cookies, as required.
566ca35587Sdholland  * There is one mapping for each NFS_DIRBLKSIZ bytes of directory information
576ca35587Sdholland  * stored in increasing logical offset byte order.
586ca35587Sdholland  */
596ca35587Sdholland #define	NFSNUMCOOKIES		31
606ca35587Sdholland 
616ca35587Sdholland struct nfsdmap {
626ca35587Sdholland 	LIST_ENTRY(nfsdmap)	ndm_list;
636ca35587Sdholland 	int			ndm_eocookie;
646ca35587Sdholland 	union {
656ca35587Sdholland 		nfsuint64	ndmu3_cookies[NFSNUMCOOKIES];
666ca35587Sdholland 		uint64_t	ndmu4_cookies[NFSNUMCOOKIES];
676ca35587Sdholland 	} ndm_un1;
686ca35587Sdholland };
696ca35587Sdholland 
706ca35587Sdholland #define	ndm_cookies	ndm_un1.ndmu3_cookies
716ca35587Sdholland #define	ndm4_cookies	ndm_un1.ndmu4_cookies
726ca35587Sdholland 
736ca35587Sdholland struct nfs_accesscache {
746ca35587Sdholland 	u_int32_t		mode;	/* ACCESS mode cache */
756ca35587Sdholland 	uid_t			uid;	/* credentials having mode */
766ca35587Sdholland 	time_t			stamp;	/* mode cache timestamp */
776ca35587Sdholland };
786ca35587Sdholland 
796ca35587Sdholland /*
806ca35587Sdholland  * The nfsnode is the nfs equivalent to ufs's inode. Any similarity
816ca35587Sdholland  * is purely coincidental.
826ca35587Sdholland  * There is a unique nfsnode allocated for each active file,
836ca35587Sdholland  * each current directory, each mounted-on file, text file, and the root.
846ca35587Sdholland  * An nfsnode is 'named' by its file handle. (nget/nfs_node.c)
856ca35587Sdholland  * If this structure exceeds 256 bytes (it is currently 256 using 4.4BSD-Lite
866ca35587Sdholland  * type definitions), file handles of > 32 bytes should probably be split out
876ca35587Sdholland  * into a separate MALLOC()'d data structure. (Reduce the size of nfsfh_t by
886ca35587Sdholland  * changing the definition in nfsproto.h of NFS_SMALLFH.)
896ca35587Sdholland  * NB: Hopefully the current order of the fields is such that everything will
906ca35587Sdholland  *     be well aligned and, therefore, tightly packed.
916ca35587Sdholland  */
926ca35587Sdholland struct nfsnode {
93*3be2222bSpgoyette 	kmutex_t 		n_mtx;		/* Protects all of these members */
946ca35587Sdholland 	u_quad_t		n_size;		/* Current size of file */
956ca35587Sdholland 	u_quad_t		n_brev;		/* Modify rev when cached */
966ca35587Sdholland 	u_quad_t		n_lrev;		/* Modify rev for lease */
976ca35587Sdholland 	struct nfsvattr		n_vattr;	/* Vnode attribute cache */
986ca35587Sdholland 	time_t			n_attrstamp;	/* Attr. cache timestamp */
996ca35587Sdholland 	struct nfs_accesscache	n_accesscache[NFS_ACCESSCACHESIZE];
1006ca35587Sdholland 	struct timespec		n_mtime;	/* Prev modify time. */
1016ca35587Sdholland 	struct nfsfh		*n_fhp;		/* NFS File Handle */
1026ca35587Sdholland 	struct vnode		*n_vnode;	/* associated vnode */
1036ca35587Sdholland 	struct vnode		*n_dvp;		/* parent vnode */
1046ca35587Sdholland 	struct lockf		*n_lockf;	/* Locking record of file */
1056ca35587Sdholland 	int			n_error;	/* Save write error value */
1066ca35587Sdholland 	union {
1076ca35587Sdholland 		struct timespec	nf_atim;	/* Special file times */
1086ca35587Sdholland 		nfsuint64	nd_cookieverf;	/* Cookie verifier (dir only) */
1096ca35587Sdholland 		u_char		nd4_cookieverf[NFSX_VERF];
1106ca35587Sdholland 	} n_un1;
1116ca35587Sdholland 	union {
1126ca35587Sdholland 		struct timespec	nf_mtim;
1136ca35587Sdholland 		off_t		nd_direof;	/* Dir. EOF offset cache */
1146ca35587Sdholland 	} n_un2;
1156ca35587Sdholland 	union {
1166ca35587Sdholland 		struct sillyrename *nf_silly;	/* Ptr to silly rename struct */
1176ca35587Sdholland 		LIST_HEAD(, nfsdmap) nd_cook;	/* cookies */
1186ca35587Sdholland 	} n_un3;
1196ca35587Sdholland 	short			n_fhsize;	/* size in bytes, of fh */
1206ca35587Sdholland 	u_int32_t		n_flag;		/* Flag for locking.. */
1216ca35587Sdholland 	int			n_directio_opens;
1226ca35587Sdholland 	int                     n_directio_asyncwr;
1236ca35587Sdholland 	u_int64_t		 n_change;	/* old Change attribute */
1246ca35587Sdholland 	struct nfsv4node	*n_v4;		/* extra V4 stuff */
1256ca35587Sdholland 	struct ucred		*n_writecred;	/* Cred. for putpages */
1266ca35587Sdholland };
1276ca35587Sdholland 
1286ca35587Sdholland #define	n_atim		n_un1.nf_atim
1296ca35587Sdholland #define	n_mtim		n_un2.nf_mtim
1306ca35587Sdholland #define	n_sillyrename	n_un3.nf_silly
1316ca35587Sdholland #define	n_cookieverf	n_un1.nd_cookieverf
1326ca35587Sdholland #define	n4_cookieverf	n_un1.nd4_cookieverf
1336ca35587Sdholland #define	n_direofoffset	n_un2.nd_direof
1346ca35587Sdholland #define	n_cookies	n_un3.nd_cook
1356ca35587Sdholland 
1366ca35587Sdholland /*
1376ca35587Sdholland  * Flags for n_flag
1386ca35587Sdholland  */
1396ca35587Sdholland #define	NDIRCOOKIELK	0x00000001  /* Lock to serialize access to directory cookies */
1406ca35587Sdholland #define	NFSYNCWAIT      0x00000002  /* fsync waiting for all directio async
1416ca35587Sdholland 				  writes to drain */
1426ca35587Sdholland #define	NMODIFIED	0x00000004  /* Might have a modified buffer in bio */
1436ca35587Sdholland #define	NWRITEERR	0x00000008  /* Flag write errors so close will know */
1446ca35587Sdholland #define	NCREATED	0x00000010  /* Opened by nfs_create() */
1456ca35587Sdholland #define	NTRUNCATE	0x00000020  /* Opened by nfs_setattr() */
1466ca35587Sdholland #define	NSIZECHANGED	0x00000040  /* File size has changed: need cache inval */
1476ca35587Sdholland #define	NNONCACHE	0x00000080  /* Node marked as noncacheable */
1486ca35587Sdholland #define	NACC		0x00000100  /* Special file accessed */
1496ca35587Sdholland #define	NUPD		0x00000200  /* Special file updated */
1506ca35587Sdholland #define	NCHG		0x00000400  /* Special file times changed */
1516ca35587Sdholland #define	NDELEGMOD	0x00000800  /* Modified delegation */
1526ca35587Sdholland #define	NDELEGRECALL	0x00001000  /* Recall in progress */
1536ca35587Sdholland #define	NREMOVEINPROG	0x00002000  /* Remove in progress */
1546ca35587Sdholland #define	NREMOVEWANT	0x00004000  /* Want notification that remove is done */
1556ca35587Sdholland #define	NLOCK		0x00008000  /* Sleep lock the node */
1566ca35587Sdholland #define	NLOCKWANT	0x00010000  /* Want the sleep lock */
1576ca35587Sdholland #define	NNOLAYOUT	0x00020000  /* Can't get a layout for this file */
1586ca35587Sdholland #define	NWRITEOPENED	0x00040000  /* Has been opened for writing */
159e81f0ea2Spgoyette #define	NHASBEENLOCKED	0x00080000  /* Has been file locked. */
1606ca35587Sdholland 
1616ca35587Sdholland /*
1626ca35587Sdholland  * Convert between nfsnode pointers and vnode pointers
1636ca35587Sdholland  */
1646ca35587Sdholland #define	VTONFS(vp)	((struct nfsnode *)(vp)->v_data)
1656ca35587Sdholland #define	NFSTOV(np)	((struct vnode *)(np)->n_vnode)
1666ca35587Sdholland 
1676ca35587Sdholland #define	NFS_TIMESPEC_COMPARE(T1, T2)	(((T1)->tv_sec != (T2)->tv_sec) || ((T1)->tv_nsec != (T2)->tv_nsec))
1686ca35587Sdholland 
1696ca35587Sdholland #if defined(_KERNEL)
1706ca35587Sdholland 
1716ca35587Sdholland /*
1726ca35587Sdholland  * Prototypes for NFS vnode operations
1736ca35587Sdholland  */
1746ca35587Sdholland int	ncl_getpages(struct vop_getpages_args *);
1756ca35587Sdholland int	ncl_putpages(struct vop_putpages_args *);
1766ca35587Sdholland int	ncl_write(struct vop_write_args *);
1776ca35587Sdholland int	ncl_inactive(struct vop_inactive_args *);
1786ca35587Sdholland int	ncl_reclaim(struct vop_reclaim_args *);
1796ca35587Sdholland 
1806ca35587Sdholland /* other stuff */
1816ca35587Sdholland int	ncl_removeit(struct sillyrename *, struct vnode *);
1826ca35587Sdholland int	ncl_nget(struct mount *, u_int8_t *, int, struct nfsnode **, int);
1836ca35587Sdholland nfsuint64 *ncl_getcookie(struct nfsnode *, off_t, int);
1846ca35587Sdholland void	ncl_invaldir(struct vnode *);
1856ca35587Sdholland int	ncl_upgrade_vnlock(struct vnode *);
1866ca35587Sdholland void	ncl_downgrade_vnlock(struct vnode *, int);
1876ca35587Sdholland void	ncl_dircookie_lock(struct nfsnode *);
1886ca35587Sdholland void	ncl_dircookie_unlock(struct nfsnode *);
1896ca35587Sdholland 
1906ca35587Sdholland #endif /* _KERNEL */
1916ca35587Sdholland 
1926ca35587Sdholland #endif	/* _NFSCLIENT_NFSNODE_H_ */
193