Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(uring): add openat2 compat #78

Merged
merged 2 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions cmake/CompileOption.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,6 @@ if(CMAKE_BUILD_TYPE MATCHES Release)
target_compile_options(co_context PUBLIC -march=native)
endif()

# Get the linux kernel version to liburingcxx
message(STATUS "target_kernel_version = ${CMAKE_SYSTEM_VERSION}")
set(kernel_version ${CMAKE_SYSTEM_VERSION})
string(REGEX MATCH "^([0-9]+)\.([0-9]+)" kernel_version ${kernel_version})
string(REGEX MATCH "^([0-9]+)" kernel_version_major ${kernel_version})
string(REGEX REPLACE "^([0-9]+)\\." "" kernel_version_minor ${kernel_version})
message(STATUS "kernel_version_major = ${kernel_version_major}")
message(STATUS "kernel_version_minor = ${kernel_version_minor}")
target_compile_definitions(co_context
PUBLIC "$<BUILD_INTERFACE:LIBURINGCXX_KERNEL_VERSION_MAJOR=${kernel_version_major}>"
PUBLIC "$<BUILD_INTERFACE:LIBURINGCXX_KERNEL_VERSION_MINOR=${kernel_version_minor}>"
)
unset(kernel_version)

# Optional IPO/LTO.
include(CheckIPOSupported)
check_ipo_supported(RESULT is_support_IPO OUTPUT output_support_IPO)
Expand Down
17 changes: 17 additions & 0 deletions cmake/Platform.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
# ----------------------------------------------------------------------------
# Linux
# ----------------------------------------------------------------------------
# Get the linux kernel version to liburingcxx
message(STATUS "target_kernel_version = ${CMAKE_SYSTEM_VERSION}")
set(kernel_version ${CMAKE_SYSTEM_VERSION})
string(REGEX MATCH "^([0-9]+)\.([0-9]+)" kernel_version ${kernel_version})
string(REGEX MATCH "^([0-9]+)" kernel_version_major ${kernel_version})
string(REGEX REPLACE "^([0-9]+)\\." "" kernel_version_minor ${kernel_version})
message(STATUS "kernel_version_major = ${kernel_version_major}")
message(STATUS "kernel_version_minor = ${kernel_version_minor}")
target_compile_definitions(co_context
PUBLIC "$<BUILD_INTERFACE:LIBURINGCXX_KERNEL_VERSION_MAJOR=${kernel_version_major}>"
PUBLIC "$<BUILD_INTERFACE:LIBURINGCXX_KERNEL_VERSION_MINOR=${kernel_version_minor}>"
)
unset(kernel_version)

# ----------------------------------------------------------------------------
# Gcc
# ----------------------------------------------------------------------------
Expand Down
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
4 changes: 2 additions & 2 deletions include/uring/utility/kernel_version.hpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once

#ifndef LIBURINGCXX_KERNEL_VERSION_MAJOR
#error Fail to detect kernel version. Please check CMakeLists.txt (at root level).
#error Fail to detect kernel version. Please check cmake/Platform.cmake .
#endif

#ifndef LIBURINGCXX_KERNEL_VERSION_MINOR
#error Fail to detect kernel version. Please check CMakeLists.txt (at root level).
#error Fail to detect kernel version. Please check cmake/Platform.cmake .
#endif

namespace liburingcxx {
Expand Down
Loading