diff --git a/docs/ops.md b/docs/ops.md index 02fac6a1..4d4ccbd7 100644 --- a/docs/ops.md +++ b/docs/ops.md @@ -69,6 +69,7 @@ These are fundamental asynchronous operations. Many of them are asynchronous ver - `condy::async_fixed_fd_install()` - `condy::async_ftruncate()` - `condy::async_cmd_discard()` +- `condy::async_cmd_zone_reset_all()` - `condy::async_bind()` - `condy::async_listen()` - `condy::async_epoll_ctl()` @@ -135,6 +136,7 @@ These asynchronous operations accept the index of a file registered with the ker - `condy::async_cmd_getsockname()` - `condy::async_ftruncate()` - `condy::async_cmd_discard()` +- `condy::async_cmd_zone_reset_all()` - `condy::async_bind()` - `condy::async_listen()` diff --git a/include/condy/async_operations.hpp b/include/condy/async_operations.hpp index e795793b..06110bdb 100644 --- a/include/condy/async_operations.hpp +++ b/include/condy/async_operations.hpp @@ -1011,6 +1011,17 @@ inline auto async_cmd_discard(Fd fd, uint64_t offset, uint64_t nbytes) { } #endif +#if CONDY_URING_VERSION_GE(2, 16) // >= 2.16 +/** + * @brief See io_uring_prep_cmd_zone_reset_all + */ +template +inline auto async_cmd_zone_reset_all(Fd fd) { + auto op = detail::make_op_awaiter(io_uring_prep_cmd_zone_reset_all, fd); + return detail::maybe_flag_fixed_fd(std::move(op), fd); +} +#endif + #if CONDY_URING_VERSION_GE(2, 7) // >= 2.7 /** * @brief See io_uring_prep_bind diff --git a/module/condy.cppm b/module/condy.cppm index cb167d00..8cec558a 100644 --- a/module/condy.cppm +++ b/module/condy.cppm @@ -204,6 +204,9 @@ using condy::async_cmd_getsockname; using condy::async_nop128; using condy::async_uring_cmd128; #endif +#if CONDY_URING_VERSION_GE(2, 16) // >= 2.16 +using condy::async_cmd_zone_reset_all; +#endif } // namespace condy diff --git a/tests/test_async_operations.4.cpp b/tests/test_async_operations.4.cpp index 5d0cb001..00c58bdc 100644 --- a/tests/test_async_operations.4.cpp +++ b/tests/test_async_operations.4.cpp @@ -870,6 +870,51 @@ TEST_CASE("test async_operations - test cmd_discard - fixed fd") { } #endif +#if CONDY_URING_VERSION_GE(2, 16) // >= 2.16 +TEST_CASE("test async_operations - test cmd_zone_reset_all - basic") { + BlkDevice blkdev; + if (blkdev.path().empty()) { + MESSAGE("Can't create loop device, skipping"); + return; + } + + int fd = open(blkdev.path().c_str(), O_RDWR); + REQUIRE(fd >= 0); + + auto func = [&]() -> condy::Coro { + int r = co_await condy::async_cmd_zone_reset_all(fd); + REQUIRE(r == 0); + }; + condy::sync_wait(func()); + close(fd); +} +#endif + +#if CONDY_URING_VERSION_GE(2, 16) // >= 2.16 +TEST_CASE("test async_operations - test cmd_zone_reset_all - fixed fd") { + BlkDevice blkdev; + if (blkdev.path().empty()) { + MESSAGE("Can't create loop device, skipping"); + return; + } + + int fd = open(blkdev.path().c_str(), O_RDWR); + REQUIRE(fd >= 0); + + auto func = [&]() -> condy::Coro { + auto &fd_table = condy::current_runtime().fd_table(); + fd_table.init(1); + int r = co_await condy::async_files_update(&fd, 1, 0); + REQUIRE(r == 1); + + r = co_await condy::async_cmd_zone_reset_all(condy::fixed(0)); + REQUIRE(r == 0); + }; + condy::sync_wait(func()); + close(fd); +} +#endif + #if CONDY_URING_VERSION_GE(2, 7) // >= 2.7 TEST_CASE("test async_operations - test bind - basic") { int sock_fd = socket(AF_INET, SOCK_DGRAM, 0);