NetBSD/sys/nfs/nfsnode.h

293 lines
9.7 KiB
C
Raw Normal View History

/* $NetBSD: nfsnode.h,v 1.54 2005/01/26 10:30:58 yamt Exp $ */
1993-04-20 15:20:47 +04:00
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
1993-04-20 15:20:47 +04:00
*
* This code is derived from software contributed to Berkeley by
* Rick Macklem at The University of Guelph.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
1993-04-20 15:20:47 +04:00
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)nfsnode.h 8.9 (Berkeley) 5/14/95
1993-04-20 15:20:47 +04:00
*/
#ifndef _NFS_NFSNODE_H_
#define _NFS_NFSNODE_H_
#ifndef _NFS_NFS_H_
#include <nfs/nfs.h>
#endif
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
#include <miscfs/genfs/genfs.h>
#include <miscfs/genfs/genfs_node.h>
/*
* Silly rename structure that hangs off the nfsnode until the name
* can be removed by nfs_inactive()
*/
struct sillyrename {
struct ucred *s_cred;
struct vnode *s_dvp;
long s_namlen;
char s_name[20];
};
1993-04-20 15:20:47 +04:00
/*
* Definitions for the directory cache. Because directory cookies
* are an opaque 64 bit entity, we need to provide some sort of
* mapping between cookies and logical blocknumbers. Also,
* we should store the cookies from the server somewhere,
* to be able to satisfy VOP_READDIR requests for cookies.
* We can't store the cookies in the dirent structure, as some
* other systems.
*
* Each offset is hashed into a per-nfsnode hashtable. An entry
* found therein contains information about the (faked up)
* logical blocknumber, and also a pointer to a buffer where
* the cookies are stored.
*/
extern u_long nfsdirhashmask;
LIST_HEAD(nfsdirhashhead, nfsdircache);
TAILQ_HEAD(nfsdirchainhead, nfsdircache);
struct nfsdircache {
off_t dc_cookie; /* Own offset (key) */
off_t dc_blkcookie; /* Offset of block we're in */
LIST_ENTRY(nfsdircache) dc_hash; /* Hash chain */
TAILQ_ENTRY(nfsdircache) dc_chain; /* Least recently entered chn */
u_int32_t dc_cookie32; /* Key for 64<->32 xlate case */
int dc_entry; /* Entry number within block */
int dc_refcnt; /* Reference count */
int dc_flags; /* NFSDC_ flags */
};
#define NFSDC_INVALID 1
/*
* NFSDC_BLKNO: get buffer cache index
*/
#define NFSDC_BLKNO(ndp) ((daddr_t)(ndp)->dc_blkcookie)
1993-04-20 15:20:47 +04:00
/*
* The nfsnode is the nfs equivalent to ufs's inode. Any similarity
* is purely coincidental.
* There is a unique nfsnode allocated for each active file,
* each current directory, each mounted-on file, text file, and the root.
* An nfsnode is 'named' by its file handle. (nget/nfs_node.c)
*/
struct nfsnode_spec {
struct timespec nspec_mtim; /* local mtime */
struct timespec nspec_atim; /* local atime */
};
struct nfsnode_reg {
off_t nreg_pushedlo; /* 1st blk in commited range */
off_t nreg_pushedhi; /* Last block in range */
off_t nreg_pushlo; /* 1st block in commit range */
off_t nreg_pushhi; /* Last block in range */
struct lock nreg_commitlock; /* Serialize commits XXX */
int nreg_commitflags;
int nreg_error; /* Save write error value */
};
struct nfsnode_dir {
off_t ndir_direof; /* EOF offset cache */
nfsuint64 ndir_cookieverf; /* Cookie verifier */
struct nfsdirhashhead *ndir_dircache; /* offset -> cache hash heads */
struct nfsdirchainhead ndir_dirchain; /* Chain of dir cookies */
struct timespec ndir_nctime; /* Last name cache entry */
unsigned ndir_dircachesize; /* Size of dir cookie cache */
};
1993-04-20 15:20:47 +04:00
struct nfsnode {
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
struct genfs_node n_gnode;
u_quad_t n_size; /* Current size of file */
union {
struct nfsnode_spec nu_spec;
struct nfsnode_reg nu_reg;
struct nfsnode_dir nu_dir;
} n_un1;
#define n_mtim n_un1.nu_spec.nspec_mtim
#define n_atim n_un1.nu_spec.nspec_atim
#define n_pushedlo n_un1.nu_reg.nreg_pushedlo
#define n_pushedhi n_un1.nu_reg.nreg_pushedhi
#define n_pushlo n_un1.nu_reg.nreg_pushlo
#define n_pushhi n_un1.nu_reg.nreg_pushhi
#define n_commitlock n_un1.nu_reg.nreg_commitlock
#define n_commitflags n_un1.nu_reg.nreg_commitflags
#define n_error n_un1.nu_reg.nreg_error
#define n_direofoffset n_un1.nu_dir.ndir_direof
#define n_cookieverf n_un1.nu_dir.ndir_cookieverf
#define n_dircache n_un1.nu_dir.ndir_dircache
#define n_dirchain n_un1.nu_dir.ndir_dirchain
#define n_nctime n_un1.nu_dir.ndir_nctime
#define n_dircachesize n_un1.nu_dir.ndir_dircachesize
union {
struct sillyrename *nf_silly; /* !VDIR: silly rename struct */
unsigned *ndir_dirgens; /* 32<->64bit xlate gen. no. */
} n_un2;
#define n_sillyrename n_un2.nf_silly
#define n_dirgens n_un2.ndir_dirgens
LIST_ENTRY(nfsnode) n_hash; /* Hash chain */
nfsfh_t *n_fhp; /* NFS File Handle */
struct vattr *n_vattr; /* Vnode attribute cache */
struct vnode *n_vnode; /* associated vnode */
struct lockf *n_lockf; /* Locking record of file */
time_t n_attrstamp; /* Attr. cache timestamp */
struct timespec n_mtime; /* Prev modify time. */
time_t n_ctime; /* Prev create time. */
short n_fhsize; /* size in bytes, of fh */
short n_flag; /* Flag for locking.. */
nfsfh_t n_fh; /* Small File Handle */
time_t n_accstamp; /* Access cache timestamp */
uid_t n_accuid; /* Last access requester */
int n_accmode; /* Mode last requested */
int n_accerror; /* Error last returned */
struct ucred *n_rcred;
struct ucred *n_wcred;
/* members below are only used by NQNFS */
CIRCLEQ_ENTRY(nfsnode) n_timer; /* Nqnfs timer chain */
u_quad_t n_brev; /* Modify rev when cached */
u_quad_t n_lrev; /* Modify rev for lease */
time_t n_expiry; /* Lease expiry time */
1993-04-20 15:20:47 +04:00
};
LIST_HEAD(nfsnodehashhead, nfsnode);
1993-04-20 15:20:47 +04:00
2000-09-20 02:18:40 +04:00
/*
* Values for n_commitflags
*/
#define NFS_COMMIT_PUSH_VALID 0x0001 /* push range valid */
#define NFS_COMMIT_PUSHED_VALID 0x0002 /* pushed range valid */
/*
* Flags for n_flag
*/
#define NFLUSHWANT 0x0001 /* Want wakeup from a flush in prog. */
#define NFLUSHINPROG 0x0002 /* Avoid multiple calls to vinvalbuf() */
#define NMODIFIED 0x0004 /* Might have a modified buffer in bio */
#define NWRITEERR 0x0008 /* Flag write errors so close will know */
#define NQNFSNONCACHE 0x0020 /* Non-cachable lease */
#define NQNFSWRITE 0x0040 /* Write lease */
#define NQNFSEVICTED 0x0080 /* Has been evicted */
#define NACC 0x0100 /* Special file accessed */
#define NUPD 0x0200 /* Special file updated */
#define NCHG 0x0400 /* Special file times changed */
#define NTRUNCDELAYED 0x1000 /* Should be truncated later;
implies stale cache */
#define NREMOVED 0x2000 /* Has been removed */
#define NUSEOPENCRED 0x4000 /* Try open cred first rather than owner's */
#define NEOFVALID 0x8000 /* dir: n_direofoffset is valid */
#define NFS_EOFVALID(ndp) ((ndp)->n_flag & NEOFVALID)
1993-04-20 15:20:47 +04:00
/*
* Convert between nfsnode pointers and vnode pointers
*/
#define VTONFS(vp) ((struct nfsnode *)(vp)->v_data)
#define NFSTOV(np) ((np)->n_vnode)
1993-04-20 15:20:47 +04:00
/*
* Per-nfsiod datas
1993-04-20 15:20:47 +04:00
*/
2003-04-09 18:22:33 +04:00
struct nfs_iod {
2003-05-07 20:18:53 +04:00
struct simplelock nid_slock;
2003-04-09 18:22:33 +04:00
struct proc *nid_proc;
struct proc *nid_want;
struct nfsmount *nid_mount;
};
extern struct nfs_iod nfs_asyncdaemon[NFS_MAXASYNCDAEMON];
1993-04-20 15:20:47 +04:00
1995-03-27 00:35:13 +04:00
#ifdef _KERNEL
1993-04-20 15:20:47 +04:00
/*
* Prototypes for NFS vnode operations
*/
int nfs_lookup __P((void *));
int nfs_create __P((void *));
int nfs_mknod __P((void *));
int nfs_open __P((void *));
int nfs_close __P((void *));
int nfsspec_close __P((void *));
int nfsfifo_close __P((void *));
int nfs_access __P((void *));
int nfsspec_access __P((void *));
int nfs_getattr __P((void *));
int nfs_setattr __P((void *));
int nfs_read __P((void *));
int nfs_write __P((void *));
#define nfs_lease_check genfs_nullop
int nfsspec_read __P((void *));
int nfsspec_write __P((void *));
int nfsfifo_read __P((void *));
int nfsfifo_write __P((void *));
#define nfs_ioctl genfs_enoioctl
1996-09-07 16:40:22 +04:00
#define nfs_poll genfs_poll
1998-03-01 05:20:01 +03:00
#define nfs_revoke genfs_revoke
#define nfs_mmap genfs_mmap
int nfs_fsync __P((void *));
#define nfs_seek genfs_seek
int nfs_remove __P((void *));
int nfs_link __P((void *));
int nfs_rename __P((void *));
int nfs_mkdir __P((void *));
int nfs_rmdir __P((void *));
int nfs_symlink __P((void *));
int nfs_readdir __P((void *));
int nfs_readlink __P((void *));
#define nfs_abortop genfs_abortop
int nfs_inactive __P((void *));
int nfs_reclaim __P((void *));
2001-02-06 14:40:02 +03:00
#define nfs_lock genfs_lock
int nfs_unlock __P((void *));
2001-02-06 14:40:02 +03:00
#define nfs_islocked genfs_islocked
int nfs_bmap __P((void *));
int nfs_strategy __P((void *));
int nfs_print __P((void *));
int nfs_pathconf __P((void *));
int nfs_advlock __P((void *));
int nfs_getpages __P((void *));
int nfs_putpages __P((void *));
a whole bunch of changes to improve performance and robustness under load: - remove special treatment of pager_map mappings in pmaps. this is required now, since I've removed the globals that expose the address range. pager_map now uses pmap_kenter_pa() instead of pmap_enter(), so there's no longer any need to special-case it. - eliminate struct uvm_vnode by moving its fields into struct vnode. - rewrite the pageout path. the pager is now responsible for handling the high-level requests instead of only getting control after a bunch of work has already been done on its behalf. this will allow us to UBCify LFS, which needs tighter control over its pages than other filesystems do. writing a page to disk no longer requires making it read-only, which allows us to write wired pages without causing all kinds of havoc. - use a new PG_PAGEOUT flag to indicate that a page should be freed on behalf of the pagedaemon when it's unlocked. this flag is very similar to PG_RELEASED, but unlike PG_RELEASED, PG_PAGEOUT can be cleared if the pageout fails due to eg. an indirect-block buffer being locked. this allows us to remove the "version" field from struct vm_page, and together with shrinking "loan_count" from 32 bits to 16, struct vm_page is now 4 bytes smaller. - no longer use PG_RELEASED for swap-backed pages. if the page is busy because it's being paged out, we can't release the swap slot to be reallocated until that write is complete, but unlike with vnodes we don't keep a count of in-progress writes so there's no good way to know when the write is done. instead, when we need to free a busy swap-backed page, just sleep until we can get it busy ourselves. - implement a fast-path for extending writes which allows us to avoid zeroing new pages. this substantially reduces cpu usage. - encapsulate the data used by the genfs code in a struct genfs_node, which must be the first element of the filesystem-specific vnode data for filesystems which use genfs_{get,put}pages(). - eliminate many of the UVM pagerops, since they aren't needed anymore now that the pager "put" operation is a higher-level operation. - enhance the genfs code to allow NFS to use the genfs_{get,put}pages instead of a modified copy. - clean up struct vnode by removing all the fields that used to be used by the vfs_cluster.c code (which we don't use anymore with UBC). - remove kmem_object and mb_object since they were useless. instead of allocating pages to these objects, we now just allocate pages with no object. such pages are mapped in the kernel until they are freed, so we can use the mapping to find the page to free it. this allows us to remove splvm() protection in several places. The sum of all these changes improves write throughput on my decstation 5000/200 to within 1% of the rate of NetBSD 1.5 and reduces the elapsed time for "make release" of a NetBSD 1.5 source tree on my 128MB pc to 10% less than a 1.5 kernel took.
2001-09-16 00:36:31 +04:00
int nfs_gop_write(struct vnode *, struct vm_page **, int, int);
int nfs_kqfilter __P((void *));
1996-02-10 00:48:19 +03:00
extern int (**nfsv2_vnodeop_p) __P((void *));
#define NFS_INVALIDATE_ATTRCACHE(np) (np)->n_attrstamp = 0
1995-03-27 00:35:13 +04:00
#endif /* _KERNEL */
#endif