From: Casey Bodley Date: Thu, 30 Nov 2017 23:40:06 +0000 (-0500) Subject: rgw: add rgw_rados_operate() to wrap optionally-async operate X-Git-Tag: v14.1.0~759^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=42921b98d1701c15b0926f8de3f4476f19ae8954;p=ceph.git rgw: add rgw_rados_operate() to wrap optionally-async operate calls IoCtx::operate() when given an empty optional_yield, or librados::async_operate() when non-empty. calling async_operate() with a yield_context behaves just like a synchronous call to IoCtx::operate(), except that the stackful coroutine is suspended and resumed on completion instead of blocking the calling thread Signed-off-by: Casey Bodley --- diff --git a/src/rgw/rgw_tools.cc b/src/rgw/rgw_tools.cc index b3e895328709..66829d98fc97 100644 --- a/src/rgw/rgw_tools.cc +++ b/src/rgw/rgw_tools.cc @@ -5,6 +5,8 @@ #include "common/errno.h" #include "common/safe_io.h" +#include "librados/librados_asio.h" +#include "common/async/yield_context.h" #include "include/types.h" @@ -15,6 +17,7 @@ #include "services/svc_sys_obj.h" #define dout_subsys ceph_subsys_rgw +#define dout_context g_ceph_context #define READ_CHUNK_LEN (512 * 1024) @@ -116,6 +119,42 @@ int rgw_delete_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string .remove(); } +int rgw_rados_operate(librados::IoCtx& ioctx, const std::string& oid, + librados::ObjectReadOperation *op, bufferlist* pbl, + optional_yield y) +{ +#ifdef HAVE_BOOST_CONTEXT + // given a yield_context, call async_operate() to yield the coroutine instead + // of blocking + if (y) { + auto& context = y.get_io_context(); + auto& yield = y.get_yield_context(); + boost::system::error_code ec; + auto bl = librados::async_operate(context, ioctx, oid, op, 0, yield[ec]); + if (pbl) { + *pbl = std::move(bl); + } + return -ec.value(); + } +#endif + return ioctx.operate(oid, op, nullptr); +} + +int rgw_rados_operate(librados::IoCtx& ioctx, const std::string& oid, + librados::ObjectWriteOperation *op, optional_yield y) +{ +#ifdef HAVE_BOOST_CONTEXT + if (y) { + auto& context = y.get_io_context(); + auto& yield = y.get_yield_context(); + boost::system::error_code ec; + librados::async_operate(context, ioctx, oid, op, 0, yield[ec]); + return -ec.value(); + } +#endif + return ioctx.operate(oid, op); +} + void parse_mime_map_line(const char *start, const char *end) { char line[end - start + 1]; diff --git a/src/rgw/rgw_tools.h b/src/rgw/rgw_tools.h index 38e85f651b95..be37634205f8 100644 --- a/src/rgw/rgw_tools.h +++ b/src/rgw/rgw_tools.h @@ -13,6 +13,7 @@ class RGWRados; class RGWSysObjectCtx; struct RGWObjVersionTracker; +class optional_yield; struct obj_version; @@ -30,6 +31,13 @@ const char *rgw_find_mime_by_ext(string& ext); void rgw_filter_attrset(map& unfiltered_attrset, const string& check_prefix, map *attrset); +/// perform the rados operation, using the yield context when given +int rgw_rados_operate(librados::IoCtx& ioctx, const std::string& oid, + librados::ObjectReadOperation *op, bufferlist* pbl, + optional_yield y); +int rgw_rados_operate(librados::IoCtx& ioctx, const std::string& oid, + librados::ObjectWriteOperation *op, optional_yield y); + int rgw_tools_init(CephContext *cct); void rgw_tools_cleanup();