git: 225b93b1700e - stable/13 - cache: add cache_enter_time_flags

Mateusz Guzik mjg at FreeBSD.org
Sun Jul 25 07:03:00 UTC 2021


The branch stable/13 has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=225b93b1700e687b6a5fdad88053e639c8f81ee2

commit 225b93b1700e687b6a5fdad88053e639c8f81ee2
Author:     Mateusz Guzik <mjg at FreeBSD.org>
AuthorDate: 2021-07-08 07:56:27 +0000
Commit:     Mateusz Guzik <mjg at FreeBSD.org>
CommitDate: 2021-07-25 06:59:56 +0000

    cache: add cache_enter_time_flags
    
    (cherry picked from commit 844aa31c6d8785e7256a84d8ee7e8ae2362f9367)
---
 sys/kern/vfs_cache.c | 24 ++++++++++++++++++++++++
 sys/sys/vnode.h      |  6 ++++++
 2 files changed, 30 insertions(+)

diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c
index 5b978511db17..09f926d0cd31 100644
--- a/sys/kern/vfs_cache.c
+++ b/sys/kern/vfs_cache.c
@@ -2582,6 +2582,30 @@ out_unlock_free:
 	return;
 }
 
+/*
+ * A variant of the above accepting flags.
+ *
+ * - VFS_CACHE_DROPOLD -- if a conflicting entry is found, drop it.
+ *
+ * TODO: this routine is a hack. It blindly removes the old entry, even if it
+ * happens to match and it is doing it in an inefficient manner. It was added
+ * to accomodate NFS which runs into a case where the target for a given name
+ * may change from under it. Note this does nothing to solve the following
+ * race: 2 callers of cache_enter_time_flags pass a different target vnode for
+ * the same [dvp, cnp]. It may be argued that code doing this is broken.
+ */
+void
+cache_enter_time_flags(struct vnode *dvp, struct vnode *vp, struct componentname *cnp,
+    struct timespec *tsp, struct timespec *dtsp, int flags)
+{
+
+	MPASS((flags & ~(VFS_CACHE_DROPOLD)) == 0);
+
+	if (flags & VFS_CACHE_DROPOLD)
+		cache_remove_cnp(dvp, cnp);
+	cache_enter_time(dvp, vp, cnp, tsp, dtsp);
+}
+
 static u_int
 cache_roundup_2(u_int val)
 {
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index f492b3389d0e..8b14aac36df0 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -638,6 +638,12 @@ int	bnoreuselist(struct bufv *bufv, struct bufobj *bo, daddr_t startn,
 	    daddr_t endn);
 /* cache_* may belong in namei.h. */
 void	cache_changesize(u_long newhashsize);
+
+#define	VFS_CACHE_DROPOLD	0x1
+
+void	cache_enter_time_flags(struct vnode *dvp, struct vnode *vp,
+	    struct componentname *cnp, struct timespec *tsp,
+	    struct timespec *dtsp, int flags);
 #define	cache_enter(dvp, vp, cnp)					\
 	cache_enter_time(dvp, vp, cnp, NULL, NULL)
 void	cache_enter_time(struct vnode *dvp, struct vnode *vp,


More information about the dev-commits-src-all mailing list