]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osdc: Add error codes for Objecter error returns
authorAdam C. Emerson <aemerson@redhat.com>
Fri, 10 May 2019 20:59:36 +0000 (16:59 -0400)
committerAdam C. Emerson <aemerson@redhat.com>
Fri, 15 May 2020 14:55:10 +0000 (10:55 -0400)
For errors generated /within/ the Objecter, not those returned from
the OSD.

Signed-off-by: Adam C. Emerson <aemerson@redhat.com>
src/CMakeLists.txt
src/osdc/CMakeLists.txt
src/osdc/error_code.cc [new file with mode: 0644]
src/osdc/error_code.h [new file with mode: 0644]

index 5dbe424b504a000dc6890db3a8e8849c494ab439..47ff4a5dcd708b4a108ea1c863fc6b3ccad2a1b3 100644 (file)
@@ -343,6 +343,7 @@ set(libcommon_files
   osd/osd_op_util.cc
   osdc/Striper.cc
   osdc/Objecter.cc
+  osdc/error_code.cc
   librbd/Features.cc
   ${mds_files})
 set_source_files_properties(ceph_ver.c
index 6dd97b39362377ef6d0b586698522c70c9c96ccf..551b105f893fb280c7bcbdccc3eb82f476ad19d7 100644 (file)
@@ -2,6 +2,7 @@ set(osdc_files
   Filer.cc
   ObjectCacher.cc
   Objecter.cc
+  error_code.cc
   Striper.cc)
 add_library(osdc STATIC ${osdc_files})
 if(WITH_EVENTTRACE)
diff --git a/src/osdc/error_code.cc b/src/osdc/error_code.cc
new file mode 100644 (file)
index 0000000..5dc5483
--- /dev/null
@@ -0,0 +1,159 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2019 Red Hat <contact@redhat.com>
+ * Author: Adam C. Emerson <aemerson@redhat.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#include <string>
+
+#include "common/error_code.h"
+#include "error_code.h"
+
+namespace bs = boost::system;
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
+class osdc_error_category : public ceph::converting_category {
+public:
+  osdc_error_category(){}
+  const char* name() const noexcept override;
+  const char* message(int ev, char*, std::size_t) const noexcept override;
+  std::string message(int ev) const override;
+  bs::error_condition default_error_condition(int ev) const noexcept
+    override;
+  bool equivalent(int ev, const bs::error_condition& c) const
+    noexcept override;
+  using ceph::converting_category::equivalent;
+  int from_code(int ev) const noexcept override;
+};
+#pragma GCC diagnostic pop
+#pragma clang diagnostic pop
+
+const char* osdc_error_category::name() const noexcept {
+  return "osdc";
+}
+
+const char* osdc_error_category::message(int ev, char*,
+                                        std::size_t) const noexcept {
+  if (ev == 0)
+    return "No error";
+
+  switch (static_cast<osdc_errc>(ev)) {
+  case osdc_errc::pool_dne:
+    return "Pool does not exist";
+
+  case osdc_errc::pool_exists:
+    return "Pool already exists";
+
+  case osdc_errc::precondition_violated:
+    return "Precondition for operation not satisfied";
+
+  case osdc_errc::not_supported:
+    return "Operation not supported";
+
+  case osdc_errc::snapshot_exists:
+    return "Snapshot already exists";
+
+  case osdc_errc::snapshot_dne:
+    return "Snapshot does not exist";
+
+  case osdc_errc::timed_out:
+    return "Operation timed out";
+  }
+
+  return "Unknown error";
+}
+
+std::string osdc_error_category::message(int ev) const {
+  return message(ev, nullptr, 0);
+}
+
+bs::error_condition
+osdc_error_category::default_error_condition(int ev) const noexcept {
+  switch (static_cast<osdc_errc>(ev)) {
+  case osdc_errc::pool_dne:
+    return ceph::errc::does_not_exist;
+  case osdc_errc::pool_exists:
+    return ceph::errc::exists;
+  case osdc_errc::precondition_violated:
+    return bs::errc::invalid_argument;
+  case osdc_errc::not_supported:
+    return bs::errc::operation_not_supported;
+  case osdc_errc::snapshot_exists:
+    return ceph::errc::exists;
+  case osdc_errc::snapshot_dne:
+    return ceph::errc::does_not_exist;
+  case osdc_errc::timed_out:
+    return bs::errc::timed_out;
+  }
+
+  return { ev, *this };
+}
+
+bool osdc_error_category::equivalent(int ev,
+                                     const bs::error_condition& c) const noexcept {
+  if (static_cast<osdc_errc>(ev) == osdc_errc::pool_dne) {
+    if (c == bs::errc::no_such_file_or_directory) {
+      return true;
+    }
+    if (c == ceph::errc::not_in_map) {
+      return true;
+    }
+  }
+  if (static_cast<osdc_errc>(ev) == osdc_errc::pool_exists) {
+    if (c == bs::errc::file_exists) {
+      return true;
+    }
+  }
+  if (static_cast<osdc_errc>(ev) == osdc_errc::snapshot_exists) {
+    if (c == bs::errc::file_exists) {
+      return true;
+    }
+  }
+  if (static_cast<osdc_errc>(ev) == osdc_errc::snapshot_dne) {
+    if (c == bs::errc::no_such_file_or_directory) {
+      return true;
+    }
+    if (c == ceph::errc::not_in_map) {
+      return true;
+    }
+  }
+
+  return default_error_condition(ev) == c;
+}
+
+int osdc_error_category::from_code(int ev) const noexcept {
+  switch (static_cast<osdc_errc>(ev)) {
+  case osdc_errc::pool_dne:
+    return -ENOENT;
+  case osdc_errc::pool_exists:
+    return -EEXIST;
+  case osdc_errc::precondition_violated:
+    return -EINVAL;
+  case osdc_errc::not_supported:
+    return -EOPNOTSUPP;
+  case osdc_errc::snapshot_exists:
+    return -EEXIST;
+  case osdc_errc::snapshot_dne:
+    return -ENOENT;
+  case osdc_errc::timed_out:
+    return -ETIMEDOUT;
+  }
+  return -EDOM;
+}
+
+const bs::error_category& osdc_category() noexcept {
+  static const osdc_error_category c;
+  return c;
+}
diff --git a/src/osdc/error_code.h b/src/osdc/error_code.h
new file mode 100644 (file)
index 0000000..53c9e3c
--- /dev/null
@@ -0,0 +1,55 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2019 Red Hat <contact@redhat.com>
+ * Author: Adam C. Emerson <aemerson@redhat.com>
+ *
+ * This is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1, as published by the Free Software
+ * Foundation.  See file COPYING.
+ *
+ */
+
+#pragma once
+
+#include <boost/system/error_code.hpp>
+
+#include "include/rados.h"
+
+const boost::system::error_category& osdc_category() noexcept;
+
+enum class osdc_errc {
+  pool_dne = 1,
+  pool_exists,
+  // Come the revolution, we'll just kill your program. Maybe.
+  precondition_violated,
+  not_supported,
+  snapshot_exists,
+  snapshot_dne,
+  timed_out
+};
+
+namespace boost::system {
+template<>
+struct is_error_code_enum<::osdc_errc> {
+  static const bool value = true;
+};
+
+template<>
+struct is_error_condition_enum<::osdc_errc> {
+  static const bool value = false;
+};
+}
+
+//  implicit conversion:
+inline boost::system::error_code make_error_code(osdc_errc e) noexcept {
+  return { static_cast<int>(e), osdc_category() };
+}
+
+// explicit conversion:
+inline boost::system::error_condition make_error_condition(osdc_errc e) noexcept {
+  return { static_cast<int>(e), osdc_category() };
+}