BOOST_ASIO_HAS_IO_URING is a user-defined macro that enables io_uring
support in Boost.Asio for specific operations that explicitly opt in,
such as file I/O via basic_file (BOOST_ASIO_HAS_FILE) and buffer
registration. Unlike BOOST_ASIO_HAS_IO_URING_AS_DEFAULT, it does NOT
replace epoll as the default event loop. Currently, Ceph does not use
Boost.Asio to perform file I/O, so this macro only affects compilation,
not runtime behavior.
When BOOST_ASIO_HAS_IO_URING is defined, the umbrella header
boost/asio.hpp pulls in <liburing.h> via:
boost/asio.hpp
-> boost/asio/basic_file.hpp (guarded by BOOST_ASIO_HAS_FILE)
-> boost/asio/detail/io_uring_file_service.hpp
-> boost/asio/detail/io_uring_descriptor_service.hpp
-> boost/asio/detail/io_uring_service.hpp
-> <liburing.h>
PR #50821 introduced BOOST_ASIO_HAS_IO_URING (commit
05c341b30de) as
preparation for uring-based file I/O in rgw/posix. To avoid pulling
liburing headers (which define macros like BLOCK_SIZE and DATA_OFFSET
that conflict with Ceph code) into unrelated translation units, that PR
also converted many files to use granular Boost.Asio includes instead of
the umbrella boost/asio.hpp.
However, BOOST_ASIO_HAS_IO_URING was added as a global compile
definition, and individual targets linked uring::uring directly. This
has two problems:
1. The uring::uring CMake target only exists when WITH_LIBURING=ON, so
targets that link it unconditionally break when WITH_LIBURING=OFF.
2. The global definition causes all translation units to see
BOOST_ASIO_HAS_IO_URING, even those that don't need io_uring.
Since neither CMake's FindBoost module nor Boost's CMake config file
defines a Boost::asio target, introduce one as an INTERFACE IMPORTED
library. When WITH_LIBURING=ON, the Boost::asio target carries the
BOOST_ASIO_HAS_IO_URING definition and uring::uring dependency; when
WITH_LIBURING=OFF, it is an empty interface. Targets that don't need
io_uring should use Boost::headers or Boost::boost instead.
This also improves code organization:
- Scope the BOOST_ASIO_HAS_IO_URING compile definition to Boost::asio
instead of adding it globally, so only targets that actually use
Boost.Asio with io_uring see the definition.
- Place the uring-in-Boost::asio configuration next to where we
build/detect Boost libraries for better readability.
- Set the Boost::asio properties in a single place for better
maintainability.
See also
-
05c341b30deab327444eac464e24a840dae25083
-
f479bbc4bc118989849fb663b5dcf5f46f05097d
Signed-off-by: Kefu Chai <k.chai@proxmox.com>