]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/services/svc_sys_obj.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / rgw / services / svc_sys_obj.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 #pragma once
5
6 #include "common/static_ptr.h"
7
8 #include "rgw_service.h"
9
10 #include "svc_rados.h"
11 #include "svc_sys_obj_types.h"
12 #include "svc_sys_obj_core_types.h"
13
14
15 class RGWSI_Zone;
16 class RGWSI_SysObj;
17
18 struct rgw_cache_entry_info;
19
20 class RGWSI_SysObj : public RGWServiceInstance
21 {
22 friend struct RGWServices_Def;
23
24 public:
25 class Obj {
26 friend class ROp;
27
28 RGWSI_SysObj_Core *core_svc;
29 rgw_raw_obj obj;
30
31 public:
32 Obj(RGWSI_SysObj_Core *_core_svc, const rgw_raw_obj& _obj)
33 : core_svc(_core_svc), obj(_obj) {}
34
35 rgw_raw_obj& get_obj() {
36 return obj;
37 }
38
39 struct ROp {
40 Obj& source;
41
42 ceph::static_ptr<RGWSI_SysObj_Obj_GetObjState, sizeof(RGWSI_SysObj_Core_GetObjState)> state;
43
44 RGWObjVersionTracker *objv_tracker{nullptr};
45 std::map<std::string, bufferlist> *attrs{nullptr};
46 bool raw_attrs{false};
47 boost::optional<obj_version> refresh_version{boost::none};
48 ceph::real_time *lastmod{nullptr};
49 uint64_t *obj_size{nullptr};
50 rgw_cache_entry_info *cache_info{nullptr};
51
52 ROp& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) {
53 objv_tracker = _objv_tracker;
54 return *this;
55 }
56
57 ROp& set_last_mod(ceph::real_time *_lastmod) {
58 lastmod = _lastmod;
59 return *this;
60 }
61
62 ROp& set_obj_size(uint64_t *_obj_size) {
63 obj_size = _obj_size;
64 return *this;
65 }
66
67 ROp& set_attrs(std::map<std::string, bufferlist> *_attrs) {
68 attrs = _attrs;
69 return *this;
70 }
71
72 ROp& set_raw_attrs(bool ra) {
73 raw_attrs = ra;
74 return *this;
75 }
76
77 ROp& set_refresh_version(boost::optional<obj_version>& rf) {
78 refresh_version = rf;
79 return *this;
80 }
81
82 ROp& set_cache_info(rgw_cache_entry_info *ci) {
83 cache_info = ci;
84 return *this;
85 }
86
87 ROp(Obj& _source);
88
89 int stat(optional_yield y, const DoutPrefixProvider *dpp);
90 int read(const DoutPrefixProvider *dpp, int64_t ofs, int64_t end, bufferlist *pbl, optional_yield y);
91 int read(const DoutPrefixProvider *dpp, bufferlist *pbl, optional_yield y) {
92 return read(dpp, 0, -1, pbl, y);
93 }
94 int get_attr(const DoutPrefixProvider *dpp, const char *name, bufferlist *dest, optional_yield y);
95 };
96
97 struct WOp {
98 Obj& source;
99
100 RGWObjVersionTracker *objv_tracker{nullptr};
101 std::map<std::string, bufferlist> attrs;
102 ceph::real_time mtime;
103 ceph::real_time *pmtime{nullptr};
104 bool exclusive{false};
105
106 WOp& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) {
107 objv_tracker = _objv_tracker;
108 return *this;
109 }
110
111 WOp& set_attrs(std::map<std::string, bufferlist>& _attrs) {
112 attrs = _attrs;
113 return *this;
114 }
115
116 WOp& set_attrs(std::map<std::string, bufferlist>&& _attrs) {
117 attrs = _attrs;
118 return *this;
119 }
120
121 WOp& set_mtime(const ceph::real_time& _mtime) {
122 mtime = _mtime;
123 return *this;
124 }
125
126 WOp& set_pmtime(ceph::real_time *_pmtime) {
127 pmtime = _pmtime;
128 return *this;
129 }
130
131 WOp& set_exclusive(bool _exclusive = true) {
132 exclusive = _exclusive;
133 return *this;
134 }
135
136 WOp(Obj& _source) : source(_source) {}
137
138 int remove(const DoutPrefixProvider *dpp, optional_yield y);
139 int write(const DoutPrefixProvider *dpp, bufferlist& bl, optional_yield y);
140
141 int write_data(const DoutPrefixProvider *dpp, bufferlist& bl, optional_yield y); /* write data only */
142 int write_attrs(const DoutPrefixProvider *dpp, optional_yield y); /* write attrs only */
143 int write_attr(const DoutPrefixProvider *dpp, const char *name, bufferlist& bl,
144 optional_yield y); /* write attrs only */
145 };
146
147 struct OmapOp {
148 Obj& source;
149
150 bool must_exist{false};
151
152 OmapOp& set_must_exist(bool _must_exist = true) {
153 must_exist = _must_exist;
154 return *this;
155 }
156
157 OmapOp(Obj& _source) : source(_source) {}
158
159 int get_all(const DoutPrefixProvider *dpp, std::map<std::string, bufferlist> *m, optional_yield y);
160 int get_vals(const DoutPrefixProvider *dpp, const std::string& marker, uint64_t count,
161 std::map<std::string, bufferlist> *m,
162 bool *pmore, optional_yield y);
163 int set(const DoutPrefixProvider *dpp, const std::string& key, bufferlist& bl, optional_yield y);
164 int set(const DoutPrefixProvider *dpp, const std::map<std::string, bufferlist>& m, optional_yield y);
165 int del(const DoutPrefixProvider *dpp, const std::string& key, optional_yield y);
166 };
167
168 struct WNOp {
169 Obj& source;
170
171 WNOp(Obj& _source) : source(_source) {}
172
173 int notify(const DoutPrefixProvider *dpp, bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl,
174 optional_yield y);
175 };
176 ROp rop() {
177 return ROp(*this);
178 }
179
180 WOp wop() {
181 return WOp(*this);
182 }
183
184 OmapOp omap() {
185 return OmapOp(*this);
186 }
187
188 WNOp wn() {
189 return WNOp(*this);
190 }
191 };
192
193 class Pool {
194 friend class Op;
195 friend class RGWSI_SysObj_Core;
196
197 RGWSI_SysObj_Core *core_svc;
198 rgw_pool pool;
199
200 protected:
201 using ListImplInfo = RGWSI_SysObj_Pool_ListInfo;
202
203 struct ListCtx {
204 ceph::static_ptr<ListImplInfo, sizeof(RGWSI_SysObj_Core_PoolListImplInfo)> impl; /* update this if creating new backend types */
205 };
206
207 public:
208 Pool(RGWSI_SysObj_Core *_core_svc,
209 const rgw_pool& _pool) : core_svc(_core_svc),
210 pool(_pool) {}
211
212 rgw_pool& get_pool() {
213 return pool;
214 }
215
216 struct Op {
217 Pool& source;
218 ListCtx ctx;
219
220 Op(Pool& _source) : source(_source) {}
221
222 int init(const DoutPrefixProvider *dpp, const std::string& marker, const std::string& prefix);
223 int get_next(const DoutPrefixProvider *dpp, int max, std::vector<std::string> *oids, bool *is_truncated);
224 int get_marker(std::string *marker);
225 };
226
227 int list_prefixed_objs(const DoutPrefixProvider *dpp, const std::string& prefix, std::function<void(const std::string&)> cb);
228
229 template <typename Container>
230 int list_prefixed_objs(const DoutPrefixProvider *dpp, const std::string& prefix,
231 Container *result) {
232 return list_prefixed_objs(dpp, prefix, [&](const std::string& val) {
233 result->push_back(val);
234 });
235 }
236
237 Op op() {
238 return Op(*this);
239 }
240 };
241
242 friend class Obj;
243 friend class Obj::ROp;
244 friend class Obj::WOp;
245 friend class Pool;
246 friend class Pool::Op;
247
248 protected:
249 RGWSI_RADOS *rados_svc{nullptr};
250 RGWSI_SysObj_Core *core_svc{nullptr};
251
252 void init(RGWSI_RADOS *_rados_svc,
253 RGWSI_SysObj_Core *_core_svc) {
254 rados_svc = _rados_svc;
255 core_svc = _core_svc;
256 }
257
258 public:
259 RGWSI_SysObj(CephContext *cct): RGWServiceInstance(cct) {}
260
261 Obj get_obj(const rgw_raw_obj& obj);
262
263 Pool get_pool(const rgw_pool& pool) {
264 return Pool(core_svc, pool);
265 }
266
267 RGWSI_Zone *get_zone_svc();
268 };
269
270 using RGWSysObj = RGWSI_SysObj::Obj;