]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: extend RGWRestfulIO to cover dynamic filter injection.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Sun, 23 Apr 2017 02:33:38 +0000 (04:33 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Wed, 7 Jun 2017 10:43:18 +0000 (12:43 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_client_io.h

index af8dffa9ec9473d2f5e03f11f339b514cb92b5cb..305fb5013a3a4b482c9082fcd6c163f1972294da 100644 (file)
@@ -16,6 +16,9 @@
 #include "include/types.h"
 #include "rgw_common.h"
 
+
+class RGWRestfulIO;
+
 namespace rgw {
 namespace io {
 
@@ -155,6 +158,7 @@ public:
 template <typename DecorateeT>
 class DecoratedRestfulClient : public RestfulClient {
   template<typename T> friend class DecoratedRestfulClient;
+  friend RGWRestfulIO;
 
   typedef typename std::remove_pointer<DecorateeT>::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 <typename T = void,
+            typename std::enable_if<
+    ! std::is_pointer<DecorateeT>::value, T>::type* = nullptr>
+  DerefedDecorateeT& get_decoratee() {
+    return decoratee;
+  }
+
+protected:
   template <typename T = void,
             typename std::enable_if<
     std::is_pointer<DecorateeT>::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 <typename T = void,
             typename std::enable_if<
-    std::is_pointer<DecorateeT>::value, T>::type* = nullptr>
-  DerefedDecorateeT& get_decoratee() {
-    return decoratee;
+    std::is_pointer<DecorateeT>::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<rgw::io::RestfulClient*> {
   SHA256 *sha256_hash;
+  std::vector<std::shared_ptr<DecoratedRestfulClient>> filters;
 
 public:
   ~RGWRestfulIO() override {}
@@ -332,6 +348,12 @@ public:
   using DecoratedRestfulClient<RestfulClient*>::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<DecoratedRestfulClient> new_filter) {
+    new_filter->set_decoratee(this->get_decoratee());
+    this->set_decoratee(*new_filter);
+    filters.emplace_back(std::move(new_filter));
+  }
 }; /* RGWRestfulIO */