From 2407f576ef6b48285972243a84b247292badd2c1 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Wed, 31 Jul 2019 19:38:30 +0200 Subject: [PATCH] crimson/osd: exceptions derive from std::system_error now. This change is be useful especially for CEPH_OSD_OP_CALL which will be brought by further commits. The issue here is that the Ceph Classes will be based on existing iface handling errors with usual, int-based ret codes. These codes needs to be glued with the existing handling in pg::do_osd_ops(). Signed-off-by: Radoslaw Zarzynski --- src/crimson/osd/exceptions.h | 27 ++++++++++++++++++++++++--- src/crimson/osd/pg.cc | 9 +++++---- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/crimson/osd/exceptions.h b/src/crimson/osd/exceptions.h index 7437ae4b887..06063c41582 100644 --- a/src/crimson/osd/exceptions.h +++ b/src/crimson/osd/exceptions.h @@ -4,12 +4,33 @@ #pragma once #include +#include -class object_not_found : public std::exception { +class crimson_error : private std::system_error { +public: + crimson_error(const std::errc ec) + : system_error(std::make_error_code(ec)) { + } + + using system_error::code; + using system_error::what; + +private: + crimson_error(const int ret) noexcept + : system_error(ret, std::system_category()) { + } +}; + + +struct object_not_found : public crimson_error { + object_not_found() : crimson_error(std::errc::no_such_file_or_directory) {} }; -class object_corrupted : public std::exception { +struct object_corrupted : public crimson_error { + object_corrupted() : crimson_error(std::errc::illegal_byte_sequence) {} }; -class invalid_argument : public std::exception { +struct invalid_argument : public crimson_error { + invalid_argument() : crimson_error(std::errc::invalid_argument) {} }; + diff --git a/src/crimson/osd/pg.cc b/src/crimson/osd/pg.cc index d224555685d..b87ffae86f4 100644 --- a/src/crimson/osd/pg.cc +++ b/src/crimson/osd/pg.cc @@ -463,12 +463,13 @@ seastar::future> PG::do_osd_ops(Ref m) 0, false); reply->add_flags(CEPH_OSD_FLAG_ACK | CEPH_OSD_FLAG_ONDISK); return seastar::make_ready_future>(std::move(reply)); - }).handle_exception_type([=](const object_not_found& dne) { - logger().debug("got object_not_found for {}", oid); + }).handle_exception_type([=](const crimson_error& ce) { + logger().debug("got crimson_error while handling object {}: {} ({})", + oid, ce.code(), ce.what()); backend->evict_object_state(oid); - auto reply = make_message(m.get(), -ENOENT, get_osdmap_epoch(), - 0, false); + auto reply = make_message( + m.get(), -ce.code().value(), get_osdmap_epoch(), 0, false); reply->set_enoent_reply_versions(peering_state.get_info().last_update, peering_state.get_info().last_user_version); return seastar::make_ready_future>(std::move(reply)); -- 2.39.5