svn commit: r275897 - in head/sys: cddl/contrib/opensolaris/uts/common/fs/zfs fs/ext2fs fs/fuse fs/msdosfs fs/nandfs fs/nfsclient fs/nfsserver fs/tmpfs fs/unionfs kern nfsclient nfsserver ufs/ffs u...
Konstantin Belousov
kib at FreeBSD.org
Thu Dec 18 10:01:17 UTC 2014
Author: kib
Date: Thu Dec 18 10:01:12 2014
New Revision: 275897
URL: https://svnweb.freebsd.org/changeset/base/275897
Log:
The VOP_LOOKUP() implementations for CREATE op do not put the name
into namecache, to avoid cache trashing when doing large operations.
E.g., tar archive extraction is not usually followed by access to many
of the files created.
Right now, each VOP_LOOKUP() implementation explicitely knowns about
this quirk and tests for both MAKEENTRY flag presence and op != CREATE
to make the call to cache_enter(). Centralize the handling of the
quirk into VFS, by deciding to cache only by MAKEENTRY flag in VOP.
VFS now sets NOCACHE flag for CREATE namei() calls.
Note that the change in semantic is backward-compatible and could be
merged to the stable branch, and is compatible with non-changed
third-party filesystems which correctly handle MAKEENTRY.
Suggested by: Chris Torek <torek at pi-coral.com>
Reviewed by: mckusick
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Modified:
head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
head/sys/fs/ext2fs/ext2_lookup.c
head/sys/fs/fuse/fuse_vnops.c
head/sys/fs/msdosfs/msdosfs_lookup.c
head/sys/fs/nandfs/nandfs_vnops.c
head/sys/fs/nfsclient/nfs_clvnops.c
head/sys/fs/nfsserver/nfs_nfsdserv.c
head/sys/fs/tmpfs/tmpfs_vnops.c
head/sys/fs/unionfs/union_subr.c
head/sys/fs/unionfs/union_vnops.c
head/sys/kern/uipc_usrreq.c
head/sys/kern/vfs_syscalls.c
head/sys/kern/vfs_vnops.c
head/sys/nfsclient/nfs_vnops.c
head/sys/nfsserver/nfs_serv.c
head/sys/ufs/ffs/ffs_snapshot.c
head/sys/ufs/ufs/ufs_lookup.c
Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -1548,7 +1548,7 @@ zfs_lookup(vnode_t *dvp, char *nm, vnode
/*
* Insert name into cache (as non-existent) if appropriate.
*/
- if (error == ENOENT && (cnp->cn_flags & MAKEENTRY) && nameiop != CREATE)
+ if (error == ENOENT && (cnp->cn_flags & MAKEENTRY) != 0)
cache_enter(dvp, *vpp, cnp);
/*
* Insert name into cache if appropriate.
Modified: head/sys/fs/ext2fs/ext2_lookup.c
==============================================================================
--- head/sys/fs/ext2fs/ext2_lookup.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/fs/ext2fs/ext2_lookup.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -514,7 +514,7 @@ notfound:
/*
* Insert name into cache (as non-existent) if appropriate.
*/
- if ((cnp->cn_flags & MAKEENTRY) && nameiop != CREATE)
+ if ((cnp->cn_flags & MAKEENTRY) != 0)
cache_enter(vdp, NULL, cnp);
return (ENOENT);
Modified: head/sys/fs/fuse/fuse_vnops.c
==============================================================================
--- head/sys/fs/fuse/fuse_vnops.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/fs/fuse/fuse_vnops.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -795,7 +795,7 @@ calldaemon:
* caching...)
*/
#if 0
- if ((cnp->cn_flags & MAKEENTRY) && nameiop != CREATE) {
+ if ((cnp->cn_flags & MAKEENTRY) != 0) {
FS_DEBUG("inserting NULL into cache\n");
cache_enter(dvp, NULL, cnp);
}
Modified: head/sys/fs/msdosfs/msdosfs_lookup.c
==============================================================================
--- head/sys/fs/msdosfs/msdosfs_lookup.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/fs/msdosfs/msdosfs_lookup.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -416,7 +416,7 @@ notfound:
* and 8.3 filenames. Hence, it may not invalidate all negative
* entries if a file with this name is later created.
*/
- if ((cnp->cn_flags & MAKEENTRY) && nameiop != CREATE)
+ if ((cnp->cn_flags & MAKEENTRY) != 0)
cache_enter(vdp, *vpp, cnp);
#endif
return (ENOENT);
Modified: head/sys/fs/nandfs/nandfs_vnops.c
==============================================================================
--- head/sys/fs/nandfs/nandfs_vnops.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/fs/nandfs/nandfs_vnops.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -478,7 +478,7 @@ out:
* the file might not be found and thus putting it into the namecache
* might be seen as negative caching.
*/
- if ((cnp->cn_flags & MAKEENTRY) && nameiop != CREATE)
+ if ((cnp->cn_flags & MAKEENTRY) != 0)
cache_enter(dvp, *vpp, cnp);
return (error);
Modified: head/sys/fs/nfsclient/nfs_clvnops.c
==============================================================================
--- head/sys/fs/nfsclient/nfs_clvnops.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/fs/nfsclient/nfs_clvnops.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -1184,8 +1184,7 @@ nfs_lookup(struct vop_lookup_args *ap)
return (EJUSTRETURN);
}
- if ((cnp->cn_flags & MAKEENTRY) && cnp->cn_nameiop != CREATE &&
- dattrflag) {
+ if ((cnp->cn_flags & MAKEENTRY) != 0 && dattrflag) {
/*
* Cache the modification time of the parent
* directory from the post-op attributes in
Modified: head/sys/fs/nfsserver/nfs_nfsdserv.c
==============================================================================
--- head/sys/fs/nfsserver/nfs_nfsdserv.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/fs/nfsserver/nfs_nfsdserv.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -994,7 +994,7 @@ nfsrvd_create(struct nfsrv_descript *nd,
goto out;
}
NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE,
- LOCKPARENT | LOCKLEAF | SAVESTART);
+ LOCKPARENT | LOCKLEAF | SAVESTART | NOCACHE);
nfsvno_setpathbuf(&named, &bufp, &hashp);
error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
if (error)
@@ -1205,7 +1205,7 @@ nfsrvd_mknod(struct nfsrv_descript *nd,
goto out;
}
}
- NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE, cnflags);
+ NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE, cnflags | NOCACHE);
nfsvno_setpathbuf(&named, &bufp, &hashp);
error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
if (error)
@@ -1658,7 +1658,7 @@ nfsrvd_link(struct nfsrv_descript *nd, i
}
}
NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE,
- LOCKPARENT | SAVENAME);
+ LOCKPARENT | SAVENAME | NOCACHE);
if (!nd->nd_repstat) {
nfsvno_setpathbuf(&named, &bufp, &hashp);
error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
@@ -1735,7 +1735,7 @@ nfsrvd_symlink(struct nfsrv_descript *nd
*vpp = NULL;
NFSVNO_ATTRINIT(&nva);
NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE,
- LOCKPARENT | SAVESTART);
+ LOCKPARENT | SAVESTART | NOCACHE);
nfsvno_setpathbuf(&named, &bufp, &hashp);
error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
if (!error && !nd->nd_repstat)
@@ -1853,7 +1853,7 @@ nfsrvd_mkdir(struct nfsrv_descript *nd,
goto out;
}
NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE,
- LOCKPARENT | SAVENAME);
+ LOCKPARENT | SAVENAME | NOCACHE);
nfsvno_setpathbuf(&named, &bufp, &hashp);
error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen);
if (error)
@@ -2782,7 +2782,7 @@ nfsrvd_open(struct nfsrv_descript *nd, _
}
if (create == NFSV4OPEN_CREATE)
NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, CREATE,
- LOCKPARENT | LOCKLEAF | SAVESTART);
+ LOCKPARENT | LOCKLEAF | SAVESTART | NOCACHE);
else
NFSNAMEICNDSET(&named.ni_cnd, nd->nd_cred, LOOKUP,
LOCKLEAF | SAVESTART);
Modified: head/sys/fs/tmpfs/tmpfs_vnops.c
==============================================================================
--- head/sys/fs/tmpfs/tmpfs_vnops.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/fs/tmpfs/tmpfs_vnops.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -195,7 +195,7 @@ tmpfs_lookup(struct vop_cachedlookup_arg
/* Store the result of this lookup in the cache. Avoid this if the
* request was for creation, as it does not improve timings on
* emprical tests. */
- if ((cnp->cn_flags & MAKEENTRY) && cnp->cn_nameiop != CREATE)
+ if ((cnp->cn_flags & MAKEENTRY) != 0)
cache_enter(dvp, *vpp, cnp);
out:
Modified: head/sys/fs/unionfs/union_subr.c
==============================================================================
--- head/sys/fs/unionfs/union_subr.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/fs/unionfs/union_subr.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -536,6 +536,8 @@ unionfs_relookup(struct vnode *dvp, stru
cn->cn_flags |= (cnp->cn_flags & (DOWHITEOUT | SAVESTART));
else if (RENAME == nameiop)
cn->cn_flags |= (cnp->cn_flags & SAVESTART);
+ else if (nameiop == CREATE)
+ cn->cn_flags |= NOCACHE;
vref(dvp);
VOP_UNLOCK(dvp, LK_RELEASE);
Modified: head/sys/fs/unionfs/union_vnops.c
==============================================================================
--- head/sys/fs/unionfs/union_vnops.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/fs/unionfs/union_vnops.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -160,8 +160,7 @@ unionfs_lookup(struct vop_cachedlookup_a
LK_RETRY);
vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY);
- } else if (error == ENOENT && (cnflags & MAKEENTRY) &&
- nameiop != CREATE)
+ } else if (error == ENOENT && (cnflags & MAKEENTRY) != 0)
cache_enter(dvp, NULLVP, cnp);
UNIONFS_INTERNAL_DEBUG("unionfs_lookup: leave (%d)\n", error);
@@ -337,7 +336,7 @@ unionfs_lookup_out:
if (lvp != NULLVP)
vrele(lvp);
- if (error == ENOENT && (cnflags & MAKEENTRY) && nameiop != CREATE)
+ if (error == ENOENT && (cnflags & MAKEENTRY) != 0)
cache_enter(dvp, NULLVP, cnp);
UNIONFS_INTERNAL_DEBUG("unionfs_lookup: leave (%d)\n", error);
Modified: head/sys/kern/uipc_usrreq.c
==============================================================================
--- head/sys/kern/uipc_usrreq.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/kern/uipc_usrreq.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -505,7 +505,7 @@ uipc_bindat(int fd, struct socket *so, s
buf[namelen] = 0;
restart:
- NDINIT_ATRIGHTS(&nd, CREATE, NOFOLLOW | LOCKPARENT | SAVENAME,
+ NDINIT_ATRIGHTS(&nd, CREATE, NOFOLLOW | LOCKPARENT | SAVENAME | NOCACHE,
UIO_SYSSPACE, buf, fd, cap_rights_init(&rights, CAP_BINDAT), td);
/* SHOULD BE ABLE TO ADOPT EXISTING AND wakeup() ALA FIFO's */
error = namei(&nd);
Modified: head/sys/kern/vfs_syscalls.c
==============================================================================
--- head/sys/kern/vfs_syscalls.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/kern/vfs_syscalls.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -1269,8 +1269,9 @@ kern_mknodat(struct thread *td, int fd,
return (error);
restart:
bwillwrite();
- NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1,
- pathseg, path, fd, cap_rights_init(&rights, CAP_MKNODAT), td);
+ NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1 |
+ NOCACHE, pathseg, path, fd, cap_rights_init(&rights, CAP_MKNODAT),
+ td);
if ((error = namei(&nd)) != 0)
return (error);
vp = nd.ni_vp;
@@ -1384,8 +1385,9 @@ kern_mkfifoat(struct thread *td, int fd,
AUDIT_ARG_MODE(mode);
restart:
bwillwrite();
- NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1,
- pathseg, path, fd, cap_rights_init(&rights, CAP_MKFIFOAT), td);
+ NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1 |
+ NOCACHE, pathseg, path, fd, cap_rights_init(&rights, CAP_MKFIFOAT),
+ td);
if ((error = namei(&nd)) != 0)
return (error);
if (nd.ni_vp != NULL) {
@@ -1530,8 +1532,9 @@ again:
vrele(vp);
return (EPERM); /* POSIX */
}
- NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE2,
- segflg, path2, fd2, cap_rights_init(&rights, CAP_LINKAT), td);
+ NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE2 |
+ NOCACHE, segflg, path2, fd2, cap_rights_init(&rights, CAP_LINKAT),
+ td);
if ((error = namei(&nd)) == 0) {
if (nd.ni_vp != NULL) {
NDFREE(&nd, NDF_ONLY_PNBUF);
@@ -1650,8 +1653,9 @@ kern_symlinkat(struct thread *td, char *
AUDIT_ARG_TEXT(syspath);
restart:
bwillwrite();
- NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1,
- segflg, path2, fd, cap_rights_init(&rights, CAP_SYMLINKAT), td);
+ NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1 |
+ NOCACHE, segflg, path2, fd, cap_rights_init(&rights, CAP_SYMLINKAT),
+ td);
if ((error = namei(&nd)) != 0)
goto out;
if (nd.ni_vp) {
@@ -3581,8 +3585,9 @@ kern_mkdirat(struct thread *td, int fd,
AUDIT_ARG_MODE(mode);
restart:
bwillwrite();
- NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1,
- segflg, path, fd, cap_rights_init(&rights, CAP_MKDIRAT), td);
+ NDINIT_ATRIGHTS(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1 |
+ NOCACHE, segflg, path, fd, cap_rights_init(&rights, CAP_MKDIRAT),
+ td);
nd.ni_cnd.cn_flags |= WILLBEDIR;
if ((error = namei(&nd)) != 0)
return (error);
Modified: head/sys/kern/vfs_vnops.c
==============================================================================
--- head/sys/kern/vfs_vnops.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/kern/vfs_vnops.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -189,7 +189,11 @@ restart:
fmode = *flagp;
if (fmode & O_CREAT) {
ndp->ni_cnd.cn_nameiop = CREATE;
- ndp->ni_cnd.cn_flags = ISOPEN | LOCKPARENT | LOCKLEAF;
+ /*
+ * Set NOCACHE to avoid flushing the cache when
+ * rolling in many files at once.
+ */
+ ndp->ni_cnd.cn_flags = ISOPEN | LOCKPARENT | LOCKLEAF | NOCACHE;
if ((fmode & O_EXCL) == 0 && (fmode & O_NOFOLLOW) == 0)
ndp->ni_cnd.cn_flags |= FOLLOW;
if (!(vn_open_flags & VN_OPEN_NOAUDIT))
Modified: head/sys/nfsclient/nfs_vnops.c
==============================================================================
--- head/sys/nfsclient/nfs_vnops.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/nfsclient/nfs_vnops.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -1184,8 +1184,7 @@ nfsmout:
return (EJUSTRETURN);
}
- if ((cnp->cn_flags & MAKEENTRY) && cnp->cn_nameiop != CREATE &&
- dattrflag) {
+ if ((cnp->cn_flags & MAKEENTRY) != 0 && dattrflag) {
/*
* Cache the modification time of the parent
* directory from the post-op attributes in
Modified: head/sys/nfsserver/nfs_serv.c
==============================================================================
--- head/sys/nfsserver/nfs_serv.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/nfsserver/nfs_serv.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -1217,7 +1217,7 @@ nfsrv_create(struct nfsrv_descript *nfsd
nd.ni_cnd.cn_cred = cred;
nd.ni_cnd.cn_nameiop = CREATE;
- nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | SAVESTART;
+ nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | SAVESTART | NOCACHE;
/*
* Call namei and do initial cleanup to get a few things
@@ -1501,7 +1501,7 @@ nfsrv_mknod(struct nfsrv_descript *nfsd,
nd.ni_cnd.cn_cred = cred;
nd.ni_cnd.cn_nameiop = CREATE;
- nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | SAVESTART;
+ nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | SAVESTART | NOCACHE;
/*
* Handle nfs_namei() call. If an error occurs, the nd structure
@@ -2030,7 +2030,7 @@ nfsrv_link(struct nfsrv_descript *nfsd,
VOP_UNLOCK(vp, 0);
nd.ni_cnd.cn_cred = cred;
nd.ni_cnd.cn_nameiop = CREATE;
- nd.ni_cnd.cn_flags = LOCKPARENT;
+ nd.ni_cnd.cn_flags = LOCKPARENT | NOCACHE;
error = nfs_namei(&nd, nfsd, dfhp, len, slp, nam, &md, &dpos,
&dirp, v3, &dirfor, &dirfor_ret, FALSE);
if (dirp && !v3) {
@@ -2153,7 +2153,7 @@ nfsrv_symlink(struct nfsrv_descript *nfs
nfsm_srvnamesiz(len);
nd.ni_cnd.cn_cred = cred;
nd.ni_cnd.cn_nameiop = CREATE;
- nd.ni_cnd.cn_flags = LOCKPARENT | SAVESTART;
+ nd.ni_cnd.cn_flags = LOCKPARENT | SAVESTART | NOCACHE;
error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos,
&dirp, v3, &dirfor, &dirfor_ret, FALSE);
if (error == 0) {
@@ -2325,7 +2325,7 @@ nfsrv_mkdir(struct nfsrv_descript *nfsd,
nfsm_srvnamesiz(len);
nd.ni_cnd.cn_cred = cred;
nd.ni_cnd.cn_nameiop = CREATE;
- nd.ni_cnd.cn_flags = LOCKPARENT;
+ nd.ni_cnd.cn_flags = LOCKPARENT | NOCACHE;
error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos,
&dirp, v3, &dirfor, &dirfor_ret, FALSE);
Modified: head/sys/ufs/ffs/ffs_snapshot.c
==============================================================================
--- head/sys/ufs/ffs/ffs_snapshot.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/ufs/ffs/ffs_snapshot.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -256,7 +256,8 @@ ffs_snapshot(mp, snapfile)
* Create the snapshot file.
*/
restart:
- NDINIT(&nd, CREATE, LOCKPARENT | LOCKLEAF, UIO_SYSSPACE, snapfile, td);
+ NDINIT(&nd, CREATE, LOCKPARENT | LOCKLEAF | NOCACHE, UIO_SYSSPACE,
+ snapfile, td);
if ((error = namei(&nd)) != 0)
return (error);
if (nd.ni_vp != NULL) {
Modified: head/sys/ufs/ufs/ufs_lookup.c
==============================================================================
--- head/sys/ufs/ufs/ufs_lookup.c Thu Dec 18 08:49:50 2014 (r275896)
+++ head/sys/ufs/ufs/ufs_lookup.c Thu Dec 18 10:01:12 2014 (r275897)
@@ -550,7 +550,7 @@ notfound:
/*
* Insert name into cache (as non-existent) if appropriate.
*/
- if ((cnp->cn_flags & MAKEENTRY) && nameiop != CREATE)
+ if ((cnp->cn_flags & MAKEENTRY) != 0)
cache_enter(vdp, NULL, cnp);
return (ENOENT);
More information about the svn-src-all
mailing list