git: 2ecfb14781cb - stable/14 - tmpfs: recalculate OBJ_TMPFS_VREF on reinstantiating node' vnode

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Mon, 20 May 2024 00:25:30 UTC
The branch stable/14 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=2ecfb14781cb28e359623ffe6e2421b1abe03231

commit 2ecfb14781cb28e359623ffe6e2421b1abe03231
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-05-06 18:31:31 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-05-19 00:57:54 +0000

    tmpfs: recalculate OBJ_TMPFS_VREF on reinstantiating node' vnode
    
    (cherry picked from commit 58d7ac11e77db28640b8e47f9f9c1fe81d15baf5)
---
 sys/fs/tmpfs/tmpfs_subr.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/sys/fs/tmpfs/tmpfs_subr.c b/sys/fs/tmpfs/tmpfs_subr.c
index ef7fca2ae185..13323d50228a 100644
--- a/sys/fs/tmpfs/tmpfs_subr.c
+++ b/sys/fs/tmpfs/tmpfs_subr.c
@@ -1053,15 +1053,19 @@ loop:
 		KASSERT((object->flags & OBJ_TMPFS_VREF) == 0,
 		    ("%s: object %p with OBJ_TMPFS_VREF but without vnode",
 		    __func__, object));
-		KASSERT(object->un_pager.swp.writemappings == 0,
-		    ("%s: object %p has writemappings",
-		    __func__, object));
 		VI_LOCK(vp);
 		KASSERT(vp->v_object == NULL, ("Not NULL v_object in tmpfs"));
 		vp->v_object = object;
 		vn_irflag_set_locked(vp, (tm->tm_pgread ? VIRF_PGREAD : 0) |
 		    VIRF_TEXT_REF);
 		VI_UNLOCK(vp);
+		VNASSERT((object->flags & OBJ_TMPFS_VREF) == 0, vp,
+		    ("leaked OBJ_TMPFS_VREF"));
+		if (object->un_pager.swp.writemappings > 0) {
+			vrefact(vp);
+			vlazy(vp);
+			vm_object_set_flag(object, OBJ_TMPFS_VREF);
+		}
 		VM_OBJECT_WUNLOCK(object);
 		break;
 	case VDIR: