]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson: use std::error_code instances for errors.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 20 Sep 2019 11:33:08 +0000 (13:33 +0200)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Wed, 20 Nov 2019 19:37:42 +0000 (20:37 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/crimson/common/errorator.h
src/crimson/osd/exceptions.h
src/crimson/osd/ops_executer.cc
src/crimson/osd/ops_executer.h

index 0df8b8b8d533574952324d4f3380cd256a651b56..927aa20cf6219050a3cbb61b73d5fc62c258c986 100644 (file)
@@ -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 ConcreteErrorT>
 class error_t {
@@ -590,17 +578,29 @@ public:
   using futurize = ::seastar::futurize<T>;
 }; // 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 <std::errc ErrorV>
+inline std::error_code ec = std::make_error_code(ErrorV);
+
+template <std::errc ErrorV>
+using ct_error_code = unthrowable_wrapper<const std::error_code&, ec<ErrorV>>;
+
 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<std::errc::no_such_file_or_directory>;
+  using enodata = ct_error_code<std::errc::no_message_available>;
+  using invarg =  ct_error_code<std::errc::invalid_argument>;
+  using input_output_error = ct_error_code<std::errc::io_error>;
+  using object_corrupted = ct_error_code<std::errc::illegal_byte_sequence>;
+  using permission_denied = ct_error_code<std::errc::permission_denied>;
+  using operation_not_supported =
+    ct_error_code<std::errc::operation_not_supported>;
 }
 
 using stateful_errc = stateful_error_t<std::errc>;
 using stateful_errint = stateful_error_t<int>;
+using stateful_ec = stateful_error_t<std::error_code>;
 
 } // namespace crimson
index 38dce4e5e8d3f1f0c7a7673c6e86a238e5ac0f3e..d1b52333850da18f98d6aacb35d5ab0ed999dc91 100644 (file)
@@ -25,7 +25,7 @@ private:
 };
 
 inline error make_error(const int ret) {
-  return error{-ret};
+  return error{ret};
 }
 
 struct object_not_found : public error {
index 6db62ecf38d633815480887e873d8669240fc334..28006cde05da253fe4eb09dd091cc6a047208dda 100644 (file)
@@ -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<crimson::ct_error::enoent,
-                         crimson::ct_error::input_output_error,
-                         crimson::ct_error::operation_not_supported,
-                         crimson::ct_error::permission_denied,
-                         crimson::ct_error::invarg>::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) {
index ad56e69a81bd2ee81382e7da5cef48ea731de915..483e1c39a96ca46fc5a8257092e09208ce738dab 100644 (file)
@@ -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,