The branch main has been updated by khng:

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

commit c15384f8963191a238cb4a33382b4d394f1ac0b4
Author:     Ka Ho Ng <[email protected]>
AuthorDate: 2021-08-12 09:35:34 +0000
Commit:     Ka Ho Ng <[email protected]>
CommitDate: 2021-08-12 09:35:34 +0000

    vfs: Add get_write_ioflag helper to calculate ioflag
    
    Converted vn_write to use this helper.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      3 days
    Reviewed by:    kib
    Differential Revision:  https://reviews.freebsd.org/D31513
---
 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 015a13c1c385..5572c324469b 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -920,6 +920,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)
 {
@@ -1119,25 +1148,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) {
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-main
To unsubscribe, send any mail to "[email protected]"

Reply via email to