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