io_uring: add support for passing fixed file descriptors
authorJens Axboe <axboe@kernel.dk>
Mon, 13 Jun 2022 10:47:02 +0000 (04:47 -0600)
committerJens Axboe <axboe@kernel.dk>
Thu, 21 Jul 2022 14:46:58 +0000 (08:46 -0600)
commit9bf2944565b3ec20c9b27ccaad7e729d3588d46b
tree65760094b2721112a6b7a3868461e1f3bf3bff9b
parentd75c24f662f1feb350d84afe23d7536397319d09
io_uring: add support for passing fixed file descriptors

With IORING_OP_MSG_RING, one ring can send a message to another ring.
Extend that support to also allow sending a fixed file descriptor to
that ring, enabling one ring to pass a registered descriptor to another
one.

Arguments are extended to pass in:

sqe->addr3 fixed file slot in source ring
sqe->file_index fixed file slot in destination ring

IORING_OP_MSG_RING is extended to take a command argument in sqe->addr.
If set to zero (or IORING_MSG_DATA), it sends just a message like before.
If set to IORING_MSG_SEND_FD, a fixed file descriptor is sent according
to the above arguments.

Two common use cases for this are:

1) Server needs to be shutdown or restarted, pass file descriptors to
   another onei

2) Backend is split, and one accepts connections, while others then get
  the fd passed and handle the actual connection.

Both of those are classic SCM_RIGHTS use cases, and it's not possible to
support them with direct descriptors today.

By default, this will post a CQE to the target ring, similarly to how
IORING_MSG_DATA does it. If IORING_MSG_RING_CQE_SKIP is set, no message
is posted to the target ring. The issuer is expected to notify the
receiver side separately.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
include/uapi/linux/io_uring.h
io_uring/msg_ring.c