Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 18 Jan 2024 01:14:01 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: 282fd2c39ee6 - stable/13 - Add vnode_pager_clean_{a,}sync(9)
Message-ID:  <202401180114.40I1E1qm053389@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by kib:

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

commit 282fd2c39ee6df6104d54388f622471fe3e7ab3a
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-01-08 05:18:40 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2024-01-18 01:02:52 +0000

    Add vnode_pager_clean_{a,}sync(9)
    
    (cherry picked from commit b068bb09a1a82d9fef0e939ad6135443a959e290)
---
 .../openzfs/include/os/freebsd/spl/sys/vnode.h     |  9 +++---
 sys/fs/fuse/fuse_io.c                              |  7 ++--
 sys/fs/nfsclient/nfs_clbio.c                       |  8 ++---
 sys/fs/nfsclient/nfs_clnode.c                      | 17 +++-------
 sys/fs/nfsclient/nfs_clvnops.c                     | 27 ++++------------
 sys/fs/nfsserver/nfs_nfsdport.c                    |  8 ++---
 sys/fs/smbfs/smbfs_io.c                            |  7 +---
 sys/kern/vfs_aio.c                                 |  9 ++----
 sys/kern/vfs_subr.c                                | 37 ++++++++--------------
 sys/kern/vfs_syscalls.c                            |  7 ++--
 sys/kern/vfs_vnops.c                               |  9 ++----
 sys/sys/param.h                                    |  2 +-
 sys/ufs/ffs/ffs_rawread.c                          | 14 +++-----
 sys/ufs/ufs/ufs_bmap.c                             |  9 ++----
 sys/vm/vnode_pager.c                               | 27 ++++++++++++++++
 sys/vm/vnode_pager.h                               |  3 ++
 16 files changed, 82 insertions(+), 118 deletions(-)

diff --git a/sys/contrib/openzfs/include/os/freebsd/spl/sys/vnode.h b/sys/contrib/openzfs/include/os/freebsd/spl/sys/vnode.h
index 00f718eadb3f..29f4642580c6 100644
--- a/sys/contrib/openzfs/include/os/freebsd/spl/sys/vnode.h
+++ b/sys/contrib/openzfs/include/os/freebsd/spl/sys/vnode.h
@@ -61,6 +61,7 @@ enum symfollow { NO_FOLLOW = NOFOLLOW };
 #include <sys/syscallsubr.h>
 #include <sys/vm.h>
 #include <vm/vm_object.h>
+#include <vm/vnode_pager.h>
 
 typedef	struct vop_vector	vnodeops_t;
 #define	VOP_FID		VOP_VPTOFH
@@ -95,11 +96,11 @@ vn_flush_cached_data(vnode_t *vp, boolean_t sync)
 #else
 	if (vp->v_object->flags & OBJ_MIGHTBEDIRTY) {
 #endif
-		int flags = sync ? OBJPC_SYNC : 0;
 		vn_lock(vp, LK_SHARED | LK_RETRY);
-		zfs_vmobject_wlock(vp->v_object);
-		vm_object_page_clean(vp->v_object, 0, 0, flags);
-		zfs_vmobject_wunlock(vp->v_object);
+		if (sync)
+			vnode_pager_clean_sync(vp);
+		else
+			vnode_pager_clean_async(vp);
 		VOP_UNLOCK(vp);
 	}
 }
diff --git a/sys/fs/fuse/fuse_io.c b/sys/fs/fuse/fuse_io.c
index 5dffe44e95c0..0646246545cc 100644
--- a/sys/fs/fuse/fuse_io.c
+++ b/sys/fs/fuse/fuse_io.c
@@ -96,6 +96,7 @@
 #include <vm/vm_map.h>
 #include <vm/vm_page.h>
 #include <vm/vm_object.h>
+#include <vm/vnode_pager.h>
 
 #include "fuse.h"
 #include "fuse_file.h"
@@ -945,11 +946,7 @@ fuse_io_invalbuf(struct vnode *vp, struct thread *td)
 	}
 	fvdat->flag |= FN_FLUSHINPROG;
 
