From: Radoslaw Zarzynski Date: Sun, 23 Apr 2017 02:33:38 +0000 (+0200) Subject: rgw: extend RGWRestfulIO to cover dynamic filter injection. X-Git-Tag: v12.1.0~155^2~31 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=139de6a0bd64ecbd34477f4b85195ce26971cc01;p=ceph.git rgw: extend RGWRestfulIO to cover dynamic filter injection. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/rgw/rgw_client_io.h b/src/rgw/rgw_client_io.h index af8dffa9ec94..305fb5013a3a 100644 --- a/src/rgw/rgw_client_io.h +++ b/src/rgw/rgw_client_io.h @@ -16,6 +16,9 @@ #include "include/types.h" #include "rgw_common.h" + +class RGWRestfulIO; + namespace rgw { namespace io { @@ -155,6 +158,7 @@ public: template class DecoratedRestfulClient : public RestfulClient { template friend class DecoratedRestfulClient; + friend RGWRestfulIO; typedef typename std::remove_pointer::type DerefedDecorateeT; @@ -167,6 +171,14 @@ class DecoratedRestfulClient : public RestfulClient { * code base between dynamic and static decorators. The difference is about * what we store internally: pointer to a decorated object versus the whole * object itself. */ + template ::value, T>::type* = nullptr> + DerefedDecorateeT& get_decoratee() { + return decoratee; + } + +protected: template ::value, T>::type* = nullptr> @@ -174,14 +186,17 @@ class DecoratedRestfulClient : public RestfulClient { return *decoratee; } + /* Dynamic decorators (those storing a pointer instead of the decorated + * object itself) can be reconfigured on-the-fly. HOWEVER: there are no + * facilities for orchestrating such changes. Callers must take care of + * atomicity and thread-safety. */ template ::value, T>::type* = nullptr> - DerefedDecorateeT& get_decoratee() { - return decoratee; + std::is_pointer::value, T>::type* = nullptr> + void set_decoratee(DerefedDecorateeT& new_dec) { + decoratee = &new_dec; } -protected: void init_env(CephContext *cct) override { return get_decoratee().init_env(cct); } @@ -274,7 +289,7 @@ class StaticOutputBufferer : public std::streambuf { if (! sync()) { /* No error, the buffer has been successfully synchronized. */ return c; - } else { + } else { return std::streambuf::traits_type::eof(); } } @@ -320,6 +335,7 @@ public: * rgw::io::Accounter came in as a part of rgw::io::AccountingFilter. */ class RGWRestfulIO : public rgw::io::AccountingFilter { SHA256 *sha256_hash; + std::vector> filters; public: ~RGWRestfulIO() override {} @@ -332,6 +348,12 @@ public: using DecoratedRestfulClient::recv_body; virtual int recv_body(char* buf, size_t max, bool calculate_hash); std::string grab_aws4_sha256_hash(); + + void add_filter(std::shared_ptr new_filter) { + new_filter->set_decoratee(this->get_decoratee()); + this->set_decoratee(*new_filter); + filters.emplace_back(std::move(new_filter)); + } }; /* RGWRestfulIO */