git: d689a4aad9cf - main - sys: use bdflush task to fsync mntfs devvp for all filesystems
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 23 Nov 2026 01:43:57 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=d689a4aad9cf058b7a842d53b71903b25201f2f0
commit d689a4aad9cf058b7a842d53b71903b25201f2f0
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2026-11-20 01:17:02 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2026-11-23 01:43:25 +0000
sys: use bdflush task to fsync mntfs devvp for all filesystems
The bufbdflush() function calls VOP_FSYNC() on unlocked devvp similarly
to ffs_bdflush() in ffs_snapshot.c. Move the bdflush task into struct
mount as a generic facility. Convert both UFS and msdosfs to use it.
Reported by: llm-postcr
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
---
sys/fs/mntfs/mntfs_vnops.c | 26 ++++++++++++++++++++++++++
sys/fs/msdosfs/msdosfs_vfsops.c | 2 ++
sys/kern/vfs_bio.c | 2 +-
sys/kern/vfs_mount.c | 1 +
sys/sys/mount.h | 5 +++++
sys/ufs/ffs/ffs_extern.h | 1 -
sys/ufs/ffs/ffs_snapshot.c | 24 ++----------------------
sys/ufs/ffs/ffs_vfsops.c | 7 ++-----
sys/ufs/ufs/ufsmount.h | 1 -
9 files changed, 39 insertions(+), 30 deletions(-)
diff --git a/sys/fs/mntfs/mntfs_vnops.c b/sys/fs/mntfs/mntfs_vnops.c
index 45c429c34c07..e2ca132d61c4 100644
--- a/sys/fs/mntfs/mntfs_vnops.c
+++ b/sys/fs/mntfs/mntfs_vnops.c
@@ -28,6 +28,7 @@
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/mount.h>
+#include <sys/taskqueue.h>
#include <sys/vnode.h>
/*
@@ -51,6 +52,17 @@ mntfs_reclaim(struct vop_reclaim_args *ap)
return (0);
}
+void
+mntfs_fsync_task(void *arg, int pending)
+{
+ struct vnode *devvp;
+
+ devvp = arg;
+ vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
+ (void)vn_fsync_buf(devvp, MNT_NOWAIT);
+ VOP_UNLOCK(devvp);
+}
+
struct vop_vector mntfs_vnodeops = {
.vop_default = &default_vnodeops,
@@ -79,6 +91,7 @@ mntfs_allocvp(struct mount *mp, struct vnode *ovp)
getnewvnode("mntfs", mp, &mntfs_vnodeops, &vp);
vp->v_type = VCHR;
vp->v_data = mp;
+ mp->mnt_bdflush_task.ta_context = vp;
dev_ref(dev);
vp->v_rdev = dev;
@@ -95,3 +108,16 @@ mntfs_freevp(struct vnode *vp)
vgone(vp);
vput(vp);
}
+
+void
+mntfs_fsync_delayed(struct vnode *vp)
+{
+ struct mount *mp;
+
+ if (vp->v_op == &mntfs_vnodeops) {
+ mp = vp->v_data;
+ taskqueue_enqueue(taskqueue_thread, &mp->mnt_bdflush_task);
+ } else {
+ (void)VOP_FSYNC(vp, MNT_NOWAIT, curthread);
+ }
+}
diff --git a/sys/fs/msdosfs/msdosfs_vfsops.c b/sys/fs/msdosfs/msdosfs_vfsops.c
index cdb3cc30fdff..236ebc5575bf 100644
--- a/sys/fs/msdosfs/msdosfs_vfsops.c
+++ b/sys/fs/msdosfs/msdosfs_vfsops.c
@@ -863,6 +863,7 @@ mountmsdosfs(struct vnode *odevvp, struct mount *mp)
error_exit:
if (bp != NULL)
brelse(bp);
+ taskqueue_drain(taskqueue_thread, &mp->mnt_bdflush_task);
if (cp != NULL)
g_vfs_close_unlocked(cp);
if (pmp != NULL) {
@@ -953,6 +954,7 @@ msdosfs_unmount(struct mount *mp, int mntflags)
if (susp)
vfs_write_resume(mp, VR_START_WRITE);
+ taskqueue_drain(taskqueue_thread, &mp->mnt_bdflush_task);
vn_lock(pmp->pm_devvp, LK_EXCLUSIVE | LK_RETRY);
g_topology_lock();
g_vfs_close(pmp->pm_cp);
diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c
index 868d7de7d6c8..f0f042147b55 100644
--- a/sys/kern/vfs_bio.c
+++ b/sys/kern/vfs_bio.c
@@ -2410,7 +2410,7 @@ bufbdflush(struct bufobj *bo, struct buf *bp)
bd = &bdomain[bo->bo_domain];
if (bo->bo_dirty.bv_cnt > bd->bd_dirtybufthresh + 10) {
- (void) VOP_FSYNC(bp->b_vp, MNT_NOWAIT, curthread);
+ mntfs_fsync_delayed(bp->b_vp);
altbufferflushes++;
} else if (bo->bo_dirty.bv_cnt > bd->bd_dirtybufthresh) {
BO_LOCK(bo);
diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c
index 39c9135f3f4c..27852c25961d 100644
--- a/sys/kern/vfs_mount.c
+++ b/sys/kern/vfs_mount.c
@@ -715,6 +715,7 @@ vfs_mount_alloc(struct vnode *vp, struct vfsconf *vfsp, const char *fspath,
TAILQ_INIT(&mp->mnt_notify);
mp->mnt_taskqueue_flags = 0;
mp->mnt_unmount_retries = 0;
+ TASK_INIT(&mp->mnt_bdflush_task, 0, mntfs_fsync_task, NULL);
return (mp);
}
diff --git a/sys/sys/mount.h b/sys/sys/mount.h
index 30f4cc35dac0..962e4f9d7511 100644
--- a/sys/sys/mount.h
+++ b/sys/sys/mount.h
@@ -43,10 +43,12 @@
#include <sys/tslog.h>
#include <sys/_mutex.h>
#include <sys/_sx.h>
+#include <sys/_task.h>
#elif defined(_WANT_MOUNT)
#include <sys/_lock.h>
#include <sys/_lockmgr.h>
#include <sys/_mutex.h>
+#include <sys/_task.h>
#endif
/*
@@ -281,6 +283,7 @@ struct mount {
taskqueue */
unsigned int mnt_unmount_retries; /* (d) # of failed deferred
unmount attempts */
+ struct task mnt_bdflush_task;
};
#endif /* _WANT_MOUNT || _KERNEL */
@@ -1109,6 +1112,8 @@ extern struct sx vfsconf_sx;
#define vfsconf_sunlock() sx_sunlock(&vfsconf_sx)
struct vnode *mntfs_allocvp(struct mount *, struct vnode *);
void mntfs_freevp(struct vnode *);
+void mntfs_fsync_delayed(struct vnode *);
+void mntfs_fsync_task(void *, int);
/*
* Declarations for these vfs default operations are located in
diff --git a/sys/ufs/ffs/ffs_extern.h b/sys/ufs/ffs/ffs_extern.h
index 8ac2a6c44809..0dc52ee48b1e 100644
--- a/sys/ufs/ffs/ffs_extern.h
+++ b/sys/ufs/ffs/ffs_extern.h
@@ -228,7 +228,6 @@ void softdep_freework(struct workhead *);
#define DATA_ONLY 0x00000002
int ffs_rdonly(struct inode *);
-void ffs_devvp_bdflush_fsync(void *arg, int pending);
TAILQ_HEAD(snaphead, inode);
diff --git a/sys/ufs/ffs/ffs_snapshot.c b/sys/ufs/ffs/ffs_snapshot.c
index 1a6e6b880822..121837647b33 100644
--- a/sys/ufs/ffs/ffs_snapshot.c
+++ b/sys/ufs/ffs/ffs_snapshot.c
@@ -123,11 +123,6 @@ ffs_sync_snap(struct mount *mp, int waitfor)
{
}
-void
-ffs_devvp_bdflush_fsync(void *arg, int pending)
-{
-}
-
#else
FEATURE(ffs_snapshot, "FFS snapshot support");
@@ -2200,26 +2195,11 @@ ffs_bp_snapblk(struct vnode *devvp, struct buf *bp)
return (0);
}
-void
-ffs_devvp_bdflush_fsync(void *arg, int pending)
-{
- struct ufsmount *ump;
- struct vnode *devvp;
-
- ump = arg;
- devvp = ump->um_devvp;
- vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY);
- (void)VOP_FSYNC(devvp, MNT_NOWAIT, curthread);
- VOP_UNLOCK(devvp);
- altbufferflushes++;
-}
-
void
ffs_bdflush(struct bufobj *bo, struct buf *bp)
{
struct vnode *devvp;
struct buf *nbp;
- struct ufsmount *ump;
int bp_bdskip;
if (bo->bo_dirty.bv_cnt <= dirtybufthresh)
@@ -2234,8 +2214,8 @@ ffs_bdflush(struct bufobj *bo, struct buf *bp)
bdwriteskip++;
VI_UNLOCK(devvp);
if (bo->bo_dirty.bv_cnt > dirtybufthresh + 10 && !bp_bdskip) {
- ump = VFSTOUFS((struct mount *)devvp->v_data);
- taskqueue_enqueue(taskqueue_thread, &ump->um_devvp_fsync_task);
+ mntfs_fsync_delayed(devvp);
+ altbufferflushes++;
} else {
BO_LOCK(bo);
/*
diff --git a/sys/ufs/ffs/ffs_vfsops.c b/sys/ufs/ffs/ffs_vfsops.c
index 9f13f049f7a2..5b6558f7fde6 100644
--- a/sys/ufs/ffs/ffs_vfsops.c
+++ b/sys/ufs/ffs/ffs_vfsops.c
@@ -1146,8 +1146,6 @@ ffs_mountfs(struct vnode *odevvp, struct mount *mp, struct thread *td)
ufs_extattr_uepm_init(&ump->um_extattr);
#endif
- TASK_INIT(&ump->um_devvp_fsync_task, 0, ffs_devvp_bdflush_fsync, ump);
-
/*
* Set FS local "last mounted on" information (NULL pad)
*/
@@ -1206,8 +1204,7 @@ out:
free(fs->fs_si, M_UFSMNT);
free(fs, M_UFSMNT);
}
- if (ump != NULL)
- taskqueue_drain(taskqueue_thread, &ump->um_devvp_fsync_task);
+ taskqueue_drain(taskqueue_thread, &mp->mnt_bdflush_task);
if (cp != NULL)
g_vfs_close_unlocked(cp);
if (ump != NULL) {
@@ -1323,7 +1320,7 @@ ffs_unmount(struct mount *mp, int mntflags)
taskqueue_free(ump->um_trim_tq);
free (ump->um_trimhash, M_TRIM);
}
- taskqueue_drain(taskqueue_thread, &ump->um_devvp_fsync_task);
+ taskqueue_drain(taskqueue_thread, &mp->mnt_bdflush_task);
vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY);
g_topology_lock();
g_vfs_close(ump->um_cp);
diff --git a/sys/ufs/ufs/ufsmount.h b/sys/ufs/ufs/ufsmount.h
index 4f57ef715865..d33b01e4425e 100644
--- a/sys/ufs/ufs/ufsmount.h
+++ b/sys/ufs/ufs/ufsmount.h
@@ -117,7 +117,6 @@ struct ufsmount {
struct trimlist_hashhead *um_trimhash; /* (i) trimlist hash table */
u_long um_trimlisthashsize; /* (i) trim hash table size-1 */
/* (c) - below function ptrs */
- struct task um_devvp_fsync_task;
int (*um_balloc)(struct vnode *, off_t, int, struct ucred *,
int, struct buf **);
int (*um_blkatoff)(struct vnode *, off_t, char **, struct buf **);