]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_rados.h
import ceph 16.2.6
[ceph.git] / ceph / src / rgw / rgw_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 #ifndef CEPH_RGWRADOS_H
5 #define CEPH_RGWRADOS_H
6
7 #include <functional>
8 #include <boost/container/flat_map.hpp>
9
10 #include "include/rados/librados.hpp"
11 #include "include/Context.h"
12 #include "common/RefCountedObj.h"
13 #include "common/RWLock.h"
14 #include "common/ceph_time.h"
15 #include "rgw_common.h"
16 #include "cls/rgw/cls_rgw_types.h"
17 #include "cls/version/cls_version_types.h"
18 #include "cls/log/cls_log_types.h"
19 #include "cls/timeindex/cls_timeindex_types.h"
20 #include "cls/otp/cls_otp_types.h"
21 #include "rgw_log.h"
22 #include "rgw_metadata.h"
23 #include "rgw_meta_sync_status.h"
24 #include "rgw_period_puller.h"
25 #include "rgw_obj_manifest.h"
26 #include "rgw_sync_module.h"
27 #include "rgw_trim_bilog.h"
28 #include "rgw_service.h"
29 #include "rgw_sal.h"
30
31 #include "services/svc_rados.h"
32 #include "services/svc_bi_rados.h"
33
34 class RGWWatcher;
35 class SafeTimer;
36 class ACLOwner;
37 class RGWGC;
38 class RGWMetaNotifier;
39 class RGWDataNotifier;
40 class RGWLC;
41 class RGWObjectExpirer;
42 class RGWMetaSyncProcessorThread;
43 class RGWDataSyncProcessorThread;
44 class RGWSyncLogTrimThread;
45 class RGWSyncTraceManager;
46 struct RGWZoneGroup;
47 struct RGWZoneParams;
48 class RGWReshard;
49 class RGWReshardWait;
50
51 class RGWSysObjectCtx;
52
53 /* flags for put_obj_meta() */
54 #define PUT_OBJ_CREATE 0x01
55 #define PUT_OBJ_EXCL 0x02
56 #define PUT_OBJ_CREATE_EXCL (PUT_OBJ_CREATE | PUT_OBJ_EXCL)
57
58 #define RGW_OBJ_NS_MULTIPART "multipart"
59 #define RGW_OBJ_NS_SHADOW "shadow"
60
61 static inline void prepend_bucket_marker(const rgw_bucket& bucket, const string& orig_oid, string& oid)
62 {
63 if (bucket.marker.empty() || orig_oid.empty()) {
64 oid = orig_oid;
65 } else {
66 oid = bucket.marker;
67 oid.append("_");
68 oid.append(orig_oid);
69 }
70 }
71
72 static inline void get_obj_bucket_and_oid_loc(const rgw_obj& obj, string& oid, string& locator)
73 {
74 const rgw_bucket& bucket = obj.bucket;
75 prepend_bucket_marker(bucket, obj.get_oid(), oid);
76 const string& loc = obj.key.get_loc();
77 if (!loc.empty()) {
78 prepend_bucket_marker(bucket, loc, locator);
79 } else {
80 locator.clear();
81 }
82 }
83
84 int rgw_policy_from_attrset(const DoutPrefixProvider *dpp, CephContext *cct, map<string, bufferlist>& attrset, RGWAccessControlPolicy *policy);
85
86 struct RGWOLHInfo {
87 rgw_obj target;
88 bool removed;
89
90 RGWOLHInfo() : removed(false) {}
91
92 void encode(bufferlist& bl) const {
93 ENCODE_START(1, 1, bl);
94 encode(target, bl);
95 encode(removed, bl);
96 ENCODE_FINISH(bl);
97 }
98
99 void decode(bufferlist::const_iterator& bl) {
100 DECODE_START(1, bl);
101 decode(target, bl);
102 decode(removed, bl);
103 DECODE_FINISH(bl);
104 }
105 static void generate_test_instances(list<RGWOLHInfo*>& o);
106 void dump(Formatter *f) const;
107 };
108 WRITE_CLASS_ENCODER(RGWOLHInfo)
109
110 struct RGWOLHPendingInfo {
111 ceph::real_time time;
112
113 RGWOLHPendingInfo() {}
114
115 void encode(bufferlist& bl) const {
116 ENCODE_START(1, 1, bl);
117 encode(time, bl);
118 ENCODE_FINISH(bl);
119 }
120
121 void decode(bufferlist::const_iterator& bl) {
122 DECODE_START(1, bl);
123 decode(time, bl);
124 DECODE_FINISH(bl);
125 }
126
127 void dump(Formatter *f) const;
128 };
129 WRITE_CLASS_ENCODER(RGWOLHPendingInfo)
130
131 struct RGWUsageBatch {
132 map<ceph::real_time, rgw_usage_log_entry> m;
133
134 void insert(ceph::real_time& t, rgw_usage_log_entry& entry, bool *account) {
135 bool exists = m.find(t) != m.end();
136 *account = !exists;
137 m[t].aggregate(entry);
138 }
139 };
140
141 class RGWGetDataCB {
142 public:
143 virtual int handle_data(bufferlist& bl, off_t bl_ofs, off_t bl_len) = 0;
144 RGWGetDataCB() {}
145 virtual ~RGWGetDataCB() {}
146 };
147
148 struct RGWCloneRangeInfo {
149 rgw_obj src;
150 off_t src_ofs;
151 off_t dst_ofs;
152 uint64_t len;
153 };
154
155 struct RGWObjState {
156 rgw_obj obj;
157 bool is_atomic{false};
158 bool has_attrs{false};
159 bool exists{false};
160 uint64_t size{0}; //< size of raw object
161 uint64_t accounted_size{0}; //< size before compression, encryption
162 ceph::real_time mtime;
163 uint64_t epoch{0};
164 bufferlist obj_tag;
165 bufferlist tail_tag;
166 string write_tag;
167 bool fake_tag{false};
168 std::optional<RGWObjManifest> manifest;
169 string shadow_obj;
170 bool has_data{false};
171 bufferlist data;
172 bool prefetch_data{false};
173 bool keep_tail{false};
174 bool is_olh{false};
175 bufferlist olh_tag;
176 uint64_t pg_ver{false};
177 uint32_t zone_short_id{0};
178
179 /* important! don't forget to update copy constructor */
180
181 RGWObjVersionTracker objv_tracker;
182
183 map<string, bufferlist> attrset;
184
185 RGWObjState();
186 RGWObjState(const RGWObjState& rhs);
187 ~RGWObjState();
188
189 bool get_attr(string name, bufferlist& dest) {
190 map<string, bufferlist>::iterator iter = attrset.find(name);
191 if (iter != attrset.end()) {
192 dest = iter->second;
193 return true;
194 }
195 return false;
196 }
197 };
198
199 class RGWFetchObjFilter {
200 public:
201 virtual ~RGWFetchObjFilter() {}
202
203 virtual int filter(CephContext *cct,
204 const rgw_obj_key& source_key,
205 const RGWBucketInfo& dest_bucket_info,
206 std::optional<rgw_placement_rule> dest_placement_rule,
207 const map<string, bufferlist>& obj_attrs,
208 std::optional<rgw_user> *poverride_owner,
209 const rgw_placement_rule **prule) = 0;
210 };
211
212 class RGWFetchObjFilter_Default : public RGWFetchObjFilter {
213 protected:
214 rgw_placement_rule dest_rule;
215 public:
216 RGWFetchObjFilter_Default() {}
217
218 int filter(CephContext *cct,
219 const rgw_obj_key& source_key,
220 const RGWBucketInfo& dest_bucket_info,
221 std::optional<rgw_placement_rule> dest_placement_rule,
222 const map<string, bufferlist>& obj_attrs,
223 std::optional<rgw_user> *poverride_owner,
224 const rgw_placement_rule **prule) override;
225 };
226
227 class RGWObjectCtx {
228 rgw::sal::RGWRadosStore *store;
229 ceph::shared_mutex lock = ceph::make_shared_mutex("RGWObjectCtx");
230 void *s{nullptr};
231
232 std::map<rgw_obj, RGWObjState> objs_state;
233 public:
234 explicit RGWObjectCtx(rgw::sal::RGWRadosStore *_store) : store(_store) {}
235 explicit RGWObjectCtx(rgw::sal::RGWRadosStore *_store, void *_s) : store(_store), s(_s) {}
236
237 void *get_private() {
238 return s;
239 }
240
241 rgw::sal::RGWRadosStore *get_store() {
242 return store;
243 }
244
245 RGWObjState *get_state(const rgw_obj& obj);
246
247 void set_atomic(rgw_obj& obj);
248 void set_prefetch_data(const rgw_obj& obj);
249 void invalidate(const rgw_obj& obj);
250 };
251
252
253 struct RGWRawObjState {
254 rgw_raw_obj obj;
255 bool has_attrs{false};
256 bool exists{false};
257 uint64_t size{0};
258 ceph::real_time mtime;
259 uint64_t epoch{0};
260 bufferlist obj_tag;
261 bool has_data{false};
262 bufferlist data;
263 bool prefetch_data{false};
264 uint64_t pg_ver{0};
265
266 /* important! don't forget to update copy constructor */
267
268 RGWObjVersionTracker objv_tracker;
269
270 map<string, bufferlist> attrset;
271 RGWRawObjState() {}
272 RGWRawObjState(const RGWRawObjState& rhs) : obj (rhs.obj) {
273 has_attrs = rhs.has_attrs;
274 exists = rhs.exists;
275 size = rhs.size;
276 mtime = rhs.mtime;
277 epoch = rhs.epoch;
278 if (rhs.obj_tag.length()) {
279 obj_tag = rhs.obj_tag;
280 }
281 has_data = rhs.has_data;
282 if (rhs.data.length()) {
283 data = rhs.data;
284 }
285 prefetch_data = rhs.prefetch_data;
286 pg_ver = rhs.pg_ver;
287 objv_tracker = rhs.objv_tracker;
288 }
289 };
290
291 struct RGWPoolIterCtx {
292 librados::IoCtx io_ctx;
293 librados::NObjectIterator iter;
294 };
295
296 struct RGWListRawObjsCtx {
297 bool initialized;
298 RGWPoolIterCtx iter_ctx;
299
300 RGWListRawObjsCtx() : initialized(false) {}
301 };
302
303 struct objexp_hint_entry {
304 string tenant;
305 string bucket_name;
306 string bucket_id;
307 rgw_obj_key obj_key;
308 ceph::real_time exp_time;
309
310 void encode(bufferlist& bl) const {
311 ENCODE_START(2, 1, bl);
312 encode(bucket_name, bl);
313 encode(bucket_id, bl);
314 encode(obj_key, bl);
315 encode(exp_time, bl);
316 encode(tenant, bl);
317 ENCODE_FINISH(bl);
318 }
319
320 void decode(bufferlist::const_iterator& bl) {
321 // XXX Do we want DECODE_START_LEGACY_COMPAT_LEN(2, 1, 1, bl); ?
322 DECODE_START(2, bl);
323 decode(bucket_name, bl);
324 decode(bucket_id, bl);
325 decode(obj_key, bl);
326 decode(exp_time, bl);
327 if (struct_v >= 2) {
328 decode(tenant, bl);
329 } else {
330 tenant.clear();
331 }
332 DECODE_FINISH(bl);
333 }
334
335 void dump(Formatter *f) const;
336 static void generate_test_instances(list<objexp_hint_entry*>& o);
337 };
338 WRITE_CLASS_ENCODER(objexp_hint_entry)
339
340 class RGWDataChangesLog;
341 class RGWMetaSyncStatusManager;
342 class RGWDataSyncStatusManager;
343 class RGWCoroutinesManagerRegistry;
344
345 class RGWGetBucketStats_CB : public RefCountedObject {
346 protected:
347 rgw_bucket bucket;
348 map<RGWObjCategory, RGWStorageStats> *stats;
349 public:
350 explicit RGWGetBucketStats_CB(const rgw_bucket& _bucket) : bucket(_bucket), stats(NULL) {}
351 ~RGWGetBucketStats_CB() override {}
352 virtual void handle_response(int r) = 0;
353 virtual void set_response(map<RGWObjCategory, RGWStorageStats> *_stats) {
354 stats = _stats;
355 }
356 };
357
358 class RGWGetUserStats_CB : public RefCountedObject {
359 protected:
360 rgw_user user;
361 RGWStorageStats stats;
362 public:
363 explicit RGWGetUserStats_CB(const rgw_user& _user) : user(_user) {}
364 ~RGWGetUserStats_CB() override {}
365 virtual void handle_response(int r) = 0;
366 virtual void set_response(RGWStorageStats& _stats) {
367 stats = _stats;
368 }
369 };
370
371 class RGWGetDirHeader_CB;
372 class RGWGetUserHeader_CB;
373 namespace rgw { namespace sal {
374 class RGWRadosStore;
375 class MPRadosSerializer;
376 class LCRadosSerializer;
377 } }
378
379 class RGWAsyncRadosProcessor;
380
381 template <class T>
382 class RGWChainedCacheImpl;
383
384 struct bucket_info_entry {
385 RGWBucketInfo info;
386 real_time mtime;
387 map<string, bufferlist> attrs;
388 };
389
390 struct tombstone_entry;
391
392 template <class K, class V>
393 class lru_map;
394 using tombstone_cache_t = lru_map<rgw_obj, tombstone_entry>;
395
396 class RGWIndexCompletionManager;
397
398 class RGWRados
399 {
400 friend class RGWGC;
401 friend class RGWMetaNotifier;
402 friend class RGWDataNotifier;
403 friend class RGWObjectExpirer;
404 friend class RGWMetaSyncProcessorThread;
405 friend class RGWDataSyncProcessorThread;
406 friend class RGWReshard;
407 friend class RGWBucketReshard;
408 friend class RGWBucketReshardLock;
409 friend class BucketIndexLockGuard;
410 friend class rgw::sal::MPRadosSerializer;
411 friend class rgw::sal::LCRadosSerializer;
412 friend class rgw::sal::RGWRadosStore;
413
414 /** Open the pool used as root for this gateway */
415 int open_root_pool_ctx(const DoutPrefixProvider *dpp);
416 int open_gc_pool_ctx(const DoutPrefixProvider *dpp);
417 int open_lc_pool_ctx(const DoutPrefixProvider *dpp);
418 int open_objexp_pool_ctx(const DoutPrefixProvider *dpp);
419 int open_reshard_pool_ctx(const DoutPrefixProvider *dpp);
420 int open_notif_pool_ctx(const DoutPrefixProvider *dpp);
421
422 int open_pool_ctx(const DoutPrefixProvider *dpp, const rgw_pool& pool, librados::IoCtx& io_ctx,
423 bool mostly_omap);
424
425 std::atomic<int64_t> max_req_id = { 0 };
426 ceph::mutex lock = ceph::make_mutex("rados_timer_lock");
427 SafeTimer *timer;
428
429 rgw::sal::RGWRadosStore *store;
430 RGWGC *gc = nullptr;
431 RGWLC *lc;
432 RGWObjectExpirer *obj_expirer;
433 bool use_gc_thread;
434 bool use_lc_thread;
435 bool quota_threads;
436 bool run_sync_thread;
437 bool run_reshard_thread;
438
439 RGWMetaNotifier *meta_notifier;
440 RGWDataNotifier *data_notifier;
441 RGWMetaSyncProcessorThread *meta_sync_processor_thread;
442 RGWSyncTraceManager *sync_tracer = nullptr;
443 map<rgw_zone_id, RGWDataSyncProcessorThread *> data_sync_processor_threads;
444
445 boost::optional<rgw::BucketTrimManager> bucket_trim;
446 RGWSyncLogTrimThread *sync_log_trimmer{nullptr};
447
448 ceph::mutex meta_sync_thread_lock = ceph::make_mutex("meta_sync_thread_lock");
449 ceph::mutex data_sync_thread_lock = ceph::make_mutex("data_sync_thread_lock");
450
451 librados::IoCtx root_pool_ctx; // .rgw
452
453 double inject_notify_timeout_probability = 0;
454 unsigned max_notify_retries = 0;
455
456 friend class RGWWatcher;
457
458 ceph::mutex bucket_id_lock = ceph::make_mutex("rados_bucket_id");
459
460 // This field represents the number of bucket index object shards
461 uint32_t bucket_index_max_shards;
462
463 int get_obj_head_ref(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj, rgw_rados_ref *ref);
464 int get_system_obj_ref(const DoutPrefixProvider *dpp, const rgw_raw_obj& obj, rgw_rados_ref *ref);
465 uint64_t max_bucket_id;
466
467 int get_olh_target_state(const DoutPrefixProvider *dpp, RGWObjectCtx& rctx, const RGWBucketInfo& bucket_info, const rgw_obj& obj,
468 RGWObjState *olh_state, RGWObjState **target_state, optional_yield y);
469 int get_obj_state_impl(const DoutPrefixProvider *dpp, RGWObjectCtx *rctx, const RGWBucketInfo& bucket_info, const rgw_obj& obj, RGWObjState **state,
470 bool follow_olh, optional_yield y, bool assume_noent = false);
471 int append_atomic_test(const DoutPrefixProvider *dpp, RGWObjectCtx *rctx, const RGWBucketInfo& bucket_info, const rgw_obj& obj,
472 librados::ObjectOperation& op, RGWObjState **state, optional_yield y);
473 int append_atomic_test(const DoutPrefixProvider *dpp, const RGWObjState* astate, librados::ObjectOperation& op);
474
475 int update_placement_map();
476 int store_bucket_info(RGWBucketInfo& info, map<string, bufferlist> *pattrs, RGWObjVersionTracker *objv_tracker, bool exclusive);
477
478 void remove_rgw_head_obj(librados::ObjectWriteOperation& op);
479 void cls_obj_check_prefix_exist(librados::ObjectOperation& op, const string& prefix, bool fail_if_exist);
480 void cls_obj_check_mtime(librados::ObjectOperation& op, const real_time& mtime, bool high_precision_time, RGWCheckMTimeType type);
481 protected:
482 CephContext *cct;
483
484 librados::Rados rados;
485
486 using RGWChainedCacheImpl_bucket_info_entry = RGWChainedCacheImpl<bucket_info_entry>;
487 RGWChainedCacheImpl_bucket_info_entry *binfo_cache;
488
489 tombstone_cache_t *obj_tombstone_cache;
490
491 librados::IoCtx gc_pool_ctx; // .rgw.gc
492 librados::IoCtx lc_pool_ctx; // .rgw.lc
493 librados::IoCtx objexp_pool_ctx;
494 librados::IoCtx reshard_pool_ctx;
495 librados::IoCtx notif_pool_ctx; // .rgw.notif
496
497 bool pools_initialized;
498
499 RGWQuotaHandler *quota_handler;
500
501 RGWCoroutinesManagerRegistry *cr_registry;
502
503 RGWSyncModuleInstanceRef sync_module;
504 bool writeable_zone{false};
505
506 RGWIndexCompletionManager *index_completion_manager{nullptr};
507
508 bool use_cache{false};
509 bool use_gc{true};
510
511 int get_obj_head_ioctx(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj, librados::IoCtx *ioctx);
512 public:
513 RGWRados(): timer(NULL),
514 gc(NULL), lc(NULL), obj_expirer(NULL), use_gc_thread(false), use_lc_thread(false), quota_threads(false),
515 run_sync_thread(false), run_reshard_thread(false), meta_notifier(NULL),
516 data_notifier(NULL), meta_sync_processor_thread(NULL),
517 bucket_index_max_shards(0),
518 max_bucket_id(0), cct(NULL),
519 binfo_cache(NULL), obj_tombstone_cache(nullptr),
520 pools_initialized(false),
521 quota_handler(NULL),
522 cr_registry(NULL),
523 pctl(&ctl),
524 reshard(NULL) {}
525
526 RGWRados& set_use_cache(bool status) {
527 use_cache = status;
528 return *this;
529 }
530
531 RGWRados& set_use_gc(bool status) {
532 use_gc = status;
533 return *this;
534 }
535
536 RGWLC *get_lc() {
537 return lc;
538 }
539
540 RGWRados& set_run_gc_thread(bool _use_gc_thread) {
541 use_gc_thread = _use_gc_thread;
542 return *this;
543 }
544
545 RGWRados& set_run_lc_thread(bool _use_lc_thread) {
546 use_lc_thread = _use_lc_thread;
547 return *this;
548 }
549
550 RGWRados& set_run_quota_threads(bool _run_quota_threads) {
551 quota_threads = _run_quota_threads;
552 return *this;
553 }
554
555 RGWRados& set_run_sync_thread(bool _run_sync_thread) {
556 run_sync_thread = _run_sync_thread;
557 return *this;
558 }
559
560 RGWRados& set_run_reshard_thread(bool _run_reshard_thread) {
561 run_reshard_thread = _run_reshard_thread;
562 return *this;
563 }
564
565 uint64_t get_new_req_id() {
566 return ++max_req_id;
567 }
568
569 librados::IoCtx* get_lc_pool_ctx() {
570 return &lc_pool_ctx;
571 }
572
573 librados::IoCtx& get_notif_pool_ctx() {
574 return notif_pool_ctx;
575 }
576
577 void set_context(CephContext *_cct) {
578 cct = _cct;
579 }
580 void set_store(rgw::sal::RGWRadosStore *_store) {
581 store = _store;
582 }
583
584 RGWServices svc;
585 RGWCtl ctl;
586
587 RGWCtl *pctl{nullptr};
588
589 /**
590 * AmazonS3 errors contain a HostId string, but is an opaque base64 blob; we
591 * try to be more transparent. This has a wrapper so we can update it when zonegroup/zone are changed.
592 */
593 string host_id;
594
595 RGWReshard *reshard;
596 std::shared_ptr<RGWReshardWait> reshard_wait;
597
598 virtual ~RGWRados() = default;
599
600 tombstone_cache_t *get_tombstone_cache() {
601 return obj_tombstone_cache;
602 }
603 const RGWSyncModuleInstanceRef& get_sync_module() {
604 return sync_module;
605 }
606 RGWSyncTraceManager *get_sync_tracer() {
607 return sync_tracer;
608 }
609
610 int get_required_alignment(const DoutPrefixProvider *dpp, const rgw_pool& pool, uint64_t *alignment);
611 void get_max_aligned_size(uint64_t size, uint64_t alignment, uint64_t *max_size);
612 int get_max_chunk_size(const rgw_pool& pool, uint64_t *max_chunk_size, const DoutPrefixProvider *dpp, uint64_t *palignment = nullptr);
613 int get_max_chunk_size(const rgw_placement_rule& placement_rule, const rgw_obj& obj, uint64_t *max_chunk_size, const DoutPrefixProvider *dpp, uint64_t *palignment = nullptr);
614
615 uint32_t get_max_bucket_shards() {
616 return RGWSI_BucketIndex_RADOS::shards_max();
617 }
618
619
620 int get_raw_obj_ref(const DoutPrefixProvider *dpp, const rgw_raw_obj& obj, rgw_rados_ref *ref);
621
622 int list_raw_objects_init(const DoutPrefixProvider *dpp, const rgw_pool& pool, const string& marker, RGWListRawObjsCtx *ctx);
623 int list_raw_objects_next(const DoutPrefixProvider *dpp, const string& prefix_filter, int max,
624 RGWListRawObjsCtx& ctx, list<string>& oids,
625 bool *is_truncated);
626 int list_raw_objects(const DoutPrefixProvider *dpp, const rgw_pool& pool, const string& prefix_filter, int max,
627 RGWListRawObjsCtx& ctx, list<string>& oids,
628 bool *is_truncated);
629 string list_raw_objs_get_cursor(RGWListRawObjsCtx& ctx);
630
631 CephContext *ctx() { return cct; }
632 /** do all necessary setup of the storage device */
633 int initialize(CephContext *_cct, const DoutPrefixProvider *dpp) {
634 set_context(_cct);
635 return initialize(dpp);
636 }
637 /** Initialize the RADOS instance and prepare to do other ops */
638 int init_svc(bool raw, const DoutPrefixProvider *dpp);
639 int init_ctl(const DoutPrefixProvider *dpp);
640 int init_rados();
641 int init_complete(const DoutPrefixProvider *dpp);
642 int initialize(const DoutPrefixProvider *dpp);
643 void finalize();
644
645 int register_to_service_map(const string& daemon_type, const map<string, string>& meta);
646 int update_service_map(std::map<std::string, std::string>&& status);
647
648 /// list logs
649 int log_list_init(const DoutPrefixProvider *dpp, const string& prefix, RGWAccessHandle *handle);
650 int log_list_next(RGWAccessHandle handle, string *name);
651
652 /// remove log
653 int log_remove(const DoutPrefixProvider *dpp, const string& name);
654
655 /// show log
656 int log_show_init(const DoutPrefixProvider *dpp, const string& name, RGWAccessHandle *handle);
657 int log_show_next(RGWAccessHandle handle, rgw_log_entry *entry);
658
659 // log bandwidth info
660 int log_usage(const DoutPrefixProvider *dpp, map<rgw_user_bucket, RGWUsageBatch>& usage_info);
661 int read_usage(const DoutPrefixProvider *dpp, const rgw_user& user, const string& bucket_name, uint64_t start_epoch, uint64_t end_epoch,
662 uint32_t max_entries, bool *is_truncated, RGWUsageIter& read_iter, map<rgw_user_bucket,
663 rgw_usage_log_entry>& usage);
664 int trim_usage(const DoutPrefixProvider *dpp, const rgw_user& user, const string& bucket_name, uint64_t start_epoch, uint64_t end_epoch);
665 int clear_usage(const DoutPrefixProvider *dpp);
666
667 int create_pool(const DoutPrefixProvider *dpp, const rgw_pool& pool);
668
669 void create_bucket_id(string *bucket_id);
670
671 bool get_obj_data_pool(const rgw_placement_rule& placement_rule, const rgw_obj& obj, rgw_pool *pool);
672 bool obj_to_raw(const rgw_placement_rule& placement_rule, const rgw_obj& obj, rgw_raw_obj *raw_obj);
673
674 int create_bucket(const RGWUserInfo& owner, rgw_bucket& bucket,
675 const string& zonegroup_id,
676 const rgw_placement_rule& placement_rule,
677 const string& swift_ver_location,
678 const RGWQuotaInfo * pquota_info,
679 map<std::string,bufferlist>& attrs,
680 RGWBucketInfo& bucket_info,
681 obj_version *pobjv,
682 obj_version *pep_objv,
683 ceph::real_time creation_time,
684 rgw_bucket *master_bucket,
685 uint32_t *master_num_shards,
686 optional_yield y,
687 const DoutPrefixProvider *dpp,
688 bool exclusive = true);
689
690 RGWCoroutinesManagerRegistry *get_cr_registry() { return cr_registry; }
691
692 struct BucketShard {
693 RGWRados *store;
694 rgw_bucket bucket;
695 int shard_id;
696 RGWSI_RADOS::Obj bucket_obj;
697
698 explicit BucketShard(RGWRados *_store) : store(_store), shard_id(-1) {}
699 int init(const rgw_bucket& _bucket, const rgw_obj& obj, RGWBucketInfo* out, const DoutPrefixProvider *dpp);
700 int init(const rgw_bucket& _bucket, int sid, const rgw::bucket_index_layout_generation& idx_layout, RGWBucketInfo* out, const DoutPrefixProvider *dpp);
701 int init(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj);
702 int init(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw::bucket_index_layout_generation& idx_layout, int sid);
703 };
704
705 class Object {
706 RGWRados *store;
707 RGWBucketInfo bucket_info;
708 RGWObjectCtx& ctx;
709 rgw_obj obj;
710
711 BucketShard bs;
712
713 RGWObjState *state;
714
715 bool versioning_disabled;
716
717 bool bs_initialized;
718
719 protected:
720 int get_state(const DoutPrefixProvider *dpp, RGWObjState **pstate, bool follow_olh, optional_yield y, bool assume_noent = false);
721 void invalidate_state();
722
723 int prepare_atomic_modification(const DoutPrefixProvider *dpp, librados::ObjectWriteOperation& op, bool reset_obj, const string *ptag,
724 const char *ifmatch, const char *ifnomatch, bool removal_op, bool modify_tail, optional_yield y);
725 int complete_atomic_modification(const DoutPrefixProvider *dpp);
726
727 public:
728 Object(RGWRados *_store, const RGWBucketInfo& _bucket_info, RGWObjectCtx& _ctx, const rgw_obj& _obj) : store(_store), bucket_info(_bucket_info),
729 ctx(_ctx), obj(_obj), bs(store),
730 state(NULL), versioning_disabled(false),
731 bs_initialized(false) {}
732
733 RGWRados *get_store() { return store; }
734 rgw_obj& get_obj() { return obj; }
735 RGWObjectCtx& get_ctx() { return ctx; }
736 RGWBucketInfo& get_bucket_info() { return bucket_info; }
737 int get_manifest(const DoutPrefixProvider *dpp, RGWObjManifest **pmanifest, optional_yield y);
738
739 int get_bucket_shard(BucketShard **pbs, const DoutPrefixProvider *dpp) {
740 if (!bs_initialized) {
741 int r =
742 bs.init(bucket_info.bucket, obj, nullptr /* no RGWBucketInfo */, dpp);
743 if (r < 0) {
744 return r;
745 }
746 bs_initialized = true;
747 }
748 *pbs = &bs;
749 return 0;
750 }
751
752 void set_versioning_disabled(bool status) {
753 versioning_disabled = status;
754 }
755
756 bool versioning_enabled() {
757 return (!versioning_disabled && bucket_info.versioning_enabled());
758 }
759
760 struct Read {
761 RGWRados::Object *source;
762
763 struct GetObjState {
764 map<rgw_pool, librados::IoCtx> io_ctxs;
765 rgw_pool cur_pool;
766 librados::IoCtx *cur_ioctx{nullptr};
767 rgw_obj obj;
768 rgw_raw_obj head_obj;
769 } state;
770
771 struct ConditionParams {
772 const ceph::real_time *mod_ptr;
773 const ceph::real_time *unmod_ptr;
774 bool high_precision_time;
775 uint32_t mod_zone_id;
776 uint64_t mod_pg_ver;
777 const char *if_match;
778 const char *if_nomatch;
779
780 ConditionParams() :
781 mod_ptr(NULL), unmod_ptr(NULL), high_precision_time(false), mod_zone_id(0), mod_pg_ver(0),
782 if_match(NULL), if_nomatch(NULL) {}
783 } conds;
784
785 struct Params {
786 ceph::real_time *lastmod;
787 uint64_t *obj_size;
788 map<string, bufferlist> *attrs;
789 rgw_obj *target_obj;
790
791 Params() : lastmod(nullptr), obj_size(nullptr), attrs(nullptr),
792 target_obj(nullptr) {}
793 } params;
794
795 explicit Read(RGWRados::Object *_source) : source(_source) {}
796
797 int prepare(optional_yield y, const DoutPrefixProvider *dpp);
798 static int range_to_ofs(uint64_t obj_size, int64_t &ofs, int64_t &end);
799 int read(int64_t ofs, int64_t end, bufferlist& bl, optional_yield y, const DoutPrefixProvider *dpp);
800 int iterate(const DoutPrefixProvider *dpp, int64_t ofs, int64_t end, RGWGetDataCB *cb, optional_yield y);
801 int get_attr(const DoutPrefixProvider *dpp, const char *name, bufferlist& dest, optional_yield y);
802 };
803
804 struct Write {
805 RGWRados::Object *target;
806
807 struct MetaParams {
808 ceph::real_time *mtime;
809 map<std::string, bufferlist>* rmattrs;
810 const bufferlist *data;
811 RGWObjManifest *manifest;
812 const string *ptag;
813 list<rgw_obj_index_key> *remove_objs;
814 ceph::real_time set_mtime;
815 rgw_user owner;
816 RGWObjCategory category;
817 int flags;
818 const char *if_match;
819 const char *if_nomatch;
820 std::optional<uint64_t> olh_epoch;
821 ceph::real_time delete_at;
822 bool canceled;
823 const string *user_data;
824 rgw_zone_set *zones_trace;
825 bool modify_tail;
826 bool completeMultipart;
827 bool appendable;
828
829 MetaParams() : mtime(NULL), rmattrs(NULL), data(NULL), manifest(NULL), ptag(NULL),
830 remove_objs(NULL), category(RGWObjCategory::Main), flags(0),
831 if_match(NULL), if_nomatch(NULL), canceled(false), user_data(nullptr), zones_trace(nullptr),
832 modify_tail(false), completeMultipart(false), appendable(false) {}
833 } meta;
834
835 explicit Write(RGWRados::Object *_target) : target(_target) {}
836
837 int _do_write_meta(const DoutPrefixProvider *dpp,
838 uint64_t size, uint64_t accounted_size,
839 map<std::string, bufferlist>& attrs,
840 bool modify_tail, bool assume_noent,
841 void *index_op, optional_yield y);
842 int write_meta(const DoutPrefixProvider *dpp, uint64_t size, uint64_t accounted_size,
843 map<std::string, bufferlist>& attrs, optional_yield y);
844 int write_data(const char *data, uint64_t ofs, uint64_t len, bool exclusive);
845 const req_state* get_req_state() {
846 return (req_state *)target->get_ctx().get_private();
847 }
848 };
849
850 struct Delete {
851 RGWRados::Object *target;
852
853 struct DeleteParams {
854 rgw_user bucket_owner;
855 int versioning_status; // versioning flags in enum RGWBucketFlags
856 ACLOwner obj_owner; // needed for creation of deletion marker
857 uint64_t olh_epoch;
858 string marker_version_id;
859 uint32_t bilog_flags;
860 list<rgw_obj_index_key> *remove_objs;
861 ceph::real_time expiration_time;
862 ceph::real_time unmod_since;
863 ceph::real_time mtime; /* for setting delete marker mtime */
864 bool high_precision_time;
865 rgw_zone_set *zones_trace;
866 bool abortmp;
867 uint64_t parts_accounted_size;
868
869 DeleteParams() : versioning_status(0), olh_epoch(0), bilog_flags(0), remove_objs(NULL), high_precision_time(false), zones_trace(nullptr), abortmp(false), parts_accounted_size(0) {}
870 } params;
871
872 struct DeleteResult {
873 bool delete_marker;
874 string version_id;
875
876 DeleteResult() : delete_marker(false) {}
877 } result;
878
879 explicit Delete(RGWRados::Object *_target) : target(_target) {}
880
881 int delete_obj(optional_yield y, const DoutPrefixProvider *dpp);
882 };
883
884 struct Stat {
885 RGWRados::Object *source;
886
887 struct Result {
888 rgw_obj obj;
889 std::optional<RGWObjManifest> manifest;
890 uint64_t size{0};
891 struct timespec mtime {};
892 map<string, bufferlist> attrs;
893 } result;
894
895 struct State {
896 librados::IoCtx io_ctx;
897 librados::AioCompletion *completion;
898 int ret;
899
900 State() : completion(NULL), ret(0) {}
901 } state;
902
903
904 explicit Stat(RGWRados::Object *_source) : source(_source) {}
905
906 int stat_async(const DoutPrefixProvider *dpp);
907 int wait();
908 int stat();
909 private:
910 int finish();
911 };
912 };
913
914 class Bucket {
915 RGWRados *store;
916 RGWBucketInfo bucket_info;
917 rgw_bucket& bucket;
918 int shard_id;
919
920 public:
921 Bucket(RGWRados *_store, const RGWBucketInfo& _bucket_info) : store(_store), bucket_info(_bucket_info), bucket(bucket_info.bucket),
922 shard_id(RGW_NO_SHARD) {}
923 RGWRados *get_store() { return store; }
924 rgw_bucket& get_bucket() { return bucket; }
925 RGWBucketInfo& get_bucket_info() { return bucket_info; }
926
927 int update_bucket_id(const string& new_bucket_id, const DoutPrefixProvider *dpp);
928
929 int get_shard_id() { return shard_id; }
930 void set_shard_id(int id) {
931 shard_id = id;
932 }
933
934 class UpdateIndex {
935 RGWRados::Bucket *target;
936 string optag;
937 rgw_obj obj;
938 uint16_t bilog_flags{0};
939 BucketShard bs;
940 bool bs_initialized{false};
941 bool blind;
942 bool prepared{false};
943 rgw_zone_set *zones_trace{nullptr};
944
945 int init_bs(const DoutPrefixProvider *dpp) {
946 int r =
947 bs.init(target->get_bucket(), obj, nullptr /* no RGWBucketInfo */, dpp);
948 if (r < 0) {
949 return r;
950 }
951 bs_initialized = true;
952 return 0;
953 }
954
955 void invalidate_bs() {
956 bs_initialized = false;
957 }
958
959 int guard_reshard(const DoutPrefixProvider *dpp, BucketShard **pbs, std::function<int(BucketShard *)> call);
960 public:
961
962 UpdateIndex(RGWRados::Bucket *_target, const rgw_obj& _obj) : target(_target), obj(_obj),
963 bs(target->get_store()) {
964 blind = (target->get_bucket_info().layout.current_index.layout.type == rgw::BucketIndexType::Indexless);
965 }
966
967 int get_bucket_shard(BucketShard **pbs, const DoutPrefixProvider *dpp) {
968 if (!bs_initialized) {
969 int r = init_bs(dpp);
970 if (r < 0) {
971 return r;
972 }
973 }
974 *pbs = &bs;
975 return 0;
976 }
977
978 void set_bilog_flags(uint16_t flags) {
979 bilog_flags = flags;
980 }
981
982 void set_zones_trace(rgw_zone_set *_zones_trace) {
983 zones_trace = _zones_trace;
984 }
985
986 int prepare(const DoutPrefixProvider *dpp, RGWModifyOp, const string *write_tag, optional_yield y);
987 int complete(const DoutPrefixProvider *dpp, int64_t poolid, uint64_t epoch, uint64_t size,
988 uint64_t accounted_size, ceph::real_time& ut,
989 const string& etag, const string& content_type,
990 const string& storage_class,
991 bufferlist *acl_bl, RGWObjCategory category,
992 list<rgw_obj_index_key> *remove_objs, const string *user_data = nullptr, bool appendable = false);
993 int complete_del(const DoutPrefixProvider *dpp,
994 int64_t poolid, uint64_t epoch,
995 ceph::real_time& removed_mtime, /* mtime of removed object */
996 list<rgw_obj_index_key> *remove_objs);
997 int cancel(const DoutPrefixProvider *dpp);
998
999 const string *get_optag() { return &optag; }
1000
1001 bool is_prepared() { return prepared; }
1002 }; // class UpdateIndex
1003
1004 class List {
1005 protected:
1006 // absolute maximum number of objects that
1007 // list_objects_(un)ordered can return
1008 static constexpr int64_t bucket_list_objects_absolute_max = 25000;
1009
1010 RGWRados::Bucket *target;
1011 rgw_obj_key next_marker;
1012
1013 int list_objects_ordered(const DoutPrefixProvider *dpp,
1014 int64_t max,
1015 vector<rgw_bucket_dir_entry> *result,
1016 map<string, bool> *common_prefixes,
1017 bool *is_truncated,
1018 optional_yield y);
1019 int list_objects_unordered(const DoutPrefixProvider *dpp,
1020 int64_t max,
1021 vector<rgw_bucket_dir_entry> *result,
1022 map<string, bool> *common_prefixes,
1023 bool *is_truncated,
1024 optional_yield y);
1025
1026 public:
1027
1028 struct Params {
1029 string prefix;
1030 string delim;
1031 rgw_obj_key marker;
1032 rgw_obj_key end_marker;
1033 string ns;
1034 bool enforce_ns;
1035 RGWAccessListFilter *filter;
1036 bool list_versions;
1037 bool allow_unordered;
1038
1039 Params() :
1040 enforce_ns(true),
1041 filter(NULL),
1042 list_versions(false),
1043 allow_unordered(false)
1044 {}
1045 } params;
1046
1047 explicit List(RGWRados::Bucket *_target) : target(_target) {}
1048
1049 int list_objects(const DoutPrefixProvider *dpp, int64_t max,
1050 vector<rgw_bucket_dir_entry> *result,
1051 map<string, bool> *common_prefixes,
1052 bool *is_truncated,
1053 optional_yield y) {
1054 if (params.allow_unordered) {
1055 return list_objects_unordered(dpp, max, result, common_prefixes,
1056 is_truncated, y);
1057 } else {
1058 return list_objects_ordered(dpp, max, result, common_prefixes,
1059 is_truncated, y);
1060 }
1061 }
1062 rgw_obj_key& get_next_marker() {
1063 return next_marker;
1064 }
1065 }; // class List
1066 }; // class Bucket
1067
1068 int on_last_entry_in_listing(const DoutPrefixProvider *dpp,
1069 RGWBucketInfo& bucket_info,
1070 const std::string& obj_prefix,
1071 const std::string& obj_delim,
1072 std::function<int(const rgw_bucket_dir_entry&)> handler);
1073
1074 bool swift_versioning_enabled(rgw::sal::RGWBucket* bucket) const;
1075
1076 int swift_versioning_copy(RGWObjectCtx& obj_ctx, /* in/out */
1077 const rgw_user& user, /* in */
1078 rgw::sal::RGWBucket* bucket, /* in */
1079 rgw::sal::RGWObject* obj, /* in */
1080 const DoutPrefixProvider *dpp, /* in/out */
1081 optional_yield y); /* in */
1082 int swift_versioning_restore(RGWObjectCtx& obj_ctx, /* in/out */
1083 const rgw_user& user, /* in */
1084 rgw::sal::RGWBucket* bucket, /* in */
1085 rgw::sal::RGWObject* obj, /* in */
1086 bool& restored, /* out */
1087 const DoutPrefixProvider *dpp); /* in/out */
1088 int copy_obj_to_remote_dest(const DoutPrefixProvider *dpp,
1089 RGWObjState *astate,
1090 map<string, bufferlist>& src_attrs,
1091 RGWRados::Object::Read& read_op,
1092 const rgw_user& user_id,
1093 rgw::sal::RGWObject* dest_obj,
1094 ceph::real_time *mtime);
1095
1096 enum AttrsMod {
1097 ATTRSMOD_NONE = 0,
1098 ATTRSMOD_REPLACE = 1,
1099 ATTRSMOD_MERGE = 2
1100 };
1101
1102 int rewrite_obj(RGWBucketInfo& dest_bucket_info, rgw::sal::RGWObject* obj, const DoutPrefixProvider *dpp, optional_yield y);
1103
1104 int stat_remote_obj(const DoutPrefixProvider *dpp,
1105 RGWObjectCtx& obj_ctx,
1106 const rgw_user& user_id,
1107 req_info *info,
1108 const rgw_zone_id& source_zone,
1109 rgw::sal::RGWObject* src_obj,
1110 const RGWBucketInfo *src_bucket_info,
1111 real_time *src_mtime,
1112 uint64_t *psize,
1113 const real_time *mod_ptr,
1114 const real_time *unmod_ptr,
1115 bool high_precision_time,
1116 const char *if_match,
1117 const char *if_nomatch,
1118 map<string, bufferlist> *pattrs,
1119 map<string, string> *pheaders,
1120 string *version_id,
1121 string *ptag,
1122 string *petag);
1123
1124 int fetch_remote_obj(RGWObjectCtx& obj_ctx,
1125 const rgw_user& user_id,
1126 req_info *info,
1127 const rgw_zone_id& source_zone,
1128 rgw::sal::RGWObject* dest_obj,
1129 rgw::sal::RGWObject* src_obj,
1130 rgw::sal::RGWBucket* dest_bucket,
1131 rgw::sal::RGWBucket* src_bucket,
1132 std::optional<rgw_placement_rule> dest_placement,
1133 ceph::real_time *src_mtime,
1134 ceph::real_time *mtime,
1135 const ceph::real_time *mod_ptr,
1136 const ceph::real_time *unmod_ptr,
1137 bool high_precision_time,
1138 const char *if_match,
1139 const char *if_nomatch,
1140 AttrsMod attrs_mod,
1141 bool copy_if_newer,
1142 rgw::sal::RGWAttrs& attrs,
1143 RGWObjCategory category,
1144 std::optional<uint64_t> olh_epoch,
1145 ceph::real_time delete_at,
1146 string *ptag,
1147 string *petag,
1148 void (*progress_cb)(off_t, void *),
1149 void *progress_data,
1150 const DoutPrefixProvider *dpp,
1151 RGWFetchObjFilter *filter,
1152 rgw_zone_set *zones_trace= nullptr,
1153 std::optional<uint64_t>* bytes_transferred = 0);
1154 /**
1155 * Copy an object.
1156 * dest_obj: the object to copy into
1157 * src_obj: the object to copy from
1158 * attrs: usage depends on attrs_mod parameter
1159 * attrs_mod: the modification mode of the attrs, may have the following values:
1160 * ATTRSMOD_NONE - the attributes of the source object will be
1161 * copied without modifications, attrs parameter is ignored;
1162 * ATTRSMOD_REPLACE - new object will have the attributes provided by attrs
1163 * parameter, source object attributes are not copied;
1164 * ATTRSMOD_MERGE - any conflicting meta keys on the source object's attributes
1165 * are overwritten by values contained in attrs parameter.
1166 * Returns: 0 on success, -ERR# otherwise.
1167 */
1168 int copy_obj(RGWObjectCtx& obj_ctx,
1169 const rgw_user& user_id,
1170 req_info *info,
1171 const rgw_zone_id& source_zone,
1172 rgw::sal::RGWObject* dest_obj,
1173 rgw::sal::RGWObject* src_obj,
1174 rgw::sal::RGWBucket* dest_bucket,
1175 rgw::sal::RGWBucket* src_bucket,
1176 const rgw_placement_rule& dest_placement,
1177 ceph::real_time *src_mtime,
1178 ceph::real_time *mtime,
1179 const ceph::real_time *mod_ptr,
1180 const ceph::real_time *unmod_ptr,
1181 bool high_precision_time,
1182 const char *if_match,
1183 const char *if_nomatch,
1184 AttrsMod attrs_mod,
1185 bool copy_if_newer,
1186 map<std::string, bufferlist>& attrs,
1187 RGWObjCategory category,
1188 uint64_t olh_epoch,
1189 ceph::real_time delete_at,
1190 string *version_id,
1191 string *ptag,
1192 string *petag,
1193 void (*progress_cb)(off_t, void *),
1194 void *progress_data,
1195 const DoutPrefixProvider *dpp,
1196 optional_yield y);
1197
1198 int copy_obj_data(RGWObjectCtx& obj_ctx,
1199 rgw::sal::RGWBucket* bucket,
1200 const rgw_placement_rule& dest_placement,
1201 RGWRados::Object::Read& read_op, off_t end,
1202 rgw::sal::RGWObject* dest_obj,
1203 ceph::real_time *mtime,
1204 ceph::real_time set_mtime,
1205 map<string, bufferlist>& attrs,
1206 uint64_t olh_epoch,
1207 ceph::real_time delete_at,
1208 string *petag,
1209 const DoutPrefixProvider *dpp,
1210 optional_yield y);
1211
1212 int transition_obj(RGWObjectCtx& obj_ctx,
1213 rgw::sal::RGWBucket* bucket,
1214 rgw::sal::RGWObject& obj,
1215 const rgw_placement_rule& placement_rule,
1216 const real_time& mtime,
1217 uint64_t olh_epoch,
1218 const DoutPrefixProvider *dpp,
1219 optional_yield y);
1220
1221 int check_bucket_empty(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, optional_yield y);
1222
1223 /**
1224 * Delete a bucket.
1225 * bucket: the name of the bucket to delete
1226 * Returns 0 on success, -ERR# otherwise.
1227 */
1228 int delete_bucket(RGWBucketInfo& bucket_info, RGWObjVersionTracker& objv_tracker, optional_yield y, const DoutPrefixProvider *dpp, bool check_empty = true);
1229
1230 void wakeup_meta_sync_shards(set<int>& shard_ids);
1231 void wakeup_data_sync_shards(const rgw_zone_id& source_zone, map<int, set<string> >& shard_ids);
1232
1233 RGWMetaSyncStatusManager* get_meta_sync_manager();
1234 RGWDataSyncStatusManager* get_data_sync_manager(const rgw_zone_id& source_zone);
1235
1236 int set_bucket_owner(rgw_bucket& bucket, ACLOwner& owner, const DoutPrefixProvider *dpp);
1237 int set_buckets_enabled(std::vector<rgw_bucket>& buckets, bool enabled, const DoutPrefixProvider *dpp);
1238 int bucket_suspended(const DoutPrefixProvider *dpp, rgw_bucket& bucket, bool *suspended);
1239
1240 /** Delete an object.*/
1241 int delete_obj(const DoutPrefixProvider *dpp,
1242 RGWObjectCtx& obj_ctx,
1243 const RGWBucketInfo& bucket_owner,
1244 const rgw_obj& src_obj,
1245 int versioning_status, // versioning flags in enum RGWBucketFlags
1246 uint16_t bilog_flags = 0,
1247 const ceph::real_time& expiration_time = ceph::real_time(),
1248 rgw_zone_set *zones_trace = nullptr);
1249
1250 int delete_raw_obj(const DoutPrefixProvider *dpp, const rgw_raw_obj& obj);
1251
1252 /** Remove an object from the bucket index */
1253 int delete_obj_index(const rgw_obj& obj, ceph::real_time mtime, const DoutPrefixProvider *dpp);
1254
1255 /**
1256 * Set an attr on an object.
1257 * bucket: name of the bucket holding the object
1258 * obj: name of the object to set the attr on
1259 * name: the attr to set
1260 * bl: the contents of the attr
1261 * Returns: 0 on success, -ERR# otherwise.
1262 */
1263 int set_attr(const DoutPrefixProvider *dpp, void *ctx, const RGWBucketInfo& bucket_info, rgw_obj& obj, const char *name, bufferlist& bl);
1264
1265 int set_attrs(const DoutPrefixProvider *dpp, void *ctx, const RGWBucketInfo& bucket_info, rgw_obj& obj,
1266 map<string, bufferlist>& attrs,
1267 map<string, bufferlist>* rmattrs,
1268 optional_yield y);
1269
1270 int get_obj_state(const DoutPrefixProvider *dpp, RGWObjectCtx *rctx, const RGWBucketInfo& bucket_info, const rgw_obj& obj, RGWObjState **state,
1271 bool follow_olh, optional_yield y, bool assume_noent = false);
1272 int get_obj_state(const DoutPrefixProvider *dpp, RGWObjectCtx *rctx, const RGWBucketInfo& bucket_info, const rgw_obj& obj, RGWObjState **state, optional_yield y) {
1273 return get_obj_state(dpp, rctx, bucket_info, obj, state, true, y);
1274 }
1275
1276 using iterate_obj_cb = int (*)(const DoutPrefixProvider*, const rgw_raw_obj&, off_t, off_t,
1277 off_t, bool, RGWObjState*, void*);
1278
1279 int iterate_obj(const DoutPrefixProvider *dpp, RGWObjectCtx& ctx, const RGWBucketInfo& bucket_info,
1280 const rgw_obj& obj, off_t ofs, off_t end,
1281 uint64_t max_chunk_size, iterate_obj_cb cb, void *arg,
1282 optional_yield y);
1283
1284 int get_obj_iterate_cb(const DoutPrefixProvider *dpp,
1285 const rgw_raw_obj& read_obj, off_t obj_ofs,
1286 off_t read_ofs, off_t len, bool is_head_obj,
1287 RGWObjState *astate, void *arg);
1288
1289 void get_obj_aio_completion_cb(librados::completion_t cb, void *arg);
1290
1291 /**
1292 * a simple object read without keeping state
1293 */
1294
1295 int raw_obj_stat(const DoutPrefixProvider *dpp,
1296 rgw_raw_obj& obj, uint64_t *psize, ceph::real_time *pmtime, uint64_t *epoch,
1297 map<string, bufferlist> *attrs, bufferlist *first_chunk,
1298 RGWObjVersionTracker *objv_tracker, optional_yield y);
1299
1300 int obj_operate(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj, librados::ObjectWriteOperation *op);
1301 int obj_operate(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj, librados::ObjectReadOperation *op);
1302
1303 int guard_reshard(const DoutPrefixProvider *dpp,
1304 BucketShard *bs,
1305 const rgw_obj& obj_instance,
1306 const RGWBucketInfo& bucket_info,
1307 std::function<int(BucketShard *)> call);
1308 int block_while_resharding(RGWRados::BucketShard *bs,
1309 string *new_bucket_id,
1310 const RGWBucketInfo& bucket_info,
1311 optional_yield y,
1312 const DoutPrefixProvider *dpp);
1313
1314 void bucket_index_guard_olh_op(const DoutPrefixProvider *dpp, RGWObjState& olh_state, librados::ObjectOperation& op);
1315 int olh_init_modification(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, RGWObjState& state, const rgw_obj& olh_obj, string *op_tag);
1316 int olh_init_modification_impl(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, RGWObjState& state, const rgw_obj& olh_obj, string *op_tag);
1317 int bucket_index_link_olh(const DoutPrefixProvider *dpp,
1318 const RGWBucketInfo& bucket_info, RGWObjState& olh_state,
1319 const rgw_obj& obj_instance, bool delete_marker,
1320 const string& op_tag, struct rgw_bucket_dir_entry_meta *meta,
1321 uint64_t olh_epoch,
1322 ceph::real_time unmod_since, bool high_precision_time,
1323 rgw_zone_set *zones_trace = nullptr,
1324 bool log_data_change = false);
1325 int bucket_index_unlink_instance(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj_instance, const string& op_tag, const string& olh_tag, uint64_t olh_epoch, rgw_zone_set *zones_trace = nullptr);
1326 int bucket_index_read_olh_log(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, RGWObjState& state, const rgw_obj& obj_instance, uint64_t ver_marker,
1327 map<uint64_t, vector<rgw_bucket_olh_log_entry> > *log, bool *is_truncated);
1328 int bucket_index_trim_olh_log(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, RGWObjState& obj_state, const rgw_obj& obj_instance, uint64_t ver);
1329 int bucket_index_clear_olh(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, RGWObjState& state, const rgw_obj& obj_instance);
1330 int apply_olh_log(const DoutPrefixProvider *dpp, RGWObjectCtx& ctx, RGWObjState& obj_state, const RGWBucketInfo& bucket_info, const rgw_obj& obj,
1331 bufferlist& obj_tag, map<uint64_t, vector<rgw_bucket_olh_log_entry> >& log,
1332 uint64_t *plast_ver, rgw_zone_set *zones_trace = nullptr);
1333 int update_olh(const DoutPrefixProvider *dpp, RGWObjectCtx& obj_ctx, RGWObjState *state, const RGWBucketInfo& bucket_info, const rgw_obj& obj, rgw_zone_set *zones_trace = nullptr);
1334 int set_olh(const DoutPrefixProvider *dpp, RGWObjectCtx& obj_ctx, const RGWBucketInfo& bucket_info, const rgw_obj& target_obj, bool delete_marker, rgw_bucket_dir_entry_meta *meta,
1335 uint64_t olh_epoch, ceph::real_time unmod_since, bool high_precision_time,
1336 optional_yield y, rgw_zone_set *zones_trace = nullptr, bool log_data_change = false);
1337 int repair_olh(const DoutPrefixProvider *dpp, RGWObjState* state, const RGWBucketInfo& bucket_info,
1338 const rgw_obj& obj);
1339 int unlink_obj_instance(const DoutPrefixProvider *dpp, RGWObjectCtx& obj_ctx, RGWBucketInfo& bucket_info, const rgw_obj& target_obj,
1340 uint64_t olh_epoch, optional_yield y, rgw_zone_set *zones_trace = nullptr);
1341
1342 void check_pending_olh_entries(map<string, bufferlist>& pending_entries, map<string, bufferlist> *rm_pending_entries);
1343 int remove_olh_pending_entries(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, RGWObjState& state, const rgw_obj& olh_obj, map<string, bufferlist>& pending_attrs);
1344 int follow_olh(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, RGWObjectCtx& ctx, RGWObjState *state, const rgw_obj& olh_obj, rgw_obj *target);
1345 int get_olh(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj, RGWOLHInfo *olh);
1346
1347 void gen_rand_obj_instance_name(rgw_obj_key *target_key);
1348 void gen_rand_obj_instance_name(rgw_obj *target);
1349
1350 int update_containers_stats(map<string, RGWBucketEnt>& m, const DoutPrefixProvider *dpp);
1351 int append_async(const DoutPrefixProvider *dpp, rgw_raw_obj& obj, size_t size, bufferlist& bl);
1352
1353 public:
1354 void set_atomic(void *ctx, rgw_obj& obj) {
1355 RGWObjectCtx *rctx = static_cast<RGWObjectCtx *>(ctx);
1356 rctx->set_atomic(obj);
1357 }
1358 void set_prefetch_data(void *ctx, const rgw_obj& obj) {
1359 RGWObjectCtx *rctx = static_cast<RGWObjectCtx *>(ctx);
1360 rctx->set_prefetch_data(obj);
1361 }
1362 int decode_policy(bufferlist& bl, ACLOwner *owner);
1363 int get_bucket_stats(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, int shard_id, string *bucket_ver, string *master_ver,
1364 map<RGWObjCategory, RGWStorageStats>& stats, string *max_marker, bool* syncstopped = NULL);
1365 int get_bucket_stats_async(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, int shard_id, RGWGetBucketStats_CB *cb);
1366
1367 int put_bucket_instance_info(RGWBucketInfo& info, bool exclusive, ceph::real_time mtime, map<string, bufferlist> *pattrs, const DoutPrefixProvider *dpp);
1368 /* xxx dang obj_ctx -> svc */
1369 int get_bucket_instance_info(RGWSysObjectCtx& obj_ctx, const string& meta_key, RGWBucketInfo& info, ceph::real_time *pmtime, map<string, bufferlist> *pattrs, optional_yield y, const DoutPrefixProvider *dpp);
1370 int get_bucket_instance_info(RGWSysObjectCtx& obj_ctx, const rgw_bucket& bucket, RGWBucketInfo& info, ceph::real_time *pmtime, map<string, bufferlist> *pattrs, optional_yield y, const DoutPrefixProvider *dpp);
1371
1372 static void make_bucket_entry_name(const string& tenant_name, const string& bucket_name, string& bucket_entry);
1373
1374 int get_bucket_info(RGWServices *svc,
1375 const string& tenant_name, const string& bucket_name,
1376 RGWBucketInfo& info,
1377 ceph::real_time *pmtime, optional_yield y,
1378 const DoutPrefixProvider *dpp, map<string, bufferlist> *pattrs = NULL);
1379
1380 // Returns 0 on successful refresh. Returns error code if there was
1381 // an error or the version stored on the OSD is the same as that
1382 // presented in the BucketInfo structure.
1383 //
1384 int try_refresh_bucket_info(RGWBucketInfo& info,
1385 ceph::real_time *pmtime,
1386 const DoutPrefixProvider *dpp,
1387 map<string, bufferlist> *pattrs = nullptr);
1388
1389 int put_linked_bucket_info(RGWBucketInfo& info, bool exclusive, ceph::real_time mtime, obj_version *pep_objv,
1390 map<string, bufferlist> *pattrs, bool create_entry_point,
1391 const DoutPrefixProvider *dpp);
1392
1393 int cls_obj_prepare_op(const DoutPrefixProvider *dpp, BucketShard& bs, RGWModifyOp op, string& tag, rgw_obj& obj, uint16_t bilog_flags, optional_yield y, rgw_zone_set *zones_trace = nullptr);
1394 int cls_obj_complete_op(BucketShard& bs, const rgw_obj& obj, RGWModifyOp op, string& tag, int64_t pool, uint64_t epoch,
1395 rgw_bucket_dir_entry& ent, RGWObjCategory category, list<rgw_obj_index_key> *remove_objs, uint16_t bilog_flags, rgw_zone_set *zones_trace = nullptr);
1396 int cls_obj_complete_add(BucketShard& bs, const rgw_obj& obj, string& tag, int64_t pool, uint64_t epoch, rgw_bucket_dir_entry& ent,
1397 RGWObjCategory category, list<rgw_obj_index_key> *remove_objs, uint16_t bilog_flags, rgw_zone_set *zones_trace = nullptr);
1398 int cls_obj_complete_del(BucketShard& bs, string& tag, int64_t pool, uint64_t epoch, rgw_obj& obj,
1399 ceph::real_time& removed_mtime, list<rgw_obj_index_key> *remove_objs, uint16_t bilog_flags, rgw_zone_set *zones_trace = nullptr);
1400 int cls_obj_complete_cancel(BucketShard& bs, string& tag, rgw_obj& obj, uint16_t bilog_flags, rgw_zone_set *zones_trace = nullptr);
1401 int cls_obj_set_bucket_tag_timeout(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, uint64_t timeout);
1402
1403 using ent_map_t =
1404 boost::container::flat_map<std::string, rgw_bucket_dir_entry>;
1405
1406 using check_filter_t = bool (*)(const std::string&);
1407
1408 int cls_bucket_list_ordered(const DoutPrefixProvider *dpp,
1409 RGWBucketInfo& bucket_info,
1410 const int shard_id,
1411 const rgw_obj_index_key& start_after,
1412 const string& prefix,
1413 const string& delimiter,
1414 const uint32_t num_entries,
1415 const bool list_versions,
1416 const uint16_t exp_factor, // 0 means ignore
1417 ent_map_t& m,
1418 bool* is_truncated,
1419 bool* cls_filtered,
1420 rgw_obj_index_key *last_entry,
1421 optional_yield y,
1422 check_filter_t force_check_filter = nullptr);
1423 int cls_bucket_list_unordered(const DoutPrefixProvider *dpp,
1424 RGWBucketInfo& bucket_info,
1425 int shard_id,
1426 const rgw_obj_index_key& start_after,
1427 const string& prefix,
1428 uint32_t num_entries,
1429 bool list_versions,
1430 vector<rgw_bucket_dir_entry>& ent_list,
1431 bool *is_truncated,
1432 rgw_obj_index_key *last_entry,
1433 optional_yield y,
1434 check_filter_t = nullptr);
1435 int cls_bucket_head(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, int shard_id, vector<rgw_bucket_dir_header>& headers, map<int, string> *bucket_instance_ids = NULL);
1436 int cls_bucket_head_async(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, int shard_id, RGWGetDirHeader_CB *ctx, int *num_aio);
1437
1438 int bi_get_instance(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj, rgw_bucket_dir_entry *dirent);
1439 int bi_get_olh(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj, rgw_bucket_olh_entry *olh);
1440 int bi_get(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const rgw_obj& obj, BIIndexType index_type, rgw_cls_bi_entry *entry);
1441 void bi_put(librados::ObjectWriteOperation& op, BucketShard& bs, rgw_cls_bi_entry& entry);
1442 int bi_put(BucketShard& bs, rgw_cls_bi_entry& entry);
1443 int bi_put(const DoutPrefixProvider *dpp, rgw_bucket& bucket, rgw_obj& obj, rgw_cls_bi_entry& entry);
1444 int bi_list(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, int shard_id, const string& filter_obj, const string& marker, uint32_t max, list<rgw_cls_bi_entry> *entries, bool *is_truncated);
1445 int bi_list(BucketShard& bs, const string& filter_obj, const string& marker, uint32_t max, list<rgw_cls_bi_entry> *entries, bool *is_truncated);
1446 int bi_list(const DoutPrefixProvider *dpp, rgw_bucket& bucket, const string& obj_name, const string& marker, uint32_t max,
1447 list<rgw_cls_bi_entry> *entries, bool *is_truncated);
1448 int bi_remove(BucketShard& bs);
1449
1450 int cls_obj_usage_log_add(const DoutPrefixProvider *dpp, const string& oid, rgw_usage_log_info& info);
1451 int cls_obj_usage_log_read(const DoutPrefixProvider *dpp, const string& oid, const string& user, const string& bucket, uint64_t start_epoch,
1452 uint64_t end_epoch, uint32_t max_entries, string& read_iter, map<rgw_user_bucket,
1453 rgw_usage_log_entry>& usage, bool *is_truncated);
1454 int cls_obj_usage_log_trim(const DoutPrefixProvider *dpp, const string& oid, const string& user, const string& bucket, uint64_t start_epoch,
1455 uint64_t end_epoch);
1456 int cls_obj_usage_log_clear(const DoutPrefixProvider *dpp, string& oid);
1457
1458 int get_target_shard_id(const rgw::bucket_index_normal_layout& layout, const string& obj_key, int *shard_id);
1459
1460 int lock_exclusive(const rgw_pool& pool, const string& oid, ceph::timespan& duration, rgw_zone_id& zone_id, string& owner_id);
1461 int unlock(const rgw_pool& pool, const string& oid, rgw_zone_id& zone_id, string& owner_id);
1462
1463 void update_gc_chain(const DoutPrefixProvider *dpp, rgw_obj& head_obj, RGWObjManifest& manifest, cls_rgw_obj_chain *chain);
1464 int send_chain_to_gc(cls_rgw_obj_chain& chain, const string& tag);
1465 void delete_objs_inline(const DoutPrefixProvider *dpp, cls_rgw_obj_chain& chain, const string& tag);
1466 int gc_operate(const DoutPrefixProvider *dpp, string& oid, librados::ObjectWriteOperation *op);
1467 int gc_aio_operate(const std::string& oid, librados::AioCompletion *c,
1468 librados::ObjectWriteOperation *op);
1469 int gc_operate(const DoutPrefixProvider *dpp, string& oid, librados::ObjectReadOperation *op, bufferlist *pbl);
1470
1471 int list_gc_objs(int *index, string& marker, uint32_t max, bool expired_only, std::list<cls_rgw_gc_obj_info>& result, bool *truncated, bool& processing_queue);
1472 int process_gc(bool expired_only);
1473 bool process_expire_objects(const DoutPrefixProvider *dpp);
1474 int defer_gc(const DoutPrefixProvider *dpp, void *ctx, const RGWBucketInfo& bucket_info, const rgw_obj& obj, optional_yield y);
1475
1476 int process_lc();
1477 int list_lc_progress(string& marker, uint32_t max_entries,
1478 vector<rgw::sal::Lifecycle::LCEntry>& progress_map, int& index);
1479
1480 int bucket_check_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info,
1481 map<RGWObjCategory, RGWStorageStats> *existing_stats,
1482 map<RGWObjCategory, RGWStorageStats> *calculated_stats);
1483 int bucket_rebuild_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info);
1484 int bucket_set_reshard(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, const cls_rgw_bucket_instance_entry& entry);
1485 int remove_objs_from_index(const DoutPrefixProvider *dpp, RGWBucketInfo& bucket_info, list<rgw_obj_index_key>& oid_list);
1486 int move_rados_obj(const DoutPrefixProvider *dpp,
1487 librados::IoCtx& src_ioctx,
1488 const string& src_oid, const string& src_locator,
1489 librados::IoCtx& dst_ioctx,
1490 const string& dst_oid, const string& dst_locator);
1491 int fix_head_obj_locator(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, bool copy_obj, bool remove_bad, rgw_obj_key& key);
1492 int fix_tail_obj_locator(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, rgw_obj_key& key, bool fix, bool *need_fix, optional_yield y);
1493
1494 int check_quota(const rgw_user& bucket_owner, rgw_bucket& bucket,
1495 RGWQuotaInfo& user_quota, RGWQuotaInfo& bucket_quota, uint64_t obj_size,
1496 optional_yield y, bool check_size_only = false);
1497
1498 int check_bucket_shards(const RGWBucketInfo& bucket_info, const rgw_bucket& bucket,
1499 uint64_t num_objs, const DoutPrefixProvider *dpp);
1500
1501 int add_bucket_to_reshard(const DoutPrefixProvider *dpp, const RGWBucketInfo& bucket_info, uint32_t new_num_shards);
1502
1503 uint64_t instance_id();
1504
1505 librados::Rados* get_rados_handle();
1506
1507 int delete_raw_obj_aio(const DoutPrefixProvider *dpp, const rgw_raw_obj& obj, list<librados::AioCompletion *>& handles);
1508 int delete_obj_aio(const DoutPrefixProvider *dpp, const rgw_obj& obj, RGWBucketInfo& info, RGWObjState *astate,
1509 list<librados::AioCompletion *>& handles, bool keep_index_consistent,
1510 optional_yield y);
1511
1512 private:
1513 /**
1514 * Check the actual on-disk state of the object specified
1515 * by list_state, and fill in the time and size of object.
1516 * Then append any changes to suggested_updates for
1517 * the rgw class' dir_suggest_changes function.
1518 *
1519 * Note that this can maul list_state; don't use it afterwards. Also
1520 * it expects object to already be filled in from list_state; it only
1521 * sets the size and mtime.
1522 *
1523 * Returns 0 on success, -ENOENT if the object doesn't exist on disk,
1524 * and -errno on other failures. (-ENOENT is not a failure, and it
1525 * will encode that info as a suggested update.)
1526 */
1527 int check_disk_state(const DoutPrefixProvider *dpp,
1528 librados::IoCtx io_ctx,
1529 const RGWBucketInfo& bucket_info,
1530 rgw_bucket_dir_entry& list_state,
1531 rgw_bucket_dir_entry& object,
1532 bufferlist& suggested_updates,
1533 optional_yield y);
1534
1535 /**
1536 * Init pool iteration
1537 * pool: pool to use for the ctx initialization
1538 * ctx: context object to use for the iteration
1539 * Returns: 0 on success, -ERR# otherwise.
1540 */
1541 int pool_iterate_begin(const DoutPrefixProvider *dpp, const rgw_pool& pool, RGWPoolIterCtx& ctx);
1542
1543 /**
1544 * Init pool iteration
1545 * pool: pool to use
1546 * cursor: position to start iteration
1547 * ctx: context object to use for the iteration
1548 * Returns: 0 on success, -ERR# otherwise.
1549 */
1550 int pool_iterate_begin(const DoutPrefixProvider *dpp, const rgw_pool& pool, const string& cursor, RGWPoolIterCtx& ctx);
1551
1552 /**
1553 * Get pool iteration position
1554 * ctx: context object to use for the iteration
1555 * Returns: string representation of position
1556 */
1557 string pool_iterate_get_cursor(RGWPoolIterCtx& ctx);
1558
1559 /**
1560 * Iterate over pool return object names, use optional filter
1561 * ctx: iteration context, initialized with pool_iterate_begin()
1562 * num: max number of objects to return
1563 * objs: a vector that the results will append into
1564 * is_truncated: if not NULL, will hold true iff iteration is complete
1565 * filter: if not NULL, will be used to filter returned objects
1566 * Returns: 0 on success, -ERR# otherwise.
1567 */
1568 int pool_iterate(RGWPoolIterCtx& ctx, uint32_t num, vector<rgw_bucket_dir_entry>& objs,
1569 bool *is_truncated, RGWAccessListFilter *filter);
1570
1571 uint64_t next_bucket_id();
1572
1573 /**
1574 * This is broken out to facilitate unit testing.
1575 */
1576 static uint32_t calc_ordered_bucket_list_per_shard(uint32_t num_entries,
1577 uint32_t num_shards);
1578 };
1579
1580 #endif