]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/immutable_object_cache/Types.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / tools / immutable_object_cache / Types.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_CACHE_TYPES_H
5 #define CEPH_CACHE_TYPES_H
6
7 #include "include/encoding.h"
8 #include "include/Context.h"
9 #include "SocketCommon.h"
10
11 namespace ceph {
12 namespace immutable_obj_cache {
13
14 namespace {
15 struct HeaderHelper {
16 uint8_t v;
17 uint8_t c_v;
18 ceph_le32 len;
19 }__attribute__((packed));
20
21 inline uint8_t get_header_size() {
22 return sizeof(HeaderHelper);
23 }
24
25 inline uint32_t get_data_len(char* buf) {
26 HeaderHelper* header = reinterpret_cast<HeaderHelper*>(buf);
27 return header->len;
28 }
29 } // namespace
30
31 class ObjectCacheRequest {
32 public:
33 uint16_t type;
34 uint64_t seq;
35
36 bufferlist payload;
37
38 CacheGenContextURef process_msg;
39
40 ObjectCacheRequest();
41 ObjectCacheRequest(uint16_t type, uint64_t seq);
42 virtual ~ObjectCacheRequest();
43
44 // encode consists of two steps
45 // step 1 : directly encode common bits using encode method of base classs.
46 // step 2 : according to payload_empty, determine whether addtional bits
47 // need to be encoded which be implements by child class.
48 void encode();
49 void decode(bufferlist& bl);
50 bufferlist get_payload_bufferlist() { return payload; }
51
52 virtual void encode_payload() = 0;
53 virtual void decode_payload(bufferlist::const_iterator bl_it) = 0;
54 virtual uint16_t get_request_type() = 0;
55 virtual bool payload_empty() = 0;
56 };
57
58 class ObjectCacheRegData : public ObjectCacheRequest {
59 public:
60 ObjectCacheRegData();
61 ObjectCacheRegData(uint16_t t, uint64_t s);
62 ~ObjectCacheRegData() override;
63 void encode_payload() override;
64 void decode_payload(bufferlist::const_iterator bl) override;
65 uint16_t get_request_type() override { return RBDSC_REGISTER; }
66 bool payload_empty() override { return true; }
67 };
68
69 class ObjectCacheRegReplyData : public ObjectCacheRequest {
70 public:
71 ObjectCacheRegReplyData();
72 ObjectCacheRegReplyData(uint16_t t, uint64_t s);
73 ~ObjectCacheRegReplyData() override;
74 void encode_payload() override;
75 void decode_payload(bufferlist::const_iterator iter) override;
76 uint16_t get_request_type() override { return RBDSC_REGISTER_REPLY; }
77 bool payload_empty() override { return true; }
78 };
79
80 class ObjectCacheReadData : public ObjectCacheRequest {
81 public:
82 uint64_t read_offset;
83 uint64_t read_len;
84 uint64_t pool_id;
85 uint64_t snap_id;
86 std::string oid;
87 std::string pool_namespace;
88 ObjectCacheReadData(uint16_t t, uint64_t s, uint64_t read_offset,
89 uint64_t read_len, uint64_t pool_id,
90 uint64_t snap_id, std::string oid,
91 std::string pool_namespace);
92 ObjectCacheReadData(uint16_t t, uint64_t s);
93 ~ObjectCacheReadData() override;
94 void encode_payload() override;
95 void decode_payload(bufferlist::const_iterator bl) override;
96 uint16_t get_request_type() override { return RBDSC_READ; }
97 bool payload_empty() override { return false; }
98 };
99
100 class ObjectCacheReadReplyData : public ObjectCacheRequest {
101 public:
102 std::string cache_path;
103 ObjectCacheReadReplyData(uint16_t t, uint64_t s, std::string cache_path);
104 ObjectCacheReadReplyData(uint16_t t, uint64_t s);
105 ~ObjectCacheReadReplyData() override;
106 void encode_payload() override;
107 void decode_payload(bufferlist::const_iterator bl) override;
108 uint16_t get_request_type() override { return RBDSC_READ_REPLY; }
109 bool payload_empty() override { return false; }
110 };
111
112 class ObjectCacheReadRadosData : public ObjectCacheRequest {
113 public:
114 ObjectCacheReadRadosData();
115 ObjectCacheReadRadosData(uint16_t t, uint64_t s);
116 ~ObjectCacheReadRadosData() override;
117 void encode_payload() override;
118 void decode_payload(bufferlist::const_iterator bl) override;
119 uint16_t get_request_type() override { return RBDSC_READ_RADOS; }
120 bool payload_empty() override { return true; }
121 };
122
123 ObjectCacheRequest* decode_object_cache_request(bufferlist payload_buffer);
124
125 } // namespace immutable_obj_cache
126 } // namespace ceph
127 #endif // CEPH_CACHE_TYPES_H