Skip to content

Commit

Permalink
feat(uring): openat2 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
Codesire-Deng committed Sep 17, 2023
1 parent 99e52ac commit beedf76
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
4 changes: 4 additions & 0 deletions include/co_context/detail/lazy_io_awaiter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,12 +630,15 @@ struct lazy_recv_multishot : lazy_awaiter {
};
#endif

#ifdef LIBURINGCXX_HAS_OPENAT2
struct lazy_openat2 : lazy_awaiter {
inline lazy_openat2(int dfd, const char *path, open_how *how) noexcept {
sqe->prep_openat2(dfd, path, how);
}
};
#endif

#ifdef LIBURINGCXX_HAS_OPENAT2
/* open directly into the fixed file table */
struct lazy_openat2_direct : lazy_awaiter {
inline lazy_openat2_direct(
Expand All @@ -644,6 +647,7 @@ struct lazy_openat2_direct : lazy_awaiter {
sqe->prep_openat2_direct(dfd, path, how, file_index);
}
};
#endif

struct lazy_epoll_ctl : lazy_awaiter {
inline lazy_epoll_ctl(int epfd, int fd, int op, epoll_event *ev) noexcept {
Expand Down
4 changes: 4 additions & 0 deletions include/co_context/lazy_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,18 +425,22 @@ inline namespace lazy {
}
#endif

#ifdef LIBURINGCXX_HAS_OPENAT2
[[CO_CONTEXT_AWAIT_HINT]]
inline detail::lazy_openat2
openat2(int dfd, const char *path, open_how *how) noexcept {
return detail::lazy_openat2{dfd, path, how};
}
#endif

#ifdef LIBURINGCXX_HAS_OPENAT2
[[CO_CONTEXT_AWAIT_HINT]]
inline detail::lazy_openat2_direct openat2_direct(
int dfd, const char *path, open_how *how, unsigned int file_index
) noexcept {
return detail::lazy_openat2_direct{dfd, path, how, file_index};
}
#endif

[[CO_CONTEXT_AWAIT_HINT]]
inline detail::lazy_epoll_ctl
Expand Down
9 changes: 0 additions & 9 deletions include/uring/compat.h

This file was deleted.

8 changes: 8 additions & 0 deletions include/uring/compat.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

#include <linux/time_types.h>

#if __has_include(<linux/openat2.h>)
#include <linux/openat2.h>
#define LIBURINGCXX_HAS_OPENAT2
#endif
8 changes: 7 additions & 1 deletion include/uring/sq_entry.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <uring/compat.h>
#include <uring/compat.hpp>
#include <uring/io_uring.h>
#include <uring/utility/io_helper.hpp>
#include <uring/utility/kernel_version.hpp>
Expand Down Expand Up @@ -559,14 +559,17 @@ class sq_entry final : private io_uring_sqe {
}
#endif

#ifdef LIBURINGCXX_HAS_OPENAT2
inline sq_entry &
prep_openat2(int dfd, const char *path, struct open_how *how) noexcept {
prep_rw(
IORING_OP_OPENAT2, dfd, path, sizeof(*how), (uint64_t)(uintptr_t)how
);
return *this;
}
#endif

#ifdef LIBURINGCXX_HAS_OPENAT2
/* open directly into the fixed file table */
inline sq_entry &prep_openat2_direct(
int dfd, const char *path, struct open_how *how, unsigned file_index
Expand All @@ -575,13 +578,16 @@ class sq_entry final : private io_uring_sqe {
set_target_fixed_file(file_index);
return *this;
}
#endif

#ifdef LIBURINGCXX_HAS_OPENAT2
/* open directly into the fixed file table */
inline sq_entry &prep_openat2_direct_alloc(
int dfd, const char *path, struct open_how *how
) noexcept {
return prep_openat2_direct(dfd, path, how, IORING_FILE_INDEX_ALLOC - 1);
}
#endif

inline sq_entry &
prep_epoll_ctl(int epfd, int fd, int op, epoll_event *ev) noexcept {
Expand Down
2 changes: 1 addition & 1 deletion include/uring/uring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

#include <uring/barrier.h>
#include <uring/buf_ring.hpp>
#include <uring/compat.h>
#include <uring/compat.hpp>
#include <uring/cq_entry.hpp>
#include <uring/detail/cq.hpp>
#include <uring/detail/int_flags.h>
Expand Down

0 comments on commit beedf76

Please sign in to comment.