1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*-
2 // vim: ts=8 sw=2 smarttab
8 #include <boost/intrusive_ptr.hpp>
9 #include <boost/smart_ptr/intrusive_ref_counter.hpp>
11 #include "include/byteorder.h"
12 #include "seastore_types.h"
14 namespace crimson::os::seastore
{
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
26 // TODO: implement flexible-sized onode value to store inline ss_attr
28 static constexpr int MAX_SS_LENGTH
= 1;
33 omap_root_le_t omap_root
;
34 omap_root_le_t xattr_root
;
36 object_data_le_t object_data
;
38 char oi
[MAX_OI_LENGTH
];
39 char ss
[MAX_SS_LENGTH
];
40 } __attribute__((packed
));
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.
51 class Onode
: public boost::intrusive_ref_counter
<
53 boost::thread_unsafe_counter
>
56 virtual laddr_t
get_hint() const = 0;
57 const uint32_t default_metadata_offset
= 0;
58 const uint32_t default_metadata_range
= 0;
60 Onode(uint32_t ddr
, uint32_t dmr
)
61 : default_metadata_offset(ddr
),
62 default_metadata_range(dmr
)
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;
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
);
77 laddr_t
get_data_hint() const {
83 std::ostream
& operator<<(std::ostream
&out
, const Onode
&rhs
);
84 using OnodeRef
= boost::intrusive_ptr
<Onode
>;
87 #if FMT_VERSION >= 90000
88 template<> struct fmt::formatter
<crimson::os::seastore::Onode
> : fmt::ostream_formatter
{};