From 52174f7139d0f8a7dbe74d17c8a2b1f9a6711adb Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Mon, 24 Aug 2009 08:15:17 -0700 Subject: [PATCH] Add a flags argument to VOP_FSYNC() * So filesystem code knows whether it is being called from userland or not. --- sys/kern/vfs_subr.c | 2 +- sys/kern/vfs_sync.c | 2 +- sys/kern/vfs_syscalls.c | 3 ++- sys/kern/vfs_vopops.c | 3 ++- sys/sys/mount.h | 2 ++ sys/sys/vfsops.h | 7 ++++--- sys/vfs/gnu/ext2fs/ext2_vfsops.c | 4 ++-- sys/vfs/msdosfs/msdosfs_vfsops.c | 4 ++-- sys/vfs/nfs/nfs_serv.c | 2 +- sys/vfs/nfs/nfs_vfsops.c | 2 +- sys/vfs/nfs/nfs_vnops.c | 6 +++--- sys/vfs/nwfs/nwfs_vfsops.c | 2 +- sys/vfs/smbfs/smbfs_vfsops.c | 2 +- sys/vfs/ufs/ffs_balloc.c | 4 ++-- sys/vfs/ufs/ffs_inode.c | 4 ++-- sys/vfs/ufs/ffs_rawread.c | 2 +- sys/vfs/ufs/ffs_softdep.c | 12 ++++++------ sys/vfs/ufs/ffs_vfsops.c | 6 +++--- sys/vfs/union/union_vnops.c | 2 +- 19 files changed, 38 insertions(+), 33 deletions(-) diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index b82ee44cf1..9f56e001b4 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -297,7 +297,7 @@ vinvalbuf(struct vnode *vp, int flags, int slpflag, int slptimeo) if (error) goto done; if (!RB_EMPTY(&vp->v_rbdirty_tree)) { - if ((error = VOP_FSYNC(vp, MNT_WAIT)) != 0) + if ((error = VOP_FSYNC(vp, MNT_WAIT, 0)) != 0) goto done; /* diff --git a/sys/kern/vfs_sync.c b/sys/kern/vfs_sync.c index 3650dd212c..9cbeb71b3a 100644 --- a/sys/kern/vfs_sync.c +++ b/sys/kern/vfs_sync.c @@ -216,7 +216,7 @@ sched_sync(void) while ((vp = LIST_FIRST(slp)) != NULL) { if (vget(vp, LK_EXCLUSIVE | LK_NOWAIT) == 0) { - VOP_FSYNC(vp, MNT_LAZY); + VOP_FSYNC(vp, MNT_LAZY, 0); vput(vp); } diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index 0152abbaa8..ff6ed66496 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -3302,7 +3302,8 @@ sys_fsync(struct fsync_args *uap) vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); if ((obj = vp->v_object) != NULL) vm_object_page_clean(obj, 0, 0, 0); - if ((error = VOP_FSYNC(vp, MNT_WAIT)) == 0 && vp->v_mount) + error = VOP_FSYNC(vp, MNT_WAIT, VOP_FSYNC_SYSCALL); + if (error == 0 && vp->v_mount) error = buf_fsync(vp); vn_unlock(vp); fdrop(fp); diff --git a/sys/kern/vfs_vopops.c b/sys/kern/vfs_vopops.c index 951f61ed66..afe4cf895d 100644 --- a/sys/kern/vfs_vopops.c +++ b/sys/kern/vfs_vopops.c @@ -423,7 +423,7 @@ vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred) } int -vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor) +vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor, int flags) { struct vop_fsync_args ap; int error; @@ -432,6 +432,7 @@ vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor) ap.a_head.a_ops = ops; ap.a_vp = vp; ap.a_waitfor = waitfor; + ap.a_flags = flags; DO_OPS(ops, error, &ap, vop_fsync); return(error); diff --git a/sys/sys/mount.h b/sys/sys/mount.h index 4fc785f25b..b7656ef0de 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -320,6 +320,8 @@ struct mount { #define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */ #define MNT_LAZY 4 /* be lazy and do not necessarily push it all */ +#define VOP_FSYNC_SYSCALL 0x0001 /* from system call */ + /* * Generic file handle */ diff --git a/sys/sys/vfsops.h b/sys/sys/vfsops.h index 3cf91324ea..f6afc83a7e 100644 --- a/sys/sys/vfsops.h +++ b/sys/sys/vfsops.h @@ -205,6 +205,7 @@ struct vop_fsync_args { struct vop_generic_args a_head; struct vnode *a_vp; int a_waitfor; + int a_flags; }; struct vop_old_remove_args { @@ -749,7 +750,7 @@ int vop_poll(struct vop_ops *ops, struct vnode *vp, int events, int vop_kqfilter(struct vop_ops *ops, struct vnode *vp, struct knote *kn); int vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred); -int vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor); +int vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor, int flags); int vop_old_remove(struct vop_ops *ops, struct vnode *dvp, struct vnode *vp, struct componentname *cnp); int vop_old_link(struct vop_ops *ops, struct vnode *tdvp, @@ -991,8 +992,8 @@ extern struct syslink_desc vop_nrename_desc; vop_kqfilter(*(vp)->v_ops, vp, kn) #define VOP_MMAP(vp, fflags, cred) \ vop_mmap(*(vp)->v_ops, vp, fflags, cred) -#define VOP_FSYNC(vp, waitfor) \ - vop_fsync(*(vp)->v_ops, vp, waitfor) +#define VOP_FSYNC(vp, waitfor, flags) \ + vop_fsync(*(vp)->v_ops, vp, waitfor, flags) #define VOP_READDIR(vp, uio, cred, eofflag, ncookies, cookies) \ vop_readdir(*(vp)->v_ops, vp, uio, cred, eofflag, ncookies, cookies) #define VOP_READLINK(vp, uio, cred) \ diff --git a/sys/vfs/gnu/ext2fs/ext2_vfsops.c b/sys/vfs/gnu/ext2fs/ext2_vfsops.c index 9c1799c6d7..437dd4d29a 100644 --- a/sys/vfs/gnu/ext2fs/ext2_vfsops.c +++ b/sys/vfs/gnu/ext2fs/ext2_vfsops.c @@ -1054,7 +1054,7 @@ ext2_sync(struct mount *mp, int waitfor) */ if (waitfor != MNT_LAZY) { vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY); - if ((error = VOP_FSYNC(ump->um_devvp, waitfor)) != 0) + if ((error = VOP_FSYNC(ump->um_devvp, waitfor, 0)) != 0) scaninfo.allerror = error; vn_unlock(ump->um_devvp); } @@ -1087,7 +1087,7 @@ ext2_sync_scan(struct mount *mp, struct vnode *vp, void *data) (RB_EMPTY(&vp->v_rbdirty_tree) || info->waitfor == MNT_LAZY))) { return(0); } - if ((error = VOP_FSYNC(vp, info->waitfor)) != 0) + if ((error = VOP_FSYNC(vp, info->waitfor, 0)) != 0) info->allerror = error; return(0); } diff --git a/sys/vfs/msdosfs/msdosfs_vfsops.c b/sys/vfs/msdosfs/msdosfs_vfsops.c index 39dd119b2f..8a39bb2bee 100644 --- a/sys/vfs/msdosfs/msdosfs_vfsops.c +++ b/sys/vfs/msdosfs/msdosfs_vfsops.c @@ -732,7 +732,7 @@ msdosfs_sync(struct mount *mp, int waitfor) */ if (waitfor != MNT_LAZY) { vn_lock(pmp->pm_devvp, LK_EXCLUSIVE | LK_RETRY); - if ((error = VOP_FSYNC(pmp->pm_devvp, waitfor)) != 0) + if ((error = VOP_FSYNC(pmp->pm_devvp, waitfor, 0)) != 0) scaninfo.allerror = error; vn_unlock(pmp->pm_devvp); } @@ -753,7 +753,7 @@ msdosfs_sync_scan(struct mount *mp, struct vnode *vp, void *data) (RB_EMPTY(&vp->v_rbdirty_tree) || info->waitfor == MNT_LAZY))) { return(0); } - if ((error = VOP_FSYNC(vp, info->waitfor)) != 0) + if ((error = VOP_FSYNC(vp, info->waitfor, 0)) != 0) info->allerror = error; return(0); } diff --git a/sys/vfs/nfs/nfs_serv.c b/sys/vfs/nfs/nfs_serv.c index 6ffa5105e0..6d2104251d 100644 --- a/sys/vfs/nfs/nfs_serv.c +++ b/sys/vfs/nfs/nfs_serv.c @@ -3565,7 +3565,7 @@ nfsrv_commit(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, (vp->v_object->flags & OBJ_MIGHTBEDIRTY)) { vm_object_page_clean(vp->v_object, 0, 0, OBJPC_SYNC); } - error = VOP_FSYNC(vp, MNT_WAIT); + error = VOP_FSYNC(vp, MNT_WAIT, 0); } else { /* * Locate and synchronously write any buffers that fall diff --git a/sys/vfs/nfs/nfs_vfsops.c b/sys/vfs/nfs/nfs_vfsops.c index 0d3ac791b4..fd3988fbf0 100644 --- a/sys/vfs/nfs/nfs_vfsops.c +++ b/sys/vfs/nfs/nfs_vfsops.c @@ -1302,7 +1302,7 @@ nfs_sync_scan2(struct mount *mp, struct vnode *vp, void *data) struct scaninfo *info = data; int error; - error = VOP_FSYNC(vp, info->waitfor); + error = VOP_FSYNC(vp, info->waitfor, 0); if (error) info->allerror = error; return(0); diff --git a/sys/vfs/nfs/nfs_vnops.c b/sys/vfs/nfs/nfs_vnops.c index 4c5befd75d..5cad213c8a 100644 --- a/sys/vfs/nfs/nfs_vnops.c +++ b/sys/vfs/nfs/nfs_vnops.c @@ -1787,9 +1787,9 @@ nfs_rename(struct vop_old_rename_args *ap) * server after the rename. */ if (nfs_flush_on_rename) - VOP_FSYNC(fvp, MNT_WAIT); + VOP_FSYNC(fvp, MNT_WAIT, 0); if (tvp) - VOP_FSYNC(tvp, MNT_WAIT); + VOP_FSYNC(tvp, MNT_WAIT, 0); /* * If the tvp exists and is in use, sillyrename it before doing the @@ -1906,7 +1906,7 @@ nfs_link(struct vop_old_link_args *ap) * Defaults to off. */ if (nfs_flush_on_hlink) - VOP_FSYNC(vp, MNT_WAIT); + VOP_FSYNC(vp, MNT_WAIT, 0); info.mrep = NULL; info.v3 = NFS_ISV3(vp); diff --git a/sys/vfs/nwfs/nwfs_vfsops.c b/sys/vfs/nwfs/nwfs_vfsops.c index dcccee2b9e..d178314147 100644 --- a/sys/vfs/nwfs/nwfs_vfsops.c +++ b/sys/vfs/nwfs/nwfs_vfsops.c @@ -447,7 +447,7 @@ loop: if (vget(vp, LK_EXCLUSIVE)) goto loop; /* XXX vp may not be retained */ - error = VOP_FSYNC(vp, waitfor); + error = VOP_FSYNC(vp, waitfor, 0); if (error) allerror = error; vput(vp); diff --git a/sys/vfs/smbfs/smbfs_vfsops.c b/sys/vfs/smbfs/smbfs_vfsops.c index 16f2355dc3..b236a9cb91 100644 --- a/sys/vfs/smbfs/smbfs_vfsops.c +++ b/sys/vfs/smbfs/smbfs_vfsops.c @@ -399,7 +399,7 @@ loop: continue; if (vget(vp, LK_EXCLUSIVE)) goto loop; - error = VOP_FSYNC(vp, waitfor); + error = VOP_FSYNC(vp, waitfor, 0); if (error) allerror = error; vput(vp); diff --git a/sys/vfs/ufs/ffs_balloc.c b/sys/vfs/ufs/ffs_balloc.c index c0c5b51008..694ab36cb1 100644 --- a/sys/vfs/ufs/ffs_balloc.c +++ b/sys/vfs/ufs/ffs_balloc.c @@ -441,7 +441,7 @@ fail: * occurence. The error return from fsync is ignored as we already * have an error to return to the user. */ - (void) VOP_FSYNC(vp, MNT_WAIT); + VOP_FSYNC(vp, MNT_WAIT, 0); for (deallocated = 0, blkp = allociblk, lbns_remfree = lbns; blkp < allocblk; blkp++, lbns_remfree++) { /* @@ -485,7 +485,7 @@ fail: ip->i_blocks -= btodb(deallocated); ip->i_flag |= IN_CHANGE | IN_UPDATE; } - (void) VOP_FSYNC(vp, MNT_WAIT); + VOP_FSYNC(vp, MNT_WAIT, 0); /* * After the buffers are invalidated and on-disk pointers are diff --git a/sys/vfs/ufs/ffs_inode.c b/sys/vfs/ufs/ffs_inode.c index 4a2c2a3528..d8057d33a0 100644 --- a/sys/vfs/ufs/ffs_inode.c +++ b/sys/vfs/ufs/ffs_inode.c @@ -193,7 +193,7 @@ ffs_truncate(struct vnode *vp, off_t length, int flags, struct ucred *cred) * rarely, we solve the problem by syncing the file * so that it will have no data structures left. */ - if ((error = VOP_FSYNC(ovp, MNT_WAIT)) != 0) + if ((error = VOP_FSYNC(ovp, MNT_WAIT, 0)) != 0) return (error); } else { #ifdef QUOTA @@ -261,7 +261,7 @@ ffs_truncate(struct vnode *vp, off_t length, int flags, struct ucred *cred) */ if (DOINGSOFTDEP(ovp) && lbn < NDADDR && fragroundup(fs, blkoff(fs, length)) < fs->fs_bsize && - (error = VOP_FSYNC(ovp, MNT_WAIT)) != 0) { + (error = VOP_FSYNC(ovp, MNT_WAIT, 0)) != 0) { return (error); } oip->i_size = length; diff --git a/sys/vfs/ufs/ffs_rawread.c b/sys/vfs/ufs/ffs_rawread.c index 37f6354f58..18bae99625 100644 --- a/sys/vfs/ufs/ffs_rawread.c +++ b/sys/vfs/ufs/ffs_rawread.c @@ -121,7 +121,7 @@ ffs_rawread_sync(struct vnode *vp) } /* Flush dirty buffers */ if (!RB_EMPTY(&vp->v_rbdirty_tree)) { - if ((error = VOP_FSYNC(vp, MNT_WAIT)) != 0) { + if ((error = VOP_FSYNC(vp, MNT_WAIT, 0)) != 0) { if (upgraded != 0) vn_lock(vp, LK_DOWNGRADE); goto done; diff --git a/sys/vfs/ufs/ffs_softdep.c b/sys/vfs/ufs/ffs_softdep.c index 6a4dbe69f5..8e2c63f61f 100644 --- a/sys/vfs/ufs/ffs_softdep.c +++ b/sys/vfs/ufs/ffs_softdep.c @@ -815,7 +815,7 @@ softdep_flushfiles(struct mount *oldmnt, int flags) break; } vn_lock(devvp, LK_EXCLUSIVE | LK_RETRY); - error = VOP_FSYNC(devvp, MNT_WAIT); + error = VOP_FSYNC(devvp, MNT_WAIT, 0); vn_unlock(devvp); if (error) break; @@ -4693,8 +4693,8 @@ flush_pagedep_deps(struct vnode *pvp, struct mount *mp, FREE_LOCK(&lk); if ((error = VFS_VGET(mp, NULL, inum, &vp)) != 0) break; - if ((error=VOP_FSYNC(vp, MNT_NOWAIT)) || - (error=VOP_FSYNC(vp, MNT_NOWAIT))) { + if ((error=VOP_FSYNC(vp, MNT_NOWAIT, 0)) || + (error=VOP_FSYNC(vp, MNT_NOWAIT, 0))) { vput(vp); break; } @@ -4909,7 +4909,7 @@ clear_remove(struct thread *td) softdep_error("clear_remove: vget", error); return; } - if ((error = VOP_FSYNC(vp, MNT_NOWAIT))) + if ((error = VOP_FSYNC(vp, MNT_NOWAIT, 0))) softdep_error("clear_remove: fsync", error); drain_output(vp, 0); vput(vp); @@ -4998,10 +4998,10 @@ clear_inodedeps(struct thread *td) return; } if (ino == lastino) { - if ((error = VOP_FSYNC(vp, MNT_WAIT))) + if ((error = VOP_FSYNC(vp, MNT_WAIT, 0))) softdep_error("clear_inodedeps: fsync1", error); } else { - if ((error = VOP_FSYNC(vp, MNT_NOWAIT))) + if ((error = VOP_FSYNC(vp, MNT_NOWAIT, 0))) softdep_error("clear_inodedeps: fsync2", error); drain_output(vp, 0); } diff --git a/sys/vfs/ufs/ffs_vfsops.c b/sys/vfs/ufs/ffs_vfsops.c index 964d1bb5a2..723daed535 100644 --- a/sys/vfs/ufs/ffs_vfsops.c +++ b/sys/vfs/ufs/ffs_vfsops.c @@ -913,7 +913,7 @@ ffs_flushfiles(struct mount *mp, int flags) * Flush filesystem metadata. */ vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY); - error = VOP_FSYNC(ump->um_devvp, MNT_WAIT); + error = VOP_FSYNC(ump->um_devvp, MNT_WAIT, 0); vn_unlock(ump->um_devvp); return (error); } @@ -992,7 +992,7 @@ ffs_sync(struct mount *mp, int waitfor) if (ump->um_mountp->mnt_flag & MNT_SOFTDEP) waitfor = MNT_NOWAIT; vn_lock(ump->um_devvp, LK_EXCLUSIVE | LK_RETRY); - if ((error = VOP_FSYNC(ump->um_devvp, waitfor)) != 0) + if ((error = VOP_FSYNC(ump->um_devvp, waitfor, 0)) != 0) scaninfo.allerror = error; vn_unlock(ump->um_devvp); } @@ -1048,7 +1048,7 @@ ffs_sync_scan2(struct mount *mp, struct vnode *vp, void *data) return(0); } if (vp->v_type != VCHR) { - if ((error = VOP_FSYNC(vp, info->waitfor)) != 0) + if ((error = VOP_FSYNC(vp, info->waitfor, 0)) != 0) info->allerror = error; } else { /* diff --git a/sys/vfs/union/union_vnops.c b/sys/vfs/union/union_vnops.c index ae6378cbda..203e4dbe84 100644 --- a/sys/vfs/union/union_vnops.c +++ b/sys/vfs/union/union_vnops.c @@ -1168,7 +1168,7 @@ union_fsync(struct vop_fsync_args *ap) struct union_node *un = VTOUNION(ap->a_vp); if ((targetvp = union_lock_other(un, td)) != NULLVP) { - error = VOP_FSYNC(targetvp, ap->a_waitfor); + error = VOP_FSYNC(targetvp, ap->a_waitfor, 0); union_unlock_other(targetvp, td); } -- 2.41.0