fcntl: add F_DUPFD_QUERY fcntl()
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 9 May 2024 11:04:24 +0000 (13:04 +0200)
committerChristian Brauner <brauner@kernel.org>
Fri, 10 May 2024 06:26:31 +0000 (08:26 +0200)
commitc62b758bae6af16fee94f556091fa74883a96b1e
tree78133c1a8dbb78f59a4afa5aa84b6b78e3a2540e
parenta0fde7ed05ff020c3e7f410d73ce4f3a72b262d6
fcntl: add F_DUPFD_QUERY fcntl()

Often userspace needs to know whether two file descriptors refer to the
same struct file. For example, systemd uses this to filter out duplicate
file descriptors in it's file descriptor store (cf. [1]) and vulkan uses
it to compare dma-buf fds (cf. [2]).

The only api we provided for this was kcmp() but that's not generally
available or might be disallowed because it is way more powerful (allows
ordering of file pointers, operates on non-current task) etc. So give
userspace a simple way of comparing two file descriptors for sameness
adding a new fcntl() F_DUDFD_QUERY.

Link: https://github.com/systemd/systemd/blob/a4f0e0da3573a10bc5404142be8799418760b1d1/src/basic/fd-util.c#L517
Link: https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/render/vulkan/texture.c#L490
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
[brauner: commit message]
Signed-off-by: Christian Brauner <brauner@kernel.org>
fs/fcntl.c
include/uapi/linux/fcntl.h