]>
Commit | Line | Data |
---|---|---|
9f95a23c TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
11fdf7f2 TL |
4 | #include "osd_meta.h" |
5 | ||
9f95a23c TL |
6 | #include <fmt/format.h> |
7 | #include <fmt/ostream.h> | |
8 | ||
9 | #include "crimson/os/futurized_collection.h" | |
10 | #include "crimson/os/futurized_store.h" | |
11 | #include "os/Transaction.h" | |
12 | ||
20effc67 | 13 | using std::string; |
1e59de90 | 14 | using read_errorator = crimson::os::FuturizedStore::Shard::read_errorator; |
11fdf7f2 TL |
15 | |
16 | void OSDMeta::create(ceph::os::Transaction& t) | |
17 | { | |
9f95a23c | 18 | t.create_collection(coll->get_cid(), 0); |
11fdf7f2 TL |
19 | } |
20 | ||
21 | void OSDMeta::store_map(ceph::os::Transaction& t, | |
22 | epoch_t e, const bufferlist& m) | |
23 | { | |
9f95a23c | 24 | t.write(coll->get_cid(), osdmap_oid(e), 0, m.length(), m); |
11fdf7f2 TL |
25 | } |
26 | ||
27 | seastar::future<bufferlist> OSDMeta::load_map(epoch_t e) | |
28 | { | |
20effc67 TL |
29 | return store.read(coll, |
30 | osdmap_oid(e), 0, 0, | |
31 | CEPH_OSD_OP_FLAG_FADVISE_WILLNEED).handle_error( | |
9f95a23c | 32 | read_errorator::all_same_way([e] { |
aee94f69 TL |
33 | ceph_abort_msg(fmt::format("{} read gave enoent on {}", |
34 | __func__, osdmap_oid(e))); | |
9f95a23c | 35 | })); |
11fdf7f2 TL |
36 | } |
37 | ||
38 | void OSDMeta::store_superblock(ceph::os::Transaction& t, | |
39 | const OSDSuperblock& superblock) | |
40 | { | |
41 | bufferlist bl; | |
42 | encode(superblock, bl); | |
9f95a23c | 43 | t.write(coll->get_cid(), superblock_oid(), 0, bl.length(), bl); |
11fdf7f2 TL |
44 | } |
45 | ||
1e59de90 | 46 | OSDMeta::load_superblock_ret OSDMeta::load_superblock() |
11fdf7f2 | 47 | { |
1e59de90 TL |
48 | return store.read( |
49 | coll, superblock_oid(), 0, 0 | |
50 | ).safe_then([] (bufferlist&& bl) { | |
51 | auto p = bl.cbegin(); | |
52 | OSDSuperblock superblock; | |
53 | decode(superblock, p); | |
54 | return seastar::make_ready_future<OSDSuperblock>(std::move(superblock)); | |
55 | }); | |
11fdf7f2 TL |
56 | } |
57 | ||
f67539c2 TL |
58 | seastar::future<std::tuple<pg_pool_t, |
59 | std::string, | |
60 | OSDMeta::ec_profile_t>> | |
11fdf7f2 | 61 | OSDMeta::load_final_pool_info(int64_t pool) { |
20effc67 | 62 | return store.read(coll, final_pool_info_oid(pool), |
f67539c2 | 63 | 0, 0).safe_then([] (bufferlist&& bl) { |
11fdf7f2 TL |
64 | auto p = bl.cbegin(); |
65 | pg_pool_t pi; | |
66 | string name; | |
67 | ec_profile_t ec_profile; | |
68 | decode(pi, p); | |
69 | decode(name, p); | |
70 | decode(ec_profile, p); | |
f67539c2 TL |
71 | return seastar::make_ready_future<std::tuple<pg_pool_t, |
72 | string, | |
73 | ec_profile_t>>( | |
74 | std::make_tuple(std::move(pi), | |
75 | std::move(name), | |
76 | std::move(ec_profile))); | |
9f95a23c TL |
77 | },read_errorator::all_same_way([pool] { |
78 | throw std::runtime_error(fmt::format("read gave enoent on {}", | |
79 | final_pool_info_oid(pool))); | |
80 | })); | |
11fdf7f2 TL |
81 | } |
82 | ||
83 | ghobject_t OSDMeta::osdmap_oid(epoch_t epoch) | |
84 | { | |
85 | string name = fmt::format("osdmap.{}", epoch); | |
86 | return ghobject_t(hobject_t(sobject_t(object_t(name), 0))); | |
87 | } | |
88 | ||
89 | ghobject_t OSDMeta::final_pool_info_oid(int64_t pool) | |
90 | { | |
91 | string name = fmt::format("final_pool_{}", pool); | |
92 | return ghobject_t(hobject_t(sobject_t(object_t(name), CEPH_NOSNAP))); | |
93 | } | |
94 | ||
95 | ghobject_t OSDMeta::superblock_oid() | |
96 | { | |
97 | return ghobject_t(hobject_t(sobject_t(object_t("osd_superblock"), 0))); | |
98 | } |