From: Ronen Friedman Date: Mon, 5 Aug 2024 05:29:59 +0000 (-0500) Subject: osd,common: add explicit formatter for shard_id_t X-Git-Tag: v20.0.0~1231^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3db48acaa495e9fd092f621bd4b418385041e9e3;p=ceph.git osd,common: add explicit formatter for shard_id_t Signed-off-by: Ronen Friedman --- diff --git a/src/include/types_fmt.h b/src/include/types_fmt.h new file mode 100644 index 000000000000..f73f5dd93851 --- /dev/null +++ b/src/include/types_fmt.h @@ -0,0 +1,14 @@ +// -*- 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 "common/fmt_common.h" +#include "include/types.h" + + +static inline auto format_as(shard_id_t sid) +{ + return (int)sid.id; +} diff --git a/src/osd/osd_types_fmt.h b/src/osd/osd_types_fmt.h index e8e9d807c466..04f4d46ee510 100644 --- a/src/osd/osd_types_fmt.h +++ b/src/osd/osd_types_fmt.h @@ -2,10 +2,11 @@ // vim: ts=8 sw=2 smarttab #pragma once /** - * \file fmtlib formatters for some types.h classes + * \file fmtlib formatters for some osd_types.h classes */ #include "common/hobject.h" +#include "include/types_fmt.h" #include "osd/osd_types.h" #include #include @@ -14,8 +15,9 @@ #include #endif +namespace fmt { template <> -struct fmt::formatter { +struct formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template @@ -27,7 +29,7 @@ struct fmt::formatter { }; template <> -struct fmt::formatter { +struct formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template @@ -39,12 +41,12 @@ struct fmt::formatter { if (shrd.shard == shard_id_t::NO_SHARD) { return fmt::format_to(ctx.out(), "{}", shrd.get_osd()); } - return fmt::format_to(ctx.out(), "{}({})", shrd.get_osd(), shrd.shard); + return fmt::format_to(ctx.out(), "{}({:d})", shrd.get_osd(), shrd.shard); } }; template <> -struct fmt::formatter { +struct formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template @@ -55,7 +57,7 @@ struct fmt::formatter { }; template <> -struct fmt::formatter { +struct formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template @@ -68,7 +70,7 @@ struct fmt::formatter { }; template <> -struct fmt::formatter { +struct formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template @@ -85,7 +87,7 @@ struct fmt::formatter { }; template <> -struct fmt::formatter { +struct formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template @@ -112,7 +114,7 @@ struct fmt::formatter { }; template <> -struct fmt::formatter { +struct formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template @@ -124,7 +126,7 @@ struct fmt::formatter { template <> -struct fmt::formatter { +struct formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template @@ -139,7 +141,7 @@ struct fmt::formatter { }; template <> -struct fmt::formatter { +struct formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template @@ -167,7 +169,7 @@ struct fmt::formatter { }; template <> -struct fmt::formatter { +struct formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template @@ -200,7 +202,7 @@ struct fmt::formatter { // snaps and snap-sets template <> -struct fmt::formatter { +struct formatter { template constexpr auto parse(ParseContext& ctx) { @@ -262,7 +264,7 @@ struct fmt::formatter { }; template <> -struct fmt::formatter { +struct formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } ///\todo: consider passing the 'D" flag to control snapset dump @@ -295,7 +297,7 @@ struct fmt::formatter { }; template <> -struct fmt::formatter { +struct formatter { template constexpr auto parse(ParseContext& ctx) { @@ -329,7 +331,7 @@ struct fmt::formatter { }; template <> -struct fmt::formatter { +struct formatter { constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } template @@ -382,6 +384,8 @@ struct fmt::formatter { #undef FORMAT } }; +} // namespace fmt + inline std::ostream &operator<<(std::ostream &lhs, const object_stat_sum_t &sum) { return lhs << fmt::format("{}", sum); }