nfsnode.h revision 191783
1191783Srmacklem/*- 2191783Srmacklem * Copyright (c) 1989, 1993 3191783Srmacklem * The Regents of the University of California. All rights reserved. 4191783Srmacklem * 5191783Srmacklem * This code is derived from software contributed to Berkeley by 6191783Srmacklem * Rick Macklem at The University of Guelph. 7191783Srmacklem * 8191783Srmacklem * Redistribution and use in source and binary forms, with or without 9191783Srmacklem * modification, are permitted provided that the following conditions 10191783Srmacklem * are met: 11191783Srmacklem * 1. Redistributions of source code must retain the above copyright 12191783Srmacklem * notice, this list of conditions and the following disclaimer. 13191783Srmacklem * 2. Redistributions in binary form must reproduce the above copyright 14191783Srmacklem * notice, this list of conditions and the following disclaimer in the 15191783Srmacklem * documentation and/or other materials provided with the distribution. 16191783Srmacklem * 4. Neither the name of the University nor the names of its contributors 17191783Srmacklem * may be used to endorse or promote products derived from this software 18191783Srmacklem * without specific prior written permission. 19191783Srmacklem * 20191783Srmacklem * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21191783Srmacklem * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22191783Srmacklem * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23191783Srmacklem * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24191783Srmacklem * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25191783Srmacklem * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26191783Srmacklem * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27191783Srmacklem * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28191783Srmacklem * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29191783Srmacklem * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30191783Srmacklem * SUCH DAMAGE. 31191783Srmacklem * 32191783Srmacklem * $FreeBSD: head/sys/fs/nfsclient/nfsnode.h 191783 2009-05-04 15:23:58Z rmacklem $ 33191783Srmacklem */ 34191783Srmacklem 35191783Srmacklem#ifndef _NFSCLIENT_NFSNODE_H_ 36191783Srmacklem#define _NFSCLIENT_NFSNODE_H_ 37191783Srmacklem 38191783Srmacklem/* 39191783Srmacklem * Silly rename structure that hangs off the nfsnode until the name 40191783Srmacklem * can be removed by nfs_inactive() 41191783Srmacklem */ 42191783Srmacklemstruct sillyrename { 43191783Srmacklem struct ucred *s_cred; 44191783Srmacklem struct vnode *s_dvp; 45191783Srmacklem long s_namlen; 46191783Srmacklem char s_name[32]; 47191783Srmacklem}; 48191783Srmacklem 49191783Srmacklem/* 50191783Srmacklem * This structure is used to save the logical directory offset to 51191783Srmacklem * NFS cookie mappings. 52191783Srmacklem * The mappings are stored in a list headed 53191783Srmacklem * by n_cookies, as required. 54191783Srmacklem * There is one mapping for each NFS_DIRBLKSIZ bytes of directory information 55191783Srmacklem * stored in increasing logical offset byte order. 56191783Srmacklem */ 57191783Srmacklem#define NFSNUMCOOKIES 31 58191783Srmacklem 59191783Srmacklemstruct nfsdmap { 60191783Srmacklem LIST_ENTRY(nfsdmap) ndm_list; 61191783Srmacklem int ndm_eocookie; 62191783Srmacklem union { 63191783Srmacklem nfsuint64 ndmu3_cookies[NFSNUMCOOKIES]; 64191783Srmacklem uint64_t ndmu4_cookies[NFSNUMCOOKIES]; 65191783Srmacklem } ndm_un1; 66191783Srmacklem}; 67191783Srmacklem 68191783Srmacklem#define ndm_cookies ndm_un1.ndmu3_cookies 69191783Srmacklem#define ndm4_cookies ndm_un1.ndmu4_cookies 70191783Srmacklem 71191783Srmacklem#define n_ac_ts_tid n_ac_ts.nfs_ac_ts_tid 72191783Srmacklem#define n_ac_ts_pid n_ac_ts.nfs_ac_ts_pid 73191783Srmacklem#define n_ac_ts_syscalls n_ac_ts.nfs_ac_ts_syscalls 74191783Srmacklem 75191783Srmacklemstruct nfs_attrcache_timestamp { 76191783Srmacklem lwpid_t nfs_ac_ts_tid; 77191783Srmacklem pid_t nfs_ac_ts_pid; 78191783Srmacklem unsigned long nfs_ac_ts_syscalls; 79191783Srmacklem}; 80191783Srmacklem 81191783Srmacklemstruct nfs_accesscache { 82191783Srmacklem u_int32_t mode; /* ACCESS mode cache */ 83191783Srmacklem uid_t uid; /* credentials having mode */ 84191783Srmacklem time_t stamp; /* mode cache timestamp */ 85191783Srmacklem}; 86191783Srmacklem 87191783Srmacklem/* 88191783Srmacklem * The nfsnode is the nfs equivalent to ufs's inode. Any similarity 89191783Srmacklem * is purely coincidental. 90191783Srmacklem * There is a unique nfsnode allocated for each active file, 91191783Srmacklem * each current directory, each mounted-on file, text file, and the root. 92191783Srmacklem * An nfsnode is 'named' by its file handle. (nget/nfs_node.c) 93191783Srmacklem * If this structure exceeds 256 bytes (it is currently 256 using 4.4BSD-Lite 94191783Srmacklem * type definitions), file handles of > 32 bytes should probably be split out 95191783Srmacklem * into a separate MALLOC()'d data structure. (Reduce the size of nfsfh_t by 96191783Srmacklem * changing the definition in nfsproto.h of NFS_SMALLFH.) 97191783Srmacklem * NB: Hopefully the current order of the fields is such that everything will 98191783Srmacklem * be well aligned and, therefore, tightly packed. 99191783Srmacklem */ 100191783Srmacklemstruct nfsnode { 101191783Srmacklem struct mtx n_mtx; /* Protects all of these members */ 102191783Srmacklem u_quad_t n_size; /* Current size of file */ 103191783Srmacklem u_quad_t n_brev; /* Modify rev when cached */ 104191783Srmacklem u_quad_t n_lrev; /* Modify rev for lease */ 105191783Srmacklem struct nfsvattr n_vattr; /* Vnode attribute cache */ 106191783Srmacklem time_t n_attrstamp; /* Attr. cache timestamp */ 107191783Srmacklem struct nfs_accesscache n_accesscache[NFS_ACCESSCACHESIZE]; 108191783Srmacklem struct timespec n_mtime; /* Prev modify time. */ 109191783Srmacklem time_t n_ctime; /* Prev create time. */ 110191783Srmacklem time_t n_dmtime; /* Prev dir modify time. */ 111191783Srmacklem time_t n_expiry; /* Lease expiry time */ 112191783Srmacklem struct nfsfh *n_fhp; /* NFS File Handle */ 113191783Srmacklem struct vnode *n_vnode; /* associated vnode */ 114191783Srmacklem struct vnode *n_dvp; /* parent vnode */ 115191783Srmacklem struct lockf *n_lockf; /* Locking record of file */ 116191783Srmacklem int n_error; /* Save write error value */ 117191783Srmacklem union { 118191783Srmacklem struct timespec nf_atim; /* Special file times */ 119191783Srmacklem nfsuint64 nd_cookieverf; /* Cookie verifier (dir only) */ 120191783Srmacklem u_char nd4_cookieverf[NFSX_VERF]; 121191783Srmacklem } n_un1; 122191783Srmacklem union { 123191783Srmacklem struct timespec nf_mtim; 124191783Srmacklem off_t nd_direof; /* Dir. EOF offset cache */ 125191783Srmacklem } n_un2; 126191783Srmacklem union { 127191783Srmacklem struct sillyrename *nf_silly; /* Ptr to silly rename struct */ 128191783Srmacklem LIST_HEAD(, nfsdmap) nd_cook; /* cookies */ 129191783Srmacklem } n_un3; 130191783Srmacklem short n_fhsize; /* size in bytes, of fh */ 131191783Srmacklem u_int32_t n_flag; /* Flag for locking.. */ 132191783Srmacklem int n_directio_opens; 133191783Srmacklem int n_directio_asyncwr; 134191783Srmacklem struct nfs_attrcache_timestamp n_ac_ts; 135191783Srmacklem u_int64_t n_change; /* old Change attribute */ 136191783Srmacklem struct nfsv4node *n_v4; /* extra V4 stuff */ 137191783Srmacklem}; 138191783Srmacklem 139191783Srmacklem#define n_atim n_un1.nf_atim 140191783Srmacklem#define n_mtim n_un2.nf_mtim 141191783Srmacklem#define n_sillyrename n_un3.nf_silly 142191783Srmacklem#define n_cookieverf n_un1.nd_cookieverf 143191783Srmacklem#define n4_cookieverf n_un1.nd4_cookieverf 144191783Srmacklem#define n_direofoffset n_un2.nd_direof 145191783Srmacklem#define n_cookies n_un3.nd_cook 146191783Srmacklem 147191783Srmacklem/* 148191783Srmacklem * Flags for n_flag 149191783Srmacklem */ 150191783Srmacklem#define NDIRCOOKIELK 0x00000001 /* Lock to serialize access to directory cookies */ 151191783Srmacklem#define NFSYNCWAIT 0x00000002 /* fsync waiting for all directio async 152191783Srmacklem writes to drain */ 153191783Srmacklem#define NMODIFIED 0x00000004 /* Might have a modified buffer in bio */ 154191783Srmacklem#define NWRITEERR 0x00000008 /* Flag write errors so close will know */ 155191783Srmacklem#define NCREATED 0x00000010 /* Opened by nfs_create() */ 156191783Srmacklem#define NTRUNCATE 0x00000020 /* Opened by nfs_setattr() */ 157191783Srmacklem#define NSIZECHANGED 0x00000040 /* File size has changed: need cache inval */ 158191783Srmacklem#define NNONCACHE 0x00000080 /* Node marked as noncacheable */ 159191783Srmacklem#define NACC 0x00000100 /* Special file accessed */ 160191783Srmacklem#define NUPD 0x00000200 /* Special file updated */ 161191783Srmacklem#define NCHG 0x00000400 /* Special file times changed */ 162191783Srmacklem#define NDELEGMOD 0x00000800 /* Modified delegation */ 163191783Srmacklem#define NDELEGRECALL 0x00001000 /* Recall in progress */ 164191783Srmacklem#define NREMOVEINPROG 0x00002000 /* Remove in progress */ 165191783Srmacklem#define NREMOVEWANT 0x00004000 /* Want notification that remove is done */ 166191783Srmacklem#define NLOCK 0x00008000 /* Sleep lock the node */ 167191783Srmacklem#define NLOCKWANT 0x00010000 /* Want the sleep lock */ 168191783Srmacklem 169191783Srmacklem/* 170191783Srmacklem * Convert between nfsnode pointers and vnode pointers 171191783Srmacklem */ 172191783Srmacklem#define VTONFS(vp) ((struct nfsnode *)(vp)->v_data) 173191783Srmacklem#define NFSTOV(np) ((struct vnode *)(np)->n_vnode) 174191783Srmacklem 175191783Srmacklem#define NFS_TIMESPEC_COMPARE(T1, T2) (((T1)->tv_sec != (T2)->tv_sec) || ((T1)->tv_nsec != (T2)->tv_nsec)) 176191783Srmacklem 177191783Srmacklem#if defined(_KERNEL) 178191783Srmacklem 179191783Srmacklem/* 180191783Srmacklem * Prototypes for NFS vnode operations 181191783Srmacklem */ 182191783Srmacklemint ncl_getpages(struct vop_getpages_args *); 183191783Srmacklemint ncl_putpages(struct vop_putpages_args *); 184191783Srmacklemint ncl_write(struct vop_write_args *); 185191783Srmacklemint ncl_inactive(struct vop_inactive_args *); 186191783Srmacklemint ncl_reclaim(struct vop_reclaim_args *); 187191783Srmacklem 188191783Srmacklem/* other stuff */ 189191783Srmacklemint ncl_removeit(struct sillyrename *, struct vnode *); 190191783Srmacklemint ncl_nget(struct mount *, u_int8_t *, int, struct nfsnode **); 191191783Srmacklemnfsuint64 *ncl_getcookie(struct nfsnode *, off_t, int); 192191783Srmacklemvoid ncl_invaldir(struct vnode *); 193191783Srmacklemint ncl_upgrade_vnlock(struct vnode *); 194191783Srmacklemvoid ncl_downgrade_vnlock(struct vnode *, int); 195191783Srmacklemvoid ncl_printf(const char *, ...); 196191783Srmacklemvoid ncl_dircookie_lock(struct nfsnode *); 197191783Srmacklemvoid ncl_dircookie_unlock(struct nfsnode *); 198191783Srmacklem 199191783Srmacklem#endif /* _KERNEL */ 200191783Srmacklem 201191783Srmacklem#endif /* _NFSCLIENT_NFSNODE_H_ */ 202