git: cfd6c9b99f49 - stable/13 - vfs: slightly rework vn_rlimit_fsize
Mateusz Guzik
mjg at FreeBSD.org
Sun Jun 13 02:16:27 UTC 2021
The branch stable/13 has been updated by mjg:
URL: https://cgit.FreeBSD.org/src/commit/?id=cfd6c9b99f49dd24860456742eecccabfc100326
commit cfd6c9b99f49dd24860456742eecccabfc100326
Author: Mateusz Guzik <mjg at FreeBSD.org>
AuthorDate: 2021-05-29 17:33:50 +0000
Commit: Mateusz Guzik <mjg at FreeBSD.org>
CommitDate: 2021-06-13 02:15:25 +0000
vfs: slightly rework vn_rlimit_fsize
(cherry picked from commit 478c52f1e3654213c7d79096a2bc7f908e0b501d)
---
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 cf6a1f715d83..fc5118e8aa24 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -2364,12 +2364,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-all
mailing list