]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
MFC r359836-r359837, r359891, r360236-r360237: close_range(2)
authorKyle Evans <kevans@FreeBSD.org>
Wed, 5 Aug 2020 03:53:57 +0000 (03:53 +0000)
committerKyle Evans <kevans@FreeBSD.org>
Wed, 5 Aug 2020 03:53:57 +0000 (03:53 +0000)
commita80adba5ab46ba6d44d5abfc9b7f3b6de8afda55
treeb5a7537d9fbb67d44876bd51b0ccb8f6cab9937b
parent929b6c297a7bedae52f8963a790629424d3caa25
MFC r359836-r359837, r359891, r360236-r360237: close_range(2)

This commit diverges from our usual procedure of committing generated files
separately because the original commit, r359836, conflated userland use (in
tests) with the implementation.

__FreeBSD_version was already bumped ~15 hours prior to this MFC, 1201522
marks the introduction of close_range.

CPython will use this syscall for some pretty sizable performance gains.

r359836:
Implement a close_range(2) syscall

close_range(min, max, flags) allows for a range of descriptors to be
closed. The Python folk have indicated that they would much prefer this
interface to closefrom(2), as the case may be that they/someone have special
fds dup'd to higher in the range and they can't necessarily closefrom(min)
because they don't want to hit the upper range, but relocating them to lower
isn't necessarily feasible.

sys_closefrom has been rewritten to use kern_close_range() using ~0U to
indicate closing to the end of the range. This was chosen rather than
requiring callers of kern_close_range() to hold FILEDESC_SLOCK across the
call to kern_close_range for simplicity.

The flags argument of close_range(2) is currently unused, so any flags set
is currently EINVAL. It was added to the interface in Linux so that future
flags could be added for, e.g., "halt on first error" and things of this
nature.

This patch is based on a syscall of the same design that is expected to be
merged into Linux.

r359837:
sysent: re-roll after introduction of close_range in r359836

r359891:
close_range/closefrom: fix regression from close_range introduction

close_range will clamp the range between [0, fdp->fd_lastfile], but failed
to take into account that fdp->fd_lastfile can become -1 if all fds are
closed. =-( In this scenario, just return because there's nothing further we
can do at the moment.

Add a test case for this, fork() and simply closefrom(0) twice in the child;
on the second invocation, fdp->fd_lastfile == -1 and will trigger a panic
before this change.

r360236:
close_range(2): use newly assigned AUE_CLOSERANGE

r360237:
sysent: re-roll after 360236 (AUE_CLOSERANGE used)
20 files changed:
include/unistd.h
lib/libc/sys/Makefile.inc
lib/libc/sys/Symbol.map
lib/libc/sys/closefrom.2
sys/compat/freebsd32/freebsd32_syscall.h
sys/compat/freebsd32/freebsd32_syscalls.c
sys/compat/freebsd32/freebsd32_sysent.c
sys/compat/freebsd32/freebsd32_systrace_args.c
sys/compat/freebsd32/syscalls.master
sys/kern/capabilities.conf
sys/kern/init_sysent.c
sys/kern/kern_descrip.c
sys/kern/syscalls.c
sys/kern/syscalls.master
sys/kern/systrace_args.c
sys/sys/syscall.h
sys/sys/syscall.mk
sys/sys/syscallsubr.h
sys/sys/sysproto.h
tests/sys/file/closefrom_test.c