summaryrefslogtreecommitdiffstats
path: root/src/tools/immutable_object_cache/Types.h
blob: 05394d843070c4cc9dbfdba4373f5bf57b5e1494 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPH_CACHE_TYPES_H
#define CEPH_CACHE_TYPES_H

#include "include/encoding.h"
#include "include/Context.h"
#include "SocketCommon.h"

namespace ceph {
namespace immutable_obj_cache {

namespace {
struct HeaderHelper {
  uint8_t v;
  uint8_t c_v;
  ceph_le32 len;
}__attribute__((packed));

inline uint8_t get_header_size() {
  return sizeof(HeaderHelper);
}

inline uint32_t get_data_len(char* buf) {
  HeaderHelper* header = reinterpret_cast<HeaderHelper*>(buf);
  return header->len;
}
}  //  namespace

class ObjectCacheRequest {
 public:
  uint16_t type;
  uint64_t seq;

  bufferlist payload;

  CacheGenContextURef process_msg;

  ObjectCacheRequest();
  ObjectCacheRequest(uint16_t type, uint64_t seq);
  virtual ~ObjectCacheRequest();

  // encode consists of two steps
  // step 1 : directly encode common bits using encode method of base classs.
  // step 2 : according to payload_empty, determine whether addtional bits
  //          need to be encoded which be implements by child class.
  void encode();
  void decode(bufferlist& bl);
  bufferlist get_payload_bufferlist() { return payload; }

  virtual void encode_payload() = 0;
  virtual void decode_payload(bufferlist::const_iterator bl_it,
                              __u8 encode_version) = 0;
  virtual uint16_t get_request_type() = 0;
  virtual bool payload_empty() = 0;
};

class ObjectCacheRegData : public ObjectCacheRequest {
 public:
  std::string version;
  ObjectCacheRegData();
  ObjectCacheRegData(uint16_t t, uint64_t s, const std::string &version);
  ObjectCacheRegData(uint16_t t, uint64_t s);
  ~ObjectCacheRegData() override;
  void encode_payload() override;
  void decode_payload(bufferlist::const_iterator bl,
                      __u8 encode_version) override;
  uint16_t get_request_type() override { return RBDSC_REGISTER; }
  bool payload_empty() override { return false; }
};

class ObjectCacheRegReplyData : public ObjectCacheRequest {
 public:
  ObjectCacheRegReplyData();
  ObjectCacheRegReplyData(uint16_t t, uint64_t s);
  ~ObjectCacheRegReplyData() override;
  void encode_payload() override;
  void decode_payload(bufferlist::const_iterator iter,
                      __u8 encode_version) override;
  uint16_t get_request_type() override { return RBDSC_REGISTER_REPLY; }
  bool payload_empty() override { return true; }
};

class ObjectCacheReadData : public ObjectCacheRequest {
 public:
  uint64_t read_offset;
  uint64_t read_len;
  uint64_t pool_id;
  uint64_t snap_id;
  uint64_t object_size = 0;
  std::string oid;
  std::string pool_namespace;
  ObjectCacheReadData(uint16_t t, uint64_t s, uint64_t read_offset,
                      uint64_t read_len, uint64_t pool_id,
                      uint64_t snap_id, uint64_t object_size,
                      std::string oid, std::string pool_namespace);
  ObjectCacheReadData(uint16_t t, uint64_t s);
  ~ObjectCacheReadData() override;
  void encode_payload() override;
  void decode_payload(bufferlist::const_iterator bl,
                      __u8 encode_version) override;
  uint16_t get_request_type() override { return RBDSC_READ; }
  bool payload_empty() override { return false; }
};

class ObjectCacheReadReplyData : public ObjectCacheRequest {
 public:
  std::string cache_path;
  ObjectCacheReadReplyData(uint16_t t, uint64_t s, std::string cache_path);
  ObjectCacheReadReplyData(uint16_t t, uint64_t s);
  ~ObjectCacheReadReplyData() override;
  void encode_payload() override;
  void decode_payload(bufferlist::const_iterator bl,
                      __u8 encode_version) override;
  uint16_t get_request_type() override { return RBDSC_READ_REPLY; }
  bool payload_empty() override { return false; }
};

class ObjectCacheReadRadosData : public ObjectCacheRequest {
 public:
  ObjectCacheReadRadosData();
  ObjectCacheReadRadosData(uint16_t t, uint64_t s);
  ~ObjectCacheReadRadosData() override;
  void encode_payload() override;
  void decode_payload(bufferlist::const_iterator bl,
                      __u8 encode_version) override;
  uint16_t get_request_type() override { return RBDSC_READ_RADOS; }
  bool payload_empty() override { return true; }
};

ObjectCacheRequest* decode_object_cache_request(bufferlist payload_buffer);

}  // namespace immutable_obj_cache
}  // namespace ceph
#endif  // CEPH_CACHE_TYPES_H