blob: edf082f1e383f7563846b1f68f7a0c029cc5691a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#pragma once
#include "crimson/os/seastore/cached_extent.h"
namespace crimson::os::seastore {
struct RootMetaBlock : LogicalCachedExtent {
using meta_t = std::map<std::string, std::string>;
using Ref = TCachedExtentRef<RootMetaBlock>;
static constexpr size_t SIZE = 4096;
static constexpr int MAX_META_LENGTH = 1024;
explicit RootMetaBlock(ceph::bufferptr &&ptr)
: LogicalCachedExtent(std::move(ptr)) {}
explicit RootMetaBlock(extent_len_t length)
: LogicalCachedExtent(length) {}
RootMetaBlock(const RootMetaBlock &rhs)
: LogicalCachedExtent(rhs) {}
CachedExtentRef duplicate_for_write(Transaction&) final {
return CachedExtentRef(new RootMetaBlock(*this));
}
static constexpr extent_types_t TYPE = extent_types_t::ROOT_META;
extent_types_t get_type() const final {
return extent_types_t::ROOT_META;
}
/// dumps root meta as delta
ceph::bufferlist get_delta() final {
ceph::bufferlist bl;
ceph::buffer::ptr bptr(get_bptr(), 0, MAX_META_LENGTH);
bl.append(bptr);
return bl;
}
/// overwrites root
void apply_delta(const ceph::bufferlist &_bl) final
{
assert(_bl.length() == MAX_META_LENGTH);
ceph::bufferlist bl = _bl;
bl.rebuild();
get_bptr().copy_in(0, MAX_META_LENGTH, bl.front().c_str());
}
meta_t get_meta() const {
bufferlist bl;
bl.append(get_bptr());
meta_t ret;
auto iter = bl.cbegin();
decode(ret, iter);
return ret;
}
void set_meta(const meta_t &m) {
ceph::bufferlist bl;
encode(m, bl);
ceph_assert(bl.length() <= MAX_META_LENGTH);
bl.rebuild();
get_bptr().zero(0, MAX_META_LENGTH);
get_bptr().copy_in(0, bl.length(), bl.front().c_str());
}
};
using RootMetaBlockRef = RootMetaBlock::Ref;
} // crimson::os::seastore
#if FMT_VERSION >= 90000
template <> struct fmt::formatter<crimson::os::seastore::RootMetaBlock>
: fmt::ostream_formatter {};
#endif
|