From: Radoslaw Zarzynski Date: Thu, 6 Oct 2016 12:44:36 +0000 (+0200) Subject: rgw: switch to size_t and exception in rgw::io::BasicClient::complete_request. X-Git-Tag: v11.1.0~454^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3e1a90d535c426402de2a5920213aaf5507e5783;p=ceph.git rgw: switch to size_t and exception in rgw::io::BasicClient::complete_request. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/rgw/librgw.cc b/src/rgw/librgw.cc index dfdb853ef262..a31408e7a086 100644 --- a/src/rgw/librgw.cc +++ b/src/rgw/librgw.cc @@ -290,9 +290,11 @@ namespace rgw { op->complete(); done: - int r = io->complete_request(); - if (r < 0) { - dout(0) << "ERROR: io->complete_request() returned " << r << dendl; + try { + io->complete_request(); + } catch (rgw::io::Exception& e) { + dout(0) << "ERROR: io->complete_request() returned " + << e.what() << dendl; } if (should_log) { rgw_log_op(store, s, (op ? op->name() : "unknown"), olog); diff --git a/src/rgw/rgw_asio_client.cc b/src/rgw/rgw_asio_client.cc index b098edf6b26b..aa920ecf96d4 100644 --- a/src/rgw/rgw_asio_client.cc +++ b/src/rgw/rgw_asio_client.cc @@ -85,7 +85,7 @@ size_t RGWAsioClientIO::write_data(const char* const buf, auto bytes = boost::asio::write(socket, boost::asio::buffer(buf, len), ec); if (ec) { derr << "write_data failed: " << ec.message() << dendl; - throw rgw::io::RestfulClient::Exception(ec.value(), std::system_category()); + throw rgw::io::Exception(ec.value(), std::system_category()); } return bytes; } @@ -98,7 +98,7 @@ size_t RGWAsioClientIO::read_data(char* const buf, const size_t max) return bytes; } -int RGWAsioClientIO::complete_request() +size_t RGWAsioClientIO::complete_request() { return 0; } diff --git a/src/rgw/rgw_asio_client.h b/src/rgw/rgw_asio_client.h index 2c106f957f46..c451839d3ab6 100644 --- a/src/rgw/rgw_asio_client.h +++ b/src/rgw/rgw_asio_client.h @@ -46,7 +46,7 @@ class RGWAsioClientIO : public rgw::io::RestfulClient { ~RGWAsioClientIO(); void init_env(CephContext *cct) override; - int complete_request() override; + size_t complete_request() override; void flush() override; size_t send_status(int status, const char *status_name) override; size_t send_100_continue() override; diff --git a/src/rgw/rgw_civetweb.cc b/src/rgw/rgw_civetweb.cc index 2eb74a840066..1873a84a4eba 100644 --- a/src/rgw/rgw_civetweb.cc +++ b/src/rgw/rgw_civetweb.cc @@ -17,9 +17,9 @@ size_t RGWCivetWeb::write_data(const char *buf, size_t len) const int ret = mg_write(conn, buf, len); if (ret == 0) { /* didn't send anything, error out */ - throw rgw::io::RestfulClient::Exception(EIO, std::system_category()); + throw rgw::io::Exception(EIO, std::system_category()); } else if (ret < 0) { - throw rgw::io::RestfulClient::Exception(-ret, std::system_category()); + throw rgw::io::Exception(-ret, std::system_category()); } return ret; } @@ -36,7 +36,7 @@ size_t RGWCivetWeb::read_data(char *buf, size_t len) { const int ret = mg_read(conn, buf, len); if (ret < 0) { - throw rgw::io::RestfulClient::Exception(-ret, std::system_category()); + throw rgw::io::Exception(-ret, std::system_category()); } return ret; } @@ -45,7 +45,7 @@ void RGWCivetWeb::flush() { } -int RGWCivetWeb::complete_request() +size_t RGWCivetWeb::complete_request() { return 0; } @@ -121,9 +121,9 @@ static inline size_t safe_mg_printf(Args&&... args) const int ret = mg_printf(std::forward(args)...); if (ret == 0) { /* didn't send anything, error out */ - throw rgw::io::RestfulClient::Exception(EIO, std::system_category()); + throw rgw::io::Exception(EIO, std::system_category()); } else if (ret < 0) { - throw rgw::io::RestfulClient::Exception(-ret, std::system_category()); + throw rgw::io::Exception(-ret, std::system_category()); } return static_cast(ret); } diff --git a/src/rgw/rgw_civetweb.h b/src/rgw/rgw_civetweb.h index d353a8c152de..f3ec6bb7e148 100644 --- a/src/rgw/rgw_civetweb.h +++ b/src/rgw/rgw_civetweb.h @@ -42,7 +42,7 @@ public: return write_data(buf, len); } - int complete_request() override; + size_t complete_request() override; void flush() override; diff --git a/src/rgw/rgw_client_io.cc b/src/rgw/rgw_client_io.cc index a01a357e1bbe..da501307838c 100644 --- a/src/rgw/rgw_client_io.cc +++ b/src/rgw/rgw_client_io.cc @@ -40,7 +40,7 @@ int RGWRestfulIO::recv_body(char *buf, size_t max, bool calculate_hash) calc_hash_sha256_update_stream(sha256_hash, buf, sent); } return sent; - } catch (rgw::io::RestfulClient::Exception& e) { + } catch (rgw::io::Exception& e) { return -e.code().value(); } } diff --git a/src/rgw/rgw_client_io.h b/src/rgw/rgw_client_io.h index e7cca88268df..de1b09cb5cd8 100644 --- a/src/rgw/rgw_client_io.h +++ b/src/rgw/rgw_client_io.h @@ -19,6 +19,8 @@ namespace rgw { namespace io { +using Exception = std::system_error; + class BasicClient { protected: virtual void init_env(CephContext *cct) = 0; @@ -28,7 +30,7 @@ public: void init(CephContext *cct); virtual RGWEnv& get_env() noexcept = 0; - virtual int complete_request() = 0; + virtual size_t complete_request() = 0; }; /* rgw::io::Client */ @@ -47,8 +49,6 @@ class RestfulClient : public BasicClient { template friend class DecoratedRestfulClient; public: - typedef std::system_error Exception; - virtual size_t send_status(int status, const char *status_name) = 0; virtual size_t send_100_continue() = 0; @@ -170,7 +170,7 @@ public: return get_decoratee().get_env(); } - int complete_request() override { + size_t complete_request() override { return get_decoratee().complete_request(); } }; diff --git a/src/rgw/rgw_client_io_decoimpl.h b/src/rgw/rgw_client_io_decoimpl.h index 5847c5b4c24b..3ffab616b07b 100644 --- a/src/rgw/rgw_client_io_decoimpl.h +++ b/src/rgw/rgw_client_io_decoimpl.h @@ -135,7 +135,7 @@ public: size_t send_chunked_transfer_encoding() override; size_t complete_header() override; size_t send_body(const char* buf, size_t len) override; - int complete_request() override; + size_t complete_request() override; }; template @@ -177,7 +177,7 @@ size_t BufferingFilter::complete_header() } template -int BufferingFilter::complete_request() +size_t BufferingFilter::complete_request() { size_t sent = 0; @@ -251,7 +251,7 @@ public: } } - int complete_request() override { + size_t complete_request() override { size_t sent = 0; if (chunking_enabled) { diff --git a/src/rgw/rgw_fcgi.cc b/src/rgw/rgw_fcgi.cc index 54e842d49f30..173f45390631 100644 --- a/src/rgw/rgw_fcgi.cc +++ b/src/rgw/rgw_fcgi.cc @@ -8,7 +8,7 @@ size_t RGWFCGX::write_data(const char* const buf, const size_t len) { const auto ret = FCGX_PutStr(buf, len, fcgx->out); if (ret < 0) { - throw rgw::io::RestfulClient::Exception(-ret, std::system_category()); + throw rgw::io::Exception(-ret, std::system_category()); } return ret; } @@ -17,7 +17,7 @@ size_t RGWFCGX::read_data(char* const buf, const size_t len) { const auto ret = FCGX_GetStr(buf, len, fcgx->in); if (ret < 0) { - throw rgw::io::RestfulClient::Exception(-ret, std::system_category()); + throw rgw::io::Exception(-ret, std::system_category()); } return ret; } diff --git a/src/rgw/rgw_fcgi.h b/src/rgw/rgw_fcgi.h index 952bb0a8eb21..8562c296f69f 100644 --- a/src/rgw/rgw_fcgi.h +++ b/src/rgw/rgw_fcgi.h @@ -46,7 +46,7 @@ public: return env; } - int complete_request() override { + size_t complete_request() override { return 0; } }; diff --git a/src/rgw/rgw_lib.h b/src/rgw/rgw_lib.h index a730822308b6..2493260d1384 100644 --- a/src/rgw/rgw_lib.h +++ b/src/rgw/rgw_lib.h @@ -81,7 +81,7 @@ namespace rgw { return env; } - int complete_request() override { /* XXX */ + size_t complete_request() override { /* XXX */ return 0; }; diff --git a/src/rgw/rgw_loadgen.cc b/src/rgw/rgw_loadgen.cc index 451df92b2d21..3c61cf21d79e 100644 --- a/src/rgw/rgw_loadgen.cc +++ b/src/rgw/rgw_loadgen.cc @@ -64,7 +64,7 @@ void RGWLoadGenIO::flush() { } -int RGWLoadGenIO::complete_request() +size_t RGWLoadGenIO::complete_request() { return 0; } diff --git a/src/rgw/rgw_loadgen.h b/src/rgw/rgw_loadgen.h index a5faf282309f..dd9e2d8f6afc 100644 --- a/src/rgw/rgw_loadgen.h +++ b/src/rgw/rgw_loadgen.h @@ -69,7 +69,7 @@ public: return env; } - int complete_request() override; + size_t complete_request() override; }; #endif diff --git a/src/rgw/rgw_process.cc b/src/rgw/rgw_process.cc index 3304db6ff1a9..08c8ce01e153 100644 --- a/src/rgw/rgw_process.cc +++ b/src/rgw/rgw_process.cc @@ -197,10 +197,13 @@ int process_request(RGWRados* store, RGWREST* rest, RGWRequest* req, goto done; } done: - int r = client_io->complete_request(); - if (r < 0) { - dout(0) << "ERROR: client_io->complete_request() returned " << r << dendl; + try { + client_io->complete_request(); + } catch (rgw::io::Exception& e) { + dout(0) << "ERROR: client_io->complete_request() returned " + << e.what() << dendl; } + if (should_log) { rgw_log_op(store, s, (op ? op->name() : "unknown"), olog); } diff --git a/src/rgw/rgw_rest.cc b/src/rgw/rgw_rest.cc index dfddc3a29f1b..d22ee87c4f88 100644 --- a/src/rgw/rgw_rest.cc +++ b/src/rgw/rgw_rest.cc @@ -281,7 +281,7 @@ static void dump_status(struct req_state *s, int status, s->formatter->set_status(status, status_name); try { RESTFUL_IO(s)->send_status(status, status_name); - } catch (rgw::io::RestfulClient::Exception& e) { + } catch (rgw::io::Exception& e) { ldout(s->cct, 0) << "ERROR: s->cio->send_status() returned err=" << e.what() << dendl; } @@ -376,7 +376,7 @@ void dump_header(struct req_state* const s, { try { RESTFUL_IO(s)->send_header(name, val); - } catch (rgw::io::RestfulClient::Exception& e) { + } catch (rgw::io::Exception& e) { ldout(s->cct, 0) << "ERROR: s->cio->send_header() returned err=" << e.what() << dendl; } @@ -415,7 +415,7 @@ void dump_content_length(struct req_state* const s, const uint64_t len) { try { RESTFUL_IO(s)->send_content_length(len); - } catch (rgw::io::RestfulClient::Exception& e) { + } catch (rgw::io::Exception& e) { ldout(s->cct, 0) << "ERROR: s->cio->send_content_length() returned err=" << e.what() << dendl; } @@ -426,7 +426,7 @@ static void dump_chunked_encoding(struct req_state* const s) { try { RESTFUL_IO(s)->send_chunked_transfer_encoding(); - } catch (rgw::io::RestfulClient::Exception& e) { + } catch (rgw::io::Exception& e) { ldout(s->cct, 0) << "ERROR: RESTFUL_IO(s)->send_chunked_transfer_encoding()" << " returned err=" << e.what() << dendl; } @@ -708,7 +708,7 @@ void end_header(struct req_state* s, RGWOp* op, const char *content_type, try { RESTFUL_IO(s)->complete_header(); - } catch (rgw::io::RestfulClient::Exception& e) { + } catch (rgw::io::Exception& e) { ldout(s->cct, 0) << "ERROR: RESTFUL_IO(s)->complete_header() returned err=" << e.what() << dendl; } @@ -798,7 +798,7 @@ void dump_continue(struct req_state * const s) { try { RESTFUL_IO(s)->send_100_continue(); - } catch (rgw::io::RestfulClient::Exception& e) { + } catch (rgw::io::Exception& e) { ldout(s->cct, 0) << "ERROR: RESTFUL_IO(s)->send_100_continue() returned err=" << e.what() << dendl; } @@ -834,7 +834,7 @@ int dump_body(struct req_state* const s, { try { return RESTFUL_IO(s)->send_body(buf, len); - } catch (rgw::io::RestfulClient::Exception& e) { + } catch (rgw::io::Exception& e) { return -e.code().value(); } } @@ -855,7 +855,7 @@ int recv_body(struct req_state* const s, { try { return AWS_AUTHv4_IO(s)->recv_body(buf, max, s->aws4_auth_needs_complete); - } catch (rgw::io::RestfulClient::Exception& e) { + } catch (rgw::io::Exception& e) { return -e.code().value(); } }