-	if (vp->v_bufobj.bo_object != NULL) {
-		VM_OBJECT_WLOCK(vp->v_bufobj.bo_object);
-		vm_object_page_clean(vp->v_bufobj.bo_object, 0, 0, OBJPC_SYNC);
-		VM_OBJECT_WUNLOCK(vp->v_bufobj.bo_object);
-	}
+	vnode_pager_clean_sync(vp);
 	error = vinvalbuf(vp, V_SAVE, PCATCH, 0);
 	while (error) {
 		if (error == ERESTART || error == EINTR) {
diff --git a/sys/fs/nfsclient/nfs_clbio.c b/sys/fs/nfsclient/nfs_clbio.c
index f6b8cc0a70a4..9a471f6681ca 100644
--- a/sys/fs/nfsclient/nfs_clbio.c
+++ b/sys/fs/nfsclient/nfs_clbio.c
@@ -1439,11 +1439,9 @@ ncl_vinvalbuf(struct vnode *vp, int flags, struct thread *td, int intrflg)
 	/*
 	 * Now, flush as required.
 	 */
-	if ((flags & (V_SAVE | V_VMIO)) == V_SAVE &&
-	     vp->v_bufobj.bo_object != NULL) {
-		VM_OBJECT_WLOCK(vp->v_bufobj.bo_object);
-		vm_object_page_clean(vp->v_bufobj.bo_object, 0, 0, OBJPC_SYNC);
-		VM_OBJECT_WUNLOCK(vp->v_bufobj.bo_object);
+	if ((flags & (V_SAVE | V_VMIO)) == V_SAVE) {
+		vnode_pager_clean_sync(vp);
+
 		/*
 		 * If the page clean was interrupted, fail the invalidation.
 		 * Not doing so, we run the risk of losing dirty pages in the
diff --git a/sys/fs/nfsclient/nfs_clnode.c b/sys/fs/nfsclient/nfs_clnode.c
index a7ace3cdadc9..203c3360e792 100644
--- a/sys/fs/nfsclient/nfs_clnode.c
+++ b/sys/fs/nfsclient/nfs_clnode.c
@@ -48,6 +48,8 @@
 #include <sys/taskqueue.h>
 #include <sys/vnode.h>
 
+#include <vm/vm_param.h>
+#include <vm/vnode_pager.h>
 #include <vm/uma.h>
 
 #include <fs/nfs/nfsport.h>
@@ -236,7 +238,6 @@ ncl_inactive(struct vop_inactive_args *ap)
 	struct vnode *vp = ap->a_vp;
 	struct nfsnode *np;
 	struct thread *td;
-	boolean_t retv;
 
 	td = curthread;
 	np = VTONFS(vp);
@@ -250,17 +251,9 @@ ncl_inactive(struct vop_inactive_args *ap)
 		 * buffers/pages must be flushed before the close, so that the
 		 * stateid is available for the writes.
 		 */
-		if (vp->v_object != NULL) {
-			VM_OBJECT_WLOCK(vp->v_object);
-			retv = vm_object_page_clean(vp->v_object, 0, 0,
-			    OBJPC_SYNC);
-			VM_OBJECT_WUNLOCK(vp->v_object);
-		} else
-			retv = TRUE;
-		if (retv == TRUE) {
-			(void)ncl_flush(vp, MNT_WAIT, td, 1, 0);
-			(void)nfsrpc_close(vp, 1, td);
-		}
+		vnode_pager_clean_sync(vp);
+		(void)ncl_flush(vp, MNT_WAIT, td, 1, 0);
+		(void)nfsrpc_close(vp, 1, td);
 	}
 
 	NFSLOCKNODE(np);
diff --git a/sys/fs/nfsclient/nfs_clvnops.c b/sys/fs/nfsclient/nfs_clvnops.c
index 05948b4d6ef6..411b7f82a445 100644
--- a/sys/fs/nfsclient/nfs_clvnops.c
+++ b/sys/fs/nfsclient/nfs_clvnops.c
@@ -67,6 +67,7 @@
 #include <vm/vm.h>
 #include <vm/vm_extern.h>
 #include <vm/vm_object.h>
+#include <vm/vnode_pager.h>
 
 #include <fs/nfs/nfsport.h>
 #include <fs/nfsclient/nfsnode.h>
@@ -764,9 +765,7 @@ nfs_open(struct vop_open_args *ap)
 				if (VN_IS_DOOMED(vp))
 					return (EBADF);
 			}
-			VM_OBJECT_WLOCK(obj);
-			vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
-			VM_OBJECT_WUNLOCK(obj);
+			vnode_pager_clean_sync(vp);
 		}
 
 		/* Now, flush the buffer cache. */
@@ -852,9 +851,7 @@ nfs_close(struct vop_close_args *ap)
 			if (VN_IS_DOOMED(vp) && ap->a_fflag != FNONBLOCK)
 				return (EBADF);
 		}
