VFS messaging/interfacing work stage 5/99. Start work on the new
[dragonfly.git] / sys / vfs / nfs / nfsnode.h
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Rick Macklem at The University of Guelph.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)nfsnode.h 8.9 (Berkeley) 5/14/95
79e5012e 37 * $FreeBSD: /repoman/r/ncvs/src/sys/nfsclient/nfsnode.h,v 1.43 2004/04/14 23:23:55 peadar Exp $
3446c007 38 * $DragonFly: src/sys/vfs/nfs/nfsnode.h,v 1.12 2004/08/28 19:02:20 dillon Exp $
984263bc
MD
39 */
40
41
42#ifndef _NFS_NFSNODE_H_
43#define _NFS_NFSNODE_H_
44
45#if !defined(_NFS_NFS_H_) && !defined(_KERNEL)
1f2de5d4 46#include "nfs.h"
984263bc
MD
47#endif
48
508ceb09
JS
49#include <sys/lockf.h>
50
984263bc
MD
51/*
52 * Silly rename structure that hangs off the nfsnode until the name
53 * can be removed by nfs_inactive()
54 */
55struct sillyrename {
56 struct ucred *s_cred;
57 struct vnode *s_dvp;
58 long s_namlen;
59 char s_name[20];
60};
61
62/*
63 * This structure is used to save the logical directory offset to
64 * NFS cookie mappings.
65 * The mappings are stored in a list headed
66 * by n_cookies, as required.
67 * There is one mapping for each NFS_DIRBLKSIZ bytes of directory information
68 * stored in increasing logical offset byte order.
69 */
70#define NFSNUMCOOKIES 31
71
72struct nfsdmap {
73 LIST_ENTRY(nfsdmap) ndm_list;
74 int ndm_eocookie;
75 nfsuint64 ndm_cookies[NFSNUMCOOKIES];
76};
77
78/*
79 * The nfsnode is the nfs equivalent to ufs's inode. Any similarity
c1cf1e59
MD
80 * is purely coincidental. There is a unique nfsnode allocated for
81 * each active file, each current directory, each mounted-on file,
82 * text file, and the root.
83 *
984263bc 84 * An nfsnode is 'named' by its file handle. (nget/nfs_node.c)
c1cf1e59
MD
85 *
86 * File handles are accessed via n_fhp, which will point to n_fh if the
87 * file handle is small enough (<= NFS_SMALLFH). Otherwise the file handle
88 * will be allocated.
89 *
90 * DragonFly does not pass ucreds to read and write operations, since such
91 * operations are not possible unless the ucred has already been validated.
92 * Validating ucreds are stored in nfsnode to pass on to NFS read/write RPCs.
984263bc
MD
93 */
94struct nfsnode {
984263bc
MD
95 LIST_ENTRY(nfsnode) n_hash; /* Hash chain */
96 CIRCLEQ_ENTRY(nfsnode) n_timer; /* Nqnfs timer chain */
97 u_quad_t n_size; /* Current size of file */
98 u_quad_t n_brev; /* Modify rev when cached */
99 u_quad_t n_lrev; /* Modify rev for lease */
100 struct vattr n_vattr; /* Vnode attribute cache */
101 time_t n_attrstamp; /* Attr. cache timestamp */
102 u_int32_t n_mode; /* ACCESS mode cache */
103 uid_t n_modeuid; /* credentials having mode */
104 time_t n_modestamp; /* mode cache timestamp */
105 time_t n_mtime; /* Prev modify time. */
106 time_t n_ctime; /* Prev create time. */
107 time_t n_expiry; /* Lease expiry time */
108 nfsfh_t *n_fhp; /* NFS File Handle */
c1cf1e59
MD
109 struct ucred *n_rucred;
110 struct ucred *n_wucred;
984263bc 111 struct vnode *n_vnode; /* associated vnode */
508ceb09 112 struct lockf n_lockf; /* Locking record of file */
984263bc
MD
113 int n_error; /* Save write error value */
114 union {
115 struct timespec nf_atim; /* Special file times */
116 nfsuint64 nd_cookieverf; /* Cookie verifier (dir only) */
117 } n_un1;
118 union {
119 struct timespec nf_mtim;
120 off_t nd_direof; /* Dir. EOF offset cache */
121 } n_un2;
122 union {
123 struct sillyrename *nf_silly; /* Ptr to silly rename struct */
124 LIST_HEAD(, nfsdmap) nd_cook; /* cookies */
125 } n_un3;
126 short n_fhsize; /* size in bytes, of fh */
127 short n_flag; /* Flag for locking.. */
128 nfsfh_t n_fh; /* Small File Handle */
129 struct lock n_rslock;
130};
131
132#define n_atim n_un1.nf_atim
133#define n_mtim n_un2.nf_mtim
134#define n_sillyrename n_un3.nf_silly
135#define n_cookieverf n_un1.nd_cookieverf
136#define n_direofoffset n_un2.nd_direof
137#define n_cookies n_un3.nd_cook
138
139/*
140 * Flags for n_flag
141 */
142#define NFLUSHWANT 0x0001 /* Want wakeup from a flush in prog. */
143#define NFLUSHINPROG 0x0002 /* Avoid multiple calls to vinvalbuf() */
144#define NMODIFIED 0x0004 /* Might have a modified buffer in bio */
145#define NWRITEERR 0x0008 /* Flag write errors so close will know */
146#define NQNFSNONCACHE 0x0020 /* Non-cachable lease */
147#define NQNFSWRITE 0x0040 /* Write lease */
148#define NQNFSEVICTED 0x0080 /* Has been evicted */
149#define NACC 0x0100 /* Special file accessed */
150#define NUPD 0x0200 /* Special file updated */
151#define NCHG 0x0400 /* Special file times changed */
9ebbf428
DR
152#define NLOCKED 0x0800 /* node is locked */
153#define NWANTED 0x0100 /* someone wants to lock */
79e5012e 154#define NSIZECHANGED 0x2000 /* File size has changed: need cache inval */
984263bc
MD
155
156/*
157 * Convert between nfsnode pointers and vnode pointers
158 */
9ebbf428
DR
159#define VTONFS(vp) ((struct nfsnode *)(vp)->v_data)
160#define NFSTOV(np) ((struct vnode *)(np)->n_vnode)
984263bc
MD
161
162/*
163 * Queue head for nfsiod's
164 */
165extern TAILQ_HEAD(nfs_bufq, buf) nfs_bufq;
dadab5e9 166extern struct thread *nfs_iodwant[NFS_MAXASYNCDAEMON];
984263bc
MD
167extern struct nfsmount *nfs_iodmount[NFS_MAXASYNCDAEMON];
168
169#if defined(_KERNEL)
170
171/*
172 * nfs_rslock - Attempt to obtain lock on nfsnode
173 *
174 * Attempt to obtain a lock on the passed nfsnode, returning ENOLCK
175 * if the lock could not be obtained due to our having to sleep. This
176 * function is generally used to lock around code that modifies an
177 * NFS file's size. In order to avoid deadlocks the lock
178 * should not be obtained while other locks are being held.
179 */
180
181static __inline
182int
dadab5e9 183nfs_rslock(struct nfsnode *np, struct thread *td)
984263bc 184{
9ebbf428
DR
185 return(lockmgr(&np->n_rslock, LK_EXCLUSIVE | LK_CANRECURSE |
186 LK_SLEEPFAIL, NULL, td));
984263bc
MD
187}
188
189static __inline
190void
dadab5e9 191nfs_rsunlock(struct nfsnode *np, struct thread *td)
984263bc 192{
dadab5e9 193 (void)lockmgr(&np->n_rslock, LK_RELEASE, NULL, td);
984263bc
MD
194}
195
c1cf1e59
MD
196static __inline
197struct ucred *
198nfs_vpcred(struct vnode *vp, int ndflag)
199{
200 struct nfsnode *np = VTONFS(vp);
201
202 if (np && (ndflag & ND_WRITE) && np->n_wucred)
203 return(np->n_wucred);
204 if (np && (ndflag & ND_READ) && np->n_rucred)
205 return(np->n_rucred);
206 return(VFSTONFS((vp)->v_mount)->nm_cred);
207}
208
984263bc
MD
209/*
210 * Prototypes for NFS vnode operations
211 */
a6ee311a
RG
212int nfs_getpages (struct vop_getpages_args *);
213int nfs_putpages (struct vop_putpages_args *);
214int nfs_write (struct vop_write_args *);
215int nqnfs_vop_lease_check (struct vop_lease_args *);
216int nfs_inactive (struct vop_inactive_args *);
217int nfs_reclaim (struct vop_reclaim_args *);
984263bc
MD
218
219/* other stuff */
a6ee311a
RG
220int nfs_removeit (struct sillyrename *);
221int nfs_nget (struct mount *,nfsfh_t *,int,struct nfsnode **);
222nfsuint64 *nfs_getcookie (struct nfsnode *, off_t, int);
9ebbf428 223void nfs_invaldir (struct vnode *);
984263bc 224
9ebbf428 225#define nqnfs_lease_updatetime nfs_lease_updatetime
984263bc
MD
226
227#endif /* _KERNEL */
228
229#endif