11558Srgrimes/*- 21558Srgrimes * Copyright (c) 1989, 1993 31558Srgrimes * The Regents of the University of California. All rights reserved. 41558Srgrimes * 51558Srgrimes * This code is derived from software contributed to Berkeley by 61558Srgrimes * Rick Macklem at The University of Guelph. 71558Srgrimes * 81558Srgrimes * Redistribution and use in source and binary forms, with or without 91558Srgrimes * modification, are permitted provided that the following conditions 101558Srgrimes * are met: 111558Srgrimes * 1. Redistributions of source code must retain the above copyright 121558Srgrimes * notice, this list of conditions and the following disclaimer. 131558Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141558Srgrimes * notice, this list of conditions and the following disclaimer in the 151558Srgrimes * documentation and/or other materials provided with the distribution. 161558Srgrimes * 4. Neither the name of the University nor the names of its contributors 171558Srgrimes * may be used to endorse or promote products derived from this software 181558Srgrimes * without specific prior written permission. 191558Srgrimes * 201558Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 211558Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 221558Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 231558Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 241558Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 251558Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 261558Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 271558Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 281558Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 291558Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 301558Srgrimes * SUCH DAMAGE. 311558Srgrimes * 321558Srgrimes * @(#)nfsnode.h 8.9 (Berkeley) 5/14/95 331558Srgrimes * $FreeBSD$ 341558Srgrimes */ 3541477Sjulian 3623675Speter#ifndef _NFSCLIENT_NFSNODE_H_ 3741477Sjulian#define _NFSCLIENT_NFSNODE_H_ 3841477Sjulian 3950476Speter#include <sys/_task.h> 401558Srgrimes#if !defined(_NFSCLIENT_NFS_H_) && !defined(_KERNEL) 411558Srgrimes#include <nfs/nfs.h> 421558Srgrimes#endif 4341474Sjulian 4474556Smckusick/* 4523675Speter * Silly rename structure that hangs off the nfsnode until the name 461558Srgrimes * can be removed by nfs_inactive() 471558Srgrimes */ 481558Srgrimesstruct sillyrename { 4923796Sbde struct task s_task; 5023675Speter struct ucred *s_cred; 511558Srgrimes struct vnode *s_dvp; 5223675Speter int (*s_removeit)(struct sillyrename *sp); 531558Srgrimes long s_namlen; 541558Srgrimes char s_name[32]; 551558Srgrimes}; 561558Srgrimes 5774556Smckusick/* 5874556Smckusick * This structure is used to save the logical directory offset to 5974556Smckusick * NFS cookie mappings. 6074556Smckusick * The mappings are stored in a list headed 611558Srgrimes * by n_cookies, as required. 621558Srgrimes * There is one mapping for each NFS_DIRBLKSIZ bytes of directory information 631558Srgrimes * stored in increasing logical offset byte order. 641558Srgrimes */ 651558Srgrimes#define NFSNUMCOOKIES 31 661558Srgrimes 671558Srgrimesstruct nfsdmap { 681558Srgrimes LIST_ENTRY(nfsdmap) ndm_list; 691558Srgrimes int ndm_eocookie; 7092839Simp union { 7192839Simp nfsuint64 ndmu3_cookies[NFSNUMCOOKIES]; 7292839Simp uint64_t ndmu4_cookies[NFSNUMCOOKIES]; 7392839Simp } ndm_un1; 7492839Simp}; 7592839Simp 7692839Simp#define ndm_cookies ndm_un1.ndmu3_cookies 7792839Simp#define ndm4_cookies ndm_un1.ndmu4_cookies 781558Srgrimes 791558Srgrimesstruct nfs_accesscache { 801558Srgrimes u_int32_t mode; /* ACCESS mode cache */ 811558Srgrimes uid_t uid; /* credentials having mode */ 827585Sbde time_t stamp; /* mode cache timestamp */ 8392839Simp}; 841558Srgrimes 8592806Sobrien/* 861558Srgrimes * The nfsnode is the nfs equivalent to ufs's inode. Any similarity 871558Srgrimes * is purely coincidental. 881558Srgrimes * There is a unique nfsnode allocated for each active file, 891558Srgrimes * each current directory, each mounted-on file, text file, and the root. 901558Srgrimes * An nfsnode is 'named' by its file handle. (nget/nfs_node.c) 911558Srgrimes * If this structure exceeds 256 bytes (it is currently 256 using 4.4BSD-Lite 921558Srgrimes * type definitions), file handles of > 32 bytes should probably be split out 931558Srgrimes * into a separate MALLOC()'d data structure. (Reduce the size of nfsfh_t by 941558Srgrimes * changing the definition in nfsproto.h of NFS_SMALLFH.) 951558Srgrimes * NB: Hopefully the current order of the fields is such that everything will 9641474Sjulian * be well aligned and, therefore, tightly packed. 9741474Sjulian */ 9841474Sjulianstruct nfsnode { 991558Srgrimes struct mtx n_mtx; /* Protects all of these members */ 1001558Srgrimes u_quad_t n_size; /* Current size of file */ 1011558Srgrimes u_quad_t n_brev; /* Modify rev when cached */ 1021558Srgrimes u_quad_t n_lrev; /* Modify rev for lease */ 1031558Srgrimes struct vattr n_vattr; /* Vnode attribute cache */ 1041558Srgrimes time_t n_attrstamp; /* Attr. cache timestamp */ 1051558Srgrimes struct nfs_accesscache n_accesscache[NFS_ACCESSCACHESIZE]; 1061558Srgrimes struct timespec n_mtime; /* Prev modify time. */ 1071558Srgrimes nfsfh_t *n_fhp; /* NFS File Handle */ 1087585Sbde struct vnode *n_vnode; /* associated vnode */ 10992839Simp struct vnode *n_dvp; /* parent vnode */ 1101558Srgrimes int n_error; /* Save write error value */ 11192806Sobrien union { 11292806Sobrien struct timespec nf_atim; /* Special file times */ 11374556Smckusick nfsuint64 nd_cookieverf; /* Cookie verifier (dir only) */ 1141558Srgrimes u_char nd4_cookieverf[NFSX_V4VERF]; 1151558Srgrimes } n_un1; 1161558Srgrimes union { 1171558Srgrimes struct timespec nf_mtim; 11823675Speter off_t nd_direof; /* Dir. EOF offset cache */ 1191558Srgrimes } n_un2; 1201558Srgrimes union { 1211558Srgrimes struct sillyrename *nf_silly; /* Ptr to silly rename struct */ 1221558Srgrimes LIST_HEAD(, nfsdmap) nd_cook; /* cookies */ 1231558Srgrimes } n_un3; 1241558Srgrimes short n_fhsize; /* size in bytes, of fh */ 1251558Srgrimes short n_flag; /* Flag for locking.. */ 1261558Srgrimes nfsfh_t n_fh; /* Small File Handle */ 1271558Srgrimes u_char *n_name; /* leaf name, for v4 OPEN op */ 1281558Srgrimes uint32_t n_namelen; 1291558Srgrimes int n_directio_opens; 13041474Sjulian int n_directio_asyncwr; 13141474Sjulian struct ucred *n_writecred; /* Cred. for putpages */ 13223675Speter}; 1331558Srgrimes 1341558Srgrimes#define n_atim n_un1.nf_atim 1351558Srgrimes#define n_mtim n_un2.nf_mtim 1361558Srgrimes#define n_sillyrename n_un3.nf_silly 1371558Srgrimes#define n_cookieverf n_un1.nd_cookieverf 1381558Srgrimes#define n4_cookieverf n_un1.nd4_cookieverf 1391558Srgrimes#define n_direofoffset n_un2.nd_direof 1401558Srgrimes#define n_cookies n_un3.nd_cook 1411558Srgrimes 1421558Srgrimes/* 1431558Srgrimes * Flags for n_flag 1441558Srgrimes */ 1451558Srgrimes#define NFSYNCWAIT 0x0002 /* fsync waiting for all directio async writes 1461558Srgrimes to drain */ 1471558Srgrimes#define NMODIFIED 0x0004 /* Might have a modified buffer in bio */ 1481558Srgrimes#define NWRITEERR 0x0008 /* Flag write errors so close will know */ 1491558Srgrimes/* 0x20, 0x40, 0x80 free */ 1501558Srgrimes#define NACC 0x0100 /* Special file accessed */ 1511558Srgrimes#define NUPD 0x0200 /* Special file updated */ 1521558Srgrimes#define NCHG 0x0400 /* Special file times changed */ 1531558Srgrimes#define NCREATED 0x0800 /* Opened by nfs_create() */ 1541558Srgrimes#define NTRUNCATE 0x1000 /* Opened by nfs_setattr() */ 1551558Srgrimes#define NSIZECHANGED 0x2000 /* File size has changed: need cache inval */ 1561558Srgrimes#define NNONCACHE 0x4000 /* Node marked as noncacheable */ 15723675Speter#define NDIRCOOKIELK 0x8000 /* Lock to serialize access to directory cookies */ 1581558Srgrimes 1591558Srgrimes/* 1601558Srgrimes * Convert between nfsnode pointers and vnode pointers 1611558Srgrimes */ 1628871Srgrimes#define VTONFS(vp) ((struct nfsnode *)(vp)->v_data) 1631558Srgrimes#define NFSTOV(np) ((struct vnode *)(np)->n_vnode) 1641558Srgrimes 1651558Srgrimes#define NFS_TIMESPEC_COMPARE(T1, T2) (((T1)->tv_sec != (T2)->tv_sec) || ((T1)->tv_nsec != (T2)->tv_nsec)) 1661558Srgrimes 1671558Srgrimes/* 1681558Srgrimes * NFS iod threads can be in one of these two states once spawned. 1691558Srgrimes * NFSIOD_NOT_AVAILABLE - Cannot be assigned an I/O operation at this time. 1701558Srgrimes * NFSIOD_AVAILABLE - Available to be assigned an I/O operation. 17123675Speter */ 17292839Simpenum nfsiod_state { 1731558Srgrimes NFSIOD_NOT_AVAILABLE = 0, 17492806Sobrien NFSIOD_AVAILABLE = 1, 17592806Sobrien}; 1761558Srgrimes 1771558Srgrimes/* 1781558Srgrimes * Queue head for nfsiod's 1791558Srgrimes */ 1801558Srgrimesextern TAILQ_HEAD(nfs_bufq, buf) nfs_bufq; 1811558Srgrimesextern enum nfsiod_state nfs_iodwant[NFS_MAXASYNCDAEMON]; 1821558Srgrimesextern struct nfsmount *nfs_iodmount[NFS_MAXASYNCDAEMON]; 1831558Srgrimes 1841558Srgrimes#if defined(_KERNEL) 18523675Speter 18623675Speterextern struct vop_vector nfs_fifoops; 1871558Srgrimesextern struct vop_vector nfs_vnodeops; 1881558Srgrimesextern struct buf_ops buf_ops_nfs; 1891558Srgrimes 1901558Srgrimes/* 1911558Srgrimes * Prototypes for NFS vnode operations 1921558Srgrimes */ 1931558Srgrimesint nfs_getpages(struct vop_getpages_args *); 1941558Srgrimesint nfs_putpages(struct vop_putpages_args *); 1951558Srgrimesint nfs_write(struct vop_write_args *); 1961558Srgrimesint nfs_inactive(struct vop_inactive_args *); 1971558Srgrimesint nfs_reclaim(struct vop_reclaim_args *); 1981558Srgrimes 1991558Srgrimes/* other stuff */ 2001558Srgrimesint nfs_removeit(struct sillyrename *); 2011558Srgrimesint nfs_nget(struct mount *, nfsfh_t *, int, struct nfsnode **, int flags); 2021558Srgrimesnfsuint64 *nfs_getcookie(struct nfsnode *, off_t, int); 2031558Srgrimesvoid nfs_invaldir(struct vnode *); 2041558Srgrimesint nfs_upgrade_vnlock(struct vnode *vp); 2051558Srgrimesvoid nfs_downgrade_vnlock(struct vnode *vp, int old_lock); 2061558Srgrimesvoid nfs_printf(const char *fmt, ...); 2071558Srgrimes 2081558Srgrimesvoid nfs_dircookie_lock(struct nfsnode *np); 2091558Srgrimesvoid nfs_dircookie_unlock(struct nfsnode *np); 2101558Srgrimes 2111558Srgrimes#endif /* _KERNEL */ 2121558Srgrimes 2131558Srgrimes#endif 2141558Srgrimes