2 /* $Id: nfs4_vn_subs.c,v 1.9 2003/11/05 14:59:00 rees Exp $ */
6 * the regents of the university of michigan
9 * permission is granted to use, copy, create derivative works and redistribute
10 * this software and such derivative works for any purpose, so long as the name
11 * of the university of michigan is not used in any advertising or publicity
12 * pertaining to the use or distribution of this software without specific,
13 * written prior authorization. if the above copyright notice or any other
14 * identification of the university of michigan is included in any copy of any
15 * portion of this software, then the disclaimer below must also be included.
17 * this software is provided as is, without representation from the university
18 * of michigan as to its fitness for any purpose, and without warranty by the
19 * university of michigan of any kind, either express or implied, including
20 * without limitation the implied warranties of merchantability and fitness for
21 * a particular purpose. the regents of the university of michigan shall not be
22 * liable for any damages, including special, indirect, incidental, or
23 * consequential damages, with respect to any claim arising out of or in
24 * connection with the use of the software, even if it has been or is hereafter
25 * advised of the possibility of such damages.
28 #include <sys/param.h>
29 #include <sys/systm.h>
30 #include <sys/kernel.h>
31 #include <sys/limits.h>
33 #include <sys/malloc.h>
35 #include <sys/module.h>
36 #include <sys/mount.h>
38 #include <sys/socket.h>
39 #include <sys/socketvar.h>
40 #include <sys/sockio.h>
41 #include <sys/vnode.h>
42 #include <sys/types.h>
45 #include <vm/vm_extern.h>
49 #include <net/route.h>
50 #include <netinet/in.h>
52 #include <rpc/rpcclnt.h>
54 #include <nfs/rpcv2.h>
55 #include <nfs/nfsproto.h>
56 #include <nfsclient/nfs.h>
57 #include <nfsclient/nfsmount.h>
58 #include <nfs/xdr_subs.h>
59 #include <nfsclient/nfsm_subs.h>
60 #include <nfsclient/nfsdiskless.h>
63 #include <nfs4client/nfs4.h>
64 #include <nfs4client/nfs4m_subs.h>
65 #include <nfs4client/nfs4_vn.h>
67 #include <nfsclient/nfsnode.h>
70 nfs4_vnop_loadattrcache(struct vnode *vp, struct nfsv4_fattr *fap,
78 struct timespec mtime;
83 vtyp = nv3tov_type[fap->fa4_type & 0x7];
84 vmode = (fap->fa4_valid & FA4V_MODE) ? fap->fa4_mode : 0777;
85 rdev = (fap->fa4_valid & FA4V_RDEV) ?
86 makedev(fap->fa4_rdev_major, fap->fa4_rdev_minor) : 0;
87 if (fap->fa4_valid & FA4V_MTIME)
88 mtime = fap->fa4_mtime;
90 bzero(&mtime, sizeof mtime);
93 * If v_type == VNON it is a new node, so fill in the v_type,
94 * n_mtime fields. Check to see if it represents a special
95 * device, and if so, check for a possible alias. Once the
96 * correct vnode has been obtained, fill in the rest of the
101 if (vp->v_type != vtyp || np->n_mtime.tv_sec == 0) {
102 bzero(vap, sizeof *vap);
104 np->n_mtime.tv_sec = mtime.tv_sec;
107 vap->va_mode = (vmode & 07777);
109 vap->va_mtime = mtime;
110 vap->va_fsid = vp->v_mount->mnt_stat.f_fsid.val[0];
111 if (fap->fa4_valid & FA4V_NLINK)
112 vap->va_nlink = fap->fa4_nlink;
113 if (fap->fa4_valid & FA4V_UID)
114 vap->va_uid = fap->fa4_uid;
115 if (fap->fa4_valid & FA4V_GID)
116 vap->va_gid = fap->fa4_gid;
117 vap->va_size = fap->fa4_size;
118 vap->va_blocksize = NFS_FABLKSIZE;
119 vap->va_bytes = fap->fa4_size;
120 if (fap->fa4_valid & FA4V_FILEID)
121 vap->va_fileid = nfs_v4fileid4_to_fileid(fap->fa4_fileid);
122 if (fap->fa4_valid & FA4V_ATIME)
123 vap->va_atime = fap->fa4_atime;
124 if (fap->fa4_valid & FA4V_BTIME)
125 vap->va_birthtime = fap->fa4_btime;
126 if (fap->fa4_valid & FA4V_CTIME)
127 vap->va_ctime = fap->fa4_ctime;
130 /* XXX dontshrink flag? */
131 if (vap->va_size != np->n_size) {
132 if (vap->va_type == VREG) {
133 if (np->n_flag & NMODIFIED) {
134 if (vap->va_size < np->n_size)
135 vap->va_size = np->n_size;
137 np->n_size = vap->va_size;
139 np->n_size = vap->va_size;
140 vnode_pager_setsize(vp, np->n_size);
142 np->n_size = vap->va_size;
144 np->n_attrstamp = tv.tv_sec;
146 bcopy((caddr_t)vap, (caddr_t)vaper, sizeof(*vap));
147 if (np->n_flag & NCHG) {
148 if (np->n_flag & NACC)
149 vaper->va_atime = np->n_atim;
150 if (np->n_flag & NUPD)
151 vaper->va_mtime = np->n_mtim;
156 static uint64_t nfs_nullcookie = 0;
158 * This function finds the directory cookie that corresponds to the
159 * logical byte offset given.
162 nfs4_getcookie(struct nfsnode *np, off_t off, int add)
164 struct nfsdmap *dp, *dp2;
167 pos = (uoff_t)off / NFS_DIRBLKSIZ;
168 if (pos == 0 || off < 0) {
171 panic("nfs getcookie add at <= 0");
173 return (&nfs_nullcookie);
176 dp = LIST_FIRST(&np->n_cookies);
179 MALLOC(dp, struct nfsdmap *, sizeof (struct nfsdmap),
180 M_NFSDIROFF, M_WAITOK);
181 dp->ndm_eocookie = 0;
182 LIST_INSERT_HEAD(&np->n_cookies, dp, ndm_list);
186 while (pos >= NFSNUMCOOKIES) {
187 pos -= NFSNUMCOOKIES;
188 if (LIST_NEXT(dp, ndm_list)) {
189 if (!add && dp->ndm_eocookie < NFSNUMCOOKIES &&
190 pos >= dp->ndm_eocookie)
192 dp = LIST_NEXT(dp, ndm_list);
194 MALLOC(dp2, struct nfsdmap *, sizeof (struct nfsdmap),
195 M_NFSDIROFF, M_WAITOK);
196 dp2->ndm_eocookie = 0;
197 LIST_INSERT_AFTER(dp, dp2, ndm_list);
202 if (pos >= dp->ndm_eocookie) {
204 dp->ndm_eocookie = pos + 1;
208 return (&dp->ndm4_cookies[pos]);
212 * Invalidate cached directory information, except for the actual directory
213 * blocks (which are invalidated separately).
214 * Done mainly to avoid the use of stale offset cookies.
217 nfs4_invaldir(struct vnode *vp)
219 struct nfsnode *np = VTONFS(vp);
221 np->n_direofoffset = 0;
222 bzero(np->n4_cookieverf, NFSX_V4VERF);
223 if (LIST_FIRST(&np->n_cookies))
224 LIST_FIRST(&np->n_cookies)->ndm_eocookie = 0;