git: 9a91689e414c - stable/13 - vfs: Add get_write_ioflag helper to calculate ioflag
Ka Ho Ng
khng at FreeBSD.org
Fri Aug 27 11:42:45 UTC 2021
The branch stable/13 has been updated by khng:
URL: https://cgit.FreeBSD.org/src/commit/?id=9a91689e414cf26204fc993b4d32c4a1fc61aaf0
commit 9a91689e414cf26204fc993b4d32c4a1fc61aaf0
Author: Ka Ho Ng <khng at FreeBSD.org>
AuthorDate: 2021-08-12 09:35:34 +0000
Commit: Ka Ho Ng <khng at FreeBSD.org>
CommitDate: 2021-08-27 08:50:12 +0000
vfs: Add get_write_ioflag helper to calculate ioflag
Converted vn_write to use this helper.
Sponsored by: The FreeBSD Foundation
Reviewed by: kib
Differential Revision: https://reviews.freebsd.org/D31513
(cherry picked from commit c15384f8963191a238cb4a33382b4d394f1ac0b4)
---
sys/kern/vfs_vnops.c | 48 ++++++++++++++++++++++++++++++++----------------
1 file changed, 32 insertions(+), 16 deletions(-)
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index b7e53add5a35..8f5442bf3429 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -914,6 +914,35 @@ get_advice(struct file *fp, struct uio *uio)
return (ret);
}
+static int
+get_write_ioflag(struct file *fp)
+{
+ int ioflag;
+ struct mount *mp;
+ struct vnode *vp;
+
+ ioflag = 0;
+ vp = fp->f_vnode;
+ mp = atomic_load_ptr(&vp->v_mount);
+
+ if ((fp->f_flag & O_DIRECT) != 0)
+ ioflag |= IO_DIRECT;
+
+ if ((fp->f_flag & O_FSYNC) != 0 ||
+ (mp != NULL && (mp->mnt_flag & MNT_SYNCHRONOUS) != 0))
+ ioflag |= IO_SYNC;
+
+ /*
+ * For O_DSYNC we set both IO_SYNC and IO_DATASYNC, so that VOP_WRITE()
+ * or VOP_DEALLOCATE() implementations that don't understand IO_DATASYNC
+ * fall back to full O_SYNC behavior.
+ */
+ if ((fp->f_flag & O_DSYNC) != 0)
+ ioflag |= IO_SYNC | IO_DATASYNC;
+
+ return (ioflag);
+}
+
int
vn_read_from_obj(struct vnode *vp, struct uio *uio)
{
@@ -1113,25 +1142,12 @@ vn_write(struct file *fp, struct uio *uio, struct ucred *active_cred, int flags,
if (vp->v_type == VREG)
bwillwrite();
ioflag = IO_UNIT;
- if (vp->v_type == VREG && (fp->f_flag & O_APPEND))
+ if (vp->v_type == VREG && (fp->f_flag & O_APPEND) != 0)
ioflag |= IO_APPEND;
- if (fp->f_flag & FNONBLOCK)
+ if ((fp->f_flag & FNONBLOCK) != 0)
ioflag |= IO_NDELAY;
- if (fp->f_flag & O_DIRECT)
- ioflag |= IO_DIRECT;
+ ioflag |= get_write_ioflag(fp);
- mp = atomic_load_ptr(&vp->v_mount);
- if ((fp->f_flag & O_FSYNC) ||
- (mp != NULL && (mp->mnt_flag & MNT_SYNCHRONOUS)))
- ioflag |= IO_SYNC;
-
- /*
- * For O_DSYNC we set both IO_SYNC and IO_DATASYNC, so that VOP_WRITE()
- * implementations that don't understand IO_DATASYNC fall back to full
- * O_SYNC behavior.
- */
- if (fp->f_flag & O_DSYNC)
- ioflag |= IO_SYNC | IO_DATASYNC;
mp = NULL;
need_finished_write = false;
if (vp->v_type != VCHR) {
More information about the dev-commits-src-all
mailing list