git: 2ac083f60f8c - main - Add vn_rlimit_trunc()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 24 Sep 2022 16:42:32 UTC
The branch main has been updated by kib:
URL: https://cgit.FreeBSD.org/src/commit/?id=2ac083f60f8c9ce361c3daf691c60486459d87ae
commit 2ac083f60f8c9ce361c3daf691c60486459d87ae
Author: Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2022-09-18 19:52:13 +0000
Commit: Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2022-09-24 16:41:18 +0000
Add vn_rlimit_trunc()
Reviewed by: asomers, jah, markj
Tested by: pho
Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Differential revision: https://reviews.freebsd.org/D36625
---
sys/kern/vfs_vnops.c | 24 +++++++++++++++++++-----
sys/sys/vnode.h | 1 +
2 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c
index 1d2c4f332473..6eef39a37f25 100644
--- a/sys/kern/vfs_vnops.c
+++ b/sys/kern/vfs_vnops.c
@@ -2372,6 +2372,23 @@ vn_vget_ino_gen(struct vnode *vp, vn_get_ino_t alloc, void *alloc_arg,
return (error);
}
+static void
+vn_send_sigxfsz(struct proc *p)
+{
+ PROC_LOCK(p);
+ kern_psignal(p, SIGXFSZ);
+ PROC_UNLOCK(p);
+}
+
+int
+vn_rlimit_trunc(u_quad_t size, struct thread *td)
+{
+ if (size <= lim_cur(td, RLIMIT_FSIZE))
+ return (0);
+ vn_send_sigxfsz(td->td_proc);
+ return (EFBIG);
+}
+
int
vn_rlimit_fsize(const struct vnode *vp, const struct uio *uio,
struct thread *td)
@@ -2400,11 +2417,8 @@ vn_rlimit_fsize(const struct vnode *vp, const struct uio *uio,
(td->td_pflags2 & TDP2_ACCT) != 0)
return (0);
- if (!ktr_write || ktr_filesize_limit_signal) {
- PROC_LOCK(td->td_proc);
- kern_psignal(td->td_proc, SIGXFSZ);
- PROC_UNLOCK(td->td_proc);
- }
+ if (!ktr_write || ktr_filesize_limit_signal)
+ vn_send_sigxfsz(td->td_proc);
return (EFBIG);
}
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index f3170d77e6d4..da17170cbb2d 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -786,6 +786,7 @@ int vn_rdwr_inchunks(enum uio_rw rw, struct vnode *vp, void *base,
int vn_read_from_obj(struct vnode *vp, struct uio *uio);
int vn_rlimit_fsize(const struct vnode *vp, const struct uio *uio,
struct thread *td);
+int vn_rlimit_trunc(u_quad_t size, struct thread *td);
int vn_start_write(struct vnode *vp, struct mount **mpp, int flags);
int vn_start_secondary_write(struct vnode *vp, struct mount **mpp,
int flags);