-		VM_OBJECT_WLOCK(vp->v_object);
-		vm_object_page_clean(vp->v_object, 0, 0, 0);
-		VM_OBJECT_WUNLOCK(vp->v_object);
+		vnode_pager_clean_async(vp);
 	    }
 	    NFSLOCKNODE(np);
 	    if (np->n_flag & NMODIFIED) {
@@ -3663,7 +3660,6 @@ nfs_allocate(struct vop_allocate_args *ap)
 {
 	struct vnode *vp = ap->a_vp;
 	struct thread *td = curthread;
-	vm_object_t obj;
 	struct nfsvattr nfsva;
 	struct nfsmount *nmp;
 	struct nfsnode *np;
@@ -3693,12 +3689,7 @@ nfs_allocate(struct vop_allocate_args *ap)
 		 * file's allocation on the server.
 		 */
 		if (error == 0) {
-			obj = vp->v_object;
-			if (obj != NULL) {
-				VM_OBJECT_WLOCK(obj);
-				vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
-				VM_OBJECT_WUNLOCK(obj);
-			}
+			vnode_pager_clean_sync(vp);
 			error = ncl_flush(vp, MNT_WAIT, td, 1, 0);
 		}
 		if (error == 0)
@@ -3833,9 +3824,7 @@ relock:
 					vn_finished_write(mp);
 				goto relock;
 			}
-			VM_OBJECT_WLOCK(invp_obj);
-			vm_object_page_clean(invp_obj, 0, 0, OBJPC_SYNC);
-			VM_OBJECT_WUNLOCK(invp_obj);
+			vnode_pager_clean_sync(invp);
 		}
 		error = ncl_flush(invp, MNT_WAIT, curthread, 1, 0);
 	}
