]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: remove the legacy, non-throwing variant of RGWStreamIO.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Mon, 15 Aug 2016 15:05:48 +0000 (17:05 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Fri, 21 Oct 2016 20:57:21 +0000 (22:57 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_client_io.cc
src/rgw/rgw_client_io.h
src/rgw/rgw_rest.cc

index 964bf770cb0442b346badcb5cd4480557303cf43..0d540bf1bab26d0198dc94e227ad475ccf8be33c 100644 (file)
@@ -23,18 +23,21 @@ void RGWClientIO::init(CephContext *cct) {
 }
 
 
-int RGWStreamIOLegacyWrapper::recv_body(char *buf, std::size_t max, bool calculate_hash)
+int RGWStreamIO::recv_body(char *buf, std::size_t max, bool calculate_hash)
 {
-  const auto len = recv_body(buf, max);
-
-  if (len >= 0 && calculate_hash) {
-    if (!sha256_hash) {
-      sha256_hash = calc_hash_sha256_open_stream();
+  try {
+    const auto sent = recv_body(buf, max);
+
+    if (calculate_hash) {
+      if (! sha256_hash) {
+        sha256_hash = calc_hash_sha256_open_stream();
+      }
+      calc_hash_sha256_update_stream(sha256_hash, buf, sent);
     }
-    calc_hash_sha256_update_stream(sha256_hash, buf, len);
+    return sent;
+  } catch (RGWStreamIOEngine::Exception& e) {
+    return e.value();
   }
-
-  return len;
 }
 
 string RGWStreamIO::grab_aws4_sha256_hash()
index e30d417dfc1bee3a7e8e4b687eb6ae2e5c6b9c6e..68847a3dd46bf3e32744623f5ef798db6d45c599 100644 (file)
@@ -41,6 +41,7 @@ public:
 
 class RGWStreamIOEngine : public RGWClientIO {
   friend class RGWStreamIOLegacyWrapper;
+  template<typename T> friend class RGWDecoratedStreamIO;
 
 public:
   class Exception : public std::exception {
@@ -183,8 +184,8 @@ public:
 
 
 /* HTTP IO: compatibility layer */
-class RGWStreamIO : public RGWClientIO,
-                    public RGWClientIOAccounter {
+class RGWStreamIO : public RGWClientIOAccounter,
+                    public RGWDecoratedStreamIO<RGWStreamIOEngine*> {
 protected:
   bool _account;
   size_t bytes_sent;
@@ -199,28 +200,18 @@ protected:
   RGWEnv env;
 
 public:
-  virtual int send_status(int status, const char *status_name) = 0;
-  virtual int send_100_continue() = 0;
-  virtual std::size_t send_header(const boost::string_ref& name,
-                                  const boost::string_ref& value) noexcept = 0;
-  virtual int send_content_length(uint64_t len) = 0;
-  virtual int send_chunked_transfer_encoding() = 0;
-  virtual int complete_header() = 0;
-
-  virtual int recv_body(char* buf, std::size_t max) = 0;
-  virtual int recv_body(char* buf, std::size_t max, bool calculate_hash) = 0;
-  virtual int send_body(const char* buf, std::size_t len) = 0;
-  virtual void flush() = 0;
-
   virtual ~RGWStreamIO() {}
 
-  RGWStreamIO()
-    : _account(false),
+  RGWStreamIO(RGWStreamIOEngine* engine)
+    : RGWDecoratedStreamIO<RGWStreamIOEngine*>(std::move(engine)),
+      _account(false),
       bytes_sent(0),
       bytes_received(0),
       sha256_hash(nullptr) {
   }
 
+  using RGWDecoratedStreamIO<RGWStreamIOEngine*>::recv_body;
+  virtual int recv_body(char* buf, std::size_t max, bool calculate_hash);
   std::string grab_aws4_sha256_hash();
 
   RGWEnv& get_env() noexcept override {
@@ -246,82 +237,9 @@ public:
  * from RGWDecoratedStreamIO<> to avoid using virtual inheritance in engine.
  * Should be removed after converting all clients. */
 class RGWStreamIOLegacyWrapper : public RGWStreamIO {
-  RGWStreamIOEngine * const engine;
-
-  RGWStreamIOEngine& get_decoratee() {
-    return *engine;
-  }
-
-#define EXCPT_TO_RC(code)                                       \
-  try {                                                         \
-    return code;                                                \
-  } catch (RGWStreamIOEngine::Exception& e) {                   \
-    return e.value();                                           \
-  }
-
-#define EXCPT_TO_VOID(code)                                     \
-  try {                                                         \
-    return code;                                                \
-  } catch (RGWStreamIOEngine::Exception& e) {                   \
-    return;                                                     \
-  }
-
-protected:
-  void init_env(CephContext *cct) override {
-    EXCPT_TO_VOID(get_decoratee().init_env(cct));
-  }
-
 public:
   RGWStreamIOLegacyWrapper(RGWStreamIOEngine * const engine)
-    : engine(engine) {
-  }
-
-  int send_status(const int status, const char* const status_name) override {
-    EXCPT_TO_RC(get_decoratee().send_status(status, status_name));
-  }
-
-  std::size_t send_header(const boost::string_ref& name,
-                          const boost::string_ref& value) noexcept override {
-    EXCPT_TO_RC(get_decoratee().send_header(name, value));
-  }
-
-  int send_100_continue() override {
-    EXCPT_TO_RC(get_decoratee().send_100_continue());
-  }
-
-  int send_content_length(const uint64_t len) override {
-    EXCPT_TO_RC(get_decoratee().send_content_length(len));
-  }
-
-  int send_chunked_transfer_encoding() override {
-    EXCPT_TO_RC(get_decoratee().send_chunked_transfer_encoding());
-  }
-
-  int complete_header() override {
-    EXCPT_TO_RC(get_decoratee().complete_header());
-  }
-
-  int recv_body(char* buf, const std::size_t max) override {
-    EXCPT_TO_RC(get_decoratee().recv_body(buf, max));
-  }
-
-  int recv_body(char* buf, std::size_t max, bool calculate_hash) override;
-
-  int send_body(const char* const buf, const std::size_t len) override {
-    EXCPT_TO_RC(get_decoratee().send_body(buf, len));
-  }
-
-
-  void flush() override {
-    EXCPT_TO_VOID(get_decoratee().flush());
-  }
-
-  RGWEnv& get_env() noexcept override {
-    return get_decoratee().get_env();
-  }
-
-  int complete_request() override {
-    EXCPT_TO_RC(get_decoratee().complete_request());
+    : RGWStreamIO(std::move(engine)) {
   }
 };
 
index 27189e0f5ef79dea972048364fdd9eb1ef34f838..41c158d3e620b0c282769fd34a16d9d053c90b77 100644 (file)
@@ -279,10 +279,11 @@ static void dump_status(struct req_state *s, int status,
                        const char *status_name)
 {
   s->formatter->set_status(status, status_name);
-  int r = STREAM_IO(s)->send_status(status, status_name);
-  if (r < 0) {
-    ldout(s->cct, 0) << "ERROR: s->cio->send_status() returned err=" << r
-                    << dendl;
+  try {
+    STREAM_IO(s)->send_status(status, status_name);
+  } catch (RGWStreamIOEngine::Exception& e) {
+    ldout(s->cct, 0) << "ERROR: s->cio->send_status() returned err="
+                     << e.value() << dendl;
   }
 }
 
@@ -373,10 +374,11 @@ void dump_header(struct req_state* const s,
                  const boost::string_ref& name,
                  const boost::string_ref& val)
 {
-  const int r = STREAM_IO(s)->send_header(name, val);
-  if (r < 0) {
+  try {
+    STREAM_IO(s)->send_header(name, val);
+  } catch (RGWStreamIOEngine::Exception& e) {
     ldout(s->cct, 0) << "ERROR: s->cio->send_header() returned err="
-                     << r << dendl;
+                     << e.value() << dendl;
   }
 }
 
@@ -411,10 +413,11 @@ void dump_header(struct req_state* const s,
 
 void dump_content_length(struct req_state* const s, const uint64_t len)
 {
-  int r = STREAM_IO(s)->send_content_length(len);
-  if (r < 0) {
+  try {
+    STREAM_IO(s)->send_content_length(len);
+  } catch (RGWStreamIOEngine::Exception& e) {
     ldout(s->cct, 0) << "ERROR: s->cio->send_content_length() returned err="
-                     << r << dendl;
+                     << e.value() << dendl;
   }
   dump_header(s, "Accept-Ranges", "bytes");
 }
@@ -702,10 +705,12 @@ void end_header(struct req_state* s, RGWOp* op, const char *content_type,
   if (content_type) {
     dump_header(s, "Content-Type", content_type);
   }
-  int r = STREAM_IO(s)->complete_header();
-  if (r < 0) {
+
+  try {
+    STREAM_IO(s)->complete_header();
+  } catch (RGWStreamIOEngine::Exception& e) {
     ldout(s->cct, 0) << "ERROR: STREAM_IO(s)->complete_header() returned err="
-                    << r << dendl;
+                    << e.value() << dendl;
   }
 
   STREAM_IO(s)->set_account(true);
@@ -789,9 +794,14 @@ void abort_early(struct req_state *s, RGWOp *op, int err_no,
   perfcounter->inc(l_rgw_failed_req);
 }
 
-void dump_continue(struct req_state *s)
+void dump_continue(struct req_state * const s)
 {
-  STREAM_IO(s)->send_100_continue();
+  try {
+    STREAM_IO(s)->send_100_continue();
+  } catch (RGWStreamIOEngine::Exception& e) {
+    ldout(s->cct, 0) << "ERROR: STREAM_IO(s)->send_100_continue() returned err="
+                    << e.value() << dendl;
+  }
 }
 
 void dump_range(struct req_state* const s,
@@ -822,7 +832,11 @@ int dump_body(struct req_state* const s,
               const char* const buf,
               const std::size_t len)
 {
-  return STREAM_IO(s)->send_body(buf, len);
+  try {
+    return STREAM_IO(s)->send_body(buf, len);
+  } catch (RGWStreamIOEngine::Exception& e) {
+    return e.value();
+  }
 }
 
 int dump_body(struct req_state* const s, /* const */ ceph::buffer::list& bl)
@@ -839,7 +853,11 @@ int recv_body(struct req_state* const s,
               char* const buf,
               const std::size_t max)
 {
-  return STREAM_IO(s)->recv_body(buf, max, s->aws4_auth_needs_complete);
+  try {
+    return STREAM_IO(s)->recv_body(buf, max, s->aws4_auth_needs_complete);
+  } catch (RGWStreamIOEngine::Exception& e) {
+    return e.value();
+  }
 }
 
 int RGWGetObj_ObjStore::get_params()