From: Radoslaw Zarzynski Date: Fri, 20 Sep 2019 11:33:08 +0000 (+0200) Subject: crimson: use std::error_code instances for errors. X-Git-Tag: v15.1.0~801^2~22 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=cc49a9e82f60f16a054b00f1ca8d91d94f65fa9e;p=ceph-ci.git crimson: use std::error_code instances for errors. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/crimson/common/errorator.h b/src/crimson/common/errorator.h index 0df8b8b8d53..927aa20cf62 100644 --- a/src/crimson/common/errorator.h +++ b/src/crimson/common/errorator.h @@ -7,18 +7,6 @@ namespace crimson { -namespace _impl { - enum class ct_error { - enoent, - invarg, - enodata, - input_output_error, - object_corrupted, - permission_denied, - operation_not_supported - }; -} - // define the interface between error types and errorator template class error_t { @@ -590,17 +578,29 @@ public: using futurize = ::seastar::futurize; }; // class errorator, <> specialization + +// this is conjunction of two nasty features: C++14's variable template +// and inline global variable of C++17. The latter is crucial to ensure +// the variable will get the same address across all translation units. +template +inline std::error_code ec = std::make_error_code(ErrorV); + +template +using ct_error_code = unthrowable_wrapper>; + namespace ct_error { - using enoent = unthrowable_wrapper<_impl::ct_error, _impl::ct_error::enoent>; - using enodata = unthrowable_wrapper<_impl::ct_error, _impl::ct_error::enodata>; - using invarg = unthrowable_wrapper<_impl::ct_error, _impl::ct_error::invarg>; - using input_output_error = unthrowable_wrapper<_impl::ct_error, _impl::ct_error::input_output_error>; - using object_corrupted = unthrowable_wrapper<_impl::ct_error, _impl::ct_error::object_corrupted>; - using permission_denied = unthrowable_wrapper<_impl::ct_error, _impl::ct_error::permission_denied>; - using operation_not_supported = unthrowable_wrapper<_impl::ct_error, _impl::ct_error::operation_not_supported>; + using enoent = ct_error_code; + using enodata = ct_error_code; + using invarg = ct_error_code; + using input_output_error = ct_error_code; + using object_corrupted = ct_error_code; + using permission_denied = ct_error_code; + using operation_not_supported = + ct_error_code; } using stateful_errc = stateful_error_t; using stateful_errint = stateful_error_t; +using stateful_ec = stateful_error_t; } // namespace crimson diff --git a/src/crimson/osd/exceptions.h b/src/crimson/osd/exceptions.h index 38dce4e5e8d..d1b52333850 100644 --- a/src/crimson/osd/exceptions.h +++ b/src/crimson/osd/exceptions.h @@ -25,7 +25,7 @@ private: }; inline error make_error(const int ret) { - return error{-ret}; + return error{ret}; } struct object_not_found : public error { diff --git a/src/crimson/osd/ops_executer.cc b/src/crimson/osd/ops_executer.cc index 6db62ecf38d..28006cde05d 100644 --- a/src/crimson/osd/ops_executer.cc +++ b/src/crimson/osd/ops_executer.cc @@ -106,7 +106,11 @@ OpsExecuter::call_errorator::future<> OpsExecuter::do_op_call(OSDOp& osd_op) } if (ret < 0) { return call_errorator::make_plain_exception_future<>( +<<<<<<< HEAD crimson::stateful_errint{ ret }); +======= + ceph::stateful_ec{ std::error_code(-ret, std::generic_category()) }); +>>>>>>> 520100f... crimson: use std::error_code instances for errors. } return seastar::now(); } @@ -421,17 +425,10 @@ OpsExecuter::execute_osd_op(OSDOp& osd_op) return this->do_op_call(osd_op).safe_then( [] { return seastar::now(); - }, ceph::stateful_errint::handle([] (int err) { - // TODO: implement the handler. NOP for now. - }), crimson::ct_error::input_output_error::handle([] { - // TODO: implement the handler. NOP for now. - }), - crimson::errorator::discard_all{} - ); + }, call_errorator::all_same_way([] (const std::error_code& err) { + assert(err.value() > 0); + throw crimson::osd::make_error(err.value()); + })); case CEPH_OSD_OP_STAT: // note: stat does not require RD return do_const_op([&osd_op] (/* const */auto& backend, const auto& os) { diff --git a/src/crimson/osd/ops_executer.h b/src/crimson/osd/ops_executer.h index ad56e69a81b..483e1c39a96 100644 --- a/src/crimson/osd/ops_executer.h +++ b/src/crimson/osd/ops_executer.h @@ -66,7 +66,7 @@ class OpsExecuter { auto with_effect(Context&& ctx, MainFunc&& main_func, EffectFunc&& effect_func); using call_errorator = crimson::errorator< - crimson::stateful_errint, + crimson::stateful_ec, crimson::ct_error::enoent, crimson::ct_error::invarg, crimson::ct_error::permission_denied,