@@ -3980,7 +3969,6 @@ static int
 nfs_ioctl(struct vop_ioctl_args *ap)
 {
 	struct vnode *vp = ap->a_vp;
-	vm_object_t obj;
 	struct nfsvattr nfsva;
 	struct nfsmount *nmp;
 	int attrflag, content, error, ret;
@@ -4025,10 +4013,7 @@ nfs_ioctl(struct vop_ioctl_args *ap)
 		 * size is up to date on the Metadata Server.
 		 */
 
-		obj = vp->v_object;
-		VM_OBJECT_WLOCK(obj);
-		vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
-		VM_OBJECT_WUNLOCK(obj);
+		vnode_pager_clean_sync(vp);
 		error = ncl_flush(vp, MNT_WAIT, ap->a_td, 1, 0);
 		if (error == 0)
 			error = nfsrpc_seek(vp, (off_t *)ap->a_data, &eof,
diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c
index 05cebdd13f7d..ebc560836205 100644
--- a/sys/fs/nfsserver/nfs_nfsdport.c
+++ b/sys/fs/nfsserver/nfs_nfsdport.c
@@ -52,6 +52,8 @@
 #include <sys/sysctl.h>
 #include <nlm/nlm_prot.h>
 #include <nlm/nlm.h>
+#include <vm/vm_param.h>
+#include <vm/vnode_pager.h>
 
 FEATURE(nfsd, "NFSv4 server");
 
@@ -1735,11 +1737,7 @@ nfsvno_fsync(struct vnode *vp, u_int64_t off, int cnt, struct ucred *cred,
 		/*
 		 * Give up and do the whole thing
 		 */
-		if (vp->v_object && vm_object_mightbedirty(vp->v_object)) {
-			VM_OBJECT_WLOCK(vp->v_object);
-			vm_object_page_clean(vp->v_object, 0, 0, OBJPC_SYNC);
-			VM_OBJECT_WUNLOCK(vp->v_object);
-		}
+		vnode_pager_clean_sync(vp);
 		error = VOP_FSYNC(vp, MNT_WAIT, td);
 	} else {
 		/*
diff --git a/sys/fs/smbfs/smbfs_io.c b/sys/fs/smbfs/smbfs_io.c
index f09254289769..324f38abd10e 100644
--- a/sys/fs/smbfs/smbfs_io.c
+++ b/sys/fs/smbfs/smbfs_io.c
@@ -636,12 +636,7 @@ smbfs_vinvalbuf(struct vnode *vp, struct thread *td)
 	}
 	np->n_flag |= NFLUSHINPROG;
 
-	if (vp->v_bufobj.bo_object != NULL) {
-		VM_OBJECT_WLOCK(vp->v_bufobj.bo_object);
-		vm_object_page_clean(vp->v_bufobj.bo_object, 0, 0, OBJPC_SYNC);
-		VM_OBJECT_WUNLOCK(vp->v_bufobj.bo_object);
-	}
-
+	vnode_pager_clean_sync(vp);
 	error = vinvalbuf(vp, V_SAVE, PCATCH, 0);
 	while (error) {
 		if (error == ERESTART || error == EINTR) {
diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c
index 1bdd32ed7969..a5b179e9d7d3 100644
--- a/sys/kern/vfs_aio.c
+++ b/sys/kern/vfs_aio.c
@@ -68,6 +68,7 @@
 #include <vm/pmap.h>
 #include <vm/vm_map.h>
 #include <vm/vm_object.h>
+#include <vm/vnode_pager.h>
 #include <vm/uma.h>
 #include <sys/aio.h>
 
@@ -718,7 +719,6 @@ static int
 aio_fsync_vnode(struct thread *td, struct vnode *vp, int op)
 {
 	struct mount *mp;
-	vm_object_t obj;
 	int error;
 
 	for (;;) {
@@ -726,12 +726,7 @@ aio_fsync_vnode(struct thread *td, struct vnode *vp, int op)
 		if (error != 0)
 			break;
 		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
-		obj = vp->v_object;
-		if (obj != NULL) {
-			VM_OBJECT_WLOCK(obj);
-			vm_object_page_clean(obj, 0, 0, 0);
-			VM_OBJECT_WUNLOCK(obj);
-		}
+		vnode_pager_clean_async(vp);
 		if (op == LIO_DSYNC)
 			error = VOP_FDATASYNC(vp, td);
 		else
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 1166fd6c5389..33232987705e 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -95,6 +95,7 @@
 #include <vm/vm_map.h>
 #include <vm/vm_page.h>
 #include <vm/vm_kern.h>
+#include <vm/vnode_pager.h>
 #include <vm/uma.h>
 
 #if defined(DEBUG_VFS_LOCKS) && (!defined(INVARIANTS) || !defined(WITNESS))
@@ -4016,7 +4017,6 @@ vdrop_recycle(struct vnode *vp)
 static int
 vinactivef(struct vnode *vp)
 {
-	struct vm_object *obj;
 	int error;
 
 	ASSERT_VOP_ELOCKED(vp, "vinactive");
@@ -4027,6 +4027,7 @@ vinactivef(struct vnode *vp)
 	vp->v_iflag |= VI_DOINGINACT;
 	vp->v_iflag &= ~VI_OWEINACT;
 	VI_UNLOCK(vp);
+
 	/*
 	 * Before moving off the active list, we must be sure that any
 	 * modified pages are converted into the vnode's dirty
@@ -4037,12 +4038,9 @@ vinactivef(struct vnode *vp)
 	 * point that VOP_INACTIVE() is called, there could still be
 	 * pending I/O and dirty pages in the object.
 	 */
-	if ((obj = vp->v_object) != NULL && (vp->v_vflag & VV_NOSYNC) == 0 &&
-	    vm_object_mightbedirty(obj)) {
-		VM_OBJECT_WLOCK(obj);
-		vm_object_page_clean(obj, 0, 0, 0);
-		VM_OBJECT_WUNLOCK(obj);
-	}
+	if ((vp->v_vflag & VV_NOSYNC) == 0)
+		vnode_pager_clean_async(vp);
+
 	error = VOP_INACTIVE(vp);
 	VI_LOCK(vp);
 	VNASSERT(vp->v_iflag & VI_DOINGINACT, vp,
@@ -4141,11 +4139,7 @@ loop:
 		 * vnodes open for writing.
 		 */
 		if (flags & WRITECLOSE) {
-			if (vp->v_object != NULL) {
-				VM_OBJECT_WLOCK(vp->v_object);
-				vm_object_page_clean(vp->v_object, 0, 0, 0);
-				VM_OBJECT_WUNLOCK(vp->v_object);
-			}
+			vnode_pager_clean_async(vp);
 			do {
 				error = VOP_FSYNC(vp, MNT_WAIT, td);
 			} while (error == ERELOOKUP);
@@ -5208,17 +5202,12 @@ static void __noinline
 vfs_periodic_msync_inactive(struct mount *mp, int flags)
 {
 	struct vnode *vp, *mvp;
-	struct vm_object *obj;
-	int lkflags, objflags;
+	int lkflags;
 	bool seen_defer;
 
 	lkflags = LK_EXCLUSIVE | LK_INTERLOCK;
-	if (flags != MNT_WAIT) {
+	if (flags != MNT_WAIT)
 		lkflags |= LK_NOWAIT;
-		objflags = OBJPC_NOSYNC;
-	} else {
-		objflags = OBJPC_SYNC;
-	}
 
 	MNT_VNODE_FOREACH_LAZY(vp, mp, mvp, vfs_periodic_msync_inactive_filter, NULL) {
 		seen_defer = false;
@@ -5234,11 +5223,11 @@ vfs_periodic_msync_inactive(struct mount *mp, int flags)
 			continue;
 		}
 		if (vget(vp, lkflags) == 0) {
-			obj = vp->v_object;
-			if (obj != NULL && (vp->v_vflag & VV_NOSYNC) == 0) {
-				VM_OBJECT_WLOCK(obj);
-				vm_object_page_clean(obj, 0, 0, objflags);
-				VM_OBJECT_WUNLOCK(obj);
+			if ((vp->v_vflag & VV_NOSYNC) == 0) {
+				if (flags == MNT_WAIT)
+					vnode_pager_clean_sync(vp);
+				else
+					vnode_pager_clean_async(vp);
 			}
 			vput(vp);
 			if (seen_defer)
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index cf733133bec0..830f0d008aca 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -82,6 +82,7 @@
 #include <vm/vm.h>
 #include <vm/vm_object.h>
 #include <vm/vm_page.h>
+#include <vm/vnode_pager.h>
 #include <vm/uma.h>
 
 #include <fs/devfs/devfs.h>
@@ -3529,11 +3530,7 @@ retry:
 		goto drop;
 	vn_lock(vp, vn_lktype_write(mp, vp) | LK_RETRY);
 	AUDIT_ARG_VNODE1(vp);
-	if (vp->v_object != NULL) {
-		VM_OBJECT_WLOCK(vp->v_object);
-		vm_object_page_clean(vp->v_object, 0, 0, 0);
-		VM_OBJECT_WUNLOCK(vp->v_object);
-	}
+	vnode_pager_clean_async(vp);
 	error = fullsync ? VOP_FSYNC(vp, MNT_WAIT, td) : VOP_FDATASYNC(vp, td);
 	VOP_UNLOCK(vp);
 	vn_finished_write(mp);
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index be3739f41086..d2df3e2c5e4d 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -90,6 +90,7 @@
 #include <vm/vm_object.h>
 #include <vm/vm_page.h>
 #include <vm/vm_pager.h>
+#include <vm/vnode_pager.h>
 
 #ifdef HWPMC_HOOKS
 #include <sys/pmckern.h>
@@ -2551,7 +2552,6 @@ vn_pages_remove_valid(struct vnode *vp, vm_pindex_t start, vm_pindex_t end)
 int
 vn_bmap_seekhole(struct vnode *vp, u_long cmd, off_t *off, struct ucred *cred)
 {
-	vm_object_t obj;
 	struct vattr va;
 	daddr_t bn, bnp;
 	uint64_t bsize;
@@ -2577,12 +2577,7 @@ vn_bmap_seekhole(struct vnode *vp, u_long cmd, off_t *off, struct ucred *cred)
 	}
 
 	/* See the comment in ufs_bmap_seekdata(). */
-	obj = vp->v_object;
-	if (obj != NULL) {
-		VM_OBJECT_WLOCK(obj);
-		vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
-		VM_OBJECT_WUNLOCK(obj);
-	}
+	vnode_pager_clean_sync(vp);
 
 	bsize = vp->v_mount->mnt_stat.f_iosize;
 	for (bn = noff / bsize; noff < va.va_size; bn++, noff += bsize -
diff --git a/sys/sys/param.h b/sys/sys/param.h
index f1c0d969b369..bf8697633d18 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -59,7 +59,7 @@
  *		in the range 5 to 9.
  */
 #undef __FreeBSD_version
-#define __FreeBSD_version 1302510	/* Master, propagated to newvers */
+#define __FreeBSD_version 1302511	/* Master, propagated to newvers */
 
 /*
  * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
diff --git a/sys/ufs/ffs/ffs_rawread.c b/sys/ufs/ffs/ffs_rawread.c
index ef93c1ab6783..3a415d766303 100644
--- a/sys/ufs/ffs/ffs_rawread.c
+++ b/sys/ufs/ffs/ffs_rawread.c
@@ -52,6 +52,7 @@
 #include <vm/vm.h>
 #include <vm/vm_extern.h>
 #include <vm/vm_object.h>
+#include <vm/vnode_pager.h>
 
 static int ffs_rawread_readahead(struct vnode *vp,
 				 caddr_t udata,
@@ -132,15 +133,10 @@ ffs_rawread_sync(struct vnode *vp)
 			vn_finished_write(mp);
 			return (EIO);
 		}
-		/* Attempt to msync mmap() regions to clean dirty mmap */ 
-		if ((obj = vp->v_object) != NULL &&
-		    vm_object_mightbedirty(obj)) {
-			VI_UNLOCK(vp);
-			VM_OBJECT_WLOCK(obj);
-			vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
-			VM_OBJECT_WUNLOCK(obj);
-		} else
-			VI_UNLOCK(vp);
+		VI_UNLOCK(vp);
+
+		/* Attempt to msync mmap() regions to clean dirty mmap */
+		vnode_pager_clean_sync(vp);
 
 		/* Wait for pending writes to complete */
 		BO_LOCK(bo);
diff --git a/sys/ufs/ufs/ufs_bmap.c b/sys/ufs/ufs/ufs_bmap.c
index 44aeefe17d13..4311f771409f 100644
--- a/sys/ufs/ufs/ufs_bmap.c
+++ b/sys/ufs/ufs/ufs_bmap.c
@@ -51,6 +51,7 @@
 
 #include <vm/vm.h>
 #include <vm/vm_object.h>
+#include <vm/vnode_pager.h>
 
 #include <ufs/ufs/extattr.h>
 #include <ufs/ufs/quota.h>
@@ -350,7 +351,6 @@ ufs_bmap_seekdata(struct vnode *vp, off_t *offp)
 	struct inode *ip;
 	struct mount *mp;
 	struct ufsmount *ump;
-	vm_object_t obj;
 	ufs2_daddr_t bn, daddr, nextbn;
 	uint64_t bsize;
 	off_t numblks;
@@ -373,12 +373,7 @@ ufs_bmap_seekdata(struct vnode *vp, off_t *offp)
 	 * pages into buffer writes to ensure that we see all
 	 * allocated data.
 	 */
-	obj = vp->v_object;
-	if (obj != NULL) {
-		VM_OBJECT_WLOCK(obj);
-		vm_object_page_clean(obj, 0, 0, OBJPC_SYNC);
-		VM_OBJECT_WUNLOCK(obj);
-	}
+	vnode_pager_clean_sync(vp);
 
 	bsize = mp->mnt_stat.f_iosize;
 	for (bn = *offp / bsize, numblks = howmany(ip->i_size, bsize);
diff --git a/sys/vm/vnode_pager.c b/sys/vm/vnode_pager.c
index b994de8592db..62cc9d35b653 100644
--- a/sys/vm/vnode_pager.c
+++ b/sys/vm/vnode_pager.c
@@ -1622,3 +1622,30 @@ vnode_pager_getvp(vm_object_t object, struct vnode **vpp, bool *vp_heldp)
 {
 	*vpp = object->handle;
 }
+
+static void
+vnode_pager_clean1(struct vnode *vp, int sync_flags)
+{
+	struct vm_object *obj;
+
+	ASSERT_VOP_LOCKED(vp, "needs lock for writes");
+	obj = vp->v_object;
+	if (obj == NULL)
+		return;
+
+	VM_OBJECT_WLOCK(obj);
+	vm_object_page_clean(obj, 0, 0, sync_flags);
+	VM_OBJECT_WUNLOCK(obj);
+}
+
+void
+vnode_pager_clean_sync(struct vnode *vp)
+{
+	vnode_pager_clean1(vp, OBJPC_SYNC);
+}
+
+void
+vnode_pager_clean_async(struct vnode *vp)
+{
+	vnode_pager_clean1(vp, 0);
+}
diff --git a/sys/vm/vnode_pager.h b/sys/vm/vnode_pager.h
index 558d080717b7..ca98cf9cdd24 100644
--- a/sys/vm/vnode_pager.h
+++ b/sys/vm/vnode_pager.h
@@ -41,6 +41,9 @@
 
 #ifdef _KERNEL
 
+struct vnode;
+void vnode_pager_clean_sync(struct vnode *vp);
+void vnode_pager_clean_async(struct vnode *vp);
 int vnode_pager_generic_getpages(struct vnode *vp, vm_page_t *m,
     int count, int *rbehind, int *rahead, vop_getpages_iodone_t iodone,
     void *arg);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202401180114.40I1E1qm053389>