]> git.proxmox.com Git - ceph.git/blame - ceph/src/crimson/os/seastore/onode.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / crimson / os / seastore / onode.h
CommitLineData
20effc67 1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:nil -*-
f67539c2
TL
2// vim: ts=8 sw=2 smarttab
3
4#pragma once
5
20effc67 6#include <iosfwd>
f67539c2
TL
7
8#include <boost/intrusive_ptr.hpp>
9#include <boost/smart_ptr/intrusive_ref_counter.hpp>
10
20effc67
TL
11#include "include/byteorder.h"
12#include "seastore_types.h"
f67539c2
TL
13
14namespace crimson::os::seastore {
15
20effc67
TL
16struct 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
42class 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 */
f67539c2
TL
51class Onode : public boost::intrusive_ref_counter<
52 Onode,
53 boost::thread_unsafe_counter>
54{
20effc67
TL
55protected:
56 virtual laddr_t get_hint() const = 0;
57 const uint32_t default_metadata_offset = 0;
58 const uint32_t default_metadata_range = 0;
f67539c2 59public:
20effc67
TL
60 Onode(uint32_t ddr, uint32_t dmr)
61 : default_metadata_offset(ddr),
62 default_metadata_range(dmr)
f67539c2 63 {}
20effc67
TL
64
65 virtual const onode_layout_t &get_layout() const = 0;
66 virtual onode_layout_t &get_mutable_layout(Transaction &t) = 0;
67 virtual ~Onode() = default;
68
69 laddr_t get_metadata_hint() const {
70 assert(default_metadata_offset);
71 assert(default_metadata_range);
72 return get_hint() + default_metadata_offset +
73 ((uint32_t)std::rand() % default_metadata_range);
f67539c2 74 }
20effc67
TL
75 laddr_t get_data_hint() const {
76 return get_hint();
f67539c2 77 }
f67539c2
TL
78};
79
20effc67 80
f67539c2
TL
81std::ostream& operator<<(std::ostream &out, const Onode &rhs);
82using OnodeRef = boost::intrusive_ptr<Onode>;
83}