summaryrefslogtreecommitdiffstats
path: root/src/tools/immutable_object_cache/Types.cc
blob: 860017d6aae0a7adffd32e36244a99294edcb922 (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "Types.h"
#include "SocketCommon.h"

#define dout_subsys ceph_subsys_immutable_obj_cache
#undef dout_prefix
#define dout_prefix *_dout << "ceph::cache::Types: " << __func__ << ": "

namespace ceph {
namespace immutable_obj_cache {

ObjectCacheRequest::ObjectCacheRequest() {}
ObjectCacheRequest::ObjectCacheRequest(uint16_t t, uint64_t s)
  : type(t), seq(s) {}
ObjectCacheRequest::~ObjectCacheRequest() {}

void ObjectCacheRequest::encode() {
  ENCODE_START(2, 1, payload);
  ceph::encode(type, payload);
  ceph::encode(seq, payload);
  if (!payload_empty()) {
    encode_payload();
  }
  ENCODE_FINISH(payload);
}

void ObjectCacheRequest::decode(bufferlist& bl) {
  auto i = bl.cbegin();
  DECODE_START(2, i);
  ceph::decode(type, i);
  ceph::decode(seq, i);
  if (!payload_empty()) {
    decode_payload(i, struct_v);
  }
  DECODE_FINISH(i);
}

ObjectCacheRegData::ObjectCacheRegData() {}
ObjectCacheRegData::ObjectCacheRegData(uint16_t t, uint64_t s)
  : ObjectCacheRequest(t, s) {}
ObjectCacheRegData::ObjectCacheRegData(uint16_t t, uint64_t s,
                                       const std::string &version)
  : ObjectCacheRequest(t, s),
    version(version) {
}

ObjectCacheRegData::~ObjectCacheRegData() {}

void ObjectCacheRegData::encode_payload() {
  ceph::encode(version, payload);
}

void ObjectCacheRegData::decode_payload(bufferlist::const_iterator i,
                                        __u8 encode_version) {
  if (i.end()) {
    return;
  }
  ceph::decode(version, i);
}

ObjectCacheRegReplyData::ObjectCacheRegReplyData() {}
ObjectCacheRegReplyData::ObjectCacheRegReplyData(uint16_t t, uint64_t s)
  : ObjectCacheRequest(t, s) {}

ObjectCacheRegReplyData::~ObjectCacheRegReplyData() {}

void ObjectCacheRegReplyData::encode_payload() {}

void ObjectCacheRegReplyData::decode_payload(bufferlist::const_iterator bl,
                                            __u8 encode_version) {}

ObjectCacheReadData::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)
  : ObjectCacheRequest(t, s), read_offset(read_offset),
    read_len(read_len), pool_id(pool_id), snap_id(snap_id),
    object_size(object_size), oid(oid), pool_namespace(pool_namespace)
{}

ObjectCacheReadData::ObjectCacheReadData(uint16_t t, uint64_t s)
  : ObjectCacheRequest(t, s) {}

ObjectCacheReadData::~ObjectCacheReadData() {}

void ObjectCacheReadData::encode_payload() {
  ceph::encode(read_offset, payload);
  ceph::encode(read_len, payload);
  ceph::encode(pool_id, payload);
  ceph::encode(snap_id, payload);
  ceph::encode(oid, payload);
  ceph::encode(pool_namespace, payload);
  ceph::encode(object_size, payload);
}

void ObjectCacheReadData::decode_payload(bufferlist::const_iterator i,
                                        __u8 encode_version) {
  ceph::decode(read_offset, i);
  ceph::decode(read_len, i);
  ceph::decode(pool_id, i);
  ceph::decode(snap_id, i);
  ceph::decode(oid, i);
  ceph::decode(pool_namespace, i);
  if (encode_version >= 2) {
    ceph::decode(object_size, i);
  }
}

ObjectCacheReadReplyData::ObjectCacheReadReplyData(uint16_t t, uint64_t s,
                                                   string cache_path)
  : ObjectCacheRequest(t, s), cache_path(cache_path) {}
ObjectCacheReadReplyData::ObjectCacheReadReplyData(uint16_t t, uint64_t s)
  : ObjectCacheRequest(t, s) {}

ObjectCacheReadReplyData::~ObjectCacheReadReplyData() {}

void ObjectCacheReadReplyData::encode_payload() {
  ceph::encode(cache_path, payload);
}

void ObjectCacheReadReplyData::decode_payload(bufferlist::const_iterator i,
                                              __u8 encode_version) {
  ceph::decode(cache_path, i);
}

ObjectCacheReadRadosData::ObjectCacheReadRadosData() {}
ObjectCacheReadRadosData::ObjectCacheReadRadosData(uint16_t t, uint64_t s)
  : ObjectCacheRequest(t, s) {}

ObjectCacheReadRadosData::~ObjectCacheReadRadosData() {}

void ObjectCacheReadRadosData::encode_payload() {}

void ObjectCacheReadRadosData::decode_payload(bufferlist::const_iterator i,
                                              __u8 encode_version) {}

ObjectCacheRequest* decode_object_cache_request(bufferlist payload_buffer) {
  ObjectCacheRequest* req = nullptr;

  uint16_t type;
  uint64_t seq;
  auto i = payload_buffer.cbegin();
  DECODE_START(1, i);
  ceph::decode(type, i);
  ceph::decode(seq, i);
  DECODE_FINISH(i);

  switch (type) {
    case RBDSC_REGISTER: {
      req = new ObjectCacheRegData(type, seq);
      break;
    }
    case RBDSC_READ: {
      req = new ObjectCacheReadData(type, seq);
      break;
    }
    case RBDSC_REGISTER_REPLY: {
      req = new ObjectCacheRegReplyData(type, seq);
      break;
    }
    case RBDSC_READ_REPLY: {
      req = new ObjectCacheReadReplyData(type, seq);
      break;
    }
    case RBDSC_READ_RADOS: {
      req = new ObjectCacheReadRadosData(type, seq);
      break;
    }
    default:
      ceph_assert(0);
  }

  req->decode(payload_buffer);

  return req;
}

}  // namespace immutable_obj_cache
}  // namespace ceph