From owner-dev-commits-src-all@freebsd.org Wed Sep 1 12:19:36 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 34233669429; Wed, 1 Sep 2021 12:19:36 +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 4H035h0SThz4rG1; Wed, 1 Sep 2021 12:19:36 +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 DC48D25209; Wed, 1 Sep 2021 12:19:35 +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 181CJZHS054355; Wed, 1 Sep 2021 12:19:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 181CJZxH054354; Wed, 1 Sep 2021 12:19:35 GMT (envelope-from git) Date: Wed, 1 Sep 2021 12:19:35 GMT Message-Id: <202109011219.181CJZxH054354@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Ka Ho Ng Subject: git: 92bb74fd4f01 - main - vfs: Use file_cred for VOP_DEALLOCATE in vn_deallocate if non-NULL 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/main X-Git-Reftype: branch X-Git-Commit: 92bb74fd4f015aad9f50b3bf100e89da7008fda6 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: Wed, 01 Sep 2021 12:19:36 -0000 The branch main has been updated by khng: URL: https://cgit.FreeBSD.org/src/commit/?id=92bb74fd4f015aad9f50b3bf100e89da7008fda6 commit 92bb74fd4f015aad9f50b3bf100e89da7008fda6 Author: Ka Ho Ng AuthorDate: 2021-09-01 12:18:24 +0000 Commit: Ka Ho Ng CommitDate: 2021-09-01 12:19:08 +0000 vfs: Use file_cred for VOP_DEALLOCATE in vn_deallocate if non-NULL This changes vn_deallocate() to match the behavior of vn_rdwr() when picking which ucred to use. That is, vn_deallocate() uses file_cred for making VOP call if it is non-NULL, or use active_cred otherwise. Sponsored by: The FreeBSD Foundation Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D31712 --- sys/kern/vfs_vnops.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index bd512f73eae5..bf1270dc8ad8 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -3463,7 +3463,8 @@ vn_fallocate(struct file *fp, off_t offset, off_t len, struct thread *td) static int vn_deallocate_impl(struct vnode *vp, off_t *offset, off_t *length, int flags, - int ioflag, struct ucred *active_cred, struct ucred *file_cred) + int ioflag, struct ucred *cred, struct ucred *active_cred, + struct ucred *file_cred) { struct mount *mp; void *rl_cookie; @@ -3510,7 +3511,7 @@ vn_deallocate_impl(struct vnode *vp, off_t *offset, off_t *length, int flags, #endif if (error == 0) error = VOP_DEALLOCATE(vp, &off, &len, flags, ioflag, - active_cred); + cred); if ((ioflag & IO_NODELOCKED) == 0) { VOP_UNLOCK(vp); @@ -3530,17 +3531,24 @@ out: return (error); } +/* + * This function is supposed to be used in the situations where the deallocation + * is not triggered by a user request. + */ int vn_deallocate(struct vnode *vp, off_t *offset, off_t *length, int flags, int ioflag, struct ucred *active_cred, struct ucred *file_cred) { + struct ucred *cred; + if (*offset < 0 || *length <= 0 || *length > OFF_MAX - *offset || flags != 0) return (EINVAL); if (vp->v_type != VREG) return (ENODEV); - return (vn_deallocate_impl(vp, offset, length, flags, ioflag, + cred = file_cred != NOCRED ? file_cred : active_cred; + return (vn_deallocate_impl(vp, offset, length, flags, ioflag, cred, active_cred, file_cred)); } @@ -3565,7 +3573,7 @@ vn_fspacectl(struct file *fp, int cmd, off_t *offset, off_t *length, int flags, switch (cmd) { case SPACECTL_DEALLOC: error = vn_deallocate_impl(vp, offset, length, flags, ioflag, - active_cred, fp->f_cred); + active_cred, active_cred, fp->f_cred); break; default: panic("vn_fspacectl: unknown cmd %d", cmd);