]> git.proxmox.com Git - ceph.git/blob - ceph/src/cls/fifo/cls_fifo_ops.h
91a012c0847ec4c842d3cc6b7e1b1aaa4cd2213d
[ceph.git] / ceph / src / cls / fifo / cls_fifo_ops.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 /*
5 * Ceph - scalable distributed file system
6 *
7 * Copyright (C) 2019 Red Hat, Inc.
8 * Copyright (C) 2019 SUSE LLC
9 *
10 * This is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License version 2.1, as published by the Free Software
13 * Foundation. See file COPYING.
14 *
15 */
16
17 #pragma once
18
19 #include <cstdint>
20 #include <optional>
21 #include <string>
22 #include <vector>
23
24 #include "include/buffer.h"
25 #include "include/encoding.h"
26 #include "include/types.h"
27
28 #include "cls/fifo/cls_fifo_types.h"
29
30 namespace rados::cls::fifo::op {
31 struct create_meta
32 {
33 std::string id;
34 std::optional<objv> version;
35 struct {
36 std::string name;
37 std::string ns;
38 } pool;
39 std::optional<std::string> oid_prefix;
40
41 std::uint64_t max_part_size{0};
42 std::uint64_t max_entry_size{0};
43
44 bool exclusive{false};
45
46 void encode(ceph::buffer::list& bl) const {
47 ENCODE_START(1, 1, bl);
48 encode(id, bl);
49 encode(version, bl);
50 encode(pool.name, bl);
51 encode(pool.ns, bl);
52 encode(oid_prefix, bl);
53 encode(max_part_size, bl);
54 encode(max_entry_size, bl);
55 encode(exclusive, bl);
56 ENCODE_FINISH(bl);
57 }
58 void decode(ceph::buffer::list::const_iterator& bl) {
59 DECODE_START(1, bl);
60 decode(id, bl);
61 decode(version, bl);
62 decode(pool.name, bl);
63 decode(pool.ns, bl);
64 decode(oid_prefix, bl);
65 decode(max_part_size, bl);
66 decode(max_entry_size, bl);
67 decode(exclusive, bl);
68 DECODE_FINISH(bl);
69 }
70 };
71 WRITE_CLASS_ENCODER(create_meta)
72
73 struct get_meta
74 {
75 std::optional<objv> version;
76
77 void encode(ceph::buffer::list& bl) const {
78 ENCODE_START(1, 1, bl);
79 encode(version, bl);
80 ENCODE_FINISH(bl);
81 }
82 void decode(ceph::buffer::list::const_iterator& bl) {
83 DECODE_START(1, bl);
84 decode(version, bl);
85 DECODE_FINISH(bl);
86 }
87 };
88 WRITE_CLASS_ENCODER(get_meta)
89
90 struct get_meta_reply
91 {
92 fifo::info info;
93 std::uint32_t part_header_size{0};
94 /* per entry extra data that is stored */
95 std::uint32_t part_entry_overhead{0};
96
97 void encode(ceph::buffer::list& bl) const {
98 ENCODE_START(1, 1, bl);
99 encode(info, bl);
100 encode(part_header_size, bl);
101 encode(part_entry_overhead, bl);
102 ENCODE_FINISH(bl);
103 }
104 void decode(ceph::buffer::list::const_iterator& bl) {
105 DECODE_START(1, bl);
106 decode(info, bl);
107 decode(part_header_size, bl);
108 decode(part_entry_overhead, bl);
109 DECODE_FINISH(bl);
110 }
111 };
112 WRITE_CLASS_ENCODER(get_meta_reply)
113
114 struct update_meta
115 {
116 objv version;
117
118 std::optional<std::uint64_t> tail_part_num;
119 std::optional<std::uint64_t> head_part_num;
120 std::optional<std::uint64_t> min_push_part_num;
121 std::optional<std::uint64_t> max_push_part_num;
122 std::vector<journal_entry> journal_entries_add;
123 std::vector<journal_entry> journal_entries_rm;
124
125 void encode(ceph::buffer::list& bl) const {
126 ENCODE_START(1, 1, bl);
127 encode(version, bl);
128 encode(tail_part_num, bl);
129 encode(head_part_num, bl);
130 encode(min_push_part_num, bl);
131 encode(max_push_part_num, bl);
132 encode(journal_entries_add, bl);
133 encode(journal_entries_rm, bl);
134 ENCODE_FINISH(bl);
135 }
136 void decode(ceph::buffer::list::const_iterator& bl) {
137 DECODE_START(1, bl);
138 decode(version, bl);
139 decode(tail_part_num, bl);
140 decode(head_part_num, bl);
141 decode(min_push_part_num, bl);
142 decode(max_push_part_num, bl);
143 decode(journal_entries_add, bl);
144 decode(journal_entries_rm, bl);
145 DECODE_FINISH(bl);
146 }
147 };
148 WRITE_CLASS_ENCODER(update_meta)
149
150 struct init_part
151 {
152 std::string tag;
153 data_params params;
154
155 void encode(ceph::buffer::list& bl) const {
156 ENCODE_START(1, 1, bl);
157 encode(tag, bl);
158 encode(params, bl);
159 ENCODE_FINISH(bl);
160 }
161 void decode(ceph::buffer::list::const_iterator& bl) {
162 DECODE_START(1, bl);
163 decode(tag, bl);
164 decode(params, bl);
165 DECODE_FINISH(bl);
166 }
167 };
168 WRITE_CLASS_ENCODER(init_part)
169
170 struct push_part
171 {
172 std::string tag;
173 std::deque<ceph::buffer::list> data_bufs;
174 std::uint64_t total_len{0};
175
176 void encode(ceph::buffer::list& bl) const {
177 ENCODE_START(1, 1, bl);
178 encode(tag, bl);
179 encode(data_bufs, bl);
180 encode(total_len, bl);
181 ENCODE_FINISH(bl);
182 }
183 void decode(ceph::buffer::list::const_iterator& bl) {
184 DECODE_START(1, bl);
185 decode(tag, bl);
186 decode(data_bufs, bl);
187 decode(total_len, bl);
188 DECODE_FINISH(bl);
189 }
190 };
191 WRITE_CLASS_ENCODER(push_part)
192
193 struct trim_part
194 {
195 std::optional<std::string> tag;
196 std::uint64_t ofs{0};
197 bool exclusive = false;
198
199 void encode(ceph::buffer::list& bl) const {
200 ENCODE_START(1, 1, bl);
201 encode(tag, bl);
202 encode(ofs, bl);
203 encode(exclusive, bl);
204 ENCODE_FINISH(bl);
205 }
206 void decode(ceph::buffer::list::const_iterator& bl) {
207 DECODE_START(1, bl);
208 decode(tag, bl);
209 decode(ofs, bl);
210 decode(exclusive, bl);
211 DECODE_FINISH(bl);
212 }
213 };
214 WRITE_CLASS_ENCODER(trim_part)
215
216 struct list_part
217 {
218 std::optional<std::string> tag;
219 std::uint64_t ofs{0};
220 int max_entries{100};
221
222 void encode(ceph::buffer::list& bl) const {
223 ENCODE_START(1, 1, bl);
224 encode(tag, bl);
225 encode(ofs, bl);
226 encode(max_entries, bl);
227 ENCODE_FINISH(bl);
228 }
229 void decode(ceph::buffer::list::const_iterator& bl) {
230 DECODE_START(1, bl);
231 decode(tag, bl);
232 decode(ofs, bl);
233 decode(max_entries, bl);
234 DECODE_FINISH(bl);
235 }
236 };
237 WRITE_CLASS_ENCODER(list_part)
238 inline constexpr int MAX_LIST_ENTRIES = 512;
239
240 struct list_part_reply
241 {
242 std::string tag;
243 std::vector<part_list_entry> entries;
244 bool more{false};
245 bool full_part{false}; /* whether part is full or still can be written to.
246 A non full part is by definition head part */
247
248 void encode(ceph::buffer::list& bl) const {
249 ENCODE_START(1, 1, bl);
250 encode(tag, bl);
251 encode(entries, bl);
252 encode(more, bl);
253 encode(full_part, bl);
254 ENCODE_FINISH(bl);
255 }
256 void decode(ceph::buffer::list::const_iterator& bl) {
257 DECODE_START(1, bl);
258 decode(tag, bl);
259 decode(entries, bl);
260 decode(more, bl);
261 decode(full_part, bl);
262 DECODE_FINISH(bl);
263 }
264 };
265 WRITE_CLASS_ENCODER(list_part_reply)
266
267 struct get_part_info
268 {
269 void encode(ceph::buffer::list &bl) const {
270 ENCODE_START(1, 1, bl);
271 ENCODE_FINISH(bl);
272 }
273 void decode(ceph::buffer::list::const_iterator &bl) {
274 DECODE_START(1, bl);
275 DECODE_FINISH(bl);
276 }
277 };
278 WRITE_CLASS_ENCODER(get_part_info)
279
280 struct get_part_info_reply
281 {
282 part_header header;
283
284 void encode(ceph::buffer::list &bl) const {
285 ENCODE_START(1, 1, bl);
286 encode(header, bl);
287 ENCODE_FINISH(bl);
288 }
289 void decode(ceph::buffer::list::const_iterator &bl) {
290 DECODE_START(1, bl);
291 decode(header, bl);
292 DECODE_FINISH(bl);
293 }
294 };
295 WRITE_CLASS_ENCODER(get_part_info_reply)
296
297 inline constexpr auto CLASS = "fifo";
298 inline constexpr auto CREATE_META = "create_meta";
299 inline constexpr auto GET_META = "get_meta";
300 inline constexpr auto UPDATE_META = "update_meta";
301 inline constexpr auto INIT_PART = "init_part";
302 inline constexpr auto PUSH_PART = "push_part";
303 inline constexpr auto TRIM_PART = "trim_part";
304 inline constexpr auto LIST_PART = "part_list";
305 inline constexpr auto GET_PART_INFO = "get_part_info";
306 } // namespace rados::cls::fifo::op