From 7942c937251329b3be76ab6d23505acca3420bc8 Mon Sep 17 00:00:00 2001 From: Orit Wasserman Date: Mon, 9 Nov 2015 11:59:22 +0100 Subject: [PATCH] rgw: fix compilation with older boost versions that don't have asio coroutines Signed-off-by: Orit Wasserman --- CMakeLists.txt | 1 + configure.ac | 3 ++ src/CMakeLists.txt | 5 ++ src/rgw/Makefile.am | 2 + src/rgw/rgw_boost_asio_coroutine.h | 67 +++++++++++++++++++++++++ src/rgw/rgw_boost_asio_yield.h | 78 ++++++++++++++++++++++++++++++ src/rgw/rgw_coroutine.cc | 2 +- src/rgw/rgw_coroutine.h | 2 + src/rgw/rgw_cr_rados.cc | 4 +- src/rgw/rgw_data_sync.cc | 4 +- src/rgw/rgw_sync.cc | 4 +- 11 files changed, 162 insertions(+), 10 deletions(-) create mode 100644 src/rgw/rgw_boost_asio_coroutine.h create mode 100644 src/rgw/rgw_boost_asio_yield.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 65282030af5e7..413243b68c7e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ CHECK_FUNCTION_EXISTS(mallinfo HAVE_MALLINFO) CHECK_FUNCTION_EXISTS(pwritev HAVE_PWRITEV) CHECK_INCLUDE_FILES("arpa/inet.h" HAVE_ARPA_INET_H) CHECK_INCLUDE_FILES("boost/random/discrete_distribution.hpp" HAVE_BOOST_RANDOM_DISCRETE_DISTRIBUTION) +CHECK_INCLUDE_FILE_CXX("boost/asio/coroutine.hpp" HAVE_BOOST_ASIO_COROUTINE) CHECK_INCLUDE_FILES("dirent.h" HAVE_DIRENT_H) CHECK_INCLUDE_FILES("dlfcn.h" HAVE_DLFCN_H) CHECK_INCLUDE_FILES("inttypes.h" HAVE_INTTYPES_H) diff --git a/configure.ac b/configure.ac index 09d9f64231cc5..62ef1b1f113a4 100644 --- a/configure.ac +++ b/configure.ac @@ -915,6 +915,9 @@ AC_CHECK_HEADER([boost/random/discrete_distribution.hpp], [AC_DEFINE([HAVE_BOOST_RANDOM_DISCRETE_DISTRIBUTION], [], [have boost::random::discrete_distribution])], []) +AC_CHECK_HEADER([boost/asio/coroutine.hpp], + [AC_DEFINE([HAVE_BOOST_ASIO_COROUTINE], [], [have boost::asio::coroutine])], + []) AC_CHECK_HEADER([boost/statechart/state.hpp], [], AC_MSG_FAILURE(["Can't find boost statechart headers; need 1.34 or later"])) AC_CHECK_HEADER([boost/regex.hpp], [], diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 52bfc4a152c18..9e71f43a204f2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1182,6 +1182,10 @@ if(${WITH_RADOSGW}) cls_log_client cls_statelog_client cls_timeindex_client cls_version_client cls_replica_log_client cls_user_client curl global expat) + if(HAVE_BOOST_ASIO_COROUTINE) + target_compile_definitions(rgw_a PUBLIC "HAVE_BOOST_ASIO_COROUTINE") + endif() + set(radosgw_srcs rgw/rgw_resolve.cc rgw/rgw_rest.cc @@ -1232,6 +1236,7 @@ if(${WITH_RADOSGW}) cls_log_client cls_statelog_client cls_timeindex_client cls_version_client cls_replica_log_client cls_user_client curl expat global fcgi resolv ${BLKID_LIBRARIES} ${ALLOC_LIBS}) + install(TARGETS radosgw-admin DESTINATION bin) add_executable(radosgw-object-expirer ${radosgw_object_expirer_srcs} $) diff --git a/src/rgw/Makefile.am b/src/rgw/Makefile.am index 32f34311ba93b..8d7816b491555 100644 --- a/src/rgw/Makefile.am +++ b/src/rgw/Makefile.am @@ -203,6 +203,8 @@ noinst_HEADERS += \ rgw/rgw_keystone.h \ rgw/rgw_realm_watcher.h \ rgw/rgw_civetweb.h \ + rgw/rgw_boost_asio_coroutine.h \ + rgw/rgw_boost_asio_yield.h \ rgw/rgw_civetweb_log.h \ rgw/rgw_website.h \ rgw/rgw_rest_s3website.h \ diff --git a/src/rgw/rgw_boost_asio_coroutine.h b/src/rgw/rgw_boost_asio_coroutine.h new file mode 100644 index 0000000000000..2dd911e489c1a --- /dev/null +++ b/src/rgw/rgw_boost_asio_coroutine.h @@ -0,0 +1,67 @@ +// +// copy of needed class and macors from coroutine.hpp +// +// Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef RGW_BOOST_ASIO_COROUTINE_H +#define RGW_BOOST_ASIO_COROUTINE_H + +#ifndef HAVE_BOOST_ASIO_COROUTINE + +namespace boost { +namespace asio { +namespace detail { + +class coroutine_ref; + +} // namespace detail + +class coroutine +{ +public: + /// Constructs a coroutine in its initial state. + coroutine() : value_(0) {} + + /// Returns true if the coroutine is the child of a fork. + bool is_child() const { return value_ < 0; } + + /// Returns true if the coroutine is the parent of a fork. + bool is_parent() const { return !is_child(); } + + /// Returns true if the coroutine has reached its terminal state. + bool is_complete() const { return value_ == -1; } + +private: + friend class detail::coroutine_ref; + int value_; +}; + + +namespace detail { + +class coroutine_ref +{ +public: + coroutine_ref(coroutine& c) : value_(c.value_), modified_(false) {} + coroutine_ref(coroutine* c) : value_(c->value_), modified_(false) {} + ~coroutine_ref() { if (!modified_) value_ = -1; } + operator int() const { return value_; } + int& operator=(int v) { modified_ = true; return value_ = v; } +private: + void operator=(const coroutine_ref&); + int& value_; + bool modified_; +}; + +} // namespace detail +} // namespace asio +} // namespace boost + +#endif // HAVE_BOOST_ASIO_COROUTINE + +#endif // RGW_BOOST_ASIO_COROUTINE_H + diff --git a/src/rgw/rgw_boost_asio_yield.h b/src/rgw/rgw_boost_asio_yield.h new file mode 100644 index 0000000000000..aeb93215c102a --- /dev/null +++ b/src/rgw/rgw_boost_asio_yield.h @@ -0,0 +1,78 @@ +// +// copy of needed macors from yield.hpp +// +// Copyright (c) 2003-2013 Christopher M. Kohlhoff (chris at kohlhoff dot com) +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef RGW_BOOST_ASIO_YIELD_H +#define RGW_BOOST_ASIO_YIELD_H + +#ifdef HAVE_BOOST_ASIO_COROUTINE +#include +#else +#define BOOST_ASIO_CORO_REENTER(c) \ + switch (::boost::asio::detail::coroutine_ref _coro_value = c) \ + case -1: if (_coro_value) \ + { \ + goto terminate_coroutine; \ + terminate_coroutine: \ + _coro_value = -1; \ + goto bail_out_of_coroutine; \ + bail_out_of_coroutine: \ + break; \ + } \ + else case 0: + +#define BOOST_ASIO_CORO_YIELD_IMPL(n) \ + for (_coro_value = (n);;) \ + if (_coro_value == 0) \ + { \ + case (n): ; \ + break; \ + } \ + else \ + switch (_coro_value ? 0 : 1) \ + for (;;) \ + case -1: if (_coro_value) \ + goto terminate_coroutine; \ + else for (;;) \ + case 1: if (_coro_value) \ + goto bail_out_of_coroutine; \ + else case 0: + +#define BOOST_ASIO_CORO_FORK_IMPL(n) \ + for (_coro_value = -(n);; _coro_value = (n)) \ + if (_coro_value == (n)) \ + { \ + case -(n): ; \ + break; \ + } \ + else + +#if defined(_MSC_VER) +# define BOOST_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD_IMPL(__COUNTER__ + 1) +# define BOOST_ASIO_CORO_FORK BOOST_ASIO_CORO_FORK_IMPL(__COUNTER__ + 1) +#else // defined(_MSC_VER) +# define BOOST_ASIO_CORO_YIELD BOOST_ASIO_CORO_YIELD_IMPL(__LINE__) +# define BOOST_ASIO_CORO_FORK BOOST_ASIO_CORO_FORK_IMPL(__LINE__) +#endif // defined(_MSC_VER) + +#ifndef reenter +# define reenter(c) BOOST_ASIO_CORO_REENTER(c) +#endif + +#ifndef yield +# define yield BOOST_ASIO_CORO_YIELD +#endif + +#ifndef fork +# define fork BOOST_ASIO_CORO_FORK +#endif + +#endif // HAVE_BOOST_ASIO_COROUTINE + +#endif // RGW_BOOST_ASIO_YIELD_H + diff --git a/src/rgw/rgw_coroutine.cc b/src/rgw/rgw_coroutine.cc index 1459524a12cab..eaac0ef13845d 100644 --- a/src/rgw/rgw_coroutine.cc +++ b/src/rgw/rgw_coroutine.cc @@ -1,8 +1,8 @@ #include "rgw_coroutine.h" +#include "rgw_boost_asio_yield.h" -#include #define dout_subsys ceph_subsys_rgw diff --git a/src/rgw/rgw_coroutine.h b/src/rgw/rgw_coroutine.h index 2c90629aafb70..24d38cc0050cc 100644 --- a/src/rgw/rgw_coroutine.h +++ b/src/rgw/rgw_coroutine.h @@ -18,6 +18,7 @@ #include "common/Timer.h" #include "rgw_common.h" +#include "rgw_boost_asio_coroutine.h" #define RGW_ASYNC_OPS_MGR_WINDOW 100 @@ -125,6 +126,7 @@ struct rgw_spawned_stacks { }; + class RGWCoroutine : public RefCountedObject, public boost::asio::coroutine { friend class RGWCoroutinesStack; diff --git a/src/rgw/rgw_cr_rados.cc b/src/rgw/rgw_cr_rados.cc index 030829fc511ea..9ffefdac5e59d 100644 --- a/src/rgw/rgw_cr_rados.cc +++ b/src/rgw/rgw_cr_rados.cc @@ -1,12 +1,10 @@ #include "rgw_rados.h" #include "rgw_coroutine.h" +#include "rgw_boost_asio_yield.h" #include "rgw_cr_rados.h" #include "cls/lock/cls_lock_client.h" -#include - - #define dout_subsys ceph_subsys_rgw bool RGWAsyncRadosProcessor::RGWWQ::_enqueue(RGWAsyncRadosRequest *req) { diff --git a/src/rgw/rgw_data_sync.cc b/src/rgw/rgw_data_sync.cc index c23845d57a09d..f5fa262aced9b 100644 --- a/src/rgw/rgw_data_sync.cc +++ b/src/rgw/rgw_data_sync.cc @@ -14,12 +14,10 @@ #include "rgw_http_client.h" #include "rgw_bucket.h" #include "rgw_metadata.h" +#include "rgw_boost_asio_yield.h" #include "cls/lock/cls_lock_client.h" -#include - - #define dout_subsys ceph_subsys_rgw static string datalog_sync_status_oid_prefix = "datalog.sync-status"; diff --git a/src/rgw/rgw_sync.cc b/src/rgw/rgw_sync.cc index 71504e78a894d..49ddd98b893a2 100644 --- a/src/rgw/rgw_sync.cc +++ b/src/rgw/rgw_sync.cc @@ -13,12 +13,10 @@ #include "rgw_cr_rados.h" #include "rgw_cr_rest.h" #include "rgw_http_client.h" +#include "rgw_boost_asio_yield.h" #include "cls/lock/cls_lock_client.h" -#include - - #define dout_subsys ceph_subsys_rgw static string mdlog_sync_status_oid = "mdlog.sync-status"; -- 2.39.5