From ac6117ea4ef49ee6d534352624f4c45bdcb32221 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 28 Nov 2024 16:57:39 +0100 Subject: [PATCH] io/uring/CoOperation: add unlink support --- src/io/uring/CoOperation.cxx | 14 ++++++++++++++ src/io/uring/CoOperation.hxx | 23 +++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/io/uring/CoOperation.cxx b/src/io/uring/CoOperation.cxx index 1c50d88dd..ad5b84a32 100644 --- a/src/io/uring/CoOperation.cxx +++ b/src/io/uring/CoOperation.cxx @@ -130,4 +130,18 @@ CoWriteOperation::GetValue(int value) const return value; } +CoUnlinkOperation::CoUnlinkOperation(struct io_uring_sqe &sqe, + const char *path, + int flags) noexcept +{ + io_uring_prep_unlink(&sqe, path, flags); +} + +CoUnlinkOperation::CoUnlinkOperation(struct io_uring_sqe &sqe, + FileDescriptor directory_fd, const char *path, + int flags) noexcept +{ + io_uring_prep_unlinkat(&sqe, directory_fd.Get(), path, flags); +} + } // namespace Uring diff --git a/src/io/uring/CoOperation.hxx b/src/io/uring/CoOperation.hxx index 6182dc501..f1115b9cb 100644 --- a/src/io/uring/CoOperation.hxx +++ b/src/io/uring/CoOperation.hxx @@ -138,4 +138,27 @@ public: using CoWrite = CoOperation; +/** + * Performs the unlink() or unlinkat() system call. + * + * @return 0 on success or a negative errno value on error (no + * exceptions thrown on error) + */ +class CoUnlinkOperation final { +public: + CoUnlinkOperation(struct io_uring_sqe &sqe, + const char *path, + int flags=0) noexcept; + + CoUnlinkOperation(struct io_uring_sqe &sqe, + FileDescriptor directory_fd, const char *path, + int flags=0) noexcept; + + int GetValue(int value) const noexcept { + return value; + } +}; + +using CoUnlink = CoOperation; + } // namespace Uring