git: 92bb74fd4f01 - main - vfs: Use file_cred for VOP_DEALLOCATE in vn_deallocate if non-NULL

Ka Ho Ng khng at FreeBSD.org
Wed Sep 1 12:19:36 UTC 2021


The branch main has been updated by khng:

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

commit 92bb74fd4f015aad9f50b3bf100e89da7008fda6
Author:     Ka Ho Ng <khng at FreeBSD.org>
AuthorDate: 2021-09-01 12:18:24 +0000
Commit:     Ka Ho Ng <khng at FreeBSD.org>
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);


More information about the dev-commits-src-all mailing list