From 31aa539f26697c75452114fc79e0a9c75cb0ccaa Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 27 Jul 2022 00:38:31 +0800 Subject: [PATCH] osd: use fmt/ranges.h for printing ranges now that fmt/ranges.h provides a generic mechinary for printing ranges. let's just use it. the output format is changed a little bit when it comes to set and map, but as long as it makes sense, and we don't use a tool to parse the logging messages for extracting information from the messages printed by fmt::format(), we should be safe. Signed-off-by: Kefu Chai --- src/common/hobject_fmt.h | 1 - src/include/types_fmt.h | 67 ----------------------------- src/msg/msg_fmt.h | 1 - src/osd/osd_types_fmt.h | 18 -------- src/osd/scrubber/pg_scrubber.cc | 2 + src/osd/scrubber/scrub_backend.cc | 2 + src/test/osd/scrubber_generators.cc | 2 + src/test/osd/test_scrubber_be.cc | 2 + 8 files changed, 8 insertions(+), 87 deletions(-) delete mode 100644 src/include/types_fmt.h diff --git a/src/common/hobject_fmt.h b/src/common/hobject_fmt.h index e60fc2a14fc0..9c33f43446a8 100644 --- a/src/common/hobject_fmt.h +++ b/src/common/hobject_fmt.h @@ -9,7 +9,6 @@ #include "common/hobject.h" #include "include/object_fmt.h" -#include "include/types_fmt.h" #include "msg/msg_fmt.h" // \todo reimplement diff --git a/src/include/types_fmt.h b/src/include/types_fmt.h deleted file mode 100644 index a3ea24d99e70..000000000000 --- a/src/include/types_fmt.h +++ /dev/null @@ -1,67 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab -#pragma once -/** - * \file fmtlib formatters for some types.h classes - */ - -#include - -#include - -#include "include/types.h" - -template -struct fmt::formatter> { - constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } - - template - auto format(const std::pair& p, FormatContext& ctx) - { - return fmt::format_to(ctx.out(), "{}={}", p.first, p.second); - } -}; - -template -struct fmt::formatter> { - constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } - - template - auto format(const std::map& m, FormatContext& ctx) - { - return fmt::format_to(ctx.out(), "{{{}}}", fmt::join(m, ",")); - } -}; - -template -struct fmt::formatter> { - constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } - - template - auto format(const std::list& l, FormatContext& ctx) - { - return fmt::format_to(ctx.out(), "{}", fmt::join(l, ",")); - } -}; - -template -struct fmt::formatter> { - constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } - - template - auto format(const std::vector& v, FormatContext& ctx) - { - return fmt::format_to(ctx.out(), "[{}]", fmt::join(v, ",")); - } -}; - -template -struct fmt::formatter> { - constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } - - template - auto format(const std::set& s, FormatContext& ctx) - { - return fmt::format_to(ctx.out(), "{}", fmt::join(s, ",")); - } -}; diff --git a/src/msg/msg_fmt.h b/src/msg/msg_fmt.h index 5ed4ca997fe5..41c4c6af89de 100644 --- a/src/msg/msg_fmt.h +++ b/src/msg/msg_fmt.h @@ -8,7 +8,6 @@ #include -#include "include/types_fmt.h" #include "msg/msg_types.h" template <> diff --git a/src/osd/osd_types_fmt.h b/src/osd/osd_types_fmt.h index cb54572c8e24..9124ac202085 100644 --- a/src/osd/osd_types_fmt.h +++ b/src/osd/osd_types_fmt.h @@ -6,7 +6,6 @@ */ #include "common/hobject_fmt.h" -#include "include/types_fmt.h" #include "osd/osd_types.h" #include @@ -195,23 +194,6 @@ struct fmt::formatter { // snaps and snap-sets -template class C> -struct fmt::formatter> { - constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } - - template - auto format(const interval_set& inter, FormatContext& ctx) - { - bool first = true; - fmt::format_to(ctx.out(), "["); - for (const auto& [start, len] : inter) { - fmt::format_to(ctx.out(), "{}{}~{}", (first ? "" : ","), start, len); - first = false; - } - return fmt::format_to(ctx.out(), "]"); - } -}; - template <> struct fmt::formatter { template diff --git a/src/osd/scrubber/pg_scrubber.cc b/src/osd/scrubber/pg_scrubber.cc index f27a9c79a9c4..557e32e328ae 100644 --- a/src/osd/scrubber/pg_scrubber.cc +++ b/src/osd/scrubber/pg_scrubber.cc @@ -7,6 +7,8 @@ #include #include +#include + #include "debug.h" #include "common/errno.h" diff --git a/src/osd/scrubber/scrub_backend.cc b/src/osd/scrubber/scrub_backend.cc index 70b3eed9ed0a..478eca12380f 100644 --- a/src/osd/scrubber/scrub_backend.cc +++ b/src/osd/scrubber/scrub_backend.cc @@ -5,6 +5,8 @@ #include +#include + #include "common/debug.h" #include "include/utime_fmt.h" diff --git a/src/test/osd/scrubber_generators.cc b/src/test/osd/scrubber_generators.cc index 4e84406c6789..0f2f371e714b 100644 --- a/src/test/osd/scrubber_generators.cc +++ b/src/test/osd/scrubber_generators.cc @@ -3,6 +3,8 @@ #include "test/osd/scrubber_generators.h" +#include + using namespace ScrubGenerator; // ref: PGLogTestRebuildMissing() diff --git a/src/test/osd/test_scrubber_be.cc b/src/test/osd/test_scrubber_be.cc index d42634020af9..1c7f0abab655 100644 --- a/src/test/osd/test_scrubber_be.cc +++ b/src/test/osd/test_scrubber_be.cc @@ -7,6 +7,8 @@ #include #include +#include + #include "common/async/context_pool.h" #include "common/ceph_argparse.h" #include "global/global_context.h" -- 2.47.3