]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/scrub_types.h: add formatters for several scrub types
authorSamuel Just <sjust@redhat.com>
Tue, 19 Sep 2023 23:09:15 +0000 (23:09 +0000)
committerSamuel Just <sjust@redhat.com>
Mon, 11 Dec 2023 04:10:17 +0000 (04:10 +0000)
Signed-off-by: Samuel Just <sjust@redhat.com>
src/common/scrub_types.h

index 0394eddd7e6b12c4095b8f100cf74a60942db828..150ba87af8afe24d29c3fd33e46c0957f9296985 100644 (file)
@@ -4,6 +4,8 @@
 #ifndef CEPH_SCRUB_TYPES_H
 #define CEPH_SCRUB_TYPES_H
 
+#include <fmt/ranges.h>
+
 #include "osd/osd_types.h"
 
 // wrappers around scrub types to offer the necessary bits other than
@@ -207,4 +209,197 @@ struct scrub_ls_result_t {
 
 WRITE_CLASS_ENCODER(scrub_ls_result_t);
 
+template <>
+struct fmt::formatter<librados::object_id_t> {
+  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
+
+  template <typename FormatContext>
+  auto format(const auto &oid, FormatContext& ctx) const
+  {
+    return format_to(ctx.out(), "{}/{}/{}", oid.locator, oid.nspace, oid.name);
+  }
+};
+
+template <>
+struct fmt::formatter<librados::err_t> {
+  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
+
+  template <typename FormatContext>
+  auto format(const auto &err, FormatContext& ctx) const
+  {
+    bool first = true;
+#define F(FLAG_NAME)                                   \
+    if (err.errors & librados::err_t::FLAG_NAME) {     \
+      if (!first) {                                    \
+       fmt::format_to(ctx.out(), "|");                 \
+      } else {                                         \
+       first = false;                                  \
+      }                                                        \
+      fmt::format_to(ctx.out(), #FLAG_NAME);           \
+    }
+    F(SHARD_MISSING);
+    F(SHARD_STAT_ERR);
+    F(SHARD_READ_ERR);
+    F(DATA_DIGEST_MISMATCH_INFO);
+    F(OMAP_DIGEST_MISMATCH_INFO);
+    F(SIZE_MISMATCH_INFO);
+    F(SHARD_EC_HASH_MISMATCH);
+    F(SHARD_EC_SIZE_MISMATCH);
+    F(INFO_MISSING);
+    F(INFO_CORRUPTED);
+    F(SNAPSET_MISSING);
+    F(SNAPSET_CORRUPTED);
+    F(OBJ_SIZE_INFO_MISMATCH);
+    F(HINFO_MISSING);
+    F(HINFO_CORRUPTED);
+#undef F
+    return ctx.out();
+  }
+};
+
+template <>
+struct fmt::formatter<librados::shard_info_t> {
+  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
+
+  template <typename FormatContext>
+  auto format(const auto &err, FormatContext& ctx) const
+  {
+    return fmt::format_to(
+      ctx.out(),
+      "shard_info_t(error: {}, "
+      "size: {}, "
+      "omap_digest_present: {}, "
+      "omap_digest: {}, "
+      "data_digest_present: {}, "
+      "data_digest: {}, "
+      "selected_io: {}, "
+      "primary: {})",
+      static_cast<librados::err_t>(err),
+      err.size,
+      err.omap_digest_present,
+      err.omap_digest,
+      err.data_digest_present,
+      err.data_digest,
+      err.selected_oi,
+      err.primary);
+  }
+};
+
+template <>
+struct fmt::formatter<shard_info_wrapper> :
+  fmt::formatter<librados::shard_info_t> {};
+
+template <>
+struct fmt::formatter<librados::obj_err_t> {
+  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
+
+  template <typename FormatContext>
+  auto format(const auto &err, FormatContext& ctx) const
+  {
+    bool first = true;
+#define F(FLAG_NAME)                                   \
+    if (err.errors & librados::obj_err_t::FLAG_NAME) { \
+      if (!first) {                                    \
+       fmt::format_to(ctx.out(), "|");                 \
+      } else {                                         \
+       first = false;                                  \
+      }                                                        \
+      fmt::format_to(ctx.out(), #FLAG_NAME);           \
+    }
+    F(OBJECT_INFO_INCONSISTENCY);
+    F(DATA_DIGEST_MISMATCH);
+    F(OMAP_DIGEST_MISMATCH);
+    F(SIZE_MISMATCH);
+    F(ATTR_VALUE_MISMATCH);
+    F(ATTR_NAME_MISMATCH);
+    F(SNAPSET_INCONSISTENCY);
+    F(HINFO_INCONSISTENCY);
+    F(SIZE_TOO_LARGE);
+#undef F
+    return ctx.out();
+  }
+};
+
+template <>
+struct fmt::formatter<librados::osd_shard_t> {
+  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
+
+  template <typename FormatContext>
+  auto format(const auto &shard, FormatContext& ctx) const
+  {
+    return fmt::format_to(
+      ctx.out(),
+      "osd_shard_t(osd: {}, shard: {})",
+      shard.osd, shard.shard);
+  }
+};
+
+template <>
+struct fmt::formatter<librados::inconsistent_obj_t> {
+  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
+
+  template <typename FormatContext>
+  auto format(const auto &err, FormatContext& ctx) const
+  {
+    return fmt::format_to(
+      ctx.out(),
+      "inconsistent_obj_t(error: {}, "
+      "object: {}, "
+      "version: {}, "
+      "shards: {}, "
+      "union_shards: {})",
+      static_cast<librados::obj_err_t>(err),
+      err.object,
+      err.version,
+      err.shards,
+      err.union_shards);
+  }
+};
+
+template <>
+struct fmt::formatter<inconsistent_obj_wrapper> :
+  fmt::formatter<librados::inconsistent_obj_t> {};
+
+template <>
+struct fmt::formatter<librados::inconsistent_snapset_t> {
+  constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); }
+
+  template <typename FormatContext>
+  auto format(const auto &err, FormatContext& ctx) const
+  {
+    fmt::format_to(ctx.out(), "inconsistent_snapset_t(errors: ");
+    bool first = true;
+#define F(FLAG_NAME)                                                   \
+    if (err.errors & librados::inconsistent_snapset_t::FLAG_NAME) {    \
+      if (!first) {                                                    \
+       fmt::format_to(ctx.out(), "|");                                 \
+      } else {                                                         \
+       first = false;                                                  \
+      }                                                                        \
+      fmt::format_to(ctx.out(), #FLAG_NAME);                           \
+    }
+    F(SNAPSET_MISSING);
+    F(SNAPSET_CORRUPTED);
+    F(CLONE_MISSING);
+    F(SNAP_ERROR);
+    F(HEAD_MISMATCH);
+    F(HEADLESS_CLONE);
+    F(SIZE_MISMATCH);
+    F(OI_MISSING);
+    F(INFO_MISSING);
+    F(OI_CORRUPTED);
+    F(INFO_CORRUPTED);
+    F(EXTRA_CLONES);
+#undef F
+    return fmt::format_to(
+      ctx.out(),
+      ", object: {}, clones: {}, missing: {}",
+      err.object, err.clones, err.missing);
+  }
+};
+
+template <>
+struct fmt::formatter<inconsistent_snapset_wrapper> :
+  fmt::formatter<librados::inconsistent_snapset_t> {};
+
 #endif