git: e95708d7a1bf - stable/13 - tmpfs: recalculate OBJ_TMPFS_VREF on reinstantiating node' vnode

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

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

commit e95708d7a1bf70d555da498eedc1a030a9106096
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:59:13 +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 d1aff2397cc4..a69e0357bc59 100644
--- a/sys/fs/tmpfs/tmpfs_subr.c
+++ b/sys/fs/tmpfs/tmpfs_subr.c
@@ -1061,14 +1061,18 @@ 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));
 		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: