]>
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 | ||
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: | |
f91f0fd5 | 60 | std::string version; |
9f95a23c | 61 | ObjectCacheRegData(); |
f91f0fd5 | 62 | ObjectCacheRegData(uint16_t t, uint64_t s, const std::string &version); |
9f95a23c TL |
63 | ObjectCacheRegData(uint16_t t, uint64_t s); |
64 | ~ObjectCacheRegData() override; | |
65 | void encode_payload() override; | |
66 | void decode_payload(bufferlist::const_iterator bl) override; | |
67 | uint16_t get_request_type() override { return RBDSC_REGISTER; } | |
f91f0fd5 | 68 | bool payload_empty() override { return false; } |
9f95a23c TL |
69 | }; |
70 | ||
71 | class ObjectCacheRegReplyData : public ObjectCacheRequest { | |
72 | public: | |
73 | ObjectCacheRegReplyData(); | |
74 | ObjectCacheRegReplyData(uint16_t t, uint64_t s); | |
75 | ~ObjectCacheRegReplyData() override; | |
76 | void encode_payload() override; | |
77 | void decode_payload(bufferlist::const_iterator iter) override; | |
78 | uint16_t get_request_type() override { return RBDSC_REGISTER_REPLY; } | |
79 | bool payload_empty() override { return true; } | |
80 | }; | |
81 | ||
82 | class ObjectCacheReadData : public ObjectCacheRequest { | |
83 | public: | |
84 | uint64_t read_offset; | |
85 | uint64_t read_len; | |
86 | uint64_t pool_id; | |
87 | uint64_t snap_id; | |
88 | std::string oid; | |
89 | std::string pool_namespace; | |
90 | ObjectCacheReadData(uint16_t t, uint64_t s, uint64_t read_offset, | |
91 | uint64_t read_len, uint64_t pool_id, | |
92 | uint64_t snap_id, std::string oid, | |
93 | std::string pool_namespace); | |
94 | ObjectCacheReadData(uint16_t t, uint64_t s); | |
95 | ~ObjectCacheReadData() override; | |
96 | void encode_payload() override; | |
97 | void decode_payload(bufferlist::const_iterator bl) override; | |
98 | uint16_t get_request_type() override { return RBDSC_READ; } | |
99 | bool payload_empty() override { return false; } | |
100 | }; | |
101 | ||
102 | class ObjectCacheReadReplyData : public ObjectCacheRequest { | |
103 | public: | |
104 | std::string cache_path; | |
105 | ObjectCacheReadReplyData(uint16_t t, uint64_t s, std::string cache_path); | |
106 | ObjectCacheReadReplyData(uint16_t t, uint64_t s); | |
107 | ~ObjectCacheReadReplyData() override; | |
108 | void encode_payload() override; | |
109 | void decode_payload(bufferlist::const_iterator bl) override; | |
110 | uint16_t get_request_type() override { return RBDSC_READ_REPLY; } | |
111 | bool payload_empty() override { return false; } | |
112 | }; | |
113 | ||
114 | class ObjectCacheReadRadosData : public ObjectCacheRequest { | |
115 | public: | |
116 | ObjectCacheReadRadosData(); | |
117 | ObjectCacheReadRadosData(uint16_t t, uint64_t s); | |
118 | ~ObjectCacheReadRadosData() override; | |
119 | void encode_payload() override; | |
120 | void decode_payload(bufferlist::const_iterator bl) override; | |
121 | uint16_t get_request_type() override { return RBDSC_READ_RADOS; } | |
122 | bool payload_empty() override { return true; } | |
123 | }; | |
124 | ||
125 | ObjectCacheRequest* decode_object_cache_request(bufferlist payload_buffer); | |
126 | ||
127 | } // namespace immutable_obj_cache | |
128 | } // namespace ceph | |
129 | #endif // CEPH_CACHE_TYPES_H |