From owner-dev-commits-src-all@freebsd.org Fri Aug 27 11:42:45 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C5A8065E4A0; Fri, 27 Aug 2021 11:42:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GwyWT4jsQz4ryy; Fri, 27 Aug 2021 11:42:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 893A822CA2; Fri, 27 Aug 2021 11:42:45 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 17RBgjrf080086; Fri, 27 Aug 2021 11:42:45 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17RBgjsJ080085; Fri, 27 Aug 2021 11:42:45 GMT (envelope-from git) Date: Fri, 27 Aug 2021 11:42:45 GMT Message-Id: <202108271142.17RBgjsJ080085@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Ka Ho Ng Subject: git: 9a91689e414c - stable/13 - vfs: Add get_write_ioflag helper to calculate ioflag MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: khng X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 9a91689e414cf26204fc993b4d32c4a1fc61aaf0 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Aug 2021 11:42:45 -0000 The branch stable/13 has been updated by khng: URL: https://cgit.FreeBSD.org/src/commit/?id=9a91689e414cf26204fc993b4d32c4a1fc61aaf0 commit 9a91689e414cf26204fc993b4d32c4a1fc61aaf0 Author: Ka Ho Ng AuthorDate: 2021-08-12 09:35:34 +0000 Commit: Ka Ho Ng 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) {