nfsnode.h revision 220732
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 220732 2011-04-16 23:20:21Z 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 71191783Srmacklemstruct nfs_accesscache { 72191783Srmacklem u_int32_t mode; /* ACCESS mode cache */ 73191783Srmacklem uid_t uid; /* credentials having mode */ 74191783Srmacklem time_t stamp; /* mode cache timestamp */ 75191783Srmacklem}; 76191783Srmacklem 77191783Srmacklem/* 78191783Srmacklem * The nfsnode is the nfs equivalent to ufs's inode. Any similarity 79191783Srmacklem * is purely coincidental. 80191783Srmacklem * There is a unique nfsnode allocated for each active file, 81191783Srmacklem * each current directory, each mounted-on file, text file, and the root. 82191783Srmacklem * An nfsnode is 'named' by its file handle. (nget/nfs_node.c) 83191783Srmacklem * If this structure exceeds 256 bytes (it is currently 256 using 4.4BSD-Lite 84191783Srmacklem * type definitions), file handles of > 32 bytes should probably be split out 85191783Srmacklem * into a separate MALLOC()'d data structure. (Reduce the size of nfsfh_t by 86191783Srmacklem * changing the definition in nfsproto.h of NFS_SMALLFH.) 87191783Srmacklem * NB: Hopefully the current order of the fields is such that everything will 88191783Srmacklem * be well aligned and, therefore, tightly packed. 89191783Srmacklem */ 90191783Srmacklemstruct nfsnode { 91191783Srmacklem struct mtx n_mtx; /* Protects all of these members */ 92191783Srmacklem u_quad_t n_size; /* Current size of file */ 93191783Srmacklem u_quad_t n_brev; /* Modify rev when cached */ 94191783Srmacklem u_quad_t n_lrev; /* Modify rev for lease */ 95191783Srmacklem struct nfsvattr n_vattr; /* Vnode attribute cache */ 96191783Srmacklem time_t n_attrstamp; /* Attr. cache timestamp */ 97191783Srmacklem struct nfs_accesscache n_accesscache[NFS_ACCESSCACHESIZE]; 98191783Srmacklem struct timespec n_mtime; /* Prev modify time. */ 99212293Sjhb struct timespec n_ctime; /* Prev create time. */ 100212293Sjhb struct timespec n_dmtime; /* Prev dir modify time. */ 101203303Srmacklem int n_dmtime_ticks; /* Tick of -ve cache entry */ 102191783Srmacklem struct nfsfh *n_fhp; /* NFS File Handle */ 103191783Srmacklem struct vnode *n_vnode; /* associated vnode */ 104191783Srmacklem struct vnode *n_dvp; /* parent vnode */ 105191783Srmacklem struct lockf *n_lockf; /* Locking record of file */ 106191783Srmacklem int n_error; /* Save write error value */ 107191783Srmacklem union { 108191783Srmacklem struct timespec nf_atim; /* Special file times */ 109191783Srmacklem nfsuint64 nd_cookieverf; /* Cookie verifier (dir only) */ 110191783Srmacklem u_char nd4_cookieverf[NFSX_VERF]; 111191783Srmacklem } n_un1; 112191783Srmacklem union { 113191783Srmacklem struct timespec nf_mtim; 114191783Srmacklem off_t nd_direof; /* Dir. EOF offset cache */ 115191783Srmacklem } n_un2; 116191783Srmacklem union { 117191783Srmacklem struct sillyrename *nf_silly; /* Ptr to silly rename struct */ 118191783Srmacklem LIST_HEAD(, nfsdmap) nd_cook; /* cookies */ 119191783Srmacklem } n_un3; 120191783Srmacklem short n_fhsize; /* size in bytes, of fh */ 121191783Srmacklem u_int32_t n_flag; /* Flag for locking.. */ 122191783Srmacklem int n_directio_opens; 123191783Srmacklem int n_directio_asyncwr; 124191783Srmacklem u_int64_t n_change; /* old Change attribute */ 125191783Srmacklem struct nfsv4node *n_v4; /* extra V4 stuff */ 126191783Srmacklem}; 127191783Srmacklem 128191783Srmacklem#define n_atim n_un1.nf_atim 129191783Srmacklem#define n_mtim n_un2.nf_mtim 130191783Srmacklem#define n_sillyrename n_un3.nf_silly 131191783Srmacklem#define n_cookieverf n_un1.nd_cookieverf 132191783Srmacklem#define n4_cookieverf n_un1.nd4_cookieverf 133191783Srmacklem#define n_direofoffset n_un2.nd_direof 134191783Srmacklem#define n_cookies n_un3.nd_cook 135191783Srmacklem 136191783Srmacklem/* 137191783Srmacklem * Flags for n_flag 138191783Srmacklem */ 139191783Srmacklem#define NDIRCOOKIELK 0x00000001 /* Lock to serialize access to directory cookies */ 140191783Srmacklem#define NFSYNCWAIT 0x00000002 /* fsync waiting for all directio async 141191783Srmacklem writes to drain */ 142191783Srmacklem#define NMODIFIED 0x00000004 /* Might have a modified buffer in bio */ 143191783Srmacklem#define NWRITEERR 0x00000008 /* Flag write errors so close will know */ 144191783Srmacklem#define NCREATED 0x00000010 /* Opened by nfs_create() */ 145191783Srmacklem#define NTRUNCATE 0x00000020 /* Opened by nfs_setattr() */ 146191783Srmacklem#define NSIZECHANGED 0x00000040 /* File size has changed: need cache inval */ 147191783Srmacklem#define NNONCACHE 0x00000080 /* Node marked as noncacheable */ 148191783Srmacklem#define NACC 0x00000100 /* Special file accessed */ 149191783Srmacklem#define NUPD 0x00000200 /* Special file updated */ 150191783Srmacklem#define NCHG 0x00000400 /* Special file times changed */ 151191783Srmacklem#define NDELEGMOD 0x00000800 /* Modified delegation */ 152191783Srmacklem#define NDELEGRECALL 0x00001000 /* Recall in progress */ 153191783Srmacklem#define NREMOVEINPROG 0x00002000 /* Remove in progress */ 154191783Srmacklem#define NREMOVEWANT 0x00004000 /* Want notification that remove is done */ 155191783Srmacklem#define NLOCK 0x00008000 /* Sleep lock the node */ 156191783Srmacklem#define NLOCKWANT 0x00010000 /* Want the sleep lock */ 157191783Srmacklem 158191783Srmacklem/* 159191783Srmacklem * Convert between nfsnode pointers and vnode pointers 160191783Srmacklem */ 161191783Srmacklem#define VTONFS(vp) ((struct nfsnode *)(vp)->v_data) 162191783Srmacklem#define NFSTOV(np) ((struct vnode *)(np)->n_vnode) 163191783Srmacklem 164191783Srmacklem#define NFS_TIMESPEC_COMPARE(T1, T2) (((T1)->tv_sec != (T2)->tv_sec) || ((T1)->tv_nsec != (T2)->tv_nsec)) 165191783Srmacklem 166191783Srmacklem#if defined(_KERNEL) 167191783Srmacklem 168191783Srmacklem/* 169191783Srmacklem * Prototypes for NFS vnode operations 170191783Srmacklem */ 171191783Srmacklemint ncl_getpages(struct vop_getpages_args *); 172191783Srmacklemint ncl_putpages(struct vop_putpages_args *); 173191783Srmacklemint ncl_write(struct vop_write_args *); 174191783Srmacklemint ncl_inactive(struct vop_inactive_args *); 175191783Srmacklemint ncl_reclaim(struct vop_reclaim_args *); 176191783Srmacklem 177191783Srmacklem/* other stuff */ 178191783Srmacklemint ncl_removeit(struct sillyrename *, struct vnode *); 179220732Srmacklemint ncl_nget(struct mount *, u_int8_t *, int, struct nfsnode **, int); 180191783Srmacklemnfsuint64 *ncl_getcookie(struct nfsnode *, off_t, int); 181191783Srmacklemvoid ncl_invaldir(struct vnode *); 182191783Srmacklemint ncl_upgrade_vnlock(struct vnode *); 183191783Srmacklemvoid ncl_downgrade_vnlock(struct vnode *, int); 184191783Srmacklemvoid ncl_printf(const char *, ...); 185191783Srmacklemvoid ncl_dircookie_lock(struct nfsnode *); 186191783Srmacklemvoid ncl_dircookie_unlock(struct nfsnode *); 187191783Srmacklem 188191783Srmacklem#endif /* _KERNEL */ 189191783Srmacklem 190191783Srmacklem#endif /* _NFSCLIENT_NFSNODE_H_ */ 191