git: 478c52f1e365 - main - vfs: slightly rework vn_rlimit_fsize

Mateusz Guzik mjg at FreeBSD.org
Sat May 29 22:04:20 UTC 2021


The branch main has been updated by mjg:

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

commit 478c52f1e3654213c7d79096a2bc7f908e0b501d
Author:     Mateusz Guzik <mjg at FreeBSD.org>
AuthorDate: 2021-05-29 17:33:50 +0000
Commit:     Mateusz Guzik <mjg at FreeBSD.org>
CommitDate: 2021-05-29 22:04:09 +0000

    vfs: slightly rework vn_rlimit_fsize
---
 sys/kern/vfs_vnops.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index 34fcef1b7e1f..019aefead0b3 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -2363,12 +2363,25 @@ vn_rlimit_fsize(const struct vnode *vp, const struct uio *uio,
 	off_t lim;
 	bool ktr_write;
 
-	if (vp->v_type != VREG || td == NULL ||
-	    (td->td_pflags2 & TDP2_ACCT) != 0)
+	if (td == NULL)
 		return (0);
+
+	/*
+	 * There are conditions where the limit is to be ignored.
+	 * However, since it is almost never reached, check it first.
+	 */
 	ktr_write = (td->td_pflags & TDP_INKTRACE) != 0;
-	lim = ktr_write ? td->td_ktr_io_lim : lim_cur(td, RLIMIT_FSIZE);
-	if ((uoff_t)uio->uio_offset + uio->uio_resid <= lim)
+	lim = lim_cur(td, RLIMIT_FSIZE);
+	if (__predict_false(ktr_write))
+		lim = td->td_ktr_io_lim;
+	if (__predict_true((uoff_t)uio->uio_offset + uio->uio_resid <= lim))
+		return (0);
+
+	/*
+	 * The limit is reached.
+	 */
+	if (vp->v_type != VREG ||
+	    (td->td_pflags2 & TDP2_ACCT) != 0)
 		return (0);
 
 	if (!ktr_write || ktr_filesize_limit_signal) {


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