1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
#include "svc_rados.h"
#include "include/rados/librados.hpp"
#include "common/errno.h"
#include "osd/osd_types.h"
#include "rgw/rgw_tools.h"
#define dout_subsys ceph_subsys_rgw
int RGWSI_RADOS::do_start()
{
int ret = rados.init_with_context(cct);
if (ret < 0) {
return ret;
}
ret = rados.connect();
if (ret < 0) {
return ret;
}
return 0;
}
librados::Rados* RGWSI_RADOS::get_rados_handle()
{
return &rados;
}
uint64_t RGWSI_RADOS::instance_id()
{
return get_rados_handle()->get_instance_id();
}
int RGWSI_RADOS::open_pool_ctx(const rgw_pool& pool, librados::IoCtx& io_ctx)
{
constexpr bool create = true; // create the pool if it doesn't exist
return rgw_init_ioctx(get_rados_handle(), pool, io_ctx, create);
}
int RGWSI_RADOS::pool_iterate(librados::IoCtx& io_ctx,
librados::NObjectIterator& iter,
uint32_t num, vector<rgw_bucket_dir_entry>& objs,
RGWAccessListFilter *filter,
bool *is_truncated)
{
if (iter == io_ctx.nobjects_end())
return -ENOENT;
uint32_t i;
for (i = 0; i < num && iter != io_ctx.nobjects_end(); ++i, ++iter) {
rgw_bucket_dir_entry e;
string oid = iter->get_oid();
ldout(cct, 20) << "RGWRados::pool_iterate: got " << oid << dendl;
// fill it in with initial values; we may correct later
if (filter && !filter->filter(oid, oid))
continue;
e.key = oid;
objs.push_back(e);
}
if (is_truncated)
*is_truncated = (iter != io_ctx.nobjects_end());
return objs.size();
}
void RGWSI_RADOS::Obj::init(const rgw_raw_obj& obj)
{
ref.obj = obj;
}
int RGWSI_RADOS::Obj::open()
{
int r = rados_svc->open_pool_ctx(ref.obj.pool, ref.ioctx);
if (r < 0) {
return r;
}
ref.ioctx.locator_set_key(ref.obj.loc);
return 0;
}
int RGWSI_RADOS::Obj::operate(librados::ObjectWriteOperation *op,
optional_yield y)
{
return rgw_rados_operate(ref.ioctx, ref.obj.oid, op, y);
}
int RGWSI_RADOS::Obj::operate(librados::ObjectReadOperation *op, bufferlist *pbl,
optional_yield y)
{
return rgw_rados_operate(ref.ioctx, ref.obj.oid, op, pbl, y);
}
int RGWSI_RADOS::Obj::aio_operate(librados::AioCompletion *c, librados::ObjectWriteOperation *op)
{
return ref.ioctx.aio_operate(ref.obj.oid, c, op);
}
int RGWSI_RADOS::Obj::aio_operate(librados::AioCompletion *c, librados::ObjectReadOperation *op,
bufferlist *pbl)
{
return ref.ioctx.aio_operate(ref.obj.oid, c, op, pbl);
}
int RGWSI_RADOS::Obj::watch(uint64_t *handle, librados::WatchCtx2 *ctx)
{
return ref.ioctx.watch2(ref.obj.oid, handle, ctx);
}
int RGWSI_RADOS::Obj::aio_watch(librados::AioCompletion *c, uint64_t *handle, librados::WatchCtx2 *ctx)
{
return ref.ioctx.aio_watch(ref.obj.oid, c, handle, ctx);
}
int RGWSI_RADOS::Obj::unwatch(uint64_t handle)
{
return ref.ioctx.unwatch2(handle);
}
int RGWSI_RADOS::Obj::notify(bufferlist& bl,
uint64_t timeout_ms,
bufferlist *pbl)
{
return ref.ioctx.notify2(ref.obj.oid, bl, timeout_ms, pbl);
}
void RGWSI_RADOS::Obj::notify_ack(uint64_t notify_id,
uint64_t cookie,
bufferlist& bl)
{
ref.ioctx.notify_ack(ref.obj.oid, notify_id, cookie, bl);
}
uint64_t RGWSI_RADOS::Obj::get_last_version()
{
return ref.ioctx.get_last_version();
}
int RGWSI_RADOS::Pool::create()
{
librados::Rados *rad = rados_svc->get_rados_handle();
int r = rad->pool_create(pool.name.c_str());
if (r < 0) {
ldout(rados_svc->cct, 0) << "WARNING: pool_create returned " << r << dendl;
return r;
}
librados::IoCtx io_ctx;
r = rad->ioctx_create(pool.name.c_str(), io_ctx);
if (r < 0) {
ldout(rados_svc->cct, 0) << "WARNING: ioctx_create returned " << r << dendl;
return r;
}
r = io_ctx.application_enable(pg_pool_t::APPLICATION_NAME_RGW, false);
if (r < 0) {
ldout(rados_svc->cct, 0) << "WARNING: application_enable returned " << r << dendl;
return r;
}
return 0;
}
int RGWSI_RADOS::Pool::create(const vector<rgw_pool>& pools, vector<int> *retcodes)
{
vector<librados::PoolAsyncCompletion *> completions;
vector<int> rets;
librados::Rados *rad = rados_svc->get_rados_handle();
for (auto iter = pools.begin(); iter != pools.end(); ++iter) {
librados::PoolAsyncCompletion *c = librados::Rados::pool_async_create_completion();
completions.push_back(c);
auto& pool = *iter;
int ret = rad->pool_create_async(pool.name.c_str(), c);
rets.push_back(ret);
}
vector<int>::iterator riter;
vector<librados::PoolAsyncCompletion *>::iterator citer;
bool error = false;
ceph_assert(rets.size() == completions.size());
for (riter = rets.begin(), citer = completions.begin(); riter != rets.end(); ++riter, ++citer) {
int r = *riter;
librados::PoolAsyncCompletion *c = *citer;
if (r == 0) {
c->wait();
r = c->get_return_value();
if (r < 0) {
ldout(rados_svc->cct, 0) << "WARNING: async pool_create returned " << r << dendl;
error = true;
}
}
c->release();
retcodes->push_back(r);
}
if (error) {
return 0;
}
std::vector<librados::IoCtx> io_ctxs;
retcodes->clear();
for (auto pool : pools) {
io_ctxs.emplace_back();
int ret = rad->ioctx_create(pool.name.c_str(), io_ctxs.back());
if (ret < 0) {
ldout(rados_svc->cct, 0) << "WARNING: ioctx_create returned " << ret << dendl;
error = true;
}
retcodes->push_back(ret);
}
if (error) {
return 0;
}
completions.clear();
for (auto &io_ctx : io_ctxs) {
librados::PoolAsyncCompletion *c =
librados::Rados::pool_async_create_completion();
completions.push_back(c);
int ret = io_ctx.application_enable_async(pg_pool_t::APPLICATION_NAME_RGW,
false, c);
ceph_assert(ret == 0);
}
retcodes->clear();
for (auto c : completions) {
c->wait();
int ret = c->get_return_value();
if (ret == -EOPNOTSUPP) {
ret = 0;
} else if (ret < 0) {
ldout(rados_svc->cct, 0) << "WARNING: async application_enable returned " << ret
<< dendl;
error = true;
}
c->release();
retcodes->push_back(ret);
}
return 0;
}
int RGWSI_RADOS::Pool::lookup()
{
librados::Rados *rad = rados_svc->get_rados_handle();
int ret = rad->pool_lookup(pool.name.c_str());
if (ret < 0) {
return ret;
}
return 0;
}
int RGWSI_RADOS::Pool::List::init(const string& marker, RGWAccessListFilter *filter)
{
if (ctx.initialized) {
return -EINVAL;
}
int r = pool.rados_svc->open_pool_ctx(pool.pool, ctx.ioctx);
if (r < 0) {
return r;
}
librados::ObjectCursor oc;
if (!oc.from_str(marker)) {
ldout(pool.rados_svc->cct, 10) << "failed to parse cursor: " << marker << dendl;
return -EINVAL;
}
ctx.iter = ctx.ioctx.nobjects_begin(oc);
ctx.filter = filter;
ctx.initialized = true;
return 0;
}
int RGWSI_RADOS::Pool::List::get_next(int max,
std::list<string> *oids,
bool *is_truncated)
{
if (!ctx.initialized) {
return -EINVAL;
}
vector<rgw_bucket_dir_entry> objs;
int r = pool.rados_svc->pool_iterate(ctx.ioctx, ctx.iter, max, objs, ctx.filter, is_truncated);
if (r < 0) {
if(r != -ENOENT) {
ldout(pool.rados_svc->cct, 10) << "failed to list objects pool_iterate returned r=" << r << dendl;
}
return r;
}
vector<rgw_bucket_dir_entry>::iterator iter;
for (auto& o : objs) {
oids->push_back(o.key.name);
}
return oids->size();
}
int RGWSI_RADOS::Handle::watch_flush()
{
librados::Rados *rad = rados_svc->get_rados_handle();
return rad->watch_flush();
}
|