io_uring_close_ring_fd(3)

πŸ’– io_uring_close_ring_fd β€” the liburing glow-up where your fd just… dips πŸ’…

okay bestie, so this is a page from the liburing manual, and it's about the absolute main-character move of closing a ring file descriptor and living your life through a registered index instead. no cap.


✨ NAME ✨

io_uring_close_ring_fd β€” close a ring file descriptor and use it only via registered index πŸ¦‹


🌸 SYNOPSIS 🌸

#include <liburing.h>

int io_uring_close_ring_fd(struct io_uring *ring);

πŸŽ€ DESCRIPTION πŸŽ€

so like, io_uring_close_ring_fd(3) closes the ring file descriptor, and that fd must have been previously registered, periodt. the file itself stays open btw β€” it doesn't go anywhere β€” but now you can only reach it via the registered index, not via any file descriptor at all. she's exclusive now πŸ’….

and here's the slay part: subsequent liburing calls keep working just fine, because they use the registered ring fd instead. nothing breaks, everything continues, it's giving seamless πŸ”₯.

your kernel has to support IORING_FEAT_REG_REG_RING for any of this to hit, so check that first bestie, fr fr.

now, why would anyone want this? libraries that must avoid disrupting their users' uses of file descriptors, and that also need to keep working even when faced with close_range(2) and similar fd-nuking situations, can use io_uring_close_ring_fd(3) to work with liburing while having zero open file descriptors. imagine the peace. no fd left behind. iconic ✨.


🫢 NOTES 🫢

every single thread that wants to make use of io_uring has to register the fd. yes, every one. no shortcuts πŸ™ˆ.

so a library that might get called from arbitrary threads may need to detect when it gets called on a thread it's never seen before, and then create and register a ring for that thread. basically: new thread, who dis? here's your ring πŸ’–.


⭐ RETURN VALUE ⭐

  • 1 β€” success, you ate πŸ’…
  • -errno β€” error, and it tells you which one via errno 😭

πŸ’œ SEE ALSO πŸ’œ


and that's the whole vibe, bestie πŸŽ€ β€” this page came from liburing-2.4, dated September 25, 2022. go forth and close that fd like the icon you are πŸŒˆβœ¨πŸ‘‘

πŸ“¦ where this page comes from