]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_cr_rados.h
buildsys: change download over to reef release
[ceph.git] / ceph / src / rgw / rgw_cr_rados.h
CommitLineData
11fdf7f2 1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
9f95a23c 2// vim: ts=8 sw=2 smarttab ft=cpp
11fdf7f2 3
7c673cae
FG
4#ifndef CEPH_RGW_CR_RADOS_H
5#define CEPH_RGW_CR_RADOS_H
6
7#include <boost/intrusive_ptr.hpp>
11fdf7f2 8#include "include/ceph_assert.h"
7c673cae 9#include "rgw_coroutine.h"
9f95a23c 10#include "rgw_sal.h"
f67539c2 11#include "rgw_sal_rados.h"
7c673cae
FG
12#include "common/WorkQueue.h"
13#include "common/Throttle.h"
14
15#include <atomic>
16
11fdf7f2 17#include "services/svc_sys_obj.h"
9f95a23c 18#include "services/svc_bucket.h"
11fdf7f2 19
b3b6e05e
TL
20#define dout_subsys ceph_subsys_rgw
21
7c673cae
FG
22class RGWAsyncRadosRequest : public RefCountedObject {
23 RGWCoroutine *caller;
24 RGWAioCompletionNotifier *notifier;
25
26 int retcode;
27
9f95a23c 28 ceph::mutex lock = ceph::make_mutex("RGWAsyncRadosRequest::lock");
7c673cae
FG
29
30protected:
b3b6e05e 31 virtual int _send_request(const DoutPrefixProvider *dpp) = 0;
7c673cae 32public:
9f95a23c
TL
33 RGWAsyncRadosRequest(RGWCoroutine *_caller, RGWAioCompletionNotifier *_cn)
34 : caller(_caller), notifier(_cn), retcode(0) {
7c673cae
FG
35 }
36 ~RGWAsyncRadosRequest() override {
37 if (notifier) {
38 notifier->put();
39 }
40 }
41
b3b6e05e 42 void send_request(const DoutPrefixProvider *dpp) {
7c673cae 43 get();
b3b6e05e 44 retcode = _send_request(dpp);
7c673cae 45 {
9f95a23c 46 std::lock_guard l{lock};
7c673cae
FG
47 if (notifier) {
48 notifier->cb(); // drops its own ref
49 notifier = nullptr;
50 }
51 }
52 put();
53 }
54
55 int get_ret_status() { return retcode; }
56
57 void finish() {
58 {
9f95a23c 59 std::lock_guard l{lock};
7c673cae
FG
60 if (notifier) {
61 // we won't call notifier->cb() to drop its ref, so drop it here
62 notifier->put();
63 notifier = nullptr;
64 }
65 }
66 put();
67 }
68};
69
70
71class RGWAsyncRadosProcessor {
20effc67 72 std::deque<RGWAsyncRadosRequest *> m_req_queue;
7c673cae
FG
73 std::atomic<bool> going_down = { false };
74protected:
9f95a23c 75 CephContext *cct;
7c673cae
FG
76 ThreadPool m_tp;
77 Throttle req_throttle;
78
b3b6e05e 79 struct RGWWQ : public DoutPrefixProvider, public ThreadPool::WorkQueue<RGWAsyncRadosRequest> {
7c673cae 80 RGWAsyncRadosProcessor *processor;
f67539c2
TL
81 RGWWQ(RGWAsyncRadosProcessor *p,
82 ceph::timespan timeout, ceph::timespan suicide_timeout,
83 ThreadPool *tp)
7c673cae
FG
84 : ThreadPool::WorkQueue<RGWAsyncRadosRequest>("RGWWQ", timeout, suicide_timeout, tp), processor(p) {}
85
86 bool _enqueue(RGWAsyncRadosRequest *req) override;
87 void _dequeue(RGWAsyncRadosRequest *req) override {
88 ceph_abort();
89 }
90 bool _empty() override;
91 RGWAsyncRadosRequest *_dequeue() override;
92 using ThreadPool::WorkQueue<RGWAsyncRadosRequest>::_process;
93 void _process(RGWAsyncRadosRequest *req, ThreadPool::TPHandle& handle) override;
94 void _dump_queue();
95 void _clear() override {
11fdf7f2 96 ceph_assert(processor->m_req_queue.empty());
7c673cae 97 }
b3b6e05e
TL
98
99 CephContext *get_cct() const { return processor->cct; }
100 unsigned get_subsys() const { return ceph_subsys_rgw; }
101 std::ostream& gen_prefix(std::ostream& out) const { return out << "rgw async rados processor: ";}
102
7c673cae
FG
103 } req_wq;
104
105public:
9f95a23c 106 RGWAsyncRadosProcessor(CephContext *_cct, int num_threads);
7c673cae
FG
107 ~RGWAsyncRadosProcessor() {}
108 void start();
109 void stop();
b3b6e05e 110 void handle_request(const DoutPrefixProvider *dpp, RGWAsyncRadosRequest *req);
7c673cae
FG
111 void queue(RGWAsyncRadosRequest *req);
112
113 bool is_going_down() {
114 return going_down;
115 }
b3b6e05e 116
7c673cae
FG
117};
118
11fdf7f2
TL
119template <class P>
120class RGWSimpleWriteOnlyAsyncCR : public RGWSimpleCoroutine {
121 RGWAsyncRadosProcessor *async_rados;
20effc67 122 rgw::sal::RadosStore* store;
11fdf7f2
TL
123
124 P params;
9f95a23c 125 const DoutPrefixProvider *dpp;
11fdf7f2
TL
126
127 class Request : public RGWAsyncRadosRequest {
20effc67 128 rgw::sal::RadosStore* store;
11fdf7f2 129 P params;
9f95a23c 130 const DoutPrefixProvider *dpp;
11fdf7f2 131 protected:
b3b6e05e 132 int _send_request(const DoutPrefixProvider *dpp) override;
11fdf7f2
TL
133 public:
134 Request(RGWCoroutine *caller,
135 RGWAioCompletionNotifier *cn,
20effc67 136 rgw::sal::RadosStore* store,
9f95a23c
TL
137 const P& _params,
138 const DoutPrefixProvider *dpp) : RGWAsyncRadosRequest(caller, cn),
11fdf7f2 139 store(store),
9f95a23c
TL
140 params(_params),
141 dpp(dpp) {}
11fdf7f2 142 } *req{nullptr};
7c673cae 143
11fdf7f2
TL
144 public:
145 RGWSimpleWriteOnlyAsyncCR(RGWAsyncRadosProcessor *_async_rados,
20effc67 146 rgw::sal::RadosStore* _store,
9f95a23c
TL
147 const P& _params,
148 const DoutPrefixProvider *_dpp) : RGWSimpleCoroutine(_store->ctx()),
11fdf7f2
TL
149 async_rados(_async_rados),
150 store(_store),
9f95a23c
TL
151 params(_params),
152 dpp(_dpp) {}
11fdf7f2
TL
153
154 ~RGWSimpleWriteOnlyAsyncCR() override {
155 request_cleanup();
156 }
157 void request_cleanup() override {
158 if (req) {
159 req->finish();
160 req = NULL;
161 }
162 }
163
b3b6e05e 164 int send_request(const DoutPrefixProvider *dpp) override {
11fdf7f2
TL
165 req = new Request(this,
166 stack->create_completion_notifier(),
167 store,
9f95a23c
TL
168 params,
169 dpp);
11fdf7f2
TL
170
171 async_rados->queue(req);
172 return 0;
173 }
174 int request_complete() override {
175 return req->get_ret_status();
176 }
177};
178
179
180template <class P, class R>
181class RGWSimpleAsyncCR : public RGWSimpleCoroutine {
182 RGWAsyncRadosProcessor *async_rados;
20effc67 183 rgw::sal::RadosStore* store;
11fdf7f2
TL
184
185 P params;
186 std::shared_ptr<R> result;
b3b6e05e 187 const DoutPrefixProvider *dpp;
11fdf7f2
TL
188
189 class Request : public RGWAsyncRadosRequest {
20effc67 190 rgw::sal::RadosStore* store;
11fdf7f2
TL
191 P params;
192 std::shared_ptr<R> result;
b3b6e05e 193 const DoutPrefixProvider *dpp;
11fdf7f2 194 protected:
b3b6e05e 195 int _send_request(const DoutPrefixProvider *dpp) override;
11fdf7f2 196 public:
b3b6e05e
TL
197 Request(const DoutPrefixProvider *dpp,
198 RGWCoroutine *caller,
11fdf7f2 199 RGWAioCompletionNotifier *cn,
20effc67 200 rgw::sal::RadosStore* _store,
11fdf7f2 201 const P& _params,
b3b6e05e
TL
202 std::shared_ptr<R>& _result,
203 const DoutPrefixProvider *_dpp) : RGWAsyncRadosRequest(caller, cn),
11fdf7f2
TL
204 store(_store),
205 params(_params),
b3b6e05e
TL
206 result(_result),
207 dpp(_dpp) {}
11fdf7f2
TL
208 } *req{nullptr};
209
210 public:
211 RGWSimpleAsyncCR(RGWAsyncRadosProcessor *_async_rados,
20effc67 212 rgw::sal::RadosStore* _store,
11fdf7f2 213 const P& _params,
b3b6e05e
TL
214 std::shared_ptr<R>& _result,
215 const DoutPrefixProvider *_dpp) : RGWSimpleCoroutine(_store->ctx()),
11fdf7f2
TL
216 async_rados(_async_rados),
217 store(_store),
218 params(_params),
b3b6e05e
TL
219 result(_result),
220 dpp(_dpp) {}
11fdf7f2
TL
221
222 ~RGWSimpleAsyncCR() override {
223 request_cleanup();
224 }
225 void request_cleanup() override {
226 if (req) {
227 req->finish();
228 req = NULL;
229 }
230 }
231
b3b6e05e
TL
232 int send_request(const DoutPrefixProvider *dpp) override {
233 req = new Request(dpp,
234 this,
11fdf7f2
TL
235 stack->create_completion_notifier(),
236 store,
237 params,
b3b6e05e
TL
238 result,
239 dpp);
11fdf7f2
TL
240
241 async_rados->queue(req);
242 return 0;
243 }
244 int request_complete() override {
245 return req->get_ret_status();
246 }
247};
248
9f95a23c
TL
249class RGWGenericAsyncCR : public RGWSimpleCoroutine {
250 RGWAsyncRadosProcessor *async_rados;
20effc67 251 rgw::sal::RadosStore* store;
9f95a23c
TL
252
253
254public:
255 class Action {
256 public:
257 virtual ~Action() {}
258 virtual int operate() = 0;
259 };
260
261private:
262 std::shared_ptr<Action> action;
263
264 class Request : public RGWAsyncRadosRequest {
265 std::shared_ptr<Action> action;
266 protected:
b3b6e05e 267 int _send_request(const DoutPrefixProvider *dpp) override {
9f95a23c
TL
268 if (!action) {
269 return 0;
270 }
271 return action->operate();
272 }
273 public:
b3b6e05e
TL
274 Request(const DoutPrefixProvider *dpp,
275 RGWCoroutine *caller,
9f95a23c
TL
276 RGWAioCompletionNotifier *cn,
277 std::shared_ptr<Action>& _action) : RGWAsyncRadosRequest(caller, cn),
278 action(_action) {}
279 } *req{nullptr};
280
281 public:
282 RGWGenericAsyncCR(CephContext *_cct,
283 RGWAsyncRadosProcessor *_async_rados,
284 std::shared_ptr<Action>& _action) : RGWSimpleCoroutine(_cct),
285 async_rados(_async_rados),
286 action(_action) {}
287 template<typename T>
288 RGWGenericAsyncCR(CephContext *_cct,
289 RGWAsyncRadosProcessor *_async_rados,
290 std::shared_ptr<T>& _action) : RGWSimpleCoroutine(_cct),
291 async_rados(_async_rados),
292 action(std::static_pointer_cast<Action>(_action)) {}
293
294 ~RGWGenericAsyncCR() override {
295 request_cleanup();
296 }
297 void request_cleanup() override {
298 if (req) {
299 req->finish();
300 req = NULL;
301 }
302 }
303
b3b6e05e
TL
304 int send_request(const DoutPrefixProvider *dpp) override {
305 req = new Request(dpp, this,
9f95a23c
TL
306 stack->create_completion_notifier(),
307 action);
308
309 async_rados->queue(req);
310 return 0;
311 }
312 int request_complete() override {
313 return req->get_ret_status();
314 }
315};
316
11fdf7f2
TL
317
318class RGWAsyncGetSystemObj : public RGWAsyncRadosRequest {
b3b6e05e 319 const DoutPrefixProvider *dpp;
11fdf7f2 320 RGWSysObjectCtx obj_ctx;
7c673cae 321 rgw_raw_obj obj;
91327a77 322 const bool want_attrs;
11fdf7f2 323 const bool raw_attrs;
7c673cae 324protected:
b3b6e05e 325 int _send_request(const DoutPrefixProvider *dpp) override;
7c673cae 326public:
b3b6e05e
TL
327 RGWAsyncGetSystemObj(const DoutPrefixProvider *dpp,
328 RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWSI_SysObj *_svc,
7c673cae 329 RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj,
11fdf7f2 330 bool want_attrs, bool raw_attrs);
91327a77
AA
331
332 bufferlist bl;
20effc67 333 std::map<std::string, bufferlist> attrs;
f67539c2 334 RGWObjVersionTracker objv_tracker;
7c673cae
FG
335};
336
337class RGWAsyncPutSystemObj : public RGWAsyncRadosRequest {
b3b6e05e 338 const DoutPrefixProvider *dpp;
11fdf7f2 339 RGWSI_SysObj *svc;
7c673cae
FG
340 rgw_raw_obj obj;
341 bool exclusive;
342 bufferlist bl;
343
344protected:
b3b6e05e 345 int _send_request(const DoutPrefixProvider *dpp) override;
7c673cae 346public:
b3b6e05e
TL
347 RGWAsyncPutSystemObj(const DoutPrefixProvider *dpp, RGWCoroutine *caller,
348 RGWAioCompletionNotifier *cn, RGWSI_SysObj *_svc,
91327a77
AA
349 RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj,
350 bool _exclusive, bufferlist _bl);
351
352 RGWObjVersionTracker objv_tracker;
7c673cae
FG
353};
354
355class RGWAsyncPutSystemObjAttrs : public RGWAsyncRadosRequest {
b3b6e05e 356 const DoutPrefixProvider *dpp;
11fdf7f2 357 RGWSI_SysObj *svc;
7c673cae 358 rgw_raw_obj obj;
20effc67 359 std::map<std::string, bufferlist> attrs;
7c673cae
FG
360
361protected:
b3b6e05e 362 int _send_request(const DoutPrefixProvider *dpp) override;
7c673cae 363public:
b3b6e05e 364 RGWAsyncPutSystemObjAttrs(const DoutPrefixProvider *dpp, RGWCoroutine *caller, RGWAioCompletionNotifier *cn, RGWSI_SysObj *_svc,
7c673cae 365 RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj,
20effc67 366 std::map<std::string, bufferlist> _attrs);
91327a77
AA
367
368 RGWObjVersionTracker objv_tracker;
7c673cae
FG
369};
370
371class RGWAsyncLockSystemObj : public RGWAsyncRadosRequest {
20effc67 372 rgw::sal::RadosStore* store;
7c673cae 373 rgw_raw_obj obj;
20effc67
TL
374 std::string lock_name;
375 std::string cookie;
7c673cae
FG
376 uint32_t duration_secs;
377
378protected:
b3b6e05e 379 int _send_request(const DoutPrefixProvider *dpp) override;
7c673cae 380public:
20effc67 381 RGWAsyncLockSystemObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, rgw::sal::RadosStore* _store,
7c673cae 382 RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj,
20effc67 383 const std::string& _name, const std::string& _cookie, uint32_t _duration_secs);
7c673cae
FG
384};
385
386class RGWAsyncUnlockSystemObj : public RGWAsyncRadosRequest {
20effc67 387 rgw::sal::RadosStore* store;
7c673cae 388 rgw_raw_obj obj;
20effc67
TL
389 std::string lock_name;
390 std::string cookie;
7c673cae
FG
391
392protected:
b3b6e05e 393 int _send_request(const DoutPrefixProvider *dpp) override;
7c673cae 394public:
20effc67 395 RGWAsyncUnlockSystemObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, rgw::sal::RadosStore* _store,
7c673cae 396 RGWObjVersionTracker *_objv_tracker, const rgw_raw_obj& _obj,
20effc67 397 const std::string& _name, const std::string& _cookie);
7c673cae
FG
398};
399
7c673cae
FG
400template <class T>
401class RGWSimpleRadosReadCR : public RGWSimpleCoroutine {
b3b6e05e 402 const DoutPrefixProvider *dpp;
7c673cae 403 RGWAsyncRadosProcessor *async_rados;
11fdf7f2
TL
404 RGWSI_SysObj *svc;
405
7c673cae 406 rgw_raw_obj obj;
7c673cae
FG
407 T *result;
408 /// on ENOENT, call handle_data() with an empty object instead of failing
409 const bool empty_on_enoent;
410 RGWObjVersionTracker *objv_tracker;
7c673cae
FG
411 RGWAsyncGetSystemObj *req{nullptr};
412
413public:
b3b6e05e
TL
414 RGWSimpleRadosReadCR(const DoutPrefixProvider *_dpp,
415 RGWAsyncRadosProcessor *_async_rados, RGWSI_SysObj *_svc,
7c673cae
FG
416 const rgw_raw_obj& _obj,
417 T *_result, bool empty_on_enoent = true,
418 RGWObjVersionTracker *objv_tracker = nullptr)
b3b6e05e 419 : RGWSimpleCoroutine(_svc->ctx()), dpp(_dpp), async_rados(_async_rados), svc(_svc),
91327a77 420 obj(_obj), result(_result),
7c673cae
FG
421 empty_on_enoent(empty_on_enoent), objv_tracker(objv_tracker) {}
422 ~RGWSimpleRadosReadCR() override {
423 request_cleanup();
424 }
425
426 void request_cleanup() override {
427 if (req) {
428 req->finish();
429 req = NULL;
430 }
431 }
432
b3b6e05e 433 int send_request(const DoutPrefixProvider *dpp) override;
7c673cae
FG
434 int request_complete() override;
435
436 virtual int handle_data(T& data) {
437 return 0;
438 }
439};
440
441template <class T>
b3b6e05e 442int RGWSimpleRadosReadCR<T>::send_request(const DoutPrefixProvider *dpp)
7c673cae 443{
b3b6e05e 444 req = new RGWAsyncGetSystemObj(dpp, this, stack->create_completion_notifier(), svc,
11fdf7f2 445 objv_tracker, obj, false, false);
7c673cae
FG
446 async_rados->queue(req);
447 return 0;
448}
449
450template <class T>
451int RGWSimpleRadosReadCR<T>::request_complete()
452{
453 int ret = req->get_ret_status();
454 retcode = ret;
455 if (ret == -ENOENT && empty_on_enoent) {
456 *result = T();
457 } else {
458 if (ret < 0) {
459 return ret;
460 }
461 try {
11fdf7f2 462 auto iter = req->bl.cbegin();
7c673cae
FG
463 if (iter.end()) {
464 // allow successful reads with empty buffers. ReadSyncStatus coroutines
465 // depend on this to be able to read without locking, because the
11fdf7f2 466 // cls lock from InitSyncStatus will create an empty object if it didn't
7c673cae
FG
467 // exist
468 *result = T();
469 } else {
11fdf7f2 470 decode(*result, iter);
7c673cae
FG
471 }
472 } catch (buffer::error& err) {
473 return -EIO;
474 }
475 }
476
477 return handle_data(*result);
478}
479
480class RGWSimpleRadosReadAttrsCR : public RGWSimpleCoroutine {
b3b6e05e 481 const DoutPrefixProvider *dpp;
7c673cae 482 RGWAsyncRadosProcessor *async_rados;
11fdf7f2
TL
483 RGWSI_SysObj *svc;
484
7c673cae 485 rgw_raw_obj obj;
20effc67 486 std::map<std::string, bufferlist> *pattrs;
11fdf7f2 487 bool raw_attrs;
f67539c2
TL
488 RGWObjVersionTracker* objv_tracker;
489 RGWAsyncGetSystemObj *req = nullptr;
7c673cae
FG
490
491public:
b3b6e05e 492 RGWSimpleRadosReadAttrsCR(const DoutPrefixProvider *_dpp, RGWAsyncRadosProcessor *_async_rados, RGWSI_SysObj *_svc,
20effc67 493 const rgw_raw_obj& _obj, std::map<std::string, bufferlist> *_pattrs,
f67539c2
TL
494 bool _raw_attrs, RGWObjVersionTracker* objv_tracker = nullptr)
495 : RGWSimpleCoroutine(_svc->ctx()),
b3b6e05e 496 dpp(_dpp),
f67539c2
TL
497 async_rados(_async_rados), svc(_svc),
498 obj(_obj),
499 pattrs(_pattrs),
500 raw_attrs(_raw_attrs),
501 objv_tracker(objv_tracker)
502 {}
7c673cae
FG
503 ~RGWSimpleRadosReadAttrsCR() override {
504 request_cleanup();
505 }
506
507 void request_cleanup() override {
508 if (req) {
509 req->finish();
510 req = NULL;
511 }
512 }
513
b3b6e05e 514 int send_request(const DoutPrefixProvider *dpp) override;
7c673cae
FG
515 int request_complete() override;
516};
517
518template <class T>
519class RGWSimpleRadosWriteCR : public RGWSimpleCoroutine {
b3b6e05e 520 const DoutPrefixProvider *dpp;
7c673cae 521 RGWAsyncRadosProcessor *async_rados;
11fdf7f2 522 RGWSI_SysObj *svc;
7c673cae 523 bufferlist bl;
7c673cae
FG
524 rgw_raw_obj obj;
525 RGWObjVersionTracker *objv_tracker;
7c673cae
FG
526 RGWAsyncPutSystemObj *req{nullptr};
527
528public:
b3b6e05e
TL
529 RGWSimpleRadosWriteCR(const DoutPrefixProvider *_dpp,
530 RGWAsyncRadosProcessor *_async_rados, RGWSI_SysObj *_svc,
7c673cae
FG
531 const rgw_raw_obj& _obj,
532 const T& _data, RGWObjVersionTracker *objv_tracker = nullptr)
b3b6e05e 533 : RGWSimpleCoroutine(_svc->ctx()), dpp(_dpp), async_rados(_async_rados),
11fdf7f2
TL
534 svc(_svc), obj(_obj), objv_tracker(objv_tracker) {
535 encode(_data, bl);
7c673cae
FG
536 }
537
538 ~RGWSimpleRadosWriteCR() override {
539 request_cleanup();
540 }
541
542 void request_cleanup() override {
543 if (req) {
544 req->finish();
545 req = NULL;
546 }
547 }
548
b3b6e05e
TL
549 int send_request(const DoutPrefixProvider *dpp) override {
550 req = new RGWAsyncPutSystemObj(dpp, this, stack->create_completion_notifier(),
11fdf7f2 551 svc, objv_tracker, obj, false, std::move(bl));
7c673cae
FG
552 async_rados->queue(req);
553 return 0;
554 }
555
556 int request_complete() override {
91327a77
AA
557 if (objv_tracker) { // copy the updated version
558 *objv_tracker = req->objv_tracker;
559 }
7c673cae
FG
560 return req->get_ret_status();
561 }
562};
563
564class RGWSimpleRadosWriteAttrsCR : public RGWSimpleCoroutine {
b3b6e05e 565 const DoutPrefixProvider *dpp;
7c673cae 566 RGWAsyncRadosProcessor *async_rados;
11fdf7f2 567 RGWSI_SysObj *svc;
91327a77 568 RGWObjVersionTracker *objv_tracker;
11fdf7f2 569
7c673cae 570 rgw_raw_obj obj;
20effc67 571 std::map<std::string, bufferlist> attrs;
91327a77 572 RGWAsyncPutSystemObjAttrs *req = nullptr;
7c673cae
FG
573
574public:
b3b6e05e
TL
575 RGWSimpleRadosWriteAttrsCR(const DoutPrefixProvider *_dpp,
576 RGWAsyncRadosProcessor *_async_rados,
11fdf7f2 577 RGWSI_SysObj *_svc, const rgw_raw_obj& _obj,
20effc67 578 std::map<std::string, bufferlist> _attrs,
91327a77 579 RGWObjVersionTracker *objv_tracker = nullptr)
b3b6e05e 580 : RGWSimpleCoroutine(_svc->ctx()), dpp(_dpp), async_rados(_async_rados),
11fdf7f2 581 svc(_svc), objv_tracker(objv_tracker), obj(_obj),
91327a77 582 attrs(std::move(_attrs)) {
7c673cae
FG
583 }
584 ~RGWSimpleRadosWriteAttrsCR() override {
585 request_cleanup();
586 }
587
588 void request_cleanup() override {
589 if (req) {
590 req->finish();
591 req = NULL;
592 }
593 }
594
b3b6e05e
TL
595 int send_request(const DoutPrefixProvider *dpp) override {
596 req = new RGWAsyncPutSystemObjAttrs(dpp, this, stack->create_completion_notifier(),
11fdf7f2 597 svc, objv_tracker, obj, std::move(attrs));
7c673cae
FG
598 async_rados->queue(req);
599 return 0;
600 }
601
602 int request_complete() override {
91327a77
AA
603 if (objv_tracker) { // copy the updated version
604 *objv_tracker = req->objv_tracker;
605 }
7c673cae
FG
606 return req->get_ret_status();
607 }
608};
609
610class RGWRadosSetOmapKeysCR : public RGWSimpleCoroutine {
20effc67
TL
611 rgw::sal::RadosStore* store;
612 std::map<std::string, bufferlist> entries;
7c673cae
FG
613
614 rgw_rados_ref ref;
615
616 rgw_raw_obj obj;
617
224ce89b 618 boost::intrusive_ptr<RGWAioCompletionNotifier> cn;
7c673cae
FG
619
620public:
20effc67 621 RGWRadosSetOmapKeysCR(rgw::sal::RadosStore* _store,
7c673cae 622 const rgw_raw_obj& _obj,
20effc67 623 std::map<std::string, bufferlist>& _entries);
7c673cae 624
b3b6e05e 625 int send_request(const DoutPrefixProvider *dpp) override;
7c673cae
FG
626 int request_complete() override;
627};
628
629class RGWRadosGetOmapKeysCR : public RGWSimpleCoroutine {
11fdf7f2
TL
630 public:
631 struct Result {
632 rgw_rados_ref ref;
633 std::set<std::string> entries;
634 bool more = false;
635 };
636 using ResultPtr = std::shared_ptr<Result>;
7c673cae 637
20effc67
TL
638 RGWRadosGetOmapKeysCR(rgw::sal::RadosStore* _store, const rgw_raw_obj& _obj,
639 const std::string& _marker, int _max_entries,
11fdf7f2 640 ResultPtr result);
7c673cae 641
b3b6e05e 642 int send_request(const DoutPrefixProvider *dpp) override;
11fdf7f2 643 int request_complete() override;
7c673cae 644
11fdf7f2 645 private:
20effc67 646 rgw::sal::RadosStore* store;
7c673cae 647 rgw_raw_obj obj;
20effc67 648 std::string marker;
11fdf7f2
TL
649 int max_entries;
650 ResultPtr result;
224ce89b 651 boost::intrusive_ptr<RGWAioCompletionNotifier> cn;
7c673cae
FG
652};
653
f67539c2
TL
654class RGWRadosGetOmapValsCR : public RGWSimpleCoroutine {
655 public:
656 struct Result {
657 rgw_rados_ref ref;
658 std::map<std::string, bufferlist> entries;
659 bool more = false;
660 };
661 using ResultPtr = std::shared_ptr<Result>;
662
20effc67
TL
663 RGWRadosGetOmapValsCR(rgw::sal::RadosStore* _store, const rgw_raw_obj& _obj,
664 const std::string& _marker, int _max_entries,
f67539c2
TL
665 ResultPtr result);
666
b3b6e05e 667 int send_request(const DoutPrefixProvider *dpp) override;
f67539c2
TL
668 int request_complete() override;
669
670 private:
20effc67 671 rgw::sal::RadosStore* store;
f67539c2 672 rgw_raw_obj obj;
20effc67 673 std::string marker;
f67539c2
TL
674 int max_entries;
675 ResultPtr result;
676 boost::intrusive_ptr<RGWAioCompletionNotifier> cn;
677};
678
7c673cae 679class RGWRadosRemoveOmapKeysCR : public RGWSimpleCoroutine {
20effc67 680 rgw::sal::RadosStore* store;
7c673cae 681
7c673cae
FG
682 rgw_rados_ref ref;
683
20effc67 684 std::set<std::string> keys;
7c673cae
FG
685
686 rgw_raw_obj obj;
687
224ce89b 688 boost::intrusive_ptr<RGWAioCompletionNotifier> cn;
7c673cae
FG
689
690public:
20effc67 691 RGWRadosRemoveOmapKeysCR(rgw::sal::RadosStore* _store,
7c673cae 692 const rgw_raw_obj& _obj,
20effc67 693 const std::set<std::string>& _keys);
7c673cae 694
b3b6e05e 695 int send_request(const DoutPrefixProvider *dpp) override;
7c673cae 696
224ce89b 697 int request_complete() override;
7c673cae
FG
698};
699
700class RGWRadosRemoveCR : public RGWSimpleCoroutine {
20effc67 701 rgw::sal::RadosStore* store;
7c673cae
FG
702 librados::IoCtx ioctx;
703 const rgw_raw_obj obj;
f67539c2 704 RGWObjVersionTracker* objv_tracker;
7c673cae
FG
705 boost::intrusive_ptr<RGWAioCompletionNotifier> cn;
706
707public:
20effc67 708 RGWRadosRemoveCR(rgw::sal::RadosStore* store, const rgw_raw_obj& obj,
f67539c2 709 RGWObjVersionTracker* objv_tracker = nullptr);
7c673cae 710
b3b6e05e 711 int send_request(const DoutPrefixProvider *dpp) override;
11fdf7f2 712 int request_complete() override;
7c673cae
FG
713};
714
715class RGWSimpleRadosLockCR : public RGWSimpleCoroutine {
716 RGWAsyncRadosProcessor *async_rados;
20effc67
TL
717 rgw::sal::RadosStore* store;
718 std::string lock_name;
719 std::string cookie;
7c673cae
FG
720 uint32_t duration;
721
722 rgw_raw_obj obj;
723
724 RGWAsyncLockSystemObj *req;
725
726public:
20effc67 727 RGWSimpleRadosLockCR(RGWAsyncRadosProcessor *_async_rados, rgw::sal::RadosStore* _store,
7c673cae 728 const rgw_raw_obj& _obj,
20effc67
TL
729 const std::string& _lock_name,
730 const std::string& _cookie,
7c673cae
FG
731 uint32_t _duration);
732 ~RGWSimpleRadosLockCR() override {
733 request_cleanup();
734 }
735 void request_cleanup() override;
736
b3b6e05e 737 int send_request(const DoutPrefixProvider *dpp) override;
7c673cae
FG
738 int request_complete() override;
739
740 static std::string gen_random_cookie(CephContext* cct) {
741#define COOKIE_LEN 16
742 char buf[COOKIE_LEN + 1];
743 gen_rand_alphanumeric(cct, buf, sizeof(buf) - 1);
744 return buf;
745 }
746};
747
748class RGWSimpleRadosUnlockCR : public RGWSimpleCoroutine {
749 RGWAsyncRadosProcessor *async_rados;
20effc67
TL
750 rgw::sal::RadosStore* store;
751 std::string lock_name;
752 std::string cookie;
7c673cae
FG
753
754 rgw_raw_obj obj;
755
756 RGWAsyncUnlockSystemObj *req;
757
758public:
20effc67 759 RGWSimpleRadosUnlockCR(RGWAsyncRadosProcessor *_async_rados, rgw::sal::RadosStore* _store,
7c673cae 760 const rgw_raw_obj& _obj,
20effc67
TL
761 const std::string& _lock_name,
762 const std::string& _cookie);
7c673cae
FG
763 ~RGWSimpleRadosUnlockCR() override {
764 request_cleanup();
765 }
766 void request_cleanup() override;
767
b3b6e05e 768 int send_request(const DoutPrefixProvider *dpp) override;
7c673cae
FG
769 int request_complete() override;
770};
771
772#define OMAP_APPEND_MAX_ENTRIES_DEFAULT 100
773
20effc67 774class RGWOmapAppend : public RGWConsumerCR<std::string> {
7c673cae 775 RGWAsyncRadosProcessor *async_rados;
20effc67 776 rgw::sal::RadosStore* store;
7c673cae
FG
777
778 rgw_raw_obj obj;
779
780 bool going_down;
781
782 int num_pending_entries;
20effc67 783 std::list<std::string> pending_entries;
7c673cae 784
20effc67 785 std::map<std::string, bufferlist> entries;
7c673cae
FG
786
787 uint64_t window_size;
788 uint64_t total_entries;
789public:
20effc67 790 RGWOmapAppend(RGWAsyncRadosProcessor *_async_rados, rgw::sal::RadosStore* _store,
7c673cae
FG
791 const rgw_raw_obj& _obj,
792 uint64_t _window_size = OMAP_APPEND_MAX_ENTRIES_DEFAULT);
b3b6e05e 793 int operate(const DoutPrefixProvider *dpp) override;
7c673cae 794 void flush_pending();
20effc67 795 bool append(const std::string& s);
7c673cae
FG
796 bool finish();
797
798 uint64_t get_total_entries() {
799 return total_entries;
800 }
801
802 const rgw_raw_obj& get_obj() {
803 return obj;
804 }
805};
806
7c673cae
FG
807class RGWShardedOmapCRManager {
808 RGWAsyncRadosProcessor *async_rados;
20effc67 809 rgw::sal::RadosStore* store;
7c673cae
FG
810 RGWCoroutine *op;
811
812 int num_shards;
813
20effc67 814 std::vector<RGWOmapAppend *> shards;
7c673cae 815public:
20effc67 816 RGWShardedOmapCRManager(RGWAsyncRadosProcessor *_async_rados, rgw::sal::RadosStore* _store, RGWCoroutine *_op, int _num_shards, const rgw_pool& pool, const std::string& oid_prefix)
7c673cae
FG
817 : async_rados(_async_rados),
818 store(_store), op(_op), num_shards(_num_shards) {
819 shards.reserve(num_shards);
820 for (int i = 0; i < num_shards; ++i) {
821 char buf[oid_prefix.size() + 16];
822 snprintf(buf, sizeof(buf), "%s.%d", oid_prefix.c_str(), i);
823 RGWOmapAppend *shard = new RGWOmapAppend(async_rados, store, rgw_raw_obj(pool, buf));
824 shard->get();
825 shards.push_back(shard);
826 op->spawn(shard, false);
827 }
828 }
829
830 ~RGWShardedOmapCRManager() {
831 for (auto shard : shards) {
832 shard->put();
833 }
834 }
835
20effc67 836 bool append(const std::string& entry, int shard_id) {
7c673cae
FG
837 return shards[shard_id]->append(entry);
838 }
839 bool finish() {
840 bool success = true;
20effc67
TL
841 for (auto& append_op : shards) {
842 success &= (append_op->finish() && (!append_op->is_error()));
7c673cae
FG
843 }
844 return success;
845 }
846
847 uint64_t get_total_entries(int shard_id) {
848 return shards[shard_id]->get_total_entries();
849 }
850};
851
852class RGWAsyncGetBucketInstanceInfo : public RGWAsyncRadosRequest {
20effc67 853 rgw::sal::RadosStore* store;
9f95a23c 854 rgw_bucket bucket;
b3b6e05e 855 const DoutPrefixProvider *dpp;
7c673cae
FG
856
857protected:
b3b6e05e 858 int _send_request(const DoutPrefixProvider *dpp) override;
7c673cae
FG
859public:
860 RGWAsyncGetBucketInstanceInfo(RGWCoroutine *caller, RGWAioCompletionNotifier *cn,
20effc67 861 rgw::sal::RadosStore* _store, const rgw_bucket& bucket,
b3b6e05e
TL
862 const DoutPrefixProvider *dpp)
863 : RGWAsyncRadosRequest(caller, cn), store(_store), bucket(bucket), dpp(dpp) {}
91327a77
AA
864
865 RGWBucketInfo bucket_info;
20effc67 866 std::map<std::string, bufferlist> attrs;
7c673cae
FG
867};
868
869class RGWGetBucketInstanceInfoCR : public RGWSimpleCoroutine {
870 RGWAsyncRadosProcessor *async_rados;
20effc67 871 rgw::sal::RadosStore* store;
9f95a23c 872 rgw_bucket bucket;
7c673cae 873 RGWBucketInfo *bucket_info;
20effc67 874 std::map<std::string, bufferlist> *pattrs;
b3b6e05e 875 const DoutPrefixProvider *dpp;
7c673cae 876
b32b8144 877 RGWAsyncGetBucketInstanceInfo *req{nullptr};
7c673cae
FG
878
879public:
b32b8144 880 // rgw_bucket constructor
20effc67 881 RGWGetBucketInstanceInfoCR(RGWAsyncRadosProcessor *_async_rados, rgw::sal::RadosStore* _store,
9f95a23c 882 const rgw_bucket& _bucket, RGWBucketInfo *_bucket_info,
20effc67 883 std::map<std::string, bufferlist> *_pattrs, const DoutPrefixProvider *dpp)
7c673cae 884 : RGWSimpleCoroutine(_store->ctx()), async_rados(_async_rados), store(_store),
b3b6e05e 885 bucket(_bucket), bucket_info(_bucket_info), pattrs(_pattrs), dpp(dpp) {}
7c673cae
FG
886 ~RGWGetBucketInstanceInfoCR() override {
887 request_cleanup();
888 }
889 void request_cleanup() override {
890 if (req) {
891 req->finish();
892 req = NULL;
893 }
894 }
895
b3b6e05e
TL
896 int send_request(const DoutPrefixProvider *dpp) override {
897 req = new RGWAsyncGetBucketInstanceInfo(this, stack->create_completion_notifier(), store, bucket, dpp);
7c673cae
FG
898 async_rados->queue(req);
899 return 0;
900 }
901 int request_complete() override {
91327a77
AA
902 if (bucket_info) {
903 *bucket_info = std::move(req->bucket_info);
904 }
9f95a23c
TL
905 if (pattrs) {
906 *pattrs = std::move(req->attrs);
907 }
7c673cae
FG
908 return req->get_ret_status();
909 }
910};
911
b32b8144 912class RGWRadosBILogTrimCR : public RGWSimpleCoroutine {
20effc67
TL
913 const RGWBucketInfo& bucket_info;
914 int shard_id;
b32b8144
FG
915 RGWRados::BucketShard bs;
916 std::string start_marker;
917 std::string end_marker;
918 boost::intrusive_ptr<RGWAioCompletionNotifier> cn;
919 public:
b3b6e05e 920 RGWRadosBILogTrimCR(const DoutPrefixProvider *dpp,
20effc67 921 rgw::sal::RadosStore* store, const RGWBucketInfo& bucket_info,
b32b8144
FG
922 int shard_id, const std::string& start_marker,
923 const std::string& end_marker);
924
b3b6e05e 925 int send_request(const DoutPrefixProvider *dpp) override;
b32b8144
FG
926 int request_complete() override;
927};
928
7c673cae 929class RGWAsyncFetchRemoteObj : public RGWAsyncRadosRequest {
20effc67 930 rgw::sal::RadosStore* store;
9f95a23c 931 rgw_zone_id source_zone;
7c673cae 932
9f95a23c
TL
933 std::optional<rgw_user> user_id;
934
935 rgw_bucket src_bucket;
11fdf7f2 936 std::optional<rgw_placement_rule> dest_placement_rule;
9f95a23c 937 RGWBucketInfo dest_bucket_info;
7c673cae
FG
938
939 rgw_obj_key key;
11fdf7f2
TL
940 std::optional<rgw_obj_key> dest_key;
941 std::optional<uint64_t> versioned_epoch;
7c673cae
FG
942
943 real_time src_mtime;
944
945 bool copy_if_newer;
9f95a23c 946 std::shared_ptr<RGWFetchObjFilter> filter;
91327a77 947 rgw_zone_set zones_trace;
81eedcae 948 PerfCounters* counters;
9f95a23c 949 const DoutPrefixProvider *dpp;
7c673cae
FG
950
951protected:
b3b6e05e 952 int _send_request(const DoutPrefixProvider *dpp) override;
7c673cae 953public:
20effc67 954 RGWAsyncFetchRemoteObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, rgw::sal::RadosStore* _store,
9f95a23c
TL
955 const rgw_zone_id& _source_zone,
956 std::optional<rgw_user>& _user_id,
957 const rgw_bucket& _src_bucket,
11fdf7f2 958 std::optional<rgw_placement_rule> _dest_placement_rule,
9f95a23c 959 const RGWBucketInfo& _dest_bucket_info,
7c673cae 960 const rgw_obj_key& _key,
11fdf7f2
TL
961 const std::optional<rgw_obj_key>& _dest_key,
962 std::optional<uint64_t> _versioned_epoch,
9f95a23c
TL
963 bool _if_newer,
964 std::shared_ptr<RGWFetchObjFilter> _filter,
965 rgw_zone_set *_zones_trace,
966 PerfCounters* counters, const DoutPrefixProvider *dpp)
81eedcae
TL
967 : RGWAsyncRadosRequest(caller, cn), store(_store),
968 source_zone(_source_zone),
9f95a23c
TL
969 user_id(_user_id),
970 src_bucket(_src_bucket),
81eedcae 971 dest_placement_rule(_dest_placement_rule),
9f95a23c 972 dest_bucket_info(_dest_bucket_info),
81eedcae
TL
973 key(_key),
974 dest_key(_dest_key),
975 versioned_epoch(_versioned_epoch),
9f95a23c
TL
976 copy_if_newer(_if_newer),
977 filter(_filter),
978 counters(counters),
979 dpp(dpp)
91327a77
AA
980 {
981 if (_zones_trace) {
982 zones_trace = *_zones_trace;
983 }
984 }
7c673cae
FG
985};
986
987class RGWFetchRemoteObjCR : public RGWSimpleCoroutine {
988 CephContext *cct;
989 RGWAsyncRadosProcessor *async_rados;
20effc67 990 rgw::sal::RadosStore* store;
9f95a23c 991 rgw_zone_id source_zone;
7c673cae 992
9f95a23c
TL
993 std::optional<rgw_user> user_id;
994
995 rgw_bucket src_bucket;
11fdf7f2 996 std::optional<rgw_placement_rule> dest_placement_rule;
9f95a23c 997 RGWBucketInfo dest_bucket_info;
7c673cae
FG
998
999 rgw_obj_key key;
11fdf7f2
TL
1000 std::optional<rgw_obj_key> dest_key;
1001 std::optional<uint64_t> versioned_epoch;
7c673cae
FG
1002
1003 real_time src_mtime;
1004
1005 bool copy_if_newer;
1006
9f95a23c
TL
1007 std::shared_ptr<RGWFetchObjFilter> filter;
1008
7c673cae 1009 RGWAsyncFetchRemoteObj *req;
31f18b77 1010 rgw_zone_set *zones_trace;
81eedcae 1011 PerfCounters* counters;
9f95a23c 1012 const DoutPrefixProvider *dpp;
7c673cae
FG
1013
1014public:
20effc67 1015 RGWFetchRemoteObjCR(RGWAsyncRadosProcessor *_async_rados, rgw::sal::RadosStore* _store,
9f95a23c
TL
1016 const rgw_zone_id& _source_zone,
1017 std::optional<rgw_user> _user_id,
1018 const rgw_bucket& _src_bucket,
11fdf7f2 1019 std::optional<rgw_placement_rule> _dest_placement_rule,
9f95a23c 1020 const RGWBucketInfo& _dest_bucket_info,
7c673cae 1021 const rgw_obj_key& _key,
11fdf7f2
TL
1022 const std::optional<rgw_obj_key>& _dest_key,
1023 std::optional<uint64_t> _versioned_epoch,
9f95a23c
TL
1024 bool _if_newer,
1025 std::shared_ptr<RGWFetchObjFilter> _filter,
1026 rgw_zone_set *_zones_trace,
1027 PerfCounters* counters, const DoutPrefixProvider *dpp)
81eedcae
TL
1028 : RGWSimpleCoroutine(_store->ctx()), cct(_store->ctx()),
1029 async_rados(_async_rados), store(_store),
1030 source_zone(_source_zone),
9f95a23c
TL
1031 user_id(_user_id),
1032 src_bucket(_src_bucket),
81eedcae 1033 dest_placement_rule(_dest_placement_rule),
9f95a23c 1034 dest_bucket_info(_dest_bucket_info),
81eedcae
TL
1035 key(_key),
1036 dest_key(_dest_key),
1037 versioned_epoch(_versioned_epoch),
9f95a23c
TL
1038 copy_if_newer(_if_newer),
1039 filter(_filter),
1040 req(NULL),
1041 zones_trace(_zones_trace), counters(counters), dpp(dpp) {}
7c673cae
FG
1042
1043
1044 ~RGWFetchRemoteObjCR() override {
1045 request_cleanup();
1046 }
1047
1048 void request_cleanup() override {
1049 if (req) {
1050 req->finish();
1051 req = NULL;
1052 }
1053 }
1054
b3b6e05e 1055 int send_request(const DoutPrefixProvider *dpp) override {
11fdf7f2 1056 req = new RGWAsyncFetchRemoteObj(this, stack->create_completion_notifier(), store,
9f95a23c
TL
1057 source_zone, user_id, src_bucket, dest_placement_rule, dest_bucket_info,
1058 key, dest_key, versioned_epoch, copy_if_newer, filter,
1059 zones_trace, counters, dpp);
7c673cae
FG
1060 async_rados->queue(req);
1061 return 0;
1062 }
1063
1064 int request_complete() override {
1065 return req->get_ret_status();
1066 }
1067};
1068
1069class RGWAsyncStatRemoteObj : public RGWAsyncRadosRequest {
20effc67 1070 rgw::sal::RadosStore* store;
9f95a23c 1071 rgw_zone_id source_zone;
7c673cae 1072
9f95a23c 1073 rgw_bucket src_bucket;
7c673cae
FG
1074 rgw_obj_key key;
1075
1076 ceph::real_time *pmtime;
1077 uint64_t *psize;
20effc67
TL
1078 std::string *petag;
1079 std::map<std::string, bufferlist> *pattrs;
1080 std::map<std::string, std::string> *pheaders;
7c673cae
FG
1081
1082protected:
b3b6e05e 1083 int _send_request(const DoutPrefixProvider *dpp) override;
7c673cae 1084public:
20effc67 1085 RGWAsyncStatRemoteObj(RGWCoroutine *caller, RGWAioCompletionNotifier *cn, rgw::sal::RadosStore* _store,
9f95a23c
TL
1086 const rgw_zone_id& _source_zone,
1087 rgw_bucket& _src_bucket,
7c673cae
FG
1088 const rgw_obj_key& _key,
1089 ceph::real_time *_pmtime,
1090 uint64_t *_psize,
20effc67
TL
1091 std::string *_petag,
1092 std::map<std::string, bufferlist> *_pattrs,
1093 std::map<std::string, std::string> *_pheaders) : RGWAsyncRadosRequest(caller, cn), store(_store),
7c673cae 1094 source_zone(_source_zone),
9f95a23c 1095 src_bucket(_src_bucket),
7c673cae
FG
1096 key(_key),
1097 pmtime(_pmtime),
1098 psize(_psize),
11fdf7f2
TL
1099 petag(_petag),
1100 pattrs(_pattrs),
1101 pheaders(_pheaders) {}
7c673cae
FG
1102};
1103
1104class RGWStatRemoteObjCR : public RGWSimpleCoroutine {
1105 CephContext *cct;
1106 RGWAsyncRadosProcessor *async_rados;
20effc67 1107 rgw::sal::RadosStore* store;
9f95a23c 1108 rgw_zone_id source_zone;
7c673cae 1109
9f95a23c 1110 rgw_bucket src_bucket;
7c673cae
FG
1111 rgw_obj_key key;
1112
1113 ceph::real_time *pmtime;
1114 uint64_t *psize;
20effc67
TL
1115 std::string *petag;
1116 std::map<std::string, bufferlist> *pattrs;
1117 std::map<std::string, std::string> *pheaders;
7c673cae
FG
1118
1119 RGWAsyncStatRemoteObj *req;
1120
1121public:
20effc67 1122 RGWStatRemoteObjCR(RGWAsyncRadosProcessor *_async_rados, rgw::sal::RadosStore* _store,
9f95a23c
TL
1123 const rgw_zone_id& _source_zone,
1124 rgw_bucket& _src_bucket,
7c673cae
FG
1125 const rgw_obj_key& _key,
1126 ceph::real_time *_pmtime,
1127 uint64_t *_psize,
20effc67
TL
1128 std::string *_petag,
1129 std::map<std::string, bufferlist> *_pattrs,
1130 std::map<std::string, std::string> *_pheaders) : RGWSimpleCoroutine(_store->ctx()), cct(_store->ctx()),
7c673cae
FG
1131 async_rados(_async_rados), store(_store),
1132 source_zone(_source_zone),
9f95a23c 1133 src_bucket(_src_bucket),
7c673cae
FG
1134 key(_key),
1135 pmtime(_pmtime),
1136 psize(_psize),
11fdf7f2 1137 petag(_petag),
7c673cae 1138 pattrs(_pattrs),
11fdf7f2 1139 pheaders(_pheaders),
7c673cae
FG
1140 req(NULL) {}
1141
1142
1143 ~RGWStatRemoteObjCR() override {
1144 request_cleanup();
1145 }
1146
1147 void request_cleanup() override {
1148 if (req) {
1149 req->finish();
1150 req = NULL;
1151 }
1152 }
1153
b3b6e05e 1154 int send_request(const DoutPrefixProvider *dpp) override {
7c673cae 1155 req = new RGWAsyncStatRemoteObj(this, stack->create_completion_notifier(), store, source_zone,
9f95a23c 1156 src_bucket, key, pmtime, psize, petag, pattrs, pheaders);
7c673cae
FG
1157 async_rados->queue(req);
1158 return 0;
1159 }
1160
1161 int request_complete() override {
1162 return req->get_ret_status();
1163 }
1164};
1165
1166class RGWAsyncRemoveObj : public RGWAsyncRadosRequest {
b3b6e05e 1167 const DoutPrefixProvider *dpp;
20effc67 1168 rgw::sal::RadosStore* store;
9f95a23c 1169 rgw_zone_id source_zone;
7c673cae
FG
1170
1171 RGWBucketInfo bucket_info;
1172
1173 rgw_obj_key key;
20effc67
TL
1174 std::string owner;
1175 std::string owner_display_name;
7c673cae
FG
1176 bool versioned;
1177 uint64_t versioned_epoch;
20effc67 1178 std::string marker_version_id;
7c673cae
FG
1179
1180 bool del_if_older;
1181 ceph::real_time timestamp;
91327a77 1182 rgw_zone_set zones_trace;
7c673cae
FG
1183
1184protected:
b3b6e05e 1185 int _send_request(const DoutPrefixProvider *dpp) override;
7c673cae 1186public:
b3b6e05e 1187 RGWAsyncRemoveObj(const DoutPrefixProvider *_dpp, RGWCoroutine *caller, RGWAioCompletionNotifier *cn,
20effc67 1188 rgw::sal::RadosStore* _store,
9f95a23c 1189 const rgw_zone_id& _source_zone,
7c673cae
FG
1190 RGWBucketInfo& _bucket_info,
1191 const rgw_obj_key& _key,
20effc67
TL
1192 const std::string& _owner,
1193 const std::string& _owner_display_name,
7c673cae
FG
1194 bool _versioned,
1195 uint64_t _versioned_epoch,
1196 bool _delete_marker,
1197 bool _if_older,
31f18b77 1198 real_time& _timestamp,
b3b6e05e 1199 rgw_zone_set* _zones_trace) : RGWAsyncRadosRequest(caller, cn), dpp(_dpp), store(_store),
7c673cae
FG
1200 source_zone(_source_zone),
1201 bucket_info(_bucket_info),
1202 key(_key),
1203 owner(_owner),
1204 owner_display_name(_owner_display_name),
1205 versioned(_versioned),
1206 versioned_epoch(_versioned_epoch),
1207 del_if_older(_if_older),
91327a77 1208 timestamp(_timestamp) {
7c673cae
FG
1209 if (_delete_marker) {
1210 marker_version_id = key.instance;
1211 }
91327a77
AA
1212
1213 if (_zones_trace) {
1214 zones_trace = *_zones_trace;
1215 }
7c673cae
FG
1216 }
1217};
1218
1219class RGWRemoveObjCR : public RGWSimpleCoroutine {
b3b6e05e 1220 const DoutPrefixProvider *dpp;
7c673cae
FG
1221 CephContext *cct;
1222 RGWAsyncRadosProcessor *async_rados;
20effc67 1223 rgw::sal::RadosStore* store;
9f95a23c 1224 rgw_zone_id source_zone;
7c673cae
FG
1225
1226 RGWBucketInfo bucket_info;
1227
1228 rgw_obj_key key;
1229 bool versioned;
1230 uint64_t versioned_epoch;
1231 bool delete_marker;
20effc67
TL
1232 std::string owner;
1233 std::string owner_display_name;
7c673cae
FG
1234
1235 bool del_if_older;
1236 real_time timestamp;
1237
1238 RGWAsyncRemoveObj *req;
31f18b77
FG
1239
1240 rgw_zone_set *zones_trace;
7c673cae
FG
1241
1242public:
20effc67 1243 RGWRemoveObjCR(const DoutPrefixProvider *_dpp, RGWAsyncRadosProcessor *_async_rados, rgw::sal::RadosStore* _store,
9f95a23c 1244 const rgw_zone_id& _source_zone,
7c673cae
FG
1245 RGWBucketInfo& _bucket_info,
1246 const rgw_obj_key& _key,
1247 bool _versioned,
1248 uint64_t _versioned_epoch,
20effc67
TL
1249 std::string *_owner,
1250 std::string *_owner_display_name,
7c673cae 1251 bool _delete_marker,
31f18b77 1252 real_time *_timestamp,
b3b6e05e 1253 rgw_zone_set *_zones_trace) : RGWSimpleCoroutine(_store->ctx()), dpp(_dpp), cct(_store->ctx()),
7c673cae
FG
1254 async_rados(_async_rados), store(_store),
1255 source_zone(_source_zone),
1256 bucket_info(_bucket_info),
1257 key(_key),
1258 versioned(_versioned),
1259 versioned_epoch(_versioned_epoch),
31f18b77 1260 delete_marker(_delete_marker), req(NULL), zones_trace(_zones_trace) {
7c673cae
FG
1261 del_if_older = (_timestamp != NULL);
1262 if (_timestamp) {
1263 timestamp = *_timestamp;
1264 }
1265
1266 if (_owner) {
1267 owner = *_owner;
1268 }
1269
1270 if (_owner_display_name) {
1271 owner_display_name = *_owner_display_name;
1272 }
1273 }
1274 ~RGWRemoveObjCR() override {
1275 request_cleanup();
1276 }
1277
1278 void request_cleanup() override {
1279 if (req) {
1280 req->finish();
1281 req = NULL;
1282 }
1283 }
1284
b3b6e05e
TL
1285 int send_request(const DoutPrefixProvider *dpp) override {
1286 req = new RGWAsyncRemoveObj(dpp, this, stack->create_completion_notifier(), store, source_zone, bucket_info,
7c673cae 1287 key, owner, owner_display_name, versioned, versioned_epoch,
31f18b77 1288 delete_marker, del_if_older, timestamp, zones_trace);
7c673cae
FG
1289 async_rados->queue(req);
1290 return 0;
1291 }
1292
1293 int request_complete() override {
1294 return req->get_ret_status();
1295 }
1296};
1297
1298class RGWContinuousLeaseCR : public RGWCoroutine {
1299 RGWAsyncRadosProcessor *async_rados;
20effc67 1300 rgw::sal::RadosStore* store;
7c673cae
FG
1301
1302 const rgw_raw_obj obj;
1303
20effc67
TL
1304 const std::string lock_name;
1305 const std::string cookie;
7c673cae
FG
1306
1307 int interval;
f67539c2 1308 bool going_down{ false };
7c673cae
FG
1309 bool locked{false};
1310
1311 RGWCoroutine *caller;
1312
1313 bool aborted{false};
1314
1315public:
20effc67 1316 RGWContinuousLeaseCR(RGWAsyncRadosProcessor *_async_rados, rgw::sal::RadosStore* _store,
7c673cae 1317 const rgw_raw_obj& _obj,
20effc67 1318 const std::string& _lock_name, int _interval, RGWCoroutine *_caller)
7c673cae
FG
1319 : RGWCoroutine(_store->ctx()), async_rados(_async_rados), store(_store),
1320 obj(_obj), lock_name(_lock_name),
1321 cookie(RGWSimpleRadosLockCR::gen_random_cookie(cct)),
9f95a23c 1322 interval(_interval), caller(_caller)
7c673cae
FG
1323 {}
1324
20effc67
TL
1325 virtual ~RGWContinuousLeaseCR() override;
1326
b3b6e05e 1327 int operate(const DoutPrefixProvider *dpp) override;
7c673cae 1328
f67539c2 1329 bool is_locked() const {
7c673cae
FG
1330 return locked;
1331 }
1332
1333 void set_locked(bool status) {
7c673cae
FG
1334 locked = status;
1335 }
1336
1337 void go_down() {
1338 going_down = true;
1339 wakeup();
1340 }
1341
1342 void abort() {
1343 aborted = true;
1344 }
1345};
1346
1347class RGWRadosTimelogAddCR : public RGWSimpleCoroutine {
b3b6e05e 1348 const DoutPrefixProvider *dpp;
20effc67
TL
1349 rgw::sal::RadosStore* store;
1350 std::list<cls_log_entry> entries;
7c673cae 1351
20effc67 1352 std::string oid;
7c673cae 1353
224ce89b 1354 boost::intrusive_ptr<RGWAioCompletionNotifier> cn;
7c673cae
FG
1355
1356public:
20effc67 1357 RGWRadosTimelogAddCR(const DoutPrefixProvider *dpp, rgw::sal::RadosStore* _store, const std::string& _oid,
7c673cae 1358 const cls_log_entry& entry);
7c673cae 1359
b3b6e05e 1360 int send_request(const DoutPrefixProvider *dpp) override;
7c673cae
FG
1361 int request_complete() override;
1362};
1363
1364class RGWRadosTimelogTrimCR : public RGWSimpleCoroutine {
b3b6e05e 1365 const DoutPrefixProvider *dpp;
20effc67 1366 rgw::sal::RadosStore* store;
224ce89b 1367 boost::intrusive_ptr<RGWAioCompletionNotifier> cn;
7c673cae
FG
1368 protected:
1369 std::string oid;
1370 real_time start_time;
1371 real_time end_time;
1372 std::string from_marker;
1373 std::string to_marker;
1374
1375 public:
b3b6e05e 1376 RGWRadosTimelogTrimCR(const DoutPrefixProvider *dpp,
20effc67 1377 rgw::sal::RadosStore* store, const std::string& oid,
7c673cae
FG
1378 const real_time& start_time, const real_time& end_time,
1379 const std::string& from_marker,
1380 const std::string& to_marker);
7c673cae 1381
b3b6e05e 1382 int send_request(const DoutPrefixProvider *dpp) override;
7c673cae
FG
1383 int request_complete() override;
1384};
1385
1386// wrapper to update last_trim_marker on success
1387class RGWSyncLogTrimCR : public RGWRadosTimelogTrimCR {
1388 CephContext *cct;
1389 std::string *last_trim_marker;
1390 public:
eafe8130
TL
1391 static constexpr const char* max_marker = "99999999";
1392
20effc67
TL
1393 RGWSyncLogTrimCR(const DoutPrefixProvider *dpp,
1394 rgw::sal::RadosStore* store, const std::string& oid,
7c673cae
FG
1395 const std::string& to_marker, std::string *last_trim_marker);
1396 int request_complete() override;
1397};
1398
1399class RGWAsyncStatObj : public RGWAsyncRadosRequest {
b3b6e05e 1400 const DoutPrefixProvider *dpp;
20effc67 1401 rgw::sal::RadosStore* store;
7c673cae
FG
1402 RGWBucketInfo bucket_info;
1403 rgw_obj obj;
1404 uint64_t *psize;
1405 real_time *pmtime;
1406 uint64_t *pepoch;
1407 RGWObjVersionTracker *objv_tracker;
1408protected:
b3b6e05e 1409 int _send_request(const DoutPrefixProvider *dpp) override;
7c673cae 1410public:
20effc67 1411 RGWAsyncStatObj(const DoutPrefixProvider *dpp, RGWCoroutine *caller, RGWAioCompletionNotifier *cn, rgw::sal::RadosStore* store,
7c673cae
FG
1412 const RGWBucketInfo& _bucket_info, const rgw_obj& obj, uint64_t *psize = nullptr,
1413 real_time *pmtime = nullptr, uint64_t *pepoch = nullptr,
1414 RGWObjVersionTracker *objv_tracker = nullptr)
b3b6e05e 1415 : RGWAsyncRadosRequest(caller, cn), dpp(dpp), store(store), obj(obj), psize(psize),
7c673cae
FG
1416 pmtime(pmtime), pepoch(pepoch), objv_tracker(objv_tracker) {}
1417};
1418
1419class RGWStatObjCR : public RGWSimpleCoroutine {
b3b6e05e 1420 const DoutPrefixProvider *dpp;
20effc67 1421 rgw::sal::RadosStore* store;
7c673cae
FG
1422 RGWAsyncRadosProcessor *async_rados;
1423 RGWBucketInfo bucket_info;
1424 rgw_obj obj;
1425 uint64_t *psize;
1426 real_time *pmtime;
1427 uint64_t *pepoch;
1428 RGWObjVersionTracker *objv_tracker;
1429 RGWAsyncStatObj *req = nullptr;
1430 public:
20effc67 1431 RGWStatObjCR(const DoutPrefixProvider *dpp, RGWAsyncRadosProcessor *async_rados, rgw::sal::RadosStore* store,
7c673cae
FG
1432 const RGWBucketInfo& _bucket_info, const rgw_obj& obj, uint64_t *psize = nullptr,
1433 real_time* pmtime = nullptr, uint64_t *pepoch = nullptr,
1434 RGWObjVersionTracker *objv_tracker = nullptr);
1435 ~RGWStatObjCR() override {
1436 request_cleanup();
1437 }
1438 void request_cleanup() override;
1439
b3b6e05e 1440 int send_request(const DoutPrefixProvider *dpp) override;
7c673cae
FG
1441 int request_complete() override;
1442};
1443
b32b8144
FG
1444/// coroutine wrapper for IoCtx::aio_notify()
1445class RGWRadosNotifyCR : public RGWSimpleCoroutine {
20effc67 1446 rgw::sal::RadosStore* const store;
b32b8144
FG
1447 const rgw_raw_obj obj;
1448 bufferlist request;
1449 const uint64_t timeout_ms;
1450 bufferlist *response;
1451 rgw_rados_ref ref;
1452 boost::intrusive_ptr<RGWAioCompletionNotifier> cn;
1453
1454public:
20effc67 1455 RGWRadosNotifyCR(rgw::sal::RadosStore* store, const rgw_raw_obj& obj,
b32b8144
FG
1456 bufferlist& request, uint64_t timeout_ms,
1457 bufferlist *response);
1458
b3b6e05e 1459 int send_request(const DoutPrefixProvider *dpp) override;
b32b8144
FG
1460 int request_complete() override;
1461};
1462
7c673cae 1463#endif