]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
Add vn_rlimit_fsizex() and vn_rlimit_fsizex_res()
authorKonstantin Belousov <kib@FreeBSD.org>
Sun, 18 Sep 2022 11:46:19 +0000 (14:46 +0300)
committerKonstantin Belousov <kib@FreeBSD.org>
Sat, 24 Sep 2022 16:41:33 +0000 (19:41 +0300)
commit1b4b75171ee3f2213b7671878a910fd5ddb3306e
treee917be73c4eeaa546591ae11d0bfa2a19a068dfc
parentb5b16659c5aceb9caa0a9b76c7746e1d12a505ce
Add vn_rlimit_fsizex() and vn_rlimit_fsizex_res()

The vn_rlimit_fsizex() function:
- checks that the write does not exceed RLIMIT_FSIZE limit and fs
  maximum supported file size
- truncates write length if it exceeds the RLIMIT_FSIZE or max file size,
  but there are some bytes to write
- sends SIGXFSZ if RLIMIT_FSIZE would be exceed otherwise

POSIX mandates the truncated write in case when some bytes can be
written but whole write request fails the RLIMIT_FSIZE check.

The function is supposed to be used from VOP_WRITE()s. Due to
pecularity in the VFS generic write syscall layer, uio_resid must
correctly reflect the written amount (noted by markj). Provide the dual
vn_rlimit_fsizex_res() function to correct uio_resid after the clamp
done in vn_rlimit_fsizex() on VOP_WRITE() return.

PR: 164793
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
sys/sys/vnode.h