Skip to content

Commit 9dd892e

Browse files
committed
rgw: switch back to boost::asio for spawn() and yield_context
a fork of boost::asio::spawn() was introduced in 2020 with spawn::spawn() from ceph#31580. this fork enabled rgw to customize how the coroutine stacks are allocated in order to avoid stack overflows in frontend request coroutines. this customization was based on a StackAllocator concept from the boost::context library in boost 1.80, that same StackAllocator overload was added to boost::asio::spawn(), along with other improvements like per-op cancellation. now that boost has everything we need, switch back and drop the spawn submodule this required switching a lot of async functions from async_completion<> to async_initiate<>. similar changes were necessary to enable the c++20 coroutine token boost::asio::use_awaitable Signed-off-by: Casey Bodley <[email protected]>
1 parent 9117352 commit 9dd892e

40 files changed

+393
-362
lines changed

src/cls/CMakeLists.txt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ if (WITH_RADOSGW)
7676
target_link_libraries(cls_otp OATH::OATH)
7777
target_include_directories(cls_otp
7878
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw/driver/rados"
79-
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw"
80-
PUBLIC "${CMAKE_SOURCE_DIR}/src/spawn/include")
79+
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw")
8180
set_target_properties(cls_otp PROPERTIES
8281
VERSION "1.0.0"
8382
SOVERSION "1"
@@ -204,8 +203,7 @@ if (WITH_RADOSGW)
204203
target_link_libraries(cls_rgw ${FMT_LIB} json_spirit)
205204
target_include_directories(cls_rgw
206205
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw/driver/rados"
207-
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw"
208-
PUBLIC "${CMAKE_SOURCE_DIR}/src/spawn/include")
206+
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw")
209207
set_target_properties(cls_rgw PROPERTIES
210208
VERSION "1.0.0"
211209
SOVERSION "1"
@@ -220,8 +218,7 @@ if (WITH_RADOSGW)
220218
add_library(cls_rgw_client STATIC ${cls_rgw_client_srcs})
221219
target_include_directories(cls_rgw_client
222220
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw/driver/rados"
223-
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw"
224-
PUBLIC "${CMAKE_SOURCE_DIR}/src/spawn/include")
221+
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw")
225222

226223
endif (WITH_RADOSGW)
227224

@@ -313,8 +310,7 @@ if (WITH_RADOSGW)
313310
add_library(cls_rgw_gc SHARED ${cls_rgw_gc_srcs})
314311
target_include_directories(cls_rgw_gc
315312
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw/driver/rados"
316-
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw"
317-
PUBLIC "${CMAKE_SOURCE_DIR}/src/spawn/include")
313+
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw")
318314
set_target_properties(cls_rgw_gc PROPERTIES
319315
VERSION "1.0.0"
320316
SOVERSION "1"
@@ -328,8 +324,7 @@ if (WITH_RADOSGW)
328324
add_library(cls_rgw_gc_client STATIC ${cls_rgw_gc_client_srcs})
329325
target_include_directories(cls_rgw_gc_client
330326
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw/driver/rados"
331-
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw"
332-
PUBLIC "${CMAKE_SOURCE_DIR}/src/spawn/include")
327+
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw")
333328
endif (WITH_RADOSGW)
334329

335330

src/common/async/yield_context.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,18 @@
1717
#include <boost/range/begin.hpp>
1818
#include <boost/range/end.hpp>
1919
#include <boost/asio/io_context.hpp>
20+
#include <boost/asio/spawn.hpp>
2021

2122
#include "acconfig.h"
2223

23-
#include <spawn/spawn.hpp>
24-
25-
/// optional-like wrapper for a spawn::yield_context and its associated
26-
/// boost::asio::io_context. operations that take an optional_yield argument
27-
/// will, when passed a non-empty yield context, suspend this coroutine instead
28-
/// of the blocking the thread of execution
24+
/// optional-like wrapper for a boost::asio::yield_context. operations that take
25+
/// an optional_yield argument will, when passed a non-empty yield context,
26+
/// suspend this coroutine instead of the blocking the thread of execution
2927
class optional_yield {
30-
boost::asio::io_context *c = nullptr;
31-
spawn::yield_context *y = nullptr;
28+
boost::asio::yield_context *y = nullptr;
3229
public:
3330
/// construct with a valid io and yield_context
34-
explicit optional_yield(boost::asio::io_context& c,
35-
spawn::yield_context& y) noexcept
36-
: c(&c), y(&y) {}
31+
optional_yield(boost::asio::yield_context& y) noexcept : y(&y) {}
3732

3833
/// type tag to construct an empty object
3934
struct empty_t {};
@@ -42,11 +37,8 @@ class optional_yield {
4237
/// implicit conversion to bool, returns true if non-empty
4338
operator bool() const noexcept { return y; }
4439

45-
/// return a reference to the associated io_context. only valid if non-empty
46-
boost::asio::io_context& get_io_context() const noexcept { return *c; }
47-
4840
/// return a reference to the yield_context. only valid if non-empty
49-
spawn::yield_context& get_yield_context() const noexcept { return *y; }
41+
boost::asio::yield_context& get_yield_context() const noexcept { return *y; }
5042
};
5143

5244
// type tag object to construct an empty optional_yield

src/crypto/isa-l/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ endif(HAVE_NASM_X64)
3030
add_library(ceph_crypto_isal SHARED ${isal_crypto_plugin_srcs})
3131
target_include_directories(ceph_crypto_isal PRIVATE ${isal_dir}/include)
3232

33-
target_link_libraries(ceph_crypto_isal PRIVATE spawn)
33+
target_link_libraries(ceph_crypto_isal PRIVATE Boost::context)
3434

3535
set_target_properties(ceph_crypto_isal PROPERTIES
3636
VERSION 1.0.0

src/crypto/openssl/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ add_library(ceph_crypto_openssl SHARED ${openssl_crypto_plugin_srcs})
88
target_link_libraries(ceph_crypto_openssl
99
PRIVATE OpenSSL::Crypto
1010
$<$<PLATFORM_ID:Windows>:ceph-common>
11-
spawn)
11+
Boost::context)
1212
target_include_directories(ceph_crypto_openssl PRIVATE ${OPENSSL_INCLUDE_DIR})
1313
add_dependencies(crypto_plugins ceph_crypto_openssl)
1414
set_target_properties(ceph_crypto_openssl PROPERTIES INSTALL_RPATH "")

src/crypto/qat/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ add_dependencies(crypto_plugins ceph_crypto_qat)
1414
target_link_libraries(ceph_crypto_qat PRIVATE
1515
QAT::qat
1616
QAT::usdm
17-
spawn)
17+
Boost::context)
1818

1919
add_dependencies(crypto_plugins ceph_crypto_qat)
2020
set_target_properties(ceph_crypto_qat PROPERTIES VERSION 1.0.0 SOVERSION 1)

src/crypto/qat/qcccrypto.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ bool QccCrypto::perform_op_batch(unsigned char* out, const unsigned char* in, si
331331
int avail_inst = NON_INSTANCE;
332332

333333
if (y) {
334-
spawn::yield_context yield = y.get_yield_context();
334+
boost::asio::yield_context yield = y.get_yield_context();
335335
avail_inst = async_get_instance(yield);
336336
} else {
337337
auto result = async_get_instance(boost::asio::use_future);
@@ -546,7 +546,7 @@ bool QccCrypto::symPerformOp(int avail_inst,
546546
do {
547547
poll_retry_num = RETRY_MAX_NUM;
548548
if (y) {
549-
spawn::yield_context yield = y.get_yield_context();
549+
boost::asio::yield_context yield = y.get_yield_context();
550550
status = helper.async_perform_op(std::span<CpaCySymDpOpData*>(pOpDataVec), yield);
551551
} else {
552552
auto result = helper.async_perform_op(std::span<CpaCySymDpOpData*>(pOpDataVec), boost::asio::use_future);

src/rgw/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ target_link_libraries(rgw_common
301301
PUBLIC
302302
${LUA_LIBRARIES}
303303
RapidJSON::RapidJSON
304-
spawn
304+
Boost::context
305305
${FMT_LIB}
306306
OpenSSL::SSL)
307307
target_include_directories(rgw_common
@@ -433,7 +433,7 @@ target_link_libraries(rgw_a
433433
OATH::OATH
434434
PUBLIC
435435
rgw_common
436-
spawn)
436+
Boost::context)
437437

438438
if(WITH_CURL_OPENSSL)
439439
# used by rgw_http_client_curl.cc
@@ -449,7 +449,7 @@ set(rgw_schedulers_srcs
449449

450450
add_library(rgw_schedulers STATIC ${rgw_schedulers_srcs})
451451
target_link_libraries(rgw_schedulers
452-
PUBLIC dmclock::dmclock spawn)
452+
PUBLIC dmclock::dmclock Boost::context)
453453

454454
set(radosgw_srcs
455455
rgw_main.cc)

src/rgw/driver/d4n/d4n_directory.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct initiate_exec {
1717
{
1818
auto h = boost::asio::consign(std::move(handler), conn);
1919
return boost::asio::dispatch(get_executor(),
20-
[c = conn, &req, &resp, h = std::move(h)] {
20+
[c = conn, &req, &resp, h = std::move(h)] () mutable {
2121
return c->async_exec(req, resp, std::move(h));
2222
});
2323
}

src/rgw/driver/d4n/d4n_policy.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ struct initiate_exec {
1717
void operator()(Handler handler, const boost::redis::request& req, Response& resp)
1818
{
1919
auto h = asio::consign(std::move(handler), conn);
20-
return asio::dispatch(get_executor(), [c=conn, &req, &resp, h=std::move(h)] {
21-
c->async_exec(req, resp, std::move(h));
22-
});
20+
return asio::dispatch(get_executor(),
21+
[c=conn, &req, &resp, h=std::move(h)] () mutable {
22+
c->async_exec(req, resp, std::move(h));
23+
});
2324
}
2425
};
2526

src/rgw/driver/dbstore/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ target_include_directories(dbstore_lib
2929
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw"
3030
PUBLIC "${CMAKE_SOURCE_DIR}/src/rgw/store/rados"
3131
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
32-
set(link_targets spawn)
32+
set(link_targets Boost::context)
3333
if(WITH_JAEGER)
3434
list(APPEND link_targets jaeger_base)
3535
endif()

0 commit comments

Comments
 (0)