1/* $NetBSD: nfsnode.h,v 1.73 2014/05/30 08:47:45 hannken Exp $ */
2
3/*
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Rick Macklem at The University of Guelph.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 * @(#)nfsnode.h 8.9 (Berkeley) 5/14/95
35 */
36
37
38#ifndef _NFS_NFSNODE_H_
39#define _NFS_NFSNODE_H_
40
41#include <sys/condvar.h>
42#include <sys/mutex.h>
43
44#ifndef _NFS_NFS_H_
45#include <nfs/nfs.h>
46#endif
47#include <miscfs/genfs/genfs.h>
48#include <miscfs/genfs/genfs_node.h>
49
50/*
51 * Definitions for the directory cache. Because directory cookies
52 * are an opaque 64 bit entity, we need to provide some sort of
53 * mapping between cookies and logical blocknumbers. Also,
54 * we should store the cookies from the server somewhere,
55 * to be able to satisfy VOP_READDIR requests for cookies.
56 * We can't store the cookies in the dirent structure, as some
57 * other systems.
58 *
59 * Each offset is hashed into a per-nfsnode hashtable. An entry
60 * found therein contains information about the (faked up)
61 * logical blocknumber, and also a pointer to a buffer where
62 * the cookies are stored.
63 */
64
65
66LIST_HEAD(nfsdirhashhead, nfsdircache);
67TAILQ_HEAD(nfsdirchainhead, nfsdircache);
68
69struct nfsdircache {
70 off_t dc_cookie; /* Own offset (key) */
71 off_t dc_blkcookie; /* Offset of block we're in */
72 LIST_ENTRY(nfsdircache) dc_hash; /* Hash chain */
73 TAILQ_ENTRY(nfsdircache) dc_chain; /* Least recently entered chn */
74 u_int32_t dc_cookie32; /* Key for 64<->32 xlate case */
75 int dc_entry; /* Entry number within block */
76 int dc_refcnt; /* Reference count */
77 int dc_flags; /* NFSDC_ flags */
78};
79
80#define NFSDC_INVALID 1
81
82/*
83 * NFSDC_BLKNO: get buffer cache index
84 */
85#define NFSDC_BLKNO(ndp) ((daddr_t)(ndp)->dc_blkcookie)
86
87/*
88 * The nfsnode is the nfs equivalent to ufs's inode. Any similarity
89 * is purely coincidental.
90 * There is a unique nfsnode allocated for each active file,
91 * each current directory, each mounted-on file, text file, and the root.
92 * An nfsnode is 'named' by its file handle. (nget/nfs_node.c)
93 */
94
95struct nfsnode_spec {
96 struct timespec nspec_mtim; /* local mtime */
97 struct timespec nspec_atim; /* local atime */
98};
99
100struct nfsnode_reg {
101 off_t nreg_pushedlo; /* 1st blk in commited range */
102 off_t nreg_pushedhi; /* Last block in range */
103 off_t nreg_pushlo; /* 1st block in commit range */
104 off_t nreg_pushhi; /* Last block in range */
105 kmutex_t nreg_commitlock; /* Serialize commits XXX */
106 int nreg_commitflags;
107 int nreg_error; /* Save write error value */
108};
109
110struct nfsnode_dir {
111 off_t ndir_direof; /* EOF offset cache */
112 nfsuint64 ndir_cookieverf; /* Cookie verifier */
113 struct nfsdirhashhead *ndir_dircache; /* offset -> cache hash heads */
114 struct nfsdirchainhead ndir_dirchain; /* Chain of dir cookies */
115 struct timespec ndir_nctime; /* Last name cache entry */
116 unsigned ndir_dircachesize; /* Size of dir cookie cache */
117};
118
119struct nfsnode {
120 struct genfs_node n_gnode;
121 u_quad_t n_size; /* Current size of file */
122
123 union {
124 struct nfsnode_spec nu_spec;
125 struct nfsnode_reg nu_reg;
126 struct nfsnode_dir nu_dir;
127 } n_un1;
128
129#define n_mtim n_un1.nu_spec.nspec_mtim
130#define n_atim n_un1.nu_spec.nspec_atim
131
132#define n_pushedlo n_un1.nu_reg.nreg_pushedlo
133#define n_pushedhi n_un1.nu_reg.nreg_pushedhi
134#define n_pushlo n_un1.nu_reg.nreg_pushlo
135#define n_pushhi n_un1.nu_reg.nreg_pushhi
136#define n_commitlock n_un1.nu_reg.nreg_commitlock
137#define n_commitflags n_un1.nu_reg.nreg_commitflags
138#define n_error n_un1.nu_reg.nreg_error
139
140#define n_direofoffset n_un1.nu_dir.ndir_direof
141#define n_cookieverf n_un1.nu_dir.ndir_cookieverf
142#define n_dircache n_un1.nu_dir.ndir_dircache
143#define n_dirchain n_un1.nu_dir.ndir_dirchain
144#define n_nctime n_un1.nu_dir.ndir_nctime
145#define n_dircachesize n_un1.nu_dir.ndir_dircachesize
146
147 union {
148 struct sillyrename *nf_silly; /* !VDIR: silly rename struct */
149 unsigned *ndir_dirgens; /* 32<->64bit xlate gen. no. */
150 } n_un2;
151
152#define n_sillyrename n_un2.nf_silly
153#define n_dirgens n_un2.ndir_dirgens
154
155 nfsfh_t *n_fhp; /* NFS File Handle */
156 struct vattr *n_vattr; /* Vnode attribute cache */
157 struct vnode *n_vnode; /* associated vnode */
158 struct lockf *n_lockf; /* Locking record of file */
159 time_t n_attrstamp; /* Attr. cache timestamp */
160 struct timespec n_mtime; /* Prev modify time. */
161 time_t n_ctime; /* Prev create time. */
162 short n_fhsize; /* size in bytes, of fh */
163 short n_flag; /* Flag for locking.. */
164 nfsfh_t n_fh; /* Small File Handle */
165 time_t n_accstamp; /* Access cache timestamp */
166 uid_t n_accuid; /* Last access requester */
167 int n_accmode; /* Mode last requested */
168 int n_accerror; /* Error last returned */
169 kauth_cred_t n_rcred;
170 kauth_cred_t n_wcred;
171};
172
173/*
174 * Values for n_commitflags
175 */
176#define NFS_COMMIT_PUSH_VALID 0x0001 /* push range valid */
177#define NFS_COMMIT_PUSHED_VALID 0x0002 /* pushed range valid */
178
179/*
180 * Flags for n_flag
181 */
182#define NFLUSHWANT 0x0001 /* Want wakeup from a flush in prog. */
183#define NFLUSHINPROG 0x0002 /* Avoid multiple calls to vinvalbuf() */
184#define NMODIFIED 0x0004 /* Might have a modified buffer in bio */
185#define NWRITEERR 0x0008 /* Flag write errors so close will know */
186#define NACC 0x0100 /* Special file accessed */
187#define NUPD 0x0200 /* Special file updated */
188#define NCHG 0x0400 /* Special file times changed */
189#define NTRUNCDELAYED 0x1000 /* Should be truncated later;
190 implies stale cache */
191#define NREMOVED 0x2000 /* Has been removed */
192#define NUSEOPENCRED 0x4000 /* Try open cred first rather than owner's */
193#define NEOFVALID 0x8000 /* dir: n_direofoffset is valid */
194
195#define NFS_EOFVALID(ndp) ((ndp)->n_flag & NEOFVALID)
196
197/*
198 * Convert between nfsnode pointers and vnode pointers
199 */
200#define VTONFS(vp) ((struct nfsnode *)(vp)->v_data)
201#define NFSTOV(np) ((np)->n_vnode)
202
203#ifdef _KERNEL
204
205#include <sys/workqueue.h>
206/*
207 * Silly rename structure that hangs off the nfsnode until the name
208 * can be removed by nfs_inactive()
209 */
210struct sillyrename {
211 struct work s_work;
212 kauth_cred_t s_cred;
213 struct vnode *s_dvp;
214 long s_namlen;
215 char s_name[20];
216};
217
218/*
219 * Per-nfsiod datas
220 */
221struct nfs_iod {
222 kmutex_t nid_lock;
223 kcondvar_t nid_cv;
224 LIST_ENTRY(nfs_iod) nid_idle;
225 struct nfsmount *nid_mount;
226 bool nid_exiting;
227
228 LIST_ENTRY(nfs_iod) nid_all;
229};
230
231LIST_HEAD(nfs_iodlist, nfs_iod);
232extern kmutex_t nfs_iodlist_lock;
233extern struct nfs_iodlist nfs_iodlist_idle;
234extern struct nfs_iodlist nfs_iodlist_all;
235extern u_long nfsdirhashmask;
236
237/*
238 * Prototypes for NFS vnode operations
239 */
240int nfs_lookup(void *);
241int nfs_create(void *);
242int nfs_mknod(void *);
243int nfs_open(void *);
244int nfs_close(void *);
245int nfsspec_close(void *);
246int nfsfifo_close(void *);
247int nfs_access(void *);
248int nfsspec_access(void *);
249int nfs_getattr(void *);
250int nfs_setattr(void *);
251int nfs_read(void *);
252int nfs_write(void *);
253int nfsspec_read(void *);
254int nfsspec_write(void *);
255int nfsfifo_read(void *);
256int nfsfifo_write(void *);
257#define nfs_ioctl genfs_enoioctl
258#define nfs_poll genfs_poll
259#define nfs_revoke genfs_revoke
260#define nfs_mmap genfs_mmap
261int nfs_fsync(void *);
262#define nfs_seek genfs_seek
263int nfs_remove(void *);
264int nfs_link(void *);
265int nfs_rename(void *);
266int nfs_mkdir(void *);
267int nfs_rmdir(void *);
268int nfs_symlink(void *);
269int nfs_readdir(void *);
270int nfs_readlink(void *);
271#define nfs_abortop genfs_abortop
272int nfs_inactive(void *);
273int nfs_reclaim(void *);
274#define nfs_lock genfs_lock
275int nfs_unlock(void *);
276#define nfs_islocked genfs_islocked
277int nfs_bmap(void *);
278int nfs_strategy(void *);
279int nfs_print(void *);
280int nfs_pathconf(void *);
281int nfs_advlock(void *);
282int nfs_getpages(void *);
283int nfs_putpages(void *);
284int nfs_kqfilter(void *);
285
286extern int (**nfsv2_vnodeop_p)(void *);
287
288#define NFS_INVALIDATE_ATTRCACHE(np) (np)->n_attrstamp = 0
289
290#endif /* _KERNEL */
291
292#endif
293