]>
Commit | Line | Data |
---|---|---|
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 | 4 | #pragma once |
11fdf7f2 TL |
5 | |
6 | #include "rgw/rgw_service.h" | |
7 | ||
8 | #include "include/rados/librados.hpp" | |
9 | #include "common/async/yield_context.h" | |
9f95a23c TL |
10 | #include "common/RWLock.h" |
11 | ||
12 | class RGWAsyncRadosProcessor; | |
11fdf7f2 TL |
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 | ||
11fdf7f2 TL |
29 | class RGWSI_RADOS : public RGWServiceInstance |
30 | { | |
494da23a | 31 | librados::Rados rados; |
9f95a23c | 32 | std::unique_ptr<RGWAsyncRadosProcessor> async_processor; |
11fdf7f2 | 33 | |
f67539c2 | 34 | int do_start(optional_yield) override; |
11fdf7f2 | 35 | |
9f95a23c TL |
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: | |
9f95a23c TL |
54 | int open_pool_ctx(const rgw_pool& pool, librados::IoCtx& io_ctx, |
55 | const OpenParams& params = {}); | |
11fdf7f2 TL |
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: | |
9f95a23c TL |
63 | RGWSI_RADOS(CephContext *cct); |
64 | ~RGWSI_RADOS(); | |
f67539c2 | 65 | librados::Rados* get_rados_handle(); |
11fdf7f2 TL |
66 | |
67 | void init() {} | |
9f95a23c | 68 | void shutdown() override; |
11fdf7f2 TL |
69 | |
70 | uint64_t instance_id(); | |
9f95a23c | 71 | bool check_secure_mon_conn() const; |
11fdf7f2 | 72 | |
9f95a23c TL |
73 | RGWAsyncRadosProcessor *get_async_processor() { |
74 | return async_processor.get(); | |
75 | } | |
11fdf7f2 | 76 | |
9f95a23c | 77 | int clog_warn(const string& msg); |
11fdf7f2 | 78 | |
9f95a23c | 79 | class Handle; |
11fdf7f2 TL |
80 | |
81 | class Pool { | |
82 | friend class RGWSI_RADOS; | |
494da23a | 83 | friend Handle; |
9f95a23c | 84 | friend class Obj; |
11fdf7f2 TL |
85 | |
86 | RGWSI_RADOS *rados_svc{nullptr}; | |
11fdf7f2 TL |
87 | rgw_pool pool; |
88 | ||
9f95a23c TL |
89 | struct State { |
90 | librados::IoCtx ioctx; | |
91 | } state; | |
92 | ||
11fdf7f2 | 93 | Pool(RGWSI_RADOS *_rados_svc, |
494da23a TL |
94 | const rgw_pool& _pool) : rados_svc(_rados_svc), |
95 | pool(_pool) {} | |
11fdf7f2 TL |
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(); | |
9f95a23c TL |
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 | } | |
11fdf7f2 TL |
113 | |
114 | struct List { | |
9f95a23c | 115 | Pool *pool{nullptr}; |
11fdf7f2 TL |
116 | |
117 | struct Ctx { | |
118 | bool initialized{false}; | |
119 | librados::IoCtx ioctx; | |
120 | librados::NObjectIterator iter; | |
121 | RGWAccessListFilter *filter{nullptr}; | |
122 | } ctx; | |
123 | ||
9f95a23c TL |
124 | List() {} |
125 | List(Pool *_pool) : pool(_pool) {} | |
11fdf7f2 TL |
126 | |
127 | int init(const string& marker, RGWAccessListFilter *filter = nullptr); | |
128 | int get_next(int max, | |
9f95a23c | 129 | std::vector<string> *oids, |
11fdf7f2 | 130 | bool *is_truncated); |
9f95a23c TL |
131 | |
132 | int get_marker(string *marker); | |
11fdf7f2 TL |
133 | }; |
134 | ||
135 | List op() { | |
9f95a23c | 136 | return List(this); |
11fdf7f2 TL |
137 | } |
138 | ||
494da23a | 139 | friend List; |
11fdf7f2 TL |
140 | }; |
141 | ||
9f95a23c TL |
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 | ||
f6b5b4d7 TL |
169 | int operate(librados::ObjectWriteOperation *op, optional_yield y, |
170 | int flags = 0); | |
9f95a23c | 171 | int operate(librados::ObjectReadOperation *op, bufferlist *pbl, |
f6b5b4d7 | 172 | optional_yield y, int flags = 0); |
9f95a23c TL |
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 | ||
11fdf7f2 TL |
196 | class Handle { |
197 | friend class RGWSI_RADOS; | |
198 | ||
199 | RGWSI_RADOS *rados_svc{nullptr}; | |
11fdf7f2 | 200 | |
494da23a | 201 | Handle(RGWSI_RADOS *_rados_svc) : rados_svc(_rados_svc) {} |
11fdf7f2 | 202 | public: |
9f95a23c | 203 | Obj obj(const rgw_raw_obj& o); |
11fdf7f2 TL |
204 | |
205 | Pool pool(const rgw_pool& p) { | |
494da23a | 206 | return Pool(rados_svc, p); |
11fdf7f2 TL |
207 | } |
208 | ||
209 | int watch_flush(); | |
9f95a23c TL |
210 | |
211 | int mon_command(std::string cmd, | |
212 | const bufferlist& inbl, | |
213 | bufferlist *outbl, | |
214 | std::string *outs); | |
11fdf7f2 TL |
215 | }; |
216 | ||
494da23a TL |
217 | Handle handle() { |
218 | return Handle(this); | |
11fdf7f2 TL |
219 | } |
220 | ||
221 | Obj obj(const rgw_raw_obj& o) { | |
494da23a | 222 | return Obj(this, o); |
11fdf7f2 TL |
223 | } |
224 | ||
9f95a23c TL |
225 | Obj obj(Pool& pool, const string& oid) { |
226 | return Obj(pool, oid); | |
227 | } | |
228 | ||
11fdf7f2 TL |
229 | Pool pool() { |
230 | return Pool(this); | |
231 | } | |
232 | ||
233 | Pool pool(const rgw_pool& p) { | |
494da23a | 234 | return Pool(this, p); |
11fdf7f2 TL |
235 | } |
236 | ||
494da23a TL |
237 | friend Obj; |
238 | friend Pool; | |
239 | friend Pool::List; | |
11fdf7f2 TL |
240 | }; |
241 | ||
9f95a23c TL |
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 | } |