]> git.proxmox.com Git - ceph.git/blob - ceph/src/crimson/os/seastore/onode.h
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / crimson / os / seastore / onode.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #pragma once
5
6 #include <iosfwd>
7
8 #include <boost/intrusive_ptr.hpp>
9 #include <boost/smart_ptr/intrusive_ref_counter.hpp>
10
11 #include "include/byteorder.h"
12 #include "seastore_types.h"
13
14 namespace crimson::os::seastore {
15
16 struct onode_layout_t {
17 // The expected decode size of object_info_t without oid.
18 static constexpr int MAX_OI_LENGTH = 232;
19 // We might want to move the ss field out of onode_layout_t.
20 // The reason is that ss_attr may grow to relative large, as
21 // its clone_overlap may grow to a large size, if applications
22 // set objects to a relative large size(for the purpose of reducing
23 // the number of objects per OSD, so that all objects' metadata
24 // can be cached in memory) and do many modifications between
25 // snapshots.
26 // TODO: implement flexible-sized onode value to store inline ss_attr
27 // effectively.
28 static constexpr int MAX_SS_LENGTH = 1;
29
30 ceph_le32 size{0};
31 ceph_le32 oi_size{0};
32 ceph_le32 ss_size{0};
33 omap_root_le_t omap_root;
34 omap_root_le_t xattr_root;
35
36 object_data_le_t object_data;
37
38 char oi[MAX_OI_LENGTH];
39 char ss[MAX_SS_LENGTH];
40 } __attribute__((packed));
41
42 class Transaction;
43
44 /**
45 * Onode
46 *
47 * Interface manipulated by seastore. OnodeManager implementations should
48 * return objects derived from this interface with layout referencing
49 * internal representation of onode_layout_t.
50 */
51 class Onode : public boost::intrusive_ref_counter<
52 Onode,
53 boost::thread_unsafe_counter>
54 {
55 protected:
56 virtual laddr_t get_hint() const = 0;
57 const uint32_t default_metadata_offset = 0;
58 const uint32_t default_metadata_range = 0;
59 public:
60 Onode(uint32_t ddr, uint32_t dmr)
61 : default_metadata_offset(ddr),
62 default_metadata_range(dmr)
63 {}
64
65 virtual bool is_alive() const = 0;
66 virtual const onode_layout_t &get_layout() const = 0;
67 virtual onode_layout_t &get_mutable_layout(Transaction &t) = 0;
68 virtual ~Onode() = default;
69
70 laddr_t get_metadata_hint(uint64_t block_size) const {
71 assert(default_metadata_offset);
72 assert(default_metadata_range);
73 uint64_t range_blocks = default_metadata_range / block_size;
74 return get_hint() + default_metadata_offset +
75 (((uint32_t)std::rand() % range_blocks) * block_size);
76 }
77 laddr_t get_data_hint() const {
78 return get_hint();
79 }
80 };
81
82
83 std::ostream& operator<<(std::ostream &out, const Onode &rhs);
84 using OnodeRef = boost::intrusive_ptr<Onode>;
85 }
86
87 #if FMT_VERSION >= 90000
88 template<> struct fmt::formatter<crimson::os::seastore::Onode> : fmt::ostream_formatter {};
89 #endif