]>
Commit | Line | Data |
---|---|---|
20effc67 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | #pragma once | |
4 | /** | |
5 | * \file fmtlib formatters for some types.h classes | |
6 | */ | |
7 | ||
8 | #include "common/hobject_fmt.h" | |
9 | #include "osd/osd_types.h" | |
10 | ||
11 | template <> | |
12 | struct fmt::formatter<osd_reqid_t> { | |
13 | constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } | |
14 | ||
15 | template <typename FormatContext> | |
16 | auto format(const osd_reqid_t& req_id, FormatContext& ctx) | |
17 | { | |
18 | return fmt::format_to(ctx.out(), "{}.{}:{}", req_id.name, req_id.inc, | |
19 | req_id.tid); | |
20 | } | |
21 | }; | |
22 | ||
23 | template <> | |
24 | struct fmt::formatter<pg_shard_t> { | |
25 | constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } | |
26 | ||
27 | template <typename FormatContext> | |
28 | auto format(const pg_shard_t& shrd, FormatContext& ctx) | |
29 | { | |
30 | if (shrd.is_undefined()) { | |
31 | return fmt::format_to(ctx.out(), "?"); | |
32 | } | |
33 | if (shrd.shard == shard_id_t::NO_SHARD) { | |
34 | return fmt::format_to(ctx.out(), "{}", shrd.get_osd()); | |
35 | } | |
36 | return fmt::format_to(ctx.out(), "{}({})", shrd.get_osd(), shrd.shard); | |
37 | } | |
38 | }; | |
39 | ||
40 | template <> | |
41 | struct fmt::formatter<eversion_t> { | |
42 | constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } | |
43 | ||
44 | template <typename FormatContext> | |
45 | auto format(const eversion_t& ev, FormatContext& ctx) | |
46 | { | |
47 | return fmt::format_to(ctx.out(), "{}'{}", ev.epoch, ev.version); | |
48 | } | |
49 | }; | |
50 | ||
51 | template <> | |
52 | struct fmt::formatter<chunk_info_t> { | |
53 | constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } | |
54 | ||
55 | template <typename FormatContext> | |
56 | auto format(const chunk_info_t& ci, FormatContext& ctx) | |
57 | { | |
58 | return fmt::format_to(ctx.out(), "(len: {} oid: {} offset: {} flags: {})", | |
59 | ci.length, ci.oid, ci.offset, | |
60 | ci.get_flag_string(ci.flags)); | |
61 | } | |
62 | }; | |
63 | ||
64 | template <> | |
65 | struct fmt::formatter<object_manifest_t> { | |
66 | constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } | |
67 | ||
68 | template <typename FormatContext> | |
69 | auto format(const object_manifest_t& om, FormatContext& ctx) | |
70 | { | |
71 | fmt::format_to(ctx.out(), "manifest({}", om.get_type_name()); | |
72 | if (om.is_redirect()) { | |
73 | fmt::format_to(ctx.out(), " {}", om.redirect_target); | |
74 | } else if (om.is_chunked()) { | |
75 | fmt::format_to(ctx.out(), " {}", om.chunk_map); | |
76 | } | |
77 | return fmt::format_to(ctx.out(), ")"); | |
78 | } | |
79 | }; | |
80 | ||
81 | template <> | |
82 | struct fmt::formatter<object_info_t> { | |
83 | constexpr auto parse(format_parse_context& ctx) { return ctx.begin(); } | |
84 | ||
85 | template <typename FormatContext> | |
86 | auto format(const object_info_t& oi, FormatContext& ctx) | |
87 | { | |
88 | fmt::format_to(ctx.out(), "{}({} {} {} s {} uv {}", oi.soid, oi.version, | |
89 | oi.last_reqid, (oi.flags ? oi.get_flag_string() : ""), oi.size, | |
90 | oi.user_version); | |
91 | if (oi.is_data_digest()) { | |
92 | fmt::format_to(ctx.out(), " dd {:x}", oi.data_digest); | |
93 | } | |
94 | if (oi.is_omap_digest()) { | |
95 | fmt::format_to(ctx.out(), " od {:x}", oi.omap_digest); | |
96 | } | |
97 | ||
98 | fmt::format_to(ctx.out(), " alloc_hint [{} {} {}]", oi.expected_object_size, | |
99 | oi.expected_write_size, oi.alloc_hint_flags); | |
100 | ||
101 | if (oi.has_manifest()) { | |
102 | fmt::format_to(ctx.out(), " {}", oi.manifest); | |
103 | } | |
104 | return fmt::format_to(ctx.out(), ")"); | |
105 | } | |
106 | }; |