]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/services/svc_rados.h
b09cd6d73a9756117dbd88aa43b5107522dda1de
[ceph.git] / ceph / src / rgw / services / svc_rados.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 "rgw/rgw_service.h"
7
8 #include "include/rados/librados.hpp"
9 #include "common/async/yield_context.h"
10 #include "common/RWLock.h"
11
12 class RGWAsyncRadosProcessor;
13
14 class RGWAccessListFilter {
15 public:
16 virtual ~RGWAccessListFilter() {}
17 virtual bool filter(const string& name, string& key) = 0;
18 };
19
20 struct RGWAccessListFilterPrefix : public RGWAccessListFilter {
21 string prefix;
22
23 explicit RGWAccessListFilterPrefix(const string& _prefix) : prefix(_prefix) {}
24 bool filter(const string& name, string& key) override {
25 return (prefix.compare(key.substr(0, prefix.size())) == 0);
26 }
27 };
28
29 class RGWSI_RADOS : public RGWServiceInstance
30 {
31 librados::Rados rados;
32 std::unique_ptr<RGWAsyncRadosProcessor> async_processor;
33
34 int do_start(optional_yield) override;
35
36 public:
37 struct OpenParams {
38 bool create{true};
39 bool mostly_omap{false};
40
41 OpenParams() {}
42
43 OpenParams& set_create(bool _create) {
44 create = _create;
45 return *this;
46 }
47 OpenParams& set_mostly_omap(bool _mostly_omap) {
48 mostly_omap = _mostly_omap;
49 return *this;
50 }
51 };
52
53 private:
54 int open_pool_ctx(const rgw_pool& pool, librados::IoCtx& io_ctx,
55 const OpenParams& params = {});
56 int pool_iterate(librados::IoCtx& ioctx,
57 librados::NObjectIterator& iter,
58 uint32_t num, vector<rgw_bucket_dir_entry>& objs,
59 RGWAccessListFilter *filter,
60 bool *is_truncated);
61
62 public:
63 RGWSI_RADOS(CephContext *cct);
64 ~RGWSI_RADOS();
65 librados::Rados* get_rados_handle();
66
67 void init() {}
68 void shutdown() override;
69
70 uint64_t instance_id();
71 bool check_secure_mon_conn() const;
72
73 RGWAsyncRadosProcessor *get_async_processor() {
74 return async_processor.get();
75 }
76
77 int clog_warn(const string& msg);
78
79 class Handle;
80
81 class Pool {
82 friend class RGWSI_RADOS;
83 friend Handle;
84 friend class Obj;
85
86 RGWSI_RADOS *rados_svc{nullptr};
87 rgw_pool pool;
88
89 struct State {
90 librados::IoCtx ioctx;
91 } state;
92
93 Pool(RGWSI_RADOS *_rados_svc,
94 const rgw_pool& _pool) : rados_svc(_rados_svc),
95 pool(_pool) {}
96
97 Pool(RGWSI_RADOS *_rados_svc) : rados_svc(_rados_svc) {}
98 public:
99 Pool() {}
100
101 int create();
102 int create(const std::vector<rgw_pool>& pools, std::vector<int> *retcodes);
103 int lookup();
104 int open(const OpenParams& params = {});
105
106 const rgw_pool& get_pool() {
107 return pool;
108 }
109
110 librados::IoCtx& ioctx() {
111 return state.ioctx;
112 }
113
114 struct List {
115 Pool *pool{nullptr};
116
117 struct Ctx {
118 bool initialized{false};
119 librados::IoCtx ioctx;
120 librados::NObjectIterator iter;
121 RGWAccessListFilter *filter{nullptr};
122 } ctx;
123
124 List() {}
125 List(Pool *_pool) : pool(_pool) {}
126
127 int init(const string& marker, RGWAccessListFilter *filter = nullptr);
128 int get_next(int max,
129 std::vector<string> *oids,
130 bool *is_truncated);
131
132 int get_marker(string *marker);
133 };
134
135 List op() {
136 return List(this);
137 }
138
139 friend List;
140 };
141
142
143 struct rados_ref {
144 RGWSI_RADOS::Pool pool;
145 rgw_raw_obj obj;
146 };
147
148 class Obj {
149 friend class RGWSI_RADOS;
150 friend class Handle;
151
152 RGWSI_RADOS *rados_svc{nullptr};
153 rados_ref ref;
154
155 void init(const rgw_raw_obj& obj);
156
157 Obj(RGWSI_RADOS *_rados_svc, const rgw_raw_obj& _obj)
158 : rados_svc(_rados_svc) {
159 init(_obj);
160 }
161
162 Obj(Pool& pool, const string& oid);
163
164 public:
165 Obj() {}
166
167 int open();
168
169 int operate(librados::ObjectWriteOperation *op, optional_yield y,
170 int flags = 0);
171 int operate(librados::ObjectReadOperation *op, bufferlist *pbl,
172 optional_yield y, int flags = 0);
173 int aio_operate(librados::AioCompletion *c, librados::ObjectWriteOperation *op);
174 int aio_operate(librados::AioCompletion *c, librados::ObjectReadOperation *op,
175 bufferlist *pbl);
176
177 int watch(uint64_t *handle, librados::WatchCtx2 *ctx);
178 int aio_watch(librados::AioCompletion *c, uint64_t *handle, librados::WatchCtx2 *ctx);
179 int unwatch(uint64_t handle);
180 int notify(bufferlist& bl, uint64_t timeout_ms,
181 bufferlist *pbl, optional_yield y);
182 void notify_ack(uint64_t notify_id,
183 uint64_t cookie,
184 bufferlist& bl);
185
186 uint64_t get_last_version();
187
188 rados_ref& get_ref() { return ref; }
189 const rados_ref& get_ref() const { return ref; }
190
191 const rgw_raw_obj& get_raw_obj() const {
192 return ref.obj;
193 }
194 };
195
196 class Handle {
197 friend class RGWSI_RADOS;
198
199 RGWSI_RADOS *rados_svc{nullptr};
200
201 Handle(RGWSI_RADOS *_rados_svc) : rados_svc(_rados_svc) {}
202 public:
203 Obj obj(const rgw_raw_obj& o);
204
205 Pool pool(const rgw_pool& p) {
206 return Pool(rados_svc, p);
207 }
208
209 int watch_flush();
210
211 int mon_command(std::string cmd,
212 const bufferlist& inbl,
213 bufferlist *outbl,
214 std::string *outs);
215 };
216
217 Handle handle() {
218 return Handle(this);
219 }
220
221 Obj obj(const rgw_raw_obj& o) {
222 return Obj(this, o);
223 }
224
225 Obj obj(Pool& pool, const string& oid) {
226 return Obj(pool, oid);
227 }
228
229 Pool pool() {
230 return Pool(this);
231 }
232
233 Pool pool(const rgw_pool& p) {
234 return Pool(this, p);
235 }
236
237 friend Obj;
238 friend Pool;
239 friend Pool::List;
240 };
241
242 using rgw_rados_ref = RGWSI_RADOS::rados_ref;
243
244 inline ostream& operator<<(ostream& out, const RGWSI_RADOS::Obj& obj) {
245 return out << obj.get_raw_obj();
246 }