FreeBSD Bugzilla – Attachment 228973 Details for
Bug 259071
Read past EoF in NFS client and fusefs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
timestamp file modifications so Lookup can discard stale attributes
stat.patch (text/plain), 5.07 KB, created by
Rick Macklem
on 2021-10-24 01:42:44 UTC
(
hide
)
Description:
timestamp file modifications so Lookup can discard stale attributes
Filename:
MIME Type:
Creator:
Rick Macklem
Created:
2021-10-24 01:42:44 UTC
Size:
5.07 KB
patch
obsolete
>--- sys/fs/nfsclient/nfs_clvnops.c.stat 2021-10-23 08:21:28.878849000 -0700 >+++ sys/fs/nfsclient/nfs_clvnops.c 2021-10-23 17:43:14.386998000 -0700 >@@ -301,6 +301,10 @@ int newnfs_directio_allow_mmap = 1; > SYSCTL_INT(_vfs_nfs, OID_AUTO, nfs_directio_allow_mmap, CTLFLAG_RW, > &newnfs_directio_allow_mmap, 0, "Enable mmaped IO on file with O_DIRECT opens"); > >+static int lookupcnt = 0; >+SYSCTL_INT(_vfs_nfs, OID_AUTO, lookupcnt, CTLFLAG_RD, >+ &lookupcnt, 0, " "); >+ > static uint64_t nfs_maxalloclen = 64 * 1024 * 1024; > SYSCTL_U64(_vfs_nfs, OID_AUTO, maxalloclen, CTLFLAG_RW, > &nfs_maxalloclen, 0, "NFS max allocate/deallocate length"); >@@ -1014,6 +1018,7 @@ nfs_setattr(struct vop_setattr_args *ap) > struct vattr *vap = ap->a_vap; > int error = 0; > u_quad_t tsize; >+ struct timespec ts; > > #ifndef nolint > tsize = (u_quad_t)0; >@@ -1108,11 +1113,18 @@ nfs_setattr(struct vop_setattr_args *ap) > NFSUNLOCKNODE(np); > } > error = nfs_setattrrpc(vp, vap, ap->a_cred, td); >- if (error && vap->va_size != VNOVAL) { >- NFSLOCKNODE(np); >- np->n_size = np->n_vattr.na_size = tsize; >- vnode_pager_setsize(vp, tsize); >- NFSUNLOCKNODE(np); >+ if (vap->va_size != VNOVAL) { >+ if (error == 0) { >+ nanouptime(&ts); >+ NFSLOCKNODE(np); >+ np->n_localmodtime = ts; >+ NFSUNLOCKNODE(np); >+ } else { >+ NFSLOCKNODE(np); >+ np->n_size = np->n_vattr.na_size = tsize; >+ vnode_pager_setsize(vp, tsize); >+ NFSUNLOCKNODE(np); >+ } > } > return (error); > } >@@ -1169,7 +1181,7 @@ nfs_lookup(struct vop_lookup_args *ap) > struct nfsfh *nfhp; > struct nfsvattr dnfsva, nfsva; > struct vattr vattr; >- struct timespec nctime; >+ struct timespec nctime, ts; > uint32_t openmode; > > *vpp = NULLVP; >@@ -1293,6 +1305,7 @@ nfs_lookup(struct vop_lookup_args *ap) > > newvp = NULLVP; > NFSINCRGLOBAL(nfsstatsv1.lookupcache_misses); >+ nanouptime(&ts); > error = nfsrpc_lookup(dvp, cnp->cn_nameptr, cnp->cn_namelen, > cnp->cn_cred, td, &dnfsva, &nfsva, &nfhp, &attrflag, &dattrflag, > NULL, openmode); >@@ -1359,6 +1372,21 @@ nfs_lookup(struct vop_lookup_args *ap) > if (error) > return (error); > newvp = NFSTOV(np); >+ /* >+ * If n_localmodtime >= time before RPC, then >+ * a file modification operation, such as >+ * VOP_SETATTR() of size, has occurred while >+ * the Lookup RPC and acquisition of the vnode >+ * happened. As such, the attributes might >+ * be stale, with possibly an incorrect size. >+ */ >+ NFSLOCKNODE(np); >+ if (timespecisset(&np->n_localmodtime) && >+ timespeccmp(&np->n_localmodtime, &ts, >=)) >+{ lookupcnt++; >+ attrflag = 0; >+} >+ NFSUNLOCKNODE(np); > if (attrflag) > (void) nfscl_loadattrcache(&newvp, &nfsva, NULL, NULL, > 0, 1); >@@ -1418,6 +1446,21 @@ nfs_lookup(struct vop_lookup_args *ap) > if (error) > return (error); > newvp = NFSTOV(np); >+ /* >+ * If n_localmodtime >= time before RPC, then >+ * a file modification operation, such as >+ * VOP_SETATTR() of size, has occurred while >+ * the Lookup RPC and acquisition of the vnode >+ * happened. As such, the attributes might >+ * be stale, with possibly an incorrect size. >+ */ >+ NFSLOCKNODE(np); >+ if (timespecisset(&np->n_localmodtime) && >+ timespeccmp(&np->n_localmodtime, &ts, >=)) >+{ lookupcnt++; >+ attrflag = 0; >+} >+ NFSUNLOCKNODE(np); > if (attrflag) > (void) nfscl_loadattrcache(&newvp, &nfsva, NULL, NULL, > 0, 1); >@@ -3643,11 +3686,14 @@ nfs_allocate(struct vop_allocate_args *ap) > struct thread *td = curthread; > struct nfsvattr nfsva; > struct nfsmount *nmp; >+ struct nfsnode *np; > off_t alen; > int attrflag, error, ret; >+ struct timespec ts; > > attrflag = 0; > nmp = VFSTONFS(vp->v_mount); >+ np = VTONFS(vp); > mtx_lock(&nmp->nm_mtx); > if (NFSHASNFSV4(nmp) && nmp->nm_minorvers >= NFSV42_MINORVERSION && > (nmp->nm_privflag & NFSMNTP_NOALLOCATE) == 0) { >@@ -3667,6 +3713,10 @@ nfs_allocate(struct vop_allocate_args *ap) > if (error == 0) { > *ap->a_offset += alen; > *ap->a_len -= alen; >+ nanouptime(&ts); >+ NFSLOCKNODE(np); >+ np->n_localmodtime = ts; >+ NFSUNLOCKNODE(np); > } else if (error == NFSERR_NOTSUPP) { > mtx_lock(&nmp->nm_mtx); > nmp->nm_privflag |= NFSMNTP_NOALLOCATE; >@@ -3701,6 +3751,7 @@ nfs_deallocate(struct vop_deallocate_args *ap) > off_t tlen, mlen; > int attrflag, error, ret; > bool clipped; >+ struct timespec ts; > > error = 0; > attrflag = 0; >@@ -3743,6 +3794,10 @@ nfs_deallocate(struct vop_deallocate_args *ap) > if (error == 0) { > NFSCL_DEBUG(4, "dealloc: attrflag=%d na_size=%ju\n", > attrflag, (uintmax_t)nfsva.na_size); >+ nanouptime(&ts); >+ NFSLOCKNODE(np); >+ np->n_localmodtime = ts; >+ NFSUNLOCKNODE(np); > if (attrflag != 0) { > if ((uint64_t)*ap->a_offset < nfsva.na_size) > *ap->a_offset += omin((off_t) >--- sys/fs/nfsclient/nfsnode.h.stat 2021-10-21 14:33:13.350971000 -0700 >+++ sys/fs/nfsclient/nfsnode.h 2021-10-22 17:56:03.072484000 -0700 >@@ -129,6 +129,7 @@ struct nfsnode { > struct nfsv4node *n_v4; /* extra V4 stuff */ > struct ucred *n_writecred; /* Cred. for putpages */ > struct nfsclopen *n_openstateid; /* Cached open stateid */ >+ struct timespec n_localmodtime; /* Last local modify */ > }; > > #define n_atim n_un1.nf_atim
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 259071
:
228584
|
228935
| 228973 |
229053